MStatus getDagPathListByName(const MString & objectNames, std::vector<MDagPath> & dagPathList) { MStatus status; MStringArray theArray; status = objectNames.split(' ', theArray); if (status == MS::kSuccess) { unsigned int len = theArray.length(); for (unsigned int i = 0; i < len; i++) { MDagPath dagPath; status = getDagPathByName(theArray[i], dagPath); if (status == MS::kSuccess) dagPathList.push_back(dagPath); else { MString theError(theArray[i]); theError += MString(" doesn't exist"); MGlobal::displayError(theError); } } } return status; }
void liqIPRNodeMessage::onOtherNode(const MString &node, std::vector<MString> &updateObjectName) { MStringArray descendents; MString cmd("listRelatives -allDescendents "+node); MGlobal::executeCommand(cmd, descendents); for(int i=0; i<descendents.length(); ++i) { addUpdateObject(updateObjectName, descendents[i]);//record descendents[i] MDagPath dagPath; getDagPathByName(dagPath, descendents[i].asChar()); if( dagPath.node().hasFn(MFn::kTransform) ) { onOtherNode(descendents[i], updateObjectName);//visit descendents[i] } else if( dagPath.node().hasFn(MFn::kMesh) ) { std::vector<std::string> shaderPlugs; liquid::RendererMgr::getInstancePtr()-> getRenderer()->getValidShaderPlugsInShadingGroup(shaderPlugs); IfMErrorWarn(dagPath.extendToShape());//extend to shape std::vector<std::string> shadingGroups; getShadingGroups(dagPath.fullPathName(), shadingGroups); for(std::size_t j=0; j<shadingGroups.size(); ++j)//for each shading group { MString shadingGroup(shadingGroups[j].c_str()); for(std::size_t k=0; k<shaderPlugs.size(); ++k)//for each shader plug { MString shaderPlug(shaderPlugs[k].c_str()); int isShaderPlugExist; cmd = "attributeQuery -node \""+shadingGroup+"\" -ex \""+shaderPlug+"\""; IfMErrorMsgWarn(MGlobal::executeCommand( cmd, isShaderPlugExist), cmd); if( isShaderPlugExist ) { //get the source shade node of $shadingGroup.$shaderPlug MStringArray shaders; cmd = "listConnections -s true -d false -plugs false (\""+shadingGroup+"\" + \"."+shaderPlug+"\")"; IfMErrorMsgWarn(MGlobal::executeCommand( cmd, shaders), cmd); if( shaders.length() > 0 )//has source shader node { onShaderNode(shaders[0], updateObjectName); }//if( shaders.length() > 0 )//has source shader node }//if( isShaderPlugExist ) }//for each shader plug }//for each shading group }//kMesh }//for(int i=0; i<descendents.length(); ++i) }
MStatus setInitialShadingGroup(const MString & dagNodeName) { MObject initShader; MDagPath dagPath; if (getObjectByName("initialShadingGroup", initShader) == MS::kSuccess && getDagPathByName(dagNodeName, dagPath) == MS::kSuccess) { MFnSet set(initShader); set.addMember(dagPath); } else { MString theError("Error getting adding "); theError += dagNodeName; theError += MString(" to initalShadingGroup."); MGlobal::displayError(theError); return MS::kFailure; } return MS::kSuccess; }
MStatus AlembicAssignInitialSGCommand::doIt(const MArgList& args) { MStatus status; MArgParser argData(syntax(), args, &status); if (argData.isFlagSet("help")) { MGlobal::displayInfo("[ExocortexAlembic]: ExocortexAlembic_assignFaceset command:"); MGlobal::displayInfo(" -m : mesh to assign the initialShadingGroup on"); return MS::kSuccess; } if (!argData.isFlagSet("mesh")) { MGlobal::displayError("No mesh/subdiv specified!"); return MS::kFailure; } MObject initShader; MDagPath dagPath; if (getObjectByName("initialShadingGroup", initShader) == MS::kSuccess && getDagPathByName(argData.flagArgumentString("mesh", 0), dagPath) == MS::kSuccess) { ESS_PROFILE_SCOPE("AlembicAssignInitialSGCommand::doIt::MFnSet"); MFnSet set(initShader); set.addMember(dagPath); } else { MString theError("Error getting adding "); theError += argData.flagArgumentString("mesh", 0); theError += MString(" to initalShadingGroup."); MGlobal::displayError(theError); return MS::kFailure; } return MS::kSuccess; }
MStatus AbcImport::doIt(const MArgList & args) { MStatus status; MArgParser argData(syntax(), args, &status); MString filename(""); MString connectRootNodes(""); MString filterString(""); MString excludeFilterString(""); MObject reparentObj = MObject::kNullObj; bool swap = false; bool createIfNotFound = false; bool removeIfNoUpdate = false; bool debugOn = false; if (argData.isFlagSet("help")) { MGlobal::displayInfo(usage); return status; } if (argData.isFlagSet("debug")) debugOn = true; if (argData.isFlagSet("reparent")) { MString parent(""); MDagPath reparentDagPath; status = argData.getFlagArgument("reparent", 0, parent); if (status == MS::kSuccess && getDagPathByName(parent, reparentDagPath) == MS::kSuccess) { reparentObj = reparentDagPath.node(); } else { MString theWarning = parent; theWarning += MString(" is not a valid DagPath"); printWarning(theWarning); } } if (!argData.isFlagSet("connect") && argData.isFlagSet("mode")) { MString modeStr; argData.getFlagArgument("mode", 0, modeStr); if (modeStr == "replace") deleteCurrentSelection(); else if (modeStr == "open") { MFileIO fileIo; fileIo.newFile(true); } } else if (argData.isFlagSet("connect")) { swap = true; argData.getFlagArgument("connect", 0, connectRootNodes); if (argData.isFlagSet("createIfNotFound")) { createIfNotFound = true; } if (argData.isFlagSet("removeIfNoUpdate")) removeIfNoUpdate = true; } if (argData.isFlagSet("filterObjects")) { argData.getFlagArgument("filterObjects", 0, filterString); } if (argData.isFlagSet("excludeFilterObjects")) { argData.getFlagArgument("excludeFilterObjects", 0, excludeFilterString); } // if the flag isn't specified we'll only do stuff marked with the Maya // meta data bool recreateColorSets = false; if (argData.isFlagSet("recreateAllColorSets")) { recreateColorSets = true; } status = argData.getCommandArgument(0, filename); MString abcNodeName; if (status == MS::kSuccess) { { MString fileRule, expandName; MString alembicFileRule = "alembicCache"; MString alembicFilePath = "cache/alembic"; MString queryFileRuleCmd; queryFileRuleCmd.format("workspace -q -fre \"^1s\"", alembicFileRule); MString queryFolderCmd; queryFolderCmd.format("workspace -en `workspace -q -fre \"^1s\"`", alembicFileRule); // query the file rule for alembic cache MGlobal::executeCommand(queryFileRuleCmd, fileRule); if (fileRule.length() > 0) { // we have alembic file rule, query the folder MGlobal::executeCommand(queryFolderCmd, expandName); } // resolve the expanded file rule if (expandName.length() == 0) { expandName = alembicFilePath; } // get the path to the alembic file rule MFileObject directory; directory.setRawFullName(expandName); MString directoryName = directory.resolvedFullName(); // resolve the relative path MFileObject absoluteFile; absoluteFile.setRawFullName(filename); absoluteFile.setResolveMethod(MFileObject::kInputFile); #if MAYA_API_VERSION < 201300 if (absoluteFile.resolvedFullName() != absoluteFile.expandedFullName()) { #else if (!MFileObject::isAbsolutePath(filename)) { #endif // this is a relative path MString absoluteFileName = directoryName + "/" + filename; absoluteFile.setRawFullName(absoluteFileName); filename = absoluteFile.resolvedFullName(); } else { filename = absoluteFile.resolvedFullName(); } } MFileObject fileObj; status = fileObj.setRawFullName(filename); if (status == MS::kSuccess && fileObj.exists()) { ArgData inputData(filename, debugOn, reparentObj, swap, connectRootNodes, createIfNotFound, removeIfNoUpdate, recreateColorSets, filterString, excludeFilterString); abcNodeName = createScene(inputData); if (inputData.mSequenceStartTime != inputData.mSequenceEndTime && inputData.mSequenceStartTime != -DBL_MAX && inputData.mSequenceEndTime != DBL_MAX) { if (argData.isFlagSet("fitTimeRange")) { MTime sec(1.0, MTime::kSeconds); setPlayback( inputData.mSequenceStartTime * sec.as(MTime::uiUnit()), inputData.mSequenceEndTime * sec.as(MTime::uiUnit()) ); } if (argData.isFlagSet("setToStartFrame")) { MTime sec(1.0, MTime::kSeconds); MGlobal::viewFrame( inputData.mSequenceStartTime * sec.as(MTime::uiUnit()) ); } } } else { MString theError("In AbcImport::doIt(), "); theError += filename; theError += MString(" doesn't exist"); printError(theError); } } MPxCommand::setResult(abcNodeName); return status; }