@null3d/engine 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/README.md +109 -0
  2. package/THIRD-PARTY-NOTICES.txt +0 -1
  3. package/dist/wasm/single/null3d.js +19 -6
  4. package/dist/wasm/single/null3d_bg.wasm +0 -0
  5. package/dist/wasm/threaded/null3d.js +19 -6
  6. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  7. package/docs/api/animation.md +23 -67
  8. package/docs/api/assets.md +42 -26
  9. package/docs/api/cameras.md +8 -6
  10. package/docs/api/controls.md +46 -44
  11. package/docs/api/debug.md +13 -8
  12. package/docs/api/engine.md +17 -11
  13. package/docs/api/feature-draws.md +3 -3
  14. package/docs/api/feature-effects.md +3 -3
  15. package/docs/api/feature-instances.md +2 -2
  16. package/docs/api/features.md +14 -15
  17. package/docs/api/geometry.md +56 -75
  18. package/docs/api/grass.md +1 -1
  19. package/docs/api/impostors.md +120 -9
  20. package/docs/api/input.md +4 -11
  21. package/docs/api/lights.md +14 -38
  22. package/docs/api/lines.md +8 -25
  23. package/docs/api/materials.md +69 -70
  24. package/docs/api/math.md +6 -7
  25. package/docs/api/objects.md +13 -13
  26. package/docs/api/particles.md +2 -14
  27. package/docs/api/points.md +3 -25
  28. package/docs/api/post.md +22 -23
  29. package/docs/api/quality.md +11 -6
  30. package/docs/api/raycast.md +13 -32
  31. package/docs/api/reference/animation.md +9 -9
  32. package/docs/api/reference/assets.md +18 -18
  33. package/docs/api/reference/cameras.md +5 -2
  34. package/docs/api/reference/controls.md +75 -23
  35. package/docs/api/reference/debug.md +23 -8
  36. package/docs/api/reference/engine.md +22 -10
  37. package/docs/api/reference/geometry.md +161 -82
  38. package/docs/api/reference/grass.md +1 -1
  39. package/docs/api/reference/impostors.md +92 -1
  40. package/docs/api/reference/input.md +3 -3
  41. package/docs/api/reference/lights.md +9 -9
  42. package/docs/api/reference/lines.md +7 -7
  43. package/docs/api/reference/materials.md +48 -48
  44. package/docs/api/reference/math.md +22 -22
  45. package/docs/api/reference/objects.md +9 -9
  46. package/docs/api/reference/points.md +4 -4
  47. package/docs/api/reference/post.md +18 -18
  48. package/docs/api/reference/quality.md +7 -3
  49. package/docs/api/reference/raycast.md +6 -6
  50. package/docs/api/reference/render.md +2 -2
  51. package/docs/api/reference/scene.md +29 -26
  52. package/docs/api/reference/sketch.md +4 -0
  53. package/docs/api/reference/sound.md +203 -0
  54. package/docs/api/reference/sprites.md +5 -5
  55. package/docs/api/reference/terrain.md +2 -1
  56. package/docs/api/reference/textures.md +4 -4
  57. package/docs/api/reference/ui.md +3 -3
  58. package/docs/api/reference/vertex-draws.md +3 -3
  59. package/docs/api/reference/water.md +77 -6
  60. package/docs/api/reference/wind.md +2 -2
  61. package/docs/api/render.md +12 -10
  62. package/docs/api/scene.md +40 -29
  63. package/docs/api/sketch.md +64 -3
  64. package/docs/api/sound.md +169 -0
  65. package/docs/api/splats.md +7 -0
  66. package/docs/api/sprites.md +4 -20
  67. package/docs/api/tasks.md +2 -2
  68. package/docs/api/terrain.md +2 -14
  69. package/docs/api/textures.md +9 -9
  70. package/docs/api/ui.md +3 -15
  71. package/docs/api/water.md +198 -15
  72. package/docs/api/wind.md +5 -5
  73. package/docs/cli/null3d.md +93 -18
  74. package/docs/concepts/architecture.md +10 -10
  75. package/docs/concepts/assets.md +2 -19
  76. package/docs/concepts/backends.md +7 -5
  77. package/docs/concepts/color-management.md +15 -26
  78. package/docs/concepts/culling.md +1 -1
  79. package/docs/concepts/instances.md +5 -5
  80. package/docs/concepts/large-worlds.md +1 -1
  81. package/docs/concepts/lighting.md +50 -55
  82. package/docs/concepts/lod.md +2 -15
  83. package/docs/concepts/materials.md +16 -16
  84. package/docs/concepts/post-processing.md +7 -29
  85. package/docs/concepts/quality-preset-tables.md +53 -50
  86. package/docs/concepts/quality-presets.md +56 -27
  87. package/docs/concepts/render-graph.md +19 -14
  88. package/docs/concepts/render-layers.md +3 -17
  89. package/docs/concepts/shadows.md +10 -28
  90. package/docs/concepts/static-dynamic.md +2 -2
  91. package/docs/cookbook/index.md +1 -1
  92. package/docs/data/threejs-mapping.json +136 -102
  93. package/docs/errors/E1214.md +3 -3
  94. package/docs/errors/E1307.md +23 -0
  95. package/docs/errors/E1420.md +3 -3
  96. package/docs/errors/index.md +3 -2
  97. package/docs/getting-started/cdn.md +17 -1
  98. package/docs/getting-started/first-scene.md +1 -1
  99. package/docs/getting-started/hosting.md +50 -9
  100. package/docs/getting-started/install.md +8 -7
  101. package/docs/getting-started/network-use.md +10 -2
  102. package/docs/getting-started/project-structure.md +15 -6
  103. package/docs/getting-started/third-party-notices.md +8 -6
  104. package/docs/guides/accessibility.md +1 -1
  105. package/docs/guides/add-ons.md +3 -2
  106. package/docs/guides/agents.md +16 -5
  107. package/docs/guides/assets-pipeline.md +13 -12
  108. package/docs/guides/audio.md +109 -124
  109. package/docs/guides/car-paint.md +1 -1
  110. package/docs/guides/content-pages.md +10 -6
  111. package/docs/guides/custom-passes.md +9 -8
  112. package/docs/guides/custom-shaders.md +6 -3
  113. package/docs/guides/debugging.md +78 -4
  114. package/docs/guides/deploying.md +105 -5
  115. package/docs/guides/deterministic-simulation.md +1 -1
  116. package/docs/guides/first-use-shaders.md +4 -4
  117. package/docs/guides/loading-screens.md +78 -33
  118. package/docs/guides/multiple-views.md +41 -2
  119. package/docs/guides/performance.md +6 -3
  120. package/docs/guides/phones.md +12 -1
  121. package/docs/guides/physics.md +1 -1
  122. package/docs/guides/screens.md +7 -5
  123. package/docs/guides/start-time.md +328 -0
  124. package/docs/guides/testing.md +23 -5
  125. package/docs/guides/ui-overlays.md +3 -3
  126. package/docs/index.md +12 -8
  127. package/docs/pages.md +26 -23
  128. package/docs/porting/react-three-fiber.md +228 -5
  129. package/docs/porting/threejs-loop-and-threads.md +220 -6
  130. package/docs/porting/threejs-mapping.md +86 -84
  131. package/docs/porting/threejs-materials.md +212 -5
  132. package/docs/porting/threejs-overview.md +218 -5
  133. package/docs/porting/threejs-postprocessing.md +2 -2
  134. package/docs/porting/threejs-shaders.md +298 -5
  135. package/docs/porting/threejs-unsupported.md +82 -6
  136. package/docs/porting/verification.md +181 -5
  137. package/docs/shaders/builtins.md +1 -1
  138. package/docs/shaders/library.md +63 -39
  139. package/docs/shaders/surface-functions.md +11 -10
  140. package/docs/shaders/wgsl-rules.md +1 -1
  141. package/lib/debug/channel.d.ts +103 -0
  142. package/lib/debug/channel.js +269 -0
  143. package/lib/debug/debug.d.ts +9 -7
  144. package/lib/debug/draw.d.ts +9 -0
  145. package/lib/debug/draw.js +49 -2
  146. package/lib/debug/inspector.d.ts +60 -0
  147. package/lib/debug/inspector.js +475 -0
  148. package/lib/debug/stats-panel.d.ts +1 -1
  149. package/lib/debug/stats.d.ts +2 -3
  150. package/lib/errors/codes.js +8 -2
  151. package/lib/errors/engine-error.js +25 -10
  152. package/lib/errors/fixes.d.ts +1 -0
  153. package/lib/errors/fixes.js +3 -2
  154. package/lib/generated/core.d.ts +1 -1
  155. package/lib/generated/core.js +1 -1
  156. package/lib/gpu/early-builds.d.ts +68 -0
  157. package/lib/gpu/early-builds.js +158 -0
  158. package/lib/gpu/pipeline-name.d.ts +6 -0
  159. package/lib/gpu/pipeline-name.js +23 -0
  160. package/lib/gpu/webgl2/backend.d.ts +63 -2
  161. package/lib/gpu/webgl2/backend.js +226 -8
  162. package/lib/gpu/webgl2/programs.d.ts +18 -0
  163. package/lib/gpu/webgl2/programs.js +4 -1
  164. package/lib/gpu/webgpu/backend.d.ts +89 -2
  165. package/lib/gpu/webgpu/backend.js +255 -8
  166. package/lib/gpu/webgpu/pipelines.d.ts +13 -0
  167. package/lib/gpu/webgpu/pipelines.js +15 -1
  168. package/lib/index.d.ts +6 -4
  169. package/lib/index.js +3 -2
  170. package/lib/math/color.d.ts +5 -5
  171. package/lib/math/color.js +5 -5
  172. package/lib/math/mat4.d.ts +6 -12
  173. package/lib/math/mat4.js +6 -12
  174. package/lib/math/namespaces/quat.d.ts +3 -3
  175. package/lib/math/namespaces/quat.js +3 -3
  176. package/lib/math/quat.d.ts +8 -12
  177. package/lib/math/quat.js +8 -12
  178. package/lib/math/random.d.ts +2 -3
  179. package/lib/math/random.js +2 -3
  180. package/lib/math/types.d.ts +4 -4
  181. package/lib/math/vec3.d.ts +3 -6
  182. package/lib/math/vec3.js +3 -6
  183. package/lib/page/capabilities.d.ts +7 -7
  184. package/lib/page/capabilities.js +39 -25
  185. package/lib/page/check-store.d.ts +14 -2
  186. package/lib/page/check-store.js +34 -11
  187. package/lib/page/engine.d.ts +103 -26
  188. package/lib/page/engine.js +420 -97
  189. package/lib/page/first-frame.d.ts +16 -0
  190. package/lib/page/first-frame.js +35 -0
  191. package/lib/page/frame-stats.d.ts +34 -1
  192. package/lib/page/frame-stats.js +15 -0
  193. package/lib/page/label-loop.d.ts +7 -3
  194. package/lib/page/label-loop.js +17 -10
  195. package/lib/page/labels.d.ts +3 -3
  196. package/lib/page/pipeline-store.d.ts +25 -0
  197. package/lib/page/pipeline-store.js +84 -0
  198. package/lib/page/start-marker.d.ts +4 -1
  199. package/lib/page/start-marker.js +5 -2
  200. package/lib/page/switches.d.ts +32 -2
  201. package/lib/page/switches.js +9 -1
  202. package/lib/quality/check.d.ts +24 -3
  203. package/lib/quality/check.js +21 -7
  204. package/lib/quality/chooser.d.ts +6 -0
  205. package/lib/quality/chooser.js +8 -0
  206. package/lib/quality/governor.d.ts +98 -6
  207. package/lib/quality/governor.js +250 -20
  208. package/lib/quality/preset-docs.d.ts +16 -1
  209. package/lib/quality/preset-docs.js +3 -0
  210. package/lib/quality/presets.d.ts +84 -7
  211. package/lib/quality/presets.js +94 -2
  212. package/lib/render/draw.d.ts +3 -2
  213. package/lib/render/draw.js +15 -5
  214. package/lib/render/load-draw.d.ts +7 -5
  215. package/lib/render/load-draw.js +7 -5
  216. package/lib/render/loss.d.ts +28 -10
  217. package/lib/render/loss.js +50 -22
  218. package/lib/render/recovery.d.ts +20 -0
  219. package/lib/render/recovery.js +44 -4
  220. package/lib/render/renderer.d.ts +85 -9
  221. package/lib/render/renderer.js +181 -42
  222. package/lib/render/scene-renderer.d.ts +19 -1
  223. package/lib/render/scene-renderer.js +25 -1
  224. package/lib/render/webgl2-renderers.js +8 -5
  225. package/lib/render/webgpu-renderers.js +5 -4
  226. package/lib/scene/animation.d.ts +28 -32
  227. package/lib/scene/animation.js +12 -15
  228. package/lib/scene/assets.d.ts +61 -86
  229. package/lib/scene/assets.js +103 -236
  230. package/lib/scene/background.d.ts +14 -18
  231. package/lib/scene/background.js +5 -2
  232. package/lib/scene/color.d.ts +3 -3
  233. package/lib/scene/downloads.d.ts +2 -0
  234. package/lib/scene/downloads.js +371 -0
  235. package/lib/scene/environment.d.ts +7 -7
  236. package/lib/scene/environment.js +1 -1
  237. package/lib/scene/fake-call-values.js +1 -1
  238. package/lib/scene/fog.d.ts +11 -4
  239. package/lib/scene/fog.js +8 -2
  240. package/lib/scene/frame-cameras.d.ts +19 -0
  241. package/lib/scene/frame-cameras.js +58 -0
  242. package/lib/scene/gltf.d.ts +32 -2
  243. package/lib/scene/gltf.js +78 -49
  244. package/lib/scene/grading.d.ts +2 -2
  245. package/lib/scene/grading.js +3 -3
  246. package/lib/scene/ktx2.d.ts +9 -1
  247. package/lib/scene/ktx2.js +3 -2
  248. package/lib/scene/level-rule.d.ts +120 -0
  249. package/lib/scene/level-rule.js +130 -0
  250. package/lib/scene/lines.d.ts +13 -17
  251. package/lib/scene/lines.js +3 -3
  252. package/lib/scene/lut.d.ts +1 -2
  253. package/lib/scene/lut.js +1 -2
  254. package/lib/scene/picks.d.ts +2 -2
  255. package/lib/scene/pointer-events.d.ts +4 -7
  256. package/lib/scene/post.d.ts +38 -43
  257. package/lib/scene/post.js +4 -1
  258. package/lib/scene/prefab.d.ts +7 -8
  259. package/lib/scene/prefab.js +7 -8
  260. package/lib/scene/property-animation.d.ts +1 -1
  261. package/lib/scene/property-animation.js +1 -1
  262. package/lib/scene/queries.d.ts +7 -13
  263. package/lib/scene/resources.d.ts +225 -254
  264. package/lib/scene/resources.js +179 -81
  265. package/lib/scene/scene.d.ts +149 -118
  266. package/lib/scene/scene.js +196 -98
  267. package/lib/scene/serial-loads.d.ts +29 -0
  268. package/lib/scene/serial-loads.js +68 -0
  269. package/lib/scene/shader-preloads.d.ts +34 -0
  270. package/lib/scene/shader-preloads.js +38 -0
  271. package/lib/scene/sprites.d.ts +14 -17
  272. package/lib/scene/sprites.js +5 -6
  273. package/lib/scene/textures.d.ts +11 -12
  274. package/lib/scene/textures.js +9 -10
  275. package/lib/scene/time-of-day.d.ts +3 -4
  276. package/lib/scene/time-of-day.js +2 -3
  277. package/lib/scene/vertex-draws.d.ts +5 -4
  278. package/lib/scene/vertex-draws.js +7 -5
  279. package/lib/shader-artifact.json +1 -0
  280. package/lib/shared/core.d.ts +5 -0
  281. package/lib/shared/core.js +1 -0
  282. package/lib/shared/import-once.d.ts +6 -0
  283. package/lib/shared/import-once.js +19 -0
  284. package/lib/shared/metrics.d.ts +38 -0
  285. package/lib/shared/metrics.js +62 -1
  286. package/lib/shared/run-task.js +7 -1
  287. package/lib/shared/task-pending.d.ts +12 -0
  288. package/lib/shared/task-pending.js +61 -1
  289. package/lib/shared/tasks.js +79 -32
  290. package/lib/shared/version.d.ts +17 -1
  291. package/lib/shared/version.js +19 -1
  292. package/lib/shared/wasm.d.ts +12 -4
  293. package/lib/shared/wasm.js +50 -27
  294. package/lib/shared/worker-start.d.ts +7 -0
  295. package/lib/shared/worker-start.js +27 -0
  296. package/lib/sketch/define-sketch.d.ts +35 -0
  297. package/lib/sketch/input.d.ts +2 -2
  298. package/lib/sketch/preset-check.d.ts +20 -6
  299. package/lib/sketch/preset-check.js +42 -17
  300. package/lib/sketch/quality.d.ts +69 -11
  301. package/lib/sketch/quality.js +54 -13
  302. package/lib/sketch/runner.d.ts +76 -9
  303. package/lib/sketch/runner.js +385 -52
  304. package/lib/sketch/ui.d.ts +5 -8
  305. package/lib/workers/probe-worker.d.ts +5 -0
  306. package/lib/workers/probe-worker.js +13 -4
  307. package/lib/workers/protocol.d.ts +61 -13
  308. package/lib/workers/protocol.js +4 -0
  309. package/lib/workers/render-worker.js +25 -4
  310. package/lib/workers/sketch-worker.js +104 -15
  311. package/package.json +2 -2
