Share via


BaseMesh.Clone(MeshFlags,VertexFormats,Device) Method (Microsoft.DirectX.Direct3D)

How Do I...?

  • Clone a Mesh

Clones, or copies, a mesh object.

Definition

Visual Basic Public Function Clone( _
    ByVal options As MeshFlags, _
    ByVal vertexFormat As VertexFormats, _
    ByVal device As Device _
) As Mesh
C# public Mesh Clone(
    MeshFlags options,
    VertexFormats vertexFormat,
    Device device
);
C++ public:
MeshClone(
    MeshFlags options,
    VertexFormats vertexFormat,
    Devicedevice
);
JScript public function Clone(
    options : MeshFlags,
    vertexFormat : VertexFormats,
    device : Device
) : Mesh;

Parameters

options Microsoft.DirectX.Direct3D.MeshFlags
Mesh creation options, as specified with one or more MeshFlags flags (excepting the Simplify* and Optimize* flags, which should not be used for this purpose).
vertexFormat Microsoft.DirectX.Direct3D.VertexFormats
Mesh vertex format, as specified with one or more VertexFormats flags.
device Microsoft.DirectX.Direct3D.Device
The Device object associated with the mesh.

Return Value

Microsoft.DirectX.Direct3D.Mesh
Cloned mesh.

Remarks

The BaseMesh.Clone method is used to reformat and change the vertex data layout, which it does by creating a new mesh object. For example, the method can be used to add space for normals, texture coordinates, colors, and weights.

The BaseMesh.UpdateSemantics method updates the vertex declaration with new semantic information without changing the layout of the vertex buffer. This method does not modify the contents of the vertex buffer. It can be used, for example, to relabel a 3-D texture coordinate as a binormal or tangent, or vice versa.

Exceptions

InvalidCallException

The method call is invalid. For example, a method's parameter might contain an invalid value.

OutOfMemoryExceptionLeave Site

Microsoft Direct3D could not allocate sufficient memory to complete the call.

How Do I...?

Clone a Mesh

This example shows how to clone a mesh to add space for normals, texture coordinates, colors, weights, etc. that were not originally present.

In the following C# code example, after the mesh is loaded from a file, the Mesh.Clone method is called. The call to pMesh.Clone obtains mesh flags from pMesh, and adds flags for supported VertexFormats and vertex normals.

The original pMesh mesh object is overwritten to contain these additional values. Note that pMesh is disposed before setting to the updated temporary mesh object.

In this example, device is assumed to be the rendering Device.

              [C#]
              

using Microsoft.DirectX.Direct3D;

pMesh = Mesh.FromFile("a_mesh_file.x", MeshFlags.Managed, device);

if ((pMesh.VertexFormat & VertexFormats.Normal) == 0)
{
    Mesh pTempMesh = pMesh.Clone(pMesh.Options.Value,
                                 pMesh.VertexFormat |
                                 VertexFormats.Normal, device);
    pTempMesh.ComputeNormals();
    pMesh.Dispose();
    pMesh = pTempMesh;
}

Applies To

Mesh, ProgressiveMesh

See Also