How to Triangulate() Not-Planar Faces

How to Triangulate() Not-Planar Faces

ankofl
Advocate Advocate
333 Views
2 Replies
Message 1 of 3

How to Triangulate() Not-Planar Faces

ankofl
Advocate
Advocate

I have a method that creates a triangulated solid mesh based on Solid, but it only works with PlanarFace.

 

public static bool CreateMesh(this Solid solid, out List<XYZ> listVectors, out List<Tri> listTri)
{
	double k = UnitUtils.ConvertFromInternalUnits(1, UnitTypeId.Meters);
	listVectors = [];
	listTri = [];

	bool allPlanar = true;

	int indV = 0;
	foreach (Face face in solid.Faces)
	{
		if (face is PlanarFace pFace)
		{
			Mesh mesh = pFace.Triangulate();
			for (int tN = 0; tN < mesh.NumTriangles; tN++)
			{
				var tri = mesh.get_Triangle(tN);

				var pT = new int[3];

				for (int vN = 0; vN < 3; vN++)
				{
					var p = tri.get_Vertex(vN) * k;

					if (p.Contain(listVectors, out XYZ pF, out int index))
					{
						pT[vN] = index;
					}
					else
					{
						pT[vN] = indV;
						listVectors.Add(p);
						indV++;
					}
				}

				listTri.Add(new(pT[2], pT[1], pT[0]));
			}
		}
		else
		{
			allPlanar = false;
			break;
		}
	}

	return allPlanar;
}

 

 Is there a way to get a triangulated surface from a Face that is not a PlanarFace?

0 Likes
Accepted solutions (1)
334 Views
2 Replies
Replies (2)
Message 2 of 3

ricaun
Advisor
Advisor
Accepted solution

What do you mean with 'it only works with PlanarFace' ?

 

The Triangulate method is from the Face class, all faces can be triangulate to a Mesh.

 

You can replace in your code the PlanarFace to Face and should work.

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 3 of 3

ankofl
Advocate
Advocate

I feel pretty stupid, it seems about a year ago I added this check to PlanarFace to get it Normal() so that I could then perform the extrusion, but after a while I apparently forgot that the restriction only applies to Normal() and Triangulate() works correctly in both cases.

 

Funny, thing is, it was so long ago that I was getting Solid without Non-PlanarFaces and then filling the holes through CGAL.

 

Thanks for the reply)

0 Likes