[Closed] getting Z-Axis of a vertex
hi,
im wirting a little script to export the Z-axis of a displaced plane for use as a terain in my game engine.
i’ve written all the script and it all works fine, only problem is that im useing the
meshop.getVert $.mesh (i)
command to go through each vertex in a for loop and putting the cordiants to an array and it writes all the axis. is there any way i can just get the Z-Axis or any ideas on a work around.
cheers
geoff
One thing I am not really clear about is which Z-axis you need. If it’s a local Z-axis of the vert then you are trying to find the normal of the vert and the comand for it is getNormal <mesh> <vert_index_integer>. The result is the direction of the up-vector of the vert or yyou Z-axis.
cheers for the reply. sorry its local Z-Axis.
i’ve just tried that command and it ended up giving me this:
[0.258973,-0.334605,0.906075]
not too sure what this is as it isnt the XYZ position.
Happy you found your solution:) What you got from my idea was an XYZ position as you see it is a float3 value [x,y,z]. But it is a normalized XYZ meaning that the length of the vector they define is 1. I went from the direction of how shaders find which vertices are going to be rendered by the pixel shader, where the vertex shader figures out the normal of each vert to find whether the vert is visible to the camera (or is located witinin the viewable area of the camera coordinate system). The getNormal function would find you the direction of the Z axis, but I guess that’s not exactly what you were looking for:)
Judging from the script you were only looking for the Z position of the vert, so that’s why my idea was useless to ya:)
the function you are using should work fine. all you have to do is store it in a variable and then put the z axis of that variable into the array. Or even faster would be to use the collect function like so:
theMesh = $.mesh
count = getNumVerts theMesh
-- collect all the z position values
theArray = for i = 1 to count collect (getVert theMesh i).z
EDIT: if you want the world space z position use the following line instead of the last line in the previous code:
theArray = for i = 1 to count collect ((getVert theMesh i) * $.transform).z
i ended up using a simular idea to your own.
p = meshop.getNumVerts $.mesh
--makes a blank array
height_data = #()
-- for loop to collect the data into an array
for i = 1 to p do
(
--assaises a varibal with the local Z-axis of the selected vertice
new_z = teraine.verts [i].pos.z
--adds the data from the varibal to an array witch corrosponds with the vertex number
height_data[i] = new_z
)
thats the code incase anyone else needs it at some point.
thanks for all your help guys.