Jump to content
  • Advertisement
Sign in to follow this  
ifaaan

X files and DrawSubset method

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

If I right understood X files format it can contains some meshes in it. For example: ... Mesh SomeMesh1 {...} Mesh SomeMesh2 {...} ... So the question is: DrawSubset function requires attributeID which is the integer identifier. How can I get attributeID from mesh name (SomeMesh1 and SomeMesh2 in example). Correct me, please, if I'm wrong somewhere. P.S. Sorry for moderators: I already posted that in "For beginners" forum, but it was ignored =( And sorry for my terrible English =)

Share this post


Link to post
Share on other sites
Advertisement
you should check this function:

HRESULT D3DXLoadMeshFromX(
LPCTSTR pFilename,
DWORD Options,
LPDIRECT3DDEVICE9 pD3DDevice,
LPD3DXBUFFER * ppAdjacency,
LPD3DXBUFFER * ppMaterials,
LPD3DXBUFFER * ppEffectInstances,
DWORD * pNumMaterials,
LPD3DXMESH * ppMesh
);

DWORD* pNumMaterials contains the number of subsets, so you just a loop for that
and then draw it::

for(int i = 0; i < pNumMaterials; ++i)
{
mesh->drawSubset(i);
}

you can also create a std::vector with the materials and go until you reached the end of that vector :)

Share this post


Link to post
Share on other sites
It's not exactly what I mean. I know how to draw subsets. I need to know the name of mesh defined in X file which binded to subset.

Share this post


Link to post
Share on other sites
As far as I know an X file contains only one mesh. The whole mesh is then loaded into a single vertex buffer. But because the mesh can contain several materials (like different textures) it also contains an attribute buffer besides the index buffer and the vertex buffer. The attribute buffer holds an index for each triangle. This index tells the triangle in which subset it is. That's why it is important to call Optimize if your attributes are not sorted.

For example if you have 5 triangles in your mesh and triangles 1,2,3 use texture 1 and triangles 4,5 use texture 2. The attribute buffer will be [0,0,0,1,1]. Furthermore the mesh will have 2 attribute ranges. An attribute range is equivalent to a subset.

typedef struct D3DXATTRIBUTERANGE {
DWORD AttribId;
DWORD FaceStart;
DWORD FaceCount;
DWORD VertexStart;
DWORD VertexCount;
} D3DXATTRIBUTERANGE, *LPD3DXATTRIBUTERANGE;


The first attribute range will be:

attrib[0].AttribID = 0; // first subset
attrib[0].FaceStart = 0; // triangle 1 is the first triangle in this subset
attrib[0].FaceCount = 3; // 3 triangles in the first subset
attrib[0].VertexStart = 0;
attrib[0].VertexCount = 6; // how many vertices are used during the rendering of this subset (the vertex count depends on whether you use index buffers and so on)


The second attribute range will be:

attrib[1].AttribID = 1; // second subset
attrib[1].FaceStart = 4; // start with triangle 4 in this subset
attrib[1].FaceCount = 2; // 2 triangles in the second subset
attrib[1].VertexStart = 6; // vertex index in the vertex buffer
attrib[1].VertexCount = 4; // (again, depends on how your mesh is indexed)


When you call DrawSubset you provide an AttributeID. If you call DrawSubset(0) the first subset will be rendered. The DrawSubset method will then internally do something like this:

m_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, attrib[AttributeID].VertexStart, 0, 
attrib[AttributeID].VertexCount, attrib[AttributeID].FaceStart*3, attrib[AttributeID].FaceCount);


So I think there is only one mesh and only one mesh name stored in an x file. Correct me if I'm wrong.

Share this post


Link to post
Share on other sites
Noup, you are wrong. X file can contain some meshes. Try it. And each mesh will be stored in the different subset

xof 0302txt 0032

Header {
1;
0;
1;
}



Material HightechFloor01 {
1.000000;1.000000;1.000000;1.000000;;
0.000000;
0.000000;0.000000;0.000000;;
0.000000;0.000000;0.000000;;
TextureFileName {
"HightechFloor01.jpg";
}
}

Mesh Mesh1{
24;
112.0000000;8.0000000;0.0000000;,
0.0000000;8.0000000;0.0000000;,
0.0000000;0.0000000;0.0000000;,
112.0000000;0.0000000;0.0000000;,
0.0000000;8.0000000;0.0000000;,
0.0000000;8.0000000;112.0000000;,
0.0000000;0.0000000;112.0000000;,
0.0000000;0.0000000;0.0000000;,
0.0000000;8.0000000;112.0000000;,
112.0000000;8.0000000;112.0000000;,
112.0000000;0.0000000;112.0000000;,
0.0000000;0.0000000;112.0000000;,
112.0000000;8.0000000;112.0000000;,
112.0000000;8.0000000;0.0000000;,
112.0000000;0.0000000;0.0000000;,
112.0000000;0.0000000;112.0000000;,
0.0000000;0.0000000;112.0000000;,
112.0000000;0.0000000;112.0000000;,
112.0000000;0.0000000;0.0000000;,
0.0000000;0.0000000;0.0000000;,
0.0000000;8.0000000;0.0000000;,
112.0000000;8.0000000;0.0000000;,
112.0000000;8.0000000;112.0000000;,
0.0000000;8.0000000;112.0000000;;

6;
4;3,2,1,0;,
4;7,6,5,4;,
4;11,10,9,8;,
4;15,14,13,12;,
4;19,18,17,16;,
4;23,22,21,20;;
MeshMaterialList {
1;
6;
0,
0,
0,
0,
0,
0;;
{ HightechFloor01 }
}
MeshNormals {
8;
0.5773503;-0.5773503;-0.5773503;,
-0.5773503;-0.5773503;-0.5773503;,
-0.5773503;-0.5773503;0.5773503;,
0.5773503;-0.5773503;0.5773503;,
0.5773503;0.5773503;-0.5773503;,
-0.5773503;0.5773503;-0.5773503;,
-0.5773503;0.5773503;0.5773503;,
0.5773503;0.5773503;0.5773503;;
6;
4;0,1,5,4;,
4;1,2,6,5;,
4;2,3,7,6;,
4;3,0,4,7;,
4;1,0,3,2;,
4;6,7,4,5;;
}
MeshTextureCoords {
24;
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;;
}
}

