Cinematics : renamed all XXXTrack in cinematic.event to XXXEvent, so there is no confusion with the Tracks in the animation system.

Old XXXTrack classes are now deprecated an just extend the corresponding XXXEvent class.
Also removed PositionTrack, RotationTrack and ScaleTrack for they are deprecated since alpha 3.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9567 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent 94ae185d6d
commit c02b24da12
  1. 10
      engine/src/core/com/jme3/cinematic/MotionPath.java
  2. 6
      engine/src/core/com/jme3/cinematic/MotionPathListener.java
  3. 202
      engine/src/core/com/jme3/cinematic/events/AnimationEvent.java
  4. 156
      engine/src/core/com/jme3/cinematic/events/AnimationTrack.java
  5. 448
      engine/src/core/com/jme3/cinematic/events/MotionEvent.java
  6. 372
      engine/src/core/com/jme3/cinematic/events/MotionTrack.java
  7. 122
      engine/src/core/com/jme3/cinematic/events/PositionTrack.java
  8. 126
      engine/src/core/com/jme3/cinematic/events/RotationTrack.java
  9. 121
      engine/src/core/com/jme3/cinematic/events/ScaleTrack.java
  10. 184
      engine/src/core/com/jme3/cinematic/events/SoundEvent.java
  11. 121
      engine/src/core/com/jme3/cinematic/events/SoundTrack.java
  12. 13
      engine/src/test/jme3test/animation/TestCameraMotionPath.java
  13. 26
      engine/src/test/jme3test/animation/TestCinematic.java
  14. 11
      engine/src/test/jme3test/animation/TestMotionPath.java

