Пример #1
0
        public static Autodesk.DesignScript.Geometry.NurbsSurface ToDynamoType(Parasite_NurbsSurface nurbsSurface)
        {
            Parasite_Point3d[][] vertices = nurbsSurface.ControlPoints;
            double[][]           weights  = nurbsSurface.Weights;
            double[]             knotsU   = nurbsSurface.KnotsU;
            double[]             knotsV   = nurbsSurface.KnotsV;

            return(Autodesk.DesignScript.Geometry.NurbsSurface.ByControlPointsWeightsKnots(ToDynamoType(vertices), weights, knotsU, knotsV, nurbsSurface.DegreeU, nurbsSurface.DegreeV));

            //return Autodesk.DesignScript.Geometry.NurbsSurface.ByControlPoints(vertices.ToDynamoType(), nurbsSurface.DegreeU, nurbsSurface.DegreeV);
        }
Пример #2
0
        //public static Parasite_BrepSurface ToParasiteType(this DB.Face face, bool untrimmed = false)
        //{
        //    var surface = face.ToRhinoSurface();
        //    if (surface is null)
        //        return null;

        //    var brep = Brep.CreateFromSurface(surface);
        //    if (brep is null)
        //        return null;


        //    if (untrimmed)
        //        return brep;

        //    var loops = face.GetEdgesAsCurveLoops().ToRhino().ToArray();



        //    try { return brep.TrimFaces(loops); }
        //    finally { brep.Dispose(); }
        //}


        //public static Parasite_BrepSolid ToParasiteType(DB.Solid solid)
        //{
        //    return solid.Faces.
        //           Cast<DB.Face>().
        //           Select(x => x.ToRhino()).
        //           ToArray().
        //           JoinAndMerge(Revit.VertexTolerance);
        //}


        #endregion


        #region NURBS SURFACE

        public static Parasite_NurbsSurface ToParasiteType(Rhino.Geometry.NurbsSurface nurbsSurface, Dictionary <string, string> properties = null)
        {
            Parasite_NurbsSurface parasite_NurbsSurface = null;

            if (!nurbsSurface.IsValid)
            {
                throw new ParasiteArgumentException("Please enter a valid Rhino Nurbs Surface");
            }

            else
            {
                if (nurbsSurface.IsSphere())
                {
                    throw new ParasiteNotImplementedExceptions("There is still no support for Rhino NURBS Spheres");
                }

                else if (nurbsSurface.IsTorus())
                {
                    throw new ParasiteNotImplementedExceptions("There is still no support for Rhino NURBS Torus");
                }

                else
                {
                    NurbsSurfaceKnotList  rhinoKnotsU = nurbsSurface.KnotsU;
                    NurbsSurfaceKnotList  rhinoKnotsV = nurbsSurface.KnotsV;
                    NurbsSurfacePointList cp          = nurbsSurface.Points;

                    double[]   knotsU  = new double[rhinoKnotsU.Count];
                    double[]   knotsV  = new double[rhinoKnotsV.Count];
                    double[][] weights = new double[cp.Count()][];

                    if (cp.Any((x) => !x.Location.IsValid))
                    {
                        throw new ParasiteArgumentException("The Rhino NURBS Surface had an invalid Control Point!");
                    }

                    Parasite_Point3d[][] vertices = new Parasite_Point3d[cp.Count()][];

                    for (int i = 0; i < rhinoKnotsU.Count; i++)
                    {
                        knotsU[i] = rhinoKnotsU[i];
                        knotsV[i] = rhinoKnotsV[i];
                    }


                    //for (int u = 0; u < cp.CountU; u++)
                    //{
                    //    for (int v = 0; v < cp.CountV; v++)
                    //    {
                    //        Point3d controlP = cp.GetControlPoint(u, v).Location;
                    //        double weight = cp.GetWeight(u, v);

                    //    }
                    //}



                    int count = -1;
                    foreach (var item in cp)
                    {
                        count++;
                        if (item.Weight <= 1e-11)
                        {
                            weights[count] = new double[] { 0.0 }
                        }
                        ;

                        weights[count]  = new double[] { item.Weight };
                        vertices[count] = new Parasite_Point3d[] { ToParasiteType(item.Location) };
                    }

                    parasite_NurbsSurface = new Parasite_NurbsSurface(vertices, knotsU, knotsV, weights, nurbsSurface.Degree(0), nurbsSurface.Degree(1));
                }
            }

            return(parasite_NurbsSurface);
        }

        #endregion

        #endregion
    }
