@null3d/engine 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/dist/wasm/single/null3d.js +10 -8
  2. package/dist/wasm/single/null3d_bg.wasm +0 -0
  3. package/dist/wasm/threaded/null3d.js +10 -8
  4. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  5. package/docs/api/animation.md +96 -24
  6. package/docs/api/assets.md +99 -29
  7. package/docs/api/cameras.md +38 -7
  8. package/docs/api/controls.md +47 -23
  9. package/docs/api/debug.md +105 -35
  10. package/docs/api/engine.md +108 -32
  11. package/docs/api/feature-draws.md +21 -15
  12. package/docs/api/feature-effects.md +8 -8
  13. package/docs/api/feature-instances.md +68 -17
  14. package/docs/api/features.md +68 -37
  15. package/docs/api/geometry.md +83 -14
  16. package/docs/api/grass.md +55 -13
  17. package/docs/api/impostors.md +92 -50
  18. package/docs/api/input.md +22 -9
  19. package/docs/api/lights.md +67 -16
  20. package/docs/api/lines.md +38 -13
  21. package/docs/api/materials.md +187 -59
  22. package/docs/api/math.md +6 -6
  23. package/docs/api/objects.md +40 -15
  24. package/docs/api/page.md +58 -7
  25. package/docs/api/particles.md +36 -11
  26. package/docs/api/points.md +18 -8
  27. package/docs/api/post.md +57 -23
  28. package/docs/api/quality.md +36 -16
  29. package/docs/api/raycast.md +57 -24
  30. package/docs/api/reference/animation.md +1 -2
  31. package/docs/api/reference/assets.md +7 -4
  32. package/docs/api/reference/cameras.md +3 -2
  33. package/docs/api/reference/controls.md +59 -2
  34. package/docs/api/reference/debug.md +58 -6
  35. package/docs/api/reference/engine.md +40 -10
  36. package/docs/api/reference/feature-draws.md +3 -4
  37. package/docs/api/reference/feature-effects.md +2 -3
  38. package/docs/api/reference/feature-instances.md +5 -4
  39. package/docs/api/reference/features.md +7 -4
  40. package/docs/api/reference/geometry.md +132 -21
  41. package/docs/api/reference/grass.md +62 -2
  42. package/docs/api/reference/impostors.md +120 -16
  43. package/docs/api/reference/input.md +1 -2
  44. package/docs/api/reference/lights.md +4 -3
  45. package/docs/api/reference/lines.md +3 -4
  46. package/docs/api/reference/materials.md +7 -6
  47. package/docs/api/reference/math.md +13 -2
  48. package/docs/api/reference/objects.md +2 -3
  49. package/docs/api/reference/particles.md +31 -6
  50. package/docs/api/reference/points.md +2 -3
  51. package/docs/api/reference/post.md +4 -3
  52. package/docs/api/reference/quality.md +1 -2
  53. package/docs/api/reference/raycast.md +1 -2
  54. package/docs/api/reference/render.md +4 -3
  55. package/docs/api/reference/scene.md +24 -5
  56. package/docs/api/reference/sketch.md +11 -11
  57. package/docs/api/reference/sound.md +33 -2
  58. package/docs/api/reference/splats.md +42 -3
  59. package/docs/api/reference/sprites.md +2 -3
  60. package/docs/api/reference/tasks.md +16 -3
  61. package/docs/api/reference/terrain.md +26 -5
  62. package/docs/api/reference/textures.md +1 -2
  63. package/docs/api/reference/three-compat.md +18 -7
  64. package/docs/api/reference/time.md +1 -2
  65. package/docs/api/reference/ui.md +10 -7
  66. package/docs/api/reference/vertex-draws.md +2 -3
  67. package/docs/api/reference/water.md +78 -5
  68. package/docs/api/reference/wind.md +15 -2
  69. package/docs/api/render.md +67 -25
  70. package/docs/api/scene.md +129 -36
  71. package/docs/api/sketch.md +45 -19
  72. package/docs/api/sound.md +48 -12
  73. package/docs/api/splats.md +42 -15
  74. package/docs/api/sprites.md +8 -6
  75. package/docs/api/tasks.md +31 -22
  76. package/docs/api/terrain.md +44 -12
  77. package/docs/api/textures.md +61 -12
  78. package/docs/api/three-compat.md +15 -7
  79. package/docs/api/time.md +3 -5
  80. package/docs/api/ui.md +18 -10
  81. package/docs/api/vertex-draws.md +13 -12
  82. package/docs/api/water.md +111 -67
  83. package/docs/api/wind.md +61 -15
  84. package/docs/cli/null3d.md +90 -15
  85. package/docs/concepts/architecture.md +69 -23
  86. package/docs/concepts/assets.md +57 -16
  87. package/docs/concepts/backends.md +68 -24
  88. package/docs/concepts/color-management.md +42 -13
  89. package/docs/concepts/culling.md +68 -47
  90. package/docs/concepts/handles.md +14 -5
  91. package/docs/concepts/instances.md +72 -23
  92. package/docs/concepts/large-worlds.md +17 -7
  93. package/docs/concepts/lighting.md +117 -44
  94. package/docs/concepts/lod.md +128 -33
  95. package/docs/concepts/materials.md +43 -12
  96. package/docs/concepts/particle-buffer.md +48 -35
  97. package/docs/concepts/post-processing.md +77 -14
  98. package/docs/concepts/quality-preset-tables.md +3 -2
  99. package/docs/concepts/quality-presets.md +122 -39
  100. package/docs/concepts/render-graph.md +56 -21
  101. package/docs/concepts/render-layers.md +9 -5
  102. package/docs/concepts/shadows.md +96 -25
  103. package/docs/concepts/static-dynamic.md +22 -7
  104. package/docs/cookbook/index.md +163 -119
  105. package/docs/data/threejs-mapping.json +301 -340
  106. package/docs/errors/E1101.md +23 -5
  107. package/docs/errors/E1102.md +11 -3
  108. package/docs/errors/E1103.md +11 -3
  109. package/docs/errors/E1104.md +11 -3
  110. package/docs/errors/E1105.md +13 -5
  111. package/docs/errors/E1106.md +11 -3
  112. package/docs/errors/E1107.md +15 -5
  113. package/docs/errors/E1108.md +11 -3
  114. package/docs/errors/E1109.md +32 -6
  115. package/docs/errors/E1110.md +23 -5
  116. package/docs/errors/E1111.md +11 -3
  117. package/docs/errors/E1112.md +11 -3
  118. package/docs/errors/E1203.md +12 -4
  119. package/docs/errors/E1204.md +11 -3
  120. package/docs/errors/E1205.md +11 -3
  121. package/docs/errors/E1206.md +28 -6
  122. package/docs/errors/E1207.md +11 -3
  123. package/docs/errors/E1208.md +12 -3
  124. package/docs/errors/E1209.md +11 -3
  125. package/docs/errors/E1213.md +27 -5
  126. package/docs/errors/E1214.md +11 -3
  127. package/docs/errors/E1215.md +31 -6
  128. package/docs/errors/E1216.md +31 -6
  129. package/docs/errors/E1217.md +29 -6
  130. package/docs/errors/E1218.md +22 -6
  131. package/docs/errors/E1219.md +11 -3
  132. package/docs/errors/E1220.md +24 -5
  133. package/docs/errors/E1221.md +24 -5
  134. package/docs/errors/E1222.md +11 -3
  135. package/docs/errors/E1223.md +39 -6
  136. package/docs/errors/E1224.md +11 -3
  137. package/docs/errors/E1225.md +11 -3
  138. package/docs/errors/E1301.md +11 -3
  139. package/docs/errors/E1302.md +11 -3
  140. package/docs/errors/E1303.md +11 -3
  141. package/docs/errors/E1304.md +11 -3
  142. package/docs/errors/E1305.md +13 -3
  143. package/docs/errors/E1306.md +11 -3
  144. package/docs/errors/E1307.md +23 -6
  145. package/docs/errors/E1308.md +31 -0
  146. package/docs/errors/E1401.md +11 -3
  147. package/docs/errors/E1402.md +13 -5
  148. package/docs/errors/E1403.md +11 -3
  149. package/docs/errors/E1404.md +13 -3
  150. package/docs/errors/E1405.md +15 -4
  151. package/docs/errors/E1406.md +31 -5
  152. package/docs/errors/E1407.md +11 -3
  153. package/docs/errors/E1408.md +11 -3
  154. package/docs/errors/E1409.md +11 -3
  155. package/docs/errors/E1410.md +13 -5
  156. package/docs/errors/E1411.md +11 -3
  157. package/docs/errors/E1412.md +29 -6
  158. package/docs/errors/E1413.md +11 -3
  159. package/docs/errors/E1414.md +11 -3
  160. package/docs/errors/E1415.md +11 -3
  161. package/docs/errors/E1416.md +27 -6
  162. package/docs/errors/E1417.md +11 -3
  163. package/docs/errors/E1418.md +12 -3
  164. package/docs/errors/E1419.md +13 -5
  165. package/docs/errors/E1420.md +11 -3
  166. package/docs/errors/E1421.md +11 -3
  167. package/docs/errors/E1422.md +12 -3
  168. package/docs/errors/E1423.md +12 -3
  169. package/docs/errors/E1424.md +24 -5
  170. package/docs/errors/E1425.md +11 -3
  171. package/docs/errors/E1426.md +11 -3
  172. package/docs/errors/E1430.md +11 -3
  173. package/docs/errors/E1431.md +11 -3
  174. package/docs/errors/E1432.md +11 -3
  175. package/docs/errors/E1433.md +11 -3
  176. package/docs/errors/E1434.md +15 -6
  177. package/docs/errors/E1435.md +11 -3
  178. package/docs/errors/E1436.md +11 -3
  179. package/docs/errors/E1437.md +14 -6
  180. package/docs/errors/E1501.md +41 -6
  181. package/docs/errors/E1502.md +13 -3
  182. package/docs/errors/E1503.md +11 -3
  183. package/docs/errors/E1504.md +11 -3
  184. package/docs/errors/E1505.md +23 -5
  185. package/docs/errors/E1506.md +11 -3
  186. package/docs/errors/index.md +53 -29
  187. package/docs/getting-started/cdn.md +15 -9
  188. package/docs/getting-started/first-scene.md +20 -12
  189. package/docs/getting-started/hosting.md +113 -63
  190. package/docs/getting-started/install.md +39 -24
  191. package/docs/getting-started/network-use.md +31 -21
  192. package/docs/getting-started/project-structure.md +20 -8
  193. package/docs/getting-started/third-party-notices.md +6 -10
  194. package/docs/guides/accessibility.md +4 -4
  195. package/docs/guides/add-ons.md +83 -13
  196. package/docs/guides/agents.md +13 -14
  197. package/docs/guides/assets-pipeline.md +294 -72
  198. package/docs/guides/audio.md +17 -15
  199. package/docs/guides/baked-light-data.md +44 -23
  200. package/docs/guides/car-paint.md +37 -31
  201. package/docs/guides/content-pages.md +86 -29
  202. package/docs/guides/custom-passes.md +59 -17
  203. package/docs/guides/custom-shaders.md +54 -37
  204. package/docs/guides/debugging.md +31 -41
  205. package/docs/guides/deploying.md +10 -27
  206. package/docs/guides/deterministic-simulation.md +23 -16
  207. package/docs/guides/first-use-shaders.md +83 -45
  208. package/docs/guides/lens-kit.md +29 -26
  209. package/docs/guides/loading-screens.md +74 -30
  210. package/docs/guides/multiple-views.md +22 -11
  211. package/docs/guides/performance.md +188 -37
  212. package/docs/guides/phones.md +71 -19
  213. package/docs/guides/physics.md +6 -10
  214. package/docs/guides/screens.md +41 -29
  215. package/docs/guides/start-time.md +126 -85
  216. package/docs/guides/testing.md +137 -98
  217. package/docs/guides/ui-overlays.md +17 -12
  218. package/docs/guides/video-textures.md +14 -13
  219. package/docs/images/api/animation/character.webp +0 -0
  220. package/docs/images/api/animation/look-at-ring.webp +0 -0
  221. package/docs/images/api/animation/morph-tulips.webp +0 -0
  222. package/docs/images/api/animation/skeleton-lines.webp +0 -0
  223. package/docs/images/api/controls/gizmo-handles.webp +0 -0
  224. package/docs/images/api/controls/walk-and-fly.webp +0 -0
  225. package/docs/images/api/debug/debug-shapes.webp +0 -0
  226. package/docs/images/api/debug/levels-view.webp +0 -0
  227. package/docs/images/api/engine/transparent-canvas.webp +0 -0
  228. package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
  229. package/docs/images/api/feature-instances/compute-instances.webp +0 -0
  230. package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
  231. package/docs/images/api/geometry/extra-shapes.webp +0 -0
  232. package/docs/images/api/geometry/generators.webp +0 -0
  233. package/docs/images/api/geometry/mesh-arrays.webp +0 -0
  234. package/docs/images/api/geometry/vertex-updates.webp +0 -0
  235. package/docs/images/api/grass/grass-grove.webp +0 -0
  236. package/docs/images/api/grass/grass-presets.webp +0 -0
  237. package/docs/images/api/grass/grass-shadow.webp +0 -0
  238. package/docs/images/api/impostors/impostor-handover.webp +0 -0
  239. package/docs/images/api/impostors/impostor-shadow.webp +0 -0
  240. package/docs/images/api/impostors/impostors-forest.webp +0 -0
  241. package/docs/images/api/lights/spot-cookies.webp +0 -0
  242. package/docs/images/api/lines/lines-lit.webp +0 -0
  243. package/docs/images/api/lines/lines-widths.webp +0 -0
  244. package/docs/images/api/materials/coat-and-sheen.webp +0 -0
  245. package/docs/images/api/materials/decals.webp +0 -0
  246. package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
  247. package/docs/images/api/materials/relief.webp +0 -0
  248. package/docs/images/api/materials/shader-inputs.webp +0 -0
  249. package/docs/images/api/materials/standard-grid.webp +0 -0
  250. package/docs/images/api/materials/subsurface.webp +0 -0
  251. package/docs/images/api/materials/translucency.webp +0 -0
  252. package/docs/images/api/objects/objects-turntable.webp +0 -0
  253. package/docs/images/api/particles/campfire.webp +0 -0
  254. package/docs/images/api/points/galaxy.webp +0 -0
  255. package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
  256. package/docs/images/api/render/fullscreen-glow.webp +0 -0
  257. package/docs/images/api/render/reflection-mirror.webp +0 -0
  258. package/docs/images/api/render/security-camera.webp +0 -0
  259. package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
  260. package/docs/images/api/sound/sound-demo.webp +0 -0
  261. package/docs/images/api/splats/splats-demo.webp +0 -0
  262. package/docs/images/api/sprites/sprites-lines.webp +0 -0
  263. package/docs/images/api/terrain/terrain-demo.webp +0 -0
  264. package/docs/images/api/textures/canvas-screen.webp +0 -0
  265. package/docs/images/api/textures/mipmaps.webp +0 -0
  266. package/docs/images/api/vertex-draws/rain.webp +0 -0
  267. package/docs/images/api/water/ocean.webp +0 -0
  268. package/docs/images/api/water/water-demo.webp +0 -0
  269. package/docs/images/api/water/water-rain.webp +0 -0
  270. package/docs/images/api/water/waterfall.webp +0 -0
  271. package/docs/images/concepts/assets/gltf-model.webp +0 -0
  272. package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
  273. package/docs/images/concepts/culling/far-from-origin.webp +0 -0
  274. package/docs/images/concepts/instances/instances.webp +0 -0
  275. package/docs/images/concepts/instances/per-row-colors.webp +0 -0
  276. package/docs/images/concepts/large-worlds/large-world.webp +0 -0
  277. package/docs/images/concepts/lighting/area-lights.webp +0 -0
  278. package/docs/images/concepts/lighting/atmosphere.webp +0 -0
  279. package/docs/images/concepts/lighting/environment.webp +0 -0
  280. package/docs/images/concepts/lighting/light-shafts.webp +0 -0
  281. package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
  282. package/docs/images/concepts/lod/forest.webp +0 -0
  283. package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
  284. package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
  285. package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
  286. package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
  287. package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
  288. package/docs/images/concepts/post-processing/sharpen.webp +0 -0
  289. package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
  290. package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
  291. package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
  292. package/docs/images/cookbook/index/picking.webp +0 -0
  293. package/docs/images/cookbook/index/time-of-day.webp +0 -0
  294. package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
  295. package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
  296. package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
  297. package/docs/images/guides/multiple-views/split-screen.webp +0 -0
  298. package/docs/images/guides/performance/overdraw-view.webp +0 -0
  299. package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
  300. package/docs/images/index/showcase-island.webp +0 -0
  301. package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
  302. package/docs/images/shaders/builtins/builtins.webp +0 -0
  303. package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
  304. package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
  305. package/docs/images/shots.json +2231 -0
  306. package/docs/index.md +14 -23
  307. package/docs/moves.json +1 -0
  308. package/docs/nav.json +300 -0
  309. package/docs/pages.md +230 -212
  310. package/docs/porting/react-three-fiber.md +2 -6
  311. package/docs/porting/threejs-loop-and-threads.md +1 -5
  312. package/docs/porting/threejs-mapping.md +1248 -234
  313. package/docs/porting/threejs-materials.md +10 -5
  314. package/docs/porting/threejs-overview.md +26 -6
  315. package/docs/porting/threejs-postprocessing.md +2 -6
  316. package/docs/porting/threejs-shaders.md +16 -14
  317. package/docs/porting/threejs-unsupported.md +6 -6
  318. package/docs/porting/verification.md +0 -4
  319. package/docs/shaders/builtins.md +15 -4
  320. package/docs/shaders/library.md +9 -6
  321. package/docs/shaders/surface-functions.md +51 -16
  322. package/docs/shaders/wgsl-rules.md +12 -5
  323. package/lib/debug/debug.d.ts +2 -2
  324. package/lib/debug/draw.d.ts +2 -2
  325. package/lib/debug/draw.js +8 -4
  326. package/lib/debug/overlay-look.d.ts +6 -0
  327. package/lib/debug/overlay-look.js +29 -7
  328. package/lib/debug/overlay.js +15 -11
  329. package/lib/debug/stats-options.d.ts +13 -0
  330. package/lib/debug/stats-panel.d.ts +21 -6
  331. package/lib/debug/stats-panel.js +80 -13
  332. package/lib/errors/codes.d.ts +17 -3
  333. package/lib/errors/codes.js +116 -105
  334. package/lib/errors/engine-error.js +1 -1
  335. package/lib/errors/fixes.d.ts +1 -0
  336. package/lib/errors/fixes.js +19 -18
  337. package/lib/generated/shader-permutations.d.ts +6 -0
  338. package/lib/generated/shader-permutations.js +6 -0
  339. package/lib/gpu/variants.d.ts +8 -2
  340. package/lib/gpu/variants.js +39 -7
  341. package/lib/gpu/webgl2/programs.js +1 -1
  342. package/lib/gpu/webgpu/pipelines.js +13 -13
  343. package/lib/index.d.ts +1 -1
  344. package/lib/page/capabilities.d.ts +1 -1
  345. package/lib/page/engine.d.ts +29 -7
  346. package/lib/page/engine.js +79 -7
  347. package/lib/page/label-loop.js +9 -4
  348. package/lib/page/stats-switch.js +2 -0
  349. package/lib/page/switches.d.ts +6 -4
  350. package/lib/page/switches.js +20 -4
  351. package/lib/scene/baked-light.d.ts +2 -2
  352. package/lib/scene/fake-call-values.js +2 -2
  353. package/lib/scene/frame-cameras.d.ts +16 -4
  354. package/lib/scene/frame-cameras.js +28 -10
  355. package/lib/scene/gltf.d.ts +1 -1
  356. package/lib/scene/level-rule.d.ts +6 -5
  357. package/lib/scene/level-rule.js +2 -2
  358. package/lib/scene/particles.d.ts +7 -3
  359. package/lib/scene/particles.js +3 -1
  360. package/lib/scene/post.d.ts +3 -2
  361. package/lib/scene/resources.d.ts +15 -9
  362. package/lib/scene/scene.d.ts +18 -2
  363. package/lib/scene/scene.js +47 -5
  364. package/lib/scene/time-of-day.d.ts +10 -5
  365. package/lib/scene/time-of-day.js +11 -7
  366. package/lib/shader-artifact.json +1 -1
  367. package/lib/shared/labels.d.ts +5 -2
  368. package/lib/shared/labels.js +5 -2
  369. package/lib/shared/permutation-words.d.ts +8 -0
  370. package/lib/shared/permutation-words.js +14 -0
  371. package/lib/shared/recording.d.ts +13 -5
  372. package/lib/shared/recording.js +31 -10
  373. package/lib/shared/sketch-data.d.ts +9 -0
  374. package/lib/shared/sketch-data.js +57 -0
  375. package/lib/shared/tier.d.ts +9 -0
  376. package/lib/shared/tier.js +4 -1
  377. package/lib/shared/version.d.ts +1 -1
  378. package/lib/shared/version.js +1 -1
  379. package/lib/sketch/define-sketch.d.ts +16 -7
  380. package/lib/sketch/define-sketch.js +2 -1
  381. package/lib/sketch/runner.d.ts +4 -0
  382. package/lib/sketch/runner.js +5 -0
  383. package/lib/sketch/ui.js +4 -2
  384. package/lib/stats.d.ts +1 -0
  385. package/lib/workers/protocol.d.ts +10 -0
  386. package/lib/workers/render-worker.js +4 -1
  387. package/lib/workers/sketch-worker.js +4 -1
  388. package/package.json +1 -1
