Skip to content

Commit

Permalink
Idle first ClipAction, Continue second only after 1st run
Browse files Browse the repository at this point in the history
  • Loading branch information
pavly-gerges committed May 13, 2021
1 parent 4610505 commit b65e49d
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
import com.jme3.anim.util.HasLocalTransform;
import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import com.jme3.cinematic.Cinematic;
import com.jme3.cinematic.events.AnimEvent;
import com.jme3.cinematic.events.AnimationEvent;
import com.jme3.cinematic.events.CinematicEvent;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
Expand All @@ -36,9 +41,11 @@ public class BlendableAnimation extends BaseAppState implements BlendSpace {
private final Spatial dataBaseStack;
//create a global AnimComposer Control instance
private AnimComposer animComposer;
private LinearBlendSpace linearBlendSpace;
private ClipAction capRotationClip;
private BlendAction blendAction;
private BaseAction baseAction;
private float count = 0;
public BlendableAnimation(final String id, final Spatial dataBaseStack){
super(id);
this.dataBaseStack=dataBaseStack;
Expand Down Expand Up @@ -91,12 +98,16 @@ protected void initialize(Application app) {
capRotationClip.setLength(10f);
capRotationClip.setTransitionLength(10f);
//9)feed the BlendableActions to a single BlendAction
blendAction=new BlendAction(new LinearBlendSpace(5,10), bottleTractionClip, capRotationClip);
float minValueOfBlendSlider = 6;
float maxValueOfBlendSlider = 12;
linearBlendSpace = new LinearBlendSpace(minValueOfBlendSlider, maxValueOfBlendSlider);
linearBlendSpace.setValue(FastMath.interpolateLinear(0.5f, 6, 12));
blendAction=new BlendAction(linearBlendSpace, capRotationClip, bottleTractionClip);
baseAction=new BaseAction(Tweens.sequence(capRotationClip, blendAction));
baseAction.setLength(10f);
baseAction.setSpeed(2f);
//10)add that BlendAction to the AnimComposer using addAction(...)
animComposer.addAction("SimulateBottleFall", baseAction);
animComposer.addAction("SimulateBottleFall", blendAction);
animComposer.makeLayer(LayerBuilder.LAYER_BLENDABLE_ANIM, new ArmatureMask());

}
Expand Down Expand Up @@ -124,6 +135,14 @@ protected void onDisable() {
}
}

@Override
public void update(float tpf) {
count += tpf;
if(count > blendAction.getLength()){
linearBlendSpace.setValue(FastMath.interpolateLinear(1, 6, 12));
}
}

/**
* additional method for additional settings to set during the instantiation of #{@link BlendAction} instance
* this method gets called inside the Constructor of #{@link BlendAction#BlendAction(BlendSpace, BlendableAction...)} when the BlendAction instance gets instantiated\.
Expand Down Expand Up @@ -175,8 +194,7 @@ public void setBlendAction(BlendAction action) {
*/
@Override
public float getWeight() {
capRotationClip.setCollectTransformDelegate(blendAction);
return 1.5f;
return 1;
}

/**
Expand Down

0 comments on commit b65e49d

Please sign in to comment.