/// <summary> /// Converts a Dynamo Solid to a Parasite Brep Solid. /// This method iterates through all the faces of the Dynamo Solid, /// extracts their vertices and computes a new Parasite Brep Surface from them. /// Each Parasite Brep Surface is sequentially added to a Collection as input for constructing /// a Parasite Brep Solid /// </summary> /// <param name="solid"></param> /// <param name="properties"></param> /// <returns></returns> public static Parasite_BrepSolid ToParasiteType(Autodesk.DesignScript.Geometry.Solid solid, Dictionary <string, Parameter> properties = null) { Autodesk.DesignScript.Geometry.Face[] faces = solid.Faces; Parasite_BrepSurface[] brepSurfs = new Parasite_BrepSurface[faces.Length]; for (int i = 0; i < faces.Length; i++) { Autodesk.DesignScript.Geometry.Loop [] loops = faces[i].Loops; List <Autodesk.DesignScript.Geometry.Curve> lines = new List <Autodesk.DesignScript.Geometry.Curve>(); for (int k = 0; k < loops.Length; k++) { Autodesk.DesignScript.Geometry.CoEdge[] coEdge = loops[k].CoEdges; for (int m = 0; m < coEdge.Length; m++) { lines.Add(coEdge[m].Edge.CurveGeometry); } } Autodesk.DesignScript.Geometry.Vertex[] vertices = faces[i].Vertices; Parasite_Point3d[] vertexArray = new Parasite_Point3d[vertices.Length]; for (int j = 0; j < vertices.Length; j++) { vertexArray[j] = ToParasiteType(vertices[j].PointGeometry); } Parasite_BrepSurface brepSrf = new Parasite_BrepSurface(vertexArray, ToParasiteType(lines), properties); brepSurfs[i] = brepSrf; } return(new Parasite_BrepSolid(brepSurfs, properties)); }
/// <summary> /// Converts a Parasite_BrepSurface object to a Dynamo Surface object /// </summary> /// <param name="brep">A Parasite_BrepSurface object </param> /// <returns>A Dynamo Surface on success</returns> public static Autodesk.DesignScript.Geometry.Surface ToDynamoType(Parasite_BrepSurface brep) { IEnumerable <Autodesk.DesignScript.Geometry.Point> vertices = brep.Vertices.Select(x => ToDynamoType(x)); return(Autodesk.DesignScript.Geometry.Surface.ByPerimeterPoints(vertices)); }
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); }