[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
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user