interrupting animations
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
d7e20f0970
commit
d319f05a2e
@ -109,7 +109,10 @@ public class StateTransitionUtil {
|
||||
animation = state.getAnimation.get();
|
||||
}
|
||||
|
||||
//Main simulation
|
||||
|
||||
//
|
||||
//Play main animation
|
||||
//
|
||||
if(!actor.isPlayingAnimation() && state.onComplete != null && state.startedAnimation == true){
|
||||
//state transition if this isn't set to loop
|
||||
state.onComplete.run();
|
||||
@ -138,6 +141,10 @@ public class StateTransitionUtil {
|
||||
state.onComplete.run();
|
||||
state.startedAnimation = false;
|
||||
}
|
||||
|
||||
//
|
||||
//Play animation in first person
|
||||
//
|
||||
if(animation != null){
|
||||
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, animation);
|
||||
}
|
||||
@ -160,6 +167,10 @@ public class StateTransitionUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
//Play main animation
|
||||
//
|
||||
if(animation == null){
|
||||
state.startedAnimation = true;
|
||||
if(state.onComplete != null){
|
||||
@ -193,7 +204,7 @@ public class StateTransitionUtil {
|
||||
|
||||
//Gets the first person animation
|
||||
Supplier<TreeDataAnimation> getAnimation;
|
||||
|
||||
|
||||
//The audio data
|
||||
TreeDataAudio audioData;
|
||||
|
||||
|
||||
@ -122,6 +122,22 @@ public class FirstPersonTree implements BehaviorTree {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays an animation if it exists
|
||||
* @param animationName the name of the animation
|
||||
*/
|
||||
public void interruptAnimation(TreeDataAnimation animation){
|
||||
if(Globals.firstPersonEntity != null){
|
||||
Actor actor = EntityUtils.getActor(Globals.firstPersonEntity);
|
||||
if(
|
||||
(actor.isPlayingAnimation() || actor.isPlayingAnimation(animation.getNameFirstPerson())) &&
|
||||
(Globals.assetManager.fetchModel(actor.getModelPath()) != null && Globals.assetManager.fetchModel(actor.getModelPath()).getAnimation(animation.getNameFirstPerson()) != null)
|
||||
){
|
||||
actor.interruptAnimation(animation, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the entity has a first person tree, plays the provided animation
|
||||
* @param entity The entity
|
||||
@ -145,4 +161,15 @@ public class FirstPersonTree implements BehaviorTree {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the entity has a first person tree, interrupts the provided animation
|
||||
* @param entity The entity
|
||||
* @param animation The animation
|
||||
*/
|
||||
public static void conditionallyInterruptAnimation(Entity entity, TreeDataAnimation animation){
|
||||
if(entity != null && FirstPersonTree.hasTree(entity)){
|
||||
FirstPersonTree.getTree(entity).interruptAnimation(animation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package electrosphere.entity.state.life;
|
||||
|
||||
|
||||
import electrosphere.net.parser.net.message.SynchronizationMessage;
|
||||
import electrosphere.net.synchronization.BehaviorTreeIdEnums;
|
||||
import electrosphere.entity.btree.BehaviorTree;
|
||||
import electrosphere.entity.btree.StateTransitionUtil;
|
||||
|
||||
@ -279,6 +279,39 @@ public class Actor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupts an animation, thereby causing it to stop playing
|
||||
* @param animation The animation to interrupt
|
||||
*/
|
||||
public void interruptAnimation(TreeDataAnimation animation, boolean isThirdPerson){
|
||||
//Get the animation's name
|
||||
String animationName = "";
|
||||
if(isThirdPerson){
|
||||
animationName = animation.getNameThirdPerson();
|
||||
} else {
|
||||
animationName = animation.getNameFirstPerson();
|
||||
}
|
||||
|
||||
//Get the animation's priority
|
||||
int priority = AnimationPriorities.getValue(AnimationPriorities.DEFAULT);
|
||||
if(animation.getPriority() != null){
|
||||
priority = animation.getPriority();
|
||||
}
|
||||
if(animation.getPriorityCategory() != null){
|
||||
priority = AnimationPriorities.getValue(animation.getPriorityCategory());
|
||||
}
|
||||
|
||||
toRemoveMasks.clear();
|
||||
for(ActorAnimationMask mask : this.animationQueue){
|
||||
if(mask.animationName == animationName && mask.priority == priority){
|
||||
toRemoveMasks.add(mask);
|
||||
}
|
||||
}
|
||||
for(ActorAnimationMask currentMask : toRemoveMasks){
|
||||
animationQueue.remove(currentMask);
|
||||
}
|
||||
}
|
||||
|
||||
public void playAnimationWithMask(String animationName, int priority, List<String> boneMask){
|
||||
Model model = Globals.assetManager.fetchModel(modelPath);
|
||||
if(model != null){
|
||||
|
||||
@ -255,6 +255,39 @@ public class PoseActor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupts an animation, thereby causing it to stop playing
|
||||
* @param animation The animation to interrupt
|
||||
*/
|
||||
public void interruptAnimation(TreeDataAnimation animation, boolean isThirdPerson){
|
||||
//Get the animation's name
|
||||
String animationName = "";
|
||||
if(isThirdPerson){
|
||||
animationName = animation.getNameThirdPerson();
|
||||
} else {
|
||||
animationName = animation.getNameFirstPerson();
|
||||
}
|
||||
|
||||
//Get the animation's priority
|
||||
int priority = AnimationPriorities.getValue(AnimationPriorities.DEFAULT);
|
||||
if(animation.getPriority() != null){
|
||||
priority = animation.getPriority();
|
||||
}
|
||||
if(animation.getPriorityCategory() != null){
|
||||
priority = AnimationPriorities.getValue(animation.getPriorityCategory());
|
||||
}
|
||||
|
||||
toRemoveMasks.clear();
|
||||
for(ActorAnimationMask mask : this.animationQueue){
|
||||
if(mask.getAnimationName() == animationName && mask.getPriority() == priority){
|
||||
toRemoveMasks.add(mask);
|
||||
}
|
||||
}
|
||||
for(ActorAnimationMask currentMask : toRemoveMasks){
|
||||
animationQueue.remove(currentMask);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play an animation with a mask that makes the animation only apply to specific bones
|
||||
* @param animationName The name of the animation
|
||||
|
||||
Loading…
Reference in New Issue
Block a user