Source: src/public/studio.h in ValveSoftware/source-sdk-2013, version 48, read on
13 November 2026. Sizes are the sums of the declared field types for the 32-bit layout. Every
…index is a byte offset from the start of the record that holds it. A sequence is a named,
blendable group of animations; an animation is the movement of the bones over a number of frames.
Animation descriptions
mstudioanimdesc_t, 100 bytes, at the header’s localanimindex.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 4 | int32 | baseptr | Offset back to the header, from this record |
| 4 | 4 | int32 | sznameindex | Offset of the name |
| 8 | 4 | float | fps | Frames per second |
| 12 | 4 | int32 | flags | Looping and other flags; see the sequence flags below |
| 16 | 4 | int32 | numframes | Number of frames |
| 20, 24 | 4, 4 | int32 | nummovements, movementindex | Piecewise movement: mstudiomovement_t, 44 bytes |
| 28 | 24 | int32[6] | unused1 | Unused (to be zero when loading older versions) |
| 52 | 4 | int32 | animblock | Animation block that holds the data |
| 56 | 4 | int32 | animindex | Offset of the animation data; non-zero when the data is not in sections |
| 60, 64 | 4, 4 | int32 | numikrules, ikruleindex | IK rules stored in the .mdl (ikruleindex non-zero then) |
| 68 | 4 | int32 | animblockikruleindex | Non-zero when the IK data is in the animation block file |
| 72, 76 | 4, 4 | int32 | numlocalhierarchy, localhierarchyindex | mstudiolocalhierarchy_t, 48 bytes |
| 80 | 4 | int32 | sectionindex | Offset of the mstudioanimsections_t records |
| 84 | 4 | int32 | sectionframes | Frames in each fast-lookup section; 0 if sections are not used |
| 88 | 2 | int16 | zeroframespan | Frames per span (not valid before version 47) |
| 90 | 2 | int16 | zeroframecount | Number of spans |
| 92 | 4 | int32 | zeroframeindex | Offset of the zero-frame data, 0 for none (cleared when converting version 47) |
| 96 | 4 | float | zeroframestalltime | Saved during read stalls (mutable) |
Sections
An mstudioanimsections_t is 8 bytes: animblock and animindex (ints).
With sections the animation is cut into runs of sectionframes frames, each with its own
data, so one frame can be found without reading the whole animation.
Movements
mstudiomovement_t, 44 bytes: endframe (int), motionflags (int, the
motion types), v0 (velocity at the start
of the block), v1 (at the end), angle (yaw rotation at the end of the block’s
movement), vector (movement relative to the block’s initial angle), and position
(relative to the start of the animation; the header marks it with question marks).
Local hierarchy
mstudiolocalhierarchy_t, 48 bytes: iBone (the bone being adjusted),
iNewParent, start, peak, tail, end (floats:
beginning of influence, start of full influence, end of full influence, end of all influence),
iStart (first frame), localanimindex (offset of an
mstudiocompressedikerror_t, see Skeleton) and
four unused ints.
Per-bone animation data
An animation’s data is a chain of mstudioanim_t records, one per animated bone. Each starts
with 4 bytes and is followed by data chosen by the flags.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 1 | byte | bone | Bone index |
| 1 | 1 | byte | flags | Below |
| 2 | 2 | int16 | nextoffset | Offset from this record to the next; 0 ends the chain |
| 4 | … | data | In this order, as the flags select: the rotation (a raw quaternion, or a value pointer), then the position |
| Flag | Name | Data that follows |
|---|---|---|
| 0x01 | STUDIO_ANIM_RAWPOS | A Vector48, constant over the animation |
| 0x02 | STUDIO_ANIM_RAWROT | A Quaternion48, constant |
| 0x04 | STUDIO_ANIM_ANIMPOS | An mstudioanim_valueptr_t for position |
| 0x08 | STUDIO_ANIM_ANIMROT | An mstudioanim_valueptr_t for rotation |
| 0x10 | STUDIO_ANIM_DELTA | Delta animation |
| 0x20 | STUDIO_ANIM_RAWROT2 | A Quaternion64, constant |
The header’s accessors place the data as follows. The rotation data starts at offset 4. A raw position
follows the raw rotation: after a Quaternion48 if RAWROT is set, after a
Quaternion64 if RAWROT2 is set. With animated data the position value pointer follows the
rotation value pointer if ANIMROT is set, and starts at offset 4 if it is not.
Value streams
mstudioanim_valueptr_t is 6 bytes: offset[3], three shorts, one each for x, y and
z. An offset is from the start of this value pointer to a value stream; 0 or negative means there is none
for that axis. A stream is made of mstudioanimvalue_t entries, a union of two bytes
(valid, total) or one short value.
A stream is a series of spans. Each span is one entry holding valid and
total, followed by valid values. The span covers total frames: the
first valid frames take the stored values in turn and the rest repeat the last one. To find a
frame, spans are skipped, taking total from the frame number, until the frame falls inside
one; a span with a total of 0 gives 0. Between two frames the engine takes the value of the
next frame as well, from the following span if the current one ends. The values are multiplied by the
bone’s posscale (position) or rotscale (radian angles), and unless the record is a
delta, the bone’s pos or rot is added. The two sets of angles are turned into
quaternions before they are blended; if the bone has the flag BONE_FIXED_ALIGNMENT
(0x00100000) the result of a non-delta rotation is aligned to qAlignment.
Packed vectors and quaternions
| Type | Bytes | Layout, lowest bits first |
|---|---|---|
float16 | 2 | 10 bits mantissa, 5 bits exponent with a bias of 15, 1 sign bit. An exponent of 31 reads as ±65504 when the mantissa is 0 and as 0 otherwise |
Vector48 | 6 | Three float16: x, y, z |
Quaternion48 | 6 | x 16 bits, y 16 bits, z 15 bits, 1 bit for the sign of w. x = (x − 32768) ÷ 32768, y the same way, z = (z − 16384) ÷ 16384 |
Quaternion64 | 8 | x, y, z 21 bits each, 1 bit for the sign of w. Each is (n − 1048576) ÷ 1048576.5 |
In both quaternions w is the square root of 1 − x² − y² − z², negative if the sign bit is set.
Sequence descriptions
mstudioseqdesc_t, 212 bytes, at the header’s localseqindex.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 4 | int32 | baseptr | Offset back to the header, from this record |
| 4 | 4 | int32 | szlabelindex | Offset of the label |
| 8 | 4 | int32 | szactivitynameindex | Offset of the activity name |
| 12 | 4 | int32 | flags | Looping and other flags, below |
| 16 | 4 | int32 | activity | Initialised at load time to the game’s values |
| 20 | 4 | int32 | actweight | Activity weight |
| 24, 28 | 4, 4 | int32 | numevents, eventindex | mstudioevent_t, 80 bytes |
| 32 | 12 | Vector | bbmin | Per-sequence bounding box, lower corner |
| 44 | 12 | Vector | bbmax | Upper corner |
| 56 | 4 | int32 | numblends | Number of blended animations |
| 60 | 4 | int32 | animindexindex | Offset of an array of shorts, groupsize[0] × groupsize[1] long, each an animation index; the entry for (x, y) is y × groupsize[0] + x, and x and y are clamped to the group size |
| 64 | 4 | int32 | movementindex | Offset of a float array, one per blend, for blended movement |
| 68 | 8 | int32[2] | groupsize | Size of the blend grid |
| 76 | 8 | int32[2] | paramindex | Pose parameters that drive the blend (X, Y, Z, XR, YR, ZR) |
| 84 | 8 | float[2] | paramstart | Local (0 to 1) starting value |
| 92 | 8 | float[2] | paramend | Local ending value |
| 100 | 4 | int32 | paramparent | Parent parameter |
| 104, 108 | 4, 4 | float | fadeintime, fadeouttime | Ideal cross-fade times (0.2 by default) |
| 112, 116, 120 | 4 each | int32 | localentrynode, localexitnode, nodeflags | Transition nodes at entry and exit, and the transition rules |
| 124, 128 | 4, 4 | float | entryphase, exitphase | Used to match the entry and exit gait |
| 132 | 4 | float | lastframe | Frame that should generate the end-of-sequence event |
| 136 | 4 | int32 | nextseq | Auto-advancing sequence |
| 140 | 4 | int32 | pose | Index of the delta animation between the end and nextseq |
| 144 | 4 | int32 | numikrules | Number of IK rules |
| 148, 152 | 4, 4 | int32 | numautolayers, autolayerindex | mstudioautolayer_t, 24 bytes |
| 156 | 4 | int32 | weightlistindex | Offset of one float per bone |
| 160 | 4 | int32 | posekeyindex | Offset of floats read as iParam × groupsize[0] + iAnim |
| 164, 168 | 4, 4 | int32 | numiklocks, iklockindex | mstudioiklock_t, 32 bytes |
| 172, 176 | 4, 4 | int32 | keyvalueindex, keyvaluesize | Key-values text; a size of 0 means none |
| 180 | 4 | int32 | cycleposeindex | Pose parameter used as the cycle index |
| 184, 188 | 4, 4 | int32 | activitymodifierindex, numactivitymodifiers | mstudioactivitymodifier_t, 4 bytes: sznameindex |
| 192 | 20 | int32[5] | unused | Unused; the header comment says they grow back to 8 ints on a version change |
Events
mstudioevent_t, 80 bytes.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 4 | float | cycle | Point in the sequence |
| 4 | 4 | int32 | event | Event number |
| 8 | 4 | int32 | type | Event type; the header defines NEW_EVENT_STYLE as 1 << 10 and calls the old event system one to phase out |
| 12 | 64 | char[64] | options | Option string |
| 76 | 4 | int32 | szeventindex | Offset of the event name |
Auto layers
mstudioautolayer_t, 24 bytes: iSequence (int16), iPose (int16),
flags (int32), and the floats start, peak, tail,
end (beginning of influence, start of full influence, end of full influence, end of all
influence).
Flags
| Where | Values |
|---|---|
Sequence and animation flags | 0x0001 STUDIO_LOOPING, ending frame the same as the start; 0x0002 STUDIO_SNAP, no interpolation from the previous animation; 0x0004 STUDIO_DELTA, adds to the base sequences instead of blending; 0x0008 STUDIO_AUTOPLAY, always plays; 0x0010 STUDIO_POST; 0x0020 STUDIO_ALLZEROS, no real animation data; 0x0040 unused; 0x0080 STUDIO_CYCLEPOSE, cycle from a pose parameter; 0x0100 STUDIO_REALTIME, cycle from a real-time clock; 0x0200 STUDIO_LOCAL, has a local context sequence; 0x0400 STUDIO_HIDDEN, hidden in default views; 0x0800 STUDIO_OVERRIDE, a forward-declared empty sequence; 0x1000 STUDIO_ACTIVITY, activity index updated at run time; 0x2000 STUDIO_EVENT, event index updated at run time; 0x4000 STUDIO_WORLD, blends in world space |
Auto layer flags | 0x0010 STUDIO_AL_POST; 0x0040 STUDIO_AL_SPLINE, ramp in and out is a spline instead of linear; 0x0080 STUDIO_AL_XFADE, pre-bias the ramp for a weight other than 1; 0x0200 STUDIO_AL_NOBLEND, always blends at 1.0, ignoring weight; 0x1000 STUDIO_AL_LOCAL, a local context sequence; 0x4000 STUDIO_AL_POSE, blends using a pose parameter instead of the parent cycle |
How a sequence is played
Facts from public/bone_setup.cpp of the same repository. The running game keeps each pose
parameter as a number from 0 to 1 of the way from start to end; a value in units
is first wrapped into the looping range when loop is not 0.
The place in the grid
Columns and rows are each driven by their own pose parameter, and give the first animation i of a square of the grid and the share s of the next one.
- Without pose keys, s is the parameter measured from
paramstarttoparamendand held to 0 to 1. With more than two animations in the direction it is multiplied by the size less 1; the whole part is i (at most the size less 2) and the rest is s. - With pose keys, the parameter is taken in its units, i advances while the value lies beyond the next key, and s is (value − key i) ÷ (key i+1 − key i), held to 0 to 1.
The mix
A share below 0.001 counts as 0 and, for columns, above 0.999 as 1. With a the column share and b the row share:
- a 0 or 1: one column is used; one of its animations when b is 0 or 1, else the
two mixed by b. With b 0, an animation flagged
STUDIO_ALLZEROSleaves the rest pose. - b 0: the two columns mixed by a. If one of them is all zeros, the other is instead scaled by its own share: its positions are multiplied by it and its rotation moved that far from no rotation, then brought to length 1.
- b 1: the two columns of the next row mixed by a.
- Otherwise three corners of the square are mixed, the square being cut along a diagonal that alternates from square to square:
| Column + row of the square | Case | Corners (column, row) and weights |
|---|---|---|
| Even | a > b | (0,0) 1 − a; (1,0) a − b; (1,1) b |
| Even | otherwise | (1,1) a; (0,1) b − a; (0,0) 1 − b |
| Odd | a + b > 1 | (1,0) 1 − b; (1,1) a + b − 1; (0,1) 1 − a |
| Odd | otherwise | (0,1) b; (0,0) 1 − a − b; (1,0) a |
The first two corners are mixed in proportion, then the third by its weight. A second weight below 0.001
counts as 0. Positions are mixed linearly; rotations linearly and brought to length 1, after aligning their
signs unless the bone has BONE_FIXED_ALIGNMENT. The length of the sequence comes from the four
corners of the square with the weights (1−a)(1−b), a(1−b),
(1−a)b and ab: cycles a second are the weighted sum of
fps ÷ (numframes − 1), and the frame count the weighted sum of
numframes.
Laying a sequence on a pose
A sequence is laid on the pose built so far (at first the rest pose) with a weight. Each bone’s share is the
weight, held to 1, times the bone’s entry in the weight list. A delta sequence multiplies the bone’s rotation
by its own, scaled to the share (after it with STUDIO_POST, before it without), and adds its
position times the share; any other sequence is mixed in, positions linearly and rotations spherically. The
sequence’s auto layers are then laid on the result, each in the same way and with its own layers. A sequence
flagged STUDIO_LOCAL first lays its STUDIO_AL_LOCAL layers on its own pose, with a
weight of 1, before that pose is laid down. A sequence flagged STUDIO_CYCLEPOSE takes its cycle
from a pose parameter, one flagged STUDIO_REALTIME from the clock.
A layer whose start equals its end takes the parent’s cycle and weight. Otherwise
it plays while the measure — the parent’s cycle, or with STUDIO_AL_POSE the pose parameter
iPose in its units — is at least start and below end. The ramp
r rises from 0 to 1 between start and peak, stays 1, and falls to 0
between tail and end; STUDIO_AL_SPLINE turns it into
3r² − 2r³. With w the parent’s weight the layer’s weight is
wr; past tail with STUDIO_AL_XFADE it is
rw ÷ (1 − w + rw); otherwise with STUDIO_AL_NOBLEND it is
r. A layer measured on the cycle runs its own cycle from 0 at start to 1 at
end.
World space blending
A sequence flagged STUDIO_WORLD is mixed in the model’s space, whatever its other flags
say. Each bone’s share s is the weight times its entry in the weight list. Where the bone’s and
its parent’s shares are both 1, the bone takes the sequence’s rotation and position as they are. Otherwise,
for a share above 0, the bone’s orientation in model space is worked out for the pose underneath and for
the sequence’s pose, the two are mixed spherically by s, and the result, placed where the bone
stands underneath, is turned back into a rotation relative to the parent’s mixed matrix. The position
relative to the parent is mixed linearly; a bone without a parent keeps its position. Where the parent was
not mixed this way (its share is 0, or it took the shortcut above), the SDK’s code reads a matrix that it
has not set.
Autoplay sequences
After the sequence being played and its layers, each sequence flagged STUDIO_AUTOPLAY is
laid on the pose in turn with a weight of 1. Its cycle is the fraction part of the time in seconds times its
cycles a second, as mixed from the animations of its grid. The ends of the chains named
by the autoplay IK locks are noted before this step and put back after it. The client code
runs this step with a separate IK context that is thrown away, so the IK rules of autoplay sequences are
never solved.
Inverse kinematics
An IK chain names a thigh, a knee and a foot bone (the first three links; the names stand for any limb). The client applies, in this order: the locks of each sequence while it is laid on, the autoplay locks around the autoplay sequences, the bone controllers, and then the IK rules gathered from the sequence being played and its layers. Procedural bones are worked out afterwards; a bone the solver placed keeps the matrix the solver built for it. The client does none of this for a model without chains, for a scaled model, for a ragdoll, or for an entity that asks for no IK.
The solver. With a and b the present lengths of the two links, the
target is pulled in to at most 0.9998 (a + b) from the thigh and pushed out to at
least the larger of 1.15 |a − b| and 0.15 min(a, b). Where the
first link has a kneeDir, that direction, turned with the thigh, is taken from the present knee
and carried out 100 times the leg’s length to say which side the knee bends to. Where it has none, the knee
keeps to the side it is on, and a leg already stretched past 0.9998 (a + b) is not
solved. The knee then follows from the two lengths, in the plane of the target and that direction. The thigh
and knee matrices are turned so that their first axis runs along the link, keeping the third axis as near as
they can; the foot is moved to the target and given the wanted orientation; and the three bones are turned
back into rotations and positions in their parents.
Locks. A lock notes the foot’s position and orientation in model space, from the pose
before a step. After the step the foot target is the present position moved towards the noted one by
flPosWeight; the chain is solved; the foot takes the noted orientation; and its rotation in its
parent is then moved spherically back, by flLocalQWeight, towards the one it had before the
solve. Autoplay locks also note the knee’s position and preferred direction. Sequence locks note the
direction, but the SDK’s code leaves the knee position they use at the model’s origin. A sequence’s locks
are noted before it is laid on and solved after its auto layers.
Rules. Animations hold the rules; a sequence has numikrules of them, rule
i blended from rule i of the animations of its grid, with the weights of the mix.
start, peak, tail and end are blended first (values more
than half a cycle from the first animation’s are moved by a whole cycle). The rule’s strength rises from 0
at start to 1 at peak, holds to tail and falls to 0 at
end, each ramp eased as 3r² − 2r³; where end is past 1, a
cycle below start counts as one cycle later. A rule at 0.001 or less is passed over, except a
ground rule of a looping animation spanning more than 0.75 of the cycle, which is kept at 0.001. In each
animation the error frame is iStart + (numframes − 1) × (cycle −
start), mixed between neighbouring records; a plain error is a position and a quaternion, a
compressed one six value streams giving a position and three angles. The errors of the animations are summed
with their weights (release and unlatch rules add none).
The rules of a sequence are filed under their chain as it is laid on, with the weight it was laid with. One
whose strength times that weight is above 0.999 removes the rules filed before it for the chain (unless it
is an unlatch), and a release at that strength is not filed itself. At the end each chain starts from where
its foot is. A rule of type self takes the error as a target in the space of
bone (or of the model, for −1), moves the chain’s result towards it by its strength, and adds to
the chain’s weight; a release moves the result back towards the foot’s own place and adds
no weight. Chains with a weight above 0 are solved. Of the other types, a world rule only reaches an
assertion in this step and an unlatch does nothing in it; ground and attachment rules work through targets
that the running game fills from traces against the world, from attachments on entities and from what it
kept of earlier frames.
Root movement
An animation’s movement blocks place the whole model. In the block whose endframe is the first
at or past the frame, with f the fraction of the block passed, the distance is
v0 f + ½(v1 − v0) f², taken along
vector from the position of the block before; the yaw is mixed linearly from the
previous block’s angle to this one’s. For a mixed sequence, positions and angles of the four
animations are summed with their weights.
Pose parameters, transitions and included models
A pose parameter, mstudioposeparamdesc_t at localposeparamindex, is 20 bytes:
sznameindex (int), flags (int; the header’s comment is “????”), start,
end and loop (floats; loop is the looping range, 0 for no looping, 360
for rotations).
The transition graph is numlocalnodes × numlocalnodes bytes at
localnodeindex, read as from × numlocalnodes + to by the header’s
pLocalTransition accessor, and an array of name offsets (from the file start) at
localnodenameindex.
Included models, mstudiomodelgroup_t at includemodelindex, are 8 bytes:
szlabelindex (a text name) and sznameindex (the file name), both from the start of
the record. They name external animation and model files (the header’s comment). The
animation block table, mstudioanimblock_t (8 bytes: datastart,
dataend), at animblockindex, divides the .ani file named by
szanimblocknameindex. Block 0 is not used by the accessor, which asserts an index above 0.
How included models are joined
Facts from public/studio_virtualmodel.cpp and public/bone_setup.cpp of the same
repository. The engine builds one list from the model (group 0) and the models it includes: for each model its
sequences, animations, bones, attachments, pose parameters, nodes and IK autoplay locks are appended, then
the models it includes in turn, in the order of its records. An included file that is not found is passed
over, and at most 64 are taken from one model. Names are compared without regard to case.
- A sequence whose label is already listed is not added again, unless the listed one has the flag
STUDIO_OVERRIDE(a forward declaration): then the new one takes its place. - An animation or node whose name is already listed is not added again.
- Bones are matched to the first model’s bones by name; a bone with no namesake there is dropped. A different parent only draws a warning.
- An attachment whose bone has no match is dropped; one whose name is already listed is the listed one.
- Pose parameters of one name are one parameter, whose range runs from the smallest to the largest of the two starts and two ends.
- IK autoplay locks of one chain number are listed once. When the numbers of IK chains agree, a first model’s chain whose first link has no knee direction takes the included model’s.
- To pose a sequence of another model, every bone that is matched and has a weight above 0 in the sequence (weights are numbered by the sequence’s model) starts from that model’s rest position and rotation, or from no movement for a delta animation. The animation’s tracks are decoded with the bones of the model that holds the animation, and put on the matched bones of the first model.
- The numbers inside a sequence belong to its own model and are translated to the joined lists: the animations of its grid, the sequences of its auto layers, and its pose parameters (the parameter a layer’s ramp is measured on is translated by the model of the layered sequence). The bone an IK rule of type self names is translated to the first model’s bone; IK chain numbers are used as they are.
The viewer on this site tables, besides the joined sequences and pose parameters, the events, movement blocks, IK locks and IK rules of every included file it read, each under its file with the number the sequence or animation has in the joined lists, or the earlier one whose name it shares.