Skill library

Agent skill Web motion

Three.js

Build a Three.js product viewer or hero scene with glTF models, camera controls and a render budget for mobile.

  • 3D / WebGL
  • Three.js
  • Animation

Install the skill

Installation method

Run the command from your project root with Node.js and npm.

npx skills@latest add https://github.com/MengTo/Skills/tree/main/agent-skills/web-design/threejs --skill threejs --agent claude-code --yes

Check this file in your project.claude/skills/threejs/SKILL.md

Other ways to install
  • Choose an assistant interactively

    npx skills@latest add https://github.com/MengTo/Skills/tree/main/agent-skills/web-design/threejs --skill threejs

    Select your assistant and choose the project installation scope.

    Official instructions

The tested Skills CLI 1.10.0 requires Node.js 22.20 or later. Use a coding assistant that loads the Skill. The WebGL examples need the separate three package, a WebGL 2-capable browser for current WebGLRenderer, and an approved model and poster for the product viewer.

View operation manual

What this skill helps with

  • Use spatial graphics, scenes or materials to support a web experience.

Good for

  • 3D on the web
Publisher
Meng To. The installed folder includes a Skill, references, and a standalone demo.
Runtime
Three.js Scene, camera, and WebGLRenderer, with optional GLTFLoader and controls.
Inputs
Target route, viewport sizes, approved artwork, and a static fallback.
Deliverable
A canvas scene that resizes cleanly and releases the resources it owns.
Skill name
threejs
Repository
MengTo/Skills

Define what the visitor can learn from 3D

A vague request

Replace the hero image with something in Three.js.

The subject, need for controls, device constraints, and fallback remain open, so the result can cost more to run without explaining the product.

A scoped scene

  1. Choose a decorative shape or an approved model with specific views to inspect.
  2. Reserve canvas space and keep a poster and ordinary page controls available.
  3. Check resize, rendering when needed, and teardown after navigating away.

Three.js operation manual

Create a small WebGL hero scene, then use an approved model to build a product viewer with an accessible static state.

Prove the renderer, camera, and resize behavior with one lit object before adding heavier assets.

  1. Open the installed visual reference

    The bundled page draws a projected wireframe using Canvas 2D. Use the WebGLRenderer recipe in SKILL.md for the Three.js scene.

    Prompt · Step 1
    Use Meng To’s installed threejs Skill to plan one decorative WebGL scene for my existing hero. Find SKILL.md, REFERENCES.md, demo/PROMPT.md, and demo/index.html in the installed directory. To inspect the included HTML, run python3 -u -m http.server 0 --bind 127.0.0.1 --directory "/absolute/path/to/installed/threejs/demo", replacing the directory with the actual demo folder. Port 0 asks the OS for a free port. Open the loopback URL printed by that server and stop only the temporary server you started when the inspection is complete. Identify the demo’s Canvas 2D rendering and the separate WebGLRenderer example in SKILL.md. Then propose one scene subject, its canvas area at narrow and wide widths, its static fallback, and how autoplay should respond to reduced motion. Keep this pass to planning.
    python3 -u -m http.server 0 --bind 127.0.0.1 --directory "/absolute/path/to/installed/threejs/demo"
  2. Set up the scene, camera and resize

    Render a lit mesh with a perspective camera and size the drawing buffer for the CSS canvas.

    Prompt · Step 2
    Use threejs to implement the agreed scene using the project’s compatible three version. Create one Scene, PerspectiveCamera, WebGLRenderer, and lit mesh with BoxGeometry and MeshStandardMaterial. Keep CSS in charge of the canvas dimensions. On a nonzero wrapper resize, cap the pixel ratio at 2 or lower for the target device, call renderer.setSize(width, height, false), update camera.aspect and camera.updateProjectionMatrix(), and render. Give the hero heading and action their existing document positions.
    
    Show a still frame when reduced motion is requested and use the poster if the renderer cannot start. If you add an animation loop, advance by elapsed time, pause when the page is hidden, and cancel it at teardown. Disconnect the resize observer and dispose the geometry, material, and renderer owned by this scene. Give me the local route and changed files.
  3. Verify size, fallback, and remount

    Check the scene at phone and desktop width and verify there is one live renderer after returning.

    • The scene keeps its proportions after resize.
    • The route still works when WebGL is unavailable or motion is reduced.
    • Returning to the page starts a single scene.
    Prompt · Step 3
    Use threejs to verify the local hero at phone and desktop widths, including a resize of the same page. Confirm the canvas stays sharp at the chosen pixel-ratio cap and the object does not stretch. Test reduced motion, tab visibility, and a branch where WebGL initialization is unavailable so the poster and existing main action remain usable. Navigate away and back twice, checking for uncaught errors, extra active animation loops, and stale resize listeners. Record the browser, canvas dimensions and observed results, and mark absent device checks unverified.

Look up a rendering issue

Include the installed Three.js version, browser, route, and whether the behavior occurs after loading or resizing.

The canvas stretches at a breakpointResize
Command or reference
setSize() and updateProjectionMatrix()
Examples
Use nonzero CSS wrapper dimensions for both the drawing buffer size and camera aspect.
The poster appears but the model never loadsAssets
Command or reference
GLTFLoader and browser Network
Examples
Check the real model URL, asset response, relative textures, and whether the model requires a decoder configured by the loader.
The preview slows after repeatedly navigating backCleanup
Command or reference
dispose() and loop cancellation
Examples
Check for a renderer, observer, or frame loop left behind. Dispose the resources owned by that instance.

Three.js troubleshooting

Does the bundled demo use Three.js?

The verified demo/index.html draws a perspective wireframe with Canvas 2D. Use it as visual reference. The SKILL.md setup and rotating-cube recipe show WebGLRenderer and real Three.js objects.

Why is a lit mesh black?

Check that the selected material has lights and that the camera frames the mesh. A temporary MeshBasicMaterial helps isolate lighting from framing while you debug.

Do I always need a render loop?

A static scene can render in response to resize, assets, or controls. Use a loop for continuous motion and stop it when hidden, reduced motion is active for a decorative scene, or the component is removed.