/// <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) { Color color = Color.White; double linewidth = 1; DA.GetData(0, ref color); DA.GetData(1, ref linewidth); // Build the material object dynamic material = new ExpandoObject(); material.uuid = Guid.NewGuid(); material.type = "LineBasicMaterial"; material.color = Convert.ToInt32(color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"), 16); material.linewidth = linewidth; // Wrap the material MaterialWrapper wrapper = new MaterialWrapper(material); // Serialize string JSON = JsonConvert.SerializeObject(material); DA.SetData(0, JSON); DA.SetData(1, wrapper); }
/// <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 Color color = Color.White; double linewidth = 1; double dashSize = 1; double gapSize = 1; // Reference the inputs DA.GetData(0, ref color); DA.GetData(1, ref linewidth); DA.GetData(2, ref dashSize); DA.GetData(3, ref gapSize); // Build the material object dynamic material = new ExpandoObject(); material.uuid = Guid.NewGuid(); material.type = "LineDashedMaterial"; material.color = Convert.ToInt32(color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"), 16); material.linewidth = linewidth; material.dashSize = dashSize; material.gapSize = gapSize; // Wrap the material MaterialWrapper wrapper = new MaterialWrapper(material); // Serialize string JSON = JsonConvert.SerializeObject(material); DA.SetData(0, JSON); DA.SetData(1, wrapper); }
/// <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 bool wireframe = false; string wireframeLinejoin = "round"; double wireframeLinewidth = 1; // Reference the inputs DA.GetData(0, ref wireframe); DA.GetData(1, ref wireframeLinejoin); DA.GetData(2, ref wireframeLinewidth); // Create material object dynamic material = new ExpandoObject(); material.uuid = Guid.NewGuid(); material.type = "MeshNormalMaterial"; material.wireframe = wireframe; material.wireframeLinejoin = wireframeLinejoin; material.wireframeLinewidth = wireframeLinewidth; /// Wrap the material MaterialWrapper wrapper = new MaterialWrapper(material); string JSON = JsonConvert.SerializeObject(material); DA.SetData(0, JSON); DA.SetData(1, wrapper); }
/// <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 Color color = Color.White; double opacity = 1; double roughness = 1; double metalness = 0.5; Color emissive = Color.Black; double emissiveIntensity = 1; bool wireframe = false; string wireframeLinejoin = "round"; double wireframeLinewidth = 1; // Reference inputs DA.GetData(0, ref color); DA.GetData(1, ref opacity); DA.GetData(2, ref roughness); DA.GetData(3, ref metalness); DA.GetData(4, ref emissive); DA.GetData(5, ref emissiveIntensity); DA.GetData(6, ref wireframe); DA.GetData(7, ref wireframeLinejoin); DA.GetData(8, ref wireframeLinewidth); // Create the material object dynamic material = new ExpandoObject(); material.uuid = Guid.NewGuid(); material.type = "MeshStandardMaterial"; material.color = Convert.ToInt32(color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"), 16); material.transparent = true; material.opacity = opacity; material.roughness = roughness; material.metalness = metalness; material.emissive = Convert.ToInt32(emissive.R.ToString("X2") + emissive.G.ToString("X2") + emissive.B.ToString("X2"), 16); material.emissiveIntensity = emissiveIntensity; material.wireframe = wireframe; material.wireframeLinejoin = wireframeLinejoin; material.wireframeLinewidth = wireframeLinewidth; /// Wrap the material MaterialWrapper wrapper = new MaterialWrapper(material); string JSON = JsonConvert.SerializeObject(material); DA.SetData(0, JSON); DA.SetData(1, wrapper); }
/// <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 Color color = Color.White; bool wireframe = false; string wireframeLinejoin = "round"; double wireframeLinewidth = 1; // Reference the inputs DA.GetData(0, ref color); DA.GetData(1, ref wireframe); DA.GetData(2, ref wireframeLinejoin); DA.GetData(3, ref wireframeLinewidth); // Build the material object dynamic material = new ExpandoObject(); material.uuid = Guid.NewGuid(); material.type = "MeshBasicMaterial"; material.color = Convert.ToInt32(color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"), 16); // If the wireframe is set to true, add wireframe attributes if (wireframe) { material.wireframe = wireframe; material.wireframeLinejoin = wireframeLinejoin; material.wireframeLinewidth = wireframeLinewidth; } //Wrap the material MaterialWrapper wrapper = new MaterialWrapper(material); // Serialize string JSON = JsonConvert.SerializeObject(material); // Set the outputs DA.SetData(0, JSON); DA.SetData(1, wrapper); }
/// <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 = ""; MaterialWrapper material = null; // Reference the inputs DA.GetData(0, ref curve); DA.GetData(1, ref name); DA.GetData(2, ref material); // 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 = null; curve.TryGetPolyline(out polyline); // Fill a list with the polyline's point coordinates List <double> array = new List <double>(); for (int i = 0; i < polyline.Count; i++) { // Get point values var px = polyline.X[i]; var py = polyline.Y[i]; var pz = polyline.Z[i]; // Add point values to array array.Add(Math.Round(px, 3) * -1); array.Add(Math.Round(pz, 3)); array.Add(Math.Round(py, 3)); } //Build the position object dynamic position = new ExpandoObject(); position.itemSize = 3; position.type = "Float32Array"; position.array = array; position.normalized = false; // Build the attribute object dynamic attributes = new ExpandoObject(); attributes.position = position; // If LineDashedMaterial is used, add the lineDistance attribute if (material != null && string.Equals(material.Material.type, "LineDashedMaterial")) { // Create list to populate with lineDistances List <double> lineDistances = new List <double>(); Point3d previousPt = new Point3d(); // Loop over vertices and measure the distance from start to each vertex for (int i = 0; i < polyline.Count; i++) { // Get point values var px = polyline.X[i]; var py = polyline.Y[i]; var pz = polyline.Z[i]; // Distance to previous point Point3d pt = new Point3d(px, py, pz); if (i == 0) { lineDistances.Add(0); } else { lineDistances.Add(pt.DistanceTo(previousPt) + lineDistances[i - 1]); } previousPt = pt; } // Build the lineDistance object dynamic lineDistance = new ExpandoObject(); lineDistance.type = "Float32Array"; lineDistance.array = lineDistances; lineDistance.count = polyline.Count; lineDistance.itemSize = 1; // Add the lineDistance object to the attributes object attributes.lineDistance = lineDistance; } // Build the data object dynamic data = new ExpandoObject(); data.attributes = attributes; // Build the geometry object dynamic geometry = new ExpandoObject(); geometry.uuid = Guid.NewGuid(); geometry.type = "BufferGeometry"; geometry.data = data; // Build the child object dynamic child = new ExpandoObject(); child.uuid = Guid.NewGuid(); if (name.Length > 0) { child.name = name; } child.type = "Line"; child.geometry = geometry.uuid; if (material != null) { child.material = material.Material.uuid; } child.matrix = new List <double> { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; // Fill the children list List <dynamic> children = new List <dynamic>(); children.Add(child); // Wrap the objects in a wrapper object GeometryWrapper wrapper = null; if (material != null) { wrapper = new GeometryWrapper(geometry, child, material.Material); } else { wrapper = new GeometryWrapper(geometry, child, null); } // Serialize wrapper object string JSON = JsonConvert.SerializeObject(wrapper); // Set outputs DA.SetData(0, JSON); DA.SetData(1, wrapper); }
/// <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 Rhino.Geometry.Mesh mesh = null; string name = ""; MaterialWrapper material = null; // Reference the inputs DA.GetData(0, ref mesh); DA.GetData(1, ref name); DA.GetData(2, ref material); // If the meshes have quads, triangulate them if (!mesh.Faces.ConvertQuadsToTriangles()) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Error triangulating quad meshes. Try triangulating quads before feeding into this component."); } ; // Fill the vertices and colors list List <double> vertices = new List <double>(); List <double> colors = new List <double>(); for (int i = 0; i < mesh.Vertices.Count; i++) { vertices.Add(Math.Round(mesh.Vertices[i].X, 3) * -1); vertices.Add(Math.Round(mesh.Vertices[i].Z, 3)); vertices.Add(Math.Round(mesh.Vertices[i].Y, 3)); colors.Add((float)mesh.VertexColors[i].R / 255); colors.Add((float)mesh.VertexColors[i].G / 255); colors.Add((float)mesh.VertexColors[i].B / 255); } // Create position object dynamic position = new ExpandoObject(); position.itemSize = 3; position.type = "Float32Array"; position.array = vertices; position.normalized = false; // Create color object dynamic color = new ExpandoObject(); color.itemSize = 3; color.type = "Float32Array"; color.array = colors; // Fill the normals list List <double> normals = new List <double>(); for (int i = 0; i < mesh.Normals.Count; i++) { normals.Add(Math.Round(mesh.Normals[i].X, 3) * -1); normals.Add(Math.Round(mesh.Normals[i].Z, 3)); normals.Add(Math.Round(mesh.Normals[i].Y, 3)); } // Create normal object dynamic normal = new ExpandoObject(); normal.itemSize = 3; normal.type = "Float32Array"; normal.array = normals; normal.normalized = false; // Fill the uvs list List <double> uvs = new List <double>(); for (int i = 0; i < mesh.TextureCoordinates.Count; i++) { uvs.Add(Math.Round(mesh.TextureCoordinates[i].X, 3)); uvs.Add(Math.Round(mesh.TextureCoordinates[i].Y, 3)); } // Create uv object dynamic uv = new ExpandoObject(); uv.itemSize = 2; uv.type = "Float32Array"; uv.array = uvs; uv.normalized = false; // Create attributes object dynamic attributes = new ExpandoObject(); attributes.position = position; attributes.color = color; attributes.normal = normal; attributes.uv = uv; // Fill faces list List <int> faces = new List <int>(); for (int i = 0; i < mesh.Faces.Count; i++) { faces.Add(mesh.Faces.GetFace(i).A); faces.Add(mesh.Faces.GetFace(i).B); faces.Add(mesh.Faces.GetFace(i).C); } // Create the index object dynamic index = new ExpandoObject(); index.type = "Uint32Array"; index.array = faces; // Create the data object dynamic data = new ExpandoObject(); data.attributes = attributes; data.index = index; /// Add the bufferGeometry dynamic bufferGeometry = new ExpandoObject(); bufferGeometry.uuid = Guid.NewGuid();; bufferGeometry.type = "BufferGeometry"; bufferGeometry.data = data; /// Add the child dynamic child = new ExpandoObject(); child.uuid = Guid.NewGuid(); if (name.Length > 0) { child.name = name; } child.type = "Mesh"; child.geometry = bufferGeometry.uuid; child.material = material.Material.uuid; child.matrix = new List <double> { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; child.castShadow = true; child.receiveShadow = true; // Set the material to use vertex colors material.Material.vertexColors = 2; material.Material.color = "0xffffff"; /// Wrap the bufferGeometries and children to the wrapper GeometryWrapper wrapper = new GeometryWrapper(bufferGeometry, child, material.Material); // Create JSON string string JSON = JsonConvert.SerializeObject(wrapper); // Set outputs DA.SetData(0, JSON); DA.SetData(1, wrapper); }