/// <summary> /// Get material bitmap from texture evaluator /// </summary> /// <param name="shader"></param> /// <param name="rm"></param> /// <param name="renderTexture"></param> /// <param name="textureType"></param> internal static void MaterialBitmapFromEvaluator(ref ShaderBody shader, RenderMaterial rm, RenderTexture renderTexture, RenderMaterial.StandardChildSlots textureType) { if (renderTexture == null) { return; } var rId = renderTexture.RenderHashWithoutLocalMapping; var rhinotfm = renderTexture.LocalMappingTransform; var projectionMode = renderTexture.GetProjectionMode(); var envProjectionMode = renderTexture.GetInternalEnvironmentMappingMode(); var repeat = renderTexture.GetWrapType() == TextureWrapType.Repeating; using (var textureEvaluator = renderTexture.CreateEvaluator(RenderTexture.TextureEvaluatorFlags.DisableLocalMapping)) { SimulatedTexture st = textureEvaluator == null?renderTexture.SimulatedTexture(RenderTexture.TextureGeneration.Disallow) : null; using ( var actualEvaluator = textureEvaluator ?? RenderTexture.NewBitmapTexture(st).CreateEvaluator(RenderTexture.TextureEvaluatorFlags.DisableLocalMapping)) { InternalMaterialBitmapFromEvaluator(shader, renderTexture, textureType, rhinotfm, rId, actualEvaluator, projectionMode, envProjectionMode, repeat); } } }
/// <summary> /// This method reads the values introduced by the user and established class properties with them. /// </summary> protected override void ReadDataFromUI() { bool hasTexture; var textureParam = GetChildSlotParameter(REFLECTANCE_TEXTURE_FIELD, REFLECTANCE_TEXTURE_SLOT); Fields.TryGetValue(REFLECTANCE_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(REFLECTANCE_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); Reflectance.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); Reflectance.SecondParameter = texSim.Filename; } } } else { Reflectance.SecondParameter = string.Empty; } } else { //We have color Color4f color; Fields.TryGetValue(REFLECTANCE_COLOR_FIELD, out color); Reflectance.FirstParameter = color; Reflectance.SecondParameter = string.Empty; } }
public override void SimulateMaterial(ref Rhino.DocObjects.Material simulatedMaterial, bool forDataOnly) { var boolrc = false; boolrc = HandleTexturedValue(Pbr.BaseColor, Base); simulatedMaterial.DiffuseColor = Base.Value.AsSystemColor(); if (Base.Texture != null && Base.On) { SimulatedTexture simtex = Base.Texture.SimulatedTexture(RenderTexture.TextureGeneration.Allow); simulatedMaterial.SetBitmapTexture(simtex.Texture()); } boolrc = HandleTexturedValue(Pbr.Metallic, Metallic); simulatedMaterial.Reflectivity = Metallic.Value; if (Metallic.Value > 0.5f) { simulatedMaterial.DiffuseColor = System.Drawing.Color.Black; simulatedMaterial.ReflectionColor = Base.Value.AsSystemColor(); } boolrc = HandleTexturedValue(Pbr.Roughness, Roughness); simulatedMaterial.ReflectionGlossiness = 1.0f - Roughness.Value; boolrc = HandleTexturedValue(Pbr.Opacity, Transmission); simulatedMaterial.Transparency = 1.0f - Transmission.Value; if (Transmission.Value > 0.5f) { simulatedMaterial.TransparentColor = Base.Value.AsSystemColor(); } boolrc = HandleTexturedValue(Pbr.OpacityRoughness, TransmissionRoughness); simulatedMaterial.RefractionGlossiness = 1.0f - TransmissionRoughness.Value; boolrc = HandleTexturedValue(Pbr.OpacityIor, Ior); simulatedMaterial.IndexOfRefraction = Ior.Value; boolrc = HandleTexturedValue(Pbr.Bump, Bump); if (Bump.On && Bump.Texture != null) { SimulatedTexture simtex = Bump.Texture.SimulatedTexture(RenderTexture.TextureGeneration.Allow); simulatedMaterial.SetBumpTexture(simtex.Texture()); } }
/// <summary> /// This method reads the values introduced by the user and established class properties with them. /// </summary> protected override void ReadDataFromUI() { if (_distributionCombo != null) { Distribution = _distributionCombo.SelectedItem; } else { string distribution_key; Fields.TryGetValue(DISTRIBUTION_FIELD, out distribution_key); //Setting the _distributionCombo value if (_distributionCombo != null) { _distributionCombo.SelectedItem = distribution_key; } Distribution = distribution_key; } //Interior Index of Refraction if (_intIORCombo != null) { var myValue = StandardIORTypes.Types.FirstOrDefault(x => x.Value == _intIORCombo.SelectedItem).Key; IntIOR.SecondParameter = myValue; } else { //If we're reading a RMTL file, take the value from this file string intIOR_key; Fields.TryGetValue(INTIOR_FIELD, out intIOR_key); //Set the combobox value string combo_value; StandardIORTypes.Types.TryGetValue(intIOR_key, out combo_value); if (_extIORCombo != null) { _extIORCombo.SelectedItem = combo_value; } IntIOR.SecondParameter = combo_value; } //Exterior Index of Refraction if (_extIORCombo != null) { var myValue = StandardIORTypes.Types.FirstOrDefault(x => x.Value == _extIORCombo.SelectedItem).Key; ExtIOR.SecondParameter = myValue; } else { //If we're reading a RMTL file, take the value from this file string extIOR_key; Fields.TryGetValue(EXTIOR_FIELD, out extIOR_key); //Set the combobox value string combo_value; StandardIORTypes.Types.TryGetValue(extIOR_key, out combo_value); if (_extIORCombo != null) { _extIORCombo.SelectedItem = combo_value; } ExtIOR.SecondParameter = combo_value; } //Alpha bool hasTexture; var textureParam = GetChildSlotParameter(ALPHA_TEXTURE_FIELD, ALPHA_TEXTURE_SLOT); Fields.TryGetValue(ALPHA_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(ALPHA_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); Alpha.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); Alpha.SecondParameter = texSim.Filename; } } } else { Alpha.SecondParameter = string.Empty; } } else { float alpha; Fields.TryGetValue(ALPHA_FLOAT_FIELD, out alpha); Alpha.FirstParameter = alpha; } //AlphaU textureParam = GetChildSlotParameter(ALPHAU_TEXTURE_FIELD, ALPHAU_TEXTURE_SLOT); Fields.TryGetValue(ALPHAU_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(ALPHAU_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); AlphaU.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); AlphaU.SecondParameter = texSim.Filename; } } } else { AlphaU.SecondParameter = string.Empty; } } else { float alphaU; Fields.TryGetValue(ALPHAU_FLOAT_FIELD, out alphaU); AlphaU.FirstParameter = alphaU; } //AlphaV textureParam = GetChildSlotParameter(ALPHAV_TEXTURE_FIELD, ALPHAV_TEXTURE_SLOT); Fields.TryGetValue(ALPHAV_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(ALPHAV_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); AlphaV.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); AlphaV.SecondParameter = texSim.Filename; } } } else { AlphaV.SecondParameter = string.Empty; } } else { float alphaV; Fields.TryGetValue(ALPHAV_FLOAT_FIELD, out alphaV); AlphaV.FirstParameter = alphaV; } //Interior Index of Refraction //float extIOR; //Fields.TryGetValue(EXTIOR_FIELD, out extIOR); //ExtIOR.FirstParameter = extIOR; //Exterior Index of Refraction //float intIOR; //if (Fields.TryGetValue(INTIOR_FIELD, out intIOR)) // IntIOR.FirstParameter = intIOR; //else IntIOR.FirstParameter = -1; }
/// <summary> /// </summary> protected override void ReadDataFromUI() { //Interior Index of Refraction if (_intIORCombo != null) { var myValue = StandardIORTypes.Types.FirstOrDefault(x => x.Value == _intIORCombo.SelectedItem).Key; IntIOR.SecondParameter = myValue; } else { //If we're reading a RMTL file, take the value from this file string intIOR_key; Fields.TryGetValue(INTIOR_FIELD, out intIOR_key); //Set the combobox value string combo_value; StandardIORTypes.Types.TryGetValue(intIOR_key, out combo_value); if (_extIORCombo != null) { _extIORCombo.SelectedItem = combo_value; } IntIOR.SecondParameter = combo_value; } //Exterior Index of Refraction if (_extIORCombo != null) { var myValue = StandardIORTypes.Types.FirstOrDefault(x => x.Value == _extIORCombo.SelectedItem).Key; ExtIOR.SecondParameter = myValue; } else { //If we're reading a RMTL file, take the value from this file string extIOR_key; Fields.TryGetValue(EXTIOR_FIELD, out extIOR_key); //Set the combobox value string combo_value; StandardIORTypes.Types.TryGetValue(extIOR_key, out combo_value); if (_extIORCombo != null) { _extIORCombo.SelectedItem = combo_value; } ExtIOR.SecondParameter = combo_value; } //Exterior Index of Refraction //float extIOR; //Fields.TryGetValue(EXTIOR_FIELD, out extIOR); //ExtIOR.FirstParameter = extIOR; //Interior Index of Refraction //float intIOR; //if (Fields.TryGetValue(INTIOR_FIELD, out intIOR)) IntIOR.FirstParameter = intIOR; //Diffuse Refectance bool hasTexture; var textureParam = GetChildSlotParameter(REFLECTANCE_TEXTURE_FIELD, REFLECTANCE_TEXTURE_SLOT); Fields.TryGetValue(REFLECTANCE_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(REFLECTANCE_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); DiffuseReflectance.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); DiffuseReflectance.SecondParameter = texSim.Filename; } } } else { DiffuseReflectance.SecondParameter = string.Empty; } } else { //We have color Color4f color; Fields.TryGetValue(REFLECTANCE_COLOR_FIELD, out color); DiffuseReflectance.FirstParameter = color; DiffuseReflectance.SecondParameter = string.Empty; } //Nonlinear bool nonLinear; if (Fields.TryGetValue(NONLINEAR_FIELD, out nonLinear)) { Nonlinear = nonLinear; } }
/// <summary> /// Converts a SimulatedTexture to a RenderTexture /// </summary> /// <param name="simTex"></param> /// <param name="doc"></param> /// <returns></returns> public static RenderTexture ToRenderTexture(this SimulatedTexture simTex, RhinoDoc doc) { return(RenderTexture.NewBitmapTexture(simTex, doc)); }
/// <summary> /// This method reads the values introduced by the user and established class properties with them. /// </summary> protected override void ReadDataFromUI() { bool hasTexture; var textureParam = GetChildSlotParameter(REFLECTANCE_TEXTURE_FIELD, REFLECTANCE_TEXTURE_SLOT); Fields.TryGetValue(REFLECTANCE_TEXTURE_FIELD, out hasTexture); //Reflectance if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(REFLECTANCE_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); Reflectance.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); Reflectance.SecondParameter = texSim.Filename; } } } else { Reflectance.SecondParameter = string.Empty; } } else { //We have color Color4f color; Fields.TryGetValue(REFLECTANCE_COLOR_FIELD, out color); Reflectance.FirstParameter = color; Reflectance.SecondParameter = string.Empty; } //Alpha textureParam = GetChildSlotParameter(ALPHA_TEXTURE_FIELD, ALPHA_TEXTURE_SLOT); Fields.TryGetValue(ALPHA_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(ALPHA_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); Alpha.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); Alpha.SecondParameter = texSim.Filename; } } } else { Alpha.SecondParameter = string.Empty; } } else { float alpha; Fields.TryGetValue(ALPHA_FLOAT_FIELD, out alpha); Alpha.FirstParameter = alpha; Reflectance.SecondParameter = string.Empty; } //Use fast approximation? bool useFastApprox; Fields.TryGetValue(USE_FAST_APPROX_FIELD, out useFastApprox); UseFastApprox = useFastApprox; }
/// <summary> /// This method reads the values introduced by the user and established class properties with them. /// </summary> protected override void ReadDataFromUI() { //Material if (_materialCombo != null) { var myValue = StandardConductorTypes.Types.FirstOrDefault(x => x.Value == _materialCombo.SelectedItem).Key; Material = myValue; } else { //If we're reading a RMTL file, take the value from this file string material_key; Fields.TryGetValue(MATERIAL_FIELD, out material_key); //Set the combobox value string combo_value; StandardConductorTypes.Types.TryGetValue(material_key, out combo_value); if (_materialCombo != null) { _materialCombo.SelectedItem = combo_value; } Material = combo_value; } //ETA Color4f colorEta; Fields.TryGetValue(ETA_FIELD, out colorEta); Eta = colorEta; //K Color4f colorK; Fields.TryGetValue(K_FIELD, out colorK); Eta = colorK; //ExtEta bool hasTexture; var textureParam = GetChildSlotParameter(EXT_ETA_TEXTURE_FIELD, EXT_ETA_TEXTURE_SLOT); Fields.TryGetValue(EXT_ETA_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(EXT_ETA_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); ExtEta.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); ExtEta.SecondParameter = texSim.Filename; } } } else { ExtEta.SecondParameter = string.Empty; } } else { float extEta; Fields.TryGetValue(EXT_ETA_FLOAT_FIELD, out extEta); ExtEta.FirstParameter = extEta; } }
/// <summary> /// This method reads the values introduced by the user and established class properties with them. /// </summary> protected override void ReadDataFromUI() { //Material if (_materialCombo != null) { var myValue = StandardConductorTypes.Types.FirstOrDefault(x => x.Value == _materialCombo.SelectedItem).Key; Material = myValue; } else { //If we're reading a RMTL file, take the value from this file string material_key; Fields.TryGetValue(MATERIAL_FIELD, out material_key); //Set the combobox value string combo_value; StandardConductorTypes.Types.TryGetValue(material_key, out combo_value); if (_materialCombo != null) { _materialCombo.SelectedItem = combo_value; } Material = combo_value; } //Distribution if (_distributionCombo != null) { Distribution = _distributionCombo.SelectedItem; } else { string distribution_key; Fields.TryGetValue(DISTRIBUTION_FIELD, out distribution_key); //Setting the _distributionCombo value if (_distributionCombo != null) { _distributionCombo.SelectedItem = distribution_key; } Distribution = distribution_key; } //Alpha bool hasTexture; var textureParam = GetChildSlotParameter(ALPHA_TEXTURE_FIELD, ALPHA_TEXTURE_SLOT); Fields.TryGetValue(ALPHA_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(ALPHA_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); Alpha.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); Alpha.SecondParameter = texSim.Filename; } } } else { Alpha.SecondParameter = string.Empty; } } else { float alpha; Fields.TryGetValue(ALPHA_FLOAT_FIELD, out alpha); Alpha.FirstParameter = alpha; } //AlphaU textureParam = GetChildSlotParameter(ALPHAU_TEXTURE_FIELD, ALPHAU_TEXTURE_SLOT); Fields.TryGetValue(ALPHAU_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(ALPHAU_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); AlphaU.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); AlphaU.SecondParameter = texSim.Filename; } } } else { AlphaU.SecondParameter = string.Empty; } } else { float alphaU; Fields.TryGetValue(ALPHAU_FLOAT_FIELD, out alphaU); AlphaU.FirstParameter = alphaU; } //AlphaV textureParam = GetChildSlotParameter(ALPHAV_TEXTURE_FIELD, ALPHAV_TEXTURE_SLOT); Fields.TryGetValue(ALPHAV_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(ALPHAV_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); AlphaV.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); AlphaV.SecondParameter = texSim.Filename; } } } else { AlphaV.SecondParameter = string.Empty; } } else { float alphaV; Fields.TryGetValue(ALPHAV_FLOAT_FIELD, out alphaV); AlphaV.FirstParameter = alphaV; } //Eta Color4f eta; Fields.TryGetValue(ETA_FIELD, out eta); Eta = eta; //k Color4f k; Fields.TryGetValue(K_FIELD, out k); K = k; //ExtEta textureParam = GetChildSlotParameter(EXT_ETA_TEXTURE_FIELD, EXT_ETA_TEXTURE_SLOT); Fields.TryGetValue(EXT_ETA_TEXTURE_FIELD, out hasTexture); if (hasTexture && textureParam != null) { //We have texture var tx = FindChild(EXT_ETA_TEXTURE_FIELD); if (tx != null) { if (tx.Fields.ContainsField("filename")) { var fields = tx.Fields.GetField("filename"); ExtEta.SecondParameter = fields.ValueAsObject().ToString(); } else { var text = tx as RenderTexture; if (text != null) { var texSim = new SimulatedTexture(); text.SimulateTexture(ref texSim, false); ExtEta.SecondParameter = texSim.Filename; } } } else { ExtEta.SecondParameter = string.Empty; } } else { float extEta; Fields.TryGetValue(EXT_ETA_FLOAT_FIELD, out extEta); ExtEta.FirstParameter = extEta; } }