diff --git a/.gitignore b/.gitignore index d43dd612..0df2db42 100755 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ lib/ *.sdf tools/MayaExporter/MayaExporter/x64/Debug/ tools/MayaExporter/x64/Debug/ + +tools/MayaExporter/MayaExporter/Debug/ +tools/MayaExporter/MayaExporter/GeneratedFiles/ diff --git a/tools/MayaExporter/MayaExporter/Material.cpp b/tools/MayaExporter/MayaExporter/Material.cpp index 53d029dc..2bc084dc 100644 --- a/tools/MayaExporter/MayaExporter/Material.cpp +++ b/tools/MayaExporter/MayaExporter/Material.cpp @@ -111,6 +111,8 @@ bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode& material_node.ColorMapFile = FullPath.substr(FullPath.find_last_of("/")); + // Test + MGlobal::displayInfo(MString() + "Texture file: " + FullPath.c_str()); return true; } } diff --git a/tools/MayaExporter/MayaExporter/Material.h b/tools/MayaExporter/MayaExporter/Material.h index 1685453d..c5d57529 100644 --- a/tools/MayaExporter/MayaExporter/Material.h +++ b/tools/MayaExporter/MayaExporter/Material.h @@ -5,6 +5,7 @@ #include #include #include + #include "MayaIncludes.h" struct MaterialNode diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj index c8ce591c..ffc93c0f 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj @@ -173,6 +173,7 @@ true + @@ -195,6 +196,7 @@ + Moc%27ing Menu.h... .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters index 4719620b..70af7805 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters @@ -53,6 +53,9 @@ Source Files + + Source Files + @@ -75,5 +78,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 5d8af1d4..3fc760e6 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -10,39 +10,39 @@ Menu::Menu() Menu::Menu(QDialog* dialog) { // Save the dialog pointer. Needed when the application gets destroyed - dialogPointer = dialog; + m_DialogPointer = dialog; // Create QpushButtons & give them names - exportSelectedButton = new QPushButton("&Export Selected", this); - browseButton = new QPushButton("&...", this); - exportAllButton = new QPushButton("&Export All", this); - cancelButton = new QPushButton("&Cancel", this); + m_ExportSelectedButton = new QPushButton("&Export Selected", this); + m_BrowseButton = new QPushButton("&...", this); + m_ExportAllButton = new QPushButton("&Export All", this); + m_CancelButton = new QPushButton("&Cancel", this); // Option box and checkboxes QGroupBox *optionsBox = new QGroupBox(tr("Options")); - exportAnimationsButton = new QCheckBox(tr("&Export Animations")); - copyTexturesButton = new QCheckBox(tr("&Copy Textures")); - button3 = new QCheckBox(tr("option3")); + m_ExportAnimationsButton = new QCheckBox(tr("&Export Animations")); + m_CopyTexturesButton = new QCheckBox(tr("&Copy Textures")); + m_Button3 = new QCheckBox(tr("Test Materials")); - exportAnimationsButton->setChecked(true); - copyTexturesButton->setChecked(true); + m_ExportAnimationsButton->setChecked(true); + m_CopyTexturesButton->setChecked(true); QVBoxLayout *vbox = new QVBoxLayout; - vbox->addWidget(exportAnimationsButton); - vbox->addWidget(copyTexturesButton); - vbox->addWidget(button3); + vbox->addWidget(m_ExportAnimationsButton); + vbox->addWidget(m_CopyTexturesButton); + vbox->addWidget(m_Button3); vbox->addStretch(1); optionsBox->setLayout(vbox); // Connect the buttons with signals & functions - connect(exportSelectedButton, SIGNAL(clicked(bool)), this, SLOT(ExportSelected(bool))); - connect(browseButton, SIGNAL(clicked(bool)), this, SLOT(ExportPathClicked(bool))); - connect(exportAllButton, SIGNAL(clicked(bool)), this, SLOT(ExportAll(bool))); - connect(cancelButton, SIGNAL(clicked(bool)), this, SLOT(CancelClicked(bool))); + 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(exportAnimationsButton, SIGNAL(clicked(bool)), this, SLOT(Button1Clicked(bool))); - connect(copyTexturesButton, SIGNAL(clicked(bool)), this, SLOT(Button2Clicked(bool))); - connect(button3, SIGNAL(clicked(bool)), this, SLOT(Button3Clicked(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))); // Creating several layouts, adding widgets & adding them to one layout in the end QHBoxLayout* topLayout = new QHBoxLayout; @@ -50,8 +50,8 @@ Menu::Menu(QDialog* dialog) QHBoxLayout* botLayout = new QHBoxLayout; QVBoxLayout* baseLayout = new QVBoxLayout; - exportPath = new QLineEdit; - fileDialog = new QFileDialog; + m_ExportPath = new QLineEdit; + m_FileDialog = new QFileDialog; QLabel* exportLabel = new QLabel; exportLabel->setText("Export Path:"); @@ -59,12 +59,12 @@ Menu::Menu(QDialog* dialog) midLayout->addWidget(optionsBox); topLayout->addWidget(exportLabel); - topLayout->addWidget(exportPath); - topLayout->addWidget(browseButton); + topLayout->addWidget(m_ExportPath); + topLayout->addWidget(m_BrowseButton); - botLayout->addWidget(exportSelectedButton); - botLayout->addWidget(exportAllButton); - botLayout->addWidget(cancelButton); + botLayout->addWidget(m_ExportSelectedButton); + botLayout->addWidget(m_ExportAllButton); + botLayout->addWidget(m_CancelButton); baseLayout->addLayout(topLayout); baseLayout->addLayout(midLayout); @@ -86,28 +86,30 @@ void Menu::ExportSelected(bool checked) MGlobal::getActiveSelectionList(selected); // Loop through or list of selection(s) - for (unsigned int i = 0; i < selected.length();i++) - { + 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); + Mesh mesh; + mesh.GetMeshData(object); } - if (exportPath->text().isEmpty()) + if (m_ExportPath->text().isEmpty()) { cout << "Please select a folder." << endl; - else - cout << exportPath->text().toLocal8Bit().constData() << endl; + } + else { + cout << m_ExportPath->text().toLocal8Bit().constData() << endl; + } } void Menu::ExportPathClicked(bool) { // Opens up a file dialog. Save/Changes the name in the exportPath - fileDialog->setFileMode(QFileDialog::Directory); - fileDialog->setOption(QFileDialog::ShowDirsOnly); - QString fileName = fileDialog->getExistingDirectory(this, "Select", "/home", QFileDialog::ShowDirsOnly); - exportPath->setText(fileName); + m_FileDialog->setFileMode(QFileDialog::Directory); + m_FileDialog->setOption(QFileDialog::ShowDirsOnly); + QString fileName = m_FileDialog->getExistingDirectory(this, "Select", "/home", QFileDialog::ShowDirsOnly); + m_ExportPath->setText(fileName); } void Menu::ExportAll(bool) @@ -116,118 +118,65 @@ void Menu::ExportAll(bool) // Loop through all nodes in the scene MItDependencyNodes it(MFn::kInvalid); - for (;!it.isDone();it.next()) - { + for (;!it.isDone();it.next()) { MObject node = it.thisNode(); - if (node.hasFn(MFn::kMesh)) - { + if (node.hasFn(MFn::kMesh)) { MFnDependencyNode thisNode(node); cout << thisNode.name().asChar() << endl; - GetMeshData(node); + Mesh mesh; + mesh.GetMeshData(node); } } - if (exportPath->text().isEmpty()) + if (m_ExportPath->text().isEmpty()) { cout << "Please select a folder." << endl; - else - cout << exportPath->text().toLocal8Bit().constData() << endl; + } + else { + cout << m_ExportPath->text().toLocal8Bit().constData() << endl; + } } void Menu::CancelClicked(bool) { - dialogPointer->close(); + m_DialogPointer->close(); } void Menu::Button1Clicked(bool) { - if(exportAnimationsButton->isChecked()) + if (m_ExportAnimationsButton->isChecked()) { MGlobal::displayInfo("1 checked!"); - else + } + else { MGlobal::displayInfo("1 unchecked!"); + } } void Menu::Button2Clicked(bool) { - if (copyTexturesButton->isChecked()) + if (m_CopyTexturesButton->isChecked()) { cout << "2 checked!" << endl; - else + } + else { cout << "2 unchecked!" << endl; + } } void Menu::Button3Clicked(bool) { - if (button3->isChecked()) + if (m_Button3->isChecked()) { cout << "3 checked!" << endl; - else - cout << "3 unchecked!" << endl; -} - -void Menu::GetMeshData(MObject object) -{ - // In here, we retrieve triangulated polygons from the mesh - MFnMesh mesh(object); - - map> vertexToIndex; - - vector verticesData; - vectorindexArray; - - MIntArray intdexOffsetVertexCount, vertices, triangleList; - MPointArray dummy; - - UINT vertexIndex; - MVector normal; - MPoint pos; - float2 UV; - VertexLayout thisVertex; - - for (MItMeshPolygon meshPolyIter(object); !meshPolyIter.isDone(); meshPolyIter.next()) - { - vector localVertexToGlobalIndex; - meshPolyIter.getVertices(vertices); - - meshPolyIter.getTriangles(dummy, triangleList); - UINT indexOffset = verticesData.size(); - - for (UINT i = 0; i < vertices.length(); i++) - { - vertexIndex = meshPolyIter.vertexIndex(i); - pos = meshPolyIter.point(i); - pos.get(thisVertex.pos); - - meshPolyIter.getNormal(i, normal); - thisVertex.normal[0] = normal[0]; - thisVertex.normal[1] = normal[1]; - thisVertex.normal[2] = normal[2]; - - meshPolyIter.getUV(i, UV); - thisVertex.uv[0] = UV[0]; - thisVertex.uv[1] = UV[1]; - - verticesData.push_back(thisVertex); - localVertexToGlobalIndex.push_back(vertexIndex); - - cout << "Pos: " << thisVertex.pos[0] << "/" << thisVertex.pos[1] << "/" << thisVertex.pos[2] << endl; - cout << "Normals: " << thisVertex.normal[0] << "/" << thisVertex.normal[1] << "/" << thisVertex.normal[2] << endl; - cout << "UV: " << thisVertex.uv[0] << "/" << thisVertex.uv[1] << endl; - } - for (UINT i = 0; i < triangleList.length(); i++) - { - UINT k = 0; - while (localVertexToGlobalIndex[k] != triangleList[i]) - k++; - indexArray.push_back(indexOffset + k); - } } - + else { + cout << "3 unchecked!" << endl; + } } void Menu::GetMaterialData() { - this->MaterialHandler = new Material(); + this->m_MaterialHandler = new Material(); // Traverse scene and return vector with all materials - std::vector* AllMaterials = MaterialHandler->DoIt(); + std::vector* AllMaterials = m_MaterialHandler->DoIt(); // Access the colorR component of one material (example) cout << AllMaterials->at(0).Color[0] << endl; @@ -240,6 +189,6 @@ Menu::~Menu() //delete browseButton; //delete exportPath; //delete fileDialog; - fileDialog->~QFileDialog(); - delete MaterialHandler; + m_FileDialog->~QFileDialog(); + //delete MaterialHandler; } \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Menu.h b/tools/MayaExporter/MayaExporter/Menu.h index b2731c0a..e58c86fb 100644 --- a/tools/MayaExporter/MayaExporter/Menu.h +++ b/tools/MayaExporter/MayaExporter/Menu.h @@ -1,11 +1,9 @@ -#ifndef BUTTONS_H -#define BUTTONS_H +#ifndef Menu_Menu_h__ +#define Menu_Menu_h__ #include #include -#include "MayaIncludes.h" -#include "Material.h" // Qt #pragma comment(lib, "QtCore4") #pragma comment(lib, "QtGui4") @@ -32,12 +30,9 @@ #include #include -struct VertexLayout -{ - float pos[3]; - float normal[3]; - float uv[2]; -}; +#include "MayaIncludes.h" +#include "Material.h" +#include "Mesh.h" class Menu : public QWidget { @@ -46,7 +41,6 @@ public: Menu(QDialog* dialog); ~Menu(); - void GetMeshData(MObject object); void GetMaterialData(); private slots: @@ -62,20 +56,20 @@ private slots: private: Menu(); - QPushButton* exportSelectedButton; - QPushButton* browseButton; - QPushButton* exportAllButton; - QPushButton* cancelButton; + QPushButton* m_ExportSelectedButton = nullptr; + QPushButton* m_BrowseButton = nullptr; + QPushButton* m_ExportAllButton = nullptr; + QPushButton* m_CancelButton = nullptr; - QCheckBox* exportAnimationsButton; - QCheckBox* copyTexturesButton; - QCheckBox* button3; + QCheckBox* m_ExportAnimationsButton = nullptr; + QCheckBox* m_CopyTexturesButton = nullptr; + QCheckBox* m_Button3 = nullptr; - QLineEdit* exportPath; - QFileDialog* fileDialog; - QDialog* dialogPointer; + QLineEdit* m_ExportPath = nullptr; + QFileDialog* m_FileDialog = nullptr; + QDialog* m_DialogPointer = nullptr; - Material* MaterialHandler; + Material* m_MaterialHandler = nullptr; }; #endif \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp new file mode 100644 index 00000000..fa52fc8e --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -0,0 +1,70 @@ +#pragma once +#include "Mesh.h" + +using namespace std; + +Mesh::Mesh() +{ + +} + +void Mesh::GetMeshData(MObject object) +{ + // In here, we retrieve triangulated polygons from the mesh + MFnMesh mesh(object); + + map> vertexToIndex; + + vector verticesData; + vectorindexArray; + + MIntArray intdexOffsetVertexCount, vertices, triangleList; + MPointArray dummy; + + UINT vertexIndex; + MVector normal; + MPoint pos; + float2 UV; + VertexLayout thisVertex; + + for (MItMeshPolygon meshPolyIter(object); !meshPolyIter.isDone(); meshPolyIter.next()) { + vector localVertexToGlobalIndex; + meshPolyIter.getVertices(vertices); + + meshPolyIter.getTriangles(dummy, triangleList); + UINT indexOffset = verticesData.size(); + + for (UINT i = 0; i < vertices.length(); i++) { + vertexIndex = meshPolyIter.vertexIndex(i); + pos = meshPolyIter.point(i); + pos.get(thisVertex.Pos); + + meshPolyIter.getNormal(i, normal); + thisVertex.Normal[0] = normal[0]; + thisVertex.Normal[1] = normal[1]; + thisVertex.Normal[2] = normal[2]; + + meshPolyIter.getUV(i, UV); + thisVertex.Uv[0] = UV[0]; + thisVertex.Uv[1] = UV[1]; + + verticesData.push_back(thisVertex); + localVertexToGlobalIndex.push_back(vertexIndex); + + cout << "Pos: " << thisVertex.Pos[0] << "/" << thisVertex.Pos[1] << "/" << thisVertex.Pos[2] << endl; + cout << "Normals: " << thisVertex.Normal[0] << "/" << thisVertex.Normal[1] << "/" << thisVertex.Normal[2] << endl; + cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl; + } + for (UINT i = 0; i < triangleList.length(); i++) { + UINT k = 0; + while (localVertexToGlobalIndex[k] != triangleList[i]) + k++; + indexArray.push_back(indexOffset + k); + } + } +} + +Mesh::~Mesh() +{ + +} \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Mesh.h b/tools/MayaExporter/MayaExporter/Mesh.h new file mode 100644 index 00000000..0ba9624d --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Mesh.h @@ -0,0 +1,24 @@ +#ifndef Mesh_Mesh_h__ +#define Mesh_Mesh_h__ + +#include +#include + +#include "MayaIncludes.h" + +struct VertexLayout +{ + float Pos[3]; + float Normal[3]; + float Uv[2]; +}; + +class Mesh +{ +public: + Mesh(); + void GetMeshData(MObject Object); + ~Mesh(); +}; + +#endif \ No newline at end of file