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,94 @@
1
+ import type { Ring } from '../../gen-core/index.ts';
2
+ import type { PropBox } from '../../gen-mesh/index.ts';
3
+ import type { VertexLayout } from '../../base/index.ts';
4
+ /** What a vertex carries about its building or box. */
5
+ export interface VertexMaterial {
6
+ seed: number;
7
+ bayWidth: number;
8
+ wallColor: number;
9
+ roofColor: number;
10
+ windowStyle: number;
11
+ trimColor: number;
12
+ }
13
+ /** Façade data of one wall piece for the shader. Zero for roofs, boxes and buildings without a recipe. */
14
+ export interface WallAttr {
15
+ doorU: number;
16
+ doorW: number;
17
+ doorY: number;
18
+ groundFloorH: number;
19
+ /** Window width, height, sill and plinth height in metres (stored with 2 cm resolution). */
20
+ win: [number, number, number, number];
21
+ /** FACADE_FLAG bits, misc (mullions | ground floor kind << 2 | door kind << 4), shares, masks. */
22
+ bits: [number, number, number, number];
23
+ /** Palette rows: frame, plinth, door, accent. */
24
+ cols: [number, number, number, number];
25
+ }
26
+ export declare const NO_WALL_ATTR: WallAttr;
27
+ export declare const BUILDING_ATTRIBS: {
28
+ readonly a_pos: 0;
29
+ readonly a_normal: 1;
30
+ readonly a_surf: 2;
31
+ readonly a_bld: 3;
32
+ readonly a_mat: 4;
33
+ readonly a_fac: 5;
34
+ readonly a_win: 6;
35
+ readonly a_bits: 7;
36
+ readonly a_col: 8;
37
+ };
38
+ /** Kind of surface, fourth component of the normal (low three bits). `interior` only appears in a damaged structure. */
39
+ export declare const KIND: {
40
+ readonly wall: 0;
41
+ readonly roofPitched: 1;
42
+ readonly roofFlat: 2;
43
+ readonly trim: 3;
44
+ readonly interior: 4;
45
+ readonly wallInside: 5;
46
+ };
47
+ /**
48
+ * Vertex damage channel: the fourth component of the normal carries `kind + DAMAGE_STEP × damage`, damage 0 intact,
49
+ * 1 cracked, 2 heavily damaged (around a breach), 3 a cut or inner face of a damaged structure, 4 rubble.
50
+ */
51
+ export declare const DAMAGE_STEP = 8;
52
+ export declare const STRIDE = 80;
53
+ /** Vertex layout of the structure mesh (attribute locations in `BUILDING_ATTRIBS`). */
54
+ export declare const BUILDING_LAYOUT: VertexLayout;
55
+ /** Resolution of the window sizes packed into bytes. */
56
+ export declare const WIN_UNIT = 0.02;
57
+ /**
58
+ * Scale of the window height of an arched window (bit 7 of `bits[1]`): its height is stored in steps of
59
+ * `WIN_UNIT * WIN_TALL`, so it can reach 20.4 m.
60
+ */
61
+ export declare const WIN_TALL = 4;
62
+ /** Bit of `bits[1]` that marks an arched window. */
63
+ export declare const ARCH_WINDOW_BIT = 128;
64
+ export declare class VertexWriter {
65
+ private buf;
66
+ private f32;
67
+ private i8;
68
+ private u8;
69
+ count: number;
70
+ private grow;
71
+ push(x: number, y: number, z: number, nx: number, ny: number, nz: number, kind: number, s0: number, s1: number, s2: number, s3: number, b: VertexMaterial, floors: number, floorHeight: number, fa?: WallAttr): void;
72
+ /**
73
+ * Marks vertices `from`–`to` (exclusive) to grow in: from height `baseY` up to their place between clock times
74
+ * `start` and `start + seconds` (the vertex shader reads a negative a_fac.y as the mark).
75
+ */
76
+ growIn(from: number, to: number, start: number, seconds: number, baseY: number): void;
77
+ bytes(): Uint8Array;
78
+ }
79
+ /**
80
+ * Writes a box: four sides and the top. The bottom is skipped unless `underside` asks for it (a band under an overhang).
81
+ * `damage` goes into the vertex damage channel (see `KIND`), 0 for an intact box.
82
+ */
83
+ export declare function pushBox(w: VertexWriter, p: PropBox, damage?: number, underside?: boolean): void;
84
+ /** Box in front of a wall: `u0`–`u1` along the wall from point a in direction d, `d0`–`d1` out of the wall. */
85
+ export declare function wallBox(ax: number, az: number, dx: number, dz: number, u0: number, u1: number, d0: number, d1: number, baseY: number, height: number, color: number, hash: number): PropBox;
86
+ /** Do all four corners of the box, grown by `margin`, lie inside the rings? */
87
+ export declare function boxInside(p: {
88
+ cx: number;
89
+ cz: number;
90
+ ux: number;
91
+ uz: number;
92
+ halfL: number;
93
+ halfW: number;
94
+ }, rings: Ring[], margin: number): boolean;
@@ -0,0 +1,195 @@
1
+ // Vertex stream of the structure mesh and the box primitive written into it. Shared by the intact path
2
+ // (buildings.ts), the damaged path (damaged.ts) and the rubble generator (rubble.ts).
3
+ import { pointInRings, unit } from '../../gen-core/index.js';
4
+ export const NO_WALL_ATTR = { doorU: -1e4, doorW: 0, doorY: 0, groundFloorH: 0, win: [0, 0, 0, 0], bits: [0, 0, 0, 0], cols: [0, 0, 0, 0] };
5
+ export const BUILDING_ATTRIBS = { a_pos: 0, a_normal: 1, a_surf: 2, a_bld: 3, a_mat: 4, a_fac: 5, a_win: 6, a_bits: 7, a_col: 8 };
6
+ /** Kind of surface, fourth component of the normal (low three bits). `interior` only appears in a damaged structure. */
7
+ export const KIND = { wall: 0, roofPitched: 1, roofFlat: 2, trim: 3, interior: 4, wallInside: 5 };
8
+ /**
9
+ * Vertex damage channel: the fourth component of the normal carries `kind + DAMAGE_STEP × damage`, damage 0 intact,
10
+ * 1 cracked, 2 heavily damaged (around a breach), 3 a cut or inner face of a damaged structure, 4 rubble.
11
+ */
12
+ export const DAMAGE_STEP = 8;
13
+ export const STRIDE = 80;
14
+ /** Vertex layout of the structure mesh (attribute locations in `BUILDING_ATTRIBS`). */
15
+ export const BUILDING_LAYOUT = {
16
+ stride: STRIDE,
17
+ attribs: [
18
+ { name: 'a_pos', size: 3, type: 'f32', offset: 0 },
19
+ { name: 'a_normal', size: 4, type: 'i8', offset: 12 },
20
+ { name: 'a_surf', size: 4, type: 'f32', offset: 16 },
21
+ { name: 'a_bld', size: 4, type: 'f32', offset: 32 },
22
+ { name: 'a_mat', size: 4, type: 'u8', integer: true, offset: 48 },
23
+ { name: 'a_fac', size: 4, type: 'f32', offset: 52 },
24
+ { name: 'a_win', size: 4, type: 'u8', integer: true, offset: 68 },
25
+ { name: 'a_bits', size: 4, type: 'u8', integer: true, offset: 72 },
26
+ { name: 'a_col', size: 4, type: 'u8', integer: true, offset: 76 },
27
+ ],
28
+ };
29
+ /** Resolution of the window sizes packed into bytes. */
30
+ export const WIN_UNIT = 0.02;
31
+ /**
32
+ * Scale of the window height of an arched window (bit 7 of `bits[1]`): its height is stored in steps of
33
+ * `WIN_UNIT * WIN_TALL`, so it can reach 20.4 m.
34
+ */
35
+ export const WIN_TALL = 4;
36
+ /** Bit of `bits[1]` that marks an arched window. */
37
+ export const ARCH_WINDOW_BIT = 128;
38
+ export class VertexWriter {
39
+ buf = new ArrayBuffer(1 << 21);
40
+ f32 = new Float32Array(this.buf);
41
+ i8 = new Int8Array(this.buf);
42
+ u8 = new Uint8Array(this.buf);
43
+ count = 0;
44
+ grow() {
45
+ const next = new ArrayBuffer(this.buf.byteLength * 2);
46
+ new Uint8Array(next).set(this.u8);
47
+ this.buf = next;
48
+ this.f32 = new Float32Array(next);
49
+ this.i8 = new Int8Array(next);
50
+ this.u8 = new Uint8Array(next);
51
+ }
52
+ push(x, y, z, nx, ny, nz, kind, s0, s1, s2, s3, b, floors, floorHeight, fa = NO_WALL_ATTR) {
53
+ if ((this.count + 1) * STRIDE > this.buf.byteLength)
54
+ this.grow();
55
+ const o = this.count * STRIDE;
56
+ const f = o / 4;
57
+ this.f32[f] = x;
58
+ this.f32[f + 1] = y;
59
+ this.f32[f + 2] = z;
60
+ this.i8[o + 12] = Math.round(nx * 127);
61
+ this.i8[o + 13] = Math.round(ny * 127);
62
+ this.i8[o + 14] = Math.round(nz * 127);
63
+ this.i8[o + 15] = kind;
64
+ this.f32[f + 4] = s0;
65
+ this.f32[f + 5] = s1;
66
+ this.f32[f + 6] = s2;
67
+ this.f32[f + 7] = s3;
68
+ this.f32[f + 8] = floorHeight;
69
+ this.f32[f + 9] = floors;
70
+ this.f32[f + 10] = b.seed;
71
+ this.f32[f + 11] = b.bayWidth;
72
+ this.u8[o + 48] = b.wallColor;
73
+ this.u8[o + 49] = b.roofColor;
74
+ this.u8[o + 50] = b.windowStyle;
75
+ this.u8[o + 51] = b.trimColor;
76
+ this.f32[f + 13] = fa.doorU;
77
+ this.f32[f + 14] = fa.doorW;
78
+ this.f32[f + 15] = fa.doorY;
79
+ this.f32[f + 16] = fa.groundFloorH;
80
+ for (let k = 0; k < 4; k++) {
81
+ const step = k === 1 && fa.bits[1] & ARCH_WINDOW_BIT ? WIN_UNIT * WIN_TALL : WIN_UNIT;
82
+ this.u8[o + 68 + k] = Math.max(0, Math.min(255, Math.round(fa.win[k] / step)));
83
+ this.u8[o + 72 + k] = fa.bits[k];
84
+ this.u8[o + 76 + k] = fa.cols[k];
85
+ }
86
+ this.count++;
87
+ }
88
+ /**
89
+ * Marks vertices `from`–`to` (exclusive) to grow in: from height `baseY` up to their place between clock times
90
+ * `start` and `start + seconds` (the vertex shader reads a negative a_fac.y as the mark).
91
+ */
92
+ growIn(from, to, start, seconds, baseY) {
93
+ for (let i = from; i < to; i++) {
94
+ const f = (i * STRIDE) / 4;
95
+ this.f32[f + 13] = start;
96
+ this.f32[f + 14] = -Math.max(1e-3, seconds);
97
+ this.f32[f + 15] = baseY;
98
+ }
99
+ }
100
+ bytes() {
101
+ return new Uint8Array(this.buf, 0, this.count * STRIDE);
102
+ }
103
+ }
104
+ /**
105
+ * Writes a box: four sides and the top. The bottom is skipped unless `underside` asks for it (a band under an overhang).
106
+ * `damage` goes into the vertex damage channel (see `KIND`), 0 for an intact box.
107
+ */
108
+ export function pushBox(w, p, damage = 0, underside = false) {
109
+ const mat = { seed: unit(p.hash), bayWidth: 1, wallColor: p.color, roofColor: p.color, windowStyle: 0, trimColor: p.color };
110
+ const vx = -p.uz;
111
+ const vz = p.ux;
112
+ // Corners in the same winding as footprint rings (positive orientation in the x, z plane).
113
+ const signs = [
114
+ [-1, -1],
115
+ [1, -1],
116
+ [1, 1],
117
+ [-1, 1],
118
+ ];
119
+ const corners = signs.map(([su, sv]) => [
120
+ p.cx + p.ux * p.halfL * su + vx * p.halfW * sv,
121
+ p.baseY + p.slope * p.halfL * su,
122
+ p.cz + p.uz * p.halfL * su + vz * p.halfW * sv,
123
+ ]);
124
+ const v = (c, up, nx, ny, nz) => w.push(c[0], c[1] + up, c[2], nx, ny, nz, KIND.trim + DAMAGE_STEP * damage, 0, 0, up, 100, mat, 1, 3);
125
+ for (let i = 0; i < 4; i++) {
126
+ const a = corners[i];
127
+ const b = corners[(i + 1) % 4];
128
+ const len = Math.hypot(b[0] - a[0], b[2] - a[2]) || 1;
129
+ const nx = (b[2] - a[2]) / len;
130
+ const nz = -(b[0] - a[0]) / len;
131
+ v(a, 0, nx, 0, nz);
132
+ v(b, p.height, nx, 0, nz);
133
+ v(b, 0, nx, 0, nz);
134
+ v(a, 0, nx, 0, nz);
135
+ v(a, p.height, nx, 0, nz);
136
+ v(b, p.height, nx, 0, nz);
137
+ }
138
+ const c0 = corners[0];
139
+ const c1 = corners[1];
140
+ const c2 = corners[2];
141
+ const c3 = corners[3];
142
+ v(c0, p.height, 0, 1, 0);
143
+ v(c3, p.height, 0, 1, 0);
144
+ v(c1, p.height, 0, 1, 0);
145
+ v(c1, p.height, 0, 1, 0);
146
+ v(c3, p.height, 0, 1, 0);
147
+ v(c2, p.height, 0, 1, 0);
148
+ if (underside) {
149
+ // Bottom face, looking down: the winding of the top reversed.
150
+ v(c0, 0, 0, -1, 0);
151
+ v(c1, 0, 0, -1, 0);
152
+ v(c3, 0, 0, -1, 0);
153
+ v(c1, 0, 0, -1, 0);
154
+ v(c2, 0, 0, -1, 0);
155
+ v(c3, 0, 0, -1, 0);
156
+ }
157
+ }
158
+ /** Box in front of a wall: `u0`–`u1` along the wall from point a in direction d, `d0`–`d1` out of the wall. */
159
+ export function wallBox(ax, az, dx, dz, u0, u1, d0, d1, baseY, height, color, hash) {
160
+ const um = (u0 + u1) / 2;
161
+ const dm = (d0 + d1) / 2;
162
+ const nx = dz;
163
+ const nz = -dx;
164
+ const long = u1 - u0 >= d1 - d0;
165
+ return {
166
+ cx: ax + dx * um + nx * dm,
167
+ cz: az + dz * um + nz * dm,
168
+ baseY,
169
+ ux: long ? dx : nx,
170
+ uz: long ? dz : nz,
171
+ halfL: (long ? u1 - u0 : d1 - d0) / 2,
172
+ halfW: (long ? d1 - d0 : u1 - u0) / 2,
173
+ height,
174
+ slope: 0,
175
+ color,
176
+ hash,
177
+ };
178
+ }
179
+ /** Do all four corners of the box, grown by `margin`, lie inside the rings? */
180
+ export function boxInside(p, rings, margin) {
181
+ if (!pointInRings(p.cx, p.cz, rings))
182
+ return false;
183
+ for (const [su, sv] of [
184
+ [-1, -1],
185
+ [1, -1],
186
+ [1, 1],
187
+ [-1, 1],
188
+ ]) {
189
+ const x = p.cx + p.ux * (p.halfL + margin) * su - p.uz * (p.halfW + margin) * sv;
190
+ const z = p.cz + p.uz * (p.halfL + margin) * su + p.ux * (p.halfW + margin) * sv;
191
+ if (!pointInRings(x, z, rings))
192
+ return false;
193
+ }
194
+ return true;
195
+ }
@@ -0,0 +1,138 @@
1
+ import type { MeshData, InstanceData } from '../base/data.ts';
2
+ import type { Vec3 } from '../base/math.ts';
3
+ /** Face of a flat world (0–5 are reserved for the faces of a cube-sphere, 6 is reserved). */
4
+ export declare const FACE_FLAT = 7;
5
+ /** Edge of the root tile of a flat world (level 0). */
6
+ export declare const FLAT_ROOT_EDGE_M = 65536;
7
+ /** Named levels of a flat world: region 4,096 m, district 1,024 m, streaming cell 256 m. */
8
+ export declare const LEVEL: {
9
+ readonly region: 4;
10
+ readonly district: 6;
11
+ readonly cell: 8;
12
+ };
13
+ export interface CellId {
14
+ readonly face: number;
15
+ readonly level: number;
16
+ readonly x: number;
17
+ readonly y: number;
18
+ }
19
+ export declare function cellId(face: number, level: number, x: number, y: number): CellId;
20
+ /** Text form `face/level/x/y`, coordinates without the offset (for example `7/8/12/-3`). Exact and usable as a map key. */
21
+ export declare function cellKey(c: CellId): string;
22
+ export declare function parseCellKey(key: string): CellId;
23
+ /** The 64-bit id as unsigned 32-bit halves [high, low]. */
24
+ export declare function cellBits(c: CellId): [number, number];
25
+ export declare function cellFromBits(hi: number, lo: number): CellId;
26
+ export declare function sameCell(a: CellId, b: CellId): boolean;
27
+ /** Total order: level, then y, then x. Used wherever a deterministic order of cells is needed. */
28
+ export declare function compareCells(a: CellId, b: CellId): number;
29
+ /** World position in metres, double precision: x east, y up, z south. */
30
+ export type WorldPos = readonly [number, number, number];
31
+ /** Axis-aligned box in cell-local metres (floats relative to the cell origin). */
32
+ export interface LocalBounds {
33
+ min: Vec3;
34
+ max: Vec3;
35
+ }
36
+ /**
37
+ * The world shape port: everything that differs between a flat world and a planet. Only the flat implementation
38
+ * exists; code above it asks the port for cell sizes, distances, origins and "up" instead of assuming them.
39
+ */
40
+ export interface WorldShape {
41
+ readonly name: string;
42
+ /** Edge of a cell of this level in metres. Cell size is a query, never an engine constant. */
43
+ edgeM(level: number): number;
44
+ /** Cell of the given level that contains a world position. */
45
+ cellAt(p: WorldPos, level: number): CellId;
46
+ /** Origin of the cell frame in world metres (double). Cell data are relative to it. */
47
+ origin(c: CellId): WorldPos;
48
+ /** Position relative to the cell origin, rounded to float. */
49
+ toLocal(c: CellId, p: WorldPos): Vec3;
50
+ /** World position of a cell-local point (double). */
51
+ toWorld(c: CellId, local: readonly [number, number, number]): WorldPos;
52
+ /**
53
+ * Distance along the surface from the point below (or above) a world position to the cell's footprint, 0 inside it.
54
+ * The height of the position above the surface is not part of it; streaming adds it as the ticket's altitude.
55
+ */
56
+ distanceM(c: CellId, p: WorldPos): number;
57
+ /** Middle of the cell's footprint on the base surface (world metres, double). */
58
+ center(c: CellId): WorldPos;
59
+ /**
60
+ * Cells of `level` whose footprint may lie within `reachM` (measured as `distanceM`) of a world position, in a fixed
61
+ * order. A superset is fine: the caller tests every cell with `distanceM`. Streaming finds its coarsest cells here.
62
+ */
63
+ cellsNear(p: WorldPos, reachM: number, level: number): CellId[];
64
+ /** Cells sharing an edge or a corner, in a fixed order. */
65
+ neighbours(c: CellId): CellId[];
66
+ /** Cell one level coarser that contains this one, or null at the root. */
67
+ parent(c: CellId): CellId | null;
68
+ /** The cells one level finer that cover this one, in a fixed order. */
69
+ children(c: CellId): CellId[];
70
+ /** Unit "up" at a world position. */
71
+ upAt(p: WorldPos): Vec3;
72
+ /** Coordinates that seamless noise is evaluated at (a flat world returns x, z, 0). */
73
+ noiseDomain(p: WorldPos): [number, number, number];
74
+ /** Short text that identifies the shape and its parameters (enters cache keys and file headers). */
75
+ readonly hashKey: string;
76
+ }
77
+ /** A flat, unbounded world on the XZ plane with a quadtree of square cells. */
78
+ export declare class FlatWorld implements WorldShape {
79
+ readonly name = "flat";
80
+ readonly rootEdgeM: number;
81
+ readonly hashKey: string;
82
+ constructor(rootEdgeM?: number);
83
+ edgeM(level: number): number;
84
+ cellAt(p: WorldPos, level: number): CellId;
85
+ origin(c: CellId): WorldPos;
86
+ toLocal(c: CellId, p: WorldPos): Vec3;
87
+ toWorld(c: CellId, local: readonly [number, number, number]): WorldPos;
88
+ distanceM(c: CellId, p: WorldPos): number;
89
+ center(c: CellId): WorldPos;
90
+ cellsNear(p: WorldPos, reachM: number, level: number): CellId[];
91
+ neighbours(c: CellId): CellId[];
92
+ parent(c: CellId): CellId | null;
93
+ children(c: CellId): CellId[];
94
+ upAt(): Vec3;
95
+ noiseDomain(p: WorldPos): [number, number, number];
96
+ }
97
+ /**
98
+ * The shape's `hashKey` as an unsigned 32-bit number, never 0. It is written into shaped cell files and into their
99
+ * path, so cells built for one shape (or one radius, or one root edge) are never read as cells of another.
100
+ */
101
+ export declare function shapeHash(shape: Pick<WorldShape, 'hashKey'>): number;
102
+ /** One mesh of a cell, drawn with a material the application registered under this name. */
103
+ export interface CellMesh {
104
+ material: string;
105
+ mesh: MeshData;
106
+ }
107
+ /** Instances of one archetype (a shared shape with its level-of-detail chain) placed in a cell. */
108
+ export interface CellInstances {
109
+ archetype: string;
110
+ /** Positions relative to the cell origin. */
111
+ data: InstanceData;
112
+ /** Stable 64-bit object ids from the input-space anchor, as [high, low] pairs, one pair per instance. */
113
+ ids: Uint32Array;
114
+ }
115
+ /**
116
+ * What a cell holds once it is MESHED: meshes and instances as plain data, relative to the cell origin, and their
117
+ * extent. A generator and a pre-baked file produce exactly this, byte for byte.
118
+ */
119
+ export interface CellContent {
120
+ cell: CellId;
121
+ /** Version of the generator domain the cell was built with. */
122
+ domainVersion: number;
123
+ bounds: LocalBounds;
124
+ meshes: CellMesh[];
125
+ instances: CellInstances[];
126
+ /**
127
+ * `shapeHash` of the world shape the cell was built for. Optional: a cell that states it (or `error`) is encoded in
128
+ * format 2, a cell without both keeps format 1 and its bytes.
129
+ */
130
+ shapeHash?: number;
131
+ /**
132
+ * Largest distance in metres between this cell's surface and the surface its children would show (an estimate is
133
+ * fine). Streaming by screen-space error skips the split of a cell whose error is too small to see.
134
+ */
135
+ error?: number;
136
+ }
137
+ /** Bytes of the typed arrays a cell holds. */
138
+ export declare function cellContentBytes(c: CellContent): number;
@@ -0,0 +1,150 @@
1
+ // Cell identity and world shape (Wallhammer Zero CONVENTIONS §2–§3, `eng_cell_id` and the world shape port).
2
+ //
3
+ // A cell id is the 64-bit number `[face:3][level:5][x:28][y:28]`. In JavaScript it is a small frozen object with
4
+ // four integers, because a plain number holds only 53 bits exactly and a BigInt is slow to hash and compare. Two exact
5
+ // encodings exist next to it: the text key `face/level/x/y` (map key, log, file names; x and y without the offset) and
6
+ // the 64-bit value as two unsigned 32-bit halves (`cellBits`, for files and hashes).
7
+ //
8
+ // This engine is y-up: the map is the XZ plane, x east, z south. A cell's `x` index runs along +x and its `y` index
9
+ // along +z. The authoritative position is a double; cell data are floats relative to the cell origin, and only
10
+ // differences of doubles near the camera ever become floats.
11
+ import { hashString } from './hash.js';
12
+ /** Face of a flat world (0–5 are reserved for the faces of a cube-sphere, 6 is reserved). */
13
+ export const FACE_FLAT = 7;
14
+ /** Offset that makes negative grid coordinates unsigned in the 28-bit fields. */
15
+ const XY_OFFSET = 2 ** 27;
16
+ const XY_MASK = 2 ** 28 - 1;
17
+ /** Edge of the root tile of a flat world (level 0). */
18
+ export const FLAT_ROOT_EDGE_M = 65536;
19
+ /** Named levels of a flat world: region 4,096 m, district 1,024 m, streaming cell 256 m. */
20
+ export const LEVEL = { region: 4, district: 6, cell: 8 };
21
+ export function cellId(face, level, x, y) {
22
+ if (!(face >= 0 && face <= 7 && level >= 0 && level <= 31) || x < -XY_OFFSET || x >= XY_OFFSET || y < -XY_OFFSET || y >= XY_OFFSET) {
23
+ throw new Error(`cell id out of range: ${face}/${level}/${x}/${y}`);
24
+ }
25
+ return Object.freeze({ face, level, x: x | 0, y: y | 0 });
26
+ }
27
+ /** Text form `face/level/x/y`, coordinates without the offset (for example `7/8/12/-3`). Exact and usable as a map key. */
28
+ export function cellKey(c) {
29
+ return `${c.face}/${c.level}/${c.x}/${c.y}`;
30
+ }
31
+ export function parseCellKey(key) {
32
+ const p = key.split('/').map(Number);
33
+ if (p.length !== 4 || p.some((v) => !Number.isInteger(v)))
34
+ throw new Error(`not a cell key: ${key}`);
35
+ return cellId(p[0], p[1], p[2], p[3]);
36
+ }
37
+ /** The 64-bit id as unsigned 32-bit halves [high, low]. */
38
+ export function cellBits(c) {
39
+ const X = c.x + XY_OFFSET;
40
+ const Y = c.y + XY_OFFSET;
41
+ const hi = ((c.face << 29) | (c.level << 24) | Math.floor(X / 16)) >>> 0;
42
+ const lo = (((X & 15) << 28) | Y) >>> 0;
43
+ return [hi, lo];
44
+ }
45
+ export function cellFromBits(hi, lo) {
46
+ const face = hi >>> 29;
47
+ const level = (hi >>> 24) & 31;
48
+ const X = (hi & 0xffffff) * 16 + (lo >>> 28);
49
+ const Y = lo & XY_MASK;
50
+ return cellId(face, level, X - XY_OFFSET, Y - XY_OFFSET);
51
+ }
52
+ export function sameCell(a, b) {
53
+ return a.face === b.face && a.level === b.level && a.x === b.x && a.y === b.y;
54
+ }
55
+ /** Total order: level, then y, then x. Used wherever a deterministic order of cells is needed. */
56
+ export function compareCells(a, b) {
57
+ return a.face - b.face || a.level - b.level || a.y - b.y || a.x - b.x;
58
+ }
59
+ /** A flat, unbounded world on the XZ plane with a quadtree of square cells. */
60
+ export class FlatWorld {
61
+ name = 'flat';
62
+ rootEdgeM;
63
+ hashKey;
64
+ constructor(rootEdgeM = FLAT_ROOT_EDGE_M) {
65
+ this.rootEdgeM = rootEdgeM;
66
+ this.hashKey = `flat:${rootEdgeM}`;
67
+ }
68
+ edgeM(level) {
69
+ // A power-of-two division: exact.
70
+ return this.rootEdgeM / 2 ** level;
71
+ }
72
+ cellAt(p, level) {
73
+ const e = this.edgeM(level);
74
+ return cellId(FACE_FLAT, level, Math.floor(p[0] / e), Math.floor(p[2] / e));
75
+ }
76
+ origin(c) {
77
+ const e = this.edgeM(c.level);
78
+ return [c.x * e, 0, c.y * e];
79
+ }
80
+ toLocal(c, p) {
81
+ const o = this.origin(c);
82
+ return [Math.fround(p[0] - o[0]), Math.fround(p[1] - o[1]), Math.fround(p[2] - o[2])];
83
+ }
84
+ toWorld(c, local) {
85
+ const o = this.origin(c);
86
+ return [o[0] + local[0], o[1] + local[1], o[2] + local[2]];
87
+ }
88
+ distanceM(c, p) {
89
+ const e = this.edgeM(c.level);
90
+ const x0 = c.x * e;
91
+ const z0 = c.y * e;
92
+ const dx = p[0] < x0 ? x0 - p[0] : p[0] > x0 + e ? p[0] - x0 - e : 0;
93
+ const dz = p[2] < z0 ? z0 - p[2] : p[2] > z0 + e ? p[2] - z0 - e : 0;
94
+ return Math.sqrt(dx * dx + dz * dz);
95
+ }
96
+ center(c) {
97
+ const e = this.edgeM(c.level);
98
+ return [c.x * e + e / 2, 0, c.y * e + e / 2];
99
+ }
100
+ cellsNear(p, reachM, level) {
101
+ const lo = this.cellAt([p[0] - reachM, 0, p[2] - reachM], level);
102
+ const hi = this.cellAt([p[0] + reachM, 0, p[2] + reachM], level);
103
+ const out = [];
104
+ for (let y = lo.y; y <= hi.y; y++)
105
+ for (let x = lo.x; x <= hi.x; x++)
106
+ out.push(cellId(FACE_FLAT, level, x, y));
107
+ return out;
108
+ }
109
+ neighbours(c) {
110
+ const out = [];
111
+ for (let dy = -1; dy <= 1; dy++)
112
+ for (let dx = -1; dx <= 1; dx++)
113
+ if (dx !== 0 || dy !== 0)
114
+ out.push(cellId(c.face, c.level, c.x + dx, c.y + dy));
115
+ return out;
116
+ }
117
+ parent(c) {
118
+ if (c.level === 0)
119
+ return null;
120
+ return cellId(c.face, c.level - 1, Math.floor(c.x / 2), Math.floor(c.y / 2));
121
+ }
122
+ children(c) {
123
+ const l = c.level + 1;
124
+ const x = c.x * 2;
125
+ const y = c.y * 2;
126
+ return [cellId(c.face, l, x, y), cellId(c.face, l, x + 1, y), cellId(c.face, l, x, y + 1), cellId(c.face, l, x + 1, y + 1)];
127
+ }
128
+ upAt() {
129
+ return [0, 1, 0];
130
+ }
131
+ noiseDomain(p) {
132
+ return [p[0], p[2], 0];
133
+ }
134
+ }
135
+ /**
136
+ * The shape's `hashKey` as an unsigned 32-bit number, never 0. It is written into shaped cell files and into their
137
+ * path, so cells built for one shape (or one radius, or one root edge) are never read as cells of another.
138
+ */
139
+ export function shapeHash(shape) {
140
+ return hashString(shape.hashKey) || 1;
141
+ }
142
+ /** Bytes of the typed arrays a cell holds. */
143
+ export function cellContentBytes(c) {
144
+ let n = 0;
145
+ for (const m of c.meshes)
146
+ n += m.mesh.vertices.byteLength + (m.mesh.indices?.byteLength ?? 0);
147
+ for (const i of c.instances)
148
+ n += i.data.data.byteLength + i.ids.byteLength;
149
+ return n;
150
+ }
@@ -0,0 +1,57 @@
1
+ import type { Vec3 } from '../base/math.ts';
2
+ type V3 = readonly [number, number, number];
3
+ /** Grid axes `u`, `v` and the outward axis `n` of each face of the cube. */
4
+ export declare const CUBE_FACE_AXES: readonly {
5
+ readonly u: V3;
6
+ readonly v: V3;
7
+ readonly n: V3;
8
+ }[];
9
+ /**
10
+ * Face coordinate (−1 … 1, equal angles) of grid line `g` out of `count` intervals across the face. Line `count − g`
11
+ * gives exactly the negated value, and a line of a finer grid that coincides with this one gives the same bits.
12
+ */
13
+ export declare function cubeGrid(g: number, count: number): number;
14
+ /**
15
+ * The warp: face coordinate (−1 … 1, proportional to the angle from the face's middle) → position on the face of the
16
+ * cube (−1 … 1), `tan(s · π/4)`. Odd, and exactly ±1 at ±1. Defined a little beyond the face as well.
17
+ */
18
+ export declare function cubeWarp(s: number): number;
19
+ /** Inverse of `cubeWarp`. */
20
+ export declare function cubeUnwarp(t: number): number;
21
+ /** Unit direction from the centre to the point of `face` at warped coordinates (`cubeWarp` of the face coordinates). */
22
+ export declare function cubeDirectionWarped(face: number, wu: number, wv: number, out?: Vec3): Vec3;
23
+ /** Unit direction from the centre to the point of `face` at face coordinates `s`, `t` (−1 … 1). */
24
+ export declare function cubeDirection(face: number, s: number, t: number, out?: Vec3): Vec3;
25
+ /** The face a direction points at (the first of x, y, z among equals) and its face coordinates there (−1 … 1). */
26
+ export declare function cubeFaceOf(dir: V3): {
27
+ face: number;
28
+ s: number;
29
+ t: number;
30
+ };
31
+ /**
32
+ * Face coordinates of a direction on a given face, not clamped: beyond ±1 the direction points past the face's edge.
33
+ * Only directions on the face's side of the centre have coordinates; for the others the result is [NaN, NaN].
34
+ */
35
+ export declare function cubeFaceCoords(face: number, dir: V3): [number, number];
36
+ /**
37
+ * The cell `dx`, `dy` cells away from cell (`x`, `y`) of `face` at `level`, across an edge of the face if need be.
38
+ * Null when the step leaves the face over a corner of the cube: three faces meet there and no cell lies diagonally.
39
+ *
40
+ * Exact integer geometry: the cell's middle is taken on the cube in half-cell units, the part that sticks out past
41
+ * the face's edge is folded round the edge onto the next face, and that face's indices are read back.
42
+ */
43
+ export declare function cubeNeighbour(face: number, level: number, x: number, y: number, dx: number, dy: number): {
44
+ face: number;
45
+ x: number;
46
+ y: number;
47
+ } | null;
48
+ /**
49
+ * Two unit directions across `dir` that depend on `dir` alone (not on a face or a grid): `t1` is square to `dir` and
50
+ * to the world axis `dir` leans on least, `t2 = dir × t1`, so `t1 × t2 = dir`. Differences taken along them give the
51
+ * same result wherever the point is reached from.
52
+ */
53
+ export declare function directionTangents(dir: V3): {
54
+ t1: Vec3;
55
+ t2: Vec3;
56
+ };
57
+ export {};