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,137 @@
1
+ // Stamps outlines and discs into a byte raster of class codes, for shapes that are about as small as a raster cell.
2
+ // A cell takes the stamped code with a probability equal to the share of the cell the shape covers (ordered samples
3
+ // inside the cell against a hash of the cell), so many small shapes keep their total area in the raster and shapes
4
+ // that overlap add up. The hash depends only on the seed, the cell and the shape's salt, never on the part of the
5
+ // raster being worked on: a raster stamped part by part (per tile, in workers) equals one stamped at once.
6
+ import { hashInts, unit } from '../gen-core/index.js';
7
+ /** Samples per cell side that measure the covered share. */
8
+ const SUB = 4;
9
+ const FULL = SUB * SUB;
10
+ export class CodeStamp {
11
+ /** Cells stamped so far (a cell stamped twice counts twice). */
12
+ stamped = 0;
13
+ region;
14
+ /** The cells of the region, `cols × rows` bytes, row `row0` first. Fill it with what lies under the stamps. */
15
+ codes;
16
+ seed;
17
+ counts = new Uint8Array(64);
18
+ constructor(region, codes, seed) {
19
+ if (codes.length !== region.cols * region.rows)
20
+ throw new Error('CodeStamp: the raster does not match the region');
21
+ this.region = region;
22
+ this.codes = codes;
23
+ this.seed = seed;
24
+ }
25
+ /** Whether a cell with `hits` covered samples takes the code. */
26
+ take(col, row, salt, hits) {
27
+ if (hits <= 0)
28
+ return false;
29
+ return hits >= FULL || hits / FULL > unit(hashInts(this.seed, col, row, salt));
30
+ }
31
+ /**
32
+ * Stamps a polygon: rings of x, z pairs (not closed, either winding), inside by the even-odd rule, so later rings
33
+ * cut holes. `salt` tells shapes apart (two shapes on one cell decide independently). Returns the cells stamped.
34
+ */
35
+ polygon(rings, code, salt) {
36
+ const { col0, row0, cols, rows, step } = this.region;
37
+ let minX = Infinity;
38
+ let maxX = -Infinity;
39
+ let minZ = Infinity;
40
+ let maxZ = -Infinity;
41
+ for (const ring of rings) {
42
+ for (let i = 0; i + 1 < ring.length; i += 2) {
43
+ const x = ring[i];
44
+ const z = ring[i + 1];
45
+ if (x < minX)
46
+ minX = x;
47
+ if (x > maxX)
48
+ maxX = x;
49
+ if (z < minZ)
50
+ minZ = z;
51
+ if (z > maxZ)
52
+ maxZ = z;
53
+ }
54
+ }
55
+ const c0 = Math.max(col0, Math.floor(minX / step));
56
+ const c1 = Math.min(col0 + cols - 1, Math.floor(maxX / step));
57
+ const r0 = Math.max(row0, Math.floor(minZ / step));
58
+ const r1 = Math.min(row0 + rows - 1, Math.floor(maxZ / step));
59
+ if (!(c0 <= c1) || !(r0 <= r1))
60
+ return 0;
61
+ const width = c1 - c0 + 1;
62
+ if (this.counts.length < width)
63
+ this.counts = new Uint8Array(width * 2);
64
+ const counts = this.counts;
65
+ const sub = step / SUB;
66
+ const first = c0 * SUB;
67
+ const last = (c1 + 1) * SUB - 1;
68
+ const xs = [];
69
+ let n = 0;
70
+ for (let r = r0; r <= r1; r++) {
71
+ counts.fill(0, 0, width);
72
+ for (let s = 0; s < SUB; s++) {
73
+ const z = (r * SUB + s + 0.5) * sub;
74
+ xs.length = 0;
75
+ for (const ring of rings) {
76
+ const m = ring.length >> 1;
77
+ for (let i = 0, j = m - 1; i < m; j = i++) {
78
+ const az = ring[j * 2 + 1];
79
+ const bz = ring[i * 2 + 1];
80
+ if (az > z !== bz > z)
81
+ xs.push(ring[j * 2] + ((z - az) / (bz - az)) * (ring[i * 2] - ring[j * 2]));
82
+ }
83
+ }
84
+ xs.sort((a, b) => a - b);
85
+ for (let k = 0; k + 1 < xs.length; k += 2) {
86
+ // Samples whose centre lies between the two points where the outline cuts the sample row.
87
+ const q0 = Math.max(first, Math.ceil(xs[k] / sub - 0.5));
88
+ const q1 = Math.min(last, Math.ceil(xs[k + 1] / sub - 0.5) - 1);
89
+ for (let q = q0; q <= q1; q++)
90
+ counts[Math.floor(q / SUB) - c0]++;
91
+ }
92
+ }
93
+ const row = (r - row0) * cols - col0;
94
+ for (let c = c0; c <= c1; c++) {
95
+ if (!this.take(c, r, salt, counts[c - c0]))
96
+ continue;
97
+ this.codes[row + c] = code;
98
+ n++;
99
+ }
100
+ }
101
+ this.stamped += n;
102
+ return n;
103
+ }
104
+ /** Stamps a disc around (x, z). Returns the cells stamped. */
105
+ disc(x, z, radius, code, salt) {
106
+ const { col0, row0, cols, rows, step } = this.region;
107
+ const c0 = Math.max(col0, Math.floor((x - radius) / step));
108
+ const c1 = Math.min(col0 + cols - 1, Math.floor((x + radius) / step));
109
+ const r0 = Math.max(row0, Math.floor((z - radius) / step));
110
+ const r1 = Math.min(row0 + rows - 1, Math.floor((z + radius) / step));
111
+ if (!(c0 <= c1) || !(r0 <= r1))
112
+ return 0;
113
+ const sub = step / SUB;
114
+ const rr = radius * radius;
115
+ let n = 0;
116
+ for (let r = r0; r <= r1; r++) {
117
+ const row = (r - row0) * cols - col0;
118
+ for (let c = c0; c <= c1; c++) {
119
+ let hits = 0;
120
+ for (let j = 0; j < SUB; j++) {
121
+ const dz = (r * SUB + j + 0.5) * sub - z;
122
+ for (let i = 0; i < SUB; i++) {
123
+ const dx = (c * SUB + i + 0.5) * sub - x;
124
+ if (dx * dx + dz * dz <= rr)
125
+ hits++;
126
+ }
127
+ }
128
+ if (!this.take(c, r, salt, hits))
129
+ continue;
130
+ this.codes[row + c] = code;
131
+ n++;
132
+ }
133
+ }
134
+ this.stamped += n;
135
+ return n;
136
+ }
137
+ }
@@ -0,0 +1,7 @@
1
+ export { boxBlur, codeTexture, colorTable } from './textures.ts';
2
+ export { NO_VALUE, VALUE_RAMPS, VALUE_TABLE_WIDTH, VALUE_WORD_MAX, colorRamp, quantizeValues, rampColor, valueTableSize, wordTexture, wordValue } from './value-textures.ts';
3
+ export type { RampStop, ValueRampName } from './value-textures.ts';
4
+ export { CodeStamp } from './code-stamp.ts';
5
+ export type { CodeRegion } from './code-stamp.ts';
6
+ export { SurfaceRaster, horizonTexture, lightHorizon } from './light-horizon.ts';
7
+ export type { HorizonTexture } from './light-horizon.ts';
@@ -0,0 +1,5 @@
1
+ // Layer 3, gen-tex: texture generators. Pure functions that return texture data; the GPU never appears here.
2
+ export { boxBlur, codeTexture, colorTable } from './textures.js';
3
+ export { NO_VALUE, VALUE_RAMPS, VALUE_TABLE_WIDTH, VALUE_WORD_MAX, colorRamp, quantizeValues, rampColor, valueTableSize, wordTexture, wordValue } from './value-textures.js';
4
+ export { CodeStamp } from './code-stamp.js';
5
+ export { SurfaceRaster, horizonTexture, lightHorizon } from './light-horizon.js';
@@ -0,0 +1,47 @@
1
+ import type { TextureData } from '../base/data.ts';
2
+ /**
3
+ * Surface heights in square cells over the x–z plane: cell (col, row) covers x from `col × step` and z from
4
+ * `row × step`, and holds the height at its centre.
5
+ */
6
+ export declare class SurfaceRaster {
7
+ readonly cols: number;
8
+ readonly rows: number;
9
+ /** Cell size in metres. */
10
+ readonly step: number;
11
+ /** `cols × rows` heights, row 0 first. */
12
+ readonly heights: Float32Array;
13
+ /** `base(x, z)` gives the height of the bare surface at a cell centre; without it the raster starts at 0. */
14
+ constructor(cols: number, rows: number, step: number, base?: (x: number, z: number) => number);
15
+ /**
16
+ * Raises every cell whose centre lies inside a polygon to at least `top`. Rings of x, z pairs (not closed, either
17
+ * winding), inside by the even-odd rule, so later rings cut holes. Returns the cells raised.
18
+ */
19
+ raisePolygon(rings: readonly ArrayLike<number>[], top: number): number;
20
+ /** Raises every cell whose centre lies within `radius` of (x, z) to at least `top`. Returns the cells raised. */
21
+ raiseDisc(x: number, z: number, radius: number, top: number): number;
22
+ }
23
+ /**
24
+ * The light horizon of a surface for a unit direction toward the light (`toLight`, y up): per cell the height below
25
+ * which a point over the cell centre is hidden from the light by other cells. `-Infinity` where nothing stands between
26
+ * the cell and the light.
27
+ *
28
+ * One sweep, row by row away from the light: a cell's horizon is the higher of surface and horizon one row closer
29
+ * to the light, lowered by what the light gains in height over that step. The light rarely runs along the rows, so the
30
+ * value one row closer is read between two cells; that widens and softens a shadow a little with its length, which
31
+ * suits a term that is only used far away. The cost does not depend on the light's height.
32
+ */
33
+ export declare function lightHorizon(surface: SurfaceRaster, toLight: readonly [number, number, number]): Float32Array;
34
+ /** A light horizon packed for the renderer. */
35
+ export interface HorizonTexture {
36
+ /** Two bytes per cell (`rg8`, high byte first), filtered linearly: `baseY + code / 65535 × rangeM`. */
37
+ texture: TextureData;
38
+ /** The height code 0 stands for: the lowest point of the surface, below which nothing needs an answer. */
39
+ baseY: number;
40
+ /** The span of heights the codes cover, metres. */
41
+ rangeM: number;
42
+ }
43
+ /**
44
+ * Packs a horizon (`lightHorizon`) of a surface into a texture. Heights below the lowest point of the surface
45
+ * (and cells without a horizon) become code 0: every point of the surface is lit there.
46
+ */
47
+ export declare function horizonTexture(horizon: Float32Array, surface: SurfaceRaster): HorizonTexture;
@@ -0,0 +1,180 @@
1
+ // The light horizon of a surface: for every cell of a raster of surface heights, the height below which a point above
2
+ // that cell is hidden from a directional light by the rest of the surface. One number per cell answers "is this point
3
+ // lit" for the ground and for anything standing on it (a point is lit when it lies above the horizon), so a coarse
4
+ // raster over a whole scene can stand in for a shadow map where the shadow map does not reach.
5
+ //
6
+ // `SurfaceRaster` collects the heights (a base surface, raised under outlines and discs), `lightHorizon` sweeps it
7
+ // once along the light and `horizonTexture` packs the result into two bytes per cell for the renderer.
8
+ /**
9
+ * Surface heights in square cells over the x–z plane: cell (col, row) covers x from `col × step` and z from
10
+ * `row × step`, and holds the height at its centre.
11
+ */
12
+ export class SurfaceRaster {
13
+ cols;
14
+ rows;
15
+ /** Cell size in metres. */
16
+ step;
17
+ /** `cols × rows` heights, row 0 first. */
18
+ heights;
19
+ /** `base(x, z)` gives the height of the bare surface at a cell centre; without it the raster starts at 0. */
20
+ constructor(cols, rows, step, base) {
21
+ this.cols = cols;
22
+ this.rows = rows;
23
+ this.step = step;
24
+ this.heights = new Float32Array(cols * rows);
25
+ if (base) {
26
+ for (let r = 0; r < rows; r++)
27
+ for (let c = 0; c < cols; c++)
28
+ this.heights[r * cols + c] = base((c + 0.5) * step, (r + 0.5) * step);
29
+ }
30
+ }
31
+ /**
32
+ * Raises every cell whose centre lies inside a polygon to at least `top`. Rings of x, z pairs (not closed, either
33
+ * winding), inside by the even-odd rule, so later rings cut holes. Returns the cells raised.
34
+ */
35
+ raisePolygon(rings, top) {
36
+ const { cols, rows, step } = this;
37
+ let minZ = Infinity;
38
+ let maxZ = -Infinity;
39
+ for (const ring of rings) {
40
+ for (let i = 1; i < ring.length; i += 2) {
41
+ const z = ring[i];
42
+ if (z < minZ)
43
+ minZ = z;
44
+ if (z > maxZ)
45
+ maxZ = z;
46
+ }
47
+ }
48
+ const r0 = Math.max(0, Math.ceil(minZ / step - 0.5));
49
+ const r1 = Math.min(rows - 1, Math.ceil(maxZ / step - 0.5) - 1);
50
+ const xs = [];
51
+ let n = 0;
52
+ for (let r = r0; r <= r1; r++) {
53
+ const z = (r + 0.5) * step;
54
+ xs.length = 0;
55
+ for (const ring of rings) {
56
+ const m = ring.length >> 1;
57
+ for (let i = 0, j = m - 1; i < m; j = i++) {
58
+ const az = ring[j * 2 + 1];
59
+ const bz = ring[i * 2 + 1];
60
+ if (az > z !== bz > z)
61
+ xs.push(ring[j * 2] + ((z - az) / (bz - az)) * (ring[i * 2] - ring[j * 2]));
62
+ }
63
+ }
64
+ xs.sort((a, b) => a - b);
65
+ for (let k = 0; k + 1 < xs.length; k += 2) {
66
+ // Cells whose centre lies between the two points where the outline cuts the row of centres.
67
+ const c0 = Math.max(0, Math.ceil(xs[k] / step - 0.5));
68
+ const c1 = Math.min(cols - 1, Math.ceil(xs[k + 1] / step - 0.5) - 1);
69
+ for (let c = c0; c <= c1; c++) {
70
+ const o = r * cols + c;
71
+ if (this.heights[o] < top) {
72
+ this.heights[o] = top;
73
+ n++;
74
+ }
75
+ }
76
+ }
77
+ }
78
+ return n;
79
+ }
80
+ /** Raises every cell whose centre lies within `radius` of (x, z) to at least `top`. Returns the cells raised. */
81
+ raiseDisc(x, z, radius, top) {
82
+ const { cols, rows, step } = this;
83
+ const c0 = Math.max(0, Math.ceil((x - radius) / step - 0.5));
84
+ const c1 = Math.min(cols - 1, Math.ceil((x + radius) / step - 0.5) - 1);
85
+ const r0 = Math.max(0, Math.ceil((z - radius) / step - 0.5));
86
+ const r1 = Math.min(rows - 1, Math.ceil((z + radius) / step - 0.5) - 1);
87
+ const rr = radius * radius;
88
+ let n = 0;
89
+ for (let r = r0; r <= r1; r++) {
90
+ const dz = (r + 0.5) * step - z;
91
+ for (let c = c0; c <= c1; c++) {
92
+ const dx = (c + 0.5) * step - x;
93
+ if (dx * dx + dz * dz > rr)
94
+ continue;
95
+ const o = r * cols + c;
96
+ if (this.heights[o] < top) {
97
+ this.heights[o] = top;
98
+ n++;
99
+ }
100
+ }
101
+ }
102
+ return n;
103
+ }
104
+ }
105
+ /** The light counts as at least this high above the horizontal (rise per metre): a lower one would shade everything. */
106
+ const MIN_RISE = 0.03;
107
+ /** Below this horizontal share of the direction the light comes from straight above and nothing shades anything. */
108
+ const MIN_RUN = 1e-4;
109
+ /**
110
+ * The light horizon of a surface for a unit direction toward the light (`toLight`, y up): per cell the height below
111
+ * which a point over the cell centre is hidden from the light by other cells. `-Infinity` where nothing stands between
112
+ * the cell and the light.
113
+ *
114
+ * One sweep, row by row away from the light: a cell's horizon is the higher of surface and horizon one row closer
115
+ * to the light, lowered by what the light gains in height over that step. The light rarely runs along the rows, so the
116
+ * value one row closer is read between two cells; that widens and softens a shadow a little with its length, which
117
+ * suits a term that is only used far away. The cost does not depend on the light's height.
118
+ */
119
+ export function lightHorizon(surface, toLight) {
120
+ const { cols, rows, step, heights } = surface;
121
+ const out = new Float32Array(cols * rows).fill(-Infinity);
122
+ const run = Math.hypot(toLight[0], toLight[2]);
123
+ if (!(run > MIN_RUN) || cols === 0 || rows === 0)
124
+ return out;
125
+ const rise = Math.max(toLight[1] / run, MIN_RISE);
126
+ // Sweep along the axis the light direction follows more closely; `lines` are the rows of that sweep.
127
+ const alongZ = Math.abs(toLight[2]) >= Math.abs(toLight[0]);
128
+ const major = alongZ ? toLight[2] : toLight[0];
129
+ const minor = alongZ ? toLight[0] : toLight[2];
130
+ const lines = alongZ ? rows : cols;
131
+ const width = alongZ ? cols : rows;
132
+ const toward = major > 0 ? 1 : -1;
133
+ // Per line toward the light the direction moves this many cells sideways.
134
+ const shift = minor / Math.abs(major);
135
+ const drop = step * Math.sqrt(1 + shift * shift) * rise;
136
+ const at = (line, k) => (alongZ ? line * cols + k : k * cols + line);
137
+ // The higher of surface and horizon of the line closer to the light.
138
+ const closer = new Float32Array(width);
139
+ for (let n = 1; n < lines; n++) {
140
+ const line = toward > 0 ? lines - 1 - n : n;
141
+ const from = line + toward;
142
+ for (let k = 0; k < width; k++)
143
+ closer[k] = Math.max(heights[at(from, k)], out[at(from, k)]);
144
+ for (let k = 0; k < width; k++) {
145
+ const s = k + shift;
146
+ const k0 = Math.floor(s);
147
+ const f = s - k0;
148
+ const a = closer[Math.min(width - 1, Math.max(0, k0))];
149
+ const b = closer[Math.min(width - 1, Math.max(0, k0 + 1))];
150
+ out[at(line, k)] = a + (b - a) * f - drop;
151
+ }
152
+ }
153
+ return out;
154
+ }
155
+ /**
156
+ * Packs a horizon (`lightHorizon`) of a surface into a texture. Heights below the lowest point of the surface
157
+ * (and cells without a horizon) become code 0: every point of the surface is lit there.
158
+ */
159
+ export function horizonTexture(horizon, surface) {
160
+ const { cols, rows, heights } = surface;
161
+ let baseY = Infinity;
162
+ let top = -Infinity;
163
+ for (let i = 0; i < heights.length; i++)
164
+ if (heights[i] < baseY)
165
+ baseY = heights[i];
166
+ for (let i = 0; i < horizon.length; i++)
167
+ if (horizon[i] > top)
168
+ top = horizon[i];
169
+ if (!Number.isFinite(baseY))
170
+ baseY = 0;
171
+ const rangeM = Math.max(1, top - baseY);
172
+ const data = new Uint8Array(cols * rows * 2);
173
+ for (let i = 0; i < cols * rows; i++) {
174
+ const h = horizon[i];
175
+ const code = h > baseY ? Math.min(65535, Math.round(((h - baseY) / rangeM) * 65535)) : 0;
176
+ data[i * 2] = code >> 8;
177
+ data[i * 2 + 1] = code & 255;
178
+ }
179
+ return { texture: { width: cols, height: rows, format: 'rg8', data, filter: 'linear' }, baseY, rangeM };
180
+ }
@@ -0,0 +1,8 @@
1
+ import type { RGB } from '../base/math.ts';
2
+ import type { TextureData } from '../base/data.ts';
3
+ /** A byte raster (one byte per pixel, row 0 first) as an unsigned integer texture, read with `texelFetch`. */
4
+ export declare function codeTexture(codes: Uint8Array, cols: number, rows: number): TextureData;
5
+ /** Table of 256 colours by code, one row. A code not in the table gets `fallback`. */
6
+ export declare function colorTable(colors: ReadonlyMap<number, RGB>, fallback?: RGB): TextureData;
7
+ /** Blurs one channel with a moving average, twice horizontally and twice vertically. */
8
+ export declare function boxBlur(src: Float32Array, cols: number, rows: number, radius: number): Float32Array;
@@ -0,0 +1,49 @@
1
+ // Texture generators: byte rasters and colour tables as texture data, and a separable blur for masks.
2
+ /** A byte raster (one byte per pixel, row 0 first) as an unsigned integer texture, read with `texelFetch`. */
3
+ export function codeTexture(codes, cols, rows) {
4
+ return { width: cols, height: rows, format: 'r8ui', data: codes };
5
+ }
6
+ /** Table of 256 colours by code, one row. A code not in the table gets `fallback`. */
7
+ export function colorTable(colors, fallback = [1, 0, 1]) {
8
+ const data = new Uint8Array(256 * 4);
9
+ for (let code = 0; code < 256; code++) {
10
+ const c = colors.get(code) ?? fallback;
11
+ data[code * 4] = Math.round(c[0] * 255);
12
+ data[code * 4 + 1] = Math.round(c[1] * 255);
13
+ data[code * 4 + 2] = Math.round(c[2] * 255);
14
+ data[code * 4 + 3] = 255;
15
+ }
16
+ return { width: 256, height: 1, format: 'rgba8', data };
17
+ }
18
+ /** Blurs one channel with a moving average, twice horizontally and twice vertically. */
19
+ export function boxBlur(src, cols, rows, radius) {
20
+ let a = src;
21
+ let b = new Float32Array(src.length);
22
+ const pass = (horizontal) => {
23
+ const n = horizontal ? cols : rows;
24
+ const lines = horizontal ? rows : cols;
25
+ const stride = horizontal ? 1 : cols;
26
+ const lineStride = horizontal ? cols : 1;
27
+ const win = 2 * radius + 1;
28
+ for (let l = 0; l < lines; l++) {
29
+ const base = l * lineStride;
30
+ let sum = 0;
31
+ for (let k = -radius; k <= radius; k++)
32
+ sum += a[base + Math.min(n - 1, Math.max(0, k)) * stride];
33
+ for (let k = 0; k < n; k++) {
34
+ b[base + k * stride] = sum / win;
35
+ const add = Math.min(n - 1, k + radius + 1);
36
+ const sub = Math.max(0, k - radius);
37
+ sum += a[base + add * stride] - a[base + sub * stride];
38
+ }
39
+ }
40
+ const t = a;
41
+ a = b;
42
+ b = t === src ? new Float32Array(src.length) : t;
43
+ };
44
+ pass(true);
45
+ pass(false);
46
+ pass(true);
47
+ pass(false);
48
+ return a;
49
+ }
@@ -0,0 +1,46 @@
1
+ import type { RGB } from '../base/math.ts';
2
+ import type { TextureData } from '../base/data.ts';
3
+ /** The word that means "no value here". */
4
+ export declare const NO_VALUE = 0;
5
+ /** Largest word; the words 1–65535 span the value range linearly. */
6
+ export declare const VALUE_WORD_MAX = 65535;
7
+ /** Widest table texture: rows of a table wrap at this width. */
8
+ export declare const VALUE_TABLE_WIDTH = 1024;
9
+ /** One stop of a colour ramp: a position 0–1 and the colour shown there (as it should appear on the screen). */
10
+ export interface RampStop {
11
+ at: number;
12
+ color: RGB;
13
+ }
14
+ /** Ready-made ramps. `diverging` has its neutral colour in the middle of the range. */
15
+ export declare const VALUE_RAMPS: {
16
+ readonly viridis: RampStop[];
17
+ readonly heat: RampStop[];
18
+ readonly blues: RampStop[];
19
+ readonly diverging: RampStop[];
20
+ readonly grey: RampStop[];
21
+ };
22
+ export type ValueRampName = keyof typeof VALUE_RAMPS;
23
+ /**
24
+ * Colour of a ramp at position `t` (0–1). Stops are sorted by position here, so their order does not matter. With
25
+ * `bands` > 0 the ramp has that many flat steps, each in the colour of its middle.
26
+ */
27
+ export declare function rampColor(stops: readonly RampStop[], t: number, bands?: number): RGB;
28
+ /** A ramp as a 256 × 1 texture: texel k holds the colour at (k + 0.5) / 256. Smooth ramps filter linearly, banded ones not. */
29
+ export declare function colorRamp(stops: readonly RampStop[], bands?: number): TextureData;
30
+ /**
31
+ * Values as words: `min` becomes 1, `max` becomes 65535, values outside are clamped, and a value that is not a finite
32
+ * number becomes `NO_VALUE`. `out` is reused when it is long enough.
33
+ */
34
+ export declare function quantizeValues(values: ArrayLike<number>, min: number, max: number, out?: Uint16Array): Uint16Array;
35
+ /** The value a word stands for, or NaN for `NO_VALUE`. */
36
+ export declare function wordValue(word: number, min: number, max: number): number;
37
+ /** Size of the table texture that holds `count` rows: rows fill it line by line and wrap at `VALUE_TABLE_WIDTH`. */
38
+ export declare function valueTableSize(count: number): {
39
+ width: number;
40
+ height: number;
41
+ };
42
+ /**
43
+ * Words as a two-channel byte texture of `width` × `height` (red = low byte, green = high byte), read with
44
+ * `texelFetch`. Row 0 of the words is row 0 of the texture. Missing words at the end are `NO_VALUE`.
45
+ */
46
+ export declare function wordTexture(words: Uint16Array, width: number, height: number): TextureData;
@@ -0,0 +1,102 @@
1
+ // Numbers as textures, for layers that show values over a scene: values quantised to 16-bit words (one word per grid
2
+ // cell, point or table row), the words as a two-byte texture, and colour ramps as a one-row texture. What the numbers
3
+ // mean is the caller's business; here they are a range from `min` to `max` and a word that says "no value".
4
+ /** The word that means "no value here". */
5
+ export const NO_VALUE = 0;
6
+ /** Largest word; the words 1–65535 span the value range linearly. */
7
+ export const VALUE_WORD_MAX = 65535;
8
+ /** Widest table texture: rows of a table wrap at this width. */
9
+ export const VALUE_TABLE_WIDTH = 1024;
10
+ const hex = (h) => [parseInt(h.slice(1, 3), 16) / 255, parseInt(h.slice(3, 5), 16) / 255, parseInt(h.slice(5, 7), 16) / 255];
11
+ const even = (colors) => colors.map((c, i) => ({ at: i / (colors.length - 1), color: hex(c) }));
12
+ /** Ready-made ramps. `diverging` has its neutral colour in the middle of the range. */
13
+ export const VALUE_RAMPS = {
14
+ viridis: even(['#440154', '#414487', '#2a788e', '#22a884', '#7ad151', '#fde725']),
15
+ heat: even(['#ffffcc', '#fed976', '#fd8d3c', '#e31a1c', '#800026']),
16
+ blues: even(['#f7fbff', '#9ecae1', '#4292c6', '#08519c', '#08306b']),
17
+ diverging: even(['#2166ac', '#92c5de', '#f7f7f7', '#f4a582', '#b2182b']),
18
+ grey: even(['#f2f2f2', '#262626']),
19
+ };
20
+ /**
21
+ * Colour of a ramp at position `t` (0–1). Stops are sorted by position here, so their order does not matter. With
22
+ * `bands` > 0 the ramp has that many flat steps, each in the colour of its middle.
23
+ */
24
+ export function rampColor(stops, t, bands = 0) {
25
+ if (stops.length === 0)
26
+ return [1, 0, 1];
27
+ const sorted = [...stops].sort((a, b) => a.at - b.at);
28
+ let u = Math.min(1, Math.max(0, t));
29
+ if (bands > 0)
30
+ u = (Math.min(bands - 1, Math.floor(u * bands)) + 0.5) / bands;
31
+ const first = sorted[0];
32
+ const last = sorted[sorted.length - 1];
33
+ if (u <= first.at)
34
+ return first.color;
35
+ if (u >= last.at)
36
+ return last.color;
37
+ for (let k = 1; k < sorted.length; k++) {
38
+ const hi = sorted[k];
39
+ if (u > hi.at)
40
+ continue;
41
+ const lo = sorted[k - 1];
42
+ const span = hi.at - lo.at;
43
+ const f = span > 0 ? (u - lo.at) / span : 0;
44
+ return [lo.color[0] + (hi.color[0] - lo.color[0]) * f, lo.color[1] + (hi.color[1] - lo.color[1]) * f, lo.color[2] + (hi.color[2] - lo.color[2]) * f];
45
+ }
46
+ return last.color;
47
+ }
48
+ /** A ramp as a 256 × 1 texture: texel k holds the colour at (k + 0.5) / 256. Smooth ramps filter linearly, banded ones not. */
49
+ export function colorRamp(stops, bands = 0) {
50
+ const data = new Uint8Array(256 * 4);
51
+ for (let k = 0; k < 256; k++) {
52
+ const c = rampColor(stops, (k + 0.5) / 256, bands);
53
+ data[k * 4] = Math.round(c[0] * 255);
54
+ data[k * 4 + 1] = Math.round(c[1] * 255);
55
+ data[k * 4 + 2] = Math.round(c[2] * 255);
56
+ data[k * 4 + 3] = 255;
57
+ }
58
+ return { width: 256, height: 1, format: 'rgba8', data, filter: bands > 0 ? 'nearest' : 'linear' };
59
+ }
60
+ /**
61
+ * Values as words: `min` becomes 1, `max` becomes 65535, values outside are clamped, and a value that is not a finite
62
+ * number becomes `NO_VALUE`. `out` is reused when it is long enough.
63
+ */
64
+ export function quantizeValues(values, min, max, out) {
65
+ const n = values.length;
66
+ const words = out && out.length >= n ? out : new Uint16Array(n);
67
+ const span = max - min;
68
+ const k = span > 0 ? (VALUE_WORD_MAX - 1) / span : 0;
69
+ for (let i = 0; i < n; i++) {
70
+ const v = values[i];
71
+ if (!Number.isFinite(v))
72
+ words[i] = NO_VALUE;
73
+ else
74
+ words[i] = 1 + Math.round(Math.min(VALUE_WORD_MAX - 1, Math.max(0, (v - min) * k)));
75
+ }
76
+ return words;
77
+ }
78
+ /** The value a word stands for, or NaN for `NO_VALUE`. */
79
+ export function wordValue(word, min, max) {
80
+ return word === NO_VALUE ? NaN : min + ((word - 1) / (VALUE_WORD_MAX - 1)) * (max - min);
81
+ }
82
+ /** Size of the table texture that holds `count` rows: rows fill it line by line and wrap at `VALUE_TABLE_WIDTH`. */
83
+ export function valueTableSize(count) {
84
+ const n = Math.max(1, count);
85
+ const width = Math.min(n, VALUE_TABLE_WIDTH);
86
+ return { width, height: Math.ceil(n / width) };
87
+ }
88
+ /**
89
+ * Words as a two-channel byte texture of `width` × `height` (red = low byte, green = high byte), read with
90
+ * `texelFetch`. Row 0 of the words is row 0 of the texture. Missing words at the end are `NO_VALUE`.
91
+ */
92
+ export function wordTexture(words, width, height) {
93
+ const cells = width * height;
94
+ const data = new Uint8Array(cells * 2);
95
+ const n = Math.min(cells, words.length);
96
+ for (let i = 0; i < n; i++) {
97
+ const w = words[i];
98
+ data[i * 2] = w & 255;
99
+ data[i * 2 + 1] = w >> 8;
100
+ }
101
+ return { width, height, format: 'rg8', data, filter: 'nearest' };
102
+ }
@@ -0,0 +1,20 @@
1
+ import type { EnvSlot } from '../base/index.ts';
2
+ /** How wind moves canopies. */
3
+ export interface SwayConfig {
4
+ /** Deflection of an ordinary tree's top in metres per 1 m/s of wind, and its cap. */
5
+ mPerMs: number;
6
+ maxM: number;
7
+ /** Canopy surface flutter as a share of the deflection. */
8
+ flutterShare: number;
9
+ }
10
+ export declare const DEFAULT_SWAY: SwayConfig;
11
+ export interface SwayState {
12
+ /** Top deflection of a tree with flexibility 1, and the flutter, in metres. */
13
+ swayM: number;
14
+ flutterM: number;
15
+ }
16
+ export declare function swayAt(windSpeedMs: number, p?: SwayConfig): SwayState;
17
+ /** How far a canopy with the given flexibility deflects horizontally at most. A check compares it with the gap at a wall. */
18
+ export declare function maxSway(windSpeedMs: number, flex?: number, p?: SwayConfig): number;
19
+ /** Sway slot: fills the free lanes of the engine's `u_wind` member. */
20
+ export declare function swaySlot(sway?: Partial<SwayConfig>): EnvSlot<SwayConfig, SwayState>;
@@ -0,0 +1,29 @@
1
+ // Environment slot of this module: how wind bends canopies. The app registers it with the engine
2
+ // (`assembleFrameBlock`); the shaders here read its lanes of `u_wind`. The season (`u_season`), which the vegetation
3
+ // shader reads as well, is a slot of gen-ground, so the ground does not depend on the vegetation.
4
+ export const DEFAULT_SWAY = { mPerMs: 0.075, maxM: 0.28, flutterShare: 0.2 };
5
+ /**
6
+ * Largest horizontal deflection as a multiple of the bend and the flutter. Follows from the formula in the vertex shader
7
+ * (bend with the wind, quarter bend across, flutter in three axes).
8
+ */
9
+ const SWAY_BOUND = 1.03;
10
+ const FLUTTER_BOUND = 1.46;
11
+ export function swayAt(windSpeedMs, p = DEFAULT_SWAY) {
12
+ const swayM = Math.min(p.maxM, Math.max(0, windSpeedMs) * p.mPerMs);
13
+ return { swayM, flutterM: swayM * p.flutterShare };
14
+ }
15
+ /** How far a canopy with the given flexibility deflects horizontally at most. A check compares it with the gap at a wall. */
16
+ export function maxSway(windSpeedMs, flex = 1, p = DEFAULT_SWAY) {
17
+ const { swayM, flutterM } = swayAt(windSpeedMs, p);
18
+ return flex * swayM * SWAY_BOUND + flutterM * FLUTTER_BOUND;
19
+ }
20
+ /** Sway slot: fills the free lanes of the engine's `u_wind` member. */
21
+ export function swaySlot(sway = {}) {
22
+ return {
23
+ name: 'sway',
24
+ params: { ...DEFAULT_SWAY, ...sway },
25
+ fields: [{ member: 'u_wind', lanes: 'zw', doc: 'z tree top deflection in metres, w foliage flutter in metres' }],
26
+ compute: (env, p) => swayAt(env.windSpeedMs, p),
27
+ lanes: (s) => [s.swayM, s.flutterM],
28
+ };
29
+ }
@@ -0,0 +1,8 @@
1
+ export { TREE_KINDS, TREE_MAX_FLEX, TREE_SPECIES, plantTrees, plantTreesSteps } from './planting.ts';
2
+ export type { CanopyRaster, PlantedTree, CrownRule, PlantingInput, PlantingRules, PlantingStats, StreetLine, TreeKind, TreeSpecies } from './planting.ts';
3
+ export { TREE_ATTRIBS, TREE_INSTANCE_BOUNDS, TREE_INSTANCE_FLOATS, TREE_INSTANCE_LAYOUT, TREE_LOD_COUNT, TREE_VERTEX_LAYOUT, buildTreeBatch, buildTreeBatches, packTreeInstances, treeBatchUniforms, } from './trees.ts';
4
+ export type { TreeBatch, TreeMaterial } from './trees.ts';
5
+ export { DEPTH_TREE_FS, DEPTH_TREE_VS, TREE_FS, TREE_VS } from './tree-shader.ts';
6
+ export { VEGETATION_MATERIAL, vegetationSieve, vegetationUniforms } from './materials.ts';
7
+ export { DEFAULT_SWAY, maxSway, swayAt, swaySlot } from './env-slots.ts';
8
+ export type { SwayConfig, SwayState } from './env-slots.ts';
@@ -0,0 +1,7 @@
1
+ // wallhammer-web/gen-vegetation: vegetation and its placement, the material that draws it and the sway slot (the
2
+ // season slot it reads is in gen-ground). Everything is plain data; the app uploads it through the engine.
3
+ export { TREE_KINDS, TREE_MAX_FLEX, TREE_SPECIES, plantTrees, plantTreesSteps } from './planting.js';
4
+ export { TREE_ATTRIBS, TREE_INSTANCE_BOUNDS, TREE_INSTANCE_FLOATS, TREE_INSTANCE_LAYOUT, TREE_LOD_COUNT, TREE_VERTEX_LAYOUT, buildTreeBatch, buildTreeBatches, packTreeInstances, treeBatchUniforms, } from './trees.js';
5
+ export { DEPTH_TREE_FS, DEPTH_TREE_VS, TREE_FS, TREE_VS } from './tree-shader.js';
6
+ export { VEGETATION_MATERIAL, vegetationSieve, vegetationUniforms } from './materials.js';
7
+ export { DEFAULT_SWAY, maxSway, swayAt, swaySlot } from './env-slots.js';