Assembly: Microsoft.Xna.Framework.Content.Pipeline (in microsoft.xna.framework.content.pipeline.dll)
MeshBuilder is designed to make it easier to write importers. It creates an abstraction of the internal workings of the MeshContent, and GeometryContent classes and provides a simple way to create a mesh object.
There are three steps to creating a mesh.
Call StartMesh to get a MeshBuilder object. To initialize this object, fill the positions buffer with data by using the CreatePosition function. After retrieving the positions data, call the CreateVertexChannel generic function to specify the types of vertex channels needed—for example, normals, UVs, and color channels.
After setting up the position and vertex data channel buffers, begin creating triangles. Use SetMaterial and SetOpaqueData to set the data of each triangle, and use SetVertexChannelData to set the individual vertex data of each triangle. After setting this data, call AddTriangleVertex for each vertex of each triangle.
- In the final step, call FinishMesh. After this call, the mesh is optimized automatically with calls to MergeDuplicateVertices and CalculateNormals.
For a complete example of this procedure, download the Generated Geometry Sample from the Creators Club Online website and load the solution. Open the TerrainProcessor.cs file and examine the
Process method. This method implements the steps listed above.