@ -32,7 +32,7 @@
package com.jme3.cinematic;
import com.jme3.asset.AssetManager;
import com.jme3.cinematic.events.MotionTrack;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.export.*;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
@ -71,11 +71,11 @@ public class MotionPath implements Savable {
/**
* interpolate the path giving the time since the beginnin and the motionControl
* this methods sets the new localTranslation to the spatial of the motionTrack control.
* this methods sets the new localTranslation to the spatial of the MotionEvent control.
* @param time the time since the animation started
* @param control the ocntrol over the moving spatial
*/
public float interpolatePath(float time, MotionTrack control, float tpf) {
public float interpolatePath(float time, MotionEvent control, float tpf) {
float traveledDistance = 0;
TempVars vars = TempVars.get();
@ -104,7 +104,7 @@ public class MotionPath implements Savable {
return traveledDistance;
}
public void checkWayPoint(MotionTrack control, float tpf) {
public void checkWayPoint(MotionEvent control, float tpf) {
//Epsilon varies with the tpf to avoid missing a waypoint on low framerate.
float epsilon = tpf * 4f;
if (control.getCurrentWayPoint() != prevWayPoint) {
@ -317,7 +317,7 @@ public class MotionPath implements Savable {
return spline.getControlPoints().size();
}
public void triggerWayPointReach(int wayPointIndex, MotionTrack control) {
public void triggerWayPointReach(int wayPointIndex, MotionEvent control) {
if (listeners != null) {
for (Iterator<MotionPathListener> it = listeners.iterator(); it.hasNext();) {
MotionPathListener listener = it.next();

@ -32,7 +32,7 @@
package com.jme3.cinematic;
import com.jme3.cinematic.events.MotionTrack;
import com.jme3.cinematic.events.MotionEvent;
/**
* Trigger the events appening on an motion path
@ -42,9 +42,9 @@ public interface MotionPathListener {
/**
* Triggers every time the target reach a waypoint on the path
* @param motionControl the MotionTrack objects that reached the waypoint
* @param motionControl the MotionEvent objects that reached the waypoint
* @param wayPointIndex the index of the way point reached
*/
public void onWayPointReach(MotionTrack motionControl,int wayPointIndex);
public void onWayPointReach(MotionEvent motionControl,int wayPointIndex);
}

@ -0,0 +1,202 @@
/*
* Copyright (c) 2009-2010 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.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.LoopMode;
import com.jme3.app.Application;
import com.jme3.cinematic.Cinematic;
import com.jme3.cinematic.PlayState;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.scene.Spatial;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Nehon
*/
public class AnimationEvent extends AbstractCinematicEvent {
private static final Logger log = Logger.getLogger(AnimationEvent.class.getName());
protected AnimChannel channel;
protected String animationName;
protected String modelName;
public AnimationEvent() {
}
public AnimationEvent(Spatial model, String animationName) {
modelName = model.getName();
this.animationName = animationName;
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
}
public AnimationEvent(Spatial model, String animationName, float initialDuration) {
super(initialDuration);
modelName = model.getName();
this.animationName = animationName;
}
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode) {
super(loopMode);
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
modelName = model.getName();
this.animationName = animationName;
}
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode);
modelName = model.getName();
this.animationName = animationName;
}
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
if (channel == null) {
Object s = cinematic.getEventData("modelChannels", modelName);
if (s != null && s instanceof AnimChannel) {
this.channel = (AnimChannel) s;
} else if (s == null) {
Spatial model = cinematic.getScene().getChild(modelName);
if (model != null) {
channel = model.getControl(AnimControl.class).createChannel();
cinematic.putEventData("modelChannels", modelName, channel);
} else {
log.log(Level.WARNING, "spatial {0} not found in the scene, cannot perform animation", modelName);
}
}
}
}
@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();
}
if (loopMode == loopMode.Cycle) {
float parity = (float) Math.ceil(time / channel.getAnimMaxTime());
if (parity > 0 && parity % 2 == 0) {
t = channel.getAnimMaxTime() - t % channel.getAnimMaxTime();
} else {
t = t % channel.getAnimMaxTime();
}
}
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
public void onPlay() {
channel.getControl().setEnabled(true);
if (playState == PlayState.Stopped) {
channel.setAnim(animationName);
channel.setSpeed(speed);
channel.setLoopMode(loopMode);
channel.setTime(time);
}
}
@Override
public void setSpeed(float speed) {
super.setSpeed(speed);
if (channel != null) {
channel.setSpeed(speed);
}
}
@Override
public void onUpdate(float tpf) {
}
@Override
public void onStop() {
if (channel != null) {
channel.setTime(0);
channel.reset(false);
}
}
@Override
public void onPause() {
if (channel != null) {
channel.getControl().setEnabled(false);
}
}
@Override
public void setLoopMode(LoopMode loopMode) {
super.setLoopMode(loopMode);
if (channel != null) {
channel.setLoopMode(loopMode);
}
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(modelName, "modelName", "");
oc.write(animationName, "animationName", "");
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
modelName = ic.readString("modelName", "");
animationName = ic.readString("animationName", "");
}
}

@ -31,172 +31,34 @@
*/
package com.jme3.cinematic.events;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.LoopMode;
import com.jme3.app.Application;
import com.jme3.cinematic.Cinematic;
import com.jme3.cinematic.PlayState;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.scene.Spatial;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @deprecated use AnimationEvent instead
* @author Nehon
*/
public class AnimationTrack extends AbstractCinematicEvent {
private static final Logger log = Logger.getLogger(AnimationTrack.class.getName());
protected AnimChannel channel;
protected String animationName;
protected String modelName;
@Deprecated
public class AnimationTrack extends AnimationEvent {
public AnimationTrack() {
super();
}
public AnimationTrack(Spatial model, String animationName) {
modelName = model.getName();
this.animationName = animationName;
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
super(model, animationName);
}
public AnimationTrack(Spatial model, String animationName, float initialDuration) {
super(initialDuration);
modelName = model.getName();
this.animationName = animationName;
super(model, animationName, initialDuration);
}
public AnimationTrack(Spatial model, String animationName, LoopMode loopMode) {
super(loopMode);
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName);
modelName = model.getName();
this.animationName = animationName;
}
public AnimationTrack(Spatial model, String animationName, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode);
modelName = model.getName();
this.animationName = animationName;
}
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
if (channel == null) {
Object s = cinematic.getEventData("modelChannels", modelName);
if (s != null && s instanceof AnimChannel) {
this.channel = (AnimChannel) s;
} else if (s == null) {
Spatial model = cinematic.getScene().getChild(modelName);
if (model != null) {
channel = model.getControl(AnimControl.class).createChannel();
cinematic.putEventData("modelChannels", modelName, channel);
} else {
log.log(Level.WARNING, "spatial {0} not found in the scene, cannot perform animation", modelName);
}
}
super(model, animationName, loopMode);
}
}
@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();
}
if (loopMode == loopMode.Cycle) {
float parity = (float) Math.ceil(time / channel.getAnimMaxTime());
if (parity > 0 && parity % 2 == 0) {
t = channel.getAnimMaxTime() - t % channel.getAnimMaxTime();
} else {
t = t % channel.getAnimMaxTime();
}
}
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
public void onPlay() {
channel.getControl().setEnabled(true);
if (playState == PlayState.Stopped) {
channel.setAnim(animationName);
channel.setSpeed(speed);
channel.setLoopMode(loopMode);
channel.setTime(time);
}
}
@Override
public void setSpeed(float speed) {
super.setSpeed(speed);
if (channel != null) {
channel.setSpeed(speed);
}
}
@Override
public void onUpdate(float tpf) {
}
@Override
public void onStop() {
if (channel != null) {
channel.setTime(0);
channel.reset(false);
}
}
@Override
public void onPause() {
if (channel != null) {
channel.getControl().setEnabled(false);
}
}
@Override
public void setLoopMode(LoopMode loopMode) {
super.setLoopMode(loopMode);
if (channel != null) {
channel.setLoopMode(loopMode);
}
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(modelName, "modelName", "");
oc.write(animationName, "animationName", "");
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
modelName = ic.readString("modelName", "");
animationName = ic.readString("animationName", "");
public AnimationTrack(Spatial model, String animationName, float initialDuration, LoopMode loopMode) {
super(model, animationName, initialDuration, loopMode);
}
}

@ -0,0 +1,448 @@
/*
* Copyright (c) 2009-2010 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.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.LoopMode;
import com.jme3.animation.Track;
import com.jme3.app.Application;
import com.jme3.cinematic.Cinematic;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.PlayState;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;
import com.jme3.util.TempVars;
import java.io.IOException;
/**
* A MotionTrack is a control over the spatial that manage the position and direction of the spatial while following a motion Path
*
* You must first create a MotionPath and then create a MotionTrack to associate a spatial and the path.
*
* @author Nehon
*/
public class MotionEvent extends AbstractCinematicEvent implements Control {
protected Spatial spatial;
protected int currentWayPoint;
protected float currentValue;
protected Vector3f direction = new Vector3f();
protected Vector3f lookAt;
protected Vector3f upVector;
protected Quaternion rotation;
protected Direction directionType = Direction.None;
protected MotionPath path;
private boolean isControl = true;
/**
* the distance traveled by the spatial on the path
*/
protected float traveledDistance = 0;
/**
* Enum for the different type of target direction behavior
*/
public enum Direction {
/**
* the target stay in the starting direction
*/
None,
/**
* The target rotates with the direction of the path
*/
Path,
/**
* The target rotates with the direction of the path but with the additon of a rtotation
* you need to use the setRotation mathod when using this Direction
*/
PathAndRotation,
/**
* The target rotates with the given rotation
*/
Rotation,
/**
* The target looks at a point
* You need to use the setLookAt method when using this direction
*/
LookAt
}
/**
* Create MotionTrack,
* when using this constructor don't forget to assign spatial and path
*/
public MotionEvent() {
super();
}
/**
* Creates a MotionPath for the given spatial on the given motion path
* @param spatial
* @param path
*/
public MotionEvent(Spatial spatial, MotionPath path) {
super();
this.spatial = spatial;
spatial.addControl(this);
this.path = path;
}
/**
* Creates a MotionPath for the given spatial on the given motion path
* @param spatial
* @param path
*/
public MotionEvent(Spatial spatial, MotionPath path, float initialDuration) {
super(initialDuration);
this.spatial = spatial;
spatial.addControl(this);
this.path = path;
}
/**
* Creates a MotionPath for the given spatial on the given motion path
* @param spatial
* @param path
*/
public MotionEvent(Spatial spatial, MotionPath path, LoopMode loopMode) {
super();
this.spatial = spatial;
spatial.addControl(this);
this.path = path;
this.loopMode = loopMode;
}
/**
* Creates a MotionPath for the given spatial on the given motion path
* @param spatial
* @param path
*/
public MotionEvent(Spatial spatial, MotionPath path, float initialDuration, LoopMode loopMode) {
super(initialDuration);
this.spatial = spatial;
spatial.addControl(this);
this.path = path;
this.loopMode = loopMode;
}
public void update(float tpf) {
if (isControl) {
internalUpdate(tpf);
}
}
@Override
public void internalUpdate(float tpf) {
if (playState == PlayState.Playing) {
time = time + (tpf * speed);
if (loopMode == loopMode.Loop && time < 0) {
time = initialDuration;
}
if ((time >= initialDuration || time < 0) && loopMode == loopMode.DontLoop) {
if (time >= initialDuration) {
path.triggerWayPointReach(path.getNbWayPoints() - 1, this);
}
stop();
} else {
onUpdate(tpf);
}
}
}
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
isControl = false;
}
@Override
public void setTime(float time) {
super.setTime(time);
onUpdate(0);
}
public void onUpdate(float tpf) {
traveledDistance = path.interpolatePath(time, this, tpf);
computeTargetDirection();
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(lookAt, "lookAt", Vector3f.ZERO);
oc.write(upVector, "upVector", Vector3f.UNIT_Y);
oc.write(rotation, "rotation", Quaternion.IDENTITY);
oc.write(directionType, "directionType", Direction.None);
oc.write(path, "path", null);
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule in = im.getCapsule(this);
lookAt = (Vector3f) in.readSavable("lookAt", Vector3f.ZERO);
upVector = (Vector3f) in.readSavable("upVector", Vector3f.UNIT_Y);
rotation = (Quaternion) in.readSavable("rotation", Quaternion.IDENTITY);
directionType = in.readEnum("directionType", Direction.class, Direction.None);
path = (MotionPath) in.readSavable("path", null);
}
/**
* this method is meant to be called by the motion path only
* @return
*/
public boolean needsDirection() {
return directionType == Direction.Path || directionType == Direction.PathAndRotation;
}
private void computeTargetDirection() {
switch (directionType) {
case Path:
Quaternion q = new Quaternion();
q.lookAt(direction, Vector3f.UNIT_Y);
spatial.setLocalRotation(q);
break;
case LookAt:
if (lookAt != null) {
spatial.lookAt(lookAt, upVector);
}
break;
case PathAndRotation:
if (rotation != null) {
Quaternion q2 = new Quaternion();
q2.lookAt(direction, Vector3f.UNIT_Y);
q2.multLocal(rotation);
spatial.setLocalRotation(q2);
}
break;
case Rotation:
if (rotation != null) {
spatial.setLocalRotation(rotation);
}
break;
case None:
break;
default:
break;
}
}
/**
* Clone this control for the given spatial
* @param spatial
* @return
*/
public Control cloneForSpatial(Spatial spatial) {
MotionEvent control = new MotionEvent(spatial, path);
control.playState = playState;
control.currentWayPoint = currentWayPoint;
control.currentValue = currentValue;
control.direction = direction.clone();
control.lookAt = lookAt.clone();
control.upVector = upVector.clone();
control.rotation = rotation.clone();
control.initialDuration = initialDuration;
control.speed = speed;
control.loopMode = loopMode;
control.directionType = directionType;
return control;
}
@Override
public void onPlay() {
traveledDistance = 0;
}
@Override
public void onStop() {
currentWayPoint = 0;
}
@Override
public void onPause() {
}
/**
* this method is meant to be called by the motion path only
* @return
*/
public float getCurrentValue() {
return currentValue;
}
/**
* this method is meant to be called by the motion path only
*
*/
public void setCurrentValue(float currentValue) {
this.currentValue = currentValue;
}
/**
* this method is meant to be called by the motion path only
* @return
*/
public int getCurrentWayPoint() {
return currentWayPoint;
}
/**
* this method is meant to be called by the motion path only
*
*/
public void setCurrentWayPoint(int currentWayPoint) {
this.currentWayPoint = currentWayPoint;
}
/**
* returns the direction the spatial is moving
* @return
*/
public Vector3f getDirection() {
return direction;
}
/**
* Sets the direction of the spatial
* This method is used by the motion path.
* @param direction
*/
public void setDirection(Vector3f direction) {
this.direction.set(direction);
}
/**
* returns the direction type of the target
* @return the direction type
*/
public Direction getDirectionType() {
return directionType;
}
/**
* Sets the direction type of the target
* On each update the direction given to the target can have different behavior
* See the Direction Enum for explanations
* @param directionType the direction type
*/
public void setDirectionType(Direction directionType) {
this.directionType = directionType;
}
/**
* Set the lookAt for the target
* This can be used only if direction Type is Direction.LookAt
* @param lookAt the position to look at
* @param upVector the up vector
*/
public void setLookAt(Vector3f lookAt, Vector3f upVector) {
this.lookAt = lookAt;
this.upVector = upVector;
}
/**
* returns the rotation of the target
* @return the rotation quaternion
*/
public Quaternion getRotation() {
return rotation;
}
/**
* sets the rotation of the target
* This can be used only if direction Type is Direction.PathAndRotation or Direction.Rotation
* With PathAndRotation the target will face the direction of the path multiplied by the given Quaternion.
* With Rotation the rotation of the target will be set with the given Quaternion.
* @param rotation the rotation quaternion
*/
public void setRotation(Quaternion rotation) {
this.rotation = rotation;
}
/**
* retun the motion path this control follows
* @return
*/
public MotionPath getPath() {
return path;
}
/**
* Sets the motion path to follow
* @param path
*/
public void setPath(MotionPath path) {
this.path = path;
}
public void setEnabled(boolean enabled) {
if (enabled) {
play();
} else {
pause();
}
}
public boolean isEnabled() {
return playState != PlayState.Stopped;
}
public void render(RenderManager rm, ViewPort vp) {
}
public void setSpatial(Spatial spatial) {
this.spatial = spatial;
}
public Spatial getSpatial() {
return spatial;
}
/**
* return the distance traveled by the spatial on the path
* @return
*/
public float getTraveledDistance() {
return traveledDistance;
}
}

@ -32,76 +32,18 @@
package com.jme3.cinematic.events;
import com.jme3.animation.LoopMode;
import com.jme3.app.Application;
import com.jme3.cinematic.Cinematic;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.PlayState;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;
import java.io.IOException;
/**
* A MotionTrack is a control over the spatial that manage the position and direction of the spatial while following a motion Path
*
* You must first create a MotionPath and then create a MotionTrack to associate a spatial and the path.
*
* @author Nehon
* @deprecated use MotionEvent instead
*/
public class MotionTrack extends AbstractCinematicEvent implements Control {
protected Spatial spatial;
protected int currentWayPoint;
protected float currentValue;
protected Vector3f direction = new Vector3f();
protected Vector3f lookAt;
protected Vector3f upVector;
protected Quaternion rotation;
protected Direction directionType = Direction.None;
protected MotionPath path;
private boolean isControl = true;
/**
* the distance traveled by the spatial on the path
*/
protected float traveledDistance = 0;
/**
* Enum for the different type of target direction behavior
*/
public enum Direction {
@Deprecated
public class MotionTrack extends MotionEvent {
/**
* the target stay in the starting direction
*/
None,
/**
* The target rotates with the direction of the path
*/
Path,
/**
* The target rotates with the direction of the path but with the additon of a rtotation
* you need to use the setRotation mathod when using this Direction
*/
PathAndRotation,
/**
* The target rotates with the given rotation
*/
Rotation,
/**
* The target looks at a point
* You need to use the setLookAt method when using this direction
*/
LookAt
}
/**
/**
* Create MotionTrack,
* when using this constructor don't forget to assign spatial and path
*/
@ -115,10 +57,7 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
* @param path
*/
public MotionTrack(Spatial spatial, MotionPath path) {
super();
this.spatial = spatial;
spatial.addControl(this);
this.path = path;
super(spatial, path);
}
/**
@ -127,10 +66,7 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
* @param path
*/
public MotionTrack(Spatial spatial, MotionPath path, float initialDuration) {
super(initialDuration);
this.spatial = spatial;
spatial.addControl(this);
this.path = path;
super(spatial, path, initialDuration);
}
/**
@ -139,11 +75,8 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
* @param path
*/
public MotionTrack(Spatial spatial, MotionPath path, LoopMode loopMode) {
super();
this.spatial = spatial;
spatial.addControl(this);
this.path = path;
this.loopMode = loopMode;
super(spatial, path, loopMode);
}
/**
@ -152,293 +85,6 @@ public class MotionTrack extends AbstractCinematicEvent implements Control {
* @param path
*/
public MotionTrack(Spatial spatial, MotionPath path, float initialDuration, LoopMode loopMode) {
super(initialDuration);
this.spatial = spatial;
spatial.addControl(this);
this.path = path;
this.loopMode = loopMode;
}
public void update(float tpf) {
if (isControl) {
internalUpdate(tpf);
}
}
@Override
public void internalUpdate(float tpf) {
if (playState == PlayState.Playing) {
time = time + (tpf * speed);
if (loopMode == loopMode.Loop && time < 0) {
time = initialDuration;
}
if ((time >= initialDuration || time < 0) && loopMode == loopMode.DontLoop) {
if (time >= initialDuration) {
path.triggerWayPointReach(path.getNbWayPoints() - 1, this);
}
stop();
} else {
onUpdate(tpf);
}
}
}
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
isControl = false;
}
@Override
public void setTime(float time) {
super.setTime(time);
onUpdate(0);
}
public void onUpdate(float tpf) {
traveledDistance = path.interpolatePath(time, this, tpf);
computeTargetDirection();
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(lookAt, "lookAt", Vector3f.ZERO);
oc.write(upVector, "upVector", Vector3f.UNIT_Y);
oc.write(rotation, "rotation", Quaternion.IDENTITY);
oc.write(directionType, "directionType", Direction.None);
oc.write(path, "path", null);
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule in = im.getCapsule(this);
lookAt = (Vector3f) in.readSavable("lookAt", Vector3f.ZERO);
upVector = (Vector3f) in.readSavable("upVector", Vector3f.UNIT_Y);
rotation = (Quaternion) in.readSavable("rotation", Quaternion.IDENTITY);
directionType = in.readEnum("directionType", Direction.class, Direction.None);
path = (MotionPath) in.readSavable("path", null);
}
/**
* this method is meant to be called by the motion path only
* @return
*/
public boolean needsDirection() {
return directionType == Direction.Path || directionType == Direction.PathAndRotation;
}
private void computeTargetDirection() {
switch (directionType) {
case Path:
Quaternion q = new Quaternion();
q.lookAt(direction, Vector3f.UNIT_Y);
spatial.setLocalRotation(q);
break;
case LookAt:
if (lookAt != null) {
spatial.lookAt(lookAt, upVector);
}
break;
case PathAndRotation:
if (rotation != null) {
Quaternion q2 = new Quaternion();
q2.lookAt(direction, Vector3f.UNIT_Y);
q2.multLocal(rotation);
spatial.setLocalRotation(q2);
}
break;
case Rotation:
if (rotation != null) {
spatial.setLocalRotation(rotation);
}
break;
case None:
break;
default:
break;
}
}
/**
* Clone this control for the given spatial
* @param spatial
* @return
*/
public Control cloneForSpatial(Spatial spatial) {
MotionTrack control = new MotionTrack(spatial, path);
control.playState = playState;
control.currentWayPoint = currentWayPoint;
control.currentValue = currentValue;
control.direction = direction.clone();
control.lookAt = lookAt.clone();
control.upVector = upVector.clone();
control.rotation = rotation.clone();
control.initialDuration = initialDuration;
control.speed = speed;
control.loopMode = loopMode;
control.directionType = directionType;
return control;
}
@Override
public void onPlay() {
traveledDistance = 0;
}
@Override
public void onStop() {
currentWayPoint = 0;
}
@Override
public void onPause() {
}
/**
* this method is meant to be called by the motion path only
* @return
*/
public float getCurrentValue() {
return currentValue;
}
/**
* this method is meant to be called by the motion path only
*
*/
public void setCurrentValue(float currentValue) {
this.currentValue = currentValue;
}
/**
* this method is meant to be called by the motion path only
* @return
*/
public int getCurrentWayPoint() {
return currentWayPoint;
}
/**
* this method is meant to be called by the motion path only
*
*/
public void setCurrentWayPoint(int currentWayPoint) {
this.currentWayPoint = currentWayPoint;
}
/**
* returns the direction the spatial is moving
* @return
*/
public Vector3f getDirection() {
return direction;
}
/**
* Sets the direction of the spatial
* This method is used by the motion path.
* @param direction
*/
public void setDirection(Vector3f direction) {
this.direction.set(direction);
}
/**
* returns the direction type of the target
* @return the direction type
*/
public Direction getDirectionType() {
return directionType;
}
/**
* Sets the direction type of the target
* On each update the direction given to the target can have different behavior
* See the Direction Enum for explanations
* @param directionType the direction type
*/
public void setDirectionType(Direction directionType) {
this.directionType = directionType;
}
/**
* Set the lookAt for the target
* This can be used only if direction Type is Direction.LookAt
* @param lookAt the position to look at
* @param upVector the up vector
*/
public void setLookAt(Vector3f lookAt, Vector3f upVector) {
this.lookAt = lookAt;
this.upVector = upVector;
}
/**
* returns the rotation of the target
* @return the rotation quaternion
*/
public Quaternion getRotation() {
return rotation;
}
/**
* sets the rotation of the target
* This can be used only if direction Type is Direction.PathAndRotation or Direction.Rotation
* With PathAndRotation the target will face the direction of the path multiplied by the given Quaternion.
* With Rotation the rotation of the target will be set with the given Quaternion.
* @param rotation the rotation quaternion
*/
public void setRotation(Quaternion rotation) {
this.rotation = rotation;
}
/**
* retun the motion path this control follows
* @return
*/
public MotionPath getPath() {
return path;
}
/**
* Sets the motion path to follow
* @param path
*/
public void setPath(MotionPath path) {
this.path = path;
}
public void setEnabled(boolean enabled) {
if (enabled) {
play();
} else {
pause();
}
}
public boolean isEnabled() {
return playState != PlayState.Stopped;
}
public void render(RenderManager rm, ViewPort vp) {
}
public void setSpatial(Spatial spatial) {
this.spatial = spatial;
}
public Spatial getSpatial() {
return spatial;
}
/**
* return the distance traveled by the spatial on the path
* @return
*/
public float getTraveledDistance() {
return traveledDistance;
super(spatial, path, initialDuration, loopMode);
}
}

@ -1,122 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.jme3.cinematic.events;
import com.jme3.animation.LoopMode;
import com.jme3.app.Application;
import com.jme3.cinematic.Cinematic;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Nehon
* @deprecated use spatial animation instead.
*/
@Deprecated
public class PositionTrack extends AbstractCinematicEvent {
private static final Logger log = Logger.getLogger(PositionTrack.class.getName());
private Vector3f startPosition;
private Vector3f endPosition;
private Spatial spatial;
private String spatialName = "";
private float value = 0;
public PositionTrack() {
}
public PositionTrack(Spatial spatial, Vector3f endPosition) {
this.endPosition = endPosition;
this.spatial = spatial;
spatialName = spatial.getName();
}
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
if (spatial == null) {
spatial = cinematic.getScene().getChild(spatialName);
if (spatial == null) {
} else {
log.log(Level.WARNING, "spatial {0} not found in the scene", spatialName);
}
}
}
public PositionTrack(Spatial spatial, Vector3f endPosition, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode);
this.endPosition = endPosition;
this.spatial = spatial;
spatialName = spatial.getName();
}
public PositionTrack(Spatial spatial, Vector3f endPosition, LoopMode loopMode) {
super(loopMode);
this.endPosition = endPosition;
this.spatial = spatial;
spatialName = spatial.getName();
}
public PositionTrack(Spatial spatial, Vector3f endPosition, float initialDuration) {
super(initialDuration);
this.endPosition = endPosition;
this.spatial = spatial;
spatialName = spatial.getName();
}
@Override
public void onPlay() {
if (playState != playState.Paused) {
startPosition = spatial.getWorldTranslation().clone();
}
if (initialDuration == 0 && spatial != null) {
spatial.setLocalTranslation(endPosition);
}
}
@Override
public void onUpdate(float tpf) {
if (spatial != null) {
value = Math.min(time / initialDuration, 1.0f);
Vector3f pos = FastMath.interpolateLinear(value, startPosition, endPosition);
spatial.setLocalTranslation(pos);
}
}
@Override
public void onStop() {
value = 0;
}
@Override
public void onPause() {
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(spatialName, "spatialName", "");
oc.write(endPosition, "endPosition", null);
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
spatialName = ic.readString("spatialName", "");
endPosition = (Vector3f) ic.readSavable("endPosition", null);
}
}

