Author Topic: Animate character  (Read 3270 times)

Offline whis

  • byte
  • *
  • Posts: 7
    • View Profile
Animate character
« on: March 06, 2007, 11:22:25 pm »
Hello,

I have a problem with the animation in jPCT:

I loaded a file .3ds in an 3dObject (body) and I added it into the world.
Then i loaded 6 file .3ds in 6 3dObject (marche1, marche2,....): they are my 3d sprites.

I also created a new animation with the 3d sprites:

Code: [Select]
        theWorld.addObject(body);
animation = new Animation(6);
int marcheseq = animation.createSubSequence("marche");
body.build();
marche1.build();
marche2.build();
marche3.build();
marche4.build();
marche5.build();
marche6.build();
animation.addKeyFrame(marche1.getMesh());
animation.addKeyFrame(marche2.getMesh());
animation.addKeyFrame(marche3.getMesh());
animation.addKeyFrame(marche4.getMesh());
animation.addKeyFrame(marche5.getMesh());
animation.addKeyFrame(marche6.getMesh());

body.setAnimationSequence(animation);
 
Loader.setVertexOptimization(false);

To finish I run my animation:

Code: [Select]
while (!exit)
{

buffer.clear();
theWorld.renderScene(buffer);
theWorld.draw(buffer);
buffer.update();
buffer.display(frameGraphics);
body.animate(x, marcheseq);
if (x>6) {
anim=0;
}
else
{
anim+=1;
}
}
}

My character appears on the screen (body) but the animation don't start(I have no errors), why?
Someone can help me?

Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Animate character
« Reply #1 on: March 06, 2007, 11:50:59 pm »
There seems to be a mixture of "x" and "anim" in your code. Anyway, the animation's index is a float ranging from 0 to 1. In your code, you seem to increment it in steps of 1, which will lead to no animation at all. Try to increase it by 0.1f or something and see if that helps.
Btw: When creating animations out of 3ds files, it makes sense to set http://www.jpct.net/doc/com/threed/jpct/Loader.html#setVertexOptimization(boolean) to false before loading the model.
« Last Edit: March 06, 2007, 11:53:03 pm by EgonOlsen »

Offline whis

  • byte
  • *
  • Posts: 7
    • View Profile
Re: Animate character
« Reply #2 on: March 07, 2007, 11:16:03 am »
I'm sorry for the mix of "anim" and "x".
T have try to set this variable at 0 then incremente it by 0.1.
I have also set "setVertexOptimization" to false before loading the 3ds files.

I doesn't work.

The 3d object that emcapsulate the animation have to be empty or not?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Animate character
« Reply #3 on: March 07, 2007, 11:20:33 am »
The 3d object that emcapsulate the animation have to be empty or not?
No. It has to be initialized with a mesh of the same kind. For example the first mesh in the series. If it isn't, you should get a warning about it in the console.

Offline whis

  • byte
  • *
  • Posts: 7
    • View Profile
Re: Animate character
« Reply #4 on: March 07, 2007, 11:25:31 am »
Ok thanks, and when i create a keyframe does a message appears in the console (becaus i Have no messages fot it)?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Animate character
« Reply #5 on: March 07, 2007, 04:59:46 pm »
...and when i create a keyframe does a message appears in the console (becaus i Have no messages fot it)?
No, it doesn't. That's an operation like any other...no extra message for this one.