Material HightechWall03 {
1.000000;1.000000;1.000000;1.000000;;
0.000000;
0.000000;0.000000;0.000000;;
0.000000;0.000000;0.000000;;
TextureFileName {
"HightechWall03.jpg";
}
}

Mesh Mesh2{
24;
32.0000000;80.0000000;-4.0000000;,
-32.0000000;80.0000000;-4.0000000;,
-32.0000000;0.0000000;-4.0000000;,
32.0000000;0.0000000;-4.0000000;,
-32.0000000;80.0000000;-4.0000000;,
-32.0000000;80.0000000;4.0000000;,
-32.0000000;0.0000000;4.0000000;,
-32.0000000;0.0000000;-4.0000000;,
-32.0000000;80.0000000;4.0000000;,
32.0000000;80.0000000;4.0000000;,
32.0000000;0.0000000;4.0000000;,
-32.0000000;0.0000000;4.0000000;,
32.0000000;80.0000000;4.0000000;,
32.0000000;80.0000000;-4.0000000;,
32.0000000;0.0000000;-4.0000000;,
32.0000000;0.0000000;4.0000000;,
-32.0000000;0.0000000;4.0000000;,
32.0000000;0.0000000;4.0000000;,
32.0000000;0.0000000;-4.0000000;,
-32.0000000;0.0000000;-4.0000000;,
-32.0000000;80.0000000;-4.0000000;,
32.0000000;80.0000000;-4.0000000;,
32.0000000;80.0000000;4.0000000;,
-32.0000000;80.0000000;4.0000000;;

6;
4;3,2,1,0;,
4;7,6,5,4;,
4;11,10,9,8;,
4;15,14,13,12;,
4;19,18,17,16;,
4;23,22,21,20;;
MeshMaterialList {
1;
6;
0,
0,
0,
0,
0,
0;;
{ HightechWall03 }
}
MeshNormals {
8;
0.5773503;-0.5773503;-0.5773503;,
-0.5773503;-0.5773503;-0.5773503;,
-0.5773503;-0.5773503;0.5773503;,
0.5773503;-0.5773503;0.5773503;,
0.5773503;0.5773503;-0.5773503;,
-0.5773503;0.5773503;-0.5773503;,
-0.5773503;0.5773503;0.5773503;,
0.5773503;0.5773503;0.5773503;;
6;
4;0,1,5,4;,
4;1,2,6,5;,
4;2,3,7,6;,
4;3,0,4,7;,
4;1,0,3,2;,
4;6,7,4,5;;
}
MeshTextureCoords {
24;
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;,
0.0000000;1.0000000;,
1.0000000;1.0000000;,
1.0000000;0.0000000;,
0.0000000;0.0000000;;
}
}




Try DrawSubset(0) and DrawSubset(1) and you'll see.

Share this post


Link to post
Share on other sites
I see. I ran the following code on your mesh:

DWORD tsize;
pD3DXMesh->GetAttributeTable(NULL, &tsize);

DWORD nv = pD3DXMesh->GetNumVertices();
DWORD nf = pD3DXMesh->GetNumFaces();

DWORD *pAB;
pD3DXMesh->LockAttributeBuffer(D3DLOCK_READONLY, &pAB);
for (DWORD i = 0; i < nf; i++)
{
pAB++;
}
pD3DXMesh->UnlockAttributeBuffer();


The results are these:
tsize = 0
nv = 48
nf = 24
pAB = 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1

It looks like although the file specifies 2 meshes, both are stored in the same vertex buffer and in the same index buffer. The ID3DXMesh object will generate attributes for every triangle but the attribute table is not generated. I think the attribute table is generated when you call DrawSubset. So I guess the names are not stored and you need to know in what order the meshes are stored in your X-File. But I don't have much experience with X-Files so I could be totally wrong. Maybe someone else can tell you more.

[Edited by - 84r on July 31, 2008 7:04:56 AM]

Share this post


Link to post
Share on other sites
why you want more then 1 static mesh into 1 x-file?

And if you have more x-files that mostly if you have a animated x-file then use::

HRESULT D3DXLoadMeshHierarchyFromX(
LPCSTR Filename,
DWORD MeshOptions,
LPDIRECT3DDEVICE9 pDevice,
LPD3DXALLOCATEHIERARCHY pAlloc,
LPD3DXLOADUSERDATA pUserDataLoader,
LPD3DXFRAME* ppFrameHierarchy,
LPD3DXANIMATIONCONTROLLER* ppAnimController
);

i think this also works for more then one static mesh in a x-file but well its a lot of more work to do cos you have to write the LPD3DXALLOCATEHIERARCHY yourself but its your decision ;)

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!