#!/usr/bin/env python3 """[215] Testszene für den Cycles-Standalone: kleines Haus (Quader + Satteldach) auf Wiese, Kamera, Nishita-Himmel mit Sonne, Principled BSDF. Schreibt eine Cycles-XML-Szene: python3 scripts/cycles/spike-scene.py haus.xml cycles --background --samples 64 --width 1280 --height 720 --output haus.exr haus.xml Gelernt beim Bau (Vorlage für den späteren XML-Schreiber im Kern, doc/CYCLES.md): - ``: 16 Zahlen SPALTENWEISE (Spalten rechts, oben, Blickrichtung, Position); die Kamera blickt entlang +Z (Blender spiegelt beim Export Z), Bild-oben = +Y. - Der Himmel braucht ein Hintergrundlicht (`` mit shader="default_background"), sonst wird die Sonnenscheibe nicht gezielt abgetastet (Rauschen, Lichtpunkte). - Himmel/Sonne sind physikalisch (sehr hell): Belichtung über ``, Ausgabe als EXR und dann Tonwert-Abbildung/sRGB ausserhalb (PNG aus dem Standalone ist lineares Licht, 8 Bit). - Entrauschen: `` (OIDN), kein Kommandozeilen-Schalter. """ import math import sys W, H = 1280, 720 def mesh(points, faces): pts = " ".join(f"{x} {y} {z}" for x, y, z in points) nv = " ".join(str(len(f)) for f in faces) vs = " ".join(" ".join(map(str, f)) for f in faces) return f'' def cross(a, b): return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]] def norm(a): n = math.sqrt(sum(c * c for c in a)) return [c / n for c in a] def look(pos, target, up=(0, 0, 1)): f = norm([t - p for t, p in zip(target, pos)]) r = norm(cross(f, up)) u = cross(r, f) m = [*r, 0, *u, 0, *f, 0, *pos, 1] # spaltenweise, Blick = +Z return " ".join(f"{v:.6f}" for v in m) x0, x1, y0, y1, h, rh = -5, 5, -4, 4, 3, 5.2 box = [(x0, y0, 0), (x1, y0, 0), (x1, y1, 0), (x0, y1, 0), (x0, y0, h), (x1, y0, h), (x1, y1, h), (x0, y1, h)] walls = [(0, 3, 2, 1), (4, 5, 6, 7), (0, 1, 5, 4), (1, 2, 6, 5), (2, 3, 7, 6), (3, 0, 4, 7)] ov = 0.5 roof_p = [(x0 - ov, y0 - ov, h - 0.3), (x1 + ov, y0 - ov, h - 0.3), (x1 + ov, 0, rh), (x0 - ov, 0, rh), (x0 - ov, y1 + ov, h - 0.3), (x1 + ov, y1 + ov, h - 0.3)] roof = [(0, 1, 2, 3), (3, 2, 5, 4)] gable_p = [(x0, y0, h), (x0, y1, h), (x0, 0, rh), (x1, y1, h), (x1, y0, h), (x1, 0, rh)] gable = [(0, 1, 2), (3, 4, 5)] g = 60 ground = [(-g, -g, 0), (g, -g, 0), (g, g, 0), (-g, g, 0)] out = sys.argv[1] if len(sys.argv) > 1 else "haus.xml" fov = math.radians(45) # vertikal sun_el, sun_rot = math.radians(38), math.radians(150) def pbr(name, rgb, rough): return (f'' f'') xml = f''' {pbr("putz", "0.82 0.78 0.70", 0.85)} {pbr("ziegel", "0.45 0.12 0.07", 0.7)} {pbr("gras", "0.12 0.25 0.05", 0.9)} {mesh(box, walls)}{mesh(gable_p, gable)} {mesh(roof_p, roof)} {mesh(ground, [(0, 1, 2, 3)])} ''' with open(out, "w") as f: f.write(xml) print("geschrieben:", out)