@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,14 +1,12 @@
1
1
  ---
2
2
  id: api/geometry
3
3
  title: Geometry
4
- status: experimental
5
- since: "0.1"
6
- summary: "Generators with three.js parameters; extra shapes in @null3d/geometry; meshes from arrays; morph targets; vertices that change; levels of detail that meshes plan on the job workers; vertex formats; large meshes."
4
+ summary: "Generators of common shapes; extra shapes in @null3d/geometry; meshes from arrays; morph targets; vertices that change; levels of detail that meshes plan on the job workers; vertex formats; large meshes."
7
5
  ---
8
6
 
9
7
  # Geometry
10
8
 
11
- > Roadmap step 0.1, first released in null3D 0.1.0. Step 0.2 adds integer attributes, joints and weights, morph targets, the `@null3d/geometry` package, vertex updates and the levels of detail that meshes made in code plan. The API is experimental, so it can still change between versions. Not built yet: a call that skins a mesh you build. So joints and weights do not move its vertices yet. Coding agents must not use it.
9
+ > No call skins a mesh that you build, so its joints and weights do not move its vertices.
12
10
 
13
11
  ```mermaid
14
12
  flowchart LR
@@ -21,11 +19,15 @@ flowchart LR
21
19
  mesh --> objects["scene.createMesh()<br/>scene.createInstances()"]
22
20
  ```
23
21
 
24
- A mesh is the shape that objects draw. `ctx.geometry` makes meshes, and any number of objects and instance batches can share one mesh. The generators make common shapes with three.js's parameters. `geometry.fromArrays` makes a mesh from your own vertex data, as three.js's `BufferGeometry` does.
22
+ A mesh is the shape that objects draw. `ctx.geometry` makes meshes, and any number of objects and instance batches can share one mesh. The generators make common shapes from named options. `geometry.fromArrays` makes a mesh from your own vertex data.
25
23
 
26
24
  ## Generators
27
25
 
28
- Each generator takes the parameters and defaults of a three.js geometry class, as named options. It builds the same vertices in the same order as three.js, so a scene draws the same triangles in both engines.
26
+ Each generator takes named options. An option that you leave out takes its default.
27
+
28
+ ![Nine shapes in a 3 by 3 grid, three with a tile texture made in code and the rest plastic and metal.](../images/api/geometry/generators.webp)
29
+
30
+ The geometry generators.
29
31
 
30
32
  ```ts
31
33
  // sketch.ts
@@ -35,31 +37,35 @@ const pillar = geometry.cylinder({ radiusTop: 0.3, radiusBottom: 0.4, height: 2
35
37
  scene.createMesh({ mesh: crate, material: materials.standard({ color: '#c8a064' }) });
36
38
  ```
37
39
 
38
- | Generator | three.js class | Shape |
39
- | --- | --- | --- |
40
- | `geometry.box` | `BoxGeometry` | A box |
41
- | `geometry.sphere` | `SphereGeometry` | A sphere with its poles on the Y axis, or a part of one |
42
- | `geometry.plane` | `PlaneGeometry` | A rectangle in the XY plane that faces +Z |
43
- | `geometry.cylinder` | `CylinderGeometry` | A cylinder on the Y axis, closed at each end unless `openEnded` is true |
44
- | `geometry.cone` | `ConeGeometry` | A cone on the Y axis, with its point at the top |
45
- | `geometry.torus` | `TorusGeometry` | A tube bent into a ring around the Z axis |
46
- | `geometry.capsule` | `CapsuleGeometry` | A cylinder on the Y axis with a half sphere on each end |
47
- | `geometry.circle` | `CircleGeometry` | A disc in the XY plane that faces +Z, or a slice of one |
48
- | `geometry.ring` | `RingGeometry` | A disc with a hole, in the XY plane, that faces +Z |
40
+ | Generator | Shape |
41
+ | --- | --- |
42
+ | `geometry.box` | A box |
43
+ | `geometry.sphere` | A sphere with its poles on the Y axis, or a part of one |
44
+ | `geometry.plane` | A rectangle in the XY plane that faces +Z |
45
+ | `geometry.cylinder` | A cylinder on the Y axis, closed at each end unless `openEnded` is true |
46
+ | `geometry.cone` | A cone on the Y axis, with its point at the top |
47
+ | `geometry.torus` | A tube bent into a ring around the Z axis |
48
+ | `geometry.capsule` | A cylinder on the Y axis with a half sphere on each end |
49
+ | `geometry.circle` | A disc in the XY plane that faces +Z, or a slice of one |
50
+ | `geometry.ring` | A disc with a hole, in the XY plane, that faces +Z |
49
51
 
50
- Every shape is centered on its origin. The options have the names of the three.js constructor's arguments, and the API reference below gives each default. Angles are in radians. Segment counts round down to whole numbers. Each count has a least, which the API reference gives, and a smaller count rises to it. A sphere, for example, has at least 3 segments around it.
52
+ Every shape is centered on its origin. The API reference below gives each option and its default. Angles are in radians. Segment counts round down to whole numbers. Each count has a least, which the API reference gives, and a smaller count rises to it. A sphere, for example, has at least 3 segments around it.
51
53
 
