WIP, commit to be able to pull stuff down

This commit is contained in:
Teejoon
2016-02-04 14:58:46 +01:00
parent da49dc35ee
commit 336b058c9f
8 changed files with 188 additions and 89 deletions
+1 -1
View File
@@ -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;
+15 -4
View File
@@ -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<MaterialGroup> MaterialGroups;
bool isSkined;
std::vector<unsigned int> m_Indices;
Skeleton* m_Skeleton = nullptr;
glm::mat4 m_Matrix;
private:
bool hasSkin;
std::vector<Vertex> m_Vertices;
std::vector<SkinedVertex> m_SkinedVertices;
+4 -8
View File
@@ -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<int> 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);
}
+3 -3
View File
@@ -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");
}
+47 -9
View File
@@ -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<MaterialNode::Texture>& textureVector, MFnDependencyNode& node) {
return false;
}
// Returns the absolute path for all textures. Use for copying texture files.
std::vector<std::string>* Material::TexturePaths()
{
+88 -36
View File
@@ -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<Texture> ColorMaps;
std::vector<Texture> SpecularMaps;
std::vector<Texture> NormalMaps;
std::vector<Texture> 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<MaterialNode::Texture>& textureVector, MFnDependencyNode& node);
void grabLambertProperties(MaterialNode& material_node, MFnDependencyNode& node);
void grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node);
void grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node);
@@ -40,8 +40,9 @@
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -77,6 +78,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<TargetExt>.mll</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@@ -135,7 +137,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;QT_DLL;QT_NO_DEBUG;QT_NO_IMPORT_QT47_QML;UNICODE;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\Program Files\Autodesk\Maya2016\include;.\GeneratedFiles;.\GeneratedFiles\$(ConfigurationName);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>
</DebugInformationFormat>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@@ -144,7 +146,7 @@
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<AdditionalLibraryDirectories>$(QTDIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>qtmain.lib;%(AdditionalDependencies)</AdditionalDependencies>
+25 -25
View File
@@ -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);