|
|
|
@ -59,7 +59,7 @@ import java.util.logging.Logger; |
|
|
|
|
* @author Nehon |
|
|
|
|
*/ |
|
|
|
|
public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = Logger.getLogger(Application.class.getName()); |
|
|
|
|
private Node scene; |
|
|
|
|
protected TimeLine timeLine = new TimeLine(); |
|
|
|
@ -68,30 +68,30 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
private Map<String, CameraNode> cameras = new HashMap<String, CameraNode>(); |
|
|
|
|
private CameraNode currentCam; |
|
|
|
|
private boolean initialized = false; |
|
|
|
|
private Map<String, Map<String, Object>> eventsData; |
|
|
|
|
|
|
|
|
|
private Map<String, Map<String, Object>> eventsData; |
|
|
|
|
|
|
|
|
|
public Cinematic() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Cinematic(Node scene) { |
|
|
|
|
this.scene = scene; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Cinematic(Node scene, float initialDuration) { |
|
|
|
|
super(initialDuration); |
|
|
|
|
this.scene = scene; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Cinematic(Node scene, LoopMode loopMode) { |
|
|
|
|
super(loopMode); |
|
|
|
|
this.scene = scene; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Cinematic(Node scene, float initialDuration, LoopMode loopMode) { |
|
|
|
|
super(initialDuration, loopMode); |
|
|
|
|
this.scene = scene; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onPlay() { |
|
|
|
|
if (isInitialized()) { |
|
|
|
@ -105,7 +105,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onStop() { |
|
|
|
|
time = 0; |
|
|
|
@ -116,7 +116,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
} |
|
|
|
|
enableCurrentCam(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onPause() { |
|
|
|
|
for (int i = 0; i < cinematicEvents.size(); i++) { |
|
|
|
@ -126,28 +126,28 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void write(JmeExporter ex) throws IOException { |
|
|
|
|
super.write(ex); |
|
|
|
|
OutputCapsule oc = ex.getCapsule(this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
oc.writeSavableArrayList((ArrayList) cinematicEvents, "cinematicEvents", null); |
|
|
|
|
oc.writeStringSavableMap(cameras, "cameras", null); |
|
|
|
|
oc.write(timeLine, "timeLine", null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void read(JmeImporter im) throws IOException { |
|
|
|
|
super.read(im); |
|
|
|
|
InputCapsule ic = im.getCapsule(this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cinematicEvents = ic.readSavableArrayList("cinematicEvents", null); |
|
|
|
|
cameras = (Map<String, CameraNode>) ic.readStringSavableMap("cameras", null); |
|
|
|
|
timeLine = (TimeLine) ic.readSavable("timeLine", null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void setSpeed(float speed) { |
|
|
|
|
super.setSpeed(speed); |
|
|
|
@ -155,53 +155,53 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
CinematicEvent ce = cinematicEvents.get(i); |
|
|
|
|
ce.setSpeed(speed); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void initialize(AppStateManager stateManager, Application app) { |
|
|
|
|
initEvent(app, this); |
|
|
|
|
for (CinematicEvent cinematicEvent : cinematicEvents) { |
|
|
|
|
cinematicEvent.initEvent(app, this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialized = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isInitialized() { |
|
|
|
|
return initialized; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setEnabled(boolean enabled) { |
|
|
|
|
if (enabled) { |
|
|
|
|
play(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isEnabled() { |
|
|
|
|
return playState == PlayState.Playing; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void stateAttached(AppStateManager stateManager) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void stateDetached(AppStateManager stateManager) { |
|
|
|
|
stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void update(float tpf) { |
|
|
|
|
if (isInitialized()) { |
|
|
|
|
internalUpdate(tpf); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onUpdate(float tpf) { |
|
|
|
|
public void onUpdate(float tpf) { |
|
|
|
|
for (int i = 0; i < cinematicEvents.size(); i++) { |
|
|
|
|
CinematicEvent ce = cinematicEvents.get(i); |
|
|
|
|
ce.internalUpdate(tpf); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time); |
|
|
|
|
|
|
|
|
|
//iterate to make sure every key frame is triggered
|
|
|
|
@ -211,33 +211,37 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
keyFrame.trigger(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastFetchedKeyFrame = keyFrameIndex; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void setTime(float time) { |
|
|
|
|
super.setTime(time); |
|
|
|
|
int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time); |
|
|
|
|
super.setTime(time); |
|
|
|
|
//stopping all events
|
|
|
|
|
for (CinematicEvent ce : cinematicEvents) { |
|
|
|
|
ce.stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//triggering all the event from start to "time"
|
|
|
|
|
//then computing timeOffset for each event
|
|
|
|
|
for (int i = 0; i <= keyFrameIndex; i++) { |
|
|
|
|
KeyFrame keyFrame = timeLine.get(i); |
|
|
|
|
//then computing timeOffset for each event
|
|
|
|
|
for (KeyFrame keyFrame : timeLine.values()) { |
|
|
|
|
//KeyFrame keyFrame = timeLine.get(timeLine.keySet());
|
|
|
|
|
if (keyFrame != null) { |
|
|
|
|
for (CinematicEvent ce : keyFrame.getCinematicEvents()) { |
|
|
|
|
ce.play(); |
|
|
|
|
ce.setTime(time - timeLine.getKeyFrameTime(keyFrame)); |
|
|
|
|
float t = this.time - timeLine.getKeyFrameTime(keyFrame); |
|
|
|
|
if (t >= 0 && (t <= ce.getInitialDuration() || ce.getLoopMode() != LoopMode.DontLoop)) { |
|
|
|
|
ce.play(); |
|
|
|
|
ce.setTime(t); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (playState != PlayState.Playing) { |
|
|
|
|
pause(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// step();
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public KeyFrame addCinematicEvent(float timeStamp, CinematicEvent cinematicEvent) { |
|
|
|
|
KeyFrame keyFrame = timeLine.getKeyFrameAtTime(timeStamp); |
|
|
|
|
if (keyFrame == null) { |
|
|
|
@ -248,13 +252,13 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
cinematicEvents.add(cinematicEvent); |
|
|
|
|
return keyFrame; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void render(RenderManager rm) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void postRender() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void cleanup() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -270,10 +274,10 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
d = (ce.getDuration() * ce.getSpeed()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialDuration = d; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CameraNode bindCamera(String cameraName, Camera cam) { |
|
|
|
|
CameraNode node = new CameraNode(cameraName, cam); |
|
|
|
|
node.setControlDir(ControlDirection.SpatialToCamera); |
|
|
|
@ -282,17 +286,17 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
scene.attachChild(node); |
|
|
|
|
return node; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CameraNode getCamera(String cameraName) { |
|
|
|
|
return cameras.get(cameraName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void enableCurrentCam(boolean enabled) { |
|
|
|
|
if (currentCam != null) { |
|
|
|
|
currentCam.getControl(CameraControl.class).setEnabled(enabled); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setActiveCamera(String cameraName) { |
|
|
|
|
enableCurrentCam(false); |
|
|
|
|
currentCam = cameras.get(cameraName); |
|
|
|
@ -301,51 +305,51 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
} |
|
|
|
|
enableCurrentCam(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void activateCamera(final float timeStamp, final String cameraName) { |
|
|
|
|
addCinematicEvent(timeStamp, new AbstractCinematicEvent() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void play() { |
|
|
|
|
super.play(); |
|
|
|
|
stop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onPlay() { |
|
|
|
|
setActiveCamera(cameraName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onUpdate(float tpf) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onStop() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onPause() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void setTime(float time) { |
|
|
|
|
play(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setScene(Node scene) { |
|
|
|
|
this.scene = scene; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Map<String, Object>> getEventsData() { |
|
|
|
|
if (eventsData == null) { |
|
|
|
|
eventsData = new HashMap<String, Map<String, Object>>(); |
|
|
|
|
} |
|
|
|
|
return eventsData; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void putEventData(String type, String name, Object object) { |
|
|
|
|
Map<String, Map<String, Object>> data = getEventsData(); |
|
|
|
|
Map<String, Object> row = data.get(type); |
|
|
|
@ -354,7 +358,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
} |
|
|
|
|
row.put(name, object); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Object getEventData(String type, String name) { |
|
|
|
|
if (eventsData != null) { |
|
|
|
|
Map<String, Object> row = eventsData.get(type); |
|
|
|
@ -364,7 +368,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Savable removeEventData(String type, String name) { |
|
|
|
|
if (eventsData != null) { |
|
|
|
|
Map<String, Object> row = eventsData.get(type); |
|
|
|
@ -374,7 +378,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState { |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Node getScene() { |
|
|
|
|
return scene; |
|
|
|
|
} |
|
|
|
|