mcpbeat Sign in

Threejs Scene Setup Agent Skill

> Scene/PerspectiveCamera/WebGLRenderer trio, the setAnimationLoop render loop, responsive resize, and OrbitControls. Use when starting or debugging a three.js app — when the user mentions three.js, THREE.Scene, WebGLRenderer, PerspectiveCamera, the render loop, resizing, or OrbitControls. For models use threejs-gltf-loading; for materials/lights use threejs-materials-lighting.

3k tokens
context cost
the whole folder, loaded on every use
2
files
instructions only
0
copies elsewhere
how many repositories repackaged it
401
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill threejs-scene-setup

The instruction itself

12 sections, as written by the author

three.js Scene Setup

Create the foundation of a three.js app: module loading, the

scene/camera/renderer trio, the render loop, responsive resizing, and camera

controls. Patterns target r165+ and are verified against r184.

When to use

  • Use when bootstrapping a three.js scene, fixing a blank/black canvas, making the

canvas responsive, setting up the animation loop, or adding OrbitControls.

  • Use when package.json depends on three and code does `import * as THREE from

'three'`.

When *not* to use: loading .gltf/.glb models or skinned animation →

threejs-gltf-loading. Materials, lights, shadows, environment maps →

threejs-materials-lighting. 2D rendering → pixijs-rendering.

Core workflow

  • Load three.js as an ES module with an import map. Since r147 the bare

specifier 'three' and 'three/addons/' must be mapped (in HTML or by a

bundler). Addons (controls, loaders) live under three/addons/....

  • Create the trio. A Scene (root of the graph), a `PerspectiveCamera(fov,

aspect, near, far) moved back from the origin, and a WebGLRenderer` whose

domElement is in the DOM. Set size and pixelRatio.

  • Add a mesh. new Mesh(geometry, material) and scene.add(mesh). With a

lit material you also need a light (see threejs-materials-lighting).

  • Drive a render loop with renderer.setAnimationLoop(fn). It's the modern,

WebXR-/WebGPU-safe replacement for hand-rolled requestAnimationFrame. Use a

Clock for delta time.

  • Handle resize so the camera aspect and renderer match the canvas; update

camera.aspect, call updateProjectionMatrix(), and renderer.setSize(...).

  • Add OrbitControls for orbit/pan/zoom while developing. Confirm something

actually renders (a lit cube, the controls responding) before assuming success.

Patterns

1. HTML import map + module entry (no bundler)

<canvas id="c"></canvas>
<script type="importmap">
{
  "imports": {
    "three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
    "three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/"
  }
}
</script>
<script type="module" src="./main.js"></script>

With a bundler (Vite/webpack), skip the import map and just

npm i three; the same import statements resolve.

2. Scene + camera + renderer

// main.js
import * as THREE from 'three';

const canvas = document.querySelector('#c');
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); // cap for perf
renderer.setSize(window.innerWidth, window.innerHeight);

const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101018);

const camera = new THREE.PerspectiveCamera(
  60,                                   // vertical field of view (degrees)
  window.innerWidth / window.innerHeight, // aspect
  0.1,                                  // near
  100                                   // far
);
camera.position.set(3, 2, 5);
camera.lookAt(0, 0, 0);

const cube = new THREE.Mesh(
  new THREE.BoxGeometry(1, 1, 1),
  new THREE.MeshNormalMaterial()        // unlit; shows orientation without a light
);
scene.add(cube);

3. The render loop (setAnimationLoop + Clock)

const clock = new THREE.Clock();

renderer.setAnimationLoop(() => {
  const dt = clock.getDelta();          // seconds since last frame
  cube.rotation.x += dt;                // frame-rate independent
  cube.rotation.y += dt * 0.7;
  renderer.render(scene, camera);
});
// renderer.setAnimationLoop(null); // stop the loop

4. Responsive resize

function onResize() {
  const w = window.innerWidth, h = window.innerHeight;
  camera.aspect = w / h;
  camera.updateProjectionMatrix();      // required after changing aspect
  renderer.setSize(w, h);
}
window.addEventListener('resize', onResize);

5. OrbitControls (orbit / pan / zoom)

import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;          // inertial feel
controls.target.set(0, 0, 0);

renderer.setAnimationLoop(() => {
  controls.update();                    // needed every frame when damping is on
  renderer.render(scene, camera);
});

Pitfalls

  • Failed to resolve module specifier "three" → missing import map (or bundler

config). Map both "three" and "three/addons/"; addon paths must end with /.

  • Black canvas, no errors → camera is at the origin (inside/behind the object),

or you used a lit material (MeshStandardMaterial) with no light. Move the camera

back; use MeshNormalMaterial/MeshBasicMaterial to verify geometry first.

  • Nothing animates → you never called renderer.render inside the loop, or you

call setAnimationLoop but render outside it.

  • Stretched / squashed view on resize → you resized the renderer but didn't

update camera.aspect + updateProjectionMatrix().

  • Blurry or jagged on HiDPI → set renderer.setPixelRatio(...); cap it (≈2) so

4K/retina screens don't tank performance.

  • OrbitControls feel dead → with enableDamping = true you must call

controls.update() every frame.

  • Old tutorials use <script src="three.min.js"> → since r147 three.js ships

ES modules only; use type="module" + import maps.

References

  • For coordinate conventions, the scene-graph (Group, parent/child transforms,

Object3D add/remove), OrthographicCamera for 2.5D, and disposing of

geometries/materials/textures to avoid leaks, read references/scene-graph.md.

  • threejs-materials-lighting — give surfaces a lit look (lights, shadows, PBR).
  • threejs-gltf-loading — load 3D models and play their animations.
  • pixijs-rendering — 2D rendering in the browser.
  • fps-shooter — a 3D genre template that composes three.js skills.

Other skills for the same job

different authors, same section of the catalogue
Protocolsio Integration
by christophacham
×4

Integration with protocols.io API for managing scientific protocols. This skill should be used when working with protocols.io to search, create, update, or publish protocols; manage protocol steps and materials; handle discussions and comments; organize workspaces; upload and manage files; or integrate protocols.io functionality into workflows. Applicable for protocol discovery, collaborative protocol development, experiment tracking, lab protocol management, and scientific documentation.

16k tokens
Tailored Resume Generator
by frostant
×4

Analyzes job descriptions and generates tailored resumes that highlight relevant experience, skills, and achievements to maximize interview chances

3k tokens
Excalidraw Diagram Generator
by github
vendor ×3

Generate Excalidraw diagrams from natural language descriptions. Use when asked to "create a diagram", "make a flowchart", "visualize a process", "draw a system architecture", "create a mind map", or "generate an Excalidraw file". Supports flowcharts, relationship diagrams, mind maps, and system architecture diagrams. Outputs .excalidraw JSON files that can be opened directly in Excalidraw.

36k tokens scripts
Expo Dev Client
by openai
vendor ×3

Build and distribute Expo development clients locally or via TestFlight

961 tokens
Executing Plans
by ZhanlinCui
×3

Use when you have a written implementation plan to execute in a separate session with review checkpoints

542 tokens
Anndata
by christophacham
×3

Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

16k tokens
Benchling Integration
by christophacham
×3

Benchling R&D platform integration. Access registry (DNA, proteins), inventory, ELN entries, workflows via API, build Benchling Apps, query Data Warehouse, for lab data management automation.

14k tokens
Biopython
by christophacham
×3

Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.

24k tokens

How to use it

Copy the folder

Take gamedev-skills/threejs-scene-setup from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.

Install what it needs

The instructions reference npm. Without those the skill loads but fails at the first command.