GUIDE // THREE.JS

How to loop a fire or smoke sprite sheet animation in three.js

Read the elapsed time from a THREE.Clock inside your animation loop, multiply it by the sheet's frame rate, round down and wrap it with the frame count, then set the texture offset to that frame's cell on every tick. A sheet whose last frame flows into its first then keeps looping without a visible jump.

  • Godot 4 Available
  • Unity Manual setup
  • Unreal Engine Manual setup
  • Roblox Studio Manual setup
  • three.js Available

A draft compile is from $0.05, and new accounts start with $5 of usage.

FIREFINAL
First frame of the fire bake
Fire, 4.1 x 7.0 m, compiled with Spatial Compiler. Spec →

01 // HOW TO

Loop the 2 s fire

  1. Load the sheet and set texture.repeat to 1/8 by 1/8, as in the loading guide.
  2. Take the frame rate from layout.json. The fire has 64 frames over 2 s, so 32 frames per second.
  3. Inside renderer.setAnimationLoop, compute the frame from elapsed time, wrap it with % 64 and set the offset.
  4. For the 4 s smoke plume, change the rate to 16.
loopFire.js
import * as THREE from 'three';

const FPS = 32;    // 64 frames over the 2 s fire loop
const FRAMES = 64;
const clock = new THREE.Clock();

renderer.setAnimationLoop(() => {
  const frame = Math.floor(clock.getElapsedTime() * FPS) % FRAMES;
  texture.offset.set((frame % 8) / 8, 1 - (Math.floor(frame / 8) + 1) / 8);
  renderer.render(scene, camera);
});

02 // REAL OUTPUT

A slower loop

The smoke plume runs twice as long per loop as the fire, so it needs half the rate.

SMOKE_PLUMEFINAL
First frame of the smoke_plume bake
Smoke plume, 7.0 x 10.8 m, compiled with Spatial Compiler. Spec →

03 // WHY TIME

Drive the frame from elapsed time

Adding one frame per tick ties the speed to the screen, so the fire burns twice as fast on a 120 Hz display as on a 60 Hz one. Elapsed time plays the clip at its real speed everywhere, and when a hidden browser tab resumes, the loop picks up at the right frame.

The wrap with % only looks right on a sheet made to loop. The looping example compiles from Spatial Compiler blend their last 12 frames into the first, so frame 63 leads into frame 0.

Godot 4 gets a ready scene that relights the smoke. three.js uses the documented snippet. A native six-way material is not built yet.

05 // FAQ

three.js looping sprite questions

All questions →

README.THREEJS_LOOP_SPRITE_ANIMATION
How do I make a fire effect in three.js?

Play a fire sprite sheet on a THREE.Sprite, set texture repeat to one eighth, step the offset through 64 frames and use additive blending.

Does three.js have a sprite sheet animation helper?

No built in helper exists. You set texture repeat and offset per frame in a few lines of code or use a small shader.

How do I loop a smoke plume sprite sheet in three.js?

Advance a frame counter at 64 frames per 4 seconds, wrap it modulo 64 and set texture.offset from the column and row.

How do I calculate UV coordinates for a sprite sheet with rows and columns in three.js?

Set texture.repeat to 1/C by 1/R. Compute column n % C and row Math.floor(n / C), then offset X by column / C and Y from the top.

Compile your first effect

You pay per compile and see the price before it runs. New accounts start with $5 of usage.

All effects, guides and explainers →