Several changes to load cinematics

Cinematic:
	* Reattach CameraNode to scene
	* Set CameraNode's camera to be app's camera
AnimationEvent:
	* Save modelName
	* Use modelName and try to replace scene's model in initEvent
empirephoenix-patch-1
Rickard Edén 7 years ago committed by Rémy Bouquet
parent ae97614c83
commit 74f2f703b3
  1. 13
      jme3-core/src/main/java/com/jme3/cinematic/Cinematic.java
  2. 32
      jme3-core/src/main/java/com/jme3/cinematic/events/AnimationEvent.java

@ -277,7 +277,11 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
for (CinematicEvent cinematicEvent : cinematicEvents) { for (CinematicEvent cinematicEvent : cinematicEvents) {
cinematicEvent.initEvent(app, this); cinematicEvent.initEvent(app, this);
} }
if(!cameras.isEmpty()){
for(CameraNode n : cameras.values()){
n.setCamera(app.getCamera());
}
}
initialized = true; initialized = true;
} }
@ -336,7 +340,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
*/ */
@Override @Override
public void update(float tpf) { public void update(float tpf) {
if (isInitialized()) { if (isInitialized() && playState == PlayState.Playing) {
internalUpdate(tpf); internalUpdate(tpf);
} }
} }
@ -670,6 +674,11 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
*/ */
public void setScene(Node scene) { public void setScene(Node scene) {
this.scene = scene; this.scene = scene;
if(!cameras.isEmpty()){
for(CameraNode n : cameras.values()){
this.scene.attachChild(n);
}
}
} }
/** /**

@ -41,7 +41,10 @@ import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter; import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.util.clone.Cloner;
import com.jme3.util.clone.JmeCloneable;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -91,6 +94,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
*/ */
public AnimationEvent(Spatial model, String animationName) { public AnimationEvent(Spatial model, String animationName) {
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
} }
@ -105,6 +109,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
public AnimationEvent(Spatial model, String animationName, float initialDuration) { public AnimationEvent(Spatial model, String animationName, float initialDuration) {
super(initialDuration); super(initialDuration);
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
} }
@ -120,6 +125,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
super(loopMode); super(loopMode);
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
} }
@ -135,6 +141,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode) { public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode); super(initialDuration, loopMode);
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
} }
@ -150,6 +157,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
public AnimationEvent(Spatial model, String animationName, float initialDuration, float blendTime) { public AnimationEvent(Spatial model, String animationName, float initialDuration, float blendTime) {
super(initialDuration); super(initialDuration);
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
this.blendTime = blendTime; this.blendTime = blendTime;
} }
@ -168,6 +176,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
super(loopMode); super(loopMode);
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
this.blendTime = blendTime; this.blendTime = blendTime;
} }
@ -186,6 +195,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode, float blendTime) { public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode, float blendTime) {
super(initialDuration, loopMode); super(initialDuration, loopMode);
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
this.blendTime = blendTime; this.blendTime = blendTime;
} }
@ -204,6 +214,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
super(loopMode); super(loopMode);
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
this.channelIndex = channelIndex; this.channelIndex = channelIndex;
} }
@ -218,6 +229,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
*/ */
public AnimationEvent(Spatial model, String animationName, int channelIndex) { public AnimationEvent(Spatial model, String animationName, int channelIndex) {
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
this.channelIndex = channelIndex; this.channelIndex = channelIndex;
@ -234,6 +246,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
*/ */
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex, float blendTime) { public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex, float blendTime) {
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
this.loopMode = loopMode; this.loopMode = loopMode;
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
@ -253,6 +266,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
public AnimationEvent(Spatial model, String animationName, float initialDuration, int channelIndex) { public AnimationEvent(Spatial model, String animationName, float initialDuration, int channelIndex) {
super(initialDuration); super(initialDuration);
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
this.channelIndex = channelIndex; this.channelIndex = channelIndex;
} }
@ -271,6 +285,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode, int channelIndex) { public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode, int channelIndex) {
super(initialDuration, loopMode); super(initialDuration, loopMode);
this.model = model; this.model = model;
this.modelName = model.getName();
this.animationName = animationName; this.animationName = animationName;
this.channelIndex = channelIndex; this.channelIndex = channelIndex;
} }
@ -300,6 +315,18 @@ public class AnimationEvent extends AbstractCinematicEvent {
model = cinematic.getScene().getChild(modelName); model = cinematic.getScene().getChild(modelName);
} }
if (model != null) { if (model != null) {
if(cinematic.getScene() != null){
Spatial sceneModel = cinematic.getScene().getChild(model.getName());
if(sceneModel != null){
Node parent = sceneModel.getParent();
parent.detachChild(sceneModel);
sceneModel = model;
parent.attachChild(sceneModel);
} else {
cinematic.getScene().attachChild(model);
}
}
channel = model.getControl(AnimControl.class).createChannel(); channel = model.getControl(AnimControl.class).createChannel();
map.put(channelIndex, channel); map.put(channelIndex, channel);
} else { } else {
@ -402,6 +429,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
OutputCapsule oc = ex.getCapsule(this); OutputCapsule oc = ex.getCapsule(this);
oc.write(model, "model", null); oc.write(model, "model", null);
oc.write(modelName, "modelName", null);
oc.write(animationName, "animationName", ""); oc.write(animationName, "animationName", "");
oc.write(blendTime, "blendTime", 0f); oc.write(blendTime, "blendTime", 0f);
oc.write(channelIndex, "channelIndex", 0); oc.write(channelIndex, "channelIndex", 0);
@ -412,9 +440,9 @@ public class AnimationEvent extends AbstractCinematicEvent {
public void read(JmeImporter im) throws IOException { public void read(JmeImporter im) throws IOException {
super.read(im); super.read(im);
InputCapsule ic = im.getCapsule(this); InputCapsule ic = im.getCapsule(this);
if (im.getFormatVersion() == 0) { // if (im.getFormatVersion() == 0) {
modelName = ic.readString("modelName", ""); modelName = ic.readString("modelName", "");
} // }
//FIXME always the same issue, because of the clonning of assets, this won't work //FIXME always the same issue, because of the clonning of assets, this won't work
//we have to somehow store userdata in the spatial and then recurse the //we have to somehow store userdata in the spatial and then recurse the
//scene sub scenegraph to find the correct instance of the model //scene sub scenegraph to find the correct instance of the model

Loading…
Cancel
Save