@ -1,126 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.jme3.cinematic.events;
import com.jme3.animation.LoopMode;
import com.jme3.app.Application;
import com.jme3.cinematic.Cinematic;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.math.Quaternion;
import com.jme3.scene.Spatial;
import com.jme3.util.TempVars;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Nehon
* @deprecated use spatial animation instead.
*/
@Deprecated
public class RotationTrack extends AbstractCinematicEvent {
private static final Logger log = Logger.getLogger(RotationTrack.class.getName());
private Quaternion startRotation = new Quaternion();
private Quaternion endRotation = new Quaternion();
private Spatial spatial;
private String spatialName = "";
private float value = 0;
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
if (spatial == null) {
spatial = cinematic.getScene().getChild(spatialName);
if (spatial == null) {
} else {
log.log(Level.WARNING, "spatial {0} not found in the scene", spatialName);
}
}
}
public RotationTrack() {
}
public RotationTrack(Spatial spatial, Quaternion endRotation) {
this.endRotation.set(endRotation);
this.spatial = spatial;
spatialName = spatial.getName();
}
public RotationTrack(Spatial spatial, Quaternion endRotation, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode);
this.endRotation.set(endRotation);
this.spatial = spatial;
spatialName = spatial.getName();
}
public RotationTrack(Spatial spatial, Quaternion endRotation, LoopMode loopMode) {
super(loopMode);
this.endRotation.set(endRotation);
this.spatial = spatial;
spatialName = spatial.getName();
}
public RotationTrack(Spatial spatial, Quaternion endRotation, float initialDuration) {
super(initialDuration);
this.endRotation.set(endRotation);
this.spatial = spatial;
spatialName = spatial.getName();
}
@Override
public void onPlay() {
if (playState != playState.Paused) {
startRotation.set(spatial.getWorldRotation());
}
if (initialDuration == 0 && spatial != null) {
spatial.setLocalRotation(endRotation);
stop();
}
}
@Override
public void onUpdate(float tpf) {
if (spatial != null) {
value = Math.min(time / initialDuration, 1.0f);
TempVars vars = TempVars.get();
Quaternion q = vars.quat1;
q.set(startRotation).slerp(endRotation, value);
spatial.setLocalRotation(q);
vars.release();
}
}
@Override
public void onStop() {
value = 0;
}
@Override
public void onPause() {
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(spatialName, "spatialName", "");
oc.write(endRotation, "endRotation", null);
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
spatialName = ic.readString("spatialName", "");
endRotation = (Quaternion) ic.readSavable("endRotation", null);
}
}

