/// <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); }
/// <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) { Texture map = null; Texture alphaMap = null; double alphaTest = 0.5; Texture bumpMap = null; double bumpScale = 1; Texture displacementMap = null; double displacementScale = 1; Texture normalMap = null; Texture envMap = null; double envMapIntensity = 1; Texture roughnessMap = null; Texture metalnessMap = null; Texture aoMap = null; double aoMapIntensity = 1; Texture emissiveMap = null; if (!DA.GetData(0, ref map)) { map = null; } if (!DA.GetData(1, ref alphaMap)) { alphaMap = null; } DA.GetData(2, ref alphaTest); if (!DA.GetData(3, ref bumpMap)) { bumpMap = null; } DA.GetData(4, ref bumpScale); if (!DA.GetData(5, ref displacementMap)) { displacementMap = null; } DA.GetData(6, ref displacementScale); if (!DA.GetData(7, ref normalMap)) { normalMap = null; } if (!DA.GetData(8, ref envMap)) { envMap = null; } DA.GetData(9, ref envMapIntensity); if (!DA.GetData(10, ref roughnessMap)) { roughnessMap = null; } if (!DA.GetData(11, ref metalnessMap)) { metalnessMap = null; } if (!DA.GetData(12, ref aoMap)) { aoMap = null; } DA.GetData(13, ref aoMapIntensity); if (!DA.GetData(14, ref emissiveMap)) { emissiveMap = null; } MeshStandardMaterialMaps materialMaps = new MeshStandardMaterialMaps(); materialMaps.Map = map; materialMaps.AlphaMap = alphaMap; materialMaps.AlphaTest = alphaTest; materialMaps.BumpMap = bumpMap; materialMaps.BumpScale = bumpScale; materialMaps.DisplacementMap = displacementMap; materialMaps.DisplacementScale = displacementScale; materialMaps.EnvMap = envMap; materialMaps.EnvMapIntensity = envMapIntensity; materialMaps.NormalMap = normalMap; materialMaps.RoughnessMap = roughnessMap; materialMaps.MetalnessMap = metalnessMap; materialMaps.AoMap = aoMap; materialMaps.AoMapIntensity = aoMapIntensity; materialMaps.EmissiveMap = emissiveMap; DA.SetData(0, materialMaps); }