[211] [213] Rendering: physikalisch plausible Bildwirkung, Material je Bauteil, Kamerawahl
Skript: Nishita mit Sonnenstärke 1.0 und automatischer Belichtung nach Sonnenhöhe (gemessene Tabelle), AgX, Albedo höchstens 0.8, Wiese fürs Gelände, Ziegel/Blech/Kies nach Dachschicht, Kontext hellgrau, Glas mit Transmission (für Schattenstrahlen durchsichtig), leichte Umgebungsverdeckung. Export: Dachschichten je Baustoff statt alle als "Dach" (splitRoofMaterials), Rolle und Baustoff je Material in scene.json. Dialog: Auswahl aktuelle 3D-Ansicht oder gespeicherte Kamera samt Sonnenzeit; CLI --camera <Name|id>.
This commit is contained in:
11 files changed
+625
-38
No files matched your search
@@ -70,7 +70,7 @@ Kennwort, anonym) als PDF; Austausch mit Fachplanern über DXF/IFC.
|
||||
- [61] Raumprogramm gegen Modell und Flächennachweis SIA 416 als Tabelle/Layout-Element ([70]); Kennzahlen (GF, GV, HNF/GF, Fassadenanteil).
|
||||
- 3D-Bilder für die Abgabe: hochaufgelöster PNG-Export (Perspektive, Axonometrie, Schatten), Sonnenstand; [205] Pausfolie.
|
||||
- [199]/[204] Plan- und App-Review-Reste im Darstellungsbereich 1:500/1:200 schliessen.
|
||||
- [211] Rendering mit Blender/Cycles (◐, Eintrag unter „Import und Export“): Belichtung/Materialien abstimmen, Kamera [213] im Dialog wählbar, Mac-Gegenprobe.
|
||||
- [211] Rendering mit Blender/Cycles (◐, Eintrag unter „Import und Export“): Mac-Gegenprobe (Tauri, Metal), Blender 3.6/4.x, Dialog im Browser klicken.
|
||||
- [213] Kameras und Begehen/WASD (◐, Eintrag unter „Grundriss“): Kopieren/Gruppen/IFC, Mac-Gegenprobe.
|
||||
- ○ **[214]** 3D-Engine optimieren (12.11., Wunsch Maintainer: „render3d hat sich sehr früh entwickelt, Leistung könnte besser sein“).
|
||||
Zuerst messen (Bildzeit, Draw-Calls, Upload-Zeit, Neu-Vernetzen je Änderung, Speicher; Musterhaus komplex + Grossgebäude
|
||||
@@ -773,7 +773,7 @@ Punktwolken/BCF-Ausbau, Windows-Paket, [C5]/[C7]/[15] Kern-Umbauten — ausser s
|
||||
|
||||
## Import und Export
|
||||
|
||||
- ◐ **[211]** Rendering mit Blender/Cycles (12.11.). Export-Paket `model.glb` + `scene.json` + `textures/` (`export/blenderRender.ts`, Format renderer-neutral in `doc/RENDER-SZENE.md`, Leser für Cycles-Standalone [215] vorgesehen): Kamera der aktiven 3D-Ansicht (`getCamera`) oder Voreinstellung, Sonne aus Sonnenstand/Ort, Materialtabelle (Farbe, Rauheit, Metall, Glas mit Transmission/IOR, Bildkarten aus `Component.material`). Texturen ohne UVs per Box-Projektion (Kachel `sizeM`); keine UVs im GLB. Skript `scripts/blender/render_dossier.py` (Cycles, Nishita/Mehrfachstreuung-Himmel, Denoiser, GPU/Metal wenn vorhanden). App: Dialog „Rendering mit Blender" (Befehl `rendering`, Menü Ansicht, Pfad in Einstellungen), Fortschritt „Sample x von y", Abbrechen, Vorschau, Bild speichern; Tauri `src-tauri/src/blender.rs` + Capabilities (fs nur `$TEMP/dossier-render`), Electron `scripts/electron-blender.cjs`, Browser: Paket als ZIP. CLI `render --out bild.png [--view --when --samples --size --cpu --blender]`. Geprüft: vitest (Szene, Paket, Prozess gemockt, CLI mit Blender-Ersatz), Rust-Logik `blender.rs` (rustc --test, 6 Tests), `cargo check` der Tauri-App (Linux), echter Lauf mit `bpy` 5.3 (CPU) am Musterhaus komplex, Sonnenrichtung per Schattentest. **Offen:** nicht in der Tauri-App/auf dem Mac geprüft (Berechtigungen, Metal-GPU, Ereignisse), nicht mit einem installierten Blender 3.6/4.x; „Als Bild ins Layout" entfällt (Layouts haben keine Bildelemente); Dialog nicht im Browser geklickt; ambientCG-Web-Texturen lädt die CLI nicht. · M
|
||||
- ◐ **[211]** Rendering mit Blender/Cycles (12.11.). Export-Paket `model.glb` + `scene.json` + `textures/` (`export/blenderRender.ts`, Format renderer-neutral in `doc/RENDER-SZENE.md`, Leser für Cycles-Standalone [215] vorgesehen): Kamera der aktiven 3D-Ansicht (`getCamera`) oder Voreinstellung, Sonne aus Sonnenstand/Ort, Materialtabelle (Farbe, Rauheit, Metall, Glas mit Transmission/IOR, Bildkarten aus `Component.material`). Texturen ohne UVs per Box-Projektion (Kachel `sizeM`); keine UVs im GLB. Skript `scripts/blender/render_dossier.py` (Cycles, Nishita/Mehrfachstreuung-Himmel, Denoiser, GPU/Metal wenn vorhanden). App: Dialog „Rendering mit Blender" (Befehl `rendering`, Menü Ansicht, Pfad in Einstellungen), Fortschritt „Sample x von y", Abbrechen, Vorschau, Bild speichern; Tauri `src-tauri/src/blender.rs` + Capabilities (fs nur `$TEMP/dossier-render`), Electron `scripts/electron-blender.cjs`, Browser: Paket als ZIP. CLI `render --out bild.png [--view --when --samples --size --cpu --blender]`. Geprüft: vitest (Szene, Paket, Prozess gemockt, CLI mit Blender-Ersatz), Rust-Logik `blender.rs` (rustc --test, 6 Tests), `cargo check` der Tauri-App (Linux), echter Lauf mit `bpy` 5.3 (CPU) am Musterhaus komplex, Sonnenrichtung per Schattentest. **Offen:** nicht in der Tauri-App/auf dem Mac geprüft (Berechtigungen, Metal-GPU, Ereignisse), nicht mit einem installierten Blender 3.6/4.x; „Als Bild ins Layout" entfällt (Layouts haben keine Bildelemente); Dialog nicht im Browser geklickt; ambientCG-Web-Texturen lädt die CLI nicht. **Stand 12.11. (Bildwirkung, Kamerawahl):** Nishita mit Sonnenstärke 1.0 und automatischer Belichtung nach Sonnenhöhe (gemessen: weisse besonnte Fläche ≈ 45 bei 60°, Tabelle `SUNLIT_WHITE` im Skript), AgX, Albedo ≤ 0.8, Wiese `Grass005` fürs Gelände (Rückfall Wiesengrün), Dachschichten je Baustoff (`splitRoofMaterials`: vorher hingen Ziegel/Kies/Blech am gleichen „Dach“-Material), Kontext hellgrau, Glas mit Transmission und durchsichtig für Schattenstrahlen, leichte Umgebungsverdeckung. Kamera im Dialog („Aktuelle 3D-Ansicht“ oder gespeicherte Kamera, Sonnenzeit der Kamera), CLI `--camera <Name|id>`. Geprüft: vitest (Materialzuordnung, Kamerawahl, CLI), echter Lauf mit `bpy` 5.3 (CPU) an Musterhaus komplex, Iso und Kamera „Südost“. **Offen:** Mac/Tauri-Gegenprobe, Blender 3.6/4.x (Mix-Knoten per Platz, `light_settings.ao_factor` nur in 5.x geprüft), Dialog nicht im Browser geklickt, Gelände hat kein Material im Modell (immer Wiese), Dachtyp-Schichten ohne Bildkarte (z. B. Faserzement) nur nach Namen. · M
|
||||
|
||||
- ◐ **[B4]** (= [25], zweite Stufe) IFC-Import zu echten Bauteilen (`io/ifcImport*`, `fileio`). Dächer, Treppen mit 3+ Podesten, Träger, schräge/
|
||||
gekrümmte Wände, Wände mit Profiländerung, Decken aus Netzen mit T-Stössen, Tür-Anschlag, Typen aus
|
||||
|
||||
+27
-2
@@ -25,10 +25,35 @@ nach z-oben zurück, `scene.json` braucht keine Umrechnung.
|
||||
direction[3] (normiert), up[3], fovDeg (vertikal), orthoHeight (volle Sichthöhe, m)}`.
|
||||
- `sun {azimuth, elevation, when, lat, lon}`: Grad, Azimut von Norden im Uhrzeigersinn (Ost = 90), Höhe über
|
||||
dem Horizont. Himmel: physikalischer Tageshimmel mit Sonnenscheibe an dieser Richtung; unter dem Horizont wird
|
||||
mit 1° gerendert. Optional `sun.intensity` und `exposure` (Leser-Voreinstellungen), `ground` (bool, Bodenplatte).
|
||||
mit 1° gerendert. Optional `sun.intensity` (Standard 1.0) und `exposure` (EV; fehlt sie, belichtet der Leser automatisch
|
||||
nach Sonnenhöhe, s. u.), `ground` (bool, Bodenplatte).
|
||||
- `materials[]`, Schlüssel = glTF-Materialname:
|
||||
`color [r,g,b]` sRGB 0..1, `opacity`, `roughness`, `metallic`, `glass` (bool), `transmission` 0..1, `ior`,
|
||||
`textures {color, normal, roughness, metalness}` (Pfade), `sizeM` (Kantenlänge einer Kachel in m).
|
||||
`textures {color, normal, roughness, metalness}` (Pfade), `sizeM` (Kantenlänge einer Kachel in m),
|
||||
`role` (`terrain` | `roof` | `context` | `opening` | `building`: Verwendung nach dem Bauteil-Knoten des GLB) und
|
||||
`component` (Baustoff, wenn er vom Materialnamen abweicht). Gleiche Namen mit verschiedener Farbe ordnet der Leser
|
||||
über die Farbe zu.
|
||||
|
||||
## Material je Bauteil
|
||||
|
||||
Der glTF-Materialname ist der Baustoff-Name (`Component.name`); dessen `material` liefert die Bildkarten. Ausnahmen:
|
||||
- **Dach:** der Kern legt alle Dachschichten als „Dach“ ab. `splitRoofMaterials` ordnet jedem Teilnetz die Schicht des Dachtyps
|
||||
zu (Farbe des Baustoffs, Rückfall die äusserste Schicht) und benennt das Material `Dach: <Baustoff>` (`component` = Baustoff,
|
||||
damit dessen Bildkarten/Ersatzlook gelten). Hat das Dach eine eigene Farbe (`Roof.color`), bleibt es bei „Dach“.
|
||||
- **Gelände:** hat im Modell kein Material; bekommt die Wiese `Grass005` der Bibliothek (Kachel 4 m). Ohne Bildkarte setzt der
|
||||
Leser ein Wiesengrün. **Kontext** (importierte Körper): neutral hellgrau.
|
||||
|
||||
## Bildwirkung (Leser)
|
||||
|
||||
Cycles-Standard statt Augenmass: Nishita-Himmel mit Sonnenstärke 1.0 (absolut, weisse besonnte Fläche ≈ 45 bei 60°), automatische
|
||||
Belichtung nach Sonnenhöhe (besonnte weisse Fläche → 1.5; ≈ −4.9 EV bei 60°), AgX, Albedo höchstens 0.8, Wiese/Ziegel/Blech nach
|
||||
Rolle und Baustoffname, Glas mit Transmission (für Schattenstrahlen durchsichtig), leichte Umgebungsverdeckung. Werte im Kopf von
|
||||
`render_dossier.py`.
|
||||
|
||||
## Kamera
|
||||
|
||||
`camera` = Voreinstellung oder explizit. Der Dialog bietet „Aktuelle 3D-Ansicht“ und jede gespeicherte Kamera (`Project.cameras`,
|
||||
[213]); deren Sonnenzeit (`sunWhen`) füllt die Zeit vor (änderbar). CLI: `--camera <Name|id>`; `--when` übersteuert die Zeit.
|
||||
|
||||
## Texturen ohne UVs
|
||||
|
||||
|
||||
@@ -18,6 +18,24 @@
|
||||
# Koordinaten: Modell-Koordinaten (x = Ost, y = Nord, z = Hoehe, Meter). Der glTF-Import von Blender dreht die
|
||||
# Y-oben-Achsen des GLB (x, z, -y) genau auf diese zurueck, Kamera und Sonne brauchen keine Umrechnung.
|
||||
#
|
||||
# Materialien (`materials[]`): `name` = glTF-Materialname, `role` (terrain | roof | context | opening | building),
|
||||
# `component` (Baustoff, wenn er vom Namen abweicht: "Dach: Tonziegel"), `color` sRGB, `glass`, `textures`, `sizeM`.
|
||||
# Mehrere Eintraege gleichen Namens (gleicher Name, andere Farbe) ordnet das Skript ueber die Farbe zu.
|
||||
#
|
||||
# Bildwirkung (physikalisch plausibel, wie ein Cycles-Standardbild und nicht "nach Augenmass"):
|
||||
# * Himmel: Nishita (ab Blender 5.0 "Mehrfachstreuung"), Sonnenstaerke 1.0, Sonnenscheibe 0.545 Grad (Winkeldurchmesser der
|
||||
# Sonne), Luft/Staub/Ozon auf 1.0 (Standard). Sonnenstand aus Ort und Zeit der Szene (`sun`).
|
||||
# * Belichtung: Nishita rechnet absolut (weisse besonnte Flaeche ~ 45 bei 60 Grad Sonnenhoehe), die Kamera belichtet wie eine
|
||||
# Automatik (`auto_exposure`, ~ -5 EV mittags) und die Farbumsetzung ist AgX (Filmic, wo AgX fehlt): Lichter laufen weich aus,
|
||||
# Weiss frisst nicht aus. `sun.intensity` und `exposure` (EV) in scene.json uebersteuern (Voreinstellung 1.0 und automatisch).
|
||||
# * Albedo: kein Baustoff reflektiert 100 Prozent. Flaechenfarben und Texturen werden auf 0.80 (linear, = sRGB 0.91, frischer
|
||||
# weisser Putz) begrenzt, sonst frisst Weiss unter der Sonne aus.
|
||||
# * Gelaende: Wiese (Bildkarten der Bibliothek oder ohne diese ein Wiesengruen), Boden darunter erdig-gruen.
|
||||
# * Dach: Baustoff der aeussersten Dachschicht (Textur; ohne Textur Ziegel, Blech, Kies, Schiefer, Schindeln nach dem Namen).
|
||||
# * Kontext (Nachbargebaeude, importierte Koerper): neutral hellgrau (sRGB 0.78), matt.
|
||||
# * Glas: Transmission 1, Rauheit 0, IOR 1.5, leichte Toenung; fuer Schattenstrahlen durchsichtig, damit Sonne ins Innere kommt.
|
||||
# * Umgebungsverdeckung leicht (Cycles-Weltoption `ao_factor`), dazu die globale Beleuchtung mit 8 Abprallern.
|
||||
#
|
||||
# Ausgabe: Blender schreibt auf stdout "Sample x/y" (Cycles), dazu meldet das Skript Marken, die Dossier liest:
|
||||
# DOSSIER_STAGE <name> Phase (import, materials, render, denoise)
|
||||
# DOSSIER_DONE <pfad.png> fertig
|
||||
@@ -111,8 +129,33 @@ def principled(mat):
|
||||
return None
|
||||
|
||||
|
||||
ALBEDO_MAX = 0.80 # linear; frischer weisser Putz ~0.8, nichts in der Natur reflektiert 100 Prozent
|
||||
|
||||
|
||||
def srgb_to_linear(c):
|
||||
return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4
|
||||
|
||||
|
||||
def lin(rgb):
|
||||
"""sRGB-Tripel (0..1) -> linear."""
|
||||
return tuple(srgb_to_linear(float(c)) for c in rgb[:3])
|
||||
|
||||
|
||||
def clamp_albedo(rgb_linear):
|
||||
return tuple(min(float(c), ALBEDO_MAX) for c in rgb_linear[:3])
|
||||
|
||||
|
||||
def is_unset(color):
|
||||
"""Weiss = vom Modell nicht gesetzt (Baustoff-Farbe #ffffff, der Look kommt aus der Bildkarte)."""
|
||||
return all(float(c) >= 0.97 for c in color[:3])
|
||||
|
||||
|
||||
def make_glass(mat, spec):
|
||||
"""Verglasung: Transmission statt Alpha-Blending, damit Cycles Brechung und Spiegelung rechnet."""
|
||||
"""Verglasung: Transmission statt Alpha-Blending, damit Cycles Brechung und Spiegelung rechnet.
|
||||
|
||||
Physikalisch: klarer Glaskoerper, IOR 1.5, Rauheit 0, hauchduenn getoent. Fuer Schattenstrahlen ist die Scheibe
|
||||
durchsichtig (Mix mit Transparent ueber Light Path > Is Shadow Ray), sonst bliebe das Innere hinter Fenstern
|
||||
dunkel; das ist die uebliche Architektur-Naeherung fuer duenne Verglasung."""
|
||||
bsdf = principled(mat)
|
||||
if bsdf is None:
|
||||
return
|
||||
@@ -120,26 +163,39 @@ def make_glass(mat, spec):
|
||||
if base is not None:
|
||||
c = list(base.default_value)
|
||||
# Leichte Toenung, nie schwarz (Transmission faerbt mit der Basisfarbe).
|
||||
base.default_value = (0.85 + 0.15 * c[0], 0.85 + 0.15 * c[1], 0.85 + 0.15 * c[2], 1.0)
|
||||
base.default_value = (0.90 + 0.10 * c[0], 0.94 + 0.06 * c[1], 0.95 + 0.05 * c[2], 1.0)
|
||||
set_input(bsdf, ("Alpha",), 1.0)
|
||||
set_input(bsdf, ("Transmission Weight", "Transmission"), float(spec.get("transmission", 1.0)))
|
||||
set_input(bsdf, ("Roughness",), 0.03)
|
||||
set_input(bsdf, ("IOR",), float(spec.get("ior", 1.45)))
|
||||
set_input(bsdf, ("Roughness",), 0.0)
|
||||
set_input(bsdf, ("IOR",), float(spec.get("ior", 1.5)))
|
||||
set_input(bsdf, ("Metallic",), 0.0)
|
||||
if hasattr(mat, "blend_method"):
|
||||
mat.blend_method = "OPAQUE"
|
||||
if hasattr(mat, "surface_render_method"):
|
||||
mat.surface_render_method = "DITHERED"
|
||||
nt = mat.node_tree
|
||||
out = next((n for n in nt.nodes if n.type == "OUTPUT_MATERIAL"), None)
|
||||
if out is None:
|
||||
return
|
||||
lp = nt.nodes.new("ShaderNodeLightPath")
|
||||
clear = nt.nodes.new("ShaderNodeBsdfTransparent")
|
||||
mix = nt.nodes.new("ShaderNodeMixShader")
|
||||
nt.links.new(lp.outputs["Is Shadow Ray"], mix.inputs["Fac"])
|
||||
nt.links.new(bsdf.outputs["BSDF"], mix.inputs[1])
|
||||
nt.links.new(clear.outputs["BSDF"], mix.inputs[2])
|
||||
nt.links.new(mix.outputs["Shader"], out.inputs["Surface"])
|
||||
|
||||
|
||||
def add_textures(mat, spec, base_dir):
|
||||
"""Bildtexturen aus dem Material-System (ambientCG): Kachelung ueber Objektkoordinaten mit Box-Projektion.
|
||||
|
||||
Das GLB traegt keine UV-Koordinaten. Die Box-Projektion (Bild je Achse, weiche Uebergaenge) legt die Textur
|
||||
in Metern fest (`sizeM` = Kantenlaenge einer Kachel) und kommt ohne UVs aus."""
|
||||
in Metern fest (`sizeM` = Kantenlaenge einer Kachel) und kommt ohne UVs aus. Gibt zurueck, ob eine Farbkarte
|
||||
angebunden wurde."""
|
||||
bsdf = principled(mat)
|
||||
textures = spec.get("textures") or {}
|
||||
if bsdf is None or not textures:
|
||||
return
|
||||
return False
|
||||
nt = mat.node_tree
|
||||
size = float(spec.get("sizeM") or 1.0)
|
||||
coord = nt.nodes.new("ShaderNodeTexCoord")
|
||||
@@ -161,9 +217,19 @@ def add_textures(mat, spec, base_dir):
|
||||
nt.links.new(mapping.outputs["Vector"], node.inputs["Vector"])
|
||||
return node
|
||||
|
||||
has_color = False
|
||||
n = image_node(textures["color"], "sRGB") if "color" in textures else None
|
||||
if n is not None:
|
||||
nt.links.new(n.outputs["Color"], bsdf.inputs["Base Color"])
|
||||
has_color = True
|
||||
# Albedo begrenzen (ALBEDO_MAX): Textur * Faktor, damit helle Karten (Putz) nicht ausfressen.
|
||||
mul = nt.nodes.new("ShaderNodeMix")
|
||||
mul.data_type = "RGBA"
|
||||
mul.blend_type = "MULTIPLY"
|
||||
mul.inputs[0].default_value = 1.0
|
||||
# Eingaenge nach Platz (Blender 3.4 bis 5): 6 = A (Farbe), 7 = B (Farbe), Ausgang 2 = Ergebnis (Farbe).
|
||||
mul.inputs[7].default_value = (ALBEDO_MAX, ALBEDO_MAX, ALBEDO_MAX, 1.0)
|
||||
nt.links.new(n.outputs["Color"], mul.inputs[6])
|
||||
nt.links.new(mul.outputs[2], bsdf.inputs["Base Color"])
|
||||
n = image_node(textures["roughness"], "Non-Color") if "roughness" in textures else None
|
||||
if n is not None:
|
||||
nt.links.new(n.outputs["Color"], bsdf.inputs["Roughness"])
|
||||
@@ -176,19 +242,106 @@ def add_textures(mat, spec, base_dir):
|
||||
nm.inputs["Strength"].default_value = 0.8
|
||||
nt.links.new(n.outputs["Color"], nm.inputs["Color"])
|
||||
nt.links.new(nm.outputs["Normal"], bsdf.inputs["Normal"])
|
||||
return has_color
|
||||
|
||||
|
||||
# Ersatzlooks ohne Bildkarte: (Schluesselwoerter im Baustoffnamen) -> (Farbe sRGB, Rauheit, Metall).
|
||||
ROOF_LOOKS = (
|
||||
(("ziegel", "biber", "dachstein"), (0.56, 0.25, 0.16), 0.7, 0.0),
|
||||
(("schindel",), (0.40, 0.28, 0.18), 0.85, 0.0),
|
||||
(("blech", "zink", "titan", "kupfer", "alu", "stehfalz"), (0.55, 0.57, 0.58), 0.35, 1.0),
|
||||
(("kies",), (0.46, 0.44, 0.41), 0.95, 0.0),
|
||||
(("schiefer", "faserzement", "eternit"), (0.22, 0.23, 0.25), 0.8, 0.0),
|
||||
(("begr", "substrat", "gras"), (0.30, 0.42, 0.18), 0.95, 0.0),
|
||||
(("bitumen", "abdicht", "folie"), (0.10, 0.10, 0.10), 0.7, 0.0),
|
||||
)
|
||||
ROOF_DEFAULT = ((0.34, 0.30, 0.28), 0.75, 0.0)
|
||||
BUILDING_LOOKS = (
|
||||
(("backstein", "ziegel"), (0.60, 0.31, 0.22), 0.8, 0.0),
|
||||
(("beton",), (0.52, 0.52, 0.50), 0.85, 0.0),
|
||||
(("holz", "parkett", "lattung", "schalung", "bsp", "brettsperr"), (0.56, 0.40, 0.24), 0.65, 0.0),
|
||||
(("stahl", "metall", "alu"), (0.55, 0.57, 0.58), 0.4, 1.0),
|
||||
(("naturstein", "marmor", "granit"), (0.62, 0.60, 0.57), 0.5, 0.0),
|
||||
(("keramik", "fliese", "platte"), (0.75, 0.74, 0.72), 0.3, 0.0),
|
||||
)
|
||||
GRASS_SRGB = (0.33, 0.45, 0.18)
|
||||
CONTEXT_SRGB = (0.78, 0.78, 0.77)
|
||||
|
||||
|
||||
def pick_look(table, text):
|
||||
for words, color, rough, metal in table:
|
||||
if any(w in text for w in words):
|
||||
return color, rough, metal
|
||||
return None
|
||||
|
||||
|
||||
def flat_look(mat, spec):
|
||||
"""Material ohne Bildkarte: Farbe/Rauheit/Metall nach Verwendung (`role`), Baustoffname und gesetzter Farbe."""
|
||||
bsdf = principled(mat)
|
||||
if bsdf is None:
|
||||
return
|
||||
role = spec.get("role")
|
||||
text = (spec.get("component") or spec.get("name") or "").lower()
|
||||
color = tuple(spec.get("color") or (1.0, 1.0, 1.0))
|
||||
rough = float(spec.get("roughness", 0.9))
|
||||
metal = float(spec.get("metallic", 0.0))
|
||||
srgb = None
|
||||
if role == "terrain":
|
||||
srgb, rough, metal = GRASS_SRGB, 0.95, 0.0
|
||||
elif role == "context":
|
||||
srgb, rough, metal = CONTEXT_SRGB, 0.9, 0.0
|
||||
elif role == "roof":
|
||||
hit = pick_look(ROOF_LOOKS, text)
|
||||
if hit:
|
||||
srgb, rough, metal = hit
|
||||
elif is_unset(color):
|
||||
srgb, rough, metal = ROOF_DEFAULT
|
||||
# sonst gesetzte Farbe behalten
|
||||
elif is_unset(color):
|
||||
hit = pick_look(BUILDING_LOOKS, text)
|
||||
if hit:
|
||||
srgb, rough, metal = hit
|
||||
if srgb is not None:
|
||||
color = srgb
|
||||
set_input(bsdf, ("Base Color",), (*clamp_albedo(lin(color)), 1.0))
|
||||
set_input(bsdf, ("Roughness",), rough)
|
||||
set_input(bsdf, ("Metallic",), metal)
|
||||
|
||||
|
||||
def base_color_of(mat):
|
||||
bsdf = principled(mat)
|
||||
s = socket(bsdf, "Base Color") if bsdf is not None else None
|
||||
return tuple(s.default_value)[:3] if s is not None else None
|
||||
|
||||
|
||||
def pick_spec(mat, candidates):
|
||||
"""Mehrere Eintraege gleichen Namens (z. B. zwei "Oeffnungsteil" in verschiedener Farbe): der mit der naechsten Farbe."""
|
||||
if len(candidates) == 1:
|
||||
return candidates[0]
|
||||
have = base_color_of(mat)
|
||||
if have is None:
|
||||
return candidates[0]
|
||||
def dist(spec):
|
||||
want = lin(spec.get("color") or (1.0, 1.0, 1.0))
|
||||
return sum(abs(a - b) for a, b in zip(have, want))
|
||||
return min(candidates, key=dist)
|
||||
|
||||
|
||||
def apply_materials(specs, base_dir):
|
||||
stage("materials")
|
||||
by_name = {s["name"]: s for s in specs}
|
||||
by_name = {}
|
||||
for s in specs:
|
||||
by_name.setdefault(s["name"], []).append(s)
|
||||
for mat in bpy.data.materials:
|
||||
spec = by_name.get(mat.name) or by_name.get(strip_suffix(mat.name))
|
||||
if spec is None:
|
||||
candidates = by_name.get(mat.name) or by_name.get(strip_suffix(mat.name))
|
||||
if not candidates:
|
||||
continue
|
||||
spec = pick_spec(mat, candidates)
|
||||
ensure_nodes(mat)
|
||||
if spec.get("glass"):
|
||||
make_glass(mat, spec)
|
||||
else:
|
||||
add_textures(mat, spec, base_dir)
|
||||
elif not add_textures(mat, spec, base_dir):
|
||||
flat_look(mat, spec)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- Kamera
|
||||
@@ -290,11 +443,17 @@ def make_sky(sun):
|
||||
sky.sun_rotation = math.radians(float(sun.get("azimuth", 180.0)) % 360.0)
|
||||
sky.sun_disc = True
|
||||
sky.sun_size = math.radians(0.545)
|
||||
sky.sun_intensity = float(sun.get("intensity", 0.3))
|
||||
sky.sun_intensity = float(sun.get("intensity", 1.0))
|
||||
# Luft/Staub (Blender 3.x/4.x: air_density, dust_density; 5.x: aerosol_density) — nur setzen, was es gibt.
|
||||
for name in ("air_density", "dust_density", "aerosol_density"):
|
||||
for name in ("air_density", "dust_density", "aerosol_density", "ozone_density"):
|
||||
if hasattr(sky, name):
|
||||
setattr(sky, name, 1.0)
|
||||
# Leichte Umgebungsverdeckung (Cycles-Weltoption, in Blender 5 nur noch ao_factor/distance): dunkelt Ecken und Fugen
|
||||
# sanft ab, ohne die globale Beleuchtung zu ersetzen.
|
||||
ls = getattr(world, "light_settings", None)
|
||||
if ls is not None and hasattr(ls, "ao_factor"):
|
||||
ls.ao_factor = 0.4
|
||||
ls.distance = 1.5
|
||||
bg = nt.nodes.new("ShaderNodeBackground")
|
||||
out = nt.nodes.new("ShaderNodeOutputWorld")
|
||||
nt.links.new(sky.outputs["Color"], bg.inputs["Color"])
|
||||
@@ -315,7 +474,8 @@ def add_ground(objects):
|
||||
bpy.context.scene.collection.objects.link(obj)
|
||||
mat = bpy.data.materials.new("Boden")
|
||||
bsdf = principled(mat)
|
||||
set_input(bsdf, ("Base Color",), (0.30, 0.32, 0.28, 1.0))
|
||||
# Erdig-gruen, matter als die Wiese des Gelaendes (Albedo von Gras/Erde ~0.1 bis 0.2 linear).
|
||||
set_input(bsdf, ("Base Color",), (*lin((0.40, 0.46, 0.28)), 1.0))
|
||||
set_input(bsdf, ("Roughness",), 0.95)
|
||||
obj.data.materials.append(mat)
|
||||
|
||||
@@ -347,6 +507,29 @@ def setup_device(scene, wanted):
|
||||
return "CPU"
|
||||
|
||||
|
||||
# Gemessene Strahldichte einer weissen (Albedo 1), waagrechten, besonnten Flaeche im Nishita-Himmel bei Sonnenstaerke 1.0
|
||||
# (Cycles, Blender 5.3, Mittel ueber Sonne + Himmel, Luminanz) nach Sonnenhoehe in Grad. Die Werte sind weit ueber 1.0: Nishita
|
||||
# rechnet absolut (Mittagssonne ~ 100 000 lx), die Kamera muss das wie in der Fotografie belichten.
|
||||
SUNLIT_WHITE = ((1, 0.65), (3, 1.5), (6, 3.3), (10, 6.4), (15, 10.9), (20, 14.9), (30, 23.7), (45, 34.9), (60, 43.5), (70, 47.5), (90, 50.8))
|
||||
# Gewuenschte Szenenhelligkeit einer weissen besonnten Flaeche (Albedo 1). Weisser Putz (0.8) liegt dann bei ~1.2, noch unter dem
|
||||
# Weisspunkt der AgX-Kurve (Lichter laufen weich aus), Mittelgrau 0.18 bei ~0.27 (mittlere Anzeigehelligkeit).
|
||||
SUNLIT_TARGET = 1.5
|
||||
|
||||
|
||||
def auto_exposure(sun):
|
||||
"""Belichtung in EV wie eine Kamera mit Belichtungsautomatik: besonnte weisse Flaeche -> SUNLIT_TARGET, je nach
|
||||
Sonnenhoehe (tiefe Sonne = weniger Licht = hellere Belichtung) und Sonnenstaerke. Sonst brennt Weiss aus (Nishita ~ 45 bei 60 Grad)."""
|
||||
elevation = max(float(sun.get("elevation", 40.0)), 1.0)
|
||||
strength = max(float(sun.get("intensity", 1.0)), 1e-3)
|
||||
value = SUNLIT_WHITE[-1][1]
|
||||
for (e0, v0), (e1, v1) in zip(SUNLIT_WHITE, SUNLIT_WHITE[1:]):
|
||||
if elevation <= e1:
|
||||
f = max(0.0, (elevation - e0) / (e1 - e0))
|
||||
value = math.exp(math.log(v0) * (1.0 - f) + math.log(v1) * f)
|
||||
break
|
||||
return max(-8.0, min(3.0, -math.log2(value * strength / SUNLIT_TARGET)))
|
||||
|
||||
|
||||
def setup_cycles(spec):
|
||||
scene = bpy.context.scene
|
||||
scene.render.engine = "CYCLES"
|
||||
@@ -362,9 +545,21 @@ def setup_cycles(spec):
|
||||
scene.cycles.denoiser = "OPENIMAGEDENOISE"
|
||||
except Exception:
|
||||
pass
|
||||
# Sonniges Bild ohne ausgebrannte Flaechen: Sonnenstaerke und Belichtung zurueck (mit dem Blender-Standard
|
||||
# sind helle Putzflaechen im Sonnenlicht ausgebrannt). Beides in scene.json uebersteuerbar (`sun.intensity`, `exposure`).
|
||||
scene.view_settings.exposure = float(spec.get("exposure", -1.5))
|
||||
# Standard-Belichtung (0 EV) mit AgX (Filmic, wo es fehlt): die Farbumsetzung komprimiert Lichter, Weiss frisst nicht aus.
|
||||
# In scene.json uebersteuerbar (`exposure` in EV, `sun.intensity`).
|
||||
for transform in ("AgX", "Filmic", "Standard"):
|
||||
try:
|
||||
scene.view_settings.view_transform = transform
|
||||
break
|
||||
except TypeError:
|
||||
continue
|
||||
for look in ("AgX - Medium High Contrast", "Medium High Contrast"):
|
||||
try:
|
||||
scene.view_settings.look = look
|
||||
break
|
||||
except TypeError:
|
||||
continue
|
||||
scene.view_settings.exposure = float(spec["exposure"]) if "exposure" in spec else auto_exposure(spec.get("sun") or {})
|
||||
scene.cycles.max_bounces = 8
|
||||
# Glas-Abpraller heissen je nach Version `glass_bounces` (3.x) oder `transmission_bounces` (4.x+).
|
||||
for name in ("transmission_bounces", "glass_bounces"):
|
||||
|
||||
+9
-3
@@ -36,7 +36,7 @@
|
||||
// [154] Bauteile aus 2D-Zeichnung erkennen (Wände, Öffnungen, Räume
|
||||
// ins Geschoss); Bericht als JSON. Z. B. convert plan.dxf p.obp --cmd "erkennen --out e.obp"
|
||||
// dossier-cli <projekt.obp> render --out bild.png [--view iso|perspective|front|back|left|right|top] [--when 2026-06-21T10:00Z]
|
||||
// [--samples 128] [--size 1920x1080] [--cpu] [--blender pfad] [--keep] [211] Rendering mit Blender/Cycles
|
||||
// [--camera Name|id] [--samples 128] [--size 1920x1080] [--cpu] [--blender pfad] [--keep] [211] Rendering mit Blender/Cycles
|
||||
// dossier-cli <projekt.obp> model3d [--explode 3] [--hide …] [--grey …] [--out modell.json] 3D-Modell fürs Headless-Rendern (render_png)
|
||||
// dossier-cli pointcloud-info <datei.las|laz|e57|ply|xyz|pts> [--voxel 0.05] [--max 2000000]
|
||||
// Punktwolke lesen ([B9]) und Bericht als JSON (ohne Projekt)
|
||||
@@ -152,6 +152,8 @@ import {
|
||||
BLENDER_CANDIDATES,
|
||||
BLENDER_DOWNLOAD_URL,
|
||||
RENDER_VIEW_PRESETS,
|
||||
findRenderCamera,
|
||||
projectRenderCameras,
|
||||
} from "../core";
|
||||
import type { BlenderHost, Filter3d, Project, RenderViewPreset, TextureLoader, ViewTemplate } from "../core";
|
||||
import { serveStdio } from "./mcp";
|
||||
@@ -765,8 +767,12 @@ function nodeBlenderHost(keep: boolean): BlenderHost {
|
||||
async function runRender(project: Project, args: Args): Promise<number> {
|
||||
const view = (args.flags.get("view") ?? "iso") as RenderViewPreset;
|
||||
if (!(RENDER_VIEW_PRESETS as readonly string[]).includes(view)) return fail(`--view: ${RENDER_VIEW_PRESETS.join("|")}`);
|
||||
// [213] `--camera <Name|id>`: gespeicherte Kamera (Standpunkt, Ziel, Bildwinkel; Sonnenzeit der Kamera, falls `--when` fehlt).
|
||||
const camKey = args.flags.get("camera");
|
||||
const choice = camKey ? findRenderCamera(project, camKey) : null;
|
||||
if (camKey && !choice) return fail(`--camera: "${camKey}" nicht gefunden (vorhanden: ${projectRenderCameras(project).map((c) => c.name).join(", ") || "keine"})`);
|
||||
const whenText = args.flags.get("when");
|
||||
const when = whenText ? new Date(whenText) : defaultRenderTime(project);
|
||||
const when = whenText ? new Date(whenText) : (choice?.sunWhen ?? defaultRenderTime(project));
|
||||
if (Number.isNaN(when.getTime())) return fail("--when: ungültiges Datum");
|
||||
const samples = Number(args.flags.get("samples") ?? 128);
|
||||
if (!Number.isFinite(samples) || samples < 1) return fail("--samples: Zahl ≥ 1");
|
||||
@@ -776,7 +782,7 @@ async function runRender(project: Project, args: Args): Promise<number> {
|
||||
await loadFileio();
|
||||
const pkg = await buildRenderPackage(
|
||||
project,
|
||||
{ width: Number(m[1]), height: Number(m[2]), samples, when, camera: { preset: view }, device: args.flags.has("cpu") ? "cpu" : "auto" },
|
||||
{ width: Number(m[1]), height: Number(m[2]), samples, when, camera: choice ? choice.camera : { preset: view }, device: args.flags.has("cpu") ? "cpu" : "auto" },
|
||||
localTextureLoader(),
|
||||
);
|
||||
if (pkg.missingTextures.length > 0) process.stderr.write(`Hinweis: ${pkg.missingTextures.length} Bildkarten nicht lesbar (Material erscheint einfarbig)\n`);
|
||||
|
||||
@@ -64,6 +64,30 @@ describe("dossier-cli render", () => {
|
||||
expect(scene.sun.elevation).toBeGreaterThan(40);
|
||||
}, 60_000);
|
||||
|
||||
it("--camera: gespeicherte Kamera und deren Sonnenzeit (--when übersteuert)", async () => {
|
||||
const err = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
||||
try {
|
||||
expect(await run([":musterhaus-komplex", "render", "--out", join(dir, "k.png"), "--camera", "Südost", "--samples", "8", "--size", "320x180", "--cpu", "--blender", fake])).toBe(0);
|
||||
const scene = JSON.parse(readFileSync(join(dir, "fake-scene.json"), "utf8"));
|
||||
expect(scene.camera.kind).toBe("perspective");
|
||||
expect(scene.camera.position[0]).toBeCloseTo(17, 6);
|
||||
expect(scene.camera.position[1]).toBeCloseTo(-3, 6);
|
||||
expect(scene.camera.fovDeg).toBe(50);
|
||||
expect(scene.sun.when).toBe("2026-06-21T16:00:00.000Z");
|
||||
expect(await run([":musterhaus-komplex", "render", "--out", join(dir, "k2.png"), "--camera", "kamera-suedost", "--when", "2026-06-21T08:00Z", "--samples", "8", "--size", "320x180", "--cpu", "--blender", fake])).toBe(0);
|
||||
expect(JSON.parse(readFileSync(join(dir, "fake-scene.json"), "utf8")).sun.when).toBe("2026-06-21T08:00:00.000Z");
|
||||
// `fail()` beendet den Prozess: hier als Ausnahme abfangen.
|
||||
const exit = vi.spyOn(process, "exit").mockImplementation((() => {
|
||||
throw new Error("exit");
|
||||
}) as never);
|
||||
await expect(run([":musterhaus-komplex", "render", "--out", join(dir, "k3.png"), "--camera", "gibt-es-nicht", "--blender", fake])).rejects.toThrow("exit");
|
||||
exit.mockRestore();
|
||||
expect(err.mock.calls.map((c) => String(c[0])).join("")).toContain("--camera");
|
||||
} finally {
|
||||
err.mockRestore();
|
||||
}
|
||||
}, 120_000);
|
||||
|
||||
it("ohne Blender: Hinweis und Exit-Code 3", async () => {
|
||||
const err = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
||||
try {
|
||||
|
||||
+2
-1
@@ -100,6 +100,7 @@ export type { MeshRect } from "../geometry/meshPick";
|
||||
// [211] Rendering mit Blender/Cycles: Export-Paket, Prozess-Ablauf (Gastgeber: Tauri/Electron/Node)
|
||||
export {
|
||||
buildRenderPackage, runBlenderRender, parseBlenderLine, blenderArgs, glbMaterials, renderSun, defaultRenderTime, paperPixels,
|
||||
projectRenderCameras, findRenderCamera,
|
||||
BlenderMissingError, RenderCancelled, RENDER_SIZE_PRESETS, RENDER_QUALITY_PRESETS, RENDER_VIEW_PRESETS, BLENDER_CANDIDATES, BLENDER_DOWNLOAD_URL,
|
||||
} from "../export/blenderRender";
|
||||
export type { BlenderHost, RenderPackage, RenderOptions, RenderScene, RenderCamera, RenderCameraSpec, RenderViewPreset, RenderMaterial, TextureLoader, BlenderEvent, RenderResult, RenderRunOptions } from "../export/blenderRender";
|
||||
export type { BlenderHost, RenderPackage, RenderOptions, RenderScene, RenderCamera, RenderCameraSpec, RenderViewPreset, RenderMaterial, RenderRole, RenderCameraChoice, TextureLoader, BlenderEvent, RenderResult, RenderRunOptions } from "../export/blenderRender";
|
||||
@@ -20,10 +20,16 @@ import {
|
||||
parseBlenderLine,
|
||||
renderSun,
|
||||
runBlenderRender,
|
||||
findRenderCamera,
|
||||
projectRenderCameras,
|
||||
renderCameraOf,
|
||||
splitRoofMaterials,
|
||||
TERRAIN_MATERIAL,
|
||||
type BlenderHost,
|
||||
type RenderOptions,
|
||||
} from "./blenderRender";
|
||||
import { exportGlb } from "./exportMesh";
|
||||
import { cameraToView } from "../viewport/cameraView";
|
||||
|
||||
const when = new Date(Date.UTC(2026, 5, 21, 10, 0, 0));
|
||||
const opts = (over: Partial<RenderOptions> = {}): RenderOptions => ({ width: 640, height: 360, samples: 16, when, camera: { preset: "iso" }, ...over });
|
||||
@@ -232,3 +238,105 @@ describe("Blender-Skript", () => {
|
||||
expect(r.status, String(r.stderr)).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Materialzuordnung Gelände und Dach ([211])", () => {
|
||||
const mk = buildComplexSampleProject();
|
||||
|
||||
it("Dachschichten bekommen eigene Materialien nach Baustoff (Ziegel, Kies, Blech), nicht mehr alle „Dach“", async () => {
|
||||
const pkg = await buildRenderPackage(mk, opts(), async () => new Uint8Array([1]));
|
||||
const roofs = pkg.scene.materials.filter((m) => m.role === "roof");
|
||||
const names = roofs.map((m) => m.name);
|
||||
expect(names).toContain("Dach: Tonziegel");
|
||||
expect(names).toContain("Dach: Kies / Sauberkeitsschicht");
|
||||
expect(names).toContain("Dach: Trapezblech");
|
||||
expect(names).not.toContain("Dach");
|
||||
const tile = roofs.find((m) => m.name === "Dach: Tonziegel")!;
|
||||
expect(tile.component).toBe("Tonziegel");
|
||||
// Bildkarten des Baustoffs „Tonziegel“ (RoofingTiles013A), nicht des Namens „Dach“.
|
||||
expect(tile.textures?.color).toBeDefined();
|
||||
expect(tile.sizeM).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("das neue GLB bleibt gültig und die Dachknoten zeigen auf die neuen Materialien", () => {
|
||||
const glb = splitRoofMaterials(exportGlb(mk), mk);
|
||||
const dv = new DataView(glb.buffer, glb.byteOffset, glb.byteLength);
|
||||
expect(dv.getUint32(0, true)).toBe(0x46546c67);
|
||||
expect(dv.getUint32(8, true)).toBe(glb.byteLength);
|
||||
expect(dv.getUint32(12, true) % 4).toBe(0);
|
||||
const json = JSON.parse(new TextDecoder().decode(glb.subarray(20, 20 + dv.getUint32(12, true))));
|
||||
// BIN-Chunk dahinter unverändert vorhanden.
|
||||
const binLen = dv.getUint32(20 + dv.getUint32(12, true), true);
|
||||
expect(20 + dv.getUint32(12, true) + 8 + binLen).toBe(glb.byteLength);
|
||||
const roofNode = json.nodes.find((n: { name?: string }) => n.name === "Dach_dach-haupt");
|
||||
const used = json.meshes[roofNode.mesh].primitives.map((p: { material: number }) => json.materials[p.material].name);
|
||||
expect(used).toEqual(["Dach: Tonziegel"]);
|
||||
});
|
||||
|
||||
it("Gelände: Rolle terrain mit Wiese aus der Bibliothek; ohne Bildkarten bleibt die Rolle für den Leser", async () => {
|
||||
const pkg = await buildRenderPackage(mk, opts(), async () => new Uint8Array([1]));
|
||||
const terrain = pkg.scene.materials.find((m) => m.name === "Gelaende")!;
|
||||
expect(terrain.role).toBe("terrain");
|
||||
expect(terrain.textures?.color).toMatch(/^textures\/\d+_color\.jpg$/);
|
||||
expect(terrain.sizeM).toBe(TERRAIN_MATERIAL.sizeM);
|
||||
expect(TERRAIN_MATERIAL.libraryId).toBe("Grass005");
|
||||
const bare = await buildRenderPackage(mk, opts());
|
||||
const t2 = bare.scene.materials.find((m) => m.name === "Gelaende")!;
|
||||
expect(t2.role).toBe("terrain");
|
||||
expect(t2.textures).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Glas und Öffnungsteile haben ihre Rolle, Wände „building“", async () => {
|
||||
const pkg = await buildRenderPackage(mk, opts());
|
||||
expect(pkg.scene.materials.find((m) => m.glass)?.role).toBe("opening");
|
||||
expect(pkg.scene.materials.find((m) => m.name === "Aussenputz")?.role).toBe("building");
|
||||
});
|
||||
|
||||
it("jedes Material des GLB hat eine Rolle und kommt in der Tabelle vor, nicht benutzte (altes „Dach“) fehlen", () => {
|
||||
const mats = glbMaterials(splitRoofMaterials(exportGlb(mk), mk));
|
||||
expect(mats.every((m) => m.role)).toBe(true);
|
||||
expect(mats.some((m) => m.name === "Dach")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Kamera wählen ([213])", () => {
|
||||
const mk = buildComplexSampleProject();
|
||||
|
||||
it("Südost: gleiche Sicht wie cameraToView, Sonnenzeit der Kamera", () => {
|
||||
const choice = findRenderCamera(mk, "Südost")!;
|
||||
expect(choice).toBeTruthy();
|
||||
expect(choice.id).toBe("kamera-suedost");
|
||||
const cam = mk.cameras![0];
|
||||
const view = cameraToView(mk, cam)!;
|
||||
expect(choice.camera.position).toEqual(view.position);
|
||||
expect(choice.camera.direction).toEqual(view.direction);
|
||||
expect(choice.camera.up).toEqual(view.up);
|
||||
expect(choice.camera.fovDeg).toBe(view.fovDeg);
|
||||
expect(choice.camera.kind).toBe(view.kind);
|
||||
expect(choice.camera.orthoHeight).toBe(view.orthoHeight);
|
||||
expect(choice.sunWhen?.toISOString()).toBe("2026-06-21T16:00:00.000Z");
|
||||
// Augenhöhe 1.6 m über OK EG.
|
||||
expect(choice.camera.position[2]).toBeCloseTo(1.6 + (mk.drawingLevels.find((l) => l.id === "eg")?.baseElevation ?? 0), 9);
|
||||
});
|
||||
|
||||
it("Suche nach Id oder Name (Schreibweise egal), unbekannt = null", () => {
|
||||
expect(findRenderCamera(mk, "kamera-suedost")?.name).toBe("Südost");
|
||||
expect(findRenderCamera(mk, "südost")?.id).toBe("kamera-suedost");
|
||||
expect(findRenderCamera(mk, "gibt es nicht")).toBeNull();
|
||||
expect(projectRenderCameras(sampleProject)).toEqual([]);
|
||||
});
|
||||
|
||||
it("entartete Kamera (Standpunkt = Ziel) fällt aus der Liste", () => {
|
||||
const cam = { ...mk.cameras![0], target: { ...mk.cameras![0].position } };
|
||||
expect(renderCameraOf(mk, { ...cam, targetHeight: 1.6 })).toBeNull();
|
||||
expect(projectRenderCameras({ ...mk, cameras: [{ ...cam, targetHeight: 1.6 }] })).toEqual([]);
|
||||
});
|
||||
|
||||
it("das Paket trägt die Kamera und die Sonne der Kamera", async () => {
|
||||
const choice = findRenderCamera(mk, "Südost")!;
|
||||
const pkg = await buildRenderPackage(mk, opts({ camera: choice.camera, when: choice.sunWhen! }));
|
||||
expect(pkg.scene.camera).toEqual(choice.camera);
|
||||
expect(pkg.scene.sun.when).toBe("2026-06-21T16:00:00.000Z");
|
||||
// Abendsonne: tiefer als zur Vormittagszeit des Projekts.
|
||||
expect(pkg.scene.sun.elevation).toBeLessThan(renderSun(mk, defaultRenderTime(mk)).elevation);
|
||||
});
|
||||
});
|
||||
+202
-11
@@ -9,7 +9,9 @@
|
||||
// UV-Koordinaten: das GLB hat keine. Texturen legt das Skript per Box-Projektion über Objektkoordinaten
|
||||
// (Kachelgrösse `sizeM` des Materials in Metern), das ersetzt UVs ohne den Rust-Exporter anzufassen.
|
||||
// Materialzuordnung: der glTF-Materialname ist der Bauteilname (`Component.name`); dessen `material` (ambientCG-
|
||||
// Karten) kommt als Textur-Eintrag in die Materialtabelle. Verglasung (Deckkraft < 1) bekommt `glass: true`.
|
||||
// Karten) kommt als Textur-Eintrag in die Materialtabelle. Verglasung (Deckkraft < 1) bekommt `glass: true`. Dachschichten
|
||||
// bekommen je Baustoff ein eigenes Material (`splitRoofMaterials`), das Gelände die Wiese `Grass005`, jedes Material seine
|
||||
// Verwendung (`role`, aus dem Knoten des GLB) — der Leser wählt danach Ersatzlooks ohne Bildkarte.
|
||||
//
|
||||
// Das Format ist renderer-neutral und in `doc/RENDER-SZENE.md` beschrieben (Blender-Skript = ein Leser davon;
|
||||
// später auch Cycles-Standalone, [215]).
|
||||
@@ -17,7 +19,7 @@
|
||||
// Achsen in `scene.json`: Modell-Koordinaten (x Ost, y Nord, z oben, Meter) — Blenders glTF-Import dreht das
|
||||
// Y-oben-GLB genau dorthin zurück, Kamera und Sonne brauchen im Skript keine Umrechnung.
|
||||
|
||||
import type { ComponentMaterial, LayoutOrientation, LayoutPaperFormat, Project } from "../model/types";
|
||||
import type { Camera, ComponentMaterial, LayoutOrientation, LayoutPaperFormat, Project } from "../model/types";
|
||||
import { projectLatLon, sunPosition } from "../analysis/sun";
|
||||
import { sheetSizeMm } from "../model/layoutModel";
|
||||
import { exportGlb } from "./exportMesh";
|
||||
@@ -100,8 +102,15 @@ export interface RenderMaterial {
|
||||
textures?: Partial<Record<TextureKind, string>>;
|
||||
/** Kantenlänge einer Texturkachel in Metern. */
|
||||
sizeM?: number;
|
||||
/** Wofür das Material gebraucht wird (aus dem Bauteil-Knoten des GLB); der Leser wählt danach Ersatzlooks (Wiese, Ziegel, Kontext). */
|
||||
role?: RenderRole;
|
||||
/** Name des Bauteils (Baustoff), dessen Aussehen gilt, wenn er vom Materialnamen abweicht (Dachschicht: `Dach: Tonziegel`). */
|
||||
component?: string;
|
||||
}
|
||||
|
||||
/** Verwendung eines Materials: Gelände, Dach, Kontext-Körper (Nachbarn), Öffnungsteile, sonst Gebäude. */
|
||||
export type RenderRole = "terrain" | "roof" | "context" | "opening" | "building";
|
||||
|
||||
export type TextureKind = "color" | "normal" | "roughness" | "metalness";
|
||||
const TEXTURE_KINDS: TextureKind[] = ["color", "normal", "roughness", "metalness"];
|
||||
|
||||
@@ -134,7 +143,7 @@ export function defaultRenderTime(project: Project): Date {
|
||||
}
|
||||
|
||||
/** JSON-Chunk eines GLB. */
|
||||
function glbJson(glb: Uint8Array): { materials?: GltfMaterial[] } {
|
||||
function glbJson(glb: Uint8Array): GltfJson {
|
||||
const dv = new DataView(glb.buffer, glb.byteOffset, glb.byteLength);
|
||||
if (glb.byteLength < 20 || dv.getUint32(0, true) !== 0x46546c67) throw new Error("Kein GLB");
|
||||
const len = dv.getUint32(12, true);
|
||||
@@ -144,32 +153,145 @@ function glbJson(glb: Uint8Array): { materials?: GltfMaterial[] } {
|
||||
interface GltfMaterial {
|
||||
name?: string;
|
||||
alphaMode?: string;
|
||||
extras?: { component?: string };
|
||||
pbrMetallicRoughness?: { baseColorFactor?: number[]; metallicFactor?: number; roughnessFactor?: number };
|
||||
}
|
||||
|
||||
interface GltfJson {
|
||||
materials?: GltfMaterial[];
|
||||
meshes?: { name?: string; primitives: { material?: number }[] }[];
|
||||
nodes?: { name?: string; mesh?: number; extras?: { type?: string; id?: string } }[];
|
||||
}
|
||||
|
||||
/** GLB mit geändertem JSON-Chunk (BIN-Chunk unverändert; Länge auf 4 Byte aufgefüllt). */
|
||||
function glbWithJson(glb: Uint8Array, json: GltfJson): Uint8Array {
|
||||
const dv = new DataView(glb.buffer, glb.byteOffset, glb.byteLength);
|
||||
const oldLen = dv.getUint32(12, true);
|
||||
const rest = glb.subarray(20 + oldLen);
|
||||
const bytes = new TextEncoder().encode(JSON.stringify(json));
|
||||
const padded = new Uint8Array(Math.ceil(bytes.length / 4) * 4).fill(0x20);
|
||||
padded.set(bytes);
|
||||
const out = new Uint8Array(20 + padded.length + rest.length);
|
||||
const odv = new DataView(out.buffer);
|
||||
out.set(glb.subarray(0, 4), 0);
|
||||
odv.setUint32(4, dv.getUint32(4, true), true);
|
||||
odv.setUint32(8, out.length, true);
|
||||
odv.setUint32(12, padded.length, true);
|
||||
out.set(glb.subarray(16, 20), 16);
|
||||
out.set(padded, 20);
|
||||
out.set(rest, 20 + padded.length);
|
||||
return out;
|
||||
}
|
||||
|
||||
const linearToSrgb = (c: number): number => {
|
||||
const x = Math.min(1, Math.max(0, c));
|
||||
return x <= 0.0031308 ? x * 12.92 : 1.055 * Math.pow(x, 1 / 2.4) - 0.055;
|
||||
};
|
||||
|
||||
/** Materialien eines GLB (glTF speichert die Farbe linear, hier sRGB). */
|
||||
const hexToLinear = (hex: string): [number, number, number] | null => {
|
||||
const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
|
||||
if (!m) return null;
|
||||
const c = (i: number) => {
|
||||
const v = parseInt(m[1].slice(i, i + 2), 16) / 255;
|
||||
return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
|
||||
};
|
||||
return [c(0), c(2), c(4)];
|
||||
};
|
||||
|
||||
/**
|
||||
* Dachschichten als eigene Materialien. Der Kern legt alle Dachteile unter den Namen „Dach" ab (gleiche Farbe =
|
||||
* ein Material), darum hängt „Ziegel" am selben Material wie „Kies", und Texturen lassen sich nicht zuordnen.
|
||||
* Hier bekommt jedes Dach-Teilnetz ein Material `Dach: <Baustoff>`: die Schicht des Dachtyps (aussen → innen),
|
||||
* deren Baustoff-Farbe die des Teilnetzes ist (sichtbar ist die äusserste), Rückfall die äusserste Schicht.
|
||||
* Hat das Dach eine eigene Farbe (`Roof.color`), bleibt es bei dieser (ohne Baustoff-Textur).
|
||||
*/
|
||||
export function splitRoofMaterials(glb: Uint8Array, project: Project): Uint8Array {
|
||||
const json = glbJson(glb);
|
||||
const mats = json.materials ?? [];
|
||||
const roofById = new Map((project.roofs ?? []).map((r) => [r.id, r]));
|
||||
const made = new Map<string, number>();
|
||||
let changed = false;
|
||||
for (const node of json.nodes ?? []) {
|
||||
if (node.extras?.type !== "roof" || node.mesh === undefined) continue;
|
||||
const roof = roofById.get(node.extras.id ?? "");
|
||||
const type = roof?.roofTypeId ? project.roofTypes?.find((t) => t.id === roof.roofTypeId) : undefined;
|
||||
if (!roof || roof.color || !type || type.layers.length === 0) continue;
|
||||
const layers = type.layers.map((l) => project.components.find((c) => c.id === l.componentId)).filter((c): c is NonNullable<typeof c> => !!c);
|
||||
if (layers.length === 0) continue;
|
||||
for (const prim of json.meshes?.[node.mesh]?.primitives ?? []) {
|
||||
const src = prim.material === undefined ? undefined : mats[prim.material];
|
||||
if (!src || src.name !== "Dach") continue;
|
||||
const f = src.pbrMetallicRoughness?.baseColorFactor ?? [1, 1, 1, 1];
|
||||
const close = (a: [number, number, number] | null) => a !== null && Math.abs(a[0] - f[0]) + Math.abs(a[1] - f[1]) + Math.abs(a[2] - f[2]) < 0.02;
|
||||
const comp = layers.find((c) => close(hexToLinear(c.color))) ?? layers[0];
|
||||
const key = `${comp.name}|${prim.material}`;
|
||||
let idx = made.get(key);
|
||||
if (idx === undefined) {
|
||||
idx = mats.length;
|
||||
mats.push({ ...src, name: `Dach: ${comp.name}`, extras: { component: comp.name } });
|
||||
made.set(key, idx);
|
||||
}
|
||||
prim.material = idx;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed ? glbWithJson(glb, { ...json, materials: mats }) : glb;
|
||||
}
|
||||
|
||||
/** Verwendung je Material aus den Knoten (`extras.type`); bei mehreren gewinnt Gelände vor Kontext, Dach, Öffnung, Gebäude. */
|
||||
const ROLE_PRIORITY: RenderRole[] = ["terrain", "context", "roof", "opening", "building"];
|
||||
function roleOfNode(type: string | undefined): RenderRole {
|
||||
switch (type) {
|
||||
case "terrain":
|
||||
return "terrain";
|
||||
case "context":
|
||||
return "context";
|
||||
case "roof":
|
||||
return "roof";
|
||||
case "window":
|
||||
case "door":
|
||||
case "opening":
|
||||
return "opening";
|
||||
default:
|
||||
return "building";
|
||||
}
|
||||
}
|
||||
|
||||
/** Materialien eines GLB (glTF speichert die Farbe linear, hier sRGB), mit Verwendung; nicht benutzte entfallen. */
|
||||
export function glbMaterials(glb: Uint8Array): RenderMaterial[] {
|
||||
const json = glbJson(glb);
|
||||
const roles = new Map<number, RenderRole>();
|
||||
for (const node of json.nodes ?? []) {
|
||||
if (node.mesh === undefined) continue;
|
||||
const role = roleOfNode(node.extras?.type);
|
||||
for (const prim of json.meshes?.[node.mesh]?.primitives ?? []) {
|
||||
if (prim.material === undefined) continue;
|
||||
const prev = roles.get(prim.material);
|
||||
if (!prev || ROLE_PRIORITY.indexOf(role) < ROLE_PRIORITY.indexOf(prev)) roles.set(prim.material, role);
|
||||
}
|
||||
}
|
||||
const out: RenderMaterial[] = [];
|
||||
for (const m of glbJson(glb).materials ?? []) {
|
||||
(json.materials ?? []).forEach((m, i) => {
|
||||
const p = m.pbrMetallicRoughness ?? {};
|
||||
const f = p.baseColorFactor ?? [1, 1, 1, 1];
|
||||
const opacity = f[3] ?? 1;
|
||||
const glass = m.alphaMode === "BLEND" && opacity < 1;
|
||||
const used = roles.get(i);
|
||||
// Materialien ohne Knoten (Altlasten nach `splitRoofMaterials`) lässt der Leser weg; ohne Knotenangaben (GLB fremder Herkunft) bleiben alle.
|
||||
if (!used && roles.size > 0) return;
|
||||
out.push({
|
||||
name: m.name ?? "",
|
||||
color: [linearToSrgb(f[0] ?? 1), linearToSrgb(f[1] ?? 1), linearToSrgb(f[2] ?? 1)],
|
||||
opacity,
|
||||
roughness: p.roughnessFactor ?? 0.9,
|
||||
metallic: p.metallicFactor ?? 0,
|
||||
glass: m.alphaMode === "BLEND" && opacity < 1,
|
||||
transmission: m.alphaMode === "BLEND" && opacity < 1 ? 1 : 0,
|
||||
ior: m.alphaMode === "BLEND" && opacity < 1 ? 1.45 : 1.5,
|
||||
glass,
|
||||
transmission: glass ? 1 : 0,
|
||||
ior: 1.5,
|
||||
...(used ? { role: used } : {}),
|
||||
...(m.extras?.component ? { component: m.extras.component } : {}),
|
||||
});
|
||||
}
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -189,6 +311,15 @@ function extensionOf(url: string): string {
|
||||
return m ? m[1].toLowerCase() : "jpg";
|
||||
}
|
||||
|
||||
/** Wiese für das Gelände (ambientCG Grass005, im Material-Katalog `public/assets/materials`); Kachel 4 m. */
|
||||
export const TERRAIN_MATERIAL: ComponentMaterial = {
|
||||
libraryId: "Grass005",
|
||||
color: "/assets/materials/Grass005/color.jpg",
|
||||
normal: "/assets/materials/Grass005/normal.jpg",
|
||||
roughness: "/assets/materials/Grass005/roughness.jpg",
|
||||
sizeM: 4,
|
||||
};
|
||||
|
||||
/** Bauteil-Materialkarten nach glTF-Materialname (erste Komponente gleichen Namens mit Farbkarte gewinnt). */
|
||||
function componentMaterials(project: Project): Map<string, ComponentMaterial> {
|
||||
const byName = new Map<string, ComponentMaterial>();
|
||||
@@ -203,7 +334,7 @@ function componentMaterials(project: Project): Map<string, ComponentMaterial> {
|
||||
* Kamera, Sonne. Verlangt das geladene Format-Modul (`await loadFileio()`) und den Kern.
|
||||
*/
|
||||
export async function buildRenderPackage(project: Project, opts: RenderOptions, loadTexture?: TextureLoader): Promise<RenderPackage> {
|
||||
const glb = exportGlb(project);
|
||||
const glb = splitRoofMaterials(exportGlb(project), project);
|
||||
const files: RenderPackage["files"] = [{ path: "model.glb", bytes: glb }];
|
||||
const materials = glbMaterials(glb);
|
||||
const comp = componentMaterials(project);
|
||||
@@ -211,7 +342,8 @@ export async function buildRenderPackage(project: Project, opts: RenderOptions,
|
||||
const stored = new Map<string, string>();
|
||||
|
||||
for (const mat of materials) {
|
||||
const cm = comp.get(mat.name);
|
||||
// Gelände hat im Modell kein Material: Wiese aus der mitgelieferten Bibliothek (ohne Bildkarten übernimmt der Leser eine Wiesenfarbe).
|
||||
const cm = mat.role === "terrain" ? TERRAIN_MATERIAL : comp.get(mat.component ?? mat.name);
|
||||
if (!cm || mat.glass || !loadTexture) continue;
|
||||
const textures: Partial<Record<TextureKind, string>> = {};
|
||||
for (const kind of TEXTURE_KINDS) {
|
||||
@@ -253,6 +385,65 @@ export async function buildRenderPackage(project: Project, opts: RenderOptions,
|
||||
return { scene, files, missingTextures: missing };
|
||||
}
|
||||
|
||||
// ── Kameras ([213]) ─────────────────────────────────────────────────────────
|
||||
|
||||
/** Eine gespeicherte Kamera (`Project.cameras`) als Rendering-Kamera, mit ihrer Sonnenzeit. */
|
||||
export interface RenderCameraChoice {
|
||||
id: string;
|
||||
name: string;
|
||||
camera: RenderCamera;
|
||||
/** `Camera.sunWhen`, falls gesetzt und gültig. */
|
||||
sunWhen?: Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sicht einer Kamera in Modell-Koordinaten: Standpunkt = Fussboden des Geschosses + Augenhöhe, Blick zum Ziel,
|
||||
* Up aus der Senkrechten (bei senkrechtem Blick Norden). Gleiche Rechnung wie `viewport/cameraView.ts::cameraToView`
|
||||
* (der Kern darf den Viewport nicht importieren; der Test vergleicht beide). Null bei Standpunkt = Ziel.
|
||||
*/
|
||||
export function renderCameraOf(project: Project, cam: Camera): RenderCamera | null {
|
||||
const base = project.drawingLevels.find((l) => l.id === cam.floorId)?.baseElevation;
|
||||
const eye: [number, number, number] = [cam.position.x, cam.position.y, (typeof base === "number" && Number.isFinite(base) ? base : 0) + (Number.isFinite(cam.eyeHeight) ? cam.eyeHeight : 1.6)];
|
||||
const tgt: [number, number, number] = [cam.target.x, cam.target.y, cam.targetHeight];
|
||||
if (![...eye, ...tgt].every(Number.isFinite)) return null;
|
||||
const d = [tgt[0] - eye[0], tgt[1] - eye[1], tgt[2] - eye[2]];
|
||||
const len = Math.hypot(d[0], d[1], d[2]);
|
||||
if (!(len > 1e-9)) return null;
|
||||
const dir: [number, number, number] = [d[0] / len, d[1] / len, d[2] / len];
|
||||
const ref = Math.abs(dir[2]) > 0.9999 ? [0, 1, 0] : [0, 0, 1];
|
||||
const k = ref[0] * dir[0] + ref[1] * dir[1] + ref[2] * dir[2];
|
||||
const u = [ref[0] - dir[0] * k, ref[1] - dir[1] * k, ref[2] - dir[2] * k];
|
||||
const ul = Math.hypot(u[0], u[1], u[2]);
|
||||
const fov = Number.isFinite(cam.fovDeg) && cam.fovDeg > 0 ? Math.min(120, Math.max(5, cam.fovDeg)) : 50;
|
||||
return {
|
||||
kind: cam.projection === "perspective" ? "perspective" : "orthogonal",
|
||||
position: eye,
|
||||
direction: dir,
|
||||
up: [u[0] / ul, u[1] / ul, u[2] / ul],
|
||||
fovDeg: fov,
|
||||
orthoHeight: cam.orthoHeight && cam.orthoHeight > 0 ? cam.orthoHeight : 10,
|
||||
};
|
||||
}
|
||||
|
||||
/** Alle brauchbaren Kameras des Projekts in Listenreihenfolge. */
|
||||
export function projectRenderCameras(project: Project): RenderCameraChoice[] {
|
||||
const out: RenderCameraChoice[] = [];
|
||||
for (const c of project.cameras ?? []) {
|
||||
const camera = renderCameraOf(project, c);
|
||||
if (!camera) continue;
|
||||
const w = c.sunWhen ? new Date(c.sunWhen) : null;
|
||||
out.push({ id: c.id, name: c.name, camera, ...(w && Number.isFinite(w.getTime()) ? { sunWhen: w } : {}) });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Kamera nach Id oder Name (Gross-/Kleinschreibung egal; bei gleichem Namen die erste). */
|
||||
export function findRenderCamera(project: Project, key: string): RenderCameraChoice | null {
|
||||
const all = projectRenderCameras(project);
|
||||
const k = key.trim().toLowerCase();
|
||||
return all.find((c) => c.id === key) ?? all.find((c) => c.name.toLowerCase() === k) ?? null;
|
||||
}
|
||||
|
||||
// ── Blender-Ausgabe lesen ───────────────────────────────────────────────────
|
||||
|
||||
export type BlenderEvent =
|
||||
|
||||
@@ -3906,6 +3906,9 @@ export const de = {
|
||||
"menu.view.rendering": "Rendering mit Blender …",
|
||||
"render.title": "Rendering mit Blender",
|
||||
"render.intro": "Fotorealistisches Bild der aktiven 3D-Ansicht mit Blender/Cycles (installiertes Blender, läuft als eigener Prozess).",
|
||||
"render.camera.title": "Kamera",
|
||||
"render.camera.live": "Aktuelle 3D-Ansicht",
|
||||
"render.camera.saved": "Kamera: «{name}» (gespeichert)",
|
||||
"render.camera.view": "Kamera: aktuelle 3D-Ansicht",
|
||||
"render.camera.preset": "Kamera: Voreinstellung «{name}» (3D-Ansicht nicht offen)",
|
||||
"render.size": "Bildgrösse",
|
||||
|
||||
@@ -3892,6 +3892,9 @@ export const en: Record<TranslationKey, string> = {
|
||||
"menu.view.rendering": "Render with Blender …",
|
||||
"render.title": "Render with Blender",
|
||||
"render.intro": "Photorealistic image of the active 3D view with Blender/Cycles (installed Blender, runs as a separate process).",
|
||||
"render.camera.title": "Camera",
|
||||
"render.camera.live": "Current 3D view",
|
||||
"render.camera.saved": "Camera: «{name}» (saved)",
|
||||
"render.camera.view": "Camera: current 3D view",
|
||||
"render.camera.preset": "Camera: preset «{name}» (3D view not open)",
|
||||
"render.size": "Image size",
|
||||
|
||||
+32
-1
@@ -13,8 +13,10 @@ import {
|
||||
RenderCancelled,
|
||||
defaultRenderTime,
|
||||
paperPixels,
|
||||
projectRenderCameras,
|
||||
renderSun,
|
||||
type BlenderHost,
|
||||
type RenderCameraChoice,
|
||||
type RenderCameraSpec,
|
||||
} from "../core";
|
||||
import { getState } from "../state/appStore";
|
||||
@@ -50,6 +52,9 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
const [quality, setQuality] = useState<(typeof RENDER_QUALITY_PRESETS)[number]["id"]>("normal");
|
||||
const [when, setWhen] = useState("");
|
||||
const [camera, setCamera] = useState<RenderCameraSpec>({ preset: "iso" });
|
||||
// [213] "live" = aktuelle 3D-Ansicht, sonst die Id einer gespeicherten Kamera.
|
||||
const [cameraKey, setCameraKey] = useState("live");
|
||||
const [cameras, setCameras] = useState<RenderCameraChoice[]>([]);
|
||||
const [blenderPath, setPath] = useState("");
|
||||
const [host, setHost] = useState<BlenderHost | null | undefined>(undefined);
|
||||
const [phase, setPhase] = useState<Phase>("setup");
|
||||
@@ -65,6 +70,8 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
const st = getState();
|
||||
setWhen(toInputValue(defaultRenderTime(st.project)));
|
||||
setCamera(currentRenderCamera());
|
||||
setCameraKey("live");
|
||||
setCameras(projectRenderCameras(st.project));
|
||||
setPath(getBlenderPath());
|
||||
setPhase("setup");
|
||||
setMessage("");
|
||||
@@ -118,6 +125,17 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
const validDims = dims.width >= 16 && dims.height >= 16 && dims.width <= MAX_EDGE && dims.height <= MAX_EDGE;
|
||||
const canStart = validDims && date !== null && !busy;
|
||||
const samples = RENDER_QUALITY_PRESETS.find((q) => q.id === quality)?.samples ?? 128;
|
||||
const pickCamera = (key: string) => {
|
||||
setCameraKey(key);
|
||||
const choice = cameras.find((c) => c.id === key);
|
||||
if (!choice) {
|
||||
setCamera(currentRenderCamera());
|
||||
return;
|
||||
}
|
||||
setCamera(choice.camera);
|
||||
// Sonnenzeit der Kamera übernehmen (änderbar).
|
||||
if (choice.sunWhen) setWhen(toInputValue(choice.sunWhen));
|
||||
};
|
||||
const request = () => ({ width: dims.width, height: dims.height, samples, when: date!, camera });
|
||||
|
||||
const start = async () => {
|
||||
@@ -191,7 +209,7 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
if (await saveBinaryFile(png, name, "image/png")) st.notify(t("render.saved"), "info");
|
||||
};
|
||||
|
||||
const camLabel = "preset" in camera ? t("render.camera.preset", { name: t(`view3d.${camera.preset === "right" ? "side" : camera.preset}` as never) }) : t("render.camera.view");
|
||||
const camLabel = cameraKey !== "live" ? t("render.camera.saved", { name: cameras.find((c) => c.id === cameraKey)?.name ?? "" }) : "preset" in camera ? t("render.camera.preset", { name: t(`view3d.${camera.preset === "right" ? "side" : camera.preset}` as never) }) : t("render.camera.view");
|
||||
const browserOnly = host === null;
|
||||
|
||||
return (
|
||||
@@ -208,6 +226,19 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
<p className="imp-note" data-testid="render-camera">
|
||||
{camLabel}
|
||||
</p>
|
||||
{phase !== "done" && cameras.length > 0 && (
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("render.camera.title")}</div>
|
||||
<select className="imp-select" data-testid="render-camera-select" value={cameraKey} disabled={busy} onChange={(e) => pickCamera(e.target.value)}>
|
||||
<option value="live">{t("render.camera.live")}</option>
|
||||
{cameras.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{phase !== "done" && (
|
||||
<>
|
||||
|
||||
Reference in new issue
Block a user