[333] 3D-Griffe: Treppe, Öffnung, Stütze; Plan: nächster Griff gewinnt
Treppe (Bewegpunkt + Parameter-Griffe), Wandöffnung (Gleit-Griff auf Brüstungshöhe) und Stütze (Mitte, Ecken) haben 3D-Griffe mit denselben Kern-Anfragen wie im Plan. Plan-Treffer: nächster Griff statt erster im Radius (kleine Stütze: Ecke statt Mitte).
This commit is contained in:
16 files changed
+416
-19
No files matched your search
@@ -885,6 +885,10 @@ export default function App() {
|
||||
| "edit3dDrawings"
|
||||
| "edit3dCeilings"
|
||||
| "edit3dRoofs"
|
||||
| "edit3dStairs"
|
||||
| "edit3dOpenings"
|
||||
| "edit3dColumns"
|
||||
| "onEdit3dElement"
|
||||
| "onEdit3dVertex"
|
||||
| "onEdit3dBody"
|
||||
| "onEdit3dEdge"
|
||||
|
||||
@@ -3781,6 +3781,9 @@ export const de = {
|
||||
"viewport3d.grip.move": "Verschieben",
|
||||
"viewport3d.grip.edge": "Kante ziehen",
|
||||
"viewport3d.grip.roofpitch": "Dachneigung ziehen",
|
||||
"viewport3d.grip.slide": "Öffnung in der Wand verschieben",
|
||||
"viewport3d.grip.stairParam": "Treppenmass ziehen",
|
||||
"viewport3d.grip.columnSize": "Stützengrösse ziehen",
|
||||
|
||||
// ── Element-Baum (Elemente-Panel, ROADMAP §11) ──────────────────────────────
|
||||
"elements.title": "Elemente",
|
||||
|
||||
@@ -3768,6 +3768,9 @@ export const en: Record<TranslationKey, string> = {
|
||||
"viewport3d.grip.height": "Drag height",
|
||||
"viewport3d.grip.move": "Move",
|
||||
"viewport3d.grip.roofpitch": "Drag roof pitch",
|
||||
"viewport3d.grip.slide": "Slide opening along wall",
|
||||
"viewport3d.grip.stairParam": "Drag stair dimension",
|
||||
"viewport3d.grip.columnSize": "Drag column size",
|
||||
|
||||
// ── Element tree (Elements panel, ROADMAP §11) ──────────────────────────────
|
||||
"elements.title": "Elements",
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { useMemo, useRef, useState, type RefObject } from "react";
|
||||
import type { Ceiling, Drawing2D, Project, Roof, Vec2, Wall } from "../model/types";
|
||||
import type { Ceiling, Column, Drawing2D, Opening, Project, Roof, Stair, Vec2, Wall } from "../model/types";
|
||||
import type { SnapResult, SnapSettings, ToolDraft } from "../tools/types";
|
||||
import { computeSnap } from "../tools/snapping";
|
||||
import { roofBaseElevation, roofGeometry } from "../core";
|
||||
import { roofBaseElevation, roofGeometry, stairMoveHandle } from "../core";
|
||||
import type { ElemGripTarget } from "../viewport/elementGrips3d";
|
||||
import {
|
||||
neighbor3dVertex,
|
||||
bodyMoveAnchor,
|
||||
@@ -48,6 +49,10 @@ export function useGrip3dEditing(opts: {
|
||||
moveGripOf: Actions["moveGripOf"];
|
||||
moveElementByOf: Actions["moveElementByOf"];
|
||||
updateWall: Actions["updateWall"];
|
||||
moveStairBy: Actions["moveStairBy"];
|
||||
dragStairParam: Actions["dragStairParam"];
|
||||
slideOpening: Actions["slideOpening"];
|
||||
moveColumnGrip: Actions["moveColumnGrip"];
|
||||
}) {
|
||||
const {
|
||||
project,
|
||||
@@ -67,8 +72,13 @@ export function useGrip3dEditing(opts: {
|
||||
moveGripOf,
|
||||
moveElementByOf,
|
||||
updateWall,
|
||||
moveStairBy,
|
||||
dragStairParam,
|
||||
slideOpening,
|
||||
moveColumnGrip,
|
||||
} = opts;
|
||||
const { walls: selectedWallIds, drawings: selectedDrawingIds, ceilings: selectedCeilingIds, roofs: selectedRoofIds } = selection;
|
||||
const { stairs: selectedStairIds, openings: selectedOpeningIds, columns: selectedColumnIds } = selection;
|
||||
// ── 3D-Editier-Griffe (direkt im Viewport3D) ──────────────────────────────
|
||||
// Genau EINE gewählte Wand (kein 2D-Element) bzw. genau EIN 2D-Element liefert
|
||||
// die Quelle der 3D-Griffe. Dieselben Store-Actions wie bei den Plan-Griffen
|
||||
@@ -121,6 +131,38 @@ export function useGrip3dEditing(opts: {
|
||||
: [],
|
||||
[selectedWallIds, selectedDrawingIds, selectedCeilingIds, selectedRoofIds, project.roofs],
|
||||
);
|
||||
// [333] Treppen, Wandöffnungen und Stützen: Griffe nur, wenn sonst nichts mit eigenen 3D-Griffen gewählt ist
|
||||
// (eindeutiger Editierfokus). Gesperrte Elemente zeigt `elementGrips3d` nicht.
|
||||
const noOtherGrips =
|
||||
selectedWallIds.length === 0 && selectedDrawingIds.length === 0 && selectedCeilingIds.length === 0 && selectedRoofIds.length === 0;
|
||||
const edit3dStairs = useMemo(
|
||||
() => (noOtherGrips ? selectedStairIds.map((id) => (project.stairs ?? []).find((s) => s.id === id)).filter((s): s is Stair => !!s) : []),
|
||||
[noOtherGrips, selectedStairIds, project.stairs],
|
||||
);
|
||||
const edit3dOpenings = useMemo(
|
||||
() => (noOtherGrips ? selectedOpeningIds.map((id) => (project.openings ?? []).find((o) => o.id === id)).filter((o): o is Opening => !!o) : []),
|
||||
[noOtherGrips, selectedOpeningIds, project.openings],
|
||||
);
|
||||
const edit3dColumns = useMemo(
|
||||
() => (noOtherGrips ? selectedColumnIds.map((id) => (project.columns ?? []).find((c) => c.id === id)).filter((c): c is Column => !!c) : []),
|
||||
[noOtherGrips, selectedColumnIds, project.columns],
|
||||
);
|
||||
// Griff von Treppe/Öffnung/Stütze ziehen: derselbe Kern-Zug wie im Plan (`stairBy`/`stairParam`/`openingSlide`/`columnGrip`),
|
||||
// `pt` = Strahl-Treffpunkt auf der Griff-Ebene in Modell-Metern. Ein Undo-Schritt je Zug über den coalesceKey der Aktion.
|
||||
const onEdit3dElement = (target: ElemGripTarget, index: number, pt: Vec2) => {
|
||||
if (target.stairId) {
|
||||
const st = (project.stairs ?? []).find((s) => s.id === target.stairId);
|
||||
if (!st || st.locked) return;
|
||||
if (index > 0) dragStairParam(st.id, index - 1, pt);
|
||||
else moveStairBy(st.id, { x: pt.x - stairMoveHandle(st).x, y: pt.y - stairMoveHandle(st).y });
|
||||
} else if (target.openingId) {
|
||||
const op = (project.openings ?? []).find((o) => o.id === target.openingId);
|
||||
if (op && !op.locked) slideOpening(op.id, { pt }, `slideOpening:${op.id}`);
|
||||
} else if (target.columnId) {
|
||||
const c = (project.columns ?? []).find((x) => x.id === target.columnId);
|
||||
if (c && !c.locked) moveColumnGrip(c.id, index, pt);
|
||||
}
|
||||
};
|
||||
// Snap beim 3D-Vertex-Drag: dieselbe computeSnap-Logik wie die Plan-Griffe.
|
||||
// Das/die gerade GEZOGENEN Element(e) werden aus den Snap-Quellen genommen
|
||||
// (sonst fängt der Punkt an sich selbst). `excludeWallIds`/`excludeDrawingIds`
|
||||
@@ -415,6 +457,10 @@ export function useGrip3dEditing(opts: {
|
||||
edit3dDrawings,
|
||||
edit3dCeilings,
|
||||
edit3dRoofs,
|
||||
edit3dStairs,
|
||||
edit3dOpenings,
|
||||
edit3dColumns,
|
||||
onEdit3dElement: useEvent(onEdit3dElement),
|
||||
grip3dEdit,
|
||||
setGrip3dEdit,
|
||||
last3dDragRef,
|
||||
|
||||
@@ -392,6 +392,7 @@ export function useProjectActions(
|
||||
const sheetEndGrip = useStore((s) => s.sheetEndGrip);
|
||||
const updateStair = useStore((s) => s.updateStair);
|
||||
const moveStairBy = useStore((s) => s.moveStairBy);
|
||||
const moveColumnGrip = useStore((s) => s.moveColumnGrip);
|
||||
const dragStairParam = useStore((s) => s.dragStairParam);
|
||||
const updateRoom = useStore((s) => s.updateRoom);
|
||||
const moveRoomBy = useStore((s) => s.moveRoomBy);
|
||||
@@ -517,6 +518,7 @@ export function useProjectActions(
|
||||
sheetEndGrip,
|
||||
updateStair,
|
||||
moveStairBy,
|
||||
moveColumnGrip,
|
||||
dragStairParam,
|
||||
updateRoom,
|
||||
moveRoomBy,
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
// Pixel an der Viewport-Höhe normiert), damit sich beide Pfade gleich anfühlen.
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { Project, Wall, Drawing2D, Ceiling, Roof, Vec2 } from "../model/types";
|
||||
import type { Project, Wall, Drawing2D, Ceiling, Roof, Vec2, Stair, Opening, Column } from "../model/types";
|
||||
import { roofBaseElevation, roofGeometry, verticalExtents } from "../core";
|
||||
import { projectToModel3d, pickGeometry, draftWorldLines, explodeFloorOffsets, hiddenClassCodes, filter3d } from "../core";
|
||||
import type { Hide3d } from "../core";
|
||||
@@ -66,6 +66,7 @@ import { useWasm3dRenderer } from "./useWasm3dRenderer";
|
||||
import { cameraRay, pickNearest, rayPlaneY, rayPlane, worldToScreen } from "./raycast3d";
|
||||
import type { Vec3 } from "../core";
|
||||
import { drawingGripVertices, drawingMoveAnchor } from "./drawingGrips";
|
||||
import { elemExplodeDz, elementGrips3d, type ElemGripTarget } from "./elementGrips3d";
|
||||
import { pointCloudSyncItems } from "./pointCloudSync";
|
||||
import { usePointClouds } from "../state/pointCloudStore";
|
||||
import { sun3dFor, sun3dKey } from "./sun3d";
|
||||
@@ -133,7 +134,9 @@ type GripKind = "vertex" | "height" | "move" | "edge" | "roofpitch";
|
||||
interface Grip {
|
||||
kind: GripKind;
|
||||
/** Element, dessen Griff das ist (Wand-/Drawing-/Decken-/Dach-ID). */
|
||||
target: { wallId?: string; drawingId?: string; ceilingId?: string; roofId?: string };
|
||||
target: { wallId?: string; drawingId?: string; ceilingId?: string; roofId?: string } & ElemGripTarget;
|
||||
/** [333] Arbeitsebene (Welt-y) bei Treppen-/Öffnungs-/Stützen-Griffen; sonst aus dem Ziel abgeleitet. */
|
||||
planeY?: number;
|
||||
/** Vertex-Index (`vertex`) bzw. erster Kanten-Index (`edge`); -1 sonst. */
|
||||
index: number;
|
||||
/** Zweiter Kanten-Index (nur `kind==="edge"`). */
|
||||
@@ -151,6 +154,7 @@ function sameGripScreens(a: readonly { grip: Grip; x: number; y: number }[], b:
|
||||
const u = q.grip.target;
|
||||
if (p.x !== q.x || p.y !== q.y || p.grip.kind !== q.grip.kind || p.grip.index !== q.grip.index || p.grip.index2 !== q.grip.index2) return false;
|
||||
if (t.wallId !== u.wallId || t.drawingId !== u.drawingId || t.ceilingId !== u.ceilingId || t.roofId !== u.roofId) return false;
|
||||
if (t.stairId !== u.stairId || t.openingId !== u.openingId || t.columnId !== u.columnId) return false;
|
||||
const [x, y, z] = p.grip.pos;
|
||||
if (x !== q.grip.pos[0] || y !== q.grip.pos[1] || z !== q.grip.pos[2]) return false;
|
||||
}
|
||||
@@ -211,12 +215,19 @@ function computeGrips(
|
||||
drawingElevation: number,
|
||||
/** Explosionsaxonometrie ([65]): Versatz je Geschoss-id; Griffe sitzen auf den gehobenen Bauteilen. */
|
||||
floorOffsets: Readonly<Record<string, number>> = {},
|
||||
/** [333] Gewählte Treppen/Öffnungen/Stützen. */
|
||||
elems: { stairs: readonly Stair[]; openings: readonly Opening[]; columns: readonly Column[] } = { stairs: [], openings: [], columns: [] },
|
||||
): Grip[] {
|
||||
const out = computeGripsAt(project, walls, drawings, ceilings, roofs, drawingElevation);
|
||||
for (const g of out) {
|
||||
const dz = explodeGripDz(project, floorOffsets, g.target);
|
||||
if (dz !== 0) g.pos = [g.pos[0], g.pos[1] + dz, g.pos[2]];
|
||||
}
|
||||
// [333] Treppe/Öffnung/Stütze: Lage und Ebene mit Explosionsversatz (Ebene = Höhe, auf der gezogen wird).
|
||||
for (const e of elementGrips3d(project, elems.stairs, elems.openings, elems.columns)) {
|
||||
const dz = elemExplodeDz(project, floorOffsets, e.target);
|
||||
out.push({ kind: e.kind, target: e.target, index: e.index, pos: [e.pos[0], e.pos[1] + dz, e.pos[2]], planeY: e.planeY + dz });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -408,6 +419,10 @@ export function Wasm3DViewport({
|
||||
editDrawings = [],
|
||||
editCeilings = [],
|
||||
editRoofs = [],
|
||||
editStairs = [],
|
||||
editOpenings = [],
|
||||
editColumns = [],
|
||||
onEditElement,
|
||||
onEditVertex,
|
||||
onEditBody,
|
||||
onEditEdge,
|
||||
@@ -470,6 +485,12 @@ export function Wasm3DViewport({
|
||||
editCeilings?: Ceiling[];
|
||||
/** Gewählte Dächer — Quelle der 3D-Eckpunkt-/Verschiebe-/First-Griffe. */
|
||||
editRoofs?: Roof[];
|
||||
/** [333] Gewählte Treppen/Wandöffnungen/Stützen — Quelle ihrer 3D-Griffe. */
|
||||
editStairs?: Stair[];
|
||||
editOpenings?: Opening[];
|
||||
editColumns?: Column[];
|
||||
/** [333] Griff von Treppe/Öffnung/Stütze gezogen: Griff-Index und Punkt (Modell-m) auf der Griff-Ebene. */
|
||||
onEditElement?: (target: ElemGripTarget, index: number, pt: Vec2) => void;
|
||||
/**
|
||||
* Endpunkt-Griff gezogen: neuer XY-Modellpunkt für den Vertex `index` des
|
||||
* Elements. Optionale `excludeWallIds`/`excludeDrawingIds` = Koinzidenz-
|
||||
@@ -576,6 +597,14 @@ export function Wasm3DViewport({
|
||||
editCeilingsRef.current = editCeilings;
|
||||
const editRoofsRef = useRef(editRoofs);
|
||||
editRoofsRef.current = editRoofs;
|
||||
const editStairsRef = useRef(editStairs);
|
||||
editStairsRef.current = editStairs;
|
||||
const editOpeningsRef = useRef(editOpenings);
|
||||
editOpeningsRef.current = editOpenings;
|
||||
const editColumnsRef = useRef(editColumns);
|
||||
editColumnsRef.current = editColumns;
|
||||
const onEditElementRef = useRef(onEditElement);
|
||||
onEditElementRef.current = onEditElement;
|
||||
const onEditVertexRef = useRef(onEditVertex);
|
||||
onEditVertexRef.current = onEditVertex;
|
||||
const onEditBodyRef = useRef(onEditBody);
|
||||
@@ -1003,7 +1032,10 @@ export function Wasm3DViewport({
|
||||
(editWalls.length === 0 &&
|
||||
editDrawings.length === 0 &&
|
||||
editCeilings.length === 0 &&
|
||||
editRoofs.length === 0)
|
||||
editRoofs.length === 0 &&
|
||||
editStairs.length === 0 &&
|
||||
editOpenings.length === 0 &&
|
||||
editColumns.length === 0)
|
||||
) {
|
||||
setGripScreens([]);
|
||||
return;
|
||||
@@ -1024,6 +1056,7 @@ export function Wasm3DViewport({
|
||||
editRoofsRef.current,
|
||||
groundElevationRef.current,
|
||||
floorOffsetsRef.current,
|
||||
{ stairs: editStairsRef.current, openings: editOpeningsRef.current, columns: editColumnsRef.current },
|
||||
);
|
||||
const next: { grip: Grip; x: number; y: number }[] = [];
|
||||
for (const g of grips) {
|
||||
@@ -1038,7 +1071,7 @@ export function Wasm3DViewport({
|
||||
};
|
||||
raf = requestAnimationFrame(tick);
|
||||
return () => cancelAnimationFrame(raf);
|
||||
}, [ready, editWalls, editDrawings, editCeilings, editRoofs]);
|
||||
}, [ready, editWalls, editDrawings, editCeilings, editRoofs, editStairs, editOpenings, editColumns]);
|
||||
|
||||
// Cursor-HUD-Bildschirmposition (Länge/Winkel beim Zeichnen ODER Δx/Δy/
|
||||
// Länge-Winkel während eines Griff-Drags, s. `hudFields`-Doc): derselbe
|
||||
@@ -1160,6 +1193,7 @@ export function Wasm3DViewport({
|
||||
moveCoincident: MoveCoincidentVertex[];
|
||||
}
|
||||
| { kind: "edge"; ceilingId: string; a: number; b: number; planeY: number; lastModel: Vec2 | null }
|
||||
| { kind: "elem"; target: ElemGripTarget; index: number; planeY: number }
|
||||
| { kind: "height"; wallId: string }
|
||||
| { kind: "roofpitch"; roofId: string; apexXZ: readonly [number, number] };
|
||||
const gripDragRef = useRef<GripDrag | null>(null);
|
||||
@@ -1204,7 +1238,11 @@ export function Wasm3DViewport({
|
||||
endGripDrag();
|
||||
return;
|
||||
}
|
||||
if (grip.kind === "height") {
|
||||
if (grip.target.stairId || grip.target.openingId || grip.target.columnId) {
|
||||
// [333] Treppe/Öffnung/Stütze: Strahl auf die waagrechte Griff-Ebene, der Kern rechnet den Zug (wie im Plan).
|
||||
if (grip.planeY == null) return;
|
||||
gripDragRef.current = { kind: "elem", target: grip.target, index: grip.index, planeY: grip.planeY };
|
||||
} else if (grip.kind === "height") {
|
||||
if (!grip.target.wallId) return;
|
||||
gripDragRef.current = { kind: "height", wallId: grip.target.wallId };
|
||||
} else if (grip.kind === "roofpitch") {
|
||||
@@ -1321,6 +1359,12 @@ export function Wasm3DViewport({
|
||||
const hit = rayPlaneY(ray, drag.planeY);
|
||||
if (!hit) return;
|
||||
const model: Vec2 = { x: hit[0], y: hit[2] };
|
||||
if (drag.kind === "elem") {
|
||||
const et = drag.target;
|
||||
// Ein Undo-Schritt je Zug: gleicher Schlüssel (Aktionen coalescen zusätzlich über ihren eigenen).
|
||||
editGroup(`grip3dElem:${et.stairId ?? et.openingId ?? et.columnId}:${drag.index}`, () => onEditElementRef.current?.(et, drag.index, model));
|
||||
return;
|
||||
}
|
||||
if (drag.kind === "vertex") {
|
||||
// Pfeiltasten-Achsen-Lock (s. Datei-Kommentar an `axisLockRef`) hat
|
||||
// Vorrang vor Shift — ein bewusst per Taste gewählter Anker/Achse soll
|
||||
@@ -2139,10 +2183,16 @@ export function Wasm3DViewport({
|
||||
const glyphStrokeWidth = grip.kind === "edge" ? 1.5 : 1.75;
|
||||
return (
|
||||
<div
|
||||
key={`${grip.kind}:${grip.target.wallId ?? grip.target.drawingId ?? grip.target.ceilingId ?? grip.target.roofId}:${grip.index}`}
|
||||
key={`${grip.kind}:${grip.target.wallId ?? grip.target.drawingId ?? grip.target.ceilingId ?? grip.target.roofId ?? grip.target.stairId ?? grip.target.openingId ?? grip.target.columnId}:${grip.index}`}
|
||||
onPointerDown={startGripDrag(grip)}
|
||||
title={t(
|
||||
grip.kind === "height"
|
||||
grip.target.openingId
|
||||
? "viewport3d.grip.slide"
|
||||
: grip.target.stairId && grip.kind === "vertex"
|
||||
? "viewport3d.grip.stairParam"
|
||||
: grip.target.columnId && grip.kind === "vertex"
|
||||
? "viewport3d.grip.columnSize"
|
||||
: grip.kind === "height"
|
||||
? "viewport3d.grip.height"
|
||||
: grip.kind === "roofpitch"
|
||||
? "viewport3d.grip.roofpitch"
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { columnTopZ, openingSillZ, elemExplodeDz, elementGrips3d } from "./elementGrips3d";
|
||||
|
||||
const p = buildComplexSampleProject();
|
||||
|
||||
describe("elementGrips3d", () => {
|
||||
it("Stütze: Mitte als Verschiebe-Griff, dazu Ecken (Index wie columnGrip)", () => {
|
||||
const c = p.columns!.find((x) => x.id === "st-carport-1")!;
|
||||
const gs = elementGrips3d(p, [], [], [c]);
|
||||
expect(gs.length).toBe(6);
|
||||
expect(gs[0]).toMatchObject({ kind: "move", index: 0, target: { columnId: c.id } });
|
||||
expect(gs[0].pos[0]).toBeCloseTo(c.position.x);
|
||||
expect(gs[0].pos[2]).toBeCloseTo(c.position.y);
|
||||
expect(gs[0].pos[1]).toBeGreaterThan(columnTopZ(p, c));
|
||||
expect(gs.slice(1).every((g) => g.kind === "vertex")).toBe(true);
|
||||
});
|
||||
|
||||
it("gesperrte Stütze hat keine Griffe", () => {
|
||||
const c = { ...p.columns![0], locked: true };
|
||||
expect(elementGrips3d(p, [], [], [c])).toEqual([]);
|
||||
});
|
||||
|
||||
it("Öffnung: ein Gleit-Griff auf Brüstungshöhe", () => {
|
||||
const win = p.openings!.find((o) => o.sillHeight > 0 && !o.hostRoofId && !o.hostCeilingId)!;
|
||||
const gs = elementGrips3d(p, [], [win], []);
|
||||
expect(gs).toHaveLength(1);
|
||||
expect(gs[0].kind).toBe("move");
|
||||
const w = p.walls.find((x) => x.id === win.hostWallId)!;
|
||||
expect(gs[0].planeY).toBeCloseTo(openingSillZ(p, win, w) + 0.05);
|
||||
});
|
||||
|
||||
it("Treppe: Bewegpunkt zuerst, Parameter-Griffe ab Index 1", () => {
|
||||
const st = p.stairs![0];
|
||||
const gs = elementGrips3d(p, [st], [], []);
|
||||
expect(gs[0]).toMatchObject({ kind: "move", index: 0 });
|
||||
gs.slice(1).forEach((g, i) => expect(g.index).toBe(i + 1));
|
||||
});
|
||||
|
||||
it("Explosion: Versatz des Geschosses", () => {
|
||||
const c = p.columns!.find((x) => x.id === "st-carport-1")!;
|
||||
expect(elemExplodeDz(p, { [c.floorId]: 3 }, { columnId: c.id })).toBe(3);
|
||||
expect(elemExplodeDz(p, {}, { columnId: c.id })).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
// 3D-Griffe für Treppen, Wandöffnungen und Stützen ([333]): reine Lagen-Berechnung (Welt-Koordinaten
|
||||
// x, Höhe, y) und Arbeitsebene je Griff. Die Griff-Punkte selbst und die Änderungen rechnet der Kern
|
||||
// (`stairParamPoints`/`stairMoveHandle`, `columnGripPoints`, `openingGripPoint`; Anfragen `stairBy`,
|
||||
// `stairParam`, `columnGrip`, `openingSlide`) — hier nur die Höhe, auf der der Griff sitzt.
|
||||
|
||||
import type { Column, Opening, Project, Stair, Vec2, Wall } from "../model/types";
|
||||
import { columnGripPoints, openingGripPoint, stairMoveHandle, stairParamPoints, verticalExtents } from "../core";
|
||||
import type { Vec3 } from "../core";
|
||||
|
||||
/** Ziel eines Element-Griffs (genau eines gesetzt). */
|
||||
export interface ElemGripTarget {
|
||||
stairId?: string;
|
||||
openingId?: string;
|
||||
columnId?: string;
|
||||
}
|
||||
|
||||
/** Ein Element-Griff: `index` = Griff-Index der Anfrage (Treppe: 0 = Bewegpunkt, n = Parameter n−1). */
|
||||
export interface ElemGrip {
|
||||
kind: "move" | "vertex";
|
||||
target: ElemGripTarget;
|
||||
index: number;
|
||||
pos: Vec3;
|
||||
/** Arbeitsebene (Höhe, Welt-y), auf der der Griff gezogen wird. */
|
||||
planeY: number;
|
||||
}
|
||||
|
||||
/** Geschoss-OK (m), 0 ohne Angabe. */
|
||||
function floorBaseZ(project: Project, floorId: string): number {
|
||||
const z = project.drawingLevels.find((l) => l.id === floorId)?.baseElevation;
|
||||
return typeof z === "number" && Number.isFinite(z) ? z : 0;
|
||||
}
|
||||
|
||||
/** Höhe einer vertikalen Bindung; ohne Bindung `fallback`. */
|
||||
function anchorZ(project: Project, a: Column["bottom"], fallback: number): number {
|
||||
if (!a) return fallback;
|
||||
return a.mode === "custom" ? a.z : floorBaseZ(project, a.floorId) + (a.offset ?? 0);
|
||||
}
|
||||
|
||||
/** Unterkante (absolutes Z) einer Stütze. */
|
||||
export function columnBottomZ(project: Project, c: Column): number {
|
||||
return anchorZ(project, c.bottom, floorBaseZ(project, c.floorId));
|
||||
}
|
||||
|
||||
/** Oberkante (absolutes Z) einer Stütze. */
|
||||
export function columnTopZ(project: Project, c: Column): number {
|
||||
return anchorZ(project, c.top, columnBottomZ(project, c) + c.height);
|
||||
}
|
||||
|
||||
/** Brüstungshöhe (absolutes Z) einer Wandöffnung: Wand-UK + `sillHeight`. */
|
||||
export function openingSillZ(project: Project, op: Opening, wall: Wall): number {
|
||||
return verticalExtents(project, [wall]).walls[0].zBottom + (op.sillHeight ?? 0);
|
||||
}
|
||||
|
||||
const world = (p: Vec2, y: number): Vec3 => [p.x, y, p.y];
|
||||
|
||||
/**
|
||||
* Griffe der gewählten Treppen, Wandöffnungen und Stützen. Gesperrte Elemente (`locked`) haben keine.
|
||||
* Treppe: Bewegpunkt + Parameter-Griffe auf der Antrittsebene; Öffnung: ein Gleit-Griff auf Brüstungshöhe;
|
||||
* Stütze: Mitte (verschieben) knapp über der Oberkante, Ecken/Radius/Dreh-Griff auf der Oberkante.
|
||||
*/
|
||||
export function elementGrips3d(project: Project, stairs: readonly Stair[], openings: readonly Opening[], columns: readonly Column[]): ElemGrip[] {
|
||||
const out: ElemGrip[] = [];
|
||||
for (const st of stairs) {
|
||||
if (st.locked) continue;
|
||||
const y = floorBaseZ(project, st.floorId) + 0.05;
|
||||
const target = { stairId: st.id };
|
||||
out.push({ kind: "move", target, index: 0, pos: world(stairMoveHandle(st), y), planeY: y });
|
||||
stairParamPoints(st).forEach((p, i) => out.push({ kind: "vertex", target, index: i + 1, pos: world(p, y), planeY: y }));
|
||||
}
|
||||
for (const op of openings) {
|
||||
if (op.locked || op.hostRoofId || op.hostCeilingId) continue;
|
||||
const w = project.walls.find((x) => x.id === op.hostWallId);
|
||||
if (!w) continue;
|
||||
const y = openingSillZ(project, op, w) + 0.05;
|
||||
out.push({ kind: "move", target: { openingId: op.id }, index: 0, pos: world(openingGripPoint(w, op), y), planeY: y });
|
||||
}
|
||||
for (const c of columns) {
|
||||
if (c.locked) continue;
|
||||
const top = columnTopZ(project, c);
|
||||
const target = { columnId: c.id };
|
||||
columnGripPoints(c).forEach((p, i) => {
|
||||
const y = top + (i === 0 ? 0.25 : 0.02);
|
||||
out.push({ kind: i === 0 ? "move" : "vertex", target, index: i, pos: world(p, y), planeY: y });
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Höhenversatz der Explosionsaxonometrie ([65]) eines Element-Griffs (Geschoss des Elements). */
|
||||
export function elemExplodeDz(project: Project, offsets: Readonly<Record<string, number>>, target: ElemGripTarget): number {
|
||||
let floorId: string | undefined;
|
||||
if (target.stairId) floorId = project.stairs?.find((s) => s.id === target.stairId)?.floorId;
|
||||
else if (target.columnId) floorId = project.columns?.find((c) => c.id === target.columnId)?.floorId;
|
||||
else if (target.openingId) {
|
||||
const op = project.openings?.find((o) => o.id === target.openingId);
|
||||
floorId = project.walls.find((w) => w.id === op?.hostWallId)?.floorId;
|
||||
}
|
||||
return (floorId && offsets[floorId]) || 0;
|
||||
}
|
||||
@@ -44,6 +44,10 @@ type DerivedContentProps =
|
||||
| "edit3dDrawings"
|
||||
| "edit3dCeilings"
|
||||
| "edit3dRoofs"
|
||||
| "edit3dStairs"
|
||||
| "edit3dOpenings"
|
||||
| "edit3dColumns"
|
||||
| "onEdit3dElement"
|
||||
| "onEdit3dVertex"
|
||||
| "onEdit3dBody"
|
||||
| "onEdit3dEdge"
|
||||
@@ -191,9 +195,13 @@ export function ViewportCenter(props: {
|
||||
moveGripOf: pa.moveGripOf,
|
||||
moveElementByOf: pa.moveElementByOf,
|
||||
updateWall: pa.updateWall,
|
||||
moveStairBy: pa.moveStairBy,
|
||||
dragStairParam: pa.dragStairParam,
|
||||
slideOpening: pa.slideOpening,
|
||||
moveColumnGrip: pa.moveColumnGrip,
|
||||
});
|
||||
const {
|
||||
edit3dWalls, edit3dDrawings, edit3dCeilings, edit3dRoofs, onEdit3dVertex, onEdit3dBody, onEdit3dEdge,
|
||||
edit3dWalls, edit3dDrawings, edit3dCeilings, edit3dRoofs, edit3dStairs, edit3dOpenings, edit3dColumns, onEdit3dElement, onEdit3dVertex, onEdit3dBody, onEdit3dEdge,
|
||||
onEdit3dRoofPitch, onEdit3dWallTop, onEdit3dEnd, cycleGrip3dEditField, cancelGrip3dEdit,
|
||||
} = grip3d;
|
||||
|
||||
@@ -232,6 +240,10 @@ export function ViewportCenter(props: {
|
||||
edit3dDrawings={edit3dDrawings}
|
||||
edit3dCeilings={edit3dCeilings}
|
||||
edit3dRoofs={edit3dRoofs}
|
||||
edit3dStairs={edit3dStairs}
|
||||
edit3dOpenings={edit3dOpenings}
|
||||
edit3dColumns={edit3dColumns}
|
||||
onEdit3dElement={onEdit3dElement}
|
||||
onEdit3dVertex={onEdit3dVertex}
|
||||
onEdit3dBody={onEdit3dBody}
|
||||
onEdit3dEdge={onEdit3dEdge}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { pickGripIndex } from "./gripPick";
|
||||
|
||||
// Stütze 12 cm: Mitte (Index 0) und Ecke (Index 1) nur 7 px auseinander.
|
||||
const col = [{ x: 100, y: 100 }, { x: 107, y: 100 }, { x: 93, y: 100 }];
|
||||
|
||||
describe("pickGripIndex", () => {
|
||||
it("Klick auf die Ecke trifft die Ecke, nicht die Mitte", () => {
|
||||
expect(pickGripIndex(col, 107, 100, 9)).toBe(1);
|
||||
expect(pickGripIndex(col, 93, 101, 9)).toBe(2);
|
||||
});
|
||||
it("Klick auf die Mitte trifft die Mitte", () => {
|
||||
expect(pickGripIndex(col, 100, 100, 9)).toBe(0);
|
||||
});
|
||||
it("praktisch gleich nah: Ecke (höherer Index) vor Mitte", () => {
|
||||
expect(pickGripIndex(col, 103.5, 100, 9)).toBe(1);
|
||||
});
|
||||
it("ausserhalb des Radius: null", () => {
|
||||
expect(pickGripIndex(col, 140, 100, 9)).toBeNull();
|
||||
expect(pickGripIndex([], 0, 0, 9)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
// Griff-Treffer im Plan ([333]): der NÄCHSTE Griff gewinnt, nicht der erste im Radius. Bei einer kleinen Stütze
|
||||
// (12 cm) liegen die Eck-Griffe nur etwa 7 px vom Mittelgriff; die Liste führt den Mittel-/Verschiebe-Griff an
|
||||
// Index 0, die Ecken folgen — der alte „erster Treffer"-Test nahm deshalb auch beim Klick auf eine Ecke die Mitte.
|
||||
|
||||
/** Abstand (px), innerhalb dessen zwei Griffe als gleich nah gelten (dann gewinnt der spätere: Ecke statt Mitte). */
|
||||
export const GRIP_TIE_PX = 2;
|
||||
|
||||
/**
|
||||
* Index des Griffs, dessen Mittelpunkt dem Zeiger am nächsten liegt und höchstens `hitPx` entfernt ist; sonst null.
|
||||
* Liegen mehrere Griffe praktisch gleich nah (Unterschied ≤ {@link GRIP_TIE_PX}), gilt der mit dem höheren Index —
|
||||
* die Listen der Bauteile führen den Verschiebe-Griff (Mitte) vorn, Ecken/Eckpunkte dahinter.
|
||||
*/
|
||||
export function pickGripIndex(centers: readonly { x: number; y: number }[], px: number, py: number, hitPx: number): number | null {
|
||||
const d = centers.map((c) => Math.hypot(c.x - px, c.y - py));
|
||||
let minD = Infinity;
|
||||
for (const x of d) if (x <= hitPx && x < minD) minD = x;
|
||||
if (!Number.isFinite(minD)) return null;
|
||||
let best: number | null = null;
|
||||
for (let i = 0; i < d.length; i++) if (d[i] <= hitPx && d[i] <= minD + GRIP_TIE_PX) best = i;
|
||||
return best;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import type { ViewBox__plan_planView_geometry as ViewBox, ClientMap } from "../.
|
||||
import type { Vec2, EdgeGrip } from "../../../model/types";
|
||||
import type { BodyTarget } from "./types";
|
||||
import { GRIP_HIT_PX } from "./constants";
|
||||
import { pickGripIndex } from "./gripPick";
|
||||
import { createCursorStore } from "../../../state/cursorStore";
|
||||
import type { GripHandlers } from "./types";
|
||||
import type { PlanViewHandle } from "./types";
|
||||
@@ -302,12 +303,16 @@ export function usePlanCoords(inp: UsePlanCoordsArgs) {
|
||||
// Index des Griffs unter dem Cursor (Bildschirm-Pixel) oder null.
|
||||
const gripAt = (clientX: number, clientY: number): number | null => {
|
||||
if (!grips) return null;
|
||||
for (let i = 0; i < grips.length; i++) {
|
||||
const vb = toScreen(grips[i]);
|
||||
const c = vbToClient(vb.x, vb.y);
|
||||
if (Math.hypot(c.x - clientX, c.y - clientY) <= GRIP_HIT_PX) return i;
|
||||
}
|
||||
return null;
|
||||
// [333] Nächster Griff gewinnt (kleine Stütze: Ecke statt Mitte), s. `gripPick.ts`.
|
||||
return pickGripIndex(
|
||||
grips.map((g) => {
|
||||
const vb = toScreen(g);
|
||||
return vbToClient(vb.x, vb.y);
|
||||
}),
|
||||
clientX,
|
||||
clientY,
|
||||
GRIP_HIT_PX,
|
||||
);
|
||||
};
|
||||
// Bildschirm-Versatz (viewBox-Einheiten) eines Kanten-Anfassers entlang seiner
|
||||
// Normale: das Dreieck sitzt etwas AUSSERHALB der Kante. Y wird gespiegelt
|
||||
|
||||
@@ -20,6 +20,9 @@ import type {
|
||||
Layout,
|
||||
Project,
|
||||
Roof,
|
||||
Stair,
|
||||
Opening,
|
||||
Column,
|
||||
Vec2,
|
||||
Wall,
|
||||
} from "../model/types";
|
||||
@@ -139,6 +142,10 @@ export const Content = memo(function Content({
|
||||
edit3dDrawings,
|
||||
edit3dCeilings,
|
||||
edit3dRoofs,
|
||||
edit3dStairs,
|
||||
edit3dOpenings,
|
||||
edit3dColumns,
|
||||
onEdit3dElement,
|
||||
onEdit3dVertex,
|
||||
onEdit3dBody,
|
||||
onEdit3dEdge,
|
||||
@@ -247,6 +254,11 @@ export const Content = memo(function Content({
|
||||
/** Alle gewählten Decken — 3D-Eckpunkt-/Kanten-/Verschiebe-Griffe. */
|
||||
edit3dCeilings: Ceiling[];
|
||||
edit3dRoofs: Roof[];
|
||||
/** [333] Gewählte Treppen/Wandöffnungen/Stützen — 3D-Griffe (Kern-Anfragen wie im Plan). */
|
||||
edit3dStairs: Stair[];
|
||||
edit3dOpenings: Opening[];
|
||||
edit3dColumns: Column[];
|
||||
onEdit3dElement: (target: { stairId?: string; openingId?: string; columnId?: string }, index: number, pt: Vec2) => void;
|
||||
onEdit3dVertex: (
|
||||
target: { wallId?: string; drawingId?: string; ceilingId?: string; roofId?: string },
|
||||
index: number,
|
||||
@@ -358,6 +370,10 @@ export const Content = memo(function Content({
|
||||
editDrawings={edit3dDrawings}
|
||||
editCeilings={edit3dCeilings}
|
||||
editRoofs={edit3dRoofs}
|
||||
editStairs={edit3dStairs}
|
||||
editOpenings={edit3dOpenings}
|
||||
editColumns={edit3dColumns}
|
||||
onEditElement={onEdit3dElement}
|
||||
onEditVertex={onEdit3dVertex}
|
||||
onEditBody={onEdit3dBody}
|
||||
onEditEdge={onEdit3dEdge}
|
||||
|
||||
Reference in new issue
Block a user