Author Topic: animation  (Read 4708 times)

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
animation
« on: February 15, 2008, 09:15:52 am »
I'm just starting to look at animation.  I did a search and tried the two possibilities in Blender.  The md2 looks to be hopeless.  So I'll need to load 3ds key frames.  From what I read you load them and add them to the animation.  The part I don't quite understand is how you assign it time wise.  For instance, if I do a walk animation I might have a key at 1,5,10,15 or something.  In this case, it's evenly spaced, but other animations don't have evenly spaced key frames so how do I assign times to the key frames?
« Last Edit: February 15, 2008, 09:17:23 am by fireside »
click here->Fireside 7 Games<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: animation
« Reply #1 on: February 15, 2008, 11:06:57 am »
You either have to make sure that the animation's frames are evenly distributed or you have to adjust the speed yourself by increasing the index in Object3D.animation(<float>, <int>) at different rates depending on its value.

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: animation
« Reply #2 on: February 15, 2008, 05:21:10 pm »
O.K. thanks.  I'll have to just start playing around with it till I get some understanding.  I'm not quite clear on it yet.
click here->Fireside 7 Games<-

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: animation
« Reply #3 on: February 17, 2008, 01:01:05 am »
Well, I found some animation code and tried to work it into my helloworld app that's being converted to my game.  Right now, the mouse loads and I can move him right and left with the arrow keys.  I added the animation code as shown(I'm including the game loop in case it's throwing something off).  Basically, nothing at all happens.  It works just like it did before I added the animation code.  No errors are thrown.  I tested the walk models as the stand and they all loaded.  The stand model is still being displayed in the game.

Code: [Select]
    Mouse = loadModel("stand.3ds",1);           
  Mouse.translate(0, 15, 0);
Mouse.build();
  Mouse.createTriangleStrips();
TextureManager tm = TextureManager.getInstance();
    Texture tex=new Texture("fur.jpg");
    tm.addTexture("fur", tex);    
    tex = new Texture("red.jpg"); 
    tm.addTexture("red", tex);    
    Mouse.setTexture("fur");
world.addObject(Mouse);
  Animation walk = new Animation(4);
  walk.addKeyFrame(loadModel("walk1.3ds",1).getMesh());
  walk.addKeyFrame(loadModel("walk2.3ds",1).getMesh());
  walk.addKeyFrame(loadModel("walk3.3ds",1).getMesh());
  walk.addKeyFrame(loadModel("walk4.3ds",1).getMesh());
  Mouse.setAnimationSequence(walk);
  Mouse.animate(1);
  Mouse.rotateY(3.1416f/2f);
 
    camera=world.getCamera();
    camera.setPosition(0,5,-75);
    camera.lookAt(Mouse.getTransformedCenter());


    Object3D platform = loadModel("platform.3ds",1);
         
platform.translate(0, 20, 0);
platform.build();
    platform.setTexture("red");
world.addObject(platform);
}

private void loop() throws Exception {
fb = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
Canvas canvas=fb.enableGLCanvasRenderer();
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);
frame.add(canvas);

while (frame.isShowing()) {
poll();
if(left){
  if(goingRight){
  if(rotL < 16){
  Mouse.rotateY(3.1416f/16f); rotL++;}
  if(rotL>15){
  goingRight = false;rotL = 0;}
      }
      Mouse.translate(-.2f,0f,0f);  
}
if(right){
  if(!goingRight){
  if(rotR < 16){
  Mouse.rotateY(-3.1416f/16f); rotR++;}
  if(rotR>15){
  goingRight = true;rotR = 0;}
      }
      Mouse.translate(.2f,0f,0f);  
}

    camera.setPosition(Mouse.getTransformedCenter().x,5,-75);
    lightVector.set(Mouse.getTransformedCenter().x,-10.0f,-20.0f);
light.setPosition(lightVector);    
fb.clear(java.awt.Color.BLUE);
world.renderScene(fb);
world.draw(fb);
fb.update();
fb.displayGLOnly();
canvas.repaint();
Thread.sleep(10);
}
« Last Edit: February 17, 2008, 01:09:22 am by fireside »
click here->Fireside 7 Games<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: animation
« Reply #4 on: February 17, 2008, 11:05:35 am »
You have to iterate the index counter for animate and use it in the loop, i.e. do something like this in your loop:

Code: [Select]
....
ind+=0.1f;
if (ind>1f) {
   ind-=1f;
}
mouse.animate(ind);

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: animation
« Reply #5 on: February 17, 2008, 02:09:27 pm »
O.K.  That clears things up.  I was wondering just how all that could work.
click here->Fireside 7 Games<-

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: animation
« Reply #6 on: February 17, 2008, 04:01:02 pm »
I don't know if I missed this before, but I'm getting an error loading the animation files, now.  It's says "bounding box missing in this mesh".  I did the stand load exactly the same, but it doesn't give me an error for that, but when I load the walk meshes, it gives me that error.