@@ -57,9 +57,9 @@ The options of `scene.setBackground` for a texture, an environment, a cube map o
57
57
 
58
58
  | Member | Description |
59
59
  | --- | --- |
60
- | `intensity?: number` | The factor of the background's light, 0 or more, as three.js's `scene.backgroundIntensity`. The default is 1. |
61
- | `blur?: number` | How much an environment blurs, from 0 (sharp) to 1, as three.js's `scene.backgroundBlurriness`. It reads the environment's light at that roughness, so a blurred background costs no more than a sharp one. Only environments blur. The default is 0. |
62
- | `rotation?: readonly [number, number, number]` | The turn of a cube map or an environment about the scene, as Euler angles in radians in the order X, Y, Z, as three.js's `scene.backgroundRotation`. The default is `[0, 0, 0]`. |
60
+ | `intensity?: number` | The factor of the background's light, 0 or more. The default is 1. |
61
+ | `blur?: number` | How much an environment blurs, from 0 (sharp) to 1. It reads the environment's light at that roughness, so a blurred background costs no more than a sharp one. Only environments blur. The default is 0. |
62
+ | `rotation?: readonly [number, number, number]` | The turn of a cube map or an environment about the scene, as Euler angles in radians in the order X, Y, Z. The default is `[0, 0, 0]`. |
63
63
 
64
64
  ## `BackgroundSource`
65
65
 
@@ -67,7 +67,7 @@ The options of `scene.setBackground` for a texture, an environment, a cube map o
67
67
  type BackgroundSource = Texture | Environment | Cubemap | SkyBackground | AtmosphereBackground;
68
68
  ```
69
69
 
70
- What `scene.setBackground` draws behind every object in place of a plain color: a texture, an environment, a cube map, three.js's sky or the physical sky.
70
+ What `scene.setBackground` draws behind every object in place of a plain color: a texture, an environment, a cube map, the analytic sky or the physical sky.
71
71
 
72
72
  ## `bakeProbes`
73
73
 
@@ -139,8 +139,8 @@ The options of `scene.setEnvironment`. A call that leaves an option out takes it
139
139
 
140
140
  | Member | Description |
141
141
  | --- | --- |
142
- | `intensity?: number` | The factor of the environment's light on every surface, 0 or more, as three.js's `scene.environmentIntensity`. A material's `envIntensity` multiplies it. The default is 1. |
143
- | `rotation?: readonly [number, number, number]` | The turn of the environment about the scene, as Euler angles in radians in the order X, Y, Z, as three.js's `scene.environmentRotation`. The default is `[0, 0, 0]`. |
142
+ | `intensity?: number` | The factor of the environment's light on every surface, 0 or more. A material's `envIntensity` multiplies it. The default is 1. |
143
+ | `rotation?: readonly [number, number, number]` | The turn of the environment about the scene, as Euler angles in radians in the order X, Y, Z. The default is `[0, 0, 0]`. |
144
144
 
145
145
  ## `FogCurve`
146
146
 
@@ -148,7 +148,7 @@ The options of `scene.setEnvironment`. A call that leaves an option out takes it
148
148
  type FogCurve = 'exponential' | 'exp2' | 'linear';
149
149
  ```
150
150
 
151
- How fog thickens with distance. Exponential fog, `'exponential'`, follows light through an even haze. An object at distance d takes the fog color by a factor of 1 - exp(-density × d). Exponential squared fog, `'exp2'`, thickens with the square of the distance, as three.js's `FogExp2`: 1 - exp(-(density × d)²). Linear fog, `'linear'`, is clear up to `near` and hides objects from `far`, with a smooth step between them, as three.js's `Fog`.
151
+ How fog thickens with distance. Exponential fog, `'exponential'`, follows light through an even haze. An object at distance d takes the fog color by a factor of 1 - exp(-density × d). Exponential squared fog, `'exp2'`, thickens with the square of the distance: 1 - exp(-(density × d)²). Linear fog, `'linear'`, is clear up to `near` and hides objects from `far`, with a smooth step between them.
152
152
 
153
153
  ## `FogOptions`
154
154
 
@@ -158,7 +158,7 @@ Options of `scene.setFog`. Fog measures each object's straight-line distance fro
158
158
 
159
159
  | Member | Description |
160
160
  | --- | --- |
161
- | `color: ColorInput` | The fog's color. Give the background the same color, because the background takes no fog. |
161
+ | `color: ColorInput` | The fog's color. A scene whose background takes the fog needs no other color for it. |
162
162
  | `curve?: FogCurve` | How the fog thickens with distance. The default is `'exponential'`. |
163
163
  | `density?: number` | How fast exponential and exponential squared fog thicken with distance: 0 or more. At the default of 0.01, exponential fog hides about two thirds of an object 100 units away. |
164
164
  | `near?: number` | The distance where linear fog starts. The default is 1. |
@@ -167,6 +167,7 @@ Options of `scene.setFog`. Fog measures each object's straight-line distance fro
167
167
  | `heightFalloff?: number` | How fast the fog thins with height, 0 or more: its density falls by a factor of e, to about a third, every 1 / `heightFalloff` units up. The engine adds up the fog along each line of sight, so a view down into a valley sees thick fog and a view up sees clear air. The default is 0: the fog is the same at every height. |
168
168
  | `sunGlow?: number` | How much of the main directional light the fog scatters toward the camera, 0 or more. Fog toward that light then glows in the light's color. The default is 0: no glow. |
