@pascal-app/editor 1.0.0-beta.5 → 1.0.1
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/LICENSE +21 -0
- package/bunfig.toml +4 -0
- package/package.json +15 -8
- package/scripts/generate-print-golden-house.ts +89 -0
- package/src/components/editor/bake-exporter.tsx +5 -0
- package/src/components/editor/bake-thumbnail.tsx +4 -1
- package/src/components/editor/camera-dragging-lifecycle.test.ts +41 -0
- package/src/components/editor/camera-dragging-lifecycle.ts +10 -2
- package/src/components/editor/capture-camera-rig.tsx +59 -0
- package/src/components/editor/custom-camera-controls.tsx +20 -11
- package/src/components/editor/editor-layout-mobile.tsx +6 -6
- package/src/components/editor/editor-layout-v2.tsx +9 -2
- package/src/components/editor/export-manager.tsx +175 -33
- package/src/components/editor/first-person/build-collider-world.test.ts +30 -0
- package/src/components/editor/first-person-controls.tsx +180 -12
- package/src/components/editor/floating-action-menu.tsx +55 -51
- package/src/components/editor/floorplan-panel.tsx +99 -15
- package/src/components/editor/grid.tsx +12 -7
- package/src/components/editor/group-actions.ts +34 -50
- package/src/components/editor/group-move-3d.ts +51 -21
- package/src/components/editor/group-transform-shared.test.ts +78 -0
- package/src/components/editor/group-transform-shared.ts +74 -7
- package/src/components/editor/handles/handle-arrow-raycast.test.ts +86 -0
- package/src/components/editor/handles/handle-arrow.tsx +109 -48
- package/src/components/editor/handles/handle-placement.test.ts +111 -0
- package/src/components/editor/handles/handle-placement.ts +69 -0
- package/src/components/editor/handles/linear-resize-drag.ts +78 -0
- package/src/components/editor/handles/resize-snap.test.ts +46 -0
- package/src/components/editor/handles/resize-snap.ts +10 -1
- package/src/components/editor/handles/use-handle-drag.ts +23 -3
- package/src/components/editor/index.tsx +151 -24
- package/src/components/editor/node-action-menu.tsx +14 -1
- package/src/components/editor/node-arrow-handles.tsx +67 -119
- package/src/components/editor/selection-manager.tsx +153 -42
- package/src/components/editor/snapshot-capture-overlay.tsx +298 -39
- package/src/components/editor/snapshot-capture.test.ts +422 -0
- package/src/components/editor/snapshot-capture.ts +145 -0
- package/src/components/editor/thumbnail-generator.tsx +295 -239
- package/src/components/editor/use-floorplan-background-placement.ts +53 -5
- package/src/components/editor/wall-move-side-handles.tsx +299 -7
- package/src/components/editor-2d/floorplan-group-move.tsx +67 -33
- package/src/components/editor-2d/floorplan-registered-tool-layer.tsx +3 -1
- package/src/components/editor-2d/floorplan-registry-action-menu.tsx +12 -1
- package/src/components/editor-2d/floorplan-registry-move-overlay.tsx +129 -38
- package/src/components/editor-2d/renderers/floorplan-dimension-renderer.tsx +14 -1
- package/src/components/editor-2d/renderers/floorplan-geometry-renderer.test.tsx +16 -0
- package/src/components/editor-2d/renderers/floorplan-geometry-renderer.tsx +2 -0
- package/src/components/editor-2d/renderers/floorplan-placement-preview-layer.tsx +52 -3
- package/src/components/editor-2d/renderers/floorplan-registry-layer.test.ts +196 -1
- package/src/components/editor-2d/renderers/floorplan-registry-layer.tsx +226 -35
- package/src/components/procedural-items/inspector.tsx +223 -0
- package/src/components/systems/ceiling/ceiling-bracket-batch.test.ts +402 -0
- package/src/components/systems/ceiling/ceiling-bracket-batch.ts +371 -0
- package/src/components/systems/ceiling/ceiling-selection-affordance-system.test.ts +347 -0
- package/src/components/systems/ceiling/ceiling-selection-affordance-system.tsx +281 -305
- package/src/components/systems/ceiling/ceiling-system.tsx +3 -1
- package/src/components/systems/roof/roof-edit-system.test.tsx +120 -0
- package/src/components/systems/roof/roof-edit-system.tsx +10 -19
- package/src/components/systems/selection-affordance-manager.tsx +59 -9
- package/src/components/systems/selection-affordance-services.ts +19 -0
- package/src/components/systems/stair/stair-edit-system.tsx +5 -2
- package/src/components/tools/fence/fence-drafting.test.ts +100 -0
- package/src/components/tools/fence/fence-drafting.ts +6 -25
- package/src/components/tools/item/draft-creation.test.ts +12 -0
- package/src/components/tools/item/draft-creation.ts +10 -0
- package/src/components/tools/item/face-host-commit.test.ts +65 -0
- package/src/components/tools/item/face-host-commit.ts +56 -0
- package/src/components/tools/item/face-host-preview.test.ts +77 -0
- package/src/components/tools/item/face-host-preview.ts +82 -0
- package/src/components/tools/item/item-surface-placement.test.ts +175 -0
- package/src/components/tools/item/item-surface-strategy-resolver.test.ts +210 -0
- package/src/components/tools/item/move-tool.tsx +4 -3
- package/src/components/tools/item/placement-math.test.ts +11 -1
- package/src/components/tools/item/placement-math.ts +0 -20
- package/src/components/tools/item/placement-strategies.test.ts +331 -4
- package/src/components/tools/item/placement-strategies.ts +304 -171
- package/src/components/tools/item/placement-surface.test.ts +61 -0
- package/src/components/tools/item/placement-surface.ts +24 -0
- package/src/components/tools/item/placement-types.ts +10 -0
- package/src/components/tools/item/shelf-surface-strategy-resolver.test.ts +257 -0
- package/src/components/tools/item/test-face-host.ts +121 -0
- package/src/components/tools/item/use-draft-node.test.tsx +336 -0
- package/src/components/tools/item/use-draft-node.ts +116 -44
- package/src/components/tools/item/use-placement-coordinator.tsx +672 -256
- package/src/components/tools/registered-tool-install-lifecycle.test.tsx +256 -0
- package/src/components/tools/registry/item-surface-child-frame.test.ts +90 -0
- package/src/components/tools/registry/item-surface-move.test.ts +501 -0
- package/src/components/tools/registry/item-surface-move.ts +441 -0
- package/src/components/tools/registry/item-surface-resolver.test.ts +257 -0
- package/src/components/tools/registry/move-registry-node-tool.test.ts +10 -0
- package/src/components/tools/registry/move-registry-node-tool.tsx +505 -164
- package/src/components/tools/registry-tool-context.tsx +30 -0
- package/src/components/tools/select/box-select-tool.tsx +3 -1
- package/src/components/tools/select/marquee-footprint.test.ts +53 -0
- package/src/components/tools/select/marquee-footprint.ts +29 -0
- package/src/components/tools/shared/placement-box.tsx +57 -7
- package/src/components/tools/shared/placement-dimension-guides.tsx +121 -0
- package/src/components/tools/shared/pointer-support-cap.test.ts +319 -17
- package/src/components/tools/shared/pointer-support-cap.ts +56 -17
- package/src/components/tools/shared/shelf-stickiness.ts +54 -0
- package/src/components/tools/shared/surface-hit.test.ts +56 -0
- package/src/components/tools/shared/surface-hit.ts +23 -0
- package/src/components/tools/shared/surface-rejection.test.tsx +106 -0
- package/src/components/tools/shared/surface-rejection.tsx +29 -0
- package/src/components/tools/site/terrain-sculpt-grid.tsx +9 -5
- package/src/components/tools/site/terrain-sculpt-tool.tsx +1 -1
- package/src/components/tools/stair/stair-tool.tsx +127 -74
- package/src/components/tools/tool-manager.tsx +25 -8
- package/src/components/tools/wall/wall-drafting.test.ts +320 -2
- package/src/components/tools/wall/wall-drafting.ts +23 -114
- package/src/components/tools/zone/zone-tool.tsx +13 -4
- package/src/components/ui/action-menu/control-modes.tsx +9 -6
- package/src/components/ui/action-menu/index.tsx +11 -1
- package/src/components/ui/command-palette/editor-commands.tsx +63 -13
- package/src/components/ui/command-palette/index.tsx +7 -2
- package/src/components/ui/controls/material-paint-panel.tsx +6 -4
- package/src/components/ui/controls/material-picker.tsx +4 -4
- package/src/components/ui/controls/metric-control.tsx +29 -13
- package/src/components/ui/controls/scene-material-list.tsx +6 -5
- package/src/components/ui/controls/segmented-control.tsx +8 -1
- package/src/components/ui/controls/slider-control.tsx +44 -21
- package/src/components/ui/controls/toggle-control.tsx +18 -5
- package/src/components/ui/controls/tool-options-panel.tsx +126 -0
- package/src/components/ui/floating-level-selector.tsx +103 -10
- package/src/components/ui/helpers/contextual-helper-panel.tsx +9 -0
- package/src/components/ui/helpers/helper-manager.tsx +47 -11
- package/src/components/ui/helpers/item-helper.tsx +1 -1
- package/src/components/ui/helpers/registered-tool-helper.tsx +21 -0
- package/src/components/ui/panels/homogeneous-selection.test.ts +80 -0
- package/src/components/ui/panels/homogeneous-selection.ts +47 -0
- package/src/components/ui/panels/mobile-selection-bar.tsx +11 -5
- package/src/components/ui/panels/multi-field-value.test.ts +209 -0
- package/src/components/ui/panels/multi-field-value.ts +163 -0
- package/src/components/ui/panels/multi-height-mode.tsx +185 -0
- package/src/components/ui/panels/multi-parametric-inspector.tsx +266 -0
- package/src/components/ui/panels/multi-selection-panel.tsx +48 -37
- package/src/components/ui/panels/node-display.ts +4 -0
- package/src/components/ui/panels/panel-manager.tsx +77 -3
- package/src/components/ui/panels/parametric-field-control.tsx +173 -0
- package/src/components/ui/panels/parametric-field-utils.ts +18 -0
- package/src/components/ui/panels/parametric-inspector.tsx +35 -164
- package/src/components/ui/panels/reference-panel.tsx +34 -4
- package/src/components/ui/primitives/checkbox.tsx +34 -0
- package/src/components/ui/primitives/shortcut-token.tsx +23 -1
- package/src/components/ui/scene-loader.tsx +35 -0
- package/src/components/ui/sidebar/panels/settings-panel/index.tsx +502 -31
- package/src/components/ui/sidebar/panels/settings-panel/keyboard-shortcuts-dialog.tsx +20 -23
- package/src/components/ui/sidebar/panels/settings-panel/print-export-button.test.ts +167 -0
- package/src/components/ui/sidebar/panels/settings-panel/print-export-button.tsx +128 -0
- package/src/components/ui/sidebar/panels/site-panel/building-tree-node.tsx +8 -1
- package/src/components/ui/sidebar/panels/site-panel/dormer-tree-node.tsx +19 -5
- package/src/components/ui/sidebar/panels/site-panel/index.tsx +222 -50
- package/src/components/ui/sidebar/panels/site-panel/item-tree-node.tsx +2 -7
- package/src/components/ui/sidebar/panels/site-panel/level-tree-node.tsx +5 -2
- package/src/components/ui/sidebar/panels/site-panel/registry-tree-node.tsx +28 -11
- package/src/components/ui/sidebar/panels/site-panel/shelf-tree-node.tsx +3 -8
- package/src/components/ui/sidebar/panels/site-panel/tree-node.test.ts +8 -0
- package/src/components/ui/sidebar/panels/site-panel/tree-node.tsx +20 -7
- package/src/components/ui/sidebar/panels/site-panel/unit-tree-node.tsx +224 -0
- package/src/components/ui/sidebar/panels/site-panel/zone-membership-checkbox.tsx +22 -0
- package/src/components/ui/sidebar/panels/site-panel/zone-tree-node.tsx +24 -7
- package/src/components/ui/sidebar/tab-bar.tsx +2 -0
- package/src/components/ui/sidebar/use-plugin-panels.tsx +17 -2
- package/src/components/ui/snap-target-badge.tsx +2 -0
- package/src/components/viewer/viewer-scene-header.tsx +5 -1
- package/src/components/viewer/viewer-stage.tsx +4 -1
- package/src/components/viewer/viewer-units-panel.tsx +116 -0
- package/src/components/viewer-overlay.tsx +1 -22
- package/src/components/viewer-zone-system.tsx +6 -2
- package/src/components/walkthrough-hud.tsx +19 -10
- package/src/hooks/use-auto-save.test.ts +73 -1
- package/src/hooks/use-auto-save.ts +76 -5
- package/src/hooks/use-ceiling-events.test.ts +144 -0
- package/src/hooks/use-ceiling-events.ts +5 -1
- package/src/hooks/use-drag-action.ts +17 -3
- package/src/hooks/use-grid-events.test.ts +240 -0
- package/src/hooks/use-grid-events.ts +190 -11
- package/src/hooks/use-keyboard.test.ts +244 -0
- package/src/hooks/use-keyboard.ts +132 -63
- package/src/hooks/use-registered-tool-enabled.ts +20 -0
- package/src/hooks/use-save-shortcut.ts +33 -0
- package/src/index.tsx +87 -4
- package/src/lib/active-placement-surface.test.ts +16 -0
- package/src/lib/active-placement-surface.ts +14 -0
- package/src/lib/ceiling-surface-raycast.test.ts +64 -0
- package/src/lib/ceiling-surface-raycast.ts +12 -0
- package/src/lib/contextual-help-extension.ts +17 -0
- package/src/lib/continuation.test.ts +11 -0
- package/src/lib/continuation.ts +8 -1
- package/src/lib/direct-manipulation.test.ts +132 -0
- package/src/lib/direct-manipulation.ts +38 -1
- package/src/lib/editor-api.ts +6 -3
- package/src/lib/elevation-guides.test.ts +28 -1
- package/src/lib/elevation-guides.ts +22 -7
- package/src/lib/export-texture-utils.test.ts +167 -0
- package/src/lib/export-texture-utils.ts +121 -0
- package/src/lib/export-user-data.test.ts +48 -0
- package/src/lib/export-user-data.ts +69 -0
- package/src/lib/floating-menu-scale.test.ts +29 -0
- package/src/lib/floating-menu-scale.ts +14 -0
- package/src/lib/floorplan/apply-alignment.test.ts +47 -2
- package/src/lib/floorplan/apply-alignment.ts +10 -1
- package/src/lib/floorplan/floorplan-export.test.ts +536 -2
- package/src/lib/floorplan/floorplan-export.tsx +120 -19
- package/src/lib/floorplan/floorplan-pdfkit-renderer.test.ts +26 -0
- package/src/lib/floorplan/floorplan-pdfkit-renderer.ts +32 -24
- package/src/lib/floorplan/floorplan-readonly.ts +5 -0
- package/src/lib/floorplan-grid-event-point.test.ts +29 -0
- package/src/lib/floorplan-grid-event-point.ts +13 -0
- package/src/lib/fresh-planar-placement.ts +13 -5
- package/src/lib/glb-export-serialize.test.ts +280 -0
- package/src/lib/glb-export.test.ts +1375 -21
- package/src/lib/glb-export.ts +781 -106
- package/src/lib/grid-event-presentation.ts +16 -0
- package/src/lib/history.test.ts +528 -147
- package/src/lib/history.ts +81 -7
- package/src/lib/host-tree-children.test.ts +27 -0
- package/src/lib/host-tree-children.ts +79 -0
- package/src/lib/interaction/hot-set.test.ts +10 -1
- package/src/lib/interaction/hot-set.ts +3 -1
- package/src/lib/interaction/overlay-policy.test.ts +33 -1
- package/src/lib/interaction/overlay-policy.ts +16 -0
- package/src/lib/interaction/registered-drafting.ts +36 -0
- package/src/lib/interaction/scope.ts +31 -0
- package/src/lib/level-duplication.test.ts +73 -0
- package/src/lib/level-duplication.ts +32 -2
- package/src/lib/level-print-export.test.ts +484 -0
- package/src/lib/level-print-export.ts +526 -0
- package/src/lib/linear-display.test.ts +59 -0
- package/src/lib/linear-display.ts +39 -0
- package/src/lib/local-guide-image.test.ts +24 -0
- package/src/lib/local-guide-image.ts +34 -1
- package/src/lib/local-project-presentation-persistence.test.ts +302 -0
- package/src/lib/local-project-presentation-persistence.ts +335 -0
- package/src/lib/material-paint.ts +2 -0
- package/src/lib/model-export.ts +29 -0
- package/src/lib/node-action-movement.ts +21 -0
- package/src/lib/paint-preview-owner.ts +71 -0
- package/src/lib/planar-cursor-placement.test.ts +178 -1
- package/src/lib/planar-cursor-placement.ts +61 -5
- package/src/lib/plugin-panels.test.ts +92 -1
- package/src/lib/plugin-panels.ts +48 -0
- package/src/lib/portable-export.test.ts +455 -0
- package/src/lib/portable-export.ts +1042 -0
- package/src/lib/print-3mf.test.ts +86 -0
- package/src/lib/print-3mf.ts +161 -0
- package/src/lib/print-content-scope.test.ts +107 -0
- package/src/lib/print-content-scope.ts +90 -0
- package/src/lib/print-export.test.ts +294 -0
- package/src/lib/print-export.ts +735 -0
- package/src/lib/print-feature-thickness.test.ts +147 -0
- package/src/lib/print-feature-thickness.ts +180 -0
- package/src/lib/print-golden-house.test-fixture.ts +352 -0
- package/src/lib/print-golden-house.test.ts +249 -0
- package/src/lib/print-roof-solids.test.ts +133 -0
- package/src/lib/print-roof-solids.ts +630 -0
- package/src/lib/print-shell-compiler-baseline.test.ts +419 -0
- package/src/lib/print-shell-compiler-baseline.ts +225 -0
- package/src/lib/print-shell-compiler-manifold-core.ts +379 -0
- package/src/lib/print-shell-compiler-manifold-worker.ts +200 -0
- package/src/lib/print-shell-compiler-manifold.worker.ts +20 -0
- package/src/lib/print-shell-compiler-mesh-data.ts +32 -0
- package/src/lib/print-shell-compiler-protocol.ts +38 -0
- package/src/lib/print-shell-compiler.ts +273 -0
- package/src/lib/print-wall-solids.test.ts +194 -0
- package/src/lib/print-wall-solids.ts +328 -0
- package/src/lib/rigid-plan-svg-transform.test.ts +35 -0
- package/src/lib/rigid-plan-svg-transform.ts +24 -0
- package/src/lib/scene-clipboard.ts +1 -1
- package/src/lib/scene.ts +22 -8
- package/src/lib/selection-routing.test.ts +105 -1
- package/src/lib/selection-routing.ts +19 -0
- package/src/lib/send-to-app.test.ts +108 -0
- package/src/lib/send-to-app.ts +121 -0
- package/src/lib/sfx/movement-tick.ts +37 -0
- package/src/lib/sfx-bus.ts +4 -0
- package/src/lib/sfx-player.ts +8 -0
- package/src/lib/snapping-mode.test.ts +32 -4
- package/src/lib/snapping-mode.ts +11 -7
- package/src/lib/surface-attachment.ts +77 -0
- package/src/lib/units.ts +254 -0
- package/src/lib/usdz-export.ts +65 -0
- package/src/lib/use-linear-display.ts +8 -32
- package/src/lib/walkthrough-pointer-lock.ts +47 -0
- package/src/store/live-draft-preview-stores.test.ts +3 -0
- package/src/store/terrain-sculpt-mode.test.ts +3 -6
- package/src/store/tool-mode.test.ts +87 -0
- package/src/store/use-camera-hint-focus.ts +48 -0
- package/src/store/use-editor.tsx +299 -188
- package/src/store/use-floorplan-draft-preview.ts +9 -0
- package/src/store/use-handle-group.ts +4 -0
- package/src/store/use-interaction-scope.test.ts +23 -1
- package/src/store/use-interaction-scope.ts +63 -2
- package/src/store/use-placement-preview.ts +56 -3
- package/src/store/use-send-to-app.ts +21 -0
- package/src/components/tools/roof/roof-tool.tsx +0 -656
- package/src/components/ui/helpers/roof-helper.tsx +0 -14
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { Group } from 'three'
|
|
3
|
+
import {
|
|
4
|
+
applyFaceHostPreviewPose,
|
|
5
|
+
clampFaceHostCenterPosition,
|
|
6
|
+
clampFaceHostPosition,
|
|
7
|
+
resolveFaceHostSwitch,
|
|
8
|
+
shouldDetachFaceHostOnLeave,
|
|
9
|
+
} from './face-host-preview'
|
|
10
|
+
|
|
11
|
+
describe('applyFaceHostPreviewPose', () => {
|
|
12
|
+
test('moves the rendered draft synchronously with the pointer result', () => {
|
|
13
|
+
const mesh = new Group()
|
|
14
|
+
mesh.position.set(8, 8, 8)
|
|
15
|
+
mesh.rotation.set(1, 1, 1)
|
|
16
|
+
|
|
17
|
+
applyFaceHostPreviewPose(mesh, [1.25, -0.5, 0], [0, 0, 0])
|
|
18
|
+
|
|
19
|
+
expect(mesh.position.toArray()).toEqual([1.25, -0.5, 0])
|
|
20
|
+
expect(mesh.rotation.toArray().slice(0, 3)).toEqual([0, 0, 0])
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('resolveFaceHostSwitch', () => {
|
|
25
|
+
test('ignores a single adjacent-face hit and accepts a repeated hit', () => {
|
|
26
|
+
const first = resolveFaceHostSwitch('face-a', 'face-b', null)
|
|
27
|
+
expect(first).toEqual({ accept: false, pendingFaceId: 'face-b' })
|
|
28
|
+
|
|
29
|
+
const second = resolveFaceHostSwitch('face-a', 'face-b', first.pendingFaceId)
|
|
30
|
+
expect(second).toEqual({ accept: true, pendingFaceId: null })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('clears a pending switch when the pointer returns to the current face', () => {
|
|
34
|
+
expect(resolveFaceHostSwitch('face-a', 'face-a', 'face-b')).toEqual({
|
|
35
|
+
accept: true,
|
|
36
|
+
pendingFaceId: null,
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe('shouldDetachFaceHostOnLeave', () => {
|
|
42
|
+
test('detaches attached items when they leave a block face', () => {
|
|
43
|
+
expect(shouldDetachFaceHostOnLeave('wall')).toBe(true)
|
|
44
|
+
expect(shouldDetachFaceHostOnLeave('wall-side')).toBe(true)
|
|
45
|
+
expect(shouldDetachFaceHostOnLeave('ceiling')).toBe(true)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('allows free floor items to leave a block face', () => {
|
|
49
|
+
expect(shouldDetachFaceHostOnLeave(undefined)).toBe(true)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('clampFaceHostPosition', () => {
|
|
54
|
+
test('keeps the complete wall item inside the face after snapping', () => {
|
|
55
|
+
expect(
|
|
56
|
+
clampFaceHostPosition([1.9, 2.8, 0], { minU: -2, maxU: 2, minV: 0, maxV: 3 }, [1, 1]),
|
|
57
|
+
).toEqual([1.5, 2, 0])
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('rejects a face that is smaller than the item', () => {
|
|
61
|
+
expect(
|
|
62
|
+
clampFaceHostPosition([0, 0, 0], { minU: -0.25, maxU: 0.25, minV: 0, maxV: 0.5 }, [1, 1]),
|
|
63
|
+
).toBeNull()
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
describe('clampFaceHostCenterPosition', () => {
|
|
68
|
+
test('keeps a ceiling fixture footprint inside the face on both axes', () => {
|
|
69
|
+
expect(
|
|
70
|
+
clampFaceHostCenterPosition(
|
|
71
|
+
[1.9, 1.9, 0.25],
|
|
72
|
+
{ minU: -2, maxU: 2, minV: -2, maxV: 2 },
|
|
73
|
+
[1, 1],
|
|
74
|
+
),
|
|
75
|
+
).toEqual([1.5, 1.5, 0.25])
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Object3D } from 'three'
|
|
2
|
+
|
|
3
|
+
type Vector3Tuple = readonly [number, number, number]
|
|
4
|
+
|
|
5
|
+
type FaceBounds = {
|
|
6
|
+
minU: number
|
|
7
|
+
maxU: number
|
|
8
|
+
minV: number
|
|
9
|
+
maxV: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function applyFaceHostPreviewPose(
|
|
13
|
+
mesh: Object3D,
|
|
14
|
+
position: Vector3Tuple,
|
|
15
|
+
rotation: Vector3Tuple,
|
|
16
|
+
): void {
|
|
17
|
+
mesh.position.set(position[0], position[1], position[2])
|
|
18
|
+
mesh.rotation.set(rotation[0], rotation[1], rotation[2])
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function resolveFaceHostSwitch(
|
|
22
|
+
currentFaceId: string | null | undefined,
|
|
23
|
+
nextFaceId: string | null | undefined,
|
|
24
|
+
pendingFaceId: string | null,
|
|
25
|
+
): { accept: boolean; pendingFaceId: string | null } {
|
|
26
|
+
if (!currentFaceId || !nextFaceId || currentFaceId === nextFaceId) {
|
|
27
|
+
return { accept: true, pendingFaceId: null }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (pendingFaceId === nextFaceId) {
|
|
31
|
+
return { accept: true, pendingFaceId: null }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { accept: false, pendingFaceId: nextFaceId }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function shouldDetachFaceHostOnLeave(attachTo: string | undefined): boolean {
|
|
38
|
+
return (
|
|
39
|
+
attachTo === undefined ||
|
|
40
|
+
attachTo === 'wall' ||
|
|
41
|
+
attachTo === 'wall-side' ||
|
|
42
|
+
attachTo === 'ceiling'
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function clampFaceHostPosition(
|
|
47
|
+
position: Vector3Tuple,
|
|
48
|
+
bounds: FaceBounds,
|
|
49
|
+
dimensions: readonly [width: number, height: number],
|
|
50
|
+
): [number, number, number] | null {
|
|
51
|
+
const [width, height] = dimensions
|
|
52
|
+
const minU = bounds.minU + width / 2
|
|
53
|
+
const maxU = bounds.maxU - width / 2
|
|
54
|
+
const minV = bounds.minV
|
|
55
|
+
const maxV = bounds.maxV - height
|
|
56
|
+
if (minU > maxU || minV > maxV) return null
|
|
57
|
+
|
|
58
|
+
return [
|
|
59
|
+
Math.min(maxU, Math.max(minU, position[0])),
|
|
60
|
+
Math.min(maxV, Math.max(minV, position[1])),
|
|
61
|
+
position[2],
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function clampFaceHostCenterPosition(
|
|
66
|
+
position: Vector3Tuple,
|
|
67
|
+
bounds: FaceBounds,
|
|
68
|
+
dimensions: readonly [width: number, depth: number],
|
|
69
|
+
): [number, number, number] | null {
|
|
70
|
+
const [width, depth] = dimensions
|
|
71
|
+
const minU = bounds.minU + width / 2
|
|
72
|
+
const maxU = bounds.maxU - width / 2
|
|
73
|
+
const minV = bounds.minV + depth / 2
|
|
74
|
+
const maxV = bounds.maxV - depth / 2
|
|
75
|
+
if (minU > maxU || minV > maxV) return null
|
|
76
|
+
|
|
77
|
+
return [
|
|
78
|
+
Math.min(maxU, Math.max(minU, position[0])),
|
|
79
|
+
Math.min(maxV, Math.max(minV, position[1])),
|
|
80
|
+
position[2],
|
|
81
|
+
]
|
|
82
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
2
|
+
import {
|
|
3
|
+
type ItemEvent,
|
|
4
|
+
ItemNode,
|
|
5
|
+
nodeRegistry,
|
|
6
|
+
registerNode,
|
|
7
|
+
sceneRegistry,
|
|
8
|
+
useScene,
|
|
9
|
+
} from '@pascal-app/core'
|
|
10
|
+
import { Group, Vector3 } from 'three'
|
|
11
|
+
import useEditor from '../../../store/use-editor'
|
|
12
|
+
import useInteractionScope from '../../../store/use-interaction-scope'
|
|
13
|
+
import { itemSurfaceStrategy } from './placement-strategies'
|
|
14
|
+
import type { PlacementContext } from './placement-types'
|
|
15
|
+
|
|
16
|
+
const asset = {
|
|
17
|
+
id: 'table',
|
|
18
|
+
name: 'Table',
|
|
19
|
+
category: 'furniture',
|
|
20
|
+
thumbnail: '',
|
|
21
|
+
src: '/table.glb',
|
|
22
|
+
dimensions: [2, 1, 3],
|
|
23
|
+
}
|
|
24
|
+
let restoreRegistry: () => void
|
|
25
|
+
const editorState = useEditor.getState()
|
|
26
|
+
const scopeState = useInteractionScope.getState()
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
restoreRegistry = nodeRegistry._snapshot()
|
|
30
|
+
nodeRegistry._reset()
|
|
31
|
+
registerNode({
|
|
32
|
+
kind: 'item',
|
|
33
|
+
schemaVersion: 1,
|
|
34
|
+
schema: ItemNode,
|
|
35
|
+
category: 'furnish',
|
|
36
|
+
snapProfile: 'item',
|
|
37
|
+
defaults: () => ({}),
|
|
38
|
+
capabilities: {},
|
|
39
|
+
})
|
|
40
|
+
useInteractionScope.setState({ scope: { kind: 'idle' } })
|
|
41
|
+
useEditor.setState({ mode: 'build', tool: 'item', gridSnapStep: 0.5 })
|
|
42
|
+
useEditor.getState().setSnappingMode('item', 'grid')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
restoreRegistry()
|
|
47
|
+
sceneRegistry.nodes.delete('item_surface-test')
|
|
48
|
+
useEditor.setState(editorState)
|
|
49
|
+
useInteractionScope.setState(scopeState)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
function surface(overrides: Partial<ItemNode> = {}) {
|
|
53
|
+
const host = ItemNode.parse({ id: 'item_surface-test', asset, ...overrides })
|
|
54
|
+
const mesh = new Group()
|
|
55
|
+
mesh.position.set(4, 2, -3)
|
|
56
|
+
mesh.rotation.y = Math.PI / 3
|
|
57
|
+
mesh.updateMatrixWorld(true)
|
|
58
|
+
sceneRegistry.nodes.set(host.id, mesh)
|
|
59
|
+
const world = mesh.localToWorld(new Vector3(0.37, 0.81, -0.39))
|
|
60
|
+
const event = {
|
|
61
|
+
node: host,
|
|
62
|
+
object: mesh,
|
|
63
|
+
position: world.toArray(),
|
|
64
|
+
localPosition: [0.37, 0.81, -0.39],
|
|
65
|
+
normal: [0, 1, 0],
|
|
66
|
+
stopPropagation: () => {},
|
|
67
|
+
nativeEvent: {} as ItemEvent['nativeEvent'],
|
|
68
|
+
} as ItemEvent
|
|
69
|
+
return { host, mesh, event }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function enterSurface(
|
|
73
|
+
event: ItemEvent,
|
|
74
|
+
dimensions: [number, number, number],
|
|
75
|
+
yaw = 0,
|
|
76
|
+
draftId?: ItemNode['id'],
|
|
77
|
+
) {
|
|
78
|
+
const draft = ItemNode.parse({ id: draftId, asset: { ...asset, dimensions } })
|
|
79
|
+
return itemSurfaceStrategy.enter(
|
|
80
|
+
{
|
|
81
|
+
asset: draft.asset,
|
|
82
|
+
draftItem: draft,
|
|
83
|
+
state: { surface: 'floor' },
|
|
84
|
+
currentCursorRotationY: yaw,
|
|
85
|
+
} as PlacementContext,
|
|
86
|
+
event,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
describe('itemSurfaceStrategy production placement', () => {
|
|
91
|
+
test('scaled host accepts centred rotated and oversized footprints', () => {
|
|
92
|
+
const { event } = surface({ scale: [2, 1, 0.5] })
|
|
93
|
+
expect(enterSurface(event, [4, 5, 1.5], 0)).not.toBeNull()
|
|
94
|
+
expect(enterSurface(event, [4, 5, 1.5], Math.PI / 3)).not.toBeNull()
|
|
95
|
+
expect(enterSurface(event, [4.01, 1, 1.5], 0)).not.toBeNull()
|
|
96
|
+
expect(enterSurface(event, [4, 1, 1.51], 0)).not.toBeNull()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('rejects ceiling hosts, low profiles, side hits, and absent normals', () => {
|
|
100
|
+
for (const overrides of [
|
|
101
|
+
{ asset: { ...asset, attachTo: 'ceiling' } },
|
|
102
|
+
{ asset: { ...asset, dimensions: [2, 0.05, 3] } },
|
|
103
|
+
]) {
|
|
104
|
+
const { event } = surface(overrides as Partial<ItemNode>)
|
|
105
|
+
expect(enterSurface(event, [0.5, 1, 0.5], 0)).toBeNull()
|
|
106
|
+
}
|
|
107
|
+
const { event } = surface()
|
|
108
|
+
for (const normal of [[1, 0, 0], [0, -1, 0], undefined]) {
|
|
109
|
+
expect(enterSurface({ ...event, normal } as ItemEvent, [0.5, 1, 0.5], 0)).toBeNull()
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('uses scaled asset surface height, snapped host-local XZ, and continuous world yaw', () => {
|
|
114
|
+
const { mesh, event } = surface({
|
|
115
|
+
asset: { ...asset, surface: { height: 0.7 } } as ItemNode['asset'],
|
|
116
|
+
scale: [1, 2, 1],
|
|
117
|
+
})
|
|
118
|
+
const pose = enterSurface(event, [0.5, 1, 0.5], Math.PI / 4)!
|
|
119
|
+
expect(pose.nodeUpdate.position!).toEqual([0.25, 1.4, -0.25])
|
|
120
|
+
expect(pose.nodeUpdate.rotation![1]! + Math.PI / 3).toBeCloseTo(Math.PI / 4)
|
|
121
|
+
expect(pose.cursorPosition).toEqual(
|
|
122
|
+
mesh.localToWorld(new Vector3(...pose.nodeUpdate.position!)).toArray(),
|
|
123
|
+
)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('uses local hit Y without surface metadata and honors snapping off', () => {
|
|
127
|
+
useEditor.getState().setSnappingMode('item', 'off')
|
|
128
|
+
const { event } = surface()
|
|
129
|
+
const pose = enterSurface(event, [0.5, 1, 0.5], 0)!
|
|
130
|
+
expect(pose.nodeUpdate.position![0]).toBeCloseTo(0.37)
|
|
131
|
+
expect(pose.nodeUpdate.position![1]).toBeCloseTo(0.81)
|
|
132
|
+
expect(pose.nodeUpdate.position![2]).toBeCloseTo(-0.39)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('rejects the moving node and its descendants', () => {
|
|
136
|
+
const { host, event } = surface({ parentId: 'item_moving' })
|
|
137
|
+
expect(enterSurface(event, [0.5, 1, 0.5], 0, host.id)).toBeNull()
|
|
138
|
+
expect(enterSurface(event, [0.5, 1, 0.5], 0, 'item_moving')).toBeNull()
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('catalog strategy keeps its enter pose and position-only move contract', () => {
|
|
142
|
+
const { host, event } = surface()
|
|
143
|
+
const draft = ItemNode.parse({ asset: { ...asset, dimensions: [0.5, 1, 0.5] } })
|
|
144
|
+
const ctx = {
|
|
145
|
+
asset: draft.asset,
|
|
146
|
+
draftItem: draft,
|
|
147
|
+
state: {
|
|
148
|
+
surface: 'floor',
|
|
149
|
+
wallId: null,
|
|
150
|
+
roofSegmentId: null,
|
|
151
|
+
ceilingId: null,
|
|
152
|
+
surfaceItemId: null,
|
|
153
|
+
shelfId: null,
|
|
154
|
+
},
|
|
155
|
+
currentCursorRotationY: 0.2,
|
|
156
|
+
gridPosition: new Vector3(),
|
|
157
|
+
levelId: 'level_test',
|
|
158
|
+
} as PlacementContext
|
|
159
|
+
const enter = itemSurfaceStrategy.enter(ctx, event)!
|
|
160
|
+
expect(enter.nodeUpdate.parentId).toBe(host.id)
|
|
161
|
+
expect(enter.nodeUpdate.rotation?.[1]).toBeCloseTo(0.2 - Math.PI / 3)
|
|
162
|
+
const oldNodes = useScene.getState().nodes
|
|
163
|
+
useScene.setState({ nodes: { ...oldNodes, [host.id]: host } })
|
|
164
|
+
try {
|
|
165
|
+
const move = itemSurfaceStrategy.move(
|
|
166
|
+
{ ...ctx, state: { ...ctx.state, surface: 'item-surface', surfaceItemId: host.id } },
|
|
167
|
+
event,
|
|
168
|
+
)!
|
|
169
|
+
expect(move.nodeUpdate).toEqual({ position: enter.gridPosition })
|
|
170
|
+
expect(move.cursorRotationY).toBe(0.2)
|
|
171
|
+
} finally {
|
|
172
|
+
useScene.setState({ nodes: oldNodes })
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
})
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, spyOn, test } from 'bun:test'
|
|
2
|
+
import * as core from '@pascal-app/core'
|
|
3
|
+
import {
|
|
4
|
+
type ItemEvent,
|
|
5
|
+
ItemNode,
|
|
6
|
+
nodeRegistry,
|
|
7
|
+
registerNode,
|
|
8
|
+
sceneRegistry,
|
|
9
|
+
useScene,
|
|
10
|
+
} from '@pascal-app/core'
|
|
11
|
+
import { Group, Vector3 } from 'three'
|
|
12
|
+
import useEditor from '../../../store/use-editor'
|
|
13
|
+
import useInteractionScope from '../../../store/use-interaction-scope'
|
|
14
|
+
import { itemSurfaceStrategy } from './placement-strategies'
|
|
15
|
+
import type { PlacementContext } from './placement-types'
|
|
16
|
+
|
|
17
|
+
const asset = {
|
|
18
|
+
id: 'table',
|
|
19
|
+
name: 'Table',
|
|
20
|
+
category: 'furniture',
|
|
21
|
+
thumbnail: '',
|
|
22
|
+
src: '/table.glb',
|
|
23
|
+
dimensions: [2, 1, 3],
|
|
24
|
+
}
|
|
25
|
+
const host = ItemNode.parse({ id: 'item_strategy-resolver-host', asset, scale: [2, 1, 0.5] })
|
|
26
|
+
const child = ItemNode.parse({
|
|
27
|
+
id: 'item_strategy-resolver-child',
|
|
28
|
+
asset: { ...asset, dimensions: [0.5, 1, 0.5] },
|
|
29
|
+
rotation: [0.1, 0.2, 0.3],
|
|
30
|
+
})
|
|
31
|
+
let restoreRegistry: () => void
|
|
32
|
+
let savedNodes: ReturnType<typeof useScene.getState>['nodes']
|
|
33
|
+
let savedEditor: ReturnType<typeof useEditor.getState>
|
|
34
|
+
let savedScope: ReturnType<typeof useInteractionScope.getState>
|
|
35
|
+
let resolver: ReturnType<typeof spyOn<typeof core, 'resolveSurfacePlacement'>>
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
restoreRegistry = nodeRegistry._snapshot()
|
|
39
|
+
nodeRegistry._reset()
|
|
40
|
+
registerNode({
|
|
41
|
+
kind: 'item',
|
|
42
|
+
schemaVersion: 1,
|
|
43
|
+
schema: ItemNode,
|
|
44
|
+
category: 'furnish',
|
|
45
|
+
snapProfile: 'item',
|
|
46
|
+
defaults: () => ({}),
|
|
47
|
+
capabilities: {},
|
|
48
|
+
})
|
|
49
|
+
savedNodes = useScene.getState().nodes
|
|
50
|
+
savedEditor = useEditor.getState()
|
|
51
|
+
savedScope = useInteractionScope.getState()
|
|
52
|
+
useScene.setState({ nodes: { [host.id]: host, [child.id]: child } })
|
|
53
|
+
useInteractionScope.setState({ scope: { kind: 'idle' } })
|
|
54
|
+
useEditor.setState({ mode: 'build', tool: 'item', gridSnapStep: 0.5 })
|
|
55
|
+
useEditor.getState().setSnappingMode('item', 'grid')
|
|
56
|
+
const mesh = new Group()
|
|
57
|
+
mesh.position.set(4, 2, -3)
|
|
58
|
+
mesh.rotation.set(0.1, Math.PI / 3, -0.1)
|
|
59
|
+
mesh.scale.set(2, 1, 0.5)
|
|
60
|
+
mesh.updateMatrixWorld(true)
|
|
61
|
+
sceneRegistry.nodes.set(host.id, mesh)
|
|
62
|
+
resolver = spyOn(core, 'resolveSurfacePlacement')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
afterEach(() => {
|
|
66
|
+
resolver.mockRestore()
|
|
67
|
+
restoreRegistry()
|
|
68
|
+
sceneRegistry.nodes.delete(host.id)
|
|
69
|
+
useScene.setState({ nodes: savedNodes })
|
|
70
|
+
useEditor.setState(savedEditor)
|
|
71
|
+
useInteractionScope.setState(savedScope)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
function context(draftItem = child): PlacementContext {
|
|
75
|
+
return {
|
|
76
|
+
asset: draftItem.asset,
|
|
77
|
+
draftItem,
|
|
78
|
+
state: {
|
|
79
|
+
surface: 'floor',
|
|
80
|
+
wallId: null,
|
|
81
|
+
roofSegmentId: null,
|
|
82
|
+
ceilingId: null,
|
|
83
|
+
surfaceItemId: null,
|
|
84
|
+
shelfId: null,
|
|
85
|
+
},
|
|
86
|
+
currentCursorRotationY: 0.2,
|
|
87
|
+
gridPosition: new Vector3(),
|
|
88
|
+
levelId: 'level_test',
|
|
89
|
+
} as PlacementContext
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function hit(): ItemEvent {
|
|
93
|
+
const object = sceneRegistry.nodes.get(host.id)!
|
|
94
|
+
return {
|
|
95
|
+
node: host,
|
|
96
|
+
object,
|
|
97
|
+
normal: [0, 1, 0],
|
|
98
|
+
position: object.localToWorld(new Vector3(0.37, 0.81, -0.39)).toArray(),
|
|
99
|
+
localPosition: [0.37, 0.81, -0.39],
|
|
100
|
+
nativeEvent: {},
|
|
101
|
+
stopPropagation() {},
|
|
102
|
+
} as ItemEvent
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function onHost(ctx: PlacementContext): PlacementContext {
|
|
106
|
+
return { ...ctx, state: { ...ctx.state, surface: 'item-surface', surfaceItemId: host.id } }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Expected poses were captured from resolveItemSurfacePlacement at ad2a57b8 before its removal.
|
|
110
|
+
test.each([
|
|
111
|
+
[4.01, 1, 1.5],
|
|
112
|
+
[4, 1, 1.51],
|
|
113
|
+
] as [
|
|
114
|
+
number,
|
|
115
|
+
number,
|
|
116
|
+
number,
|
|
117
|
+
][])('enter and move accept oversized objects with their centres on the host: %j', (width, height, depth) => {
|
|
118
|
+
const draft = ItemNode.parse({
|
|
119
|
+
...child,
|
|
120
|
+
asset: { ...asset, dimensions: [width, height, depth] },
|
|
121
|
+
})
|
|
122
|
+
const ctx = context(draft)
|
|
123
|
+
const event = hit()
|
|
124
|
+
const before = useScene.getState().nodes
|
|
125
|
+
expect(itemSurfaceStrategy.enter(ctx, event)).not.toBeNull()
|
|
126
|
+
const expected: {
|
|
127
|
+
position: [number, number, number]
|
|
128
|
+
worldPosition: [number, number, number]
|
|
129
|
+
} =
|
|
130
|
+
width === 4.01
|
|
131
|
+
? {
|
|
132
|
+
position: [0.5049999999999999, 0.8099999999999996, -0.25],
|
|
133
|
+
worldPosition: [4.434656461734313, 2.8017166019018256, -3.927442316539199],
|
|
134
|
+
}
|
|
135
|
+
: {
|
|
136
|
+
position: [0.5, 0.8099999999999996, -0.245],
|
|
137
|
+
worldPosition: [4.4318465044173845, 2.8017248933478855, -3.9175249544338326],
|
|
138
|
+
}
|
|
139
|
+
const moved = itemSurfaceStrategy.move(onHost(ctx), event)!
|
|
140
|
+
expect(moved.nodeUpdate).toEqual({ position: expected.position })
|
|
141
|
+
expect(moved.cursorPosition).toEqual(expected.worldPosition)
|
|
142
|
+
expect(moved.cursorRotationY).toBe(ctx.currentCursorRotationY)
|
|
143
|
+
expect(resolver.mock.calls.map(([args]) => args.checkFootprint)).toEqual([true, true])
|
|
144
|
+
expect(useScene.getState().nodes).toBe(before)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test.each([
|
|
148
|
+
'grid',
|
|
149
|
+
'off',
|
|
150
|
+
] as const)('accepted poses match the frozen live capture with snapping %s', (mode) => {
|
|
151
|
+
useEditor.getState().setSnappingMode('item', mode)
|
|
152
|
+
const ctx = context()
|
|
153
|
+
const event = hit()
|
|
154
|
+
const expected: {
|
|
155
|
+
position: [number, number, number]
|
|
156
|
+
worldPosition: [number, number, number]
|
|
157
|
+
rotationY: number
|
|
158
|
+
} = {
|
|
159
|
+
...(mode === 'grid'
|
|
160
|
+
? {
|
|
161
|
+
position: [0.25, 0.8099999999999996, -0.25],
|
|
162
|
+
worldPosition: [4.180930399588417, 2.808503845962115, -3.4850883647019826],
|
|
163
|
+
}
|
|
164
|
+
: {
|
|
165
|
+
position: [0.36999999999999966, 0.8099999999999996, -0.39000000000000146],
|
|
166
|
+
worldPosition: [4.239709121156868, 2.808804018339912, -3.728080076057168],
|
|
167
|
+
}),
|
|
168
|
+
rotationY: -0.84936351290154,
|
|
169
|
+
}
|
|
170
|
+
const entered = itemSurfaceStrategy.enter(ctx, event)!
|
|
171
|
+
expect(entered.nodeUpdate).toEqual({
|
|
172
|
+
position: expected.position,
|
|
173
|
+
parentId: host.id,
|
|
174
|
+
rotation: [0.1, expected.rotationY, 0.3],
|
|
175
|
+
})
|
|
176
|
+
expect(entered.cursorPosition).toEqual(expected.worldPosition)
|
|
177
|
+
expect(itemSurfaceStrategy.move(onHost(ctx), event)!.nodeUpdate).toEqual({
|
|
178
|
+
position: expected.position,
|
|
179
|
+
})
|
|
180
|
+
expect(resolver).toHaveBeenCalledTimes(2)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test('resolver rejection leaves both enter and move drafts alone', () => {
|
|
184
|
+
resolver.mockReturnValue(null)
|
|
185
|
+
const ctx = context()
|
|
186
|
+
const before = useScene.getState().nodes
|
|
187
|
+
expect(itemSurfaceStrategy.enter(ctx, hit())).toBeNull()
|
|
188
|
+
expect(itemSurfaceStrategy.move(onHost(ctx), hit())).toBeNull()
|
|
189
|
+
expect(useScene.getState().nodes).toBe(before)
|
|
190
|
+
expect(ctx.draftItem).toBe(child)
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
test('move still rejects side hits and missing normals', () => {
|
|
194
|
+
for (const normal of [[1, 0, 0], [0, -1, 0], undefined] as ItemEvent['normal'][]) {
|
|
195
|
+
const event = { ...hit(), normal }
|
|
196
|
+
expect(itemSurfaceStrategy.enter(context(), event)).toBeNull()
|
|
197
|
+
expect(itemSurfaceStrategy.move(onHost(context()), event)).toBeNull()
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
test('enter rejects itself and indirect descendants before asking the resolver', () => {
|
|
202
|
+
expect(itemSurfaceStrategy.enter(context(host), hit())).toBeNull()
|
|
203
|
+
const middle = ItemNode.parse({ id: 'item_strategy-middle', parentId: child.id, asset })
|
|
204
|
+
const descendant = { ...host, parentId: middle.id }
|
|
205
|
+
useScene.setState({
|
|
206
|
+
nodes: { ...useScene.getState().nodes, [middle.id]: middle, [host.id]: descendant },
|
|
207
|
+
})
|
|
208
|
+
expect(itemSurfaceStrategy.enter(context(), { ...hit(), node: descendant })).toBeNull()
|
|
209
|
+
expect(resolver).not.toHaveBeenCalled()
|
|
210
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnyNodeId, ElevatorNode, SpawnNode } from '@pascal-app/core'
|
|
2
|
-
import { nodeRegistry } from '@pascal-app/core'
|
|
3
|
-
import { Suspense } from 'react'
|
|
2
|
+
import { createSceneApi, nodeRegistry, useScene } from '@pascal-app/core'
|
|
3
|
+
import { Suspense, useMemo } from 'react'
|
|
4
4
|
import { useMovingNode } from '../../../store/use-interaction-scope'
|
|
5
5
|
import { MoveElevatorTool } from '../elevator/move-elevator-tool'
|
|
6
6
|
import { MoveRegistryNodeTool } from '../registry/move-registry-node-tool'
|
|
@@ -28,6 +28,7 @@ export const MoveTool: React.FC<{
|
|
|
28
28
|
onSpawnMoved?: (nodeId: SpawnNode['id']) => void
|
|
29
29
|
}> = ({ onNodeMoved }) => {
|
|
30
30
|
const movingNode = useMovingNode()
|
|
31
|
+
const sceneApi = useMemo(() => createSceneApi(useScene), [])
|
|
31
32
|
|
|
32
33
|
if (!movingNode) return null
|
|
33
34
|
|
|
@@ -37,7 +38,7 @@ export const MoveTool: React.FC<{
|
|
|
37
38
|
if (RegistryMove) {
|
|
38
39
|
return (
|
|
39
40
|
<Suspense fallback={null}>
|
|
40
|
-
<RegistryMove node={movingNode} />
|
|
41
|
+
<RegistryMove node={movingNode} sceneApi={sceneApi} />
|
|
41
42
|
</Suspense>
|
|
42
43
|
)
|
|
43
44
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { getDetachedAttachmentPreviewLift, stripTransient } from './placement-math'
|
|
2
|
+
import { getDetachedAttachmentPreviewLift, steppedRotation, stripTransient } from './placement-math'
|
|
3
|
+
|
|
4
|
+
describe('steppedRotation', () => {
|
|
5
|
+
test('rotates a placement clockwise to the next 45 degree increment', () => {
|
|
6
|
+
expect(steppedRotation(Math.PI / 15, 1)).toBeCloseTo(Math.PI / 4)
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('rotates a placement counter-clockwise to the previous 45 degree increment', () => {
|
|
10
|
+
expect(steppedRotation(Math.PI / 15, -1)).toBeCloseTo(-Math.PI / 4)
|
|
11
|
+
})
|
|
12
|
+
})
|
|
3
13
|
|
|
4
14
|
describe('stripTransient', () => {
|
|
5
15
|
test('removes placement-only metadata flags before commit', () => {
|
|
@@ -81,26 +81,6 @@ export function getDetachedAttachmentPreviewLift(
|
|
|
81
81
|
return attachTo ? 0.45 : 0
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
/**
|
|
85
|
-
* Calculate cursor rotation in WORLD space from wall normal and orientation.
|
|
86
|
-
*/
|
|
87
|
-
export function calculateCursorRotation(
|
|
88
|
-
normal: [number, number, number] | undefined,
|
|
89
|
-
wallStart: [number, number],
|
|
90
|
-
wallEnd: [number, number],
|
|
91
|
-
): number {
|
|
92
|
-
if (!normal) return 0
|
|
93
|
-
|
|
94
|
-
// Wall direction angle in world XZ plane
|
|
95
|
-
const wallAngle = Math.atan2(wallEnd[1] - wallStart[1], wallEnd[0] - wallStart[0])
|
|
96
|
-
|
|
97
|
-
// In local wall space, front face has normal.z < 0, back face has normal.z > 0
|
|
98
|
-
if (normal[2] < 0) {
|
|
99
|
-
return -wallAngle
|
|
100
|
-
}
|
|
101
|
-
return Math.PI - wallAngle
|
|
102
|
-
}
|
|
103
|
-
|
|
104
84
|
/**
|
|
105
85
|
* Calculate item rotation in WALL-LOCAL space from normal.
|
|
106
86
|
* Items are children of the wall mesh, so their rotation is relative to wall's local space.
|