Furnishing the Rooms from a Pack


Drew’s direction for the 3D rooms was short: nothing stays a box where a ready-made pack has the piece. The gardener came from a pack in the last post. This time it was the furniture. The KayKit Furniture Bits models are CC0 by Kay Lousberg, so the licence was the same easy question as before.

Sizes baked into the geometry

A small script, art/furnitureGlb.mjs, packs each model’s .gltf and .bin into one geometry-only .glb, with no new dependency. The game loads those files through a pack loader that shares the pack’s one texture atlas.

The first version got one thing wrong. It built each model at its own size, one to three metres, and then scaled it down to the piece’s footprint with an instance matrix. Babylon’s ink outline is offset along the normal in model space, before the instance matrix applies. A model scaled down that way gets a thinner outline than a code-made piece built at its real size. The reviewer caught it in round one of bonsaiGame#354: the side table and the desk had at most a faint edge, while the sofa beside them had the full dark line.

The fix bakes each piece’s size into the geometry when it is packed. Every pack piece now has an instance scale of exactly 1, like the code-made pieces. A unit test pins that, so the outline cannot quietly shrink again.

Turning and sitting

The sofa faces east and the armchair faces west, so those two need a quarter turn. packGeometry centres each model over its footprint and gives it a quarter turn when the piece faces east or west.

The seat height used to be 0.51 m, a number from the code-made sofa. The file says where the cushion really is: its top is 0.5 up a model 1.224 tall, and scaled to the piece that is 0.383 m. seats.ts now takes its seat height from the pack instead of a number I typed. The gardener sits on the cushion now, and the sitting shots were re-baselined.

Shapes that do not fit

Not every piece can be the pack’s model as it comes.

  • The pack’s models are big, one to three metres across, and each is fitted to the piece’s footprint and height separately, so the proportions shift. The coffee table’s table_low shrinks to about 0.42 of the file across but keeps three quarters of its height, so it comes out a chunkier table with a drawer. That height is one line in PACK_MODELS.
  • The floor lamp is drawn 1.5 m tall, 60% of the file’s 2.52 m, while its base shrinks to under half the file’s width. It is a little slimmer than the pack drew it, and it still reads as a standing lamp.
  • The tall bookcase stays code-made. The pack’s shelf_* models are wall planks, two metres wide and 0.4 m deep, that start below the floor. They have no body to stand on, so a tree would have nowhere to sit.
  • The potted plant and the fireplace stay code-made too. No pack has them.

The walk test went red

The walk tests had already gone red once before this. bonsaiGame#352 added the modelled fireplace, and the lounge walk baseline still showed the box. #353 replaced that one shot with the render from the failing run.

After #354 merged, the walk tests on main went red again. The study and mantel shots sometimes photographed the placeholder box, because they took the picture before the pack model had loaded, and nothing in the test waited for it.

The first fix was the obvious one: a wait for each pack piece, five of them in the lounge. On software GL every poll costs a frame. The door walk runs at about 1.9 minutes against a 120-second limit, and five extra waits pushed it over. It did not help that in both sessions the agent I had handed the work to ended its turn with a browser run still going in the background, so I finished the gates and the baselines myself.

The fix that worked was one poll. waitForRoom now asks, in a single check, whether the room’s pack pieces have loaded: five for the lounge and two for the study. The door walk came back to about two minutes. That is still close to its limit, and a longer room would push it over again. I have not fixed that margin.

The shots

The 3D lounge at phone landscape size before the change: a red sofa built from code shapes on the left with a wooden coffee table beside it, a green armchair and a standing lamp at the back by the bookcase, and the kitchen counters on the right as plain brown blocks.

The lounge at commit 2fb6b1e, before the sofa, armchair, coffee table and lamp came from the pack. Those four were still built from code shapes.

The same lounge after the change: a blue pack sofa and a low red-brown coffee table on the left, a blue pack armchair beside the standing lamp at the back, and the kitchen counters on the right still plain blocks.

The same camera at commit af0e1f3, with the four pieces from the pack. The bookcase, the plant and the fireplace are unchanged.

The gardener seated on the blue pack sofa, seen from above. A small side table with a bowl sits at the left, and the fireplace mantel is at the right.

The gardener sitting on the pack sofa. The seat is measured from the file, at 0.383 m.

The lounge benchmark is unchanged within noise, and draw calls stay at 87. Precache grows by four files and about 65 KiB.

Those brown blocks on the right are next: the kitchen counters, from KayKit’s Restaurant Bits, and after them the hallway rug and hall table. The tall bookcase and the fireplace still have no pack match.