MStatus DDConvexHullCmd::doIt(const MArgList& args) { if (args.length() != 1) { MGlobal::displayError("Needs at least 2 args"); return MS::kFailure; } MString input = args.asString(0); MString output = args.asString(1); // Get the mObject for the input MSelectionList selList; selList.add(input); MDagPath inputMesh; selList.getDagPath(0, inputMesh); // Ensure we're looking at the shape inputMesh.extendToShape(); // Create output object MDagModifier dm; MObject outMeshNode = dm.createNode(MFn::kMesh); MFnDependencyNode outMeshDag(outMeshNode); outMeshDag.setName("poopShape#"); DDConvexHullUtils::hullOpts hullOptions; return DDConvexHullUtils::generateMayaHull(outMeshNode, inputMesh.node(), hullOptions); }
MStatus helix::doIt( const MArgList& args ) { MStatus stat; const unsigned deg = 3; // Curve Degree const unsigned ncvs = 20; // Number of CVs const unsigned spans = ncvs - deg; // Number of spans const unsigned nknots = spans+2*deg-1;// Number of knots double radius = 4.0; // Helix radius double pitch = 0.5; // Helix pitch unsigned i; // Parse the arguments. for ( i = 0; i < args.length(); i++ ) if ( MString( "-p" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { double tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) pitch = tmp; } else if ( MString( "-r" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { double tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) radius = tmp; } MPointArray controlVertices; MDoubleArray knotSequences; // Set up cvs and knots for the helix // for (i = 0; i < ncvs; i++) controlVertices.append( MPoint( radius * cos( (double)i ), pitch * (double)i, radius * sin( (double)i ) ) ); for (i = 0; i < nknots; i++) knotSequences.append( (double)i ); // Now create the curve // MFnNurbsCurve curveFn; curveFn.create( controlVertices, knotSequences, deg, MFnNurbsCurve::kOpen, false, false, MObject::kNullObj, &stat ); if ( MS::kSuccess != stat ) cout<<"Error creating curve."<<endl; return stat; }
MStatus particleSystemInfoCmd::parseArgs( const MArgList& args ) { // Parse the arguments. MStatus stat = MS::kSuccess; if( args.length() > 1 ) { MGlobal::displayError( "Too many arguments." ); return MS::kFailure; } if( args.length() == 1 ) { MString particleName = args.asString( 0, &stat ); CHECKRESULT(stat, "Failed to parse particle node name argument." ); nodeFromName( particleName, particleNode ); if( !particleNode.isNull() && !particleNode.hasFn( MFn::kParticle ) ) { MGlobal::displayError( "The named node is not a particle system." ); return MS::kFailure; } } return MS::kSuccess; }
MStatus createClip::parseArgs( const MArgList& args ) // // No arguments to parse. // { MStatus stat = MS::kSuccess; MString arg; MSelectionList list; bool charNameUsed = 0; MString charName; const MString charFlag ("-c"); const MString charFlagLong ("-char"); // Parse the arguments. for ( unsigned int i = 0; i < args.length(); i++ ) { arg = args.asString( i, &stat ); if (!stat) continue; if ( arg == charFlag || arg == charFlagLong ) { // get the char name // if (i == args.length()-1) { arg += ": must specify a character name"; displayError(arg); return MS::kFailure; } i++; args.get(i, charName); list.add(charName); charNameUsed = 1; } else { arg += ": unknown argument"; displayError(arg); return MS::kFailure; } } if (charNameUsed) { // get the character corresponding to the node name // MItSelectionList iter (list); for ( /* nothing */ ; !iter.isDone(); iter.next() ) { MObject node; iter.getDependNode(node); if (node.apiType() == MFn::kCharacter) { fCharacter = node; break; } } if (fCharacter.isNull()) { MString errMsg("Character flag must specify a character node."); displayError(errMsg); return MS::kFailure; } } return stat; }
MStatus helix2::doIt( const MArgList& args ) { MStatus status; // Parse the arguments. for ( unsigned i = 0; i < args.length(); i++ ) { if ( MString( "-p" ) == args.asString( i, &status ) && MS::kSuccess == status) { double tmp = args.asDouble( ++i, &status ); if ( MS::kSuccess == status ) pitch = tmp; } else if ( MString( "-r" ) == args.asString( i, &status ) && MS::kSuccess == status) { double tmp = args.asDouble( ++i, &status ); if ( MS::kSuccess == status ) radius = tmp; } else { MString msg = "Invalid flag: "; msg += args.asString( i ); displayError( msg ); return MS::kFailure; } } // Get the first selected curve from the selection list. MSelectionList slist; MGlobal::getActiveSelectionList( slist ); MItSelectionList list( slist, MFn::kNurbsCurve, &status ); if (MS::kSuccess != status) { cerr << "doIt: could not create selection list iterator\n"; return status; } if (list.isDone()) { cerr << "doIt: no curve has been selected\n"; return MS::kFailure; } list.getDagPath( fDagPath, fComponent ); return redoIt(); }
MStatus motionTrace::doIt( const MArgList& args ) // // Description // This method is called from MEL when this command is called. // It should set up any class data necessary for redo/undo, // parse any given arguments, and then call redoIt. // { start = 1.0; end = 60.0; by = 1.0; MStatus stat; double tmp; unsigned i; // Parse the arguments. for ( i = 0; i < args.length(); i++ ) { if ( MString( "-s" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) start = tmp; } else if ( MString( "-e" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) end = tmp; } else if ( MString( "-b" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) by = tmp; } } stat = redoIt(); return stat; }
MStatus fluidInfoCmd::parseArgs( const MArgList& args ) { // Parse the arguments. MStatus stat = MS::kSuccess; // some defaults for the number of voxels we might want to print requestedVoxels = -1; if( args.length() < 1 ) { MGlobal::displayError( "Missing fluid node name argument." ); return MS::kFailure; } else if( args.length() > 2 ) { MGlobal::displayError( "Too many arguments." ); return MS::kFailure; } fluidName = args.asString( 0, &stat ); if (stat != MS::kSuccess) { MGlobal::displayError( "Failed to parse fluid node name argument." ); return MS::kFailure; } if(args.length() == 1) { // assume that the user wants to print all the voxels // they probably won't do this more than once requestedVoxels = -1; } else { requestedVoxels = args.asInt( 1, &stat ); if (stat != MS::kSuccess) { MGlobal::displayError( "Failed to parse num voxels to pribt argument." ); return MS::kFailure; } } nodeFromName( fluidName, fluidNode ); if( fluidNode.isNull() ) { MGlobal::displayError( "There is no fluid node with the given name." ); return MS::kFailure; } if( ! fluidNode.hasFn( MFn::kFluid ) ) { MGlobal::displayError( "The named node is not a fluid." ); return MS::kFailure; } return MS::kSuccess; }
MStatus liqGetAttr::doIt( const MArgList& args ) { CM_TRACE_FUNC("liqGetAttr::doIt(args)"); MStatus status; unsigned i; MString nodeName, attrName; MSelectionList nodeList; for ( i = 0; i < args.length(); i++ ) { if ( MString( "-debug" ) == args.asString( i, &status) ) { } else if ( MString( "-node" ) == args.asString( i, &status) ) { i++; nodeName = args.asString( i, &status ) ; } else if ( MString( "-attr" ) == args.asString( i, &status) ) { i++; attrName = args.asString( i, &status ); } } nodeList.add( nodeName ); MObject depNodeObj; nodeList.getDependNode(0, depNodeObj); MFnDependencyNode depNode( depNodeObj ); MPlug attrPlug = depNode.findPlug( attrName ); MObject plugObj; attrPlug.getValue( plugObj ); if( plugObj.apiType() == MFn::kDoubleArrayData ) { MFnDoubleArrayData fnDoubleArrayData( plugObj ); const MDoubleArray& doubleArrayData( fnDoubleArrayData.array( &status ) ); for ( i = 0; i < doubleArrayData.length(); i++ ) appendToResult( doubleArrayData[i] ); } return MS::kSuccess; };
MStatus setupRGBShaders::doIt( const MArgList & args ) { unsigned int FIndex = args.flagIndex( "fp", "folderPath" ); unsigned int fIndex = args.flagIndex( "fn", "fileName" ); if( FIndex == MArgList::kInvalidArgIndex || fIndex == MArgList::kInvalidArgIndex ) { MGlobal::displayError( "Error specifying flag or flag values. \n-fp, -folderPath <folder_path> \t -fn, -fileName <file_name>" ); return MS::kFailure; } folderPath = args.asString( FIndex ); fileName = args.asString( fIndex ); MItDag meshIt( MItDag::kDepthFirst, MFn::kMesh ); for( ; !meshIt.isDone(); meshIt.next() ) { MDagPath dagPath; meshIt.getPath( dagPath ); meshObjs.append( dagPath.transform() ); } MItDag camIt( MItDag::kDepthFirst, MFn::kCamera ); for( ; !camIt.isDone(); camIt.next() ) { MDagPath dagPath; camIt.getPath( dagPath ); MFnDependencyNode camFn( dagPath.node() ); bool isRenderable; camFn.findPlug( "renderable" ).getValue( isRenderable ); if( isRenderable ) camObjs.append( dagPath.transform() ); } MGlobal::executeCommand( "setAttr miDefaultFramebuffer.datatype 5" ); return redoIt(); }
// parseArgs // MStatus viewCallbackTest::parseArgs(const MArgList& args) { MStatus status; MArgDatabase argData(syntax(), args); // Buffer operation argument variables mBufferOperation = kInvertColorBuffer; MString operationString; MString arg; for ( unsigned int i = 0; i < args.length(); i++ ) { arg = args.asString( i, &status ); if (!status) continue; if ( arg == MString(bufferOperationShortName) || arg == MString(bufferOperationLongName) ) { if (i == args.length()-1) { arg += ": must specify a buffer operation."; displayError(arg); return MS::kFailure; } i++; args.get(i, operationString ); bool validOperation = false; for (unsigned int k=0; k<_NUMBER_BUFFER_OPERATIONS_; k++) { if (bufferOperationStrings[i] == operationString) { mBufferOperation = bufferOperations[k]; validOperation = true; } } if (!validOperation) status.perror("Invalid operation specified. Using invert by default."); } } // Read off the panel name status = argData.getCommandArgument(0, mPanelName); if (!status) { status.perror("No panel name specified as command argument"); return status; } return MS::kSuccess; }
MStatus Pick::doIt( const MArgList& args ) { MStatus res = MS::kSuccess; unsigned len = args.length(); if ( len > 0 ) { MString object_name( args.asString(0) ); if ( MS::kSuccess != MGlobal::selectByName( object_name ) ) cerr << "Object " << object_name.asChar() << " not found\n"; } else { cerr << "No Object name specified\n"; } return res; }
MStatus dagPoseInfo::parseArgs( const MArgList& args ) // // There is one mandatory flag: -f/-file <filename> // { MStatus stat; MString arg; MString fileName; const MString fileFlag ("-f"); const MString fileFlagLong ("-file"); // Parse the arguments. for ( unsigned int i = 0; i < args.length(); i++ ) { arg = args.asString( i, &stat ); if (!stat) continue; if ( arg == fileFlag || arg == fileFlagLong ) { // get the file name // if (i == args.length()-1) { arg += ": must specify a file name"; displayError(arg); return MS::kFailure; } i++; args.get(i, fileName); } else { arg += ": unknown argument"; displayError(arg); return MS::kFailure; } } file = fopen(fileName.asChar(),"wb"); if (!file) { MString openError("Could not open: "); openError += fileName; displayError(openError); stat = MS::kFailure; } return stat; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- uint CVstSmdIOCmd::GetExportType( const MArgDatabase &mArgDatabase ) { uint retVal( 0 ); if ( mArgDatabase.isFlagSet( kOptExportType ) ) { MString optExportType; MArgList tmpArgList; const uint etEnd( mArgDatabase.numberOfFlagUses( kOptExportType ) ); for ( uint eti( 0 ); eti != etEnd; ++eti ) { mArgDatabase.getFlagArgumentList( kOptExportType, eti, tmpArgList ); optExportType = tmpArgList.asString( 0 ); if ( strnicmp( optExportType.asChar(), "r", 1 ) == 0 || strnicmp( optExportType.asChar(), "m", 1 ) == 0 ) { retVal |= CSmdExport::kReference; } else if ( strnicmp( optExportType.asChar(), "p", 1 ) == 0 ) { retVal |= CSmdExport::kPhysModel; } else if ( strnicmp( optExportType.asChar(), "a", 1 ) == 0 || strnicmp( optExportType.asChar(), "s", 1 ) == 0 ) { retVal |= CSmdExport::kAnimation; } else if ( strnicmp( optExportType.asChar(), "v", 1 ) == 0 ) { retVal |= CSmdExport::kVTA; } else { MGlobal::displayWarning( MString( "Cannot determine the type of export from -et " ) + optExportType + ", assume reference/model" ); } } } if ( retVal == 0 ) { retVal = CSmdExport::kReference; } return retVal; }
bool readMultiUseFlag(const char flagName[], MArgDatabase &args, MSelectionList &sel){ if (!args.isFlagSet(flagName)) return false; MStatus status; for(unsigned int i=0,numUses = args.numberOfFlagUses(flagName); i<numUses; i++ ) { MArgList argList; status = args.getFlagArgumentList( flagName, i, argList ); CHECK_STATUS("problem reading multi flag",status); MString name = argList.asString( 0, &status ); CHECK_STATUS("problem reading multi flag (2)",status); status = sel.add(name); CHECK_STATUS("problem adding item to selection",status); } return true; }
MStatus PRTAttrs::doIt(const MArgList& args) { MStatus stat; MString prtNodeName = args.asString(0, &stat); MCHECK(stat); MSelectionList tempList; tempList.add(prtNodeName); MObject prtNode; MCHECK(tempList.getDependNode(0, prtNode)); MFnDependencyNode fNode(prtNode, &stat); MCHECK(stat); if(fNode.typeId().id() != PRT_TYPE_ID) return MS::kFailure; MString sRulePkg; updateRuleFiles(fNode, getStringParameter(prtNode, ((PRTNode*)fNode.userNode())->rulePkg, sRulePkg)); MGlobal::executeCommand(MString("refreshEditorTemplates")); return MS::kSuccess; }
MStatus liqIPRNodeMessage::doIt( const MArgList& args) // // Takes the nodes that are on the active selection list and adds an // attriubte changed callback to each one. // { MStatus stat; for( unsigned i( 0 ); i < args.length(); i++ ) { MString arg = args.asString( i, &stat ); IfMErrorWarn(stat); if( (arg == kRegisterFlag) || (arg == kRegisterFlagLong) ){ isRunningIPR = 1; liqRibTranslator::getInstancePtr()->IPRRenderBegin(); IfMErrorWarn(registerCallback()); //liqRibTranslator::getInstancePtr()->IPRDoIt(); } else if( (arg == kUnregisterFlag) || (arg == kUnregisterFlagLong) ){ IfMErrorWarn(unregisterCallback()); liqRibTranslator::getInstancePtr()->IPRRenderEnd(); isRunningIPR = 0; } else if( (arg == kIsRunningIPR) || (arg == kIsRunningIPRLong) ){ setResult(isRunningIPR); } else{ liquidMessage2(messageError,"Parameter [%s] is undefined in liqIPRNodeMessage.", arg.asChar()); return MS::kUnknownParameter; } } return MS::kSuccess; }
//-***************************************************************************** MStatus AbcExport::doIt( const MArgList & args ) { MStatus status; MTime oldCurTime = MAnimControl::currentTime(); MArgParser argData( syntax(), args, &status ); if ( status != MS::kSuccess ) { return status; } unsigned int numberOfArguments = args.length(); MString msg; msg += "AlembicSimpleAbcExport [options] OutputFileName.abc\n\n"; msg += "Options:\n"; msg += "-h / help Print this message.\n"; msg += "\n"; msg += "-fs / frameStart int (default: 0)\n"; msg += "The export start frame\n"; msg += "\n"; msg += "-fe / frameEnd int (default: 0)\n"; msg += "The export end frame\n"; msg += "\n"; msg += "-v / verbose Verbose output\n"; msg += "\n"; if ( argData.isFlagSet( "help" ) ) { MGlobal::displayInfo( msg ); return MS::kSuccess; } bool verbose = argData.isFlagSet( "verbose" ); int frameStart = 0; if ( argData.isFlagSet( "frameStart" ) ) { argData.getFlagArgument( "frameStart", 0, frameStart ); } int frameEnd = 0; if ( argData.isFlagSet( "frameEnd" ) ) { argData.getFlagArgument( "frameEnd", 0, frameEnd ); } // status = argData.getCommandArgument(0, argStr); // Get filenameArgument MString fileNameStr = args.asString( numberOfArguments-1, &status ); // Okay, do it. Parameters params; params.fileName = fileNameStr.asChar(); params.startFrame = frameStart; params.endFrame = frameEnd; params.verbose = verbose; params.polysAsSubds = false; params.deforming = true; params.allUserAttributes = true; params.allMayaAttributes = false; try { status = AbcExportSelected( params ); } catch ( std::exception &exc ) { MGlobal::displayError( exc.what() ); status = MS::kFailure; } catch ( ... ) { MGlobal::displayError( "AlembicSimpleAbcExport: UNKNOWN EXCEPTION" ); status = MS::kFailure; } return status; }
MStatus cvPos::doIt( const MArgList& args ) { MString componentName; MSpace::Space transformSpace = MSpace::kWorld; for (unsigned int i = 0; i < args.length (); i++) { MString argStr; args.get (i, argStr); if (MString ("-l") == argStr || MString ("-local") == argStr) transformSpace = MSpace::kObject; else if (MString ("-w") == args.asString (i) || MString ("-world") == argStr) transformSpace = MSpace::kWorld; else componentName = argStr; } MObject component; MDagPath dagPath; if (!componentName.length ()) { MSelectionList activeList; MGlobal::getActiveSelectionList (activeList); MItSelectionList iter (activeList, MFn::kComponent); if (iter.isDone ()) { displayError ("No components selected"); return MS::kFailure; } else { iter.getDagPath (dagPath, component); iter.next (); if (!iter.isDone ()) { displayError ("More than one component is selected"); return MS::kFailure; } } } else { MSelectionList list; if (! list.add( componentName ) ) { componentName += ": no such component"; displayError(componentName); return MS::kFailure; // no such component } MItSelectionList iter( list ); iter.getDagPath( dagPath, component ); } if (component.isNull()) { displayError("not a component"); return MS::kFailure; } switch (component.apiType()) { case MFn::kCurveCVComponent: { MItCurveCV curveCVIter( dagPath, component ); point = curveCVIter.position(transformSpace ); curveCVIter.next(); if (!curveCVIter.isDone()) { displayError ("More than one component is selected"); return MS::kFailure; } break; } case MFn::kSurfaceCVComponent: { MItSurfaceCV surfCVIter( dagPath, component, true ); point = surfCVIter.position(transformSpace ); surfCVIter.next(); if (!surfCVIter.isDone()) { displayError ("More than one component is selected"); return MS::kFailure; } break; } case MFn::kMeshVertComponent: { MItMeshVertex vertexIter( dagPath, component ); point = vertexIter.position(transformSpace ); vertexIter.next(); if (!vertexIter.isDone()) { displayError ("More than one component is selected"); return MS::kFailure; } break; } default: cerr << "Selected unsupported type: (" << component.apiType() << "): " << component.apiTypeStr() << endl; } return redoIt(); }
MStatus usdImport::doIt(const MArgList & args) { MStatus status; MArgDatabase argData(syntax(), args, &status); // Check that all flags were valid if (status != MS::kSuccess) { MGlobal::displayError("Invalid parameters detected. Exiting."); return status; } JobImportArgs jobArgs; //bool verbose = argData.isFlagSet("verbose"); std::string mFileName; if (argData.isFlagSet("file")) { // Get the value MString tmpVal; argData.getFlagArgument("file", 0, tmpVal); // resolve the path into an absolute path MFileObject absoluteFile; absoluteFile.setRawFullName(tmpVal); absoluteFile.setRawFullName( absoluteFile.resolvedFullName() ); // Make sure an absolute path if (!absoluteFile.exists()) { MGlobal::displayError("File does not exist. Exiting."); return MS::kFailure; } // Set the fileName mFileName = absoluteFile.resolvedFullName().asChar(); MGlobal::displayInfo(MString("Importing ") + MString(mFileName.c_str())); } if (mFileName.empty()) { MString error = "Non empty file specified. Skipping..."; MGlobal::displayError(error); return MS::kFailure; } if (argData.isFlagSet("shadingMode")) { MString stringVal; argData.getFlagArgument("shadingMode", 0, stringVal); TfToken shadingMode(stringVal.asChar()); if (shadingMode.IsEmpty()) { jobArgs.shadingMode = PxrUsdMayaShadingModeTokens->displayColor; } else { if (PxrUsdMayaShadingModeRegistry::GetInstance().GetExporter(shadingMode)) { jobArgs.shadingMode = shadingMode; } else { MGlobal::displayError(TfStringPrintf("No shadingMode '%s' found. Setting shadingMode='none'", shadingMode.GetText()).c_str()); jobArgs.shadingMode = PxrUsdMayaShadingModeTokens->none; } } } if (argData.isFlagSet("readAnimData")) { bool tmpBool = false; argData.getFlagArgument("readAnimData", 0, tmpBool); jobArgs.readAnimData = tmpBool; } // Specify usd PrimPath. Default will be "/<useFileBasename>" std::string mPrimPath; if (argData.isFlagSet("primPath")) { // Get the value MString tmpVal; argData.getFlagArgument("primPath", 0, tmpVal); mPrimPath = tmpVal.asChar(); } // Add variant (variantSet, variant). Multi-use std::map<std::string,std::string> mVariants; for (unsigned int i=0; i < argData.numberOfFlagUses("variant"); ++i) { MArgList tmpArgList; status = argData.getFlagArgumentList("variant", i, tmpArgList); // Get the value MString tmpKey = tmpArgList.asString(0, &status); MString tmpVal = tmpArgList.asString(1, &status); mVariants.insert( std::pair<std::string, std::string>(tmpKey.asChar(), tmpVal.asChar()) ); } if (argData.isFlagSet("assemblyRep")) { // Get the value MString stringVal; argData.getFlagArgument("assemblyRep", 0, stringVal); std::string assemblyRep = stringVal.asChar(); if (not assemblyRep.empty()) { jobArgs.assemblyRep = TfToken(assemblyRep); } } // Create the command if (mUsdReadJob) { delete mUsdReadJob; } // pass in assemblyTypeName and proxyShapeTypeName mUsdReadJob = new usdReadJob(mFileName, mPrimPath, mVariants, jobArgs, _assemblyTypeName, _proxyShapeTypeName); // Add optional command params if (argData.isFlagSet("parent")) { // Get the value MString tmpVal; argData.getFlagArgument("parent", 0, tmpVal); if (tmpVal.length()) { MSelectionList selList; selList.add(tmpVal); MDagPath dagPath; status = selList.getDagPath(0, dagPath); if (status != MS::kSuccess) { std::string errorStr = TfStringPrintf( "Invalid path \"%s\"for -parent.", tmpVal.asChar()); MGlobal::displayError(MString(errorStr.c_str())); return MS::kFailure; } mUsdReadJob->setMayaRootDagPath( dagPath ); } } // Execute the command std::vector<MDagPath> addedDagPaths; bool success = mUsdReadJob->doIt(&addedDagPaths); if (success) { TF_FOR_ALL(iter, addedDagPaths) { appendToResult(iter->fullPathName()); } }
MStatus AlembicExportCommand::doIt(const MArgList &args) { ESS_PROFILE_SCOPE("AlembicExportCommand::doIt"); MStatus status = MS::kFailure; MTime currentAnimStartTime = MAnimControl::animationStartTime(), currentAnimEndTime = MAnimControl::animationEndTime(), oldCurTime = MAnimControl::currentTime(), curMinTime = MAnimControl::minTime(), curMaxTime = MAnimControl::maxTime(); MArgParser argData(syntax(), args, &status); if (argData.isFlagSet("help")) { // TODO: implement help for this command // MGlobal::displayInfo(util::getHelpText()); return MS::kSuccess; } unsigned int jobCount = argData.numberOfFlagUses("jobArg"); MStringArray jobStrings; if (jobCount == 0) { // TODO: display dialog MGlobal::displayError("[ExocortexAlembic] No jobs specified."); MPxCommand::setResult( "Error caught in AlembicExportCommand::doIt: no job specified"); return status; } else { // get all of the jobstrings for (unsigned int i = 0; i < jobCount; i++) { MArgList jobArgList; argData.getFlagArgumentList("jobArg", i, jobArgList); jobStrings.append(jobArgList.asString(0)); } } // create a vector to store the jobs std::vector<AlembicWriteJob *> jobPtrs; double minFrame = 1000000.0; double maxFrame = -1000000.0; double maxSteps = 1; double maxSubsteps = 1; // init the curve accumulators AlembicCurveAccumulator::Initialize(); try { // for each job, check the arguments bool failure = false; for (unsigned int i = 0; i < jobStrings.length(); ++i) { double frameIn = 1.0; double frameOut = 1.0; double frameSteps = 1.0; double frameSubSteps = 1.0; MString filename; bool purepointcache = false; bool normals = true; bool uvs = true; bool facesets = true; bool bindpose = true; bool dynamictopology = false; bool globalspace = false; bool withouthierarchy = false; bool transformcache = false; bool useInitShadGrp = false; bool useOgawa = false; // Later, will need to be changed! MStringArray objectStrings; std::vector<std::string> prefixFilters; std::set<std::string> attributes; std::vector<std::string> userPrefixFilters; std::set<std::string> userAttributes; MObjectArray objects; std::string search_str, replace_str; // process all tokens of the job MStringArray tokens; jobStrings[i].split(';', tokens); for (unsigned int j = 0; j < tokens.length(); j++) { MStringArray valuePair; tokens[j].split('=', valuePair); if (valuePair.length() != 2) { MGlobal::displayWarning( "[ExocortexAlembic] Skipping invalid token: " + tokens[j]); continue; } const MString &lowerValue = valuePair[0].toLowerCase(); if (lowerValue == "in") { frameIn = valuePair[1].asDouble(); } else if (lowerValue == "out") { frameOut = valuePair[1].asDouble(); } else if (lowerValue == "step") { frameSteps = valuePair[1].asDouble(); } else if (lowerValue == "substep") { frameSubSteps = valuePair[1].asDouble(); } else if (lowerValue == "normals") { normals = valuePair[1].asInt() != 0; } else if (lowerValue == "uvs") { uvs = valuePair[1].asInt() != 0; } else if (lowerValue == "facesets") { facesets = valuePair[1].asInt() != 0; } else if (lowerValue == "bindpose") { bindpose = valuePair[1].asInt() != 0; } else if (lowerValue == "purepointcache") { purepointcache = valuePair[1].asInt() != 0; } else if (lowerValue == "dynamictopology") { dynamictopology = valuePair[1].asInt() != 0; } else if (lowerValue == "globalspace") { globalspace = valuePair[1].asInt() != 0; } else if (lowerValue == "withouthierarchy") { withouthierarchy = valuePair[1].asInt() != 0; } else if (lowerValue == "transformcache") { transformcache = valuePair[1].asInt() != 0; } else if (lowerValue == "filename") { filename = valuePair[1]; } else if (lowerValue == "objects") { // try to find each object valuePair[1].split(',', objectStrings); } else if (lowerValue == "useinitshadgrp") { useInitShadGrp = valuePair[1].asInt() != 0; } // search/replace else if (lowerValue == "search") { search_str = valuePair[1].asChar(); } else if (lowerValue == "replace") { replace_str = valuePair[1].asChar(); } else if (lowerValue == "ogawa") { useOgawa = valuePair[1].asInt() != 0; } else if (lowerValue == "attrprefixes") { splitListArg(valuePair[1], prefixFilters); } else if (lowerValue == "attrs") { splitListArg(valuePair[1], attributes); } else if (lowerValue == "userattrprefixes") { splitListArg(valuePair[1], userPrefixFilters); } else if (lowerValue == "userattrs") { splitListArg(valuePair[1], userAttributes); } else { MGlobal::displayWarning( "[ExocortexAlembic] Skipping invalid token: " + tokens[j]); continue; } } // now check the object strings for (unsigned int k = 0; k < objectStrings.length(); k++) { MSelectionList sl; MString objectString = objectStrings[k]; sl.add(objectString); MDagPath dag; for (unsigned int l = 0; l < sl.length(); l++) { sl.getDagPath(l, dag); MObject objRef = dag.node(); if (objRef.isNull()) { MGlobal::displayWarning("[ExocortexAlembic] Skipping object '" + objectStrings[k] + "', not found."); break; } // get all parents MObjectArray parents; // check if this is a camera bool isCamera = false; for (unsigned int m = 0; m < dag.childCount(); ++m) { MFnDagNode child(dag.child(m)); MFn::Type ctype = child.object().apiType(); if (ctype == MFn::kCamera) { isCamera = true; break; } } if (dag.node().apiType() == MFn::kTransform && !isCamera && !globalspace && !withouthierarchy) { MDagPath ppath = dag; while (!ppath.node().isNull() && ppath.length() > 0 && ppath.isValid()) { parents.append(ppath.node()); if (ppath.pop() != MStatus::kSuccess) { break; } } } else { parents.append(dag.node()); } // push all parents in while (parents.length() > 0) { bool found = false; for (unsigned int m = 0; m < objects.length(); m++) { if (objects[m] == parents[parents.length() - 1]) { found = true; break; } } if (!found) { objects.append(parents[parents.length() - 1]); } parents.remove(parents.length() - 1); } // check all of the shapes below if (!transformcache) { sl.getDagPath(l, dag); for (unsigned int m = 0; m < dag.childCount(); m++) { MFnDagNode child(dag.child(m)); if (child.isIntermediateObject()) { continue; } objects.append(child.object()); } } } } // check if we have incompatible subframes if (maxSubsteps > 1.0 && frameSubSteps > 1.0) { const double part = (frameSubSteps > maxSubsteps) ? (frameSubSteps / maxSubsteps) : (maxSubsteps / frameSubSteps); if (abs(part - floor(part)) > 0.001) { MString frameSubStepsStr, maxSubstepsStr; frameSubStepsStr.set(frameSubSteps); maxSubstepsStr.set(maxSubsteps); MGlobal::displayError( "[ExocortexAlembic] You cannot combine substeps " + frameSubStepsStr + " and " + maxSubstepsStr + " in one export. Aborting."); return MStatus::kInvalidParameter; } } // remember the min and max values for the frames if (frameIn < minFrame) { minFrame = frameIn; } if (frameOut > maxFrame) { maxFrame = frameOut; } if (frameSteps > maxSteps) { maxSteps = frameSteps; } if (frameSteps > 1.0) { frameSubSteps = 1.0; } if (frameSubSteps > maxSubsteps) { maxSubsteps = frameSubSteps; } // check if we have a filename if (filename.length() == 0) { MGlobal::displayError("[ExocortexAlembic] No filename specified."); for (size_t k = 0; k < jobPtrs.size(); k++) { delete (jobPtrs[k]); } MPxCommand::setResult( "Error caught in AlembicExportCommand::doIt: no filename " "specified"); return MStatus::kFailure; } // construct the frames MDoubleArray frames; { const double frameIncr = frameSteps / frameSubSteps; for (double frame = frameIn; frame <= frameOut; frame += frameIncr) { frames.append(frame); } } AlembicWriteJob *job = new AlembicWriteJob(filename, objects, frames, useOgawa, prefixFilters, attributes, userPrefixFilters, userAttributes); job->SetOption("exportNormals", normals ? "1" : "0"); job->SetOption("exportUVs", uvs ? "1" : "0"); job->SetOption("exportFaceSets", facesets ? "1" : "0"); job->SetOption("exportInitShadGrp", useInitShadGrp ? "1" : "0"); job->SetOption("exportBindPose", bindpose ? "1" : "0"); job->SetOption("exportPurePointCache", purepointcache ? "1" : "0"); job->SetOption("exportDynamicTopology", dynamictopology ? "1" : "0"); job->SetOption("indexedNormals", "1"); job->SetOption("indexedUVs", "1"); job->SetOption("exportInGlobalSpace", globalspace ? "1" : "0"); job->SetOption("flattenHierarchy", withouthierarchy ? "1" : "0"); job->SetOption("transformCache", transformcache ? "1" : "0"); // check if the search/replace strings are valid! if (search_str.length() ? !replace_str.length() : replace_str.length()) // either search or // replace string is // missing or empty! { ESS_LOG_WARNING( "Missing search or replace parameter. No strings will be " "replaced."); job->replacer = SearchReplace::createReplacer(); } else { job->replacer = SearchReplace::createReplacer(search_str, replace_str); } // check if the job is satifsied if (job->PreProcess() != MStatus::kSuccess) { MGlobal::displayError("[ExocortexAlembic] Job skipped. Not satisfied."); delete (job); failure = true; break; } // push the job to our registry MGlobal::displayInfo("[ExocortexAlembic] Using WriteJob:" + jobStrings[i]); jobPtrs.push_back(job); } if (failure) { for (size_t k = 0; k < jobPtrs.size(); k++) { delete (jobPtrs[k]); } return MS::kFailure; } // compute the job count unsigned int jobFrameCount = 0; for (size_t i = 0; i < jobPtrs.size(); i++) jobFrameCount += (unsigned int)jobPtrs[i]->GetNbObjects() * (unsigned int)jobPtrs[i]->GetFrames().size(); // now, let's run through all frames, and process the jobs const double frameRate = MTime(1.0, MTime::kSeconds).as(MTime::uiUnit()); const double incrSteps = maxSteps / maxSubsteps; double nextFrame = minFrame + incrSteps; for (double frame = minFrame; frame <= maxFrame; frame += incrSteps, nextFrame += incrSteps) { MAnimControl::setCurrentTime(MTime(frame / frameRate, MTime::kSeconds)); MAnimControl::setAnimationEndTime( MTime(nextFrame / frameRate, MTime::kSeconds)); MAnimControl::playForward(); // this way, it forces Maya to play exactly // one frame! and particles are updated! AlembicCurveAccumulator::StartRecordingFrame(); for (size_t i = 0; i < jobPtrs.size(); i++) { MStatus status = jobPtrs[i]->Process(frame); if (status != MStatus::kSuccess) { MGlobal::displayError("[ExocortexAlembic] Job aborted :" + jobPtrs[i]->GetFileName()); for (size_t k = 0; k < jobPtrs.size(); k++) { delete (jobPtrs[k]); } restoreOldTime(currentAnimStartTime, currentAnimEndTime, oldCurTime, curMinTime, curMaxTime); return status; } } AlembicCurveAccumulator::StopRecordingFrame(); } } catch (...) { MGlobal::displayError( "[ExocortexAlembic] Jobs aborted, force closing all archives!"); for (std::vector<AlembicWriteJob *>::iterator beg = jobPtrs.begin(); beg != jobPtrs.end(); ++beg) { (*beg)->forceCloseArchive(); } restoreOldTime(currentAnimStartTime, currentAnimEndTime, oldCurTime, curMinTime, curMaxTime); MPxCommand::setResult("Error caught in AlembicExportCommand::doIt"); status = MS::kFailure; } MAnimControl::stop(); AlembicCurveAccumulator::Destroy(); // restore the animation start/end time and the current time! restoreOldTime(currentAnimStartTime, currentAnimEndTime, oldCurTime, curMinTime, curMaxTime); // delete all jobs for (size_t k = 0; k < jobPtrs.size(); k++) { delete (jobPtrs[k]); } // remove all known archives deleteAllArchives(); return status; }
MStatus volumeLight::doIt( const MArgList& args ) { MStatus stat; double arc = 180.0f; double coneEndRadius = 0.0f; MFnVolumeLight::MLightDirection volumeLightDirection = MFnVolumeLight::kOutward; MFnVolumeLight::MLightShape lightShape = MFnVolumeLight::kConeVolume; bool emitAmbient = true; unsigned i; // Parse the arguments. for ( i = 0; i < args.length(); i++ ) { if ( MString( "-a" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { double tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) arc = tmp; } else if ( MString( "-c" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { double tmp = args.asDouble( ++i, &stat ); if ( MS::kSuccess == stat ) coneEndRadius = tmp; } else if ( MString( "-e" ) == args.asString( i, &stat ) && MS::kSuccess == stat) { bool tmp = args.asBool( ++i, &stat ); if ( MS::kSuccess == stat ) emitAmbient = tmp; } } MFnVolumeLight light; light.create( true, &stat); cout<<"What's up?"; if ( MS::kSuccess != stat ) { cout<<"Error creating light."<<endl; return stat; } stat = light.setArc ((float)arc); if ( MS::kSuccess != stat ) { cout<<"Error setting \"arc\" attribute."<<endl; return stat; } stat = light.setVolumeLightDirection (volumeLightDirection); if ( MS::kSuccess != stat ) { cout<<"Error setting \"volumeLightDirection\" attribute."<<endl; return stat; } stat = light.setConeEndRadius ((float)coneEndRadius); if ( MS::kSuccess != stat ) { cout<<"Error setting \"coneEndRadius\" attribute."<<endl; return stat; } stat = light.setEmitAmbient (emitAmbient); if ( MS::kSuccess != stat ) { cout<<"Error setting \"emitAmbient\" attribute."<<endl; return stat; } stat = light.setLightShape (lightShape); if ( MS::kSuccess != stat ) { cout<<"Error setting \"lightShape\" attribute."<<endl; return stat; } double arcGet = light.arc (&stat); if ( MS::kSuccess != stat || arcGet != arc) { cout<<"Error getting \"arc\" attribute."<<endl; return stat; } MFnVolumeLight::MLightDirection volumeLightDirectionGet = light.volumeLightDirection (&stat); if ( MS::kSuccess != stat || volumeLightDirectionGet != volumeLightDirection) { cout<<"Error getting \"volumeLightDirection\" attribute."<<endl; return stat; } double coneEndRadiusGet = light.coneEndRadius (&stat); if ( MS::kSuccess != stat || coneEndRadiusGet != coneEndRadius) { cout<<"Error getting \"coneEndRadius\" attribute."<<endl; return stat; } bool emitAmbientGet = light.emitAmbient (&stat); if ( MS::kSuccess != stat || emitAmbientGet != emitAmbient) { cout<<"Error getting \"emitAmbient\" attribute."<<endl; return stat; } MFnVolumeLight::MLightShape lightShapeGet = light.lightShape (&stat); if ( MS::kSuccess != stat || lightShapeGet != lightShape) { cout<<"Error getting \"lightShape\" attribute."<<endl; return stat; } // Get reference to the penumbra ramp. MRampAttribute ramp = light.penumbraRamp (&stat); if ( MS::kSuccess != stat ) { cout<<"Error getting \"penumbraRamp\" attribute."<<endl; return stat; } MFloatArray a, b; MIntArray c,d; // Get the entries in the ramp ramp.getEntries (d, a, b, c, &stat); if ( MS::kSuccess != stat ) { cout<<"Error getting entries from \"penumbraRamp\" attribute."<<endl; return stat; } // There should be 2 entries by default. if (d.length() != 2) { cout<<"Invalid number of entries in \"penumbraRamp\" attribute."<<endl; return stat; } MFloatArray a1, b1; MIntArray c1; // Prepare an array of entries to add. // In this case we are just adding 1 more entry // at position 0.5 with a curve value of 0.25 and a linear interpolation. a1.append (0.5f); b1.append (0.25f); c1.append (MRampAttribute::kLinear); // Add it to the curve ramp ramp.addEntries (a1, b1, c1, &stat); if ( MS::kSuccess != stat) { cout<<"Error adding entries to \"penumbraRamp\" attribute."<<endl; return stat; } // Get the entries to make sure that the above add actually worked. MFloatArray a2, b2; MIntArray c2,d2; ramp.getEntries (d2, a2, b2, c2, &stat); if ( MS::kSuccess != stat ) { cout<<"Error getting entries from \"penumbraRamp\" attribute."<<endl; return stat; } if ( a.length() + a1.length() != a2.length()) { cout<<"Invalid number of entries in \"penumbraRamp\" attribute."<<endl; return stat; } // Now try to interpolate the value at a point float newVal = -1; ramp.getValueAtPosition(.3f, newVal, &stat); if ( MS::kSuccess != stat ) { cout<<"Error interpolating value from \"penumbraRamp\" attribute."<<endl; return stat; } if ( !EQUAL(newVal, .15f)) { cout<<"Invalid interpolation in \"penumbraRamp\" expected .15 got "<<newVal <<" ."<<endl; } // Try to delete an entry in an incorrect manner. // This delete will work because there is an entry at 0, // However we should never do it this way, because the entries // array can become sparse, so trying to delete an entry without // checking whether an entry exists at that index can cause a failure. MIntArray entriesToDelete; entriesToDelete.append (0); ramp.deleteEntries (entriesToDelete, &stat); if ( MS::kSuccess != stat ) { cout<<"Error deleting entries from \"penumbraRamp\" attribute."<<endl; return stat; } // Check to see whether the above delete worked. // As mentioned earlier it did work, but we shouldn't do it this way. // To illustrate why we shouldn't do it this way, we'll try to delete // entry at index 0 ( this no longer exists) ramp.getEntries (d2, a2, b2, c2, &stat); if ( a2.length() != 2) { cout<<"Invalid number of entries in \"penumbraRamp\" attribute."<<endl; return stat; } // Trying to delete entry at 0. entriesToDelete.clear(); entriesToDelete.append (0); ramp.deleteEntries (entriesToDelete, &stat); // It will fail because no entry exists. if ( MS::kSuccess == stat) { cout<<"Error deleting entries from \"penumbraRamp\" attribute."<<endl; return stat; } if ( a2.length() != 2) { cout<<"Invalid number of entries in \"penumbraRamp\" attribute."<<endl; return stat; } // The proper way to delete is to retrieve the index by calling "getEntries" ramp.getEntries (d2, a2, b2, c2, &stat); entriesToDelete.clear(); entriesToDelete.append (d2[0]); // Delete the first logical entry in the entry array. ramp.deleteEntries (entriesToDelete, &stat); if ( MS::kSuccess != stat) { cout<<"Error deleting entries from \"penumbraRamp\" attribute."<<endl; return stat; } // There should be only 1 entry left. ramp.getEntries (d2, a2, b2, c2, &stat); if ( MS::kSuccess != stat) { cout<<"Error getting entries from \"penumbraRamp\" attribute."<<endl; return stat; } entriesToDelete.clear(); entriesToDelete.append (d2[0]); // Can't delete the last entry, should return failure. ramp.deleteEntries (entriesToDelete, &stat); if ( MS::kSuccess == stat) { cout<<"Error deleting entries from \"penumbraRamp\" attribute."<<endl; return stat; } ramp.setPositionAtIndex (0.0f, d2[0], &stat); if ( MS::kSuccess != stat) { printf("Error setting position at index: %d, of \"penumbraRamp\" attribute.\n", d2[0]); return stat; } ramp.setValueAtIndex (1.0f, d2[0], &stat); if ( MS::kSuccess != stat) { printf("Error setting value at index: %d, of \"penumbraRamp\" attribute.\n", d2[0]); return stat; } ramp.setInterpolationAtIndex (MRampAttribute::kNone, d2[0], &stat); if ( MS::kSuccess != stat) { printf("Error setting interpolation at index: %d, of \"penumbraRamp\" attribute.\n", d2[0]); return stat; } MRampAttribute ramp2 = light.colorRamp (&stat); if ( MS::kSuccess != stat) { cout<<"Error getting \"colorRamp\" attribute."<<endl; return stat; } MFloatArray a3; MColorArray b3; MIntArray c3,d3; // Get the entries in the ramp ramp2.getEntries (d3, a3, b3, c3, &stat); if ( MS::kSuccess != stat) { cout<<"Error getting entries from \"colorRamp\" attribute."<<endl; return stat; } // There should be 2 entries by default. if ( d3.length() != 2) { cout<<"Invalid number of entries in \"colorRamp\" attribute."<<endl; return stat; } MFloatArray a4; MColorArray b4; MIntArray c4; // Prepare an array of entries to add. // In this case we are just adding 1 more entry // at position 0.5 withe curve value of 0.5 and a linear interpolation. a4.append (0.5f); b4.append (MColor (0.0f, 0.0f, 0.75f)); c4.append (MRampAttribute::kLinear); // Add it to the curve ramp ramp2.addEntries (a4, b4, c4, &stat); if ( MS::kSuccess != stat) { cout<<"Error adding entries to \"colorRamp\" attribute."<<endl; return stat; } // Get the entries to make sure that the above add actually worked. MFloatArray a5; MColorArray b5; MIntArray c5,d5; ramp2.getEntries (d5, a5, b5, c5, &stat); if ( MS::kSuccess != stat) { cout<<"Error getting entries from \"colorRamp\" attribute."<<endl; return stat; } if ( a3.length() + a4.length() != a5.length()) { cout<<"Invalid number of entries in \"colorRamp\" attribute."<<endl; return stat; } // Now try to interpolate the color at a point MColor newCol(0.0, 0.0, 0.0); ramp2.getColorAtPosition(.3f, newCol, &stat); if ( MS::kSuccess != stat ) { cout<<"Error interpolating color from \"penumbraRamp\" attribute."<<endl; return stat; } if ( !EQUAL(newCol[2], .45)) { cout<<"Invalid color interpolation in \"colorRamp\" expected .45 got "<<newCol[2]<<endl; } MColor clr (0.5, 0.5, 0.0); ramp2.setColorAtIndex (clr, d5[0], &stat); if ( MS::kSuccess != stat) { cout<<"Error setting color at index: "<<d5[0] <<", of \"colorRamp\" attribute."<<endl; return stat; } ramp2.setInterpolationAtIndex (MRampAttribute::kSpline, d5[1], &stat); if ( MS::kSuccess != stat) { cout<<"Error setting interpolation at index: "<<d5[1] <<", of \"colorRamp\" attribute."<<endl; return stat; } return stat; }
MStatus testExCameraSetCmd::parseArgs( const MArgList& args) // // Parses the command line arguments. // { MStatus status; // Get the flags. If the create or help flags are used, return success and ignore the other flags. createUsed = (args.flagIndex(kCreateFlag, kCreateFlagLong) != MArgList::kInvalidArgIndex); editUsed = (args.flagIndex(kEditFlag, kEditFlagLong) != MArgList::kInvalidArgIndex); queryUsed = (args.flagIndex(kQueryFlag, kQueryFlagLong) != MArgList::kInvalidArgIndex); helpUsed = (args.flagIndex(kHelpFlag, kHelpFlagLong) != MArgList::kInvalidArgIndex); numLayersUsed = (args.flagIndex(kNumLayersFlag, kNumLayersFlagLong) != MArgList::kInvalidArgIndex); // If flags are used which require no other information, return now. if (createUsed || helpUsed) return MS::kSuccess; unsigned int maxArg = args.length() - 1; unsigned int activeIndex = args.flagIndex(kActiveFlag, kActiveFlagLong); unsigned int appendCameraIndex = args.flagIndex(kAppendCameraFlag, kAppendCameraFlagLong); unsigned int appendCameraAndSetIndex = args.flagIndex(kAppendCameraAndSetFlag, kAppendCameraAndSetFlagLong); unsigned int cameraIndex = args.flagIndex(kCameraFlag, kCameraFlagLong); unsigned int deleteLayerIndex = args.flagIndex(kDeleteLayerFlag, kDeleteLayerFlagLong); unsigned int layerIndex = args.flagIndex(kLayerFlag, kLayerFlagLong); unsigned int layerTypeIndex = args.flagIndex(kLayerTypeFlag, kLayerTypeFlagLong); unsigned int setIndex = args.flagIndex(kSetFlag, kSetFlagLong); activeUsed = (activeIndex != MArgList::kInvalidArgIndex); appendCameraUsed = (appendCameraIndex != MArgList::kInvalidArgIndex); appendCameraAndSetUsed = (appendCameraAndSetIndex != MArgList::kInvalidArgIndex); cameraUsed = (cameraIndex != MArgList::kInvalidArgIndex); deleteLayerUsed = (deleteLayerIndex != MArgList::kInvalidArgIndex); layerUsed = (layerIndex != MArgList::kInvalidArgIndex); layerTypeUsed = (layerTypeIndex != MArgList::kInvalidArgIndex); setUsed = (setIndex != MArgList::kInvalidArgIndex); // Process each flag. bool maxArgUsed = false; if (activeUsed) { if (editUsed) { activeVal = args.asBool((activeIndex+1), &status); if (status != MS::kSuccess) { MGlobal::displayError("-active must be either true or false"); return status; } if ((layerTypeIndex+1) == maxArg) maxArgUsed = true; } } if (appendCameraUsed) { camName = args.asString((appendCameraIndex+1), &status); if (status != MS::kSuccess) { MGlobal::displayError("-appendCamera must have a valid camera node specified"); return status; } if ((appendCameraIndex+1) == maxArg) maxArgUsed = true; } if (appendCameraAndSetUsed) { camName = args.asString((appendCameraAndSetIndex+1)); setName = args.asString((appendCameraAndSetIndex+2)); if ((appendCameraAndSetIndex+2) == maxArg) maxArgUsed = true; } if (cameraUsed) { if (editUsed) { camName = args.asString(cameraIndex+1); if ((cameraIndex+1) == maxArg) maxArgUsed = true; } } if (deleteLayerUsed) { cameraLayer = args.asInt(deleteLayerIndex+1); if ((deleteLayerIndex+1) == maxArg) maxArgUsed = true; } if (layerUsed) { cameraLayer = args.asInt(layerIndex+1); if ((layerIndex+1) == maxArg) maxArgUsed = true; } if (layerTypeUsed) { if (editUsed) { layerTypeVal = args.asString(layerTypeIndex+1); if ((layerTypeIndex+1) == maxArg) maxArgUsed = true; } } if (setUsed) { if (editUsed) { setName = args.asString(setIndex+1); if ((setIndex+1) == maxArg) maxArgUsed = true; } } // If all of the arguments have been used, get the cameraSet node from the selection list. // Otherwise, get it from the last argument. if (maxArgUsed) MGlobal::getActiveSelectionList(list); else list.add(args.asString(maxArg)); return MS::kSuccess; }
/* emits particles with color sampled from specified shading node/shading engine */ MStatus sampleParticles::doIt( const MArgList& args ) { unsigned int i; bool shadow = 0; bool reuse = 0; for ( i = 0; i < args.length(); i++ ) if ( args.asString(i) == MString("-shadow") || args.asString(i) == MString("-s") ) shadow = 1; else if ( args.asString(i) == MString("-reuse") || args.asString(i) == MString("-r") ) reuse = 1; else break; if ( args.length() - i < 5 ) { displayError( "Usage: sampleParticles [-shadow|-reuse] particleName <shadingEngine|shadingNode.plug> resX resY scale\n" " Example: sampleParticles -shadow particle1 phong1SG 64 64 10;\n" " Example: sampleParticles particle1 file1.outColor 128 128 5;\n" ); return MS::kFailure; } if ( reuse && !shadow ) // can only reuse if shadow is turned on reuse = 0; MString particleName = args.asString( i ); MString node = args.asString( i+1 ); int resX = args.asInt( i+2 ); int resY = args.asInt( i+3 ); double scale = args.asDouble( i+4 ); if ( scale <= 0.0 ) scale = 1.0; MFloatArray uCoord, vCoord; MFloatPointArray points; MFloatVectorArray normals, tanUs, tanVs; if ( resX <= 0 ) resX = 1; if ( resY <= 0 ) resY = 1; MString command( "emit -o " ); command += particleName; char tmp[2048]; float stepU = (float) (1.0 / resX); float stepV = (float) (1.0 / resY); // stuff sample data by iterating over grid // Y is set to arch along the X axis int x, y; for ( y = 0; y < resY; y++ ) for ( x = 0; x < resX; x++ ) { uCoord.append( stepU * x ); vCoord.append( stepV * y ); float curY = (float) (sin( stepU * (x) * M_PI )*2.0); MFloatPoint curPt( (float) (stepU * x * scale), curY, (float) (stepV * y * scale )); MFloatPoint uPt( (float) (stepU * (x+1) * scale), (float) (sin( stepU * (x+1) * M_PI )*2.0), (float) (stepV * y * scale )); MFloatPoint vPt( (float) (stepU * (x) * scale), curY, (float) (stepV * (y+1) * scale )); MFloatVector du, dv, n; du = uPt-curPt; dv = vPt-curPt; n = dv^du; // normal is based on dU x dV n = n.normal(); normals.append( n ); du.normal(); dv.normal(); tanUs.append( du ); tanVs.append( dv ); points.append( curPt ); } // get current camera's world matrix MDagPath cameraPath; M3dView::active3dView().getCamera( cameraPath ); MMatrix mat = cameraPath.inclusiveMatrix(); MFloatMatrix cameraMat( mat.matrix ); MFloatVectorArray colors, transps; if ( MS::kSuccess == MRenderUtil::sampleShadingNetwork( node, points.length(), shadow, reuse, cameraMat, &points, &uCoord, &vCoord, &normals, &points, &tanUs, &tanVs, NULL, // don't need filterSize colors, transps ) ) { fprintf( stderr, "%u points sampled...\n", points.length() ); for ( i = 0; i < uCoord.length(); i++ ) { sprintf( tmp, " -pos %g %g %g -at velocity -vv %g %g %g -at rgbPP -vv %g %g %g", points[i].x, points[i].y, points[i].z, normals[i].x, normals[i].y, normals[i].z, colors[i].x, colors[i].y, colors[i].z ); command += MString( tmp ); // execute emit command once every 512 samples if ( i % 512 == 0 ) { fprintf( stderr, "%u...\n", i ); MGlobal::executeCommand( command, false, false ); command = MString( "emit -o " ); command += particleName; } } if ( i % 512 ) MGlobal::executeCommand( command, true, true ); } else { displayError( node + MString(" is not a shading engine! Specify node.attr or shading group node." ) ); } return MS::kSuccess; }
MStatus AbcExport::doIt(const MArgList & args) { try { MStatus status; MTime oldCurTime = MAnimControl::currentTime(); MArgParser argData(syntax(), args, &status); if (argData.isFlagSet("help")) { MGlobal::displayInfo(util::getHelpText()); return MS::kSuccess; } bool verbose = argData.isFlagSet("verbose"); // If skipFrame is true, when going through the playback range of the // scene, as much frames are skipped when possible. This could cause // a problem for, time dependent solutions like // particle system / hair simulation bool skipFrame = true; if (argData.isFlagSet("dontSkipUnwrittenFrames")) skipFrame = false; double startEvaluationTime = DBL_MAX; if (argData.isFlagSet("preRollStartFrame")) { double startAt = 0.0; argData.getFlagArgument("preRollStartFrame", 0, startAt); startEvaluationTime = startAt; } unsigned int jobSize = argData.numberOfFlagUses("jobArg"); if (jobSize == 0) return status; // the frame range we will be iterating over for all jobs, // includes frames which are not skipped and the startAt offset std::set<double> allFrameRange; // this will eventually hold only the animated jobs. // its a list because we will be removing jobs from it std::list < AbcWriteJobPtr > jobList; for (unsigned int jobIndex = 0; jobIndex < jobSize; jobIndex++) { JobArgs jobArgs; MArgList jobArgList; argData.getFlagArgumentList("jobArg", jobIndex, jobArgList); MString jobArgsStr = jobArgList.asString(0); MStringArray jobArgsArray; { // parse the job arguments // e.g. -perFrameCallbackMel "print \"something\"" will be splitted to // [0] -perFrameCallbackMel // [1] print "something" enum State { kArgument, // parsing an argument (not quoted) kDoubleQuotedString, // parsing a double quoted string kSingleQuotedString, // parsing a single quoted string }; State state = kArgument; MString stringBuffer; for (unsigned int charIdx = 0; charIdx < jobArgsStr.numChars(); charIdx++) { MString ch = jobArgsStr.substringW(charIdx, charIdx); switch (state) { case kArgument: if (ch == " ") { // space terminates the current argument if (stringBuffer.length() > 0) { jobArgsArray.append(stringBuffer); stringBuffer.clear(); } // goto another argument state = kArgument; } else if (ch == "\"") { if (stringBuffer.length() > 0) { // double quote is part of the argument stringBuffer += ch; } else { // goto double quoted string state = kDoubleQuotedString; } } else if (ch == "'") { if (stringBuffer.length() > 0) { // single quote is part of the argument stringBuffer += ch; } else { // goto single quoted string state = kSingleQuotedString; } } else { stringBuffer += ch; } break; case kDoubleQuotedString: // double quote terminates the current string if (ch == "\"") { jobArgsArray.append(stringBuffer); stringBuffer.clear(); state = kArgument; } else if (ch == "\\") { // escaped character MString nextCh = (++charIdx < jobArgsStr.numChars()) ? jobArgsStr.substringW(charIdx, charIdx) : "\\"; if (nextCh == "n") stringBuffer += "\n"; else if (nextCh == "t") stringBuffer += "\t"; else if (nextCh == "r") stringBuffer += "\r"; else if (nextCh == "\\") stringBuffer += "\\"; else if (nextCh == "'") stringBuffer += "'"; else if (nextCh == "\"") stringBuffer += "\""; else stringBuffer += nextCh; } else { stringBuffer += ch; } break; case kSingleQuotedString: // single quote terminates the current string if (ch == "'") { jobArgsArray.append(stringBuffer); stringBuffer.clear(); state = kArgument; } else if (ch == "\\") { // escaped character MString nextCh = (++charIdx < jobArgsStr.numChars()) ? jobArgsStr.substringW(charIdx, charIdx) : "\\"; if (nextCh == "n") stringBuffer += "\n"; else if (nextCh == "t") stringBuffer += "\t"; else if (nextCh == "r") stringBuffer += "\r"; else if (nextCh == "\\") stringBuffer += "\\"; else if (nextCh == "'") stringBuffer += "'"; else if (nextCh == "\"") stringBuffer += "\""; else stringBuffer += nextCh; } else { stringBuffer += ch; } break; } } // the rest of the argument if (stringBuffer.length() > 0) { jobArgsArray.append(stringBuffer); } } // the frame range within this job std::vector< FrameRangeArgs > frameRanges(1); frameRanges.back().startTime = oldCurTime.value(); frameRanges.back().endTime = oldCurTime.value(); frameRanges.back().strideTime = 1.0; bool hasRange = false; bool hasRoot = false; bool sampleGeo = true; // whether or not to subsample geometry std::string fileName; bool asOgawa = true; unsigned int numJobArgs = jobArgsArray.length(); for (unsigned int i = 0; i < numJobArgs; ++i) { MString arg = jobArgsArray[i]; arg.toLowerCase(); if (arg == "-f" || arg == "-file") { if (i+1 >= numJobArgs) { MGlobal::displayError("File incorrectly specified."); return MS::kFailure; } fileName = jobArgsArray[++i].asChar(); } else if (arg == "-fr" || arg == "-framerange") { if (i+2 >= numJobArgs || !jobArgsArray[i+1].isDouble() || !jobArgsArray[i+2].isDouble()) { MGlobal::displayError("Frame Range incorrectly specified."); return MS::kFailure; } // this is not the first -frameRange argument, we are going // to add one more frame range to the frame range array. if (hasRange) { frameRanges.push_back(FrameRangeArgs()); } hasRange = true; frameRanges.back().startTime = jobArgsArray[++i].asDouble(); frameRanges.back().endTime = jobArgsArray[++i].asDouble(); // make sure start frame is smaller or equal to endTime if (frameRanges.back().startTime > frameRanges.back().endTime) { std::swap(frameRanges.back().startTime, frameRanges.back().endTime); } } else if (arg == "-frs" || arg == "-framerelativesample") { if (i+1 >= numJobArgs || !jobArgsArray[i+1].isDouble()) { MGlobal::displayError( "Frame Relative Sample incorrectly specified."); return MS::kFailure; } frameRanges.back().shutterSamples.insert( jobArgsArray[++i].asDouble()); } else if (arg == "-nn" || arg == "-nonormals") { jobArgs.noNormals = true; } else if (arg == "-pr" || arg == "-preroll") { frameRanges.back().preRoll = true; } else if (arg == "-ro" || arg == "-renderableonly") { jobArgs.excludeInvisible = true; } else if (arg == "-s" || arg == "-step") { if (i+1 >= numJobArgs || !jobArgsArray[i+1].isDouble()) { MGlobal::displayError("Step incorrectly specified."); return MS::kFailure; } frameRanges.back().strideTime = jobArgsArray[++i].asDouble(); } else if (arg == "-sl" || arg == "-selection") { jobArgs.useSelectionList = true; } else if (arg == "-sn" || arg == "-stripnamespaces") { if (i+1 >= numJobArgs || !jobArgsArray[i+1].isUnsigned()) { // the strip all namespaces case // so we pick a very LARGE number jobArgs.stripNamespace = 0xffffffff; } else { jobArgs.stripNamespace = jobArgsArray[++i].asUnsigned(); } } else if (arg == "-uv" || arg == "-uvwrite") { jobArgs.writeUVs = true; } else if (arg == "-wcs" || arg == "-writecolorsets") { jobArgs.writeColorSets = true; } else if (arg == "-wfs" || arg == "-writefacesets") { jobArgs.writeFaceSets = true; } else if (arg == "-wfg" || arg == "-wholeframegeo") { sampleGeo = false; } else if (arg == "-ws" || arg == "-worldspace") { jobArgs.worldSpace = true; } else if (arg == "-wuvs" || arg == "-writeuvsets") { jobArgs.writeUVSets = true; } else if (arg == "-wv" || arg == "-writevisibility") { jobArgs.writeVisibility = true; } else if (arg == "-as" || arg == "-autosubd") { jobArgs.autoSubd = true; } else if (arg == "-mfc" || arg == "-melperframecallback") { if (i+1 >= numJobArgs) { MGlobal::displayError( "melPerFrameCallback incorrectly specified."); return MS::kFailure; } jobArgs.melPerFrameCallback = jobArgsArray[++i].asChar(); } else if (arg == "-pfc" || arg == "-pythonperframecallback") { if (i+1 >= numJobArgs) { MGlobal::displayError( "pythonPerFrameCallback incorrectly specified."); return MS::kFailure; } jobArgs.pythonPerFrameCallback = jobArgsArray[++i].asChar(); } else if (arg == "-mpc" || arg == "-melpostjobcallback") { if (i+1 >= numJobArgs) { MGlobal::displayError( "melPostJobCallback incorrectly specified."); return MS::kFailure; } jobArgs.melPostCallback = jobArgsArray[++i].asChar(); } else if (arg == "-ppc" || arg == "-pythonpostjobcallback") { if (i+1 >= numJobArgs) { MGlobal::displayError( "pythonPostJobCallback incorrectly specified."); return MS::kFailure; } jobArgs.pythonPostCallback = jobArgsArray[++i].asChar(); } // geomArbParams - attribute filtering stuff else if (arg == "-atp" || arg == "-attrprefix") { if (i+1 >= numJobArgs) { MGlobal::displayError( "attrPrefix incorrectly specified."); return MS::kFailure; } jobArgs.prefixFilters.push_back(jobArgsArray[++i].asChar()); } else if (arg == "-a" || arg == "-attr") { if (i+1 >= numJobArgs) { MGlobal::displayError( "attr incorrectly specified."); return MS::kFailure; } jobArgs.attribs.insert(jobArgsArray[++i].asChar()); } // userProperties - attribute filtering stuff else if (arg == "-uatp" || arg == "-userattrprefix") { if (i+1 >= numJobArgs) { MGlobal::displayError( "userAttrPrefix incorrectly specified."); return MS::kFailure; } jobArgs.userPrefixFilters.push_back(jobArgsArray[++i].asChar()); } else if (arg == "-u" || arg == "-userattr") { if (i+1 >= numJobArgs) { MGlobal::displayError( "userAttr incorrectly specified."); return MS::kFailure; } jobArgs.userAttribs.insert(jobArgsArray[++i].asChar()); } else if (arg == "-rt" || arg == "-root") { if (i+1 >= numJobArgs) { MGlobal::displayError( "root incorrectly specified."); return MS::kFailure; } hasRoot = true; MString root = jobArgsArray[++i]; MSelectionList sel; if (sel.add(root) != MS::kSuccess) { MString warn = root; warn += " could not be select, skipping."; MGlobal::displayWarning(warn); continue; } unsigned int numRoots = sel.length(); for (unsigned int j = 0; j < numRoots; ++j) { MDagPath path; if (sel.getDagPath(j, path) != MS::kSuccess) { MString warn = path.fullPathName(); warn += " (part of "; warn += root; warn += " ) not a DAG Node, skipping."; MGlobal::displayWarning(warn); continue; } jobArgs.dagPaths.insert(path); } } else if (arg == "-ef" || arg == "-eulerfilter") { jobArgs.filterEulerRotations = true; } else if (arg == "-df" || arg == "-dataformat") { if (i+1 >= numJobArgs) { MGlobal::displayError( "dataFormat incorrectly specified."); return MS::kFailure; } MString dataFormat = jobArgsArray[++i]; dataFormat.toLowerCase(); if (dataFormat == "hdf") { asOgawa = false; } else if (dataFormat == "ogawa") { asOgawa = true; } } else { MString warn = "Ignoring unsupported flag: "; warn += jobArgsArray[i]; MGlobal::displayWarning(warn); } } // for i if (fileName == "") { MString error = "-file not specified."; MGlobal::displayError(error); return MS::kFailure; } { 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); } else { // alembic file rule does not exist, create it MString addFileRuleCmd; addFileRuleCmd.format("workspace -fr \"^1s\" \"^2s\"", alembicFileRule, alembicFilePath); MGlobal::executeCommand(addFileRuleCmd); // save the workspace. maya may discard file rules on exit MGlobal::executeCommand("workspace -s"); // 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(); // make sure the cache folder exists if (!directory.exists()) { // create the cache folder MString createFolderCmd; createFolderCmd.format("sysFile -md \"^1s\"", directoryName); MGlobal::executeCommand(createFolderCmd); } // resolve the relative path MFileObject absoluteFile; absoluteFile.setRawFullName(fileName.c_str()); #if MAYA_API_VERSION < 201300 if (absoluteFile.resolvedFullName() != absoluteFile.expandedFullName()) { #else if (!MFileObject::isAbsolutePath(fileName.c_str())) { #endif // this is a relative path MString absoluteFileName = directoryName + "/" + fileName.c_str(); absoluteFile.setRawFullName(absoluteFileName); fileName = absoluteFile.resolvedFullName().asChar(); } else { fileName = absoluteFile.resolvedFullName().asChar(); } // check the path must exist before writing MFileObject absoluteFilePath; absoluteFilePath.setRawFullName(absoluteFile.path()); if (!absoluteFilePath.exists()) { MString error; error.format("Path ^1s does not exist!", absoluteFilePath.resolvedFullName()); MGlobal::displayError(error); return MS::kFailure; } // check the file is used by any AlembicNode in the scene MItDependencyNodes dgIter(MFn::kPluginDependNode); for (; !dgIter.isDone(); dgIter.next()) { MFnDependencyNode alembicNode(dgIter.thisNode()); if (alembicNode.typeName() != "AlembicNode") { continue; } MPlug abcFilePlug = alembicNode.findPlug("abc_File"); if (abcFilePlug.isNull()) { continue; } MFileObject alembicFile; alembicFile.setRawFullName(abcFilePlug.asString()); if (!alembicFile.exists()) { continue; } if (alembicFile.resolvedFullName() == absoluteFile.resolvedFullName()) { MString error = "Can't export to an Alembic file which is in use."; MGlobal::displayError(error); return MS::kFailure; } } std::ofstream ofs(fileName.c_str()); if (!ofs.is_open()) { MString error = MString("Can't write to file: ") + fileName.c_str(); MGlobal::displayError(error); return MS::kFailure; } ofs.close(); } // if -frameRelativeSample argument is not specified for a frame range, // we are assuming a -frameRelativeSample 0.0 for (std::vector<FrameRangeArgs>::iterator range = frameRanges.begin(); range != frameRanges.end(); ++range) { if (range->shutterSamples.empty()) range->shutterSamples.insert(0.0); } if (jobArgs.prefixFilters.empty()) { jobArgs.prefixFilters.push_back("ABC_"); } // the list of frame ranges for sampling std::vector<FrameRangeArgs> sampleRanges; std::vector<FrameRangeArgs> preRollRanges; for (std::vector<FrameRangeArgs>::const_iterator range = frameRanges.begin(); range != frameRanges.end(); ++range) { if (range->preRoll) preRollRanges.push_back(*range); else sampleRanges.push_back(*range); } // the list of frames written into the abc file std::set<double> geoSamples; std::set<double> transSamples; for (std::vector<FrameRangeArgs>::const_iterator range = sampleRanges.begin(); range != sampleRanges.end(); ++range) { for (double frame = range->startTime; frame <= range->endTime; frame += range->strideTime) { for (std::set<double>::const_iterator shutter = range->shutterSamples.begin(); shutter != range->shutterSamples.end(); ++shutter) { double curFrame = *shutter + frame; if (!sampleGeo) { double intFrame = (double)(int)( curFrame >= 0 ? curFrame + .5 : curFrame - .5); // only insert samples that are close to being an integer if (fabs(curFrame - intFrame) < 1e-4) { geoSamples.insert(curFrame); } } else { geoSamples.insert(curFrame); } transSamples.insert(curFrame); } } if (geoSamples.empty()) { geoSamples.insert(range->startTime); } if (transSamples.empty()) { transSamples.insert(range->startTime); } } bool isAcyclic = false; if (sampleRanges.empty()) { // no frame ranges or all frame ranges are pre-roll ranges hasRange = false; geoSamples.insert(frameRanges.back().startTime); transSamples.insert(frameRanges.back().startTime); } else { // check if the time range is even (cyclic) // otherwise, we will use acyclic // sub frames pattern std::vector<double> pattern( sampleRanges.begin()->shutterSamples.begin(), sampleRanges.begin()->shutterSamples.end()); std::transform(pattern.begin(), pattern.end(), pattern.begin(), std::bind2nd(std::plus<double>(), sampleRanges.begin()->startTime)); // check the frames against the pattern std::vector<double> timeSamples( transSamples.begin(), transSamples.end()); for (size_t i = 0; i < timeSamples.size(); i++) { // next pattern if (i % pattern.size() == 0 && i / pattern.size() > 0) { std::transform(pattern.begin(), pattern.end(), pattern.begin(), std::bind2nd(std::plus<double>(), sampleRanges.begin()->strideTime)); } // pattern mismatch, we use acyclic time sampling type if (timeSamples[i] != pattern[i % pattern.size()]) { isAcyclic = true; break; } } } // the list of frames to pre-roll std::set<double> preRollSamples; for (std::vector<FrameRangeArgs>::const_iterator range = preRollRanges.begin(); range != preRollRanges.end(); ++range) { for (double frame = range->startTime; frame <= range->endTime; frame += range->strideTime) { for (std::set<double>::const_iterator shutter = range->shutterSamples.begin(); shutter != range->shutterSamples.end(); ++shutter) { double curFrame = *shutter + frame; preRollSamples.insert(curFrame); } } if (preRollSamples.empty()) { preRollSamples.insert(range->startTime); } } if (jobArgs.dagPaths.size() > 1) { // check for validity of the DagPath relationships complexity : n^2 util::ShapeSet::const_iterator m, n; util::ShapeSet::const_iterator end = jobArgs.dagPaths.end(); for (m = jobArgs.dagPaths.begin(); m != end; ) { MDagPath path1 = *m; m++; for (n = m; n != end; n++) { MDagPath path2 = *n; if (util::isAncestorDescendentRelationship(path1,path2)) { MString errorMsg = path1.fullPathName(); errorMsg += " and "; errorMsg += path2.fullPathName(); errorMsg += " have an ancestor relationship."; MGlobal::displayError(errorMsg); return MS::kFailure; } } // for n } // for m } // no root is specified, and we aren't using a selection // so we'll try to translate the whole Maya scene by using all // children of the world as roots. else if (!hasRoot && !jobArgs.useSelectionList) { MSelectionList sel; #if MAYA_API_VERSION >= 201100 sel.add("|*", true); #else // older versions of Maya will not be able to find top level nodes // within namespaces sel.add("|*"); #endif unsigned int numRoots = sel.length(); for (unsigned int i = 0; i < numRoots; ++i) { MDagPath path; sel.getDagPath(i, path); jobArgs.dagPaths.insert(path); } } else if (hasRoot && jobArgs.dagPaths.empty()) { MString errorMsg = "No valid root nodes were specified."; MGlobal::displayError(errorMsg); return MS::kFailure; } else if (jobArgs.useSelectionList) { MSelectionList activeList; MGlobal::getActiveSelectionList(activeList); if (activeList.length() == 0) { MString errorMsg = "-selection specified but nothing is actively selected."; MGlobal::displayError(errorMsg); return MS::kFailure; } } AbcA::TimeSamplingPtr transTime, geoTime; if (hasRange) { if (isAcyclic) { // acyclic, uneven time sampling // e.g. [0.8, 1, 1.2], [2.8, 3, 3.2], .. not continuous // [0.8, 1, 1.2], [1.7, 2, 2.3], .. shutter different std::vector<double> samples( transSamples.begin(), transSamples.end()); std::transform(samples.begin(), samples.end(), samples.begin(), std::bind2nd(std::multiplies<double>(), util::spf())); transTime.reset(new AbcA::TimeSampling(AbcA::TimeSamplingType( AbcA::TimeSamplingType::kAcyclic), samples)); } else { // cyclic, even time sampling between time periods // e.g. [0.8, 1, 1.2], [1.8, 2, 2.2], ... std::vector<double> samples; double startTime = sampleRanges[0].startTime; double strideTime = sampleRanges[0].strideTime; for (std::set<double>::const_iterator shutter = sampleRanges[0].shutterSamples.begin(); shutter != sampleRanges[0].shutterSamples.end(); ++shutter) { samples.push_back((startTime + *shutter) * util::spf()); } if (samples.size() > 1) { Alembic::Util::uint32_t numSamples = static_cast<Alembic::Util::uint32_t>(samples.size()); transTime.reset( new AbcA::TimeSampling(AbcA::TimeSamplingType( numSamples, strideTime * util::spf()), samples)); } // uniform sampling else { transTime.reset(new AbcA::TimeSampling( strideTime * util::spf(), samples[0])); } } } else { // time ranges are not specified transTime.reset(new AbcA::TimeSampling()); } if (sampleGeo || !hasRange) { geoTime = transTime; } else { // sampling geo on whole frames if (isAcyclic) { // acyclic, uneven time sampling std::vector<double> samples( geoSamples.begin(), geoSamples.end()); // one more sample for setup() if (*transSamples.begin() != *geoSamples.begin()) samples.insert(samples.begin(), *transSamples.begin()); std::transform(samples.begin(), samples.end(), samples.begin(), std::bind2nd(std::multiplies<double>(), util::spf())); geoTime.reset(new AbcA::TimeSampling(AbcA::TimeSamplingType( AbcA::TimeSamplingType::kAcyclic), samples)); } else { double geoStride = sampleRanges[0].strideTime; if (geoStride < 1.0) geoStride = 1.0; double geoStart = *geoSamples.begin() * util::spf(); geoTime.reset(new AbcA::TimeSampling( geoStride * util::spf(), geoStart)); } } AbcWriteJobPtr job(new AbcWriteJob(fileName.c_str(), asOgawa, transSamples, transTime, geoSamples, geoTime, jobArgs)); jobList.push_front(job); // make sure we add additional whole frames, if we arent skipping // the inbetween ones if (!skipFrame && !allFrameRange.empty()) { double localMin = *(transSamples.begin()); std::set<double>::iterator last = transSamples.end(); last--; double localMax = *last; double globalMin = *(allFrameRange.begin()); last = allFrameRange.end(); last--; double globalMax = *last; // if the min of our current frame range is beyond // what we know about, pad a few more frames if (localMin > globalMax) { for (double f = globalMax; f < localMin; f++) { allFrameRange.insert(f); } } // if the max of our current frame range is beyond // what we know about, pad a few more frames if (localMax < globalMin) { for (double f = localMax; f < globalMin; f++) { allFrameRange.insert(f); } } } // right now we just copy over the translation samples since // they are guaranteed to contain all the geometry samples allFrameRange.insert(transSamples.begin(), transSamples.end()); // copy over the pre-roll samples allFrameRange.insert(preRollSamples.begin(), preRollSamples.end()); } // add extra evaluation run up, if necessary if (startEvaluationTime != DBL_MAX && !allFrameRange.empty()) { double firstFrame = *allFrameRange.begin(); for (double f = startEvaluationTime; f < firstFrame; ++f) { allFrameRange.insert(f); } } std::set<double>::iterator it = allFrameRange.begin(); std::set<double>::iterator itEnd = allFrameRange.end(); MComputation computation; computation.beginComputation(); // loop through every frame in the list, if a job has that frame in it's // list of transform or shape frames, then it will write out data and // call the perFrameCallback, if that frame is also the last one it has // to work on then it will also call the postCallback. // If it doesn't have this frame, then it does nothing for (; it != itEnd; it++) { if (verbose) { double frame = *it; MString info; info = frame; MGlobal::displayInfo(info); } MGlobal::viewFrame(*it); std::list< AbcWriteJobPtr >::iterator j = jobList.begin(); std::list< AbcWriteJobPtr >::iterator jend = jobList.end(); while (j != jend) { if (computation.isInterruptRequested()) return MS::kFailure; bool lastFrame = (*j)->eval(*it); if (lastFrame) { j = jobList.erase(j); } else j++; } } computation.endComputation(); // set the time back MGlobal::viewFrame(oldCurTime); return MS::kSuccess; } catch (Alembic::Util::Exception & e) { MString theError("Alembic Exception encountered: "); theError += e.what(); MGlobal::displayError(theError); return MS::kFailure; } catch (std::exception & e) { MString theError("std::exception encountered: "); theError += e.what(); MGlobal::displayError(theError); return MS::kFailure; } }
MStatus CBPoseSpaceCmd::parseArgs( const MArgList& args ) { _operation = tCreate; _cacheName = ""; _poseName = ""; _bindName = ""; // Parse the arguments. MStatus stat = MS::kSuccess; MString arg; const MString createCacheFlag ("-cc"); const MString createCacheFlagLong ("-createCache"); const MString loadCacheFlag ("-lc"); const MString loadCacheFlagLong ("-loadCache"); const MString savePoseFlag ("-sp"); const MString savePoseFlagLong ("-savePose"); const MString loadPoseFlag ("-lp"); const MString loadPoseFlagLong ("-loadPose"); const MString poseAtFlag ("-pa"); const MString poseAtFlagLong ("-poseAt"); const MString bindToFlag ("-bt"); const MString bindToFlagLong ("-bindTo"); for ( unsigned int i = 0; i < args.length(); i++ ) { arg = args.asString( i, &stat ); if (!stat) continue; if ( arg == createCacheFlag || arg == createCacheFlagLong ) { _operation = tCreate; } else if ( arg == loadCacheFlag || arg == loadCacheFlagLong ) { if (i == args.length()-1) continue; i++; _operation = tLoad; args.get(i, _cacheName); } else if ( arg == savePoseFlag || arg == savePoseFlagLong ) { if (i == args.length()-1) continue; i++; _operation = tSavePose; args.get(i, _cacheName); } else if ( arg == loadPoseFlag || arg == loadPoseFlagLong ) { if (i == args.length()-1) continue; i++; _operation = tLoadPose; args.get(i, _cacheName); } else if ( arg == poseAtFlag || arg == poseAtFlagLong ) { if (i == args.length()-1) continue; i++; args.get(i, _poseName); } else if ( arg == bindToFlag || arg == bindToFlagLong ) { if (i == args.length()-1) continue; i++; args.get(i, _bindName); } else { MGlobal::displayInfo(MString("unknown flag ") + arg); } } if(_operation == tLoad) { if( _cacheName == "") { MGlobal::displayError("must give -lc cacheFileName to load pose cache"); return MS::kFailure; } if(_poseName == "") { MGlobal::displayError("must give -pa poseMeshName to create pose cache"); return MS::kFailure; } } else if(_operation == tSavePose) { if(_cacheName == "") { MGlobal::displayError("must give -sp cacheFileName to save pose cache"); return MS::kFailure; } if(_poseName == "") { MGlobal::displayError("must give -pa poseMeshName to save pose cache"); return MS::kFailure; } } else if(_operation == tLoadPose) { if(_cacheName == "") { MGlobal::displayError("must give -lp cacheFileName to load pose cache"); return MS::kFailure; } if(_poseName == "") { MGlobal::displayError("must give -pa poseMeshName to load pose cache"); return MS::kFailure; } } else if(_operation == tCreate) { if(_poseName == "" || _bindName == "") { MGlobal::displayError("must give -pa poseMeshName and -bt bindMeshName to create pose cache"); return MS::kFailure; } } return stat; }
MStatus convertGeometryCache::doIt( const MArgList& args ) /////////////////////////////////////////////////////////////////////////////// // // Description : ( public method ) // Converts the specified files to the specified conversion format // /////////////////////////////////////////////////////////////////////////////// { MStatus status = MS::kSuccess; MArgDatabase argDb( syntax(), args, &status ); if( !status ) return status; bool isToAscii = argDb.isFlagSet( SFLAG_TOASCII ); bool hasFile = argDb.isFlagSet( SFLAG_FILE ); if( !isToAscii || !hasFile ) { MGlobal::displayError( "Specify at least one file and format to convert to." ); return status; } // Create an MIffFile to read our cache files // MIffFile iffFilePtr; // Iterate through all the files specified // uint numUses = argDb.numberOfFlagUses( SFLAG_FILE ); for( uint i = 0; i < numUses; i++ ) { MArgList argList; status = argDb.getFlagArgumentList( SFLAG_FILE, i, argList ); if( !status ) return status; MString name = argList.asString( 0, &status ); if( !status ) return status; // Create a geometryCacheFile object from the current file path // geometryCacheFile cacheFile( name, &iffFilePtr); // Read the geometry cache file // bool readStatus = cacheFile.readCacheFiles(); if( !readStatus ) { // If the read failed, report the file name that failed // MGlobal::displayError( "Failed in reading file \"" + name + "\"" ); // Skip the conversion process // continue; } // Convert the geometry cache file to the specified format // if( isToAscii ) { // Convert to Ascii // bool convertStatus = cacheFile.convertToAscii(); if( !convertStatus ) { // If the convert failed, report the file name that failed // MGlobal::displayError( "Failed in converting file \"" + name + "\" to ASCII"); } } // Insert other file format conversions here // } return status; }
MStatus ParameterisedHolderModificationCmd::doIt( const MArgList &argList ) { // get the node we're operating on MSelectionList selection; selection.add( argList.asString( 0 ) ); selection.getDependNode( 0, m_node ); if( m_node.isNull() ) { return MS::kFailure; } MFnDependencyNode fnNode( m_node ); MPxNode *userNode = fnNode.userNode(); m_parameterisedHolder = dynamic_cast<ParameterisedHolderInterface *>( userNode ); if( !m_parameterisedHolder ) { return MStatus::kFailure; } // if we're being asked to change class then store the details of the class we want to set // and the one we're replacing if( argList.length() == 4 ) { std::string originalClassName; std::string originalSearchPathEnvVar; m_parameterisedHolder->getParameterised( &originalClassName, &m_originalClassVersion, &originalSearchPathEnvVar ); m_originalClassName = originalClassName.c_str(); m_originalSearchPathEnvVar = originalSearchPathEnvVar.c_str(); m_newClassName = argList.asString( 1 ); m_newClassVersion = argList.asInt( 2 ); m_newSearchPathEnvVar = argList.asString( 3 ); m_changingClass = true; } else if( argList.length() != 1 ) { displayError( "ieParameterisedHolderSetParameterised : wrong number of arguments." ); return MS::kFailure; } // store the original and new values of everything. these are just passed in from // the FnParameterisedHolder. in the case of changing the held class we won't have // any new values. m_originalValues = g_originalValue; m_originalClasses = g_originalClasses; m_newValues = g_newValue; m_newClasses = g_newClasses; g_originalValue = 0; g_originalClasses = 0; g_newValue = 0; g_newClasses = 0; // change the maya side class or monkey with the maya side class parameters as requested. then remember the new values // of everything and which parameters are changing so we can push them in and out during undo and redo. if( m_changingClass ) { MStatus s = m_parameterisedHolder->setParameterised( m_newClassName.asChar(), m_newClassVersion, m_newSearchPathEnvVar.asChar() ); if ( !s ) { return s; } m_newValues = m_parameterisedHolder->getParameterisedInterface()->parameters()->getValue()->copy(); storeParametersWithNewValues( m_originalValues.get(), m_newValues.get(), "" ); despatchSetParameterisedCallbacks(); } else { storeParametersWithNewValues( m_originalValues.get(), m_newValues.get(), "" ); m_parameterisedHolder->updateParameterised(); setNodeValuesForParametersWithNewValues(); despatchClassSetCallbacks(); } return MS::kSuccess; }
MStatus DMPParameters::parseArgs( const MArgList& args ) { MStatus stat; // reset all parameters. *this = DMPParameters(); // param list MString output = "-output"; bool exportTargetSpecified = false; MString all = "-all"; MString sel = "-sel"; MString lu = "-lu"; MString revZ = "-revZ"; MString mesh = "-mesh"; MString norm = "-norm"; MString curSkel = "-curSkel"; MString assSkel = "-assSkel"; MString morphAnim = "-morphAnim"; MString skel = "-skel"; MString np = "-np"; MString anim = "-skelAnim"; MString samp = "-samp"; MString fps = "-fps"; MString sampRate = "-sampRate"; MString clip = "-clip"; MString range = "-range"; MString curArg; // Parse arguments from command line for (unsigned int i = 0; i < args.length(); i++) { curArg = args.asString(i,&stat); if (output == curArg && (MS::kSuccess == stat)) { ++i; outputDir = args.asString(i, &stat); if (!((MS::kSuccess == stat) && outputDir.substring(outputDir.length()-1, outputDir.length()) == "/")) { MGlobal::executeCommand("print \"invalid parameter of -output\\n\""); stat.perror("invalid parameter of -output"); return stat; } } else if (all == curArg && (MS::kSuccess == stat)) { exportTargetSpecified = true; bExportAll = true; } else if (sel == curArg && (MS::kSuccess == stat)) { exportTargetSpecified = true; bExportAll = false; } else if (lu == curArg && (MS::kSuccess == stat)) { ++i; MString unit = args.asString(i, &stat); if (!(MS::kSuccess == stat)) { MGlobal::executeCommand("print \"invalid parameter of -lu\\n\""); stat.perror("invalid parameter of -lu"); return stat; } if (MString("pref") == unit) { MGlobal::executeCommand("currentUnit -q -l",unit,false); } if (MString("mm") == unit) { lum = CM2MM; } else if (MString("cm") == unit) { lum = CM2CM; } else if (MString("m") == unit) { lum = CM2M; } else if (MString("in") == unit) { lum = CM2IN; } else if (MString("ft") == unit) { lum = CM2FT; } else if (MString("yd") == unit) { lum = CM2YD; } else { stat.perror("unknown parameter: " + unit); MGlobal::executeCommand("print \"invalid parameter of -lu\\n\""); return stat; } } else if (revZ == curArg && (MS::kSuccess == stat)) { bReverseZAxis = true; } else if (mesh == curArg && (MS::kSuccess == stat)) { bExportMesh = true; ++i; meshFileName = args.asString(i, &stat); if (!((MS::kSuccess == stat) && meshFileName.substring(0,1) != "-")) { MGlobal::executeCommand("print \"invalid parameter of -mesh\\n\""); stat.perror("invalid parameter of -mesh"); return stat; } } else if (norm == curArg && (MS::kSuccess == stat)) { bExportMeshNormal = true; } else if (assSkel == curArg && (MS::kSuccess == stat)) { ++i; assignSkeleton = args.asString(i, &stat); if (!((MS::kSuccess == stat) && assignSkeleton.substring(0,1) != "-")) { MGlobal::executeCommand("print \"invalid parameter of -assSkel\\n\""); stat.perror("invalid parameter of -assSkel"); return stat; } skeletonTarget = ST_UseAssigned; } else if (curSkel == curArg && (MS::kSuccess == stat)) { skeletonTarget = ST_UseCurrent; } else if (morphAnim == curArg && (MS::kSuccess == stat)) { bExportMorphAnimation = true; } else if (skel == curArg && (MS::kSuccess == stat)) { bExportSkeleton = true; ++i; skeletonFileName = args.asString(i, &stat); if (!((MS::kSuccess == stat) && skeletonFileName.substring(0,1) != "-")) { MGlobal::executeCommand("print \"invalid parameter of -skel\\n\""); stat.perror("invalid parameter of -skel"); return stat; } } else if (np == curArg && (MS::kSuccess == stat)) { ++i; MString npType = args.asString(i, &stat); if (!((MS::kSuccess == stat) && skeletonFileName.substring(0,1) != "-")) { MGlobal::executeCommand("print \"invalid parameter of -np\\n\""); stat.perror("invalid parameter of -np"); return stat; } if (npType == "bindPose") { neutralPoseType = NPT_SkinBindPose; } else if (npType == "curFrame") { neutralPoseType = NPT_CurrentFrame; } else { MGlobal::executeCommand("print \"invalid parameter of -np\\n\""); stat.perror("invalid parameter of -np"); return stat; } } else if (anim == curArg && (MS::kSuccess == stat)) { bExportSkelAnimation = true; } else if (samp == curArg && (MS::kSuccess == stat)) { ++i; MString sampType = args.asString(i, &stat); if (!((MS::kSuccess == stat) && skeletonFileName.substring(0,1) != "-")) { MGlobal::executeCommand("print \"invalid parameter of -samp\\n\""); stat.perror("invalid parameter of -samp"); return stat; } if (sampType == "frame") { animSampleType = AST_Frame; } else if (sampType == "second") { animSampleType = AST_Second; } else { MGlobal::executeCommand("print \"invalid parameter of -samp\\n\""); stat.perror("invalid parameter of -samp"); return stat; } } else if (fps == curArg && (MS::kSuccess == stat)) { ++i; fps = (float)args.asDouble(i, &stat); if (!(MS::kSuccess == stat)) { MGlobal::executeCommand("print \"invalid parameter of -fps\\n\""); stat.perror("invalid parameter of -fps"); return stat; } } else if (sampRate == curArg && (MS::kSuccess == stat)) { ++i; samplerRate = (float)args.asDouble(i, &stat); if (!(MS::kSuccess == stat)) { MGlobal::executeCommand("print \"invalid parameter of -sampRate\\n\""); stat.perror("invalid parameter of -sampRate"); return stat; } } else if (clip == curArg && (MS::kSuccess == stat)) { ++i; AnimationClip newClip; newClip.clipName = args.asString(i, &stat); if(!((MS::kSuccess == stat) && skeletonFileName.substring(0,1) != "-")) { MGlobal::executeCommand("print \"invalid parameter of -clip\\n\""); stat.perror("invalid parameter of -clip"); return stat; } ++i; if (MString("-range") == args.asString(i,&stat) && (MS::kSuccess == stat)) { ++i; newClip.start = (float)args.asDouble(i, &stat); if (!(MS::kSuccess == stat)) { MGlobal::executeCommand("print \"invalid parameter of -range\\n\""); stat.perror("invalid parameter of -range"); return stat; } ++i; newClip.end = (float)args.asDouble(i, &stat); if (!(MS::kSuccess == stat)) { MGlobal::executeCommand("print \"invalid parameter of -range\\n\""); stat.perror("invalid parameter of -range"); return stat; } clipList.push_back(newClip); } else { MGlobal::executeCommand("print \"incomplete parameter of -range\\n\""); stat.perror("incomplete parameter of -range"); return stat; } } else { stat.perror("unknown parameter"); MGlobal::executeCommand("print \"unknown parameter: " + curArg + "\\n\""); return stat; } } return stat; }
MStatus UVSeams::doIt(const MArgList& args) { MStatus stat; MString meshName = args.asString(0, &stat);er MSelectionList list; list.add(meshName); MDagPath path; stat = list.getDagPath(0, path);er MFnMesh fnMesh(path, &stat);er MObject obj = UVCommon::getUVMesh(fnMesh); // go over every vertex MItMeshVertex itmeshv(obj, &stat);er MItMeshVertex itmeshv2(obj, &stat);er MItMeshEdge itmeshe(obj, &stat);er MSelectionList selection; bool seamFound = false; MIntArray seamVerts; for (itmeshv.reset(); itmeshv.isDone() == false; itmeshv.next()) { MIntArray edgeList; // for each vertex get ever edge stat = itmeshv.getConnectedEdges(edgeList); int vertexIndex = itmeshv.index(); // if neighbouring edge has dot prod of circa 1 that's most likely a seam for (size_t i = 0; i < edgeList.length(); i++) { int e1 = edgeList[i]; int e2 = edgeList[i < edgeList.length()-1 ? i + 1 : 0]; int oppVertex1; int oppVertex2; int prevIndex = 0; stat = itmeshv.getOppositeVertex(oppVertex1, e1);er MPoint e1v0 = itmeshv.position(MSpace::kObject,&stat);er stat = itmeshv2.setIndex(oppVertex1, prevIndex);er MPoint e1v1 = itmeshv2.position(MSpace::kObject,&stat);er MVector e1e(e1v1 - e1v0); stat = itmeshv.getOppositeVertex(oppVertex2, e2);er stat = itmeshv2.setIndex(oppVertex2, prevIndex);er MPoint e2v1 = itmeshv2.position(MSpace::kObject,&stat);er MVector e2e(e2v1 - e1v0); if ((e1e.normal() * e2e.normal() > 0.999) && fabs(e1e.length() - e2e.length()) < 0.001) { seamVerts.append(vertexIndex); seamVerts.append(oppVertex1); seamVerts.append(oppVertex2); seamFound = true; } if (edgeList.length() == 2) break; } } setResult(seamFound); if (seamFound) { MString str = "select -add "; for (size_t i = 0; i < seamVerts.length(); i++) { str += meshName + ".map[" + seamVerts[i] + "] "; } MGlobal::executeCommand(str); } stat = MGlobal::deleteNode( obj );er return stat; }
/* private */ MStatus cgfxShaderCmd::parseArgs(const MArgList& args, MSelectionList& selList) { MStatus status; MString sMsg; selList.clear(); fArgString.clear(); for ( unsigned iArg = 0; iArg < args.length(); ++iArg ) { if ( iArg > 0 ) fArgString += " "; fArgString += args.asString( iArg ); } #ifdef KH_DEBUG MString ss = " .. Cmd "; ss += fArgString; ss += "\n"; ::OutputDebugString( ss.asChar() ); #endif MArgDatabase argData( syntax(), args, &status ); if ( !status ) return status; bool bCgfxShaderNodeRequired = true; fIsEdit = argData.isEdit(); fIsQuery = argData.isQuery(); if ( argData.isFlagSet( kMaxTexCoordsFlag ) ) { bCgfxShaderNodeRequired = false; fMaxTexCoords = true; fIsQuery = true; } if ( argData.isFlagSet( kPluginPathFlag ) ) { bCgfxShaderNodeRequired = false; fPluginPath = true; fIsQuery = true; } if ( argData.isFlagSet( kEmptyUVFlag ) ) { fEmptyUV = true; fIsQuery = true; } if ( argData.isFlagSet( kEmptyUVShapesFlag ) ) { fEmptyUVShapes = true; fIsQuery = true; } if ( argData.isFlagSet( kTexCoordSourceFlag ) ) { fTexCoordSource = true; fIsQuery = true; } #if MAYA_API_VERSION >= 700 if ( argData.isFlagSet( kColorSourceFlag ) ) { fColorSource = true; fIsQuery = true; } #endif if (argData.isFlagSet(kFxFlag)) { fFxFile = true; if (!fIsQuery) { argData.getFlagArgument(kFxFlag, 0, fNewFxFile); } } if (argData.isFlagSet(kFxPathFlag)) { fFxPath = true; fIsQuery = true; } if (argData.isFlagSet(kFxTechniqueFlag)) { fTechnique = true; if (!fIsQuery) { argData.getFlagArgument( kFxTechniqueFlag, 0, fNewTechnique ); } } if (argData.isFlagSet(kFxProfileFlag)) { fProfile = true; if (!fIsQuery) { argData.getFlagArgument( kFxProfileFlag, 0, fNewProfile ); } } if (argData.isFlagSet(kNameFlag)) { argData.getFlagArgument(kNameFlag, 0, fNodeName); } if (argData.isFlagSet(kListParametersFlag)) { fListParameters = true; fIsQuery = true; } if ( argData.isFlagSet( kListTechniquesFlag ) ) { fListTechniques = true; fIsQuery = true; } if ( argData.isFlagSet( kListProfilesFlag ) ) { bCgfxShaderNodeRequired = false; fListProfiles = true; fIsQuery = true; } if (argData.isFlagSet(kParameterFlag)) { argData.getFlagArgument(kParameterFlag, 0, fParameterName); fIsQuery = true; } if ( argData.isFlagSet( kCaseInsensitiveFlag ) ) { fCaseInsensitive = true; fIsQuery = true; } if ( argData.isFlagSet( kDescriptionFlag ) ) { fDescription = true; fIsQuery = true; } // Check for mutually exclusive flags. if ( fIsQuery && fIsEdit ) { MString es = "cgfxShader: invalid use of -e/-edit flag"; MGlobal::displayError( es ); return MS::kInvalidParameter; } // Get the objects on which to operate. if ( bCgfxShaderNodeRequired ) { argData.getObjects(selList); if ( selList.length() == 0 ) MGlobal::getActiveSelectionList( selList ); if ( selList.length() != 1 ) { sMsg = "Exactly one node must be specified or selected for command: cgfxShader "; sMsg += fArgString; MGlobal::displayError( sMsg ); status = MS::kInvalidParameter; } } return status; }