IFP

From GTAMods Wiki
Revision as of 14:59, 3 February 2009 by Steve-m (talk | contribs) (various fixes)
Jump to navigation Jump to search

IFP is the animation format of the Grand Theft Auto series since GTA III. With GTA San Andreas there came a new version of the file format, but it still supports animations with the old version. IFP files can contain several single animations which are split up to objects and linked to the animated object or actor in that way. Each object contains a certain number of frames including a time key. Two frames are interpolated by the game.

File Specification

Version 1

Version 1 packages are split up as usual into several data structures. The values of those structures are identified by 4 byte information markers. Those are 4 characters describing the following value(s). Note that the only markers which are really used are "DGAN" and "NAME". All others are simply waste of space. Do not search for them in your code, because not all animations got information markers where they are expected. Sometimes they are also simply zero.

Offsets are always relative to the current file position. To convert a relative offset to an absolute one just add the number of read bytes. Strings are always padded to 4 byte bounds. The "AnimNameLength" string after the "NAME" information marker describes the string including the terminating zero-byte. You have to round up this value until the number is able to be divided by 4 without any rest, to get the number of bytes you have to write.


Header

4b   - FourCC   - "ANPK" (Animation Package, Version identifier)
4b   - Int32    - Offset to the end of the file
4b   - FourCC   - "INFO"
4b   - Int32    - Offset to end of header
4b   - Int32    - Number of animations
Xb   - Char[X]  - Null-terminated string (internal file name used in the script)

Animation

4b   - FourCC   - "NAME"
4b   - Int32    - Length of the name of the animation (X)
Xb   - char[X]  - Animation name (null-terminated string)
4b   - FourCC   - "DGAN"
4b   - Int32    - Offset to the end of the animation (including it's content)
4b   - FourCC   - "INFO"
4b   - Int32    - Offset to first object (usually 0x08)
4b   - Int32    - Number of objects in the animation
4b   - Int32    - NULL

Object

4b   - FourCC   - "CPAN"
4b   - Int32    - Offset to end of object
4b   - FourCC   - "ANIM"
4b   - Int32    - Offset to the start of frames (usually 0x2C)
28b  - Char[28] - Object name (null-terminated string)
4b   - Int32    - Number of frames
4b   - Int32    - NULL
4b   - Int32    - Next sibling
4b   - Int32    - Previous sibling

Frame Info

4b   - FourCC   - Type
4b   - Int32    - End of frame data
Frame Types

Frame types define the size and the content of a frame. Actually there are 3 known types. Each frame type identifier starts with K which corresponds to "Keyframe". The following 3 bytes define the order and the content of the data. They are ASCII encoded characters

R - Rotation
T - Translation
S - Scale
0 - None

Translation is a vector describing a difference in position relative to the current offset in the world as defined by parent frames. For cutscenes it is relative to an offset given in a special file. Usually just the root object contains translated frames.

Frame Data

Each type has a different structure. They can be combined and are read by the game in the order they are written in the type value.

// Rotation
4b   - Float    - Quaternion X
4b   - Float    - Quaternion Y
4b   - Float    - Quaternion Z
4b   - Float    - Quaternion W
// Translation
4b   - Float    - Position X
4b   - Float    - Position Y
4b   - Float    - Position Z
// Scale
4b   - Float    - Scale X
4b   - Float    - Scale Y
4b   - Float    - Scale Z

Every frame got one last floating value at the end describing the time in seconds.

4b   - Float    - Time

Version 2

Version 2 archives got basically the same hierarchy as above, but the structures are a bit different. In version 2 all strings are null-terminated, but they got a constant size of 24 bytes.

Header

4b   - FourCC   - 'ANP3' (Animation Package 3, Version identifier. However there is no pack with ANP2)
4b   - Int32    - Offset to end of file
24b  - Char[24] - internal file name used in the script
4b   - Int32    - Number of Animations

Animation

24b  - Char[24] - Animation Name
4b   - Int32    - Number of Objects
4b   - Int32    - Size of frame data
4b   - Int32    - Unknown, always 1

The size of data value is a number of bytes which corresponds to the exact size of the frame's usable data, including the compressed coordinates and rotation info.

Object

24b  - Char[24] - Object Name
4b   - Int32    - Frame type: Child = 3, Root = 4
4b   - Int32    - Number of Frames
4b   - Int32    - Bone ID

Frame

Root frames usually follow the following structure:

2b   - Int16    - Quaternion X
2b   - Int16    - Quaternion Y
2b   - Int16    - Quaternion Z
2b   - Int16    - Quaternion W
2b   - Int16    - Time (in seconds)
2b   - Int16    - Translation X
2b   - Int16    - Translation Y
2b   - Int16    - Translation Z

Child sections normally have no translation values:

2b   - Int16    - Quaternion X
2b   - Int16    - Quaternion Y
2b   - Int16    - Quaternion Z
2b   - Int16    - Quaternion W
2b   - Int16    - Time (in seconds)

To convert quaternion and translation values to floating values divide them by 4096.

External Links