diff --git a/src/hooks/useCreateLine.ts b/src/hooks/useCreateLine.ts index cf4bf31..9199303 100644 --- a/src/hooks/useCreateLine.ts +++ b/src/hooks/useCreateLine.ts @@ -1,6 +1,7 @@ import { useEffect, useRef } from 'react' import { useThree } from '@react-three/fiber' -import { Line2, LineGeometry, LineMaterial } from 'three-stdlib' +import type { LineMaterial } from 'three-stdlib' +import { Line2, LineGeometry } from 'three-stdlib' import { BufferAttribute, BufferGeometry, Points, PointsMaterial, Vector3 } from 'three' import useModeStore from '@/store/mode' @@ -21,20 +22,6 @@ const useCreateLine = () => { const { scene } = useThree() const { drawline } = useModeStore(state => state) - const initCreateLine = () => { - const geometry = new LineGeometry() - geometry.setPositions(pointsRef.current) - const material = new LineMaterial({ color: 0x000000, linewidth: 0.001 }) - - const line = new Line2(geometry, material) - lineRef.current = line - - scene.add(line) - geometry.attributes.position.needsUpdate = true - - return geometry - } - /** * line first point helper show * @param x @@ -144,13 +131,8 @@ const useCreateLine = () => { } useEffect(() => { - if (drawline) { - const setFunction = initCreateLine() - geometryRef.current = setFunction - } - else { + if (!drawline) destroyLine() - } }, [drawline]) return [pushPoint, tryPushPoint]