169
169
  | `sunGlowExponent?: number` | How tightly the glow gathers around the light's direction, above 0. Higher values make a smaller glow. The default is 8. |
170
+ | `background?: number` | How much of the fog the background takes, 0 to 1. At 1, the sky and a cube-map background take the same fog as a surface at the camera's far plane, so a scene's haze carries on over the sky it meets and the far edge of the land and the sky read as one. The camera's far plane must be within the fog's reach for the haze to be full. The default is 0: the background takes no fog. |
170
171
  | `volumetric?: boolean \| FogVolumeOptions` | Lights the fog with the main directional light and the point and spot lights, through their shadows: sun rays through gaps in trees, and glowing cones under lamps and headlights. `true` takes the default options. While it draws, it replaces `sunGlow` with its own light of the sun. It needs HDR color, and the quality setting `fogSlices` above 0: on the Low preset the fog keeps its sun glow. The default is `false`. |
171
172
 
172
173
  ## `FogVolumeOptions`
@@ -222,8 +223,8 @@ Options for `scene.createInstances`.
222
223
  | --- | --- |
223
224
  | `material: Material` | The material of every row. |
224
225
  | `dynamic?: boolean` | Every row updates and uploads every frame; a static batch updates rows marked dirty only. |
225
- | `colors?: boolean` | Adds a color per row (RGBA, linear) in `batch.colors`, white at first. It multiplies the material's base color and opacity, as a mesh's vertex colors do, and as three.js's `InstancedMesh.setColorAt` does. A material that lets light through draws its rows without it. |
226
- | `values?: boolean` | Adds four numbers per row of the sketch's own in `batch.values`, 0 at first, such as a wind phase, an age or a tint. A custom material's `surface`, `vertexOffset` and `lobe` functions read the row's as `object.values`, as three.js's instanced attributes give a shader values per instance. With values, a masked material tests its alpha against its cutoff, without alpha to coverage or the alpha hash. |
226
+ | `colors?: boolean` | Adds a color per row (RGBA, linear) in `batch.colors`, white at first. It multiplies the material's base color and opacity, as a mesh's vertex colors do. A material that lets light through draws its rows without it. |
227
+ | `values?: boolean` | Adds four numbers per row of the sketch's own in `batch.values`, 0 at first, such as a wind phase, an age or a tint. A custom material's `surface`, `vertexOffset` and `lobe` functions read the row's as `object.values`. With values, a masked material tests its alpha against its cutoff, without alpha to coverage or the alpha hash. |
227
228
  | `ranges?: boolean` | Adds a start and an end distance per row in `batch.ranges`, so each row draws in a band of its own. Leave it out for a range that every row shares, which costs no memory. |
228
229
  | `layers?: number` | The layers every row is on, as a 32-bit mask. The default, 1, is layer 0. |
229
230
  | `origin?: Vec3` | The point that every row's position is relative to. The default is (0, 0, 0). The engine keeps the origin at full precision, so rows near it keep the precision of 32-bit floats at any distance from the world's origin. Give a batch far from the origin, such as a forest on a planet, an origin among its rows. |
@@ -285,7 +286,7 @@ Options for `scene.createMesh`.
285
286
  | --- | --- |
286
287
  | `mesh: MeshGeometry` | The shape to draw, from `ctx.geometry`. |
287
288
  | `material: Material` | How the surface looks, from `ctx.materials`. |
288
- | `castShadows?: boolean` | True makes the mesh cast the shadows of a directional light, like `setCastShadows(true)`. The default is false. |
289
+ | `castShadows?: boolean` | True makes the mesh cast the shadows of the lights that cast them, like `setCastShadows(true)`. The default is false. |
289
290
  | `receiveShadows?: boolean` | True makes shadows fall on the mesh, like `setReceiveShadows(true)`. The default is false. Unlit materials show no shadows. |
290
291
  | `occluder?: boolean` | Whether the mesh blocks the view for occlusion culling, like `setOccluder`. True makes it a blocker on WebGL2 too. False keeps it from hiding anything on WebGPU. Left out, the mesh blocks nothing on WebGL2, and on WebGPU it hides what lies behind it whenever it looks large enough. |
291
292
 
@@ -316,7 +317,7 @@ The group that holds a copy of a model, which `scene.instantiate` returns. Its c
316
317
  | `batches: readonly InstanceBatch[]` | The instance batches of the nodes with instancing of their own, as the file gives them. Their rows are placed in the world when the copy is created, and they do not move with the group. |
317
318
  | `find(name: string): Object3D \| undefined` | The copy's first object with `name`, in the file's order, which is not destroyed, or undefined. It searches the copy's objects, so call it at setup. |
318
319
  | `destroy(): void` | Removes the whole copy at the next frame: this group, every object that the copy created and that is not destroyed yet, and its instance batches. Objects that the sketch put under the copy later become roots, as children of any destroyed object do. |
319
- | `setOutlined(outlined: boolean): void` | Outlines every mesh of the copy, or stops, as `Mesh.setOutlined` does for one mesh: the whole model takes one outline, as three.js's `OutlinePass` outlines a selected group. The copy's instance batches take none. |
320
+ | `setOutlined(outlined: boolean): void` | Outlines every mesh of the copy, or stops, as `Mesh.setOutlined` does for one mesh: the whole model takes one outline. The copy's instance batches take none. |
320
321
 
321
322
  ## `ProbeBake`
322
323
 
@@ -371,25 +372,27 @@ The scene: every object, the active camera, the lights and the background.
371
372
  | --- | --- |
372
373
  | `dropViews(): void` | Forgets the views of the scene's arrays and of the morph weights. |
373
374
  | `find(name: string): Object3D \| undefined` | The first object created with `name` that is not destroyed, or undefined when no object has the name. It looks the name up in an index, so its cost does not grow with the scene. Call it at setup and keep the object it returns. |
375
+ | `listObjects(): Object3D[]` | Every object of the scene that is not destroyed, in the order of their slots, as a new array. The in-page inspector lists the scene with it. It walks the whole scene and allocates, so call it from tools and setup code, never in every frame. |
374
376
  | `createGroup(options: NodeOptions = {}): Group` | An empty node, for hierarchy. |
375
377
  | `createMesh(options: MeshOptions): Mesh` | A drawn object. It is static unless `dynamic: true`. |
376
378
  | `instantiate(prefab: Prefab, options: InstantiateOptions = {}): PrefabInstance` | Creates the objects of a model that `assets.loadGltf` loaded, under one new group that `options` places, and returns that group. All the objects are created with one batch of commands, and every copy shares the model's meshes, materials and textures. The group's `find` gives the copy's object of a node, by the node's name. A model with clips or skins gives the group an animator, which plays the clips: `copy.animator().play('Walk')`. Throws E1102 when the scene, the animation table or the batch table has no room for the copy. Then no part of the copy stays. `destroy()` on the group removes the whole copy. |
377
379
  | `animateProperty(target: Light \| Camera \| Material \| Object3D, path: string, keyframes: PropertyKeyframes): PropertyAnimation` | Animates one value of a light, a camera, a material or an object from keyframes, such as a lamp that pulses or a color that changes, and returns an object that controls it. The engine writes the value in each frame, so the sketch has no update call to make. A glTF file animates the same kinds of value with its `KHR_animation_pointer` channels. `path` names the value. A light takes `'light.intensity'`, `'light.color'`, `'light.range'`, `'light.decay'`, `'light.angle'` or `'light.penumbra'`; a camera takes `'camera.fov'` (in degrees), `'camera.near'`, `'camera.far'` or `'camera.height'` (for an orthographic camera); a material takes the values that `setUniform` takes, such as `'material.opacity'` or `'material.color'`; and every object takes `'position'`, `'rotation'`, `'scale'` or `'visible'`. The prefix is optional, so `'intensity'` and `'position'` work too. Every object that uses the material changes with it, and an animation that writes every frame allocates nothing. `setTime` places the animation at a time; a frozen keyframes object is read once. Throws E1218 for a path that the target does not take, or for keyframes that do not fit the value's numbers per key. |
378
- | `clone<T extends Object3D>(object: T): T` | Copies an object and every object below it, as three.js's `clone` does, with their meshes, materials, lights, cameras and settings, and returns the copy of the object. The copy has the same parent, so it starts in the same place. The copies are created with one batch of commands. An animated object's copy gets an animator of its own, with no clip playing, which moves the copies of its meshes, as three.js's `SkeletonUtils.clone` does. Instance batches are not objects, so they are not copied. Throws E1102 when the scene or the animation table has no room for the copies. Then no copy stays. |
380
+ | `clone<T extends Object3D>(object: T): T` | Copies an object and every object below it, with their meshes, materials, lights, cameras and settings, and returns the copy of the object. The copy has the same parent, so it starts in the same place. The copies are created with one batch of commands. An animated object's copy gets an animator of its own, with no clip playing, which moves the copies of its meshes. Instance batches are not objects, so they are not copied. Throws E1102 when the scene or the animation table has no room for the copies. Then no copy stays. |
379
381
  | `createInstances(mesh: MeshGeometry, count: number, options: InstanceOptions): InstanceBatch` | Many copies of one mesh and material, with typed arrays of rows. Or many copies of a model that `assets.loadGltf` loaded, without a material: one batch for each mesh of the model, which share one set of rows, so one row places a whole copy. The model's lights are left out. Throws E1417 for a model with no meshes, or with instancing of its own. |
380
382
  | `createInstances(prefab: Prefab, count: number, options?: Omit<InstanceOptions, 'material'>): InstanceBatch` | Many copies of one mesh and material, with typed arrays of rows. Or many copies of a model that `assets.loadGltf` loaded, without a material: one batch for each mesh of the model, which share one set of rows, so one row places a whole copy. The model's lights are left out. Throws E1417 for a model with no meshes, or with instancing of its own. |
381
- | `createSprites(options: SpriteOptions): Promise<SpriteBatch>` | Many sprites in one batch: quads that face the camera, like three.js's `Sprite` with a `SpriteMaterial`. Typed arrays give each sprite its position, size, rotation, color and atlas frame, as an instance batch's arrays give its rows. Sprites blend by default, and blended sprites draw back to front with the other blended objects. The first call downloads the sprite code. Throws E1108 for an atlas side that is not a whole number from 1 to 2048, E1203 for a center that is not two finite numbers, and E1406 when the sprite code does not download. |
382
- | `createPoints(options: PointOptions): Promise<PointBatch>` | Many points in one batch: squares that face the camera, all of one size, like three.js's `Points` with a `PointsMaterial`. Each point is a sprite: typed arrays give each point its position and color, as an instance batch's arrays give its rows. Sizes above one pixel work on every GPU path. Points are opaque by default, and blended points draw back to front with the other blended objects. The first call downloads the sprite code. Throws E1206 for points or colors that make no points, E1108 for a size that is not above 0, E1203 for a size that is not finite, and E1406 when the sprite code does not download. |
383
+ | `createSprites(options: SpriteOptions): Promise<SpriteBatch>` | Many sprites in one batch: quads that face the camera. Typed arrays give each sprite its position, size, rotation, color and atlas frame, as an instance batch's arrays give its rows. Sprites blend by default, and blended sprites draw back to front with the other blended objects. The first call downloads the sprite code. Throws E1108 for an atlas side that is not a whole number from 1 to 2048, E1203 for a center that is not two finite numbers, and E1406 when the sprite code does not download. |
384
+ | `createPoints(options: PointOptions): Promise<PointBatch>` | Many points in one batch: squares that face the camera, all of one size. Each point is a sprite: typed arrays give each point its position and color, as an instance batch's arrays give its rows. Sizes above one pixel work on every GPU path. Points are opaque by default, and blended points draw back to front with the other blended objects. The first call downloads the sprite code. Throws E1206 for points or colors that make no points, E1108 for a size that is not above 0, E1203 for a size that is not finite, and E1406 when the sprite code does not download. |
383
385
  | `addFeatureDraw<const Wgsl extends string \| CompiledWgsl>(description: FeatureDescription, options: FeatureDrawOptions<Wgsl>): Promise<FeatureDraw<Wgsl>>` | An add-on's own kind of draw, declared by a feature description with the kind `'draw'`: its WGSL, its vertex data, its uniforms and the description's frame point, band and order. The engine draws the object on every GPU path and in every thread mode, as it draws the scene's other objects, and sorts a blended draw among the transparent pass's objects. The first call downloads the draw adapter. The description names the frame point: `'opaque'` with an opaque or masked material, `'transparent'` with a blended one, or `'resolve'` with a blended one that blends after the transparent pass's objects. With MSAA, a draw at `'resolve'` blends its surfaces back to front in a layer of one sample per pixel, which the engine then blends over the scene, so many overlapping surfaces, such as Gaussian splats, cost one blend per pixel instead of one per sample. Its surfaces show in front of every object of the transparent pass, and other views draw them in their own transparent pass. The band and order place a blended draw among the pass's objects. The adapter records in the main view alone, so a description with another view throws E1223. The description's `reads`, `writes`, `outputs` and `provides` stay with the feature registry: this draw draws no scene resource. Throws E1223 for a description that is not a draw the adapter can place, E1215, E1216 and E1217 for WGSL and values that `materials.shader` refuses, E1206 for vertex data that makes no mesh, and E1406 when the adapter does not download. |
