@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
@@ -8,7 +8,7 @@ summary: "createEngine options and start errors; memory; capabilities and mode;
8
8
 
9
9
  # Page API: createEngine
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds `requestPointerLock`. The API is experimental, so it can still change between versions.
11
+ > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
12
 
13
13
  `createEngine` starts the engine on a canvas and runs a sketch. It returns an `Engine`, the page's handle on the running engine. The page keeps the HTML, and the sketch builds the scene in a worker of its own.
14
14
 
@@ -26,21 +26,22 @@ try {
26
26
  engine.onFailure((error) => console.error(error.code, error.message));
27
27
  await engine.firstFrame; // the first frame is on the screen: remove the loading screen
28
28
  } catch (error) {
29
- // The browser cannot run the engine: show the page without the scene.
29
+ // The browser cannot run the engine, or the engine stopped before its first frame: show the page
30
+ // without the scene.
30
31
  }
31
32
  ```
32
33
 
33
34
  ## The start
34
35
 
35
- `createEngine` tests what the browser offers, and picks the build and the GPU path from those tests, never from browser or GPU names. It starts the engine's threads, loads the sketch module and runs the sketch's setup. It resolves once the setup has run, and `engine.firstFrame` resolves once the GPU has finished the first frame. When the engine chose the preset itself, `createEngine` also waits for the [preset check](../concepts/quality-presets.md#the-preset-check). The check draws the first frames, so the first frame is then on the screen before `createEngine` resolves. On a repeat visit, the engine takes the check's stored result instead, and `createEngine` resolves after the setup.
36
+ `createEngine` tests what the browser offers, and picks the build and the GPU path from those tests, never from browser or GPU names. It starts the engine's threads, loads the sketch module and runs the sketch's setup. It resolves once the setup has run, and `engine.firstFrame` resolves once the GPU has finished the first frame. The engine can stop drawing before that frame. Then `engine.firstFrame` rejects with the failure that ended its frames, such as [E1404](../errors/E1404.md) when the thread that draws fails. A destroy before the first frame rejects it with [E1420](../errors/E1420.md). When the engine chose the preset itself, its [preset check](../concepts/quality-presets.md#the-preset-check) measures the first frames of play, and `engine.presetChecked` resolves once the check has ended. With the `presetCheck` option's `before-play`, the check runs before play, and `createEngine` waits for it. The first frame is then on the screen before `createEngine` resolves. On a repeat visit, the engine takes the check's stored result instead, and runs no check.
36
37
 
37
38
  `onProgress` reports each stage of the start, in this order:
38
39
 
39
40
  - `core-download`, as the engine core's file downloads, with the bytes that have arrived and the
40
41
  length that the server announced;
41
42
  - `core`, once the engine core is compiled and the GPU paths are tested;
42
- - `sketch`, after the sketch's setup, and after the preset check when one runs;
43
- - `first-frame`, once the GPU has finished the first frame.
43
+ - `sketch`, after the sketch's setup, and after the preset check when the `presetCheck` option is `before-play`;
44
+ - `first-frame`, once the GPU has finished the first frame after the setup. It does not wait for a preset check during play.
44
45
 
45
46
  The handler's second argument carries a stage's figures: `done` and `total`, in bytes, for
46
47
  `core-download`. The handler gets it only while the stage has figures. The total is 0 when the
@@ -58,7 +59,7 @@ An `AbortSignal` in `signal` cancels a start in progress. Then `createEngine` st
58
59
  | --- | --- |
59
60
  | [E1407](../errors/E1407.md) | The `hold` option or the `?hold=` switch gives a time that is not a number of seconds from 0 to 600. |
60
61
  | [E1415](../errors/E1415.md) | The sketch would run on the page's main thread, where another engine still runs its sketch. |
61
- | [E1213](../errors/E1213.md) | An option is out of its range: `preset`, `targetFps`, `maxPixelRatio`, `antialias`, the shadow options, `depthPrepass`, `maxLabels` or `maxLabels3d`. The options table gives each range. |
62
+ | [E1213](../errors/E1213.md) | An option is out of its range: `preset`, `presetCheck`, `targetFps`, `maxPixelRatio`, `antialias` or a shadow option. It can also be `depthPrepass`, `momentTransparency`, `gpuOcclusion`, `softwareOcclusion`, `morphTargets`, `cloudSteps` or `textureMemoryMiB`. It can also be `expectedObjects`, `maxLabels` or `maxLabels3d`. The options table gives each range. |
62
63
  | [E1409](../errors/E1409.md) | The `memory` option asks for a maximum that is not a whole number of MiB from 256 to 4096. |
63
64
  | [E1303](../errors/E1303.md) | The browser runs WebAssembly without SIMD. |
64
65
  | [E1306](../errors/E1306.md) | The browser runs the WebKit engine of a Safari before 18: Safari 17 or older, or any browser on iOS or iPadOS 17 or older. |
@@ -89,6 +90,7 @@ The canvas takes its size from CSS. The engine sizes the canvas's drawing buffer
89
90
  | Option | Default | What it does |
90
91
  | --- | --- | --- |
91
92
  | `preset` | `'auto'` | The quality preset, which the engine chooses for the device unless the page names one: [Quality presets](../concepts/quality-presets.md). The `?preset=` switch wins over it. |
93
+ | `presetCheck` | `'during-play'` | When the engine checks a preset that it chose: in the first frames of play, while the loading screen is gone, or `'before-play'`, with `createEngine` waiting for it. `engine.presetChecked` resolves once the check has ended: [The preset check](../concepts/quality-presets.md#the-preset-check). The `?preset-check=` switch wins over it. |
92
94
  | `targetFps` | The display's rate, at most 60 | The frame rate that the engine defends. `'display'` defends the display's full rate, such as 120 or 144 for a game. A whole number caps the target at that rate: [Quality presets](../concepts/quality-presets.md#the-target-frame-rate). The `?target-fps=` switch wins over it. Another value fails with [E1213](../errors/E1213.md). |
93
95
  | `maxPixelRatio` | The preset's cap | Caps the screen's pixel ratio that the engine draws at, in place of the preset's cap |
94
96
  | `antialias` | The preset's mode | `'msaa'`, `'fxaa'` or `'none'`, in place of the preset's anti-aliasing mode: [GPU tiers and backends](../concepts/backends.md#color-and-anti-aliasing-on-each-tier) |
@@ -97,9 +99,10 @@ The canvas takes its size from CSS. The engine sizes the canvas's drawing buffer
97
99
  | `cloudSteps` | The preset's value | The steps of each ray of the sky's volumetric cloud tier, in place of the preset's value: 0 draws the flat layer, and a number above 0 the volumetric clouds, at that many steps. WebGL2 and compatibility mode stop at Medium, so a page there reaches the tier with this option or with `quality.set`. The tier's noise and shaders load at its first use: [Quality API](quality.md#settings). Another value fails with [E1213](../errors/E1213.md). |
98
100
  | `shadowCascades`, `shadowMapSize`, `heroTileSize`, `gpuOcclusion`, `morphTargets`, `softwareOcclusion`, `textureMemoryMiB` | The preset's values | These settings, in place of the preset's values: [Quality API](quality.md#settings). Another value fails with [E1213](../errors/E1213.md). |
99
101
  | `depthPrepass` | `true` on WebGL2 and `false` on WebGPU, on every preset | `true` draws the depth of the opaque objects before they are shaded: [The depth prepass](../concepts/quality-presets.md#the-depth-prepass). The `?prepass=` switch wins over it. |
100
- | `keepTextureCopies` | `true` on phones and tablets, `false` on desktops | `true` keeps the engine's copy of each texture's texels after their upload, so a texture draws with its map again after the browser takes the GPU away. It costs about one more copy of each image in memory: [When the GPU goes away](../concepts/backends.md#when-the-gpu-goes-away). |
102
+ | `momentTransparency` | `false` on every preset | `true` blends the camera's blended surfaces in a layer that needs no sort, and draws those surfaces twice: [Moment transparency](materials.md#moment-transparency). It stays fixed while the engine runs. The `?moments=` switch wins over it. Another value fails with [E1213](../errors/E1213.md). |
103
+ | `keepTextureCopies` | `true` on phones and tablets, `false` on desktops | `true` keeps the engine's copy of each texture's texels after their upload, so a texture draws with its map again after the browser takes the GPU away. It costs about one more copy of each image in memory: [When the GPU goes away](../concepts/backends.md#when-the-gpu-goes-away). With it, the engine also gives its GPU back while the page sits in the browser's back-forward cache. |
101
104
  | `gpu` | `'auto'` | Forces a GPU path, for tests only. The `?gpu=` switch in the page's address wins over it, and also takes `compat` for WebGPU's compatibility mode. |
102
- | `powerPreference` | `'high-performance'` | Picks the GPU on a device that has two. `'low-power'` saves battery. |
105
+ | `powerPreference` | `'high-performance'` | Picks the GPU on a device that has two. `'low-power'` saves battery. The engine's start-up tests of the GPU run on the GPU that it picks. |
103
106
  | `latency` | `'pipelined'` | The latency mode, `'pipelined'` or `'low'`: [Architecture](../concepts/architecture.md#latency-modes). The `?latency=` switch wins over it, and the single-threaded build ignores it. Where no worker can draw, the engine runs pipelined. |
104
107
  | `transparent` | false | Makes a see-through canvas: [A transparent canvas](#a-transparent-canvas) |
105
108
  | `largeWorld` | false | Keeps the positions of objects exact at any distance from the origin, for scenes the size of a planet: [Large worlds and precision](../concepts/large-worlds.md#large-world-mode) |
@@ -150,14 +153,14 @@ The single-threaded build's memory is not shared. It grows as the scene needs, s
150
153
  ## What the engine reports
151
154
 
152
155
  - `engine.capabilities` gives the GPU path (`tier`), whether the engine runs threaded, and the optional features and limits of the GPU path. It also gives whether the scene draws HDR color (`hdr`), the depth mode, and the most objects and instance rows that the device draws (`maxInstances`). The `directDraws` field says whether the device draws buckets directly. A start-up measurement picks that path only on an Apple GPU in Safari, or in any browser on iPhone and iPad. The `drawPath` field says why the engine took its path, such as `not-apple-gpu-in-webkit`. The `halfPrecision` field says whether the scene shaders do their color math at half precision, which only the `?half=on` switch turns on. [GPU tiers and backends](../concepts/backends.md) explains each.
153
- - `engine.mode` gives the build, the latency mode, the thread that runs the sketch and the thread that draws. It also gives the most job workers that the engine may start, and the held time in hold mode. The job workers start as the work grows ([Architecture](../concepts/architecture.md#when-the-job-workers-start)). It gives the quality preset, what the preset check measured, the starts that crashed the tab before this one, and the memory maximum. The `keepTextureCopies` field says whether the engine keeps each texture's copy. It restores a map after a GPU loss ([When the GPU goes away](../concepts/backends.md#when-the-gpu-goes-away)). `renderFallback` says why the page draws where a worker was meant to, or is null.
156
+ - `engine.mode` gives the build, the latency mode, the thread that runs the sketch and the thread that draws. It also gives the most job workers that the engine may start, and the held time in hold mode. The job workers start as the work grows ([Architecture](../concepts/architecture.md#when-the-job-workers-start)). It gives the quality preset that runs now and what the preset check measured. It also gives the starts that crashed the tab before this one, and the memory maximum. While a check runs during play, `presetCheck` is null and the preset can still drop. `engine.presetChecked` resolves once both hold the check's choice. The `keepTextureCopies` field says whether the engine keeps each texture's copy. It restores a map after a GPU loss ([When the GPU goes away](../concepts/backends.md#when-the-gpu-goes-away)). The `renderFallback` field says why the page draws where a worker was meant to, or is null.
154
157
  - `engine.report` holds every result of the start's tests, as plain JSON.
155
158
 
156
159
  ## The running engine
157
160
 
158
161
  - `setPaused(true)` stops the sketch's frames, and `setPaused(false)` resumes them. The first step after a pause is 0 seconds.
159
162
  - `detach()` takes the canvas off the page and pauses the engine, and `attach(container)` puts it back. Use them when a single-page app leaves the view with the canvas and comes back. The engine keeps its threads, its GPU resources and the scene.
160
- - `onFailure(handler)` receives a failure after the start. It can be a GPU that the engine could not get back ([E1302](../errors/E1302.md)), or an engine thread that failed ([E1404](../errors/E1404.md)). It can be a file of a custom shader's builds that a pipeline needs and that did not download ([E1424](../errors/E1424.md)). After E1404 or E1424 the engine stops drawing new frames, and the canvas keeps the last one: destroy the engine and start a new one. It can also be a job worker that did not start ([E1405](../errors/E1405.md)). On WebGPU it can be a GPU that ran out of memory ([E1304](../errors/E1304.md)) or rejected the engine's work ([E1305](../errors/E1305.md)). The engine then draws on without the objects that failed. The first handler that attaches after a failure that no handler heard still receives it, and the engine also logs the failure to the console. The handler is the only place where these failures show: no promise rejects for them. A failure that ends the frames reaches these handlers before the `onStop` handlers.
163
+ - `onFailure(handler)` receives a failure after the start. It can be a GPU that the engine could not get back ([E1302](../errors/E1302.md)), or an engine thread that failed ([E1404](../errors/E1404.md)). It can be a file of a custom shader's builds that a pipeline needs and that did not download ([E1424](../errors/E1424.md)). After E1404 or E1424 the engine stops drawing new frames, and the canvas keeps the last one: destroy the engine and start a new one. It can also be a job worker that did not start ([E1405](../errors/E1405.md)). On WebGPU it can be a GPU that ran out of memory ([E1304](../errors/E1304.md)) or rejected the engine's work ([E1305](../errors/E1305.md)). On either GPU path it can be a pipeline of the scene's objects that the GPU's driver refused twice ([E1307](../errors/E1307.md)). After these three the engine draws on without the objects that failed. The first handler that attaches after a failure that no handler heard still receives it, and the engine also logs the failure to the console. The handler is the only place where these failures show: no promise rejects for them. A failure that ends the frames reaches these handlers before the `onStop` handlers.
161
164
  - `onStop(handler)` calls the handler once, when the engine stops drawing for good. That happens as `destroy()` begins, or at a failure after which it draws no new frames: [E1302](../errors/E1302.md), [E1404](../errors/E1404.md) or [E1424](../errors/E1424.md). At such a failure, the `onFailure` handlers hear it first. A handler added after that runs at once. A handler that throws reaches the console, and the other handlers and the stop go on. Use it to end the page's own work for the engine, such as a frame loop that sends the sketch messages. It returns a function that removes the handler.
162
165
  - `onSketchError(handler)` receives each distinct error that the sketch's frame code threw, or a core call in a frame. The engine keeps drawing frames, so such an error does not stop it. `measure()` counts each frame whose update failed in `updateErrors`, and leaves it out of `updatedFps`. Without a handler, the error reaches the console. The `onSketchError` option adds a handler from the start.
163
166
  - `simulateGpuLoss()` acts out a loss of the GPU, so you can test how the page handles one. The engine starts a new GPU device and draws the whole scene again.
@@ -165,7 +168,9 @@ The single-threaded build's memory is not shared. It grows as the scene needs, s
165
168
  - `stats(true)` shows the stats overlay over the canvas, and `stats(false)` hides it: [Stats overlay and frame figures](debug.md#stats-overlay-and-frame-figures). Options in place of `true` set whether the card starts closed, on a shown overlay too. The sketch's `debug.stats` shows and hides the same overlay, and the last call from either side wins.
166
169
  - `capture()` resolves with a PNG image of the next frame that the engine draws: [Screenshots](#screenshots).
167
170
  - `captureFrame()` returns the pixels of the next frame that the engine draws, as RGBA8 rows, top row first. The thread that draws waits for its frame loop to take a new frame, then draws that frame again offscreen and reads it back. So captures back to back give newer frames, even on a slow GPU whose readback holds that thread up. In hold mode it returns the held frame and draws nothing. On a transparent canvas the pixels keep their premultiplied alpha. Tests use it: [Testing your sketch](../guides/testing.md).
171
+ - `saveRecording()` resolves with the recording of the session so far, or `undefined` when the page records none. A page records with the `?record` switch, and `?replay=<file>` plays a saved recording: [Record a session that went wrong](../guides/testing.md#record-a-session-that-went-wrong).
168
172
  - `postToSketch` and `onSketchMessage` send and receive [messages](page.md).
173
+ - `inspect(call, args)` runs an inspection call against the live scene, for the in-page inspector and the MCP server: `objects`, `object`, `setObject`, `setMaterial`, `stats`, `errors`, `graph`, `setQuality`, `highlight` and `info`. The call runs between frames, in the thread that runs the sketch, and returns a JSON-safe value. The page answers `capture` itself, with `{ png, bytes }`: the PNG image of the next frame as base64 text, and its size in bytes. The method exists only in a development build, which carries the channel, and a production build leaves it out. Code that uses it checks for it first: `await engine.inspect?.('objects')`. [Debugging](../guides/debugging.md#the-in-page-inspector) shows the calls.
169
174
  - `labels.bind(id, element)` moves an HTML element over the label that the sketch tracks under `id`: [UI overlays and labels](ui.md).
170
175
  - `registerVideo(video, { name, maxSize, frameRate })` shows a video element on the page as a texture in the sketch, which makes it with `textures.fromVideo(name)`: [Video textures](../guides/video-textures.md). The page sends one image per frame that the video presents, scaled to `maxSize`, 512 texels by default. The call returns a function that stops the frames.
171
176
  - `requestPointerLock()` locks the pointer to the canvas, for [first-person controls](controls.md#pointer-lock) and games that turn with the mouse. Call it in a click or key handler: browsers lock the pointer only right after the user acts. It resolves once the lock begins. It fails with [E1425](../errors/E1425.md) when the browser refuses the lock: on a phone, in a frame without `allow-pointer-lock`, or just after the user pressed Esc. The option `{ unadjustedMovement: true }` asks for the mouse's raw movement, which some browsers cannot give. While the lock holds, the sketch's `input.pointer.locked` is true. The user ends the lock with Esc, and the page with `document.exitPointerLock()`. Destroying the engine ends a lock that it took or that its input read. On an engine started with `input: false`, it fails with [E1426](../errors/E1426.md): the code that records the page's input locks the canvas itself. Destroying the engine then leaves that lock.
@@ -174,12 +179,13 @@ The single-threaded build's memory is not shared. It grows as the scene needs, s
174
179
  - A new engine can start on the canvas of an engine that you destroyed. Its start waits until the old engine has stopped, so it can begin before `destroy()` resolves. React's StrictMode needs this, because it starts an effect twice on one `<canvas>`. A canvas that a worker drew on stays with that worker. So the new engine needs the same thread options as the old one. The worker ends when the canvas leaves the page or the page goes away. It also ends when the browser refuses memory for a new engine while no engine runs on the canvas. A new engine on its canvas then fails with [E1419](../errors/E1419.md), as on a canvas whose engine still runs.
175
180
  - In Safari, a stopped engine's canvas that stays in the page keeps the engine's memory, 1 GiB by default, until that worker ends. A new engine that needs the room gets it. Other code does not: a page that also loads a large WebAssembly module can run out of room. So remove the canvas from the page once you are done with it.
176
181
  - A page that goes away without `destroy()`, such as a page in a frame that your app removes, still gives back the engine's memory. When the page hides, the engine wakes its job workers and ends their loops. Safari never frees the memory of a worker that it stops while the worker waits for work. Without this, an iPad would run out of room after a few such pages. A page that the browser brings back from its back-forward cache runs on, with the job workers' share of the work on the sketch thread.
182
+ - Where the engine keeps texture copies, as phones and tablets do by default, it gives its GPU back. It does so while the browser keeps the page in its back-forward cache. The thread that draws destroys its textures, its buffers and its device. When the page shows again, it starts a new device, as after a GPU loss, and builds every pipeline again before the scene shows. The cached page then leaves its GPU memory to the next page. A repeat visit of a heavy page on a phone with little memory needs that room ([E1307](../errors/E1307.md)).
177
183
 
178
184
  Each `on...` call returns a function that removes its handler.
179
185
 
180
186
  ## Screenshots
181
187
 
182
- `engine.capture()` resolves with an image of the next frame that the engine draws, as a PNG `Blob`. It takes the place of three.js's `preserveDrawingBuffer` with `canvas.toDataURL()`. The page cannot read a frame from the canvas itself: a worker usually draws on it, and the browser clears it after each frame.
188
+ `engine.capture()` resolves with an image of the next frame that the engine draws, as a PNG `Blob`. The page cannot read a frame from the canvas itself: a worker usually draws on it, and the browser clears it after each frame.
183
189
 
184
190
  ```ts
