/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Declate variables Curve curve = null; string name = ""; Material material = null; List <Color> colors = new List <Color>(); int decimalAccuracy = 3; // Reference the inputs DA.GetData(0, ref curve); DA.GetData(1, ref name); DA.GetData(2, ref material); if (!DA.GetDataList(3, colors)) { return; } DA.GetData(4, ref decimalAccuracy); // Throw error message if curve cannot be converted to a polyline if (!curve.IsPolyline()) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input must be polyine, curves are not allowed."); return; } // Convert curve to polyline Polyline polyline; curve.TryGetPolyline(out polyline); // Get the center of the object so the bufferGeometry can be given local coordinates Point3d center = polyline.BoundingBox.Center; // Produce a buffer geometry from the polyline dynamic geometry = new BufferGeometry(polyline, center, decimalAccuracy); geometry.AddVertexColors(colors); // If dashed material is used add the line distance to the buffer geometry if (material != null && string.Equals(material.Data.Type, "LineDashedMaterial")) { geometry.AddLineDistance(); } //Create a threejs object definition dynamic lineObject = new ExpandoObject(); lineObject.Uuid = Guid.NewGuid(); lineObject.Name = name; lineObject.Type = "Line"; lineObject.Geometry = geometry.Uuid; lineObject.Matrix = new Matrix(center).Array; // Create file object Object3d object3d = new Object3d(lineObject); object3d.AddGeometry(geometry); // If there is a material, add the material, textures, and images if (material != null) { lineObject.Material = material.Data.Uuid; material.Data.vertexColors = 2; object3d.AddMaterial(material.Data); if (material.Textures != null) { foreach (dynamic texture in material.Textures) { object3d.AddTexture(texture); } } if (material.Images != null) { foreach (dynamic image in material.Images) { object3d.AddImage(image); } } } else { Guid uuid = Guid.NewGuid(); lineObject.Material = uuid; // Build the material object dynamic lineBasicMaterial = new ExpandoObject(); lineBasicMaterial.Uuid = uuid; lineBasicMaterial.Type = "LineBasicMaterial"; lineBasicMaterial.vertexColors = 2; object3d.AddMaterial(lineBasicMaterial); } // Set outputs DA.SetData(0, object3d); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Declare variables List <Point3d> points = new List <Point3d>(); string name = ""; Material material = null; List <Color> colors = new List <Color>(); int decimalAccuracy = 3; // Reference the inputs if (!DA.GetDataList(0, points)) { return; } DA.GetData(1, ref name); DA.GetData(2, ref material); if (!DA.GetDataList(3, colors)) { return; } DA.GetData(4, ref decimalAccuracy); // Get the center of the bounding box to create local coordinates PointCloud pointCloud = new PointCloud(points); Point3d center = pointCloud.GetBoundingBox(true).Center; // Build the customColor objet dynamic customColor = new ExpandoObject(); customColor.ItemSize = 3; customColor.Type = "Float32Array"; customColor.Array = new List <double>(); customColor.Normalized = false; // Build the size object dynamic size = new ExpandoObject(); size.Itemsize = 1; size.Type = "Float32Array"; size.Array = new List <double>(); size.Normalized = false; // Build the attributes object //dynamic attributes = new ExpandoObject(); //attributes.position = position; //attributes.customColor = customColor; //attributes.size = size; // Create the buffer geometry BufferGeometry geometry = new BufferGeometry(points, center, decimalAccuracy); geometry.AddVertexColors(colors); // Build the child object dynamic pointsObject = new ExpandoObject(); pointsObject.Uuid = Guid.NewGuid(); pointsObject.Type = "Points"; pointsObject.Layers = 1; pointsObject.Matrix = new Matrix(center).Array; pointsObject.Geometry = geometry.Uuid; // Create line object Object3d object3d = new Object3d(pointsObject); object3d.AddGeometry(geometry); // If there is a material, add the material, textures, and images if (material != null) { pointsObject.Material = material.Data.Uuid; material.Data.vertexColors = 2; object3d.AddMaterial(material.Data); if (material.Textures != null) { foreach (dynamic texture in material.Textures) { object3d.AddTexture(texture); } } if (material.Images != null) { foreach (dynamic image in material.Images) { object3d.AddImage(image); } } } else { Guid uuid = Guid.NewGuid(); pointsObject.Material = uuid; // Build the material object dynamic pointsMaterial = new ExpandoObject(); pointsMaterial.Uuid = uuid; pointsMaterial.Type = "PointsMaterial"; pointsMaterial.vertexColors = 2; object3d.AddMaterial(pointsMaterial); } // Set output references DA.SetData(0, object3d); }