BaseMesh.VertexFormat Property (Microsoft.DirectX.Direct3D)

How Do I...?

  • Clone a Mesh

Retrieves the vertex format that describes the contents of vertices.

Definition

Visual Basic Public ReadOnly Property VertexFormat As VertexFormats
C# public VertexFormats VertexFormat { get; }
C++ public:
property VertexFormats VertexFormat {
        VertexFormats get();
}
JScript public function get VertexFormat() : VertexFormats

Property Value

Microsoft.DirectX.Direct3D.VertexFormats
A VertexFormats object that describes the content of the vertices associated with the mesh.

This property is read-only. 

Remarks

If the vertex format cannot be mapped directly to a flexible vertex format (FVF) code, this method can return 0. This can occur when a mesh created from a vertex declaration does not have the same order and elements as those supported by the FVF codes.

Exceptions

InvalidCallException

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

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