wallhammer-web 0.0.0-stage → 0.4.0

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 +88 -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,48 @@
1
+ import type { EnvSlot } from '../base/index.ts';
2
+ /**
3
+ * When broadleaf trees leaf out, change colour and shed, in days of the year. Defaults correspond to the Central European
4
+ * lowlands and uplands. Conifers do not change.
5
+ */
6
+ export interface PhenologyConfig {
7
+ /** Leaf-out: from when to when the canopy thickens. */
8
+ leafOutStart: number;
9
+ leafOutEnd: number;
10
+ /** Until when the foliage is fresh spring green. */
11
+ springEnd: number;
12
+ /** Colouring: start and peak. */
13
+ colorStart: number;
14
+ colorPeak: number;
15
+ /** Leaf fall: start and bare canopies. */
16
+ dropStart: number;
17
+ dropEnd: number;
18
+ /** Grass: when it turns green and when it starts to dry and brown. */
19
+ grassGreenStart: number;
20
+ grassGreenEnd: number;
21
+ grassBrownStart: number;
22
+ grassBrownEnd: number;
23
+ }
24
+ /** Vegetation state on one day of the year. Everything 0–1. */
25
+ export interface SeasonState {
26
+ /** Broadleaf foliage: 1 full canopies, 0 bare branches. */
27
+ leafDensity: number;
28
+ /** Autumn leaf colouring. */
29
+ autumn: number;
30
+ /** Fresh spring green. */
31
+ fresh: number;
32
+ /** Grass outside the growing season: faded and brownish. */
33
+ dormancy: number;
34
+ }
35
+ export declare const DEFAULT_PHENOLOGY: PhenologyConfig;
36
+ /** Vegetation state on a given day of the year (1–366). Pure function. */
37
+ export declare function seasonAt(dayOfYear: number, p?: PhenologyConfig): SeasonState;
38
+ /**
39
+ * Season slot: `u_season` from the day of year. Foliage density changes how much light passes through canopies, so it
40
+ * is part of the shadow key. Order 65 places the member between the engine's weather and fog colour members.
41
+ */
42
+ export declare function seasonSlot(phenology?: Partial<PhenologyConfig>): EnvSlot<PhenologyConfig, SeasonState>;
43
+ /**
44
+ * Snow slot: `snowOn`, how much snow lies on a surface. Only on upward-facing surfaces; the edge of the cover is
45
+ * irregular according to world-anchored noise. It has no Frame members of its own and reads the engine's snow cover.
46
+ * Shaders include it with `#include <snow>` after `lighting`.
47
+ */
48
+ export declare function snowSlot(): EnvSlot<null, null>;
@@ -0,0 +1,78 @@
1
+ // Environment slots of this module: the season of the year (`u_season`, foliage and grass) and where snow settles. The
2
+ // app registers them with the engine (`assembleFrameBlock`); the terrain shader reads the season member and includes
3
+ // the snow GLSL. The vegetation shader of gen-vegetation reads the same two slots; they live here so that the ground
4
+ // does not depend on the vegetation.
5
+ import { smoothstep } from '../base/index.js';
6
+ export const DEFAULT_PHENOLOGY = {
7
+ leafOutStart: 95,
8
+ leafOutEnd: 132,
9
+ springEnd: 165,
10
+ colorStart: 262,
11
+ colorPeak: 296,
12
+ dropStart: 288,
13
+ dropEnd: 322,
14
+ grassGreenStart: 72,
15
+ grassGreenEnd: 112,
16
+ grassBrownStart: 285,
17
+ grassBrownEnd: 335,
18
+ };
19
+ /** Vegetation state on a given day of the year (1–366). Pure function. */
20
+ export function seasonAt(dayOfYear, p = DEFAULT_PHENOLOGY) {
21
+ const d = dayOfYear;
22
+ const leafDensity = Math.min(smoothstep(p.leafOutStart, p.leafOutEnd, d), 1 - smoothstep(p.dropStart, p.dropEnd, d));
23
+ const autumn = d > (p.leafOutEnd + p.colorStart) / 2 ? smoothstep(p.colorStart, p.colorPeak, d) : 0;
24
+ const fresh = smoothstep(p.leafOutStart, p.leafOutEnd - 8, d) * (1 - smoothstep(p.leafOutEnd, p.springEnd, d));
25
+ const dormancy = Math.max(1 - smoothstep(p.grassGreenStart, p.grassGreenEnd, d), smoothstep(p.grassBrownStart, p.grassBrownEnd, d));
26
+ return { leafDensity, autumn, fresh, dormancy };
27
+ }
28
+ /**
29
+ * Season slot: `u_season` from the day of year. Foliage density changes how much light passes through canopies, so it
30
+ * is part of the shadow key. Order 65 places the member between the engine's weather and fog colour members.
31
+ */
32
+ export function seasonSlot(phenology = {}) {
33
+ return {
34
+ name: 'season',
35
+ params: { ...DEFAULT_PHENOLOGY, ...phenology },
36
+ fields: [{ member: 'u_season', order: 65, lanes: 'xyzw', doc: 'x broadleaf foliage, y autumn colour, z spring freshness, w grass outside the growing season' }],
37
+ compute: (env, p) => seasonAt(env.dayOfYear, p),
38
+ lanes: (s) => [s.leafDensity, s.autumn, s.fresh, s.dormancy],
39
+ shadowKey: (s) => s.leafDensity.toFixed(3),
40
+ };
41
+ }
42
+ /**
43
+ * Snow slot: `snowOn`, how much snow lies on a surface. Only on upward-facing surfaces; the edge of the cover is
44
+ * irregular according to world-anchored noise. It has no Frame members of its own and reads the engine's snow cover.
45
+ * Shaders include it with `#include <snow>` after `lighting`.
46
+ */
47
+ export function snowSlot() {
48
+ return {
49
+ name: 'snow',
50
+ params: null,
51
+ fields: [],
52
+ compute: () => null,
53
+ lanes: () => [],
54
+ glsl: SNOW_GLSL,
55
+ };
56
+ }
57
+ const SNOW_GLSL = /* glsl */ `
58
+ // How much snow lies on a surface with normal n: only on upward-facing surfaces, the edge of the cover is irregular
59
+ // according to world-anchored noise. bias shifts the threshold: positive = snow lies here longer (roof), negative = it
60
+ // vanishes sooner (road). Returns 0–1.
61
+ float snowOn(vec3 worldPos, vec3 n, float bias) {
62
+ float s = u_weather.x;
63
+ if (s <= 0.0) return 0.0;
64
+ #ifdef WH_LOCAL_UP
65
+ // Up is radial: "upward-facing" is measured against the local up, and the pattern is a field in space.
66
+ float up = smoothstep(0.45, 0.85, dot(n, localUp(worldPos)));
67
+ vec3 sp = worldPos - u_upCenter.xyz;
68
+ float patchN = 0.65 * vnoise3(sp / 7.0, 71u) + 0.35 * vnoise3(sp / 1.7, 72u);
69
+ #else
70
+ float up = smoothstep(0.45, 0.85, n.y);
71
+ float patchN = 0.65 * vnoise(worldPos.xz / 7.0, 71u) + 0.35 * vnoise(worldPos.xz / 1.7, 72u);
72
+ #endif
73
+ patchN = mix(0.5, patchN, 0.4 + 0.6 * detailVisible(1.7));
74
+ // Cover s goes from 0 (nothing) through patchy spots to 1 (everywhere).
75
+ float t = s * 1.25 + bias - 0.12;
76
+ return up * smoothstep(patchN - 0.12, patchN + 0.12, t);
77
+ }
78
+ `;
@@ -0,0 +1,78 @@
1
+ import type { BakeDesc, RGB } from '../base/index.ts';
2
+ /** Appearance of one surface class. */
3
+ export interface GroundMaterial {
4
+ /** Three tones (0–1, display space) between which the surface blends. */
5
+ colors: readonly [RGB, RGB, RGB];
6
+ /** Size of colour blobs in metres. */
7
+ patchM: number;
8
+ /** Strength of fine grain at close view, 0–1. */
9
+ grain: number;
10
+ /** Roadway: on the edge with another surface it gets a kerb. */
11
+ kerb?: boolean;
12
+ /** Width of mowing stripes in metres (sports lawn), 0 = no stripes. */
13
+ stripesM?: number;
14
+ /** Surface kind for seasons and weather. Without it the class counts as bare ground. */
15
+ surface?: GroundSurface;
16
+ }
17
+ /**
18
+ * vegetation: grass and greenery (changes colour with the season), paved: paving and hard surfaces (gets wet, snow disappears from it sooner),
19
+ * road: roadway (like paved, snow is cleared from it first), water: water.
20
+ */
21
+ export type GroundSurface = 'vegetation' | 'paved' | 'road' | 'water' | 'bare';
22
+ export interface GroundInput {
23
+ /** Class codes, one byte per pixel, rows from the north. */
24
+ codes: Uint8Array;
25
+ cols: number;
26
+ rows: number;
27
+ /** Pixel size of the class raster in metres. */
28
+ step: number;
29
+ /** Appearance by class code. A missing code gets `fallback`. */
30
+ materials: Map<number, GroundMaterial>;
31
+ fallback: GroundMaterial;
32
+ occlusion: OcclusionMask;
33
+ /** What the palette colours are multiplied by before light falls on them. */
34
+ albedoScale: number;
35
+ /**
36
+ * Lowered kerb: rectangles from a to b (local metres [x, z]) with a cross width. Inside, the kerb on the roadway edge
37
+ * is only hinted at and a paved area next to the roadway gets a warning strip (`warningStrip`). Useful for crossings,
38
+ * driveways, stops.
39
+ */
40
+ loweredKerbs?: readonly {
41
+ a: readonly [number, number];
42
+ b: readonly [number, number];
43
+ width: number;
44
+ }[];
45
+ /** Warning strip at a lowered kerb: colour and depth from the roadway edge in metres. Without it only an interrupted kerb. */
46
+ warningStrip?: {
47
+ color: RGB;
48
+ depthM: number;
49
+ };
50
+ }
51
+ /** Coarse shadow mask: R share of buildings, G share of canopies, both blurred. */
52
+ export interface OcclusionMask {
53
+ data: Uint8Array;
54
+ cols: number;
55
+ rows: number;
56
+ }
57
+ /**
58
+ * Describes the ground bake (run it with `renderer.bake`). Targets: `color` rgb colour with alpha the fine-grain
59
+ * strength; `surface` r vegetation, g paved area (0.6) or roadway (1), b canopy above ground, a water. Both with
60
+ * mipmaps, size same as the class raster.
61
+ */
62
+ export declare function groundBake(input: GroundInput, kerb: RGB): BakeDesc;
63
+ export interface OcclusionInput {
64
+ /** Surface class raster and which class is a building (array of 256 flags by code). */
65
+ codes: Uint8Array;
66
+ codeCols: number;
67
+ codeStep: number;
68
+ isBuilding: Uint8Array;
69
+ /** Canopy coverage 0–255 in a coarser grid in which the mask is computed. */
70
+ cover: Uint8Array;
71
+ cols: number;
72
+ rows: number;
73
+ step: number;
74
+ /** Blur radius in metres: how far from a house and a canopy the ground is still darker. */
75
+ blurM: number;
76
+ }
77
+ /** Ground shadow mask from the class raster and canopy coverage. */
78
+ export declare function buildOcclusionMask(input: OcclusionInput): OcclusionMask;
@@ -0,0 +1,208 @@
1
+ // Ground colour. At start, one texture with mipmaps is baked from the surface class raster and the palette:
2
+ // each class gets three tones from the palette, between which world-anchored noise blends,
3
+ // kerbs on the roadway edge and darkening near houses and under canopies. No image is loaded.
4
+ // Next to the colour a second texture with the surface kind is baked (vegetation, paved area and roadway, canopy above ground, water),
5
+ // from which the terrain shader draws seasons and weather: snow, wetness, puddles, faded grass.
6
+ import { boxBlur } from '../gen-tex/index.js';
7
+ /** Kerb width in metres. */
8
+ const KERB_WIDTH_M = 0.3;
9
+ /** How much the ground darkens right next to a house and under a dense canopy. */
10
+ const BUILDING_AO = 0.42;
11
+ const CANOPY_AO = 0.38;
12
+ const LUT_SIZE = 64;
13
+ const BAKE_FS = /* glsl */ `#include <header>
14
+ #include <noise>
15
+ uniform usampler2D u_classes;
16
+ uniform sampler2D u_lut;
17
+ uniform sampler2D u_occlusion;
18
+ uniform float u_step;
19
+ uniform vec2 u_worldSize;
20
+ uniform vec3 u_kerbColor;
21
+ uniform float u_albedoScale;
22
+ uniform sampler2D u_lowered;
23
+ uniform vec3 u_warnColor;
24
+ uniform float u_warnDepth;
25
+ layout(location = 0) out vec4 o_color;
26
+ layout(location = 1) out vec4 o_surface;
27
+
28
+ bool isRoad(ivec2 p) {
29
+ ivec2 q = clamp(p, ivec2(0), textureSize(u_classes, 0) - 1);
30
+ return texelFetch(u_lut, ivec2(int(texelFetch(u_classes, q, 0).r), 3), 0).b > 0.5;
31
+ }
32
+
33
+ void main() {
34
+ ivec2 px = ivec2(gl_FragCoord.xy);
35
+ int c = int(texelFetch(u_classes, px, 0).r);
36
+ vec2 w = (vec2(px) + 0.5) * u_step;
37
+ vec3 c0 = texelFetch(u_lut, ivec2(c, 0), 0).rgb;
38
+ vec3 c1 = texelFetch(u_lut, ivec2(c, 1), 0).rgb;
39
+ vec3 c2 = texelFetch(u_lut, ivec2(c, 2), 0).rgb;
40
+ vec4 prm = texelFetch(u_lut, ivec2(c, 3), 0);
41
+ vec4 kind = texelFetch(u_lut, ivec2(c, 4), 0);
42
+ float patchM = prm.r * 64.0;
43
+ float stripes = prm.a * 64.0;
44
+
45
+ // Blobs at three scales, anchored in the world.
46
+ uint seed = uint(c) * 7919u;
47
+ float n = 0.55 * vnoise(w / patchM, seed) + 0.30 * vnoise(w / (patchM * 0.31), seed + 1u) + 0.15 * vnoise(w / (patchM * 0.09), seed + 2u);
48
+ n = smoothstep(0.22, 0.78, n);
49
+ vec3 col = n < 0.5 ? mix(c0, c1, n * 2.0) : mix(c1, c2, n * 2.0 - 1.0);
50
+ // Slow brightness drift across whole areas, common to all classes.
51
+ col *= 0.93 + 0.14 * vnoise(w / 46.0, 99u);
52
+
53
+ if (stripes > 0.0) {
54
+ float s = step(0.5, fract(w.x / (stripes * 2.0)));
55
+ col *= 0.95 + 0.1 * s;
56
+ }
57
+
58
+ if (prm.b > 0.5) {
59
+ // Kerb: a roadway that has a different surface within the kerb width.
60
+ int r = int(ceil(${KERB_WIDTH_M.toFixed(2)} / u_step));
61
+ bool edge = false;
62
+ for (int j = -r; j <= r && !edge; j++) {
63
+ for (int i = -r; i <= r; i++) {
64
+ if (i * i + j * j > r * r) continue;
65
+ if (!isRoad(px + ivec2(i, j))) { edge = true; break; }
66
+ }
67
+ }
68
+ if (edge) {
69
+ // The lowered kerb is sunk into the roadway plane: only a faint line of stone remains of the kerb.
70
+ bool lowered = texelFetch(u_lowered, px, 0).r > 0.5;
71
+ col = mix(col, u_kerbColor, lowered ? 0.2 : 0.7);
72
+ kind = vec4(0.0, 0.6, 0.0, 0.0);
73
+ }
74
+ } else if (u_warnDepth > 0.0 && kind.g > 0.3 && texelFetch(u_lowered, px, 0).r > 0.5) {
75
+ // Warning strip: paved area right next to the roadway where the kerb is lowered.
76
+ int r = int(ceil(u_warnDepth / u_step));
77
+ bool near = false;
78
+ for (int j = -r; j <= r && !near; j++) {
79
+ for (int i = -r; i <= r; i++) {
80
+ if (i * i + j * j > r * r) continue;
81
+ if (isRoad(px + ivec2(i, j))) { near = true; break; }
82
+ }
83
+ }
84
+ if (near) {
85
+ // Coarse tile jointing, anchored in the world.
86
+ float tile = 0.92 + 0.08 * step(0.5, fract(w.x / 0.4 + 0.5 * step(0.5, fract(w.y / 0.4))));
87
+ col = u_warnColor * tile;
88
+ }
89
+ }
90
+
91
+ vec2 occ = texture(u_occlusion, w / u_worldSize).rg;
92
+ col *= 1.0 - ${BUILDING_AO.toFixed(2)} * smoothstep(0.02, 0.55, occ.r);
93
+ col *= 1.0 - ${CANOPY_AO.toFixed(2)} * smoothstep(0.05, 0.9, occ.g);
94
+ o_color = vec4(col * u_albedoScale, prm.g);
95
+ o_surface = vec4(kind.r, kind.g, smoothstep(0.1, 0.8, occ.g), kind.a);
96
+ }`;
97
+ /**
98
+ * Describes the ground bake (run it with `renderer.bake`). Targets: `color` rgb colour with alpha the fine-grain
99
+ * strength; `surface` r vegetation, g paved area (0.6) or roadway (1), b canopy above ground, a water. Both with
100
+ * mipmaps, size same as the class raster.
101
+ */
102
+ export function groundBake(input, kerb) {
103
+ const { cols, rows } = input;
104
+ const classes = { width: cols, height: rows, format: 'r8ui', data: input.codes };
105
+ const lut = new Uint8Array(LUT_SIZE * 5 * 4);
106
+ for (let code = 0; code < LUT_SIZE; code++) {
107
+ const m = input.materials.get(code) ?? input.fallback;
108
+ m.colors.forEach((c, row) => {
109
+ const o = (row * LUT_SIZE + code) * 4;
110
+ lut[o] = Math.round(c[0] * 255);
111
+ lut[o + 1] = Math.round(c[1] * 255);
112
+ lut[o + 2] = Math.round(c[2] * 255);
113
+ lut[o + 3] = 255;
114
+ });
115
+ const o = (3 * LUT_SIZE + code) * 4;
116
+ lut[o] = Math.round((Math.min(m.patchM, 64) / 64) * 255);
117
+ lut[o + 1] = Math.round(m.grain * 255);
118
+ lut[o + 2] = m.kerb ? 255 : 0;
119
+ lut[o + 3] = Math.round((Math.min(m.stripesM ?? 0, 64) / 64) * 255);
120
+ const k = (4 * LUT_SIZE + code) * 4;
121
+ lut[k] = m.surface === 'vegetation' ? 255 : 0;
122
+ // Paved areas 0.6, roadways 1: the shader tells both apart from this.
123
+ lut[k + 1] = m.surface === 'road' ? 255 : m.surface === 'paved' ? 153 : 0;
124
+ lut[k + 3] = m.surface === 'water' ? 255 : 0;
125
+ }
126
+ const lutTex = { width: LUT_SIZE, height: 5, format: 'rgba8', data: lut };
127
+ // Lowered-kerb mask at the class raster resolution.
128
+ const lowered = new Uint8Array(cols * rows);
129
+ for (const k of input.loweredKerbs ?? []) {
130
+ const dx = k.b[0] - k.a[0];
131
+ const dz = k.b[1] - k.a[1];
132
+ const len = Math.hypot(dx, dz);
133
+ if (len < 1e-3)
134
+ continue;
135
+ const ux = dx / len;
136
+ const uz = dz / len;
137
+ const hw = k.width / 2;
138
+ const xs = [k.a[0] - uz * hw, k.a[0] + uz * hw, k.b[0] - uz * hw, k.b[0] + uz * hw];
139
+ const zs = [k.a[1] + ux * hw, k.a[1] - ux * hw, k.b[1] + ux * hw, k.b[1] - ux * hw];
140
+ const c0 = Math.max(0, Math.floor(Math.min(...xs) / input.step));
141
+ const c1 = Math.min(cols - 1, Math.floor(Math.max(...xs) / input.step));
142
+ const r0 = Math.max(0, Math.floor(Math.min(...zs) / input.step));
143
+ const r1 = Math.min(rows - 1, Math.floor(Math.max(...zs) / input.step));
144
+ for (let r = r0; r <= r1; r++) {
145
+ for (let c = c0; c <= c1; c++) {
146
+ const px = (c + 0.5) * input.step - k.a[0];
147
+ const pz = (r + 0.5) * input.step - k.a[1];
148
+ const u = px * ux + pz * uz;
149
+ const v = -px * uz + pz * ux;
150
+ if (u >= 0 && u <= len && Math.abs(v) <= hw)
151
+ lowered[r * cols + c] = 255;
152
+ }
153
+ }
154
+ }
155
+ // Texture rows go from the north, same as the class raster.
156
+ const loweredTex = { width: cols, height: rows, format: 'r8', data: lowered };
157
+ const occTex = { width: input.occlusion.cols, height: input.occlusion.rows, format: 'rg8', data: input.occlusion.data, filter: 'linear' };
158
+ const target = { format: 'rgba8', filter: 'mipmap', anisotropy: 4 };
159
+ return {
160
+ name: 'ground bake',
161
+ width: cols,
162
+ height: rows,
163
+ fs: BAKE_FS,
164
+ inputs: [
165
+ { sampler: 'u_classes', texture: classes },
166
+ { sampler: 'u_lut', texture: lutTex },
167
+ { sampler: 'u_occlusion', texture: occTex },
168
+ { sampler: 'u_lowered', texture: loweredTex },
169
+ ],
170
+ uniforms: {
171
+ u_step: { float: input.step },
172
+ u_worldSize: { vec2: [cols * input.step, rows * input.step] },
173
+ u_kerbColor: { vec3: kerb },
174
+ u_albedoScale: { float: input.albedoScale },
175
+ u_warnColor: { vec3: input.warningStrip ? input.warningStrip.color : [0, 0, 0] },
176
+ u_warnDepth: { float: input.warningStrip?.depthM ?? 0 },
177
+ },
178
+ targets: [target, target],
179
+ };
180
+ }
181
+ /** Ground shadow mask from the class raster and canopy coverage. */
182
+ export function buildOcclusionMask(input) {
183
+ const { codes, codeCols, isBuilding, cover, cols, rows, step } = input;
184
+ const per = Math.round(step / input.codeStep);
185
+ const b = new Float32Array(cols * rows);
186
+ const c = new Float32Array(cols * rows);
187
+ for (let j = 0; j < rows; j++) {
188
+ for (let i = 0; i < cols; i++) {
189
+ let n = 0;
190
+ for (let r = j * per; r < (j + 1) * per; r++) {
191
+ const row = r * codeCols;
192
+ for (let q = i * per; q < (i + 1) * per; q++)
193
+ n += isBuilding[codes[row + q]];
194
+ }
195
+ b[j * cols + i] = n / (per * per);
196
+ c[j * cols + i] = cover[j * cols + i] / 255;
197
+ }
198
+ }
199
+ const radius = Math.max(1, Math.round(input.blurM / step));
200
+ const bb = boxBlur(b, cols, rows, radius);
201
+ const cb = boxBlur(c, cols, rows, radius);
202
+ const out = new Uint8Array(cols * rows * 2);
203
+ for (let k = 0; k < cols * rows; k++) {
204
+ out[k * 2] = Math.round(Math.min(1, bb[k]) * 255);
205
+ out[k * 2 + 1] = Math.round(Math.min(1, cb[k]) * 255);
206
+ }
207
+ return { data: out, cols, rows };
208
+ }
@@ -0,0 +1,9 @@
1
+ export { buildOcclusionMask, groundBake } from './ground.ts';
2
+ export type { GroundInput, GroundMaterial, GroundSurface, OcclusionInput, OcclusionMask } from './ground.ts';
3
+ export { MARKING_ATTRIBS, MARKING_LAYOUT, buildGroundMarkings } from './markings.ts';
4
+ export type { GroundMarking, MarkingPattern } from './markings.ts';
5
+ export { MARKING_FS, MARKING_VS, TERRAIN_FS, TERRAIN_VS } from './terrain-shader.ts';
6
+ export { GROUND_SAMPLERS, MARKING_MATERIAL, TERRAIN_MATERIAL, groundUniforms } from './materials.ts';
7
+ export type { GroundShading } from './materials.ts';
8
+ export { DEFAULT_PHENOLOGY, seasonAt, seasonSlot, snowSlot } from './env-slots.ts';
9
+ export type { PhenologyConfig, SeasonState } from './env-slots.ts';
@@ -0,0 +1,7 @@
1
+ // wallhammer-web/gen-ground: ground from surface classes, markings on the surface, the materials that draw them and the
2
+ // season and snow slots. Everything is plain data; the app uploads it through the engine.
3
+ export { buildOcclusionMask, groundBake } from './ground.js';
4
+ export { MARKING_ATTRIBS, MARKING_LAYOUT, buildGroundMarkings } from './markings.js';
5
+ export { MARKING_FS, MARKING_VS, TERRAIN_FS, TERRAIN_VS } from './terrain-shader.js';
6
+ export { GROUND_SAMPLERS, MARKING_MATERIAL, TERRAIN_MATERIAL, groundUniforms } from './materials.js';
7
+ export { DEFAULT_PHENOLOGY, seasonAt, seasonSlot, snowSlot } from './env-slots.js';
@@ -0,0 +1,46 @@
1
+ import type { MeshData, RGB, VertexLayout } from '../base/index.ts';
2
+ import type { HeightField } from '../gen-core/index.ts';
3
+ export declare const MARKING_ATTRIBS: {
4
+ readonly a_pos: 0;
5
+ readonly a_normal: 1;
6
+ readonly a_uv: 2;
7
+ readonly a_size: 3;
8
+ readonly a_paint: 4;
9
+ readonly a_pattern: 5;
10
+ };
11
+ /** Vertex layout of the marking mesh. */
12
+ export declare const MARKING_LAYOUT: VertexLayout;
13
+ /**
14
+ * Pattern inside the rectangle.
15
+ * - solid: full area (arrow, parking space area).
16
+ * - stripes: stripes across the axis, repeated along it with period `periodM`; the colour takes `duty` of the period from its
17
+ * start. A zebra crossing is an axis across the road and 0.5/0.5 m stripes, a dashed line is an axis along the road and a long period.
18
+ * - outline: only an outline with line width `lineM` (parking space).
19
+ */
20
+ export type MarkingPattern = {
21
+ kind: 'solid';
22
+ } | {
23
+ kind: 'stripes';
24
+ periodM: number;
25
+ duty: number;
26
+ } | {
27
+ kind: 'outline';
28
+ lineM: number;
29
+ };
30
+ /** One marking shape: a rectangle from point a to point b (local metres [x, z]) with a cross width. */
31
+ export interface GroundMarking {
32
+ a: readonly [number, number];
33
+ b: readonly [number, number];
34
+ width: number;
35
+ pattern: MarkingPattern;
36
+ /** Paint colour, 0–1 in display space. */
37
+ color: RGB;
38
+ /** Wear 0–1: how much paint is worn off. */
39
+ wear?: number;
40
+ }
41
+ /**
42
+ * Builds the marking mesh above the terrain. Each shape gets the terrain cells that cover it, with the same vertices
43
+ * and normals as the terrain mesh (hence no offset above the surface). `albedoScale` as for the ground colour.
44
+ * Returns null when there is nothing to draw.
45
+ */
46
+ export declare function buildGroundMarkings(terrain: HeightField, marks: readonly GroundMarking[], albedoScale?: number): MeshData | null;
@@ -0,0 +1,124 @@
1
+ // Horizontal markings on the ground: crossings, later lane lines and parking spaces.
2
+ // The app passes shapes (a rectangle along an axis with a pattern and colour) and the core builds a mesh from them that follows
3
+ // the terrain cells. It is drawn with the same shader as the ground, so markings get the same light, shadow, snow,
4
+ // wetness and fog. Edges and stripes are smoothed by the pixel footprint: sharp up close, blending into the average from afar.
5
+ export const MARKING_ATTRIBS = { a_pos: 0, a_normal: 1, a_uv: 2, a_size: 3, a_paint: 4, a_pattern: 5 };
6
+ /** Vertex layout of the marking mesh. */
7
+ export const MARKING_LAYOUT = {
8
+ stride: 68,
9
+ attribs: [
10
+ { name: 'a_pos', size: 3, type: 'f32', offset: 0 },
11
+ { name: 'a_normal', size: 4, type: 'i16', offset: 12 },
12
+ { name: 'a_uv', size: 2, type: 'f32', offset: 20 },
13
+ { name: 'a_size', size: 4, type: 'f32', offset: 28 },
14
+ { name: 'a_paint', size: 4, type: 'f32', offset: 44 },
15
+ { name: 'a_pattern', size: 2, type: 'f32', offset: 60 },
16
+ ],
17
+ };
18
+ const STRIDE = 68;
19
+ const PATTERN_CODE = { solid: 0, stripes: 1, outline: 2 };
20
+ /**
21
+ * Builds the marking mesh above the terrain. Each shape gets the terrain cells that cover it, with the same vertices
22
+ * and normals as the terrain mesh (hence no offset above the surface). `albedoScale` as for the ground colour.
23
+ * Returns null when there is nothing to draw.
24
+ */
25
+ export function buildGroundMarkings(terrain, marks, albedoScale = 1) {
26
+ const { step, cols, rows, heights } = terrain;
27
+ const cells = [];
28
+ marks.forEach((mk, m) => {
29
+ const dx = mk.b[0] - mk.a[0];
30
+ const dz = mk.b[1] - mk.a[1];
31
+ const len = Math.hypot(dx, dz);
32
+ if (len < 1e-3 || mk.width <= 0)
33
+ return;
34
+ const ux = dx / len;
35
+ const uz = dz / len;
36
+ const hw = mk.width / 2;
37
+ const corners = [
38
+ [mk.a[0] - uz * hw, mk.a[1] + ux * hw],
39
+ [mk.a[0] + uz * hw, mk.a[1] - ux * hw],
40
+ [mk.b[0] - uz * hw, mk.b[1] + ux * hw],
41
+ [mk.b[0] + uz * hw, mk.b[1] - ux * hw],
42
+ ];
43
+ const i0 = Math.max(0, Math.floor(Math.min(...corners.map((c) => c[0])) / step));
44
+ const i1 = Math.min(cols - 2, Math.floor(Math.max(...corners.map((c) => c[0])) / step));
45
+ const j0 = Math.max(0, Math.floor(Math.min(...corners.map((c) => c[1])) / step));
46
+ const j1 = Math.min(rows - 2, Math.floor(Math.max(...corners.map((c) => c[1])) / step));
47
+ const reach = step * Math.SQRT1_2;
48
+ for (let j = j0; j <= j1; j++) {
49
+ for (let i = i0; i <= i1; i++) {
50
+ // A cell whose centre is farther from the rectangle than half a diagonal cannot touch it.
51
+ const cx = (i + 0.5) * step - mk.a[0];
52
+ const cz = (j + 0.5) * step - mk.a[1];
53
+ const u = cx * ux + cz * uz;
54
+ const v = -cx * uz + cz * ux;
55
+ if (u < -reach || u > len + reach || Math.abs(v) > hw + reach)
56
+ continue;
57
+ cells.push({ i, j, m });
58
+ }
59
+ }
60
+ });
61
+ if (cells.length === 0)
62
+ return null;
63
+ const buf = new ArrayBuffer(cells.length * 6 * STRIDE);
64
+ const view = new DataView(buf);
65
+ let o = 0;
66
+ const normals = new Map();
67
+ const normalAt = (i, j) => {
68
+ const k = j * cols + i;
69
+ let n = normals.get(k);
70
+ if (!n) {
71
+ n = terrain.vertexNormal(i, j);
72
+ normals.set(k, n);
73
+ }
74
+ return n;
75
+ };
76
+ for (const { i, j, m } of cells) {
77
+ const mk = marks[m];
78
+ const len = Math.hypot(mk.b[0] - mk.a[0], mk.b[1] - mk.a[1]);
79
+ const ux = (mk.b[0] - mk.a[0]) / len;
80
+ const uz = (mk.b[1] - mk.a[1]) / len;
81
+ const col = mk.color;
82
+ const p = mk.pattern;
83
+ const period = p.kind === 'stripes' ? p.periodM : 1;
84
+ const duty = p.kind === 'stripes' ? p.duty : 1;
85
+ const line = p.kind === 'outline' ? p.lineM : 0;
86
+ // The same diagonal split of a cell as in the terrain mesh: (a, c, b) and (b, c, d).
87
+ const corner = [
88
+ [i, j],
89
+ [i, j + 1],
90
+ [i + 1, j],
91
+ [i + 1, j],
92
+ [i, j + 1],
93
+ [i + 1, j + 1],
94
+ ];
95
+ for (const [ci, cj] of corner) {
96
+ const x = ci * step;
97
+ const z = cj * step;
98
+ const n = normalAt(ci, cj);
99
+ view.setFloat32(o, x, true);
100
+ view.setFloat32(o + 4, heights[cj * cols + ci], true);
101
+ view.setFloat32(o + 8, z, true);
102
+ view.setInt16(o + 12, Math.round(n[0] * 32767), true);
103
+ view.setInt16(o + 14, Math.round(n[1] * 32767), true);
104
+ view.setInt16(o + 16, Math.round(n[2] * 32767), true);
105
+ view.setInt16(o + 18, 0, true);
106
+ const rx = x - mk.a[0];
107
+ const rz = z - mk.a[1];
108
+ view.setFloat32(o + 20, rx * ux + rz * uz, true);
109
+ view.setFloat32(o + 24, -rx * uz + rz * ux, true);
110
+ view.setFloat32(o + 28, len, true);
111
+ view.setFloat32(o + 32, mk.width, true);
112
+ view.setFloat32(o + 36, period, true);
113
+ view.setFloat32(o + 40, duty, true);
114
+ view.setFloat32(o + 44, col[0] * albedoScale, true);
115
+ view.setFloat32(o + 48, col[1] * albedoScale, true);
116
+ view.setFloat32(o + 52, col[2] * albedoScale, true);
117
+ view.setFloat32(o + 56, mk.wear ?? 0, true);
118
+ view.setFloat32(o + 60, PATTERN_CODE[p.kind], true);
119
+ view.setFloat32(o + 64, line, true);
120
+ o += STRIDE;
121
+ }
122
+ }
123
+ return { layout: MARKING_LAYOUT, vertices: new Uint8Array(buf), indices: null, count: cells.length * 6 };
124
+ }
@@ -0,0 +1,18 @@
1
+ import type { MaterialDesc, RGB, Uniforms } from '../base/index.ts';
2
+ /** The terrain mesh (`heightFieldMesh`) with the baked ground texture. Colour pass only, it casts no shadows. */
3
+ export declare const TERRAIN_MATERIAL: MaterialDesc;
4
+ /** Markings drawn over the terrain triangles with the same depth: paint over the ground by its coverage, the target alpha stays. */
5
+ export declare const MARKING_MATERIAL: MaterialDesc;
6
+ /** Samplers of the terrain and marking materials, in binding order. */
7
+ export declare const GROUND_SAMPLERS: readonly ['u_ground', 'u_surface'];
8
+ /** What the terrain and marking materials read besides the samplers. */
9
+ export interface GroundShading {
10
+ /** Extent of the ground texture in metres. */
11
+ sizeX: number;
12
+ sizeZ: number;
13
+ /** Highest terrain point. */
14
+ topY: number;
15
+ /** Colour of the side skirt. */
16
+ skirt: RGB;
17
+ }
18
+ export declare function groundUniforms(g: GroundShading): Uniforms;
@@ -0,0 +1,22 @@
1
+ // Materials of the ground and the markings, as plain descriptions for the renderer.
2
+ import { HEIGHT_FIELD_ATTRIBS } from '../gen-mesh/index.js';
3
+ import { MARKING_ATTRIBS } from './markings.js';
4
+ import { MARKING_FS, MARKING_VS, TERRAIN_FS, TERRAIN_VS } from './terrain-shader.js';
5
+ /** The terrain mesh (`heightFieldMesh`) with the baked ground texture. Colour pass only, it casts no shadows. */
6
+ export const TERRAIN_MATERIAL = {
7
+ name: 'terrain',
8
+ attribs: HEIGHT_FIELD_ATTRIBS,
9
+ passes: { color: { vs: TERRAIN_VS, fs: TERRAIN_FS } },
10
+ };
11
+ /** Markings drawn over the terrain triangles with the same depth: paint over the ground by its coverage, the target alpha stays. */
12
+ export const MARKING_MATERIAL = {
13
+ name: 'markings',
14
+ attribs: MARKING_ATTRIBS,
15
+ passes: { color: { vs: MARKING_VS, fs: MARKING_FS } },
16
+ state: { color: { blend: { src: 'src-alpha', dst: 'one-minus-src-alpha', srcAlpha: 'zero', dstAlpha: 'one' }, depthFunc: 'lequal', depthWrite: false } },
17
+ };
18
+ /** Samplers of the terrain and marking materials, in binding order. */
19
+ export const GROUND_SAMPLERS = ['u_ground', 'u_surface'];
20
+ export function groundUniforms(g) {
21
+ return { u_invWorldSize: { vec2: [1 / g.sizeX, 1 / g.sizeZ] }, u_earth: { vec3: g.skirt }, u_topY: { float: g.topY } };
22
+ }
@@ -0,0 +1,5 @@
1
+ export declare const TERRAIN_VS = "#include <header>\ninvariant gl_Position;\nin vec3 a_pos;\nin vec4 a_normal;\nout vec3 v_world;\nout vec3 v_normal;\nflat out float v_kind;\nvoid main() {\n v_world = a_pos;\n v_normal = a_normal.xyz;\n v_kind = a_normal.w;\n gl_Position = u_viewProj * vec4(a_pos, 1.0);\n}";
2
+ /** Marking vertices: position and normal as terrain, plus coordinates in the shape and its parameters. */
3
+ export declare const MARKING_VS = "#include <header>\ninvariant gl_Position;\nin vec3 a_pos;\nin vec4 a_normal;\nin vec2 a_uv;\nin vec4 a_size;\nin vec4 a_paint;\nin vec2 a_pattern;\nout vec3 v_world;\nout vec3 v_normal;\nout vec2 v_uv;\nflat out vec4 v_size;\nflat out vec4 v_paint;\nflat out vec2 v_pattern;\nvoid main() {\n v_world = a_pos;\n v_normal = a_normal.xyz;\n v_uv = a_uv;\n v_size = a_size;\n v_paint = a_paint;\n v_pattern = a_pattern;\n gl_Position = u_viewProj * vec4(a_pos, 1.0);\n}";
4
+ export declare const TERRAIN_FS: string;
5
+ export declare const MARKING_FS: string;