3D with three.js

Build a scene with the real three.js API, move it by time, and Volito renders it to video. With no GPU by default, or on the graphics card with soft shadows and film passes. New in 0.5.0.

volito render three-title.js --duration 7 --three gpu --sound --format mp4: extruded letters on springs, a sweeping spot light, a torus knot, soft shadows, depth of field and bloom. One file of three.js, rendered in 17.5 s on a laptop.

A scene in a program

A three.js program is a program like any other. Build the scene once in setup($) and return what you will move; in frame(t, $), move it by t and draw it with renderThree. Use THREE and the three.js library (r187, MIT) comes with your program; nothing to install.

function setup($) {
  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(38, $.W / $.H, 0.1, 100);
  const sun = new THREE.DirectionalLight(0xffffff, 2.6);
  sun.position.set(4, 6, 5); sun.castShadow = true;
  scene.add(sun, new THREE.HemisphereLight(0xffffff, 0x334455, 0.8));
  const knot = new THREE.Mesh(new THREE.TorusKnotGeometry(0.9, 0.3, 140, 18),
    new THREE.MeshStandardMaterial({ color: $.c.accent, roughness: 0.3 }));
  knot.castShadow = true; scene.add(knot);
  const floor = new THREE.Mesh(new THREE.PlaneGeometry(14, 14), new THREE.ShadowMaterial({ opacity: 0.35 }));
  floor.rotation.x = -Math.PI / 2; floor.position.y = -1.6; floor.receiveShadow = true; scene.add(floor);
  return { scene, camera, knot };
}

function frame(t, $) {
  const S = $.state;
  S.camera.position.set(Math.sin(t * 0.4) * 6.5, 1.4, Math.cos(t * 0.4) * 6.5);
  S.camera.lookAt(0, 0, 0);
  S.knot.rotation.set(t * 0.5, t * 0.8, 0);
  return $.panel(t) + renderThree($, S.scene, S.camera);   // the brand's ground, then the scene
}
volito render knot.js --duration 6 --format mp4               # SVG, no GPU
volito render knot.js --duration 6 --three gpu --format mp4   # three.js's WebGLRenderer on the graphics card

Everything in three.js core is there: every geometry (TorusKnot, Extrude, Lathe, Tube…), instanced meshes, the Basic, Lambert, Phong, Standard, Physical, Toon and Shadow materials, every light, fog, groups, curves and the maths, and AnimationMixer (sample it with mixer.setTime(t)). Loaders that fetch files and custom shaders are not.

Two ways to draw it

The VOLITO title and a pink torus knot drawn as SVG: smooth shading, the floor lit pink and blue
SVG (the default): no GPU, the same pixels on every machine.
The same frame drawn on the GPU: soft shadows, depth of field and glow
--three gpu: per-pixel light, soft shadows, film passes.
SVG (default)WebGL: --three webgl or gpu
NeedsNothingA Chrome; volito doctor says which one it found
LooksSmooth shading, soft projected shadows on flat floors and walls, pictures mapped per trianglePer-pixel PBR, shadow maps, environment: "room", anti-aliasing, film passes
Same pixels everywhereYeswebgl yes (software); gpu to the eye
Live in <volito-player>YesRenders only

Use the default for previews, contact sheets and anything that must render anywhere. Use --three gpu for the final render when the scene has glossy materials, reflections or many overlapping objects: the SVG route sorts by triangle, so meshes that cut through each other can show the far one in front.

renderThree options

renderThree($, scene, camera, {
  toneMapping: "aces", exposure: 0.82, environment: "room", environmentIntensity: 0.3,
  shadowType: "vsm",                                   // WebGL: soft shadows (light.shadow.radius)
  post: { ao: { radius: 0.3 }, dof: { focus: 8, aperture: 0.0012 }, bloom: { threshold: 1.15 } },
})
OptionWhat it does
boxWhere the scene goes, { x, y, w, h }; the whole frame by default. The camera's aspect follows it, so one scene fits 16:9, 9:16 and 1:1. Two boxes make a split screen.
toneMapping exposure"aces" or "neutral", and the exposure before it.
environment environmentIntensity"room": soft studio light from every side, and reflections on glossy materials.
background shadowsSet false to leave out the scene's background or its shadows.
shading"smooth" or "flat" (SVG route).
shadowType"vsm" for soft shadows (WebGL route).
postFilm passes on the WebGL route: ao (ambient occlusion), dof (depth of field: focus, aperture, maxblur), bloom (strength, radius, threshold). Each takes true or its own settings. Put the backdrop in scene.background when you use them.

Text, pictures and labels

HelperWhat it gives
threeText($, "WORD", { face, size, depth, bevel })An extruded, centred text geometry in the brand's own faces ($.font("display")); userData.width for laying out letters one by one.
threeImage($, name)A texture from one of the graphic's pictures, for material.map. A program you write takes them with --image name=path (MCP: images).
threeToScreen($, camera, point, box)Where a 3D point lands on the frame, { x, y, depth, visible }: pin labels, numbers and callouts drawn with Volito's text over the 3D.

Tips

  • On the SVG route, light and fog are worked out at each triangle's corners and blended across it. Give big flat surfaces segments, a 40-unit floor as PlaneGeometry(40, 40, 32, 32), or a fogged or point-lit floor shades as two flat halves.
  • Keep triangle counts sensible on the SVG route: a few thousand visible triangles draw in about 100 ms a frame at 1080p.
  • Bloom with a threshold above 1 glows only where light is really bright; lower, and everything glows.
  • A dense mesh that moves every frame (water, cloth) looks cleaner without castShadow and receiveShadow on itself.
  • volito sheet my.js --three gpu shows the GPU look at a few moments before a full render.

From Node and agents

import { customItem, renderVideo } from "volito";
import { readFileSync } from "node:fs";

const item = customItem(readFileSync("knot.js", "utf8"), { duration: 6 });
await renderVideo(item, { three: "gpu", format: "mp4", out: "knot.mp4" });

Agents get the same through MCP: motion_preview, motion_still, motion_check, motion_review and motion_render take three ("svg", "webgl" or "gpu"), or set VOLITO_THREE=gpu for the server. volito api prints the whole three.js reference for an agent to read.