2 #ifndef KJY_ANIM_ENGINE_SKELETON_HPP_ 3 #define KJY_ANIM_ENGINE_SKELETON_HPP_ 7 #define GLM_ENABLE_EXPERIMENTAL 8 #include <glm/gtx/rotate_vector.hpp> 9 #include <components/inheritable/drawable.hpp> 10 #include <components/attachable/KeyframeAnimation.hpp> 11 #include "EntitiesBase.hpp" 13 #pragma warning(disable: 4250) // Disable warnings about dominance in MSVC 18 Bone(
const glm::mat4& inverse_bind);
19 Bone(
const glm::mat4& inverse_bind,
const Pose& pose);
20 Bone(
const glm::vec3& head,
const glm::vec3& tail,
float roll);
22 glm::vec3 getHead()
const;
23 glm::vec3 getTail()
const;
24 float getLength()
const;
25 virtual void draw(
const MVPset& MVP,
Program* shader =
nullptr)
override;
26 virtual bool isHidden()
const override {
return(
true);}
27 virtual bool canOverrideShader()
const override {
return(
false);}
28 virtual bool requiresOverrideShader()
const override {
return(
false);}
30 virtual void configureDrawScale(
Pose* pose)
const {(*pose)*= glm::scale(glm::vec3(getLength()));}
33 virtual const Pose& getPose()
const override {
return(_pose);}
34 virtual void setPose(
const Pose& pose)
override {_pose = pose;_cached_joint_dirty =
true;}
36 virtual void unlink()
override;
37 virtual void link(
Entity* parent)
override;
38 virtual bool hasParentBone()
const {
return(_parent_bone !=
nullptr);}
40 virtual glm::mat4 getBoneLocalTransform()
const;
41 virtual glm::mat4 getBoneWorldTransform()
const;
42 virtual glm::mat4 getInverseBindTransform()
const;
43 virtual glm::mat4 getJointTransform()
const;
44 virtual glm::mat4 getJointTransform();
46 int legacy_parent = -1;
47 std::vector<int> legacy_children;
51 enum class DrawMode{lines, axes };
52 DrawMode draw_mode = DrawMode::lines;
54 bool use_edit_color =
false;
55 const static glm::vec3 edit_color;
56 const static glm::vec3 pose_color;
61 void _update_joint_transform_cache();
64 glm::mat4 _inverse_bind;
67 Bone* _parent_bone =
nullptr;
68 bool _cached_joint_dirty =
true;
69 glm::mat4 _cached_joint_transform;
74 virtual const Pose& getPose()
const override {
return(skeleton_entity_pose);}
75 virtual Pose& getMutablePose() {
return(skeleton_entity_pose);}
76 virtual void setPose(
const Pose& pose)
override {this->skeleton_entity_pose = pose;}
78 virtual Pose getBoneSkinningPose(
size_t index)
const = 0;
80 virtual void addBone(
Bone* bone) {bones.push_back(bone); addChild(bone);}
81 virtual void setBonePose(
size_t index,
const Pose& pose) = 0;
82 virtual Bone* getBone(
size_t index) {
return(bones.at(index));}
83 virtual const Bone* getBone(
size_t index)
const {
return(bones.at(index));}
84 virtual const std::vector<Bone*>& getBonesArray()
const {
return(bones);}
85 virtual size_t numBones()
const {
return(bones.size());}
87 virtual void resetPose() = 0;
93 std::vector<Bone*> bones;
96 Pose skeleton_entity_pose;
110 virtual void drawSkeletonRestPose(
const MVPset& MVP);
111 virtual void drawSkeletonFinalPose(
const MVPset& MVP);
115 virtual Pose getBoneRestPose(
size_t index)
const;
117 virtual Pose getBoneFinalPose(
size_t index)
const;
119 virtual Pose getBoneSkinningPose(
size_t index)
const override;
121 virtual void addBone(
Bone* bone)
override {bones.push_back(bone); addChild(bone); bone_poses.emplace_back();}
122 virtual void setBonePose(
size_t index,
const Pose& pose)
override {bone_poses.at(index) = pose;}
124 virtual void resetPose()
override;
129 virtual Pose getWorldBoneTransform(
size_t index)
const;
133 std::vector<Pose> bone_poses;
139 virtual Pose getBoneSkinningPose(
size_t index)
const override;
143 virtual void addBone(
Bone* bone)
override {bones.push_back(bone);}
146 virtual void setBonesRecursive(
Bone* root);
148 virtual Bone* getBone(
size_t index)
override {
return(bones.at(index));}
149 virtual const Bone* getBone(
size_t index)
const override {
return(bones.at(index));}
150 virtual size_t numBones()
const override {
return(bones.size());}
152 virtual Bone* getRootBone() {
return(root);}
154 virtual void setBonePose(
size_t index,
const Pose& pose)
override {bones.at(index)->setPose(pose);}
156 virtual void resetPose()
override;
158 virtual void clearSkeleton();
162 virtual void _addBonesRecursive(
Bone* bone);
164 Bone* root =
nullptr;
167 bool _inited =
false;
Definition: Skeleton.hpp:15
Definition: drawable.hpp:8
Definition: EntitiesBase.hpp:54
Definition: EntitiesBase.hpp:18
Definition: poseable.hpp:16
Definition: Skeleton.hpp:72
Definition: drawable.hpp:14