/***************************************************/ public static BHG.SurfaceTrim FromRhino(this RHG.BrepLoop loop) { BHG.PolyCurve curve2d = new BHG.PolyCurve(); BHG.PolyCurve curve3d = new BHG.PolyCurve(); foreach (RHG.BrepTrim trim in loop.Trims) { curve2d.Curves.Add(trim.ToBHoMTrimCurve()); RHG.Curve trim3d = loop.Face.Pushup(trim, BHG.Tolerance.Distance); curve3d.Curves.Add(trim3d.ToBHoMTrimCurve()); } return(new BHG.SurfaceTrim(curve3d, curve2d)); }
/***************************************************/ /**** Private methods ****/ /***************************************************/ private static void AddBrepTrim(this RHG.Brep brep, RHG.BrepFace face, BHG.SurfaceTrim trim, RHG.BrepLoopType loopType) { RHG.BrepLoop loop = brep.Loops.Add(loopType, face); List <BHG.ICurve> subParts3d = trim.Curve3d.ISubParts().ToList(); List <BHG.ICurve> subParts2d = trim.Curve2d.ISubParts().ToList(); double rhinoTolerance = Query.DocumentTolerance(); for (int i = 0; i < subParts3d.Count; i++) { BHG.ICurve bhc = subParts3d[i]; RHG.Curve rhc = bhc.IToRhino(); int startId = brep.AddVertex(rhc.PointAtStart); int endId = brep.AddVertex(rhc.PointAtEnd); RHG.BrepTrim rhTrim; RHG.Curve rhc2d = subParts2d[i].IToRhino(); rhc2d.ChangeDimension(2); int crv2d = brep.Curves2D.Add(rhc2d); if (rhc.IsValid) { bool rev3d = true; RHG.BrepEdge edge = null; foreach (RHG.BrepEdge e in brep.Edges) { if (e.StartVertex.VertexIndex == endId && e.EndVertex.VertexIndex == startId && rhc.IsSameEdge(e)) { edge = e; break; } } if (edge == null) { int crv = brep.Curves3D.Add(rhc); edge = brep.Edges.Add(startId, endId, crv, rhinoTolerance); rev3d = false; } rhTrim = brep.Trims.Add(edge, rev3d, loop, crv2d); } else { rhTrim = brep.Trims.AddSingularTrim(brep.Vertices[startId], loop, RHG.IsoStatus.None, crv2d); } rhTrim.SetTolerances(rhinoTolerance, rhinoTolerance); //TODO: In Rhino 6 this could be replaced with Surface.IsIsoParametric(Curve) RHG.Point3d start = rhc2d.PointAtStart; RHG.Point3d end = rhc2d.PointAtEnd; if (rhc2d.IsLinear()) { if (Math.Abs(start.X - end.X) <= rhinoTolerance) { RHG.Interval domainU = brep.Surfaces[face.SurfaceIndex].Domain(0); if (Math.Abs(start.X - domainU.Min) <= rhinoTolerance) { rhTrim.IsoStatus = RHG.IsoStatus.West; } else if (Math.Abs(start.X - domainU.Max) <= rhinoTolerance) { rhTrim.IsoStatus = RHG.IsoStatus.East; } else { rhTrim.IsoStatus = RHG.IsoStatus.X; } } else if (Math.Abs(start.Y - end.Y) <= rhinoTolerance) { RHG.Interval domainV = brep.Surfaces[face.SurfaceIndex].Domain(1); if (Math.Abs(start.Y - domainV.Min) <= rhinoTolerance) { rhTrim.IsoStatus = RHG.IsoStatus.South; } else if (Math.Abs(start.Y - domainV.Max) <= rhinoTolerance) { rhTrim.IsoStatus = RHG.IsoStatus.North; } else { rhTrim.IsoStatus = RHG.IsoStatus.Y; } } } } }