#ifndef Skeleton_h__ #define Skeleton_h__ #include #include "Common.h" #include "../GLM.h" #include #include #include "../Core/EntityWrapper.h" class BlendTree; class Skeleton { public: struct Bone { Bone(int id, Bone* parent, std::string name, glm::mat4 offsetMatrix) : ID(id) , Parent(parent) , Name(name) , OffsetMatrix(offsetMatrix) { } std::string Name; glm::mat4 OffsetMatrix; int ID; Bone* Parent; std::vector Children; }; struct Animation { struct Keyframe { struct BoneProperty { glm::vec3 Position; glm::quat Rotation; glm::vec3 Scale = glm::vec3(1); }; int Index = 0; double Time = 0.0; BoneProperty BoneProperties; }; std::string Name; double Duration; std::map> JointAnimations; }; struct PoseData { glm::vec3 Translation; glm::quat Orientation; glm::vec3 Scale; }; Skeleton() { } ~Skeleton(); Bone* RootBone; std::map Bones; std::unordered_map> BlendTrees; // Attach a new bone to the skeleton // Returns: New bone index int CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix); int GetBoneID(std::string name); const Animation* GetAnimation(std::string name); std::map GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false); std::map BlendPoses(const std::map& pose1, const std::map& pose2, double weight); std::map OverridePose(const std::map& overridePose, const std::map& targetPose); std::map BlendPoseAdditive(const std::map& additivePose, const std::map& targetPose); void GetFinalPose(std::map& boneMatrices, std::vector& finalPose, std::map& boneTransforms); std::vector GetTPose(); std::map Animations; private: Skeleton::PoseData GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time); void AccumulateFinalPose(std::map& boneMatrices, std::map& poseDatas, std::map& boneTransforms, const Bone* bone, glm::mat4 parentMatrix); void AdditiveBoneTransforms(const Animation* animation, double time, std::map& boneMatrices, const Bone* bone); void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map& boneMatrices, const Bone* bone); std::map m_BonesByName; }; #endif