threejs-scene-setup
Ce qu’il fait
Explique comment créer la base 3D d'une application web three.js. Elle s'adresse aux développeurs qui débutent une page 3D ou corrigent un canevas vide ou noir.
Quand l’utiliser
- ✓Quand vous démarrez une nouvelle application three.js ou que le canevas est vide.
- ✓Quand la vue 3D doit se redimensionner correctement avec la fenêtre du navigateur.
- ✓Quand vous voulez que les utilisateurs tournent et zooment dans une vue 3D avec la souris ou le tactile.
Lien du skill
https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/web-engines/threejs-scene-setup/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Crée une page three.js avec un cube qui tourne et qui remplit la fenêtre, et que je peux faire tourner à la souris.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
Elle explique comment charger three.js avec une import map, créer la scène, la caméra et le moteur de rendu, faire tourner la boucle de rendu, gérer les changements de taille de fenêtre et ajouter les contrôles d'orbite.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis GitHub.
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 r186. Read the installed three version before
changing an existing project because examples and addons move across releases.
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.jsondepends onthreeand code doesimport * 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 r137 the bare
specifier
'three'must be resolved by an import map (in HTML) or a bundler; map'three/addons/'too. Addons (controls, loaders) live underthree/addons/.... - Create the trio. A
Scene(root of the graph), aPerspectiveCamera(fov, aspect, near, far)moved back from the origin, and aWebGLRendererwhosedomElementis in the DOM. Set size andpixelRatio. - Add a mesh.
new Mesh(geometry, material)andscene.add(mesh). With a lit material you also need a light (seethreejs-materials-lighting). - Drive a render loop with
renderer.setAnimationLoop(fn). It's the modern, WebXR-/WebGPU-safe replacement for hand-rolledrequestAnimationFrame. Use aTimerfor delta time (Clockis deprecated since r183). - Handle resize so the camera aspect and renderer match the canvas; update
camera.aspect, callupdateProjectionMatrix(), andrenderer.setSize(...). - Add
OrbitControlsfor 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/three@0.186.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.186.1/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, 1.5)); // starting budget; profile on target hardware
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 + Timer)
const timer = new THREE.Timer(); // replaces the deprecated THREE.Clock (r183+)
timer.connect(document); // optional: no huge delta after a hidden tab
renderer.setAnimationLoop(() => {
timer.update(); // use performance.now(), like visibility reset
const dt = Math.min(Math.max(timer.getDelta(), 0), 0.1); // seconds; bound stalls and negative deltas
cube.rotation.x += dt; // frame-rate independent
cube.rotation.y += dt * 0.7;
renderer.render(scene, camera);
});
// renderer.setAnimationLoop(null); // stop the loop
// timer.dispose(); // remove visibility listener when tearing down
In r186, visibility reset samples performance.now(). A supplied animation-frame
timestamp can precede that reset and produce a negative delta. Using update()
keeps the clock source consistent; the lower clamp also protects a fixed-step
accumulator. Feed the bounded dt into simulation, not raw getDelta().
The 0.1-second upper bo
Questions fréquentes
Qu'est-ce qu'une import map ?
C'est un réglage du HTML qui indique au navigateur où trouver three.js lorsqu'un fichier l'importe.
Couvre-t-elle WebGPU ?
Seulement comme option. La compétence indique comment activer le moteur de rendu WebGPU.
Couvre-t-elle le chargement de modèles ?
Non. Le chargement des modèles relève de la compétence glTF distincte.
Détails
Description originale de l’auteur
Stand up a three.js scene: import maps and the three/addons path, the Scene/PerspectiveCamera/WebGLRenderer trio, the setAnimationLoop render loop, responsive resize, OrbitControls, and opting into WebGPURenderer. Use when starting or debugging a three.js app — when the user mentions three.js, THREE.Scene, WebGLRenderer, WebGPURenderer, PerspectiveCamera, the render loop, resizing, or OrbitControls. For models use threejs-gltf-loading; for materials/lights use threejs-materials-lighting.
Popularité
- Étoiles GitHub
- 6.6k
- Position au classement
- #13863
- Licence
- Apache-2.0
- Mis à jour
- 28/10/2026
Commentaires
- …
Autres skills de ce dépôt
router
6.6kAide votre agent à choisir la bonne compétence de développement de jeu pour une demande, en détectant votre moteur et le type de tâche.
ai-behavior-trees-utility-ai
6.6kAide votre agent à construire un arbre de comportement et une IA par utilité pour des ennemis qui choisissent leurs actions selon priorité et score.
audio-design
6.6kApprend à votre agent le mixage audio de jeu : bus, volume en décibels, baisse sous les dialogues, musique adaptative et variation des effets sonores.
camera-systems
6.6kAide votre agent à construire des caméras de jeu qui suivent en douceur, restent dans le niveau, et pivotent ou regardent autour en 3D.
Skills similaires
angular-developer
280kAide votre agent à créer du code Angular et à conseiller sur la structure des projets. Utile pour démarrer, créer des composants ou améliorer performances et accessibilité.
frontend-a11y
280kAide votre agent à rendre les interfaces web accessibles à tous. Il garantit que sites et apps fonctionnent avec les lecteurs d'écran et la navigation au clavier.
frontend-patterns
280kPermet à votre agent d'appliquer les modèles modernes du frontend : optimisation des performances, gestion d'état et bonnes pratiques avec React et Next.js.