@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
@@ -3,18 +3,18 @@ id: errors/E1214
3
3
  title: "E1214: Invalid sketch option"
4
4
  status: generated
5
5
  since: "0.1"
6
- summary: "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."
6
+ summary: "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."
7
7
  ---
8
8
 
9
9
  # E1214: Invalid sketch option
10
10
 
11
11
  ## What happened
12
12
 
13
- 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.
13
+ 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.
14
14
 
15
15
  ## How to fix it
16
16
 
17
- 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.
17
+ 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'.
18
18
 
19
19
  ## Example
20
20
 
@@ -0,0 +1,23 @@
1
+ ---
2
+ id: errors/E1307
3
+ title: "E1307: Pipeline not built"
4
+ status: generated
5
+ since: "0.3"
6
+ summary: "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."
7
+ ---
8
+
9
+ # E1307: Pipeline not built
10
+
11
+ ## What happened
12
+
13
+ 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.
14
+
15
+ ## How to fix it
16
+
17
+ 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.
18
+
19
+ ## Example
20
+
21
+ ```text
22
+ 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.
23
+ ```
@@ -3,18 +3,18 @@ id: errors/E1420
3
3
  title: "E1420: Engine stopped"
4
4
  status: generated
5
5
  since: "0.2"
6
- summary: "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."
6
+ summary: "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."
7
7
  ---
8
8
 
9
9
  # E1420: Engine stopped
10
10
 
11
11
  ## What happened
12
12
 
13
- 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.
13
+ 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.
14
14
 
15
15
  ## How to fix it
16
16
 
17
- Remove the sketch's timers, event listeners and message handlers in its onDestroy callback, which runs when the engine stops.
17
+ 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.
18
18
 
19
19
  ## Example
20
20
 
@@ -32,7 +32,7 @@ Every error the engine throws is an `EngineError` with a code. Its message names
32
32
  | [E1208](E1208.md) | Invalid texture | A call that makes or updates a texture received something it cannot use. It can be an option the engine does not know, or an image without pixels or larger than the device takes. It can also be data that does not fit the texture's size and format, or numbers that make no color grading table. With a KTX2 file, it can be an option that the file cannot take, or an update of its texture. |
33
33
  | [E1209](E1209.md) | Too many textures | A material whose shader reads more textures than a WebGL2 shader stage has units. The engine numbers the textures that a program reads, and WebGL2 gives every stage at least 16 units, as many as the device reports. The lit shader reads most of them, so a custom material or add-on draw reaches the limit with its own textures, beside the maps and the shadows. |
34
34
  | [E1213](E1213.md) | Invalid setting | A call received a setting that it does not have, or a value that the setting does not take. Examples are a tone mapping that the engine does not know, a negative exposure, a grading control outside its range, and a built-in environment that the engine does not have. It also covers a glTF extension handler that names no extension, that another handler reads, or that returns a part without a mesh or a material. |
35
- | [E1214](E1214.md) | Invalid sketch option | 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. |
35
+ | [E1214](E1214.md) | Invalid sketch option | 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. |
36
36
  | [E1215](E1215.md) | Invalid custom WGSL | materials.shader(), post.addEffect(), post.set() or scene.setSkyLayer() received WGSL that it cannot draw with. The null3D Vite plugin compiles WGSL while it builds the project. The engine therefore takes only what the plugin compiled: a template literal after a /* wgsl */ comment, or a .wgsl file that a module imports. The WGSL of a custom material declares a surface function, a vertex offset or a lobe. A full shader instead has a @vertex entry point that takes an InstanceIn from null3d::mesh. An effect declares fn effect, a tone curve fn toneCurve, and a sky layer fn skyLayer. |
37
37
  | [E1216](E1216.md) | Invalid uniform or texture | A custom material's or effect's uniforms or textures did not match its WGSL. The uniforms option and set() take the names of the fields of struct Uniforms in the WGSL, each with a value of its type. A field cannot have the name of a standard value, such as color or roughness, because set() takes those too. The textures option takes the names of the WGSL's `var name: texture_2d<f32>;` and `var name: texture_2d_array<f32>;` declarations, each with a texture of the layers that its declaration takes. |
38
38
  | [E1217](E1217.md) | Invalid material option | A material factory or scene.createLines() received an option value that it does not take, such as an unknown alpha mode, blending or line mode. Custom materials refuse the 'weighted' blending, and take alpha to coverage or the hash mode only where their WGSL sets or reads the surface's alpha. A material that lets light through refuses the hash alpha mode and the weighted blending. A layered material, with a clear coat, a sheen, iridescence or anisotropy, refuses a light map, specular maps, and two textures for a pair of layer maps that glTF packs into one. It refuses a transmission or a thickness map only where one of its layer maps fills the array that the map samples: the clear coat's normal map and iridescence's thickness map fill the array that the transmission map samples, and the sheen's maps and the anisotropy map fill the array that the thickness map samples. A material with transmission refuses a thickness map beside a specular color map, whose sRGB texture never shares the thickness map's array, and other materials refuse those two maps. A material that lets light through to its other side refuses the specular maps, whose places its diffuse transmission maps take, a clear coat, a sheen and the weighted blending, and other materials refuse the diffuse transmission maps. A custom material refuses subsurfaceRadius, which only a standard material takes. A custom material whose WGSL declares a coverage function takes the mask mode, or the blend mode with the cutoff that its shadow caster tests. |
@@ -50,6 +50,7 @@ Every error the engine throws is an `EngineError` with a code. Its message names
50
50
  | [E1304](E1304.md) | GPU out of memory | The GPU had no room for a buffer or texture that the engine made after the start. The objects that use it draw wrong or not at all. The engine reports the first time this happens on each GPU device, and draws on. |
51
51
  | [E1305](E1305.md) | GPU rejected work | The GPU path refused a command that the engine gave it after the start, such as a buffer larger than the device allows. The objects that the command made or drew are missing, and the canvas can stay black. The engine reports the first time this happens on each GPU device, and draws on. |
52
52
  | [E1306](E1306.md) | Safari before 18 | The browser runs the WebKit engine of a Safari before 18, which null3D does not support. Every browser on iPhone and iPad runs WebKit, so Chrome, Edge and Firefox there count too. |
53
+ | [E1307](E1307.md) | Pipeline not built | 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. |
53
54
  | [E1401](E1401.md) | Not a sketch module | The module passed to createEngine as the sketch does not export a sketch as its default export. |
54
55
  | [E1402](E1402.md) | Engine core out of date | The engine core WebAssembly file lacks functions that the TypeScript side calls, so the two come from different builds. Development builds check this when the core loads. When null3D's own dev server serves the engine from a checkout of its repository, the check also compares the stamp of the Rust sources that the core was built from with the stamp of the checkout's sources. A core built before a merge or an edit of those sources then fails at once, before it can run with code that expects another core. |
55
56
  | [E1403](E1403.md) | Engine core not ready | An engine call ran before the engine core started in this worker, or the core started twice. |
