Public Group

# 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.

## 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 on other sites
Hi,

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.

hth
Jack

##### Share on other sites
Yap, this VertexCount killing me. I will try this.

Huge thanks for help,
Zaharije Pasalic

##### Share on other sites
Hi,

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:
LPDIRECT3DVERTEXBUFFER9		pVB		= NULL;LPDIRECT3DINDEXBUFFER9		pIB		= NULL;g_pMesh->GetVertexBuffer( &pVB );g_pMesh->GetIndexBuffer( &pIB );DWORD dwFVF = g_pMesh->GetFVF( );DWORD attrSize = 0;g_pMesh->GetAttributeTable( NULL, &attrSize );D3DXATTRIBUTERANGE *pAttr = new D3DXATTRIBUTERANGE[ attrSize ];g_pMesh->GetAttributeTable( pAttr, &attrSize );// Configure the deviceg_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!
Jack

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 31
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634120
• Total Posts
3015611
×