ANIM (Metroid Prime 3)

This article is for the ANIM format used in Metroid Prime 3''. See ANIM (File Format) for the other revisions of this format.''

The ANIM format is used in conjunction with CINF + CSKR rigging to animate CMDL meshes.

There are two versions of the ANIM format in Metroid Prime 3 (indicated by the file's first u32 value):

Quaternion Array Format
This format is identical to Metroid Prime 2's Version 0 except for an unknown u16 value inserted at the beginning.

Bitstream Format
The Bitstream Format (0x1) version of ANIM is a significant departure from Version 0x2 used in MP1/2. It's still based on a bitstream with delta encoding and quantization, but the quaternion encoding is simpler to decode and the key-layout is slightly different.

There is no longer a frame interval value for defining a consistent frame-rate; each key's time position is explicitly defined as a floating-point value in seconds.

Additionally, CINF bone-IDs are no longer explicitly defined; the indexing position of the bone channel serves as the bone-ID (beginning at 0 for the root bone).

Key Values
Each keyed-frame begins with 1-bit in the stream; its purpose is unknown.

Each channel attribute is initialized iteratively using the init_block values. For every frame of every bone channel, the key value in the bitstream is added with the previous key value (to resolve the delta encoding).

Once resolved, rotation imaginary components and scale components are divided by 0x7FFF, resulting in normalized floats.

Rotation channels consist of 4-components per-bone. The first expresses the quaternion W-sign in the least-significant bit. The remaining 3 express quaternion imaginary (XYZ) values. The W value itself is calculated using normalized-difference:

q = 1.0 / 0x7FFF X = rx * q Y = ry * q Z = rz * q W = sqrt(MAX((1.0 - (X*X + Y*Y + Z*Z)), 0.0)) W = (rw & 0x1) ? -W : W

Translation components are multiplied by translation_multiplier, yielding world units.