[201] IFC-GlobalId-Rundreise, Normalen in glTF/OBJ

- ifcGlobalId an Wand, Öffnung, Decke, Stütze, Dach, Treppe, Raum, Extrusionskörper: Import setzt sie, Export schreibt sie zurück
  (Datensatz GUIDS), sonst weiter abgeleitet; doppelte/ungültige fallen auf die abgeleitete zurück. Kopieren, Einfügen, Reihe,
  Spiegeln und Wand teilen setzen sie nicht mit. BCF-Zuordnung nimmt sie.
- glTF/GLB mit NORMAL, OBJ mit vn/usemtl und .mtl (zweite Datei: zweiter Speichern-Dialog, CLI schreibt beide). Normalen aus
  hatchgen/mesh_normals.rs, derselben Funktion wie die 3D-Anzeige (aus render3d verschoben).
- Doku DATEIFORMATE.md und TODO.md nachgeführt.
This commit is contained in:
Claude committed 2026-11-12 09:20:42 +00:00
1 parent 5ca168cb87
commit 6d84697163
33 files changed
+798 -157

No files matched your search

+11
View File
@@ -121,6 +121,17 @@ describe("BCF-GlobalId-Zuordnung", () => {
expect(resolveGuids(sampleProject, [g]).selection.wallIds).toEqual([w.id]);
});
it("[201] Bauteil mit übernommener ifcGlobalId: sie gilt statt der abgeleiteten (beide Richtungen)", () => {
const own = "2O2Fr$t4X7Zf8NOew3FLOH";
const p = { ...sampleProject, walls: sampleProject.walls.map((w, i) => (i === 0 ? { ...w, ifcGlobalId: own } : w)) } as Project;
const w = p.walls[0];
expect(resolveGuids(p, [own]).selection.wallIds).toEqual([w.id]);
expect(resolveGuids(p, [ifcGuid(`${p.id}/wall/${w.id}`)]).missing).toHaveLength(1);
const sel = emptyBcfSelection();
sel.wallIds = [w.id];
expect(selectionToGuids(p, sel)).toEqual([own]);
});
it("unbekannte GUIDs werden gemeldet", () => {
const r = resolveGuids(sampleProject, ["0000000000000000000000", ifcGuid(`${sampleProject.id}/wall/${sampleProject.walls[0].id}`)]);
expect(r.missing).toEqual(["0000000000000000000000"]);
+25 -19
View File
@@ -2,7 +2,8 @@
//
// Dieselbe Ableitung wie der IFC-Export (`exportIfc.ts`/`ifc_export/mod.rs`: `ifcGuid("<Projekt-id>/<Art>/<id>")`),
// damit die Rundreise Dossier → IFC → Solibri → BCF → Dossier trifft. Importierte Meshes tragen die
// GlobalId ihres Quell-Bauteils (`ImportedMesh.ifcGlobalId`). Bauteile, die im Export nicht vorkommen
// GlobalId ihres Quell-Bauteils (`ImportedMesh.ifcGlobalId`); erkannte Bauteile des IFC-Imports ebenso (`ifcGlobalId`,
// [201]: der Export schreibt sie zurück, sie gilt statt der abgeleiteten). Bauteile, die im Export nicht vorkommen
// (2D-Zeichnungen, Gruppen), haben keine GlobalId.
import type { BcfViewpoint } from "./bcf";
@@ -49,17 +50,21 @@ interface Target {
export function buildGuidIndex(project: Project): Map<string, Target> {
const index = new Map<string, Target>();
const pid = project.id;
const add = (key: string, channel: BcfChannel, id: string) => index.set(ifcGuid(`${pid}/${key}/${id}`), { channel, id });
for (const w of project.walls ?? []) add("wall", "wallIds", w.id);
for (const c of project.ceilings ?? []) add("slab", "ceilingIds", c.id);
for (const r of project.roofs ?? []) add("roof", "roofIds", r.id);
for (const c of project.columns ?? []) add("column", "columnIds", c.id);
for (const s of project.stairs ?? []) add("stair", "stairIds", s.id);
for (const e of project.extrudedSolids ?? []) add("extrusion", "extrudedSolidIds", e.id);
for (const r of project.rooms ?? []) add("space", "roomIds", r.id);
// Übernommene GlobalId (Import) vor der abgeleiteten; bei doppelter GlobalId gilt der erste (wie im Export).
const add = (key: string, channel: BcfChannel, id: string, own?: string) => {
const g = own || ifcGuid(`${pid}/${key}/${id}`);
if (!index.has(g)) index.set(g, { channel, id });
};
for (const w of project.walls ?? []) add("wall", "wallIds", w.id, w.ifcGlobalId);
for (const c of project.ceilings ?? []) add("slab", "ceilingIds", c.id, c.ifcGlobalId);
for (const r of project.roofs ?? []) add("roof", "roofIds", r.id, r.ifcGlobalId);
for (const c of project.columns ?? []) add("column", "columnIds", c.id, c.ifcGlobalId);
for (const s of project.stairs ?? []) add("stair", "stairIds", s.id, s.ifcGlobalId);
for (const e of project.extrudedSolids ?? []) add("extrusion", "extrudedSolidIds", e.id, e.ifcGlobalId);
for (const r of project.rooms ?? []) add("space", "roomIds", r.id, r.ifcGlobalId);
for (const o of project.openings ?? []) {
// Tür/Fenster (IfcDoor/IfcWindow) und Öffnung (IfcOpeningElement) gehören zur selben Dossier-Öffnung.
add("fill", "openingIds", o.id);
add("fill", "openingIds", o.id, o.ifcGlobalId);
add("opening", "openingIds", o.id);
}
for (const o of project.context ?? []) {
@@ -96,15 +101,16 @@ export function viewpointGuids(vp: BcfViewpoint): string[] {
export function selectionToGuids(project: Project, sel: BcfSelection): string[] {
const pid = project.id;
const guids: string[] = [];
const g = (key: string, ids: string[]) => ids.forEach((id) => guids.push(ifcGuid(`${pid}/${key}/${id}`)));
g("wall", sel.wallIds);
g("slab", sel.ceilingIds);
g("roof", sel.roofIds);
g("column", sel.columnIds);
g("stair", sel.stairIds);
g("extrusion", sel.extrudedSolidIds);
g("space", sel.roomIds);
g("fill", sel.openingIds);
const g = (key: string, ids: string[], items: { id: string; ifcGlobalId?: string }[] | undefined) =>
ids.forEach((id) => guids.push(items?.find((e) => e.id === id)?.ifcGlobalId || ifcGuid(`${pid}/${key}/${id}`)));
g("wall", sel.wallIds, project.walls);
g("slab", sel.ceilingIds, project.ceilings);
g("roof", sel.roofIds, project.roofs);
g("column", sel.columnIds, project.columns);
g("stair", sel.stairIds, project.stairs);
g("extrusion", sel.extrudedSolidIds, project.extrudedSolids);
g("space", sel.roomIds, project.rooms);
g("fill", sel.openingIds, project.openings);
for (const id of sel.contextObjectIds) {
const o = (project.context ?? []).find((c) => c.id === id);
if (o?.type === "importedMesh" && o.ifcGlobalId) guids.push(o.ifcGlobalId);
+66
View File
@@ -0,0 +1,66 @@
// [201] IFC-GlobalId-Rundreise: der Import setzt `ifcGlobalId` an jedem erkannten Bauteil (Wand, Öffnung, Decke, Stütze, Dach,
// Treppe, Raum, Extrusion), der Export schreibt sie zurück; ohne sie bleibt es bei der abgeleiteten GUID. Doppelte
// GlobalIds (Datei zweimal importiert) landen nie doppelt in der Ausgabe.
import "../engine/fileioWasm.setup";
import { describe, expect, it } from "vitest";
import { exportIfcSpf } from "../export/exportIfc";
import { emptyProject, sampleProject } from "../model/sampleProject";
import type { Project } from "../model/types";
import { importIfcInto } from "./importView.testutil";
const bytesOf = (s: string) => new TextEncoder().encode(s);
/** GlobalIds je IFC-Klasse (nur die 22-stelligen Kennungen am Anfang einer Entität). */
function guidsByClass(spf: string): Map<string, string[]> {
const out = new Map<string, string[]>();
for (const m of spf.matchAll(/#\d+=(IFC[A-Z0-9]+)\('([0-9A-Za-z_$]{22})'/g)) {
out.set(m[1], [...(out.get(m[1]) ?? []), m[2]]);
}
for (const v of out.values()) v.sort();
return out;
}
async function imported(base: Project, src: Project): Promise<Project> {
return (await importIfcInto(base, bytesOf(exportIfcSpf(src)), { elements: true })).project;
}
const BIM = ["IFCWALL", "IFCSLAB", "IFCDOOR", "IFCWINDOW", "IFCROOF", "IFCSTAIR", "IFCSPACE"];
describe("[201] IFC-GlobalId-Rundreise", () => {
it("Import setzt ifcGlobalId an jedem erkannten Bauteil", async () => {
const p = await imported(emptyProject, sampleProject);
const all = [...p.walls, ...(p.openings ?? []), ...(p.ceilings ?? []), ...(p.roofs ?? []), ...(p.stairs ?? []), ...(p.rooms ?? [])];
expect(all.length).toBeGreaterThan(10);
for (const e of all) expect(e.ifcGlobalId, `${e.type} ${e.id}`).toMatch(/^[0-3][0-9A-Za-z_$]{21}$/);
});
it("Import → Export: gleiche GlobalIds je Klasse wie die Quelldatei", async () => {
const a = guidsByClass(exportIfcSpf(sampleProject));
const p = await imported(emptyProject, sampleProject);
const b = guidsByClass(exportIfcSpf(p));
for (const cls of BIM) {
expect(a.get(cls)?.length ?? 0, `${cls} in der Quelle`).toBeGreaterThan(0);
expect(b.get(cls), cls).toEqual(a.get(cls));
}
});
it("ohne ifcGlobalId bleibt die abgeleitete GUID (deterministisch wie bisher)", () => {
const x = guidsByClass(exportIfcSpf(sampleProject));
const y = guidsByClass(exportIfcSpf(sampleProject));
expect(x.get("IFCWALL")).toEqual(y.get("IFCWALL"));
});
it("dieselbe Datei zweimal importiert: keine GlobalId doppelt in der Ausgabe", async () => {
const once = await imported(emptyProject, sampleProject);
const twice = await imported(once, sampleProject);
expect(twice.walls.length).toBe(once.walls.length * 2);
const spf = exportIfcSpf(twice);
const all = [...spf.matchAll(/#\d+=IFC[A-Z0-9]+\('([0-9A-Za-z_$]{22})'/g)].map((m) => m[1]);
expect(new Set(all).size).toBe(all.length);
// Die erste Kopie behält die ursprünglichen GlobalIds.
const src = guidsByClass(exportIfcSpf(sampleProject)).get("IFCWALL")!;
const out = new Set(guidsByClass(spf).get("IFCWALL")!);
for (const g of src) expect(out.has(g)).toBe(true);
});
});