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
16 changes: 12 additions & 4 deletions jme3-core/src/main/java/com/jme3/anim/AnimComposer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AnimComposer extends AbstractControl {
private Map<String, Layer> layers = new LinkedHashMap<>();

public AnimComposer() {
layers.put(DEFAULT_LAYER, new Layer());
layers.put(DEFAULT_LAYER, new Layer(this));
}

/**
Expand Down Expand Up @@ -171,7 +171,7 @@ public Action removeAction(String name) {
}

public void makeLayer(String name, AnimationMask mask) {
Layer l = new Layer();
Layer l = new Layer(this);
l.mask = mask;
layers.put(name, l);
}
Expand Down Expand Up @@ -300,23 +300,30 @@ public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
animClipMap = (Map<String, AnimClip>) ic.readStringSavableMap("animClipMap", new HashMap<String, AnimClip>());
globalSpeed = ic.readFloat("globalSpeed", 1f);
}

@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.writeStringSavableMap(animClipMap, "animClipMap", new HashMap<String, AnimClip>());
oc.write(globalSpeed, "globalSpeed", 1f);
}

private class Layer implements JmeCloneable {
private static class Layer implements JmeCloneable {
private AnimComposer ac;
private Action currentAction;
private AnimationMask mask;
private float weight;
private double time;

public Layer(AnimComposer ac) {
this.ac = ac;
}

public void advance(float tpf) {
time += tpf * currentAction.getSpeed() * globalSpeed;
time += tpf * currentAction.getSpeed() * ac.globalSpeed;
// make sure negative time is in [0, length] range
if (time < 0) {
double length = currentAction.getLength();
Expand All @@ -337,6 +344,7 @@ public Object jmeClone() {

@Override
public void cloneFields(Cloner cloner, Object original) {
ac = cloner.clone(ac);
currentAction = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ public void simpleInitApp() {
Spatial originalModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
composer = originalModel.getControl(AnimComposer.class);
composer.setCurrentAction("Walk");
composer.setGlobalSpeed(1.5f);
rootNode.attachChild(originalModel);

Spatial clonedModel = originalModel.clone();
clonedModel.move(10, 0, 0);
composer = clonedModel.getControl(AnimComposer.class);
composer.setCurrentAction("push");
System.out.println("clonedModel: globalSpeed=" + composer.getGlobalSpeed());
rootNode.attachChild(clonedModel);

Spatial exportedModel = BinaryExporter.saveAndLoad(assetManager, originalModel);
exportedModel.move(20, 0, 0);
composer = exportedModel.getControl(AnimComposer.class);
composer.setCurrentAction("pull");
System.out.println("exportedModel: globalSpeed=" + composer.getGlobalSpeed());
rootNode.attachChild(exportedModel);
}
}