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
32 changes: 32 additions & 0 deletions jme3-core/src/main/java/com/jme3/anim/AnimComposer.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,37 @@ public void setGlobalSpeed(float globalSpeed) {
this.globalSpeed = globalSpeed;
}

/**
* Access the manager of the named layer.
*
* @param layerName the name of the layer to access
* @return the current manager (typically an AnimEvent) or null for none
*/
public Object getLayerManager(String layerName) {
Layer layer = layers.get(layerName);
if (layer == null) {
throw new IllegalArgumentException("Unknown layer " + layerName);
}

return layer.manager;
}

/**
* Assign a manager to the named layer.
*
* @param layerName the name of the layer to modify
* @param manager the desired manager (typically an AnimEvent) or null for
* none
*/
public void setLayerManager(String layerName, Object manager) {
Layer layer = layers.get(layerName);
if (layer == null) {
throw new IllegalArgumentException("Unknown layer " + layerName);
}

layer.manager = manager;
}

/**
* Create a shallow clone for the JME cloner.
*
Expand Down Expand Up @@ -539,6 +570,7 @@ private static class Layer implements JmeCloneable {
private Action currentAction;
private AnimationMask mask;
private double time;
private Object manager;

public Layer(AnimComposer ac) {
this.ac = ac;
Expand Down
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 @@ -120,8 +120,11 @@ public void initEvent(Application app, Cinematic cinematic) {
public void onPause() {
logger.log(Level.SEVERE, "");

Action eventAction = composer.action(actionName);
eventAction.setSpeed(0f);
Object layerManager = composer.getLayerManager(layerName);
if (layerManager == this) {
Action eventAction = composer.action(actionName);
eventAction.setSpeed(0f);
}
}

/**
Expand All @@ -142,6 +145,7 @@ public void onPlay() {
composer.setTime(layerName, 0.0);
}
eventAction.setSpeed(speed);
composer.setLayerManager(layerName, this);
}

/**
Expand All @@ -150,7 +154,12 @@ public void onPlay() {
@Override
public void onStop() {
logger.log(Level.INFO, "");
composer.removeCurrentAction(layerName);

Object layerManager = composer.getLayerManager(layerName);
if (layerManager == this) {
composer.removeCurrentAction(layerName);
composer.setLayerManager(layerName, null);
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions jme3-examples/src/main/java/jme3test/animation/TestJaime.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,19 @@ public void setupCinematic(final Node jaime) {
AnimClip forwardClip = af.buildAnimation(jaime);
AnimComposer composer = jaime.getControl(AnimComposer.class);
composer.addAnimClip(forwardClip);
/*
* Add a clip that warps the model to its starting position.
*/
AnimFactory af2 = new AnimFactory(0.01f, "StartingPosition", 30f);
af2.addTimeTranslation(0f, new Vector3f(0f, 0f, -3f));
AnimClip startClip = af2.buildAnimation(jaime);
composer.addAnimClip(startClip);

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

cinematic.addCinematicEvent(0f,
new AnimEvent(composer, "StartingPosition", "SpatialLayer"));
cinematic.enqueueCinematicEvent(
new AnimEvent(composer, "Idle", boneLayer));
float jumpStart = cinematic.enqueueCinematicEvent(
Expand Down