Files
rice-cube/contact_sheet.py
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

79 lines
2.7 KiB
Python

"""Compose the rendered variants into one labelled sheet.
python3 contact_sheet.py out/
"""
import json
import os
import sys
from PIL import Image, ImageDraw, ImageFont
FONT = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
FONT_BOLD = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
PANEL_W = 820
PAD = 18
TITLE_H = 74
def main(out_dir):
with open(os.path.join(out_dir, "summary.json")) as f:
summary = json.load(f)
with open(os.path.join(out_dir, "verify.json")) as f:
verified = json.load(f)
names = list(summary["variants"])
panels = []
for name in names:
img = Image.open(os.path.join(out_dir, f"preview_{name}.png"))
ratio = PANEL_W / img.width
panels.append(img.resize((PANEL_W, int(img.height * ratio)),
Image.LANCZOS))
panel_h = panels[0].height
label_h = 96
width = PANEL_W * len(panels) + PAD * (len(panels) + 1)
height = TITLE_H + panel_h + label_h + PAD
sheet = Image.new("RGB", (width, height), (32, 34, 36))
draw = ImageDraw.Draw(sheet)
title = ImageFont.truetype(FONT_BOLD, 30)
body = ImageFont.truetype(FONT, 20)
small = ImageFont.truetype(FONT, 17)
draw.text((PAD, 20),
f"Rice cube — {summary['cube_mm']:.0f} mm rounded cube, "
f"displacement from {summary['height_map']}",
font=title, fill=(235, 235, 235))
draw.text((PAD, 52),
f"source: {summary['source']} · one height field at three "
f"apparent grain scales · relief = "
f"{summary['relief_ratio']:.2f} x grain (from the map itself)",
font=small, fill=(150, 152, 155))
for index, (name, panel) in enumerate(zip(names, panels)):
x = PAD + index * (PANEL_W + PAD)
sheet.paste(panel, (x, TITLE_H))
info = summary["variants"][name]
check = verified.get(f"rice_cube_{name}.3mf", {})
lines = [
f"{name} {info['grain_mm']} mm grains",
f"texture spans {info['patch_mm']:.0f} mm "
f"relief {info['displacement_mm']:.2f} mm",
f"{check.get('triangles', 0):,} tris "
f"{check.get('signed_volume_mm3', 0):,.0f} mm3 "
f"boundary edges {check.get('boundary_edges', '?')}",
]
for row, text in enumerate(lines):
draw.text((x + 4, TITLE_H + panel_h + 10 + row * 27), text,
font=body if row == 0 else small,
fill=(232, 232, 232) if row == 0 else (158, 160, 163))
path = os.path.join(out_dir, "variants.png")
sheet.save(path)
print(f"wrote {path} ({sheet.width}x{sheet.height})")
if __name__ == "__main__":
main(sys.argv[1] if len(sys.argv) > 1 else "out")