Animation problem

Started by Zemalax, October 16, 2011, 11:10:51 PM

Previous topic - Next topic

Zemalax

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:

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:


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


The place where I run animate:


public void onDrawFrame(GL10 gl) {
doAnim();
...

(ind - float)
It's just an animated model, I can not get it to perform motion.
Help pls

EgonOlsen

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.

Zemalax

And what format is well suited to animation?

EgonOlsen

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.

Zemalax

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

EgonOlsen

Yes, it will be interpolated. As long as your keyframes aren't very different, this should look fine.

Zemalax


AGP

This hasn't been working for me on Android (but works, as it should, on the desktop):


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!).

EgonOlsen

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().

AGP

Switching the order crashes. Compile(true, true) didn't help.

AGP

Also, since I couldn't not call build before setAnimation(Animation), I tried calling it both before AND after it. Didn't help.

EgonOlsen

Switching the order might cause an exception but not a "crash". Any log output?

AGP

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

EgonOlsen

Just what i expected...add a calcBoundingBox()-call instead of the build-call that's before the setAnimation and the build()-call afterwards.

AGP

But you didn't expect the crash, smarty-pants. I'll try and report back.