@@ -69,7 +70,7 @@ Every error the engine throws is an `EngineError` with a code. Its message names
69
70
  | [E1417](E1417.md) | glTF feature not supported | A glTF file needs an extension that the engine does not read, as its extensionsRequired list says. When a foundation add-on reads that extension, the message names the package to import, such as "Import @null3d/splats, which reads it", and that add-on registers the handler that loads the file. Or a call asked a model for something it cannot give, such as instance batches of a model with no meshes. |
70
71
  | [E1418](E1418.md) | WebAssembly blocked by the page | The page's Content-Security-Policy does not allow WebAssembly, so the engine core, the KTX2 transcoder, the meshopt decoder or the Draco decoder could not compile. A policy allows it only when its script-src, or its default-src without a script-src, holds 'wasm-unsafe-eval'. |
71
72
  | [E1419](E1419.md) | Canvas held by another engine | createEngine() got a canvas that another engine still draws on, or a canvas whose drawing thread ended, so no engine can draw on it again. That thread ends when it fails, or when the canvas leaves the page. It also ends when the page goes away, or when the browser refuses memory for a new engine. A canvas serves one engine at a time. After destroy(), a new engine can start on the same canvas. |
72
- | [E1420](E1420.md) | Engine stopped | 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. |
73
+ | [E1420](E1420.md) | Engine stopped | 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. |
73
74
  | [E1421](E1421.md) | Unknown feature to preload | createEngine()'s preload option names a feature whose shaders the engine does not have. The features are ao, background, bloom, coat_sheen, coverage, cutout, dof, effect_groups, hash, lines, lod_fade, morph, occlusion, row_values, skinning, sky, sprites, transmission and views, and instance_index and texcoords for the engine's own tests. |
74
75
  | [E1422](E1422.md) | Engine file blocked by the page | The engine's files come from another origin than the page, such as a CDN, and the page's Content-Security-Policy blocks one of them. The engine starts each worker from a blob: address that imports the worker's script from that origin, and downloads its .wasm files from there. So the policy's worker-src must allow blob: and the other origin, and its script-src and connect-src must allow the other origin too. Firefox checks the modules that a worker imports against worker-src. |
75
76
  | [E1423](E1423.md) | Engine file without CORS | The engine's files come from another origin than the page, such as a CDN. One of them came without a CORS header, or did not download. A page loads a module or a .wasm file from another origin only when the response carries Access-Control-Allow-Origin. |
@@ -40,6 +40,8 @@ Give every file a CORS header, because the engine imports its modules and downlo
40
40
  Access-Control-Allow-Origin: *
41
41
  ```
42
42
 
43
+ Send each `.wasm` file with `Content-Type: application/wasm`, with nothing after it, and let browsers keep the files. Chrome then keeps the compiled engine core, and a repeat visit skips most of its compile ([Let Chrome keep the compiled core](hosting.md#let-chrome-keep-the-compiled-core)). The folder's file names hold no hash of their content. So upload each engine version under a prefix of its own, such as `https://cdn.example.com/null3d/0.1.0/`. Then serve its files with `Cache-Control: public, max-age=31536000, immutable`, so a repeat visit takes them from the browser's cache.
44
+
43
45
  ## Production and development entries
44
46
 
45
47
  The build holds the engine's entry point twice. Both draw the same scene. They differ in the checks that run and in the switches that the page's address can set.
@@ -51,7 +53,7 @@ The build holds the engine's entry point twice. Both draw the same scene. They d
51
53
 