@ -1,121 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.jme3.cinematic.events;
import com.jme3.animation.LoopMode;
import com.jme3.app.Application;
import com.jme3.cinematic.Cinematic;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Nehon
* @deprecated use spatial animation instead.
*/
@Deprecated
public class ScaleTrack extends AbstractCinematicEvent {
private static final Logger log = Logger.getLogger(RotationTrack.class.getName());
private Vector3f startScale;
private Vector3f endScale;
private Spatial spatial;
private String spatialName = "";
private float value = 0;
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
if (spatial == null) {
spatial = cinematic.getScene().getChild(spatialName);
if (spatial == null) {
} else {
log.log(Level.WARNING, "spatial {0} not found in the scene", spatialName);
}
}
}
public ScaleTrack() {
}
public ScaleTrack(Spatial spatial, Vector3f endScale) {
this.endScale = endScale;
this.spatial = spatial;
spatialName = spatial.getName();
}
public ScaleTrack(Spatial spatial, Vector3f endScale, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode);
this.endScale = endScale;
this.spatial = spatial;
spatialName = spatial.getName();
}
public ScaleTrack(Spatial spatial, Vector3f endScale, LoopMode loopMode) {
super(loopMode);
this.endScale = endScale;
this.spatial = spatial;
spatialName = spatial.getName();
}
public ScaleTrack(Spatial spatial, Vector3f endScale, float initialDuration) {
super(initialDuration);
this.endScale = endScale;
this.spatial = spatial;
spatialName = spatial.getName();
}
@Override
public void onPlay() {
if (playState != playState.Paused) {
startScale = spatial.getWorldScale().clone();
}
if (initialDuration == 0 && spatial != null) {
spatial.setLocalScale(endScale);
stop();
}
}
@Override
public void onUpdate(float tpf) {
if (spatial != null) {
value = Math.min(time / initialDuration, 1.0f);
spatial.setLocalScale(FastMath.interpolateLinear(value, startScale, endScale));
}
}
@Override
public void onStop() {
value = 0;
}
@Override
public void onPause() {
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(spatialName, "spatialName", "");
oc.write(endScale, "endScale", null);
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
spatialName = ic.readString("spatialName", "");
endScale = (Vector3f) ic.readSavable("endScale", null);
}
}

