/***************************************************/ /**** Public Methods - Interfaces ****/ /***************************************************/ public static void IRenderWires(this BHG.IGeometry geometry, GH_PreviewWireArgs args) { if (geometry == null) { return; } Color bhColour = RenderColour(args.Color, Color.FromArgb(80, 255, 41, 105));//BHoM pink! try { RenderWires(geometry as dynamic, args.Pipeline, bhColour); } catch (Exception) { } }
/***************************************************/ /**** Fallback Methods ****/ /***************************************************/ public static BHG.IGeometry FromRhino(this object obj) { BHG.IGeometry geom = obj as BHG.IGeometry; if (geom != null) { return(geom); } if (obj != null) { Engine.Reflection.Compute.RecordError($"No conversion could be found between {obj.GetType().IToText()} and Rhino geometry."); } return(null); }
/***************************************************/ /**** Public Methods - Interfaces ****/ /***************************************************/ public static void IRenderMeshes(this BHG.IGeometry geometry, GH_PreviewMeshArgs args) { if (geometry == null) { return; } else if (!(geometry is BHG.ISurface) & !(geometry is BHG.Mesh)) { return; } DisplayMaterial bhMaterial = RenderMaterial(args.Material, Color.FromArgb(80, 255, 41, 105));//BHoM pink! try { RenderMeshes(geometry as dynamic, args.Pipeline, bhMaterial); } catch (Exception) { } }
public static global::Topologic.Topology TopologyByGeometry(BH.oM.Geometry.IGeometry geometry, double tolerance = 0.0001) { BH.oM.Geometry.Point bhomPoint = geometry as BH.oM.Geometry.Point; if (bhomPoint != null) { return(Create.VertexByPoint(bhomPoint)); } // Handle polyline and polycurve first BH.oM.Geometry.Polyline bhomPolyline = geometry as BH.oM.Geometry.Polyline; if (bhomPolyline != null) { if (bhomPolyline.ControlPoints.Count < 2) { throw new Exception("An invalid polyline with fewer than 2 control points is given."); } else if (bhomPolyline.ControlPoints.Count == 2) { BH.oM.Geometry.Line bhomLine = BH.Engine.Geometry.Create.Line(bhomPolyline.ControlPoints[0], bhomPolyline.ControlPoints[1]); return(Create.EdgeByLine(bhomLine)); } else { return(Create.WireByPolyLine(bhomPolyline)); } } BH.oM.Geometry.PolyCurve bhomPolyCurve = geometry as BH.oM.Geometry.PolyCurve; if (bhomPolyCurve != null) { if (bhomPolyCurve.Curves.Count == 0) { throw new Exception("An invalid polycurve with no curve is given."); } else if (bhomPolyCurve.Curves.Count == 1) { BH.oM.Geometry.ICurve bhomACurve = bhomPolyCurve.Curves[0]; return(Create.EdgeByCurve(bhomACurve)); } else { return(Create.WireByPolyCurve(bhomPolyCurve)); } } // Then curve BH.oM.Geometry.ICurve bhomCurve = geometry as BH.oM.Geometry.ICurve; if (bhomCurve != null) { return(Create.EdgeByCurve(bhomCurve)); } // Do polysurface first. BH.oM.Geometry.PolySurface bhomPolySurface = geometry as BH.oM.Geometry.PolySurface; if (bhomPolySurface != null) { return(Create.ShellByPolySurface(bhomPolySurface, tolerance)); } // Then surface BH.oM.Geometry.ISurface bhomSurface = geometry as BH.oM.Geometry.ISurface; if (bhomSurface != null) { return(Create.FaceBySurface(bhomSurface)); } BH.oM.Geometry.ISolid bhomSolid = geometry as BH.oM.Geometry.ISolid; if (bhomSolid != null) { return(Create.CellBySolid(bhomSolid, tolerance)); } BH.oM.Geometry.BoundingBox bhomBoundingBox = geometry as BH.oM.Geometry.BoundingBox; if (bhomBoundingBox != null) { return(Create.CellByBoundingBox(bhomBoundingBox)); } BH.oM.Geometry.CompositeGeometry bhomCompositeGeometry = geometry as BH.oM.Geometry.CompositeGeometry; if (bhomCompositeGeometry != null) { return(Create.ClusterByCompositeGeometry(bhomCompositeGeometry, tolerance)); } BH.oM.Geometry.Mesh bhomMesh = geometry as BH.oM.Geometry.Mesh; if (bhomMesh != null) { return(Create.TopologyByMesh(bhomMesh)); } throw new NotImplementedException("This BHoM geometry is not yet supported."); }
/***************************************************/ /**** Public Methods - Interfaces ****/ /***************************************************/ public static object IToRhino(this BHG.IGeometry geometry) { return((geometry == default(BHG.IGeometry)) ? null : Convert.ToRhino(geometry as dynamic)); }