Пример #3
0
        public DataContainer CollectData(List <List <object> > dataFromApp)
        {
            DataContainer dataContainer = new DataContainer(dataFromApp.Count);

            for (int i = 0; i < dataFromApp.Count; i++)
            {
                DataNode <ParasiteAbstractObject>[] nodeArray = new DataNode <ParasiteAbstractObject> [dataFromApp[i].Count];

                for (int j = 0; j < dataFromApp[i].Count; j++)
                {
                    if (dataFromApp[i][j] is GH_Point p)
                    {
                        if (p.CastTo(out Point3d pt))
                        {
                            Parasite_Point3d point = ParasiteConversion.ToParasiteType(pt);
                            nodeArray[j] = new DataNode <ParasiteAbstractObject>(point);
                        }
                    }

                    else if (dataFromApp[i][j] is GH_Surface srf)
                    {
                        Brep brep = srf.Value;

                        if (brep.IsSurface)
                        {
                            BrepSurfaceList srfList = brep.Surfaces;

                            if (srfList.Count == 1)
                            {
                                Parasite_NurbsSurface paraSrf = ParasiteConversion.ToParasiteType(srfList[0].ToNurbsSurface());
                                nodeArray[j] = new DataNode <ParasiteAbstractObject>(paraSrf);
                            }
                        }
                    }


                    else if (dataFromApp[i][j] is GH_Brep b)
                    {
                        Brep brep = b.Value;

                        if (brep.IsSurface && !brep.IsSolid)
                        {
                            Parasite_BrepSurface parasiteBrepSrf = ParasiteConversion.ToParasiteType(brep);
                            nodeArray[j] = new DataNode <ParasiteAbstractObject>(parasiteBrepSrf);
                        }

                        if (!brep.IsSurface && brep.IsSolid)
                        {
                            // dataContainer.Data.Add(new Parasite_BrepSolid(brep));
                        }
                    }

                    else if (dataFromApp[i][j] is GH_Mesh m)
                    {
                        Rhino.Geometry.Mesh mesh = m.Value;

                        Parasite_Mesh parasiteMesh = ParasiteConversion.ToParasiteType(mesh);
                        nodeArray[j] = new DataNode <ParasiteAbstractObject>(parasiteMesh);
                    }


                    /// CONNVERT GH_CURVE TO PARASITE CURVE
                    else if (dataFromApp[i][j] is GH_Curve curve)
                    {
                        Rhino.Geometry.NurbsCurve nc = curve.Value as NurbsCurve;

                        if (nc.IsArc())
                        {
                            throw new ParasiteNotImplementedExceptions("Object type not implemented yet!");
                        }

                        else if (nc.IsCircle())
                        {
                            throw new ParasiteNotImplementedExceptions("Object type not implemented yet!");
                        }

                        else if (nc.IsEllipse())
                        {
                            throw new ParasiteNotImplementedExceptions("Object type not implemented yet!");
                        }

                        else if (nc.IsPolyline())
                        {
                            throw new ParasiteNotImplementedExceptions("Object type not implemented yet!");
                        }

                        else
                        {
                            Parasite_NurbsCurve parasiteNurbsCurve = ParasiteConversion.ToParasiteType(nc);
                            nodeArray[j] = new DataNode <ParasiteAbstractObject>(parasiteNurbsCurve);
                        }
                    }



                    else
                    {
                        throw new ParasiteNotImplementedExceptions("Type conversion not implemented yet!");
                    }
                }


                dataContainer.Data[i] = nodeArray;
            }

            return(dataContainer);
        }