/// <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 = ""; Material material = null; int decimalAccuracy = 3; // Reference the inputs DA.GetData(0, ref mesh); DA.GetData(1, ref name); DA.GetData(2, ref material); DA.GetData(3, ref decimalAccuracy); // 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."); } ; // Get the center of the object so the bufferGeometry can be given a local coordinates Point3d center = mesh.GetBoundingBox(true).Center; /// Add the bufferGeometry BufferGeometry geometry = new BufferGeometry(mesh, center, decimalAccuracy, true); /// Add the child dynamic meshObject = new ExpandoObject(); meshObject.Uuid = Guid.NewGuid(); if (name.Length > 0) { meshObject.name = name; } meshObject.Type = "Mesh"; meshObject.Geometry = geometry.Uuid; meshObject.Matrix = new Matrix(center).Array; meshObject.CastShadow = true; meshObject.ReceiveShadow = true; // Create line object Object3d object3d = new Object3d(meshObject); object3d.AddGeometry(geometry); // If there is a material, add the material, textures, and images if (material != null) { meshObject.Material = material.Data.Uuid; // Set the material to use vertex colors material.Data.vertexColors = 2; material.Data.color = "0xffffff"; 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(); meshObject.Material = uuid; // Build the material object dynamic meshBasicMaterial = new ExpandoObject(); meshBasicMaterial.Uuid = uuid; meshBasicMaterial.Type = "MeshBasicMaterial"; meshBasicMaterial.vertexColors = 2; object3d.AddMaterial(meshBasicMaterial); } // Set output references 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 Mesh mesh = null; string name = ""; Material material = null; int decimalAccuracy = 3; UserData userData = null; // Reference the inputs DA.GetData(0, ref mesh); DA.GetData(1, ref name); DA.GetData(2, ref material); DA.GetData(3, ref decimalAccuracy); DA.GetData(4, ref userData); // 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."); } ; // Get the center of the object so the bufferGeometry can be given a local coordinates Point3d center = mesh.GetBoundingBox(true).Center; // Create bufferGeometry var geometry = new BufferGeometry(mesh, center, decimalAccuracy); //Create a mesh object dynamic meshObject = new ExpandoObject(); meshObject.Uuid = Guid.NewGuid(); meshObject.Name = name; meshObject.Type = "Mesh"; meshObject.Geometry = geometry.Uuid; meshObject.Matrix = new Matrix(center).Array; meshObject.CastShadow = true; meshObject.ReceiveShadow = true; // If there is userData, add it to the object if (userData != null) { meshObject.UserData = userData.properties; } // Create mesh object Object3d object3d = new Object3d(meshObject); object3d.AddGeometry(geometry); // If there is a material, add the material, textures, and images if (material != null) { meshObject.Material = material.Data.Uuid; 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); } } } // 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 <Object3d> object3ds = new List <Object3d>(); String name = ""; Color backgroundColor = Color.LightGray; Texture background = null; Texture environment = null; Fog fog = null; // Reference the inputs DA.GetDataList(0, object3ds); DA.GetData(1, ref name); DA.GetData(2, ref backgroundColor); DA.GetData(3, ref background); DA.GetData(4, ref environment); DA.GetData(5, ref fog); /// Scene dynamic scene = new ExpandoObject(); scene.Uuid = Guid.NewGuid(); scene.Type = "Scene"; scene.Name = name; scene.Matrix = new Matrix(Point3d.Origin).Array; scene.Children = new List <dynamic>(); Object3d sceneObject = new Object3d(scene); // Create lists for ids to make sure there are no duplicates List <string> geometriesIds = new List <string>(); List <string> materialsIds = new List <string>(); List <string> texturesIds = new List <string>(); List <string> imagesIds = new List <string>(); // If there is a background, add it to the scene if (background != null) { scene.Background = background.Data.Uuid; if (!texturesIds.Contains(background.Data.Uuid.ToString())) { sceneObject.AddTexture(background.Data); texturesIds.Add(background.Data.Uuid.ToString()); } if (!imagesIds.Contains(background.Image.Uuid.ToString())) { sceneObject.AddImage(background.Image); imagesIds.Add(background.Image.Uuid.ToString()); } } else { scene.Background = new DecimalColor(backgroundColor).Color; } // If there is an environment, add it to the scene if (environment != null) { scene.Environment = environment.Data.Uuid; if (!texturesIds.Contains(environment.Data.Uuid.ToString())) { sceneObject.AddTexture(environment.Data); texturesIds.Add(environment.Data.Uuid.ToString()); } if (!imagesIds.Contains(environment.Image.Uuid.ToString())) { sceneObject.AddImage(environment.Image); imagesIds.Add(environment.Image.Uuid.ToString()); } } // If there is an fog input, add it to the scene if (fog != null) { scene.Fog = fog; } // Loop over all the threejs objects and add them to the scene foreach (Object3d object3d in object3ds) { // Add the objects to the scene as child objects scene.Children.Add(object3d.Object); // If Threejs object includes geometries list, add geometry objects to the scene if (object3d.Geometries != null) { foreach (dynamic geometry in object3d.Geometries) { if (!geometriesIds.Contains(geometry.Uuid.ToString())) { sceneObject.AddGeometry(geometry); geometriesIds.Add(geometry.Uuid.ToString()); } } } // If Threejs object includes materials list, add material obects to the scene if (object3d.Materials != null) { foreach (dynamic material in object3d.Materials) { if (!materialsIds.Contains(material.Uuid.ToString())) { sceneObject.AddMaterial(material); materialsIds.Add(material.Uuid.ToString()); } } } // If Threejs object includes textures list, add the textures to the scene if (object3d.Textures != null) { foreach (dynamic texture in object3d.Textures) { if (!texturesIds.Contains(texture.Uuid.ToString())) { sceneObject.AddTexture(texture); texturesIds.Add(texture.Uuid.ToString()); } } } // If Threejs object includes images list, add the images to the scene if (object3d.Images != null) { foreach (dynamic image in object3d.Images) { if (!imagesIds.Contains(image.Uuid.ToString())) { sceneObject.AddImage(image); imagesIds.Add(image.Uuid.ToString()); } } } } // Set the outputs DA.SetData(0, sceneObject); }
/// <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); }