AutoAnimationBlend on unique node working but scale is not working correctly

This commit is contained in:
viktorljung
2016-03-02 13:30:04 +01:00
parent 5bc0483f49
commit 07ccb9c041
13 changed files with 1404 additions and 749 deletions
+51 -3
View File
@@ -3,13 +3,19 @@
#include "GLM.h"
#include "Common.h"
#include "Core/System.h"
#include "Core/ResourceManager.h"
#include "../Common.h"
#include "../Core/System.h"
#include "../Core/ResourceManager.h"
#include "Rendering/Model.h"
#include "Rendering/EAnimationComplete.h"
#include "Rendering/Skeleton.h"
#include "Rendering/BlendTree.h"
#include "Rendering/EAnimationBlend.h"
#include "Rendering/EAutoAnimationBlend.h"
#include "../Input/EInputCommand.h"
#include "../Core/EntityWrapper.h"
#include "imgui/imgui.h"
class AnimationSystem : public ImpureSystem
{
@@ -20,7 +26,49 @@ public:
private:
void CreateBlendTrees();
void UpdateAnimations(double dt);
void UpdateWeights(double dt);
void AnimationComplete(EntityWrapper animationEntity);
EventRelay<AnimationSystem, Events::AnimationBlend> m_EAnimationBlend;
bool OnAnimationBlend(Events::AnimationBlend& e);
EventRelay<AnimationSystem, Events::AutoAnimationBlend> m_EAutoAnimationBlend;
bool OnAutoAnimationBlend(Events::AutoAnimationBlend& e);
EventRelay<AnimationSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
struct BlendJob
{
EntityWrapper BlendEntity = EntityWrapper::Invalid;
double StartWeight;
double GoalWeight;
double Duration;
double CurrentTime = 0.0;
};
struct QueuedBlendJob : BlendJob
{
EntityWrapper AnimationEntity = EntityWrapper::Invalid;
};
struct AutoBlendJob
{
EntityWrapper RootNode = EntityWrapper::Invalid;
double Duration;
double CurrentTime = 0.0;
BlendTree::AutoBlendInfo BlendInfo;
};
std::list<AutoBlendJob> m_AutoBlendJobs;
std::list<BlendJob> m_BlendJobs;
std::list<QueuedBlendJob> m_QueuedBlendJobs;
char m_AnimationName1[20] = "Run";
float m_BlendTime1 = 0.5f;
char m_AnimationName2[20] = "Jump";
float m_BlendTime2 = 0.5f;
};
#endif
+10 -2
View File
@@ -23,12 +23,13 @@ public:
struct Node
{
std::string Name;
EntityWrapper Entity;
Node* Parent = nullptr;
Node* Child[2] = { nullptr, nullptr };
NodeType Type;
std::map<int, glm::mat4> Pose;
//std::vector<glm::mat4> Pose;
float Weight = 0.f;
double Weight = 0.0;
Node* Next() {
Node* next = this;
@@ -54,7 +55,12 @@ public:
};
struct AutoBlendInfo
{
std::string NodeName;
double progress;
std::unordered_map<EntityWrapper, double> StartWeights;
};
BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton);
@@ -66,6 +72,7 @@ public:
bool IsValid() { return (m_Root == nullptr ? false : true); }
void PrintTree();
BlendTree::AutoBlendInfo AutoBlendStep(AutoBlendInfo blendInfo);
private:
Skeleton* m_Skeleton = nullptr;
@@ -76,6 +83,7 @@ private:
std::vector<glm::mat4> AccumulateFinalPose();
BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity);
std::vector<BlendTree::Node*> FindNodesByName(std::string name);
void Blend(std::map<int, glm::mat4>& pose);
};
@@ -0,0 +1,21 @@
#ifndef Events_AnimationBlend_h__
#define Events_AnimationBlend_h__
#include "../Core/EventBroker.h"
#include "../Core/EntityWrapper.h"
namespace Events
{
struct AnimationBlend : Event
{
EntityWrapper BlendEntity = EntityWrapper::Invalid;
double GoalWeight;
double Duration;
EntityWrapper AnimationEntity = EntityWrapper::Invalid;
};
}
#endif
@@ -0,0 +1,21 @@
#ifndef Events_AutoAnimationBlend_h__
#define Events_AutoAnimationBlend_h__
#include "../Core/EventBroker.h"
#include "../Core/EntityWrapper.h"
namespace Events
{
struct AutoAnimationBlend : Event
{
EntityWrapper RootNode = EntityWrapper::Invalid;
std::string NodeName;
double Duration;
EntityWrapper AnimationEntity = EntityWrapper::Invalid;
};
}
#endif
+1 -1
View File
@@ -67,7 +67,7 @@ public:
std::map<int, glm::mat4> GetFrameBones(const Animation* animation, double time, bool additive, bool noRootMotion = false);
glm::mat4 GetBoneTransform(const Bone* bone, const Animation* animation, float time, 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);
std::map<int, glm::mat4> BlendPoses(const std::map<int, glm::mat4>& pose1, const std::map<int, glm::mat4>& pose2, double weight);
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);
void GetFinalPose(std::map<int, glm::mat4>& boneMatrices, std::vector<glm::mat4>& finalPose, std::map<int, glm::mat4>& boneTransforms);
File diff suppressed because it is too large Load Diff
+130 -103
View File
@@ -18,9 +18,9 @@
<Transparent>true</Transparent>
</c:Model>
<c:Transform>
<Position X="0.47420007" Y="0.928898275" Z="0.0299553983"/>
<Position X="0.155832842" Y="1.12994993" Z="-0.201626897"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.100000001"/>
<Orientation X="1.60548508" Y="-1.10789871" Z="-1.51772225"/>
<Orientation X="0.195066273" Y="-0.0870126858" Z="0.148657113"/>
</c:Transform>
</Components>
<Children/>
@@ -29,16 +29,17 @@
<Components>
<c:BoneAttachment>
<BoneName>R_Hand</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.448672563" Y="0.992614031" Z="0.0575723015"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="1.60548508" Y="-1.10789871" Z="-1.51772225"/>
<Position X="0.202149346" Y="1.12270021" Z="-0.144635201"/>
<Scale X="0.0500000231" Y="0.0500000305" Z="0.0500000119"/>
<Orientation X="1.41306889" Y="0.0776072815" Z="-0.744222522"/>
</c:Transform>
</Components>
<Children/>
@@ -47,16 +48,17 @@
<Components>
<c:BoneAttachment>
<BoneName>R_Arm</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.12972948" Y="1.28044498" Z="-0.0855199769"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.178462029" Y="-0.240202308" Z="-0.227051333"/>
<Position X="0.0609518476" Y="1.16432548" Z="0.0783129707"/>
<Scale X="0.0500000194" Y="0.0500000082" Z="0.0500000194"/>
<Orientation X="0.311971247" Y="0.199406415" Z="0.162320927"/>
</c:Transform>
</Components>
<Children/>
@@ -65,16 +67,17 @@
<Components>
<c:BoneAttachment>
<BoneName>R_Shoulder</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.0566707924" Y="1.22090316" Z="-0.110467494"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.798247218" Y="0.000491484476" Z="-0.00077928009"/>
<Position X="0.0742288083" Y="1.12503755" Z="-0.00992172211"/>
<Scale X="0.0500000119" Y="0.0500000082" Z="0.0500000119"/>
<Orientation X="-0.295679808" Y="-1.03809071" Z="-0.158694059"/>
</c:Transform>
</Components>
<Children/>
@@ -83,16 +86,17 @@
<Components>
<c:BoneAttachment>
<BoneName>Neck</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="19.6078434"/>
</c:Model>
<c:Transform>
<Position X="6.88049477e-05" Y="1.29971886" Z="-0.151777163"/>
<Scale X="0.0500000007" Y="0.100000001" Z="0.0500000007"/>
<Orientation X="-1.03466523" Y="-0.0017389874" Z="0.00627749134"/>
<Position X="0.0288712904" Y="1.20688999" Z="-0.0585537553"/>
<Scale X="0.0500000194" Y="0.0500000082" Z="0.0500000082"/>
<Orientation X="-0.0778672397" Y="-0.380205482" Z="-0.116210334"/>
</c:Transform>
</Components>
<Children/>
@@ -101,16 +105,17 @@
<Components>
<c:BoneAttachment>
<BoneName>Spine_3</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="19.6078434"/>
</c:Model>
<c:Transform>
<Position X="-0.000299328996" Y="1.2487011" Z="-0.0936965123"/>
<Scale X="0.0500000007" Y="0.100000001" Z="0.0500000007"/>
<Orientation X="-0.798247218" Y="0.000491484476" Z="-0.00077928009"/>
<Position X="0.0190485716" Y="1.13146138" Z="-0.0447565243"/>
<Scale X="0.0500000119" Y="0.0500000082" Z="0.0500000119"/>
<Orientation X="-0.295679808" Y="-1.03809071" Z="-0.158694059"/>
</c:Transform>
</Components>
<Children/>
@@ -119,16 +124,17 @@
<Components>
<c:BoneAttachment>
<BoneName>Spine_2</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="19.6078434"/>
</c:Model>
<c:Transform>
<Position X="-0.000528411241" Y="1.1669693" Z="0.000368326902"/>
<Scale X="0.0500000007" Y="0.100000001" Z="0.0500000007"/>
<Orientation X="-0.798247218" Y="0.000491484476" Z="-0.00077928009"/>
<Position X="0.00282198261" Y="1.01004541" Z="-0.0218831152"/>
<Scale X="0.0500000119" Y="0.0500000082" Z="0.0500000119"/>
<Orientation X="-0.295679808" Y="-1.03809071" Z="-0.158694059"/>
</c:Transform>
</Components>
<Children/>
@@ -137,16 +143,17 @@
<Components>
<c:BoneAttachment>
<BoneName>Spine_1</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="19.6078434"/>
</c:Model>
<c:Transform>
<Position X="-0.000317580998" Y="1.03476369" Z="7.06899816e-17"/>
<Scale X="0.0500000007" Y="0.100000001" Z="0.0500000007"/>
<Orientation X="-0.168994248" Y="-0.000270629855" Z="-6.74916964e-06"/>
<Position X="-0.00298201409" Y="0.878305078" Z="-0.0124331526"/>
<Scale X="0.0500000082" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.478212297" Y="-1.01566339" Z="-0.374480605"/>
</c:Transform>
</Components>
<Children/>
@@ -155,15 +162,17 @@
<Components>
<c:BoneAttachment>
<BoneName>Hip</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="19.6078434"/>
</c:Model>
<c:Transform>
<Position X="0" Y="0.901226044" Z="0"/>
<Scale X="0.100000001" Y="0.0500000007" Z="0.0500000007"/>
<Position X="0" Y="0.745380521" Z="0"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.0850669593" Y="-0.351720452" Z="0.0214110892"/>
</c:Transform>
</Components>
<Children/>
@@ -172,16 +181,17 @@
<Components>
<c:BoneAttachment>
<BoneName>L_Leg_Top</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.0735318959" Y="0.86343354" Z="0.00186898722"/>
<Position X="-0.0688988566" Y="0.704185605" Z="-0.0198653266"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="0.431212306" Y="-0.0456388369" Z="-0.00236316444"/>
<Orientation X="-0.124463096" Y="0.178934589" Z="0.0281526987"/>
</c:Transform>
</Components>
<Children/>
@@ -190,16 +200,17 @@
<Components>
<c:BoneAttachment>
<BoneName>L_Leg_Bottom</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.0971027464" Y="0.534537971" Z="-0.158307418"/>
<Position X="-0.0895988718" Y="0.340622783" Z="0.022300493"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.435873091" Y="0.0584642813" Z="-0.0526505522"/>
<Orientation X="-0.634849846" Y="0.204822823" Z="0.0869619399"/>
</c:Transform>
</Components>
<Children/>
@@ -208,16 +219,17 @@
<Components>
<c:BoneAttachment>
<BoneName>L_Foot</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.136750847" Y="0.215778053" Z="0.0181705151"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-7.45058151e-06" Y="-4.34406102e-05" Z="-2.32085604e-05"/>
<Position X="-0.0861766189" Y="0.0597670376" Z="0.257741988"/>
<Scale X="0.0500000082" Y="0.0500000007" Z="0.0500000082"/>
<Orientation X="-0.185180262" Y="-0.00943047088" Z="-0.00198192359"/>
</c:Transform>
</Components>
<Children/>
@@ -226,16 +238,17 @@
<Components>
<c:BoneAttachment>
<BoneName>L_Toe</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.142155826" Y="0.180158257" Z="-0.171162993"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-7.45058151e-06" Y="-4.34406102e-05" Z="-2.32085604e-05"/>
<Position X="-0.0898738578" Y="-0.0101006478" Z="0.078159079"/>
<Scale X="0.0500000082" Y="0.0500000007" Z="0.0500000082"/>
<Orientation X="-0.185180262" Y="-0.00943047088" Z="-0.00198192359"/>
</c:Transform>
</Components>
<Children/>
@@ -244,16 +257,17 @@
<Components>
<c:BoneAttachment>
<BoneName>L_Shoulder</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.0569540039" Y="1.22099173" Z="-0.110411651"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.798247218" Y="0.000491484476" Z="-0.00077928009"/>
<Position X="0.0172477104" Y="1.11405122" Z="-0.107610352"/>
<Scale X="0.0500000119" Y="0.0500000082" Z="0.0500000119"/>
<Orientation X="-0.295679808" Y="-1.03809071" Z="-0.158694059"/>
</c:Transform>
</Components>
<Children/>
@@ -262,16 +276,17 @@
<Components>
<c:BoneAttachment>
<BoneName>L_Arm</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.129911453" Y="1.28064728" Z="-0.0853923708"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="0.558630228" Y="-0.558619261" Z="-0.988305748"/>
<Position X="-0.0692541152" Y="1.13922095" Z="-0.14491269"/>
<Scale X="0.0500000194" Y="0.0500000194" Z="0.0500000231"/>
<Orientation X="1.49024689" Y="-0.866028547" Z="1.11317146"/>
</c:Transform>
</Components>
<Children/>
@@ -280,16 +295,17 @@
<Components>
<c:BoneAttachment>
<BoneName>L_Hand</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.454215586" Y="1.41859245" Z="-0.370613039"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.931911349" Y="4.81306633e-05" Z="0.000111658264"/>
<Position X="0.100635156" Y="1.17628682" Z="-0.439798951"/>
<Scale X="0.0500000231" Y="0.0500000305" Z="0.050000038"/>
<Orientation X="0.026293885" Y="-0.262760967" Z="2.338521"/>
</c:Transform>
</Components>
<Children/>
@@ -298,16 +314,17 @@
<Components>
<c:BoneAttachment>
<BoneName>L_Shoulder_Armor_Joint</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.138541639" Y="1.30872273" Z="-0.144261822"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.798247218" Y="0.000491484476" Z="-0.00077928009"/>
<Position X="-0.0505402647" Y="1.1960609" Z="-0.172250509"/>
<Scale X="0.0500000194" Y="0.0500000119" Z="0.0500000119"/>
<Orientation X="-0.295679778" Y="-1.03809094" Z="-0.506270111"/>
</c:Transform>
</Components>
<Children/>
@@ -316,16 +333,17 @@
<Components>
<c:BoneAttachment>
<BoneName>Chin</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="19.6078434"/>
</c:Model>
<c:Transform>
<Position X="-0.00033863826" Y="1.2016536" Z="-0.251047492"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.931916714" Y="-9.67644155e-07" Z="2.18351502e-07"/>
<Position X="0.0539259352" Y="1.22412896" Z="-0.183897316"/>
<Scale X="0.0500000119" Y="0.0500000082" Z="0.0500000082"/>
<Orientation X="-0.0481163412" Y="-0.134963214" Z="-0.102023236"/>
</c:Transform>
</Components>
<Children/>
@@ -334,16 +352,17 @@
<Components>
<c:BoneAttachment>
<BoneName>Head</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="19.6078434"/>
</c:Model>
<c:Transform>
<Position X="-0.000338668207" Y="1.33565879" Z="-0.254856527"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.931916714" Y="-9.67644155e-07" Z="2.18351502e-07"/>
<Position X="0.0481297895" Y="1.31164014" Z="-0.0825063139"/>
<Scale X="0.0500000119" Y="0.0500000082" Z="0.0500000082"/>
<Orientation X="-0.0481163412" Y="-0.134963214" Z="-0.102023236"/>
</c:Transform>
</Components>
<Children/>
@@ -352,16 +371,17 @@
<Components>
<c:BoneAttachment>
<BoneName>Perietal</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="19.6078434"/>
</c:Model>
<c:Transform>
<Position X="-0.000338537793" Y="1.43159795" Z="-0.410463303"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.931916714" Y="-9.67644155e-07" Z="2.18351502e-07"/>
<Position X="0.0686318353" Y="1.49197555" Z="-0.104337469"/>
<Scale X="0.0500000119" Y="0.0500000082" Z="0.0500000082"/>
<Orientation X="-0.0481163412" Y="-0.134963214" Z="-0.102023236"/>
</c:Transform>
</Components>
<Children/>
@@ -370,16 +390,17 @@
<Components>
<c:BoneAttachment>
<BoneName>L_Elbow</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.312942117" Y="1.35850036" Z="-0.246365055"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="0.353978485" Y="-0.15571253" Z="-0.903516531"/>
<Position X="-0.0776530653" Y="1.10232043" Z="-0.397976696"/>
<Scale X="0.0500000231" Y="0.0500000231" Z="0.0500000231"/>
<Orientation X="2.36848879" Y="-0.278962672" Z="2.07910991"/>
</c:Transform>
</Components>
<Children/>
@@ -388,16 +409,17 @@
<Components>
<c:BoneAttachment>
<BoneName>R_Leg_Bottom</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.105701312" Y="0.499459773" Z="0.030466903"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-1.02907228" Y="-0.0580535792" Z="0.116703011"/>
<Position X="0.115077674" Y="0.503088951" Z="-0.267230242"/>
<Scale X="0.0500000007" Y="0.0499999933" Z="0.049999997"/>
<Orientation X="-0.511662602" Y="-0.216903374" Z="-0.0133549664"/>
</c:Transform>
</Components>
<Children/>
@@ -406,16 +428,17 @@
<Components>
<c:BoneAttachment>
<BoneName>R_Elbow</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.309118003" Y="1.12181115" Z="0.00506293867"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.391992599" Y="-0.509281039" Z="-0.0413108058"/>
<Position X="0.301801801" Y="1.09683371" Z="0.023665078"/>
<Scale X="0.0500000231" Y="0.0500000194" Z="0.0500000194"/>
<Orientation X="1.67780411" Y="0.697954118" Z="-1.36570835"/>
</c:Transform>
</Components>
<Children/>
@@ -424,16 +447,17 @@
<Components>
<c:BoneAttachment>
<BoneName>R_Leg_Top</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.074000001" Y="0.863433301" Z="0.00200000009"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.0984009728" Y="0.0146064674" Z="0.00352247525"/>
<Position X="0.0695244595" Y="0.711660385" Z="0.0306202006"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.049999997"/>
<Orientation X="0.929966331" Y="0.0844758675" Z="0.0447596237"/>
</c:Transform>
</Components>
<Children/>
@@ -442,16 +466,17 @@
<Components>
<c:BoneAttachment>
<BoneName>R_Foot</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.139749736" Y="0.334264338" Z="0.356020123"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.000313894066" Y="0.00262229913" Z="0.00155029749"/>
<Position X="0.137999952" Y="0.19909358" Z="-0.0635268986"/>
<Scale X="0.0500000007" Y="0.0499999933" Z="0.049999997"/>
<Orientation X="-0.193798333" Y="-0.056662742" Z="-0.0102932369"/>
</c:Transform>
</Components>
<Children/>
@@ -460,16 +485,17 @@
<Components>
<c:BoneAttachment>
<BoneName>R_Toe</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.144308567" Y="0.298593462" Z="0.166685253"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.000313894066" Y="0.00262229913" Z="0.00155029749"/>
<Position X="0.153348058" Y="0.127739012" Z="-0.24189125"/>
<Scale X="0.0500000007" Y="0.0499999933" Z="0.049999997"/>
<Orientation X="-0.193798333" Y="-0.056662742" Z="-0.0102932369"/>
</c:Transform>
</Components>
<Children/>
@@ -478,16 +504,17 @@
<Components>
<c:BoneAttachment>
<BoneName>R_Shoulder_Armor_Joint</BoneName>
<ScaleOffset X="0.200000003" Y="0.200000003" Z="0.200000003"/>
<ScaleOffset X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<InheritScale>true</InheritScale>
</c:BoneAttachment>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="19.6078434" G="19.6078434" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.13872239" Y="1.30850673" Z="-0.144398093"/>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
<Orientation X="-0.798247218" Y="0.000491484476" Z="-0.00077928009"/>
<Position X="0.0885034204" Y="1.22286928" Z="0.0661265627"/>
<Scale X="0.0500000119" Y="0.0500000119" Z="0.0500000119"/>
<Orientation X="-0.295679808" Y="-1.03809083" Z="-0.237101197"/>
</c:Transform>
</Components>
<Children/>
+298
View File
@@ -0,0 +1,298 @@
<?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>Aim</Adder>
<Receiver>FinalBlend</Receiver>
</c:BlendAdditive>
<c:Model>
<GlowIntensity>4</GlowIntensity>
<Resource>Models/Characters/Sniper/SniperBlue.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>
<Position X="0.161506474" Y="1.12409711" Z="-0.197195739"/>
<Scale X="1.00000012" Y="1" Z="1.00000012"/>
<Orientation X="0.185420558" Y="-0.0891536027" Z="0.122916825"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Light">
<Components>
<c:PointLight>
<Radius>3</Radius>
</c:PointLight>
<c:Transform>
<Position X="0" Y="0.100000001" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Aim">
<Components>
<c:Animation>
<AnimationName>AimRifleA</AnimationName>
<Time>0.60000038146972656</Time>
<Loop>false</Loop>
<Additive>true</Additive>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="FinalBlend">
<Components>
<c:BlendOverride>
<Master>WeaponBlend</Master>
<Slave>MovementBlend</Slave>
</c:BlendOverride>
<c:Transform/>
</Components>
<Children>
<Entity name="WeaponBlend">
<Components>
<c:Blend>
<Pose1>ShootBlend</Pose1>
<Pose2>Reload</Pose2>
<Weight>1</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="ShootBlend">
<Components>
<c:Blend>
<Pose1>ShootFast</Pose1>
<Pose2>ShootSlow</Pose2>
<Weight>1</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="ShootFast">
<Components>
<c:Animation>
<AnimationName>ShootFastRifleU</AnimationName>
<Time>0.19319528378127959</Time>
<Speed>1</Speed>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="ShootSlow">
<Components>
<c:Animation>
<AnimationName>ShootRifleU</AnimationName>
<Time>0.59328474141239074</Time>
<Speed>1</Speed>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="Reload">
<Components>
<c:Animation>
<AnimationName>ReloadSwitchU</AnimationName>
<Time>1</Time>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="MovementBlend">
<Components>
<c:Blend>
<Pose1>StandCrouchBlend</Pose1>
<Pose2>Jump</Pose2>
<Weight>1</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="StandCrouchBlend">
<Components>
<c:Blend>
<Pose1>StandMovement</Pose1>
<Pose2>CrouchMovement</Pose2>
<Weight>1</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="CrouchMovement">
<Components>
<c:Blend>
<Pose1>Walk</Pose1>
<Pose2>StrafeBlend</Pose2>
<Weight>1</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="Walk">
<Components>
<c:Animation>
<AnimationName>CrouchWalkF</AnimationName>
<Time>0.35684875796278082</Time>
<Speed>1</Speed>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="StrafeBlend">
<Components>
<c:Blend>
<Pose1>Left</Pose1>
<Pose2>Right</Pose2>
<Weight>1</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="Left">
<Components>
<c:Animation>
<AnimationName>CrouchStrafeLeftF</AnimationName>
<Time>0.35684875796278082</Time>
<Speed>1</Speed>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Right">
<Components>
<c:Animation>
<AnimationName>CrouchStrafeRightF</AnimationName>
<Time>0.35684875796278082</Time>
<Speed>1</Speed>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
<Entity name="StandMovement">
<Components>
<c:Blend>
<Pose1>RunWalkBlend</Pose1>
<Pose2>StrafeBlend</Pose2>
<Weight>1</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="RunWalkBlend">
<Components>
<c:Blend>
<Pose1>Run</Pose1>
<Pose2>Walk</Pose2>
<Weight>1</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="Run">
<Components>
<c:Animation>
<AnimationName>RunF</AnimationName>
<Time>0.35684875796278082</Time>
<Speed>1</Speed>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Walk">
<Components>
<c:Animation>
<AnimationName>WalkF</AnimationName>
<Time>0.35684875796278082</Time>
<Speed>1</Speed>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="StrafeBlend">
<Components>
<c:Blend>
<Pose1>Left</Pose1>
<Pose2>Right</Pose2>
<Weight>0</Weight>
</c:Blend>
<c:Transform/>
</Components>
<Children>
<Entity name="Left">
<Components>
<c:Animation>
<AnimationName>StrafeLeftF</AnimationName>
<Time>0.35684875796278082</Time>
<Speed>1</Speed>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Right">
<Components>
<c:Animation>
<AnimationName>StrafeRightF</AnimationName>
<Time>0.35684875796278082</Time>
<Speed>1</Speed>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
<Entity name="Jump">
<Components>
<c:Animation>
<AnimationName>JumpF</AnimationName>
<Time>1</Time>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+2 -2
View File
@@ -33,8 +33,8 @@ void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int
va_end(args);
if (logLevel == LOG_LEVEL_ERROR) {
std::cerr << file << ":" << line << " " << func << std::endl;
std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
/*std::cerr << file << ":" << line << " " << func << std::endl;
std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;*/
} else {
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
}
+223 -4
View File
@@ -3,13 +3,21 @@
AnimationSystem::AnimationSystem(SystemParams params)
: System(params)
{
EVENT_SUBSCRIBE_MEMBER(m_EAnimationBlend, &AnimationSystem::OnAnimationBlend);
EVENT_SUBSCRIBE_MEMBER(m_EAutoAnimationBlend, &AnimationSystem::OnAutoAnimationBlend);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &AnimationSystem::OnInputCommand);
}
void AnimationSystem::Update(double dt)
{
ImGui::InputText("AnimationName1", &m_AnimationName1[0], sizeof(m_AnimationName1));
ImGui::SliderFloat("Blendtime1", &m_BlendTime1, 0.f, 10.f);
ImGui::InputText("AnimationName2", &m_AnimationName2[0], sizeof(m_AnimationName2));
ImGui::SliderFloat("Blendtime2", &m_BlendTime2, 0.f, 10.f);
UpdateAnimations(dt);
CreateBlendTrees();
UpdateWeights(dt);
}
void AnimationSystem::CreateBlendTrees()
@@ -94,16 +102,17 @@ void AnimationSystem::UpdateAnimations(double dt)
e.Entity = entity;
e.Name = (std::string)animationC["AnimationName"];
m_EventBroker->Publish(e);
AnimationComplete(entity);
(double&)animationC["Speed"] = 0.0;
} else if (nextTime < 0) {
Events::AnimationComplete e;
e.Entity = entity;
e.Name = (std::string)animationC["AnimationName"];
m_EventBroker->Publish(e);
AnimationComplete(entity);
nextTime = 0;
(double&)animationC["Speed"] = 0.0;
}
(double&)animationC["Speed"] = 0.0;
} else {
if (nextTime > animation->Duration) {
Events::AnimationComplete e;
@@ -131,3 +140,213 @@ void AnimationSystem::UpdateAnimations(double dt)
}
}
void AnimationSystem::UpdateWeights(double dt)
{
/* for (auto it = m_BlendJobs.begin(); it != m_BlendJobs.end(); it++) {
if (!it->BlendEntity.Valid()) {
it = m_BlendJobs.erase(it);
continue;
}
if (it->BlendEntity.HasComponent("Blend")) {
it->CurrentTime += dt;
double progress = it->CurrentTime / it->Duration;
progress = glm::clamp(progress, 0.0, 1.0);
double weight = ((it->GoalWeight - it->StartWeight) * progress) + it->StartWeight;
(double&)it->BlendEntity["Blend"]["Weight"] = weight;
if(weight == it->GoalWeight) {
it = m_BlendJobs.erase(it);
}
}
}*/
for (auto it = m_AutoBlendJobs.begin(); it != m_AutoBlendJobs.end();) {
it->CurrentTime += dt;
if (!it->RootNode.Valid()) {
it = m_AutoBlendJobs.erase(it);
continue;
}
if (!it->RootNode.HasComponent("Model")) {
it = m_AutoBlendJobs.erase(it);
continue;
}
Model* model;
try {
model = ResourceManager::Load<::Model, true>(it->RootNode["Model"]["Resource"]);
} catch (const std::exception&) {
continue;
}
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
if (skeleton == nullptr) {
continue;
}
std::shared_ptr<BlendTree> blendTree;
if(skeleton->BlendTrees.find(it->RootNode) != skeleton->BlendTrees.end()) {
blendTree = skeleton->BlendTrees.at(it->RootNode);
} else {
it = m_AutoBlendJobs.erase(it);
continue;
}
it->BlendInfo.progress = glm::clamp(it->CurrentTime / it->Duration, 0.0, 1.0);
it->BlendInfo = blendTree->AutoBlendStep(it->BlendInfo);
if (it->CurrentTime >= it->Duration) {
it = m_AutoBlendJobs.erase(it);
continue;
}
++it;
}
}
void AnimationSystem::AnimationComplete(EntityWrapper animationEntity)
{
for (auto it = m_QueuedBlendJobs.begin(); it != m_QueuedBlendJobs.end(); it++) {
if (!it->BlendEntity.Valid() || !it->AnimationEntity.Valid()) {
it = m_QueuedBlendJobs.erase(it);
continue;
}
if(animationEntity == it->AnimationEntity) {
BlendJob bj;
bj.BlendEntity = it->BlendEntity;
bj.StartWeight = it->StartWeight;
bj.GoalWeight = it->GoalWeight;
bj.Duration = it->Duration;
bj.CurrentTime = 0.0;
m_BlendJobs.push_back(bj);
it = m_QueuedBlendJobs.erase(it);
}
}
}
bool AnimationSystem::OnAnimationBlend(Events::AnimationBlend& e)
{
if(!e.BlendEntity.Valid()) {
return false;
}
if(!e.BlendEntity.HasComponent("Blend")){
return false;
}
if (e.AnimationEntity.Valid()) {
if (e.AnimationEntity.HasComponent("Animation")) {
QueuedBlendJob qbj;
qbj.BlendEntity = e.BlendEntity;
qbj.StartWeight = (double)e.BlendEntity["Blend"]["Weight"];
qbj.GoalWeight = e.GoalWeight;
qbj.Duration = e.Duration;
qbj.CurrentTime = 0.0;
qbj.AnimationEntity = e.AnimationEntity;
m_QueuedBlendJobs.push_back(qbj);
return true;
}
}
BlendJob bj;
bj.BlendEntity = e.BlendEntity;
bj.StartWeight = (double)e.BlendEntity["Blend"]["Weight"];
bj.GoalWeight = e.GoalWeight;
bj.Duration = e.Duration;
bj.CurrentTime = 0.0;
m_BlendJobs.push_back(bj);
return true;
}
bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
{
if(!e.RootNode.Valid()) {
return false;
}
if(!e.RootNode.HasComponent("Model")) {
return false;
}
AutoBlendJob abj;
abj.RootNode = e.RootNode;
abj.CurrentTime = 0.0;
abj.Duration = e.Duration;
BlendTree::AutoBlendInfo abInfo;
abInfo.NodeName = e.NodeName;
abInfo.progress = 0.0;
abj.BlendInfo = abInfo;
m_AutoBlendJobs.push_back(abj);
}
bool AnimationSystem::OnInputCommand(const Events::InputCommand& e)
{
if (e.Value == 1.f) {
if (e.Command == "BlendTest0") {
auto blendComponents = m_World->GetComponents("BlendAdditive");
if (blendComponents == nullptr) {
return false;
}
for (auto& bc : *blendComponents) {
EntityWrapper entity = EntityWrapper(m_World, bc.EntityID);
if (entity.Name() == "Assault") {
Events::AutoAnimationBlend aeb;
aeb.Duration = m_BlendTime1;
aeb.NodeName = m_AnimationName1;
aeb.RootNode = entity;
m_EventBroker->Publish(aeb);
}
}
} else if (e.Command == "BlendTest1") {
auto blendComponents = m_World->GetComponents("BlendAdditive");
if (blendComponents == nullptr) {
return false;
}
for (auto& bc : *blendComponents) {
EntityWrapper entity = EntityWrapper(m_World, bc.EntityID);
if (entity.Name() == "Assault") {
Events::AutoAnimationBlend aeb;
aeb.Duration = m_BlendTime2;
aeb.NodeName = m_AnimationName2;
aeb.RootNode = entity;
m_EventBroker->Publish(aeb);
}
}
}
}
}
+82 -6
View File
@@ -14,6 +14,7 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
}
m_Root = new Node();
m_Root->Entity = ModelEntity;
m_Root->Name = ModelEntity.Name();
m_Root->Pose = m_Skeleton->GetFrameBones(animation, (double)ModelEntity["Animation"]["Time"], (bool)ModelEntity["Animation"]["Additive"]);
m_Root->Parent = nullptr;
@@ -21,15 +22,18 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
} else if (ModelEntity.HasComponent("Blend")) {
m_Root = new Node();
m_Root->Entity = ModelEntity;
m_Root->Name = ModelEntity.Name();
m_Root->Parent = nullptr;
m_Root->Type = NodeType::Blend;
m_Root->Weight = (double)ModelEntity["Blend"]["Weight"];
(double&)ModelEntity["Blend"]["Weight"] = glm::clamp((double)ModelEntity["Blend"]["Weight"], 0.0, 1.0);
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);
} else if (ModelEntity.HasComponent("BlendOverride")) {
m_Root = new Node();
m_Root->Entity = ModelEntity;
m_Root->Name = ModelEntity.Name();
m_Root->Parent = nullptr;
m_Root->Type = NodeType::Override;
@@ -38,6 +42,7 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
} else if (ModelEntity.HasComponent("BlendAdditive")) {
m_Root = new Node();
m_Root->Entity = ModelEntity;
m_Root->Name = ModelEntity.Name();
m_Root->Parent = nullptr;
m_Root->Type = NodeType::Additive;
@@ -97,8 +102,6 @@ void BlendTree::PrintTree()
LOG_INFO("%s", currentNode->Name.c_str());
currentNode = currentNode->Next();
}
}
BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity)
@@ -116,6 +119,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
}
Node* node = new Node();
node->Entity = childEntity;
node->Name = childEntity.Name();
node->Pose = m_Skeleton->GetFrameBones(animation, (double)childEntity["Animation"]["Time"], (bool)childEntity["Animation"]["Additive"]);
node->Parent = parentNode;
@@ -124,24 +128,26 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
} else if (childEntity.HasComponent("Blend")) {
Node* node = new Node();
node->Entity = childEntity;
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);
(double&)childEntity["Blend"]["Weight"] = glm::clamp((double)childEntity["Blend"]["Weight"], 0.0, 1.0);
node->Weight = (double)childEntity["Blend"]["Weight"];
if (node->Weight < 1.f && node->Weight > 0.f) {
//if (node->Weight < 1.f && node->Weight > 0.f) {
node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity);
node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity);
} else if (node->Weight == 1.f) {
/* } else if (node->Weight == 1.f) {
node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity);
} else if (node->Weight == 0.f) {
node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity);
}
}*/
return node;
} else if (childEntity.HasComponent("BlendOverride")) {
Node* node = new Node();
node->Entity = childEntity;
node->Name = childEntity.Name();
node->Parent = parentNode;
node->Type = NodeType::Override;
@@ -150,6 +156,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
return node;
} else if (childEntity.HasComponent("BlendAdditive")) {
Node* node = new Node();
node->Entity = childEntity;
node->Name = childEntity.Name();
node->Parent = parentNode;
node->Type = NodeType::Additive;
@@ -162,6 +169,75 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
return nullptr;
}
std::vector<BlendTree::Node*> BlendTree::FindNodesByName(std::string name)
{
std::vector<Node*> Nodes;
Node* currentNode = m_Root;
while (currentNode->Child[0] != nullptr) {
currentNode = currentNode->Child[0];
}
while (currentNode != nullptr) {
if(currentNode->Name == name) {
Nodes.push_back(currentNode);
}
currentNode = currentNode->Next();
}
return Nodes;
}
BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
{
std::vector<Node*> goalNodes = FindNodesByName(blendInfo.NodeName);
if(goalNodes.size() == 0) {
return blendInfo;
} else if(goalNodes.size() == 1) {
Node* currentNode = goalNodes[0]->Parent;
Node* lastNode = goalNodes[0];
while (currentNode != nullptr)
{
if(!currentNode->Entity.HasComponent("Blend")) {
return blendInfo;
}
double startWeight;
if(blendInfo.StartWeights.find(currentNode->Entity) != blendInfo.StartWeights.end()) {
startWeight = blendInfo.StartWeights.at(currentNode->Entity);
} else {
startWeight = currentNode->Weight;
blendInfo.StartWeights[currentNode->Entity] = startWeight;
}
double goalWeight;
if(currentNode->Child[0] == lastNode) {
goalWeight = 0.0;
} else if (currentNode->Child[1] == lastNode) {
goalWeight = 1.0;
}
double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight;
(double&)currentNode->Entity["Blend"]["Weight"] = weight;
currentNode->Weight = weight;
lastNode = currentNode;
currentNode = currentNode->Parent;
}
} else if(goalNodes.size() >= 2) {
}
return blendInfo;
}
void BlendTree::Blend(std::map<int, glm::mat4>& pose)
{
Node* currentNode;
+1 -1
View File
@@ -142,7 +142,7 @@ void Renderer::Draw(RenderFrame& frame)
PerformanceTimer::StopTimer("Renderer-Depth");
}
PerformanceTimer::StartTimer("AO generation");
m_SSAOPass->Draw(m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera);
//m_SSAOPass->Draw(m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera);
GLuint ao = m_SSAOPass->SSAOTexture();
PerformanceTimer::StopTimer("AO generation");
for (auto scene : frame.RenderScenes){
+6 -10
View File
@@ -57,7 +57,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim
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::quat rotation = glm::normalize(glm::slerp(currentBoneProperty.Rotation, nextBoneProperty.Rotation, progress));
glm::vec3 scale = currentBoneProperty.Scale * (1.f - progress) + nextBoneProperty.Scale * progress;
// Flag for no root motion
@@ -71,7 +71,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation* anim
} else { // 1 keyframes for the current bone
currentFrame = boneKeyFrames.at(0);
boneMatrix = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(currentFrame.BoneProperties.Rotation) * glm::scale(currentFrame.BoneProperties.Scale));
boneMatrix = (glm::translate(currentFrame.BoneProperties.Position) * glm::toMat4(glm::normalize(currentFrame.BoneProperties.Rotation)) * glm::scale(currentFrame.BoneProperties.Scale));
boneMatrices[bone->ID] = boneMatrix;// *bone->OffsetMatrix;
}
} else { // 0 keyframes for the current bone
@@ -244,7 +244,7 @@ glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animatio
}
if (progress > 1.0f || progress < 0.0f) {
LOG_INFO("Progress %f", progress);
//LOG_INFO("Progress %f", progress);
progress = glm::clamp(progress, 0.0f, 1.0f);
}
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties;
@@ -276,7 +276,7 @@ glm::mat4 Skeleton::GetBoneTransform(const Bone* bone, const Animation* animatio
}
}
std::map<int, glm::mat4> Skeleton::BlendPoses(const std::map<int, glm::mat4>& pose1, const std::map<int, glm::mat4>& pose2, float weight)
std::map<int, glm::mat4> Skeleton::BlendPoses(const std::map<int, glm::mat4>& pose1, const std::map<int, glm::mat4>& pose2, double weight)
{
std::map<int, glm::mat4> finalPose;
@@ -285,8 +285,8 @@ std::map<int, glm::mat4> Skeleton::BlendPoses(const std::map<int, glm::mat4>& po
glm::mat4 blendedPose = glm::mat4(0);
if(pose1.find(boneID) != pose1.end() && pose2.find(boneID) != pose2.end()) {
blendedPose += pose1.at(boneID) * weight;
blendedPose += pose2.at(boneID) * (1.f - weight);
blendedPose += pose1.at(boneID) * (float)(1.0 - weight);
blendedPose += pose2.at(boneID) * (float)weight;
finalPose[boneID] = blendedPose;
} else if(pose1.find(boneID) != pose1.end()) {
finalPose[boneID] = pose1.at(boneID);
@@ -347,15 +347,11 @@ void Skeleton::GetFinalPose(std::map<int, glm::mat4>& boneMatrices, std::vector<
void Skeleton::AccumulateFinalPose(std::map<int, glm::mat4>& boneMatrices, std::map<int, glm::mat4>& boneTransforms, const Bone* bone, glm::mat4 parentMatrix)
{
glm::mat4 boneMatrix;
if (boneMatrices.find(bone->ID) != boneMatrices.end()) {
boneMatrix = parentMatrix * boneMatrices.at(bone->ID);
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
} else {
if (bone->Parent) {
boneMatrix = parentMatrix * (glm::inverse(bone->OffsetMatrix) * bone->Parent->OffsetMatrix);