Can't run AnimChannel and AnimControl

Hi to all monkeys :slight_smile: i’ve begun develop with jme a few days ago and i’m stuck with my first animation test.
So, what i’ve made?i made a model with blender, then i have imported it and converted in a *.j3o file
In blender also i have made 2 action , walk and idling. i set the animation on walk in the code. I run the code but it give me this error-log:

[java]
apr 02, 2013 4:35:02 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.0.0 Beta
apr 02, 2013 4:35:02 PM com.jme3.system.Natives extractNativeLibs
INFO: Extraction Directory: C:\Users\Administrator\Documents\JMONKEY_PROJECT\Animazione
apr 02, 2013 4:35:03 PM com.jme3.system.lwjgl.LwjglAbstractDisplay run
INFO: Using LWJGL 2.8.4
apr 02, 2013 4:35:03 PM com.jme3.system.lwjgl.LwjglDisplay createContext
INFO: Selected display mode: 640 x 480 x 0 @0Hz
apr 02, 2013 4:35:04 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Adapter: nvd3dum
apr 02, 2013 4:35:04 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Driver Version: 7.15.11.7948
apr 02, 2013 4:35:04 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Vendor: NVIDIA Corporation
apr 02, 2013 4:35:04 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: OpenGL Version: 2.1.2
apr 02, 2013 4:35:04 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Renderer: GeForce Go 7300/PCI/SSE2
apr 02, 2013 4:35:04 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: GLSL Ver: 1.20 NVIDIA via Cg compiler
apr 02, 2013 4:35:04 PM com.jme3.system.lwjgl.LwjglTimer
INFO: Timer resolution: 1.000 ticks per second
apr 02, 2013 4:35:04 PM com.jme3.renderer.lwjgl.LwjglRenderer initialize
INFO: Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, OpenGL20, OpenGL21, ARBprogram, GLSL100, GLSL110, GLSL120, VertexTextureFetch, FloatTexture, FloatColorBuffer, NonPowerOfTwoTextures, Multisample]
apr 02, 2013 4:35:04 PM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
apr 02, 2013 4:35:04 PM com.jme3.asset.DesktopAssetManager
INFO: DesktopAssetManager created.
apr 02, 2013 4:35:04 PM com.jme3.renderer.Camera
INFO: Camera created (W: 640, H: 480)
apr 02, 2013 4:35:04 PM com.jme3.renderer.Camera
INFO: Camera created (W: 640, H: 480)
apr 02, 2013 4:35:04 PM com.jme3.input.lwjgl.LwjglMouseInput initialize
INFO: Mouse created.
apr 02, 2013 4:35:04 PM com.jme3.input.lwjgl.LwjglKeyInput initialize
INFO: Keyboard created.
apr 02, 2013 4:35:05 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: AudioRenderer supports 64 channels
apr 02, 2013 4:35:05 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio effect extension version: 1.0
apr 02, 2013 4:35:05 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio max auxilary sends: 4
apr 02, 2013 4:35:05 PM com.jme3.material.MaterialDef
INFO: Loaded material definition: Unshaded
apr 02, 2013 4:35:05 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
apr 02, 2013 4:35:05 PM com.jme3.material.MaterialDef
INFO: Loaded material definition: Phong Lighting
apr 02, 2013 4:35:05 PM com.jme3.scene.Node attachChild
INFO: Child (Models/omino_anim_2/omino_anim_2.blend) attached to this node (Root Node)
apr 02, 2013 4:35:05 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:28)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:722)

apr 02, 2013 4:35:05 PM com.jme3.renderer.lwjgl.LwjglRenderer cleanup
INFO: Deleting objects and invalidating state
apr 02, 2013 4:35:05 PM com.jme3.input.lwjgl.LwjglMouseInput destroy
INFO: Mouse destroyed.
apr 02, 2013 4:35:05 PM com.jme3.input.lwjgl.LwjglKeyInput destroy
INFO: Keyboard destroyed.
apr 02, 2013 4:35:05 PM com.jme3.system.lwjgl.LwjglAbstractDisplay deinitInThread
INFO: Display destroyed.
[/java]

and this is the code:

[java]
package mygame;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

public class Main extends SimpleApplication {

private AnimChannel channel;
private AnimControl control;

public static void main(String[] args) {
	Main app = new Main();
    app.start();
}

@Override
public void simpleInitApp() {
    Spatial model = assetManager.loadModel("Models/omino/omino_anim_2.j3o");
    rootNode.attachChild(model);
    model.center();
    control = model.getControl(AnimControl.class);
    channel = control.createChannel();
    channel.setAnim("walk");
}

public void setUpLight(){
    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));

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);
}

private Spatial findNode(Node rootNode, String name) {
    if (name.equals(rootNode.getName())) {
        return rootNode;
    }
    return rootNode.getChild(name);
}

}
[/java]

The anim control is probably attached to an object inside the node loaded by loadModel.

Look at the layout inside the j3o file using the scene explorer window and you can see what you need to do.

You can use something like:

[java]
private static Node findAnimNode(Node node) {
AnimControl l_animControl;

    l_animControl = node.getControl(AnimControl.class);
    if (l_animControl != null) {
        if (!l_animControl.getAnimationNames().isEmpty()) {
            Animation l_anim = l_animControl.getAnim(l_animControl.getAnimationNames().iterator().next());
            if (l_anim != null && l_anim.getTracks().length > 0 && l_anim.getTracks()[0] instanceof BoneTrack) {
                return node;
            }
        }
    }

    for (Spatial l_child : node.getChildren()) {
        Node l_ret = findAnimNode((Node) l_child);
        if (l_ret != null) {
            return l_ret;
        }
    }

    return null;
}

[/java]

To find the first node with an valid (in this case bonetrack) animation.