@null3d/engine 0.0.0 → 0.1.1

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 (517) hide show
  1. package/README.md +109 -0
  2. package/THIRD-PARTY-NOTICES.txt +0 -1
  3. package/dist/wasm/single/null3d.js +25 -10
  4. package/dist/wasm/single/null3d_bg.wasm +0 -0
  5. package/dist/wasm/threaded/null3d.js +25 -10
  6. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  7. package/docs/api/animation.md +114 -86
  8. package/docs/api/assets.md +135 -49
  9. package/docs/api/cameras.md +45 -12
  10. package/docs/api/controls.md +88 -62
  11. package/docs/api/debug.md +116 -41
  12. package/docs/api/engine.md +117 -35
  13. package/docs/api/feature-draws.md +23 -17
  14. package/docs/api/feature-effects.md +11 -11
  15. package/docs/api/feature-instances.md +70 -19
  16. package/docs/api/features.md +77 -47
  17. package/docs/api/geometry.md +132 -82
  18. package/docs/api/grass.md +55 -13
  19. package/docs/api/impostors.md +175 -22
  20. package/docs/api/input.md +24 -18
  21. package/docs/api/lights.md +78 -51
  22. package/docs/api/lines.md +41 -33
  23. package/docs/api/materials.md +248 -121
  24. package/docs/api/math.md +12 -13
  25. package/docs/api/objects.md +47 -22
  26. package/docs/api/page.md +58 -7
  27. package/docs/api/particles.md +33 -20
  28. package/docs/api/points.md +19 -31
  29. package/docs/api/post.md +75 -42
  30. package/docs/api/quality.md +42 -17
  31. package/docs/api/raycast.md +65 -51
  32. package/docs/api/reference/animation.md +10 -11
  33. package/docs/api/reference/assets.md +25 -22
  34. package/docs/api/reference/cameras.md +8 -4
  35. package/docs/api/reference/controls.md +134 -25
  36. package/docs/api/reference/debug.md +81 -14
  37. package/docs/api/reference/engine.md +58 -17
  38. package/docs/api/reference/feature-draws.md +3 -4
  39. package/docs/api/reference/feature-effects.md +2 -3
  40. package/docs/api/reference/feature-instances.md +5 -4
  41. package/docs/api/reference/features.md +7 -4
  42. package/docs/api/reference/geometry.md +287 -97
  43. package/docs/api/reference/grass.md +63 -3
  44. package/docs/api/reference/impostors.md +208 -13
  45. package/docs/api/reference/input.md +4 -5
  46. package/docs/api/reference/lights.md +13 -12
  47. package/docs/api/reference/lines.md +10 -11
  48. package/docs/api/reference/materials.md +54 -53
  49. package/docs/api/reference/math.md +35 -24
  50. package/docs/api/reference/objects.md +11 -12
  51. package/docs/api/reference/particles.md +31 -6
  52. package/docs/api/reference/points.md +6 -7
  53. package/docs/api/reference/post.md +21 -20
  54. package/docs/api/reference/quality.md +8 -5
  55. package/docs/api/reference/raycast.md +7 -8
  56. package/docs/api/reference/render.md +5 -4
  57. package/docs/api/reference/scene.md +52 -30
  58. package/docs/api/reference/sketch.md +15 -11
  59. package/docs/api/reference/sound.md +234 -0
  60. package/docs/api/reference/splats.md +42 -3
  61. package/docs/api/reference/sprites.md +7 -8
  62. package/docs/api/reference/tasks.md +16 -3
  63. package/docs/api/reference/terrain.md +27 -5
  64. package/docs/api/reference/textures.md +5 -6
  65. package/docs/api/reference/three-compat.md +18 -7
  66. package/docs/api/reference/time.md +1 -2
  67. package/docs/api/reference/ui.md +12 -9
  68. package/docs/api/reference/vertex-draws.md +5 -6
  69. package/docs/api/reference/water.md +153 -9
  70. package/docs/api/reference/wind.md +17 -4
  71. package/docs/api/render.md +73 -29
  72. package/docs/api/scene.md +164 -60
  73. package/docs/api/sketch.md +102 -15
  74. package/docs/api/sound.md +205 -0
  75. package/docs/api/splats.md +46 -12
  76. package/docs/api/sprites.md +10 -24
  77. package/docs/api/tasks.md +33 -24
  78. package/docs/api/terrain.md +42 -22
  79. package/docs/api/textures.md +68 -19
  80. package/docs/api/three-compat.md +15 -7
  81. package/docs/api/time.md +3 -5
  82. package/docs/api/ui.md +19 -23
  83. package/docs/api/vertex-draws.md +13 -12
  84. package/docs/api/water.md +262 -35
  85. package/docs/api/wind.md +63 -17
  86. package/docs/cli/null3d.md +177 -27
  87. package/docs/concepts/architecture.md +73 -27
  88. package/docs/concepts/assets.md +57 -33
  89. package/docs/concepts/backends.md +69 -27
  90. package/docs/concepts/color-management.md +54 -36
  91. package/docs/concepts/culling.md +68 -47
  92. package/docs/concepts/handles.md +14 -5
  93. package/docs/concepts/instances.md +74 -25
  94. package/docs/concepts/large-worlds.md +18 -8
  95. package/docs/concepts/lighting.md +155 -87
  96. package/docs/concepts/lod.md +126 -44
  97. package/docs/concepts/materials.md +58 -27
  98. package/docs/concepts/particle-buffer.md +48 -35
  99. package/docs/concepts/post-processing.md +84 -43
  100. package/docs/concepts/quality-preset-tables.md +56 -52
  101. package/docs/concepts/quality-presets.md +164 -52
  102. package/docs/concepts/render-graph.md +69 -29
  103. package/docs/concepts/render-layers.md +11 -21
  104. package/docs/concepts/shadows.md +105 -52
  105. package/docs/concepts/static-dynamic.md +22 -7
  106. package/docs/cookbook/index.md +164 -120
  107. package/docs/data/threejs-mapping.json +362 -367
  108. package/docs/errors/E1101.md +23 -5
  109. package/docs/errors/E1102.md +11 -3
  110. package/docs/errors/E1103.md +11 -3
  111. package/docs/errors/E1104.md +11 -3
  112. package/docs/errors/E1105.md +13 -5
  113. package/docs/errors/E1106.md +11 -3
  114. package/docs/errors/E1107.md +15 -5
  115. package/docs/errors/E1108.md +11 -3
  116. package/docs/errors/E1109.md +32 -6
  117. package/docs/errors/E1110.md +23 -5
  118. package/docs/errors/E1111.md +11 -3
  119. package/docs/errors/E1112.md +11 -3
  120. package/docs/errors/E1203.md +12 -4
  121. package/docs/errors/E1204.md +11 -3
  122. package/docs/errors/E1205.md +11 -3
  123. package/docs/errors/E1206.md +28 -6
  124. package/docs/errors/E1207.md +11 -3
  125. package/docs/errors/E1208.md +12 -3
  126. package/docs/errors/E1209.md +11 -3
  127. package/docs/errors/E1213.md +27 -5
  128. package/docs/errors/E1214.md +14 -6
  129. package/docs/errors/E1215.md +31 -6
  130. package/docs/errors/E1216.md +31 -6
  131. package/docs/errors/E1217.md +29 -6
  132. package/docs/errors/E1218.md +22 -6
  133. package/docs/errors/E1219.md +11 -3
  134. package/docs/errors/E1220.md +24 -5
  135. package/docs/errors/E1221.md +24 -5
  136. package/docs/errors/E1222.md +11 -3
  137. package/docs/errors/E1223.md +39 -6
  138. package/docs/errors/E1224.md +11 -3
  139. package/docs/errors/E1225.md +11 -3
  140. package/docs/errors/E1301.md +11 -3
  141. package/docs/errors/E1302.md +11 -3
  142. package/docs/errors/E1303.md +11 -3
  143. package/docs/errors/E1304.md +11 -3
  144. package/docs/errors/E1305.md +13 -3
  145. package/docs/errors/E1306.md +11 -3
  146. package/docs/errors/E1307.md +40 -0
  147. package/docs/errors/E1401.md +11 -3
  148. package/docs/errors/E1402.md +13 -5
  149. package/docs/errors/E1403.md +11 -3
  150. package/docs/errors/E1404.md +13 -3
  151. package/docs/errors/E1405.md +15 -4
  152. package/docs/errors/E1406.md +31 -5
  153. package/docs/errors/E1407.md +11 -3
  154. package/docs/errors/E1408.md +11 -3
  155. package/docs/errors/E1409.md +11 -3
  156. package/docs/errors/E1410.md +13 -5
  157. package/docs/errors/E1411.md +11 -3
  158. package/docs/errors/E1412.md +29 -6
  159. package/docs/errors/E1413.md +11 -3
  160. package/docs/errors/E1414.md +11 -3
  161. package/docs/errors/E1415.md +11 -3
  162. package/docs/errors/E1416.md +27 -6
  163. package/docs/errors/E1417.md +11 -3
  164. package/docs/errors/E1418.md +12 -3
  165. package/docs/errors/E1419.md +13 -5
  166. package/docs/errors/E1420.md +14 -6
  167. package/docs/errors/E1421.md +11 -3
  168. package/docs/errors/E1422.md +12 -3
  169. package/docs/errors/E1423.md +12 -3
  170. package/docs/errors/E1424.md +24 -5
  171. package/docs/errors/E1425.md +11 -3
  172. package/docs/errors/E1426.md +11 -3
  173. package/docs/errors/E1430.md +11 -3
  174. package/docs/errors/E1431.md +11 -3
  175. package/docs/errors/E1432.md +11 -3
  176. package/docs/errors/E1433.md +11 -3
  177. package/docs/errors/E1434.md +15 -6
  178. package/docs/errors/E1435.md +11 -3
  179. package/docs/errors/E1436.md +11 -3
  180. package/docs/errors/E1437.md +14 -6
  181. package/docs/errors/E1501.md +41 -6
  182. package/docs/errors/E1502.md +13 -3
  183. package/docs/errors/E1503.md +11 -3
  184. package/docs/errors/E1504.md +11 -3
  185. package/docs/errors/E1505.md +23 -5
  186. package/docs/errors/E1506.md +11 -3
  187. package/docs/errors/index.md +54 -30
  188. package/docs/getting-started/cdn.md +32 -10
  189. package/docs/getting-started/first-scene.md +21 -13
  190. package/docs/getting-started/hosting.md +152 -63
  191. package/docs/getting-started/install.md +44 -28
  192. package/docs/getting-started/network-use.md +33 -15
  193. package/docs/getting-started/project-structure.md +33 -12
  194. package/docs/getting-started/third-party-notices.md +12 -14
  195. package/docs/guides/accessibility.md +5 -5
  196. package/docs/guides/add-ons.md +86 -15
  197. package/docs/guides/agents.md +16 -9
  198. package/docs/guides/assets-pipeline.md +259 -82
  199. package/docs/guides/audio.md +115 -128
  200. package/docs/guides/baked-light-data.md +44 -23
  201. package/docs/guides/car-paint.md +38 -32
  202. package/docs/guides/content-pages.md +63 -35
  203. package/docs/guides/custom-passes.md +65 -22
  204. package/docs/guides/custom-shaders.md +59 -39
  205. package/docs/guides/debugging.md +74 -10
  206. package/docs/guides/deploying.md +85 -6
  207. package/docs/guides/deterministic-simulation.md +24 -17
  208. package/docs/guides/first-use-shaders.md +83 -45
  209. package/docs/guides/lens-kit.md +29 -26
  210. package/docs/guides/loading-screens.md +132 -47
  211. package/docs/guides/multiple-views.md +63 -13
  212. package/docs/guides/performance.md +192 -38
  213. package/docs/guides/phones.md +78 -15
  214. package/docs/guides/physics.md +7 -11
  215. package/docs/guides/screens.md +47 -33
  216. package/docs/guides/start-time.md +363 -0
  217. package/docs/guides/testing.md +152 -95
  218. package/docs/guides/ui-overlays.md +19 -14
  219. package/docs/guides/video-textures.md +14 -13
  220. package/docs/images/api/animation/character.webp +0 -0
  221. package/docs/images/api/animation/look-at-ring.webp +0 -0
  222. package/docs/images/api/animation/morph-tulips.webp +0 -0
  223. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  224. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  225. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  226. package/docs/images/api/debug/debug-shapes.webp +0 -0
  227. package/docs/images/api/debug/levels-view.webp +0 -0
  228. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  229. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  230. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  231. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  232. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  233. package/docs/images/api/geometry/generators.webp +0 -0
  234. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  235. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  236. package/docs/images/api/grass/grass-grove.webp +0 -0
  237. package/docs/images/api/grass/grass-presets.webp +0 -0
  238. package/docs/images/api/grass/grass-shadow.webp +0 -0
  239. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  240. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  241. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  242. package/docs/images/api/lights/spot-cookies.webp +0 -0
  243. package/docs/images/api/lines/lines-lit.webp +0 -0
  244. package/docs/images/api/lines/lines-widths.webp +0 -0
  245. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  246. package/docs/images/api/materials/decals.webp +0 -0
  247. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  248. package/docs/images/api/materials/relief.webp +0 -0
  249. package/docs/images/api/materials/shader-inputs.webp +0 -0
  250. package/docs/images/api/materials/standard-grid.webp +0 -0
  251. package/docs/images/api/materials/subsurface.webp +0 -0
  252. package/docs/images/api/materials/translucency.webp +0 -0
  253. package/docs/images/api/objects/objects-turntable.webp +0 -0
  254. package/docs/images/api/particles/campfire.webp +0 -0
  255. package/docs/images/api/points/galaxy.webp +0 -0
  256. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  257. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  258. package/docs/images/api/render/reflection-mirror.webp +0 -0
  259. package/docs/images/api/render/security-camera.webp +0 -0
  260. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  261. package/docs/images/api/sound/sound-demo.webp +0 -0
  262. package/docs/images/api/splats/splats-demo.webp +0 -0
  263. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  264. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  265. package/docs/images/api/textures/canvas-screen.webp +0 -0
  266. package/docs/images/api/textures/mipmaps.webp +0 -0
  267. package/docs/images/api/vertex-draws/rain.webp +0 -0
  268. package/docs/images/api/water/ocean.webp +0 -0
  269. package/docs/images/api/water/water-demo.webp +0 -0
  270. package/docs/images/api/water/water-rain.webp +0 -0
  271. package/docs/images/api/water/waterfall.webp +0 -0
  272. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  273. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  274. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  275. package/docs/images/concepts/instances/instances.webp +0 -0
  276. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  277. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  278. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  279. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  280. package/docs/images/concepts/lighting/environment.webp +0 -0
  281. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  282. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  283. package/docs/images/concepts/lod/forest.webp +0 -0
  284. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  285. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  286. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  287. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  288. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  289. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  290. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  291. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  292. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  293. package/docs/images/cookbook/index/picking.webp +0 -0
  294. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  295. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  296. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  297. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  298. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  299. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  300. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  301. package/docs/images/index/showcase-island.webp +0 -0
  302. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  303. package/docs/images/shaders/builtins/builtins.webp +0 -0
  304. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  305. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  306. package/docs/images/shots.json +2231 -0
  307. package/docs/index.md +18 -23
  308. package/docs/moves.json +1 -0
  309. package/docs/nav.json +300 -0
  310. package/docs/pages.md +230 -209
  311. package/docs/porting/react-three-fiber.md +225 -6
  312. package/docs/porting/threejs-loop-and-threads.md +217 -7
  313. package/docs/porting/threejs-mapping.md +1249 -233
  314. package/docs/porting/threejs-materials.md +218 -6
  315. package/docs/porting/threejs-overview.md +240 -7
  316. package/docs/porting/threejs-postprocessing.md +4 -8
  317. package/docs/porting/threejs-shaders.md +301 -6
  318. package/docs/porting/threejs-unsupported.md +83 -7
  319. package/docs/porting/verification.md +178 -6
  320. package/docs/shaders/builtins.md +15 -4
  321. package/docs/shaders/library.md +72 -45
  322. package/docs/shaders/surface-functions.md +59 -23
  323. package/docs/shaders/wgsl-rules.md +12 -5
  324. package/lib/debug/channel.d.ts +103 -0
  325. package/lib/debug/channel.js +269 -0
  326. package/lib/debug/debug.d.ts +11 -9
  327. package/lib/debug/draw.d.ts +11 -2
  328. package/lib/debug/draw.js +57 -6
  329. package/lib/debug/inspector.d.ts +60 -0
  330. package/lib/debug/inspector.js +475 -0
  331. package/lib/debug/overlay-look.d.ts +6 -0
  332. package/lib/debug/overlay-look.js +29 -7
  333. package/lib/debug/overlay.js +15 -11
  334. package/lib/debug/stats-options.d.ts +13 -0
  335. package/lib/debug/stats-panel.d.ts +22 -7
  336. package/lib/debug/stats-panel.js +80 -13
  337. package/lib/debug/stats.d.ts +2 -3
  338. package/lib/errors/codes.d.ts +17 -3
  339. package/lib/errors/codes.js +117 -105
  340. package/lib/errors/engine-error.js +25 -10
  341. package/lib/errors/fixes.d.ts +1 -0
  342. package/lib/errors/fixes.js +20 -19
  343. package/lib/generated/core.d.ts +1 -1
  344. package/lib/generated/core.js +1 -1
  345. package/lib/gpu/early-builds.d.ts +68 -0
  346. package/lib/gpu/early-builds.js +158 -0
  347. package/lib/gpu/pipeline-name.d.ts +6 -0
  348. package/lib/gpu/pipeline-name.js +23 -0
  349. package/lib/gpu/variants.d.ts +8 -2
  350. package/lib/gpu/variants.js +39 -7
  351. package/lib/gpu/webgl2/backend.d.ts +63 -2
  352. package/lib/gpu/webgl2/backend.js +226 -8
  353. package/lib/gpu/webgl2/programs.d.ts +18 -0
  354. package/lib/gpu/webgl2/programs.js +5 -2
  355. package/lib/gpu/webgpu/backend.d.ts +89 -2
  356. package/lib/gpu/webgpu/backend.js +255 -8
  357. package/lib/gpu/webgpu/pipelines.d.ts +13 -0
  358. package/lib/gpu/webgpu/pipelines.js +28 -14
  359. package/lib/index.d.ts +7 -5
  360. package/lib/index.js +3 -2
  361. package/lib/math/color.d.ts +5 -5
  362. package/lib/math/color.js +5 -5
  363. package/lib/math/mat4.d.ts +6 -12
  364. package/lib/math/mat4.js +6 -12
  365. package/lib/math/namespaces/quat.d.ts +3 -3
  366. package/lib/math/namespaces/quat.js +3 -3
  367. package/lib/math/quat.d.ts +8 -12
  368. package/lib/math/quat.js +8 -12
  369. package/lib/math/random.d.ts +2 -3
  370. package/lib/math/random.js +2 -3
  371. package/lib/math/types.d.ts +4 -4
  372. package/lib/math/vec3.d.ts +3 -6
  373. package/lib/math/vec3.js +3 -6
  374. package/lib/page/capabilities.d.ts +8 -8
  375. package/lib/page/capabilities.js +39 -25
  376. package/lib/page/check-store.d.ts +14 -2
  377. package/lib/page/check-store.js +34 -11
  378. package/lib/page/engine.d.ts +117 -31
  379. package/lib/page/engine.js +438 -99
  380. package/lib/page/first-frame.d.ts +16 -0
  381. package/lib/page/first-frame.js +35 -0
  382. package/lib/page/frame-stats.d.ts +34 -1
  383. package/lib/page/frame-stats.js +15 -0
  384. package/lib/page/label-loop.d.ts +7 -3
  385. package/lib/page/label-loop.js +26 -14
  386. package/lib/page/labels.d.ts +3 -3
  387. package/lib/page/pipeline-store.d.ts +25 -0
  388. package/lib/page/pipeline-store.js +84 -0
  389. package/lib/page/start-marker.d.ts +4 -1
  390. package/lib/page/start-marker.js +5 -2
  391. package/lib/page/stats-switch.js +2 -0
  392. package/lib/page/switches.d.ts +38 -6
  393. package/lib/page/switches.js +29 -5
  394. package/lib/quality/check.d.ts +24 -3
  395. package/lib/quality/check.js +21 -7
  396. package/lib/quality/chooser.d.ts +6 -0
  397. package/lib/quality/chooser.js +8 -0
  398. package/lib/quality/governor.d.ts +98 -6
  399. package/lib/quality/governor.js +250 -20
  400. package/lib/quality/preset-docs.d.ts +16 -1
  401. package/lib/quality/preset-docs.js +3 -0
  402. package/lib/quality/presets.d.ts +84 -7
  403. package/lib/quality/presets.js +94 -2
  404. package/lib/render/draw.d.ts +3 -2
  405. package/lib/render/draw.js +15 -5
  406. package/lib/render/load-draw.d.ts +7 -5
  407. package/lib/render/load-draw.js +7 -5
  408. package/lib/render/loss.d.ts +28 -10
  409. package/lib/render/loss.js +50 -22
  410. package/lib/render/recovery.d.ts +20 -0
  411. package/lib/render/recovery.js +44 -4
  412. package/lib/render/renderer.d.ts +85 -9
  413. package/lib/render/renderer.js +181 -42
  414. package/lib/render/scene-renderer.d.ts +19 -1
  415. package/lib/render/scene-renderer.js +25 -1
  416. package/lib/render/webgl2-renderers.js +8 -5
  417. package/lib/render/webgpu-renderers.js +5 -4
  418. package/lib/scene/animation.d.ts +28 -32
  419. package/lib/scene/animation.js +12 -15
  420. package/lib/scene/assets.d.ts +61 -86
  421. package/lib/scene/assets.js +103 -236
  422. package/lib/scene/background.d.ts +14 -18
  423. package/lib/scene/background.js +5 -2
  424. package/lib/scene/baked-light.d.ts +2 -2
  425. package/lib/scene/color.d.ts +3 -3
  426. package/lib/scene/downloads.d.ts +2 -0
  427. package/lib/scene/downloads.js +371 -0
  428. package/lib/scene/environment.d.ts +7 -7
  429. package/lib/scene/environment.js +1 -1
  430. package/lib/scene/fake-call-values.js +3 -3
  431. package/lib/scene/fog.d.ts +11 -4
  432. package/lib/scene/fog.js +8 -2
  433. package/lib/scene/frame-cameras.d.ts +35 -4
  434. package/lib/scene/frame-cameras.js +86 -10
  435. package/lib/scene/gltf.d.ts +33 -3
  436. package/lib/scene/gltf.js +78 -49
  437. package/lib/scene/grading.d.ts +2 -2
  438. package/lib/scene/grading.js +3 -3
  439. package/lib/scene/ktx2.d.ts +9 -1
  440. package/lib/scene/ktx2.js +3 -2
  441. package/lib/scene/level-rule.d.ts +121 -0
  442. package/lib/scene/level-rule.js +130 -0
  443. package/lib/scene/lines.d.ts +13 -17
  444. package/lib/scene/lines.js +3 -3
  445. package/lib/scene/lut.d.ts +1 -2
  446. package/lib/scene/lut.js +1 -2
  447. package/lib/scene/particles.d.ts +7 -3
  448. package/lib/scene/particles.js +3 -1
  449. package/lib/scene/picks.d.ts +2 -2
  450. package/lib/scene/pointer-events.d.ts +4 -7
  451. package/lib/scene/post.d.ts +39 -43
  452. package/lib/scene/post.js +4 -1
  453. package/lib/scene/prefab.d.ts +7 -8
  454. package/lib/scene/prefab.js +7 -8
  455. package/lib/scene/property-animation.d.ts +1 -1
  456. package/lib/scene/property-animation.js +1 -1
  457. package/lib/scene/queries.d.ts +7 -13
  458. package/lib/scene/resources.d.ts +238 -261
  459. package/lib/scene/resources.js +179 -81
  460. package/lib/scene/scene.d.ts +167 -120
  461. package/lib/scene/scene.js +243 -103
  462. package/lib/scene/serial-loads.d.ts +29 -0
  463. package/lib/scene/serial-loads.js +68 -0
  464. package/lib/scene/shader-preloads.d.ts +34 -0
  465. package/lib/scene/shader-preloads.js +38 -0
  466. package/lib/scene/sprites.d.ts +14 -17
  467. package/lib/scene/sprites.js +5 -6
  468. package/lib/scene/textures.d.ts +11 -12
  469. package/lib/scene/textures.js +9 -10
  470. package/lib/scene/time-of-day.d.ts +11 -7
  471. package/lib/scene/time-of-day.js +11 -8
  472. package/lib/scene/vertex-draws.d.ts +5 -4
  473. package/lib/scene/vertex-draws.js +7 -5
  474. package/lib/shader-artifact.json +1 -0
  475. package/lib/shared/core.d.ts +5 -0
  476. package/lib/shared/core.js +1 -0
  477. package/lib/shared/import-once.d.ts +6 -0
  478. package/lib/shared/import-once.js +19 -0
  479. package/lib/shared/labels.d.ts +5 -2
  480. package/lib/shared/labels.js +5 -2
  481. package/lib/shared/metrics.d.ts +38 -0
  482. package/lib/shared/metrics.js +62 -1
  483. package/lib/shared/permutation-words.d.ts +2 -0
  484. package/lib/shared/permutation-words.js +8 -0
  485. package/lib/shared/recording.d.ts +13 -5
  486. package/lib/shared/recording.js +31 -10
  487. package/lib/shared/run-task.js +7 -1
  488. package/lib/shared/sketch-data.d.ts +9 -0
  489. package/lib/shared/sketch-data.js +57 -0
  490. package/lib/shared/task-pending.d.ts +12 -0
  491. package/lib/shared/task-pending.js +61 -1
  492. package/lib/shared/tasks.js +79 -32
  493. package/lib/shared/version.d.ts +17 -1
  494. package/lib/shared/version.js +19 -1
  495. package/lib/shared/wasm.d.ts +12 -4
  496. package/lib/shared/wasm.js +50 -27
  497. package/lib/shared/worker-start.d.ts +7 -0
  498. package/lib/shared/worker-start.js +27 -0
  499. package/lib/sketch/define-sketch.d.ts +51 -7
  500. package/lib/sketch/define-sketch.js +2 -1
  501. package/lib/sketch/input.d.ts +2 -2
  502. package/lib/sketch/preset-check.d.ts +20 -6
  503. package/lib/sketch/preset-check.js +42 -17
  504. package/lib/sketch/quality.d.ts +69 -11
  505. package/lib/sketch/quality.js +54 -13
  506. package/lib/sketch/runner.d.ts +80 -9
  507. package/lib/sketch/runner.js +390 -52
  508. package/lib/sketch/ui.d.ts +5 -8
  509. package/lib/sketch/ui.js +4 -2
  510. package/lib/stats.d.ts +1 -0
  511. package/lib/workers/probe-worker.d.ts +5 -0
  512. package/lib/workers/probe-worker.js +13 -4
  513. package/lib/workers/protocol.d.ts +71 -13
  514. package/lib/workers/protocol.js +4 -0
  515. package/lib/workers/render-worker.js +29 -5
  516. package/lib/workers/sketch-worker.js +108 -16
  517. package/package.json +2 -2
