IFP

From GTAMods Wiki
Revision as of 11:49, 4 July 2008 by Aschratt (talk | contribs) (Object)
Jump to navigation Jump to search

IFP is the animation format of the Grand Theft Auto series since. With 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 descriping the following value(s). Offsets are allways relative to the current file position. To convert a relative offset to an absolute one just add the number of read bytes.

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)

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
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 end of frames
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

Frametypes

Frametypes define the size and the content of a frame. Actually there are 3 known types. Each frametype 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 which points to an offset in the world. For cutscenes it is relative to an offset given in a special file. Usualy 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    - Quarternion X
4b   - Float    - Quarternion Y
4b   - Float    - Quarternion Z
4b   - Float    - Quarternion W
// Translation
4b   - Float    - X
4b   - Float    - Y
4b   - Float    - Z
// Scale
4b   - Float    - X
4b   - Float    - Y
4b   - Float    - Z

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

4b   - Float    - Time

Version 2

Version 2 archives got basicly 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
4b   - Int32    - Number of Animations

Animation

24b  - Char[24] - Animation Name
4b   - Int32    - Number of Objects
4b   - Int32    - Spaceallocator
4b   - Int32    - Unknown, allways 1

The spaceallocating value is required by the game to allocate memory for the frame array. It is an exact number of all values including floating coordinates and time keys in the frames section. Those are not parsed and directly stored as words. They are parsed, when the game needs them.

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 allways follow the following structure:

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

Child sections have no translation values.

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

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