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
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.
And what format is well suited to animation?
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.
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?)
Yes, it will be interpolated. As long as your keyframes aren't very different, this should look fine.
Thank you very much)
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!).
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().
Switching the order crashes. Compile(true, true) didn't help.
Also, since I couldn't not call build before setAnimation(Animation), I tried calling it both before AND after it. Didn't help.
Switching the order might cause an exception but not a "crash". Any log output?
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
Just what i expected...add a calcBoundingBox()-call instead of the build-call that's before the setAnimation and the build()-call afterwards.
But you didn't expect the crash, smarty-pants. I'll try and report back.
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().
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... ???
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.
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.
I will email one to you. Thanks a lot.
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.
There were/are a few problems...
- Vertex count of the head and the head smiling don't match. This might not result in an obvious problem, but it's not correct either. It should be fixed if possible.
- You are animating the head in worker thread, which is a bad idea. jPCT-AE (just like jPCT) isn't thread safe. Ignoring this is asking for trouble. In your test case, i simply fixed it by synchronizing rendering and animations to lal3d, but that's just a hack and nothing you really want to do.
- The meshes used for the animations had no normales calculated. You should add a call to Object3D.calcNormals() just like you did for Object3D.calcBoundingBox().
- If you do the former, there was a bug in jPCT-AE, which resulted in the center/rotation pivot not being calculated for lal3d. This has been fixed here: http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)
I'll send my fixed version of the test case back to you...
Cool. Thanks a lot, pal.