The puppet from step 38 stands on a turntable in a dressing room and tries things on: a straw hat, a blue coat with tails, riding boots, a backpack, a wanderer's staff. Every piece hangs on the puppet's bones or on a named point of them, an anchor, so the clothes run, jump and wave with it. The toolbox learns clothes for its cut-out puppets: wardrobes as plain data, outfits as plain data, and a drawing order that the data decides.
Play it · Source: collection-spielwerk/39-kleiderschrank · Toolbox 6.2.0 or later
The game
There is nothing to win. The wardrobe has five drawers: hats, tops, trousers, shoes and accessories, 29 pieces in all. Click a piece and the puppet wears it; whatever was in that place comes off. Click it again and it comes off too. "Zufall" dresses the puppet at random, "Ausziehen" takes everything off. Three slots keep outfits: "Merken" keeps what the puppet wears now, "Anziehen" puts it back on, also after a reload (on the desktop they are files in /saves/tce-kleiderschrank/).
The puppet never stands still for long. The keys under the stage play its clips, standing, walking, running, jumping and waving, all on the spot, so you see a coat's tails swing with the thighs and a sword stay in the hand. "Anker" shows the points the pieces hang on. "Haut" puts the gardener from step 38 under the same clothes. "Drehen" turns the turntable round.
- Mouse or touch: the drawers, the pieces, the keys.
- Keyboard: 1 to 5 open the drawers, R dresses at random, U undresses, N shows the anchors, H swaps the skin, T turns, C plays the next clip, M mutes. A gamepad works too.
New in the toolbox: clothes on anchors
The problem. Step 38's puppets are a set of parts on a skeleton. A second set of parts makes another person, but a hat on top of a person is neither: it has to go onto any puppet of that skeleton, together with whatever else it wears, and in front of the right things. A coat is harder still. As one picture it would stand stiff while the arms swing.
The idea. A wardrobe is a second atlas for every puppet of one skeleton, with a rig that holds no bones, only pieces. Each piece is worn in a place (hat, top, trousers, shoes, belt, back, hand_l, hand_r), one piece per place. A piece has one part or several:
- A hat is one part on the anchor
head_top; a sword is one part onhand_r. Anchors are named points on the rig's bones, now with an angle: the hat's pivot sits on the anchor and turns as the head turns. - A coat is seven parts, each on its bone: the torso, two sleeve parts per arm and two tails on the thighs. The coat follows the run because its pieces do.
The drawing order is data. A part is drawn, by default, just in front of its bone's own part: a sleeve over the arm. The data can say behind a slot (a backpack behind the far thigh, a staff behind the hand that grips it), in_front_of another one, or slot, drawn instead of the body's part there. Where two pieces meet at one spot, the place's layer decides: trousers under boots under the coat. The puppet sorts this once when the outfit changes, never per frame; puppet.drawing_order is the same list until the next change, which makes the order easy to test.
Outfits are data too. { hat: "straw-hat", top: "blue-coat", shoes: "tall-boots" } is all the save slots keep. A game needs a few lines:
const hero = this.load_puppet("wanderer");
hero.use_wardrobe(this.load_wardrobe("clothes")); // catalogue_images: { clothes: "rendered/puppet/clothes" }
hero.set_outfit({ hat: "straw-hat", top: "blue-coat" }); // worn as soon as the wardrobe has come
hero.wear("top-hat"); // the straw hat comes off
hero.take_off("top"); // a place, or a piece's id
save(hero.outfit);
const hand = hero.anchor_world("hand_r", x, floor_y, { scale, flip_x }); // { x, y, rotation }: a spark at the sword
Every change sends one OutfitEvent (what came on, what came off), which is where the "Strohhut an" under the stage comes from. A piece that doesn't fit, one for an anchor the rig lacks or for another skeleton, is refused, and fit_problems(id) says why in words. The drawers' pictures are the toolbox too: a puppet wearing only that piece, drawn with only_clothes and framed with bounds(id).
The art. All 29 pieces come from one Blender script (39-kleiderschrank/clothes__blender/build.sh), built on step 38's figures and skeleton and rendered the same way: from the side, part by part, with the same toon shading and outline. Hats are made from turned profiles, stripes and tartan are patterns in world space so they line up across a coat's parts, and every covering part is rendered on its own bone. The clothes are sized for the larger of the two skins, and the build measures them: for every part that covers the body, how much of the wanderer's and the gardener's part beneath it hides (two thirds hide all of it, the gathered shins of the baggy trousers the least, 81 percent; shorts, the kilt and short sleeves cover part of a limb on purpose). Both wardrobes go into the asset library as rendered/puppet/clothes and rendered/puppet/accessories.
What it costs. Measured in Node 22 (Intel i7-11700F): 1 000 running puppets, half of them in an outfit of six pieces (35 parts instead of 15), update in 0.63 ms and lay out their draw calls in 0.25 ms; changing an outfit, with its one sort and the first draw, takes about 18 µs. Clothes cost what their parts cost to draw (one transform and one drawImage each, as in step 38) and nothing per frame besides.
Tests. The toolbox checks a hat on head_top through the whole run, a sleeve on its arm at every key, a pinned drawing order before and after an outfit change and that it is sorted once per change, the events, a piece for a missing anchor refused, a wardrobe that arrives after the outfit, two wardrobes on one puppet, a mirrored anchor, and an outfit through SaveSlots. The game checks that every piece fits both skins, that random outfits with every place filled keep to the order rules, that a saved look loads into exactly the same drawing, and the turntable, the drawers and the slots. The browser check clicks a piece of each kind on and off, dresses three times at random, saves and loads a slot, and shows the anchors.
The modules are in src/canvas/puppet/ (Wardrobe.ts, Puppet.ts); the docs are the "Clothes on anchors" section of docs/puppet.md.
From earlier steps
- The puppets, their clips and reskinning from step 38; the clothes need nothing new from the clips.
SaveSlotsfrom step 35: the three slots, kept as files on the desktop.- The catalogue hook from step 32:
load_wardrobecomes through it asload_puppetdid. - The
ActionMapfrom step 30: keys and a gamepad.
The scaffold, start screen, intro and scaling are explained in Spielwerk 00: The workbench.
Embed it
<script src="https://www.game-object.de/tce-elements/tobidot/dll-tce-assets"></script>
<script src="https://www.game-object.de/tce-elements/tobidot/tce-kleiderschrank"></script>
<tce-kleiderschrank></tce-kleiderschrank>
| Attribute | Values | Default |
|---|---|---|
init-seed |
whole number: what "Zufall" picks | random |
init-intro |
true / false: play the GO logo intro |
true |
Next
Previous: Spielwerk 38: Puppenspieler · Next: Spielwerk 40: Maskenbildner · All steps
Comments