Sign in to follow this  

MeshBuilder Help?

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

Hey guys. I'm trying to create my maps via parsing a map file (VMF - Valve Map Format), and then creating a model of the geometry (Similar to the heightmap tutorial) by using a custom Content Processor / Importer. This works, and the VMF file is imported and parsed into KeyValues (The VMF format), however, I'm stuck on how to use the MeshBuilder (The docs are very sparse, and not very helpful). From the map format, I have planes to deal with, each which can have its own texture, and I have 3 vectors for 3 corners of this plane. This is the point I am VERY confused at... any help much appreciated.

Share this post


Link to post
Share on other sites
First, I'm not familiar with MeshBuilder so you'll have to translate my comments yourself.

However, from the sounds of it, you will have several triangles (call them faces), each of which may have it's own texture, and you want to create a mesh of those faces.

If that's correct, the mesh will need to be comprised of several attribute groups.

An attribute group is a set of faces which have the same material (colors and textures).

Before you go through the steps below, you'll have to create a data table with an entry for each face (to know which faces need which materials). This will come from your map data (I assume). For each face, you'll need to have 3 vertices, 3 normals (one for each vertex*), 3 sets of texture coordinates (one for each vertex), and a number indicating what material to use**.

*If you don't have a normal, calculate one for the face and use the same normal for each vertex of the face.

**You'll want to set up a materials table (including a texture pointer) with no duplicates for efficiency's sake.

I'm assuming there are no shared vertices in the data set. That is, each face is comprised of vertices that are not shared with any other face.

The basic outline of creating such a mesh is:
1. create a mesh with the total number of vertices you need to draw the total number of faces.
2. fill the vertex buffer with 3 vertices per face (vertex,normal,tex coords), forming each face in CCW order.
3. fill the index buffer with indices 0,1,2,.. This puts the faces (3 vertices) in the same order as the data table.
4. get the attribute buffer for the mesh.

The attribute buffer is a list of DWORDs, one for each face, that indicates what material to use to draw that face.

5. go through the data table and fill the attribute buffer with a number indicating which material you want to use for each face.
6. optimize the mesh (using D3DXMESHOPT_ATTRSORT at a minimum). You may have to generate an adjacency table first to do the optimization. You can OptimizeInPlace if you want.

Then when you render:

for(DWORD iAttrib = 0; iAttrib < numMaterials; iAttrib++)
{
// Setup the material
D3DXMATERIAL matl = materialsList[iAttrib];
device->SetMaterial.MatD3D;
device->SetTexture(0,<texture[iAttrib]>); // whereever you store the texture pointer for each material group

// Draw the subset
mesh->DrawSubset(iAttrib);
}


Well.. I hope that has something to do which what you're asking about [smile] and you can translate enough of it to use MeshBuilder.

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
First, I'm not familiar with MeshBuilder so you'll have to translate my comments yourself.

However, from the sounds of it, you will have several triangles (call them faces), each of which may have it's own texture, and you want to create a mesh of those faces.

If that's correct, the mesh will need to be comprised of several attribute groups.

An attribute group is a set of faces which have the same material (colors and textures).

Before you go through the steps below, you'll have to create a data table with an entry for each face (to know which faces need which materials). This will come from your map data (I assume). For each face, you'll need to have 3 vertices, 3 normals (one for each vertex*), 3 sets of texture coordinates (one for each vertex), and a number indicating what material to use**.

*If you don't have a normal, calculate one for the face and use the same normal for each vertex of the face.

**You'll want to set up a materials table (including a texture pointer) with no duplicates for efficiency's sake.

I'm assuming there are no shared vertices in the data set. That is, each face is comprised of vertices that are not shared with any other face.

The basic outline of creating such a mesh is:
1. create a mesh with the total number of vertices you need to draw the total number of faces.
2. fill the vertex buffer with 3 vertices per face (vertex,normal,tex coords), forming each face in CCW order.
3. fill the index buffer with indices 0,1,2,.. This puts the faces (3 vertices) in the same order as the data table.
4. get the attribute buffer for the mesh.

The attribute buffer is a list of DWORDs, one for each face, that indicates what material to use to draw that face.

5. go through the data table and fill the attribute buffer with a number indicating which material you want to use for each face.
6. optimize the mesh (using D3DXMESHOPT_ATTRSORT at a minimum). You may have to generate an adjacency table first to do the optimization. You can OptimizeInPlace if you want.

Then when you render:

for(DWORD iAttrib = 0; iAttrib < numMaterials; iAttrib++)
{
// Setup the material
D3DXMATERIAL matl = materialsList[iAttrib];
device->SetMaterial.MatD3D;
device->SetTexture(0,<texture[iAttrib]>); // whereever you store the texture pointer for each material group

// Draw the subset
mesh->DrawSubset(iAttrib);
}


Well.. I hope that has something to do which what you're asking about [smile] and you can translate enough of it to use MeshBuilder.



Thanks a lot, i'll read up on this more later today - even though its in C++ I should be able to work out how its done in XNA.

Thanks :D

Share this post


Link to post
Share on other sites

This topic is 3460 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this