wallhammer-web 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (408) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -2
  3. package/dist/base/data.d.ts +67 -0
  4. package/dist/base/data.js +10 -0
  5. package/dist/base/destructible.d.ts +167 -0
  6. package/dist/base/destructible.js +47 -0
  7. package/dist/base/env-slot.d.ts +101 -0
  8. package/dist/base/env-slot.js +8 -0
  9. package/dist/base/frames.d.ts +138 -0
  10. package/dist/base/frames.js +459 -0
  11. package/dist/base/index.d.ts +21 -0
  12. package/dist/base/index.js +11 -0
  13. package/dist/base/mat34.d.ts +46 -0
  14. package/dist/base/mat34.js +173 -0
  15. package/dist/base/material.d.ts +87 -0
  16. package/dist/base/material.js +6 -0
  17. package/dist/base/math.d.ts +27 -0
  18. package/dist/base/math.js +60 -0
  19. package/dist/base/progress.d.ts +38 -0
  20. package/dist/base/progress.js +81 -0
  21. package/dist/base/rig.d.ts +177 -0
  22. package/dist/base/rig.js +97 -0
  23. package/dist/base/trig.d.ts +29 -0
  24. package/dist/base/trig.js +169 -0
  25. package/dist/base/up.d.ts +26 -0
  26. package/dist/base/up.js +40 -0
  27. package/dist/base/view.d.ts +128 -0
  28. package/dist/base/view.js +136 -0
  29. package/dist/camera/camera.d.ts +99 -0
  30. package/dist/camera/camera.js +228 -0
  31. package/dist/camera/follow.d.ts +120 -0
  32. package/dist/camera/follow.js +320 -0
  33. package/dist/camera/free.d.ts +153 -0
  34. package/dist/camera/free.js +359 -0
  35. package/dist/camera/index.d.ts +10 -0
  36. package/dist/camera/index.js +6 -0
  37. package/dist/camera/orbit.d.ts +93 -0
  38. package/dist/camera/orbit.js +261 -0
  39. package/dist/camera/path.d.ts +48 -0
  40. package/dist/camera/path.js +179 -0
  41. package/dist/core/ballistic.d.ts +66 -0
  42. package/dist/core/ballistic.js +104 -0
  43. package/dist/core/bodies.d.ts +77 -0
  44. package/dist/core/bodies.js +125 -0
  45. package/dist/core/clock.d.ts +37 -0
  46. package/dist/core/clock.js +87 -0
  47. package/dist/core/cover-fade.d.ts +14 -0
  48. package/dist/core/cover-fade.js +38 -0
  49. package/dist/core/index.d.ts +13 -0
  50. package/dist/core/index.js +8 -0
  51. package/dist/core/kepler.d.ts +74 -0
  52. package/dist/core/kepler.js +108 -0
  53. package/dist/core/level-fade.d.ts +66 -0
  54. package/dist/core/level-fade.js +123 -0
  55. package/dist/core/palette.d.ts +15 -0
  56. package/dist/core/palette.js +47 -0
  57. package/dist/env/atmosphere.d.ts +129 -0
  58. package/dist/env/atmosphere.js +707 -0
  59. package/dist/env/cloud-field.d.ts +44 -0
  60. package/dist/env/cloud-field.js +111 -0
  61. package/dist/env/environment.d.ts +217 -0
  62. package/dist/env/environment.js +441 -0
  63. package/dist/env/frame-block.d.ts +29 -0
  64. package/dist/env/frame-block.js +152 -0
  65. package/dist/env/glsl.d.ts +35 -0
  66. package/dist/env/glsl.js +246 -0
  67. package/dist/env/index.d.ts +13 -0
  68. package/dist/env/index.js +9 -0
  69. package/dist/env/sky.d.ts +48 -0
  70. package/dist/env/sky.js +227 -0
  71. package/dist/env/sun.d.ts +31 -0
  72. package/dist/env/sun.js +42 -0
  73. package/dist/gen-arch/build.d.ts +17 -0
  74. package/dist/gen-arch/build.js +414 -0
  75. package/dist/gen-arch/damage/damaged.d.ts +44 -0
  76. package/dist/gen-arch/damage/damaged.js +1119 -0
  77. package/dist/gen-arch/damage/fall-material.d.ts +10 -0
  78. package/dist/gen-arch/damage/fall-material.js +47 -0
  79. package/dist/gen-arch/damage/fall.d.ts +78 -0
  80. package/dist/gen-arch/damage/fall.js +797 -0
  81. package/dist/gen-arch/damage/rubble.d.ts +22 -0
  82. package/dist/gen-arch/damage/rubble.js +188 -0
  83. package/dist/gen-arch/index.d.ts +25 -0
  84. package/dist/gen-arch/index.js +16 -0
  85. package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
  86. package/dist/gen-arch/interior/interior-plan.js +615 -0
  87. package/dist/gen-arch/interior/interior.d.ts +97 -0
  88. package/dist/gen-arch/interior/interior.js +966 -0
  89. package/dist/gen-arch/structure/building-shader.d.ts +25 -0
  90. package/dist/gen-arch/structure/building-shader.js +946 -0
  91. package/dist/gen-arch/structure/buildings.d.ts +248 -0
  92. package/dist/gen-arch/structure/buildings.js +294 -0
  93. package/dist/gen-arch/structure/dims.d.ts +77 -0
  94. package/dist/gen-arch/structure/dims.js +39 -0
  95. package/dist/gen-arch/structure/distant.d.ts +62 -0
  96. package/dist/gen-arch/structure/distant.js +316 -0
  97. package/dist/gen-arch/structure/env-slots.d.ts +18 -0
  98. package/dist/gen-arch/structure/env-slots.js +47 -0
  99. package/dist/gen-arch/structure/facade.d.ts +193 -0
  100. package/dist/gen-arch/structure/facade.js +159 -0
  101. package/dist/gen-arch/structure/parts.d.ts +31 -0
  102. package/dist/gen-arch/structure/parts.js +69 -0
  103. package/dist/gen-arch/structure/roof.d.ts +76 -0
  104. package/dist/gen-arch/structure/roof.js +568 -0
  105. package/dist/gen-arch/structure/structure-material.d.ts +23 -0
  106. package/dist/gen-arch/structure/structure-material.js +55 -0
  107. package/dist/gen-arch/structure/writer.d.ts +94 -0
  108. package/dist/gen-arch/structure/writer.js +195 -0
  109. package/dist/gen-core/cell.d.ts +138 -0
  110. package/dist/gen-core/cell.js +150 -0
  111. package/dist/gen-core/cube-sphere.d.ts +57 -0
  112. package/dist/gen-core/cube-sphere.js +159 -0
  113. package/dist/gen-core/field.d.ts +55 -0
  114. package/dist/gen-core/field.js +154 -0
  115. package/dist/gen-core/geometry.d.ts +31 -0
  116. package/dist/gen-core/geometry.js +231 -0
  117. package/dist/gen-core/hash.d.ts +18 -0
  118. package/dist/gen-core/hash.js +58 -0
  119. package/dist/gen-core/height-field.d.ts +33 -0
  120. package/dist/gen-core/height-field.js +137 -0
  121. package/dist/gen-core/index.d.ts +22 -0
  122. package/dist/gen-core/index.js +17 -0
  123. package/dist/gen-core/instance-cells.d.ts +37 -0
  124. package/dist/gen-core/instance-cells.js +72 -0
  125. package/dist/gen-core/near-scatter.d.ts +56 -0
  126. package/dist/gen-core/near-scatter.js +120 -0
  127. package/dist/gen-core/noise.d.ts +23 -0
  128. package/dist/gen-core/noise.js +72 -0
  129. package/dist/gen-core/occupancy.d.ts +21 -0
  130. package/dist/gen-core/occupancy.js +104 -0
  131. package/dist/gen-core/sphere-patch.d.ts +138 -0
  132. package/dist/gen-core/sphere-patch.js +544 -0
  133. package/dist/gen-core/strip-surface.d.ts +34 -0
  134. package/dist/gen-core/strip-surface.js +246 -0
  135. package/dist/gen-core/strip.d.ts +102 -0
  136. package/dist/gen-core/strip.js +817 -0
  137. package/dist/gen-ground/env-slots.d.ts +48 -0
  138. package/dist/gen-ground/env-slots.js +78 -0
  139. package/dist/gen-ground/ground.d.ts +78 -0
  140. package/dist/gen-ground/ground.js +208 -0
  141. package/dist/gen-ground/index.d.ts +9 -0
  142. package/dist/gen-ground/index.js +7 -0
  143. package/dist/gen-ground/markings.d.ts +46 -0
  144. package/dist/gen-ground/markings.js +124 -0
  145. package/dist/gen-ground/materials.d.ts +18 -0
  146. package/dist/gen-ground/materials.js +22 -0
  147. package/dist/gen-ground/terrain-shader.d.ts +5 -0
  148. package/dist/gen-ground/terrain-shader.js +151 -0
  149. package/dist/gen-mesh/bare-shapes.d.ts +194 -0
  150. package/dist/gen-mesh/bare-shapes.js +596 -0
  151. package/dist/gen-mesh/bisect-surface.d.ts +47 -0
  152. package/dist/gen-mesh/bisect-surface.js +261 -0
  153. package/dist/gen-mesh/box.d.ts +18 -0
  154. package/dist/gen-mesh/box.js +2 -0
  155. package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
  156. package/dist/gen-mesh/cell-morph-mesh.js +258 -0
  157. package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
  158. package/dist/gen-mesh/cell-surface-mesh.js +140 -0
  159. package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
  160. package/dist/gen-mesh/chunk-mesh.js +112 -0
  161. package/dist/gen-mesh/drape-mesh.d.ts +36 -0
  162. package/dist/gen-mesh/drape-mesh.js +98 -0
  163. package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
  164. package/dist/gen-mesh/height-field-mesh.js +98 -0
  165. package/dist/gen-mesh/index.d.ts +26 -0
  166. package/dist/gen-mesh/index.js +15 -0
  167. package/dist/gen-mesh/line-mesh.d.ts +25 -0
  168. package/dist/gen-mesh/line-mesh.js +62 -0
  169. package/dist/gen-mesh/mesh-builder.d.ts +115 -0
  170. package/dist/gen-mesh/mesh-builder.js +315 -0
  171. package/dist/gen-mesh/packed-mesh.d.ts +53 -0
  172. package/dist/gen-mesh/packed-mesh.js +205 -0
  173. package/dist/gen-mesh/prism-mesh.d.ts +33 -0
  174. package/dist/gen-mesh/prism-mesh.js +176 -0
  175. package/dist/gen-mesh/rig-mesh.d.ts +9 -0
  176. package/dist/gen-mesh/rig-mesh.js +135 -0
  177. package/dist/gen-mesh/strip-mesh.d.ts +45 -0
  178. package/dist/gen-mesh/strip-mesh.js +258 -0
  179. package/dist/gen-plan/drain.d.ts +58 -0
  180. package/dist/gen-plan/drain.js +270 -0
  181. package/dist/gen-plan/grid.d.ts +37 -0
  182. package/dist/gen-plan/grid.js +182 -0
  183. package/dist/gen-plan/horizon.d.ts +50 -0
  184. package/dist/gen-plan/horizon.js +185 -0
  185. package/dist/gen-plan/index.d.ts +15 -0
  186. package/dist/gen-plan/index.js +13 -0
  187. package/dist/gen-plan/line-tiles.d.ts +35 -0
  188. package/dist/gen-plan/line-tiles.js +190 -0
  189. package/dist/gen-plan/lines.d.ts +31 -0
  190. package/dist/gen-plan/lines.js +183 -0
  191. package/dist/gen-plan/plots.d.ts +40 -0
  192. package/dist/gen-plan/plots.js +282 -0
  193. package/dist/gen-plan/route.d.ts +55 -0
  194. package/dist/gen-plan/route.js +297 -0
  195. package/dist/gen-plan/sites.d.ts +32 -0
  196. package/dist/gen-plan/sites.js +209 -0
  197. package/dist/gen-tex/code-stamp.d.ts +31 -0
  198. package/dist/gen-tex/code-stamp.js +137 -0
  199. package/dist/gen-tex/index.d.ts +7 -0
  200. package/dist/gen-tex/index.js +5 -0
  201. package/dist/gen-tex/light-horizon.d.ts +47 -0
  202. package/dist/gen-tex/light-horizon.js +180 -0
  203. package/dist/gen-tex/textures.d.ts +8 -0
  204. package/dist/gen-tex/textures.js +49 -0
  205. package/dist/gen-tex/value-textures.d.ts +46 -0
  206. package/dist/gen-tex/value-textures.js +102 -0
  207. package/dist/gen-vegetation/env-slots.d.ts +20 -0
  208. package/dist/gen-vegetation/env-slots.js +29 -0
  209. package/dist/gen-vegetation/index.d.ts +8 -0
  210. package/dist/gen-vegetation/index.js +7 -0
  211. package/dist/gen-vegetation/materials.d.ts +7 -0
  212. package/dist/gen-vegetation/materials.js +17 -0
  213. package/dist/gen-vegetation/planting.d.ts +170 -0
  214. package/dist/gen-vegetation/planting.js +363 -0
  215. package/dist/gen-vegetation/tree-shader.d.ts +23 -0
  216. package/dist/gen-vegetation/tree-shader.js +229 -0
  217. package/dist/gen-vegetation/trees.d.ts +59 -0
  218. package/dist/gen-vegetation/trees.js +329 -0
  219. package/dist/gpu/device.d.ts +286 -0
  220. package/dist/gpu/device.js +1157 -0
  221. package/dist/gpu/gl.d.ts +134 -0
  222. package/dist/gpu/gl.js +276 -0
  223. package/dist/gpu/index.d.ts +4 -0
  224. package/dist/gpu/index.js +3 -0
  225. package/dist/index.d.ts +11 -0
  226. package/dist/index.js +13 -0
  227. package/dist/motion/graph.d.ts +244 -0
  228. package/dist/motion/graph.js +739 -0
  229. package/dist/motion/index.d.ts +8 -0
  230. package/dist/motion/index.js +8 -0
  231. package/dist/motion/pose-ops.d.ts +30 -0
  232. package/dist/motion/pose-ops.js +232 -0
  233. package/dist/motion/reach.d.ts +45 -0
  234. package/dist/motion/reach.js +264 -0
  235. package/dist/motion/skeleton.d.ts +49 -0
  236. package/dist/motion/skeleton.js +99 -0
  237. package/dist/platform/byte-store.d.ts +21 -0
  238. package/dist/platform/byte-store.js +137 -0
  239. package/dist/platform/canvas.d.ts +29 -0
  240. package/dist/platform/canvas.js +76 -0
  241. package/dist/platform/context-loss.d.ts +8 -0
  242. package/dist/platform/context-loss.js +17 -0
  243. package/dist/platform/free-input.d.ts +51 -0
  244. package/dist/platform/free-input.js +100 -0
  245. package/dist/platform/index.d.ts +18 -0
  246. package/dist/platform/index.js +10 -0
  247. package/dist/platform/input.d.ts +48 -0
  248. package/dist/platform/input.js +117 -0
  249. package/dist/platform/keys.d.ts +12 -0
  250. package/dist/platform/keys.js +29 -0
  251. package/dist/platform/loop.d.ts +41 -0
  252. package/dist/platform/loop.js +84 -0
  253. package/dist/platform/walk-input.d.ts +74 -0
  254. package/dist/platform/walk-input.js +226 -0
  255. package/dist/platform/worker.d.ts +51 -0
  256. package/dist/platform/worker.js +170 -0
  257. package/dist/render/bone-instances.d.ts +24 -0
  258. package/dist/render/bone-instances.js +74 -0
  259. package/dist/render/cells.d.ts +70 -0
  260. package/dist/render/cells.js +144 -0
  261. package/dist/render/glsl.d.ts +66 -0
  262. package/dist/render/glsl.js +173 -0
  263. package/dist/render/index.d.ts +26 -0
  264. package/dist/render/index.js +16 -0
  265. package/dist/render/instance-sets.d.ts +97 -0
  266. package/dist/render/instance-sets.js +241 -0
  267. package/dist/render/near-instances.d.ts +75 -0
  268. package/dist/render/near-instances.js +219 -0
  269. package/dist/render/particles.d.ts +63 -0
  270. package/dist/render/particles.js +215 -0
  271. package/dist/render/pieces.d.ts +57 -0
  272. package/dist/render/pieces.js +151 -0
  273. package/dist/render/point-lights.d.ts +97 -0
  274. package/dist/render/point-lights.js +243 -0
  275. package/dist/render/renderer.d.ts +447 -0
  276. package/dist/render/renderer.js +1100 -0
  277. package/dist/render/rig.d.ts +74 -0
  278. package/dist/render/rig.js +576 -0
  279. package/dist/render/shadow-areas.d.ts +49 -0
  280. package/dist/render/shadow-areas.js +125 -0
  281. package/dist/render/shadow-glsl.d.ts +12 -0
  282. package/dist/render/shadow-glsl.js +146 -0
  283. package/dist/render/transient.d.ts +61 -0
  284. package/dist/render/transient.js +213 -0
  285. package/dist/render/value-glsl.d.ts +17 -0
  286. package/dist/render/value-glsl.js +208 -0
  287. package/dist/render/value-layers.d.ts +180 -0
  288. package/dist/render/value-layers.js +333 -0
  289. package/dist/runtime/atmosphere.d.ts +37 -0
  290. package/dist/runtime/atmosphere.js +304 -0
  291. package/dist/runtime/cloud-shell.d.ts +29 -0
  292. package/dist/runtime/cloud-shell.js +158 -0
  293. package/dist/runtime/engine.d.ts +155 -0
  294. package/dist/runtime/engine.js +305 -0
  295. package/dist/runtime/environment-link.d.ts +22 -0
  296. package/dist/runtime/environment-link.js +49 -0
  297. package/dist/runtime/index.d.ts +13 -0
  298. package/dist/runtime/index.js +12 -0
  299. package/dist/runtime/precipitation-glsl.d.ts +2 -0
  300. package/dist/runtime/precipitation-glsl.js +70 -0
  301. package/dist/runtime/precipitation.d.ts +11 -0
  302. package/dist/runtime/precipitation.js +78 -0
  303. package/dist/runtime/sky.d.ts +30 -0
  304. package/dist/runtime/sky.js +114 -0
  305. package/dist/runtime/streaming.d.ts +245 -0
  306. package/dist/runtime/streaming.js +602 -0
  307. package/dist/sim/agenda.d.ts +167 -0
  308. package/dist/sim/agenda.js +425 -0
  309. package/dist/sim/bytes.d.ts +34 -0
  310. package/dist/sim/bytes.js +125 -0
  311. package/dist/sim/destruction/apply.d.ts +59 -0
  312. package/dist/sim/destruction/apply.js +243 -0
  313. package/dist/sim/destruction/cell-states.d.ts +54 -0
  314. package/dist/sim/destruction/cell-states.js +198 -0
  315. package/dist/sim/destruction/index.d.ts +11 -0
  316. package/dist/sim/destruction/index.js +10 -0
  317. package/dist/sim/destruction/int-geometry.d.ts +17 -0
  318. package/dist/sim/destruction/int-geometry.js +131 -0
  319. package/dist/sim/destruction/pick.d.ts +13 -0
  320. package/dist/sim/destruction/pick.js +59 -0
  321. package/dist/sim/destruction/rubble.d.ts +8 -0
  322. package/dist/sim/destruction/rubble.js +159 -0
  323. package/dist/sim/destruction/state.d.ts +15 -0
  324. package/dist/sim/destruction/state.js +83 -0
  325. package/dist/sim/destruction/structure.d.ts +30 -0
  326. package/dist/sim/destruction/structure.js +139 -0
  327. package/dist/sim/events.d.ts +37 -0
  328. package/dist/sim/events.js +106 -0
  329. package/dist/sim/fixed.d.ts +21 -0
  330. package/dist/sim/fixed.js +64 -0
  331. package/dist/sim/flow-probe.d.ts +58 -0
  332. package/dist/sim/flow-probe.js +158 -0
  333. package/dist/sim/flow.d.ts +257 -0
  334. package/dist/sim/flow.js +967 -0
  335. package/dist/sim/index.d.ts +28 -0
  336. package/dist/sim/index.js +20 -0
  337. package/dist/sim/interlock.d.ts +47 -0
  338. package/dist/sim/interlock.js +252 -0
  339. package/dist/sim/movers.d.ts +228 -0
  340. package/dist/sim/movers.js +1083 -0
  341. package/dist/sim/nav.d.ts +72 -0
  342. package/dist/sim/nav.js +292 -0
  343. package/dist/sim/paths.d.ts +80 -0
  344. package/dist/sim/paths.js +197 -0
  345. package/dist/sim/regions.d.ts +87 -0
  346. package/dist/sim/regions.js +517 -0
  347. package/dist/sim/simulation.d.ts +114 -0
  348. package/dist/sim/simulation.js +291 -0
  349. package/dist/sim/states.d.ts +23 -0
  350. package/dist/sim/states.js +54 -0
  351. package/dist/sim/table.d.ts +49 -0
  352. package/dist/sim/table.js +126 -0
  353. package/dist/sim/zones.d.ts +11 -0
  354. package/dist/sim/zones.js +196 -0
  355. package/dist/tools/collision-lines.d.ts +12 -0
  356. package/dist/tools/collision-lines.js +50 -0
  357. package/dist/tools/data-view-glsl.d.ts +3 -0
  358. package/dist/tools/data-view-glsl.js +63 -0
  359. package/dist/tools/data-view-layers.d.ts +20 -0
  360. package/dist/tools/data-view-layers.js +60 -0
  361. package/dist/tools/debug-view.d.ts +30 -0
  362. package/dist/tools/debug-view.js +4 -0
  363. package/dist/tools/index.d.ts +10 -0
  364. package/dist/tools/index.js +7 -0
  365. package/dist/tools/mesh-checks.d.ts +67 -0
  366. package/dist/tools/mesh-checks.js +188 -0
  367. package/dist/tools/profile.d.ts +85 -0
  368. package/dist/tools/profile.js +173 -0
  369. package/dist/world/cell-cache.d.ts +32 -0
  370. package/dist/world/cell-cache.js +60 -0
  371. package/dist/world/cell-format.d.ts +25 -0
  372. package/dist/world/cell-format.js +232 -0
  373. package/dist/world/collide.d.ts +192 -0
  374. package/dist/world/collide.js +822 -0
  375. package/dist/world/index.d.ts +16 -0
  376. package/dist/world/index.js +12 -0
  377. package/dist/world/mesh-solids.d.ts +48 -0
  378. package/dist/world/mesh-solids.js +169 -0
  379. package/dist/world/pick.d.ts +34 -0
  380. package/dist/world/pick.js +177 -0
  381. package/dist/world/providers.d.ts +66 -0
  382. package/dist/world/providers.js +83 -0
  383. package/dist/world/sphere.d.ts +69 -0
  384. package/dist/world/sphere.js +271 -0
  385. package/dist/world/streaming.d.ts +288 -0
  386. package/dist/world/streaming.js +801 -0
  387. package/dist/world/walker.d.ts +145 -0
  388. package/dist/world/walker.js +502 -0
  389. package/docs/architecture.md +111 -0
  390. package/docs/cameras.md +302 -0
  391. package/docs/concepts.md +123 -0
  392. package/docs/destruction.md +127 -0
  393. package/docs/frames.md +199 -0
  394. package/docs/generators.md +575 -0
  395. package/docs/getting-started.md +123 -0
  396. package/docs/headless.md +50 -0
  397. package/docs/motion.md +160 -0
  398. package/docs/planet.md +152 -0
  399. package/docs/recipes.md +521 -0
  400. package/docs/reference.md +364 -0
  401. package/docs/rendering.md +823 -0
  402. package/docs/rigs.md +203 -0
  403. package/docs/simulation.md +235 -0
  404. package/docs/streaming.md +590 -0
  405. package/docs/system.md +166 -0
  406. package/docs/tools.md +175 -0
  407. package/docs/walking.md +262 -0
  408. package/package.json +131 -3
