[SOLVED] How to run glb animation?

I make model
In blender i have animations


hit
die
stand
run

in jmonkey:

character = assetManager.loadModel("Models/char.glb");
        rootNode.attachChild(character);
        character.setLocalTranslation(1.2311511f, -0.5f, 6.1211777f);
        character.setLocalScale(0.1f);
        character.rotate(0, -1.7f, 0);
        AnimComposer animComposer = character.getControl(AnimComposer.class);
        animComposer.setCurrentAction("run");

and have error:
java.lang.NullPointerException
at com.mygame.Main.initMain(Main.java:99)

run animation not exists

how to run blender animation in jmonkey (glb model) ?

1 Like

try this

AnimControl control = character.getControl(AnimControl.class);
        AnimChannel channel = control.createChannel(); <- line 103
        channel.setAnim("run");

java.lang.NullPointerException
at com.mygame.Main.initMain(Main.java:103)

control is null. character does not have an AnimControl.

…it would be an AnimComposer anyway.

But there is no guarantee if it’s on the root character node. You may have to get it from a child.

1 Like

Try this

Node charNode = (Node)character;
       Spatial body = charNode.getChild("Body");
       AnimComposer animComposer = body.getControl(AnimComposer.class); <- 105
       animComposer.setCurrentAction("run");

java.lang.NullPointerException
at com.mygame.Main.initMain(Main.java:105)

Solved

Node charNode = (Node)character;
       Node armature = (Node)charNode.getChild("Armature");
       AnimComposer animComposer = armature.getControl(AnimComposer.class);
       animComposer.setCurrentAction("run");
3 Likes