#!/usr/bin/env bash # Render the artwork headlessly for the compare loop. # Usage: tools/shoot.sh [outfile] [query] # tools/shoot.sh /tmp/bc.png "preset=BEBC%20Archival&size_px=1200" # tools/shoot.sh /tmp/bc.png "seed=KAON-0088&shockIntensity=0.9" set -e ROOT="$(cd "$(dirname "$0")/.." && pwd)" OUT="${1:-/tmp/bc.png}" QUERY="${2:-size_px=1200}" PORT=8731 CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" # start a static server if not already up if ! curl -s "http://localhost:$PORT/tools/preview.html" >/dev/null 2>&1; then (cd "$ROOT" && python3 -m http.server "$PORT" >/tmp/bc_server.log 2>&1 &) sleep 1 fi # pull size for the window SIZE=$(echo "$QUERY" | sed -n 's/.*size_px=\([0-9]*\).*/\1/p'); SIZE="${SIZE:-1200}" # scale the virtual-time budget with resolution; cap with a hard watchdog so a # slow/hung render can never block forever. BUDGET=4000; WATCHDOG=45 if [ "$SIZE" -ge 1800 ]; then BUDGET=8000; WATCHDOG=90; fi "$CHROME" --headless=new --disable-gpu --hide-scrollbars \ --force-device-scale-factor=1 --virtual-time-budget="$BUDGET" \ --run-all-compositor-stages-before-draw \ --screenshot="$OUT" --window-size="$SIZE,$SIZE" \ "http://localhost:$PORT/tools/preview.html?$QUERY" 2>/dev/null & CPID=$! ( sleep "$WATCHDOG"; kill -9 "$CPID" 2>/dev/null ) & WPID=$! wait "$CPID" 2>/dev/null kill "$WPID" 2>/dev/null || true if [ -f "$OUT" ]; then echo "shot -> $OUT ($QUERY)"; else echo "FAILED -> $OUT ($QUERY)"; exit 1; fi