Exemple #1
0
        /***************************************************/

        public static BHG.ISurface FromRhino(this RHG.NurbsSurface surface)
        {
            if (surface == null)
            {
                return(null);
            }

            if (surface.IsPlanar(BH.oM.Geometry.Tolerance.Distance))
            {
                BHG.ICurve externalEdge = RHG.Curve.JoinCurves(surface.ToBrep().DuplicateNakedEdgeCurves(true, false)).FirstOrDefault().FromRhino();
                return(new BHG.PlanarSurface(externalEdge, new List <BHG.ICurve>()));
            }

            BHG.NurbsSurface bhs = new BHG.NurbsSurface
                                   (
                surface.Points.Select(x => x.Location.FromRhino()).ToList(),
                surface.Points.Select(x => x.Weight).ToList(),
                surface.KnotsU.ToList(),
                surface.KnotsV.ToList(),
                surface.Degree(0),
                surface.Degree(1),
                new List <BHG.SurfaceTrim>(),
                new List <BHG.SurfaceTrim>()
                                   );

            return(bhs);
        }
        /***************************************************/

        public static void RenderMeshes(BHG.NurbsSurface surface, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material)
        {
            RHG.GeometryBase geometry = surface.ToRhino();
            if (geometry is RHG.Surface)
            {
                geometry = RHG.Brep.CreateFromSurface((RHG.Surface)geometry);
            }

            pipeline.DrawBrepShaded((RHG.Brep)geometry, material);
        }
        /***************************************************/

        public static void RenderWires(BHG.NurbsSurface surface, Rhino.Display.DisplayPipeline pipeline, Color bhColour)
        {
            RHG.GeometryBase geometry = surface.ToRhino();
            if (geometry is RHG.Surface)
            {
                geometry = RHG.Brep.CreateFromSurface((RHG.Surface)geometry);
            }

            pipeline.DrawBrepWires((RHG.Brep)geometry, bhColour, 2);
        }
Exemple #4
0
        /***************************************************/

        public static RHG.GeometryBase ToRhino(this BHG.NurbsSurface surface)
        {
            if (surface == null)
            {
                return(null);
            }

            List <int> uvCount = surface.UVCount();

            RHG.NurbsSurface rhSurface = RHG.NurbsSurface.Create(3, true, surface.UDegree + 1, surface.VDegree + 1, uvCount[0], uvCount[1]);
            for (int i = 0; i < rhSurface.KnotsU.Count; i++)
            {
                rhSurface.KnotsU[i] = surface.UKnots[i];
            }
            for (int i = 0; i < rhSurface.KnotsV.Count; i++)
            {
                rhSurface.KnotsV[i] = surface.VKnots[i];
            }
            for (int i = 0; i < uvCount[0]; i++)
            {
                for (int j = 0; j < uvCount[1]; j++)
                {
                    rhSurface.Points.SetControlPoint(i, j, new RHG.ControlPoint(surface.ControlPoints[j + (uvCount[1] * i)].ToRhino(), surface.Weights[j + (uvCount[1] * i)]));
                }
            }

            if (!rhSurface.IsValid)
            {
                return(null);
            }

            if (surface.OuterTrims.Count == 0 && surface.InnerTrims.Count == 0)
            {
                return(rhSurface);
            }
            else
            {
                RHG.Brep     brep = new RHG.Brep();
                int          srf  = brep.AddSurface(rhSurface);
                RHG.BrepFace face = brep.Faces.Add(srf);

                foreach (BHG.SurfaceTrim trim in surface.OuterTrims)
                {
                    brep.AddBrepTrim(face, trim, RHG.BrepLoopType.Outer);
                }

                foreach (BHG.SurfaceTrim trim in surface.InnerTrims)
                {
                    brep.AddBrepTrim(face, trim, RHG.BrepLoopType.Inner);
                }

                return(brep.IsValid ? brep : null);
            }
        }