Get world coordinates of mesh's vertices

I want to attach an arrow for debugging purposes to all vertices of a mesh that I created.



The problem is that the vectors I get from the [java].getMesh().getFloatBuffer(VertexBuffer.Type.Position)[/java]

refer to the coordinates of the original mesh that I created and don’t return the actual position in space,

means when I scale a geometry the mesh vertex position are still the same.



Makes actually sense, but how do I get the actual vertex locations in space?

Apply the world transform of the spatial to the vertex vectors?

1 Like

Yes I guess I have to multiply the vertex coordinates with a matrix, I’m trying to find out how to do that.

getWorldTransform().transform(vector, null) ?

1 Like

Oh yeah dude, you’re awesome! Thank you.

Happy to help. Be aware that you will be creating a lot of objects (one vector3f thrown away per vertice) that way so in most cases you would be better off doing something like:



[java]

Vector3f working=null;

Transform t = spatial.getWorldTransform();



for (Vector3f vert: vertices) {

working = t . transform ( vert, working ) ;

// Do stuff with working here

}

[/java]



It won’t make a big difference on some platforms but on others it could be significant.

1 Like

That is actually a good idea, because I’m doing a little bit more with the transformation matrix.

Well querying the transformation matrix doesn’t create a clone. It’s all the Vertex3f that were being created by the t . transform call that is being avoided here.