384
386
  | `addFeatureInstances<const Wgsl extends string \| CompiledWgsl>(description: FeatureDescription, options: FeatureInstancesOptions<Wgsl>): Promise<FeatureInstances<Wgsl>>` | An add-on's own kind of draw, repeated once for each row of an instance batch, declared by a feature description with the kind `'draw'`. It takes the options of `addFeatureDraw` and a number of copies; each row of `draw.batch` places one copy and brings its own color and four values. The engine culls and sorts the rows in each view as it does a batch's, so a blended draw of many copies draws back to front on both GPU paths. Throws E1223 for a description that the adapter cannot place, for a place that belongs to one object, or for a count that is not a whole number from 1 up, E1215, E1216 and E1217 for WGSL and values that `materials.shader` refuses, E1206 for vertex data that makes no mesh, and E1406 when the adapter does not download. |
385
387
  | `addComputeInstances<const Wgsl extends string \| CompiledWgsl = string \| CompiledWgsl>(description: FeatureDescription, options: ComputeInstancesOptions<Wgsl>): Promise<ComputeInstances<Wgsl>>` | An add-on's own kind of draw whose instance count the GPU writes: the description places it, the options give its one shape, its shader and the most instances that it holds, and the add-on fills its per-instance data. On WebGPU the draw reads the add-on's instance buffer and the count word that its compute pass writes; the engine copies the count into the indirect draw each frame. WebGL2 has no compute, so the page sets the instances and the count on the CPU, which draws the same picture. The description names the frame point `'opaque'` and the main view alone. The draw is unculled: the add-on's own cull or count decides what draws. The first call downloads the adapter. Throws E1223 for a description that the adapter cannot place or a capacity that it cannot take, E1215, E1216 and E1217 for WGSL and values that `materials.shader` refuses, E1206 for vertex data that makes no mesh, and E1406 when the adapter does not download. A draw that arrives after the first frame on a device that draws directly fails the frame with E1506: create it in the setup, and await this call there. |
386
- | `createVertexDraw<const Wgsl extends string \| CompiledWgsl = string \| CompiledWgsl>(options: VertexDrawOptions<Wgsl>): VertexDraw<Wgsl>` | A draw that has a custom material and a vertex count but no mesh data: its shader makes every vertex of every copy from `@builtin(vertex_index)` and `@builtin(instance_index)`, so a draw of 50,000 rain streaks uploads nothing in a frame. The draw's object gives its place, its layers and the sphere that culls it, and the material's values move its shapes. The draw blends, so it draws in the transparent pass. The options take every option of `materials.shader` but the maps: a draw's WGSL declares no texture. The draw's culling sphere holds every shape, or a shape that leaves it stops drawing. A draw that uses the camera's position, such as rain around the camera, reads it in its WGSL, and `null3d::wrap` wraps a position relative to the camera into a box. Throws E1108 for a count or a sphere that the draw cannot take, or when the scene holds the most draws already, E1215 for WGSL that the plugin did not compile as a draw shader, and E1217 for a texture or an alpha mode that a draw does not take. |
388
+ | `createVertexDraw<const Wgsl extends string \| CompiledWgsl = string \| CompiledWgsl>(options: VertexDrawOptions<Wgsl>): VertexDraw<Wgsl>` | A draw that has a custom material and a vertex count but no mesh data: its shader makes every vertex of every copy from `@builtin(vertex_index)` and `@builtin(instance_index)`, so a draw of 50,000 rain streaks uploads nothing in a frame. The draw's object gives its place, its layers and the sphere that culls it. The engine writes no uniforms for its WGSL, so `frame.time` moves its shapes. The draw blends, so it draws in the transparent pass. The options take every option of `materials.shader` but the maps: a draw's WGSL declares no texture. The draw's culling sphere holds every shape, or a shape that leaves it stops drawing. A draw that uses the camera's position, such as rain around the camera, reads it in its WGSL, and `null3d::wrap` wraps a position relative to the camera into a box. Throws E1108 for a count or a sphere that the draw cannot take, or when the scene holds the most draws already, E1215 for WGSL that the plugin did not compile as a draw shader, and E1217 for a texture or an alpha mode that a draw does not take. |
387
389
  | `createParticleBuffer(options: ParticleBufferOptions): Promise<ParticleBuffer>` | A particle buffer: a scene object that draws a quad for each live particle, which the GPU moves and colors at the particle's age in closed form. The `@null3d/particles` add-on's emitters fill it; use the add-on rather than this call. The first call downloads the particle code. Throws E1108 for a capacity that is not a whole number from 1 to 4,194,304, or when the scene holds 256 particle buffers already, and E1406 when the particle code does not download. |
388
- | `createLines(options: LineOptions): Promise<LineBatch>` | Lines of any width in one batch, like three.js's `Line2` and `LineSegments2` with a `LineMaterial`, and its `Line`, `LineSegments` and `LineLoop`. Each segment between two points draws as a quad with round ends that faces the camera, `width` CSS pixels wide, or world units wide with `worldUnits`. A typed array gives each point its position and color, as an instance batch's arrays give its rows. The first call downloads the line code. Throws E1206 for points or colors that make no line, E1217 for an unknown mode, E1108 for a width that is not positive or a dash or gap below 0, E1203 for a value that is not finite, and E1406 when the line code does not download. |
390
+ | `createLines(options: LineOptions): Promise<LineBatch>` | Lines of any width in one batch: strips, loops or separate segments. Each segment between two points draws as a quad with round ends that faces the camera, `width` CSS pixels wide, or world units wide with `worldUnits`. A typed array gives each point its position and color, as an instance batch's arrays give its rows. The first call downloads the line code. Throws E1206 for points or colors that make no line, E1217 for an unknown mode, E1108 for a width that is not positive or a dash or gap below 0, E1203 for a value that is not finite, and E1406 when the line code does not download. |
389
391
  | `createPerspectiveCamera(options: PerspectiveCameraOptions = {}): PerspectiveCamera` | A perspective camera; `fov` is vertical, in degrees. Cameras are dynamic by default. |
390
392
  | `createOrthographicCamera(options: OrthographicCameraOptions = {}): OrthographicCamera` | An orthographic camera, whose view is a box: things keep their size at every distance. Give `height`, and the width follows the canvas, or give `left`, `right`, `top` and `bottom`. Cameras are dynamic by default. |
391
393
  | `setActiveCamera(camera: Camera): void` | Draws the scene from this camera. |
392
394
  | `createView(options: SceneViewOptions): SceneView` | Draws the scene again from `camera`, into the rectangle of the canvas that `rect` gives, after the camera's view and in the same frame: a split screen or a picture in picture. The view draws the scene once more at the rectangle's pixels, with its own culling, so its cost follows the rectangle's area. It draws the sun and its shadows as the camera's view does, which costs nothing more, the background and the fog. Its objects take no ambient occlusion or screen-space reflections, which shade the camera's view; the camera's volumetric fog and outline reach the whole image, a view's rectangle included. An object whose material shows a render pass's texture does not draw in a view. The camera's view still draws the whole canvas first, so a split screen that covers the canvas draws the scene one more time than it needs for its two halves. The scene and its passes share 32 views, the camera's included. Throws E1501 when the 32 views are in use. Development builds throw E1213 for a camera or a rectangle that a view does not take, and E1203 for a number that is not finite. |
395
+ | `viewAt(x: number, y: number): SceneView \| undefined` | The view whose image covers the point (`x`, `y`) in CSS pixels from the canvas's top-left corner, or undefined where only the camera's view shows. Where views overlap, it gives the one on top, which the engine draws last. Pass the view to `view.screenToRay` to pick in it, and use `camera.screenToRay` when it gives undefined. It allocates nothing. |
393
396
  | `createDirectionalLight(options: DirectionalLightOptions = {}): DirectionalLight` | Light from one direction, like sunlight: `direction` is the way it travels. |
394
397
  | `createPointLight(options: PointLightOptions): PointLight` | Light from a point in every direction, out to `range` meters, which it needs. |
395
398
  | `createSpotLight(options: SpotLightOptions): SpotLight` | Light from a point in a cone, out to `range` meters, which it needs. |
@@ -397,15 +400,15 @@ The scene: every object, the active camera, the lights and the background.
397
400
  | `createTubeLight(options: TubeLightOptions): TubeLight` | Light from a tube, `length` meters along `direction`, out to `range` meters, which it needs. |
398
401
  | `createHemisphereLight(options: HemisphereLightOptions = {}): HemisphereLight` | Light from the sky above and the ground below. |
399
402
  | `createAmbientLight(options: AmbientLightOptions = {}): AmbientLight` | Light on every surface, from no direction. |
