Getlocation at the end of animation

Hi,

I made an Animation, the character will fly from A to B and export it as Ogre to jme (3)

when I play the animation it will fly from A to B, but at the end of Animation it will teleport back to A.

are there any way to made the character setlocation at B at the end of Animation? or any way to get the location of B



I tried something in  onAnimCycleDone , but it didnt work out for me

Depends on how you animated the model, you would have a root bone that contains the animation that shifts the character from A to B. In that case, you can find that bone using AnimControl.getBone(String) and track its position via Bone.getModelSpacePosition(). You can then set the character's position to that on your onAnimCycleDone callback.

Hi I tried this

@Override
public void onAnimCycleDone(AnimControl control, AnimChannel channel,String animName) {
   p1.setLocalTranslation(animControl1.getSkeleton().getBone("head").getModelSpacePosition());
}



but it didnt work.There was though some position changing.
does it have to be a root bone or it doesnt matter? I just randomly chose the head bone, because the character flies, and head moves farthest.



The root bone in a rig is the first parent of the bone tree (hence the root).



Usually, it allow to move the entire model without deforming it.

Look here search root bone it's pretty well explained.

http://wiki.blender.org/index.php/Doc:Tutorials/Animation/Armatures/Flying_Bird/1:Building_the_Rig



hope that helps

@Nehon

I have 2 roots or may be more

I can make all of them children of the new root Bone though.

But I wonder if any Bone will work, or it only works with root bone (and any root bone or only with the boss root bone  }:-@)



:?



Ps Blender 2.53 is out ^^

xieu90 said:

I can make all of them children of the new root Bone though.

Yep that is a good practice.

xieu90 said:

But I wonder if any Bone will work, or it only works with root bone (and any root bone or only with the boss root bone  }:-@)

:?

Well in fact it must be a bone that can move all the other ones of the rig. As long as child bones copy the translation of their parent, the "boss root bone" is a good candidate.  :D

xieu90 said:

Ps Blender 2.53 is out ^^

o/ gonna try that out!

Hi

I tried something and it didnt work ^^

  • at the end of animation the mesh should have a new location (the end position of the animation)
  • the right key work, but after animation it wont work anymore (dont know why, may be because of dontloop ?)



    ModelSpacePosition is actually replacement of WorldLocation, there might be a new improvement there, but I dont know what. anyway, I feel like the Bone will always be somewhere at the middle of scrren and doesnt move along with mesh

    This time I made a cube in Blender and only 1 bone. So 1 bone 1 mesh like Don Quixote 1 Spear 1 Horse against something in Holland ^^

    and sure that only bone must be a rootBone or boss rootBone

    I might upload the blender file if anyone need it (to operate the problem)

    here is the code and the ogre xml



import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.animation.Skeleton;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.ui.Picture;


public class main extends SimpleApplication implements AnimEventListener{
   /****************************player1******************************/
   public static Spatial p1;
   
   
   public static AnimControl animControl1;
   public static AnimChannel animChannel1;
   public static Skeleton skeleton1;

   public static ActionListener p1pl,p1pr,p1kl,p1kr,p1j,p1l,p1def,p1speed,p1sl,p1sr,p1r,p1d;
   
   
   @Override// TODO SimpleInit
   public void simpleInitApp() {
      flyCam.setEnabled(false);
      /*******************add Light*********************/
      DirectionalLight sun = new DirectionalLight();
       sun.setDirection(new Vector3f(-10f, -70f, -10).normalizeLocal());
       rootNode.addLight(sun);
       
       /*******************add Player***********************/
       p1=assetManager.loadModel("model/Cube.mesh.xml");
       
       
       animControl1=(AnimControl) p1.getControl(0);
      animChannel1=animControl1.createChannel();
      skeleton1=animControl1.getSkeleton();
      animControl1.addListener(this);
       initKeys();
       rootNode.attachChild(p1);
       cam.setLocation(new Vector3f(0,0,50));
       
   }

   @Override// TODO AnimChange
   public void onAnimChange(AnimControl control, AnimChannel channel,String animName) {
      
   }

   @Override// TODO AnimDone
   public void onAnimCycleDone(AnimControl control, AnimChannel channel,String animName) {
      p1.setLocalTranslation(skeleton1.getBone("Bone").getModelSpacePosition());    //the problem might be somewhere here
   }   
   public static void main(String[] args) {
      main app= new main();      app.setShowSettings(false);      app.start();
   }
   
   public void initKeys(){
      //*************************init keys for player 1******************************/
      inputManager.addMapping("left",new KeyTrigger(KeyInput.KEY_LEFT));
      inputManager.addMapping("right",new KeyTrigger(KeyInput.KEY_RIGHT));
      
         p1pl=new ActionListener(){
         public void onAction(String name, boolean keyPressed, float tpf) {
            if(name.equals("left")){
               animChannel1.setAnim("Action");
               animChannel1.setLoopMode(LoopMode.DontLoop);
            }
            if(name.equals("right")){
               p1.setLocalTranslation(p1.getLocalTranslation().add(-1,0,0));
            }
         }};
         inputManager.addListener(p1pl, new String[]{"left","right"});
   }
}