@null3d/engine 0.1.0 → 0.1.2

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 (388) hide show
  1. package/dist/wasm/single/null3d.js +10 -8
  2. package/dist/wasm/single/null3d_bg.wasm +0 -0
  3. package/dist/wasm/threaded/null3d.js +10 -8
  4. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  5. package/docs/api/animation.md +96 -24
  6. package/docs/api/assets.md +99 -29
  7. package/docs/api/cameras.md +38 -7
  8. package/docs/api/controls.md +47 -23
  9. package/docs/api/debug.md +105 -35
  10. package/docs/api/engine.md +108 -32
  11. package/docs/api/feature-draws.md +21 -15
  12. package/docs/api/feature-effects.md +8 -8
  13. package/docs/api/feature-instances.md +68 -17
  14. package/docs/api/features.md +68 -37
  15. package/docs/api/geometry.md +83 -14
  16. package/docs/api/grass.md +55 -13
  17. package/docs/api/impostors.md +92 -50
  18. package/docs/api/input.md +22 -9
  19. package/docs/api/lights.md +67 -16
  20. package/docs/api/lines.md +38 -13
  21. package/docs/api/materials.md +187 -59
  22. package/docs/api/math.md +6 -6
  23. package/docs/api/objects.md +40 -15
  24. package/docs/api/page.md +58 -7
  25. package/docs/api/particles.md +36 -11
  26. package/docs/api/points.md +18 -8
  27. package/docs/api/post.md +57 -23
  28. package/docs/api/quality.md +36 -16
  29. package/docs/api/raycast.md +57 -24
  30. package/docs/api/reference/animation.md +1 -2
  31. package/docs/api/reference/assets.md +7 -4
  32. package/docs/api/reference/cameras.md +3 -2
  33. package/docs/api/reference/controls.md +59 -2
  34. package/docs/api/reference/debug.md +58 -6
  35. package/docs/api/reference/engine.md +40 -10
  36. package/docs/api/reference/feature-draws.md +3 -4
  37. package/docs/api/reference/feature-effects.md +2 -3
  38. package/docs/api/reference/feature-instances.md +5 -4
  39. package/docs/api/reference/features.md +7 -4
  40. package/docs/api/reference/geometry.md +132 -21
  41. package/docs/api/reference/grass.md +62 -2
  42. package/docs/api/reference/impostors.md +120 -16
  43. package/docs/api/reference/input.md +1 -2
  44. package/docs/api/reference/lights.md +4 -3
  45. package/docs/api/reference/lines.md +3 -4
  46. package/docs/api/reference/materials.md +7 -6
  47. package/docs/api/reference/math.md +13 -2
  48. package/docs/api/reference/objects.md +2 -3
  49. package/docs/api/reference/particles.md +31 -6
  50. package/docs/api/reference/points.md +2 -3
  51. package/docs/api/reference/post.md +4 -3
  52. package/docs/api/reference/quality.md +1 -2
  53. package/docs/api/reference/raycast.md +1 -2
  54. package/docs/api/reference/render.md +4 -3
  55. package/docs/api/reference/scene.md +24 -5
  56. package/docs/api/reference/sketch.md +11 -11
  57. package/docs/api/reference/sound.md +33 -2
  58. package/docs/api/reference/splats.md +42 -3
  59. package/docs/api/reference/sprites.md +2 -3
  60. package/docs/api/reference/tasks.md +16 -3
  61. package/docs/api/reference/terrain.md +26 -5
  62. package/docs/api/reference/textures.md +1 -2
  63. package/docs/api/reference/three-compat.md +18 -7
  64. package/docs/api/reference/time.md +1 -2
  65. package/docs/api/reference/ui.md +10 -7
  66. package/docs/api/reference/vertex-draws.md +2 -3
  67. package/docs/api/reference/water.md +78 -5
  68. package/docs/api/reference/wind.md +15 -2
  69. package/docs/api/render.md +67 -25
  70. package/docs/api/scene.md +129 -36
  71. package/docs/api/sketch.md +45 -19
  72. package/docs/api/sound.md +48 -12
  73. package/docs/api/splats.md +42 -15
  74. package/docs/api/sprites.md +8 -6
  75. package/docs/api/tasks.md +31 -22
  76. package/docs/api/terrain.md +44 -12
  77. package/docs/api/textures.md +61 -12
  78. package/docs/api/three-compat.md +15 -7
  79. package/docs/api/time.md +3 -5
  80. package/docs/api/ui.md +18 -10
  81. package/docs/api/vertex-draws.md +13 -12
  82. package/docs/api/water.md +111 -67
  83. package/docs/api/wind.md +61 -15
  84. package/docs/cli/null3d.md +90 -15
  85. package/docs/concepts/architecture.md +69 -23
  86. package/docs/concepts/assets.md +57 -16
  87. package/docs/concepts/backends.md +68 -24
  88. package/docs/concepts/color-management.md +42 -13
  89. package/docs/concepts/culling.md +68 -47
  90. package/docs/concepts/handles.md +14 -5
  91. package/docs/concepts/instances.md +72 -23
  92. package/docs/concepts/large-worlds.md +17 -7
  93. package/docs/concepts/lighting.md +117 -44
  94. package/docs/concepts/lod.md +128 -33
  95. package/docs/concepts/materials.md +43 -12
  96. package/docs/concepts/particle-buffer.md +48 -35
  97. package/docs/concepts/post-processing.md +77 -14
  98. package/docs/concepts/quality-preset-tables.md +3 -2
  99. package/docs/concepts/quality-presets.md +122 -39
  100. package/docs/concepts/render-graph.md +56 -21
  101. package/docs/concepts/render-layers.md +9 -5
  102. package/docs/concepts/shadows.md +96 -25
  103. package/docs/concepts/static-dynamic.md +22 -7
  104. package/docs/cookbook/index.md +163 -119
  105. package/docs/data/threejs-mapping.json +301 -340
  106. package/docs/errors/E1101.md +23 -5
  107. package/docs/errors/E1102.md +11 -3
  108. package/docs/errors/E1103.md +11 -3
  109. package/docs/errors/E1104.md +11 -3
  110. package/docs/errors/E1105.md +13 -5
  111. package/docs/errors/E1106.md +11 -3
  112. package/docs/errors/E1107.md +15 -5
  113. package/docs/errors/E1108.md +11 -3
  114. package/docs/errors/E1109.md +32 -6
  115. package/docs/errors/E1110.md +23 -5
  116. package/docs/errors/E1111.md +11 -3
  117. package/docs/errors/E1112.md +11 -3
  118. package/docs/errors/E1203.md +12 -4
  119. package/docs/errors/E1204.md +11 -3
  120. package/docs/errors/E1205.md +11 -3
  121. package/docs/errors/E1206.md +28 -6
  122. package/docs/errors/E1207.md +11 -3
  123. package/docs/errors/E1208.md +12 -3
  124. package/docs/errors/E1209.md +11 -3
  125. package/docs/errors/E1213.md +27 -5
  126. package/docs/errors/E1214.md +11 -3
  127. package/docs/errors/E1215.md +31 -6
  128. package/docs/errors/E1216.md +31 -6
  129. package/docs/errors/E1217.md +29 -6
  130. package/docs/errors/E1218.md +22 -6
  131. package/docs/errors/E1219.md +11 -3
  132. package/docs/errors/E1220.md +24 -5
  133. package/docs/errors/E1221.md +24 -5
  134. package/docs/errors/E1222.md +11 -3
  135. package/docs/errors/E1223.md +39 -6
  136. package/docs/errors/E1224.md +11 -3
  137. package/docs/errors/E1225.md +11 -3
  138. package/docs/errors/E1301.md +11 -3
  139. package/docs/errors/E1302.md +11 -3
  140. package/docs/errors/E1303.md +11 -3
  141. package/docs/errors/E1304.md +11 -3
  142. package/docs/errors/E1305.md +13 -3
  143. package/docs/errors/E1306.md +11 -3
  144. package/docs/errors/E1307.md +23 -6
  145. package/docs/errors/E1308.md +31 -0
  146. package/docs/errors/E1401.md +11 -3
  147. package/docs/errors/E1402.md +13 -5
  148. package/docs/errors/E1403.md +11 -3
  149. package/docs/errors/E1404.md +13 -3
  150. package/docs/errors/E1405.md +15 -4
  151. package/docs/errors/E1406.md +31 -5
  152. package/docs/errors/E1407.md +11 -3
  153. package/docs/errors/E1408.md +11 -3
  154. package/docs/errors/E1409.md +11 -3
  155. package/docs/errors/E1410.md +13 -5
  156. package/docs/errors/E1411.md +11 -3
  157. package/docs/errors/E1412.md +29 -6
  158. package/docs/errors/E1413.md +11 -3
  159. package/docs/errors/E1414.md +11 -3
  160. package/docs/errors/E1415.md +11 -3
  161. package/docs/errors/E1416.md +27 -6
  162. package/docs/errors/E1417.md +11 -3
  163. package/docs/errors/E1418.md +12 -3
  164. package/docs/errors/E1419.md +13 -5
  165. package/docs/errors/E1420.md +11 -3
  166. package/docs/errors/E1421.md +11 -3
  167. package/docs/errors/E1422.md +12 -3
  168. package/docs/errors/E1423.md +12 -3
  169. package/docs/errors/E1424.md +24 -5
  170. package/docs/errors/E1425.md +11 -3
  171. package/docs/errors/E1426.md +11 -3
  172. package/docs/errors/E1430.md +11 -3
  173. package/docs/errors/E1431.md +11 -3
  174. package/docs/errors/E1432.md +11 -3
  175. package/docs/errors/E1433.md +11 -3
  176. package/docs/errors/E1434.md +15 -6
  177. package/docs/errors/E1435.md +11 -3
  178. package/docs/errors/E1436.md +11 -3
  179. package/docs/errors/E1437.md +14 -6
  180. package/docs/errors/E1501.md +41 -6
  181. package/docs/errors/E1502.md +13 -3
  182. package/docs/errors/E1503.md +11 -3
  183. package/docs/errors/E1504.md +11 -3
  184. package/docs/errors/E1505.md +23 -5
  185. package/docs/errors/E1506.md +11 -3
  186. package/docs/errors/index.md +53 -29
  187. package/docs/getting-started/cdn.md +15 -9
  188. package/docs/getting-started/first-scene.md +20 -12
  189. package/docs/getting-started/hosting.md +113 -63
  190. package/docs/getting-started/install.md +39 -24
  191. package/docs/getting-started/network-use.md +31 -21
  192. package/docs/getting-started/project-structure.md +20 -8
  193. package/docs/getting-started/third-party-notices.md +6 -10
  194. package/docs/guides/accessibility.md +4 -4
  195. package/docs/guides/add-ons.md +83 -13
  196. package/docs/guides/agents.md +13 -14
  197. package/docs/guides/assets-pipeline.md +294 -72
  198. package/docs/guides/audio.md +17 -15
  199. package/docs/guides/baked-light-data.md +44 -23
  200. package/docs/guides/car-paint.md +37 -31
  201. package/docs/guides/content-pages.md +86 -29
  202. package/docs/guides/custom-passes.md +59 -17
  203. package/docs/guides/custom-shaders.md +54 -37
  204. package/docs/guides/debugging.md +31 -41
  205. package/docs/guides/deploying.md +10 -27
  206. package/docs/guides/deterministic-simulation.md +23 -16
  207. package/docs/guides/first-use-shaders.md +83 -45
  208. package/docs/guides/lens-kit.md +29 -26
  209. package/docs/guides/loading-screens.md +74 -30
  210. package/docs/guides/multiple-views.md +22 -11
  211. package/docs/guides/performance.md +188 -37
  212. package/docs/guides/phones.md +71 -19
  213. package/docs/guides/physics.md +6 -10
  214. package/docs/guides/screens.md +41 -29
  215. package/docs/guides/start-time.md +126 -85
  216. package/docs/guides/testing.md +137 -98
  217. package/docs/guides/ui-overlays.md +17 -12
  218. package/docs/guides/video-textures.md +14 -13
  219. package/docs/images/api/animation/character.webp +0 -0
  220. package/docs/images/api/animation/look-at-ring.webp +0 -0
  221. package/docs/images/api/animation/morph-tulips.webp +0 -0
  222. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  223. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  224. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  225. package/docs/images/api/debug/debug-shapes.webp +0 -0
  226. package/docs/images/api/debug/levels-view.webp +0 -0
  227. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  228. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  229. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  230. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  231. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  232. package/docs/images/api/geometry/generators.webp +0 -0
  233. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  234. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  235. package/docs/images/api/grass/grass-grove.webp +0 -0
  236. package/docs/images/api/grass/grass-presets.webp +0 -0
  237. package/docs/images/api/grass/grass-shadow.webp +0 -0
  238. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  239. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  240. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  241. package/docs/images/api/lights/spot-cookies.webp +0 -0
  242. package/docs/images/api/lines/lines-lit.webp +0 -0
  243. package/docs/images/api/lines/lines-widths.webp +0 -0
  244. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  245. package/docs/images/api/materials/decals.webp +0 -0
  246. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  247. package/docs/images/api/materials/relief.webp +0 -0
  248. package/docs/images/api/materials/shader-inputs.webp +0 -0
  249. package/docs/images/api/materials/standard-grid.webp +0 -0
  250. package/docs/images/api/materials/subsurface.webp +0 -0
  251. package/docs/images/api/materials/translucency.webp +0 -0
  252. package/docs/images/api/objects/objects-turntable.webp +0 -0
  253. package/docs/images/api/particles/campfire.webp +0 -0
  254. package/docs/images/api/points/galaxy.webp +0 -0
  255. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  256. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  257. package/docs/images/api/render/reflection-mirror.webp +0 -0
  258. package/docs/images/api/render/security-camera.webp +0 -0
  259. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  260. package/docs/images/api/sound/sound-demo.webp +0 -0
  261. package/docs/images/api/splats/splats-demo.webp +0 -0
  262. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  263. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  264. package/docs/images/api/textures/canvas-screen.webp +0 -0
  265. package/docs/images/api/textures/mipmaps.webp +0 -0
  266. package/docs/images/api/vertex-draws/rain.webp +0 -0
  267. package/docs/images/api/water/ocean.webp +0 -0
  268. package/docs/images/api/water/water-demo.webp +0 -0
  269. package/docs/images/api/water/water-rain.webp +0 -0
  270. package/docs/images/api/water/waterfall.webp +0 -0
  271. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  272. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  273. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  274. package/docs/images/concepts/instances/instances.webp +0 -0
  275. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  276. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  277. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  278. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  279. package/docs/images/concepts/lighting/environment.webp +0 -0
  280. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  281. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  282. package/docs/images/concepts/lod/forest.webp +0 -0
  283. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  284. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  285. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  286. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  287. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  288. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  289. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  290. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  291. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  292. package/docs/images/cookbook/index/picking.webp +0 -0
  293. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  294. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  295. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  296. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  297. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  298. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  299. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  300. package/docs/images/index/showcase-island.webp +0 -0
  301. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  302. package/docs/images/shaders/builtins/builtins.webp +0 -0
  303. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  304. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  305. package/docs/images/shots.json +2231 -0
  306. package/docs/index.md +14 -23
  307. package/docs/moves.json +1 -0
  308. package/docs/nav.json +300 -0
  309. package/docs/pages.md +230 -212
  310. package/docs/porting/react-three-fiber.md +2 -6
  311. package/docs/porting/threejs-loop-and-threads.md +1 -5
  312. package/docs/porting/threejs-mapping.md +1248 -234
  313. package/docs/porting/threejs-materials.md +10 -5
  314. package/docs/porting/threejs-overview.md +26 -6
  315. package/docs/porting/threejs-postprocessing.md +2 -6
  316. package/docs/porting/threejs-shaders.md +16 -14
  317. package/docs/porting/threejs-unsupported.md +6 -6
  318. package/docs/porting/verification.md +0 -4
  319. package/docs/shaders/builtins.md +15 -4
  320. package/docs/shaders/library.md +9 -6
  321. package/docs/shaders/surface-functions.md +51 -16
  322. package/docs/shaders/wgsl-rules.md +12 -5
  323. package/lib/debug/debug.d.ts +2 -2
  324. package/lib/debug/draw.d.ts +2 -2
  325. package/lib/debug/draw.js +8 -4
  326. package/lib/debug/overlay-look.d.ts +6 -0
  327. package/lib/debug/overlay-look.js +29 -7
  328. package/lib/debug/overlay.js +15 -11
  329. package/lib/debug/stats-options.d.ts +13 -0
  330. package/lib/debug/stats-panel.d.ts +21 -6
  331. package/lib/debug/stats-panel.js +80 -13
  332. package/lib/errors/codes.d.ts +17 -3
  333. package/lib/errors/codes.js +116 -105
  334. package/lib/errors/engine-error.js +1 -1
  335. package/lib/errors/fixes.d.ts +1 -0
  336. package/lib/errors/fixes.js +19 -18
  337. package/lib/generated/shader-permutations.d.ts +6 -0
  338. package/lib/generated/shader-permutations.js +6 -0
  339. package/lib/gpu/variants.d.ts +8 -2
  340. package/lib/gpu/variants.js +39 -7
  341. package/lib/gpu/webgl2/programs.js +1 -1
  342. package/lib/gpu/webgpu/pipelines.js +13 -13
  343. package/lib/index.d.ts +1 -1
  344. package/lib/page/capabilities.d.ts +1 -1
  345. package/lib/page/engine.d.ts +29 -7
  346. package/lib/page/engine.js +79 -7
  347. package/lib/page/label-loop.js +9 -4
  348. package/lib/page/stats-switch.js +2 -0
  349. package/lib/page/switches.d.ts +6 -4
  350. package/lib/page/switches.js +20 -4
  351. package/lib/scene/baked-light.d.ts +2 -2
  352. package/lib/scene/fake-call-values.js +2 -2
  353. package/lib/scene/frame-cameras.d.ts +16 -4
  354. package/lib/scene/frame-cameras.js +28 -10
  355. package/lib/scene/gltf.d.ts +1 -1
  356. package/lib/scene/level-rule.d.ts +6 -5
  357. package/lib/scene/level-rule.js +2 -2
  358. package/lib/scene/particles.d.ts +7 -3
  359. package/lib/scene/particles.js +3 -1
  360. package/lib/scene/post.d.ts +3 -2
  361. package/lib/scene/resources.d.ts +15 -9
  362. package/lib/scene/scene.d.ts +18 -2
  363. package/lib/scene/scene.js +47 -5
  364. package/lib/scene/time-of-day.d.ts +10 -5
  365. package/lib/scene/time-of-day.js +11 -7
  366. package/lib/shader-artifact.json +1 -1
  367. package/lib/shared/labels.d.ts +5 -2
  368. package/lib/shared/labels.js +5 -2
  369. package/lib/shared/permutation-words.d.ts +8 -0
  370. package/lib/shared/permutation-words.js +14 -0
  371. package/lib/shared/recording.d.ts +13 -5
  372. package/lib/shared/recording.js +31 -10
  373. package/lib/shared/sketch-data.d.ts +9 -0
  374. package/lib/shared/sketch-data.js +57 -0
  375. package/lib/shared/tier.d.ts +9 -0
  376. package/lib/shared/tier.js +4 -1
  377. package/lib/shared/version.d.ts +1 -1
  378. package/lib/shared/version.js +1 -1
  379. package/lib/sketch/define-sketch.d.ts +16 -7
  380. package/lib/sketch/define-sketch.js +2 -1
  381. package/lib/sketch/runner.d.ts +4 -0
  382. package/lib/sketch/runner.js +5 -0
  383. package/lib/sketch/ui.js +4 -2
  384. package/lib/stats.d.ts +1 -0
  385. package/lib/workers/protocol.d.ts +10 -0
  386. package/lib/workers/render-worker.js +4 -1
  387. package/lib/workers/sketch-worker.js +4 -1
  388. package/package.json +1 -1
