BaseMesh.ComputeNormals(Int32[]) Method (Microsoft.DirectX.Direct3D)

How Do I...?

  • Clone a Mesh

Computes normals for each vertex in a mesh.

Definition

Visual Basic Public Sub ComputeNormals( _
    ByVal adjacency() As Integer _
)
C# public void ComputeNormals(
    int[] adjacency
);
C++ public:
void ComputeNormals(
    array<int>^ adjacency
);
JScript public function ComputeNormals(
    adjacency : int[]
);

Parameters

adjacency System.Int32[]
Array of three Int32Leave Site values per face, which specify the three neighbors for each face in the mesh.

Remarks

The input mesh must have the VertexFormats.Normal flag specified.

A normal for a vertex is generated by averaging the normals of all faces that share that vertex.

If adjacency is provided, replicated vertices are ignored and smoothed over. If adjacency is not provided, the normals of replicated vertices are averaged only from the faces that explicitly reference them.

Exceptions

InvalidCallException

The method call is invalid. For example, a 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