Example #1
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
            Color   color           = Color.White;
            double  size            = 1;
            bool    sizeAttenuation = true;
            Texture map             = null;
            Texture alphaMap        = null;
            double  alphaTest       = 0.5;

            // Reference the inputs
            DA.GetData(0, ref color);
            DA.GetData(1, ref size);
            DA.GetData(2, ref sizeAttenuation);
            if (!DA.GetData(3, ref map))
            {
                map = null;
            }
            if (!DA.GetData(4, ref alphaMap))
            {
                alphaMap = null;
            }
            DA.GetData(5, ref alphaTest);

            // Build the material object
            dynamic material = new ExpandoObject();

            material.Uuid            = Guid.NewGuid();
            material.Type            = "PointsMaterial";
            material.Color           = new DecimalColor(color).Color;
            material.Size            = size;
            material.SizeAttenuation = sizeAttenuation;
            if (map != null)
            {
                material.map = map.Data.Uuid;
            }
            if (alphaMap != null)
            {
                material.AlphaMap = alphaMap.Data.Uuid;
            }
            material.transparent = false;
            material.AlphaTest   = alphaTest;

            // Build the file object
            Material materialObject = new Material(material);

            if (map != null)
            {
                materialObject.AddTexture(map);
            }
            if (alphaMap != null)
            {
                materialObject.AddTexture(alphaMap);
            }

            // Set output references
            DA.SetData(0, materialObject);
        }
        /// <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;
            WireframeSettings wireframe = null;
            Texture           map       = null;

            // Reference the inputs
            DA.GetData(0, ref color);
            if (!DA.GetData(1, ref wireframe))
            {
                wireframe = null;
            }
            if (!DA.GetData(2, ref map))
            {
                map = null;
            }

            // Build the material object
            dynamic material = new ExpandoObject();

            material.Uuid  = Guid.NewGuid();
            material.Type  = "MeshBasicMaterial";
            material.Color = new DecimalColor(color).Color;

            // If the material has map
            if (map != null)
            {
                material.Map = map.Data.Uuid;
            }

            // If the wireframe is set to true, add wireframe attributes
            if (wireframe != null)
            {
                material.Wireframe          = true;
                material.WireframeLinejoin  = wireframe.WireframeLinejoin;
                material.WireframeLinewidth = wireframe.WireframeLinewidth;
            }

            // Build the file object
            Material materialObject = new Material(material);

            if (map != null)
            {
                materialObject.AddTexture(map);
            }

            // Set the outputs
            DA.SetData(0, materialObject);
        }
        /// <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                    emmisiveColor     = Color.Black;
            double                   emissiveIntensity = 1;
            WireframeSettings        wireframe         = null;
            MeshStandardMaterialMaps materialMaps      = null;

            // 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 emmisiveColor);
            DA.GetData(5, ref emissiveIntensity);
            if (!DA.GetData(6, ref wireframe))
            {
                wireframe = null;
            }
            if (!DA.GetData(7, ref materialMaps))
            {
                materialMaps = null;
            }

            // Create the material object
            dynamic material = new ExpandoObject();

            material.Uuid              = Guid.NewGuid();
            material.Type              = "MeshStandardMaterial";
            material.Color             = new DecimalColor(color).Color;
            material.Transparent       = true;
            material.Opacity           = opacity;
            material.Roughness         = roughness;
            material.Metalness         = metalness;
            material.Emissive          = new DecimalColor(emmisiveColor).Color;
            material.EmissiveIntensity = emissiveIntensity;

            // If the wireframe is set to true, add wireframe attributes
            if (wireframe != null)
            {
                material.Wireframe          = true;
                material.WireframeLinejoin  = wireframe.WireframeLinejoin;
                material.WireframeLinewidth = wireframe.WireframeLinewidth;
            }

            // Build the file object
            Material materialObject = new Material(material);

            // If there are material maps, add them
            if (materialMaps != null)
            {
                if (materialMaps.Map != null)
                {
                    material.Map = materialMaps.Map.Data.Uuid;
                    materialObject.AddTexture(materialMaps.Map);
                }

                if (materialMaps.AlphaMap != null)
                {
                    material.AlphaMap  = materialMaps.AlphaMap.Data.Uuid;
                    material.AlphaTest = materialMaps.AlphaTest;
                    materialObject.AddTexture(materialMaps.AlphaMap);
                }

                if (materialMaps.BumpMap != null)
                {
                    material.BumpMap   = materialMaps.BumpMap.Data.Uuid;
                    material.BumpScale = materialMaps.BumpScale;
                    materialObject.AddTexture(materialMaps.BumpMap);
                }

                if (materialMaps.DisplacementMap != null)
                {
                    material.DisplacementMap   = materialMaps.DisplacementMap.Data.Uuid;
                    material.DisplacementScale = materialMaps.DisplacementScale;
                    materialObject.AddTexture(materialMaps.DisplacementMap);
                }

                if (materialMaps.NormalMap != null)
                {
                    material.NormalMap = materialMaps.NormalMap.Data.Uuid;
                    materialObject.AddTexture(materialMaps.NormalMap);
                }

                if (materialMaps.EnvMap != null)
                {
                    material.EnvMap          = materialMaps.EnvMap.Data.Uuid;
                    material.EnvMapIntensity = materialMaps.EnvMapIntensity;
                    materialObject.AddTexture(materialMaps.EnvMap);
                }

                if (materialMaps.RoughnessMap != null)
                {
                    material.RoughnessMap = materialMaps.RoughnessMap.Data.Uuid;
                    materialObject.AddTexture(materialMaps.RoughnessMap);
                }

                if (materialMaps.MetalnessMap != null)
                {
                    material.MetalnessMap = materialMaps.MetalnessMap.Data.Uuid;
                    materialObject.AddTexture(materialMaps.MetalnessMap);
                }

                if (materialMaps.AoMap != null)
                {
                    material.AoMap          = materialMaps.AoMap.Data.Uuid;
                    material.AoMapIntensity = materialMaps.AoMapIntensity;
                    materialObject.AddTexture(materialMaps.AoMap);
                }

                if (materialMaps.EmissiveMap != null)
                {
                    material.EmissiveMap = materialMaps.EmissiveMap.Data.Uuid;
                    materialObject.AddTexture(materialMaps.EmissiveMap);
                }
            }

            // Set the outputs
            DA.SetData(0, materialObject);
        }