Migrate TestBlenderAnim to the new anim system

Migrate to the new animation system, migration of old Spatial object containing animation and adding method to list all animation name in AnimComposer.
master
Jérôme 5 years ago committed by Stephen Gold
parent 11d3bc67f8
commit 1433f98ad3
  1. 86
      jme3-examples/src/main/java/jme3test/model/anim/TestBlenderAnim.java

@ -32,8 +32,9 @@
package jme3test.model.anim; package jme3test.model.anim;
import com.jme3.animation.AnimChannel; import com.jme3.anim.AnimClip;
import com.jme3.animation.AnimControl; import com.jme3.anim.AnimComposer;
import com.jme3.anim.util.AnimMigrationUtils;
import com.jme3.app.SimpleApplication; import com.jme3.app.SimpleApplication;
import com.jme3.asset.BlenderKey; import com.jme3.asset.BlenderKey;
import com.jme3.light.DirectionalLight; import com.jme3.light.DirectionalLight;
@ -45,49 +46,50 @@ import com.jme3.scene.Spatial;
public class TestBlenderAnim extends SimpleApplication { public class TestBlenderAnim extends SimpleApplication {
private AnimChannel channel; public static void main(String[] args) {
private AnimControl control; TestBlenderAnim app = new TestBlenderAnim();
app.start();
}
public static void main(String[] args) { @Override
TestBlenderAnim app = new TestBlenderAnim(); public void simpleInitApp() {
app.start(); flyCam.setMoveSpeed(10f);
} cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));
@Override DirectionalLight dl = new DirectionalLight();
public void simpleInitApp() { dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
flyCam.setMoveSpeed(10f); dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f)); rootNode.addLight(dl);
cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));
DirectionalLight dl = new DirectionalLight(); BlenderKey blenderKey = new BlenderKey("Blender/2.4x/BaseMesh_249.blend");
dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
rootNode.addLight(dl);
BlenderKey blenderKey = new BlenderKey("Blender/2.4x/BaseMesh_249.blend"); Spatial scene = assetManager.loadModel(blenderKey);
rootNode.attachChild(scene);
Spatial scene = assetManager.loadModel(blenderKey);
rootNode.attachChild(scene);
Spatial model = this.findNode(rootNode, "BaseMesh_01");
model.center();
control = model.getControl(AnimControl.class);
channel = control.createChannel();
channel.setAnim("run_01"); Spatial model = this.findNode(rootNode, "BaseMesh_01");
} AnimMigrationUtils.migrate(model);
model.center();
/**
* This method finds a node of a given name. AnimComposer animComposer = model.getControl(AnimComposer.class);
* @param rootNode the root node to search animComposer.getAnimClips().forEach(animClip -> System.out.println("AnimClip name: " + animClip.getName()));
* @param name the name of the searched node AnimClip animClip = animComposer.getAnimClip("run_01"); // run_sideway_left, aim, run_sideway_right, base_stand, run_01, base, jump
* @return the found node or null animComposer.setCurrentAction(animClip.getName());
*/ }
private Spatial findNode(Node rootNode, String name) {
if (name.equals(rootNode.getName())) { /**
return rootNode; * This method finds a node of a given name.
} *
return rootNode.getChild(name); * @param rootNode
} * the root node to search
* @param name
* the name of the searched node
* @return the found node or null
*/
private Spatial findNode(Node rootNode, String name) {
if (name.equals(rootNode.getName())) {
return rootNode;
}
return rootNode.getChild(name);
}
} }

Loading…
Cancel
Save