diff --git a/tools/MayaExporter/MayaExporter/Export.cpp b/tools/MayaExporter/MayaExporter/Export.cpp index 2b2764b1..3497fd04 100644 --- a/tools/MayaExporter/MayaExporter/Export.cpp +++ b/tools/MayaExporter/MayaExporter/Export.cpp @@ -120,6 +120,8 @@ bool Export::Materials(std::string pathName) bool Export::Animations(std::string pathName, std::vector animInfo) { + allAnimations.clear(); + allBindPoses.clear(); if (MAnimControl::currentTime().unit() != MTime::kNTSCField) { MGlobal::displayError(MString() + "Please change to 60 FPS under Preferences/Settings!"); diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 9cc6de91..02810018 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -60,8 +60,6 @@ Menu::Menu(QDialog* dialog) m_ExportPath = new QLineEdit; m_FileDialog = new QFileDialog; - QString tmpPath("C:/Users/Nickelodion/Desktop/workspace/tacticalZ/assets/models/"); - m_ExportPath->setText(tmpPath); QLabel* exportLabel = new QLabel; exportLabel->setText("Export Path:"); QLabel* nameLabel = new QLabel; diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp index 94031629..bde87247 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.cpp +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -74,28 +74,86 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e returnData.nameLength = animationName.size() + 1; returnData.Duration = (endFrame - startFrame) * oneDivSixty; + std::map, 4>> joinCheckMap; + std::map exportJoint; + MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); - while (!jointIt.isDone()) + for (unsigned int i = startFrame; i <= endFrame; i++) { - m_Hierarchy.push_back(jointIt.item()); - - MFnDependencyNode depNode(jointIt.item()); - MGlobal::displayInfo("-------- INFO ---------"); - MGlobal::displayInfo("Joint name: " + depNode.name()); - //Loop toght the attr Array to find keyframes; - for (int i = 0; i < 9; i++) + MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField)); + while (!jointIt.isDone()) { - MStatus tmp; - MPlug plug = depNode.findPlug(attr[i].c_str(), &tmp); + m_Hierarchy.push_back(jointIt.item()); - MPlugArray connections; - plug.connectedTo(connections, true, false, 0); - for (int j = 0; j != connections.length(); j++) { - MObject connected = connections[j].node(); + MFnTransform MayaJoint(jointIt.item()); + MMatrix transformationMatrix = MayaJoint.transformationMatrix(); - if (connected.hasFn(MFn::kAnimCurve)) { + if (i == startFrame) + { + double doubleMat[4][4]; + transformationMatrix.get(doubleMat); - MFnAnimCurve jointAnim(connected); + joinCheckMap[MayaJoint.name().asChar()][0][0] = doubleMat[0][0]; + joinCheckMap[MayaJoint.name().asChar()][0][1] = doubleMat[0][1]; + joinCheckMap[MayaJoint.name().asChar()][0][2] = doubleMat[0][2]; + joinCheckMap[MayaJoint.name().asChar()][0][3] = doubleMat[0][3]; + joinCheckMap[MayaJoint.name().asChar()][1][0] = doubleMat[1][0]; + joinCheckMap[MayaJoint.name().asChar()][1][1] = doubleMat[1][1]; + joinCheckMap[MayaJoint.name().asChar()][1][2] = doubleMat[1][2]; + joinCheckMap[MayaJoint.name().asChar()][1][3] = doubleMat[1][3]; + joinCheckMap[MayaJoint.name().asChar()][2][0] = doubleMat[2][0]; + joinCheckMap[MayaJoint.name().asChar()][2][1] = doubleMat[2][1]; + joinCheckMap[MayaJoint.name().asChar()][2][2] = doubleMat[2][2]; + joinCheckMap[MayaJoint.name().asChar()][2][3] = doubleMat[2][3]; + joinCheckMap[MayaJoint.name().asChar()][3][0] = doubleMat[3][0]; + joinCheckMap[MayaJoint.name().asChar()][3][1] = doubleMat[3][1]; + joinCheckMap[MayaJoint.name().asChar()][3][2] = doubleMat[3][2]; + joinCheckMap[MayaJoint.name().asChar()][3][3] = doubleMat[3][3]; + + exportJoint[MayaJoint.name().asChar()] = false; + } + else if(!exportJoint[MayaJoint.name().asChar()])//!exportJoint[MayaJoint.name().asChar()]) + { + double doubleMat[4][4]; + + doubleMat[0][0] = joinCheckMap[MayaJoint.name().asChar()][0][0]; + doubleMat[0][1] = joinCheckMap[MayaJoint.name().asChar()][0][1]; + doubleMat[0][2] = joinCheckMap[MayaJoint.name().asChar()][0][2]; + doubleMat[0][3] = joinCheckMap[MayaJoint.name().asChar()][0][3]; + doubleMat[1][0] = joinCheckMap[MayaJoint.name().asChar()][1][0]; + doubleMat[1][1] = joinCheckMap[MayaJoint.name().asChar()][1][1]; + doubleMat[1][2] = joinCheckMap[MayaJoint.name().asChar()][1][2]; + doubleMat[1][3] = joinCheckMap[MayaJoint.name().asChar()][1][3]; + doubleMat[2][0] = joinCheckMap[MayaJoint.name().asChar()][2][0]; + doubleMat[2][1] = joinCheckMap[MayaJoint.name().asChar()][2][1]; + doubleMat[2][2] = joinCheckMap[MayaJoint.name().asChar()][2][2]; + doubleMat[2][3] = joinCheckMap[MayaJoint.name().asChar()][2][3]; + doubleMat[3][0] = joinCheckMap[MayaJoint.name().asChar()][3][0]; + doubleMat[3][1] = joinCheckMap[MayaJoint.name().asChar()][3][1]; + doubleMat[3][2] = joinCheckMap[MayaJoint.name().asChar()][3][2]; + doubleMat[3][3] = joinCheckMap[MayaJoint.name().asChar()][3][3]; + + MMatrix tmp(doubleMat); + if (!tmp.isEquivalent(transformationMatrix)) { + MGlobal::displayInfo(MString() + MayaJoint.name() + " is exported"); + exportJoint[MayaJoint.name().asChar()] = true; + animatedJoints.push_back(MayaJoint.object()); + } + } + + /*for (int i = 0; i < 9; i++) + { + MStatus tmp; + MPlug plug = depNode.findPlug(attr[i].c_str(), &tmp); + + MPlugArray connections; + plug.connectedTo(connections, true, false, 0); + for (int j = 0; j != connections.length(); j++) { + MObject connected = connections[j].node(); + + if (connected.hasFn(MFn::kAnimCurve)) { + + MFnAnimCurve jointAnim(connected); //MGlobal::displayInfo(MString() + "curve : " + jointAnim.name()); //MGlobal::displayInfo(MString() + "curve keys : " + jointAnim.numKeys()); @@ -103,61 +161,62 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e //MGlobal::displayInfo(MString() + "startFrame : " + startFrame); //MGlobal::displayInfo(MString() + "endFrame : " + endFrame); - unsigned int startKeyFrameIndex = jointAnim.findClosest(MTime(startFrame, MTime::kNTSCField), &tmp); + unsigned int startKeyFrameIndex = jointAnim.findClosest(MTime(startFrame, MTime::kNTSCField), &tmp); - if (tmp == MStatus::kFailure) - MGlobal::displayInfo(MString() + "Fail :c"); + if (tmp == MStatus::kFailure) + MGlobal::displayInfo(MString() + "Fail :c"); - //MGlobal::displayInfo(MString() + "Start key index : " + startKeyFrameIndex); + if (startFrame * oneDivSixty <= jointAnim.time(startKeyFrameIndex).value() && jointAnim.time(startKeyFrameIndex).value() <= endFrame * oneDivSixty) { //MGlobal::displayInfo(MString() + "Start key time : " + jointAnim.time(startKeyFrameIndex).value()); if (startFrame <= jointAnim.time(startKeyFrameIndex).value() && jointAnim.time(startKeyFrameIndex).value() <= endFrame ) { - animatedJoints.push_back(jointIt.item()); - i = 9; - break; - } + animatedJoints.push_back(jointIt.item()); + i = 9; + break; + } - unsigned int endKeyFrameIndex = jointAnim.findClosest(MTime(endFrame, MTime::kNTSCField), &tmp); - if (tmp == MStatus::kFailure) + unsigned int endKeyFrameIndex = jointAnim.findClosest(MTime(endFrame, MTime::kNTSCField)); + MGlobal::displayInfo(MString() + startKeyFrameIndex + " " + endKeyFrameIndex); MGlobal::displayInfo(MString() + "Fail!!!!!!!!!!!!!!!!!!!!!!!!!"); - + if (startFrame * oneDivSixty <= jointAnim.time(endKeyFrameIndex).value() && jointAnim.time(endKeyFrameIndex).value() <= endFrame * oneDivSixty || endKeyFrameIndex - startKeyFrameIndex > 0) { //MGlobal::displayInfo(MString() + "End key index : " + endKeyFrameIndex); //MGlobal::displayInfo(MString() + "end key time : " + jointAnim.time(endKeyFrameIndex).value()); /*MGlobal::displayInfo(MString() + "start keyfram index: " + startKeyFrameIndex + ". End keyfram index: " + endKeyFrameIndex + ".");*/ if (startFrame <= jointAnim.time(endKeyFrameIndex).value() && jointAnim.time(endKeyFrameIndex).value() <= endFrame || endKeyFrameIndex - startKeyFrameIndex > 0) { - animatedJoints.push_back(jointIt.item()); - i = 9; - break; + animatedJoints.push_back(jointIt.item()); + i = 9; + break; + } + + MFnTransform MayaJoint(jointIt.item()); + + MPlug BindPose = MayaJoint.findPlug("bindPose"); + MDataHandle DataHandle; + BindPose.getValue(DataHandle); + MFnMatrixData MartixFn(DataHandle.data()); + MMatrix BindPoseMatrix = MartixFn.matrix(); + + if (!BindPoseMatrix.isEquivalent(MayaJoint.transformationMatrix())) + { + MGlobal::displayError(MString() + animationName.c_str() + " is using " + MayaJoint.name() + " that is not in bind pose nor is it key framed in the animation, the exported animation will NOT correspond to the animation in Maya"); + } + } } - - MFnTransform MayaJoint(jointIt.item()); - - MPlug BindPose = MayaJoint.findPlug("bindPose"); - MDataHandle DataHandle; - BindPose.getValue(DataHandle); - MFnMatrixData MartixFn(DataHandle.data()); - MMatrix BindPoseMatrix = MartixFn.matrix(); - - if (!BindPoseMatrix.isEquivalent(MayaJoint.transformationMatrix(), 0.0000001f)) - { - MGlobal::displayError(MString() + animationName.c_str() + " is using " + MayaJoint.name() + " that is not in bind pose nor is it key framed in the animation, the exported animation will NOT correspond to the animation in Maya"); - } - } - }//end of connections.length() loop + }*/ } // end of int i loop - jointIt.next(); - } // enf of while (!jointIt.isDone()) - - + jointIt.next(); + } + jointIt.reset(); + } int currentFrame = startFrame; - while (currentFrame != endFrame + 1) { // ANDREAS + while (currentFrame <= endFrame) { // ANDREAS Animation::Keyframe thisKeyFrame; thisKeyFrame.Index = currentFrame - startFrame; thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty; @@ -242,7 +301,7 @@ std::vector Skeleton::GetBindPoses() MFnTransform MayaJoint(jointIt.currentItem()); BindPoseSkeletonNode::BindPoseJoint NewJoint; - if (MFnDependencyNode(MayaJoint.parent(0)).name() == "world") { + if (MFnDependencyNode(MayaJoint.parent(0)).object().apiType() != MFn::kJoint) { if (SkeletonStorage.Joints.size() != 0) { m_AllSkeletons.push_back(SkeletonStorage); diff --git a/tools/MayaExporter/MayaExporter/Skeleton.h b/tools/MayaExporter/MayaExporter/Skeleton.h index 6a288c8a..9033441d 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.h +++ b/tools/MayaExporter/MayaExporter/Skeleton.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "MayaIncludes.h" #include "OutputData.h"