52
- The generators give each vertex a position, a normal and texture coordinates, with the values that three.js gives them. The [geometry generators demo](https://github.com/null3d-engine/null3d/tree/main/examples/generators) draws all nine shapes.
54
+ The generators give each vertex a position, a normal and texture coordinates. The [geometry generators demo](https://github.com/null3d-engine/null3d/tree/main/examples/generators) draws all nine shapes.
53
55
 
54
56
  ## Extra shapes
55
57
 
56
- The `@null3d/geometry` package holds the rest of three.js's geometry classes. Install it beside the engine:
58
+ The `@null3d/geometry` package holds more shapes, and the curves and outlines that build them. Install it beside the engine:
59
+
60
+ ![A torus knot, polyhedra, a lathe vase, an extruded star, a tube and a glowing flat heart, reflected in a polished floor at dusk.](../images/api/geometry/extra-shapes.webp)
61
+
62
+ Extra shapes from @null3d/geometry.
57
63
 
58
64
  ```sh
59
65
  bun add @null3d/geometry
60
66
  ```
61
67
 
62
- Each function takes the parameters and defaults of a three.js class, as named options, and returns arrays for `geometry.fromArrays`. The arrays hold the same numbers as the three.js geometry's attributes: the same vertices in the same order, with the same normals and texture coordinates. The mesh that `fromArrays` makes from them plans its [levels of detail](#levels-of-detail) as any mesh made in code does, and keeps that order.
68
+ Each function takes named options, and an option that you leave out takes its default. It returns arrays for `geometry.fromArrays`. The arrays hold a position, a normal and texture coordinates for each vertex, and indices for some shapes. The mesh that `fromArrays` makes from them plans its [levels of detail](#levels-of-detail) as any mesh made in code does, and keeps its vertices in their order.
63
69
 
64
70
  ```ts
65
71
  // sketch.ts
@@ -70,23 +76,23 @@ const outline = new Shape().moveTo(0, 0).lineTo(1, 0).lineTo(0.5, 1).lineTo(0, 0
70
76
  const wedge = geometry.fromArrays(extrude({ shapes: outline, depth: 0.4, bevelEnabled: false }));
71
77
  ```
72
78
 
73
- | Function | three.js class | Shape |
74
- | --- | --- | --- |
75
- | `torusKnot` | `TorusKnotGeometry` | A tube that winds around a torus |
76
- | `tetrahedron`, `octahedron`, `icosahedron`, `dodecahedron` | `TetrahedronGeometry` and the others | A polyhedron, with `detail` that splits its faces toward a sphere |
77
- | `polyhedron` | `PolyhedronGeometry` | A polyhedron from your own corners and faces |
78
- | `lathe` | `LatheGeometry` | A profile of points turned around the Y axis, such as a vase |
79
- | `shape` | `ShapeGeometry` | A flat shape from outlines, with holes, in the XY plane |
80
- | `extrude` | `ExtrudeGeometry` | A shape pushed along +Z or along a curve, with an optional bevel |
81
- | `tube` | `TubeGeometry` | A tube along a 3D curve |
79
+ | Function | Shape |
80
+ | --- | --- |
81
+ | `torusKnot` | A tube that winds around a torus |
82
+ | `tetrahedron`, `octahedron`, `icosahedron`, `dodecahedron` | A polyhedron, with `detail` that splits its faces toward a sphere |
83
+ | `polyhedron` | A polyhedron from your own corners and faces |
84
+ | `lathe` | A profile of points turned around the Y axis, such as a vase |
85
+ | `shape` | A flat shape from outlines, with holes, in the XY plane |
86
+ | `extrude` | A shape pushed along +Z or along a curve, with an optional bevel |
87
+ | `tube` | A tube along a 3D curve |
82
88
 
83
- The package also has the classes that these shapes take, with three.js's names and methods. `Shape` and `Path` draw with `moveTo`, `lineTo`, `bezierCurveTo` and the rest. The 2D and 3D curves, such as `CatmullRomCurve3`, and `ShapeUtils` come too. Points are arrays of numbers, `[x, y]` or `[x, y, z]`, not `Vector2` or `Vector3` objects. A method that returns a point returns a new array, or fills the array that you pass last.
89
+ The package also has the classes that these shapes take. `Shape` and `Path` draw with `moveTo`, `lineTo`, `bezierCurveTo` and the rest. The 2D and 3D curves, such as `CatmullRomCurve3`, and `ShapeUtils` come too. Points are arrays of numbers, `[x, y]` or `[x, y, z]`. A method that returns a point returns a new array, or fills the array that you pass last.
84
90
 
85
- A mesh has one material. three.js's `ExtrudeGeometry` puts its caps and its sides in two groups, which can take two materials. Here they form one mesh. To give the caps a material of their own, make them as a second mesh with `shape`, at each end. The [extra shapes demo](https://github.com/null3d-engine/null3d/tree/main/examples/extra-shapes) draws a shape from each function.
91
+ A mesh has one material, and an extrusion's caps and sides form one mesh. To give the caps a material of their own, make them as a second mesh with `shape`, at each end. The [extra shapes demo](https://github.com/null3d-engine/null3d/tree/main/examples/extra-shapes) draws a shape from each function.
86
92
 
87
93
  ## Meshes from arrays
88
94
 
89
- `geometry.fromArrays` takes one array per vertex attribute, laid out as three.js's `BufferGeometry` keeps them: the values of vertex 0, then vertex 1, and so on. Typed arrays and plain arrays of numbers both work. An attribute can also come as 8-bit or 16-bit integers, as [integer attributes](#integer-attributes) shows.
95
+ `geometry.fromArrays` takes one flat array per vertex attribute: the values of vertex 0, then vertex 1, and so on. Typed arrays and plain arrays of numbers both work. An attribute can also come as 8-bit or 16-bit integers, as [integer attributes](#integer-attributes) shows.
90
96
 
91
97
  ```ts
92
98
  // sketch.ts: a quad that faces +z, with texture coordinates
@@ -99,24 +105,25 @@ const quad = geometry.fromArrays({
99
105
  scene.createMesh({ mesh: quad, material: materials.unlit({ color: '#ffffff' }) });
100
106
  ```
101
107
 
102
- | Array | Numbers per vertex | three.js attribute |
103
- | --- | --- | --- |
104
- | `positions` | 3 | `position` |
105
- | `normals` | 3 | `normal` |
106
- | `uvs` | 2 | `uv` |
107
- | `uvs1` | 2, such as a light map's coordinates | `uv1` |
108
- | `colors` | 3, or 4 with alpha, as linear values from 0 to 1 | `color` |
109
- | `tangents` | 4: the direction in which u grows, then 1 or -1 for the direction of v | `tangent` |
110
- | `joints` | 4 joint indices, for skinned meshes | `skinIndex` |
111
- | `weights` | 4: how much each joint moves the vertex, which add up to 1 | `skinWeight` |
112
- | `targets` | 4: the position that the vertex takes at a coarser level of detail, and that level's error, which a generated shape's material reads | None |
108
+ | Array | Numbers per vertex |
109
+ | --- | --- |
110
+ | `positions` | 3 |
111
+ | `normals` | 3 |
112
+ | `uvs` | 2 |
113
+ | `uvs1` | 2, such as a light map's coordinates |
114
+ | `colors` | 3, or 4 with alpha, as linear values from 0 to 1 |
115
+ | `tangents` | 4: the direction in which u grows, then 1 or -1 for the direction of v |
116
+ | `joints` | 4 joint indices, for skinned meshes |
117
+ | `weights` | 4: how much each joint moves the vertex, which add up to 1 |
118
+ | `targets` | 4 numbers that a custom material's vertex offset reads, such as the position that the vertex takes at the next coarser level and that level's error |
113
119
 
114
120
  The arrays follow these rules:
115
121
 
116
122
  - `positions` is required. Give `normals`, or set `computeNormals: true`.
117
123
  - `indices` takes a `Uint16Array`, a `Uint32Array` or an array of numbers, with three indices per triangle. Without indices, each three vertices in a row make one triangle.
118
- - `joints` and `weights` come together. A mesh keeps them for [skinning](animation.md#skinned-meshes). No call skins a mesh that you build yet, so it draws in the pose that its positions give.
124
+ - `joints` and `weights` come together. A mesh keeps them for [skinning](animation.md#skinned-meshes). A mesh that you build draws in the pose that its positions give.
119
125
  - `targets` takes floats only, and a mesh takes it or `morphTargets`, never both: the two share one vertex record.
126
+ - `targets` is for a shape whose material moves its vertices between levels of detail, as the [terrain](terrain.md#how-it-works) does. The material's vertex offset reads the four numbers as `input.vertexRecord` ([Vertex offsets](../shaders/surface-functions.md#vertex-offsets)). Leave it out unless your vertex offset reads it.
120
127
  - A triangle's front face has its vertices in counter-clockwise order.
121
128
  - Each array's length must fit the vertex count, and its type must be one that its attribute takes. Each index must name a vertex, and each value must be a finite number. Otherwise the call throws [E1206](../errors/E1206.md).
122
129
  - The engine copies the arrays. You can change or drop them after the call.
@@ -125,7 +132,7 @@ The arrays follow these rules:
125
132
 
126
133
  Each attribute can come as 8-bit or 16-bit integers instead of 32-bit floats, as glTF's `KHR_mesh_quantization` extension allows. The mesh keeps the integers on the GPU, so it takes less memory and uploads faster. A position of 16-bit integers takes 8 bytes, where floats take 12. A normal of 8-bit integers takes 4 bytes, where floats take 12.
127
134
 
128
- Integers read in one of two ways. Normalized integers read as fractions: from 0 to 1 when they are unsigned, and from -1 to 1 when they are signed. Plain integers read as whole numbers. Give an attribute as `{ array, normalized }` to choose, as three.js's `BufferAttribute` does. The default is plain, as in three.js and glTF.
135
+ Integers read in one of two ways. Normalized integers read as fractions: from 0 to 1 when they are unsigned, and from -1 to 1 when they are signed. Plain integers read as whole numbers. Give an attribute as `{ array, normalized }` to choose. The default is plain, as in glTF.
129
136
 
130
137
  | Array | Takes | Integers read as |
131
138
  | --- | --- | --- |
@@ -152,13 +159,19 @@ Integer positions keep their own units. Give the object the scale and the positi
152
159
 
153
160
  ## Computing normals and tangents
154
161
 
155
- `computeNormals: true` computes the normals as three.js's `computeVertexNormals` does. Each vertex gets the average of the normals of its triangles, weighted by their areas. Vertices that triangles share get smooth normals. For hard edges, give each face its own vertices. The [meshes from arrays demo](https://github.com/null3d-engine/null3d/tree/main/examples/mesh-arrays) shows both: a smooth height field, an island with a color at each vertex, and a crystal with hard edges.
162
+ `computeNormals: true` computes the normals from the triangles. Each vertex gets the average of the normals of its triangles, weighted by their areas. Vertices that triangles share get smooth normals. For hard edges, give each face its own vertices. The [meshes from arrays demo](https://github.com/null3d-engine/null3d/tree/main/examples/mesh-arrays) shows both: a smooth height field, an island with a color at each vertex, and a crystal with hard edges.
156
163
 
157
- `computeTangents: true` computes tangents as three.js's `computeTangents` does, from the positions, the normals and `uvs`. It needs `uvs`, and it works with or without indices. The job workers share the work, so a large mesh takes less time. Both options give the same numbers as three.js, bit for bit. They compute from integer positions, normals and texture coordinates too, as shaders read them, and give 32-bit floats.
164
+ ![An island with smooth normals and vertex colors beside a hard-edged crystal.](../images/api/geometry/mesh-arrays.webp)
165
+
166
+ Meshes from arrays.
167
+
168
+ `computeTangents: true` computes tangents from the positions, the normals and `uvs`, with Eric Lengyel's method. It needs `uvs`, and it works with or without indices. The job workers share the work, so a large mesh takes less time. Both options compute from integer positions, normals and texture coordinates too, as shaders read them, and give 32-bit floats.
158
169
 
159
170
  ## Morph targets
160
171
 
161
- A morph target is another shape of a mesh, such as a smile on a face. The `morphTargets` option gives a mesh its targets, as three.js's `morphAttributes` with `morphTargetsRelative` does. Each target is an array of three numbers per vertex: how far the target moves the vertex at weight 1. The list `positions` moves the vertices, `normals` turns their normals, and `tangents` turns their tangents. The list `colors` changes the mesh's vertex colors, with as many numbers per vertex as `colors` has, three or four. Every list holds the same number of targets, from 1 to 256. The list `names` names the targets.
172
+ A morph target is another shape of a mesh, such as a smile on a face. The `morphTargets` option gives a mesh its targets, as glTF stores them. Each target is an array of three numbers per vertex: how far the target moves the vertex at weight 1. The list `positions` moves the vertices, `normals` turns their normals, and `tangents` turns their tangents.
173
+
174
+ The list `colors` changes the mesh's vertex colors, with as many numbers per vertex as `colors` has, three or four. Every list holds the same number of targets, from 1 to 256. The list `names` names the targets.
162
175
 
163
176
  ```ts
164
177
  const count = positions.length / 3;
@@ -175,11 +188,26 @@ const head = scene.createMesh({ mesh: face, material });
175
188
  head.setMorphWeight('Smile', 0.8);
176
189
  ```
177
190
 
178
- Each object of the mesh has weights of its own, which start at 0. `setMorphWeight` sets them, and clips from glTF files animate them ([Morph targets](animation.md#morph-targets)). The [morph targets demo](https://github.com/null3d-engine/null3d/tree/main/examples/morph-flowers) makes tulips with one target, which opens the petals, turns their normals and changes their color. Each tulip has a weight of its own. The engine stores, for each vertex, only the targets that move it. So a face whose targets each move a small part of it takes far less memory than three.js's copy of every vertex for every target. A vertex can take up to 255 targets. The targets of every mesh together can take up to 4,194,304 deltas, 32 MiB of GPU memory. Each of a vertex's positions, normals, tangents and colors counts once. Past those limits, `fromArrays` throws E1206. The GPU keeps each delta in a 16-bit float, which is exact to 1/2048 of the delta's size, and each weight in a 32-bit float. A morphed color stays between 0 and 1, as the glTF specification asks. three.js does not clamp it, so a color that the weights push past 1 or below 0 draws brighter or darker there.
191
+ Each object of the mesh has weights of its own, which start at 0. `setMorphWeight` sets them, and clips from glTF files animate them ([Morph targets](animation.md#morph-targets)). The [morph targets demo](https://github.com/null3d-engine/null3d/tree/main/examples/morph-flowers) makes tulips with one target, which opens the petals, turns their normals and changes their color. Each tulip has a weight of its own.
192
+
193
+ The targets of a mesh have size limits. Past them, `fromArrays` throws [E1206](../errors/E1206.md).
194
+
195
+ <details>
196
+ <summary>Technical details: how morph targets are stored</summary>
197
+
198
+ The engine stores, for each vertex, only the targets that move it. So a face whose targets each move a small part of it takes far less memory than a copy of every vertex for every target. A vertex can take up to 255 targets.
199
+
200
+ The targets of every mesh together can take up to 4,194,304 deltas, 32 MiB of GPU memory. Each of a vertex's positions, normals, tangents and colors counts once. The GPU keeps each delta in a 16-bit float, which is exact to 1/2048 of the delta's size, and each weight in a 32-bit float. A morphed color stays between 0 and 1, as the glTF specification asks.
201
+
202
+ </details>
179
203
 
180
204
  ## Vertices that change
181
205
 
182
- `mesh.updateVertices(name, values, start, count)` writes new values into one attribute of a mesh, as three.js's `attribute.needsUpdate = true` does. Keep the arrays that you made the mesh with, change them, and pass them again:
206
+ `mesh.updateVertices(name, values, start, count)` writes new values into one attribute of a mesh. Keep the arrays that you made the mesh with, change them, and pass them again:
207
+
208
+ ![Rings spread over a pool from a glowing float.](../images/api/geometry/vertex-updates.webp)
209
+
210
+ updateVertices every frame.
183
211
 
184
212
  ```ts
185
213
  // sketch.ts: a sheet whose middle rows rise and fall
@@ -198,14 +226,16 @@ The call follows these rules:
198
226
 
199
227
  - `name` is `positions`, `normals`, `uvs`, `uvs1`, `colors` or `tangents`, and the mesh must have that attribute. Colors take three or four numbers per vertex. Three keep each vertex's alpha.
200
228
  - `values` holds the values of every vertex, in the array type that the mesh was made with. That is a `Float32Array` or a plain array for floats, or the same integer array.
201
- - `start` and `count` pick the vertices that change, as three.js's `addUpdateRange` does. By default every vertex changes. The next frame uploads only the bytes of those vertices.
229
+ - `start` and `count` pick the vertices that change. By default every vertex changes. The next frame uploads only the bytes of those vertices.
202
230
  - Values that do not fit the mesh throw [E1206](../errors/E1206.md), and so does a mesh with joints or morph targets.
203
231
  - The first call takes away the levels of detail that the mesh planned, which measured the old shape, and the mesh plans no levels on its own again. Give a mesh whose vertices change in every frame `levels: false`, so it plans none.
204
- - The call allocates nothing, so a call in every frame makes no garbage. `bun run bench:allocation --calls` checks it.
232
+ - The call allocates nothing, so a call in every frame makes no garbage. The engine's allocation benchmark checks it in every frame.
205
233
 
206
234
  Change the normals with the positions when the shape changes, because the engine does not compute them again. The [vertex updates demo](https://github.com/null3d-engine/null3d/tree/main/examples/vertex-updates) moves rings over a pool of water this way.
207
235
 
208
- The mesh keeps the bounding sphere of the vertices that it was made with, as three.js keeps a geometry's `boundingSphere` until you compute it again. Culling tests that sphere. When the new vertices reach outside it, give each object that draws the mesh bounds that hold every shape, with [`setBounds`](objects.md#mesh-calls). Raycasts and overlap queries always test the new vertices. The first query after an update builds the mesh's tree again. So a scene that updates a large mesh and raycasts in each frame pays for a build in each frame. Shadows of point and spot lights draw again when a mesh that casts them changes.
236
+ The mesh keeps the bounding sphere of the vertices that it was made with. Culling tests that sphere. When the new vertices reach outside it, give each object that draws the mesh bounds that hold every shape, with [`setBounds`](objects.md#mesh-calls). Raycasts and overlap queries always test the new vertices.
237
+
238
+ The first query after an update builds the mesh's tree again. So a scene that updates a large mesh and raycasts in each frame pays for a build in each frame. Shadows of point and spot lights draw again when a mesh that casts them changes.
209
239
 
210
240
  The first update of a mesh rebuilds the draw tables once, as `setMesh` does, so make it at setup or behind a loading screen. Later updates cost only the copy and the upload. On WebGL2, a mesh whose positions changed no longer hides the objects behind it from software occlusion culling. For many objects that move as wholes, use [instance batches](../concepts/instances.md) instead: they move each object with one matrix, not each vertex.
211
241
 
@@ -225,7 +255,9 @@ Meshes of one vertex format share GPU buffers, so the engine draws them with few
225
255
 
226
256
  ## Levels of detail
227
257
 
228
- A mesh made in code plans its own levels of detail the first time the scene draws it, when it holds 4,096 triangles or more, or when its copies hold 65,536 triangles together and it holds at least 256, as a batch of pebbles does. Meshes from `geometry.fromArrays` and from the generators both plan. The plan runs on the job workers, never in a frame. It uses the planner of the asset tool's `--lod`, with the same simplifier, so a mesh made in code gets the levels that the same mesh in a file gets. The mesh draws its full shape until the levels arrive, a few frames later. Then every object and instance batch that draws it picks its level:
258
+ A mesh made in code plans its own levels of detail the first time the scene draws it, when it holds 4,096 triangles or more, or when its copies hold 65,536 triangles together and it holds at least 256, as a batch of pebbles does. Meshes from `geometry.fromArrays` and from the generators both plan. The plan runs on the job workers, never in a frame.
259
+
260
+ It uses the planner of the asset tool's `--lod`, with the same simplifier, so a mesh made in code gets the levels that the same mesh in a file gets. The mesh draws its full shape until the levels arrive, a few frames later. Then every object and instance batch that draws it picks its level:
229
261
 
230
262
  ```ts
231
263
  // 32,768 triangles: the first draw plans about six levels, down to a few hundred triangles.
@@ -235,9 +267,33 @@ scene.createInstances(ground, 400, { material: grass });
235
267
  const levels = await ground.buildLevels();
236
268
  ```
237
269
 
238
- Each level about halves the triangles of the level above and keeps the largest distance between its surface and the mesh's as its error. So it switches in at once, with no fade, while that distance covers less than the `lodThreshold` setting's pixels. The governor can raise that threshold past about one and a half pixels, where the switch shows, and the level then fades. A preset's own threshold never makes it fade. The levels name the mesh's own vertices: a level costs its indices alone, and the mesh keeps its vertices and triangles in their order. A mesh of more than 65,535 vertices, which the engine splits into parts, shares its vertices part by part. Only the few triangles that cross from one part to another copy their vertices. A plan of 130,000 triangles takes about half a second of one job worker, and a plan of a million about six seconds; the frames go on meanwhile. A large mesh spreads its work over frames, so no frame waits for it. The engine reads one part of the mesh in each frame for the plan. It makes one level in each frame when the plan is done. It gives the scene the whole set once, so its draw tables rebuild once. The planner, about 23 KB after Brotli, downloads with the first mesh that plans.
270
+ Each level about halves the triangles of the level above and keeps the largest distance between its surface and the mesh's as its error. So it switches in at once, with no fade, while that distance covers less than the `lodThreshold` setting's pixels. The governor can raise that threshold past about one and a half pixels, where the switch shows, and the level then fades. A preset's own threshold never makes it fade.
271
+
272
+ A level costs only its indices. The plan runs on the job workers, and the frames go on meanwhile.
273
+
274
+ <details>
275
+ <summary>Technical details: how the planner works</summary>
276
+
277
+ The levels name the mesh's own vertices: the mesh keeps its vertices and triangles in their order, and a level costs its indices alone. A mesh of more than 65,535 vertices, which the engine splits into parts, shares its vertices part by part. Only the few triangles that cross from one part to another copy their vertices.
278
+
279
+ A plan of 130,000 triangles takes about half a second of one job worker, and a plan of a million about six seconds. A large mesh spreads its work over frames, so no frame waits for it.
280
+
281
+ The engine reads one part of the mesh in each frame for the plan. It makes one level in each frame when the plan is done. It gives the scene the whole set once, so its draw tables rebuild once. The planner, about 23 KB after Brotli, downloads with the first mesh that plans.
282
+
283
+ </details>
284
+
285
+ The plan also sorts large levels into pieces, so each copy skips the pieces that lie outside the view or face away from the camera. [Pieces of a large level](../concepts/lod.md#pieces-of-a-large-level) gives the rules.
286
+
287
+ <details>
288
+ <summary>Technical details: how the planner builds and splits levels</summary>
239
289
 
240
- The plan also sorts the mesh and each level of 32,768 triangles or more into 8 to 16 pieces, and each copy skips the pieces that lie outside the view or face away from the camera ([Pieces of a large level](../concepts/lod.md#pieces-of-a-large-level)). A mesh that one object draws gets pieces of its own too, over a sorted copy of its indices that arrives in the frame after the last level, so the mesh keeps its triangles in their order. Copies of a large mesh draw their full mesh only near the camera, so only their levels get pieces. A list that faces mostly one way, such as a ground, splits by space. A smaller list of 1,024 triangles or more that many copies draw gets facing pieces where its triangles face a few ways. A building's walls are such a list: they get one piece for each way, and one for the rest. A mesh whose levels are set by hand plans such pieces of its own list too. They draw only once the scene's copies of the mesh hold 65,536 triangles together.
290
+ The plan sorts the mesh and each level of 32,768 triangles or more into 8 to 16 pieces. A mesh that one object draws gets pieces of its own too, over a sorted copy of its indices that arrives in the frame after the last level, so the mesh keeps its triangles in their order. Copies of a large mesh draw their full mesh only near the camera, so only their levels get pieces.
291
+
292
+ A list that faces mostly one way, such as a ground, splits by space. A smaller list of 1,024 triangles or more that many copies draw gets facing pieces where its triangles face a few ways. A building's walls are such a list: they get one piece for each way, and one for the rest.
293
+
294
+ A mesh whose levels are set by hand plans such pieces of its own list too. They draw only once the scene's copies of the mesh hold 65,536 triangles together.
295
+
296
+ </details>
241
297
 
242
298
  The `levels` option of `fromArrays` and of every generator controls the plan:
243
299
 
@@ -274,9 +330,20 @@ rock.setLevels([
274
330
  ]);
275
331
  ```
276
332
 
277
- An `error` level draws while it covers fewer pixels than the `lodThreshold` quality setting. A `distance` level draws while the camera lies farther than that distance. A `coverage` level draws while the bounds cover less than that share of the render's height. A level given by a distance, by a coverage or by a hand-set error fades over a short band. A level with a measured error switches at once, and fades once the governor raises the threshold above about one and a half pixels. A glTF file marks a measured error with the screen coverage that the asset tool writes beside it. An error alone is hand-set, and it fades. `setLevels(levels, { fade: false })` switches every level at once while the threshold stays small.
333
+ An `error` level draws while it covers fewer pixels than the `lodThreshold` quality setting. A `distance` level draws while the camera lies farther than that distance. A `coverage` level draws while the bounds cover less than that share of the render's height. A level given by a distance, by a coverage or by a hand-set error fades over a short band.
334
+
335
+ A level with a measured error switches at once, and fades once the governor raises the threshold above about one and a half pixels. A glTF file marks a measured error with the screen coverage that the asset tool writes beside it. An error alone is hand-set, and it fades. `setLevels(levels, { fade: false })` switches every level at once while the threshold stays small.
336
+
337
+ Each level must have the mesh's vertex attributes, as it draws with the same pipelines. A level may name a `material` of its own, so a far level shades more cheaply. A level without one draws with the material of the level before it. The base level draws with the object's or the instance batch's material.
278
338
 
279
- Each level must have the mesh's vertex attributes, as it draws with the same pipelines. A level may name a `material` of its own, so a far level shades more cheaply. A level without one draws with the material of the level before it. The base level draws with the object's or the instance batch's material. An empty list takes the levels away, and destroying a level's mesh takes every level away. `mesh.levels` lists them as you gave them. A mesh whose bound covers fewer pixels than the threshold draws nothing: its last level holds no geometry. Wrong levels throw [E1221](../errors/E1221.md). [Levels of detail](../concepts/lod.md) explains the three measures, the hide distance, the fading bands and the shadows. It also explains how glTF files from the asset tool bring their levels.
339
+ An empty list takes the levels away, and destroying a level's mesh takes every level away. `mesh.levels` lists them as you gave them. A mesh whose bound covers fewer pixels than the threshold draws nothing: its last level holds no geometry. Wrong levels throw [E1221](../errors/E1221.md).
340
+
341
+ [Levels of detail](../concepts/lod.md) explains the three measures, the hide distance, the fading bands and the shadows. It also explains how glTF files from the asset tool bring their levels. The [forest demo](https://github.com/null3d-engine/null3d/tree/main/examples/forest) calls `setLevels` on each tree mesh, with measured errors.
342
+
343
+ A far object that draws as a card follows its own rules. A card that lights unlike its mesh reads as
344
+ another tree. [Impostors](impostors.md#make-a-card-read-as-its-mesh) says which mesh to bake, the
345
+ color space, the views and texels, the normal bake, and the matched-crop check before a card is
346
+ accepted.
280
347
 
281
348
  ## Destroying a mesh
282
349
 
@@ -295,31 +362,14 @@ While an object or an instance batch still uses the mesh, `destroy` throws [E111
295
362
 
296
363
  ## Large meshes
297
364
 
298
- A mesh can have any number of vertices. The engine uses 16-bit indices. WebGL2 always reads the largest one, 65,535, as the end of a primitive, so one draw reaches 65,535 vertices. A mesh with more vertices splits into parts that draw one after another. Each part holds a copy of the vertices that it shares with the part before it. For the fewest draw calls, keep meshes under 65,535 vertices. A mesh that draws a cluster tree is the exception. Its patches draw in one draw across all its parts, as [cluster levels](../concepts/lod.md#cluster-levels) describes.
365
+ A mesh can have any number of vertices. A mesh of more than 65,535 vertices splits into parts that draw one after another. For the fewest draw calls, keep meshes under 65,535 vertices. A mesh that draws a cluster tree is the exception. Its patches draw in one draw across all its parts, as [cluster levels](../concepts/lod.md#cluster-levels) describes.
299
366
 
300
- ## From three.js
367
+ <details>
368
+ <summary>Technical details: why large meshes split</summary>
301
369
 
302
- | three.js | null3D |
303
- | --- | --- |
304
- | `new BoxGeometry(1, 2, 3)`, and the other eight classes above | `geometry.box({ width: 1, height: 2, depth: 3 })`: the arguments become named options |
305
- | `rotateX`, `translate` or `scale` on a generated shape, such as a plane laid flat | Turn, move or scale the object instead: `floor.setRotationEuler(-Math.PI / 2, 0, 0)` |
306
- | `new BufferGeometry()` with `setAttribute` and `setIndex` | `geometry.fromArrays({ positions, normals, uvs, indices })` |
307
- | `new BufferAttribute(new Int16Array(values), 3, true)` | `{ array: new Int16Array(values), normalized: true }` |
308
- | `geometry.computeVertexNormals()` | `computeNormals: true` |
309
- | `geometry.computeTangents()` | `computeTangents: true` |
310
- | `geometry.computeBoundingSphere()` | Nothing: the engine computes bounds itself |
311
- | `geometry.morphAttributes.position = [...]` with `morphTargetsRelative = true` | `morphTargets: { positions: [...] }` |
312
- | `geometry.morphAttributes.color = [...]` | `morphTargets: { colors: [...] }`, with `colors` on the mesh |
313
- | `mesh.morphTargetDictionary` | The mesh geometry's `morphTargetNames`, a list in target order; `setMorphWeight` takes a name too |
314
- | `geometry.dispose()` | `mesh.destroy()`, once no object or batch uses the mesh |
315
- | `lod.addLevel(object, distance)` | `mesh.setLevels([{ mesh, distance }])` on the base mesh ([Levels of detail](../concepts/lod.md#from-threejs)) |
316
- | `SimplifyModifier.modify(geometry, count)` from three/addons, for a far copy | Nothing: a mesh of 4,096 triangles or more plans its levels on the job workers when it first draws. `mesh.buildLevels()` plans a smaller one |
317
- | `new TorusKnotGeometry(1, 0.4)`, and `Icosahedron`, `Lathe`, `Shape`, `Extrude`, `Tube` and the other geometry classes | `geometry.fromArrays(torusKnot({ radius: 1, tube: 0.4 }))`, with the functions of `@null3d/geometry` |
318
- | `new THREE.Shape()`, `new THREE.CatmullRomCurve3(points)` | The same classes from `@null3d/geometry`, with points as arrays: `new CatmullRomCurve3([[0, 0, 0], [1, 1, 0]])` |
319
- | `attribute.needsUpdate = true`, `setUsage(DynamicDrawUsage)` | `mesh.updateVertices('positions', positions)`. There is no usage hint |
320
- | `attribute.addUpdateRange(start, count)` | `mesh.updateVertices(name, values, startVertex, vertexCount)`, in vertices rather than numbers |
321
-
322
- [three.js to null3D](../porting/threejs-mapping.md) lists every mapping.
370
+ The engine uses 16-bit indices, and WebGL2 always reads the largest one, 65,535, as the end of a primitive, so one draw reaches 65,535 vertices. Each part holds a copy of the vertices that it shares with the part before it.
371
+
372
+ </details>
323
373
 
324
374
  ## API reference
325
375
 
package/docs/api/grass.md CHANGED
@@ -1,22 +1,18 @@
1
1
  ---
2
2
  id: api/grass
3
3
  title: "Grass (@null3d/grass)"
4
- status: experimental
5
- since: "0.3"
6
- summary: "createGrass: tufts of bent blades over a ground, placed by integer hashes, built in a compute pass on WebGPU with near shadows, swaying in the wind add-on's field, with a share for each quality preset."
4
+ summary: "createGrass: tufts of bent blades over a ground, placed by integer hashes, built in a compute pass on WebGPU with the sun's shadows, swaying in the wind add-on's field, with a share for each quality preset."
7
5
  ---
8
6
 
9
7
  # Grass (@null3d/grass)
10
8
 
11
- > Roadmap step 0.3, first released in null3D 0.1.0. The API is experimental, so it can still change between versions.
12
-
13
9
  ```mermaid
14
10
  flowchart LR
15
11
  ground["The ground's height,<br/>a mask, a seed"] --> place["Tufts placed<br/>by integer hash"]
16
12
  place --> gpu["WebGPU: a compute pass<br/>writes the blade list"]
17
13
  place --> batch["WebGL2: one instance<br/>batch for each shape"]
18
14
  camera["The camera"] --> gpu
19
- gpu --> draw["The blades, with<br/>near shadows"]
15
+ gpu --> draw["The blades, with<br/>the sun's shadows"]
20
16
  batch --> draw
21
17
  wind["The wind add-on's field"] --> draw
22
18
  preset["The quality preset"] --> place
@@ -24,6 +20,10 @@ flowchart LR
24
20
 
25
21
  `@null3d/grass` draws tufts of bent blades over a square of ground. One seed places the same tufts on every device, and the blades bend in the air of the wind add-on's field. On WebGPU a compute pass builds the blade list each frame, culls it to the view and thins the far tufts. WebGL2 draws the same rows as an instance batch. The grass casts and receives the sun's shadows on both paths.
26
22
 
23
+ ![A grove of oaks, birches and firs at the edge of a grassy meadow, all swaying in one wind field.](../images/api/grass/grass-grove.webp)
24
+
25
+ The plants in wind demo. On feature-instances: the grass add-on places and counts its blades with a compute pass on WebGPU.
26
+
27
27
  The package is built on the engine's public API. Its two shaders ship compiled, so your build does not compile them. It reads the field of `@null3d/wind`, which it lists as a peer dependency.
28
28
 
29
29
  ```sh
@@ -37,12 +37,19 @@ import { createGrass, swayDistanceFor } from '@null3d/grass';
37
37
  import { createWind } from '@null3d/wind';
38
38
 
39
39
  export default defineSketch(async (ctx) => {
40
- const { scene, quality } = ctx;
40
+ const { scene, quality, geometry, materials } = ctx;
41
41
  const camera = scene.createPerspectiveCamera({ position: [0, 2, 12], target: [0, 0, 0] });
42
42
  scene.setActiveCamera(camera);
43
43
  scene.createDirectionalLight({ direction: [-0.4, -1, -0.3], intensity: 3, castShadows: true });
44
44
 
45
- const height = (x: number, z: number) => 0.4 * Math.sin(x * 0.2) * Math.cos(z * 0.15);
45
+ const height = () => 0;
46
+ scene.setBackground('#8fb3cf');
47
+ scene.createMesh({
48
+ mesh: geometry.plane({ width: 40, height: 40 }),
49
+ material: materials.standard({ color: '#4f6b2a' }),
50
+ rotation: [-Math.SQRT1_2, 0, 0, Math.SQRT1_2],
51
+ receiveShadows: true,
52
+ });
46
53
  const wind = createWind(ctx, { camera, box: 128 });
47
54
  wind.setBase(3, 0.4);
48
55
  const grass = await createGrass(ctx, {
@@ -54,6 +61,10 @@ export default defineSketch(async (ctx) => {
54
61
  camera,
55
62
  swayDistance: swayDistanceFor(quality.preset),
56
63
  });
64
+ quality.onChange(() => {
65
+ grass.fit(quality.preset);
66
+ grass.setSwayDistance(swayDistanceFor(quality.preset));
67
+ });
57
68
 
58
69
  return {
59
70
  onUpdate() {
@@ -66,13 +77,30 @@ export default defineSketch(async (ctx) => {
66
77
 
67
78
  ## Grass on the ground
68
79
 
69
- `await createGrass(ctx, { height, area, count, seed, mask, wind })` draws tufts of bent blades over a square of ground. The tufts stand on `height(x, z)` and skip ground steeper than `maxSlope`. They also skip the ground that `mask` refuses, such as water, a stone or a footprint. Their turn and size come from integer hashes, so one seed places the same grass on every device. Each tuft's tint comes from a hash of its root's place in the shader. `count` is the tufts at the High preset. Low, Medium and Ultra draw 0.35, 0.6 and 1.25 of it. `createGrass` fits the engine's starting preset, and `grass.fit(preset)` takes a new one. Await the call in the sketch's setup, because WebGPU makes its draw then.
80
+ `await createGrass(ctx, options)` draws tufts of bent blades over a square of ground. Await the call in the sketch's setup, because WebGPU makes its draw then. The [`GrassOptions` table](reference/grass.md#grassoptions) lists every option with its default.
81
+
82
+ ![The same hill of grass at the Low, High and Ultra presets.](../images/api/grass/grass-presets.webp)
83
+
84
+ Grass counts follow the preset.
85
+
86
+ The tufts stand on `height(x, z)` and skip ground steeper than `maxSlope`. They also skip ground that `mask` refuses, such as water or a footprint, and ground that `where` refuses, such as a road. A tuft grows only where both allow it.
87
+
88
+ `count` is the tufts at the High preset. Low, Medium and Ultra draw 0.35, 0.6 and 1.25 of it. `createGrass` fits the engine's starting preset, and `grass.fit(preset)` takes a new one.
89
+
90
+ <details>
91
+ <summary>Technical details: how the tufts are placed</summary>
92
+
93
+ Each tuft's turn and size come from integer hashes, so one seed places the same grass on every device. Each tuft's tint comes from a hash of its root's place, in the shader.
94
+
95
+ </details>
70
96
 
71
97
  The blades bend in the wind add-on's field. Give `createGrass` its `wind` field, and call `grass.setWindLayer(field)` in each frame with the field's newest state. A page that gives no field grows grass that stands still.
72
98
 
73
99
  ## The blade shape
74
100
 
75
- Without a shape, each blade narrows to a point from its root. The `blade` option gives every blade one shape. Its `widthAt(t)` is the blade's width in meters at a share `t` of its length, from 0 at the root to 1 at the tip. Its `fold` is the degrees that each half rises from the keel. A blade with a fold draws a vertex at its keel, so its two halves light apart. Give a plant's own blade with the plant's own `color`, so the cover reads as the same grass where the plant stands.
101
+ Without a shape, each blade narrows to a point from its root. The `blade` option gives every blade one shape. Its `widthAt(t)` is the blade's width in meters at a share `t` of its length, from 0 at the root to 1 at the tip. Its `fold` is the degrees that each half rises from the keel.
102
+
103
+ A blade with a fold draws a vertex at its keel, so its two halves light apart. Give a plant's own blade with the plant's own `color`, so the cover reads as the same grass where the plant stands.
76
104
 
77
105
  ```ts
78
106
  const grass = await createGrass(ctx, {
@@ -89,15 +117,25 @@ const grass = await createGrass(ctx, {
89
117
 
90
118
  On WebGPU and compatibility mode a compute pass builds the blade list. It writes each tuft's row and the count into a draw that the frame culls no further. The engine copies the count into the main view and every drawn shadow view.
91
119
 
92
- Give the pass the drawing `camera`, and it culls the tiles outside the view and thins the far tufts. A far tuft draws the share that its root's hash picks. Its blades widen by the inverse of that share, so the hill's cover stays the same. The draw shader then culls each view to its own box, from that view's matrix. The camera's view draws its frustum. A light's view draws its cascade, whose box reaches toward the light over the casters. So a shadow view does not draw the whole kept list.
120
+ Give the pass the drawing `camera`, and it culls the tiles outside the view and thins the far tufts. A far tuft draws the share that its root's hash picks. Its blades widen by the inverse of that share, so the hill's cover stays the same.
121
+
122
+ The draw shader then culls each view to its own box, from that view's matrix. The camera's view draws its frustum. A light's view draws its cascade, whose box reaches toward the light over the casters. So a shadow view does not draw the whole kept list.
93
123
 
94
124
  WebGL2 fills one instance batch for each tuft shape on the CPU. Its vertex shader applies the same share and the same per-view cull, so both paths draw the same hill. The rows are built for Ultra's share once. A preset change then changes only how many rows draw, not the memory. A page that drives the rows itself gives `compute: false`, which keeps the instance batch on both paths.
95
125
 
96
126
  The tuft meshes plan no levels of detail: the wind bends their blades in the shader, and the tufts thin with distance by themselves.
97
127
 
98
- ## Near shadows and the sway distance
128
+ ## Shadows and the sway distance
129
+
130
+ The grass casts and receives the sun's shadows on both paths. Far shadow cascades draw only every few frames, unless a moving caster touches them. Swaying blades count as moving, so by default the far cascades draw in every frame ([Shadows](../concepts/shadows.md#update-rates)).
131
+
132
+ ![Long blade shadows on a hill under a low sun.](../images/api/grass/grass-shadow.webp)
133
+
134
+ Near grass shadows.
135
+
136
+ Give the grass a `swayDistance` to stop the blades past that distance. Then a far cascade that only the grass reaches keeps its turns. The default, 0, sways at every distance. Call `grass.setSwayDistance(distance)` when the preset changes.
99
137
 
100
- The grass casts and receives the sun's shadows on both paths. Give it a `swayDistance` to stop the blades past that distance. A far cascade that only the grass reaches then keeps its cached layer. Call `grass.setSwayDistance(distance)` when the preset changes. `swayDistanceFor(preset)` gives each preset's distance from `PLANT_SWAY_DISTANCE`: 8, 16, 24 and 32 meters from Low to Ultra. Give a swaying plant's material the same distance, so plants and grass stop at one line. The ground's own color and the blades' root colors should meet at the hill's foot.
138
+ `swayDistanceFor(preset)` gives each preset's distance from `PLANT_SWAY_DISTANCE`: 8, 16, 24 and 32 meters from Low to Ultra. Give a swaying plant's material the same distance, so plants and grass stop at one line. The ground's own color and the blades' root colors should meet at the hill's foot.
101
139
 
102
140
  ## The placement hash
103
141
 
@@ -111,4 +149,8 @@ The grass casts and receives the sun's shadows on both paths. Give it a `swayDis
111
149
 
112
150
  - [Wind](wind.md): the field of air that the blades bend in.
113
151
  - [Add-on instance draws](feature-instances.md): the draw whose count the blade list writes.
152
+ - [Shadows](../concepts/shadows.md#update-rates): how the far cascades keep their layers.
114
153
  - [Quality API](quality.md): the preset and the frame-budget governor.
154
+ - [Grass in the wind](https://github.com/null3d-engine/null3d/tree/main/examples/vegetation-wind): a grove whose grass and plants sway in the wind field.
155
+ - [Grass in a scene](https://github.com/null3d-engine/null3d/tree/main/examples/contact-shadows): tufts of grass that cast contact shadows in a stone garden.
156
+ - [Grass at scale](https://github.com/null3d-engine/null3d/tree/main/examples/showcase/island): the island sets `compute: false`, so its grass draws as an instance batch on both paths.