Skip to content

Commit 84be37b

Browse files
committed
fixes review drcmda
1 parent d2b6a5b commit 84be37b

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

src/Autofocus.tsx

+5-25
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(
3737
const hitpointRef = useRef<THREE.Mesh>(null)
3838
const targetRef = useRef<THREE.Mesh>(null)
3939

40-
const { size, gl, scene } = useThree()
40+
const scene = useThree(({ scene }) => scene)
41+
const pointer = useThree(({ pointer }) => pointer)
4142
const { composer, camera } = useContext(EffectComposerContext)
4243

4344
// see: https://codesandbox.io/s/depthpickingpass-x130hg
@@ -67,25 +68,6 @@ export const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(
6768
[ndc, depthPickingPass, camera]
6869
)
6970

70-
const [pointer] = useState(new THREE.Vector2())
71-
useEffect(() => {
72-
if (!followMouse) return
73-
74-
async function onPointermove(e: PointerEvent) {
75-
const clientX = e.clientX - size.left
76-
const clientY = e.clientY - size.top
77-
const x = (clientX / size.width) * 2.0 - 1.0
78-
const y = -(clientY / size.height) * 2.0 + 1.0
79-
80-
pointer.set(x, y)
81-
}
82-
gl.domElement.addEventListener('pointermove', onPointermove, {
83-
passive: true,
84-
})
85-
86-
return () => void gl.domElement.removeEventListener('pointermove', onPointermove)
87-
}, [gl.domElement, hitpoint, size, followMouse, getHit, pointer])
88-
8971
const update = useCallback(
9072
async (delta: number, updateTarget = true) => {
9173
// Update hitpoint
@@ -110,11 +92,9 @@ export const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(
11092
)
11193

11294
useFrame(async (_, delta) => {
113-
if (manual) return
114-
update(delta)
115-
})
116-
117-
useFrame(() => {
95+
if (!manual) {
96+
update(delta)
97+
}
11898
if (hitpointRef.current) {
11999
hitpointRef.current.position.copy(hitpoint)
120100
}

0 commit comments

Comments
 (0)