Curve Modifier Playground (r183 roadmap)

Flow-based geometry deformation demo that moves and bends a mesh along an editable Catmull-Rom spline path in real time.

Key topics: three.js curve modifier, flow, spline deformation, catmullromcurve3, r183

Overview

Bending a mesh along a path is a common need: trains on tracks, text running along a ribbon, tentacles, cables and conveyor props. Three.js's CurveModifier addon does it on the GPU. This playground deforms a mesh along an editable Catmull-Rom spline and slides it along the curve in real time, with controls for the path's shape and the object's roll.

How it works

Flow from examples/jsm/modifiers/CurveModifier.js wraps a mesh and replaces its material's vertex shader logic. The curve is sampled and its points and moving frames (tangent, normal and binormal) are stored in a data texture. In the vertex shader, each vertex's position along the mesh's long axis is treated as a distance along the curve: the shader looks up the curve point and frame at that distance, then places the vertex using its remaining two coordinates as offsets in the frame's normal and binormal directions. The result is a mesh that bends smoothly to follow the path.

Moving the object along the path is just a matter of adding an offset to that distance each frame with flow.moveAlongCurve(amount), so animation costs almost nothing on the CPU. When you change the spline (bend, arc height, centre height or tension), the demo rebuilds the curve, resamples it, and updates the flow texture. The roll parameter rotates the object around the tangent.

Exploring the demo

Adjust bend and arc height to reshape the path and watch the mesh conform to it as it travels. Increase the tension to tighten the corners, and change the roll to twist the object around its direction of travel. Turn on the spline line and control points to see exactly what the mesh is following.

Practical advice

The mesh needs enough subdivisions along its long axis to bend smoothly, since only vertices move. Moving frames can twist unexpectedly on curves with inflection points; parallel-transport frames or a fixed up vector avoid that. For curve construction see the spline editor, for interpolation theory see Bézier interpolants, and for sweeping profiles along curves see lathe and sweep.

What this code does

- CurveModifier Flow: uses `Flow` from `examples/jsm/modifiers/CurveModifier.js` to deform and move geometry along a curve.
- Editable Spline Inputs: GUI controls modify spline bend, arc height, center height, and tension at runtime.
- Live Curve Rebuild: each control change regenerates sampled path geometry and updates flow deformation instantly.
- Orientation Control: roll parameter rotates the deformed object around its tangent direction for alignment testing.
- Path Debugging: optional spline line and control-point markers help verify shape continuity and curve tuning.
- Practical Use: useful for conveyor props, tracks, tentacle-like motion, and stylized path-following behaviors.

Continue Learning

JavaScript Implementation

ES6+
import { Flow } from 'three/examples/jsm/modifiers/CurveModifier.js'

const mesh = new THREE.Mesh(
  new THREE.TorusKnotGeometry(0.45, 0.14, 120, 22),
  new THREE.MeshStandardMaterial({ color: 0x8ab0ff, metalness: 0.2, roughness: 0.3 })
)
const flow = new Flow(mesh)

const curve = new THREE.CatmullRomCurve3([
  new THREE.Vector3(-4, 1, -2),
  new THREE.Vector3(-1, 2, 3),
  new THREE.Vector3(2, 1, -3),
  new THREE.Vector3(4, 2, 2)
], true)

flow.updateCurve(0, curve)
scene.add(flow.object3D)

// Animate the object along the deformed path.
flow.moveAlongCurve(0.002)

Related demos

Trending this week

Most popular