Merge branch 'worktree-agent-ad1b4a0a708d60d18' into claude/practical-noether-1hb2s1

This commit is contained in:
Claude committed 2026-11-13 14:39:54 +00:00
commit 0933205f65
24 files changed
+1511 -171

No files matched your search

+3
View File
@@ -124,6 +124,7 @@ import {
viewportLevelPlan,
planToRenderScene,
projectToModel3d,
pathtraceMaterials,
emitDrawingLineVerts,
emitSurfacePatternLines,
ghostFilter3d,
@@ -1238,6 +1239,8 @@ async function execute(project: Project, file: string, command: string, rest: st
...projectToModel3d(project, { explode, hide: filter }),
// Flächenmuster ([100]) des Modells (render_png zeichnet sie in den Kanten-Stilen).
patternLines: Array.from(emitSurfacePatternLines(project, explode, filter)),
// [212] Materialtabelle des Pathtracers (render_png `--style pathtrace`).
ptMaterials: pathtraceMaterials(project),
};
// Geisterschicht: Modell, dazu gedämpfte 2D-Spuren und Flächenmuster (render_png `ghostDrawing`/`ghostPattern`).
const json = ghost
+1
View File
@@ -263,6 +263,7 @@ export {
projectToModel3dParts,
selectionHighlightLines,
wallMaterialColorMaps,
pathtraceMaterials,
} from "../plan/toWalls3d";
export type { Model3dPart } from "../plan/toWalls3d";
export { hiddenClassCodes } from "../plan/toWalls3d";
+1
View File
@@ -3961,6 +3961,7 @@ export const de = {
"image3d.size.custom": "Eigene Grösse",
"image3d.clamped": "Die Grafikkarte erlaubt höchstens {max} px je Seite: das Bild wird {width} × {height} px.",
"image3d.transparent": "Transparenter Hintergrund",
"image3d.samples": "Samples je Pixel (Pathtracing)",
"image3d.working": "Zeichne {width} × {height} px …",
"image3d.done": "Bild {width} × {height} px erstellt",
"image3d.start": "Bild erzeugen",
+1
View File
@@ -3947,6 +3947,7 @@ export const en: Record<TranslationKey, string> = {
"image3d.size.custom": "Custom size",
"image3d.clamped": "The graphics card allows at most {max} px per side: the image will be {width} × {height} px.",
"image3d.transparent": "Transparent background",
"image3d.samples": "Samples per pixel (path tracing)",
"image3d.working": "Drawing {width} × {height} px …",
"image3d.done": "Image {width} × {height} px created",
"image3d.start": "Create image",
+28
View File
@@ -0,0 +1,28 @@
/**
* [212] Materialtabelle des Pathtracers: je Textur-Ebene ({@link wallMaterialColorMaps}) Baustoff-Name und Farbkarte,
* in derselben Reihenfolge (render3d ordnet `materialIndex` i der Tabelle i − 1 zu).
*/
import { describe, expect, it } from "vitest";
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
import { pathtraceMaterials, wallMaterialColorMaps } from "./toWalls3d";
const sampleProjectComplex = buildComplexSampleProject();
describe("[212] pathtraceMaterials", () => {
it("folgt den Textur-Ebenen und nennt den Baustoff", () => {
const maps = wallMaterialColorMaps(sampleProjectComplex);
const table = pathtraceMaterials(sampleProjectComplex);
expect(maps.length).toBeGreaterThan(0);
expect(table.map((e) => e.map)).toEqual(maps);
for (const e of table) {
const comp = (sampleProjectComplex.components ?? []).find((c) => c.name === e.name);
expect(comp?.material?.color).toBe(e.map);
}
});
it("leer ohne Farbkarten", () => {
const bare = { ...sampleProjectComplex, components: (sampleProjectComplex.components ?? []).map((c) => ({ ...c, material: undefined })) };
expect(pathtraceMaterials(bare)).toEqual([]);
});
});
+10
View File
@@ -198,6 +198,16 @@ export function wallMaterialColorMaps(project: Project): string[] {
return maps;
}
/**
* [212] Materialtabelle des Pathtracers: je Textur-Ebene ({@link wallMaterialColorMaps}, gleiche Reihenfolge) der
* Baustoff-Name (erstes Bauteil mit dieser Farbkarte) und die Farbkarte. render3d ordnet daraus Rauigkeit, Metall und
* Glas zu (`render3d/src/pt_material.rs`, wie der Blender-Leser [211]).
*/
export function pathtraceMaterials(project: Project): { name: string; map: string }[] {
const comps = project.components ?? [];
return wallMaterialColorMaps(project).map((map) => ({ name: comps.find((c) => c.material?.color === map)?.name ?? "", map }));
}
/**
* Dach-Meshes (geschlossene, geschichtete Körper je Dachschicht); `onlyRoofId` beschränkt auf ein
* Dach (IFC-Export). Rechnet der Kern.
+12 -2
View File
@@ -13,7 +13,7 @@ import { defaultTargetLayout, placeImageOnLayout } from "../state/layoutImageAct
import { saveBinaryFile } from "../native/saveFile";
import { captureImage, getCamera, viewportAvailable, type ViewCamera } from "../viewport/cameraBridge";
import { cameraToView } from "../viewport/cameraView";
import { IMAGE_MAX_EDGE, clampImageSize, imageFileName } from "../viewport/imageExport";
import { IMAGE_MAX_EDGE, PT_EXPORT_MAX_SAMPLES, PT_EXPORT_SAMPLES, clampImageSize, exportSamples, imageFileName } from "../viewport/imageExport";
type SizeId = "view" | "hd" | "uhd" | "a4" | "a3" | "a2" | "custom";
const SIZE_IDS: SizeId[] = ["view", "hd", "uhd", "a4", "a3", "a2", "custom"];
@@ -39,6 +39,9 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
const [size, setSize] = useState<SizeId>("uhd");
const [dims, setDims] = useState({ width: 3840, height: 2160 });
const [transparent, setTransparent] = useState(false);
// [212] Samples je Pixel, wenn die 3D-Ansicht im Stil „Pathtracing (Vorschau)“ steht.
const [samples, setSamples] = useState(PT_EXPORT_SAMPLES);
const [pathtrace, setPathtrace] = useState(false);
const [cameraKey, setCameraKey] = useState("live");
const [phase, setPhase] = useState<Phase>("setup");
const [message, setMessage] = useState("");
@@ -53,6 +56,7 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
const a = getCamera()?.aspect;
const asp = a && Number.isFinite(a) && a > 0 ? a : 16 / 9;
setAspect(asp);
setPathtrace(st.renderMode === "pathtrace");
setCameraKey("live");
setPhase("setup");
setMessage("");
@@ -118,7 +122,7 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
setMessage("");
// Dem Browser einen Frame lassen, damit „Arbeite …" erscheint, bevor das Zeichnen den Hauptthread belegt.
await new Promise((r) => requestAnimationFrame(() => r(null)));
const img = await captureImage({ width: dims.width, height: dims.height, transparent, ...(camera ? { camera } : {}) });
const img = await captureImage({ width: dims.width, height: dims.height, transparent, ...(camera ? { camera } : {}), ...(pathtrace ? { samples: exportSamples(samples) } : {}) });
if (!img) {
setPhase("error");
setMessage(viewportAvailable() ? t("image3d.empty") : t("image3d.noViewport"));
@@ -196,6 +200,12 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
<input type="checkbox" data-testid="image3d-transparent" checked={transparent} disabled={busy} onChange={(e) => setTransparent(e.target.checked)} />
{t("image3d.transparent")}
</label>
{pathtrace && (
<label style={{ display: "flex", gap: 6, alignItems: "center", marginTop: 6 }}>
{t("image3d.samples")}{" "}
<input className="imp-input" type="number" min={1} max={PT_EXPORT_MAX_SAMPLES} style={{ width: 90 }} data-testid="image3d-samples" value={samples} disabled={busy} onChange={(e) => setSamples(Number(e.target.value))} />
</label>
)}
</section>
</>
)}
+1 -1
View File
@@ -804,7 +804,7 @@ export function Wasm3DViewport({
// Gespeicherte Kamera ([213]) oder die Live-Kamera; das Blickziel liegt im Abstand der Live-Kamera.
const cam = o.camera ? camera3dFromViewCamera(o.camera, cur.dist) : orbitCamera(cur);
if (!cam) return Promise.resolve(null);
return exportImage({ camera: cam, width: o.width, height: o.height, transparent: o.transparent, restore: draw });
return exportImage({ camera: cam, width: o.width, height: o.height, transparent: o.transparent, ...(o.samples !== undefined ? { samples: o.samples } : {}), restore: draw });
},
section: (plane) => setExtSection(plane),
fit: () => fitCameraRef.current(),
+5 -4
View File
@@ -213,8 +213,9 @@ export interface ViewportCameraApi {
write(cam: Camera3d, animate: boolean): boolean;
/** Aktuelles 3D-Bild als PNG, höchstens `maxEdge` Pixel auf der langen Seite. */
snapshot(maxEdge: number): Promise<Uint8Array | null>;
/** [223] Bild in Zielgrösse (render3d zeichnet direkt in `width` × `height`), mit Live- oder gegebener Kamera. */
image(opts: { width: number; height: number; transparent: boolean; camera?: Camera3dSource }): Promise<CapturedImage | null>;
/** [223] Bild in Zielgrösse (render3d zeichnet direkt in `width` × `height`), mit Live- oder gegebener Kamera.
* [212] `samples`: Samples je Pixel im Stil „Pathtracing (Vorschau)“ (sonst ohne Wirkung). */
image(opts: { width: number; height: number; transparent: boolean; camera?: Camera3dSource; samples?: number }): Promise<CapturedImage | null>;
/** Live-Schnitt von aussen setzen (world) oder aufheben (null). */
section(plane: { point: V3; normal: V3 } | null): void;
/** Kamera auf Modell und sichtbare Punktwolken einpassen (aktuelles Preset). */
@@ -322,12 +323,12 @@ export async function captureSnapshot(opts: { maxEdge?: number } = {}): Promise<
* leerem Bild. Ohne `camera` zeichnet die Live-Kamera. Test-Hook: `globalThis.__dossierImageMock` ersetzt das Zeichnen
* (headless liefert WebGPU kein Bild; e2e prüft damit den Dialog und das Einsetzen).
*/
export async function captureImage(opts: { width: number; height: number; transparent?: boolean; camera?: ViewCamera }): Promise<CapturedImage | null> {
export async function captureImage(opts: { width: number; height: number; transparent?: boolean; camera?: ViewCamera; samples?: number }): Promise<CapturedImage | null> {
const mock = (globalThis as { __dossierImageMock?: (o: { width: number; height: number; transparent: boolean }) => Promise<CapturedImage | null> }).__dossierImageMock;
if (typeof mock === "function") return mock({ width: opts.width, height: opts.height, transparent: opts.transparent === true });
if (!api) return null;
try {
return await api.image({ width: opts.width, height: opts.height, transparent: opts.transparent === true, ...(opts.camera ? { camera: opts.camera } : {}) });
return await api.image({ width: opts.width, height: opts.height, transparent: opts.transparent === true, ...(opts.camera ? { camera: opts.camera } : {}), ...(opts.samples !== undefined ? { samples: opts.samples } : {}) });
} catch {
return null;
}
+12 -1
View File
@@ -1,5 +1,16 @@
import { describe, expect, it } from "vitest";
import { IMAGE_MAX_EDGE, clampImageSize, imageFileName, isBlankImage, matteFromBlackWhite } from "./imageExport";
import { IMAGE_MAX_EDGE, PT_EXPORT_MAX_SAMPLES, PT_EXPORT_SAMPLES, clampImageSize, exportSamples, imageFileName, isBlankImage, matteFromBlackWhite } from "./imageExport";
describe("[212] Bild-Export im Pathtracing-Stil", () => {
it("rechnet N Samples (Vorgabe 64, 1 … 1024)", () => {
expect(exportSamples(undefined)).toBe(PT_EXPORT_SAMPLES);
expect(exportSamples(Number.NaN)).toBe(PT_EXPORT_SAMPLES);
expect(exportSamples(16.4)).toBe(16);
expect(exportSamples(0)).toBe(1);
expect(exportSamples(-5)).toBe(1);
expect(exportSamples(5000)).toBe(PT_EXPORT_MAX_SAMPLES);
});
});
describe("[223] Bild-Export 3D", () => {
it("Zielgrösse: unverändert, begrenzt mit Seitenverhältnis, Unsinn wird 16 px", () => {
+12
View File
@@ -5,6 +5,18 @@
/** Längste Bildkante (px): WebGPU-Standardgrenze für 2D-Texturen (`maxTextureDimension2D`). */
export const IMAGE_MAX_EDGE = 8192;
/** [212] Samples je Pixel des Bild-Exports im Stil „Pathtracing (Vorschau)“: Vorgabe und Obergrenze (= Ziel der Vorschau). */
export const PT_EXPORT_SAMPLES = 64;
export const PT_EXPORT_MAX_SAMPLES = 1024;
/** [212] Pixel je Sample beim Export (die Vorschau rechnet ≤ 1.2 MPx und zieht hoch; das Bild feiner, Speicher ≈ 80 B/px). */
export const PT_EXPORT_MAX_PIXELS = 4_000_000;
/** [212] Samples des Exports: ganzzahlig 1 … `PT_EXPORT_MAX_SAMPLES`, sonst die Vorgabe. */
export function exportSamples(n: number | undefined): number {
if (n === undefined || !Number.isFinite(n)) return PT_EXPORT_SAMPLES;
return Math.min(PT_EXPORT_MAX_SAMPLES, Math.max(1, Math.round(n)));
}
export interface ImageSize {
width: number;
height: number;
+37 -4
View File
@@ -20,7 +20,7 @@
import { useCallback, useEffect, useRef, useState } from "react";
import type { ContextImage, Project } from "../model/types";
import { GhostLayerSync } from "./ghostSync";
import { emitDrawingLineVerts, emitSurfacePatternLines, filter3d, ghostFilter3d, hiddenClassCodes, projectToModel3d, projectToModel3dParts, siteEnvelope3d } from "../core";
import { emitDrawingLineVerts, emitSurfacePatternLines, filter3d, ghostFilter3d, hiddenClassCodes, pathtraceMaterials, projectToModel3d, projectToModel3dParts, siteEnvelope3d } from "../core";
import type { Hide3d } from "../core";
import { Model3dPartsSync } from "./model3dPartsSync";
import type { DetailLevel } from "../model/viewTypes";
@@ -28,7 +28,7 @@ import { loadEngine3d } from "../engine/engine3d";
import { decodeMaterialTextures } from "./materialTextures";
import { decodeImageToRgba } from "../io/swissImage";
import { planPointCloudSync } from "./pointCloudSync";
import { clampImageSize, isBlankImage, matteFromBlackWhite } from "./imageExport";
import { PT_EXPORT_MAX_PIXELS, clampImageSize, exportSamples, isBlankImage, matteFromBlackWhite } from "./imageExport";
import type { PointCloudSyncItem, UploadedPointCloud } from "./pointCloudSync";
/** Fertige Kamera für einen Frame (world-Meter, Y-up — wie render3d::types::Camera). */
@@ -121,6 +121,13 @@ interface WebModelRendererLike {
* die Karten belegen Ebenen 1..N (siehe `WallInput.materialIndex`). Optional —
* ältere WASM-Builds ohne diesen Export lassen den Aufrufer still zurückfallen. */
set_material_textures?(rgba: Uint8Array, layerCount: number): void;
/** [212] Materialtabelle des Pathtracers (`web::set_pathtrace_materials`): JSON `[{ name, map }]` je Textur-Ebene
* (gleiche Reihenfolge wie `set_material_textures`). Optional — ältere WASM-Builds. */
set_pathtrace_materials?(json: string): void;
/** [212] Samples je `render` (Bild-Export rechnet N auf einmal), Entrauscher an/aus, Pixel je Sample (0 = Standard). */
set_pathtrace_batch?(n: number): void;
set_pathtrace_denoise?(on: boolean): void;
set_pathtrace_max_pixels?(n: number): void;
/** Luftbild aufs Gelände drapieren (`web::set_aerial_texture`): `rgba` =
* gepackte RGBA8-Bytes (`width*height*4`, zeilenweise von oben = Nord), plus
* Modell-Meter-Bbox (min/max, x=Ost/y=Nord). render3d legt es pixelscharf als
@@ -280,6 +287,9 @@ export function useWasm3dRenderer(
// erneutes (teures) Dekodieren/Hochladen, wenn sich die Materialien nicht
// geändert haben (updateModel läuft bei JEDER Projektänderung).
const materialSigRef = useRef<string | null>(null);
// [212] Zuletzt gesetzte Materialtabelle des Pathtracers (JSON) und Darstellungsart (Bild-Export).
const ptMaterialsRef = useRef<string | null>(null);
const styleRef = useRef<string>("shaded");
// [180]/[214] Was render3d an Geisterschicht hat (`ghostSync.ts`).
const ghostSyncRef = useRef(new GhostLayerSync());
// Signatur des zuletzt hochgeladenen Drape-Luftbilds (src + Bbox) — verhindert
@@ -350,6 +360,18 @@ export function useWasm3dRenderer(
console.warn("render3d set_pattern_lines fehlgeschlagen:", e);
}
}
// [212] Materialtabelle des Pathtracers (Rauigkeit/Metall/Glas je Baustoff), nur bei Änderung (baut den Baum neu).
if (typeof r.set_pathtrace_materials === "function") {
try {
const json = JSON.stringify(pathtraceMaterials(project));
if (json !== ptMaterialsRef.current) {
ptMaterialsRef.current = json;
r.set_pathtrace_materials(json);
}
} catch (e) {
console.warn("render3d set_pathtrace_materials fehlgeschlagen:", e);
}
}
// Material-Farbkarten (Stil „textured") ASYNCHRON dekodieren + hochladen.
// Fire-and-forget: bis die Texturen ankommen, zeigt render3d für die
// betroffenen Bänder das Fallback-Schachbrett (graceful). Nur neu laden,
@@ -477,6 +499,7 @@ export function useWasm3dRenderer(
const setRenderStyle = useCallback((style: string) => {
const r = rendererRef.current;
if (!r) return;
styleRef.current = style;
try {
r.set_render_style(style);
} catch (e) {
@@ -665,12 +688,14 @@ export function useWasm3dRenderer(
* WebGPU-Canvas liefert seinen Inhalt nur dort); danach stellt `restore` das Fenster-Bild wieder her. Null bei leerem Bild.
*/
const exportImage = useCallback(
async (opts: { camera: Camera3d; width: number; height: number; transparent: boolean; restore: () => void }): Promise<{ png: Uint8Array; width: number; height: number; transparent: boolean } | null> => {
async (opts: { camera: Camera3d; width: number; height: number; transparent: boolean; samples?: number; restore: () => void }): Promise<{ png: Uint8Array; width: number; height: number; transparent: boolean } | null> => {
const canvas = canvasRef.current;
const r = rendererRef.current;
if (!canvas || !r) return null;
const { width: W, height: H } = clampImageSize(opts.width, opts.height);
const canMatte = opts.transparent && typeof r.set_clear_color === "function";
// [212] Pathtracing: N Samples in einem `render` (statt 1), feiner gerechnet; Hintergrund ist der Himmel (keine Transparenz).
const pt = styleRef.current === "pathtrace" && typeof r.set_pathtrace_batch === "function";
const canMatte = !pt && opts.transparent && typeof r.set_clear_color === "function";
const prevW = canvas.width;
const prevH = canvas.height;
const out = document.createElement("canvas");
@@ -683,6 +708,10 @@ export function useWasm3dRenderer(
canvas.width = W;
canvas.height = H;
r.resize(W, H);
if (pt) {
r.set_pathtrace_max_pixels?.(PT_EXPORT_MAX_PIXELS);
r.set_pathtrace_batch?.(exportSamples(opts.samples));
}
const c = opts.camera;
const shot = (bg: number | null): ImageData => {
if (bg !== null) r.set_clear_color?.(bg, bg, bg);
@@ -705,6 +734,10 @@ export function useWasm3dRenderer(
image = null;
} finally {
try {
if (pt) {
r.set_pathtrace_batch?.(1);
r.set_pathtrace_max_pixels?.(0);
}
r.set_clear_color?.(0.961, 0.961, 0.961);
canvas.width = prevW;
canvas.height = prevH;