Beispiel #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;
            }
        }
Beispiel #2
0
        public static void ExportMaterials(FDatasmithFacadeScene DatasmithScene, DatasmithRhinoSceneParser SceneParser)
        {
            int TextureAndMaterialCount    = SceneParser.TextureHashToTextureInfo.Count + SceneParser.MaterialHashToMaterialInfo.Count;
            int TextureAndMaterialProgress = 0;

            foreach (RhinoTextureInfo CurrentTextureInfo in SceneParser.TextureHashToTextureInfo.Values)
            {
                FDatasmithRhinoProgressManager.Instance.UpdateCurrentTaskProgress((float)(++TextureAndMaterialProgress) / TextureAndMaterialCount);

                FDatasmithFacadeTexture TextureElement = ParseTexture(CurrentTextureInfo);
                if (TextureElement != null)
                {
                    DatasmithScene.AddTexture(TextureElement);
                }
            }

            foreach (RhinoMaterialInfo CurrentMaterialInfo in SceneParser.MaterialHashToMaterialInfo.Values)
            {
                FDatasmithRhinoProgressManager.Instance.UpdateCurrentTaskProgress((float)(++TextureAndMaterialProgress) / TextureAndMaterialCount);
                FDatasmithFacadeUEPbrMaterial DSMaterial = new FDatasmithFacadeUEPbrMaterial(CurrentMaterialInfo.Name);
                DSMaterial.SetLabel(CurrentMaterialInfo.Label);
                ParseMaterial(DSMaterial, CurrentMaterialInfo.RhinoMaterial, SceneParser);

                DatasmithScene.AddMaterial(DSMaterial);
            }
        }
Beispiel #3
0
 public static FDatasmithFacadeMaterialExpressionTexture CreateTextureExpression(FDatasmithFacadeUEPbrMaterial MaterialElement, string ParameterName, string TextureMapPath, FDatasmithFacadeMaterialsUtils.FUVEditParameters UVParameters)
 {
     global::System.IntPtr objectPtr = DatasmithFacadeCSharpPINVOKE.FDatasmithFacadeMaterialsUtils_CreateTextureExpression(FDatasmithFacadeUEPbrMaterial.getCPtr(MaterialElement), ParameterName, TextureMapPath, FDatasmithFacadeMaterialsUtils.FUVEditParameters.getCPtr(UVParameters));
     if (DatasmithFacadeCSharpPINVOKE.SWIGPendingException.Pending)
     {
         throw DatasmithFacadeCSharpPINVOKE.SWIGPendingException.Retrieve();
     }
     if (objectPtr == global::System.IntPtr.Zero)
     {
         return(null);
     }
     else
     {
         return(new FDatasmithFacadeMaterialExpressionTexture(objectPtr, true));
     }
 }
Beispiel #4
0
    public static FDatasmithFacadeMaterialExpression CreateWeightedMaterialExpression(FDatasmithFacadeUEPbrMaterial MaterialElement, string ParameterName, FDatasmithFacadeMaterialsUtils.FWeightedMaterialExpressionParameters WeightedExpressionParameter)
    {
        global::System.IntPtr objectPtr = DatasmithFacadeCSharpPINVOKE.FDatasmithFacadeMaterialsUtils_CreateWeightedMaterialExpression(FDatasmithFacadeUEPbrMaterial.getCPtr(MaterialElement), ParameterName, FDatasmithFacadeMaterialsUtils.FWeightedMaterialExpressionParameters.getCPtr(WeightedExpressionParameter));
        if (DatasmithFacadeCSharpPINVOKE.SWIGPendingException.Pending)
        {
            throw DatasmithFacadeCSharpPINVOKE.SWIGPendingException.Retrieve();
        }
        if (objectPtr == global::System.IntPtr.Zero)
        {
            return(null);
        }
        else
        {
            //Query the type with a temporary wrapper with no memory ownership.
            EDatasmithFacadeMaterialExpressionType ExpressionType = (new FDatasmithFacadeMaterialExpression(objectPtr, false)).GetExpressionType();

            switch (ExpressionType)
            {
            case EDatasmithFacadeMaterialExpressionType.ConstantBool:
                return(new FDatasmithFacadeMaterialExpressionBool(objectPtr, true));

            case EDatasmithFacadeMaterialExpressionType.ConstantColor:
                return(new FDatasmithFacadeMaterialExpressionColor(objectPtr, true));

            case EDatasmithFacadeMaterialExpressionType.ConstantScalar:
                return(new FDatasmithFacadeMaterialExpressionScalar(objectPtr, true));

            case EDatasmithFacadeMaterialExpressionType.FlattenNormal:
                return(new FDatasmithFacadeMaterialExpressionFlattenNormal(objectPtr, true));

            case EDatasmithFacadeMaterialExpressionType.FunctionCall:
                return(new FDatasmithFacadeMaterialExpressionFunctionCall(objectPtr, true));

            case EDatasmithFacadeMaterialExpressionType.Generic:
                return(new FDatasmithFacadeMaterialExpressionGeneric(objectPtr, true));

            case EDatasmithFacadeMaterialExpressionType.Texture:
                return(new FDatasmithFacadeMaterialExpressionTexture(objectPtr, true));

            case EDatasmithFacadeMaterialExpressionType.TextureCoordinate:
                return(new FDatasmithFacadeMaterialExpressionTextureCoordinate(objectPtr, true));

            default:
                return(null);
            }
        }
    }
Beispiel #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(FDatasmithFacadeUEPbrMaterial obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }