garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/makehuman-avatars.md

raw


topic: makehuman-avatars triggers: [crates/human, crowd.rs, crowd_pose.wesl, CrowdMaterial, CrowdSwatch, starter_looks, AvatarLook, SetAvatarLook, AvatarLookOf, RemoteLooks, looks.rs, V38__avatar_looks.sql, net/look.rs, systems::human_avatar, human_avatar.rs, avatar_designer.rs, HumanLook, CARTO_HUMAN_LOOK, aim_height, human-pack, default.humanpack, assets/models/avatar/human, mocap.rs, rig.rs, hands.rs, level_gaze, HumanTextureLoader, HumanNormalLoader, nrm.avatar, avatar.jpg, PACK_VERSION, ProxyRef, MakeHuman, MPFB, 100STYLE, CMU, BVH, from_stored, skin_tone, extras, aim_reach, aim_screen, DesignerTurn] updated: 2026-11-26

Realistic avatars are MakeHuman bodies built at runtime

Every avatar is a person built in the client from MakeHuman's data: the base mesh, the shape targets the sliders blend, the game_engine rig and its weights, and clothes and hair as fitting rules. crates/human does the arithmetic (Bevy-free); systems::human_avatar turns the result into joints, skinned meshes and clips. It replaced the stylised Quaternius characters (retired/quaternius-avatars.md), whose only choice was a costume, on 2026-10-18; there is no switch back.

Why MakeHuman, and what lost (2026-10-17)

MPFB's maintainer advised exactly this shape for a Bevy game (makehumancommunity/mpfb2#381): parse the native files rather than push 1 200 mutually exclusive shape keys through glTF.

The pack

human-pack (crates/human/src/bin, feature pack) reads the sources and writes assets/models/avatar/human/default.humanpack (postcard) plus the textures beside it. Sources: mpfb2's src/mpfb/data, the MakeHuman system assets zip (files2.makehumancommunity.org/asset_packs/makehuman_system_assets/), and motion capture: 100STYLE's Neutral style (zenodo.org/records/8127870, CC BY 4.0) for the idle, and the CMU database's cgspeed BVH (github.com/una-dinosauria/cmu-mocap, free for all uses but not for resale) for the walk, the run, the gestures and the seat. The cuts — which take, which frames — are listed in human-pack.

The pack carries every macro target (TargetSet::Macros), so the sliders can make any adult. That is most of it; one body needs about 30 of the 516, so fetching a body's targets on demand is the next step if it must get smaller. HumanModel::missing_targets is how a body asked of a pack without them says so.