@@ -1,8 +1,7 @@
1
1
  ---
2
2
  id: api/reference/quality
3
3
  title: "Quality API: API reference"
4
- status: generated
5
- since: "0.1"
4
+ generated: true
6
5
  summary: "Every export of the Quality API API, from the engine's doc comments."
7
6
  ---
8
7
 
@@ -49,7 +48,7 @@ What the preset check measured when the engine started, as `engine.mode.presetCh
49
48
  | `from: QualityPreset` | The preset that the engine chose from the device before the check. |
50
49
  | `targetFps: number` | The frame rate that each preset had to hold: the display's refresh rate, at most 60 or at most the page's `targetFps` option. |
51
50
  | `rounds: PresetCheckRound[]` | Each preset that the check measured, from `from` down. The last is the preset that the engine runs. |
52
- | `reused: boolean` | True when the engine took this result from an earlier start of the sketch in this browser on this device, and did not measure again. The engine stores each check's result for a week. |
51
+ | `reused: boolean` | True when the engine took this result from an earlier start of the sketch in this browser on this device, and did not measure again. The engine stores each check's result for a week. A check that went on from the rounds of an earlier start, whose check never ended, is false, and lists those rounds first. |
53
52
 
54
53
  ## `PresetCheckRound`
55
54
 
@@ -124,6 +123,7 @@ What the frame-budget governor has lowered, in `quality.governor`. It lowers a s
124
123
  | `readonly ssrScale: number` | The size of screen-space reflections' grid now: `settings.ssrScale`, or a quarter of the render size after the governor's step that follows ambient occlusion's while reflections draw. |
125
124
  | `readonly contactShadowSteps: number` | The steps of each search for the sun's contact shadows now: `settings.contactShadowSteps`, or the fewest after the governor's last step. |
126
125
  | `readonly farAnimationInterval: number` | The frames between two updates of a far character's pose now. It is `settings.farAnimationInterval`, or up to twice as long for each of the governor's last steps, at most every 4th frame. Give it to `animator.setUpdateInterval` for the characters that the camera sees from far. |
126
+ | `readonly lowest: boolean` | True while the lowest quality tier applies: the render scale's floor has fallen to a third, the sun's cast shadows and bloom are off, reflections draw at a quarter of the render size, and WebGL2 draws no depth prepass. The governor enters the tier when the scale has held at the preset's floor through its sustained window and the frames still miss. It leaves the tier when the frames keep room through the window that raises a step. |
127
127
 
128
128
  ## `QualityPreset`
129
129
 
@@ -152,7 +152,9 @@ The quality settings that a sketch reads and changes through `ctx.quality`. Each
152
152
  | `followMovingCasters: boolean` | True when a far shadow cascade draws in every frame while a dynamic object that casts shadows touches it, so moving shadows stay under their casters. False keeps each far cascade to its turns of `farCascadeInterval` frames: a moving shadow in a far cascade then trails its caster by up to that many frames less one, and the frames draw fewer shadow passes. The governor then leaves `farCascadeInterval` as set, so the trail never grows. Every preset turns it on. It changes during play. |
153
153
  | `farAnimationInterval: number` | How often a far character's pose updates: once in this many frames, from 1 to 4. Give it to `animator.setUpdateInterval` for the characters that the camera sees from far. Give 1 to the ones near it, so a crowd samples and skins less without a near character stepping. The governor raises it when frames take too long, after its shadow and effect steps and before its step of the volumetric fog. It changes during play. |
154
154
  | `shadowCascadeBlend: number` | The share of each shadow cascade's length, at its far end, over which its shadow blends into the next cascade's, from 0 to 0.5. The blend hides the line where a near cascade's sharper shadows hand over to a far cascade's softer ones. Pixels in the band read both cascades, so a wider band costs a little more. 0 hands over at once. It changes during play. |
155
+ | `castShadows: boolean` | True while the scene draws the sun's cast shadows, which a sketch gives its directional lights' `castShadows` option. Every preset starts it on. The lowest quality tier turns it off when the frames still miss with the render scale at the preset's floor. It changes during play. |
155
156
  | `bloomSize: 64 \| 128 \| 256 \| 512` | The texels on the short side of the largest level of bloom's chain: 64, 128, 256 or 512. A smaller value costs less and keeps the glow's size, with a softer core. The base never takes more than half the canvas's short side. It changes during play, which makes bloom's targets again. |
157
+ | `bloom: boolean` | True while the sketch draws bloom's glow, which it turns on through `post.set`. Every preset starts it on. The lowest quality tier turns it off when the frames still miss with the render scale at the preset's floor. It changes during play. |
156
158
  | `aoScale: 0 \| 0.25 \| 0.5` | The size of ambient occlusion's targets, as a share of the render size each way: 0.5, 0.25, or 0, which draws no ambient occlusion even when `post.set` turns it on. A smaller share costs less, with softer occlusion. It changes during play: 0.5 and 0.25 make no GPU object, and a change to or from 0 adds or removes ambient occlusion's passes. |
157
159
  | `contactShadowSteps: 0 \| 4 \| 8 \| 16` | The steps of each search for the sun's contact shadows: 4, 8 or 16, or 0, which draws none. More steps find thinner contacts and cost more. Contact shadows need a directional light that casts shadows, with a `contactDistance` above 0. They read the depth of a prepass, which they turn on where the preset leaves it off. It changes during play. |
158
160
  | `dofSamples: 0 \| 16 \| 22 \| 43 \| 71` | The taps of depth of field's gather: 16, 22, 43 or 71, or 0, which draws no depth of field even when `post.set` turns it on. More taps fill a wide blur more smoothly and cost more. It changes during play. |
@@ -169,9 +171,10 @@ The quality settings that a sketch reads and changes through `ctx.quality`. Each
169
171
  | `lodThreshold: number` | The error in pixels under which a mesh's coarser level of detail draws (see `mesh.setLevels`). Each object and instance row draws the coarsest level whose error covers fewer pixels than this on the screen, at the render scale. A larger number draws coarser levels nearer the camera, which costs less. 0 draws every mesh's base level. It takes a number from 0 to 16, and changes during play. |
170
172
  | `lodShadowThreshold: number` | The error in texels of a shadow map under which a shadow caster's coarser level of detail draws in that map. Each cascade and each spot or point light's tile picks the level in its own texels, whatever the camera's distance, so a shadow map that keeps its depth between draws stays right as the camera moves. A caster whose bounds cover fewer texels than this draws nothing in the map. A larger number draws coarser casters, which costs less. 0 draws every caster's base level. It takes a number from 0 to 16, and changes during play. |
171
173
  | `lodFade: boolean` | Whether a mesh's distance band, from `setDrawRange`, fades at each edge over a short band where a dither pattern drops a growing share of the pixels, so the mesh does not pop. False cuts each edge at once. A level of detail's own hand-over follows the level: a hand-set level fades whatever this setting, and a measured one switches at once until the governor raises the threshold above about one and a half pixels, where it fades. It changes during play. |
172
- | `physicalSky: boolean` | Whether `{ atmosphere }` backgrounds draw the physical sky from its tables. False draws three.js's analytic sky in its place, with the same sun, moon, air and clouds, matched to the physical sky's brightness, and keeps the haze on distant objects. It changes during play. |
174
+ | `physicalSky: boolean` | Whether `{ atmosphere }` backgrounds draw the physical sky from its tables. False draws the analytic `{ sky }` background in its place, with the same sun, moon, air and clouds, matched to the physical sky's brightness, and keeps the haze on distant objects. It changes during play. |
173
175
  | `cloudSteps: number` | The steps of each ray of the sky's volumetric cloud tier. Above 0 the sky draws volumetric clouds in place of the flat layer, from the same cloud settings, with this many steps along each ray; 0 draws the flat layer, as the lighter presets do. It changes during play. The noise field and the tier's shaders load at its first use. The sky's environment map marches at most 16 steps, and draws them only from a start above 0, because it picks its tier's shaders then. |
174
176
  | `governor: boolean` | Whether the frame-budget governor runs. When frames take too long, it lowers the settings one step at a time: a sketch's budget and the render scale in turn, a budget's step first, so a sketch's system scales down before the render scale reaches `minRenderScale`; once the scale is at its floor, the budgets' remaining steps come first. Then it raises `lodThreshold` up to four times while a mesh has levels of detail. Then it lowers how often far shadow cascades draw, the shadow filter, bloom's size while bloom is on, ambient occlusion's scale while it draws, the scale of screen-space reflections while they draw, the steps of contact shadows, how often far characters' poses update, and the volumetric fog's slices while it draws. It raises them again, in the reverse order, once frames have time to spare. `quality.governor` reports its steps. False keeps the render scale at `maxRenderScale` and the other settings as set, as benchmarks and captures need. It changes during play. |
177
+ | `governorLevels: boolean` | Whether the governor may raise `lodThreshold` as one of its steps, trading model detail for frames. True does, up to four doublings while a mesh has levels of detail. False leaves every model's level where its distance puts it, while the governor's other steps still run, so a model stays whole near the camera on a slow device. It changes during play. |
175
178
  | `antialias: 'none' \| 'fxaa' \| 'msaa'` | How the engine smooths the edges of what it draws: `msaa` draws 4 samples per pixel, `fxaa` smooths edges in the final pass, and `none` leaves them sharp. The mode is fixed when the engine starts: the page's `antialias` option of `createEngine` sets it, and `set` does not take it. |
176
179
  | `momentTransparency: boolean` | True to blend the camera's blended surfaces in the moment transparency layer, which needs no sort and is nearer an exact back-to-front blend than `blending: 'weighted'` is, and which draws those surfaces twice. The mode is fixed when the engine starts: the page's `momentTransparency` option of `createEngine` sets it, and `set` does not take it. |
177
180
  | `shadowCascades: number` | The cascades of a directional light's shadows, a whole number from 1 to 4, for each light whose `shadow` options name none. More cascades keep shadows sharp further from the camera, and each draws the shadow casters once more. The `shadowCascades` option of `createEngine` sets it, and `set` does not take it. |
@@ -180,7 +183,7 @@ The quality settings that a sketch reads and changes through `ctx.quality`. Each
180
183
  | `shadowTileSize: number` | Texels on each side of each tile of the shadow atlas: 256, 512, 1,024 or 2,048. Larger tiles give sharper shadows and take more memory, 4 bytes per texel. The `shadowTileSize` option of `createEngine` sets it, and `set` does not take it. |
181
184
  | `heroTileSize: number` | Texels on each side of the tile that holds a directional light's hero shadow, for each light whose `shadow` options name no `heroTileSize`: 1,024, 2,048 or 4,096. The tile is a layer of the shadow atlas, so every layer takes its size and a larger one takes more memory, 4 bytes per texel. The `heroTileSize` option of `createEngine` sets it, and `set` does not take it. |
182
185
  | `pointLightShadows: boolean` | True when point lights cast shadows. Each point light that casts them takes six tiles of the shadow atlas, one for each face of a cube around it, within `shadowTiles`. The `pointLightShadows` option of `createEngine` sets it, and `set` does not take it. |
183
- | `depthPrepass: boolean` | True when the engine draws the depth of the opaque objects before it shades them, so it shades each pixel once, for its nearest surface. Every preset turns it on for WebGL2 and off for WebGPU. The setting is fixed when the engine starts: the page's `depthPrepass` option of `createEngine` sets it, and `set` does not take it. |
186
+ | `depthPrepass: boolean` | True when the engine draws the depth of the opaque objects before it shades them, so it shades each pixel once, for its nearest surface. Every preset turns it on for WebGL2 and off for WebGPU. The page's `depthPrepass` option of `createEngine` gives its first value. It changes during play, and ambient occlusion, contact shadows, the bounce light and screen-space reflections still draw the prepass while they run, as they read its depth. |
184
187
  | `gpuOcclusion: boolean` | True when GPU occlusion culling runs on WebGPU: each camera view draws the depth of the opaque objects that showed in the last frame and look large on the screen, and skips every object that lies wholly behind them. `setOccluder(false)` keeps an object out of them. A check during play turns the extra passes off while they hide too little or make the GPU's frame longer, and on again when they pay. High and Ultra turn it on for desktops, and phones and tablets keep it off unless the page asks for it. The page's `gpuOcclusion` option of `createEngine` sets it, and `set` does not take it. It is always false on WebGL2, and when the depth prepass is on. |
185
188
  | `morphTargets: number` | The most morph target weights of each object that a WebGL2 device draws, a whole number from 1 to 256. Each object keeps the weights farthest from 0, and draws the others as 0. WebGPU draws every weight. The `morphTargets` option of `createEngine` sets it, and `set` does not take it. |
186
189
  | `softwareOcclusion: boolean` | True when software occlusion culling runs on WebGL2: each frame, the job workers draw the objects that `setOccluder(true)` marks into a small depth buffer, and the engine skips every object that lies wholly behind them. It costs the job workers time for each blocker, and saves drawing what they hide. Every preset leaves it off, and the `softwareOcclusion` option of `createEngine` turns it on. It changes during play. WebGPU ignores it. |
@@ -1,8 +1,7 @@
1
1
  ---
2
2
  id: api/reference/raycast
3
3
  title: "Raycasting and spatial queries: API reference"
4
- status: generated
5
- since: "0.2"
4
+ generated: true
6
5
  summary: "Every export of the Raycasting and spatial queries API, from the engine's doc comments."
7
6
  ---
8
7
 
@@ -31,7 +30,7 @@ What a pick found: an object or the batch of a row, the row of an instance batch
31
30
  | --- | --- |
32
31
  | `object: QueryTarget` | The object or the batch of a row. |
33
32
  | `instance: number` | The row of a batch, or -1 for an object of the scene. |
34
- | `uv?: Vec2Like` | Where on the surface the pixel landed, as the first texture coordinates of the hit triangle blended across its three corners, as three.js's `intersection.uv`. Read `hasUv` first: the numbers mean nothing when it is false. |
33
+ | `uv?: Vec2Like` | Where on the surface the pixel landed, as the first texture coordinates of the hit triangle blended across its three corners. Read `hasUv` first: the numbers mean nothing when it is false. |
35
34
  | `hasUv?: boolean` | True when the picked surface has a first texture coordinate set, so `uv` holds where on the surface the pixel landed. False for a mesh that has no such coordinates, and when the ray that finds them met another source than the pick's. |
36
35
 
37
36
  ## `QueryOptions`
@@ -42,7 +41,7 @@ The options of every query.
42
41
 
43
42
  | Member | Description |
44
43
  | --- | --- |
45
- | `layers?: number` | The layers to test, as a 32-bit mask like `Object3D.setLayers` takes. A query tests an object when their masks share a layer. The default is layer 0 alone, as for a camera and for three.js's `Raycaster`. |
44
+ | `layers?: number` | The layers to test, as a 32-bit mask like `Object3D.setLayers` takes. A query tests an object when their masks share a layer. The default is layer 0 alone, as for a camera. |
46
45
 
47
46
  ## `QueryTarget`
48
47
 
@@ -77,8 +76,8 @@ A raycast's hit. Create one with `point` and `normal` arrays, and pass it to eac
77
76
  | `point: Vec3Like` | Where the ray hit, in world space. |
78
77
  | `normal: Vec3Like` | The unit normal of the hit triangle in world space, on the side that faces the ray. A hit on a sprite or a point faces the camera; on a line, or within a threshold, it points back along the ray. |
79
78
  | `distance: number` | The distance from the ray's origin to the hit, in meters. |
80
- | `triangle: number` | The index of the hit triangle in its mesh, as three.js's `faceIndex`, or -1 for a sprite, a point or a line. |
81
- | `uv?: Vec2Like` | Where on the surface the ray hit, as the first texture coordinates of the hit triangle blended across its three corners, as three.js's `intersection.uv`. Give the hit object an array of two numbers, as it has arrays for `point` and `normal`, and every raycast fills it. Read `hasUv` first: the numbers mean nothing when it is false. |
79
+ | `triangle: number` | The index of the hit triangle in its mesh, or -1 for a sprite, a point or a line. |
80
+ | `uv?: Vec2Like` | Where on the surface the ray hit, as the first texture coordinates of the hit triangle blended across its three corners. Give the hit object an array of two numbers, as it has arrays for `point` and `normal`, and every raycast fills it. Read `hasUv` first: the numbers mean nothing when it is false. |
82
81
  | `hasUv?: boolean` | True when the raycast found a triangle with a first texture coordinate set, so `uv` holds where on the surface the ray hit. False for a hit on a sprite, a point or a line, and for a mesh that has no such coordinates. Every raycast writes it. |
83
82
 
84
83
  ## `RaycastOptions`
@@ -90,5 +89,5 @@ The options of a raycast.
90
89
  | Member | Description |
91
90
  | --- | --- |
92
91
  | `maxDistance?: number` | The farthest hit, in meters from the ray's origin. The default is no limit. |
93
- | `pointThreshold?: number` | When set, a ray hits a point that it passes within this many meters of, whatever the point's size, as three.js's `Raycaster.params.Points.threshold` does. By default a ray hits the square that a point draws. |
94
- | `lineThreshold?: number` | When set, a ray hits a line that it passes within this many meters of, whatever the line's width, as three.js's `Raycaster.params.Line.threshold` does. By default a ray hits a line within half its width. |
92
+ | `pointThreshold?: number` | When set, a ray hits a point that it passes within this many meters of, whatever the point's size. By default a ray hits the square that a point draws. |
93
+ | `lineThreshold?: number` | When set, a ray hits a line that it passes within this many meters of, whatever the line's width. By default a ray hits a line within half its width. |
@@ -1,8 +1,7 @@
1
1
  ---
2
2
  id: api/reference/render
3
3
  title: "Render graph API: API reference"
4
- status: generated
5
- since: "0.2"
4
+ generated: true
6
5
  summary: "Every export of the Render graph API API, from the engine's doc comments."
7
6
  ---
8
7
 
@@ -40,7 +39,9 @@ The format of a compute pass's storage texture. `'rgba16float'` holds HDR color,
40
39
 
41
40
  Interface `ComputePassOptions`.
42
41
 
43
- Options of `render.addPass` for a compute pass, which runs a compiled compute shader over a storage texture of its own. The texture is the description's output, which `textures.fromPass` gives to materials, effects and other passes: they sample it in the frame that the pass writes it, and the render graph orders the pass before them. A compute pass runs on WebGPU. On WebGL2 it runs its fragment form when the options give one, and the call throws otherwise. The shader declares `@group(0)
42
+ Options of `render.addPass` for a compute pass, which runs a compiled compute shader over a storage texture of its own. The texture is the description's output, which `textures.fromPass` gives to materials, effects and other passes: they sample it in the frame that the pass writes it, and the render graph orders the pass before them. A compute pass runs on WebGPU. On WebGL2 it runs its fragment form when the options give one, and the call throws otherwise.
43
+
44
+ The shader declares `@group(0) @binding(0) var<uniform>` for the pass's block and `@group(0) @binding(1) var` for its storage texture, which it reads as an array of one layer, and the textures of `textures` at group 1, as a custom material's maps bind. The block holds the render size, the clock, the inverse of the camera's projection, eight vectors of `values`, and the target's size.
44
45
 
