From 24486c314dffcdf0294682cc3da0e6be1f559c56 Mon Sep 17 00:00:00 2001 From: antc13 Date: Wed, 13 Jan 2016 14:03:58 +0100 Subject: [PATCH] Reworked the Exporter. --- tools/MayaExporter/MayaExporter/Export.cpp | 172 ++++++++++++++ tools/MayaExporter/MayaExporter/Export.h | 54 +++++ .../GeneratedFiles/Debug/moc_Menu.cpp | 42 ++-- .../MayaExporter/MayaExporter.vcxproj | 2 + .../MayaExporter/MayaExporter.vcxproj.filters | 6 + tools/MayaExporter/MayaExporter/Menu.cpp | 213 ++++-------------- tools/MayaExporter/MayaExporter/Menu.h | 23 +- tools/MayaExporter/MayaExporter/Mesh.cpp | 26 ++- tools/MayaExporter/MayaExporter/Mesh.h | 45 +++- tools/MayaExporter/MayaExporter/Skeleton.cpp | 11 +- tools/MayaExporter/MayaExporter/Skeleton.h | 6 + tools/MayaExporter/MayaExporter/WriteToFile.h | 10 +- 12 files changed, 369 insertions(+), 241 deletions(-) create mode 100644 tools/MayaExporter/MayaExporter/Export.cpp create mode 100644 tools/MayaExporter/MayaExporter/Export.h diff --git a/tools/MayaExporter/MayaExporter/Export.cpp b/tools/MayaExporter/MayaExporter/Export.cpp new file mode 100644 index 00000000..82c81cfa --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Export.cpp @@ -0,0 +1,172 @@ +#include "Export.h" + +Export::Export() +{ + +} + +bool Export::Meshes(std::string pathName, bool selectedOnly) +{ + if (pathName.empty()) { + MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file"); + return false; + } + meshes.clear(); + + if (selectedOnly) { + // Retrieving the objects we currently have selected + MSelectionList selected; + MGlobal::getActiveSelectionList(selected); + + // Loop through or list of selection(s) + for (unsigned int i = 0; i < selected.length(); i++) { + MObject object; + selected.getDependNode(i, object); + + if (object.hasFn(MFn::kMesh)) { + MFnDependencyNode thisNode(object); + GetMeshData(object); + } + } + } else { + // Loop through all nodes in the scene + MItDependencyNodes it(MFn::kMesh); + for (; !it.isDone(); it.next()) { + MObject node = it.thisNode(); + MFnDependencyNode thisNode(node); + MPlugArray connections; + thisNode.findPlug("inMesh").connectedTo(connections, true, true); + bool next = false; + + for (unsigned int i = 0; i < connections.length(); i++) { + if (connections[i].node().apiType() == MFn::kSkinClusterFilter) { + next = true; + break; + } + } + + if (next) + continue; + + GetMeshData(node); + } + } + MGlobal::displayInfo(MString() + "nrofmeshes: " + meshes.size()); + WriteMeshData(pathName); + return true; +} + +bool Export::Materials() +{ + return true; +} + +bool Export::Animations(std::string pathName, std::vector animInfo) +{ + if (MAnimControl::currentTime().unit() != MTime::kNTSCField) { + + MGlobal::displayError(MString() + "Please change to 60 FPS under Preferences/Settings!"); + return false; + } + + if (pathName.empty()) { + MGlobal::displayError(MString() + "Export::Animations() got no pathName. Do not know where to write file"); + return false; + } + MGlobal::displayInfo("HALLOOOO"); + allBindPoses = m_SkeletonHandler.GetBindPoses(); + + for (auto clip : animInfo) { + MGlobal::displayInfo("preben"); + if (!GetAnimationData(clip)) { + MGlobal::displayError(MString() + "Export::Animations() failed to export " + clip.Name.c_str()); + return false; + } + } + MGlobal::displayInfo("ghihgihi"); + WriteAnimData(pathName); + return true; +} + +bool Export::GetMeshData(MObject object) +{ + if (!object.hasFn(MFn::kMesh)) + return false; + + meshes.push_back(m_MeshHandler.GetMeshData(object)); + return true; +} + +bool Export::GetMaterialData() +{ + // Traverse scene and return vector with all materials + std::vector* AllMaterials = m_MaterialHandler.DoIt(); + + // Access the colorR component of one material (example) + cout << AllMaterials->at(0).Color[0] << endl; + MGlobal::displayInfo(MString() + AllMaterials->at(0).Color[0]); + return true; +} + +bool Export::GetAnimationData(AnimationInfo animInfo) +{ + if (animInfo.Name.empty()) { + MGlobal::displayError(MString() + "A clip does not have a name"); + return false; + } + if (animInfo.End - animInfo.Start <= 0) { + MGlobal::displayError(MString() + "A clip ends before it starts or contains 0 frames"); + return false; + } + + allAnimations.push_back(m_SkeletonHandler.GetAnimData(animInfo.Name, animInfo.Start, animInfo.End)); + return true; +} + +void Export::WriteMeshData(std::string pathName) +{ + m_MeshFile.ASCIIFilePath(pathName +"_mesh.txt"); + m_MeshFile.binaryFilePath(pathName + ".mesh"); + + m_MeshFile.OpenFiles(); + + for (auto aMesh : meshes) { + m_MeshFile.writeToFiles((OutputData*)&aMesh); + } + + m_MeshFile.CloseFiles(); +} + +void Export::WriteAnimData(std::string pathName) +{ + if (allBindPoses.size() > 0) { + m_AnimFile.ASCIIFilePath(pathName + "_anim.txt"); + m_AnimFile.binaryFilePath(pathName + ".anim"); + + m_AnimFile.OpenFiles(); + int size = allBindPoses.size(); + m_AnimFile.writeToFiles(&size); + + size = allAnimations.size(); + m_AnimFile.writeToFiles(&size); + + //print out all bind poses + for (auto aBindPose : allBindPoses) { + m_AnimFile.writeToFiles((OutputData*)&aBindPose); + } + for (auto aAnimation : allAnimations) { + m_AnimFile.writeToFiles((OutputData*)&aAnimation); + } + + m_AnimFile.CloseFiles(); + } else + MGlobal::displayInfo("Export::WriteAnimData() got called when allBindPoses contained no data, did not write nor created them"); +} + +Export::~Export() +{ + /* delete m_MaterialHandler; + delete m_SkeletonHandler; + delete m_MeshHandler;*/ + +} \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Export.h b/tools/MayaExporter/MayaExporter/Export.h new file mode 100644 index 00000000..83d27459 --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Export.h @@ -0,0 +1,54 @@ +#ifndef Export_Export_h__ +#define Export_Export_h__ + +#include +#include + +#include "MayaIncludes.h" +#include "Material.h" +#include "Mesh.h" +#include "Skeleton.h" +#include "WriteToFile.h" + +class Export { +public: + Export(); + + ~Export(); + + struct AnimationInfo { + std::string Name; + int Start; + int End; + }; + + bool Meshes(std::string pathName, bool selectedOnly = false); + bool Materials(); + bool Animations(std::string pathName, std::vector animInfo); + +private: + bool GetMeshData(MObject object); + bool GetMaterialData(); + bool GetAnimationData(AnimationInfo info); + + void WriteMeshData(std::string pathName); + void WriteAnimData(std::string pathName); + + Material m_MaterialHandler; + Skeleton m_SkeletonHandler; + MeshClass m_MeshHandler; + + + //File export + WriteToFile m_MeshFile; + WriteToFile m_AnimFile; + + //Mesh Data + std::vector meshes; + + //Animation Data + std::vector allBindPoses; + std::vector allAnimations; + +}; +#endif \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/GeneratedFiles/Debug/moc_Menu.cpp b/tools/MayaExporter/MayaExporter/GeneratedFiles/Debug/moc_Menu.cpp index a375ed53..c7879431 100644 --- a/tools/MayaExporter/MayaExporter/GeneratedFiles/Debug/moc_Menu.cpp +++ b/tools/MayaExporter/MayaExporter/GeneratedFiles/Debug/moc_Menu.cpp @@ -22,7 +22,7 @@ static const uint qt_meta_data_Menu[] = { 6, // revision 0, // classname 0, 0, // classinfo - 9, 14, // methods + 5, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors @@ -30,25 +30,19 @@ static const uint qt_meta_data_Menu[] = { 0, // signalCount // slots: signature, parameters, type, tag, flags - 14, 6, 5, 5, 0x08, - 35, 5, 5, 5, 0x08, - 59, 5, 5, 5, 0x08, - 80, 5, 5, 5, 0x08, - 104, 5, 5, 5, 0x08, - 120, 5, 5, 5, 0x08, - 140, 5, 5, 5, 0x08, - 161, 5, 5, 5, 0x08, - 182, 5, 5, 5, 0x08, + 6, 5, 5, 5, 0x08, + 30, 5, 5, 5, 0x08, + 51, 5, 5, 5, 0x08, + 75, 5, 5, 5, 0x08, + 91, 5, 5, 5, 0x08, 0 // eod }; static const char qt_meta_stringdata_Menu[] = { - "Menu\0\0checked\0ExportSelected(bool)\0" - "ExportPathClicked(bool)\0AddClipClicked(bool)\0" - "RemoveClipClicked(bool)\0ExportAll(bool)\0" - "CancelClicked(bool)\0Button1Clicked(bool)\0" - "Button2Clicked(bool)\0Button3Clicked(bool)\0" + "Menu\0\0ExportPathClicked(bool)\0" + "AddClipClicked(bool)\0RemoveClipClicked(bool)\0" + "ExportAll(bool)\0CancelClicked(bool)\0" }; void Menu::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) @@ -57,15 +51,11 @@ void Menu::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void * Q_ASSERT(staticMetaObject.cast(_o)); Menu *_t = static_cast(_o); switch (_id) { - case 0: _t->ExportSelected((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 1: _t->ExportPathClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 2: _t->AddClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 3: _t->RemoveClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 4: _t->ExportAll((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 5: _t->CancelClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 6: _t->Button1Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 7: _t->Button2Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 8: _t->Button3Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break; + case 0: _t->ExportPathClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; + case 1: _t->AddClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; + case 2: _t->RemoveClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; + case 3: _t->ExportAll((*reinterpret_cast< bool(*)>(_a[1]))); break; + case 4: _t->CancelClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; default: ; } } @@ -103,9 +93,9 @@ int Menu::qt_metacall(QMetaObject::Call _c, int _id, void **_a) if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { - if (_id < 9) + if (_id < 5) qt_static_metacall(this, _c, _id, _a); - _id -= 9; + _id -= 5; } return _id; } diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj index 701b39cf..4a7ac07e 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj @@ -153,6 +153,7 @@ + @@ -199,6 +200,7 @@ + diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters index be5b36b1..ae3d2478 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters @@ -62,6 +62,9 @@ Source Files + + Source Files + @@ -96,5 +99,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 7e1e6cde..1ff007b4 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -13,9 +13,8 @@ Menu::Menu(QDialog* dialog) m_DialogPointer = dialog; // Create QpushButtons & give them names - m_ExportSelectedButton = new QPushButton("&Export Selected", this); m_BrowseButton = new QPushButton("&...", this); - m_ExportAllButton = new QPushButton("&Export All", this); + m_ExportAllButton = new QPushButton("&Export", this); m_CancelButton = new QPushButton("&Cancel", this); m_AddClipsButton = new QPushButton("&Add Clips", this); m_RemoveClipsButton = new QPushButton("&Remove Latest Clip", this); @@ -23,6 +22,7 @@ Menu::Menu(QDialog* dialog) // Option box and checkboxes QGroupBox *optionsBox = new QGroupBox(tr("Options")); + m_ExportSelectedButton = new QCheckBox(tr("&Export Selected")); m_ExportAnimationsButton = new QCheckBox(tr("&Export Animations")); m_CopyTexturesButton = new QCheckBox(tr("&Copy Textures")); m_Button3 = new QCheckBox(tr("Test Materials")); @@ -30,6 +30,7 @@ Menu::Menu(QDialog* dialog) m_ExportAnimationsButton->setChecked(true); m_CopyTexturesButton->setChecked(true); QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(m_ExportSelectedButton); vbox->addWidget(m_ExportAnimationsButton); vbox->addWidget(m_CopyTexturesButton); vbox->addWidget(m_Button3); @@ -37,16 +38,16 @@ Menu::Menu(QDialog* dialog) optionsBox->setLayout(vbox); // Connect the buttons with signals & functions - connect(m_ExportSelectedButton, SIGNAL(clicked(bool)), this, SLOT(ExportSelected(bool))); connect(m_BrowseButton, SIGNAL(clicked(bool)), this, SLOT(ExportPathClicked(bool))); connect(m_ExportAllButton, SIGNAL(clicked(bool)), this, SLOT(ExportAll(bool))); connect(m_CancelButton, SIGNAL(clicked(bool)), this, SLOT(CancelClicked(bool))); connect(m_AddClipsButton, SIGNAL(clicked(bool)), this, SLOT(AddClipClicked(bool))); connect(m_RemoveClipsButton, SIGNAL(clicked(bool)), this, SLOT(RemoveClipClicked(bool))); - connect(m_ExportAnimationsButton, SIGNAL(clicked(bool)), this, SLOT(Button1Clicked(bool))); - connect(m_CopyTexturesButton, SIGNAL(clicked(bool)), this, SLOT(Button2Clicked(bool))); - connect(m_Button3, SIGNAL(clicked(bool)), this, SLOT(Button3Clicked(bool))); + connect(m_ExportSelectedButton, SIGNAL(clicked(bool)), this, SLOT(NULL)); + connect(m_ExportAnimationsButton, SIGNAL(clicked(bool)), this, SLOT(NULL)); + connect(m_CopyTexturesButton, SIGNAL(clicked(bool)), this, SLOT(NULL)); + connect(m_Button3, SIGNAL(clicked(bool)), this, SLOT(NULL)); // Creating several layouts, adding widgets & adding them to one layout in the end QHBoxLayout* topLayout = new QHBoxLayout; @@ -61,7 +62,8 @@ Menu::Menu(QDialog* dialog) m_ExportPath = new QLineEdit; m_FileDialog = new QFileDialog; - + QString tmpPath("C:/Users/Nickelodion/Desktop/Baljj"); + m_ExportPath->setText(tmpPath); QLabel* exportLabel = new QLabel; exportLabel->setText("Export Path:"); QLabel* nameLabel = new QLabel; @@ -79,7 +81,6 @@ Menu::Menu(QDialog* dialog) topLayout->addWidget(m_ExportPath); topLayout->addWidget(m_BrowseButton); - botLayout->addWidget(m_ExportSelectedButton); botLayout->addWidget(m_ExportAllButton); botLayout->addWidget(m_CancelButton); @@ -111,35 +112,6 @@ Menu::Menu(QDialog* dialog) } - -void Menu::ExportSelected(bool checked) -{ - // Retrieving the objects we currently have selected - MSelectionList selected; - MGlobal::getActiveSelectionList(selected); - - // Loop through or list of selection(s) - for (unsigned int i = 0; i < selected.length(); i++) { - MObject object; - selected.getDependNode(i, object); - MFnDependencyNode thisNode(object); - - cout << thisNode.name().asChar() << endl; - GetMeshData(object); - } - if (m_ExportPath->text().isEmpty()) { - cout << "Please select a folder." << endl; - } - else { - cout << m_ExportPath->text().toLocal8Bit().constData() << endl; - } - - if (m_ExportAnimationsButton->isChecked()) { - GetSkeletonData(); - } - -} - void Menu::ExportPathClicked(bool) { // Opens up a file dialog. Save/Changes the name in the exportPath @@ -188,50 +160,45 @@ void Menu::RemoveClipClicked(bool) layouts.pop_back(); m_StartFrameLines.pop_back(); m_EndFrameLines.pop_back(); + m_AnimationClipName.pop_back(); } } void Menu::ExportAll(bool) { - MDagPath path; - m_File.ASCIIFilePath("C:/Users/Nickelodion/Desktop/coolASCII.txt"); - m_File.binaryFilePath("C:/Users/Nickelodion/Desktop/coolSoptunz.bin"); - m_File.OpenFiles(); + if (m_ExportPath->text().isEmpty()) { + MGlobal::displayError(MString() + "Please select a folder."); + return; + } - // Loop through all nodes in the scene - MItDependencyNodes it(MFn::kMesh); - for (; !it.isDone(); it.next()) { - MObject node = it.thisNode(); - if (node.hasFn(MFn::kMesh)) { - MFnDependencyNode thisNode(node); - MPlugArray connections; + //Export meshes + if (!m_Export.Meshes(m_ExportPath->text().toLocal8Bit().constData(), m_ExportSelectedButton->isChecked())) { + MGlobal::displayError(MString() + "Could not export mesh"); + return; + } - thisNode.findPlug("inMesh").connectedTo(connections, true, true); - bool next = false; - for (unsigned int i = 0; i < connections.length(); i++) { - if(connections[i].node().apiType() == MFn::kSkinClusterFilter){ - next = true; - break; - } - } - if (next) - continue; + std::vector animations; + MGlobal::displayInfo(MString() + "yeeehaa"); + for (unsigned int i = 0; i < m_AnimationClipName.size(); i++) { + Export::AnimationInfo thisClip; + MGlobal::displayInfo(MString() + "qwqw"); + thisClip.Name = std::string(m_AnimationClipName[i]->text().toLocal8Bit().constData()); + MGlobal::displayInfo(MString() + "shizzzz"); + thisClip.Start = m_StartFrameLines[i]->text().toInt(); + MGlobal::displayInfo(MString() + "dsdsfg"); + thisClip.End = m_EndFrameLines[i]->text().toInt(); + MGlobal::displayInfo(MString() + "aaaaaaaaaaaaaaaaaaaa"); - cout << thisNode.name().asChar() << endl; - MGlobal::displayInfo("EXPORT ALL FUNCTION: " + thisNode.name() + " " + thisNode.findPlug("inMesh").asMObject().apiTypeStr()); - GetMeshData(node); - } - } - if (m_ExportPath->text().isEmpty()) { - cout << "Please select a folder." << endl; - } - else { - cout << m_ExportPath->text().toLocal8Bit().constData() << endl; - } - - if (m_ExportAnimationsButton->isChecked()) - GetSkeletonData(); - m_File.CloseFiles(); + animations.push_back(thisClip); + } + MGlobal::displayInfo(MString() + "asdf"); + if (m_ExportAnimationsButton->isChecked()) { + //Export Animations + if (!m_Export.Animations(m_ExportPath->text().toLocal8Bit().constData(), animations)) { + MGlobal::displayError(MString() + "Could not export animations"); + return; + } + } } void Menu::CancelClicked(bool) @@ -239,105 +206,6 @@ void Menu::CancelClicked(bool) m_DialogPointer->close(); } -void Menu::Button1Clicked(bool) -{ - if (m_ExportAnimationsButton->isChecked()) { - MGlobal::displayInfo("1 checked!"); - } - else { - MGlobal::displayInfo("1 unchecked!"); - } -} - -void Menu::Button2Clicked(bool) -{ - if (m_CopyTexturesButton->isChecked()) { - cout << "2 checked!" << endl; - } - else { - cout << "2 unchecked!" << endl; - } -} - -void Menu::Button3Clicked(bool) -{ - if (m_Button3->isChecked()) { - cout << "3 checked!" << endl; - } - else { - cout << "3 unchecked!" << endl; - } -} -void Menu::GetMeshData(MObject object) -{ - std::vector vertexList; - std::vector indexList; - - Mesh mesh; - mesh.GetMeshData(object, vertexList, indexList); - - for (auto aVertex : vertexList) { - m_File.writeToFiles(&aVertex); - } - m_File.writeToFiles(indexList.data(), indexList.size()); -} -void Menu::GetMaterialData() -{ - this->m_MaterialHandler = new Material(); - - // Traverse scene and return vector with all materials - std::vector* AllMaterials = m_MaterialHandler->DoIt(); - - // Access the colorR component of one material (example) - cout << AllMaterials->at(0).Color[0] << endl; - MGlobal::displayInfo(MString() + AllMaterials->at(0).Color[0]); -} - -void Menu::GetSkeletonData() -{ - if (MAnimControl::currentTime().unit() != MTime::kNTSCField) { - - MGlobal::displayError(MString() + "Please change to 60 FPS under Preferences/Settings!"); - return; - } - - std::vector allBindPoses; - std::vector allAnimations; - - allBindPoses = m_SkeletonHandler->GetBindPoses(); - - for (unsigned int j = 0; j < m_StartFrameLines.size(); j++) { - if (m_StartFrameLines[j]->text().isEmpty() == true || m_StartFrameLines[j]->text().isEmpty() == true) { - MGlobal::displayError(MString() + "Empty Animation Clip(s)"); - return; - } - - int startFrame = m_StartFrameLines[j]->text().toInt(); - int endFrame = m_EndFrameLines[j]->text().toInt(); - std::string animationName = m_AnimationClipName[j]->text().toAscii().constData(); - - allAnimations.push_back(m_SkeletonHandler->GetAnimData(animationName, startFrame, endFrame)); - } - - //print out all bind poses - for (auto aBindPose : allBindPoses){ - m_File.writeToFiles(&aBindPose); - MGlobal::displayInfo(MString() + "BindPose Skeleton name: " + aBindPose.Name.c_str()); - - for (int i = 0; i < aBindPose.Joints.size(); i++){ - //MGlobal::displayInfo(MString() + aBindPose.JointNames[i].c_str()); - //MGlobal::displayInfo(MString() + aBindPose.ParentIDs[i]); - //MGlobal::displayInfo(MString() + aBindPose.Joints[i].Translation[0] + " " + aBindPose.Joints[i].Translation[1] + " " + aBindPose.Joints[i].Translation[2]); - //MGlobal::displayInfo(MString() + aBindPose.Joints[i].Rotation[0] + " " + aBindPose.Joints[i].Rotation[1] + " " + aBindPose.Joints[i].Rotation[2]); - //MGlobal::displayInfo(MString() + aBindPose.Joints[i].Scale[0] + " " + aBindPose.Joints[i].Scale[1] + " " + aBindPose.Joints[i].Scale[2]); - } - } - //print out all animations - for (auto aAnimation : allAnimations) { - m_File.writeToFiles(&aAnimation); - } -} - Menu::~Menu() { //delete exportSelectedButton; @@ -346,5 +214,6 @@ Menu::~Menu() //delete fileDialog; m_FileDialog->~QFileDialog(); + //delete m_Export; //delete MaterialHandler; } \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Menu.h b/tools/MayaExporter/MayaExporter/Menu.h index 9f3492ab..a8b517bc 100644 --- a/tools/MayaExporter/MayaExporter/Menu.h +++ b/tools/MayaExporter/MayaExporter/Menu.h @@ -32,12 +32,8 @@ #include #include - #include "MayaIncludes.h" -#include "Material.h" -#include "Mesh.h" -#include "Skeleton.h" -#include "WriteToFile.h" +#include "Export.h" class Menu : public QWidget { @@ -46,23 +42,13 @@ public: Menu(QDialog* dialog); ~Menu(); - void GetMeshData(MObject object); - void GetMaterialData(); - void GetSkeletonData(); - private slots: - void ExportSelected(bool checked); void ExportPathClicked(bool); void AddClipClicked(bool); void RemoveClipClicked(bool); void ExportAll(bool); void CancelClicked(bool); - void Button1Clicked(bool); - void Button2Clicked(bool); - void Button3Clicked(bool); - - private: Menu(); std::vector m_AnimationClipName; @@ -71,13 +57,13 @@ private: std::vector layouts; QVBoxLayout* m_ClipLayout; - QPushButton* m_ExportSelectedButton = nullptr; QPushButton* m_BrowseButton = nullptr; QPushButton* m_ExportAllButton = nullptr; QPushButton* m_CancelButton = nullptr; QPushButton* m_AddClipsButton = nullptr; QPushButton* m_RemoveClipsButton = nullptr; + QCheckBox* m_ExportSelectedButton = nullptr; QCheckBox* m_ExportAnimationsButton = nullptr; QCheckBox* m_CopyTexturesButton = nullptr; QCheckBox* m_Button3 = nullptr; @@ -86,10 +72,7 @@ private: QFileDialog* m_FileDialog = nullptr; QDialog* m_DialogPointer = nullptr; - Material* m_MaterialHandler = nullptr; - Skeleton* m_SkeletonHandler = nullptr; - - WriteToFile m_File; + Export m_Export; }; #endif \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index 0ac66b33..d9b47875 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -3,11 +3,12 @@ using namespace std; -Mesh::Mesh() +MeshClass::MeshClass() { } -std::map Mesh::GetWeightData() + +std::map MeshClass::GetWeightData() { map weightMap; @@ -72,10 +73,14 @@ std::map Mesh::GetWeightData() return weightMap; } -void Mesh::GetMeshData(MObject object, std::vector& vertexList, std::vector& indexList) +Mesh MeshClass::GetMeshData(MObject object) { + Mesh newMesh; + std::vector& vertexList = newMesh.Vertices; + std::vector& indexList = newMesh.Indices; // In here, we retrieve triangulated polygons from the mesh MFnMesh mesh(object); + map> vertexToIndex;; MIntArray intdexOffsetVertexCount, vertices, triangleList; @@ -106,7 +111,7 @@ void Mesh::GetMeshData(MObject object, std::vector& vertexList, st meshPolyIter.getVertices(vertices); meshPolyIter.getTriangles(dummy, triangleList); - MGlobal::displayInfo(MString() + "vertices.length(): " + vertices.length()); + //MGlobal::displayInfo("Befor Second Loop"); for (unsigned int i = 0; i < vertices.length(); i++) { vertexIndex = meshPolyIter.vertexIndex(i); @@ -160,25 +165,26 @@ void Mesh::GetMeshData(MObject object, std::vector& vertexList, st //cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl; //cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl; } - //MGlobal::displayInfo("Befor Third Loop"); - MGlobal::displayInfo(MString() + "localVertexToGlobalIndex.size(): " + localVertexToGlobalIndex.size()); - MGlobal::displayInfo(MString() + "vertexList.size(): " + vertexList.size()); + for (unsigned int i = 0; i < triangleList.length(); i++) { unsigned int k = 0; - MGlobal::displayInfo(MString() + "triangleList[i]: " + triangleList[i]); if (localVertexToGlobalIndex.size() > 0) { while (localVertexToGlobalIndex[k] != triangleList[i] && k < localVertexToGlobalIndex.size()) { - MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k]: " + localVertexToGlobalIndex[k]); k++; } indexList.push_back(indexOffset + k); } } } + + newMesh.NumIndices = newMesh.Indices.size(); + newMesh.NumVertices = newMesh.Vertices.size(); + + return newMesh; } -Mesh::~Mesh() +MeshClass::~MeshClass() { } \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Mesh.h b/tools/MayaExporter/MayaExporter/Mesh.h index 6fab0536..c9445e4e 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.h +++ b/tools/MayaExporter/MayaExporter/Mesh.h @@ -10,7 +10,6 @@ class VertexLayout : public OutputData { public: - float Pos[3]; float Normal[3]; float BiNormal[3]; @@ -32,7 +31,6 @@ public: virtual void WriteASCII(std::ostream& out) const { - out << "New Vertex: " << endl; out << Pos[0] << " " << Pos[1] << " " << Pos[2] << endl; out << Normal[0] << " " << Normal[1] << " " << Normal[2] << endl; out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl; @@ -56,15 +54,50 @@ public: } }; +class Mesh : public OutputData { +public: + int NumVertices; + int NumIndices; + std::vector Vertices; + std::vector Indices; + + virtual void WriteBinary(std::ostream& out) + { + out.write((char*)&NumVertices, sizeof(int)); + out.write((char*)&NumIndices, sizeof(int)); + for (auto aVertex : Vertices) { + aVertex.WriteBinary(out); + } + for (auto aIndex : Indices) { + out.write((char*)&aIndex, sizeof(int)); + } + } + + virtual void WriteASCII(std::ostream& out) const + { + out << "New Mesh _ not in binary" << endl; + out << "Number of vertices: " << NumVertices << endl; + out << "number of indices: " << NumIndices << endl; + int vertexNumber = 0; + for (auto aVertex : Vertices) { + out << "New vertex number: " << vertexNumber << "_ not in binary" << endl; + aVertex.WriteASCII(out); + vertexNumber++; + } + for (int i = 0; i < NumIndices; i += 3) { + out << Indices[i] << " " << Indices[i+1] << " " << Indices[i + 2] << endl; + } + } +}; -class Mesh +class MeshClass { public: - Mesh(); - void GetMeshData(MObject Object, std::vector& vertexList, std::vector& indexList); - ~Mesh(); + MeshClass(); + Mesh GetMeshData(MObject Object); + ~MeshClass(); private: struct WeightInfo { float BoneIndices[4] = { 0 }; diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp index 394f548b..0497aa31 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.cpp +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -64,12 +64,13 @@ std::string attr[9] = { "scaleX", "scaleY", "scaleZ", "translateX", "translateY" Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame) { + std::vector animatedJoints; + std::vector m_Hierarchy; + Animation returnData; double oneDivSixty = 1 / 60.0; returnData.Name = animationName; returnData.Duration = (endFrame - startFrame) * oneDivSixty; - std::vector animatedJoints; - std::vector m_Hierarchy; MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); while (!jointIt.isDone()) @@ -121,7 +122,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e if (BindPoseMatrix != MayaJoint.transformationMatrix()) { - MGlobal::displayError(MString() + animationName.c_str() + " is using a joint 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"); + 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"); } } } @@ -173,6 +174,10 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e returnData.Keyframes.push_back(thisKeyFrame); currentFrame++; } + + returnData.NumKeyFrames = returnData.Keyframes.size(); + returnData.NumberOfJoints = animatedJoints.size(); + return returnData; } diff --git a/tools/MayaExporter/MayaExporter/Skeleton.h b/tools/MayaExporter/MayaExporter/Skeleton.h index 0b0c2a60..dda0cfea 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.h +++ b/tools/MayaExporter/MayaExporter/Skeleton.h @@ -26,12 +26,16 @@ public: std::string Name; double Duration; + int NumKeyFrames; + int NumberOfJoints; std::vector Keyframes; virtual void WriteBinary(std::ostream& out) { out.write(Name.c_str(), Name.size() + 1); out.write((char*)&Duration, sizeof(double)); + out.write((char*)&NumKeyFrames, sizeof(int)); + out.write((char*)&NumberOfJoints, sizeof(int)); for (auto aKeyframe : Keyframes) { out.write((char*)&aKeyframe.Index, sizeof(int)); out.write((char*)&aKeyframe.Time, sizeof(double)); @@ -48,6 +52,8 @@ public: { out << "Animation Name: " << Name << endl; out << "Duration: " << Duration << endl; + out << "Number of KeyFrames: " << NumKeyFrames << endl; + out << "Number of Joints: " << NumberOfJoints << endl; for (auto aKeyframe : Keyframes) { out << "Frame: " << aKeyframe.Index << endl; out << "Time: " << aKeyframe.Time << endl; diff --git a/tools/MayaExporter/MayaExporter/WriteToFile.h b/tools/MayaExporter/MayaExporter/WriteToFile.h index 3d6cc078..91ca7103 100644 --- a/tools/MayaExporter/MayaExporter/WriteToFile.h +++ b/tools/MayaExporter/MayaExporter/WriteToFile.h @@ -17,7 +17,7 @@ public: void writeToFiles(OutputData* toWrite, unsigned int numOfElementToWrite = 1, unsigned int startIndex = 0) { - MGlobal::displayInfo("WriteToFile::writeToFiles()"); + MGlobal::displayInfo("WriteToFile::writeToFiles(OutputData*)"); if (ASCIIFile.is_open()) { for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++) @@ -32,16 +32,18 @@ public: } - void writeToFiles(unsigned int* toWrite, unsigned int numOfElementToWrite = 1, unsigned int startIndex = 0) + template + void writeToFiles(T* toWrite, unsigned int numOfElementToWrite = 1, unsigned int startIndex = 0) { - MGlobal::displayInfo("WriteToFile::writeToFiles()"); + MGlobal::displayInfo("WriteToFile::writeToFiles(T*) - Template T"); if (ASCIIFile.is_open()) { for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++) ASCIIFile << toWrite[i] << endl; } if (binFile.is_open()) { - binFile.write((char*)toWrite, numOfElementToWrite * sizeof(int)); + for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++) + binFile.write((char*)toWrite, sizeof(T)); } }