Main Menu

animation

Started by fireside, February 15, 2008, 09:15:52 AM

Previous topic - Next topic

fireside

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?
click here->Fireside 7 Games<-

EgonOlsen

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.

fireside

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<-

fireside

#3
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.


    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);
}
click here->Fireside 7 Games<-

EgonOlsen

You have to iterate the index counter for animate and use it in the loop, i.e. do something like this in your loop:


....
ind+=0.1f;
if (ind>1f) {
   ind-=1f;
}
mouse.animate(ind);

fireside

O.K.  That clears things up.  I was wondering just how all that could work.
click here->Fireside 7 Games<-

fireside

#6
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.
click here->Fireside 7 Games<-

majitri

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.

fireside

#8
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:

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:
    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.
click here->Fireside 7 Games<-

majitri

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?

fireside

#10
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.
click here->Fireside 7 Games<-