Mesh.Mesh Constructor |
Language: |
Creates a new Mesh instance.
Visual Basic Public Sub New( _
ByVal numFaces As Integer, _
ByVal numVertices As Integer, _
ByVal options As MeshFlags, _
ByVal declaration() As VertexElement, _
ByVal device As Device _
)C# public Mesh(
int numFaces,
int numVertices,
MeshFlags options,
VertexElement[] declaration,
Device device
);C++ public:
Mesh(
int numFaces,
int numVertices,
MeshFlags options,
array<VertexElement>^ declaration,
Device^ device
);JScript public function Mesh(
numFaces : int,
numVertices : int,
options : MeshFlags,
declaration : VertexElement[],
device : Device
);
numFaces System.Int32
Number of faces for the mesh. The valid range is greater than 0 and one less than the maximum Int32 (typically 65534), because the last index is reserved.numVertices System.Int32
Number of vertices for the mesh. This parameter must be greater than 0.options Microsoft.DirectX.Direct3D.MeshFlags
One or more flags from the MeshFlags enumeration that specify creation options for the mesh (excepting the Simplify* and Optimize* flags).declaration Microsoft.DirectX.Direct3D.VertexElement[]
An array of VertexElement objects, that describes the vertex format for the returned mesh. This parameter must map directly to a flexible vertex format (FVF).device Microsoft.DirectX.Direct3D.Device
A Device object that represents the device associated with the mesh.
Exceptions
InvalidCallException The method call is invalid. For example, a method's parameter might contain an invalid value. OutOfMemoryException Microsoft Direct3D could not allocate sufficient memory to complete the call.
Create a Mesh Object
This example shows how to create a Mesh object.
In the following C# code example, device is assumed to be the rendering Device.
[C#]
int numberVerts = 8; short[] indices = { 0,1,2, // Front Face 1,3,2, // Front Face 4,5,6, // Back Face 6,5,7, // Back Face 0,5,4, // Top Face 0,2,5, // Top Face 1,6,7, // Bottom Face 1,7,3, // Bottom Face 0,6,1, // Left Face 4,6,0, // Left Face 2,3,7, // Right Face 5,2,7 // Right Face }; Mesh mesh = new Mesh(numberVerts * 3, numberVerts, MeshFlags.Managed, CustomVertex.PositionColored.Format, device); using(VertexBuffer vb = mesh.VertexBuffer) { GraphicsStream data = vb.Lock(0, 0, LockFlags.None); data.Write(new CustomVertex.PositionColored(-1.0f, 1.0f, 1.0f, 0x00ff00ff)); data.Write(new CustomVertex.PositionColored(-1.0f, -1.0f, 1.0f, 0x00ff00ff)); data.Write(new CustomVertex.PositionColored(1.0f, 1.0f, 1.0f, 0x00ff00ff)); data.Write(new CustomVertex.PositionColored(1.0f, -1.0f, 1.0f, 0x00ff00ff)); data.Write(new CustomVertex.PositionColored(-1.0f, 1.0f, -1.0f, 0x00ff00ff)); data.Write(new CustomVertex.PositionColored(1.0f, 1.0f, -1.0f, 0x00ff00ff)); data.Write(new CustomVertex.PositionColored(-1.0f, -1.0f, -1.0f, 0x00ff00ff)); data.Write(new CustomVertex.PositionColored(1.0f, -1.0f, -1.0f, 0x00ff00ff)); vb.Unlock(); } using (IndexBuffer ib = mesh.IndexBuffer) { ib.SetData(indices, 0, LockFlags.None); }
Send comments about this topic to Microsoft. © Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center