refactor: Add point snapping functionality and enhance aisle management with new Point and Gizmo components

This commit is contained in:
2025-05-30 14:33:55 +05:30
parent 0e0a53bd5a
commit 63bb7c84aa
10 changed files with 234 additions and 77 deletions

View File

@@ -6,14 +6,16 @@ import { DragControls } from '@react-three/drei';
import { useAisleStore } from '../../../store/builder/useAisleStore';
import { useThree } from '@react-three/fiber';
import { useBuilderStore } from '../../../store/builder/useBuilderStore';
import { usePointSnapping } from './usePointSnapping';
function Point({ point, userData }: { readonly point: Point, readonly userData: any }) {
function Point({ point }: { readonly point: Point }) {
const materialRef = useRef<THREE.ShaderMaterial>(null);
const { raycaster, camera, pointer } = useThree();
const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []);
const [isHovered, setIsHovered] = useState(false);
const { toolMode } = useToolMode();
const { setPosition, removePoint } = useAisleStore();
const { checkSnapForAisle } = usePointSnapping(point);
const { hoveredPoint, setHoveredPoint } = useBuilderStore();
const { deletePointOrLine } = useDeletePointOrLine();
@@ -53,9 +55,12 @@ function Point({ point, userData }: { readonly point: Point, readonly userData:
raycaster.setFromCamera(pointer, camera);
const intersectionPoint = new THREE.Vector3();
const position = raycaster.ray.intersectPlane(plane, intersectionPoint);
if (userData.pointType === 'Aisle') {
if (point.pointType === 'Aisle') {
if (position) {
setPosition(point.uuid, [position.x, position.y, position.z]);
const newPosition: [number, number, number] = [position.x, position.y, position.z];
const snappedPosition = checkSnapForAisle(newPosition);
setPosition(point.uuid, snappedPosition);
}
}
}
@@ -113,7 +118,7 @@ function Point({ point, userData }: { readonly point: Point, readonly userData:
}
setIsHovered(false)
}}
userData={userData}
userData={point}
>
<boxGeometry args={boxScale} />
<shaderMaterial