internal static global::Topologic.Shell ShellByMesh(Mesh bhomMesh) { List <global::Topologic.Face> faces = new List <global::Topologic.Face>(); foreach (BH.oM.Geometry.Face bhomFace in bhomMesh.Faces) { List <Point> bhomControlPoints = new List <Point>(); Point p1 = bhomMesh.Vertices[bhomFace.A]; bhomControlPoints.Add(p1); Point p2 = bhomMesh.Vertices[bhomFace.B]; bhomControlPoints.Add(p2); Point p3 = bhomMesh.Vertices[bhomFace.C]; bhomControlPoints.Add(p3); Point p4 = null; if (bhomFace.D >= 0) { p4 = bhomMesh.Vertices[bhomFace.D]; bhomControlPoints.Add(p4); } bhomControlPoints.Add(p1); // close the wire Polyline bhomBoundary = new Polyline { ControlPoints = bhomControlPoints }; BH.oM.Geometry.PlanarSurface bhomPlanarSurface = new BH.oM.Geometry.PlanarSurface(bhomBoundary, null); global::Topologic.Face face = Create.FaceByPlanarSurface(bhomPlanarSurface); faces.Add(face); } return(global::Topologic.Shell.ByFaces(faces, 0.0001)); }
/***************************************************/ private static BHG.PlanarSurface ToBHoMPlanarSurface(this RHG.BrepFace face) { RHG.Surface rhSurf = face.UnderlyingSurface(); if (rhSurf == null) { return(null); } BHG.PlanarSurface bhs = rhSurf.FromRhino() as BHG.PlanarSurface; List <BHG.ICurve> internalBoundaries = new List <BHG.ICurve>(); BHG.ICurve externalBoundary = bhs.ExternalBoundary; foreach (RHG.BrepLoop loop in face.Loops) { if (loop.LoopType == RHG.BrepLoopType.Inner) { internalBoundaries.Add(new BHG.PolyCurve { Curves = loop.Trims.Select(x => rhSurf.Pushup(x, BHG.Tolerance.Distance).FromRhino()).ToList() }); } else if (loop.LoopType == RHG.BrepLoopType.Outer) { externalBoundary = new BHG.PolyCurve { Curves = loop.Trims.Select(x => rhSurf.Pushup(x, BHG.Tolerance.Distance).FromRhino()).ToList() } } ; } return(BH.Engine.Geometry.Create.PlanarSurface(externalBoundary, internalBoundaries)); }
internal static global::Topologic.Face FaceBySurface(ISurface bhomSurface) { BH.oM.Geometry.PlanarSurface bhomPlanarSurface = bhomSurface as BH.oM.Geometry.PlanarSurface; if (bhomPlanarSurface != null) { return(FaceByPlanarSurface(bhomPlanarSurface)); } throw new NotImplementedException("This type of BHoM surface is not yet supported."); }
internal static BH.oM.Geometry.PlanarSurface PlanarSurface(global::Topologic.Face face) { Polyline bhomExternalBoundary = Convert.Polyline(face.ExternalBoundary); List <ICurve> bhomInternalBoundaries = new List <ICurve>(); List <global::Topologic.Wire> internalBoundaries = face.InternalBoundaries; foreach (global::Topologic.Wire internalBoundary in internalBoundaries) { bhomInternalBoundaries.Add(Convert.Polyline(internalBoundary)); } BH.oM.Geometry.PlanarSurface planarSurface = new BH.oM.Geometry.PlanarSurface(bhomExternalBoundary, bhomInternalBoundaries); return(planarSurface); }
internal static global::Topologic.Face FaceByPlanarSurface(BH.oM.Geometry.PlanarSurface bhomPlanarSurface) { ICurve bhomExternalBoundary = bhomPlanarSurface.ExternalBoundary; List <ICurve> bhomInternalBoundaries = bhomPlanarSurface.InternalBoundaries; global::Topologic.Wire externalBoundary = Create.WireByCurve(bhomExternalBoundary); List <global::Topologic.Wire> internalBoundaries = new List <global::Topologic.Wire>(); if (bhomInternalBoundaries != null) { foreach (ICurve bhomInternalBoundary in bhomInternalBoundaries) { global::Topologic.Wire internalBoundary = Create.WireByCurve(bhomInternalBoundary); internalBoundaries.Add(internalBoundary); } } return(global::Topologic.Face.ByExternalInternalBoundaries(externalBoundary, internalBoundaries)); }
/***************************************************/ public static RHG.Brep ToRhino(this BHG.PlanarSurface planarSurface) { if (planarSurface == null || planarSurface.ExternalBoundary == null) { return(null); } RHG.Curve externalCurve = planarSurface.ExternalBoundary.IToRhino(); if (externalCurve == null || !externalCurve.IsPlanar(BHG.Tolerance.Distance)) { return(null); } List <RHG.Curve> rhCurves = new List <RHG.Curve>(); if (planarSurface.InternalBoundaries != null) { rhCurves.AddRange(planarSurface.InternalBoundaries.Select(c => c.IToRhino()).Where(c => c.IsPlanar(BHG.Tolerance.Distance)).ToList()); if (rhCurves.Count < planarSurface.InternalBoundaries.Count) { int skipped = planarSurface.InternalBoundaries.Count - rhCurves.Count; Reflection.Compute.RecordWarning($"{skipped} internal boundaries skipped due to a failed planarity test."); } } rhCurves.Add(externalCurve); RHG.Brep[] rhSurfaces = RHG.Brep.CreatePlanarBreps(rhCurves); if (rhSurfaces == null) { return(null); } if (rhSurfaces.Length > 1) { //If more than one surface is extracted, try boolean difference of the curves to generate the geometry List <RHG.Curve> inner = new List <RHG.Curve>(rhCurves); inner.RemoveAt(inner.Count - 1); RHG.Curve[] difference = RHG.Curve.CreateBooleanDifference(externalCurve, inner); //Internal and external edges fully overlap -> 0 edges -> empty Brep if (difference == null || difference.Length == 0) { return(null); } RHG.Brep[] rhSurfacesFromDifference = RHG.Brep.CreatePlanarBreps(difference); if (rhSurfacesFromDifference == null) { return(null); } if (rhSurfacesFromDifference.Length > 1) { Reflection.Compute.RecordWarning("Surface edges are not coplanar or their intersection is not empty." + "The conversion to Rhino results into multiple Breps and only the first brep will be returned."); } else if (rhSurfacesFromDifference.Length == 1) { Reflection.Compute.RecordWarning("The internal edges overlap with the external." + "Boolean intersection has been used to try to get out the correct geometry." + "Topology might have changed for the surface obejct"); return(rhSurfacesFromDifference.FirstOrDefault()); } } return(rhSurfaces.FirstOrDefault()); }
/***************************************************/ public static void RenderMeshes(BHG.PlanarSurface surface, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material) { pipeline.DrawBrepShaded(surface.ToRhino(), material); }
/***************************************************/ public static void RenderWires(BHG.PlanarSurface surface, Rhino.Display.DisplayPipeline pipeline, Color bhColour) { pipeline.DrawBrepWires(surface.ToRhino(), bhColour, 0); }