Birdoggydog's Builds

Animating rebuilt heads with a face rig in Godot

Thirteen new heads with a 14-bone face rig, then a script that blinks, glances and snarls them in the game, six orc heads by type and bodies tinted to match.

Every head in the game was rebuilt, and now the faces move. Monsters blink every 2 to 5 seconds, glance aside, put their brows down when they’ve seen the party and snarl as it closes. A hit makes a face flinch, and a dead face goes slack and stays that way. Six different orc heads are in use, picked by the monster’s type, and the body under a head now takes that head’s skin color.

61 seconds in the game, captioned. Five orc types in a corridor with their heads, blinks and glances, a snarl closing from 6 m, the body’s hide with and without the tint, a hit and a kill, an NPC left alone, three human figures and a husk.

Why did the heads need rebuilding?

I wanted a study of faces like the one I’d done for bodies, because the heads were the weak point once the bodies got better. The study ran in three rounds. In the first I tried four approaches on a human and an orc each: bigger eyes with brows and fuller lips, a bone rig with weights worked out from distance, both together, and a head cut from MakeHuman’s CC0 base mesh. The MakeHuman head was a person up close, but at 5 m and 12 m it read no better than the heads I had, and cutting it down to 1,600 triangles broke the lids. I said no to it, and yes to the bigger eyes and the bone rig.

The second round was twelve new faces, six human and six orc. I kept all six orcs and three of the humans (the foreman, the cutter and the boy). It also turned up a bug in the kit, and it showed that the time of day matters. At noon an upright face takes a third of the sun and everything under the brow goes sky-lit gray, so I judge faces at 15:30.

46 seconds in the game. The old heads beside the new ones, at the distances the game shows them.

The bug: the kit left out a lift that it stands the head mesh up by, so every blob painted on a head (socket shadows, brows, the light on a lip) landed 110 to 192 mm too low, and the rig turned the lids and jaw about points that far under them. After the fix they’re 0.0 to 2.8 mm off.

The third round was about why an orc reads at a distance and a human doesn’t. I measured the spread of light and dark over the face at 12 m. An orc was 20.8. The same orc painted one flat tone was 20.7, so paint lost nothing. With the tusks and ears off it was a green ball. A bald human was 14.9, skin color alone didn’t help (15.0), raised brows alone gave 15.2, hair alone 17.4, and all three together 19.7. A human’s hair does the job an orc’s ears and tusks do. So the answer was form and frame, not paint, and hair became the next thing to build.

Rows of heads at four distances. A bald human stays a pale blur at 12 m, a human with hair gets a dark cap that stands out, and an orc stays readable even painted one flat color.

Why an orc reads and a human doesn’t, one change at a time, close up, at 5 m, at 12 m and as an outline.

How does the face rig work?

Each head has 14 bones after the head bone: the jaw, two eyes, upper and lower lids, brows, mouth corners and lips. The kit finds the face’s landmarks on the skin, then gives each point a weight for each bone from its distance to the bone’s segment. Nothing is painted by hand, so the rig fits any head the kit makes. An orc got the human’s rig with no change.

There are nine face clips per head, named face_<pose>: blink, look left, look right, look up, brows up, brows down, open, smile and snarl. Each is 30 frames with key times 1, 8, 22 and 31, so it’s at rest, holds the pose from frame 8 to 22 and goes back to rest. They have tracks for the face’s bones only, plus the jaw in open, smile and snarl. That’s what lets the game play a face clip over the body’s clip.

The rig costs no triangles. The kit removes any triangle that no eye can reach, at rest or in any pose. The heads came out at 1,187 to 1,650 triangles each, against 1,239 to 1,329 for the old ones. I also gave the brows their own material as a flat strip about 48 triangles, so the game can lay a hair color over them, and each head writes a small scalp file that a hair generator needs.

Laying a face clip over a body clip

A head already follows its body’s clip through its own animation player, which is seeked each frame and poses all 14 bones. I looked at two ways of adding the face and picked a third. A second animation player would fight the first for the jaw. An animation tree would blend every track of every clip, for every head, every frame.

So FaceLife sets bones by hand. It reads each head file’s nine clips once, at 0.5 seconds in, and keeps each pose as one rotation per bone from its rest. Then each frame, every bone is set to its base times the product of identity.slerp(turn, weight) over the poses that have a weight. The base is the bone’s rest, except for the jaw. Its base is wherever the body’s clip just put it, so a snarl lands on an attack’s bite or a death’s gape instead of replacing it. The node is the head’s last child, so it runs after the head’s player has posed it.