185
191
  shotButton.onclick = async () => {
@@ -8,7 +8,7 @@ summary: "scene.addFeatureDraw turns a draw feature description into a draw of y
8
8
 
9
9
  # Add-on feature draws
10
10
 
11
- > Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. A draw records in the main view alone, and at the opaque or the transparent point.
11
+ > Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. A draw records in the main view alone, and at the opaque, the transparent or the resolve point.
12
12
 
13
13
  ```mermaid
14
14
  flowchart LR
@@ -111,7 +111,7 @@ A draw's vertex data and material draw as one scene object. The engine culls it
111
111
  - `'transparent'` draws with the blended objects, back to front. The description's band and order place it among them, as `mesh.setRenderOrder` does: `draw.setRenderOrder(order)` changes the place later.
112
112
  - `'resolve'` blends after the camera's other blended objects. While the scene has more than one sample per pixel (MSAA), the camera draws such surfaces back to front into a layer of one sample per pixel, tested against a one-sample copy of the opaque depth, and blends the layer over the scene. Thousands of overlapping blended cards, such as Gaussian splats, then cost one blend per pixel instead of one per sample. Use it for a draw of soft, heavily overlapping surfaces. A glass or a particle in front of such a draw shows behind it, and a mesh's anti-aliased edge in front of it can show a faint fringe. With one sample, other views and frames before the layer's shaders are ready, the draw blends in the transparent pass, back to front with the other blended objects.
113
113
 
114
- A draw can cast the shadows that a directional light casts with `castShadows`, and receive shadows with `receiveShadows`. `draw.object` gives the scene object for every other object call: `setPosition`, `setRotation`, `setScale`, `setVisible`, `setLayers` and `destroy`.
114
+ The draw's scene object, `draw.object`, takes the other object calls, such as `setPosition`, `setRotation`, `setScale` and `setLayers`. Its `setCastShadows(true)` makes the draw cast the shadows of every light that casts them, and its `setReceiveShadows(true)` makes the draw receive them. The draw's own `setVisible` shows and hides it. The draw's own `destroy()` frees its object, its material and its vertices, where `draw.object.destroy()` frees the object alone.
115
115
 
116
116
  ## Many copies of one shape
117
117
 
@@ -146,7 +146,7 @@ values.set([...]); // four numbers of yours for each row, read as `object.values
146
146
 
147
147
  ## Limits
148
148
 
149
- - The adapter places the main view alone. A scene pass and a reflection pass do not draw a feature draw yet, and a description that names one throws E1223.
149
+ - The adapter places the main view alone. A scene pass and a reflection pass do not draw a feature draw, and a description that names one throws E1223.
150
150
  - A draw has one shape and one material, repeated once for each row. A scene that draws a different shape for each copy, or whose copies the GPU chooses, needs another hook.
151
151
  - A compact buffer of many copies that a shader expands, as a large splat scene needs, is not this hook: [compute instances](feature-instances.md) draw a capacity of instances whose live count a compute pass writes.
152
152
  - The feature description's `reads`, `writes`, `outputs` and `provides` stay with the [feature registry](features.md): this draw reads and writes no scene resource and provides no lighting slot.
@@ -83,7 +83,7 @@ export default defineSketch(async ({ post, quality, engine, page }) => {
83
83
  | Field | What a full-screen effect takes |
84
84
  | --- | --- |
85
85
  | `kind` | `'fullscreen'`. Any other kind throws E1223. |
86
- | `frame` | `'resolve'`. No public pass draws an add-on's effect after the tone curve yet, so another frame point throws E1223. |
86
+ | `frame` | `'resolve'`. No public pass draws an add-on's effect after the tone curve, so another frame point throws E1223. |
87
87
  | `band` | `'before'`, `'normal'` or `'after'`. It places the pass among the sketch's other effects, whose orders the band's ranges keep in that order. |
88
88
  | `order` | The place inside the band. A lower number runs first. |
89
89
  | `reads` | `'sceneColor'`, and `'sceneDepth'` when the WGSL reads the depth. Another resource throws E1223. |
@@ -111,8 +111,8 @@ Add the feature to its `FeatureHost` before you place it. The host's quality cal
111
111
 
112
112
  ## Limits
113
113
 
114
- - The pass records at the resolve point and in the main view alone. An add-on's effect after the tone curve, or in a scene or reflection pass, needs a hook that the engine does not have yet.
115
- - The pass reads the scene's color and depth alone. Normals, motion vectors, history and the shadow atlas need a binding that the effect chain does not add yet.
114
+ - The pass records at the resolve point and in the main view alone. An add-on's effect cannot run after the tone curve, or in a scene or reflection pass.
115
+ - The pass reads the scene's color and depth alone. It cannot read the normals, the motion vectors, the history or the shadow atlas.
116
116
  - The pass publishes no texture and provides no lighting slot. A feature that publishes an output is a compute pass, and a lighting slot belongs to the pass that shades the surfaces.
117
117
  - The chain runs in one place in the frame, so the band orders the pass among the sketch's other effects. The engine's own bloom and depth of field keep their own places around it.
118
118
 
@@ -86,7 +86,7 @@ export default defineSketch(async ({ scene }) => {
86
86
  | Field | What an instance draw takes |
87
87
  | --- | --- |
88
88
  | `kind` | `'draw'`. Any other kind throws E1223. |
89
- | `frame` | `'opaque'`. A transparent instance draw is not placed yet. |
89
+ | `frame` | `'opaque'`. The adapter places no transparent instance draw. |
90
90
  | `views` | `['main']`. The adapter refuses another view. |
91
91
  | `band`, `order` | Read, but the opaque pass orders its own draws. |
92
92
 
@@ -140,7 +140,7 @@ On WebGL2, each row's matrix is split into a position, a rotation and a scale th
140
140
 
141
141
  ## Limits
142
142
 
143
- - The draw records at the opaque point, and its feature records in the main view alone. The engine still draws the object into the shadow views of the lights that it casts into. A transparent instance draw, and one in a reflection or a scene pass, arrives with the add-on that first needs it.
143
+ - The draw records at the opaque point, and its feature records in the main view alone. The engine still draws the object into the shadow views of the lights that it casts into. The adapter places no transparent instance draw, and none in a reflection or a scene pass.
144
144
  - The draw records only while the description's `ready` callback answers true. The sketch's thread asks it once each frame. While it answers false the engine records no draw, no count copy and no conversion for it, and draws none of its rows on WebGL2.
145
145
  - The engine does not cull the draw by the camera's frustum or layers. Your compute's cull, or your count, decides what draws. `draw.setVisible(false)` stops it, and so does a hidden parent.
146
146
  - The engine does not bound the count. Keep the add-on's count at or under `capacity`. Past it, the GPU reads past the end of the buffer.
@@ -121,7 +121,7 @@ A feature without an `order` takes the first place of its band, which is 0 for `
121
121
  | --- | --- |
122
122
  | `'sceneColor'` | The scene's color, before the tone curve. |
123
123
  | `'sceneDepth'` | The scene's depth. |
124
- | `'normals'` | The scene's surface normals. No pass makes them yet. |
124
+ | `'normals'` | The scene's surface normals. No pass makes them, so a feature that reads them gets the neutral value. |
125
125
  | `'motionVectors'` | How far each pixel's surface moved since the last frame. |
126
126
  | `'history'` | The image of an earlier frame, which a temporal effect keeps. |
127
127
  | `'shadowAtlas'` | The sun's cascades and the point and spot lights' shadow tiles. |
@@ -142,13 +142,11 @@ An output is a texture that a feature publishes to materials, effects and passes
142
142
 
143
143
  A reader shows the neutral value while the feature is absent, switched off or not ready. A missing feature then breaks nothing downstream. Output names are unique across the engine's features.
144
144
 
145
- Nothing binds a registered output to a texture yet. The compute pass publishes the texture that its description names, and a material reads it through `textures.fromPass`. The declared neutral default is checked and kept, and it becomes a bound texture when an adapter reads a registered output.
145
+ No adapter binds a registered output to a texture. The compute pass publishes the texture that its description names, and a material reads it through `textures.fromPass`. The declared neutral default is checked and kept.
146
146
 
147
147
  ## Lighting slots
148
148
 
149
- A feature can provide one or more lighting slots: `'shadow'`, `'ambient'`, `'sky'`, `'ao'`, `'reflection'` or `'fog'`. One feature provides each slot. A second provider throws, because the scene would then have two answers for one kind of light.
150
-
151
- Nothing reads a slot's provider yet. The rule keeps one owner ready for the hook that first consumes a slot.
149
+ A feature can provide one or more lighting slots: `'shadow'`, `'ambient'`, `'sky'`, `'ao'`, `'reflection'` or `'fog'`. One feature provides each slot. A second provider throws, because the scene would then have two answers for one kind of light. No part of the engine reads a slot's provider: the rule keeps one owner for each slot.
152
150
 
153
151
  ## Views
154
152
 
@@ -272,13 +270,13 @@ A feature's `memory` callback runs when the engine reads the figures, which happ
272
270
  - `reset` names why the feature must drop its history. The reasons are a new render size, a camera cut to another place, and an exposure change that makes stored values stale.
273
271
  - `destroy` frees the feature's own objects. The registry does not call it. The full-screen adapter's handle calls it when you destroy the handle, and otherwise stop the feature before you remove it.
274
272
 
275
- Not every callback has a caller yet, and the page says which do:
273
+ This table says who calls each callback:
276
274
 
277
- | Callback | Who calls it today |
275
+ | Callback | Who calls it |
278
276
  | --- | --- |
279
277
  | `quality` | `FeatureHost`, when the preset or its settings change |
280
- | `ready` | The full-screen adapter, when it places a feature and on each quality change, and `effect.refresh()` when the add-on calls it. The draw, instance, compute and sky-layer adapters do not ask it yet. |
281
- | `resize`, `reset` | Nothing yet. An add-on that keeps targets or history keeps its own size and reset state. |
278
+ | `ready` | The full-screen adapter, when it places a feature and on each quality change, and `effect.refresh()` when the add-on calls it. The instance adapter asks it once each frame. The draw, compute and sky-layer adapters do not ask it. |
279
+ | `resize`, `reset` | Nothing in the engine. An add-on that keeps targets or history keeps its own size and reset state. |
282
280
  | `destroy` | The full-screen adapter's handle, when the add-on destroys it. Otherwise the owner of the feature calls it. |
283
281
 
284
282
  ## Adapters
@@ -289,15 +287,16 @@ Adapters turn a checked description into work in the frame. Five exist:
289
287
  - **Instance draws:** [`scene.addComputeInstances(description, options)`](feature-instances.md) draws a capacity of instances from the add-on's own buffer. The count comes from the GPU on WebGPU, and from the page on WebGL2. The adapter places the main view alone, at the opaque point.
290
288
  - **Full-screen effects:** [`post.addFeatureEffect(description, options)`](feature-effects.md) runs the add-on's WGSL over the whole image, at the `'resolve'` point. The pass reads the scene's color, and its depth when the description declares it, and writes the color. The adapter draws it only while the feature is ready, and asks `ready` again when the quality changes.
291
289
  - **Compute passes:** [`render.addPass({ kind: 'compute', description, ... })`](render.md#compute-passes) runs the add-on's compute shader over a storage texture, which materials, effects and passes sample in the same frame. The adapter places the main view alone, binds no scene resource, and publishes the description's one output. A WebGL2 page runs the pass's fragment form, or the call throws.
292
- - **Sky layers:** [`scene.setSkyLayer(description, options)`](scene.md#sky-layers) draws the add-on's WGSL over the background, at the `'background'` point as a `'draw'`, with the `'sky'` slot and the three views. The engine places it itself, because the background draws it before the opaque objects. Its function reads the core sky's values (D-242).
290
+ - **Sky layers:** [`scene.setSkyLayer(description, options)`](scene.md#sky-layers) draws the add-on's WGSL over the background, at the `'background'` point as a `'draw'`, with the `'sky'` slot and the three views. The engine places it itself, because the background draws it before the opaque objects. Its function reads the core sky's values.
293
291
 
294
- The other hooks still need their own payload, and they arrive with the add-on that uses them first:
292
+ The descriptions serve these five adapters alone. Some kinds of add-on have no hook:
295
293
 
296
- | Hook | What the description does not yet give it |
294
+ | Kind of add-on | What the engine does |
297
295
  | --- | --- |
298
- | Material lobes, baked-data formats and glTF extension handlers | They are not frame features, so each needs its own hook. |
299
- | An effect after the tone curve, a pass in another view, and the normals, motion, history or shadow reads | The adapters refuse them until a hook needs each one. |
300
- | Scene inputs | A depth input behind a material needs its own declaration. |
296
+ | Material lobes and glTF extension handlers | They are not frame features. A custom material declares its own lobe ([A material's own lobe](../shaders/surface-functions.md#a-materials-own-lobe)), and `assets.registerGltfExtension` takes a handler ([Assets](assets.md#extensions-that-add-ons-read)). |
297
+ | Baked-data formats | They are not frame features, and no hook takes them. |
298
+ | An effect after the tone curve, a pass in another view, and reads of the normals, motion, history or shadows | The adapters refuse them with E1223. |
299
+ | A scene input behind a material | A custom material declares its depth input itself ([Materials](materials.md#the-scene-behind-a-surface)). |
301
300
 
302
301
  ## Checks
303
302
 
@@ -3,12 +3,12 @@ id: api/geometry
3
3
  title: Geometry
4
4
  status: experimental
5
5
  since: "0.1"
6
- summary: "Generators with three.js parameters; extra shapes in @null3d/geometry; meshes from arrays; morph targets; vertices that change; levels of detail that meshes plan on the job workers; vertex formats; large meshes."
6
+ summary: "Generators of common shapes; extra shapes in @null3d/geometry; meshes from arrays; morph targets; vertices that change; levels of detail that meshes plan on the job workers; vertex formats; large meshes."
7
7
  ---
8
8
 
9
9
  # Geometry
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds integer attributes, joints and weights, morph targets, the `@null3d/geometry` package, vertex updates and the levels of detail that meshes made in code plan. The API is experimental, so it can still change between versions. Not built yet: a call that skins a mesh you build. So joints and weights do not move its vertices yet. Coding agents must not use it.
11
+ > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. No call skins a mesh that you build, so its joints and weights do not move its vertices.
12
12
 
13
13
  ```mermaid
14
14
  flowchart LR
@@ -21,11 +21,11 @@ flowchart LR
21
21
  mesh --> objects["scene.createMesh()<br/>scene.createInstances()"]
22
22
  ```
23
23
 
24
- A mesh is the shape that objects draw. `ctx.geometry` makes meshes, and any number of objects and instance batches can share one mesh. The generators make common shapes with three.js's parameters. `geometry.fromArrays` makes a mesh from your own vertex data, as three.js's `BufferGeometry` does.
24
+ A mesh is the shape that objects draw. `ctx.geometry` makes meshes, and any number of objects and instance batches can share one mesh. The generators make common shapes from named options. `geometry.fromArrays` makes a mesh from your own vertex data.
25
25
 
26
26
  ## Generators
27
27
 
28
- Each generator takes the parameters and defaults of a three.js geometry class, as named options. It builds the same vertices in the same order as three.js, so a scene draws the same triangles in both engines.
28
+ Each generator takes named options. An option that you leave out takes its default.
29
29
 
30
30
  ```ts
31
31
  // sketch.ts
@@ -35,31 +35,31 @@ const pillar = geometry.cylinder({ radiusTop: 0.3, radiusBottom: 0.4, height: 2
35
35
  scene.createMesh({ mesh: crate, material: materials.standard({ color: '#c8a064' }) });
36
36
  ```
37
37
 
38
- | Generator | three.js class | Shape |
39
- | --- | --- | --- |
40
- | `geometry.box` | `BoxGeometry` | A box |
41
- | `geometry.sphere` | `SphereGeometry` | A sphere with its poles on the Y axis, or a part of one |
42
- | `geometry.plane` | `PlaneGeometry` | A rectangle in the XY plane that faces +Z |
43
- | `geometry.cylinder` | `CylinderGeometry` | A cylinder on the Y axis, closed at each end unless `openEnded` is true |
44
- | `geometry.cone` | `ConeGeometry` | A cone on the Y axis, with its point at the top |
45
- | `geometry.torus` | `TorusGeometry` | A tube bent into a ring around the Z axis |
46
- | `geometry.capsule` | `CapsuleGeometry` | A cylinder on the Y axis with a half sphere on each end |
47
- | `geometry.circle` | `CircleGeometry` | A disc in the XY plane that faces +Z, or a slice of one |
48
- | `geometry.ring` | `RingGeometry` | A disc with a hole, in the XY plane, that faces +Z |
38
+ | Generator | Shape |
39
+ | --- | --- |
40
+ | `geometry.box` | A box |
41
+ | `geometry.sphere` | A sphere with its poles on the Y axis, or a part of one |
42
+ | `geometry.plane` | A rectangle in the XY plane that faces +Z |
43
+ | `geometry.cylinder` | A cylinder on the Y axis, closed at each end unless `openEnded` is true |
44
+ | `geometry.cone` | A cone on the Y axis, with its point at the top |
45
+ | `geometry.torus` | A tube bent into a ring around the Z axis |
46
+ | `geometry.capsule` | A cylinder on the Y axis with a half sphere on each end |
47
+ | `geometry.circle` | A disc in the XY plane that faces +Z, or a slice of one |
48
+ | `geometry.ring` | A disc with a hole, in the XY plane, that faces +Z |
49
49
 
50
- Every shape is centered on its origin. The options have the names of the three.js constructor's arguments, and the API reference below gives each default. Angles are in radians. Segment counts round down to whole numbers. Each count has a least, which the API reference gives, and a smaller count rises to it. A sphere, for example, has at least 3 segments around it.
50
+ Every shape is centered on its origin. The API reference below gives each option and its default. Angles are in radians. Segment counts round down to whole numbers. Each count has a least, which the API reference gives, and a smaller count rises to it. A sphere, for example, has at least 3 segments around it.
51
51
 
52
- The generators give each vertex a position, a normal and texture coordinates, with the values that three.js gives them. The [geometry generators demo](https://github.com/null3d-engine/null3d/tree/main/examples/generators) draws all nine shapes.
52
+ The generators give each vertex a position, a normal and texture coordinates. The [geometry generators demo](https://github.com/null3d-engine/null3d/tree/main/examples/generators) draws all nine shapes.
53
53
 
54
54
  ## Extra shapes
55
55
 
56
- The `@null3d/geometry` package holds the rest of three.js's geometry classes. Install it beside the engine:
56
+ The `@null3d/geometry` package holds more shapes, and the curves and outlines that build them. Install it beside the engine:
57
57
 
58
58
  ```sh
59
59
  bun add @null3d/geometry
60
60
  ```
61
61
 
62
- Each function takes the parameters and defaults of a three.js class, as named options, and returns arrays for `geometry.fromArrays`. The arrays hold the same numbers as the three.js geometry's attributes: the same vertices in the same order, with the same normals and texture coordinates. The mesh that `fromArrays` makes from them plans its [levels of detail](#levels-of-detail) as any mesh made in code does, and keeps that order.
62
+ Each function takes named options, and an option that you leave out takes its default. It returns arrays for `geometry.fromArrays`. The arrays hold a position, a normal and texture coordinates for each vertex, and indices for some shapes. The mesh that `fromArrays` makes from them plans its [levels of detail](#levels-of-detail) as any mesh made in code does, and keeps its vertices in their order.
63
63
 
64
64
  ```ts
65
65
  // sketch.ts
@@ -70,23 +70,23 @@ const outline = new Shape().moveTo(0, 0).lineTo(1, 0).lineTo(0.5, 1).lineTo(0, 0
70
70
  const wedge = geometry.fromArrays(extrude({ shapes: outline, depth: 0.4, bevelEnabled: false }));
71
71
  ```
72
72
 
73
- | Function | three.js class | Shape |
74
- | --- | --- | --- |
75
- | `torusKnot` | `TorusKnotGeometry` | A tube that winds around a torus |
76
- | `tetrahedron`, `octahedron`, `icosahedron`, `dodecahedron` | `TetrahedronGeometry` and the others | A polyhedron, with `detail` that splits its faces toward a sphere |
77
- | `polyhedron` | `PolyhedronGeometry` | A polyhedron from your own corners and faces |
78
- | `lathe` | `LatheGeometry` | A profile of points turned around the Y axis, such as a vase |
79
- | `shape` | `ShapeGeometry` | A flat shape from outlines, with holes, in the XY plane |
80
- | `extrude` | `ExtrudeGeometry` | A shape pushed along +Z or along a curve, with an optional bevel |
81
- | `tube` | `TubeGeometry` | A tube along a 3D curve |
73
+ | Function | Shape |
74
+ | --- | --- |
75
+ | `torusKnot` | A tube that winds around a torus |
76
+ | `tetrahedron`, `octahedron`, `icosahedron`, `dodecahedron` | A polyhedron, with `detail` that splits its faces toward a sphere |
77
+ | `polyhedron` | A polyhedron from your own corners and faces |
78
+ | `lathe` | A profile of points turned around the Y axis, such as a vase |
79
+ | `shape` | A flat shape from outlines, with holes, in the XY plane |
80
+ | `extrude` | A shape pushed along +Z or along a curve, with an optional bevel |
81
+ | `tube` | A tube along a 3D curve |
82
82
 
83
- The package also has the classes that these shapes take, with three.js's names and methods. `Shape` and `Path` draw with `moveTo`, `lineTo`, `bezierCurveTo` and the rest. The 2D and 3D curves, such as `CatmullRomCurve3`, and `ShapeUtils` come too. Points are arrays of numbers, `[x, y]` or `[x, y, z]`, not `Vector2` or `Vector3` objects. A method that returns a point returns a new array, or fills the array that you pass last.
83
+ The package also has the classes that these shapes take. `Shape` and `Path` draw with `moveTo`, `lineTo`, `bezierCurveTo` and the rest. The 2D and 3D curves, such as `CatmullRomCurve3`, and `ShapeUtils` come too. Points are arrays of numbers, `[x, y]` or `[x, y, z]`. A method that returns a point returns a new array, or fills the array that you pass last.
84
84
 
85
- A mesh has one material. three.js's `ExtrudeGeometry` puts its caps and its sides in two groups, which can take two materials. Here they form one mesh. To give the caps a material of their own, make them as a second mesh with `shape`, at each end. The [extra shapes demo](https://github.com/null3d-engine/null3d/tree/main/examples/extra-shapes) draws a shape from each function.
85
+ A mesh has one material, and an extrusion's caps and sides form one mesh. To give the caps a material of their own, make them as a second mesh with `shape`, at each end. The [extra shapes demo](https://github.com/null3d-engine/null3d/tree/main/examples/extra-shapes) draws a shape from each function.
86
86
 
87
87
  ## Meshes from arrays
88
88
 
89
- `geometry.fromArrays` takes one array per vertex attribute, laid out as three.js's `BufferGeometry` keeps them: the values of vertex 0, then vertex 1, and so on. Typed arrays and plain arrays of numbers both work. An attribute can also come as 8-bit or 16-bit integers, as [integer attributes](#integer-attributes) shows.
89
+ `geometry.fromArrays` takes one flat array per vertex attribute: the values of vertex 0, then vertex 1, and so on. Typed arrays and plain arrays of numbers both work. An attribute can also come as 8-bit or 16-bit integers, as [integer attributes](#integer-attributes) shows.
90
90
 
91
91
  ```ts
92
92
  // sketch.ts: a quad that faces +z, with texture coordinates
@@ -99,23 +99,23 @@ const quad = geometry.fromArrays({
99
99
  scene.createMesh({ mesh: quad, material: materials.unlit({ color: '#ffffff' }) });
100
100
  ```
101
101
 
102
- | Array | Numbers per vertex | three.js attribute |
103
- | --- | --- | --- |
104
- | `positions` | 3 | `position` |
105
- | `normals` | 3 | `normal` |
106
- | `uvs` | 2 | `uv` |
107
- | `uvs1` | 2, such as a light map's coordinates | `uv1` |
108
- | `colors` | 3, or 4 with alpha, as linear values from 0 to 1 | `color` |
109
- | `tangents` | 4: the direction in which u grows, then 1 or -1 for the direction of v | `tangent` |
110
- | `joints` | 4 joint indices, for skinned meshes | `skinIndex` |
111
- | `weights` | 4: how much each joint moves the vertex, which add up to 1 | `skinWeight` |
112
- | `targets` | 4: the position that the vertex takes at a coarser level of detail, and that level's error, which a generated shape's material reads | None |
102
+ | Array | Numbers per vertex |
103
+ | --- | --- |
104
+ | `positions` | 3 |
105
+ | `normals` | 3 |
106
+ | `uvs` | 2 |
107
+ | `uvs1` | 2, such as a light map's coordinates |
108
+ | `colors` | 3, or 4 with alpha, as linear values from 0 to 1 |
109
+ | `tangents` | 4: the direction in which u grows, then 1 or -1 for the direction of v |
110
+ | `joints` | 4 joint indices, for skinned meshes |
111
+ | `weights` | 4: how much each joint moves the vertex, which add up to 1 |
112
+ | `targets` | 4: the position that the vertex takes at a coarser level of detail, and that level's error, which a generated shape's material reads |
113
113
 
114
114
  The arrays follow these rules:
115
115
 
116
116
  - `positions` is required. Give `normals`, or set `computeNormals: true`.
117
117
  - `indices` takes a `Uint16Array`, a `Uint32Array` or an array of numbers, with three indices per triangle. Without indices, each three vertices in a row make one triangle.
118
- - `joints` and `weights` come together. A mesh keeps them for [skinning](animation.md#skinned-meshes). No call skins a mesh that you build yet, so it draws in the pose that its positions give.
118
+ - `joints` and `weights` come together. A mesh keeps them for [skinning](animation.md#skinned-meshes). A mesh that you build draws in the pose that its positions give.
119
119
  - `targets` takes floats only, and a mesh takes it or `morphTargets`, never both: the two share one vertex record.
120
120
  - A triangle's front face has its vertices in counter-clockwise order.
121
121
  - Each array's length must fit the vertex count, and its type must be one that its attribute takes. Each index must name a vertex, and each value must be a finite number. Otherwise the call throws [E1206](../errors/E1206.md).
@@ -125,7 +125,7 @@ The arrays follow these rules:
125
125
 
126
126
  Each attribute can come as 8-bit or 16-bit integers instead of 32-bit floats, as glTF's `KHR_mesh_quantization` extension allows. The mesh keeps the integers on the GPU, so it takes less memory and uploads faster. A position of 16-bit integers takes 8 bytes, where floats take 12. A normal of 8-bit integers takes 4 bytes, where floats take 12.
127
127
 
128
- Integers read in one of two ways. Normalized integers read as fractions: from 0 to 1 when they are unsigned, and from -1 to 1 when they are signed. Plain integers read as whole numbers. Give an attribute as `{ array, normalized }` to choose, as three.js's `BufferAttribute` does. The default is plain, as in three.js and glTF.
128
+ Integers read in one of two ways. Normalized integers read as fractions: from 0 to 1 when they are unsigned, and from -1 to 1 when they are signed. Plain integers read as whole numbers. Give an attribute as `{ array, normalized }` to choose. The default is plain, as in glTF.
129
129
 
130
130
  | Array | Takes | Integers read as |
131
131
  | --- | --- | --- |
@@ -152,13 +152,13 @@ Integer positions keep their own units. Give the object the scale and the positi
152
152
 
153
153
  ## Computing normals and tangents
154
154
 
155
- `computeNormals: true` computes the normals as three.js's `computeVertexNormals` does. Each vertex gets the average of the normals of its triangles, weighted by their areas. Vertices that triangles share get smooth normals. For hard edges, give each face its own vertices. The [meshes from arrays demo](https://github.com/null3d-engine/null3d/tree/main/examples/mesh-arrays) shows both: a smooth height field, an island with a color at each vertex, and a crystal with hard edges.
155
+ `computeNormals: true` computes the normals from the triangles. Each vertex gets the average of the normals of its triangles, weighted by their areas. Vertices that triangles share get smooth normals. For hard edges, give each face its own vertices. The [meshes from arrays demo](https://github.com/null3d-engine/null3d/tree/main/examples/mesh-arrays) shows both: a smooth height field, an island with a color at each vertex, and a crystal with hard edges.
156
156
 
157
- `computeTangents: true` computes tangents as three.js's `computeTangents` does, from the positions, the normals and `uvs`. It needs `uvs`, and it works with or without indices. The job workers share the work, so a large mesh takes less time. Both options give the same numbers as three.js, bit for bit. They compute from integer positions, normals and texture coordinates too, as shaders read them, and give 32-bit floats.
157
+ `computeTangents: true` computes tangents from the positions, the normals and `uvs`, with Eric Lengyel's method. It needs `uvs`, and it works with or without indices. The job workers share the work, so a large mesh takes less time. Both options compute from integer positions, normals and texture coordinates too, as shaders read them, and give 32-bit floats.
158
158
 
159
159
  ## Morph targets
160
160
 
161
- A morph target is another shape of a mesh, such as a smile on a face. The `morphTargets` option gives a mesh its targets, as three.js's `morphAttributes` with `morphTargetsRelative` does. Each target is an array of three numbers per vertex: how far the target moves the vertex at weight 1. The list `positions` moves the vertices, `normals` turns their normals, and `tangents` turns their tangents. The list `colors` changes the mesh's vertex colors, with as many numbers per vertex as `colors` has, three or four. Every list holds the same number of targets, from 1 to 256. The list `names` names the targets.
161
+ A morph target is another shape of a mesh, such as a smile on a face. The `morphTargets` option gives a mesh its targets, as glTF stores them. Each target is an array of three numbers per vertex: how far the target moves the vertex at weight 1. The list `positions` moves the vertices, `normals` turns their normals, and `tangents` turns their tangents. The list `colors` changes the mesh's vertex colors, with as many numbers per vertex as `colors` has, three or four. Every list holds the same number of targets, from 1 to 256. The list `names` names the targets.
162
162
 
163
163
  ```ts
164
164
  const count = positions.length / 3;
@@ -175,11 +175,11 @@ const head = scene.createMesh({ mesh: face, material });
175
175
  head.setMorphWeight('Smile', 0.8);
176
176
  ```
177
177
 
178
- Each object of the mesh has weights of its own, which start at 0. `setMorphWeight` sets them, and clips from glTF files animate them ([Morph targets](animation.md#morph-targets)). The [morph targets demo](https://github.com/null3d-engine/null3d/tree/main/examples/morph-flowers) makes tulips with one target, which opens the petals, turns their normals and changes their color. Each tulip has a weight of its own. The engine stores, for each vertex, only the targets that move it. So a face whose targets each move a small part of it takes far less memory than three.js's copy of every vertex for every target. A vertex can take up to 255 targets. The targets of every mesh together can take up to 4,194,304 deltas, 32 MiB of GPU memory. Each of a vertex's positions, normals, tangents and colors counts once. Past those limits, `fromArrays` throws E1206. The GPU keeps each delta in a 16-bit float, which is exact to 1/2048 of the delta's size, and each weight in a 32-bit float. A morphed color stays between 0 and 1, as the glTF specification asks. three.js does not clamp it, so a color that the weights push past 1 or below 0 draws brighter or darker there.
178
+ Each object of the mesh has weights of its own, which start at 0. `setMorphWeight` sets them, and clips from glTF files animate them ([Morph targets](animation.md#morph-targets)). The [morph targets demo](https://github.com/null3d-engine/null3d/tree/main/examples/morph-flowers) makes tulips with one target, which opens the petals, turns their normals and changes their color. Each tulip has a weight of its own. The engine stores, for each vertex, only the targets that move it. So a face whose targets each move a small part of it takes far less memory than a copy of every vertex for every target. A vertex can take up to 255 targets. The targets of every mesh together can take up to 4,194,304 deltas, 32 MiB of GPU memory. Each of a vertex's positions, normals, tangents and colors counts once. Past those limits, `fromArrays` throws E1206. The GPU keeps each delta in a 16-bit float, which is exact to 1/2048 of the delta's size, and each weight in a 32-bit float. A morphed color stays between 0 and 1, as the glTF specification asks.
179
179
 
180
180
  ## Vertices that change
181
181
 
182
- `mesh.updateVertices(name, values, start, count)` writes new values into one attribute of a mesh, as three.js's `attribute.needsUpdate = true` does. Keep the arrays that you made the mesh with, change them, and pass them again:
182
+ `mesh.updateVertices(name, values, start, count)` writes new values into one attribute of a mesh. Keep the arrays that you made the mesh with, change them, and pass them again:
183
183
 
184
184
  ```ts
185
185
  // sketch.ts: a sheet whose middle rows rise and fall
@@ -198,14 +198,14 @@ The call follows these rules:
198
198
 
199
199
  - `name` is `positions`, `normals`, `uvs`, `uvs1`, `colors` or `tangents`, and the mesh must have that attribute. Colors take three or four numbers per vertex. Three keep each vertex's alpha.
200
200
  - `values` holds the values of every vertex, in the array type that the mesh was made with. That is a `Float32Array` or a plain array for floats, or the same integer array.
201
- - `start` and `count` pick the vertices that change, as three.js's `addUpdateRange` does. By default every vertex changes. The next frame uploads only the bytes of those vertices.
201
+ - `start` and `count` pick the vertices that change. By default every vertex changes. The next frame uploads only the bytes of those vertices.
202
202
  - Values that do not fit the mesh throw [E1206](../errors/E1206.md), and so does a mesh with joints or morph targets.
203
203
  - The first call takes away the levels of detail that the mesh planned, which measured the old shape, and the mesh plans no levels on its own again. Give a mesh whose vertices change in every frame `levels: false`, so it plans none.
204
204
  - The call allocates nothing, so a call in every frame makes no garbage. `bun run bench:allocation --calls` checks it.
205
205
 
206
206
  Change the normals with the positions when the shape changes, because the engine does not compute them again. The [vertex updates demo](https://github.com/null3d-engine/null3d/tree/main/examples/vertex-updates) moves rings over a pool of water this way.
207
207
 
208
- The mesh keeps the bounding sphere of the vertices that it was made with, as three.js keeps a geometry's `boundingSphere` until you compute it again. Culling tests that sphere. When the new vertices reach outside it, give each object that draws the mesh bounds that hold every shape, with [`setBounds`](objects.md#mesh-calls). Raycasts and overlap queries always test the new vertices. The first query after an update builds the mesh's tree again. So a scene that updates a large mesh and raycasts in each frame pays for a build in each frame. Shadows of point and spot lights draw again when a mesh that casts them changes.
208
+ The mesh keeps the bounding sphere of the vertices that it was made with. Culling tests that sphere. When the new vertices reach outside it, give each object that draws the mesh bounds that hold every shape, with [`setBounds`](objects.md#mesh-calls). Raycasts and overlap queries always test the new vertices. The first query after an update builds the mesh's tree again. So a scene that updates a large mesh and raycasts in each frame pays for a build in each frame. Shadows of point and spot lights draw again when a mesh that casts them changes.
209
209
 
210
210
  The first update of a mesh rebuilds the draw tables once, as `setMesh` does, so make it at setup or behind a loading screen. Later updates cost only the copy and the upload. On WebGL2, a mesh whose positions changed no longer hides the objects behind it from software occlusion culling. For many objects that move as wholes, use [instance batches](../concepts/instances.md) instead: they move each object with one matrix, not each vertex.
211
211
 
@@ -278,6 +278,11 @@ An `error` level draws while it covers fewer pixels than the `lodThreshold` qual
278
278
 
279
279
  Each level must have the mesh's vertex attributes, as it draws with the same pipelines. A level may name a `material` of its own, so a far level shades more cheaply. A level without one draws with the material of the level before it. The base level draws with the object's or the instance batch's material. An empty list takes the levels away, and destroying a level's mesh takes every level away. `mesh.levels` lists them as you gave them. A mesh whose bound covers fewer pixels than the threshold draws nothing: its last level holds no geometry. Wrong levels throw [E1221](../errors/E1221.md). [Levels of detail](../concepts/lod.md) explains the three measures, the hide distance, the fading bands and the shadows. It also explains how glTF files from the asset tool bring their levels.
280
280
 
281
+ A far object that draws as a card follows its own rules. A card that lights unlike its mesh reads as
282
+ another tree. [Impostors](impostors.md#make-a-card-read-as-its-mesh) says which mesh to bake, the
283
+ color space, the views and texels, the normal bake, and the matched-crop check before a card is
284
+ accepted.
285
+
281
286
  ## Destroying a mesh
282
287
 
283
288
  `mesh.destroy()` frees a mesh that the scene no longer draws. Destroy the objects and instance batches that use it first. They can go in the same frame, just before the mesh:
@@ -297,30 +302,6 @@ While an object or an instance batch still uses the mesh, `destroy` throws [E111
297
302
 
298
303
  A mesh can have any number of vertices. The engine uses 16-bit indices. WebGL2 always reads the largest one, 65,535, as the end of a primitive, so one draw reaches 65,535 vertices. A mesh with more vertices splits into parts that draw one after another. Each part holds a copy of the vertices that it shares with the part before it. For the fewest draw calls, keep meshes under 65,535 vertices. A mesh that draws a cluster tree is the exception. Its patches draw in one draw across all its parts, as [cluster levels](../concepts/lod.md#cluster-levels) describes.
299
304
 
300
- ## From three.js
301
-
302
- | three.js | null3D |
303
- | --- | --- |
304
- | `new BoxGeometry(1, 2, 3)`, and the other eight classes above | `geometry.box({ width: 1, height: 2, depth: 3 })`: the arguments become named options |
305
- | `rotateX`, `translate` or `scale` on a generated shape, such as a plane laid flat | Turn, move or scale the object instead: `floor.setRotationEuler(-Math.PI / 2, 0, 0)` |
306
- | `new BufferGeometry()` with `setAttribute` and `setIndex` | `geometry.fromArrays({ positions, normals, uvs, indices })` |
307
- | `new BufferAttribute(new Int16Array(values), 3, true)` | `{ array: new Int16Array(values), normalized: true }` |
308
- | `geometry.computeVertexNormals()` | `computeNormals: true` |
309
- | `geometry.computeTangents()` | `computeTangents: true` |
310
- | `geometry.computeBoundingSphere()` | Nothing: the engine computes bounds itself |
311
- | `geometry.morphAttributes.position = [...]` with `morphTargetsRelative = true` | `morphTargets: { positions: [...] }` |
312
- | `geometry.morphAttributes.color = [...]` | `morphTargets: { colors: [...] }`, with `colors` on the mesh |
313
- | `mesh.morphTargetDictionary` | The mesh geometry's `morphTargetNames`, a list in target order; `setMorphWeight` takes a name too |
314
- | `geometry.dispose()` | `mesh.destroy()`, once no object or batch uses the mesh |
315
- | `lod.addLevel(object, distance)` | `mesh.setLevels([{ mesh, distance }])` on the base mesh ([Levels of detail](../concepts/lod.md#from-threejs)) |
316
- | `SimplifyModifier.modify(geometry, count)` from three/addons, for a far copy | Nothing: a mesh of 4,096 triangles or more plans its levels on the job workers when it first draws. `mesh.buildLevels()` plans a smaller one |
317
- | `new TorusKnotGeometry(1, 0.4)`, and `Icosahedron`, `Lathe`, `Shape`, `Extrude`, `Tube` and the other geometry classes | `geometry.fromArrays(torusKnot({ radius: 1, tube: 0.4 }))`, with the functions of `@null3d/geometry` |
318
- | `new THREE.Shape()`, `new THREE.CatmullRomCurve3(points)` | The same classes from `@null3d/geometry`, with points as arrays: `new CatmullRomCurve3([[0, 0, 0], [1, 1, 0]])` |
319
- | `attribute.needsUpdate = true`, `setUsage(DynamicDrawUsage)` | `mesh.updateVertices('positions', positions)`. There is no usage hint |
320
- | `attribute.addUpdateRange(start, count)` | `mesh.updateVertices(name, values, startVertex, vertexCount)`, in vertices rather than numbers |
321
-
322
- [three.js to null3D](../porting/threejs-mapping.md) lists every mapping.
323
-
324
305
  ## API reference
325
306
 
326
307
  [The API reference](reference/geometry.md) lists every export of this page with its type and description. The engine's doc comments make it.
package/docs/api/grass.md CHANGED
@@ -66,7 +66,7 @@ export default defineSketch(async (ctx) => {
66
66
 
67
67
  ## Grass on the ground
68
68
 
69
- `await createGrass(ctx, { height, area, count, seed, mask, wind })` draws tufts of bent blades over a square of ground. The tufts stand on `height(x, z)` and skip ground steeper than `maxSlope`. They also skip the ground that `mask` refuses, such as water, a stone or a footprint. Their turn and size come from integer hashes, so one seed places the same grass on every device. Each tuft's tint comes from a hash of its root's place in the shader. `count` is the tufts at the High preset. Low, Medium and Ultra draw 0.35, 0.6 and 1.25 of it. `createGrass` fits the engine's starting preset, and `grass.fit(preset)` takes a new one. Await the call in the sketch's setup, because WebGPU makes its draw then.
69
+ `await createGrass(ctx, { height, area, count, seed, mask, wind })` draws tufts of bent blades over a square of ground. The tufts stand on `height(x, z)` and skip ground steeper than `maxSlope`. They also skip the ground that `mask` refuses, such as water, a stone or a footprint. The `where` option refuses ground in the same way, such as a road or a wall, and a tuft grows only where both allow it. Their turn and size come from integer hashes, so one seed places the same grass on every device. Each tuft's tint comes from a hash of its root's place in the shader. `count` is the tufts at the High preset. Low, Medium and Ultra draw 0.35, 0.6 and 1.25 of it. `createGrass` fits the engine's starting preset, and `grass.fit(preset)` takes a new one. Await the call in the sketch's setup, because WebGPU makes its draw then.
70
70
 
71
71
  The blades bend in the wind add-on's field. Give `createGrass` its `wind` field, and call `grass.setWindLayer(field)` in each frame with the field's newest state. A page that gives no field grows grass that stands still.
72
72