Ejemplo n.º 1
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 );
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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();
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
MStatus CVData::readASCII ( const MArgList& args,
							unsigned& lastParsedElement ) 
{
	MStatus status;
	_intData = args.asInt( lastParsedElement++, &status );
	if ( status == MS::kSuccess ) {
	    _doubleData = args.asDouble( lastParsedElement++, &status );
	} 
	return status;
}
Ejemplo n.º 6
0
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;
    }
}
Ejemplo n.º 7
0
MStatus customAttrCmd::doIt( const MArgList& args )
//
// Description
// 	  This method executes the command given the passed arguments.
//    The arguments consist of a delta value and one or more axes
//    along which the delta value will be applied.
//
{
	MStatus stat;

	delta = args.asDouble( 0, &stat );

	return action( DOIT );
}
Ejemplo n.º 8
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;
}
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;
}
Ejemplo n.º 10
0
/*

	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;
}
Ejemplo n.º 11
0
	void ParamList::parseArgs(const MArgList &args)
	{
		MStatus stat;
		// Parse arguments from command line
		for (unsigned int i = 0; i < args.length(); i++ )
		{
			if ((MString("-all") == args.asString(i,&stat)) && (MS::kSuccess == stat))
				exportAll = true;
			else if ((MString("-world") == args.asString(i,&stat)) && (MS::kSuccess == stat))
				exportWorldCoords = true;
			else if ((MString("-mesh") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportMesh = true;
				meshFilename = args.asString(++i,&stat);
			}
			else if ((MString("-mat") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportMaterial = true;
				materialFilename = args.asString(++i,&stat);
			}
			else if ((MString("-matPrefix") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				matPrefix = args.asString(++i,&stat);
			}
			else if ((MString("-copyTex") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				copyTextures = true;
				texOutputDir = args.asString(++i,&stat);
			}
			else if ((MString("-lightOff") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				lightingOff = true;
			}
			else if ((MString("-skel") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportSkeleton = true;
				skeletonFilename = args.asString(++i,&stat);
			}
			else if ((MString("-anims") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportAnims = true;
			}
			else if ((MString("-animCur") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportAnimCurves = true;
				animFilename = args.asString(++i,&stat);
			}
			else if ((MString("-cam") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportCameras = true;
				camerasFilename = args.asString(++i,&stat);
			}
			else if ((MString("-v") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportVBA = true;
			}
			else if ((MString("-n") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportVertNorm = true;
			}
			else if ((MString("-c") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportVertCol = true;
			}
			else if ((MString("-cw") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportVertCol = true;
				exportVertColWhite = true;
			}
			else if ((MString("-t") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportTexCoord = true;
			}
			else if ((MString("-camAnim") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportCamerasAnim = true;
			}
			else if ((MString("-meshbin") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportMeshBin = true;
			}
			else if ((MString("-skelbin") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportSkelBin = true;
			}
			else if ((MString("-particles") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				exportParticles = true;
				particlesFilename = args.asString(++i,&stat);
			}
			else if ((MString("-shared") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				useSharedGeom = true;
			}
			else if ((MString("-np") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				MString npType = args.asString(i,&stat);
				if (npType == "curFrame")
					neutralPoseType = NPT_CURFRAME;
				else if (npType == "bindPose")
					neutralPoseType = NPT_BINDPOSE;
				else if (npType == "frame")
				{
					neutralPoseType = NPT_FRAME;
					neutralPoseFrame = args.asInt(++i,&stat);
				}
			}
			else if ((MString("-clip") == args.asString(i,&stat)) && (MS::kSuccess == stat))
			{
				//get clip name
				MString clipName = args.asString(++i,&stat);
				//get clip range
				MString clipRangeType = args.asString(++i,&stat);
				double startTime, stopTime;
				if (clipRangeType == "startEnd")
				{
					startTime = args.asDouble(++i,&stat);
					stopTime = args.asDouble(++i,&stat);
					MString rangeUnits = args.asString(++i,&stat);
					if (rangeUnits == "frames")
					{
						//range specified in frames => convert to seconds
						MTime t1(startTime, MTime::uiUnit());
						MTime t2(stopTime, MTime::uiUnit());
						startTime = t1.as(MTime::kSeconds);
						stopTime = t2.as(MTime::kSeconds);
					}
				}
				else
				{
					//range specified by time slider
					MTime t1 = MAnimControl::minTime();
					MTime t2 = MAnimControl::maxTime();
					startTime = t1.as(MTime::kSeconds);
					stopTime = t2.as(MTime::kSeconds);
				}
				// get sample rate
				double rate;
				MString sampleRateType = args.asString(++i,&stat);
				if (sampleRateType == "sampleByFrames")
				{
					// rate specified in frames
					int intRate = args.asInt(++i,&stat);
					MTime t = MTime(intRate, MTime::uiUnit());
					rate = t.as(MTime::kSeconds);
				}
				else
				{
					// rate specified in seconds
					rate = args.asDouble(++i,&stat);
				}
				//add clip info
				clipInfo clip;
				clip.name = clipName;
				clip.start = startTime;
				clip.stop = stopTime;
				clip.rate = rate;
				clipList.push_back(clip);
				std::cout << "clip " << clipName.asChar() << "\n";
				std::cout << "start: " << startTime << ", stop: " << stopTime << "\n";
				std::cout << "rate: " << rate << "\n";
				std::cout << "-----------------\n";
			}
		}
	/*	// Read options from exporter window
		// Gather clips data
		// Read info about the clips we have to transform
		int numClips,exportClip,rangeType,rateType,rangeUnits;
		double startTime,stopTime,rate;
		MString clipName;
		//read number of clips
		MGlobal::executeCommand("eval \"$numClips+=0\"",numClips,false);
		//read clips data
		for (int i=1; i<=numClips; i++)
		{
			MString command = "checkBox -q -v ExportClip";
			command += i;
			MGlobal::executeCommand(command,exportClip,false);
			if (exportClip)
			{
				//get clip name
				command = "textField -q -tx ClipName";
				command += i;
				MGlobal::executeCommand(command,clipName,false);
				//get clip range
				command = "radioButtonGrp -q -sl ClipRangeRadio";
				command += i;
				MGlobal::executeCommand(command,rangeType,false);
				if (rangeType == 1)
				{	//range specified from user
					command = "floatField -q -v ClipRangeStart";
					command += i;
					MGlobal::executeCommand(command,startTime,false);
					command = "floatField -q -v ClipRangeEnd";
					command += i;
					MGlobal::executeCommand(command,stopTime,false);
					//get range units
					command = "radioButtonGrp -q -sl ClipRangeUnits";
					command += i;
					MGlobal::executeCommand(command,rangeUnits,false);
					if (rangeUnits == 1)
					{	//range specified in frames => convert to seconds
						MTime t1(startTime, MTime::uiUnit());
						MTime t2(stopTime, MTime::uiUnit());
						startTime = t1.as(MTime::kSeconds);
						stopTime = t2.as(MTime::kSeconds);
					}
				}
				else
				{	//range specified by time slider
					MTime t1 = MAnimControl::minTime();
					MTime t2 = MAnimControl::maxTime();
					startTime = t1.as(MTime::kSeconds);
					stopTime = t2.as(MTime::kSeconds);
				}
				//get sample rate
				command = "radioButtonGrp -q -sl ClipRateType";
				command += i;
				MGlobal::executeCommand(command,rateType,false);
				MTime t;
				switch (rateType)
				{
				case 1:	//rate specified in frames
					command = "intField -q -v ClipRateFrames";
					command += i;
					MGlobal::executeCommand(command,rate,false);
					t = MTime(rate, MTime::uiUnit());
					rate = t.as(MTime::kSeconds);
					break;
				case 2:	//rate specified in seconds
					command = "floatField -q -v ClipRateSeconds";
					command += i;
					MGlobal::executeCommand(command,rate,false);
					break;
				default://rate not specified, get from time slider
					rate = -1;
					break;
				}
				//add clip info
				clipInfo clip;
				clip.name = clipName;
				clip.start = startTime;
				clip.stop = stopTime;
				clip.rate = rate;
				clipList.push_back(clip);
				std::cout << "clip " << clipName.asChar() << "\n";
				std::cout << "start: " << startTime << ", stop: " << stopTime << "\n";
				std::cout << "rate: " << rate << "\n";
				std::cout << "-----------------\n";
			}
		}*/
	}
