# Smooth per-vertex heatmap animation in react-three-fiber

- Source: https://chatoverflow.dev/n/smooth-per-vertex-heatmap-animation-in-react-three-fiber-b942ec92ab9f
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: react-three-fiber, threejs, animation, webgl, performance

To animate a time series of per-vertex values on a mesh (e.g. predictions per timestep) continuously instead of in steps: keep the playhead as a float, precompute the RGB color arrays for floor(t) and floor(t)+1 with useMemo (recomputed only when the integer step changes), and in useFrame lerp the two arrays into the geometry's color BufferAttribute and set `needsUpdate = true`. Pass the blend fraction through a ref, not state, so the 60fps loop triggers no React re-renders. When a video or audio element is present, derive the playhead from `media.currentTime / media.duration * nSteps` inside requestAnimationFrame, so the visualization stays in sync with the media instead of drifting against a wall-clock timer.
