Fixed memory leaks and cleaned up Skeleton and BlendTree
This commit is contained in:
@@ -60,17 +60,22 @@ public:
|
|||||||
BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton);
|
BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton);
|
||||||
~BlendTree();
|
~BlendTree();
|
||||||
|
|
||||||
std::vector<glm::mat4> GetBoneTransforms(Skeleton* skeleton);
|
|
||||||
|
std::vector<glm::mat4> GetFinalPose() { return m_FinalPose; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrintTree();
|
void PrintTree();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Skeleton* m_Skeleton = nullptr;
|
||||||
Node* m_Root = nullptr;
|
Node* m_Root = nullptr;
|
||||||
|
|
||||||
void FillTree(Node* parentNode, EntityWrapper parentEntity, Skeleton* skeleton);
|
std::vector<glm::mat4> m_FinalPose;
|
||||||
BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity, Skeleton* skeleton);
|
std::vector<glm::mat4> AccumulateFinalPose();
|
||||||
|
BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity);
|
||||||
|
|
||||||
void Blend(Skeleton* skeleton, std::map<int, glm::mat4>& pose);
|
void Blend(std::map<int, glm::mat4>& pose);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -146,9 +146,6 @@ struct ModelJob : RenderJob
|
|||||||
glm::vec4 Color;
|
glm::vec4 Color;
|
||||||
const ::Model* Model = nullptr;
|
const ::Model* Model = nullptr;
|
||||||
::Skeleton* Skeleton = nullptr;
|
::Skeleton* Skeleton = nullptr;
|
||||||
std::vector<::Skeleton::AnimationData> Animations;
|
|
||||||
::Skeleton::AnimationOffset AnimationOffset;
|
|
||||||
|
|
||||||
std::shared_ptr<::BlendTree> BlendTree = nullptr;
|
std::shared_ptr<::BlendTree> BlendTree = nullptr;
|
||||||
|
|
||||||
glm::vec4 DiffuseColor;
|
glm::vec4 DiffuseColor;
|
||||||
|
|||||||
@@ -68,34 +68,6 @@ public:
|
|||||||
std::map<int, std::vector<Keyframe>> JointAnimations;
|
std::map<int, std::vector<Keyframe>> JointAnimations;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class BlendType
|
|
||||||
{
|
|
||||||
Additive,
|
|
||||||
Blend,
|
|
||||||
Override,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AnimationData
|
|
||||||
{
|
|
||||||
const Animation* animation;
|
|
||||||
BlendType blendType;
|
|
||||||
float time;
|
|
||||||
int level;
|
|
||||||
float weight;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct JointFramePose {
|
|
||||||
BlendType Type;
|
|
||||||
int Level = 0;
|
|
||||||
glm::mat4 Pose = glm::mat4(0);
|
|
||||||
float Weight = 0.0f;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AnimationOffset {
|
|
||||||
const Animation* animation;
|
|
||||||
float time;
|
|
||||||
};
|
|
||||||
|
|
||||||
Skeleton() { }
|
Skeleton() { }
|
||||||
~Skeleton();
|
~Skeleton();
|
||||||
|
|
||||||
@@ -106,36 +78,23 @@ public:
|
|||||||
// Attach a new bone to the skeleton
|
// Attach a new bone to the skeleton
|
||||||
// Returns: New bone index
|
// Returns: New bone index
|
||||||
int CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix);
|
int CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix);
|
||||||
|
|
||||||
int GetBoneID(std::string name);
|
int GetBoneID(std::string name);
|
||||||
|
const Animation* GetAnimation(std::string name);
|
||||||
std::vector<glm::mat4> GetFrameBones();
|
|
||||||
|
|
||||||
std::map<int, glm::mat4> GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false);
|
std::map<int, glm::mat4> GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false);
|
||||||
void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map<int, glm::mat4>& boneMatrices, bool additive, const Bone* bone, glm::mat4 parentMatrix);
|
|
||||||
|
|
||||||
const Animation* GetAnimation(std::string name);
|
|
||||||
glm::mat4 AdditiveBlend(const Bone* bone, AnimationOffset animationOffset, glm::mat4 targetPose);
|
|
||||||
|
|
||||||
std::map<std::string, Animation> Animations;
|
|
||||||
|
|
||||||
glm::mat4 GetBoneTransform(const Bone* bone, const Animation* animation, float time, glm::mat4 childMatrix);
|
glm::mat4 GetBoneTransform(const Bone* bone, const Animation* animation, float time, glm::mat4 childMatrix);
|
||||||
glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector<AnimationData> animations, AnimationOffset animationOffset, glm::mat4 childMatrix);
|
std::map<int, glm::mat4> BlendPoses(const std::map<int, glm::mat4>& pose1, const std::map<int, glm::mat4>& pose2, float weight);
|
||||||
glm::mat4 GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector<AnimationData> animations, glm::mat4 childMatrix);
|
std::map<int, glm::mat4> OverridePose(const std::map<int, glm::mat4>& overridePose, const std::map<int, glm::mat4>& targetPose);
|
||||||
|
std::map<int, glm::mat4> BlendPoseAdditive(const std::map<int, glm::mat4>& additivePose, const std::map<int, glm::mat4>& targetPose);
|
||||||
|
|
||||||
std::map<int, glm::mat4> BlendPoses(std::map<int, glm::mat4> pose1, std::map<int, glm::mat4> pose2, float weight);
|
|
||||||
std::map<int, glm::mat4> OverridePose(std::map<int, glm::mat4> overridePose, std::map<int, glm::mat4> targetPose);
|
|
||||||
std::map<int, glm::mat4> BlendPoseAdditive(std::map<int, glm::mat4> additivePose, std::map<int, glm::mat4> targetPose);
|
|
||||||
|
|
||||||
std::vector<glm::mat4> GetFinalPose(std::map<int, glm::mat4>& boneMatrices);
|
std::vector<glm::mat4> GetFinalPose(std::map<int, glm::mat4>& boneMatrices);
|
||||||
void AccumulateFinalPose(std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix);
|
|
||||||
|
std::map<std::string, Animation> Animations;
|
||||||
void AdditiveBoneTransforms(const Animation* animation, double time, std::map<int, glm::mat4>& boneMatrices, const Bone* bone);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glm::mat4 GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time);
|
glm::mat4 GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time);
|
||||||
glm::mat4 GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion);
|
glm::mat4 GetBonePose(const Bone* bone, const Animation* animation, double time, bool noRootMotion);
|
||||||
|
void AccumulateFinalPose(std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix);
|
||||||
|
void AdditiveBoneTransforms(const Animation* animation, double time, std::map<int, glm::mat4>& boneMatrices, const Bone* bone);
|
||||||
|
void AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix);
|
||||||
|
|
||||||
std::map<std::string, Bone*> m_BonesByName;
|
std::map<std::string, Bone*> m_BonesByName;
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
<Color A="1" B="0.137254909" G="0.121568628" R="0.160784319"/>
|
<Color A="1" B="0.137254909" G="0.121568628" R="0.160784319"/>
|
||||||
</c:Model>
|
</c:Model>
|
||||||
<c:Transform>
|
<c:Transform>
|
||||||
|
<Position X="-0.565843403" Y="0" Z="0"/>
|
||||||
<Scale X="10" Y="1" Z="10"/>
|
<Scale X="10" Y="1" Z="10"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
@@ -113,7 +114,7 @@
|
|||||||
<Components>
|
<Components>
|
||||||
<c:Animation>
|
<c:Animation>
|
||||||
<AnimationName>ShootFastRifleU</AnimationName>
|
<AnimationName>ShootFastRifleU</AnimationName>
|
||||||
<Time>0.10655260153188972</Time>
|
<Time>0.15443509503129649</Time>
|
||||||
<Speed>1</Speed>
|
<Speed>1</Speed>
|
||||||
</c:Animation>
|
</c:Animation>
|
||||||
<c:Transform/>
|
<c:Transform/>
|
||||||
@@ -134,7 +135,7 @@
|
|||||||
<Components>
|
<Components>
|
||||||
<c:Animation>
|
<c:Animation>
|
||||||
<AnimationName>StrafeRightF</AnimationName>
|
<AnimationName>StrafeRightF</AnimationName>
|
||||||
<Time>0.16490204151743337</Time>
|
<Time>0.4127890381477517</Time>
|
||||||
<Speed>1</Speed>
|
<Speed>1</Speed>
|
||||||
</c:Animation>
|
</c:Animation>
|
||||||
<c:Transform/>
|
<c:Transform/>
|
||||||
@@ -155,7 +156,7 @@
|
|||||||
<Components>
|
<Components>
|
||||||
<c:Animation>
|
<c:Animation>
|
||||||
<AnimationName>RunF</AnimationName>
|
<AnimationName>RunF</AnimationName>
|
||||||
<Time>0.9239205116676299</Time>
|
<Time>0.17180750829794933</Time>
|
||||||
<Speed>1</Speed>
|
<Speed>1</Speed>
|
||||||
</c:Animation>
|
</c:Animation>
|
||||||
<c:Transform/>
|
<c:Transform/>
|
||||||
@@ -166,7 +167,370 @@
|
|||||||
<Components>
|
<Components>
|
||||||
<c:Animation>
|
<c:Animation>
|
||||||
<AnimationName>WalkF</AnimationName>
|
<AnimationName>WalkF</AnimationName>
|
||||||
<Time>0.15333325334317904</Time>
|
<Time>0.40122024997349826</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="AssaultRed">
|
||||||
|
<Components>
|
||||||
|
<c:BlendAdditive>
|
||||||
|
<Adder>AimAdditive</Adder>
|
||||||
|
<Receiver>BlendOverride</Receiver>
|
||||||
|
</c:BlendAdditive>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Characters/Assault/AssaultAnimations.mesh</Resource>
|
||||||
|
<Color A="1" B="0.00392156886" G="0.00392156886" R="1"/>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="-1" Y="0" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="WeaponAttachment">
|
||||||
|
<Components>
|
||||||
|
<c:BoneAttachment>
|
||||||
|
<BoneName>R_Arm_Weapon_Joint</BoneName>
|
||||||
|
</c:BoneAttachment>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Scale X="1.00000012" Y="1" Z="1.00000012"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="AimAdditive">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>AimRifleA</AnimationName>
|
||||||
|
<Time>1</Time>
|
||||||
|
<Additive>true</Additive>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BlendOverride">
|
||||||
|
<Components>
|
||||||
|
<c:BlendOverride>
|
||||||
|
<Master>ShootRifleAnimation</Master>
|
||||||
|
<Slave>MovementBlend</Slave>
|
||||||
|
</c:BlendOverride>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="ShootRifleAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>ShootFastRifleU</AnimationName>
|
||||||
|
<Time>0.074040246120830933</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="MovementBlend">
|
||||||
|
<Components>
|
||||||
|
<c:Blend>
|
||||||
|
<Pose1>BlendWalkRun</Pose1>
|
||||||
|
<Pose2>StrafeAnimation</Pose2>
|
||||||
|
<Weight>1</Weight>
|
||||||
|
</c:Blend>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="StrafeAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>StrafeRightF</AnimationName>
|
||||||
|
<Time>0.33239292263858555</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BlendWalkRun">
|
||||||
|
<Components>
|
||||||
|
<c:Blend>
|
||||||
|
<Pose1>RunAnimtaion</Pose1>
|
||||||
|
<Pose2>WalkAnimation</Pose2>
|
||||||
|
<Weight>0.43000054359436035</Weight>
|
||||||
|
</c:Blend>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="RunAnimtaion">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>RunF</AnimationName>
|
||||||
|
<Time>0.091411392788782297</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="WalkAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>WalkF</AnimationName>
|
||||||
|
<Time>0.32082413446433122</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="AssaultBlue">
|
||||||
|
<Components>
|
||||||
|
<c:BlendAdditive>
|
||||||
|
<Adder>AimAdditive</Adder>
|
||||||
|
<Receiver>BlendOverride</Receiver>
|
||||||
|
</c:BlendAdditive>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Characters/Assault/AssaultAnimations.mesh</Resource>
|
||||||
|
<Color A="1" B="1" G="0.196078435" R="0.00392156886"/>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="1" Y="0" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="WeaponAttachment">
|
||||||
|
<Components>
|
||||||
|
<c:BoneAttachment>
|
||||||
|
<BoneName>R_Arm_Weapon_Joint</BoneName>
|
||||||
|
</c:BoneAttachment>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Scale X="1.00000012" Y="1" Z="1.00000012"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="AimAdditive">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>AimRifleA</AnimationName>
|
||||||
|
<Time>1</Time>
|
||||||
|
<Additive>true</Additive>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BlendOverride">
|
||||||
|
<Components>
|
||||||
|
<c:BlendOverride>
|
||||||
|
<Master>ShootRifleAnimation</Master>
|
||||||
|
<Slave>MovementBlend</Slave>
|
||||||
|
</c:BlendOverride>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="ShootRifleAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>ShootFastRifleU</AnimationName>
|
||||||
|
<Time>0.14396212913172102</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="MovementBlend">
|
||||||
|
<Components>
|
||||||
|
<c:Blend>
|
||||||
|
<Pose1>BlendWalkRun</Pose1>
|
||||||
|
<Pose2>StrafeAnimation</Pose2>
|
||||||
|
<Weight>1</Weight>
|
||||||
|
</c:Blend>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="StrafeAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>StrafeRightF</AnimationName>
|
||||||
|
<Time>0.40231464173670251</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BlendWalkRun">
|
||||||
|
<Components>
|
||||||
|
<c:Blend>
|
||||||
|
<Pose1>RunAnimtaion</Pose1>
|
||||||
|
<Pose2>WalkAnimation</Pose2>
|
||||||
|
<Weight>0.43000054359436035</Weight>
|
||||||
|
</c:Blend>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="RunAnimtaion">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>RunF</AnimationName>
|
||||||
|
<Time>0.16133311188689925</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="WalkAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>WalkF</AnimationName>
|
||||||
|
<Time>0.39074585356244818</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="AssaultPurple">
|
||||||
|
<Components>
|
||||||
|
<c:BlendAdditive>
|
||||||
|
<Adder>AimAdditive</Adder>
|
||||||
|
<Receiver>BlendOverride</Receiver>
|
||||||
|
</c:BlendAdditive>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Characters/Assault/AssaultAnimations.mesh</Resource>
|
||||||
|
<Color A="1" B="1" G="0" R="0.196078435"/>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Position X="0" Y="0" Z="1"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="WeaponAttachment">
|
||||||
|
<Components>
|
||||||
|
<c:BoneAttachment>
|
||||||
|
<BoneName>R_Arm_Weapon_Joint</BoneName>
|
||||||
|
</c:BoneAttachment>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Scale X="1.00000012" Y="1" Z="1.00000012"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="AimAdditive">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>AimRifleA</AnimationName>
|
||||||
|
<Time>1</Time>
|
||||||
|
<Additive>true</Additive>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BlendOverride">
|
||||||
|
<Components>
|
||||||
|
<c:BlendOverride>
|
||||||
|
<Master>ShootRifleAnimation</Master>
|
||||||
|
<Slave>MovementBlend</Slave>
|
||||||
|
</c:BlendOverride>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="ShootRifleAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>ShootFastRifleU</AnimationName>
|
||||||
|
<Time>0.032048013485985738</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="MovementBlend">
|
||||||
|
<Components>
|
||||||
|
<c:Blend>
|
||||||
|
<Pose1>BlendWalkRun</Pose1>
|
||||||
|
<Pose2>StrafeAnimation</Pose2>
|
||||||
|
<Weight>1</Weight>
|
||||||
|
</c:Blend>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="StrafeAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>StrafeRightF</AnimationName>
|
||||||
|
<Time>0.090400359197961855</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BlendWalkRun">
|
||||||
|
<Components>
|
||||||
|
<c:Blend>
|
||||||
|
<Pose1>RunAnimtaion</Pose1>
|
||||||
|
<Pose2>WalkAnimation</Pose2>
|
||||||
|
<Weight>0.43000054359436035</Weight>
|
||||||
|
</c:Blend>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="RunAnimtaion">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>RunF</AnimationName>
|
||||||
|
<Time>0.8494188293481586</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="WalkAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>WalkF</AnimationName>
|
||||||
|
<Time>0.078831571023707525</Time>
|
||||||
<Speed>1</Speed>
|
<Speed>1</Speed>
|
||||||
</c:Animation>
|
</c:Animation>
|
||||||
<c:Transform/>
|
<c:Transform/>
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
|
<Entity name="Assault" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
|
||||||
|
|
||||||
|
<Components>
|
||||||
|
<c:BlendAdditive>
|
||||||
|
<Adder>AimAdditive</Adder>
|
||||||
|
<Receiver>BlendOverride</Receiver>
|
||||||
|
</c:BlendAdditive>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Characters/Assault/AssaultAnimations.mesh</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
|
||||||
|
<Children>
|
||||||
|
<Entity name="WeaponAttachment">
|
||||||
|
<Components>
|
||||||
|
<c:BoneAttachment>
|
||||||
|
<BoneName>R_Arm_Weapon_Joint</BoneName>
|
||||||
|
</c:BoneAttachment>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
|
||||||
|
</c:Model>
|
||||||
|
<c:Transform>
|
||||||
|
<Scale X="1.00000012" Y="1" Z="1.00000012"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="AimAdditive">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>AimRifleA</AnimationName>
|
||||||
|
<Time>1</Time>
|
||||||
|
<Additive>true</Additive>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BlendOverride">
|
||||||
|
<Components>
|
||||||
|
<c:BlendOverride>
|
||||||
|
<Master>ShootRifleAnimation</Master>
|
||||||
|
<Slave>MovementBlend</Slave>
|
||||||
|
</c:BlendOverride>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="ShootRifleAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>ShootFastRifleU</AnimationName>
|
||||||
|
<Time>0.11937709655124218</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="MovementBlend">
|
||||||
|
<Components>
|
||||||
|
<c:Blend>
|
||||||
|
<Pose1>BlendWalkRun</Pose1>
|
||||||
|
<Pose2>StrafeAnimation</Pose2>
|
||||||
|
<Weight>1</Weight>
|
||||||
|
</c:Blend>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="StrafeAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>StrafeRightF</AnimationName>
|
||||||
|
<Time>0.37772682263908042</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="BlendWalkRun">
|
||||||
|
<Components>
|
||||||
|
<c:Blend>
|
||||||
|
<Pose1>RunAnimtaion</Pose1>
|
||||||
|
<Pose2>WalkAnimation</Pose2>
|
||||||
|
<Weight>0.43000054359436035</Weight>
|
||||||
|
</c:Blend>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children>
|
||||||
|
<Entity name="RunAnimtaion">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>RunF</AnimationName>
|
||||||
|
<Time>0.13674529278927716</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
<Entity name="WalkAnimation">
|
||||||
|
<Components>
|
||||||
|
<c:Animation>
|
||||||
|
<AnimationName>WalkF</AnimationName>
|
||||||
|
<Time>0.36615803446482609</Time>
|
||||||
|
<Speed>1</Speed>
|
||||||
|
</c:Animation>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
</Entity>
|
||||||
|
</Children>
|
||||||
|
|
||||||
|
</Entity>
|
||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
|
BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
m_Skeleton = skeleton;
|
||||||
|
|
||||||
|
|
||||||
auto itPair = ModelEntity.World->GetChildren(ModelEntity.ID);
|
auto itPair = ModelEntity.World->GetChildren(ModelEntity.ID);
|
||||||
if (itPair.first == itPair.second) {
|
if (itPair.first == itPair.second) {
|
||||||
return;
|
return;
|
||||||
@@ -16,7 +20,7 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
|
|||||||
|
|
||||||
m_Root = new Node();
|
m_Root = new Node();
|
||||||
m_Root->Name = ModelEntity.Name();
|
m_Root->Name = ModelEntity.Name();
|
||||||
m_Root->Pose = skeleton->GetFrameBones(animation, (double)ModelEntity["Animation"]["Time"], (bool)ModelEntity["Animation"]["Additive"]);
|
m_Root->Pose = m_Skeleton->GetFrameBones(animation, (double)ModelEntity["Animation"]["Time"], (bool)ModelEntity["Animation"]["Additive"]);
|
||||||
m_Root->Parent = nullptr;
|
m_Root->Parent = nullptr;
|
||||||
m_Root->Type = NodeType::Animation;
|
m_Root->Type = NodeType::Animation;
|
||||||
|
|
||||||
@@ -26,26 +30,27 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
|
|||||||
m_Root->Parent = nullptr;
|
m_Root->Parent = nullptr;
|
||||||
m_Root->Type = NodeType::Blend;
|
m_Root->Type = NodeType::Blend;
|
||||||
m_Root->Weight = (double)ModelEntity["Blend"]["Weight"];
|
m_Root->Weight = (double)ModelEntity["Blend"]["Weight"];
|
||||||
m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity, skeleton);
|
m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity);
|
||||||
m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity, skeleton);
|
m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity);
|
||||||
|
|
||||||
} else if (ModelEntity.HasComponent("BlendOverride")) {
|
} else if (ModelEntity.HasComponent("BlendOverride")) {
|
||||||
m_Root = new Node();
|
m_Root = new Node();
|
||||||
m_Root->Name = ModelEntity.Name();
|
m_Root->Name = ModelEntity.Name();
|
||||||
m_Root->Parent = nullptr;
|
m_Root->Parent = nullptr;
|
||||||
m_Root->Type = NodeType::Override;
|
m_Root->Type = NodeType::Override;
|
||||||
m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Master"], ModelEntity, skeleton);
|
m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Master"], ModelEntity);
|
||||||
m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Slave"], ModelEntity, skeleton);
|
m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendOverride"]["Slave"], ModelEntity);
|
||||||
|
|
||||||
} else if (ModelEntity.HasComponent("BlendAdditive")) {
|
} else if (ModelEntity.HasComponent("BlendAdditive")) {
|
||||||
m_Root = new Node();
|
m_Root = new Node();
|
||||||
m_Root->Name = ModelEntity.Name();
|
m_Root->Name = ModelEntity.Name();
|
||||||
m_Root->Parent = nullptr;
|
m_Root->Parent = nullptr;
|
||||||
m_Root->Type = NodeType::Additive;
|
m_Root->Type = NodeType::Additive;
|
||||||
m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Adder"], ModelEntity, skeleton);
|
m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Adder"], ModelEntity);
|
||||||
m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Receiver"], ModelEntity, skeleton);
|
m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["BlendAdditive"]["Receiver"], ModelEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_FinalPose = AccumulateFinalPose();
|
||||||
|
|
||||||
|
|
||||||
// PrintTree();
|
// PrintTree();
|
||||||
@@ -62,15 +67,12 @@ BlendTree::~BlendTree()
|
|||||||
std::list<Node*> m_NodesToRemove;
|
std::list<Node*> m_NodesToRemove;
|
||||||
|
|
||||||
while (currentNode != nullptr) {
|
while (currentNode != nullptr) {
|
||||||
currentNode = currentNode->Next();
|
|
||||||
m_NodesToRemove.push_back(currentNode);
|
m_NodesToRemove.push_back(currentNode);
|
||||||
|
currentNode = currentNode->Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto it = m_NodesToRemove.begin(); it != m_NodesToRemove.end(); it++) {
|
for (auto it = m_NodesToRemove.begin(); it != m_NodesToRemove.end(); it++) {
|
||||||
if ((*it) != nullptr) {
|
delete (*it);
|
||||||
delete (*it);
|
|
||||||
(*it) = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,92 +91,26 @@ void BlendTree::PrintTree()
|
|||||||
currentNode = currentNode->Next();
|
currentNode = currentNode->Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity)
|
||||||
|
|
||||||
void BlendTree::FillTree(Node* parentNode, EntityWrapper parentEntity, Skeleton* skeleton)
|
|
||||||
{
|
{
|
||||||
auto itPair = parentEntity.World->GetChildren(parentEntity.ID);
|
EntityWrapper childEntity = parentEntity.FirstChildByName(name); // Make first level child by name
|
||||||
if (itPair.first == itPair.second) {
|
|
||||||
return; // no children
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int childIndex = 0;
|
|
||||||
for (auto it = itPair.first; it != itPair.second; ++it) {
|
|
||||||
|
|
||||||
EntityWrapper childEntity = EntityWrapper(parentEntity.World, it->second);
|
|
||||||
|
|
||||||
if(!childEntity.Valid()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (childEntity.HasComponent("Animation")) {
|
|
||||||
const Skeleton::Animation* animation = skeleton->GetAnimation(childEntity["Animation"]["AnimationName"]);
|
|
||||||
if(animation == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Node* node = new Node();
|
|
||||||
node->Name = childEntity.Name();
|
|
||||||
node->Pose = skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]);
|
|
||||||
node->Parent = parentNode;
|
|
||||||
node->Type = NodeType::Animation;
|
|
||||||
parentNode->Child[childIndex] = node;
|
|
||||||
childIndex++;
|
|
||||||
FillTree(node, childEntity, skeleton);
|
|
||||||
|
|
||||||
} else if (childEntity.HasComponent("Blend")) {
|
|
||||||
Node* node = new Node();
|
|
||||||
node->Name = childEntity.Name();
|
|
||||||
node->Parent = parentNode;
|
|
||||||
node->Type = NodeType::Blend;
|
|
||||||
(double&)childEntity["Blend"]["Weight"] = glm::clamp((float)(double)childEntity["Blend"]["Weight"], 0.f, 1.f);
|
|
||||||
node->Weight = (double)childEntity["Blend"]["Weight"];
|
|
||||||
parentNode->Child[childIndex] = node;
|
|
||||||
childIndex++;
|
|
||||||
FillTree(node, childEntity, skeleton);
|
|
||||||
|
|
||||||
} else if (childEntity.HasComponent("BlendOverride")) {
|
|
||||||
Node* node = new Node();
|
|
||||||
node->Name = childEntity.Name();
|
|
||||||
node->Parent = parentNode;
|
|
||||||
node->Type = NodeType::Override;
|
|
||||||
parentNode->Child[childIndex] = node;
|
|
||||||
childIndex++;
|
|
||||||
FillTree(node, childEntity, skeleton);
|
|
||||||
|
|
||||||
} else if (childEntity.HasComponent("BlendAdditive")) {
|
|
||||||
Node* node = new Node();
|
|
||||||
node->Name = childEntity.Name();
|
|
||||||
node->Parent = parentNode;
|
|
||||||
node->Type = NodeType::Additive;
|
|
||||||
parentNode->Child[childIndex] = node;
|
|
||||||
childIndex++;
|
|
||||||
FillTree(node, childEntity, skeleton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity, Skeleton* skeleton)
|
|
||||||
{
|
|
||||||
EntityWrapper childEntity = parentEntity.FirstChildByName(name);
|
|
||||||
|
|
||||||
if (!childEntity.Valid()) {
|
if (!childEntity.Valid()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (childEntity.HasComponent("Animation")) {
|
if (childEntity.HasComponent("Animation")) {
|
||||||
const Skeleton::Animation* animation = skeleton->GetAnimation(childEntity["Animation"]["AnimationName"]);
|
const Skeleton::Animation* animation = m_Skeleton->GetAnimation(childEntity["Animation"]["AnimationName"]);
|
||||||
if (animation == nullptr) {
|
if (animation == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* node = new Node();
|
Node* node = new Node();
|
||||||
node->Name = childEntity.Name();
|
node->Name = childEntity.Name();
|
||||||
node->Pose = skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]);
|
node->Pose = m_Skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]);
|
||||||
node->Parent = parentNode;
|
node->Parent = parentNode;
|
||||||
node->Type = NodeType::Animation;
|
node->Type = NodeType::Animation;
|
||||||
return node;
|
return node;
|
||||||
@@ -186,31 +122,32 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
|
|||||||
node->Type = NodeType::Blend;
|
node->Type = NodeType::Blend;
|
||||||
(double&)childEntity["Blend"]["Weight"] = glm::clamp((float)(double)childEntity["Blend"]["Weight"], 0.f, 1.f);
|
(double&)childEntity["Blend"]["Weight"] = glm::clamp((float)(double)childEntity["Blend"]["Weight"], 0.f, 1.f);
|
||||||
node->Weight = (double)childEntity["Blend"]["Weight"];
|
node->Weight = (double)childEntity["Blend"]["Weight"];
|
||||||
node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity, skeleton);
|
node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity);
|
||||||
node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity, skeleton);
|
node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity);
|
||||||
return node;
|
return node;
|
||||||
} else if (childEntity.HasComponent("BlendOverride")) {
|
} else if (childEntity.HasComponent("BlendOverride")) {
|
||||||
Node* node = new Node();
|
Node* node = new Node();
|
||||||
node->Name = childEntity.Name();
|
node->Name = childEntity.Name();
|
||||||
node->Parent = parentNode;
|
node->Parent = parentNode;
|
||||||
node->Type = NodeType::Override;
|
node->Type = NodeType::Override;
|
||||||
node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Master"], childEntity, skeleton);
|
node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Master"], childEntity);
|
||||||
node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Slave"], childEntity, skeleton);
|
node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendOverride"]["Slave"], childEntity);
|
||||||
return node;
|
return node;
|
||||||
} else if (childEntity.HasComponent("BlendAdditive")) {
|
} else if (childEntity.HasComponent("BlendAdditive")) {
|
||||||
Node* node = new Node();
|
Node* node = new Node();
|
||||||
node->Name = childEntity.Name();
|
node->Name = childEntity.Name();
|
||||||
node->Parent = parentNode;
|
node->Parent = parentNode;
|
||||||
node->Type = NodeType::Additive;
|
node->Type = NodeType::Additive;
|
||||||
node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Adder"], childEntity, skeleton);
|
node->Child[0] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Adder"], childEntity);
|
||||||
node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Receiver"], childEntity, skeleton);
|
node->Child[1] = FillTreeByName(node, (std::string)childEntity["BlendAdditive"]["Receiver"], childEntity);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlendTree::Blend(Skeleton* skeleton, std::map<int, glm::mat4>& pose)
|
void BlendTree::Blend(std::map<int, glm::mat4>& pose)
|
||||||
{
|
{
|
||||||
Node* currentNode;
|
Node* currentNode;
|
||||||
Node* start = m_Root;
|
Node* start = m_Root;
|
||||||
@@ -219,7 +156,7 @@ void BlendTree::Blend(Skeleton* skeleton, std::map<int, glm::mat4>& pose)
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentNode = start;
|
currentNode = start;
|
||||||
LOG_INFO("\n\n");
|
|
||||||
while (m_Root->Pose.size() == 0) {
|
while (m_Root->Pose.size() == 0) {
|
||||||
if(currentNode->Pose.size() == 0) {
|
if(currentNode->Pose.size() == 0) {
|
||||||
if (currentNode->Child[0] != nullptr && currentNode->Child[1] != nullptr) {
|
if (currentNode->Child[0] != nullptr && currentNode->Child[1] != nullptr) {
|
||||||
@@ -227,20 +164,18 @@ void BlendTree::Blend(Skeleton* skeleton, std::map<int, glm::mat4>& pose)
|
|||||||
|
|
||||||
switch (currentNode->Type) {
|
switch (currentNode->Type) {
|
||||||
case BlendTree::NodeType::Additive:
|
case BlendTree::NodeType::Additive:
|
||||||
currentNode->Pose = skeleton->BlendPoseAdditive(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose);
|
currentNode->Pose = m_Skeleton->BlendPoseAdditive(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose);
|
||||||
break;
|
break;
|
||||||
case BlendTree::NodeType::Blend:
|
case BlendTree::NodeType::Blend:
|
||||||
currentNode->Pose = skeleton->BlendPoses(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose, currentNode->Weight);
|
currentNode->Pose = m_Skeleton->BlendPoses(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose, currentNode->Weight);
|
||||||
break;
|
break;
|
||||||
case BlendTree::NodeType::Override:
|
case BlendTree::NodeType::Override:
|
||||||
currentNode->Pose = skeleton->OverridePose(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose);
|
currentNode->Pose = m_Skeleton->OverridePose(currentNode->Child[0]->Pose, currentNode->Child[1]->Pose);
|
||||||
break;
|
break;
|
||||||
case BlendTree::NodeType::Animation:
|
case BlendTree::NodeType::Animation:
|
||||||
// do nothing
|
// do nothing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("Blending %s and %s", currentNode->Child[0]->Name.c_str(), currentNode->Child[1]->Name.c_str());
|
|
||||||
}
|
}
|
||||||
} else if (currentNode->Child[0] != nullptr) {
|
} else if (currentNode->Child[0] != nullptr) {
|
||||||
if (currentNode->Child[0]->Pose.size() != 0) {
|
if (currentNode->Child[0]->Pose.size() != 0) {
|
||||||
@@ -264,21 +199,21 @@ void BlendTree::Blend(Skeleton* skeleton, std::map<int, glm::mat4>& pose)
|
|||||||
pose = m_Root->Pose;
|
pose = m_Root->Pose;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<glm::mat4> BlendTree::GetBoneTransforms(Skeleton* skeleton)
|
std::vector<glm::mat4> BlendTree::AccumulateFinalPose()
|
||||||
{
|
{
|
||||||
std::vector<glm::mat4> finalPose;
|
std::vector<glm::mat4> finalPose;
|
||||||
if (skeleton == nullptr || m_Root == nullptr) {
|
if (m_Skeleton == nullptr || m_Root == nullptr) {
|
||||||
|
|
||||||
for (int i = 0; i < skeleton->Bones.size(); i++) {
|
for (int i = 0; i < m_Skeleton->Bones.size(); i++) {
|
||||||
finalPose.push_back(glm::mat4(1));
|
finalPose.push_back(glm::mat4(1));
|
||||||
}
|
}
|
||||||
return finalPose;
|
return finalPose;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, glm::mat4> pose;
|
std::map<int, glm::mat4> pose;
|
||||||
Blend(skeleton, pose);
|
Blend(pose);
|
||||||
|
|
||||||
finalPose = skeleton->GetFinalPose(pose);
|
finalPose = m_Skeleton->GetFinalPose(pose);
|
||||||
|
|
||||||
return finalPose;
|
return finalPose;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<::Skeleton::AnimationData> Animations;
|
/* std::vector<::Skeleton::AnimationData> Animations;
|
||||||
::Skeleton::AnimationOffset AnimationOffset;
|
::Skeleton::AnimationOffset AnimationOffset;
|
||||||
glm::mat4 boneTransform;
|
glm::mat4 boneTransform;
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
|
|||||||
glm::decompose(boneTransform, scale, rotation, translation, skew, perspective);
|
glm::decompose(boneTransform, scale, rotation, translation, skew, perspective);
|
||||||
|
|
||||||
glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation));
|
glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation));
|
||||||
/*
|
/ *
|
||||||
|
|
||||||
angles.y = asin(-boneTransform[0][2]);
|
angles.y = asin(-boneTransform[0][2]);
|
||||||
if (cos(angles.y) != 0) {
|
if (cos(angles.y) != 0) {
|
||||||
@@ -81,7 +81,7 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
|
|||||||
} else {
|
} else {
|
||||||
angles.x = atan2(-boneTransform[2][0], boneTransform[1][1]);
|
angles.x = atan2(-boneTransform[2][0], boneTransform[1][1]);
|
||||||
angles.z = 0;
|
angles.z = 0;
|
||||||
}*/
|
}* /
|
||||||
|
|
||||||
if ((bool)entity["BoneAttachment"]["InheritPosition"]) {
|
if ((bool)entity["BoneAttachment"]["InheritPosition"]) {
|
||||||
(glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
|
(glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
|
||||||
@@ -91,5 +91,5 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
|
|||||||
}
|
}
|
||||||
if ((bool)entity["BoneAttachment"]["InheritScale"]) {
|
if ((bool)entity["BoneAttachment"]["InheritScale"]) {
|
||||||
(glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"];
|
(glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"];
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,12 +338,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
|||||||
//bind textures
|
//bind textures
|
||||||
BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob);
|
BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob);
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/*if (explosionEffectJob->AnimationOffset.animation != nullptr) {
|
frameBones = explosionEffectJob->BlendTree->GetFinalPose();
|
||||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
} else {
|
} else {
|
||||||
m_ExplosionEffectProgram->Bind();
|
m_ExplosionEffectProgram->Bind();
|
||||||
@@ -366,12 +361,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
|||||||
BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob);
|
BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob);
|
||||||
GLERROR("asdasd");
|
GLERROR("asdasd");
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/*if (explosionEffectJob->AnimationOffset.animation != nullptr) {
|
frameBones = explosionEffectJob->BlendTree->GetFinalPose();
|
||||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -412,12 +402,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
|||||||
//bind textures
|
//bind textures
|
||||||
BindModelTextures(forwardSkinnedHandle, modelJob);
|
BindModelTextures(forwardSkinnedHandle, modelJob);
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/* if (modelJob->AnimationOffset.animation != nullptr) {
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = modelJob->BlendTree->GetBoneTransforms(modelJob->Skeleton);
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -441,12 +426,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
|||||||
BindModelTextures(forwardSplatMapSkinnedHandle, modelJob);
|
BindModelTextures(forwardSplatMapSkinnedHandle, modelJob);
|
||||||
GLERROR("asdasd");
|
GLERROR("asdasd");
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/* if (modelJob->AnimationOffset.animation != nullptr) {
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = modelJob->BlendTree->GetBoneTransforms(modelJob->Skeleton);
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -490,12 +470,7 @@ void DrawFinalPass::DrawShieldToStencilBuffer(std::list<std::shared_ptr<RenderJo
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/*if (modelJob->AnimationOffset.animation != nullptr) {
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
} else {
|
} else {
|
||||||
m_ShieldToStencilProgram->Bind();
|
m_ShieldToStencilProgram->Bind();
|
||||||
@@ -549,12 +524,7 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list<std::shared_ptr<Rende
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/* if (explosionEffectJob->AnimationOffset.animation != nullptr) {
|
frameBones = explosionEffectJob->BlendTree->GetFinalPose();
|
||||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|
||||||
if (GLERROR("Animation")) {
|
if (GLERROR("Animation")) {
|
||||||
@@ -589,12 +559,7 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list<std::shared_ptr<Rende
|
|||||||
BindModelTextures(forwardHandle ,modelJob);
|
BindModelTextures(forwardHandle ,modelJob);
|
||||||
|
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/* if (modelJob->AnimationOffset.animation != nullptr) {
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|
||||||
|
|
||||||
@@ -626,12 +591,7 @@ void DrawFinalPass::DrawToDepthBuffer(std::list<std::shared_ptr<RenderJob>>& job
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||||
|
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/*if (modelJob->AnimationOffset.animation != nullptr) {
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -103,12 +103,7 @@ void PickingPass::Draw(RenderScene& scene)
|
|||||||
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
|
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
|
||||||
|
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/*if (modelJob->AnimationOffset.animation != nullptr) {
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -161,12 +156,7 @@ void PickingPass::Draw(RenderScene& scene)
|
|||||||
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||||
|
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/* if (modelJob->AnimationOffset.animation != nullptr) {
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
} else {
|
} else {
|
||||||
m_PickingProgram->Bind();
|
m_PickingProgram->Bind();
|
||||||
@@ -217,12 +207,7 @@ void PickingPass::Draw(RenderScene& scene)
|
|||||||
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||||
|
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/* if (modelJob->AnimationOffset.animation != nullptr) {
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -279,12 +264,7 @@ void PickingPass::Draw(RenderScene& scene)
|
|||||||
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
|
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
|
||||||
|
|
||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
/*if (modelJob->AnimationOffset.animation != nullptr) {
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
|
||||||
} else {
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations);
|
|
||||||
}*/
|
|
||||||
frameBones = modelJob->Skeleton->GetFrameBones();
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,6 @@
|
|||||||
#include "Rendering/Skeleton.h"
|
#include "Rendering/Skeleton.h"
|
||||||
|
|
||||||
int Skeleton::CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix)
|
std::map<int, glm::mat4> Skeleton::GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion /*= false*/)
|
||||||
{
|
|
||||||
if (m_BonesByName.find(name) != m_BonesByName.end()) {
|
|
||||||
return m_BonesByName.at(name)->ID;
|
|
||||||
} else {
|
|
||||||
Bone* bone;
|
|
||||||
|
|
||||||
if (parentID == -1) {
|
|
||||||
bone = new Bone(ID, nullptr, name, offsetMatrix);
|
|
||||||
RootBone = bone;
|
|
||||||
} else {
|
|
||||||
Bone* parent = Bones[parentID];
|
|
||||||
bone = new Bone(ID, parent, name, offsetMatrix);
|
|
||||||
parent->Children.push_back(bone);
|
|
||||||
}
|
|
||||||
|
|
||||||
Bones[ID] = bone;
|
|
||||||
m_BonesByName[name] = bone;
|
|
||||||
return ID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Skeleton::~Skeleton()
|
|
||||||
{
|
|
||||||
for (auto &kv : Bones) {
|
|
||||||
delete kv.second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Skeleton::Animation* Skeleton::GetAnimation(std::string name)
|
|
||||||
{
|
|
||||||
auto it = Animations.find(name);
|
|
||||||
if (it != Animations.end()) {
|
|
||||||
return const_cast<const Animation*>(&it->second);
|
|
||||||
} else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<glm::mat4> Skeleton::GetFrameBones()
|
|
||||||
{
|
|
||||||
std::vector<glm::mat4> finalMatrices;
|
|
||||||
for (auto& b : Bones) {
|
|
||||||
finalMatrices.push_back(glm::mat4(1));
|
|
||||||
}
|
|
||||||
return finalMatrices;
|
|
||||||
}
|
|
||||||
std::map<int, glm::mat4> Skeleton::GetFrameBones(const Animation* animation, const double time, bool additive, bool noRootMotion /*= false*/)
|
|
||||||
{
|
{
|
||||||
if (animation == nullptr) {
|
if (animation == nullptr) {
|
||||||
std::map<int, glm::mat4> finalMatrices;
|
std::map<int, glm::mat4> finalMatrices;
|
||||||
@@ -63,7 +14,7 @@ std::map<int, glm::mat4> Skeleton::GetFrameBones(const Animation* animation, con
|
|||||||
std::map<int, glm::mat4> frameBones;
|
std::map<int, glm::mat4> frameBones;
|
||||||
|
|
||||||
if(!additive) {
|
if(!additive) {
|
||||||
AccumulateBoneTransforms(true, animation, time, frameBones, additive, RootBone, glm::mat4(1));
|
AccumulateBoneTransforms(true, animation, time, frameBones, RootBone, glm::mat4(1));
|
||||||
} else {
|
} else {
|
||||||
AdditiveBoneTransforms(animation, time, frameBones, RootBone);
|
AdditiveBoneTransforms(animation, time, frameBones, RootBone);
|
||||||
}
|
}
|
||||||
@@ -71,12 +22,8 @@ std::map<int, glm::mat4> Skeleton::GetFrameBones(const Animation* animation, con
|
|||||||
return frameBones;
|
return frameBones;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map<int, glm::mat4>& boneMatrices, bool additive, const Bone* bone, glm::mat4 parentMatrix)
|
void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* animation, double time, std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix)
|
||||||
{
|
{
|
||||||
if (additive) {
|
|
||||||
time += 1.0/60.0; // first frame is a reference frame
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::mat4 boneMatrix;
|
glm::mat4 boneMatrix;
|
||||||
|
|
||||||
|
|
||||||
@@ -138,7 +85,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto &child : bone->Children) {
|
for (auto &child : bone->Children) {
|
||||||
AccumulateBoneTransforms(noRootMotion, animation, time, boneMatrices, additive, child, boneMatrix);
|
AccumulateBoneTransforms(noRootMotion, animation, time, boneMatrices, child, boneMatrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,20 +104,6 @@ void Skeleton::AdditiveBoneTransforms(const Animation* animation, double time, s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 Skeleton::AdditiveBlend(const Bone* bone, AnimationOffset animationOffset, glm::mat4 targetPose)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
AnimationOffset refOffset = animationOffset;
|
|
||||||
refOffset.time = 0.5f; // reference pose is at 0.5s for now
|
|
||||||
glm::mat4 refPose = GetAdditiveBonePose(bone, refOffset);
|
|
||||||
glm::mat4 srcPose = GetAdditiveBonePose(bone, animationOffset);
|
|
||||||
glm::mat4 differencePose = srcPose * glm::inverse(refPose);
|
|
||||||
glm::mat4 finalPose = differencePose * targetPose;*/
|
|
||||||
return glm::mat4();
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::mat4 Skeleton::GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time)
|
glm::mat4 Skeleton::GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time)
|
||||||
{
|
{
|
||||||
glm::vec3 position = glm::vec3(0);
|
glm::vec3 position = glm::vec3(0);
|
||||||
@@ -227,9 +160,6 @@ glm::mat4 Skeleton::GetBonePose(const Bone* bone, const Animation* animation, do
|
|||||||
{
|
{
|
||||||
glm::mat4 boneMatrix;
|
glm::mat4 boneMatrix;
|
||||||
|
|
||||||
std::vector<JointFramePose> JointPoses;
|
|
||||||
|
|
||||||
|
|
||||||
if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) {
|
if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) {
|
||||||
std::vector<Animation::Keyframe> boneKeyFrames = animation->JointAnimations.at(bone->ID);
|
std::vector<Animation::Keyframe> boneKeyFrames = animation->JointAnimations.at(bone->ID);
|
||||||
|
|
||||||
@@ -346,235 +276,7 @@ glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animatio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector<AnimationData> animations, AnimationOffset animationOffset, glm::mat4 childMatrix)
|
std::map<int, glm::mat4> Skeleton::BlendPoses(const std::map<int, glm::mat4>& pose1, const std::map<int, glm::mat4>& pose2, float weight)
|
||||||
{
|
|
||||||
glm::mat4 boneMatrix;
|
|
||||||
|
|
||||||
std::vector<JointFramePose> JointPoses;
|
|
||||||
|
|
||||||
for (const AnimationData animationData : animations) {
|
|
||||||
const Animation* animation = animationData.animation;
|
|
||||||
const float time = animationData.time;
|
|
||||||
|
|
||||||
JointFramePose jointPose;
|
|
||||||
jointPose.Weight = animationData.weight;;
|
|
||||||
|
|
||||||
if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) {
|
|
||||||
std::vector<Animation::Keyframe> boneKeyFrames = animation->JointAnimations.at(bone->ID);
|
|
||||||
|
|
||||||
Animation::Keyframe currentFrame;
|
|
||||||
Animation::Keyframe nextFrame;
|
|
||||||
|
|
||||||
if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone
|
|
||||||
for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame
|
|
||||||
if (time >= boneKeyFrames.at(index).Time) {
|
|
||||||
currentFrame = boneKeyFrames.at(index);
|
|
||||||
nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float progress;
|
|
||||||
|
|
||||||
if (nextFrame.Index == 0) {
|
|
||||||
nextFrame = currentFrame;
|
|
||||||
progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time);
|
|
||||||
} else {
|
|
||||||
progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (progress > 1.0f || progress < 0.0f) {
|
|
||||||
progress = glm::clamp(progress, 0.0f, 1.0f);
|
|
||||||
}
|
|
||||||
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties;
|
|
||||||
Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties;
|
|
||||||
|
|
||||||
glm::vec3 position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress;
|
|
||||||
glm::quat rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress);
|
|
||||||
glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress;
|
|
||||||
|
|
||||||
// Flag for no root motion
|
|
||||||
if (bone == RootBone && noRootMotion) {
|
|
||||||
position.x = 0;
|
|
||||||
position.z = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
jointPose.Pose = (glm::translate(position) * glm::toMat4(rotation) * glm::scale(scale));
|
|
||||||
JointPoses.push_back(jointPose);
|
|
||||||
|
|
||||||
} else { // 1 keyframes for the current bone
|
|
||||||
currentFrame = boneKeyFrames.at(0);
|
|
||||||
jointPose.Pose = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale));
|
|
||||||
JointPoses.push_back(jointPose);
|
|
||||||
}
|
|
||||||
} else { // 0 keyframes for the current bone
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (JointPoses.size() == 0) {
|
|
||||||
if (bone->Parent) {
|
|
||||||
|
|
||||||
glm::mat4 jointPose = (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix);
|
|
||||||
glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, jointPose);
|
|
||||||
|
|
||||||
boneMatrix = boneTransform * childMatrix;
|
|
||||||
} else {
|
|
||||||
boneMatrix = glm::inverse(bone->OffsetMatrix) * childMatrix;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
float totalWeight = 0;
|
|
||||||
|
|
||||||
for (JointFramePose jointFramePose : JointPoses) {
|
|
||||||
totalWeight += jointFramePose.Weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::mat4 finalBlend = glm::mat4(0);
|
|
||||||
|
|
||||||
for (JointFramePose jointFramePose : JointPoses) {
|
|
||||||
if (jointFramePose.Weight == 1.0f) {
|
|
||||||
finalBlend = jointFramePose.Pose;
|
|
||||||
} else {
|
|
||||||
finalBlend += jointFramePose.Pose * (jointFramePose.Weight / totalWeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 boneTransform = AdditiveBlend(bone, animationOffset, finalBlend);
|
|
||||||
boneMatrix = boneTransform * childMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bone->Parent != nullptr) {
|
|
||||||
return GetBoneTransform(noRootMotion, bone->Parent, animations, animationOffset, boneMatrix);
|
|
||||||
} else {
|
|
||||||
return boneMatrix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::mat4 Skeleton::GetBoneTransform(bool noRootMotion, const Bone* bone, std::vector<AnimationData> animations, glm::mat4 childMatrix)
|
|
||||||
{
|
|
||||||
glm::mat4 boneMatrix;
|
|
||||||
/* std::vector<JointFrameTransform> JointTransforms;
|
|
||||||
|
|
||||||
for (const AnimationData animationData : animations) {
|
|
||||||
const Animation* animation = animationData.animation;
|
|
||||||
const float time = animationData.time;
|
|
||||||
|
|
||||||
JointFrameTransform jointTransform;
|
|
||||||
jointTransform.Weight = animationData.weight;;
|
|
||||||
|
|
||||||
if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) {
|
|
||||||
std::vector<Animation::Keyframe> boneKeyFrames = animation->JointAnimations.at(bone->ID);
|
|
||||||
|
|
||||||
Animation::Keyframe currentFrame;
|
|
||||||
Animation::Keyframe nextFrame;
|
|
||||||
|
|
||||||
if (boneKeyFrames.size() > 1) { // 2+ keyframes for the current bone
|
|
||||||
for (int index = boneKeyFrames.size()-1; index >= 0; index--) { // find the bone keyframes that surrounds the current frame
|
|
||||||
if (time >= boneKeyFrames.at(index).Time) {
|
|
||||||
currentFrame = boneKeyFrames.at(index);
|
|
||||||
nextFrame = boneKeyFrames.at((index + 1) % boneKeyFrames.size());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float progress;
|
|
||||||
|
|
||||||
if (nextFrame.Index == 0) {
|
|
||||||
nextFrame = currentFrame;
|
|
||||||
progress = (time - currentFrame.Time) / (animation->Duration - currentFrame.Time);
|
|
||||||
} else {
|
|
||||||
progress = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (progress > 1.0f || progress < 0.0f) {
|
|
||||||
progress = glm::clamp(progress, 0.0f, 1.0f);
|
|
||||||
}
|
|
||||||
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties;
|
|
||||||
Animation::Keyframe::BoneProperty nextBoneProperty = nextFrame.BoneProperties;
|
|
||||||
|
|
||||||
jointTransform.Position = currentBoneProperty.Position * (1.f - progress) + nextBoneProperty.Position * progress;
|
|
||||||
jointTransform.Rotation = glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress);
|
|
||||||
jointTransform.Scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress;
|
|
||||||
|
|
||||||
// Flag for no root motion
|
|
||||||
if (bone == RootBone && noRootMotion) {
|
|
||||||
jointTransform.Position.x = 0;
|
|
||||||
jointTransform.Position.z = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
JointTransforms.push_back(jointTransform);
|
|
||||||
|
|
||||||
} else { // 1 keyframes for the current bone
|
|
||||||
currentFrame = boneKeyFrames.at(0);
|
|
||||||
jointTransform.Position = currentFrame.BoneProperties.Position;
|
|
||||||
jointTransform.Rotation = currentFrame.BoneProperties.Rotation;
|
|
||||||
jointTransform.Scale = currentFrame.BoneProperties.Scale;
|
|
||||||
JointTransforms.push_back(jointTransform);
|
|
||||||
|
|
||||||
}
|
|
||||||
} else { // 0 keyframes for the current bone
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (JointTransforms.size() <= 0) {
|
|
||||||
if (bone->Parent) {
|
|
||||||
boneMatrix = glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix * childMatrix;
|
|
||||||
} else {
|
|
||||||
boneMatrix = glm::inverse(bone->OffsetMatrix) * childMatrix;
|
|
||||||
}
|
|
||||||
} else if (JointTransforms.size() == 1) {
|
|
||||||
boneMatrix = (glm::translate(JointTransforms.at(0).Position) * glm::toMat4(JointTransforms.at(0).Rotation) * glm::scale(JointTransforms.at(0).Scale)) * childMatrix;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
glm::vec3 finalPosInterp;
|
|
||||||
glm::quat finalRotInterp;
|
|
||||||
glm::vec3 finalScaleInterp;
|
|
||||||
float totalWeight = 0;
|
|
||||||
|
|
||||||
for (JointFrameTransform jointTransform : JointTransforms) {
|
|
||||||
totalWeight += jointTransform.Weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (JointFrameTransform jointTransform : JointTransforms) {
|
|
||||||
if (jointTransform.Weight == 1.0f) {
|
|
||||||
finalPosInterp = jointTransform.Position;
|
|
||||||
finalRotInterp = jointTransform.Rotation;
|
|
||||||
finalScaleInterp = jointTransform.Scale;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
finalPosInterp += jointTransform.Position * (jointTransform.Weight/totalWeight);
|
|
||||||
finalRotInterp *= glm::slerp(glm::quat(), jointTransform.Rotation, (jointTransform.Weight/totalWeight));
|
|
||||||
finalScaleInterp += jointTransform.Scale * (jointTransform.Weight/totalWeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
boneMatrix = (glm::translate(finalPosInterp) * glm::toMat4(finalRotInterp) * glm::scale(finalScaleInterp)) * childMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (bone->Parent != nullptr) {
|
|
||||||
return GetBoneTransform(noRootMotion, bone->Parent, animations, boneMatrix);
|
|
||||||
} else {
|
|
||||||
return boneMatrix;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return boneMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::map<int, glm::mat4> Skeleton::BlendPoses(std::map<int, glm::mat4> pose1, std::map<int, glm::mat4> pose2, float weight)
|
|
||||||
{
|
{
|
||||||
std::map<int, glm::mat4> finalPose;
|
std::map<int, glm::mat4> finalPose;
|
||||||
|
|
||||||
@@ -596,8 +298,7 @@ std::map<int, glm::mat4> Skeleton::BlendPoses(std::map<int, glm::mat4> pose1, st
|
|||||||
return finalPose;
|
return finalPose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<int, glm::mat4> Skeleton::OverridePose(const std::map<int, glm::mat4>& overridePose, const std::map<int, glm::mat4>& targetPose)
|
||||||
std::map<int, glm::mat4> Skeleton::OverridePose(std::map<int, glm::mat4> overridePose, std::map<int, glm::mat4> targetPose)
|
|
||||||
{
|
{
|
||||||
std::map<int, glm::mat4> finalPose;
|
std::map<int, glm::mat4> finalPose;
|
||||||
|
|
||||||
@@ -612,8 +313,7 @@ std::map<int, glm::mat4> Skeleton::OverridePose(std::map<int, glm::mat4> overrid
|
|||||||
return finalPose;
|
return finalPose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<int, glm::mat4> Skeleton::BlendPoseAdditive(const std::map<int, glm::mat4>& additivePose, const std::map<int, glm::mat4>& targetPose)
|
||||||
std::map<int, glm::mat4> Skeleton::BlendPoseAdditive(std::map<int, glm::mat4> additivePose, std::map<int, glm::mat4> targetPose)
|
|
||||||
{
|
{
|
||||||
std::map<int, glm::mat4> finalPose;
|
std::map<int, glm::mat4> finalPose;
|
||||||
|
|
||||||
@@ -683,3 +383,42 @@ int Skeleton::GetBoneID(std::string name)
|
|||||||
return m_BonesByName.at(name)->ID;
|
return m_BonesByName.at(name)->ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Skeleton::CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix)
|
||||||
|
{
|
||||||
|
if (m_BonesByName.find(name) != m_BonesByName.end()) {
|
||||||
|
return m_BonesByName.at(name)->ID;
|
||||||
|
} else {
|
||||||
|
Bone* bone;
|
||||||
|
|
||||||
|
if (parentID == -1) {
|
||||||
|
bone = new Bone(ID, nullptr, name, offsetMatrix);
|
||||||
|
RootBone = bone;
|
||||||
|
} else {
|
||||||
|
Bone* parent = Bones[parentID];
|
||||||
|
bone = new Bone(ID, parent, name, offsetMatrix);
|
||||||
|
parent->Children.push_back(bone);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bones[ID] = bone;
|
||||||
|
m_BonesByName[name] = bone;
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Skeleton::~Skeleton()
|
||||||
|
{
|
||||||
|
for (auto &kv : Bones) {
|
||||||
|
delete kv.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Skeleton::Animation* Skeleton::GetAnimation(std::string name)
|
||||||
|
{
|
||||||
|
auto it = Animations.find(name);
|
||||||
|
if (it != Animations.end()) {
|
||||||
|
return const_cast<const Animation*>(&it->second);
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user