www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Zemalax on October 16, 2011, 11:10:51 pm

Title: Animation problem
Post by: Zemalax 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
Title: Re: Animation problem
Post by: EgonOlsen 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.
Title: Re: Animation problem
Post by: Zemalax on October 16, 2011, 11:50:46 pm
And what format is well suited to animation?
Title: Re: Animation problem
Post by: EgonOlsen 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.
Title: Re: Animation problem
Post by: Zemalax 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?)
Title: Re: Animation problem
Post by: EgonOlsen 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.
Title: Re: Animation problem
Post by: Zemalax on October 17, 2011, 03:35:07 pm
Thank you very much)
Title: Re: Animation problem
Post by: AGP 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!).
Title: Re: Animation problem
Post by: EgonOlsen 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().
Title: Re: Animation problem
Post by: AGP on April 06, 2012, 06:37:10 pm
Switching the order crashes. Compile(true, true) didn't help.
Title: Re: Animation problem
Post by: AGP 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.
Title: Re: Animation problem
Post by: EgonOlsen on April 07, 2012, 09:04:54 am
Switching the order might cause an exception but not a "crash". Any log output?
Title: Re: Animation problem
Post by: AGP 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
Title: Re: Animation problem
Post by: EgonOlsen 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.
Title: Re: Animation problem
Post by: AGP on April 07, 2012, 09:24:24 am
But you didn't expect the crash, smarty-pants. I'll try and report back.
Title: Re: Animation problem
Post by: AGP on April 07, 2012, 09:34:00 am
Very odd result: now when the animation is supposed to change, the model blinks (as in ever-so-briefly disappears from the screen) but doesn't move. Note: with compile(true, true) called before calcBoundingBox() the model was dark (unlit) and seemed stuck on one of the keyframes. I've removed the explicit calls to compile().
Title: Re: Animation problem
Post by: EgonOlsen on April 07, 2012, 01:41:26 pm
Maybe your animation is screwed up somehow? Do the meshes you are using actually match? How does the log output looks now? And what do you mean by 'you didn't expected the crash'? It's not a crash. It's an exception that happens on purpose and it also tells you what's wrong... ???
Title: Re: Animation problem
Post by: AGP on April 07, 2012, 06:21:36 pm
It's a crash. The app crashes (or it did before we added calcBoundingBox()). And no, the animation is right, as again it's both the same code and the same models as the ones for the desktop version.
Title: Re: Animation problem
Post by: EgonOlsen on April 07, 2012, 08:38:09 pm
I guess it's pointless to argue about the semantic difference between a crash and an exception...and it doesn't solve the problem, so...i think i need a test case. Animations should work fine on Android and i've never seen a problem with them. I think it's something in the way you create the Animation, but i can't tell without a test case.
Title: Re: Animation problem
Post by: AGP on April 07, 2012, 08:43:15 pm
I will email one to you. Thanks a lot.
Title: Re: Animation problem
Post by: AGP on April 08, 2012, 12:24:51 am
I just sent it. I just noticed I forgot to include the hair model. Sorry about that. Just remove the reference to it. :- ) It doesn't really matter since it's not part of the animations.
Title: Re: Animation problem
Post by: EgonOlsen on April 09, 2012, 04:50:04 pm
There were/are a few problems...


I'll send my fixed version of the test case back to you...
Title: Re: Animation problem
Post by: AGP on April 09, 2012, 05:41:10 pm
Cool. Thanks a lot, pal.