Example #1
0
        /***************************************************/

        public static BHG.IGeometry FromRhino(this RHG.Extrusion extrusion)
        {
            if (extrusion == null)
            {
                return(null);
            }

            RHG.LineCurve line    = extrusion.PathLineCurve();
            BHG.Vector    extrVec = BH.Engine.Geometry.Create.Vector(line.PointAtStart.FromRhino(), line.PointAtEnd.FromRhino());

            List <BHG.Extrusion> extrs = new List <BHG.Extrusion>();

            // Exploits the fact that GetWireframe returns first the "profile" curves of the extrusion.
            var profileCurves = extrusion.GetWireframe();

            for (int i = 0; i < extrusion.ProfileCount; i++)
            {
                var           profileConverted = profileCurves.ElementAt(i).FromRhino();
                BHG.Extrusion extr             = BH.Engine.Geometry.Create.Extrusion(profileConverted, extrVec, extrusion.IsCappedAtBottom && extrusion.IsCappedAtTop);

                extrs.Add(extr);
            }


            if (extrs.Count == 1)
            {
                return(extrs[0]);
            }

            if (extrs.Count > 1)
            {
                return new BH.oM.Geometry.CompositeGeometry()
                       {
                           Elements = extrs.OfType <BH.oM.Geometry.IGeometry>().ToList()
                       }
            }
            ;

            BH.Engine.Reflection.Compute.RecordError("Could not convert the extrusion.");
            return(null);
        }
Example #2
0
        /***************************************************/

        public static Rhino.Geometry.Surface ToRhino(this BHG.Extrusion extrusion)
        {
            if (!extrusion.Curve.IIsPlanar())
            {
                BH.Engine.Reflection.Compute.RecordError("The provided BHoM Extrusion has a base curve that is not planar.");
                return(null);
            }

            var planarCurve = extrusion.Curve.IToRhino();

            RHG.Plane curvePlane;
            planarCurve.TryGetPlane(out curvePlane);

            double angle = RHG.Vector3d.VectorAngle(curvePlane.Normal, extrusion.Direction.ToRhino());

            double tolerance = 0.001;

            if (angle < tolerance || (2 * Math.PI - tolerance < angle && angle < 2 * Math.PI + tolerance))
            {
                // It can be represented by a Rhino extrusion (which enforces perpendicularity btw Curve plane and Vector)

                double extrHeight = extrusion.Direction.Length();

                if (angle > Math.PI)
                {
                    extrHeight = -extrHeight;
                }

                RHG.Extrusion extr = Rhino.Geometry.Extrusion.Create(planarCurve, extrHeight, extrusion.Capped);

                return(extr);
            }

            // Otherwise, provide a Sweep to cover extrusion with a base curve that is not orthogonal to the extr direction

            // Create a Line to be the sweep rail. Use centroid/mid-point of base curve as start point.
            RHG.Point3d centrePoint;
            if (planarCurve.IsClosed)
            {
                var areaProp = Rhino.Geometry.AreaMassProperties.Compute(planarCurve);
                centrePoint = areaProp.Centroid;
            }
            else
            {
                centrePoint = planarCurve.PointAt(0.5);
            }

            RHG.Point3d endPoint = centrePoint + extrusion.Direction.ToRhino();
            var         rail     = new RHG.LineCurve(centrePoint, endPoint);

            var joinedSweep = new RHG.SweepOneRail()
                              .PerformSweep(rail, planarCurve)
                              .Aggregate((b1, b2) => { b1.Join(b2, tolerance, true); return(b1); });

            if (joinedSweep.IsSurface)
            {
                return(joinedSweep.Surfaces[0]);
            }

            BH.Engine.Reflection.Compute.RecordError("Could not convert this BHoM Extrusion to a Rhino Surface. The extrusion direction is not perpendicular to the base curve, and the base curve is too complex for a Sweep to return a valid Surface.");


            return(null);
        }
Example #3
0
        /***************************************************/
        /**** Public Methods  - Surfaces                ****/
        /***************************************************/

        public static void RenderMeshes(BHG.Extrusion surface, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material)
        {
            pipeline.DrawBrepShaded(RHG.Brep.CreateFromSurface(surface.ToRhino()), material);
        }
Example #4
0
        /***************************************************/
        /**** Public Methods  - Surfaces                ****/
        /***************************************************/

        public static void RenderWires(BHG.Extrusion surface, Rhino.Display.DisplayPipeline pipeline, Color bhColour)
        {
            RHG.Surface rSurface = surface.ToRhino();
            pipeline.DrawSurface(rSurface, bhColour, 2);
        }