45
46
  | Member | Description |
46
47
  | --- | --- |
@@ -48,7 +49,7 @@ Options of `render.addPass` for a compute pass, which runs a compiled compute sh
48
49
  | `readonly description: FeatureDescription` | The feature description that places the pass: its frame point, its order band and order, and its single output, which names the texture that the pass writes. |
49
50
  | `readonly wgsl: Wgsl` | The compiled WGSL, whose `@compute` entry point fills the storage texture. |
50
51
  | `readonly format?: ComputeFormat` | The storage texture's format. The default is `'rgba16float'`. |
51
- | `readonly history?: boolean` | The pass keeps two states, and each run reads the state of the run before and writes the other. The texture holds the states as two ranges of layers: the first run's state, then the other's. Readers sample the state that the last run wrote by its layer, which `Texture.layer` gives once the pass is added. The shader reads the previous state from `@group(0) |
52
+ | `readonly history?: boolean` | The pass keeps two states, and each run reads the state of the run before and writes the other. The texture holds the states as two ranges of layers: the first run's state, then the other's. Readers sample the state that the last run wrote by its layer, which `Texture.layer` gives once the pass is added. The shader reads the previous state from `@group(0) @binding(2) var history: texture_2d_array<f32>;` at the layer `id.z` that it writes, and writes its own state through `@group(0) @binding(1)` at that layer. The fragment form reads the state of the run before as its input image, `input.color`. The call throws E1220 for a pass that fills an instance draw's buffers, and on WebGL2 without a fallback. |
52
53
  | `readonly layers?: number` | The array layers of each state: the texture has that many, or twice as many with `history`. A `'writes'` dispatch runs one workgroup along z for each layer, so the shader writes layer `id.z`. The default is 1. WebGL2's fragment form draws each layer in a pass of its own, up to 32, and the call throws E1220 past them. |
53
54
  | `readonly steps?: number` | The runs that a frame records, swapping the two states between them, so a 40-step pressure solve is one pass. It is 1 by default, and `render.setPassSteps` changes it. Zero runs keep the states that the frame before left. A pass without `history` runs once. |
54
55
  | `readonly workgroupSize?: ComputeWorkgroup` | The invocations along each axis of a workgroup. The default is the shader's `@workgroup_size`. Another value throws, so a pass cannot dispatch another grid. |
@@ -1,8 +1,7 @@
1
1
  ---
2
2
  id: api/reference/scene
3
3
  title: "Scene: API reference"
4
- status: generated
5
- since: "0.1"
4
+ generated: true
6
5
  summary: "Every export of the Scene API, from the engine's doc comments."
7
6
  ---
8
7
 
@@ -57,9 +56,9 @@ The options of `scene.setBackground` for a texture, an environment, a cube map o
57
56
 
58
57
  | Member | Description |
59
58
  | --- | --- |
60
- | `intensity?: number` | The factor of the background's light, 0 or more, as three.js's `scene.backgroundIntensity`. The default is 1. |
61
- | `blur?: number` | How much an environment blurs, from 0 (sharp) to 1, as three.js's `scene.backgroundBlurriness`. It reads the environment's light at that roughness, so a blurred background costs no more than a sharp one. Only environments blur. The default is 0. |
62
- | `rotation?: readonly [number, number, number]` | The turn of a cube map or an environment about the scene, as Euler angles in radians in the order X, Y, Z, as three.js's `scene.backgroundRotation`. The default is `[0, 0, 0]`. |
59
+ | `intensity?: number` | The factor of the background's light, 0 or more. The default is 1. |
60
+ | `blur?: number` | How much an environment blurs, from 0 (sharp) to 1. It reads the environment's light at that roughness, so a blurred background costs no more than a sharp one. Only environments blur. The default is 0. |
61
+ | `rotation?: readonly [number, number, number]` | The turn of a cube map or an environment about the scene, as Euler angles in radians in the order X, Y, Z. The default is `[0, 0, 0]`. |
63
62
 
64
63
  ## `BackgroundSource`
65
64
 
@@ -67,7 +66,7 @@ The options of `scene.setBackground` for a texture, an environment, a cube map o
67
66
  type BackgroundSource = Texture | Environment | Cubemap | SkyBackground | AtmosphereBackground;
68
67
  ```
