Tested some of the Material Code. Seems to work. The project should now be following the code standard properly (hopefully).

This commit is contained in:
antc13
2015-12-10 11:18:34 +01:00
parent 74c1beed20
commit a22d086e60
9 changed files with 189 additions and 138 deletions
@@ -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;
}
}
@@ -5,6 +5,7 @@
#include <array>
#include <algorithm>
#include <cmath>
#include "MayaIncludes.h"
struct MaterialNode
@@ -173,6 +173,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="Main.cpp" />
<ClCompile Include="Mesh.cpp" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="MayaExporter.ui">
@@ -195,6 +196,7 @@
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Mesh.h" />
<CustomBuild Include="Menu.h">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Moc%27ing Menu.h...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
@@ -53,6 +53,9 @@
<ClCompile Include="Material.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Mesh.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="leeeeel.qrc">
@@ -75,5 +78,8 @@
<ClInclude Include="Material.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Mesh.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
+65 -116
View File
@@ -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<UINT, vector<UINT>> vertexToIndex;
vector<VertexLayout> verticesData;
vector<UINT>indexArray;
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<UINT> 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<MaterialNode>* AllMaterials = MaterialHandler->DoIt();
std::vector<MaterialNode>* 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;
}
+16 -22
View File
@@ -1,11 +1,9 @@
#ifndef BUTTONS_H
#define BUTTONS_H
#ifndef Menu_Menu_h__
#define Menu_Menu_h__
#include <map>
#include <vector>
#include "MayaIncludes.h"
#include "Material.h"
// Qt
#pragma comment(lib, "QtCore4")
#pragma comment(lib, "QtGui4")
@@ -32,12 +30,9 @@
#include <QtGui/qlineedit.h>
#include <QtGui/qgroupbox.h>
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
+70
View File
@@ -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<UINT, vector<UINT>> vertexToIndex;
vector<VertexLayout> verticesData;
vector<UINT>indexArray;
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<UINT> 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()
{
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef Mesh_Mesh_h__
#define Mesh_Mesh_h__
#include <map>
#include <vector>
#include "MayaIncludes.h"
struct VertexLayout
{
float Pos[3];
float Normal[3];
float Uv[2];
};
class Mesh
{
public:
Mesh();
void GetMeshData(MObject Object);
~Mesh();
};
#endif