[115][G1][180] 3D: freie Körper aus den Kern-Netzen statt truck
Eine Quelle für die Geometrie freier Körper: 3D-Bild, Pick, Explosion, Abzugskörper an Wänden/Decken und die Kennwerte der Objekt-Info nehmen dieselben Kern-Netze (solid_mesh.rs, Manifold) wie Grundriss, Schnitt und Ansicht. - model3d/solids.rs: Teil solidMeshes (Owner::Solid für den Klassen-Filter, Farbe/Textur aus componentId, glatt schattiert), 3D-Facettierung mindestens 48 je Vollkreis (Fugen unter dem 15°-Kantenwinkel von render3d), Explosion hebt mit dem Geschoss. - pick_solids: Dreiecke des Kern-Netzes statt Prisma-Näherung. - solid_specs::void_meshes: Wand/Decke minus Abzugskörper im Kern (Teil voidMeshes) statt truck-Boolean in TS. - Abfrage solidProps (Volumen, Oberfläche, Schwerpunkt) statt truck. - Volle Verjüngung ergibt eine Pyramide (Netz-Spezifikation). - Entfernt: toWalls3d/extrusions.ts, TRUCK_MESH_READY_EVENT, truck-Wrapper extrudePolygon/extrudeCircle/buildSolidMesh, needsBrepPath. truck bleibt für STEP und Kollisionsprüfung. - Golden komplex-model3d: drei Körper neu im Modell.
This commit is contained in:
38 files changed
+507
-505
No files matched your search
+3
-3
@@ -11,7 +11,7 @@ Fassaden, die den Kern fragen, und die Leser der Plan-Puffer. Die Hülle importi
|
||||
| `generatePlan.ts` | `generatePlan()`, `generateVisibleLevelsPlan()`: Grundriss eines Geschosses aus der Kern-Abfrage `planDomains`; Typ `Plan` |
|
||||
| `generatePlan/shared.ts` | Typ `Primitive` (Austauschformat aller Plan-Verbraucher), `HatchRender`, Detailgrad |
|
||||
| `generatePlan/layerSig.ts` | Signatur der stilrelevanten Ebenen-Eigenschaften (Cache-Schlüssel) |
|
||||
| `toSection.ts` | `computeSection()` (Körper-Netze über truck), `generateSectionPlan()` (Abfrage `sectionPlan`) |
|
||||
| `toSection.ts` | `computeSection()` (Cache-Schlüssel; Körper-Netze rechnet der Kern), `generateSectionPlan()` (Abfrage `sectionPlan`) |
|
||||
| `toElevation.ts` | `generateElevationPlan()` (Abfrage `elevationPlan`) |
|
||||
| `viewportPlan.ts` | Inhalt eines Layout-Viewports: Plan der Ebene, auf die sein Ausschnitt zeigt (mit verknüpfter Ansichtsvorlage) |
|
||||
| `viewTemplate.ts` | [34] Ansichtsvorlage → Projekt/Anzeigewerte für Viewport und CLI (`projectWithTemplate`, `templateDisplay`) |
|
||||
@@ -36,7 +36,7 @@ Fassaden, die den Kern fragen, und die Leser der Plan-Puffer. Die Hülle importi
|
||||
|---|---|
|
||||
| `glPlan/` | GPU-Chunk-Cache (`glPlanChunks.ts`) und Fassaden der GPU-Kompilierung und Schraffur (`glPlanCompile.ts`, `glPlanHatch.ts`) für den nativen macOS-Weg |
|
||||
| `planView/` | reine Helfer der Plan-Ansicht: Picken über den Kern-Index (`planPick.ts`), Culling, Marquee, Massstab |
|
||||
| `toWalls3d/` | Teile der 3D-Ableitung, die TS bleiben: truck-Körper (`extrusions.ts`, `voids3d.ts`), gemeinsame Typen (`shared.ts`) |
|
||||
| `toWalls3d/` | Teile der 3D-Ableitung, die TS bleiben: Abzugskörper-Netze des Kerns einsetzen (`voids3d.ts`), gemeinsame Typen (`shared.ts`) |
|
||||
| `__golden__/` | Referenz-Digests für `golden.test.ts` |
|
||||
|
||||
## 3D und Körper
|
||||
@@ -44,7 +44,7 @@ Fassaden, die den Kern fragen, und die Leser der Plan-Puffer. Die Hülle importi
|
||||
| Datei | Inhalt |
|
||||
|---|---|
|
||||
| `toWalls3d.ts` | `projectToModel3d()`, `projectToModel3dParts()`: 3D-Modell aus dem Kern (`model3dParts`), Pick-Geometrie, Auswahl-Umrisse |
|
||||
| `extrudedSolidSpec.ts` | `ExtrudedSolid` → B-Rep-Spezifikation für truck |
|
||||
| `extrudedSolidSpec.ts` | `ExtrudedSolid` → B-Rep-Spezifikation für truck (Kollisionsprüfung) |
|
||||
| `wallSpec.ts` | B-Rep-Spezifikation einer Wandschicht für truck |
|
||||
| `voids.ts` | Abzugskörper (Fassade) |
|
||||
| `surfaceOpening.ts` | Dach- und Deckenfenster: Lage in der Wirtsfläche |
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
meshes [1958]
|
||||
meshes[].color [3] x1958
|
||||
meshes [1961]
|
||||
meshes[].color [3] x1961
|
||||
meshes[].indices [108] x6
|
||||
meshes[].indices [11376]
|
||||
meshes[].indices [1152]
|
||||
meshes[].indices [12960]
|
||||
meshes[].indices [144] x55
|
||||
meshes[].indices [156642]
|
||||
meshes[].indices [1584]
|
||||
meshes[].indices [1716]
|
||||
meshes[].indices [180]
|
||||
meshes[].indices [192] x3
|
||||
meshes[].indices [348] x6
|
||||
meshes[].indices [360]
|
||||
meshes[].indices [36] x1860
|
||||
meshes[].indices [396]
|
||||
meshes[].indices [564]
|
||||
meshes[].indices [564] x2
|
||||
meshes[].indices [60] x9
|
||||
meshes[].indices [72]
|
||||
meshes[].indices [7632]
|
||||
@@ -27,17 +29,19 @@ meshes[].positions [216]
|
||||
meshes[].positions [24] x1828
|
||||
meshes[].positions [252] x2
|
||||
meshes[].positions [264]
|
||||
meshes[].positions [288] x7
|
||||
meshes[].positions [288] x8
|
||||
meshes[].positions [306] x3
|
||||
meshes[].positions [324] x6
|
||||
meshes[].positions [4128]
|
||||
meshes[].positions [4746]
|
||||
meshes[].positions [576]
|
||||
meshes[].positions [6096]
|
||||
meshes[].positions [7050]
|
||||
meshes[].positions [72] x2
|
||||
meshes[].positions [78837]
|
||||
meshes[].positions [78] x55
|
||||
meshes[].positions [798]
|
||||
meshes[].positions [864]
|
||||
roofLayers [59]
|
||||
roofLayers[].color [3] x59
|
||||
roofLayers[].normal [3] x59
|
||||
@@ -68,4 +72,4 @@ walls[].start [2] x1492
|
||||
walls[].startCut [4] x1107
|
||||
walls[].topDrop [2] x115
|
||||
walls[].topPlane [3] x271
|
||||
hash 11c141a0fe0852d7
|
||||
hash 1a05da01394b019d
|
||||
@@ -1,31 +1,28 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ExtrudedSolid } from "../model/types";
|
||||
import { extrudedSolidSpec, needsBrepPath } from "./extrudedSolidSpec";
|
||||
import { extrudedSolidSpec } from "./extrudedSolidSpec";
|
||||
|
||||
const sq = [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 2 }, { x: 0, y: 2 }];
|
||||
const base: ExtrudedSolid = { id: "e1", type: "extrudedSolid", categoryCode: "20", levelId: "eg", points: sq, height: 3 };
|
||||
|
||||
describe("extrudedSolidSpec", () => {
|
||||
it("Prisma ohne Besonderheiten bleibt auf dem alten Pfad", () => {
|
||||
expect(needsBrepPath(base)).toBe(false);
|
||||
it("Prisma ohne Besonderheiten: einfache Extrusion", () => {
|
||||
expect(extrudedSolidSpec(base, 1)).toMatchObject({ kind: "extrude", z0: 1, height: 3 });
|
||||
});
|
||||
|
||||
it("Eckenradius schaltet auf den B-Rep-Pfad und landet in der Spezifikation", () => {
|
||||
it("Eckenradius landet in der Spezifikation", () => {
|
||||
const s = { ...base, cornerRadius: 0.3 };
|
||||
expect(needsBrepPath(s)).toBe(true);
|
||||
expect(extrudedSolidSpec(s, 0)).toMatchObject({ kind: "extrude", cornerRadius: 0.3 });
|
||||
});
|
||||
|
||||
it("Fase schaltet ebenfalls auf den B-Rep-Pfad und landet in der Spezifikation", () => {
|
||||
it("Fase landet in der Spezifikation", () => {
|
||||
const s = { ...base, chamfer: 0.2 };
|
||||
expect(needsBrepPath(s)).toBe(true);
|
||||
expect(extrudedSolidSpec(s, 0)).toMatchObject({ kind: "extrude", chamfer: 0.2 });
|
||||
});
|
||||
|
||||
it("Verjüngung → Loft, volle Verjüngung (Pyramide) → keine B-Rep-Beschreibung", () => {
|
||||
it("Verjüngung → Loft, volle Verjüngung → Pyramide als Netz ([115])", () => {
|
||||
expect(extrudedSolidSpec({ ...base, taper: 0.5 }, 0)?.kind).toBe("loft");
|
||||
expect(extrudedSolidSpec({ ...base, taper: 1 }, 0)).toBeNull();
|
||||
expect(extrudedSolidSpec({ ...base, taper: 1 }, 0)).toMatchObject({ kind: "mesh", positions: [0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 2, 0, 1, 1, 3] });
|
||||
});
|
||||
|
||||
it("Kreisprofil → Zylinder bzw. Kegel", () => {
|
||||
@@ -40,7 +37,6 @@ describe("extrudedSolidSpec", () => {
|
||||
points: sq.map((p) => ({ x: p.x + 5, y: p.y - 1 })),
|
||||
brep: { spec: { kind: "sphere", center: [1, 1, 1], r: 1 }, origin: { x: 0, y: 0 } },
|
||||
};
|
||||
expect(needsBrepPath(moved)).toBe(true);
|
||||
expect(extrudedSolidSpec(moved, 2.6)).toEqual({
|
||||
kind: "translate",
|
||||
v: [5, -1, 2.6],
|
||||
|
||||
@@ -1,27 +1,16 @@
|
||||
// Übersetzt einen `ExtrudedSolid` des Projekts in eine B-Rep-Spezifikation (`SolidSpec`,
|
||||
// truck/trucksolid). Gemeinsame Quelle für den 3D-Viewer (Eckenradius, Grundkörper) und den
|
||||
// STEP-Export; die Beschreibung rechnet der Rust-Kern.
|
||||
// truck/trucksolid) für die Kollisionsprüfung; die Beschreibung rechnet der Rust-Kern (dieselbe, aus der er die
|
||||
// Körper-Netze für Grundriss, Schnitt, Ansicht und 3D baut, `solid_mesh.rs`, und die STEP-Spezifikationen).
|
||||
|
||||
import type { ExtrudedSolid } from "../model/types";
|
||||
import type { SolidSpec } from "../engine/truckSolid";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { fromMarkedJson, toMarkedJson } from "../core/ops";
|
||||
|
||||
/**
|
||||
* Ob der Körper über den B-Rep-Pfad (`buildSolidMesh`) gebaut werden muss: Grundkörper
|
||||
* (`brep`) und Profile mit Eckenradius. Alles andere nutzt weiter die Prisma-Extrusion
|
||||
* (`extrudePolygon`/`extrudeCircle`) — bitgleich zum bisherigen Verhalten.
|
||||
*/
|
||||
export function needsBrepPath(solid: ExtrudedSolid): boolean {
|
||||
if (solid.brep) return true;
|
||||
const rounded = (solid.cornerRadius ?? 0) > 1e-9 || (solid.chamfer ?? 0) > 1e-9;
|
||||
return rounded && !solid.circle && (solid.taper ?? 0) < 1e-6;
|
||||
}
|
||||
|
||||
/**
|
||||
* B-Rep-Spezifikation des Körpers, UK auf `baseZ` (Rust-Kern, `cmd_solid.rs::extruded_solid_spec`:
|
||||
* Grundkörper verschoben, Zylinder/Kegel bei Kreis-Profil, Extrusion mit Eckenradius/Fase, Loft bei
|
||||
* Verjüngung). `null`, wenn truck dafür (noch) keine Beschreibung hat (Pyramide: Spitze als B-Rep entartet).
|
||||
* Verjüngung, Pyramide als Netz). `null` ohne Körper (Höhe ≤ 0, zu wenig Punkte).
|
||||
*/
|
||||
export function extrudedSolidSpec(solid: ExtrudedSolid, floorZ: number): SolidSpec | null {
|
||||
const out = core().extruded_solid_spec_json(toMarkedJson(solid), floorZ);
|
||||
|
||||
@@ -112,8 +112,7 @@ export interface PickTreeMesh {
|
||||
|
||||
/**
|
||||
* [137] Freier Körper (`extrudedSolids`, Loft/Rotation/Abzug/B-Rep) für den Raycast: WORLD-Dreiecke
|
||||
* (x, Höhe, y). Der Kern liefert das Prisma über dem Umriss; sobald das truck-Netz geladen ist, ersetzt
|
||||
* `pickGeometry` (plan/toWalls3d.ts) es durch dessen Dreiecke.
|
||||
* (x, Höhe, y) des Kern-Netzes ([115], dasselbe wie im 3D-Bild; ohne Netz das Prisma über dem Umriss).
|
||||
*/
|
||||
export interface PickSolidMesh {
|
||||
tris: ReadonlyArray<readonly [Vec3, Vec3, Vec3]>;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// [137] Alles Sichtbare anwählbar im 3D: freie Körper (Prisma aus dem Kern, truck-Netz sobald geladen),
|
||||
// [137] Alles Sichtbare anwählbar im 3D: freie Körper (Netz aus dem Kern, [115]),
|
||||
// Stützen lagerichtig (x, Höhe, y wie die Darstellung), Hervorhebung beider, Gelände einzeln ausgeblendet.
|
||||
|
||||
import { describe, expect, it, afterEach } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Project, TerrainMesh } from "../model/types";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { pickGeometry, selectionHighlightLines } from "./toWalls3d";
|
||||
import { __setTruckMeshForTest } from "./toWalls3d/extrusions";
|
||||
import { pickGeometry, projectToModel3d, projectToModel3dParts, selectionHighlightLines } from "./toWalls3d";
|
||||
import { pickNearest, type Ray } from "../viewport/raycast3d";
|
||||
|
||||
const base: Project = {
|
||||
@@ -32,8 +31,6 @@ const pick = (p: Project, ray: Ray) => {
|
||||
return pickNearest(ray, g.walls, g.slabs, g.openings, g.stairs, g.roofs, g.contextMeshes, g.drawings, g.columns, g.solids);
|
||||
};
|
||||
|
||||
afterEach(() => __setTruckMeshForTest("s1", null));
|
||||
|
||||
describe("[137] 3D-Pick freie Körper und Stützen", () => {
|
||||
it("freier Körper: Prisma über dem Umriss, Abzugskörper nicht; Treffer von oben auf OK", () => {
|
||||
const g = pickGeometry(base);
|
||||
@@ -46,20 +43,27 @@ describe("[137] 3D-Pick freie Körper und Stützen", () => {
|
||||
expect(pick(base, down(40.5, 0.3))).toBeNull();
|
||||
});
|
||||
|
||||
it("geladenes truck-Netz ersetzt die Prisma-Näherung (z. B. Pyramide statt Quader)", () => {
|
||||
// Pyramide über demselben Umriss, Spitze bei (31, 3.5) auf 4.6 m (Modell x, y, z).
|
||||
__setTruckMeshForTest("s1", {
|
||||
positions: [30, 2, 3.1, 32, 2, 3.1, 32, 5, 3.1, 30, 5, 3.1, 31, 3.5, 4.6],
|
||||
indices: [0, 1, 4, 1, 2, 4, 2, 3, 4, 3, 0, 4, 0, 2, 1, 0, 3, 2],
|
||||
kind: "extrusion",
|
||||
color: [1, 1, 1],
|
||||
} as never);
|
||||
const hit = pick(base, down(30.1, 2.1));
|
||||
it("[115] Kern-Netz statt Prisma-Näherung (Verjüngung 1 = Pyramide), synchron ohne truck", () => {
|
||||
const pyr = { ...base, extrudedSolids: [{ ...base.extrudedSolids![0], taper: 0.999 }] } as Project;
|
||||
const hit = pick(pyr, down(30.1, 2.1));
|
||||
expect(hit?.id).toBe("s1");
|
||||
// Am Rand der Pyramide nahe der UK statt auf der Prisma-OK.
|
||||
// Am Rand der Pyramide nahe der UK (3.1) statt auf der Prisma-OK (4.6).
|
||||
expect(50 - hit!.t).toBeLessThan(3.3);
|
||||
});
|
||||
|
||||
it("[115] 3D-Modell und Teile enthalten die freien Körper als Kern-Netz, Klasse aus ⇒ weg", () => {
|
||||
const m = projectToModel3d(base);
|
||||
const solidMeshes = m.meshes.filter((x) => x.color[0] === 0.85 && x.color[1] === 0.55);
|
||||
expect(solidMeshes.length).toBe(1);
|
||||
const zs = solidMeshes[0].positions.filter((_, i) => i % 3 === 2);
|
||||
expect(Math.min(...zs)).toBeCloseTo(3.1, 9);
|
||||
expect(Math.max(...zs)).toBeCloseTo(4.6, 9);
|
||||
const parts = projectToModel3dParts(base)!;
|
||||
expect(parts.find((p) => p.id === "solids")?.meshes?.length).toBe(1);
|
||||
const hidden = projectToModel3dParts(base, { hide: ["20"] })!;
|
||||
expect(hidden.find((p) => p.id === "solids")?.meshes ?? []).toEqual([]);
|
||||
});
|
||||
|
||||
it("Stütze lagerichtig: Welt-z = +y (wie gezeichnet), nicht gespiegelt", () => {
|
||||
expect(pick(base, down(20, 3))?.kind).toBe("column");
|
||||
expect(pick(base, down(20, -3))).toBeNull();
|
||||
|
||||
+27
-58
@@ -37,8 +37,8 @@
|
||||
// gemeinsame Serde-Vokabular (`RWall`/`RSlab`/`RMesh`/…) und die Farb-/
|
||||
// Schraffur-/Material-Auflösung leben in `toWalls3d/shared.ts`; jede
|
||||
// Bauteil-Domäne (Wand-Bänder, Decken, Öffnungen, Treppen, Dächer, Stützen,
|
||||
// truck-Extrusionen, freie 2D-Geometrie) hat ihre eigene Datei unter
|
||||
// `toWalls3d/` — siehe dort für die konkrete Emissions-Logik je Bauteil.
|
||||
// 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 { collectVisibleCodes, flattenCategories } from "../model/types";
|
||||
@@ -54,13 +54,11 @@ import {
|
||||
type RVec2,
|
||||
type RWall,
|
||||
} from "./toWalls3d/shared";
|
||||
import { emitExtrudedSolids, truckSolidPickTris, TRUCK_MESH_READY_EVENT } from "./toWalls3d/extrusions";
|
||||
import { applyVoids3d, type VoidCuts } from "./toWalls3d/voids3d";
|
||||
import { applyVoidMeshes, type VoidMeshes } from "./toWalls3d/voids3d";
|
||||
|
||||
// Re-Export des gemeinsamen Vokabulars — externe Konsumenten (viewport/,
|
||||
// export/, toSection.ts, nativeSync.ts, …) importieren weiterhin
|
||||
// ausschliesslich von hier, unverändert zur Zeit vor dem Domänen-Split.
|
||||
export { TRUCK_MESH_READY_EVENT };
|
||||
export type { RVec2, RRgb, RWall, RSlab, RModel3d };
|
||||
|
||||
/**
|
||||
@@ -90,8 +88,8 @@ export function classFilterText(hide?: readonly string[], extra?: Record<string,
|
||||
}
|
||||
|
||||
/**
|
||||
* [180] Ausgeblendete Klassen-Codes (Ebenen-Baum samt Elternklassen, dazu `hide`) — für die TS-seitigen
|
||||
* 3D-Teile (truck-Körper); alles andere filtert der Kern.
|
||||
* [180] Ausgeblendete Klassen-Codes (Ebenen-Baum samt Elternklassen, dazu `hide`) — für die 3D-Zutaten, die
|
||||
* nicht aus dem Kern-Modell kommen (Schatten, Baurechts-Hülle); die Teile filtert der Kern.
|
||||
*/
|
||||
export function hiddenClassCodes(project: Project, hide?: readonly string[]): Set<string> {
|
||||
const out = new Set(hide ?? []);
|
||||
@@ -177,7 +175,7 @@ export interface Model3dOptions {
|
||||
/** Schnitt-Eingabe: Treppen immer als Tritt-Prismen (s. `emitStairs` `forSection`). */
|
||||
forSection?: boolean;
|
||||
/**
|
||||
* 3D-Viewer: Abzugskörper per truck-Boolean von Wänden/Decken abziehen (s.
|
||||
* 3D-Viewer: Abzugskörper von Wänden/Decken abziehen (Kern-Netze über Manifold, s.
|
||||
* `toWalls3d/voids3d.ts`). Schnitt/Ansicht/Export behandeln Abzugskörper selbst.
|
||||
*/
|
||||
voids?: boolean;
|
||||
@@ -204,17 +202,17 @@ export interface Model3dOptions {
|
||||
export function projectToModel3d(project: Project, opts: Model3dOptions = {}): RModel3d {
|
||||
const layered = opts.layeredWalls ?? true;
|
||||
const detail = opts.detail ?? "fein";
|
||||
// Mit `voids` liefert der Kern zusätzlich die getroffenen Wände/Decken als truck-Spezifikationen.
|
||||
// Mit `voids` liefert der Kern zusätzlich die getroffenen Wände/Decken als Netze „Bauteil − Körper".
|
||||
const explode = explodeGap(opts.explode);
|
||||
const voids = !!opts.voids && typeof window !== "undefined";
|
||||
const voids = !!opts.voids;
|
||||
const args = [layered ? 1 : 0, DETAIL_CODE[detail] ?? 3, opts.forSection ? 1 : 0, voids ? 1 : 0, explode];
|
||||
// Ohne Explosion inkrementell ([58]): nur geänderte Wände reisen aus dem Kern und werden gelesen.
|
||||
const doc = documentFor(project);
|
||||
const text = classFilterText(opts.hide, opts.modelView ? { modelView: opts.modelView } : undefined);
|
||||
const parts = opts.modelView || explode > 0 ? doc.query<Model3dParts>("model3dParts", args, text) : doc.model3dParts<Model3dParts>(args, text);
|
||||
// Die truck-Körper (asynchron, mit Cache) kommen zwischen Kontext-Meshes und Stützen.
|
||||
// [115] Freie Körper als Kern-Netze (`model3d/solids.rs`) zwischen Kontext-Meshes und Stützen.
|
||||
const meshes: RMesh[] = [...parts.contextMeshes];
|
||||
for (const m of emitExtrudedSolids(project, parts.floorOffsets, hiddenClassCodes(project, opts.hide))) meshes.push(m);
|
||||
for (const m of parts.solidMeshes) meshes.push(m);
|
||||
for (const m of parts.columnMeshes) meshes.push(m);
|
||||
for (const m of parts.openingMeshes) meshes.push(m);
|
||||
for (const m of parts.stairMeshes) meshes.push(m);
|
||||
@@ -229,7 +227,7 @@ export function projectToModel3d(project: Project, opts: Model3dOptions = {}): R
|
||||
meshes,
|
||||
roofLayers: parts.roofLayers,
|
||||
};
|
||||
if (parts.voidCuts) applyVoids3d(model, parts.voidCuts);
|
||||
if (parts.voidMeshes) applyVoidMeshes(model, parts.voidMeshes);
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -247,15 +245,6 @@ export interface Model3dPart {
|
||||
roofLayers?: RModel3d["roofLayers"];
|
||||
}
|
||||
|
||||
/** Stabile Nummer je Objekt (truck-Ergebnis der Abzugskörper) für die Teil-id. */
|
||||
const objectIds = new WeakMap<object, number>();
|
||||
let nextObjectId = 1;
|
||||
function objectId(o: object): number {
|
||||
let id = objectIds.get(o);
|
||||
if (id === undefined) objectIds.set(o, (id = nextObjectId++));
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Das 3D-Modell wie {@link projectToModel3d} (gleiche Wände, Decken, Meshes — nur anders gruppiert), aber
|
||||
* in Teilen ([58]): je Wand-Eintrag des Kern-Caches (`w…`) und je Öffnungs-Eintrag (`o…`) ein
|
||||
@@ -265,28 +254,16 @@ export function projectToModel3dParts(project: Project, opts: Model3dOptions = {
|
||||
const layered = opts.layeredWalls ?? true;
|
||||
const detail = opts.detail ?? "fein";
|
||||
if (explodeGap(opts.explode) > 0) return null;
|
||||
const voids = !!opts.voids && typeof window !== "undefined";
|
||||
const voids = !!opts.voids;
|
||||
const args = [layered ? 1 : 0, DETAIL_CODE[detail] ?? 3, opts.forSection ? 1 : 0, voids ? 1 : 0, 0];
|
||||
const { parts, keyed } = documentFor(project).model3dPartsKeyed<Model3dParts>(args, classFilterText(opts.hide));
|
||||
const wallEntries = keyed.wallEntries as (readonly [number, RWall[]])[];
|
||||
const openingEntries = keyed.openingEntries as (readonly [number, RMesh[][]])[];
|
||||
// Abzugskörper wie im vollen Modell (gleiche Reihenfolge, gleicher truck-Cache); danach zuordnen,
|
||||
// welche Wand/Decke durch welches Netz ersetzt wurde (Netze in Index-Reihenfolge der Schnitte).
|
||||
const vm: RModel3d = { walls: parts.walls, slabs: parts.slabs, meshes: [], roofLayers: [] };
|
||||
const wallMesh = new Map<number, RMesh>();
|
||||
const slabMeshes: RMesh[] = [];
|
||||
if (parts.voidCuts) {
|
||||
applyVoids3d(vm, parts.voidCuts);
|
||||
const keptW = new Set(vm.walls);
|
||||
const keptS = new Set(vm.slabs);
|
||||
let mi = 0;
|
||||
for (const i of parts.voidCuts.walls.map(([i]) => i).sort((a, b) => a - b)) {
|
||||
if (!keptW.has(parts.walls[i])) wallMesh.set(i, vm.meshes[mi++]);
|
||||
}
|
||||
for (const i of parts.voidCuts.slabs.map(([i]) => i).sort((a, b) => a - b)) {
|
||||
if (!keptS.has(parts.slabs[i])) slabMeshes.push(vm.meshes[mi++]);
|
||||
}
|
||||
}
|
||||
// Abzugskörper ([115], Kern-Netze): Wand/Decke durch ihr Netz ersetzen; der Inhalts-Schlüssel geht in die Teil-id.
|
||||
const wallMesh = new Map((parts.voidMeshes?.walls ?? []).map(([i, key, m]) => [i, [key, m] as const]));
|
||||
const slabCut = new Set((parts.voidMeshes?.slabs ?? []).map(([i]) => i));
|
||||
const slabMeshes = (parts.voidMeshes?.slabs ?? []).map(([, , m]) => m);
|
||||
const slabs = slabCut.size ? parts.slabs.filter((_, i) => !slabCut.has(i)) : parts.slabs;
|
||||
const ns = `${coreEpoch()}.`;
|
||||
const out: Model3dPart[] = [];
|
||||
let at = 0;
|
||||
@@ -299,8 +276,8 @@ export function projectToModel3dParts(project: Project, opts: Model3dOptions = {
|
||||
for (let i = start; i < at; i++) {
|
||||
const m = wallMesh.get(i);
|
||||
if (m) {
|
||||
meshes.push(m);
|
||||
cut += `.${i - start}m${objectId(m)}`;
|
||||
meshes.push(m[1]);
|
||||
cut += `.${i - start}m${m[0]}`;
|
||||
} else walls.push(parts.walls[i]);
|
||||
}
|
||||
out.push(cut ? { id: `w${ns}${k}${cut}`, fixed: true, walls, meshes } : { id: `w${ns}${k}`, fixed: true, walls });
|
||||
@@ -310,9 +287,9 @@ export function projectToModel3dParts(project: Project, opts: Model3dOptions = {
|
||||
if (meshes.length) out.push({ id: `o${ns}${k}`, fixed: true, meshes });
|
||||
}
|
||||
const rest = (id: string, p: Omit<Model3dPart, "id" | "fixed">) => out.push({ id, fixed: false, ...p });
|
||||
rest("slabs", { slabs: vm.slabs, meshes: slabMeshes });
|
||||
rest("slabs", { slabs, meshes: slabMeshes });
|
||||
rest("context", { meshes: parts.contextMeshes });
|
||||
rest("extrusions", { meshes: emitExtrudedSolids(project, parts.floorOffsets, hiddenClassCodes(project, opts.hide)) });
|
||||
rest("solids", { meshes: parts.solidMeshes });
|
||||
rest("columns", { meshes: parts.columnMeshes });
|
||||
rest("openingTail", { meshes: keyed.openingTail as RMesh[] });
|
||||
rest("stairs", { meshes: [...parts.stairMeshes, ...parts.stairRailings] });
|
||||
@@ -331,10 +308,10 @@ interface Model3dParts {
|
||||
stairRailings: RMesh[];
|
||||
roofMeshes: RMesh[];
|
||||
roofLayers: RModel3d["roofLayers"];
|
||||
/** Nur mit Abzugskörpern: (Index im Modell, Bauteil − Körper) je getroffene Wand/Decke. */
|
||||
voidCuts?: VoidCuts;
|
||||
/** Nur mit Explosion: Versatz (m) je Geschoss-id (für die truck-Extrusionen). */
|
||||
floorOffsets?: Record<string, number>;
|
||||
/** [115] Freie Körper (ohne Abzugskörper) als Kern-Netze, Klassen gefiltert, mit der Explosion angehoben. */
|
||||
solidMeshes: RMesh[];
|
||||
/** Nur mit Abzugskörpern: (Index im Modell, Schlüssel, Netz „Bauteil − Körper") je getroffene Wand/Decke. */
|
||||
voidMeshes?: VoidMeshes;
|
||||
}
|
||||
|
||||
/** Explosionsabstand bereinigt: endlich und > 0, sonst 0 (= aus). */
|
||||
@@ -377,16 +354,8 @@ export function pickGeometry(
|
||||
/** [149] Bäume (Stamm + Krone). */
|
||||
trees: PickTreeMesh[];
|
||||
} {
|
||||
const g = documentFor(project).query("pickGeometry", [explodeGap(explode)], classFilterText(hide)) as ReturnType<typeof pickGeometry>;
|
||||
// [137] Freie Körper: das geladene truck-Netz (Loft, Rotation, Verjüngung, Rundung) statt der Prisma-Näherung des Kerns.
|
||||
const gap = explodeGap(explode);
|
||||
const offsets = gap > 0 ? explodeFloorOffsets(project, gap) : undefined;
|
||||
const levelOf = new Map((project.extrudedSolids ?? []).map((s) => [s.id, s.levelId]));
|
||||
g.solids = (g.solids ?? []).map((s) => {
|
||||
const tris = truckSolidPickTris(s.solidId, offsets?.[levelOf.get(s.solidId) ?? ""] ?? 0);
|
||||
return tris ? { ...s, tris } : s;
|
||||
});
|
||||
return g;
|
||||
// [137]/[115] Freie Körper als Dreiecke ihres Kern-Netzes (dasselbe wie im Bild, mit der Explosion angehoben).
|
||||
return documentFor(project).query("pickGeometry", [explodeGap(explode)], classFilterText(hide)) as ReturnType<typeof pickGeometry>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
// Extrusions-Domäne der 3D-Ableitung (truck-Integration, `docs/design/
|
||||
// truck-plan.md`): extrudiert `project.extrudedSolids` asynchron zu Kontext-
|
||||
// Meshes, über einen modulweiten Cache je Solid-Id (siehe Moduldoc unten).
|
||||
|
||||
import type { ExtrudedSolid, Project } from "../../model/types";
|
||||
import { getFloor } from "../../model/types";
|
||||
import { buildSolidMesh, extrudeCircle, extrudePolygon } from "../../engine/truckSolid";
|
||||
import { extrudedSolidSpec, needsBrepPath } from "../extrudedSolidSpec";
|
||||
import type { RMesh, RRgb } from "./shared";
|
||||
import type { Vec3 } from "../pickTypes";
|
||||
|
||||
/** Warmes Orange für truck-Profil-Extrusionen (hebt sie klar von Wand/Decke/Kontext ab). */
|
||||
const EXTRUSION_RGB: RRgb = [0.85, 0.55, 0.25];
|
||||
|
||||
/** Event-Name für den "Extrusion(en) geladen"-Stoss (s. Wasm3DViewport.tsx/nativeSync.ts). */
|
||||
export const TRUCK_MESH_READY_EVENT = "dossier:truck-mesh-ready";
|
||||
|
||||
/**
|
||||
* Extrudiert `project.extrudedSolids` (truck-Integration, `docs/design/
|
||||
* truck-plan.md`) zu Kontext-Meshes. `extrudePolygon` lädt WASM asynchron;
|
||||
* `emitMeshes`/`emitExtrudedSolids` selbst bleiben synchron (Aufrufer wie
|
||||
* `updateModel`/`pushNativeWalls` erwarten das) — daher ein modulweiter Cache
|
||||
* je Solid-Id, der bei fehlendem/veraltetem Eintrag die Extrusion im
|
||||
* Hintergrund anstösst und `TRUCK_MESH_READY_EVENT` feuert, sobald sie fertig
|
||||
* ist (Wasm3DViewport/nativeSync hören darauf und re-pushen das Modell — ohne
|
||||
* das Signal käme eine fertige Extrusion trotz Erfolgs NIE ins Bild, weil
|
||||
* `updateModel` nur bei PROJEKT-Änderungen erneut läuft). Nur im Browser (kein
|
||||
* `window` unter vitest/node) und mit stillem Fallback bei Fehlern.
|
||||
*/
|
||||
interface TruckCacheEntry {
|
||||
/** Signatur (Punkte+Höhe) des Solids beim Laden — invalidiert den Eintrag bei Änderung. */
|
||||
signature: string;
|
||||
/** null, solange die Extrusion noch lädt. */
|
||||
mesh: RMesh | null;
|
||||
}
|
||||
const truckMeshCache = new Map<string, TruckCacheEntry>();
|
||||
|
||||
function extrudedSolidSignature(solid: ExtrudedSolid): string {
|
||||
const brep = solid.brep ? `${JSON.stringify(solid.brep.spec)}@${solid.brep.origin.x},${solid.brep.origin.y}` : "";
|
||||
return `${solid.baseOffset ?? 0}|${solid.height}|${solid.taper ?? 0}|${solid.cornerRadius ?? 0}|${solid.chamfer ?? 0}|${brep}|${solid.points.map((p) => `${p.x},${p.y}`).join(";")}`;
|
||||
}
|
||||
|
||||
export function emitExtrudedSolids(
|
||||
project: Project,
|
||||
/** Explosionsaxonometrie ([65]): Versatz (m) je Geschoss-id; der Cache bleibt unverschoben. */
|
||||
floorOffsets?: Record<string, number>,
|
||||
/** [180] Ausgeblendete Klassen: deren Körper fehlen (Cache bleibt). */
|
||||
hiddenCodes?: ReadonlySet<string>,
|
||||
): RMesh[] {
|
||||
if (typeof window === "undefined") return [];
|
||||
const out: RMesh[] = [];
|
||||
// Cache-Einträge gelöschter/nicht mehr existierender Körper verwerfen (sonst
|
||||
// wächst der Cache unbegrenzt über eine Session, z. B. nach Extrudieren →
|
||||
// Kopieren → Löschen in Serie).
|
||||
const liveIds = new Set((project.extrudedSolids ?? []).map((s) => s.id));
|
||||
for (const id of truckMeshCache.keys()) {
|
||||
if (!liveIds.has(id)) truckMeshCache.delete(id);
|
||||
}
|
||||
for (const solid of project.extrudedSolids ?? []) {
|
||||
if (solid.points.length < 3 || solid.height <= 0) continue;
|
||||
// Abzugskörper sind kein Material (sie wirken über `voids3d.ts`).
|
||||
if (solid.operation === "subtract") continue;
|
||||
if (hiddenCodes?.has(solid.categoryCode)) continue;
|
||||
const signature = extrudedSolidSignature(solid);
|
||||
let entry = truckMeshCache.get(solid.id);
|
||||
if (!entry || entry.signature !== signature) {
|
||||
// Die bisherige Mesh (falls vorhanden) WEITER anzeigen, bis die neue
|
||||
// Extrusion fertig geladen ist — sonst verschwindet der Körper kurz,
|
||||
// während der Nutzer Höhe/Verjüngung im Attribute-Panel tippt (jeder
|
||||
// Tastendruck feuert onChange → neue Signatur).
|
||||
const staleMesh = entry?.mesh ?? null;
|
||||
entry = { signature, mesh: staleMesh };
|
||||
truckMeshCache.set(solid.id, entry);
|
||||
let baseZ = 0;
|
||||
try {
|
||||
baseZ = getFloor(project, solid.levelId).baseElevation ?? 0;
|
||||
} catch {
|
||||
// Geschoss nicht (mehr) auflösbar: bei UK 0 extrudieren (Fallback).
|
||||
}
|
||||
baseZ += solid.baseOffset ?? 0;
|
||||
// Kreis-Profil: echte runde truck-Extrusion (extrudeCircle) statt der
|
||||
// 48-Eck-Tessellierung in `points` — glattes Zylinder-Mesh.
|
||||
const taper = solid.taper ?? 0;
|
||||
// B-Rep-Pfad (Grundkörper, Eckenradius): die Spezifikation trägt die UK (baseZ) selbst.
|
||||
const brepSpec = needsBrepPath(solid) ? extrudedSolidSpec(solid, baseZ - (solid.baseOffset ?? 0)) : null;
|
||||
const extrusion = brepSpec
|
||||
? buildSolidMesh(brepSpec, 0.005)
|
||||
: solid.circle
|
||||
? extrudeCircle(solid.circle.center.x, solid.circle.center.y, solid.circle.r, solid.height, taper)
|
||||
: extrudePolygon(solid.points.flatMap((p) => [p.x, p.y]), solid.height, taper);
|
||||
extrusion
|
||||
.then((mesh) => {
|
||||
// Prisma-Pfad: truck extrudiert ab z=0 — auf die Geschoss-UK anheben.
|
||||
const positions =
|
||||
brepSpec || baseZ === 0
|
||||
? mesh.positions
|
||||
: mesh.positions.map((v, i) => (i % 3 === 2 ? v + baseZ : v));
|
||||
const cur = truckMeshCache.get(solid.id);
|
||||
if (!cur || cur.signature !== signature) return; // inzwischen veraltet
|
||||
cur.mesh = { positions, indices: mesh.indices, kind: "extrusion", color: EXTRUSION_RGB };
|
||||
window.dispatchEvent(new Event(TRUCK_MESH_READY_EVENT));
|
||||
})
|
||||
.catch((e) => console.warn("truck-Extrusion fehlgeschlagen:", e));
|
||||
}
|
||||
if (!entry.mesh) continue;
|
||||
const dz = floorOffsets?.[solid.levelId] ?? 0;
|
||||
out.push(dz === 0 ? entry.mesh : { ...entry.mesh, positions: entry.mesh.positions.map((v, i) => (i % 3 === 2 ? v + dz : v)) });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* [137] Dreiecke des geladenen truck-Netzes eines freien Körpers in WORLD-Koordinaten (x, Höhe, y — wie
|
||||
* render3d `Extrusion`), um `dz` (Explosion) angehoben; `null`, solange das Netz nicht geladen ist.
|
||||
*/
|
||||
export function truckSolidPickTris(solidId: string, dz = 0): [Vec3, Vec3, Vec3][] | null {
|
||||
const mesh = truckMeshCache.get(solidId)?.mesh;
|
||||
if (!mesh || mesh.indices.length < 3) return null;
|
||||
const pos = mesh.positions;
|
||||
const n = pos.length / 3;
|
||||
const at = (i: number): Vec3 => [pos[i * 3], pos[i * 3 + 2] + dz, pos[i * 3 + 1]];
|
||||
const tris: [Vec3, Vec3, Vec3][] = [];
|
||||
for (let k = 0; k + 2 < mesh.indices.length; k += 3) {
|
||||
const [a, b, c] = [mesh.indices[k], mesh.indices[k + 1], mesh.indices[k + 2]];
|
||||
if (a < n && b < n && c < n) tris.push([at(a), at(b), at(c)]);
|
||||
}
|
||||
return tris.length ? tris : null;
|
||||
}
|
||||
|
||||
/** Nur für Tests: ein truck-Netz für einen Körper in den Cache legen. */
|
||||
export function __setTruckMeshForTest(solidId: string, mesh: RMesh | null): void {
|
||||
if (mesh) truckMeshCache.set(solidId, { signature: "test", mesh });
|
||||
else truckMeshCache.delete(solidId);
|
||||
}
|
||||
@@ -1,99 +1,31 @@
|
||||
// Abzugskörper im 3D: jede Wandschicht und Decke, die ein Abzugskörper durchdringt, bestimmt der
|
||||
// Kern samt Spezifikation (`solid_specs.rs`, Abfrage `model3dParts` mit `voids`); hier wird sie
|
||||
// über truck als Boolean-Differenz gebaut (B-Rep, bei bündigen Flächen automatisch Mesh-CSG) und
|
||||
// statt des Prismas als Mesh gezeigt.
|
||||
//
|
||||
// Wie die Extrusionen (`extrusions.ts`) asynchron mit modulweitem Cache: solange das Ergebnis
|
||||
// lädt, bleibt das ungeschnittene Prisma stehen; ist es fertig, feuert
|
||||
// `TRUCK_MESH_READY_EVENT` und der Viewer pusht das Modell neu.
|
||||
// Abzugskörper im 3D ([115]): jede Wandschicht und Decke, die ein Abzugskörper durchdringt, bestimmt der Kern
|
||||
// und baut ihr Netz „Bauteil − Körper" selbst (Manifold, `solid_specs::void_meshes`, Abfrage `model3dParts` mit
|
||||
// `voids`). Hier wird das Bauteil nur noch durch sein Netz ersetzt — synchron, ohne truck.
|
||||
|
||||
import { buildSolidMesh } from "../../engine/truckSolid";
|
||||
import type { SolidSpec } from "../../engine/truckSolid";
|
||||
import { TRUCK_MESH_READY_EVENT } from "./extrusions";
|
||||
import type { RMesh, RModel3d, RSlab, RWall } from "./shared";
|
||||
|
||||
/** Vom Kern getroffene Bauteile: (Index in `walls` bzw. `slabs`, Bauteil − Körper). */
|
||||
export interface VoidCuts {
|
||||
walls: Array<[number, SolidSpec]>;
|
||||
slabs: Array<[number, SolidSpec]>;
|
||||
/** Vom Kern geschnittene Bauteile: (Index in `walls` bzw. `slabs`, Inhalts-Schlüssel, Netz). */
|
||||
export interface VoidMeshes {
|
||||
walls: Array<[number, string, RMesh]>;
|
||||
slabs: Array<[number, string, RMesh]>;
|
||||
}
|
||||
|
||||
interface Entry {
|
||||
signature: string;
|
||||
/** null = lädt noch; "failed" = Boolean scheiterte (Prisma bleibt). */
|
||||
mesh: RMesh | null | "failed";
|
||||
}
|
||||
const cache = new Map<string, Entry>();
|
||||
|
||||
function request(key: string, signature: string, spec: SolidSpec, make: (m: { positions: number[]; indices: number[] }) => RMesh): Entry {
|
||||
let e = cache.get(key);
|
||||
if (e && e.signature === signature) return e;
|
||||
const entry: Entry = { signature, mesh: null };
|
||||
cache.set(key, entry);
|
||||
buildSolidMesh(spec, 0.005)
|
||||
.then((m) => {
|
||||
const cur = cache.get(key);
|
||||
if (cur !== entry) return;
|
||||
entry.mesh = make(m);
|
||||
window.dispatchEvent(new Event(TRUCK_MESH_READY_EVENT));
|
||||
})
|
||||
.catch((err) => {
|
||||
entry.mesh = "failed";
|
||||
console.warn("Abzugskörper-Boolean fehlgeschlagen:", err);
|
||||
});
|
||||
e = entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ersetzt in `model` die von Abzugskörpern getroffenen Wandschichten/Decken durch ihre
|
||||
* Boolean-Meshes (sobald geladen). Ohne `window` (Tests/Node) bleibt das Modell unverändert.
|
||||
*/
|
||||
export function applyVoids3d(model: RModel3d, cuts: VoidCuts): void {
|
||||
if (typeof window === "undefined") return;
|
||||
const live = new Set<string>();
|
||||
const wallCut = new Map(cuts.walls);
|
||||
/** Ersetzt in `model` die geschnittenen Wandschichten/Decken durch ihre Netze (Netze hinten an `meshes`). */
|
||||
export function applyVoidMeshes(model: RModel3d, cuts: VoidMeshes): void {
|
||||
const wallCut = new Map(cuts.walls.map(([i, , m]) => [i, m]));
|
||||
const walls: RWall[] = [];
|
||||
model.walls.forEach((w, i) => {
|
||||
const spec = wallCut.get(i);
|
||||
if (!spec) {
|
||||
walls.push(w);
|
||||
return;
|
||||
}
|
||||
const key = `w:${w.wallId}:${i}`;
|
||||
live.add(key);
|
||||
const e = request(key, JSON.stringify(spec), spec, (m) => ({
|
||||
positions: m.positions,
|
||||
indices: m.indices,
|
||||
kind: "extrusion",
|
||||
color: w.color,
|
||||
...(w.materialIndex !== undefined ? { materialIndex: w.materialIndex } : {}),
|
||||
}));
|
||||
if (e.mesh && e.mesh !== "failed") model.meshes.push(e.mesh);
|
||||
const m = wallCut.get(i);
|
||||
if (m) model.meshes.push(m);
|
||||
else walls.push(w);
|
||||
});
|
||||
model.walls = walls;
|
||||
|
||||
const slabCut = new Map(cuts.slabs);
|
||||
const slabCut = new Map(cuts.slabs.map(([i, , m]) => [i, m]));
|
||||
const slabs: RSlab[] = [];
|
||||
model.slabs.forEach((s, i) => {
|
||||
const spec = slabCut.get(i);
|
||||
if (!spec) {
|
||||
slabs.push(s);
|
||||
return;
|
||||
}
|
||||
const key = `s:${s.ceilingId}:${i}`;
|
||||
live.add(key);
|
||||
const e = request(key, JSON.stringify(spec), spec, (m) => ({
|
||||
positions: m.positions,
|
||||
indices: m.indices,
|
||||
kind: "extrusion",
|
||||
color: s.color,
|
||||
}));
|
||||
if (e.mesh && e.mesh !== "failed") model.meshes.push(e.mesh);
|
||||
const m = slabCut.get(i);
|
||||
if (m) model.meshes.push(m);
|
||||
else slabs.push(s);
|
||||
});
|
||||
model.slabs = slabs;
|
||||
|
||||
for (const k of cache.keys()) if (!live.has(k)) cache.delete(k);
|
||||
}
|
||||
Reference in new issue
Block a user