69
68
 
70
- What `scene.setBackground` draws behind every object in place of a plain color: a texture, an environment, a cube map, three.js's sky or the physical sky.
69
+ What `scene.setBackground` draws behind every object in place of a plain color: a texture, an environment, a cube map, the analytic sky or the physical sky.
71
70
 
72
71
  ## `bakeProbes`
73
72
 
@@ -112,7 +111,11 @@ One chunk's rows, in the order that a coarser level keeps: its count, and its ar
112
111
 
113
112
  Class `ChunkRowWriter`.
114
113
 
115
- Packs chunked rows into an instance batch's rows. Store each chunk once with [`write`], then call [`pack`] with one chosen count for each slot. The pack writes the chosen prefix of each chunk, in slot order, and sets the batch's active count. The batch must own its rows' transforms. A batch that reads another batch's rows, such as a part of a model, or a sprite or line batch, takes no chunked rows: a pack on one writes nothing and keeps its active count. The writer keeps one plan array in the engine's memory, so a frame's pack allocates nothing once the slot count is set.
114
+ Packs chunked rows into an instance batch's rows. Store each chunk once with [`write`], then call [`pack`] with one chosen count for each slot. The pack writes the chosen prefix of each chunk, in slot order, and sets the batch's active count.
115
+
116
+ The batch must own its rows' transforms. A batch that reads another batch's rows, such as a part of a model, or a sprite or line batch, takes no chunked rows: a pack on one writes nothing and keeps its active count.
117
+
118
+ The writer keeps one plan array in the engine's memory, so a frame's pack allocates nothing once the slot count is set.
116
119
 
117
120
  | Member | Description |
118
121
  | --- | --- |
@@ -139,8 +142,8 @@ The options of `scene.setEnvironment`. A call that leaves an option out takes it
139
142
 
140
143
  | Member | Description |