@@ -17,7 +17,7 @@ import { Cubemap, isAtmosphereBackground, isSkyBackground, SceneBackground, Scen
17
17
  import { linearColor, writeLinearColor } from './color.js';
18
18
  import { Environment, SceneEnvironment } from './environment.js';
19
19
  import { setSceneFog } from './fog.js';
20
- import { FrameCameras, LENS_CENTER_X, LENS_CENTER_Y, LENS_FAR, LENS_FLOATS, LENS_HALF_HEIGHT, LENS_HALF_WIDTH, LENS_NEAR, LENS_ORTHO, } from './frame-cameras.js';
20
+ import { FrameCameras, LENS_CENTER_X, LENS_CENTER_Y, LENS_FAR, LENS_FLOATS, LENS_HALF_HEIGHT, LENS_HALF_WIDTH, LENS_NEAR, LENS_ORTHO, LENS_SHIFT_X, LENS_SHIFT_Y, } from './frame-cameras.js';
21
21
  import { checkFov, checkNearFar, checkOrthographicSize, checkSize, DEFAULT_FAR, DEFAULT_FOV, DEFAULT_NEAR, HALF_SENSOR_MM, newCamera, orthographicView, setViewHeight, } from './lens.js';
22
22
  import { SceneLightProbeGrid } from './light-probes.js';
23
23
  import { ScenePicks } from './picks.js';
@@ -999,8 +999,9 @@ export class Mesh extends Object3D {
999
999
  this.renderOrder = order;
1000
1000
  }
1001
1001
  /**
1002
- * Raises or lowers the threshold that picks this mesh's levels of detail, as Godot's
1003
- * `lod_bias` does. A bias above 1 makes every switch happen nearer, so the object draws
1002
+ * Raises or lowers the threshold that picks this mesh's levels of detail, as the inverse of
1003
+ * Godot's `lod_bias`: a Godot bias of 2 is about a null3D bias of 0.5. A bias above 1 makes
1004
+ * every switch happen nearer, so the object draws
1004
1005
  * coarser levels. A bias below 1 keeps its detail, which a hero object wants. The bias
1005
1006
  * multiplies the threshold of the level switches and of the distance at which the object
1006
1007
  * hides, so both move by the same factor. The default is 1. The object's mesh needs levels
@@ -1074,6 +1075,8 @@ export class Camera extends Object3D {
1074
1075
  layers = C.LAYERS_DEFAULT;
1075
1076
  /** @internal The lens as the frame cameras keep it, which `updateLens` writes. */
1076
1077
  lens = new Float64Array(LENS_FLOATS);
1078
+ /** @internal The lens shift across and up, which `lensShift` gives. */
1079
+ shift = [0, 0];
1077
1080
  /** @internal */
1078
1081
  constructor(scene, handle, name, nearPlane, farPlane) {
1079
1082
  super(scene, handle, name);
@@ -1110,6 +1113,32 @@ export class Camera extends Object3D {
1110
1113
  this.farPlane = far;
1111
1114
  this.scene.lensChanged(this);
1112
1115
  }
1116
+ /**
1117
+ * The lens shift: how far the view sits right of and above the camera's axis, as fractions of the
1118
+ * view's width and height. The array is the camera's own and changes with `setLensShift`, so
1119
+ * copy it to keep a value.
1120
+ */
1121
+ get lensShift() {
1122
+ return this.shift;
1123
+ }
1124
+ /**
1125
+ * Moves the view off the camera's axis, as a shift lens on a real camera does: right by `x`
1126
+ * times the view's width, and up by `y` times its height. The perspective stays as it is, so the
1127
+ * image is a crop of a wider view from the same place. A shift of 0.25 across puts the camera's
1128
+ * axis, and a `target` it looks at, a quarter of the width left of the middle. Culling,
1129
+ * shadows, picking, `screenToRay`, `worldToScreen`, views and labels all follow the shifted
1130
+ * view. The default is no shift. It allocates nothing.
1131
+ */
1132
+ setLensShift(x, y) {
1133
+ if (DEV) {
1134
+ checkLive('setLensShift', this);
1135
+ checkNumber('setLensShift', 'x', x, this);
1136
+ checkNumber('setLensShift', 'y', y, this);
1137
+ }
1138
+ this.shift[0] = x;
1139
+ this.shift[1] = y;
1140
+ this.scene.lensChanged(this);
1141
+ }
1113
1142
  /**
1114
1143
  * Writes the ray from the camera through a point on the canvas into `out`: `x` and `y` are CSS
1115
1144
  * pixels from the canvas's top-left corner, as `input.pointer` gives them. A perspective ray
@@ -1150,6 +1179,15 @@ export class Camera extends Object3D {
1150
1179
  this.writeLensShape(lens);
1151
1180
  lens[LENS_NEAR] = this.nearPlane;
1152
1181
  lens[LENS_FAR] = this.farPlane;
1182
+ lens[LENS_SHIFT_X] = this.shift[0];
1183
+ lens[LENS_SHIFT_Y] = this.shift[1];
1184
+ }
1185
+ /** @internal Gives a copy of this camera the layers and the lens shift that this one has. */
1186
+ copyLensTo(twin) {
1187
+ twin.layers = this.layers;
1188
+ twin.shift[0] = this.shift[0];
1189
+ twin.shift[1] = this.shift[1];
1190
+ twin.updateLens();
1153
1191
  }
1154
1192
  }
1155
1193
  /**
@@ -1209,7 +1247,7 @@ export class PerspectiveCamera extends Camera {
1209
1247
  /** @internal */
1210
1248
  twin(handle) {
1211
1249
  const twin = new PerspectiveCamera(this.scene, handle, this.name, this.verticalFov, this.near, this.far);
1212
- twin.layers = this.layers;
1250
+ this.copyLensTo(twin);
1213
1251
  return twin;
1214
1252
  }
1215
1253
  /** @internal */
@@ -1218,6 +1256,8 @@ export class PerspectiveCamera extends Camera {
1218
1256
  values[0] = this.verticalFov;
1219
1257
  values[1] = this.near;
1220
1258
  values[2] = this.far;
1259
+ values[3] = this.shift[0];
1260
+ values[4] = this.shift[1];
1221
1261
  core.glue.setPerspectiveCamera(this.handle, layers, target);
1222
1262
  }
1223
1263
  }
