Skip to content

Instantly share code, notes, and snippets.

@RenaudRohlinger
Created September 8, 2022 06:15
Show Gist options
  • Save RenaudRohlinger/02909775cedc192f2c602b94e6806f0a to your computer and use it in GitHub Desktop.
Save RenaudRohlinger/02909775cedc192f2c602b94e6806f0a to your computer and use it in GitHub Desktop.
Synchronize gsap and r3f raf loop
import React, { useEffect } from 'react'
import gsap from 'gsap'
import { useFrame } from '@react-three/fiber'
// sync gsap raf to r3f raf
gsap.ticker.remove(gsap.updateRoot)
export const GsapTicker = () => {
const pg = React.useRef(0)
gsap.ticker.remove(gsap.updateRoot)
useFrame((_, delta) => {
pg.current += delta
gsap.updateRoot(pg.current)
})
useEffect(() => {
return () => {
gsap.ticker.remove(gsap.updateRoot)
}
})
return null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment