AnimComposer: updated to save globalSpeed on export and fixed issue with Layer cloning (#1080)

* AnimComposer: save globalSpeed on export

* Updated TestModelExportingCloning to test AnimComposer.globalSpeed

* Fixed issue with AnimComposer.Layer cloning
accellbaker
Ali-RS 6 years ago committed by GitHub
parent 50aed6f59e
commit c4d2de1656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      jme3-core/src/main/java/com/jme3/anim/AnimComposer.java
  2. 3
      jme3-examples/src/main/java/jme3test/model/anim/TestModelExportingCloning.java

@ -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));
}
/**
@ -171,7 +171,7 @@ public class AnimComposer extends AbstractControl {
}
public void makeLayer(String name, AnimationMask mask) {
Layer l = new Layer();
Layer l = new Layer(this);
l.mask = mask;
layers.put(name, l);
}
@ -300,6 +300,7 @@ public class AnimComposer extends AbstractControl {
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
@ -307,16 +308,22 @@ public class AnimComposer extends AbstractControl {
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();
@ -337,6 +344,7 @@ public class AnimComposer extends AbstractControl {
@Override
public void cloneFields(Cloner cloner, Object original) {
ac = cloner.clone(ac);
currentAction = null;
}
}

@ -61,18 +61,21 @@ public class TestModelExportingCloning extends SimpleApplication {
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);
}
}

Loading…
Cancel
Save