Update Morph

Hi, there



I loaded a TriMesh array with all move of my character

follow de code:



morph[0] - walk

morph[1] - walk

morph[2] - walk



morph[3] - running

morph[4] - running

morph[5] - running



how can I do to press a key, like 'w' for instance, and the character change  walk move to run move?



I need to change  the move of my character in the main class? How I do that?





my code:






public class MorphPersonagens{
      
   public TriMesh morph[] = new TriMesh[6];
   public TriMesh aux = new TriMesh();
   public KeyframeController kc = new KeyframeController();
   public FileInputStream leJME[] = new FileInputStream[6];
   public FileInputStream leJMEAux;
   public Node recebeJME[] = new Node[6];
      
   public float f = -0.3f;
   public int posInicial = 0;
   public int posFinal = 6;
   
   public MorphPersonagens(){}
   
   public TriMesh[] personagem(){
      
      KeyframeController kc = new KeyframeController();
            
      try{
         for (int i = posInicial; i < posFinal; i++){
            leJME[i] = new FileInputStream("c:/projeto/personagens/lyan/obj/lyan"+i+".jme");
         }         
         //FileInputStream para carregar o JME base
         leJMEAux = new FileInputStream("c:/projeto/personagens/lyan/obj/lyan1.jme");
         //Usa o metodo loadBinaryFormat para carregar os arquivos .JME dentro do Node
         JmeBinaryReader carregaJME = new JmeBinaryReader();
                                    
         try{
            // Node base para o TriMesh
            Node recebeAux = (Node)carregaJME.loadBinaryFormat(leJMEAux);
            // "FOR" para colocar os .JME dentro da Node
            for (int i = 0; i < 6; i++){
               recebeJME[i] = (Node)carregaJME.loadBinaryFormat(leJME[i]);
            }
            for(int i = 0; i < 3; i++){
               morph[i] = (TriMesh)recebeJME[i].getChild(0);
               // indica a velocidade da morfagem                    
            }
            
         }
         catch(Exception e){}
      }
      catch(FileNotFoundException fnfe){}
      
      return morph;
   }
}




public class MorphController extends Controller{

   public TriMesh base = new TriMesh("base");;
   public TriMesh morph[];
   
   public float f = -0.3f;
   public int posInicial = 0;
   public int posFinal = 3;
   
   public KeyframeController kc = new KeyframeController();
   
   public MorphController(TriMesh morph[]){
      this.morph = morph;
   }
   
   public void update(float time){
            
      //Localidade no Mundo 3D
      base.setLocalScale(2);
      //Indica ao KeyFrameController qual Trimesh ser

Take a look at the source code for SimpleGame.  It registers keys for the camera and other things.  That should explain pretty well how to use the built-in keyboard and mouse events in jME.



darkfrog

it capture the key  I want, the problem is:



when I morph a character with all moves  for the main class and press the key it dont change to walk for run.



Hunter

Refer to SimpleGame as an example.  Take a look at the references to KeyBindingManager in initSystem().  Also, I assume you already realize this, but if you don't, you should not use SimpleGame for anything but initial testing.  Your actual game should be an extension of BaseGame or AbstractGame.  SimpleGame is just a class that allows you have basic controls to fly around and look at the scene, not intended to be the basis for building a game.



darkfrog

i think we

I do understand, but if you reference the SimpleGame to figure out how it does key binding you can use that to write your own key binding that does your animation instead of moving forward.  I'm assuming you already know how to change the animation sequence, you just need to figure out a way to trigger it on a keypress…that's what I'm pointing you to.



darkfrog

That's exactly what I want to know! How to change the animation sequence during runtime?



sorry, I

Does anybody Know how to do that?





I already told you…look at SimpleGame at how they configure key bindings and that will tell you what you want to know.



darkfrog

or download starter.pdf on the homepage

there is also some Sample for keybindings



what u want is quite simple



3 states.

stand, walk, run

1 options:

make some value to differ between walk and run, this also would fit to boolean

make your keybindings on w change the state of this value

make your own MoveForwardAction to differ the different possibilities by simply doubling the input for running actions.



darkfrog already told u to look at simple game class.

there are keybindings i think what u want to know is how to make a key acting only once.

that was a trial also for me but solution is quite simple



u can vary it in ur simpleUpdate method:



if(KeyBindingManager.getKeyBindingManager().isValidCommand("turnLeft",false)){



setting this to true would make it turn by default turning as long as u press the left key

but setting this to false makes it a one klick action.

it is unimportant how long u press this key as its action is only forced onced



hope i could be of help without making u tired :slight_smile:

I think his question is more along the lines of how to start and stop an animation controller.  You refer to Morph alot, do you have a controller already or have you simply loaded several models representing frames of animation and you want to know how to make them flow together as an animation?

renanse,



you got very close to what I want to do…I can already capture the key and the character already moves to diferent positions along the scenario. What

morph = new TriMsh[6]

base = new TriMesh("Base");



int posInicial = 0;

int posFinal = 3;



for(int i = posInicial; i < posFinal; i++){

f += 0.3f;

kc.setKeyframe(f, morph);

}



kc.setRepeatType(Controller.RT_CYCLE);

base.addController(kc);



When I press the key "w", for instance…I change the "posInicial" to 3 and "posFinal" to 6. Where the variables "posInicial" and "posFinal", corresponds to the array interval that contains the TriMeshs of the walking animation. I must send the "base" object that contains the new animation to "rootNode" in the main class…but I have a problem, when I do that (rootNode.setChild(0, base)), a "NullPointerExceptionn" occurs…Thats is my problem…