feat(editor): node-declared per-context snapping + contextual HUD + painter scope
Generify the snapping/modifier HUD off the FSM scope and node declarations
instead of wall-creation-shaped, leaking pills.
- Per-context snapping (`snappingModeByContext`, persisted): wall / item /
polygon mode-sets with exclusive modes (grid | lines | angles | off), each
doing exactly what its chip says. Context is node-declared via the new
`NodeDefinition.snapProfile` ('item' | 'structural'); the resolver maps
(profile × action) → context with no per-kind switch.
- Scope-driven HUD: helper-manager reads the interaction scope; reshaping
(endpoint/curve/boundary) and item move get their own chip, no select-hint
leak. Rotate R/T rounds to 45°; Alt = force-place only (hidden for
structural kinds); Shift = cycle everywhere.
- Slab/ceiling drafting: Shift=cycle, mode-aware grid/angle, Enter finishes
(minDraftVertices); polygon boundary vertex/edge drag begins a reshaping
scope. Fix grid/angle being ignored on boundary edit + slab creation:
make resolveSurfacePlanPointSnap exclusive (alignment gated on magnetic) so
grid/angles keep the snapped fallback instead of the raw cursor.
- Painter application scope: node-derived (single/object/matching/room) from
the hovered node, cyclable via Shift, single-source HUD chip.
- Remove the redundant GridSnapControl from view-toggles (grid step lives in
the contextual HUD now).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b8b3d35f26
commit
04f1b0d59e
@@ -2,10 +2,12 @@
|
||||
|
||||
import { resolveLevelId, type SlabNode, useLiveNodeOverrides, useScene } from '@pascal-app/core'
|
||||
import {
|
||||
boundaryReshapeScope,
|
||||
clearSlabSnapFeedback,
|
||||
PolygonEditor,
|
||||
type PolygonEditorPlanPointSnapContext,
|
||||
resolveSlabPlanPointSnap,
|
||||
useInteractionScope,
|
||||
} from '@pascal-app/editor'
|
||||
import { useViewer } from '@pascal-app/viewer'
|
||||
import { useCallback, useEffect } from 'react'
|
||||
@@ -65,6 +67,17 @@ export const SlabBoundaryEditor: React.FC<{ slabId: SlabNode['id'] }> = ({ slabI
|
||||
clearSlabSnapFeedback()
|
||||
}, [])
|
||||
|
||||
// A vertex/edge drag is a `boundary` reshape — drive the snapping HUD (the
|
||||
// no-angle 'polygon' set) and keep the idle select hints off-screen.
|
||||
const handleDragStateChange = useCallback(
|
||||
(isDragging: boolean) => {
|
||||
const scope = useInteractionScope.getState()
|
||||
if (isDragging) scope.begin(boundaryReshapeScope(slabId))
|
||||
else scope.endIf((s) => s.kind === 'reshaping' && s.reshape === 'boundary')
|
||||
},
|
||||
[slabId],
|
||||
)
|
||||
|
||||
const resolvePolygonEditorPlanPoint = useCallback(
|
||||
(context: PolygonEditorPlanPointSnapContext) =>
|
||||
resolveSlabPlanPointSnap({
|
||||
@@ -73,7 +86,6 @@ export const SlabBoundaryEditor: React.FC<{ slabId: SlabNode['id'] }> = ({ slabI
|
||||
levelId: slabLevelId,
|
||||
excludeId: slabId,
|
||||
altKey: context.nativeEvent?.altKey === true,
|
||||
shiftKey: context.nativeEvent?.shiftKey === true,
|
||||
}).point,
|
||||
[slabId, slabLevelId],
|
||||
)
|
||||
@@ -86,6 +98,9 @@ export const SlabBoundaryEditor: React.FC<{ slabId: SlabNode['id'] }> = ({ slabI
|
||||
clearSlabSnapFeedback()
|
||||
useLiveNodeOverrides.getState().clear(slabId)
|
||||
useScene.getState().markDirty(slabId)
|
||||
useInteractionScope
|
||||
.getState()
|
||||
.endIf((s) => s.kind === 'reshaping' && s.reshape === 'boundary')
|
||||
}
|
||||
}, [slabId])
|
||||
|
||||
@@ -98,6 +113,7 @@ export const SlabBoundaryEditor: React.FC<{ slabId: SlabNode['id'] }> = ({ slabI
|
||||
levelId={slabLevelId ?? undefined}
|
||||
minVertices={3}
|
||||
onDragCommit={handleDragCommit}
|
||||
onDragStateChange={handleDragStateChange}
|
||||
onPolygonChange={handlePolygonChange}
|
||||
onPolygonPreview={handlePolygonPreview}
|
||||
polygon={slab.polygon}
|
||||
|
||||
@@ -133,6 +133,7 @@ function slabHandles(_node: SlabNodeType): HandleDescriptor<SlabNodeType>[] {
|
||||
*/
|
||||
export const slabDefinition: NodeDefinition<typeof SlabNode> = {
|
||||
kind: 'slab',
|
||||
snapProfile: 'structural',
|
||||
schemaVersion: 1,
|
||||
schema: SlabNode,
|
||||
category: 'structure',
|
||||
@@ -206,8 +207,7 @@ export const slabDefinition: NodeDefinition<typeof SlabNode> = {
|
||||
|
||||
toolHints: [
|
||||
{ key: 'Left click', label: 'Trace slab outline' },
|
||||
{ key: 'Enter', label: 'Finish slab' },
|
||||
{ key: 'Shift', label: 'Free outline' },
|
||||
{ key: 'Enter', label: 'Finish slab', minDraftVertices: 3 },
|
||||
{ key: 'Esc', label: 'Cancel' },
|
||||
],
|
||||
|
||||
|
||||
@@ -169,18 +169,15 @@ export const MoveSlabTool: React.FC<{ node: SlabNode }> = ({ node }) => {
|
||||
const onGridMove = (event: GridEvent) => {
|
||||
if (isFloorplanSourcedEvent(event)) return
|
||||
const gridStep = getSegmentGridStep()
|
||||
const bypassSnap = event.nativeEvent?.shiftKey === true
|
||||
const [localX, localZ] = snapFenceDraftPoint({
|
||||
point: [event.localPosition[0], event.localPosition[2]],
|
||||
walls: levelWalls,
|
||||
fences: levelFences,
|
||||
bypassSnap,
|
||||
magnetic: !bypassSnap && isMagneticSnapActive(),
|
||||
magnetic: isMagneticSnapActive(),
|
||||
gridSnap: (p) => snapBuildingLocalToWorldGrid(p, gridStep),
|
||||
})
|
||||
|
||||
if (
|
||||
!bypassSnap &&
|
||||
previousGridPosRef.current &&
|
||||
(localX !== previousGridPosRef.current[0] || localZ !== previousGridPosRef.current[1])
|
||||
) {
|
||||
@@ -196,8 +193,8 @@ export const MoveSlabTool: React.FC<{ node: SlabNode }> = ({ node }) => {
|
||||
|
||||
// Figma-style alignment snap: align the slab's translated polygon
|
||||
// vertices to other objects' anchors; fold the snap into the delta and
|
||||
// publish a guide. Alt bypasses alignment; Shift bypasses all snap.
|
||||
const bypass = event.nativeEvent?.altKey === true || bypassSnap
|
||||
// publish a guide. Alignment follows the global magnetic snap mode.
|
||||
const bypass = !isMagneticSnapActive()
|
||||
if (!bypass && alignmentCandidates.length > 0) {
|
||||
const result = resolveAlignmentForActiveBuilding({
|
||||
moving: polygonAnchors(slabId, translatePolygon(originalPolygon, deltaX, deltaZ)),
|
||||
|
||||
@@ -8,6 +8,7 @@ import { createSlotPaintCapability, previewGeometrySlot } from '../shared/slot-p
|
||||
* `node.slots[slotId]` (a shared scene-material or `library:` ref) like the shelf.
|
||||
*/
|
||||
export const slabPaint = createSlotPaintCapability({
|
||||
roomScope: true,
|
||||
resolveRole: ({ hitObject }) => {
|
||||
const slotId = (hitObject?.userData as { slotId?: string } | undefined)?.slotId
|
||||
return slotId === 'side' ? 'side' : 'surface'
|
||||
|
||||
@@ -13,6 +13,8 @@ import {
|
||||
CursorSphere,
|
||||
clearSlabSnapFeedback,
|
||||
EDITOR_LAYER,
|
||||
isAngleSnapActive,
|
||||
isGridSnapActive,
|
||||
markToolCancelConsumed,
|
||||
resolveSlabPlanPointSnap,
|
||||
triggerSFX,
|
||||
@@ -62,7 +64,6 @@ export const SlabTool: React.FC = () => {
|
||||
const [snappedCursorPosition, setSnappedCursorPosition] = useState<[number, number]>([0, 0])
|
||||
const [levelY, setLevelY] = useState(0)
|
||||
const previousSnappedPointRef = useRef<[number, number] | null>(null)
|
||||
const shiftPressed = useRef(false)
|
||||
|
||||
// Clear preset-seeded defaults on deactivation so a later manual slab draw
|
||||
// isn't built with a stale preset's parameters. Unmount-only.
|
||||
@@ -70,42 +71,39 @@ export const SlabTool: React.FC = () => {
|
||||
|
||||
useEffect(() => () => clearSlabSnapFeedback(), [])
|
||||
|
||||
// Publish the live vertex count so the HUD shows "Finish" only at ≥ 3 points.
|
||||
useEffect(() => {
|
||||
useEditor.getState().setDraftVertexCount(points.length)
|
||||
}, [points.length])
|
||||
useEffect(() => () => useEditor.getState().setDraftVertexCount(0), [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentLevelId) return
|
||||
|
||||
const onGridMove = (event: GridEvent) => {
|
||||
if (!cursorRef.current) return
|
||||
const rawPoint: [number, number] = [event.localPosition[0], event.localPosition[2]]
|
||||
const bypassSnap = shiftPressed.current || event.nativeEvent?.shiftKey === true
|
||||
const gridPosition: [number, number] = bypassSnap
|
||||
? rawPoint
|
||||
: [...snapPointToGrid(rawPoint, useEditor.getState().gridSnapStep)]
|
||||
// Slab drafting is the 'polygon' snap context (grid / lines / off — no
|
||||
// angle, no Shift bypass; Shift cycles the mode, Off is the bypass).
|
||||
const gridStep = isGridSnapActive() ? useEditor.getState().gridSnapStep : 0
|
||||
const gridPosition: [number, number] = [...snapPointToGrid(rawPoint, gridStep)]
|
||||
setCursorPosition(gridPosition)
|
||||
setLevelY(event.localPosition[1])
|
||||
const lastPoint = points[points.length - 1]
|
||||
// 15° angle snap from the raw cursor (matching the 2D floorplan
|
||||
// pipeline) with the distance snapped along the ray to the grid step.
|
||||
// Angle lock only when the mode asks for it (polygon never does today, but
|
||||
// honour the flag so the behaviour follows the HUD).
|
||||
const orthoPoint: [number, number] =
|
||||
bypassSnap || !lastPoint
|
||||
? gridPosition
|
||||
: [
|
||||
...snapPointAlongAngleRay(
|
||||
lastPoint,
|
||||
rawPoint,
|
||||
DEFAULT_ANGLE_STEP,
|
||||
useEditor.getState().gridSnapStep,
|
||||
),
|
||||
]
|
||||
isAngleSnapActive() && lastPoint
|
||||
? [...snapPointAlongAngleRay(lastPoint, rawPoint, DEFAULT_ANGLE_STEP, gridStep)]
|
||||
: gridPosition
|
||||
const displayPoint = resolveSlabPlanPointSnap({
|
||||
rawPoint,
|
||||
fallbackPoint: orthoPoint,
|
||||
levelId: currentLevelId,
|
||||
altKey: event.nativeEvent?.altKey === true,
|
||||
shiftKey: bypassSnap,
|
||||
}).point
|
||||
setSnappedCursorPosition(displayPoint)
|
||||
if (
|
||||
!bypassSnap &&
|
||||
points.length > 0 &&
|
||||
previousSnappedPointRef.current &&
|
||||
(displayPoint[0] !== previousSnappedPointRef.current[0] ||
|
||||
@@ -139,14 +137,18 @@ export const SlabTool: React.FC = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Finish the polygon (Enter or double-click): commit once there are enough
|
||||
// vertices. Closing near the first vertex (in onGridClick) is the third way.
|
||||
const finishDrawing = () => {
|
||||
if (points.length < 3) return
|
||||
const slabId = commitSlabDrawing(currentLevelId, points)
|
||||
setSelection({ selectedIds: [slabId] })
|
||||
setPoints([])
|
||||
clearSlabSnapFeedback()
|
||||
}
|
||||
|
||||
const onGridDoubleClick = (_event: GridEvent) => {
|
||||
if (!currentLevelId) return
|
||||
if (points.length >= 3) {
|
||||
const slabId = commitSlabDrawing(currentLevelId, points)
|
||||
setSelection({ selectedIds: [slabId] })
|
||||
setPoints([])
|
||||
clearSlabSnapFeedback()
|
||||
}
|
||||
finishDrawing()
|
||||
}
|
||||
|
||||
const onCancel = () => {
|
||||
@@ -156,17 +158,12 @@ export const SlabTool: React.FC = () => {
|
||||
}
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Shift') shiftPressed.current = true
|
||||
}
|
||||
const onKeyUp = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Shift') shiftPressed.current = false
|
||||
}
|
||||
const onWindowBlur = () => {
|
||||
shiftPressed.current = false
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
finishDrawing()
|
||||
}
|
||||
}
|
||||
document.addEventListener('keydown', onKeyDown)
|
||||
document.addEventListener('keyup', onKeyUp)
|
||||
window.addEventListener('blur', onWindowBlur)
|
||||
|
||||
emitter.on('grid:move', onGridMove)
|
||||
emitter.on('grid:click', onGridClick)
|
||||
@@ -175,8 +172,6 @@ export const SlabTool: React.FC = () => {
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', onKeyDown)
|
||||
document.removeEventListener('keyup', onKeyUp)
|
||||
window.removeEventListener('blur', onWindowBlur)
|
||||
emitter.off('grid:move', onGridMove)
|
||||
emitter.off('grid:click', onGridClick)
|
||||
emitter.off('grid:double-click', onGridDoubleClick)
|
||||
|
||||
Reference in New Issue
Block a user