From 168937035669ea3cb958284ce29f02004f950594 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Tue, 15 Dec 2015 11:49:59 +0100 Subject: [PATCH] Export the skeletons Not really tested though --- tools/MayaExporter/MayaExporter/Menu.cpp | 14 +++++ tools/MayaExporter/MayaExporter/Menu.h | 2 + tools/MayaExporter/MayaExporter/Skeleton.cpp | 62 +++++++++++++++++--- tools/MayaExporter/MayaExporter/Skeleton.h | 16 +++-- 4 files changed, 79 insertions(+), 15 deletions(-) diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index fc3808f6..8eb245e2 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -145,6 +145,7 @@ void Menu::Button1Clicked(bool) { if (m_ExportAnimationsButton->isChecked()) { MGlobal::displayInfo("1 checked!"); + this->GetSkeletonData(); } else { MGlobal::displayInfo("1 unchecked!"); @@ -185,7 +186,20 @@ void Menu::GetMaterialData() void Menu::GetSkeletonData() { + this->m_SkeletonHandler = new Skeleton(); + // Traverse scene and return vector with all materials + std::vector* AllMaterials = m_SkeletonHandler->DoIt(); + + MGlobal::displayInfo(MString() + AllMaterials->size()); + + for (int i = 0; i < AllMaterials->size(); i++) + { + for (int j = 0; j < AllMaterials->at(i).Joints.size(); j++) + { + MGlobal::displayInfo(MString() + AllMaterials->at(i).Joints.at(j).Name.c_str()); + } + } } Menu::~Menu() diff --git a/tools/MayaExporter/MayaExporter/Menu.h b/tools/MayaExporter/MayaExporter/Menu.h index 6f766025..a0fe93f6 100644 --- a/tools/MayaExporter/MayaExporter/Menu.h +++ b/tools/MayaExporter/MayaExporter/Menu.h @@ -33,6 +33,7 @@ #include "MayaIncludes.h" #include "Material.h" #include "Mesh.h" +#include "Skeleton.h" class Menu : public QWidget { @@ -71,6 +72,7 @@ private: QDialog* m_DialogPointer = nullptr; Material* m_MaterialHandler = nullptr; + Skeleton* m_SkeletonHandler = nullptr; }; #endif \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp index 28f56563..3e95b817 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.cpp +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -1,11 +1,55 @@ #include "Skeleton.h" -//std::vector* Skeleton::DoIt() -//{ -// MItDependencyNodes jointIt(MFn::kJoint); -// -// for (; !jointIt.isDone(); jointIt.next()) -// { -// //MFnDependencyNode -// } -//} \ No newline at end of file +std::vector* Skeleton::DoIt() +{ + MItDependencyNodes jointIt(MFn::kJoint); + SkeletonNode SkeletonStorage; + + while (!jointIt.isDone()) { + MFnDependencyNode SkeletonFnDN(jointIt.thisNode()); + MFnTransform TransformNode(SkeletonFnDN.object()); + Joint NewJoint; + + if (MFnDependencyNode(TransformNode.parent(0)).name() == "world") { + if (SkeletonStorage.Joints.size() != 0) { + m_AllSkeletons.push_back(SkeletonStorage); + + SkeletonStorage.Joints.clear(); + SkeletonStorage.Name.clear(); + } + + SkeletonStorage.Name = TransformNode.name().asChar(); + + NewJoint.ParentIndex = -1; // This joint is root + } + else { + auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), TransformNode.parent(0)); + if (it != m_Hierarchy.end()) { + NewJoint.ParentIndex = it - m_Hierarchy.begin(); + } + else { + MGlobal::displayError(MString() + "Could not find joint parent for: " + TransformNode.name()); + } + } + + m_Hierarchy.push_back(TransformNode.object()); + + NewJoint.Name = TransformNode.name().asChar(); + + MMatrix Matrix = TransformNode.transformationMatrix(); + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j]; + } + } + + SkeletonStorage.Joints.push_back(NewJoint); + + jointIt.next(); + } + + m_AllSkeletons.push_back(SkeletonStorage); + + return &m_AllSkeletons; +} \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Skeleton.h b/tools/MayaExporter/MayaExporter/Skeleton.h index 8b111490..26e99d4b 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.h +++ b/tools/MayaExporter/MayaExporter/Skeleton.h @@ -3,25 +3,29 @@ #include #include +#include #include "MayaIncludes.h" struct Joint { int ParentIndex; - std::array Rotation; - std::array Translation; - std::array Scale; + //std::array Rotation; + //std::array Translation; + //std::array Scale; + std::array, 4> OffsetMatrix; + std::string Name; }; struct SkeletonNode { std::string Name; - std::vector joints; + std::vector Joints; }; class Skeleton { public: - //std::vector* DoIt(); + std::vector* DoIt(); private: - //std::vector m_AllSkeletons; + std::vector m_AllSkeletons; + std::vector m_Hierarchy; }; #endif //Skeleton_Skeleton_h__ \ No newline at end of file