Reworked the Exporter.

This commit is contained in:
antc13
2016-01-13 14:03:58 +01:00
parent 7b62dc19bf
commit 24486c314d
12 changed files with 369 additions and 241 deletions
+172
View File
@@ -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<AnimationInfo> 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<MaterialNode>* 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;*/
}
+54
View File
@@ -0,0 +1,54 @@
#ifndef Export_Export_h__
#define Export_Export_h__
#include <vector>
#include <string>
#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<AnimationInfo> 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<Mesh> meshes;
//Animation Data
std::vector<BindPoseSkeletonNode> allBindPoses;
std::vector<Animation> allAnimations;
};
#endif
@@ -22,7 +22,7 @@ static const uint qt_meta_data_Menu[] = {
6, // revision 6, // revision
0, // classname 0, // classname
0, 0, // classinfo 0, 0, // classinfo
9, 14, // methods 5, 14, // methods
0, 0, // properties 0, 0, // properties
0, 0, // enums/sets 0, 0, // enums/sets
0, 0, // constructors 0, 0, // constructors
@@ -30,25 +30,19 @@ static const uint qt_meta_data_Menu[] = {
0, // signalCount 0, // signalCount
// slots: signature, parameters, type, tag, flags // slots: signature, parameters, type, tag, flags
14, 6, 5, 5, 0x08, 6, 5, 5, 5, 0x08,
35, 5, 5, 5, 0x08, 30, 5, 5, 5, 0x08,
59, 5, 5, 5, 0x08, 51, 5, 5, 5, 0x08,
80, 5, 5, 5, 0x08, 75, 5, 5, 5, 0x08,
104, 5, 5, 5, 0x08, 91, 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 0 // eod
}; };
static const char qt_meta_stringdata_Menu[] = { static const char qt_meta_stringdata_Menu[] = {
"Menu\0\0checked\0ExportSelected(bool)\0" "Menu\0\0ExportPathClicked(bool)\0"
"ExportPathClicked(bool)\0AddClipClicked(bool)\0" "AddClipClicked(bool)\0RemoveClipClicked(bool)\0"
"RemoveClipClicked(bool)\0ExportAll(bool)\0" "ExportAll(bool)\0CancelClicked(bool)\0"
"CancelClicked(bool)\0Button1Clicked(bool)\0"
"Button2Clicked(bool)\0Button3Clicked(bool)\0"
}; };
void Menu::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 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)); Q_ASSERT(staticMetaObject.cast(_o));
Menu *_t = static_cast<Menu *>(_o); Menu *_t = static_cast<Menu *>(_o);
switch (_id) { switch (_id) {
case 0: _t->ExportSelected((*reinterpret_cast< bool(*)>(_a[1]))); break; case 0: _t->ExportPathClicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 1: _t->ExportPathClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; case 1: _t->AddClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 2: _t->AddClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; case 2: _t->RemoveClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 3: _t->RemoveClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break; case 3: _t->ExportAll((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 4: _t->ExportAll((*reinterpret_cast< bool(*)>(_a[1]))); break; case 4: _t->CancelClicked((*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: ; default: ;
} }
} }
@@ -103,9 +93,9 @@ int Menu::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0) if (_id < 0)
return _id; return _id;
if (_c == QMetaObject::InvokeMetaMethod) { if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 9) if (_id < 5)
qt_static_metacall(this, _c, _id, _a); qt_static_metacall(this, _c, _id, _a);
_id -= 9; _id -= 5;
} }
return _id; return _id;
} }
@@ -153,6 +153,7 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Export.cpp" />
<ClCompile Include="Material.cpp" /> <ClCompile Include="Material.cpp" />
<ClCompile Include="Menu.cpp" /> <ClCompile Include="Menu.cpp" />
<ClCompile Include="GeneratedFiles\Debug\moc_Menu.cpp"> <ClCompile Include="GeneratedFiles\Debug\moc_Menu.cpp">
@@ -199,6 +200,7 @@
</CustomBuild> </CustomBuild>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Export.h" />
<ClInclude Include="Mesh.h" /> <ClInclude Include="Mesh.h" />
<ClInclude Include="OutputData.h" /> <ClInclude Include="OutputData.h" />
<ClInclude Include="Skeleton.h" /> <ClInclude Include="Skeleton.h" />
@@ -62,6 +62,9 @@
<ClCompile Include="WriteToFile.cpp"> <ClCompile Include="WriteToFile.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Export.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="leeeeel.qrc"> <CustomBuild Include="leeeeel.qrc">
@@ -96,5 +99,8 @@
<ClInclude Include="OutputData.h"> <ClInclude Include="OutputData.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Export.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
+41 -172
View File
@@ -13,9 +13,8 @@ Menu::Menu(QDialog* dialog)
m_DialogPointer = dialog; m_DialogPointer = dialog;
// Create QpushButtons & give them names // Create QpushButtons & give them names
m_ExportSelectedButton = new QPushButton("&Export Selected", this);
m_BrowseButton = new QPushButton("&...", 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_CancelButton = new QPushButton("&Cancel", this);
m_AddClipsButton = new QPushButton("&Add Clips", this); m_AddClipsButton = new QPushButton("&Add Clips", this);
m_RemoveClipsButton = new QPushButton("&Remove Latest Clip", this); m_RemoveClipsButton = new QPushButton("&Remove Latest Clip", this);
@@ -23,6 +22,7 @@ Menu::Menu(QDialog* dialog)
// Option box and checkboxes // Option box and checkboxes
QGroupBox *optionsBox = new QGroupBox(tr("Options")); QGroupBox *optionsBox = new QGroupBox(tr("Options"));
m_ExportSelectedButton = new QCheckBox(tr("&Export Selected"));
m_ExportAnimationsButton = new QCheckBox(tr("&Export Animations")); m_ExportAnimationsButton = new QCheckBox(tr("&Export Animations"));
m_CopyTexturesButton = new QCheckBox(tr("&Copy Textures")); m_CopyTexturesButton = new QCheckBox(tr("&Copy Textures"));
m_Button3 = new QCheckBox(tr("Test Materials")); m_Button3 = new QCheckBox(tr("Test Materials"));
@@ -30,6 +30,7 @@ Menu::Menu(QDialog* dialog)
m_ExportAnimationsButton->setChecked(true); m_ExportAnimationsButton->setChecked(true);
m_CopyTexturesButton->setChecked(true); m_CopyTexturesButton->setChecked(true);
QVBoxLayout *vbox = new QVBoxLayout; QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(m_ExportSelectedButton);
vbox->addWidget(m_ExportAnimationsButton); vbox->addWidget(m_ExportAnimationsButton);
vbox->addWidget(m_CopyTexturesButton); vbox->addWidget(m_CopyTexturesButton);
vbox->addWidget(m_Button3); vbox->addWidget(m_Button3);
@@ -37,16 +38,16 @@ Menu::Menu(QDialog* dialog)
optionsBox->setLayout(vbox); optionsBox->setLayout(vbox);
// Connect the buttons with signals & functions // 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_BrowseButton, SIGNAL(clicked(bool)), this, SLOT(ExportPathClicked(bool)));
connect(m_ExportAllButton, SIGNAL(clicked(bool)), this, SLOT(ExportAll(bool))); connect(m_ExportAllButton, SIGNAL(clicked(bool)), this, SLOT(ExportAll(bool)));
connect(m_CancelButton, SIGNAL(clicked(bool)), this, SLOT(CancelClicked(bool))); connect(m_CancelButton, SIGNAL(clicked(bool)), this, SLOT(CancelClicked(bool)));
connect(m_AddClipsButton, SIGNAL(clicked(bool)), this, SLOT(AddClipClicked(bool))); connect(m_AddClipsButton, SIGNAL(clicked(bool)), this, SLOT(AddClipClicked(bool)));
connect(m_RemoveClipsButton, SIGNAL(clicked(bool)), this, SLOT(RemoveClipClicked(bool))); connect(m_RemoveClipsButton, SIGNAL(clicked(bool)), this, SLOT(RemoveClipClicked(bool)));
connect(m_ExportAnimationsButton, SIGNAL(clicked(bool)), this, SLOT(Button1Clicked(bool))); connect(m_ExportSelectedButton, SIGNAL(clicked(bool)), this, SLOT(NULL));
connect(m_CopyTexturesButton, SIGNAL(clicked(bool)), this, SLOT(Button2Clicked(bool))); connect(m_ExportAnimationsButton, SIGNAL(clicked(bool)), this, SLOT(NULL));
connect(m_Button3, SIGNAL(clicked(bool)), this, SLOT(Button3Clicked(bool))); 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 // Creating several layouts, adding widgets & adding them to one layout in the end
QHBoxLayout* topLayout = new QHBoxLayout; QHBoxLayout* topLayout = new QHBoxLayout;
@@ -61,7 +62,8 @@ Menu::Menu(QDialog* dialog)
m_ExportPath = new QLineEdit; m_ExportPath = new QLineEdit;
m_FileDialog = new QFileDialog; m_FileDialog = new QFileDialog;
QString tmpPath("C:/Users/Nickelodion/Desktop/Baljj");
m_ExportPath->setText(tmpPath);
QLabel* exportLabel = new QLabel; QLabel* exportLabel = new QLabel;
exportLabel->setText("Export Path:"); exportLabel->setText("Export Path:");
QLabel* nameLabel = new QLabel; QLabel* nameLabel = new QLabel;
@@ -79,7 +81,6 @@ Menu::Menu(QDialog* dialog)
topLayout->addWidget(m_ExportPath); topLayout->addWidget(m_ExportPath);
topLayout->addWidget(m_BrowseButton); topLayout->addWidget(m_BrowseButton);
botLayout->addWidget(m_ExportSelectedButton);
botLayout->addWidget(m_ExportAllButton); botLayout->addWidget(m_ExportAllButton);
botLayout->addWidget(m_CancelButton); 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) void Menu::ExportPathClicked(bool)
{ {
// Opens up a file dialog. Save/Changes the name in the exportPath // Opens up a file dialog. Save/Changes the name in the exportPath
@@ -188,50 +160,45 @@ void Menu::RemoveClipClicked(bool)
layouts.pop_back(); layouts.pop_back();
m_StartFrameLines.pop_back(); m_StartFrameLines.pop_back();
m_EndFrameLines.pop_back(); m_EndFrameLines.pop_back();
m_AnimationClipName.pop_back();
} }
} }
void Menu::ExportAll(bool) void Menu::ExportAll(bool)
{ {
MDagPath path; if (m_ExportPath->text().isEmpty()) {
m_File.ASCIIFilePath("C:/Users/Nickelodion/Desktop/coolASCII.txt"); MGlobal::displayError(MString() + "Please select a folder.");
m_File.binaryFilePath("C:/Users/Nickelodion/Desktop/coolSoptunz.bin"); return;
m_File.OpenFiles(); }
// Loop through all nodes in the scene //Export meshes
MItDependencyNodes it(MFn::kMesh); if (!m_Export.Meshes(m_ExportPath->text().toLocal8Bit().constData(), m_ExportSelectedButton->isChecked())) {
for (; !it.isDone(); it.next()) { MGlobal::displayError(MString() + "Could not export mesh");
MObject node = it.thisNode(); return;
if (node.hasFn(MFn::kMesh)) { }
MFnDependencyNode thisNode(node);
MPlugArray connections;
thisNode.findPlug("inMesh").connectedTo(connections, true, true); std::vector<Export::AnimationInfo> animations;
bool next = false; MGlobal::displayInfo(MString() + "yeeehaa");
for (unsigned int i = 0; i < connections.length(); i++) { for (unsigned int i = 0; i < m_AnimationClipName.size(); i++) {
if(connections[i].node().apiType() == MFn::kSkinClusterFilter){ Export::AnimationInfo thisClip;
next = true; MGlobal::displayInfo(MString() + "qwqw");
break; thisClip.Name = std::string(m_AnimationClipName[i]->text().toLocal8Bit().constData());
} MGlobal::displayInfo(MString() + "shizzzz");
} thisClip.Start = m_StartFrameLines[i]->text().toInt();
if (next) MGlobal::displayInfo(MString() + "dsdsfg");
continue; thisClip.End = m_EndFrameLines[i]->text().toInt();
MGlobal::displayInfo(MString() + "aaaaaaaaaaaaaaaaaaaa");
cout << thisNode.name().asChar() << endl; animations.push_back(thisClip);
MGlobal::displayInfo("EXPORT ALL FUNCTION: " + thisNode.name() + " " + thisNode.findPlug("inMesh").asMObject().apiTypeStr()); }
GetMeshData(node); MGlobal::displayInfo(MString() + "asdf");
} if (m_ExportAnimationsButton->isChecked()) {
} //Export Animations
if (m_ExportPath->text().isEmpty()) { if (!m_Export.Animations(m_ExportPath->text().toLocal8Bit().constData(), animations)) {
cout << "Please select a folder." << endl; MGlobal::displayError(MString() + "Could not export animations");
} return;
else { }
cout << m_ExportPath->text().toLocal8Bit().constData() << endl; }
}
if (m_ExportAnimationsButton->isChecked())
GetSkeletonData();
m_File.CloseFiles();
} }
void Menu::CancelClicked(bool) void Menu::CancelClicked(bool)
@@ -239,105 +206,6 @@ void Menu::CancelClicked(bool)
m_DialogPointer->close(); 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<VertexLayout> vertexList;
std::vector<unsigned int> 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<MaterialNode>* 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<BindPoseSkeletonNode> allBindPoses;
std::vector<Animation> 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() Menu::~Menu()
{ {
//delete exportSelectedButton; //delete exportSelectedButton;
@@ -346,5 +214,6 @@ Menu::~Menu()
//delete fileDialog; //delete fileDialog;
m_FileDialog->~QFileDialog(); m_FileDialog->~QFileDialog();
//delete m_Export;
//delete MaterialHandler; //delete MaterialHandler;
} }
+3 -20
View File
@@ -32,12 +32,8 @@
#include <QtGui/qlayoutitem.h> #include <QtGui/qlayoutitem.h>
#include <QtGui/qtabwidget.h> #include <QtGui/qtabwidget.h>
#include "MayaIncludes.h" #include "MayaIncludes.h"
#include "Material.h" #include "Export.h"
#include "Mesh.h"
#include "Skeleton.h"
#include "WriteToFile.h"
class Menu : public QWidget class Menu : public QWidget
{ {
@@ -46,23 +42,13 @@ public:
Menu(QDialog* dialog); Menu(QDialog* dialog);
~Menu(); ~Menu();
void GetMeshData(MObject object);
void GetMaterialData();
void GetSkeletonData();
private slots: private slots:
void ExportSelected(bool checked);
void ExportPathClicked(bool); void ExportPathClicked(bool);
void AddClipClicked(bool); void AddClipClicked(bool);
void RemoveClipClicked(bool); void RemoveClipClicked(bool);
void ExportAll(bool); void ExportAll(bool);
void CancelClicked(bool); void CancelClicked(bool);
void Button1Clicked(bool);
void Button2Clicked(bool);
void Button3Clicked(bool);
private: private:
Menu(); Menu();
std::vector<QLineEdit*> m_AnimationClipName; std::vector<QLineEdit*> m_AnimationClipName;
@@ -71,13 +57,13 @@ private:
std::vector<QHBoxLayout*> layouts; std::vector<QHBoxLayout*> layouts;
QVBoxLayout* m_ClipLayout; QVBoxLayout* m_ClipLayout;
QPushButton* m_ExportSelectedButton = nullptr;
QPushButton* m_BrowseButton = nullptr; QPushButton* m_BrowseButton = nullptr;
QPushButton* m_ExportAllButton = nullptr; QPushButton* m_ExportAllButton = nullptr;
QPushButton* m_CancelButton = nullptr; QPushButton* m_CancelButton = nullptr;
QPushButton* m_AddClipsButton = nullptr; QPushButton* m_AddClipsButton = nullptr;
QPushButton* m_RemoveClipsButton = nullptr; QPushButton* m_RemoveClipsButton = nullptr;
QCheckBox* m_ExportSelectedButton = nullptr;
QCheckBox* m_ExportAnimationsButton = nullptr; QCheckBox* m_ExportAnimationsButton = nullptr;
QCheckBox* m_CopyTexturesButton = nullptr; QCheckBox* m_CopyTexturesButton = nullptr;
QCheckBox* m_Button3 = nullptr; QCheckBox* m_Button3 = nullptr;
@@ -86,10 +72,7 @@ private:
QFileDialog* m_FileDialog = nullptr; QFileDialog* m_FileDialog = nullptr;
QDialog* m_DialogPointer = nullptr; QDialog* m_DialogPointer = nullptr;
Material* m_MaterialHandler = nullptr; Export m_Export;
Skeleton* m_SkeletonHandler = nullptr;
WriteToFile m_File;
}; };
#endif #endif
+16 -10
View File
@@ -3,11 +3,12 @@
using namespace std; using namespace std;
Mesh::Mesh() MeshClass::MeshClass()
{ {
} }
std::map<int, Mesh::WeightInfo> Mesh::GetWeightData()
std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
{ {
map<int, WeightInfo> weightMap; map<int, WeightInfo> weightMap;
@@ -72,10 +73,14 @@ std::map<int, Mesh::WeightInfo> Mesh::GetWeightData()
return weightMap; return weightMap;
} }
void Mesh::GetMeshData(MObject object, std::vector<VertexLayout>& vertexList, std::vector<unsigned int>& indexList) Mesh MeshClass::GetMeshData(MObject object)
{ {
Mesh newMesh;
std::vector<VertexLayout>& vertexList = newMesh.Vertices;
std::vector<int>& indexList = newMesh.Indices;
// In here, we retrieve triangulated polygons from the mesh // In here, we retrieve triangulated polygons from the mesh
MFnMesh mesh(object); MFnMesh mesh(object);
map<unsigned int, vector<unsigned int>> vertexToIndex;; map<unsigned int, vector<unsigned int>> vertexToIndex;;
MIntArray intdexOffsetVertexCount, vertices, triangleList; MIntArray intdexOffsetVertexCount, vertices, triangleList;
@@ -106,7 +111,7 @@ void Mesh::GetMeshData(MObject object, std::vector<VertexLayout>& vertexList, st
meshPolyIter.getVertices(vertices); meshPolyIter.getVertices(vertices);
meshPolyIter.getTriangles(dummy, triangleList); meshPolyIter.getTriangles(dummy, triangleList);
MGlobal::displayInfo(MString() + "vertices.length(): " + vertices.length());
//MGlobal::displayInfo("Befor Second Loop"); //MGlobal::displayInfo("Befor Second Loop");
for (unsigned int i = 0; i < vertices.length(); i++) { for (unsigned int i = 0; i < vertices.length(); i++) {
vertexIndex = meshPolyIter.vertexIndex(i); vertexIndex = meshPolyIter.vertexIndex(i);
@@ -160,25 +165,26 @@ void Mesh::GetMeshData(MObject object, std::vector<VertexLayout>& vertexList, st
//cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[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 << "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++) { for (unsigned int i = 0; i < triangleList.length(); i++) {
unsigned int k = 0; unsigned int k = 0;
MGlobal::displayInfo(MString() + "triangleList[i]: " + triangleList[i]);
if (localVertexToGlobalIndex.size() > 0) { if (localVertexToGlobalIndex.size() > 0) {
while (localVertexToGlobalIndex[k] != triangleList[i] && k < localVertexToGlobalIndex.size()) { while (localVertexToGlobalIndex[k] != triangleList[i] && k < localVertexToGlobalIndex.size()) {
MGlobal::displayInfo(MString() + "localVertexToGlobalIndex[k]: " + localVertexToGlobalIndex[k]);
k++; k++;
} }
indexList.push_back(indexOffset + k); indexList.push_back(indexOffset + k);
} }
} }
} }
newMesh.NumIndices = newMesh.Indices.size();
newMesh.NumVertices = newMesh.Vertices.size();
return newMesh;
} }
Mesh::~Mesh() MeshClass::~MeshClass()
{ {
} }
+39 -6
View File
@@ -10,7 +10,6 @@
class VertexLayout : public OutputData class VertexLayout : public OutputData
{ {
public: public:
float Pos[3]; float Pos[3];
float Normal[3]; float Normal[3];
float BiNormal[3]; float BiNormal[3];
@@ -32,7 +31,6 @@ public:
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 << Pos[0] << " " << Pos[1] << " " << Pos[2] << endl;
out << Normal[0] << " " << Normal[1] << " " << Normal[2] << endl; out << Normal[0] << " " << Normal[1] << " " << Normal[2] << endl;
out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[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<VertexLayout> Vertices;
std::vector<int> 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: public:
Mesh(); MeshClass();
void GetMeshData(MObject Object, std::vector<VertexLayout>& vertexList, std::vector<unsigned int>& indexList); Mesh GetMeshData(MObject Object);
~Mesh(); ~MeshClass();
private: private:
struct WeightInfo { struct WeightInfo {
float BoneIndices[4] = { 0 }; float BoneIndices[4] = { 0 };
+8 -3
View File
@@ -64,12 +64,13 @@ std::string attr[9] = { "scaleX", "scaleY", "scaleZ", "translateX", "translateY"
Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame) Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame)
{ {
std::vector<MObject> animatedJoints;
std::vector<MObject> m_Hierarchy;
Animation returnData; Animation returnData;
double oneDivSixty = 1 / 60.0; double oneDivSixty = 1 / 60.0;
returnData.Name = animationName; returnData.Name = animationName;
returnData.Duration = (endFrame - startFrame) * oneDivSixty; returnData.Duration = (endFrame - startFrame) * oneDivSixty;
std::vector<MObject> animatedJoints;
std::vector<MObject> m_Hierarchy;
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint); MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
while (!jointIt.isDone()) while (!jointIt.isDone())
@@ -121,7 +122,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
if (BindPoseMatrix != MayaJoint.transformationMatrix()) 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); returnData.Keyframes.push_back(thisKeyFrame);
currentFrame++; currentFrame++;
} }
returnData.NumKeyFrames = returnData.Keyframes.size();
returnData.NumberOfJoints = animatedJoints.size();
return returnData; return returnData;
} }
@@ -26,12 +26,16 @@ public:
std::string Name; std::string Name;
double Duration; double Duration;
int NumKeyFrames;
int NumberOfJoints;
std::vector<Keyframe> Keyframes; std::vector<Keyframe> Keyframes;
virtual void WriteBinary(std::ostream& out) virtual void WriteBinary(std::ostream& out)
{ {
out.write(Name.c_str(), Name.size() + 1); out.write(Name.c_str(), Name.size() + 1);
out.write((char*)&Duration, sizeof(double)); out.write((char*)&Duration, sizeof(double));
out.write((char*)&NumKeyFrames, sizeof(int));
out.write((char*)&NumberOfJoints, sizeof(int));
for (auto aKeyframe : Keyframes) { for (auto aKeyframe : Keyframes) {
out.write((char*)&aKeyframe.Index, sizeof(int)); out.write((char*)&aKeyframe.Index, sizeof(int));
out.write((char*)&aKeyframe.Time, sizeof(double)); out.write((char*)&aKeyframe.Time, sizeof(double));
@@ -48,6 +52,8 @@ public:
{ {
out << "Animation Name: " << Name << endl; out << "Animation Name: " << Name << endl;
out << "Duration: " << Duration << endl; out << "Duration: " << Duration << endl;
out << "Number of KeyFrames: " << NumKeyFrames << endl;
out << "Number of Joints: " << NumberOfJoints << endl;
for (auto aKeyframe : Keyframes) { for (auto aKeyframe : Keyframes) {
out << "Frame: " << aKeyframe.Index << endl; out << "Frame: " << aKeyframe.Index << endl;
out << "Time: " << aKeyframe.Time << endl; out << "Time: " << aKeyframe.Time << endl;
@@ -17,7 +17,7 @@ public:
void writeToFiles(OutputData* toWrite, unsigned int numOfElementToWrite = 1, unsigned int startIndex = 0) 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()) if (ASCIIFile.is_open())
{ {
for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++) 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 <typename T>
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()) { if (ASCIIFile.is_open()) {
for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++) for (unsigned int i = startIndex; i < numOfElementToWrite + startIndex; i++)
ASCIIFile << toWrite[i] << endl; ASCIIFile << toWrite[i] << endl;
} }
if (binFile.is_open()) { 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));
} }
} }