@@ -37,7 +37,8 @@ export const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(
37
37
const hitpointRef = useRef < THREE . Mesh > ( null )
38
38
const targetRef = useRef < THREE . Mesh > ( null )
39
39
40
- const { size, gl, scene } = useThree ( )
40
+ const scene = useThree ( ( { scene } ) => scene )
41
+ const pointer = useThree ( ( { pointer } ) => pointer )
41
42
const { composer, camera } = useContext ( EffectComposerContext )
42
43
43
44
// see: https://codesandbox.io/s/depthpickingpass-x130hg
@@ -67,25 +68,6 @@ export const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(
67
68
[ ndc , depthPickingPass , camera ]
68
69
)
69
70
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
-
89
71
const update = useCallback (
90
72
async ( delta : number , updateTarget = true ) => {
91
73
// Update hitpoint
@@ -110,11 +92,9 @@ export const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(
110
92
)
111
93
112
94
useFrame ( async ( _ , delta ) => {
113
- if ( manual ) return
114
- update ( delta )
115
- } )
116
-
117
- useFrame ( ( ) => {
95
+ if ( ! manual ) {
96
+ update ( delta )
97
+ }
118
98
if ( hitpointRef . current ) {
119
99
hitpointRef . current . position . copy ( hitpoint )
120
100
}
0 commit comments