Exemple #1
0
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 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;
}
Exemple #3
0
MStatus iffPpm::doIt( const MArgList& args )
{
    MString componentName;
	if (args.length () < 2 || args.length () > 3) {
		displayError ("Syntax: iffPpm ifffile ppmfile [-depth]");
		return MS::kFailure;
	}

	args.get (0, fileName);
	args.get (1, ppmFile);
	if (args.length () == 3)
	{
		MString lastArg;
		args.get (2, lastArg);
		if (lastArg != MString ("-depth")) {
			displayError ("Syntax: iffPpm ifffile ppmfile [-depth]");
			return MS::kFailure;
		}
		useDepth = true;
	}
	else
		useDepth = false;

    return redoIt();
}
Exemple #4
0
MStatus mDbl3dNoise::doIt( const MArgList& args )
{
	if (args.length() == 1)
	{
    	// vector array
		// get the arguments
    	MDoubleArray dblA;
	    unsigned int count;
		MStatus stat = getArgVec(args, dblA, count);
		ERROR_FAIL(stat);
    
		// do the job
		MDoubleArray result = MDoubleArray(count);		

        Noise noiseGen;
        for(int i=0;i<count;i++)
        {
        	int id = ELEMENTS_VEC *i;
	    	result[i] = noiseGen.improvedPerlin3dS(float(dblA[id]), float(dblA[id+1]),float(dblA[id+2]));
        }
            
        setResult(result);
        
	}
	else if (args.length() == 3)
	{
		// get the arguments
	    MDoubleArray dblA, dblB, dblC;
    	unsigned int incA, incB, incC, count;
		MStatus stat = getArgDblDblDbl(args, dblA, dblB, dblC, incA, incB, incC, count);
		ERROR_FAIL(stat);
	
		// do the actual job
		unsigned int iterA, iterB, iterC;
		iterA = iterB = iterC = 0;

		MDoubleArray result(count);
		Noise noiseGen;

		for (unsigned int i=0;i<count;i++)
		{
        	result[i] = noiseGen.improvedPerlin3dS(float(dblA[iterA]), float(dblB[iterB]),  float(dblC[iterC]));

			iterA += incA;
			iterB += incB;
			iterC += incC;            
		}
		
        setResult(result);
	}
	else
	{
		USER_ERROR_CHECK(MS::kFailure,("mDbl3dNoise: wrong number of arguments, should be 1 vecArray or 3 dblArrays!"));
	}
    
	return MS::kSuccess;

}
Exemple #5
0
MStatus mDblGauss::doIt( const MArgList& args )
{
	MStatus stat;
	int count = 1;
    
    srand(mfSeed);
    
	// check how many arguments we have
	if (args.length() == 0)
	{
		// no args
		// just return a single double
		setResult(MDoubleArray(1,gauss()));
		return MS::kSuccess;
	}
	else if (args.length() == 1)
	{
		// one args, check if its an int - if yes return int identity arrays
		stat = getIntArg(args, 0, count);
		ERROR_FAIL(stat);
        MDoubleArray result(count);
        
        double randDif = ((double)RAND_MAX + 1);
        
        for (int i=0; i< count; i++)
			result[i] = gauss();
        
        setResult(result);
		return MS::kSuccess;
	}
	else if (args.length() == 3)
	{
		double mean, diff;
        
		stat = getIntArg(args, 0, count);
		ERROR_FAIL(stat);

		stat = getDoubleArg(args, 1, mean);
		ERROR_FAIL(stat);

		stat = getDoubleArg(args, 2, diff);
		ERROR_FAIL(stat);

      	MDoubleArray result(count);
                  
        for (int i=0; i< count; i++)
			result[i] = gauss()*diff+mean;
        
        setResult(result);
		return MS::kSuccess;
	}
	else
	{
		ERROR_FAIL(MS::kFailure);	
	}
}
Exemple #6
0
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;
}
Exemple #7
0
MStatus mDbl2dNoise::doIt( const MArgList& args )
{
	if (args.length() == 1)
	{
		// get the arguments
    	MDoubleArray dblA;
	    unsigned int count;
		MStatus stat = getArgUV(args, dblA, count);
		ERROR_FAIL(stat);
    
		// do the job
		MDoubleArray result = MDoubleArray(count);		

        Noise noiseGen;
        for(int i=0;i<count;i++)
	    	result[i] = noiseGen.improvedPerlin2dS(float(dblA[i*ELEMENTS_UV]), float(dblA[i*ELEMENTS_UV+1]));
            
        setResult(result);
        
	}
	else if (args.length() == 2)
	{
		// get the arguments
	    MDoubleArray dblA, dblB;
    	unsigned int incA, incB, count;
		MStatus stat = getArgDblDbl(args, dblA, dblB, incA, incB, count);
		ERROR_FAIL(stat);
	
		// do the actual job
		unsigned int iterA, iterB;
		iterA = iterB = 0;

		MDoubleArray result(count);
		Noise noiseGen;

		for (unsigned int i=0;i<count;i++)
		{
        	result[i] = noiseGen.improvedPerlin2dS(float(dblA[iterA]), float(dblB[iterB]));

			iterA += incA;
			iterB += incB;
		}
		
        setResult(result);
	}
	else
	{
		USER_ERROR_CHECK(MS::kFailure,("mDbl2dNoise: wrong number of arguments, should be 1 uvArray or 2 dblArrays!"));
	}
    
	return MS::kSuccess;

}
// 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 blindComplexData::readASCII(  const MArgList& args,
        		                        unsigned& lastParsedElement )
{
    MStatus status;
	int argLength = args.length();
    if( argLength > 0 ) {
		int numDataRecord = (argLength - lastParsedElement); 
		//
		// Note: a better solution to determine the number of records is to
		// write out the number of records in the writeASCII() routine.
		//
		if ( numDataRecord % 2 != 0 ) {
			cerr << "warning: corrupted data for blindComplexData" << endl;
		}
		// 
		// 2 numbers per record.
		numDataRecord /= 2;
		setLength(numDataRecord); 
		for ( unsigned int i=0; i < _length; i++ ) {
        	status = _CVDataArrayPtr[i].readASCII(args, lastParsedElement);
			if ( status != MS::kSuccess ) {
				return status;
			}
		}
		return MS::kSuccess;
    } 
	return MS::kFailure;
}
Exemple #10
0
MStatus moveCmd::doIt( const MArgList& args )
//
// Description
// 		Test MItSelectionList class
//
{
	MStatus stat;
	MVector	vector( 1.0, 0.0, 0.0 );	// default delta
	unsigned i = 0;

	switch ( args.length() )	 // set arguments to vector
	{
		case 1:
			vector.x = args.asDouble( 0, &stat );
			break;
		case 2:
			vector.x = args.asDouble( 0, &stat );
			vector.y = args.asDouble( 1, &stat );
			break;
		case 3:
			vector = args.asVector(i,3);
			break;
		case 0:
		default:
			break;
	}
	delta = vector;

	return action( DOIT );
}
MStatus GetMetaNodeConnectionCmd::parseArgs(const MArgList & args)
{
    MStatus status;
    if( args.length() == 0 ) {
        return MS::kNotFound;
    }

    MArgDatabase argData(syntax(), args);

    //get the node name argument
    if (argData.isFlagSet(GetMetaNodeConnectionCmd::FileParam())) {
        MString tmp;
        status = argData.getFlagArgument(GetMetaNodeConnectionCmd::FileParam(), 0, tmp);
        if (!status) {
            status.perror("node flag parsing failed");
            return status;
        }
        this->m_metaNodeName = tmp;
    }
    //get the connection name argument
    if (argData.isFlagSet(GetMetaNodeConnectionCmd::FileParam2())) {
        MString tmp;
        status = argData.getFlagArgument(GetMetaNodeConnectionCmd::FileParam2(), 0, tmp);
        if (!status) {
            status.perror("connection flag parsing failed");
            return status;
        }
        this->m_connectionName = tmp;
    }

    return MS::kSuccess;
}
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 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;
}
Exemple #14
0
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 blindDoubleData::readASCII(  const MArgList& args,
                                unsigned& lastParsedElement )
{
    MStatus status;
    if( args.length() > 0 ) {
        fValue = args.asDouble( lastParsedElement++, &status  );
        return status; 
    } else {
        return MS::kFailure;
    }
}
Exemple #16
0
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;
}
Exemple #17
0
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();
}
Exemple #18
0
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	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 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;
}
Exemple #21
0
//-*****************************************************************************
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 findFileTextures::doIt( const MArgList& args )
{

	MSelectionList list;
    MStatus        status;

	if ( args.length() > 0 ) {
		// Arg list is > 0 so use objects that were passes in
		//
		MString argStr;

		unsigned last = args.length();
		for ( unsigned i = 0; i < last; i++ ) {
			// Attempt to find all of the objects matched
			// by the string and add them to the list
			//
			args.get( i, argStr );  
			list.add( argStr ); 
		}
	} else {
		// Get arguments from Maya's selection list.
		MGlobal::getActiveSelectionList( list );
    }

	MObject             node;
    MFnDependencyNode   nodeFn,dgNodeFnSet;
    MItDependencyGraph* dgIt; 
    MObject             currentNode;
	MObject 			thisNode;
    MObjectArray        nodePath;

	for ( MItSelectionList iter( list ); !iter.isDone(); iter.next() ) {

		iter.getDependNode( node );

        //
        // The following code shows how to navigate the DG manually without
        // using an iterator.  First, find the attribute that you are 
        // interested.  Then connect a plug to it and see where the plug 
        // connected to.  Once you get all the connections, you can choose 
        // which route you want to go.
        //
        // In here, we wanted to get to the nodes that instObjGroups connected
        // to since we know that the shadingEngine connects to the instObjGroup
        // attribute.
        //

        nodeFn.setObject( node );
        MObject iogAttr = nodeFn.attribute( "instObjGroups", &status);
		if ( !status ) {
			cerr << nodeFn.name() << ": is not a renderable object, skipping\n";
			continue;
		}

        MPlug iogPlug( node, iogAttr );
        MPlugArray iogConnections;

        //
        // instObjGroups is a multi attribute.  In this example, just the
        // first connection will be tried.
        //
        iogPlug.elementByLogicalIndex(0).connectedTo( iogConnections, false, true, &status );

		if ( !status ) {
			cerr << nodeFn.name() << ": is not in a shading group, skipping\n";
			continue;
		}

        //
        // Now we would like to traverse the DG starting from the shadingEngine
        // since most likely all file texture nodes will be found.  Note the 
        // filter used to initialize the DG iterator.  There are lots of filter
        // type available in MF::Type that you can choose to suite your needs.
        //
		bool foundATexture = false;
        for ( unsigned int i=0; i<iogConnections.length(); i++ ) {

            currentNode = iogConnections[i].node();

            // 
            // Note that upon initilization, the current pointer of the 
            // iterator already points to the first valid node.
            //
            dgIt = new MItDependencyGraph( currentNode, 
                               MFn::kFileTexture,
                               MItDependencyGraph::kUpstream, 
                               MItDependencyGraph::kBreadthFirst,
                               MItDependencyGraph::kNodeLevel, 
                               &status );
			if ( !status ) {
				delete dgIt;
				continue;
			}
            dgIt->disablePruningOnFilter();

            for ( ; ! dgIt->isDone(); dgIt->next() ) {
              
			   	thisNode = dgIt->thisNode();
                dgNodeFnSet.setObject( thisNode ); 
                status = dgIt->getNodePath( nodePath );

                if ( !status ) {
					status.perror("getNodePath");
					continue;
                }

                //
                // append the starting node.
                //
                nodePath.append(node);
                dumpInfo( thisNode, dgNodeFnSet, nodePath );
				foundATexture = true;
            }
            delete dgIt;
        }
		
		if ( !foundATexture ) {
			cerr << nodeFn.name() << ": is not connected to a file texture\n";
		}
    }
    return MS::kSuccess; 
}
Exemple #23
0
MStatus intersectCmd::doIt(const MArgList& args)

