// Legacy Builder Patch public static void ExtrusionInfo(Brep extrusion, out Brep ftPlanar, out Brep capPlanar, out double height) { Point3d centroid = ComputeCentroid(extrusion); BrepFace ftFace = null; BrepFace capFace = null; Point3d ftCentroid = centroid; Point3d capCentroid = centroid; // Analyze each face. Not the optimal solution for what we need here. foreach (BrepFace bf in extrusion.Faces) { double u, v; bf.ClosestPoint(centroid, out u, out v); Point3d cloestPoint = bf.PointAt(u, v); if (cloestPoint.Z <= ftCentroid.Z) { ftCentroid = cloestPoint; ftFace = bf; } if (cloestPoint.Z >= capCentroid.Z) { capCentroid = cloestPoint; capFace = bf; } } ftPlanar = ftFace.DuplicateFace(true); capPlanar = capFace.DuplicateFace(true); height = Math.Abs(capCentroid.Z - ftCentroid.Z); }
public static bool _Trim(this Surface srf, Curve[] crvs3d, out Brep newBrep, out string fixFailReason) { newBrep = null; fixFailReason = ""; var joins = Curve.JoinCurves(crvs3d, 0.1, true); if (joins.Length != 1) { fixFailReason = "Failed to join {0} edges into loop"._Format(crvs3d.Length); return(false); } var srfBrep = srf.ToBrep(); if (srfBrep.Faces.Count != 1) { fixFailReason = "Failed to convert surface to brep"; return(false); } var b = srf._Split_ThreadSafe(crvs3d, 0.1); if (b == null || b.Faces.Count == 0) { fixFailReason = "Failed to split surface using 3D curves"; return(false); } BrepFace bestFace = b.Faces[0]; double bestMinDist = Double.MaxValue; if (b.Faces.Count > 1) { var centroid = srf._GetCentroid(crvs3d, false); foreach (var f in b.Faces_ThreadSafe()) { if (f.Loops.Count == 1 && f.OuterLoop != null) { var centroidNew = f.OuterLoop._GetCentroid(false); var dist = centroid._DistanceTo(centroidNew); if (dist < bestMinDist) { bestMinDist = dist; bestFace = f; } } } } if (bestFace == null) { fixFailReason = "Failed to extract splited face after splitting 3D curves"; return(false); } newBrep = bestFace.DuplicateFace(true); return(true); }
//Computing Floor Edges private List <Curve> ComputeFloorEdges(BrepFace face) { List <Curve> OuterEdges = new List <Curve>(); int counter = 0; OuterEdges.AddRange(face.DuplicateFace(true).DuplicateEdgeCurves()); counter = OuterEdges.Count; Console.Write("Edge Count = " + counter.ToString()); return(OuterEdges); }
// split face using 3d curves or return null if fail public static Brep _Split_ThreadSafe(this BrepFace face, Curve[] curves, double tol) { using (var faceDUPLICATED = face.DuplicateFace(false)) // must be here to avoid System.AccessViolationException { if (faceDUPLICATED.Faces.Count == 0) { return(null); } var splitedBreps = faceDUPLICATED.Faces[0].Split(curves, tol); return(splitedBreps); } }
public Guid AddFace(BrepFace face, Color color = default(Color)) // , int displayOrder = 0 { if (!IS_ENABLED) { return(Guid.Empty); } //color = DefColor(color); if (color == default(Color)) { color = Color.Coral; } var newBrep = face.DuplicateFace(true); var attr = new ObjectAttributes { LayerIndex = LayerIndex, //Mode = ObjectMode.Locked, - this option will force color to be Gray //DisplayOrder = displayOrder, doesnt work - why? no clue! ObjectColor = color, ColorSource = ObjectColorSource.ColorFromObject }; // Ovveride display mode to color surface http://developer.rhino3d.com/samples/rhinocommon/objectdisplaymode/ DisplayModesManager.ObjectAttributes_SetDisplayModeOverride(attr, DisplayModeType.TopologyColoredSurfaces); Guid id = Doc.Objects.AddBrep(newBrep, attr, null, true); // create mesh if it not created yet var facemesh = face.GetMesh(MeshType.Any); if (facemesh == null || facemesh.Faces.Count == 0) { CreateMesh(id); } return(id); }