141
144
  | --- | --- |
142
- | `intensity?: number` | The factor of the environment's light on every surface, 0 or more, as three.js's `scene.environmentIntensity`. A material's `envIntensity` multiplies it. The default is 1. |
143
- | `rotation?: readonly [number, number, number]` | The turn of the environment about the scene, as Euler angles in radians in the order X, Y, Z, as three.js's `scene.environmentRotation`. The default is `[0, 0, 0]`. |
145
+ | `intensity?: number` | The factor of the environment's light on every surface, 0 or more. A material's `envIntensity` multiplies it. The default is 1. |
146
+ | `rotation?: readonly [number, number, number]` | The turn of the environment about the scene, as Euler angles in radians in the order X, Y, Z. The default is `[0, 0, 0]`. |
144
147
 
145
148
  ## `FogCurve`
146
149
 
@@ -148,7 +151,7 @@ The options of `scene.setEnvironment`. A call that leaves an option out takes it
148
151
  type FogCurve = 'exponential' | 'exp2' | 'linear';
149
152
  ```
150
153
 
151
- How fog thickens with distance. Exponential fog, `'exponential'`, follows light through an even haze. An object at distance d takes the fog color by a factor of 1 - exp(-density × d). Exponential squared fog, `'exp2'`, thickens with the square of the distance, as three.js's `FogExp2`: 1 - exp(-(density × d)²). Linear fog, `'linear'`, is clear up to `near` and hides objects from `far`, with a smooth step between them, as three.js's `Fog`.
154
+ How fog thickens with distance. Exponential fog, `'exponential'`, follows light through an even haze. An object at distance d takes the fog color by a factor of 1 - exp(-density × d). Exponential squared fog, `'exp2'`, thickens with the square of the distance: 1 - exp(-(density × d)²). Linear fog, `'linear'`, is clear up to `near` and hides objects from `far`, with a smooth step between them.
152
155
 
153
156
  ## `FogOptions`
154
157
 
@@ -158,7 +161,7 @@ Options of `scene.setFog`. Fog measures each object's straight-line distance fro
158
161
 
159
162
  | Member | Description |
160
163
  | --- | --- |
161
- | `color: ColorInput` | The fog's color. Give the background the same color, because the background takes no fog. |
164
+ | `color: ColorInput` | The fog's color. A scene whose background takes the fog needs no other color for it. |
162
165
  | `curve?: FogCurve` | How the fog thickens with distance. The default is `'exponential'`. |
163
166
  | `density?: number` | How fast exponential and exponential squared fog thicken with distance: 0 or more. At the default of 0.01, exponential fog hides about two thirds of an object 100 units away. |
164
167
  | `near?: number` | The distance where linear fog starts. The default is 1. |
@@ -167,6 +170,7 @@ Options of `scene.setFog`. Fog measures each object's straight-line distance fro
167
170
  | `heightFalloff?: number` | How fast the fog thins with height, 0 or more: its density falls by a factor of e, to about a third, every 1 / `heightFalloff` units up. The engine adds up the fog along each line of sight, so a view down into a valley sees thick fog and a view up sees clear air. The default is 0: the fog is the same at every height. |
168
171
  | `sunGlow?: number` | How much of the main directional light the fog scatters toward the camera, 0 or more. Fog toward that light then glows in the light's color. The default is 0: no glow. |
169
172
  | `sunGlowExponent?: number` | How tightly the glow gathers around the light's direction, above 0. Higher values make a smaller glow. The default is 8. |
173
+ | `background?: number` | How much of the fog the background takes, 0 to 1. At 1, the sky and a cube-map background take the same fog as a surface at the camera's far plane, so a scene's haze carries on over the sky it meets and the far edge of the land and the sky read as one. The camera's far plane must be within the fog's reach for the haze to be full. The default is 0: the background takes no fog. |
170
174
  | `volumetric?: boolean \| FogVolumeOptions` | Lights the fog with the main directional light and the point and spot lights, through their shadows: sun rays through gaps in trees, and glowing cones under lamps and headlights. `true` takes the default options. While it draws, it replaces `sunGlow` with its own light of the sun. It needs HDR color, and the quality setting `fogSlices` above 0: on the Low preset the fog keeps its sun glow. The default is `false`. |
171
175
 
172
176
  ## `FogVolumeOptions`
@@ -222,8 +226,8 @@ Options for `scene.createInstances`.
222
226
  | --- | --- |
223
227
  | `material: Material` | The material of every row. |
224
228
  | `dynamic?: boolean` | Every row updates and uploads every frame; a static batch updates rows marked dirty only. |
225
- | `colors?: boolean` | Adds a color per row (RGBA, linear) in `batch.colors`, white at first. It multiplies the material's base color and opacity, as a mesh's vertex colors do, and as three.js's `InstancedMesh.setColorAt` does. A material that lets light through draws its rows without it. |
226
- | `values?: boolean` | Adds four numbers per row of the sketch's own in `batch.values`, 0 at first, such as a wind phase, an age or a tint. A custom material's `surface`, `vertexOffset` and `lobe` functions read the row's as `object.values`, as three.js's instanced attributes give a shader values per instance. With values, a masked material tests its alpha against its cutoff, without alpha to coverage or the alpha hash. |
229
+ | `colors?: boolean` | Adds a color per row (RGBA, linear) in `batch.colors`, white at first. It multiplies the material's base color and opacity, as a mesh's vertex colors do. A material that lets light through draws its rows without it. |
230
+ | `values?: boolean` | Adds four numbers per row of the sketch's own in `batch.values`, 0 at first, such as a wind phase, an age or a tint. A custom material's `surface`, `vertexOffset` and `lobe` functions read the row's as `object.values`. With values, a masked material tests its alpha against its cutoff, without alpha to coverage or the alpha hash. |
227
231
  | `ranges?: boolean` | Adds a start and an end distance per row in `batch.ranges`, so each row draws in a band of its own. Leave it out for a range that every row shares, which costs no memory. |
228
232
  | `layers?: number` | The layers every row is on, as a 32-bit mask. The default, 1, is layer 0. |
229
233
  | `origin?: Vec3` | The point that every row's position is relative to. The default is (0, 0, 0). The engine keeps the origin at full precision, so rows near it keep the precision of 32-bit floats at any distance from the world's origin. Give a batch far from the origin, such as a forest on a planet, an origin among its rows. |
@@ -285,7 +289,7 @@ Options for `scene.createMesh`.
285
289
  | --- | --- |
286
290
  | `mesh: MeshGeometry` | The shape to draw, from `ctx.geometry`. |
287
291
  | `material: Material` | How the surface looks, from `ctx.materials`. |
288
- | `castShadows?: boolean` | True makes the mesh cast the shadows of a directional light, like `setCastShadows(true)`. The default is false. |
292
+ | `castShadows?: boolean` | True makes the mesh cast the shadows of the lights that cast them, like `setCastShadows(true)`. The default is false. |
289
293
  | `receiveShadows?: boolean` | True makes shadows fall on the mesh, like `setReceiveShadows(true)`. The default is false. Unlit materials show no shadows. |
290
294
  | `occluder?: boolean` | Whether the mesh blocks the view for occlusion culling, like `setOccluder`. True makes it a blocker on WebGL2 too. False keeps it from hiding anything on WebGPU. Left out, the mesh blocks nothing on WebGL2, and on WebGPU it hides what lies behind it whenever it looks large enough. |
291
295
 
@@ -316,7 +320,7 @@ The group that holds a copy of a model, which `scene.instantiate` returns. Its c
316
320
  | `batches: readonly InstanceBatch[]` | The instance batches of the nodes with instancing of their own, as the file gives them. Their rows are placed in the world when the copy is created, and they do not move with the group. |
317
321
  | `find(name: string): Object3D \| undefined` | The copy's first object with `name`, in the file's order, which is not destroyed, or undefined. It searches the copy's objects, so call it at setup. |
318
322
  | `destroy(): void` | Removes the whole copy at the next frame: this group, every object that the copy created and that is not destroyed yet, and its instance batches. Objects that the sketch put under the copy later become roots, as children of any destroyed object do. |
319
- | `setOutlined(outlined: boolean): void` | Outlines every mesh of the copy, or stops, as `Mesh.setOutlined` does for one mesh: the whole model takes one outline, as three.js's `OutlinePass` outlines a selected group. The copy's instance batches take none. |
323
+ | `setOutlined(outlined: boolean): void` | Outlines every mesh of the copy, or stops, as `Mesh.setOutlined` does for one mesh: the whole model takes one outline. The copy's instance batches take none. |
320
324
 
321
325
  ## `ProbeBake`
322
326
 
@@ -371,25 +375,27 @@ The scene: every object, the active camera, the lights and the background.
371
375
  | --- | --- |
372
376
  | `dropViews(): void` | Forgets the views of the scene's arrays and of the morph weights. |
373
377
  | `find(name: string): Object3D \| undefined` | The first object created with `name` that is not destroyed, or undefined when no object has the name. It looks the name up in an index, so its cost does not grow with the scene. Call it at setup and keep the object it returns. |
378
+ | `listObjects(): Object3D[]` | Every object of the scene that is not destroyed, in the order of their slots, as a new array. The in-page inspector lists the scene with it. It walks the whole scene and allocates, so call it from tools and setup code, never in every frame. |
374
379
  | `createGroup(options: NodeOptions = {}): Group` | An empty node, for hierarchy. |
375
380
  | `createMesh(options: MeshOptions): Mesh` | A drawn object. It is static unless `dynamic: true`. |
376
381
  | `instantiate(prefab: Prefab, options: InstantiateOptions = {}): PrefabInstance` | Creates the objects of a model that `assets.loadGltf` loaded, under one new group that `options` places, and returns that group. All the objects are created with one batch of commands, and every copy shares the model's meshes, materials and textures. The group's `find` gives the copy's object of a node, by the node's name. A model with clips or skins gives the group an animator, which plays the clips: `copy.animator().play('Walk')`. Throws E1102 when the scene, the animation table or the batch table has no room for the copy. Then no part of the copy stays. `destroy()` on the group removes the whole copy. |
377
382
  | `animateProperty(target: Light \| Camera \| Material \| Object3D, path: string, keyframes: PropertyKeyframes): PropertyAnimation` | Animates one value of a light, a camera, a material or an object from keyframes, such as a lamp that pulses or a color that changes, and returns an object that controls it. The engine writes the value in each frame, so the sketch has no update call to make. A glTF file animates the same kinds of value with its `KHR_animation_pointer` channels. `path` names the value. A light takes `'light.intensity'`, `'light.color'`, `'light.range'`, `'light.decay'`, `'light.angle'` or `'light.penumbra'`; a camera takes `'camera.fov'` (in degrees), `'camera.near'`, `'camera.far'` or `'camera.height'` (for an orthographic camera); a material takes the values that `setUniform` takes, such as `'material.opacity'` or `'material.color'`; and every object takes `'position'`, `'rotation'`, `'scale'` or `'visible'`. The prefix is optional, so `'intensity'` and `'position'` work too. Every object that uses the material changes with it, and an animation that writes every frame allocates nothing. `setTime` places the animation at a time; a frozen keyframes object is read once. Throws E1218 for a path that the target does not take, or for keyframes that do not fit the value's numbers per key. |
378
- | `clone<T extends Object3D>(object: T): T` | Copies an object and every object below it, as three.js's `clone` does, with their meshes, materials, lights, cameras and settings, and returns the copy of the object. The copy has the same parent, so it starts in the same place. The copies are created with one batch of commands. An animated object's copy gets an animator of its own, with no clip playing, which moves the copies of its meshes, as three.js's `SkeletonUtils.clone` does. Instance batches are not objects, so they are not copied. Throws E1102 when the scene or the animation table has no room for the copies. Then no copy stays. |
383
+ | `clone<T extends Object3D>(object: T): T` | Copies an object and every object below it, with their meshes, materials, lights, cameras and settings, and returns the copy of the object. The copy has the same parent, so it starts in the same place. The copies are created with one batch of commands. An animated object's copy gets an animator of its own, with no clip playing, which moves the copies of its meshes. Instance batches are not objects, so they are not copied. Throws E1102 when the scene or the animation table has no room for the copies. Then no copy stays. |
379
384
  | `createInstances(mesh: MeshGeometry, count: number, options: InstanceOptions): InstanceBatch` | Many copies of one mesh and material, with typed arrays of rows. Or many copies of a model that `assets.loadGltf` loaded, without a material: one batch for each mesh of the model, which share one set of rows, so one row places a whole copy. The model's lights are left out. Throws E1417 for a model with no meshes, or with instancing of its own. |
380
385
  | `createInstances(prefab: Prefab, count: number, options?: Omit<InstanceOptions, 'material'>): InstanceBatch` | Many copies of one mesh and material, with typed arrays of rows. Or many copies of a model that `assets.loadGltf` loaded, without a material: one batch for each mesh of the model, which share one set of rows, so one row places a whole copy. The model's lights are left out. Throws E1417 for a model with no meshes, or with instancing of its own. |
381
- | `createSprites(options: SpriteOptions): Promise<SpriteBatch>` | Many sprites in one batch: quads that face the camera, like three.js's `Sprite` with a `SpriteMaterial`. Typed arrays give each sprite its position, size, rotation, color and atlas frame, as an instance batch's arrays give its rows. Sprites blend by default, and blended sprites draw back to front with the other blended objects. The first call downloads the sprite code. Throws E1108 for an atlas side that is not a whole number from 1 to 2048, E1203 for a center that is not two finite numbers, and E1406 when the sprite code does not download. |
382
- | `createPoints(options: PointOptions): Promise<PointBatch>` | Many points in one batch: squares that face the camera, all of one size, like three.js's `Points` with a `PointsMaterial`. Each point is a sprite: typed arrays give each point its position and color, as an instance batch's arrays give its rows. Sizes above one pixel work on every GPU path. Points are opaque by default, and blended points draw back to front with the other blended objects. The first call downloads the sprite code. Throws E1206 for points or colors that make no points, E1108 for a size that is not above 0, E1203 for a size that is not finite, and E1406 when the sprite code does not download. |
386
+ | `createSprites(options: SpriteOptions): Promise<SpriteBatch>` | Many sprites in one batch: quads that face the camera. Typed arrays give each sprite its position, size, rotation, color and atlas frame, as an instance batch's arrays give its rows. Sprites blend by default, and blended sprites draw back to front with the other blended objects. The first call downloads the sprite code. Throws E1108 for an atlas side that is not a whole number from 1 to 2048, E1203 for a center that is not two finite numbers, and E1406 when the sprite code does not download. |
387
+ | `createPoints(options: PointOptions): Promise<PointBatch>` | Many points in one batch: squares that face the camera, all of one size. Each point is a sprite: typed arrays give each point its position and color, as an instance batch's arrays give its rows. Sizes above one pixel work on every GPU path. Points are opaque by default, and blended points draw back to front with the other blended objects. The first call downloads the sprite code. Throws E1206 for points or colors that make no points, E1108 for a size that is not above 0, E1203 for a size that is not finite, and E1406 when the sprite code does not download. |
383
388
  | `addFeatureDraw<const Wgsl extends string \| CompiledWgsl>(description: FeatureDescription, options: FeatureDrawOptions<Wgsl>): Promise<FeatureDraw<Wgsl>>` | An add-on's own kind of draw, declared by a feature description with the kind `'draw'`: its WGSL, its vertex data, its uniforms and the description's frame point, band and order. The engine draws the object on every GPU path and in every thread mode, as it draws the scene's other objects, and sorts a blended draw among the transparent pass's objects. The first call downloads the draw adapter. The description names the frame point: `'opaque'` with an opaque or masked material, `'transparent'` with a blended one, or `'resolve'` with a blended one that blends after the transparent pass's objects. With MSAA, a draw at `'resolve'` blends its surfaces back to front in a layer of one sample per pixel, which the engine then blends over the scene, so many overlapping surfaces, such as Gaussian splats, cost one blend per pixel instead of one per sample. Its surfaces show in front of every object of the transparent pass, and other views draw them in their own transparent pass. The band and order place a blended draw among the pass's objects. The adapter records in the main view alone, so a description with another view throws E1223. The description's `reads`, `writes`, `outputs` and `provides` stay with the feature registry: this draw draws no scene resource. Throws E1223 for a description that is not a draw the adapter can place, E1215, E1216 and E1217 for WGSL and values that `materials.shader` refuses, E1206 for vertex data that makes no mesh, and E1406 when the adapter does not download. |
384
389
  | `addFeatureInstances<const Wgsl extends string \| CompiledWgsl>(description: FeatureDescription, options: FeatureInstancesOptions<Wgsl>): Promise<FeatureInstances<Wgsl>>` | An add-on's own kind of draw, repeated once for each row of an instance batch, declared by a feature description with the kind `'draw'`. It takes the options of `addFeatureDraw` and a number of copies; each row of `draw.batch` places one copy and brings its own color and four values. The engine culls and sorts the rows in each view as it does a batch's, so a blended draw of many copies draws back to front on both GPU paths. Throws E1223 for a description that the adapter cannot place, for a place that belongs to one object, or for a count that is not a whole number from 1 up, E1215, E1216 and E1217 for WGSL and values that `materials.shader` refuses, E1206 for vertex data that makes no mesh, and E1406 when the adapter does not download. |
385
390
  | `addComputeInstances<const Wgsl extends string \| CompiledWgsl = string \| CompiledWgsl>(description: FeatureDescription, options: ComputeInstancesOptions<Wgsl>): Promise<ComputeInstances<Wgsl>>` | An add-on's own kind of draw whose instance count the GPU writes: the description places it, the options give its one shape, its shader and the most instances that it holds, and the add-on fills its per-instance data. On WebGPU the draw reads the add-on's instance buffer and the count word that its compute pass writes; the engine copies the count into the indirect draw each frame. WebGL2 has no compute, so the page sets the instances and the count on the CPU, which draws the same picture. The description names the frame point `'opaque'` and the main view alone. The draw is unculled: the add-on's own cull or count decides what draws. The first call downloads the adapter. Throws E1223 for a description that the adapter cannot place or a capacity that it cannot take, E1215, E1216 and E1217 for WGSL and values that `materials.shader` refuses, E1206 for vertex data that makes no mesh, and E1406 when the adapter does not download. A draw that arrives after the first frame on a device that draws directly fails the frame with E1506: create it in the setup, and await this call there. |
386
- | `createVertexDraw<const Wgsl extends string \| CompiledWgsl = string \| CompiledWgsl>(options: VertexDrawOptions<Wgsl>): VertexDraw<Wgsl>` | A draw that has a custom material and a vertex count but no mesh data: its shader makes every vertex of every copy from `@builtin(vertex_index)` and `@builtin(instance_index)`, so a draw of 50,000 rain streaks uploads nothing in a frame. The draw's object gives its place, its layers and the sphere that culls it, and the material's values move its shapes. The draw blends, so it draws in the transparent pass. The options take every option of `materials.shader` but the maps: a draw's WGSL declares no texture. The draw's culling sphere holds every shape, or a shape that leaves it stops drawing. A draw that uses the camera's position, such as rain around the camera, reads it in its WGSL, and `null3d::wrap` wraps a position relative to the camera into a box. Throws E1108 for a count or a sphere that the draw cannot take, or when the scene holds the most draws already, E1215 for WGSL that the plugin did not compile as a draw shader, and E1217 for a texture or an alpha mode that a draw does not take. |
391
+ | `createVertexDraw<const Wgsl extends string \| CompiledWgsl = string \| CompiledWgsl>(options: VertexDrawOptions<Wgsl>): VertexDraw<Wgsl>` | A draw that has a custom material and a vertex count but no mesh data: its shader makes every vertex of every copy from `@builtin(vertex_index)` and `@builtin(instance_index)`, so a draw of 50,000 rain streaks uploads nothing in a frame. The draw's object gives its place, its layers and the sphere that culls it. The engine writes no uniforms for its WGSL, so `frame.time` moves its shapes. The draw blends, so it draws in the transparent pass. The options take every option of `materials.shader` but the maps: a draw's WGSL declares no texture. The draw's culling sphere holds every shape, or a shape that leaves it stops drawing. A draw that uses the camera's position, such as rain around the camera, reads it in its WGSL, and `null3d::wrap` wraps a position relative to the camera into a box. Throws E1108 for a count or a sphere that the draw cannot take, or when the scene holds the most draws already, E1215 for WGSL that the plugin did not compile as a draw shader, and E1217 for a texture or an alpha mode that a draw does not take. |
387
392
  | `createParticleBuffer(options: ParticleBufferOptions): Promise<ParticleBuffer>` | A particle buffer: a scene object that draws a quad for each live particle, which the GPU moves and colors at the particle's age in closed form. The `@null3d/particles` add-on's emitters fill it; use the add-on rather than this call. The first call downloads the particle code. Throws E1108 for a capacity that is not a whole number from 1 to 4,194,304, or when the scene holds 256 particle buffers already, and E1406 when the particle code does not download. |
388
- | `createLines(options: LineOptions): Promise<LineBatch>` | Lines of any width in one batch, like three.js's `Line2` and `LineSegments2` with a `LineMaterial`, and its `Line`, `LineSegments` and `LineLoop`. Each segment between two points draws as a quad with round ends that faces the camera, `width` CSS pixels wide, or world units wide with `worldUnits`. A typed array gives each point its position and color, as an instance batch's arrays give its rows. The first call downloads the line code. Throws E1206 for points or colors that make no line, E1217 for an unknown mode, E1108 for a width that is not positive or a dash or gap below 0, E1203 for a value that is not finite, and E1406 when the line code does not download. |
393
+ | `createLines(options: LineOptions): Promise<LineBatch>` | Lines of any width in one batch: strips, loops or separate segments. Each segment between two points draws as a quad with round ends that faces the camera, `width` CSS pixels wide, or world units wide with `worldUnits`. A typed array gives each point its position and color, as an instance batch's arrays give its rows. The first call downloads the line code. Throws E1206 for points or colors that make no line, E1217 for an unknown mode, E1108 for a width that is not positive or a dash or gap below 0, E1203 for a value that is not finite, and E1406 when the line code does not download. |
389
394
  | `createPerspectiveCamera(options: PerspectiveCameraOptions = {}): PerspectiveCamera` | A perspective camera; `fov` is vertical, in degrees. Cameras are dynamic by default. |
390
395
  | `createOrthographicCamera(options: OrthographicCameraOptions = {}): OrthographicCamera` | An orthographic camera, whose view is a box: things keep their size at every distance. Give `height`, and the width follows the canvas, or give `left`, `right`, `top` and `bottom`. Cameras are dynamic by default. |
391
396
  | `setActiveCamera(camera: Camera): void` | Draws the scene from this camera. |
392
397
  | `createView(options: SceneViewOptions): SceneView` | Draws the scene again from `camera`, into the rectangle of the canvas that `rect` gives, after the camera's view and in the same frame: a split screen or a picture in picture. The view draws the scene once more at the rectangle's pixels, with its own culling, so its cost follows the rectangle's area. It draws the sun and its shadows as the camera's view does, which costs nothing more, the background and the fog. Its objects take no ambient occlusion or screen-space reflections, which shade the camera's view; the camera's volumetric fog and outline reach the whole image, a view's rectangle included. An object whose material shows a render pass's texture does not draw in a view. The camera's view still draws the whole canvas first, so a split screen that covers the canvas draws the scene one more time than it needs for its two halves. The scene and its passes share 32 views, the camera's included. Throws E1501 when the 32 views are in use. Development builds throw E1213 for a camera or a rectangle that a view does not take, and E1203 for a number that is not finite. |
398
+ | `viewAt(x: number, y: number): SceneView \| undefined` | The view whose image covers the point (`x`, `y`) in CSS pixels from the canvas's top-left corner, or undefined where only the camera's view shows. Where views overlap, it gives the one on top, which the engine draws last. Pass the view to `view.screenToRay` to pick in it, and use `camera.screenToRay` when it gives undefined. It allocates nothing. |
393
399
  | `createDirectionalLight(options: DirectionalLightOptions = {}): DirectionalLight` | Light from one direction, like sunlight: `direction` is the way it travels. |
394
400
  | `createPointLight(options: PointLightOptions): PointLight` | Light from a point in every direction, out to `range` meters, which it needs. |
395
401
  | `createSpotLight(options: SpotLightOptions): SpotLight` | Light from a point in a cone, out to `range` meters, which it needs. |
@@ -397,15 +403,15 @@ The scene: every object, the active camera, the lights and the background.
397
403
  | `createTubeLight(options: TubeLightOptions): TubeLight` | Light from a tube, `length` meters along `direction`, out to `range` meters, which it needs. |
398
404
  | `createHemisphereLight(options: HemisphereLightOptions = {}): HemisphereLight` | Light from the sky above and the ground below. |
399
405
  | `createAmbientLight(options: AmbientLightOptions = {}): AmbientLight` | Light on every surface, from no direction. |
400
- | `setBackground(background: ColorInput \| BackgroundSource, options?: BackgroundOptions): void` | What the camera shows behind every object, as three.js's `scene.background`: a color, a texture, an environment from `assets.loadEnvironment` or `assets.builtinEnvironment`, a cube map from `assets.loadCubemap`, three.js's sky with `{ sky: { sunPosition } }`, or the physical sky with `{ atmosphere: { sunPosition } }`, whose air also hazes distant objects. A texture fills the view and stretches to its shape. An environment or a cube map surrounds the scene, and `options` give its intensity, rotation and, for an environment, its blur, as three.js's `backgroundIntensity`, `backgroundRotation` and `backgroundBlurriness`. The color set before shows until a texture's texels are on the GPU, and again if the texture is destroyed. A color takes the place of any other background. Exposure and tone mapping change the background with the rest of the scene. Without a background, the canvas shows black, or the page behind it on a transparent canvas. Settings are values, not shader builds, and the call allocates nothing, so a sketch can move the sky's sun or turn a cube map every frame. Throws E1204 for a color it cannot read, E1203 for a number that is not finite, E1108 for a number out of its range, E1213 for an option that the background does not take, and E1101 for a texture, an environment or a cube map that was destroyed. |
406
+ | `setBackground(background: ColorInput \| BackgroundSource, options?: BackgroundOptions): void` | What the camera shows behind every object: a color, a texture, an environment from `assets.loadEnvironment` or `assets.builtinEnvironment`, a cube map from `assets.loadCubemap`, the analytic sky with `{ sky: { sunPosition } }`, or the physical sky with `{ atmosphere: { sunPosition } }`, whose air also hazes distant objects. A texture fills the view and stretches to its shape. An environment or a cube map surrounds the scene, and `options` give its intensity, rotation and, for an environment, its blur. The color set before shows until a texture's texels are on the GPU, and again if the texture is destroyed. A color takes the place of any other background. Exposure and tone mapping change the background with the rest of the scene. Without a background, the canvas shows black, or the page behind it on a transparent canvas. Settings are values, not shader builds, and the call allocates nothing, so a sketch can move the sky's sun or turn a cube map every frame. Throws E1204 for a color it cannot read, E1203 for a number that is not finite, E1108 for a number out of its range, E1213 for an option that the background does not take, and E1101 for a texture, an environment or a cube map that was destroyed. |
401
407
  | `setSkyLayer(description: FeatureDescription, options: SkyLayerOptions): SkyLayer` | Draws an add-on's sky layer over the background, under every object: the top of a sky, such as an aurora, a second layer of clouds or a space backdrop. The description is a feature description ([Add-on feature descriptions](../features.md)): it names the feature and records at the background point, as a draw, provides the sky, and draws in the main view, the scene passes and the reflections. The layer's WGSL, compiled by the null3D Vite plugin, declares `fn skyLayer(input: SkyLayerInput) -> SkyLayer`. The engine gives it the fragment's direction in the world, the core sky's cloud coverage, density, elevation and scale, the sketch time and the share of the sun that the layer hides, and it blends what the layer returns over the sky by the layer's coverage and opacity. A layer that hides part of the sun also dims the disc and glow that the core sky draws, through `sun`. The layer draws in the main view, in scene passes and in reflections, and draws nothing where the background draws nothing, as in a debug view. A second call replaces the layer. Throws E1223 for a description that the engine cannot place, E1215 for WGSL that the plugin did not compile as a sky layer, E1203 for a number that is not finite, and E1108 for a number out of its range. |
402
408
  | `clearSkyLayer(): void` | Removes the sky layer that `setSkyLayer` installed, from the next frame on, and gives the core sky its full sun back. A call with no layer installed does nothing. |
403
409
  | `setDecalLayers(mask: number): void` | Sets the layers whose objects decals mark, as a 32-bit mask as `setLayers` takes. An object that is also on a layer outside the mask shows no decals, so a character on a layer of its own walks through a puddle clean. Such objects draw a second time after the decals, over their own pixels, in each frame that has decals. The default is every layer. |
404
- | `overrideMaterial: Material \| null` | Draws every mesh and instance batch of the main pass with this material in place of its own, as three.js's `scene.overrideMaterial` does, or with their own materials with null. Each object keeps its mesh, its place and its instances, so a batch draws every row with it, and every camera view draws with it, the scene passes among them. Sprites, points, lines and particle systems keep their own materials, and the shadow maps keep each object's material, as three.js's shadow maps do. A change rebuilds the engine's draw tables in the next frame; after that it adds no draw call and builds no pipeline. Throws E1224 for a sprite, point or line material, E1101 for a material that is destroyed, and E1103 for a material of another engine. |
405
- | `setEnvironment(environment: Environment \| null, options?: EnvironmentOptions): void` | Lights the scene with an environment from `assets.loadEnvironment` or `assets.builtinEnvironment`, as three.js's `scene.environment` does with a texture from `PMREMGenerator`, or with none for null. Standard materials reflect it, sharply when smooth and blurred when rough, and take its diffuse light, each times its `envIntensity`. The scene draws without a file's environment until its map is on the GPU. The built-in room's map is whole in the first frame that uses it. It allocates nothing, so a sketch can turn the environment every frame. Throws E1203 for a number that is not finite, E1108 for a negative intensity, E1213 for a value that is not an environment, and E1101 for an environment that was destroyed. |
410
+ | `overrideMaterial: Material \| null` | Draws every mesh and instance batch of the main pass with this material in place of its own, or with their own materials with null. Each object keeps its mesh, its place and its instances, so a batch draws every row with it, and every camera view draws with it, the scene passes among them. Sprites, points, lines and particle systems keep their own materials, and the shadow maps keep each object's material, so a masked object still cuts its shadow. A change rebuilds the engine's draw tables in the next frame; after that it adds no draw call and builds no pipeline. Throws E1224 for a sprite, point or line material, E1101 for a material that is destroyed, and E1103 for a material of another engine. |
411
+ | `setEnvironment(environment: Environment \| null, options?: EnvironmentOptions): void` | Lights the scene with an environment from `assets.loadEnvironment` or `assets.builtinEnvironment`, or with none for null. Standard materials reflect it, sharply when smooth and blurred when rough, and take its diffuse light, each times its `envIntensity`. The scene draws without a file's environment until its map is on the GPU. The built-in room's map is whole in the first frame that uses it. It allocates nothing, so a sketch can turn the environment every frame. Throws E1203 for a number that is not finite, E1108 for a negative intensity, E1213 for a value that is not an environment, and E1101 for an environment that was destroyed. |
406
412
  | `createReflectionProbe(options: ReflectionProbeOptions): ReflectionProbe` | Makes a reflection probe: the scene around a point, which the engine captures on the GPU and filters for each roughness, as an environment's map. It lights the surfaces inside its box in place of the environment, with reflections that meet the box's sides, as a room's walls or a street's houses stand. A probe captures in a frame soon after it is made, and frames before that draw with the environment. A scene has at most 16 probes. Their captures take 6 of the 32 views that the scene and its passes share. Throws E1430 past those limits, E1203 for a number that is not finite, E1108 for a negative blend or intensity or a box whose min does not lie below its max, and E1213 for an option that probes do not take. |
407
413
  | `setLightProbeGrid(grid: LightProbeGridOptions \| null): void` | Lights the scene with a grid of irradiance probes, or with none for null. The grid's light takes the place of the environment's diffuse light where `environmentWeight` says so, so light that changes with a surface's place, bounced from colored walls or sky, reaches it. The probes' coefficients come from a 3D texture that `LightProbeGridData.toTexture` packs and uploads, from `bakeProbes` or from a grid baked elsewhere. Throws the errors that `scene.setEnvironment` throws for a value out of range, E1213 for something that is not a texture, and E1101 for a texture that was destroyed. |
408
- | `setFog(fog: FogOptions \| null): void` | Fog over every object, by each object's straight-line distance from the camera along a curve: exponential by default, exponential squared or linear. The fog can thin with height and glow toward the main directional light. With `volumetric`, the sun and the point and spot lights light the fog through their shadows. Null removes the fog. The background takes no fog, and a material created with `fog: false` keeps its color. Throws E1108 for an unknown curve or a value out of its range, and E1203 for a value that is not finite. The call allocates nothing, so a sketch can change the fog in every frame. |
414
+ | `setFog(fog: FogOptions \| null): void` | Fog over every object, by each object's straight-line distance from the camera along a curve: exponential by default, exponential squared or linear. The fog can thin with height and glow toward the main directional light. With `volumetric`, the sun and the point and spot lights light the fog through their shadows. Null removes the fog. The background takes the share of the fog that `background` gives, none by default, and a material created with `fog: false` keeps its color. Throws E1108 for an unknown curve or a value out of its range, and E1203 for a value that is not finite. The call allocates nothing, so a sketch can change the fog in every frame. |
409
415
  | `pick(x: number, y: number): Promise<PickHit \| null>` | Finds the object that the camera draws at a point of the canvas, or `null` where it draws nothing there. `x` and `y` are CSS pixels from the canvas's top-left corner, as `camera.screenToRay` takes them, and the point is tested at the pixel that the camera draws, not at a projected triangle: a cut-out material's holes and a surface thinner than a pixel answer as the image shows them. A hit carries `uv`, where on the surface the pixel landed in the mesh's first texture coordinates, blended across its triangle's three corners as a raycast's `uv` is, and `hasUv`, which says whether to read it. A ray from the camera of the frame that recorded the pick finds them from the same point, so the two ways of asking agree. A skinned or morphed character, and a custom material that offsets its vertices, draws a different shape than the mesh that the ray tests, so its coordinates can differ from the pose it drew. The answer arrives one or more frames later, through a promise, and a pick in every frame waits in a queue of its own. The frame that records the pick draws it, so the camera of that frame answers, and a camera that moves between the click and the frame can differ from the frame that the click saw. A scene with a source that the id target cannot hold, such as a custom material without a vertex offset, a blended surface or a sprite, answers with a raycast instead, which tests triangles and so ignores alpha masks. |
410
416
  | `raycast(origin: Vec3Like, direction: Vec3Like, options: RaycastOptions \| undefined, hit: RaycastHit): boolean` | Casts a ray from `origin` along `direction`, and writes its closest hit into `hit`. Returns true on a hit. On a miss it sets `hit.object` to null and leaves the other fields as they were. The direction needs no unit length. The ray tests the triangles of objects and instance rows on the layers of `options.layers`, as their materials draw them: front faces, or both faces for a double-sided material. Queries see the scene as the last frame's update left it, so a move, a new object or a destroy in this frame counts from the next frame, or from `onLateUpdate`. A query before the first frame, as a bake in a sketch's setup, first applies the changes queued so far and updates them, so it sees what the setup has built. Create `hit` and `options` once and pass them each time. |
411
417
  | `raycastAny(origin: Vec3Like, direction: Vec3Like, options?: RaycastOptions): boolean` | True when a ray from `origin` along `direction` hits anything on the layers of `options.layers`. It stops at the first hit it finds, so it is faster than `raycast`: use it for line-of-sight checks. |
@@ -419,7 +425,7 @@ The scene: every object, the active camera, the lights and the background.
419
425
 
420
426
  Interface `SkyBackground`.
421
427
 
422
- three.js's analytic sky as a background: `scene.setBackground({ sky: { sunPosition } })`.
428
+ The analytic sky as a background: `scene.setBackground({ sky: { sunPosition } })`.
423
429
 
424
430
  | Member | Description |
425
431
  | --- | --- |
@@ -461,11 +467,11 @@ The values of a sky layer that `scene.setSkyLayer` takes, and that a later call
461
467
 
462
468
  Interface `SkyOptions`.
463
469
 
464
- The settings of three.js's sky, with the names and defaults of its `Sky` object's uniforms. A call that leaves a setting out takes its default.
470
+ The settings of the analytic sky, the Preetham daylight model with a sun disc and drifting clouds. A call that leaves a setting out takes its default.
465
471
 
466
472
  | Member | Description |
467
473
  | --- | --- |
468
- | `sunPosition?: readonly [number, number, number]` | A point toward the sun, as three.js's `sunPosition`. Its direction places the sun. A point far below the horizon, hundreds of thousands of units down, also dims the sky, as in three.js. The default is the sun 2 degrees above the horizon toward -Z, as three.js's sky example sets it: `[0, 0.0349, -0.9994]`. |
474
+ | `sunPosition?: readonly [number, number, number]` | A point toward the sun. Its direction places the sun. A point far below the horizon, hundreds of thousands of units down, also dims the sky. The default is the sun 2 degrees above the horizon toward -Z: `[0, 0.0349, -0.9994]`. |
469
475
  | `turbidity?: number` | The haze in the air, 0 or more. The default is 2. |
470
476
  | `rayleigh?: number` | The scattering by the air's molecules, which makes the sky blue, 0 or more. The default is 1. |
471
477
  | `mieCoefficient?: number` | The scattering by haze, 0 or more. The default is 0.005. |
@@ -486,7 +492,23 @@ The settings of three.js's sky, with the names and defaults of its `Sky` object'
486
492
  function timeOfDay(time: number | TimeOfDayPreset, options: TimeOfDayOptions = {}, out: TimeOfDay = emptyTimeOfDay()): TimeOfDay
487
493
  ```