The timings are all game seconds, read from GameClock, so a pause stops them. A blink starts every 2 to 5 seconds, takes 0.09 to shut and 0.17 to open. A glance comes every 2.5 to 7 seconds, held 0.5 to 1.6, in one of five directions. Each face has its own random generator seeded from what it is or where it stands, so nothing touches the game’s dice. If the clock jumps, as in a rest, a face doesn’t owe the blinks it skipped.

A monster that knows where the party is puts its brow down and its eyes on the party, and snarls from 6 m, whole at 1.5 m. A hit plays a flinch, with the blink at full, the mouth open a little more than half and the brows up. An NPC being talked to looks at the party and raises its brow a little. It never snarls, and since there’s no look-down clip it follows the party up but not down.

Faces cost nothing when they don’t have to. Corpses and husks never process. Every quarter of a second, a face asks whether its monster is alive, whether the head is visible and whether the camera is within 18 m. If any answer is no, it goes to sleep, sets no bones and only asks again once a second. In a test, 40 faces awake and all watching the party cost 0.42 to 0.49 ms per frame, and 40 asleep cost 0.06 ms.

Choosing one of six orc heads

The six orc heads are the brute, the hunter, the old scarred one, the matriarch, the tusker and the whelp. A monster’s type picks its head where a type suits a face. The Slab Warden, a wall that stands guard, gets the brute or the tusker. The Rind Stalker gets the lean hunter, the Bile Seer the old scar, the Marrow Mender the matriarch, and the Gristle Spitter the whelp. Anything else, like the Suet Auditor, takes any of the six.

Which of two, or which of six, is settled by where the monster is first stood, to a tenth of a meter, hashed and mixed. I didn’t use its id, because its body is made before whatever placed it has named it. A plain string hash also put names that differ in the last figure on heads in a row, so the hash is mixed. Nothing is rolled, so no test’s or save’s numbers moved, and the monster keeps its head through a save and load and on its corpse. Over 600 places for a type with no row, the six heads came out 104, 98, 111, 99, 96 and 92.

Matching a body’s hide to its head

A head can now have its own skin color, and the body under it has to follow. Each head’s manifest gives its face color and the race’s hide color, which the neck is painted with. The tint is the face’s color divided by the hide’s, a channel at a time. It’s carried as vertex colors on a copy of each body mesh, and nothing has to be rebuilt or repainted. A vertex color is only 8 bits, so a tint over 1 is stored as a share of its biggest channel and the material’s color brings the rest.

I used vertex colors because the code that washes a corpse or tints an NPC copies the material and changes its color. With head and body on the same material color, a wash changes both and they still meet. The head also needs its neck ring tinted, so the kit’s ring is tinted where it was painted, whole at the stub’s end and fading out over 1.3 neck radii.

The first version made the orc’s red and purple patches redder and more purple than they were painted, because the hunter’s tint lifts red and blue more than green. The orc body’s picture is 56 percent hide-colored, 34 percent red and 10 percent purple. So a point whose texel isn’t hide-colored now takes only the tint’s brightness, and a hide-colored point takes the whole thing. Under the hunter’s head, 1,090 of 2,210 points take the whole tint and 701 take its brightness only.

At the neck, the tinted body and the head’s ring were within 0.06 in every channel for all nine heads I checked, from 0.008 for the boy to 0.056 for the foreman.

Eight game screenshots in a grid. Orcs in a corridor, a close-up of an orc with a snarl, a body with a green tint, a monster in a cloud of poison, a bald NPC, three humans in a row and a husk on the floor.

Eight stills from the film above, each with its caption.

What’s still wrong?

The two gray-headed orcs’ bodies still look gray-brown, because the body’s picture is browner than the hide its neck is painted. The hide under the hunter goes from 0.95 to 1.15 in red against green where the face is 0.96, and only a repaint fixes that. Husks in an imported dungeon take any of the six heads and not their type’s, a thrall wears head 01, and a corpse lies face down so its still face is barely seen.

The heads are still trials until I’ve seen them, and hair is a trial too. The study built eight styles and three beards from the scalp file alone, each a shell with its edge sunk 6 mm under the skin, 108 to 254 triangles apiece, and I kept all eight styles. Orcs go bald. Hair isn’t in the kit yet.

58 seconds in the game. Round three of the study, with hair as a part hung on a head, eight styles.