Beispiel #1
0
        public static MFnDependencyNode CreateLayeredTextureNode(List <MFnDependencyNode> imageNodes)
        {
            //MFnDependencyNode layeredTextureNode = new MFnDependencyNode();
            //layeredTextureNode.create("layeredTexture");
            MFnDependencyNode layeredTextureNode   = CreateShadingNode(ShadingNodeType.Utility, "layeredTexture");
            MPlug             layeredTexInputsPlug = layeredTextureNode.findPlug(ConstantValue.plugName_layeredTextureInputs);
            //check place2DTextures
            MDGModifier dGModifier = new MDGModifier();

            for (int i = 0; i < imageNodes.Count; i++)
            {
                //place2dTexture setting
                MFnDependencyNode p2dNode = GetPlace2dTextureForTex(imageNodes[i]);
                p2dNode.findPlug("wrapU").setBool(false);
                p2dNode.findPlug("translateFrameU").setFloat(i);

                //set tex default color to 0
                imageNodes[i].findPlug(ConstantValue.plugName_fileTexDefaultColorR).setFloat(0);
                imageNodes[i].findPlug(ConstantValue.plugName_fileTexDefaultColorG).setFloat(0);
                imageNodes[i].findPlug(ConstantValue.plugName_fileTexDefaultColorB).setFloat(0);

                //move uv
                MSelectionList matList = GetMaterialsWithTex(imageNodes[i]);
                for (int j = 0; j < matList.length; j++)
                {
                    MObject matObj = new MObject();
                    matList.getDependNode((uint)j, matObj);
                    string matName = new MFnDependencyNode(matObj).absoluteName;
                    Debug.Log("move uv for mat:" + matName);
                    MoveUV(i, 0, matName);
                }
                MPlug layeredTexInputPlug  = layeredTexInputsPlug.elementByLogicalIndex((uint)i);
                MPlug texOutColorPlug      = imageNodes[i].findPlug(ConstantValue.plugName_fileTexOutputColor);
                MPlug layeredTexInputColor = layeredTexInputPlug.child((int)ConstantValue.LayeredTextureInputDataIndex.Color);
                dGModifier.connect(texOutColorPlug, layeredTexInputColor);
                //set blendMode to add
                MPlug blendMode = layeredTexInputPlug.child((int)ConstantValue.LayeredTextureInputDataIndex.BlendMode);
                if (i < imageNodes.Count - 1)
                {
                    blendMode.setInt((int)ConstantValue.LayeredTextureBlendMode.Add);
                }
                else
                {
                    blendMode.setInt((int)ConstantValue.LayeredTextureBlendMode.None);
                }
            }
            dGModifier.doIt();
            return(layeredTextureNode);
        }