public bool Compute() { DMesh3 copy = new DMesh3(Mesh); //Frame3f PlaneO = SceneTransforms.SceneToObject(TargetSO, PlaneS); Vector3f PlaneNormal = Plane.GetAxis(nPlaneAxis); MeshPlaneCut cut = new MeshPlaneCut(copy, Plane.Origin, PlaneNormal); cut.Cut(); Loops = new DCurve3[cut.CutLoops.Count]; for (int li = 0; li < cut.CutLoops.Count; ++li) { EdgeLoop edgeloop = cut.CutLoops[li]; DCurve3 loop = MeshUtil.ExtractLoopV(copy, edgeloop.Vertices); // [TODO] collapse degenerate points... if (NormalOffset > 0) { for (int i = 0; i < loop.VertexCount; ++i) { Vector3f n = Vector3f.Zero; if (copy.HasVertexNormals) { n = (Vector3f)copy.GetVertexNormal(edgeloop.Vertices[i]); } else { n = (Vector3f)MeshNormals.QuickCompute(Mesh, edgeloop.Vertices[i]); } n -= n.Dot(PlaneNormal) * PlaneNormal; n.Normalize(); loop[i] += NormalOffset * (Vector3d)n; } } Loops[li] = loop; } return(Loops.Length > 0); }
static GeneralPolygon2d GetPolygonFromMesh(string sPath) { DMesh3 mesh = StandardMeshReader.ReadMesh(sPath); MeshBoundaryLoops loops = new MeshBoundaryLoops(mesh); PlanarComplex complex = new PlanarComplex(); foreach (var loop in loops) { Polygon2d poly = new Polygon2d(); DCurve3 curve = MeshUtil.ExtractLoopV(mesh, loop.Vertices); foreach (Vector3d v in curve.Vertices) { poly.AppendVertex(v.xy); } complex.Add(poly); } PlanarComplex.SolidRegionInfo solids = complex.FindSolidRegions(0.0, false); return(solids.Polygons[0]); }