Meshes without .x file

Started by
2 comments, last by Buckeye 15 years, 9 months ago
What are the steps to load and render a mesh without using an X file? Let's assume I can parse what ever format my artist hands me and at minimum get vertex position, normals, and texture coords. Looking over the SDK I see D3DX10CreateMesh I assume I define what a vertex format in this step. ID3DX10Mesh::SetVertexData ID3DX10Mesh::SetIndexData ID3DX10Mesh::DrawSubset I am confused as to how you specify a technique. I am confused as to how you specify a "subset" and what a subset is I am confused what they are referring to when they mention attributes and attribute tables. I am confused as to what a materiel is, although I know my 3D software defines them. How a materiel is used in a mesh and what the data consists of. Any guidance?
Advertisement
I can't help you in all those topics but:

A subset is a part of the mesh. Imagine your mesh consists of 2 boxes (box A and box B), you can have that mesh organized in such a way (using the attribute table) so that you define that the 1st subset is the box A, and the 2nd is the box B.

A material is something that specifies the appearence of a mesh. In Direct3D10 this can be one or several things like shaders, textures, etc.

So, if you wanted to draw boxes (A and B) with a different material you'd do something like:
... // set shaders, textures, renderstates etc for box Aboxes->DrawSubset( 0 );... // set shaders, textures, renderstates etc for box Bboxes->DrawSubset( 1 );
It looks like maya at least gives materiels that have

diffuse
specular
emissive

Seems to be the way something reflects light. How does that translate into direct3d? I no they have those kind of lights, but this is defining the surface it reflects from not the light...


I also see that a subset is a group of vetices that you may want to use a different texture, shader, or something else on, however it doesn't seem that the mesh object has any storage for that relationship. I guess it is up to a user defined wrapper to keep track of what texture, shader, etc, goes with which subset? It seems the subset is just a number of the vertices associated with a subset number, nothing else in that structure that I can see.
Quote:it is up to a user defined wrapper to keep track of what texture, shader, etc

Yep. The usual way to do it is to have an array of D3DXMATERIALs, one D3DXMATERIAL for each attribute group, where "subset"=="attribute group."

A D3DXMATERIAL contains a D3DMATERIAL9 (diffuse, specular, emissive) and a char*, most often used to store a texture name or path. You can certainly setup your own structure if you want to store separate effects or shaders for each attribute group.

Quote:It seems the subset is just a number of the vertices associated with a subset number

Sort of. Not the vertices but which face goes with which material. That relationship is stored (by you if you set up the mesh) in the mesh's attribute buffer.

The attribute buffer contains a DWORD (or WORD, I can't remember) for each face. That attribute number is the subset number you'll use. When you call mesh->DrawSubset(n), the mesh draws the faces that have the attribute number 'n' in the attribute buffer. If 'n' is found in the 5th, 7th and 20th positions in the attribute buffer, it will draw the 5th, 7th and 20th faces during that call.

So, when you set up the mesh, you have to ensure that the order of index buffer (which vertices go with which face) matches the order of the attributes in the attribute buffer.

Eventually, you'll want to call Optimize() or OptimizeInPlace() after the mesh is loaded. You may want to look into that later. You can get the mesh to organize itself to put all the faces with attribute 0 in order first, then attribute 1, 2, etc.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement