Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions jme3-core/src/main/java/com/jme3/cinematic/events/AnimEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public class AnimEvent extends AbstractCinematicEvent {
private String layerName;

/**
* Instantiate an event.
* Instantiate a non-looping event to play the named action on the named
* layer of the specified AnimComposer.
*
* @param composer the Control that will play the animation (not null)
* @param actionName the name of the animation action to be played
Expand All @@ -86,6 +87,14 @@ public AnimEvent(AnimComposer composer, String actionName,
this.composer = composer;
this.actionName = actionName;
this.layerName = layerName;
/*
* Override initialDuration, which defaults to 10 seconds.
*/
Action eventAction = composer.action(actionName);
if (eventAction == null) {
throw new IllegalStateException("No action named: " + actionName);
}
initialDuration = (float) eventAction.getLength();
}

/**
Expand Down Expand Up @@ -132,7 +141,7 @@ public void onPlay() {
}

if (currentAction != eventAction) {
composer.setCurrentAction(actionName);
composer.setCurrentAction(actionName, layerName);
assert composer.getCurrentAction(layerName) == eventAction;
}

Expand Down Expand Up @@ -209,7 +218,7 @@ public void setTime(float time) {
Action currentAction = composer.getCurrentAction(layerName);
Action eventAction = composer.action(actionName);
if (currentAction != eventAction) {
composer.setCurrentAction(actionName);
composer.setCurrentAction(actionName, layerName);
assert composer.getCurrentAction(layerName) == eventAction;
}

Expand Down
37 changes: 26 additions & 11 deletions jme3-examples/src/main/java/jme3test/animation/TestCinematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
*/
package jme3test.animation;

import com.jme3.anim.AnimClip;
import com.jme3.anim.AnimComposer;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimationFactory;
import com.jme3.anim.AnimFactory;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.cinematic.*;
Expand Down Expand Up @@ -100,28 +100,43 @@ public void simpleInitApp() {
createCameraMotion();

//creating spatial animation for the teapot
AnimationFactory factory = new AnimationFactory(20, "teapotAnim");
AnimFactory factory = new AnimFactory(20f, "teapotAnim", 30f);
factory.addTimeTranslation(0, new Vector3f(10, 0, 10));
factory.addTimeTranslation(20, new Vector3f(10, 0, -10));
factory.addTimeScale(10, new Vector3f(4, 4, 4));
factory.addTimeScale(20, new Vector3f(1, 1, 1));
factory.addTimeRotationAngles(20, 0, 4 * FastMath.TWO_PI, 0);
AnimControl control = new AnimControl();
control.addAnim(factory.buildAnimation());
teapot.addControl(control);
for (int iStep = 1; iStep <= 12; ++iStep) {
float animationTime = iStep * 20f / 12; // in seconds
float yRotationAngle = iStep * FastMath.TWO_PI / 3; // in radians
factory.addTimeRotation(animationTime, 0f, yRotationAngle, 0f);
}
AnimClip spatialAnimation = factory.buildAnimation(teapot);
AnimComposer teapotComposer = new AnimComposer();
teapotComposer.addAnimClip(spatialAnimation);
teapot.addControl(teapotComposer);

//fade in
cinematic.addCinematicEvent(0, new FadeEvent(true));
// cinematic.activateCamera(0, "aroundCam");
cinematic.addCinematicEvent(0, new AnimationEvent(teapot, "teapotAnim", LoopMode.DontLoop));

// 20-second spatial animation begins at t=0 seconds
AnimEvent teapotAnimEvent = new AnimEvent(teapotComposer, "teapotAnim",
AnimComposer.DEFAULT_LAYER);
cinematic.addCinematicEvent(0f, teapotAnimEvent);

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 SoundEvent("Sound/Effects/Beep.ogg", 1));
AnimComposer composer = model.getControl(AnimComposer.class);
cinematic.addCinematicEvent(2f,
new AnimEvent(composer, "Walk", AnimComposer.DEFAULT_LAYER));

// 1.24-second bone animation loop begins at t=2 seconds
AnimComposer otoComposer = model.getControl(AnimComposer.class);
AnimEvent walkEvent = new AnimEvent(otoComposer, "Walk",
AnimComposer.DEFAULT_LAYER);
walkEvent.setLoopMode(LoopMode.Loop);
cinematic.addCinematicEvent(2f, walkEvent);

cinematic.activateCamera(0, "topView");
// cinematic.activateCamera(10, "aroundCam");

Expand Down
54 changes: 37 additions & 17 deletions jme3-examples/src/main/java/jme3test/animation/TestJaime.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
*/
package jme3test.animation;

import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimationFactory;
import com.jme3.anim.AnimClip;
import com.jme3.anim.AnimComposer;
import com.jme3.anim.AnimFactory;
import com.jme3.anim.util.AnimMigrationUtils;
import com.jme3.animation.LoopMode;
import com.jme3.app.DebugKeysAppState;
import com.jme3.app.FlyCamAppState;
Expand All @@ -42,7 +44,7 @@
import com.jme3.cinematic.Cinematic;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.PlayState;
import com.jme3.cinematic.events.AnimationEvent;
import com.jme3.cinematic.events.AnimEvent;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
Expand Down Expand Up @@ -99,6 +101,7 @@ public void simpleInitApp() {

public Node LoadModel() {
Node jaime = (Node)assetManager.loadModel("Models/Jaime/Jaime.j3o");
jaime = (Node) AnimMigrationUtils.migrate(jaime);
jaime.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
rootNode.attachChild(jaime);
return jaime;
Expand Down Expand Up @@ -149,23 +152,40 @@ public void setupCinematic(final Node jaime) {
stateManager.attach(cinematic);

jaime.move(0, 0, -3);
AnimationFactory af = new AnimationFactory(0.7f, "JumpForward");
AnimFactory af = new AnimFactory(0.7f, "JumpForward", 30f);
af.addTimeTranslation(0, new Vector3f(0, 0, -3));
af.addTimeTranslation(0.35f, new Vector3f(0, 1, -1.5f));
af.addTimeTranslation(0.7f, new Vector3f(0, 0, 0));
jaime.getControl(AnimControl.class).addAnim(af.buildAnimation());

cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle",3, LoopMode.DontLoop));
float jumpStart = cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "JumpStart", LoopMode.DontLoop));
cinematic.addCinematicEvent(jumpStart+0.2f, new AnimationEvent(jaime, "JumpForward", LoopMode.DontLoop,1));
cinematic.enqueueCinematicEvent( new AnimationEvent(jaime, "JumpEnd", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent( new AnimationEvent(jaime, "Punches", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent( new AnimationEvent(jaime, "SideKick", LoopMode.DontLoop));
float camStart = cinematic.enqueueCinematicEvent( new AnimationEvent(jaime, "Taunt", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent( new AnimationEvent(jaime, "Idle",1, LoopMode.DontLoop));
cinematic.enqueueCinematicEvent( new AnimationEvent(jaime, "Wave", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent( new AnimationEvent(jaime, "Idle", LoopMode.DontLoop));

AnimClip forwardClip = af.buildAnimation(jaime);
AnimComposer composer = jaime.getControl(AnimComposer.class);
composer.addAnimClip(forwardClip);

composer.makeLayer("SpatialLayer", null);
String boneLayer = AnimComposer.DEFAULT_LAYER;

cinematic.enqueueCinematicEvent(
new AnimEvent(composer, "Idle", boneLayer));
float jumpStart = cinematic.enqueueCinematicEvent(
new AnimEvent(composer, "JumpStart", boneLayer));
cinematic.addCinematicEvent(jumpStart + 0.2f,
new AnimEvent(composer, "JumpForward", "SpatialLayer"));
cinematic.enqueueCinematicEvent(
new AnimEvent(composer, "JumpEnd", boneLayer));
cinematic.enqueueCinematicEvent(
new AnimEvent(composer, "Punches", boneLayer));
cinematic.enqueueCinematicEvent(
new AnimEvent(composer, "SideKick", boneLayer));

float camStart = cinematic.enqueueCinematicEvent(
new AnimEvent(composer, "Taunt", boneLayer));
AnimEvent idleOneSecond = new AnimEvent(composer, "Idle", boneLayer);
idleOneSecond.setInitialDuration(1f);
cinematic.enqueueCinematicEvent(idleOneSecond);
cinematic.enqueueCinematicEvent(
new AnimEvent(composer, "Wave", boneLayer));
cinematic.enqueueCinematicEvent(
new AnimEvent(composer, "Idle", boneLayer));

CameraNode camNode = cinematic.bindCamera("cam", cam);
camNode.setLocalTranslation(new Vector3f(1.1f, 1.2f, 2.9f));
camNode.lookAt(new Vector3f(0, 0.5f, 0), Vector3f.UNIT_Y);
Expand Down