threejs-fundamentals

Configures Three.js scenes, cameras, renderers, and Object3D hierarchies for 3D web applications.

1|Updated Aug 20, 2023
One-click install
npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-fundamentals-imanlangaran
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: threejs-fundamentals
Source: https://github.com/imanlangaran/mini-projects/tree/main/building-sell/.claude/skills/threejs-fundamentals
Command: npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-fundamentals-imanlangaran

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires three.

What problem does it solve? Setting up a Three.js scene involves many interdependent pieces—cameras, renderers, lights, object hierarchies, and math utilities—and getting any of them wrong leads to blank screens, distorted views, or memory leaks. This Skill provides correct, ready-to-use patterns for the core Three.js building blocks. ## Core Features & Use Cases - Scene and Renderer Setup: Create scenes with backgrounds, fog, and environment maps, and configure WebGLRenderer with tone mapping, color space, shadows, and pixel ratio handling. - Camera Configuration: Use PerspectiveCamera, OrthographicCamera, ArrayCamera, and CubeCamera for standard views, isometric views, split viewports, and real-time reflections. - Object Hierarchy and Math Utilities: Manage Object3D transforms, groups, layers, and traversal, plus Vector3, Matrix4, Quaternion, Euler, and Color operations. - Use Case: When building an interactive 3D product viewer, use this Skill to set up the scene, camera, lighting, resize handling, and animation loop correctly on the first attempt, including proper disposal to avoid GPU memory leaks. ## Quick Start Set up a basic Three.js scene with a perspective camera, a lit rotating cube, an animation loop, and responsive resize handling.

Frequently Asked Questions about threejs-fundamentals

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up a basic Three.js scene with camera and renderer?

Create a THREE.Scene, a PerspectiveCamera with fov, aspect, near, and far values, and a WebGLRenderer with antialias enabled. Set the renderer size and pixel ratio, append its DOM element to the body, add meshes and lights to the scene, then call renderer.render inside a requestAnimationFrame loop.

What is the difference between PerspectiveCamera and OrthographicCamera in Three.js?

PerspectiveCamera simulates the human eye with a field of view and depth-based scaling, making it the default for most 3D scenes. OrthographicCamera has no perspective distortion and uses left, right, top, and bottom frustum bounds, which suits 2D interfaces and isometric views.

How do I handle window resize in Three.js?

Add a resize event listener that updates camera.aspect with the new width-to-height ratio, calls camera.updateProjectionMatrix(), and resizes the renderer with renderer.setSize. Also reapply setPixelRatio capped at 2 to keep rendering sharp on high-DPI displays.

Why does my Three.js app leak memory over time?

Three.js does not automatically free GPU resources, so geometries, materials, and textures must be disposed manually with their dispose() methods. Remove objects from the scene and call renderer.dispose() when tearing down to release WebGL contexts.

How do I make Three.js animations framerate-independent?

Use THREE.Clock and multiply movement by clock.getDelta(), the elapsed seconds since the last frame. This keeps rotation and motion speeds consistent regardless of whether the display runs at 30, 60, or 144 frames per second.

Does Three.js support shadows and how do I enable them?

Yes, enable shadows by setting renderer.shadowMap.enabled to true and choosing a shadow map type such as PCFSoftShadowMap. Then set castShadow on meshes that cast shadows and receiveShadow on surfaces that receive them, with a light that supports shadow casting.