@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
@@ -2,8 +2,9 @@ import type { StatsOverlayOptions, StatsRequest } from '../debug/stats-options.j
2
2
  import { EngineError } from '../errors/engine-error.js';
3
3
  import { type ShaderFeature } from '../generated/shader-features.js';
4
4
  import type { DrawPathReason } from '../gpu/webgpu/draw-path-probe.js';
5
- import { type PresetCheck, type TargetFps } from '../quality/check.js';
5
+ import { type PresetCheck, type PresetCheckTiming, type TargetFps } from '../quality/check.js';
6
6
  import { type QualityPreset } from '../quality/presets.js';
7
+ import type { GpuErrorKind } from '../render/loss.js';
7
8
  import type { Tier } from '../render/renderer.js';
8
9
  import type { ReplayResult } from '../shared/recording.js';
9
10
  import type { QualityUpdate } from '../sketch/quality.js';
@@ -48,6 +49,18 @@ export interface EngineOptions {
48
49
  * E1213.
49
50
  */
50
51
  targetFps?: TargetFps;
52
+ /**
53
+ * When the preset check measures, on a start where the engine checks the preset that it chose.
54
+ * With `during-play`, the default, the scene shows at its first frame: `createEngine` resolves
55
+ * once the setup has run, and `engine.firstFrame` once the GPU has finished the first frame. The
56
+ * check then measures the first frames of play, a lighter preset applies in front of the viewer,
57
+ * and `engine.presetChecked` resolves once the check has ended. With `before-play`, the check
58
+ * measures the scene that the setup built before the sketch's update runs, and `createEngine`
59
+ * resolves after it, so a loading screen hides the check and any change of preset. A start that
60
+ * takes the stored result of an earlier check, or that runs no check, plays at once either way.
61
+ * Another value fails with E1213. The `?preset-check=` switch wins over it.
62
+ */
63
+ presetCheck?: PresetCheckTiming;
51
64
  /**
52
65
  * Cap for the device pixel ratio, a number from 0.5 up. Without it, the quality preset sets the
53
66
  * cap. `ctx.quality.set` changes it during play.
@@ -112,8 +125,8 @@ export interface EngineOptions {
112
125
  * shaded once, for its nearest surface. It saves GPU time in scenes where objects hide many
113
126
  * others and shading costs much, and costs a second pass over the objects' vertices. Without
114
127
  * it, the quality preset decides: every preset draws the prepass on WebGL2, and none on WebGPU.
115
- * The prepass stays fixed while the engine runs, and the `?prepass=on` or `?prepass=off`
116
- * switch wins over this option. Another value fails with E1213.
128
+ * A sketch can change it during play with `quality.set`, and the `?prepass=on` or
129
+ * `?prepass=off` switch wins over this option. Another value fails with E1213.
117
130
  */
118
131
  depthPrepass?: boolean;
119
132
  /**
@@ -175,7 +188,8 @@ export interface EngineOptions {
175
188
  * one more copy of each image in memory. False frees each copy once no frame reads it, and such
176
189
  * a texture draws with its color alone until the sketch gives it texels again. Without this
177
190
  * option, a phone and a tablet keep copies and a desktop does not, because a phone or a tablet
178
- * is likeliest to lose its GPU.
191
+ * is likeliest to lose its GPU. With copies, the engine also gives its GPU back while the browser
192
+ * keeps the page in its back/forward cache, and starts a new device when the page shows again.
179
193
  */
180
194
  keepTextureCopies?: boolean;
181
195
  /**
@@ -248,7 +262,9 @@ export interface EngineOptions {
248
262
  * Called as the start reaches each stage, in this order: `core-download` as the engine core's
249
263
  * file downloads, with the bytes that have arrived; `core` once the engine core is compiled and
250
264
  * the GPU paths are tested; `sketch` once the sketch's setup has run; and `first-frame` once the
251
- * GPU has finished the first frame. Before `core`, `core-download` reports the core file's bytes,
265
+ * GPU has finished the first frame after the setup. The preset check does not hold up either
266
+ * stage, unless the `presetCheck` option is `before-play`: `sketch` then comes after the check
267
+ * too. Before `core`, `core-download` reports the core file's bytes,
252
268
  * and `memory-wait` comes when the browser has refused the engine's memory for 10 seconds. The
253
269
  * engine then tries for about 35 seconds more before it fails with E1109. `progress` gives a
254
270
  * stage's figures while it has some: the bytes of a download, measured against the length that
@@ -323,8 +339,8 @@ export interface EngineOptions {
323
339
  * lets light through to its other side,
324
340
  * `'subsurface'` with the first material with a `subsurfaceRadius` while the subsurface blur has
325
341
  * taps, `'coat_sheen'` with the first material with a clear coat or a sheen, `'weighted'` with
326
- * the first material of the `weighted` blending, and `'occlusion'` with the first opaque object that
327
- * may hide others while GPU occlusion culling runs on WebGPU. WebGPU morphs in the skinning pass, so there
342
+ * the first material of the `weighted` blending, and `'occlusion'` with the first opaque
343
+ * material while GPU occlusion culling runs on WebGPU. WebGPU morphs in the skinning pass, so there
328
344
  * `'morph'` loads the skinning shaders, and WebGL2 has no `'occlusion'` shaders to load. Listed
329
345
  * features download beside the engine's own
330
346
  * shaders, so the start waits only for the largest. The shaders that two or more listed features
@@ -460,16 +476,20 @@ export interface EngineMode {
460
476
  /** The sketch time in seconds that hold mode holds the sketch at, or null for a live engine. */
461
477
  hold: number | null;
462
478
  /**
463
- * The quality preset that the engine runs. The preset check can lower it before `createEngine`
464
- * resolves, and `ctx.quality.setPreset` in the sketch changes it later.
479
+ * The quality preset that the engine runs now. The preset check can lower it while it runs:
480
+ * during the first frames of play, or before `createEngine` resolves with the `presetCheck`
481
+ * option's `before-play`. `ctx.quality.setPreset` in the sketch changes it later. Once
482
+ * `engine.presetChecked` has resolved, it holds the preset that the check chose.
465
483
  */
466
484
  preset: QualityPreset;
467
485
  /**
468
- * What the preset check measured, or null when no check ran. The engine checks the preset when
469
- * it chose it from the device: after the first frame, it measures the frame rate of the scene
470
- * that the setup built, and lowers the preset until one holds the target. A later start of the
471
- * sketch in the same browser on the same device takes the stored result instead, and starts at
472
- * its preset. `reused` is then true.
486
+ * What the preset check measured, or null while the check runs, and when no check ran or the
487
+ * sketch chose its own preset first. The engine checks the preset when it chose it from the
488
+ * device: after the first frame, it measures the frame rate of the scene, and lowers the preset
489
+ * until one holds the target. A later start of the sketch in the same browser on the same
490
+ * device takes the stored result instead, and starts at its preset. `reused` is then true. A
491
+ * start after a check that never ended starts at the preset that the check had lowered to, and
492
+ * its own check goes on from there, with the earlier rounds first.
473
493
  */
474
494
  presetCheck: PresetCheck | null;
475
495
  /**
@@ -519,10 +539,21 @@ export interface Engine {
519
539
  /** How the engine runs on this device. */
520
540
  readonly mode: EngineMode;
521
541
  /**
522
- * Resolves once the GPU has finished the first frame, so it is on screen: the moment to remove
523
- * a loading screen. It never resolves when the engine is destroyed first.
542
+ * Resolves once the GPU has finished the first frame after the setup, so it is on screen: the
543
+ * moment to remove a loading screen. It rejects when the engine stops drawing first, with the
544
+ * failure that ended its frames, such as E1404 when the thread that draws fails at its first
545
+ * frame. A destroy before the first frame rejects it with E1420. A page that never waits for it
546
+ * gets no unhandled rejection.
524
547
  */
525
548
  readonly firstFrame: Promise<void>;
549
+ /**
550
+ * Resolves once the preset check has ended, so `mode.preset` holds the preset that the check
551
+ * chose and `mode.presetCheck` what it measured. It has resolved when `createEngine` resolves
552
+ * where no check runs: for a preset that the page names, a stored result, Low, and hold mode,
553
+ * and with the `presetCheck` option's `before-play`. When the engine stops drawing first, it
554
+ * resolves then, and `mode.presetCheck` stays null.
555
+ */
556
+ readonly presetChecked: Promise<void>;
526
557
  /** The HTML elements that follow the labels the sketch tracks with `ui.trackLabel`. */
527
558
  readonly labels: EngineLabels;
528
559
  /**
@@ -549,11 +580,12 @@ export interface Engine {
549
580
  * not carry on with a new device (E1302), or an engine thread failed (E1404). A custom shader's
550
581
  * builds that a pipeline needs and that did not download fail the thread that draws with E1424.
551
582
  * After E1404 or E1424 the engine draws no new frames: destroy it and start a new one. On WebGPU,
552
- * the GPU can also run out of memory (E1304) or reject the engine's work (E1305), and the engine
553
- * draws on without the objects that failed. The engine reports each failure once. A failure that
554
- * no handler listened for when the engine reported it reaches the first handler that listens, so
555
- * a failure that the app could not hear yet still arrives, and the engine also logs it to the
556
- * console. A failure that ends the frames reaches these handlers before `onStop`'s. Returns a
583
+ * the GPU can also run out of memory (E1304) or reject the engine's work (E1305). On either GPU
584
+ * path, its driver can refuse to build a pipeline that draws objects of the scene twice (E1307).
585
+ * After these three the engine draws on without the objects that failed. The engine reports each
586
+ * failure once. A failure that no handler listened for when the engine reported it reaches the
587
+ * first handler that listens, so a failure that the app could not hear yet still arrives, and the
588
+ * engine also logs it to the console. A failure that ends the frames reaches these handlers before `onStop`'s. Returns a
557
589
  * function that removes the handler.
558
590
  */
559
591
  onFailure(handler: (error: EngineError) => void): () => void;
@@ -597,6 +629,16 @@ export interface Engine {
597
629
  * whose interval broke that many milliseconds, each with the frame's own GPU parts.
598
630
  */
599
631
  measure(seconds: number, options?: MeasureOptions): Promise<FrameMetrics>;
632
+ /**
633
+ * Runs an inspection call against the live scene, for the in-page inspector and the MCP server:
634
+ * `objects`, `object`, `setObject`, `setMaterial`, `stats`, `errors`, `graph`, `setQuality`,
635
+ * `highlight` and `info`, with the arguments that [Debugging](../../guides/debugging.md#the-in-page-inspector)
636
+ * lists. The call runs between frames, in the thread that runs the sketch, and its value is
637
+ * JSON-safe. The page answers `capture` itself, with `{ png, bytes }`: the PNG image of the next
638
+ * frame as base64 text, and its size in bytes. The method exists only in a development build, which is the build that carries the channel; a
639
+ * release build leaves it out, so code that uses it must check for it first.
640
+ */
641
+ inspect?(call: string, args?: unknown): Promise<unknown>;
600
642
  /**
601
643
  * Shows an overlay of figures over the top-right corner of the canvas, or hides it with
602
644
  * `false`: the GPU path, the frame rates, CPU time per frame of each thread, GPU time, draw
@@ -699,6 +741,13 @@ export interface Engine {
699
741
  * the page to wait with no end.
700
742
  */
701
743
  export declare const WORKER_REPLY_LIMIT_MS = 600000;
744
+ /**
745
+ * How long a copy of a worker whose script did not load may take to report its first reply. A
746
+ * script that loads reports in about a second on the slowest machines that run the tests, so a
747
+ * copy that has sent nothing by this time never ran: the page fails the start with E1405 rather
748
+ * than waiting for a worker that may never speak.
749
+ */
750
+ export declare const RETRY_REPLY_MS = 10000;
702
751
  interface TierChoice {
703
752
  tier: Tier;
704
753
  forceCompat: boolean;
@@ -724,9 +773,11 @@ interface WorkerEvents {
724
773
  sketchError(error: Error): void;
725
774
  /**
726
775
  * A failure of a thread. It ends a start that is still under way, unless `endsStart` is false:
727
- * the engine then runs on without the thread.
776
+ * the engine then runs on without the thread. It ends hold mode's read-back of its frame too,
777
+ * unless `endsHold` is false: the frames never needed the thread, such as a job worker that did
778
+ * not start.
728
779
  */
729
- failure(error: EngineError, endsStart?: boolean): void;
780
+ failure(error: EngineError, endsStart?: boolean, endsHold?: boolean): void;
730
781
  /** The quality preset and settings after a change, and the preset check's result. */
731
782
  quality(update: QualityUpdate): void;
732
783
  /** The sketch asked to show or hide the stats overlay, or to change its options. */
@@ -743,12 +794,15 @@ interface WorkerEvents {
743
794
  recording?(bytes: Uint8Array): void;
744
795
  /** What a replay gave, after the sketch thread ran the recording's frames. */
745
796
  replay?(result: ReplayResult): void;
797
+ /** The pipeline list of the pipelines that the first frame built, which the page stores. */
798
+ pipelineList?(list: Uint32Array): void;
746
799
  }
747
800
  /**
748
- * The error of a GPU that ran out of memory (E1304) or rejected a command (E1305), on `thread`, such
749
- * as "the render worker".
801
+ * The error of a GPU that ran out of memory (E1304), rejected a command (E1305), or whose driver
802
+ * could not build a pipeline of the scene's objects (E1307), on `thread`, such as "the render
803
+ * worker". `message` names the pipeline for E1307.
750
804
  */
751
- export declare function gpuFailure(thread: string, outOfMemory: boolean, message: string): EngineError;
805
+ export declare function gpuFailure(thread: string, kind: GpuErrorKind, message: string): EngineError;
752
806
  /**
753
807
  * A worker whose replies are routed: events to the page's handlers, answers to the oldest request.
754
808
  * A failure that a started worker reports, or that ends it, reaches the page as E1404, or with its
@@ -767,6 +821,12 @@ export declare class EngineWorker {
767
821
  */
768
822
  private readonly restart?;
769
823
  private readonly waiting;
824
+ /**
825
+ * The inspection calls that wait for their answers, by their id. A production build never makes
826
+ * one, so the map is made at the first call.
827
+ */
828
+ private inspectWaiters;
829
+ private nextInspect;
770
830
  private readyPromise;
771
831
  private readonly stoppedPromise;
772
832
  private worker;
@@ -780,6 +840,8 @@ export declare class EngineWorker {
780
840
  private scriptLoaded;
781
841
  /** True once the page replaced a worker whose script did not load. */
782
842
  private retried;
843
+ /** Clears the wait for the replacement worker's first reply, or undefined once it has one. */
844
+ private retryTimer;
783
845
  /**
784
846
  * The messages that the page sent before the worker reported that its script loaded. A worker
785
847
  * that has not run its script cannot take them, so they wait here: a copy that replaces a
@@ -810,6 +872,14 @@ export declare class EngineWorker {
810
872
  * shows which file failed.
811
873
  */
812
874
  private startFailure;
875
+ /**
876
+ * What the page reports when the copy that replaced a worker whose script did not load has sent
877
+ * nothing within the wait. The first failure named the script; the copy's silence names it too,
878
+ * so a wrong path stays visible and a stall is not read as a wrong path.
879
+ */
880
+ private stalledFailure;
881
+ /** Ends the wait for a replacement worker's first reply, once one arrives or the worker fails. */
882
+ private heardReply;
813
883
  /**
814
884
  * Drops the handlers that reach this engine, so a worker that the page keeps, such as a drawing
815
885
  * worker parked with its canvas, holds none of the engine or its shared memory alive.
@@ -845,6 +915,13 @@ export declare class EngineWorker {
845
915
  stopped(): Promise<void>;
846
916
  /** Stops the worker, and fails each request that still waits for its answer. */
847
917
  terminate(): void;
918
+ /**
919
+ * Runs a development build's inspection call in this worker, and waits for its answer. The
920
+ * worker answers with the value of the call, or why it failed.
921
+ */
922
+ inspect(call: string, args?: unknown): Promise<unknown>;
923
+ /** Gives an inspection call its answer. */
924
+ private answerInspect;
848
925
  /**
849
926
  * Sends a request and waits for the worker's answer, which ends with a failure once the answer
850
927
  * has taken longer than the wait's limit. The request keeps its place in the queue, so an answer