[213] Kameras als Modell-Elemente und Begehen (WASD) im 3D

Project.cameras (Rust Camera: Standpunkt + Augenhöhe über Geschoss, Ziel, Bildwinkel, Perspektive/
Axonometrie/Parallel, Sonnenstand) auf der neuen Klasse "Kameras" (92). Grundriss-Symbol im Kern
(plan/cameras.rs: Gehäuse, Sichtkegel, Ziel, Name, schmale Pick-Bänder), Griffe im Kern (camera.rs,
grips.rs: Standpunkt, Ziel, Bildwinkel/Sichtbreite), Auswahl/Entf, Objekt-Info CameraSection, Liste im
Panel Ausschnitte, "Kamera aus aktueller Ansicht anlegen", "Kamera öffnen" (auch per Doppelklick auf das
Symbol), cameraToView() für das Rendering [211]. Begehen im 3D: Umschalt+F, W/A/S/D/Pfeile, Q/E,
Umschalt/Alt, Umschauen um den Augpunkt (viewport/walk.ts). Beispiel: Kamera im Musterhaus komplex.
This commit is contained in:
Claude committed 2026-11-12 18:31:37 +00:00
1 parent b02b9232bd
commit ed475fe64b
64 files changed
+2031 -50

No files matched your search

+108
View File
@@ -0,0 +1,108 @@
// [213] Aktionen zu Kamera-Elementen (`Project.cameras`): aus der aktuellen 3D-Ansicht anlegen, eine Kamera im 3D
// öffnen (Ansicht exakt setzen, Sonne übernehmen), die Kamera mit der aktuellen Ansicht überschreiben. Die Umrechnung
// Kamera ↔ Ansicht steht rein in `viewport/cameraView.ts`; hier hängt sie am Store, an den Reitern und am Viewport.
import { addItems, patchItem, setField } from "../core";
import { t } from "../i18n";
import type { Camera } from "../model/types";
import { getCamera, getCameraTargetDistance, setCamera, viewportAvailable } from "../viewport/cameraBridge";
import { cameraFromView, cameraToView, nextCameraName } from "../viewport/cameraView";
import { getState } from "./appStore";
import { fromIds } from "./selection";
import { switchViewType } from "./tabNavigation";
function newCameraId(): string {
const r = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID().slice(0, 8) : Math.random().toString(36).slice(2, 10);
return `cam-${r}`;
}
/** Kamera aus der aktuellen 3D-Ansicht anlegen und wählen. Gibt die id zurück, `null` ohne 3D-Ansicht. */
export function createCameraFromView(): string | null {
const st = getState();
const view = viewportAvailable() ? getCamera() : null;
if (!view) {
st.notify(t("camera.noViewport"), "warning");
return null;
}
const cam = cameraFromView(st.project, view, {
id: newCameraId(),
name: nextCameraName(st.project, t("camera.defaultName")),
fallbackFloorId: st.activeLevelId,
distance: getCameraTargetDistance() ?? undefined,
});
st.applyChange(addItems("cameras", [cam]));
st.setSelection(fromIds("cameras", [cam.id]));
st.notify(t("camera.created", { name: cam.name }), "info");
return cam.id;
}
/** Wartet (höchstens `timeoutMs`), bis der 3D-Viewport Kamera-Zugriff meldet — nach dem Wechsel in den 3D-Reiter. */
function whenViewportReady(timeoutMs = 3000): Promise<boolean> {
if (viewportAvailable()) return Promise.resolve(true);
return new Promise((resolve) => {
const t0 = performance.now();
const poll = () => {
if (viewportAvailable()) resolve(true);
else if (performance.now() - t0 > timeoutMs) resolve(false);
else requestAnimationFrame(poll);
};
requestAnimationFrame(poll);
});
}
/**
* Kamera im 3D öffnen: in den 3D-Reiter wechseln, die Ansicht exakt setzen (Standpunkt, Blickrichtung, Bildwinkel,
* Projektion) und — hat die Kamera einen Sonnenstand — die Sonnenstudie darauf stellen (Schatten im 3D an).
*/
export async function openCamera(id: string): Promise<boolean> {
const st = getState();
const cam = (st.project.cameras ?? []).find((c) => c.id === id);
if (!cam) return false;
const view = cameraToView(st.project, cam);
if (!view) {
st.notify(t("camera.invalid", { name: cam.name }), "warning");
return false;
}
if (!viewportAvailable()) switchViewType("perspektive");
if (!(await whenViewportReady())) {
st.notify(t("camera.noViewport"), "warning");
return false;
}
// Seitenverhältnis des Viewports behalten (die Brücke füllt es aus der Live-Kamera).
const live = getCamera();
const placed = setCamera({ ...view, aspect: live?.aspect ?? view.aspect }, { animate: true });
if (!placed) {
st.notify(t("camera.invalid", { name: cam.name }), "warning");
return false;
}
if (cam.sunWhen && Number.isFinite(new Date(cam.sunWhen).getTime())) {
const study = getState().project.sunStudy;
if (study?.when !== cam.sunWhen || study.shadows3d !== true) {
getState().applyChange([setField("sunStudy", { ...(study ?? { show: false }), when: cam.sunWhen, shadows3d: true } as NonNullable<typeof study>)]);
}
}
return true;
}
/** Kamera mit der aktuellen 3D-Ansicht überschreiben (Standpunkt, Ziel, Bildwinkel, Projektion; Name und Klasse bleiben). */
export function updateCameraFromView(id: string): boolean {
const st = getState();
const old = (st.project.cameras ?? []).find((c) => c.id === id);
const view = viewportAvailable() ? getCamera() : null;
if (!old || !view) {
st.notify(t("camera.noViewport"), "warning");
return false;
}
const fresh = cameraFromView(st.project, view, {
id: old.id,
name: old.name,
fallbackFloorId: old.floorId,
distance: getCameraTargetDistance() ?? undefined,
categoryCode: old.categoryCode,
});
const next: Camera = { ...old, ...fresh, locked: old.locked, sunWhen: old.sunWhen };
if (fresh.projection === "perspective") delete next.orthoHeight;
st.applyChange((p) => patchItem(p, "cameras", id, () => next));
st.notify(t("camera.updated", { name: old.name }), "info");
return true;
}
+5 -1
View File
@@ -60,7 +60,8 @@ export type ShortcutId =
| "showAllLayers"
| "fitAll"
| "fitSelection"
| "isolateLayer";
| "isolateLayer"
| "walkMode";
export type ShortcutCategory =
| "general"
@@ -233,6 +234,9 @@ export const SHORTCUT_DEFS: ShortcutDef[] = [
{ id: "fitSelection", category: "navigation", labelKey: "shortcut.fitSelection", defaultCombo: "mod+shift+f" },
// [192] Ebenen schnell schalten (Cmd/Ctrl+Shift+I ist der Boolean-Schnitt, daher L = Layer).
{ id: "isolateLayer", category: "navigation", labelKey: "shortcut.isolateLayer", defaultCombo: "mod+shift+l" },
// [213] Begehen im 3D (WASD): Umschalt+F schaltet den Begehen-Modus; die Bewegungstasten selbst (W/A/S/D, Q/E, Pfeile) gelten nur
// darin, damit sie nicht mit „s" (Spiegeln), „d" (Drehen) und „q" (Messen) kollidieren (`viewport/walk.ts`).
{ id: "walkMode", category: "navigation", labelKey: "shortcut.walkMode", defaultCombo: "shift+f" },
];
const DEFS_BY_ID = new Map<ShortcutId, ShortcutDef>(SHORTCUT_DEFS.map((d) => [d.id, d]));
+1 -1
View File
@@ -34,7 +34,7 @@ export interface SelectionAppearance {
/** Zahl der gewählten Elemente (ohne Gruppen, Schnittlinien, Lage-Darstellung, Bäume). */
export function selectedCount(sel: Selection): number {
return ELEMENT_KINDS.filter((k) => k !== "sectionLines" && k !== "site" && k !== "trees").reduce((n, k) => n + sel[k].length, 0);
return ELEMENT_KINDS.filter((k) => k !== "sectionLines" && k !== "site" && k !== "trees" && k !== "cameras").reduce((n, k) => n + sel[k].length, 0);
}
/** Effektive Strichstärke und Farbe über die gewählten Wände/Decken/2D-Elemente. */
+1 -1
View File
@@ -23,7 +23,7 @@ export function openObjectSettings(deps: ObjectSettingsDeps): boolean {
const sel = selectionInfoFor(project, selection);
let target = objectSettingsTarget(sel, deps.activeTool, isGridDrawing(sel?.kind === "drawing2d" ? sel.id : undefined));
// Baum, Lage-Darstellung und Schnittlinie sind keine `SelectionInfo`, haben aber ihre Felder in der Objekt-Info.
if (!target && (selection.trees.length > 0 || selection.site.length > 0 || selection.sectionLines.length > 0)) {
if (!target && (selection.trees.length > 0 || selection.cameras.length > 0 || selection.site.length > 0 || selection.sectionLines.length > 0)) {
target = { group: selection.sectionLines.length > 0 ? "sectionLine" : null };
}
if (!target) return false;
+3
View File
@@ -390,6 +390,8 @@ export interface ProjectSlice {
moveExcavationGrip: (id: string, index: number, pt: Vec2) => void;
/** [176] Griff einer Schnittlinie: 0 = Anfang, dann die Knickpunkte, zuletzt das Ende. */
moveSectionLineGrip: (id: string, index: number, pt: Vec2, coalesceKey?: string) => void;
/** [213] Griff einer Kamera: 0 = Standpunkt, 1 = Ziel, 2 = Bildwinkel/Sichtbreite. */
moveCameraGrip: (id: string, index: number, pt: Vec2) => void;
/** [176] Knick in Segment `seg` (Mittel-Griff) einfügen; `coalesceKey` fasst den anschliessenden Zug zusammen. */
insertSectionBend: (id: string, seg: number, pt: Vec2, coalesceKey?: string) => void;
/** [176] Knick löschen (`index` wie bei {@link moveSectionLineGrip}; Anfang/Ende lassen sich nicht löschen). */
@@ -1296,6 +1298,7 @@ export function createProjectSlice(
moveExcavationGrip: (id, index, pt) => applyGrip({ op: "excavationGrip", id, index, pt: gripPt(pt) }, `moveExcavationGrip:${id}:${index}`),
moveSectionLineGrip: (id, index, pt, coalesceKey) =>
applyGrip({ op: "sectionLineGrip", id, index, pt: gripPt(pt) }, coalesceKey ?? `moveSectionLineGrip:${id}:${index}`),
moveCameraGrip: (id, index, pt) => applyGrip({ op: "cameraGrip", id, index, pt: gripPt(pt) }, `moveCameraGrip:${id}:${index}`),
insertSectionBend: (id, seg, pt, coalesceKey) => applyGrip({ op: "sectionBendInsert", id, seg, pt: gripPt(pt) }, coalesceKey),
deleteSectionBend: (id, index) => applyGrip({ op: "sectionBendDelete", id, index }),
moveRingVertex: (kind, id, index, pt, coalesceKey) => {
+6
View File
@@ -39,6 +39,8 @@ export interface Selection {
site: string[];
/** [149] Bäume (`Project.trees`). */
trees: string[];
/** [213] Kameras (`Project.cameras`). */
cameras: string[];
/**
* Gewählte Gruppen — rein informativ (Bounding-Box, Doppelklick-Ziel); die
* Mitglieder stehen zusätzlich in den übrigen Arten (s. `groupActions.ts`).
@@ -63,6 +65,7 @@ export const SELECTION_KINDS: readonly SelectionKind[] = [
"sectionLines",
"site",
"trees",
"cameras",
"groups",
];
@@ -184,6 +187,8 @@ export interface SelectionIdLists {
groupIds: string[];
/** [149] Bäume (nicht gruppierbar; Zwischenablage, Nachauswahl). */
treeIds?: string[];
/** [213] Kameras (nicht gruppierbar). */
cameraIds?: string[];
}
const ID_LIST_KEYS: [SelectionKind, keyof SelectionIdLists][] = [
@@ -200,6 +205,7 @@ const ID_LIST_KEYS: [SelectionKind, keyof SelectionIdLists][] = [
["sectionLines", "sectionLineIds"],
["groups", "groupIds"],
["trees", "treeIds"],
["cameras", "cameraIds"],
];
/** Auswahl → `…Ids`-Listen (passt strukturell auf `GroupMembership` und `BcfSelection`). */
+1 -1
View File
@@ -63,5 +63,5 @@ export function hideSelectionIn3d(): void {
const ids = selectionIds3d(st.selection);
if (!ids.length) return;
setView3dFilter(hideSelection3d(getView3dFilter(), ids));
st.setSelection(clearKinds("walls", "ceilings", "openings", "stairs", "solids", "columns", "roofs", "contextObjects", "trees", "drawings", "groups"));
st.setSelection(clearKinds("walls", "ceilings", "openings", "stairs", "solids", "columns", "roofs", "contextObjects", "trees", "cameras", "drawings", "groups"));
}
+14
View File
@@ -51,6 +51,7 @@ import { getPlanViewport, subscribePlanViewport } from "./planViewport";
import { growRect, meshGripIndices } from "../core";
import { patchItem, verticalExtents } from "../core";
import { treeGripPatch, treeGripPoints } from "./treeGrips";
import { cameraGripPoints } from "../core";
import type { Selection } from "./selection";
export interface GripEditFieldsState {
@@ -209,6 +210,9 @@ export function useGripEditing(opts: {
const meshViewport = useSyncExternalStore(subscribePlanViewport, () => (selectedMesh && selectedMesh.positions.length / 3 > 600 ? getPlanViewport() : null));
const selectedTreeId = single(selection, "trees");
const selectedTree = selectedTreeId ? (project.trees ?? []).find((x) => x.id === selectedTreeId) : undefined;
// [213] Kamera: Griffe an Standpunkt, Ziel und Sichtkegel-Rand (Bildwinkel); nur auf dem Geschoss der Kamera.
const selectedCameraId = single(selection, "cameras");
const selectedCamera = selectedCameraId ? (project.cameras ?? []).find((x) => x.id === selectedCameraId && x.floorId === levelId) : undefined;
// [176] Schnitt-/Ansichtslinie im Grundriss: Griffe an Anfang, Knickpunkten (`bendPoints`) und Ende.
const selectedSectionLineId = single(selection, "sectionLines");
const selectedSectionLine = modelEditable && selectedSectionLineId
@@ -510,6 +514,11 @@ export function useGripEditing(opts: {
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
return pts;
}
if (selectedCamera && modelEditable && !selectedCamera.locked) {
const pts = cameraGripPoints(selectedCamera, scaleDenominator);
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
return pts;
}
if (selectedTree && modelEditable && !selectedTree.locked) {
const pts = treeGrips(selectedTree);
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
@@ -1238,6 +1247,11 @@ export function useGripEditing(opts: {
else if (st) moveStairBy(st.id, sub(pt, stairMoveHandle(st)));
return;
}
// [213] Kamera: Standpunkt, Ziel bzw. Sichtkegel-Rand live (Kern `camera::grip_edit`), ein Undo-Schritt je Zug.
if (selectedCamera) {
if (!selectedCamera.locked) storeState().moveCameraGrip(selectedCamera.id, index, pt);
return;
}
// [149] Baum: Stammmitte, Kronenrand bzw. Beschriftung live, ein Undo-Schritt je Zug (gleicher coalesceKey).
if (selectedTree) {
const tr = selectedTree;
+7 -1
View File
@@ -215,6 +215,7 @@ export function useMouseSelectionHandlers(opts: {
context: "contextObjects",
site: "site",
tree: "trees",
camera: "cameras",
} as const satisfies Record<string, SelectionKind>;
type Kind = keyof typeof channels;
const target: { kind: Kind; id: string } | null = sel.sectionLineId
@@ -235,6 +236,8 @@ export function useMouseSelectionHandlers(opts: {
? { kind: "solid", id: sel.extrudedSolidId }
: sel.treeId
? { kind: "tree", id: sel.treeId }
: sel.cameraId
? { kind: "camera", id: sel.cameraId }
: sel.columnId
? { kind: "column", id: sel.columnId }
: sel.roofId
@@ -301,7 +304,9 @@ export function useMouseSelectionHandlers(opts: {
? ["site", sel.siteId]
: sel.treeId
? ["trees", sel.treeId]
: null;
: sel.cameraId
? ["cameras", sel.cameraId]
: null;
setSelection({ ...clearKinds(), groups: [], ...(one ? { [one[0]]: [one[1]] } : {}) });
};
// Links-Drag (Marquee) im Grundriss: die getroffene Wand-MENGE übernehmen
@@ -353,6 +358,7 @@ export function useMouseSelectionHandlers(opts: {
stairs: expanded.stairIds,
rooms: expanded.roomIds,
trees: expanded.treeIds,
cameras: sel.cameraIds ?? [],
groups: groupIds,
});
};
+3
View File
@@ -151,6 +151,8 @@ export function useSelectionCommands(opts: {
const ctxids = new Set(selection.contextObjects);
// [149] Bäume (gesperrte bleiben).
const treeids = new Set(selection.trees.filter((id) => !(project.trees ?? []).find((t) => t.id === id)?.locked));
// [213] Kameras (gesperrte bleiben).
const camids = new Set(selection.cameras.filter((id) => !(project.cameras ?? []).find((c) => c.id === id)?.locked));
// [193] Abgeleitete Lage-Darstellung (Schatten, Baurecht) ist kein Element: Entf blendet sie aus
// (`show: false`; über die Lage-Panels wieder einschaltbar).
const siteHide: ReturnType<typeof fieldOps> = [];
@@ -175,6 +177,7 @@ export function useSelectionCommands(opts: {
...removeItems(p, "openings", (o) => oids.has(o.id) || wids.has(o.hostWallId) || (!!o.hostRoofId && rfids.has(o.hostRoofId)) || (!!o.hostCeilingId && cids.has(o.hostCeilingId))),
...removeItems(p, "context", ctxids),
...removeItems(p, "trees", treeids),
...removeItems(p, "cameras", camids),
]),
);
};