Support proper actuator animation
This commit is contained in:
@@ -16,10 +16,12 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs)
|
||||
int i, j;
|
||||
ch.mSkeleton->setBlendMode(
|
||||
Ogre::ANIMBLEND_CUMULATIVE);
|
||||
Ogre::String animNames[] = { "idle", "walking",
|
||||
"running",
|
||||
"treading_water",
|
||||
"swimming" };
|
||||
Ogre::String animNames[] = {
|
||||
"idle", "walking",
|
||||
"running", "treading_water",
|
||||
"swimming", "hanging-idle",
|
||||
"hanging-climb", "swimming-hold-edge"
|
||||
};
|
||||
int state_count = sizeof(animNames) /
|
||||
sizeof(animNames[0]);
|
||||
anim.mAnimationSystem =
|
||||
@@ -68,6 +70,19 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs)
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->state("actuator")
|
||||
->state_machine(ANIM_FADE_SPEED, "actuator-state")
|
||||
->state("hanging-idle")
|
||||
->animation("hanging-idle")
|
||||
->end()
|
||||
->state("swimming-hold-edge")
|
||||
->animation("swimming-hold-edge")
|
||||
->end()
|
||||
->state("hanging-climb")
|
||||
->animation("hanging-climb")
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end();
|
||||
/* clang-format on */
|
||||
|
||||
@@ -107,10 +122,13 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs)
|
||||
Ogre::Vector3 pos = ch.mBodyNode->getPosition();
|
||||
Ogre::Vector3 boneMotion = ch.mBoneMotion;
|
||||
v.velocity = rot * boneMotion / eng.delta;
|
||||
if (eng.startupDelay <= 0.0f)
|
||||
v.velocity += v.gvelocity;
|
||||
v.velocity.y = Ogre::Math::Clamp(v.velocity.y, -10.5f,
|
||||
1000000.0f);
|
||||
if (!e.has<CharacterDisablePhysics>() &&
|
||||
!e.has<CharacterInActuator>()) {
|
||||
if (eng.startupDelay <= 0.0f)
|
||||
v.velocity += v.gvelocity;
|
||||
v.velocity.y = Ogre::Math::Clamp(
|
||||
v.velocity.y, -10.5f, 1000000.0f);
|
||||
}
|
||||
});
|
||||
ecs.system<const EngineData, const AnimationControl,
|
||||
const CharacterBase, CharacterVelocity>("HandleSwimming")
|
||||
@@ -119,6 +137,8 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs)
|
||||
.with<WaterReady>()
|
||||
.with<InWater>()
|
||||
.with<CharacterBuoyancy>()
|
||||
.without<CharacterDisablePhysics>()
|
||||
.without<CharacterInActuator>()
|
||||
.each([this](flecs::entity e, const EngineData &eng,
|
||||
const AnimationControl &anim,
|
||||
const CharacterBase &ch, CharacterVelocity &gr) {
|
||||
@@ -204,11 +224,51 @@ CharacterAnimationModule::CharacterAnimationModule(flecs::world &ecs)
|
||||
next_state = "idle";
|
||||
state_machine->setAnimation(next_state);
|
||||
});
|
||||
ecs.system<const CharacterBase, const CharacterInActuator,
|
||||
AnimationControl>("HandlePlayerAnimationsActuator")
|
||||
.kind(flecs::OnUpdate)
|
||||
.with<Character>()
|
||||
.each([](flecs::entity e, const CharacterBase &ch,
|
||||
const CharacterInActuator &inact,
|
||||
AnimationControl &anim) {
|
||||
if (!anim.configured)
|
||||
return;
|
||||
AnimationNodeStateMachine *main_sm =
|
||||
anim.mAnimationSystem
|
||||
->get<AnimationNodeStateMachine>(
|
||||
"main");
|
||||
AnimationNodeStateMachine *actuator_sm =
|
||||
anim.mAnimationSystem
|
||||
->get<AnimationNodeStateMachine>(
|
||||
"actuator-state");
|
||||
Ogre::String current_state = main_sm->getCurrentState();
|
||||
if (current_state != "actuator")
|
||||
main_sm->setAnimation("actuator");
|
||||
actuator_sm->setAnimation(inact.animationState);
|
||||
});
|
||||
ecs.system<const CharacterBase, AnimationControl>(
|
||||
"HandlePlayerAnimationsNoActuator")
|
||||
.kind(flecs::OnUpdate)
|
||||
.with<Character>()
|
||||
.without<CharacterInActuator>()
|
||||
.each([](flecs::entity e, const CharacterBase &ch,
|
||||
AnimationControl &anim) {
|
||||
if (!anim.configured)
|
||||
return;
|
||||
AnimationNodeStateMachine *main_sm =
|
||||
anim.mAnimationSystem
|
||||
->get<AnimationNodeStateMachine>(
|
||||
"main");
|
||||
Ogre::String current_state = main_sm->getCurrentState();
|
||||
if (current_state != "locomotion")
|
||||
main_sm->setAnimation("locomotion");
|
||||
});
|
||||
ecs.system<const Input, const CharacterBase, AnimationControl>(
|
||||
"HandlePlayerAnimations")
|
||||
.kind(flecs::OnUpdate)
|
||||
.with<Character>()
|
||||
.with<Player>()
|
||||
.without<CharacterInActuator>()
|
||||
.each([](flecs::entity e, const Input &input,
|
||||
const CharacterBase &ch, AnimationControl &anim) {
|
||||
if (!anim.configured)
|
||||
|
||||
Reference in New Issue
Block a user