Ejemplo n.º 12
0
MStatus pointOnMeshCommand::doIt(const MArgList& args)

{

    // INITIALIZE PRIVATE DATA FOR THE COMMAND:

    nodeCreated = positionSpecified = normalSpecified = faceIndexSpecified = relativeSpecified = parameterUSpecified = parameterVSpecified = false;

    meshNodeName = pointOnMeshInfoName = "";



    // PARSE THE COMMAND'S ARGUMENTS:

    for (unsigned i=0; i<args.length(); i++)

    {

        if ((MString("-name")==args.asString(i)) || (MString("-na")==args.asString(i)))

            pointOnMeshInfoName = args.asString(++i);

        else if ((MString("-position")==args.asString(i)) || (MString("-p")==args.asString(i)))

            positionSpecified = true;

        else if ((MString("-normal")==args.asString(i)) || (MString("-nr")==args.asString(i)))

            normalSpecified = true;

        else if ((MString("-faceIndex")==args.asString(i)) || (MString("-f")==args.asString(i)))

        {

            faceIndexSpecified = true;

            int temp = args.asInt(++i);

            if (temp<0)

            {

                displayError("Invalid faceIndex!");

                return MS::kFailure;

            }

            faceIndex = temp;

        }

        else if ((MString("-relative")==args.asString(i)) || (MString("-r")==args.asString(i)))

        {

            relativeSpecified = true;

            relative = args.asBool(++i);

        }

        else if ((MString("-parameterU")==args.asString(i)) || (MString("-u")==args.asString(i)))

        {

            parameterUSpecified = true;

            double temp = args.asDouble(++i);

            if ((temp<0) || (temp>1))

            {

                displayError("Invalid parameterU!");

                return MS::kFailure;

            }

            parameterU = temp;

        }

        else if ((MString("-parameterV")==args.asString(i)) || (MString("-v")==args.asString(i)))

        {

            parameterVSpecified = true;

            double temp = args.asDouble(++i);

            if ((temp<0) || (temp>1))

            {

                displayError("Invalid parameterV!");

                return MS::kFailure;

            }

            parameterV = temp;

        }

        else if (i==(args.length()-1))

            meshNodeName = args.asString(i);

        else

        {

            MString errorMessage = "Invalid flag: ";

            errorMessage += args.asString(i);

            displayError(errorMessage);

            return MS::kFailure;

        }

    }



    // MAKE SURE UNSPECIFIED INPUT PARAMETER FLAGS GET DEFAULT VALUES:

    if (!faceIndexSpecified)

        faceIndex = 0;

    if (!relativeSpecified)

        relative = true;

    if (!parameterUSpecified)

        parameterU = 0.5;

    if (!parameterVSpecified)

        parameterV = 0.5;



    // DO THE WORK:

    return redoIt();

}