488
494
 
489
- Works out the settings of a time of day: an hour from 0 to 24, or a named preset. The sun rises at 6, stands highest at 12 and sets at 18. After sunset the sky dims to a deep blue, and then to a navy night sky lit from the moon's place, and the moon takes over as the main light. Each value comes from three.js's sky model, the one that the sky background draws, so the fog fades into the sky's horizon. Throws a `RangeError` for an hour that is not a finite number, or an unknown preset. Give it `out`, an object of a previous call, and it writes the new settings into that object: a day cycle then allocates nothing, so a sketch can move the time in every frame. `bun run bench:allocation --time-of-day` checks that. Without it the call makes a new object. `emptyTimeOfDay()` makes the first one to pass. ```ts const day = emptyTimeOfDay(); timeOfDay('goldenHour', {}, day); scene.setBackground({ sky: day.sky }, { intensity: day.skyIntensity }); scene.setEnvironment(skyLight, { intensity: day.skyIntensity }); sun.setDirection(...day.light.direction); sun.setColor(day.light.color); sun.setIntensity(day.light.intensity); scene.setFog({ color: day.fog.color, density: 0.01, sunGlow: day.fog.sunGlow }); post.set({ exposure: day.exposure }); ```
495
+ Works out the settings of a time of day: an hour from 0 to 24, or a named preset. The sun rises at 6, stands highest at 12 and sets at 18. After sunset the sky dims to a deep blue, and then to a navy night sky lit from the moon's place, and the moon takes over as the main light.
496
+
497
+ Each value comes from the model of the sky that the background draws, so the fog takes that sky's horizon color by day and its average at dusk. With the physical model it takes the sky's mean light by day and through dusk, then the moon sky's horizon light at night. Throws a `RangeError` for an hour that is not a finite number, or an unknown preset.
498
+
499
+ Give it `out`, an object of a previous call, and it writes the new settings into that object: a day cycle then allocates nothing, so a sketch can move the time in every frame. `bun run bench:allocation --time-of-day` checks that. Without it the call makes a new object. `emptyTimeOfDay()` makes the first one to pass.
500
+
501
+ ```ts
502
+ const day = emptyTimeOfDay();
503
+ timeOfDay('goldenHour', {}, day);
504
+ scene.setBackground({ sky: day.sky }, { intensity: day.skyIntensity });
505
+ scene.setEnvironment(skyLight, { intensity: day.skyIntensity });
506
+ sun.setDirection(...day.light.direction);
507
+ sun.setColor(day.light.color);
508
+ sun.setIntensity(day.light.intensity);
509
+ scene.setFog({ color: day.fog.color, density: 0.01, sunGlow: day.fog.sunGlow });
510
+ post.set({ exposure: day.exposure });
511
+ ```
490
512
 
