MStatus nodeInfo::doIt( const MArgList& args ) // // Description // This method performs the action of the command. // // This method iterates over all selected items and // prints out connected plug and dependency node type // information. // { MStatus stat; // Status code MObject dependNode; // Selected dependency node stat = parseArgs ( args ); if ( !stat ) return stat; // Create a selection list iterator // MSelectionList slist; MGlobal::getActiveSelectionList( slist ); MItSelectionList iter( slist, MFn::kInvalid,&stat ); // Iterate over all selected dependency nodes // for ( ; !iter.isDone(); iter.next() ) { // Get the selected dependency node // stat = iter.getDependNode( dependNode ); if ( !stat ) { stat.perror("getDependNode"); continue; } // Create a function set for the dependency node // MFnDependencyNode fnDependNode( dependNode ); // Check the type of the dependency node // MString nodeName = fnDependNode.name(); nodeName += ": "; printType( dependNode, nodeName ); // Get all connected plugs to this node // MPlugArray connectedPlugs; stat = fnDependNode.getConnections( connectedPlugs ); int numberOfPlugs = connectedPlugs.length(); if ( !quiet ) cerr << " Found: " << numberOfPlugs << " connections" << endl; // Print out the dependency node name and attributes // for each plug // for ( int i=0; i<numberOfPlugs; i++ ) { MPlug plug = connectedPlugs[i]; MString pinfo = plug.info(); if ( !quiet ) cerr << " Plug info: " << pinfo << endl; // Now get the plugs that this plug is the // destination of and print the node type. // MPlugArray array; plug.connectedTo( array, true, false ); for ( unsigned int j=0; j<array.length(); j++ ) { MObject mnode = array[j].node(); MString msg( " This plug is a dest of a " ); printType( mnode, msg ); } } } return MS::kSuccess; }
void DMPDSExporter::fillBones( DMPSkeletonData::SubSkeletonStruct* subSkel, string parent, DMPParameters* param, MDagPath& jointDag ) { MStatus status; if (jointDag.apiType() != MFn::kJoint) { return; // early out. } DMPSkeletonData::BoneStruct newBone; newBone.boneHandle = (unsigned int)subSkel->bones.size(); newBone.name = jointDag.partialPathName().asUTF8(); newBone.parentName = parent; MFnIkJoint fnJoint(jointDag, &status); // matrix = [S] * [RO] * [R] * [JO] * [IS] * [T] /* These matrices are defined as follows: •[S] : scale •[RO] : rotateOrient (attribute name is rotateAxis) •[R] : rotate •[JO] : jointOrient •[IS] : parentScaleInverse •[T] : translate The methods to get the value of these matrices are: •[S] : getScale •[RO] : getScaleOrientation •[R] : getRotation •[JO] : getOrientation •[IS] : (the inverse of the getScale on the parent transformation matrix) •[T] : translation */ MVector trans = fnJoint.getTranslation(MSpace::kTransform); double scale[3]; fnJoint.getScale(scale); MQuaternion R, RO, JO; fnJoint.getScaleOrientation(RO); fnJoint.getRotation(R); fnJoint.getOrientation(JO); MQuaternion rot = RO * R * JO; newBone.translate[0] = trans.x * param->lum; newBone.translate[1] = trans.y * param->lum; newBone.translate[2] = trans.z * param->lum; newBone.orientation[0] = rot.w; newBone.orientation[1] = rot.x; newBone.orientation[2] = rot.y; newBone.orientation[3] = rot.z; newBone.scale[0] = scale[0]; newBone.scale[1] = scale[1]; newBone.scale[2] = scale[2]; subSkel->bones.push_back(newBone); // Load child joints for (unsigned int i=0; i<jointDag.childCount();i++) { MObject child; child = jointDag.child(i); MDagPath childDag = jointDag; childDag.push(child); fillBones(subSkel, newBone.name, param, childDag); } // now go for animations if (param->bExportSkelAnimation) { for (unsigned int i = 0; i < subSkel->animations.size(); ++i) { DMPSkeletonData::TransformAnimation& anim = subSkel->animations[i]; DMPSkeletonData::TransformTrack subTrack; subTrack.targetBone = newBone.name; MPlug plugT; // translate MPlug plugR; // R MPlug plugRO; // RO MPlug plugJO; // JO MPlug plugS; // scale double dataT[3]; double dataR[3]; double dataRO[3]; double dataJO[3]; double dataS[3]; MFnDependencyNode fnDependNode( jointDag.node(), &status ); plugT = fnDependNode.findPlug("translate", false, &status); plugR = fnDependNode.findPlug("rotate", false, &status); plugRO = fnDependNode.findPlug("rotateAxis", false, &status); plugJO = fnDependNode.findPlug("jointOrient", false, &status); plugS = fnDependNode.findPlug("scale", false, &status); float timeStep = param->samplerRate; if (param->animSampleType == DMPParameters::AST_Frame) { timeStep /= param->fps; } for (float curTime = anim.startTime; curTime <= anim.endTime; curTime += timeStep) { MTime mayaTime; DMPSkeletonData::TransformKeyFrame keyframe; keyframe.time = curTime - anim.startTime; mayaTime.setUnit(MTime::kSeconds); mayaTime.setValue(curTime); // Get its value at the specified Time. plugT.child(0).getValue(dataT[0], MDGContext(mayaTime)); plugT.child(1).getValue(dataT[1], MDGContext(mayaTime)); plugT.child(2).getValue(dataT[2], MDGContext(mayaTime)); plugR.child(0).getValue(dataR[0], MDGContext(mayaTime)); plugR.child(1).getValue(dataR[1], MDGContext(mayaTime)); plugR.child(2).getValue(dataR[2], MDGContext(mayaTime)); plugRO.child(0).getValue(dataRO[0], MDGContext(mayaTime)); plugRO.child(1).getValue(dataRO[1], MDGContext(mayaTime)); plugRO.child(2).getValue(dataRO[2], MDGContext(mayaTime)); plugJO.child(0).getValue(dataJO[0], MDGContext(mayaTime)); plugJO.child(1).getValue(dataJO[1], MDGContext(mayaTime)); plugJO.child(2).getValue(dataJO[2], MDGContext(mayaTime)); plugS.child(0).getValue(dataS[0], MDGContext(mayaTime)); plugS.child(1).getValue(dataS[1], MDGContext(mayaTime)); plugS.child(2).getValue(dataS[2], MDGContext(mayaTime)); // fill the frame. keyframe.translate[0] = dataT[0] * param->lum; keyframe.translate[1] = dataT[1] * param->lum; keyframe.translate[2] = dataT[2] * param->lum; // calculate quaternion. MEulerRotation rotR(dataR[0], dataR[1], dataR[2]); MEulerRotation rotRO(dataRO[0], dataRO[1], dataRO[2]); MEulerRotation rotJO(dataJO[0], dataJO[1], dataJO[2]); MQuaternion finalRot = rotRO.asQuaternion()*rotR.asQuaternion()*rotJO.asQuaternion(); keyframe.orientation[0] = finalRot.w; keyframe.orientation[1] = finalRot.x; keyframe.orientation[2] = finalRot.y; keyframe.orientation[3] = finalRot.z; keyframe.scale[0] = dataS[0]; keyframe.scale[1] = dataS[1]; keyframe.scale[2] = dataS[2]; subTrack.frames.push_back(keyframe); } anim.tracks.push_back(subTrack); } } }
MStatus motionTrace::redoIt() // // Description // This method performs the action of the command. // // This method iterates over all selected items and // prints out connected plug and dependency node type // information. // { MStatus stat; // Status code MObjectArray picked; MObject dependNode; // Selected dependency node // Create a selection list iterator // MSelectionList slist; MGlobal::getActiveSelectionList( slist ); MItSelectionList iter( slist, MFn::kInvalid,&stat ); // Iterate over all selected dependency nodes // and save them in a list // for ( ; !iter.isDone(); iter.next() ) { // Get the selected dependency node // if ( MS::kSuccess != iter.getDependNode( dependNode ) ) { cerr << "Error getting the dependency node" << endl; continue; } picked.append( dependNode ); } // array of arrays for object position MPointArray *pointArrays = new MPointArray [ picked.length() ]; unsigned int i; double time; // Sample the animation using start, end, by values for ( time = start; time <= end; time+=by ) { MTime timeval(time); MGlobal::viewFrame( timeval ); // Iterate over selected dependency nodes // for ( i = 0; i < picked.length(); i++ ) { // Get the selected dependency node // dependNode = picked[i]; // Create a function set for the dependency node // MFnDependencyNode fnDependNode( dependNode ); // Get the translation attribute values MObject txAttr; txAttr = fnDependNode.attribute( MString("translateX"), &stat ); MPlug txPlug( dependNode, txAttr ); double tx; stat = txPlug.getValue( tx ); MObject tyAttr; tyAttr = fnDependNode.attribute( MString("translateY"), &stat ); MPlug tyPlug( dependNode, tyAttr ); double ty; stat = tyPlug.getValue( ty ); MObject tzAttr; tzAttr = fnDependNode.attribute( MString("translateZ"), &stat ); MPlug tzPlug( dependNode, tzAttr ); double tz; stat = tzPlug.getValue( tz ); #if 0 fprintf( stderr, "Time = %2.2lf, XYZ = ( %2.2lf, %2.2lf, %2.2lf )\n\n", time, tx, ty, tz ); #endif pointArrays[i].append( MPoint( tx, ty, tz )) ; } } // make a path curve for each selected object for ( i = 0; i < picked.length(); i++ ) jMakeCurve( pointArrays[i] ); delete [] pointArrays; return MS::kSuccess; }