Esempio n. 1
0
        private static void AddTextureToMaterial(FDatasmithFacadeUEPbrMaterial DSMaterial, RhinoTextureInfo TextureInfo, Color DiffuseColor)
        {
            if (!TextureInfo.IsSupported())
            {
                return;
            }

            Texture RhinoTexture = TextureInfo.RhinoTexture;

            // Extract texture mapping info
            double BlendConstant, BlendA0, BlendA1, BlendA2, BlendA3;

            RhinoTexture.GetAlphaBlendValues(out BlendConstant, out BlendA0, out BlendA1, out BlendA2, out BlendA3);
            FDatasmithFacadeMaterialsUtils.FWeightedMaterialExpressionParameters WeightedExpressionParameters = new FDatasmithFacadeMaterialsUtils.FWeightedMaterialExpressionParameters((float)BlendConstant);
            FDatasmithFacadeMaterialsUtils.FUVEditParameters UVParameters = GetUVParameter(RhinoTexture);

            switch (RhinoTexture.TextureType)
            {
            case TextureType.Bitmap:
            {
                FDatasmithFacadeMaterialExpression TextureExpression = FDatasmithFacadeMaterialsUtils.CreateTextureExpression(DSMaterial, "Diffuse Map", TextureInfo.Name, UVParameters);

                WeightedExpressionParameters.SetColorsRGB(DiffuseColor.R, DiffuseColor.G, DiffuseColor.B, DiffuseColor.A);
                WeightedExpressionParameters.SetExpression(TextureExpression);
                FDatasmithFacadeMaterialExpression Expression = FDatasmithFacadeMaterialsUtils.CreateWeightedMaterialExpression(DSMaterial, "Diffuse Color", WeightedExpressionParameters);

                DSMaterial.GetBaseColor().SetExpression(Expression);
            }
            break;

            case TextureType.Bump:
            {
                FDatasmithFacadeMaterialExpression TextureExpression = FDatasmithFacadeMaterialsUtils.CreateTextureExpression(DSMaterial, "Bump Map", TextureInfo.Name, UVParameters);

                WeightedExpressionParameters.SetExpression(TextureExpression);
                WeightedExpressionParameters.SetTextureMode(FDatasmithFacadeTexture.ETextureMode.Bump);
                FDatasmithFacadeMaterialExpression Expression = FDatasmithFacadeMaterialsUtils.CreateWeightedMaterialExpression(DSMaterial, "Bump Height", WeightedExpressionParameters);

                DSMaterial.GetNormal().SetExpression(Expression);
            }
            break;

            case TextureType.Transparency:
            {
                FDatasmithFacadeMaterialExpression TextureExpression = FDatasmithFacadeMaterialsUtils.CreateTextureExpression(DSMaterial, "Opacity Map", TextureInfo.Name, UVParameters);

                Color BlendColor = Color.White;
                WeightedExpressionParameters.SetColorsRGB(BlendColor.R, BlendColor.G, BlendColor.B, BlendColor.A);
                WeightedExpressionParameters.SetExpression(TextureExpression);
                FDatasmithFacadeMaterialExpression Expression = FDatasmithFacadeMaterialsUtils.CreateWeightedMaterialExpression(DSMaterial, "White", WeightedExpressionParameters);

                DSMaterial.GetOpacity().SetExpression(Expression);
                if (Math.Abs(BlendConstant) > float.Epsilon)
                {
                    DSMaterial.SetBlendMode(/*EBlendMode::BLEND_Translucent*/ 2);
                }
            }
            break;
            }
        }
Esempio n. 2
0
 public void SetExpression(FDatasmithFacadeMaterialExpression InExpression)
 {
     DatasmithFacadeCSharpPINVOKE.FDatasmithFacadeMaterialsUtils_FWeightedMaterialExpressionParameters_SetExpression(swigCPtr, FDatasmithFacadeMaterialExpression.getCPtr(InExpression));
     if (DatasmithFacadeCSharpPINVOKE.SWIGPendingException.Pending)
     {
         throw DatasmithFacadeCSharpPINVOKE.SWIGPendingException.Retrieve();
     }
 }
    public int GetExpressionIndex(FDatasmithFacadeMaterialExpression Expression)
    {
        int ret = DatasmithFacadeCSharpPINVOKE.FDatasmithFacadeUEPbrMaterial_GetExpressionIndex(swigCPtr, FDatasmithFacadeMaterialExpression.getCPtr(Expression));

        if (DatasmithFacadeCSharpPINVOKE.SWIGPendingException.Pending)
        {
            throw DatasmithFacadeCSharpPINVOKE.SWIGPendingException.Retrieve();
        }
        return(ret);
    }
 public void SetExpression(FDatasmithFacadeMaterialExpression InExpression)
 {
     DatasmithFacadeCSharpPINVOKE.FDatasmithFacadeExpressionInput_SetExpression(swigCPtr, FDatasmithFacadeMaterialExpression.getCPtr(InExpression));
 }
