Author Topic: keyframe animation  (Read 996 times)

Offline ciropan

  • byte
  • *
  • Posts: 1
    • View Profile
keyframe animation
« on: February 05, 2012, 01:49:50 pm »
I'm trying animation keyframe, but my object stand still.
Why?
Code: [Select]

                               thing = loadModel(R.raw.omino_1, 1f);

Animation anim = new Animation(4);
anim.createSubSequence("idle");
                anim.addKeyFrame(thing.getMesh());
       
anim.createSubSequence("walk");
anim.addKeyFrame(loadModel(R.raw.omino_1, 1f).getMesh());
anim.addKeyFrame(loadModel(R.raw.omino_2, 1f).getMesh());
anim.addKeyFrame(loadModel(R.raw.omino_3, 1f).getMesh());

thing.setAnimationSequence(anim);
world.addObject(thing);
...


Code: [Select]
private Object3D loadModel(int objId, float scale) {
Resources res = getResources();
        Object3D[] model = Loader.load3DS(res.openRawResource(objId), scale);
        Object3D o3d = new Object3D(0);
        Object3D temp = null;
        for (int i = 0; i < model.length; i++) {
            temp = model[i];
            temp.setCenter(SimpleVector.ORIGIN);
            temp.rotateX((float)( -.5*Math.PI));
            temp.rotateMesh();
            temp.setRotationMatrix(new Matrix());
            o3d = Object3D.mergeObjects(o3d, temp);
            o3d.build();
        }
        return o3d;
    }

Code: [Select]
public void doAnim() {
        ind += 0.1f;
        if (ind >= 1f) {
                ind = 0;
        }
       
        Logger.log("frame: "+ind);
        thing.animate(ind, thing.getAnimationSequence().getSequence("walk"));        
}
What is the problem?
Can you help me, please?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: keyframe animation
« Reply #1 on: February 05, 2012, 08:37:28 pm »
That way, you are calling build() before the animation has been assigned, which makes jPCT-AE compile the object into static mode. Try to replace the call to o3d.build(); int the loadModel-method by o3d.calcNormals(); o3d.calcBoundingBox(); and call build() only on the final object after setting the animation. I guess i should add a log message to handle this case better.