[204] Schnitt: gewachsenes Terrain nicht durch die Gebäuderäume; Grundriss öffnet aufs Gebäude eingepasst (Bauteil-Ausmass im Plan-Puffer)
This commit is contained in:
13 files changed
+310
-36
No files matched your search
@@ -61,6 +61,11 @@ export interface PlanImage {
|
||||
export interface Plan {
|
||||
primitives: Primitive[];
|
||||
bounds: { minX: number; minY: number; maxX: number; maxY: number };
|
||||
/**
|
||||
* [204] Ausmass nur der Bauteile (Wände, Decken, Dächer, Räume, Treppen) ohne Kontext/Kataster, Gelände,
|
||||
* Raster, Zeichnungen und Schnittmarken: Ziel des Einpassens beim Öffnen. Fehlt ohne Bauteile (dann `bounds`).
|
||||
*/
|
||||
houseBounds?: { minX: number; minY: number; maxX: number; maxY: number };
|
||||
/** Hintergrund-Rasterbilder (Luftbild) — nur für die interaktive Ansicht. */
|
||||
backgroundImages?: PlanImage[];
|
||||
/**
|
||||
@@ -304,7 +309,8 @@ export function generatePlan(
|
||||
}));
|
||||
// Ausmass samt Schatten, Baurecht und Kontext (immer gesetzt, ohne Punkte 0,0–1,1).
|
||||
const [minX, minY, maxX, maxY] = dom.buf.bounds ?? [0, 0, 1, 1];
|
||||
return lazyPlan({ bounds: { minX, minY, maxX, maxY }, backgroundImages, lineEnds: lineEndsCode(project), ...(underlay.length ? { underlay } : {}) }, pieces);
|
||||
const h = dom.buf.house;
|
||||
return lazyPlan({ bounds: { minX, minY, maxX, maxY }, ...(h ? { houseBounds: { minX: h[0], minY: h[1], maxX: h[2], maxY: h[3] } } : {}), backgroundImages, lineEnds: lineEndsCode(project), ...(underlay.length ? { underlay } : {}) }, pieces);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,6 +378,14 @@ export function generateVisibleLevelsPlan(
|
||||
bounds.maxX = Math.max(bounds.maxX, b.maxX);
|
||||
bounds.maxY = Math.max(bounds.maxY, b.maxY);
|
||||
};
|
||||
// [204] Bauteil-Ausmass aller gezeigten Geschosse (aktives und gedimmte Pausfolien).
|
||||
let house: Plan["bounds"] | undefined;
|
||||
const extendHouse = (b: Plan["bounds"] | undefined) => {
|
||||
if (!b) return;
|
||||
house = house
|
||||
? { minX: Math.min(house.minX, b.minX), minY: Math.min(house.minY, b.minY), maxX: Math.max(house.maxX, b.maxX), maxY: Math.max(house.maxY, b.maxY) }
|
||||
: { ...b };
|
||||
};
|
||||
|
||||
// Andere sichtbare Ebenen ZUERST (unten als Referenz), die aktive zuletzt
|
||||
// (obenauf) — wie `buildBuilding` in meshBuilders.ts für die 3D-Szene.
|
||||
@@ -405,6 +419,7 @@ export function generateVisibleLevelsPlan(
|
||||
// jede leere Nachbar-Ebene den Ausschnitt bis zum Ursprung (bei Landes-
|
||||
// koordinaten ~2,7 Mio. m daneben → "Einpassen" zeigte nichts).
|
||||
if (n > 0 || p.underlay) extend(p.bounds);
|
||||
extendHouse(p.houseBounds);
|
||||
}
|
||||
|
||||
const activePlan = generatePlan(
|
||||
@@ -425,10 +440,12 @@ export function generateVisibleLevelsPlan(
|
||||
for (const g of activePlan.underlay ?? []) underlay.push(g);
|
||||
// Aktive Ebene leer UND keine Nachbar-Ebene mit Inhalt → Platzhalter-Ausmass.
|
||||
if (activeCount > 0 || activePlan.underlay || bounds.minX === Infinity) extend(activePlan.bounds);
|
||||
extendHouse(activePlan.houseBounds);
|
||||
|
||||
return lazyPlan(
|
||||
{
|
||||
bounds,
|
||||
...(house ? { houseBounds: house } : {}),
|
||||
backgroundImages: activePlan.backgroundImages,
|
||||
lineEnds: lineEndsCode(project),
|
||||
...(greyedRanges.length ? { greyedRanges } : {}),
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// [204] Einpassen beim Öffnen: das Plan-Ausmass hat zusätzlich das Ausmass nur der Bauteile (ohne Kataster/Gelände).
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { emptyProject } from "../model/sampleProject";
|
||||
import { collectVisibleCodes } from "../model/layers";
|
||||
import { generatePlan } from "./generatePlan";
|
||||
|
||||
const area = (b: { minX: number; minY: number; maxX: number; maxY: number }) => (b.maxX - b.minX) * (b.maxY - b.minY);
|
||||
|
||||
describe("Bauteil-Ausmass des Grundrisses [204]", () => {
|
||||
const p = buildComplexSampleProject();
|
||||
const codes = collectVisibleCodes(p.layers);
|
||||
|
||||
it("Musterhaus komplex: Gebäude deutlich kleiner als das ganze Ausmass mit Kontext", () => {
|
||||
const plan = generatePlan(p, "eg", codes, undefined, "mittel", false, true, true, 100);
|
||||
const h = plan.houseBounds;
|
||||
expect(h).toBeDefined();
|
||||
const b = plan.bounds;
|
||||
// Das Gebäude liegt im Ausmass …
|
||||
expect(h!.minX).toBeGreaterThanOrEqual(b.minX - 1e-9);
|
||||
expect(h!.maxX).toBeLessThanOrEqual(b.maxX + 1e-9);
|
||||
expect(h!.minY).toBeGreaterThanOrEqual(b.minY - 1e-9);
|
||||
expect(h!.maxY).toBeLessThanOrEqual(b.maxY + 1e-9);
|
||||
// … und das Kataster/Gelände macht das Ausmass deutlich grösser.
|
||||
expect(area(h!)).toBeLessThan(area(b) * 0.5);
|
||||
// Haus ~ 10 × 12 m, nicht das Grundstück.
|
||||
expect(h!.maxX - h!.minX).toBeLessThan(40);
|
||||
});
|
||||
|
||||
it("ohne Bauteile: kein Bauteil-Ausmass (Aufrufer fällt auf das Ausmass zurück)", () => {
|
||||
const plan = generatePlan(emptyProject, "eg", new Set(), undefined, "mittel", false, true, true, 100);
|
||||
expect(plan.houseBounds).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -97,7 +97,7 @@ function canon(v: unknown): string {
|
||||
function recFlags(bytes: Uint8Array): number[] {
|
||||
const f = new Float64Array(bytes.buffer, bytes.byteOffset, bytes.byteLength >> 3);
|
||||
const [nStrings, , nHatchWords, nGroups, nPrims] = [f[3], f[4], f[5], f[6], f[7]];
|
||||
const offAt = 16 + 2 * nStrings + nHatchWords + 2 * nGroups;
|
||||
const offAt = 20 + 2 * nStrings + nHatchWords + 2 * nGroups;
|
||||
const recAt = offAt + nPrims * (f[2] & 1 ? 2 : 1);
|
||||
return Array.from({ length: nPrims }, (_, i) => f[recAt + f[offAt + i] + 1]);
|
||||
}
|
||||
@@ -118,15 +118,17 @@ describe("Plan-Puffer v2", () => {
|
||||
|
||||
it("Hin und zurück: alle Typen gemischt, mit Gruppen und Ausmass", () => {
|
||||
const prims = Object.values(PRIMS);
|
||||
const buf = encodePlanBuf(prims, { groups: [[0, 2], [2, prims.length]], bounds: [-1, -2, 3, 4] });
|
||||
const buf = encodePlanBuf(prims, { groups: [[0, 2], [2, prims.length]], bounds: [-1, -2, 3, 4], house: [0, 0, 1, 2] });
|
||||
const d = decodePlanBuf(buf);
|
||||
expect(canon(d.prims)).toBe(canon(prims));
|
||||
expect(d.groups).toEqual([[0, 2], [2, prims.length]]);
|
||||
expect(d.bounds).toEqual([-1, -2, 3, 4]);
|
||||
expect(d.house).toEqual([0, 0, 1, 2]);
|
||||
expect(d.hashes).toBeNull();
|
||||
const back = decodePlanBuf(core().plan_buf_recode(buf));
|
||||
expect(canon(back.prims)).toBe(canon(prims));
|
||||
expect(back.groups).toEqual(d.groups);
|
||||
expect(back.house).toEqual([0, 0, 1, 2]);
|
||||
// Schraffuren werden einmal gelesen und geteilt.
|
||||
expect((d.prims[0] as { hatch: unknown }).hatch).toBe((d.prims[prims.length - 1] as { hatch: unknown }).hatch);
|
||||
});
|
||||
@@ -216,7 +218,7 @@ describe("Plan-Puffer v2", () => {
|
||||
const h = encodeHatch(hatch);
|
||||
const buf = encodePlanBuf([PRIMS.polygon]);
|
||||
const f = new Float64Array(buf.buffer, 0, buf.byteLength >> 3);
|
||||
const at = 16 + 2 * f[3] + 1; // nach dem JSON-String-Index des ersten Eintrags
|
||||
const at = 20 + 2 * f[3] + 1; // nach dem JSON-String-Index des ersten Eintrags
|
||||
const inPlan = f.slice(at, at + h.length);
|
||||
// Im Plan-Puffer steht der Farb-String statt −1.
|
||||
expect(inPlan[5]).toBeGreaterThanOrEqual(0);
|
||||
|
||||
+15
-4
@@ -8,8 +8,9 @@
|
||||
*
|
||||
* ```text
|
||||
* Bytes: f64-Teil, dann UTF-16-Einheiten aller Texte
|
||||
* Kopf (16) [MAGIC "PLB2", VERSION 2, flags (1 Hashes, 2 Ausmass), nStrings, nHatches, nHatchWords,
|
||||
* nGroups, nPrims, nRecWords, nPool, nUnits, 0, minX, minY, maxX, maxY]
|
||||
* Kopf (20) [MAGIC "PLB2", VERSION 2, flags (1 Hashes, 2 Ausmass, 4 Bauteil-Ausmass), nStrings, nHatches,
|
||||
* nHatchWords, nGroups, nPrims, nRecWords, nPool, nUnits, 0, minX, minY, maxX, maxY,
|
||||
* Bauteile minX, minY, maxX, maxY]
|
||||
* Strings nStrings × [unitOff, unitLen]
|
||||
* Schraffur nHatches × [jsonStr, Hatch] (Hatch wie encodeHatch, Farbe = String-Index)
|
||||
* Gruppen nGroups × [start, end)
|
||||
@@ -31,7 +32,7 @@ export const PLAN_BUF_MAGIC = 0x504c4232;
|
||||
export const PLAN_BUF_VERSION = 2;
|
||||
/** Fehlerpuffer einer Kern-Abfrage ("PLBe"): `[ERR_MAGIC, nUnits]` + Meldung (UTF-16). */
|
||||
export const PLAN_BUF_ERR_MAGIC = 0x504c4265;
|
||||
const HEAD = 16;
|
||||
const HEAD = 20;
|
||||
|
||||
const F_GREYED_SET = 1;
|
||||
const F_GREYED = 2;
|
||||
@@ -201,6 +202,8 @@ export interface EncodeOptions {
|
||||
/** Gruppen `[start, end)` in den Kopf schreiben. */
|
||||
groups?: ReadonlyArray<readonly [number, number]>;
|
||||
bounds?: readonly [number, number, number, number];
|
||||
/** [204] Ausmass der Bauteile (Wände, Decken, Dächer, Räume, Treppen) — fürs Einpassen beim Öffnen. */
|
||||
house?: readonly [number, number, number, number];
|
||||
}
|
||||
|
||||
/** Primitive → Plan-Puffer v2 (Format s. Dateikopf). */
|
||||
@@ -418,10 +421,11 @@ export function encodePlanBuf(prims: readonly Primitive[], opts: EncodeOptions =
|
||||
const out = new ArrayBuffer(nF64 * 8 + units * 2);
|
||||
const f = new Float64Array(out, 0, nF64);
|
||||
const bounds = opts.bounds;
|
||||
const house = opts.house;
|
||||
f.set([
|
||||
PLAN_BUF_MAGIC,
|
||||
PLAN_BUF_VERSION,
|
||||
bounds ? 2 : 0,
|
||||
(bounds ? 2 : 0) | (house ? 4 : 0),
|
||||
nStrings,
|
||||
hatchIdx.size,
|
||||
hatchW.length,
|
||||
@@ -435,6 +439,10 @@ export function encodePlanBuf(prims: readonly Primitive[], opts: EncodeOptions =
|
||||
bounds ? bounds[1] : 0,
|
||||
bounds ? bounds[2] : 0,
|
||||
bounds ? bounds[3] : 0,
|
||||
house ? house[0] : 0,
|
||||
house ? house[1] : 0,
|
||||
house ? house[2] : 0,
|
||||
house ? house[3] : 0,
|
||||
]);
|
||||
let k = HEAD;
|
||||
f.set(strTab.buf.subarray(0, strTab.length), k);
|
||||
@@ -475,6 +483,8 @@ export interface DecodedPlanBuf {
|
||||
tag(i: number): number;
|
||||
groups: Array<[number, number]>;
|
||||
bounds?: [number, number, number, number];
|
||||
/** [204] Ausmass der Bauteile (ohne Zeichnungen/Kontext); fehlt ohne Bauteile. */
|
||||
house?: [number, number, number, number];
|
||||
/** Inhalts-Hash je Primitiv (vom Kern; Schlüssel des GPU-Chunk-Caches) oder null. */
|
||||
hashes: Float64Array | null;
|
||||
/** Nummer des im Kern gehaltenen Puffers (0 = keiner), s. `compilePlanBufRange`. */
|
||||
@@ -718,6 +728,7 @@ export function decodePlanBuf(input: Uint8Array): DecodedPlanBuf {
|
||||
tag: (i: number): number => f[recAt + f[offAt + i]],
|
||||
groups,
|
||||
bounds: flags & 2 ? [hd[12], hd[13], hd[14], hd[15]] : undefined,
|
||||
house: flags & 4 ? [hd[16], hd[17], hd[18], hd[19]] : undefined,
|
||||
hashes: hashes ? new Float64Array(bytes.buffer, bytes.byteOffset + hashAt * 8, nPrims) : null,
|
||||
hold: 0,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user