Files
rice-cube/rebuild.sh
T
Markk116 8104e01d6b Rice cube: procedural rice material and displaced filleted cubes
Two halves, one pipeline.

make_rice_texture.py models short-grain rice as randomly oriented 3D
ellipsoids (surface height solved as the quadratic root, so any orientation
works -- including grains standing on end), scattered by Poisson disk on a
torus and unioned into a height field. Because the scatter wraps by index, the
baked height/normal/AO/albedo set tiles exactly; that is proven by translating
the whole scatter a quarter patch and requiring a rolled copy back (0.0 mm
error), not by sampling a seam line, which turned out to be a coin flip.

make_rice_cube.py displaces a filleted cube with that height map: voxel remesh
for uniform vertex density, then triplanar sampling of the height field in
Geometry Nodes on object-space position. Exports STL via Blender and a
hand-rolled core-1.0 3MF, because this Blender build has no 3MF support and the
nix store is read-only.

Kept here: the procedural map set, the render of each body that was built
(40 mm / 4 mm fillet, and 160 mm / 8 mm), and the A/B sheets that record why --
fusing is voxel resolution, relief ratio 0.6 beats the map's own 0.9 on a small
body, and the fillet only reads once the body is large relative to the relief.

Not kept: mesh binaries (560 MB, 384 MB of it one STL), the scan extract, and
the baseline runs whose renders survive inside the sheets. rebuild.sh
regenerates all of it, in dependency order, including the sheets.
2026-11-12 10:54:43 +01:00

49 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Rebuild everything .gitignore leaves out, including the committed A/B sheets.
# Order matters only in that the sheets need the runs first; the 160 mm body is
# last of the meshes because it is the only expensive one (~3 GB RSS, ~2 min).
set -euo pipefail
cd "$(dirname "$0")"
SCAN=~/Downloads/food_0015_2k_sc65C6.zip
CUBE=(blender -b --factory-startup -P make_rice_cube.py --)
PROC=(--height tex_proc/rice_height_16bit.png --sidecar tex_proc/rice_maps.json)
# 1. The scanned baseline's source: external asset, not ours.
unzip -o "$SCAN" -x "__MACOSX/*" -d tex/
# 2. Procedural map set. 14 s, deterministic from SEED in the script.
python3 make_rice_texture.py
python3 preview_maps.py
# 3. The one that was liked: 40 mm, 0.2 mm voxel, relief 0.6 x grain.
"${CUBE[@]}" "${PROC[@]}" --patch 60 --voxel 0.2 --relief-ratio 0.6 --out out_calm
# 4. The 160 mm body with 8 mm fillets: 7.68M triangles.
"${CUBE[@]}" "${PROC[@]}" --size 160 --fillet 8 --patch 60 --voxel 0.2 \
--relief-ratio 0.6 --out out_160
# 5. Baselines kept only as A/B panes.
"${CUBE[@]}" "${PROC[@]}" --patch 60 --voxel 0.3 --out out # fusing, coarse
"${CUBE[@]}" "${PROC[@]}" --patch 60 --voxel 0.2 --out out_crisp # fusing, fine
"${CUBE[@]}" --out out_scan # scanned rice
# 6. The comparison sheets that are committed.
python3 contact_sheet.py out # variant ladder
python3 compare.py --out out/fusing_ab.png \
--title "fusing: voxel 0.3 mm vs 0.2 mm (everything else identical)" \
"voxel 0.3 · 210k tris · 10.5 MB=out/preview_g5_00.png" \
"voxel 0.2 · 480k tris · 24 MB=out_crisp/preview_g5_00.png"
python3 compare.py --out out/relief_ab.png \
--title "relief A/B: 0.90 x grain (4.48 mm) vs 0.60 x grain (3.00 mm)" \
"relief 4.48 mm · ratio 0.90=out_crisp/preview_g5_00.png" \
"relief 3.00 mm · ratio 0.60=out_calm/preview_g5_00.png"
python3 compare.py --out out/size_ab.png --crop 0.36,0.26,0.70,0.68 \
--title "same rice, body scaled: 40 mm cube / 4 mm fillet vs 160 mm cube / 8 mm fillet" \
"40 mm · fillet 4 · 480k tris=out_calm/preview_g5_00.png" \
"160 mm · fillet 8 · 7.68M tris=out_160/preview_g5_00.png"
python3 compare.py --out out/scan_vs_procedural.png \
--title "rice cube — scanned vs procedural rice" \
"scanned · grain 6.5 mm=out_scan/preview_g6_50.png" \
"procedural · grain 5.0 mm=out_calm/preview_g5_00.png"