|
32 | 32 |
|
33 | 33 | package jme3test.model.anim; |
34 | 34 |
|
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; |
37 | 38 | import com.jme3.app.SimpleApplication; |
38 | 39 | import com.jme3.asset.BlenderKey; |
39 | 40 | import com.jme3.light.DirectionalLight; |
|
45 | 46 |
|
46 | 47 | public class TestBlenderAnim extends SimpleApplication { |
47 | 48 |
|
48 | | - private AnimChannel channel; |
49 | | - private AnimControl control; |
| 49 | + public static void main(String[] args) { |
| 50 | + TestBlenderAnim app = new TestBlenderAnim(); |
| 51 | + app.start(); |
| 52 | + } |
50 | 53 |
|
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)); |
55 | 59 |
|
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); |
61 | 64 |
|
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"); |
66 | 66 |
|
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); |
77 | 69 |
|
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 | + } |
93 | 95 | } |
0 commit comments