#!/usr/bin/env bash # Wrapper for the Blender GLB post-processor. # # Usage: # postprocess [options] # postprocess .tmp/glb-gen/furniture/desks/scifi_desk.glb client-tmp/models/furniture/scifi_desk.glb # postprocess .tmp/glb-gen/furniture/desks/scifi_desk.glb # auto-output to .tmp/glb-gen/postproc/... # # Options are passed through to the Blender script: # --target-width FLOAT Target width in world units (default: 1.0) # --target-height FLOAT Target height in world units (default: auto) # --color-threshold FLOAT Dominant color detection threshold (default: 0.25) # --material-name NAME Material slot name (default: mat_primary) # # Output: # Post-processed model (texture preserved) # Recolor mask sidecar (if texture found) set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" BLENDER_SCRIPT="$SCRIPT_DIR/postprocess_glb.py" # Find project root via git PROJECT_ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel)" if [ $# -lt 1 ]; then echo "Usage: postprocess [output.glb] [--target-width N] [--color-threshold N]" echo "" echo "If output is omitted, writes to .tmp/glb-gen/postproc/ mirroring the input path." exit 1 fi INPUT_REL="$1" shift # Resolve to absolute if [[ "$INPUT_REL" = /* ]]; then INPUT_ABS="$INPUT_REL" else INPUT_ABS="$(cd "$PROJECT_ROOT" && pwd)/$INPUT_REL" fi if [ ! -f "$INPUT_ABS" ]; then echo "ERROR: Input file not found: $INPUT_ABS" >&2 exit 1 fi # Determine output path if [ $# -ge 1 ] && [[ "$1" != --* ]]; then OUTPUT_REL="$1" shift if [[ "$OUTPUT_REL" = /* ]]; then OUTPUT_ABS="$OUTPUT_REL" else OUTPUT_ABS="$(cd "$PROJECT_ROOT" && pwd)/$OUTPUT_REL" fi else # Auto-output: mirror input path under .tmp/glb-gen/postproc/ # e.g. .tmp/glb-gen/furniture/desks/foo.glb → .tmp/glb-gen/postproc/furniture/desks/foo.glb REL_TO_TMP="${INPUT_REL#.tmp/glb-gen/}" OUTPUT_ABS="$(cd "$PROJECT_ROOT" && pwd)/.tmp/glb-gen/postproc/$REL_TO_TMP" fi mkdir -p "$(dirname "$OUTPUT_ABS")" echo "Post-processing: $(basename "$INPUT_ABS")" echo " Input: $INPUT_REL" echo " Output: ${OUTPUT_ABS#$(cd "$PROJECT_ROOT" && pwd)/}" flatpak run org.blender.Blender --background \ --python "$BLENDER_SCRIPT" \ -- "$INPUT_ABS" "$OUTPUT_ABS" "$@" 2>&1 \ | grep -E "^ |^=|WARNING|ERROR|Dominant|Mask" MASK="${OUTPUT_ABS%.glb}_mask.png" if [ -f "$MASK" ]; then echo " Mask: ${MASK#$(cd "$PROJECT_ROOT" && pwd)/}" fi echo "Done."