onAnimCycleDone doesnt work properly

hi i wanted to create a simple program that plays all model animations.

the problem is onAnimCycleDone doesnt notify me when “stand” animation is finished.



[java]package nooblike;



import com.jme3.animation.AnimChannel;

import com.jme3.animation.AnimControl;

import com.jme3.animation.AnimEventListener;

import com.jme3.app.SimpleApplication;

import com.jme3.light.DirectionalLight;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Spatial;

import java.util.Iterator;



public class BeginnerTest07_PlayAllAnimation extends SimpleApplication implements AnimEventListener

{

public static void main(String[] args)

{

BeginnerTest07_PlayAllAnimation app = new BeginnerTest07_PlayAllAnimation();

app.start();

}



private AnimControl control;

private AnimChannel channel;

private Spatial player;

Iterator<String> animations ;



@Override

public void simpleInitApp()

{

player = assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);

rootNode.attachChild(player);



control = player.getControl(AnimControl.class);

control.addListener(this);

channel = control.createChannel();

for (String anim : control.getAnimationNames()) { System.out.println(anim); }



playNextAnimation();

//channel.setLoopMode( LoopMode.Cycle );



/** Must add a light to make the lit object visible! */

DirectionalLight sun = new DirectionalLight();

sun.setDirection(new Vector3f(1, 0, -2).normalizeLocal());

sun.setColor(ColorRGBA.White);

rootNode.addLight(sun);

}



public void playNextAnimation()

{

System.out.println("


");
System.out.println("play animation start");
if (animations != null && animations.hasNext())
{
String animationName = animations.next();
System.out.println("Playing "+animationName);
channel.setAnim(animationName);
}
else
{
System.out.println("iterator");
animations = control.getAnimationNames().iterator();
String animationName = animations.next();
System.out.println("Playing "+animationName);
channel.setAnim(animationName);
}
System.out.println("play next animation done");
}

public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName)
{
System.out.println("AnimCycleDone");
playNextAnimation();
}

public void onAnimChange(AnimControl control, AnimChannel channel, String animName)
{
System.out.println("AnimChange : "+animName);
}
}[/java]

how can i fix it ?

I checked the length of stand animation

and I think its length is 0 —> you wont get notify

with my model + blender I always made the stand animation start at 1 and end at 2 frame and it solved the problem, I got the notify

and in this case I think it is the same





AnimCycleDone


play animation start
Playing Walk
AnimChange : Walk
channel.getAnimMaxTime(); 1.24 //the length of walk animation
play next animation done
AnimCycleDone
channel.getAnimMaxTime(); 0.0 //I think this is the length of stand animation
play animation start
Playing stand
AnimChange : stand
play next animation done

i see, so i have to find out if an animation has 0 length to solve it.

Its actually a feature and not a bug … Think about it. If the length is 0 then the callback would be called every frame, which is probably not what you want.