public Geometry.Surface SurfaceToSpeckle(AC.NurbSurface surface)
        {
            List <double> Uknots = new List <double>();
            List <double> Vknots = new List <double>();

            foreach (var knot in surface.UKnots)
            {
                Uknots.Add((double)knot);
            }
            foreach (var knot in surface.VKnots)
            {
                Vknots.Add((double)knot);
            }

            var _surface = new Geometry.Surface
            {
                degreeU  = surface.DegreeInU,
                degreeV  = surface.DegreeInV,
                rational = surface.IsRationalInU && surface.IsRationalInV,
                closedU  = surface.IsClosedInU(),
                closedV  = surface.IsClosedInV(),
                domainU  = IntervalToSpeckle(surface.GetEnvelope()[0]),
                domainV  = IntervalToSpeckle(surface.GetEnvelope()[1]),
                knotsU   = Uknots,
                knotsV   = Vknots
            };

            _surface.units = ModelUnits;
            _surface.SetControlPoints(ControlPointsToSpeckle(surface.ControlPoints, surface.Weights));
            return(_surface);
        }
Пример #2
0
        /// <summary>
        /// Constructs a Rhino_DotNet OnSurface that is a copy of a given curve.
        /// </summary>
        /// <param name="source">A source brep.</param>
        /// <returns>
        /// Rhino_DotNet object on success. This will be an independent copy.
        /// </returns>
        /// <since>5.0</since>
        public static object ToOnSurface(Geometry.Surface source)
        {
            object rc = null;
            IntPtr const_ptr_source = source.ConstPointer();
            Type   on_type          = GetRhinoDotNetType("RMA.OpenNURBS.OnSurface");

            if (IntPtr.Zero != const_ptr_source && null != on_type)
            {
                System.Reflection.MethodInfo mi = on_type.GetMethod("WrapNativePointer", new[] { typeof(IntPtr), typeof(bool), typeof(bool) });
                IntPtr ptr_new_surface          = UnsafeNativeMethods.ON_Surface_DuplicateSurface(const_ptr_source);
                rc = mi.Invoke(null, new object[] { ptr_new_surface, false, true });
            }
            return(rc);
        }
