From c8cb0ee93978dd8b4646cb4cb37e5fb397fcabd3 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Wed, 9 Dec 2015 11:58:49 +0100 Subject: [PATCH 01/28] Grab all materials --- tools/MayaExporter/MayaExporter/Material.cpp | 239 ++++++++++++++++++ tools/MayaExporter/MayaExporter/Material.h | 46 ++++ .../MayaExporter/MayaExporter.vcxproj | 2 + .../MayaExporter/MayaExporter.vcxproj.filters | 6 + .../MayaExporter/MayaExporter/MayaIncludes.h | 1 + tools/MayaExporter/MayaExporter/Menu.cpp | 14 +- tools/MayaExporter/MayaExporter/Menu.h | 4 +- 7 files changed, 307 insertions(+), 5 deletions(-) create mode 100644 tools/MayaExporter/MayaExporter/Material.cpp create mode 100644 tools/MayaExporter/MayaExporter/Material.h diff --git a/tools/MayaExporter/MayaExporter/Material.cpp b/tools/MayaExporter/MayaExporter/Material.cpp new file mode 100644 index 00000000..53d029dc --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Material.cpp @@ -0,0 +1,239 @@ +#include "Material.h" + +void Material::grabLambertProperties(MaterialNode& material_node, MFnDependencyNode& node) +{ + material_node.Name = node.name().asChar(); + + if (findColorTexture(material_node, node)) { + material_node.Color.fill(1.0f); + } + else { + m_Plug = node.findPlug("colorR"); + m_Plug.getValue(material_node.Color[0]); + m_Plug = node.findPlug("colorG"); + m_Plug.getValue(material_node.Color[1]); + m_Plug = node.findPlug("colorB"); + m_Plug.getValue(material_node.Color[2]); + + float TempTransp[3]; + m_Plug = node.findPlug("transparencyR"); + m_Plug.getValue(TempTransp[0]); + m_Plug = node.findPlug("transparencyG"); + m_Plug.getValue(TempTransp[1]); + m_Plug = node.findPlug("transparencyB"); + m_Plug.getValue(TempTransp[2]); + + MColor TranspNode(TempTransp[0], TempTransp[1], TempTransp[2]); + float DummyH, DummyS; + TranspNode.get(MColor::kHSV, DummyH, DummyS, material_node.Color[3]); + } + + if (findIncandescenceTexture(material_node, node)) { + material_node.Incandescence.fill(1.0f); + } + else { + m_Plug = node.findPlug("incandescenceR"); + m_Plug.getValue(material_node.Incandescence[0]); + m_Plug = node.findPlug("incandescenceG"); + m_Plug.getValue(material_node.Incandescence[1]); + m_Plug = node.findPlug("incandescenceB"); + m_Plug.getValue(material_node.Incandescence[2]); + } + + findNormalTexture(material_node, node); +} + +void Material::grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node) +{ + if (findSpecularTexture(material_node, node)) { + material_node.Specular.fill(1.0f); + } + else { + m_Plug = node.findPlug("specularColorR"); + m_Plug.getValue(material_node.Specular[0]); + m_Plug = node.findPlug("specularColorG"); + m_Plug.getValue(material_node.Specular[1]); + m_Plug = node.findPlug("specularColorB"); + m_Plug.getValue(material_node.Specular[2]); + } + + m_Plug = node.findPlug("reflectivity"); + m_Plug.getValue(material_node.ReflectionFactor); + + m_Plug = node.findPlug("eccentricity"); + float TempEccent; + m_Plug.getValue(TempEccent); + + // Blinn works differently from Phong which is used in-game. + // This is some magic numbers and math to make a conversion estimate between the two. + // There is no exact conversion between the two, so there are errors. + + // Phong min/max is around Blinn 0.7/0.1 + TempEccent = std::max(std::min(TempEccent, 0.7f), 0.1f); + + material_node.SpecularExponent = std::max(std::min(((2.66f) + (427.0f) * exp((-14.8f) * TempEccent)), 100.0f), 2.0f); +} + +void Material::grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node) +{ + if (findSpecularTexture(material_node, node)) { + material_node.Specular.fill(1.0f); + } + else { + m_Plug = node.findPlug("specularColorR"); + m_Plug.getValue(material_node.Specular[0]); + m_Plug = node.findPlug("specularColorG"); + m_Plug.getValue(material_node.Specular[1]); + m_Plug = node.findPlug("specularColorB"); + m_Plug.getValue(material_node.Specular[2]); + } + + m_Plug = node.findPlug("reflectivity"); + m_Plug.getValue(material_node.ReflectionFactor); + + m_Plug = node.findPlug("cosinePower "); + m_Plug.getValue(material_node.SpecularExponent); +} + +bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode& node) +{ + MPlugArray AllConnections; + + m_Plug = node.findPlug("color", true); + m_Plug.connectedTo(AllConnections, true, false); + + for (int i = 0; i < AllConnections.length(); i++) { + if (AllConnections[i].node().hasFn(MFn::kFileTexture)) { + MFnDependencyNode TextureNode(AllConnections[i].node()); + + std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); + m_TexturePaths.push_back(FullPath); + + material_node.ColorMapFile = FullPath.substr(FullPath.find_last_of("/")); + + return true; + } + } + + return false; +} + +bool Material::findNormalTexture(MaterialNode& material_node, MFnDependencyNode& node) +{ + MPlugArray AllConnections; + MPlugArray AllBumpConnections; + + m_Plug = node.findPlug("normalCamera", true); + m_Plug.connectedTo(AllConnections, true, false); + + for (int i = 0; i < AllConnections.length(); i++) { + if (AllConnections[i].node().apiType() == MFn::kBump) { + MFnDependencyNode BumpNode(AllConnections[i].node()); + + BumpNode.findPlug("bumpValue").connectedTo(AllBumpConnections, true, false); + for (int j = 0; j < AllBumpConnections.length(); j++) { + if (AllBumpConnections[j].node().hasFn(MFn::kFileTexture)) { + MFnDependencyNode TextureNode(AllBumpConnections[j].node()); + + std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); + m_TexturePaths.push_back(FullPath); + + material_node.NormalMapFile = FullPath.substr(FullPath.find_last_of("/")); + + return true; + } + } + } + } + + return false; +} + +bool Material::findSpecularTexture(MaterialNode& material_node, MFnDependencyNode& node) +{ + MPlugArray AllConnections; + + m_Plug = node.findPlug("specularColor", true); + m_Plug.connectedTo(AllConnections, true, false); + + for (int i = 0; i < AllConnections.length(); i++) { + if (AllConnections[i].node().hasFn(MFn::kFileTexture)) { + MFnDependencyNode TextureNode(AllConnections[i].node()); + + std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); + m_TexturePaths.push_back(FullPath); + + material_node.SpecularMapFile = FullPath.substr(FullPath.find_last_of("/")); + + return true; + } + } + return false; +} + +bool Material::findIncandescenceTexture(MaterialNode& material_node, MFnDependencyNode& node) +{ + MPlugArray AllConnections; + + m_Plug = node.findPlug("incandescence", true); + m_Plug.connectedTo(AllConnections, true, false); + + for (int i = 0; i < AllConnections.length(); i++) { + if (AllConnections[i].node().hasFn(MFn::kFileTexture)) { + MFnDependencyNode TextureNode(AllConnections[i].node()); + + std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); + m_TexturePaths.push_back(FullPath); + + material_node.SpecularMapFile = FullPath.substr(FullPath.find_last_of("/")); + + return true; + } + } + return false; +} + +// Returns the absolute path for all textures. Use for copying texture files. +std::vector* Material::TexturePaths() +{ + return &m_TexturePaths; +} + +// Traverse the DAG and grab all the materials +std::vector* Material::DoIt() +{ + // All materials we care about inherit from Lambert + MItDependencyNodes matIt(MFn::kLambert); + + while (!matIt.isDone()) { + MFnDependencyNode MaterialFnDN(matIt.thisNode()); + MaterialNode MaterialStorage; + + if (matIt.thisNode().hasFn(MFn::kPhong)) { + grabLambertProperties(MaterialStorage, MaterialFnDN); + grabPhongProperties(MaterialStorage, MaterialFnDN); + + m_AllMaterials.push_back(MaterialStorage); + } + else if (matIt.thisNode().hasFn(MFn::kBlinn)) { + grabLambertProperties(MaterialStorage, MaterialFnDN); + grabBlinnProperties(MaterialStorage, MaterialFnDN); + + m_AllMaterials.push_back(MaterialStorage); + } + else if (matIt.thisNode().hasFn(MFn::kLambert)) { + grabLambertProperties(MaterialStorage, MaterialFnDN); + + m_AllMaterials.push_back(MaterialStorage); + + MaterialStorage.Specular.fill(0.0f); + MaterialStorage.ReflectionFactor = 0.0f; + MaterialStorage.SpecularExponent = 0.0f; + } + + matIt.next(); + } + + return &m_AllMaterials; +} + diff --git a/tools/MayaExporter/MayaExporter/Material.h b/tools/MayaExporter/MayaExporter/Material.h new file mode 100644 index 00000000..1685453d --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Material.h @@ -0,0 +1,46 @@ +#ifndef Material_Material_h__ +#define Material_Material_h__ + +#include +#include +#include +#include +#include "MayaIncludes.h" + +struct MaterialNode +{ + std::string Name; + std::array Color; + std::array Incandescence; + std::array Specular; + float ReflectionFactor; + float SpecularExponent; + std::string ColorMapFile; + std::string SpecularMapFile; + std::string NormalMapFile; + std::string IncandescenceMapFile; +}; + +class Material +{ +public: + Material() {}; + ~Material() {}; + std::vector* DoIt(); + std::vector* TexturePaths(); +private: + MPlug m_Plug; + + std::vector m_AllMaterials; + std::vector m_TexturePaths; + + bool findColorTexture(MaterialNode& material_node, MFnDependencyNode& node); + bool findNormalTexture(MaterialNode& material_node, MFnDependencyNode& node); + bool findSpecularTexture(MaterialNode& material_node, MFnDependencyNode& node); + bool findIncandescenceTexture(MaterialNode& material_node, MFnDependencyNode& node); + void grabLambertProperties(MaterialNode& material_node, MFnDependencyNode& node); + void grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node); + void grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node); +}; + +#endif // Material_Material_h__ \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj index 42b1b45a..c8ce591c 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj @@ -152,6 +152,7 @@ + true @@ -213,6 +214,7 @@ $(QTDIR)\bin\moc.exe;%(FullPath);$(QTDIR)\bin\moc.exe;%(FullPath) + diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters index d5bcfd00..4719620b 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters @@ -50,6 +50,9 @@ Source Files + + Source Files + @@ -69,5 +72,8 @@ Generated Files + + Header Files + \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/MayaIncludes.h b/tools/MayaExporter/MayaExporter/MayaIncludes.h index 3573d30d..6c092052 100644 --- a/tools/MayaExporter/MayaExporter/MayaIncludes.h +++ b/tools/MayaExporter/MayaExporter/MayaIncludes.h @@ -30,6 +30,7 @@ #include #include #include +#include // Wrappers diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 6af300aa..5d8af1d4 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -141,9 +141,9 @@ void Menu::CancelClicked(bool) void Menu::Button1Clicked(bool) { if(exportAnimationsButton->isChecked()) - cout << "1 checked!" << endl; + MGlobal::displayInfo("1 checked!"); else - cout << "1 unchecked!" << endl; + MGlobal::displayInfo("1 unchecked!"); } void Menu::Button2Clicked(bool) @@ -222,11 +222,16 @@ void Menu::GetMeshData(MObject object) } -void Menu::exportMaterial(MObject object) +void Menu::GetMaterialData() { - MItDependencyNodes matIt(MFn::kLambert); + this->MaterialHandler = new Material(); + // Traverse scene and return vector with all materials + std::vector* AllMaterials = 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]); } Menu::~Menu() @@ -236,4 +241,5 @@ Menu::~Menu() //delete exportPath; //delete fileDialog; 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 44eca702..b2731c0a 100644 --- a/tools/MayaExporter/MayaExporter/Menu.h +++ b/tools/MayaExporter/MayaExporter/Menu.h @@ -5,6 +5,7 @@ #include #include "MayaIncludes.h" +#include "Material.h" // Qt #pragma comment(lib, "QtCore4") #pragma comment(lib, "QtGui4") @@ -46,7 +47,7 @@ public: ~Menu(); void GetMeshData(MObject object); - void exportMaterial(MObject object); + void GetMaterialData(); private slots: void ExportSelected(bool checked); @@ -74,6 +75,7 @@ private: QFileDialog* fileDialog; QDialog* dialogPointer; + Material* MaterialHandler; }; #endif \ No newline at end of file From 74c1beed2036e5629a36f3b273c0f91144ecee25 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Wed, 9 Dec 2015 12:03:01 +0100 Subject: [PATCH 02/28] gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 1774c281..d43dd612 100755 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ bin/ lib/ # Because apparently nobody has any self control *.orig + +*.suo +*.sdf +tools/MayaExporter/MayaExporter/x64/Debug/ +tools/MayaExporter/x64/Debug/ From a22d086e60ad9861c47ff592c0fae9c482b26b00 Mon Sep 17 00:00:00 2001 From: antc13 Date: Thu, 10 Dec 2015 11:18:34 +0100 Subject: [PATCH 03/28] Tested some of the Material Code. Seems to work. The project should now be following the code standard properly (hopefully). --- .gitignore | 3 + tools/MayaExporter/MayaExporter/Material.cpp | 2 + tools/MayaExporter/MayaExporter/Material.h | 1 + .../MayaExporter/MayaExporter.vcxproj | 2 + .../MayaExporter/MayaExporter.vcxproj.filters | 6 + tools/MayaExporter/MayaExporter/Menu.cpp | 181 +++++++----------- tools/MayaExporter/MayaExporter/Menu.h | 38 ++-- tools/MayaExporter/MayaExporter/Mesh.cpp | 70 +++++++ tools/MayaExporter/MayaExporter/Mesh.h | 24 +++ 9 files changed, 189 insertions(+), 138 deletions(-) create mode 100644 tools/MayaExporter/MayaExporter/Mesh.cpp create mode 100644 tools/MayaExporter/MayaExporter/Mesh.h 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 From 60b3ce89b22889fdf0a9aa3635fee711a3dd3744 Mon Sep 17 00:00:00 2001 From: antc13 Date: Mon, 14 Dec 2015 12:59:54 +0100 Subject: [PATCH 04/28] Skeleton/Joints WIP --- assets | 2 +- .../MayaExporter/MayaExporter.vcxproj | 2 ++ .../MayaExporter/MayaExporter.vcxproj.filters | 6 +++++ tools/MayaExporter/MayaExporter/Menu.cpp | 5 ++++ tools/MayaExporter/MayaExporter/Menu.h | 1 + tools/MayaExporter/MayaExporter/Skeleton.cpp | 11 ++++++++ tools/MayaExporter/MayaExporter/Skeleton.h | 27 +++++++++++++++++++ 7 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tools/MayaExporter/MayaExporter/Skeleton.cpp create mode 100644 tools/MayaExporter/MayaExporter/Skeleton.h diff --git a/assets b/assets index 4bd902b6..56305dcc 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 4bd902b697b8eef063da800102e6e9c3b29353eb +Subproject commit 56305dcca629b8adaf57efc4e6a853b6c5f345f8 diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj index ffc93c0f..50577919 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj @@ -174,6 +174,7 @@ + @@ -197,6 +198,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 70af7805..cf4a5a35 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters @@ -56,6 +56,9 @@ Source Files + + Source Files + @@ -81,5 +84,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 3fc760e6..fc3808f6 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -183,6 +183,11 @@ void Menu::GetMaterialData() MGlobal::displayInfo(MString() + AllMaterials->at(0).Color[0]); } +void Menu::GetSkeletonData() +{ + +} + Menu::~Menu() { //delete exportSelectedButton; diff --git a/tools/MayaExporter/MayaExporter/Menu.h b/tools/MayaExporter/MayaExporter/Menu.h index e58c86fb..6f766025 100644 --- a/tools/MayaExporter/MayaExporter/Menu.h +++ b/tools/MayaExporter/MayaExporter/Menu.h @@ -42,6 +42,7 @@ public: ~Menu(); void GetMaterialData(); + void GetSkeletonData(); private slots: void ExportSelected(bool checked); diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp new file mode 100644 index 00000000..28f56563 --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -0,0 +1,11 @@ +#include "Skeleton.h" + +//std::vector* Skeleton::DoIt() +//{ +// MItDependencyNodes jointIt(MFn::kJoint); +// +// for (; !jointIt.isDone(); jointIt.next()) +// { +// //MFnDependencyNode +// } +//} \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Skeleton.h b/tools/MayaExporter/MayaExporter/Skeleton.h new file mode 100644 index 00000000..8b111490 --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Skeleton.h @@ -0,0 +1,27 @@ +#ifndef Skeleton_Skeleton_h__ +#define Skeleton_Skeleton_h__ + +#include +#include +#include "MayaIncludes.h" + +struct Joint { + int ParentIndex; + std::array Rotation; + std::array Translation; + std::array Scale; +}; + +struct SkeletonNode { + std::string Name; + std::vector joints; +}; + +class Skeleton { +public: + //std::vector* DoIt(); +private: + //std::vector m_AllSkeletons; +}; + +#endif //Skeleton_Skeleton_h__ \ No newline at end of file From 168937035669ea3cb958284ce29f02004f950594 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Tue, 15 Dec 2015 11:49:59 +0100 Subject: [PATCH 05/28] 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 From 4e535c110293b527fe112c8e52a76ed5f3660145 Mon Sep 17 00:00:00 2001 From: antc13 Date: Tue, 15 Dec 2015 15:24:46 +0100 Subject: [PATCH 06/28] =?UTF-8?q?File=20Writer=20WIP.=20Rework=20soon?= =?UTF-8?q?=E2=84=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MayaExporter/MayaExporter.vcxproj | 2 + .../MayaExporter/MayaExporter.vcxproj.filters | 6 ++ tools/MayaExporter/MayaExporter/Menu.h | 1 + tools/MayaExporter/MayaExporter/Var.cpp | 70 +++++++++++++++++++ tools/MayaExporter/MayaExporter/Var.h | 32 +++++++++ 5 files changed, 111 insertions(+) create mode 100644 tools/MayaExporter/MayaExporter/Var.cpp create mode 100644 tools/MayaExporter/MayaExporter/Var.h diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj index 50577919..b04d032f 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj @@ -175,6 +175,7 @@ + @@ -199,6 +200,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 cf4a5a35..6f836155 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters @@ -59,6 +59,9 @@ Source Files + + Source Files + @@ -87,5 +90,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Menu.h b/tools/MayaExporter/MayaExporter/Menu.h index 6f766025..bf77e59f 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 "Var.h" class Menu : public QWidget { diff --git a/tools/MayaExporter/MayaExporter/Var.cpp b/tools/MayaExporter/MayaExporter/Var.cpp new file mode 100644 index 00000000..adfcb212 --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Var.cpp @@ -0,0 +1,70 @@ +#include "Var.h" +#include "MayaIncludes.h" +#include + +Var::Var(Var::Type type, unsigned int numElements) +{ + m_Type = type; + m_NumElements = numElements; + + switch (m_Type) + { + case Var::Type::Int: + m_Data = new int[m_NumElements]; + break; + case Var::Type::Float: + m_Data = new float[m_NumElements]; + break; + case Var::Type::String: + m_Data = new std::string[m_NumElements]; + break; + default: + MGlobal::displayError("Var is an invalid type"); + assert(0); + break; + } +} + +Var& Var::operator=(const int& other) +{ + assert(m_Type == Type::Int); + *(int*)m_Data = other; + return *this; +} + +Var& Var::operator=(const float& other) +{ + assert(m_Type == Type::Float); + *(float*)m_Data = other; + return *this; +} + +Var& Var::operator=(const std::string& other) +{ + assert(m_Type == Type::String); + std::string tmp(other); + (*(std::string*)m_Data).swap(tmp); + return *this; +} + +//Var& Var::operator=(const Var& other) +//{ +// m_Data = other.m_Data; +// m_Type = other.m_Type; +// return *this; +//} + +Var::Type Var::isType() const +{ + return m_Type; +} + +unsigned int Var::NumElements() const +{ + return m_NumElements; +} + +void* Var::Data() +{ + return m_Data; +} \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Var.h b/tools/MayaExporter/MayaExporter/Var.h new file mode 100644 index 00000000..b0ec66dd --- /dev/null +++ b/tools/MayaExporter/MayaExporter/Var.h @@ -0,0 +1,32 @@ +#ifndef Var_Var_h__ +#define Var_Var_h__ + +#include + +class Var +{ +public: + enum class Type + { + Int, + Float, + String + }; + + Var(Var::Type type, unsigned int numElements = 1); + ~Var() { delete[] m_Data; }; + + Var& operator=(const int& other); + Var& operator=(const float& other); + Var& operator=(const std::string& other); + //Var& operator=(const Var& other); + Type isType() const; + unsigned int NumElements() const; + void* Data(); +private: + Type m_Type; + unsigned int m_NumElements; + void* m_Data; +}; + +#endif \ No newline at end of file From 67017fcaf47a9a72fc9c8b7379d3c8aeb0f548f9 Mon Sep 17 00:00:00 2001 From: antc13 Date: Wed, 16 Dec 2015 11:33:42 +0100 Subject: [PATCH 07/28] Stepping through the timeline. --- .../MayaExporter/MayaExporter.vcxproj | 2 - .../MayaExporter/MayaExporter.vcxproj.filters | 6 -- .../MayaExporter/MayaExporter/MayaIncludes.h | 3 + tools/MayaExporter/MayaExporter/Menu.cpp | 26 +++++-- tools/MayaExporter/MayaExporter/Var.cpp | 70 ------------------- tools/MayaExporter/MayaExporter/Var.h | 32 --------- 6 files changed, 22 insertions(+), 117 deletions(-) delete mode 100644 tools/MayaExporter/MayaExporter/Var.cpp delete mode 100644 tools/MayaExporter/MayaExporter/Var.h diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj index b04d032f..50577919 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj @@ -175,7 +175,6 @@ - @@ -200,7 +199,6 @@ - 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 6f836155..cf4a5a35 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters @@ -59,9 +59,6 @@ Source Files - - Source Files - @@ -90,8 +87,5 @@ Header Files - - Header Files - \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/MayaIncludes.h b/tools/MayaExporter/MayaExporter/MayaIncludes.h index 6c092052..9186bfe6 100644 --- a/tools/MayaExporter/MayaExporter/MayaIncludes.h +++ b/tools/MayaExporter/MayaExporter/MayaIncludes.h @@ -31,6 +31,8 @@ #include #include #include +#include +#include // Wrappers @@ -59,5 +61,6 @@ #pragma comment(lib,"Foundation.lib") #pragma comment(lib,"OpenMaya.lib") #pragma comment(lib,"OpenMayaUI.lib") +#pragma comment (lib, "OpenMayaAnim.lib") #endif \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 8eb245e2..06c115c8 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -187,17 +187,29 @@ void Menu::GetMaterialData() void Menu::GetSkeletonData() { this->m_SkeletonHandler = new Skeleton(); + MTime startFrame = MAnimControl::animationStartTime(); + MTime endFrame = MAnimControl::animationEndTime(); - // Traverse scene and return vector with all materials - std::vector* AllMaterials = m_SkeletonHandler->DoIt(); + std::vector*> AllSkeletons; - MGlobal::displayInfo(MString() + AllMaterials->size()); - - for (int i = 0; i < AllMaterials->size(); i++) + for (int i = startFrame.value(); i < endFrame.value();i++) { - for (int j = 0; j < AllMaterials->at(i).Joints.size(); j++) + MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField)); + // Traverse scene and return vector with all materials + AllSkeletons.push_back(m_SkeletonHandler->DoIt()); + } + + MGlobal::displayInfo(MString() + AllSkeletons.size()); + + for (int i = 0; i < AllSkeletons.size(); i++) + { + std::vector*& thisSkeleton = AllSkeletons.at(i); + for (int k = 0; k < thisSkeleton->size(); k++) { - MGlobal::displayInfo(MString() + AllMaterials->at(i).Joints.at(j).Name.c_str()); + for (int j = 0; j < thisSkeleton->at(k).Joints.size(); j++) + { + MGlobal::displayInfo(MString() + thisSkeleton->at(k).Joints.at(j).Name.c_str()); + } } } } diff --git a/tools/MayaExporter/MayaExporter/Var.cpp b/tools/MayaExporter/MayaExporter/Var.cpp deleted file mode 100644 index adfcb212..00000000 --- a/tools/MayaExporter/MayaExporter/Var.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "Var.h" -#include "MayaIncludes.h" -#include - -Var::Var(Var::Type type, unsigned int numElements) -{ - m_Type = type; - m_NumElements = numElements; - - switch (m_Type) - { - case Var::Type::Int: - m_Data = new int[m_NumElements]; - break; - case Var::Type::Float: - m_Data = new float[m_NumElements]; - break; - case Var::Type::String: - m_Data = new std::string[m_NumElements]; - break; - default: - MGlobal::displayError("Var is an invalid type"); - assert(0); - break; - } -} - -Var& Var::operator=(const int& other) -{ - assert(m_Type == Type::Int); - *(int*)m_Data = other; - return *this; -} - -Var& Var::operator=(const float& other) -{ - assert(m_Type == Type::Float); - *(float*)m_Data = other; - return *this; -} - -Var& Var::operator=(const std::string& other) -{ - assert(m_Type == Type::String); - std::string tmp(other); - (*(std::string*)m_Data).swap(tmp); - return *this; -} - -//Var& Var::operator=(const Var& other) -//{ -// m_Data = other.m_Data; -// m_Type = other.m_Type; -// return *this; -//} - -Var::Type Var::isType() const -{ - return m_Type; -} - -unsigned int Var::NumElements() const -{ - return m_NumElements; -} - -void* Var::Data() -{ - return m_Data; -} \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Var.h b/tools/MayaExporter/MayaExporter/Var.h deleted file mode 100644 index b0ec66dd..00000000 --- a/tools/MayaExporter/MayaExporter/Var.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef Var_Var_h__ -#define Var_Var_h__ - -#include - -class Var -{ -public: - enum class Type - { - Int, - Float, - String - }; - - Var(Var::Type type, unsigned int numElements = 1); - ~Var() { delete[] m_Data; }; - - Var& operator=(const int& other); - Var& operator=(const float& other); - Var& operator=(const std::string& other); - //Var& operator=(const Var& other); - Type isType() const; - unsigned int NumElements() const; - void* Data(); -private: - Type m_Type; - unsigned int m_NumElements; - void* m_Data; -}; - -#endif \ No newline at end of file From 73708ec7066fd0305363e3844c35903b8edf3fa1 Mon Sep 17 00:00:00 2001 From: antc13 Date: Thu, 17 Dec 2015 14:58:46 +0100 Subject: [PATCH 08/28] You can now add/remove animation clips. --- tools/MayaExporter/MayaExporter/Menu.cpp | 144 +++++++++++++++++++---- tools/MayaExporter/MayaExporter/Menu.h | 13 ++ 2 files changed, 134 insertions(+), 23 deletions(-) diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 06c115c8..591c15fa 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -17,6 +17,8 @@ Menu::Menu(QDialog* dialog) m_BrowseButton = new QPushButton("&...", this); m_ExportAllButton = new QPushButton("&Export All", this); m_CancelButton = new QPushButton("&Cancel", this); + m_AddClipsButton = new QPushButton("&Add Clips", this); + m_RemoveClipsButton = new QPushButton("&Remove Latest Clip", this); // Option box and checkboxes QGroupBox *optionsBox = new QGroupBox(tr("Options")); @@ -39,6 +41,8 @@ Menu::Menu(QDialog* dialog) 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))); @@ -49,12 +53,25 @@ Menu::Menu(QDialog* dialog) QVBoxLayout* midLayout = new QVBoxLayout; QHBoxLayout* botLayout = new QHBoxLayout; QVBoxLayout* baseLayout = new QVBoxLayout; + QHBoxLayout* clipButtonLayout = new QHBoxLayout; + QHBoxLayout* startEndLabelLayout = new QHBoxLayout; + m_ClipLayout = new QVBoxLayout; + + m_ExportPath = new QLineEdit; m_FileDialog = new QFileDialog; QLabel* exportLabel = new QLabel; exportLabel->setText("Export Path:"); + QLabel* nameLabel = new QLabel; + nameLabel->setText("Name:"); + QLabel* startLabel = new QLabel; + startLabel->setText("Start:"); + QLabel* endLabel = new QLabel; + endLabel->setText("End:"); + + //exportLabel->setText("Export Path:"); midLayout->addWidget(optionsBox); @@ -66,19 +83,35 @@ Menu::Menu(QDialog* dialog) botLayout->addWidget(m_ExportAllButton); botLayout->addWidget(m_CancelButton); + startEndLabelLayout->addWidget(nameLabel); + startEndLabelLayout->addWidget(startLabel); + startEndLabelLayout->addWidget(endLabel); + + clipButtonLayout->addWidget(m_AddClipsButton); + clipButtonLayout->addWidget(m_RemoveClipsButton); + baseLayout->addLayout(topLayout); baseLayout->addLayout(midLayout); baseLayout->addSpacing(10); - baseLayout->addLayout(botLayout); + + baseLayout->addSpacing(10); + baseLayout->addLayout(clipButtonLayout); + baseLayout->addLayout(startEndLabelLayout); + baseLayout->addLayout(m_ClipLayout); baseLayout->addStretch(); // Set the layout for our window dialog->setLayout(baseLayout); + for (unsigned int i = 0; i < 3; i++) { + this->AddClipClicked(true); + } + } + void Menu::ExportSelected(bool checked) { // Retrieving the objects we currently have selected @@ -101,6 +134,11 @@ void Menu::ExportSelected(bool checked) else { cout << m_ExportPath->text().toLocal8Bit().constData() << endl; } + + if (m_ExportAnimationsButton->isChecked()) { + GetSkeletonData(); + } + } void Menu::ExportPathClicked(bool) @@ -112,6 +150,48 @@ void Menu::ExportPathClicked(bool) m_ExportPath->setText(fileName); } +void Menu::AddClipClicked(bool) +{ + QHBoxLayout* tempLayout = new QHBoxLayout; + + QLineEdit* nameLineEdit = new QLineEdit; + QLineEdit* startLineEdit = new QLineEdit; + QLineEdit* endLineEdit = new QLineEdit; + + m_AnimationClipName.push_back(nameLineEdit); + m_StartFrameLines.push_back(startLineEdit); + m_EndFrameLines.push_back(endLineEdit); + + tempLayout->addWidget(nameLineEdit); + tempLayout->addWidget(startLineEdit); + tempLayout->addWidget(endLineEdit); + + m_ClipLayout->addLayout(tempLayout); + //m_ClipLayout->update(); + layouts.push_back(tempLayout); +} + +void Menu::RemoveClipClicked(bool) +{ + if (m_StartFrameLines.size() > 0) { + QLayoutItem* tempWidget;// = m_ClipLayout->itemAt(0); + + for (unsigned int i = 0; i < layouts.size(); i++) { + while ((tempWidget = layouts[layouts.size()-1]->takeAt(0)) != 0) { + delete tempWidget->widget(); + delete tempWidget; + } + } + + m_ClipLayout->removeItem(tempWidget); + m_ClipLayout->update(); + + layouts.pop_back(); + m_StartFrameLines.pop_back(); + m_EndFrameLines.pop_back(); + } +} + void Menu::ExportAll(bool) { MDagPath path; @@ -134,6 +214,9 @@ void Menu::ExportAll(bool) else { cout << m_ExportPath->text().toLocal8Bit().constData() << endl; } + + if(m_ExportAnimationsButton->isChecked()) + GetSkeletonData(); } void Menu::CancelClicked(bool) @@ -145,7 +228,6 @@ void Menu::Button1Clicked(bool) { if (m_ExportAnimationsButton->isChecked()) { MGlobal::displayInfo("1 checked!"); - this->GetSkeletonData(); } else { MGlobal::displayInfo("1 unchecked!"); @@ -186,31 +268,46 @@ void Menu::GetMaterialData() void Menu::GetSkeletonData() { - this->m_SkeletonHandler = new Skeleton(); - MTime startFrame = MAnimControl::animationStartTime(); - MTime endFrame = MAnimControl::animationEndTime(); + if (MAnimControl::currentTime().unit() != MTime::kNTSCField) { + MGlobal::displayError(MString() + "Please change to 60 FPS under Preferences/Settings!"); + return; + } + + this->m_SkeletonHandler = new Skeleton(); std::vector*> AllSkeletons; - for (int i = startFrame.value(); i < endFrame.value();i++) - { - MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField)); - // Traverse scene and return vector with all materials - AllSkeletons.push_back(m_SkeletonHandler->DoIt()); - } - - MGlobal::displayInfo(MString() + AllSkeletons.size()); - - for (int i = 0; i < AllSkeletons.size(); i++) - { - std::vector*& thisSkeleton = AllSkeletons.at(i); - for (int k = 0; k < thisSkeleton->size(); k++) - { - for (int j = 0; j < thisSkeleton->at(k).Joints.size(); j++) - { - MGlobal::displayInfo(MString() + thisSkeleton->at(k).Joints.at(j).Name.c_str()); - } + 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(); + + for (int i = startFrame; i < endFrame;++i) + { + MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField)); + MTime time = MAnimControl::currentTime(); + + // Traverse scene and return vector with all materials + AllSkeletons.push_back(m_SkeletonHandler->DoIt()); + } + + //MGlobal::displayInfo(MString() + AllSkeletons.size()); + + /*for (int i = 0; i < AllSkeletons.size(); i++) + { + std::vector*& thisSkeleton = AllSkeletons.at(i); + for (int k = 0; k < thisSkeleton->size(); k++) + { + for (int j = 0; j < thisSkeleton->at(k).Joints.size(); j++) + { + MGlobal::displayInfo(MString() + thisSkeleton->at(k).Joints.at(j).Name.c_str()); + } + } + }*/ } } @@ -221,5 +318,6 @@ Menu::~Menu() //delete exportPath; //delete fileDialog; 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 a0fe93f6..81ec2834 100644 --- a/tools/MayaExporter/MayaExporter/Menu.h +++ b/tools/MayaExporter/MayaExporter/Menu.h @@ -29,6 +29,9 @@ #include #include #include +#include +#include + #include "MayaIncludes.h" #include "Material.h" @@ -48,6 +51,8 @@ public: private slots: void ExportSelected(bool checked); void ExportPathClicked(bool); + void AddClipClicked(bool); + void RemoveClipClicked(bool); void ExportAll(bool); void CancelClicked(bool); @@ -58,10 +63,18 @@ private slots: private: Menu(); + std::vector m_AnimationClipName; + std:: vector m_StartFrameLines; + std::vector m_EndFrameLines; + 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_ExportAnimationsButton = nullptr; QCheckBox* m_CopyTexturesButton = nullptr; From bc4cc5db548eeeb76391f1cd5f263e5aedd611e9 Mon Sep 17 00:00:00 2001 From: Teejoon Date: Fri, 18 Dec 2015 10:03:00 +0100 Subject: [PATCH 09/28] Changed how we get skeletons. Made so that we could get the bind pose for each skeleton in the scene --- .../MayaExporter/MayaExporter/MayaIncludes.h | 3 + tools/MayaExporter/MayaExporter/Menu.cpp | 37 ++++-- tools/MayaExporter/MayaExporter/Skeleton.cpp | 114 +++++++++++++++--- tools/MayaExporter/MayaExporter/Skeleton.h | 13 +- 4 files changed, 135 insertions(+), 32 deletions(-) diff --git a/tools/MayaExporter/MayaExporter/MayaIncludes.h b/tools/MayaExporter/MayaExporter/MayaIncludes.h index 9186bfe6..4a810787 100644 --- a/tools/MayaExporter/MayaExporter/MayaIncludes.h +++ b/tools/MayaExporter/MayaExporter/MayaIncludes.h @@ -33,6 +33,9 @@ #include #include #include +#include +#include +#include // Wrappers diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 06c115c8..410e0fa3 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -190,25 +190,44 @@ void Menu::GetSkeletonData() MTime startFrame = MAnimControl::animationStartTime(); MTime endFrame = MAnimControl::animationEndTime(); - std::vector*> AllSkeletons; + std::vector> allSkeletons; + + std::vector allBindPoses; + allBindPoses = m_SkeletonHandler->GetBindPoses(); for (int i = startFrame.value(); i < endFrame.value();i++) { MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField)); // Traverse scene and return vector with all materials - AllSkeletons.push_back(m_SkeletonHandler->DoIt()); + allSkeletons.push_back(m_SkeletonHandler->DoIt()); + } + + //print out all bind poses + for (auto aBindPose : allBindPoses) + { + 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]); + } } - MGlobal::displayInfo(MString() + AllSkeletons.size()); - - for (int i = 0; i < AllSkeletons.size(); i++) + //Print out all skeletons for all frames + MGlobal::displayInfo(MString() + allSkeletons.size()); + for (auto frameSkeletons : allSkeletons) { - std::vector*& thisSkeleton = AllSkeletons.at(i); - for (int k = 0; k < thisSkeleton->size(); k++) + for (auto aSkeleton : frameSkeletons) { - for (int j = 0; j < thisSkeleton->at(k).Joints.size(); j++) + MGlobal::displayInfo(MString() + aSkeleton.Name.c_str()); + for (auto joint : aSkeleton.Joints) { - MGlobal::displayInfo(MString() + thisSkeleton->at(k).Joints.at(j).Name.c_str()); + //MGlobal::displayInfo(MString() + joint.Translation[0] + " " + joint.Translation[1] + " " + joint.Translation[2]); + //MGlobal::displayInfo(MString() + joint.Rotation[0] + " " + joint.Rotation[1] + " " + joint.Rotation[2]); + //MGlobal::displayInfo(MString() + joint.Scale[0] + " " + joint.Scale[1] + " " + joint.Scale[2]); } } } diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp index 3e95b817..030c17dd 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.cpp +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -1,13 +1,14 @@ #include "Skeleton.h" -std::vector* Skeleton::DoIt() +std::vector Skeleton::DoIt() { - MItDependencyNodes jointIt(MFn::kJoint); + std::vector m_AllSkeletons; + + MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); SkeletonNode SkeletonStorage; while (!jointIt.isDone()) { - MFnDependencyNode SkeletonFnDN(jointIt.thisNode()); - MFnTransform TransformNode(SkeletonFnDN.object()); + MFnTransform TransformNode(jointIt.currentItem()); Joint NewJoint; if (MFnDependencyNode(TransformNode.parent(0)).name() == "world") { @@ -20,24 +21,27 @@ std::vector* Skeleton::DoIt() 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()); - } + //NewJoint.ParentIndex = -1; // This joint is root } - m_Hierarchy.push_back(TransformNode.object()); - - NewJoint.Name = TransformNode.name().asChar(); + //NewJoint.Name = TransformNode.name().asChar(); MMatrix Matrix = TransformNode.transformationMatrix(); + //double tmp[3]; + //((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp); + //NewJoint.Rotation[0] = tmp[0]; + //NewJoint.Rotation[1] = tmp[1]; + //NewJoint.Rotation[2] = tmp[2]; + //((MTransformationMatrix)Matrix).getScale(tmp, MSpace::Space::kTransform); + //NewJoint.Scale[0] = tmp[0]; + //NewJoint.Scale[1] = tmp[1]; + //NewJoint.Scale[2] = tmp[2]; + //((MTransformationMatrix)Matrix).getTranslation(MSpace::Space::kTransform).get(tmp); + //NewJoint.Translation[0] = tmp[0]; + //NewJoint.Translation[1] = tmp[1]; + //NewJoint.Translation[2] = tmp[2]; + for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j]; @@ -51,5 +55,79 @@ std::vector* Skeleton::DoIt() m_AllSkeletons.push_back(SkeletonStorage); - return &m_AllSkeletons; + return m_AllSkeletons; +} + +std::vector Skeleton::GetBindPoses() +{ + std::vector m_AllSkeletons; + std::vector m_Hierarchy; + + MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); + BindPoseSkeletonNode SkeletonStorage; + + while (!jointIt.isDone()) { + MFnTransform MayaJoint(jointIt.currentItem()); + + if (MFnDependencyNode(MayaJoint.parent(0)).name() == "world") { + if (SkeletonStorage.Joints.size() != 0) { + m_AllSkeletons.push_back(SkeletonStorage); + + SkeletonStorage.Joints.clear(); + SkeletonStorage.Name.clear(); + SkeletonStorage.ParentIDs.clear(); + SkeletonStorage.Name.clear(); + } + + SkeletonStorage.Name = MayaJoint.name().asChar(); + SkeletonStorage.ParentIDs.push_back(-1); // This joint is root + } + else { + auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), MayaJoint.parent(0)); + if (it != m_Hierarchy.end()) { + SkeletonStorage.ParentIDs.push_back(it - m_Hierarchy.begin()); + } + else { + MGlobal::displayError(MString() + "Could not find joint parent for: " + MayaJoint.name()); + } + } + m_Hierarchy.push_back(MayaJoint.object()); + + Joint NewJoint; + + MPlug BindPose = MayaJoint.findPlug("bindPose"); + MDataHandle DataHandle; + BindPose.getValue(DataHandle); + MFnMatrixData MartixFn(DataHandle.data()); + MMatrix Matrix = MartixFn.matrix(); + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j]; + } + } + + /*double tmp[3]; + ((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp); + NewJoint.Rotation[0] = tmp[0]; + NewJoint.Rotation[1] = tmp[1]; + NewJoint.Rotation[2] = tmp[2]; + ((MTransformationMatrix)Matrix).getScale(tmp, MSpace::Space::kTransform); + NewJoint.Scale[0] = tmp[0]; + NewJoint.Scale[1] = tmp[1]; + NewJoint.Scale[2] = tmp[2]; + ((MTransformationMatrix)Matrix).getTranslation(MSpace::Space::kTransform).get(tmp); + NewJoint.Translation[0] = tmp[0]; + NewJoint.Translation[1] = tmp[1]; + NewJoint.Translation[2] = tmp[2];*/ + + SkeletonStorage.Joints.push_back(NewJoint); + SkeletonStorage.JointNames.push_back(MayaJoint.name().asChar()); + + 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 26e99d4b..3ee01224 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.h +++ b/tools/MayaExporter/MayaExporter/Skeleton.h @@ -7,12 +7,11 @@ #include "MayaIncludes.h" struct Joint { - int ParentIndex; + //int ParentIndex; //std::array Rotation; //std::array Translation; //std::array Scale; std::array, 4> OffsetMatrix; - std::string Name; }; struct SkeletonNode { @@ -20,12 +19,16 @@ struct SkeletonNode { std::vector Joints; }; +struct BindPoseSkeletonNode : SkeletonNode { + std::vector ParentIDs; + std::vector JointNames; +}; + class Skeleton { public: - std::vector* DoIt(); + std::vector DoIt(); + std::vector GetBindPoses(); private: - std::vector m_AllSkeletons; - std::vector m_Hierarchy; }; #endif //Skeleton_Skeleton_h__ \ No newline at end of file From c9db46564f1394978bf75e88d5b18bce0e0d3908 Mon Sep 17 00:00:00 2001 From: antc13 Date: Fri, 18 Dec 2015 16:21:07 +0100 Subject: [PATCH 10/28] Spitting out files WIP --- .../MayaExporter/MayaExporter.vcxproj | 3 + .../MayaExporter/MayaExporter.vcxproj.filters | 9 +++ .../MayaExporter/MayaExporter/MayaIncludes.h | 1 + tools/MayaExporter/MayaExporter/Menu.cpp | 12 +++- tools/MayaExporter/MayaExporter/Menu.h | 3 + tools/MayaExporter/MayaExporter/Mesh.cpp | 52 ++++++++++---- tools/MayaExporter/MayaExporter/Mesh.h | 14 +++- tools/MayaExporter/MayaExporter/OutputData.h | 23 ++++++ tools/MayaExporter/MayaExporter/Skeleton.cpp | 3 + tools/MayaExporter/MayaExporter/Skeleton.h | 70 +++++++++++++++++-- .../MayaExporter/MayaExporter/WriteToFile.cpp | 38 ++++++++++ tools/MayaExporter/MayaExporter/WriteToFile.h | 49 +++++++++++++ 12 files changed, 257 insertions(+), 20 deletions(-) create mode 100644 tools/MayaExporter/MayaExporter/OutputData.h create mode 100644 tools/MayaExporter/MayaExporter/WriteToFile.cpp create mode 100644 tools/MayaExporter/MayaExporter/WriteToFile.h diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj index 50577919..a9154ac7 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj @@ -175,6 +175,7 @@ + @@ -198,7 +199,9 @@ + + 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 cf4a5a35..be5b36b1 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj.filters @@ -59,6 +59,9 @@ Source Files + + Source Files + @@ -87,5 +90,11 @@ Header Files + + Header Files + + + Header Files + \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/MayaIncludes.h b/tools/MayaExporter/MayaExporter/MayaIncludes.h index 4a810787..0e490208 100644 --- a/tools/MayaExporter/MayaExporter/MayaIncludes.h +++ b/tools/MayaExporter/MayaExporter/MayaIncludes.h @@ -36,6 +36,7 @@ #include #include #include +#include // Wrappers diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index ae5b1732..ed09ec25 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -215,8 +215,12 @@ void Menu::ExportAll(bool) cout << m_ExportPath->text().toLocal8Bit().constData() << endl; } + m_File.ASCIIFilePath("C:/Users/Nickelodion/Desktop/coolASCII.txt"); + m_File.binaryFilePath("C:/Users/Nickelodion/Desktop/coolSoptunz.bin"); + if(m_ExportAnimationsButton->isChecked()) GetSkeletonData(); + } void Menu::CancelClicked(bool) @@ -298,8 +302,10 @@ void Menu::GetSkeletonData() } //print out all bind poses + m_File.OpenFiles(); 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++) { @@ -312,21 +318,25 @@ void Menu::GetSkeletonData() } //Print out all skeletons for all frames + MGlobal::displayInfo(MString() + allSkeletons.size()); for (auto frameSkeletons : allSkeletons) { for (auto aSkeleton : frameSkeletons) { MGlobal::displayInfo(MString() + aSkeleton.Name.c_str()); + //m_File.writeToFiles(&aSkeleton); for (auto joint : aSkeleton.Joints) { + //m_File.writeToFiles(&joint); //MGlobal::displayInfo(MString() + joint.Translation[0] + " " + joint.Translation[1] + " " + joint.Translation[2]); //MGlobal::displayInfo(MString() + joint.Rotation[0] + " " + joint.Rotation[1] + " " + joint.Rotation[2]); //MGlobal::displayInfo(MString() + joint.Scale[0] + " " + joint.Scale[1] + " " + joint.Scale[2]); } } - }*/ + } } + m_File.CloseFiles(); } Menu::~Menu() diff --git a/tools/MayaExporter/MayaExporter/Menu.h b/tools/MayaExporter/MayaExporter/Menu.h index 81ec2834..0174cbc3 100644 --- a/tools/MayaExporter/MayaExporter/Menu.h +++ b/tools/MayaExporter/MayaExporter/Menu.h @@ -37,6 +37,7 @@ #include "Material.h" #include "Mesh.h" #include "Skeleton.h" +#include "WriteToFile.h" class Menu : public QWidget { @@ -86,6 +87,8 @@ private: Material* m_MaterialHandler = nullptr; Skeleton* m_SkeletonHandler = nullptr; + + WriteToFile m_File; }; #endif \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index fa52fc8e..3965daf8 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -25,26 +25,48 @@ void Mesh::GetMeshData(MObject object) MVector normal; MPoint pos; float2 UV; + double biTangent[3]; + double biNormal[3]; VertexLayout thisVertex; + MFloatVectorArray biTangents; + MFloatVectorArray biNormals; + mesh.getTangents(biTangents, MSpace::kObject, NULL); + mesh.getBinormals(biNormals, MSpace::kObject, NULL); + + MGlobal::displayInfo("Befor Loop"); + MItMeshFaceVertex faceVert(object); + int intDummy = 0; for (MItMeshPolygon meshPolyIter(object); !meshPolyIter.isDone(); meshPolyIter.next()) { vector localVertexToGlobalIndex; meshPolyIter.getVertices(vertices); meshPolyIter.getTriangles(dummy, triangleList); UINT indexOffset = verticesData.size(); - + MGlobal::displayInfo("Befor Second Loop"); for (UINT i = 0; i < vertices.length(); i++) { - vertexIndex = meshPolyIter.vertexIndex(i); - pos = meshPolyIter.point(i); - pos.get(thisVertex.Pos); - - meshPolyIter.getNormal(i, normal); + faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); + MGlobal::displayInfo("In Second Loop"); + faceVert.position().get(thisVertex.Pos); + faceVert.getNormal(normal); thisVertex.Normal[0] = normal[0]; thisVertex.Normal[1] = normal[1]; thisVertex.Normal[2] = normal[2]; - meshPolyIter.getUV(i, UV); + MFloatVector biTangent = biTangents[faceVert.tangentId()]; + //MVector tmp = faceVert.getTangent(MSpace::kObject, NULL); + //tmp.get(biTangent); + thisVertex.BiTangent[0] = biTangent[0]; + thisVertex.BiTangent[1] = biTangent[1]; + thisVertex.BiTangent[2] = biTangent[2]; + + MFloatVector biNormal = biNormals[faceVert.tangentId()]; + //faceVert.getBinormal().get(biNormal); + thisVertex.BiNormal[0] = biNormal[0]; + thisVertex.BiNormal[1] = biNormal[1]; + thisVertex.BiNormal[2] = biNormal[2]; + + faceVert.getUV(UV); thisVertex.Uv[0] = UV[0]; thisVertex.Uv[1] = UV[1]; @@ -53,14 +75,18 @@ void Mesh::GetMeshData(MObject object) 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 << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl; + cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[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); - } + MGlobal::displayInfo("Befor Third Loop"); + + //for (UINT i = 0; i < triangleList.length(); i++) { + // UINT k = 0; + // while (localVertexToGlobalIndex[k] != triangleList[i]) + // k++; + // indexArray.push_back(indexOffset + k); + //} } } diff --git a/tools/MayaExporter/MayaExporter/Mesh.h b/tools/MayaExporter/MayaExporter/Mesh.h index 0ba9624d..00b88654 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.h +++ b/tools/MayaExporter/MayaExporter/Mesh.h @@ -4,13 +4,25 @@ #include #include +#include "OutputData.h" #include "MayaIncludes.h" -struct VertexLayout +class VertexLayout : public OutputData { +public: + float Pos[3]; float Normal[3]; + float BiNormal[3]; + float BiTangent[3]; float Uv[2]; + + virtual void WriteBinary(std::ostream& out) { + + } + virtual void WriteASCII(std::ostream& out) const { + + } }; class Mesh diff --git a/tools/MayaExporter/MayaExporter/OutputData.h b/tools/MayaExporter/MayaExporter/OutputData.h new file mode 100644 index 00000000..60159340 --- /dev/null +++ b/tools/MayaExporter/MayaExporter/OutputData.h @@ -0,0 +1,23 @@ +#ifndef OutputData_OutputData_h__ +#define OutputData_OutputData_h__ +#include +//template +class OutputData +{ +public://std::ostream& out, const OutputData& obj + //OutputData(T& object) + // : m_Object(object) + //{}; + + friend std::ostream& operator<<(std::ostream& out, const OutputData& obj) + { + obj.WriteASCII(out); + return out; + }; + virtual void WriteBinary(std::ostream& out) = 0; + virtual void WriteASCII(std::ostream& out) const = 0; + + //T& m_Object = nullptr; +}; + +#endif \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp index 030c17dd..3bba4c0a 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.cpp +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -1,5 +1,8 @@ #include "Skeleton.h" + + + std::vector Skeleton::DoIt() { std::vector m_AllSkeletons; diff --git a/tools/MayaExporter/MayaExporter/Skeleton.h b/tools/MayaExporter/MayaExporter/Skeleton.h index 3ee01224..2d363cf8 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.h +++ b/tools/MayaExporter/MayaExporter/Skeleton.h @@ -5,23 +5,83 @@ #include #include #include "MayaIncludes.h" - -struct Joint { +#include "OutputData.h" +class Joint : public OutputData{ +public: + //Joint() : OutputData((Joint)*this) + //{}; //int ParentIndex; //std::array Rotation; //std::array Translation; //std::array Scale; - std::array, 4> OffsetMatrix; + //std::array, 4> OffsetMatrix; + float OffsetMatrix[4][4]; + + virtual void WriteBinary(std::ostream& out) + { + out.write((char*)OffsetMatrix, 4 * 4 * sizeof(float)); + } + + virtual void WriteASCII(std::ostream& out) const + { + for (int i = 0; i < 4; i++) + { + for (int k = 0; k < 4; k++) + out << this->OffsetMatrix[i][k] << " "; + out << endl; + } + }; }; -struct SkeletonNode { +class SkeletonNode : public OutputData { +public: std::string Name; std::vector Joints; + + virtual void WriteBinary(std::ostream& out) + { + out.write(Name.c_str(), Name.size()); + for (auto aJoint : Joints) + { + aJoint.WriteBinary(out); + } + } + virtual void WriteASCII(std::ostream& out) const + { + out << "Skeleton: " << Name << endl; + for (auto aJoint : Joints) + { + aJoint.WriteASCII(out); + } + }; }; -struct BindPoseSkeletonNode : SkeletonNode { +class BindPoseSkeletonNode : public SkeletonNode { +public: std::vector ParentIDs; std::vector JointNames; + virtual void WriteBinary(std::ostream& out) + { + out.write(Name.c_str(), Name.size()); + for (int i = 0; i < Joints.size(); i++) + { + out.write((char*)&ParentIDs[i],sizeof(int)); + Joints[i].WriteBinary(out); + out.write(JointNames[i].c_str(), JointNames[i].size()); + } + + } + + virtual void WriteASCII(std::ostream& out) const + { + out << "Bind Pose: " << Name << endl; + for (int i = 0; i < Joints.size(); i++) + { + out << ParentIDs[i] << endl; + Joints[i].WriteASCII(out); + out << JointNames[i] << endl; + } + }; }; class Skeleton { diff --git a/tools/MayaExporter/MayaExporter/WriteToFile.cpp b/tools/MayaExporter/MayaExporter/WriteToFile.cpp new file mode 100644 index 00000000..10883416 --- /dev/null +++ b/tools/MayaExporter/MayaExporter/WriteToFile.cpp @@ -0,0 +1,38 @@ +#include "WriteToFile.h" + +WriteToFile::~WriteToFile() +{ + CloseFiles(); +} + +bool WriteToFile::binaryFilePath(string filePathAndFileName) +{ + binFileName = filePathAndFileName; + ofstream binFile(filePathAndFileName, ofstream::binary); + if (!binFile) + return false; + return true; +} + +bool WriteToFile::ASCIIFilePath(string filePathAndFileName) +{ + ASCIIFileName = filePathAndFileName; + ofstream ASCIIFile(filePathAndFileName); + if (!ASCIIFile) + return false; + return true; +} + +void WriteToFile::OpenFiles() +{ + if (binFile) + binFile.open(binFileName, ofstream::binary); + if (ASCIIFile) + ASCIIFile.open(ASCIIFileName); +} + +void WriteToFile::CloseFiles() +{ + binFile.close(); + ASCIIFile.close(); +} \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/WriteToFile.h b/tools/MayaExporter/MayaExporter/WriteToFile.h new file mode 100644 index 00000000..f0c066d4 --- /dev/null +++ b/tools/MayaExporter/MayaExporter/WriteToFile.h @@ -0,0 +1,49 @@ +#ifndef WriteToFile_WriteToFile_h__ +#define WriteToFile_WriteToFile_h__ + +#include "MayaIncludes.h" +#include "OutputData.h" +#include +#include + +using namespace std; + +class WriteToFile +{ +public: + ~WriteToFile(); + bool binaryFilePath(string filePathAndFileName); + bool ASCIIFilePath(string filePathAndFileName); + + void writeToFiles(OutputData* toWrite, unsigned int numOfElementToWrite = 1, unsigned int startIndex = 0) + { + MGlobal::displayInfo("WriteToFile::writeToFiles()"); + if (ASCIIFile.is_open()) + { + MGlobal::displayInfo("Writing to ASCIIfile"); + for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++) + ASCIIFile << toWrite[i] << endl; + } + + if (binFile.is_open()) + { + MGlobal::displayInfo("Writing to binaryfile"); + for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++) + toWrite[i].WriteBinary(binFile); + } + + } + + void OpenFiles(); + void CloseFiles(); + +private: + string binFileName; + string ASCIIFileName; + ofstream binFile; + ofstream ASCIIFile; +}; + + + +#endif \ No newline at end of file From eb5fca898ff4b092a93c1209a798824e1f796f1b Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Mon, 21 Dec 2015 12:55:25 +0100 Subject: [PATCH 11/28] Fix small bug with push_back order Commited directly from GitHub. Blame it if something explodes. --- tools/MayaExporter/MayaExporter/Material.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/MayaExporter/MayaExporter/Material.cpp b/tools/MayaExporter/MayaExporter/Material.cpp index 2bc084dc..ac9c46ea 100644 --- a/tools/MayaExporter/MayaExporter/Material.cpp +++ b/tools/MayaExporter/MayaExporter/Material.cpp @@ -226,11 +226,11 @@ std::vector* Material::DoIt() else if (matIt.thisNode().hasFn(MFn::kLambert)) { grabLambertProperties(MaterialStorage, MaterialFnDN); - m_AllMaterials.push_back(MaterialStorage); - MaterialStorage.Specular.fill(0.0f); MaterialStorage.ReflectionFactor = 0.0f; MaterialStorage.SpecularExponent = 0.0f; + + m_AllMaterials.push_back(MaterialStorage); } matIt.next(); From 1667358e0c3a59ee50b317bac75b85b8b35d5b2b Mon Sep 17 00:00:00 2001 From: antc13 Date: Fri, 8 Jan 2016 16:47:04 +0100 Subject: [PATCH 12/28] We now export animations. --- .../GeneratedFiles/Debug/moc_Menu.cpp | 31 +- tools/MayaExporter/MayaExporter/Menu.cpp | 63 ++-- tools/MayaExporter/MayaExporter/Mesh.cpp | 17 +- tools/MayaExporter/MayaExporter/Skeleton.cpp | 296 ++++++++++++------ tools/MayaExporter/MayaExporter/Skeleton.h | 117 ++++--- 5 files changed, 318 insertions(+), 206 deletions(-) diff --git a/tools/MayaExporter/MayaExporter/GeneratedFiles/Debug/moc_Menu.cpp b/tools/MayaExporter/MayaExporter/GeneratedFiles/Debug/moc_Menu.cpp index aef8d533..a375ed53 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 - 7, 14, // methods + 9, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors @@ -33,17 +33,20 @@ static const uint qt_meta_data_Menu[] = { 14, 6, 5, 5, 0x08, 35, 5, 5, 5, 0x08, 59, 5, 5, 5, 0x08, - 75, 5, 5, 5, 0x08, - 95, 5, 5, 5, 0x08, - 116, 5, 5, 5, 0x08, - 137, 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, 0 // eod }; static const char qt_meta_stringdata_Menu[] = { "Menu\0\0checked\0ExportSelected(bool)\0" - "ExportPathClicked(bool)\0ExportAll(bool)\0" + "ExportPathClicked(bool)\0AddClipClicked(bool)\0" + "RemoveClipClicked(bool)\0ExportAll(bool)\0" "CancelClicked(bool)\0Button1Clicked(bool)\0" "Button2Clicked(bool)\0Button3Clicked(bool)\0" }; @@ -56,11 +59,13 @@ void Menu::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void * 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->ExportAll((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 3: _t->CancelClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 4: _t->Button1Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 5: _t->Button2Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break; - case 6: _t->Button3Clicked((*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; default: ; } } @@ -98,9 +103,9 @@ int Menu::qt_metacall(QMetaObject::Call _c, int _id, void **_a) if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { - if (_id < 7) + if (_id < 9) qt_static_metacall(this, _c, _id, _a); - _id -= 7; + _id -= 9; } return _id; } diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index ed09ec25..77241cad 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -72,7 +72,7 @@ Menu::Menu(QDialog* dialog) endLabel->setText("End:"); //exportLabel->setText("Export Path:"); - + midLayout->addWidget(optionsBox); topLayout->addWidget(exportLabel); @@ -119,7 +119,7 @@ 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); @@ -177,7 +177,7 @@ void Menu::RemoveClipClicked(bool) QLayoutItem* tempWidget;// = m_ClipLayout->itemAt(0); for (unsigned int i = 0; i < layouts.size(); i++) { - while ((tempWidget = layouts[layouts.size()-1]->takeAt(0)) != 0) { + while ((tempWidget = layouts[layouts.size() - 1]->takeAt(0)) != 0) { delete tempWidget->widget(); delete tempWidget; } @@ -185,7 +185,7 @@ void Menu::RemoveClipClicked(bool) m_ClipLayout->removeItem(tempWidget); m_ClipLayout->update(); - + layouts.pop_back(); m_StartFrameLines.pop_back(); m_EndFrameLines.pop_back(); @@ -195,10 +195,10 @@ void Menu::RemoveClipClicked(bool) void Menu::ExportAll(bool) { MDagPath path; - + // 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)) { MFnDependencyNode thisNode(node); @@ -218,7 +218,7 @@ void Menu::ExportAll(bool) m_File.ASCIIFilePath("C:/Users/Nickelodion/Desktop/coolASCII.txt"); m_File.binaryFilePath("C:/Users/Nickelodion/Desktop/coolSoptunz.bin"); - if(m_ExportAnimationsButton->isChecked()) + if (m_ExportAnimationsButton->isChecked()) GetSkeletonData(); } @@ -267,7 +267,7 @@ void Menu::GetMaterialData() // Access the colorR component of one material (example) cout << AllMaterials->at(0).Color[0] << endl; - MGlobal::displayInfo(MString() + AllMaterials->at(0).Color[0]); + MGlobal::displayInfo(MString() + AllMaterials->at(0).Color[0]); } void Menu::GetSkeletonData() @@ -277,10 +277,10 @@ void Menu::GetSkeletonData() MGlobal::displayError(MString() + "Please change to 60 FPS under Preferences/Settings!"); return; } - - std::vector> allSkeletons; std::vector allBindPoses; + std::vector allAnimations; + allBindPoses = m_SkeletonHandler->GetBindPoses(); for (unsigned int j = 0; j < m_StartFrameLines.size(); j++) { @@ -291,24 +291,19 @@ void Menu::GetSkeletonData() int startFrame = m_StartFrameLines[j]->text().toInt(); int endFrame = m_EndFrameLines[j]->text().toInt(); + std::string animationName = m_AnimationClipName[j]->text().toAscii().constData(); - for (int i = startFrame; i < endFrame;++i) - { - MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField)); - MTime time = MAnimControl::currentTime(); + allAnimations.push_back(m_SkeletonHandler->GetAnimData(animationName, startFrame, endFrame)); + } + + m_File.OpenFiles(); - // Traverse scene and return vector with all materials - allSkeletons.push_back(m_SkeletonHandler->DoIt()); - } - //print out all bind poses - m_File.OpenFiles(); - for (auto aBindPose : allBindPoses) - { + 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++) - { + + 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]); @@ -316,25 +311,9 @@ void Menu::GetSkeletonData() //MGlobal::displayInfo(MString() + aBindPose.Joints[i].Scale[0] + " " + aBindPose.Joints[i].Scale[1] + " " + aBindPose.Joints[i].Scale[2]); } } - - //Print out all skeletons for all frames - - MGlobal::displayInfo(MString() + allSkeletons.size()); - for (auto frameSkeletons : allSkeletons) - { - for (auto aSkeleton : frameSkeletons) - { - MGlobal::displayInfo(MString() + aSkeleton.Name.c_str()); - //m_File.writeToFiles(&aSkeleton); - for (auto joint : aSkeleton.Joints) - { - //m_File.writeToFiles(&joint); - //MGlobal::displayInfo(MString() + joint.Translation[0] + " " + joint.Translation[1] + " " + joint.Translation[2]); - //MGlobal::displayInfo(MString() + joint.Rotation[0] + " " + joint.Rotation[1] + " " + joint.Rotation[2]); - //MGlobal::displayInfo(MString() + joint.Scale[0] + " " + joint.Scale[1] + " " + joint.Scale[2]); - } - } - } + //print out all animations + for (auto aAnimation : allAnimations) { + m_File.writeToFiles(&aAnimation); } m_File.CloseFiles(); } diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index 3965daf8..58a7fbe4 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -34,7 +34,6 @@ void Mesh::GetMeshData(MObject object) mesh.getTangents(biTangents, MSpace::kObject, NULL); mesh.getBinormals(biNormals, MSpace::kObject, NULL); - MGlobal::displayInfo("Befor Loop"); MItMeshFaceVertex faceVert(object); int intDummy = 0; for (MItMeshPolygon meshPolyIter(object); !meshPolyIter.isDone(); meshPolyIter.next()) { @@ -43,10 +42,10 @@ void Mesh::GetMeshData(MObject object) meshPolyIter.getTriangles(dummy, triangleList); UINT indexOffset = verticesData.size(); - MGlobal::displayInfo("Befor Second Loop"); + //MGlobal::displayInfo("Befor Second Loop"); for (UINT i = 0; i < vertices.length(); i++) { faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); - MGlobal::displayInfo("In Second Loop"); + //MGlobal::displayInfo("In Second Loop"); faceVert.position().get(thisVertex.Pos); faceVert.getNormal(normal); thisVertex.Normal[0] = normal[0]; @@ -73,13 +72,13 @@ void Mesh::GetMeshData(MObject object) 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 << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl; - cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl; - cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl; + //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 << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl; + //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("Befor Third Loop"); //for (UINT i = 0; i < triangleList.length(); i++) { // UINT k = 0; diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp index 3bba4c0a..394f548b 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.cpp +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -3,33 +3,225 @@ -std::vector Skeleton::DoIt() +//std::vector Skeleton::DoIt() +//{ +// std::vector m_AllSkeletons; +// +// MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); +// SkeletonNode SkeletonStorage; +// +// while (!jointIt.isDone()) { +// MFnTransform TransformNode(jointIt.currentItem()); +// 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 +// } +// +// //NewJoint.Name = TransformNode.name().asChar(); +// +// MMatrix Matrix = TransformNode.transformationMatrix(); +// +// //double tmp[3]; +// //((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp); +// //NewJoint.Rotation[0] = tmp[0]; +// //NewJoint.Rotation[1] = tmp[1]; +// //NewJoint.Rotation[2] = tmp[2]; +// //((MTransformationMatrix)Matrix).getScale(tmp, MSpace::Space::kTransform); +// //NewJoint.Scale[0] = tmp[0]; +// //NewJoint.Scale[1] = tmp[1]; +// //NewJoint.Scale[2] = tmp[2]; +// //((MTransformationMatrix)Matrix).getTranslation(MSpace::Space::kTransform).get(tmp); +// //NewJoint.Translation[0] = tmp[0]; +// //NewJoint.Translation[1] = tmp[1]; +// //NewJoint.Translation[2] = tmp[2]; +// +// 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; +//} +std::string attr[9] = { "scaleX", "scaleY", "scaleZ", "translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ" }; + +Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame) { - std::vector m_AllSkeletons; + 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); - SkeletonNode SkeletonStorage; + while (!jointIt.isDone()) + { + m_Hierarchy.push_back(jointIt.item()); + + MFnDependencyNode depNode(jointIt.item()); + 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); + + unsigned int startKeyFrameIndex = jointAnim.findClosest(MTime(startFrame, MTime::kNTSCField), &tmp); + + if (tmp == MStatus::kFailure) + MGlobal::displayInfo(MString() + "Fail :c"); + + if (startFrame * oneDivSixty <= jointAnim.time(startKeyFrameIndex).value() && jointAnim.time(startKeyFrameIndex).value() <= endFrame * oneDivSixty) { + animatedJoints.push_back(jointIt.item()); + i = 9; + break; + } + + unsigned int endKeyFrameIndex = jointAnim.findClosest(MTime(endFrame, MTime::kNTSCField)); + MGlobal::displayInfo(MString() + startKeyFrameIndex + " " + endKeyFrameIndex); + + if (startFrame * oneDivSixty <= jointAnim.time(endKeyFrameIndex).value() && jointAnim.time(endKeyFrameIndex).value() <= endFrame * oneDivSixty || endKeyFrameIndex - startKeyFrameIndex > 0) { + 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 != 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"); + } + } + } + } + + jointIt.next(); + } + + int currentFrame = startFrame; + while (currentFrame != endFrame) { + Animation::Keyframe thisKeyFrame; + thisKeyFrame.Index = currentFrame - startFrame; + thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty; + + MAnimControl::setCurrentTime(MTime(currentFrame, MTime::kNTSCField)); + MTime time = MAnimControl::currentTime(); + + for (auto aJoint : animatedJoints){ + MFnTransform thisJoint(aJoint); + Animation::Keyframe::JointProperty joint; + + auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), thisJoint.object()); + if (it != m_Hierarchy.end()) { + joint.ID = it - m_Hierarchy.begin(); + } + else { + MGlobal::displayError(MString() + "Could not find joint ID for: " + thisJoint.name()); + } + + MMatrix Matrix = thisJoint.transformationMatrix(); + + double tmp[4]; + thisJoint.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]); + joint.Rotation[0] = tmp[0]; + joint.Rotation[1] = tmp[1]; + joint.Rotation[2] = tmp[2]; + joint.Rotation[3] = tmp[3]; + thisJoint.getTranslation(MSpace::kPreTransform).get(tmp); + joint.Position[0] = tmp[0]; + joint.Position[1] = tmp[1]; + joint.Position[2] = tmp[2]; + thisJoint.getScale(tmp); + joint.Scale[0] = tmp[0]; + joint.Scale[1] = tmp[1]; + joint.Scale[2] = tmp[2]; + + thisKeyFrame.JointProperties.push_back(joint); + } + returnData.Keyframes.push_back(thisKeyFrame); + currentFrame++; + } + return returnData; +} + +std::vector Skeleton::GetBindPoses() +{ + std::vector m_AllSkeletons; + std::vector m_Hierarchy; + + MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); + BindPoseSkeletonNode SkeletonStorage; while (!jointIt.isDone()) { - MFnTransform TransformNode(jointIt.currentItem()); - Joint NewJoint; + MFnTransform MayaJoint(jointIt.currentItem()); + BindPoseSkeletonNode::BindPoseJoint NewJoint; - if (MFnDependencyNode(TransformNode.parent(0)).name() == "world") { + if (MFnDependencyNode(MayaJoint.parent(0)).name() == "world") { if (SkeletonStorage.Joints.size() != 0) { m_AllSkeletons.push_back(SkeletonStorage); SkeletonStorage.Joints.clear(); SkeletonStorage.Name.clear(); } + SkeletonStorage.Name = std::string(MayaJoint.name().asChar()); + NewJoint.ParentID = -1; // This joint is root + } + else { + auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), MayaJoint.parent(0)); + if (it != m_Hierarchy.end()) { + NewJoint.ParentID = it - m_Hierarchy.begin(); + } + else { + MGlobal::displayError(MString() + "Could not find joint parent for: " + MayaJoint.name()); + } + } + m_Hierarchy.push_back(MayaJoint.object()); - SkeletonStorage.Name = TransformNode.name().asChar(); + MPlug BindPose = MayaJoint.findPlug("bindPose"); + MDataHandle DataHandle; + BindPose.getValue(DataHandle); + MFnMatrixData MartixFn(DataHandle.data()); + MMatrix Matrix = MartixFn.matrix(); - //NewJoint.ParentIndex = -1; // This joint is root + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j]; + } } - //NewJoint.Name = TransformNode.name().asChar(); - - MMatrix Matrix = TransformNode.transformationMatrix(); + NewJoint.Name = MayaJoint.name().asChar(); //double tmp[3]; //((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp); @@ -44,89 +236,7 @@ std::vector Skeleton::DoIt() //NewJoint.Translation[0] = tmp[0]; //NewJoint.Translation[1] = tmp[1]; //NewJoint.Translation[2] = tmp[2]; - - 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; -} - -std::vector Skeleton::GetBindPoses() -{ - std::vector m_AllSkeletons; - std::vector m_Hierarchy; - - MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); - BindPoseSkeletonNode SkeletonStorage; - - while (!jointIt.isDone()) { - MFnTransform MayaJoint(jointIt.currentItem()); - - if (MFnDependencyNode(MayaJoint.parent(0)).name() == "world") { - if (SkeletonStorage.Joints.size() != 0) { - m_AllSkeletons.push_back(SkeletonStorage); - - SkeletonStorage.Joints.clear(); - SkeletonStorage.Name.clear(); - SkeletonStorage.ParentIDs.clear(); - SkeletonStorage.Name.clear(); - } - - SkeletonStorage.Name = MayaJoint.name().asChar(); - SkeletonStorage.ParentIDs.push_back(-1); // This joint is root - } - else { - auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), MayaJoint.parent(0)); - if (it != m_Hierarchy.end()) { - SkeletonStorage.ParentIDs.push_back(it - m_Hierarchy.begin()); - } - else { - MGlobal::displayError(MString() + "Could not find joint parent for: " + MayaJoint.name()); - } - } - m_Hierarchy.push_back(MayaJoint.object()); - - Joint NewJoint; - - MPlug BindPose = MayaJoint.findPlug("bindPose"); - MDataHandle DataHandle; - BindPose.getValue(DataHandle); - MFnMatrixData MartixFn(DataHandle.data()); - MMatrix Matrix = MartixFn.matrix(); - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j]; - } - } - - /*double tmp[3]; - ((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp); - NewJoint.Rotation[0] = tmp[0]; - NewJoint.Rotation[1] = tmp[1]; - NewJoint.Rotation[2] = tmp[2]; - ((MTransformationMatrix)Matrix).getScale(tmp, MSpace::Space::kTransform); - NewJoint.Scale[0] = tmp[0]; - NewJoint.Scale[1] = tmp[1]; - NewJoint.Scale[2] = tmp[2]; - ((MTransformationMatrix)Matrix).getTranslation(MSpace::Space::kTransform).get(tmp); - NewJoint.Translation[0] = tmp[0]; - NewJoint.Translation[1] = tmp[1]; - NewJoint.Translation[2] = tmp[2];*/ - - SkeletonStorage.Joints.push_back(NewJoint); - SkeletonStorage.JointNames.push_back(MayaJoint.name().asChar()); - jointIt.next(); } diff --git a/tools/MayaExporter/MayaExporter/Skeleton.h b/tools/MayaExporter/MayaExporter/Skeleton.h index 2d363cf8..0b0c2a60 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.h +++ b/tools/MayaExporter/MayaExporter/Skeleton.h @@ -6,68 +6,81 @@ #include #include "MayaIncludes.h" #include "OutputData.h" -class Joint : public OutputData{ + +class Animation : public OutputData { public: - //Joint() : OutputData((Joint)*this) - //{}; - //int ParentIndex; - //std::array Rotation; - //std::array Translation; - //std::array Scale; - //std::array, 4> OffsetMatrix; - float OffsetMatrix[4][4]; - - virtual void WriteBinary(std::ostream& out) + struct Keyframe { - out.write((char*)OffsetMatrix, 4 * 4 * sizeof(float)); - } - - virtual void WriteASCII(std::ostream& out) const - { - for (int i = 0; i < 4; i++) + struct JointProperty { - for (int k = 0; k < 4; k++) - out << this->OffsetMatrix[i][k] << " "; - out << endl; - } - }; -}; + int ID; + float Position[3]; + float Rotation[4]; + float Scale[3]; + }; + + int Index; + double Time; + std::vector JointProperties; + }; -class SkeletonNode : public OutputData { -public: std::string Name; - std::vector Joints; + double Duration; + std::vector Keyframes; virtual void WriteBinary(std::ostream& out) { - out.write(Name.c_str(), Name.size()); - for (auto aJoint : Joints) - { - aJoint.WriteBinary(out); + out.write(Name.c_str(), Name.size() + 1); + out.write((char*)&Duration, sizeof(double)); + for (auto aKeyframe : Keyframes) { + out.write((char*)&aKeyframe.Index, sizeof(int)); + out.write((char*)&aKeyframe.Time, sizeof(double)); + for (auto aJoint : aKeyframe.JointProperties) { + out.write((char*)&aJoint.ID, sizeof(int)); + out.write((char*)aJoint.Position, sizeof(float) * 3); + out.write((char*)aJoint.Rotation, sizeof(float) * 4); + out.write((char*)aJoint.Scale, sizeof(float) * 3); + } } } + virtual void WriteASCII(std::ostream& out) const { - out << "Skeleton: " << Name << endl; - for (auto aJoint : Joints) - { - aJoint.WriteASCII(out); + out << "Animation Name: " << Name << endl; + out << "Duration: " << Duration << endl; + for (auto aKeyframe : Keyframes) { + out << "Frame: " << aKeyframe.Index << endl; + out << "Time: " << aKeyframe.Time << endl; + for (auto aJoint : aKeyframe.JointProperties) { + out << "Joint ID: " << aJoint.ID << endl; + out << aJoint.Position[0] << " " << aJoint.Position[1] << " " << aJoint.Position[2] << endl; + out << aJoint.Rotation[0] << " " << aJoint.Rotation[1] << " " << aJoint.Rotation[2] << " " << aJoint.Rotation[3] << endl; + out << aJoint.Scale[0] << " " << aJoint.Scale[1] << " " << aJoint.Scale[2] << endl; + } } - }; + + } }; -class BindPoseSkeletonNode : public SkeletonNode { +class BindPoseSkeletonNode : public OutputData { public: - std::vector ParentIDs; - std::vector JointNames; + struct BindPoseJoint + { + int ParentID; + std::string Name; + float OffsetMatrix[4][4]; + }; + + std::string Name; + std::vector Joints; virtual void WriteBinary(std::ostream& out) { - out.write(Name.c_str(), Name.size()); - for (int i = 0; i < Joints.size(); i++) - { - out.write((char*)&ParentIDs[i],sizeof(int)); - Joints[i].WriteBinary(out); - out.write(JointNames[i].c_str(), JointNames[i].size()); + out.write(Name.c_str(), Name.size() + 1); + for (auto Joint:Joints) + { + out.write(Joint.Name.c_str(), Joint.Name.size() + 1); + out.write((char*)&Joint.OffsetMatrix, sizeof(float) * 4 * 4); + out.write((char*)&Joint.ParentID, sizeof(int)); } } @@ -75,18 +88,24 @@ public: virtual void WriteASCII(std::ostream& out) const { out << "Bind Pose: " << Name << endl; - for (int i = 0; i < Joints.size(); i++) + for (auto Joint : Joints) { - out << ParentIDs[i] << endl; - Joints[i].WriteASCII(out); - out << JointNames[i] << endl; + out << Joint.Name << endl; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++){ + out << Joint.OffsetMatrix[i][j] << " "; + } + out << endl; + } + out << Joint.ParentID << endl; } }; }; class Skeleton { public: - std::vector DoIt(); + //std::vector DoIt(); + Animation GetAnimData(std::string animationName, int startFrame, int endFrame); std::vector GetBindPoses(); private: }; From 7b62dc19bf0e5f85ec1dc7dc2f3d69a0d18d22ef Mon Sep 17 00:00:00 2001 From: antc13 Date: Tue, 12 Jan 2016 15:39:29 +0100 Subject: [PATCH 13/28] Spitting out Meshes & Animation Data to file. --- .../MayaExporter/MayaExporter.vcxproj | 1 + .../MayaExporter/MayaExporter/MayaIncludes.h | 5 + tools/MayaExporter/MayaExporter/Menu.cpp | 46 +++-- tools/MayaExporter/MayaExporter/Menu.h | 1 + tools/MayaExporter/MayaExporter/Mesh.cpp | 193 +++++++++++++----- tools/MayaExporter/MayaExporter/Mesh.h | 53 ++++- tools/MayaExporter/MayaExporter/WriteToFile.h | 16 +- 7 files changed, 242 insertions(+), 73 deletions(-) diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj index a9154ac7..701b39cf 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj @@ -140,6 +140,7 @@ MultiThreadedDLL true + Disabled Windows diff --git a/tools/MayaExporter/MayaExporter/MayaIncludes.h b/tools/MayaExporter/MayaExporter/MayaIncludes.h index 0e490208..66527470 100644 --- a/tools/MayaExporter/MayaExporter/MayaIncludes.h +++ b/tools/MayaExporter/MayaExporter/MayaIncludes.h @@ -37,6 +37,11 @@ #include #include #include +#include +#include +#include +#include +#include // Wrappers diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 77241cad..7e1e6cde 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -125,8 +125,7 @@ void Menu::ExportSelected(bool checked) MFnDependencyNode thisNode(object); cout << thisNode.name().asChar() << endl; - Mesh mesh; - mesh.GetMeshData(object); + GetMeshData(object); } if (m_ExportPath->text().isEmpty()) { cout << "Please select a folder." << endl; @@ -195,17 +194,32 @@ void Menu::RemoveClipClicked(bool) 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(); // Loop through all nodes in the scene - MItDependencyNodes it(MFn::kInvalid); + MItDependencyNodes it(MFn::kMesh); for (; !it.isDone(); it.next()) { MObject node = it.thisNode(); if (node.hasFn(MFn::kMesh)) { MFnDependencyNode thisNode(node); + MPlugArray connections; - cout << thisNode.name().asChar() << endl; - Mesh mesh; - mesh.GetMeshData(node); + 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; + + cout << thisNode.name().asChar() << endl; + MGlobal::displayInfo("EXPORT ALL FUNCTION: " + thisNode.name() + " " + thisNode.findPlug("inMesh").asMObject().apiTypeStr()); + GetMeshData(node); } } if (m_ExportPath->text().isEmpty()) { @@ -215,12 +229,9 @@ void Menu::ExportAll(bool) cout << m_ExportPath->text().toLocal8Bit().constData() << endl; } - m_File.ASCIIFilePath("C:/Users/Nickelodion/Desktop/coolASCII.txt"); - m_File.binaryFilePath("C:/Users/Nickelodion/Desktop/coolSoptunz.bin"); - if (m_ExportAnimationsButton->isChecked()) GetSkeletonData(); - + m_File.CloseFiles(); } void Menu::CancelClicked(bool) @@ -257,7 +268,19 @@ void Menu::Button3Clicked(bool) 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(); @@ -296,8 +319,6 @@ void Menu::GetSkeletonData() allAnimations.push_back(m_SkeletonHandler->GetAnimData(animationName, startFrame, endFrame)); } - m_File.OpenFiles(); - //print out all bind poses for (auto aBindPose : allBindPoses){ m_File.writeToFiles(&aBindPose); @@ -315,7 +336,6 @@ void Menu::GetSkeletonData() for (auto aAnimation : allAnimations) { m_File.writeToFiles(&aAnimation); } - m_File.CloseFiles(); } Menu::~Menu() diff --git a/tools/MayaExporter/MayaExporter/Menu.h b/tools/MayaExporter/MayaExporter/Menu.h index 0174cbc3..9f3492ab 100644 --- a/tools/MayaExporter/MayaExporter/Menu.h +++ b/tools/MayaExporter/MayaExporter/Menu.h @@ -46,6 +46,7 @@ public: Menu(QDialog* dialog); ~Menu(); + void GetMeshData(MObject object); void GetMaterialData(); void GetSkeletonData(); diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index 58a7fbe4..0ac66b33 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -7,21 +7,80 @@ Mesh::Mesh() { } +std::map Mesh::GetWeightData() +{ + map weightMap; -void Mesh::GetMeshData(MObject object) + MItDependencyNodes it(MFn::kSkinClusterFilter); + + while (!it.isDone()) { + + MObject object = it.item(); + MFnSkinCluster skinCluster(object); + MDagPathArray influences; + + unsigned int nrOfInfluences = skinCluster.influenceObjects(influences); + + unsigned int index; + index = skinCluster.indexForOutputConnection(0); + MDagPath skinPath; + skinCluster.getPathAtIndex(index, skinPath); + + MItGeometry geomIter(skinPath); + //for (unsigned int i = 0; i < nrOfInfluences; i++) { + // MGlobal::displayInfo(MString() + " Influence object name: " + influences[i].partialPathName().asChar()); + //} + WeightInfo weightInfo; + + while (!geomIter.isDone()) { + MObject comp = geomIter.component(); + MFloatArray weights; + unsigned int influenceCount; + skinCluster.getWeights(skinPath, comp, weights, influenceCount); + MFnDependencyNode test(comp); + + unsigned int nrOfWeights = 0; + + for (unsigned int j = 0; j < weights.length() && nrOfWeights != 4; j++) { + if (weights[j] > 0.00001) { + weightInfo.BoneWeights[nrOfWeights] = weights[j]; + weightInfo.BoneIndices[nrOfWeights] = j; + nrOfWeights++; + } + } + + float totalWeight = 0.0f; + for (unsigned int i = 0; i < 4; i++) { + totalWeight += weightInfo.BoneWeights[i]; + } + for (unsigned int i = 0; i < 4; i++) { + weightInfo.BoneWeights[i] /= totalWeight; + } + weightMap[geomIter.index()] = weightInfo; + + + for (unsigned int k = 0; k!=nrOfWeights; k++) { + //MGlobal::displayInfo(MString() + "influence: " + weightInfo.BoneIndices[k] + " weight: " + weightInfo.BoneWeights[k]); + } + geomIter.next(); + + + } + + it.next(); + } + return weightMap; +} + +void Mesh::GetMeshData(MObject object, std::vector& vertexList, std::vector& indexList) { // In here, we retrieve triangulated polygons from the mesh MFnMesh mesh(object); - - map> vertexToIndex; - - vector verticesData; - vectorindexArray; + map> vertexToIndex;; MIntArray intdexOffsetVertexCount, vertices, triangleList; MPointArray dummy; - - UINT vertexIndex; + unsigned int vertexIndex; MVector normal; MPoint pos; float2 UV; @@ -31,62 +90,92 @@ void Mesh::GetMeshData(MObject object) MFloatVectorArray biTangents; MFloatVectorArray biNormals; + std::map vertexWeights = GetWeightData(); + mesh.getTangents(biTangents, MSpace::kObject, NULL); mesh.getBinormals(biNormals, MSpace::kObject, NULL); MItMeshFaceVertex faceVert(object); + int intDummy = 0; - for (MItMeshPolygon meshPolyIter(object); !meshPolyIter.isDone(); meshPolyIter.next()) { - vector localVertexToGlobalIndex; - meshPolyIter.getVertices(vertices); - meshPolyIter.getTriangles(dummy, triangleList); - UINT indexOffset = verticesData.size(); - //MGlobal::displayInfo("Befor Second Loop"); - for (UINT i = 0; i < vertices.length(); i++) { - faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); - //MGlobal::displayInfo("In Second Loop"); - faceVert.position().get(thisVertex.Pos); - faceVert.getNormal(normal); - thisVertex.Normal[0] = normal[0]; - thisVertex.Normal[1] = normal[1]; - thisVertex.Normal[2] = normal[2]; + for (MItMeshPolygon meshPolyIter(object); !meshPolyIter.isDone(); meshPolyIter.next()) { - MFloatVector biTangent = biTangents[faceVert.tangentId()]; - //MVector tmp = faceVert.getTangent(MSpace::kObject, NULL); - //tmp.get(biTangent); - thisVertex.BiTangent[0] = biTangent[0]; - thisVertex.BiTangent[1] = biTangent[1]; - thisVertex.BiTangent[2] = biTangent[2]; + vector localVertexToGlobalIndex; + unsigned int indexOffset = vertexList.size(); - MFloatVector biNormal = biNormals[faceVert.tangentId()]; - //faceVert.getBinormal().get(biNormal); - thisVertex.BiNormal[0] = biNormal[0]; - thisVertex.BiNormal[1] = biNormal[1]; - thisVertex.BiNormal[2] = biNormal[2]; + 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); + faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); + //MGlobal::displayInfo("In Second Loop"); + faceVert.position().get(thisVertex.Pos); + faceVert.getNormal(normal); + thisVertex.Normal[0] = normal[0]; + thisVertex.Normal[1] = normal[1]; + thisVertex.Normal[2] = normal[2]; - faceVert.getUV(UV); - thisVertex.Uv[0] = UV[0]; - thisVertex.Uv[1] = UV[1]; + MFloatVector biTangent = biTangents[faceVert.tangentId()]; + //MVector tmp = faceVert.getTangent(MSpace::kObject, NULL); + //tmp.get(biTangent); + thisVertex.BiTangent[0] = biTangent[0]; + thisVertex.BiTangent[1] = biTangent[1]; + thisVertex.BiTangent[2] = biTangent[2]; - verticesData.push_back(thisVertex); - localVertexToGlobalIndex.push_back(vertexIndex); + MFloatVector biNormal = biNormals[faceVert.tangentId()]; + //faceVert.getBinormal().get(biNormal); + thisVertex.BiNormal[0] = biNormal[0]; + thisVertex.BiNormal[1] = biNormal[1]; + thisVertex.BiNormal[2] = biNormal[2]; - //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 << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl; - //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"); + faceVert.getUV(UV); + thisVertex.Uv[0] = UV[0]; + thisVertex.Uv[1] = UV[1]; - //for (UINT i = 0; i < triangleList.length(); i++) { - // UINT k = 0; - // while (localVertexToGlobalIndex[k] != triangleList[i]) - // k++; - // indexArray.push_back(indexOffset + k); - //} - } + thisVertex.BoneIndices[0] = vertexWeights[faceVert.vertId()].BoneIndices[0]; + thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1]; + thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2]; + thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3]; + + thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0]; + thisVertex.BoneWeights[1] = vertexWeights[faceVert.vertId()].BoneWeights[1]; + thisVertex.BoneWeights[2] = vertexWeights[faceVert.vertId()].BoneWeights[2]; + thisVertex.BoneWeights[3] = vertexWeights[faceVert.vertId()].BoneWeights[3]; + + std::vector::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex); + + if (it != vertexList.end()) { + localVertexToGlobalIndex.push_back(vertexIndex); + } else { + localVertexToGlobalIndex.push_back(vertexIndex); + vertexList.push_back(thisVertex); + } + + //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 << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl; + //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); + } + } + } } Mesh::~Mesh() diff --git a/tools/MayaExporter/MayaExporter/Mesh.h b/tools/MayaExporter/MayaExporter/Mesh.h index 00b88654..6fab0536 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.h +++ b/tools/MayaExporter/MayaExporter/Mesh.h @@ -16,21 +16,62 @@ public: float BiNormal[3]; float BiTangent[3]; float Uv[2]; + float BoneIndices[4]; + float BoneWeights[4]; - virtual void WriteBinary(std::ostream& out) { + virtual void WriteBinary(std::ostream& out) + { + out.write((char*)&Pos, sizeof(float) * 3); + out.write((char*)&Normal, sizeof(float) * 3); + out.write((char*)&BiNormal, sizeof(float) * 3); + out.write((char*)&BiTangent, sizeof(float) * 3); + out.write((char*)&Uv, sizeof(float) * 2); + out.write((char*)&BoneIndices, sizeof(float) * 4); + out.write((char*)&BoneWeights, sizeof(float) * 4); + } - } - virtual void WriteASCII(std::ostream& out) const { + 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; + out << BiTangent[0] << " " << BiTangent[1] << " " << BiTangent[2] << endl; + out << Uv[0] << " " << Uv[1] << endl; + out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl; + out << BoneWeights[0] << " " << BoneWeights[1] << " " << BoneWeights[2] << " " << BoneWeights[3] << endl; - } + } + bool operator==(const VertexLayout& right) + { + return + this->Pos[0] == right.Pos[0] && this->Pos[1] == right.Pos[1] && this->Pos[2] == right.Pos[2] && + this->Normal[0] == right.Normal[0] && this->Normal[1] == right.Normal[1] && this->Normal[2] == right.Normal[2] && + this->BiNormal[0] == right.BiNormal[0] && this->BiNormal[1] == right.BiNormal[1] && this->BiNormal[2] == right.BiNormal[2] && + this->BiTangent[0] == right.BiTangent[0] && this->BiTangent[1] == right.BiTangent[1] && this->BiTangent[2] == right.BiTangent[2] && + this->Uv[0] == right.Uv[0] && this->Uv[1] == right.Uv[1] && + this->BoneIndices[0] == right.BoneIndices[0] && this->BoneIndices[1] == right.BoneIndices[1] && this->BoneIndices[2] == right.BoneIndices[2] && this->BoneIndices[3] == right.BoneIndices[3] && + this->BoneWeights[0] == right.BoneWeights[0] && this->BoneWeights[1] == right.BoneWeights[1] && this->BoneWeights[2] == right.BoneWeights[2] && this->BoneWeights[3] == right.BoneWeights[3] + ; + } }; + + + class Mesh { public: Mesh(); - void GetMeshData(MObject Object); - ~Mesh(); + void GetMeshData(MObject Object, std::vector& vertexList, std::vector& indexList); + ~Mesh(); +private: + struct WeightInfo { + float BoneIndices[4] = { 0 }; + float BoneWeights[4] = { 0 }; + }; + std::map GetWeightData(); + }; #endif \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/WriteToFile.h b/tools/MayaExporter/MayaExporter/WriteToFile.h index f0c066d4..3d6cc078 100644 --- a/tools/MayaExporter/MayaExporter/WriteToFile.h +++ b/tools/MayaExporter/MayaExporter/WriteToFile.h @@ -20,20 +20,32 @@ public: MGlobal::displayInfo("WriteToFile::writeToFiles()"); if (ASCIIFile.is_open()) { - MGlobal::displayInfo("Writing to ASCIIfile"); for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++) ASCIIFile << toWrite[i] << endl; } if (binFile.is_open()) { - MGlobal::displayInfo("Writing to binaryfile"); for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++) toWrite[i].WriteBinary(binFile); } } + void writeToFiles(unsigned int* toWrite, unsigned int numOfElementToWrite = 1, unsigned int startIndex = 0) + { + MGlobal::displayInfo("WriteToFile::writeToFiles()"); + 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)); + } + + } + void OpenFiles(); void CloseFiles(); From 24486c314dffcdf0294682cc3da0e6be1f559c56 Mon Sep 17 00:00:00 2001 From: antc13 Date: Wed, 13 Jan 2016 14:03:58 +0100 Subject: [PATCH 14/28] 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)); } } From 8437b9c734a72fee32bd79d9a59b8db345d43ff2 Mon Sep 17 00:00:00 2001 From: antc13 Date: Fri, 15 Jan 2016 17:58:26 +0100 Subject: [PATCH 15/28] Commit for Pull --- include/Engine/Collision/Collision.h | 2 +- include/Engine/Rendering/Model.h | 2 +- .../{RawModel.h => RawModelAssimp.h} | 18 ++--- include/Engine/Rendering/RawModelCustom.h | 68 +++++++++++++++++++ src/Engine/Rendering/Model.cpp | 10 +-- .../{RawModel.cpp => RawModelAssimp.cpp} | 22 ++---- src/Engine/Rendering/RawModelCustom.cpp | 67 ++++++++++++++++++ tools/MayaExporter/MayaExporter/Mesh.cpp | 12 ++-- tools/MayaExporter/MayaExporter/Mesh.h | 8 +-- 9 files changed, 158 insertions(+), 51 deletions(-) rename include/Engine/Rendering/{RawModel.h => RawModelAssimp.h} (79%) create mode 100644 include/Engine/Rendering/RawModelCustom.h rename src/Engine/Rendering/{RawModel.cpp => RawModelAssimp.cpp} (92%) create mode 100644 src/Engine/Rendering/RawModelCustom.cpp diff --git a/include/Engine/Collision/Collision.h b/include/Engine/Collision/Collision.h index 714cee3f..3ac43baf 100644 --- a/include/Engine/Collision/Collision.h +++ b/include/Engine/Collision/Collision.h @@ -9,7 +9,7 @@ #include "Core/Ray.h" #include "Core/AABB.h" -#include "Engine/Rendering/RawModel.h" +#include "Engine/Rendering/RawModelAssimp.h" #include "Core/Entity.h" class World; diff --git a/include/Engine/Rendering/Model.h b/include/Engine/Rendering/Model.h index 9cc145af..228e7acf 100644 --- a/include/Engine/Rendering/Model.h +++ b/include/Engine/Rendering/Model.h @@ -1,7 +1,7 @@ #ifndef Model_h__ #define Model_h__ -#include "RawModel.h" +#include "RawModelAssimp.h" #include "../OpenGL.h" class Model : public RawModel diff --git a/include/Engine/Rendering/RawModel.h b/include/Engine/Rendering/RawModelAssimp.h similarity index 79% rename from include/Engine/Rendering/RawModel.h rename to include/Engine/Rendering/RawModelAssimp.h index c8226168..5c96d946 100644 --- a/include/Engine/Rendering/RawModel.h +++ b/include/Engine/Rendering/RawModelAssimp.h @@ -1,5 +1,5 @@ -#ifndef RawModel_h__ -#define RawModel_h__ +#ifndef RawModelAssimp_h__ +#define RawModelAssimp_h__ #include #include @@ -23,7 +23,7 @@ class RawModel : public Resource friend class ResourceManager; protected: - RawModel(std::string fileName); + RawModel(std::string fileName); public: ~RawModel(); @@ -33,14 +33,10 @@ public: glm::vec3 Position; glm::vec3 Normal; glm::vec3 Tangent; - glm::vec3 BiTangent; + glm::vec3 BiNormal; glm::vec2 TextureCoords; - glm::vec4 DiffuseVertexColor; - glm::vec4 SpecularVertexColor; - glm::vec4 BoneIndices1; - glm::vec4 BoneIndices2; - glm::vec4 BoneWeights1; - glm::vec4 BoneWeights2; + glm::vec4 BoneIndices; + glm::vec4 BoneWeights; }; struct MaterialGroup @@ -64,8 +60,6 @@ private: std::vector BoneIndices; std::vector BoneWeights; std::vector Normals; - std::vector DiffuseVertexColor; - std::vector SpecularVertexColor; std::vector TangentNormals; std::vector BiTangentNormals; std::vector TextureCoords; diff --git a/include/Engine/Rendering/RawModelCustom.h b/include/Engine/Rendering/RawModelCustom.h new file mode 100644 index 00000000..c6e97242 --- /dev/null +++ b/include/Engine/Rendering/RawModelCustom.h @@ -0,0 +1,68 @@ +#ifndef RawModelCustom_h__ +#define RawModelCustom_h__ + +#include +#include +#include +#include +#include + +#include + +#include "../Common.h" +#include "../GLM.h" +#include "../Core/ResourceManager.h" +#include "Texture.h" +#include "Skeleton.h" + +#include "boost\endian\buffers.hpp" + +class RawModel : public Resource +{ + friend class ResourceManager; + +protected: + RawModel(std::string fileName); + +public: + ~RawModel(); + + struct Vertex + { + glm::vec3 Position; + glm::vec3 Normal; + glm::vec3 Tangent; + glm::vec3 BiNormal; + glm::vec2 TextureCoords; + glm::vec4 BoneIndices; + glm::vec4 BoneWeights; + }; + + struct MaterialGroup + { + float Shininess; + std::shared_ptr<::Texture> Texture; + std::shared_ptr<::Texture> NormalMap; + std::shared_ptr<::Texture> SpecularMap; + unsigned int StartIndex; + unsigned int EndIndex; + }; + + std::vector TextureGroups; + + std::vector m_Vertices; + std::vector m_Indices; + Skeleton* m_Skeleton = nullptr; + glm::mat4 m_Matrix; + +private: + + bool ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize); + bool ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize); + bool ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); + bool ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); + + //void CreateSkeleton(std::vector> &boneInfo, std::map &boneNameMapping, aiNode* node, int parentID); +}; + +#endif diff --git a/src/Engine/Rendering/Model.cpp b/src/Engine/Rendering/Model.cpp index f346d9e1..c7b5667b 100644 --- a/src/Engine/Rendering/Model.cpp +++ b/src/Engine/Rendering/Model.cpp @@ -18,7 +18,7 @@ Model::Model(std::string fileName) GLERROR("GLEW: BufferFail4"); glBindBuffer(GL_ARRAY_BUFFER, buffer); - std::vector structSizes = { 3, 3, 3, 3, 2, 4, 4, 4, 4, 4, 4 }; + std::vector structSizes = { 3, 3, 3, 3, 2, 4, 4 }; int stride = 0; for (int size : structSizes) { stride += size; @@ -34,10 +34,6 @@ Model::Model(std::string fileName) glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; - glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; - glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; - glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; - glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; } GLERROR("GLEW: BufferFail5"); @@ -48,10 +44,6 @@ Model::Model(std::string fileName) glEnableVertexAttribArray(4); glEnableVertexAttribArray(5); glEnableVertexAttribArray(6); - glEnableVertexAttribArray(7); - glEnableVertexAttribArray(8); - glEnableVertexAttribArray(9); - glEnableVertexAttribArray(10); GLERROR("GLEW: BufferFail5"); //CreateBuffers(); diff --git a/src/Engine/Rendering/RawModel.cpp b/src/Engine/Rendering/RawModelAssimp.cpp similarity index 92% rename from src/Engine/Rendering/RawModel.cpp rename to src/Engine/Rendering/RawModelAssimp.cpp index 95a75a15..68cbb23e 100644 --- a/src/Engine/Rendering/RawModel.cpp +++ b/src/Engine/Rendering/RawModelAssimp.cpp @@ -1,4 +1,4 @@ -#include "Rendering/RawModel.h" +#include "Rendering/RawModelAssimp.h" RawModel::RawModel(std::string fileName) { @@ -38,7 +38,7 @@ RawModel::RawModel(std::string fileName) //LOG_DEBUG("Index count %i", numIndices); //LOG_DEBUG("Model has %i embedded textures", scene->mNumTextures); - + std::vector> boneInfo; std::map boneNameMapping; @@ -75,17 +75,6 @@ RawModel::RawModel(std::string fileName) desc.TextureCoords = glm::vec2(uv.x, uv.y); } - // Material diffuse color - aiColor3D diffuse; - material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse); - float opacity; - material->Get(AI_MATKEY_OPACITY, opacity); - desc.DiffuseVertexColor = glm::vec4(diffuse.r, diffuse.g, diffuse.b, opacity); - // Material specular color - aiColor3D specular; - material->Get(AI_MATKEY_COLOR_SPECULAR, specular); - desc.SpecularVertexColor = glm::vec4(specular.r, specular.g, specular.b, 1.f); - m_Vertices.push_back(desc); } @@ -125,7 +114,7 @@ RawModel::RawModel(std::string fileName) } for (auto& vertex : m_Vertices) { vertex.Tangent = glm::normalize(vertex.Tangent); - vertex.BiTangent = glm::normalize(glm::cross(vertex.Tangent, glm::normalize(vertex.Normal))); + vertex.BiNormal = glm::normalize(glm::cross(vertex.Tangent, glm::normalize(vertex.Normal))); } // Material info @@ -203,10 +192,7 @@ RawModel::RawModel(std::string fileName) LOG_WARNING("Vertex weights (%i) greater than max weights per vertex (%i)", weights.size(), maxWeights); } for (int weightIndex = 0; weightIndex < weights.size() && weightIndex < maxWeights && weightIndex < 4; ++weightIndex) { - std::tie(desc.BoneIndices1[weightIndex], desc.BoneWeights1[weightIndex]) = weights[weightIndex]; - } - for (int weightIndex = 4; weightIndex < weights.size() && weightIndex < maxWeights && weightIndex < 8; ++weightIndex) { - std::tie(desc.BoneIndices2[weightIndex - 4], desc.BoneWeights2[weightIndex - 4]) = weights[weightIndex]; + std::tie(desc.BoneIndices[weightIndex], desc.BoneWeights[weightIndex]) = weights[weightIndex]; } } diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp new file mode 100644 index 00000000..a5493bd8 --- /dev/null +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -0,0 +1,67 @@ +#include "Rendering\RawModelCustom.h" + +RawModel::RawModel(std::string fileName) +{ + boost::endian::big_int16_buf_t* test; + int16_t tal; + test = &(boost::endian::big_int16_buf_t)tal; + + char* fileData; + std::ifstream in(fileName.c_str(), std::ios_base::binary | std::ios_base::ate); + + if (!in.is_open()) + LOG_ERROR("Failed to load custom binary model \"%s\"", fileName.c_str()); + + unsigned int fileByteSize = in.tellg(); + in.seekg(0, std::ios_base::beg); + + fileData = new char[fileByteSize]; + in.read(fileData, fileByteSize); + in.close(); + + unsigned int offset = 0; + ReadMeshFileHeader(offset, fileData, fileByteSize); + ReadMesh(offset, fileData, fileByteSize); + +} + +bool RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +{ +#ifdef BOOST_LITTLE_ENDIAN + m_Vertices.resize(*fileData); + offset += sizeof(unsigned int); + m_Indices.resize(*(fileData + offset)); + offset += sizeof(unsigned int); +#else +#endif +} + +bool RawModel::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +{ + ReadVertices(offset, fileData, fileByteSize); + ReadIndices(offset, fileData, fileByteSize); +} + +bool RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +{ +#ifdef BOOST_LITTLE_ENDIAN + memcpy(&m_Vertices[0], fileData, m_Vertices.size() * sizeof(Vertex)); + offset += m_Vertices.size() * sizeof(Vertex); +#else +#endif +} + +bool RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +{ +#ifdef BOOST_LITTLE_ENDIAN + memcpy(&m_Indices[0], fileData, m_Indices.size() * sizeof(unsigned int)); + offset += m_Indices.size() * sizeof(unsigned int); +#else +#endif +} + + +RawModel::~RawModel() +{ + +} \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index d9b47875..24e661ac 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -92,12 +92,12 @@ Mesh MeshClass::GetMeshData(MObject object) double biTangent[3]; double biNormal[3]; VertexLayout thisVertex; - MFloatVectorArray biTangents; + MFloatVectorArray Tangents; MFloatVectorArray biNormals; std::map vertexWeights = GetWeightData(); - mesh.getTangents(biTangents, MSpace::kObject, NULL); + mesh.getTangents(Tangents, MSpace::kObject, NULL); mesh.getBinormals(biNormals, MSpace::kObject, NULL); MItMeshFaceVertex faceVert(object); @@ -123,12 +123,12 @@ Mesh MeshClass::GetMeshData(MObject object) thisVertex.Normal[1] = normal[1]; thisVertex.Normal[2] = normal[2]; - MFloatVector biTangent = biTangents[faceVert.tangentId()]; + MFloatVector Tangent = Tangents[faceVert.tangentId()]; //MVector tmp = faceVert.getTangent(MSpace::kObject, NULL); //tmp.get(biTangent); - thisVertex.BiTangent[0] = biTangent[0]; - thisVertex.BiTangent[1] = biTangent[1]; - thisVertex.BiTangent[2] = biTangent[2]; + thisVertex.Tangent[0] = Tangent[0]; + thisVertex.Tangent[1] = Tangent[1]; + thisVertex.Tangent[2] = Tangent[2]; MFloatVector biNormal = biNormals[faceVert.tangentId()]; //faceVert.getBinormal().get(biNormal); diff --git a/tools/MayaExporter/MayaExporter/Mesh.h b/tools/MayaExporter/MayaExporter/Mesh.h index c9445e4e..ff7cc3b0 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.h +++ b/tools/MayaExporter/MayaExporter/Mesh.h @@ -12,8 +12,8 @@ class VertexLayout : public OutputData public: float Pos[3]; float Normal[3]; + float Tangent[3]; float BiNormal[3]; - float BiTangent[3]; float Uv[2]; float BoneIndices[4]; float BoneWeights[4]; @@ -22,7 +22,7 @@ public: { out.write((char*)&Pos, sizeof(float) * 3); out.write((char*)&Normal, sizeof(float) * 3); - out.write((char*)&BiNormal, sizeof(float) * 3); + out.write((char*)&Tangent, sizeof(float) * 3); out.write((char*)&BiTangent, sizeof(float) * 3); out.write((char*)&Uv, sizeof(float) * 2); out.write((char*)&BoneIndices, sizeof(float) * 4); @@ -33,7 +33,7 @@ public: { out << Pos[0] << " " << Pos[1] << " " << Pos[2] << endl; out << Normal[0] << " " << Normal[1] << " " << Normal[2] << endl; - out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl; + out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl; out << BiTangent[0] << " " << BiTangent[1] << " " << BiTangent[2] << endl; out << Uv[0] << " " << Uv[1] << endl; out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl; @@ -45,7 +45,7 @@ public: return this->Pos[0] == right.Pos[0] && this->Pos[1] == right.Pos[1] && this->Pos[2] == right.Pos[2] && this->Normal[0] == right.Normal[0] && this->Normal[1] == right.Normal[1] && this->Normal[2] == right.Normal[2] && - this->BiNormal[0] == right.BiNormal[0] && this->BiNormal[1] == right.BiNormal[1] && this->BiNormal[2] == right.BiNormal[2] && + this->Tangent[0] == right.Tangent[0] && this->Tangent[1] == right.Tangent[1] && this->Tangent[2] == right.Tangent[2] && this->BiTangent[0] == right.BiTangent[0] && this->BiTangent[1] == right.BiTangent[1] && this->BiTangent[2] == right.BiTangent[2] && this->Uv[0] == right.Uv[0] && this->Uv[1] == right.Uv[1] && this->BoneIndices[0] == right.BoneIndices[0] && this->BoneIndices[1] == right.BoneIndices[1] && this->BoneIndices[2] == right.BoneIndices[2] && this->BoneIndices[3] == right.BoneIndices[3] && From 2a3009212ae9b921a777941dfb8426c9c1349e8e Mon Sep 17 00:00:00 2001 From: antc13 Date: Mon, 18 Jan 2016 19:37:55 +0100 Subject: [PATCH 16/28] Importing custom mesh without material. --- include/Engine/Collision/Collision.h | 3 +- include/Engine/Core/ResourceManager.h | 8 +- include/Engine/Rendering/Model.h | 4 +- include/Engine/Rendering/RawModelCustom.h | 25 ++- resources/Schema/Entities/Model.xml | 30 +++ resources/Shaders/BasicForward.vert.glsl | 11 +- resources/Shaders/ForwardPlus.frag.glsl | 5 +- resources/Shaders/ForwardPlus.vert.glsl | 10 +- src/Engine/Editor/EditorSystem.cpp | 26 +-- src/Engine/Rendering/RawModelAssimp.cpp | 3 - src/Engine/Rendering/RawModelCustom.cpp | 54 +++-- src/Engine/Rendering/RenderSystem.cpp | 4 +- src/Engine/Rendering/Renderer.cpp | 4 +- tools/MayaExporter/MayaExporter/Export.cpp | 30 ++- tools/MayaExporter/MayaExporter/Export.h | 6 +- tools/MayaExporter/MayaExporter/Material.cpp | 85 +++----- tools/MayaExporter/MayaExporter/Material.h | 69 ++++++- tools/MayaExporter/MayaExporter/Menu.cpp | 25 ++- tools/MayaExporter/MayaExporter/Menu.h | 3 +- tools/MayaExporter/MayaExporter/Mesh.cpp | 206 +++++++++++++------ tools/MayaExporter/MayaExporter/Mesh.h | 39 ++-- 21 files changed, 402 insertions(+), 248 deletions(-) create mode 100644 resources/Schema/Entities/Model.xml diff --git a/include/Engine/Collision/Collision.h b/include/Engine/Collision/Collision.h index 98ca1fb0..9777614f 100644 --- a/include/Engine/Collision/Collision.h +++ b/include/Engine/Collision/Collision.h @@ -9,7 +9,8 @@ #include "../Core/Ray.h" #include "../Core/AABB.h" -#include "Engine/Rendering/RawModelAssimp.h" +//#include "Engine/Rendering/RawModelAssimp.h" +#include "Engine/Rendering/RawModelCustom.h" #include "../Core/Entity.h" class World; diff --git a/include/Engine/Core/ResourceManager.h b/include/Engine/Core/ResourceManager.h index 15a551e7..10529819 100644 --- a/include/Engine/Core/ResourceManager.h +++ b/include/Engine/Core/ResourceManager.h @@ -32,10 +32,10 @@ public: }; struct FailedLoadingException : public std::exception { - virtual const char* what() const throw() - { - return "Resource is failed to load."; - } + FailedLoadingException(char const* const _Message) + : std::exception(_Message) + { } + FailedLoadingException() :std::exception("Resource failed to load.") { }; }; // Pretend that this is a pure virtual function that you have to implement diff --git a/include/Engine/Rendering/Model.h b/include/Engine/Rendering/Model.h index e99347c9..f79cacd5 100644 --- a/include/Engine/Rendering/Model.h +++ b/include/Engine/Rendering/Model.h @@ -1,7 +1,7 @@ #ifndef Model_h__ #define Model_h__ -#include "RawModelAssimp.h" +#include "RawModelCustom.h" #include "../OpenGL.h" class Model : public ThreadUnsafeResource @@ -23,8 +23,6 @@ public: private: RawModel* m_RawModel; GLuint VertexBuffer; - GLuint DiffuseVertexColorBuffer; - GLuint SpecularVertexColorBuffer; GLuint NormalBuffer; GLuint TangentNormalsBuffer; GLuint BiTangentNormalsBuffer; diff --git a/include/Engine/Rendering/RawModelCustom.h b/include/Engine/Rendering/RawModelCustom.h index c6e97242..b5bf44cc 100644 --- a/include/Engine/Rendering/RawModelCustom.h +++ b/include/Engine/Rendering/RawModelCustom.h @@ -40,15 +40,22 @@ public: struct MaterialGroup { - float Shininess; - std::shared_ptr<::Texture> Texture; - std::shared_ptr<::Texture> NormalMap; - std::shared_ptr<::Texture> SpecularMap; + float SpecularExponent; + float ReflectionFactor; unsigned int StartIndex; unsigned int EndIndex; + //float Transparency; + std::string TexturePath; + std::shared_ptr<::Texture> Texture; + std::string NormalMapPath; + std::shared_ptr<::Texture> NormalMap; + std::string SpecularMapPath; + std::shared_ptr<::Texture> SpecularMap; + std::string IncandescenceMapPath; + std::shared_ptr<::Texture> IncandescenceMap; }; - std::vector TextureGroups; + std::vector MaterialGroups; std::vector m_Vertices; std::vector m_Indices; @@ -57,10 +64,10 @@ public: private: - bool ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize); - bool ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize); - bool ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); - bool ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); + void ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize); + void ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize); + void ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); + void ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); //void CreateSkeleton(std::vector> &boneInfo, std::map &boneNameMapping, aiNode* node, int parentID); }; diff --git a/resources/Schema/Entities/Model.xml b/resources/Schema/Entities/Model.xml new file mode 100644 index 00000000..e4e60e4f --- /dev/null +++ b/resources/Schema/Entities/Model.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + models/coolTriangle.mesh + + + + + + + + diff --git a/resources/Shaders/BasicForward.vert.glsl b/resources/Shaders/BasicForward.vert.glsl index 96f081f4..cb231e45 100644 --- a/resources/Shaders/BasicForward.vert.glsl +++ b/resources/Shaders/BasicForward.vert.glsl @@ -9,18 +9,14 @@ layout(location = 1) in vec3 Normal; layout(location = 2) in vec3 Tangent; layout(location = 3) in vec3 BiTangent; layout(location = 4) in vec2 TextureCoords; -layout(location = 5) in vec4 DiffuseVertexColor; -layout(location = 6) in vec4 SpecularVertexColor; -layout(location = 7) in vec4 BoneIndices1; -layout(location = 8) in vec4 BoneIndices2; -layout(location = 9) in vec4 BoneWeights1; -layout(location = 10) in vec4 BoneWeights2; +layout(location = 5) in vec4 BoneIndices; +layout(location = 6) in vec4 BoneWeights; + out VertexData{ vec3 Position; vec3 Normal; vec2 TextureCoordinate; - vec4 DiffuseColor; }Output; void main() @@ -30,5 +26,4 @@ void main() Output.Position = Position; Output.TextureCoordinate = TextureCoords; Output.Normal = Normal; - Output.DiffuseColor = DiffuseVertexColor; } \ No newline at end of file diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 3d5b9bfd..450d8929 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -44,7 +44,6 @@ in VertexData{ vec3 Position; vec3 Normal; vec2 TextureCoordinate; - vec4 DiffuseColor; }Input; out vec4 fragmentColor; @@ -114,7 +113,7 @@ void main() totalLighting.Specular += result.Specular; } - fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; + //fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; //fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color; //fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1); //fragmentColor = texel * Input.DiffuseColor * Color; @@ -126,7 +125,7 @@ void main() } - + fragmentColor = vec4(1.0f, 1.0f, 1.0f, 1.0f); } diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index 20ab9051..9ef20d5b 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -9,18 +9,13 @@ layout(location = 1) in vec3 Normal; layout(location = 2) in vec3 Tangent; layout(location = 3) in vec3 BiTangent; layout(location = 4) in vec2 TextureCoords; -layout(location = 5) in vec4 DiffuseVertexColor; -layout(location = 6) in vec4 SpecularVertexColor; -layout(location = 7) in vec4 BoneIndices1; -layout(location = 8) in vec4 BoneIndices2; -layout(location = 9) in vec4 BoneWeights1; -layout(location = 10) in vec4 BoneWeights2; +layout(location = 5) in vec4 BoneIndices; +layout(location = 6) in vec4 BoneWeights; out VertexData{ vec3 Position; vec3 Normal; vec2 TextureCoordinate; - vec4 DiffuseColor; }Output; void main() @@ -30,5 +25,4 @@ void main() Output.Position = Position; Output.TextureCoordinate = TextureCoords; Output.Normal = Normal; - Output.DiffuseColor = DiffuseVertexColor; } \ No newline at end of file diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 94e848c0..0f32a519 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -291,21 +291,21 @@ void EditorSystem::createWidget() m_WidgetPlaneX = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneX, "Transform"); m_World->AttachComponent(m_WidgetPlaneX, "Model"); - m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/WidgetPlaneX.obj"; + m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh"; m_WidgetY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetY, "Transform"); m_World->AttachComponent(m_WidgetY, "Model"); m_WidgetPlaneY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneY, "Transform"); m_World->AttachComponent(m_WidgetPlaneY, "Model"); - m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/WidgetPlaneY.obj"; + m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh"; m_WidgetZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetZ, "Transform"); m_World->AttachComponent(m_WidgetZ, "Model"); m_WidgetPlaneZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneZ, "Transform"); m_World->AttachComponent(m_WidgetPlaneZ, "Model"); - m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; + m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh"; m_WidgetOrigin = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetOrigin, "Transform"); m_World->AttachComponent(m_WidgetOrigin, "Model"); @@ -350,9 +350,9 @@ void EditorSystem::setWidgetMode(WidgetMode newMode) m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = false; if (newMode == WidgetMode::Translate) { - m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/TranslationWidgetX.obj"; - m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/TranslationWidgetY.obj"; - m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/TranslationWidgetZ.obj"; + //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/TranslationWidgetX.obj"; + //m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/TranslationWidgetY.obj"; + //m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/TranslationWidgetZ.obj"; // Temporarily disabled for local space until I can figure out what's wrong with the math if (m_WidgetSpace != WidgetSpace::Local) { m_World->GetComponent(m_WidgetPlaneX, "Model")["Visible"] = true; @@ -366,19 +366,19 @@ void EditorSystem::setWidgetMode(WidgetMode newMode) } } } else if (newMode == WidgetMode::Scale) { - m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/ScaleWidgetX.obj"; - m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/ScaleWidgetY.obj"; - m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/ScaleWidgetZ.obj"; + //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/ScaleWidgetX.obj"; + //m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/ScaleWidgetY.obj"; + //m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/ScaleWidgetZ.obj"; m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = true; - m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.obj"; + //m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.obj"; if (m_Selection != EntityID_Invalid) { auto selectionTransform = m_World->GetComponent(m_Selection, "Transform"); widgetTransform["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(m_World, m_Selection)); } } else if (newMode == WidgetMode::Rotate) { - m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.obj"; - m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/RotationWidgetY.obj"; - m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/RotationWidgetZ.obj"; + //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.obj"; + //m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/RotationWidgetY.obj"; + //m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/RotationWidgetZ.obj"; if (m_Selection != EntityID_Invalid) { auto selectionTransform = m_World->GetComponent(m_Selection, "Transform"); if (m_WidgetSpace == WidgetSpace::Local) { diff --git a/src/Engine/Rendering/RawModelAssimp.cpp b/src/Engine/Rendering/RawModelAssimp.cpp index 875bacbf..259eafc3 100644 --- a/src/Engine/Rendering/RawModelAssimp.cpp +++ b/src/Engine/Rendering/RawModelAssimp.cpp @@ -74,9 +74,6 @@ RawModel::RawModel(std::string fileName) auto uv = mesh->mTextureCoords[0][vertexIndex]; desc.TextureCoords = glm::vec2(uv.x, uv.y); } - - - desc.DiffuseVertexColor = glm::vec4(diffuse.r, diffuse.g, diffuse.b, opacity); m_Vertices.push_back(desc); } diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index a5493bd8..a165e1a4 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -2,16 +2,12 @@ RawModel::RawModel(std::string fileName) { - boost::endian::big_int16_buf_t* test; - int16_t tal; - test = &(boost::endian::big_int16_buf_t)tal; - char* fileData; std::ifstream in(fileName.c_str(), std::ios_base::binary | std::ios_base::ate); - if (!in.is_open()) - LOG_ERROR("Failed to load custom binary model \"%s\"", fileName.c_str()); - + if (!in.is_open()) { + throw Resource::FailedLoadingException("Open file failed"); + } unsigned int fileByteSize = in.tellg(); in.seekg(0, std::ios_base::beg); @@ -20,42 +16,64 @@ RawModel::RawModel(std::string fileName) in.close(); unsigned int offset = 0; - ReadMeshFileHeader(offset, fileData, fileByteSize); - ReadMesh(offset, fileData, fileByteSize); - + if (fileByteSize > 0) { + ReadMeshFileHeader(offset, fileData, fileByteSize); + ReadMesh(offset, fileData, fileByteSize); + } + delete fileData; + MaterialGroup mat; + mat.StartIndex = 0; + mat.EndIndex = m_Indices.size() - 1; + MaterialGroups.push_back(mat); } -bool RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +void RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN - m_Vertices.resize(*fileData); + unsigned int test; + test = *(unsigned int*)fileData; + unsigned int* test2; + test2 = (unsigned int*)fileData; + + m_Vertices.resize(test); offset += sizeof(unsigned int); - m_Indices.resize(*(fileData + offset)); + test = *(unsigned int*)(fileData + offset); + m_Indices.resize(*(unsigned int*)(fileData + offset)); offset += sizeof(unsigned int); #else #endif } -bool RawModel::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +void RawModel::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { ReadVertices(offset, fileData, fileByteSize); ReadIndices(offset, fileData, fileByteSize); } -bool RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +void RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN - memcpy(&m_Vertices[0], fileData, m_Vertices.size() * sizeof(Vertex)); + if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) { + throw Resource::FailedLoadingException("Reading vertices failed"); + } + unsigned int i = sizeof(Vertex); + unsigned int ii = sizeof(unsigned int); + memcpy(&m_Vertices[0], fileData + offset, m_Vertices.size() * sizeof(Vertex)); offset += m_Vertices.size() * sizeof(Vertex); #else #endif } -bool RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +void RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN - memcpy(&m_Indices[0], fileData, m_Indices.size() * sizeof(unsigned int)); + if (offset + m_Indices.size() * sizeof(unsigned int) > fileByteSize) { + throw Resource::FailedLoadingException("Reading indices failed"); + } + + memcpy(&m_Indices[0], fileData + offset, m_Indices.size() * sizeof(unsigned int)); offset += m_Indices.size() * sizeof(unsigned int); + #else #endif } diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index c8def2b9..bc43a5a6 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -95,10 +95,10 @@ void RenderSystem::fillModels(std::list>& jobs, World model = ResourceManager::Load<::Model, true>(resource); } catch (const Resource::StillLoadingException&) { //continue; - model = ResourceManager::Load<::Model>("Models/Core/UnitRaptor.obj"); + model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); } catch (const std::exception&) { try { - model = ResourceManager::Load<::Model>("Models/Core/Error.obj"); + model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); } catch (const std::exception&) { continue; } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 9ae317ca..983b0736 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -10,9 +10,9 @@ void Renderer::Initialize() InitializeShaders(); InitializeTextures(); - m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.obj"); + /* m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.obj"); m_UnitQuad = ResourceManager::Load("Models/Core/UnitQuad.obj"); - m_UnitSphere = ResourceManager::Load("Models/Core/UnitSphere.obj"); + m_UnitSphere = ResourceManager::Load("Models/Core/UnitSphere.obj");*/ m_ImGuiRenderPass = new ImGuiRenderPass(this, m_EventBroker); diff --git a/tools/MayaExporter/MayaExporter/Export.cpp b/tools/MayaExporter/MayaExporter/Export.cpp index 82c81cfa..20b99e0f 100644 --- a/tools/MayaExporter/MayaExporter/Export.cpp +++ b/tools/MayaExporter/MayaExporter/Export.cpp @@ -51,13 +51,15 @@ bool Export::Meshes(std::string pathName, bool selectedOnly) GetMeshData(node); } } - MGlobal::displayInfo(MString() + "nrofmeshes: " + meshes.size()); WriteMeshData(pathName); return true; } -bool Export::Materials() +bool Export::Materials(std::string pathName) { + if (!GetMaterialData()) + return false; + WriteMaterialData(pathName); return true; } @@ -73,17 +75,14 @@ bool Export::Animations(std::string pathName, std::vector animInf 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; } @@ -100,11 +99,8 @@ bool Export::GetMeshData(MObject object) bool Export::GetMaterialData() { // Traverse scene and return vector with all materials - std::vector* AllMaterials = m_MaterialHandler.DoIt(); + 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; } @@ -163,6 +159,22 @@ void Export::WriteAnimData(std::string pathName) MGlobal::displayInfo("Export::WriteAnimData() got called when allBindPoses contained no data, did not write nor created them"); } +void Export::WriteMaterialData(std::string pathName) +{ + m_MtrlFile.ASCIIFilePath(pathName +"_mtrl.txt"); + m_MtrlFile.binaryFilePath(pathName + ".mtrl"); + + m_MtrlFile.OpenFiles(); + + int size = (*AllMaterials).size(); + m_MtrlFile.writeToFiles(&size); + + for (auto aMaterial : *AllMaterials) { + m_MtrlFile.writeToFiles((OutputData*)&aMaterial); + } + m_MtrlFile.CloseFiles(); +} + Export::~Export() { /* delete m_MaterialHandler; diff --git a/tools/MayaExporter/MayaExporter/Export.h b/tools/MayaExporter/MayaExporter/Export.h index 83d27459..b05dee4e 100644 --- a/tools/MayaExporter/MayaExporter/Export.h +++ b/tools/MayaExporter/MayaExporter/Export.h @@ -23,7 +23,7 @@ public: }; bool Meshes(std::string pathName, bool selectedOnly = false); - bool Materials(); + bool Materials(std::string pathName); bool Animations(std::string pathName, std::vector animInfo); private: @@ -33,6 +33,7 @@ private: void WriteMeshData(std::string pathName); void WriteAnimData(std::string pathName); + void WriteMaterialData(std::string pathName); Material m_MaterialHandler; Skeleton m_SkeletonHandler; @@ -42,6 +43,7 @@ private: //File export WriteToFile m_MeshFile; WriteToFile m_AnimFile; + WriteToFile m_MtrlFile; //Mesh Data std::vector meshes; @@ -50,5 +52,7 @@ private: std::vector allBindPoses; std::vector allAnimations; + //Material Data + std::vector* AllMaterials; }; #endif \ No newline at end of file diff --git a/tools/MayaExporter/MayaExporter/Material.cpp b/tools/MayaExporter/MayaExporter/Material.cpp index ac9c46ea..8071efab 100644 --- a/tools/MayaExporter/MayaExporter/Material.cpp +++ b/tools/MayaExporter/MayaExporter/Material.cpp @@ -4,57 +4,24 @@ void Material::grabLambertProperties(MaterialNode& material_node, MFnDependencyN { material_node.Name = node.name().asChar(); - if (findColorTexture(material_node, node)) { - material_node.Color.fill(1.0f); - } - else { - m_Plug = node.findPlug("colorR"); - m_Plug.getValue(material_node.Color[0]); - m_Plug = node.findPlug("colorG"); - m_Plug.getValue(material_node.Color[1]); - m_Plug = node.findPlug("colorB"); - m_Plug.getValue(material_node.Color[2]); + if (!findColorTexture(material_node, node)) { + MGlobal::displayWarning(MString() + "Material " + node.name() + " has no color texture. Please apply a texture insted of using a value"); + } - float TempTransp[3]; - m_Plug = node.findPlug("transparencyR"); - m_Plug.getValue(TempTransp[0]); - m_Plug = node.findPlug("transparencyG"); - m_Plug.getValue(TempTransp[1]); - m_Plug = node.findPlug("transparencyB"); - m_Plug.getValue(TempTransp[2]); - - MColor TranspNode(TempTransp[0], TempTransp[1], TempTransp[2]); - float DummyH, DummyS; - TranspNode.get(MColor::kHSV, DummyH, DummyS, material_node.Color[3]); - } if (findIncandescenceTexture(material_node, node)) { - material_node.Incandescence.fill(1.0f); - } - else { - m_Plug = node.findPlug("incandescenceR"); - m_Plug.getValue(material_node.Incandescence[0]); - m_Plug = node.findPlug("incandescenceG"); - m_Plug.getValue(material_node.Incandescence[1]); - m_Plug = node.findPlug("incandescenceB"); - m_Plug.getValue(material_node.Incandescence[2]); + MGlobal::displayWarning(MString() + "Material " + node.name() + " has no Incandescence texture. Please apply a texture insted of using value"); } - findNormalTexture(material_node, node); + if (findNormalTexture(material_node, node)) { + MGlobal::displayWarning(MString() + "Material " + node.name() + " has no normal texture. Please apply a texture to it"); + } } void Material::grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node) { if (findSpecularTexture(material_node, node)) { - material_node.Specular.fill(1.0f); - } - else { - m_Plug = node.findPlug("specularColorR"); - m_Plug.getValue(material_node.Specular[0]); - m_Plug = node.findPlug("specularColorG"); - m_Plug.getValue(material_node.Specular[1]); - m_Plug = node.findPlug("specularColorB"); - m_Plug.getValue(material_node.Specular[2]); + MGlobal::displayWarning(MString() + "Material " + node.name() + " has no specular texture. Please apply a specular to it"); } m_Plug = node.findPlug("reflectivity"); @@ -76,17 +43,9 @@ void Material::grabBlinnProperties(MaterialNode& material_node, MFnDependencyNod void Material::grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node) { - if (findSpecularTexture(material_node, node)) { - material_node.Specular.fill(1.0f); - } - else { - m_Plug = node.findPlug("specularColorR"); - m_Plug.getValue(material_node.Specular[0]); - m_Plug = node.findPlug("specularColorG"); - m_Plug.getValue(material_node.Specular[1]); - m_Plug = node.findPlug("specularColorB"); - m_Plug.getValue(material_node.Specular[2]); - } + if (findSpecularTexture(material_node, node)) { + MGlobal::displayWarning(MString() + "Material " + node.name() + " has no specular texture. Please apply a specular to it"); + } m_Plug = node.findPlug("reflectivity"); m_Plug.getValue(material_node.ReflectionFactor); @@ -109,8 +68,10 @@ bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode& std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); m_TexturePaths.push_back(FullPath); - material_node.ColorMapFile = FullPath.substr(FullPath.find_last_of("/")); + FullPath = FullPath.substr(FullPath.find_last_of("/") + 1); + material_node.ColorMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); + material_node.ColorMapFileLength = material_node.ColorMapFile.length() + 1; // Test MGlobal::displayInfo(MString() + "Texture file: " + FullPath.c_str()); return true; @@ -140,8 +101,9 @@ bool Material::findNormalTexture(MaterialNode& material_node, MFnDependencyNode& std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); m_TexturePaths.push_back(FullPath); - material_node.NormalMapFile = FullPath.substr(FullPath.find_last_of("/")); - + FullPath = FullPath.substr(FullPath.find_last_of("/") + 1); + material_node.NormalMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); + material_node.NormalMapFileLength = material_node.NormalMapFile.length() + 1; return true; } } @@ -165,8 +127,9 @@ bool Material::findSpecularTexture(MaterialNode& material_node, MFnDependencyNod std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); m_TexturePaths.push_back(FullPath); - material_node.SpecularMapFile = FullPath.substr(FullPath.find_last_of("/")); - + FullPath = FullPath.substr(FullPath.find_last_of("/") + 1); + material_node.SpecularMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); + material_node.SpecularMapFileLength = material_node.SpecularMapFile.length() + 1; return true; } } @@ -187,8 +150,9 @@ bool Material::findIncandescenceTexture(MaterialNode& material_node, MFnDependen std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); m_TexturePaths.push_back(FullPath); - material_node.SpecularMapFile = FullPath.substr(FullPath.find_last_of("/")); - + FullPath = FullPath.substr(FullPath.find_last_of("/") + 1); + material_node.IncandescenceMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); + material_node.IncandescenceMapFileLength = material_node.IncandescenceMapFile.length() + 1; return true; } } @@ -206,7 +170,7 @@ std::vector* Material::DoIt() { // All materials we care about inherit from Lambert MItDependencyNodes matIt(MFn::kLambert); - + m_AllMaterials.clear(); while (!matIt.isDone()) { MFnDependencyNode MaterialFnDN(matIt.thisNode()); MaterialNode MaterialStorage; @@ -226,7 +190,6 @@ std::vector* Material::DoIt() else if (matIt.thisNode().hasFn(MFn::kLambert)) { grabLambertProperties(MaterialStorage, MaterialFnDN); - MaterialStorage.Specular.fill(0.0f); MaterialStorage.ReflectionFactor = 0.0f; MaterialStorage.SpecularExponent = 0.0f; diff --git a/tools/MayaExporter/MayaExporter/Material.h b/tools/MayaExporter/MayaExporter/Material.h index c5d57529..9a6058f0 100644 --- a/tools/MayaExporter/MayaExporter/Material.h +++ b/tools/MayaExporter/MayaExporter/Material.h @@ -5,21 +5,80 @@ #include #include #include +#include #include "MayaIncludes.h" +#include "OutputData.h" +#include "Mesh.h" -struct MaterialNode +class MaterialNode : public OutputData { +public: std::string Name; - std::array Color; - std::array Incandescence; - std::array Specular; + float ReflectionFactor; - float SpecularExponent; + float SpecularExponent; + + unsigned int ColorMapFileLength = 0; std::string ColorMapFile; + + unsigned int SpecularMapFileLength = 0; std::string SpecularMapFile; + + unsigned int NormalMapFileLength = 0; std::string NormalMapFile; + + unsigned int IncandescenceMapFileLength = 0; std::string IncandescenceMapFile; + + unsigned int IndexStart; + unsigned int IndexEnd; + + virtual void WriteBinary(std::ostream& out) + { + out.write((char*)&ColorMapFileLength, sizeof(unsigned int)); + out.write((char*)&NormalMapFileLength, sizeof(unsigned int)); + out.write((char*)&SpecularMapFileLength, sizeof(unsigned int)); + out.write((char*)&IncandescenceMapFileLength, sizeof(unsigned int)); + + out.write((char*)&SpecularExponent, sizeof(float)); + out.write((char*)&ReflectionFactor, sizeof(float)); + out.write((char*)&IndexStart, sizeof(unsigned int)); + out.write((char*)&IndexEnd, sizeof(unsigned int)); + + out.write(ColorMapFile.c_str(), ColorMapFileLength); + out.write(NormalMapFile.c_str(), NormalMapFileLength); + out.write(SpecularMapFile.c_str(), SpecularMapFileLength); + out.write(IncandescenceMapFile.c_str(), IncandescenceMapFileLength); + } + + virtual void WriteASCII(std::ostream& out) const + { + out << "New Material _ not in binary" << endl; + out << "number of indices: " << Name << " _ not in binary" << endl; + + out << "ColorMapFile length: " << ColorMapFileLength << endl; + out << "NormalMapFile length: " << NormalMapFileLength << endl; + out << "SpecularMapFile length: " << SpecularMapFileLength << endl; + out << "IncandescenceMapFile length: " << IncandescenceMapFileLength << endl; + + out << "SpecularExponent: " << SpecularExponent << endl; + out << "ReflectionFactor: " << ReflectionFactor << endl; + out << "IndexStart: " << IndexStart << endl; + out << "IndexEnd: " << IndexEnd << endl; + + out << "ColorMapFile length: " << ColorMapFileLength << endl; + if (ColorMapFileLength > 0) + out << "ColorMapFile: " << ColorMapFile << endl; + if (NormalMapFileLength > 0) + out << "NormalMapFile: " << NormalMapFile << endl; + + if (SpecularMapFileLength > 0) + out << "SpecularMapFile: " << SpecularMapFile << endl; + + if (IncandescenceMapFileLength > 0) + out << "IncandescenceMapFile: " << IncandescenceMapFile << endl; + } }; class Material diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 1ff007b4..a03788a6 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -24,16 +24,15 @@ Menu::Menu(QDialog* dialog) 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")); + m_ExportMaterialButton = new QCheckBox(tr("&Export Material"));; m_ExportAnimationsButton->setChecked(true); - m_CopyTexturesButton->setChecked(true); + m_ExportMaterialButton->setChecked(true); QVBoxLayout *vbox = new QVBoxLayout; vbox->addWidget(m_ExportSelectedButton); vbox->addWidget(m_ExportAnimationsButton); - vbox->addWidget(m_CopyTexturesButton); - vbox->addWidget(m_Button3); + vbox->addWidget(m_ExportMaterialButton); + vbox->addStretch(1); optionsBox->setLayout(vbox); @@ -46,8 +45,7 @@ Menu::Menu(QDialog* dialog) 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)); + connect(m_ExportMaterialButton, SIGNAL(clicked(bool)), this, SLOT(NULL)); // Creating several layouts, adding widgets & adding them to one layout in the end QHBoxLayout* topLayout = new QHBoxLayout; @@ -178,20 +176,14 @@ void Menu::ExportAll(bool) } 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"); animations.push_back(thisClip); } - MGlobal::displayInfo(MString() + "asdf"); if (m_ExportAnimationsButton->isChecked()) { //Export Animations if (!m_Export.Animations(m_ExportPath->text().toLocal8Bit().constData(), animations)) { @@ -199,6 +191,13 @@ void Menu::ExportAll(bool) return; } } + + if (m_ExportMaterialButton->isChecked()) { + if (!m_Export.Materials(m_ExportPath->text().toLocal8Bit().constData())){ + MGlobal::displayError(MString() + "Could not export materials"); + return; + } + } } void Menu::CancelClicked(bool) diff --git a/tools/MayaExporter/MayaExporter/Menu.h b/tools/MayaExporter/MayaExporter/Menu.h index a8b517bc..fb95a953 100644 --- a/tools/MayaExporter/MayaExporter/Menu.h +++ b/tools/MayaExporter/MayaExporter/Menu.h @@ -65,8 +65,7 @@ private: QCheckBox* m_ExportSelectedButton = nullptr; QCheckBox* m_ExportAnimationsButton = nullptr; - QCheckBox* m_CopyTexturesButton = nullptr; - QCheckBox* m_Button3 = nullptr; + QCheckBox* m_ExportMaterialButton = nullptr; QLineEdit* m_ExportPath = nullptr; QFileDialog* m_FileDialog = nullptr; diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index 24e661ac..c37a7bed 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -76,8 +76,8 @@ std::map MeshClass::GetWeightData() Mesh MeshClass::GetMeshData(MObject object) { Mesh newMesh; - std::vector& vertexList = newMesh.Vertices; - std::vector& indexList = newMesh.Indices; + vector& vertexList = newMesh.Vertices; + map>& indexLists = newMesh.Indices; // In here, we retrieve triangulated polygons from the mesh MFnMesh mesh(object); @@ -91,11 +91,28 @@ Mesh MeshClass::GetMeshData(MObject object) float2 UV; double biTangent[3]; double biNormal[3]; - VertexLayout thisVertex; MFloatVectorArray Tangents; MFloatVectorArray biNormals; - std::map vertexWeights = GetWeightData(); + MObjectArray shaderList; + MIntArray shaderIndexList; + mesh.getConnectedShaders(0, shaderList, shaderIndexList); + + map> materialFaceIDs; + MGlobal::displayInfo(MString() + "shaderIndexList: " + shaderIndexList.length()); + MGlobal::displayInfo(MString() + "shaderList: " + shaderList.length()); + MPlugArray plugArray; + for (int i = 0; i < shaderIndexList.length(); i++) + { + MFnDependencyNode shader(shaderList[shaderIndexList[i]]); + MPlug p_Plug = shader.findPlug("surfaceShader"); + if (p_Plug.connectedTo(plugArray, true, false)) { + MFnDependencyNode node = plugArray[0].node(); + materialFaceIDs[node.name().asChar()].push_back(i); + } + } + + map vertexWeights = GetWeightData(); mesh.getTangents(Tangents, MSpace::kObject, NULL); mesh.getBinormals(biNormals, MSpace::kObject, NULL); @@ -103,82 +120,139 @@ Mesh MeshClass::GetMeshData(MObject object) MItMeshFaceVertex faceVert(object); int intDummy = 0; + + MItMeshPolygon meshPolyIter(object); - for (MItMeshPolygon meshPolyIter(object); !meshPolyIter.isDone(); meshPolyIter.next()) { + for (auto aMaterial : materialFaceIDs) { + for (auto faceID : aMaterial.second) { - vector localVertexToGlobalIndex; - unsigned int indexOffset = vertexList.size(); + vector> localVertexToGlobalIndex; + meshPolyIter.setIndex(faceID, intDummy); - meshPolyIter.getVertices(vertices); - meshPolyIter.getTriangles(dummy, triangleList); + meshPolyIter.getVertices(vertices); + meshPolyIter.getTriangles(dummy, triangleList); + //MGlobal::displayInfo("Befor Second Loop"); + for (unsigned int i = 0; i < vertices.length(); i++) { + VertexLayout thisVertex; + vertexIndex = meshPolyIter.vertexIndex(i); + faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); + //MGlobal::displayInfo("In Second Loop"); + pos = faceVert.position(); + if (abs(pos.x) > 0.0001) + thisVertex.Pos[0] = pos.x; + if (abs(pos.y) > 0.0001) + thisVertex.Pos[1] = pos.y; + if (abs(pos.z) > 0.0001) + thisVertex.Pos[2] = pos.z; - //MGlobal::displayInfo("Befor Second Loop"); - for (unsigned int i = 0; i < vertices.length(); i++) { - vertexIndex = meshPolyIter.vertexIndex(i); - faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); - //MGlobal::displayInfo("In Second Loop"); - faceVert.position().get(thisVertex.Pos); - faceVert.getNormal(normal); - thisVertex.Normal[0] = normal[0]; - thisVertex.Normal[1] = normal[1]; - thisVertex.Normal[2] = normal[2]; + faceVert.getNormal(normal); + if (abs(normal[0]) > 0.0001) + thisVertex.Normal[0] = normal[0]; + if (abs(normal[1]) > 0.0001) + thisVertex.Normal[1] = normal[1]; + if (abs(normal[2]) > 0.0001) + thisVertex.Normal[2] = normal[2]; - MFloatVector Tangent = Tangents[faceVert.tangentId()]; - //MVector tmp = faceVert.getTangent(MSpace::kObject, NULL); - //tmp.get(biTangent); - thisVertex.Tangent[0] = Tangent[0]; - thisVertex.Tangent[1] = Tangent[1]; - thisVertex.Tangent[2] = Tangent[2]; + MFloatVector Tangent = Tangents[faceVert.tangentId()]; + //MVector tmp = faceVert.getTangent(MSpace::kObject, NULL); + //tmp.get(biTangent); + if (abs(Tangent[0]) > 0.0001) + thisVertex.Tangent[0] = Tangent[0]; + if (abs(Tangent[1]) > 0.0001) + thisVertex.Tangent[1] = Tangent[1]; + if (abs(Tangent[2]) > 0.0001) + thisVertex.Tangent[2] = Tangent[2]; - MFloatVector biNormal = biNormals[faceVert.tangentId()]; - //faceVert.getBinormal().get(biNormal); - thisVertex.BiNormal[0] = biNormal[0]; - thisVertex.BiNormal[1] = biNormal[1]; - thisVertex.BiNormal[2] = biNormal[2]; + MFloatVector biNormal = biNormals[faceVert.tangentId()]; + //faceVert.getBinormal().get(biNormal); + if (abs(biNormal[0]) > 0.0001) + thisVertex.BiNormal[0] = biNormal[0]; + if (abs(biNormal[1]) > 0.0001) + thisVertex.BiNormal[1] = biNormal[1]; + if (abs(biNormal[2]) > 0.0001) + thisVertex.BiNormal[2] = biNormal[2]; - faceVert.getUV(UV); - thisVertex.Uv[0] = UV[0]; - thisVertex.Uv[1] = UV[1]; + faceVert.getUV(UV); + thisVertex.Uv[0] = UV[0]; + thisVertex.Uv[1] = UV[1]; - thisVertex.BoneIndices[0] = vertexWeights[faceVert.vertId()].BoneIndices[0]; - thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1]; - thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2]; - thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3]; + thisVertex.BoneIndices[0] = vertexWeights[faceVert.vertId()].BoneIndices[0]; + thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1]; + thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2]; + thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3]; - thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0]; - thisVertex.BoneWeights[1] = vertexWeights[faceVert.vertId()].BoneWeights[1]; - thisVertex.BoneWeights[2] = vertexWeights[faceVert.vertId()].BoneWeights[2]; - thisVertex.BoneWeights[3] = vertexWeights[faceVert.vertId()].BoneWeights[3]; + if (abs(vertexWeights[faceVert.vertId()].BoneWeights[0]) > 0.0001) + thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0]; + if (abs(vertexWeights[faceVert.vertId()].BoneWeights[1]) > 0.0001) + thisVertex.BoneWeights[1] = vertexWeights[faceVert.vertId()].BoneWeights[1]; + if (abs(vertexWeights[faceVert.vertId()].BoneWeights[2]) > 0.0001) + thisVertex.BoneWeights[2] = vertexWeights[faceVert.vertId()].BoneWeights[2]; + if (abs(vertexWeights[faceVert.vertId()].BoneWeights[3]) > 0.0001) + thisVertex.BoneWeights[3] = vertexWeights[faceVert.vertId()].BoneWeights[3]; - std::vector::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex); - - if (it != vertexList.end()) { - localVertexToGlobalIndex.push_back(vertexIndex); - } else { - localVertexToGlobalIndex.push_back(vertexIndex); - vertexList.push_back(thisVertex); - } - - //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 << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl; - //cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl; - //cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl; - } - - - for (unsigned int i = 0; i < triangleList.length(); i++) { - unsigned int k = 0; - if (localVertexToGlobalIndex.size() > 0) { - while (localVertexToGlobalIndex[k] != triangleList[i] && k < localVertexToGlobalIndex.size()) { - k++; + float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3]; + if (totalWeight < 1.00f && totalWeight > 0.01f) { + thisVertex.BoneWeights[0] /= totalWeight; + thisVertex.BoneWeights[1] /= totalWeight; + thisVertex.BoneWeights[2] /= totalWeight; + thisVertex.BoneWeights[3] /= totalWeight; } - indexList.push_back(indexOffset + k); - } + + std::vector::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex); + array tmp; + if (it != vertexList.end()) { + tmp[0] = vertexIndex; + tmp[1] = it - vertexList.begin(); + localVertexToGlobalIndex.push_back(tmp); + } else { + tmp[0] = vertexIndex; + tmp[1] = vertexList.size(); + localVertexToGlobalIndex.push_back(tmp); + vertexList.push_back(thisVertex); + } + //MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1]: " + localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1][0] + " " + localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1][1]); + //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 << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl; + //cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl; + //cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl; + } + for (unsigned int i = 0; i < triangleList.length(); i++) { + unsigned int k = 0; + if (localVertexToGlobalIndex.size() > 0) { + //MGlobal::displayInfo(MString() + "triangleList[i] : " + triangleList[i]); + while (localVertexToGlobalIndex[k][0] != triangleList[i] && k < localVertexToGlobalIndex.size()) { + k++; + } + //MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k] : " + localVertexToGlobalIndex[k][0] + " " + localVertexToGlobalIndex[k][1]); + indexLists[aMaterial.first.c_str()].push_back(localVertexToGlobalIndex[k][1]); + } + } } + // MGlobal::displayInfo( MString() + "localVertexToGlobalIndex.size(): " + localVertexToGlobalIndex.size()); + // if (localVertexToGlobalIndex.size() > 0) { + // MGlobal::displayInfo(MString() + "triangleList.length(): " + triangleList.length()); + // for (unsigned int i = triangleList.length() - 1; i >= 0; i--) { + // MGlobal::displayInfo(MString() + "i: " + i); + // unsigned int k = localVertexToGlobalIndex.size() - 1; + // MGlobal::displayInfo(MString() + "triangleList[i] : " + triangleList[i]); + // while (localVertexToGlobalIndex[k] != triangleList[i] && k >= 0) { + // MGlobal::displayInfo(MString() + "k: " + k); + // k--; + // } + // MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k] : " + localVertexToGlobalIndex[k]); + // indexList.push_back(indexOffset + k); + // } + // } } - newMesh.NumIndices = newMesh.Indices.size(); + + int totalIndecies = 0; + for (auto aList : newMesh.Indices) { + totalIndecies += aList.second.size(); + } + + newMesh.NumIndices = totalIndecies; newMesh.NumVertices = newMesh.Vertices.size(); return newMesh; diff --git a/tools/MayaExporter/MayaExporter/Mesh.h b/tools/MayaExporter/MayaExporter/Mesh.h index ff7cc3b0..15c16913 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.h +++ b/tools/MayaExporter/MayaExporter/Mesh.h @@ -3,6 +3,7 @@ #include #include +#include #include "OutputData.h" #include "MayaIncludes.h" @@ -10,20 +11,20 @@ class VertexLayout : public OutputData { public: - float Pos[3]; - float Normal[3]; - float Tangent[3]; - float BiNormal[3]; - float Uv[2]; - float BoneIndices[4]; - float BoneWeights[4]; + float Pos[3]{ 0 }; + float Normal[3]{ 0 }; + float Tangent[3]{ 0 }; + float BiNormal[3]{ 0 }; + float Uv[2]{ 0 }; + float BoneIndices[4]{ 0 }; + float BoneWeights[4]{ 0 }; virtual void WriteBinary(std::ostream& out) { out.write((char*)&Pos, sizeof(float) * 3); out.write((char*)&Normal, sizeof(float) * 3); out.write((char*)&Tangent, sizeof(float) * 3); - out.write((char*)&BiTangent, sizeof(float) * 3); + out.write((char*)&BiNormal, sizeof(float) * 3); out.write((char*)&Uv, sizeof(float) * 2); out.write((char*)&BoneIndices, sizeof(float) * 4); out.write((char*)&BoneWeights, sizeof(float) * 4); @@ -34,7 +35,7 @@ public: out << Pos[0] << " " << Pos[1] << " " << Pos[2] << endl; out << Normal[0] << " " << Normal[1] << " " << Normal[2] << endl; out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl; - out << BiTangent[0] << " " << BiTangent[1] << " " << BiTangent[2] << endl; + out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl; out << Uv[0] << " " << Uv[1] << endl; out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl; out << BoneWeights[0] << " " << BoneWeights[1] << " " << BoneWeights[2] << " " << BoneWeights[3] << endl; @@ -46,7 +47,7 @@ public: this->Pos[0] == right.Pos[0] && this->Pos[1] == right.Pos[1] && this->Pos[2] == right.Pos[2] && this->Normal[0] == right.Normal[0] && this->Normal[1] == right.Normal[1] && this->Normal[2] == right.Normal[2] && this->Tangent[0] == right.Tangent[0] && this->Tangent[1] == right.Tangent[1] && this->Tangent[2] == right.Tangent[2] && - this->BiTangent[0] == right.BiTangent[0] && this->BiTangent[1] == right.BiTangent[1] && this->BiTangent[2] == right.BiTangent[2] && + this->BiNormal[0] == right.BiNormal[0] && this->BiNormal[1] == right.BiNormal[1] && this->BiNormal[2] == right.BiNormal[2] && this->Uv[0] == right.Uv[0] && this->Uv[1] == right.Uv[1] && this->BoneIndices[0] == right.BoneIndices[0] && this->BoneIndices[1] == right.BoneIndices[1] && this->BoneIndices[2] == right.BoneIndices[2] && this->BoneIndices[3] == right.BoneIndices[3] && this->BoneWeights[0] == right.BoneWeights[0] && this->BoneWeights[1] == right.BoneWeights[1] && this->BoneWeights[2] == right.BoneWeights[2] && this->BoneWeights[3] == right.BoneWeights[3] @@ -56,10 +57,10 @@ public: class Mesh : public OutputData { public: - int NumVertices; - int NumIndices; + unsigned int NumVertices; + unsigned int NumIndices; std::vector Vertices; - std::vector Indices; + std::map> Indices; virtual void WriteBinary(std::ostream& out) { @@ -69,7 +70,7 @@ public: aVertex.WriteBinary(out); } for (auto aIndex : Indices) { - out.write((char*)&aIndex, sizeof(int)); + out.write((char*)aIndex.second.data(), sizeof(int) * aIndex.second.size()); } } @@ -80,12 +81,16 @@ public: out << "number of indices: " << NumIndices << endl; int vertexNumber = 0; for (auto aVertex : Vertices) { - out << "New vertex number: " << vertexNumber << "_ not in binary" << endl; + 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; + out << "New vertex Triangels: " << NumIndices/3 << " _ not in binary" << endl; + for (auto aIndexList : Indices) { + out << "Using Material: " << aIndexList.first << " _ not in binary" << endl; + for (int i = 0; i < aIndexList.second.size(); i += 3) { + out << aIndexList.second[i] << " " << aIndexList.second[i+1] << " " << aIndexList.second[i + 2] << endl; + } } } }; From 3826142e94a6c7b98f69b702922a847de390c54c Mon Sep 17 00:00:00 2001 From: antc13 Date: Tue, 19 Jan 2016 17:40:34 +0100 Subject: [PATCH 17/28] Now supporting multiple material per mesh. Simon changed glDrawElementsBaseVertex to glDrawElements in DrawFinalPass.cpp Hallelulijah! --- include/Engine/Rendering/Model.h | 3 +- include/Engine/Rendering/RawModelCustom.h | 8 +- resources/Schema/Entities/Model.xml | 2 +- src/Engine/Editor/EditorSystem.cpp | 6 +- src/Engine/Rendering/DrawFinalPass.cpp | 4 +- src/Engine/Rendering/DrawFinalPassState.cpp | 2 +- src/Engine/Rendering/RawModelCustom.cpp | 136 +++++++- src/Engine/Rendering/RenderSystem.cpp | 4 +- src/Engine/Rendering/Renderer.cpp | 8 +- tools/MayaExporter/MayaExporter/Export.cpp | 20 +- tools/MayaExporter/MayaExporter/Export.h | 4 +- tools/MayaExporter/MayaExporter/Material.cpp | 44 +-- tools/MayaExporter/MayaExporter/Material.h | 4 +- tools/MayaExporter/MayaExporter/Mesh.cpp | 337 ++++++++++--------- tools/MayaExporter/MayaExporter/Mesh.h | 7 +- 15 files changed, 359 insertions(+), 230 deletions(-) diff --git a/include/Engine/Rendering/Model.h b/include/Engine/Rendering/Model.h index f79cacd5..4b83562c 100644 --- a/include/Engine/Rendering/Model.h +++ b/include/Engine/Rendering/Model.h @@ -19,9 +19,10 @@ public: GLuint VAO; GLuint ElementBuffer; + RawModel* m_RawModel; private: - RawModel* m_RawModel; + GLuint VertexBuffer; GLuint NormalBuffer; GLuint TangentNormalsBuffer; diff --git a/include/Engine/Rendering/RawModelCustom.h b/include/Engine/Rendering/RawModelCustom.h index b5bf44cc..bc85e32c 100644 --- a/include/Engine/Rendering/RawModelCustom.h +++ b/include/Engine/Rendering/RawModelCustom.h @@ -22,7 +22,7 @@ class RawModel : public Resource friend class ResourceManager; protected: - RawModel(std::string fileName); + RawModel(std::string& fileName); public: ~RawModel(); @@ -63,12 +63,18 @@ public: glm::mat4 m_Matrix; private: + + void ReadMeshFile(std::string filePath); void ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize); void ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize); void ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); void ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize); + void ReadMaterialFile(std::string filePath); + void ReadMaterials(unsigned int &offset, char* fileData, unsigned int& fileByteSize); + void ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize); + //void CreateSkeleton(std::vector> &boneInfo, std::map &boneNameMapping, aiNode* node, int parentID); }; diff --git a/resources/Schema/Entities/Model.xml b/resources/Schema/Entities/Model.xml index e4e60e4f..8962d7e1 100644 --- a/resources/Schema/Entities/Model.xml +++ b/resources/Schema/Entities/Model.xml @@ -19,7 +19,7 @@ - models/coolTriangle.mesh + models/Baljj diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 0f32a519..044c0cd7 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -291,21 +291,21 @@ void EditorSystem::createWidget() m_WidgetPlaneX = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneX, "Transform"); m_World->AttachComponent(m_WidgetPlaneX, "Model"); - m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh"; + m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube"; m_WidgetY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetY, "Transform"); m_World->AttachComponent(m_WidgetY, "Model"); m_WidgetPlaneY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneY, "Transform"); m_World->AttachComponent(m_WidgetPlaneY, "Model"); - m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh"; + m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube"; m_WidgetZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetZ, "Transform"); m_World->AttachComponent(m_WidgetZ, "Model"); m_WidgetPlaneZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneZ, "Transform"); m_World->AttachComponent(m_WidgetPlaneZ, "Model"); - m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh"; + m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube"; m_WidgetOrigin = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetOrigin, "Transform"); m_World->AttachComponent(m_WidgetOrigin, "Model"); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index b0ca4afe..7093b00f 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -56,9 +56,7 @@ void DrawFinalPass::Draw(RenderScene& scene) glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex); - - continue; + glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); } } GLERROR("DrawFinalPass::Draw: END"); diff --git a/src/Engine/Rendering/DrawFinalPassState.cpp b/src/Engine/Rendering/DrawFinalPassState.cpp index 1cb9d7da..5bafc294 100644 --- a/src/Engine/Rendering/DrawFinalPassState.cpp +++ b/src/Engine/Rendering/DrawFinalPassState.cpp @@ -7,7 +7,7 @@ DrawFinalPassState::DrawFinalPassState() Enable(GL_BLEND); BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Enable(GL_DEPTH_TEST); - Enable(GL_CULL_FACE); + Disable(GL_CULL_FACE); //Should be enabled, fix it johan and andreas. ClearColor(glm::vec4(200.f / 255, 0.f / 255, 200.f / 255, 0.f)); Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index a165e1a4..a749e1fd 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -1,12 +1,19 @@ -#include "Rendering\RawModelCustom.h" +#include "Rendering/RawModelCustom.h" -RawModel::RawModel(std::string fileName) +RawModel::RawModel(std::string& fileName) { + ReadMeshFile(fileName); + ReadMaterialFile(fileName); +} + +void RawModel::ReadMeshFile(std::string filePath) +{ char* fileData; - std::ifstream in(fileName.c_str(), std::ios_base::binary | std::ios_base::ate); + filePath += ".mesh"; + std::ifstream in(filePath.c_str(), std::ios_base::binary | std::ios_base::ate); if (!in.is_open()) { - throw Resource::FailedLoadingException("Open file failed"); + throw Resource::FailedLoadingException("Open mesh file failed"); } unsigned int fileByteSize = in.tellg(); in.seekg(0, std::ios_base::beg); @@ -21,23 +28,13 @@ RawModel::RawModel(std::string fileName) ReadMesh(offset, fileData, fileByteSize); } delete fileData; - MaterialGroup mat; - mat.StartIndex = 0; - mat.EndIndex = m_Indices.size() - 1; - MaterialGroups.push_back(mat); } void RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN - unsigned int test; - test = *(unsigned int*)fileData; - unsigned int* test2; - test2 = (unsigned int*)fileData; - - m_Vertices.resize(test); + m_Vertices.resize(*(unsigned int*)(fileData + offset)); offset += sizeof(unsigned int); - test = *(unsigned int*)(fileData + offset); m_Indices.resize(*(unsigned int*)(fileData + offset)); offset += sizeof(unsigned int); #else @@ -78,6 +75,115 @@ void RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& f #endif } +void RawModel::ReadMaterialFile(std::string filePath) +{ + char* fileData; + filePath += ".mtrl"; + std::ifstream in(filePath.c_str(), std::ios_base::binary | std::ios_base::ate); + + if (!in.is_open()) { + throw Resource::FailedLoadingException("Open material file failed"); + } + unsigned int fileByteSize = in.tellg(); + in.seekg(0, std::ios_base::beg); + + fileData = new char[fileByteSize]; + in.read(fileData, fileByteSize); + in.close(); + + unsigned int offset = 0; + if (fileByteSize > 0) { + ReadMaterials(offset, fileData, fileByteSize); + } + delete fileData; +} + +void RawModel::ReadMaterials(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +{ +#ifdef BOOST_LITTLE_ENDIAN + unsigned int* numMaterials = (unsigned int*)(fileData); + MaterialGroups.reserve(*numMaterials); + offset += sizeof(unsigned int); + + for (int i = 0; i < *numMaterials; i++) { + ReadMaterialSingle(offset, fileData, fileByteSize); + } +#else +#endif +} + +void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize) +{ + MaterialGroup newMaterial; + +#ifdef BOOST_LITTLE_ENDIAN + + if (offset + sizeof(unsigned int) * 4 > fileByteSize) { + throw Resource::FailedLoadingException("Reading Material texture names length failed"); + } + + unsigned int* nameLengths = (unsigned int*)(fileData + offset); + offset += sizeof(unsigned int) * 4; + + if (offset + sizeof(float) * 2 > fileByteSize) { + throw Resource::FailedLoadingException("Reading Material specular and reflection values failed"); + } + + newMaterial.SpecularExponent = *(float*)(fileData + offset); + offset += sizeof(float); + newMaterial.ReflectionFactor = *(float*)(fileData + offset); + offset += sizeof(float); + + if (offset + sizeof(unsigned int) * 2 > fileByteSize) { + throw Resource::FailedLoadingException("Reading Material start and end index values failed"); + } + + newMaterial.StartIndex = *(unsigned int*)(fileData + offset); + offset += sizeof(unsigned int); + newMaterial.EndIndex = *(unsigned int*)(fileData + offset); + offset += sizeof(unsigned int); + + if (nameLengths[0] > 0) { + if (offset + nameLengths[0] > fileByteSize) { + throw Resource::FailedLoadingException("Reading Material texture path failed"); + } + + newMaterial.TexturePath = (fileData + offset); + offset += nameLengths[0]; + } + + if (nameLengths[1] > 0) { + if (offset + nameLengths[1] > fileByteSize) { + throw Resource::FailedLoadingException("Reading Material NormalMap path failed"); + } + + newMaterial.NormalMapPath = (fileData + offset); + offset += nameLengths[1]; + } + + if (nameLengths[2] > 0) { + if (offset + nameLengths[2] > fileByteSize) { + throw Resource::FailedLoadingException("Reading Material SpecularMap path failed"); + } + + newMaterial.SpecularMapPath = (fileData + offset); + offset += nameLengths[2]; + } + + if (nameLengths[3] > 0) { + if (offset + nameLengths[3] > fileByteSize) { + throw Resource::FailedLoadingException("Reading Material IncandescenceMap path failed"); + } + + newMaterial.IncandescenceMapPath = (fileData + offset); + offset += nameLengths[3]; + } + +#else +#endif + + MaterialGroups.push_back(newMaterial); +} RawModel::~RawModel() { diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index bc43a5a6..42628ad1 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -95,10 +95,10 @@ void RenderSystem::fillModels(std::list>& jobs, World model = ResourceManager::Load<::Model, true>(resource); } catch (const Resource::StillLoadingException&) { //continue; - model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); + model = ResourceManager::Load<::Model>("Models/coolCube"); } catch (const std::exception&) { try { - model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); + model = ResourceManager::Load<::Model>("Models/coolCube"); } catch (const std::exception&) { continue; } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 983b0736..f86fea43 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -101,10 +101,10 @@ void Renderer::Draw(RenderFrame& frame) m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras. FillDepth(*scene); - m_PickingPass->Draw(*scene); - m_LightCullingPass->GenerateNewFrustum(*scene); - m_LightCullingPass->FillLightList(*scene); - m_LightCullingPass->CullLights(*scene); + //m_PickingPass->Draw(*scene); + //m_LightCullingPass->GenerateNewFrustum(*scene); + //m_LightCullingPass->FillLightList(*scene); + //m_LightCullingPass->CullLights(*scene); m_DrawFinalPass->Draw(*scene); //m_DrawScenePass->Draw(rq); diff --git a/tools/MayaExporter/MayaExporter/Export.cpp b/tools/MayaExporter/MayaExporter/Export.cpp index 20b99e0f..1db753d7 100644 --- a/tools/MayaExporter/MayaExporter/Export.cpp +++ b/tools/MayaExporter/MayaExporter/Export.cpp @@ -11,8 +11,8 @@ bool Export::Meshes(std::string pathName, bool selectedOnly) MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file"); return false; } - meshes.clear(); + MObjectArray Objects; if (selectedOnly) { // Retrieving the objects we currently have selected MSelectionList selected; @@ -25,7 +25,7 @@ bool Export::Meshes(std::string pathName, bool selectedOnly) if (object.hasFn(MFn::kMesh)) { MFnDependencyNode thisNode(object); - GetMeshData(object); + Objects.append(object); } } } else { @@ -48,9 +48,10 @@ bool Export::Meshes(std::string pathName, bool selectedOnly) if (next) continue; - GetMeshData(node); + Objects.append(node); } } + GetMeshData(Objects); WriteMeshData(pathName); return true; } @@ -87,19 +88,16 @@ bool Export::Animations(std::string pathName, std::vector animInf return true; } -bool Export::GetMeshData(MObject object) +bool Export::GetMeshData(MObjectArray object) { - if (!object.hasFn(MFn::kMesh)) - return false; - - meshes.push_back(m_MeshHandler.GetMeshData(object)); + meshes = m_MeshHandler.GetMeshData(object); return true; } bool Export::GetMaterialData() { // Traverse scene and return vector with all materials - AllMaterials = m_MaterialHandler.DoIt(); + AllMaterials = m_MaterialHandler.DoIt(meshes); return true; } @@ -126,9 +124,7 @@ void Export::WriteMeshData(std::string pathName) m_MeshFile.OpenFiles(); - for (auto aMesh : meshes) { - m_MeshFile.writeToFiles((OutputData*)&aMesh); - } + m_MeshFile.writeToFiles((OutputData*)&meshes); m_MeshFile.CloseFiles(); } diff --git a/tools/MayaExporter/MayaExporter/Export.h b/tools/MayaExporter/MayaExporter/Export.h index b05dee4e..42b40445 100644 --- a/tools/MayaExporter/MayaExporter/Export.h +++ b/tools/MayaExporter/MayaExporter/Export.h @@ -27,7 +27,7 @@ public: bool Animations(std::string pathName, std::vector animInfo); private: - bool GetMeshData(MObject object); + bool GetMeshData(MObjectArray object); bool GetMaterialData(); bool GetAnimationData(AnimationInfo info); @@ -46,7 +46,7 @@ private: WriteToFile m_MtrlFile; //Mesh Data - std::vector meshes; + Mesh meshes; //Animation Data std::vector allBindPoses; diff --git a/tools/MayaExporter/MayaExporter/Material.cpp b/tools/MayaExporter/MayaExporter/Material.cpp index 8071efab..8f6b0a62 100644 --- a/tools/MayaExporter/MayaExporter/Material.cpp +++ b/tools/MayaExporter/MayaExporter/Material.cpp @@ -166,36 +166,42 @@ std::vector* Material::TexturePaths() } // Traverse the DAG and grab all the materials -std::vector* Material::DoIt() +std::vector* Material::DoIt(Mesh mesh) { // All materials we care about inherit from Lambert MItDependencyNodes matIt(MFn::kLambert); m_AllMaterials.clear(); + int totalIndices = 0; while (!matIt.isDone()) { MFnDependencyNode MaterialFnDN(matIt.thisNode()); MaterialNode MaterialStorage; + bool meshHasMaterial = false; + //Mesh Indices is a map with : indices> + for (auto aMeshMaterial : mesh.Indices) { + if (aMeshMaterial.first.compare(MaterialFnDN.name().asChar()) == 0) { + meshHasMaterial = true; + MaterialStorage.IndexStart = totalIndices; + MaterialStorage.IndexEnd = totalIndices + aMeshMaterial.second.size() - 1; + totalIndices += aMeshMaterial.second.size(); + break; + } + } + if (meshHasMaterial) { + grabLambertProperties(MaterialStorage, MaterialFnDN); - if (matIt.thisNode().hasFn(MFn::kPhong)) { - grabLambertProperties(MaterialStorage, MaterialFnDN); - grabPhongProperties(MaterialStorage, MaterialFnDN); + if (matIt.thisNode().hasFn(MFn::kPhong)) { + grabPhongProperties(MaterialStorage, MaterialFnDN); - m_AllMaterials.push_back(MaterialStorage); - } - else if (matIt.thisNode().hasFn(MFn::kBlinn)) { - grabLambertProperties(MaterialStorage, MaterialFnDN); - grabBlinnProperties(MaterialStorage, MaterialFnDN); + } else if (matIt.thisNode().hasFn(MFn::kBlinn)) { + grabBlinnProperties(MaterialStorage, MaterialFnDN); - m_AllMaterials.push_back(MaterialStorage); - } - else if (matIt.thisNode().hasFn(MFn::kLambert)) { - grabLambertProperties(MaterialStorage, MaterialFnDN); - - MaterialStorage.ReflectionFactor = 0.0f; - MaterialStorage.SpecularExponent = 0.0f; - - m_AllMaterials.push_back(MaterialStorage); - } + } else if (matIt.thisNode().hasFn(MFn::kLambert)) { + MaterialStorage.ReflectionFactor = 0.0f; + MaterialStorage.SpecularExponent = 0.0f; + } + m_AllMaterials.push_back(MaterialStorage); + } matIt.next(); } diff --git a/tools/MayaExporter/MayaExporter/Material.h b/tools/MayaExporter/MayaExporter/Material.h index 9a6058f0..4b567d8b 100644 --- a/tools/MayaExporter/MayaExporter/Material.h +++ b/tools/MayaExporter/MayaExporter/Material.h @@ -67,9 +67,9 @@ public: out << "IndexStart: " << IndexStart << endl; out << "IndexEnd: " << IndexEnd << endl; - out << "ColorMapFile length: " << ColorMapFileLength << endl; if (ColorMapFileLength > 0) out << "ColorMapFile: " << ColorMapFile << endl; + if (NormalMapFileLength > 0) out << "NormalMapFile: " << NormalMapFile << endl; @@ -86,7 +86,7 @@ class Material public: Material() {}; ~Material() {}; - std::vector* DoIt(); + std::vector* DoIt(Mesh mesh); std::vector* TexturePaths(); private: MPlug m_Plug; diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index c37a7bed..0f99533c 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -73,186 +73,201 @@ std::map MeshClass::GetWeightData() return weightMap; } -Mesh MeshClass::GetMeshData(MObject object) +Mesh MeshClass::GetMeshData(MObjectArray object) { Mesh newMesh; vector& vertexList = newMesh.Vertices; map>& indexLists = newMesh.Indices; - // In here, we retrieve triangulated polygons from the mesh - MFnMesh mesh(object); + for (int ObjectID = 0; ObjectID < object.length(); ObjectID++) { + if (!object[ObjectID].hasFn(MFn::kMesh)) + continue; - map> vertexToIndex;; + // In here, we retrieve triangulated polygons from the mesh + MFnMesh mesh(object[ObjectID]); + MDagPathArray dagPaths; + MDagPath::getAllPathsTo(object[ObjectID], dagPaths); + for (int pathID = 0; pathID < dagPaths.length(); pathID++) { + MGlobal::displayInfo(dagPaths[pathID].fullPathName()); + MDagPath thisMeshPath(dagPaths[pathID]); + MMatrix transformMatrix = thisMeshPath.inclusiveMatrix(); - MIntArray intdexOffsetVertexCount, vertices, triangleList; - MPointArray dummy; - unsigned int vertexIndex; - MVector normal; - MPoint pos; - float2 UV; - double biTangent[3]; - double biNormal[3]; - MFloatVectorArray Tangents; - MFloatVectorArray biNormals; + map> vertexToIndex;; - MObjectArray shaderList; - MIntArray shaderIndexList; - mesh.getConnectedShaders(0, shaderList, shaderIndexList); + MIntArray intdexOffsetVertexCount, vertices, triangleList; + MPointArray dummy; + unsigned int vertexIndex; + MVector normal; + MPoint pos; + float2 UV; + double biTangent[3]; + double biNormal[3]; + MFloatVectorArray Tangents; + MFloatVectorArray biNormals; - map> materialFaceIDs; - MGlobal::displayInfo(MString() + "shaderIndexList: " + shaderIndexList.length()); - MGlobal::displayInfo(MString() + "shaderList: " + shaderList.length()); - MPlugArray plugArray; - for (int i = 0; i < shaderIndexList.length(); i++) - { - MFnDependencyNode shader(shaderList[shaderIndexList[i]]); - MPlug p_Plug = shader.findPlug("surfaceShader"); - if (p_Plug.connectedTo(plugArray, true, false)) { - MFnDependencyNode node = plugArray[0].node(); - materialFaceIDs[node.name().asChar()].push_back(i); - } - } - - map vertexWeights = GetWeightData(); + MObjectArray shaderList; + MIntArray shaderIndexList; + mesh.getConnectedShaders(0, shaderList, shaderIndexList); - mesh.getTangents(Tangents, MSpace::kObject, NULL); - mesh.getBinormals(biNormals, MSpace::kObject, NULL); - - MItMeshFaceVertex faceVert(object); - - int intDummy = 0; - - MItMeshPolygon meshPolyIter(object); - - for (auto aMaterial : materialFaceIDs) { - for (auto faceID : aMaterial.second) { - - vector> localVertexToGlobalIndex; - meshPolyIter.setIndex(faceID, intDummy); - - meshPolyIter.getVertices(vertices); - meshPolyIter.getTriangles(dummy, triangleList); - //MGlobal::displayInfo("Befor Second Loop"); - for (unsigned int i = 0; i < vertices.length(); i++) { - VertexLayout thisVertex; - vertexIndex = meshPolyIter.vertexIndex(i); - faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); - //MGlobal::displayInfo("In Second Loop"); - pos = faceVert.position(); - if (abs(pos.x) > 0.0001) - thisVertex.Pos[0] = pos.x; - if (abs(pos.y) > 0.0001) - thisVertex.Pos[1] = pos.y; - if (abs(pos.z) > 0.0001) - thisVertex.Pos[2] = pos.z; - - faceVert.getNormal(normal); - if (abs(normal[0]) > 0.0001) - thisVertex.Normal[0] = normal[0]; - if (abs(normal[1]) > 0.0001) - thisVertex.Normal[1] = normal[1]; - if (abs(normal[2]) > 0.0001) - thisVertex.Normal[2] = normal[2]; - - MFloatVector Tangent = Tangents[faceVert.tangentId()]; - //MVector tmp = faceVert.getTangent(MSpace::kObject, NULL); - //tmp.get(biTangent); - if (abs(Tangent[0]) > 0.0001) - thisVertex.Tangent[0] = Tangent[0]; - if (abs(Tangent[1]) > 0.0001) - thisVertex.Tangent[1] = Tangent[1]; - if (abs(Tangent[2]) > 0.0001) - thisVertex.Tangent[2] = Tangent[2]; - - MFloatVector biNormal = biNormals[faceVert.tangentId()]; - //faceVert.getBinormal().get(biNormal); - if (abs(biNormal[0]) > 0.0001) - thisVertex.BiNormal[0] = biNormal[0]; - if (abs(biNormal[1]) > 0.0001) - thisVertex.BiNormal[1] = biNormal[1]; - if (abs(biNormal[2]) > 0.0001) - thisVertex.BiNormal[2] = biNormal[2]; - - faceVert.getUV(UV); - thisVertex.Uv[0] = UV[0]; - thisVertex.Uv[1] = UV[1]; - - thisVertex.BoneIndices[0] = vertexWeights[faceVert.vertId()].BoneIndices[0]; - thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1]; - thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2]; - thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3]; - - if (abs(vertexWeights[faceVert.vertId()].BoneWeights[0]) > 0.0001) - thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0]; - if (abs(vertexWeights[faceVert.vertId()].BoneWeights[1]) > 0.0001) - thisVertex.BoneWeights[1] = vertexWeights[faceVert.vertId()].BoneWeights[1]; - if (abs(vertexWeights[faceVert.vertId()].BoneWeights[2]) > 0.0001) - thisVertex.BoneWeights[2] = vertexWeights[faceVert.vertId()].BoneWeights[2]; - if (abs(vertexWeights[faceVert.vertId()].BoneWeights[3]) > 0.0001) - thisVertex.BoneWeights[3] = vertexWeights[faceVert.vertId()].BoneWeights[3]; - - float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3]; - if (totalWeight < 1.00f && totalWeight > 0.01f) { - thisVertex.BoneWeights[0] /= totalWeight; - thisVertex.BoneWeights[1] /= totalWeight; - thisVertex.BoneWeights[2] /= totalWeight; - thisVertex.BoneWeights[3] /= totalWeight; + map> materialFaceIDs; + MGlobal::displayInfo(MString() + "shaderIndexList: " + shaderIndexList.length()); + MGlobal::displayInfo(MString() + "shaderList: " + shaderList.length()); + MPlugArray plugArray; + for (int i = 0; i < shaderIndexList.length(); i++) { + MFnDependencyNode shader(shaderList[shaderIndexList[i]]); + MPlug p_Plug = shader.findPlug("surfaceShader"); + if (p_Plug.connectedTo(plugArray, true, false)) { + MFnDependencyNode node = plugArray[0].node(); + materialFaceIDs[node.name().asChar()].push_back(i); } - - std::vector::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex); - array tmp; - if (it != vertexList.end()) { - tmp[0] = vertexIndex; - tmp[1] = it - vertexList.begin(); - localVertexToGlobalIndex.push_back(tmp); - } else { - tmp[0] = vertexIndex; - tmp[1] = vertexList.size(); - localVertexToGlobalIndex.push_back(tmp); - vertexList.push_back(thisVertex); - } - //MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1]: " + localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1][0] + " " + localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1][1]); - //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 << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl; - //cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl; - //cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl; } - for (unsigned int i = 0; i < triangleList.length(); i++) { - unsigned int k = 0; - if (localVertexToGlobalIndex.size() > 0) { - //MGlobal::displayInfo(MString() + "triangleList[i] : " + triangleList[i]); - while (localVertexToGlobalIndex[k][0] != triangleList[i] && k < localVertexToGlobalIndex.size()) { - k++; + + map vertexWeights = GetWeightData(); + + mesh.getTangents(Tangents, MSpace::kTransform, NULL); + mesh.getBinormals(biNormals, MSpace::kTransform, NULL); + + MItMeshFaceVertex faceVert(object[ObjectID]); + + int intDummy = 0; + + MItMeshPolygon meshPolyIter(object[ObjectID]); + MFloatPointArray positions; + + mesh.getPoints(positions); + + for (auto aMaterial : materialFaceIDs) { + for (auto faceID : aMaterial.second) { + + vector> localVertexToGlobalIndex; + meshPolyIter.setIndex(faceID, intDummy); + + meshPolyIter.getVertices(vertices); + meshPolyIter.getTriangles(dummy, triangleList); + //MGlobal::displayInfo("Befor Second Loop"); + for (unsigned int i = 0; i < vertices.length(); i++) { + VertexLayout thisVertex; + vertexIndex = meshPolyIter.vertexIndex(i); + faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); + //MGlobal::displayInfo("In Second Loop"); + //pos = faceVert.position(MSpace::kTransform); + //mesh.getPoint(vertexIndex, pos, MSpace::kPostTransform); + pos = positions[vertexIndex]; + pos = pos * transformMatrix; + if (abs(pos.x) > 0.0001) + thisVertex.Pos[0] = pos.x; + if (abs(pos.y) > 0.0001) + thisVertex.Pos[1] = pos.y; + if (abs(pos.z) > 0.0001) + thisVertex.Pos[2] = pos.z; + + faceVert.getNormal(normal, MSpace::kTransform); + if (abs(normal[0]) > 0.0001) + thisVertex.Normal[0] = normal[0]; + if (abs(normal[1]) > 0.0001) + thisVertex.Normal[1] = normal[1]; + if (abs(normal[2]) > 0.0001) + thisVertex.Normal[2] = normal[2]; + + MFloatVector Tangent = Tangents[faceVert.tangentId()]; + //MVector tmp = faceVert.getTangent(MSpace::kObject, NULL); + //tmp.get(biTangent); + if (abs(Tangent[0]) > 0.0001) + thisVertex.Tangent[0] = Tangent[0]; + if (abs(Tangent[1]) > 0.0001) + thisVertex.Tangent[1] = Tangent[1]; + if (abs(Tangent[2]) > 0.0001) + thisVertex.Tangent[2] = Tangent[2]; + + MFloatVector biNormal = biNormals[faceVert.tangentId()]; + //faceVert.getBinormal().get(biNormal); + if (abs(biNormal[0]) > 0.0001) + thisVertex.BiNormal[0] = biNormal[0]; + if (abs(biNormal[1]) > 0.0001) + thisVertex.BiNormal[1] = biNormal[1]; + if (abs(biNormal[2]) > 0.0001) + thisVertex.BiNormal[2] = biNormal[2]; + + faceVert.getUV(UV); + thisVertex.Uv[0] = UV[0]; + thisVertex.Uv[1] = UV[1]; + + thisVertex.BoneIndices[0] = vertexWeights[faceVert.vertId()].BoneIndices[0]; + thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1]; + thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2]; + thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3]; + + if (abs(vertexWeights[faceVert.vertId()].BoneWeights[0]) > 0.0001) + thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0]; + if (abs(vertexWeights[faceVert.vertId()].BoneWeights[1]) > 0.0001) + thisVertex.BoneWeights[1] = vertexWeights[faceVert.vertId()].BoneWeights[1]; + if (abs(vertexWeights[faceVert.vertId()].BoneWeights[2]) > 0.0001) + thisVertex.BoneWeights[2] = vertexWeights[faceVert.vertId()].BoneWeights[2]; + if (abs(vertexWeights[faceVert.vertId()].BoneWeights[3]) > 0.0001) + thisVertex.BoneWeights[3] = vertexWeights[faceVert.vertId()].BoneWeights[3]; + + float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3]; + if (totalWeight < 1.00f && totalWeight > 0.01f) { + thisVertex.BoneWeights[0] /= totalWeight; + thisVertex.BoneWeights[1] /= totalWeight; + thisVertex.BoneWeights[2] /= totalWeight; + thisVertex.BoneWeights[3] /= totalWeight; + } + + std::vector::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex); + array tmp; + if (it != vertexList.end()) { + tmp[0] = vertexIndex; + tmp[1] = it - vertexList.begin(); + localVertexToGlobalIndex.push_back(tmp); + } else { + tmp[0] = vertexIndex; + tmp[1] = vertexList.size(); + localVertexToGlobalIndex.push_back(tmp); + vertexList.push_back(thisVertex); + } + //MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1]: " + localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1][0] + " " + localVertexToGlobalIndex[localVertexToGlobalIndex.size()-1][1]); + //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 << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl; + //cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl; + //cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl; + } + for (unsigned int i = 0; i < triangleList.length(); i++) { + unsigned int k = 0; + if (localVertexToGlobalIndex.size() > 0) { + //MGlobal::displayInfo(MString() + "triangleList[i] : " + triangleList[i]); + while (localVertexToGlobalIndex[k][0] != triangleList[i] && k < localVertexToGlobalIndex.size()) { + k++; + } + //MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k] : " + localVertexToGlobalIndex[k][0] + " " + localVertexToGlobalIndex[k][1]); + indexLists[aMaterial.first.c_str()].push_back(localVertexToGlobalIndex[k][1]); + } } - //MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k] : " + localVertexToGlobalIndex[k][0] + " " + localVertexToGlobalIndex[k][1]); - indexLists[aMaterial.first.c_str()].push_back(localVertexToGlobalIndex[k][1]); } + // MGlobal::displayInfo( MString() + "localVertexToGlobalIndex.size(): " + localVertexToGlobalIndex.size()); + // if (localVertexToGlobalIndex.size() > 0) { + // MGlobal::displayInfo(MString() + "triangleList.length(): " + triangleList.length()); + // for (unsigned int i = triangleList.length() - 1; i >= 0; i--) { + // MGlobal::displayInfo(MString() + "i: " + i); + // unsigned int k = localVertexToGlobalIndex.size() - 1; + // MGlobal::displayInfo(MString() + "triangleList[i] : " + triangleList[i]); + // while (localVertexToGlobalIndex[k] != triangleList[i] && k >= 0) { + // MGlobal::displayInfo(MString() + "k: " + k); + // k--; + // } + // MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k] : " + localVertexToGlobalIndex[k]); + // indexList.push_back(indexOffset + k); + // } + // } } } - // MGlobal::displayInfo( MString() + "localVertexToGlobalIndex.size(): " + localVertexToGlobalIndex.size()); - // if (localVertexToGlobalIndex.size() > 0) { - // MGlobal::displayInfo(MString() + "triangleList.length(): " + triangleList.length()); - // for (unsigned int i = triangleList.length() - 1; i >= 0; i--) { - // MGlobal::displayInfo(MString() + "i: " + i); - // unsigned int k = localVertexToGlobalIndex.size() - 1; - // MGlobal::displayInfo(MString() + "triangleList[i] : " + triangleList[i]); - // while (localVertexToGlobalIndex[k] != triangleList[i] && k >= 0) { - // MGlobal::displayInfo(MString() + "k: " + k); - // k--; - // } - // MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k] : " + localVertexToGlobalIndex[k]); - // indexList.push_back(indexOffset + k); - // } - // } } - - int totalIndecies = 0; + int totalIndices = 0; for (auto aList : newMesh.Indices) { - totalIndecies += aList.second.size(); + totalIndices += aList.second.size(); } - - newMesh.NumIndices = totalIndecies; + newMesh.NumIndices = totalIndices; newMesh.NumVertices = newMesh.Vertices.size(); return newMesh; diff --git a/tools/MayaExporter/MayaExporter/Mesh.h b/tools/MayaExporter/MayaExporter/Mesh.h index 15c16913..0538e83c 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.h +++ b/tools/MayaExporter/MayaExporter/Mesh.h @@ -69,8 +69,9 @@ public: for (auto aVertex : Vertices) { aVertex.WriteBinary(out); } - for (auto aIndex : Indices) { - out.write((char*)aIndex.second.data(), sizeof(int) * aIndex.second.size()); + //for (auto aIndex : Indices) { + for (std::map>::reverse_iterator aIndex = Indices.rbegin(); aIndex != Indices.rend(); aIndex++){ + out.write((char*)(*aIndex).second.data(), sizeof(int) * (*aIndex).second.size()); } } @@ -101,7 +102,7 @@ class MeshClass { public: MeshClass(); - Mesh GetMeshData(MObject Object); + Mesh GetMeshData(MObjectArray Object); ~MeshClass(); private: struct WeightInfo { From e64358197190bc148ec0b63cb7d3b7de4063791a Mon Sep 17 00:00:00 2001 From: antc13 Date: Tue, 19 Jan 2016 18:21:27 +0100 Subject: [PATCH 18/28] Commit in order to pull from Master. --- resources/Shaders/ForwardPlus.frag.glsl | 3 +-- src/Engine/Rendering/DrawFinalPassState.cpp | 2 +- src/Engine/Rendering/RawModelCustom.cpp | 4 +++- src/Engine/Rendering/Renderer.cpp | 8 ++++---- tools/MayaExporter/MayaExporter/Mesh.h | 7 ++++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 450d8929..b6d07ba2 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -113,7 +113,7 @@ void main() totalLighting.Specular += result.Specular; } - //fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; + fragmentColor += (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; //fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color; //fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1); //fragmentColor = texel * Input.DiffuseColor * Color; @@ -125,7 +125,6 @@ void main() } - fragmentColor = vec4(1.0f, 1.0f, 1.0f, 1.0f); } diff --git a/src/Engine/Rendering/DrawFinalPassState.cpp b/src/Engine/Rendering/DrawFinalPassState.cpp index 5bafc294..1cb9d7da 100644 --- a/src/Engine/Rendering/DrawFinalPassState.cpp +++ b/src/Engine/Rendering/DrawFinalPassState.cpp @@ -7,7 +7,7 @@ DrawFinalPassState::DrawFinalPassState() Enable(GL_BLEND); BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Enable(GL_DEPTH_TEST); - Disable(GL_CULL_FACE); //Should be enabled, fix it johan and andreas. + Enable(GL_CULL_FACE); ClearColor(glm::vec4(200.f / 255, 0.f / 255, 200.f / 255, 0.f)); Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index a749e1fd..b7f2a2fd 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -148,7 +148,9 @@ void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned throw Resource::FailedLoadingException("Reading Material texture path failed"); } - newMaterial.TexturePath = (fileData + offset); + newMaterial.TexturePath = "Textures/"; + newMaterial.TexturePath += (fileData + offset); + newMaterial.TexturePath += ".png"; offset += nameLengths[0]; } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index f86fea43..983b0736 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -101,10 +101,10 @@ void Renderer::Draw(RenderFrame& frame) m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras. FillDepth(*scene); - //m_PickingPass->Draw(*scene); - //m_LightCullingPass->GenerateNewFrustum(*scene); - //m_LightCullingPass->FillLightList(*scene); - //m_LightCullingPass->CullLights(*scene); + m_PickingPass->Draw(*scene); + m_LightCullingPass->GenerateNewFrustum(*scene); + m_LightCullingPass->FillLightList(*scene); + m_LightCullingPass->CullLights(*scene); m_DrawFinalPass->Draw(*scene); //m_DrawScenePass->Draw(rq); diff --git a/tools/MayaExporter/MayaExporter/Mesh.h b/tools/MayaExporter/MayaExporter/Mesh.h index 0538e83c..11f6bcf8 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.h +++ b/tools/MayaExporter/MayaExporter/Mesh.h @@ -69,9 +69,10 @@ public: for (auto aVertex : Vertices) { aVertex.WriteBinary(out); } - //for (auto aIndex : Indices) { - for (std::map>::reverse_iterator aIndex = Indices.rbegin(); aIndex != Indices.rend(); aIndex++){ - out.write((char*)(*aIndex).second.data(), sizeof(int) * (*aIndex).second.size()); + for (auto aIndex : Indices) { + //for (std::map>::reverse_iterator aIndex = Indices.rbegin(); aIndex != Indices.rend(); aIndex++){ + //out.write((char*)(*aIndex).second.data(), sizeof(int) * (*aIndex).second.size()); + out.write((char*)aIndex.second.data(), sizeof(int) * aIndex.second.size()); } } From 386e76f6422ad206be119af06c90b590f42bcc35 Mon Sep 17 00:00:00 2001 From: antc13 Date: Wed, 20 Jan 2016 09:49:54 +0100 Subject: [PATCH 19/28] Puyshing --- src/Engine/Editor/EditorSystem.cpp | 14 +++++++------- src/Engine/Network/Client.cpp | 2 +- src/Engine/Network/Server.cpp | 2 +- src/Engine/Rendering/RenderSystem.cpp | 4 ++-- src/Engine/Sound/SoundSystem.cpp | 2 +- src/Tests/CollisionTest.cpp | 10 +++++----- src/Tests/HealthSystemTest.cpp | 4 ++-- src/Tests/OctTreeTestGameClass.cpp | 2 +- src/Tests/OctTreeTestHardCodedTestWorld.h | 4 ++-- src/Tests/OldOctTree.cpp | 2 +- src/Tests/ResourceManagerTest.cpp | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 2790ebbb..624c4ad6 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -292,21 +292,21 @@ void EditorSystem::createWidget() m_WidgetPlaneX = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneX, "Transform"); m_World->AttachComponent(m_WidgetPlaneX, "Model"); - m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube"; + m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube"; // 360NoScope widgetPlaneX m_WidgetY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetY, "Transform"); m_World->AttachComponent(m_WidgetY, "Model"); m_WidgetPlaneY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneY, "Transform"); m_World->AttachComponent(m_WidgetPlaneY, "Model"); - m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube"; + m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube"; // 360NoScope widgetPlaneY m_WidgetZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetZ, "Transform"); m_World->AttachComponent(m_WidgetZ, "Model"); m_WidgetPlaneZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneZ, "Transform"); m_World->AttachComponent(m_WidgetPlaneZ, "Model"); - m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube"; + m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube"; // 360NoScope widgetPlaneZ m_WidgetOrigin = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetOrigin, "Transform"); m_World->AttachComponent(m_WidgetOrigin, "Model"); @@ -351,7 +351,7 @@ void EditorSystem::setWidgetMode(WidgetMode newMode) m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = false; if (newMode == WidgetMode::Translate) { - //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/TranslationWidgetX.obj"; + //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/TranslationWidgetX.obj"; // 360NoScope TranslationWidgets mesh //m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/TranslationWidgetY.obj"; //m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/TranslationWidgetZ.obj"; // Temporarily disabled for local space until I can figure out what's wrong with the math @@ -367,17 +367,17 @@ void EditorSystem::setWidgetMode(WidgetMode newMode) } } } else if (newMode == WidgetMode::Scale) { - //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/ScaleWidgetX.obj"; + //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/ScaleWidgetX.obj"; // 360NoScope ScaleWidgets mesh //m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/ScaleWidgetY.obj"; //m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/ScaleWidgetZ.obj"; m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = true; - //m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.obj"; + //m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.obj"; // 360NoScope ScaleWidgetOrigin mesh if (m_Selection != EntityID_Invalid) { auto selectionTransform = m_World->GetComponent(m_Selection, "Transform"); widgetTransform["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(m_World, m_Selection)); } } else if (newMode == WidgetMode::Rotate) { - //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.obj"; + //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.obj"; // 360NoScope RotationWidget mesh //m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/RotationWidgetY.obj"; //m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/RotationWidgetZ.obj"; if (m_Selection != EntityID_Invalid) { diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index b8849ed0..efd25120 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -331,7 +331,7 @@ EntityID Client::createPlayer() EntityID entityID = m_World->CreateEntity(); ComponentWrapper transform = m_World->AttachComponent(entityID, "Transform"); ComponentWrapper model = m_World->AttachComponent(entityID, "Model"); - model["Resource"] = "Models/Core/UnitSphere.obj"; + model["Resource"] = "Models/Core/UnitSphere.obj"; // 360NoScope UnitSphere mesh ComponentWrapper player = m_World->AttachComponent(entityID, "Player"); return entityID; } diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index 07fed65b..367f444b 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -349,7 +349,7 @@ EntityID Server::createPlayer() ComponentWrapper transform = m_World->AttachComponent(entityID, "Transform"); transform["Position"] = glm::vec3(-1.5f, 0.f, 0.f); ComponentWrapper model = m_World->AttachComponent(entityID, "Model"); - model["Resource"] = "Models/Core/UnitSphere.obj"; + model["Resource"] = "Models/Core/UnitSphere.obj"; // 360NoScope UnitSphere model["Color"] = glm::vec4(rand()%255 / 255.f, rand()%255 / 255.f, rand() %255 / 255.f, 1.f); ComponentWrapper player = m_World->AttachComponent(entityID, "Player"); return entityID; diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index d243afff..1b016f73 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -96,10 +96,10 @@ void RenderSystem::fillModels(std::list>& jobs, World model = ResourceManager::Load<::Model, true>(resource); } catch (const Resource::StillLoadingException&) { //continue; - model = ResourceManager::Load<::Model>("Models/coolCube"); + model = ResourceManager::Load<::Model>("Models/coolCube"); // 360NoScope StillLoading mesh } catch (const std::exception&) { try { - model = ResourceManager::Load<::Model>("Models/coolCube"); + model = ResourceManager::Load<::Model>("Models/coolCube"); // 360NoScope Error mesh } catch (const std::exception&) { continue; } diff --git a/src/Engine/Sound/SoundSystem.cpp b/src/Engine/Sound/SoundSystem.cpp index 1292e0b1..2494581d 100644 --- a/src/Engine/Sound/SoundSystem.cpp +++ b/src/Engine/Sound/SoundSystem.cpp @@ -198,7 +198,7 @@ bool SoundSystem::OnPlaySoundOnPosition(const Events::PlaySoundOnPosition & e) (float&)(double)emitter["RollOffFactor"] = e.RollOffFactor; (float&)(double)emitter["ReferenceDistance"] = e.ReferenceDistance; auto model = m_World->AttachComponent(emitterID, "Model"); - (std::string&)model["Resource"] = "Models/Core/UnitCube.obj"; + (std::string&)model["Resource"] = "Models/Core/UnitCube.obj"; // 360NoScope UnitCube source->Type = SoundType::SFX; m_Sources[emitterID] = source; playSound(source); diff --git a/src/Tests/CollisionTest.cpp b/src/Tests/CollisionTest.cpp index 9f400330..4ba7ca87 100644 --- a/src/Tests/CollisionTest.cpp +++ b/src/Tests/CollisionTest.cpp @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(collisionTest2) BOOST_AUTO_TEST_CASE(rayVsModelTest) { //simple box test - RayTest("Models/Core/UnitCube.obj"); + RayTest("Models/Core/UnitCube.obj"); // 360NoScope Unitcube } BOOST_AUTO_TEST_CASE(rayVsModelTest2) @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) someAABB = AABB(minPos, maxPos); //using a rawmodel here, else we have to init the renderingsystem ResourceManager::RegisterType("RawModel"); - auto unitBox = ResourceManager::Load("Models/Core/UnitCube.obj"); + auto unitBox = ResourceManager::Load("Models/Core/UnitCube.obj"); // 360NoScope unitcube BOOST_CHECK(unitBox != nullptr); for (size_t i = 0; i < 1000000; i++) @@ -187,19 +187,19 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) BOOST_AUTO_TEST_CASE(rayVsModelTest3) { //simple test - RayTest("Models/Core/UnitSphere.obj"); + RayTest("Models/Core/UnitSphere.obj"); // 360NoScope unitSphere } BOOST_AUTO_TEST_CASE(rayVsModelTest4) { //simple test - RayTest("Models/Core/UnitCylinder.obj"); + RayTest("Models/Core/UnitCylinder.obj"); // 360NoScope unitCylinder } BOOST_AUTO_TEST_CASE(rayVsModelTest5) { //simple test - RayTest("Models/Core/UnitRaptor.obj"); + RayTest("Models/Core/UnitRaptor.obj"); // 360NoScope unitRaptor } BOOST_AUTO_TEST_CASE(octTest) { diff --git a/src/Tests/HealthSystemTest.cpp b/src/Tests/HealthSystemTest.cpp index 84d6199d..7c3ad641 100644 --- a/src/Tests/HealthSystemTest.cpp +++ b/src/Tests/HealthSystemTest.cpp @@ -55,7 +55,7 @@ GameHealthSystemTest::GameHealthSystemTest() EntityID playerID = m_World->CreateEntity(); ComponentWrapper transform = m_World->AttachComponent(playerID, "Transform"); ComponentWrapper model = m_World->AttachComponent(playerID, "Model"); - model["Resource"] = "Models/Core/UnitSphere.obj"; + model["Resource"] = "Models/Core/UnitSphere.obj"; // 360NoScope UnitSphere ComponentWrapper player = m_World->AttachComponent(playerID, "Player"); ComponentWrapper health = m_World->AttachComponent(playerID, "Health"); healthsID = playerID; @@ -80,7 +80,7 @@ GameHealthSystemTest::GameHealthSystemTest() EntityID playerID2 = m_World->CreateEntity(); ComponentWrapper transform2 = m_World->AttachComponent(playerID2, "Transform"); ComponentWrapper model2 = m_World->AttachComponent(playerID2, "Model"); - model2["Resource"] = "Models/Core/UnitSphere.obj"; + model2["Resource"] = "Models/Core/UnitSphere.obj"; // 360NoScope UnitSphere ComponentWrapper player2 = m_World->AttachComponent(playerID2, "Player"); ComponentWrapper health2 = m_World->AttachComponent(playerID2, "Health"); //END TEST diff --git a/src/Tests/OctTreeTestGameClass.cpp b/src/Tests/OctTreeTestGameClass.cpp index 2c45d897..d03153e7 100644 --- a/src/Tests/OctTreeTestGameClass.cpp +++ b/src/Tests/OctTreeTestGameClass.cpp @@ -149,7 +149,7 @@ void Game::Tick() ComponentWrapper transform = m_World->AttachComponent(m_BoxID, "Transform"); transform["Scale"] = boxSize; ComponentWrapper model = m_World->AttachComponent(m_BoxID, "Model"); - model["Resource"] = "Models/Core/UnitBox.obj"; + model["Resource"] = "Models/Core/UnitBox.obj"; // 360NoScope UnitBox m_World->createTestEntitiesTest2(); } diff --git a/src/Tests/OctTreeTestHardCodedTestWorld.h b/src/Tests/OctTreeTestHardCodedTestWorld.h index db0b3b3c..89c3c3f3 100644 --- a/src/Tests/OctTreeTestHardCodedTestWorld.h +++ b/src/Tests/OctTreeTestHardCodedTestWorld.h @@ -112,7 +112,7 @@ private: ComponentWrapper transform = world.AttachComponent(entityCollisionBox, "Transform"); transform["Position"] = glm::vec3(0.f, 2.f, 0.f); ComponentWrapper model = world.AttachComponent(entityCollisionBox, "Model"); - model["Resource"] = "Models/Core/UnitBox.obj"; + model["Resource"] = "Models/Core/UnitBox.obj"; // 360NoScope UnitBox } void AddBoxModel(const glm::vec3 ¢er, const float &halfSize, Octree::Child* child, EntityID &outEntityId) { @@ -124,7 +124,7 @@ private: transform["Position"] = center; transform["Scale"] = glm::vec3(1.0f, 1.0f, 1.0f)*halfSize*2.0f*0.97f; ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model"); - model["Resource"] = "Models/Core/UnitBox.obj"; + model["Resource"] = "Models/Core/UnitBox.obj"; // 360NoScope unitBox model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); if (child->m_DynamicObjIndices.size() != 0) model["Color"] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); diff --git a/src/Tests/OldOctTree.cpp b/src/Tests/OldOctTree.cpp index 0fb92e18..a94bf465 100644 --- a/src/Tests/OldOctTree.cpp +++ b/src/Tests/OldOctTree.cpp @@ -112,7 +112,7 @@ void OctTree::Update(float dt, World* world, Camera* cam) ComponentWrapper transform = world->AttachComponent(m_BoxID, "Transform"); transform["Scale"] = boxSize; ComponentWrapper model = world->AttachComponent(m_BoxID, "Model"); - model["Resource"] = "Models/Core/UnitBox.obj"; + model["Resource"] = "Models/Core/UnitBox.obj"; // 360NoScope UnitBox m_UpdatedOnce = true; } diff --git a/src/Tests/ResourceManagerTest.cpp b/src/Tests/ResourceManagerTest.cpp index 9d62fa93..f83c6c9f 100644 --- a/src/Tests/ResourceManagerTest.cpp +++ b/src/Tests/ResourceManagerTest.cpp @@ -26,7 +26,7 @@ BOOST_AUTO_TEST_CASE(resourceManagerTest) //configfile without register //check so output says "EE failed to load: type not registered..." - auto m_ScreenQuadNoRegister = ResourceManager::Load("Models/Core/ScreenQuad.obj"); + auto m_ScreenQuadNoRegister = ResourceManager::Load("Models/Core/ScreenQuad.obj"); // 360NoScope ScreenQuad BOOST_CHECK(!ResourceManager::IsResourceLoaded("Model", "Models/Core/ScreenQuad.obj")); //there is no error feedback to check if you try to release the wrong resources - hence that cant be tested either From 84b7cf165c449d9ec48d8882c519545a42112bd2 Mon Sep 17 00:00:00 2001 From: antc13 Date: Wed, 20 Jan 2016 11:46:32 +0100 Subject: [PATCH 20/28] Reduced the chance of crashing in Export. --- tools/MayaExporter/MayaExporter/Mesh.cpp | 154 ++++++++++++++++++----- 1 file changed, 125 insertions(+), 29 deletions(-) diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index 0f99533c..2062bad5 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -10,22 +10,43 @@ MeshClass::MeshClass() std::map MeshClass::GetWeightData() { + MS status; map weightMap; MItDependencyNodes it(MFn::kSkinClusterFilter); while (!it.isDone()) { - MObject object = it.item(); - MFnSkinCluster skinCluster(object); + MObject object = it.thisNode(&status); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + " it.thisNode() ERROR: " + status.errorString()); + break; + } + MFnSkinCluster skinCluster(object, &status); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "skinCluster() ERROR: " + status.errorString()); + break; + } MDagPathArray influences; - unsigned int nrOfInfluences = skinCluster.influenceObjects(influences); + unsigned int nrOfInfluences = skinCluster.influenceObjects(influences,&status); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "skinCluster.influenceObjects() ERROR: " + status.errorString()); + break; + } unsigned int index; - index = skinCluster.indexForOutputConnection(0); + index = skinCluster.indexForOutputConnection(0,&status); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "skinCluster.indexForOutputConnection() ERROR: " + status.errorString()); + break; + } MDagPath skinPath; - skinCluster.getPathAtIndex(index, skinPath); + status = skinCluster.getPathAtIndex(index, skinPath); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "skinCluster.getPathAtIndex() ERROR: " + status.errorString()); + break; + } MItGeometry geomIter(skinPath); //for (unsigned int i = 0; i < nrOfInfluences; i++) { @@ -34,10 +55,18 @@ std::map MeshClass::GetWeightData() WeightInfo weightInfo; while (!geomIter.isDone()) { - MObject comp = geomIter.component(); + MObject comp = geomIter.component(&status); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "geomIter.component() ERROR: " + status.errorString()); + break; + } MFloatArray weights; unsigned int influenceCount; - skinCluster.getWeights(skinPath, comp, weights, influenceCount); + status = skinCluster.getWeights(skinPath, comp, weights, influenceCount); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "skinCluster.getWeights() ERROR: " + status.errorString()); + break; + } MFnDependencyNode test(comp); unsigned int nrOfWeights = 0; @@ -64,10 +93,7 @@ std::map MeshClass::GetWeightData() //MGlobal::displayInfo(MString() + "influence: " + weightInfo.BoneIndices[k] + " weight: " + weightInfo.BoneWeights[k]); } geomIter.next(); - - } - it.next(); } return weightMap; @@ -75,6 +101,7 @@ std::map MeshClass::GetWeightData() Mesh MeshClass::GetMeshData(MObjectArray object) { + MS status; Mesh newMesh; vector& vertexList = newMesh.Vertices; map>& indexLists = newMesh.Indices; @@ -85,11 +112,21 @@ Mesh MeshClass::GetMeshData(MObjectArray object) // In here, we retrieve triangulated polygons from the mesh MFnMesh mesh(object[ObjectID]); MDagPathArray dagPaths; - MDagPath::getAllPathsTo(object[ObjectID], dagPaths); + status = MDagPath::getAllPathsTo(object[ObjectID], dagPaths); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "MDagPath::getAllPathsTo() ERROR: " + status.errorString()); + break; + } + for (int pathID = 0; pathID < dagPaths.length(); pathID++) { MGlobal::displayInfo(dagPaths[pathID].fullPathName()); MDagPath thisMeshPath(dagPaths[pathID]); - MMatrix transformMatrix = thisMeshPath.inclusiveMatrix(); + + MMatrix transformMatrix = thisMeshPath.inclusiveMatrix(&status); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "thisMeshPath.inclusiveMatrix() ERROR: " + status.errorString() + " for " + thisMeshPath.fullPathName()); + break; + } map> vertexToIndex;; @@ -106,28 +143,57 @@ Mesh MeshClass::GetMeshData(MObjectArray object) MObjectArray shaderList; MIntArray shaderIndexList; - mesh.getConnectedShaders(0, shaderList, shaderIndexList); + status = mesh.getConnectedShaders(0, shaderList, shaderIndexList); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "mesh.getConnectedShaders() ERROR: " + status.errorString() + " for " + thisMeshPath.fullPathName()); + break; + } + if (shaderList.length() == 0) { + MGlobal::displayError(MString() + "Object: \"" + thisMeshPath.fullPathName() + "\" have no material and will not be exported"); + break; + } map> materialFaceIDs; MGlobal::displayInfo(MString() + "shaderIndexList: " + shaderIndexList.length()); MGlobal::displayInfo(MString() + "shaderList: " + shaderList.length()); MPlugArray plugArray; for (int i = 0; i < shaderIndexList.length(); i++) { MFnDependencyNode shader(shaderList[shaderIndexList[i]]); - MPlug p_Plug = shader.findPlug("surfaceShader"); - if (p_Plug.connectedTo(plugArray, true, false)) { + MPlug p_Plug = shader.findPlug("surfaceShader", status); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "shader.findPlug(\"surfaceShader\") ERROR: " + status.errorString() + " for " + thisMeshPath.fullPathName()); + continue; + } + if (p_Plug.connectedTo(plugArray, true, false, &status)) { + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "p_Plug.connectedTo() ERROR in if: " + status.errorString() + " for " + thisMeshPath.fullPathName()); + continue; + } MFnDependencyNode node = plugArray[0].node(); materialFaceIDs[node.name().asChar()].push_back(i); } + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "p_Plug.connectedTo() ERROR: " + status.errorString() + " for " + thisMeshPath.fullPathName()); + continue; + } } map vertexWeights = GetWeightData(); - - mesh.getTangents(Tangents, MSpace::kTransform, NULL); - mesh.getBinormals(biNormals, MSpace::kTransform, NULL); - + status = mesh.getTangents(Tangents, MSpace::kObject); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "mesh.getTangents ERROR: " + status.errorString() + " for " + thisMeshPath.fullPathName()); + continue; + } + status = mesh.getBinormals(biNormals, MSpace::kObject); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "mesh.getBinormals ERROR: " + status.errorString() + " for " + thisMeshPath.fullPathName()); + continue; + } + if(Tangents.length() == 0 || biNormals.length() == 0){ + MGlobal::displayError(MString() + "Unknown ERROR with " + thisMeshPath.fullPathName()); + continue; + } MItMeshFaceVertex faceVert(object[ObjectID]); - int intDummy = 0; MItMeshPolygon meshPolyIter(object[ObjectID]); @@ -137,17 +203,40 @@ Mesh MeshClass::GetMeshData(MObjectArray object) for (auto aMaterial : materialFaceIDs) { for (auto faceID : aMaterial.second) { - vector> localVertexToGlobalIndex; - meshPolyIter.setIndex(faceID, intDummy); - meshPolyIter.getVertices(vertices); - meshPolyIter.getTriangles(dummy, triangleList); + status = meshPolyIter.setIndex(faceID, intDummy); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + " meshPolyIter.setIndex() ERROR: " + status.errorString() + " for faceID " + faceID + " in mesh " + thisMeshPath.fullPathName()); + break; + } + + status = meshPolyIter.getVertices(vertices); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + " meshPolyIter.getVertices() ERROR: " + status.errorString() + " for faceID " + faceID + " in mesh " + thisMeshPath.fullPathName()); + break; + } + + status = meshPolyIter.getTriangles(dummy, triangleList); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + " meshPolyIter.getTriangles() ERROR: " + status.errorString() + " for faceID " + faceID + " in mesh " + thisMeshPath.fullPathName()); + break; + } //MGlobal::displayInfo("Befor Second Loop"); for (unsigned int i = 0; i < vertices.length(); i++) { VertexLayout thisVertex; - vertexIndex = meshPolyIter.vertexIndex(i); - faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); + + vertexIndex = meshPolyIter.vertexIndex(i, &status); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + " meshPolyIter.vertexIndex() ERROR: " + status.errorString() + "for local vertex " + i + " in " + faceID + " in mesh " + thisMeshPath.fullPathName()); + break; + } + + status = faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "faceVert.setIndex() ERROR: " + status.errorString() + "for local vertex " + i + " in " + faceID + " in mesh " + thisMeshPath.fullPathName()); + break; + } //MGlobal::displayInfo("In Second Loop"); //pos = faceVert.position(MSpace::kTransform); //mesh.getPoint(vertexIndex, pos, MSpace::kPostTransform); @@ -160,7 +249,11 @@ Mesh MeshClass::GetMeshData(MObjectArray object) if (abs(pos.z) > 0.0001) thisVertex.Pos[2] = pos.z; - faceVert.getNormal(normal, MSpace::kTransform); + status = faceVert.getNormal(normal, MSpace::kObject); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "faceVert.getNormal() ERROR: " + status.errorString() + "for local vertex " + i + " in " + faceID + " in mesh " + thisMeshPath.fullPathName()); + break; + } if (abs(normal[0]) > 0.0001) thisVertex.Normal[0] = normal[0]; if (abs(normal[1]) > 0.0001) @@ -187,7 +280,11 @@ Mesh MeshClass::GetMeshData(MObjectArray object) if (abs(biNormal[2]) > 0.0001) thisVertex.BiNormal[2] = biNormal[2]; - faceVert.getUV(UV); + status = faceVert.getUV(UV); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + " faceVert.getUV() ERROR: " + status.errorString() + "for local vertex " + i + " in " + faceID + " in mesh " + thisMeshPath.fullPathName()); + break; + } thisVertex.Uv[0] = UV[0]; thisVertex.Uv[1] = UV[1]; @@ -195,7 +292,6 @@ Mesh MeshClass::GetMeshData(MObjectArray object) thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1]; thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2]; thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3]; - if (abs(vertexWeights[faceVert.vertId()].BoneWeights[0]) > 0.0001) thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0]; if (abs(vertexWeights[faceVert.vertId()].BoneWeights[1]) > 0.0001) From c984f76b2fea45d0e7b67fd3eb44a75df3fcdb55 Mon Sep 17 00:00:00 2001 From: antc13 Date: Wed, 20 Jan 2016 18:36:03 +0100 Subject: [PATCH 21/28] Importing & Reading Custom animation data. TODO: Shaders. --- include/Engine/Rendering/RawModelCustom.h | 9 +- include/Engine/Rendering/Skeleton.h | 2 +- resources/Schema/Entities/Model.xml | 2 +- src/Engine/Editor/EditorSystem.cpp | 6 +- src/Engine/Rendering/RawModelCustom.cpp | 180 ++++++++++++++++++- src/Engine/Rendering/RenderSystem.cpp | 4 +- tools/MayaExporter/MayaExporter/Export.cpp | 13 +- tools/MayaExporter/MayaExporter/Skeleton.cpp | 9 +- tools/MayaExporter/MayaExporter/Skeleton.h | 44 +++-- 9 files changed, 230 insertions(+), 39 deletions(-) diff --git a/include/Engine/Rendering/RawModelCustom.h b/include/Engine/Rendering/RawModelCustom.h index bc85e32c..a3c29f62 100644 --- a/include/Engine/Rendering/RawModelCustom.h +++ b/include/Engine/Rendering/RawModelCustom.h @@ -22,7 +22,7 @@ class RawModel : public Resource friend class ResourceManager; protected: - RawModel(std::string& fileName); + RawModel(std::string fileName); public: ~RawModel(); @@ -74,6 +74,13 @@ private: void ReadMaterialFile(std::string filePath); void ReadMaterials(unsigned int &offset, char* fileData, unsigned int& fileByteSize); void ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize); + + void ReadAnimationFile(std::string filePath); + void ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsigned int& fileByteSize); + void ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize); + void ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips); + void ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex); + void ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfJoints, Skeleton::Animation& animation); //void CreateSkeleton(std::vector> &boneInfo, std::map &boneNameMapping, aiNode* node, int parentID); }; diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index 73d407dd..4a4d507b 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -38,9 +38,9 @@ public: , OffsetMatrix(offsetMatrix) { } - int ID; std::string Name; glm::mat4 OffsetMatrix; + int ID; Bone* Parent; std::vector Children; diff --git a/resources/Schema/Entities/Model.xml b/resources/Schema/Entities/Model.xml index 8962d7e1..6534815c 100644 --- a/resources/Schema/Entities/Model.xml +++ b/resources/Schema/Entities/Model.xml @@ -19,7 +19,7 @@ - models/Baljj + models/Baljj.mesh diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 624c4ad6..547a96e1 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -292,21 +292,21 @@ void EditorSystem::createWidget() m_WidgetPlaneX = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneX, "Transform"); m_World->AttachComponent(m_WidgetPlaneX, "Model"); - m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube"; // 360NoScope widgetPlaneX + m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneX m_WidgetY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetY, "Transform"); m_World->AttachComponent(m_WidgetY, "Model"); m_WidgetPlaneY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneY, "Transform"); m_World->AttachComponent(m_WidgetPlaneY, "Model"); - m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube"; // 360NoScope widgetPlaneY + m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneY m_WidgetZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetZ, "Transform"); m_World->AttachComponent(m_WidgetZ, "Model"); m_WidgetPlaneZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneZ, "Transform"); m_World->AttachComponent(m_WidgetPlaneZ, "Model"); - m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube"; // 360NoScope widgetPlaneZ + m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneZ m_WidgetOrigin = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetOrigin, "Transform"); m_World->AttachComponent(m_WidgetOrigin, "Model"); diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index b7f2a2fd..f7354d92 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -1,9 +1,12 @@ #include "Rendering/RawModelCustom.h" -RawModel::RawModel(std::string& fileName) +RawModel::RawModel(std::string fileName) { + fileName = fileName.erase(fileName.find_last_of("."), fileName.find_last_of(".") - fileName.size()); ReadMeshFile(fileName); ReadMaterialFile(fileName); + ReadAnimationFile(fileName); + int k = 0; } void RawModel::ReadMeshFile(std::string filePath) @@ -53,8 +56,7 @@ void RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) { throw Resource::FailedLoadingException("Reading vertices failed"); } - unsigned int i = sizeof(Vertex); - unsigned int ii = sizeof(unsigned int); + memcpy(&m_Vertices[0], fileData + offset, m_Vertices.size() * sizeof(Vertex)); offset += m_Vertices.size() * sizeof(Vertex); #else @@ -187,6 +189,178 @@ void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned MaterialGroups.push_back(newMaterial); } +void RawModel::ReadAnimationFile(std::string filePath) +{ + char* fileData; + filePath += ".anim"; + std::ifstream in(filePath.c_str(), std::ios_base::binary | std::ios_base::ate); + + if (!in.is_open()) { + //throw Resource::FailedLoadingException("Open animation file failed"); + return; // AJABAJA!!!!!!!! + } + + unsigned int fileByteSize = in.tellg(); + in.seekg(0, std::ios_base::beg); + + fileData = new char[fileByteSize]; + in.read(fileData, fileByteSize); + in.close(); + + unsigned int offset = 0; + if (fileByteSize > 0) { + m_Skeleton = new Skeleton(); + +#ifdef BOOST_LITTLE_ENDIAN + unsigned int numBindPoses = *(unsigned int*)(fileData); + offset += sizeof(unsigned int); + unsigned int numAnimations = *(unsigned int*)(fileData); + offset += sizeof(unsigned int); +#else +#endif + + ReadAnimationBindPoses(offset, fileData, fileByteSize); + ReadAnimationClips(offset, fileData, fileByteSize, numAnimations); + } + delete fileData; +} + +void RawModel::ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsigned int& fileByteSize) +{ +#ifdef BOOST_LITTLE_ENDIAN + unsigned int* numBones = (unsigned int*)(fileData + offset); + offset += sizeof(unsigned int); + + for (unsigned int i = 0; i < *numBones; i++) { + ReadAnimationJoint(offset, fileData, fileByteSize); + } +#else +#endif +} + +void RawModel::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize) +{ +#ifdef BOOST_LITTLE_ENDIAN + if (offset + sizeof(unsigned int) > fileByteSize) { + throw Resource::FailedLoadingException("Reading Joint name length failed"); + } + unsigned int jointNameLength = *(unsigned int*)(fileData + offset); + offset += sizeof(unsigned int); + + if (offset + jointNameLength > fileByteSize) { + throw Resource::FailedLoadingException("Reading Joint name failed"); + } + std::string jointName = (fileData + offset); + offset += jointNameLength; + + if (offset + sizeof(float) * 4 * 4 > fileByteSize) { + throw Resource::FailedLoadingException("Reading Joint offset matrix failed"); + } + glm::mat4 offsetMatrix; + memcpy(&offsetMatrix, fileData + offset, sizeof(float) * 4 * 4); + offset += sizeof(float) * 4 * 4; + + if (offset + sizeof(int) > fileByteSize) { + throw Resource::FailedLoadingException("Reading Joint ID failed"); + } + int jointID = *(int*)(fileData + offset); + offset += sizeof(int); + + if (offset + sizeof(int) > fileByteSize) { + throw Resource::FailedLoadingException("Reading Joint Parent ID failed"); + } + int jointParentID = *(int*)(fileData + offset); + offset += sizeof(int); + + // Adding joint to the Skeleton + m_Skeleton->CreateBone(jointID, jointParentID, jointName, offsetMatrix); + + +#else +#endif +} + +void RawModel::ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips) +{ + for (unsigned int i = 0; i < numberOfClips; i++) { + ReadAnimationClipSingle(offset, fileData, fileByteSize, i); + } +} + +void RawModel::ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex) +{ +#ifdef BOOST_LITTLE_ENDIAN + Skeleton::Animation newAnimation; + + if (offset + sizeof(unsigned int) > fileByteSize) { + throw Resource::FailedLoadingException("Reading AnimationClip name length failed"); + } + unsigned int clipNameLength = *(unsigned int*)(fileData + offset); + offset += sizeof(unsigned int); + + if (offset + clipNameLength > fileByteSize) { + throw Resource::FailedLoadingException("Reading AnimationClip name failed"); + } + newAnimation.Name = (fileData + offset); + offset += clipNameLength; + + if (offset + sizeof(float) > fileByteSize) { + throw Resource::FailedLoadingException("Reading AnimationClip duration failed"); + } + + newAnimation.Duration = *(float*)(fileData + offset); + offset += sizeof(float); + + if (offset + sizeof(unsigned int) > fileByteSize) { + throw Resource::FailedLoadingException("Reading AnimationClip NrOfKeyframes failed"); + } + unsigned int nrOfKeyframes = *(unsigned int*)(fileData + offset); + offset += sizeof(unsigned int); + + if (offset + sizeof(unsigned int) > fileByteSize) { + throw Resource::FailedLoadingException("Reading AnimationClip NrOfJoints failed"); + } + unsigned int nrOfJoints = *(unsigned int*)(fileData + offset); + offset += sizeof(unsigned int); + + newAnimation.Keyframes.reserve(nrOfKeyframes); + for (unsigned int i = 0; i < nrOfKeyframes; i++) { + ReadAnimationKeyFrame(offset, fileData, fileByteSize, nrOfJoints, newAnimation); + } + m_Skeleton->Animations[newAnimation.Name] = newAnimation; +#else +#endif +} + +void RawModel::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int nrOfJoints, Skeleton::Animation& animation) +{ + Skeleton::Animation::Keyframe newKeyFrame; + + if (offset + sizeof(int) > fileByteSize) { + throw Resource::FailedLoadingException("Reading AnimationKeyFrame index failed"); + } + newKeyFrame.Index = *(int*)(fileData + offset); + offset += sizeof(int); + + if (offset + sizeof(float) > fileByteSize) { + throw Resource::FailedLoadingException("Reading AnimationKeyFrame time failed"); + } + newKeyFrame.Time = *(float*)(fileData + offset); + offset += sizeof(float); + + if (offset + sizeof(Skeleton::Animation::Keyframe::BoneProperty) * nrOfJoints> fileByteSize) { + throw Resource::FailedLoadingException("Reading AnimationKeyFrame joints failed"); + } + + Skeleton::Animation::Keyframe::BoneProperty newBone; + for (unsigned int i = 0; i < nrOfJoints; i++) { + memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty)); + offset += sizeof(Skeleton::Animation::Keyframe::BoneProperty); + newKeyFrame.BoneProperties[i] = newBone; + } + animation.Keyframes.push_back(newKeyFrame); +} + RawModel::~RawModel() { diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 1b016f73..2a6a49c2 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -96,10 +96,10 @@ void RenderSystem::fillModels(std::list>& jobs, World model = ResourceManager::Load<::Model, true>(resource); } catch (const Resource::StillLoadingException&) { //continue; - model = ResourceManager::Load<::Model>("Models/coolCube"); // 360NoScope StillLoading mesh + model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope StillLoading mesh } catch (const std::exception&) { try { - model = ResourceManager::Load<::Model>("Models/coolCube"); // 360NoScope Error mesh + model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope Error mesh } catch (const std::exception&) { continue; } diff --git a/tools/MayaExporter/MayaExporter/Export.cpp b/tools/MayaExporter/MayaExporter/Export.cpp index 1db753d7..d25faa4c 100644 --- a/tools/MayaExporter/MayaExporter/Export.cpp +++ b/tools/MayaExporter/MayaExporter/Export.cpp @@ -11,7 +11,9 @@ bool Export::Meshes(std::string pathName, bool selectedOnly) MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file"); return false; } - + MSelectionList selectedOnStart; + MGlobal::getActiveSelectionList(selectedOnStart); + MObjectArray Objects; if (selectedOnly) { // Retrieving the objects we currently have selected @@ -36,18 +38,14 @@ bool Export::Meshes(std::string pathName, bool selectedOnly) 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; + MGlobal::select(node); + MGlobal::executeCommand("gotoBindPose"); } } - if (next) - continue; - Objects.append(node); } } @@ -139,6 +137,7 @@ void Export::WriteAnimData(std::string pathName) int size = allBindPoses.size(); m_AnimFile.writeToFiles(&size); + size = allAnimations.size(); m_AnimFile.writeToFiles(&size); diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp index 0497aa31..9f887561 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.cpp +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -70,6 +70,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e Animation returnData; double oneDivSixty = 1 / 60.0; returnData.Name = animationName; + returnData.nameLength = animationName.size() + 1; returnData.Duration = (endFrame - startFrame) * oneDivSixty; MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); @@ -132,7 +133,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e } int currentFrame = startFrame; - while (currentFrame != endFrame) { + while (currentFrame != endFrame + 1) { // ANDREAS Animation::Keyframe thisKeyFrame; thisKeyFrame.Index = currentFrame - startFrame; thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty; @@ -188,7 +189,6 @@ std::vector Skeleton::GetBindPoses() MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); BindPoseSkeletonNode SkeletonStorage; - while (!jointIt.isDone()) { MFnTransform MayaJoint(jointIt.currentItem()); BindPoseSkeletonNode::BindPoseJoint NewJoint; @@ -227,7 +227,8 @@ std::vector Skeleton::GetBindPoses() } NewJoint.Name = MayaJoint.name().asChar(); - + NewJoint.NameLength = MayaJoint.name().length() + 1; + NewJoint.ID = SkeletonStorage.Joints.size(); //double tmp[3]; //((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp); //NewJoint.Rotation[0] = tmp[0]; @@ -242,9 +243,9 @@ std::vector Skeleton::GetBindPoses() //NewJoint.Translation[1] = tmp[1]; //NewJoint.Translation[2] = tmp[2]; SkeletonStorage.Joints.push_back(NewJoint); + SkeletonStorage.numBones++; jointIt.next(); } - m_AllSkeletons.push_back(SkeletonStorage); return m_AllSkeletons; diff --git a/tools/MayaExporter/MayaExporter/Skeleton.h b/tools/MayaExporter/MayaExporter/Skeleton.h index dda0cfea..6a288c8a 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.h +++ b/tools/MayaExporter/MayaExporter/Skeleton.h @@ -13,32 +13,35 @@ public: { struct JointProperty { - int ID; - float Position[3]; - float Rotation[4]; - float Scale[3]; + int ID = 0; + float Position[3]{ 0 }; + float Rotation[4]{ 0 }; + float Scale[3]{ 0 }; }; - int Index; - double Time; + int Index = 0; + float Time = 0; std::vector JointProperties; }; std::string Name; - double Duration; - int NumKeyFrames; - int NumberOfJoints; + int nameLength = 0; + float Duration = 0; + int NumKeyFrames = 0; + int NumberOfJoints = 0; std::vector Keyframes; virtual void WriteBinary(std::ostream& out) { + out.write((char*)&nameLength, sizeof(int)); out.write(Name.c_str(), Name.size() + 1); - out.write((char*)&Duration, sizeof(double)); + out.write((char*)&Duration, sizeof(float)); out.write((char*)&NumKeyFrames, sizeof(int)); out.write((char*)&NumberOfJoints, sizeof(int)); + //Här under loopas alla key frames igenom for (auto aKeyframe : Keyframes) { out.write((char*)&aKeyframe.Index, sizeof(int)); - out.write((char*)&aKeyframe.Time, sizeof(double)); + out.write((char*)&aKeyframe.Time, sizeof(float)); for (auto aJoint : aKeyframe.JointProperties) { out.write((char*)&aJoint.ID, sizeof(int)); out.write((char*)aJoint.Position, sizeof(float) * 3); @@ -72,20 +75,24 @@ class BindPoseSkeletonNode : public OutputData { public: struct BindPoseJoint { - int ParentID; + int NameLength; std::string Name; - float OffsetMatrix[4][4]; + float OffsetMatrix[4][4]{ 0 }; + int ID = 0; + int ParentID = 0; }; - + int numBones = 0; std::string Name; std::vector Joints; virtual void WriteBinary(std::ostream& out) { - out.write(Name.c_str(), Name.size() + 1); + out.write((char*)&numBones, sizeof(int)); for (auto Joint:Joints) { + out.write((char*)&Joint.NameLength, sizeof(int)); out.write(Joint.Name.c_str(), Joint.Name.size() + 1); out.write((char*)&Joint.OffsetMatrix, sizeof(float) * 4 * 4); + out.write((char*)&Joint.ID, sizeof(int)); out.write((char*)&Joint.ParentID, sizeof(int)); } @@ -93,16 +100,19 @@ public: virtual void WriteASCII(std::ostream& out) const { - out << "Bind Pose: " << Name << endl; + out << "Bind Pose: " << Name << " _ not in binary" << endl; + out << "numberOfBones: " << numBones << endl; for (auto Joint : Joints) { - out << Joint.Name << endl; + out << "Joint NameLength " << Joint.NameLength << endl; + out << "Joint name " << Joint.Name << endl; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++){ out << Joint.OffsetMatrix[i][j] << " "; } out << endl; } + out << Joint.ID << endl; out << Joint.ParentID << endl; } }; From f1835fd89c2abcd9e069bc3e4074cd42db1db8ef Mon Sep 17 00:00:00 2001 From: antc13 Date: Sat, 23 Jan 2016 18:02:42 +0100 Subject: [PATCH 22/28] Animations PROBABLY works fine if all joints got keyframes. --- include/Engine/Collision/Collision.h | 4 +- .../Rendering/DebugCameraInputController.h | 2 +- include/Engine/Rendering/Model.h | 3 +- include/Engine/Rendering/RawModelAssimp.h | 11 +- include/Engine/Rendering/RawModelCustom.h | 17 ++- include/Engine/Rendering/Skeleton.h | 1 + resources/Schema/Entities/Model.xml | 2 +- resources/Shaders/ForwardPlus.vert.glsl | 13 ++- src/Engine/Editor/EditorSystem.cpp | 12 ++ src/Engine/Rendering/DrawFinalPass.cpp | 20 +++- src/Engine/Rendering/Model.cpp | 3 + src/Engine/Rendering/RawModelAssimp.cpp | 11 +- src/Engine/Rendering/RawModelCustom.cpp | 46 ++++---- src/Engine/Rendering/RenderSystem.cpp | 8 ++ src/Engine/Rendering/Skeleton.cpp | 9 +- src/Tests/CollisionTest.cpp | 4 +- tools/MayaExporter/MayaExporter/Export.cpp | 59 ++++++++-- .../MayaExporter/MayaExporter/MayaIncludes.h | 3 + tools/MayaExporter/MayaExporter/Menu.cpp | 16 +-- tools/MayaExporter/MayaExporter/Mesh.cpp | 61 ++++++---- tools/MayaExporter/MayaExporter/Skeleton.cpp | 104 ++++++++++++++++-- 21 files changed, 325 insertions(+), 84 deletions(-) diff --git a/include/Engine/Collision/Collision.h b/include/Engine/Collision/Collision.h index 207d4893..194a18dc 100644 --- a/include/Engine/Collision/Collision.h +++ b/include/Engine/Collision/Collision.h @@ -10,8 +10,8 @@ #include "../Core/Ray.h" #include "../Core/AABB.h" -//#include "Engine/Rendering/RawModelAssimp.h" -#include "Engine/Rendering/RawModelCustom.h" +#include "Rendering/RawModelCustom.h" +//#include "Rendering/RawModelAssimp.h" #include "../Core/Transform.h" #include "../Core/Entity.h" #include "../Core/EntityWrapper.h" diff --git a/include/Engine/Rendering/DebugCameraInputController.h b/include/Engine/Rendering/DebugCameraInputController.h index 4d74e288..d69098c2 100644 --- a/include/Engine/Rendering/DebugCameraInputController.h +++ b/include/Engine/Rendering/DebugCameraInputController.h @@ -61,6 +61,6 @@ public: protected: glm::vec3 m_Position = glm::vec3(0, 0, 0); glm::vec3 m_Velocity = glm::vec3(0, 0, 0); - float m_BaseSpeed = 2.0f; + float m_BaseSpeed = 50.0f;//2.0f; float m_Speed = m_BaseSpeed; }; \ No newline at end of file diff --git a/include/Engine/Rendering/Model.h b/include/Engine/Rendering/Model.h index 4b83562c..f751a8cc 100644 --- a/include/Engine/Rendering/Model.h +++ b/include/Engine/Rendering/Model.h @@ -1,7 +1,8 @@ #ifndef Model_h__ #define Model_h__ -#include "RawModelCustom.h" +#include "Rendering/RawModelCustom.h" +//#include "Rendering/RawModelAssimp.h" #include "../OpenGL.h" class Model : public ThreadUnsafeResource diff --git a/include/Engine/Rendering/RawModelAssimp.h b/include/Engine/Rendering/RawModelAssimp.h index 92258782..08df818d 100644 --- a/include/Engine/Rendering/RawModelAssimp.h +++ b/include/Engine/Rendering/RawModelAssimp.h @@ -1,6 +1,8 @@ #ifndef RawModelAssimp_h__ #define RawModelAssimp_h__ +#ifdef USING_ASSIMP_AS_IMPORTER + #include #include #include @@ -18,15 +20,17 @@ #include "Texture.h" #include "Skeleton.h" -class RawModel : public Resource +#define RawModel RawModelAssimp + +class RawModelAssimp : public Resource { friend class ResourceManager; protected: - RawModel(std::string fileName); + RawModelAssimp(std::string fileName); public: - ~RawModel(); + ~RawModelAssimp(); struct Vertex { @@ -72,3 +76,4 @@ private: }; #endif +#endif \ No newline at end of file diff --git a/include/Engine/Rendering/RawModelCustom.h b/include/Engine/Rendering/RawModelCustom.h index a3c29f62..2dea51ff 100644 --- a/include/Engine/Rendering/RawModelCustom.h +++ b/include/Engine/Rendering/RawModelCustom.h @@ -1,6 +1,10 @@ #ifndef RawModelCustom_h__ #define RawModelCustom_h__ +#ifndef USING_ASSIMP_AS_IMPORTER + +#define RawModel RawModelCustom + #include #include #include @@ -17,15 +21,17 @@ #include "boost\endian\buffers.hpp" -class RawModel : public Resource + + +class RawModelCustom : public Resource { friend class ResourceManager; protected: - RawModel(std::string fileName); + RawModelCustom(std::string fileName); public: - ~RawModel(); + ~RawModelCustom(); struct Vertex { @@ -85,4 +91,9 @@ private: //void CreateSkeleton(std::vector> &boneInfo, std::map &boneNameMapping, aiNode* node, int parentID); }; +#else + +#include "RawModelAssimp.h" + #endif +#endif \ No newline at end of file diff --git a/include/Engine/Rendering/Skeleton.h b/include/Engine/Rendering/Skeleton.h index 4a4d507b..3b89b89b 100644 --- a/include/Engine/Rendering/Skeleton.h +++ b/include/Engine/Rendering/Skeleton.h @@ -4,6 +4,7 @@ #include #include "Common.h" #include "../GLM.h" +#include //struct Bone //{ diff --git a/resources/Schema/Entities/Model.xml b/resources/Schema/Entities/Model.xml index 6534815c..57856cbd 100644 --- a/resources/Schema/Entities/Model.xml +++ b/resources/Schema/Entities/Model.xml @@ -19,7 +19,7 @@ - models/Baljj.mesh + models/animTest.mesh diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index e4b4eacc..aa8c9446 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -3,6 +3,7 @@ uniform mat4 M; uniform mat4 V; uniform mat4 P; +uniform mat4 Bones[100]; layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; @@ -20,9 +21,17 @@ out VertexData{ void main() { - gl_Position = P*V*M * vec4(Position, 1.0); - Output.Position = Position; + + mat4 boneTransform = mat4(1); + boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])] + + BoneWeights[1] * Bones[int(BoneIndices[1])] + + BoneWeights[2] * Bones[int(BoneIndices[2])] + + BoneWeights[3] * Bones[int(BoneIndices[3])]; + + gl_Position = P*V*M*boneTransform * vec4(Position, 1.0); + + Output.Position = (boneTransform * vec4(Position, 1.0)).xyz; Output.TextureCoordinate = TextureCoords; Output.Normal = vec3(M * vec4(Normal, 0.0)); } \ No newline at end of file diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 547a96e1..46aad8df 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -292,21 +292,33 @@ void EditorSystem::createWidget() m_WidgetPlaneX = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneX, "Transform"); m_World->AttachComponent(m_WidgetPlaneX, "Model"); +#ifdef USING_ASSIMP_AS_IMPORTER + m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; // 360NoScope widgetPlaneX +#else m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneX +#endif m_WidgetY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetY, "Transform"); m_World->AttachComponent(m_WidgetY, "Model"); m_WidgetPlaneY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneY, "Transform"); m_World->AttachComponent(m_WidgetPlaneY, "Model"); +#ifdef USING_ASSIMP_AS_IMPORTER + m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; // 360NoScope widgetPlaneY +#else m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneY +#endif m_WidgetZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetZ, "Transform"); m_World->AttachComponent(m_WidgetZ, "Model"); m_WidgetPlaneZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetPlaneZ, "Transform"); m_World->AttachComponent(m_WidgetPlaneZ, "Model"); +#ifdef USING_ASSIMP_AS_IMPORTER + m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; // 360NoScope widgetPlaneZ +#else m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneZ +#endif m_WidgetOrigin = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetOrigin, "Transform"); m_World->AttachComponent(m_WidgetOrigin, "Model"); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 7093b00f..1dd5f9bc 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -22,6 +22,8 @@ void DrawFinalPass::InitializeShaderPrograms() m_ForwardPlusProgram->Link(); } +static double tempFrameCounter = 6.348; + void DrawFinalPass::Draw(RenderScene& scene) { GLERROR("DrawFinalPass::Draw: Pre"); @@ -38,6 +40,7 @@ void DrawFinalPass::Draw(RenderScene& scene) glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); + //tempFrameCounter += 0.01; //TODO: Render: Add code for more jobs than modeljobs. for (auto &job : scene.ForwardJobs) { auto modelJob = std::dynamic_pointer_cast(job); @@ -54,6 +57,21 @@ void DrawFinalPass::Draw(RenderScene& scene) glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); } + if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { +#ifdef USING_ASSIMP_AS_IMPORTER + auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("combinedAnim_0"); +#else + auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running"); +#endif + if (animation != nullptr) { + std::vector frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones( + *animation, + tempFrameCounter + ); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } + } + // -3 - 9 glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); @@ -61,4 +79,4 @@ void DrawFinalPass::Draw(RenderScene& scene) } GLERROR("DrawFinalPass::Draw: END"); -} +} \ No newline at end of file diff --git a/src/Engine/Rendering/Model.cpp b/src/Engine/Rendering/Model.cpp index c8a2bc41..cf4923a3 100644 --- a/src/Engine/Rendering/Model.cpp +++ b/src/Engine/Rendering/Model.cpp @@ -15,6 +15,9 @@ Model::Model(std::string fileName) if (!group.SpecularMapPath.empty()) { group.SpecularMap = std::shared_ptr(ResourceManager::Load(group.SpecularMapPath)); } + if (!group.IncandescenceMapPath.empty()) { + group.IncandescenceMap = std::shared_ptr(ResourceManager::Load(group.IncandescenceMapPath)); + } } // Generate GL buffers diff --git a/src/Engine/Rendering/RawModelAssimp.cpp b/src/Engine/Rendering/RawModelAssimp.cpp index 259eafc3..6bc3f3f7 100644 --- a/src/Engine/Rendering/RawModelAssimp.cpp +++ b/src/Engine/Rendering/RawModelAssimp.cpp @@ -1,6 +1,8 @@ #include "Rendering/RawModelAssimp.h" -RawModel::RawModel(std::string fileName) +#ifdef USING_ASSIMP_AS_IMPORTER + +RawModelAssimp::RawModelAssimp(std::string fileName) { Assimp::Importer importer; const aiScene* scene = importer.ReadFile(fileName, aiProcess_CalcTangentSpace | aiProcess_Triangulate); @@ -271,16 +273,17 @@ RawModel::RawModel(std::string fileName) m_Skeleton->Animations[animationName] = skelAnim; } + int k = 0; } -RawModel::~RawModel() +RawModelAssimp::~RawModelAssimp() { if (m_Skeleton) { delete m_Skeleton; } } -void RawModel::CreateSkeleton(std::vector> &boneInfo, std::map &boneNameMapping, aiNode* node, int parentID) +void RawModelAssimp::CreateSkeleton(std::vector> &boneInfo, std::map &boneNameMapping, aiNode* node, int parentID) { std::string nodeName = node->mName.C_Str(); @@ -300,3 +303,5 @@ void RawModel::CreateSkeleton(std::vector> &b CreateSkeleton(boneInfo, boneNameMapping, child, parentID); } } + +#endif \ No newline at end of file diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index f7354d92..7c387dd9 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -1,6 +1,8 @@ #include "Rendering/RawModelCustom.h" -RawModel::RawModel(std::string fileName) +#ifndef USING_ASSIMP_AS_IMPORTER + +RawModelCustom::RawModelCustom(std::string fileName) { fileName = fileName.erase(fileName.find_last_of("."), fileName.find_last_of(".") - fileName.size()); ReadMeshFile(fileName); @@ -9,7 +11,7 @@ RawModel::RawModel(std::string fileName) int k = 0; } -void RawModel::ReadMeshFile(std::string filePath) +void RawModelCustom::ReadMeshFile(std::string filePath) { char* fileData; filePath += ".mesh"; @@ -33,7 +35,7 @@ void RawModel::ReadMeshFile(std::string filePath) delete fileData; } -void RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +void RawModelCustom::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN m_Vertices.resize(*(unsigned int*)(fileData + offset)); @@ -44,13 +46,13 @@ void RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned #endif } -void RawModel::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +void RawModelCustom::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { ReadVertices(offset, fileData, fileByteSize); ReadIndices(offset, fileData, fileByteSize); } -void RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +void RawModelCustom::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) { @@ -63,7 +65,7 @@ void RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& #endif } -void RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +void RawModelCustom::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN if (offset + m_Indices.size() * sizeof(unsigned int) > fileByteSize) { @@ -77,7 +79,7 @@ void RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& f #endif } -void RawModel::ReadMaterialFile(std::string filePath) +void RawModelCustom::ReadMaterialFile(std::string filePath) { char* fileData; filePath += ".mtrl"; @@ -100,7 +102,7 @@ void RawModel::ReadMaterialFile(std::string filePath) delete fileData; } -void RawModel::ReadMaterials(unsigned int& offset, char* fileData, unsigned int& fileByteSize) +void RawModelCustom::ReadMaterials(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN unsigned int* numMaterials = (unsigned int*)(fileData); @@ -114,7 +116,7 @@ void RawModel::ReadMaterials(unsigned int& offset, char* fileData, unsigned int& #endif } -void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize) +void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize) { MaterialGroup newMaterial; @@ -189,7 +191,7 @@ void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned MaterialGroups.push_back(newMaterial); } -void RawModel::ReadAnimationFile(std::string filePath) +void RawModelCustom::ReadAnimationFile(std::string filePath) { char* fileData; filePath += ".anim"; @@ -214,7 +216,7 @@ void RawModel::ReadAnimationFile(std::string filePath) #ifdef BOOST_LITTLE_ENDIAN unsigned int numBindPoses = *(unsigned int*)(fileData); offset += sizeof(unsigned int); - unsigned int numAnimations = *(unsigned int*)(fileData); + unsigned int numAnimations = *(unsigned int*)(fileData + offset); offset += sizeof(unsigned int); #else #endif @@ -225,7 +227,7 @@ void RawModel::ReadAnimationFile(std::string filePath) delete fileData; } -void RawModel::ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsigned int& fileByteSize) +void RawModelCustom::ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN unsigned int* numBones = (unsigned int*)(fileData + offset); @@ -238,7 +240,7 @@ void RawModel::ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsi #endif } -void RawModel::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize) +void RawModelCustom::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN if (offset + sizeof(unsigned int) > fileByteSize) { @@ -259,7 +261,7 @@ void RawModel::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned glm::mat4 offsetMatrix; memcpy(&offsetMatrix, fileData + offset, sizeof(float) * 4 * 4); offset += sizeof(float) * 4 * 4; - + if (offset + sizeof(int) > fileByteSize) { throw Resource::FailedLoadingException("Reading Joint ID failed"); } @@ -280,14 +282,14 @@ void RawModel::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned #endif } -void RawModel::ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips) +void RawModelCustom::ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips) { for (unsigned int i = 0; i < numberOfClips; i++) { ReadAnimationClipSingle(offset, fileData, fileByteSize, i); } } -void RawModel::ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex) +void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex) { #ifdef BOOST_LITTLE_ENDIAN Skeleton::Animation newAnimation; @@ -332,7 +334,7 @@ void RawModel::ReadAnimationClipSingle(unsigned int &offset, char* fileData, uns #endif } -void RawModel::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int nrOfJoints, Skeleton::Animation& animation) +void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int nrOfJoints, Skeleton::Animation& animation) { Skeleton::Animation::Keyframe newKeyFrame; @@ -356,12 +358,16 @@ void RawModel::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsig for (unsigned int i = 0; i < nrOfJoints; i++) { memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty)); offset += sizeof(Skeleton::Animation::Keyframe::BoneProperty); - newKeyFrame.BoneProperties[i] = newBone; + newKeyFrame.BoneProperties[newBone.ID] = newBone; } animation.Keyframes.push_back(newKeyFrame); } -RawModel::~RawModel() +RawModelCustom::~RawModelCustom() { + if (m_Skeleton != nullptr) { + delete m_Skeleton; + } +} -} \ No newline at end of file +#endif \ No newline at end of file diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 2a6a49c2..5d9d474d 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -96,10 +96,18 @@ void RenderSystem::fillModels(std::list>& jobs, World model = ResourceManager::Load<::Model, true>(resource); } catch (const Resource::StillLoadingException&) { //continue; +#ifdef USING_ASSIMP_AS_IMPORTER + model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.obj"); // 360NoScope StillLoading mesh +#else model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope StillLoading mesh +#endif } catch (const std::exception&) { try { +#ifdef USING_ASSIMP_AS_IMPORTER + model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.obj"); // 360NoScope Error mesh +#else model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope Error mesh +#endif } catch (const std::exception&) { continue; } diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 44276308..986e634c 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -68,7 +68,7 @@ std::vector Skeleton::GetFrameBones(const Animation& animation, doubl void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyframe ¤tFrame, const Animation::Keyframe &nextFrame, float progress, std::map &boneMatrices, const Bone* bone, glm::mat4 parentMatrix) { - glm::mat4 boneMatrix; + glm::mat4 boneMatrix; if (currentFrame.BoneProperties.find(bone->ID) != currentFrame.BoneProperties.end() || nextFrame.BoneProperties.find(bone->ID) != nextFrame.BoneProperties.end()) { Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties.at(bone->ID); @@ -84,10 +84,14 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyf positionInterp.z = 0; } + boneMatrix = parentMatrix * (glm::translate(positionInterp) * glm::toMat4(rotationInterp) * glm::scale(scaleInterp)); boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; + int k = 0; } else { - boneMatrix = parentMatrix * bone->Parent->OffsetMatrix; // * glm::inverse(bone->OffsetMatrix); + if (bone->Parent) { + boneMatrix = parentMatrix * bone->Parent->OffsetMatrix * glm::translate(glm::vec3(1.718, 0, 0)); // * glm::inverse(bone->OffsetMatrix); + } boneMatrices[bone->ID] = boneMatrix; // * bone->OffsetMatrix; } @@ -95,6 +99,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyf std::string name = child->Name; AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, progress, boneMatrices, child, boneMatrix); } + } int Skeleton::GetBoneID(std::string name) diff --git a/src/Tests/CollisionTest.cpp b/src/Tests/CollisionTest.cpp index 4ba7ca87..767fbe3a 100644 --- a/src/Tests/CollisionTest.cpp +++ b/src/Tests/CollisionTest.cpp @@ -27,7 +27,9 @@ using boost::unit_test_framework::test_case; void RayTest(std::string fileName) { //simple box test Ray ray(glm::vec3(-50, 0, 0), glm::vec3(1, 0, 0)); - //using a rawmodel here, else we have to init the renderingsystem + //using a + + here, else we have to init the renderingsystem ResourceManager::RegisterType("RawModel"); auto unitBox = ResourceManager::Load(fileName); BOOST_REQUIRE(unitBox != nullptr); diff --git a/tools/MayaExporter/MayaExporter/Export.cpp b/tools/MayaExporter/MayaExporter/Export.cpp index d25faa4c..d8f1abd4 100644 --- a/tools/MayaExporter/MayaExporter/Export.cpp +++ b/tools/MayaExporter/MayaExporter/Export.cpp @@ -7,26 +7,56 @@ Export::Export() bool Export::Meshes(std::string pathName, bool selectedOnly) { + MStatus status; if (pathName.empty()) { MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file"); return false; } + MSelectionList selectedOnStart; MGlobal::getActiveSelectionList(selectedOnStart); - + if (selectedOnStart.length() > 0) { + for (int i = 0; i < selectedOnStart.length(); i++) { + MObject item; + selectedOnStart.getDependNode(i, item); + MGlobal::unselect(item); + } + } + MGlobal::displayInfo(MString() + "Disabel IKSolvers"); + status = MGlobal::executeCommand("doEnableNodeItems false all;"); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "EnableNodeItems false all failed: " + status.errorString()); + } + MGlobal::displayInfo(MString() + "Has disabel IKSolvers"); MObjectArray Objects; 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++) { + for (unsigned int i = 0; i < selectedOnStart.length(); i++) { MObject object; - selected.getDependNode(i, object); + selectedOnStart.getDependNode(i, object); if (object.hasFn(MFn::kMesh)) { - MFnDependencyNode thisNode(object); + MFnMesh shape(object); + + for (unsigned int k = 0; k < shape.parentCount(); k++) { + MFnDependencyNode thisNode(object); + MPlugArray connections; + thisNode.findPlug("inMesh").connectedTo(connections, true, true); + + for (unsigned int i = 0; i < connections.length(); i++) { + if (connections[i].node().apiType() == MFn::kSkinClusterFilter) { + MGlobal::select(shape.parent(i), MGlobal::kReplaceList); + MGlobal::displayInfo(MString() + "Moving " + thisNode.name() + " to bindPose."); + status = MGlobal::executeCommand("GoToBindPose;"); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "GoToBindPose: " + status.errorString()); + } + MGlobal::displayInfo(MString() + "Has moved " + thisNode.name() + " to bindPose."); + } + } + } Objects.append(object); } } @@ -42,7 +72,9 @@ bool Export::Meshes(std::string pathName, bool selectedOnly) for (unsigned int i = 0; i < connections.length(); i++) { if (connections[i].node().apiType() == MFn::kSkinClusterFilter) { MGlobal::select(node); - MGlobal::executeCommand("gotoBindPose"); + MGlobal::displayInfo(MString() + "Moving " + thisNode.name() + " to bindPose."); + MGlobal::executeCommand("GoToBindPose"); + MGlobal::displayInfo(MString() + "Has moved " + thisNode.name() + " to bindPose."); } } @@ -51,6 +83,19 @@ bool Export::Meshes(std::string pathName, bool selectedOnly) } GetMeshData(Objects); WriteMeshData(pathName); + MGlobal::displayInfo(MString() + "Enabling IKSolvers"); + status = MGlobal::executeCommand("doEnableNodeItems true all;"); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "doEnableNodeItems true all: " + status.errorString()); + } + MGlobal::displayInfo(MString() + "Has enabling IKSolvers"); + if (selectedOnStart.length() > 0) { + for (int i = 0; i < selectedOnStart.length(); i++) { + MObject item; + selectedOnStart.getDependNode(i, item); + MGlobal::select(item); + } + } return true; } diff --git a/tools/MayaExporter/MayaExporter/MayaIncludes.h b/tools/MayaExporter/MayaExporter/MayaIncludes.h index 66527470..7322bdc5 100644 --- a/tools/MayaExporter/MayaExporter/MayaIncludes.h +++ b/tools/MayaExporter/MayaExporter/MayaIncludes.h @@ -42,6 +42,9 @@ #include #include #include +#include +#include +#include // Wrappers diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index a03788a6..897cc655 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -60,7 +60,7 @@ Menu::Menu(QDialog* dialog) m_ExportPath = new QLineEdit; m_FileDialog = new QFileDialog; - QString tmpPath("C:/Users/Nickelodion/Desktop/Baljj"); + QString tmpPath("C:/Users/Nickelodion/Desktop/animTest"); m_ExportPath->setText(tmpPath); QLabel* exportLabel = new QLabel; exportLabel->setText("Export Path:"); @@ -175,6 +175,13 @@ void Menu::ExportAll(bool) return; } + if (m_ExportMaterialButton->isChecked()) { + if (!m_Export.Materials(m_ExportPath->text().toLocal8Bit().constData())) { + MGlobal::displayError(MString() + "Could not export materials"); + return; + } + } + std::vector animations; for (unsigned int i = 0; i < m_AnimationClipName.size(); i++) { Export::AnimationInfo thisClip; @@ -191,13 +198,6 @@ void Menu::ExportAll(bool) return; } } - - if (m_ExportMaterialButton->isChecked()) { - if (!m_Export.Materials(m_ExportPath->text().toLocal8Bit().constData())){ - MGlobal::displayError(MString() + "Could not export materials"); - return; - } - } } void Menu::CancelClicked(bool) diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index 2062bad5..26d5c7b2 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -68,7 +68,6 @@ std::map MeshClass::GetWeightData() break; } MFnDependencyNode test(comp); - unsigned int nrOfWeights = 0; for (unsigned int j = 0; j < weights.length() && nrOfWeights != 4; j++) { @@ -90,7 +89,7 @@ std::map MeshClass::GetWeightData() for (unsigned int k = 0; k!=nrOfWeights; k++) { - //MGlobal::displayInfo(MString() + "influence: " + weightInfo.BoneIndices[k] + " weight: " + weightInfo.BoneWeights[k]); + MGlobal::displayInfo(MString() + "influence: " + weightInfo.BoneIndices[k] + " weight: " + weightInfo.BoneWeights[k]); } geomIter.next(); } @@ -109,6 +108,26 @@ Mesh MeshClass::GetMeshData(MObjectArray object) if (!object[ObjectID].hasFn(MFn::kMesh)) continue; + MObject node = object[ObjectID]; + MFnDependencyNode thisNode(node); + MPlugArray connections; + thisNode.findPlug("inMesh").connectedTo(connections, true, true); + MGlobal::displayInfo(MString() + "inMesh"); + bool hasSkin = false; + MPlug weightList, weights; + MObject weightListObject; + for (unsigned int i = 0; i < connections.length(); i++) { + if (connections[i].node().apiType() == MFn::kSkinClusterFilter) { + MFnSkinCluster skinCluster(connections[i].node()); + weightList = skinCluster.findPlug("weightList", &status); + weightListObject = weightList.attribute(); + weights = skinCluster.findPlug("weights"); + hasSkin = true; + break; + } + } + + // In here, we retrieve triangulated polygons from the mesh MFnMesh mesh(object[ObjectID]); MDagPathArray dagPaths; @@ -178,7 +197,7 @@ Mesh MeshClass::GetMeshData(MObjectArray object) } } - map vertexWeights = GetWeightData(); + // map vertexWeights = GetWeightData(); status = mesh.getTangents(Tangents, MSpace::kObject); if (status != MS::kSuccess) { MGlobal::displayError(MString() + "mesh.getTangents ERROR: " + status.errorString() + " for " + thisMeshPath.fullPathName()); @@ -288,27 +307,25 @@ Mesh MeshClass::GetMeshData(MObjectArray object) thisVertex.Uv[0] = UV[0]; thisVertex.Uv[1] = UV[1]; - thisVertex.BoneIndices[0] = vertexWeights[faceVert.vertId()].BoneIndices[0]; - thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1]; - thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2]; - thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3]; - if (abs(vertexWeights[faceVert.vertId()].BoneWeights[0]) > 0.0001) - thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0]; - if (abs(vertexWeights[faceVert.vertId()].BoneWeights[1]) > 0.0001) - thisVertex.BoneWeights[1] = vertexWeights[faceVert.vertId()].BoneWeights[1]; - if (abs(vertexWeights[faceVert.vertId()].BoneWeights[2]) > 0.0001) - thisVertex.BoneWeights[2] = vertexWeights[faceVert.vertId()].BoneWeights[2]; - if (abs(vertexWeights[faceVert.vertId()].BoneWeights[3]) > 0.0001) - thisVertex.BoneWeights[3] = vertexWeights[faceVert.vertId()].BoneWeights[3]; - - float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3]; - if (totalWeight < 1.00f && totalWeight > 0.01f) { - thisVertex.BoneWeights[0] /= totalWeight; - thisVertex.BoneWeights[1] /= totalWeight; - thisVertex.BoneWeights[2] /= totalWeight; - thisVertex.BoneWeights[3] /= totalWeight; + + if (hasSkin) { + MIntArray jointIDs /* ??? */; + weights.selectAncestorLogicalIndex(vertexIndex, weightListObject); + weights.getExistingArrayAttributeIndices(jointIDs); + for (unsigned int i = 0; i < jointIDs.length() && i < 4; i++) { + thisVertex.BoneIndices[i] = jointIDs[i]; + thisVertex.BoneWeights[i] = weights[i].asFloat(); + } } + //float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3]; + //if (totalWeight > 0.0001f) { + // thisVertex.BoneWeights[0] /= totalWeight; + // thisVertex.BoneWeights[1] /= totalWeight; + // thisVertex.BoneWeights[2] /= totalWeight; + // thisVertex.BoneWeights[3] /= totalWeight; + //} + std::vector::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex); array tmp; if (it != vertexList.end()) { diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp index 9f887561..c30311b8 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.cpp +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -64,6 +64,7 @@ std::string attr[9] = { "scaleX", "scaleY", "scaleZ", "translateX", "translateY" Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame) { + MStatus status; std::vector animatedJoints; std::vector m_Hierarchy; @@ -121,7 +122,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e MFnMatrixData MartixFn(DataHandle.data()); MMatrix BindPoseMatrix = MartixFn.matrix(); - if (BindPoseMatrix != MayaJoint.transformationMatrix()) + 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"); } @@ -153,19 +154,43 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e MGlobal::displayError(MString() + "Could not find joint ID for: " + thisJoint.name()); } - MMatrix Matrix = thisJoint.transformationMatrix(); - + MTransformationMatrix Matrix = thisJoint.transformation(); + MPlug BindPose = thisJoint.findPlug("bindPose"); + MDataHandle DataHandle; + BindPose.getValue(DataHandle); + MFnMatrixData MartixFn(DataHandle.data()); + MMatrix BindPoseMatrix = MartixFn.matrix(); + Matrix = Matrix.asMatrix(); + + MObject jointOrientObj = thisJoint.attribute("jointOrient"); + MFnNumericAttribute jointOrient(jointOrientObj); + double jointOrientDouble[3]; + jointOrient.getDefault(jointOrientDouble[0], jointOrientDouble[1], jointOrientDouble[2]); + //MGlobal::displayError(MString() + "Joint Matrix: "); + //MGlobal::displayError(MString() + Matrix.asMatrix()[0][0] + " " + Matrix.asMatrix()[0][1] + " " + Matrix.asMatrix()[0][2] + " " + Matrix.asMatrix()[0][3]); + //MGlobal::displayError(MString() + Matrix.asMatrix()[1][0] + " " + Matrix.asMatrix()[1][1] + " " + Matrix.asMatrix()[1][2] + " " + Matrix.asMatrix()[1][3]); + //MGlobal::displayError(MString() + Matrix.asMatrix()[2][0] + " " + Matrix.asMatrix()[2][1] + " " + Matrix.asMatrix()[2][2] + " " + Matrix.asMatrix()[2][3]); + //MGlobal::displayError(MString() + Matrix.asMatrix()[3][0] + " " + Matrix.asMatrix()[3][1] + " " + Matrix.asMatrix()[3][2] + " " + Matrix.asMatrix()[3][3]); + + MEulerRotation joEuler(jointOrientDouble[0], jointOrientDouble[1], jointOrientDouble[2]); + MQuaternion jo = joEuler.asQuaternion(); + double tmp[4]; - thisJoint.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]); + Matrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]); + MQuaternion rotation(tmp); + + rotation = rotation * jo; + rotation.get(tmp); + joint.Rotation[0] = tmp[0]; joint.Rotation[1] = tmp[1]; joint.Rotation[2] = tmp[2]; joint.Rotation[3] = tmp[3]; - thisJoint.getTranslation(MSpace::kPreTransform).get(tmp); + Matrix.getTranslation(MSpace::kTransform).get(tmp); joint.Position[0] = tmp[0]; joint.Position[1] = tmp[1]; joint.Position[2] = tmp[2]; - thisJoint.getScale(tmp); + Matrix.getScale(tmp, MSpace::kTransform); joint.Scale[0] = tmp[0]; joint.Scale[1] = tmp[1]; joint.Scale[2] = tmp[2]; @@ -184,6 +209,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e std::vector Skeleton::GetBindPoses() { + MStatus status; std::vector m_AllSkeletons; std::vector m_Hierarchy; @@ -214,12 +240,76 @@ std::vector Skeleton::GetBindPoses() } m_Hierarchy.push_back(MayaJoint.object()); - MPlug BindPose = MayaJoint.findPlug("bindPose"); + MPlug BindPose = MayaJoint.findPlug("bindPose", &status); + if (status != MS::kSuccess) { + MGlobal::displayError(MString() + "Could not find bindPose plug: " + status.errorString()); + } MDataHandle DataHandle; BindPose.getValue(DataHandle); MFnMatrixData MartixFn(DataHandle.data()); MMatrix Matrix = MartixFn.matrix(); + + MVector tmp = MayaJoint.transformation().getTranslation(MSpace::kObject); + MGlobal::displayError(MString() + "translation befor: " + tmp[0] + " " + tmp[1] + " " + tmp[2]); + //Matrix[3][0] *= -1; + //Matrix[3][2] *= -1; + //Matrix[3][1] *= -1; + + double test[3]; + MayaJoint.transformation().getScale(test, MSpace::kObject); + MGlobal::displayError(MString() + "scale: " + test[0] + " " + test[1] + " " + test[2]); + + MTransformationMatrix::RotationOrder order = MTransformationMatrix::RotationOrder::kXYZ; + MayaJoint.transformation().getRotation(test, order); + MGlobal::displayError(MString() + "rotation: " + test[0] + " " + test[1] + " " + test[2]); + + //----- test + + + //MDataHandle DataHandle; + //MObject jointObject(jointIt.currentItem()); + //MFnDependencyNode jointDependNode(jointObject); + //MPlug worldMatrixArray(jointObject, jointDependNode.attribute("worldMatrix")); + + //MMatrix Matrix; + //for (int i = 0; i < worldMatrixArray.numElements(); i++) { + // MPlugArray connections; + + // MPlug element = worldMatrixArray[i]; + // unsigned int logicalIndex = element.logicalIndex(); + + // MItDependencyGraph it(element, MFn::kSkinClusterFilter); + + // for (; !it.isDone(); it.next()) { + // MFnSkinCluster skinCluster(it.thisNode()); + + // MPlug bindPreMatrixArrayPlug = + // skinCluster.findPlug("bindPreMatrix", &status); + + // if (status != MS::kSuccess) { + // MGlobal::displayError(MString() + "Could not find bindPreMatrix plug: " + status.errorString()); + // break; + // } + + // MPlug bindPreMatrixPlug = + // bindPreMatrixArrayPlug.elementByLogicalIndex(logicalIndex); + // MObject dataObject; + // bindPreMatrixPlug.getValue(dataObject); + + // MFnMatrixData matDataFn(dataObject); + + // MMatrix invMat = matDataFn.matrix(); + // Matrix = invMat.inverse(); + // } + //} + + + //----- end test + + + Matrix = Matrix.inverse(); + for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j]; From 3baa988ad46ab495e51e387b0d0a6a412697a5fc Mon Sep 17 00:00:00 2001 From: antc13 Date: Sat, 23 Jan 2016 20:35:58 +0100 Subject: [PATCH 23/28] Changed .obj files to our own format. DummyScene.mesh may be broken. --- .../Rendering/DebugCameraInputController.h | 2 +- .../Schema/Entities/CollisionTestLevel.xml | 14 ++++----- resources/Schema/Entities/EditorTestWorld.xml | 8 ++--- resources/Schema/Entities/MovementTest.xml | 6 ++-- resources/Schema/Entities/OctreeTest.xml | 6 ++-- resources/Schema/Entities/Player.xml | 2 +- resources/Schema/Entities/RaptorCopter.xml | 8 ++--- resources/Schema/Entities/RenderingWorld.xml | 6 ++-- resources/Schema/Entities/SoundTestLevel.xml | 2 +- resources/Schema/Entities/SpawnTest.xml | 4 +-- resources/Shaders/ForwardPlus.vert.glsl | 2 ++ src/Engine/Editor/EditorSystem.cpp | 26 ++++++++-------- src/Engine/Network/Client.cpp | 2 +- src/Engine/Network/Server.cpp | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 12 ++----- src/Engine/Rendering/RawModelCustom.cpp | 15 +++++---- src/Engine/Rendering/RenderSystem.cpp | 4 +-- src/Engine/Sound/SoundSystem.cpp | 2 +- src/Tests/CollisionTest.cpp | 10 +++--- src/Tests/HealthSystemTest.cpp | 4 +-- src/Tests/OctTreeTestGameClass.cpp | 2 +- src/Tests/OctTreeTestHardCodedTestWorld.h | 4 +-- src/Tests/OldOctTree.cpp | 2 +- src/Tests/ResourceManagerTest.cpp | 4 +-- tools/MayaExporter/MayaExporter/Material.cpp | 31 ++++++++++++++----- tools/MayaExporter/MayaExporter/Menu.cpp | 2 +- 26 files changed, 99 insertions(+), 83 deletions(-) diff --git a/include/Engine/Rendering/DebugCameraInputController.h b/include/Engine/Rendering/DebugCameraInputController.h index d69098c2..4d74e288 100644 --- a/include/Engine/Rendering/DebugCameraInputController.h +++ b/include/Engine/Rendering/DebugCameraInputController.h @@ -61,6 +61,6 @@ public: protected: glm::vec3 m_Position = glm::vec3(0, 0, 0); glm::vec3 m_Velocity = glm::vec3(0, 0, 0); - float m_BaseSpeed = 50.0f;//2.0f; + float m_BaseSpeed = 2.0f; float m_Speed = m_BaseSpeed; }; \ No newline at end of file diff --git a/resources/Schema/Entities/CollisionTestLevel.xml b/resources/Schema/Entities/CollisionTestLevel.xml index d5e932c2..e58ab6ce 100644 --- a/resources/Schema/Entities/CollisionTestLevel.xml +++ b/resources/Schema/Entities/CollisionTestLevel.xml @@ -6,7 +6,7 @@ - Models/DummyScene.obj + Models/DummyScene.mesh @@ -17,7 +17,7 @@ - Models/Core/UnitSphere.obj + Models/Core/UnitSphere.mesh @@ -28,7 +28,7 @@ - Models/RotationWidgetX.obj + Models/RotationWidgetX.mesh @@ -43,7 +43,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh @@ -69,7 +69,7 @@ - Models/Core/UnitRaptor.obj + Models/Core/UnitRaptor.mesh @@ -94,7 +94,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh @@ -107,7 +107,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/EditorTestWorld.xml b/resources/Schema/Entities/EditorTestWorld.xml index 2e95d626..5649a630 100755 --- a/resources/Schema/Entities/EditorTestWorld.xml +++ b/resources/Schema/Entities/EditorTestWorld.xml @@ -9,7 +9,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh @@ -58,7 +58,7 @@ - Models/DirectionalLightWidget.obj + Models/DirectionalLightWidget.mesh @@ -70,7 +70,7 @@ - Models/Assault.obj + Models/Assault.mesh @@ -94,7 +94,7 @@ - Models/Core/UnitSphere.obj + Models/Core/UnitSphere.mesh diff --git a/resources/Schema/Entities/MovementTest.xml b/resources/Schema/Entities/MovementTest.xml index 93b4d374..dc271908 100644 --- a/resources/Schema/Entities/MovementTest.xml +++ b/resources/Schema/Entities/MovementTest.xml @@ -18,7 +18,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh @@ -37,7 +37,7 @@ - Models/Assault.obj + Models/Assault.mesh @@ -55,7 +55,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/OctreeTest.xml b/resources/Schema/Entities/OctreeTest.xml index 4d7fe709..a510a98c 100644 --- a/resources/Schema/Entities/OctreeTest.xml +++ b/resources/Schema/Entities/OctreeTest.xml @@ -11,7 +11,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh @@ -27,7 +27,7 @@ false - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh @@ -42,7 +42,7 @@ false - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/Player.xml b/resources/Schema/Entities/Player.xml index 6c3b39c3..485c6cff 100644 --- a/resources/Schema/Entities/Player.xml +++ b/resources/Schema/Entities/Player.xml @@ -6,7 +6,7 @@ - Models/Core/UnitSphere.obj + Models/Core/UnitSphere.mesh diff --git a/resources/Schema/Entities/RaptorCopter.xml b/resources/Schema/Entities/RaptorCopter.xml index 0ee62368..82aa0efa 100644 --- a/resources/Schema/Entities/RaptorCopter.xml +++ b/resources/Schema/Entities/RaptorCopter.xml @@ -7,7 +7,7 @@ - Models/Core/UnitRaptor.obj + Models/Core/UnitRaptor.mesh @@ -31,7 +31,7 @@ - Models/Core/UnitCylinder.obj + Models/Core/UnitCylinder.mesh @@ -44,7 +44,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh @@ -57,7 +57,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/RenderingWorld.xml b/resources/Schema/Entities/RenderingWorld.xml index 86a3090a..67ddd046 100644 --- a/resources/Schema/Entities/RenderingWorld.xml +++ b/resources/Schema/Entities/RenderingWorld.xml @@ -13,7 +13,7 @@ - Models/Camera.obj + Models/Camera.mesh MainCamera @@ -26,7 +26,7 @@ - Models/Camera.obj + Models/Camera.mesh ActionCamera @@ -40,7 +40,7 @@ - Models/Core/UnitPlane.obj + Models/Core/UnitPlane.mesh diff --git a/resources/Schema/Entities/SoundTestLevel.xml b/resources/Schema/Entities/SoundTestLevel.xml index 366ae81b..4e9c3093 100644 --- a/resources/Schema/Entities/SoundTestLevel.xml +++ b/resources/Schema/Entities/SoundTestLevel.xml @@ -12,7 +12,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/SpawnTest.xml b/resources/Schema/Entities/SpawnTest.xml index a5574027..16608b47 100644 --- a/resources/Schema/Entities/SpawnTest.xml +++ b/resources/Schema/Entities/SpawnTest.xml @@ -24,7 +24,7 @@ - Models/Core/UnitSphere.obj + Models/Core/UnitSphere.mesh @@ -37,7 +37,7 @@ - Models/Core/UnitSphere.obj + Models/Core/UnitSphere.mesh diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index aa8c9446..cb5f41b3 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -24,10 +24,12 @@ void main() mat4 boneTransform = mat4(1); + if(BoneWeights[0] > 0.f){ boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])] + BoneWeights[1] * Bones[int(BoneIndices[1])] + BoneWeights[2] * Bones[int(BoneIndices[2])] + BoneWeights[3] * Bones[int(BoneIndices[3])]; + } gl_Position = P*V*M*boneTransform * vec4(Position, 1.0); diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 46aad8df..e60890b6 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -295,7 +295,7 @@ void EditorSystem::createWidget() #ifdef USING_ASSIMP_AS_IMPORTER m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; // 360NoScope widgetPlaneX #else - m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneX + m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/WidgetPlaneZ.mesh"; #endif m_WidgetY = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetY, "Transform"); @@ -306,7 +306,7 @@ void EditorSystem::createWidget() #ifdef USING_ASSIMP_AS_IMPORTER m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; // 360NoScope widgetPlaneY #else - m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneY + m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/WidgetPlaneZ.mesh"; #endif m_WidgetZ = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetZ, "Transform"); @@ -317,7 +317,7 @@ void EditorSystem::createWidget() #ifdef USING_ASSIMP_AS_IMPORTER m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; // 360NoScope widgetPlaneZ #else - m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneZ + m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/WidgetPlaneZ.mesh"; #endif m_WidgetOrigin = m_World->CreateEntity(m_Widget); m_World->AttachComponent(m_WidgetOrigin, "Transform"); @@ -363,9 +363,9 @@ void EditorSystem::setWidgetMode(WidgetMode newMode) m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = false; if (newMode == WidgetMode::Translate) { - //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/TranslationWidgetX.obj"; // 360NoScope TranslationWidgets mesh - //m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/TranslationWidgetY.obj"; - //m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/TranslationWidgetZ.obj"; + m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/TranslationWidgetX.mesh"; + m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/TranslationWidgetY.mesh"; + m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/TranslationWidgetZ.mesh"; // Temporarily disabled for local space until I can figure out what's wrong with the math if (m_WidgetSpace != WidgetSpace::Local) { m_World->GetComponent(m_WidgetPlaneX, "Model")["Visible"] = true; @@ -379,19 +379,19 @@ void EditorSystem::setWidgetMode(WidgetMode newMode) } } } else if (newMode == WidgetMode::Scale) { - //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/ScaleWidgetX.obj"; // 360NoScope ScaleWidgets mesh - //m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/ScaleWidgetY.obj"; - //m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/ScaleWidgetZ.obj"; + m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/ScaleWidgetX.mesh"; + m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/ScaleWidgetY.mesh"; + m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/ScaleWidgetZ.mesh"; m_World->GetComponent(m_WidgetOrigin, "Model")["Visible"] = true; - //m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.obj"; // 360NoScope ScaleWidgetOrigin mesh + m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.mesh"; if (m_Selection != EntityID_Invalid) { auto selectionTransform = m_World->GetComponent(m_Selection, "Transform"); widgetTransform["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(m_World, m_Selection)); } } else if (newMode == WidgetMode::Rotate) { - //m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.obj"; // 360NoScope RotationWidget mesh - //m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/RotationWidgetY.obj"; - //m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/RotationWidgetZ.obj"; + m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.mesh"; + m_World->GetComponent(m_WidgetY, "Model")["Resource"] = "Models/RotationWidgetY.mesh"; + m_World->GetComponent(m_WidgetZ, "Model")["Resource"] = "Models/RotationWidgetZ.mesh"; if (m_Selection != EntityID_Invalid) { auto selectionTransform = m_World->GetComponent(m_Selection, "Transform"); if (m_WidgetSpace == WidgetSpace::Local) { diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index efd25120..162ccfd6 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -331,7 +331,7 @@ EntityID Client::createPlayer() EntityID entityID = m_World->CreateEntity(); ComponentWrapper transform = m_World->AttachComponent(entityID, "Transform"); ComponentWrapper model = m_World->AttachComponent(entityID, "Model"); - model["Resource"] = "Models/Core/UnitSphere.obj"; // 360NoScope UnitSphere mesh + model["Resource"] = "Models/Core/UnitSphere.mesh"; ComponentWrapper player = m_World->AttachComponent(entityID, "Player"); return entityID; } diff --git a/src/Engine/Network/Server.cpp b/src/Engine/Network/Server.cpp index 367f444b..951fbfb9 100644 --- a/src/Engine/Network/Server.cpp +++ b/src/Engine/Network/Server.cpp @@ -349,7 +349,7 @@ EntityID Server::createPlayer() ComponentWrapper transform = m_World->AttachComponent(entityID, "Transform"); transform["Position"] = glm::vec3(-1.5f, 0.f, 0.f); ComponentWrapper model = m_World->AttachComponent(entityID, "Model"); - model["Resource"] = "Models/Core/UnitSphere.obj"; // 360NoScope UnitSphere + model["Resource"] = "Models/Core/UnitSphere.mesh"; model["Color"] = glm::vec4(rand()%255 / 255.f, rand()%255 / 255.f, rand() %255 / 255.f, 1.f); ComponentWrapper player = m_World->AttachComponent(entityID, "Player"); return entityID; diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 1dd5f9bc..afb27d69 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -22,8 +22,6 @@ void DrawFinalPass::InitializeShaderPrograms() m_ForwardPlusProgram->Link(); } -static double tempFrameCounter = 6.348; - void DrawFinalPass::Draw(RenderScene& scene) { GLERROR("DrawFinalPass::Draw: Pre"); @@ -40,7 +38,6 @@ void DrawFinalPass::Draw(RenderScene& scene) glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); - //tempFrameCounter += 0.01; //TODO: Render: Add code for more jobs than modeljobs. for (auto &job : scene.ForwardJobs) { auto modelJob = std::dynamic_pointer_cast(job); @@ -57,21 +54,18 @@ void DrawFinalPass::Draw(RenderScene& scene) glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); } + //TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :) if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { -#ifdef USING_ASSIMP_AS_IMPORTER - auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("combinedAnim_0"); -#else auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running"); -#endif if (animation != nullptr) { std::vector frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones( *animation, - tempFrameCounter + 1.0f ); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } } - // -3 - 9 + glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index 7c387dd9..3bad2ae5 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -162,8 +162,9 @@ void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, un if (offset + nameLengths[1] > fileByteSize) { throw Resource::FailedLoadingException("Reading Material NormalMap path failed"); } - - newMaterial.NormalMapPath = (fileData + offset); + newMaterial.NormalMapPath = "Textures/"; + newMaterial.NormalMapPath += (fileData + offset); + newMaterial.NormalMapPath += ".png"; offset += nameLengths[1]; } @@ -171,8 +172,9 @@ void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, un if (offset + nameLengths[2] > fileByteSize) { throw Resource::FailedLoadingException("Reading Material SpecularMap path failed"); } - - newMaterial.SpecularMapPath = (fileData + offset); + newMaterial.SpecularMapPath = "Textures/"; + newMaterial.SpecularMapPath += (fileData + offset); + newMaterial.SpecularMapPath += ".png"; offset += nameLengths[2]; } @@ -180,8 +182,9 @@ void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, un if (offset + nameLengths[3] > fileByteSize) { throw Resource::FailedLoadingException("Reading Material IncandescenceMap path failed"); } - - newMaterial.IncandescenceMapPath = (fileData + offset); + newMaterial.IncandescenceMapPath = "Textures/"; + newMaterial.IncandescenceMapPath += (fileData + offset); + newMaterial.IncandescenceMapPath += ".png"; offset += nameLengths[3]; } diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 5d9d474d..16de4961 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -99,14 +99,14 @@ void RenderSystem::fillModels(std::list>& jobs, World #ifdef USING_ASSIMP_AS_IMPORTER model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.obj"); // 360NoScope StillLoading mesh #else - model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope StillLoading mesh + model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.mesh"); #endif } catch (const std::exception&) { try { #ifdef USING_ASSIMP_AS_IMPORTER model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.obj"); // 360NoScope Error mesh #else - model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope Error mesh + model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.mesh"); #endif } catch (const std::exception&) { continue; diff --git a/src/Engine/Sound/SoundSystem.cpp b/src/Engine/Sound/SoundSystem.cpp index 2494581d..a55c1fee 100644 --- a/src/Engine/Sound/SoundSystem.cpp +++ b/src/Engine/Sound/SoundSystem.cpp @@ -198,7 +198,7 @@ bool SoundSystem::OnPlaySoundOnPosition(const Events::PlaySoundOnPosition & e) (float&)(double)emitter["RollOffFactor"] = e.RollOffFactor; (float&)(double)emitter["ReferenceDistance"] = e.ReferenceDistance; auto model = m_World->AttachComponent(emitterID, "Model"); - (std::string&)model["Resource"] = "Models/Core/UnitCube.obj"; // 360NoScope UnitCube + (std::string&)model["Resource"] = "Models/Core/UnitCube.mesh"; // 360NoScope UnitCube source->Type = SoundType::SFX; m_Sources[emitterID] = source; playSound(source); diff --git a/src/Tests/CollisionTest.cpp b/src/Tests/CollisionTest.cpp index 767fbe3a..42d7667c 100644 --- a/src/Tests/CollisionTest.cpp +++ b/src/Tests/CollisionTest.cpp @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(collisionTest2) BOOST_AUTO_TEST_CASE(rayVsModelTest) { //simple box test - RayTest("Models/Core/UnitCube.obj"); // 360NoScope Unitcube + RayTest("Models/Core/UnitCube.mesh"); // 360NoScope Unitcube } BOOST_AUTO_TEST_CASE(rayVsModelTest2) @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) someAABB = AABB(minPos, maxPos); //using a rawmodel here, else we have to init the renderingsystem ResourceManager::RegisterType("RawModel"); - auto unitBox = ResourceManager::Load("Models/Core/UnitCube.obj"); // 360NoScope unitcube + auto unitBox = ResourceManager::Load("Models/Core/UnitCube.mesh"); // 360NoScope unitcube BOOST_CHECK(unitBox != nullptr); for (size_t i = 0; i < 1000000; i++) @@ -189,19 +189,19 @@ BOOST_AUTO_TEST_CASE(rayVsModelTest2) BOOST_AUTO_TEST_CASE(rayVsModelTest3) { //simple test - RayTest("Models/Core/UnitSphere.obj"); // 360NoScope unitSphere + RayTest("Models/Core/UnitSphere.mesh"); // 360NoScope unitSphere } BOOST_AUTO_TEST_CASE(rayVsModelTest4) { //simple test - RayTest("Models/Core/UnitCylinder.obj"); // 360NoScope unitCylinder + RayTest("Models/Core/UnitCylinder.mesh"); // 360NoScope unitCylinder } BOOST_AUTO_TEST_CASE(rayVsModelTest5) { //simple test - RayTest("Models/Core/UnitRaptor.obj"); // 360NoScope unitRaptor + RayTest("Models/Core/UnitRaptor.mesh"); // 360NoScope unitRaptor } BOOST_AUTO_TEST_CASE(octTest) { diff --git a/src/Tests/HealthSystemTest.cpp b/src/Tests/HealthSystemTest.cpp index 7c3ad641..6f157352 100644 --- a/src/Tests/HealthSystemTest.cpp +++ b/src/Tests/HealthSystemTest.cpp @@ -55,7 +55,7 @@ GameHealthSystemTest::GameHealthSystemTest() EntityID playerID = m_World->CreateEntity(); ComponentWrapper transform = m_World->AttachComponent(playerID, "Transform"); ComponentWrapper model = m_World->AttachComponent(playerID, "Model"); - model["Resource"] = "Models/Core/UnitSphere.obj"; // 360NoScope UnitSphere + model["Resource"] = "Models/Core/UnitSphere.mesh"; // 360NoScope UnitSphere ComponentWrapper player = m_World->AttachComponent(playerID, "Player"); ComponentWrapper health = m_World->AttachComponent(playerID, "Health"); healthsID = playerID; @@ -80,7 +80,7 @@ GameHealthSystemTest::GameHealthSystemTest() EntityID playerID2 = m_World->CreateEntity(); ComponentWrapper transform2 = m_World->AttachComponent(playerID2, "Transform"); ComponentWrapper model2 = m_World->AttachComponent(playerID2, "Model"); - model2["Resource"] = "Models/Core/UnitSphere.obj"; // 360NoScope UnitSphere + model2["Resource"] = "Models/Core/UnitSphere.mesh"; // 360NoScope UnitSphere ComponentWrapper player2 = m_World->AttachComponent(playerID2, "Player"); ComponentWrapper health2 = m_World->AttachComponent(playerID2, "Health"); //END TEST diff --git a/src/Tests/OctTreeTestGameClass.cpp b/src/Tests/OctTreeTestGameClass.cpp index d03153e7..9ddee19b 100644 --- a/src/Tests/OctTreeTestGameClass.cpp +++ b/src/Tests/OctTreeTestGameClass.cpp @@ -149,7 +149,7 @@ void Game::Tick() ComponentWrapper transform = m_World->AttachComponent(m_BoxID, "Transform"); transform["Scale"] = boxSize; ComponentWrapper model = m_World->AttachComponent(m_BoxID, "Model"); - model["Resource"] = "Models/Core/UnitBox.obj"; // 360NoScope UnitBox + model["Resource"] = "Models/Core/UnitBox.mesh"; // 360NoScope UnitBox m_World->createTestEntitiesTest2(); } diff --git a/src/Tests/OctTreeTestHardCodedTestWorld.h b/src/Tests/OctTreeTestHardCodedTestWorld.h index 89c3c3f3..9c8f3988 100644 --- a/src/Tests/OctTreeTestHardCodedTestWorld.h +++ b/src/Tests/OctTreeTestHardCodedTestWorld.h @@ -112,7 +112,7 @@ private: ComponentWrapper transform = world.AttachComponent(entityCollisionBox, "Transform"); transform["Position"] = glm::vec3(0.f, 2.f, 0.f); ComponentWrapper model = world.AttachComponent(entityCollisionBox, "Model"); - model["Resource"] = "Models/Core/UnitBox.obj"; // 360NoScope UnitBox + model["Resource"] = "Models/Core/UnitBox.mesh"; // 360NoScope UnitBox } void AddBoxModel(const glm::vec3 ¢er, const float &halfSize, Octree::Child* child, EntityID &outEntityId) { @@ -124,7 +124,7 @@ private: transform["Position"] = center; transform["Scale"] = glm::vec3(1.0f, 1.0f, 1.0f)*halfSize*2.0f*0.97f; ComponentWrapper model = world.AttachComponent(entityDummyScene, "Model"); - model["Resource"] = "Models/Core/UnitBox.obj"; // 360NoScope unitBox + model["Resource"] = "Models/Core/UnitBox.mesh"; // 360NoScope unitBox model["Color"] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); if (child->m_DynamicObjIndices.size() != 0) model["Color"] = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); diff --git a/src/Tests/OldOctTree.cpp b/src/Tests/OldOctTree.cpp index a94bf465..ec51b522 100644 --- a/src/Tests/OldOctTree.cpp +++ b/src/Tests/OldOctTree.cpp @@ -112,7 +112,7 @@ void OctTree::Update(float dt, World* world, Camera* cam) ComponentWrapper transform = world->AttachComponent(m_BoxID, "Transform"); transform["Scale"] = boxSize; ComponentWrapper model = world->AttachComponent(m_BoxID, "Model"); - model["Resource"] = "Models/Core/UnitBox.obj"; // 360NoScope UnitBox + model["Resource"] = "Models/Core/UnitBox.mesh"; // 360NoScope UnitBox m_UpdatedOnce = true; } diff --git a/src/Tests/ResourceManagerTest.cpp b/src/Tests/ResourceManagerTest.cpp index f83c6c9f..1f52472e 100644 --- a/src/Tests/ResourceManagerTest.cpp +++ b/src/Tests/ResourceManagerTest.cpp @@ -26,8 +26,8 @@ BOOST_AUTO_TEST_CASE(resourceManagerTest) //configfile without register //check so output says "EE failed to load: type not registered..." - auto m_ScreenQuadNoRegister = ResourceManager::Load("Models/Core/ScreenQuad.obj"); // 360NoScope ScreenQuad - BOOST_CHECK(!ResourceManager::IsResourceLoaded("Model", "Models/Core/ScreenQuad.obj")); + auto m_ScreenQuadNoRegister = ResourceManager::Load("Models/Core/ScreenQuad.mesh"); // 360NoScope ScreenQuad + BOOST_CHECK(!ResourceManager::IsResourceLoaded("Model", "Models/Core/ScreenQuad.mesh")); //there is no error feedback to check if you try to release the wrong resources - hence that cant be tested either } diff --git a/tools/MayaExporter/MayaExporter/Material.cpp b/tools/MayaExporter/MayaExporter/Material.cpp index 8f6b0a62..0a897e6e 100644 --- a/tools/MayaExporter/MayaExporter/Material.cpp +++ b/tools/MayaExporter/MayaExporter/Material.cpp @@ -57,22 +57,27 @@ void Material::grabPhongProperties(MaterialNode& material_node, MFnDependencyNod bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode& node) { MPlugArray AllConnections; - + m_Plug = node.findPlug("color", true); m_Plug.connectedTo(AllConnections, true, false); for (int i = 0; i < AllConnections.length(); i++) { if (AllConnections[i].node().hasFn(MFn::kFileTexture)) { MFnDependencyNode TextureNode(AllConnections[i].node()); - - std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); + + std::string FullPath = TextureNode.findPlug("fileTextureName").asString().asChar(); m_TexturePaths.push_back(FullPath); - FullPath = FullPath.substr(FullPath.find_last_of("/") + 1); + MString workspace; + MStatus status = MGlobal::executeCommand(MString("workspace -q -rd;"), + workspace); + FullPath = FullPath.substr(workspace.length()); + FullPath = FullPath.substr(FullPath.find_first_of("/") + 1); material_node.ColorMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); material_node.ColorMapFileLength = material_node.ColorMapFile.length() + 1; // Test + MGlobal::displayInfo(MString() + "getAbsolutePathToResources: " + workspace); MGlobal::displayInfo(MString() + "Texture file: " + FullPath.c_str()); return true; } @@ -101,7 +106,11 @@ bool Material::findNormalTexture(MaterialNode& material_node, MFnDependencyNode& std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); m_TexturePaths.push_back(FullPath); - FullPath = FullPath.substr(FullPath.find_last_of("/") + 1); + MString workspace; + MStatus status = MGlobal::executeCommand(MString("workspace -q -rd;"), + workspace); + FullPath = FullPath.substr(workspace.length()); + FullPath = FullPath.substr(FullPath.find_first_of("/") + 1); material_node.NormalMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); material_node.NormalMapFileLength = material_node.NormalMapFile.length() + 1; return true; @@ -127,7 +136,11 @@ bool Material::findSpecularTexture(MaterialNode& material_node, MFnDependencyNod std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); m_TexturePaths.push_back(FullPath); - FullPath = FullPath.substr(FullPath.find_last_of("/") + 1); + MString workspace; + MStatus status = MGlobal::executeCommand(MString("workspace -q -rd;"), + workspace); + FullPath = FullPath.substr(workspace.length()); + FullPath = FullPath.substr(FullPath.find_first_of("/") + 1); material_node.SpecularMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); material_node.SpecularMapFileLength = material_node.SpecularMapFile.length() + 1; return true; @@ -150,7 +163,11 @@ bool Material::findIncandescenceTexture(MaterialNode& material_node, MFnDependen std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); m_TexturePaths.push_back(FullPath); - FullPath = FullPath.substr(FullPath.find_last_of("/") + 1); + MString workspace; + MStatus status = MGlobal::executeCommand(MString("workspace -q -rd;"), + workspace); + FullPath = FullPath.substr(workspace.length()); + FullPath = FullPath.substr(FullPath.find_first_of("/") + 1); material_node.IncandescenceMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); material_node.IncandescenceMapFileLength = material_node.IncandescenceMapFile.length() + 1; return true; diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 897cc655..4f32af84 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -60,7 +60,7 @@ Menu::Menu(QDialog* dialog) m_ExportPath = new QLineEdit; m_FileDialog = new QFileDialog; - QString tmpPath("C:/Users/Nickelodion/Desktop/animTest"); + QString tmpPath("C:/Users/Nickelodion/Desktop/workspace/tacticalZ/assets/models/"); m_ExportPath->setText(tmpPath); QLabel* exportLabel = new QLabel; exportLabel->setText("Export Path:"); From b5b1140f5c3a29b3fc91969df603507c7195c86d Mon Sep 17 00:00:00 2001 From: antc13 Date: Sun, 24 Jan 2016 13:28:40 +0100 Subject: [PATCH 24/28] Custom Animations should now work. We also save color values if there's no texture. --- include/Engine/Rendering/RawModelCustom.h | 3 + resources/Schema/Entities/AnimatedArmy | 273 ++++++++++++++++++ resources/Shaders/ForwardPlus.vert.glsl | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 6 +- src/Engine/Rendering/RawModelCustom.cpp | 15 +- tools/MayaExporter/MayaExporter/Material.cpp | 30 +- tools/MayaExporter/MayaExporter/Material.h | 9 + tools/MayaExporter/MayaExporter/Menu.cpp | 7 +- tools/MayaExporter/MayaExporter/Mesh.cpp | 14 +- .../MayaExporter/MayaExporter/WriteToFile.cpp | 9 +- tools/MayaExporter/MayaExporter/WriteToFile.h | 1 + 11 files changed, 341 insertions(+), 28 deletions(-) create mode 100644 resources/Schema/Entities/AnimatedArmy diff --git a/include/Engine/Rendering/RawModelCustom.h b/include/Engine/Rendering/RawModelCustom.h index 2dea51ff..a1a2f1f6 100644 --- a/include/Engine/Rendering/RawModelCustom.h +++ b/include/Engine/Rendering/RawModelCustom.h @@ -48,6 +48,9 @@ public: { float SpecularExponent; float ReflectionFactor; + float DiffuseColor[3]; + float SpecularColor[3]; + float IncandescenceColor[3]; unsigned int StartIndex; unsigned int EndIndex; //float Transparency; diff --git a/resources/Schema/Entities/AnimatedArmy b/resources/Schema/Entities/AnimatedArmy new file mode 100644 index 00000000..b711a0fe --- /dev/null +++ b/resources/Schema/Entities/AnimatedArmy @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + models/dummyscene.mesh + + + + + + + + + + + models/animtest. + + + + + + + + + + + models/animTest.mesh + + + + + + + + + + + models/animTest.mesh + + + + + + + + + + + models/animTest.mesh + + + + + + + + + + + 0.13000047206878662 + + + + + + + + + + + + 0.30000001192092896 + + + + + + + + + + + + 5 + + + + + + + + + + + + 5 + 0.80000001192092896 + + + + + + + + + + + + 5 + + + + + + + + + + + + 5 + + + + + + + + + + + + + 0.50999981164932251 + + + + + + + + + + + + + 5 + 5 + + + + + + + + + + + + 5 + + + + + + + + + + + + 5 + + + + + + + + + + + + 5 + + + + + + + + + + + + 5 + + + + + + + + + + + + 5 + + + + + + + + + + + + 5 + + + + + + + + + + + 5 + + + + + + + + + + + + 5 + + + + + + + + + + + + diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index cb5f41b3..c51216cb 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -24,7 +24,7 @@ void main() mat4 boneTransform = mat4(1); - if(BoneWeights[0] > 0.f){ + if(BoneWeights[0] > 0.0f){ boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])] + BoneWeights[1] * Bones[int(BoneIndices[1])] + BoneWeights[2] * Bones[int(BoneIndices[2])] diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index afb27d69..7be1223a 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -21,7 +21,7 @@ void DrawFinalPass::InitializeShaderPrograms() m_ForwardPlusProgram->Compile(); m_ForwardPlusProgram->Link(); } - +static double tempTime = 0.0; void DrawFinalPass::Draw(RenderScene& scene) { GLERROR("DrawFinalPass::Draw: Pre"); @@ -53,14 +53,14 @@ void DrawFinalPass::Draw(RenderScene& scene) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); } - + tempTime += 0.01f; //TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :) if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running"); if (animation != nullptr) { std::vector frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones( *animation, - 1.0f + tempTime ); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index 3bad2ae5..de87d5fc 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -129,8 +129,8 @@ void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, un unsigned int* nameLengths = (unsigned int*)(fileData + offset); offset += sizeof(unsigned int) * 4; - if (offset + sizeof(float) * 2 > fileByteSize) { - throw Resource::FailedLoadingException("Reading Material specular and reflection values failed"); + if (offset + sizeof(float) * 11 + sizeof(unsigned int) * 2 > fileByteSize) { + throw Resource::FailedLoadingException("Reading Material specular, reflection, color and start and end index values failed"); } newMaterial.SpecularExponent = *(float*)(fileData + offset); @@ -138,9 +138,12 @@ void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, un newMaterial.ReflectionFactor = *(float*)(fileData + offset); offset += sizeof(float); - if (offset + sizeof(unsigned int) * 2 > fileByteSize) { - throw Resource::FailedLoadingException("Reading Material start and end index values failed"); - } + memcpy(newMaterial.DiffuseColor, fileData + offset, sizeof(float) * 3); + offset += sizeof(float) * 3; + memcpy(newMaterial.SpecularColor, fileData + offset, sizeof(float) * 3); + offset += sizeof(float) * 3; + memcpy(newMaterial.IncandescenceColor, fileData + offset, sizeof(float) * 3); + offset += sizeof(float) * 3; newMaterial.StartIndex = *(unsigned int*)(fileData + offset); offset += sizeof(unsigned int); @@ -202,7 +205,7 @@ void RawModelCustom::ReadAnimationFile(std::string filePath) if (!in.is_open()) { //throw Resource::FailedLoadingException("Open animation file failed"); - return; // AJABAJA!!!!!!!! + return; } unsigned int fileByteSize = in.tellg(); diff --git a/tools/MayaExporter/MayaExporter/Material.cpp b/tools/MayaExporter/MayaExporter/Material.cpp index 0a897e6e..03521231 100644 --- a/tools/MayaExporter/MayaExporter/Material.cpp +++ b/tools/MayaExporter/MayaExporter/Material.cpp @@ -5,23 +5,30 @@ void Material::grabLambertProperties(MaterialNode& material_node, MFnDependencyN material_node.Name = node.name().asChar(); if (!findColorTexture(material_node, node)) { - MGlobal::displayWarning(MString() + "Material " + node.name() + " has no color texture. Please apply a texture insted of using a value"); + node.findPlug("colorR").getValue(material_node.DiffuseColor[0]); + node.findPlug("colorG").getValue(material_node.DiffuseColor[1]); + node.findPlug("colorB").getValue(material_node.DiffuseColor[2]); + } - if (findIncandescenceTexture(material_node, node)) { - MGlobal::displayWarning(MString() + "Material " + node.name() + " has no Incandescence texture. Please apply a texture insted of using value"); + if (!findIncandescenceTexture(material_node, node)) { + node.findPlug("incandescenceR").getValue(material_node.IncandescenceColor[0]); + node.findPlug("incandescenceG").getValue(material_node.IncandescenceColor[1]); + node.findPlug("incandescenceB").getValue(material_node.IncandescenceColor[2]); } if (findNormalTexture(material_node, node)) { - MGlobal::displayWarning(MString() + "Material " + node.name() + " has no normal texture. Please apply a texture to it"); + MGlobal::displayWarning(MString() + "Material " + node.name() + " has no normal texture."); } } void Material::grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node) { - if (findSpecularTexture(material_node, node)) { - MGlobal::displayWarning(MString() + "Material " + node.name() + " has no specular texture. Please apply a specular to it"); + if (!findSpecularTexture(material_node, node)) { + node.findPlug("specularColorR").getValue(material_node.SpecularColor[0]); + node.findPlug("specularColorG").getValue(material_node.SpecularColor[1]); + node.findPlug("specularColorB").getValue(material_node.SpecularColor[2]); } m_Plug = node.findPlug("reflectivity"); @@ -43,8 +50,10 @@ void Material::grabBlinnProperties(MaterialNode& material_node, MFnDependencyNod void Material::grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node) { - if (findSpecularTexture(material_node, node)) { - MGlobal::displayWarning(MString() + "Material " + node.name() + " has no specular texture. Please apply a specular to it"); + if (!findSpecularTexture(material_node, node)) { + node.findPlug("specularColorR").getValue(material_node.SpecularColor[0]); + node.findPlug("specularColorG").getValue(material_node.SpecularColor[1]); + node.findPlug("specularColorB").getValue(material_node.SpecularColor[2]); } m_Plug = node.findPlug("reflectivity"); @@ -188,20 +197,21 @@ std::vector* Material::DoIt(Mesh mesh) // All materials we care about inherit from Lambert MItDependencyNodes matIt(MFn::kLambert); m_AllMaterials.clear(); - int totalIndices = 0; while (!matIt.isDone()) { MFnDependencyNode MaterialFnDN(matIt.thisNode()); MaterialNode MaterialStorage; bool meshHasMaterial = false; //Mesh Indices is a map with : indices> + int totalIndices = 0; for (auto aMeshMaterial : mesh.Indices) { + MGlobal::displayInfo(MString() + "Material: " + aMeshMaterial.first.c_str() + " " + MaterialFnDN.name().asChar()); if (aMeshMaterial.first.compare(MaterialFnDN.name().asChar()) == 0) { meshHasMaterial = true; MaterialStorage.IndexStart = totalIndices; MaterialStorage.IndexEnd = totalIndices + aMeshMaterial.second.size() - 1; - totalIndices += aMeshMaterial.second.size(); break; } + totalIndices += aMeshMaterial.second.size(); } if (meshHasMaterial) { grabLambertProperties(MaterialStorage, MaterialFnDN); diff --git a/tools/MayaExporter/MayaExporter/Material.h b/tools/MayaExporter/MayaExporter/Material.h index 4b567d8b..341843e8 100644 --- a/tools/MayaExporter/MayaExporter/Material.h +++ b/tools/MayaExporter/MayaExporter/Material.h @@ -19,15 +19,18 @@ public: float ReflectionFactor; float SpecularExponent; + float DiffuseColor[3]{ 1.0f }; unsigned int ColorMapFileLength = 0; std::string ColorMapFile; + float SpecularColor[3]{ 1.0f }; unsigned int SpecularMapFileLength = 0; std::string SpecularMapFile; unsigned int NormalMapFileLength = 0; std::string NormalMapFile; + float IncandescenceColor[3]{ 1.0f }; unsigned int IncandescenceMapFileLength = 0; std::string IncandescenceMapFile; @@ -43,6 +46,9 @@ public: out.write((char*)&SpecularExponent, sizeof(float)); out.write((char*)&ReflectionFactor, sizeof(float)); + out.write((char*)&DiffuseColor, sizeof(float) * 3); + out.write((char*)&SpecularColor, sizeof(float) * 3); + out.write((char*)&IncandescenceColor, sizeof(float) * 3); out.write((char*)&IndexStart, sizeof(unsigned int)); out.write((char*)&IndexEnd, sizeof(unsigned int)); @@ -64,6 +70,9 @@ public: out << "SpecularExponent: " << SpecularExponent << endl; out << "ReflectionFactor: " << ReflectionFactor << endl; + out << "DiffuseColor: " << DiffuseColor[0] << " " << DiffuseColor[1] << " " << DiffuseColor[2] << endl; + out << "SpecularColor: " << SpecularColor[0] << " " << SpecularColor[1] << " " << SpecularColor[2] << endl; + out << "IncandescenceColor: " << IncandescenceColor[0] << " " << IncandescenceColor[1] << " " << IncandescenceColor[2] << endl; out << "IndexStart: " << IndexStart << endl; out << "IndexEnd: " << IndexEnd << endl; diff --git a/tools/MayaExporter/MayaExporter/Menu.cpp b/tools/MayaExporter/MayaExporter/Menu.cpp index 4f32af84..9cc6de91 100644 --- a/tools/MayaExporter/MayaExporter/Menu.cpp +++ b/tools/MayaExporter/MayaExporter/Menu.cpp @@ -104,9 +104,10 @@ Menu::Menu(QDialog* dialog) // Set the layout for our window dialog->setLayout(baseLayout); - for (unsigned int i = 0; i < 3; i++) { - this->AddClipClicked(true); - } + this->AddClipClicked(true); + //for (unsigned int i = 0; i < 3; i++) { + // this->AddClipClicked(true); + //} } diff --git a/tools/MayaExporter/MayaExporter/Mesh.cpp b/tools/MayaExporter/MayaExporter/Mesh.cpp index 26d5c7b2..6af8a557 100644 --- a/tools/MayaExporter/MayaExporter/Mesh.cpp +++ b/tools/MayaExporter/MayaExporter/Mesh.cpp @@ -309,12 +309,22 @@ Mesh MeshClass::GetMeshData(MObjectArray object) if (hasSkin) { + float totalWeight = 0.0f; + unsigned int totalBones = 0; MIntArray jointIDs /* ??? */; weights.selectAncestorLogicalIndex(vertexIndex, weightListObject); weights.getExistingArrayAttributeIndices(jointIDs); for (unsigned int i = 0; i < jointIDs.length() && i < 4; i++) { - thisVertex.BoneIndices[i] = jointIDs[i]; - thisVertex.BoneWeights[i] = weights[i].asFloat(); + if (weights[i].asFloat() > 0.001f) { + thisVertex.BoneIndices[totalBones] = jointIDs[i]; + thisVertex.BoneWeights[totalBones] = weights[i].asFloat(); + totalWeight = totalWeight + weights[i].asFloat(); + totalBones++; + } + } + + for (unsigned int i = 0; i < 4; i++) { + thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight; } } diff --git a/tools/MayaExporter/MayaExporter/WriteToFile.cpp b/tools/MayaExporter/MayaExporter/WriteToFile.cpp index 10883416..a0368c4f 100644 --- a/tools/MayaExporter/MayaExporter/WriteToFile.cpp +++ b/tools/MayaExporter/MayaExporter/WriteToFile.cpp @@ -25,10 +25,13 @@ bool WriteToFile::ASCIIFilePath(string filePathAndFileName) void WriteToFile::OpenFiles() { - if (binFile) - binFile.open(binFileName, ofstream::binary); - if (ASCIIFile) + if (binFile) { + binFile.open(binFileName, ofstream::binary); + } + if (ASCIIFile){ ASCIIFile.open(ASCIIFileName); + ASCIIFile << std::fixed << std::setprecision(3); + } } void WriteToFile::CloseFiles() diff --git a/tools/MayaExporter/MayaExporter/WriteToFile.h b/tools/MayaExporter/MayaExporter/WriteToFile.h index 91ca7103..216fcfc9 100644 --- a/tools/MayaExporter/MayaExporter/WriteToFile.h +++ b/tools/MayaExporter/MayaExporter/WriteToFile.h @@ -5,6 +5,7 @@ #include "OutputData.h" #include #include +#include using namespace std; From 8286d052b34801763295e6ab487100c1f9606a2d Mon Sep 17 00:00:00 2001 From: antc13 Date: Sun, 24 Jan 2016 14:18:04 +0100 Subject: [PATCH 25/28] Changed color values from floats to glm::vec4 --- include/Engine/Rendering/ModelJob.h | 8 ++++++++ include/Engine/Rendering/RawModelCustom.h | 6 +++--- resources/Shaders/ForwardPlus.frag.glsl | 3 ++- src/Engine/Rendering/DrawFinalPass.cpp | 1 + src/Engine/Rendering/RawModelCustom.cpp | 6 +++--- src/Engine/Rendering/Skeleton.cpp | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/Engine/Rendering/ModelJob.h b/include/Engine/Rendering/ModelJob.h index a88530e7..01f4cca4 100644 --- a/include/Engine/Rendering/ModelJob.h +++ b/include/Engine/Rendering/ModelJob.h @@ -24,6 +24,10 @@ struct ModelJob : RenderJob DiffuseTexture = matGroup.Texture.get(); NormalTexture = matGroup.NormalMap.get(); SpecularTexture = matGroup.SpecularMap.get(); + IncandescenceTexture = matGroup.IncandescenceMap.get(); + DiffuseColor = matGroup.DiffuseColor; + SpecularColor = matGroup.SpecularColor; + IncandescenceColor = matGroup.IncandescenceColor; StartIndex = matGroup.StartIndex; EndIndex = matGroup.EndIndex; Matrix = matrix; @@ -43,9 +47,13 @@ struct ModelJob : RenderJob const Texture* DiffuseTexture; const Texture* NormalTexture; const Texture* SpecularTexture; + const Texture* IncandescenceTexture; float Shininess = 0.f; glm::vec4 Color; const ::Model* Model = nullptr; + glm::vec4 DiffuseColor; + glm::vec4 SpecularColor; + glm::vec4 IncandescenceColor; unsigned int StartIndex = 0; unsigned int EndIndex = 0; World* World; diff --git a/include/Engine/Rendering/RawModelCustom.h b/include/Engine/Rendering/RawModelCustom.h index a1a2f1f6..f1bc0e24 100644 --- a/include/Engine/Rendering/RawModelCustom.h +++ b/include/Engine/Rendering/RawModelCustom.h @@ -48,9 +48,9 @@ public: { float SpecularExponent; float ReflectionFactor; - float DiffuseColor[3]; - float SpecularColor[3]; - float IncandescenceColor[3]; + glm::vec4 DiffuseColor{ 1.0f, 1.0f, 1.0f, 1.0f }; + glm::vec4 SpecularColor{ 1.0f, 1.0f, 1.0f, 1.0f }; + glm::vec4 IncandescenceColor{ 1.0f, 1.0f, 1.0f, 1.0f }; unsigned int StartIndex; unsigned int EndIndex; //float Transparency; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index b9db56d3..2a524096 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -4,6 +4,7 @@ uniform mat4 M; uniform mat4 V; uniform mat4 P; uniform vec4 Color; +uniform vec4 DiffuseColor; uniform vec2 ScreenDimensions; uniform sampler2D texture0; @@ -129,7 +130,7 @@ void main() totalLighting.Specular += result.Specular; } - fragmentColor += (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; + fragmentColor += DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; //fragmentColor += Input.DiffuseColor; //fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color; //fragmentColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Amount/3, 0, 1); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 7be1223a..2b126951 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -45,6 +45,7 @@ void DrawFinalPass::Draw(RenderScene& scene) //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color)); + glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(modelJob->DiffuseColor)); if(modelJob->DiffuseTexture != nullptr) { glActiveTexture(GL_TEXTURE0); diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index de87d5fc..fca796ac 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -138,11 +138,11 @@ void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, un newMaterial.ReflectionFactor = *(float*)(fileData + offset); offset += sizeof(float); - memcpy(newMaterial.DiffuseColor, fileData + offset, sizeof(float) * 3); + memcpy(&newMaterial.DiffuseColor[0], fileData + offset, sizeof(float) * 3); offset += sizeof(float) * 3; - memcpy(newMaterial.SpecularColor, fileData + offset, sizeof(float) * 3); + memcpy(&newMaterial.SpecularColor[0], fileData + offset, sizeof(float) * 3); offset += sizeof(float) * 3; - memcpy(newMaterial.IncandescenceColor, fileData + offset, sizeof(float) * 3); + memcpy(&newMaterial.IncandescenceColor[0], fileData + offset, sizeof(float) * 3); offset += sizeof(float) * 3; newMaterial.StartIndex = *(unsigned int*)(fileData + offset); diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 986e634c..1f150b00 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -90,7 +90,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyf int k = 0; } else { if (bone->Parent) { - boneMatrix = parentMatrix * bone->Parent->OffsetMatrix * glm::translate(glm::vec3(1.718, 0, 0)); // * glm::inverse(bone->OffsetMatrix); + boneMatrix = parentMatrix; // * glm::inverse(bone->OffsetMatrix); } boneMatrices[bone->ID] = boneMatrix; // * bone->OffsetMatrix; } From 666f1fd8784a9aed5439ae5f1df0d0335996bd31 Mon Sep 17 00:00:00 2001 From: antc13 Date: Sun, 24 Jan 2016 15:30:20 +0100 Subject: [PATCH 26/28] Removed temp variables & the "forced" animation in DrawFinalPass --- resources/Shaders/ForwardPlus.frag.glsl | 4 +-- .../Rendering/DrawColorCorrectionPass.cpp | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 30 +++++++------------ src/Engine/Rendering/RawModelAssimp.cpp | 1 - src/Engine/Rendering/RawModelCustom.cpp | 1 - src/Engine/Rendering/RenderSystem.cpp | 12 ++------ src/Engine/Rendering/Skeleton.cpp | 1 - tools/MayaExporter/MayaExporter/Material.h | 6 ++-- 8 files changed, 19 insertions(+), 38 deletions(-) diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index e158640e..57b1d627 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -4,6 +4,7 @@ uniform mat4 M; uniform mat4 V; uniform mat4 P; uniform vec4 Color; +uniform vec4 DiffuseColor; uniform vec2 ScreenDimensions; layout (binding = 0) uniform sampler2D DiffuseTexture; layout (binding = 1) uniform sampler2D GlowMap; @@ -46,7 +47,6 @@ in VertexData{ vec3 Position; vec3 Normal; vec2 TextureCoordinate; - vec4 DiffuseColor; }Input; out vec4 sceneColor; @@ -135,7 +135,7 @@ void main() } //sceneColor += Input.DiffuseColor; - vec4 color_result = Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * diffuseTexel * Color; + vec4 color_result = DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * diffuseTexel * Color; //bloomColor = vec4(0.3, 0.8, 0.6, 1.0); sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); //These if statements should be removed if they are slow. diff --git a/src/Engine/Rendering/DrawColorCorrectionPass.cpp b/src/Engine/Rendering/DrawColorCorrectionPass.cpp index c9789602..5989584e 100644 --- a/src/Engine/Rendering/DrawColorCorrectionPass.cpp +++ b/src/Engine/Rendering/DrawColorCorrectionPass.cpp @@ -5,7 +5,7 @@ DrawColorCorrectionPass::DrawColorCorrectionPass(IRenderer* renderer) m_Renderer = renderer; m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.obj"); - m_Exposure = 1; //TODO: Renderer: Fixa så att denna går att ändra på genom komponent eller setting. + m_Exposure = 0.4; //TODO: Renderer: Fixa så att denna går att ändra på genom komponent eller setting. InitializeShaderPrograms(); } diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index fddc0338..9977f194 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -43,7 +43,7 @@ void DrawFinalPass::InitializeShaderPrograms() m_ForwardPlusProgram->BindFragDataLocation(1, "bloomColor"); m_ForwardPlusProgram->Link(); } -static double tempTime = 0.0; + void DrawFinalPass::Draw(RenderScene& scene) { GLERROR("DrawFinalPass::Draw: Pre"); @@ -65,6 +65,7 @@ void DrawFinalPass::Draw(RenderScene& scene) glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); + //TODO: Render: Add code for more jobs than modeljobs. for (auto &job : scene.ForwardJobs) { auto modelJob = std::dynamic_pointer_cast(job); @@ -80,33 +81,24 @@ void DrawFinalPass::Draw(RenderScene& scene) } else { glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); } - tempTime += 0.01f; - //TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :) - if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { - auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running"); - if (animation != nullptr) { - std::vector frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones( - *animation, - tempTime glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); - - /*if(modelJob->GlowMap != nullptr) { - glBindTexture(GL_TEXTURE_2D, modelJob->GlowMap->m_Texture); + if (modelJob->IncandescenceTexture != nullptr) { + glBindTexture(GL_TEXTURE_2D, modelJob->IncandescenceTexture->m_Texture); } else { glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); - }*/ - ); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); - } } - + + /*if(modelJob->GlowMap != nullptr) { + glBindTexture(GL_TEXTURE_2D, modelJob->GlowMap->m_Texture); + } else { + glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); + }*/ + glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); } } - m_FinalPassFrameBuffer.Unbind(); GLERROR("DrawFinalPass::Draw: END"); delete state; } diff --git a/src/Engine/Rendering/RawModelAssimp.cpp b/src/Engine/Rendering/RawModelAssimp.cpp index 6bc3f3f7..7bf72a22 100644 --- a/src/Engine/Rendering/RawModelAssimp.cpp +++ b/src/Engine/Rendering/RawModelAssimp.cpp @@ -273,7 +273,6 @@ RawModelAssimp::RawModelAssimp(std::string fileName) m_Skeleton->Animations[animationName] = skelAnim; } - int k = 0; } RawModelAssimp::~RawModelAssimp() diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index fca796ac..74c524c9 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -8,7 +8,6 @@ RawModelCustom::RawModelCustom(std::string fileName) ReadMeshFile(fileName); ReadMaterialFile(fileName); ReadAnimationFile(fileName); - int k = 0; } void RawModelCustom::ReadMeshFile(std::string filePath) diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 455e25e9..334b3b1b 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -51,18 +51,10 @@ void RenderSystem::fillModels(std::list>& jobs) model = ResourceManager::Load<::Model, true>(resource); } catch (const Resource::StillLoadingException&) { //continue; -#ifdef USING_ASSIMP_AS_IMPORTER - model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.obj"); // 360NoScope StillLoading mesh -#else - model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.mesh"); -#endif + model = ResourceManager::Load<::Model>("Models/Core/Error.mesh"); } catch (const std::exception&) { try { -#ifdef USING_ASSIMP_AS_IMPORTER - model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.obj"); // 360NoScope Error mesh -#else - model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.mesh"); -#endif + model = ResourceManager::Load<::Model>("Models/Core/Error.mesh"); } catch (const std::exception&) { continue; } diff --git a/src/Engine/Rendering/Skeleton.cpp b/src/Engine/Rendering/Skeleton.cpp index 1f150b00..cebabb67 100644 --- a/src/Engine/Rendering/Skeleton.cpp +++ b/src/Engine/Rendering/Skeleton.cpp @@ -87,7 +87,6 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyf boneMatrix = parentMatrix * (glm::translate(positionInterp) * glm::toMat4(rotationInterp) * glm::scale(scaleInterp)); boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix; - int k = 0; } else { if (bone->Parent) { boneMatrix = parentMatrix; // * glm::inverse(bone->OffsetMatrix); diff --git a/tools/MayaExporter/MayaExporter/Material.h b/tools/MayaExporter/MayaExporter/Material.h index 341843e8..e405dd07 100644 --- a/tools/MayaExporter/MayaExporter/Material.h +++ b/tools/MayaExporter/MayaExporter/Material.h @@ -19,18 +19,18 @@ public: float ReflectionFactor; float SpecularExponent; - float DiffuseColor[3]{ 1.0f }; + float DiffuseColor[3]{ 1.0f, 1.0f, 1.0f }; unsigned int ColorMapFileLength = 0; std::string ColorMapFile; - float SpecularColor[3]{ 1.0f }; + float SpecularColor[3]{ 1.0f, 1.0f, 1.0f }; unsigned int SpecularMapFileLength = 0; std::string SpecularMapFile; unsigned int NormalMapFileLength = 0; std::string NormalMapFile; - float IncandescenceColor[3]{ 1.0f }; + float IncandescenceColor[3]{ 1.0f, 1.0f, 1.0f }; unsigned int IncandescenceMapFileLength = 0; std::string IncandescenceMapFile; From 96a735c54289ca80108f6a0c2d48101418801347 Mon Sep 17 00:00:00 2001 From: antc13 Date: Sun, 24 Jan 2016 16:12:31 +0100 Subject: [PATCH 27/28] Changed .obj to .mesh for all meshes. --- assets | 2 +- .../{AnimatedArmy => AnimatedArmy.xml} | 0 resources/Schema/Entities/CaptureTest.xml | 14 ++++++------- .../Schema/Entities/CaptureTestState1.xml | 14 ++++++------- .../Schema/Entities/CaptureTestState2.xml | 14 ++++++------- .../Schema/Entities/CaptureTestState3.xml | 20 +++++++++---------- .../Schema/Entities/CaptureTestState4.xml | 20 +++++++++---------- resources/Schema/Entities/CollisionTest1.xml | 2 +- .../Schema/Entities/EditorWidgetRotate.xml | 6 +++--- .../Schema/Entities/EditorWidgetScale.xml | 8 ++++---- .../Schema/Entities/EditorWidgetTranslate.xml | 14 ++++++------- resources/Schema/Entities/Empty.xml | 12 ++++++++++- resources/Schema/Entities/RenderingWorld.xml | 14 ++++++------- resources/Schema/Entities/ShootEventTest.xml | 20 +++++++++---------- resources/Schema/Entities/Test.xml | 4 ++-- src/Engine/Editor/EditorRenderSystem.cpp | 2 +- src/Engine/Rendering/DrawBloomPass.cpp | 2 +- .../Rendering/DrawColorCorrectionPass.cpp | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 12 +++++++++++ src/Engine/Rendering/DrawScreenQuadPass.cpp | 2 +- src/Engine/Rendering/RawModelCustom.cpp | 3 +++ src/Tests/ResourceManagerTest.cpp | 2 +- 22 files changed, 107 insertions(+), 82 deletions(-) rename resources/Schema/Entities/{AnimatedArmy => AnimatedArmy.xml} (100%) diff --git a/assets b/assets index e8174f63..068fbb2d 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit e8174f630fc3242e15ada1346b42c72f44cbc854 +Subproject commit 068fbb2d20682dd60f186c82172d7731e60ed7e9 diff --git a/resources/Schema/Entities/AnimatedArmy b/resources/Schema/Entities/AnimatedArmy.xml similarity index 100% rename from resources/Schema/Entities/AnimatedArmy rename to resources/Schema/Entities/AnimatedArmy.xml diff --git a/resources/Schema/Entities/CaptureTest.xml b/resources/Schema/Entities/CaptureTest.xml index 70a8ae14..5f657e51 100644 --- a/resources/Schema/Entities/CaptureTest.xml +++ b/resources/Schema/Entities/CaptureTest.xml @@ -9,7 +9,7 @@ - ../assets/Models/DummyScene.obj + ../assets/Models/DummyScene.mesh @@ -41,7 +41,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -61,7 +61,7 @@ 1 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -81,7 +81,7 @@ 2 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -102,7 +102,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -120,7 +120,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -138,7 +138,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/CaptureTestState1.xml b/resources/Schema/Entities/CaptureTestState1.xml index 75b14858..ffabd5c2 100644 --- a/resources/Schema/Entities/CaptureTestState1.xml +++ b/resources/Schema/Entities/CaptureTestState1.xml @@ -9,7 +9,7 @@ - ../assets/Models/DummyScene.obj + ../assets/Models/DummyScene.mesh @@ -42,7 +42,7 @@ 6.9158446328696002 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -63,7 +63,7 @@ 1 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -83,7 +83,7 @@ 2 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -104,7 +104,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -122,7 +122,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -140,7 +140,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/CaptureTestState2.xml b/resources/Schema/Entities/CaptureTestState2.xml index 77673324..29abdfbd 100644 --- a/resources/Schema/Entities/CaptureTestState2.xml +++ b/resources/Schema/Entities/CaptureTestState2.xml @@ -9,7 +9,7 @@ - ../assets/Models/DummyScene.obj + ../assets/Models/DummyScene.mesh @@ -41,7 +41,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -61,7 +61,7 @@ 1 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -79,7 +79,7 @@ 2 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -98,7 +98,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -116,7 +116,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -134,7 +134,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/CaptureTestState3.xml b/resources/Schema/Entities/CaptureTestState3.xml index 99da90a6..ff875dc4 100644 --- a/resources/Schema/Entities/CaptureTestState3.xml +++ b/resources/Schema/Entities/CaptureTestState3.xml @@ -9,7 +9,7 @@ - ../assets/Models/DummyScene.obj + ../assets/Models/DummyScene.mesh @@ -41,7 +41,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -61,7 +61,7 @@ 1 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -81,7 +81,7 @@ 2 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -101,7 +101,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -122,7 +122,7 @@ 4 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -140,7 +140,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -158,7 +158,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -176,7 +176,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -194,7 +194,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/CaptureTestState4.xml b/resources/Schema/Entities/CaptureTestState4.xml index 695df52e..740d7e7b 100644 --- a/resources/Schema/Entities/CaptureTestState4.xml +++ b/resources/Schema/Entities/CaptureTestState4.xml @@ -9,7 +9,7 @@ - ../assets/Models/DummyScene.obj + ../assets/Models/DummyScene.mesh @@ -41,7 +41,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -61,7 +61,7 @@ 1 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -79,7 +79,7 @@ 2 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -96,7 +96,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -115,7 +115,7 @@ 4 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -133,7 +133,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -151,7 +151,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -169,7 +169,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -187,7 +187,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/CollisionTest1.xml b/resources/Schema/Entities/CollisionTest1.xml index f0b310e1..e731a17a 100644 --- a/resources/Schema/Entities/CollisionTest1.xml +++ b/resources/Schema/Entities/CollisionTest1.xml @@ -24,7 +24,7 @@ false - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/EditorWidgetRotate.xml b/resources/Schema/Entities/EditorWidgetRotate.xml index b918794e..88452aac 100644 --- a/resources/Schema/Entities/EditorWidgetRotate.xml +++ b/resources/Schema/Entities/EditorWidgetRotate.xml @@ -18,7 +18,7 @@ - Models/RotationWidgetX.obj + Models/RotationWidgetX.mesh @@ -33,7 +33,7 @@ - Models/RotationWidgetY.obj + Models/RotationWidgetY.mesh @@ -48,7 +48,7 @@ - Models/RotationWidgetZ.obj + Models/RotationWidgetZ.mesh diff --git a/resources/Schema/Entities/EditorWidgetScale.xml b/resources/Schema/Entities/EditorWidgetScale.xml index 15bcb38b..786b079e 100644 --- a/resources/Schema/Entities/EditorWidgetScale.xml +++ b/resources/Schema/Entities/EditorWidgetScale.xml @@ -3,7 +3,7 @@ - Models/ScaleWidgetOrigin.obj + Models/ScaleWidgetOrigin.mesh @@ -20,7 +20,7 @@ - Models/ScaleWidgetX.obj + Models/ScaleWidgetX.mesh @@ -34,7 +34,7 @@ - Models/ScaleWidgetY.obj + Models/ScaleWidgetY.mesh @@ -48,7 +48,7 @@ - Models/ScaleWidgetZ.obj + Models/ScaleWidgetZ.mesh diff --git a/resources/Schema/Entities/EditorWidgetTranslate.xml b/resources/Schema/Entities/EditorWidgetTranslate.xml index a9b7eaff..d4ed5e76 100644 --- a/resources/Schema/Entities/EditorWidgetTranslate.xml +++ b/resources/Schema/Entities/EditorWidgetTranslate.xml @@ -3,7 +3,7 @@ - Models/TranslationWidgetOrigin.obj + Models/TranslationWidgetOrigin.mesh @@ -18,7 +18,7 @@ - Models/TranslationWidgetX.obj + Models/TranslationWidgetX.mesh @@ -30,7 +30,7 @@ - Models/TranslationWidgetY.obj + Models/TranslationWidgetY.mesh @@ -42,7 +42,7 @@ - Models/TranslationWidgetZ.obj + Models/TranslationWidgetZ.mesh @@ -54,7 +54,7 @@ - Models/WidgetPlaneX.obj + Models/WidgetPlaneX.mesh @@ -66,7 +66,7 @@ - Models/WidgetPlaneY.obj + Models/WidgetPlaneY.mesh @@ -78,7 +78,7 @@ - Models/WidgetPlaneZ.obj + Models/WidgetPlaneZ.mesh diff --git a/resources/Schema/Entities/Empty.xml b/resources/Schema/Entities/Empty.xml index 6efd8318..c9b8924f 100644 --- a/resources/Schema/Entities/Empty.xml +++ b/resources/Schema/Entities/Empty.xml @@ -5,6 +5,16 @@ - + + + + + + + + + + + diff --git a/resources/Schema/Entities/RenderingWorld.xml b/resources/Schema/Entities/RenderingWorld.xml index 69b18982..796a66f0 100644 --- a/resources/Schema/Entities/RenderingWorld.xml +++ b/resources/Schema/Entities/RenderingWorld.xml @@ -12,7 +12,7 @@ ActionCamera - Models/Camera.obj + Models/Camera.mesh @@ -39,7 +39,7 @@ - Models/Core/UnitPlane.obj + Models/Core/UnitPlane.mesh @@ -51,7 +51,7 @@ - Models/Assault.obj + Models/Assault.mesh @@ -190,7 +190,7 @@ - Models/Assault.obj + Models/Assault.mesh @@ -205,7 +205,7 @@ - Models/Camera.obj + Models/Camera.mesh false @@ -237,7 +237,7 @@ 0.80000001192092896 - Models/DirectionalLightWidget.obj + Models/DirectionalLightWidget.mesh @@ -249,7 +249,7 @@ - Models/Core/UnitCube.obj + Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/ShootEventTest.xml b/resources/Schema/Entities/ShootEventTest.xml index eae333b6..9e9adf50 100644 --- a/resources/Schema/Entities/ShootEventTest.xml +++ b/resources/Schema/Entities/ShootEventTest.xml @@ -9,7 +9,7 @@ - ../assets/Models/DummyScene.obj + ../assets/Models/DummyScene.mesh @@ -41,7 +41,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -61,7 +61,7 @@ 1 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -79,7 +79,7 @@ 2 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -96,7 +96,7 @@ 3 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -115,7 +115,7 @@ 4 - ../assets/Models/Core/UnitSphere.obj + ../assets/Models/Core/UnitSphere.mesh @@ -133,7 +133,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -151,7 +151,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -171,7 +171,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh @@ -191,7 +191,7 @@ - ../assets/Models/Core/UnitCube.obj + ../assets/Models/Core/UnitCube.mesh diff --git a/resources/Schema/Entities/Test.xml b/resources/Schema/Entities/Test.xml index 42e2660e..1f8da1a3 100644 --- a/resources/Schema/Entities/Test.xml +++ b/resources/Schema/Entities/Test.xml @@ -6,7 +6,7 @@ - Models/DummyScene.obj + Models/DummyScene.mesh @@ -19,7 +19,7 @@ - Models/Camera.obj + Models/Camera.mesh diff --git a/src/Engine/Editor/EditorRenderSystem.cpp b/src/Engine/Editor/EditorRenderSystem.cpp index 2e31e3f0..ed054052 100644 --- a/src/Engine/Editor/EditorRenderSystem.cpp +++ b/src/Engine/Editor/EditorRenderSystem.cpp @@ -39,7 +39,7 @@ void EditorRenderSystem::Update(double dt) continue; } catch (const std::exception&) { try { - model = ResourceManager::Load<::Model>("Models/Core/Error.obj"); + model = ResourceManager::Load<::Model>("Models/Core/Error.mesh"); } catch (const std::exception&) { continue; } diff --git a/src/Engine/Rendering/DrawBloomPass.cpp b/src/Engine/Rendering/DrawBloomPass.cpp index 1ad97eb5..8fe1d807 100644 --- a/src/Engine/Rendering/DrawBloomPass.cpp +++ b/src/Engine/Rendering/DrawBloomPass.cpp @@ -4,7 +4,7 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer) { m_Renderer = renderer; - m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.obj"); + m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.mesh"); InitializeTextures(); InitializeBuffers(); diff --git a/src/Engine/Rendering/DrawColorCorrectionPass.cpp b/src/Engine/Rendering/DrawColorCorrectionPass.cpp index 5989584e..ba9efe3e 100644 --- a/src/Engine/Rendering/DrawColorCorrectionPass.cpp +++ b/src/Engine/Rendering/DrawColorCorrectionPass.cpp @@ -4,7 +4,7 @@ DrawColorCorrectionPass::DrawColorCorrectionPass(IRenderer* renderer) { m_Renderer = renderer; - m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.obj"); + m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.mesh"); m_Exposure = 0.4; //TODO: Renderer: Fixa så att denna går att ändra på genom komponent eller setting. InitializeShaderPrograms(); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 9977f194..ca2a9d77 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -94,6 +94,18 @@ void DrawFinalPass::Draw(RenderScene& scene) glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); }*/ + //TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :) + if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { + auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running"); + if (animation != nullptr) { + std::vector frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones( + *animation, + 0.0f + ); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); + } + } + glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int))); diff --git a/src/Engine/Rendering/DrawScreenQuadPass.cpp b/src/Engine/Rendering/DrawScreenQuadPass.cpp index 4b155fc9..b17f5e29 100644 --- a/src/Engine/Rendering/DrawScreenQuadPass.cpp +++ b/src/Engine/Rendering/DrawScreenQuadPass.cpp @@ -4,7 +4,7 @@ DrawScreenQuadPass::DrawScreenQuadPass(IRenderer* renderer) { m_Renderer = renderer; - m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.obj"); + m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.mesh"); InitializeShaderPrograms(); } diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index 74c524c9..83f6e703 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -4,6 +4,9 @@ RawModelCustom::RawModelCustom(std::string fileName) { + if(fileName.substr(fileName.find_last_of(".")).compare(".mesh") != 0) { + throw Resource::FailedLoadingException("Unknown model file format. Please use \".mesh\" files."); + } fileName = fileName.erase(fileName.find_last_of("."), fileName.find_last_of(".") - fileName.size()); ReadMeshFile(fileName); ReadMaterialFile(fileName); diff --git a/src/Tests/ResourceManagerTest.cpp b/src/Tests/ResourceManagerTest.cpp index df1fd76d..1f9f4991 100644 --- a/src/Tests/ResourceManagerTest.cpp +++ b/src/Tests/ResourceManagerTest.cpp @@ -26,7 +26,7 @@ BOOST_AUTO_TEST_CASE(resourceManagerTest) BOOST_CHECK(!ResourceManager::IsResourceLoaded("ConfigFile", "Config.ini")); //configfile without register - BOOST_CHECK_THROW(ResourceManager::Load("Models/Core/ScreenQuad.obj"),Resource::FailedLoadingException); + BOOST_CHECK_THROW(ResourceManager::Load("Models/Core/ScreenQuad.mesh"),Resource::FailedLoadingException); //there is no error feedback to check if you try to release the wrong resources - hence that cant be tested either } From aa115befa936512a9d7a33c36db1e6cac040023a Mon Sep 17 00:00:00 2001 From: antc13 Date: Sun, 24 Jan 2016 17:04:12 +0100 Subject: [PATCH 28/28] UnitRaptor is now displayed while models are being loaded in. --- src/Engine/Rendering/RenderSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 9496fe7a..58bbd1ee 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -59,7 +59,7 @@ void RenderSystem::fillModels(std::list>& jobs) model = ResourceManager::Load<::Model, true>(resource); } catch (const Resource::StillLoadingException&) { //continue; - model = ResourceManager::Load<::Model>("Models/Core/Error.mesh"); + model = ResourceManager::Load<::Model>("Models/Core/UnitRaptor.mesh"); } catch (const std::exception&) { try { model = ResourceManager::Load<::Model>("Models/Core/Error.mesh");