public static SpeckleObject ToSpeckle(this Curve curve)
        {
            var properties = curve.UserDictionary.ToSpeckle();

            if (curve is PolyCurve)
            {
                return((( PolyCurve )curve).ToSpeckle());
            }

            if (curve.IsArc())
            {
                Arc        getObj; curve.TryGetArc(out getObj);
                SpeckleArc myObject = getObj.ToSpeckle(); myObject.Properties = properties;
                return(myObject);
            }

            if (curve.IsCircle())
            {
                Circle        getObj; curve.TryGetCircle(out getObj);
                SpeckleCircle myObject = getObj.ToSpeckle(); myObject.Properties = properties;
                return(myObject);
            }

            if (curve.IsEllipse())
            {
                Ellipse        getObj; curve.TryGetEllipse(out getObj);
                SpeckleEllipse myObject = getObj.ToSpeckle(); myObject.Properties = properties;
                return(myObject);
            }

            if (curve.IsLinear() || curve.IsPolyline()) // defaults to polyline
            {
                Polyline        getObj; curve.TryGetPolyline(out getObj);
                SpecklePolyline myObject = getObj.ToSpeckle(); myObject.Properties = properties;
                return(myObject);
            }

            Polyline poly;

            curve.ToPolyline(0, 1, 0, 0, 0, 0.1, 0, 0, true).TryGetPolyline(out poly);

            SpeckleCurve myCurve    = new SpeckleCurve(poly.ToSpeckle(), properties: curve.UserDictionary.ToSpeckle());
            NurbsCurve   nurbsCurve = curve.ToNurbsCurve();


            myCurve.Weights  = nurbsCurve.Points.Select(ctp => ctp.Weight).ToArray();
            myCurve.Points   = nurbsCurve.Points.Select(ctp => ctp.Location).ToFlatArray();
            myCurve.Knots    = nurbsCurve.Knots.ToArray();
            myCurve.Degree   = nurbsCurve.Degree;
            myCurve.Periodic = nurbsCurve.IsPeriodic;
            myCurve.Rational = nurbsCurve.IsRational;
            myCurve.Domain   = nurbsCurve.Domain.ToSpeckle();

            myCurve.Properties = properties;
            return(myCurve);
        }
        public static NurbsCurve ToNative(this SpeckleCurve curve)
        {
            var ptsList = curve.Points.ToPoints();

            if (!curve.Periodic)
            {
                // Bug/feature in Rhino sdk: creating a periodic curve adds two extra stupid points?
                var myCurve = NurbsCurve.Create(curve.Periodic, curve.Degree, ptsList);

                if (curve.Domain != null)
                {
                    myCurve.Domain = curve.Domain.ToNative();
                }

                // set weights
                for (int i = 0; i < ptsList.Length; i++)
                {
                    myCurve.Points.SetPoint(i, ptsList[i].X * curve.Weights[i], ptsList[i].Y * curve.Weights[i], ptsList[i].Z * curve.Weights[i], curve.Weights[i]);
                }

#if R6
                // set knots
                for (int i = 0; i < curve.Knots.Count; i++)
                {
                    myCurve.Knots[i] = curve.Knots[i];
                }
#endif

                myCurve.UserDictionary.ReplaceContentsWith(curve.Properties.ToNative());
                return(myCurve);
            }
            else
            {
                var thePts  = ptsList.Take(ptsList.Length - 3).ToArray();
                var myCurve = NurbsCurve.Create(curve.Periodic, curve.Degree, thePts);

                // set weights
                for (int i = 0; i < ptsList.Length; i++)
                {
                    myCurve.Points.SetPoint(i, ptsList[i].X * curve.Weights[i], ptsList[i].Y * curve.Weights[i], ptsList[i].Z * curve.Weights[i], curve.Weights[i]);
                }

#if R6
                // set knots
                for (int i = 0; i < curve.Knots.Count; i++)
                {
                    myCurve.Knots[i] = curve.Knots[i];
                }
#endif

                myCurve.Domain = curve.Domain.ToNative();
                return(myCurve);
            }
        }
