[212] Pathtracer Etappe 4: Normalen- und Rauigkeitskarten (Tangentenrahmen der planaren UV, Toksvig), Mip-Stufen mit LOD nach Strahlkegel, Bildkarten bis zum ersten Abpraller, Gelände-Material (TerrainMesh.componentId, Objekt-Info, 3D/Pathtracer/Blender), Wiese Grass005 statt prozedural
This commit is contained in:
27 files changed
+1188
-132
No files matched your search
@@ -270,5 +270,6 @@ export { hiddenClassCodes } from "../plan/toWalls3d";
|
||||
export { filter3d } from "../plan/toWalls3d";
|
||||
export { ghostFilter3d } from "../plan/toWalls3d";
|
||||
export type { Filter3d, Hide3d } from "../plan/toWalls3d";
|
||||
export type { PtMaterialEntry } from "../plan/toWalls3d";
|
||||
|
||||
export * from "./extra";
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
renderCameraOf,
|
||||
splitRoofMaterials,
|
||||
TERRAIN_MATERIAL,
|
||||
terrainRenderMaterial,
|
||||
type BlenderHost,
|
||||
type RenderOptions,
|
||||
} from "./blenderRender";
|
||||
@@ -366,6 +367,20 @@ describe("Materialzuordnung Gelände und Dach ([211])", () => {
|
||||
expect(t2.textures).toBeUndefined();
|
||||
});
|
||||
|
||||
it("[212] Gelände mit Bauteil: dessen Bildkarten statt der Wiese", async () => {
|
||||
const kies = (mk.components ?? []).find((c) => c.material?.color?.includes("Gravel043"))!;
|
||||
expect(kies).toBeDefined();
|
||||
const withComp: Project = { ...mk, context: (mk.context ?? []).map((o) => (o.type === "terrainMesh" ? { ...o, componentId: kies.id } : o)) };
|
||||
expect(terrainRenderMaterial(withComp)).toBe(kies.material);
|
||||
expect(terrainRenderMaterial(mk)).toBe(TERRAIN_MATERIAL);
|
||||
const loaded: string[] = [];
|
||||
const pkg = await buildRenderPackage(withComp, opts(), async (url) => (loaded.push(url), new Uint8Array([1])));
|
||||
const terrain = pkg.scene.materials.find((m) => m.role === "terrain")!;
|
||||
expect(terrain.textures?.color).toBeDefined();
|
||||
expect(loaded).toContain(kies.material!.color);
|
||||
expect(loaded).not.toContain(TERRAIN_MATERIAL.color);
|
||||
});
|
||||
|
||||
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");
|
||||
|
||||
@@ -24,6 +24,7 @@ import type { Camera, ComponentMaterial, LayoutOrientation, LayoutPaperFormat, P
|
||||
import { projectLatLon, sunPosition } from "../analysis/sun";
|
||||
import { sheetSizeMm } from "../model/layoutModel";
|
||||
import { exportGlb } from "./exportMesh";
|
||||
import { TERRAIN_GRASS_MATERIAL, terrainComponentMaterial, terrainMeshes } from "../materials/terrainMaterial";
|
||||
|
||||
/** Kamera in Modell-Koordinaten (gleiche Form wie `ViewCamera` der 3D-Ansicht, `viewport/cameraBridge.ts`). */
|
||||
export interface RenderCamera {
|
||||
@@ -335,13 +336,16 @@ function extensionOf(url: string): string {
|
||||
}
|
||||
|
||||
/** 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,
|
||||
};
|
||||
export const TERRAIN_MATERIAL: ComponentMaterial = TERRAIN_GRASS_MATERIAL;
|
||||
|
||||
/** [212] Material des Geländes: Bauteil des ersten Geländes mit Bildkarten (`TerrainMesh.componentId`), sonst die Wiese. */
|
||||
export function terrainRenderMaterial(project: Project): ComponentMaterial {
|
||||
for (const t of terrainMeshes(project)) {
|
||||
const m = terrainComponentMaterial(project, t);
|
||||
if (m) return m;
|
||||
}
|
||||
return TERRAIN_MATERIAL;
|
||||
}
|
||||
|
||||
/** Bauteil-Materialkarten nach glTF-Materialname (erste Komponente gleichen Namens mit Farbkarte gewinnt). */
|
||||
function componentMaterials(project: Project): Map<string, ComponentMaterial> {
|
||||
@@ -361,12 +365,14 @@ export async function buildRenderPackage(project: Project, opts: RenderOptions,
|
||||
const files: RenderPackage["files"] = [{ path: "model.glb", bytes: glb }];
|
||||
const materials = glbMaterials(glb);
|
||||
const comp = componentMaterials(project);
|
||||
const terrain = terrainRenderMaterial(project);
|
||||
const missing: string[] = [];
|
||||
const stored = new Map<string, string>();
|
||||
|
||||
for (const mat of materials) {
|
||||
// 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);
|
||||
// Gelände: Bauteil mit Bildkarten ([212] `TerrainMesh.componentId`), sonst die Wiese aus der mitgelieferten Bibliothek
|
||||
// (ohne Bildkarten übernimmt der Leser eine Wiesenfarbe).
|
||||
const cm = mat.role === "terrain" ? terrain : comp.get(mat.component ?? mat.name);
|
||||
if (!cm || mat.glass || !loadTexture) continue;
|
||||
const textures: Partial<Record<TextureKind, string>> = {};
|
||||
for (const kind of TEXTURE_KINDS) {
|
||||
|
||||
@@ -2583,6 +2583,9 @@ export const de = {
|
||||
"site.excavation.workingSpaceWarn": "Arbeitsraum zu schmal: {min} m statt {need} m an {n} Stelle(n) (rotes Kreuz im Plan)",
|
||||
"site.excavation.shoringHint": "Gewählte Kanten: senkrechte Wand (Spundwand) statt Böschung",
|
||||
"site.earthDepth": "Erdreich-Band im Schnitt [m]",
|
||||
"site.terrain.material": "Material",
|
||||
"site.terrain.material.none": "Wiese (Standard)",
|
||||
"site.terrain.material.hint": "Bauteil als Oberfläche des Geländes: Farbe und Bildkarten in der texturierten 3D-Ansicht, im Pathtracing und im Blender-Rendering. Ohne Bauteil: Wiese (Pathtracing, Blender), sonst die Geländefarbe.",
|
||||
"site.terrain.visible": "Gelände sichtbar",
|
||||
"site.terrain.visible.hint": "Blendet die Kategorie {name} ein oder aus (alle Ansichten, ein Undo-Schritt)",
|
||||
"site.terrain.smooth": "Glättung",
|
||||
|
||||
@@ -2569,6 +2569,9 @@ export const en: Record<TranslationKey, string> = {
|
||||
"site.excavation.workingSpaceWarn": "Working space too narrow: {min} m instead of {need} m at {n} spot(s) (red cross in the plan)",
|
||||
"site.excavation.shoringHint": "Selected edges: vertical wall (sheet piling) instead of a slope",
|
||||
"site.earthDepth": "Earth band in section [m]",
|
||||
"site.terrain.material": "Material",
|
||||
"site.terrain.material.none": "Grass (default)",
|
||||
"site.terrain.material.hint": "Component used as the terrain surface: colour and texture maps in the textured 3D view, in path tracing and in the Blender rendering. Without a component: grass (path tracing, Blender), otherwise the terrain colour.",
|
||||
"site.terrain.visible": "Terrain visible",
|
||||
"site.terrain.visible.hint": "Shows or hides the category {name} (all views, one undo step)",
|
||||
"site.terrain.smooth": "Smoothing",
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// Wiese für Gelände ohne eigenes Material ([211] Blender-Paket, [212] Pathtracer): ambientCG Grass005 aus der
|
||||
// mitgelieferten Bibliothek (`public/assets/materials`), Kachel 4 m. Hat ein Gelände ein Bauteil mit Bildkarten
|
||||
// (`TerrainMesh.componentId`), gilt dessen Material ({@link terrainComponentMaterial}).
|
||||
|
||||
import type { ComponentMaterial, Project, TerrainMesh } from "../model/types";
|
||||
|
||||
export const TERRAIN_GRASS_MATERIAL: ComponentMaterial = {
|
||||
libraryId: "Grass005",
|
||||
color: "/assets/materials/Grass005/color.jpg",
|
||||
normal: "/assets/materials/Grass005/normal.jpg",
|
||||
roughness: "/assets/materials/Grass005/roughness.jpg",
|
||||
sizeM: 4,
|
||||
};
|
||||
|
||||
/** Gelände-Netze des Projekts. */
|
||||
export function terrainMeshes(project: Project): TerrainMesh[] {
|
||||
return (project.context ?? []).filter((o): o is TerrainMesh => o.type === "terrainMesh");
|
||||
}
|
||||
|
||||
/** Material (mit Farbkarte) des Bauteils eines Geländes, sonst undefined. */
|
||||
export function terrainComponentMaterial(project: Project, terrain: TerrainMesh): ComponentMaterial | undefined {
|
||||
const id = terrain.componentId;
|
||||
if (!id) return undefined;
|
||||
const mat = (project.components ?? []).find((c) => c.id === id)?.material;
|
||||
return mat?.color ? mat : undefined;
|
||||
}
|
||||
@@ -3965,6 +3965,11 @@ export type TerrainMesh = {
|
||||
smooth?: number;
|
||||
/** [137] Quelle: Id des Höhenlinien-Satzes (`contourSet`), aus dem das Netz erzeugt wurde. */
|
||||
sourceId?: string;
|
||||
/**
|
||||
* [212] Bauteil (Component Manager) als Material der Oberfläche: Farbe und Bildkarten im 3D (texturierte
|
||||
* Ansicht, Pathtracer, Blender-Paket [211]). Fehlt = Gelände-Grundfarbe bzw. Wiese.
|
||||
*/
|
||||
componentId?: string;
|
||||
};
|
||||
|
||||
/** Ein zusammenhängender Textabschnitt mit einheitlicher Formatierung. */
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// [212] Material des Geländes in der Objekt-Info: Auswahl der Bauteile (Standard Wiese), die Änderung ist ein Op mit
|
||||
// einem Undo-Schritt und kommt im 3D als Textur-Ebene am Gelände an. Ohne DOM: Server-Render des Abschnitts.
|
||||
import { createElement } from "react";
|
||||
import { renderToString } from "react-dom/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import type { TerrainMesh } from "../model/types";
|
||||
import { getState } from "../state/appStore";
|
||||
import { projectToModel3d, wallMaterialColorMaps } from "../plan/toWalls3d";
|
||||
import { t } from "../i18n";
|
||||
import { PanelHostProvider } from "./host";
|
||||
import type { PanelHost } from "./types";
|
||||
import { ContextObjectProps } from "./ContextObjectProps";
|
||||
|
||||
const host = {} as unknown as PanelHost;
|
||||
const terrain = () => getState().project.context!.find((o): o is TerrainMesh => o.type === "terrainMesh")!;
|
||||
const html = () => renderToString(createElement(PanelHostProvider, { value: host }, createElement(ContextObjectProps, { obj: terrain(), quantities: [] })));
|
||||
const terrainLayer = () => projectToModel3d(getState().project).meshes.find((m) => m.kind === "terrain")!.materialIndex;
|
||||
|
||||
describe("[212] Gelände-Material in der Objekt-Info", () => {
|
||||
it("Auswahl mit allen Bauteilen, ohne Bauteil „Wiese (Standard)“", () => {
|
||||
getState().loadProject(buildComplexSampleProject());
|
||||
const out = html();
|
||||
expect(out).toContain('data-testid="terrain-material"');
|
||||
expect(out).toContain(t("site.terrain.material.none"));
|
||||
for (const c of getState().project.components ?? []) expect(out).toContain(`value="${c.id}"`);
|
||||
});
|
||||
|
||||
it("Bauteil wählen: ein Op, im 3D die Textur-Ebene seiner Farbkarte; Undo stellt zurück", () => {
|
||||
getState().loadProject(buildComplexSampleProject());
|
||||
const kies = (getState().project.components ?? []).find((c) => c.material?.color?.includes("Gravel043"))!;
|
||||
const id = terrain().id;
|
||||
expect(terrainLayer()).toBeUndefined();
|
||||
const depth = getState().undoDepth;
|
||||
getState().patchContextObject(id, { componentId: kies.id });
|
||||
expect(terrain().componentId).toBe(kies.id);
|
||||
expect(getState().undoDepth).toBe(depth + 1);
|
||||
expect(terrainLayer()).toBe(wallMaterialColorMaps(getState().project).indexOf(kies.material!.color!) + 1);
|
||||
expect(html()).toMatch(new RegExp(`<option selected="" value="${kies.id}"|value="${kies.id}" selected=""`));
|
||||
// Zurück auf „Wiese“: Feld entfällt.
|
||||
getState().patchContextObject(id, { componentId: undefined });
|
||||
expect("componentId" in terrain() && terrain().componentId !== undefined).toBe(false);
|
||||
getState().undo();
|
||||
expect(terrain().componentId).toBe(kies.id);
|
||||
getState().undo();
|
||||
expect(terrain().componentId).toBeUndefined();
|
||||
expect(terrainLayer()).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -301,6 +301,22 @@ function KindFields({ obj, quantities }: { obj: ContextObject; quantities: reado
|
||||
<NumField label={t("site.contourInterval")} value={obj.contourInterval} step={0.5} min={0} placeholder="—" onChange={patch("contourInterval")} />
|
||||
<NumField label={t("site.contourIndexEvery")} value={obj.contourIndexEvery} step={1} min={1} placeholder="5" onChange={patch("contourIndexEvery")} />
|
||||
<NumField label={t("site.earthDepth")} value={obj.earthDepth} step={0.5} min={0.1} placeholder="1.5" onChange={patch("earthDepth")} />
|
||||
{/* [212] Material der Oberfläche (Bauteil): Farbe und Bildkarten im 3D, Pathtracer und Blender-Paket. */}
|
||||
<label className="site-prop" title={t("site.terrain.material.hint")}>
|
||||
<span>{t("site.terrain.material")}</span>
|
||||
<select
|
||||
data-testid="terrain-material"
|
||||
value={obj.componentId ?? ""}
|
||||
onChange={(e) => host.onPatchContextObject(obj.id, { componentId: e.target.value || undefined })}
|
||||
>
|
||||
<option value="">{t("site.terrain.material.none")}</option>
|
||||
{(project.components ?? []).map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,38 @@
|
||||
/**
|
||||
* [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).
|
||||
* in derselben Reihenfolge (render3d ordnet `materialIndex` i der Tabelle i − 1 zu). Etappe 4: Normalen-/Rauigkeitskarte,
|
||||
* Wiese für Gelände ohne Material, Material des Geländes (`TerrainMesh.componentId`) bis ins 3D und durch die Datei.
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { pathtraceMaterials, wallMaterialColorMaps } from "./toWalls3d";
|
||||
import type { Project, TerrainMesh } from "../model/types";
|
||||
import { TERRAIN_GRASS_MATERIAL } from "../materials/terrainMaterial";
|
||||
import { parseProjectFile, serializeProject } from "../io/projectFormat";
|
||||
import { pathtraceMaterials, projectToModel3d, wallMaterialColorMaps } from "./toWalls3d";
|
||||
|
||||
const sampleProjectComplex = buildComplexSampleProject();
|
||||
|
||||
/** Das Beispiel mit dem Bauteil `componentId` am (einzigen) Gelände. */
|
||||
function withTerrainComponent(p: Project, componentId: string | undefined): Project {
|
||||
return { ...p, context: (p.context ?? []).map((o) => (o.type === "terrainMesh" ? { ...o, componentId } : o)) };
|
||||
}
|
||||
|
||||
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) {
|
||||
// Die Ebenen der Bauteile zuerst, in derselben Reihenfolge; dahinter höchstens die Wiese des Geländes.
|
||||
expect(table.slice(0, maps.length).map((e) => e.map)).toEqual(maps);
|
||||
for (const e of table.slice(0, maps.length)) {
|
||||
const comp = (sampleProjectComplex.components ?? []).find((c) => c.name === e.name);
|
||||
expect(comp?.material?.color).toBe(e.map);
|
||||
}
|
||||
});
|
||||
|
||||
it("gibt die Kachelgrösse der Bildkarte mit (Etappe 3)", () => {
|
||||
const table = pathtraceMaterials(sampleProjectComplex);
|
||||
const table = pathtraceMaterials(sampleProjectComplex).filter((e) => !e.terrain);
|
||||
for (const e of table) {
|
||||
const comp = (sampleProjectComplex.components ?? []).find((c) => c.material?.color === e.map);
|
||||
expect(e.size).toBe(comp?.material?.sizeM);
|
||||
@@ -30,8 +40,61 @@ describe("[212] pathtraceMaterials", () => {
|
||||
expect(table.some((e) => e.size !== undefined)).toBe(true);
|
||||
});
|
||||
|
||||
it("leer ohne Farbkarten", () => {
|
||||
it("Etappe 4: Normalen- und Rauigkeitskarte des Bauteils", () => {
|
||||
for (const e of pathtraceMaterials(sampleProjectComplex).filter((x) => !x.terrain)) {
|
||||
const mat = (sampleProjectComplex.components ?? []).find((c) => c.material?.color === e.map)?.material;
|
||||
expect(e.normal).toBe(mat?.normal);
|
||||
expect(e.rough).toBe(mat?.roughness);
|
||||
}
|
||||
});
|
||||
|
||||
it("Etappe 4: Gelände ohne Material bekommt hinten die Wiese (Grass005, Kachel 4 m)", () => {
|
||||
const table = pathtraceMaterials(sampleProjectComplex);
|
||||
const maps = wallMaterialColorMaps(sampleProjectComplex);
|
||||
expect(table).toHaveLength(maps.length + 1);
|
||||
expect(table.at(-1)).toEqual({
|
||||
name: "Wiese",
|
||||
map: TERRAIN_GRASS_MATERIAL.color,
|
||||
size: 4,
|
||||
normal: TERRAIN_GRASS_MATERIAL.normal,
|
||||
rough: TERRAIN_GRASS_MATERIAL.roughness,
|
||||
terrain: true,
|
||||
});
|
||||
// Ohne Gelände keine Wiese.
|
||||
const noTerrain = { ...sampleProjectComplex, context: (sampleProjectComplex.context ?? []).filter((o) => o.type !== "terrainMesh") };
|
||||
expect(pathtraceMaterials(noTerrain).some((e) => e.terrain)).toBe(false);
|
||||
});
|
||||
|
||||
it("leer ohne Farbkarten (bis auf die Wiese des Geländes)", () => {
|
||||
const bare = { ...sampleProjectComplex, components: (sampleProjectComplex.components ?? []).map((c) => ({ ...c, material: undefined })) };
|
||||
expect(pathtraceMaterials(bare)).toEqual([]);
|
||||
expect(pathtraceMaterials(bare).map((e) => e.map)).toEqual([TERRAIN_GRASS_MATERIAL.color]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("[212] Material des Geländes (TerrainMesh.componentId)", () => {
|
||||
const kies = (sampleProjectComplex.components ?? []).find((c) => c.material?.color?.includes("Gravel043"))!;
|
||||
const terrainOf = (p: Project) => (p.context ?? []).find((o): o is TerrainMesh => o.type === "terrainMesh")!;
|
||||
|
||||
it("Bauteil mit Bildkarte: Textur-Ebene am Gelände-Netz, keine Wiese", () => {
|
||||
expect(kies).toBeDefined();
|
||||
const p = withTerrainComponent(sampleProjectComplex, kies.id);
|
||||
const maps = wallMaterialColorMaps(p);
|
||||
const mesh = projectToModel3d(p).meshes.find((m) => m.kind === "terrain")!;
|
||||
expect(mesh.materialIndex).toBe(maps.indexOf(kies.material!.color!) + 1);
|
||||
expect(pathtraceMaterials(p).some((e) => e.terrain)).toBe(false);
|
||||
// Ohne Bauteil: keine Ebene.
|
||||
expect(projectToModel3d(sampleProjectComplex).meshes.find((m) => m.kind === "terrain")!.materialIndex).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Rundreise Datei: componentId bleibt, ohne Warnung", () => {
|
||||
const p = withTerrainComponent(sampleProjectComplex, kies.id);
|
||||
const r = parseProjectFile(serializeProject(p));
|
||||
expect(r.ok).toBe(true);
|
||||
if (!r.ok) return;
|
||||
expect(terrainOf(r.project).componentId).toBe(kies.id);
|
||||
expect(r.warnings.join(" ")).not.toMatch(/componentId/);
|
||||
// Entfernt (undefined) = Feld fehlt in der Datei.
|
||||
const text = serializeProject(withTerrainComponent(sampleProjectComplex, undefined));
|
||||
expect(JSON.parse(text).context.find((o: { type: string }) => o.type === "terrainMesh").componentId).toBeUndefined();
|
||||
});
|
||||
});
|
||||
+42
-6
@@ -40,7 +40,8 @@
|
||||
// freie Körper, freie 2D-Geometrie) rechnet der Kern (`src-tauri/core/src/model3d/`);
|
||||
// `toWalls3d/` hält nur noch das gemeinsame Vokabular und die Abzugskörper-Netze.
|
||||
|
||||
import type { Project, Vec2 } from "../model/types";
|
||||
import type { ComponentMaterial, Project, Vec2 } from "../model/types";
|
||||
import { TERRAIN_GRASS_MATERIAL, terrainComponentMaterial, terrainMeshes } from "../materials/terrainMaterial";
|
||||
import { collectVisibleCodes, flattenCategories } from "../model/types";
|
||||
import type { DetailLevel } from "../model/viewTypes";
|
||||
import { documentFor } from "../core/document";
|
||||
@@ -198,19 +199,54 @@ export function wallMaterialColorMaps(project: Project): string[] {
|
||||
return maps;
|
||||
}
|
||||
|
||||
/** Eintrag der Pathtracer-Materialtabelle ({@link pathtraceMaterials}, render3d `PtMaterialEntry`). */
|
||||
export interface PtMaterialEntry {
|
||||
name: string;
|
||||
/** Farbkarte. */
|
||||
map: string;
|
||||
/** Kachelgrösse in m (`sizeM`). */
|
||||
size?: number;
|
||||
/** Normalenkarte (OpenGL), Etappe 4. */
|
||||
normal?: string;
|
||||
/** Rauigkeitskarte, Etappe 4. */
|
||||
rough?: string;
|
||||
/** Bildkarte des Geländes ohne eigenes Material (Wiese). */
|
||||
terrain?: true;
|
||||
}
|
||||
|
||||
function ptEntry(name: string, map: string, mat: ComponentMaterial | undefined): PtMaterialEntry {
|
||||
const size = mat?.sizeM;
|
||||
return {
|
||||
name,
|
||||
map,
|
||||
...(typeof size === "number" && Number.isFinite(size) && size > 0 ? { size } : {}),
|
||||
...(mat?.normal ? { normal: mat.normal } : {}),
|
||||
...(mat?.roughness ? { rough: mat.roughness } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* [212] Materialtabelle des Pathtracers: je Textur-Ebene ({@link wallMaterialColorMaps}, gleiche Reihenfolge) der
|
||||
* Baustoff-Name (erstes Bauteil mit dieser Farbkarte), die Farbkarte und die Kachelgrösse in Metern (`sizeM`, nur wenn
|
||||
* gesetzt; Etappe 3: Massstab der Bildkarte im Pathtracer). render3d ordnet daraus Rauigkeit, Metall und Glas zu
|
||||
* (`render3d/src/pt_material.rs`, wie der Blender-Leser [211]).
|
||||
* (`render3d/src/pt_material.rs`, wie der Blender-Leser [211]). Etappe 4: Normalen- und Rauigkeitskarte des Bauteils;
|
||||
* hat ein Gelände kein Material, hängt hinten die Wiese ({@link TERRAIN_GRASS_MATERIAL}, `terrain: true`) an — die
|
||||
* Textur-Ebenen davor bleiben gleich, die Bildkarten lädt der Viewer in derselben Reihenfolge
|
||||
* (`viewport/materialTextures.ts`).
|
||||
*/
|
||||
export function pathtraceMaterials(project: Project): { name: string; map: string; size?: number }[] {
|
||||
export function pathtraceMaterials(project: Project): PtMaterialEntry[] {
|
||||
const comps = project.components ?? [];
|
||||
return wallMaterialColorMaps(project).map((map) => {
|
||||
const out = wallMaterialColorMaps(project).map((map) => {
|
||||
const comp = comps.find((c) => c.material?.color === map);
|
||||
const size = comp?.material?.sizeM;
|
||||
return { name: comp?.name ?? "", map, ...(typeof size === "number" && Number.isFinite(size) && size > 0 ? { size } : {}) };
|
||||
return ptEntry(comp?.name ?? "", map, comp?.material);
|
||||
});
|
||||
if (terrainMeshes(project).some((t) => !terrainComponentMaterial(project, t))) {
|
||||
const grass = TERRAIN_GRASS_MATERIAL;
|
||||
const i = out.findIndex((e) => e.map === grass.color);
|
||||
if (i >= 0) out[i] = { ...out[i], terrain: true };
|
||||
else out.push({ ...ptEntry("Wiese", grass.color!, grass), terrain: true });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,11 +12,15 @@
|
||||
* `materialIndex` je Wand-Band ableitet (1-basiert; Ebene 0 = Fallback-
|
||||
* Schachbrett). So zeigt Band-Index i+1 auf die (i)-te dekodierte Ebene, ohne
|
||||
* dass eine explizite Zuordnungstabelle zwischen JS und Rust wandern muss.
|
||||
*
|
||||
* [212] Etappe 4: Die Ebenen folgen {@link pathtraceMaterials} (= {@link wallMaterialColorMaps}, dahinter evtl. die
|
||||
* Wiese des Geländes ohne Material). Dazu je Ebene die Normalen- und Rauigkeitskarte des Bauteils für den Pathtracer
|
||||
* (`set_material_detail_textures`; fehlende bleiben schwarz = keine Karte).
|
||||
*/
|
||||
|
||||
import { netFetch } from "../net/net";
|
||||
import type { Project } from "../model/types";
|
||||
import { wallMaterialColorMaps } from "../core";
|
||||
import { pathtraceMaterials, type PtMaterialEntry } from "../core";
|
||||
|
||||
/** Kantenlänge einer Textur-Ebene in Texeln (muss zu render3d `TEXTURE_SIZE`). */
|
||||
const TEX_SIZE = 256;
|
||||
@@ -25,8 +29,12 @@ const TEX_SIZE = 256;
|
||||
export interface DecodedMaterialTextures {
|
||||
/** `count * TEX_SIZE * TEX_SIZE * 4` Bytes: je Material eine 256×256-RGBA-Ebene. */
|
||||
data: Uint8Array;
|
||||
/** Anzahl Material-Ebenen (== `wallMaterialColorMaps(project).length`). */
|
||||
/** Anzahl Material-Ebenen (== `pathtraceMaterials(project).length`). */
|
||||
count: number;
|
||||
/** [212] Normalenkarten (gleiches Format wie `data`), null ohne jede Karte. */
|
||||
normal: Uint8Array | null;
|
||||
/** [212] Rauigkeitskarten (gleiches Format wie `data`), null ohne jede Karte. */
|
||||
rough: Uint8Array | null;
|
||||
/** Signatur (die URL-Liste), um unveränderte Material-Mengen nicht neu zu dekodieren. */
|
||||
signature: string;
|
||||
}
|
||||
@@ -42,7 +50,8 @@ export async function decodeMaterialTextures(
|
||||
project: Project,
|
||||
): Promise<DecodedMaterialTextures | null> {
|
||||
if (typeof document === "undefined") return null;
|
||||
const urls = wallMaterialColorMaps(project);
|
||||
const entries = pathtraceMaterials(project);
|
||||
const urls = entries.map((e) => e.map);
|
||||
if (urls.length === 0) return null;
|
||||
|
||||
const canvas = document.createElement("canvas");
|
||||
@@ -52,21 +61,35 @@ export async function decodeMaterialTextures(
|
||||
if (!ctx) return null;
|
||||
|
||||
const bytesPerLayer = TEX_SIZE * TEX_SIZE * 4;
|
||||
const data = new Uint8Array(urls.length * bytesPerLayer);
|
||||
for (let i = 0; i < urls.length; i++) {
|
||||
const decodeInto = async (url: string, out: Uint8Array, i: number): Promise<void> => {
|
||||
try {
|
||||
const img = await loadImage(urls[i]);
|
||||
const img = await loadImage(url);
|
||||
ctx.clearRect(0, 0, TEX_SIZE, TEX_SIZE);
|
||||
// Auf 256×256 skalieren (die Ebenen eines Arrays müssen gleich groß sein).
|
||||
ctx.drawImage(img, 0, 0, TEX_SIZE, TEX_SIZE);
|
||||
const pixels = ctx.getImageData(0, 0, TEX_SIZE, TEX_SIZE);
|
||||
data.set(pixels.data, i * bytesPerLayer);
|
||||
out.set(pixels.data, i * bytesPerLayer);
|
||||
} catch {
|
||||
// Fehlgeschlagenes Bild: Ebene bleibt schwarz (0) — render3d klemmt bei
|
||||
// Bedarf ohnehin auf gültige Ebenen; die übrigen Materialien stimmen.
|
||||
}
|
||||
}
|
||||
return { data, count: urls.length, signature: urls.join("") };
|
||||
};
|
||||
const data = new Uint8Array(urls.length * bytesPerLayer);
|
||||
for (let i = 0; i < urls.length; i++) await decodeInto(urls[i], data, i);
|
||||
// [212] Normalen- und Rauigkeitskarten nur, wenn mindestens ein Eintrag sie hat (sonst kein Speicher).
|
||||
const detail = async (pick: (e: PtMaterialEntry) => string | undefined): Promise<Uint8Array | null> => {
|
||||
if (!entries.some((e) => pick(e))) return null;
|
||||
const out = new Uint8Array(urls.length * bytesPerLayer);
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const url = pick(entries[i]);
|
||||
if (url) await decodeInto(url, out, i);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const normal = await detail((e) => e.normal);
|
||||
const rough = await detail((e) => e.rough);
|
||||
const signature = entries.map((e) => `${e.map}|${e.normal ?? ""}|${e.rough ?? ""}`).join("\n");
|
||||
return { data, count: urls.length, signature, normal, rough };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,6 +124,9 @@ interface WebModelRendererLike {
|
||||
/** [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] Etappe 4: Normalen- und Rauigkeitskarten des Pathtracers (`web::set_material_detail_textures`), Ebenen wie
|
||||
* `set_material_textures` (leere Puffer = keine Karten). Optional — ältere WASM-Builds. */
|
||||
set_material_detail_textures?(normal: Uint8Array, rough: Uint8Array, layerCount: number): 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;
|
||||
@@ -392,6 +395,9 @@ export function useWasm3dRenderer(
|
||||
if (!cur || typeof cur.set_material_textures !== "function") return;
|
||||
if (decoded) cur.set_material_textures(decoded.data, decoded.count);
|
||||
else cur.set_material_textures(new Uint8Array(0), 0); // zurück auf Schachbrett
|
||||
// [212] Normalen-/Rauigkeitskarten des Pathtracers (gleiche Ebenen; leere Puffer = keine).
|
||||
const none = new Uint8Array(0);
|
||||
cur.set_material_detail_textures?.(decoded?.normal ?? none, decoded?.rough ?? none, decoded?.count ?? 0);
|
||||
} catch (e) {
|
||||
console.warn("render3d set_material_textures fehlgeschlagen:", e);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user