Export (0) Print
Expand All

MeshBuilder Class

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.40).gifNote
    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.

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

Build content in XNA Game Studio for Windows Phone 7, Xbox 360, Windows 7, Windows Vista, and Windows XP.

Community Additions

ADD
Show:
© 2015 Microsoft