mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-02 04:37:54 +08:00
Updated source code files of skeletal animation guest article.
This commit is contained in:
@@ -33,7 +33,7 @@ public:
|
||||
aiMatrix4x4 globalTransformation = scene->mRootNode->mTransformation;
|
||||
globalTransformation = globalTransformation.Inverse();
|
||||
ReadHeirarchyData(m_RootNode, scene->mRootNode);
|
||||
SetupBones(animation, *model);
|
||||
ReadMissingBones(animation, *model);
|
||||
}
|
||||
|
||||
~Animation()
|
||||
@@ -62,13 +62,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void SetupBones(const aiAnimation* animation, Model& model)
|
||||
void ReadMissingBones(const aiAnimation* animation, Model& model)
|
||||
{
|
||||
int size = animation->mNumChannels;
|
||||
|
||||
auto& boneInfoMap = model.GetOffsetMatMap();
|
||||
int& boneCount = model.GetBoneCount();
|
||||
auto& boneInfoMap = model.GetBoneInfoMap();//getting m_BoneInfoMap from Model class
|
||||
int& boneCount = model.GetBoneCount(); //getting the m_BoneCounter from Model class
|
||||
|
||||
//reading channels(bones engaged in an animation and their keyframes)
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
auto channel = animation->mChannels[i];
|
||||
|
||||
@@ -9,15 +9,17 @@
|
||||
#include <learnopengl/bone.h>
|
||||
|
||||
class Animator
|
||||
{
|
||||
{
|
||||
public:
|
||||
Animator::Animator(Animation* current)
|
||||
Animator::Animator(Animation* animation)
|
||||
{
|
||||
m_CurrentAnimation = current;
|
||||
m_CurrentTime = 0.0;
|
||||
m_Transforms.reserve(100);
|
||||
m_CurrentAnimation = animation;
|
||||
|
||||
m_FinalBoneMatrices.reserve(100);
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
m_Transforms.push_back(glm::mat4(1.0f));
|
||||
m_FinalBoneMatrices.push_back(glm::mat4(1.0f));
|
||||
}
|
||||
|
||||
void Animator::UpdateAnimation(float dt)
|
||||
@@ -57,22 +59,22 @@ public:
|
||||
{
|
||||
int index = boneInfoMap[nodeName].id;
|
||||
glm::mat4 offset = boneInfoMap[nodeName].offset;
|
||||
m_Transforms[index] = globalTransformation * offset;
|
||||
m_FinalBoneMatrices[index] = globalTransformation * offset;
|
||||
}
|
||||
|
||||
for (int i = 0; i < node->childrenCount; i++)
|
||||
CalculateBoneTransform(&node->children[i], globalTransformation);
|
||||
}
|
||||
|
||||
std::vector<glm::mat4> GetPoseTransforms()
|
||||
{
|
||||
return m_Transforms;
|
||||
std::vector<glm::mat4> GetFinalBoneMatrices()
|
||||
{
|
||||
return m_FinalBoneMatrices;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::vector<glm::mat4> m_Transforms;
|
||||
std::vector<glm::mat4> m_FinalBoneMatrices;
|
||||
Animation* m_CurrentAnimation;
|
||||
float m_CurrentTime;
|
||||
float m_DeltaTime;
|
||||
|
||||
|
||||
};
|
||||
@@ -1,18 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include<glm/glm.hpp>
|
||||
|
||||
struct BoneInfo
|
||||
{
|
||||
/*
|
||||
For uniquely indentifying the bone and
|
||||
for indexing bone transformation in shaders
|
||||
*/
|
||||
/*id is index in finalBoneMatrices*/
|
||||
int id;
|
||||
/*
|
||||
map from bone name to offset matrix.
|
||||
offset matrix transforms bone from bone space to local space
|
||||
*/
|
||||
|
||||
/*offset matrix transforms vertex from model space to bone space*/
|
||||
glm::mat4 offset;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user