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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user