@@ -0,0 +1,115 @@
1
+ import type { MeshData, VertexLayout } from '../base/data.ts';
2
+ import type { Vec3 } from '../base/math.ts';
3
+ /** What the caller stores per vertex besides position and normal. The engine never looks inside. */
4
+ export interface VertexFormat<V> {
5
+ /** Attributes, including position and normal. `layout.stride` must equal `stride`. */
6
+ readonly layout: VertexLayout;
7
+ /** Bytes per vertex. */
8
+ readonly stride: number;
9
+ /**
10
+ * Writes one vertex at byte `offset` of `view`; `p` and `n` are already in mesh space (`n` unit length or zero).
11
+ * `index` is the vertex number, for formats that keep per-vertex data of their own beside the payload.
12
+ */
13
+ write(view: DataView, offset: number, p: ArrayLike<number>, n: ArrayLike<number>, v: V, index: number): void;
14
+ }
15
+ /** Axis-aligned bounds. */
16
+ export interface MeshBounds {
17
+ min: Vec3;
18
+ max: Vec3;
19
+ }
20
+ /** Options of `MeshBuilder.build` and `MeshBuilder.indices`. */
21
+ export interface MeshBuildOptions {
22
+ /** Index width: 16 bits (only up to 65,536 vertices), 32 bits, or 'auto' (default: 16 bits when it fits). */
23
+ index?: 16 | 32 | 'auto';
24
+ }
25
+ /** Called by `MeshBuilder.edit` per vertex: `p` and `n` may be changed in place; a returned payload replaces the old. */
26
+ export type VertexEdit<V> = (p: Vec3, n: Vec3, v: V, index: number) => V | void;
27
+ /**
28
+ * Collects vertices and triangles in a vertex format supplied by the caller. Vertices go through the current
29
+ * transform (`push`/`pop`/`with`); a mirroring transform flips the winding of `tri`, `quad` and `append`.
30
+ */
31
+ export declare class MeshBuilder<V> {
32
+ readonly format: VertexFormat<V>;
33
+ /** Positions in mesh space, three per vertex. */
34
+ private readonly pos;
35
+ /** Unit normals in mesh space, three per vertex. */
36
+ private readonly nrm;
37
+ private readonly data;
38
+ private readonly idx;
39
+ /** Current transform and the saved ones (each a 12-number column-major 3 × 4 matrix). */
40
+ private m;
41
+ private readonly stack;
42
+ private identity;
43
+ private flip;
44
+ private readonly sp;
45
+ private readonly sn;
46
+ constructor(format: VertexFormat<V>);
47
+ get vertexCount(): number;
48
+ get indexCount(): number;
49
+ get triangleCount(): number;
50
+ /** The current transform (12 numbers, column-major 3 × 4). Read only; change it with `push`/`pop`. */
51
+ get transform(): Readonly<Float64Array>;
52
+ /** Whether the current transform mirrors (negative determinant): `tri` then writes the reversed winding. */
53
+ get mirrored(): boolean;
54
+ /** Multiplies the current transform by `m` (`m` applies first, to everything written until the matching `pop`). */
55
+ push(m: ArrayLike<number>): this;
56
+ /** Restores the transform saved by the matching `push`. */
57
+ pop(): this;
58
+ /** Runs `fn` with `m` pushed, and pops it again even when `fn` throws. */
59
+ with(m: ArrayLike<number>, fn: (b: this) => void): this;
60
+ private update;
61
+ /** Adds a vertex: `p` and `n` in the current local frame, `v` its payload (stored by reference). Returns its index. */
62
+ vertex(p: ArrayLike<number>, n: ArrayLike<number>, v: V): number;
63
+ /** A triangle of existing vertices, counter-clockwise seen from outside (reversed under a mirroring transform). */
64
+ tri(a: number, b: number, c: number): this;
65
+ /** A quad a-b-c-d, counter-clockwise from outside: triangles a-b-c and a-c-d. */
66
+ quad(a: number, b: number, c: number, d: number): this;
67
+ /**
68
+ * Appends another builder's vertices and triangles, through the current transform and then `m` (when given).
69
+ * Payloads are kept (the same references); a mirroring result flips the winding.
70
+ */
71
+ append(other: MeshBuilder<V>, m?: ArrayLike<number>): this;
72
+ /** Bounds of the vertices from `first` on, in mesh space. Empty: min +∞, max −∞. */
73
+ bounds(first?: number): MeshBounds;
74
+ /** Position of vertex `i` in mesh space (into `out` when given). */
75
+ position(i: number, out?: Vec3): Vec3;
76
+ /** Normal of vertex `i` in mesh space (into `out` when given). */
77
+ normal(i: number, out?: Vec3): Vec3;
78
+ /** Payload of vertex `i`. */
79
+ payload(i: number): V;
80
+ /** Replaces the payload of vertex `i`. */
81
+ setPayload(i: number, v: V): this;
82
+ /**
83
+ * Visits the vertices from `first` up to (not including) `end` in mesh space: `fn` may move the position, change the
84
+ * normal (renormalised afterwards) and return a new payload.
85
+ */
86
+ edit(fn: VertexEdit<V>, first?: number, end?: number): this;
87
+ /**
88
+ * The positions in mesh space, three per vertex, without a copy: read only and live (they grow with the builder).
89
+ * For passes over a large mesh (occlusion, checks) where a copy per pass or `position(i)` per vertex would be slow.
90
+ */
91
+ get positionData(): ArrayLike<number>;
92
+ /** The unit normals, three per vertex, without a copy: read only and live. */
93
+ get normalData(): ArrayLike<number>;
94
+ /** The indices, three per triangle, without a copy: read only and live. Change a triangle with `setTriangle`. */
95
+ get indexData(): ArrayLike<number>;
96
+ /**
97
+ * Replaces the vertices of triangle `t` exactly as given (the current transform's mirroring is not applied): to turn
98
+ * the winding of a triangle after the fact, for example so that it faces the way its vertex normals point.
99
+ */
100
+ setTriangle(t: number, a: number, b: number, c: number): this;
101
+ /** Positions as floats, three per vertex (a new array): for collisions, checks, bounds. */
102
+ positions(): Float32Array;
103
+ /** Normals as floats, three per vertex (a new array). */
104
+ normals(): Float32Array;
105
+ /** The indices (a new array): for collisions, checks, or a second index order over the same vertices. */
106
+ indices(o?: MeshBuildOptions): Uint32Array | Uint16Array;
107
+ /** The vertex bytes in the format: `format.write` once per vertex, in order. */
108
+ vertices(): Uint8Array;
109
+ /** The mesh: the vertex bytes in the format's layout and the indices. */
110
+ build(o?: MeshBuildOptions): MeshData;
111
+ /** Removes all vertices and triangles; the transform stack stays. */
112
+ clear(): this;
113
+ }
114
+ /** Unit normal of a flat polygon given counter-clockwise seen from its front (Newell's method). Zero when degenerate. */
115
+ export declare function faceNormal(points: readonly ArrayLike<number>[], out?: Vec3): Vec3;
@@ -0,0 +1,315 @@
1
+ // The core of mesh construction: triangles, a transform stack, mirroring, appending and bounds, over a vertex format that
2
+ // the caller supplies. The builder knows only the position, the normal, the transforms and the indices of a vertex;
3
+ // everything else a vertex carries (colours, flags, texture or panel coordinates, …) is a payload `V` that the
4
+ // builder stores by reference and hands back to the format's `write` when the mesh is packed. What the payload means
5
+ // and how it is encoded is the caller's business: the builder never looks inside.
6
+ //
7
+ // Positions and normals are kept as doubles until `build`; a mirroring transform (negative determinant) flips the
8
+ // winding of the triangles written under it, so faces stay counter-clockwise seen from outside. Everything here is
9
+ // meant for setup, not for every frame: it allocates freely.
10
+ import { mat34Determinant, mat34Multiply, mat34Normal, mat34Point } from '../base/mat34.js';
11
+ const IDENTITY = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
12
+ /**
13
+ * Collects vertices and triangles in a vertex format supplied by the caller. Vertices go through the current
14
+ * transform (`push`/`pop`/`with`); a mirroring transform flips the winding of `tri`, `quad` and `append`.
15
+ */
16
+ export class MeshBuilder {
17
+ format;
18
+ /** Positions in mesh space, three per vertex. */
19
+ pos = [];
20
+ /** Unit normals in mesh space, three per vertex. */
21
+ nrm = [];
22
+ data = [];
23
+ idx = [];
24
+ /** Current transform and the saved ones (each a 12-number column-major 3 × 4 matrix). */
25
+ m = Float64Array.from(IDENTITY);
26
+ stack = [];
27
+ identity = true;
28
+ flip = false;
29
+ sp = [0, 0, 0];
30
+ sn = [0, 0, 0];
31
+ constructor(format) {
32
+ if (format.layout.stride !== format.stride)
33
+ throw new Error(`MeshBuilder: layout stride ${format.layout.stride} differs from format stride ${format.stride}`);
34
+ this.format = format;
35
+ }
36
+ get vertexCount() {
37
+ return this.pos.length / 3;
38
+ }
39
+ get indexCount() {
40
+ return this.idx.length;
41
+ }
42
+ get triangleCount() {
43
+ return this.idx.length / 3;
44
+ }
45
+ /** The current transform (12 numbers, column-major 3 × 4). Read only; change it with `push`/`pop`. */
46
+ get transform() {
47
+ return this.m;
48
+ }
49
+ /** Whether the current transform mirrors (negative determinant): `tri` then writes the reversed winding. */
50
+ get mirrored() {
51
+ return this.flip;
52
+ }
53
+ /** Multiplies the current transform by `m` (`m` applies first, to everything written until the matching `pop`). */
54
+ push(m) {
55
+ this.stack.push(this.m);
56
+ this.m = mat34Multiply(this.m, m, new Float64Array(12));
57
+ this.update();
58
+ return this;
59
+ }
60
+ /** Restores the transform saved by the matching `push`. */
61
+ pop() {
62
+ const m = this.stack.pop();
63
+ if (!m)
64
+ throw new Error('MeshBuilder: pop without push');
65
+ this.m = m;
66
+ this.update();
67
+ return this;
68
+ }
69
+ /** Runs `fn` with `m` pushed, and pops it again even when `fn` throws. */
70
+ with(m, fn) {
71
+ this.push(m);
72
+ try {
73
+ fn(this);
74
+ }
75
+ finally {
76
+ this.pop();
77
+ }
78
+ return this;
79
+ }
80
+ update() {
81
+ const m = this.m;
82
+ let id = true;
83
+ for (let k = 0; k < 12; k++)
84
+ if (m[k] !== IDENTITY[k])
85
+ id = false;
86
+ this.identity = id;
87
+ this.flip = mat34Determinant(m) < 0;
88
+ }
89
+ /** Adds a vertex: `p` and `n` in the current local frame, `v` its payload (stored by reference). Returns its index. */
90
+ vertex(p, n, v) {
91
+ const i = this.pos.length / 3;
92
+ if (this.identity) {
93
+ const l = Math.sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]);
94
+ const s = l > 0 ? 1 / l : 0;
95
+ this.pos.push(p[0], p[1], p[2]);
96
+ this.nrm.push(n[0] * s, n[1] * s, n[2] * s);
97
+ }
98
+ else {
99
+ const q = mat34Point(this.m, p[0], p[1], p[2], this.sp);
100
+ const k = mat34Normal(this.m, n[0], n[1], n[2], this.sn);
101
+ this.pos.push(q[0], q[1], q[2]);
102
+ this.nrm.push(k[0], k[1], k[2]);
103
+ }
104
+ this.data.push(v);
105
+ return i;
106
+ }
107
+ /** A triangle of existing vertices, counter-clockwise seen from outside (reversed under a mirroring transform). */
108
+ tri(a, b, c) {
109
+ if (this.flip)
110
+ this.idx.push(a, c, b);
111
+ else
112
+ this.idx.push(a, b, c);
113
+ return this;
114
+ }
115
+ /** A quad a-b-c-d, counter-clockwise from outside: triangles a-b-c and a-c-d. */
116
+ quad(a, b, c, d) {
117
+ return this.tri(a, b, c).tri(a, c, d);
118
+ }
119
+ /**
120
+ * Appends another builder's vertices and triangles, through the current transform and then `m` (when given).
121
+ * Payloads are kept (the same references); a mirroring result flips the winding.
122
+ */
123
+ append(other, m) {
124
+ const full = m ? mat34Multiply(this.m, m, new Float64Array(12)) : this.m;
125
+ let id = true;
126
+ for (let k = 0; k < 12; k++)
127
+ if (full[k] !== IDENTITY[k])
128
+ id = false;
129
+ const mirror = mat34Determinant(full) < 0;
130
+ const base = this.vertexCount;
131
+ const P = other.pos, N = other.nrm;
132
+ const p = this.sp, q = this.sn;
133
+ for (let v = 0; v < P.length; v += 3) {
134
+ if (id) {
135
+ this.pos.push(P[v], P[v + 1], P[v + 2]);
136
+ this.nrm.push(N[v], N[v + 1], N[v + 2]);
137
+ }
138
+ else {
139
+ mat34Point(full, P[v], P[v + 1], P[v + 2], p);
140
+ mat34Normal(full, N[v], N[v + 1], N[v + 2], q);
141
+ this.pos.push(p[0], p[1], p[2]);
142
+ this.nrm.push(q[0], q[1], q[2]);
143
+ }
144
+ }
145
+ for (const d of other.data)
146
+ this.data.push(d);
147
+ const I = other.idx;
148
+ for (let t = 0; t < I.length; t += 3) {
149
+ const a = base + I[t], b = base + I[t + 1], c = base + I[t + 2];
150
+ if (mirror)
151
+ this.idx.push(a, c, b);
152
+ else
153
+ this.idx.push(a, b, c);
154
+ }
155
+ return this;
156
+ }
157
+ /** Bounds of the vertices from `first` on, in mesh space. Empty: min +∞, max −∞. */
158
+ bounds(first = 0) {
159
+ const min = [Infinity, Infinity, Infinity];
160
+ const max = [-Infinity, -Infinity, -Infinity];
161
+ const P = this.pos;
162
+ for (let i = first * 3; i < P.length; i += 3) {
163
+ for (let k = 0; k < 3; k++) {
164
+ const x = P[i + k];
165
+ if (x < min[k])
166
+ min[k] = x;
167
+ if (x > max[k])
168
+ max[k] = x;
169
+ }
170
+ }
171
+ return { min, max };
172
+ }
173
+ /** Position of vertex `i` in mesh space (into `out` when given). */
174
+ position(i, out = [0, 0, 0]) {
175
+ out[0] = this.pos[i * 3];
176
+ out[1] = this.pos[i * 3 + 1];
177
+ out[2] = this.pos[i * 3 + 2];
178
+ return out;
179
+ }
180
+ /** Normal of vertex `i` in mesh space (into `out` when given). */
181
+ normal(i, out = [0, 0, 0]) {
182
+ out[0] = this.nrm[i * 3];
183
+ out[1] = this.nrm[i * 3 + 1];
184
+ out[2] = this.nrm[i * 3 + 2];
185
+ return out;
186
+ }
187
+ /** Payload of vertex `i`. */
188
+ payload(i) {
189
+ if (i < 0 || i >= this.data.length)
190
+ throw new RangeError(`MeshBuilder: no vertex ${i}`);
191
+ return this.data[i];
192
+ }
193
+ /** Replaces the payload of vertex `i`. */
194
+ setPayload(i, v) {
195
+ if (i < 0 || i >= this.data.length)
196
+ throw new RangeError(`MeshBuilder: no vertex ${i}`);
197
+ this.data[i] = v;
198
+ return this;
199
+ }
200
+ /**
201
+ * Visits the vertices from `first` up to (not including) `end` in mesh space: `fn` may move the position, change the
202
+ * normal (renormalised afterwards) and return a new payload.
203
+ */
204
+ edit(fn, first = 0, end = this.vertexCount) {
205
+ const p = [0, 0, 0];
206
+ const n = [0, 0, 0];
207
+ for (let i = first; i < end; i++) {
208
+ for (let k = 0; k < 3; k++) {
209
+ p[k] = this.pos[i * 3 + k];
210
+ n[k] = this.nrm[i * 3 + k];
211
+ }
212
+ const r = fn(p, n, this.data[i], i);
213
+ if (r !== undefined)
214
+ this.data[i] = r;
215
+ const l = Math.sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]);
216
+ const s = l > 0 ? 1 / l : 0;
217
+ for (let k = 0; k < 3; k++) {
218
+ this.pos[i * 3 + k] = p[k];
219
+ this.nrm[i * 3 + k] = n[k] * s;
220
+ }
221
+ }
222
+ return this;
223
+ }
224
+ /**
225
+ * The positions in mesh space, three per vertex, without a copy: read only and live (they grow with the builder).
226
+ * For passes over a large mesh (occlusion, checks) where a copy per pass or `position(i)` per vertex would be slow.
227
+ */
228
+ get positionData() {
229
+ return this.pos;
230
+ }
231
+ /** The unit normals, three per vertex, without a copy: read only and live. */
232
+ get normalData() {
233
+ return this.nrm;
234
+ }
235
+ /** The indices, three per triangle, without a copy: read only and live. Change a triangle with `setTriangle`. */
236
+ get indexData() {
237
+ return this.idx;
238
+ }
239
+ /**
240
+ * Replaces the vertices of triangle `t` exactly as given (the current transform's mirroring is not applied): to turn
241
+ * the winding of a triangle after the fact, for example so that it faces the way its vertex normals point.
242
+ */
243
+ setTriangle(t, a, b, c) {
244
+ if (!Number.isInteger(t) || t < 0 || t * 3 >= this.idx.length)
245
+ throw new RangeError(`MeshBuilder: no triangle ${t}`);
246
+ const n = this.pos.length / 3;
247
+ if (!(a >= 0 && a < n && b >= 0 && b < n && c >= 0 && c < n) || !Number.isInteger(a + b + c)) {
248
+ throw new RangeError(`MeshBuilder: triangle ${t} names a vertex outside 0..${n - 1}`);
249
+ }
250
+ const o = t * 3;
251
+ this.idx[o] = a;
252
+ this.idx[o + 1] = b;
253
+ this.idx[o + 2] = c;
254
+ return this;
255
+ }
256
+ /** Positions as floats, three per vertex (a new array): for collisions, checks, bounds. */
257
+ positions() {
258
+ return Float32Array.from(this.pos);
259
+ }
260
+ /** Normals as floats, three per vertex (a new array). */
261
+ normals() {
262
+ return Float32Array.from(this.nrm);
263
+ }
264
+ /** The indices (a new array): for collisions, checks, or a second index order over the same vertices. */
265
+ indices(o = {}) {
266
+ const wide = o.index === 32 || ((o.index ?? 'auto') === 'auto' && this.vertexCount > 65536);
267
+ if (!wide && this.vertexCount > 65536)
268
+ throw new RangeError(`MeshBuilder: ${this.vertexCount} vertices do not fit 16-bit indices`);
269
+ return wide ? Uint32Array.from(this.idx) : Uint16Array.from(this.idx);
270
+ }
271
+ /** The vertex bytes in the format: `format.write` once per vertex, in order. */
272
+ vertices() {
273
+ const n = this.vertexCount;
274
+ const stride = this.format.stride;
275
+ const bytes = new Uint8Array(n * stride);
276
+ const view = new DataView(bytes.buffer);
277
+ const p = this.sp, q = this.sn;
278
+ for (let i = 0; i < n; i++) {
279
+ this.position(i, p);
280
+ this.normal(i, q);
281
+ this.format.write(view, i * stride, p, q, this.data[i], i);
282
+ }
283
+ return bytes;
284
+ }
285
+ /** The mesh: the vertex bytes in the format's layout and the indices. */
286
+ build(o = {}) {
287
+ const indices = this.indices(o);
288
+ return { layout: this.format.layout, vertices: this.vertices(), indices, count: indices.length };
289
+ }
290
+ /** Removes all vertices and triangles; the transform stack stays. */
291
+ clear() {
292
+ this.pos.length = 0;
293
+ this.nrm.length = 0;
294
+ this.data.length = 0;
295
+ this.idx.length = 0;
296
+ return this;
297
+ }
298
+ }
299
+ /** Unit normal of a flat polygon given counter-clockwise seen from its front (Newell's method). Zero when degenerate. */
300
+ export function faceNormal(points, out = [0, 0, 0]) {
301
+ let x = 0, y = 0, z = 0;
302
+ const n = points.length;
303
+ for (let i = 0; i < n; i++) {
304
+ const a = points[i], b = points[(i + 1) % n];
305
+ x += (a[1] - b[1]) * (a[2] + b[2]);
306
+ y += (a[2] - b[2]) * (a[0] + b[0]);
307
+ z += (a[0] - b[0]) * (a[1] + b[1]);
308
+ }
309
+ const l = Math.sqrt(x * x + y * y + z * z);
310
+ const s = l > 0 ? 1 / l : 0;
311
+ out[0] = x * s;
312
+ out[1] = y * s;
313
+ out[2] = z * s;
314
+ return out;
315
+ }
@@ -0,0 +1,53 @@
1
+ import type { MeshData, VertexLayout } from '../base/data.ts';
2
+ import type { MaterialDesc, UniformValue } from '../base/material.ts';
3
+ /** Name of the packed position attribute: four int16, x y z in steps and one spare. */
4
+ export declare const PACKED_POSITION = "a_packed";
5
+ /** Horizontal position steps per cell edge. */
6
+ export declare const PACK_STEPS_PER_EDGE = 16384;
7
+ /** How positions turn into steps. */
8
+ export interface PackFrame {
9
+ /** Metres per step on x and z (for a cell: its edge / `PACK_STEPS_PER_EDGE`). */
10
+ stepXZ: number;
11
+ /** Metres per step on y. */
12
+ stepY: number;
13
+ /** Subtracted from a position before it is divided into steps: the cell origin on x and z, the height origin on y. */
14
+ origin: readonly [number, number, number];
15
+ }
16
+ /** The frame of a cell: `edgeM` is its edge, `origin` its corner, `heightOrigin` and `stepY` are the world's. */
17
+ export declare function packFrame(edgeM: number, origin: readonly [number, number, number], heightOrigin: number, stepY: number): PackFrame;
18
+ /**
19
+ * Value of the uniform `u_pack` for materials made by `packedMaterial`: `rootEdgeM` is the edge of a level 0 cell,
20
+ * `stepY` and `heightOrigin` as given to `packFrame`.
21
+ */
22
+ export declare function packUniform(rootEdgeM: number, stepY: number, heightOrigin: number): UniformValue;
23
+ export interface PackOptions {
24
+ /**
25
+ * Vertex ranges that are indexed on their own, as ascending boundaries (first vertex of each range, then the vertex
26
+ * count): equal vertices are merged only inside a range, so each range stays one run of vertices that can be
27
+ * rewritten alone. Without it the whole mesh is one range.
28
+ */
29
+ spans?: ArrayLike<number>;
30
+ }
31
+ export interface PackedMesh {
32
+ mesh: MeshData;
33
+ /** The boundaries of `PackOptions.spans` in the packed vertices (`[0, vertex count]` without spans). */
34
+ spans: Uint32Array;
35
+ /** Positions that lay outside the 16-bit range and were moved to its border. */
36
+ clamped: number;
37
+ }
38
+ /** The layout `packMesh` gives a mesh of `layout`: the float position becomes `PACKED_POSITION`, the rest moves up. */
39
+ export declare function packedLayout(layout: VertexLayout): VertexLayout;
40
+ /**
41
+ * Packs a mesh: positions as 16-bit steps of `frame`, every other attribute byte for byte. A mesh without indices is
42
+ * indexed (equal packed vertices once, in the order of their first use); a mesh with indices keeps its vertices and
43
+ * their order. Indices are 16-bit when the vertices allow it. The result depends only on the input bytes and the
44
+ * frame, so one range packed alone gives the bytes it has inside the whole mesh.
45
+ */
46
+ export declare function packMesh(mesh: MeshData, frame: PackFrame, options?: PackOptions): PackedMesh;
47
+ /**
48
+ * The material for meshes made by `packMesh`: every vertex shader reads `PACKED_POSITION` where it read `a_pos`
49
+ * (a line `in vec3 a_pos;` of its own is required), a `'depth'` pass becomes a depth program that does the same.
50
+ * Uniforms: `u_pack` (`packUniform`), and per cell `u_cellLevel` and `u_cellOffset` as the streamed world sets them.
51
+ * A shader that declares `u_cellOffset` itself is taken to add it itself: its `a_pos` stays relative to the cell.
52
+ */
53
+ export declare function packedMaterial(desc: MaterialDesc): MaterialDesc;