Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
Skeleton.hpp
Go to the documentation of this file.
1 // Written by Koen Buitenhuis
2 #pragma once
3 
4 #include <ThirdParty/glm/glm/glm.hpp>
5 #include <ThirdParty/glm/glm/gtc/quaternion.hpp>
6 #include <ThirdParty/assimp/include/assimp/scene.h>
7 #include <ThirdParty/assimp/include/assimp/Importer.hpp>
8 
9 #include <ThirdParty/EASTL-master/include/EASTL/shared_ptr.h>
10 #include <ThirdParty/EASTL-master/include/EASTL/vector.h>
11 #include <ThirdParty/EASTL-master/include/EASTL/map.h>
12 
14 
15 namespace Engine {
16 
18  {
19  protected:
20 
21  struct AnimationNode;
22 
23  public:
28  Skeleton(const aiScene* scene);
29 
38  void LoadAnimationSet(const aiScene* scene, eastl::vector<eastl::string> names = {});
39 
43  virtual ~Skeleton();
44 
49  eastl::vector<eastl::string> GetAnimations();
50 
56  void SetAnimation(eastl::string animation, bool resetTime);
57 
63  float GetAnimationDuration(size_t animation);
64 
69  bool HasAnimations();
70 
76  Texture* GetAnimationData(size_t animation);
77 
83  size_t GetAnimationIndex(eastl::string animation);
84 
91  float GetAnimationTicksPerSecond(size_t animation);
92 
96  typedef struct Bone {
97  eastl::string name;
99  glm::mat4 transform;
100  glm::mat4 defaultTransform;
101  glm::mat4 offset;
102  struct Bone* parent;
103  aiNode* node;
104  eastl::vector<struct Bone*> childBones;
105  }Bone_t;
106 
111  eastl::map<eastl::string, Bone_t*> GetBoneMap();
112 
117  Bone_t* GetRootBone();
118 
123  void SetName(eastl::string name);
124 
129  eastl::string GetName();
130 
131  protected:
132 
133  bool animated;
134 
135  typedef struct Animation {
136  eastl::string name;
137  eastl::vector<struct AnimationNode> nodes;
138  float duration; // In ticks
140  eastl::shared_ptr<Texture> texture;
141  }Animation_t;
142 
143  typedef struct {
144  glm::mat4 transform;
145  }BoneData_t;
146 
147  typedef struct {
148  float time;
149  glm::vec3 position;
151 
152  typedef struct {
153  float time;
154  glm::quat rotation;
156 
157  typedef struct {
158  float time;
159  glm::vec3 scale;
161 
162  typedef struct AnimationNode {
164  eastl::vector<AnimationPositionKey_t> positionKeys;
165  eastl::vector<AnimationRotationKey_t> rotationKeys;
166  eastl::vector<AnimationScalingKey_t> scalingKeys;
167  aiAnimBehaviour preAnimBehaviour;
168  aiAnimBehaviour postAnimBehaviour;
170 
172 
173  eastl::vector<BoneData_t> boneData;
174 
175  eastl::map<eastl::string, size_t> animationMap;
176 
177  eastl::vector<Animation_t*> animations;
178 
179  const aiScene* scene;
180 
182 
184 
185  float time;
186 
187  float speed;
188 
189  bool paused;
190 
191  bool looping;
192 
193  eastl::map<eastl::string, Bone_t*> boneMap;
194 
195  eastl::string name;
196 
197  void ReadBones(Bone_t* bone, aiNode* node);
198 
199  void DestroyBone(Bone_t* bone);
200 
201  void SetBoneTransform(eastl::string bone, glm::mat4 transform);
202 
203  void SetBoneTransform(Bone_t* bone, glm::mat4 transform);
204 
205  void UpdateBoneTransformData(Bone_t* bone);
206 
207  void UpdateBoneTreeTransformData();
208 
209  void Update(float deltaTime);
210 
211  virtual void UpdateBoneBuffers();
212 
213  glm::mat4 InterpolateScale(float time, AnimationNode_t node);
214  glm::mat4 InterpolateRotation(float time, AnimationNode_t node);
215  glm::mat4 InterpolatePosition(float time, AnimationNode_t node);
216 
217  glm::mat4 TransformToMat4(aiMatrix4x4 transform);
218  };
219 
220 }
This object is used to store information regarding a texture. NOTE: Only the resource manager is allo...
Definition: Texture.hpp:23
struct Bone * parent
Definition: Skeleton.hpp:102
eastl::string name
Definition: Skeleton.hpp:97
#define ENGINE_API
Definition: api.hpp:25
eastl::vector< struct Bone * > childBones
Definition: Skeleton.hpp:104
eastl::vector< AnimationScalingKey_t > scalingKeys
Definition: Skeleton.hpp:166
eastl::vector< BoneData_t > boneData
Definition: Skeleton.hpp:173
size_t currentAnimationIndex
Definition: Skeleton.hpp:183
eastl::map< eastl::string, Bone_t * > boneMap
Definition: Skeleton.hpp:193
const aiScene * scene
Definition: Skeleton.hpp:179
eastl::vector< Animation_t * > animations
Definition: Skeleton.hpp:177
eastl::vector< AnimationPositionKey_t > positionKeys
Definition: Skeleton.hpp:164
glm::mat4 defaultTransform
Definition: Skeleton.hpp:100
Bone_t * rootBone
Definition: Skeleton.hpp:171
eastl::shared_ptr< Texture > texture
Definition: Skeleton.hpp:140
eastl::map< eastl::string, size_t > animationMap
Definition: Skeleton.hpp:175
A structure containing information a bone.
Definition: Skeleton.hpp:96
aiAnimBehaviour preAnimBehaviour
Definition: Skeleton.hpp:167
eastl::vector< AnimationRotationKey_t > rotationKeys
Definition: Skeleton.hpp:165
Animation_t * currentAnimation
Definition: Skeleton.hpp:181
eastl::vector< struct AnimationNode > nodes
Definition: Skeleton.hpp:137
eastl::string name
Definition: Skeleton.hpp:195
aiAnimBehaviour postAnimBehaviour
Definition: Skeleton.hpp:168