@ -0,0 +1,184 @@
/*
* Copyright (c) 2009-2010 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.animation.LoopMode;
import com.jme3.app.Application;
import com.jme3.audio.AudioNode;
import com.jme3.cinematic.Cinematic;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import java.io.IOException;
/**
* A sound track to be played in a cinematic.
* @author Nehon
*/
public class SoundEvent extends AbstractCinematicEvent {
protected String path;
protected AudioNode audioNode;
protected boolean stream = false;
/**
* creates a sound track from the given resource path
* @param path the path to an audi file (ie : "Sounds/mySound.wav")
*/
public SoundEvent(String path) {
this.path = path;
}
/**
* creates a sound track from the given resource path
* @param path the path to an audi file (ie : "Sounds/mySound.wav")
* @param stream true to make the audio data streamed
*/
public SoundEvent(String path, boolean stream) {
this(path);
this.stream = stream;
}
public SoundEvent(String path, boolean stream, float initialDuration) {
super(initialDuration);
this.path = path;
this.stream = stream;
}
public SoundEvent(String path, boolean stream, LoopMode loopMode) {
super(loopMode);
this.path = path;
this.stream = stream;
}
public SoundEvent(String path, boolean stream, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode);
this.path = path;
this.stream = stream;
}
public SoundEvent(String path, float initialDuration) {
super(initialDuration);
this.path = path;
}
public SoundEvent(String path, LoopMode loopMode) {
super(loopMode);
this.path = path;
}
public SoundEvent(String path, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode);
this.path = path;
}
public SoundEvent() {
}
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
audioNode = new AudioNode(app.getAssetManager(), path, stream);
setLoopMode(loopMode);
}
@Override
public void setTime(float time) {
super.setTime(time);
//can occur on rewind
if (time < 0f) {
stop();
}else{
audioNode.setTimeOffset(time);
}
}
@Override
public void onPlay() {
audioNode.play();
}
@Override
public void onStop() {
audioNode.stop();
}
@Override
public void onPause() {
audioNode.pause();
}
@Override
public void onUpdate(float tpf) {
if (audioNode.getStatus() == AudioNode.Status.Stopped) {
stop();
}
}
/**
* Returns the underlying audion node of this sound track
* @return
*/
public AudioNode getAudioNode() {
return audioNode;
}
@Override
public void setLoopMode(LoopMode loopMode) {
super.setLoopMode(loopMode);
if (loopMode != LoopMode.DontLoop) {
audioNode.setLooping(true);
} else {
audioNode.setLooping(false);
}
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(path, "path", "");
oc.write(stream, "stream", false);
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
path = ic.readString("path", "");
stream = ic.readBoolean("stream", false);
}
}

