void Exporter::RecursiveJointExtraction(MFnTransform& joint, int parentIndex){ Bone output; output.parent = parentIndex; output.invBindPose = joint.transformation().asMatrixInverse().matrix; MItDependencyNodes matIt(MFn::kAnimCurve); while (!matIt.isDone()) { MFnAnimCurve animCurve(matIt.item()); if (!strcmp(animCurve.name().substring(0, joint.name().length() - 1).asChar(), joint.name().asChar())){ cout << animCurve.name().asChar() << endl; std::string type = animCurve.name().substring(joint.name().length(), animCurve.name().length()).asChar(); output.frames.resize(animCurve.time(animCurve.numKeys() - 1).value()); for (int i = 0; i < output.frames.size(); i++) { MTime time; time.setValue(i); output.frames[i].time = time.value(); if (!strcmp(type.c_str(), "_translateX")){ cout << animCurve.evaluate(time) << endl; output.frames[i].trans.x = animCurve.evaluate(time); } if (!strcmp(type.c_str(), "_translateY")){ cout << animCurve.evaluate(time) << endl; output.frames[i].trans.y = animCurve.evaluate(time); } if (!strcmp(type.c_str(), "_translateZ")){ cout << animCurve.evaluate(time) << endl; output.frames[i].trans.z = animCurve.evaluate(time); } if (!strcmp(type.c_str(), "_rotateX")){ cout << animCurve.evaluate(time) << endl; output.frames[i].rot.x = animCurve.evaluate(time); } if (!strcmp(type.c_str(), "_rotateY")){ cout << animCurve.evaluate(time) << endl; output.frames[i].rot.y = animCurve.evaluate(time); } if (!strcmp(type.c_str(), "_rotateZ")){ cout << animCurve.evaluate(time) << endl; output.frames[i].rot.z = animCurve.evaluate(time); } } } matIt.next(); } scene_.skeleton.push_back(output); int children = joint.childCount(); int parent = scene_.skeleton.size() - 1; for (int i = 0; i < children; i++) RecursiveJointExtraction(MFnTransform(joint.child(i)), parent); };
void lrutils::createFKCtlFromLocation(MVectorArray location, MObject joint, MString prefix, unsigned int num, MString icon, MString color, MObject parent, MObject& fkCtlObj, MObject& fkCtlGroupObj, MString layerName, MObject metaDataNode) { MStatus status; MDGModifier dgMod; //used for holding results from executed commands MStringArray result; MFnDependencyNode depMetaDataNodeFn(metaDataNode); //used for creating metaParent attributes for objects MFnMessageAttribute mAttr; MFnTransform jointFn(joint); //create the control object and set its color status = MGlobal::executeCommand( "python(\"control = rig101().rig101WCGetByName('" + icon + "')\");" ); status = MGlobal::executeCommand( "python(\"Utils.setControllerColor(control, '" + color + "')\");" ); status = MGlobal::executeCommand( MString("python(\"control.fullPath()\");"), result ); //get the MObject for the controller status = lrutils::getObjFromName(result[0], fkCtlObj); MyCheckStatus(status, "lrutils::getObjFromName() failed"); MFnTransform fkCtlFn( fkCtlObj ); lrutils::setLocation(fkCtlObj, location, MFnTransform::MFnTransform(), false, false, true); //set controller name MString fkCtlName = prefix + "_FK_"+num+"_CTL"; dgMod.renameNode(fkCtlObj, fkCtlName); //add the metaParent attribute to the controller MObject controlAttr = mAttr.create("metaParent", "metaParent"); fkCtlFn.addAttribute(controlAttr); //connect the controller's metaParent to the MDSpine node status = dgMod.connect( depMetaDataNodeFn.findPlug("FKControllers"), fkCtlFn.findPlug("metaParent") ); dgMod.doIt(); //create the fk control null lrutils::makeHomeNull(fkCtlObj, MFnTransform(), fkCtlGroupObj); lrutils::setLocation(fkCtlGroupObj, location, MFnTransform::MFnTransform(), true, true, false); MFnTransform fkCtlGroupFn( fkCtlGroupObj ); if(!parent.isNull()) { MFnTransform parentFn(parent); MGlobal::executeCommand("parent " + fkCtlGroupFn.fullPathName() + " " + parentFn.fullPathName() + ";"); } //add the metaParent attribute to the controller group fkCtlGroupFn.addAttribute(mAttr.create("metaParent", "metaParent")); //connect the controller group's metaParent to the MDGlobal node status = dgMod.connect( depMetaDataNodeFn.findPlug("FKControllerGroups"), fkCtlGroupFn.findPlug("metaParent") ); MyCheckStatus(status, "connect failed"); dgMod.doIt(); MGlobal::executeCommand("parentConstraint -mo " + fkCtlFn.fullPathName() + " " + jointFn.fullPathName() + ";",result); MObject jointParentConstraintObj; status = lrutils::getObjFromName(result[0], jointParentConstraintObj); MyCheckStatus(status, "lrutils::getObjFromName() failed"); MFnTransform jointParentConstraintFn(jointParentConstraintObj); jointParentConstraintFn.addAttribute(mAttr.create("metaParent", "metaParent")); status = dgMod.connect( depMetaDataNodeFn.findPlug("FKJointParentConstraints"), jointParentConstraintFn.findPlug("metaParent")); dgMod.doIt(); //set the display layers for the controller and controller group MGlobal::executeCommand("editDisplayLayerMembers -noRecurse "+ layerName+" "+ fkCtlFn.fullPathName()+";"); MGlobal::executeCommand("editDisplayLayerMembers -noRecurse "+ layerName+" "+ fkCtlGroupFn.fullPathName()+";"); MGlobal::executeCommand("select -cl;"); }