From 360048fd0486f2501fc68b1f3a0fe48cedd040cf Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 26 Aug 2025 11:40:38 +0200 Subject: [PATCH] ui/scene: dont snap to occupied positions --- pkgs/clan-app/ui/src/scene/cubes.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/clan-app/ui/src/scene/cubes.tsx b/pkgs/clan-app/ui/src/scene/cubes.tsx index 5e215dab4..07de67fc1 100644 --- a/pkgs/clan-app/ui/src/scene/cubes.tsx +++ b/pkgs/clan-app/ui/src/scene/cubes.tsx @@ -506,6 +506,7 @@ export function CubeScene(props: { const intersects = raycaster.intersectObject(floor); if (intersects.length > 0) { const point = intersects[0].point; + // Snap to grid const snapped = new THREE.Vector3( Math.round(point.x / GRID_SIZE) * GRID_SIZE, @@ -513,6 +514,17 @@ export function CubeScene(props: { Math.round(point.z / GRID_SIZE) * GRID_SIZE, ); + // Skip snapping if there's already a cube at this position + if (props.sceneStore()) { + const positions = Object.values(props.sceneStore()); + const intersects = positions.some( + (p) => p.position[0] === snapped.x && p.position[1] === snapped.z, + ); + if (intersects) { + return; + } + } + if ( Math.abs(initBase.position.x - snapped.x) > 0.01 || Math.abs(initBase.position.z - snapped.z) > 0.01