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.

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
- Presets for camera inclination, rotational offset, background color (all hardcoded)
- Identification of a single 'problem mesh' to process and join at loop endpoints
- Keyboard interface
- GLUT text with various statistics, updated realtime
- GL Renderer
Planned Features
- Adjustable camera, lighting, and other currently-hardcoded settings through live interface
- Ability to select single, multiple, or no meshes for loop endpoint join
- Offscreen (high-quality) renderer
- Opaque & invisible bodies to render clothing sprites only (for costuming other sprites)
- Support for animated models in formats importable by cal3d
Unplanned Features
- Cloth collision not implemented at current time in Cal3d - some clothes will intersect body of model
- Occasional crashes on XFree86 4 with DRI drivers
- No GLUT text in Win32
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.
| Current Issue: February 2003, Recent Issues: January 2003, November 2002, October 2002 |