edit: did a search and found it.  It needed a build.
« Last Edit: February 17, 2008, 05:06:03 pm by fireside »
click here->Fireside 7 Games<-

Offline majitri

  • byte
  • *
  • Posts: 17
    • View Profile
Re: animation
« Reply #7 on: February 22, 2008, 06:50:01 pm »
Hello, I too am starting with the animation, and I wonder how can I do so that it appears that walks, the animation is a 3D object, I have been looking for the forum and I am not quite sure how.
May I also sample code, or send me mail.
Thank you for everything.

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: animation
« Reply #8 on: February 22, 2008, 08:08:47 pm »
Well, I just went through this in blender.  You make your animation.  Then you save key frames of the animation.  Like, legs apart, lifting left leg, lifting right leg, other legs apart.  You save them as 3ds.  I have a character that is a mouse.  So this is the code I did for the animation.  First you need code that loads the model and turns it the right way and builds it:
Code: [Select]
private Object3D loadModel(String filename, float scale)
{
Object3D[] model = Loader.load3DS(filename, scale);

Object3D o3d = new Object3D(0);
 
Object3D temp = null;
     
  for (int i=0; i<model.length; i++)
{
temp=model[i];
temp.setCenter(SimpleVector.ORIGIN);
  temp.rotateX((float)-Math.PI);
  temp.rotateMesh();
  temp.setRotationMatrix(new Matrix());
  o3d=Object3D.mergeObjects(o3d, temp);
  o3d.build();
  }
return o3d;           
}


I have to build the model in the y up positon in blender for that to work.

Then I use this code to load the animation:
Code: [Select]
    Mouse = loadModel("data/stand.3ds",1); 
  Mouse.translate(0, -5, 0);
TextureManager tm = TextureManager.getInstance();
    Texture tex=new Texture("data/fur.jpg");
    tm.addTexture("fur", tex);    
    tex = new Texture("data/red.jpg"); 
    tm.addTexture("red", tex);    
    Mouse.setTexture("fur");
world.addObject(Mouse);
  Animation mouse = new Animation(10);
  mouse.createSubSequence("walk");
  mouse.addKeyFrame(loadModel("data/walk2.3ds",1).getMesh());
  mouse.addKeyFrame(loadModel("data/walk3.3ds",1).getMesh());
  mouse.addKeyFrame(loadModel("data/walk4.3ds",1).getMesh());
  mouse.addKeyFrame(loadModel("data/walk1.3ds",1).getMesh());
 
  mouse.createSubSequence("stand");
  mouse.addKeyFrame(loadModel("data/stand.3ds",1).getMesh());
  mouse.addKeyFrame(loadModel("data/stand2.3ds",1).getMesh());
 
  mouse.createSubSequence("jump");
  mouse.addKeyFrame(loadModel("data/stand.3ds",1).getMesh());
mouse.addKeyFrame(loadModel("data/jump.3ds",1).getMesh());
mouse.addKeyFrame(loadModel("data/jump2.3ds",1).getMesh());

  Mouse.setAnimationSequence(mouse);
  Mouse.rotateY(3.1416f/2f);
    Mouse.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
    Mouse.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);

Then you animate as was explained earlier in this thread.  The index starts with one so, in this case, walk is 1, stand is 2, jump is 3.
« Last Edit: February 22, 2008, 08:28:13 pm by fireside »
click here->Fireside 7 Games<-

Offline majitri

  • byte
  • *
  • Posts: 17
    • View Profile
Re: animation
« Reply #9 on: February 22, 2008, 09:02:27 pm »
Thank you, but I have a doubt in your code, walk2.3ds, walk3.3ds, etc., are different 3D images? Or are the same image, but such forward one leg in each mouse, so to be able to get the animation? If the same image for a different position (moving one leg in each 3ds), how do I get these images from my 3D?

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: animation
« Reply #10 on: February 22, 2008, 09:37:12 pm »
Yes, they are actually different models in different positions.  The way I do it in Blender is to make a model, put a skeleton in it, make an animation with key frames.  Than I go to the frame with each key, I turn the model to the y up position (I normally build z up), then I select the model and go to file export 3ds, and it exports the model in that key frame position.  I name it walk1.3ds, then go to the next key frame, same thing.  You don't want to go too high poly on that type of animation.  I kept the vertices to 400 on my model and it works good.
« Last Edit: February 22, 2008, 09:44:14 pm by fireside »
click here->Fireside 7 Games<-