From 247180ebf913e1e611a0f6cf2c32e2454131b379 Mon Sep 17 00:00:00 2001 From: wass08 Date: Thu, 29 Jan 2026 07:27:07 +0900 Subject: [PATCH] push item when placing --- .../tools/item/use-placement-coordinator.tsx | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/editor/components/tools/item/use-placement-coordinator.tsx b/apps/editor/components/tools/item/use-placement-coordinator.tsx index c4e6f653..94a4285a 100644 --- a/apps/editor/components/tools/item/use-placement-coordinator.tsx +++ b/apps/editor/components/tools/item/use-placement-coordinator.tsx @@ -7,11 +7,13 @@ import { useScene, useSpatialQuery, type WallEvent, + type WallNode, } from '@pascal-app/core' import { useViewer } from '@pascal-app/viewer' import { useFrame } from '@react-three/fiber' import { useEffect, useRef } from 'react' import { BoxGeometry, Euler, type Mesh, type MeshStandardMaterial, Quaternion, Vector3 } from 'three' +import { spatialGridManager } from '../../../../../packages/core/src/hooks/spatial-grid/spatial-grid-manager' import { resolveLevelId } from '../../../../../packages/core/src/hooks/spatial-grid/spatial-grid-sync' import { ceilingStrategy, @@ -231,6 +233,15 @@ export function usePlacementCoordinator(config: PlacementCoordinatorConfig): Rea mesh.position.copy(gridPosition.current) const rot = result.nodeUpdate?.rotation if (rot) mesh.rotation.y = rot[1] + + // Push wall-side items out by half the parent wall's thickness + if (asset.attachTo === 'wall-side' && placementState.current.wallId) { + const parentWall = useScene.getState().nodes[placementState.current.wallId as AnyNodeId] + if (parentWall?.type === 'wall') { + const wallThickness = (parentWall as WallNode).thickness ?? 0.1 + mesh.position.z = (wallThickness / 2) * (draft.side === 'front' ? 1 : -1) + } + } } // Mark parent wall dirty so it rebuilds geometry — only when position changed if (result.dirtyNodeId && posChanged) { @@ -480,9 +491,22 @@ export function usePlacementCoordinator(config: PlacementCoordinatorConfig): Rea const distance = mesh.position.distanceToSquared(gridPosition.current) if (distance > 1) { mesh.position.copy(gridPosition.current) - return + } else { + mesh.position.lerp(gridPosition.current, delta * 20) + } + + // Adjust Y for slab elevation (floor items on top of slabs) + if (!asset.attachTo) { + const levelId = useViewer.getState().selection.levelId + if (levelId) { + mesh.position.y = spatialGridManager.getSlabElevationForItem( + levelId, + [gridPosition.current.x, gridPosition.current.y, gridPosition.current.z], + asset.dimensions, + draftNode.current.rotation, + ) + } } - mesh.position.lerp(gridPosition.current, delta * 20) } })