52
54
  The development entry runs the same checks as the Vite dev server. A bad argument throws an error with its code, such as [E1203](../errors/E1203.md), and a call on a destroyed object throws [E1101](../errors/E1101.md). Debug drawing and debug views draw only in a development build, such as this entry ([Debugging](../guides/debugging.md#development-checks)). The entry also reads the switches in the page's address, such as `?gpu=`, `?hold=` and `?preset=` ([Switches for tests](../guides/testing.md#switches-for-tests)).
53
55
 
54
- In each frame, some of those checks read every static object and a share of the rows of static batches. So a large scene runs slower from the development entry than from the production entry. Time a page, judge its frame rate or compare it with three.js only from the production entry. A demo from the development entry is fine to try, but its frame rate is not what your users get.
56
+ In each frame, some of those checks read every static object and a share of the rows of static batches. So a large scene runs slower from the development entry than from the production entry. Time a page, judge its frame rate or compare it with another engine only from the production entry. A demo from the development entry is fine to try, but its frame rate is not what your users get.
55
57
 
56
58
  The production entry behaves like a production build from Vite and the plugin. The checks never run, and the page ignores address switches, so a link cannot change how it runs. Its files still hold the checks' code, which a Vite build removes from the download.
57
59
 
@@ -110,6 +112,20 @@ The sketch is a module at a `blob:` address, which the page makes from the strin
110
112
 
111
113
  The page imports the production entry. While you work on the page, change both `lib/index.js` addresses to `lib-dev/index.js`, so the development checks run and their errors name your mistakes.
112
114
 
115
+ ## Start the core early
116
+
117
+ The engine core is the start's largest file. A page built with Vite and the null3D plugin starts the core's download from a small script in its head. That script runs before the page's own scripts. A page with no build step adds that script itself, as the first tag in its head:
118
+
119
+ ```html
120
+ <script type="module" async src="https://cdn.example.com/null3d/lib/page/early-core.js"></script>
121
+ ```
122
+
123
+ The script picks the build that `createEngine` will pick, and starts its download. The engine takes that download when it starts, so the core does not wait for the page's own scripts. Take the script from the page's entry: `lib-dev/page/early-core.js` with the development entry.
124
+
125
+ The build loads the engine as many small modules, and each thread finds them in several rounds of imports, one after another. So a page with no build step starts more slowly than a Vite build. Serve the folder over HTTP/2 or HTTP/3, as most CDNs do, so each round's requests go out at once.
126
+
127
+ Give the folder the headers of [Make the CDN build](#make-the-cdn-build) above, so a repeat visit downloads none of it. [A fast start](../guides/start-time.md) gives the other steps.
128
+
113
129
  ## Import maps
114
130
 
115
131
  An import map gives the engine its package name, as a bundled project has it. Then the sketch and the page write `@null3d/engine`:
@@ -96,7 +96,7 @@ The module's default export is `defineSketch(setup)`. The engine calls `setup` o
96
96
 
97
97
  - The camera's `fov` is vertical, in degrees, and `target` turns the camera toward a point. `setActiveCamera` draws the scene from it.
98
98
  - The directional light's `direction` is the way its light travels, like sunlight. The ambient light lights every surface equally.
99
- - `geometry.box` takes the parameters and defaults of three.js's `BoxGeometry`. `materials.standard` shades with the physically based formulas of three.js's `MeshStandardMaterial`.
99
+ - `geometry.box` makes a box centered on its origin. Its `width`, `height` and `depth` are 1 by default. `materials.standard` shades with glTF's physically based metallic-roughness model.
100
100
  - `dynamic: true` says that the cube moves in most frames. Objects are static by default, and a static object costs nothing in a frame where it does not change.
101
101
 
102
102
  The sketch worker has no `document` and no `window`. The page keeps the HTML, and the two sides talk through [messages](../api/page.md).
@@ -50,7 +50,7 @@ Content-Security-Policy: default-src 'self'; script-src 'self' 'wasm-unsafe-eval
50
50
  ```
51
51
 
52
52
  - `script-src 'self' 'wasm-unsafe-eval'`: the engine core, the meshopt and Draco decoders and the KTX2 transcoder are WebAssembly, and a policy blocks WebAssembly unless it holds `'wasm-unsafe-eval'`. This keyword allows WebAssembly and no JavaScript `eval`. Without it, `createEngine` rejects with [E1418](../errors/E1418.md). The engine needs no `'unsafe-eval'`.
53
- - `worker-src 'self'`: the engine's sketch, render, job and probe workers, and the glTF loader's worker.
53
+ - `worker-src 'self'`: the engine's sketch, render, job and probe workers, and its helper workers. These are the glTF loader's worker, the panorama worker for HDR and EXR files and the task worker.
54
54
  - `connect-src`: the engine downloads its `.wasm` files and your sketch module from the page's origin, which `default-src 'self'` allows. Add the origin of each CDN that your sketch loads models or textures from.
55
55
 
56
56
  The engine needs no inline script and no inline style. It sets styles from code, which a policy does not block. A page's own inline `<style>` element needs `style-src 'self' 'unsafe-inline'`.
@@ -78,6 +78,8 @@ Access-Control-Allow-Origin: *
78
78
 
79
79
  It may name the page's origin in place of `*`. `Cross-Origin-Resource-Policy` alone does not serve, because the engine imports modules and downloads `.wasm` files in CORS mode. The HTML page still sends the two isolation headers. Without them the engine runs single-threaded, as on any host.
80
80
 
81
+ The CDN also sends each `.wasm` file with `Content-Type: application/wasm`, and lets browsers keep it. Chrome then keeps the compiled engine core between visits ([Let Chrome keep the compiled core](#let-chrome-keep-the-compiled-core)).
82
+
81
83
  A worker that starts from a `blob:` address follows the page's policy. Add these parts to the page's policy, with your CDN's origin:
82
84
 
83
85
  ```http
@@ -203,7 +205,12 @@ The engine's shader text compresses well with Brotli, which finds text that repe
203
205
  | gzip at level 6, a common setting for compression on the fly | about 167 KB |
204
206
  | Files as they are | 0.6 MB |
205
207
 
206
- Netlify, Cloudflare Pages and Vercel send Brotli to browsers that accept it. GitHub Pages sends gzip only. nginx sends gzip with its own module, and Brotli with the `ngx_brotli` module. With nginx, compress the files once when you deploy them, with `brotli -q 11` on each file in `dist/assets/`, and send the compressed files with `brotli_static on;`.
208
+ The engine core is the start's largest file. Its WebAssembly file takes 2.0 MB as it is, about 0.8 MB with gzip and about 0.6 MB with Brotli. Many servers compress only text, and send `.wasm` files as they are. To check a host, open the browser's network panel and compare the core's transferred size with its size.
209
+
210
+ Netlify, Cloudflare Pages and Vercel send Brotli to browsers that accept it. GitHub Pages sends gzip only. nginx sends gzip with its own module, and Brotli with the `ngx_brotli` module. With nginx, compress the files once when you deploy them, with `brotli -q 11` on each file in `dist/assets/`, the `.wasm` files included. Then send the compressed files with `brotli_static on;`. nginx's own gzip compresses only the types that `gzip_types` lists, so add `application/wasm` there.
211
+
212
+ The null3D Vite plugin's own servers compress with Brotli too, as [During development](#during-development) says. [A fast start](../guides/start-time.md) gives the other steps that shorten a start.
213
+
207
214
 
208
215
  ## Publish the third-party notices
209
216
 
@@ -213,23 +220,27 @@ The engine and some add-ons ship code from other projects, under their licenses.
213
220
 
214
221
  ## Caches between visits
215
222
 
216
- A repeat visit starts sooner when the browser keeps what the first visit downloaded and made. Five caches do that, and each keeps something else:
223
+ A repeat visit starts sooner when the browser keeps what the first visit downloaded and made. Seven caches do that, and each keeps something else:
217
224
 
218
225
  | Cache | What it keeps | Who sets it up |
219
226
  | --- | --- | --- |
220
227
  | The HTTP cache | The build's files: the engine, its workers, the shaders and your own files | The host, with the headers below |
228
+ | Chrome's code cache | The machine code that Chrome compiled from the engine core | Chrome, for each `.wasm` file that the host sends as `application/wasm` and that the HTTP cache keeps ([Let Chrome keep the compiled core](#let-chrome-keep-the-compiled-core)) |
221
229
  | A service worker's cache | Every file the game needs, so it plays with no network | Your game, as [Offline play](#offline-play) shows |
222
230
  | The cache of derived data | Data that the engine and add-ons make from files, such as transcoded KTX2 textures, and data that your sketch makes itself | The engine, with no setup. `assets.cache` gives your sketch its own namespace ([Caching](../api/assets.md#caching)) |
223
231
  | The stored preset check | The quality preset that the device held | The engine, in `localStorage` ([Quality presets](../concepts/quality-presets.md#repeat-visits)) |
232
+ | The stored pipeline list | Which GPU pipelines the first frame needed, so the next start builds them while it loads | The engine, in `localStorage` ([Loading screens](../guides/loading-screens.md#repeat-visits)) |
224
233
  | The back/forward cache | The whole running page, for the browser's back and forward buttons | The browser ([Content pages](../guides/content-pages.md#second-visits-and-navigation)) |
225
234
 
226
- The first two keep files, so a repeat visit downloads less. The cache of derived data keeps the work done on those files, so a repeat visit skips it. A page whose KTX2 files are all in it never downloads the transcoder. The browser can delete any of them to free space, and the engine then downloads or makes the data again.
235
+ The HTTP cache and a service worker's cache keep files, so a repeat visit downloads less. The code cache and the cache of derived data keep the work done on those files, so a repeat visit skips it. A page whose KTX2 files are all in it never downloads the transcoder. The browser can delete any of them to free space, and the engine then downloads or makes the data again.
227
236
 
228
237
  ## Let browsers keep the build files
229
238
 
230
239
  Every engine thread loads its own copy of its script and of the core's loader. When the host lets the browser keep those files, each copy after the first comes from the cache. When the host asks the browser to check each file again, the copies wait for one another, one round trip each. A computer with many cores starts many threads, and on a slow phone connection one round trip can take more than half a second.
231
240
 
232
- With worker threads, the page also downloads the sketch module while the engine core downloads. The sketch worker then takes the module from the cache when it runs it. That saves a round trip only when the host lets the browser keep the file.
241
+ With worker threads, the sketch worker imports the sketch module while the engine core downloads. The page also downloads the job worker's script then, and the job workers that start later take it from the cache. That saves a round trip only when the host lets the browser keep the file.
242
+
243
+ A sketch that names its files in the `downloads` option of `defineSketch` starts them as soon as its module has loaded ([The download list](../api/sketch.md#the-download-list)). Over HTTP/1.1 a browser opens at most six connections to one server, and each large file holds one until it has arrived. So two listed files download at a time, and four at most while the setup's loads wait for them. The engine's own files, such as the first frame's shaders, then still find a free connection. Over HTTP/2 every request shares one connection. The listed files ask for low priority there, so a server that follows priorities sends the engine's own files first.
233
244
 
234
245
  Vite names the files in `assets/` with a hash of their content, so a file under a given name never changes. Serve them with a long cache lifetime, and serve the HTML page so that browsers check it each time:
235
246
 
@@ -242,6 +253,19 @@ Vite names the files in `assets/` with a hash of their content, so a file under
242
253
 
243
254
  That is the `_headers` form for Netlify and Cloudflare Pages. In nginx, add `add_header Cache-Control "public, max-age=31536000, immutable" always;` inside a `location /assets/` block.
244
255
 
256
+ Send no `Vary: Origin` header with the build's files when they come from the page's own origin. A worker's request for a module carries an `Origin` header that the page's own download of the same file does not. With `Vary: Origin`, the browser then checks the file again, one round trip, instead of taking its copy. A CDN that answers with `Access-Control-Allow-Origin: *` needs no `Vary: Origin` either.
257
+
258
+ ### Let Chrome keep the compiled core
259
+
260
+ The engine core is about 2 MB of WebAssembly, and the browser compiles it as it downloads. Chrome then keeps the machine code that it compiled, beside the file in the HTTP cache. A repeat visit that takes the core from the HTTP cache reads that code and skips most of the compile. The engine loads its other `.wasm` files, such as the KTX2 transcoder, the same way. Chrome keeps the code only when the host does both of these:
261
+
262
+ - Send each `.wasm` file with `Content-Type: application/wasm`, with nothing after it. Chrome refuses a parameter such as `; charset=utf-8`. Most hosts send this type already. To check, read the headers with `curl -I` and the address of a `.wasm` file in your build's `assets/` folder.
263
+ - Let the HTTP cache keep the file, as the headers above do. A file served with `no-cache` keeps its code too, when the server answers the browser's check with `304 Not Modified`. A file served with `no-store` keeps nothing.
264
+
265
+ With another type the engine still starts: it compiles the file as it downloads, but Chrome compiles it again on each visit.
266
+
267
+ Chrome writes the code while the page runs, not when the download ends. It first compiles each function quickly, and optimizes the functions that run most. Once it has new optimized code, it waits until no further function has been optimized for two seconds, and then writes it. With 1 MB of new optimized code, it writes at once. The engine keeps optimizing for its first seconds, so a repeat visit gains only after an earlier visit ran the engine for a while. On the engine's test page in Chrome 158, the write came about 6 seconds after the first frame. A repeat visit that read it compiled none of the core again, and its optimizing work fell from about 110 ms to 30 ms. In the engine's startup benchmark at full speed, a repeat visit that read the compiled core finished its first frame at 160 ms. Without it, the first frame took 176 to 180 ms. It compiled 3 of the core's functions again, against 273. Chrome 156 and earlier have a fault in this wait, which can put the write off for up to about half an hour. So they rarely keep the code. Chrome 157 fixed it.
268
+
245
269
  ## Offline play
246
270
 
247
271
  A game can play with no network after its first visit. Its own service worker caches the page and the build's files, and answers the page's requests from that cache. null3D ships no service worker. A production build with the null3D Vite plugin writes a list of the build's files for one, `null3d-files.json`, beside the page:
@@ -303,14 +327,24 @@ async function update() {
303
327
  }
304
328
  ```
305
329
 
306
- The page registers it in production builds only, so the dev server's pages stay out of the cache:
330
+ The page registers it once the first frame has drawn, and in production builds only. The worker's downloads then leave the connection to the start's own files, and the dev server's pages stay out of the cache:
307
331
 
308
332
  ```ts
309
- if (import.meta.env.PROD) void navigator.serviceWorker?.register('./sw.js');
333
+ // page.ts, after createEngine
334
+ engine.firstFrame.then(
335
+ () => {
336
+ if (import.meta.env.PROD) void navigator.serviceWorker?.register('./sw.js');
337
+ },
338
+ () => {}, // the engine stopped before its first frame: cache nothing
339
+ );
310
340
  ```
311
341
 
342
+ A worker that starts with the page shares the connection with every file of the start, so the first frame comes later. Over HTTP/1.1, a long list holds every connection the browser opens to the host.
343
+
312
344
  Put the game's own files that the build does not hold, such as its models in `public/`, in the list that `cache.addAll` takes. On each visit with a network, the worker checks the list. When the build changed, it caches the new build in one step and deletes the old caches. The new build then runs from the next visit.
313
345
 
346
+ `cache.addAll` keeps no file until every file of its list has arrived. A visitor who leaves before then starts the whole list again on the next visit, and each such visit shares its connection with the start. So keep the list to the files that the game needs. A build of many pages lists the files of every page in `start`.
347
+
314
348
  ### Keep the page isolated
315
349
 
316
350
  The cache keeps each response with its headers, so the cached page keeps the two isolation headers and the engine starts threaded offline. A service worker that makes a new response for the page, instead of one from `fetch` or the cache, must copy those headers. Without them the page loses its isolation, and the engine starts its single-threaded build with no error. A development build of the engine warns in the console when a service worker controls a page that is not isolated. To check a production build, reload the page offline and read `crossOriginIsolated` in the console.
@@ -329,6 +363,8 @@ The engine keeps its [cache of derived data](../api/assets.md#the-cache-of-deriv
329
363
 
330
364
  The null3D Vite plugin sends both isolation headers on every response from `vite` and `vite preview`. That includes the `.wasm` files and the worker scripts. `vite preview` also lets the browser keep the hashed files in `assets/`, as a well-set host does.
331
365
 
366
+ Both servers compress what a phone or tablet on the network downloads, with Brotli, or with gzip for a browser that lacks Brotli. The dev server compresses its answers to every request from another device, and leaves requests over `localhost` as they are. The preview compresses the build's scripts, WebAssembly, glTF models and other text for every request. After its first answers, it compresses each file again at Brotli's best level while no request waits. Later visits then download the same sizes as from a host that compresses its files ahead of time.
367
+
332
368
  Shared memory and WebGPU also need a secure context: HTTPS, or `localhost`. WebGPU, and so the High and Ultra presets, only exist there. A page served over plain HTTP on a network address silently falls back to WebGL2 at Medium. An Android phone connected by USB can reach your computer's `localhost` through `adb reverse tcp:5173 tcp:5173`.
333
369
 
334
370
  To test on a phone or tablet over your local network, serve HTTPS with a local certificate. Make one with [mkcert](https://github.com/FiloSottile/mkcert), for `localhost` and your computer's network name:
@@ -345,9 +381,13 @@ Keep the `certs` folder out of version control, because it holds a private key.
345
381
  export default defineConfig({ plugins: [null3d({ https: true, certDir: 'certs' })] });
346
382
  ```
347
383
 
348
- The plugin serves this HTTPS over HTTP/1.1. Over HTTP/2, Safari on an iPad sometimes stops while a worker loads its modules. The dev server sends each module as its own file, and every engine thread loads its own copy of each.
384
+ The plugin serves this HTTPS over HTTP/1.1. Over HTTP/2, Safari on an iPad sometimes stops while a worker loads its modules. The dev server sends each module as its own file, and every engine thread loads its own copy of each. So a page asks for hundreds of files, and HTTP/1.1 sends six at a time. For other browsers, the plugin's `http2: true` option serves HTTP/2, which sends every request at once.
385
+
386
+ The device must trust mkcert's root certificate. `mkcert -CAROOT` prints its folder. Copy `rootCA.pem` to the device and install it. On an iPhone or iPad, also turn on full trust in Settings > General > About > Certificate Trust Settings.
387
+
388
+ A browser that has not been given the root certificate shows a warning. You can accept it and continue, but then Chrome keeps no file from the site in its cache. Every load downloads every file again, so each reload is as slow as a first visit, and every timing of a start is wrong. Over a simulated phone connection, a reload of the dev server took 30 seconds instead of 15. Install the root certificate on every device that tests a page.
349
389
 
350
- The device must trust mkcert's root certificate. `mkcert -CAROOT` prints its folder. Copy `rootCA.pem` to the device and install it. On an iPhone or iPad, also turn on full trust in Settings > General > About > Certificate Trust Settings. A browser that has not been given the root certificate shows a warning: open the address over HTTPS and accept the certificate warning to continue.
390
+ The dev server also asks the browser to check every module on each load. So time a start only on a production build that a host serves, as [A fast start](../guides/start-time.md#test-a-production-build) explains.
351
391
 
352
392
  ## What isolation changes
353
393
 
@@ -357,3 +397,4 @@ The device must trust mkcert's root certificate. `mkcert -CAROOT` prints its fol
357
397
 
358
398
  - [Architecture: threads and the frame](../concepts/architecture.md): what the worker threads do.
359
399
  - [GPU tiers and backends](../concepts/backends.md): which browsers get WebGPU.
400
+ - [A fast start](../guides/start-time.md): what a host, a page and a sketch do for a fast start.
@@ -8,9 +8,9 @@ summary: "The npm packages; the Vite plugin, which every Vite build needs; packa
8
8
 
9
9
  # Install null3D
10
10
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. The API is experimental, so it can still change between versions. The packages are not on npm until the 0.1 release, so the install commands below fail before then.
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
- null3D installs from npm like any other library, and you import it in your code as you would import `three`. You need no command-line tool to build or run a null3D sketch. To try the engine in one HTML file with no install, see [Try null3D from a CDN](cdn.md).
13
+ null3D installs from npm and imports like any other library. You need no command-line tool to build or run a null3D sketch. To try the engine in one HTML file with no install, see [Try null3D from a CDN](cdn.md).
14
14
 
15
15
  The commands on these pages use [Bun](https://bun.sh) 1.4.3 or newer. Older Bun can drop its link to the browser that `bunx @null3d/cli test` and the tool's other browser commands drive, and the command then waits forever. npm, pnpm and Yarn work too, with their own install and run commands.
16
16
 
@@ -25,7 +25,7 @@ bun add -d vite @null3d/vite-plugin
25
25
  | --- | --- |
26
26
  | `@null3d/engine` | The API as JavaScript with TypeScript declarations, the worker entry points, both WebAssembly builds and these docs |
27
27
  | `@null3d/vite-plugin` | The build and dev server setup that null3D needs, and the shader compiler |
28
- | `@null3d/controls` | Orbit, map, fly and first-person camera controls, for sketches that use them |
28
+ | `@null3d/controls` | Orbit, map, fly and first-person camera controls, and gizmos that move, turn and scale objects, for sketches that use them |
29
29
 
30
30
  Add the controls when a sketch uses them:
31
31
 
@@ -43,15 +43,16 @@ import null3d from '@null3d/vite-plugin';
43
43
  export default defineConfig({ plugins: [null3d()] });
44
44
  ```
45
45
 
46
- Every Vite build of a null3D project needs the plugin, for the dev server and for production. The plugin does these jobs, which a three.js project does not need:
46
+ Every Vite build of a null3D project needs the plugin, for the dev server and for production. The plugin does these jobs:
47
47
 
48
48
  - Sends the two headers that let worker threads share memory, on the dev server and on `vite preview`. [Hosting and cross-origin isolation](hosting.md) explains them.
49
+ - Compresses what `vite preview` sends with Brotli, `.wasm` included, and what the dev server sends to another device, such as a phone. Its `https` option serves HTTPS on your network, and its `http2` option serves that over HTTP/2 ([During development](hosting.md#during-development)).
49
50
  - Compiles your sketch file for the sketch worker, and ships the engine's WebAssembly core with the production build. The build stops with an error if the installed engine lacks its core. Each built page that loads the engine gets a small script of its own, which starts the core's download as soon as the page arrives.
50
51
  - Compiles the WGSL in your code, in `.wgsl` files and in strings tagged `/* wgsl */`, for WebGPU and WebGL2. A shader error stops Vite with its file, line and column. Beside each `.wgsl` file, the plugin writes a TypeScript declaration that holds the types of the file's uniforms. It compiles on worker threads, so the dev server goes on serving while a shader compiles. On the dev server, a shader that you change reaches the running page without a reload. [Custom shaders](../guides/custom-shaders.md) explains both forms and hot reload.
51
52
  - Keeps the engine's development checks in the dev server and removes them from production builds. Without the plugin, nothing tells the engine's code which build it is in, so it runs as a development build. It then runs every check and reads the page's address switches. This also holds for another bundler, and for a page that imports the package's files with no bundler. The [CDN build](cdn.md#production-and-development-entries) has a production entry for such pages.
52
53
  - Builds the engine's workers as ES modules, so that they share the shader files. Without the plugin, Vite builds each worker as one classic script that holds every shader file. Each worker is then about 34 MB, and the page downloads them all at its start. The plugin warns if another setting builds workers in another format.
53
- - In each worker, starts the files that a file loaded on demand imports together with that file, as Vite does on the page. Without this, a worker asks for them only once the file has arrived, one round trip later. The engine's workers load the renderers of their GPU path this way.
54
- - Writes the notices of the third-party code that the engine ships beside the page in each production build. [Hosting](hosting.md#publish-the-third-party-notices) says what to do with them.
54
+ - In each worker, starts the files that a file loaded on demand imports together with that file, as Vite does on the page. Without this, a worker asks for them only once the file has arrived, one round trip later. The engine's workers load the renderers of their GPU path this way. The built file of your sketch, and of each add-on's task, also names every file that it reaches through other files. So the worker asks for all of them as soon as that file arrives, instead of one round trip for each step of the chain.
55
+ - Writes the notices of the third-party code that the engine and the add-ons ship beside the page in each production build. [Hosting](hosting.md#publish-the-third-party-notices) says what to do with them.
55
56
  - Writes the list of the build's files, `null3d-files.json`, beside the page in each production build. A game's service worker caches the files of that list for offline play, as [Hosting](hosting.md#offline-play) shows.
56
57
  - Keeps each file of the engine a file of its own: the workers' scripts, the WebAssembly and the shader files. Vite would otherwise turn a small file into a `data:` address, which a strict Content-Security-Policy blocks. Your own small files keep Vite's setting.
57
58
 
@@ -93,7 +94,7 @@ All `@null3d/*` packages share one version number, because the WebAssembly core
93
94
 
94
95
  ## The `null3d` command
95
96
 
96
- The `null3d` command, in the `@null3d/cli` package, is optional. It does jobs that a bundler does not do: image tests and screenshots in a headless browser, and benchmarks of a production build. Install it when you need one of them, and run it as `bunx @null3d/cli` followed by the command:
97
+ The `null3d` command, in the `@null3d/cli` package, is optional. It does jobs that a bundler does not do, such as image tests and screenshots in a headless browser and benchmarks of a production build. It also connects a coding agent to the live scene. Install it when you need one of them, and run it as `bunx @null3d/cli` followed by the command:
97
98
 
98
99
  ```sh
99
100
  bun add -d @null3d/cli
@@ -40,6 +40,8 @@ The engine downloads only the addresses that you give it:
40
40
  - `assets.loadTexture`, `assets.loadGltf`, `assets.loadBinary`, `assets.loadJson` and `assets.loadImageBitmap` download the address that you pass.
41
41
  - A glTF file names more addresses inside it, for its buffers, images and extensions. The engine downloads those too. They may be on another origin, which must allow the page to read them.
42
42
  - `preload` downloads the features that you list, when you call it.
43
+ - The `downloads` option of `defineSketch` downloads the files that it names, as soon as the sketch's module has loaded. A recording, a replay and hold mode download them only at their loads.
44
+ - `@null3d/sound` downloads the sound files that the sketch names, each once, when the sound starts. It downloads its own mixer module, about 17 KB, from beside its code at the same time. So the files do not wait for the mixer.
43
45
  - `@null3d/splats` downloads the SPZ file that you pass. A streamed cloud is fetched as its index and then only the chunk files that the view asks for, so a large cloud appears without the whole file. No other address is contacted.
44
46
 
45
47
  A demo that loads a model makes these same calls. The file's address is the demo's choice.
@@ -66,15 +68,21 @@ Set `NULL3D_ENGINE_SHADERS` to a folder that holds the engine's generated shader
66
68
 
67
69
  ## The command-line tool
68
70
 
69
- `bunx @null3d/cli` contacts no server of its own. It serves the page from a server on the same machine, and it drives a browser on that machine. When Playwright's browser is missing, the tool prints the command that installs it. You run that command yourself.
71
+ `bunx @null3d/cli` contacts no server of its own. It serves the page from a server on the same machine, and it drives a browser on that machine, unless you give `mcp` other addresses. When Playwright's browser is missing, the tool prints the command that installs it. You run that command yourself.
70
72
 
71
- To draw on your computer's GPU, the tool uses one pinned version of Chrome for Testing. On first use it downloads that version once, from Google's Chrome for Testing releases on `storage.googleapis.com`. The tool records the SHA-256 hash of each platform's archive, and checks the download against it before it unpacks it. It deletes an archive with another hash, and stops with [E1437](../errors/E1437.md). It keeps the checked build in a cache folder that every project on the computer shares, with the hash that it checked. A copy in that folder without that record downloads again. The [command-line tool's page](../cli/null3d.md#chrome-for-testing) says where the folder is. The tool makes no other request to that host, and a page never makes it. When the `CI` variable is set, the tool draws on the software GPU and downloads nothing. `NULL3D_CHROME=installed` draws with the installed Google Chrome and also downloads nothing.
73
+ To draw on your computer's GPU, the tool uses one pinned version of Chrome for Testing. On first use it downloads that version once, from Google's Chrome for Testing releases on `storage.googleapis.com`. The tool records the SHA-256 hash of each platform's archive, and checks the download against it before it unpacks it. It deletes an archive with another hash and installs nothing ([E1437](../errors/E1437.md)). The command then draws with the installed Google Chrome, or it stops when `NULL3D_CHROME=testing` is set. It keeps the checked build in a cache folder that every project on the computer shares, with the hash that it checked. A copy in that folder without that record downloads again. The [command-line tool's page](../cli/null3d.md#chrome-for-testing) says where the folder is. The tool makes no other request to that host, and a page never makes it. When the `CI` variable is set, the tool draws on the software GPU and downloads nothing. `NULL3D_CHROME=installed` draws with the installed Google Chrome and also downloads nothing.
72
74
 
73
75
  `check-addon` reads the allocations of an add-on's own code by asking the browser it started for a
74
76
  heap profile. That browser listens on a loopback address on this machine, and the tool talks to it
75
77
  over that address and its debugging socket. Nothing leaves the machine, and no address is a server
76
78
  the tool chooses.
77
79
 
80
+ The `mcp` command talks to the agent over its standard input and output. By default it serves the
81
+ page and drives the browser on this machine, as `shot` does. The `--url` option opens the dev server
82
+ at the address that you give. The `--connect` option attaches to the Chrome debugging endpoint at the
83
+ address that you give. Either address may be on another machine. The command contacts no other
84
+ address of its own choice. With `--connect` it starts no browser, so it downloads no Chrome.
85
+
78
86
  A command that builds the page also runs the build's one download, the engine's generated shader modules, as the section above says. Set `NULL3D_ENGINE_SHADERS` on that command to keep the tool's whole run off every network.
79
87
 
80
88
  ## Check the claim
@@ -3,12 +3,12 @@ id: getting-started/project-structure
3
3
  title: Project structure
4
4
  status: experimental
5
5
  since: "0.3"
6
- summary: "Starting from the `empty` template with `bunx @null3d/cli create`; page.ts, sketch.ts, AGENTS.md and the agent hook; what runs where."
6
+ summary: "Starting from the `empty`, `product` or `game` template with `bunx @null3d/cli create`; page.ts, sketch.ts, AGENTS.md and the agent hook; what runs where."
7
7
  ---
8
8
 
9
9
  # Project structure
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. The `empty` template is the only template today.
11
+ > Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
12
 
13
13
  ```mermaid
14
14
  flowchart LR
@@ -20,12 +20,20 @@ flowchart LR
20
20
  sketch -- "scene data" --> draw["Render worker<br/>draws the canvas"]
21
21
  ```
22
22
 
23
- `bunx @null3d/cli create` writes a new project from a template. Start with the `empty` template, then add the scene that your app needs.
23
+ `bunx @null3d/cli create` writes a new project from a template. Start with the template closest to your app, then change its scene.
24
+
25
+ | Template | What its scene shows |
26
+ | --- | --- |
27
+ | `empty` | A cube that turns, lit by a directional light and an ambient light. It is the smallest project, for a scene of your own. |
28
+ | `product` | A product viewer: shapes from `@null3d/geometry` with glazed, metal, wood and cloth materials on a turntable. A soft room light, shadows on a shadow catcher, the Neutral tone curve, and orbit controls with damping and limits. |
29
+ | `game` | A small game: a player that keys, a gamepad or a dragged finger moves, gems to pick up, rocks in instance batches, a follow camera and a score on the page. |
30
+
31
+ Each template holds the same project files, which the next sections list. The `product` template also pins `@null3d/controls` and `@null3d/geometry`.
24
32
 
25
33
  ## Make a project
26
34
 
27
35
  ```sh
28
- bunx @null3d/cli create my-game
36
+ bunx @null3d/cli create my-game --template game
29
37
  cd my-game
30
38
  bun install
31
39
  bunx vite
@@ -35,7 +43,7 @@ bunx vite
35
43
 
36
44
  | Option | Effect | Without it |
37
45
  | --- | --- | --- |
38
- | `--template <name>` | The template to copy | `empty` |
46
+ | `--template <name>` | The template to copy: `empty`, `product` or `game` | `empty` |
39
47
 
40
48
  The folder must not exist, or it must be empty. A folder with files stays as it is, and the command stops.
41
49
 
@@ -49,6 +57,7 @@ The folder must not exist, or it must be empty. A folder with files stays as it
49
57
  | `vite.config.ts` | Vite with the null3D plugin, which sends the headers that the workers need. |
50
58
  | `tsconfig.json` | The TypeScript settings that `bunx @null3d/cli test` checks the project with. |
51
59
  | `package.json` | The project's name, scripts and packages. Every `@null3d/*` package takes one version. |
60
+ | `.gitignore` | The folders that git skips: `node_modules/`, `dist/`, `test-results/` and `.vite/`. |
52
61
  | `AGENTS.md` | The rules for an AI agent that works in the project. |
53
62
  | `.agent/agent-hook.mjs` | The hook that checks the rules before each command and each edit. |
54
63
  | `.claude/settings.json` | The Claude Code settings that run the hook. |
@@ -64,6 +73,6 @@ Claude Code runs the hook through `.claude/settings.json`, and Codex runs it thr
64
73
 
65
74
  The hook refuses three commands, so they do not run. They are a command that waits with `sleep`, one that stops a process by name, and one that follows a log. The message gives the fix.
66
75
 
67
- The hook flags three source rules and lets the edit go on. It flags an object, array or string made in `onUpdate`. It flags a DOM name in the sketch module. It flags an import of a name that the installed engine does not export. A planned API does not exist, so its name is absent from the installed declarations. The message names the file, the line and the fix.
76
+ The hook flags three source rules and lets the edit go on. It flags an object, array or string made in `onUpdate`. It flags a DOM name in the sketch module. It flags an import of a name that the installed engine does not export. The message names the file, the line and the fix.
68
77
 
69
78
  The hook takes every rule from `@null3d/cli/agent-rules`. That module holds each rule and its message once, so a project and any other null3D tool agree. The hook reads the module from the installed packages, and `bun install` writes them. Before that install, the hook cannot check a call. It tells the agent to install the packages, and the call goes on.
@@ -16,19 +16,20 @@ Some null3D packages ship code from other projects, as the original file or as a
16
16
 
17
17
  | Package | Third-party code | License | Where | Notices |
18
18
  | --- | --- | --- | --- | --- |
19
- | `@null3d/engine` | Basis Universal 2.50 with Zstandard, meshoptimizer 1.3.0, Draco 1.5.7, three.js 0.186.1, TinyEXR and OpenEXR, Linearly transformed cosines, Filament, KinoBokeh and Unity's post-processing stack v1, AMD FidelityFX FSR 1 and SSSR, Qualcomm Snapdragon GSR 1, and the core's Rust crates | Apache License 2.0, BSD 3-Clause and MIT | `vendor/`, the shader modules, `panorama-worker.js`, `dist/wasm` | `THIRD-PARTY-NOTICES.txt` |
19
+ | `@null3d/engine` | Basis Universal 2.50 with Zstandard, meshoptimizer 1.3.0, Draco 1.5.7, three.js 0.186.1, TinyEXR and OpenEXR, Linearly transformed cosines, Filament, KinoBokeh and Unity's post-processing stack v1, AMD FidelityFX FSR 1 and SSSR, Qualcomm Snapdragon GSR 1, SMAA 1x, and the core's Rust crates | Apache License 2.0, BSD 3-Clause and MIT | `vendor/`, the shader modules, `panorama-worker.js`, `dist/wasm` | `THIRD-PARTY-NOTICES.txt` |
20
20
  | `@null3d/cli` | Basis Universal 2.50 with Zstandard, ufbx 0.23.1, the `exr` and `lebe` crates, three.js 0.186.1, and the asset module's other crates | Apache License 2.0, BSD 3-Clause and MIT | `vendor/`, `dist/assets.wasm` | `THIRD-PARTY-NOTICES.txt` |
21
- | `@null3d/vite-plugin` | naga and naga-types 30.0.1, naga_oil 0.23.0, serde, serde_json, toml, the shader compiler's other crates, and the engine shaders it embeds: three.js 0.186.1, Filament, KinoBokeh and Unity's post-processing stack v1, AMD FidelityFX, Qualcomm Snapdragon GSR 1 | MIT, Apache License 2.0, BSD 3-Clause and Zlib | `dist/shader-compiler.wasm` | `THIRD-PARTY-NOTICES.txt` |
21
+ | `@null3d/vite-plugin` | naga and naga-types 30.0.1, naga_oil 0.23.0, serde, serde_json, toml, the shader compiler's other crates, and the engine shaders it embeds: three.js 0.186.1, Filament, KinoBokeh and Unity's post-processing stack v1, AMD FidelityFX, Qualcomm Snapdragon GSR 1, SMAA 1x | MIT, Apache License 2.0, BSD 3-Clause and Zlib | `dist/shader-compiler.wasm` | `THIRD-PARTY-NOTICES.txt` |
22
22
  | `@null3d/controls` | three.js 0.186.1, the math and the option names of its controls | MIT | `lib/index.js` | `THIRD-PARTY-NOTICES.txt` |
23
23
  | `@null3d/geometry` | three.js 0.186.1, its generators, curves, paths and shapes; earcut 3.0.2 | MIT and ISC | `lib/index.js` | `THIRD-PARTY-NOTICES.txt` |
24
24
  | `@null3d/three-compat` | three.js 0.186.1, its tone curves and its outline pass | MIT | `lib/index.js` | `THIRD-PARTY-NOTICES.txt` |
25
25
  | `@null3d/grass` | None, its own code | None | `lib/index.js` | None |
26
26
  | `@null3d/impostors` | None, its own code | None | `lib/index.js` | None |
27
27
  | `@null3d/particles` | None, its own code | None | `lib/index.js` | None |
28
- | `@null3d/splats` | None, its own code, which reads Niantic's published SPZ format | None | `lib/index.js` | None |
29
- | `@null3d/terrain` | None, its own code | None | `lib/index.js` | None |
28
+ | `@null3d/sound` | The Rust core library and libm 0.2.16 in its mixer, beside its own code | MIT | `dist/sound.wasm` | `THIRD-PARTY-NOTICES.txt` |
29
+ | `@null3d/splats` | The Rust core library and libm 0.2.16 in its selection, beside its own code, which reads Niantic's published SPZ format | MIT | `dist/splats.wasm` | `THIRD-PARTY-NOTICES.txt` |
30
+ | `@null3d/terrain` | The Rust core library and libm 0.2.16 in its builder, beside its own code | MIT | `dist/terrain.wasm` | `THIRD-PARTY-NOTICES.txt` |
30
31
  | `@null3d/water` | None, its own code | None | `lib/index.js` | None |
31
- | `@null3d/wind` | None, its own code | None | `lib/index.js` | None |
32
+ | `@null3d/wind` | The Rust standard library in its field module, beside its own code | MIT | `dist/wind.wasm` | `THIRD-PARTY-NOTICES.txt` |
32
33
 
33
34
  The null3D packages themselves are offered under the MIT License or the Apache License 2.0. A production build writes the notices of every package that a page ships into `null3d-third-party-notices.txt`.
34
35
 
@@ -50,7 +51,7 @@ The null3D packages themselves are offered under the MIT License or the Apache L
50
51
  | TinyEXR and OpenEXR, whose code the EXR decoders follow | BSD 3-Clause | `panorama-worker.js` |
51
52
  | Linearly transformed cosines, the area light tables | BSD 3-Clause | `vendor/ltc` |
52
53
  | SMAA, the subpixel morphological anti-aliasing that smooths the moment transparency layer's edges | MIT | the renderer's moment layer tables and shaders |
53
- | The Rust crates of the core: the standard library, wasm-bindgen, bumpalo, cfg-if, once_cell and dlmalloc | MIT or Apache License 2.0 | `dist/wasm` |
54
+ | The Rust crates of the core: the standard library, wasm-bindgen, cfg-if, once_cell and dlmalloc | MIT or Apache License 2.0 | `dist/wasm` |
54
55
 
55
56
  The full texts are in the engine's `THIRD-PARTY-NOTICES.txt`.
56
57
 
@@ -80,6 +81,7 @@ The command-line tool and the Vite plugin put no code in a page. Their packages
80
81
  | The engine shaders in the module: KinoBokeh and Unity's post-processing stack v1 | MIT |
81
82
  | The engine shaders in the module: AMD FidelityFX FSR 1's RCAS and SSSR's ray march | MIT |
82
83
  | The engine shaders in the module: Qualcomm Snapdragon GSR 1 | BSD 3-Clause |
84
+ | The engine shaders in the module: SMAA 1x's three steps | MIT |
83
85
 
84
86
  ## The example add-ons
85
87
 
@@ -82,7 +82,7 @@ Motion that starts by itself and lasts more than five seconds needs a way to sto
82
82
 
83
83
  ## Loading and errors
84
84
 
85
- - Give the loading indicator `role="progressbar"` and set `aria-valuenow` from the load progress. Never let the value move back.
85
+ - Give the loading indicator `role="progressbar"` and set `aria-valuenow` from the load progress. Within a phase, never let the value move back. When a new phase starts, name it in `aria-valuetext` ([Loading screens](loading-screens.md#show-progress-on-the-page)).
86
86
  - Remove the indicator when `engine.firstFrame` resolves, so the user never waits in front of a blank canvas.
87
87
  - `createEngine` rejects when the browser cannot run the engine. Show text that says so, and what the user can still do, or an image with a text alternative.
88
88
 
@@ -62,7 +62,7 @@ Opt a mesh out with `levels: false` only where levels are wrong for it, and say
62
62
 
63
63
  | The mesh | Why it takes no levels | In the engine's add-ons |
64
64
  | --- | --- | --- |
65
- | A shader gives it its shape or its place | The levels would simplify a shape that never draws | Water surfaces, grass tufts, splat parts, floating leaves |
65
+ | A shader gives it its shape or its place | The levels would simplify a shape that never draws | Water surfaces, grass tufts, splat parts |
66
66
  | It has a level system of its own | The two systems would switch apart | Terrain blocks, which are the ground's quadtree and morph toward their parent block |
67
67
  | It is the far stand-in of other meshes | It is already the coarsest level | Impostor cards, merged far cells |
68
68
  | It keeps one size on the screen | Its levels would never switch | Gizmo handles |
@@ -129,7 +129,8 @@ Without a page, the browser gates are skipped with a reason, and the other gates
129
129
  ## Run the check
130
130
 
131
131
  ```sh
132
- bunx @null3d/cli check-addon addons/splats
132
+ bunx @null3d/cli check-addon # the add-on in the current folder
133
+ bunx @null3d/cli check-addon packages/my-addon
133
134
  ```
134
135
 
135
136
  It prints one line for each gate, and exits with 1 when one fails:
@@ -3,7 +3,7 @@ id: guides/agents
3
3
  title: Working with AI agents
4
4
  status: experimental
5
5
  since: "0.1"
6
- summary: "Installing the null3D skills in Claude Code, claude.ai and other agent tools; docs by ID; the test loop; the MCP server and AGENTS.md in templates (0.3)."
6
+ summary: "Installing the null3D skills in Claude Code, claude.ai and other agent tools; docs by ID; the test loop; the MCP server and the in-page inspector."
7
7
  ---
8
8
 
9
9
  # Working with AI agents
@@ -47,7 +47,7 @@ To install by hand, copy each skill's folder from `.claude/skills/` in the relea
47
47
 
48
48
  ## Docs by ID
49
49
 
50
- Every docs page has an ID, such as `concepts/architecture`: its path under `docs/` without `.md`. The skills name pages by ID, and each page's status says whether its API exists yet. Agents never use an API whose page is `planned`, or a part that the note on an experimental page says is not built yet.
50
+ Every docs page has an ID, such as `concepts/architecture`: its path under `docs/` without `.md`. The skills name pages by ID.
51
51
 
52
52
  ## The test loop
53
53
 
@@ -60,7 +60,18 @@ An agent checks its work with the `null3d` command, which prints short lines of
60
60
 
61
61
  `bunx @null3d/cli shot` draws one frame of a page, to look at a change that has no test yet.
62
62
 
63
- ## Coming later
63
+ ## The MCP server
64
64
 
65
- - 0.3: `bunx @null3d/cli mcp`, a Model Context Protocol server connected to the running dev session. Agents list and adjust objects, capture frames, and read frame statistics and errors through it.
66
- - 0.3: project templates from `bunx @null3d/cli create`, each with an `AGENTS.md` for agents without skills.
65
+ `bunx @null3d/cli mcp` starts a Model Context Protocol server for the project in the current folder. It runs over stdio, and an agent uses it to look inside the running scene and change it live. The server needs a development build, because a production build leaves the inspection channel out.
66
+
67
+ By default the server starts the project's own Vite dev server and a headless Chrome, as `shot` does. This works on a cloud agent with no window. With `--connect <endpoint>` it attaches to a Chrome that the developer already runs with a remote debugging port. It then drives the tab that shows the page, so the agent sees exactly what the developer sees. [Debugging](debugging.md#the-mcp-server) lists the options and the tools, and [the `mcp` command](../cli/null3d.md#mcp) is the full reference.
68
+
69
+ Register the server in Claude Code with:
70
+
71
+ ```sh
72
+ claude mcp add null3d -- bunx @null3d/cli mcp
73
+ ```
74
+
75
+ The tools list and read objects, and change a transform or a material. They capture a frame, and read the frame figures, the errors and the render graph. They also switch the quality preset or the GPU path. Live changes are for exploring: the agent writes the final values into the sketch and its tests, and checks them with `bunx @null3d/cli test`.
76
+
77
+ The page also shows a panel of its own with `?inspect`, which lists the scene, selects an object and edits it. [The in-page inspector](debugging.md#the-in-page-inspector) describes it.