Sign in to follow this  
dhanji

index buffers and meshes

Recommended Posts

Hi, I am trying to split my loaded mesh into 2. If a triangle exists above a certain plane I add it into indexbuffer A, and below into B. Obviously some triangles may be present in both. However, my question is, when using ID3DXMesh how would I render just A or B? I am currently copying A or B into the mesh's index buffer using a Lock operation. But this seems slower than is possible. I was thinking it is possible just to SetStreamSource to the mesh's VertexBuffer and SetIndices to A or B, however, the problem with this is that I dont know what texture to set to which triangle. Is there an easy way to separate the vertices into texture subsets? I know the mesh already has them stored in the attribute buffer this way. How would I go about extracting that information? So I can use DrawIP instead of ID3DXMesh::DrawSubset thanks in adv.

Share this post


Link to post
Share on other sites
Quote:
However, my question is, when using ID3DXMesh how would I render just A or B?
Well, if done right, then you'd want one to be subset-0 and the other to be subset-1. Doing it this way would probably fit in nicely with the way ID3DXMesh is designed.

Quote:
I know the mesh already has them stored in the attribute buffer this way
ID3DXMesh, afaik, stores the majority of this sort of information in the attribute buffer, I think you can retrieve it using D3DX methods/structs. However, as mentioned above, I think you want to invest your time in "re-writing" the attribute buffer.

I've not messed with this sort of thing directly, but I'm pretty sure you specify a range of indicies to belong to a given material and texture group. These then become the relevent subsets, displayed with DrawSubset( i ). With a bit of effort you should be able to pre-process your mesh at load time to create a set of "A" and "B" attribute-sections that you can then easily render.

======================= EDIT ========================

Just had a quick look on MSDN (was curious). ID3DXMesh::GetAttributeTable() is probably going to be of particular use:

Quote:
An attribute table is used to identify areas of the mesh that need to be drawn with different textures, render states, materials, and so on. In addition, the application can use the attribute table to hide portions of a mesh by not drawing a given attribute identifier when drawing the frame.


So I guess you could use this to get a list of all the material/texture combinations. The ID3DXMesh::LockAttributeBuffer() method should tell you which face belongs to which subset.

I'd guess that if you modified the attribute table to have twice the number of entries (1 for 'A' and 1 for 'B'), then locked the attribute buffer, and for each face that was in B, increment the attribute index accordingly.

There might be an easier way to do it, but this way seems fairly trivial to me.

======================= END EDIT ========================

hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this