Trigger an Animation - Blender [Solved]

Hi everyone, this is my first game so I’m new in this. I’m having a big problem since days, and I’m not sure if It’s a problem in blender or in jmonkey. I made in blender, the skeleton and the animation of this mesh:

Mario.blend

Note: I did the animation called “Derecha” that turns his head to the right.

My game runs well, until I trigger the animation with his corresponding key, and throw the following error:

jul 08, 2016 10:55:47 PM java.util.prefs.WindowsPreferences <init>
Advertencia: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
jul 08, 2016 10:55:48 PM com.jme3.system.JmeDesktopSystem initialize
Información: Running on jMonkeyEngine 3.0.10
jul 08, 2016 10:55:48 PM com.jme3.system.Natives extractNativeLibs
Información: Extraction Directory: C:\Users\Slaush\Documents\jmonkey\DONT LOOK
jul 08, 2016 10:55:49 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
Información: Lwjgl 2.9.0 context running on thread LWJGL Renderer Thread
jul 08, 2016 10:55:49 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
Información: Adapter: igdumd64
jul 08, 2016 10:55:49 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
Información: Driver Version: null
jul 08, 2016 10:55:49 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
Información: Vendor: Intel
jul 08, 2016 10:55:49 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
Información: OpenGL Version: 3.1.0 - Build 9.17.10.4229
jul 08, 2016 10:55:49 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
Información: Renderer: Intel(R) HD Graphics 3000
jul 08, 2016 10:55:49 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
Información: GLSL Ver: 1.40 - Intel Build 9.17.10.4229
jul 08, 2016 10:55:49 PM com.jme3.asset.AssetConfig loadText
Advertencia: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
jul 08, 2016 10:55:49 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
Información: Audio Device: OpenAL Soft
jul 08, 2016 10:55:49 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
Información: Audio Vendor: OpenAL Community
jul 08, 2016 10:55:49 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
Información: Audio Renderer: OpenAL Soft
jul 08, 2016 10:55:49 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
Información: Audio Version: 1.1 ALSOFT 1.15.1
jul 08, 2016 10:55:49 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
Información: AudioRenderer supports 64 channels
jul 08, 2016 10:55:49 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
Información: Audio effect extension version: 1.0
jul 08, 2016 10:55:49 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
Información: Audio max auxilary sends: 4
jul 08, 2016 10:55:51 PM com.jme3.app.Application handleError
Grave: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.ArrayIndexOutOfBoundsException: -4
	at com.jme3.animation.CompactQuaternionArray.deserialize(CompactQuaternionArray.java:97)
	at com.jme3.animation.CompactQuaternionArray.deserialize(CompactQuaternionArray.java:43)
	at com.jme3.animation.CompactArray.get(CompactArray.java:132)
	at com.jme3.animation.BoneTrack.setTime(BoneTrack.java:231)
	at com.jme3.animation.Animation.setTime(Animation.java:110)
	at com.jme3.animation.AnimChannel.update(AnimChannel.java:403)
	at com.jme3.animation.AnimControl.controlUpdate(AnimControl.java:332)
	at com.jme3.scene.control.AbstractControl.update(AbstractControl.java:112)
	at com.jme3.scene.Spatial.runControlUpdate(Spatial.java:570)
	at com.jme3.scene.Spatial.updateLogicalState(Spatial.java:688)
	at com.jme3.scene.Node.updateLogicalState(Node.java:145)
	at com.jme3.scene.Node.updateLogicalState(Node.java:152)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:244)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
	at java.lang.Thread.run(Thread.java:744)

My code is this:

public class Main extends SimpleApplication {

private AnimControl control;
private AnimChannel channel;
private Node Mario;
private static final String ANI_DERECHA = "Derecha";
private final static Trigger TRIGGER_DERECHA = new KeyTrigger(KeyInput.KEY_F);
private final static String MAPPING_DERECHA = "Girar derecha cabeza";

public static void main(String[] args) {
   
    AppSettings settings = new AppSettings(false);
    settings.setTitle("Don't Look");//titulo de la ventana
    settings.setSamples(8);//calidad, diferencia op, 2,4,8,16,32
    settings.setSettingsDialogImage("Interface/Mario_Party_logo.png");//img del cuadro inicial de op
   
    Main app = new Main();
   
   app.setSettings(settings); // apply settings to app
    app.start();
}

@Override
public void simpleInitApp() {
    
    
    setDisplayFps(false);
    setDisplayStatView(false);
    
    inputManager.addMapping(MAPPING_DERECHA, TRIGGER_DERECHA);
    inputManager.addListener(actionListener,new String[]{MAPPING_DERECHA});
    
    viewPort.setBackgroundColor(ColorRGBA.Blue);
    Mario = (Node) assetManager.loadModel("Models/Mario/Mario.mesh.j3o");
   
    Vector3f v = new Vector3f(0.0f , -160.0f , -200.0f);
    Mario.setLocalTranslation(v);

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection((new Vector3f(0.0f, -100.0f, 0.0f)));
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);
    DirectionalLight sun1 = new DirectionalLight();
    sun1.setDirection((new Vector3f(-20.0f, -100.0f, -20.0f)));
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun1);
    DirectionalLight sun2 = new DirectionalLight();
    sun2.setDirection((new Vector3f(0.0f, -200.0f, -350.0f)));
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun2);
    flyCam.setMoveSpeed(60f);
    
    rootNode.attachChild(Mario); 
  
    control = Mario.getControl(AnimControl.class); // inicializa anim
    channel = control.createChannel();
        
}

private ActionListener actionListener = new ActionListener() {
 public void onAction(String name, boolean isPressed, float tpf)
 {
        if (name.equals(MAPPING_DERECHA) && !isPressed) 
       {
         channel.setAnim(ANI_DERECHA);       
       }  
 }

};

This is all, very short actually, but one of my doubts are: Did I save the animation wrong? Did I miss something? why the “Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]”? please help me, I’m about to die :disappointed:

PD: Sorry my possible bad english, It isn’t my native language :sweat_smile:

Hi @Jessele
This is a working screenshot of your model animation in JME :

You need to bake your animation in blender.
Select Rig then go to this menu Object → Animation → Backe Action
https://hub.jmonkeyengine.org/uploads/default/original/2X/6/6020a7b8012a569c61cc1fb21432065062ff618e.png

please watch this tutorial :

2 Likes

Hey @Ali_RS REALLY thank you for your video and for take your time to answering :blush: , I watched your video and was really helpful, I didn’t know the basic steps to do when you import a mesh that was already made (That’s why the mesh looked like that, without eyes, and the scale and all that stuff), I baked the animation like you did (I had no idea I have to do that), but when I run the project, just say “Cannot find animation named: ‘ActionRight’”. I tried everything, and I repeated the steps many times but nothing…

Here’s the whole project (folder): Don’tLook.rar

My new Mario with baked animation: MarioBaked.blender

Sorry being so insistent :pensive: I reallly have no idea what to do. Thanks for reading

You’re Welcome my friend :slight_smile:
[There are also video Part1,3,4 which might be helpful ]

Ah See. Please try following :

It is because Ogre exporter only converts animations from NLA strip.
Please let me know if it worked or not.

Btw : JME 3.1 has better support for blender model importing.

Hey, finally, yesterday I did the presentation of my game and I was so busy finishing it, that’s why I am answering right now, everything was a succes thanks for your answer and for your useful videos :grinning:

1 Like

You’re welcome.
Glad that your problem is solved.:grinning: