From c9db46564f1394978bf75e88d5b18bce0e0d3908 Mon Sep 17 00:00:00 2001 From: antc13 Date: Fri, 18 Dec 2015 16:21:07 +0100 Subject: [PATCH] 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