A sequence is one animation, such as idle1 or run: a number
of frames, each giving every bone’s position and rotation. Sequences are listed in the
main file; their bone data lives in sequence groups. The layouts are from
studio.h in the Half-Life SDK (version 10), and the decoding from the
client’s StudioModelRenderer.cpp.
Sequence groups
numseqgroups records of 104 bytes at seqgroupindex
(mstudioseqgroup_t). Group 0 is the main file itself; group
n is the file name0n.mdl (see
companion files).
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 32 | char[32] | label | Name, such as default |
| 32 | 64 | char[64] | name | File name of the group |
| 96 | 4 | int32 | unused1 | A pointer into the game’s cache while running; studiomdl writes 0 |
| 100 | 4 | int32 | unused2 | Formerly a data pointer, and 0 in files studiomdl writes. Valve’s SDK model viewer adds it to animindex for sequences of group 0; the SDK’s game renderer ignores it. The viewer here does as the model viewer does; where the field is not 0, an option at the top of the window switches to the renderer’s reading |
studiomdl labels group 0 default and each further group with the
word after $sequencegroup; $sequencegroupsize gives a size
limit in kilobytes. A sequence goes into the group declared last before it. The
name of a further group, and of its file’s header, is written as
models\name01.mdl, with the number in two digits.
Sequences
numseq records of 176 bytes at seqindex
(mstudioseqdesc_t).
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 32 | char[32] | label | Sequence name |
| 32 | 4 | float32 | fps | Frames per second |
| 36 | 4 | int32 | flags | 0x0001 STUDIO_LOOPING: the sequence repeats; no other flag is defined |
| 40 | 4 | int32 | activity | Activity number the game asks for, such as walking or dying; numbers belong to the game code (activity.h in Half-Life) |
| 44 | 4 | int32 | actweight | Weight for choosing at random among sequences with the same activity |
| 48 | 4 | int32 | numevents | Events (76 bytes each) |
| 52 | 4 | int32 | eventindex | Offset of the events, from the start of the main file |
| 56 | 4 | int32 | numframes | Frames in the sequence |
| 60 | 4 | int32 | numpivots | Foot pivots (20 bytes each) |
| 64 | 4 | int32 | pivotindex | Offset of the pivots |
| 68 | 4 | int32 | motiontype | Motion flags saying how the root moves, such as STUDIO_LX |
| 72 | 4 | int32 | motionbone | Bone the motion is measured on; studiomdl writes 0 |
| 76 | 12 | float32[3] | linearmovement | Distance the model travels over the whole sequence |
| 88 | 4 | int32 | automoveposindex | Not written by studiomdl; 0 |
| 92 | 4 | int32 | automoveangleindex | Not written; 0 |
| 96 | 12 | float32[3] | bbmin | Bounding box of the sequence, lower corner |
| 108 | 12 | float32[3] | bbmax | Upper corner |
| 120 | 4 | int32 | numblends | Copies of the animation to blend between: 1, 2, or 4 for two directions |
| 124 | 4 | int32 | animindex | Offset of the animation, from the start of the sequence group’s file |
| 128 | 8 | int32[2] | blendtype | Motion flag each blend direction varies, such as STUDIO_XR for aiming up and down |
| 136 | 8 | float32[2] | blendstart | Value at blend setting 0 |
| 144 | 8 | float32[2] | blendend | Value at blend setting 255 |
| 152 | 4 | int32 | blendparent | Not written; 0 |
| 156 | 4 | int32 | seqgroup | Sequence group holding the animation |
| 160 | 4 | int32 | entrynode | Transition node at the start, or 0 |
| 164 | 4 | int32 | exitnode | Transition node at the end, or 0 |
| 168 | 4 | int32 | nodeflags | Non-zero: the sequence may also be played backwards, from exit node to entry node |
| 172 | 4 | int32 | nextseq | Not written; 0 |
The transition graph uses the node fields.
How studiomdl fills a sequence
The fields come from the words of a $sequence command in the compiler’s
script:
| Words | Effect on the file |
|---|---|
A file name, or animation and a name | One blend each, in the order given |
fps n | fps; 30 without it |
loop | STUDIO_LOOPING |
frame first last | Only those source frames are kept; first becomes frame 0, and events and pivots are renumbered to match |
blend type start end | blendtype[0], blendstart[0] and blendend[0]; start 0 and end 1 without it |
node n | entrynode and exitnode both n |
transition a b | entrynode a, exitnode b |
rtransition a b | The same, with nodeflags 1 |
A motion word such as LX or XR | Its flag is added to motiontype |
An activity name (or ACT_ and a number) and a weight | activity and actweight |
event, pivot | An event or pivot record |
The compiler also changes the animation it stores. With LX,
LY or LZ, linearmovement is the root bone’s
position in the last frame less that in the first, on those axes, and that travel is
taken out of every root bone evenly over the frames. With XR,
YR or ZR a root bone keeps its first frame’s angle on that
axis. In a looping sequence the last frame is made equal to the first, except for the
positions on the LX, LY and LZ axes. The
automatic movement flags (AX to AZR) leave nothing in the
file.
Events
numevents records of 76 bytes at the sequence’s eventindex
(mstudioevent_t). An event fires when playback reaches its frame, for a
footstep sound, a muzzle flash or a hit.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 4 | int32 | frame | Frame on which it fires, counted from the sequence’s first stored frame; studiomdl moves an event outside the sequence to its first or last frame |
| 4 | 4 | int32 | event | Event number; the game code defines what each number does |
| 8 | 4 | int32 | type | Not written by studiomdl; 0 |
| 12 | 64 | char[64] | options | Text for the event, such as a sound file name |
Event numbers
The Half-Life SDK divides the numbers into ranges: below 1000 each monster’s own code gives them a meaning, from 1000 they belong to scripted sequences, from 2000 they are shared by monsters, and from 5000 they are handled by the player’s own computer (the client). A mod may give numbers meanings of its own.
| Number | Name in the SDK | What happens |
|---|---|---|
| 1000 | SCRIPT_EVENT_DEAD | The character is now dead |
| 1001 | SCRIPT_EVENT_NOINTERRUPT | The script may not be interrupted |
| 1002 | SCRIPT_EVENT_CANINTERRUPT | The script may be interrupted again |
| 1003 | SCRIPT_EVENT_FIREEVENT | The script’s event fires now |
| 1004 | SCRIPT_EVENT_SOUND | Plays the sound named in the options on the body channel |
| 1005 | SCRIPT_EVENT_SENTENCE | Speaks the sentence named in the options |
| 1006 | SCRIPT_EVENT_INAIR | Leaves the character in the air at the end of the sequence, without looking for the floor |
| 1007 | SCRIPT_EVENT_ENDANIMATION | Sets an animation by name after the sequence completes |
| 1008 | SCRIPT_EVENT_SOUND_VOICE | Plays the sound named in the options on the voice channel |
| 1009 | SCRIPT_EVENT_SENTENCE_RND1 | Speaks the sentence only some of the time: two times in three in the common monster code, one time in four in the talking monsters (guard, scientist) |
| 1010 | SCRIPT_EVENT_NOT_DEAD | The character is alive again |
| 2001 | MONSTER_EVENT_BODYDROP_LIGHT | A light body hits the ground |
| 2002 | MONSTER_EVENT_BODYDROP_HEAVY | A heavy body hits the ground |
| 2010 | MONSTER_EVENT_SWISHSOUND | A swing is heard |
| 5001, 5011, 5021, 5031 | Muzzle flash at attachment 0, 1, 2 or 3; the options give the kind as a number | |
| 5002 | Sparks at attachment 0 | |
| 5004 | Plays the sound named in the options at attachment 0 |
Numbers below 1000, monster by monster
These are the numbers that the monsters of the Half-Life SDK act on, with the model file each of those monsters loads. A number not listed for a monster is passed on to the common monster code, which has no case for it. The common code of flying and swimming monsters gives 8 (a flap: sets the flight speed) and 9 (the flap sound); of these monsters the ichthyosaur uses it. A mod’s monsters, or a mod’s changed copy of one of these, may mean something else by the same number.
| Monster | Model file | Number: what it does |
|---|---|---|
| Alien grunt | agrunt.mdl | 1–5 fire a hornet; 10 left footstep sound; 11 right footstep sound; 12 punch with the left arm; 13 punch with the right arm |
| Barnacle | barnacle.mdl | 2 throws out a piece of gib |
| Security guard (Barney) | barney.mdl | 2 draws the pistol (changes the body model); 3 fires it; 4 holsters it (changes the body model) |
| Big momma | big_mom.mdl | 1–4 footsteps (left, right, back left, back right); 5 sack sound; 6 death sound; 8–10 leg attacks; 11 launches a mortar; 12 lays a headcrab; 13 jumps up and forward; 14 alert sound; 15 pain sound; 16 attack sound; 17 birth sound; 50 fires its target early |
| Bloater | floater.mdl | 1 melee attack: the attack sound, which the SDK leaves empty |
| Bullsquid | bullsquid.mdl | 1 spit; 2 bite; 3 blink; 4 tail whip; 5 hop; 6 throw the victim |
| Alien controller | controller.mdl | 1 head opens and lights up; 2 releases a head ball; 3 fires small balls; 4 full glow; 5 weaker glow. For 1, 3, 4 and 5 the options are a time in fifteenths of a second |
| Gargantua | garg.mdl | 1 slash attack; 3 left and 4 right footstep (sound and screen shake); 5 stomp attack; 6 breathing sound |
| Assassin | hassassin.mdl | 1 fires her pistol; 2 throws a grenade; 3 jumps |
| Headcrab, baby headcrab | headcrab.mdl, baby_headcrab.mdl | 2 leaps at the enemy |
| Human grunt | hgrunt.mdl | 2 reload; 3 kick; 4 first shot of a burst; 5, 6 following shots; 7 throw a grenade; 8 launch a grenade; 9 drop a grenade; 10 call out on seeing the player again; 11 drop the gun |
| Houndeye | houndeye.mdl | 1 warning sound; 2 attack warm-up sound; 3 sonic attack; 4, 5 angry sounds; 6 hop backwards; 7 close the eye (changes the skin) |
| Ichthyosaur | icky.mdl | 1 shake the bite to the right; 2 to the left; 8 flap: sets the swimming speed; 9 flap sound |
| Alien slave (vortigaunt) | islave.mdl | 1 claw attack; 2 claw rake; 3 starts charging the zap; 4 fires it; 5 ends it |
| Leech | leech.mdl | 1 bite; 2 flop (the code does nothing) |
| Nihilanth | nihilanth.mdl | 1 shoot (the code does nothing); 2 starts firing, with sounds and lights; 3 sends the teleporting energy ball; 4 takes a sphere from the recharger; 5 recharge sound; 6 throws a zapping energy ball; 7 nothing (its code is commented out) |
| Scientist | scientist.mdl | 1 heals the target; 2 takes out the needle (changes the body model); 3 puts it away (changes the body model) |
| Tentacle | tentacle2.mdl | 1 bang on the ground; 2 lighter tap sound; 3 killing swing starts; 4 killing swing ends; 5 whoosh (its sound is commented out); 6 light tap; 7 roar; 8 searching sound; 9 swing sound |
| Xen tree | tree.mdl | 1 strikes whatever stands in front |
| Zombie | zombie.mdl | 1 slash with the right claw; 2 with the left; 3 with both |
The viewer’s events table gives these meanings for a file with one of these names. The option “Events below 1000” picks another monster’s list for a renamed model, or leaves the numbers alone.
Source: the game code of Valve’s Half-Life SDK,
dlls/: each
monster’s HandleAnimEvent.
Activity numbers
The names Half-Life’s game code (dlls/activity.h) gives the
activity field of a sequence, each prefixed ACT_ there.
| Numbers | Names, in order |
|---|---|
| 0–9 | RESET, IDLE, GUARD, WALK, RUN, FLY, SWIM, HOP, LEAP, FALL |
| 10–19 | LAND, STRAFE_LEFT, STRAFE_RIGHT, ROLL_LEFT, ROLL_RIGHT, TURN_LEFT, TURN_RIGHT, CROUCH, CROUCHIDLE, STAND |
| 20–29 | USE, SIGNAL1, SIGNAL2, SIGNAL3, TWITCH, COWER, SMALL_FLINCH, BIG_FLINCH, RANGE_ATTACK1, RANGE_ATTACK2 |
| 30–39 | MELEE_ATTACK1, MELEE_ATTACK2, RELOAD, ARM, DISARM, EAT, DIESIMPLE, DIEBACKWARD, DIEFORWARD, DIEVIOLENT |
| 40–49 | BARNACLE_HIT, BARNACLE_PULL, BARNACLE_CHOMP, BARNACLE_CHEW, SLEEP, INSPECT_FLOOR, INSPECT_WALL, IDLE_ANGRY, WALK_HURT, RUN_HURT |
| 50–59 | HOVER, GLIDE, FLY_LEFT, FLY_RIGHT, DETECT_SCENT, SNIFF, BITE, THREAT_DISPLAY, FEAR_DISPLAY, EXCITED |
| 60–69 | SPECIAL_ATTACK1, SPECIAL_ATTACK2, COMBAT_IDLE, WALK_SCARED, RUN_SCARED, VICTORY_DANCE, DIE_HEADSHOT, DIE_CHESTSHOT, DIE_GUTSHOT, DIE_BACKSHOT |
| 70–76 | FLINCH_HEAD, FLINCH_CHEST, FLINCH_STOMACH, FLINCH_LEFTARM, FLINCH_RIGHTARM, FLINCH_LEFTLEG, FLINCH_RIGHTLEG |
Pivots
numpivots records of 20 bytes at pivotindex
(mstudiopivot_t): points a foot stays planted on for a span of
frames.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 12 | float32[3] | org | Pivot point |
| 12 | 4 | int32 | start | First frame, counted from the sequence’s first stored frame |
| 16 | 4 | int32 | end | Last frame |
Animation data
At animindex, in the file of the sequence’s group, are
numblends × numbones records of 12 bytes
(mstudioanim_t): all the bones for blend 0, then all for blend 1, and so
on.
| Offset | Size | Type | Name | Meaning |
|---|---|---|---|---|
| 0 | 12 | uint16[6] | offset | For x, y, z, x rotation, y rotation, z rotation: where that channel’s values start, counted from the start of this record; 0 means the channel does not move |
A channel with offset 0 keeps the bone’s default value in every frame.
Otherwise its frames are run-length coded in 16-bit slots
(mstudioanimvalue_t). Each run starts with a slot read as two bytes,
valid then total, followed by valid slots read as
signed 16-bit values:
- The run covers
totalframes. - Its first
validframes take the values in order. - The remaining
total−validframes repeat the last value. - The next run starts right after the last value,
valid+ 1 slots on.
A raw value r of channel j becomes
value[j] + r × scale[j], using the bone’s fields.
Rotations are Euler angles in radians. The renderer then adds any bone controller’s
adjustment and blends between neighbouring frames.
Worked example: a channel whose data is 03 05 0A 00 14 00 1E 00 is one
run with valid 3 and total 5. Frames 0, 1 and 2 have the raw
values 10, 20 and 30, and frames 3 and 4 keep 30. With value 0 and
scale 0.5 the positions are 5, 10, 15, 15 and 15.
Blends
With two blends the renderer mixes blend 0 and blend 1 by the entity’s first blending byte ÷ 255. With four, it mixes blends 0 and 1, and 2 and 3, by the first byte, then the two results by the second. Rotations are mixed as quaternions along the shorter way round, positions in a straight line.
Between two frames
At a time between frame f and the next, with fraction s, the SDK’s renderers take a second value for each channel:
- If f is among a run’s stored values and another stored value follows, that one.
- If the next frame belongs to the run’s repeated tail, the same value.
- If the run ends at f, the first value of the next run. One exception: when f is the last stored value of a run with no repeated tail, a position channel holds its value while a rotation channel moves on.
The two sets of Euler angles become quaternions, mixed by s along the
shorter way round; the two positions are mixed in a straight line. The game renderer
also guards against a run whose total is less than its
valid, taking the run’s start instead. After this, the position of the
bone motionbone is set to 0 on each axis named by STUDIO_X,
STUDIO_Y or STUDIO_Z in motiontype. How the
local rotations and positions become bone matrices is described with the
skeleton.
Playing a sequence
In the SDK’s game renderer the frame is the entity’s frame setting (0 to 256) ×
(numframes − 1) ÷ 256, plus the time since it was set × the entity’s rate ×
fps. A looping sequence wraps round every numframes − 1
frames; another stops just short of its last frame (numframes − 1.001). A
sequence of one frame or none stays at 0. The SDK’s model viewer always wraps, and
advances at most a tenth of a second at a time. The speed the game takes from a
sequence is the length of linearmovement × fps ÷
(numframes − 1).
The game renderer adds three mixes of its own. After a change of sequence it fades
from the old pose to the new over 0.2 seconds. For a player model, a second “gait”
sequence moves the legs: bones take its pose from the start of the bone list, until
the bone named Bip01 Spine, and again from a bone whose parent is
Bip01 Pelvis. And a player’s aim sets the first blend byte from the view
pitch: with b = three times the pitch, below blendstart[0] the
byte is 0, above blendend[0] it is 255, and between them 255 ×
(b − start) ÷ (end − start), or 127 if the two are less than 0.1 apart; the
pitch the model is drawn with is reduced by what the blend covers.