BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

What goes into an animation

A soldier or hero is skinned to a skeleton, a .ske file of named nodes in a bind pose. Every movement is a .baf file that stores, per animated node, seven compressed tracks: a rotation quaternion and a position, 24 frames per second. The engine samples the tracks at the current time, blends the layers of every node and multiplies the result down the tree.

BF22142Heroes

The skeleton#

A .ske (version 2) is a node list: name, parent index (-1 for a root), a local rotation quaternion x, y, z, w and a position relative to the parent. Parents always come before their children. The loader (Skeleton::load, BF2.exe!0x007f57b0) lowercases the names, snaps components below 0.001 to zero, gives nodes whose name contains mesh the identity, and builds the local matrices; bf2-anim reproduces those rules in SkeletonNode::retail_bind_rotation / retail_bind_position and SkeletonPose::from_skeleton. The skinned meshes of the mesh page refer to these nodes by index: every item a hero wears is skinned to the same skeleton, which is why separately made items fit together.

The animation file#

A .baf (version 4) names the skeleton nodes it animates (bone_ids), the frame count and the position precision, then one block per node with seven tracks (rotation x, y, z, w, position x, y, z). A track is a chain of run-length blocks of 16-bit words: a header word holds the frame count (bits 0-6), a repeat flag (bit 7) and the distance to the next header (bits 8-15); a repeat block stores one value for all its frames, a literal block one value per frame. Rotations decode as raw * 1/32767, positions as raw / (2^precision - 1) (layout and retail evidence: notes/formats/animation.md; reader crates/bf2-anim/src/baf.rs, BoneAnimation::parse / decode).

A Heroes hero's skeleton posed by the cheer emote. Top: the bind pose and six sampled poses. Bottom left: the rightarm node's rotation, the decoded frames as dots and the sampler's slerp between them as lines. Bottom right: which tracks store a value per frame; everything dark is a single repeated value.
A Heroes hero's skeleton posed by the cheer emote. Top: the bind pose and six sampled poses. Bottom left: the rightarm node's rotation, the decoded frames as dots and the sampler's slerp between them as lines. Bottom right: which tracks store a value per frame; everything dark is a single repeated value.

What the picture shows: the arm's rotation tracks are literal (a value every frame) while its position tracks are one repeat block each, because the arm does not stretch; across all 53 animated nodes most values are repeats. The skeleton strip is drawn by our own sampler: every animated node sampled with Clip::sample, written into the pose, then SkeletonPose::update_world multiplies the local matrices down the tree.

Sampling and blending#

StepWhat happensbf2-rsOriginal
frame pairx = time / length, looping or clamped, two frames and a fraction (frames * 0.041666668 s per file)sample.rs frame_pairBoneAnimation::sample bf2_w32ded.exe!0x007206e0
decodewalk the run-length chain to the frame, scale the wordsample.rs Clip::value, baf.rs Track::raw0x00723b20 (rotation 0x00723be0, position 0x00723c30)
interpolateshortest-path slerp of the two quaternions, lerp of the positionssample.rs slerp, lerpQuaternion::slerp 0x0068d630
blend layersa few layers per node (BF2 five, 2142 and Heroes ten); a weight-1 layer replaces the earlier ones, lighter ones slerp onto them; a total weight below 1 blends with the current posepose.rs SkeletonPose::update_from_animations, sample.rs blend_boneSkeleton::updateFromAnimations 0x00716fc0
worldlocal * parent_world from the roots downpose.rs SkeletonPose::update_world0x00717460

The animation scripts (.inc files with animationSystem.createAnimation and the triggers that pick a bundle per stance, speed and weapon) are the data model of crates/bf2-anim/src/system/; soldiers have their own driver in soldier.rs, ragdolls in ragdoll/.

Why the client and the server decode differently#

The whole sampler runs on the x87 FPU. The client's Direct3D 9 device switches the FPU to single precision (created without D3DCREATE_FPU_PRESERVE, RendDX9.dll!0x1000a650), the dedicated server keeps the CRT's double precision. Rotations decode the same either way, but positions are fild / fdivr / fimul on the FPU stack: on the retail data 1,914,523 of 33,145,707 position values differ in the last bit between the two. bf2-anim takes the mode as an argument (X87Precision::Single for the client, Double for the server) and reproduces every rounding step, verified bit for bit against the retail functions (notes/subsystems/animation.md).

Per game#

BF22142Heroes 1.126
soldier skeletons1p_setup.ske (70 nodes) and 3p_setup.ske (80 nodes), 16 mesh* nodes eachthe same schemebritish_male_soldier.ske / german_male_soldier.ske in Soldiers_server.zip: 74 nodes with face, cloak and bag bones, no mesh nodes
animations7,363 .baf (precision 12-15)2142's own set, same format2,657 .baf in the two skeletons' Animations folders (weapons, vehicles, emotes)
loaderBF2.exe!0x007f57b0, 0x007fd1f0BF2142.exe!0x008b8c60: BF2's codedecode copies BFHeroes.exe@bfh126!0x00b19d9c / 0x00b19e50 / 0x00b19e8d: same behaviour
blendingfive layers per node (BF2.exe!0x007f2f60)ten (BF2142.exe!0x008b6430); BF2's world update (BF2142.exe!0x008b8880); 2142's system additions in system/new_2142.rs2142's ten; ignoreMotherOrientation turns the parent chain first (BFHeroes.exe@bfh126!0x00b076c2, pose.rs heroes_mother_turn); a two-animation layer tests each animation on its own (0x00b08325)

How it is tested#

  • The original computes the expected values (crates/bf2-anim/tests/oracle.rs): the original's matrix and quaternion primitives, skeleton poses, trigger trees, bundle playback and sampler are run in a process of their own, and the port must give the same output bit for bit (the oracle).
  • Pose evaluation (crates/bf2-anim/src/pose.rs): which layer reaches which bones, the records per node in each game.
  • Per game: 2142's animation system update is tested arm by arm in a 2142 process; Heroes' removal of an animation and its thrown weapon's animation each have a test program written from the 1.126 listing.

Eight of this page's nineteen addresses stand in a test's own text. The other eleven have no test that names them.

Where it is read and drawn#

Stepbf2-rs
parse .ske / .bafbf2-anim ske.rs Skeleton::parse, baf.rs BoneAnimation::parse
sample, blend, world posebf2-anim sample.rs Clip, pose.rs SkeletonPose
skinning on the GPUbf2-render skinned.rs (bone matrices times the rig's inverse bind pose)
the picturecrates/bf2-anim/examples/anim_json.rs

The skinned meshes are drawn in stage 6 of the render pipeline; the files come out of the archives described on archives and the file system.

Source: docs/dev/assets/animation.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.