// Description:
// 		Determine if the ray from the spotlight intersects the mesh.
//		If it does, display the intersection points.

{
	MStatus stat = MStatus::kSuccess;

	if (args.length() != 2) 
	{
		MGlobal::displayError("Need 2 items!");
		return MStatus::kFailure;
	}

	MSelectionList activeList;
	int i;
	
	for ( i = 0; i < 2; i++)
	{
		MString strCurrSelection;
		stat = args.get(i, strCurrSelection);
		if (MStatus::kSuccess == stat) activeList.add(strCurrSelection);
	}

	MItSelectionList iter(activeList);
	MFnSpotLight fnLight;  
	MFnMesh fnMesh;
	MFnDagNode dagNod;
	MFnDependencyNode fnDN;

	float fX = 0;
	float fY = 0;
	float fZ = 0;

	for ( ; !iter.isDone(); iter.next() )
	{
		MObject tempObjectParent, tempObjectChild;
		iter.getDependNode(tempObjectParent);

		if (tempObjectParent.apiType() == MFn::kTransform)
		{
			dagNod.setObject(tempObjectParent);
			tempObjectChild = dagNod.child(0, &stat);
		}

		// check what type of object is selected
		if (tempObjectChild.apiType() == MFn::kSpotLight)
		{
			MDagPath pathToLight;
			MERR_CHK(MDagPath::getAPathTo(tempObjectParent, pathToLight), "Couldn't get a path to the spotlight");
			MERR_CHK(fnLight.setObject(pathToLight), "Failure on assigning light");
			
			stat = fnDN.setObject(tempObjectParent);

			MPlug pTempPlug = fnDN.findPlug("translateX", &stat);
			if (MStatus::kSuccess == stat)
			{
				pTempPlug.getValue(fX);
			}

			pTempPlug = fnDN.findPlug("translateY", &stat);
			if (MStatus::kSuccess == stat)
			{
				pTempPlug.getValue(fY);
			}

			pTempPlug = fnDN.findPlug("translateZ", &stat);
			if (MStatus::kSuccess == stat)
			{
				pTempPlug.getValue(fZ);
			}	
		}
		else if (tempObjectChild.apiType() == MFn::kMesh)
		{
			MDagPath pathToMesh;
			MERR_CHK(MDagPath::getAPathTo(tempObjectChild, pathToMesh), "Couldn't get a path to the spotlight");
			MERR_CHK(fnMesh.setObject(pathToMesh), "Failure on assigning light");	
		}
		else
		{
			MGlobal::displayError("Need a spotlight and a mesh");
			return MStatus::kFailure;
		}
	}

	MFloatPoint fpSource(fX, fY, fZ);
	MFloatVector fvRayDir = fnLight.lightDirection(0, MSpace::kWorld, &stat);
	MFloatPoint hitPoint;
	
	MMeshIsectAccelParams mmAccelParams = fnMesh.autoUniformGridParams();
	
	float fHitRayParam, fHitBary1, fHitBary2;
	int nHitFace, nHitTriangle;

	// a large positive number is used here for the maxParam parameter
	bool bAnyIntersection = fnMesh.anyIntersection(fpSource, fvRayDir, NULL, NULL, false,				MSpace::kWorld, (float)9999, false, &mmAccelParams, hitPoint, &fHitRayParam, &nHitFace, &nHitTriangle, 		&fHitBary1, &fHitBary2, (float)1e-6, &stat);
	
	if (! bAnyIntersection) 
	{
		MGlobal::displayInfo("There were no intersection points detected");
		return stat;
	}

	MFloatPointArray hitPoints;
	MFloatArray faHitRayParams;
	MIntArray iaHitFaces;
	MIntArray iaHitTriangles;
	MFloatArray faHitBary1;
	MFloatArray faHitBary2;

	bool bAllIntersections = fnMesh.allIntersections(fpSource, fvRayDir, NULL, NULL, false, MSpace::kWorld, 9999, false, NULL, false, hitPoints, &faHitRayParams, &iaHitFaces, &iaHitTriangles, &faHitBary1, &faHitBary2, 0.000001f, &stat);
	
	if (! bAllIntersections)
	{
		MGlobal::displayInfo("Error getting all intersections");
		return stat;
	}
	
	// check how many intersections are found
	unsigned int nNumberHitPoints = hitPoints.length();

	if (! nNumberHitPoints)
	{
		MGlobal::displayInfo("No hit points detected");
		return MStatus::kSuccess;
	}

	// Intersection exists; display intersections as spheres
	MString strCommandString = "string $strBall[] = `polySphere -r 0.5`;";
	strCommandString += "$strBallName = $strBall[0];";

	float x = 0;
	float y = 0;
	float z = 0;

	for (i = 0; i < (int)nNumberHitPoints; i++)
	{
		// get the points
		x = hitPoints[i][0];
		y = hitPoints[i][1];
		z = hitPoints[i][2];

		// execute some MEL to create a small sphere
		strCommandString += "setAttr ($strBallName + \".tx\") ";
		strCommandString += x;
		strCommandString += ";";

		strCommandString += "setAttr ($strBallName + \".ty\") ";
		strCommandString += y;
		strCommandString += ";";

		strCommandString += "setAttr ($strBallName + \".tz\") ";
		strCommandString += z;
		strCommandString += ";";

		MGlobal::executeCommand(strCommandString);
	}

	return stat;
}
Exemple #24
0
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;
}
Exemple #25
0
MStatus viewCapture::doIt( const MArgList& args )
{
	MStatus status = MS::kSuccess;

	if ( args.length() != 1 ) {
		// Need the file name argument
		//
		return MS::kFailure;
	}

	MString fileName;
	args.get( 0, fileName );

	// Get the active 3D view
	//
	M3dView view = M3dView::active3dView();

	// Capture the current view
	//
	view.refresh();
	view.beginGL();
 
	// Set the target for our pixel read to be the front buffer.  First, the
	// current state is saved using the glPushAttrib call.  It is important
	// to leave the OpenGL in the same state that we found it.
	//
	glPushAttrib( GL_PIXEL_MODE_BIT ); 

	int width = view.portWidth();
	int height = view.portHeight(); 

	// Allocate buffers for the pixel data
	//
	GLfloat * red   = new GLfloat[width*height];
	GLfloat * green = new GLfloat[width*height];
	GLfloat * blue  = new GLfloat[width*height];

	// Read the values from the OpenGL frame buffer
	//
	glReadBuffer( GL_FRONT );
	glReadPixels( 0, 0, width, height, GL_RED, GL_FLOAT, red );
	glReadPixels( 0, 0, width, height, GL_GREEN, GL_FLOAT, green );
	glReadPixels( 0, 0, width, height, GL_BLUE, GL_FLOAT, blue );
	
	// Put the gl read target back
	//
	glPopAttrib(); 

	view.endGL();

	// Write file as a PPM
	//
	Pic_Pixel * line = PixelAlloc( width );
	int idx;

	Pic * file = PicOpen( fileName.asChar(), (short) width, (short) height );
	if ( NULL != file ) { 
		for ( int row = height - 1; row >= 0; row-- ) {
			// Covert the row of pixels into PPM format
			//
			for ( int col = 0; col < width; col++ ) {
				// Find the array elements for this pixel
				//
				idx = ( row * width ) + ( col );
				line[col].r = (Pic_byte)( red[idx]   * 255.0 );
				line[col].g = (Pic_byte)( green[idx] * 255.0 );
				line[col].b = (Pic_byte)( blue[idx] * 255.0 );
			}
			// Write the line
			//
			if ( !PicWriteLine( file, line ) ) {
				status = MS::kFailure; 
				return MS::kFailure;
			}
		}
		PicClose( file ); 
	}
 
	delete []red;
	delete []green;
	delete []blue;
	PixelFree( line );

	return status;
}
Exemple #26
0
/* 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;
}
Exemple #27
0
// If given no arguments, translate all selected objects by 1 unit on
// the X axis.  If 3 double parameters are given, they specify the X,
// Y, and Z components of the vector to translate objects by.
MStatus translate::doIt( const MArgList& args )
{
	MStatus stat;
	MVector 	vector( 1.0, 0.0, 0.0 );

	if ( args.length() == 3 )  {
		unsigned i = 0;
		vector = args.asVector(i,3);
	}

	// Create a selection list iterator
	//
	MSelectionList slist;
	MGlobal::getActiveSelectionList( slist );
	MItSelectionList iter( slist, MFn::kInvalid, &stat );

	if ( MS::kSuccess == stat ) {
		MDagPath 	mdagPath;		// Item dag path
		MObject 	mComponent;		// Current component

		// Translate all selected objects
		//
		for ( ; !iter.isDone(); iter.next() ) 
		{
			// Get path and possibly a component
			//
			iter.getDagPath( mdagPath, mComponent );

			MItCurveCV cvFn( mdagPath, mComponent, &stat );
			if ( MS::kSuccess == stat ) {
				for ( ; !cvFn.isDone(); cvFn.next() ) {
					if ( MS::kFailure == cvFn.translateBy( vector ) ) {
						cerr << "Error setting CV\n";
					}
				}
				cvFn.updateCurve();
			}

			MItSurfaceCV sCvFn( mdagPath, mComponent, true, &stat );
			if ( MS::kSuccess == stat ) {
				for ( ; !sCvFn.isDone(); sCvFn.nextRow() ) {
					for ( ; !sCvFn.isRowDone(); sCvFn.next() ) {
						if ( MS::kFailure == sCvFn.translateBy( vector ) ) {
							cerr << "Error setting CV\n";
						}
					}
				}
				sCvFn.updateSurface();
			}

			MItMeshVertex vtxFn( mdagPath, mComponent, &stat );
			if ( MS::kSuccess == stat ) {
				for ( ; !vtxFn.isDone(); vtxFn.next() ) {
					if ( MS::kFailure == vtxFn.translateBy( vector ) ) {
						cerr << "Error setting Vertex\n";
					}
				}
				vtxFn.updateSurface();
			}

		}
	}
	else {
		cerr << "Error creating selection list iterator\n";
	}
	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;
}
Exemple #29
0
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 getAttrAffects::doIt( const MArgList& args )
{
	MStatus stat;
	MSelectionList list;

	if ( args.length() > 0 ) {
		// Arg list is > 0 so use objects that were passes in
		//
		MString argStr;

		unsigned last = args.length();
		for ( unsigned i = 0; i < last; i++ ) {
			// Attempt to find all of the objects matched
			// by the string and add them to the list
			//
			args.get( i, argStr );  
			list.add( argStr ); 
		}
	} else {
		// Get the geometry list from what is currently selected in the 
		// model
		//
		MGlobal::getActiveSelectionList( list );
	} 
	MItSelectionList iter( list );

	// Iterate over all selected dependency nodes
	//
	for ( ; !iter.isDone(); iter.next() ) 
	{
		MObject object;

		stat = iter.getDependNode( object );
		if ( !stat ) {
			stat.perror("getDependNode");
			continue;
		}

		// Create a function set for the dependency node
		//
		MFnDependencyNode node( object );

		cout << node.name() << ":\n";
		unsigned i, numAttributes = node.attributeCount();

		for (i = 0; i < numAttributes; ++i) {
			MObject attrObject = node.attribute(i);
			MFnAttribute attr;
			unsigned j, affectedLen, affectedByLen;

			attr.setObject (attrObject);

			// Get all attributes that this one affects
			MObjectArray affectedAttributes;
			node.getAffectedAttributes( attrObject, affectedAttributes );
			affectedLen = affectedAttributes.length();

			// Get all attributes that affect this one
			MObjectArray affectedByAttributes;
			node.getAffectedByAttributes( attrObject, affectedByAttributes );
			affectedByLen = affectedByAttributes.length();

			if ( affectedLen > 0 || affectedByLen > 0 ) {
				cout << "  " << attr.name() << ":\n";

				// List all attributes that are affected by the current one
				if ( affectedLen > 0 ) {
					cout << "    Affects(" << affectedLen << "):";

					for (j = 0; j < affectedLen; ++j ) {
						attr.setObject ( affectedAttributes[j] );
						cout << " " << attr.name();
					}
					cout << endl;
				}

				// List all attributes that affect the current one
				if ( affectedByLen > 0 ) {
					cout << "    AffectedBy(" << affectedByLen << "):";

					for (j = 0; j < affectedByLen; ++j ) {
						attr.setObject ( affectedByAttributes[j] );
						cout << " " << attr.name();
					}
					cout << endl;
				}
			}
		}
	}
	return MS::kSuccess;
}