@pascal-app/editor 1.0.0 → 1.0.3
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 -6
- package/src/components/editor/bake-exporter.tsx +4 -0
- package/src/components/editor/bake-thumbnail.tsx +4 -1
- package/src/components/editor/custom-camera-controls.tsx +22 -74
- package/src/components/editor/editor-layout-mobile.tsx +1 -0
- package/src/components/editor/floating-action-menu.tsx +14 -1
- package/src/components/editor/floorplan-panel.tsx +233 -166
- package/src/components/editor/grid.tsx +31 -7
- package/src/components/editor/group-actions.ts +5 -9
- package/src/components/editor/group-floating-action-menu.tsx +19 -9
- package/src/components/editor/group-move-3d.ts +4 -6
- package/src/components/editor/group-rotate-handle.tsx +81 -35
- package/src/components/editor/group-selection-box-3d.tsx +25 -17
- package/src/components/editor/group-transform-shared.test.ts +126 -1
- package/src/components/editor/group-transform-shared.ts +79 -73
- package/src/components/editor/handles/handle-arrow.tsx +72 -2
- 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 +13 -2
- package/src/components/editor/handles/use-handle-drag.ts +80 -8
- package/src/components/editor/index.tsx +36 -13
- package/src/components/editor/node-action-menu.tsx +2 -0
- package/src/components/editor/node-arrow-handles.tsx +162 -69
- package/src/components/editor/registry-action-contributions.tsx +53 -0
- package/src/components/editor/selection-manager.tsx +49 -0
- package/src/components/editor/thumbnail-generator.tsx +11 -2
- package/src/components/editor/wall-move-side-handles.tsx +71 -21
- package/src/components/editor/wall-opening-highlights.tsx +2 -3
- package/src/components/editor-2d/floorplan-group-move.tsx +17 -24
- package/src/components/editor-2d/floorplan-registered-tool-layer.tsx +33 -12
- package/src/components/editor-2d/floorplan-registry-action-menu.tsx +12 -1
- package/src/components/editor-2d/floorplan-registry-move-overlay.tsx +154 -49
- package/src/components/editor-2d/renderers/floorplan-draft-wall-measurement.tsx +166 -0
- package/src/components/editor-2d/renderers/floorplan-registry-layer.test.ts +49 -0
- package/src/components/editor-2d/renderers/floorplan-registry-layer.tsx +113 -24
- package/src/components/procedural-items/inspector.tsx +223 -0
- package/src/components/systems/ceiling/ceiling-system.tsx +3 -1
- package/src/components/systems/zone/zone-system.tsx +8 -4
- package/src/components/tools/__fixtures__/hosting.ts +10 -0
- package/src/components/tools/item/item-surface-placement.test.ts +169 -0
- package/src/components/tools/item/item-surface-strategy-resolver.test.ts +204 -0
- package/src/components/tools/item/placement-strategies.ts +212 -200
- package/src/components/tools/item/placement-types.ts +4 -0
- package/src/components/tools/item/shelf-surface-strategy-resolver.test.ts +257 -0
- package/src/components/tools/item/use-draft-node.ts +136 -47
- package/src/components/tools/item/use-placement-coordinator.tsx +391 -157
- package/src/components/tools/registry/item-surface-child-frame.test.ts +90 -0
- package/src/components/tools/registry/item-surface-move.test.ts +509 -0
- package/src/components/tools/registry/item-surface-move.ts +463 -0
- package/src/components/tools/registry/item-surface-resolver.test.ts +257 -0
- package/src/components/tools/registry/move-registry-node-tool.tsx +237 -78
- package/src/components/tools/shared/affordance-dispatch.test.ts +24 -0
- package/src/components/tools/shared/affordance-dispatch.ts +13 -0
- package/src/components/tools/shared/draft-measurement-label.tsx +38 -0
- package/src/components/tools/shared/pointer-support-cap.test.ts +27 -0
- package/src/components/tools/shared/pointer-support-cap.ts +27 -13
- 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 +107 -0
- package/src/components/tools/shared/surface-rejection.tsx +43 -0
- package/src/components/tools/tool-manager.tsx +36 -3
- package/src/components/tools/zone/zone-tool.tsx +13 -4
- package/src/components/ui/command-palette/editor-commands.tsx +54 -1
- package/src/components/ui/controls/material-paint-panel.tsx +6 -67
- package/src/components/ui/controls/material-picker.tsx +5 -67
- package/src/components/ui/controls/metric-control.tsx +29 -13
- package/src/components/ui/controls/slider-control.tsx +87 -35
- package/src/components/ui/floating-level-selector.tsx +81 -5
- package/src/components/ui/helpers/helper-manager.tsx +24 -6
- package/src/components/ui/helpers/registered-tool-helper.tsx +2 -32
- package/src/components/ui/item-catalog/item-catalog.tsx +5 -30
- package/src/components/ui/panels/multi-height-mode.tsx +27 -21
- package/src/components/ui/panels/multi-parametric-inspector.tsx +6 -3
- package/src/components/ui/panels/parametric-field-control.tsx +1 -1
- package/src/components/ui/panels/parametric-inspector.tsx +9 -17
- package/src/components/ui/panels/reference-panel.tsx +3 -3
- package/src/components/ui/primitives/checkbox.tsx +34 -0
- package/src/components/ui/primitives/shortcut-token.tsx +4 -0
- package/src/components/ui/sidebar/panels/settings-panel/audio-settings-dialog.tsx +2 -2
- package/src/components/ui/sidebar/panels/settings-panel/index.tsx +669 -336
- package/src/components/ui/sidebar/panels/settings-panel/keyboard-shortcuts-dialog.tsx +2 -2
- package/src/components/ui/sidebar/panels/settings-panel/print-export-button.test.ts +31 -4
- package/src/components/ui/sidebar/panels/settings-panel/print-export-button.tsx +30 -11
- package/src/components/ui/sidebar/panels/site-panel/building-tree-node.tsx +8 -1
- package/src/components/ui/sidebar/panels/site-panel/index.tsx +106 -4
- package/src/components/ui/sidebar/panels/site-panel/item-tree-node.tsx +2 -7
- package/src/components/ui/sidebar/panels/site-panel/shelf-tree-node.tsx +3 -8
- package/src/components/ui/sidebar/panels/site-panel/tree-node.tsx +6 -1
- 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/snap-target-badge.tsx +2 -0
- package/src/components/viewer/floorplan-preview-visibility.test.ts +35 -0
- package/src/components/viewer/floorplan-preview-visibility.ts +19 -0
- package/src/components/viewer/floorplan-preview.tsx +1 -12
- package/src/components/viewer/viewer-scene-header.tsx +3 -0
- package/src/components/viewer/viewer-units-panel.tsx +116 -0
- package/src/components/viewer-zone-system.tsx +7 -2
- package/src/hooks/use-auto-save.integration.test.tsx +197 -0
- package/src/hooks/use-auto-save.ts +21 -6
- package/src/hooks/use-ceiling-events.test.ts +25 -2
- package/src/hooks/use-ceiling-events.ts +7 -1
- package/src/hooks/use-grid-events.test.ts +2 -0
- package/src/hooks/use-grid-events.ts +16 -11
- package/src/hooks/use-keyboard.test.ts +7 -0
- package/src/hooks/use-keyboard.ts +43 -28
- package/src/index.tsx +68 -3
- package/src/lib/catalog-panel-model.ts +39 -0
- package/src/lib/catalog-selection.test.ts +27 -0
- package/src/lib/catalog-selection.ts +8 -0
- package/src/lib/contextual-help.test.ts +27 -1
- package/src/lib/contextual-help.ts +16 -9
- 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/floorplan/floorplan-export.test.ts +142 -2
- package/src/lib/floorplan/floorplan-export.tsx +9 -3
- package/src/lib/floorplan/floorplan-extension.ts +16 -0
- package/src/lib/floorplan/floorplan-readonly.ts +4 -0
- package/src/lib/fresh-planar-placement.ts +173 -33
- package/src/lib/glb-export-serialize.test.ts +280 -0
- package/src/lib/glb-export.test.ts +265 -16
- package/src/lib/glb-export.ts +197 -37
- package/src/lib/grid-frame.test.ts +19 -0
- package/src/lib/grid-frame.ts +18 -0
- package/src/lib/interaction/scope.ts +9 -1
- package/src/lib/keyboard-pan.test.ts +62 -0
- package/src/lib/keyboard-pan.ts +89 -0
- package/src/lib/level-duplication.test.ts +73 -0
- package/src/lib/level-duplication.ts +32 -2
- 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/material-catalog-model.ts +72 -0
- package/src/lib/material-paint-panel-model.ts +76 -0
- package/src/lib/node-action-movement.ts +21 -0
- package/src/lib/overlay-transform.test.ts +28 -0
- package/src/lib/overlay-transform.ts +12 -0
- package/src/lib/panel-rows.ts +75 -0
- package/src/lib/panel-tool-options.test.ts +34 -0
- package/src/lib/panel-tool-options.ts +46 -0
- package/src/lib/parametric-node-update.ts +37 -0
- package/src/lib/portable-export.test.ts +89 -0
- package/src/lib/portable-export.ts +84 -11
- package/src/lib/print-shell-compiler-manifold-core.ts +59 -10
- package/src/lib/print-shell-compiler-manifold-worker.ts +14 -1
- package/src/lib/print-shell-compiler-manifold.worker.ts +1 -1
- package/src/lib/print-shell-compiler-protocol.ts +8 -0
- package/src/lib/scene-clipboard.ts +1 -1
- package/src/lib/scene.test.ts +99 -0
- package/src/lib/scene.ts +21 -3
- 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/snapping-mode.test.ts +13 -2
- package/src/lib/snapping-mode.ts +11 -6
- package/src/lib/spatial-drag-plane.test.ts +53 -0
- package/src/lib/spatial-drag-plane.ts +19 -0
- package/src/lib/spatial-pointer-input.test.ts +72 -0
- package/src/lib/spatial-pointer-input.ts +62 -0
- package/src/lib/spatial-snap.test.ts +47 -0
- package/src/lib/surface-attachment.ts +77 -0
- package/src/lib/terrain-panel-model.ts +117 -0
- package/src/lib/units.ts +254 -0
- package/src/lib/usdz-export.ts +43 -16
- package/src/lib/use-linear-display.ts +8 -32
- package/src/lib/world-grid-snap.test.ts +48 -0
- package/src/lib/world-grid-snap.ts +9 -5
- package/src/store/rotation-snapping.test.ts +53 -0
- package/src/store/use-editor.tsx +10 -2
- package/src/store/use-floorplan-draft-preview.ts +10 -1
- package/src/store/use-handle-group.ts +4 -0
- package/src/store/use-interaction-scope.ts +155 -6
- package/src/store/use-send-to-app.ts +21 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
2
|
+
import { type ItemEvent, ItemNode, nodeRegistry, sceneRegistry, useScene } from '@pascal-app/core'
|
|
3
|
+
import { Group, Vector3 } from 'three'
|
|
4
|
+
import useEditor from '../../../store/use-editor'
|
|
5
|
+
import useInteractionScope from '../../../store/use-interaction-scope'
|
|
6
|
+
import { registerHostingTestNode } from '../__fixtures__/hosting'
|
|
7
|
+
import { itemSurfaceStrategy } from './placement-strategies'
|
|
8
|
+
import type { PlacementContext } from './placement-types'
|
|
9
|
+
|
|
10
|
+
const asset = {
|
|
11
|
+
id: 'table',
|
|
12
|
+
name: 'Table',
|
|
13
|
+
category: 'furniture',
|
|
14
|
+
thumbnail: '',
|
|
15
|
+
src: '/table.glb',
|
|
16
|
+
dimensions: [2, 1, 3],
|
|
17
|
+
}
|
|
18
|
+
let restoreRegistry: () => void
|
|
19
|
+
const editorState = useEditor.getState()
|
|
20
|
+
const scopeState = useInteractionScope.getState()
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
restoreRegistry = nodeRegistry._snapshot()
|
|
24
|
+
nodeRegistry._reset()
|
|
25
|
+
registerHostingTestNode({
|
|
26
|
+
kind: 'item',
|
|
27
|
+
schemaVersion: 1,
|
|
28
|
+
schema: ItemNode,
|
|
29
|
+
category: 'furnish',
|
|
30
|
+
snapProfile: 'item',
|
|
31
|
+
defaults: () => ({}),
|
|
32
|
+
capabilities: {},
|
|
33
|
+
})
|
|
34
|
+
useInteractionScope.setState({ scope: { kind: 'idle' } })
|
|
35
|
+
useEditor.setState({ mode: 'build', tool: 'item', gridSnapStep: 0.5 })
|
|
36
|
+
useEditor.getState().setSnappingMode('item', 'grid')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
restoreRegistry()
|
|
41
|
+
sceneRegistry.nodes.delete('item_surface-test')
|
|
42
|
+
useEditor.setState(editorState)
|
|
43
|
+
useInteractionScope.setState(scopeState)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
function surface(overrides: Partial<ItemNode> = {}) {
|
|
47
|
+
const host = ItemNode.parse({ id: 'item_surface-test', asset, ...overrides })
|
|
48
|
+
const mesh = new Group()
|
|
49
|
+
mesh.position.set(4, 2, -3)
|
|
50
|
+
mesh.rotation.y = Math.PI / 3
|
|
51
|
+
mesh.updateMatrixWorld(true)
|
|
52
|
+
sceneRegistry.nodes.set(host.id, mesh)
|
|
53
|
+
const world = mesh.localToWorld(new Vector3(0.37, 0.81, -0.39))
|
|
54
|
+
const event = {
|
|
55
|
+
node: host,
|
|
56
|
+
object: mesh,
|
|
57
|
+
position: world.toArray(),
|
|
58
|
+
localPosition: [0.37, 0.81, -0.39],
|
|
59
|
+
normal: [0, 1, 0],
|
|
60
|
+
stopPropagation: () => {},
|
|
61
|
+
nativeEvent: {} as ItemEvent['nativeEvent'],
|
|
62
|
+
} as ItemEvent
|
|
63
|
+
return { host, mesh, event }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function enterSurface(
|
|
67
|
+
event: ItemEvent,
|
|
68
|
+
dimensions: [number, number, number],
|
|
69
|
+
yaw = 0,
|
|
70
|
+
draftId?: ItemNode['id'],
|
|
71
|
+
) {
|
|
72
|
+
const draft = ItemNode.parse({ id: draftId, asset: { ...asset, dimensions } })
|
|
73
|
+
return itemSurfaceStrategy.enter(
|
|
74
|
+
{
|
|
75
|
+
asset: draft.asset,
|
|
76
|
+
draftItem: draft,
|
|
77
|
+
state: { surface: 'floor' },
|
|
78
|
+
currentCursorRotationY: yaw,
|
|
79
|
+
} as PlacementContext,
|
|
80
|
+
event,
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('itemSurfaceStrategy production placement', () => {
|
|
85
|
+
test('scaled host accepts centred rotated and oversized footprints', () => {
|
|
86
|
+
const { event } = surface({ scale: [2, 1, 0.5] })
|
|
87
|
+
expect(enterSurface(event, [4, 5, 1.5], 0)).not.toBeNull()
|
|
88
|
+
expect(enterSurface(event, [4, 5, 1.5], Math.PI / 3)).not.toBeNull()
|
|
89
|
+
expect(enterSurface(event, [4.01, 1, 1.5], 0)).not.toBeNull()
|
|
90
|
+
expect(enterSurface(event, [4, 1, 1.51], 0)).not.toBeNull()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('rejects ceiling hosts, low profiles, side hits, and absent normals', () => {
|
|
94
|
+
for (const overrides of [
|
|
95
|
+
{ asset: { ...asset, attachTo: 'ceiling' } },
|
|
96
|
+
{ asset: { ...asset, dimensions: [2, 0.05, 3] } },
|
|
97
|
+
]) {
|
|
98
|
+
const { event } = surface(overrides as Partial<ItemNode>)
|
|
99
|
+
expect(enterSurface(event, [0.5, 1, 0.5], 0)).toBeNull()
|
|
100
|
+
}
|
|
101
|
+
const { event } = surface()
|
|
102
|
+
for (const normal of [[1, 0, 0], [0, -1, 0], undefined]) {
|
|
103
|
+
expect(enterSurface({ ...event, normal } as ItemEvent, [0.5, 1, 0.5], 0)).toBeNull()
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('uses scaled asset surface height, snapped host-local XZ, and continuous world yaw', () => {
|
|
108
|
+
const { mesh, event } = surface({
|
|
109
|
+
asset: { ...asset, surface: { height: 0.7 } } as ItemNode['asset'],
|
|
110
|
+
scale: [1, 2, 1],
|
|
111
|
+
})
|
|
112
|
+
const pose = enterSurface(event, [0.5, 1, 0.5], Math.PI / 4)!
|
|
113
|
+
expect(pose.nodeUpdate.position!).toEqual([0.25, 1.4, -0.25])
|
|
114
|
+
expect(pose.nodeUpdate.rotation![1]! + Math.PI / 3).toBeCloseTo(Math.PI / 4)
|
|
115
|
+
expect(pose.cursorPosition).toEqual(
|
|
116
|
+
mesh.localToWorld(new Vector3(...pose.nodeUpdate.position!)).toArray(),
|
|
117
|
+
)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('uses local hit Y without surface metadata and honors snapping off', () => {
|
|
121
|
+
useEditor.getState().setSnappingMode('item', 'off')
|
|
122
|
+
const { event } = surface()
|
|
123
|
+
const pose = enterSurface(event, [0.5, 1, 0.5], 0)!
|
|
124
|
+
expect(pose.nodeUpdate.position![0]).toBeCloseTo(0.37)
|
|
125
|
+
expect(pose.nodeUpdate.position![1]).toBeCloseTo(0.81)
|
|
126
|
+
expect(pose.nodeUpdate.position![2]).toBeCloseTo(-0.39)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('rejects the moving node and its descendants', () => {
|
|
130
|
+
const { host, event } = surface({ parentId: 'item_moving' })
|
|
131
|
+
expect(enterSurface(event, [0.5, 1, 0.5], 0, host.id)).toBeNull()
|
|
132
|
+
expect(enterSurface(event, [0.5, 1, 0.5], 0, 'item_moving')).toBeNull()
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('catalog strategy keeps its enter pose and position-only move contract', () => {
|
|
136
|
+
const { host, event } = surface()
|
|
137
|
+
const draft = ItemNode.parse({ asset: { ...asset, dimensions: [0.5, 1, 0.5] } })
|
|
138
|
+
const ctx = {
|
|
139
|
+
asset: draft.asset,
|
|
140
|
+
draftItem: draft,
|
|
141
|
+
state: {
|
|
142
|
+
surface: 'floor',
|
|
143
|
+
wallId: null,
|
|
144
|
+
roofSegmentId: null,
|
|
145
|
+
ceilingId: null,
|
|
146
|
+
surfaceItemId: null,
|
|
147
|
+
shelfId: null,
|
|
148
|
+
},
|
|
149
|
+
currentCursorRotationY: 0.2,
|
|
150
|
+
gridPosition: new Vector3(),
|
|
151
|
+
levelId: 'level_test',
|
|
152
|
+
} as PlacementContext
|
|
153
|
+
const enter = itemSurfaceStrategy.enter(ctx, event)!
|
|
154
|
+
expect(enter.nodeUpdate.parentId).toBe(host.id)
|
|
155
|
+
expect(enter.nodeUpdate.rotation?.[1]).toBeCloseTo(0.2 - Math.PI / 3)
|
|
156
|
+
const oldNodes = useScene.getState().nodes
|
|
157
|
+
useScene.setState({ nodes: { ...oldNodes, [host.id]: host } })
|
|
158
|
+
try {
|
|
159
|
+
const move = itemSurfaceStrategy.move(
|
|
160
|
+
{ ...ctx, state: { ...ctx.state, surface: 'item-surface', surfaceItemId: host.id } },
|
|
161
|
+
event,
|
|
162
|
+
)!
|
|
163
|
+
expect(move.nodeUpdate).toEqual({ position: enter.gridPosition })
|
|
164
|
+
expect(move.cursorRotationY).toBe(0.2)
|
|
165
|
+
} finally {
|
|
166
|
+
useScene.setState({ nodes: oldNodes })
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
})
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, spyOn, test } from 'bun:test'
|
|
2
|
+
import * as core from '@pascal-app/core'
|
|
3
|
+
import { type ItemEvent, ItemNode, nodeRegistry, sceneRegistry, useScene } from '@pascal-app/core'
|
|
4
|
+
import { Group, Vector3 } from 'three'
|
|
5
|
+
import useEditor from '../../../store/use-editor'
|
|
6
|
+
import useInteractionScope from '../../../store/use-interaction-scope'
|
|
7
|
+
import { registerHostingTestNode } from '../__fixtures__/hosting'
|
|
8
|
+
import { itemSurfaceStrategy } from './placement-strategies'
|
|
9
|
+
import type { PlacementContext } from './placement-types'
|
|
10
|
+
|
|
11
|
+
const asset = {
|
|
12
|
+
id: 'table',
|
|
13
|
+
name: 'Table',
|
|
14
|
+
category: 'furniture',
|
|
15
|
+
thumbnail: '',
|
|
16
|
+
src: '/table.glb',
|
|
17
|
+
dimensions: [2, 1, 3],
|
|
18
|
+
}
|
|
19
|
+
const host = ItemNode.parse({ id: 'item_strategy-resolver-host', asset, scale: [2, 1, 0.5] })
|
|
20
|
+
const child = ItemNode.parse({
|
|
21
|
+
id: 'item_strategy-resolver-child',
|
|
22
|
+
asset: { ...asset, dimensions: [0.5, 1, 0.5] },
|
|
23
|
+
rotation: [0.1, 0.2, 0.3],
|
|
24
|
+
})
|
|
25
|
+
let restoreRegistry: () => void
|
|
26
|
+
let savedNodes: ReturnType<typeof useScene.getState>['nodes']
|
|
27
|
+
let savedEditor: ReturnType<typeof useEditor.getState>
|
|
28
|
+
let savedScope: ReturnType<typeof useInteractionScope.getState>
|
|
29
|
+
let resolver: ReturnType<typeof spyOn<typeof core, 'resolveSurfacePlacement'>>
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
restoreRegistry = nodeRegistry._snapshot()
|
|
33
|
+
nodeRegistry._reset()
|
|
34
|
+
registerHostingTestNode({
|
|
35
|
+
kind: 'item',
|
|
36
|
+
schemaVersion: 1,
|
|
37
|
+
schema: ItemNode,
|
|
38
|
+
category: 'furnish',
|
|
39
|
+
snapProfile: 'item',
|
|
40
|
+
defaults: () => ({}),
|
|
41
|
+
capabilities: {},
|
|
42
|
+
})
|
|
43
|
+
savedNodes = useScene.getState().nodes
|
|
44
|
+
savedEditor = useEditor.getState()
|
|
45
|
+
savedScope = useInteractionScope.getState()
|
|
46
|
+
useScene.setState({ nodes: { [host.id]: host, [child.id]: child } })
|
|
47
|
+
useInteractionScope.setState({ scope: { kind: 'idle' } })
|
|
48
|
+
useEditor.setState({ mode: 'build', tool: 'item', gridSnapStep: 0.5 })
|
|
49
|
+
useEditor.getState().setSnappingMode('item', 'grid')
|
|
50
|
+
const mesh = new Group()
|
|
51
|
+
mesh.position.set(4, 2, -3)
|
|
52
|
+
mesh.rotation.set(0.1, Math.PI / 3, -0.1)
|
|
53
|
+
mesh.scale.set(2, 1, 0.5)
|
|
54
|
+
mesh.updateMatrixWorld(true)
|
|
55
|
+
sceneRegistry.nodes.set(host.id, mesh)
|
|
56
|
+
resolver = spyOn(core, 'resolveSurfacePlacement')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
resolver.mockRestore()
|
|
61
|
+
restoreRegistry()
|
|
62
|
+
sceneRegistry.nodes.delete(host.id)
|
|
63
|
+
useScene.setState({ nodes: savedNodes })
|
|
64
|
+
useEditor.setState(savedEditor)
|
|
65
|
+
useInteractionScope.setState(savedScope)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
function context(draftItem = child): PlacementContext {
|
|
69
|
+
return {
|
|
70
|
+
asset: draftItem.asset,
|
|
71
|
+
draftItem,
|
|
72
|
+
state: {
|
|
73
|
+
surface: 'floor',
|
|
74
|
+
wallId: null,
|
|
75
|
+
roofSegmentId: null,
|
|
76
|
+
ceilingId: null,
|
|
77
|
+
surfaceItemId: null,
|
|
78
|
+
shelfId: null,
|
|
79
|
+
},
|
|
80
|
+
currentCursorRotationY: 0.2,
|
|
81
|
+
gridPosition: new Vector3(),
|
|
82
|
+
levelId: 'level_test',
|
|
83
|
+
} as PlacementContext
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function hit(): ItemEvent {
|
|
87
|
+
const object = sceneRegistry.nodes.get(host.id)!
|
|
88
|
+
return {
|
|
89
|
+
node: host,
|
|
90
|
+
object,
|
|
91
|
+
normal: [0, 1, 0],
|
|
92
|
+
position: object.localToWorld(new Vector3(0.37, 0.81, -0.39)).toArray(),
|
|
93
|
+
localPosition: [0.37, 0.81, -0.39],
|
|
94
|
+
nativeEvent: {},
|
|
95
|
+
stopPropagation() {},
|
|
96
|
+
} as ItemEvent
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function onHost(ctx: PlacementContext): PlacementContext {
|
|
100
|
+
return { ...ctx, state: { ...ctx.state, surface: 'item-surface', surfaceItemId: host.id } }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Expected poses were captured from resolveItemSurfacePlacement at ad2a57b8 before its removal.
|
|
104
|
+
test.each([
|
|
105
|
+
[4.01, 1, 1.5],
|
|
106
|
+
[4, 1, 1.51],
|
|
107
|
+
] as [
|
|
108
|
+
number,
|
|
109
|
+
number,
|
|
110
|
+
number,
|
|
111
|
+
][])('enter and move accept oversized objects with their centres on the host: %j', (width, height, depth) => {
|
|
112
|
+
const draft = ItemNode.parse({
|
|
113
|
+
...child,
|
|
114
|
+
asset: { ...asset, dimensions: [width, height, depth] },
|
|
115
|
+
})
|
|
116
|
+
const ctx = context(draft)
|
|
117
|
+
const event = hit()
|
|
118
|
+
const before = useScene.getState().nodes
|
|
119
|
+
expect(itemSurfaceStrategy.enter(ctx, event)).not.toBeNull()
|
|
120
|
+
const expected: {
|
|
121
|
+
position: [number, number, number]
|
|
122
|
+
worldPosition: [number, number, number]
|
|
123
|
+
} =
|
|
124
|
+
width === 4.01
|
|
125
|
+
? {
|
|
126
|
+
position: [0.5049999999999999, 0.8099999999999996, -0.25],
|
|
127
|
+
worldPosition: [4.434656461734313, 2.8017166019018256, -3.927442316539199],
|
|
128
|
+
}
|
|
129
|
+
: {
|
|
130
|
+
position: [0.5, 0.8099999999999996, -0.245],
|
|
131
|
+
worldPosition: [4.4318465044173845, 2.8017248933478855, -3.9175249544338326],
|
|
132
|
+
}
|
|
133
|
+
const moved = itemSurfaceStrategy.move(onHost(ctx), event)!
|
|
134
|
+
expect(moved.nodeUpdate).toEqual({ position: expected.position })
|
|
135
|
+
expect(moved.cursorPosition).toEqual(expected.worldPosition)
|
|
136
|
+
expect(moved.cursorRotationY).toBe(ctx.currentCursorRotationY)
|
|
137
|
+
expect(resolver.mock.calls.map(([args]) => args.checkFootprint)).toEqual([true, true])
|
|
138
|
+
expect(useScene.getState().nodes).toBe(before)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test.each([
|
|
142
|
+
'grid',
|
|
143
|
+
'off',
|
|
144
|
+
] as const)('accepted poses match the frozen live capture with snapping %s', (mode) => {
|
|
145
|
+
useEditor.getState().setSnappingMode('item', mode)
|
|
146
|
+
const ctx = context()
|
|
147
|
+
const event = hit()
|
|
148
|
+
const expected: {
|
|
149
|
+
position: [number, number, number]
|
|
150
|
+
worldPosition: [number, number, number]
|
|
151
|
+
rotationY: number
|
|
152
|
+
} = {
|
|
153
|
+
...(mode === 'grid'
|
|
154
|
+
? {
|
|
155
|
+
position: [0.25, 0.8099999999999996, -0.25],
|
|
156
|
+
worldPosition: [4.180930399588417, 2.808503845962115, -3.4850883647019826],
|
|
157
|
+
}
|
|
158
|
+
: {
|
|
159
|
+
position: [0.36999999999999966, 0.8099999999999996, -0.39000000000000146],
|
|
160
|
+
worldPosition: [4.239709121156868, 2.808804018339912, -3.728080076057168],
|
|
161
|
+
}),
|
|
162
|
+
rotationY: -0.84936351290154,
|
|
163
|
+
}
|
|
164
|
+
const entered = itemSurfaceStrategy.enter(ctx, event)!
|
|
165
|
+
expect(entered.nodeUpdate).toEqual({
|
|
166
|
+
position: expected.position,
|
|
167
|
+
parentId: host.id,
|
|
168
|
+
rotation: [0.1, expected.rotationY, 0.3],
|
|
169
|
+
})
|
|
170
|
+
expect(entered.cursorPosition).toEqual(expected.worldPosition)
|
|
171
|
+
expect(itemSurfaceStrategy.move(onHost(ctx), event)!.nodeUpdate).toEqual({
|
|
172
|
+
position: expected.position,
|
|
173
|
+
})
|
|
174
|
+
expect(resolver).toHaveBeenCalledTimes(2)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('resolver rejection leaves both enter and move drafts alone', () => {
|
|
178
|
+
resolver.mockReturnValue(null)
|
|
179
|
+
const ctx = context()
|
|
180
|
+
const before = useScene.getState().nodes
|
|
181
|
+
expect(itemSurfaceStrategy.enter(ctx, hit())).toBeNull()
|
|
182
|
+
expect(itemSurfaceStrategy.move(onHost(ctx), hit())).toBeNull()
|
|
183
|
+
expect(useScene.getState().nodes).toBe(before)
|
|
184
|
+
expect(ctx.draftItem).toBe(child)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('move still rejects side hits and missing normals', () => {
|
|
188
|
+
for (const normal of [[1, 0, 0], [0, -1, 0], undefined] as ItemEvent['normal'][]) {
|
|
189
|
+
const event = { ...hit(), normal }
|
|
190
|
+
expect(itemSurfaceStrategy.enter(context(), event)).toBeNull()
|
|
191
|
+
expect(itemSurfaceStrategy.move(onHost(context()), event)).toBeNull()
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('enter rejects itself and indirect descendants before asking the resolver', () => {
|
|
196
|
+
expect(itemSurfaceStrategy.enter(context(host), hit())).toBeNull()
|
|
197
|
+
const middle = ItemNode.parse({ id: 'item_strategy-middle', parentId: child.id, asset })
|
|
198
|
+
const descendant = { ...host, parentId: middle.id }
|
|
199
|
+
useScene.setState({
|
|
200
|
+
nodes: { ...useScene.getState().nodes, [middle.id]: middle, [host.id]: descendant },
|
|
201
|
+
})
|
|
202
|
+
expect(itemSurfaceStrategy.enter(context(), { ...hit(), node: descendant })).toBeNull()
|
|
203
|
+
expect(resolver).not.toHaveBeenCalled()
|
|
204
|
+
})
|