#include "file/token.h" #include "file/stream.h" #include "shaderMaterial/shaderMaterialGeoParamValueTexture.h" #include "shaderMaterial/shaderMaterialGeoParamDescriptionTexture.h" #include "rageShaderMaterialMayaParam.h" #include "rageShaderMaterialMaya.h" #include "rageShaderMaya65.h" #define REQUIRE_IOSTREAM #pragma warning(push) #pragma warning(disable : 4668) #include #include #include #include #include #include #pragma warning(pop) using namespace rage; extern bool g_bDisplayMGlobalExecuteCommands; bool rageShaderMaterialMaya::AddToMayaNode(MObject obNode, const rageShaderMaterial& obMaterial, bool* DeletedExistingDataDuringCreation) { MFnDependencyNode obFnThis(obNode); Assert(DeletedExistingDataDuringCreation); (*DeletedExistingDataDuringCreation) = false; if (!obFnThis.isLocked() && !obFnThis.isFromReferencedFile()) { if (obFnThis.attributeCount()) { bool attribsAreEqual = true; // Check the shader attributes for (int i=0; iGetName(), (strExistingParamName == MString(param->GetName()))); if(strExistingParamName == MString(param->GetParamDescription()->GetUIName())) { // It still exists, so don't kill it bDeleteAttribute = false; break; } } if(bDeleteAttribute) { // Displayf("Going to delete %s", obFnAttribute.name().asChar()); } } else { // It is a dynamic attribute, not a child attribute and I do not have to retain the existing textures, so delete it! bDeleteAttribute = true; } } } if(bDeleteAttribute) { //(*DeletedExistingDataDuringCreation) = true; // Safe to delete //Displayf("Deleting %s", obFnAttribute.name().asChar()); MStatus obStatus = obFnThis.removeAttribute(obFnThis.attribute(i), MFnDependencyNode::kLocalDynamicAttr); if(obStatus != MS::kSuccess) { Displayf("An error occured removing attribute %s from node %s : %s %s %d", obFnAttribute.name().asChar(), obFnThis.name().asChar(), obStatus.errorString().asChar(), __FILE__, __LINE__); return false; } i--; } } } // Add the new shader attributes for (int i=0; iGetParamDescription()->GetUIName()); if(obExistingPlug.isNull()) { //Displayf("Add Attribute [%s]", obMaterial.GetShaderParam(i)->GetParamDescription()->GetUIName()); // Don't exist, so add me //if (!rageShaderMaya::getIgnoreReferencedNodesDuringWireUpTextures()) //{ rageShaderMaterialMayaParam::AddAttributesToMayaNode(obNode, obMaterial.GetShaderParam(i)); //} } else { //Displayf("Not going to add %s because already exists", obExistingPlug.name().asChar()); } } // Restore the locked-ness return true; } bool rageShaderMaterialMaya::RemoveFromMayaNode(MObject obNode, const rageShaderMaterial& /*obMaterial*/) { MFnDependencyNode obFnThis(obNode); if (obFnThis.isLocked()) { //nothing we can do return true; } MPlug obTextureOveridePlug = obFnThis.findPlug("TextureOveride"); bool bUseExistingTextureNodes; obTextureOveridePlug.getValue(bUseExistingTextureNodes); // Delete all the attrs of the material for(unsigned int i=0; iGetParamDescription(); Assert(textureDesc); // Get texture name const char * pcTextureFilename = pobTextureParam->GetValue(); if (!pcTextureFilename) { Errorf("No texture name from RSM: %s PARAM: %s\n", obFnShaderNode.name().asChar(), obParam.GetName()); return false; } if (stricmp(pcTextureFilename, "none")) { //Displayf("Using Texture: %s from RSM: %s PARAM: %s", pcTextureFilename, obFnShaderNode.name().asChar(), obParam.GetName()); MItDependencyNodes depIterator( MFn::kFileTexture); // Do I already have a file node matching that texture file name? MObject obFileNode = MObject::kNullObj; MString strFileNodeName = ""; MStatus obStatus; for (; !depIterator.isDone(); depIterator.next() ) { MFnDependencyNode node( depIterator.item() ); if (rageShaderMaya::getIgnoreReferencedNodesDuringWireUpTextures() && node.isFromReferencedFile()) { continue; } else { MPlug plug = node.findPlug("fileTextureName"); if (!plug.isNull()) { MString textureFileName; plug.getValue(textureFileName); //Displayf("Comparing %s and %s (%s)", pcTextureFilename, textureFileName.asChar()); if (stricmp(fiAssetManager::FileName(textureFileName.asChar()), fiAssetManager::FileName(pcTextureFilename))==0) { //check the full path to make sure it is the same. if (stricmp(textureFileName.asChar(), pcTextureFilename)==0) { strFileNodeName = node.name(); obFileNode = depIterator.item(); //Displayf("Found file node: %s", strFileNodeName.asChar()); break; } } } } } if(strFileNodeName == "") { // Unable to find an existing filename that works, so make one // Can't find a good node, so create the maya texture file node MGlobal::executeCommand("shadingNode -asTexture file", strFileNodeName, g_bDisplayMGlobalExecuteCommands); // Convert node name into actual API node MSelectionList list; list.add(strFileNodeName); list.getDependNode(0, obFileNode); // Set the filename of the new node MFnDependencyNode obFnFileNode(obFileNode); MPlug obFileTextureNamePlug = obFnFileNode.findPlug("fileTextureName"); obFileTextureNamePlug.setValue(pcTextureFilename); //Displayf("Create File node with texture %s", pcTextureFilename); } // Get plugs for connections MFnDependencyNode obFnFileNode( obFileNode ); MPlug obOutColorPlug = obFnFileNode.findPlug("outColor", &obStatus); if(obOutColorPlug.isNull()) { // Oh dear MGlobal::displayError("Unable to find outColor attribute on \""+ obFnFileNode.name() +"\""); return false; } CHECK_STATUS( obStatus ); MString strTextureParamUIName = pobTextureParam->GetParamDescription()->GetUIName(); MString strSafeTextureParamUIName = rageShaderMaterialMayaParam::GetCleanVersionOfString(strTextureParamUIName.asChar()); MPlug obInColorPlug = obFnShaderNode.findPlug(strSafeTextureParamUIName, &obStatus); if(obInColorPlug.isNull()) { // Oh dear MGlobal::displayError("Unable to find \""+ strSafeTextureParamUIName +"\" attribute on \""+ obFnShaderNode.name() +"\""); return false; } CHECK_STATUS( obStatus ); // Make sure I'm not already connected MPlugArray aobPlugsConnectedToOutColor; obOutColorPlug.connectedTo(aobPlugsConnectedToOutColor, true, true, &obStatus); CHECK_STATUS( obStatus ); MPlugArray aobPlugsConnectedToInColor; obInColorPlug.connectedTo(aobPlugsConnectedToInColor, true, true, &obStatus); CHECK_STATUS( obStatus ); //Displayf("aobPlugsConnectedToInColor.length() = %d", aobPlugsConnectedToInColor.length()); //for(unsigned i=0; iGetUIName()); bool bAlreadyConnected = false; for(unsigned i=0; i %s", (int)__LINE__, obOutColorPlug.name().asChar(), obInColorPlug.name().asChar()); CHECK_STATUS(obModifier.commandToExecute(command)); MStatus obStatus = obModifier.doIt(); CHECK_STATUS(obStatus); if(obStatus != MS::kSuccess) { // An error occured Displayf("An error occurred connecting %s to %s\n", obOutColorPlug.name().asChar(), obInColorPlug.name().asChar()); } } } return true; } bool rageShaderMaterialMaya::ExpandTextureNodes(MObject obNode, const rageShaderMaterial& obMaterial) { // Wire up all the nodes for (int iParam=0; iParamGetType() == grcEffect::VT_TEXTURE) { WireUpTextureNode(obNode, *pobParam); } } return true; }