//--------------------------------------------------- // Retrieve the bind pose for a controller/joint std::pair // MMatrix DagHelper::getBindPoseInverse ( const MObject& controller, const MObject& influence ) { MStatus status; if ( controller.apiType() == MFn::kSkinClusterFilter ) { MFnSkinCluster controllerFn ( controller ); // Find the correct index for the pre-bind matrix uint index = controllerFn.indexForInfluenceObject ( MDagPath::getAPathTo ( influence ), &status ); if ( status != MStatus::kSuccess ) return MMatrix::identity; MPlug preBindMatrixPlug = controllerFn.findPlug ( "bindPreMatrix", &status ); preBindMatrixPlug = preBindMatrixPlug.elementByLogicalIndex ( index, &status ); if ( status != MStatus::kSuccess ) return MMatrix::identity; // Get the plug's matrix MMatrix ret; if ( !DagHelper::getPlugValue ( preBindMatrixPlug, ret ) ) return MMatrix::identity; return ret; } else if ( controller.apiType() == MFn::kJointCluster ) { MMatrix ret; DagHelper::getPlugValue ( influence, "bindPose", ret ); return ret.inverse(); } else return MMatrix::identity; }
void skinClusterWeights::populateInfluenceIndexArray(MFnSkinCluster &skinClusterFn, MIntArray &influenceIndexArray) { MStatus status; MIntArray allIndexArray; MDagPathArray pathArray; skinClusterFn.influenceObjects(pathArray, &status); for (unsigned j = 0; j < pathArray.length(); j++) { allIndexArray.append(skinClusterFn.indexForInfluenceObject(pathArray[j])); } if (influenceArray.length() > 0) { // Add the influence indices for the influence objects specified in the cmd for (unsigned j = 0; j < influenceArray.length(); j++) { unsigned int index = skinClusterFn.indexForInfluenceObject(influenceArray[j], &status); for (unsigned k = 0; k < allIndexArray.length(); k++) { if ((int)index == allIndexArray[k]) { influenceIndexArray.append(k); } } } } else { // Add the influence indices for all the influence objects of the skinCluster for (unsigned j = 0; j < allIndexArray.length(); j++) { influenceIndexArray.append(j); } } }
// ------------------------------------------------------------ void SceneGraph::addForcedNodes ( const MDagPath& dagPath ) { MFnMesh meshFn ( dagPath ); // Iterate upstream finding all the nodes which affect the mesh. MStatus stat; MPlug plug = meshFn.findPlug ( ATTR_IN_MESH ); if ( plug.isConnected() ) { MItDependencyGraph dependGraphIter ( plug, MFn::kInvalid, MItDependencyGraph::kUpstream, MItDependencyGraph::kDepthFirst, MItDependencyGraph::kPlugLevel, &stat ); if ( stat == MS::kSuccess ) { dependGraphIter.disablePruningOnFilter(); for ( ; ! dependGraphIter.isDone(); dependGraphIter.next() ) { MObject thisNode = dependGraphIter.thisNode(); MFn::Type type = thisNode.apiType(); if ( thisNode.apiType() == MFn::kSkinClusterFilter ) { MFnSkinCluster clusterFn ( thisNode ); MDagPathArray jointPaths; clusterFn.influenceObjects ( jointPaths, &stat ); if ( stat == MS::kSuccess ) { uint count = jointPaths.length(); for ( uint i = 0; i < count; ++i ) appendForcedNodeToList ( jointPaths[i] ); } } else if ( thisNode.apiType() == MFn::kJointCluster ) { MObject joint = DagHelper::getNodeConnectedTo ( thisNode, ATTR_MATRIX ); MDagPath jointPath = MDagPath::getAPathTo ( joint ); appendForcedNodeToList ( jointPath ); } } } } }