Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions jme3-core/src/main/java/com/jme3/anim/tween/Tweens.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,28 @@ public static Tween loopDuration(double duration, Tween... delegates) {
return new Loop(sequence(delegates), duration);
}

/**
* Creates a tween that inverts the specified delegate tween.
*
* @param delegate the desired tween
* @return a new instance
*/
public static Tween invert(Tween delegate) {
return new Invert(delegate);
}

/**
* Creates a tween that will cycle back and forth the specified delegate tween.
* When reaching the end, the tween will play backwards from the end until it
* reaches the start.
*
* @param delegate the desired tween
* @return a new instance
*/
public static Tween cycle(Tween delegate) {
return sequence(delegate, invert(delegate));
}

private static interface CurveFunction {
public double curve(double input);
}
Expand Down Expand Up @@ -761,4 +783,29 @@ public String toString() {
return getClass().getSimpleName() + "[delegate=" + delegate[0] + ", length=" + length + "]";
}
}

private static class Invert extends AbstractTween implements ContainsTweens {

private final Tween[] delegate = new Tween[1];

public Invert( Tween delegate ) {
super(delegate.getLength());
this.delegate[0] = delegate;
}

@Override
protected void doInterpolate(double t) {
delegate[0].interpolate((1.0 - t) * getLength());
}

@Override
public Tween[] getTweens() {
return delegate;
}

@Override
public String toString() {
return getClass().getSimpleName() + "[delegate=" + delegate[0] + ", length=" + getLength() + "]";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package jme3test.model.anim;

import com.jme3.anim.*;
import com.jme3.anim.tween.Tweens;
import com.jme3.anim.tween.action.*;
import com.jme3.anim.util.AnimMigrationUtils;
import com.jme3.app.ChaseCameraAppState;
Expand Down Expand Up @@ -244,8 +245,11 @@ private void setupModel(Spatial model) {

composer.action("Walk").setSpeed(-1);

composer.addAction("WalkCycle", new BaseAction(Tweens.cycle(composer.makeAction("Walk"))));

composer.makeLayer("LeftArm", ArmatureMask.createMask(sc.getArmature(), "shoulder.L"));

anims.addFirst("WalkCycle");
anims.addFirst("Blend");
anims.addFirst("Sequence2");
anims.addFirst("Sequence1");
Expand Down