Merge pull request 'ui/scene: dont snap to occupied positions' (#4967) from fixes-ui into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4967
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user