@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
@@ -0,0 +1,475 @@
1
+ // The in-page inspector: a panel docked at the left edge of the page, in a development build. It
2
+ // lists the scene as a tree, selects an object and outlines it in the view, edits its transform, its
3
+ // material and its visibility, and shows the engine's frame figures. It reads and writes the live
4
+ // scene through the page's inspection bridge (`engine.inspect`), so each change is applied between
5
+ // frames. The page loads this module on first use, when the `?inspect` switch asks for it.
6
+ /** The most rows that the tree draws at once, so a scene of many thousands stays responsive. */
7
+ const MAX_ROWS = 2000;
8
+ /** How long the search waits for the next key before it lists the scene again. */
9
+ const SEARCH_DELAY_MS = 150;
10
+ /** How often the panel reads the frame figures. */
11
+ const STATS_MS = 1000;
12
+ const CSS = `
13
+ :host { all: initial; }
14
+ .panel {
15
+ --ok: #3ddc97; --amber: #f2b453; --line: rgba(255, 255, 255, 0.08);
16
+ --line-soft: rgba(255, 255, 255, 0.045);
17
+ --text: #e9eef7; --dim: #98a3b6; --faint: #7a8699;
18
+ position: fixed; left: 0; top: 0; bottom: 0; z-index: 2147483646;
19
+ width: 320px; max-width: 82vw;
20
+ display: flex; flex-direction: column;
21
+ background: linear-gradient(180deg, rgba(20, 25, 33, 0.97), rgba(13, 17, 23, 0.98));
22
+ border-right: 1px solid rgba(255, 255, 255, 0.1);
23
+ box-shadow: 12px 0 30px rgba(0, 0, 0, 0.4);
24
+ color: var(--text);
25
+ font: 12px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
26
+ font-variant-numeric: tabular-nums;
27
+ overflow: hidden;
28
+ }
29
+ .head { display: flex; align-items: baseline; gap: 8px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
30
+ .head .title { font-weight: 600; font-size: 14px; letter-spacing: 0.01em; }
31
+ .head .meta { margin-left: auto; color: var(--faint); font-size: 10px; }
32
+ .head button {
33
+ border: 0; background: none; color: var(--faint); font: inherit; font-size: 16px;
34
+ cursor: pointer; padding: 0 2px; line-height: 1;
35
+ }
36
+ .head button:hover { color: var(--text); }
37
+ .find { padding: 10px 12px 6px; }
38
+ .find input, .field input {
39
+ box-sizing: border-box; width: 100%;
40
+ border: 1px solid var(--line); border-radius: 6px; background: #11161f;
41
+ color: var(--text); font: inherit; padding: 4px 7px; outline: none;
42
+ }
43
+ .find input:focus, .field input:focus { border-color: rgba(242, 180, 83, 0.55); }
44
+ .tree { flex: 1 1 26%; min-height: 70px; overflow: auto; padding: 2px 8px 8px; }
45
+ .row { display: flex; align-items: center; gap: 5px; padding: 2px 5px; border-radius: 5px; cursor: pointer; color: var(--dim); }
46
+ .row:hover { background: rgba(255, 255, 255, 0.04); }
47
+ .row.sel { background: rgba(242, 180, 83, 0.14); color: var(--text); }
48
+ .row .tw { width: 10px; flex: none; text-align: center; color: var(--faint); }
49
+ .row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
50
+ .row .kind { margin-left: auto; font-size: 9px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); flex: none; }
51
+ .truncated { color: var(--faint); padding: 6px 8px; font-size: 10.5px; }
52
+ .detail { border-top: 1px solid var(--line); padding: 9px 12px 10px; overflow: auto; flex: 1 1 auto; min-height: 0; }
53
+ .detail .empty { color: var(--faint); }
54
+ .detail .title { font-weight: 600; font-size: 12.5px; }
55
+ .detail .meta { color: var(--faint); font-size: 9.5px; margin-left: 6px; }
56
+ .group { margin-top: 8px; }
57
+ .group .label { font-size: 8.5px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); margin-bottom: 3px; }
58
+ .triple { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
59
+ .triple input { text-align: right; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 10.5px; padding: 3px 5px; }
60
+ .check { display: flex; align-items: center; gap: 6px; color: var(--dim); }
61
+ .check input { width: 14px; height: 14px; accent-color: #3ddc97; }
62
+ .material { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
63
+ .mat-row { display: flex; align-items: center; gap: 7px; color: var(--dim); }
64
+ .mat-row .name { width: 74px; flex: none; }
65
+ .mat-row input[type="color"] { width: 26px; height: 20px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: #11161f; }
66
+ .mat-row input[type="range"] { flex: 1; min-width: 0; accent-color: #a98bfa; }
67
+ .mat-row input[type="number"] { width: 48px; text-align: right; font-family: ui-monospace, Menlo, monospace; font-size: 10.5px; padding: 2px 4px; }
68
+ .figures { border-top: 1px solid var(--line); padding: 8px 12px 11px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
69
+ .fig { background: rgba(255, 255, 255, 0.035); border: 1px solid var(--line-soft); border-radius: 6px; padding: 4px 6px; min-width: 0; }
70
+ .fig .k { font-size: 8px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
71
+ .fig .v { font-size: 11.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
72
+ .fig .v small { font-size: 8px; font-weight: 500; color: var(--dim); }
73
+ .error { color: #ff8074; padding: 0 12px 8px; font-size: 10.5px; }
74
+ .hint { color: var(--faint); font-size: 10px; padding: 0 12px 8px; }
75
+ `;
76
+ /** The panel's element, which a page finds by this attribute. */
77
+ export const INSPECTOR_ATTRIBUTE = 'data-null3d-inspector';
78
+ /** Makes an element with a class and, where given, text. */
79
+ function el(tag, className, text) {
80
+ const node = document.createElement(tag);
81
+ if (className !== undefined)
82
+ node.className = className;
83
+ if (text !== undefined)
84
+ node.textContent = text;
85
+ return node;
86
+ }
87
+ /** Throws the bridge's error as an Error with its text, whatever it was. */
88
+ function asError(error) {
89
+ return error instanceof Error ? error : new Error(String(error));
90
+ }
91
+ /** Puts the panel's style sheet in its shadow root, passing a Content Security Policy without 'unsafe-inline'. */
92
+ function installStyles(root) {
93
+ try {
94
+ const sheet = new CSSStyleSheet();
95
+ sheet.replaceSync(CSS);
96
+ root.adoptedStyleSheets = [sheet];
97
+ }
98
+ catch {
99
+ const style = document.createElement('style');
100
+ style.textContent = CSS;
101
+ root.append(style);
102
+ }
103
+ }
104
+ /** Turns a quaternion (x, y, z, w) into X, then Y, then Z Euler angles in radians, as the engine's setRotationEuler takes. */
105
+ function quaternionToEuler(q) {
106
+ const x = q[0];
107
+ const y = q[1];
108
+ const z = q[2];
109
+ const w = q[3];
110
+ const ex = Math.atan2(2 * (w * x + y * z), 1 - 2 * (x * x + y * y));
111
+ const sy = 2 * (w * y - z * x);
112
+ const ey = Math.asin(Math.min(1, Math.max(-1, sy)));
113
+ const ez = Math.atan2(2 * (w * z + x * y), 1 - 2 * (y * y + z * z));
114
+ return [ex, ey, ez];
115
+ }
116
+ /** The panel of the in-page inspector. */
117
+ export class Inspector {
118
+ bridge;
119
+ host;
120
+ tree = el('div', 'tree');
121
+ detail = el('div', 'detail');
122
+ figures = el('div', 'figures');
123
+ count = el('span', 'meta', '');
124
+ search = el('input');
125
+ error = el('div', 'error');
126
+ treeRows = [];
127
+ collapsed = new Set();
128
+ selected;
129
+ summaries = new Map();
130
+ statsTimer;
131
+ searchTimer;
132
+ selectToken = 0;
133
+ listToken = 0;
134
+ statsBusy = false;
135
+ removed = false;
136
+ constructor(bridge) {
137
+ this.bridge = bridge;
138
+ this.host = document.createElement('div');
139
+ this.host.setAttribute(INSPECTOR_ATTRIBUTE, '');
140
+ const root = this.host.attachShadow({ mode: 'open' });
141
+ installStyles(root);
142
+ const panel = el('div', 'panel');
143
+ const head = el('div', 'head');
144
+ head.append(el('span', 'title', 'Scene'), this.count);
145
+ const close = el('button', '', '×');
146
+ close.type = 'button';
147
+ close.setAttribute('aria-label', 'Close the inspector');
148
+ close.addEventListener('click', () => this.remove());
149
+ const refresh = el('button', '', '↻');
150
+ refresh.type = 'button';
151
+ refresh.title = 'List the scene again';
152
+ refresh.setAttribute('aria-label', 'List the scene again');
153
+ refresh.addEventListener('click', () => void this.list());
154
+ head.append(refresh, close);
155
+ this.search.type = 'search';
156
+ this.search.placeholder = 'Find an object';
157
+ this.search.setAttribute('aria-label', 'Find an object by name');
158
+ this.search.addEventListener('input', () => this.scheduleSearch());
159
+ const find = el('div', 'find');
160
+ find.append(this.search);
161
+ this.detail.append(el('div', 'empty', 'Select an object to edit it.'));
162
+ const hint = el('div', 'hint', '?inspect · development build');
163
+ panel.append(head, find, this.tree, this.detail, this.figures, this.error, hint);
164
+ root.append(panel);
165
+ panel.addEventListener('keydown', (event) => {
166
+ if (event.key === 'Escape')
167
+ this.remove();
168
+ });
169
+ document.body.append(this.host);
170
+ void this.list();
171
+ this.refreshStats();
172
+ this.statsTimer = setInterval(() => this.refreshStats(), STATS_MS);
173
+ }
174
+ /** Takes the panel off the page and clears the selection's outline. */
175
+ remove() {
176
+ if (this.removed)
177
+ return;
178
+ this.removed = true;
179
+ if (this.statsTimer !== undefined)
180
+ clearInterval(this.statsTimer);
181
+ if (this.searchTimer !== undefined)
182
+ clearTimeout(this.searchTimer);
183
+ this.host.remove();
184
+ void this.bridge.inspect('highlight', {}).catch(() => { });
185
+ }
186
+ /** Lists the scene again after the search settles. */
187
+ scheduleSearch() {
188
+ if (this.searchTimer !== undefined)
189
+ clearTimeout(this.searchTimer);
190
+ this.searchTimer = setTimeout(() => {
191
+ this.searchTimer = undefined;
192
+ void this.list();
193
+ }, SEARCH_DELAY_MS);
194
+ }
195
+ /** Lists the scene, or the objects that the search names, and draws the tree. */
196
+ async list() {
197
+ const token = ++this.listToken;
198
+ try {
199
+ const answer = (await this.bridge.inspect('objects', {
200
+ filter: this.search.value.trim() || undefined,
201
+ }));
202
+ if (token !== this.listToken || this.removed)
203
+ return;
204
+ this.showError(undefined);
205
+ this.summaries = new Map(answer.objects.map((object) => [object.slot, object]));
206
+ this.count.textContent = `${answer.count} object${answer.count === 1 ? '' : 's'}`;
207
+ this.drawTree(answer);
208
+ }
209
+ catch (error) {
210
+ if (token === this.listToken)
211
+ this.showError(asError(error).message);
212
+ }
213
+ }
214
+ /** Draws the tree from a listing, parents before their children, with the rows nested. */
215
+ drawTree(listing) {
216
+ this.tree.replaceChildren();
217
+ this.treeRows.length = 0;
218
+ const children = new Map();
219
+ for (const object of listing.objects) {
220
+ const parent = object.parent !== null && this.summaries.has(object.parent) ? object.parent : null;
221
+ const list = children.get(parent);
222
+ if (list === undefined)
223
+ children.set(parent, [object]);
224
+ else
225
+ list.push(object);
226
+ }
227
+ let rows = 0;
228
+ const append = (parent, depth) => {
229
+ const list = children.get(parent);
230
+ if (list === undefined)
231
+ return;
232
+ for (const object of list) {
233
+ if (rows >= MAX_ROWS)
234
+ return;
235
+ const row = el('div', 'row');
236
+ row.style.paddingLeft = `${5 + depth * 12}px`;
237
+ row.dataset.slot = String(object.slot);
238
+ const hasChildren = object.children > 0 && children.has(object.slot);
239
+ const twist = el('span', 'tw', hasChildren ? (this.collapsed.has(object.slot) ? '▸' : '▾') : '·');
240
+ twist.addEventListener('click', (event) => {
241
+ event.stopPropagation();
242
+ if (this.collapsed.has(object.slot))
243
+ this.collapsed.delete(object.slot);
244
+ else
245
+ this.collapsed.add(object.slot);
246
+ this.drawTree(listing);
247
+ });
248
+ row.append(twist, el('span', 'name', object.name || '(unnamed)'), el('span', 'kind', object.kind));
249
+ row.addEventListener('click', () => void this.select(object.slot));
250
+ if (object.slot === this.selected)
251
+ row.classList.add('sel');
252
+ row.setAttribute('role', 'treeitem');
253
+ this.tree.append(row);
254
+ this.treeRows.push(row);
255
+ rows++;
256
+ if (hasChildren && !this.collapsed.has(object.slot))
257
+ append(object.slot, depth + 1);
258
+ }
259
+ };
260
+ append(null, 0);
261
+ if (listing.truncated || listing.count > rows)
262
+ this.tree.append(el('div', 'truncated', `Showing the first ${rows} of ${listing.count}. Search to narrow the list.`));
263
+ }
264
+ /** Selects `slot`, outlines it and shows its fields. */
265
+ async select(slot) {
266
+ const token = ++this.selectToken;
267
+ this.selected = slot;
268
+ for (const row of this.treeRows) {
269
+ row.classList.toggle('sel', row.dataset.slot === String(slot));
270
+ }
271
+ try {
272
+ const detail = (await this.bridge.inspect('object', { selector: slot }));
273
+ if (token !== this.selectToken || this.removed)
274
+ return;
275
+ this.showError(undefined);
276
+ this.drawDetail(detail);
277
+ await this.bridge.inspect('highlight', { selector: slot });
278
+ }
279
+ catch (error) {
280
+ if (token === this.selectToken)
281
+ this.showError(asError(error).message);
282
+ }
283
+ }
284
+ /** Shows an object's title, transform, flags and material. */
285
+ drawDetail(detail) {
286
+ const title = el('div');
287
+ title.append(el('span', 'title', detail.name || '(unnamed)'), el('span', 'meta', `#${detail.slot} · ${detail.kind}`));
288
+ const position = this.vectorGroup('Position · m', detail.position, 0.1, (values) => this.change({ selector: detail.slot, position: values }));
289
+ const euler = quaternionToEuler(detail.rotation).map((radians) => Number(((radians * 180) / Math.PI).toFixed(2)));
290
+ const rotation = this.vectorGroup('Rotation · °', euler, 1, (values) => this.change({
291
+ selector: detail.slot,
292
+ rotationEuler: values.map((degrees) => (degrees * Math.PI) / 180),
293
+ }));
294
+ const scale = this.vectorGroup('Scale', detail.scale, 0.01, (values) => this.change({ selector: detail.slot, scale: values }));
295
+ const visible = this.checkField('Visible', detail.visible, (on) => this.change({ selector: detail.slot, visible: on }));
296
+ const dynamic = this.checkField('Dynamic', detail.dynamic, (on) => this.change({ selector: detail.slot, dynamic: on }));
297
+ this.detail.replaceChildren(title, position, rotation, scale, visible, dynamic);
298
+ if (detail.kind === 'mesh' && detail.materialValues !== undefined)
299
+ this.detail.append(this.materialSection(detail));
300
+ }
301
+ /** A labelled row of three number fields that reports all three when one changes. */
302
+ vectorGroup(label, values, step, change) {
303
+ const group = el('div', 'group');
304
+ group.append(el('div', 'label', label));
305
+ const triple = el('div', 'triple');
306
+ const inputs = [];
307
+ for (let k = 0; k < 3; k++) {
308
+ const input = el('input');
309
+ input.type = 'number';
310
+ input.step = String(step);
311
+ input.value = String(Number(values[k].toFixed(3)));
312
+ input.setAttribute('aria-label', `${label.split(' · ')[0]} ${['X', 'Y', 'Z'][k]}`);
313
+ input.addEventListener('change', () => {
314
+ const numbers = inputs.map((field) => Number(field.value));
315
+ if (numbers.every(Number.isFinite))
316
+ change(numbers);
317
+ });
318
+ inputs.push(input);
319
+ triple.append(input);
320
+ }
321
+ group.append(triple);
322
+ return group;
323
+ }
324
+ /** A labelled checkbox. */
325
+ checkField(label, checked, change) {
326
+ const group = el('div', 'group');
327
+ const row = el('label', 'check');
328
+ const input = el('input');
329
+ input.type = 'checkbox';
330
+ input.checked = checked;
331
+ input.addEventListener('change', () => change(input.checked));
332
+ row.append(input, document.createTextNode(label));
333
+ group.append(row);
334
+ return group;
335
+ }
336
+ /** The base color and the three values that the inspector edits most. */
337
+ materialSection(detail) {
338
+ const values = detail.materialValues ?? {};
339
+ const section = el('div', 'material');
340
+ const color = el('input');
341
+ color.type = 'color';
342
+ color.value = typeof values.color === 'string' ? values.color : '#ffffff';
343
+ color.addEventListener('change', () => this.changeMaterial(detail.slot, { color: color.value }));
344
+ section.append(this.materialRow('Base color', color));
345
+ for (const [key, name] of [
346
+ ['roughness', 'Roughness'],
347
+ ['metalness', 'Metalness'],
348
+ ['opacity', 'Opacity'],
349
+ ]) {
350
+ const value = typeof values[key] === 'number' ? values[key] : 1;
351
+ const range = el('input');
352
+ range.type = 'range';
353
+ range.min = '0';
354
+ range.max = '1';
355
+ range.step = '0.01';
356
+ range.value = String(value);
357
+ const number = el('input');
358
+ number.type = 'number';
359
+ number.min = '0';
360
+ number.max = '1';
361
+ number.step = '0.01';
362
+ number.value = String(value);
363
+ const apply = (next) => {
364
+ range.value = String(next);
365
+ number.value = String(next);
366
+ this.changeMaterial(detail.slot, { [key]: next });
367
+ };
368
+ range.addEventListener('change', () => apply(Number(range.value)));
369
+ number.addEventListener('change', () => {
370
+ const next = Number(number.value);
371
+ if (Number.isFinite(next))
372
+ apply(next);
373
+ });
374
+ const row = el('div', 'mat-row');
375
+ row.append(el('span', 'name', name), range, number);
376
+ section.append(row);
377
+ }
378
+ return section;
379
+ }
380
+ /** One row of the material section. */
381
+ materialRow(name, control) {
382
+ const row = el('div', 'mat-row');
383
+ row.append(el('span', 'name', name), control);
384
+ return row;
385
+ }
386
+ /** Applies a change to the selected object and shows what the scene now holds. */
387
+ async change(args) {
388
+ const token = this.selectToken;
389
+ try {
390
+ const detail = (await this.bridge.inspect('setObject', args));
391
+ if (token !== this.selectToken || this.removed)
392
+ return;
393
+ this.showError(undefined);
394
+ this.drawDetail(detail);
395
+ }
396
+ catch (error) {
397
+ this.showError(asError(error).message);
398
+ }
399
+ }
400
+ /** Applies a material change and shows the object's new state. */
401
+ async changeMaterial(slot, values) {
402
+ const token = this.selectToken;
403
+ try {
404
+ const detail = (await this.bridge.inspect('setMaterial', {
405
+ selector: slot,
406
+ values,
407
+ }));
408
+ if (token !== this.selectToken || this.removed)
409
+ return;
410
+ this.showError(undefined);
411
+ this.drawDetail(detail);
412
+ }
413
+ catch (error) {
414
+ this.showError(asError(error).message);
415
+ }
416
+ }
417
+ /** Reads the frame figures and shows them. */
418
+ async refreshStats() {
419
+ if (this.removed || this.statsBusy)
420
+ return;
421
+ this.statsBusy = true;
422
+ try {
423
+ const stats = (await this.bridge.inspect('stats'));
424
+ if (this.removed)
425
+ return;
426
+ const figures = [
427
+ ['FPS', stats.frames > 0 ? stats.presentedFps.toFixed(0) : '—'],
428
+ ['CPU', stats.frames > 0 ? `${stats.cpuMs.toFixed(1)} ms` : '—'],
429
+ ['GPU', stats.gpuMs === null || stats.frames === 0 ? '—' : `${stats.gpuMs.toFixed(1)} ms`],
430
+ ['Draws', String(stats.drawCalls)],
431
+ ['Triangles', count(stats.triangles)],
432
+ ['Objects', String(stats.objects)],
433
+ ['Uploads', bytes(stats.uploadBytes)],
434
+ ['Preset', stats.preset],
435
+ ['Tier', stats.tier],
436
+ ];
437
+ const grid = this.figures;
438
+ grid.replaceChildren(...figures.map(([key, value]) => {
439
+ const fig = el('div', 'fig');
440
+ fig.append(el('div', 'k', key), el('div', 'v', value));
441
+ return fig;
442
+ }));
443
+ }
444
+ catch {
445
+ // The figures are a convenience; a stopped engine leaves the last ones drawn.
446
+ }
447
+ finally {
448
+ this.statsBusy = false;
449
+ }
450
+ }
451
+ /** Shows an error under the detail, or clears it. */
452
+ showError(message) {
453
+ this.error.textContent = message ?? '';
454
+ }
455
+ }
456
+ /** Counts a large number with one decimal and its scale, such as "1.2 M". */
457
+ function count(value) {
458
+ if (value >= 1_000_000)
459
+ return `${(value / 1_000_000).toFixed(1)} M`;
460
+ if (value >= 1_000)
461
+ return `${(value / 1_000).toFixed(1)} k`;
462
+ return String(Math.round(value));
463
+ }
464
+ /** Reads bytes as a short figure, such as "412 kB". */
465
+ function bytes(value) {
466
+ if (value >= 1024 * 1024)
467
+ return `${(value / (1024 * 1024)).toFixed(1)} MB`;
468
+ if (value >= 1024)
469
+ return `${Math.round(value / 1024)} kB`;
470
+ return `${Math.round(value)} B`;
471
+ }
472
+ /** Opens the inspector panel on the page, and returns it. */
473
+ export function openInspector(bridge) {
474
+ return new Inspector(bridge);
475
+ }
@@ -18,7 +18,7 @@ export interface StatsPanelOptions {
18
18
  /**
19
19
  * How the threads of a renderer share each frame's work, which a symbol before the target explains:
20
20
  * `'pipelined'` and `'low'` are null3D's latency modes, `'single'` is null3D's single-thread build,
21
- * and `'one-thread'` is a renderer that prepares and draws each frame on one thread, as three.js does.
21
+ * and `'one-thread'` is a renderer that prepares and draws each frame on one thread.
22
22
  *
23
23
  * @category api/debug
24
24
  */
@@ -90,9 +90,8 @@ export interface FrameStats {
90
90
  readonly drawCalls: number;
91
91
  /**
92
92
  * Mean triangles drawn per frame, over every pass: shadow maps and the depth prepass count as
93
- * well as the passes that shade, as three.js's `renderer.info` counts them. Lines count none.
94
- * On WebGPU the GPU culls most objects, and the count of their triangles comes back from the GPU
95
- * on one frame in eleven, a few frames late.
93
+ * well as the passes that shade. Lines count none. On WebGPU the GPU culls most objects, and the
94
+ * count of their triangles comes back from the GPU on one frame in eleven, a few frames late.
96
95
  */
97
96
  readonly triangles: number;
98
97
  /**
@@ -129,7 +129,7 @@ const DOCS = {
129
129
  },
130
130
  E1214: {
131
131
  title: 'Invalid sketch option',
132
- cause: 'defineSketch() received an option out of its range. fixedRate must be a number above 0, and maxFixedSteps a whole number of 1 or more. The engine checks the options before it runs the setup function.',
132
+ cause: 'defineSketch() received an option out of its range. fixedRate must be a number above 0, and maxFixedSteps a whole number of 1 or more. downloads must be an array of file addresses: an empty string, or a string that is not an address, fails. The engine checks the options before it runs the setup function.',
133
133
  example: 'E1214: defineSketch() got 0 for fixedRate.',
134
134
  since: '0.1',
135
135
  },
@@ -235,6 +235,12 @@ const DOCS = {
235
235
  example: 'E1306: this browser runs the WebKit engine of Safari 17, and the engine needs Safari 18 or later.',
236
236
  since: '0.2',
237
237
  },
238
+ E1307: {
239
+ title: 'Pipeline not built',
240
+ cause: "After the start, the GPU's driver could not build a pipeline that draws objects of the scene. It refused the pipeline among the other builds, and again when the engine built it alone. A driver does this when it runs short of memory as it compiles the shader, or when its compiler fails on the shader. On WebGL2, a program that the driver refuses to link twice counts the same. The message names the pipeline: its template, such as a custom material, and the pass that its build draws in. The objects that draw with it are missing from that pass. The engine reports the first time this happens on each GPU device, and draws on.",
241
+ example: "E1307: the render worker's GPU driver could not build the pipeline of custom material 135, so the objects that draw with it are missing. It failed twice, the second time alone: CreateGraphicsPipelines failed with VK_ERROR_UNKNOWN.",
242
+ since: '0.3',
243
+ },
238
244
  E1401: {
239
245
  title: 'Not a sketch module',
240
246
  cause: 'The module passed to createEngine as the sketch does not export a sketch as its default export.',
@@ -351,7 +357,7 @@ const DOCS = {
351
357
  },
352
358
  E1420: {
353
359
  title: 'Engine stopped',
354
- cause: 'Sketch code called the engine after the engine stopped, from a timer, a promise or an event handler that outlived destroy(). The call did nothing.',
360
+ cause: 'Sketch code called the engine after the engine stopped, from a timer, a promise or an event handler that outlived destroy(). The call did nothing. engine.firstFrame rejects with it too when the page destroys the engine before its first frame.',
355
361
  example: 'E1420: a call reached the engine after it stopped.',
356
362
  since: '0.2',
357
363
  },
@@ -6,22 +6,29 @@
6
6
  //
7
7
  // A thread can hold two copies of this module: in a production build, the sketch worker runs the
8
8
  // engine's worker code, and the sketch's bundle imports the engine again from the page's file. So
9
- // the table of fixes and the mark on each error live under registered symbols, which every copy in
10
- // the thread shares. Each copy then reads the same table, and instanceof accepts the errors of both.
9
+ // the table of fixes, its load and the mark on each error live under registered symbols, which
10
+ // every copy in the thread shares. Each copy then reads the same table, waits for the same load, and
11
+ // instanceof accepts the errors of both. A copy that loaded the table on its own would leave its
12
+ // errors short after the other copy's had their fixes, while a second file downloads.
11
13
  // The docs address, the message's form and the mark live in engine-error-core.ts, which code that
12
14
  // may not load the fixes, such as a simulation's math, throws its errors from.
13
15
  import { DOCS_BASE, ENGINE_ERROR, messageFor } from './engine-error-core.js';
14
16
  /** The key of the thread's table of fixes on its global object. */
15
17
  const FIXES = Symbol.for('null3d.errorFixes');
16
- /** The thread's global object, which holds the table of fixes for every copy of this module. */
18
+ /** The key of the thread's load of that table, which the first copy to need it starts. */
19
+ const LOAD = Symbol.for('null3d.errorFixesLoad');
20
+ /**
21
+ * The thread's global object, which holds the table of fixes and its load for every copy of this
22
+ * module.
23
+ */
17
24
  const thread = globalThis;
18
25
  /**
19
26
  * Every code, joined, so an error keeps its code before the file of fixes arrives. A test keeps it
20
27
  * equal to the keys of the table.
21
28
  */
22
- const CODES = 'E1101E1102E1103E1104E1105E1106E1107E1108E1109E1110E1111E1112E1203E1204E1205E1206E1207E1208E1209E1213E1214E1215E1216E1217E1218E1219E1220E1221E1222E1223E1224E1225E1301E1302E1303E1304E1305E1306E1401E1402E1403E1404E1405E1406E1407E1408E1409E1410E1411E1412E1413E1414E1415E1416E1417E1418E1419E1420E1421E1422E1423E1424E1425E1426E1430E1431E1432E1433E1434E1435E1436E1437E1501E1502E1503E1504E1505E1506';
29
+ const CODES = 'E1101E1102E1103E1104E1105E1106E1107E1108E1109E1110E1111E1112E1203E1204E1205E1206E1207E1208E1209E1213E1214E1215E1216E1217E1218E1219E1220E1221E1222E1223E1224E1225E1301E1302E1303E1304E1305E1306E1307E1401E1402E1403E1404E1405E1406E1407E1408E1409E1410E1411E1412E1413E1414E1415E1416E1417E1418E1419E1420E1421E1422E1423E1424E1425E1426E1430E1431E1432E1433E1434E1435E1436E1437E1501E1502E1503E1504E1505E1506';
23
30
  const waiting = [];
24
- /** The load of the fixes, which one thread starts once. */
31
+ /** This copy's wait for the thread's load of the fixes, which settles its own waiting errors. */
25
32
  let loading;
26
33
  /** Tells each waiting error the fix, unless its message holds other text by now. */
27
34
  function settle(fixes) {
@@ -30,16 +37,24 @@ function settle(fixes) {
30
37
  error.message = messageFor(code, detail, fixes[code]);
31
38
  }
32
39
  }
33
- /** Loads the thread's file of fixes, once, and gives each error that waits its fix. */
40
+ /**
41
+ * Loads the thread's file of fixes, once for every copy of this module in the thread, and gives
42
+ * each error of this copy that waits its fix.
43
+ */
34
44
  function loadFixes() {
35
45
  if (thread[FIXES] !== undefined)
36
46
  return Promise.resolve();
37
- loading ??= import('./fixes.js').then(({ ERROR_FIXES }) => {
47
+ if (loading)
48
+ return loading;
49
+ thread[LOAD] ??= import('./fixes.js').then(({ ERROR_FIXES }) => {
38
50
  thread[FIXES] ??= ERROR_FIXES;
39
- settle(thread[FIXES]);
40
- }, () => {
41
- // The text is a hint: an error keeps its code and detail when the file does not arrive.
51
+ return thread[FIXES];
52
+ });
53
+ loading = thread[LOAD].then(settle, () => {
54
+ // The text is a hint: an error keeps its code and detail when the file does not arrive, and
55
+ // a later error tries again.
42
56
  loading = undefined;
57
+ thread[LOAD] = undefined;
43
58
  });
44
59
  return loading;
45
60
  }
@@ -37,6 +37,7 @@ export declare const ERROR_FIXES: {
37
37
  E1304: string;
38
38
  E1305: string;
39
39
  E1306: string;
40
+ E1307: string;
40
41
  E1401: string;
41
42
  E1402: string;
42
43
  E1403: string;
@@ -24,7 +24,7 @@ export const ERROR_FIXES = {
24
24
  E1208: "Give options from the texture's docs page, such as wrap: 'repeat', filter: 'nearest' or anisotropy: 8. Give fromDatafour numbers per texel: a Uint8Array for rgba8unorm, and a Uint16Array of half floats or a Float32Array for rgba16float. Resize images larger than textures.maxSize, and decode a closed image again. Encode a KTX2 file flipped instead of passing flipY: true, and load it again instead of updating its texture.",
25
25
  E1209: "Give the material fewer textures. WebGL2 gives each shader stage at least 16 texture units, as many as the device reports, and the engine's lit shader reads most of them, so a custom material's own textures must fit in what is left. Use the standard material's own maps where they draw the effect.",
26
26
  E1213: "Pass only the settings that the call has, each with a value that it takes. The call's docs page lists them.",
27
- E1214: 'Give fixedRate the fixed steps per second, a number above 0 such as 60 or 120. Give maxFixedSteps a whole number of 1 or more, such as 8.',
27
+ E1214: "Give fixedRate the fixed steps per second, a number above 0 such as 60 or 120. Give maxFixedSteps a whole number of 1 or more, such as 8. Give downloads an array of the files that the setup loads, each a URL or an address string such as 'models/ship.glb'.",
28
28
  E1215: 'Add the null3D Vite plugin to vite.config.ts. Write the WGSL in a template literal right after a /* wgsl */ comment, or import it from a .wgsl file. Declare fn surface(input: SurfaceInput) -> Surface, fn vertexOffset(input: VertexInput) -> vec3f or fn lobe(input: LobeInput) -> vec3f in it, with no @vertex or @fragment entry point. For a full shader, give the @vertex entry point an InstanceIn from null3d::mesh. For a draw that makes its own vertices, give it @builtin(vertex_index) and @builtin(instance_index) and no mesh attribute. Give post.addEffect() WGSL that declares fn effect(input: EffectInput) -> vec4f, post.set({ toneMapping }) WGSL that declares fn toneCurve(color: vec3f) -> vec3f, and scene.setSkyLayer() WGSL that declares fn skyLayer(input: SkyLayerInput) -> SkyLayer.',
29
29
  E1216: 'Use the names of the fields of struct Uniforms in the WGSL. Give an f32 a number, and an i32 or a u32 a whole number. Give a vec2f, vec3f or vec4f an array of 2, 3 or 4 numbers. A vec3f also takes a color. Rename a field that has the name of a standard value, such as color. Give a slot that the WGSL declares as a texture_2d<f32> a texture of one layer, and a slot that it declares as a texture_2d_array<f32> a texture of several layers, from textures.fromData with a depth or a KTX2 file of layers. Give post.setEffectUniform() an effect that post.addEffect() returned.',
30
30
  E1217: "Give alphaMode 'opaque', 'mask', 'hash' or 'blend', and blending 'normal', 'additive', 'multiply' or 'weighted'. three.js's transparent: true is alphaMode: 'blend', and its alphaTest is alphaMode: 'mask' with alphaCutoff. A custom material takes 'opaque', 'mask', 'hash' or 'blend', and no 'weighted' blending. It takes alphaToCoverage or the hash mode only where its WGSL sets or reads the surface's alpha, such as s.alpha = texel.a in fn surface. A draw that makes its own vertices blends, and its WGSL declares no texture. A material with transmission takes 'opaque', 'mask' or 'blend', not the 'weighted' blending, and a custom one needs WGSL that sets the surface's transmission. A layered material takes no lightMap or specular maps: give clearcoatMap with clearcoatRoughnessMap as one texture, and sheenColorMap with sheenRoughnessMap as one. Give diffuseTransmissionMap and diffuseTransmissionColorMap only with diffuseTransmission, and no specular maps beside them. Give transmissionMap and thicknessMap only with transmission. Each samples a specular slot's texture array at a layer of its own, so a specular map may draw beside them when the two textures share an array, and a thicknessMap refuses a specularColorMap, whose sRGB texture never shares its array. A layered material keeps them beside the layer map of the light map's slot, but not beside a layer map of the array that one of them samples: transmissionMap samples the specular intensity slot's array, and thicknessMap the specular color slot's. Give diffuseTransmission without a clear coat, a sheen or the 'weighted' blending. A material's layer maps come from one family: the coat's and the sheen's, or iridescence's and the anisotropy's, since they take the same slots. Give an anisotropy map, and another map that gives the surface's texture coordinates. A custom material with diffuseTransmission needs WGSL that sets the surface's diffuseTransmission. Give subsurfaceRadius to materials.standard: a custom material draws no subsurface blur. Give a custom material that declares a coverage function alphaMode 'mask', or 'blend' with the alphaCutoff that its caster tests.",
@@ -42,6 +42,7 @@ export const ERROR_FIXES = {
42
42
  E1304: 'Lower the quality preset, use smaller or compressed textures, and share meshes and textures between objects. Destroy objects and textures that the scene no longer shows.',
43
43
  E1305: "Read the message: it quotes the GPU path. A buffer or texture past the device's limits names the limit: make the scene smaller there. Otherwise this is an engine bug: report it with the message and the browser.",
44
44
  E1306: 'Update Safari to version 18 or later. On iPhone and iPad, update iOS or iPadOS to 18 or later, which updates the engine of every browser there.',
45
+ E1307: "The engine draws on without those objects. Read the message: it names the pipeline and quotes the driver. When it names a custom material, check that material's WGSL on the device. A shorter shader, with fewer texture reads, loops and calls, gives the driver less to compile. On a device with little memory, use less of it: a lower quality preset, smaller textures and fewer objects. Update the browser and the device's system software. If the message names an engine template, report it with the device.",
45
46
  E1401: 'End the sketch module with export default defineSketch(...), and pass that module to createEngine.',
46
47
  E1402: 'Reinstall the engine package so all of its parts come from one version. If you build the engine from source, run bun run build again.',
47
48
  E1403: 'Create objects in the setup function you pass to defineSketch, or later, never when the sketch module loads.',
@@ -61,7 +62,7 @@ export const ERROR_FIXES = {
61
62
  E1417: 'Export the model again without the extension that the message names, or import the add-on that the message names and register its handler on assets. Call createInstances with a model that has meshes and no instancing of its own, or with one of its meshes and a material.',
62
63
  E1418: "Add 'wasm-unsafe-eval' to the script-src of the page's Content-Security-Policy, for example script-src 'self' 'wasm-unsafe-eval'. It allows WebAssembly and no JavaScript eval. The hosting page of the docs gives the whole policy that the engine needs.",
63
64
  E1419: "Wait for the other engine's destroy() promise before you start a new engine on its canvas. In React, call destroy() in the effect's cleanup. When the message says that no engine can draw on the canvas again, put a new canvas element in its place.",
64
- E1420: "Remove the sketch's timers, event listeners and message handlers in its onDestroy callback, which runs when the engine stops.",
65
+ E1420: "Remove the sketch's timers, event listeners and message handlers in its onDestroy callback, which runs when the engine stops. A page that destroys an engine before its first frame stops waiting for engine.firstFrame, or catches its rejection.",
65
66
  E1421: 'Name each feature as the message lists it. Leave a feature out to let its shaders download the first time the sketch uses it.',
66
67
  E1422: "Add what the message names to the page's Content-Security-Policy. Its worker-src needs blob: and the origin of the engine's files, and its script-src and connect-src need that origin. For example: worker-src 'self' blob: https://cdn.example.com; script-src 'self' https://cdn.example.com 'wasm-unsafe-eval'; connect-src 'self' https://cdn.example.com. Or serve the engine's files from the page's own origin.",
67
68
  E1423: "Have the server of the engine's files send Access-Control-Allow-Origin with the page's origin or *, on every file: the scripts, the workers and the .wasm files. If it does, check that the file exists at the address that the message names.",
@@ -374,7 +374,7 @@ export declare const POST_VALUE_SSR_THICKNESS = 61;
374
374
  export declare const POST_VALUE_SSR_MAX_ROUGHNESS = 62;
375
375
  export declare const POST_VALUE_SHARPEN = 63;
376
376
  export declare const POST_VALUE_COUNT = 64;
377
- export declare const CALL_VALUE_COUNT = 10;
377
+ export declare const CALL_VALUE_COUNT = 11;
378
378
  export declare const ENVIRONMENT_VALUE_INTENSITY = 0;
379
379
  export declare const ENVIRONMENT_VALUE_ROTATION = 1;
380
380
  export declare const ENVIRONMENT_VALUE_SH = 4;