BoneAttachments now working and BlendTrees are created in the AnimationSystem
This commit is contained in:
@@ -9,20 +9,17 @@
|
||||
#include "Rendering/Model.h"
|
||||
#include "Rendering/EAnimationComplete.h"
|
||||
#include "Rendering/Skeleton.h"
|
||||
#include <imgui/imgui.h>
|
||||
#include "Rendering/BlendTree.h"
|
||||
|
||||
class AnimationSystem : public PureSystem
|
||||
class AnimationSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
AnimationSystem(SystemParams params)
|
||||
: System(params)
|
||||
, PureSystem("Animation")
|
||||
{
|
||||
|
||||
}
|
||||
AnimationSystem(SystemParams params);
|
||||
~AnimationSystem() { }
|
||||
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt) override;
|
||||
virtual void Update(double dt) override;
|
||||
private:
|
||||
void CreateBlendTrees();
|
||||
void UpdateAnimations(double dt);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
|
||||
std::vector<glm::mat4> GetFinalPose() { return m_FinalPose; }
|
||||
|
||||
glm::mat4 GetBoneTransform(int boneID);
|
||||
|
||||
|
||||
void PrintTree();
|
||||
@@ -72,6 +72,8 @@ private:
|
||||
Node* m_Root = nullptr;
|
||||
|
||||
std::vector<glm::mat4> m_FinalPose;
|
||||
std::map<int, glm::mat4> m_FinalBoneTransforms;
|
||||
|
||||
std::vector<glm::mat4> AccumulateFinalPose();
|
||||
BlendTree::Node* FillTreeByName(Node* parentNode, std::string name, EntityWrapper parentEntity);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Core/ResourceManager.h"
|
||||
#include "Rendering/Model.h"
|
||||
#include "Rendering/Skeleton.h"
|
||||
#include "Rendering/BlendTree.h"
|
||||
|
||||
//Needs to be a higher orderlevel than AnimationSystem
|
||||
class BoneAttachmentSystem : public PureSystem
|
||||
|
||||
@@ -125,7 +125,10 @@ struct ModelJob : RenderJob
|
||||
if (Skeleton != nullptr) {
|
||||
|
||||
EntityWrapper entityWrapper = EntityWrapper(world, modelComponent.EntityID);
|
||||
BlendTree = std::shared_ptr<::BlendTree>(new ::BlendTree(entityWrapper, Skeleton));
|
||||
|
||||
if(Skeleton->BlendTrees.find(entityWrapper) != Skeleton->BlendTrees.end()) {
|
||||
BlendTree = Skeleton->BlendTrees.at(entityWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,27 +6,9 @@
|
||||
#include "../GLM.h"
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
||||
#include <imgui/imgui.h>
|
||||
#include "../Core/EntityWrapper.h"
|
||||
|
||||
//struct Bone
|
||||
//{
|
||||
// Bone(std::string name, glm::mat4 offsetMatrix)
|
||||
// : Name(name)
|
||||
// , OffsetMatrix(offsetMatrix)
|
||||
// { }
|
||||
//
|
||||
// ~Bone()
|
||||
// {
|
||||
// for (auto kv : Children) {
|
||||
// delete kv.second;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// std::string Name;
|
||||
// glm::mat4 OffsetMatrix;
|
||||
// glm::mat4 LocalMatrix;
|
||||
//
|
||||
// std::map<std::string, Bone*> Children;
|
||||
//};
|
||||
class BlendTree;
|
||||
|
||||
class Skeleton
|
||||
{
|
||||
@@ -75,6 +57,8 @@ public:
|
||||
|
||||
std::map<int, Bone*> Bones;
|
||||
|
||||
std::unordered_map<EntityWrapper, std::shared_ptr<BlendTree>> BlendTrees;
|
||||
|
||||
// Attach a new bone to the skeleton
|
||||
// Returns: New bone index
|
||||
int CreateBone(int ID, int parentID, std::string name, glm::mat4 offsetMatrix);
|
||||
@@ -86,13 +70,13 @@ public:
|
||||
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> 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::vector<glm::mat4> GetFinalPose(std::map<int, glm::mat4>& boneMatrices);
|
||||
void GetFinalPose(std::map<int, glm::mat4>& boneMatrices, std::vector<glm::mat4>& finalPose, std::map<int, glm::mat4>& boneTransforms);
|
||||
|
||||
std::map<std::string, Animation> Animations;
|
||||
private:
|
||||
glm::mat4 GetAdditiveBonePose(const Bone* bone, const Animation* animation, double time);
|
||||
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 AccumulateFinalPose(std::map<int, glm::mat4>& boneMatrices, std::map<int, glm::mat4>& boneTransforms, 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);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
: System(params)
|
||||
, PureSystem("Lifetime")
|
||||
{
|
||||
LOG_INFO("ASDASDASSA");
|
||||
|
||||
}
|
||||
|
||||
virtual void Update(double dt) override;
|
||||
|
||||
@@ -9,19 +9,22 @@
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Transform>
|
||||
<Position X="-0.100000001" Y="-1.11500001" Z="-3.10500026"/>
|
||||
<Position X="0.100000001" Y="-1.5150001" Z="-3.70500016"/>
|
||||
<Orientation X="0" Y="2.41300011" Z="0"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:DirectionalLight/>
|
||||
<c:DirectionalLight>
|
||||
<Intensity>0.10000047832727432</Intensity>
|
||||
</c:DirectionalLight>
|
||||
<c:Model>
|
||||
<Resource>Models/Widgets/Lights/DirectionalLightWidget.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="2.42800021" Z="-2.80000019"/>
|
||||
<Orientation X="5.40800047" Y="3.65100026" Z="0"/>
|
||||
<Orientation X="5.60000038" Y="3.14159203" Z="0"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
@@ -30,36 +33,22 @@
|
||||
<Components>
|
||||
<c:PointLight>
|
||||
<Color A="1" B="0.70588237" G="0.70588237" R="1"/>
|
||||
<Radius>10</Radius>
|
||||
<Radius>8</Radius>
|
||||
<Intensity>0.20000000298023224</Intensity>
|
||||
</c:PointLight>
|
||||
<c:Transform>
|
||||
<Position X="-0.375567257" Y="2.13093901" Z="-0.718547285"/>
|
||||
<Position X="0" Y="1.80280674" Z="-1.53209329"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:PointLight>
|
||||
<Color A="1" B="1" G="0.70588237" R="0.70588237"/>
|
||||
<Radius>10</Radius>
|
||||
</c:PointLight>
|
||||
<c:Transform>
|
||||
<Position X="-1.96873236" Y="0" Z="0"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitPlane.mesh</Resource>
|
||||
<Color A="1" B="0.137254909" G="0.121568628" R="0.160784319"/>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="-0.565843403" Y="0" Z="0"/>
|
||||
<Scale X="10" Y="1" Z="10"/>
|
||||
<Scale X="10" Y="10" Z="10"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
@@ -85,7 +74,9 @@
|
||||
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0.140207142" Y="0.952379346" Z="-0.0788922161"/>
|
||||
<Scale X="1.00000012" Y="1" Z="1.00000012"/>
|
||||
<Orientation X="-1.14481521" Y="0.059967503" Z="-0.176931962"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
@@ -94,7 +85,6 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>AimRifleA</AnimationName>
|
||||
<Time>1</Time>
|
||||
<Additive>true</Additive>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -114,7 +104,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>ShootFastRifleU</AnimationName>
|
||||
<Time>0.15443509503129649</Time>
|
||||
<Time>0.17385384906517576</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -123,63 +113,28 @@
|
||||
</Entity>
|
||||
<Entity name="MovementBlend">
|
||||
<Components>
|
||||
<c:Blend>
|
||||
<Pose1>BlendWalkRun</Pose1>
|
||||
<Pose2>StrafeAnimation</Pose2>
|
||||
<Weight>1</Weight>
|
||||
</c:Blend>
|
||||
<c:Animation>
|
||||
<AnimationName>RunF</AnimationName>
|
||||
<Time>0.40542068091002648</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children>
|
||||
<Entity name="StrafeAnimation">
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>StrafeRightF</AnimationName>
|
||||
<Time>0.4127890381477517</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.17180750829794933</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
<Entity name="WalkAnimation">
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>WalkF</AnimationName>
|
||||
<Time>0.40122024997349826</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</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>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="AssaultRed">
|
||||
@@ -206,7 +161,9 @@
|
||||
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0.151036888" Y="0.850736618" Z="-0.0970466882"/>
|
||||
<Scale X="1.00000012" Y="1" Z="1.00000012"/>
|
||||
<Orientation X="-0.948045969" Y="0.0299621802" Z="-0.0913181901"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
@@ -215,7 +172,8 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>AimRifleA</AnimationName>
|
||||
<Time>1</Time>
|
||||
<Time>0.16089285281973087</Time>
|
||||
<Speed>0.5</Speed>
|
||||
<Additive>true</Additive>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -235,7 +193,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>ShootFastRifleU</AnimationName>
|
||||
<Time>0.074040246120830933</Time>
|
||||
<Time>0.093816429893875508</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -247,7 +205,7 @@
|
||||
<c:Blend>
|
||||
<Pose1>BlendWalkRun</Pose1>
|
||||
<Pose2>StrafeAnimation</Pose2>
|
||||
<Weight>1</Weight>
|
||||
<Weight>0</Weight>
|
||||
</c:Blend>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
@@ -255,8 +213,8 @@
|
||||
<Entity name="StrafeAnimation">
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>StrafeRightF</AnimationName>
|
||||
<Time>0.33239292263858555</Time>
|
||||
<AnimationName>StrafeLeftF</AnimationName>
|
||||
<Time>0.48873338520059662</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -268,7 +226,7 @@
|
||||
<c:Blend>
|
||||
<Pose1>RunAnimtaion</Pose1>
|
||||
<Pose2>WalkAnimation</Pose2>
|
||||
<Weight>0.43000054359436035</Weight>
|
||||
<Weight>1</Weight>
|
||||
</c:Blend>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
@@ -277,7 +235,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>RunF</AnimationName>
|
||||
<Time>0.091411392788782297</Time>
|
||||
<Time>0.71124602785672497</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -288,7 +246,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>WalkF</AnimationName>
|
||||
<Time>0.32082413446433122</Time>
|
||||
<Time>0.94065876953227434</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -301,6 +259,20 @@
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="Light">
|
||||
<Components>
|
||||
<c:PointLight>
|
||||
<Color A="1" B="0.00392156886" G="0.00392156886" R="1"/>
|
||||
<Radius>3</Radius>
|
||||
<Intensity>0.80000001192092896</Intensity>
|
||||
<Falloff>0.30000001192092896</Falloff>
|
||||
</c:PointLight>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0.100000001" Z="0"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="AssaultBlue">
|
||||
@@ -327,7 +299,9 @@
|
||||
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0.1532076" Y="1.02745032" Z="-0.223910496"/>
|
||||
<Scale X="1.00000012" Y="1" Z="1.00000012"/>
|
||||
<Orientation X="-0.0956145823" Y="-0.0272450559" Z="0.150499463"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
@@ -336,7 +310,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>AimRifleA</AnimationName>
|
||||
<Time>1</Time>
|
||||
<Time>0.46000003814697266</Time>
|
||||
<Additive>true</Additive>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -355,8 +329,8 @@
|
||||
<Entity name="ShootRifleAnimation">
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>ShootFastRifleU</AnimationName>
|
||||
<Time>0.14396212913172102</Time>
|
||||
<AnimationName>ShootRifleU</AnimationName>
|
||||
<Time>0.041207335792059041</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -368,7 +342,7 @@
|
||||
<c:Blend>
|
||||
<Pose1>BlendWalkRun</Pose1>
|
||||
<Pose2>StrafeAnimation</Pose2>
|
||||
<Weight>1</Weight>
|
||||
<Weight>0</Weight>
|
||||
</c:Blend>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
@@ -377,7 +351,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>StrafeRightF</AnimationName>
|
||||
<Time>0.40231464173670251</Time>
|
||||
<Time>0.022149276804645623</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -398,7 +372,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>RunF</AnimationName>
|
||||
<Time>0.16133311188689925</Time>
|
||||
<Time>0.45204536957978458</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -409,7 +383,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>WalkF</AnimationName>
|
||||
<Time>0.39074585356244818</Time>
|
||||
<Time>0.010580488630391294</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -422,6 +396,19 @@
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="Light">
|
||||
<Components>
|
||||
<c:PointLight>
|
||||
<Color A="1" B="1" G="0.00392156886" R="0.00392156886"/>
|
||||
<Radius>3</Radius>
|
||||
<Falloff>0.30000001192092896</Falloff>
|
||||
</c:PointLight>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0.100000001" Z="0"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="AssaultPurple">
|
||||
@@ -448,7 +435,9 @@
|
||||
<Resource>Models/Weapons/Blue/AssaultWeaponBlue.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0.0926265344" Y="0.837827146" Z="-0.255172133"/>
|
||||
<Scale X="1.00000012" Y="1" Z="1.00000012"/>
|
||||
<Orientation X="-0.209567234" Y="0.138206437" Z="0.0942857563"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
@@ -457,7 +446,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>AimRifleA</AnimationName>
|
||||
<Time>1</Time>
|
||||
<Time>0.5</Time>
|
||||
<Additive>true</Additive>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -473,17 +462,6 @@
|
||||
<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>
|
||||
@@ -498,7 +476,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>StrafeRightF</AnimationName>
|
||||
<Time>0.090400359197961855</Time>
|
||||
<Time>0.71023499426590497</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -510,7 +488,7 @@
|
||||
<c:Blend>
|
||||
<Pose1>RunAnimtaion</Pose1>
|
||||
<Pose2>WalkAnimation</Pose2>
|
||||
<Weight>0.43000054359436035</Weight>
|
||||
<Weight>1</Weight>
|
||||
</c:Blend>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
@@ -518,8 +496,8 @@
|
||||
<Entity name="RunAnimtaion">
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>RunF</AnimationName>
|
||||
<Time>0.8494188293481586</Time>
|
||||
<AnimationName>CrouchWalkF</AnimationName>
|
||||
<Time>0.19404614253737762</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -530,7 +508,7 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>WalkF</AnimationName>
|
||||
<Time>0.078831571023707525</Time>
|
||||
<Time>0.69866620609165064</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
@@ -541,10 +519,50 @@
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="ShootRifleAnimation">
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>ReloadSwitchU</AnimationName>
|
||||
<Time>0.25662476445004501</Time>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="Light">
|
||||
<Components>
|
||||
<c:PointLight>
|
||||
<Color A="1" B="1" G="0.00392156886" R="0.196078435"/>
|
||||
<Radius>3</Radius>
|
||||
</c:PointLight>
|
||||
<c:Transform>
|
||||
<Position X="0" Y="0.100000001" Z="0"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitSphere.mesh</Resource>
|
||||
<Color A="1" B="0.00392156886" G="0.00392156886" R="78.4313736"/>
|
||||
</c:Model>
|
||||
<c:PointLight>
|
||||
<Color A="1" B="0.00392156886" G="0.00392156886" R="1"/>
|
||||
<Radius>3</Radius>
|
||||
</c:PointLight>
|
||||
<c:Transform>
|
||||
<Position X="3.07036352" Y="0.463677973" Z="2.48590684"/>
|
||||
<Scale X="0.300000012" Y="0.300000012" Z="0.300000012"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
|
||||
@@ -1,66 +1,109 @@
|
||||
#include "Rendering/AnimationSystem.h"
|
||||
|
||||
void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt)
|
||||
AnimationSystem::AnimationSystem(SystemParams params)
|
||||
: System(params)
|
||||
{
|
||||
|
||||
EntityWrapper parent = entity.FirstParentWithComponent("Model");
|
||||
|
||||
Model* model;
|
||||
try {
|
||||
model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]);
|
||||
} catch (const std::exception&) {
|
||||
}
|
||||
|
||||
void AnimationSystem::Update(double dt)
|
||||
{
|
||||
UpdateAnimations(dt);
|
||||
CreateBlendTrees();
|
||||
}
|
||||
|
||||
void AnimationSystem::CreateBlendTrees()
|
||||
{
|
||||
auto modelComponents = m_World->GetComponents("Model");
|
||||
if (modelComponents == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
for (auto& modelC : *modelComponents) {
|
||||
EntityWrapper entity = EntityWrapper(m_World, modelC.EntityID);
|
||||
|
||||
Model* model;
|
||||
try {
|
||||
model = ResourceManager::Load<::Model, true>(entity["Model"]["Resource"]);
|
||||
} catch (const std::exception&) {
|
||||
continue;;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
skeleton->BlendTrees[entity] = std::shared_ptr<BlendTree>(new BlendTree(entity, skeleton));
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationSystem::UpdateAnimations(double dt)
|
||||
{
|
||||
auto animationComponents = m_World->GetComponents("Animation");
|
||||
if(animationComponents == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= 1; i++) {
|
||||
const Skeleton::Animation* animation = skeleton->GetAnimation(animationComponent["AnimationName"]);
|
||||
for (auto& animationC : *animationComponents) {
|
||||
EntityWrapper entity = EntityWrapper(m_World, animationC.EntityID);
|
||||
EntityWrapper parent = entity.FirstParentWithComponent("Model");
|
||||
|
||||
Model* model;
|
||||
try {
|
||||
model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]);
|
||||
} catch (const std::exception&) {
|
||||
return;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Skeleton::Animation* animation = skeleton->GetAnimation(animationC["AnimationName"]);
|
||||
|
||||
if (animation == nullptr) {
|
||||
continue;;
|
||||
}
|
||||
|
||||
double animationSpeed = (double)animationComponent["Speed"];
|
||||
double animationSpeed = (double)animationC["Speed"];
|
||||
|
||||
if (animationSpeed != 0.0) {
|
||||
double nextTime = (double)animationComponent["Time"] + animationSpeed * dt;
|
||||
double nextTime = (double)animationC["Time"] + animationSpeed * dt;
|
||||
|
||||
|
||||
if (!(bool)animationComponent["Loop"]) {
|
||||
if (!(bool)animationC["Loop"]) {
|
||||
if (nextTime > animation->Duration) {
|
||||
nextTime = animation->Duration;
|
||||
Events::AnimationComplete e;
|
||||
e.Entity = entity;
|
||||
e.Name = (std::string)animationComponent["AnimationName"];
|
||||
e.Name = (std::string)animationC["AnimationName"];
|
||||
m_EventBroker->Publish(e);
|
||||
} else if (nextTime < 0) {
|
||||
Events::AnimationComplete e;
|
||||
e.Entity = entity;
|
||||
e.Name = (std::string)animationComponent["AnimationName"];
|
||||
e.Name = (std::string)animationC["AnimationName"];
|
||||
m_EventBroker->Publish(e);
|
||||
nextTime = 0;
|
||||
}
|
||||
|
||||
(double&)animationComponent["Speed"] = 0.0;
|
||||
|
||||
(double&)animationC["Speed"] = 0.0;
|
||||
|
||||
} else {
|
||||
if (nextTime > animation->Duration) {
|
||||
Events::AnimationComplete e;
|
||||
e.Entity = entity;
|
||||
e.Name = (std::string)animationComponent["AnimationName"];
|
||||
e.Name = (std::string)animationC["AnimationName"];
|
||||
m_EventBroker->Publish(e);
|
||||
|
||||
while(nextTime > animation->Duration) {
|
||||
while (nextTime > animation->Duration) {
|
||||
nextTime -= animation->Duration;
|
||||
}
|
||||
} else if (nextTime < 0) {
|
||||
Events::AnimationComplete e;
|
||||
e.Entity = entity;
|
||||
e.Name = (std::string)animationComponent["AnimationName"];
|
||||
e.Name = (std::string)animationC["AnimationName"];
|
||||
m_EventBroker->Publish(e);
|
||||
|
||||
while (nextTime < 0) {
|
||||
@@ -69,8 +112,8 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a
|
||||
}
|
||||
}
|
||||
|
||||
(double&)animationComponent["Time"] = nextTime;
|
||||
(double&)animationC["Time"] = nextTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,17 @@ BlendTree::~BlendTree()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
glm::mat4 BlendTree::GetBoneTransform(int boneID)
|
||||
{
|
||||
if(m_FinalBoneTransforms.find(boneID) != m_FinalBoneTransforms.end()) {
|
||||
return m_FinalBoneTransforms.at(boneID);
|
||||
} else {
|
||||
return glm::mat4(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BlendTree::PrintTree()
|
||||
{
|
||||
Node* currentNode = m_Root;
|
||||
@@ -213,7 +224,7 @@ std::vector<glm::mat4> BlendTree::AccumulateFinalPose()
|
||||
std::map<int, glm::mat4> pose;
|
||||
Blend(pose);
|
||||
|
||||
finalPose = m_Skeleton->GetFinalPose(pose);
|
||||
m_Skeleton->GetFinalPose(pose, finalPose, m_FinalBoneTransforms);
|
||||
|
||||
return finalPose;
|
||||
}
|
||||
|
||||
@@ -8,10 +8,13 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
|
||||
return;
|
||||
}
|
||||
|
||||
auto parent = entity.FirstParentWithComponent("Animation");
|
||||
if (!parent.HasComponent("Model")) {
|
||||
auto parent = entity.FirstParentWithComponent("Model");
|
||||
|
||||
if(!parent.Valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Model* model;
|
||||
try {
|
||||
model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]);
|
||||
@@ -35,61 +38,29 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
|
||||
return;
|
||||
}
|
||||
|
||||
/* std::vector<::Skeleton::AnimationData> Animations;
|
||||
::Skeleton::AnimationOffset AnimationOffset;
|
||||
glm::mat4 boneTransform;
|
||||
if (skeleton->BlendTrees.find(parent) != skeleton->BlendTrees.end()) {
|
||||
|
||||
if (parent.HasComponent("Animation")) {
|
||||
::Skeleton::AnimationData animationData;
|
||||
animationData.animation = model->m_RawModel->m_Skeleton->GetAnimation(parent["Animation"]["AnimationName"]);
|
||||
if (animationData.animation != nullptr) {
|
||||
animationData.time = (double)parent["Animation"]["Time"];
|
||||
Animations.push_back(animationData);
|
||||
}
|
||||
}
|
||||
|
||||
if (parent.HasComponent("AnimationOffset")) {
|
||||
AnimationOffset.animation = model->m_RawModel->m_Skeleton->GetAnimation(parent["AnimationOffset"]["AnimationName"]);
|
||||
AnimationOffset.time = (double)parent["AnimationOffset"]["Time"];
|
||||
glm::mat4 boneTransform = skeleton->BlendTrees.at(parent)->GetBoneTransform(id);
|
||||
|
||||
if(AnimationOffset.animation != nullptr) {
|
||||
boneTransform = skeleton->GetBoneTransform(false, skeleton->Bones.at(id), Animations, AnimationOffset, glm::mat4(1));
|
||||
} else {
|
||||
boneTransform = skeleton->GetBoneTransform(false, skeleton->Bones.at(id), Animations, glm::mat4(1));
|
||||
}
|
||||
glm::vec3 scale;
|
||||
glm::quat rotation;
|
||||
glm::vec3 translation;
|
||||
glm::vec3 skew;
|
||||
glm::vec4 perspective;
|
||||
glm::decompose(boneTransform, scale, rotation, translation, skew, perspective);
|
||||
|
||||
glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation));
|
||||
|
||||
} else {
|
||||
boneTransform = skeleton->GetBoneTransform(false, skeleton->Bones.at(id), Animations, glm::mat4(1));
|
||||
if ((bool)entity["BoneAttachment"]["InheritPosition"]) {
|
||||
(glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
|
||||
}
|
||||
if ((bool)entity["BoneAttachment"]["InheritOrientation"]) {
|
||||
(glm::vec3&)entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"];
|
||||
}
|
||||
if ((bool)entity["BoneAttachment"]["InheritScale"]) {
|
||||
(glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
glm::vec3 scale;
|
||||
glm::quat rotation;
|
||||
glm::vec3 translation;
|
||||
glm::vec3 skew;
|
||||
glm::vec4 perspective;
|
||||
glm::decompose(boneTransform, scale, rotation, translation, skew, perspective);
|
||||
|
||||
glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation));
|
||||
/ *
|
||||
|
||||
angles.y = asin(-boneTransform[0][2]);
|
||||
if (cos(angles.y) != 0) {
|
||||
angles.x = atan2(boneTransform[1][2], boneTransform[2][2]);
|
||||
angles.z = atan2(boneTransform[0][1], boneTransform[0][0]);
|
||||
} else {
|
||||
angles.x = atan2(-boneTransform[2][0], boneTransform[1][1]);
|
||||
angles.z = 0;
|
||||
}* /
|
||||
|
||||
if ((bool)entity["BoneAttachment"]["InheritPosition"]) {
|
||||
(glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
|
||||
}
|
||||
if ((bool)entity["BoneAttachment"]["InheritOrientation"]) {
|
||||
(glm::vec3&)entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"];
|
||||
}
|
||||
if ((bool)entity["BoneAttachment"]["InheritScale"]) {
|
||||
(glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"];
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -337,9 +337,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene);
|
||||
//bind textures
|
||||
BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob);
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = explosionEffectJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
if (explosionEffectJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = explosionEffectJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
} else {
|
||||
m_ExplosionEffectProgram->Bind();
|
||||
GLERROR("Bind ExplosionEffect program");
|
||||
@@ -360,10 +362,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
//bind textures
|
||||
BindExplosionTextures(explosionSplatMapSkinnedHandle, explosionEffectJob);
|
||||
GLERROR("asdasd");
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = explosionEffectJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
if (explosionEffectJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = explosionEffectJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
} else {
|
||||
m_ExplosionEffectSplatMapProgram->Bind();
|
||||
GLERROR("Bind ExplosionEffectSplatMap program");
|
||||
@@ -401,10 +404,12 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
BindModelUniforms(forwardSkinnedHandle, modelJob, scene);
|
||||
//bind textures
|
||||
BindModelTextures(forwardSkinnedHandle, modelJob);
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
} else {
|
||||
m_ForwardPlusProgram->Bind();
|
||||
GLERROR("Bind ForwardPlusProgram");
|
||||
@@ -425,10 +430,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
//bind textures
|
||||
BindModelTextures(forwardSplatMapSkinnedHandle, modelJob);
|
||||
GLERROR("asdasd");
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
} else {
|
||||
m_ForwardPlusSplatMapProgram->Bind();
|
||||
GLERROR("Bind SplatMap program");
|
||||
@@ -469,9 +475,11 @@ void DrawFinalPass::DrawShieldToStencilBuffer(std::list<std::shared_ptr<RenderJo
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
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()));
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
} else {
|
||||
m_ShieldToStencilProgram->Bind();
|
||||
GLuint shaderHandle = m_ShieldToStencilProgram->GetHandle();
|
||||
@@ -523,10 +531,11 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list<std::shared_ptr<Rende
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = explosionEffectJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
if (explosionEffectJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = explosionEffectJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
if (GLERROR("Animation")) {
|
||||
continue;
|
||||
}
|
||||
@@ -558,10 +567,11 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list<std::shared_ptr<Rende
|
||||
//bind textures
|
||||
BindModelTextures(forwardHandle ,modelJob);
|
||||
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
|
||||
//draw
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
@@ -590,10 +600,11 @@ void DrawFinalPass::DrawToDepthBuffer(std::list<std::shared_ptr<RenderJob>>& job
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
} else {
|
||||
m_FillDepthBufferProgram->Bind();
|
||||
GLuint shaderHandle = m_FillDepthBufferProgram->GetHandle();
|
||||
|
||||
@@ -100,12 +100,10 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
|
||||
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
}
|
||||
} else {
|
||||
m_PickingProgram->Bind();
|
||||
@@ -155,9 +153,11 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
} else {
|
||||
m_PickingProgram->Bind();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
@@ -206,9 +206,11 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
|
||||
} else {
|
||||
m_PickingProgram->Bind();
|
||||
@@ -261,12 +263,10 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
|
||||
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
std::vector<glm::mat4> frameBones;
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
}
|
||||
} else {
|
||||
m_PickingProgram->Bind();
|
||||
|
||||
@@ -94,7 +94,7 @@ void Skeleton::AdditiveBoneTransforms(const Animation* animation, double time, s
|
||||
{
|
||||
if (animation->JointAnimations.find(bone->ID) != animation->JointAnimations.end()) {
|
||||
glm::mat4 refPose = GetAdditiveBonePose(bone, animation, 0.0);
|
||||
glm::mat4 srcPose = GetAdditiveBonePose(bone, animation, time);
|
||||
glm::mat4 srcPose = GetAdditiveBonePose(bone, animation, time + 1.0/60.0);
|
||||
glm::mat4 boneMatrix = srcPose * glm::inverse(refPose);
|
||||
boneMatrices[bone->ID] = boneMatrix;
|
||||
}
|
||||
@@ -335,21 +335,17 @@ std::map<int, glm::mat4> Skeleton::BlendPoseAdditive(const std::map<int, glm::ma
|
||||
return finalPose;
|
||||
}
|
||||
|
||||
std::vector<glm::mat4> Skeleton::GetFinalPose(std::map<int, glm::mat4>& boneMatrices)
|
||||
void Skeleton::GetFinalPose(std::map<int, glm::mat4>& boneMatrices, std::vector<glm::mat4>& finalPose, std::map<int, glm::mat4>& boneTransforms)
|
||||
{
|
||||
std::vector<glm::mat4> finalPose;
|
||||
|
||||
AccumulateFinalPose(boneMatrices, RootBone, glm::mat4(1));
|
||||
|
||||
AccumulateFinalPose(boneMatrices, boneTransforms, RootBone, glm::mat4(1));
|
||||
|
||||
for(auto& b : boneMatrices) {
|
||||
finalPose.push_back(b.second);
|
||||
}
|
||||
|
||||
return finalPose;
|
||||
}
|
||||
|
||||
void Skeleton::AccumulateFinalPose(std::map<int, glm::mat4>& boneMatrices, const Bone* bone, glm::mat4 parentMatrix)
|
||||
void Skeleton::AccumulateFinalPose(std::map<int, glm::mat4>& boneMatrices, std::map<int, glm::mat4>& boneTransforms, const Bone* bone, glm::mat4 parentMatrix)
|
||||
{
|
||||
|
||||
glm::mat4 boneMatrix;
|
||||
@@ -370,8 +366,10 @@ void Skeleton::AccumulateFinalPose(std::map<int, glm::mat4>& boneMatrices, const
|
||||
}
|
||||
}
|
||||
|
||||
boneTransforms[bone->ID] = boneMatrix;
|
||||
|
||||
for (auto &child : bone->Children) {
|
||||
AccumulateFinalPose(boneMatrices, child, boneMatrix);
|
||||
AccumulateFinalPose(boneMatrices, boneTransforms, child, boneMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user