/// <summary> /// This one does many things, which essentially boil down to translating the geometry + performance measures into a spk instance. /// This instance subsequently gets json-ed out to a file /// </summary> public static System.Dynamic.ExpandoObject translateGeometry(List <System.Object> inputObjects, List <string> guids, String name, IGH_Component component) { dynamic myInstance = new System.Dynamic.ExpandoObject(); myInstance.metadata = new System.Dynamic.ExpandoObject(); myInstance.metadata.verion = "1.0"; myInstance.metadata.type = "Object"; myInstance.metadata.generator = "Instance Export"; // super important - name will link it to the correct group in three js myInstance.metadata.name = name; myInstance.metadata.properties = new List <String>(); foreach (IGH_Param param in component.Params.Input[1].Sources) { var myprop = getPanelNameAndVal(param); if (myprop != null) { myInstance.metadata.properties.Add(myprop); } } myInstance.geometries = new List <System.Object>(); int k = 0; foreach (System.Object myObj in inputObjects) { if (myObj != null) { string myguid = "000"; if (name != "staticGeo") { myguid = guids[k]; } k++; if (myObj is GH_Mesh) { GH_Mesh tempers = (GH_Mesh)myObj; SuperMesh mesh = new SuperMesh(tempers, myguid); myInstance.geometries.Add(mesh); } else if ((myObj is GH_Curve)) { GH_Curve tempers = (GH_Curve)myObj; Curve myCrv = tempers.Value; if (myCrv.Degree == 1) { Polyline tempP; myCrv.TryGetPolyline(out tempP); SuperPolyline polyline = new SuperPolyline(tempP, false, myguid); myInstance.geometries.Add(polyline); } else if ((myCrv.Degree == 2) || (myCrv.Degree == 3)) { bool isClosed = myCrv.IsClosed; int mainSegmentCount = 0, subSegmentCount = 1; double maxAngleRadians = 0, maxChordLengthRatio = 0, maxAspectRatio = 0, tolerance = 0.1, minEdgeLength = 0, maxEdgeLength = 0; bool keepStartPoint = true; PolylineCurve p = myCrv.ToPolyline(mainSegmentCount, subSegmentCount, maxAngleRadians, maxChordLengthRatio, maxAspectRatio, tolerance, minEdgeLength, maxEdgeLength, keepStartPoint); Polyline pp; p.TryGetPolyline(out pp); myInstance.geometries.Add(new SuperPolyline(pp, isClosed, myguid)); } } else if (myObj is Point3d) { GH_Point tempers = (GH_Point)myObj; SuperPoint point = new SuperPoint(tempers, myguid); myInstance.geometries.Add(point); } else if ((myObj is GH_Brep) || (myObj is GH_Surface)) { Mesh[] myMeshes; Brep myFutureBrep = null; GH_Convert.ToBrep(myObj, ref myFutureBrep, GH_Conversion.Primary); if (myFutureBrep != null) { myMeshes = Mesh.CreateFromBrep(myFutureBrep, MeshingParameters.Smooth); if (myMeshes == null || myMeshes.Length == 0) { // TODO throw an error } Mesh brep_mesh = new Mesh(); foreach (Mesh tempmesh in myMeshes) { brep_mesh.Append(tempmesh); } GH_Mesh temporal = new GH_Mesh(brep_mesh); SuperMesh mesh = new SuperMesh(temporal, myguid); myInstance.geometries.Add(mesh); } } else if (myObj is GH_Circle) { GH_Circle myCircle = myObj as GH_Circle; //NurbsCurve mycrv = myCircle.Value.ToNurbsCurve(); NurbsCurve mycrv = NurbsCurve.CreateFromCircle(myCircle.Value); int mainSegmentCount = 30, subSegmentCount = 1; double maxAngleRadians = 0, maxChordLengthRatio = 0, maxAspectRatio = 0, tolerance = 0.1, minEdgeLength = 0, maxEdgeLength = 0; bool keepStartPoint = true; if (mycrv != null) { PolylineCurve p = mycrv.ToPolyline(mainSegmentCount, subSegmentCount, maxAngleRadians, maxChordLengthRatio, maxAspectRatio, tolerance, minEdgeLength, maxEdgeLength, keepStartPoint); Polyline pp; p.TryGetPolyline(out pp); if (pp != null) { myInstance.geometries.Add(new SuperPolyline(pp, true, myguid)); } else { myInstance.geometries.Add("Circle error"); } } else { myInstance.geometries.Add("Circle error 2"); } } else if (myObj is GH_Line) { GH_Line myLine = myObj as GH_Line; myInstance.geometries.Add(new SuperPolyline(myLine, myguid)); } else { myInstance.geometries.Add("error - undefined type"); } } } return(myInstance); }