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
3.0
rem..om 13 years ago
parent 8ab5a211e2
commit 07e96d02eb
  1. 18
      engine/src/core/com/jme3/cinematic/Cinematic.java
  2. 19
      engine/src/core/com/jme3/cinematic/events/AnimationTrack.java

@ -35,10 +35,8 @@ import com.jme3.animation.LoopMode;
import com.jme3.app.Application; import com.jme3.app.Application;
import com.jme3.app.state.AppState; import com.jme3.app.state.AppState;
import com.jme3.app.state.AppStateManager; import com.jme3.app.state.AppStateManager;
import com.jme3.asset.TextureKey;
import com.jme3.cinematic.events.AbstractCinematicEvent; import com.jme3.cinematic.events.AbstractCinematicEvent;
import com.jme3.cinematic.events.CinematicEvent; import com.jme3.cinematic.events.CinematicEvent;
import com.jme3.cinematic.events.CinematicEventListener;
import com.jme3.export.*; import com.jme3.export.*;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
@ -112,6 +110,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
lastFetchedKeyFrame = -1; lastFetchedKeyFrame = -1;
for (int i = 0; i < cinematicEvents.size(); i++) { for (int i = 0; i < cinematicEvents.size(); i++) {
CinematicEvent ce = cinematicEvents.get(i); CinematicEvent ce = cinematicEvents.get(i);
ce.setTime(0);
ce.stop(); ce.stop();
} }
enableCurrentCam(false); enableCurrentCam(false);
@ -217,26 +216,27 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
@Override @Override
public void setTime(float time) { public void setTime(float time) {
super.setTime(time);
//stopping all events //stopping all events
for (CinematicEvent ce : cinematicEvents) { onStop();
ce.stop(); super.setTime(time);
}
int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time);
//triggering all the event from start to "time" //triggering all the event from start to "time"
//then computing timeOffset for each event //then computing timeOffset for each event
for (KeyFrame keyFrame : timeLine.values()) { for (int i = 0; i <= keyFrameIndex; i++) {
//KeyFrame keyFrame = timeLine.get(timeLine.keySet()); KeyFrame keyFrame = timeLine.get(i);
if (keyFrame != null) { if (keyFrame != null) {
for (CinematicEvent ce : keyFrame.getCinematicEvents()) { for (CinematicEvent ce : keyFrame.getCinematicEvents()) {
float t = this.time - timeLine.getKeyFrameTime(keyFrame); float t = this.time - timeLine.getKeyFrameTime(keyFrame);
if (t >= 0 && (t <= ce.getInitialDuration() || ce.getLoopMode() != LoopMode.DontLoop)) { if (t >= 0 && (t <= ce.getInitialDuration() || ce.getLoopMode() != LoopMode.DontLoop)) {
ce.play(); ce.play();
ce.setTime(t);
} }
ce.setTime(t);
} }
} }
} }
lastFetchedKeyFrame = keyFrameIndex;
if (playState != PlayState.Playing) { if (playState != PlayState.Playing) {
pause(); pause();
} }

@ -108,6 +108,9 @@ public class AnimationTrack extends AbstractCinematicEvent {
@Override @Override
public void setTime(float time) { public void setTime(float time) {
super.setTime(time); super.setTime(time);
if (channel.getAnimationName() == null) {
channel.setAnim(animationName);
}
float t = time; float t = time;
if (loopMode == loopMode.Loop) { if (loopMode == loopMode.Loop) {
t = t % channel.getAnimMaxTime(); t = t % channel.getAnimMaxTime();
@ -121,8 +124,18 @@ public class AnimationTrack extends AbstractCinematicEvent {
} }
} }
channel.setTime(t); if (t < 0) {
channel.getControl().update(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 @Override
@ -133,7 +146,7 @@ public class AnimationTrack extends AbstractCinematicEvent {
channel.setSpeed(speed); channel.setSpeed(speed);
channel.setLoopMode(loopMode); channel.setLoopMode(loopMode);
channel.setTime(time); channel.setTime(time);
} }
} }
@Override @Override

Loading…
Cancel
Save