/* bennett@cc.gatech.edu */ /* http://www.cc.gatech.edu/gvu/perception/projects/motionMatching/cameraTrack/ */ #include #include #include #include #include #include #include MStatus shiftPath( const MArgList& args ) { cerr << "Running shiftPath\n"; MString attr_change ("") ; double attr_value = 0.0; // Parse the arguments. for ( int t = 0; t < args.length(); t++ ) if ( MString( "-a" ) == args.asString( t ) ) attr_change = args.asString( ++t ); else if ( MString( "-v" ) == args.asString( t ) ) attr_value = args.asDouble( ++t ); // Get the selection list. MStatus status; MSelectionList list; MGlobal::getActiveSelectionList( list ); MItSelectionList * iter = new MItSelectionList( list ); MPlug find_plug; for ( ; !iter->isDone(); iter->next() ) { // find the plug for the attribute of the current node. MObject tempDependNode; iter->getDependNode( tempDependNode ); MFnDependencyNode nodeDepend( tempDependNode ); find_plug = nodeDepend.findPlug (attr_change, &status); if (status != MStatus::kSuccess) { cerr << "Plug not found.\n"; return MStatus::kFailure; } // find out what the plug is connected to. MPlugArray plugList, connectedList ; nodeDepend.getConnections ( plugList ); for ( int i = 1; i <= plugList.length(); i++ ) { /* cerr << plugList[i-1].info() << "\n"; */ if (plugList[i-1] == find_plug) { if (plugList[i-1].connectedTo( connectedList, TRUE, FALSE, &status) == FALSE) cerr << "Plug is not connected\n"; if (status == MStatus::kFailure) cerr << "Failed with connectedTo\n"; for ( int j = 1; j <= connectedList.length() ; j++) { /* cerr << connectedList[j-1].info(); */ /* cerr << "\n"; */ // the plug is connected to an anim curve! get a function set for it MObject anim_curve_ptr = connectedList[j-1].node(); MFnAnimCurve anim (anim_curve_ptr,&status); if (status == MStatus::kFailure) cerr << "Failed creating mfnanimcurve\n"; for (int k = 0; k < anim.numKeyframes(); k++) { // change the value of all keys by the value in the command line anim.setValue(k,anim.value(k) + attr_value); } } } } } return MS::kSuccess; } DeclareSingle ( shiftPath );