Author Topic: Animation problem  (Read 7204 times)

Offline Zemalax

  • byte
  • *
  • Posts: 10
    • View Profile
Animation problem
« on: October 16, 2011, 11:10:51 pm »
Hello!
I have a problem. There is an animated object (spinning cube) in the format .3 DS, I'm trying to run the animation, but it does not move.

The place where I load the model:
Code: [Select]
Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.art)),128, 128));

TextureManager.getInstance().addTexture("texture", texture);

Resources res = getResources();

test = Object3D.mergeAll(Loader.load3DS(res.openRawResource(R.raw.animcube),1.0f));

test.setTexture("texture");

test.calcNormals();
test.build();
world.addObject(test);



The place where I animate:

Code: [Select]
public void doAnim() {
{
ind += 0.02f;
if (ind > 1f) {
ind -= 1f;
}
}
test.animate(ind);
}

The place where I run animate:

Code: [Select]
public void onDrawFrame(GL10 gl) {
doAnim();
...
(ind - float)
It's just an animated model, I can not get it to perform motion.
Help pls

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Animation problem
« Reply #1 on: October 16, 2011, 11:48:09 pm »
Animated in this case means that it's animated in 3ds? If that is the case...jPCT-AE doesn't load this kind of animations. I'm not even sure that the 3ds format actually supports them. If you want to rotate a cube, you have to do it in code. Scrap that animation code and replace it with a test.rotateY(0.01f); instead.

Offline Zemalax

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Animation problem
« Reply #2 on: October 16, 2011, 11:50:46 pm »
And what format is well suited to animation?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Animation problem
« Reply #3 on: October 16, 2011, 11:56:00 pm »
jPCT supports keyframe animation by default and skeletal animations when adding the Bones library to it (see the Bones forum section for more information). A rotation should never be done as a keyframe animation nor as a skeletal one. It should be done by applying a rotation to the object. For keyframe animations, the easiest (but limited) way is to export to md2 format. Another option is to load the keyframes as separate 3ds or obj files...you should be able to find some information about that in the forum.

Edit: The most powerful and flexible way is to use Bones though.

Offline Zemalax

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Animation problem
« Reply #4 on: October 17, 2011, 01:03:14 am »
And if I make a few frames of animation (keyframes), then animate the transition from one frame to another will be smooth? (That is, the object will not jump?)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Animation problem
« Reply #5 on: October 17, 2011, 07:22:44 am »
Yes, it will be interpolated. As long as your keyframes aren't very different, this should look fine.

Offline Zemalax

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Animation problem
« Reply #6 on: October 17, 2011, 03:35:07 pm »
Thank you very much)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Animation problem
« Reply #7 on: April 06, 2012, 09:26:13 am »
This hasn't been working for me on Android (but works, as it should, on the desktop):

Code: [Select]
lal3d = Object3D.mergeAll(Loader.loadOBJ(resources.openRawResource(R.raw.head), resources.openRawResource(R.raw.headmtl), 1.0f));
Object3D openMouth = Object3D.mergeAll(Loader.loadOBJ(resources.openRawResource(R.raw.mouthopen), null, 1.0f));
Object3D blinks = Object3D.mergeAll(Loader.loadOBJ(resources.openRawResource(R.raw.blink), null, 1.0f));
Object3D smiles = Object3D.mergeAll(Loader.loadOBJ(resources.openRawResource(R.raw.smile), null, 1.0f));
lal3d.build();
openMouth.build();
blinks.build();
smiles.build();
Animation animation = new Animation(9);
animation.createSubSequence("Talks");
animation.addKeyFrame(lal3d.getMesh().cloneMesh(false));
animation.addKeyFrame(openMouth.getMesh());
animation.addKeyFrame(lal3d.getMesh().cloneMesh(false));
animation.createSubSequence("Blinks");
animation.addKeyFrame(lal3d.getMesh().cloneMesh(false));
animation.addKeyFrame(blinks.getMesh());
animation.addKeyFrame(lal3d.getMesh().cloneMesh(false));
animation.createSubSequence("Smiles");
animation.addKeyFrame(lal3d.getMesh().cloneMesh(false));
animation.addKeyFrame(smiles.getMesh());
animation.addKeyFrame(lal3d.getMesh().cloneMesh(false));
animation.setInterpolationMethod(Animation.LINEAR);
lal3d.setAnimationSequence(animation);

The result is that I can call, say, animate(.3f, 2), check that the call was made, but the model won't move. It's worth noting that it's the same OBJ model that works on the PC (meaning the keyframes are not all the same!).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Animation problem
« Reply #8 on: April 06, 2012, 10:17:07 am »
If you call build() before setting the animation, jPCT-AE will use static compilation for this object. Either switch order or add an explicit call to compile(true, true) before calling build().

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Animation problem
« Reply #9 on: April 06, 2012, 06:37:10 pm »
Switching the order crashes. Compile(true, true) didn't help.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Animation problem
« Reply #10 on: April 06, 2012, 10:42:10 pm »
Also, since I couldn't not call build before setAnimation(Animation), I tried calling it both before AND after it. Didn't help.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Animation problem
« Reply #11 on: April 07, 2012, 09:04:54 am »
Switching the order might cause an exception but not a "crash". Any log output?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Animation problem
« Reply #12 on: April 07, 2012, 09:16:33 am »
It caused a crash. A FatalException:

04-07 04:12:03.540: E/AndroidRuntime(6153): FATAL EXCEPTION: GLThread 489
04-07 04:12:03.540: E/AndroidRuntime(6153): java.lang.RuntimeException: [ 1333771923539 ] - ERROR: Bounding box missing in this mesh!
04-07 04:12:03.540: E/AndroidRuntime(6153):    at com.threed.jpct.Logger.log(Logger.java:189)
04-07 04:12:03.540: E/AndroidRuntime(6153):    at com.threed.jpct.Animation.addKeyFrame(Animation.java:271)
04-07 04:12:03.540: E/AndroidRuntime(6153):    at co.ratto.Lal.LalView$MyRenderer.onSurfaceChanged(LalView.java:181)
04-07 04:12:03.540: E/AndroidRuntime(6153):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1455)
04-07 04:12:03.540: E/AndroidRuntime(6153):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
04-07 04:12:30.170: W/SurfaceView(6153): CHECK surface infomation creating=false formatChanged=false sizeChanged=fals

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Animation problem
« Reply #13 on: April 07, 2012, 09:22:38 am »
Just what i expected...add a calcBoundingBox()-call instead of the build-call that's before the setAnimation and the build()-call afterwards.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Animation problem
« Reply #14 on: April 07, 2012, 09:24:24 am »
But you didn't expect the crash, smarty-pants. I'll try and report back.