From 07e96d02eba6fdda5a29f7c39289a5c59a8e22ca Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Mon, 12 Mar 2012 20:43:07 +0000 Subject: [PATCH] Fixed an issue in AnimationTrack when time was skipped out of bounds of the animation git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9245 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../core/com/jme3/cinematic/Cinematic.java | 20 +++++++++---------- .../jme3/cinematic/events/AnimationTrack.java | 19 +++++++++++++++--- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/engine/src/core/com/jme3/cinematic/Cinematic.java b/engine/src/core/com/jme3/cinematic/Cinematic.java index 70d23704e..70eebf03a 100644 --- a/engine/src/core/com/jme3/cinematic/Cinematic.java +++ b/engine/src/core/com/jme3/cinematic/Cinematic.java @@ -35,10 +35,8 @@ import com.jme3.animation.LoopMode; import com.jme3.app.Application; import com.jme3.app.state.AppState; import com.jme3.app.state.AppStateManager; -import com.jme3.asset.TextureKey; import com.jme3.cinematic.events.AbstractCinematicEvent; import com.jme3.cinematic.events.CinematicEvent; -import com.jme3.cinematic.events.CinematicEventListener; import com.jme3.export.*; import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; @@ -112,6 +110,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { lastFetchedKeyFrame = -1; for (int i = 0; i < cinematicEvents.size(); i++) { CinematicEvent ce = cinematicEvents.get(i); + ce.setTime(0); ce.stop(); } enableCurrentCam(false); @@ -217,26 +216,27 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { @Override public void setTime(float time) { - super.setTime(time); + //stopping all events - for (CinematicEvent ce : cinematicEvents) { - ce.stop(); - } + onStop(); + super.setTime(time); + int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time); //triggering all the event from start to "time" - //then computing timeOffset for each event - for (KeyFrame keyFrame : timeLine.values()) { - //KeyFrame keyFrame = timeLine.get(timeLine.keySet()); + //then computing timeOffset for each event + for (int i = 0; i <= keyFrameIndex; i++) { + KeyFrame keyFrame = timeLine.get(i); if (keyFrame != null) { for (CinematicEvent ce : keyFrame.getCinematicEvents()) { float t = this.time - timeLine.getKeyFrameTime(keyFrame); if (t >= 0 && (t <= ce.getInitialDuration() || ce.getLoopMode() != LoopMode.DontLoop)) { ce.play(); - ce.setTime(t); } + ce.setTime(t); } } } + lastFetchedKeyFrame = keyFrameIndex; if (playState != PlayState.Playing) { pause(); } diff --git a/engine/src/core/com/jme3/cinematic/events/AnimationTrack.java b/engine/src/core/com/jme3/cinematic/events/AnimationTrack.java index ab86fcfa8..696bf5ecc 100644 --- a/engine/src/core/com/jme3/cinematic/events/AnimationTrack.java +++ b/engine/src/core/com/jme3/cinematic/events/AnimationTrack.java @@ -108,6 +108,9 @@ public class AnimationTrack extends AbstractCinematicEvent { @Override public void setTime(float time) { super.setTime(time); + if (channel.getAnimationName() == null) { + channel.setAnim(animationName); + } float t = time; if (loopMode == loopMode.Loop) { t = t % channel.getAnimMaxTime(); @@ -121,8 +124,18 @@ public class AnimationTrack extends AbstractCinematicEvent { } } - channel.setTime(t); - channel.getControl().update(0); + if (t < 0) { + channel.setTime(0); + channel.reset(true); + } + if (t > channel.getAnimMaxTime()) { + channel.setTime(t); + channel.getControl().update(0); + stop(); + } else { + channel.setTime(t); + channel.getControl().update(0); + } } @Override @@ -133,7 +146,7 @@ public class AnimationTrack extends AbstractCinematicEvent { channel.setSpeed(speed); channel.setLoopMode(loopMode); channel.setTime(time); - } + } } @Override