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,134 @@
1
+ import type { VertexLayout } from '../base/data.ts';
2
+ import type { UniformValue } from '../base/material.ts';
3
+ import type { DepthMode } from '../base/view.ts';
4
+ export type GL = WebGL2RenderingContext;
5
+ /** Opaque GPU objects, so modules above gpu can hold them without naming WebGL. */
6
+ export type Texture = WebGLTexture;
7
+ export type GpuBuffer = WebGLBuffer;
8
+ /** A surface that can hand out a WebGL2 context: an on-screen or offscreen canvas. */
9
+ export interface ContextSource {
10
+ getContext(contextId: 'webgl2', options?: WebGLContextAttributes): WebGL2RenderingContext | null;
11
+ }
12
+ /** Samples per pixel of the main target that can be asked for (`Device.setMainSamples`). */
13
+ export type MainSamples = 0 | 2 | 4;
14
+ /**
15
+ * Creates the WebGL2 context. `depth` is the depth mode the device will be asked for (`Device.setDepthMode`): in the
16
+ * reversed and logarithmic modes the device draws into its own multisampled target with a 32-bit float depth buffer
17
+ * and copies the result to the canvas, so the canvas itself is created without antialiasing and without depth.
18
+ * `samples` is what the device will be asked for with `Device.setMainSamples`. Unset: the canvas's own antialiasing
19
+ * (standard mode) or 4 samples (the other modes), as before. In the standard mode 0 makes the canvas without
20
+ * antialiasing, 4 with it (the browser's usual count) and 2 makes it plain, as the device then draws offscreen.
21
+ */
22
+ export declare function createContext(canvas: ContextSource, depth?: DepthMode, samples?: MainSamples): GL;
23
+ /** Name of the graphics device as reported by the browser. */
24
+ export declare function rendererName(gl: GL): string;
25
+ /** Uniform blocks shared by all programs and their fixed binding points. */
26
+ export declare const UBO_BINDING: {
27
+ readonly Frame: 0;
28
+ readonly Palette: 1;
29
+ readonly PointLights: 2;
30
+ };
31
+ /** Forgets the extension objects looked up for a context: after a context loss they belong to the old context. */
32
+ export declare function forgetContextExtensions(gl: GL): void;
33
+ /**
34
+ * A shader program. Compiling and linking are only started here; the result is checked on first use (or by
35
+ * `settle()`), so a batch of programs made together compiles in parallel in the driver instead of one after another.
36
+ * With `KHR_parallel_shader_compile`, `isComplete()` tells without blocking whether the driver is done.
37
+ */
38
+ export declare class Program {
39
+ /** The WebGL program. Replaced by `restore` after a context loss, so read it when it is needed. */
40
+ handle: WebGLProgram;
41
+ /** What the program was made from, kept so it can be made again (`restore`). */
42
+ private readonly made;
43
+ private readonly gl;
44
+ private readonly locations;
45
+ private pending;
46
+ /** Last value of `u_whDepthBias` set on this program (a uniform starts at 0). */
47
+ private biasFactor;
48
+ private biasUnits;
49
+ /** `attribs` assigns fixed numbers to attribute names so one VAO can be shared between programs. */
50
+ constructor(gl: GL, label: string, vs: string, fs: string, attribs?: Record<string, number>);
51
+ /**
52
+ * Makes the program again in a fresh context (after a context loss): compiles and links the same sources and
53
+ * forgets every uniform location and value of the old one. As after construction, the status is checked on first use.
54
+ */
55
+ restore(): void;
56
+ /** True when the program is checked, or the driver reports it finished (always true without the extension). */
57
+ isComplete(): boolean;
58
+ /** Waits for the driver if needed, checks compile and link status (throws with the log) and binds uniform blocks. */
59
+ settle(): void;
60
+ use(): void;
61
+ loc(name: string): WebGLUniformLocation | null;
62
+ int(name: string, v: number): void;
63
+ ivec4(name: string, x: number, y: number, z: number, w: number): void;
64
+ float(name: string, v: number): void;
65
+ vec2(name: string, x: number, y: number): void;
66
+ vec3(name: string, x: number, y: number, z: number): void;
67
+ vec3v(name: string, v: ArrayLike<number>): void;
68
+ /** A `vec4` array uniform (`uniform vec4 name[n]`): `v` holds 4 floats per element, as many elements as it fills. */
69
+ vec4v(name: string, v: ArrayLike<number>): void;
70
+ mat4(name: string, m: Float32Array): void;
71
+ /**
72
+ * Depth offset `[factor, units]` for a program that writes its own depth (logarithmic depth mode) and so gets no
73
+ * polygon offset from the pipeline: sets `u_whDepthBias` of the program in use, only when the value changes.
74
+ * The device calls it before a draw.
75
+ */
76
+ depthBias(factor: number, units: number): void;
77
+ /** Sets a uniform from its tagged value. */
78
+ set(name: string, v: UniformValue): void;
79
+ }
80
+ export declare function createBuffer(gl: GL, target: number, data: ArrayBufferView, usage?: number): WebGLBuffer;
81
+ /** Description of one attribute in an interleaved buffer. */
82
+ export interface AttribSpec {
83
+ loc: number;
84
+ size: number;
85
+ type: number;
86
+ normalized?: boolean;
87
+ /** Integer attribute (ivec/uvec in the shader). */
88
+ integer?: boolean;
89
+ offset: number;
90
+ /** 1 = one value per instance. */
91
+ divisor?: number;
92
+ }
93
+ export declare function bindAttribs(gl: GL, buffer: WebGLBuffer, stride: number, specs: AttribSpec[]): void;
94
+ export interface TextureOptions {
95
+ internalFormat: number;
96
+ format: number;
97
+ type: number;
98
+ width: number;
99
+ height: number;
100
+ data?: ArrayBufferView | null;
101
+ minFilter?: number;
102
+ magFilter?: number;
103
+ wrap?: number;
104
+ mipmaps?: boolean;
105
+ }
106
+ export declare function createTexture(gl: GL, o: TextureOptions): WebGLTexture;
107
+ /** A mesh ready to be drawn with a single call. */
108
+ export interface Mesh {
109
+ vao: WebGLVertexArrayObject;
110
+ /** Index count, or vertex count when the mesh has no indices. */
111
+ count: number;
112
+ indexType: number | null;
113
+ triangles: number;
114
+ /** Instance count, 0 = no instancing. */
115
+ instances: number;
116
+ /** Primitive kind, default is triangles (`gl.TRIANGLES`). Lines: `gl.LINES`. */
117
+ mode?: number;
118
+ /** Buffers owned by this mesh, deleted with it (a shared instance buffer is not among them). */
119
+ buffers?: WebGLBuffer[];
120
+ /** Bytes of the buffers this mesh owns (0 for a mesh that shares another mesh's buffers). */
121
+ bytes: number;
122
+ /** The vertex and index buffers it draws from and their layout, so another mesh can share them. */
123
+ source?: MeshSource;
124
+ }
125
+ /** The buffers behind a mesh, for `Device.shareMesh`. */
126
+ export interface MeshSource {
127
+ vertices: WebGLBuffer;
128
+ indices: WebGLBuffer | null;
129
+ layout: VertexLayout;
130
+ indexType: number | null;
131
+ count: number;
132
+ mode?: number;
133
+ }
134
+ export declare function drawMesh(gl: GL, m: Mesh): void;
package/dist/gpu/gl.js ADDED
@@ -0,0 +1,276 @@
1
+ // Thin layer over WebGL2: programs, buffers, textures. No fallback paths for older browsers.
2
+ /**
3
+ * Creates the WebGL2 context. `depth` is the depth mode the device will be asked for (`Device.setDepthMode`): in the
4
+ * reversed and logarithmic modes the device draws into its own multisampled target with a 32-bit float depth buffer
5
+ * and copies the result to the canvas, so the canvas itself is created without antialiasing and without depth.
6
+ * `samples` is what the device will be asked for with `Device.setMainSamples`. Unset: the canvas's own antialiasing
7
+ * (standard mode) or 4 samples (the other modes), as before. In the standard mode 0 makes the canvas without
8
+ * antialiasing, 4 with it (the browser's usual count) and 2 makes it plain, as the device then draws offscreen.
9
+ */
10
+ export function createContext(canvas, depth = 'standard', samples) {
11
+ const own = depth === 'standard' && samples !== 2;
12
+ const gl = canvas.getContext('webgl2', {
13
+ antialias: own && samples !== 0,
14
+ alpha: false,
15
+ depth: own,
16
+ stencil: false,
17
+ powerPreference: 'high-performance',
18
+ preserveDrawingBuffer: false,
19
+ });
20
+ if (!gl)
21
+ throw new Error('This browser does not support WebGL2.');
22
+ return gl;
23
+ }
24
+ /** Name of the graphics device as reported by the browser. */
25
+ export function rendererName(gl) {
26
+ const ext = gl.getExtension('WEBGL_debug_renderer_info');
27
+ return String(ext ? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER));
28
+ }
29
+ function createShader(gl, type, src) {
30
+ const sh = gl.createShader(type);
31
+ if (!sh)
32
+ throw new Error('Cannot create a shader');
33
+ gl.shaderSource(sh, src);
34
+ gl.compileShader(sh);
35
+ return sh;
36
+ }
37
+ function shaderError(gl, sh, src, label) {
38
+ const log = gl.getShaderInfoLog(sh) ?? '';
39
+ const numbered = src
40
+ .split('\n')
41
+ .map((l, i) => `${String(i + 1).padStart(4)}: ${l}`)
42
+ .join('\n');
43
+ return new Error(`Shader ${label} failed to compile:\n${log}\n${numbered}`);
44
+ }
45
+ /** Uniform blocks shared by all programs and their fixed binding points. */
46
+ export const UBO_BINDING = { Frame: 0, Palette: 1, PointLights: 2 };
47
+ /** `KHR_parallel_shader_compile` of a context, looked up once (null without the extension). */
48
+ const parallelCompile = new WeakMap();
49
+ function parallelExt(gl) {
50
+ let e = parallelCompile.get(gl);
51
+ if (e === undefined) {
52
+ e = gl.getExtension('KHR_parallel_shader_compile');
53
+ parallelCompile.set(gl, e);
54
+ }
55
+ return e;
56
+ }
57
+ /** Forgets the extension objects looked up for a context: after a context loss they belong to the old context. */
58
+ export function forgetContextExtensions(gl) {
59
+ parallelCompile.delete(gl);
60
+ }
61
+ /**
62
+ * A shader program. Compiling and linking are only started here; the result is checked on first use (or by
63
+ * `settle()`), so a batch of programs made together compiles in parallel in the driver instead of one after another.
64
+ * With `KHR_parallel_shader_compile`, `isComplete()` tells without blocking whether the driver is done.
65
+ */
66
+ export class Program {
67
+ /** The WebGL program. Replaced by `restore` after a context loss, so read it when it is needed. */
68
+ handle;
69
+ /** What the program was made from, kept so it can be made again (`restore`). */
70
+ made;
71
+ gl;
72
+ locations = new Map();
73
+ pending;
74
+ /** Last value of `u_whDepthBias` set on this program (a uniform starts at 0). */
75
+ biasFactor = 0;
76
+ biasUnits = 0;
77
+ /** `attribs` assigns fixed numbers to attribute names so one VAO can be shared between programs. */
78
+ constructor(gl, label, vs, fs, attribs = {}) {
79
+ this.gl = gl;
80
+ this.made = { label, vs, fs, attribs };
81
+ // A program made while the context is lost has nothing behind it until `restore`.
82
+ if (gl.isContextLost()) {
83
+ this.handle = null;
84
+ this.pending = null;
85
+ return;
86
+ }
87
+ const p = gl.createProgram();
88
+ if (!p)
89
+ throw new Error('Cannot create a program');
90
+ const v = createShader(gl, gl.VERTEX_SHADER, vs);
91
+ const f = createShader(gl, gl.FRAGMENT_SHADER, fs);
92
+ gl.attachShader(p, v);
93
+ gl.attachShader(p, f);
94
+ for (const [name, loc] of Object.entries(attribs))
95
+ gl.bindAttribLocation(p, loc, name);
96
+ gl.linkProgram(p);
97
+ this.handle = p;
98
+ this.pending = { label, vs, fs, v, f };
99
+ }
100
+ /**
101
+ * Makes the program again in a fresh context (after a context loss): compiles and links the same sources and
102
+ * forgets every uniform location and value of the old one. As after construction, the status is checked on first use.
103
+ */
104
+ restore() {
105
+ const gl = this.gl;
106
+ const { label, vs, fs, attribs } = this.made;
107
+ this.locations.clear();
108
+ this.biasFactor = 0;
109
+ this.biasUnits = 0;
110
+ const p = gl.createProgram();
111
+ if (!p) {
112
+ this.pending = null;
113
+ return;
114
+ }
115
+ const v = createShader(gl, gl.VERTEX_SHADER, vs);
116
+ const f = createShader(gl, gl.FRAGMENT_SHADER, fs);
117
+ gl.attachShader(p, v);
118
+ gl.attachShader(p, f);
119
+ for (const [name, loc] of Object.entries(attribs))
120
+ gl.bindAttribLocation(p, loc, name);
121
+ gl.linkProgram(p);
122
+ this.handle = p;
123
+ this.pending = { label, vs, fs, v, f };
124
+ }
125
+ /** True when the program is checked, or the driver reports it finished (always true without the extension). */
126
+ isComplete() {
127
+ if (!this.pending)
128
+ return true;
129
+ const ext = parallelExt(this.gl);
130
+ return !ext || this.gl.getProgramParameter(this.handle, ext.COMPLETION_STATUS_KHR) === true;
131
+ }
132
+ /** Waits for the driver if needed, checks compile and link status (throws with the log) and binds uniform blocks. */
133
+ settle() {
134
+ const q = this.pending;
135
+ if (!q)
136
+ return;
137
+ this.pending = null;
138
+ const gl = this.gl;
139
+ const p = this.handle;
140
+ if (!gl.getProgramParameter(p, gl.LINK_STATUS)) {
141
+ if (!gl.getShaderParameter(q.v, gl.COMPILE_STATUS))
142
+ throw shaderError(gl, q.v, q.vs, `${q.label} (vertex)`);
143
+ if (!gl.getShaderParameter(q.f, gl.COMPILE_STATUS))
144
+ throw shaderError(gl, q.f, q.fs, `${q.label} (fragment)`);
145
+ throw new Error(`Program ${q.label} failed to link: ${gl.getProgramInfoLog(p) ?? ''}`);
146
+ }
147
+ gl.deleteShader(q.v);
148
+ gl.deleteShader(q.f);
149
+ for (const [name, binding] of Object.entries(UBO_BINDING)) {
150
+ const idx = gl.getUniformBlockIndex(p, name);
151
+ if (idx !== gl.INVALID_INDEX)
152
+ gl.uniformBlockBinding(p, idx, binding);
153
+ }
154
+ }
155
+ use() {
156
+ if (this.pending)
157
+ this.settle();
158
+ this.gl.useProgram(this.handle);
159
+ }
160
+ loc(name) {
161
+ let l = this.locations.get(name);
162
+ if (l === undefined) {
163
+ if (this.pending)
164
+ this.settle();
165
+ l = this.gl.getUniformLocation(this.handle, name);
166
+ this.locations.set(name, l);
167
+ }
168
+ return l;
169
+ }
170
+ // Uniform setters for the program in use. A name the shader does not use is ignored, as in WebGL.
171
+ int(name, v) {
172
+ this.gl.uniform1i(this.loc(name), v);
173
+ }
174
+ ivec4(name, x, y, z, w) {
175
+ this.gl.uniform4i(this.loc(name), x, y, z, w);
176
+ }
177
+ float(name, v) {
178
+ this.gl.uniform1f(this.loc(name), v);
179
+ }
180
+ vec2(name, x, y) {
181
+ this.gl.uniform2f(this.loc(name), x, y);
182
+ }
183
+ vec3(name, x, y, z) {
184
+ this.gl.uniform3f(this.loc(name), x, y, z);
185
+ }
186
+ vec3v(name, v) {
187
+ this.gl.uniform3fv(this.loc(name), v);
188
+ }
189
+ /** A `vec4` array uniform (`uniform vec4 name[n]`): `v` holds 4 floats per element, as many elements as it fills. */
190
+ vec4v(name, v) {
191
+ this.gl.uniform4fv(this.loc(name), v);
192
+ }
193
+ mat4(name, m) {
194
+ this.gl.uniformMatrix4fv(this.loc(name), false, m);
195
+ }
196
+ /**
197
+ * Depth offset `[factor, units]` for a program that writes its own depth (logarithmic depth mode) and so gets no
198
+ * polygon offset from the pipeline: sets `u_whDepthBias` of the program in use, only when the value changes.
199
+ * The device calls it before a draw.
200
+ */
201
+ depthBias(factor, units) {
202
+ if (factor === this.biasFactor && units === this.biasUnits)
203
+ return;
204
+ this.biasFactor = factor;
205
+ this.biasUnits = units;
206
+ this.gl.uniform2f(this.loc('u_whDepthBias'), factor, units);
207
+ }
208
+ /** Sets a uniform from its tagged value. */
209
+ set(name, v) {
210
+ const gl = this.gl;
211
+ const l = this.loc(name);
212
+ if ('int' in v)
213
+ gl.uniform1i(l, v.int);
214
+ else if ('float' in v)
215
+ gl.uniform1f(l, v.float);
216
+ else if ('vec2' in v)
217
+ gl.uniform2f(l, v.vec2[0], v.vec2[1]);
218
+ else if ('vec3' in v)
219
+ gl.uniform3f(l, v.vec3[0], v.vec3[1], v.vec3[2]);
220
+ else if ('vec4' in v)
221
+ gl.uniform4f(l, v.vec4[0], v.vec4[1], v.vec4[2], v.vec4[3]);
222
+ else if ('ivec4' in v)
223
+ gl.uniform4i(l, v.ivec4[0], v.ivec4[1], v.ivec4[2], v.ivec4[3]);
224
+ else
225
+ gl.uniformMatrix4fv(l, false, v.mat4);
226
+ }
227
+ }
228
+ export function createBuffer(gl, target, data, usage = gl.STATIC_DRAW) {
229
+ const b = gl.createBuffer();
230
+ if (!b)
231
+ throw new Error('Cannot create a buffer');
232
+ gl.bindBuffer(target, b);
233
+ gl.bufferData(target, data, usage);
234
+ return b;
235
+ }
236
+ export function bindAttribs(gl, buffer, stride, specs) {
237
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
238
+ for (const s of specs) {
239
+ gl.enableVertexAttribArray(s.loc);
240
+ if (s.integer)
241
+ gl.vertexAttribIPointer(s.loc, s.size, s.type, stride, s.offset);
242
+ else
243
+ gl.vertexAttribPointer(s.loc, s.size, s.type, s.normalized ?? false, stride, s.offset);
244
+ if (s.divisor)
245
+ gl.vertexAttribDivisor(s.loc, s.divisor);
246
+ }
247
+ }
248
+ export function createTexture(gl, o) {
249
+ const t = gl.createTexture();
250
+ if (!t)
251
+ throw new Error('Cannot create a texture');
252
+ gl.bindTexture(gl.TEXTURE_2D, t);
253
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
254
+ gl.texImage2D(gl.TEXTURE_2D, 0, o.internalFormat, o.width, o.height, 0, o.format, o.type, o.data ?? null);
255
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, o.minFilter ?? gl.NEAREST);
256
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, o.magFilter ?? gl.NEAREST);
257
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, o.wrap ?? gl.CLAMP_TO_EDGE);
258
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, o.wrap ?? gl.CLAMP_TO_EDGE);
259
+ if (o.mipmaps)
260
+ gl.generateMipmap(gl.TEXTURE_2D);
261
+ return t;
262
+ }
263
+ export function drawMesh(gl, m) {
264
+ const mode = m.mode ?? gl.TRIANGLES;
265
+ gl.bindVertexArray(m.vao);
266
+ if (m.instances > 0) {
267
+ if (m.indexType !== null)
268
+ gl.drawElementsInstanced(mode, m.count, m.indexType, 0, m.instances);
269
+ else
270
+ gl.drawArraysInstanced(mode, 0, m.count, m.instances);
271
+ }
272
+ else if (m.indexType !== null)
273
+ gl.drawElements(mode, m.count, m.indexType, 0);
274
+ else
275
+ gl.drawArrays(mode, 0, m.count);
276
+ }
@@ -0,0 +1,4 @@
1
+ export { Program, UBO_BINDING, bindAttribs, createBuffer, createContext, createTexture, drawMesh, rendererName } from './gl.ts';
2
+ export type { AttribSpec, ContextSource, GpuBuffer, GL, MainSamples, Mesh, MeshSource, Texture, TextureOptions } from './gl.ts';
3
+ export { Device } from './device.ts';
4
+ export type { BakeInput, ColorTarget, ColorTargetFormat, DepthTarget, GpuMemory, InstanceBuffer, UniformBlock } from './device.ts';
@@ -0,0 +1,3 @@
1
+ // Layer 4, gpu: the only place with WebGL2. Context, device, programs, buffers, textures, meshes.
2
+ export { Program, UBO_BINDING, bindAttribs, createBuffer, createContext, createTexture, drawMesh, rendererName } from './gl.js';
3
+ export { Device } from './device.js';
@@ -0,0 +1,11 @@
1
+ export * from './base/index.ts';
2
+ export * from './platform/index.ts';
3
+ export * from './core/index.ts';
4
+ export * from './gen-core/index.ts';
5
+ export * from './gen-mesh/index.ts';
6
+ export * from './gen-tex/index.ts';
7
+ export * from './gpu/index.ts';
8
+ export * from './camera/index.ts';
9
+ export * from './env/index.ts';
10
+ export * from './world/index.ts';
11
+ export * from './tools/index.ts';
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ // Wallhammer Web: a small WebGL2 engine. Every module has its own entry (`wallhammer-web/<module>`);
2
+ // this root entry re-exports the generic modules for convenience.
3
+ export * from './base/index.js';
4
+ export * from './platform/index.js';
5
+ export * from './core/index.js';
6
+ export * from './gen-core/index.js';
7
+ export * from './gen-mesh/index.js';
8
+ export * from './gen-tex/index.js';
9
+ export * from './gpu/index.js';
10
+ export * from './camera/index.js';
11
+ export * from './env/index.js';
12
+ export * from './world/index.js';
13
+ export * from './tools/index.js';