Example #3
0
        public static SpeckleObject ToSpeckle(this NurbsCurve curve)
        {
            SpeckleObject speckleCurve;

            if (curve.IsLinear())
            {
                using (Line line = curve.GetAsLine()) { speckleCurve = line.ToSpeckle(); }
            }
            else if (curve.IsArc())
            {
                using (Arc arc = curve.GetAsArc()) { speckleCurve = arc.ToSpeckle(); }
            }
            else if (curve.IsCircle())
            {
                using (Circle circle = curve.GetAsCircle()) { speckleCurve = circle.ToSpeckle(); }
            }
            else if (curve.IsEllipse())
            {
                using (Ellipse ellipse = curve.GetAsEllipse()) { speckleCurve = ellipse.ToSpeckle(); }
            }
            else
            {
                // SpeckleCurve DisplayValue
                Curve[]       curves = curve.ApproximateWithArcAndLineSegments();
                List <double> polylineCoordinates = curves.SelectMany(c => new Point[2] {
                    c.StartPoint, c.EndPoint
                }.ToFlatArray()).ToList();
                polylineCoordinates.AddRange(curves.Last().EndPoint.ToArray());
                curves.ForEach(c => c.Dispose());

                SpecklePolyline displayValue = new SpecklePolyline(polylineCoordinates);
                List <double>   dsKnots      = curve.Knots().ToList();
                dsKnots.RemoveAt(dsKnots.Count - 1);
                dsKnots.RemoveAt(0);

                SpeckleCurve spkCurve = new SpeckleCurve(displayValue);
                spkCurve.Weights  = curve.Weights().ToList();
                spkCurve.Points   = curve.ControlPoints().ToFlatArray().ToList();
                spkCurve.Knots    = dsKnots;
                spkCurve.Degree   = curve.Degree;
                spkCurve.Periodic = curve.IsPeriodic;
                spkCurve.Rational = curve.IsRational;
                spkCurve.Closed   = curve.IsClosed;
                spkCurve.Domain   = new SpeckleInterval(curve.StartParameter(), curve.EndParameter());
                //spkCurve.Properties

                spkCurve.GenerateHash();

                speckleCurve = spkCurve;
            }
            speckleCurve.Properties = curve.GetSpeckleProperties();
            return(speckleCurve);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="curve"></param>
        /// <returns></returns>
        public static SpeckleUnityPolyline ToNative(this SpeckleCurve curve)
        {
            Vector3[] points = curve.DisplayValue.Value.ToPoints();

            if (points.Length == 0)
            {
                return(null);
            }

            curve.Scale(scaleFactor);

            return(new SpeckleUnityPolyline(curve.Type, curve.DisplayValue.Value.ToPoints()));
        }
Example #5
0
        public static NurbsCurve ToNative(this SpeckleCurve curve)
        {
            var points  = curve.Points.ToPoints();
            var dsKnots = curve.Knots;

            dsKnots.Insert(0, dsKnots.First());
            dsKnots.Add(dsKnots.Last());

            NurbsCurve nurbsCurve = NurbsCurve.ByControlPointsWeightsKnots(
                points,
                curve.Weights.ToArray(),
                dsKnots.ToArray(),
                curve.Degree
                );

            return(nurbsCurve.SetSpeckleProperties <NurbsCurve>(curve.Properties));
        }
        public static NurbsCurve ToNative(this SpeckleCurve curve)
        {
            var ptsList = curve.Points.ToPoints();

            var nurbsCurve = NurbsCurve.Create(false, curve.Degree, ptsList);

            for (int j = 0; j < nurbsCurve.Points.Count; j++)
            {
                nurbsCurve.Points.SetPoint(j, ptsList[j], curve.Weights[j]);
            }

            for (int j = 0; j < nurbsCurve.Knots.Count; j++)
            {
                nurbsCurve.Knots[j] = curve.Knots[j];
            }

            nurbsCurve.Domain = curve.Domain.ToNative();
            return(nurbsCurve);
        }
    public static NurbsCurve ToVerb(this SpeckleCurve curve)
    {
        var degree    = curve.Degree;
        var knotsList = curve.Knots;//.ToArray();
        var points    = curve.Points.ToVector3Array();

        if (knotsList.Count != degree + points.Length + 1)
        {
            knotsList.Insert(0, knotsList[0]);
            knotsList.Add(knotsList[knotsList.Count - 1]);
        }

        var knots   = knotsList.ToArray();
        var weights = curve.Weights.ToArray();

        var nurbs = new NurbsCurve(degree, knots, points, weights);

        return(nurbs);
    }
        public static NurbsCurve ToNative(this SpeckleCurve curve)
        {
            var ptsList = curve.Points.ToPoints();

            // Bug/feature in Rhino sdk: creating a periodic curve adds two extra stupid points?
            var myCurve = NurbsCurve.Create(curve.Periodic, curve.Degree, new Point3d[curve.Periodic ? ptsList.Length - 2 : ptsList.Length]);

            myCurve.Domain = curve.Domain.ToNative();

            for (int i = 0; i < ptsList.Length; i++)
            {
                myCurve.Points.SetPoint(i, ptsList[i].X, ptsList[i].Y, ptsList[i].Z, curve.Weights[i]);
            }

            for (int i = 0; i < curve.Knots.Length; i++)
            {
                myCurve.Knots[i] = curve.Knots[i];
            }

            return(myCurve);
        }
        // Curve
        public static SpeckleObject ToSpeckle(this NurbsCurve curve)
        {
            var properties = curve.UserDictionary.ToSpeckle(root: curve);

            if (curve.IsArc(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance))
            {
                Arc        getObj; curve.TryGetArc(out getObj);
                SpeckleArc myObject = getObj.ToSpeckle(); myObject.Properties = properties; myObject.GenerateHash();
                return(myObject);
            }

            if (curve.IsCircle(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance))
            {
                Circle        getObj; curve.TryGetCircle(out getObj);
                SpeckleCircle myObject = getObj.ToSpeckle(); myObject.Properties = properties; myObject.GenerateHash();
                return(myObject);
            }

            if (curve.IsEllipse(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance))
            {
                Ellipse        getObj; curve.TryGetEllipse(out getObj);
                SpeckleEllipse myObject = getObj.ToSpeckle(); myObject.Properties = properties; myObject.GenerateHash();
                return(myObject);
            }

            if (curve.IsLinear(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) || curve.IsPolyline()) // defaults to polyline
            {
                Polyline      getObj; curve.TryGetPolyline(out getObj);
                SpeckleObject myObject = getObj.ToSpeckle(); myObject.Properties = properties; myObject.GenerateHash();
                return(myObject);
            }

            Polyline poly;

            curve.ToPolyline(0, 1, 0, 0, 0, 0.1, 0, 0, true).TryGetPolyline(out poly);

            SpecklePolyline displayValue;

            if (poly.Count == 2)
            {
                displayValue       = new SpecklePolyline();
                displayValue.Value = new List <double> {
                    poly[0].X, poly[0].Y, poly[0].Z, poly[1].X, poly[1].Y, poly[1].Z
                };
                displayValue.GenerateHash();
            }
            else
            {
                displayValue = poly.ToSpeckle() as SpecklePolyline;
            }

            SpeckleCurve myCurve    = new SpeckleCurve(displayValue);
            NurbsCurve   nurbsCurve = curve.ToNurbsCurve();

            myCurve.Weights  = nurbsCurve.Points.Select(ctp => ctp.Weight).ToList();
            myCurve.Points   = nurbsCurve.Points.Select(ctp => ctp.Location).ToFlatArray().ToList();
            myCurve.Knots    = nurbsCurve.Knots.ToList();
            myCurve.Degree   = nurbsCurve.Degree;
            myCurve.Periodic = nurbsCurve.IsPeriodic;
            myCurve.Rational = nurbsCurve.IsRational;
            myCurve.Domain   = nurbsCurve.Domain.ToSpeckle();
            myCurve.Closed   = nurbsCurve.IsClosed;

            myCurve.Properties = properties;
            myCurve.GenerateHash();

            return(myCurve);
        }
    public static GameObject ToNative(this SpeckleCurve curve)
    {
        var verb = curve.ToVerb();

        return(CurveToObject(curve._id, verb));
    }
 public static GameObject ToNative(this SpeckleCurve curve)
 {
     var polyline = curve.DisplayValue;
     return polyline.ToNative();
 }