wallhammer-web 0.0.0-stage → 0.4.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 (408) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -2
  3. package/dist/base/data.d.ts +67 -0
  4. package/dist/base/data.js +10 -0
  5. package/dist/base/destructible.d.ts +167 -0
  6. package/dist/base/destructible.js +47 -0
  7. package/dist/base/env-slot.d.ts +101 -0
  8. package/dist/base/env-slot.js +8 -0
  9. package/dist/base/frames.d.ts +138 -0
  10. package/dist/base/frames.js +459 -0
  11. package/dist/base/index.d.ts +21 -0
  12. package/dist/base/index.js +11 -0
  13. package/dist/base/mat34.d.ts +46 -0
  14. package/dist/base/mat34.js +173 -0
  15. package/dist/base/material.d.ts +87 -0
  16. package/dist/base/material.js +6 -0
  17. package/dist/base/math.d.ts +27 -0
  18. package/dist/base/math.js +60 -0
  19. package/dist/base/progress.d.ts +38 -0
  20. package/dist/base/progress.js +81 -0
  21. package/dist/base/rig.d.ts +177 -0
  22. package/dist/base/rig.js +97 -0
  23. package/dist/base/trig.d.ts +29 -0
  24. package/dist/base/trig.js +169 -0
  25. package/dist/base/up.d.ts +26 -0
  26. package/dist/base/up.js +40 -0
  27. package/dist/base/view.d.ts +128 -0
  28. package/dist/base/view.js +136 -0
  29. package/dist/camera/camera.d.ts +99 -0
  30. package/dist/camera/camera.js +228 -0
  31. package/dist/camera/follow.d.ts +120 -0
  32. package/dist/camera/follow.js +320 -0
  33. package/dist/camera/free.d.ts +153 -0
  34. package/dist/camera/free.js +359 -0
  35. package/dist/camera/index.d.ts +10 -0
  36. package/dist/camera/index.js +6 -0
  37. package/dist/camera/orbit.d.ts +93 -0
  38. package/dist/camera/orbit.js +261 -0
  39. package/dist/camera/path.d.ts +48 -0
  40. package/dist/camera/path.js +179 -0
  41. package/dist/core/ballistic.d.ts +66 -0
  42. package/dist/core/ballistic.js +104 -0
  43. package/dist/core/bodies.d.ts +77 -0
  44. package/dist/core/bodies.js +125 -0
  45. package/dist/core/clock.d.ts +37 -0
  46. package/dist/core/clock.js +87 -0
  47. package/dist/core/cover-fade.d.ts +14 -0
  48. package/dist/core/cover-fade.js +38 -0
  49. package/dist/core/index.d.ts +13 -0
  50. package/dist/core/index.js +8 -0
  51. package/dist/core/kepler.d.ts +74 -0
  52. package/dist/core/kepler.js +108 -0
  53. package/dist/core/level-fade.d.ts +66 -0
  54. package/dist/core/level-fade.js +123 -0
  55. package/dist/core/palette.d.ts +15 -0
  56. package/dist/core/palette.js +47 -0
  57. package/dist/env/atmosphere.d.ts +129 -0
  58. package/dist/env/atmosphere.js +707 -0
  59. package/dist/env/cloud-field.d.ts +44 -0
  60. package/dist/env/cloud-field.js +111 -0
  61. package/dist/env/environment.d.ts +217 -0
  62. package/dist/env/environment.js +441 -0
  63. package/dist/env/frame-block.d.ts +29 -0
  64. package/dist/env/frame-block.js +152 -0
  65. package/dist/env/glsl.d.ts +35 -0
  66. package/dist/env/glsl.js +246 -0
  67. package/dist/env/index.d.ts +13 -0
  68. package/dist/env/index.js +9 -0
  69. package/dist/env/sky.d.ts +48 -0
  70. package/dist/env/sky.js +227 -0
  71. package/dist/env/sun.d.ts +31 -0
  72. package/dist/env/sun.js +42 -0
  73. package/dist/gen-arch/build.d.ts +17 -0
  74. package/dist/gen-arch/build.js +414 -0
  75. package/dist/gen-arch/damage/damaged.d.ts +44 -0
  76. package/dist/gen-arch/damage/damaged.js +1119 -0
  77. package/dist/gen-arch/damage/fall-material.d.ts +10 -0
  78. package/dist/gen-arch/damage/fall-material.js +47 -0
  79. package/dist/gen-arch/damage/fall.d.ts +78 -0
  80. package/dist/gen-arch/damage/fall.js +797 -0
  81. package/dist/gen-arch/damage/rubble.d.ts +22 -0
  82. package/dist/gen-arch/damage/rubble.js +188 -0
  83. package/dist/gen-arch/index.d.ts +25 -0
  84. package/dist/gen-arch/index.js +16 -0
  85. package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
  86. package/dist/gen-arch/interior/interior-plan.js +615 -0
  87. package/dist/gen-arch/interior/interior.d.ts +97 -0
  88. package/dist/gen-arch/interior/interior.js +966 -0
  89. package/dist/gen-arch/structure/building-shader.d.ts +25 -0
  90. package/dist/gen-arch/structure/building-shader.js +946 -0
  91. package/dist/gen-arch/structure/buildings.d.ts +248 -0
  92. package/dist/gen-arch/structure/buildings.js +294 -0
  93. package/dist/gen-arch/structure/dims.d.ts +77 -0
  94. package/dist/gen-arch/structure/dims.js +39 -0
  95. package/dist/gen-arch/structure/distant.d.ts +62 -0
  96. package/dist/gen-arch/structure/distant.js +316 -0
  97. package/dist/gen-arch/structure/env-slots.d.ts +18 -0
  98. package/dist/gen-arch/structure/env-slots.js +47 -0
  99. package/dist/gen-arch/structure/facade.d.ts +193 -0
  100. package/dist/gen-arch/structure/facade.js +159 -0
  101. package/dist/gen-arch/structure/parts.d.ts +31 -0
  102. package/dist/gen-arch/structure/parts.js +69 -0
  103. package/dist/gen-arch/structure/roof.d.ts +76 -0
  104. package/dist/gen-arch/structure/roof.js +568 -0
  105. package/dist/gen-arch/structure/structure-material.d.ts +23 -0
  106. package/dist/gen-arch/structure/structure-material.js +55 -0
  107. package/dist/gen-arch/structure/writer.d.ts +94 -0
  108. package/dist/gen-arch/structure/writer.js +195 -0
  109. package/dist/gen-core/cell.d.ts +138 -0
  110. package/dist/gen-core/cell.js +150 -0
  111. package/dist/gen-core/cube-sphere.d.ts +57 -0
  112. package/dist/gen-core/cube-sphere.js +159 -0
  113. package/dist/gen-core/field.d.ts +55 -0
  114. package/dist/gen-core/field.js +154 -0
  115. package/dist/gen-core/geometry.d.ts +31 -0
  116. package/dist/gen-core/geometry.js +231 -0
  117. package/dist/gen-core/hash.d.ts +18 -0
  118. package/dist/gen-core/hash.js +58 -0
  119. package/dist/gen-core/height-field.d.ts +33 -0
  120. package/dist/gen-core/height-field.js +137 -0
  121. package/dist/gen-core/index.d.ts +22 -0
  122. package/dist/gen-core/index.js +17 -0
  123. package/dist/gen-core/instance-cells.d.ts +37 -0
  124. package/dist/gen-core/instance-cells.js +72 -0
  125. package/dist/gen-core/near-scatter.d.ts +56 -0
  126. package/dist/gen-core/near-scatter.js +120 -0
  127. package/dist/gen-core/noise.d.ts +23 -0
  128. package/dist/gen-core/noise.js +72 -0
  129. package/dist/gen-core/occupancy.d.ts +21 -0
  130. package/dist/gen-core/occupancy.js +104 -0
  131. package/dist/gen-core/sphere-patch.d.ts +138 -0
  132. package/dist/gen-core/sphere-patch.js +544 -0
  133. package/dist/gen-core/strip-surface.d.ts +34 -0
  134. package/dist/gen-core/strip-surface.js +246 -0
  135. package/dist/gen-core/strip.d.ts +102 -0
  136. package/dist/gen-core/strip.js +817 -0
  137. package/dist/gen-ground/env-slots.d.ts +48 -0
  138. package/dist/gen-ground/env-slots.js +78 -0
  139. package/dist/gen-ground/ground.d.ts +78 -0
  140. package/dist/gen-ground/ground.js +208 -0
  141. package/dist/gen-ground/index.d.ts +9 -0
  142. package/dist/gen-ground/index.js +7 -0
  143. package/dist/gen-ground/markings.d.ts +46 -0
  144. package/dist/gen-ground/markings.js +124 -0
  145. package/dist/gen-ground/materials.d.ts +18 -0
  146. package/dist/gen-ground/materials.js +22 -0
  147. package/dist/gen-ground/terrain-shader.d.ts +5 -0
  148. package/dist/gen-ground/terrain-shader.js +151 -0
  149. package/dist/gen-mesh/bare-shapes.d.ts +194 -0
  150. package/dist/gen-mesh/bare-shapes.js +596 -0
  151. package/dist/gen-mesh/bisect-surface.d.ts +47 -0
  152. package/dist/gen-mesh/bisect-surface.js +261 -0
  153. package/dist/gen-mesh/box.d.ts +18 -0
  154. package/dist/gen-mesh/box.js +2 -0
  155. package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
  156. package/dist/gen-mesh/cell-morph-mesh.js +258 -0
  157. package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
  158. package/dist/gen-mesh/cell-surface-mesh.js +140 -0
  159. package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
  160. package/dist/gen-mesh/chunk-mesh.js +112 -0
  161. package/dist/gen-mesh/drape-mesh.d.ts +36 -0
  162. package/dist/gen-mesh/drape-mesh.js +98 -0
  163. package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
  164. package/dist/gen-mesh/height-field-mesh.js +98 -0
  165. package/dist/gen-mesh/index.d.ts +26 -0
  166. package/dist/gen-mesh/index.js +15 -0
  167. package/dist/gen-mesh/line-mesh.d.ts +25 -0
  168. package/dist/gen-mesh/line-mesh.js +62 -0
  169. package/dist/gen-mesh/mesh-builder.d.ts +115 -0
  170. package/dist/gen-mesh/mesh-builder.js +315 -0
  171. package/dist/gen-mesh/packed-mesh.d.ts +53 -0
  172. package/dist/gen-mesh/packed-mesh.js +205 -0
  173. package/dist/gen-mesh/prism-mesh.d.ts +33 -0
  174. package/dist/gen-mesh/prism-mesh.js +176 -0
  175. package/dist/gen-mesh/rig-mesh.d.ts +9 -0
  176. package/dist/gen-mesh/rig-mesh.js +135 -0
  177. package/dist/gen-mesh/strip-mesh.d.ts +45 -0
  178. package/dist/gen-mesh/strip-mesh.js +258 -0
  179. package/dist/gen-plan/drain.d.ts +58 -0
  180. package/dist/gen-plan/drain.js +270 -0
  181. package/dist/gen-plan/grid.d.ts +37 -0
  182. package/dist/gen-plan/grid.js +182 -0
  183. package/dist/gen-plan/horizon.d.ts +50 -0
  184. package/dist/gen-plan/horizon.js +185 -0
  185. package/dist/gen-plan/index.d.ts +15 -0
  186. package/dist/gen-plan/index.js +13 -0
  187. package/dist/gen-plan/line-tiles.d.ts +35 -0
  188. package/dist/gen-plan/line-tiles.js +190 -0
  189. package/dist/gen-plan/lines.d.ts +31 -0
  190. package/dist/gen-plan/lines.js +183 -0
  191. package/dist/gen-plan/plots.d.ts +40 -0
  192. package/dist/gen-plan/plots.js +282 -0
  193. package/dist/gen-plan/route.d.ts +55 -0
  194. package/dist/gen-plan/route.js +297 -0
  195. package/dist/gen-plan/sites.d.ts +32 -0
  196. package/dist/gen-plan/sites.js +209 -0
  197. package/dist/gen-tex/code-stamp.d.ts +31 -0
  198. package/dist/gen-tex/code-stamp.js +137 -0
  199. package/dist/gen-tex/index.d.ts +7 -0
  200. package/dist/gen-tex/index.js +5 -0
  201. package/dist/gen-tex/light-horizon.d.ts +47 -0
  202. package/dist/gen-tex/light-horizon.js +180 -0
  203. package/dist/gen-tex/textures.d.ts +8 -0
  204. package/dist/gen-tex/textures.js +49 -0
  205. package/dist/gen-tex/value-textures.d.ts +46 -0
  206. package/dist/gen-tex/value-textures.js +102 -0
  207. package/dist/gen-vegetation/env-slots.d.ts +20 -0
  208. package/dist/gen-vegetation/env-slots.js +29 -0
  209. package/dist/gen-vegetation/index.d.ts +8 -0
  210. package/dist/gen-vegetation/index.js +7 -0
  211. package/dist/gen-vegetation/materials.d.ts +7 -0
  212. package/dist/gen-vegetation/materials.js +17 -0
  213. package/dist/gen-vegetation/planting.d.ts +170 -0
  214. package/dist/gen-vegetation/planting.js +363 -0
  215. package/dist/gen-vegetation/tree-shader.d.ts +23 -0
  216. package/dist/gen-vegetation/tree-shader.js +229 -0
  217. package/dist/gen-vegetation/trees.d.ts +59 -0
  218. package/dist/gen-vegetation/trees.js +329 -0
  219. package/dist/gpu/device.d.ts +286 -0
  220. package/dist/gpu/device.js +1157 -0
  221. package/dist/gpu/gl.d.ts +134 -0
  222. package/dist/gpu/gl.js +276 -0
  223. package/dist/gpu/index.d.ts +4 -0
  224. package/dist/gpu/index.js +3 -0
  225. package/dist/index.d.ts +11 -0
  226. package/dist/index.js +13 -0
  227. package/dist/motion/graph.d.ts +244 -0
  228. package/dist/motion/graph.js +739 -0
  229. package/dist/motion/index.d.ts +8 -0
  230. package/dist/motion/index.js +8 -0
  231. package/dist/motion/pose-ops.d.ts +30 -0
  232. package/dist/motion/pose-ops.js +232 -0
  233. package/dist/motion/reach.d.ts +45 -0
  234. package/dist/motion/reach.js +264 -0
  235. package/dist/motion/skeleton.d.ts +49 -0
  236. package/dist/motion/skeleton.js +99 -0
  237. package/dist/platform/byte-store.d.ts +21 -0
  238. package/dist/platform/byte-store.js +137 -0
  239. package/dist/platform/canvas.d.ts +29 -0
  240. package/dist/platform/canvas.js +76 -0
  241. package/dist/platform/context-loss.d.ts +8 -0
  242. package/dist/platform/context-loss.js +17 -0
  243. package/dist/platform/free-input.d.ts +51 -0
  244. package/dist/platform/free-input.js +100 -0
  245. package/dist/platform/index.d.ts +18 -0
  246. package/dist/platform/index.js +10 -0
  247. package/dist/platform/input.d.ts +48 -0
  248. package/dist/platform/input.js +117 -0
  249. package/dist/platform/keys.d.ts +12 -0
  250. package/dist/platform/keys.js +29 -0
  251. package/dist/platform/loop.d.ts +41 -0
  252. package/dist/platform/loop.js +84 -0
  253. package/dist/platform/walk-input.d.ts +74 -0
  254. package/dist/platform/walk-input.js +226 -0
  255. package/dist/platform/worker.d.ts +51 -0
  256. package/dist/platform/worker.js +170 -0
  257. package/dist/render/bone-instances.d.ts +24 -0
  258. package/dist/render/bone-instances.js +74 -0
  259. package/dist/render/cells.d.ts +70 -0
  260. package/dist/render/cells.js +144 -0
  261. package/dist/render/glsl.d.ts +66 -0
  262. package/dist/render/glsl.js +173 -0
  263. package/dist/render/index.d.ts +26 -0
  264. package/dist/render/index.js +16 -0
  265. package/dist/render/instance-sets.d.ts +97 -0
  266. package/dist/render/instance-sets.js +241 -0
  267. package/dist/render/near-instances.d.ts +75 -0
  268. package/dist/render/near-instances.js +219 -0
  269. package/dist/render/particles.d.ts +63 -0
  270. package/dist/render/particles.js +215 -0
  271. package/dist/render/pieces.d.ts +57 -0
  272. package/dist/render/pieces.js +151 -0
  273. package/dist/render/point-lights.d.ts +97 -0
  274. package/dist/render/point-lights.js +243 -0
  275. package/dist/render/renderer.d.ts +447 -0
  276. package/dist/render/renderer.js +1100 -0
  277. package/dist/render/rig.d.ts +74 -0
  278. package/dist/render/rig.js +576 -0
  279. package/dist/render/shadow-areas.d.ts +49 -0
  280. package/dist/render/shadow-areas.js +125 -0
  281. package/dist/render/shadow-glsl.d.ts +12 -0
  282. package/dist/render/shadow-glsl.js +146 -0
  283. package/dist/render/transient.d.ts +61 -0
  284. package/dist/render/transient.js +213 -0
  285. package/dist/render/value-glsl.d.ts +17 -0
  286. package/dist/render/value-glsl.js +208 -0
  287. package/dist/render/value-layers.d.ts +180 -0
  288. package/dist/render/value-layers.js +333 -0
  289. package/dist/runtime/atmosphere.d.ts +37 -0
  290. package/dist/runtime/atmosphere.js +304 -0
  291. package/dist/runtime/cloud-shell.d.ts +29 -0
  292. package/dist/runtime/cloud-shell.js +158 -0
  293. package/dist/runtime/engine.d.ts +155 -0
  294. package/dist/runtime/engine.js +305 -0
  295. package/dist/runtime/environment-link.d.ts +22 -0
  296. package/dist/runtime/environment-link.js +49 -0
  297. package/dist/runtime/index.d.ts +13 -0
  298. package/dist/runtime/index.js +12 -0
  299. package/dist/runtime/precipitation-glsl.d.ts +2 -0
  300. package/dist/runtime/precipitation-glsl.js +70 -0
  301. package/dist/runtime/precipitation.d.ts +11 -0
  302. package/dist/runtime/precipitation.js +78 -0
  303. package/dist/runtime/sky.d.ts +30 -0
  304. package/dist/runtime/sky.js +114 -0
  305. package/dist/runtime/streaming.d.ts +245 -0
  306. package/dist/runtime/streaming.js +602 -0
  307. package/dist/sim/agenda.d.ts +167 -0
  308. package/dist/sim/agenda.js +425 -0
  309. package/dist/sim/bytes.d.ts +34 -0
  310. package/dist/sim/bytes.js +125 -0
  311. package/dist/sim/destruction/apply.d.ts +59 -0
  312. package/dist/sim/destruction/apply.js +243 -0
  313. package/dist/sim/destruction/cell-states.d.ts +54 -0
  314. package/dist/sim/destruction/cell-states.js +198 -0
  315. package/dist/sim/destruction/index.d.ts +11 -0
  316. package/dist/sim/destruction/index.js +10 -0
  317. package/dist/sim/destruction/int-geometry.d.ts +17 -0
  318. package/dist/sim/destruction/int-geometry.js +131 -0
  319. package/dist/sim/destruction/pick.d.ts +13 -0
  320. package/dist/sim/destruction/pick.js +59 -0
  321. package/dist/sim/destruction/rubble.d.ts +8 -0
  322. package/dist/sim/destruction/rubble.js +159 -0
  323. package/dist/sim/destruction/state.d.ts +15 -0
  324. package/dist/sim/destruction/state.js +83 -0
  325. package/dist/sim/destruction/structure.d.ts +30 -0
  326. package/dist/sim/destruction/structure.js +139 -0
  327. package/dist/sim/events.d.ts +37 -0
  328. package/dist/sim/events.js +106 -0
  329. package/dist/sim/fixed.d.ts +21 -0
  330. package/dist/sim/fixed.js +64 -0
  331. package/dist/sim/flow-probe.d.ts +58 -0
  332. package/dist/sim/flow-probe.js +158 -0
  333. package/dist/sim/flow.d.ts +257 -0
  334. package/dist/sim/flow.js +967 -0
  335. package/dist/sim/index.d.ts +28 -0
  336. package/dist/sim/index.js +20 -0
  337. package/dist/sim/interlock.d.ts +47 -0
  338. package/dist/sim/interlock.js +252 -0
  339. package/dist/sim/movers.d.ts +228 -0
  340. package/dist/sim/movers.js +1083 -0
  341. package/dist/sim/nav.d.ts +72 -0
  342. package/dist/sim/nav.js +292 -0
  343. package/dist/sim/paths.d.ts +80 -0
  344. package/dist/sim/paths.js +197 -0
  345. package/dist/sim/regions.d.ts +87 -0
  346. package/dist/sim/regions.js +517 -0
  347. package/dist/sim/simulation.d.ts +114 -0
  348. package/dist/sim/simulation.js +291 -0
  349. package/dist/sim/states.d.ts +23 -0
  350. package/dist/sim/states.js +54 -0
  351. package/dist/sim/table.d.ts +49 -0
  352. package/dist/sim/table.js +126 -0
  353. package/dist/sim/zones.d.ts +11 -0
  354. package/dist/sim/zones.js +196 -0
  355. package/dist/tools/collision-lines.d.ts +12 -0
  356. package/dist/tools/collision-lines.js +50 -0
  357. package/dist/tools/data-view-glsl.d.ts +3 -0
  358. package/dist/tools/data-view-glsl.js +63 -0
  359. package/dist/tools/data-view-layers.d.ts +20 -0
  360. package/dist/tools/data-view-layers.js +60 -0
  361. package/dist/tools/debug-view.d.ts +30 -0
  362. package/dist/tools/debug-view.js +4 -0
  363. package/dist/tools/index.d.ts +10 -0
  364. package/dist/tools/index.js +7 -0
  365. package/dist/tools/mesh-checks.d.ts +67 -0
  366. package/dist/tools/mesh-checks.js +188 -0
  367. package/dist/tools/profile.d.ts +85 -0
  368. package/dist/tools/profile.js +173 -0
  369. package/dist/world/cell-cache.d.ts +32 -0
  370. package/dist/world/cell-cache.js +60 -0
  371. package/dist/world/cell-format.d.ts +25 -0
  372. package/dist/world/cell-format.js +232 -0
  373. package/dist/world/collide.d.ts +192 -0
  374. package/dist/world/collide.js +822 -0
  375. package/dist/world/index.d.ts +16 -0
  376. package/dist/world/index.js +12 -0
  377. package/dist/world/mesh-solids.d.ts +48 -0
  378. package/dist/world/mesh-solids.js +169 -0
  379. package/dist/world/pick.d.ts +34 -0
  380. package/dist/world/pick.js +177 -0
  381. package/dist/world/providers.d.ts +66 -0
  382. package/dist/world/providers.js +83 -0
  383. package/dist/world/sphere.d.ts +69 -0
  384. package/dist/world/sphere.js +271 -0
  385. package/dist/world/streaming.d.ts +288 -0
  386. package/dist/world/streaming.js +801 -0
  387. package/dist/world/walker.d.ts +145 -0
  388. package/dist/world/walker.js +502 -0
  389. package/docs/architecture.md +111 -0
  390. package/docs/cameras.md +302 -0
  391. package/docs/concepts.md +123 -0
  392. package/docs/destruction.md +127 -0
  393. package/docs/frames.md +199 -0
  394. package/docs/generators.md +575 -0
  395. package/docs/getting-started.md +123 -0
  396. package/docs/headless.md +50 -0
  397. package/docs/motion.md +160 -0
  398. package/docs/planet.md +152 -0
  399. package/docs/recipes.md +521 -0
  400. package/docs/reference.md +364 -0
  401. package/docs/rendering.md +823 -0
  402. package/docs/rigs.md +203 -0
  403. package/docs/simulation.md +235 -0
  404. package/docs/streaming.md +590 -0
  405. package/docs/system.md +166 -0
  406. package/docs/tools.md +175 -0
  407. package/docs/walking.md +262 -0
  408. package/package.json +131 -3