@@ -1273,7 +1313,7 @@ export class OrthographicCamera extends Camera {
1273
1313
  /** @internal */
1274
1314
  twin(handle) {
1275
1315
  const twin = new OrthographicCamera(this.scene, handle, this.name, { ...this.view }, this.near, this.far);
1276
- twin.layers = this.layers;
1316
+ this.copyLensTo(twin);
1277
1317
  return twin;
1278
1318
  }
1279
1319
  /** @internal */
@@ -1286,6 +1326,8 @@ export class OrthographicCamera extends Camera {
1286
1326
  values[3] = view.centerY;
1287
1327
  values[4] = this.near;
1288
1328
  values[5] = this.far;
1329
+ values[6] = this.shift[0];
1330
+ values[7] = this.shift[1];
1289
1331
  core.glue.setOrthographicCamera(this.handle, layers, target);
1290
1332
  }
1291
1333
  }
@@ -92,8 +92,10 @@ export interface TimeOfDay {
92
92
  intensity: number;
93
93
  };
94
94
  /**
95
- * The fog's linear color, the sky's color along the horizon, and the glow toward the main
96
- * light, for `scene.setFog`.
95
+ * The fog's linear color and the glow toward the main light, for `scene.setFog`. With the
96
+ * analytic model the color is the sky's horizon by day and its average at dusk. With the
97
+ * physical model it is the sky's mean light by day and through dusk, then the moon sky's
98
+ * horizon light at night.
97
99
  */
