@pascal-app/editor 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -7
- package/src/components/editor/bottom-sheet.tsx +149 -0
- package/src/components/editor/custom-camera-controls.tsx +75 -7
- package/src/components/editor/editor-layout-mobile.tsx +264 -0
- package/src/components/editor/editor-layout-v2.tsx +29 -0
- package/src/components/editor/first-person/build-collider-world.ts +365 -0
- package/src/components/editor/first-person/bvh-ecctrl.tsx +795 -0
- package/src/components/editor/first-person-controls.tsx +496 -143
- package/src/components/editor/floating-action-menu.tsx +281 -83
- package/src/components/editor/floating-building-action-menu.tsx +4 -3
- package/src/components/editor/floorplan-background-selection.ts +113 -0
- package/src/components/editor/floorplan-panel.tsx +10442 -3275
- package/src/components/editor/index.tsx +270 -20
- package/src/components/editor/node-action-menu.tsx +14 -1
- package/src/components/editor/selection-manager.tsx +766 -12
- package/src/components/editor/site-edge-labels.tsx +9 -3
- package/src/components/editor/thumbnail-generator.tsx +350 -157
- package/src/components/editor/use-floorplan-background-placement.ts +257 -0
- package/src/components/editor/use-floorplan-hit-testing.ts +171 -0
- package/src/components/editor/use-floorplan-scene-data.ts +189 -0
- package/src/components/editor/wall-measurement-label.tsx +377 -58
- package/src/components/editor-2d/floorplan-action-menu-layer.tsx +95 -0
- package/src/components/editor-2d/floorplan-cursor-indicator-overlay.tsx +160 -0
- package/src/components/editor-2d/floorplan-hotkey-handlers.tsx +92 -0
- package/src/components/editor-2d/renderers/floorplan-draft-layer.tsx +119 -0
- package/src/components/editor-2d/renderers/floorplan-marquee-layer.tsx +58 -0
- package/src/components/editor-2d/renderers/floorplan-measurements-layer.tsx +197 -0
- package/src/components/editor-2d/renderers/floorplan-roof-layer.tsx +113 -0
- package/src/components/editor-2d/renderers/floorplan-stair-layer.tsx +474 -0
- package/src/components/editor-2d/svg-paths.ts +119 -0
- package/src/components/systems/ceiling/ceiling-selection-affordance-system.tsx +272 -0
- package/src/components/systems/roof/roof-edit-system.tsx +5 -5
- package/src/components/tools/ceiling/ceiling-boundary-editor.tsx +1 -0
- package/src/components/tools/ceiling/ceiling-hole-editor.tsx +2 -0
- package/src/components/tools/ceiling/ceiling-tool.tsx +5 -5
- package/src/components/tools/ceiling/move-ceiling-tool.tsx +257 -0
- package/src/components/tools/column/column-tool.tsx +97 -0
- package/src/components/tools/column/move-column-tool.tsx +105 -0
- package/src/components/tools/door/door-tool.tsx +19 -0
- package/src/components/tools/door/move-door-tool.tsx +38 -8
- package/src/components/tools/fence/curve-fence-tool.tsx +179 -0
- package/src/components/tools/fence/fence-drafting.ts +27 -8
- package/src/components/tools/fence/fence-tool.tsx +159 -3
- package/src/components/tools/fence/move-fence-endpoint-tool.tsx +438 -0
- package/src/components/tools/fence/move-fence-tool.tsx +102 -27
- package/src/components/tools/item/move-tool.tsx +19 -1
- package/src/components/tools/item/placement-math.ts +44 -7
- package/src/components/tools/item/placement-strategies.ts +111 -33
- package/src/components/tools/item/placement-types.ts +7 -0
- package/src/components/tools/item/use-draft-node.ts +2 -0
- package/src/components/tools/item/use-placement-coordinator.tsx +701 -61
- package/src/components/tools/roof/move-roof-tool.tsx +111 -43
- package/src/components/tools/shared/polygon-editor.tsx +244 -29
- package/src/components/tools/shared/segment-angle.ts +156 -0
- package/src/components/tools/slab/move-slab-tool.tsx +182 -0
- package/src/components/tools/slab/slab-boundary-editor.tsx +1 -0
- package/src/components/tools/slab/slab-hole-editor.tsx +2 -0
- package/src/components/tools/spawn/move-spawn-tool.tsx +101 -0
- package/src/components/tools/spawn/spawn-tool.tsx +130 -0
- package/src/components/tools/stair/stair-tool.tsx +11 -3
- package/src/components/tools/tool-manager.tsx +30 -3
- package/src/components/tools/wall/curve-wall-tool.tsx +176 -0
- package/src/components/tools/wall/move-wall-endpoint-tool.tsx +423 -0
- package/src/components/tools/wall/move-wall-tool.tsx +356 -0
- package/src/components/tools/wall/wall-drafting.ts +348 -17
- package/src/components/tools/wall/wall-tool.tsx +134 -2
- package/src/components/tools/window/move-window-tool.tsx +28 -0
- package/src/components/tools/window/window-tool.tsx +17 -0
- package/src/components/ui/action-menu/camera-actions.tsx +37 -33
- package/src/components/ui/action-menu/control-modes.tsx +37 -5
- package/src/components/ui/action-menu/index.tsx +91 -1
- package/src/components/ui/action-menu/structure-tools.tsx +2 -0
- package/src/components/ui/action-menu/view-toggles.tsx +424 -35
- package/src/components/ui/command-palette/editor-commands.tsx +27 -5
- package/src/components/ui/command-palette/index.tsx +0 -1
- package/src/components/ui/controls/material-picker.tsx +189 -169
- package/src/components/ui/controls/slider-control.tsx +88 -26
- package/src/components/ui/floating-level-selector.tsx +286 -55
- package/src/components/ui/helpers/helper-manager.tsx +5 -0
- package/src/components/ui/item-catalog/catalog-items.tsx +1121 -1219
- package/src/components/ui/item-catalog/item-catalog.tsx +42 -175
- package/src/components/ui/level-duplicate-dialog.tsx +115 -0
- package/src/components/ui/panels/ceiling-panel.tsx +47 -27
- package/src/components/ui/panels/column-panel.tsx +715 -0
- package/src/components/ui/panels/door-panel.tsx +986 -294
- package/src/components/ui/panels/fence-panel.tsx +55 -12
- package/src/components/ui/panels/item-panel.tsx +5 -5
- package/src/components/ui/panels/mobile-panel-sheet.tsx +108 -0
- package/src/components/ui/panels/mobile-selection-bar.tsx +100 -0
- package/src/components/ui/panels/node-display.ts +39 -0
- package/src/components/ui/panels/paint-panel.tsx +138 -0
- package/src/components/ui/panels/panel-manager.tsx +241 -30
- package/src/components/ui/panels/panel-wrapper.tsx +48 -39
- package/src/components/ui/panels/reference-panel.tsx +243 -9
- package/src/components/ui/panels/roof-panel.tsx +30 -62
- package/src/components/ui/panels/roof-segment-panel.tsx +8 -23
- package/src/components/ui/panels/slab-panel.tsx +46 -24
- package/src/components/ui/panels/spawn-panel.tsx +155 -0
- package/src/components/ui/panels/stair-panel.tsx +117 -69
- package/src/components/ui/panels/stair-segment-panel.tsx +13 -27
- package/src/components/ui/panels/wall-panel.tsx +71 -17
- package/src/components/ui/panels/window-panel.tsx +665 -146
- package/src/components/ui/sidebar/mobile-tab-bar.tsx +46 -0
- package/src/components/ui/sidebar/panels/settings-panel/keyboard-shortcuts-dialog.tsx +2 -2
- package/src/components/ui/sidebar/panels/site-panel/building-tree-node.tsx +9 -5
- package/src/components/ui/sidebar/panels/site-panel/ceiling-tree-node.tsx +7 -3
- package/src/components/ui/sidebar/panels/site-panel/column-tree-node.tsx +77 -0
- package/src/components/ui/sidebar/panels/site-panel/door-tree-node.tsx +7 -3
- package/src/components/ui/sidebar/panels/site-panel/fence-tree-node.tsx +7 -3
- package/src/components/ui/sidebar/panels/site-panel/index.tsx +138 -56
- package/src/components/ui/sidebar/panels/site-panel/item-tree-node.tsx +7 -3
- package/src/components/ui/sidebar/panels/site-panel/level-tree-node.tsx +9 -5
- package/src/components/ui/sidebar/panels/site-panel/roof-tree-node.tsx +7 -3
- package/src/components/ui/sidebar/panels/site-panel/slab-tree-node.tsx +7 -3
- package/src/components/ui/sidebar/panels/site-panel/spawn-tree-node.tsx +82 -0
- package/src/components/ui/sidebar/panels/site-panel/stair-tree-node.tsx +7 -3
- package/src/components/ui/sidebar/panels/site-panel/tree-node-actions.tsx +3 -3
- package/src/components/ui/sidebar/panels/site-panel/tree-node.tsx +12 -6
- package/src/components/ui/sidebar/panels/site-panel/wall-tree-node.tsx +7 -3
- package/src/components/ui/sidebar/panels/site-panel/window-tree-node.tsx +7 -3
- package/src/components/ui/sidebar/panels/site-panel/zone-tree-node.tsx +15 -8
- package/src/components/ui/sidebar/tab-bar.tsx +3 -0
- package/src/components/ui/viewer-toolbar.tsx +96 -2
- package/src/components/viewer-overlay.tsx +25 -19
- package/src/hooks/use-auto-frame.ts +45 -0
- package/src/hooks/use-contextual-tools.ts +14 -13
- package/src/hooks/use-keyboard.ts +67 -9
- package/src/hooks/use-mobile.ts +12 -12
- package/src/index.tsx +2 -1
- package/src/lib/door-interaction.ts +88 -0
- package/src/lib/floorplan/geometry.ts +263 -0
- package/src/lib/floorplan/index.ts +38 -0
- package/src/lib/floorplan/items.ts +179 -0
- package/src/lib/floorplan/selection-tool.ts +231 -0
- package/src/lib/floorplan/stairs.ts +478 -0
- package/src/lib/floorplan/types.ts +57 -0
- package/src/lib/floorplan/walls.ts +23 -0
- package/src/lib/guide-events.ts +10 -0
- package/src/lib/history.ts +20 -0
- package/src/lib/level-duplication.test.ts +72 -0
- package/src/lib/level-duplication.ts +153 -0
- package/src/lib/local-guide-image.ts +42 -0
- package/src/lib/material-paint.ts +284 -0
- package/src/lib/roof-duplication.ts +214 -0
- package/src/lib/scene-bounds.test.ts +183 -0
- package/src/lib/scene-bounds.ts +169 -0
- package/src/lib/sfx-player.ts +96 -13
- package/src/lib/stair-duplication.ts +126 -0
- package/src/lib/window-interaction.ts +86 -0
- package/src/store/use-editor.tsx +279 -15
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { type AnyNodeId, emitter, useScene } from '@pascal-app/core'
|
|
2
2
|
import { useViewer } from '@pascal-app/viewer'
|
|
3
3
|
import { useEffect } from 'react'
|
|
4
|
+
import { closeDoorOpenState, toggleDoorOpenState } from '../lib/door-interaction'
|
|
5
|
+
import { runRedo, runUndo } from '../lib/history'
|
|
4
6
|
import { sfxEmitter } from '../lib/sfx-bus'
|
|
7
|
+
import { closeWindowOpenState, toggleWindowOpenState } from '../lib/window-interaction'
|
|
5
8
|
import useEditor from '../store/use-editor'
|
|
6
9
|
|
|
7
10
|
// Tools call this in their onCancel handler when they have an active mid-action to cancel,
|
|
@@ -11,8 +14,18 @@ export const markToolCancelConsumed = () => {
|
|
|
11
14
|
_toolCancelConsumed = true
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
export const useKeyboard = ({
|
|
17
|
+
export const useKeyboard = ({
|
|
18
|
+
isVersionPreviewMode = false,
|
|
19
|
+
disabled = false,
|
|
20
|
+
}: {
|
|
21
|
+
isVersionPreviewMode?: boolean
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
} = {}) => {
|
|
15
24
|
useEffect(() => {
|
|
25
|
+
if (disabled) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
const handleKeyDown = (e: KeyboardEvent) => {
|
|
17
30
|
// Don't handle shortcuts if user is typing in an input
|
|
18
31
|
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
|
|
@@ -20,9 +33,6 @@ export const useKeyboard = ({ isVersionPreviewMode = false } = {}) => {
|
|
|
20
33
|
}
|
|
21
34
|
|
|
22
35
|
if (e.key === 'Escape') {
|
|
23
|
-
// If in walkthrough mode, let WalkthroughControls handle ESC
|
|
24
|
-
if (useViewer.getState().walkthroughMode) return
|
|
25
|
-
|
|
26
36
|
e.preventDefault()
|
|
27
37
|
_toolCancelConsumed = false
|
|
28
38
|
emitter.emit('tool:cancel')
|
|
@@ -88,14 +98,21 @@ export const useKeyboard = ({ isVersionPreviewMode = false } = {}) => {
|
|
|
88
98
|
if (isVersionPreviewMode) return
|
|
89
99
|
e.preventDefault()
|
|
90
100
|
useEditor.getState().setMode('delete')
|
|
101
|
+
} else if (e.key === 'p' && !e.metaKey && !e.ctrlKey) {
|
|
102
|
+
if (isVersionPreviewMode) return
|
|
103
|
+
e.preventDefault()
|
|
104
|
+
useEditor.getState().primeMaterialPaintFromSelection()
|
|
105
|
+
useEditor.getState().setPhase('structure')
|
|
106
|
+
useEditor.getState().setStructureLayer('elements')
|
|
107
|
+
useEditor.getState().setMode('material-paint')
|
|
91
108
|
} else if (e.key === 'z' && (e.metaKey || e.ctrlKey)) {
|
|
92
109
|
if (isVersionPreviewMode) return
|
|
93
110
|
e.preventDefault()
|
|
94
|
-
|
|
111
|
+
runUndo()
|
|
95
112
|
} else if (e.key === 'Z' && e.shiftKey && (e.metaKey || e.ctrlKey)) {
|
|
96
113
|
if (isVersionPreviewMode) return
|
|
97
114
|
e.preventDefault()
|
|
98
|
-
|
|
115
|
+
runRedo()
|
|
99
116
|
} else if (e.key === 'ArrowUp' && (e.metaKey || e.ctrlKey)) {
|
|
100
117
|
e.preventDefault()
|
|
101
118
|
const { buildingId, levelId } = useViewer.getState().selection
|
|
@@ -130,10 +147,31 @@ export const useKeyboard = ({ isVersionPreviewMode = false } = {}) => {
|
|
|
130
147
|
}
|
|
131
148
|
} else if ((e.key === 'r' || e.key === 'R') && !isVersionPreviewMode) {
|
|
132
149
|
// Rotate selected node clockwise if it supports rotation (items, roofs, etc.)
|
|
150
|
+
// Operable doors/windows use R to toggle their open/closed state.
|
|
133
151
|
const selectedNodeIds = useViewer.getState().selection.selectedIds as AnyNodeId[]
|
|
134
152
|
if (selectedNodeIds.length === 1) {
|
|
135
153
|
const node = useScene.getState().nodes[selectedNodeIds[0]!]
|
|
136
|
-
if (node
|
|
154
|
+
if (node?.type === 'door') {
|
|
155
|
+
e.preventDefault()
|
|
156
|
+
if (node.openingKind !== 'opening') {
|
|
157
|
+
toggleDoorOpenState(node.id)
|
|
158
|
+
sfxEmitter.emit('sfx:item-rotate')
|
|
159
|
+
}
|
|
160
|
+
} else if (
|
|
161
|
+
node?.type === 'window' &&
|
|
162
|
+
node.openingKind !== 'opening' &&
|
|
163
|
+
(node.windowType === 'sliding' ||
|
|
164
|
+
node.windowType === 'casement' ||
|
|
165
|
+
node.windowType === 'awning' ||
|
|
166
|
+
node.windowType === 'hopper' ||
|
|
167
|
+
node.windowType === 'single-hung' ||
|
|
168
|
+
node.windowType === 'double-hung' ||
|
|
169
|
+
node.windowType === 'louvered')
|
|
170
|
+
) {
|
|
171
|
+
e.preventDefault()
|
|
172
|
+
toggleWindowOpenState(node.id)
|
|
173
|
+
sfxEmitter.emit('sfx:item-rotate')
|
|
174
|
+
} else if (node && 'rotation' in node) {
|
|
137
175
|
e.preventDefault()
|
|
138
176
|
const ROTATION_STEP = Math.PI / 4
|
|
139
177
|
|
|
@@ -153,7 +191,27 @@ export const useKeyboard = ({ isVersionPreviewMode = false } = {}) => {
|
|
|
153
191
|
const selectedNodeIds = useViewer.getState().selection.selectedIds as AnyNodeId[]
|
|
154
192
|
if (selectedNodeIds.length === 1) {
|
|
155
193
|
const node = useScene.getState().nodes[selectedNodeIds[0]!]
|
|
156
|
-
if (node
|
|
194
|
+
if (node?.type === 'door') {
|
|
195
|
+
e.preventDefault()
|
|
196
|
+
if (node.openingKind !== 'opening') {
|
|
197
|
+
closeDoorOpenState(node.id)
|
|
198
|
+
sfxEmitter.emit('sfx:item-rotate')
|
|
199
|
+
}
|
|
200
|
+
} else if (
|
|
201
|
+
node?.type === 'window' &&
|
|
202
|
+
node.openingKind !== 'opening' &&
|
|
203
|
+
(node.windowType === 'sliding' ||
|
|
204
|
+
node.windowType === 'casement' ||
|
|
205
|
+
node.windowType === 'awning' ||
|
|
206
|
+
node.windowType === 'hopper' ||
|
|
207
|
+
node.windowType === 'single-hung' ||
|
|
208
|
+
node.windowType === 'double-hung' ||
|
|
209
|
+
node.windowType === 'louvered')
|
|
210
|
+
) {
|
|
211
|
+
e.preventDefault()
|
|
212
|
+
closeWindowOpenState(node.id)
|
|
213
|
+
sfxEmitter.emit('sfx:item-rotate')
|
|
214
|
+
} else if (node && 'rotation' in node) {
|
|
157
215
|
e.preventDefault()
|
|
158
216
|
const ROTATION_STEP = Math.PI / 4
|
|
159
217
|
|
|
@@ -212,7 +270,7 @@ export const useKeyboard = ({ isVersionPreviewMode = false } = {}) => {
|
|
|
212
270
|
}
|
|
213
271
|
window.addEventListener('keydown', handleKeyDown)
|
|
214
272
|
return () => window.removeEventListener('keydown', handleKeyDown)
|
|
215
|
-
}, [isVersionPreviewMode])
|
|
273
|
+
}, [disabled, isVersionPreviewMode])
|
|
216
274
|
|
|
217
275
|
return null
|
|
218
276
|
}
|
package/src/hooks/use-mobile.ts
CHANGED
|
@@ -2,18 +2,18 @@ import * as React from 'react'
|
|
|
2
2
|
|
|
3
3
|
const MOBILE_BREAKPOINT = 768
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
const subscribe = (callback: () => void): (() => void) => {
|
|
6
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
|
7
|
+
mql.addEventListener('change', callback)
|
|
8
|
+
return () => mql.removeEventListener('change', callback)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const getClientSnapshot = (): boolean => window.innerWidth < MOBILE_BREAKPOINT
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
|
12
|
-
}
|
|
13
|
-
mql.addEventListener('change', onChange)
|
|
14
|
-
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
|
15
|
-
return () => mql.removeEventListener('change', onChange)
|
|
16
|
-
}, [])
|
|
13
|
+
// Server can't know the viewport — assume desktop. React's useSyncExternalStore
|
|
14
|
+
// reconciles the SSR / client snapshots without a hydration mismatch warning.
|
|
15
|
+
const getServerSnapshot = (): boolean => false
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
export function useIsMobile(): boolean {
|
|
18
|
+
return React.useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot)
|
|
19
19
|
}
|
package/src/index.tsx
CHANGED
|
@@ -15,11 +15,13 @@ export {
|
|
|
15
15
|
} from './components/ui/sidebar/panels/settings-panel'
|
|
16
16
|
export type { SitePanelProps } from './components/ui/sidebar/panels/site-panel'
|
|
17
17
|
export type { SidebarTab } from './components/ui/sidebar/tab-bar'
|
|
18
|
+
export { ViewerToolbarLeft, ViewerToolbarRight } from './components/ui/viewer-toolbar'
|
|
18
19
|
export type { PresetsAdapter, PresetsTab } from './contexts/presets-context'
|
|
19
20
|
export { PresetsProvider } from './contexts/presets-context'
|
|
20
21
|
export type { SaveStatus } from './hooks/use-auto-save'
|
|
21
22
|
export type { SceneGraph } from './lib/scene'
|
|
22
23
|
export { applySceneGraphToEditor } from './lib/scene'
|
|
24
|
+
export { triggerSFX } from './lib/sfx-bus'
|
|
23
25
|
export { default as useAudio } from './store/use-audio'
|
|
24
26
|
export { type CommandAction, useCommandRegistry } from './store/use-command-registry'
|
|
25
27
|
export type { FloorplanSelectionTool, SplitOrientation, ViewMode } from './store/use-editor'
|
|
@@ -30,4 +32,3 @@ export {
|
|
|
30
32
|
usePaletteViewRegistry,
|
|
31
33
|
} from './store/use-palette-view-registry'
|
|
32
34
|
export { useUploadStore } from './store/use-upload'
|
|
33
|
-
export { ViewerToolbarLeft, ViewerToolbarRight } from './components/ui/viewer-toolbar'
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AnyNodeId,
|
|
3
|
+
type DoorInteractiveState,
|
|
4
|
+
isOperationDoorType,
|
|
5
|
+
useInteractive,
|
|
6
|
+
useScene,
|
|
7
|
+
} from '@pascal-app/core'
|
|
8
|
+
|
|
9
|
+
export const DOOR_SWING_OPEN_ANGLE = Math.PI / 2
|
|
10
|
+
export const DOOR_TOGGLE_ANIMATION_MS = 520
|
|
11
|
+
|
|
12
|
+
export { isOperationDoorType }
|
|
13
|
+
|
|
14
|
+
type DoorOpenAnimationOptions = {
|
|
15
|
+
persist?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getDisplayedDoorValue(
|
|
19
|
+
doorId: AnyNodeId,
|
|
20
|
+
field: keyof DoorInteractiveState,
|
|
21
|
+
nodeValue: number | undefined,
|
|
22
|
+
) {
|
|
23
|
+
const interactive = useInteractive.getState()
|
|
24
|
+
const runtimeValue = interactive.doors[doorId]?.[field]
|
|
25
|
+
if (runtimeValue !== undefined) return runtimeValue
|
|
26
|
+
|
|
27
|
+
const queuedValue = interactive.doorAnimations[doorId]?.from
|
|
28
|
+
if (queuedValue !== undefined) return queuedValue
|
|
29
|
+
|
|
30
|
+
return nodeValue ?? 0
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function startDoorOpenAnimation(
|
|
34
|
+
doorId: AnyNodeId,
|
|
35
|
+
field: keyof DoorInteractiveState,
|
|
36
|
+
from: number,
|
|
37
|
+
to: number,
|
|
38
|
+
options?: DoorOpenAnimationOptions,
|
|
39
|
+
) {
|
|
40
|
+
useInteractive.getState().startDoorAnimation(doorId, {
|
|
41
|
+
field,
|
|
42
|
+
from,
|
|
43
|
+
to,
|
|
44
|
+
startedAt: null,
|
|
45
|
+
durationMs: DOOR_TOGGLE_ANIMATION_MS,
|
|
46
|
+
persist: options?.persist ?? true,
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function toggleDoorOpenState(doorId: AnyNodeId, options?: DoorOpenAnimationOptions) {
|
|
51
|
+
const node = useScene.getState().nodes[doorId]
|
|
52
|
+
if (node?.type !== 'door' || node.openingKind === 'opening') return
|
|
53
|
+
|
|
54
|
+
if (isOperationDoorType(node.doorType)) {
|
|
55
|
+
const currentOpenAmount = getDisplayedDoorValue(doorId, 'operationState', node.operationState)
|
|
56
|
+
startDoorOpenAnimation(
|
|
57
|
+
doorId,
|
|
58
|
+
'operationState',
|
|
59
|
+
currentOpenAmount,
|
|
60
|
+
currentOpenAmount >= 0.5 ? 0 : 1,
|
|
61
|
+
options,
|
|
62
|
+
)
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const currentSwingAngle = getDisplayedDoorValue(doorId, 'swingAngle', node.swingAngle)
|
|
67
|
+
startDoorOpenAnimation(
|
|
68
|
+
doorId,
|
|
69
|
+
'swingAngle',
|
|
70
|
+
currentSwingAngle,
|
|
71
|
+
currentSwingAngle >= DOOR_SWING_OPEN_ANGLE / 2 ? 0 : DOOR_SWING_OPEN_ANGLE,
|
|
72
|
+
options,
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function closeDoorOpenState(doorId: AnyNodeId, options?: DoorOpenAnimationOptions) {
|
|
77
|
+
const node = useScene.getState().nodes[doorId]
|
|
78
|
+
if (node?.type !== 'door' || node.openingKind === 'opening') return
|
|
79
|
+
|
|
80
|
+
if (isOperationDoorType(node.doorType)) {
|
|
81
|
+
const currentOpenAmount = getDisplayedDoorValue(doorId, 'operationState', node.operationState)
|
|
82
|
+
startDoorOpenAnimation(doorId, 'operationState', currentOpenAmount, 0, options)
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const currentSwingAngle = getDisplayedDoorValue(doorId, 'swingAngle', node.swingAngle)
|
|
87
|
+
startDoorOpenAnimation(doorId, 'swingAngle', currentSwingAngle, 0, options)
|
|
88
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import type { Point2D } from '@pascal-app/core'
|
|
2
|
+
import type { FloorplanLineSegment, FloorplanSelectionBounds } from './types'
|
|
3
|
+
|
|
4
|
+
export function clampPlanValue(value: number, min: number, max: number) {
|
|
5
|
+
return Math.min(Math.max(value, min), max)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function rotatePlanVector(x: number, y: number, rotation: number): [number, number] {
|
|
9
|
+
const cos = Math.cos(rotation)
|
|
10
|
+
const sin = Math.sin(rotation)
|
|
11
|
+
return [x * cos + y * sin, -x * sin + y * cos]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getRotatedRectanglePolygon(
|
|
15
|
+
center: Point2D,
|
|
16
|
+
width: number,
|
|
17
|
+
depth: number,
|
|
18
|
+
rotation: number,
|
|
19
|
+
): Point2D[] {
|
|
20
|
+
const halfWidth = width / 2
|
|
21
|
+
const halfDepth = depth / 2
|
|
22
|
+
const corners: Array<[number, number]> = [
|
|
23
|
+
[-halfWidth, -halfDepth],
|
|
24
|
+
[halfWidth, -halfDepth],
|
|
25
|
+
[halfWidth, halfDepth],
|
|
26
|
+
[-halfWidth, halfDepth],
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
return corners.map(([localX, localY]) => {
|
|
30
|
+
const [offsetX, offsetY] = rotatePlanVector(localX, localY, rotation)
|
|
31
|
+
return {
|
|
32
|
+
x: center.x + offsetX,
|
|
33
|
+
y: center.y + offsetY,
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function interpolatePlanPoint(start: Point2D, end: Point2D, t: number): Point2D {
|
|
39
|
+
return {
|
|
40
|
+
x: start.x + (end.x - start.x) * t,
|
|
41
|
+
y: start.y + (end.y - start.y) * t,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getPlanPointDistance(start: Point2D, end: Point2D): number {
|
|
46
|
+
return Math.hypot(end.x - start.x, end.y - start.y)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function movePlanPointTowards(start: Point2D, end: Point2D, distance: number): Point2D {
|
|
50
|
+
const totalDistance = getPlanPointDistance(start, end)
|
|
51
|
+
if (totalDistance <= Number.EPSILON || distance <= 0) {
|
|
52
|
+
return start
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return interpolatePlanPoint(start, end, Math.min(1, distance / totalDistance))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function getThickPlanLinePolygon(line: FloorplanLineSegment, thickness: number): Point2D[] {
|
|
59
|
+
const dx = line.end.x - line.start.x
|
|
60
|
+
const dy = line.end.y - line.start.y
|
|
61
|
+
const length = Math.hypot(dx, dy)
|
|
62
|
+
|
|
63
|
+
if (length <= Number.EPSILON || thickness <= 0) {
|
|
64
|
+
return [line.start, line.end, line.end, line.start]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const halfThickness = thickness / 2
|
|
68
|
+
const normalX = (-dy / length) * halfThickness
|
|
69
|
+
const normalY = (dx / length) * halfThickness
|
|
70
|
+
|
|
71
|
+
return [
|
|
72
|
+
{ x: line.start.x + normalX, y: line.start.y + normalY },
|
|
73
|
+
{ x: line.end.x + normalX, y: line.end.y + normalY },
|
|
74
|
+
{ x: line.end.x - normalX, y: line.end.y - normalY },
|
|
75
|
+
{ x: line.start.x - normalX, y: line.start.y - normalY },
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function getFloorplanSelectionBounds(
|
|
80
|
+
start: [number, number],
|
|
81
|
+
end: [number, number],
|
|
82
|
+
): FloorplanSelectionBounds {
|
|
83
|
+
return {
|
|
84
|
+
minX: Math.min(start[0], end[0]),
|
|
85
|
+
maxX: Math.max(start[0], end[0]),
|
|
86
|
+
minY: Math.min(start[1], end[1]),
|
|
87
|
+
maxY: Math.max(start[1], end[1]),
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function isPointInsideSelectionBounds(point: Point2D, bounds: FloorplanSelectionBounds) {
|
|
92
|
+
return (
|
|
93
|
+
point.x >= bounds.minX &&
|
|
94
|
+
point.x <= bounds.maxX &&
|
|
95
|
+
point.y >= bounds.minY &&
|
|
96
|
+
point.y <= bounds.maxY
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function isPointInsidePolygon(point: Point2D, polygon: Point2D[]) {
|
|
101
|
+
let isInside = false
|
|
102
|
+
|
|
103
|
+
for (
|
|
104
|
+
let currentIndex = 0, previousIndex = polygon.length - 1;
|
|
105
|
+
currentIndex < polygon.length;
|
|
106
|
+
previousIndex = currentIndex, currentIndex += 1
|
|
107
|
+
) {
|
|
108
|
+
const current = polygon[currentIndex]
|
|
109
|
+
const previous = polygon[previousIndex]
|
|
110
|
+
|
|
111
|
+
if (!(current && previous)) {
|
|
112
|
+
continue
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const intersects =
|
|
116
|
+
current.y > point.y !== previous.y > point.y &&
|
|
117
|
+
point.x <
|
|
118
|
+
((previous.x - current.x) * (point.y - current.y)) / (previous.y - current.y) + current.x
|
|
119
|
+
|
|
120
|
+
if (intersects) {
|
|
121
|
+
isInside = !isInside
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return isInside
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function isPointInsidePolygonWithHoles(
|
|
129
|
+
point: Point2D,
|
|
130
|
+
polygon: Point2D[],
|
|
131
|
+
holes: Point2D[][] = [],
|
|
132
|
+
) {
|
|
133
|
+
return (
|
|
134
|
+
isPointInsidePolygon(point, polygon) && !holes.some((hole) => isPointInsidePolygon(point, hole))
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function getLineOrientation(start: Point2D, end: Point2D, point: Point2D) {
|
|
139
|
+
return (end.x - start.x) * (point.y - start.y) - (end.y - start.y) * (point.x - start.x)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function isPointOnSegment(point: Point2D, start: Point2D, end: Point2D) {
|
|
143
|
+
const epsilon = 1e-9
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
Math.abs(getLineOrientation(start, end, point)) <= epsilon &&
|
|
147
|
+
point.x >= Math.min(start.x, end.x) - epsilon &&
|
|
148
|
+
point.x <= Math.max(start.x, end.x) + epsilon &&
|
|
149
|
+
point.y >= Math.min(start.y, end.y) - epsilon &&
|
|
150
|
+
point.y <= Math.max(start.y, end.y) + epsilon
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function doSegmentsIntersect(
|
|
155
|
+
firstStart: Point2D,
|
|
156
|
+
firstEnd: Point2D,
|
|
157
|
+
secondStart: Point2D,
|
|
158
|
+
secondEnd: Point2D,
|
|
159
|
+
) {
|
|
160
|
+
const orientation1 = getLineOrientation(firstStart, firstEnd, secondStart)
|
|
161
|
+
const orientation2 = getLineOrientation(firstStart, firstEnd, secondEnd)
|
|
162
|
+
const orientation3 = getLineOrientation(secondStart, secondEnd, firstStart)
|
|
163
|
+
const orientation4 = getLineOrientation(secondStart, secondEnd, firstEnd)
|
|
164
|
+
|
|
165
|
+
const hasProperIntersection =
|
|
166
|
+
((orientation1 > 0 && orientation2 < 0) || (orientation1 < 0 && orientation2 > 0)) &&
|
|
167
|
+
((orientation3 > 0 && orientation4 < 0) || (orientation3 < 0 && orientation4 > 0))
|
|
168
|
+
|
|
169
|
+
if (hasProperIntersection) {
|
|
170
|
+
return true
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
isPointOnSegment(secondStart, firstStart, firstEnd) ||
|
|
175
|
+
isPointOnSegment(secondEnd, firstStart, firstEnd) ||
|
|
176
|
+
isPointOnSegment(firstStart, secondStart, secondEnd) ||
|
|
177
|
+
isPointOnSegment(firstEnd, secondStart, secondEnd)
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function doesPolygonIntersectSelectionBounds(
|
|
182
|
+
polygon: Point2D[],
|
|
183
|
+
bounds: FloorplanSelectionBounds,
|
|
184
|
+
) {
|
|
185
|
+
if (polygon.length === 0) {
|
|
186
|
+
return false
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (polygon.some((point) => isPointInsideSelectionBounds(point, bounds))) {
|
|
190
|
+
return true
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const boundsCorners: [Point2D, Point2D, Point2D, Point2D] = [
|
|
194
|
+
{ x: bounds.minX, y: bounds.minY },
|
|
195
|
+
{ x: bounds.maxX, y: bounds.minY },
|
|
196
|
+
{ x: bounds.maxX, y: bounds.maxY },
|
|
197
|
+
{ x: bounds.minX, y: bounds.maxY },
|
|
198
|
+
]
|
|
199
|
+
|
|
200
|
+
if (boundsCorners.some((corner) => isPointInsidePolygon(corner, polygon))) {
|
|
201
|
+
return true
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const boundsEdges = [
|
|
205
|
+
[boundsCorners[0], boundsCorners[1]],
|
|
206
|
+
[boundsCorners[1], boundsCorners[2]],
|
|
207
|
+
[boundsCorners[2], boundsCorners[3]],
|
|
208
|
+
[boundsCorners[3], boundsCorners[0]],
|
|
209
|
+
] as const
|
|
210
|
+
|
|
211
|
+
for (let index = 0; index < polygon.length; index += 1) {
|
|
212
|
+
const start = polygon[index]
|
|
213
|
+
const end = polygon[(index + 1) % polygon.length]
|
|
214
|
+
|
|
215
|
+
if (!(start && end)) {
|
|
216
|
+
continue
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
for (const [edgeStart, edgeEnd] of boundsEdges) {
|
|
220
|
+
if (doSegmentsIntersect(start, end, edgeStart, edgeEnd)) {
|
|
221
|
+
return true
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return false
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function getDistanceToWallSegment(
|
|
230
|
+
point: Point2D,
|
|
231
|
+
start: [number, number],
|
|
232
|
+
end: [number, number],
|
|
233
|
+
) {
|
|
234
|
+
const dx = end[0] - start[0]
|
|
235
|
+
const dy = end[1] - start[1]
|
|
236
|
+
const lengthSquared = dx * dx + dy * dy
|
|
237
|
+
|
|
238
|
+
if (lengthSquared <= Number.EPSILON) {
|
|
239
|
+
return Math.hypot(point.x - start[0], point.y - start[1])
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const projection = clampPlanValue(
|
|
243
|
+
((point.x - start[0]) * dx + (point.y - start[1]) * dy) / lengthSquared,
|
|
244
|
+
0,
|
|
245
|
+
1,
|
|
246
|
+
)
|
|
247
|
+
const projectedX = start[0] + dx * projection
|
|
248
|
+
const projectedY = start[1] + dy * projection
|
|
249
|
+
|
|
250
|
+
return Math.hypot(point.x - projectedX, point.y - projectedY)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function pointMatchesWallPlanPoint(
|
|
254
|
+
point: Point2D | undefined,
|
|
255
|
+
planPoint: [number, number],
|
|
256
|
+
epsilon = 1e-6,
|
|
257
|
+
): boolean {
|
|
258
|
+
if (!point) {
|
|
259
|
+
return false
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return Math.abs(point.x - planPoint[0]) <= epsilon && Math.abs(point.y - planPoint[1]) <= epsilon
|
|
263
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export {
|
|
2
|
+
clampPlanValue,
|
|
3
|
+
doesPolygonIntersectSelectionBounds,
|
|
4
|
+
getDistanceToWallSegment,
|
|
5
|
+
getFloorplanSelectionBounds,
|
|
6
|
+
getPlanPointDistance,
|
|
7
|
+
getRotatedRectanglePolygon,
|
|
8
|
+
getThickPlanLinePolygon,
|
|
9
|
+
interpolatePlanPoint,
|
|
10
|
+
isPointInsidePolygon,
|
|
11
|
+
isPointInsidePolygonWithHoles,
|
|
12
|
+
isPointInsideSelectionBounds,
|
|
13
|
+
movePlanPointTowards,
|
|
14
|
+
pointMatchesWallPlanPoint,
|
|
15
|
+
rotatePlanVector,
|
|
16
|
+
} from './geometry'
|
|
17
|
+
export {
|
|
18
|
+
buildFloorplanItemEntry,
|
|
19
|
+
collectLevelDescendants,
|
|
20
|
+
getItemFloorplanTransform,
|
|
21
|
+
} from './items'
|
|
22
|
+
export {
|
|
23
|
+
buildFloorplanStairEntry,
|
|
24
|
+
computeFloorplanStairSegmentTransforms,
|
|
25
|
+
getFloorplanStairSegmentPolygon,
|
|
26
|
+
} from './stairs'
|
|
27
|
+
export type {
|
|
28
|
+
FloorplanItemEntry,
|
|
29
|
+
FloorplanLineSegment,
|
|
30
|
+
FloorplanNodeTransform,
|
|
31
|
+
FloorplanSelectionBounds,
|
|
32
|
+
FloorplanStairArrowEntry,
|
|
33
|
+
FloorplanStairEntry,
|
|
34
|
+
FloorplanStairSegmentEntry,
|
|
35
|
+
LevelDescendantMap,
|
|
36
|
+
StairSegmentTransform,
|
|
37
|
+
} from './types'
|
|
38
|
+
export { getFloorplanWall, getFloorplanWallThickness } from './walls'
|