Howto : Smooth animations using OBJ keyframes and the Morph node

Hi,

First, some background info :

  • Morph node == smooth interpolation between 2 or more shapes sharing the same appearance
  • OBJ : a static (non animated) format
  • Morph + OBJ == smoothed KeyFrame animation (every OBJ beeing a Key position)

As I’ve been privately asked to explain the animation processus used in Jack Flowers, here it is :

  • step 1 : create a “key frame” setup, for example, 6 to 8 poses for a character walking, load each pose as BranchGroup with the OBJLoader

  • step 2 : use a Switch node to group these poses, the Switch will only display one pose at a time, which will help us for calculating the animation timing sequence :

  • step 3 : calculate an appropriate timing sequence, and test it with the Switch node. for example, if the poses are time-linear, just test how much time has passed between the begining of the animation and the current frame, and find which node corresponds

 
  float sumTime;
  public void step(float deltaTime){
     this.sumTime += deltaTime;
  }
  float singleFrameDuration = 0.2; // in seconds
  public int getAnimationSequence(){
    return (int) (sumTime / singleFrameDuration);  // this has to be tweaked to find the appropriate timing (I use an enhanced version based on a array of timings)
  }

  • step 4 : convert the Switch node to a Morph node ! Add the same poses to this node.
    The morph node needs :
    -an array of GeometryArray (corresponding to every pose)
    -an appearance (should be the same for every pose)

(a recursive/tree inspection of the BranchGroup looking for a Shape3D was enough for me to find the geometry and appearance)

once the MorphNode is loaded, the last part is - for each frame - to select the two poses surrounding the current position, and the amount of these required.


  public float getAnimationSequence(){
    return  (sumTime / singleFrameDuration); // now we return a float value
  }


The morph node uses an array of weights for every pose, a zero weight for a pose makes it ignored (an optimization to avoid a lot of multiplies by 0)
So, the last part is to update this array of weights, with zeroes for every weight except for the two poses surrounding the current animation morph. These two remaining values can be easily computed from the float returned by getAnimationSequence :


  float pose = getAnimationSequence();
  int pose1 = (int) pose;
  int pose2 = (int) (pose +1);
  float pose1Weight = 1- (pose-pose1);   
  float pose2Weight = 1- (pose1Weight);   
  weights[pose1] = pose1Weight;
  weights[pose2] = pose2Weight;
  // zero the other weights ....
  // and update the morph node
  morphNode.setWeights(weights);
  

Of course, you have to take special care of loops (from last pose to first one) which is not shown here, and of course encapsulate everything into a MorphedAnimation object to avoid thinking of it again next time you’ll need an animation…

I hope some people here will find this information useful !

Lilian :slight_smile:

Of course, WE DO! Thank you very much. We try it and keep you informed.

Greetz,

Stevie

Lilian, I added your HOWTO to the new Xith site. Thank you very much. Others will follow. I consider writing one on Keyframe animation with MD2, and COLLADA.

And if you could post a few images to illustrate your HOWTO that’d be cool.

Sure, as soon as I can.

For now I’ve got something more important to do : due to yesterdays internet and electrical blow out in Paris, our hosted web server has been destroyed… I have to rebuild it completely from the backups (bad, bad day).

Lilian

this is complete offtopic … i’m just curious … is this due to the excesses in france? And (should you be from there) how bad is it to live in france at the moment?

No, not related. There has been a electrical cut on a major internet line in paris, and it has cascaded it computer crashes…

Life in France is still very good. you know, people are on the street to complain (I’m with them), but right after that, we come back home and everything’s back to normal…

It’s just our form of lobbyism… nothing related (yet) to the events of last october which were more dramatic.

Lilian

That’s right, I live in France too, and there aren’t soo much troubles. Right there are frequent strikes, but really out from schools everything’s ok.

that’s good to hear … over here (germany) it sometimes looks like there is a civil war going on when your guys are out on the streets, and i’m not talking about boulevard press here … no offense meant about that …

;D ;D ;D
No really no civil war… never.
Do the german press really say there are many violences in France ?

nahh Goliat exaggerated it. But anyways it’s not something I would call peaceful :wink: - But hey! France is big and if in one part people are throwing stones, that doesn’t mean it’s everywhere like that. I believe most demonstrations are peaceful.

But in france the unemployment rate is higher than in Germany and it’s already a very important topic in german politics.