How do I retrieve Triangles from a Mesh (.X) ?

Started by
14 comments, last by oxygen_728 20 years ago
quote:Original post by oxygen_728
I am still a little curious as to how a program would look at a mesh (.x) and say...

"Oh, Look what we have here,

We have a Vertex Buffer full of Vertecies whose FVF has:
This many Vectors of ## size.
This many other options of ## size.
And they are in THIS order."


It is very difficult for me to find a way to do this (hours of searching); However, I am now capable of continuing on with my collision detection, but I am a little curious as to the streamlined way to do this for future projects.

What it basically comes down to is taking a *really* close look at the FVF (or the VertexDeclaration when dealing with shaders) associated with a model.

The DX docs say that model vertices can have many different kinds of info, but that the info MUST be in a specific order. Take a look at this page from the DX docs:

http://msdn.microsoft.com/library/en-us/directx9_c/directx/graphics/programmingguide/gettingstarted/direct3dresources/vertexbuffers/vertexdeclaration/fixedfunctionfvfcodes.asp

The FVF will tell you how many bytes are in the vertex. The .x file is saved with data specifing how many vertices are in the model and an index buffer to use when rendering or accessing the vertices. You have to use bit-wise comparisons to check an unknown FVF for different features.

An FVF is really just a DWORD, so say you wanted to see if an FVF (and therefore, its associated vertex structure) contained a diffuse color. You would do this:

if( UNKNOWN_FVF & D3DFVF_DIFFUSE )
// Vertex contains a diffuse color.

In my opinion, I think that the best way is to just clone the mesh into a format that your engine can deal with. If a model has a whole bunch of blending weight information that your engine isn''t designed to use, does it really matter if that blending info is there?

If your engine isn''t designed to use it, then there is no harm in getting rid of it by cloning the mesh into a format that you know. Since you still have the original model, you can always update your engine to deal with blending weights and then use the model without cloning it and loosing that info.

Hope this clears things up for ya,
neneboricua
Advertisement
Thank you very much for the help... I appreciate your time!
Have you looked at D3DXIntersect?
Joshua
I belive D3DXIntersect is for rays.
The problem as stated above was:

"I am wanting to implement a collision detection algorithm which needs to be able to check a ray against each triangle of a mesh..."

D3DXIntersect is an easy way to do this.
Joshua
I haven''t used it, but I wanted to do this part of the collision detection on my own.


Thanks for the suggestion though!

This topic is closed to new replies.

Advertisement