491
513
  ## `TimeOfDay`
492
514
 
@@ -501,7 +523,7 @@ The settings of one time of day, which `timeOfDay` works out. Apply them to the
501
523
  | `atmosphere: TimeOfDayAtmosphere` | The physical sky's settings for `scene.setBackground({ atmosphere })`: the real sun and its light, and at night the moon, which lights the air too, and the stars. Spread it into the scene's own settings, such as its clouds and `aerialPerspective`. |
502
524
  | `skyIntensity: number` | The factor of the sky's light for the background's and the environment's `intensity`. It dims the analytic sky after sunset, as its model alone keeps a glow. The physical sky dims by itself, so with the physical model it is 1. |
503
525
  | `light: { direction: [number, number, number]; color: [number, number, number]; intensity: number; }` | The main directional light: the sun while it is up, and the moon at night. `direction` points from the light into the scene, as `setDirection` takes it. `color` is linear. |
504
- | `fog: { color: [number, number, number]; sunGlow: number; }` | The fog's linear color, the sky's color along the horizon, and the glow toward the main light, for `scene.setFog`. |
526
+ | `fog: { color: [number, number, number]; sunGlow: number; }` | The fog's linear color and the glow toward the main light, for `scene.setFog`. With the analytic model the color is the sky's horizon by day and its average at dusk. With the physical model it is the sky's mean light by day and through dusk, then the moon sky's horizon light at night. |
505
527
  | `ambient: { color: [number, number, number]; intensity: number; }` | A linear ambient color and intensity of the sky's average light, for a scene that has no environment. A scene lit by the sky's environment needs no ambient light. |
