3rd person animations synced with 1st person animations

This commit is contained in:
viktorljung
2016-03-09 18:27:09 +01:00
parent 7141756992
commit d42d886dcc
8 changed files with 107 additions and 87 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ struct EntityWrapper
static const EntityWrapper Invalid;
const std::string Name();
const std::string Name() const;
bool HasComponent(const std::string& componentType);
void AttachComponent(const char* componentName);
EntityWrapper Parent();
@@ -153,6 +153,31 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
m_EventBroker->Publish(aeb);
}
}
EntityWrapper firstPersonModel = m_PlayerEntity.FirstChildByName("Hands");
if (firstPersonModel.Valid()) {
if (val > 0) { // Walk/Run
if (!m_Crouching) {
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.1;
aeb.NodeName = "Run";
aeb.RootNode = firstPersonModel;
aeb.Start = true;
m_EventBroker->Publish(aeb);
}
} else if (val < 0) { // Walk/run Backwards
if (!m_Crouching) {
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.1;
aeb.NodeName = "Run";
aeb.RootNode = firstPersonModel;
aeb.Start = true;
aeb.Reverse = true;
m_EventBroker->Publish(aeb);
}
}
}
}
}
if (e.Command == "Right") {
@@ -187,27 +212,36 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
}
//Animation
if (glm::length2(m_Movement) < 0.1f) {
if (glm::length2(m_Movement) < 0.25f) {
//Blend to Idle
if (m_PlayerEntity.Valid()) {
EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel");
if (playerModel.Valid()) {
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.2;
aeb.Duration = 0.1;
aeb.NodeName = "Idle";
aeb.RootNode = playerModel;
aeb.Start = true;
m_EventBroker->Publish(aeb);
}
EntityWrapper firstPersonModel = m_PlayerEntity.FirstChildByName("Hands");
if (firstPersonModel.Valid()) {
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.1;
aeb.NodeName = "Idle";
aeb.RootNode = firstPersonModel;
aeb.Start = true;
m_EventBroker->Publish(aeb);
}
}
} else {
//Blend to movement
if (m_PlayerEntity.Valid()) {
EntityWrapper playerModel = m_PlayerEntity.FirstChildByName("PlayerModel");
if (playerModel.Valid()) {
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.2;
aeb.NodeName = "MovementBlend";
aeb.Duration = 0.1;
aeb.NodeName = "DirectionBlend";
aeb.RootNode = playerModel;
m_EventBroker->Publish(aeb);
}
@@ -226,7 +260,7 @@ bool FirstPersonInputController<EventContext>::OnCommand(const Events::InputComm
glm::vec2 direction = glm::normalize(glm::vec2(m_Movement.x, m_Movement.z));
double weight = glm::abs(glm::dot(glm::vec2(1, 0), direction));
Events::SetBlendWeight sbw;
sbw.NodeName = "MovementBlend";
sbw.NodeName = "DirectionBlend";
sbw.Weight = weight;
sbw.RootNode = playerModel;
m_EventBroker->Publish(sbw);
+49 -43
View File
@@ -2,7 +2,6 @@
<Entity name="PlayerAssault" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:NetworkComponent/>
<c:AABB>
<Origin X="0" Y="0.772000015" Z="0"/>
<Size X="1" Y="1.60000002" Z="1"/>
@@ -22,6 +21,7 @@
</c:DefenderWeapon>
<c:DoubleJump/>
<c:Health/>
<c:NetworkComponent/>
<c:Physics>
<Velocity X="2.30999646e-23" Y="0" Z="1.05272533e-23"/>
</c:Physics>
@@ -463,7 +463,7 @@
<Color A="1" B="0.392156869" G="0.392156869" R="0.392156869"/>
</c:Fill>
<c:Sprite>
<DiffuseTexture>Textures/Icons/Abilities/Superman-01.png</DiffuseTexture>
<DiffuseTexture>Textures\Icons\Abilities\Superman-01.png</DiffuseTexture>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="1" B="0.206628323" G="0.78039217" R="0.192802757"/>
@@ -504,25 +504,25 @@
<Children>
<Entity name="PrimaryAttachment">
<Components>
<c:WeaponAttachment>
<Weapon>AssaultWeapon</Weapon>
</c:WeaponAttachment>
<c:Spawner>
<EntityFile>Schema/Entities/WeaponAssaultBlueView.xml</EntityFile>
</c:Spawner>
<c:Transform/>
<c:WeaponAttachment>
<Weapon>AssaultWeapon</Weapon>
</c:WeaponAttachment>
</Components>
<Children/>
</Entity>
<Entity name="SecondaryAttachment">
<Components>
<c:WeaponAttachment>
<Weapon>DefenderWeapon</Weapon>
</c:WeaponAttachment>
<c:Spawner>
<EntityFile>Schema/Entities/WeaponDefenderBlueView.xml</EntityFile>
</c:Spawner>
<c:Transform/>
<c:WeaponAttachment>
<Weapon>DefenderWeapon</Weapon>
</c:WeaponAttachment>
</Components>
<Children/>
</Entity>
@@ -566,19 +566,19 @@
<c:BoneAttachment>
<BoneName>R_Arm_Weapon_Joint</BoneName>
</c:BoneAttachment>
<c:Spawner>
<EntityFile>Schema/Entities/WeaponAssaultBlueWorld.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="0.17052114" Y="1.03320956" Z="-0.224843055"/>
<Orientation X="-0.035638921" Y="-0.0872893855" Z="0.133119702"/>
</c:Transform>
<c:WeaponAttachment>
<Weapon>AssaultWeapon</Weapon>
<Person>
<ThirdPerson/>
</Person>
</c:WeaponAttachment>
<c:Spawner>
<EntityFile>Schema/Entities/WeaponAssaultBlueWorld.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="0.153499424" Y="1.04221034" Z="-0.231716871"/>
<Orientation X="-0.0108785164" Y="-0.0253766086" Z="0.137640417"/>
</c:Transform>
</Components>
<Children/>
</Entity>
@@ -587,26 +587,26 @@
<c:BoneAttachment>
<BoneName>R_Arm_Weapon_Joint</BoneName>
</c:BoneAttachment>
<c:Spawner>
<EntityFile>Schema/Entities/SidearmWeaponWorld.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="0.17052114" Y="1.03320956" Z="-0.224843055"/>
<Orientation X="-0.035638921" Y="-0.0872893855" Z="0.133119702"/>
</c:Transform>
<c:WeaponAttachment>
<Weapon>SidearmWeapon</Weapon>
<Person>
<ThirdPerson/>
</Person>
</c:WeaponAttachment>
<c:Spawner>
<EntityFile>Schema/Entities/SidearmWeaponWorld.xml</EntityFile>
</c:Spawner>
<c:Transform>
<Position X="0.153499424" Y="1.04221034" Z="-0.231716871"/>
<Orientation X="-0.0108785164" Y="-0.0253766086" Z="0.137640417"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="BlendTreeLower">
<Components>
<c:Blend>
<Pose1>StandCrouchBlend</Pose1>
<Pose1>MovementBlend</Pose1>
<Pose2>JumpDashBlend</Pose2>
<Weight>2.5146881298480398e-63</Weight>
<SubTreeRoot>true</SubTreeRoot>
@@ -628,7 +628,7 @@
<Entity name="CrouchMovement">
<Components>
<c:Blend>
<Pose1>MovementBlend</Pose1>
<Pose1>DirectionBlend</Pose1>
<Pose2>Idle</Pose2>
<Weight>1</Weight>
</c:Blend>
@@ -659,7 +659,7 @@
<Components>
<c:Animation>
<AnimationName>CrouchStrafeLeftF</AnimationName>
<Time>0.15801023731376773</Time>
<Time>0.79179726223533642</Time>
<Play>true</Play>
</c:Animation>
<c:Transform/>
@@ -670,7 +670,7 @@
<Components>
<c:Animation>
<AnimationName>CrouchStrafeRightF</AnimationName>
<Time>0.085331699264550309</Time>
<Time>0.719118724186119</Time>
<Play>true</Play>
</c:Animation>
<c:Transform/>
@@ -683,7 +683,7 @@
<Components>
<c:Animation>
<AnimationName>CrouchWalkF</AnimationName>
<Time>0.86370568444195328</Time>
<Time>0.49749270936352197</Time>
<Play>true</Play>
</c:Animation>
<c:Transform/>
@@ -696,7 +696,8 @@
<Components>
<c:Animation>
<AnimationName>CrouchF</AnimationName>
<Time>0.99862473341677438</Time>
<Time>1.1707202063102131</Time>
<Play>true</Play>
</c:Animation>
<c:Transform/>
</Components>
@@ -707,7 +708,7 @@
<Entity name="StandMovement">
<Components>
<c:Blend>
<Pose1>MovementBlend</Pose1>
<Pose1>DirectionBlend</Pose1>
<Pose2>Idle</Pose2>
<Weight>1</Weight>
</c:Blend>
@@ -738,7 +739,7 @@
<Components>
<c:Animation>
<AnimationName>WalkF</AnimationName>
<Time>0.36886031385172657</Time>
<Time>0.0026473387732952602</Time>
<Play>true</Play>
</c:Animation>
<c:Transform/>
@@ -749,7 +750,8 @@
<Components>
<c:Animation>
<AnimationName>RunF</AnimationName>
<Time>0.64087381787562947</Time>
<Time>0.60179430680919843</Time>
<Speed>2</Speed>
<Play>true</Play>
</c:Animation>
<c:Transform/>
@@ -772,7 +774,8 @@
<Components>
<c:Animation>
<AnimationName>StrafeLeftF</AnimationName>
<Time>0.55045293488526426</Time>
<Time>0.20450294221067544</Time>
<Speed>2</Speed>
<Play>true</Play>
</c:Animation>
<c:Transform/>
@@ -783,7 +786,8 @@
<Components>
<c:Animation>
<AnimationName>StrafeRightF</AnimationName>
<Time>0.57396846476537888</Time>
<Time>0.28191395104664174</Time>
<Speed>2</Speed>
<Play>true</Play>
</c:Animation>
<c:Transform/>
@@ -798,7 +802,7 @@
<Components>
<c:Animation>
<AnimationName>IdleF</AnimationName>
<Time>1.0177411602680451</Time>
<Time>0.96819454985941356</Time>
<Play>true</Play>
</c:Animation>
<c:Transform/>
@@ -856,7 +860,7 @@
<c:Animation>
<AnimationName>DashForwardF</AnimationName>
<Time>1</Time>
<Speed>2</Speed>
<Speed>1.7999999523162842</Speed>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
@@ -868,7 +872,7 @@
<c:Animation>
<AnimationName>DashBackwardF</AnimationName>
<Time>1</Time>
<Speed>2</Speed>
<Speed>1.7999999523162842</Speed>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
@@ -887,24 +891,24 @@
<c:Transform/>
</Components>
<Children>
<Entity name="DashLeft">
<Entity name="DashRight">
<Components>
<c:Animation>
<AnimationName>DashLeftF</AnimationName>
<AnimationName>DashRightF</AnimationName>
<Time>1</Time>
<Speed>2</Speed>
<Speed>1.7999999523162842</Speed>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="DashRight">
<Entity name="DashLeft">
<Components>
<c:Animation>
<AnimationName>DashRightF</AnimationName>
<AnimationName>DashLeftF</AnimationName>
<Time>1</Time>
<Speed>2</Speed>
<Speed>1.7999999523162842</Speed>
<Loop>false</Loop>
</c:Animation>
<c:Transform/>
@@ -981,7 +985,7 @@
</Entity>
</Children>
</Entity>
<Entity name="MovementBlend">
<Entity name="MovementBlend2">
<Components>
<c:Blend>
<Pose1>Idle</Pose1>
@@ -995,6 +999,7 @@
<Components>
<c:Animation>
<AnimationName>IdleAssaultRifleU</AnimationName>
<Time>1.6337870249215687</Time>
<Play>true</Play>
<Additive>true</Additive>
</c:Animation>
@@ -1006,6 +1011,7 @@
<Components>
<c:Animation>
<AnimationName>IdleAssaultRifleU</AnimationName>
<Time>1.6337870249215687</Time>
<Play>true</Play>
<Additive>true</Additive>
</c:Animation>
+1 -1
View File
@@ -3,7 +3,7 @@
const EntityWrapper EntityWrapper::Invalid = EntityWrapper(nullptr, EntityID_Invalid);
const std::string EntityWrapper::Name()
const std::string EntityWrapper::Name() const
{
return World->GetName(ID);
}
+4 -1
View File
@@ -127,9 +127,12 @@ void AnimationSystem::UpdateAnimations(double dt)
void AnimationSystem::UpdateWeights(double dt)
{
for (auto it = m_AutoBlendQueues.begin(); it != m_AutoBlendQueues.end(); ) {
LOG_INFO("%s", it->first.Name().c_str());
it->second.PrintQueue();
if(it->second.HasActiveBlendJob()) {
AutoBlendQueue::AutoBlendJob& blendJob = it->second.GetActiveBlendJob();
LOG_INFO("%s", blendJob.RootNode.Name().c_str());
std::shared_ptr<BlendTree> blendTree = it->second.GetBlendTree();
if (blendTree != nullptr) {
if (blendJob.Duration != 0.0) {
-2
View File
@@ -214,7 +214,6 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
}
}
}
return blendInfo;
}
@@ -333,7 +332,6 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
}
}
}
}
return blendInfo;
+11 -23
View File
@@ -85,7 +85,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
// Set third person model aim pitch
EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
if (playerModel.Valid()) {
EntityWrapper aimPrimaryEntity = playerModel.FirstChildByName("AimPrimary");
EntityWrapper aimPrimaryEntity = playerModel.FirstChildByName("Aim");
if(aimPrimaryEntity.Valid()){
if(aimPrimaryEntity.HasComponent("Animation")) {
float pitch = cameraOrientation.x;
@@ -93,14 +93,6 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
(double&)aimPrimaryEntity["Animation"]["Time"] = time;
}
}
EntityWrapper aimSecondaryEntity = playerModel.FirstChildByName("AimSecondary");
if (aimSecondaryEntity.Valid()) {
if (aimSecondaryEntity.HasComponent("Animation")) {
float pitch = cameraOrientation.x;
double time = (pitch + glm::half_pi<float>()) / glm::pi<float>();
(double&)aimSecondaryEntity["Animation"]["Time"] = time;
}
}
}
}
@@ -212,7 +204,7 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.25;
aeb.NodeName = "StandCrouchBlend";
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Start = true;
aeb.Restart = false;
@@ -243,11 +235,11 @@ void PlayerMovementSystem::updateMovementControllers(double dt)
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.25;
aeb.NodeName = "StandCrouchBlend";
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("Jump");
aeb.AnimationEntity = playerModel.FirstChildByName("BlendTreeLower").FirstChildByName("Jump");
m_EventBroker->Publish(aeb);
}
}
@@ -376,12 +368,12 @@ void PlayerMovementSystem::spawnHexagon(EntityWrapper target)
bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
{
EntityWrapper player(m_World, e.Player);
if (!player.Valid() || !IsClient){// || player.ID == LocalPlayer.ID) {
if (!player.Valid()){// || !IsClient || player.ID == LocalPlayer.ID) {
return false;
}
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/DashEffect.xml");
EntityWrapper dashEffect = entityFile->MergeInto(m_World);
// auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/DashEffect.xml");
// EntityWrapper dashEffect = entityFile->MergeInto(m_World);
EntityWrapper playerModel = player.FirstChildByName("PlayerModel");
for (auto& kv : m_PlayerInputControllers) {
@@ -409,9 +401,8 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.2;
aeb.NodeName = "StandCrouchBlend";
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Delay = 0.2;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("DashRight");
@@ -430,9 +421,8 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.2;
aeb.NodeName = "StandCrouchBlend";
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Delay = 0.2;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("DashLeft");
@@ -453,9 +443,8 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.2;
aeb.NodeName = "StandCrouchBlend";
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Delay = 0.2;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("DashForward");
@@ -474,9 +463,8 @@ bool PlayerMovementSystem::OnDashAbility(Events::DashAbility & e)
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.2;
aeb.NodeName = "StandCrouchBlend";
aeb.NodeName = "MovementBlend";
aeb.RootNode = playerModel;
aeb.Delay = 0.2;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = playerModel.FirstChildByName("DashBackward");
@@ -133,11 +133,6 @@ void AssaultWeaponBehaviour::OnReload(ComponentWrapper cWeapon, WeaponInfo& wi)
b1.Restart = true;
b1.Start = true;
m_EventBroker->Publish(b1);
Events::AutoAnimationBlend b2;
b2.RootNode = wi.ThirdPersonPlayerModel;
b2.NodeName = "MovementBlend";
b2.AnimationEntity = wi.ThirdPersonPlayerModel.FirstChildByName("AssaultWeaponBlend").FirstChildByName("Reload");
m_EventBroker->Publish(b2);
// Spawn explosion effect
if (wi.FirstPersonEntity.Valid()) {
@@ -247,6 +242,7 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
// Play animation
playAnimationAndReturn(wi.FirstPersonEntity, "ActionBlend", "Fire");
// Third person anim
Events::AutoAnimationBlend b1;
b1.RootNode = wi.ThirdPersonPlayerModel;
@@ -254,11 +250,6 @@ void AssaultWeaponBehaviour::fireBullet(ComponentWrapper cWeapon, WeaponInfo& wi
b1.Restart = true;
b1.Start = true;
m_EventBroker->Publish(b1);
Events::AutoAnimationBlend b2;
b2.RootNode = wi.ThirdPersonPlayerModel;
b2.NodeName = "MovementBlend";
b2.AnimationEntity = wi.ThirdPersonPlayerModel.FirstChildByName("AssaultWeaponBlend").FirstChildByName("Fire");
m_EventBroker->Publish(b2);
// Sound
Events::PlaySoundOnEntity e;