diff --git a/src/components/voxelEditor/VoxelEditorScene.tsx b/src/components/voxelEditor/VoxelEditorScene.tsx index 0cd5132..1c13c4d 100644 --- a/src/components/voxelEditor/VoxelEditorScene.tsx +++ b/src/components/voxelEditor/VoxelEditorScene.tsx @@ -1,5 +1,5 @@ import { OrbitControls } from '@react-three/drei'; -import { useState, useRef } from 'react'; +import { useState } from 'react'; import type { ThreeEvent } from '@react-three/fiber'; import type { Voxel, V3 } from '../../types'; @@ -12,7 +12,7 @@ type Props = { onRemove: (position: V3) => void; }; -const FLOOR_Y = -0.5; +const FLOOR_Y = 0; function adjPosition(pos: V3, nx: number, ny: number, nz: number): V3 { return [pos[0] + Math.round(nx), pos[1] + Math.round(ny), pos[2] + Math.round(nz)]; @@ -22,12 +22,13 @@ function posEq(a: V3, b: V3) { return a[0] === b[0] && a[1] === b[1] && a[2] === b[2]; } +const DRAG_THRESHOLD = 5; + export function VoxelEditorScene({ voxels, mode, color, typeId, onAdd, onRemove }: Props) { const [ghost, setGhost] = useState(null); - const isDragging = useRef(false); function handleVoxelClick(e: ThreeEvent, voxel: Voxel) { - if (isDragging.current) return; + if (e.delta > DRAG_THRESHOLD) return; e.stopPropagation(); if (mode === 'remove') { onRemove(voxel.position); @@ -40,7 +41,8 @@ export function VoxelEditorScene({ voxels, mode, color, typeId, onAdd, onRemove } } - function handleVoxelMove(_e: ThreeEvent, voxel: Voxel) { + function handleVoxelMove(e: ThreeEvent, voxel: Voxel) { + e.stopPropagation(); if (mode === 'remove') { setGhost(voxel.position); } else { @@ -49,7 +51,7 @@ export function VoxelEditorScene({ voxels, mode, color, typeId, onAdd, onRemove } function handleFloorClick(e: ThreeEvent) { - if (isDragging.current || mode !== 'add') return; + if (e.delta > DRAG_THRESHOLD || mode !== 'add') return; e.stopPropagation(); const pos: V3 = [Math.floor(e.point.x), 0, Math.floor(e.point.z)]; onAdd({ typeId, position: pos, color }); @@ -67,11 +69,7 @@ export function VoxelEditorScene({ voxels, mode, color, typeId, onAdd, onRemove - { isDragging.current = false; }} - onChange={() => { isDragging.current = true; }} - /> + {/* Floor plane */}