Bug in AnimationTrack

Hello, there is a bug in AnimationTrack that did not exist before and looks like it occurs now with the latest nightly. I thought I would point it out. Attached is a testCase. Cuboid moves to a certain location. Using “=” the hotkey for increasing the animation speed, try increasing the speed to 2 or 3 (by pressing “=” 3 times) and the cuboid will still move at the same speed then suddenly jump abruptly and catch up with the new animation speed.



Thanks



[java]

package mygame;





import com.jme3.animation.AnimControl;

import com.jme3.animation.AnimationFactory;

import com.jme3.cinematic.Cinematic;

import com.jme3.cinematic.events.CinematicEvent;

import com.jme3.app.SimpleApplication;

import com.jme3.cinematic.PlayState;

import com.jme3.cinematic.events.AnimationTrack;

import com.jme3.cinematic.events.CinematicEventListener;

import com.jme3.input.ChaseCamera;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.post.FilterPostProcessor;

import com.jme3.post.filters.FadeFilter;

import com.jme3.scene.Geometry;

import com.jme3.scene.Spatial;

import com.jme3.scene.shape.Box;

import java.util.concurrent.Callable;

import java.util.concurrent.ScheduledThreadPoolExecutor;



public class TimeTest extends SimpleApplication {



private Spatial model;

private Cinematic cinematic;

private ChaseCamera chaseCam;

private ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(2);





public static void main(String[] args) {

TimeTest app = new TimeTest();

app.start();



}



@Override

public void simpleInitApp() {



createScene();



cinematic = new Cinematic(rootNode, 1000);

stateManager.attach(cinematic);



AnimationFactory factory = new AnimationFactory(10, “animation”);

factory.addTimeTranslation(0, new Vector3f(0, 0, 0));

factory.addTimeTranslation(10, new Vector3f(5, 0, 0));



AnimControl control = model.getControl(AnimControl.class);

if( control == null){

control = new AnimControl();

model.addControl(control);

}



control.addAnim(factory.buildAnimation());



cinematic.addCinematicEvent(0, new AnimationTrack(model, “animation”));



AnimationFactory factory2 = new AnimationFactory(10, “animation2”);

factory2.addTimeTranslation(0, new Vector3f(5, 0, 0));

factory2.addTimeTranslation(10, new Vector3f(0, 0, 0));



AnimControl control2 = model.getControl(AnimControl.class);

if( control2 == null){

control2 = new AnimControl();

model.addControl(control2);

}



control2.addAnim(factory2.buildAnimation());



cinematic.addCinematicEvent(10.1f, new AnimationTrack(model, “animation2”));





cinematic.addListener(new CinematicEventListener() {



public void onPlay(CinematicEvent s) {

chaseCam.setEnabled(false);

System.out.println(“play”);

System.out.println("Animation Speed: " + cinematic.getSpeed());

System.out.println("Animation State: " + cinematic.getPlayState());

System.out.println("Animation Time: " + cinematic.getTime());

}



public void onPause(CinematicEvent cinematic) {

chaseCam.setEnabled(false);

System.out.println(“pause”);

System.out.println("Animation Speed: " + cinematic.getSpeed());

System.out.println("Animation State: " + cinematic.getPlayState());

System.out.println("Animation Time: " + cinematic.getTime());

}



public void onStop(CinematicEvent cinematic) {

chaseCam.setEnabled(false);

// fade.setValue(1);

System.out.println(“stop”);

}

});



flyCam.setEnabled(false);

chaseCam = new ChaseCamera(cam, model, inputManager);



initInputs();

cinematic.setSpeed(1);







}











private void createScene() {







Box drive_unit = new Box(new Vector3f(0, 0, 0), 1, .25f, .5f); // must take from config xml file (TODO)

model = new Geometry(“Drive #”, drive_unit);

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat1.setColor(“Color”, ColorRGBA.Orange);

model.setMaterial(mat1);



model.center();

//podModel.center();



rootNode.attachChild(model);





Material matSoil = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

matSoil.setBoolean(“UseMaterialColors”, true);

matSoil.setColor(“Ambient”, ColorRGBA.Gray);

matSoil.setColor(“Diffuse”, ColorRGBA.Green);

matSoil.setColor(“Specular”, ColorRGBA.Black);



}





private void initInputs() {

inputManager.addMapping(“togglePause”, new KeyTrigger(keyInput.KEY_RETURN));

inputManager.addMapping(“increaseSpeed”, new KeyTrigger(keyInput.KEY_EQUALS));

ActionListener acl = new ActionListener() {



public void onAction(String name, boolean keyPressed, float tpf) {

if (name.equals(“togglePause”) && keyPressed) {

if (cinematic.getPlayState() == PlayState.Playing) {

cinematic.pause();

} else {

cinematic.play();

}

}



else if (name.equals(“increaseSpeed”) && keyPressed) {



//pause to maintain animation accuracy

//cinematic.pause();

exec.submit(increaseSpeed);

}





}

};

inputManager.addListener(acl, “togglePause”);

inputManager.addListener(acl, “increaseSpeed”);

}





Callable increaseSpeed = new Callable() {



public Object call() throws Exception {

try {



TimeTest.this.enqueue(new Callable<Void>() {



public Void call() throws Exception {

//cinematic.pause();

cinematic.setSpeed(cinematic.getSpeed() + 1);

return null;

}

});



} catch (Exception nFE) {

// do nothing just cancel command

}

return null;

}

};

}

[/java]

1 Like

This may or might not be related, but I also have a problem with MotionTrack/MotionPath after a recent nightly build:



“onWayPointReach” is no longer being triggered for the FINAL waypoint in all my paths, but instead the spatial is snapped back to the starting point after reaching the end of the path (maybe just before the last waypoint is reached, causing it not to trigger?)



I wasn’t going to mention it yet 'coz I’m not at my computer to investigate it, but this behaviour only started happening after a recent nightly build, and might be related to the OP’s problem.



Jon :slight_smile:

@nehon I know we’ve bugged you so much in this but could you please take a look whenever you get a chance? It used to work fine until some nightly update (I couldn’t tell which one) and I don’t want to revert all the way back to stable.



I’ve been trying to look at this for quite some time and can’t figure out what’s causing this bump.

It should work now.

Also i wonder how it could have worked before…it was not implemented for AnimationTrack…

@jonmonkey said:
This may or might not be related, but I also have a problem with MotionTrack/MotionPath after a recent nightly build:

"onWayPointReach" is no longer being triggered for the FINAL waypoint in all my paths, but instead the spatial is snapped back to the starting point after reaching the end of the path (maybe just before the last waypoint is reached, causing it not to trigger?)

I wasn't going to mention it yet 'coz I'm not at my computer to investigate it, but this behaviour only started happening after a recent nightly build, and might be related to the OP's problem.

Jon :)

it's not related but still an issue.
I have the onWayPointReach issue, but i don't have the snap back to start problem.
could you provide a test case?

the waypoint problem is fixed.
1 Like

Thanks nehon… the “snapping” problem was some extraneous code I’d put in (as a workaround for the last waypoint not triggering)