Пример #3
0
        private string CreateMassFamily(string famPath, Geometry.Surface surface, string name)
        {
            var famDoc = Doc.Application.NewFamilyDocument(famPath);

            using (Transaction t = new Transaction(famDoc, "Create Mass"))
            {
                t.Start();

                try
                {
                    var pointLists = surface.GetControlPoints();
                    var curveArray = new ReferenceArrayArray();

                    foreach (var list in pointLists)
                    {
                        var arr = new ReferencePointArray();
                        foreach (var point in list)
                        {
                            var refPt = famDoc.FamilyCreate.NewReferencePoint(PointToNative(point));
                            arr.Append(refPt);
                        }

                        var curve          = famDoc.FamilyCreate.NewCurveByPoints(arr);
                        var referenceArray = new ReferenceArray();
                        referenceArray.Append(curve.GeometryCurve.Reference);
                        curveArray.Append(referenceArray);
                    }

                    var loft = famDoc.FamilyCreate.NewLoftForm(true, curveArray);
                }
                catch (Exception e)
                {
                }

                t.Commit();
            }
            var           famName        = "SpeckleMass_" + name;
            string        tempFamilyPath = Path.Combine(Path.GetTempPath(), famName + ".rfa");
            SaveAsOptions so             = new SaveAsOptions();

            so.OverwriteExistingFile = true;
            famDoc.SaveAs(tempFamilyPath, so);
            famDoc.Close();

            return(tempFamilyPath);
        }
        public AC.NurbSurface SurfaceToNative(Geometry.Surface surface)
        {
            // Get control points
            var points = surface.GetControlPoints().Select(l => l.Select(p =>
                                                                         new ControlPoint(
                                                                             ScaleToNative(p.x, p.units),
                                                                             ScaleToNative(p.y, p.units),
                                                                             ScaleToNative(p.z, p.units),
                                                                             p.weight,
                                                                             p.units)).ToList()).ToList();

            var _surface = AC.NurbSurface.Create(new IntPtr(), true); // check what new unmanaged pointer does!!

            // Set control points
            Point3dCollection controlPoints = new Point3dCollection();
            DoubleCollection  weights       = new DoubleCollection();

            for (var i = 0; i < points.Count; i++)
            {
                for (var j = 0; j < points[i].Count; j++)
                {
                    var pt = points[i][j];
                    controlPoints.Add(PointToNative(pt));
                    weights.Add(pt.weight);
                }
            }

            // Get knot vectors
            KnotCollection UKnots = new KnotCollection();
            KnotCollection VKnots = new KnotCollection();

            for (int i = 0; i < surface.knotsU.Count; i++)
            {
                UKnots.Add(surface.knotsU[i]);
            }
            for (int i = 0; i < surface.knotsV.Count; i++)
            {
                VKnots.Add(surface.knotsV[i]);
            }

            // Set surface info
            _surface.Set(surface.degreeU, surface.degreeV, 0, 0, surface.countU, surface.countV, controlPoints, weights, UKnots, VKnots);

            return(_surface);
        }
        public NurbsSurface SurfaceToNative(Geometry.Surface surface)
        {
            // Create rhino surface
            var points = surface.GetControlPoints().Select(l => l.Select(p =>
                                                                         new ControlPoint(
                                                                             ScaleToNative(p.x, p.units),
                                                                             ScaleToNative(p.y, p.units),
                                                                             ScaleToNative(p.z, p.units),
                                                                             p.weight,
                                                                             p.units)).ToList()).ToList();

            var result = NurbsSurface.Create(3, surface.rational, surface.degreeU + 1, surface.degreeV + 1,
                                             points.Count, points[0].Count);

            // Set knot vectors
            var correctUKnots = GetCorrectKnots(surface.knotsU, surface.countU, surface.degreeU);

            for (int i = 0; i < correctUKnots.Count; i++)
            {
                result.KnotsU[i] = correctUKnots[i];
            }
            var correctVKnots = GetCorrectKnots(surface.knotsV, surface.countV, surface.degreeV);

            for (int i = 0; i < correctVKnots.Count; i++)
            {
                result.KnotsV[i] = correctVKnots[i];
            }

            // Set control points
            for (var i = 0; i < points.Count; i++)
            {
                for (var j = 0; j < points[i].Count; j++)
                {
                    var pt = points[i][j];
                    result.Points.SetPoint(i, j, pt.x * pt.weight, pt.y * pt.weight, pt.z * pt.weight);
                    result.Points.SetWeight(i, j, pt.weight);
                }
            }

            // Return surface
            return(result);
        }
        public Geometry.Surface SurfaceToSpeckle(NurbsSurface surface)
        {
            var result = new Geometry.Surface
            {
                degreeU  = surface.OrderU - 1,
                degreeV  = surface.OrderV - 1,
                rational = surface.IsRational,
                closedU  = surface.IsClosed(0),
                closedV  = surface.IsClosed(1),
                domainU  = IntervalToSpeckle(surface.Domain(0)),
                domainV  = IntervalToSpeckle(surface.Domain(1)),
                knotsU   = surface.KnotsU.ToList(),
                knotsV   = surface.KnotsV.ToList()
            };

            result.units = ModelUnits;

            result.SetControlPoints(ControlPointsToSpeckle(surface.Points));
            return(result);
        }
        public Geometry.Surface SurfaceToSpeckle(NurbsSurface surface, string units = null)
        {
            var u      = units ?? ModelUnits;
            var result = new Geometry.Surface
            {
                degreeU  = surface.OrderU - 1,
                degreeV  = surface.OrderV - 1,
                rational = surface.IsRational,
                closedU  = surface.IsClosed(0),
                closedV  = surface.IsClosed(1),
                domainU  = IntervalToSpeckle(surface.Domain(0)),
                domainV  = IntervalToSpeckle(surface.Domain(1)),
                knotsU   = surface.KnotsU.ToList(),
                knotsV   = surface.KnotsV.ToList()
            };

            result.units = u;

            result.SetControlPoints(ControlPointsToSpeckle(surface.Points));
            result.bbox = BoxToSpeckle(new RH.Box(surface.GetBoundingBox(true)), u);

            return(result);
        }