@ -32,31 +32,21 @@
package com.jme3.cinematic.events;
import com.jme3.animation.LoopMode;
import com.jme3.app.Application;
import com.jme3.audio.AudioNode;
import com.jme3.cinematic.Cinematic;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import java.io.IOException;
/**
* A sound track to be played in a cinematic.
* @author Nehon
* @deprecated use SoundEvent instead
*/
public class SoundTrack extends AbstractCinematicEvent {
protected String path;
protected AudioNode audioNode;
protected boolean stream = false;
@Deprecated
public class SoundTrack extends SoundEvent {
/**
* creates a sound track from the given resource path
* @param path the path to an audi file (ie : "Sounds/mySound.wav")
*/
public SoundTrack(String path) {
this.path = path;
super(path);
}
/**
@ -65,120 +55,35 @@ public class SoundTrack extends AbstractCinematicEvent {
* @param stream true to make the audio data streamed
*/
public SoundTrack(String path, boolean stream) {
this(path);
this.stream = stream;
super(path, stream);
}
public SoundTrack(String path, boolean stream, float initialDuration) {
super(initialDuration);
this.path = path;
this.stream = stream;
super(path, stream, initialDuration);
}
public SoundTrack(String path, boolean stream, LoopMode loopMode) {
super(loopMode);
this.path = path;
this.stream = stream;
super(path, stream, loopMode);
}
public SoundTrack(String path, boolean stream, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode);
this.path = path;
this.stream = stream;
super(path, stream, initialDuration, loopMode);
}
public SoundTrack(String path, float initialDuration) {
super(initialDuration);
this.path = path;
super(path, initialDuration);
}
public SoundTrack(String path, LoopMode loopMode) {
super(loopMode);
this.path = path;
super(path, loopMode);
}
public SoundTrack(String path, float initialDuration, LoopMode loopMode) {
super(initialDuration, loopMode);
this.path = path;
super(path, initialDuration, loopMode);
}
public SoundTrack() {
}
@Override
public void initEvent(Application app, Cinematic cinematic) {
super.initEvent(app, cinematic);
audioNode = new AudioNode(app.getAssetManager(), path, stream);
setLoopMode(loopMode);
}
@Override
public void setTime(float time) {
super.setTime(time);
//can occur on rewind
if (time < 0f) {
stop();
}else{
audioNode.setTimeOffset(time);
}
}
@Override
public void onPlay() {
audioNode.play();
}
@Override
public void onStop() {
audioNode.stop();
}
@Override
public void onPause() {
audioNode.pause();
}
@Override
public void onUpdate(float tpf) {
if (audioNode.getStatus() == AudioNode.Status.Stopped) {
stop();
}
}
/**
* Returns the underlying audion node of this sound track
* @return
*/
public AudioNode getAudioNode() {
return audioNode;
}
@Override
public void setLoopMode(LoopMode loopMode) {
super.setLoopMode(loopMode);
if (loopMode != LoopMode.DontLoop) {
audioNode.setLooping(true);
} else {
audioNode.setLooping(false);
}
}
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(path, "path", "");
oc.write(stream, "stream", false);
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
path = ic.readString("path", "");
stream = ic.readBoolean("stream", false);
super();
}
}