@@ -0,0 +1,219 @@
1
+ // Small instances round the viewer, drawn from sets of records (`nearScatter` of gen-core): one instance buffer per
2
+ // kind with a fixed capacity, filled from the sets nearest the eye first.
3
+ //
4
+ // - A set (`put`) is one kind of the records of one square, relative to its anchor, a world point in doubles. The
5
+ // layer keeps the sets it is given and drops none by itself.
6
+ // - `view` rebuilds the buffers only when the eye has moved more than `stepM` since the last rebuild, a set came or
7
+ // went, or a gain changed by more than 0.01. A rebuild takes from every set the prefix of records that can still be
8
+ // seen from the nearest point of its sphere (`nearCount`) and copies it with its positions moved to one anchor of
9
+ // the layer (the eye of the rebuild, in doubles), so numbers on the GPU stay small. A full buffer leaves the rest
10
+ // out and counts it as clipped: the hard ceiling.
11
+ // - The exact fade runs per instance in the vertex shader (`nearKeep` of the true distance to the eye), so a rebuild
12
+ // changes no pixel. The bend in the wind follows two waves fixed to the world: the layer computes the phase of its
13
+ // anchor per wave in doubles and the shader adds the part of the instance.
14
+ // - One draw per kind that has records, colour pass only, no shadow pass. With every gain 0 nothing is drawn or uploaded.
15
+ //
16
+ // The look is the app's: `NEAR_INSTANCE_GLSL` is a vertex include that places a vertex of the unit shape; the app's
17
+ // material lights and colours it.
18
+ import { RAD_PER_TURN } from '../base/trig.js';
19
+ import { NEAR_FADE_GLSL, NEAR_FLOATS, NEAR_LAYOUT, nearCount } from '../gen-core/near-scatter.js';
20
+ import { MeshLayer } from './renderer.js';
21
+ /** Lengths of the two waves of the wind in metres, and their speeds in radians per second. */
22
+ const WAVE_M = [9, 3.5];
23
+ /** Time is wrapped to this many seconds: 1.7 and 2.9 radians per second make whole turns in it. */
24
+ const WRAP_S = 10 * RAD_PER_TURN;
25
+ /** Instances of several kinds round the eye; see the header of this file. */
26
+ export class NearInstanceLayer extends MeshLayer {
27
+ wind = { dir: [1, 0, 0], strength: 0, timeS: 0 };
28
+ stats = { parts: 0, held: 0, drawn: 0, clipped: 0, rebuilds: 0, bytes: 0 };
29
+ device;
30
+ kinds;
31
+ parts = new Map();
32
+ stepM;
33
+ origin;
34
+ dirty = true;
35
+ /** Anchor of the layer: the eye of the last rebuild. */
36
+ anchor = [0, 0, 0];
37
+ eye = [0, 0, 0];
38
+ constructor(device, o) {
39
+ super({ ...o, passes: o.passes ?? ['color'] });
40
+ this.device = device;
41
+ this.stepM = o.stepM ?? 2;
42
+ this.origin = o.origin ?? (() => [0, 0, 0]);
43
+ let bytes = 0;
44
+ this.kinds = o.kinds.map((draw) => {
45
+ const instances = device.createInstances({ layout: NEAR_LAYOUT, data: new Float32Array(draw.maxInstances * NEAR_FLOATS) });
46
+ const mesh = device.createMesh(draw.mesh, this.material.attribs, instances);
47
+ mesh.instances = 0;
48
+ bytes += draw.maxInstances * NEAR_LAYOUT.stride + mesh.bytes;
49
+ return { draw, instances, mesh, scratch: new Float32Array(draw.maxInstances * NEAR_FLOATS), count: 0, gain: -1 };
50
+ });
51
+ this.stats.bytes = bytes;
52
+ }
53
+ static id(key, kind) {
54
+ return `${kind}|${key}`;
55
+ }
56
+ /** Adds, replaces or (with null) removes one kind of one set. */
57
+ put(key, kind, part) {
58
+ const id = NearInstanceLayer.id(key, kind);
59
+ if (part)
60
+ this.parts.set(id, part);
61
+ else if (!this.parts.delete(id))
62
+ return;
63
+ this.dirty = true;
64
+ }
65
+ has(key, kind) {
66
+ return this.parts.has(NearInstanceLayer.id(key, kind));
67
+ }
68
+ /** Once per frame: the eye in world doubles and a gain 0–1 per kind that scales its reach. */
69
+ view(eye, gains) {
70
+ this.eye = [eye[0], eye[1], eye[2]];
71
+ const dx = eye[0] - this.anchor[0];
72
+ const dy = eye[1] - this.anchor[1];
73
+ const dz = eye[2] - this.anchor[2];
74
+ let rebuild = this.dirty || dx * dx + dy * dy + dz * dz > this.stepM * this.stepM;
75
+ for (let k = 0; k < this.kinds.length; k++)
76
+ if (Math.abs((gains[k] ?? 0) - this.kinds[k].gain) > 0.01)
77
+ rebuild = true;
78
+ if (!rebuild)
79
+ return;
80
+ this.dirty = false;
81
+ this.anchor = [eye[0], eye[1], eye[2]];
82
+ this.stats.rebuilds++;
83
+ // Every set by kind, nearest first, ties by key.
84
+ const byKind = this.kinds.map(() => []);
85
+ let held = 0;
86
+ for (const [id, part] of this.parts) {
87
+ const kind = Number(id.slice(0, id.indexOf('|')));
88
+ const list = byKind[kind];
89
+ if (!list)
90
+ continue;
91
+ const ax = part.anchor[0] - eye[0];
92
+ const ay = part.anchor[1] - eye[1];
93
+ const az = part.anchor[2] - eye[2];
94
+ list.push({ id, part, dist: Math.sqrt(ax * ax + ay * ay + az * az) });
95
+ held += part.data.length / NEAR_FLOATS;
96
+ }
97
+ let drawn = 0;
98
+ let clipped = 0;
99
+ for (let k = 0; k < this.kinds.length; k++) {
100
+ const s = this.kinds[k];
101
+ const gain = Math.min(1, Math.max(0, gains[k] ?? 0));
102
+ s.gain = gain;
103
+ let count = 0;
104
+ if (gain > 0) {
105
+ const list = byKind[k].sort((a, b) => a.dist - b.dist || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
106
+ const cap = s.draw.maxInstances;
107
+ for (const { part, dist } of list) {
108
+ const n = nearCount(part.data, 0, part.data.length / NEAR_FLOATS, s.draw.fade, gain, Math.max(0, dist - part.radiusM - this.stepM));
109
+ const take = Math.min(n, cap - count);
110
+ clipped += n - take;
111
+ if (take <= 0)
112
+ continue;
113
+ const ox = part.anchor[0] - eye[0];
114
+ const oy = part.anchor[1] - eye[1];
115
+ const oz = part.anchor[2] - eye[2];
116
+ const out = s.scratch;
117
+ out.set(part.data.subarray(0, take * NEAR_FLOATS), count * NEAR_FLOATS);
118
+ for (let i = 0; i < take; i++) {
119
+ const at = (count + i) * NEAR_FLOATS;
120
+ out[at] = out[at] + ox;
121
+ out[at + 1] = out[at + 1] + oy;
122
+ out[at + 2] = out[at + 2] + oz;
123
+ }
124
+ count += take;
125
+ }
126
+ }
127
+ if (count > 0)
128
+ this.device.writeBuffer(s.instances.buffer, s.scratch, count * NEAR_FLOATS);
129
+ s.count = count;
130
+ s.mesh.instances = count;
131
+ drawn += count;
132
+ }
133
+ this.stats.parts = this.parts.size;
134
+ this.stats.held = held;
135
+ this.stats.drawn = drawn;
136
+ this.stats.clipped = clipped;
137
+ }
138
+ draw(ctx) {
139
+ if (this.kinds.every((s) => s.count === 0))
140
+ return;
141
+ const program = this.begin(ctx);
142
+ if (!program)
143
+ return;
144
+ const o = this.origin();
145
+ const a = this.anchor;
146
+ const w = this.wind;
147
+ const waves = Math.min(1, Math.max(0, w.waves ?? 1));
148
+ const t = w.timeS - Math.floor(w.timeS / WRAP_S) * WRAP_S;
149
+ // Phase of the layer's anchor along the wind per wave, in doubles, wrapped to one turn.
150
+ const along = a[0] * w.dir[0] + a[1] * w.dir[1] + a[2] * w.dir[2];
151
+ const phase = (m) => {
152
+ const turns = along / m;
153
+ return (turns - Math.floor(turns)) * RAD_PER_TURN;
154
+ };
155
+ program.vec3('u_nearOffset', a[0] - o[0], a[1] - o[1], a[2] - o[2]);
156
+ program.vec3('u_nearEye', this.eye[0] - o[0], this.eye[1] - o[1], this.eye[2] - o[2]);
157
+ program.set('u_nearWave', { vec4: [phase(WAVE_M[0]), phase(WAVE_M[1]), waves, 0] });
158
+ for (const s of this.kinds) {
159
+ if (s.count === 0)
160
+ continue;
161
+ const f = s.draw.fade;
162
+ const b = w.strength * s.draw.bendM;
163
+ program.vec3('u_nearFade', s.gain * f.reachM, f.band, f.softM);
164
+ program.set('u_nearWind', { vec4: [w.dir[0] * b, w.dir[1] * b, w.dir[2] * b, t] });
165
+ ctx.device.draw(s.mesh);
166
+ ctx.count(s.mesh.triangles * s.count);
167
+ }
168
+ }
169
+ dispose() {
170
+ for (const s of this.kinds) {
171
+ this.device.deleteMesh(s.mesh);
172
+ this.device.deleteInstances(s.instances);
173
+ s.count = 0;
174
+ }
175
+ this.parts.clear();
176
+ }
177
+ }
178
+ /**
179
+ * Vertex include for the app's material (after `#include <header>`). Declares the instance attributes `i_base`,
180
+ * `i_shape`, `i_color` and the uniforms the layer sets per draw (`u_nearOffset`: layer anchor − render origin;
181
+ * `u_nearEye`: the eye in render space; `u_nearFade`: gain · reach, band, soft; `u_nearWind`: xyz = direction ·
182
+ * strength · bendM, w = time; `u_nearWave`: phases of the anchor per wave and the share of the waves). Gives
183
+ * `nearBase()` (the base in render space), `nearScale()` (0–1, the fade), `nearAxes(base)` (the instance's frame:
184
+ * upright along `localFrame`, turned about up) and `nearPoint(unitPos)`: the vertex in render space, scaled by the
185
+ * fade and bent by the wind.
186
+ */
187
+ export const NEAR_INSTANCE_GLSL = /* glsl */ `
188
+ ${NEAR_FADE_GLSL}
189
+ uniform vec3 u_nearOffset;
190
+ uniform vec3 u_nearEye;
191
+ uniform vec3 u_nearFade;
192
+ uniform vec4 u_nearWind;
193
+ uniform vec4 u_nearWave;
194
+ in vec4 i_base; // xyz relative to the layer's anchor, w order
195
+ in vec4 i_shape; // width, height, turn about up, bend
196
+ in vec4 i_color; // rgb, variant
197
+ vec3 nearBase() { return i_base.xyz + u_nearOffset; }
198
+ float nearScale() { return nearKeep(u_nearFade, i_base.w, distance(nearBase(), u_nearEye)); }
199
+ mat3 nearAxes(vec3 base) {
200
+ float c = cos(i_shape.z), s = sin(i_shape.z);
201
+ return localFrame(base) * mat3(c, 0.0, -s, 0.0, 1.0, 0.0, s, 0.0, c);
202
+ }
203
+ vec3 nearPoint(vec3 unitPos) {
204
+ vec3 base = nearBase();
205
+ float k = nearScale();
206
+ vec3 p = base + nearAxes(base) * (unitPos * vec3(i_shape.x, i_shape.y, i_shape.x) * k);
207
+ float wl = length(u_nearWind.xyz);
208
+ if (wl > 0.0) {
209
+ // Two waves fixed to the world (${WAVE_M[0]} m and ${WAVE_M[1]} m long) travel along the wind.
210
+ float along = dot(i_base.xyz, u_nearWind.xyz / wl);
211
+ float t = u_nearWind.w;
212
+ float sway = 0.35 + u_nearWave.z * (0.5 * sin(u_nearWave.x + along * ${(RAD_PER_TURN / WAVE_M[0]).toFixed(7)} - 1.7 * t)
213
+ + 0.3 * sin(u_nearWave.y + along * ${(RAD_PER_TURN / WAVE_M[1]).toFixed(7)} + 2.9 * t + 6.28 * i_color.w));
214
+ float y = max(unitPos.y, 0.0);
215
+ p += u_nearWind.xyz * (i_shape.w * i_shape.y * y * y * sway * k);
216
+ }
217
+ return p;
218
+ }
219
+ `;
@@ -0,0 +1,63 @@
1
+ import type { Layer } from './renderer.ts';
2
+ import type { DrawContext, Renderer } from './renderer.ts';
3
+ /** A looping particle source. Plain data, read when the sources are set. */
4
+ export interface ParticleSource {
5
+ /** Centre of the birth disc, in the coordinates the renderer draws in. */
6
+ position: readonly [number, number, number];
7
+ /** Particles alive at once (the source's share of the budget). */
8
+ count: number;
9
+ /** Seconds a particle lives. */
10
+ life: number;
11
+ /** Size in metres (quad edge) at birth and at death. */
12
+ size: readonly [number, number];
13
+ /** Initial upward speed, m/s. */
14
+ rise: number;
15
+ /** Radius of the birth disc (m) and the horizontal spread speed (m/s). */
16
+ spread: readonly [number, number];
17
+ /** Downward acceleration, m/s². Default 0. */
18
+ gravity?: number;
19
+ /** Share of the wind (`u_wind.xy`) that carries the particle, 0–1. Default 1. */
20
+ wind?: number;
21
+ /** Linear colour and opacity at birth and at death (rgb may exceed 1 for added light). */
22
+ colorStart: readonly [number, number, number, number];
23
+ colorEnd: readonly [number, number, number, number];
24
+ /** `'blend'` (default): alpha over the scene. `'add'`: light added onto it. */
25
+ blend?: 'blend' | 'add';
26
+ /** `'soft'` (default): a lit noise puff. `'core'`: a bright core. */
27
+ shape?: 'soft' | 'core';
28
+ /** Gain group 0–3 (default 0): opacity is multiplied by `ParticleLayer.gains[group]` at draw time. */
29
+ group?: number;
30
+ }
31
+ export interface ParticleCounts {
32
+ sources: number;
33
+ particles: number;
34
+ /** Particles left out because the budget was full. */
35
+ dropped: number;
36
+ }
37
+ export interface ParticleLayerOptions {
38
+ /** Most particles over all sources. Default 4096. */
39
+ budget?: number;
40
+ /** Layer name for profiles and statistics. */
41
+ name?: string;
42
+ }
43
+ /**
44
+ * Looping particle sources in two draws (blended, then added). Add it after the opaque layers. The materials read
45
+ * `u_time`, `u_wind`, `u_warmTint` and the `lighting` include of the environment.
46
+ */
47
+ export declare class ParticleLayer implements Layer {
48
+ name?: string;
49
+ readonly budget: number;
50
+ /** Opacity gain per group (`ParticleSource.group`), 1 by default. Change at run time. */
51
+ readonly gains: Float32Array<ArrayBuffer>;
52
+ /** What the last `setSources` packed. */
53
+ counts: ParticleCounts;
54
+ private readonly renderer;
55
+ private readonly layers;
56
+ /** Instance buffer of each mesh the layer made, deleted with it. */
57
+ private readonly owned;
58
+ constructor(renderer: Renderer, sources?: readonly ParticleSource[], o?: ParticleLayerOptions);
59
+ /** Replaces the sources: packs them within the budget and uploads the instance buffers. */
60
+ setSources(sources: readonly ParticleSource[]): void;
61
+ private upload;
62
+ draw(ctx: DrawContext): void;
63
+ }
@@ -0,0 +1,215 @@
1
+ // Particles from looping sources. Each particle is one instance of a camera-facing quad whose whole life is computed
2
+ // in the vertex shader from the animation time (`u_time.x` of the Frame block): nothing is simulated or allocated per
3
+ // frame, the instance buffers are written once when the sources are set, and pausing the clock freezes them. A source
4
+ // owns `count` particles born one after the other over `life` seconds, looping forever.
5
+ //
6
+ // Two draws at most: the sources with `blend: 'blend'` (alpha over the scene), then those with `blend: 'add'`. Both
7
+ // test depth and write none. The total number of particles has a fixed budget; sources beyond it lose particles
8
+ // (`counts.dropped`).
9
+ //
10
+ // Two shapes: `'soft'` is a puff of noise, lit like a surface facing up and toward the eye, turned a little per
11
+ // particle; `'core'` is a bright core that fades to the rim, unlit, with a fast flicker.
12
+ //
13
+ // `TransientLayer` dust is kept apart: its puffs are one-shot events at absolute clock times that come and go with
14
+ // batches (the mesh is rebuilt then), while these sources loop with no start or end.
15
+ import { MeshLayer } from './renderer.js';
16
+ /** Floats per particle record. */
17
+ const PARTICLE_FLOATS = 24;
18
+ const PARTICLE_ATTRIBS = { a_corner: 0, i_origin: 1, i_life: 2, i_motion: 3, i_c0: 4, i_c1: 5, i_kind: 6 };
19
+ const PARTICLE_LAYOUT = {
20
+ stride: PARTICLE_FLOATS * 4,
21
+ attribs: [
22
+ { name: 'i_origin', size: 4, type: 'f32', offset: 0 },
23
+ { name: 'i_life', size: 4, type: 'f32', offset: 16 },
24
+ { name: 'i_motion', size: 4, type: 'f32', offset: 32 },
25
+ { name: 'i_c0', size: 4, type: 'f32', offset: 48 },
26
+ { name: 'i_c1', size: 4, type: 'f32', offset: 64 },
27
+ { name: 'i_kind', size: 4, type: 'f32', offset: 80 },
28
+ ],
29
+ };
30
+ const QUAD = {
31
+ layout: { stride: 8, attribs: [{ name: 'a_corner', size: 2, type: 'f32', offset: 0 }] },
32
+ vertices: new Float32Array([-1, -1, 1, -1, 1, 1, -1, 1]),
33
+ indices: new Uint32Array([0, 1, 2, 0, 2, 3]),
34
+ count: 6,
35
+ };
36
+ const PARTICLE_VS = /* glsl */ `#include <header>
37
+ #include <noise>
38
+ in vec2 a_corner;
39
+ in vec4 i_origin; // xyz source, w phase 0–1
40
+ in vec4 i_life; // x life s, y size at birth, z size at death, w rise m/s
41
+ in vec4 i_motion; // x birth disc radius, y spread speed, z gravity, w wind share
42
+ in vec4 i_c0; // colour and opacity at birth
43
+ in vec4 i_c1; // at death
44
+ in vec4 i_kind; // x shape (0 soft, 1 core), y seed, z gain group, w unused
45
+ uniform vec4 u_particleGain;
46
+ out vec4 v_color;
47
+ out vec2 v_uv;
48
+ out float v_shape;
49
+ out float v_seed;
50
+ float h1(float a, float b) { return hash2(ivec2(int(a), int(b)), 77u); }
51
+ void main() {
52
+ float life = max(i_life.x, 0.05);
53
+ float cyc = u_time.x / life + i_origin.w;
54
+ float t = fract(cyc);
55
+ float k = floor(cyc);
56
+ float seed = i_kind.y;
57
+ // Random per particle and per life: birth point and drift.
58
+ float r1 = h1(seed, k), r2 = h1(seed + 101.0, k), r3 = h1(seed + 211.0, k), r4 = h1(seed + 307.0, k);
59
+ float age = t * life;
60
+ float ang = r1 * 6.2831853;
61
+ float rad = sqrt(r2) * i_motion.x;
62
+ vec3 p = i_origin.xyz + vec3(cos(ang) * rad, 0.0, sin(ang) * rad);
63
+ float ang2 = r3 * 6.2831853;
64
+ vec3 v = vec3(cos(ang2) * i_motion.y * (0.4 + 0.6 * r4), i_life.w * (0.75 + 0.5 * r4), sin(ang2) * i_motion.y * (0.4 + 0.6 * r4));
65
+ p += v * age;
66
+ p.y -= 0.5 * i_motion.z * age * age;
67
+ // The wind carries a particle more the older it gets, with a slow curl.
68
+ p.xz += u_wind.xy * i_motion.w * 1.6 * age * (0.3 + 0.7 * t);
69
+ p.xz += vec2(sin(age * 1.3 + seed), cos(age * 1.1 + seed * 1.7)) * i_motion.w * 0.25 * t;
70
+ float size = mix(i_life.y, i_life.z, t);
71
+ float spin = (r1 - 0.5) * 2.0 + age * (r2 - 0.5);
72
+ float cs = cos(spin), sn = sin(spin);
73
+ vec2 c = a_corner;
74
+ if (i_kind.x < 0.5) c = vec2(cs * c.x - sn * c.y, sn * c.x + cs * c.y);
75
+ vec3 w = p + (u_camRight.xyz * c.x + u_camUp.xyz * c.y) * size * 0.5;
76
+ float fade = smoothstep(0.0, 0.12, t) * (1.0 - smoothstep(0.65, 1.0, t));
77
+ int g = int(i_kind.z);
78
+ float gain = g == 0 ? u_particleGain.x : g == 1 ? u_particleGain.y : g == 2 ? u_particleGain.z : u_particleGain.w;
79
+ vec4 col = mix(i_c0, i_c1, t);
80
+ col.a *= fade * gain;
81
+ v_color = col;
82
+ v_uv = a_corner;
83
+ v_shape = i_kind.x;
84
+ v_seed = seed + k * 13.0;
85
+ gl_Position = u_viewProj * vec4(w, 1.0);
86
+ }`;
87
+ function particleFs(add) {
88
+ return /* glsl */ `#include <header>
89
+ #include <noise>
90
+ #include <lighting>
91
+ in vec4 v_color;
92
+ in vec2 v_uv;
93
+ in float v_shape;
94
+ in float v_seed;
95
+ out vec4 o_color;
96
+ void main() {
97
+ float r = length(v_uv);
98
+ if (r > 1.0) discard;
99
+ vec4 c = v_color;
100
+ vec3 rgb;
101
+ float a;
102
+ if (v_shape < 0.5) {
103
+ // Soft puff lit by the sky and the sun, darker underneath.
104
+ float puff = vnoise(v_uv * 2.2 + v_seed, 61u) * 0.6 + vnoise(v_uv * 5.0 + v_seed * 0.3, 62u) * 0.4;
105
+ a = c.a * smoothstep(1.0, 0.25, r) * (0.55 + 0.6 * puff);
106
+ rgb = toDisplay(c.rgb * u_warmTint.rgb * lightOn(normalize(vec3(v_uv.x, 0.6 + v_uv.y, 0.5)), 0.85, 1.0));
107
+ } else {
108
+ // Bright core with a fast flicker.
109
+ float core = smoothstep(1.0, 0.0, r);
110
+ rgb = c.rgb * (0.75 + 0.25 * vnoise(vec2(u_time.x * 9.0, v_seed), 63u));
111
+ a = c.a * core * core;
112
+ }
113
+ ${add ? 'o_color = vec4(rgb * a, 1.0);' : 'o_color = vec4(rgb, clamp(a, 0.0, 1.0));'}
114
+ }`;
115
+ }
116
+ const PARTICLE_BLEND_MATERIAL = {
117
+ name: 'particles-blend',
118
+ attribs: PARTICLE_ATTRIBS,
119
+ passes: { color: { vs: PARTICLE_VS, fs: particleFs(false) } },
120
+ state: { color: { depthWrite: false, cullBack: false, blend: { src: 'src-alpha', dst: 'one-minus-src-alpha', srcAlpha: 'one', dstAlpha: 'one-minus-src-alpha' } } },
121
+ };
122
+ const PARTICLE_ADD_MATERIAL = {
123
+ name: 'particles-add',
124
+ attribs: PARTICLE_ATTRIBS,
125
+ passes: { color: { vs: PARTICLE_VS, fs: particleFs(true) } },
126
+ state: { color: { depthWrite: false, cullBack: false, blend: { src: 'one', dst: 'one', srcAlpha: 'zero', dstAlpha: 'one' } } },
127
+ };
128
+ /**
129
+ * Looping particle sources in two draws (blended, then added). Add it after the opaque layers. The materials read
130
+ * `u_time`, `u_wind`, `u_warmTint` and the `lighting` include of the environment.
131
+ */
132
+ export class ParticleLayer {
133
+ name;
134
+ budget;
135
+ /** Opacity gain per group (`ParticleSource.group`), 1 by default. Change at run time. */
136
+ gains = new Float32Array([1, 1, 1, 1]);
137
+ /** What the last `setSources` packed. */
138
+ counts = { sources: 0, particles: 0, dropped: 0 };
139
+ renderer;
140
+ layers;
141
+ /** Instance buffer of each mesh the layer made, deleted with it. */
142
+ owned = new Map();
143
+ constructor(renderer, sources = [], o = {}) {
144
+ this.renderer = renderer;
145
+ this.budget = Math.max(0, Math.floor(o.budget ?? 4096));
146
+ if (o.name !== undefined)
147
+ this.name = o.name;
148
+ const bind = (program) => program.vec4v('u_particleGain', this.gains);
149
+ this.layers = [
150
+ new ParticleDraw({ material: renderer.material(PARTICLE_BLEND_MATERIAL), bind }),
151
+ new ParticleDraw({ material: renderer.material(PARTICLE_ADD_MATERIAL), bind }),
152
+ ];
153
+ this.setSources(sources);
154
+ }
155
+ /** Replaces the sources: packs them within the budget and uploads the instance buffers. */
156
+ setSources(sources) {
157
+ const blend = [];
158
+ const add = [];
159
+ let used = 0;
160
+ let dropped = 0;
161
+ let seed = 1;
162
+ for (const s of sources) {
163
+ const out = s.blend === 'add' ? add : blend;
164
+ const shape = s.shape === 'core' ? 1 : 0;
165
+ const n = Math.max(0, Math.floor(s.count));
166
+ for (let i = 0; i < n; i++) {
167
+ if (used >= this.budget) {
168
+ dropped++;
169
+ continue;
170
+ }
171
+ used++;
172
+ seed++;
173
+ out.push(s.position[0], s.position[1], s.position[2], i / n, s.life, s.size[0], s.size[1], s.rise, s.spread[0], s.spread[1], s.gravity ?? 0, s.wind ?? 1, s.colorStart[0], s.colorStart[1], s.colorStart[2], s.colorStart[3], s.colorEnd[0], s.colorEnd[1], s.colorEnd[2], s.colorEnd[3], shape, seed * 7 + 3, Math.max(0, Math.min(3, Math.floor(s.group ?? 0))), 0);
174
+ }
175
+ }
176
+ this.upload(this.layers[0], blend);
177
+ this.upload(this.layers[1], add);
178
+ this.counts = { sources: sources.length, particles: used, dropped };
179
+ }
180
+ upload(layer, records) {
181
+ const old = layer.mesh;
182
+ if (records.length === 0)
183
+ layer.mesh = null;
184
+ else {
185
+ const instances = this.renderer.createInstances({ layout: PARTICLE_LAYOUT, data: new Float32Array(records) });
186
+ const mesh = this.renderer.createMesh(QUAD, layer.material, instances);
187
+ mesh.instances = records.length / PARTICLE_FLOATS;
188
+ layer.mesh = mesh;
189
+ this.owned.set(mesh, instances);
190
+ }
191
+ if (old) {
192
+ this.renderer.device.deleteMesh(old);
193
+ const inst = this.owned.get(old);
194
+ if (inst)
195
+ this.renderer.device.deleteInstances(inst);
196
+ this.owned.delete(old);
197
+ }
198
+ }
199
+ draw(ctx) {
200
+ if (ctx.pass !== 'color')
201
+ return;
202
+ this.layers[0].draw(ctx);
203
+ this.layers[1].draw(ctx);
204
+ }
205
+ }
206
+ /** One of the two draws: counts every particle's triangles. */
207
+ class ParticleDraw extends MeshLayer {
208
+ draw(ctx) {
209
+ const m = this.mesh;
210
+ if (!m || m.instances <= 0 || !this.begin(ctx))
211
+ return;
212
+ ctx.device.draw(m);
213
+ ctx.count(m.triangles * m.instances);
214
+ }
215
+ }
@@ -0,0 +1,57 @@
1
+ import type { Box3, CullVolume, View } from '../base/view.ts';
2
+ import type { Mesh } from '../gpu/index.ts';
3
+ import type { PointLightSet } from './point-lights.ts';
4
+ import { MeshLayer } from './renderer.ts';
5
+ import type { DrawContext, MeshLayerOptions } from './renderer.ts';
6
+ /** One mesh and the axis-aligned box that holds all of it (in the coordinates the renderer draws in). */
7
+ export interface MeshPiece extends Box3 {
8
+ mesh: Mesh;
9
+ }
10
+ export interface PieceLayerOptions extends Omit<MeshLayerOptions, 'mesh'> {
11
+ /**
12
+ * Order of the pieces in the colour and data passes. `'added'` (default): the order they were added in.
13
+ * `'front-to-back'`: nearest box centre along the view direction first, sorted when the view set is culled, so
14
+ * opaque pieces hide what is behind them before it is shaded.
15
+ */
16
+ order?: 'added' | 'front-to-back';
17
+ /**
18
+ * Point lights: in the colour pass each piece's draw names the selected lights whose sphere reaches its box
19
+ * (`POINT_LIGHTS_PER_DRAW` at most). The material includes `<point-lights>`. Default none.
20
+ */
21
+ lights?: PointLightSet | null;
22
+ }
23
+ /**
24
+ * A `MeshLayer` with a list of pieces instead of one mesh. Material, uniforms, textures, passes and draw state are
25
+ * shared and set once per pass; each piece is one draw call. Adding or removing a piece marks the culled sets stale,
26
+ * so the renderer refits and culls again on the next frame.
27
+ */
28
+ export declare class PieceLayer extends MeshLayer {
29
+ /** Order of the pieces in the colour and data passes (`PieceLayerOptions.order`). */
30
+ order: 'added' | 'front-to-back';
31
+ /** Point lights per piece in the colour pass (`PieceLayerOptions.lights`). */
32
+ lights: PointLightSet | null;
33
+ private list;
34
+ private shadowSet;
35
+ private viewSet;
36
+ private shadowCount;
37
+ private viewCount;
38
+ /** Sort keys of the view set (depth of the box centre along the view). */
39
+ private keys;
40
+ /** Scratch for the view's axes while sorting. */
41
+ private readonly axes;
42
+ private stale;
43
+ /** Pieces drawn in the last colour (or data) pass. */
44
+ drawn: number;
45
+ constructor(o: PieceLayerOptions);
46
+ get pieces(): readonly MeshPiece[];
47
+ /** Bytes of GPU buffers the pieces' meshes own. */
48
+ get bytes(): number;
49
+ add(piece: MeshPiece): void;
50
+ /** Takes a piece out (the caller deletes its mesh). Returns whether it was there. */
51
+ remove(piece: MeshPiece): boolean;
52
+ cullStale(): boolean;
53
+ cull(volume: CullVolume, purpose: 'shadow' | 'view', view?: View): number;
54
+ /** Insertion sort of the first `n` entries of the view set by depth along the view (stable, in place). */
55
+ private sortView;
56
+ draw(ctx: DrawContext): void;
57
+ }