400
- | `setBackground(background: ColorInput \| BackgroundSource, options?: BackgroundOptions): void` | What the camera shows behind every object, as three.js's `scene.background`: a color, a texture, an environment from `assets.loadEnvironment` or `assets.builtinEnvironment`, a cube map from `assets.loadCubemap`, three.js's sky with `{ sky: { sunPosition } }`, or the physical sky with `{ atmosphere: { sunPosition } }`, whose air also hazes distant objects. A texture fills the view and stretches to its shape. An environment or a cube map surrounds the scene, and `options` give its intensity, rotation and, for an environment, its blur, as three.js's `backgroundIntensity`, `backgroundRotation` and `backgroundBlurriness`. The color set before shows until a texture's texels are on the GPU, and again if the texture is destroyed. A color takes the place of any other background. Exposure and tone mapping change the background with the rest of the scene. Without a background, the canvas shows black, or the page behind it on a transparent canvas. Settings are values, not shader builds, and the call allocates nothing, so a sketch can move the sky's sun or turn a cube map every frame. Throws E1204 for a color it cannot read, E1203 for a number that is not finite, E1108 for a number out of its range, E1213 for an option that the background does not take, and E1101 for a texture, an environment or a cube map that was destroyed. |
403
+ | `setBackground(background: ColorInput \| BackgroundSource, options?: BackgroundOptions): void` | What the camera shows behind every object: a color, a texture, an environment from `assets.loadEnvironment` or `assets.builtinEnvironment`, a cube map from `assets.loadCubemap`, the analytic sky with `{ sky: { sunPosition } }`, or the physical sky with `{ atmosphere: { sunPosition } }`, whose air also hazes distant objects. A texture fills the view and stretches to its shape. An environment or a cube map surrounds the scene, and `options` give its intensity, rotation and, for an environment, its blur. The color set before shows until a texture's texels are on the GPU, and again if the texture is destroyed. A color takes the place of any other background. Exposure and tone mapping change the background with the rest of the scene. Without a background, the canvas shows black, or the page behind it on a transparent canvas. Settings are values, not shader builds, and the call allocates nothing, so a sketch can move the sky's sun or turn a cube map every frame. Throws E1204 for a color it cannot read, E1203 for a number that is not finite, E1108 for a number out of its range, E1213 for an option that the background does not take, and E1101 for a texture, an environment or a cube map that was destroyed. |
401
404
  | `setSkyLayer(description: FeatureDescription, options: SkyLayerOptions): SkyLayer` | Draws an add-on's sky layer over the background, under every object: the top of a sky, such as an aurora, a second layer of clouds or a space backdrop. The description is a feature description ([Add-on feature descriptions](../features.md)): it names the feature and records at the background point, as a draw, provides the sky, and draws in the main view, the scene passes and the reflections. The layer's WGSL, compiled by the null3D Vite plugin, declares `fn skyLayer(input: SkyLayerInput) -> SkyLayer`. The engine gives it the fragment's direction in the world, the core sky's cloud coverage, density, elevation and scale, the sketch time and the share of the sun that the layer hides, and it blends what the layer returns over the sky by the layer's coverage and opacity. A layer that hides part of the sun also dims the disc and glow that the core sky draws, through `sun`. The layer draws in the main view, in scene passes and in reflections, and draws nothing where the background draws nothing, as in a debug view. A second call replaces the layer. Throws E1223 for a description that the engine cannot place, E1215 for WGSL that the plugin did not compile as a sky layer, E1203 for a number that is not finite, and E1108 for a number out of its range. |
402
405
  | `clearSkyLayer(): void` | Removes the sky layer that `setSkyLayer` installed, from the next frame on, and gives the core sky its full sun back. A call with no layer installed does nothing. |
403
406
  | `setDecalLayers(mask: number): void` | Sets the layers whose objects decals mark, as a 32-bit mask as `setLayers` takes. An object that is also on a layer outside the mask shows no decals, so a character on a layer of its own walks through a puddle clean. Such objects draw a second time after the decals, over their own pixels, in each frame that has decals. The default is every layer. |
404
- | `overrideMaterial: Material \| null` | Draws every mesh and instance batch of the main pass with this material in place of its own, as three.js's `scene.overrideMaterial` does, or with their own materials with null. Each object keeps its mesh, its place and its instances, so a batch draws every row with it, and every camera view draws with it, the scene passes among them. Sprites, points, lines and particle systems keep their own materials, and the shadow maps keep each object's material, as three.js's shadow maps do. A change rebuilds the engine's draw tables in the next frame; after that it adds no draw call and builds no pipeline. Throws E1224 for a sprite, point or line material, E1101 for a material that is destroyed, and E1103 for a material of another engine. |
405
- | `setEnvironment(environment: Environment \| null, options?: EnvironmentOptions): void` | Lights the scene with an environment from `assets.loadEnvironment` or `assets.builtinEnvironment`, as three.js's `scene.environment` does with a texture from `PMREMGenerator`, or with none for null. Standard materials reflect it, sharply when smooth and blurred when rough, and take its diffuse light, each times its `envIntensity`. The scene draws without a file's environment until its map is on the GPU. The built-in room's map is whole in the first frame that uses it. It allocates nothing, so a sketch can turn the environment every frame. Throws E1203 for a number that is not finite, E1108 for a negative intensity, E1213 for a value that is not an environment, and E1101 for an environment that was destroyed. |
407
+ | `overrideMaterial: Material \| null` | Draws every mesh and instance batch of the main pass with this material in place of its own, or with their own materials with null. Each object keeps its mesh, its place and its instances, so a batch draws every row with it, and every camera view draws with it, the scene passes among them. Sprites, points, lines and particle systems keep their own materials, and the shadow maps keep each object's material, so a masked object still cuts its shadow. A change rebuilds the engine's draw tables in the next frame; after that it adds no draw call and builds no pipeline. Throws E1224 for a sprite, point or line material, E1101 for a material that is destroyed, and E1103 for a material of another engine. |
408
+ | `setEnvironment(environment: Environment \| null, options?: EnvironmentOptions): void` | Lights the scene with an environment from `assets.loadEnvironment` or `assets.builtinEnvironment`, or with none for null. Standard materials reflect it, sharply when smooth and blurred when rough, and take its diffuse light, each times its `envIntensity`. The scene draws without a file's environment until its map is on the GPU. The built-in room's map is whole in the first frame that uses it. It allocates nothing, so a sketch can turn the environment every frame. Throws E1203 for a number that is not finite, E1108 for a negative intensity, E1213 for a value that is not an environment, and E1101 for an environment that was destroyed. |
406
409
  | `createReflectionProbe(options: ReflectionProbeOptions): ReflectionProbe` | Makes a reflection probe: the scene around a point, which the engine captures on the GPU and filters for each roughness, as an environment's map. It lights the surfaces inside its box in place of the environment, with reflections that meet the box's sides, as a room's walls or a street's houses stand. A probe captures in a frame soon after it is made, and frames before that draw with the environment. A scene has at most 16 probes. Their captures take 6 of the 32 views that the scene and its passes share. Throws E1430 past those limits, E1203 for a number that is not finite, E1108 for a negative blend or intensity or a box whose min does not lie below its max, and E1213 for an option that probes do not take. |
407
410
  | `setLightProbeGrid(grid: LightProbeGridOptions \| null): void` | Lights the scene with a grid of irradiance probes, or with none for null. The grid's light takes the place of the environment's diffuse light where `environmentWeight` says so, so light that changes with a surface's place, bounced from colored walls or sky, reaches it. The probes' coefficients come from a 3D texture that `LightProbeGridData.toTexture` packs and uploads, from `bakeProbes` or from a grid baked elsewhere. Throws the errors that `scene.setEnvironment` throws for a value out of range, E1213 for something that is not a texture, and E1101 for a texture that was destroyed. |
408
- | `setFog(fog: FogOptions \| null): void` | Fog over every object, by each object's straight-line distance from the camera along a curve: exponential by default, exponential squared or linear. The fog can thin with height and glow toward the main directional light. With `volumetric`, the sun and the point and spot lights light the fog through their shadows. Null removes the fog. The background takes no fog, and a material created with `fog: false` keeps its color. Throws E1108 for an unknown curve or a value out of its range, and E1203 for a value that is not finite. The call allocates nothing, so a sketch can change the fog in every frame. |
411
+ | `setFog(fog: FogOptions \| null): void` | Fog over every object, by each object's straight-line distance from the camera along a curve: exponential by default, exponential squared or linear. The fog can thin with height and glow toward the main directional light. With `volumetric`, the sun and the point and spot lights light the fog through their shadows. Null removes the fog. The background takes the share of the fog that `background` gives, none by default, and a material created with `fog: false` keeps its color. Throws E1108 for an unknown curve or a value out of its range, and E1203 for a value that is not finite. The call allocates nothing, so a sketch can change the fog in every frame. |
409
412
  | `pick(x: number, y: number): Promise<PickHit \| null>` | Finds the object that the camera draws at a point of the canvas, or `null` where it draws nothing there. `x` and `y` are CSS pixels from the canvas's top-left corner, as `camera.screenToRay` takes them, and the point is tested at the pixel that the camera draws, not at a projected triangle: a cut-out material's holes and a surface thinner than a pixel answer as the image shows them. A hit carries `uv`, where on the surface the pixel landed in the mesh's first texture coordinates, blended across its triangle's three corners as a raycast's `uv` is, and `hasUv`, which says whether to read it. A ray from the camera of the frame that recorded the pick finds them from the same point, so the two ways of asking agree. A skinned or morphed character, and a custom material that offsets its vertices, draws a different shape than the mesh that the ray tests, so its coordinates can differ from the pose it drew. The answer arrives one or more frames later, through a promise, and a pick in every frame waits in a queue of its own. The frame that records the pick draws it, so the camera of that frame answers, and a camera that moves between the click and the frame can differ from the frame that the click saw. A scene with a source that the id target cannot hold, such as a custom material without a vertex offset, a blended surface or a sprite, answers with a raycast instead, which tests triangles and so ignores alpha masks. |
410
413
  | `raycast(origin: Vec3Like, direction: Vec3Like, options: RaycastOptions \| undefined, hit: RaycastHit): boolean` | Casts a ray from `origin` along `direction`, and writes its closest hit into `hit`. Returns true on a hit. On a miss it sets `hit.object` to null and leaves the other fields as they were. The direction needs no unit length. The ray tests the triangles of objects and instance rows on the layers of `options.layers`, as their materials draw them: front faces, or both faces for a double-sided material. Queries see the scene as the last frame's update left it, so a move, a new object or a destroy in this frame counts from the next frame, or from `onLateUpdate`. A query before the first frame, as a bake in a sketch's setup, first applies the changes queued so far and updates them, so it sees what the setup has built. Create `hit` and `options` once and pass them each time. |
411
414
  | `raycastAny(origin: Vec3Like, direction: Vec3Like, options?: RaycastOptions): boolean` | True when a ray from `origin` along `direction` hits anything on the layers of `options.layers`. It stops at the first hit it finds, so it is faster than `raycast`: use it for line-of-sight checks. |
@@ -419,7 +422,7 @@ The scene: every object, the active camera, the lights and the background.
419
422
 
420
423
  Interface `SkyBackground`.
421
424
 
422
- three.js's analytic sky as a background: `scene.setBackground({ sky: { sunPosition } })`.
425
+ The analytic sky as a background: `scene.setBackground({ sky: { sunPosition } })`.
423
426
 
424
427
  | Member | Description |
425
428
  | --- | --- |
@@ -461,11 +464,11 @@ The values of a sky layer that `scene.setSkyLayer` takes, and that a later call
461
464
 
462
465
  Interface `SkyOptions`.
463
466
 
464
- The settings of three.js's sky, with the names and defaults of its `Sky` object's uniforms. A call that leaves a setting out takes its default.
467
+ The settings of the analytic sky, the Preetham daylight model with a sun disc and drifting clouds. A call that leaves a setting out takes its default.
465
468
 
466
469
  | Member | Description |
467
470
  | --- | --- |
468
- | `sunPosition?: readonly [number, number, number]` | A point toward the sun, as three.js's `sunPosition`. Its direction places the sun. A point far below the horizon, hundreds of thousands of units down, also dims the sky, as in three.js. The default is the sun 2 degrees above the horizon toward -Z, as three.js's sky example sets it: `[0, 0.0349, -0.9994]`. |
471
+ | `sunPosition?: readonly [number, number, number]` | A point toward the sun. Its direction places the sun. A point far below the horizon, hundreds of thousands of units down, also dims the sky. The default is the sun 2 degrees above the horizon toward -Z: `[0, 0.0349, -0.9994]`. |
469
472
  | `turbidity?: number` | The haze in the air, 0 or more. The default is 2. |
