예제 #1
0
        public static FDatasmithFacadeTexture ParseTexture(RhinoTextureInfo TextureInfo)
        {
            Texture RhinoTexture = TextureInfo.RhinoTexture;

            if (!TextureInfo.IsSupported())
            {
                return(null);
            }

            FDatasmithFacadeTexture TextureElement = new FDatasmithFacadeTexture(TextureInfo.Name);

            TextureElement.SetLabel(TextureInfo.Label);
            TextureElement.SetFile(TextureInfo.FilePath);
            TextureElement.SetTextureFilter(FDatasmithFacadeTexture.ETextureFilter.Default);
            TextureElement.SetRGBCurve(1);
            TextureElement.SetTextureAddressX(RhinoTexture.WrapU == TextureUvwWrapping.Clamp ? FDatasmithFacadeTexture.ETextureAddress.Clamp : FDatasmithFacadeTexture.ETextureAddress.Wrap);
            TextureElement.SetTextureAddressY(RhinoTexture.WrapV == TextureUvwWrapping.Clamp ? FDatasmithFacadeTexture.ETextureAddress.Clamp : FDatasmithFacadeTexture.ETextureAddress.Wrap);

            FDatasmithFacadeTexture.ETextureMode TextureMode = FDatasmithFacadeTexture.ETextureMode.Diffuse;
            if (RhinoTexture.TextureType == TextureType.Bump)
            {
                TextureMode = FDatasmithFacadeTexture.ETextureMode.Bump;
            }

            TextureElement.SetTextureMode(TextureMode);

            return(TextureElement);
        }
예제 #2
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());
            }
        }
예제 #3
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;
            }
        }