Spitting out files WIP

This commit is contained in:
antc13
2015-12-18 16:21:07 +01:00
parent 509a989d3b
commit c9db46564f
12 changed files with 257 additions and 20 deletions
@@ -175,6 +175,7 @@
<ClCompile Include="Main.cpp" />
<ClCompile Include="Mesh.cpp" />
<ClCompile Include="Skeleton.cpp" />
<ClCompile Include="WriteToFile.cpp" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="MayaExporter.ui">
@@ -198,7 +199,9 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="Mesh.h" />
<ClInclude Include="OutputData.h" />
<ClInclude Include="Skeleton.h" />
<ClInclude Include="WriteToFile.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>
@@ -59,6 +59,9 @@
<ClCompile Include="Skeleton.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="WriteToFile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="leeeeel.qrc">
@@ -87,5 +90,11 @@
<ClInclude Include="Skeleton.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="WriteToFile.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OutputData.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
@@ -36,6 +36,7 @@
#include <maya/MDataHandle.h>
#include <maya/MTransformationMatrix.h>
#include <maya/MFnMatrixData.h>
#include <maya/MItMeshFaceVertex.h>
// Wrappers
+11 -1
View File
@@ -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()
+3
View File
@@ -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
+39 -13
View File
@@ -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<UINT> 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);
//}
}
}
+13 -1
View File
@@ -4,13 +4,25 @@
#include <map>
#include <vector>
#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
@@ -0,0 +1,23 @@
#ifndef OutputData_OutputData_h__
#define OutputData_OutputData_h__
#include <fstream>
//template <typename T>
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
@@ -1,5 +1,8 @@
#include "Skeleton.h"
std::vector<SkeletonNode> Skeleton::DoIt()
{
std::vector<SkeletonNode> m_AllSkeletons;
+65 -5
View File
@@ -5,23 +5,83 @@
#include <array>
#include <algorithm>
#include "MayaIncludes.h"
struct Joint {
#include "OutputData.h"
class Joint : public OutputData{
public:
//Joint() : OutputData((Joint)*this)
//{};
//int ParentIndex;
//std::array<float, 3> Rotation;
//std::array<float, 3> Translation;
//std::array<float, 3> Scale;
std::array<std::array<float, 4>, 4> OffsetMatrix;
//std::array<std::array<float, 4>, 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<Joint> 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<int> ParentIDs;
std::vector<std::string> 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 {
@@ -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();
}
@@ -0,0 +1,49 @@
#ifndef WriteToFile_WriteToFile_h__
#define WriteToFile_WriteToFile_h__
#include "MayaIncludes.h"
#include "OutputData.h"
#include <fstream>
#include <string>
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