Merge remote-tracking branch 'origin/Importer' into Animations
# Conflicts: # include/Engine/Rendering/Skeleton.h # src/Engine/Rendering/RawModelCustom.cpp # src/Engine/Rendering/Skeleton.cpp
This commit is contained in:
@@ -12,3 +12,6 @@ tools/MayaExporter/x64/Debug/
|
|||||||
|
|
||||||
tools/MayaExporter/MayaExporter/Debug/
|
tools/MayaExporter/MayaExporter/Debug/
|
||||||
tools/MayaExporter/MayaExporter/GeneratedFiles/
|
tools/MayaExporter/MayaExporter/GeneratedFiles/
|
||||||
|
|
||||||
|
tools/MayaExporter/MayaExporter/x64/*
|
||||||
|
tools/MayaExporter/x64/*
|
||||||
|
|||||||
+1
-1
Submodule assets updated: 9b2fa74a6d...c4898d8281
@@ -16,8 +16,9 @@ public:
|
|||||||
~Model();
|
~Model();
|
||||||
const std::vector<RawModel::MaterialGroup>& MaterialGroups() const { return m_RawModel->MaterialGroups; }
|
const std::vector<RawModel::MaterialGroup>& MaterialGroups() const { return m_RawModel->MaterialGroups; }
|
||||||
const glm::mat4& Matrix() const { return m_RawModel->m_Matrix; }
|
const glm::mat4& Matrix() const { return m_RawModel->m_Matrix; }
|
||||||
const std::vector<RawModel::Vertex>& Vertices() const { return m_RawModel->m_Vertices; }
|
const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); }
|
||||||
|
unsigned int NumberOfVertices() const { return m_RawModel->NumVertices(); }
|
||||||
|
bool isSkined() const { return m_RawModel->isSkined; }
|
||||||
GLuint VAO;
|
GLuint VAO;
|
||||||
GLuint ElementBuffer;
|
GLuint ElementBuffer;
|
||||||
RawModel* m_RawModel;
|
RawModel* m_RawModel;
|
||||||
|
|||||||
@@ -33,13 +33,16 @@ protected:
|
|||||||
public:
|
public:
|
||||||
~RawModelCustom();
|
~RawModelCustom();
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
glm::vec3 Position;
|
glm::vec3 Position;
|
||||||
glm::vec3 Normal;
|
glm::vec3 Normal;
|
||||||
glm::vec3 Tangent;
|
glm::vec3 Tangent;
|
||||||
glm::vec3 BiNormal;
|
glm::vec3 BiNormal;
|
||||||
glm::vec2 TextureCoords;
|
glm::vec2 TextureCoords;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SkinedVertex : public Vertex {
|
||||||
glm::vec4 BoneIndices;
|
glm::vec4 BoneIndices;
|
||||||
glm::vec4 BoneWeights;
|
glm::vec4 BoneWeights;
|
||||||
};
|
};
|
||||||
@@ -64,15 +67,33 @@ public:
|
|||||||
std::shared_ptr<::Texture> IncandescenceMap;
|
std::shared_ptr<::Texture> IncandescenceMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<MaterialGroup> MaterialGroups;
|
const Vertex* Vertices() const {
|
||||||
|
if (isSkined) {
|
||||||
|
return m_SkinedVertices.data();
|
||||||
|
} else {
|
||||||
|
return m_Vertices.data();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned int NumVertices() const {
|
||||||
|
if (isSkined) {
|
||||||
|
return m_SkinedVertices.size();
|
||||||
|
} else {
|
||||||
|
return m_Vertices.size();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<MaterialGroup> MaterialGroups;
|
||||||
|
bool isSkined;
|
||||||
|
|
||||||
std::vector<Vertex> m_Vertices;
|
|
||||||
std::vector<unsigned int> m_Indices;
|
std::vector<unsigned int> m_Indices;
|
||||||
Skeleton* m_Skeleton = nullptr;
|
Skeleton* m_Skeleton = nullptr;
|
||||||
glm::mat4 m_Matrix;
|
glm::mat4 m_Matrix;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
std::vector<Vertex> m_Vertices;
|
||||||
|
std::vector<SkinedVertex> m_SkinedVertices;
|
||||||
|
|
||||||
void ReadMeshFile(std::string filePath);
|
void ReadMeshFile(std::string filePath);
|
||||||
void ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
|
void ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize);
|
||||||
@@ -89,7 +110,7 @@ private:
|
|||||||
void ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize);
|
void ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize);
|
||||||
void ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips);
|
void ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips);
|
||||||
void ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex);
|
void ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex);
|
||||||
void ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, Skeleton::Animation& animation);
|
void ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, std::vector<Skeleton::Animation::Keyframe>& animation);
|
||||||
|
|
||||||
//void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
|
//void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,23 +54,21 @@ public:
|
|||||||
{
|
{
|
||||||
struct BoneProperty
|
struct BoneProperty
|
||||||
{
|
{
|
||||||
int ID;
|
|
||||||
glm::vec3 Position;
|
glm::vec3 Position;
|
||||||
glm::quat Rotation;
|
glm::quat Rotation;
|
||||||
glm::vec3 Scale = glm::vec3(1);
|
glm::vec3 Scale = glm::vec3(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
int Index = 0;
|
int Index = 0;
|
||||||
double Time = 0.0;
|
double Time = 0.0;
|
||||||
std::map<int, Keyframe::BoneProperty> BoneProperties;
|
BoneProperty BoneProperties;
|
||||||
//Keyframe::BoneProperty boneProperty;
|
//Keyframe::BoneProperty boneProperty;
|
||||||
};
|
};
|
||||||
|
std::string Name;
|
||||||
|
double Duration;
|
||||||
|
std::map<int, std::vector<Keyframe>> JointAnimations;
|
||||||
|
|
||||||
|
|
||||||
std::string Name;
|
|
||||||
double Duration;
|
|
||||||
// unsigned int KeyFrameAmount;
|
|
||||||
std::vector<Keyframe> Keyframes;
|
|
||||||
//std::map<int, std::list<Keyframe>> BoneKeyFrames;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -255,7 +255,8 @@ bool attachAABBComponentFromModel(World* world, EntityID id)
|
|||||||
|
|
||||||
glm::vec3 mini = glm::vec3(INFINITY, INFINITY, INFINITY);
|
glm::vec3 mini = glm::vec3(INFINITY, INFINITY, INFINITY);
|
||||||
glm::vec3 maxi = glm::vec3(-INFINITY, -INFINITY, -INFINITY);
|
glm::vec3 maxi = glm::vec3(-INFINITY, -INFINITY, -INFINITY);
|
||||||
for (const auto& v : modelRes->Vertices()) {
|
for (unsigned int i = 0; i < modelRes->NumberOfVertices(); i++) {
|
||||||
|
const auto& v = modelRes->Vertices()[i];
|
||||||
const auto& wPos = modelMatrix * glm::vec4(v.Position.x, v.Position.y, v.Position.z, 1);
|
const auto& wPos = modelMatrix * glm::vec4(v.Position.x, v.Position.y, v.Position.z, 1);
|
||||||
maxi.x = std::max(wPos.x, maxi.x);
|
maxi.x = std::max(wPos.x, maxi.x);
|
||||||
maxi.y = std::max(wPos.y, maxi.y);
|
maxi.y = std::max(wPos.y, maxi.y);
|
||||||
|
|||||||
@@ -24,7 +24,12 @@ Model::Model(std::string fileName)
|
|||||||
GLuint buffer;
|
GLuint buffer;
|
||||||
glGenBuffers(1, &buffer);
|
glGenBuffers(1, &buffer);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||||
glBufferData(GL_ARRAY_BUFFER, m_RawModel->m_Vertices.size() * sizeof(RawModel::Vertex), &m_RawModel->m_Vertices[0], GL_STATIC_DRAW);
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
glGenBuffers(1, &ElementBuffer);
|
glGenBuffers(1, &ElementBuffer);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
|
||||||
@@ -35,7 +40,13 @@ Model::Model(std::string fileName)
|
|||||||
GLERROR("GLEW: BufferFail4");
|
GLERROR("GLEW: BufferFail4");
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||||
std::vector<int> structSizes = { 3, 3, 3, 3, 2, 4, 4 };
|
std::vector<int> structSizes;
|
||||||
|
if (m_RawModel->isSkined) {
|
||||||
|
structSizes = { 3, 3, 3, 3, 2, 4, 4 };
|
||||||
|
} else {
|
||||||
|
structSizes = { 3, 3, 3, 3, 2 };
|
||||||
|
}
|
||||||
|
|
||||||
int stride = 0;
|
int stride = 0;
|
||||||
for (int size : structSizes) {
|
for (int size : structSizes) {
|
||||||
stride += size;
|
stride += size;
|
||||||
@@ -49,8 +60,10 @@ 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++;
|
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++;
|
||||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
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++;
|
||||||
|
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
GLERROR("GLEW: BufferFail5");
|
GLERROR("GLEW: BufferFail5");
|
||||||
|
|
||||||
@@ -59,8 +72,10 @@ Model::Model(std::string fileName)
|
|||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
glEnableVertexAttribArray(3);
|
glEnableVertexAttribArray(3);
|
||||||
glEnableVertexAttribArray(4);
|
glEnableVertexAttribArray(4);
|
||||||
glEnableVertexAttribArray(5);
|
if (m_RawModel->isSkined) {
|
||||||
glEnableVertexAttribArray(6);
|
glEnableVertexAttribArray(5);
|
||||||
|
glEnableVertexAttribArray(6);
|
||||||
|
}
|
||||||
GLERROR("GLEW: BufferFail5");
|
GLERROR("GLEW: BufferFail5");
|
||||||
|
|
||||||
//CreateBuffers();
|
//CreateBuffers();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ RawModelCustom::RawModelCustom(std::string fileName)
|
|||||||
ReadMeshFile(fileName);
|
ReadMeshFile(fileName);
|
||||||
ReadMaterialFile(fileName);
|
ReadMaterialFile(fileName);
|
||||||
ReadAnimationFile(fileName);
|
ReadAnimationFile(fileName);
|
||||||
|
int k = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModelCustom::ReadMeshFile(std::string filePath)
|
void RawModelCustom::ReadMeshFile(std::string filePath)
|
||||||
@@ -40,7 +41,14 @@ void RawModelCustom::ReadMeshFile(std::string filePath)
|
|||||||
void RawModelCustom::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
m_Vertices.resize(*(unsigned int*)(fileData + offset));
|
isSkined = true;//*(unsigned int*)(fileData + offset);
|
||||||
|
//offset += sizeof(bool);
|
||||||
|
if (isSkined) {
|
||||||
|
m_SkinedVertices.resize(*(unsigned int*)(fileData + offset));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_Vertices.resize(*(unsigned int*)(fileData + offset));
|
||||||
|
}
|
||||||
offset += sizeof(unsigned int);
|
offset += sizeof(unsigned int);
|
||||||
m_Indices.resize(*(unsigned int*)(fileData + offset));
|
m_Indices.resize(*(unsigned int*)(fileData + offset));
|
||||||
offset += sizeof(unsigned int);
|
offset += sizeof(unsigned int);
|
||||||
@@ -57,12 +65,19 @@ void RawModelCustom::ReadMesh(unsigned int& offset, char* fileData, unsigned int
|
|||||||
void RawModelCustom::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) {
|
if (isSkined) {
|
||||||
throw Resource::FailedLoadingException("Reading vertices failed");
|
if (offset + m_SkinedVertices.size() * sizeof(SkinedVertex) > fileByteSize) {
|
||||||
}
|
throw Resource::FailedLoadingException("Reading skined vertices failed");
|
||||||
|
}
|
||||||
memcpy(&m_Vertices[0], fileData + offset, m_Vertices.size() * sizeof(Vertex));
|
memcpy(&m_SkinedVertices[0], fileData + offset, m_Vertices.size() * sizeof(SkinedVertex));
|
||||||
offset += m_Vertices.size() * sizeof(Vertex);
|
offset += m_SkinedVertices.size() * sizeof(SkinedVertex);
|
||||||
|
} else {
|
||||||
|
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) {
|
||||||
|
throw Resource::FailedLoadingException("Reading vertices failed");
|
||||||
|
}
|
||||||
|
memcpy(&m_Vertices[0], fileData + offset, m_Vertices.size() * sizeof(Vertex));
|
||||||
|
offset += m_Vertices.size() * sizeof(Vertex);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -317,19 +332,35 @@ void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileDat
|
|||||||
if (offset + sizeof(float) > fileByteSize) {
|
if (offset + sizeof(float) > fileByteSize) {
|
||||||
throw Resource::FailedLoadingException("Reading AnimationClip duration failed");
|
throw Resource::FailedLoadingException("Reading AnimationClip duration failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
newAnimation.Duration = *(float*)(fileData + offset);
|
newAnimation.Duration = *(float*)(fileData + offset);
|
||||||
offset += sizeof(float);
|
offset += sizeof(float);
|
||||||
|
|
||||||
if (offset + sizeof(unsigned int) > fileByteSize) {
|
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||||
throw Resource::FailedLoadingException("Reading AnimationClip NrOfKeyframes failed");
|
throw Resource::FailedLoadingException("Reading AnimationClip numberOfJointFrames failed");
|
||||||
}
|
}
|
||||||
unsigned int nrOfKeyframes = *(unsigned int*)(fileData + offset);
|
unsigned int numberOfJointFrames = *(unsigned int*)(fileData + offset);
|
||||||
offset += sizeof(unsigned int);
|
offset += sizeof(unsigned int);
|
||||||
|
|
||||||
newAnimation.Keyframes.reserve(nrOfKeyframes);
|
for (unsigned int i = 0; i < numberOfJointFrames; i++) {
|
||||||
for (unsigned int i = 0; i < nrOfKeyframes; i++) {
|
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||||
ReadAnimationKeyFrame(offset, fileData, fileByteSize, newAnimation);
|
throw Resource::FailedLoadingException("Reading AnimationClip JointID failed");
|
||||||
|
}
|
||||||
|
int jointID = *(unsigned int*)(fileData + offset);
|
||||||
|
offset += sizeof(unsigned int);
|
||||||
|
|
||||||
|
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||||
|
throw Resource::FailedLoadingException("Reading AnimationClip numberOFKeyFrames failed");
|
||||||
|
}
|
||||||
|
unsigned int numberOFKeyFrames = *(unsigned int*)(fileData + offset);
|
||||||
|
offset += sizeof(unsigned int);
|
||||||
|
|
||||||
|
if (numberOFKeyFrames > 0) {
|
||||||
|
newAnimation.JointAnimations[jointID].reserve(numberOFKeyFrames);
|
||||||
|
|
||||||
|
for (unsigned int j = 0; j < numberOFKeyFrames; j++) {
|
||||||
|
ReadAnimationKeyFrame(offset, fileData, fileByteSize, newAnimation.JointAnimations[jointID]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_Skeleton->Animations[newAnimation.Name] = newAnimation;
|
m_Skeleton->Animations[newAnimation.Name] = newAnimation;
|
||||||
//m_Skeleton->Animations[newAnimation.Name].KeyFrameAmount = nrOfKeyframes;
|
//m_Skeleton->Animations[newAnimation.Name].KeyFrameAmount = nrOfKeyframes;
|
||||||
@@ -337,7 +368,7 @@ void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileDat
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, Skeleton::Animation& animation)
|
void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, std::vector<Skeleton::Animation::Keyframe>& animation)
|
||||||
{
|
{
|
||||||
Skeleton::Animation::Keyframe newKeyFrame;
|
Skeleton::Animation::Keyframe newKeyFrame;
|
||||||
|
|
||||||
@@ -353,28 +384,26 @@ void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData,
|
|||||||
newKeyFrame.Time = *(float*)(fileData + offset);
|
newKeyFrame.Time = *(float*)(fileData + offset);
|
||||||
offset += sizeof(float);
|
offset += sizeof(float);
|
||||||
|
|
||||||
if (offset + sizeof(unsigned int) > fileByteSize) {
|
if (offset + sizeof(float) * 3 > fileByteSize) {
|
||||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame NrOfJoints failed");
|
throw Resource::FailedLoadingException("Reading AnimationKeyFrame Position failed");
|
||||||
}
|
}
|
||||||
unsigned int nrOfJoints = *(unsigned int*)(fileData + offset);
|
memcpy(&newKeyFrame.BoneProperties.Position[0], fileData + offset, sizeof(float) * 3);
|
||||||
offset += sizeof(unsigned int);
|
offset += sizeof(float) * 3;
|
||||||
|
|
||||||
if (offset + sizeof(Skeleton::Animation::Keyframe::BoneProperty) * nrOfJoints> fileByteSize) {
|
if (offset + sizeof(float) * 4 > fileByteSize) {
|
||||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame joints failed");
|
throw Resource::FailedLoadingException("Reading AnimationKeyFrame Rotation failed");
|
||||||
}
|
}
|
||||||
|
memcpy(&newKeyFrame.BoneProperties.Rotation[0], fileData + offset, sizeof(float) * 4);
|
||||||
|
offset += sizeof(float) * 4;
|
||||||
|
|
||||||
Skeleton::Animation::Keyframe::BoneProperty newBone;
|
if (offset + sizeof(float) * 3 > fileByteSize) {
|
||||||
|
throw Resource::FailedLoadingException("Reading AnimationKeyFrame Scale failed");
|
||||||
for (unsigned int i = 0; i < nrOfJoints; i++) {
|
|
||||||
memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty));
|
|
||||||
offset += sizeof(Skeleton::Animation::Keyframe::BoneProperty);
|
|
||||||
newKeyFrame.BoneProperties[newBone.ID] = newBone;
|
|
||||||
}
|
}
|
||||||
animation.Keyframes.push_back(newKeyFrame);
|
memcpy(&newKeyFrame.BoneProperties.Scale[0], fileData + offset, sizeof(float) * 3);
|
||||||
// memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty));
|
offset += sizeof(float) * 3;
|
||||||
//newKeyFrame.boneProperty = newBone;
|
|
||||||
|
|
||||||
// animation.BoneKeyFrames[newBone.ID].push_back(newKeyFrame);
|
|
||||||
|
animation.push_back(newKeyFrame);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public:
|
|||||||
|
|
||||||
virtual void WriteBinary(std::ostream& out)
|
virtual void WriteBinary(std::ostream& out)
|
||||||
{
|
{
|
||||||
out.write((char*)&hasSkin, sizeof(bool));
|
//out.write((char*)&hasSkin, sizeof(bool));
|
||||||
out.write((char*)&NumVertices, sizeof(int));
|
out.write((char*)&NumVertices, sizeof(int));
|
||||||
out.write((char*)&NumIndices, sizeof(int));
|
out.write((char*)&NumIndices, sizeof(int));
|
||||||
for (auto aVertex : Vertices) {
|
for (auto aVertex : Vertices) {
|
||||||
|
|||||||
@@ -214,26 +214,28 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
|||||||
jointIt.reset();
|
jointIt.reset();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
|
||||||
|
unsigned int jointID = 0;
|
||||||
|
|
||||||
int currentFrame = startFrame;
|
while (!jointIt.isDone()) {
|
||||||
while (currentFrame <= endFrame) { // ANDREAS
|
int currentFrame = startFrame;
|
||||||
Animation::Keyframe thisKeyFrame;
|
Animation::JointAnimation thisJointAnimation;
|
||||||
thisKeyFrame.Index = currentFrame - startFrame;
|
bool haxBool = false;
|
||||||
thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
|
while (currentFrame < endFrame) {
|
||||||
|
Animation::JointAnimation::KeyFrame thisKeyFrame;
|
||||||
|
//thisKeyFrame.Index = currentFrame - startFrame;
|
||||||
|
//thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
|
||||||
|
|
||||||
MAnimControl::setCurrentTime(MTime(currentFrame, MTime::kNTSCField));
|
MAnimControl::setCurrentTime(MTime(currentFrame, MTime::kNTSCField));
|
||||||
MTime time = MAnimControl::currentTime();
|
MTime time = MAnimControl::currentTime();
|
||||||
|
|
||||||
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
|
|
||||||
unsigned int jointID = 0;
|
|
||||||
while (!jointIt.isDone()) {
|
|
||||||
MFnTransform thisJoint(jointIt.currentItem());
|
MFnTransform thisJoint(jointIt.currentItem());
|
||||||
MMatrix transformationMatrix = thisJoint.transformationMatrix();
|
MMatrix transformationMatrix = thisJoint.transformationMatrix();
|
||||||
|
|
||||||
double doubleMat[4][4];
|
double doubleMat[4][4];
|
||||||
|
|
||||||
if (currentFrame != startFrame){
|
if (currentFrame != startFrame) {
|
||||||
Animation::Keyframe::JointProperty joint;
|
//Animation::JointAnimation joint;
|
||||||
|
|
||||||
doubleMat[0][0] = joinCheckMap[thisJoint.name().asChar()][0][0];
|
doubleMat[0][0] = joinCheckMap[thisJoint.name().asChar()][0][0];
|
||||||
doubleMat[0][1] = joinCheckMap[thisJoint.name().asChar()][0][1];
|
doubleMat[0][1] = joinCheckMap[thisJoint.name().asChar()][0][1];
|
||||||
@@ -255,9 +257,53 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
|||||||
MMatrix LastJointMatrix(doubleMat);
|
MMatrix LastJointMatrix(doubleMat);
|
||||||
//Is same as last KeyFrame
|
//Is same as last KeyFrame
|
||||||
if (LastJointMatrix.isEquivalent(transformationMatrix)) {
|
if (LastJointMatrix.isEquivalent(transformationMatrix)) {
|
||||||
jointID++;
|
//jointID++;
|
||||||
jointIt.next();
|
//jointIt.next();
|
||||||
|
currentFrame++;
|
||||||
|
haxBool = false;
|
||||||
continue;
|
continue;
|
||||||
|
} else if(!haxBool){
|
||||||
|
haxBool = true;
|
||||||
|
MTransformationMatrix TransformationMatrix = LastJointMatrix;
|
||||||
|
MObject jointOrientObj = thisJoint.attribute("jointOrient");
|
||||||
|
MFnNumericAttribute jointOrient(jointOrientObj);
|
||||||
|
double jointOrientDouble[3];
|
||||||
|
jointOrient.getDefault(jointOrientDouble[0], jointOrientDouble[1], jointOrientDouble[2]);
|
||||||
|
//MGlobal::displayError(MString() + "Joint Matrix: ");
|
||||||
|
//MGlobal::displayError(MString() + Matrix.asMatrix()[0][0] + " " + Matrix.asMatrix()[0][1] + " " + Matrix.asMatrix()[0][2] + " " + Matrix.asMatrix()[0][3]);
|
||||||
|
//MGlobal::displayError(MString() + Matrix.asMatrix()[1][0] + " " + Matrix.asMatrix()[1][1] + " " + Matrix.asMatrix()[1][2] + " " + Matrix.asMatrix()[1][3]);
|
||||||
|
//MGlobal::displayError(MString() + Matrix.asMatrix()[2][0] + " " + Matrix.asMatrix()[2][1] + " " + Matrix.asMatrix()[2][2] + " " + Matrix.asMatrix()[2][3]);
|
||||||
|
//MGlobal::displayError(MString() + Matrix.asMatrix()[3][0] + " " + Matrix.asMatrix()[3][1] + " " + Matrix.asMatrix()[3][2] + " " + Matrix.asMatrix()[3][3]);
|
||||||
|
|
||||||
|
MEulerRotation joEuler(jointOrientDouble[0], jointOrientDouble[1], jointOrientDouble[2]);
|
||||||
|
MQuaternion jo = joEuler.asQuaternion();
|
||||||
|
|
||||||
|
double tmp[4];
|
||||||
|
TransformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||||
|
MQuaternion rotation(tmp);
|
||||||
|
|
||||||
|
rotation = rotation * jo;
|
||||||
|
rotation.get(tmp);
|
||||||
|
|
||||||
|
//Animation::JointAnimation::KeyFrame keyframe;
|
||||||
|
Animation::JointAnimation::KeyFrame previousKeyFrame;
|
||||||
|
previousKeyFrame.Index = currentFrame - startFrame - 1;
|
||||||
|
previousKeyFrame.Time = previousKeyFrame.Index * oneDivSixty;
|
||||||
|
|
||||||
|
previousKeyFrame.Rotation[0] = tmp[0];
|
||||||
|
previousKeyFrame.Rotation[1] = tmp[1];
|
||||||
|
previousKeyFrame.Rotation[2] = tmp[2];
|
||||||
|
previousKeyFrame.Rotation[3] = tmp[3];
|
||||||
|
TransformationMatrix.getTranslation(MSpace::kTransform).get(tmp);
|
||||||
|
previousKeyFrame.Position[0] = tmp[0];
|
||||||
|
previousKeyFrame.Position[1] = tmp[1];
|
||||||
|
previousKeyFrame.Position[2] = tmp[2];
|
||||||
|
TransformationMatrix.getScale(tmp, MSpace::kTransform);
|
||||||
|
previousKeyFrame.Scale[0] = tmp[0];
|
||||||
|
previousKeyFrame.Scale[1] = tmp[1];
|
||||||
|
previousKeyFrame.Scale[2] = tmp[2];
|
||||||
|
|
||||||
|
thisJointAnimation.m_KeyFrames.push_back(previousKeyFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,13 +326,36 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
|||||||
joinCheckMap[thisJoint.name().asChar()][3][2] = doubleMat[3][2];
|
joinCheckMap[thisJoint.name().asChar()][3][2] = doubleMat[3][2];
|
||||||
joinCheckMap[thisJoint.name().asChar()][3][3] = doubleMat[3][3];
|
joinCheckMap[thisJoint.name().asChar()][3][3] = doubleMat[3][3];
|
||||||
|
|
||||||
MTransformationMatrix Matrix = thisJoint.transformation();
|
MTransformationMatrix TransformationMatrix = thisJoint.transformation();
|
||||||
MPlug BindPose = thisJoint.findPlug("bindPose");
|
|
||||||
MDataHandle DataHandle;
|
if (currentFrame == startFrame) {
|
||||||
BindPose.getValue(DataHandle);
|
MPlug thisJointBindPose = thisJoint.findPlug("bindPose");
|
||||||
MFnMatrixData MartixFn(DataHandle.data());
|
MDataHandle DataHandle;
|
||||||
MMatrix BindPoseMatrix = MartixFn.matrix();
|
thisJointBindPose.getValue(DataHandle);
|
||||||
Matrix = Matrix.asMatrix();
|
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();
|
||||||
|
|
||||||
|
thisJointBindPoseMatrix = thisJointBindPoseMatrix * parentBindPoseMatrix.inverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisJointBindPoseMatrix.isEquivalent(TransformationMatrix.asMatrix())) {
|
||||||
|
//jointID++;
|
||||||
|
//jointIt.next();
|
||||||
|
currentFrame++;
|
||||||
|
MGlobal::displayError(MString() + thisJoint.name() + " is in bindPose");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
haxBool = true;
|
||||||
|
}
|
||||||
|
|
||||||
MObject jointOrientObj = thisJoint.attribute("jointOrient");
|
MObject jointOrientObj = thisJoint.attribute("jointOrient");
|
||||||
MFnNumericAttribute jointOrient(jointOrientObj);
|
MFnNumericAttribute jointOrient(jointOrientObj);
|
||||||
@@ -302,40 +371,41 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
|||||||
MQuaternion jo = joEuler.asQuaternion();
|
MQuaternion jo = joEuler.asQuaternion();
|
||||||
|
|
||||||
double tmp[4];
|
double tmp[4];
|
||||||
Matrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
|
TransformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||||
MQuaternion rotation(tmp);
|
MQuaternion rotation(tmp);
|
||||||
|
|
||||||
rotation = rotation * jo;
|
rotation = rotation * jo;
|
||||||
rotation.get(tmp);
|
rotation.get(tmp);
|
||||||
|
|
||||||
Animation::Keyframe::JointProperty joint;
|
//Animation::JointAnimation::KeyFrame keyframe;
|
||||||
joint.ID = jointID;
|
thisKeyFrame.Index = currentFrame - startFrame;
|
||||||
|
thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
|
||||||
|
|
||||||
joint.Rotation[0] = tmp[0];
|
thisKeyFrame.Rotation[0] = tmp[0];
|
||||||
joint.Rotation[1] = tmp[1];
|
thisKeyFrame.Rotation[1] = tmp[1];
|
||||||
joint.Rotation[2] = tmp[2];
|
thisKeyFrame.Rotation[2] = tmp[2];
|
||||||
joint.Rotation[3] = tmp[3];
|
thisKeyFrame.Rotation[3] = tmp[3];
|
||||||
Matrix.getTranslation(MSpace::kTransform).get(tmp);
|
TransformationMatrix.getTranslation(MSpace::kTransform).get(tmp);
|
||||||
joint.Position[0] = tmp[0];
|
thisKeyFrame.Position[0] = tmp[0];
|
||||||
joint.Position[1] = tmp[1];
|
thisKeyFrame.Position[1] = tmp[1];
|
||||||
joint.Position[2] = tmp[2];
|
thisKeyFrame.Position[2] = tmp[2];
|
||||||
Matrix.getScale(tmp, MSpace::kTransform);
|
TransformationMatrix.getScale(tmp, MSpace::kTransform);
|
||||||
joint.Scale[0] = tmp[0];
|
thisKeyFrame.Scale[0] = tmp[0];
|
||||||
joint.Scale[1] = tmp[1];
|
thisKeyFrame.Scale[1] = tmp[1];
|
||||||
joint.Scale[2] = tmp[2];
|
thisKeyFrame.Scale[2] = tmp[2];
|
||||||
|
|
||||||
thisKeyFrame.JointProperties.push_back(joint);
|
thisJointAnimation.m_KeyFrames.push_back(thisKeyFrame);
|
||||||
|
|
||||||
jointID++;
|
currentFrame++;
|
||||||
jointIt.next();
|
|
||||||
}
|
}
|
||||||
thisKeyFrame.NumberOfJoints = thisKeyFrame.JointProperties.size();
|
//thisKeyFrame.NumberOfJoints = thisKeyFrame.JointProperties.size();
|
||||||
returnData.Keyframes.push_back(thisKeyFrame);
|
thisJointAnimation.numberOFKeyFrames = thisJointAnimation.m_KeyFrames.size();
|
||||||
currentFrame++;
|
returnData.JointsFrameMap[jointID] = (thisJointAnimation);
|
||||||
|
|
||||||
|
jointID++;
|
||||||
|
jointIt.next();
|
||||||
}
|
}
|
||||||
|
returnData.NumOfJointFrames = returnData.JointsFrameMap.size();
|
||||||
returnData.NumKeyFrames = returnData.Keyframes.size();
|
|
||||||
|
|
||||||
return returnData;
|
return returnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,44 +10,56 @@
|
|||||||
|
|
||||||
class Animation : public OutputData {
|
class Animation : public OutputData {
|
||||||
public:
|
public:
|
||||||
struct Keyframe
|
//struct Keyframe
|
||||||
{
|
//{
|
||||||
struct JointProperty
|
// struct JointProperty
|
||||||
{
|
// {
|
||||||
int ID = 0;
|
// int ID = 0;
|
||||||
|
// float Position[3]{ 0 };
|
||||||
|
// float Rotation[4]{ 0 };
|
||||||
|
// float Scale[3]{ 0 };
|
||||||
|
// };
|
||||||
|
|
||||||
|
// int Index = 0;
|
||||||
|
// float Time = 0;
|
||||||
|
// int NumberOfJoints;
|
||||||
|
// std::vector<JointProperty> JointProperties;
|
||||||
|
//};
|
||||||
|
|
||||||
|
struct JointAnimation {
|
||||||
|
struct KeyFrame {
|
||||||
|
int Index = 0;
|
||||||
|
float Time = 0;
|
||||||
float Position[3]{ 0 };
|
float Position[3]{ 0 };
|
||||||
float Rotation[4]{ 0 };
|
float Rotation[4]{ 0 };
|
||||||
float Scale[3]{ 0 };
|
float Scale[3]{ 0 };
|
||||||
};
|
};
|
||||||
|
unsigned int numberOFKeyFrames = 0;
|
||||||
int Index = 0;
|
std::vector<KeyFrame> m_KeyFrames;
|
||||||
float Time = 0;
|
};
|
||||||
int NumberOfJoints;
|
|
||||||
std::vector<JointProperty> JointProperties;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string Name;
|
std::string Name;
|
||||||
int nameLength = 0;
|
int nameLength = 0;
|
||||||
float Duration = 0;
|
float Duration = 0;
|
||||||
int NumKeyFrames = 0;
|
int NumOfJointFrames = 0;
|
||||||
std::vector<Keyframe> Keyframes;
|
std::map<int, JointAnimation> JointsFrameMap;
|
||||||
|
|
||||||
virtual void WriteBinary(std::ostream& out)
|
virtual void WriteBinary(std::ostream& out)
|
||||||
{
|
{
|
||||||
out.write((char*)&nameLength, sizeof(int));
|
out.write((char*)&nameLength, sizeof(int));
|
||||||
out.write(Name.c_str(), Name.size() + 1);
|
out.write(Name.c_str(), Name.size() + 1);
|
||||||
out.write((char*)&Duration, sizeof(float));
|
out.write((char*)&Duration, sizeof(float));
|
||||||
out.write((char*)&NumKeyFrames, sizeof(int));
|
out.write((char*)&NumOfJointFrames, sizeof(int));
|
||||||
//Här under loopas alla key frames igenom
|
//Här under loopas alla key frames igenom
|
||||||
for (auto aKeyframe : Keyframes) {
|
for (auto aJointAnimation : JointsFrameMap) {
|
||||||
out.write((char*)&aKeyframe.Index, sizeof(int));
|
out.write((char*)&aJointAnimation.first, sizeof(int));
|
||||||
out.write((char*)&aKeyframe.Time, sizeof(float));
|
out.write((char*)&aJointAnimation.second.numberOFKeyFrames, sizeof(int));
|
||||||
out.write((char*)&aKeyframe.NumberOfJoints, sizeof(int));
|
for (auto aJointKeyFrame : aJointAnimation.second.m_KeyFrames) {
|
||||||
for (auto aJoint : aKeyframe.JointProperties) {
|
out.write((char*)&aJointKeyFrame.Index, sizeof(int));
|
||||||
out.write((char*)&aJoint.ID, sizeof(int));
|
out.write((char*)&aJointKeyFrame.Time, sizeof(float));
|
||||||
out.write((char*)aJoint.Position, sizeof(float) * 3);
|
out.write((char*)&aJointKeyFrame.Position, sizeof(float) * 3);
|
||||||
out.write((char*)aJoint.Rotation, sizeof(float) * 4);
|
out.write((char*)&aJointKeyFrame.Rotation, sizeof(float) * 4);
|
||||||
out.write((char*)aJoint.Scale, sizeof(float) * 3);
|
out.write((char*)&aJointKeyFrame.Scale, sizeof(float) * 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,16 +68,17 @@ 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 KeyFrames: " << NumOfJointFrames << endl;
|
||||||
for (auto aKeyframe : Keyframes) {
|
for (auto aJointAnimation : JointsFrameMap) {
|
||||||
out << "Frame: " << aKeyframe.Index << endl;
|
out << "Bone: " << aJointAnimation.first << endl;
|
||||||
out << "Time: " << aKeyframe.Time << endl;
|
//out << "Time: " << aJointAnimation.Time << endl;
|
||||||
out << "Number of Joints: " << aKeyframe.NumberOfJoints << endl;
|
//out << "Number of Joints: " << aKeyframe.NumberOfJoints << endl;
|
||||||
for (auto aJoint : aKeyframe.JointProperties) {
|
for (auto aJointKeyFrame : aJointAnimation.second.m_KeyFrames) {
|
||||||
out << "Joint ID: " << aJoint.ID << endl;
|
//out << "Joint ID: " << aJoint.ID << endl;
|
||||||
out << aJoint.Position[0] << " " << aJoint.Position[1] << " " << aJoint.Position[2] << endl;
|
out << "Time: " << aJointKeyFrame.Time << endl;
|
||||||
out << aJoint.Rotation[0] << " " << aJoint.Rotation[1] << " " << aJoint.Rotation[2] << " " << aJoint.Rotation[3] << endl;
|
out << aJointKeyFrame.Position[0] << " " << aJointKeyFrame.Position[1] << " " << aJointKeyFrame.Position[2] << endl;
|
||||||
out << aJoint.Scale[0] << " " << aJoint.Scale[1] << " " << aJoint.Scale[2] << endl;
|
out << aJointKeyFrame.Rotation[0] << " " << aJointKeyFrame.Rotation[1] << " " << aJointKeyFrame.Rotation[2] << " " << aJointKeyFrame.Rotation[3] << endl;
|
||||||
|
out << aJointKeyFrame.Scale[0] << " " << aJointKeyFrame.Scale[1] << " " << aJointKeyFrame.Scale[2] << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user