Merge branch 'worktree-agent-ac143182c4c59003b' into claude/practical-noether-1hb2s1
This commit is contained in:
33 files changed
+798
-157
No files matched your search
@@ -3,7 +3,7 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import validator from "gltf-validator";
|
||||
import { exportGlb, exportGltf, exportObj } from "./exportMesh";
|
||||
import { exportGlb, exportGltf, exportMtl, exportObj } from "./exportMesh";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
|
||||
interface Gltf {
|
||||
@@ -83,3 +83,39 @@ describe("glTF-Export", () => {
|
||||
expect(g.materials.some((m) => names.includes(m.name))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("[201] Normalen und MTL", () => {
|
||||
it("jede Primitive trägt NORMAL (gleiche Anzahl wie POSITION); Validator ohne Meldung zu Normalen", async () => {
|
||||
const glb = exportGlb(sampleProject);
|
||||
const g = glbJson(glb) as Gltf & { meshes: { primitives: { attributes: { POSITION: number; NORMAL?: number } }[] }[] };
|
||||
for (const m of g.meshes) {
|
||||
for (const p of m.primitives) {
|
||||
expect(p.attributes.NORMAL).toBeDefined();
|
||||
expect(g.accessors[p.attributes.NORMAL!].count).toBe(g.accessors[p.attributes.POSITION].count);
|
||||
expect(g.accessors[p.attributes.NORMAL!].type).toBe("VEC3");
|
||||
}
|
||||
}
|
||||
const report = await validator.validateBytes(glb, { maxIssues: 200 });
|
||||
const normalIssues = report.issues.messages.filter((m) => /NORMAL|normal/.test(m.code + m.message));
|
||||
expect(normalIssues).toEqual([]);
|
||||
});
|
||||
|
||||
it("OBJ: vn zu jeder Fläche, usemtl je Material, mtllib nur mit MTL; MTL nennt jedes verwendete Material", () => {
|
||||
const withMtl = exportObj(sampleProject, {}, "haus.mtl");
|
||||
const lines = withMtl.split("\n");
|
||||
expect(lines).toContain("mtllib haus.mtl");
|
||||
const faces = lines.filter((l) => l.startsWith("f "));
|
||||
expect(lines.filter((l) => l.startsWith("vn ")).length).toBeGreaterThan(0);
|
||||
for (const f of faces) expect(f).toMatch(/^f \d+\/\/\d+ \d+\/\/\d+ \d+\/\/\d+$/);
|
||||
const used = new Set(lines.filter((l) => l.startsWith("usemtl ")).map((l) => l.slice(7)));
|
||||
expect(used.size).toBeGreaterThan(1);
|
||||
const mtl = exportMtl(sampleProject);
|
||||
const defined = new Set(mtl.split("\n").filter((l) => l.startsWith("newmtl ")).map((l) => l.slice(7)));
|
||||
for (const u of used) expect(defined.has(u), u).toBe(true);
|
||||
expect(mtl).toMatch(/\nKd [\d.]+ [\d.]+ [\d.]+\n/);
|
||||
// Ohne MTL: keine mtllib, Farben im Kopf als Kommentar.
|
||||
const plain = exportObj(sampleProject);
|
||||
expect(plain).not.toContain("mtllib");
|
||||
expect(plain).toMatch(/\n# \S+: Kd /);
|
||||
});
|
||||
});
|
||||
@@ -10,7 +10,7 @@ import { join } from "node:path";
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { exportIfcSpf, ifcGuid } from "./exportIfc";
|
||||
import { wallMeshVolumes } from "./meshScene.testutil";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { emptyProject, sampleProject } from "../model/sampleProject";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import type { Project } from "../model/types";
|
||||
|
||||
@@ -164,6 +164,15 @@ describe.skipIf(!hasIfcOpenShell)("IFC-Export gegen ifcopenshell", { timeout: 60
|
||||
expect(r.out).toContain("0 Befunde");
|
||||
expect(r.status).toBe(0);
|
||||
});
|
||||
it("[201] Import → Export mit übernommenen GlobalIds: gültig (22 Zeichen, keine doppelten)", async () => {
|
||||
const { importIfcInto } = await import("../io/importView.testutil");
|
||||
const first = (await importIfcInto(emptyProject, new TextEncoder().encode(exportIfcSpf(sampleProject)), { elements: true })).project;
|
||||
const ifc = exportIfcSpf(first);
|
||||
expect(ifc).toContain(`'${first.walls[0].ifcGlobalId}'`);
|
||||
const r = validate("globalid-rundreise", ifc);
|
||||
expect(r.out).toContain("0 Befunde");
|
||||
expect(r.status).toBe(0);
|
||||
}, 240_000);
|
||||
it("[191] Decken/Räume mit Bogenkanten: IfcCompositeCurve mit IfcTrimmedCurve, gültig", () => {
|
||||
const ifc = exportIfcSpf(buildComplexSampleProject());
|
||||
expect(ifc).toContain("IFCCOMPOSITECURVE(");
|
||||
|
||||
@@ -86,7 +86,7 @@ function objVolumes(obj: string): Map<string, number> {
|
||||
cur = l.slice(2).trim();
|
||||
out.set(cur, 0);
|
||||
} else if (l.startsWith("f ")) {
|
||||
const [a, b, c] = l.slice(2).trim().split(/\s+/).map((i) => verts[Number(i) - 1]);
|
||||
const [a, b, c] = l.slice(2).trim().split(/\s+/).map((i) => verts[Number(i.split("/")[0]) - 1]); // [201]: `v//vn`
|
||||
const v =
|
||||
a[0] * (b[1] * c[2] - b[2] * c[1]) - a[1] * (b[0] * c[2] - b[2] * c[0]) + a[2] * (b[0] * c[1] - b[1] * c[0]);
|
||||
out.set(cur, (out.get(cur) ?? 0) + v / 6);
|
||||
|
||||
@@ -164,7 +164,7 @@ function parseObjFaces(obj: string): number[][] {
|
||||
return obj
|
||||
.split("\n")
|
||||
.filter((l) => l.startsWith("f "))
|
||||
.map((l) => l.slice(2).trim().split(/\s+/).map(Number));
|
||||
.map((l) => l.slice(2).trim().split(/\s+/).map((t) => Number(t.split("/")[0]))); // [201]: `v//vn`
|
||||
}
|
||||
|
||||
describe("exportObj — Wavefront-OBJ-Export", () => {
|
||||
|
||||
@@ -38,10 +38,17 @@ function write<T extends string | Uint8Array>(project: Project, opts: MeshOption
|
||||
* Baut einen vollständigen Wavefront-OBJ-String des 3D-Gebäudemodells (Meter, Y-up rechtshändig:
|
||||
* Modell (x, y, z-hoch) → (x, z, −y)). Ein `o`-Objekt je Bauteil-Vorkommen (Wand, Decke, Extrusion, Dach,
|
||||
* Treppe, Stütze, Fenster/Tür, Kontext-Mesh). Leeres Projekt ⇒ gültige Datei nur mit Kopf-Kommentaren.
|
||||
* Verlangt das geladene Format-Modul (`await loadFileio()`).
|
||||
* Mit Normalen (`vn`, geteilt bis 30° Knickwinkel wie die 3D-Anzeige) und `usemtl` je Material ([201]). `mtlName` =
|
||||
* Dateiname der MTL daneben (`mtllib`, Datei von {@link exportMtl}); leer ⇒ ohne MTL, die Farben stehen dann als
|
||||
* Kommentar im Kopf. Verlangt das geladene Format-Modul (`await loadFileio()`).
|
||||
*/
|
||||
export function exportObj(project: Project, opts: MeshOptions = {}): string {
|
||||
return write(project, opts, false, (m, b, s) => m.export_mesh_obj_flat(b, s));
|
||||
export function exportObj(project: Project, opts: MeshOptions = {}, mtlName = ""): string {
|
||||
return write(project, opts, false, (m, b, s) => m.export_mesh_obj_flat(b, s, mtlName));
|
||||
}
|
||||
|
||||
/** MTL-Datei mit den Farben (`Kd`, Deckkraft `d`) der OBJ-Materialien aus {@link exportObj} ([201]). */
|
||||
export function exportMtl(project: Project, opts: MeshOptions = {}): string {
|
||||
return write(project, opts, false, (m, b, s) => m.export_mesh_mtl_flat(b, s));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +70,8 @@ export interface GltfOptions extends MeshOptions {
|
||||
* glTF 2.0 binär (GLB) für Blender, Twinmotion, Enscape, Web-Viewer. Ein Knoten je Bauteil (Name
|
||||
* `Wand_<id>`, `Decke_<id>`, `Dach_<id>`, `Treppe_<id>`, `Stuetze_<id>`, `Fenster_<id>`, `Tuer_<id>`,
|
||||
* `Extrusion_<id>`, `Kontext_<id>`, `Gelaende_<id>`; `extras` = Typ + id), PBR-Materialien mit der
|
||||
* Farbe der Bauteilschicht, Verglasung transparent (`BLEND`), Geschosse als Eltern-Knoten. Meter;
|
||||
* Farbe der Bauteilschicht, Verglasung transparent (`BLEND`), `NORMAL` je Ecke (geteilt bis 30° Knickwinkel wie die
|
||||
* 3D-Anzeige, scharfe Kanten bleiben kantig), Geschosse als Eltern-Knoten. Meter;
|
||||
* rechtshändig, Y-up: Modell (x, y, z-hoch) → (x, z, −y), Norden = −Z. Verlangt das geladene
|
||||
* Format-Modul (`await loadFileio()`).
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user