[K3a] Kontext-Mesh, Schnittfuehrung und Linienenden im Grundriss in Rust (plan_misc.rs)
This commit is contained in:
1 parent
c134d32fcc
commit
125422afec
8 files changed
+408
-245
No files matched your search
@@ -1,9 +1,11 @@
|
||||
// Kontext-Domäne des Grundriss-Generators: zeichnet `project.context`
|
||||
// (Höhenlinien, importierte Gebäude/Terrain-Meshes) als dezente Referenz-
|
||||
// Konturen — für Meshes der Grundriss-Fussabdruck nahe der Objekt-Unterkante,
|
||||
// nicht das volle Drahtgitter.
|
||||
// nicht das volle Drahtgitter. Fussabdruck (Sockelkanten, entdoppelt) und Rahmen berechnet der
|
||||
// Rust-Kern (`src-tauri/core/src/plan_misc.rs`, [K3a]).
|
||||
|
||||
import type { Project } from "../../model/types";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import { NO_HATCH, SHOW_ALL, type CategoryDisplayResolver, type Primitive } from "./shared";
|
||||
|
||||
/** Dezente Plan-Farbe der Kontext-Konturen (gedämpftes Grau). */
|
||||
@@ -11,11 +13,6 @@ const CONTEXT_LINE_COLOR = "#9aa3ad";
|
||||
/** Strichstärke der Kontext-Konturen (mm Papier, dünn). */
|
||||
const CONTEXT_LINE_MM = 0.1;
|
||||
|
||||
/** Höhen-Toleranz (Meter): Dreieckskanten, deren beide Endpunkte höchstens so
|
||||
* weit über der Objekt-Unterkante (minZ) liegen, gelten als „Sockelkante" und
|
||||
* bilden den Grundriss-Fussabdruck eines importierten Gebäudes. */
|
||||
const FOOTPRINT_Z_TOL = 0.6;
|
||||
|
||||
/**
|
||||
* Zeichnet die Kontext-Schicht `project.context` in den Grundriss:
|
||||
* • ContourSet (Höhenlinien) → dünne Referenz-Linien (Z ignoriert).
|
||||
@@ -77,68 +74,41 @@ export function addContextContours(
|
||||
|
||||
/**
|
||||
* Zeichnet den Grundriss-Fussabdruck eines Meshes: Dreieckskanten nahe der
|
||||
* Unterkante (minZ + {@link FOOTPRINT_Z_TOL}), auf XY projiziert, über
|
||||
* quantisierte Endpunkt-Schlüssel entdoppelt. `positions` = flaches [x,y,z…]-
|
||||
* Array (Modell-Meter, z = Höhe), `indices` = Dreiecks-Indizes.
|
||||
* Unterkante (minZ + 0.6 m), auf XY projiziert, über 1-cm-quantisierte Endpunkte
|
||||
* entdoppelt. `positions` = flaches [x,y,z…]-Array (Modell-Meter, z = Höhe),
|
||||
* `indices` = Dreiecks-Indizes.
|
||||
*/
|
||||
function addMeshFootprint(out: Primitive[], positions: number[], indices: number[]): void {
|
||||
const vcount = Math.floor(positions.length / 3);
|
||||
if (vcount < 3 || indices.length < 3) return;
|
||||
let minZ = Infinity;
|
||||
for (let i = 2; i < positions.length; i += 3) if (positions[i] < minZ) minZ = positions[i];
|
||||
if (!Number.isFinite(minZ)) return;
|
||||
const zLimit = minZ + FOOTPRINT_Z_TOL;
|
||||
const q = (v: number) => Math.round(v * 100); // 1-cm-Quantisierung (Entdopplung)
|
||||
const seen = new Set<string>();
|
||||
const edge = (ia: number, ib: number) => {
|
||||
if (ia >= vcount || ib >= vcount) return;
|
||||
const za = positions[ia * 3 + 2];
|
||||
const zb = positions[ib * 3 + 2];
|
||||
if (za > zLimit || zb > zLimit) return; // nur Sockelkanten
|
||||
const ax = positions[ia * 3], ay = positions[ia * 3 + 1];
|
||||
const bx = positions[ib * 3], by = positions[ib * 3 + 1];
|
||||
// Kanten-Schlüssel richtungsunabhängig (kleinerer Endpunkt zuerst).
|
||||
const ka = `${q(ax)},${q(ay)}`;
|
||||
const kb = `${q(bx)},${q(by)}`;
|
||||
if (ka === kb) return;
|
||||
const key = ka < kb ? `${ka}|${kb}` : `${kb}|${ka}`;
|
||||
if (seen.has(key)) return;
|
||||
seen.add(key);
|
||||
const f = core().context_footprint_flat(Float64Array.from(positions), Float64Array.from(indices));
|
||||
for (let i = 0; i < f[0]; i++) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: { x: ax, y: ay },
|
||||
b: { x: bx, y: by },
|
||||
a: { x: f[1 + 4 * i], y: f[2 + 4 * i] },
|
||||
b: { x: f[3 + 4 * i], y: f[4 + 4 * i] },
|
||||
cls: "context-line",
|
||||
weightMm: CONTEXT_LINE_MM,
|
||||
color: CONTEXT_LINE_COLOR,
|
||||
});
|
||||
};
|
||||
for (let i = 0; i + 2 < indices.length; i += 3) {
|
||||
const a = indices[i], b = indices[i + 1], c = indices[i + 2];
|
||||
edge(a, b);
|
||||
edge(b, c);
|
||||
edge(c, a);
|
||||
}
|
||||
}
|
||||
|
||||
/** Grundriss-Rahmen eines Meshes (nur x/y) als vier Eckpunkte, oder `null` ohne Punkte. */
|
||||
function meshBboxCorners(positions: number[]): { x: number; y: number }[] | null {
|
||||
const b = core().context_bbox_flat(Float64Array.from(positions));
|
||||
if (b.length === 0) return null;
|
||||
return [
|
||||
{ x: b[0], y: b[1] },
|
||||
{ x: b[2], y: b[1] },
|
||||
{ x: b[2], y: b[3] },
|
||||
{ x: b[0], y: b[3] },
|
||||
];
|
||||
}
|
||||
|
||||
/** Zeichnet nur den achsenparallelen 2D-Umriss (Bounding-Box) eines Meshes —
|
||||
* für Terrain, dessen volles TIN-Gitter im Plan zu dicht wäre. */
|
||||
function addMeshBboxOutline(out: Primitive[], positions: number[]): void {
|
||||
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
||||
for (let i = 0; i + 2 < positions.length; i += 3) {
|
||||
const x = positions[i], y = positions[i + 1];
|
||||
if (x < minX) minX = x;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (y > maxY) maxY = y;
|
||||
}
|
||||
if (!Number.isFinite(minX)) return;
|
||||
const corners = [
|
||||
{ x: minX, y: minY },
|
||||
{ x: maxX, y: minY },
|
||||
{ x: maxX, y: maxY },
|
||||
{ x: minX, y: maxY },
|
||||
];
|
||||
const corners = meshBboxCorners(positions);
|
||||
if (!corners) return;
|
||||
for (let i = 0; i < 4; i++) {
|
||||
out.push({
|
||||
kind: "line",
|
||||
@@ -157,28 +127,14 @@ function addMeshBboxOutline(out: Primitive[], positions: number[]): void {
|
||||
* trägt die `ContextObject.id` (analog `sectionLineId`, s. dort). Macht das
|
||||
* Objekt IRGENDWO innerhalb seiner Grundfläche anklickbar (nicht nur exakt auf
|
||||
* der dünnen Umriss-/Fussabdrucklinie) — wie bei Wänden, deren Poché-Fläche
|
||||
* ebenfalls als Ganzes klickbar ist (Nutzer-Wunsch: „eigene Elemente wie Wände").
|
||||
* `positions` = flaches [x,y,z…]-Array (Modell-Meter); die Bbox nutzt NUR x/y,
|
||||
* unabhängig von der Höhe.
|
||||
* ebenfalls als Ganzes klickbar ist.
|
||||
*/
|
||||
function addContextPickRegion(out: Primitive[], positions: number[], id: string): void {
|
||||
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
||||
for (let i = 0; i + 2 < positions.length; i += 3) {
|
||||
const x = positions[i], y = positions[i + 1];
|
||||
if (x < minX) minX = x;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (y > maxY) maxY = y;
|
||||
}
|
||||
if (!Number.isFinite(minX)) return;
|
||||
const pts = meshBboxCorners(positions);
|
||||
if (!pts) return;
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [
|
||||
{ x: minX, y: minY },
|
||||
{ x: maxX, y: minY },
|
||||
{ x: maxX, y: maxY },
|
||||
{ x: minX, y: maxY },
|
||||
],
|
||||
pts,
|
||||
fill: "none",
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
|
||||
@@ -9,18 +9,18 @@
|
||||
// Die Grösse kommt in PAPIER-MILLIMETERN herein und wird mit dem Massstab des
|
||||
// Plans in Modellmass umgerechnet (gleiche Linie wie die Bemassung, s.
|
||||
// `model/dimension.ts`): eine 3-mm-Pfeilspitze soll auf dem Papier 3 mm sein,
|
||||
// egal ob der Plan 1:50 oder 1:200 steht.
|
||||
// egal ob der Plan 1:50 oder 1:200 steht. Die Geometrie berechnet der Rust-Kern (`plan_misc.rs`, [K3a]).
|
||||
|
||||
import type { EndMark, Vec2 } from "../../model/types";
|
||||
import { mmToModel } from "../../model/dimension";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import type { Primitive } from "./shared";
|
||||
import { NO_HATCH } from "./shared";
|
||||
|
||||
/** Default-Grösse der Linienenden in Papier-Millimetern. */
|
||||
export const END_MARK_DEFAULT_SIZE_MM = 3;
|
||||
|
||||
/** Öffnungsverhältnis der Pfeilspitze (halbe Breite ÷ Länge) — schlanke Spitze. */
|
||||
const ARROW_ASPECT = 0.32;
|
||||
/** Kodierung der Linienenden im Kern (`plan_misc.rs`). */
|
||||
const MARK_CODE: Record<Exclude<EndMark, "none">, number> = { arrow: 1, arrowOpen: 2, dot: 3, tick: 4, square: 5 };
|
||||
|
||||
export interface EndMarkStyle {
|
||||
weightMm: number;
|
||||
@@ -49,82 +49,35 @@ export function addEndMark(
|
||||
style: EndMarkStyle,
|
||||
): number {
|
||||
if (!mark || mark === "none") return 0;
|
||||
const len = Math.hypot(dir.x, dir.y);
|
||||
if (len < 1e-9) return 0;
|
||||
const size = mmToModel(sizeMm, scaleDenominator);
|
||||
const ux = dir.x / len;
|
||||
const uy = dir.y / len;
|
||||
const nx = -uy;
|
||||
const ny = ux;
|
||||
const f = core().end_mark_flat(at.x, at.y, dir.x, dir.y, MARK_CODE[mark], sizeMm, scaleDenominator);
|
||||
if (f.length === 0) return 0;
|
||||
const { weightMm, color, greyed, drawingId } = style;
|
||||
|
||||
/** Fusspunkt der Spitze (size zurück entlang der Linie). */
|
||||
const base: Vec2 = { x: at.x - ux * size, y: at.y - uy * size };
|
||||
const half = size * ARROW_ASPECT;
|
||||
const wingA: Vec2 = { x: base.x + nx * half, y: base.y + ny * half };
|
||||
const wingB: Vec2 = { x: base.x - nx * half, y: base.y - ny * half };
|
||||
const line = (a: Vec2, b: Vec2) =>
|
||||
out.push({ kind: "line", a, b, cls: "draw2d", weightMm, dash: null, color, greyed, drawingId });
|
||||
|
||||
switch (mark) {
|
||||
case "arrow":
|
||||
let i = 2;
|
||||
for (let k = 0; k < f[1]; k++) {
|
||||
if (f[i] === 1) {
|
||||
const count = f[i + 1];
|
||||
const pts = Array.from({ length: count }, (_, j) => ({ x: f[i + 2 + 2 * j], y: f[i + 3 + 2 * j] }));
|
||||
out.push({ kind: "polygon", pts, fill: color, stroke: color, strokeWidthMm: weightMm, hatch: NO_HATCH, greyed, drawingId });
|
||||
i += 2 + 2 * count;
|
||||
} else if (f[i] === 2) {
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [at, wingA, wingB],
|
||||
fill: color,
|
||||
stroke: color,
|
||||
strokeWidthMm: weightMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
drawingId,
|
||||
});
|
||||
// Die gefüllte Spitze überdeckt die Linie — dort darf sie enden.
|
||||
return size;
|
||||
case "arrowOpen":
|
||||
line(wingA, at);
|
||||
line(wingB, at);
|
||||
// Offene Spitze: die Linie läuft bis zum Punkt durch (sie ist Teil des Bildes).
|
||||
return 0;
|
||||
case "dot":
|
||||
out.push({
|
||||
kind: "drawingCircle",
|
||||
center: at,
|
||||
r: size * 0.25,
|
||||
fill: color,
|
||||
stroke: color,
|
||||
kind: "line",
|
||||
a: { x: f[i + 1], y: f[i + 2] },
|
||||
b: { x: f[i + 3], y: f[i + 4] },
|
||||
cls: "draw2d",
|
||||
weightMm,
|
||||
dash: null,
|
||||
color,
|
||||
greyed,
|
||||
drawingId,
|
||||
});
|
||||
return 0;
|
||||
case "tick": {
|
||||
// 45°-Schrägstrich, mittig auf dem Endpunkt (SIA-Massstrich-Anmutung).
|
||||
const tx = (ux + nx) / Math.SQRT2;
|
||||
const ty = (uy + ny) / Math.SQRT2;
|
||||
const h = size / 2;
|
||||
line({ x: at.x - tx * h, y: at.y - ty * h }, { x: at.x + tx * h, y: at.y + ty * h });
|
||||
return 0;
|
||||
}
|
||||
case "square": {
|
||||
const h = size * 0.3;
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [
|
||||
{ x: at.x + (ux + nx) * h, y: at.y + (uy + ny) * h },
|
||||
{ x: at.x + (ux - nx) * h, y: at.y + (uy - ny) * h },
|
||||
{ x: at.x + (-ux - nx) * h, y: at.y + (-uy - ny) * h },
|
||||
{ x: at.x + (-ux + nx) * h, y: at.y + (-uy + ny) * h },
|
||||
],
|
||||
fill: color,
|
||||
stroke: color,
|
||||
strokeWidthMm: weightMm,
|
||||
hatch: NO_HATCH,
|
||||
greyed,
|
||||
drawingId,
|
||||
});
|
||||
return 0;
|
||||
i += 5;
|
||||
} else {
|
||||
out.push({ kind: "drawingCircle", center: { x: f[i + 1], y: f[i + 2] }, r: f[i + 3], fill: color, stroke: color, weightMm, greyed, drawingId });
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
return f[0];
|
||||
}
|
||||
|
||||
/** Punkt `p` um `d` in Richtung `dir` (normiert) zurückgezogen — für die Linienverkürzung. */
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// Strichpunkt-Schnittlinie mit Endmarken + Label) — NICHT zu verwechseln mit
|
||||
// `generateSectionPlan()` (der Schnitt-ALS-Plan-Übersetzung, bleibt Orchestrator
|
||||
// in `../generatePlan.ts`): diese Domäne zeichnet nur das Führungssymbol EINER
|
||||
// Schnitt-/Ansichtsebene IM Grundriss.
|
||||
// Schnitt-/Ansichtsebene IM Grundriss. Die Geometrie berechnet der Rust-Kern (`plan_misc.rs`, [K3a]).
|
||||
|
||||
import { leftNormal, normalize, sub } from "../../model/geometry";
|
||||
import { core } from "../../engine/coreWasm";
|
||||
import type { Project } from "../../model/types";
|
||||
import { NO_HATCH, SHOW_ALL, type CategoryDisplayResolver, type Primitive } from "./shared";
|
||||
|
||||
@@ -26,10 +26,6 @@ const SECTION_LINE_MM = 0.18;
|
||||
const SECTION_LINE_MARK_MM = 0.5;
|
||||
/** Strichpunkt-Muster der Schnittlinie (lange Striche + Punkt, mm Papier). */
|
||||
const SECTION_LINE_DASH: number[] = [6, 1.5, 0.4, 1.5];
|
||||
/** Länge der Endmarken (Querstrich/Pfeil) in Modell-Metern. */
|
||||
const SECTION_MARK_LEN = 0.6;
|
||||
/** Halbe Breite des unsichtbaren Pick-Bands über der Linie (Modell-Meter). */
|
||||
const SECTION_PICK_HALF = 0.3;
|
||||
/** Schrifthöhe des Schnitt-Labels (Modell-Meter). */
|
||||
const SECTION_LABEL_H = 0.5;
|
||||
|
||||
@@ -72,100 +68,48 @@ export function addSectionLines(
|
||||
const line = level.linePoints;
|
||||
if (!line) continue;
|
||||
const [p0, p1] = line;
|
||||
const axis = sub(p1, p0);
|
||||
const len = Math.hypot(axis.x, axis.y);
|
||||
if (len < 1e-6) continue;
|
||||
const u = normalize(axis);
|
||||
const n = leftNormal(u); // (-uy, ux)
|
||||
const sign = level.directionSign ?? 1;
|
||||
const bn = { x: n.x * sign, y: n.y * sign }; // Blicknormale
|
||||
|
||||
// Hauptlinie (Strichpunkt-Haarlinie).
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: p0,
|
||||
b: p1,
|
||||
cls: "section-line",
|
||||
weightMm: SECTION_LINE_MM,
|
||||
dash: SECTION_LINE_DASH,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
|
||||
// Endmarken (Querstrich + Richtungspfeil + Label) an beiden Enden.
|
||||
const half = SECTION_MARK_LEN / 2;
|
||||
for (const end of [p0, p1]) {
|
||||
// Querstrich senkrecht zur Linie, mittig am Endpunkt.
|
||||
const t0 = { x: end.x - n.x * half, y: end.y - n.y * half };
|
||||
const t1 = { x: end.x + n.x * half, y: end.y + n.y * half };
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: t0,
|
||||
b: t1,
|
||||
cls: "section-line",
|
||||
weightMm: SECTION_LINE_MARK_MM,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
// Richtungspfeil: vom Querstrich-Ende auf der Blickseite entlang bn.
|
||||
const base = { x: end.x + bn.x * half, y: end.y + bn.y * half };
|
||||
const tip = { x: base.x + bn.x * SECTION_MARK_LEN, y: base.y + bn.y * SECTION_MARK_LEN };
|
||||
const wingBack = {
|
||||
x: tip.x - bn.x * SECTION_MARK_LEN * 0.4,
|
||||
y: tip.y - bn.y * SECTION_MARK_LEN * 0.4,
|
||||
};
|
||||
const w = SECTION_MARK_LEN * 0.25;
|
||||
out.push({ kind: "line", a: base, b: tip, cls: "section-line", weightMm: SECTION_LINE_MARK_MM, color: SECTION_LINE_INK, greyed });
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: tip,
|
||||
b: { x: wingBack.x + u.x * w, y: wingBack.y + u.y * w },
|
||||
cls: "section-line",
|
||||
weightMm: SECTION_LINE_MARK_MM,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: tip,
|
||||
b: { x: wingBack.x - u.x * w, y: wingBack.y - u.y * w },
|
||||
cls: "section-line",
|
||||
weightMm: SECTION_LINE_MARK_MM,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
// Label (Kurz-Tag) etwas hinter dem Pfeil, horizontal.
|
||||
const labelAt = {
|
||||
x: tip.x + bn.x * SECTION_MARK_LEN * 0.4 - SECTION_LABEL_H * 0.3,
|
||||
y: tip.y + bn.y * SECTION_MARK_LEN * 0.4 + SECTION_LABEL_H * 0.5,
|
||||
};
|
||||
out.push({
|
||||
kind: "drawingText",
|
||||
at: labelAt,
|
||||
text: sectionLabelTag(level.name),
|
||||
heightM: SECTION_LABEL_H,
|
||||
angle: 0,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
const f = core().section_line_flat(p0.x, p0.y, p1.x, p1.y, level.directionSign ?? 1);
|
||||
if (f.length === 0) continue;
|
||||
let i = 1;
|
||||
for (let k = 0; k < f[0]; k++) {
|
||||
if (f[i] === 2) {
|
||||
const main = f[i + 1] === 0;
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: { x: f[i + 2], y: f[i + 3] },
|
||||
b: { x: f[i + 4], y: f[i + 5] },
|
||||
cls: "section-line",
|
||||
weightMm: main ? SECTION_LINE_MM : SECTION_LINE_MARK_MM,
|
||||
...(main ? { dash: SECTION_LINE_DASH } : {}),
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
i += 6;
|
||||
} else if (f[i] === 5) {
|
||||
out.push({
|
||||
kind: "drawingText",
|
||||
at: { x: f[i + 1], y: f[i + 2] },
|
||||
text: sectionLabelTag(level.name),
|
||||
heightM: SECTION_LABEL_H,
|
||||
angle: 0,
|
||||
color: SECTION_LINE_INK,
|
||||
greyed,
|
||||
});
|
||||
i += 3;
|
||||
} else {
|
||||
// Unsichtbares Pick-Band (Rechteck entlang der Linie) — klickbar per Punkt-in-Polygon in
|
||||
// PlanView, trägt die DrawingLevel-Id.
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [0, 1, 2, 3].map((j) => ({ x: f[i + 1 + 2 * j], y: f[i + 2 + 2 * j] })),
|
||||
fill: "none",
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
hatch: NO_HATCH,
|
||||
sectionLineId: level.id,
|
||||
});
|
||||
i += 9;
|
||||
}
|
||||
}
|
||||
|
||||
// Unsichtbares Pick-Band (Rechteck entlang der Linie) — klickbar per
|
||||
// Punkt-in-Polygon in PlanView, trägt die DrawingLevel-Id.
|
||||
const off = { x: n.x * SECTION_PICK_HALF, y: n.y * SECTION_PICK_HALF };
|
||||
out.push({
|
||||
kind: "polygon",
|
||||
pts: [
|
||||
{ x: p0.x + off.x, y: p0.y + off.y },
|
||||
{ x: p1.x + off.x, y: p1.y + off.y },
|
||||
{ x: p1.x - off.x, y: p1.y - off.y },
|
||||
{ x: p0.x - off.x, y: p0.y - off.y },
|
||||
],
|
||||
fill: "none",
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
hatch: NO_HATCH,
|
||||
sectionLineId: level.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user