|
| 1 | +# Three.js |
| 2 | + |
| 3 | +> Three.js is a cross-browser JavaScript library for creating 3D graphics using WebGL and WebGPU. |
| 4 | + |
| 5 | +## Instructions for Large Language Models |
| 6 | + |
| 7 | +When generating Three.js code, follow these guidelines: |
| 8 | + |
| 9 | +### 1. Use Import Maps (Not Old CDN Patterns) |
| 10 | + |
| 11 | +WRONG - outdated pattern: |
| 12 | +```html |
| 13 | +<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> |
| 14 | +``` |
| 15 | + |
| 16 | +CORRECT - modern pattern (always use latest version): |
| 17 | +```html |
| 18 | +<script type="importmap"> |
| 19 | +{ |
| 20 | + "imports": { |
| 21 | + "three": "https://cdn.jsdelivr.net/npm/three@0.182.0/build/three.module.js", |
| 22 | + "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.182.0/examples/jsm/" |
| 23 | + } |
| 24 | +} |
| 25 | +</script> |
| 26 | +<script type="module"> |
| 27 | +import * as THREE from 'three'; |
| 28 | +import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; |
| 29 | +</script> |
| 30 | +``` |
| 31 | + |
| 32 | +### 2. Choosing Between WebGLRenderer and WebGPURenderer |
| 33 | + |
| 34 | +Three.js maintains both renderers: |
| 35 | + |
| 36 | +**Use WebGLRenderer** (default, mature): |
| 37 | +- Maximum browser compatibility |
| 38 | +- Well-established, many years of development |
| 39 | +- Most examples and tutorials use this |
| 40 | + |
| 41 | +```js |
| 42 | +import * as THREE from 'three'; |
| 43 | +const renderer = new THREE.WebGLRenderer(); |
| 44 | +``` |
| 45 | + |
| 46 | +**Use WebGPURenderer** when you need: |
| 47 | +- Custom shaders/materials using TSL (Three.js Shading Language) |
| 48 | +- Compute shaders |
| 49 | +- Advanced node-based materials |
| 50 | + |
| 51 | +```js |
| 52 | +import * as THREE from 'three/webgpu'; |
| 53 | +const renderer = new THREE.WebGPURenderer(); |
| 54 | +await renderer.init(); |
| 55 | +``` |
| 56 | + |
| 57 | +### 3. TSL (Three.js Shading Language) |
| 58 | + |
| 59 | +When using WebGPURenderer, use TSL instead of raw GLSL for custom materials: |
| 60 | + |
| 61 | +```js |
| 62 | +import { texture, uv, color } from 'three/tsl'; |
| 63 | + |
| 64 | +const material = new THREE.MeshStandardNodeMaterial(); |
| 65 | +material.colorNode = texture( myTexture ).mul( color( 0xff0000 ) ); |
| 66 | +``` |
| 67 | + |
| 68 | +TSL benefits: |
| 69 | +- Works with both WebGL and WebGPU backends |
| 70 | +- No string manipulation or onBeforeCompile hacks |
| 71 | +- Type-safe, composable shader nodes |
| 72 | +- Automatic optimization |
| 73 | + |
| 74 | +### 4. NodeMaterial Classes (for WebGPU/TSL) |
| 75 | + |
| 76 | +When using TSL, use node-based materials: |
| 77 | +- MeshBasicNodeMaterial |
| 78 | +- MeshStandardNodeMaterial |
| 79 | +- MeshPhysicalNodeMaterial |
| 80 | +- LineBasicNodeMaterial |
| 81 | +- SpriteNodeMaterial |
| 82 | + |
| 83 | +## Getting Started |
| 84 | + |
| 85 | +- [Installation](https://threejs.org/manual/#en/installation) |
| 86 | +- [Creating a Scene](https://threejs.org/manual/#en/creating-a-scene) |
| 87 | +- [Fundamentals](https://threejs.org/manual/#en/fundamentals) |
| 88 | +- [Responsive Design](https://threejs.org/manual/#en/responsive) |
| 89 | + |
| 90 | +## Renderer Guides |
| 91 | + |
| 92 | +- [WebGPURenderer](https://threejs.org/manual/#en/webgpurenderer) |
| 93 | + |
| 94 | +## Core Concepts |
| 95 | + |
| 96 | +- [TSL Specification](https://threejs.org/docs/#api/en/nodes/TSL): Complete shader language reference |
| 97 | +- [Animation System](https://threejs.org/manual/#en/animation-system) |
| 98 | +- [Loading 3D Models](https://threejs.org/manual/#en/loading-3d-models) |
| 99 | +- [Scene Graph](https://threejs.org/manual/#en/scenegraph) |
| 100 | +- [Materials](https://threejs.org/manual/#en/materials) |
| 101 | +- [Textures](https://threejs.org/manual/#en/textures) |
| 102 | +- [Lights](https://threejs.org/manual/#en/lights) |
| 103 | +- [Cameras](https://threejs.org/manual/#en/cameras) |
| 104 | +- [Shadows](https://threejs.org/manual/#en/shadows) |
| 105 | + |
| 106 | +## Essential API |
| 107 | + |
| 108 | +### Core |
| 109 | +- [Object3D](https://threejs.org/docs/#api/en/core/Object3D) |
| 110 | +- [BufferGeometry](https://threejs.org/docs/#api/en/core/BufferGeometry) |
| 111 | +- [BufferAttribute](https://threejs.org/docs/#api/en/core/BufferAttribute) |
| 112 | + |
| 113 | +### Scenes |
| 114 | +- [Scene](https://threejs.org/docs/#api/en/scenes/Scene) |
| 115 | + |
| 116 | +### Cameras |
| 117 | +- [PerspectiveCamera](https://threejs.org/docs/#api/en/cameras/PerspectiveCamera) |
| 118 | +- [OrthographicCamera](https://threejs.org/docs/#api/en/cameras/OrthographicCamera) |
| 119 | + |
| 120 | +### Renderers |
| 121 | +- [WebGLRenderer](https://threejs.org/docs/#api/en/renderers/WebGLRenderer) |
| 122 | +- [WebGPURenderer](https://threejs.org/docs/#api/en/renderers/webgpu/WebGPURenderer) |
| 123 | + |
| 124 | +### Objects |
| 125 | +- [Mesh](https://threejs.org/docs/#api/en/objects/Mesh) |
| 126 | +- [InstancedMesh](https://threejs.org/docs/#api/en/objects/InstancedMesh) |
| 127 | +- [Group](https://threejs.org/docs/#api/en/objects/Group) |
| 128 | + |
| 129 | +### Materials |
| 130 | +- [MeshBasicMaterial](https://threejs.org/docs/#api/en/materials/MeshBasicMaterial) |
| 131 | +- [MeshStandardMaterial](https://threejs.org/docs/#api/en/materials/MeshStandardMaterial) |
| 132 | +- [MeshPhysicalMaterial](https://threejs.org/docs/#api/en/materials/MeshPhysicalMaterial) |
| 133 | + |
| 134 | +### Geometries |
| 135 | +- [BoxGeometry](https://threejs.org/docs/#api/en/geometries/BoxGeometry) |
| 136 | +- [SphereGeometry](https://threejs.org/docs/#api/en/geometries/SphereGeometry) |
| 137 | +- [PlaneGeometry](https://threejs.org/docs/#api/en/geometries/PlaneGeometry) |
| 138 | + |
| 139 | +### Lights |
| 140 | +- [AmbientLight](https://threejs.org/docs/#api/en/lights/AmbientLight) |
| 141 | +- [DirectionalLight](https://threejs.org/docs/#api/en/lights/DirectionalLight) |
| 142 | +- [PointLight](https://threejs.org/docs/#api/en/lights/PointLight) |
| 143 | +- [SpotLight](https://threejs.org/docs/#api/en/lights/SpotLight) |
| 144 | + |
| 145 | +### Loaders |
| 146 | +- [TextureLoader](https://threejs.org/docs/#api/en/loaders/TextureLoader) |
| 147 | +- [GLTFLoader](https://threejs.org/docs/#examples/en/loaders/GLTFLoader) |
| 148 | + |
| 149 | +### Controls |
| 150 | +- [OrbitControls](https://threejs.org/docs/#examples/en/controls/OrbitControls) |
| 151 | +- [TransformControls](https://threejs.org/docs/#examples/en/controls/TransformControls) |
| 152 | + |
| 153 | +### Math |
| 154 | +- [Vector2](https://threejs.org/docs/#api/en/math/Vector2) |
| 155 | +- [Vector3](https://threejs.org/docs/#api/en/math/Vector3) |
| 156 | +- [Matrix4](https://threejs.org/docs/#api/en/math/Matrix4) |
| 157 | +- [Quaternion](https://threejs.org/docs/#api/en/math/Quaternion) |
| 158 | +- [Color](https://threejs.org/docs/#api/en/math/Color) |
0 commit comments