Threejs scene composition

From calesthio/generative-media-skills · View interactive version

Threejs scene composition is an AI agent skill from the GitHub repository calesthio/generative-media-skills. Production guidance for planning, building, animating, capturing, and reviewing complete Three.js scenes for rendered media. Use for browser-native 3D product shots, title sequences, procedural worlds, glTF scene assembly, camera and lighting animation, shaders, post-processing, deterministic frame

How to use this skill

Skill file

Three.js scene composition

Use Three.js when depth, camera, lighting, material response, geometry, or spatial animation carries the media idea and a browser-rendered scene is an appropriate production surface. This skill begins after asset requirements and creative intent are known and ends with a reproducible rendered scene package.

It does not teach mesh modeling, retopology, rig authoring, physics simulation, WebXR product design, or game logic. It may consume approved glTF assets, animation clips, textures, environment maps, fonts, data, and audio cues produced elsewhere.

Evidence stance

Three.js releases frequently and examples/addons may change paths or APIs. Facts and links were checked 2026-07-12. Pin and record the installed revision, check migration notes, and test the exact target browser and renderer before delivery. WebGPU support and renderer parity are especially volatile.

Decide whether Three.js is the right renderer

Use Three.js when the deliverable needs:

Prefer another approach when:

Do not add a 3D scene merely to make a composition feel expensive. The camera and dimensionality must serve the message.

Lock the scene contract

Before implementation, define:

Create a scene manifest mapping stable IDs to files, checksums, transformations, licenses, and scene usage. Freeze remote assets locally before final rendering.

Scene, camera, and renderer architecture

Documented fact: Three.js composes an Object3D hierarchy in a Scene, views it through a camera, and draws it through a renderer. Child transforms inherit parent transforms. Perspective and orthographic cameras serve different spatial readings.

Structure the scene by production role:

scene
+- world
|  +- environment
|  +- set
|  `- practical-lights
+- subject-root
|  +- approved-model
|  `- subject-controls
+- fx-root
+- camera-rig
|  +- camera-target
|  `- camera
`- review-guides

Use stable names and keep camera rigs, subject transforms, imported animation, and procedural effects separate. Avoid modifying deeply nested imported nodes by array index; resolve named nodes once and validate that they exist.

Camera direction

Import and validate glTF ingredients

Documented fact: glTF 2.0 describes scenes, nodes, meshes, skins, animations, cameras, PBR materials, textures, and binary resources. Three.js GLTFLoader returns loaded scenes and animation clips and supports a documented set of glTF extensions. Core glTF materials use metallic-roughness PBR.

For every imported asset:

  1. Validate the source with Khronos glTF Validator.
  2. Record required/used extensions and verify loader support.
  3. Inspect scene scale, orientation, bounds, pivots, cameras, lights, skins, morph targets, animations, and material count.
  4. Check texture color-space annotations and UV/tangent behavior.
  5. Compare the asset in a reference viewer and the production scene.
  6. Preserve the source package; document any conversion, compression, or material override.

Use Draco or mesh compression and KTX2/Basis texture paths only after checking decoder deployment, target support, visual changes, and startup cost. Compression is a delivery decision, not an automatic quality improvement.

Color, materials, and lighting

Documented fact: Three.js uses a color-management workflow with Linear-sRGB as its working color space. Color textures such as base color and emissive maps require an sRGB color-space annotation; non-color data textures such as normal, roughness, and metalness maps should not be treated as color. Output conversion and tone mapping are renderer concerns.

Color-critical workflow:

Use physically based materials when lighting response matters. Preserve the intended distinction between dielectrics and metals, and review roughness, normals, clearcoat, transmission, volume, sheen, iridescence, and other extensions only where the asset and target support them.

Lighting plan:

Production heuristic: begin with the fewest lights and shadow maps that produce the intended form. Add complexity in response to a visible deficiency, not because more lights sound cinematic.

Animation systems

Three.js can combine imported clips, scripted transforms, morph targets, cameras, and shader uniforms. Keep one declared owner per property.

Imported clips and skeletal animation

Documented fact: AnimationMixer controls AnimationAction instances created from AnimationClip data. Clips contain keyframe tracks. Actions can loop, crossfade, change weight, and use normal or additive blending.

Morph targets

Use morphs for approved shape changes, facial poses, or corrective deformation. Validate that topology and target order match. Clamp or intentionally combine influence values; inspect midpoints for volume loss, self-intersection, and texture stretching.

Procedural motion

Write procedural state as a pure function of composition time whenever possible:

function applyFrameState(frame, fps) {
  const time = frame / fps;
  subject.rotation.y = baseRotation + time * radiansPerSecond;
  material.uniforms.uTime.value = time;
  cameraRig.position.copy(cameraPath.getPointAt(clamp01(time / shotDuration)));
}

This example assumes clamp01(value) returns Math.max(0, Math.min(1, value)) and cameraPath is a configured Three.js curve such as a Curve3 implementation. Validate the actual curve and camera target separately.

Seed particle distributions and noise inputs. Do not accumulate state with position.x += ... during frame export because seeking backward or rendering frames out of order will produce the wrong result.

Deterministic frame rendering

Live preview commonly uses requestAnimationFrame and incremental deltas. Fixed media capture should instead derive the entire scene state from the requested frame.

For each frame:

  1. Compute time = frame / fps from the composition contract.
  2. Set imported animation to that absolute time using the mixer/action strategy supported by the installed version; do not rely on an unknown number of prior update(delta) calls.
  3. Set camera rigs, procedural transforms, particles, shaders, morphs, and visibility from absolute time or cached deterministic state.
  4. Update required world matrices, skeletons, and render targets.
  5. Render the scene and post-processing chain once.
  6. Read or capture the completed frame through the host renderer.