506
528
  | `exposure: number` | The exposure for `post.set({ exposure })`, higher as the light dims. |
507
529
 
@@ -529,7 +551,7 @@ The options of `timeOfDay`. An option left out takes its default.
529
551
  | --- | --- |
530
552
  | `heading?: number` | The turn of the sun's path about +Y, in radians. At 0 the sun rises toward +X, stands toward -Z at noon and sets toward -X. The default is 0. |
531
553
  | `noonElevation?: number` | How high the noon sun stands above the horizon, in radians, from above 0 to π/2. The default is π/3, 60 degrees. |
532
- | `model?: 'analytic' \| 'physical'` | The sky that the light, the fog, the ambient light and the exposure match: `'analytic'`, three.js's sky of `scene.setBackground({ sky })`, or `'physical'`, the physical sky of `scene.setBackground({ atmosphere })`. The default is `'analytic'`. |
554
+ | `model?: 'analytic' \| 'physical'` | The sky that the light, the fog, the ambient light and the exposure match: `'analytic'`, the analytic sky of `scene.setBackground({ sky })`, or `'physical'`, the physical sky of `scene.setBackground({ atmosphere })`. The default is `'analytic'`. |
533
555
 
534
556
  ## `TimeOfDayPreset`
535
557
 
@@ -1,8 +1,7 @@
1
1
  ---
2
2
  id: api/reference/sketch
3
3
  title: "Sketch API: defineSketch and the context: API reference"
4
- status: generated
5
- since: "0.1"
4
+ generated: true
6
5
  summary: "Every export of the Sketch API: defineSketch and the context API, from the engine's doc comments."
7
6
  ---
8
7
 
@@ -13,10 +12,10 @@ summary: "Every export of the Sketch API: defineSketch and the context API, from
13
12
  ## `defineSketch`
14
13
 
15
14
  ```ts
16
- function defineSketch(setup: SketchSetup, options: SketchOptions = {}): SketchDefinition
15
+ function defineSketch<Data = unknown>(setup: SketchSetup<Data>, options: SketchOptions = {}): SketchDefinition<Data>
17
16
  ```
18
17
 
19
- Declares a sketch. In null3D, a 3D scene is called a sketch: a module that builds the scene and updates it every frame, in the sketch worker. The module must export the result as its default export. `options` sets the rate of the fixed steps.
18
+ Declares a sketch. In null3D, a 3D scene is called a sketch: a module that builds the scene and updates it every frame, in the sketch worker. The module must export the result as its default export. `options` sets the rate of the fixed steps. `Data` types the start data that the setup reads as `ctx.data`, such as `defineSketch<{ stop: string }>(...)`.
20
19
 
21
20
  ## `SketchCallbacks`
22
21
 
@@ -26,19 +25,20 @@ Callbacks a sketch returns from its setup function. In each frame the engine cal
26
25
 
27
26
  | Member | Description |
28
27
  | --- | --- |
29
- | `onFixedUpdate(step: number): void` | Runs at a fixed rate, 60 times per second of sketch time unless `defineSketch`'s options set another, with the step's length in seconds. A frame runs it once for each step that falls due since the previous frame, so 0 or more times, before `onUpdate`. After a slow frame, a frame runs at most 8 steps unless the options set another number, and drops the rest. Use it for simulation, such as physics, that must step the same at every frame rate. |
30
- | `onUpdate(dt: number): void` | Runs once per frame, before transforms, with the frame's step in seconds. The first frame, and the first after a pause or a hidden page, gets 0. No step is longer than a quarter second, so a very slow frame slows the sketch instead of jumping it. In hold mode, each frame after the first gets a fixed step of 1/60 second. |
31
- | `onLateUpdate(dt: number): void` | Runs once per frame after the engine updates transforms, and before it culls and draws, with the frame's step in seconds. World positions already hold the frame's changes, and the engine updates the objects that it moves before it draws the frame. A camera that follows an object here does not lag a frame behind it. |
32
- | `onDestroy(): void` | Runs once when the engine stops, on the sketch's thread, before its workers stop. Remove the timers, event listeners and message handlers that the sketch added outside the engine here. After it, every call to the engine fails with E1420. |
28
+ | `onFixedUpdate?(step: number): void` | Runs at a fixed rate, 60 times per second of sketch time unless `defineSketch`'s options set another, with the step's length in seconds. A frame runs it once for each step that falls due since the previous frame, so 0 or more times, before `onUpdate`. After a slow frame, a frame runs at most 8 steps unless the options set another number, and drops the rest. Use it for simulation, such as physics, that must step the same at every frame rate. |
29
+ | `onUpdate?(dt: number): void` | Runs once per frame, before transforms, with the frame's step in seconds. The first frame, and the first after a pause or a hidden page, gets 0. No step is longer than a quarter second, so a very slow frame slows the sketch instead of jumping it. In hold mode, each frame after the first gets a fixed step of 1/60 second. |
30
+ | `onLateUpdate?(dt: number): void` | Runs once per frame after the engine updates transforms, and before it culls and draws, with the frame's step in seconds. World positions already hold the frame's changes, and the engine updates the objects that it moves before it draws the frame. A camera that follows an object here does not lag a frame behind it. |
31
+ | `onDestroy?(): void` | Runs once when the engine stops, on the sketch's thread, before its workers stop. Remove the timers, event listeners and message handlers that the sketch added outside the engine here. After it, every call to the engine fails with E1420. |
33
32
 
34
33
  ## `SketchContext`
35
34
 
36
35
  Interface `SketchContext`.
37
36
 
38
- What the engine passes to a sketch's setup function.
37
+ What the engine passes to a sketch's setup function. `Data` is the type of the start data that the page passes, which `defineSketch<Data>` names.
39
38
 
40
39
  | Member | Description |
41
40
  | --- | --- |
41
+ | `readonly data: Data \| undefined` | The start data that the page passed as `createEngine`'s `sketchData`, or undefined when it passed none. It is there from the start of the setup, before the first frame, also in hold mode. The sketch gets its own copy, so a change to it reaches neither the page nor a replay. A replay gives the data that the recording keeps. |
42
42
  | `scene: Scene` | Objects, cameras, lights and instance batches. |
43
43
  | `materials: Materials` | Material factories. |
44
44
  | `geometry: Geometry` | Mesh generators. |
@@ -63,7 +63,7 @@ A sketch, as `defineSketch` returns it.
63
63
 
64
64
  | Member | Description |
65
65
  | --- | --- |
66
- | `readonly setup: SketchSetup` | The setup function passed to `defineSketch`. |
66
+ | `readonly setup: SketchSetup<Data>` | The setup function passed to `defineSketch`. |
67
67
  | `readonly options: SketchOptions` | The options passed to `defineSketch`. |
68
68
 
69
69
  ## `SketchEngine`
@@ -77,6 +77,7 @@ The engine as the sketch sees it: the canvas's size, and what the device can do.
77
77
  | `readonly viewport: SketchViewport` | The canvas's size in CSS pixels, and the pixel ratio the engine draws with. |
78
78
  | `readonly capabilities: EngineCapabilities` | The GPU path the engine chose, and what it offers: the values of `engine.capabilities` on the page. |
79
79
  | `readonly held: boolean` | True when the engine steps the sketch itself, as hold mode and a replay do, rather than running it live. A sketch that returns before its scene is complete waits for the scene when this is true, so a held frame or a replay shows the finished scene. |
80
+ | `readonly firstFrame: Promise<void>` | Resolves once the GPU has finished the engine's first frame, as `engine.firstFrame` does on the page. Start the downloads that the first frame does not need here, so they leave the network to the first frame's own files. Never await it in the setup: the first frame waits for the setup. In hold mode and a replay, it resolves once the engine has stepped the sketch to the last frame, which no later frame follows, so work that it starts never changes the frames that those modes show. It never resolves when the engine stops first. |
80
81
 
81
82
  ## `SketchOptions`
82
83
 
@@ -88,6 +89,9 @@ Options for `defineSketch`.
88
89
  | --- | --- |
89
90
  | `fixedRate?: number` | Fixed steps per second of sketch time, the rate of `onFixedUpdate`. The default is 60. |
90
91
  | `maxFixedSteps?: number` | The most fixed steps that one frame runs, after a slow frame. The default is 8. |
92
+ | `lowestTier?: boolean` | False keeps the governor out of its lowest quality tier, whose cuts reach the scene's settings. A scene whose sketch thread limits its frames gains nothing from the tier's smaller render: the cut cannot make the sketch work cheaper, and the smaller picture is a loss. The default is true, and the page's `?tier=off` switch keeps the tier out too. |
93
+ | `downloads?: readonly (string \| URL)[]` | The files that the setup loads, as addresses that resolve against the page's address, as the loading calls' do. A live start begins to download them as soon as the sketch's module has loaded, often while the engine's core still downloads. The setup's loads then take the bytes that arrived or are on their way, with no second download. List the files in the order that the setup needs them. Two download at a time, so the engine's own start files keep free connections. A load of a later file moves it to the front, and up to four listed files download while loads wait for them. Name only files that the first frame waits for, and start the others when `engine.firstFrame` resolves. A file that no load takes costs its download, and its bytes stay in memory until the engine stops. Hold mode, a replay and a recording download each file at its load, as without the list. |
94
+ | `serialLoadWarning?: boolean` | False turns off the warning of a development build for a load whose download starts only after another load's file has arrived, during the setup. Turn it off when each address comes from the contents of the file before it. The default is true. |
91
95
 
92
96
  ## `SketchPreferences`
93
97
 
@@ -103,7 +107,7 @@ The user's display preferences, which the page reads from the system and passes
103
107
  ## `SketchSetup`
104
108
 
105
109
  ```ts
106
- type SketchSetup = (context: SketchContext) => SketchCallbacks | undefined | Promise<SketchCallbacks | undefined>;
110
+ type SketchSetup<Data = unknown> = (context: SketchContext<Data>) => SketchCallbacks | undefined | Promise<SketchCallbacks | undefined>;
107
111
  ```
108
112
 
109
113
  A sketch's setup function. The engine calls it once, in the sketch worker, and it returns the sketch's callbacks, directly or through a promise.