Hello everybody.
I am trying to get the position of vertices in a mesh.
That seems to work fine except that the data I get doesn't make sense. To me.
I use a lock on the mesh.VertexBuffer (both versions... an array and a graphics stream with same results) and use the returned array or graphics stream to look for vertices that have a Position "of interest". The only issue is that some "Positions" have coordinates in scientific format which doesn't make sense since the mesh renders nice.
Some code (used on ball.x shipped with the SDK. I have tried other meshes and the only one that has "normal", normal like in making sense, data is cube.x)
//graphic stream version
GraphicsStream gs = mesh.VertexBuffer.Lock(0, 0, LockFlags.ReadOnly);
Vector3[] verts = new Vector3[mesh.NumberVertices];
float nothing;
for (int i = 0; i < mesh.NumberVertices; i++)
{
verts
= (Vector3)gs.Read(typeof(Vector3));
for (int j=12;j<mesh.NumberBytesPerVertex;j++)
nothing = (byte)gs.Read(typeof(byte));
}
mesh.VertexBuffer.Unlock();
//array version (previous cloning was done on the mesh to "make sure" they have the same VertexFormat, the mesh and the verts array)
CustomVertes.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])mesh.LockVertexBuffer(typeof(CustomVertex.PositionNormalTextured), LockFlags.None, mesh.NumberVertices);
mesh.UnlockVertexBuffer();
To be more exact.... any of this 2 will result in "verts" having some weird data. Used on ball.x this is what the watch window displays after getting the "positions":
verts[0] {X: 0 Y: 0.4 Z: 0 }
verts[1] {X: -0.05857866 Y: 0.3695518 Z:.1414214} verts[2] {X: -6.69105E-09 Y: 0.3695518 Z: 0.1530734
}
verts[3] {X: 0 Y: 0.4 Z: 0 }
verts[2].X is the problem, just one of many...
Does it have anything to do with the VertexBufferFormat of the mesh What is a general approach to get the vertices positions in any mesh
Thanks for reading my novel and thank you in advance.
One more thing ... I can't use the DumpInfo that everybody heard of, at runtime so I didn't bother.

getting the position of vertices in a mesh
Insecurity
Indeed. So the 2 digits that I set in the CreationFlags (CreationFlags.FPUPreserve) do not actually affect the buffer but the display In this case the "X" of the vertex will be 0 in the "World" but .00000... in the vertex. Thank you.
LHarrison
Thank you for "shading" some light. :)
keeperman
-6.69105E-09 is 0.00000000669105. i.e. almost 0. If you expected to see a 0 in that position then your data is fine, just a little rounding error. Hopefully that explains why the mesh renders correctly.
cdeck
All FPUPreserve does is not switch the FPU into single mode. All the vertex buffers are still singles becuase thats all DirectX understands. So the flag doesnt' affect those numbers at all, just any other math you may do in your application.
If the vertex is that value in the buffer it will be that value * world matrix when its displayed. The FPU flag is nothing to do with this so there is no concept if it affecting the buffer but not the display.
Since 0 is representable in a single float the reason the value is this must be becuase thats the value that was read from the file.