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,615 @@
1
+ // Interior plan of a structure: storeys, rooms, a corridor, a stair core and partition walls with door openings, as a
2
+ // pure function of the structure plan (footprint, storeys, window columns, doors, seed). It never reads a damage
3
+ // state, so every part key that comes from it is the same in every state and in every order of hits.
4
+ //
5
+ // Layout, in the oriented box of the footprint (s along the long axis, t across):
6
+ // - cross cuts at s = const, taken from the window column boundaries of the long walls, about 3–6 m apart;
7
+ // - a corridor along s in deep footprints (10 m and more), closed at both ends by full-depth end rooms;
8
+ // - otherwise rows across t, at most 7.5 m deep;
9
+ // - cells of that grid, clipped to the footprint inset by the wall thickness. A partition runs between two
10
+ // neighbouring cells; where it meets an outer wall it must land on a pier between window columns, never across a
11
+ // window or a door. A partition that cannot is dropped and its two cells merge into one room;
12
+ // - a stair core in a single-cell room, next to the corridor and nearest the entrance, when there are storeys to
13
+ // connect;
14
+ // - every room gets a door opening, to the corridor when it borders it.
15
+ // The same layout serves every storey. Small footprints get one room; a footprint whose inset fails gets no interior.
16
+ import earcut from 'earcut';
17
+ import { hashInts, insetRing, pointInRings, unit } from '../../gen-core/index.js';
18
+ import { INTERIOR_DIM } from '../structure/dims.js';
19
+ import { DOOR_KIND, GROUND_FLOOR } from '../structure/facade.js';
20
+ /** What a room is. Codes are what the shader reads. */
21
+ export const ROOM_TYPE = { room: 0, corridor: 1, core: 2, attic: 3 };
22
+ const toS = (f, x, z) => (x - f.cx) * f.ux + (z - f.cz) * f.uz;
23
+ const toT = (f, x, z) => -(x - f.cx) * f.uz + (z - f.cz) * f.ux;
24
+ export const frameX = (f, s, t) => f.cx + f.ux * s - f.uz * t;
25
+ export const frameZ = (f, s, t) => f.cz + f.uz * s + f.ux * t;
26
+ export { toS as frameS, toT as frameT };
27
+ /** Clips a convex polygon given in the box frame (s, t, then any extra values per vertex) to a rectangle. */
28
+ export function clipToRect(poly, r) {
29
+ let out = poly;
30
+ const planes = [
31
+ [0, 1, r.s0],
32
+ [0, -1, r.s1],
33
+ [1, 1, r.t0],
34
+ [1, -1, r.t1],
35
+ ];
36
+ for (const [axis, sign, lim] of planes) {
37
+ if (out.length < 3)
38
+ return [];
39
+ const next = [];
40
+ for (let k = 0; k < out.length; k++) {
41
+ const a = out[k];
42
+ const b = out[(k + 1) % out.length];
43
+ const fa = sign * (a[axis] - lim);
44
+ const fb = sign * (b[axis] - lim);
45
+ if (fa >= 0)
46
+ next.push(a);
47
+ if ((fa >= 0) !== (fb >= 0)) {
48
+ const t = fa / (fa - fb);
49
+ next.push(a.map((v, i) => v + (b[i] - v) * t));
50
+ }
51
+ }
52
+ out = next;
53
+ }
54
+ return out.length >= 3 ? out : [];
55
+ }
56
+ function polyArea(pts) {
57
+ let a = 0;
58
+ for (let k = 0; k < pts.length; k++) {
59
+ const p = pts[k];
60
+ const q = pts[(k + 1) % pts.length];
61
+ a += p[0] * q[1] - q[0] * p[1];
62
+ }
63
+ return Math.abs(a) / 2;
64
+ }
65
+ /** Parameter intervals (0–1) of the segment a → b that lie inside the rings (even–odd). */
66
+ export function segmentInside(rings, ax, az, bx, bz) {
67
+ const ts = [0, 1];
68
+ const dx = bx - ax;
69
+ const dz = bz - az;
70
+ for (const r of rings) {
71
+ const n = r.length / 2;
72
+ for (let i = 0; i < n; i++) {
73
+ const j = (i + 1) % n;
74
+ const px = r[i * 2];
75
+ const pz = r[i * 2 + 1];
76
+ const ex = r[j * 2] - px;
77
+ const ez = r[j * 2 + 1] - pz;
78
+ const den = dx * ez - dz * ex;
79
+ if (Math.abs(den) < 1e-12)
80
+ continue;
81
+ const t = ((px - ax) * ez - (pz - az) * ex) / den;
82
+ const u = ((px - ax) * dz - (pz - az) * dx) / den;
83
+ if (t > 1e-6 && t < 1 - 1e-6 && u >= 0 && u < 1)
84
+ ts.push(t);
85
+ }
86
+ }
87
+ ts.sort((p, q) => p - q);
88
+ const out = [];
89
+ for (let k = 0; k + 1 < ts.length; k++) {
90
+ const t0 = ts[k];
91
+ const t1 = ts[k + 1];
92
+ if (t1 - t0 < 1e-6)
93
+ continue;
94
+ const tm = (t0 + t1) / 2;
95
+ if (!pointInRings(ax + dx * tm, az + dz * tm, rings))
96
+ continue;
97
+ const last = out[out.length - 1];
98
+ if (last && Math.abs(last[1] - t0) < 1e-9)
99
+ last[1] = t1;
100
+ else
101
+ out.push([t0, t1]);
102
+ }
103
+ return out;
104
+ }
105
+ /** Index of the interval of sorted cuts that holds v (clamped to the outer intervals). */
106
+ function slot(cuts, v) {
107
+ for (let k = 1; k < cuts.length - 1; k++)
108
+ if (v < cuts[k])
109
+ return k - 1;
110
+ return cuts.length - 2;
111
+ }
112
+ /** Cell index of a point, or -1 outside the grid. */
113
+ export function cellAt(plan, x, z) {
114
+ const s = toS(plan.frame, x, z);
115
+ const t = toT(plan.frame, x, z);
116
+ const { sCuts, tCuts } = plan;
117
+ if (s < sCuts[0] - 1e-6 || s > sCuts[sCuts.length - 1] + 1e-6 || t < tCuts[0] - 1e-6 || t > tCuts[tCuts.length - 1] + 1e-6)
118
+ return -1;
119
+ return slot(sCuts, s) * (tCuts.length - 1) + slot(tCuts, t);
120
+ }
121
+ /** Room of a point, or -1. */
122
+ export function roomAt(plan, x, z) {
123
+ const c = cellAt(plan, x, z);
124
+ return c < 0 ? -1 : plan.cells[c].room;
125
+ }
126
+ /** Rectangle of a cell in the box frame. */
127
+ export function cellRect(plan, c) {
128
+ const nT = plan.tCuts.length - 1;
129
+ const i = Math.floor(c / nT);
130
+ const j = c % nT;
131
+ return { s0: plan.sCuts[i], s1: plan.sCuts[i + 1], t0: plan.tCuts[j], t1: plan.tCuts[j + 1] };
132
+ }
133
+ /** Widest window opening on a wall over all storeys, in metres; 0 when the wall has no windows. */
134
+ function widestWindow(p, e) {
135
+ const rec = p.rec;
136
+ if (rec) {
137
+ if (e.blind)
138
+ return 0;
139
+ let ww = Math.min(rec.window.width, e.colW * 0.7);
140
+ if (rec.groundFloor === GROUND_FLOOR.glazed)
141
+ ww = Math.max(ww, Math.min(0.82, (e.colW - 0.5) / e.colW) * e.colW);
142
+ return Math.min(ww, 0.86 * e.colW);
143
+ }
144
+ const style = p.b.windowStyle;
145
+ if (style === 0 || e.len <= p.b.bayWidth * 0.7)
146
+ return 0;
147
+ if (style === 2)
148
+ return 0.8 * e.colW;
149
+ if (style === 3)
150
+ return 0.36 * e.colW;
151
+ return Math.max(0.38, Math.min(0.66, 1.5 / e.colW)) * e.colW;
152
+ }
153
+ /** May a partition meet wall `e` at `u`, coming in along (dx, dz)? Only on a pier, never at a door. */
154
+ function wallAccepts(p, e, u, dx, dz) {
155
+ if (Math.abs(e.dx * dx + e.dz * dz) > 0.8)
156
+ return false;
157
+ const half = INTERIOR_DIM.partition / 2;
158
+ for (const d of e.doors)
159
+ if (Math.abs(u - d.u) < d.width / 2 + half + 0.2)
160
+ return false;
161
+ const win = widestWindow(p, e);
162
+ if (win <= 0)
163
+ return true;
164
+ const k = Math.round(u / e.colW);
165
+ const tol = Math.max(0.02, (e.colW - win) / 2 - half - 0.08);
166
+ return Math.abs(u - k * e.colW) <= tol;
167
+ }
168
+ /**
169
+ * The interior plan of one structure. Deterministic for the same structure plan; independent of any damage state.
170
+ * `wallT` is the outer wall thickness (`DESTRUCT_DIM.wall`), `roofSlab` the roof thickness.
171
+ */
172
+ export function planInterior(p, wallT, roofSlab) {
173
+ const { b, edges } = p;
174
+ const D = INTERIOR_DIM;
175
+ const frame = { cx: b.box.cx, cz: b.box.cz, ux: b.box.ux, uz: b.box.uz };
176
+ const hL = b.box.halfL;
177
+ const hW = b.box.halfW;
178
+ const r = (k, ...more) => unit(hashInts(b.hash, 0x1a7e, k, ...more));
179
+ // Storeys.
180
+ const floorY = [];
181
+ for (let f = 0; f < p.floors; f++)
182
+ floorY.push(f === 0 ? p.floorBase : p.floorBase + p.groundFloorH + (f - 1) * p.floorHeight);
183
+ floorY.push(p.eaveY);
184
+ let roofTop = p.eaveY;
185
+ for (let k = 1; k < p.roof.tris.length; k += 3)
186
+ roofTop = Math.max(roofTop, p.roof.tris[k]);
187
+ const attic = !p.flat && roofTop - p.eaveY > 1.2;
188
+ const ceilY = [];
189
+ for (let f = 0; f < p.floors; f++)
190
+ ceilY.push(floorY[f + 1] - (f + 1 < p.floors || !p.flat ? D.slab : roofSlab));
191
+ const empty = { ok: false, frame, sCuts: [-hL, hL], tCuts: [-hW, hW], corridorRow: -1, insets: [], tris: [], cells: [], rooms: [], partitions: [], core: null, floorY, ceilY, attic, wallSplits: edges.map(() => []) };
192
+ const insets = b.rings.map((ring) => insetRing(ring, wallT));
193
+ if (insets.some((x) => x === null))
194
+ return empty;
195
+ const inner = insets;
196
+ // Triangulation of the inset footprint; a triangle that is not inside the real footprint is dropped.
197
+ const coords = [];
198
+ const holes = [];
199
+ inner.forEach((ring, k) => {
200
+ if (k > 0)
201
+ holes.push(coords.length / 2);
202
+ for (const v of ring)
203
+ coords.push(v);
204
+ });
205
+ const idx = earcut(coords, holes, 2);
206
+ const tris = [];
207
+ for (let k = 0; k < idx.length; k += 3) {
208
+ const t = [idx[k], idx[k + 1], idx[k + 2]].flatMap((v) => [coords[v * 2], coords[v * 2 + 1]]);
209
+ const mx = (t[0] + t[2] + t[4]) / 3;
210
+ const mz = (t[1] + t[3] + t[5]) / 3;
211
+ if (pointInRings(mx, mz, b.rings))
212
+ tris.push(...t);
213
+ }
214
+ let area = 0;
215
+ for (let k = 0; k < tris.length; k += 6)
216
+ area += Math.abs((tris[k + 2] - tris[k]) * (tris[k + 5] - tris[k + 1]) - (tris[k + 4] - tris[k]) * (tris[k + 3] - tris[k + 1])) / 2;
217
+ if (area < 2)
218
+ return empty;
219
+ // --- Grid -----------------------------------------------------------------------------------------------------
220
+ const oneRoom = area < D.oneRoomArea || 2 * hW < D.oneRoomWidth;
221
+ const sCuts = [-hL];
222
+ if (!oneRoom) {
223
+ // Candidates: window column boundaries of the walls along the long axis (all walls when none runs along it).
224
+ const along = edges.filter((e) => Math.abs(e.dx * frame.ux + e.dz * frame.uz) > 0.95);
225
+ const source = along.length > 0 ? along : edges;
226
+ const cand = [];
227
+ for (const e of source)
228
+ for (let k = 1; k < e.cols; k++)
229
+ cand.push(toS(frame, e.ax + e.dx * k * e.colW, e.az + e.dz * k * e.colW));
230
+ cand.sort((x, y) => x - y);
231
+ const merged = [];
232
+ for (const c of cand)
233
+ if (merged.length === 0 || c - merged[merged.length - 1] > 0.3)
234
+ merged.push(c);
235
+ for (let k = 0; k < 256; k++) {
236
+ const prev = sCuts[sCuts.length - 1];
237
+ const rest = hL - prev;
238
+ if (rest < 2 * D.roomMin)
239
+ break;
240
+ let want = prev + D.roomWidthMin + (D.roomWidthMax - D.roomWidthMin) * r(1, k);
241
+ if (want > hL - D.roomMin) {
242
+ if (rest <= D.roomMax)
243
+ break;
244
+ want = prev + rest / 2;
245
+ }
246
+ let best = NaN;
247
+ for (const c of merged) {
248
+ if (c < prev + D.roomMin || c > hL - D.roomMin)
249
+ continue;
250
+ if (Number.isNaN(best) || Math.abs(c - want) < Math.abs(best - want))
251
+ best = c;
252
+ }
253
+ sCuts.push(!Number.isNaN(best) && Math.abs(best - want) <= 1.6 ? best : want);
254
+ }
255
+ }
256
+ sCuts.push(hL);
257
+ const nS = sCuts.length - 1;
258
+ const tCuts = [-hW];
259
+ let corridorRow = -1;
260
+ // Row cuts land on piers of the walls across the long axis where they can (a cut there meets those walls).
261
+ const acrossCand = [];
262
+ for (const e of edges) {
263
+ if (Math.abs(e.dx * frame.ux + e.dz * frame.uz) > 0.3)
264
+ continue;
265
+ for (let k = 1; k < e.cols; k++)
266
+ acrossCand.push(toT(frame, e.ax + e.dx * k * e.colW, e.az + e.dz * k * e.colW));
267
+ if (widestWindow(p, e) <= 0)
268
+ acrossCand.push(NaN);
269
+ }
270
+ const rows = (t0, t1) => {
271
+ const n = Math.max(1, Math.ceil((t1 - t0) / D.rowMax - 1e-6));
272
+ for (let k = 1; k < n; k++) {
273
+ const want = t0 + ((t1 - t0) * k) / n;
274
+ let best = want;
275
+ for (const c of acrossCand) {
276
+ if (Number.isNaN(c) || c < t0 + D.roomMin || c > t1 - D.roomMin)
277
+ continue;
278
+ if (Math.abs(c - want) <= 1.8 && Math.abs(c - want) < Math.abs(best - want))
279
+ best = c;
280
+ }
281
+ tCuts.push(best);
282
+ }
283
+ };
284
+ if (!oneRoom && 2 * hW >= D.corridorDepth && nS >= 3) {
285
+ const cw = D.corridorWidthMin + (D.corridorWidthMax - D.corridorWidthMin) * r(2);
286
+ const tc = (r(3) - 0.5) * 0.12 * 2 * hW;
287
+ rows(-hW, tc - cw / 2);
288
+ tCuts.push(tc - cw / 2);
289
+ corridorRow = tCuts.length - 1;
290
+ tCuts.push(tc + cw / 2);
291
+ rows(tc + cw / 2, hW);
292
+ }
293
+ else if (!oneRoom) {
294
+ rows(-hW, hW);
295
+ }
296
+ tCuts.push(hW);
297
+ const nT = tCuts.length - 1;
298
+ const isCorridorCell = (i, j) => corridorRow >= 0 && j === corridorRow && i >= 1 && i <= nS - 2;
299
+ // --- Cells ----------------------------------------------------------------------------------------------------
300
+ const triFrame = [];
301
+ for (let k = 0; k < tris.length; k += 6) {
302
+ const tri = [];
303
+ for (let v = 0; v < 6; v += 2)
304
+ tri.push([toS(frame, tris[k + v], tris[k + v + 1]), toT(frame, tris[k + v], tris[k + v + 1])]);
305
+ triFrame.push(tri);
306
+ }
307
+ const cells = [];
308
+ for (let i = 0; i < nS; i++) {
309
+ for (let j = 0; j < nT; j++) {
310
+ const rect = { s0: sCuts[i], s1: sCuts[i + 1], t0: tCuts[j], t1: tCuts[j + 1] };
311
+ const polys = [];
312
+ let a = 0;
313
+ for (const tri of triFrame) {
314
+ const ss = tri.map((v) => v[0]);
315
+ const tt = tri.map((v) => v[1]);
316
+ if (Math.max(...ss) <= rect.s0 || Math.min(...ss) >= rect.s1 || Math.max(...tt) <= rect.t0 || Math.min(...tt) >= rect.t1)
317
+ continue;
318
+ const c = clipToRect(tri, rect);
319
+ const ca = c.length ? polyArea(c) : 0;
320
+ if (ca < 1e-4)
321
+ continue;
322
+ a += ca;
323
+ polys.push(c.flatMap((v) => [frameX(frame, v[0], v[1]), frameZ(frame, v[0], v[1])]));
324
+ }
325
+ cells.push({ i, j, polys: a >= D.minCellArea ? polys : [], area: a >= D.minCellArea ? a : 0, room: -1 });
326
+ }
327
+ }
328
+ const cellIndex = (i, j) => i * nT + j;
329
+ const live = (c) => cells[c].area > 0;
330
+ // --- Partitions -------------------------------------------------------------------------------------------------
331
+ const edgeByRing = new Map();
332
+ edges.forEach((e, k) => edgeByRing.set(e.ring * 4096 + e.i, k));
333
+ const wallSplits = edges.map(() => []);
334
+ /** Edge index of the outer wall nearest to an inset boundary point, and the position along it. */
335
+ const wallAt = (x, z) => {
336
+ let best = null;
337
+ let bestD = Infinity;
338
+ inner.forEach((ring, rk) => {
339
+ const n = ring.length / 2;
340
+ for (let k = 0; k < n; k++) {
341
+ const q = (k + 1) % n;
342
+ const ax = ring[k * 2];
343
+ const az = ring[k * 2 + 1];
344
+ const ex = ring[q * 2] - ax;
345
+ const ez = ring[q * 2 + 1] - az;
346
+ const l2 = ex * ex + ez * ez;
347
+ if (l2 < 1e-12)
348
+ continue;
349
+ const t = Math.max(0, Math.min(1, ((x - ax) * ex + (z - az) * ez) / l2));
350
+ const d = Math.hypot(x - ax - ex * t, z - az - ez * t);
351
+ const ei = edgeByRing.get(rk * 4096 + k);
352
+ if (ei === undefined || d >= bestD)
353
+ continue;
354
+ const e = edges[ei];
355
+ bestD = d;
356
+ best = { ei, u: (x - e.ax) * e.dx + (z - e.az) * e.dz };
357
+ }
358
+ });
359
+ return best;
360
+ };
361
+ const partitions = [];
362
+ const pending = [];
363
+ const consider = (dir, i, j, cellA, cellB) => {
364
+ if (!live(cellA) || !live(cellB))
365
+ return;
366
+ const s0 = dir === 0 ? sCuts[i] : sCuts[i];
367
+ const s1 = dir === 0 ? sCuts[i] : sCuts[i + 1];
368
+ const t0 = dir === 0 ? tCuts[j] : tCuts[j];
369
+ const t1 = dir === 0 ? tCuts[j + 1] : tCuts[j];
370
+ const ax = frameX(frame, s0, t0);
371
+ const az = frameZ(frame, s0, t0);
372
+ const bx = frameX(frame, s1, t1);
373
+ const bz = frameZ(frame, s1, t1);
374
+ const len = Math.hypot(bx - ax, bz - az);
375
+ const dx = (bx - ax) / len;
376
+ const dz = (bz - az) / len;
377
+ const segs = [];
378
+ const hits = [];
379
+ let ok = true;
380
+ for (const [p0, p1] of segmentInside(inner, ax, az, bx, bz)) {
381
+ if ((p1 - p0) * len < 0.4)
382
+ continue;
383
+ const seg = { s0: s0 + (s1 - s0) * p0, t0: t0 + (t1 - t0) * p0, s1: s0 + (s1 - s0) * p1, t1: t0 + (t1 - t0) * p1, wall0: p0 > 1e-6, wall1: p1 < 1 - 1e-6 };
384
+ for (const [isWall, pr] of [
385
+ [seg.wall0, p0],
386
+ [seg.wall1, p1],
387
+ ]) {
388
+ if (!isWall)
389
+ continue;
390
+ const w = wallAt(ax + (bx - ax) * pr, az + (bz - az) * pr);
391
+ if (!w || !wallAccepts(p, edges[w.ei], w.u, dx, dz))
392
+ ok = false;
393
+ else
394
+ hits.push(w);
395
+ }
396
+ segs.push(seg);
397
+ }
398
+ if (!ok || segs.length === 0)
399
+ return;
400
+ pending.push({ part: { dir, i, j, cellA, cellB, segs, door: null }, hits });
401
+ };
402
+ for (let i = 1; i < nS; i++) {
403
+ for (let j = 0; j < nT; j++) {
404
+ if (corridorRow >= 0 && j === corridorRow && i !== 1 && i !== nS - 1)
405
+ continue;
406
+ consider(0, i, j, cellIndex(i - 1, j), cellIndex(i, j));
407
+ }
408
+ }
409
+ for (let j = 1; j < nT; j++) {
410
+ for (let i = 0; i < nS; i++) {
411
+ if (corridorRow >= 0 && (i === 0 || i === nS - 1))
412
+ continue;
413
+ consider(1, i, j, cellIndex(i, j - 1), cellIndex(i, j));
414
+ }
415
+ }
416
+ for (const { part, hits } of pending) {
417
+ partitions.push(part);
418
+ for (const h of hits)
419
+ wallSplits[h.ei].push(h.u);
420
+ }
421
+ for (const s of wallSplits)
422
+ s.sort((x, y) => x - y);
423
+ // Runs along s stop at the faces of cross walls they meet.
424
+ const crossAt = (i, j) => partitions.some((q) => q.dir === 0 && q.i === i && (q.j === j || q.j === j - 1));
425
+ for (const q of partitions) {
426
+ if (q.dir !== 1)
427
+ continue;
428
+ for (const seg of q.segs) {
429
+ const half = D.partition / 2;
430
+ if (!seg.wall0 && Math.abs(seg.s0 - sCuts[q.i]) < 1e-6 && crossAt(q.i, q.j))
431
+ seg.s0 += half;
432
+ if (!seg.wall1 && Math.abs(seg.s1 - sCuts[q.i + 1]) < 1e-6 && crossAt(q.i + 1, q.j))
433
+ seg.s1 -= half;
434
+ }
435
+ }
436
+ // --- Rooms: cells joined where no partition stands between them --------------------------------------------------
437
+ const parent = cells.map((_, k) => k);
438
+ const find = (k) => {
439
+ while (parent[k] !== k)
440
+ k = parent[k] = parent[parent[k]];
441
+ return k;
442
+ };
443
+ const join = (a, c) => {
444
+ const ra = find(a);
445
+ const rc = find(c);
446
+ if (ra !== rc)
447
+ parent[Math.max(ra, rc)] = Math.min(ra, rc);
448
+ };
449
+ const has = new Set(partitions.map((q) => `${q.cellA}:${q.cellB}`));
450
+ const touching = (dir, i, j) => {
451
+ const s0 = sCuts[i];
452
+ const s1 = dir === 0 ? sCuts[i] : sCuts[i + 1];
453
+ const t0 = tCuts[j];
454
+ const t1 = dir === 0 ? tCuts[j + 1] : tCuts[j];
455
+ return segmentInside(inner, frameX(frame, s0, t0), frameZ(frame, s0, t0), frameX(frame, s1, t1), frameZ(frame, s1, t1)).some(([a, c]) => c - a > 1e-3);
456
+ };
457
+ for (let i = 0; i < nS; i++) {
458
+ for (let j = 0; j < nT; j++) {
459
+ const c = cellIndex(i, j);
460
+ if (!live(c))
461
+ continue;
462
+ if (i + 1 < nS && live(cellIndex(i + 1, j)) && !has.has(`${c}:${cellIndex(i + 1, j)}`) && touching(0, i + 1, j))
463
+ join(c, cellIndex(i + 1, j));
464
+ if (j + 1 < nT && live(cellIndex(i, j + 1)) && !has.has(`${c}:${cellIndex(i, j + 1)}`) && touching(1, i, j + 1))
465
+ join(c, cellIndex(i, j + 1));
466
+ }
467
+ }
468
+ const rooms = [];
469
+ const roomOfRoot = new Map();
470
+ cells.forEach((cell, k) => {
471
+ if (!live(k))
472
+ return;
473
+ const root = find(k);
474
+ let ri = roomOfRoot.get(root);
475
+ if (ri === undefined) {
476
+ ri = rooms.length;
477
+ roomOfRoot.set(root, ri);
478
+ rooms.push({ type: ROOM_TYPE.room, cells: [], hash: unit(hashInts(b.hash, 0x726d, root)) });
479
+ }
480
+ rooms[ri].cells.push(k);
481
+ cell.room = ri;
482
+ if (isCorridorCell(cell.i, cell.j))
483
+ rooms[ri].type = ROOM_TYPE.corridor;
484
+ });
485
+ // A partition between two cells of the same room (possible around a dropped partition) is not needed.
486
+ for (let k = partitions.length - 1; k >= 0; k--) {
487
+ const q = partitions[k];
488
+ if (cells[q.cellA].room === cells[q.cellB].room)
489
+ partitions.splice(k, 1);
490
+ }
491
+ const corridor = rooms.findIndex((x) => x.type === ROOM_TYPE.corridor);
492
+ // --- Stair core ----------------------------------------------------------------------------------------------------
493
+ let core = null;
494
+ if (p.floors >= 2 && rooms.length > 1) {
495
+ let maxH = 0;
496
+ for (let f = 0; f + 1 < p.floors; f++)
497
+ maxH = Math.max(maxH, floorY[f + 1] - floorY[f]);
498
+ const steps = Math.ceil(maxH / 2 / D.stairRise);
499
+ const lenMin = steps * D.treadMin + 2 * D.landingMin;
500
+ const lenWant = steps * 0.27 + 2 * 1.1;
501
+ // Aim: inside the main entrance, else the middle of the corridor (or the box).
502
+ let aimS = 0;
503
+ let aimT = corridorRow >= 0 ? (tCuts[corridorRow] + tCuts[corridorRow + 1]) / 2 : 0;
504
+ const door = edges.flatMap((e) => e.doors.filter((d) => d.kind !== DOOR_KIND.garage).map((d) => ({ e, d })))[0];
505
+ if (door) {
506
+ const x = door.e.ax + door.e.dx * door.d.u - door.e.nx * 2;
507
+ const z = door.e.az + door.e.dz * door.d.u - door.e.nz * 2;
508
+ aimS = toS(frame, x, z);
509
+ aimT = toT(frame, x, z);
510
+ }
511
+ let bestScore = Infinity;
512
+ // First a room of its own (a stairwell); failing that, any cell of a room (an open stair in the room).
513
+ const candidates = [];
514
+ rooms.forEach((room) => {
515
+ if (room.type === ROOM_TYPE.room && room.cells.length === 1)
516
+ candidates.push(room.cells[0]);
517
+ });
518
+ const alone = candidates.length;
519
+ rooms.forEach((room) => {
520
+ if (room.type === ROOM_TYPE.room && room.cells.length > 1)
521
+ candidates.push(...room.cells);
522
+ });
523
+ candidates.forEach((c, ci) => {
524
+ const cell = cells[c];
525
+ // Bounds of the cell's floor in the box frame, kept clear of partition faces.
526
+ let s0 = Infinity;
527
+ let s1 = -Infinity;
528
+ let t0 = Infinity;
529
+ let t1 = -Infinity;
530
+ for (const poly of cell.polys) {
531
+ for (let k = 0; k < poly.length; k += 2) {
532
+ const s = toS(frame, poly[k], poly[k + 1]);
533
+ const t = toT(frame, poly[k], poly[k + 1]);
534
+ s0 = Math.min(s0, s);
535
+ s1 = Math.max(s1, s);
536
+ t0 = Math.min(t0, t);
537
+ t1 = Math.max(t1, t);
538
+ }
539
+ }
540
+ const m = D.partition / 2 + 0.04;
541
+ s0 += m;
542
+ s1 -= m;
543
+ t0 += m;
544
+ t1 -= m;
545
+ const alongS = s1 - s0 >= t1 - t0;
546
+ const long = alongS ? s1 - s0 : t1 - t0;
547
+ const short = alongS ? t1 - t0 : s1 - s0;
548
+ if (long < lenMin || short < D.stairWidthMin)
549
+ return;
550
+ const L = Math.min(long, lenWant);
551
+ const W = Math.min(short, D.stairWidthMax);
552
+ const ms = (s0 + s1) / 2;
553
+ const mt = (t0 + t1) / 2;
554
+ const rect = alongS ? { s0: ms - L / 2, s1: ms + L / 2, t0: mt - W / 2, t1: mt + W / 2 } : { s0: ms - W / 2, s1: ms + W / 2, t0: mt - L / 2, t1: mt + L / 2 };
555
+ const corners = [
556
+ [rect.s0, rect.t0],
557
+ [rect.s1, rect.t0],
558
+ [rect.s1, rect.t1],
559
+ [rect.s0, rect.t1],
560
+ ];
561
+ if (!corners.every(([s, t]) => pointInRings(frameX(frame, s, t), frameZ(frame, s, t), inner) && cellAtST(s, t) === c))
562
+ return;
563
+ const byCorridor = corridor >= 0 && partitions.some((q) => (q.cellA === c && cells[q.cellB].room === corridor) || (q.cellB === c && cells[q.cellA].room === corridor));
564
+ const score = (ci < alone ? 0 : 10000) + (byCorridor ? 0 : 1000) + Math.hypot(ms - aimS, mt - aimT);
565
+ if (score < bestScore - 1e-9) {
566
+ bestScore = score;
567
+ // Flights start at the end nearer the aim point, where the door is likely to be.
568
+ const startLow = alongS ? aimS <= ms : aimT <= mt;
569
+ core = { cell: c, rect, alongS, startLow };
570
+ }
571
+ });
572
+ const coreRoom = core ? rooms[cells[core.cell].room] : null;
573
+ if (coreRoom && coreRoom.cells.length === 1)
574
+ coreRoom.type = ROOM_TYPE.core;
575
+ }
576
+ function cellAtST(s, t) {
577
+ return slot(sCuts, s) * nT + slot(tCuts, t);
578
+ }
579
+ // --- Doors ---------------------------------------------------------------------------------------------------------
580
+ const segLen = (sg) => Math.hypot(sg.s1 - sg.s0, sg.t1 - sg.t0);
581
+ const roomOf = (c) => cells[c].room;
582
+ rooms.forEach((room, ri) => {
583
+ if (room.type === ROOM_TYPE.corridor)
584
+ return;
585
+ const width = room.type === ROOM_TYPE.core ? D.coreDoorWidth : D.doorWidth;
586
+ const mine = partitions.filter((q) => roomOf(q.cellA) === ri || roomOf(q.cellB) === ri);
587
+ const other = (q) => (roomOf(q.cellA) === ri ? roomOf(q.cellB) : roomOf(q.cellA));
588
+ if (mine.some((q) => q.door && (other(q) === corridor || corridor < 0)))
589
+ return;
590
+ const pickFrom = (list) => {
591
+ let best = null;
592
+ for (const q of list) {
593
+ if (q.door)
594
+ continue;
595
+ q.segs.forEach((sg, k) => {
596
+ const l = segLen(sg);
597
+ if (l >= width + 0.5 && (!best || l > best.len + 1e-9))
598
+ best = { q, seg: k, len: l };
599
+ });
600
+ }
601
+ if (!best)
602
+ return false;
603
+ const { q, seg, len } = best;
604
+ const room0 = (len - width) / 2 - 0.25;
605
+ q.door = { seg, at: len / 2 + (r(4, q.dir, q.i, q.j) * 2 - 1) * Math.max(0, room0), width };
606
+ return true;
607
+ };
608
+ if (corridor >= 0 && pickFrom(mine.filter((q) => other(q) === corridor)))
609
+ return;
610
+ if (mine.some((q) => q.door))
611
+ return;
612
+ pickFrom(mine);
613
+ });
614
+ return { ok: true, frame, sCuts, tCuts, corridorRow, insets: inner, tris, cells, rooms, partitions, core, floorY, ceilY, attic, wallSplits };
615
+ }