static bool CopyShaderParam(MPlug from, MPlug to, ShaderParamType spt = ShaderParamType.Color) { if (from == null || to == null) { return(false); } MPlugArray plugArr = new MPlugArray(); from.connectedTo(plugArr, true, false); if (plugArr.length == 0) { switch (spt) { case ShaderParamType.Color: { to.child(0).setFloat(from.child(0).asFloat()); to.child(1).setFloat(from.child(1).asFloat()); to.child(2).setFloat(from.child(2).asFloat()); break; } case ShaderParamType.Float: { to.setFloat(from.asFloat()); break; } } } else { MDGModifier dGModifier = new MDGModifier(); Debug.Log(from.source.partialName(true)); dGModifier.connect(from.source, to); dGModifier.doIt(); } return(true); }
public static void ConvertToRSMaterial(MFnDependencyNode matNode, bool deleteOrigin) { //replace output to shadingEngine MPlug plug_matColorOutput = matNode.findPlug(ConstantValue.plugName_matColorOutput); MPlugArray plugArr_matColorOutDest = new MPlugArray(); plug_matColorOutput.destinations(plugArr_matColorOutDest); //get textures MPlug plug_matColorInput = matNode.findPlug(ConstantValue.plugName_matColorInput); MPlug plug_matTransparency = matNode.findPlug(ConstantValue.plugName_matTransparency); MFnDependencyNode rsArchiNode = CreateShadingNode(ShadingNodeType.Shader, ConstantValue.nodeName_RS_Architectural); if (matNode.name.StartsWith("mat_")) { rsArchiNode.setName("rs" + matNode.name); } else { rsArchiNode.setName("rsmat_" + matNode.name); } MPlug plug_rsArchiDiffuse = rsArchiNode.findPlug(ConstantValue.plugName_RS_diffuse); MPlug plug_rsArchiTransColor = rsArchiNode.findPlug(ConstantValue.plugName_RS_transColor); MPlug plug_rsArchiTransWeight = rsArchiNode.findPlug(ConstantValue.plugName_RS_transWeight); MPlug plug_rsArchiOutColor = rsArchiNode.findPlug(ConstantValue.plugName_RS_outColor); MDGModifier dGModifier = new MDGModifier(); for (int i = 0; i < plugArr_matColorOutDest.length; i++) { dGModifier.disconnect(plug_matColorOutput, plugArr_matColorOutDest[i]); dGModifier.connect(plug_rsArchiOutColor, plugArr_matColorOutDest[i]); } CopyShaderParam(plug_matColorInput, plug_rsArchiDiffuse); //if (plug_matColorInput.source == null) //{ // plug_rsArchiDiffuse.child(0).setFloat(plug_matColorInput.child(0).asFloat()); // plug_rsArchiDiffuse.child(1).setFloat(plug_matColorInput.child(1).asFloat()); // plug_rsArchiDiffuse.child(2).setFloat(plug_matColorInput.child(2).asFloat()); //} //else //{ // dGModifier.connect(plug_matColorInput.source, plug_rsArchiDiffuse); //} CopyShaderParam(plug_matTransparency, plug_rsArchiTransColor); if (plug_matTransparency.child(0).asFloat() == 0 && plug_matTransparency.child(1).asFloat() == 0 && plug_matTransparency.child(2).asFloat() == 0) { plug_rsArchiTransWeight.setFloat(1); } else { plug_rsArchiTransWeight.setFloat(0); } //if (plug_matTransparency.source == null) //{ // //plug_rsArchiTransColor.setValue(plug_matColorInput.asMObject()); // float matTransparency = plug_matTransparency.asFloat(); // if (matTransparency == 0) // { // plug_rsArchiTransWeight.setFloat(0); // plug_rsArchiTransColor.child(0).setFloat(0); // plug_rsArchiTransColor.child(1).setFloat(0); // plug_rsArchiTransColor.child(2).setFloat(0); // } // else // { // plug_rsArchiTransWeight.setFloat(1); // plug_rsArchiTransColor.child(0).setFloat(plug_matTransparency.child(0).asFloat()); // plug_rsArchiTransColor.child(1).setFloat(plug_matTransparency.child(1).asFloat()); // plug_rsArchiTransColor.child(2).setFloat(plug_matTransparency.child(2).asFloat()); // } //} //else //{ // dGModifier.connect(plug_matTransparency.source, plug_rsArchiTransColor); // plug_rsArchiTransWeight.setFloat(1); //} if (deleteOrigin) { dGModifier.deleteNode(matNode.objectProperty); } dGModifier.doIt(); }