M.Kumaran
M.Kumaran

Reputation: 883

How to get all Triangles from MeshGeometry3D?

I have a System.Windows.Media.Media3D.MeshGeometry3D object and I need to get all the Triangles from that object like the following.

System.Windows.Media.Media3D.MeshGeometry3D m;
//
// code to generate mesh and assign to 'm'
//
foreach (var t in m.Triangles)  //there is no Triangles property, only TriangleIndices
{
    //t.p1, t.p2, t.p2  --> need all three points of a triangle
}

how can I get all the triangle from the mesh 'm'?

Upvotes: 0

Views: 1806

Answers (1)

Fratyx
Fratyx

Reputation: 5797

You get the triangles from the Position property. Ever consecutive triple of Point3D points in this list represents a triangle. Exception: if TriangleIndices property is set you have to take the triples from this list. Every entry in this triple is an index in the Position list.

So when Position list is P0, P1, P2, P3, P4, P5 you get triangles (P1, P2, P3), (P4, P5, P6).

If additionally TriangleIndices list is 3, 4, 5, 1, 0, 2 you get triangles (P3, P4, P5), (P1, P0, P2). (Px are Point3D structs)

Upvotes: 2

Related Questions