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/GeneratedFiles/
|
||||
|
||||
tools/MayaExporter/MayaExporter/x64/*
|
||||
tools/MayaExporter/x64/*
|
||||
|
||||
+1
-1
Submodule assets updated: 9b2fa74a6d...c4898d8281
@@ -16,8 +16,9 @@ public:
|
||||
~Model();
|
||||
const std::vector<RawModel::MaterialGroup>& MaterialGroups() const { return m_RawModel->MaterialGroups; }
|
||||
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 ElementBuffer;
|
||||
RawModel* m_RawModel;
|
||||
|
||||
@@ -33,17 +33,20 @@ protected:
|
||||
public:
|
||||
~RawModelCustom();
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Normal;
|
||||
glm::vec3 Tangent;
|
||||
glm::vec3 BiNormal;
|
||||
glm::vec2 TextureCoords;
|
||||
struct Vertex
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Normal;
|
||||
glm::vec3 Tangent;
|
||||
glm::vec3 BiNormal;
|
||||
glm::vec2 TextureCoords;
|
||||
};
|
||||
|
||||
struct SkinedVertex : public Vertex {
|
||||
glm::vec4 BoneIndices;
|
||||
glm::vec4 BoneWeights;
|
||||
};
|
||||
|
||||
|
||||
struct MaterialGroup
|
||||
{
|
||||
float SpecularExponent;
|
||||
@@ -64,15 +67,33 @@ public:
|
||||
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;
|
||||
Skeleton* m_Skeleton = nullptr;
|
||||
glm::mat4 m_Matrix;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Vertex> m_Vertices;
|
||||
std::vector<SkinedVertex> m_SkinedVertices;
|
||||
|
||||
void ReadMeshFile(std::string filePath);
|
||||
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 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 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);
|
||||
};
|
||||
|
||||
@@ -54,24 +54,22 @@ public:
|
||||
{
|
||||
struct BoneProperty
|
||||
{
|
||||
int ID;
|
||||
glm::vec3 Position;
|
||||
glm::quat Rotation;
|
||||
glm::vec3 Scale = glm::vec3(1);
|
||||
};
|
||||
|
||||
int Index = 0;
|
||||
double Time = 0.0;
|
||||
std::map<int, Keyframe::BoneProperty> BoneProperties;
|
||||
int Index = 0;
|
||||
double Time = 0.0;
|
||||
BoneProperty BoneProperties;
|
||||
//Keyframe::BoneProperty boneProperty;
|
||||
};
|
||||
|
||||
std::string Name;
|
||||
double Duration;
|
||||
// unsigned int KeyFrameAmount;
|
||||
std::vector<Keyframe> Keyframes;
|
||||
//std::map<int, std::list<Keyframe>> BoneKeyFrames;
|
||||
|
||||
std::string Name;
|
||||
double Duration;
|
||||
std::map<int, std::vector<Keyframe>> JointAnimations;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
Skeleton() { }
|
||||
|
||||
@@ -255,7 +255,8 @@ bool attachAABBComponentFromModel(World* world, EntityID id)
|
||||
|
||||
glm::vec3 mini = 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);
|
||||
maxi.x = std::max(wPos.x, maxi.x);
|
||||
maxi.y = std::max(wPos.y, maxi.y);
|
||||
|
||||
@@ -24,7 +24,12 @@ Model::Model(std::string fileName)
|
||||
GLuint buffer;
|
||||
glGenBuffers(1, &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);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
|
||||
@@ -35,7 +40,13 @@ Model::Model(std::string fileName)
|
||||
GLERROR("GLEW: BufferFail4");
|
||||
|
||||
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;
|
||||
for (int size : structSizes) {
|
||||
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++;
|
||||
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++;
|
||||
}
|
||||
}
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
@@ -59,8 +72,10 @@ Model::Model(std::string fileName)
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
glEnableVertexAttribArray(5);
|
||||
glEnableVertexAttribArray(6);
|
||||
if (m_RawModel->isSkined) {
|
||||
glEnableVertexAttribArray(5);
|
||||
glEnableVertexAttribArray(6);
|
||||
}
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
//CreateBuffers();
|
||||
|
||||
@@ -11,6 +11,7 @@ RawModelCustom::RawModelCustom(std::string fileName)
|
||||
ReadMeshFile(fileName);
|
||||
ReadMaterialFile(fileName);
|
||||
ReadAnimationFile(fileName);
|
||||
int k = 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
#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);
|
||||
m_Indices.resize(*(unsigned int*)(fileData + offset));
|
||||
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)
|
||||
{
|
||||
#ifdef BOOST_LITTLE_ENDIAN
|
||||
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);
|
||||
if (isSkined) {
|
||||
if (offset + m_SkinedVertices.size() * sizeof(SkinedVertex) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading skined vertices failed");
|
||||
}
|
||||
memcpy(&m_SkinedVertices[0], fileData + offset, m_Vertices.size() * sizeof(SkinedVertex));
|
||||
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
|
||||
#endif
|
||||
}
|
||||
@@ -317,19 +332,35 @@ void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileDat
|
||||
if (offset + sizeof(float) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationClip duration failed");
|
||||
}
|
||||
|
||||
newAnimation.Duration = *(float*)(fileData + offset);
|
||||
offset += sizeof(float);
|
||||
|
||||
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);
|
||||
|
||||
newAnimation.Keyframes.reserve(nrOfKeyframes);
|
||||
for (unsigned int i = 0; i < nrOfKeyframes; i++) {
|
||||
ReadAnimationKeyFrame(offset, fileData, fileByteSize, newAnimation);
|
||||
for (unsigned int i = 0; i < numberOfJointFrames; i++) {
|
||||
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||
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].KeyFrameAmount = nrOfKeyframes;
|
||||
@@ -337,7 +368,7 @@ void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileDat
|
||||
#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;
|
||||
|
||||
@@ -353,28 +384,26 @@ void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData,
|
||||
newKeyFrame.Time = *(float*)(fileData + offset);
|
||||
offset += sizeof(float);
|
||||
|
||||
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame NrOfJoints failed");
|
||||
if (offset + sizeof(float) * 3 > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame Position failed");
|
||||
}
|
||||
unsigned int nrOfJoints = *(unsigned int*)(fileData + offset);
|
||||
offset += sizeof(unsigned int);
|
||||
memcpy(&newKeyFrame.BoneProperties.Position[0], fileData + offset, sizeof(float) * 3);
|
||||
offset += sizeof(float) * 3;
|
||||
|
||||
if (offset + sizeof(Skeleton::Animation::Keyframe::BoneProperty) * nrOfJoints> fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame joints failed");
|
||||
if (offset + sizeof(float) * 4 > fileByteSize) {
|
||||
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;
|
||||
|
||||
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;
|
||||
if (offset + sizeof(float) * 3 > fileByteSize) {
|
||||
throw Resource::FailedLoadingException("Reading AnimationKeyFrame Scale failed");
|
||||
}
|
||||
animation.Keyframes.push_back(newKeyFrame);
|
||||
// memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty));
|
||||
//newKeyFrame.boneProperty = newBone;
|
||||
memcpy(&newKeyFrame.BoneProperties.Scale[0], fileData + offset, sizeof(float) * 3);
|
||||
offset += sizeof(float) * 3;
|
||||
|
||||
// animation.BoneKeyFrames[newBone.ID].push_back(newKeyFrame);
|
||||
|
||||
animation.push_back(newKeyFrame);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
|
||||
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*)&NumIndices, sizeof(int));
|
||||
for (auto aVertex : Vertices) {
|
||||
|
||||
@@ -214,26 +214,28 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
jointIt.reset();
|
||||
}*/
|
||||
|
||||
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
|
||||
unsigned int jointID = 0;
|
||||
|
||||
int currentFrame = startFrame;
|
||||
while (currentFrame <= endFrame) { // ANDREAS
|
||||
Animation::Keyframe thisKeyFrame;
|
||||
thisKeyFrame.Index = currentFrame - startFrame;
|
||||
thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
|
||||
while (!jointIt.isDone()) {
|
||||
int currentFrame = startFrame;
|
||||
Animation::JointAnimation thisJointAnimation;
|
||||
bool haxBool = false;
|
||||
while (currentFrame < endFrame) {
|
||||
Animation::JointAnimation::KeyFrame thisKeyFrame;
|
||||
//thisKeyFrame.Index = currentFrame - startFrame;
|
||||
//thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
|
||||
|
||||
MAnimControl::setCurrentTime(MTime(currentFrame, MTime::kNTSCField));
|
||||
MTime time = MAnimControl::currentTime();
|
||||
MAnimControl::setCurrentTime(MTime(currentFrame, MTime::kNTSCField));
|
||||
MTime time = MAnimControl::currentTime();
|
||||
|
||||
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
|
||||
unsigned int jointID = 0;
|
||||
while (!jointIt.isDone()) {
|
||||
MFnTransform thisJoint(jointIt.currentItem());
|
||||
MMatrix transformationMatrix = thisJoint.transformationMatrix();
|
||||
|
||||
|
||||
double doubleMat[4][4];
|
||||
|
||||
if (currentFrame != startFrame){
|
||||
Animation::Keyframe::JointProperty joint;
|
||||
if (currentFrame != startFrame) {
|
||||
//Animation::JointAnimation joint;
|
||||
|
||||
doubleMat[0][0] = joinCheckMap[thisJoint.name().asChar()][0][0];
|
||||
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);
|
||||
//Is same as last KeyFrame
|
||||
if (LastJointMatrix.isEquivalent(transformationMatrix)) {
|
||||
jointID++;
|
||||
jointIt.next();
|
||||
//jointID++;
|
||||
//jointIt.next();
|
||||
currentFrame++;
|
||||
haxBool = false;
|
||||
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][3] = doubleMat[3][3];
|
||||
|
||||
MTransformationMatrix Matrix = thisJoint.transformation();
|
||||
MPlug BindPose = thisJoint.findPlug("bindPose");
|
||||
MDataHandle DataHandle;
|
||||
BindPose.getValue(DataHandle);
|
||||
MFnMatrixData MartixFn(DataHandle.data());
|
||||
MMatrix BindPoseMatrix = MartixFn.matrix();
|
||||
Matrix = Matrix.asMatrix();
|
||||
MTransformationMatrix TransformationMatrix = thisJoint.transformation();
|
||||
|
||||
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();
|
||||
|
||||
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");
|
||||
MFnNumericAttribute jointOrient(jointOrientObj);
|
||||
@@ -302,40 +371,41 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
MQuaternion jo = joEuler.asQuaternion();
|
||||
|
||||
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);
|
||||
|
||||
rotation = rotation * jo;
|
||||
rotation.get(tmp);
|
||||
|
||||
Animation::Keyframe::JointProperty joint;
|
||||
joint.ID = jointID;
|
||||
//Animation::JointAnimation::KeyFrame keyframe;
|
||||
thisKeyFrame.Index = currentFrame - startFrame;
|
||||
thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
|
||||
|
||||
joint.Rotation[0] = tmp[0];
|
||||
joint.Rotation[1] = tmp[1];
|
||||
joint.Rotation[2] = tmp[2];
|
||||
joint.Rotation[3] = tmp[3];
|
||||
Matrix.getTranslation(MSpace::kTransform).get(tmp);
|
||||
joint.Position[0] = tmp[0];
|
||||
joint.Position[1] = tmp[1];
|
||||
joint.Position[2] = tmp[2];
|
||||
Matrix.getScale(tmp, MSpace::kTransform);
|
||||
joint.Scale[0] = tmp[0];
|
||||
joint.Scale[1] = tmp[1];
|
||||
joint.Scale[2] = tmp[2];
|
||||
thisKeyFrame.Rotation[0] = tmp[0];
|
||||
thisKeyFrame.Rotation[1] = tmp[1];
|
||||
thisKeyFrame.Rotation[2] = tmp[2];
|
||||
thisKeyFrame.Rotation[3] = tmp[3];
|
||||
TransformationMatrix.getTranslation(MSpace::kTransform).get(tmp);
|
||||
thisKeyFrame.Position[0] = tmp[0];
|
||||
thisKeyFrame.Position[1] = tmp[1];
|
||||
thisKeyFrame.Position[2] = tmp[2];
|
||||
TransformationMatrix.getScale(tmp, MSpace::kTransform);
|
||||
thisKeyFrame.Scale[0] = tmp[0];
|
||||
thisKeyFrame.Scale[1] = tmp[1];
|
||||
thisKeyFrame.Scale[2] = tmp[2];
|
||||
|
||||
thisKeyFrame.JointProperties.push_back(joint);
|
||||
|
||||
jointID++;
|
||||
jointIt.next();
|
||||
thisJointAnimation.m_KeyFrames.push_back(thisKeyFrame);
|
||||
|
||||
currentFrame++;
|
||||
}
|
||||
thisKeyFrame.NumberOfJoints = thisKeyFrame.JointProperties.size();
|
||||
returnData.Keyframes.push_back(thisKeyFrame);
|
||||
currentFrame++;
|
||||
//thisKeyFrame.NumberOfJoints = thisKeyFrame.JointProperties.size();
|
||||
thisJointAnimation.numberOFKeyFrames = thisJointAnimation.m_KeyFrames.size();
|
||||
returnData.JointsFrameMap[jointID] = (thisJointAnimation);
|
||||
|
||||
jointID++;
|
||||
jointIt.next();
|
||||
}
|
||||
|
||||
returnData.NumKeyFrames = returnData.Keyframes.size();
|
||||
|
||||
returnData.NumOfJointFrames = returnData.JointsFrameMap.size();
|
||||
return returnData;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,44 +10,56 @@
|
||||
|
||||
class Animation : public OutputData {
|
||||
public:
|
||||
struct Keyframe
|
||||
{
|
||||
struct JointProperty
|
||||
{
|
||||
int ID = 0;
|
||||
//struct Keyframe
|
||||
//{
|
||||
// struct JointProperty
|
||||
// {
|
||||
// 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 Rotation[4]{ 0 };
|
||||
float Scale[3]{ 0 };
|
||||
};
|
||||
|
||||
int Index = 0;
|
||||
float Time = 0;
|
||||
int NumberOfJoints;
|
||||
std::vector<JointProperty> JointProperties;
|
||||
};
|
||||
};
|
||||
unsigned int numberOFKeyFrames = 0;
|
||||
std::vector<KeyFrame> m_KeyFrames;
|
||||
};
|
||||
|
||||
std::string Name;
|
||||
int nameLength = 0;
|
||||
float Duration = 0;
|
||||
int NumKeyFrames = 0;
|
||||
std::vector<Keyframe> Keyframes;
|
||||
int NumOfJointFrames = 0;
|
||||
std::map<int, JointAnimation> JointsFrameMap;
|
||||
|
||||
virtual void WriteBinary(std::ostream& out)
|
||||
{
|
||||
out.write((char*)&nameLength, sizeof(int));
|
||||
out.write(Name.c_str(), Name.size() + 1);
|
||||
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
|
||||
for (auto aKeyframe : Keyframes) {
|
||||
out.write((char*)&aKeyframe.Index, sizeof(int));
|
||||
out.write((char*)&aKeyframe.Time, sizeof(float));
|
||||
out.write((char*)&aKeyframe.NumberOfJoints, sizeof(int));
|
||||
for (auto aJoint : aKeyframe.JointProperties) {
|
||||
out.write((char*)&aJoint.ID, sizeof(int));
|
||||
out.write((char*)aJoint.Position, sizeof(float) * 3);
|
||||
out.write((char*)aJoint.Rotation, sizeof(float) * 4);
|
||||
out.write((char*)aJoint.Scale, sizeof(float) * 3);
|
||||
for (auto aJointAnimation : JointsFrameMap) {
|
||||
out.write((char*)&aJointAnimation.first, sizeof(int));
|
||||
out.write((char*)&aJointAnimation.second.numberOFKeyFrames, sizeof(int));
|
||||
for (auto aJointKeyFrame : aJointAnimation.second.m_KeyFrames) {
|
||||
out.write((char*)&aJointKeyFrame.Index, sizeof(int));
|
||||
out.write((char*)&aJointKeyFrame.Time, sizeof(float));
|
||||
out.write((char*)&aJointKeyFrame.Position, sizeof(float) * 3);
|
||||
out.write((char*)&aJointKeyFrame.Rotation, sizeof(float) * 4);
|
||||
out.write((char*)&aJointKeyFrame.Scale, sizeof(float) * 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,16 +68,17 @@ public:
|
||||
{
|
||||
out << "Animation Name: " << Name << endl;
|
||||
out << "Duration: " << Duration << endl;
|
||||
out << "Number of KeyFrames: " << NumKeyFrames << endl;
|
||||
for (auto aKeyframe : Keyframes) {
|
||||
out << "Frame: " << aKeyframe.Index << endl;
|
||||
out << "Time: " << aKeyframe.Time << endl;
|
||||
out << "Number of Joints: " << aKeyframe.NumberOfJoints << endl;
|
||||
for (auto aJoint : aKeyframe.JointProperties) {
|
||||
out << "Joint ID: " << aJoint.ID << endl;
|
||||
out << aJoint.Position[0] << " " << aJoint.Position[1] << " " << aJoint.Position[2] << endl;
|
||||
out << aJoint.Rotation[0] << " " << aJoint.Rotation[1] << " " << aJoint.Rotation[2] << " " << aJoint.Rotation[3] << endl;
|
||||
out << aJoint.Scale[0] << " " << aJoint.Scale[1] << " " << aJoint.Scale[2] << endl;
|
||||
out << "Number of KeyFrames: " << NumOfJointFrames << endl;
|
||||
for (auto aJointAnimation : JointsFrameMap) {
|
||||
out << "Bone: " << aJointAnimation.first << endl;
|
||||
//out << "Time: " << aJointAnimation.Time << endl;
|
||||
//out << "Number of Joints: " << aKeyframe.NumberOfJoints << endl;
|
||||
for (auto aJointKeyFrame : aJointAnimation.second.m_KeyFrames) {
|
||||
//out << "Joint ID: " << aJoint.ID << endl;
|
||||
out << "Time: " << aJointKeyFrame.Time << endl;
|
||||
out << aJointKeyFrame.Position[0] << " " << aJointKeyFrame.Position[1] << " " << aJointKeyFrame.Position[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