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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tomáš Grasl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,93 @@
1
- # Temporary Holding Version
1
+ # Wallhammer Web
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <a href="https://github.com/freema/wallhammer-web/tree/main/examples/fantasy-village"><img src="https://raw.githubusercontent.com/freema/wallhammer-web/main/.github/media/fantasy-village.gif" width="100%" alt="The fantasy village example, every house, tree and villager generated by code: villagers cross the cobbled square and smoke rises while the light turns from late afternoon to evening and the windows and lanterns come on"></a>
4
+
5
+ A 3D engine for the browser where the whole world is written in code: no model files, no texture files, no images.
6
+
7
+ [![npm](https://img.shields.io/npm/v/wallhammer-web?logo=npm)](https://www.npmjs.com/package/wallhammer-web)
8
+ [![licence: MIT](https://img.shields.io/badge/licence-MIT-blue)](LICENSE)
9
+ [![TypeScript: strict](https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
10
+ [![WebGL2](https://img.shields.io/badge/WebGL2-plain-990000)](https://developer.mozilla.org/docs/Web/API/WebGL2RenderingContext)
11
+
12
+ A small WebGL2 engine for the browser, written in strict TypeScript. It uses plain WebGL2 and no graphics library. All graphics come from code; the engine loads no images. One world unit is one metre, and y points up.
13
+
14
+ The engine knows nothing about any particular project. It provides a renderer that draws the layers it is given, view rigs, an environment model (time, sun, sky, weather) that projects extend with environment slots, stateless randomness, generic geometry, a deterministic fixed-step simulation and world streaming. Ground, vegetation and structures come from three optional content modules, `gen-arch`, `gen-ground` and `gen-vegetation`. Nothing else in the engine depends on them.
15
+
16
+ In this repository the package exports its TypeScript sources and the examples build them with Vite. The published npm package holds compiled JavaScript with type declarations (`dist/`) and these docs. Its only runtime dependency is `earcut`, used for roof triangulation in `gen-arch`.
17
+
18
+ ```sh
19
+ npm install wallhammer-web
20
+ ```
21
+
22
+ ## Where the engine lives
23
+
24
+ The engine is developed in this repository, at `packages/wallhammer-web`. The repository is a pnpm workspace: the engine, its checks (`tools/`) and the examples that exercise it (`examples/`: `minimal-3d`, `destruction`, `endless`, `planet`, `system`, `fantasy-village`, `walk`, `outpost`), which import the package through the workspace, so a change here reaches them at once. Paths such as `examples/endless/...` in these docs are paths from the repository root.
25
+
26
+ Projects outside this repository use the published package or keep a copy of a fixed version. These docs name one such project, the campus app, as the place where a pattern is used at full size; its code is not part of this repository.
27
+
28
+ ## Documentation
29
+
30
+ Start here:
31
+
32
+ - [Getting started](docs/getting-started.md): start the dev container and draw a first scene.
33
+ - [Architecture](docs/architecture.md): modules, layers, the import rules and what enforces them.
34
+ - [Concepts](docs/concepts.md): plain-data contracts, determinism, the palette, the frame order.
35
+
36
+ Guides:
37
+
38
+ - [Rendering](docs/rendering.md): renderer, layers, materials, includes, shadows, environment slots, the sky.
39
+ - [Cameras and views](docs/cameras.md): `SteppedOrthoRig`, `PerspectiveOrbitRig` and the `View` contract.
40
+ - [Generators](docs/generators.md): `gen-core`, `gen-mesh`, `gen-tex` and the content modules.
41
+ - [Simulation](docs/simulation.md): `Simulation`, commands, entity tables, navigation, movers and their collision modes, shared areas, agendas and states.
42
+ - [Rigs and actors](docs/rigs.md): instanced animated rigs, `RigLayer`, how an app defines people, vehicles and stop furniture as rigs.
43
+ - [Destruction](docs/destruction.md): destructible structures, events, staged collapse, falling pieces.
44
+ - [World streaming](docs/streaming.md): cells, providers, the streaming manager and `StreamedWorld`.
45
+ - [The planet example](docs/planet.md): the sphere world, the atmosphere, the free camera and the large depth range joined in one flight from the surface to orbit.
46
+ - [The system example](docs/system.md): a sun and four bodies on their paths, and one flight from the view of the whole system down to a surface, with the camera handed from frame to frame.
47
+ - [Headless use](docs/headless.md): what runs in plain Node without a GPU.
48
+ - [Bodies on rails and nested frames](docs/frames.md): reproducible trigonometry, orbits and spin from time, 64-bit frames and numbers relative to the eye for the GPU.
49
+ - [Tools](docs/tools.md): the layer check, golden hashes, the docs check, screenshots, benchmarks.
50
+
51
+ Lookup:
52
+
53
+ - [Reference](docs/reference.md): every subpath export with its main names.
54
+ - [Recipes](docs/recipes.md): add a layer, a material, an environment slot, a generator, a destructible structure, a streamed cell provider, an animated rig; drive entities with agendas; feed agendas from external data.
55
+
56
+ ## Entries
57
+
58
+ Each engine module has its own entry, `wallhammer-web/<module>`. The root entry `wallhammer-web` re-exports `base`, `platform`, `core`, `gen-core`, `gen-mesh`, `gen-tex`, `gpu`, `camera`, `env`, `world` and `tools`. Import `render`, `sim`, `sim/destruction`, `runtime`, `gen-arch`, `gen-ground` and `gen-vegetation` from their own entries.
59
+
60
+ ```ts
61
+ import { PerspectiveOrbitRig, definePalette } from 'wallhammer-web';
62
+ import { createEngine } from 'wallhammer-web/runtime';
63
+
64
+ const engine = createEngine({
65
+ canvas: document.querySelector<HTMLCanvasElement>('canvas')!,
66
+ view: new PerspectiveOrbitRig({ fovYDeg: 40, minDistance: 20, maxDistance: 200 }),
67
+ palette: definePalette({ sky: '#6795b1' }),
68
+ background: [0.4, 0.58, 0.69],
69
+ orbitControls: true,
70
+ });
71
+ engine.start();
72
+ ```
73
+
74
+ This draws only the background. [Getting started](docs/getting-started.md) adds a mesh.
75
+
76
+ ## Rules in one paragraph
77
+
78
+ WebGL appears only in `gpu`. The browser DOM appears only in `platform`. A module imports only lower layers. Content modules import only the generator layers. Generators return plain data and never touch the GPU. Randomness comes from named hash streams, never from `Math.random`. `pnpm check:layers` enforces the import rules; [Architecture](docs/architecture.md) says which rules are checked and which are conventions only.
79
+
80
+ ## Development
81
+
82
+ From the repository root, everything runs in Docker:
83
+
84
+ ```sh
85
+ docker compose up -d
86
+ docker compose exec -T dev sh -c 'cd /app && pnpm typecheck'
87
+ docker compose exec -T dev sh -c 'cd /app && pnpm check:layers'
88
+ docker compose exec -T dev sh -c 'cd /app && pnpm test:golden'
89
+ docker compose exec -T dev sh -c 'cd /app && pnpm check:docs'
90
+ docker compose exec -T dev sh -c 'cd /app && pnpm check:pack'
91
+ ```
92
+
93
+ [Tools](docs/tools.md) explains each check. A change to the engine can also break an example; the examples have their own golden hashes (`tools/golden/`) and checks next to them.
@@ -0,0 +1,67 @@
1
+ /** Component type of a vertex attribute or texture channel. */
2
+ export type ScalarType = 'f32' | 'i8' | 'u8' | 'i16' | 'u16' | 'i32' | 'u32';
3
+ /** One attribute inside an interleaved vertex stream. */
4
+ export interface VertexAttrib {
5
+ /** Attribute name in the shader. The material fixes its location. */
6
+ name: string;
7
+ size: 1 | 2 | 3 | 4;
8
+ type: ScalarType;
9
+ /** Integer types mapped to 0–1 (or −1–1) floats. */
10
+ normalized?: boolean;
11
+ /** Read as an integer vector (ivec/uvec) in the shader. */
12
+ integer?: boolean;
13
+ /** Byte offset inside one vertex. */
14
+ offset: number;
15
+ }
16
+ /** Layout of an interleaved stream. */
17
+ export interface VertexLayout {
18
+ /** Bytes per vertex (or per instance). */
19
+ stride: number;
20
+ attribs: readonly VertexAttrib[];
21
+ }
22
+ export type Primitive = 'triangles' | 'lines';
23
+ /** A mesh as data: one interleaved vertex stream, optional indices. */
24
+ export interface MeshData {
25
+ layout: VertexLayout;
26
+ vertices: ArrayBufferView;
27
+ /** `null` draws the vertices in order. */
28
+ indices: Uint16Array | Uint32Array | null;
29
+ /** Index count, or vertex count without indices. */
30
+ count: number;
31
+ /** Default `'triangles'`. */
32
+ primitive?: Primitive;
33
+ }
34
+ /** Per-instance stream shared by several meshes (levels of detail of one shape). Floats only, rewritten when culling. */
35
+ export interface InstanceData {
36
+ layout: VertexLayout;
37
+ data: Float32Array;
38
+ }
39
+ /** Where an instance stores what culling needs, as float offsets inside one instance. */
40
+ export interface InstanceBounds {
41
+ /** Base point x, y, z (three consecutive floats). */
42
+ position: number;
43
+ /** Horizontal reach around the upright segment. */
44
+ radius: number;
45
+ /** Height of the upright segment above the base point. */
46
+ height: number;
47
+ }
48
+ export type TextureFormat = 'r8' | 'r8ui' | 'rg8' | 'rgba8';
49
+ /**
50
+ * Sampling of a texture. `nearest` and `linear` without mipmaps; `mipmap` = trilinear with mipmaps generated
51
+ * after upload or bake, optionally with anisotropic filtering up to `anisotropy`.
52
+ */
53
+ export interface TextureSampling {
54
+ filter?: 'nearest' | 'linear' | 'mipmap';
55
+ anisotropy?: number;
56
+ }
57
+ /** A 2D texture as data. Rows go from texture coordinate 0 upward; one byte per channel. */
58
+ export interface TextureData extends TextureSampling {
59
+ width: number;
60
+ height: number;
61
+ format: TextureFormat;
62
+ data: Uint8Array;
63
+ }
64
+ /** Bytes per pixel of a format. */
65
+ export declare function texelBytes(format: TextureFormat): number;
66
+ /** Number of primitives in a mesh. */
67
+ export declare function primitiveCount(m: MeshData): number;
@@ -0,0 +1,10 @@
1
+ // Plain data a generator hands over: vertex streams, meshes and textures as typed arrays with a description.
2
+ // Nothing here touches the GPU; the gpu module turns these into GPU objects.
3
+ /** Bytes per pixel of a format. */
4
+ export function texelBytes(format) {
5
+ return format === 'rgba8' ? 4 : format === 'rg8' ? 2 : 1;
6
+ }
7
+ /** Number of primitives in a mesh. */
8
+ export function primitiveCount(m) {
9
+ return m.primitive === 'lines' ? m.count / 2 : m.count / 3;
10
+ }
@@ -0,0 +1,167 @@
1
+ /** Rungs of the damage ladder of one part. */
2
+ export declare const DAMAGE: {
3
+ readonly intact: 0;
4
+ readonly cracked: 1;
5
+ readonly breached: 2;
6
+ readonly gone: 3;
7
+ };
8
+ export type DamageRung = (typeof DAMAGE)[keyof typeof DAMAGE];
9
+ /** Part flags. */
10
+ export declare const PART_FLAG: {
11
+ /** Touches the ground: the source of support in the connectivity test. */
12
+ readonly anchor: 1;
13
+ /** Never takes damage (ground, foundations). */
14
+ readonly indestructible: 2;
15
+ /** Lies inside the outline of its structure: it falls straight down and its rubble stays within its own footprint. */
16
+ readonly inner: 4;
17
+ };
18
+ /**
19
+ * Generic role of a part. The content decides which of its elements gets which role; the engine only uses the role
20
+ * to pick a default rubble archetype.
21
+ */
22
+ export declare const PART_ROLE: {
23
+ /** Under everything else, usually an anchor. */
24
+ readonly foundation: 0;
25
+ /** Carries what rests on it (a wall-like part). */
26
+ readonly bearing: 1;
27
+ /** Spans between bearing parts (a slab or cover section). */
28
+ readonly span: 2;
29
+ /** Hangs on the side of another part. */
30
+ readonly attached: 3;
31
+ /** Stands on top of another part. */
32
+ readonly fixture: 4;
33
+ };
34
+ export type PartRole = (typeof PART_ROLE)[keyof typeof PART_ROLE];
35
+ /**
36
+ * Convex piece of a part: a vertical prism over a convex polygon. `xz` holds the polygon corners as x, z pairs in
37
+ * centimetres, counter-clockwise when x points right and z points down (the same sense as a positive signed area
38
+ * of `x·z' − z·x'`). A box is a prism with four corners.
39
+ */
40
+ export interface ConvexPiece {
41
+ xz: Int32Array;
42
+ /** Bottom and top in centimetres. */
43
+ y0: number;
44
+ y1: number;
45
+ }
46
+ /** Thresholds of one destructible material in energy units. 0 for `breach` means the material has no breach rung. */
47
+ export interface DestructibleMaterial {
48
+ crack: number;
49
+ breach: number;
50
+ gone: number;
51
+ /** Density in kg/m³ of the solid the part stands for; turns mass into rubble volume. */
52
+ density: number;
53
+ }
54
+ /** One part of a structure. */
55
+ export interface StructurePart {
56
+ /**
57
+ * Stable key, unique inside the structure (unsigned 32-bit). It comes from the structure's input (a rule id and the
58
+ * part's path in the recipe), never from the order in which a generator emits geometry.
59
+ */
60
+ key: number;
61
+ role: PartRole;
62
+ /** Index into `StructureDesc.materials`. */
63
+ material: number;
64
+ /** Mass in kilograms. */
65
+ mass: number;
66
+ piece: ConvexPiece;
67
+ /** `PART_FLAG` bits. */
68
+ flags: number;
69
+ /**
70
+ * How many lateral bonds the part may hang from a part that rests on something below (a heuristic load path on
71
+ * top of plain connectivity). 255 = plain connectivity.
72
+ */
73
+ maxSpan: number;
74
+ }
75
+ /** A bond between two parts through a shared face. */
76
+ export interface StructureBond {
77
+ /** Part keys. For a bearing bond `a` is below and carries `b`. */
78
+ a: number;
79
+ b: number;
80
+ /** True when `b` rests on `a`; false for a lateral tie (side by side, or hanging on a side). */
81
+ bearing: boolean;
82
+ /** Centre of the shared face in centimetres and its area in cm². */
83
+ x: number;
84
+ y: number;
85
+ z: number;
86
+ area: number;
87
+ }
88
+ /** Everything the deterministic module needs to know about one structure. */
89
+ export interface StructureDesc {
90
+ /** Stable id of the structure (its anchor in the input), the key of its damage edit. */
91
+ id: number;
92
+ /** Protected: events never change it. */
93
+ keepOut: boolean;
94
+ /** Ground level under the structure and its centre, in centimetres. */
95
+ groundY: number;
96
+ cx: number;
97
+ cz: number;
98
+ /** Convex outline of the whole structure (x, z pairs in cm), the footprint of a ruin. */
99
+ outline: Int32Array;
100
+ materials: DestructibleMaterial[];
101
+ /** Sorted by key. */
102
+ parts: StructurePart[];
103
+ /** Sorted by (a, b). */
104
+ bonds: StructureBond[];
105
+ }
106
+ /**
107
+ * Damage entry of one part, packed into one integer: rung (2 bits), fall direction (4 bits, 0–7 compass octants
108
+ * counted from +x toward +z, 8 = straight down) and a variant (8 bits) chosen at the moment of the event.
109
+ * Rubble of a gone part is a pure function of the part and its entry.
110
+ */
111
+ export type DamageEntry = number;
112
+ export declare function packEntry(rung: DamageRung, dir: number, variant: number): DamageEntry;
113
+ export declare function entryRung(e: DamageEntry): DamageRung;
114
+ export declare function entryDir(e: DamageEntry): number;
115
+ export declare function entryVariant(e: DamageEntry): number;
116
+ /** Damage state of one structure: the authoritative edit. Intact parts have no entry. */
117
+ export interface StructureState {
118
+ structure: number;
119
+ /** Coarsened into a ruin (the budget was exceeded): every destructible part counts as gone. */
120
+ ruin: boolean;
121
+ parts: ReadonlyMap<number, DamageEntry>;
122
+ }
123
+ /** Rubble archetypes. */
124
+ export declare const RUBBLE: {
125
+ readonly heap: 0;
126
+ readonly slabs: 1;
127
+ readonly scatter: 2;
128
+ readonly ruin: 3;
129
+ };
130
+ export type RubbleArchetype = (typeof RUBBLE)[keyof typeof RUBBLE];
131
+ /**
132
+ * Where rubble lies: an oriented rectangle on the ground with a height. This is the only result of destruction that
133
+ * other systems (navigation, cover, saves) may read. Centimetres.
134
+ */
135
+ export interface RubbleFootprint {
136
+ structure: number;
137
+ /** Key of the part the rubble came from (0 for the ruin of a whole structure). */
138
+ part: number;
139
+ archetype: RubbleArchetype;
140
+ /** Material index of the source part, so the rubble has its colour. */
141
+ material: number;
142
+ cx: number;
143
+ cz: number;
144
+ y: number;
145
+ /** Unit long axis scaled by 1024. */
146
+ ux: number;
147
+ uz: number;
148
+ halfL: number;
149
+ halfW: number;
150
+ height: number;
151
+ /** Corners as x, z pairs, counter-clockwise. */
152
+ corners: Int32Array;
153
+ seed: number;
154
+ }
155
+ /**
156
+ * A canonical destruction event: what an input command or the simulation sends. Integers only, so the same event
157
+ * gives the same result everywhere. Position and radius in cm, energy in abstract units.
158
+ */
159
+ export interface DestructionEvent {
160
+ x: number;
161
+ y: number;
162
+ z: number;
163
+ radius: number;
164
+ energy: number;
165
+ seed: number;
166
+ tick: number;
167
+ }
@@ -0,0 +1,47 @@
1
+ // Destructible structures as data: the contract between a generator that knows a structure and the deterministic
2
+ // module that decides what breaks (sim/destruction). Destruction is state, not geometry: a structure is a graph of
3
+ // parts with stable keys, and its damage is a small map `part key → entry`. Geometry is regenerated from that map.
4
+ //
5
+ // Everything that takes part in a decision is an integer: positions and sizes in centimetres, mass in kilograms,
6
+ // energy in abstract units. Generators round their float geometry once, when they emit the description.
7
+ /** Rungs of the damage ladder of one part. */
8
+ export const DAMAGE = { intact: 0, cracked: 1, breached: 2, gone: 3 };
9
+ /** Part flags. */
10
+ export const PART_FLAG = {
11
+ /** Touches the ground: the source of support in the connectivity test. */
12
+ anchor: 1,
13
+ /** Never takes damage (ground, foundations). */
14
+ indestructible: 2,
15
+ /** Lies inside the outline of its structure: it falls straight down and its rubble stays within its own footprint. */
16
+ inner: 4,
17
+ };
18
+ /**
19
+ * Generic role of a part. The content decides which of its elements gets which role; the engine only uses the role
20
+ * to pick a default rubble archetype.
21
+ */
22
+ export const PART_ROLE = {
23
+ /** Under everything else, usually an anchor. */
24
+ foundation: 0,
25
+ /** Carries what rests on it (a wall-like part). */
26
+ bearing: 1,
27
+ /** Spans between bearing parts (a slab or cover section). */
28
+ span: 2,
29
+ /** Hangs on the side of another part. */
30
+ attached: 3,
31
+ /** Stands on top of another part. */
32
+ fixture: 4,
33
+ };
34
+ export function packEntry(rung, dir, variant) {
35
+ return (rung & 3) | ((dir & 15) << 2) | ((variant & 255) << 6);
36
+ }
37
+ export function entryRung(e) {
38
+ return (e & 3);
39
+ }
40
+ export function entryDir(e) {
41
+ return (e >> 2) & 15;
42
+ }
43
+ export function entryVariant(e) {
44
+ return (e >> 6) & 255;
45
+ }
46
+ /** Rubble archetypes. */
47
+ export const RUBBLE = { heap: 0, slabs: 1, scatter: 2, ruin: 3 };
@@ -0,0 +1,101 @@
1
+ import type { RGB, Vec3 } from './math.ts';
2
+ /**
3
+ * - `studio`: the light turns with the view
4
+ * - `day`: the sun follows its path for a place, date and hour
5
+ * - `fixed`: the light stands in one world direction with colours given directly (no camera, place or hour)
6
+ */
7
+ export type LightMode = 'studio' | 'day' | 'fixed';
8
+ /** Vertical extent of the fog layer: it is densest at `bottomY` and thins out toward `topY`. */
9
+ export interface FogLayer {
10
+ bottomY: number;
11
+ topY: number;
12
+ }
13
+ /** What one frame needs to know about the generic environment. */
14
+ export interface FrameEnvironment {
15
+ mode: LightMode;
16
+ /** Unit direction toward the light (sun or moon). */
17
+ toSun: Vec3;
18
+ /** Height of the sun above the horizon in degrees (in studio mode the studio light's height, in fixed mode the height above the xz plane). */
19
+ sunElevationDeg: number;
20
+ sun: RGB;
21
+ ambient: RGB;
22
+ skyFill: RGB;
23
+ bounce: RGB;
24
+ warmTint: RGB;
25
+ exposure: number;
26
+ /** Multiple of the background colour: 1 by day, dark blue at night. */
27
+ backdrop: RGB;
28
+ /** Animation time in seconds and hour of day. */
29
+ time: number;
30
+ hour: number;
31
+ /** Day of year (1–366). */
32
+ dayOfYear: number;
33
+ /** Wind: unit direction it blows toward (x, z), speed in m/s, gusts. */
34
+ windX: number;
35
+ windZ: number;
36
+ windSpeedMs: number;
37
+ gustLengthM: number;
38
+ gustSpeed: number;
39
+ /** Clouds: pattern offset in metres, darkening, size and noise thresholds. */
40
+ cloudX: number;
41
+ cloudZ: number;
42
+ cloudDarkness: number;
43
+ cloudSizeM: number;
44
+ cloudLo: number;
45
+ cloudHi: number;
46
+ /** Weather, all 0–1. */
47
+ cloudCover: number;
48
+ snowCover: number;
49
+ wetness: number;
50
+ fog: number;
51
+ /** Fog colour in screen space and the vertical extent of the fog layer. */
52
+ fogColor: RGB;
53
+ fogLayer: FogLayer;
54
+ precipitation: number;
55
+ /** 0 rain, 1 snow. */
56
+ precipitationKind: number;
57
+ snowAlbedo: RGB;
58
+ /** True unit direction toward the sun, also below the horizon (`toSun` is clamped and turns to the moon at night). */
59
+ sunDir: Vec3;
60
+ /** Unit direction toward the moon. */
61
+ moonDir: Vec3;
62
+ /** Sky colours as seen, in screen space: straight up, at the horizon, and the light scattered around the sun. */
63
+ skyZenith: RGB;
64
+ skyHorizon: RGB;
65
+ sunGlow: RGB;
66
+ }
67
+ /** Which region of the Frame block a member lives in: right after the light direction, or after the view axes. */
68
+ export type FrameRegion = 'afterLight' | 'afterView';
69
+ /**
70
+ * Part of one vec4 member of the Frame block. Several fields (from different slots) may share a member when their
71
+ * lanes do not overlap. Exactly one field per member gives `order`: members are sorted by it within their region.
72
+ * The engine's own members use multiples of 10.
73
+ */
74
+ export interface FrameField {
75
+ /** GLSL name of the vec4 member, for example `u_wind`. */
76
+ member: string;
77
+ /** Lanes this field fills, in order, for example `'zw'`. */
78
+ lanes: string;
79
+ /** Short description of the lanes for the comment in the block, for example `'z bend in metres, w flutter in metres'`. */
80
+ doc: string;
81
+ /** Position of the member within its region; only on the field that declares the member. */
82
+ order?: number;
83
+ /** Default `'afterView'`. */
84
+ region?: FrameRegion;
85
+ }
86
+ /**
87
+ * An environment slot. `compute` must be pure: the same generic state and params give the same values.
88
+ * `lanes` flattens the values into the lanes of `fields`, in order. The optional `glsl` (functions over the Frame
89
+ * members) is registered as the shader include `#include <name>`. `shadowKey` names the part of the values that
90
+ * changes the shadow map (for example how much light passes through a partly transparent occluder); the shadow map is redrawn when it changes.
91
+ */
92
+ export interface EnvSlot<P = unknown, V = unknown> {
93
+ readonly name: string;
94
+ /** Plain parameters; changes apply from the next frame. */
95
+ params: P;
96
+ readonly fields: readonly FrameField[];
97
+ compute(env: FrameEnvironment, params: P): V;
98
+ lanes(values: V): readonly number[];
99
+ readonly glsl?: string;
100
+ shadowKey?(values: V): string;
101
+ }
@@ -0,0 +1,8 @@
1
+ // The generic environment of one frame and the contract for environment slots.
2
+ //
3
+ // The engine's environment knows only time, sun and sky, light colours, fog, wind, clouds, precipitation, wetness and
4
+ // snow cover. Anything that interprets them for a particular kind of content (how foliage follows the season, how
5
+ // lit openings glow at night, where snow settles) is a slot: plain params, a pure compute from the generic state,
6
+ // the Frame block members it fills and optional GLSL. Content packages and apps define slots; the engine assembles
7
+ // them into one Frame block in a deterministic order.
8
+ export {};
@@ -0,0 +1,138 @@
1
+ import type { Vec3 } from './math.ts';
2
+ type V3 = readonly [number, number, number];
3
+ /** Rotation as a unit quaternion `[x, y, z, w]`. */
4
+ export type Quat = [number, number, number, number];
5
+ type Q4 = readonly [number, number, number, number];
6
+ export declare function quatIdentity(): Quat;
7
+ /** Rotation by `turns` (1 = 360°) about a unit axis, right-handed. */
8
+ export declare function quatAxisTurns(axis: V3, turns: number): Quat;
9
+ /** The rotation "first `b`, then `a`". */
10
+ export declare function quatMul(a: Q4, b: Q4): Quat;
11
+ /** The opposite rotation of a unit quaternion. */
12
+ export declare function quatConj(q: Q4): Quat;
13
+ export declare function quatNormalize(q: Q4): Quat;
14
+ /** Turns a vector by a unit quaternion. `out` may be the same array as `v`. */
15
+ export declare function quatRotate(q: Q4, v: V3, out?: Vec3): Vec3;
16
+ /** Rotation whose turned x, y and z axes are the given unit, mutually perpendicular, right-handed vectors. */
17
+ export declare function quatFromAxes(x: V3, y: V3, z: V3): Quat;
18
+ /** Where a frame sits in another frame: a local point p is at `origin + rotation · p` there. All 64-bit. */
19
+ export interface FramePose {
20
+ origin: Vec3;
21
+ rotation: Quat;
22
+ }
23
+ /** A point with its velocity, both in the coordinates of one frame and relative to that frame. */
24
+ export interface FrameState {
25
+ position: Vec3;
26
+ velocity: Vec3;
27
+ }
28
+ /** Unit direction and distance from a point to the origin of a frame. */
29
+ export interface FrameBearing {
30
+ direction: Vec3;
31
+ distance: number;
32
+ }
33
+ /** Parent of a top frame. */
34
+ export declare const FRAME_NONE = -1;
35
+ /**
36
+ * A hierarchy of frames. A frame is a small integer id; ids are given out in order and never reused. A top frame
37
+ * (parent `FRAME_NONE`) has no pose. Frames under different top frames cannot be converted to each other.
38
+ */
39
+ export declare class FrameSet {
40
+ private readonly parents;
41
+ private readonly names;
42
+ private data;
43
+ get count(): number;
44
+ /** Adds a frame under `parent` (a top frame when omitted) and returns its id. */
45
+ add(name: string, parent?: number, pose?: Partial<FramePose>): number;
46
+ private check;
47
+ name(id: number): string;
48
+ /** Id of the first frame with this name, or `FRAME_NONE`. */
49
+ find(name: string): number;
50
+ /** Parent of a frame, `FRAME_NONE` for a top frame. */
51
+ parent(id: number): number;
52
+ /** Number of frames above this one (0 for a top frame). */
53
+ depth(id: number): number;
54
+ /** Origin of the frame in its parent (metres, 64-bit). */
55
+ setOrigin(id: number, origin: V3): void;
56
+ /** Rotation of the frame in its parent (a unit quaternion). */
57
+ setRotation(id: number, rotation: Q4): void;
58
+ setPose(id: number, pose: FramePose): void;
59
+ /**
60
+ * How the frame moves in its parent: velocity of its origin (m/s) and its angular velocity (rad/s, the vector along
61
+ * the turning axis), both in parent coordinates. Only `convertState` and `reparent` read it; a frame that is moved
62
+ * by `setOrigin` alone counts as standing.
63
+ */
64
+ setMotion(id: number, velocity: V3, spin?: V3): void;
65
+ /** Pose of the frame in its parent (a copy). */
66
+ pose(id: number): FramePose;
67
+ /** Velocity of the frame's origin in its parent. */
68
+ velocity(id: number): Vec3;
69
+ /** Angular velocity of the frame in its parent. */
70
+ spin(id: number): Vec3;
71
+ /** The deepest frame that both frames lie in or under (either of them when one is above the other). */
72
+ commonAncestor(a: number, b: number): number;
73
+ /** One level up: from the coordinates of frame `f` to those of its parent. */
74
+ private up;
75
+ /** One level down: from the coordinates of the parent of frame `f` to those of `f`. */
76
+ private down;
77
+ /** Carries a point with its velocity, orientation and angular velocity from frame `from` to frame `to`. */
78
+ private carry;
79
+ /** A point given in frame `from`, in the coordinates of frame `to` (64-bit). */
80
+ convertPoint(p: V3, from: number, to: number, out?: Vec3): Vec3;
81
+ /** A direction (or any difference of two points) given in frame `from`, in the coordinates of frame `to`. */
82
+ convertDirection(d: V3, from: number, to: number, out?: Vec3): Vec3;
83
+ /** An orientation given in frame `from`, in the coordinates of frame `to`. */
84
+ convertRotation(q: Q4, from: number, to: number): Quat;
85
+ /**
86
+ * A point and its velocity given in (and relative to) frame `from`, in and relative to frame `to`. Uses the motion
87
+ * of the frames on the way (`setMotion`): a point standing on a turning frame moves when seen from its parent.
88
+ */
89
+ convertState(position: V3, velocity: V3, from: number, to: number): FrameState;
90
+ /** Pose of frame `from` in frame `to`: a point p of `from` is at `origin + rotation · p` in `to`. */
91
+ relativePose(from: number, to: number): FramePose;
92
+ /**
93
+ * Unit direction and distance from the point `at` of frame `frame` to the origin of frame `target`, in the
94
+ * coordinates of `frame`. With a light at the origin of `target` this is the direction toward the light.
95
+ */
96
+ directionTo(target: number, frame: number, at?: V3): FrameBearing;
97
+ /**
98
+ * Moves a frame under another parent without moving it: its pose, velocity and angular velocity are rewritten so
99
+ * that everything in it stays where it was. Both parents must lie under the same top frame, and the new parent
100
+ * must not be the frame itself or one of the frames below it. Do it on a simulation step, never between steps.
101
+ */
102
+ reparent(id: number, parent: number): void;
103
+ /**
104
+ * 32-bit digest of every bit of every frame (parents, poses, motion). Two runs that agree here agree exactly; use
105
+ * it to compare a stepped run with a jump in time, or one machine with another.
106
+ */
107
+ fingerprint(): number;
108
+ }
109
+ /**
110
+ * Model matrix for the GPU (4×4, column-major, 32-bit): takes the local coordinates of a frame to coordinates
111
+ * relative to the eye. `pose` is the frame in the frame the image is drawn in (`FrameSet.relativePose`), `eye` a
112
+ * point of that drawing frame (the camera or a render origin near it). The translation is the 64-bit difference
113
+ * `pose.origin − eye` and only then rounded, so it is small and exact near the eye.
114
+ */
115
+ export declare function relativeMatrix(pose: FramePose, eye: V3, out?: Float32Array): Float32Array;
116
+ /**
117
+ * 64-bit points (x, y, z triples) to 32-bit positions relative to the eye. With a `pose` the points are local to that
118
+ * frame and are first placed by it; with `null` they already are in the frame of the eye. The whole sum is done in
119
+ * 64 bits and rounded once.
120
+ */
121
+ export declare function relativePoints(points: ArrayLike<number>, pose: FramePose | null, eye: V3, out?: Float32Array): Float32Array;
122
+ /**
123
+ * Unit direction of a point of a sphere from latitude and longitude in degrees. +y is the pole of positive latitude;
124
+ * longitude 0 is +x and grows toward −z, which is the way a frame with a positive rotation about +y turns (east).
125
+ */
126
+ export declare function directionFromDeg(latitudeDeg: number, longitudeDeg: number): Vec3;
127
+ /** Latitude (−90 … 90) and longitude (−180 … 180) in degrees of a direction; the inverse of `directionFromDeg`. */
128
+ export declare function directionToDeg(dir: V3): {
129
+ latitudeDeg: number;
130
+ longitudeDeg: number;
131
+ };
132
+ /**
133
+ * Pose of a frame that touches a sphere around the parent's origin: its origin is `distance` along `up`, its +y is
134
+ * `up`, its +x points east (about the parent's +y) and its +z south, the axes of a flat map. At the pole of the
135
+ * parent's +y the axes are those of the parent.
136
+ */
137
+ export declare function tangentPose(up: V3, distance: number): FramePose;
138
+ export {};