MeshBuilder Class


This class is available only when developing for Windows.

Provides support for writing a custom importer for mesh objects.

Namespace: Microsoft.Xna.Framework.Content.Pipeline.Graphics
Assembly: Microsoft.Xna.Framework.Content.Pipeline (in microsoft.xna.framework.content.pipeline.dll)


public sealed class MeshBuilder


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.

  1. 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.


    The PositionCollection property of a MeshContent object is created automatically. There is no need to explicitly declare a VertexChannel object for positions.

  2. 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.


    If you call CreatePosition or CreateVertexChannel after calling AddTriangleVertex, an InvalidOperationException exception is thrown.

  3. 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 App Hub website and load the solution. Open the TerrainProcessor.cs file and examine the Process method. This method implements the steps listed above.

See Also



MeshBuilder Members
Microsoft.Xna.Framework.Content.Pipeline.Graphics Namespace


Windows 7, Windows Vista, Windows XP