THE DIET: 214MB of props become 47MB, and nobody can tell

The prop library was costing players more than it was worth. hunyuan3d
hands back ~120,000 triangles and 1024px textures per object, so a
COOKING POT was a 4MB download — and the fryer bench, which loads a pot,
a basket and a rack, made a phone fetch 13MB before it could show you
anything. Right after shipping touch controls, that is the wrong bill.

scripts/optimise-models.sh: simplify to 10% of the triangles with a
0.002 error bound, textures to 512. Across 51 models that is 214MB →
47MB, and at the distance this game frames anything, the before and
after screenshots are indistinguishable — I checked the pot at full
frame before trusting it on the rest. The fryer bench now costs under
3MB.

The script skips anything already under the threshold, so a second run
cannot grind an optimised mesh into mush; delete the file and re-run
gen-assets.sh to go back to an original.

Regression sweep after: toast scene pristine, grill 9.4, pan 8.0, steak
9.4, bruschetta 9.6, air fryer 9.5, chips 10.0, pasta 10.0, eggs 10.0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
type-two 2026-07-26 19:00:47 +10:00
parent acf9926eaf
commit 35e871599c
53 changed files with 47 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

47
scripts/optimise-models.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/bash
# optimise-models.sh — shrink the generated GLBs for the web.
#
# hunyuan3d hands back ~120k triangles and 1024px textures per prop, which is
# ~4MB of download for a cooking pot. Simplified to 10% of the triangles with a
# 0.002 error bound and 512px textures, the same pot is ~800KB and looks
# identical at the distances this game shows it from. The fryer bench alone
# went from a 13MB download to under 3MB.
#
# Idempotence guard: anything already under the threshold is skipped, so a
# second run cannot simplify an already-simplified mesh into mush. Delete the
# file and re-run gen-assets.sh to start from the original.
set -uo pipefail
cd "$(dirname "$0")/.."
MODELS=public/assets/models
SKIP_UNDER=${SKIP_UNDER:-1200000} # bytes; optimised props land well under this
RATIO=${RATIO:-0.1}
ERROR=${ERROR:-0.002}
TEX=${TEX:-512}
GT="npx --yes @gltf-transform/cli@4.4.2"
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
before=0; after=0; done_n=0; skip_n=0
for f in "$MODELS"/*.glb; do
[ -e "$f" ] || continue
name=$(basename "$f")
sz=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f")
before=$((before + sz))
if [ "$sz" -lt "$SKIP_UNDER" ]; then
echo " = $name already lean ($((sz/1024))KB)"
after=$((after + sz)); skip_n=$((skip_n + 1)); continue
fi
if $GT simplify "$f" "$TMP/a.glb" --ratio "$RATIO" --error "$ERROR" >/dev/null 2>&1 \
&& $GT resize "$TMP/a.glb" "$TMP/b.glb" --width "$TEX" --height "$TEX" >/dev/null 2>&1; then
mv "$TMP/b.glb" "$f"
nsz=$(stat -f%z "$f" 2>/dev/null || stat -c%s "$f")
after=$((after + nsz)); done_n=$((done_n + 1))
echo " + $name $((sz/1024))KB → $((nsz/1024))KB"
else
echo " ! $name FAILED — left untouched"
after=$((after + sz))
fi
done
echo "----"
echo "optimised $done_n, skipped $skip_n"
echo "total $((before/1048576))MB → $((after/1048576))MB"