Autofocus

An auto-focus effect, that extends <DepthOfField>.

Based on ektogamat/AutoFocusDOF.

export type AutofocusProps = typeof DepthOfField & {
  target?: [number, number, number] // undefined
  mouse?: boolean // false
  debug?: number // undefined
  manual?: boolean // false
  smoothTime?: number // .25
}
<EffectComposer>
  <Autofocus />
</EffectComposer>

Ref-api:

type AutofocusApi = {
  dofRef: RefObject<DepthOfFieldEffect>
  hitpoint: THREE.Vector3
  update: (delta: number, updateTarget: boolean) => void
}
<Autofocus ref={autofocusRef} />

Associated with manual prop, you can for example, animate the DOF target yourself:

useFrame((_, delta) => {
  const api = autofocusRef.current
  api.update(delta, false) // update hitpoint only
  easing.damp3(api.dofRef.curent.target, api.hitpoint, 0.5, delta) // custom easing
})

Example

Autofocus (TS + refApi)
Autofocus (TS + refApi)