98
100
  fog: {
99
101
  color: [number, number, number];
@@ -113,9 +115,12 @@ export interface TimeOfDay {
113
115
  /**
114
116
  * Works out the settings of a time of day: an hour from 0 to 24, or a named preset. The sun rises
115
117
  * at 6, stands highest at 12 and sets at 18. After sunset the sky dims to a deep blue, and then to
116
- * a navy night sky lit from the moon's place, and the moon takes over as the main light. Each value
117
- * comes from the model of the sky that the background draws, so the fog fades into the sky's
118
- * horizon. Throws a `RangeError` for an hour that is not a finite number, or an unknown preset.
118
+ * a navy night sky lit from the moon's place, and the moon takes over as the main light.
119
+ *
120
+ * Each value comes from the model of the sky that the background draws, so the fog takes that sky's horizon
121
+ * color by day and its average at dusk. With the physical model it takes the sky's mean light by
122
+ * day and through dusk, then the moon sky's horizon light at night. Throws a `RangeError` for an
123
+ * hour that is not a finite number, or an unknown preset.
119
124
  *
120
125
  * Give it `out`, an object of a previous call, and it writes the new settings into that object: a
121
126
  * day cycle then allocates nothing, so a sketch can move the time in every frame. `bun run
@@ -16,7 +16,7 @@ const PRESET_HOURS = {
16
16
  const DEGREE = Math.PI / 180;
17
17
  /**
18
18
  * How low the sky's own sun sinks after sunset, in degrees. three.js's sky gives no sun light once
19
- * its sun is about 2.3 degrees under the horizon, which leaves only a flat grey that the tone curve
19
+ * its sun is about 2.3 degrees under the horizon, which leaves only a flat gray that the tone curve
20
20
  * maps to black. So after sunset the sky keeps its sun just above that, which keeps the sunset's
21
21
  * glow, and `skyIntensity` sets how bright it shows.
22
22
  */
@@ -81,9 +81,12 @@ const EXPOSURE = [
81
81
  /**
82
82
  * Works out the settings of a time of day: an hour from 0 to 24, or a named preset. The sun rises
83
83
  * at 6, stands highest at 12 and sets at 18. After sunset the sky dims to a deep blue, and then to
84
- * a navy night sky lit from the moon's place, and the moon takes over as the main light. Each value
85
- * comes from the model of the sky that the background draws, so the fog fades into the sky's
86
- * horizon. Throws a `RangeError` for an hour that is not a finite number, or an unknown preset.
84
+ * a navy night sky lit from the moon's place, and the moon takes over as the main light.
85
+ *
86
+ * Each value comes from the model of the sky that the background draws, so the fog takes that sky's horizon
87
+ * color by day and its average at dusk. With the physical model it takes the sky's mean light by
88
+ * day and through dusk, then the moon sky's horizon light at night. Throws a `RangeError` for an
89
+ * hour that is not a finite number, or an unknown preset.
87
90
  *
88
91
  * Give it `out`, an object of a previous call, and it writes the new settings into that object: a
89
92
  * day cycle then allocates nothing, so a sketch can move the time in every frame. `bun run
@@ -474,10 +477,11 @@ function physicalDay(hours, atmosphere, elevation, out) {
474
477
  // the twilight's fill does not fall away between the two.
475
478
  const sunShare = sunLight * (1 - handover);
476
479
  const moonSkyShare = MOON_SKY_LIGHT * handover * moonShare;
477
- // The fog takes the sky's mean light at every hour, not its light along the horizon. A fog of the
478
- // horizon's light carries the brightest band of the sky over the whole scene and washes its shaded
480
+ // The physical model's fog takes the sky's mean light by day and through dusk, then the moon
481
+ // sky's horizon light at night, not the sky's light along the horizon. A fog of the horizon's
482
+ // light carries the brightest band of the sky over the whole scene and washes its shaded
479
483
  // surfaces, while the exposure follows the mean; a low sun makes that band its own glow. The
480
- // analytic model's fog takes the mean too.
484
+ // analytic model's fog takes the horizon color by day and fades to its average at dusk.
481
485
  const fogColor = out.fog.color;
482
486
  scale(fogColor, SET_MEAN, sunShare);
483
487
  add(fogColor, fogColor, scale(MOON_HORIZON, MOON_HORIZON, moonSkyShare));
@@ -1 +1 @@
1
- {"tag":"0.1.0","file":"0.1.0-shaders.tar.br","url":"https://github.com/null3d-engine/null3d/releases/download/0.1.0/0.1.0-shaders.tar.br","sha256":"fceebb2a12304cd05f72299b670a305318af470b187a49724714aed47725b8dd"}
1
+ {"tag":"0.1.2","file":"0.1.2-shaders.tar.br","url":"https://github.com/null3d-engine/null3d/releases/download/0.1.2/0.1.2-shaders.tar.br","sha256":"6ab4019ca61ff2b66f5cff07f62692330afc34ddbbad623c555fbc45c7a01be5"}
@@ -33,7 +33,8 @@ export declare const LABEL3D_STATE = 12;
33
33
  * The frame's camera, as the page needs it to build the perspective that turns a 3D label's matrix
34
34
  * into a place on the canvas: the inverse of its world matrix's 3 × 3 part, row by row; the camera's
35
35
  * position; half the view's height at one unit in front of a perspective camera, or across an
36
- * orthographic view; 1 for an orthographic lens; and that view's center.
36
+ * orthographic view; 1 for an orthographic lens; that view's center; and the lens shift, as fractions
37
+ * of the view's width and height.
37
38
  */
38
39
  export declare const CAMERA_ROTATION = 0;
39
40
  export declare const CAMERA_POSITION = 9;
@@ -41,7 +42,9 @@ export declare const CAMERA_HALF_HEIGHT = 12;
41
42
  export declare const CAMERA_ORTHO = 13;
42
43
  export declare const CAMERA_CENTER_X = 14;
43
44
  export declare const CAMERA_CENTER_Y = 15;
44
- export declare const CAMERA_FLOATS = 16;
45
+ export declare const CAMERA_SHIFT_X = 16;
46
+ export declare const CAMERA_SHIFT_Y = 17;
47
+ export declare const CAMERA_FLOATS = 18;
45
48
  /** The labels' part of the control buffer. */
46
49
  export interface LabelRegion {
47
50
  /** The header and the tables, as integers. */
@@ -45,7 +45,8 @@ export const LABEL3D_STATE = 12;
45
45
  * The frame's camera, as the page needs it to build the perspective that turns a 3D label's matrix
46
46
  * into a place on the canvas: the inverse of its world matrix's 3 × 3 part, row by row; the camera's
47
47
  * position; half the view's height at one unit in front of a perspective camera, or across an
48
- * orthographic view; 1 for an orthographic lens; and that view's center.
48
+ * orthographic view; 1 for an orthographic lens; that view's center; and the lens shift, as fractions
49
+ * of the view's width and height.
49
50
  */
50
51
  export const CAMERA_ROTATION = 0;
51
52
  export const CAMERA_POSITION = 9;
@@ -53,7 +54,9 @@ export const CAMERA_HALF_HEIGHT = 12;
53
54
  export const CAMERA_ORTHO = 13;
54
55
  export const CAMERA_CENTER_X = 14;
55
56
  export const CAMERA_CENTER_Y = 15;
56
- export const CAMERA_FLOATS = 16;
57
+ export const CAMERA_SHIFT_X = 16;
58
+ export const CAMERA_SHIFT_Y = 17;
59
+ export const CAMERA_FLOATS = 18;
57
60
  /** The header's words, before the tables. */
58
61
  const SEQUENCE = 0;
59
62
  const FRAME = 1;
@@ -0,0 +1,8 @@
1
+ /** The event on the page's global object that carries a word that the page draws with. */
2
+ export declare const PERMUTATION_WORD_EVENT = "null3d:permutation";
3
+ /**
4
+ * The event on the page's global object that carries the GPU path that the engine started on. The
5
+ * dev server compares it with the paths that a production build ships, and warns when a page draws
6
+ * with a path that the build leaves out.
7
+ */
8
+ export declare const GPU_PATH_EVENT = "null3d:gpu-path";
@@ -0,0 +1,14 @@
1
+ // The permutation words that a page draws with, on the dev server. In a development build, the
2
+ // thread that draws hands each word to the page once, without the bits that a device fixes, and
3
+ // the engine fires an event with it on the page's global object. The null3D Vite plugin's client
4
+ // module sends the word to the dev server, which compares it with the project's shader list and
5
+ // warns about a word that the list lacks. The file imports nothing, so the plugin's tests read it
6
+ // too.
7
+ /** The event on the page's global object that carries a word that the page draws with. */
8
+ export const PERMUTATION_WORD_EVENT = 'null3d:permutation';
9
+ /**
10
+ * The event on the page's global object that carries the GPU path that the engine started on. The
11
+ * dev server compares it with the paths that a production build ships, and warns when a page draws
12
+ * with a path that the build leaves out.
13
+ */
14
+ export const GPU_PATH_EVENT = 'null3d:gpu-path';
@@ -1,7 +1,10 @@
1
1
  /** The file's first four bytes, which name the format. */
2
2
  export declare const RECORDING_MAGIC = 1311982674;
3
- /** The format's version, which a reader refuses when it does not know. */
4
- export declare const RECORDING_VERSION = 1;
3
+ /**
4
+ * The format's version, which a reader refuses when it is newer than its own. Version 2 adds the
5
+ * sketch's start data; a reader takes version 1 as a recording without it.
6
+ */
7
+ export declare const RECORDING_VERSION = 2;
5
8
  /** The most sketch time that a recording keeps, in seconds. */
6
9
  export declare const MAX_RECORDING_SECONDS = 600;
7
10
  /** The numbers of one event, as the recording stores them side by side: type, code, flags, id,
@@ -33,6 +36,8 @@ export interface ReplayProgram {
33
36
  fixedRate: number;
34
37
  /** The sketch's address when it was recorded, for a message about a different scene. */
35
38
  sketch: string;
39
+ /** The start data that the sketch had, as JSON text, or undefined when it had none. */
40
+ data?: string;
36
41
  /** True when the recording stopped at its limit before the session ended. */
37
42
  stopped: boolean;
38
43
  /** Each frame's step in seconds, which sums to the frame's sketch time. */
@@ -83,14 +88,17 @@ export declare class Recorder {
83
88
  private growFrames;
84
89
  private growEvents;
85
90
  /**
86
- * The file's bytes: the session's seed, the statistics that a replay needs, the dictionary of
87
- * the keys that the input used, and each frame's step with the input that the sketch read.
91
+ * The file's bytes: the session's seed, the statistics that a replay needs, the sketch's start
92
+ * data, the dictionary of the keys that the input used, and each frame's step with the input
93
+ * that the sketch read.
88
94
  *
89
- * @param header The fixed rate of the sketch's fixed updates, and the sketch's address.
95
+ * @param header The fixed rate of the sketch's fixed updates, the sketch's address, and its
96
+ * start data as JSON text.
90
97
  */
91
98
  encode(header: {
92
99
  fixedRate: number;
93
100
  sketch: string;
101
+ data?: string;
94
102
  }): Uint8Array;
95
103
  }
96
104
  /**
@@ -2,16 +2,21 @@
2
2
  // a small binary file that replays on another machine to the same frames. The file holds the time
3
3
  // of every frame as a step, delta-coded, and a dictionary of the keys that the input used. Replay
4
4
  // runs the frames from the first one, with the sketch's setup as it started, so a session on a
5
- // phone reproduces on a computer.
5
+ // phone reproduces on a computer. The file keeps the start data that the page gave the sketch, so
6
+ // the replay's setup reads the same data.
6
7
  //
7
8
  // The recorder lives on the sketch's thread, so it records what the sketch read, not what the page
8
9
  // sent. A frame with no input costs sixteen bytes in its frame arrays and nine in the file: the
9
10
  // step's eight-byte number and a one-byte count.
10
11
  import { EVENT_KEY_DOWN, EVENT_KEY_UP } from './control.js';
12
+ import { MAX_SKETCH_DATA_BYTES } from './sketch-data.js';
11
13
  /** The file's first four bytes, which name the format. */
12
14
  export const RECORDING_MAGIC = 0x4e334452;
13
- /** The format's version, which a reader refuses when it does not know. */
14
- export const RECORDING_VERSION = 1;
15
+ /**
16
+ * The format's version, which a reader refuses when it is newer than its own. Version 2 adds the
17
+ * sketch's start data; a reader takes version 1 as a recording without it.
18
+ */
19
+ export const RECORDING_VERSION = 2;
15
20
  /** The most sketch time that a recording keeps, in seconds. */
16
21
  export const MAX_RECORDING_SECONDS = 600;
17
22
  /** The most frames and input records that a recording keeps, so a broken page cannot exhaust memory. */
@@ -19,6 +24,8 @@ const MAX_FRAMES = 2_000_000;
19
24
  const MAX_EVENTS = 1_000_000;
20
25
  /** The flag that marks a recording that stopped at its limit before the session ended. */
21
26
  const FLAG_STOPPED = 1;
27
+ /** The flag that marks a recording whose header holds the sketch's start data. */
28
+ const FLAG_DATA = 2;
22
29
  /** The numbers of one event, as the recording stores them side by side: type, code, flags, id,
23
30
  * buttons, x and y. */
24
31
  export const EVENT_STRIDE = 7;
@@ -262,19 +269,23 @@ export class Recorder {
262
269
  this.events = events;
263
270
  }
264
271
  /**
265
- * The file's bytes: the session's seed, the statistics that a replay needs, the dictionary of
266
- * the keys that the input used, and each frame's step with the input that the sketch read.
272
+ * The file's bytes: the session's seed, the statistics that a replay needs, the sketch's start
273
+ * data, the dictionary of the keys that the input used, and each frame's step with the input
274
+ * that the sketch read.
267
275
  *
268
- * @param header The fixed rate of the sketch's fixed updates, and the sketch's address.
276
+ * @param header The fixed rate of the sketch's fixed updates, the sketch's address, and its
277
+ * start data as JSON text.
269
278
  */
270
279
  encode(header) {
271
- const out = new ByteWriter(64 + this.frameCount * 8);
280
+ const out = new ByteWriter(64 + (header.data?.length ?? 0) + this.frameCount * 8);
272
281
  out.u32(RECORDING_MAGIC);
273
282
  out.u8(RECORDING_VERSION);
274
- out.u8(this.stopped ? FLAG_STOPPED : 0);
283
+ out.u8((this.stopped ? FLAG_STOPPED : 0) | (header.data === undefined ? 0 : FLAG_DATA));
275
284
  out.u16(header.fixedRate);
276
285
  out.u32(this.seed);
277
286
  out.text(header.sketch);
287
+ if (header.data !== undefined)
288
+ out.text(header.data);
278
289
  out.varint(this.keyNames.length);
279
290
  for (const name of this.keyNames)
280
291
  out.text(name);
@@ -313,12 +324,21 @@ export function decodeRecording(bytes) {
313
324
  if (bytes.length < 4 || reader.u32() !== RECORDING_MAGIC)
314
325
  throw new RecordingError('the file is not a null3D recording: it does not start with the format marker. Save the recording again, or ask for a new one.');
315
326
  const version = reader.u8();
316
- if (version !== RECORDING_VERSION)
317
- throw new RecordingError(`the file holds recording version ${version}, and this engine reads version ${RECORDING_VERSION}. Update the engine that made the recording, or replay it with the engine that recorded it.`);
327
+ if (version < 1 || version > RECORDING_VERSION)
328
+ throw new RecordingError(`the file holds recording version ${version}, and this engine reads versions 1 to ${RECORDING_VERSION}. Replay it with the engine that recorded it, or with a newer one.`);
318
329
  const flags = reader.u8();
319
330
  const fixedRate = whole(reader.u16(), 'the fixed step rate', 1, 1000);
320
331
  const seed = reader.u32();
321
332
  const sketch = reader.text(4096);
333
+ const data = (flags & FLAG_DATA) === 0 ? undefined : reader.text(MAX_SKETCH_DATA_BYTES);
334
+ if (data !== undefined) {
335
+ try {
336
+ JSON.parse(data);
337
+ }
338
+ catch {
339
+ throw new RecordingError("the file's start data for the sketch is not JSON text. Download it again, or record a new session.");
340
+ }
341
+ }
322
342
  const keyCount = whole(reader.varint(), 'the dictionary of keys', 0, 512);
323
343
  const keyNames = [];
324
344
  for (let k = 0; k < keyCount; k++)
@@ -367,6 +387,7 @@ export function decodeRecording(bytes) {
367
387
  seed,
368
388
  fixedRate,
369
389
  sketch,
390
+ data,
370
391
  stopped: (flags & FLAG_STOPPED) !== 0,
371
392
  steps,
372
393
  starts,
@@ -0,0 +1,9 @@
1
+ /** The most bytes that the start data takes as JSON text, in UTF-8. */
2
+ export declare const MAX_SKETCH_DATA_BYTES = 65536;
3
+ /**
4
+ * The JSON text of `data`, or undefined for no data. Plain objects, arrays, strings, finite numbers,
5
+ * booleans and null pass, and a property whose value is undefined is left out, as JSON leaves it.
6
+ * Any other value fails with E1213, which names where it sits: JSON would change it or drop it, so
7
+ * the sketch and a replay would see other data than the page gave.
8
+ */
9
+ export declare function sketchDataText(data: unknown): string | undefined;
@@ -0,0 +1,57 @@
1
+ // The start data that a page gives its sketch: plain JSON data, which travels to the sketch's thread
2
+ // as one string in the start message and which a recording keeps as the same text. The sketch's
3
+ // thread parses the text once, so the sketch gets its own copy on every thread.
4
+ import { EngineError } from '../errors/engine-error.js';
5
+ /** The most bytes that the start data takes as JSON text, in UTF-8. */
6
+ export const MAX_SKETCH_DATA_BYTES = 65_536;
7
+ /**
8
+ * The JSON text of `data`, or undefined for no data. Plain objects, arrays, strings, finite numbers,
9
+ * booleans and null pass, and a property whose value is undefined is left out, as JSON leaves it.
10
+ * Any other value fails with E1213, which names where it sits: JSON would change it or drop it, so
11
+ * the sketch and a replay would see other data than the page gave.
12
+ */
13
+ export function sketchDataText(data) {
14
+ if (data === undefined)
15
+ return undefined;
16
+ checkValue(data, 'sketchData', new Set());
17
+ const text = JSON.stringify(data);
18
+ const bytes = new TextEncoder().encode(text).length;
19
+ if (bytes > MAX_SKETCH_DATA_BYTES)
20
+ throw new EngineError('E1213', `createEngine() got sketchData of ${bytes.toLocaleString('en')} bytes as JSON, over the limit of ${MAX_SKETCH_DATA_BYTES.toLocaleString('en')}. Pass a small start state, and load larger data in the sketch as a file.`);
21
+ return text;
22
+ }
23
+ /** Throws E1213 when `value`, at `path` in the data, is not plain JSON data. */
24
+ function checkValue(value, path, parents) {
25
+ if (value === null || typeof value === 'string' || typeof value === 'boolean')
26
+ return;
27
+ if (typeof value === 'number') {
28
+ if (Number.isFinite(value))
29
+ return;
30
+ refuse(path, String(value));
31
+ }
32
+ if (typeof value !== 'object')
33
+ refuse(path, `a ${typeof value}`);
34
+ if (parents.has(value))
35
+ refuse(path, 'an object that holds it');
36
+ parents.add(value);
37
+ if (Array.isArray(value)) {
38
+ for (let index = 0; index < value.length; index++) {
39
+ const item = value[index];
40
+ if (item === undefined)
41
+ refuse(`${path}[${index}]`, 'undefined');
42
+ checkValue(item, `${path}[${index}]`, parents);
43
+ }
44
+ }
45
+ else {
46
+ const prototype = Object.getPrototypeOf(value);
47
+ if (prototype !== Object.prototype && prototype !== null)
48
+ refuse(path, `a ${value.constructor?.name ?? 'class instance'}`);
49
+ for (const [key, item] of Object.entries(value))
50
+ if (item !== undefined)
51
+ checkValue(item, `${path}.${key}`, parents);
52
+ }
53
+ parents.delete(value);
54
+ }
55
+ function refuse(path, what) {
56
+ throw new EngineError('E1213', `createEngine() got sketchData where ${path} is ${what}. sketchData takes plain JSON data: objects, arrays, strings, finite numbers, booleans and null.`);
57
+ }
@@ -5,3 +5,12 @@
5
5
  * @category api/engine
6
6
  */
7
7
  export type Tier = 'webgpu' | 'webgpu-compat' | 'webgl2';
8
+ /**
9
+ * A GPU path that a build can ship: WebGPU, whose shaders are WGSL, or WebGL2, whose shaders are
10
+ * GLSL ES 3.00. WebGPU's compatibility mode draws with the WebGPU shaders.
11
+ *
12
+ * @category api/engine
13
+ */
14
+ export type GpuPath = 'webgpu' | 'webgl2';
15
+ /** The path whose shaders a tier draws with. */
16
+ export declare function pathOfTier(tier: Tier): GpuPath;
@@ -1,3 +1,6 @@
1
1
  // The GPU paths, in a file of their own, so code without browser types can name them: the quality
2
2
  // presets and the docs generator.
3
- export {};
3
+ /** The path whose shaders a tier draws with. */
4
+ export function pathOfTier(tier) {
5
+ return tier === 'webgl2' ? 'webgl2' : 'webgpu';
6
+ }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @category api/engine
5
5
  */
6
- export declare const VERSION = "0.1.0";
6
+ export declare const VERSION = "0.1.2";
7
7
  /**
8
8
  * The version of the plugin interface that an add-on from another developer builds against. It is
9
9
  * a whole number, and it changes only when a stable add-on hook changes, never with every engine
@@ -11,7 +11,7 @@ import { DEV } from './dev.js';
11
11
  *
12
12
  * @category api/engine
13
13
  */
14
- export const VERSION = '0.1.0';
14
+ export const VERSION = '0.1.2';
15
15
  /**
16
16
  * The version of the plugin interface that an add-on from another developer builds against. It is
17
17
  * a whole number, and it changes only when a stable add-on hook changes, never with every engine
@@ -135,11 +135,19 @@ export interface SketchPreferences {
135
135
  onChange(handler: () => void): () => void;
136
136
  }
137
137
  /**
138
- * What the engine passes to a sketch's setup function.
138
+ * What the engine passes to a sketch's setup function. `Data` is the type of the start data that
139
+ * the page passes, which `defineSketch<Data>` names.
139
140
  *
140
141
  * @category api/sketch
141
142
  */
142
- export interface SketchContext {
143
+ export interface SketchContext<Data = unknown> {
144
+ /**
145
+ * The start data that the page passed as `createEngine`'s `sketchData`, or undefined when it
146
+ * passed none. It is there from the start of the setup, before the first frame, also in hold
147
+ * mode. The sketch gets its own copy, so a change to it reaches neither the page nor a replay.
148
+ * A replay gives the data that the recording keeps.
149
+ */
150
+ readonly data: Data | undefined;
143
151
  /** Objects, cameras, lights and instance batches. */
144
152
  scene: Scene;
145
153
  /** Material factories. */
@@ -186,7 +194,7 @@ export interface SketchContext {
186
194
  *
187
195
  * @category api/sketch
188
196
  */
189
- export type SketchSetup = (context: SketchContext) => SketchCallbacks | undefined | Promise<SketchCallbacks | undefined>;
197
+ export type SketchSetup<Data = unknown> = (context: SketchContext<Data>) => SketchCallbacks | undefined | Promise<SketchCallbacks | undefined>;
190
198
  /**
191
199
  * Options for `defineSketch`.
192
200
  *
@@ -230,21 +238,22 @@ declare const SKETCH_MARKER: unique symbol;
230
238
  *
231
239
  * @category api/sketch
232
240
  */
233
- export interface SketchDefinition {
241
+ export interface SketchDefinition<Data = unknown> {
234
242
  readonly [SKETCH_MARKER]: true;
235
243
  /** The setup function passed to `defineSketch`. */
236
- readonly setup: SketchSetup;
244
+ readonly setup: SketchSetup<Data>;
237
245
  /** The options passed to `defineSketch`. */
238
246
  readonly options: SketchOptions;
239
247
  }
240
248
  /**
241
249
  * Declares a sketch. In null3D, a 3D scene is called a sketch: a module that builds the scene and
242
250
  * updates it every frame, in the sketch worker. The module must export the result as its default
243
- * export. `options` sets the rate of the fixed steps.
251
+ * export. `options` sets the rate of the fixed steps. `Data` types the start data that the setup
252
+ * reads as `ctx.data`, such as `defineSketch<{ stop: string }>(...)`.
244
253
  *
245
254
  * @category api/sketch
246
255
  */
247
- export declare function defineSketch(setup: SketchSetup, options?: SketchOptions): SketchDefinition;
256
+ export declare function defineSketch<Data = unknown>(setup: SketchSetup<Data>, options?: SketchOptions): SketchDefinition<Data>;
248
257
  /** Imports the module at an address. */
249
258
  type ModuleImport = (url: string) => Promise<{
250
259
  default?: unknown;
@@ -19,7 +19,8 @@ const SKETCH_MARKER = Symbol.for('null3d.sketch');
19
19
  /**
20
20
  * Declares a sketch. In null3D, a 3D scene is called a sketch: a module that builds the scene and
21
21
  * updates it every frame, in the sketch worker. The module must export the result as its default
22
- * export. `options` sets the rate of the fixed steps.
22
+ * export. `options` sets the rate of the fixed steps. `Data` types the start data that the setup
23
+ * reads as `ctx.data`, such as `defineSketch<{ stop: string }>(...)`.
23
24
  *
24
25
  * @category api/sketch
25
26
  */
@@ -46,6 +46,8 @@ export interface SketchCore {
46
46
  pageUrl: string;
47
47
  /** The sketch module's address, which a recording keeps and a replay compares. */
48
48
  sketchUrl: string;
49
+ /** The start data that the page passed, as JSON text, which the sketch reads as `ctx.data`. */
50
+ data?: string;
49
51
  /**
50
52
  * The highest frame rate that the preset check and the governor aim for: the page's `targetFps`
51
53
  * setting under the ?fps= cap, and infinity for the display's full rate.
@@ -272,6 +274,8 @@ export declare class SketchRunner {
272
274
  private replaying;
273
275
  /** True when the page records this session's frames and input. */
274
276
  private readonly records;
277
+ /** The start data as JSON text: a replay's own, or the page's. A recording keeps it. */
278
+ private readonly dataText;
275
279
  /**
276
280
  * True when the session runs fixed frames rather than the page's: hold mode, which steps to a
277
281
  * time, or a replay, which steps through a recording.
@@ -505,6 +505,8 @@ export class SketchRunner {
505
505
  replaying = false;
506
506
  /** True when the page records this session's frames and input. */
507
507
  records;
508
+ /** The start data as JSON text: a replay's own, or the page's. A recording keeps it. */
509
+ dataText;
508
510
  /**
509
511
  * True when the session runs fixed frames rather than the page's: hold mode, which steps to a
510
512
  * time, or a replay, which steps through a recording.
@@ -535,6 +537,7 @@ export class SketchRunner {
535
537
  this.holdScript = holdScript;
536
538
  this.replayProgram = replay;
537
539
  this.records = record;
540
+ this.dataText = replay === undefined ? sketch.data : replay.data;
538
541
  this.holdsFrames = holdSeconds !== undefined || replay !== undefined;
539
542
  this.record = new FrameRecorder(metrics, Role.Sketch);
540
543
  this.jobRecords = Array.from({ length: sketch.jobWorkers }, (_, k) => new FrameRecorder(metrics, Role.Job + k));
@@ -711,6 +714,7 @@ export class SketchRunner {
711
714
  }
712
715
  const holdsFrames = this.holdsFrames;
713
716
  this.context = {
717
+ data: this.dataText === undefined ? undefined : JSON.parse(this.dataText),
714
718
  time: this.time,
715
719
  engine: {
716
720
  viewport: this.viewport,
@@ -1720,6 +1724,7 @@ export class SketchRunner {
1720
1724
  return this.recorder.encode({
1721
1725
  fixedRate: Math.round(1 / this.fixed.step),
1722
1726
  sketch: this.sketch.sketchUrl,
1727
+ data: this.dataText,
1723
1728
  });
1724
1729
  }
1725
1730
  /** The dump steps that fall at the frame that is about to run, which read it after it ran. */