From 0edbc65e8d15916696c2b365315b932d2a4b1268 Mon Sep 17 00:00:00 2001 From: Aymeric Rabot Date: Tue, 3 Mar 2026 16:22:08 -0500 Subject: [PATCH] Update polygon-editor.tsx --- .../tools/shared/polygon-editor.tsx | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/apps/editor/components/tools/shared/polygon-editor.tsx b/apps/editor/components/tools/shared/polygon-editor.tsx index ff4ea609..971b20e5 100644 --- a/apps/editor/components/tools/shared/polygon-editor.tsx +++ b/apps/editor/components/tools/shared/polygon-editor.tsx @@ -1,8 +1,7 @@ import { emitter, type GridEvent, sceneRegistry } from '@pascal-app/core' -import { useViewer } from '@pascal-app/viewer' import { createPortal } from '@react-three/fiber' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' -import { BufferGeometry, Float32BufferAttribute, type Mesh } from 'three' +import { BufferGeometry, Float32BufferAttribute, type Line } from 'three' import { EDITOR_LAYER } from '@/lib/constants' import { sfxEmitter } from '@/lib/sfx-bus' @@ -61,7 +60,7 @@ export const PolygonEditor: React.FC = ({ const [hoveredMidpoint, setHoveredMidpoint] = useState(null) const [cursorPosition, setCursorPosition] = useState<[number, number]>([0, 0]) - const lineRef = useRef(null!) + const lineRef = useRef(null!) const previousPositionRef = useRef<[number, number] | null>(null) // Track the last polygon prop to detect external changes (undo/redo) @@ -145,8 +144,12 @@ export const PolygonEditor: React.FC = ({ const newPosition: [number, number] = [gridX, gridZ] // Play snap sound when cursor moves to a new grid cell during drag - if (dragState?.isDragging && previousPositionRef.current && - (newPosition[0] !== previousPositionRef.current[0] || newPosition[1] !== previousPositionRef.current[1])) { + if ( + dragState?.isDragging && + previousPositionRef.current && + (newPosition[0] !== previousPositionRef.current[0] || + newPosition[1] !== previousPositionRef.current[1]) + ) { sfxEmitter.emit('sfx:grid-snap') } @@ -171,7 +174,12 @@ export const PolygonEditor: React.FC = ({ const handlePointerUp = (e: PointerEvent | MouseEvent) => { // Only handle the specific pointer that started the drag, if it's a PointerEvent - if ('pointerId' in e && dragState.pointerId !== undefined && e.pointerId !== dragState.pointerId) return + if ( + 'pointerId' in e && + dragState.pointerId !== undefined && + e.pointerId !== dragState.pointerId + ) + return // Stop the event from propagating to prevent grid click e.stopImmediatePropagation() @@ -225,10 +233,16 @@ export const PolygonEditor: React.FC = ({ const canDelete = displayPolygon.length > minVertices const editorContent = ( - + {/* Border line */} - {/* @ts-ignore */} - {}} layers={EDITOR_LAYER}> + element conflicts with SVG type + ref={lineRef} + frustumCulled={false} + renderOrder={10} + raycast={() => {}} + layers={EDITOR_LAYER} + >