Pack 7 nearly halved it losslessly (2026-10-18): 13.9 MB to 8.0 MB. Measured field by field before: the 786 targets 10.26 MB, the clothing references 2.85 MB, the mesh 0.49, the clips 0.19, the weights 0.11. The targets became differenced columns (Target's doc has the table — 5.13 MB, same numbers); the clothing references whole steps instead of f32s (ProxyRef). Trap: MakeHuman's reference weights go past 2 (up to 5.1, in a bob haircut; every pair of shoes is 3.5), so an i16 at 1/16384 clipped them, and the clipped shoes stood a grey spike out behind the legs. They are i32, which postcard writes in the same three bytes. The textures went from 9.9 MB to 7.5 MB by storing the grey (neutral) ones as one channel, plus alpha where they cut out.

Measured 2026-10-17 on mac-1: the pack was 11.1 MB (13.6 MB from 2026-10-18 with the wardrobe and the face, plus 9.9 MB of textures) — ten clips and all 516 macro targets from age 18 up (the "child" ones blend in below 25; only the baby ones are left out), stored as half-millimetre steps and deflated, where floats were 70 MB —, the nine 2048² PNG textures 19 MB (too big for a phone; downscale and compress before this ships). The default man is 1.73 m, 18 700 vertices and 33 000 triangles across body, eyes, brows, lashes, hair, outfit and shoes — the Quaternius Adventurer file is about 20 000 vertices. build took about 10 ms in the test profile.

Facts the code depends on

The designer

The Appearance panel is systems::avatar_designer (docs/mockups/avatar-designer). A look is cartopolis_core::AvatarLook (the client calls it HumanLook): whole percents, RGB bytes and names, so it compares exactly and travels in about 150 bytes. While the panel is open the avatar wears the draft (HumanDraft) and closing it unsaved puts the saved look back. It opens on taps, not sliders: eight starters and "Surprise me", a row of quick picks each for body shape, age, build (weight and muscle together) and height, and "Another face"; the sliders sit under "Fine-tune" and the face parts.

A changed look is swapped in, never rebuilt in place (HumanRebuild, 2026-10-19). The body is built on a worker (prepare_human), spawned with its meshes hidden beside the old one, and shown — the old one despawned in the same frame — once its textures are in and two more frames have let its meshes reach the GPU; its clip starts where the old body's was (avatar::animate_holder). Before, a rebuild despawned the body and built the next on the following frame: the body vanished on every slider step until its meshes were up, came back white while any texture dropped with the old materials was re-encoded, and restarted its clip — the flicker the designer had. A change of colour alone (hair, top, bottom) repaints the materials and builds nothing (same_body). One build per avatar at a time, at most every 0.1 s, each about 1.5 MB of mesh uploads; the designer keeps every texture it has shown (HumanTextures) until it closes, so going back to a skin or hair is not another 350 ms encode. Another player's new look goes through the same swap.

Three things it does so the avatar can be seen while it is shaped:

CARTO_HUMAN_LOOK="body_shape=0,weight=90,age=70" starts an undesigned avatar with those sliders, for a capture, which cannot drag one. It takes the wardrobe and face too (hair=afro01,top=150.40.40,face:nose/…=80).

Everyone sees everyone's look (protocol 42)

A client sends SetAvatarLook on every new connection and whenever its saved look changes (never while it has not designed one: then nothing is kept and everyone, itself included, draws the default body). The server checks it is reasonable (AvatarLook::is_reasonable: sliders in range, age 18–90, short names, a bounded face list — not whether the names exist, which is the client pack's business), keeps it with the account (accounts.look, postcard bytes, migration V38), wears it in the world and broadcasts AvatarLookOf { avatar_id, look } on the world channel. A client that connects is handed every online look before the snapshot that brings the avatars, and its own saved look is worn and broadcast without it sending anything. Only the avatar id travels, never the account: who an avatar is stays something a client asks.

On the client a look lives in RemoteLooks by sim id, not on RemoteAvatar, because it arrives before the avatar's snapshot. A look that changes after a model is built rebuilds it; the same look again (it is re-sent on every connection) does not. At most one MakeHuman body is built a frame, so a crowd coming into view is built over a few frames rather than in one hitch.

Protocol 42, message kinds 121 and 122 and migration V38 were reserved through midas reserve on 2026-10-18, after the meetings work took 41, 111–120 and V37.

The wardrobe, the skins and the face (2026-10-18)

From MakeHuman's CC0 system assets: 10 hair styles, 5 brows, 7 outfits, 5 shoes, a hat, 6 eye colours, and all 18 skins (African, Asian and Caucasian, young, middle-aged and old, female and male — a look picks the family, its age and body shape pick the skin). Left out on purpose: every outfit printed with MakeHuman's logo (female_casualsuit01/02, male_casualsuit02/04/06, the T-shirt the first trial wore): the assets are free, the trademark is not ours to put on everyone's shirt.

Recolouring needs neutral textures (human::textures): a tint multiplies, so over an authored texture it can only darken. Hair, brows, lashes and outfits are stored as their luminance over the texture's bright end, in grey, with the colour that gives the authored look back recorded per region; any colour, lighter ones included, is then a tint. An outfit is split into a top and a bottom by texture island — a suit is one mesh, but its shirt and trousers are separate islands — and an island whose middle is below the hip joint is the bottom. Splitting by skin weight first put a pair of overalls, bib and all, on top.

Textures went from 19 MB to 9.9 MB while tripling the wardrobe: 1024 px for skins and garments, 512 for hair and brows, 256 for eyes, JPEG unless the alpha really cuts something out. MakeHuman marks most garments transparent whether or not they are, which made every outfit a 1.5 MB PNG; the pack now looks at the alpha. The client needed Bevy's jpeg feature, whose decoder the image crate already built.

On the GPU they are block-compressed, with mips (HumanTextureLoader, reusing the map tiles' encoder): the default man's seven textures went from 16.0 MB of RGBA8 to 5.3 MB. What routes a file to that loader rather than Bevy's is its inner extension: every pack texture is *.avatar.jpg or *.avatar.png (textures::TEXTURE_EXTENSION), and Bevy tries a file's full extension before its last one. A texture written as plain .jpg still loads — uncompressed, with no error to say so.

The face is MakeHuman's modifiers, carried whole (about 110 controls, 270 targets, 0.1 MB of the pack); the designer offers about thirty. A modifier is a pair of target sets by sign, a left-and-right one moving both sides; a one-sided one (head-oval) goes 0 to 1. Face values are stored as a sparse list, so an untouched face costs nothing.

Detail and a more personal look (pack 9, protocol 45, 2026-10-27)

Trap: postcard gives no serde default to a field missing at the end. accounts.look is postcard bytes, and a look saved before protocol 45 ends before skin_tone; from_bytes fails rather than defaulting, and the old load turned that into "no look" — every saved avatar would have come back as the default body. AvatarLook::from_stored reads each older layout (AvatarLookV42, frozen) and carries it forward; the next field added needs the next frozen layout. The client's own copy is JSON, where defaults work.

The crowd: the street walkers are these people too (2026-11-04)

The walkers systems::traffic moves (220 at most) are MakeHuman bodies, made by cartopolis_human::crowd and drawn by systems::crowd. An avatar would not do: ~33 000 triangles, ~5 MB of textures and a skeleton animated every frame each, so 220 of them is ~7 M triangles before shadows. A crowd body is:

Measured 2026-11-04 on vps-1 (debug build): the fourteen bodies took 2.6 s of worker time to shape, 11.1 s to cut and bake, and 2.0 s to decode swatches, and upload 0.7–1.6 MB each (12 MB in all, meshes and pose textures); the release-built test cuts one body in 0.43 s. Every walker wearing a body shares its mesh and material, so the crowd is at most 28 instanced draws, and nothing is uploaded once it is made. A walker whose body is not made yet walks unseen. Not measured: frame time on the phone. The worst case is 220 × 3 000 triangles if every walker were near; at a street's usual few dozen near, it is ~100–200 k.

Rejected: Quaternius's animation library (2026-10-17)

The first retarget used Quaternius's Universal Animation Library. Quaternius moved to a licence forbidding redistribution on 2026-08-28, and LICENSE-THIRD-PARTY.md bars anything downloaded from them since; the March 2025 CC0 release on OpenGameArt was arguably exempt, but motion capture was the better answer anyway — real motion suits a realistic body better than hand-keyed clips — and no commit on the branch ever carried a pack made from the library. Mixamo (no redistribution), Bandai Namco's set and LAFAN1 (non-commercial) and SFU's (no commercial products) were ruled out on licence.

What code adds on top of the capture (2026-10-18)

The greetings and the throw (pack 2026-11-15)

Three CMU cuts, added to the shipped pack by human-pack --add-clip PACK CMU_DIR NAME… (the generalised --add-swim: it cuts the named clips exactly as cmu_cuts lists them, so a full rebuild cuts them the same way):

Both greeting takes are two people walking up to each other, and the walk is not wanted. Cut::plant holds the hips and legs at one frame (the contact) through the whole clip and keeps the trunk's turn in the room as captured, so the gesture is made standing where it lands. Keeping the hips' captured travel instead slid the body 0.4 m over frozen feet in the approach; held, the hands stay within 0.1 m of where they met through the shake (measured on the take, frames 90–170) because the subjects barely move then.

Both avatars play one subject's clip, stood point-symmetric by the sim (paired-gestures.md), so the partner offset is twice the palm's reach at contact on the default man — --add-clip prints it, cartopolis_core::greet carries it, and greetings_meet_halfway holds the pack to it.

Grips (hands::grip_for): half closed for the handshake (a fist read as a punch), flat for the high five, round the ball for the throw.

clothes_do_not_spike passes on all three with every outfit, and standing_clips_put_the_soles_on_the_ground and upright_clips_keep_the_shoulders_down include them, but for the high five and the throw in the shoulders test: a hand raised over the head lifts its shoulder by design, as the wave's does (the throw's averages 2 mm above rest, where the test wants 5–50 mm below).

The climb and the dangle (pack 2026-11-15)

Two more CMU cuts by --add-clip, for climbing onto walls and sitting on edges (climbing-and-edges.md). --add-clip prints, for these, the numbers the client lifts by (measure_climb_and_seat), and build::lowest_sole / build::seat_height are the measures.

Excuses, measured: the female elegant suit's skirt stretches 5.1 cm in the climb's raised knee (clothes_do_not_spike, beside its stride's); the dangle props the shoulders up 2 mm above rest, as sitting with the hands on an edge does (upright_clips_keep_the_shoulders_down). The pack grew from 12 099 KB to 12 123 KB.

Known gaps: 100STYLE is all locomotion (CMU supplies the gestures), no faint in CMU (a slip-and-fall stands in), the waving hand is the only one that opens on purpose (both hands share the clip's grip), and the --clip sheet's first tile sometimes catches the city before it has loaded.