The model2sprite tool


By Malcolm Walker

Preamble


This paper describes a program written for Worldforge called 'model2sprite' , which is designed to generate a set of animated 2D isometric sprites based on a Cal3d model.
 

Purpose


The purpose of the sprite generator program is to allow artists to quickly generate the many images required for animated character movement in 2D isometric clients (Uclient, Frost, etc.).  The images are generated from an animated skeletal model created in a modeling program such as 3D Studio Max or Milkshape.  The generated sprites are named in a scheme similar to the scheme used by Uclient, each sprite filename has the model name, animation name, direction, and frame number.
 

How It Works


The model is stored on disk in the cal3d native format.  The model is loaded and animated realtime using the Cal3D timer.  (On computers with poor 3D performance, this mode will be very choppy).  The user begins the rendering process by matching a loop - the tool will enter a controlled animation mode where the model's position is advanced by a constant amount each frame.  One mesh is chosen as a 'problem mesh' - its vertices are tracked and the absolute difference in position is calcuated for each consective frame, as well as the absolute difference between the 29th earlier frame.  Once the difference between loop endpoints is within a resonable threshold of the lower limit of total change, the loop is closed.

The vertices of the problem mesh for the frames around the loop point are then normalized so that any skip in mesh position is reduced or removed. The following two animations are composed of 30 frames each. 26 of the 30 frames are exact matches, the remaining 4 have been interpolated in the 'After' animation.

Raw Loop    Clean Loop
Before / After

Now that the model has a 'clean' set of frames to animate, the rendering process begins.  Before any files are saved to disk, the renderer is set up by setting the model-to-camera distances, angle of rotation and inclination of the camera, resetting timers and verifying that we have enough data captured from cal3d to perform the renders.  Once the preconditions are met, the model is run through the animation frames 8 times, rotated 45 degrees for each pass.  For a 30-frame animation, this results in 240 rendered images.  The images are saved in PNG format and are currently set to be 120x120 pixels in size.

http://victor.worldforge.org/cgi-bin/browser/browse.cgi?dir=/sprites/paladin
At the time of writing, the 'jog' sprites show the paladin's cape looping correctly but colliding incorrectly.  The 'walk' sprites were generated before the looping code was completed.

Components

The model loading, parsing, and rendering code is a modified version of that found in Beosil's cal3d miniviewer.  It uses the glut toolkit to handle mouse and keyboard events, and an OpenGL renderer.  Cal3D version 0.0.7 is used to animate the model.  The sprites are captured using PNG screen-capture code from the GLTron project.

Current Features

Planned Features

Unplanned Features

References

The Cal3D Library by Beosil : (http://cal3d.sourceforge.net)
PNG capture code stolen from Andreas Umbach (http://www.gltron.org/)
The model2sprite program exists in WorldForge CVS under the path forge/tools/model2sprite.