Exemplo 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;
            }
        }
Exemplo n.º 2
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);
            }
        }
    }