Advertisement Jump to content
Sign in to follow this  

ID3DXMesh AttributeTable

This topic is 4963 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

Hay, I have problem (who do not). Suppose that I have list of vertices that represents mesh and ONE OR MORE lists of faces. Every list of faces have own material and they all index samo vertex list. And I wanna to build ID3DXMesh interface. I tryed with SetAttributeTable but vertices are not grouped by face lists eg. vertex list can filled with few vertices from first list of faces, than goes few vertices from second list of faces, than goes again first, etc. With this I can not build Table (it needs: StartFace,FaceCount, StartVertex, VertexCount, ID). Any suggestion? P.S. I can write my own mesh, but I can not find any good algo for optimization (like Optimize and OptimizeInPlace), and I need CloneFVF. Both of this can be implemented from stratch, but ... Thanks, Pasalic Zaharije

Share this post

Link to post
Share on other sites

For future reference, you might well wanna drop by the DirectX forum - theres a lot of people good at the specifics of DX hanging around there [smile]

Anyway, for your problem... I understand it as this:

You have a list of vertices:

V0, V1, V2, V3, V4, V5, V6, V7, V8, V9 ...

And these go in the ID3DXMesh's vertex buffer. I assume you have no problem creating a mesh with the source data?

Now, you Have multiple lists of faces. A face being a triplet of vertex indices - presumably you are storing these in the index buffer. Correct?

To clarify:

L0 = { {V0, V1, V2}, {V3, V4, V5}, {V6, V7, V8} }
L1 = { {V0, V2, V4}, {V6, V7, V9} }

Thus your index buffer should have indices laid out accordingly:
V0, V1, V2, V3, V4, V5, V6, V7, V8, V0, V2, V4, V6, V7, V9

Ignore the fact that the indices might not make much sense in that order [smile]

So, your attribute table - a list of D3DXATTRIBUTERANGE structures - should have two entries, one for L0 and one for L1.
First List

AttribId = 0
FaceStart = 0
FaceCount = 3
VertexStart = 0
VertexCount = 9 //I'm not sure on this one, the docs aren't clear

Second List

AttribId = 1
FaceStart = 3
FaceCount = 2
VertexStart = 0
VertexCount = 6 //I'm not sure on this one, the docs aren't clear


Does that make sense to you?

I have some code at home that does this sort of thing, but I'm at work right now so can't look it up ([headshake]). If you're still stuck I can try and dig it up to find out the exact values.


Share this post

Link to post
Share on other sites

Said I'd have a look into my code when I got home from work...

It's not quite what you were after, but essentially speaking I rewrote the ID3DXMesh::DrawSubset() function. In doing so, I had to decode how the various attribute table fields translated into parameters for drawing calls.

My code works fine when handling a mesh pulled in using the regular D3DX loading code.

Maybe you can work backwards and see what values you actually need [smile]

This first bit is the "initialization" code where it acquires the necessary resources:


g_pMesh->GetVertexBuffer( &pVB );

g_pMesh->GetIndexBuffer( &pIB );

DWORD dwFVF = g_pMesh->GetFVF( );

DWORD attrSize = 0;
g_pMesh->GetAttributeTable( NULL, &attrSize );

g_pMesh->GetAttributeTable( pAttr, &attrSize );

// Configure the device
g_pd3dDevice->SetFVF( dwFVF );
g_pd3dDevice->SetStreamSource( 0, pVB, 0, D3DXGetFVFVertexSize( dwFVF ) );
g_pd3dDevice->SetIndices( pIB );

This next part is the loop, which is essentially identical to the normal ID3DXMesh rendering routine - just some different code in place of DrawSubset():

for( DWORD i = 0; i < g_dwNumMaterials; i++ )
g_pd3dDevice->SetMaterial( &g_pMeshMaterials );
g_pd3dDevice->SetTexture( 0, g_pMeshTextures );
g_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,
0, //BaseVertexIndex
pAttr.VertexStart, //MinIndex pAttr.VertexCount, //NumVertices
pAttr.FaceStart * 3, //StartIndex
pAttr.FaceCount ); //NumPrimitives

Then, as all good programs should, we clean up:

if( pVB != NULL )
pVB->Release( );

if( pIB != NULL )
pIB->Release( );

delete[] pAttr;

Fingers crossed that might of some use!

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!