@ -35,7 +35,8 @@ import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.MotionPathListener;
import com.jme3.cinematic.events.MotionTrack;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.font.BitmapText;
import com.jme3.input.ChaseCamera;
import com.jme3.input.KeyInput;
@ -58,7 +59,7 @@ public class TestCameraMotionPath extends SimpleApplication {
private boolean active = true;
private boolean playing = false;
private MotionPath path;
private MotionTrack cameraMotionControl;
private MotionEvent cameraMotionControl;
private ChaseCamera chaser;
private CameraNode camNode;
@ -83,11 +84,11 @@ public class TestCameraMotionPath extends SimpleApplication {
path.setCurveTension(0.83f);
path.enableDebugShape(assetManager, rootNode);
cameraMotionControl = new MotionTrack(camNode, path);
cameraMotionControl = new MotionEvent(camNode, path);
cameraMotionControl.setLoopMode(LoopMode.Loop);
//cameraMotionControl.setDuration(15f);
cameraMotionControl.setLookAt(teapot.getWorldTranslation(), Vector3f.UNIT_Y);
cameraMotionControl.setDirectionType(MotionTrack.Direction.LookAt);
cameraMotionControl.setDirectionType(MotionEvent.Direction.LookAt);
rootNode.attachChild(camNode);
@ -99,7 +100,7 @@ public class TestCameraMotionPath extends SimpleApplication {
path.addListener(new MotionPathListener() {
public void onWayPointReach(MotionTrack control, int wayPointIndex) {
public void onWayPointReach(MotionEvent control, int wayPointIndex) {
if (path.getNbWayPoints() == wayPointIndex + 1) {
wayPointsText.setText(control.getSpatial().getName() + " Finish!!! ");
} else {
@ -180,7 +181,7 @@ public class TestCameraMotionPath extends SimpleApplication {
}
if (name.equals("SwitchPathInterpolation") && keyPressed) {
if (path.getPathSplineType() == SplineType.CatmullRom){
if (path.getPathSplineType() == SplineType.CatmullRom) {
path.setPathSplineType(SplineType.Linear);
} else {
path.setPathSplineType(SplineType.CatmullRom);

@ -65,7 +65,7 @@ public class TestCinematic extends SimpleApplication {
private Spatial model;
private Spatial teapot;
private MotionPath path;
private MotionTrack cameraMotionTrack;
private MotionEvent cameraMotionEvent;
private Cinematic cinematic;
private ChaseCamera chaseCam;
private FilterPostProcessor fpp;
@ -119,16 +119,16 @@ public class TestCinematic extends SimpleApplication {
//fade in
cinematic.addCinematicEvent(0, new FadeEvent(true));
// cinematic.activateCamera(0, "aroundCam");
cinematic.addCinematicEvent(0, new AnimationTrack(teapot, "teapotAnim", LoopMode.DontLoop));
cinematic.addCinematicEvent(0, cameraMotionTrack);
cinematic.addCinematicEvent(0, new SoundTrack("Sound/Environment/Nature.ogg", LoopMode.Loop));
cinematic.addCinematicEvent(3f, new SoundTrack("Sound/Effects/kick.wav"));
// cinematic.activateCamera(0, "aroundCam");
cinematic.addCinematicEvent(0, new AnimationEvent(teapot, "teapotAnim", LoopMode.DontLoop));
cinematic.addCinematicEvent(0, cameraMotionEvent);
cinematic.addCinematicEvent(0, new SoundEvent("Sound/Environment/Nature.ogg", LoopMode.Loop));
cinematic.addCinematicEvent(3f, new SoundEvent("Sound/Effects/kick.wav"));
cinematic.addCinematicEvent(3, new SubtitleTrack(nifty, "start", 3, "jMonkey engine really kicks A..."));
cinematic.addCinematicEvent(5.1f, new SoundTrack("Sound/Effects/Beep.ogg", 1));
cinematic.addCinematicEvent(2, new AnimationTrack(model, "Walk", LoopMode.Loop));
cinematic.addCinematicEvent(5.1f, new SoundEvent("Sound/Effects/Beep.ogg", 1));
cinematic.addCinematicEvent(2, new AnimationEvent(model, "Walk", LoopMode.Loop));
cinematic.activateCamera(0, "topView");
// cinematic.activateCamera(10, "aroundCam");
// cinematic.activateCamera(10, "aroundCam");
//fade out
cinematic.addCinematicEvent(19, new FadeEvent(false));
@ -193,10 +193,10 @@ public class TestCinematic extends SimpleApplication {
path.addWayPoint(new Vector3f(-20, 3, 0));
path.addWayPoint(new Vector3f(0, 3, -20));
path.setCurveTension(0.83f);
cameraMotionTrack = new MotionTrack(camNode2, path);
cameraMotionTrack.setLoopMode(LoopMode.Loop);
cameraMotionTrack.setLookAt(model.getWorldTranslation(), Vector3f.UNIT_Y);
cameraMotionTrack.setDirectionType(MotionTrack.Direction.LookAt);
cameraMotionEvent = new MotionEvent(camNode2, path);
cameraMotionEvent.setLoopMode(LoopMode.Loop);
cameraMotionEvent.setLookAt(model.getWorldTranslation(), Vector3f.UNIT_Y);
cameraMotionEvent.setDirectionType(MotionEvent.Direction.LookAt);
}

@ -35,7 +35,8 @@ import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.MotionPathListener;
import com.jme3.cinematic.events.MotionTrack;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.font.BitmapText;
import com.jme3.input.ChaseCamera;
import com.jme3.input.KeyInput;
@ -58,7 +59,7 @@ public class TestMotionPath extends SimpleApplication {
private boolean active = true;
private boolean playing = false;
private MotionPath path;
private MotionTrack motionControl;
private MotionEvent motionControl;
public static void main(String[] args) {
TestMotionPath app = new TestMotionPath();
@ -80,8 +81,8 @@ public class TestMotionPath extends SimpleApplication {
path.addWayPoint(new Vector3f(15, 8, 10));
path.enableDebugShape(assetManager, rootNode);
motionControl = new MotionTrack(teapot,path);
motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
motionControl = new MotionEvent(teapot,path);
motionControl.setDirectionType(MotionEvent.Direction.PathAndRotation);
motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
motionControl.setInitialDuration(10f);
motionControl.setSpeed(2f);
@ -93,7 +94,7 @@ public class TestMotionPath extends SimpleApplication {
path.addListener(new MotionPathListener() {
public void onWayPointReach(MotionTrack control, int wayPointIndex) {
public void onWayPointReach(MotionEvent control, int wayPointIndex) {
if (path.getNbWayPoints() == wayPointIndex + 1) {
wayPointsText.setText(control.getSpatial().getName() + "Finished!!! ");
} else {

Loading…
Cancel
Save