Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MeshBuilder Class

Bb197972.note(en-us,XNAGameStudio.31).gifNote
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.

    Bb197972.note(en-us,XNAGameStudio.31).gifNote
    The PositionCollection property of a MeshContent object is created automatically. Therefore, 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.

    Bb197972.note(en-us,XNAGameStudio.31).gifNote
    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 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.

Windows XP SP2, Windows Vista

Community Additions

Show:
© 2014 Microsoft