Пример #1
0
        public void AddGeometry(BufferGeometry geometry)
        {
            // If geometries does not have a list, add an empty list
            if (Geometries == null)
            {
                Geometries = new List <BufferGeometry>();
            }

            // Add the specified geometry
            Geometries.Add(geometry);
        }
        /// <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);
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        /// <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);
        }