Example adapter shape:

export function renderAtFrame(frame, fps) {
  const time = frame / fps;
  mixer.setTime(time);
  applyFrameState(frame, fps);
  scene.updateMatrixWorld(true);
  composer.render();
}

Check the current AnimationMixer semantics before using setTime() with non-unit mixer time scale. The principle is absolute-time evaluation, not allegiance to one API call.

Do not use wall-clock time, unseeded randomness, live network responses, hidden-tab timing, device orientation, or unconstrained physics during final capture. Bake simulations or define a reproducible fixed-step cache when simulation is essential.

Render the same stress frames in two clean runs and compare them. Exact GPU pixels may vary across backends or hardware; define tolerances and lock the render environment when exact reproducibility is required.

Shaders and post-processing

Use built-in materials first when they meet the visual requirement. Custom ShaderMaterial, raw shaders, node-based shading, and post-processing increase both creative range and portability risk.

For custom shaders:

For post-processing:

Performance and resource custody

Documented fact: removing a mesh from a scene does not automatically release its geometry, material, texture, or render-target GPU resources. Disposable resources expose dispose() methods. Three.js provides renderer memory information for diagnostic use.

Production approach:

Measure a representative sequence, not an empty scene. Record load time, first-frame shader compilation, peak memory, render time per frame, readback/capture cost, and encoded output quality.

Accessibility and viewer safety

Documented fact: WCAG 2.2 SC 2.3.1 limits content to no more than three flashes in any one-second period unless below general and red flash thresholds. Evaluate loops while looping and test at the largest intended presentation.

Also review:

For interactive publication, expose motion controls and honor user preferences where applicable. For prerecorded video, produce a separate calmer output because a media query cannot alter already rendered pixels.

Rights and provenance

Three.js is MIT-licensed, but the scene's dependencies retain their own terms. Record licenses and permissions for models, textures, HDRIs, fonts, shaders, motion clips, mocap, plugins, logos, and reference media. Generated ingredients need provider/model/version/prompt/seed metadata when available.

Do not assume an asset downloaded from a public demo is cleared for commercial reuse. Preserve required notices. If a model depicts a real person, branded product, private location, artwork, or protected character, verify the applicable consent and rights before rendering.

Render QA and handoff

Review these gates:

Handoff should include source code, pinned dependencies/lockfile, local assets, scene manifest, render settings, exact command or host entrypoint, representative frame checks, performance notes, provenance ledger, license notices, QA report, and known backend limitations.

Example 1: color-critical product orbit

This is a complete example, not a mandatory formula.

Intent: produce a 12-second 4K orbit of an approved running shoe for a product launch. Material and color fidelity matter more than dramatic effects.

Inputs and constraints: validated GLB; approved base-color swatches; two 4K texture sets; licensed studio HDRI; 3840x2160 at 30 fps; H.264 review plus high-quality master frames; no invented logos or geometry.

Workflow:

  1. Load and inventory the GLB, confirm meter scale, bounds, named materials, UVs, and required extensions.
  2. Annotate base-color textures as sRGB and leave normal/roughness/metalness as non-color data.
  3. Build a neutral environment plus one broad key and restrained rim; fit a soft contact shadow to the turntable.
  4. Lock tone mapping and exposure against approved swatches and a neutral reference card.
  5. Keep the shoe static and animate a camera rig through one eased 210-degree orbit; hold the hero three-quarter view for the final two seconds.
  6. Evaluate camera and turntable state from absolute frame time.
  7. Render frames 0, 1, 90, 180, 299, 300, and 359 twice before the full export.
  8. Compare the encoded review against master frames for fine mesh, logo, shadow, and color changes.

Expected result: stable geometry and logo, repeatable camera frames, neutral material response, readable contact, and approved color through the final encode.

Likely failures: double color conversion, roughness map tagged as sRGB, environment overpowering approved color, near-plane clipping, shader compilation hitch on frame one, and compression damaging knit texture.

Variation: for 9:16, author a closer camera path and different final hold rather than cropping the 16:9 orbit.

Example 2: procedural title world

This is a complete example, not a mandatory formula.

Intent: make an eight-second title sequence in which 2,000 instanced columns rise into a city-like word silhouette while a camera passes through it.

Inputs and constraints: 1920x1080 at 30 fps; one approved title; no external 3D assets; deterministic seed; restrained glow; reduced-motion alternative; no flashing.

Workflow:

  1. Convert the approved title mask into a frozen per-instance target-height table using a stored seed and versioned generation settings.
  2. Render columns with one instanced geometry/material and per-instance transforms.
  3. Drive each height from absolute time, target height, and a deterministic spatial delay; do not mutate cumulative height.
  4. Use a camera spline with authored position and look target; cap horizon roll.
  5. Apply a subtle bloom pass after the main render and verify pass order and render-target memory.
  6. Hold the readable title silhouette for 1.5 seconds.
  7. Reduced-motion version uses a stationary camera and shorter column travel.
  8. Run full-screen flashing review and repeated stress-frame comparison.

Expected result: identical instance layout across renders, no one-frame jumps, readable title, stable camera, and bounded GPU memory.

Likely failures: unseeded instance placement, accumulated transforms breaking backward seek, moire in dense columns, excessive bloom, camera clipping, and no readable hold.

Variation: if GPU or render-worker limits are tight, pre-render the 3D layer with alpha and composite it in a 2D runtime, retaining the scene manifest and provenance.

Sources

Official and authoritative sources checked 2026-07-12:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.