Click or drag to resize
DigitalRuneTriangleMesh Class
Provides a simple ITriangleMesh implementation using vertex and index lists.
Inheritance Hierarchy
SystemObject
  DigitalRune.Geometry.MeshesTriangleMesh

Namespace: DigitalRune.Geometry.Meshes
Assembly: DigitalRune.Geometry (in DigitalRune.Geometry.dll) Version: 1.18.0.0 (1.18.2.14427)
Syntax
[SerializableAttribute]
public sealed class TriangleMesh : ITriangleMesh

The TriangleMesh type exposes the following members.

Constructors
  NameDescription
Public methodTriangleMesh
Initializes a new instance of the TriangleMesh class.
Public methodTriangleMesh(Int32, Int32)
Initializes a new instance of the TriangleMesh class with the specified initial capacity.
Top
Methods
  NameDescription
Public methodAdd(ITriangleMesh)
Adds the triangles of the specified mesh (without vertex welding).
Public methodAdd(Triangle)
Adds the triangle (without vertex welding).
Public methodAdd(ITriangleMesh, Boolean)
Adds the triangles of the specified mesh.
Public methodAdd(Triangle, Boolean)
Adds the triangle.
Public methodAdd(Triangle, Boolean, Single, Boolean)
Adds the triangle.
Public methodClone
Creates a new TriangleMesh that is a copy of the current instance.
Public methodComputeNormals
Computes the mesh normals.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodStatic memberFromModel
Creates a triangle mesh from an XNA Model. (Only available in the XNA-compatible build, except Silverlight.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetTriangle
Gets the triangle with the given index.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodReverseWindingOrder
Changes the winding order of all triangles.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTransform
Transforms all vertices by the given matrix.
Public methodWeldVertices
Removes duplicate vertices.
Public methodCode exampleWeldVertices(Single)
Removes duplicate vertices.
Top
Extension Methods
  NameDescription
Public Extension MethodGetVolume
Gets the enclosed volume of a triangle mesh.
(Defined by GeometryHelper.)
Top
Properties
  NameDescription
Public propertyIndices
Gets or sets the indices.
Public propertyNumberOfTriangles
Gets the number of triangles.
Public propertyTag
Gets or sets custom information.
Public propertyVertices
Gets or sets the vertices.
Top
Remarks

The triangles are defined using a vertex list (see Vertices) and an index list (see Indices). (NumberOfTriangles is Indices.Count / 3. It is allowed to manipulate the vertex and index lists directly, e.g. a triangle can be added by adding 3 indices to Indices.

Vertex welding: The Add(Triangle, Boolean) method and its overloads can be used to add a new triangles to the mesh. These methods can perform brute-force vertex welding to remove duplicate vertices. The brute-force approach is fast if the mesh has only a small number of vertices.

C#
// Building a simple triangle mesh using brute-force vertex welding.
TriangleMesh mesh = new TriangleMesh();

// Add triangles:
mesh.AddTriangle(new Triangle(v0, v1, v2), true);
mesh.AddTriangle(new Triangle(v4, v1, v0), true);
...

But vertex welding using brute-force is slow if there is a large number of vertices. Therefore, when constructing complex meshes the method WeldVertices(Single) should be used. WeldVertices(Single) implements a fast vertex welding algorithm that handles large meshes efficiently. (However, this algorithm is more resource intensive than the brute-force approach.)

C#
// Building a complex triangle mesh using intelligent vertex welding.
TriangleMesh mesh = new TriangleMesh();

// Add triangles:
mesh.AddTriangle(new Triangle(v0, v1, v2), false);
mesh.AddTriangle(new Triangle(v4, v1, v0), false);
...

// After all vertices are added, remove duplicates.
mesh.WeldVertices(0.001f);

See Also