From 336b058c9f517aab0ce8672869f011e2f87db4f9 Mon Sep 17 00:00:00 2001 From: Teejoon Date: Thu, 4 Feb 2016 14:58:46 +0100 Subject: [PATCH] WIP, commit to be able to pull stuff down --- include/Engine/Rendering/Model.h | 2 +- include/Engine/Rendering/RawModelCustom.h | 19 ++- src/Engine/Rendering/Model.cpp | 12 +- src/Engine/Rendering/RawModelCustom.cpp | 6 +- tools/MayaExporter/MayaExporter/Material.cpp | 56 ++++++-- tools/MayaExporter/MayaExporter/Material.h | 124 +++++++++++++----- .../MayaExporter/MayaExporter.vcxproj | 8 +- tools/MayaExporter/MayaExporter/Skeleton.cpp | 50 +++---- 8 files changed, 188 insertions(+), 89 deletions(-) diff --git a/include/Engine/Rendering/Model.h b/include/Engine/Rendering/Model.h index aeb13e2f..34d8462f 100644 --- a/include/Engine/Rendering/Model.h +++ b/include/Engine/Rendering/Model.h @@ -18,7 +18,7 @@ public: const glm::mat4& Matrix() const { return m_RawModel->m_Matrix; } const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); } unsigned int NumberOfVertices() const { return m_RawModel->NumVertices(); } - bool isSkined() const { return m_RawModel->isSkined; } + bool isSkined() const { return m_RawModel->isSkined(); } GLuint VAO; GLuint ElementBuffer; RawModel* m_RawModel; diff --git a/include/Engine/Rendering/RawModelCustom.h b/include/Engine/Rendering/RawModelCustom.h index fe00d89c..2b0172dd 100644 --- a/include/Engine/Rendering/RawModelCustom.h +++ b/include/Engine/Rendering/RawModelCustom.h @@ -68,30 +68,41 @@ public: }; const Vertex* Vertices() const { - if (isSkined) { + if (hasSkin) { return m_SkinedVertices.data(); } else { return m_Vertices.data(); } }; + unsigned int VertexSize() const { + if (hasSkin) { + return sizeof(SkinedVertex); + } + else { + return sizeof(Vertex); + } + }; + unsigned int NumVertices() const { - if (isSkined) { + if (hasSkin) { return m_SkinedVertices.size(); } else { return m_Vertices.size(); } }; + bool isSkined() const { return hasSkin; }; + std::vector MaterialGroups; - bool isSkined; + std::vector m_Indices; Skeleton* m_Skeleton = nullptr; glm::mat4 m_Matrix; private: - + bool hasSkin; std::vector m_Vertices; std::vector m_SkinedVertices; diff --git a/src/Engine/Rendering/Model.cpp b/src/Engine/Rendering/Model.cpp index 129b77fa..bf264b5a 100644 --- a/src/Engine/Rendering/Model.cpp +++ b/src/Engine/Rendering/Model.cpp @@ -25,11 +25,7 @@ Model::Model(std::string fileName) glGenBuffers(1, &buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer); - if (m_RawModel->isSkined) { - glBufferData(GL_ARRAY_BUFFER, m_RawModel->NumVertices() * sizeof(RawModel::SkinedVertex), m_RawModel->Vertices(), GL_STATIC_DRAW); - } else { - glBufferData(GL_ARRAY_BUFFER, m_RawModel->NumVertices() * sizeof(RawModel::Vertex), m_RawModel->Vertices(), GL_STATIC_DRAW); - } + glBufferData(GL_ARRAY_BUFFER, m_RawModel->NumVertices() * m_RawModel->VertexSize(), m_RawModel->Vertices(), GL_STATIC_DRAW); glGenBuffers(1, &ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer); @@ -41,7 +37,7 @@ Model::Model(std::string fileName) glBindBuffer(GL_ARRAY_BUFFER, buffer); std::vector structSizes; - if (m_RawModel->isSkined) { + if (m_RawModel->isSkined()) { structSizes = { 3, 3, 3, 3, 2, 4, 4 }; } else { structSizes = { 3, 3, 3, 3, 2 }; @@ -60,7 +56,7 @@ Model::Model(std::string fileName) glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; - if (m_RawModel->isSkined) { + if (m_RawModel->isSkined()) { glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; } @@ -72,7 +68,7 @@ Model::Model(std::string fileName) glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); glEnableVertexAttribArray(4); - if (m_RawModel->isSkined) { + if (m_RawModel->isSkined()) { glEnableVertexAttribArray(5); glEnableVertexAttribArray(6); } diff --git a/src/Engine/Rendering/RawModelCustom.cpp b/src/Engine/Rendering/RawModelCustom.cpp index c1939bdf..e22b69d1 100644 --- a/src/Engine/Rendering/RawModelCustom.cpp +++ b/src/Engine/Rendering/RawModelCustom.cpp @@ -40,9 +40,9 @@ void RawModelCustom::ReadMeshFile(std::string filePath) void RawModelCustom::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN - isSkined = *(unsigned int*)(fileData + offset); + hasSkin = *(bool*)(fileData + offset); offset += sizeof(bool); - if (isSkined) { + if (hasSkin) { m_SkinedVertices.resize(*(unsigned int*)(fileData + offset)); } else { @@ -64,7 +64,7 @@ void RawModelCustom::ReadMesh(unsigned int& offset, char* fileData, unsigned int void RawModelCustom::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize) { #ifdef BOOST_LITTLE_ENDIAN - if (isSkined) { + if (hasSkin) { if (offset + m_SkinedVertices.size() * sizeof(SkinedVertex) > fileByteSize) { throw Resource::FailedLoadingException("Reading skined vertices failed"); } diff --git a/tools/MayaExporter/MayaExporter/Material.cpp b/tools/MayaExporter/MayaExporter/Material.cpp index 0ec752f7..e487d87f 100644 --- a/tools/MayaExporter/MayaExporter/Material.cpp +++ b/tools/MayaExporter/MayaExporter/Material.cpp @@ -82,9 +82,16 @@ bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode& workspace); FullPath = FullPath.substr(workspace.length()); FullPath = FullPath.substr(FullPath.find_first_of("/") + 1); - material_node.ColorMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); - material_node.ColorMapFileLength = material_node.ColorMapFile.length() + 1; + MaterialNode::Texture newTexture; + + newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); + newTexture.FileNameLength = newTexture.FileName.length() + 1; + + newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat(); + newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat(); + + material_node.ColorMaps.push_back(newTexture); return true; } } @@ -117,8 +124,16 @@ bool Material::findNormalTexture(MaterialNode& material_node, MFnDependencyNode& workspace); FullPath = FullPath.substr(workspace.length()); FullPath = FullPath.substr(FullPath.find_first_of("/") + 1); - material_node.NormalMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); - material_node.NormalMapFileLength = material_node.NormalMapFile.length() + 1; + + MaterialNode::Texture newTexture; + + newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); + newTexture.FileNameLength = newTexture.FileName.length() + 1; + + newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat(); + newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat(); + + material_node.NormalMaps.push_back(newTexture); return true; } } @@ -147,8 +162,16 @@ bool Material::findSpecularTexture(MaterialNode& material_node, MFnDependencyNod workspace); FullPath = FullPath.substr(workspace.length()); FullPath = FullPath.substr(FullPath.find_first_of("/") + 1); - material_node.SpecularMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); - material_node.SpecularMapFileLength = material_node.SpecularMapFile.length() + 1; + + MaterialNode::Texture newTexture; + + newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); + newTexture.FileNameLength = newTexture.FileName.length() + 1; + + newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat(); + newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat(); + + material_node.SpecularMaps.push_back(newTexture); return true; } } @@ -165,7 +188,7 @@ bool Material::findIncandescenceTexture(MaterialNode& material_node, MFnDependen for (int i = 0; i < AllConnections.length(); i++) { if (AllConnections[i].node().hasFn(MFn::kFileTexture)) { MFnDependencyNode TextureNode(AllConnections[i].node()); - + std::string FullPath = TextureNode.findPlug("ftn").asString().asChar(); m_TexturePaths.push_back(FullPath); @@ -174,14 +197,29 @@ bool Material::findIncandescenceTexture(MaterialNode& material_node, MFnDependen workspace); FullPath = FullPath.substr(workspace.length()); FullPath = FullPath.substr(FullPath.find_first_of("/") + 1); - material_node.IncandescenceMapFile = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); - material_node.IncandescenceMapFileLength = material_node.IncandescenceMapFile.length() + 1; + + MaterialNode::Texture newTexture; + + newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size()); + newTexture.FileNameLength = newTexture.FileName.length() + 1; + + newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat(); + newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat(); + + material_node.IncandescenceMaps.push_back(newTexture); return true; + + } else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) { + return findSplatTextures(material_node.IncandescenceMaps, MFnDependencyNode(AllConnections[i].node())); } } return false; } +bool Material::findSplatTextures(std::vector& textureVector, MFnDependencyNode& node) { + return false; +} + // Returns the absolute path for all textures. Use for copying texture files. std::vector* Material::TexturePaths() { diff --git a/tools/MayaExporter/MayaExporter/Material.h b/tools/MayaExporter/MayaExporter/Material.h index e405dd07..844b3876 100644 --- a/tools/MayaExporter/MayaExporter/Material.h +++ b/tools/MayaExporter/MayaExporter/Material.h @@ -11,51 +11,87 @@ #include "OutputData.h" #include "Mesh.h" + +//#define ColorMapSplat 1 +//#define SpecularMapSplat 1 << 1 +//#define NormalMapSplat 1 << 2 +//#define IncandescenceMapSplat 1 << 3 + class MaterialNode : public OutputData { public: + class Texture : public OutputData { + public: + unsigned int FileNameLength = 0; + std::string FileName; + float UVTiling[2]{ 1.0f, 1.0f }; + + virtual void WriteBinary(std::ostream& out) + { + out.write((char*)&FileNameLength, sizeof(unsigned int)); + out.write(FileName.c_str(), FileNameLength); + out.write((char*)&UVTiling, sizeof(float) * 2); + } + + virtual void WriteASCII(std::ostream& out) const + { + out << "FileNameLength: " << FileNameLength << endl; + out << "FileName: " << FileName << endl; + out << "UV tiling: " << UVTiling[0] << " " << UVTiling[1] << endl; + } + }; + std::string Name; float ReflectionFactor; float SpecularExponent; - float DiffuseColor[3]{ 1.0f, 1.0f, 1.0f }; - unsigned int ColorMapFileLength = 0; - std::string ColorMapFile; + float DiffuseColor[3]{ 1.0f, 1.0f, 1.0f }; + float SpecularColor[3]{ 1.0f, 1.0f, 1.0f }; + float IncandescenceColor[3]{ 1.0f, 1.0f, 1.0f }; - float SpecularColor[3]{ 1.0f, 1.0f, 1.0f }; - unsigned int SpecularMapFileLength = 0; - std::string SpecularMapFile; + unsigned int IndexStart; + unsigned int IndexEnd; - unsigned int NormalMapFileLength = 0; - std::string NormalMapFile; + char NumColormaps = 0; + char NumSpecularMap = 0; + char NumNormalMap = 0; + char NumIncandescenceMap = 0; - float IncandescenceColor[3]{ 1.0f, 1.0f, 1.0f }; - unsigned int IncandescenceMapFileLength = 0; - std::string IncandescenceMapFile; - - unsigned int IndexStart; - unsigned int IndexEnd; + std::vector ColorMaps; + std::vector SpecularMaps; + std::vector NormalMaps; + std::vector IncandescenceMaps; virtual void WriteBinary(std::ostream& out) { - out.write((char*)&ColorMapFileLength, sizeof(unsigned int)); - out.write((char*)&NormalMapFileLength, sizeof(unsigned int)); - out.write((char*)&SpecularMapFileLength, sizeof(unsigned int)); - out.write((char*)&IncandescenceMapFileLength, sizeof(unsigned int)); - out.write((char*)&SpecularExponent, sizeof(float)); out.write((char*)&ReflectionFactor, sizeof(float)); + out.write((char*)&DiffuseColor, sizeof(float) * 3); out.write((char*)&SpecularColor, sizeof(float) * 3); out.write((char*)&IncandescenceColor, sizeof(float) * 3); + out.write((char*)&IndexStart, sizeof(unsigned int)); out.write((char*)&IndexEnd, sizeof(unsigned int)); - out.write(ColorMapFile.c_str(), ColorMapFileLength); - out.write(NormalMapFile.c_str(), NormalMapFileLength); - out.write(SpecularMapFile.c_str(), SpecularMapFileLength); - out.write(IncandescenceMapFile.c_str(), IncandescenceMapFileLength); + out.write((char*)&NumColormaps, sizeof(char)); + out.write((char*)&NumSpecularMap, sizeof(char)); + out.write((char*)&NumNormalMap, sizeof(char)); + out.write((char*)&NumIncandescenceMap, sizeof(char)); + + for(auto aTexture : ColorMaps) { + aTexture.WriteBinary(out); + } + for (auto aTexture : SpecularMaps) { + aTexture.WriteBinary(out); + } + for (auto aTexture : NormalMaps) { + aTexture.WriteBinary(out); + } + for (auto aTexture : IncandescenceMaps) { + aTexture.WriteBinary(out); + } } virtual void WriteASCII(std::ostream& out) const @@ -63,11 +99,6 @@ public: out << "New Material _ not in binary" << endl; out << "number of indices: " << Name << " _ not in binary" << endl; - out << "ColorMapFile length: " << ColorMapFileLength << endl; - out << "NormalMapFile length: " << NormalMapFileLength << endl; - out << "SpecularMapFile length: " << SpecularMapFileLength << endl; - out << "IncandescenceMapFile length: " << IncandescenceMapFileLength << endl; - out << "SpecularExponent: " << SpecularExponent << endl; out << "ReflectionFactor: " << ReflectionFactor << endl; out << "DiffuseColor: " << DiffuseColor[0] << " " << DiffuseColor[1] << " " << DiffuseColor[2] << endl; @@ -76,17 +107,37 @@ public: out << "IndexStart: " << IndexStart << endl; out << "IndexEnd: " << IndexEnd << endl; - if (ColorMapFileLength > 0) - out << "ColorMapFile: " << ColorMapFile << endl; + if (NumColormaps > 0) + out << "NumColormaps: " << NumColormaps << endl; - if (NormalMapFileLength > 0) - out << "NormalMapFile: " << NormalMapFile << endl; + if (NumSpecularMap > 0) + out << "NumSpecularMap: " << NumSpecularMap << endl; - if (SpecularMapFileLength > 0) - out << "SpecularMapFile: " << SpecularMapFile << endl; + if (NumNormalMap > 0) + out << "NumNormalMap: " << NumNormalMap << endl; - if (IncandescenceMapFileLength > 0) - out << "IncandescenceMapFile: " << IncandescenceMapFile << endl; + if (NumIncandescenceMap > 0) + out << "NumIncandescenceMap: " << NumIncandescenceMap << endl; + + out << "ColorMaps _ not in binary " << endl; + for (auto aTexture : ColorMaps) { + aTexture.WriteASCII(out); + } + + out << "SpecularMaps _ not in binary " << endl; + for (auto aTexture : SpecularMaps) { + aTexture.WriteASCII(out); + } + + out << "NormalMaps _ not in binary " << endl; + for (auto aTexture : NormalMaps) { + aTexture.WriteASCII(out); + } + + out << "IncandescenceMaps _ not in binary " << endl; + for (auto aTexture : IncandescenceMaps) { + aTexture.WriteASCII(out); + } } }; @@ -107,6 +158,7 @@ private: bool findNormalTexture(MaterialNode& material_node, MFnDependencyNode& node); bool findSpecularTexture(MaterialNode& material_node, MFnDependencyNode& node); bool findIncandescenceTexture(MaterialNode& material_node, MFnDependencyNode& node); + bool findSplatTextures(std::vector& textureVector, MFnDependencyNode& node); void grabLambertProperties(MaterialNode& material_node, MFnDependencyNode& node); void grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node); void grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node); diff --git a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj index 4a7ac07e..b9384a45 100644 --- a/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj +++ b/tools/MayaExporter/MayaExporter/MayaExporter.vcxproj @@ -40,8 +40,9 @@ v140 - Application + DynamicLibrary v140 + Unicode @@ -77,6 +78,7 @@ $(SolutionDir)$(Platform)\$(Configuration)\ + .mll @@ -135,7 +137,7 @@ NDEBUG;QT_DLL;QT_NO_DEBUG;QT_NO_IMPORT_QT47_QML;UNICODE;WIN32;%(PreprocessorDefinitions) - .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);%(AdditionalIncludeDirectories) + C:\Program Files\Autodesk\Maya2016\include;.\GeneratedFiles;.\GeneratedFiles\$(ConfigurationName);%(AdditionalIncludeDirectories) MultiThreadedDLL @@ -144,7 +146,7 @@ Windows - $(OutDir)\$(ProjectName).exe + $(OutDir)$(TargetName)$(TargetExt) $(QTDIR)\lib;%(AdditionalLibraryDirectories) false qtmain.lib;%(AdditionalDependencies) diff --git a/tools/MayaExporter/MayaExporter/Skeleton.cpp b/tools/MayaExporter/MayaExporter/Skeleton.cpp index f44b9306..5553dcdd 100644 --- a/tools/MayaExporter/MayaExporter/Skeleton.cpp +++ b/tools/MayaExporter/MayaExporter/Skeleton.cpp @@ -228,8 +228,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e unsigned int jointID = 0; while (!jointIt.isDone()) { MFnTransform thisJoint(jointIt.currentItem()); - MMatrix transformationMatrix = thisJoint.transformationMatrix(); - + MTransformationMatrix TransformationMatrix = thisJoint.transformationMatrix(); double doubleMat[4][4]; if (currentFrame != startFrame){ @@ -263,6 +262,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e transformationMatrix.get(doubleMat); + //Save transformationMatrix to joinCheckMap joinCheckMap[thisJoint.name().asChar()][0][0] = doubleMat[0][0]; joinCheckMap[thisJoint.name().asChar()][0][1] = doubleMat[0][1]; joinCheckMap[thisJoint.name().asChar()][0][2] = doubleMat[0][2]; @@ -280,32 +280,32 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e joinCheckMap[thisJoint.name().asChar()][3][2] = doubleMat[3][2]; joinCheckMap[thisJoint.name().asChar()][3][3] = doubleMat[3][3]; - MPlug thisJointBindPose = thisJoint.findPlug("bindPose"); - MDataHandle DataHandle; - thisJointBindPose.getValue(DataHandle); - MFnMatrixData MartixFn(DataHandle.data()); - MMatrix thisJointBindPoseMatrix = MartixFn.matrix(); + if (currentFrame == startFrame) { + MPlug thisJointBindPose = thisJoint.findPlug("bindPose"); + MDataHandle DataHandle; + thisJointBindPose.getValue(DataHandle); + MFnMatrixData MartixFn(DataHandle.data()); + MMatrix thisJointBindPoseMatrix = MartixFn.matrix(); - MFnTransform Parent(thisJoint.parent(0), &status); - if (status == MS::kSuccess && thisJoint.parent(0).apiType() == MFn::kJoint) { - MTransformationMatrix Matrix = Parent.transformation(); - MPlug parentBindPose = Parent.findPlug("bindPose"); - MDataHandle DataHandle; - parentBindPose.getValue(DataHandle); - MFnMatrixData MartixFn(DataHandle.data()); - MMatrix parentBindPoseMatrix = MartixFn.matrix(); + MFnTransform Parent(thisJoint.parent(0), &status); + if (status == MS::kSuccess && thisJoint.parent(0).apiType() == MFn::kJoint) { + MTransformationMatrix Matrix = Parent.transformation(); + MPlug parentBindPose = Parent.findPlug("bindPose"); + MDataHandle DataHandle; + parentBindPose.getValue(DataHandle); + MFnMatrixData MartixFn(DataHandle.data()); + MMatrix parentBindPoseMatrix = MartixFn.matrix(); - thisJointBindPoseMatrix = thisJointBindPoseMatrix * parentBindPoseMatrix.inverse(); - } + thisJointBindPoseMatrix = thisJointBindPoseMatrix * parentBindPoseMatrix.inverse(); + } - MTransformationMatrix TransformationMatrix = thisJoint.transformation(); - - if (thisJointBindPoseMatrix.isEquivalent(TransformationMatrix.asMatrix())) { - jointID++; - jointIt.next(); - MGlobal::displayError(MString() + thisJoint.name() + " is in bindPose"); - continue; - } + if (thisJointBindPoseMatrix.isEquivalent(TransformationMatrix.asMatrix())) { + jointID++; + jointIt.next(); + MGlobal::displayError(MString() + thisJoint.name() + " is in bindPose"); + continue; + } + } MObject jointOrientObj = thisJoint.attribute("jointOrient"); MFnNumericAttribute jointOrient(jointOrientObj);