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,447 @@
1
+ import type { RGB, Vec3 } from '../base/math.ts';
2
+ import type { CullVolume, DepthMode, View } from '../base/view.ts';
3
+ import type { InstanceBounds, InstanceData, MeshData, TextureData } from '../base/data.ts';
4
+ import type { BakeDesc, DrawState, MaterialDesc, PassName, Uniforms } from '../base/material.ts';
5
+ import type { Device, InstanceBuffer, MainSamples, Mesh, Program, Texture } from '../gpu/index.ts';
6
+ import type { RadialUp } from '../base/up.ts';
7
+ import type { FrameSlotSizes, FrameSlotsGlsl } from './glsl.ts';
8
+ export type { InstanceBounds, PassName };
9
+ /** Texture unit that holds the shadow map during the `color` and `data` passes. */
10
+ export declare const SHADOW_MAP_UNIT = 0;
11
+ export interface DrawContext {
12
+ readonly device: Device;
13
+ readonly pass: PassName;
14
+ readonly view: View;
15
+ /** World → light clip matrix of the shadow pass. Depth programs read it as `u_lightRender`. */
16
+ readonly lightRender: Float32Array;
17
+ /** Records one draw call with this many triangles in the frame statistics. */
18
+ count(triangles: number): void;
19
+ }
20
+ export interface Layer {
21
+ /** Optional name for profiles and statistics (`profileFrame` in `tools`). Nothing else reads it. */
22
+ name?: string;
23
+ /**
24
+ * `'dynamic'`: this layer's shadow casters move; they are redrawn over the kept static shadow map. Default
25
+ * `'static'`. With at least one dynamic layer the shadow mode `'single'` keeps a second depth map with the static
26
+ * casters only and, in a frame where a dynamic layer reports `shadowDirty`, copies it into the map that is sampled
27
+ * and draws only the dynamic layers over it. Around that draw a dynamic layer's `cull` is called with the light's
28
+ * volume and then with the view's, as at a refit. The other shadow modes redraw the whole map instead.
29
+ */
30
+ shadowCasters?: 'static' | 'dynamic';
31
+ /**
32
+ * Dynamic layers only: asked once per frame; true when what the layer casts changed since it was last drawn into the
33
+ * shadow map. The application never needs `invalidateShadows` for such a layer.
34
+ */
35
+ shadowDirty?(): boolean;
36
+ /** Draws whatever this layer has for `ctx.pass`. The pass base state is set before and restored after. */
37
+ draw(ctx: DrawContext): void;
38
+ /**
39
+ * Called when the shadow map is refitted: first with the light's volume (`'shadow'`) right before the shadow pass,
40
+ * then with the view's volume (`'view'`) for the passes that follow. Returns how many instances were kept.
41
+ * `view` is the view of the frame (for choices by distance or pixel size).
42
+ */
43
+ cull?(volume: CullVolume, purpose: 'shadow' | 'view', view: View): number;
44
+ /**
45
+ * Optional. True when the layer's culled sets are out of date (something was added or removed since the last
46
+ * `cull`). The renderer then refits the shadow map and culls every layer again in the same frame.
47
+ */
48
+ cullStale?(): boolean;
49
+ /**
50
+ * Optional. Called once in every frame that draws the scene, after the Frame block of the frame is uploaded and
51
+ * before the first pass: the place to draw into the layer's own targets (`Device.fill`), so that no pass is
52
+ * interrupted for it. Programs used here see the Frame block of this frame.
53
+ */
54
+ prepare?(device: Device, view: View): void;
55
+ }
56
+ /**
57
+ * Hooks for measuring frames (`Renderer.probe`, used by `profileFrame` in `tools`). Unset in normal use; then the
58
+ * renderer calls nothing of it and does no extra work.
59
+ */
60
+ export interface RenderProbe {
61
+ /**
62
+ * Asked for every layer before its `draw` in a pass, and before its `prepare` (`'prepare'`). False leaves the layer
63
+ * out of that call in this frame. Culling is not affected.
64
+ */
65
+ draws?(layer: Layer, pass: PassName | 'prepare'): boolean;
66
+ /** Called after every `draw` of a layer with the triangles and calls it counted in that pass. */
67
+ drawn?(layer: Layer, pass: PassName, triangles: number, calls: number): void;
68
+ }
69
+ /**
70
+ * How the shadow map is laid out.
71
+ * - `'single'` (default): one map fitted to what the view sees, redrawn whenever the view changes.
72
+ * - `'snapped'`: one map over a square of the light's plane around the centre of the view, fixed to the world's texel
73
+ * grid. It is kept between frames: nothing is drawn while neither the light nor the scene changes, and a pan
74
+ * draws only the border it uncovers. Its size follows the scale of the view up to `reachM`. For views from above
75
+ * over a large scene.
76
+ * - `'cascades'`: several maps around the eye, each reaching farther and coarser than the one before, blended into
77
+ * each other. Sharp shadows near the eye and shadows kilometres away in one perspective view; each map is kept
78
+ * until the eye has moved a sixteenth of its edge.
79
+ * In the last two modes the light may stand straight above, and beyond the reach the lookup falls back to
80
+ * `sunVisibilityBaked`'s term and to `Renderer.shadowHorizon`.
81
+ */
82
+ export type ShadowMode = 'single' | 'snapped' | 'cascades';
83
+ /** Settings of the shadow modes other than `'single'`. */
84
+ export interface ShadowOptions {
85
+ /** Default `'single'`: the renderer behaves exactly as without this object. */
86
+ mode?: ShadowMode;
87
+ /**
88
+ * How far from the focus (the centre of the view; the eye in `'cascades'` with a perspective view) the maps reach,
89
+ * metres. `'snapped'`: the largest reach the map grows to when the view zooms out, default 2048 (never less than
90
+ * the reach of the finest map, which the softness and the map size give). `'cascades'`: the reach of the last
91
+ * map, default `shadowDistanceM` when that is set, else 4000.
92
+ */
93
+ reachM?: number;
94
+ /** `'cascades'`: number of maps, 2–4. Default 4. They share the shadow map, each a quarter of it. */
95
+ cascades?: number;
96
+ /** `'cascades'`: reach of the first map, metres. Default 48. The others follow in equal ratios up to `reachM`. */
97
+ firstReachM?: number;
98
+ }
99
+ /**
100
+ * The light horizon of the scene, the far term of the shadow modes `'snapped'` and `'cascades'`: a texture over a
101
+ * rectangle of the x–z plane that holds, per texel, the height below which a point is hidden from the light
102
+ * (`lightHorizon` and `horizonTexture` in `gen-tex` make one). Positions are in world coordinates (the renderer
103
+ * subtracts `worldOrigin`). It belongs to one light direction: make a new one when the light has moved.
104
+ */
105
+ export interface ShadowHorizon {
106
+ /** `rg8`, linear: the height is `baseY + code / 65535 × rangeM` (high byte in red). Code 0: nothing hides a point there, whatever its height. */
107
+ texture: Texture;
108
+ /** World x and z of the texture's corner at coordinate (0, 0). */
109
+ originX: number;
110
+ originZ: number;
111
+ /** Extent of the texture along x and z, metres. */
112
+ sizeX: number;
113
+ sizeZ: number;
114
+ baseY: number;
115
+ rangeM: number;
116
+ /** Height over which the term fades from lit (at the horizon) to hidden (below it), metres. Default 2. */
117
+ blendM?: number;
118
+ }
119
+ export interface RendererOptions {
120
+ /** Penumbra width in metres. Limited by the shadow map resolution. */
121
+ shadowSoftnessM?: number;
122
+ /** Shadow map edge in pixels. */
123
+ shadowMapSize?: number;
124
+ /** Perspective views only: how far from the eye shadows reach, in metres. Default: the whole scene. */
125
+ shadowDistanceM?: number;
126
+ /** Layout of the shadow map (`ShadowOptions`). Default: the single fitted map, unchanged. */
127
+ shadows?: ShadowOptions;
128
+ /** Colour table for the Palette block (vec4 rows). */
129
+ palette: Float32Array;
130
+ /** The owner's slots in the Frame block: sizes in vec4 and their GLSL member declarations. Default none. */
131
+ frameSlots?: FrameSlotSizes & {
132
+ glsl: FrameSlotsGlsl;
133
+ };
134
+ /**
135
+ * How the main passes store depth (`DepthMode`). `'reversed'` and `'logarithmic'` let one perspective view hold
136
+ * a metre and a thousand kilometres; `'reversed'` falls back to `'logarithmic'` where the browser lacks
137
+ * `EXT_clip_control` (`Renderer.depthMode` tells which is in effect). For these two create the context with
138
+ * `createContext(canvas, mode)`. Default: the device's mode, which is `'standard'` unless it was changed.
139
+ */
140
+ depth?: DepthMode;
141
+ /** Reversed and logarithmic depth with a perspective view: distance of the near plane in metres. Default 0.1. */
142
+ depthNearM?: number;
143
+ /**
144
+ * Samples per pixel of the main target: 0 (no antialiasing), 2 or 4 (`Device.setMainSamples`). Create the context
145
+ * with the same count, `createContext(canvas, depth, samples)` (the engine does). Default: unchanged, the canvas's
146
+ * own antialiasing in the standard depth mode, 4 samples in the others.
147
+ */
148
+ samples?: MainSamples;
149
+ /**
150
+ * Up that points away from a point instead of along +y, for a world wrapped round that point (`center` in world
151
+ * metres, as `worldOrigin` is). Program headers then define `WH_LOCAL_UP` and the Frame block ends with
152
+ * `u_upCenter`; the header functions `localUp`, `localHeight` and `localFrame`, the lighting include, rigs and
153
+ * instance culling follow it. Default: unset, up is +y everywhere and nothing changes.
154
+ */
155
+ radialUp?: RadialUp;
156
+ }
157
+ /** Axis-aligned extent of everything drawn. */
158
+ export interface SceneBounds {
159
+ min: Vec3;
160
+ max: Vec3;
161
+ }
162
+ export interface FrameStats {
163
+ /** Triangles and calls of the main passes. */
164
+ triangles: number;
165
+ drawCalls: number;
166
+ /** Triangles and calls of the shadow pass when it was recomputed in this frame, otherwise 0. */
167
+ shadowTriangles: number;
168
+ shadowDrawCalls: number;
169
+ /**
170
+ * The part of `shadowTriangles` and `shadowDrawCalls` drawn by layers with `shadowCasters: 'dynamic'` over the kept
171
+ * static map (mode `'single'`). 0 without such layers or in a frame that did not redraw them.
172
+ */
173
+ dynamicShadowTriangles: number;
174
+ dynamicShadowDrawCalls: number;
175
+ /** Processor time to assemble the frame in ms (without waiting for the graphics). */
176
+ cpuMs: number;
177
+ shadowMapPx: number;
178
+ /** Instances kept by the layers' last view culling. */
179
+ instancesVisible: number;
180
+ /**
181
+ * Rectangles of the shadow map drawn in this frame: 0 when the map was kept as it is, 1 for a whole map in the
182
+ * mode `'single'`, in the other modes the number of whole areas and border strips drawn.
183
+ */
184
+ shadowUpdates: number;
185
+ }
186
+ /** A compiled material: a program per pass, its attribute locations and draw state. */
187
+ export declare class Material {
188
+ readonly name: string;
189
+ readonly attribs: Readonly<Record<string, number>>;
190
+ readonly state: Partial<Record<PassName, DrawState>>;
191
+ private readonly programs;
192
+ /** `resolve` turns a shader source of the given pass into what is compiled (includes, see `Renderer.resolve`). */
193
+ constructor(device: Device, desc: MaterialDesc, resolve?: (src: string, pass: PassName) => string);
194
+ /** Passes this material has a program for. */
195
+ get passes(): PassName[];
196
+ /** Program for a pass. The `data` pass falls back to the `color` program. */
197
+ program(pass: PassName): Program | null;
198
+ }
199
+ export declare class Renderer {
200
+ readonly device: Device;
201
+ readonly layers: Layer[];
202
+ /** Called at the start of every frame, before anything is read from the renderer's fields. */
203
+ readonly beforeFrame: ((view: View) => void)[];
204
+ /** Extent of the scene; `null` draws only the background. */
205
+ bounds: SceneBounds | null;
206
+ /**
207
+ * World position of the render-space origin, for a world drawn relative to a moving origin (double precision, CPU
208
+ * only). Shadow map texels snap to the world grid instead of the render-space grid, so a rebase does not shift them.
209
+ */
210
+ worldOrigin: Vec3;
211
+ background: RGB;
212
+ /** Unit direction toward the main directional light. */
213
+ lightDirection: Vec3;
214
+ /** Anything besides the view and the light direction that changes shadows (environment slots contribute to it). */
215
+ shadowKeyExtra: string;
216
+ /** `'data'` draws the `data` pass instead of `color` and skips `overlay`. */
217
+ mode: 'color' | 'data';
218
+ /** Contents of the owner's slots in the Frame block, uploaded every frame. */
219
+ readonly frameSlots: {
220
+ afterLight: Float32Array;
221
+ afterView: Float32Array;
222
+ };
223
+ /** Shader includes by name (`#include <name>` on a line of its own). `header` and `noise` are built in. */
224
+ readonly includes: Map<string, string>;
225
+ lastStats: FrameStats;
226
+ /** The depth mode of the main passes in effect (after the fallback from `'reversed'` to `'logarithmic'`). */
227
+ readonly depthMode: DepthMode;
228
+ /** Reversed and logarithmic depth with a perspective view: distance of the near plane in metres. */
229
+ depthNearM: number;
230
+ /** Measuring hooks (`RenderProbe`). Null in normal use; set only while profiling and reset afterwards. */
231
+ probe: RenderProbe | null;
232
+ private readonly shadowSoftnessM;
233
+ private shadowMapSize;
234
+ private readonly shadowDistanceM;
235
+ private readonly frameBlock;
236
+ private readonly frameData;
237
+ private readonly shadowTarget;
238
+ private shadowKey;
239
+ private lightRender;
240
+ private lightSample;
241
+ private shadowPx;
242
+ private shadowTexelM;
243
+ private instancesVisible;
244
+ private lightFit;
245
+ /** The shadow mode in effect. */
246
+ readonly shadowMode: ShadowMode;
247
+ /**
248
+ * Shadow modes `'snapped'` and `'cascades'`: the scene's light horizon, used beyond the reach of the shadow map, or
249
+ * null for none (points out there are then lit unless the material bakes its own term). May be replaced at any
250
+ * time; the texture stays the caller's to delete.
251
+ */
252
+ shadowHorizon: ShadowHorizon | null;
253
+ private readonly areaState;
254
+ /** The radial up this renderer was made with, or null when up is +y. */
255
+ readonly radialUp: RadialUp | null;
256
+ /** Mode `'single'` with dynamic casters: the depth map that holds only the static casters; made with the first dynamic layer. */
257
+ private staticShadow;
258
+ /** Whether the last frame had a dynamic layer. */
259
+ private hadDynamic;
260
+ /** Mode `'single'`: what the kept map was fitted to (view key, light direction in 1e-4 steps, `shadowKeyExtra`). */
261
+ private singleKeyValid;
262
+ private singleKeyView;
263
+ private readonly singleKeyLight;
264
+ private singleKeyExtra;
265
+ /** Instances kept by the static layers at the last view culling of a refit. */
266
+ private staticVisible;
267
+ /** The light's volume of the last refit (mode `'single'`), and the view's volume of the last culling with its key. */
268
+ private lightVolume;
269
+ private viewVolume;
270
+ private viewVolumeKey;
271
+ /** Preallocated per-frame scratch, so a frame that changes nothing allocates nothing here. */
272
+ private readonly proj;
273
+ private readonly camAxes;
274
+ private readonly rays;
275
+ private readonly sceneCenter;
276
+ private readonly singleRender;
277
+ private readonly singleSample;
278
+ private readonly countMain;
279
+ private readonly countShadow;
280
+ private readonly countDynamic;
281
+ /** The draw context handed to the layers, refilled for every pass. */
282
+ private readonly ctx;
283
+ private counting;
284
+ constructor(device: Device, options: RendererOptions);
285
+ /** Edge of the shadow map texture in pixels (`FrameStats.shadowMapPx` is the part of it in use). */
286
+ get shadowMapEdgePx(): number;
287
+ /**
288
+ * With `radialUp`: the point up points away from, in render space (relative to `worldOrigin`). Null when up is +y.
289
+ * Layers that place or cull upright things on the CPU read it.
290
+ */
291
+ upCenter(): Vec3 | null;
292
+ /**
293
+ * Replaces include lines with the registered snippets. `into` says where the program draws: `'main'` (default) for
294
+ * the main target, `'other'` for a depth target (the shadow pass) or a bake.
295
+ *
296
+ * In the logarithmic depth mode a fragment shader of the main target that starts from `<header>` is also wrapped
297
+ * (`LOG_DEPTH_PRELUDE`, `LOG_DEPTH_EPILOGUE`), so that it writes its depth itself. A source that never mentions
298
+ * `gl_Position` counts as a fragment shader. A fragment shader with its own `#version` line instead of `<header>`
299
+ * is left alone and keeps the depth of the pipeline: use it only for draws without the depth test.
300
+ */
301
+ resolve(src: string, into?: 'main' | 'other'): string;
302
+ /** Compiles a material description. */
303
+ material(desc: MaterialDesc): Material;
304
+ /** Uploads a mesh for a material (the material fixes attribute locations). */
305
+ createMesh(data: MeshData, material: Material, instances?: InstanceBuffer): Mesh;
306
+ createInstances(data: InstanceData): InstanceBuffer;
307
+ createTexture(data: TextureData): Texture;
308
+ /** Runs a texture bake on the graphics card and returns its targets. */
309
+ bake(desc: BakeDesc): Texture[];
310
+ add(layer: Layer): void;
311
+ /** Registers a layer to draw just before `before` (at the end when `before` is not registered). */
312
+ addBefore(layer: Layer, before: Layer): void;
313
+ remove(layer: Layer): void;
314
+ /** After a scene or light change forces a new shadow computation. */
315
+ invalidateShadows(): void;
316
+ /**
317
+ * Fits the light's orthographic projection to what the view sees: the projection of the visible volume (corner rays cut by
318
+ * the bottom and top of the scene) onto the plane perpendicular to the light, clipped by the scene extent and snapped
319
+ * to texels so shadows do not shimmer when panning.
320
+ */
321
+ private fitLight;
322
+ /**
323
+ * What the view sees and what the scene spans, along the axes of a light frame (render space): the rectangle of the
324
+ * light's plane the visible volume projects to, cut to the scene extent, the scene's range along the light, and the
325
+ * eye of a perspective view. The visible volume is taken as in `fitLight`; `reachM` limits a perspective view.
326
+ */
327
+ private viewFootprint;
328
+ /**
329
+ * Shadow areas, first half of a frame: places every area around the focus of the view, decides what of the map
330
+ * must be drawn and fills the areas' part of the Frame block. Positions on the block grid are counted from the
331
+ * world origin (`worldOrigin`), so neither a moving render origin nor a pan shifts a texel against the world.
332
+ */
333
+ private planAreas;
334
+ /**
335
+ * Shadow areas, second half of a frame: draws the planned rectangles into the map (each with the casters the
336
+ * light's volume over that rectangle selects), then lets the layers select for the view again.
337
+ * Returns the number of rectangles drawn.
338
+ */
339
+ private drawAreas;
340
+ /**
341
+ * Draws one pass of every layer. `casters` (shadow pass only) limits it to the layers with that `shadowCasters`
342
+ * (unset counts as `'static'`); `'all'` draws every layer.
343
+ */
344
+ private drawPass;
345
+ /** `drawPass` for one layer while a probe is set: may leave the layer out, reports what it counted. */
346
+ private drawProbed;
347
+ /** Renders one frame. Called synchronously, independent of the browser's timer. */
348
+ render(view: View): FrameStats;
349
+ /** Mode `'single'`: is the kept map still fitted to this view, light direction and `shadowKeyExtra`? */
350
+ private singleKeyHolds;
351
+ private keepSingleKey;
352
+ /**
353
+ * Renders n frames and waits for the graphics. Returns the average time of one frame in ms including the graphics work.
354
+ * `beforeFrame` is called before each frame, typically advances the clocks by a fixed step so that animation is measured.
355
+ */
356
+ benchmark(view: View, n: number, beforeFrame?: (index: number) => void): number;
357
+ }
358
+ export interface MeshLayerOptions {
359
+ material: Material;
360
+ /** Name for profiles and statistics (`Layer.name`). */
361
+ name?: string;
362
+ mesh?: Mesh | null;
363
+ /** Passes the layer draws in. Default: every pass the material has a program for. */
364
+ passes?: Iterable<PassName>;
365
+ /** Extra draw state per pass, on top of the material's state. */
366
+ state?: Partial<Record<PassName, DrawState>>;
367
+ /** Uniforms set before every draw. May be replaced at any time. */
368
+ uniforms?: Uniforms;
369
+ /** Samplers bound before every draw, to the units 1, 2, … in order (unit 0 holds the shadow map). */
370
+ textures?: Record<string, Texture | null>;
371
+ /** Sets anything else for the program of the current pass, right before the draw. */
372
+ bind?: (program: Program, ctx: DrawContext) => void;
373
+ }
374
+ /** Sets the shared uniforms and binds samplers for one draw. */
375
+ export declare function applyInputs(ctx: DrawContext, program: Program, uniforms: Uniforms, textures: Record<string, Texture | null>): void;
376
+ /**
377
+ * One mesh drawn with one material. In the shadow pass the program gets `u_lightRender`, in the others `u_shadowMap`.
378
+ */
379
+ export declare class MeshLayer implements Layer {
380
+ name?: string;
381
+ readonly material: Material;
382
+ mesh: Mesh | null;
383
+ passes: Set<PassName>;
384
+ uniforms: Uniforms;
385
+ textures: Record<string, Texture | null>;
386
+ readonly state: Partial<Record<PassName, DrawState>>;
387
+ private readonly bind;
388
+ constructor(o: MeshLayerOptions);
389
+ draw(ctx: DrawContext): void;
390
+ /**
391
+ * Sets this layer's draw state, program, uniforms and textures for `ctx.pass`. Returns the program, or null when the
392
+ * layer does not draw in this pass. Subclasses that draw several meshes call it once and then draw each mesh.
393
+ */
394
+ protected begin(ctx: DrawContext): Program | null;
395
+ }
396
+ /** A shape drawn many times: levels of detail sharing one instance buffer, and that buffer's full contents. */
397
+ export interface InstanceBatch {
398
+ /** Meshes from the coarsest to the finest, all bound to `instances`. */
399
+ lods: Mesh[];
400
+ instances: InstanceBuffer;
401
+ /** Every instance; culling copies the kept ones into the buffer. */
402
+ all: Float32Array;
403
+ /** Uniforms of this batch, set before its draw. May be replaced at any time. */
404
+ uniforms: Uniforms;
405
+ }
406
+ export interface InstancedLayerOptions {
407
+ material: Material;
408
+ /** Name for profiles and statistics (`Layer.name`). */
409
+ name?: string;
410
+ bounds: InstanceBounds;
411
+ /** Level of detail for the colour pass, asked whenever the visible set is recomputed. The shadow pass uses level 0. */
412
+ levelOfDetail?: () => number;
413
+ passes?: Iterable<PassName>;
414
+ uniforms?: Uniforms;
415
+ /**
416
+ * For a renderer with radial up: the render-space point the instances stand away from, asked at every culling
417
+ * (pass `() => renderer.upCenter()`). Default: unset, instances stand along +y.
418
+ */
419
+ upCenter?: () => readonly [number, number, number] | null;
420
+ }
421
+ /**
422
+ * Instanced batches with per-volume culling. An instance is an upright segment from its base point up by its height,
423
+ * widened by its radius; whatever reaches into the volume is kept.
424
+ */
425
+ export declare class InstancedLayer implements Layer {
426
+ name?: string;
427
+ readonly material: Material;
428
+ batches: InstanceBatch[];
429
+ passes: Set<PassName>;
430
+ uniforms: Uniforms;
431
+ /** Extra draw state per pass, on top of the material's state. May be replaced at any time. */
432
+ state: Partial<Record<PassName, DrawState>>;
433
+ private readonly device;
434
+ private readonly bounds;
435
+ private readonly levelOfDetail;
436
+ private readonly upCenter;
437
+ private scratch;
438
+ private lodNow;
439
+ constructor(device: Device, o: InstancedLayerOptions);
440
+ cull(volume: CullVolume, purpose: 'shadow' | 'view'): number;
441
+ draw(ctx: DrawContext): void;
442
+ }
443
+ /**
444
+ * Copies the instances that reach into the volume into `out`; returns the number of floats written. With `upCenter`
445
+ * (a point in the space of the instance positions) every instance stands away from that point instead of along +y.
446
+ */
447
+ export declare function cullInstances(volume: CullVolume, src: Float32Array, stride: number, b: InstanceBounds, out: Float32Array, upCenter?: readonly [number, number, number] | null): number;