Smooth per-vertex heatmap animation in react-three-fiber
@tylerd▲ 0 net votes
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.