Esempio n. 5
0
        public static void ParseMaterial(FDatasmithFacadeUEPbrMaterial DSMaterial, Material RhinoMaterial, DatasmithRhinoSceneParser SceneParser)
        {
            Color MaterialDiffuseColor = RhinoMaterial.DiffuseColor;

            MaterialDiffuseColor = Color.FromArgb(255 - (byte)(255 * RhinoMaterial.Transparency), MaterialDiffuseColor);

            Texture[] MaterialTextures = RhinoMaterial.GetTextures();
            for (int TextureIndex = 0; TextureIndex < MaterialTextures.Length; ++TextureIndex)
            {
                Texture RhinoTexture = MaterialTextures[TextureIndex];
                if (RhinoTexture != null)
                {
                    RhinoTextureInfo TextureInfo = SceneParser.GetTextureInfoFromRhinoTexture(RhinoTexture.Id);
                    if (TextureInfo != null)
                    {
                        AddTextureToMaterial(DSMaterial, TextureInfo, MaterialDiffuseColor);
                    }
                }
            }

            // Set a diffuse color if there's nothing in the BaseColor
            if (DSMaterial.GetBaseColor().GetExpression() == null)
            {
                FDatasmithFacadeMaterialExpressionColor ColorExpression = DSMaterial.AddMaterialExpressionColor();
                ColorExpression.SetName("Diffuse Color");
                ColorExpression.SetsRGBColor(MaterialDiffuseColor.R, MaterialDiffuseColor.G, MaterialDiffuseColor.B, MaterialDiffuseColor.A);

                ColorExpression.ConnectExpression(DSMaterial.GetBaseColor());
            }

            if (RhinoMaterial.Transparency > 0)
            {
                DSMaterial.SetBlendMode(/*EBlendMode::BLEND_Translucent*/ 2);
                if (DSMaterial.GetOpacity().GetExpression() == null)
                {
                    // Transparent color
                    FDatasmithFacadeMaterialExpressionScalar Scalar = DSMaterial.AddMaterialExpressionScalar();
                    Scalar.SetName("Opacity");
                    Scalar.SetScalar(1 - (float)RhinoMaterial.Transparency);
                    Scalar.ConnectExpression(DSMaterial.GetOpacity());
                }
                else
                {
                    // Modulate the opacity map with the color transparency setting
                    FDatasmithFacadeMaterialExpressionGeneric Multiply = DSMaterial.AddMaterialExpressionGeneric();
                    Multiply.SetExpressionName("Multiply");

                    FDatasmithFacadeMaterialExpressionScalar Scalar = DSMaterial.AddMaterialExpressionScalar();
                    Scalar.SetName("Opacity Output Level");
                    Scalar.SetScalar(1 - (float)RhinoMaterial.Transparency);
                    Scalar.ConnectExpression(Multiply.GetInput(0));

                    FDatasmithFacadeMaterialExpression CurrentOpacityExpression = DSMaterial.GetOpacity().GetExpression();
                    CurrentOpacityExpression.ConnectExpression(Multiply.GetInput(1));

                    DSMaterial.GetOpacity().SetExpression(Multiply);
                }
            }

            float Shininess = (float)(RhinoMaterial.Shine / Material.MaxShine);

            if (Math.Abs(Shininess) > float.Epsilon)
            {
                FDatasmithFacadeMaterialExpressionScalar ShininessExpression = DSMaterial.AddMaterialExpressionScalar();
                ShininessExpression.SetName("Roughness");
                ShininessExpression.SetScalar(1f - Shininess);
                ShininessExpression.ConnectExpression(DSMaterial.GetRoughness());
            }

            float Reflectivity = (float)RhinoMaterial.Reflectivity;

            if (Math.Abs(Reflectivity) > float.Epsilon)
            {
                FDatasmithFacadeMaterialExpressionScalar ReflectivityExpression = DSMaterial.AddMaterialExpressionScalar();
                ReflectivityExpression.SetName("Metallic");
                ReflectivityExpression.SetScalar(Reflectivity);
                ReflectivityExpression.ConnectExpression(DSMaterial.GetMetallic());
            }
        }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FDatasmithFacadeMaterialExpression obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }