llms.txt 5.3 KB

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