Jump to content
  • Advertisement
Sign in to follow this  
CodeBoyCjy

how to get the vertex format of a model in XNA??

This topic is 3566 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey: I want to get the vertex position from the Model. But the vertex buffer provides me the data with the form of an array of BYTE. I think I need to know the vertex format to parse the array. Actually , I just need to know the size of each vertex is enough. How could I get the info?? Any help will be really appreciate.

Share this post


Link to post
Share on other sites
Advertisement
You'll have to loop through all the ModelMeshParts in all of the ModelMeshes that are part of the Model. ModelMeshPart has a VertexDeclaration property that will let you access the declaration, or you can just just the VertexStride property to find the number of bytes per vertex.

Share this post


Link to post
Share on other sites
I just figured out how to do this. I did it in a way that gives the maximum and minimum vertices.


VertexPositionNormalTexture[] vertices =
new VertexPositionNormalTexture[map.model.Meshes.VertexBuffer.SizeInBytes / VertexPositionNormalTexture.SizeInBytes];
model.Meshes.VertexBuffer.GetData<VertexPositionNormalTexture>(vertices);
Vector3[] vertexs = new Vector3[vertices.Length];
for (int k = 0; k < vertexs.Length; k++)
{
vertexs[k] = Vector3.Transform(vertices[k].Position, model.Meshes.ParentBone.Transform);
}
Vector3 max = maxVector(vertexs);
Vector3 min = minVector(vertexs);
Matrix m = Matrix.CreateFromYawPitchRoll(
model.rotation.Y, model.rotation.X, model.rotation.Z) *
Matrix.CreateScale(model.scale) * Matrix.CreateTranslation(model.position);
max = Vector3.Transform(max, m);
min = Vector3.Transform(min, m);



The vertexes array ends up being 3 times longer than the amount of actual vertices because each vertex is stored 3 times (for a reason I couldn't explain to you).

Share this post


Link to post
Share on other sites
(The vertexes array ends up being 3 times longer than the amount of actual vertices because each vertex is stored 3 times (for a reason I couldn't explain to you).)

I'm realy sorry that I want to know the reason of the 3 times space. I found that last night , I'm a little confused. In the .fbx , there are only 8 vertexes which is what I want , but when I load them in the XNA's Model , the vertex number turned out to be 24 which means there is no vertex reuse. Why?? And each triangle gets three vertexes with the same normal , I think it's a waste of space. And if the 3 times space vertexes exist for a reason , why do we need index? Why don't we just order the vertexes rightly??

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!