@@ -1,29 +1,48 @@
1
1
  ---
2
2
  id: cookbook/index
3
3
  title: Cookbook
4
- status: experimental
5
- since: "0.2"
6
- summary: "Short recipes; each is also a tested example."
4
+ summary: "Recipes for one common task each: selection, cameras, characters, loading, sky and effects, screens, and hiding what walls hide."
7
5
  ---
8
6
 
9
7
  # Cookbook
10
8
 
11
- > Roadmap step 0.2, first released in null3D 0.1.0. The APIs that the recipes use are experimental, so they can still change between versions.
9
+ Each recipe is a complete sketch for one common task. Copy it into your project's `sketch.ts` and change it from there.
12
10
 
13
- ```mermaid
14
- flowchart LR
15
- page["A recipe on this page"] --> check["The type check:<br/>every call exists"]
16
- page --> hold["Hold mode on every GPU tier:<br/>the sketch sets up, steps<br/>and draws without an error"]
17
- ```
11
+ The engine's tests type check every recipe and draw it in [hold mode](../guides/testing.md) on every GPU tier. So each call that a recipe shows exists and runs in this version.
12
+
13
+ The recipes that load files name them as a project serves them from its `public` folder, such as `/models/knight.glb`. Put your own files there. The tests serve these files at those addresses:
14
+
15
+ | Address | File | Source |
16
+ | --- | --- | --- |
17
+ | `/models/knight.glb` | `Knight.glb` | [KayKit Adventurers](https://kaylousberg.itch.io/kaykit-adventurers) (CC0) |
18
+ | `/models/morph-cube.glb` | `AnimatedMorphCube.glb` | [Khronos glTF sample assets](https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/AnimatedMorphCube) |
19
+ | `/env/sunset.hdr` | `venice_sunset_2k.hdr` | [Poly Haven](https://polyhaven.com/a/venice_sunset) (CC0) |
20
+
21
+ ## Recipes
18
22
 
19
- Each recipe is a complete sketch for one common task. Copy it into your project's `sketch.ts` and change it from there. The engine's tests run every recipe on this page. They type check it against the engine, and draw it in [hold mode](../guides/testing.md) on every GPU tier. So each call that a recipe shows exists and runs in this version.
23
+ - [Select objects with the pointer](#select-objects-with-the-pointer): cast a ray from a click.
24
+ - [Walk to the point that the user clicks](#walk-to-the-point-that-the-user-clicks): move a character along the ground.
25
+ - [A third-person camera for an animated character](#a-third-person-camera-for-an-animated-character): follow a character that plays clips.
26
+ - [A crowd of animated characters](#a-crowd-of-animated-characters): draw many copies of one animated model.
27
+ - [Morph targets from a model](#morph-targets-from-a-model): blend a face or a shape.
28
+ - [A loading screen for models](#a-loading-screen-for-models): wait for a file and the first frame.
29
+ - [A sky with a moving sun and fog](#a-sky-with-a-moving-sun-and-fog): a time of day.
30
+ - [Glow and a custom effect](#glow-and-a-custom-effect): a full-screen pass of your own.
31
+ - [A trail behind a moving object](#a-trail-behind-a-moving-object): draw the path that something took.
32
+ - [A field of stars](#a-field-of-stars): draw many points.
33
+ - [A screen that shows another camera](#a-screen-that-shows-another-camera): draw a camera to a texture.
34
+ - [Screens in the world](#screens-in-the-world): draw a canvas on a mesh.
35
+ - [Hide what walls hide](#hide-what-walls-hide): skip objects behind large blockers.
20
36
 
21
- The recipes that load files name them as a project serves them from its `public` folder, such as `/models/knight.glb`. Put your own files there. The tests serve the [KayKit Knight](https://kaylousberg.itch.io/kaykit-adventurers) (CC0), a [Khronos glTF sample model](https://github.com/KhronosGroup/glTF-Sample-Assets) and a [Poly Haven](https://polyhaven.com/a/venice_sunset) sky (CC0) at those addresses.
22
37
 
23
38
  ## Select objects with the pointer
24
39
 
25
40
  `object.on` casts a ray from the pointer for you, and calls the handler of the object under it. The pointer lights up the box under it, and a click outlines the box. A second click on it clears the outline.
26
41
 
42
+ ![Six pieces on a plinth in a dark gallery, with the red cube outlined after a click.](../images/cookbook/index/picking.webp)
43
+
44
+ The picking demo.
45
+
27
46
  ```ts
28
47
  import { defineSketch, type Mesh } from '@null3d/engine';
29
48
 
@@ -57,6 +76,7 @@ export default defineSketch(({ scene, geometry, materials, post }) => {
57
76
 
58
77
  An event on a child also reaches its parents, so one handler on a model's copy hears clicks on every mesh in it. A click that outlines a mesh rebuilds the engine's draw tables once. That is fine for a click, but not for every frame. [Input](../api/input.md#pointer-events-on-objects) lists the events.
59
78
 
79
+
60
80
  ## Walk to the point that the user clicks
61
81
 
62
82
  A ray of your own can test only some layers. Here the ground has a layer of its own, and the click's ray tests only that layer. So the ray never stops on the player or on the marker.
@@ -137,6 +157,7 @@ export default defineSketch(({ scene, geometry, materials, input }) => {
137
157
 
138
158
  The pointer's place comes with the frame that was on screen when the user clicked. So `screenToRay` casts the ray that the user saw, even while the camera moves. [Raycasting](../api/raycast.md) covers rays, batches of rays and overlap queries.
139
159
 
160
+
140
161
  ## A third-person camera for an animated character
141
162
 
142
163
  A character walks where the keys or the left stick point, relative to the camera. A drag turns the camera around the character. A 1D blend mixes the idle, walk and run clips by the character's speed, and keeps their steps in phase.
@@ -222,6 +243,7 @@ export default defineSketch(async ({ scene, assets, geometry, materials, input }
222
243
 
223
244
  The job workers sample and blend the clips, so the sketch only sets the blend's value. `setBlend` allocates nothing, so call it in every frame. The blend's points sit in a frozen object, which the animator reads once. [Animation](../api/animation.md#1d-blends) explains blends, layers and clip events.
224
245
 
246
+
225
247
  ## A crowd of animated characters
226
248
 
227
249
  Each copy of a model gets an animator of its own. Give each copy a start time and a speed of its own, so the crowd does not step in time.
@@ -267,6 +289,36 @@ export default defineSketch(async ({ scene, assets, geometry, materials }) => {
267
289
 
268
290
  A copy costs one object for each mesh, and its joints cost no objects. The job workers animate the whole crowd, spread over every worker, and the sketch's thread does none of it. Instance batches draw a model in its rest pose only, so give each animated character a copy of its own. The [performance guide](../guides/performance.md) says what a crowd costs on each GPU path.
269
291
 
292
+
293
+ ## Morph targets from a model
294
+
295
+ A glTF file's morph targets load with its meshes. Set each target's weight by its number, or by its name when the file names its targets.
296
+
297
+ ```ts
298
+ import { defineSketch, type Mesh } from '@null3d/engine';
299
+
300
+ export default defineSketch(async ({ scene, assets, time }) => {
301
+ scene.setBackground('#20242a');
302
+ scene.setEnvironment(await assets.builtinEnvironment('room'));
303
+ const camera = scene.createPerspectiveCamera({ fov: 40, position: [2.5, 2, 4], target: [0, 0, 0] });
304
+ scene.setActiveCamera(camera);
305
+
306
+ const model = await assets.loadGltf('/models/morph-cube.glb');
307
+ const cube = scene.instantiate(model).find('AnimatedMorphCube') as Mesh;
308
+
309
+ return {
310
+ onUpdate() {
311
+ // Two targets: one makes the cube thin, the other bends its top.
312
+ cube.setMorphWeight(0, 0.5 + 0.5 * Math.sin(time.now * 2));
313
+ cube.setMorphWeight(1, 0.5 + 0.5 * Math.cos(time.now * 1.3));
314
+ },
315
+ };
316
+ });
317
+ ```
318
+
319
+ `setMorphWeight` allocates nothing, so call it in every frame. A clip of the file can animate the weights too, and it blends them with the weights that you set. [Morph targets](../api/animation.md#morph-targets) explains the blend, and what morphing costs on each GPU path.
320
+
321
+
270
322
  ## A loading screen for models
271
323
 
272
324
  The sketch downloads its files at once, and posts how far the downloads have come. Then it builds the scene and waits for the GPU's pipelines, so the first frame shows the whole scene.
@@ -302,38 +354,15 @@ export default defineSketch(async ({ scene, assets, page }) => {
302
354
 
303
355
  The page shows the progress in its own HTML, and removes the loading screen when `engine.firstFrame` resolves. [Loading screens](../guides/loading-screens.md) shows the page's side, and how to load the shaders of skinning and other features before the first frame.
304
356
 
305
- ## Morph targets from a model
306
-
307
- A glTF file's morph targets load with its meshes. Set each target's weight by its number, or by its name when the file names its targets.
308
-
309
- ```ts
310
- import { defineSketch, type Mesh } from '@null3d/engine';
311
-
312
- export default defineSketch(async ({ scene, assets, time }) => {
313
- scene.setBackground('#20242a');
314
- scene.setEnvironment(await assets.builtinEnvironment('room'));
315
- const camera = scene.createPerspectiveCamera({ fov: 40, position: [2.5, 2, 4], target: [0, 0, 0] });
316
- scene.setActiveCamera(camera);
317
-
318
- const model = await assets.loadGltf('/models/morph-cube.glb');
319
- const cube = scene.instantiate(model).find('AnimatedMorphCube') as Mesh;
320
-
321
- return {
322
- onUpdate() {
323
- // Two targets: one makes the cube thin, the other bends its top.
324
- cube.setMorphWeight(0, 0.5 + 0.5 * Math.sin(time.now * 2));
325
- cube.setMorphWeight(1, 0.5 + 0.5 * Math.cos(time.now * 1.3));
326
- },
327
- };
328
- });
329
- ```
330
-
331
- `setMorphWeight` allocates nothing, so call it in every frame. A clip of the file can animate the weights too, and it blends them with the weights that you set. [Morph targets](../api/animation.md#morph-targets) explains the blend, and what morphing costs on each GPU path.
332
357
 
333
358
  ## A sky with a moving sun and fog
334
359
 
335
360
  The sky's sun and the scene's sun move together. Height fog lies low over the ground, and glows toward the sun.
336
361
 
362
+ ![A lighthouse island at sunset with the sun on the horizon.](../images/cookbook/index/time-of-day.webp)
363
+
364
+ The time of day demo.
365
+
337
366
  ```ts
338
367
  import { defineSketch } from '@null3d/engine';
339
368
 
@@ -385,6 +414,7 @@ export default defineSketch(({ scene, geometry, materials, time }) => {
385
414
 
386
415
  The fog covers objects but not the sky, so give the fog a color near the sky's color at the horizon. [Fog](../api/scene.md#fog) gives every fog setting, and [the sky](../api/scene.md#environments-cube-maps-and-the-sky) every sky setting.
387
416
 
417
+
388
418
  ## Glow and a custom effect
389
419
 
390
420
  Bloom spreads the light of bright surfaces past their edges. A custom effect of your own WGSL then darkens every other row of pixels, as an old screen does.
@@ -430,6 +460,89 @@ export default defineSketch(({ scene, geometry, materials, post, time }) => {
430
460
 
431
461
  Effects run on the scene's HDR color, before bloom and the tone curve. On a device that has no HDR color, effects stay off. [Post effects](../api/post.md) gives every setting, and [Custom passes](../guides/custom-passes.md) says what an effect can read and what it costs.
432
462
 
463
+
464
+ ## A trail behind a moving object
465
+
466
+ A dynamic line batch updates every point in every frame. Each frame, the sketch moves the trail's points one place back and puts the object's place at the front.
467
+
468
+ ```ts
469
+ import { defineSketch } from '@null3d/engine';
470
+
471
+ /** Points along the trail. */
472
+ const POINTS = 120;
473
+
474
+ export default defineSketch(async ({ scene, geometry, materials, time }) => {
475
+ scene.setBackground('#0a0c14');
476
+ const camera = scene.createPerspectiveCamera({ fov: 50, position: [0, 5, 9], target: [0, 0, 0] });
477
+ scene.setActiveCamera(camera);
478
+ scene.createAmbientLight({ intensity: 1 });
479
+ const comet = scene.createMesh({
480
+ mesh: geometry.sphere({ radius: 0.15 }),
481
+ material: materials.unlit({ color: '#ffd166' }),
482
+ dynamic: true,
483
+ });
484
+ const trail = await scene.createLines({
485
+ positions: new Float32Array(POINTS * 3),
486
+ width: 4,
487
+ color: '#ff8c42',
488
+ dynamic: true,
489
+ });
490
+
491
+ return {
492
+ onUpdate() {
493
+ const x = Math.cos(time.now * 1.5) * 3;
494
+ const y = Math.sin(time.now * 3) * 0.6;
495
+ const z = Math.sin(time.now * 1.5) * 3;
496
+ comet.setPosition(x, y, z);
497
+ // Read the array from the batch each frame: the engine's memory can grow.
498
+ const { positions } = trail;
499
+ positions.copyWithin(3, 0, (POINTS - 1) * 3);
500
+ positions[0] = x;
501
+ positions[1] = y;
502
+ positions[2] = z;
503
+ },
504
+ };
505
+ });
506
+ ```
507
+
508
+ The width is in CSS pixels, so the trail looks the same on every screen. Give `worldUnits: true` for a width in meters instead. [Lines](../api/lines.md) covers dashes, lit lines and line hits.
509
+
510
+
511
+ ## A field of stars
512
+
513
+ A point batch draws thousands of points in one draw. With `sizeAttenuation: false`, each point keeps its size in CSS pixels at every distance.
514
+
515
+ ```ts
516
+ import { defineSketch, math } from '@null3d/engine';
517
+
518
+ const STARS = 5000;
519
+
520
+ export default defineSketch(async ({ scene, time }) => {
521
+ scene.setBackground('#02030a');
522
+ const camera = scene.createPerspectiveCamera({ fov: 60, far: 500 });
523
+ scene.setActiveCamera(camera);
524
+
525
+ // Random points on a large sphere around the camera.
526
+ const positions = new Float32Array(STARS * 3);
527
+ for (let i = 0; i < STARS; i++) {
528
+ const y = math.randFloat(-1, 1);
529
+ const angle = math.randFloat(0, Math.PI * 2);
530
+ const ring = Math.sqrt(1 - y * y);
531
+ positions.set([Math.cos(angle) * ring * 200, y * 200, Math.sin(angle) * ring * 200], i * 3);
532
+ }
533
+ await scene.createPoints({ positions, size: 2, sizeAttenuation: false });
534
+
535
+ return {
536
+ onUpdate() {
537
+ camera.setRotationEuler(0.2, time.now * 0.05, 0);
538
+ },
539
+ };
540
+ });
541
+ ```
542
+
543
+ A point batch that you never change is static, and costs no uploads after its first frame. [Points](../api/points.md) covers colors, round points and clicks on points. For points of many sizes, or particles that each have a picture, use [sprites](../api/sprites.md).
544
+
545
+
433
546
  ## A screen that shows another camera
434
547
 
435
548
  A scene pass draws the scene from a second camera into a texture, and a material shows that texture. This map screen shows the yard from above. The pass draws every third frame only, which saves two thirds of its cost.
@@ -477,6 +590,7 @@ export default defineSketch(({ scene, geometry, materials, textures, render, tim
477
590
 
478
591
  A pass never draws the objects that show its own texture, so the screen does not show itself. A pass that nothing shows costs nothing. [Render graph API](../api/render.md) says what a scene pass draws.
479
592
 
593
+
480
594
  ## Screens in the world
481
595
 
482
596
  An `OffscreenCanvas` in the sketch is a texture. Draw on it with the 2D context, and refresh only the rectangle that changed. Here the screen shows a score that counts up, on a panel in the world.
@@ -537,89 +651,10 @@ The `refreshHz` option caps the refreshes, so a frame rate above the cap costs n
537
651
 
538
652
  The screens example add-on in `examples/addons/screens` builds this pattern into one call. It adds a refresh rate for each screen, an LCD look that changes with distance, a boot glitch, and clicks mapped back to the canvas's coordinates. [In-world screens](../guides/screens.md) covers it.
539
653
 
540
- ## A trail behind a moving object
541
-
542
- A dynamic line batch updates every point in every frame. Each frame, the sketch moves the trail's points one place back and puts the object's place at the front.
543
-
544
- ```ts
545
- import { defineSketch } from '@null3d/engine';
546
-
547
- /** Points along the trail. */
548
- const POINTS = 120;
549
-
550
- export default defineSketch(async ({ scene, geometry, materials, time }) => {
551
- scene.setBackground('#0a0c14');
552
- const camera = scene.createPerspectiveCamera({ fov: 50, position: [0, 5, 9], target: [0, 0, 0] });
553
- scene.setActiveCamera(camera);
554
- scene.createAmbientLight({ intensity: 1 });
555
- const comet = scene.createMesh({
556
- mesh: geometry.sphere({ radius: 0.15 }),
557
- material: materials.unlit({ color: '#ffd166' }),
558
- dynamic: true,
559
- });
560
- const trail = await scene.createLines({
561
- positions: new Float32Array(POINTS * 3),
562
- width: 4,
563
- color: '#ff8c42',
564
- dynamic: true,
565
- });
566
-
567
- return {
568
- onUpdate() {
569
- const x = Math.cos(time.now * 1.5) * 3;
570
- const y = Math.sin(time.now * 3) * 0.6;
571
- const z = Math.sin(time.now * 1.5) * 3;
572
- comet.setPosition(x, y, z);
573
- // Read the array from the batch each frame: the engine's memory can grow.
574
- const { positions } = trail;
575
- positions.copyWithin(3, 0, (POINTS - 1) * 3);
576
- positions[0] = x;
577
- positions[1] = y;
578
- positions[2] = z;
579
- },
580
- };
581
- });
582
- ```
583
-
584
- The width is in CSS pixels, so the trail looks the same on every screen. Give `worldUnits: true` for a width in meters instead. [Lines](../api/lines.md) covers dashes, lit lines and line hits.
585
-
586
- ## A field of stars
587
-
588
- A point batch draws thousands of points in one draw. With `sizeAttenuation: false`, each point keeps its size in CSS pixels at every distance.
589
-
590
- ```ts
591
- import { defineSketch, math } from '@null3d/engine';
592
-
593
- const STARS = 5000;
594
-
595
- export default defineSketch(async ({ scene, time }) => {
596
- scene.setBackground('#02030a');
597
- const camera = scene.createPerspectiveCamera({ fov: 60, far: 500 });
598
- scene.setActiveCamera(camera);
599
-
600
- // Random points on a large sphere around the camera.
601
- const positions = new Float32Array(STARS * 3);
602
- for (let i = 0; i < STARS; i++) {
603
- const y = math.randFloat(-1, 1);
604
- const angle = math.randFloat(0, Math.PI * 2);
605
- const ring = Math.sqrt(1 - y * y);
606
- positions.set([Math.cos(angle) * ring * 200, y * 200, Math.sin(angle) * ring * 200], i * 3);
607
- }
608
- await scene.createPoints({ positions, size: 2, sizeAttenuation: false });
609
-
610
- return {
611
- onUpdate() {
612
- camera.setRotationEuler(0.2, time.now * 0.05, 0);
613
- },
614
- };
615
- });
616
- ```
617
-
618
- A point batch that you never change is static, and costs no uploads after its first frame. [Points](../api/points.md) covers colors, round points and clicks on points. For points of many sizes, or particles that each have a picture, use [sprites](../api/sprites.md).
619
654
 
620
655
  ## Hide what walls hide
621
656
 
622
- Large, solid objects hide the objects that lie wholly behind them, and the engine skips those. Here a wall hides a field of crates from the camera. On WebGPU, High and Ultra cull them on desktops without a mark, and `createEngine`'s `gpuOcclusion` option turns it on or off. On WebGL2, mark the wall with `occluder: true`, and `createEngine`'s `softwareOcclusion` option turns the culling on.
657
+ Large, solid objects hide the objects that lie wholly behind them, and the engine skips those. Here a wall hides a field of crates from the camera. On WebGPU, High and Ultra cull them on desktops with no `occluder` mark, and `createEngine`'s `gpuOcclusion` option turns it on or off. On WebGL2, mark the wall with `occluder: true`, and `createEngine`'s `softwareOcclusion` option turns the culling on.
623
658
 
624
659
  ```ts
625
660
  import { defineSketch } from '@null3d/engine';
@@ -653,12 +688,21 @@ export default defineSketch(({ scene, geometry, materials }) => {
653
688
  });
654
689
  ```
655
690
 
691
+ The sketch alone culls nothing on WebGL2, because every preset leaves software occlusion off. Turn it on where you create the engine:
692
+
693
+ ```ts
694
+ const engine = await createEngine({ canvas, sketch, softwareOcclusion: true });
695
+ ```
696
+
697
+ On WebGPU, the sketch culls only on desktops at High or Ultra, unless you pass `gpuOcclusion: true`.
698
+
656
699
  Occlusion culling saves GPU time only where occluders hide many objects, such as the buildings along a street. Each occluder costs some work of its own. So measure your scene with occlusion culling on and off: `engine.measure()` counts the objects that it hid. [Culling](../concepts/culling.md) explains both methods, and which presets turn them on.
657
700
 
701
+
658
702
  ## Related pages
659
703
 
660
704
  - [Loading screens](../guides/loading-screens.md): progress, warm-up and the preset check.
661
705
  - [The asset pipeline](../guides/assets-pipeline.md): smaller, faster models and textures for your files.
662
706
  - [Performance guide](../guides/performance.md): what each feature costs, and how to measure it.
663
- - [UI, HTML overlays and labels](../guides/ui-overlays.md): name tags and health bars that follow objects.
707
+ - [HTML UI around the scene](../guides/ui-overlays.md): name tags and health bars that follow objects.
664
708
  - [Examples](https://github.com/null3d-engine/null3d/tree/main/examples): longer demos, each with its own sketch.