Trying to make Cinematic serialization work.
This way at least it doesn't crash: Removed anonymous inner class and made new class; CameraEvent Added a bunch of default constructors for other related classes in the process.
This commit is contained in:
parent
2120c9d334
commit
ae97614c83
@ -68,7 +68,11 @@ public final class AnimChannel {
|
|||||||
private float blendAmount = 1f;
|
private float blendAmount = 1f;
|
||||||
private float blendRate = 0;
|
private float blendRate = 0;
|
||||||
|
|
||||||
AnimChannel(AnimControl control){
|
public AnimChannel(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public AnimChannel(AnimControl control){
|
||||||
this.control = control;
|
this.control = control;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,9 @@ import static com.jme3.animation.LoopMode.Loop;
|
|||||||
*/
|
*/
|
||||||
public class AnimationUtils {
|
public class AnimationUtils {
|
||||||
|
|
||||||
|
public AnimationUtils(){
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Clamps the time according to duration and loopMode
|
* Clamps the time according to duration and loopMode
|
||||||
* @param time
|
* @param time
|
||||||
|
@ -36,14 +36,18 @@ 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.cinematic.events.AbstractCinematicEvent;
|
import com.jme3.cinematic.events.AbstractCinematicEvent;
|
||||||
|
import com.jme3.cinematic.events.CameraEvent;
|
||||||
import com.jme3.cinematic.events.CinematicEvent;
|
import com.jme3.cinematic.events.CinematicEvent;
|
||||||
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;
|
||||||
|
import com.jme3.renderer.ViewPort;
|
||||||
import com.jme3.scene.CameraNode;
|
import com.jme3.scene.CameraNode;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.control.CameraControl;
|
import com.jme3.scene.control.CameraControl;
|
||||||
import com.jme3.scene.control.CameraControl.ControlDirection;
|
import com.jme3.scene.control.CameraControl.ControlDirection;
|
||||||
|
import com.jme3.scene.control.Control;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -88,12 +92,12 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public class Cinematic extends AbstractCinematicEvent implements AppState {
|
public class Cinematic extends AbstractCinematicEvent implements AppState {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(Application.class.getName());
|
private static final Logger logger = Logger.getLogger(Cinematic.class.getName());
|
||||||
private Node scene;
|
private Node scene;
|
||||||
protected TimeLine timeLine = new TimeLine();
|
protected TimeLine timeLine = new TimeLine();
|
||||||
private int lastFetchedKeyFrame = -1;
|
private int lastFetchedKeyFrame = -1;
|
||||||
private List<CinematicEvent> cinematicEvents = new ArrayList<CinematicEvent>();
|
private List<CinematicEvent> cinematicEvents = new ArrayList<>();
|
||||||
private Map<String, CameraNode> cameras = new HashMap<String, CameraNode>();
|
private Map<String, CameraNode> cameras = new HashMap<>();
|
||||||
private CameraNode currentCam;
|
private CameraNode currentCam;
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
private Map<String, Map<Object, Object>> eventsData;
|
private Map<String, Map<Object, Object>> eventsData;
|
||||||
@ -104,6 +108,19 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
|||||||
* directly
|
* directly
|
||||||
*/
|
*/
|
||||||
public Cinematic() {
|
public Cinematic() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cinematic(float initialDuration) {
|
||||||
|
super(initialDuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cinematic(LoopMode loopMode) {
|
||||||
|
super(loopMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cinematic(float initialDuration, LoopMode loopMode) {
|
||||||
|
super(initialDuration, loopMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -206,8 +223,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
|||||||
public void write(JmeExporter ex) throws IOException {
|
public void write(JmeExporter ex) throws IOException {
|
||||||
super.write(ex);
|
super.write(ex);
|
||||||
OutputCapsule oc = ex.getCapsule(this);
|
OutputCapsule oc = ex.getCapsule(this);
|
||||||
|
oc.write(cinematicEvents.toArray(new CinematicEvent[cinematicEvents.size()]), "cinematicEvents", null);
|
||||||
oc.writeSavableArrayList((ArrayList) cinematicEvents, "cinematicEvents", null);
|
|
||||||
oc.writeStringSavableMap(cameras, "cameras", null);
|
oc.writeStringSavableMap(cameras, "cameras", null);
|
||||||
oc.write(timeLine, "timeLine", null);
|
oc.write(timeLine, "timeLine", null);
|
||||||
|
|
||||||
@ -224,7 +240,11 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
|||||||
super.read(im);
|
super.read(im);
|
||||||
InputCapsule ic = im.getCapsule(this);
|
InputCapsule ic = im.getCapsule(this);
|
||||||
|
|
||||||
cinematicEvents = ic.readSavableArrayList("cinematicEvents", null);
|
Savable[] events = ic.readSavableArray("cinematicEvents", null);
|
||||||
|
for (Savable c : events) {
|
||||||
|
// addCinematicEvent(((CinematicEvent) c).getTime(), (CinematicEvent) c)
|
||||||
|
cinematicEvents.add((CinematicEvent) c);
|
||||||
|
}
|
||||||
cameras = (Map<String, CameraNode>) ic.readStringSavableMap("cameras", null);
|
cameras = (Map<String, CameraNode>) ic.readStringSavableMap("cameras", null);
|
||||||
timeLine = (TimeLine) ic.readSavable("timeLine", null);
|
timeLine = (TimeLine) ic.readSavable("timeLine", null);
|
||||||
}
|
}
|
||||||
@ -244,7 +264,6 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
|||||||
ce.setSpeed(speed);
|
ce.setSpeed(speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -315,6 +334,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
|||||||
*
|
*
|
||||||
* @param tpf
|
* @param tpf
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void update(float tpf) {
|
public void update(float tpf) {
|
||||||
if (isInitialized()) {
|
if (isInitialized()) {
|
||||||
internalUpdate(tpf);
|
internalUpdate(tpf);
|
||||||
@ -338,13 +358,11 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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.internalUpdate(tpf);
|
ce.internalUpdate(tpf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lastFetchedKeyFrame = keyFrameIndex;
|
lastFetchedKeyFrame = keyFrameIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,8 +404,8 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
|||||||
* Adds a cinematic event to this cinematic at the given timestamp. This
|
* Adds a cinematic event to this cinematic at the given timestamp. This
|
||||||
* operation returns a keyFrame
|
* operation returns a keyFrame
|
||||||
*
|
*
|
||||||
* @param timeStamp the time when the event will start after the beginning of
|
* @param timeStamp the time when the event will start after the beginning
|
||||||
* the cinematic
|
* of the cinematic
|
||||||
* @param cinematicEvent the cinematic event
|
* @param cinematicEvent the cinematic event
|
||||||
* @return the keyFrame for that event.
|
* @return the keyFrame for that event.
|
||||||
*/
|
*/
|
||||||
@ -580,39 +598,7 @@ public class Cinematic extends AbstractCinematicEvent implements AppState {
|
|||||||
* Cinematic#bindCamera())
|
* Cinematic#bindCamera())
|
||||||
*/
|
*/
|
||||||
public void activateCamera(final float timeStamp, final String cameraName) {
|
public void activateCamera(final float timeStamp, final String cameraName) {
|
||||||
addCinematicEvent(timeStamp, new AbstractCinematicEvent() {
|
addCinematicEvent(timeStamp, new CameraEvent(this, cameraName));
|
||||||
@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 forceStop() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setTime(float time) {
|
|
||||||
play();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +43,11 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class KeyFrame implements Savable {
|
public class KeyFrame implements Savable {
|
||||||
|
|
||||||
List<CinematicEvent> cinematicEvents = new ArrayList<CinematicEvent>();
|
public KeyFrame(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
List<CinematicEvent> cinematicEvents = new ArrayList<>();
|
||||||
private int index;
|
private int index;
|
||||||
|
|
||||||
public List<CinematicEvent> getCinematicEvents() {
|
public List<CinematicEvent> getCinematicEvents() {
|
||||||
|
@ -80,6 +80,7 @@ public class AnimationEvent extends AbstractCinematicEvent {
|
|||||||
* constructors
|
* constructors
|
||||||
*/
|
*/
|
||||||
public AnimationEvent() {
|
public AnimationEvent() {
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,146 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2017 jMonkeyEngine
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package com.jme3.cinematic.events;
|
||||||
|
|
||||||
|
import com.jme3.app.Application;
|
||||||
|
import com.jme3.cinematic.Cinematic;
|
||||||
|
import com.jme3.cinematic.TimeLine;
|
||||||
|
import com.jme3.export.InputCapsule;
|
||||||
|
import com.jme3.export.JmeExporter;
|
||||||
|
import com.jme3.export.JmeImporter;
|
||||||
|
import com.jme3.export.OutputCapsule;
|
||||||
|
import com.jme3.export.Savable;
|
||||||
|
import com.jme3.scene.CameraNode;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Rickard <neph1 @ github>
|
||||||
|
*/
|
||||||
|
public class CameraEvent extends AbstractCinematicEvent{
|
||||||
|
|
||||||
|
private String cameraName;
|
||||||
|
private Cinematic cinematic;
|
||||||
|
|
||||||
|
public String getCameraName() {
|
||||||
|
return cameraName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCameraName(String cameraName) {
|
||||||
|
this.cameraName = cameraName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraEvent(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraEvent(Cinematic parentEvent, String cameraName){
|
||||||
|
this.cinematic = parentEvent;
|
||||||
|
this.cameraName = cameraName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initEvent(Application app, Cinematic cinematic) {
|
||||||
|
super.initEvent(app, cinematic);
|
||||||
|
this.cinematic = cinematic;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void play() {
|
||||||
|
super.play();
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlay() {
|
||||||
|
cinematic.setActiveCamera(cameraName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpdate(float tpf) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forceStop() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTime(float time) {
|
||||||
|
play();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cinematic getCinematic() {
|
||||||
|
return cinematic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCinematic(Cinematic cinematic) {
|
||||||
|
this.cinematic = cinematic;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used internally for serialization
|
||||||
|
*
|
||||||
|
* @param ex
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void write(JmeExporter ex) throws IOException {
|
||||||
|
super.write(ex);
|
||||||
|
OutputCapsule oc = ex.getCapsule(this);
|
||||||
|
oc.write(cameraName, "cameraName", null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* used internally for serialization
|
||||||
|
*
|
||||||
|
* @param im
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void read(JmeImporter im) throws IOException {
|
||||||
|
super.read(im);
|
||||||
|
InputCapsule ic = im.getCapsule(this);
|
||||||
|
cameraName = ic.readString("cameraName", null);
|
||||||
|
}
|
||||||
|
}
|
@ -147,6 +147,7 @@ public class SoundEvent extends AbstractCinematicEvent {
|
|||||||
* used for serialization
|
* used for serialization
|
||||||
*/
|
*/
|
||||||
public SoundEvent() {
|
public SoundEvent() {
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,6 +53,7 @@ public class CameraNode extends Node {
|
|||||||
* Serialization only. Do not use.
|
* Serialization only. Do not use.
|
||||||
*/
|
*/
|
||||||
public CameraNode() {
|
public CameraNode() {
|
||||||
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CameraNode(String name, Camera camera) {
|
public CameraNode(String name, Camera camera) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user