Skip to content

Commit 1433f98

Browse files
sylunastephengold
authored andcommitted
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.
1 parent 11d3bc6 commit 1433f98

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

jme3-examples/src/main/java/jme3test/model/anim/TestBlenderAnim.java

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232

3333
package jme3test.model.anim;
3434

35-
import com.jme3.animation.AnimChannel;
36-
import com.jme3.animation.AnimControl;
35+
import com.jme3.anim.AnimClip;
36+
import com.jme3.anim.AnimComposer;
37+
import com.jme3.anim.util.AnimMigrationUtils;
3738
import com.jme3.app.SimpleApplication;
3839
import com.jme3.asset.BlenderKey;
3940
import com.jme3.light.DirectionalLight;
@@ -45,49 +46,50 @@
4546

4647
public class TestBlenderAnim extends SimpleApplication {
4748

48-
private AnimChannel channel;
49-
private AnimControl control;
49+
public static void main(String[] args) {
50+
TestBlenderAnim app = new TestBlenderAnim();
51+
app.start();
52+
}
5053

51-
public static void main(String[] args) {
52-
TestBlenderAnim app = new TestBlenderAnim();
53-
app.start();
54-
}
54+
@Override
55+
public void simpleInitApp() {
56+
flyCam.setMoveSpeed(10f);
57+
cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
58+
cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));
5559

56-
@Override
57-
public void simpleInitApp() {
58-
flyCam.setMoveSpeed(10f);
59-
cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
60-
cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));
60+
DirectionalLight dl = new DirectionalLight();
61+
dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
62+
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
63+
rootNode.addLight(dl);
6164

62-
DirectionalLight dl = new DirectionalLight();
63-
dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
64-
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
65-
rootNode.addLight(dl);
65+
BlenderKey blenderKey = new BlenderKey("Blender/2.4x/BaseMesh_249.blend");
6666

67-
BlenderKey blenderKey = new BlenderKey("Blender/2.4x/BaseMesh_249.blend");
68-
69-
Spatial scene = assetManager.loadModel(blenderKey);
70-
rootNode.attachChild(scene);
71-
72-
Spatial model = this.findNode(rootNode, "BaseMesh_01");
73-
model.center();
74-
75-
control = model.getControl(AnimControl.class);
76-
channel = control.createChannel();
67+
Spatial scene = assetManager.loadModel(blenderKey);
68+
rootNode.attachChild(scene);
7769

78-
channel.setAnim("run_01");
79-
}
80-
81-
/**
82-
* This method finds a node of a given name.
83-
* @param rootNode the root node to search
84-
* @param name the name of the searched node
85-
* @return the found node or null
86-
*/
87-
private Spatial findNode(Node rootNode, String name) {
88-
if (name.equals(rootNode.getName())) {
89-
return rootNode;
90-
}
91-
return rootNode.getChild(name);
92-
}
70+
Spatial model = this.findNode(rootNode, "BaseMesh_01");
71+
AnimMigrationUtils.migrate(model);
72+
model.center();
73+
74+
AnimComposer animComposer = model.getControl(AnimComposer.class);
75+
animComposer.getAnimClips().forEach(animClip -> System.out.println("AnimClip name: " + animClip.getName()));
76+
AnimClip animClip = animComposer.getAnimClip("run_01"); // run_sideway_left, aim, run_sideway_right, base_stand, run_01, base, jump
77+
animComposer.setCurrentAction(animClip.getName());
78+
}
79+
80+
/**
81+
* This method finds a node of a given name.
82+
*
83+
* @param rootNode
84+
* the root node to search
85+
* @param name
86+
* the name of the searched node
87+
* @return the found node or null
88+
*/
89+
private Spatial findNode(Node rootNode, String name) {
90+
if (name.equals(rootNode.getName())) {
91+
return rootNode;
92+
}
93+
return rootNode.getChild(name);
94+
}
9395
}

0 commit comments

Comments
 (0)