Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

yanuart

Getting a triangle list from ID3DXMesh

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

I know that we can get the vertexbuffer, but how can we get the faces list (triangle list) and their material information ?? I''m quite new on Direct3D so I don''t have the time to read all of the SDK help files to see if there is a right function. One more thing, what is an index buffer ?? And the AttributeTable is where you store the information on the material and faces that related to it,rite ?? HELPPPP

Share this post


Link to post
Share on other sites
Advertisement
to answer the index buffer question: an index buffer is a list of numbers which contain it''s vertice in a vertex buffer. Take for example a cube. In a vertex buffer you would have the 7 verticies, that''s it. Then in the index buffer you would have something like this:

  
short Indices[24] =
{
//front
6, 4, 7, 5,
//back
0, 2, 1, 3,
//left
0, 6, 1, 7,
//right
4, 2, 5, 3,
//top
8, 0, 9, 2,
//bottom
10, 1, 11, 3,
};



This might be for a triangle strip. Then you set the vertex buffer and index buffer and render. Basically, you tell the vertices to draw in an index buffer and you define them in a vertex buffer. Get it?

As for the id3dxmeshq, you would first copy the vertices into a vertex buffer and index buffer. Then you would create to objects. It''s hard to explain without seeing it: (ps: this is directly from the pick sample in the dx sdk)

WORD* pIndices;
VERTEX* pVertices;
DWORD dwNumFaces = m_pObject->GetLocalMesh()->GetNumFaces();

pIB->Lock( 0,0,(BYTE**)&pIndices, 0 );
pVB->Lock( 0,0,(BYTE**)&pVertices, 0 );

for( DWORD i=0; i<dwNumFaces; i++ )
{
D3DXVECTOR3 v0 = pVertices[pIndices[3*i+0]].p;
D3DXVECTOR3 v1 = pVertices[pIndices[3*i+1]].p;
D3DXVECTOR3 v2 = pVertices[pIndices[3*i+2]].p;
}

pIB->Unlock();
pVB->Unlock();

It creates a list of vertices using the indices. If you understand index buffer''s, it shouldn''t be hard to understand.

[Edited by - kmsixpence on October 17, 2005 7:00:52 PM]

Share this post


Link to post
Share on other sites
quote:

I know that we can get the vertexbuffer, but how can we get the faces list (triangle list) and their material information ??


For triangles, there''s an index buffer and a vertex buffer. To obtain a pointer to either:

HRESULT LockVertexBuffer(
DWORD Flags,
BYTE** ppData
);


and


HRESULT LockIndexBuffer(
DWORD Flags,
BYTE** ppData
);


Both function retrieve a pointer to the vertex (Coordinates, diffuse color, texture coordinates, etc) data and to the index (ordering of triangle faces) data.

As for materials, those are obtained when you load the mesh:

HRESULT D3DXLoadMeshFromX(
LPSTR pFilename,
DWORD Options,
LPDIRECT3DDEVICE8 pDevice,
LPD3DXBUFFER* ppAdjacency,
LPD3DXBUFFER* ppMaterials,
PDWORD pNumMaterials,
LPD3DXMESH* ppMesh
);

The ppMaterials is a pointer to a ID3DXBUFFER object that contains the names and settings for each material. Check out most of the samples that come with the SDK for examples on loading materials.

The attribute buffer is an array of DWORD values, one value that maps directly to each face in the mesh. These attribute values tell you the material # of the face. For instance, a mesh with 4 faces and two materials may have an attribute buffer like:
0, 0, 1, 1
The above means the first two faces use material #0, while the last two faces use material #1. Use the LockAttributeBuffer function to obtain a pointer to the attribute array.

Jim Adams

Share this post


Link to post
Share on other sites

  • 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!