470
473
  | `rayleigh?: number` | The scattering by the air's molecules, which makes the sky blue, 0 or more. The default is 1. |
471
474
  | `mieCoefficient?: number` | The scattering by haze, 0 or more. The default is 0.005. |
@@ -486,7 +489,7 @@ The settings of three.js's sky, with the names and defaults of its `Sky` object'
486
489
  function timeOfDay(time: number | TimeOfDayPreset, options: TimeOfDayOptions = {}, out: TimeOfDay = emptyTimeOfDay()): TimeOfDay
487
490
  ```
488
491
 
489
- Works out the settings of a time of day: an hour from 0 to 24, or a named preset. The sun rises at 6, stands highest at 12 and sets at 18. After sunset the sky dims to a deep blue, and then to a navy night sky lit from the moon's place, and the moon takes over as the main light. Each value comes from three.js's sky model, the one that the sky background draws, so the fog fades into the sky's horizon. Throws a `RangeError` for an hour that is not a finite number, or an unknown preset. Give it `out`, an object of a previous call, and it writes the new settings into that object: a day cycle then allocates nothing, so a sketch can move the time in every frame. `bun run bench:allocation --time-of-day` checks that. Without it the call makes a new object. `emptyTimeOfDay()` makes the first one to pass. ```ts const day = emptyTimeOfDay(); timeOfDay('goldenHour', {}, day); scene.setBackground({ sky: day.sky }, { intensity: day.skyIntensity }); scene.setEnvironment(skyLight, { intensity: day.skyIntensity }); sun.setDirection(...day.light.direction); sun.setColor(day.light.color); sun.setIntensity(day.light.intensity); scene.setFog({ color: day.fog.color, density: 0.01, sunGlow: day.fog.sunGlow }); post.set({ exposure: day.exposure }); ```
492
+ Works out the settings of a time of day: an hour from 0 to 24, or a named preset. The sun rises at 6, stands highest at 12 and sets at 18. After sunset the sky dims to a deep blue, and then to a navy night sky lit from the moon's place, and the moon takes over as the main light. Each value comes from the model of the sky that the background draws, so the fog fades into the sky's horizon. Throws a `RangeError` for an hour that is not a finite number, or an unknown preset. Give it `out`, an object of a previous call, and it writes the new settings into that object: a day cycle then allocates nothing, so a sketch can move the time in every frame. `bun run bench:allocation --time-of-day` checks that. Without it the call makes a new object. `emptyTimeOfDay()` makes the first one to pass. ```ts const day = emptyTimeOfDay(); timeOfDay('goldenHour', {}, day); scene.setBackground({ sky: day.sky }, { intensity: day.skyIntensity }); scene.setEnvironment(skyLight, { intensity: day.skyIntensity }); sun.setDirection(...day.light.direction); sun.setColor(day.light.color); sun.setIntensity(day.light.intensity); scene.setFog({ color: day.fog.color, density: 0.01, sunGlow: day.fog.sunGlow }); post.set({ exposure: day.exposure }); ```
490
493
 
491
494
  ## `TimeOfDay`
492
495
 
@@ -529,7 +532,7 @@ The options of `timeOfDay`. An option left out takes its default.
529
532
  | --- | --- |
530
533
  | `heading?: number` | The turn of the sun's path about +Y, in radians. At 0 the sun rises toward +X, stands toward -Z at noon and sets toward -X. The default is 0. |
531
534
  | `noonElevation?: number` | How high the noon sun stands above the horizon, in radians, from above 0 to π/2. The default is π/3, 60 degrees. |
532
- | `model?: 'analytic' \| 'physical'` | The sky that the light, the fog, the ambient light and the exposure match: `'analytic'`, three.js's sky of `scene.setBackground({ sky })`, or `'physical'`, the physical sky of `scene.setBackground({ atmosphere })`. The default is `'analytic'`. |
535
+ | `model?: 'analytic' \| 'physical'` | The sky that the light, the fog, the ambient light and the exposure match: `'analytic'`, the analytic sky of `scene.setBackground({ sky })`, or `'physical'`, the physical sky of `scene.setBackground({ atmosphere })`. The default is `'analytic'`. |
533
536
 
534
537
  ## `TimeOfDayPreset`
535
538
 
@@ -77,6 +77,7 @@ The engine as the sketch sees it: the canvas's size, and what the device can do.
77
77
  | `readonly viewport: SketchViewport` | The canvas's size in CSS pixels, and the pixel ratio the engine draws with. |
78
78
  | `readonly capabilities: EngineCapabilities` | The GPU path the engine chose, and what it offers: the values of `engine.capabilities` on the page. |
79
79
  | `readonly held: boolean` | True when the engine steps the sketch itself, as hold mode and a replay do, rather than running it live. A sketch that returns before its scene is complete waits for the scene when this is true, so a held frame or a replay shows the finished scene. |
80
+ | `readonly firstFrame: Promise<void>` | Resolves once the GPU has finished the engine's first frame, as `engine.firstFrame` does on the page. Start the downloads that the first frame does not need here, so they leave the network to the first frame's own files. Never await it in the setup: the first frame waits for the setup. In hold mode and a replay, it resolves once the engine has stepped the sketch to the last frame, which no later frame follows, so work that it starts never changes the frames that those modes show. It never resolves when the engine stops first. |
80
81
 
81
82
  ## `SketchOptions`
82
83
 
@@ -88,6 +89,9 @@ Options for `defineSketch`.
88
89
  | --- | --- |
89
90
  | `fixedRate?: number` | Fixed steps per second of sketch time, the rate of `onFixedUpdate`. The default is 60. |
90
91
  | `maxFixedSteps?: number` | The most fixed steps that one frame runs, after a slow frame. The default is 8. |
92
+ | `lowestTier?: boolean` | False keeps the governor out of its lowest quality tier, whose cuts reach the scene's settings. A scene whose sketch thread limits its frames gains nothing from the tier's smaller render: the cut cannot make the sketch work cheaper, and the smaller picture is a loss. The default is true, and the page's `?tier=off` switch keeps the tier out too. |
93
+ | `downloads?: readonly (string \| URL)[]` | The files that the setup loads, as addresses that resolve against the page's address, as the loading calls' do. A live start begins to download them as soon as the sketch's module has loaded, often while the engine's core still downloads. The setup's loads then take the bytes that arrived or are on their way, with no second download. List the files in the order that the setup needs them. Two download at a time, so the engine's own start files keep free connections. A load of a later file moves it to the front, and up to four listed files download while loads wait for them. Name only files that the first frame waits for, and start the others when `engine.firstFrame` resolves. A file that no load takes costs its download, and its bytes stay in memory until the engine stops. Hold mode, a replay and a recording download each file at its load, as without the list. |
94
+ | `serialLoadWarning?: boolean` | False turns off the warning of a development build for a load whose download starts only after another load's file has arrived, during the setup. Turn it off when each address comes from the contents of the file before it. The default is true. |
91
95
 
92
96
  ## `SketchPreferences`
93
97
 
@@ -0,0 +1,203 @@
1
+ ---
2
+ id: api/reference/sound
3
+ title: "Sound (@null3d/sound): API reference"
4
+ status: generated
5
+ since: "0.3"
6
+ summary: "Every export of the Sound (@null3d/sound) API, from the engine's doc comments."
7
+ ---
8
+
9
+ # Sound (@null3d/sound): API reference
10
+
11
+ > [Sound (@null3d/sound)](../sound.md) explains these exports. The engine's doc comments make this page.
12
+
13
+ ## `connectSound`
14
+
15
+ ```ts
16
+ function connectSound(engine: Engine, options: PageSoundOptions = {}): PageSound
17
+ ```
18
+
19
+ Connects the page to the sketch's sounds, which `createSound` makes in the sketch. Call it once, after `createEngine` resolves. Nothing plays until `start` runs in answer to a click, a tap or a key, or the user's first input with `startOnInput`.
20
+
21
+ ## `createSound`
22
+
23
+ ```ts
24
+ function createSound(ctx: SketchContext, options: SoundOptions): Sound
25
+ ```
26
+
27
+ Makes the sketch's sounds. Call it in the sketch's setup, and call `update` once a frame in `onLateUpdate`. The sounds play on the page once the page's half, `connectSound` from `@null3d/sound/page`, has started the audio. A sketch may make its sounds at any time; a sound made before the page connects plays once it does.
28
+
29
+ ## `NAMESPACE`
30
+
31
+ ```ts
32
+ const NAMESPACE: AddonNamespace
33
+ ```
34
+
35
+ The add-on's names, claimed once as the sketch loads: its name, its package and its error codes.
36
+
37
+ ## `PageSound`
38
+
39
+ Interface `PageSound`.
40
+
41
+ The page's half of the sound, as `connectSound` makes it.
42
+
43
+ | Member | Description |
44
+ | --- | --- |
45
+ | `readonly state: SoundState` | Where the sound stands now. |
46
+ | `readonly muted: boolean` | True while the page's sound is muted. |
47
+ | `start(): Promise<void>` | Starts the audio. Call it in the handler of a click, a tap or a key, since browsers start a page's audio only in answer to the user. Resolves once the audio runs, with the sounds' files still loading; each sound fades in as its file arrives. |
48
+ | `setMuted(muted: boolean): void` | Mutes or unmutes every sound. |
49
+ | `onState(handler: (state: SoundState) => void): () => void` | Calls `handler` each time the state changes. Returns a function that removes the handler. |
50
+ | `stop(): void` | Stops the audio for good and closes the link to the sketch. The engine's stop does the same. |
51
+
52
+ ## `PageSoundOptions`
53
+
54
+ Interface `PageSoundOptions`.
55
+
56
+ Options for `connectSound`.
57
+
58
+ | Member | Description |
59
+ | --- | --- |
60
+ | `startOnInput?: boolean` | Starts the sound on the user's first click, tap or key on the page, other than Escape. Browsers let a page start its audio only in answer to such an input. The default is false: the page calls `start` from its own control, such as a sound button. |
61
+ | `muted?: boolean` | Starts muted. The default is false. |
62
+
63
+ ## `Sound`
64
+
65
+ Interface `Sound`.
66
+
67
+ The sketch's sounds, as `createSound` makes them.
68
+
69
+ | Member | Description |
70
+ | --- | --- |
71
+ | `readonly connected: boolean` | True once the page's half has opened its link to the sketch. |
72
+ | `loop(options: SoundLoopOptions): SoundLoop` | Makes a sound that plays its file over and over. |
73
+ | `group(options: SoundGroupOptions): SoundGroup` | Makes a group of sounds that play one file, of which the loudest few sound at once. |
74
+ | `shot(options: SoundShotOptions): SoundShot` | Makes a sound that plays its file once for each call of its `play`. |
75
+ | `setVolume(volume: number): void` | Sets the volume of every sound, from 0 to 1. |
76
+ | `update(): void` | Reads the listener's place and turn and counts the frame. Call it once a frame, in `onLateUpdate`, after the camera has moved. A sketch that stops calling it fades every sound out, as a paused engine does. |
77
+ | `destroy(): void` | Stops every sound and closes the link to the page. |
78
+
79
+ ## `SoundGroup`
80
+
81
+ Interface `SoundGroup`.
82
+
83
+ Many sounds that play one file, such as the engines of the cars in a street, as `sound.group` makes it. Its arrays are views of the table, which a sketch may also write in bulk. They belong to the group until `destroy`: after it, the group's emitters may serve another sound, so a sketch drops the arrays with the group.
84
+
85
+ | Member | Description |
86
+ | --- | --- |
87
+ | `readonly count: number` | The members of the group. |
88
+ | `readonly positions: Float32Array` | Each member's place in the world, three numbers each. |
89
+ | `readonly levels: Float32Array` | Each member's level, from 0. |
90
+ | `readonly rates: Float32Array` | Each member's playback rate. |
91
+ | `readonly tones: Float32Array` | Each member's tone, from 0 to 1. |
92
+ | `setPosition(index: number, x: number, y: number, z: number): void` | Moves member `index` to a place in the world. |
93
+ | `setLevel(index: number, level: number): void` | Sets member `index`'s level. |
94
+ | `setRate(index: number, rate: number): void` | Sets member `index`'s playback rate. |
95
+ | `setTone(index: number, tone: number): void` | Sets member `index`'s tone. |
96
+ | `destroy(): void` | Stops every member, with a short fade, and frees the group's emitters and voices. |
97
+
98
+ ## `SoundGroupOptions`
99
+
100
+ Interface `SoundGroupOptions`, which extends `SoundPlacement`.
101
+
102
+ Options for `sound.group`.
103
+
104
+ | Member | Description |
105
+ | --- | --- |
106
+ | `file: string \| URL` | The audio file that every member plays, as `SoundLoopOptions.file` takes it. |
107
+ | `count: number` | The members of the group, each with its own place, level, rate and tone. |
108
+ | `voices: number` | The members that sound at once: the loudest where the listener stands. |
109
+
110
+ ## `SoundListener`
111
+
112
+ Interface `SoundListener`.
113
+
114
+ The object that hears the sounds, usually the active camera. The add-on reads its place and turn in the world once a frame. A camera looks down its own -Z axis, and so does the listener.
115
+
116
+ | Member | Description |
117
+ | --- | --- |
118
+ | `getWorldPosition(out: Vec3Like): void` | Writes the object's place in the world into `out`. |
119
+ | `getWorldQuaternion(out: QuatLike): void` | Writes the object's turn in the world, as a quaternion, into `out`. |
120
+
121
+ ## `SoundLoop`
122
+
123
+ Interface `SoundLoop`.
124
+
125
+ A sound that plays its file over and over, as `sound.loop` makes it.
126
+
127
+ | Member | Description |
128
+ | --- | --- |
129
+ | `setLevel(level: number): void` | Sets the level, from 0. A level of 0 silences the sound. |
130
+ | `setRate(rate: number): void` | Sets the playback rate, where 1 is the file's own speed and pitch. |
131
+ | `setTone(tone: number): void` | Sets the tone, from 0 (muffled) to 1 (the file's own brightness). |
132
+ | `setPosition(x: number, y: number, z: number): void` | Moves the sound to a place in the world. A bed that plays in both ears ignores its place. |
133
+ | `destroy(): void` | Stops the sound, with a short fade, and frees its emitter and its voice. Its setters then do nothing. |
134
+
135
+ ## `SoundLoopOptions`
136
+
137
+ Interface `SoundLoopOptions`, which extends `SoundPlacement`.
138
+
139
+ Options for `sound.loop`.
140
+
141
+ | Member | Description |
142
+ | --- | --- |
143
+ | `file: string \| URL` | The audio file's address. A relative address resolves against the page's address, as the engine's loaders do. `new URL('./file.mp3', import.meta.url)` names a file beside the sketch. |
144
+ | `positional?: boolean` | True for a sound that comes from a place, which `setPosition` moves. False for a bed that plays in both ears alike, such as wind or rain. The default is true. |
145
+ | `level?: number` | The first level, from 0. The default is 1. |
146
+ | `rate?: number` | The first playback rate, where 1 is the file's own speed and pitch. The default is 1. |
147
+ | `tone?: number` | The first tone, from 0 (muffled) to 1 (the file's own brightness). The default is 1. |
148
+ | `position?: readonly [number, number, number]` | The first place in the world. The default is the origin. |
149
+
150
+ ## `SoundOptions`
151
+
152
+ Interface `SoundOptions`.
153
+
154
+ Options for `createSound`.
155
+
156
+ | Member | Description |
157
+ | --- | --- |
158
+ | `listener: SoundListener` | The object that hears the sounds, usually the active camera. |
159
+ | `capacity?: number` | The emitters that the sketch's sounds hold together: one for each loop, one for each member of a group, and one for each voice of a shot. The default is 256 and the most is 4,096. |
160
+ | `volume?: number` | The volume of every sound, from 0 to 1. The default is 1. |
161
+
162
+ ## `SoundPlacement`
163
+
164
+ Interface `SoundPlacement`.
165
+
166
+ How a sound falls off with distance. A sound with neither distance keeps the level that the sketch gives it wherever the listener stands.
167
+
168
+ | Member | Description |
169
+ | --- | --- |
170
+ | `near?: number` | The distance within which the sound is at its full level. Beyond it the level falls as the distance grows: at twice this distance it is half. Leave it out for a sound whose level the sketch sets itself. |
171
+ | `far?: number` | The distance at which the sound has faded out. Leave it out for no such distance. |
172
+ | `muffle?: boolean` | Whether the sound loses its highs as it nears its far distance, as distant sounds do. The default is true for a sound with a far distance. |
173
+
174
+ ## `SoundShot`
175
+
176
+ Interface `SoundShot`.
177
+
178
+ A sound that plays its file once for each call, such as thunder or a door, as `sound.shot` makes it.
179
+
180
+ | Member | Description |
181
+ | --- | --- |
182
+ | `play(x: number, y: number, z: number, level?: number, rate?: number): void` | Plays the file once at a place in the world, at a level and a playback rate. A shot that plays in both ears ignores the place. |
183
+ | `destroy(): void` | Stops every play and frees the shot's emitters and voices. |
184
+
185
+ ## `SoundShotOptions`
186
+
187
+ Interface `SoundShotOptions`, which extends `SoundPlacement`.
188
+
189
+ Options for `sound.shot`.
190
+
191
+ | Member | Description |
192
+ | --- | --- |
193
+ | `file: string \| URL` | The audio file that each play starts, as `SoundLoopOptions.file` takes it. |
194
+ | `voices?: number` | The plays that sound at once. A play past this count stops the oldest. The default is 2. |
195
+ | `positional?: boolean` | True for a shot that comes from a place. The default is true. |
196
+
197
+ ## `SoundState`
198
+
199
+ ```ts
200
+ type SoundState = 'off' | 'starting' | 'on' | 'paused' | 'interrupted' | 'stopped';
201
+ ```
202
+
203
+ Where the page's sound stands: not started, starting, playing, paused while the engine is paused or the page is hidden, interrupted while the browser holds the audio, as an iPhone does during a call, or stopped for good. An interrupted sound resumes at the user's next input, or when the page shows again.
@@ -34,7 +34,7 @@ Many sprites: quads that face the camera, each with its own position, size, rota
34
34
  | `dropViews(): void` | Forgets the row arrays, which the next read makes again. |
35
35
  | `readonly positions: Float32Array` | Positions in the world, 3 floats per sprite. A new sprite is at the origin. |
36
36
  | `readonly sizes: Float32Array` | Width and height, 2 floats per sprite: world units, or CSS pixels without size attenuation. A new sprite is 1 by 1. A negative size mirrors the sprite. |
37
- | `readonly rotations: Float32Array` | The turn of each sprite on the screen, in radians, counterclockwise, 1 float per sprite, like three.js's `SpriteMaterial.rotation`. A new sprite has 0. |
37
+ | `readonly rotations: Float32Array` | The turn of each sprite on the screen, in radians, counterclockwise, 1 float per sprite. A new sprite has 0. |
38
38
  | `readonly colors: Float32Array` | Linear RGBA colors, 4 floats per sprite, which multiply the material's color and map. A new sprite is white. Components from 0 to 1024 draw, and alpha from 0 to 1. |
39
39
  | `readonly frames: Uint32Array` | The frame of the atlas that each sprite shows, 1 per sprite. Frame 0 is the top left. A frame past the last one counts again from the first. |
40
40
  | `setActiveCount(count: number): void` | Draws only the first `count` sprites. |
@@ -48,19 +48,19 @@ Many sprites: quads that face the camera, each with its own position, size, rota
48
48
 
49
49
  Interface `SpriteOptions`, which extends `SpriteValues`, `Omit`.
50
50
 
51
- Options of `scene.createSprites`. The look of the sprites takes the options of an unlit material, but sprites blend by default, as three.js's `SpriteMaterial` does.
51
+ Options of `scene.createSprites`. The look of the sprites takes the options of an unlit material, but sprites blend by default.
52
52
 
53
53
  | Member | Description |
54
54
  | --- | --- |
55
55
  | `count: number` | The number of sprites: the batch's capacity, which never changes. |
56
56
  | `map?: Texture` | A color map, in sRGB, whose color multiplies `color` and each sprite's color. With `atlas`, each sprite shows one frame of it. It is fixed when the batch is created. |
57
57
  | `atlas?: SpriteAtlas` | Splits `map` into a grid of frames, which each sprite picks from with its `frames` row. |
58
- | `sizeAttenuation?: boolean` | True gives sizes in world units, so far sprites look smaller, as three.js's `sizeAttenuation` does. False gives sizes in CSS pixels, so every sprite keeps its size on screen. The default is true. |
59
- | `center?: readonly [number, number]` | The point of each sprite that sits at its position, as a fraction of its width and height from its bottom left corner, like three.js's `Sprite.center`. The sprite turns about it. The default, `[0.5, 0.5]`, is the middle; `[0.5, 0]` stands a sprite on its position. |
58
+ | `sizeAttenuation?: boolean` | True gives sizes in world units, so far sprites look smaller. False gives sizes in CSS pixels, so every sprite keeps its size on screen. The default is true. |
59
+ | `center?: readonly [number, number]` | The point of each sprite that sits at its position, as a fraction of its width and height from its bottom left corner. The sprite turns about it. The default, `[0.5, 0.5]`, is the middle; `[0.5, 0]` stands a sprite on its position. |
60
60
  | `dynamic?: boolean` | Every sprite updates and uploads every frame; a static batch updates rows marked dirty only. |
61
61
  | `layers?: number` | The layers every sprite is on, as a 32-bit mask. The default, 1, is layer 0. |
62
62
  | `origin?: Vec3` | The point that every sprite's position is relative to, as an instance batch's `origin`. The default is (0, 0, 0). Sprites near it keep the precision of 32-bit floats at any distance from the world's origin. |
63
- | `alphaMode?: MaterialFeatures['alphaMode']` | How the sprites use their alpha. The default is `blend`, as three.js's sprites blend. |
63
+ | `alphaMode?: MaterialFeatures['alphaMode']` | How the sprites use their alpha. The default is `blend`. |
64
64
 
65
65
  ## `SpriteValues`
66
66
 
@@ -81,6 +81,7 @@ A ground drawn as a quadtree of blocks. `createTerrain` makes one.
81
81
  | `heightAt(x: number, z: number): number` | The height of the ground at a point, in meters, with bilinear interpolation between the samples of the height field. Allocates nothing. |
82
82
  | `normalAt(x: number, z: number, out: number[] \| Float32Array): void` | The unit normal of the ground at a point, written into `out` as x, y and z, for placing an object that stands on the ground. Allocates nothing. |
83
83
  | `update(eye: Vec3Like): void` | Picks the blocks to draw for a camera whose world position `eye` holds, as x, y and z. The ground picks again when the camera crosses a cell of the finest level, rises by one such cell, or draws through a different field of view or buffer height, so a still camera costs no work. The selection and the block build run in the add-on's WebAssembly module on the engine's job workers, so this call only asks for them. A new selection builds at most `blocksPerUpdate` blocks in one task, the first selection builds every block it needs, and the ground draws the selection it had until the new one is built. A block that the new selection needs takes the mesh of one that it left out. Call it in `onUpdate` with the camera's own position, in an array you keep: an array crosses the call as it is, where two fractions make the browser box each of them into an object. |
84
+ | `setTint(tint: readonly [number, number, number]): void` | Multiplies every layer's colour, so a scene darkens its open ground with the hour: white leaves the ground as its maps give it. It sets the material's own color, which every block shares, so a value that holds still costs nothing. |
84
85
  | `setMorph(enabled: boolean): void` | Turns the block morph on or off, from the next frame. The ground reads the selection's scale again with the last view, so a page that compares the look or measures the cost needs no new selection. |
85
86
  | `setVisible(visible: boolean): void` | Shows or hides the whole ground, for a camera high above it. |
86
87
  | `destroy(): void` | Destroys the ground: every block's object and mesh, and the material's own textures. |
@@ -122,7 +123,7 @@ What `createTerrain` needs and what the ground may change.
122
123
  | `skirt?: number` | How far the skirt around each block hangs down, in meters. The default is four of the block's cells, which closes the seam against a neighbour up to a level or two coarser. |
123
124
  | `morph?: boolean` | True moves each block toward its parent block's surface as the camera pulls away, so a block that hands over to a coarser one does not pop. The default is true. False switches each block at once and keeps the block's vertices as they are. |
124
125
  | `metalness?: number` | How much the ground acts like a metal, from 0 to 1. The default is 0. |
125
- | `castShadows?: boolean` | True makes the ground cast the sun's shadows. The default is true. |
126
+ | `castShadows?: boolean` | True makes the ground cast the shadows of the lights that cast them. The default is true. |
126
127
  | `receiveShadows?: boolean` | True makes shadows fall on the ground. The default is true. |
127
128
  | `maxBlocks?: number` | The most meshes the ground holds, from 16 up: a block that a selection leaves out gives up its mesh to the next block that needs one, so the ground stops building meshes once it holds this many. Its meshes wait for a block again until the count passes this figure. The default is 512. |
128
129
  | `blocksPerUpdate?: number` | The most new blocks that one task builds, from 1 up. A camera that crosses into a new cell may need tens of blocks, and building them all at once would stall the frame. The ground draws its last complete selection until the new one is built. The first selection builds every block that it needs, over a few tasks, since there is no ground to draw before it. The default is 16. |
@@ -122,11 +122,11 @@ How a texture stores and samples its texels. Every call that makes a texture tak
122
122
  | Member | Description |
123
123
  | --- | --- |
124
124
  | `colorSpace?: TextureColorSpace` | `srgb` for color maps, such as a base color, and `linear` for data maps, such as normal, roughness, metalness and occlusion maps. The default is `srgb` for images and `linear` for data. |
125
- | `wrap?: TextureWrap \| readonly [TextureWrap, TextureWrap]` | Along u, then v, or one value for both. The default is `clamp`, as in three.js. |
125
+ | `wrap?: TextureWrap \| readonly [TextureWrap, TextureWrap]` | Along u, then v, or one value for both. The default is `clamp`. |
126
126
  | `filter?: TextureFilter` | The filter of magnified and minified texels and between mip levels. The default is `linear`. |
127
127
  | `mipmaps?: boolean` | True to make mip levels on the GPU after each upload, so the texture does not shimmer where it covers few pixels. The default is true for images and false for data. `rgba16float` textures have no mip levels. |
128
128
  | `anisotropy?: number` | Samples along the direction of steepest change, a whole number from 1 to 16, which keeps a texture sharp on a surface seen at a slant. The quality preset caps it, and a `nearest` filter turns it off. The default is 1, which is off. |
129
- | `uvSet?: 0 \| 1` | The set of texture coordinates that materials read the texture at: 0 for the first, 1 for the second, as three.js's `texture.channel`. The default is 0. |
129
+ | `uvSet?: 0 \| 1` | The set of texture coordinates that materials read the texture at: 0 for the first, 1 for the second. The default is 0. |
130
130
 
131
131
  ## `Textures`
132
132
 
@@ -136,8 +136,8 @@ Makes textures from decoded images and from data, and reads what the GPU holds.
136
136
 
137
137
  | Member | Description |
138
138
  | --- | --- |
139
- | `fromPass(pass: RenderPass): Texture` | The texture that a render pass draws into, which materials and sprites take as a map, as three.js's render target textures are. It holds linear color, after the exposure and before the tone curve: high dynamic range color where the device draws it. The image stands upright on a plane, with v = 0 at its bottom row, as three.js's render targets do. A reflection pass's texture on the HDR WebGPU path is the one exception: its rows start at the top, so read it with `reflection_uv`. It samples as no texture until the pass first draws, and keeps the last image while the pass is switched off. `render.removePass` destroys it. Throws E1101 for a pass that was removed. |
140
- | `fromImageBitmap(image: ImageBitmap, options: TextureOptions = {}): Texture` | A texture from a decoded image. The image's first row goes to v = 0, the bottom of a plane. Decode images with `imageOrientation: 'flipY'`, as `assets.loadImageBitmap` does by default, so that they stand upright as three.js shows them. The image moves to the thread that draws, so this thread can use it no more. Throws E1208 for an image without pixels, one larger than `maxSize`, and options the engine does not know. |
139
+ | `fromPass(pass: RenderPass): Texture` | The texture that a render pass draws into, which materials and sprites take as a map. It holds linear color, after the exposure and before the tone curve: high dynamic range color where the device draws it. The image stands upright on a plane, with v = 0 at its bottom row. A reflection pass's texture on the HDR WebGPU path is the one exception: its rows start at the top, so read it with `reflection_uv`. It samples as no texture until the pass first draws, and keeps the last image while the pass is switched off. `render.removePass` destroys it. Throws E1101 for a pass that was removed. |
140
+ | `fromImageBitmap(image: ImageBitmap, options: TextureOptions = {}): Texture` | A texture from a decoded image. The image's first row goes to v = 0, the bottom of a plane. Decode images with `imageOrientation: 'flipY'`, as `assets.loadImageBitmap` does by default, so that they stand upright on a plane. The image moves to the thread that draws, so this thread can use it no more. Throws E1208 for an image without pixels, one larger than `maxSize`, and options the engine does not know. |
141
141
  | `fromCanvas(canvas: OffscreenCanvas \| HTMLCanvasElement, options: CanvasTextureOptions = {}): Texture` | A texture that follows a canvas, such as the `OffscreenCanvas` that the sketch draws a score, a map or a video frame on. The canvas's last row goes to v = 0, the bottom of a plane, so the canvas stands upright on a plane as on a page. Its texels upload as any image's do. `texture.refresh` then gives the texture the canvas's new pixels, and only those of the rectangle that changed. Throws E1208 for a canvas without a 2D context, or with no pixels. Call `getContext('2d', { willReadFrequently: true })` on the canvas, so the browser keeps its pixels where the engine reads them. |
142
142
  | `fromVideo(name: string, options: TextureOptions = {}): Texture` | A texture that follows a video on the page, which `engine.registerVideo` registered under `name`. The page sends the image of each frame that the video presents, and the texture uploads the newest one in its turn, within the frame's upload budget. A paused video presents no frames, so its texture costs nothing then. The image stands upright on a plane, with v = 0 at its bottom row, as an image that `textures.fromImageBitmap` takes, and the first frame gives the texture its size. Until a frame is on the GPU, materials draw with their colors alone. Call this once for each video, and `texture.destroy` to stop the page's frames. Throws E1208 for a name that is not a string with at least one character, or that another texture follows. |
143
143
  | `fromData(texture: TextureData): Texture` | A texture from data: four numbers per texel, in rows from the bottom up, layer after layer. A texture of several layers is a texture array of its own. Throws E1208 when the data does not fit the size and format, and for options the engine does not know. |
@@ -18,7 +18,7 @@ The page's labels, as `engine.labels` gives them.
18
18
 
19
19
  | Member | Description |
20
20
  | --- | --- |
21
- | `bind(id: string, element: HTMLElement): () => void` | Binds `element` to the label that the sketch tracks under `id` with `ui.trackLabel`. The engine then moves the element's center over the label's place on the canvas, in each frame on screen, through its CSS `transform`. It sets the element's `position` to `absolute` at the top left of its container, so put the element in a container that covers the canvas. It hides the element with `visibility: hidden` while the label's object is hidden, outside the camera's near and far planes, or not tracked. Binding another element to an id replaces the first. Returns a function that unbinds the element, which then stays where it is. A label that the sketch tracks with `transform: 'world'` or `'billboard'` is a plane of the scene: the engine moves the element into a container of its own inside the element's parent, and turns it with the scene's perspective, as three.js's `CSS3DRenderer` does. Leave the element's `transform-origin` at its center, and size the element in CSS pixels, which are the scene's units at the distance where the view is one pixel per unit. |
21
+ | `bind(id: string, element: HTMLElement): () => void` | Binds `element` to the label that the sketch tracks under `id` with `ui.trackLabel`. The engine then moves the element's center over the label's place on the canvas, in each frame on screen, through its CSS `transform`. It sets the element's `position` to `absolute` at the top left of its container, so put the element in a container that covers the canvas. It hides the element with `visibility: hidden` while the label's object is hidden, outside the camera's near and far planes, or not tracked. Binding another element to an id replaces the first. Returns a function that unbinds the element, which then stays where it is. A label that the sketch tracks with `transform: 'world'` or `'billboard'` is a plane of the scene: the engine moves the element into a container of its own inside the element's parent, and turns it with the scene's perspective. Leave the element's `transform-origin` at its center, and size the element in CSS pixels, which are the scene's units at the distance where the view is one pixel per unit. |
22
22
 
23
23
  ## `LabelOptions`
24
24
 
@@ -30,7 +30,7 @@ Options for `ui.trackLabel`.
30
30
  | --- | --- |
31
31
  | `offset?: Vec3Like` | Where the label sits relative to the object, in the object's own space, so the offset turns and scales with it. The default is the object's origin, `[0, 0, 0]`. |
32
32
  | `transform?: LabelTransform` | How the element sits in the scene. The default is `'screen'`. |
33
- | `rotation?: number` | The element's turn in its own plane, in radians, for `'billboard'`. It turns the content of the element, as three.js's `CSS3DSprite` `rotation2D` does. |
33
+ | `rotation?: number` | The element's turn in its own plane, in radians, for `'billboard'`. It turns the element's content counterclockwise, while the element keeps facing the camera. |
34
34
 
35
35
  ## `LabelTransform`
36
36
 
@@ -38,7 +38,7 @@ Options for `ui.trackLabel`.
38
38
  type LabelTransform = 'screen' | 'world' | 'billboard';
39
39
  ```
40
40
 
41
- How a label's element sits in the scene. - `'screen'` keeps the element flat on the screen at the label's place, always the same size, as three.js's `CSS2DRenderer` does. - `'world'` makes the element a plane of the scene: it turns and scales with the object, as three.js's `CSS3DObject` does. - `'billboard'` makes the element a plane of the scene that always faces the camera, as three.js's `CSS3DSprite` does.
41
+ How a label's element sits in the scene. - `'screen'` keeps the element flat on the screen at the label's place, always the same size. - `'world'` makes the element a plane of the scene: it turns and scales with the object. - `'billboard'` makes the element a plane of the scene that always faces the camera.
42
42
 
43
43
  ## `Ui`
44
44