@wildshard/sdk 0.0.0 → 0.2.3

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 (687) hide show
  1. package/GUIDE.md +790 -0
  2. package/README.md +14 -4
  3. package/bin/wildshard.mjs +38 -0
  4. package/lint/declaration-config.d.mts +2 -0
  5. package/lint/declaration-config.mjs +19 -0
  6. package/lint/engine-plugin.d.mts +2 -0
  7. package/lint/engine-plugin.mjs +40 -0
  8. package/lint/host-callbacks.d.mts +6 -0
  9. package/lint/host-callbacks.mjs +123 -0
  10. package/lint/host-files.d.mts +1 -0
  11. package/lint/host-files.mjs +7 -0
  12. package/lint/layer-exports.d.mts +2 -0
  13. package/lint/layer-exports.mjs +21 -0
  14. package/lint/legacy-line-basis.json +995 -0
  15. package/lint/nine-tiling-baseline.json +35 -0
  16. package/lint/ratchet.json +11 -0
  17. package/lint/runtime-files.d.mts +12 -0
  18. package/lint/runtime-files.json +16 -0
  19. package/lint/runtime-files.mjs +69 -0
  20. package/lint/runtime-performance.d.mts +6 -0
  21. package/lint/runtime-performance.mjs +184 -0
  22. package/lint/sdk-plugin.d.mts +4 -0
  23. package/lint/sdk-plugin.mjs +134 -0
  24. package/lint/shardfile-boundaries.d.mts +10 -0
  25. package/lint/shardfile-boundaries.mjs +122 -0
  26. package/lint/tile-bake-debt.json +556 -0
  27. package/package.json +371 -4
  28. package/scripts/agent-parity.mjs +1524 -0
  29. package/scripts/agent-sync.mjs +518 -0
  30. package/scripts/apfs-clone.mjs +67 -0
  31. package/scripts/assert-store-layout.mjs +23 -0
  32. package/scripts/astc6-phone-cap.d.mts +3 -0
  33. package/scripts/astc6-phone-cap.mjs +137 -0
  34. package/scripts/audit-assets.d.mts +10 -0
  35. package/scripts/audit-assets.mjs +151 -0
  36. package/scripts/bake/coatFiles.d.mts +6 -0
  37. package/scripts/bake/coatFiles.mjs +37 -0
  38. package/scripts/bake/environment.d.mts +2 -0
  39. package/scripts/bake/environment.mjs +58 -0
  40. package/scripts/bake/far-proxies.mjs +45 -0
  41. package/scripts/bake/keyed-sky.d.mts +4 -0
  42. package/scripts/bake/keyed-sky.mjs +34 -0
  43. package/scripts/bake/movers.mjs +56 -0
  44. package/scripts/bake/nativeWorld.d.mts +6 -0
  45. package/scripts/bake/nativeWorld.mjs +43 -0
  46. package/scripts/bake/navmeshGround.ts +22 -0
  47. package/scripts/bake/near-placeholder.mjs +331 -0
  48. package/scripts/bake/placeholderShards.mjs +41 -0
  49. package/scripts/bake/skins.mjs +15 -0
  50. package/scripts/bake/template-skins.mjs +33 -0
  51. package/scripts/bake/viewmodelBytes.ts +26 -0
  52. package/scripts/bake/viewmodelPage.ts +11 -0
  53. package/scripts/bake/worldHost.d.mts +35 -0
  54. package/scripts/bake/worldHost.mjs +110 -0
  55. package/scripts/bake-astc6.cache.json +80 -0
  56. package/scripts/bake-astc6.far-reach.cache.json +23 -0
  57. package/scripts/bake-astc6.list.json +111 -0
  58. package/scripts/bake-astc6.mjs +279 -0
  59. package/scripts/bake-astc6.nalati-grasslands.cache.json +42 -0
  60. package/scripts/bake-catalogue.mjs +44 -0
  61. package/scripts/bake-check.mjs +54 -0
  62. package/scripts/bake-chunk.mjs +124 -0
  63. package/scripts/bake-cloud-field.mjs +24 -0
  64. package/scripts/bake-coats.mjs +110 -0
  65. package/scripts/bake-data-maps.d.mts +24 -0
  66. package/scripts/bake-data-maps.mjs +72 -0
  67. package/scripts/bake-entry-programs.mjs +117 -0
  68. package/scripts/bake-geometry.mjs +106 -0
  69. package/scripts/bake-hybrid-tiles.mjs +28 -0
  70. package/scripts/bake-ktx2.cache.json +276 -0
  71. package/scripts/bake-ktx2.list.json +365 -0
  72. package/scripts/bake-ktx2.mjs +477 -0
  73. package/scripts/bake-map-glb.mjs +127 -0
  74. package/scripts/bake-map-rest.d.mts +7 -0
  75. package/scripts/bake-map-rest.mjs +50 -0
  76. package/scripts/bake-maps.mjs +200 -0
  77. package/scripts/bake-navmesh.mjs +259 -0
  78. package/scripts/bake-packs.mjs +129 -0
  79. package/scripts/bake-pickups.mjs +102 -0
  80. package/scripts/bake-query-terrain.mjs +64 -0
  81. package/scripts/bake-recurve-pool.mjs +16 -0
  82. package/scripts/bake-section-schemas.d.mts +3 -0
  83. package/scripts/bake-template-shardfile.mjs +32 -0
  84. package/scripts/bake-textures.mjs +80 -0
  85. package/scripts/bake-viewmodel-sets.json +45 -0
  86. package/scripts/bake-viewmodel-sets.mjs +137 -0
  87. package/scripts/bake-voxel-ao.mjs +119 -0
  88. package/scripts/bake-water-ripples.mjs +25 -0
  89. package/scripts/blender/README.md +129 -0
  90. package/scripts/blender/build.sh +166 -0
  91. package/scripts/blender/lib/export-scene.mjs +129 -0
  92. package/scripts/blender/lib/glb-digest.mjs +188 -0
  93. package/scripts/blender/lib/glb.py +68 -0
  94. package/scripts/blender/lib/save_blend.py +17 -0
  95. package/scripts/blender/lib/world_fixture.py +55 -0
  96. package/scripts/blender/targets.json +591 -0
  97. package/scripts/build-sdk.mjs +95 -0
  98. package/scripts/build-shardfiles.d.mts +7 -0
  99. package/scripts/build-shardfiles.mjs +206 -0
  100. package/scripts/capture-hero.mjs +137 -0
  101. package/scripts/check-lift-review.mjs +23 -0
  102. package/scripts/chromium-keychain-check.mjs +139 -0
  103. package/scripts/chromium-keychain.d.mts +1 -0
  104. package/scripts/chromium-keychain.mjs +5 -0
  105. package/scripts/compile-script.d.mts +3 -0
  106. package/scripts/compile-script.mjs +8 -0
  107. package/scripts/creature-color.mjs +255 -0
  108. package/scripts/decide/calibrate.py +127 -0
  109. package/scripts/decide/calibration/2026-10-03/labels-s1.tsv +281 -0
  110. package/scripts/decide/calibration/2026-10-03/labels-s2.tsv +97 -0
  111. package/scripts/decide/calibration/2026-10-03/labels-s3.tsv +48 -0
  112. package/scripts/decide/calibration/2026-10-03/labels-s3b.tsv +26 -0
  113. package/scripts/decide/calibration/2026-10-03/res-capture-status-v1.jsonl +376 -0
  114. package/scripts/decide/calibration/2026-10-03/res-text-garbled-strings.jsonl +48 -0
  115. package/scripts/decide/calibration/2026-10-03/res-text-garbled-v1.jsonl +73 -0
  116. package/scripts/decide/decide.py +262 -0
  117. package/scripts/decide/decide.sh +50 -0
  118. package/scripts/decide/layer-purity-pilot.mjs +41 -0
  119. package/scripts/decide/sets/capture-status.json +46 -0
  120. package/scripts/decide/sets/layer-purity.json +28 -0
  121. package/scripts/decide/sets/text-garbled.json +17 -0
  122. package/scripts/decide/test_decide.py +37 -0
  123. package/scripts/docs.mjs +15 -0
  124. package/scripts/entry-reads/crawl.ts +152 -0
  125. package/scripts/entry-reads/tsconfig.json +25 -0
  126. package/scripts/gen-format-schema.d.mts +2 -0
  127. package/scripts/gen-format-schema.mjs +21 -0
  128. package/scripts/gen-host-catalogue.d.mts +14 -0
  129. package/scripts/gen-host-catalogue.mjs +108 -0
  130. package/scripts/gen-shard-layout-doc.d.mts +4 -0
  131. package/scripts/gen-shard-layout-doc.mjs +55 -0
  132. package/scripts/gen-shards.d.mts +17 -0
  133. package/scripts/gen-shards.mjs +311 -0
  134. package/scripts/goldens/capture-inputs.d.mts +4 -0
  135. package/scripts/goldens/capture-inputs.mjs +34 -0
  136. package/scripts/goldens/colour_shift.py +27 -0
  137. package/scripts/goldens/native-residency.d.mts +10 -0
  138. package/scripts/goldens/native-residency.mjs +104 -0
  139. package/scripts/goldens/plot-inputs.d.mts +12 -0
  140. package/scripts/goldens/plot-inputs.mjs +46 -0
  141. package/scripts/gpu-texmem.mjs +98 -0
  142. package/scripts/horizon-matte/config.py +24 -0
  143. package/scripts/horizon-matte/encode.py +91 -0
  144. package/scripts/horizon-matte/key.py +141 -0
  145. package/scripts/horizon-matte/mkjobs.py +33 -0
  146. package/scripts/horizon-matte/mkjobs_day2.py +11 -0
  147. package/scripts/horizon-matte/overlap.py +80 -0
  148. package/scripts/horizon-matte/run_codex.py +57 -0
  149. package/scripts/horizon-matte/stitch.py +133 -0
  150. package/scripts/img2mesh/CC0.md +105 -0
  151. package/scripts/img2mesh/README.md +209 -0
  152. package/scripts/img2mesh/ab_board.py +102 -0
  153. package/scripts/img2mesh/birds/birds.json +255 -0
  154. package/scripts/img2mesh/birds/birds_atlas.py +150 -0
  155. package/scripts/img2mesh/birds/birds_fix_preview.mjs +103 -0
  156. package/scripts/img2mesh/birds/birds_fix_render.py +75 -0
  157. package/scripts/img2mesh/birds/birds_pack.py +110 -0
  158. package/scripts/img2mesh/birds/birds_phone_b.py +112 -0
  159. package/scripts/img2mesh/birds/birds_post.py +550 -0
  160. package/scripts/img2mesh/birds/birds_render.py +125 -0
  161. package/scripts/img2mesh/birds/birds_sheet.py +33 -0
  162. package/scripts/img2mesh/birds/birds_view.py +60 -0
  163. package/scripts/img2mesh/board.py +100 -0
  164. package/scripts/img2mesh/build_cc0.sh +52 -0
  165. package/scripts/img2mesh/build_driftwood.sh +12 -0
  166. package/scripts/img2mesh/build_faces.sh +53 -0
  167. package/scripts/img2mesh/build_props.py +81 -0
  168. package/scripts/img2mesh/cc0_export.py +186 -0
  169. package/scripts/img2mesh/driftwood_post.py +571 -0
  170. package/scripts/img2mesh/e304_faces.sh +67 -0
  171. package/scripts/img2mesh/face_remaster.py +911 -0
  172. package/scripts/img2mesh/face_views.py +95 -0
  173. package/scripts/img2mesh/faces-e304.json +9 -0
  174. package/scripts/img2mesh/faces.json +30 -0
  175. package/scripts/img2mesh/head_cut.py +100 -0
  176. package/scripts/img2mesh/hi3d_paint.py +94 -0
  177. package/scripts/img2mesh/hi3d_refine.py +161 -0
  178. package/scripts/img2mesh/hunyuan_cpu_rasterizer.sh +42 -0
  179. package/scripts/img2mesh/pine_hollow_phone.sh +13 -0
  180. package/scripts/img2mesh/props/coral-arch.json +32 -0
  181. package/scripts/img2mesh/props/ember-furnace.json +30 -0
  182. package/scripts/img2mesh/props/night-market-gate.json +10 -0
  183. package/scripts/img2mesh/render_still.py +86 -0
  184. package/scripts/img2mesh/rig_strip.mjs +46 -0
  185. package/scripts/img2mesh/rig_transfer.mjs +104 -0
  186. package/scripts/img2mesh/split_sheet.py +48 -0
  187. package/scripts/img2mesh/trellis_batch.py +110 -0
  188. package/scripts/img2mesh/versus_board.py +114 -0
  189. package/scripts/import-bundle.d.mts +2 -0
  190. package/scripts/import-bundle.mjs +20 -0
  191. package/scripts/ktx2-ab-board.py +133 -0
  192. package/scripts/ktx2-ab.mjs +111 -0
  193. package/scripts/ktx2-settings.mjs +18 -0
  194. package/scripts/land.d.mts +14 -0
  195. package/scripts/land.mjs +809 -0
  196. package/scripts/lint-dispatch.mjs +14 -0
  197. package/scripts/map-bake-frames.d.mts +4 -0
  198. package/scripts/map-bake-frames.mjs +23 -0
  199. package/scripts/map-geometry.d.mts +9 -0
  200. package/scripts/map-geometry.mjs +29 -0
  201. package/scripts/map-world.mjs +162 -0
  202. package/scripts/mockup-local.sh +46 -0
  203. package/scripts/music/export-midi.mjs +68 -0
  204. package/scripts/music/gen/analyze.py +308 -0
  205. package/scripts/music/gen/audio_jobs.py +46 -0
  206. package/scripts/music/gen/briefs.json +51 -0
  207. package/scripts/music/gen/build_page.py +334 -0
  208. package/scripts/music/gen/folk.json +3187 -0
  209. package/scripts/music/gen/gen_ace_step.py +156 -0
  210. package/scripts/music/gen/gen_heartmula.py +187 -0
  211. package/scripts/music/gen/gen_minimax.py +143 -0
  212. package/scripts/music/gen/gen_sao.py +122 -0
  213. package/scripts/music/gen/gen_sao_small.py +104 -0
  214. package/scripts/music/gen/gen_sfx.py +98 -0
  215. package/scripts/music/gen/gen_sfx_ezaudio.py +112 -0
  216. package/scripts/music/gen/gen_sfx_moss.py +112 -0
  217. package/scripts/music/gen/models.json +61 -0
  218. package/scripts/music/gen/nalati-jobs.json +104 -0
  219. package/scripts/music/gen/nalati-score-build.json +119 -0
  220. package/scripts/music/gen/nalati-score.json +3448 -0
  221. package/scripts/music/gen/ob7-fit-decisions.json +38 -0
  222. package/scripts/music/gen/ob7-score-jobs.json +152 -0
  223. package/scripts/music/gen/ob7-sfx-jobs.json +897 -0
  224. package/scripts/music/gen/ob7_build.py +469 -0
  225. package/scripts/music/gen/ob7_generate.py +67 -0
  226. package/scripts/music/gen/ob7_run.sh +42 -0
  227. package/scripts/music/gen/orchestral.json +3187 -0
  228. package/scripts/music/gen/own_score.py +486 -0
  229. package/scripts/music/gen/ph-jobs.json +27 -0
  230. package/scripts/music/gen/ph_page.py +222 -0
  231. package/scripts/music/gen/piano.json +3175 -0
  232. package/scripts/music/gen/rank_v3.py +248 -0
  233. package/scripts/music/gen/sfx-best.json +2486 -0
  234. package/scripts/music/gen/sfx-ezaudio.json +4082 -0
  235. package/scripts/music/gen/sfx-jobs.json +57 -0
  236. package/scripts/music/gen/sfx-minimax-jobs.json +16 -0
  237. package/scripts/music/gen/sfx-minimax.json +289 -0
  238. package/scripts/music/gen/sfx-moss.json +4082 -0
  239. package/scripts/music/gen/sfx-nalati-b3-jobs.json +17 -0
  240. package/scripts/music/gen/sfx-nalati-jobs.json +338 -0
  241. package/scripts/music/gen/sfx-nalati.json +11202 -0
  242. package/scripts/music/gen/sfx-nd-jobs.json +57 -0
  243. package/scripts/music/gen/sfx-nd-moss.json +2097 -0
  244. package/scripts/music/gen/sfx-nd-sa3-medium.json +2097 -0
  245. package/scripts/music/gen/sfx-nd-summary.json +38 -0
  246. package/scripts/music/gen/sfx-peaks.json +7 -0
  247. package/scripts/music/gen/sfx-ph-jobs.json +169 -0
  248. package/scripts/music/gen/sfx-ph-moss.json +6564 -0
  249. package/scripts/music/gen/sfx-ph-sa3-medium.json +7239 -0
  250. package/scripts/music/gen/sfx-ph-summary.json +63 -0
  251. package/scripts/music/gen/sfx-sa3-medium.json +4082 -0
  252. package/scripts/music/gen/sfx-sa3.json +4082 -0
  253. package/scripts/music/gen/sfx-summary.json +107 -0
  254. package/scripts/music/gen/sfx_build.py +332 -0
  255. package/scripts/music/gen/sfx_merge.py +255 -0
  256. package/scripts/music/gen/sfx_minimax.py +61 -0
  257. package/scripts/music/gen/sfx_nalati.py +331 -0
  258. package/scripts/music/gen/sfx_sprite.py +424 -0
  259. package/scripts/music/gen/stems.py +539 -0
  260. package/scripts/music/gen/test_loop_meter.py +29 -0
  261. package/scripts/music/gen/test_ob7_provenance.py +77 -0
  262. package/scripts/music/gen/v3-folk-build.json +148 -0
  263. package/scripts/music/gen/v3-folk.json +1818 -0
  264. package/scripts/music/gen/v3-jobs.json +145 -0
  265. package/scripts/music/gen/v3-orchestral-build.json +148 -0
  266. package/scripts/music/gen/v3-orchestral.json +1813 -0
  267. package/scripts/music/gen/v3-ph-folk-build.json +94 -0
  268. package/scripts/music/gen/v3-ph-folk.json +1806 -0
  269. package/scripts/music/gen/v3-ph-orchestral-build.json +94 -0
  270. package/scripts/music/gen/v3-ph-orchestral.json +1824 -0
  271. package/scripts/music/gen/v3-ph-piano-build.json +94 -0
  272. package/scripts/music/gen/v3-ph-piano.json +1818 -0
  273. package/scripts/music/gen/v3-piano-build.json +148 -0
  274. package/scripts/music/gen/v3-piano.json +1813 -0
  275. package/scripts/music/wildshard-theme.mid +0 -0
  276. package/scripts/music/wildshard-trailer30.mid +0 -0
  277. package/scripts/named-blob-output.d.mts +8 -0
  278. package/scripts/named-blob-output.mjs +48 -0
  279. package/scripts/pack-all.mjs +15 -0
  280. package/scripts/pid-lock.d.mts +1 -0
  281. package/scripts/pid-lock.mjs +63 -0
  282. package/scripts/practice/bake_dummy.py +53 -0
  283. package/scripts/practice/build_dummies.sh +43 -0
  284. package/scripts/practice/dummy_parts.py +568 -0
  285. package/scripts/practice/dummy_rig_gate.py +139 -0
  286. package/scripts/practice/gate_sheet.py +36 -0
  287. package/scripts/practice/generate_dummy_unimate.py +132 -0
  288. package/scripts/practice/pack_dummy.mjs +59 -0
  289. package/scripts/practice/repair_dummy_weights.mjs +68 -0
  290. package/scripts/practice/rig_dummy.py +828 -0
  291. package/scripts/practice/verify_unimate_skin.mjs +356 -0
  292. package/scripts/preparation-seed.mjs +15 -0
  293. package/scripts/prepare-basis-tool.mjs +6 -0
  294. package/scripts/prepare-product.d.mts +14 -0
  295. package/scripts/prepare-product.mjs +101 -0
  296. package/scripts/product-build-tools.d.mts +3 -0
  297. package/scripts/product-build-tools.json +3 -0
  298. package/scripts/product-build-tools.mjs +31 -0
  299. package/scripts/publish-public.mjs +7 -0
  300. package/scripts/push-tables.d.mts +1 -0
  301. package/scripts/push-tables.mjs +28 -0
  302. package/scripts/record-shard-mounts.mjs +133 -0
  303. package/scripts/sdk-externals.d.mts +2 -0
  304. package/scripts/sdk-externals.mjs +2 -0
  305. package/scripts/section-inventory.ts +209 -0
  306. package/scripts/select-candidate.mjs +15 -0
  307. package/scripts/shard-build-pool.d.mts +4 -0
  308. package/scripts/shard-build-pool.mjs +53 -0
  309. package/scripts/shard-line-baseline.json +17 -0
  310. package/scripts/shard-milestones.d.mts +15 -0
  311. package/scripts/shard-milestones.mjs +105 -0
  312. package/scripts/shard-output-report.d.mts +9 -0
  313. package/scripts/shard-output-report.mjs +85 -0
  314. package/scripts/shard-platform-cli.mjs +93 -0
  315. package/scripts/shard-progress.mjs +212 -0
  316. package/scripts/shard-timelapse.py +102 -0
  317. package/scripts/shardfile-cold-boot.mjs +79 -0
  318. package/scripts/shardfile-vite.d.mts +4 -0
  319. package/scripts/shardfile-vite.mjs +20 -0
  320. package/scripts/simplify-models.mjs +24 -0
  321. package/scripts/site-facts.mjs +88 -0
  322. package/scripts/test-template-gate.mjs +44 -0
  323. package/scripts/test_golden_compare.py +68 -0
  324. package/scripts/tex-tiers.cache.json +181 -0
  325. package/scripts/tex-tiers.mjs +240 -0
  326. package/scripts/texmem-probe.mjs +184 -0
  327. package/scripts/unused-assets.mjs +173 -0
  328. package/scripts/vite-tmp.d.mts +23 -0
  329. package/scripts/vite-tmp.mjs +157 -0
  330. package/scripts/wave-line-baselines.json +32 -0
  331. package/scripts/wildshard.d.mts +4 -0
  332. package/scripts/wildshard.mjs +105 -0
  333. package/scripts/witness-checkpoints.d.mts +10 -0
  334. package/scripts/witness-checkpoints.mjs +84 -0
  335. package/scripts/witness-generation.d.mts +10 -0
  336. package/scripts/witness-generation.mjs +45 -0
  337. package/scripts/witness-manifests.d.mts +8 -0
  338. package/scripts/witness-manifests.mjs +157 -0
  339. package/scripts/worktree-ignore.d.mts +4 -0
  340. package/scripts/worktree-ignore.mjs +36 -0
  341. package/scripts/worktree-reap.mjs +214 -0
  342. package/scripts/worktree.mjs +396 -0
  343. package/scripts/worldclaw/capture-front.sh +28 -0
  344. package/scripts/worldclaw/design-template.md +62 -0
  345. package/scripts/worldclaw/spec-map.py +92 -0
  346. package/scripts/worldclaw/spec.ts +96 -0
  347. package/skills/wildshard/SKILL.md +50 -0
  348. package/skills/wildshard-goldens/SKILL.md +54 -0
  349. package/skills/wildshard-mockup-to-model/SKILL.md +56 -0
  350. package/skills/wildshard-upgrade/SKILL.md +46 -0
  351. package/src/.oxfmtrc.json +50 -0
  352. package/src/.oxlintrc.json +173 -0
  353. package/src/cli/account/account.ts +199 -0
  354. package/src/cli/account/command.ts +193 -0
  355. package/src/cli/account/key.ts +154 -0
  356. package/src/cli/args.ts +97 -0
  357. package/src/cli/audio/audio.ts +24 -0
  358. package/src/cli/bin.mjs +8 -0
  359. package/src/cli/delete/delete.ts +258 -0
  360. package/src/cli/help.ts +196 -0
  361. package/src/cli/hero/adopt.ts +103 -0
  362. package/src/cli/hero/hero.ts +112 -0
  363. package/src/cli/hero/stamp.ts +298 -0
  364. package/src/cli/main.ts +292 -0
  365. package/src/cli/report.ts +16 -0
  366. package/src/cli/shardfile/command.ts +50 -0
  367. package/src/cli/shardfile/shardfile.ts +192 -0
  368. package/src/cli/upload/api.ts +246 -0
  369. package/src/cli/upload/compress.ts +55 -0
  370. package/src/cli/upload/hero.ts +62 -0
  371. package/src/cli/upload/placement.ts +115 -0
  372. package/src/cli/upload/provenance.ts +192 -0
  373. package/src/cli/upload/signature.ts +30 -0
  374. package/src/cli/upload/upload.ts +269 -0
  375. package/src/cli/upload/validate.ts +74 -0
  376. package/src/cli/upload/wire.ts +147 -0
  377. package/src/cli/version.ts +63 -0
  378. package/src/commons/bake/portableMath.ts +187 -0
  379. package/src/commons/catalogue.ts +10 -0
  380. package/src/commons/courseProgram.ts +32 -0
  381. package/src/commons/practiceCourse.ts +16 -0
  382. package/src/commons/scripts/abi.as +14 -0
  383. package/src/commons/scripts/bridge.as +14 -0
  384. package/src/commons/scripts/course.as +63 -0
  385. package/src/scripts/ask-new.sh +29 -0
  386. package/src/scripts/asks.mjs +141 -0
  387. package/src/scripts/herdr-prompt.sh +34 -0
  388. package/src/scripts/herdr-question-open.sh +67 -0
  389. package/src/scripts/md-wrap.mjs +229 -0
  390. package/src/server/app.ts +19 -0
  391. package/src/server/serve.ts +49 -0
  392. package/src/sharddev/admission.ts +7 -0
  393. package/src/sharddev/arenaView.ts +15 -0
  394. package/src/sharddev/as/groupBankV2.ts +36 -0
  395. package/src/sharddev/as/groupStepV2.ts +13 -0
  396. package/src/sharddev/as/ws.ts +30 -0
  397. package/src/sharddev/as/wsV2.ts +180 -0
  398. package/src/sharddev/assemblyscriptCompiler.d.mts +5 -0
  399. package/src/sharddev/assemblyscriptCompiler.mjs +14 -0
  400. package/src/sharddev/assetHandle.ts +84 -0
  401. package/src/sharddev/assetOwner.ts +70 -0
  402. package/src/sharddev/assetScope.ts +30 -0
  403. package/src/sharddev/assets.ts +21 -0
  404. package/src/sharddev/audio.ts +9 -0
  405. package/src/sharddev/audioEncode.ts +211 -0
  406. package/src/sharddev/author.ts +3 -0
  407. package/src/sharddev/authorError.ts +28 -0
  408. package/src/sharddev/authorManifest.ts +39 -0
  409. package/src/sharddev/bake/annulus.ts +19 -0
  410. package/src/sharddev/bake/assemblyscriptMemo.ts +76 -0
  411. package/src/sharddev/bake/assemblyscriptMemoPort.ts +4 -0
  412. package/src/sharddev/bake/authoredWorld.ts +201 -0
  413. package/src/sharddev/bake/basisEncoder.ts +95 -0
  414. package/src/sharddev/bake/basisGlb.ts +85 -0
  415. package/src/sharddev/bake/basisTool.ts +74 -0
  416. package/src/sharddev/bake/basisToolInputs.ts +476 -0
  417. package/src/sharddev/bake/byteCodec.ts +33 -0
  418. package/src/sharddev/bake/canvasAtlas.ts +406 -0
  419. package/src/sharddev/bake/coarseCopy.ts +59 -0
  420. package/src/sharddev/bake/colliders.ts +87 -0
  421. package/src/sharddev/bake/compactGlb.ts +224 -0
  422. package/src/sharddev/bake/compileScript.ts +119 -0
  423. package/src/sharddev/bake/compileScriptV2.ts +75 -0
  424. package/src/sharddev/bake/contactRows.ts +84 -0
  425. package/src/sharddev/bake/creaturePlacement.ts +117 -0
  426. package/src/sharddev/bake/export.ts +67 -0
  427. package/src/sharddev/bake/facetedGeometry.ts +379 -0
  428. package/src/sharddev/bake/farImpostor.ts +120 -0
  429. package/src/sharddev/bake/forest.ts +100 -0
  430. package/src/sharddev/bake/format-hook.mjs +2 -0
  431. package/src/sharddev/bake/generatorGlb.ts +23 -0
  432. package/src/sharddev/bake/geometryBounds.ts +77 -0
  433. package/src/sharddev/bake/geometryError.ts +48 -0
  434. package/src/sharddev/bake/glb.ts +355 -0
  435. package/src/sharddev/bake/glbCompression.ts +143 -0
  436. package/src/sharddev/bake/gltfSource.ts +59 -0
  437. package/src/sharddev/bake/groundMap.ts +142 -0
  438. package/src/sharddev/bake/image.ts +20 -0
  439. package/src/sharddev/bake/isleMap.ts +64 -0
  440. package/src/sharddev/bake/json.mjs +84 -0
  441. package/src/sharddev/bake/keyedSky.ts +47 -0
  442. package/src/sharddev/bake/keyedSkyMemo.ts +39 -0
  443. package/src/sharddev/bake/kinds.ts +137 -0
  444. package/src/sharddev/bake/lightSources.ts +31 -0
  445. package/src/sharddev/bake/mapAssembly.ts +84 -0
  446. package/src/sharddev/bake/mapRaster.ts +173 -0
  447. package/src/sharddev/bake/mapRest.ts +57 -0
  448. package/src/sharddev/bake/mapScenes.ts +234 -0
  449. package/src/sharddev/bake/materialGraph.ts +32 -0
  450. package/src/sharddev/bake/meadow.ts +27 -0
  451. package/src/sharddev/bake/meshoptChoiceMemo.ts +34 -0
  452. package/src/sharddev/bake/nativeInteractionFacts.ts +5 -0
  453. package/src/sharddev/bake/nativeLattice.ts +178 -0
  454. package/src/sharddev/bake/nativeRaster.ts +106 -0
  455. package/src/sharddev/bake/nativeTerrainField.ts +11 -0
  456. package/src/sharddev/bake/navigation-json.mjs +38 -0
  457. package/src/sharddev/bake/navigation.ts +113 -0
  458. package/src/sharddev/bake/navigationAsset.ts +18 -0
  459. package/src/sharddev/bake/nearPlaceholder.ts +206 -0
  460. package/src/sharddev/bake/normalizeRig.ts +80 -0
  461. package/src/sharddev/bake/phoneAstc.ts +93 -0
  462. package/src/sharddev/bake/placeholders.ts +581 -0
  463. package/src/sharddev/bake/placement.ts +80 -0
  464. package/src/sharddev/bake/portableBytes.ts +18 -0
  465. package/src/sharddev/bake/portableBytesMemo.ts +50 -0
  466. package/src/sharddev/bake/practiceCourse.ts +49 -0
  467. package/src/sharddev/bake/primitives.ts +96 -0
  468. package/src/sharddev/bake/props.ts +443 -0
  469. package/src/sharddev/bake/questPlacement.ts +98 -0
  470. package/src/sharddev/bake/rawTexture.ts +26 -0
  471. package/src/sharddev/bake/riderArms.ts +97 -0
  472. package/src/sharddev/bake/rig.ts +95 -0
  473. package/src/sharddev/bake/riggedHullRecipes.ts +40 -0
  474. package/src/sharddev/bake/signPlacements.ts +25 -0
  475. package/src/sharddev/bake/simplifier.ts +52 -0
  476. package/src/sharddev/bake/skinned.ts +312 -0
  477. package/src/sharddev/bake/slabChunks.ts +149 -0
  478. package/src/sharddev/bake/slabs.ts +263 -0
  479. package/src/sharddev/bake/source-loader.mjs +55 -0
  480. package/src/sharddev/bake/sourceMetadata.ts +54 -0
  481. package/src/sharddev/bake/species.ts +368 -0
  482. package/src/sharddev/bake/specimenCatalogue.ts +47 -0
  483. package/src/sharddev/bake/splatGround.ts +141 -0
  484. package/src/sharddev/bake/staticMaterials.ts +171 -0
  485. package/src/sharddev/bake/terrain.ts +195 -0
  486. package/src/sharddev/bake/texture.ts +33 -0
  487. package/src/sharddev/bake/textureWasm.ts +81 -0
  488. package/src/sharddev/bake/tileEncoder.ts +11 -0
  489. package/src/sharddev/bake/tileGrid.ts +62 -0
  490. package/src/sharddev/bake/v2Finite.ts +160 -0
  491. package/src/sharddev/bake/v2Fuel.ts +71 -0
  492. package/src/sharddev/bake/wholePartition.ts +74 -0
  493. package/src/sharddev/bake/wholePieceJoin.ts +147 -0
  494. package/src/sharddev/bake/world.ts +173 -0
  495. package/src/sharddev/bake/worldCollision.ts +128 -0
  496. package/src/sharddev/bake/worldGeometry.ts +237 -0
  497. package/src/sharddev/bake/worldGlb.ts +123 -0
  498. package/src/sharddev/bake/worldImage.ts +12 -0
  499. package/src/sharddev/bake/worldLod.ts +128 -0
  500. package/src/sharddev/bake/worldRows.ts +102 -0
  501. package/src/sharddev/bake/worldTextureMemo.ts +63 -0
  502. package/src/sharddev/bake/zstdBytesMemo.ts +52 -0
  503. package/src/sharddev/bake.ts +193 -0
  504. package/src/sharddev/bakePublication.ts +31 -0
  505. package/src/sharddev/behaviourSource.ts +94 -0
  506. package/src/sharddev/bin/wildshard.mjs +7 -0
  507. package/src/sharddev/blobBytes.ts +65 -0
  508. package/src/sharddev/blobs.ts +138 -0
  509. package/src/sharddev/bootInventory.ts +129 -0
  510. package/src/sharddev/bossProfiles.ts +18 -0
  511. package/src/sharddev/buildBehaviour.ts +77 -0
  512. package/src/sharddev/buildCacheMetrics.ts +17 -0
  513. package/src/sharddev/buildDecisionScripts.ts +122 -0
  514. package/src/sharddev/check.ts +117 -0
  515. package/src/sharddev/checkProject.ts +126 -0
  516. package/src/sharddev/cli.ts +191 -0
  517. package/src/sharddev/clientChannels.ts +169 -0
  518. package/src/sharddev/clientScripts.ts +10 -0
  519. package/src/sharddev/commons.ts +77 -0
  520. package/src/sharddev/commonsCosts.ts +11 -0
  521. package/src/sharddev/compileMovers.ts +11 -0
  522. package/src/sharddev/configBoundary.ts +6 -0
  523. package/src/sharddev/cookInput.ts +40 -0
  524. package/src/sharddev/crowds.ts +6 -0
  525. package/src/sharddev/decisionBindingMap.ts +11 -0
  526. package/src/sharddev/decisionScriptBindings.ts +117 -0
  527. package/src/sharddev/decisionScripts.ts +28 -0
  528. package/src/sharddev/decisionSource.ts +51 -0
  529. package/src/sharddev/dev.ts +113 -0
  530. package/src/sharddev/director.ts +26 -0
  531. package/src/sharddev/directorAbi.ts +77 -0
  532. package/src/sharddev/discoveryDocument.ts +97 -0
  533. package/src/sharddev/draft.ts +11 -0
  534. package/src/sharddev/eliteEntryRows.ts +29 -0
  535. package/src/sharddev/entries.ts +76 -0
  536. package/src/sharddev/entryReads.ts +73 -0
  537. package/src/sharddev/executeBundle.ts +55 -0
  538. package/src/sharddev/finds.ts +5 -0
  539. package/src/sharddev/formatJsonSchema.ts +3 -0
  540. package/src/sharddev/generationCache.ts +257 -0
  541. package/src/sharddev/generationRecipe.ts +94 -0
  542. package/src/sharddev/handwritten.ts +110 -0
  543. package/src/sharddev/immutable.ts +14 -0
  544. package/src/sharddev/interactions.ts +38 -0
  545. package/src/sharddev/kit/bakedGeometry.ts +16 -0
  546. package/src/sharddev/kit/geometryPack.ts +110 -0
  547. package/src/sharddev/ledger.ts +13 -0
  548. package/src/sharddev/looks/tileField.ts +67 -0
  549. package/src/sharddev/materialGraphFiles.ts +57 -0
  550. package/src/sharddev/materials.ts +574 -0
  551. package/src/sharddev/measure.ts +18 -0
  552. package/src/sharddev/modes.ts +115 -0
  553. package/src/sharddev/moverPrograms.ts +213 -0
  554. package/src/sharddev/movers.ts +75 -0
  555. package/src/sharddev/nativePopulationRows.ts +46 -0
  556. package/src/sharddev/newProject.ts +247 -0
  557. package/src/sharddev/noise.ts +54 -0
  558. package/src/sharddev/outputProduct.ts +188 -0
  559. package/src/sharddev/outputRuntime.ts +66 -0
  560. package/src/sharddev/performancePolicy.ts +18 -0
  561. package/src/sharddev/phasedBoss.ts +34 -0
  562. package/src/sharddev/physics.ts +194 -0
  563. package/src/sharddev/platformSections.ts +42 -0
  564. package/src/sharddev/plumbing.ts +8 -0
  565. package/src/sharddev/productOutput.ts +128 -0
  566. package/src/sharddev/project.ts +337 -0
  567. package/src/sharddev/projectCompilerIdentity.ts +94 -0
  568. package/src/sharddev/projectDecisions.ts +66 -0
  569. package/src/sharddev/projectEntryProof.ts +32 -0
  570. package/src/sharddev/projectGeneration.ts +219 -0
  571. package/src/sharddev/projectInputFiles.ts +47 -0
  572. package/src/sharddev/projectManifest.ts +108 -0
  573. package/src/sharddev/projectMap.ts +35 -0
  574. package/src/sharddev/projectOutput.ts +242 -0
  575. package/src/sharddev/projectPolicy.ts +17 -0
  576. package/src/sharddev/projectSections.ts +27 -0
  577. package/src/sharddev/questGraph.ts +25 -0
  578. package/src/sharddev/quests.ts +65 -0
  579. package/src/sharddev/random.ts +61 -0
  580. package/src/sharddev/refusals.ts +234 -0
  581. package/src/sharddev/reportCard.ts +13 -0
  582. package/src/sharddev/returnProjectionV2.ts +81 -0
  583. package/src/sharddev/rows.ts +192 -0
  584. package/src/sharddev/runtimeImports.ts +38 -0
  585. package/src/sharddev/runtimeMirrors.ts +39 -0
  586. package/src/sharddev/runtimePerformance.ts +38 -0
  587. package/src/sharddev/scene.ts +321 -0
  588. package/src/sharddev/sceneAnimation.ts +54 -0
  589. package/src/sharddev/sceneAudio.ts +64 -0
  590. package/src/sharddev/sceneDeclarations.ts +100 -0
  591. package/src/sharddev/sceneGraph.ts +139 -0
  592. package/src/sharddev/sceneTransform.ts +12 -0
  593. package/src/sharddev/schemaValidation.ts +61 -0
  594. package/src/sharddev/sections.ts +47 -0
  595. package/src/sharddev/shardSource.ts +59 -0
  596. package/src/sharddev/sourceReader.ts +26 -0
  597. package/src/sharddev/spawns.ts +38 -0
  598. package/src/sharddev/species/clips.ts +24 -0
  599. package/src/sharddev/species.ts +29 -0
  600. package/src/sharddev/speciesBrains.ts +19 -0
  601. package/src/sharddev/synth.ts +66 -0
  602. package/src/sharddev/test/compileDualScriptV2.ts +71 -0
  603. package/src/sharddev/test/compileSimV2.ts +21 -0
  604. package/src/sharddev/test/diskScriptScenario.ts +86 -0
  605. package/src/sharddev/test/scriptScenario.ts +249 -0
  606. package/src/sharddev/test/scriptSource.ts +12 -0
  607. package/src/sharddev/version.ts +4 -0
  608. package/src/sharddev/weapons/bowProfile.ts +20 -0
  609. package/src/sharddev/weapons/firearmRows.ts +11 -0
  610. package/src/sharddev/weapons/meleeProfile.ts +71 -0
  611. package/src/sharddev/weapons/thrownProfile.ts +10 -0
  612. package/src/sharddev/worldScenes.ts +308 -0
  613. package/src/sharddev/worldSource.ts +82 -0
  614. package/src/shards/_template/README.md +78 -0
  615. package/src/shards/_template/assets/2bf489fdb15f1734ddb4c4f32d500ec6da85c765ec7a4eb28dc6781160e7ec8c +0 -0
  616. package/src/shards/_template/assets/97ec4d8f75f5fa6239ee919444d6dc19fd35896bb305930c1f050ac6e0e0e6a6 +1 -0
  617. package/src/shards/_template/assets/a6a587a31327f936b1b04c05ade818c73fc8964260918662db43539465e27586 +0 -0
  618. package/src/shards/_template/assets/b4fbde0422e125b498c3dc8b9a5cc2516c8598f09e9d0e5f6b639b32f98179e6 +0 -0
  619. package/src/shards/_template/assets/bfa4dfc9c18979f904557ee8deab0058b8a399be10266f5fb1578b403f482fd4 +1 -0
  620. package/src/shards/_template/assets/ef3b7ff4fd22715771cb7d68a3977a903c5e7c3dc293542687d04b3ef3ace2cb +0 -0
  621. package/src/shards/_template/assets/f2db05998615ce1cb79ea96be32c168842eb6a2b34ec01feb86d36404603ee54 +0 -0
  622. package/src/shards/_template/assets/fef98ebb7fce6f66b26e78ac699e5c90f9bdcfaf8cabeb2b58125347eea8b4ab +0 -0
  623. package/src/shards/_template/behaviour/boss.as +39 -0
  624. package/src/shards/_template/behaviour/door.as +32 -0
  625. package/src/shards/_template/behaviour/hooks.json +129 -0
  626. package/src/shards/_template/behaviour/idle.as +75 -0
  627. package/src/shards/_template/behaviour/items.as +22 -0
  628. package/src/shards/_template/card/landscape.jpg +0 -0
  629. package/src/shards/_template/card/portrait.jpg +0 -0
  630. package/src/shards/_template/card/thumb.jpg +0 -0
  631. package/src/shards/_template/data/audio.json +45 -0
  632. package/src/shards/_template/data/bossDecision.json +83 -0
  633. package/src/shards/_template/data/budgets.json +70 -0
  634. package/src/shards/_template/data/card.json +281 -0
  635. package/src/shards/_template/data/clientScripts.json +987 -0
  636. package/src/shards/_template/data/creatures.json +65 -0
  637. package/src/shards/_template/data/director.json +39 -0
  638. package/src/shards/_template/data/encounters.json +96 -0
  639. package/src/shards/_template/data/items.json +172 -0
  640. package/src/shards/_template/data/layout.json +66 -0
  641. package/src/shards/_template/data/ledger.json +32 -0
  642. package/src/shards/_template/data/look.json +521 -0
  643. package/src/shards/_template/data/map.json +64 -0
  644. package/src/shards/_template/data/moves.json +16 -0
  645. package/src/shards/_template/data/placeholder.json +8 -0
  646. package/src/shards/_template/data/plumbing.json +32 -0
  647. package/src/shards/_template/data/quests.json +223 -0
  648. package/src/shards/_template/data/rows.json +423 -0
  649. package/src/shards/_template/data/skins.json +66 -0
  650. package/src/shards/_template/data/spawn.json +6 -0
  651. package/src/shards/_template/data/targets.json +150 -0
  652. package/src/shards/_template/data/text.json +12 -0
  653. package/src/shards/_template/data/ui.json +33 -0
  654. package/src/shards/_template/data/water.json +13 -0
  655. package/src/shards/_template/generators/behaviour.ts +34 -0
  656. package/src/shards/_template/generators/boss.ts +29 -0
  657. package/src/shards/_template/generators/buildOptions.ts +2 -0
  658. package/src/shards/_template/generators/cell.ts +224 -0
  659. package/src/shards/_template/generators/districts.ts +215 -0
  660. package/src/shards/_template/generators/farLook.ts +15 -0
  661. package/src/shards/_template/generators/generate.ts +27 -0
  662. package/src/shards/_template/generators/ground.ts +15 -0
  663. package/src/shards/_template/generators/kit.ts +69 -0
  664. package/src/shards/_template/generators/landscape.ts +59 -0
  665. package/src/shards/_template/generators/landscapeNoise.ts +62 -0
  666. package/src/shards/_template/generators/mapInputs.ts +10 -0
  667. package/src/shards/_template/generators/product.ts +100 -0
  668. package/src/shards/_template/generators/productOutput.ts +18 -0
  669. package/src/shards/_template/generators/props.ts +9 -0
  670. package/src/shards/_template/generators/templatePropsSource.ts +58 -0
  671. package/src/shards/_template/generators/terrain.ts +17 -0
  672. package/src/shards/_template/generators/world.ts +630 -0
  673. package/src/shards/_template/hero.json +10 -0
  674. package/src/shards/_template/look/entry-reads.json +20 -0
  675. package/src/shards/_template/manifest.json +281 -0
  676. package/src/shards/_template/shard.config.ts +10 -0
  677. package/src/shared/health.ts +10 -0
  678. package/src/tools/build-web.ts +59 -0
  679. package/src/tsconfig.json +30 -0
  680. package/src/web/app.tsx +53 -0
  681. package/src/web/index.html +12 -0
  682. package/src/web/main.tsx +10 -0
  683. package/src/web/tsconfig.json +13 -0
  684. package/tsconfig.author.json +23 -0
  685. package/tsconfig.commons.json +21 -0
  686. package/tsconfig.json +47 -0
  687. package/tsconfig.sharddev.json +20 -0
@@ -0,0 +1,630 @@
1
+ import { BoxCollider } from '@wildshard/sdk/physics';
2
+ import type { PropsBakeSource } from '@wildshard/sdk/bake/props';
3
+ import { measureUv, type MeasureRole } from '@wildshard/sdk/measure';
4
+ import { BoxGeometry, BufferGeometry, CircleGeometry, CylinderGeometry, Float32BufferAttribute, Group, IcosahedronGeometry, Material, Matrix4, Mesh, MeshStandardMaterial, PointLight, Vector3, type Object3D } from 'three';
5
+ import layout from '../data/layout.json' with { type: 'json' };
6
+
7
+ /**
8
+ * Build-time only (SHARD-PLATFORM SF16): the template's grey-box shapes as the props baker
9
+ * (src/shards/_template/generators/templatePropsSource.ts) samples them: the hut with its wall colliders, the door panel, the ramp with
10
+ * stair treads, the scattered cubes, the pool disc, the jump-course pads and the lantern's lamp. These are the legacy
11
+ * runtime builders' shapes, kept here so the bake no longer reads the runtime modules (retired with the template
12
+ * chunk); nothing here is imported by the client.
13
+ */
14
+ export const poolMask = (x: number, z: number): boolean => Math.hypot(x - 25, z - 20) < 5;
15
+
16
+ /**
17
+ * A w × h × d box whose first UV set carries SF56's measure data (its `role` and each face's own metres and size: the
18
+ * dev-map look's grid and "4×3" labels, `measureUv`). The plain look never reads it. BoxGeometry's faces run +x, −x
19
+ * (depth × height), +y, −y (width × depth), +z, −z (width × height), four corners each, u left to right and v bottom to
20
+ * top as seen from outside.
21
+ */
22
+ export function measureBox(w: number, h: number, d: number, role: MeasureRole): BoxGeometry {
23
+ const geometry = new BoxGeometry(w, h, d), uv = geometry.getAttribute('uv'), packed: number[] = [];
24
+ const sizes: [number, number][] = [[d, h], [d, h], [w, d], [w, d], [w, h], [w, h]];
25
+ for (let i = 0; i < uv.count; i++) {
26
+ const size = sizes[Math.floor(i / 4)]; if (size === undefined) throw new Error('measureBox: one segment per face');
27
+ packed.push(...measureUv(role, uv.getX(i) * size[0], uv.getY(i) * size[1], size[0], size[1]));
28
+ }
29
+ return geometry.setAttribute('uv', new Float32BufferAttribute(packed, 2));
30
+ }
31
+ /**
32
+ * LF1-7: the colours the look's `tint` keeps (look.json `materials.pbr.measure.tint`). Stone is a cool grey-violet, the
33
+ * hut's blocks a warmer grey, moss its own green (so a trim cap stays moss under a trim tint), wood and iron for the hut's
34
+ * posts, bench, barrels and lamp.
35
+ */
36
+ export const STONE = 0x847a7d, HUT_STONE = 0x8d8479, MOSS = 0x5b7a30, MOSS_LIGHT = 0x76963c, WOOD = 0x86592f, WOOD_DARK = 0x5e3d22, IRON = 0x3a3634, CAP_RED = 0xb23a26, STEM = 0xd6cbb2;
37
+ /** LF1-7: the door lamp's post (the lantern hangs 1 m left of it, over the doorway's right edge, in L0 tile 0/4/3). */
38
+ export const LAMP_POST = { x: 1.55, z: -8.3 } as const;
39
+ /** a grey-box shape (role 1, structure: stone; role 2, trim: moss) */
40
+ const cube = (w: number, h: number, d: number, color?: number, role: MeasureRole = 1): Mesh => new Mesh(measureBox(w, h, d, role), new MeshStandardMaterial({ color: color ?? (role === 2 ? MOSS : STONE), flatShading: true }));
41
+ /** What the shapes need: a root, a scope that owns their buffers, the registry sink, the seeded RNG and the ground height. */
42
+ /** One authored scene part and its collider rows, before SDK compilation. No native registry owns it. */
43
+ export interface TemplatePart {
44
+ id: string; name: string; category: 'buildings' | 'nature' | 'props' | 'ground'; file: string; object: Object3D;
45
+ colliders?: NonNullable<PropsBakeSource['colliders']>[number]['shapes'];
46
+ surface?: 'wood' | 'stone' | 'metal'; active?: () => boolean;
47
+ }
48
+ /** Build-time graph, resource cleanup, authored part sink, seeded scatter draws and ground law. */
49
+ export interface TemplateWorldPorts {
50
+ root: Object3D;
51
+ scope: { own: (resource: { dispose: () => void }) => void; onDispose: (cleanup: () => void) => void };
52
+ piece: (part: TemplatePart) => void;
53
+ rng: { stream: (name: 'cosmetic') => { range: (a: number, b: number) => number } };
54
+ heightAt: (x: number, z: number) => number;
55
+ }
56
+ /** The hut, door, ramp, `propCount` scattered cubes and the pool disc, under `root`, each a registry piece as the runtime registered it. */
57
+ export function buildTemplateWorld(ctx: TemplateWorldPorts, propCount: number): void {
58
+ const { heightAt } = ctx, file = 'src/shards/_template/generators/world.ts';
59
+ const y = heightAt(layout.HUT.x, layout.HUT.z);
60
+ const hut = new Group(); hut.position.set(layout.HUT.x, y, layout.HUT.z);
61
+ hut.add(hutRoof());
62
+ const colliders = [];
63
+ for (const [x, z, hw, hd] of [[-3, 0, 0.15, 3], [3, 0, 0.15, 3], [0, -3, 3, 0.15], [-2, 3, 1, 0.15], [2, 3, 1, 0.15]]) {
64
+ if (x === undefined || z === undefined || hw === undefined || hd === undefined) continue;
65
+ const wall = cube(hw * 2, 3, hd * 2, HUT_STONE); wall.position.set(x, 1.5, z); hut.add(wall);
66
+ colliders.push(BoxCollider.fromData({ kind: 'box', x: layout.HUT.x + x, y: (y + 3 + y) / 2, z: layout.HUT.z + z, hx: hw, hy: Math.max(0.005, (y + 3 - y) / 2), hz: hd, yaw: -0, surface: 'wood' }).toColliderData());
67
+ }
68
+ ctx.root.add(hut); ctx.piece({ id: 'template.hut', name: 'Grey hut', category: 'buildings', file, object: hut, colliders, surface: 'wood' });
69
+ const panel = cube(1.8, 2.5, 0.2, WOOD_DARK, 1); panel.position.set(layout.HUT.x, y + 1.2, layout.HUT.doorZ);
70
+ ctx.root.add(panel); ctx.piece({ id: 'template.door', name: 'Open hut door', category: 'buildings', file, object: panel,
71
+ colliders: [BoxCollider.fromData({ kind: 'box', x: layout.HUT.x, y: (y + 2.5 + y) / 2, z: layout.HUT.doorZ, hx: 0.9, hy: Math.max(0.005, (y + 2.5 - y) / 2), hz: 0.1, yaw: -0, surface: 'wood' }).toColliderData()], active: () => true });
72
+ // Mossgate Hollow v3: braziers A, B and C on labelled pads where the story puts them (LF1-0): A by the moss gate, B on
73
+ // the pond's far bank, C beside the arena gate. Unlit until their fields say so.
74
+ const braziers = new Group(), stands: NonNullable<TemplatePart['colliders']> = [];
75
+ for (const [x, z] of layout.BRAZIERS) {
76
+ if (x === undefined || z === undefined) continue;
77
+ const by = heightAt(x, z), pad = cube(3, 0.1, 3, 0x6f6866, 1), base = cube(1.1, 0.4, 1.1, STONE), stem = cube(0.6, 0.7, 0.6, STONE), bowl = cube(1.3, 0.3, 1.3, 0x6c6264, 1);
78
+ pad.position.set(x, by + 0.05, z); base.position.set(x, by + 0.3, z); stem.position.set(x, by + 0.85, z); bowl.position.set(x, by + 1.35, z);
79
+ braziers.add(pad, base, stem, bowl);
80
+ stands.push(BoxCollider.fromData({ kind: 'box', x, y: by + 0.75, z, hx: 0.55, hy: 0.75, hz: 0.55, yaw: -0, surface: 'stone' }).toColliderData());
81
+ }
82
+ ctx.root.add(braziers); ctx.piece({ id: 'template.braziers', name: 'Braziers A, B and C', category: 'props', file, object: braziers, colliders: stands, surface: 'stone' });
83
+ // Mossgate Hollow v3 (MH-2): the moss gate brazier A's shared field `template.brazier-a` opens (its bars are a panel and
84
+ // collider the field hides). The braziers burn particles (client scripts on fields 102 to 104); A also shows an emissive
85
+ // flame panel (LF1-7, `brazierFlame`): its tile 0/3/3 is at the cap of 8, paid for by drawing the panel and the hut door
86
+ // (it straddles x = 0) with no shadow, one draw each instead of two.
87
+ const gate = mossGate(heightAt);
88
+ ctx.root.add(gate.frame); ctx.piece({ id: 'template.mossgate-frame', name: 'Moss gate frame', category: 'buildings', file, object: gate.frame, colliders: gate.frameColliders, surface: 'stone' });
89
+ ctx.root.add(gate.vines); ctx.piece({ id: 'template.mossgate-vines', name: 'Moss gate vines', category: 'nature', file, object: gate.vines });
90
+ ctx.root.add(gate.panel); ctx.piece({ id: 'template.mossgate', name: 'Moss gate', category: 'nature', file, object: gate.panel, colliders: gate.panelColliders, active: () => true });
91
+ // Mossgate Hollow v3 (MH-3): brazier B's field raises the pond's stones out of the water, and brazier C's takes away the
92
+ // bars across the arena's one way in. The sunken stones are static (no collider), so the raised panel covers them.
93
+ const stones = pondStones();
94
+ ctx.root.add(stones.raised); ctx.piece({ id: 'template.pond-stones', name: 'Pond stepping stones', category: 'nature', file, object: stones.raised, colliders: stones.colliders, active: () => false });
95
+ ctx.root.add(stones.sunk); ctx.piece({ id: 'template.pond-stones-sunk', name: 'Sunken pond stones', category: 'nature', file, object: stones.sunk, surface: 'stone' });
96
+ const planting = pondPlanting(heightAt);
97
+ ctx.root.add(planting); ctx.piece({ id: 'template.pond-planting', name: 'Pond reeds, lily pads and lip', category: 'nature', file, object: planting });
98
+ const arena = arenaRing(heightAt);
99
+ ctx.root.add(arena.wall); ctx.piece({ id: 'template.arena-wall', name: 'Arena wall', category: 'buildings', file, object: arena.wall, colliders: arena.wallColliders, surface: 'stone' });
100
+ ctx.root.add(arena.gate); ctx.piece({ id: 'template.arena-gate', name: 'Arena gate', category: 'buildings', file, object: arena.gate, colliders: arena.gateColliders, active: () => true });
101
+ // LF1-9: the arena's checker floor, moss drips and rim braziers (its own piece, so the coarse L1 tiles skip it)
102
+ const arenaDress = new Group(); arenaDressing(arenaDress, heightAt);
103
+ ctx.root.add(arenaDress); ctx.piece({ id: 'template.arena-dressing', name: 'Arena floor, moss and rim braziers', category: 'buildings', file, object: arenaDress });
104
+ const dressing = mossgateDressing(heightAt);
105
+ ctx.root.add(dressing.object); ctx.piece({ id: 'template.dressing', name: 'Mossgate dressing', category: 'nature', file, object: dressing.object, colliders: dressing.colliders, surface: 'stone' });
106
+ const foliage = mossgateFoliage(heightAt);
107
+ ctx.root.add(foliage.object); ctx.piece({ id: 'template.foliage', name: 'Mossgate trees, tufts and ferns', category: 'nature', file, object: foliage.object, colliders: foliage.colliders, surface: 'wood' });
108
+ const ramp = new Group(), from: [number, number, number] = [8, heightAt(8, -8), -8], to: [number, number, number] = [8, from[1] + 2, -14];
109
+ for (let i = 0; i < 10; i++) { const tread = cube(3, 0.2, 0.6, 0x888888, 2); tread.position.set(8, from[1] + (i + 1) * 0.2 - 0.1, -8 - (i + 0.5) * 0.6); ramp.add(tread); }
110
+ const slope = cube(3, 0.24, Math.sqrt(40), 0x888888, 2); slope.position.set(12, from[1] + 0.9, -11); slope.rotation.x = Math.atan2(2, 6); ramp.add(slope);
111
+ ctx.root.add(ramp); ctx.piece({ id: 'template.ramp', name: 'Ramp and stair treads', category: 'buildings', file, object: ramp,
112
+ colliders: [{ kind: 'box', x: 12, y: from[1] + 0.9, z: -11, hx: 1.5, hy: 0.12, hz: Math.sqrt(40) / 2,
113
+ rot: { x: Math.sin(Math.atan2(2, 6) / 2), y: 0, z: 0, w: Math.cos(Math.atan2(2, 6) / 2) }, surface: 'wood' },
114
+ { kind: 'treads', from: { x: from[0], y: from[1], z: from[2] }, to: { x: to[0], y: to[1], z: to[2] }, width: 3, count: 10, surface: 'wood' }], surface: 'wood' });
115
+ const props = new Group(), random = ctx.rng.stream('cosmetic');
116
+ for (let i = 0; i < propCount; i++) { const x = random.range(-25, 25), z = random.range(5, 30), prop = cube(0.6, 0.6, 0.6); prop.position.set(x, heightAt(x, z) + 0.3, z); props.add(prop); }
117
+ ctx.root.add(props); ctx.piece({ id: 'template.props', name: 'Grey props', category: 'props', file, object: props });
118
+ const pool = new Mesh(new CircleGeometry(5, 24), new MeshStandardMaterial({ color: 0x9aa6b0, transparent: true, opacity: 0.7 }));
119
+ pool.rotation.x = -Math.PI / 2; pool.position.set(25, 0, 20); ctx.root.add(pool);
120
+ ctx.root.traverse((node) => {
121
+ if (!(node instanceof Mesh)) return;
122
+ if (node.geometry instanceof BufferGeometry) ctx.scope.own(node.geometry);
123
+ for (const material of Array.isArray(node.material) ? node.material : [node.material]) if (material instanceof Material) ctx.scope.own(material);
124
+ });
125
+ ctx.scope.onDispose(() => { ctx.root.removeFromParent(); });
126
+ }
127
+
128
+ /** A fixed jitter in −1 … 1 from two integers (the dressing never draws from the scatter stream, so the props stay put). */
129
+ const jitter = (i: number, k: number): number => { const s = Math.sin(i * 127.1 + k * 311.7) * 43758.5453; return (s - Math.floor(s)) * 2 - 1; };
130
+ /** A box of role `role` at (x, y, z), turned `yaw` and tipped `tilt` (radians). */
131
+ function block(w: number, h: number, d: number, role: MeasureRole, x: number, y: number, z: number, yaw = 0, tilt = 0, color?: number): Mesh {
132
+ const mesh = cube(w, h, d, color, role); mesh.position.set(x, y, z); mesh.rotation.set(tilt, yaw, tilt * 0.6, 'YXZ'); return mesh;
133
+ }
134
+ type Colliders = NonNullable<TemplatePart['colliders']>;
135
+ /** A stone box collider at (x, y, z), half sizes `hx`, `hy`, `hz`, turned `yaw`. */
136
+ const stoneBox = (x: number, y: number, z: number, hx: number, hy: number, hz: number, yaw = 0): Colliders[number] =>
137
+ BoxCollider.fromData({ kind: 'box', x, y, z, hx, hy, hz, yaw: yaw === 0 ? -0 : yaw, surface: 'stone' }).toColliderData();
138
+ /** L0 tile 0/4/3 (x in [0, 62.5), z in [−62.5, 0)): the one yard tile with draws to spare for the red caps' emissive draw. */
139
+ export const redCap = (x: number, z: number): boolean => x >= 0.3 && x < 62 && z < -0.3 && z >= -62;
140
+ /** The dressing's mushroom positions, as `mossgateDressing` places them. */
141
+ const MUSHROOMS: [number, number][] = [[-1.1, -4.6], [0.9, -6.6], [-3.6, -6.9], [4.4, -3.2], [-5.0, -3.6], [2.2, -8.6], [-1.9, -7.4]];
142
+ /**
143
+ * Mossgate Hollow v3 (MH-1b): the yard's dressing, one step past grey-box and still a test level. A stepping-slab path
144
+ * from spawn to the hut door, the door lamp, mossy boulders, ferns and mushroom clumps, all measure boxes (the dev-map
145
+ * look draws stone as structure, moss as trim). Fixed placements, so the build is stable; colliders on the solid pieces.
146
+ */
147
+ export function mossgateDressing(heightAt: (x: number, z: number) => number): { object: Group; colliders: NonNullable<TemplatePart['colliders']> } {
148
+ const root = new Group(), colliders: NonNullable<TemplatePart['colliders']> = [];
149
+ const box = (x: number, y: number, z: number, hx: number, hy: number, hz: number): void => { colliders.push(BoxCollider.fromData({ kind: 'box', x, y, z, hx, hy, hz, yaw: -0, surface: 'stone' }).toColliderData()); };
150
+ // the slab path: eight stepping stones from spawn to the door, each a little off the line and turned
151
+ for (let i = 0; i < 8; i++) {
152
+ const z = -1.4 - i * 1.0, x = jitter(i, 1) * 0.28, w = 1.05 + jitter(i, 2) * 0.2, d = 0.72 + jitter(i, 3) * 0.12;
153
+ root.add(block(w, 0.08, d, 1, x, heightAt(x, z) + 0.04, z, jitter(i, 4) * 0.35));
154
+ }
155
+ // the door lamp: a post right of the door, an arm over the doorway and a lamp box under a moss cap
156
+ const { x: lx, z: lz } = LAMP_POST, ly = heightAt(lx, lz);
157
+ root.add(block(0.18, 2.6, 0.18, 1, lx, ly + 1.3, lz, 0, 0, IRON), block(1.2, 0.1, 0.1, 1, lx - 0.5, ly + 2.5, lz, 0, 0, IRON), block(0.06, 0.2, 0.06, 1, lx - 1.0, ly + 2.36, lz, 0, 0, IRON));
158
+ // LF1-7: the lantern's iron frame (lid, base, four corner bars) round the glass (`hutLamp`, emissive)
159
+ root.add(block(0.5, 0.1, 0.5, 1, lx - 1.0, ly + 2.29, lz, 0, 0, IRON), block(0.46, 0.08, 0.46, 1, lx - 1.0, ly + 1.72, lz, 0, 0, IRON), block(0.46, 0.24, 0.46, 1, lx, ly + 0.12, lz));
160
+ for (const [cx, cz] of [[-1, -1], [-1, 1], [1, -1], [1, 1]] as const) root.add(block(0.05, 0.5, 0.05, 1, lx - 1.0 + cx * 0.2, ly + 2.0, lz + cz * 0.2, 0, 0, IRON));
161
+ box(lx, ly + 1.25, lz, 0.12, 1.25, 0.12);
162
+ hutFront(root, colliders, heightAt);
163
+ // mossy boulders: two or three tumbled stones and a moss cap each. LF1-7 checks: the small one moved from (-2.6, 2.6),
164
+ // which sat on the spawn-to-arena walk, to between the arena and brazier C walks (foliage.test.ts keeps them clear)
165
+ const boulders: [number, number, number][] = [[-4.4, -6.2, 1.3], [-5.2, 1.9, 1.0], [5.2, -2.6, 1.15], [-6.8, -10.4, 1.6], [13.2, -7.4, 1.4], [-1.0, 4.0, 0.8]];
166
+ boulders.forEach(([x, z, s], i) => {
167
+ const y = heightAt(x, z);
168
+ root.add(block(s, s * 0.7, s * 0.9, 1, x, y + s * 0.3, z, jitter(i, 5) * 1.5, jitter(i, 6) * 0.18));
169
+ root.add(block(s * 0.62, s * 0.5, s * 0.6, 1, x + s * 0.45, y + s * 0.2, z + s * 0.28, jitter(i, 7) * 1.5, jitter(i, 8) * 0.25));
170
+ if (s > 1.1) root.add(block(s * 0.45, s * 0.38, s * 0.5, 1, x - s * 0.5, y + s * 0.14, z - s * 0.2, jitter(i, 9) * 1.5, 0.2));
171
+ root.add(block(s * 0.8, 0.1, s * 0.7, 2, x, y + s * 0.67, z, jitter(i, 5) * 1.5, jitter(i, 6) * 0.18));
172
+ box(x, y + s * 0.35, z, s * 0.55, s * 0.35, s * 0.5);
173
+ });
174
+ // ferns: seven moss fronds fanned up and out from one root (LF1-5: tent fronds, half a box frond's bytes)
175
+ const ferns: [number, number, number][] = [[-3.45, -8.1, 1], [3.5, -8.1, 1], [-3.5, -5.2, 0.9], [1.7, -3.3, 0.8], [-1.6, -2.0, 0.75], [6.0, -4.4, 0.9], [-5.3, -8.4, 1.1], [-4.4, -0.6, 0.85], [8.3, -8.6, 1], [-3.2, -9.6, 0.8]];
176
+ ferns.forEach(([x, z, s], i) => { root.add(fern(x, heightAt(x, z), z, s, i)); });
177
+ // mushroom clumps: pale stems under domed caps, by the path and the boulders. LF1-5: a cap in L0 tile 0/4/3 (x ≥ 0, z < 0)
178
+ // is red (`mushroomCaps`, its own emissive draw); 0/3/3 is at its 8 draws, so a cap there stays a stone box (its bytes
179
+ // are near the 300 000-byte L0 cap too)
180
+ MUSHROOMS.forEach(([x, z], i) => {
181
+ for (let k = 0; k < 3; k++) {
182
+ const mx = x + jitter(i, 20 + k) * 0.28, mz = z + jitter(i, 30 + k) * 0.28, h = 0.16 + (k === 0 ? 0.12 : 0) + jitter(i, 40 + k) * 0.04, y = heightAt(mx, mz);
183
+ root.add(block(0.06, h, 0.06, 1, mx, y + h / 2, mz, 0, 0, STEM));
184
+ if (!redCap(mx, mz)) root.add(block(0.24 - k * 0.04, 0.07, 0.24 - k * 0.04, 1, mx, y + h + 0.03, mz, jitter(i, 50 + k), jitter(i, 60 + k) * 0.2, CAP_RED));
185
+ }
186
+ });
187
+ return { object: root, colliders };
188
+ }
189
+
190
+ /**
191
+ * LF1-5's foliage surfaces. A measure-look surface takes its role's flat colour (trim green, structure stone) and draws
192
+ * the grid and size labels from its first UV set; every foliage vertex carries one fixed point 0.37 m into a 0.74 m face,
193
+ * so no 1 m line, 0.25 m sub-line or label ever crosses a leaf. The mesh colour is real (a later `tint` keeps it).
194
+ */
195
+ const foliageMaterial = (color: number): MeshStandardMaterial => new MeshStandardMaterial({ color, flatShading: true });
196
+ function foliageUv<T extends BufferGeometry>(geometry: T, role: MeasureRole): T {
197
+ const [u, v] = measureUv(role, 0.37, 0.37, 0.74, 0.74), n = geometry.getAttribute('position').count, packed = new Float32Array(n * 2);
198
+ for (let i = 0; i < n; i++) { packed[i * 2] = u; packed[i * 2 + 1] = v; }
199
+ geometry.setAttribute('uv', new Float32BufferAttribute(packed, 2));
200
+ return geometry;
201
+ }
202
+ /** Closed triangles from `points`, each wound to face away from `centre`, as one flat-normalled foliage geometry. */
203
+ function tent(points: readonly Vector3[], triangles: readonly [number, number, number][], centre: Vector3, role: MeasureRole): BufferGeometry {
204
+ const out: number[] = [], ab = new Vector3(), ac = new Vector3(), mid = new Vector3();
205
+ for (const [i, j, k] of triangles) {
206
+ const a = points[i], b = points[j], c = points[k]; if (a === undefined || b === undefined || c === undefined) throw new Error('tent: a point per corner');
207
+ const normal = ab.subVectors(b, a).cross(ac.subVectors(c, a)), away = mid.copy(a).add(b).add(c).divideScalar(3).sub(centre);
208
+ for (const p of normal.dot(away) >= 0 ? [a, b, c] : [a, c, b]) out.push(p.x, p.y, p.z);
209
+ }
210
+ const geometry = new BufferGeometry().setAttribute('position', new Float32BufferAttribute(out, 3)); geometry.computeVertexNormals();
211
+ return foliageUv(geometry, role);
212
+ }
213
+ /** A fern at (x, y, z), `s` its size: seven tent fronds (six triangles each, seen from above and below) fanned up and out. */
214
+ function fern(x: number, y: number, z: number, s: number, i: number): Group {
215
+ const root = new Group(), material = foliageMaterial(0x4f7a2a); root.position.set(x, y + 0.02, z);
216
+ for (let k = 0; k < 7; k++) {
217
+ const yaw = (k / 7) * Math.PI * 2 + jitter(i, 10) + jitter(i * 7 + k, 11) * 0.2, len = s * (0.75 + jitter(i * 7 + k, 12) * 0.15), w = 0.11 * s;
218
+ const lift = 0.75 + jitter(i * 7 + k, 13) * 0.15, tip = new Vector3(0, 0, len), points = [new Vector3(0, 0, 0), new Vector3(-w, 0, len * 0.42), new Vector3(0, 0.035 * s, len * 0.45), new Vector3(w, 0, len * 0.42), tip];
219
+ const frond = new Mesh(tent(points, [[0, 1, 2], [1, 4, 2], [0, 2, 3], [2, 4, 3], [0, 3, 1], [1, 3, 4]], new Vector3(0, 0.012 * s, len * 0.4), 2), material);
220
+ frond.rotation.set(-lift * 0.75, 0, 0); const pivot = new Group(); pivot.rotation.y = yaw; pivot.add(frond); root.add(pivot);
221
+ }
222
+ return root;
223
+ }
224
+ /** A grass tuft at (x, y, z): five thin three-sided blades leaning out from one root, `s` its height in ~0.4 m. */
225
+ function tuft(x: number, y: number, z: number, s: number, i: number): Mesh {
226
+ const points: Vector3[] = [];
227
+ for (let k = 0; k < 5; k++) {
228
+ const a = (k / 5) * Math.PI * 2 + jitter(i, 70 + k) * 0.5, h = s * (0.34 + jitter(i, 75 + k) * 0.1), r = 0.035 * s, cx = Math.cos(a) * 0.05 * s, cz = Math.sin(a) * 0.05 * s;
229
+ for (let c = 0; c < 3; c++) points.push(new Vector3(cx + Math.cos(a + (c * 2 * Math.PI) / 3) * r, 0, cz + Math.sin(a + (c * 2 * Math.PI) / 3) * r));
230
+ points.push(new Vector3(cx + Math.cos(a) * h * 0.4, h, cz + Math.sin(a) * h * 0.4));
231
+ }
232
+ // each blade faces out from its own axis, so wind each side against that blade's base centre, not the tuft's
233
+ const geometry = new BufferGeometry(), out: number[] = [];
234
+ for (let k = 0; k < 5; k++) {
235
+ const blade = points.slice(k * 4, k * 4 + 4), base = blade.slice(0, 3).reduce((sum, p) => sum.add(p), new Vector3()).divideScalar(3);
236
+ const one = tent(blade, [[0, 1, 3], [1, 2, 3], [2, 0, 3]], base, 2).getAttribute('position');
237
+ for (let v = 0; v < one.count; v++) out.push(one.getX(v), one.getY(v), one.getZ(v));
238
+ }
239
+ geometry.setAttribute('position', new Float32BufferAttribute(out, 3)); geometry.computeVertexNormals();
240
+ const mesh = new Mesh(foliageUv(geometry, 2), foliageMaterial(0x6a8a34)); mesh.position.set(x, y, z); return mesh;
241
+ }
242
+ /** A domed mushroom cap, `r` across, seated on its stem's top: an eight-sided frustum with its lid. */
243
+ function mushroomCap(r: number, material: MeshStandardMaterial, role: MeasureRole = 1): Mesh {
244
+ const geometry = foliageUv(new CylinderGeometry(r * 0.35, r, r * 0.55, 8, 1, false), role); geometry.translate(0, r * 0.2, 0);
245
+ return new Mesh(geometry, material);
246
+ }
247
+
248
+ /**
249
+ * LF1-7: the hut's pitched moss roof, in the hut's own frame (walls 3 m up at x, z = ±3). The ridge runs east to west: two
250
+ * moss slabs (trim, so the look's trim grid draws their shingle courses) with a 0.5 m overhang, a pale ridge cap, and stone
251
+ * gables closing the ends. Replaces MH-1's flat slab. Lean on purpose: L0 tile 0/3/3 is near its 300 000-byte cap.
252
+ */
253
+ function hutRoof(): Group {
254
+ const roof = new Group(), run = 3.5, rise = 1.5, pitch = Math.atan2(rise, run), length = Math.hypot(run, rise), ridge = 4.55;
255
+ for (const side of [1, -1]) {
256
+ const slab = cube(7.0, 0.26, length, MOSS, 2);
257
+ slab.position.set(0, ridge - (length / 2) * Math.sin(pitch), side * (length / 2) * Math.cos(pitch)); slab.rotation.x = side * pitch; roof.add(slab);
258
+ }
259
+ const cap = cube(7.1, 0.2, 0.44, MOSS_LIGHT, 2); cap.position.y = ridge + 0.16; roof.add(cap);
260
+ // each gable's top edges lie on its slab's underside (Codex review): a base `half` wide at the wall top meets the slope
261
+ const under = ridge - 0.13 / Math.cos(pitch), half = (under - 3) / Math.tan(pitch);
262
+ for (const x of [-3, 3]) {
263
+ const points = [[-0.15, 3, -half], [-0.15, 3, half], [-0.15, under, 0], [0.15, 3, -half], [0.15, 3, half], [0.15, under, 0]].map(([px = 0, py = 0, pz = 0]) => new Vector3(x + px, py, pz));
264
+ roof.add(new Mesh(tent(points, [[0, 1, 2], [3, 4, 5], [1, 2, 5], [1, 5, 4], [2, 0, 3], [2, 3, 5]], new Vector3(x, 3.4, 0), 1), foliageMaterial(HUT_STONE)));
265
+ }
266
+ return roof;
267
+ }
268
+ /**
269
+ * LF1-7: the hut's front, around the door at (layout.HUT.x, doorZ): wood door posts and a lintel, a bench left of the door
270
+ * and two hooped barrels right of it (eight-sided, open hoops: bytes are tight; each with a wood collider), all in the static draw (bytes, not draws).
271
+ */
272
+ function hutFront(root: Group, colliders: Colliders, heightAt: (x: number, z: number) => number): void {
273
+ const { x: hx, doorZ } = layout.HUT, y = heightAt(hx, doorZ), front = doorZ + 0.17;
274
+ const wood = (x: number, z: number, hx2: number, hy: number, hz: number, y0: number): void => { colliders.push(BoxCollider.fromData({ kind: 'box', x, y: y0 + hy, z, hx: hx2, hy, hz, yaw: -0, surface: 'wood' }).toColliderData()); };
275
+ for (const side of [-1, 1]) root.add(block(0.26, 2.7, 0.36, 1, hx + side * 1.06, y + 1.35, front, 0, 0, WOOD));
276
+ root.add(block(2.6, 0.3, 0.4, 1, hx, y + 2.85, front, 0, 0, WOOD));
277
+ // the bench: a seat on two legs against the wall, left of the door
278
+ const bx = hx - 2.05, bz = doorZ + 0.5, by = heightAt(bx, bz);
279
+ root.add(block(1.5, 0.1, 0.42, 1, bx, by + 0.45, bz, 0, 0, WOOD), block(0.12, 0.4, 0.36, 1, bx - 0.6, by + 0.2, bz, 0, 0, WOOD_DARK), block(0.12, 0.4, 0.36, 1, bx + 0.6, by + 0.2, bz, 0, 0, WOOD_DARK));
280
+ wood(bx, bz, 0.75, 0.25, 0.21, by);
281
+ // two barrels right of the door: a ten-sided staved body with two iron hoops
282
+ for (const [x, z, s] of [[hx + 2.2, doorZ + 0.52, 1], [hx + 2.82, doorZ + 0.42, 0.9]] as const) {
283
+ const gy = heightAt(x, z), h = 0.82 * s, r = 0.3 * s;
284
+ const body = new Mesh(foliageUv(new CylinderGeometry(r * 0.9, r * 0.9, h, 8), 1), foliageMaterial(WOOD)); body.position.set(x, gy + h / 2, z); root.add(body);
285
+ for (const at of [0.22, 0.78]) { const hoop = new Mesh(foliageUv(new CylinderGeometry(r, r, 0.07, 8, 1, true), 1), foliageMaterial(IRON)); hoop.position.set(x, gy + h * at, z); root.add(hoop); }
286
+ wood(x, z, r, h / 2, r, gy);
287
+ }
288
+ }
289
+ /**
290
+ * LF1-7 with LF1-2: the door lamp's glass, one whole shape at the lantern (L0 tile 0/4/3) in the GLB material
291
+ * `mossgate.lamp`, which `props.materials` binds to an emissive look entry: one draw, no shadow.
292
+ */
293
+ export function hutLamp(heightAt: (x: number, z: number) => number): { mesh: Mesh; transform: Matrix4 } {
294
+ const x = LAMP_POST.x - 1.0, z = LAMP_POST.z, y = heightAt(LAMP_POST.x, LAMP_POST.z) + 2.0;
295
+ const geometry = new BoxGeometry(0.36, 0.48, 0.36).toNonIndexed(); geometry.deleteAttribute('uv');
296
+ geometry.setAttribute('color', new Float32BufferAttribute(new Float32Array(geometry.getAttribute('position').count * 3).fill(1), 3));
297
+ const mesh = new Mesh(geometry, new MeshStandardMaterial({ color: 0xffffff, vertexColors: true })); mesh.castShadow = false;
298
+ return { mesh, transform: new Matrix4().makeTranslation(x, y, z) };
299
+ }
300
+ /**
301
+ * LF1-7 with LF1-2: brazier A's flame, a panel brazier A's field shows (data/targets.json, field 102): five faceted cones
302
+ * (LF1-8: `which` 1 is brazier B's, field 103, in 0/4/4, paid for by the pond's raised stones casting no shadow)
303
+ * in the bowl, in the GLB material `mossgate.flame` (emissive), with no shadow, so it costs L0 tile 0/3/3 one draw.
304
+ */
305
+ export function brazierFlame(heightAt: (x: number, z: number) => number, which = 0): Group {
306
+ const [x = 0, z = 0] = layout.BRAZIERS[which] ?? [], y = heightAt(x, z) + 1.5, flame = new Group();
307
+ const cones: [number, number, number, number][] = [[0, 0, 0.42, 1.3], [0.24, 0.12, 0.24, 0.8], [-0.22, 0.16, 0.26, 0.9], [0.08, -0.25, 0.22, 0.75], [-0.14, -0.18, 0.2, 0.65]];
308
+ cones.forEach(([dx, dz, r, h], i) => {
309
+ const cone = new Mesh(foliageUv(new CylinderGeometry(0, r, h, 5), 1), foliageMaterial(0xffffff)); cone.position.set(x + dx, y + h / 2, z + dz); cone.rotation.y = jitter(i, 110) * 1.2; flame.add(cone);
310
+ });
311
+ return flame;
312
+ }
313
+
314
+ /** Round toy trees in the yard (LF1-5): x, z, size. Off every walk the MH-2, MH-3 and LF1-0 proofs take (see foliage test). */
315
+ export const TREES: readonly [number, number, number][] = [[-6.0, -13.5, 1.1], [-9.0, -16.5, 0.95], [5.3, -13.6, 1.1], [9.5, -2.5, 0.9], [15.5, -5.0, 1.0], [2.5, 7.5, 1.0], [12.5, 3.0, 1.05], [-12.5, 3.5, 0.9]];
316
+ /** Grass tufts at the wall bases (the hut, the moss gate's wings and pillars, the arena ring) and a few in the open yard. */
317
+ const TUFTS: readonly [number, number, number][] = [
318
+ [-3.6, -8.75, 1], [3.65, -8.7, 0.9], [-3.35, -10.2, 1.1], [-3.35, -12.6, 0.9], [-3.35, -14.3, 1], [3.35, -10.4, 1], [3.35, -12.2, 1.1], [3.35, -14.5, 0.9], [-1.4, -15.35, 1], [1.3, -15.35, 0.9],
319
+ [-8.6, -10.4, 1], [-8.6, -8.2, 0.9], [-8.4, -6.65, 1.1], [-8.4, -3.35, 1], [-8.6, -2.2, 0.9], [-8.6, 0.6, 1],
320
+ [3.6, -1.6, 0.8], [-2.2, -5.6, 0.8], [5.8, -7.0, 0.9], [-5.6, -11.8, 1], [7.5, -1.2, 0.9], [11.2, -4.6, 0.8], [-0.8, 3.2, 0.8], [4.2, 4.8, 0.9],
321
+ ];
322
+ /** New ferns at the wall bases (the dressing's ten stay where they were): the hut's back corners, the gate wings, the arena. */
323
+ const WALL_FERNS: readonly [number, number, number][] = [[3.5, -14.9, 0.95], [-3.55, -14.8, 0.9], [-8.5, -9.4, 1], [-8.5, 0.1, 0.9]];
324
+
325
+ /**
326
+ * LF1-5: the yard's foliage, all in the measure stone's one static draw per tile (the props bake merges a tile's static
327
+ * shapes into one primitive, so a tree, a tuft or a fern costs bytes, never a draw): eight round toy trees (a six-sided
328
+ * trunk under an 80-face crown, a trunk collider each), grass tufts and fern clumps at the wall bases and around the arena
329
+ * ring. The red mushroom caps are separate (`mushroomCaps`): an emissive surface is its own draw.
330
+ */
331
+ export function mossgateFoliage(heightAt: (x: number, z: number) => number): { object: Group; colliders: Colliders } {
332
+ const root = new Group(), colliders: Colliders = [], bark = foliageMaterial(0x6b4a2e), leaves = foliageMaterial(0x557a2c);
333
+ TREES.forEach(([x, z, s], i) => {
334
+ const y = heightAt(x, z), h = 2.3 * s, r = 1.3 * s;
335
+ const trunk = new Mesh(foliageUv(new CylinderGeometry(0.17 * s, 0.26 * s, h + 0.3, 6, 1, true), 1), bark); trunk.position.set(x, y + h / 2 - 0.15, z);
336
+ const crown = new Mesh(foliageUv(new IcosahedronGeometry(r, 1), 2), leaves); crown.position.set(x, y + h + r * 0.75, z); crown.rotation.set(jitter(i, 100) * 0.4, jitter(i, 101) * 3, 0);
337
+ root.add(trunk, crown);
338
+ colliders.push(BoxCollider.fromData({ kind: 'box', x, y: y + h / 2, z, hx: 0.24 * s, hy: h / 2, hz: 0.24 * s, yaw: -0, surface: 'wood' }).toColliderData());
339
+ });
340
+ TUFTS.forEach(([x, z, s], i) => { root.add(tuft(x, heightAt(x, z), z, s, i)); });
341
+ WALL_FERNS.forEach(([x, z, s], i) => { root.add(fern(x, heightAt(x, z), z, s, 20 + i)); });
342
+ // the arena ring's outer foot, on the yard's side of it: tufts and two ferns either side of the way in
343
+ const { x: cx, z: cz, radius } = layout.ARENA, door = Math.atan2(-cx, -cz);
344
+ [-0.62, -0.44, -0.3, 0.3, 0.46, 0.66, -0.95, 0.98].forEach((da, k) => {
345
+ const x = cx + (radius + 0.75) * Math.sin(door + da), z = cz + (radius + 0.75) * Math.cos(door + da);
346
+ root.add(k < 6 ? tuft(x, heightAt(x, z), z, 1, 40 + k) : fern(x, heightAt(x, z), z, 0.95, 30 + k));
347
+ });
348
+ return { object: root, colliders };
349
+ }
350
+ /**
351
+ * LF1-5 with LF1-2: the red caps of the dressing's mushrooms in tile 0/4/3, as one whole shape at its first cap (one
352
+ * draw, no shadow) in the `mossgate.mushroom-cap` GLB material, which `props.materials` binds to an emissive look entry.
353
+ */
354
+ export function mushroomCaps(heightAt: (x: number, z: number) => number): { mesh: Mesh; transform: Matrix4 } {
355
+ const out: number[] = [], normals: number[] = [];
356
+ let origin: Vector3 | undefined;
357
+ MUSHROOMS.forEach(([x, z], i) => {
358
+ for (let k = 0; k < 3; k++) {
359
+ const mx = x + jitter(i, 20 + k) * 0.28, mz = z + jitter(i, 30 + k) * 0.28, h = 0.16 + (k === 0 ? 0.12 : 0) + jitter(i, 40 + k) * 0.04, y = heightAt(mx, mz);
360
+ if (!redCap(mx, mz)) continue;
361
+ origin ??= new Vector3(mx, y, mz);
362
+ const cap = mushroomCap(0.12 - k * 0.02, foliageMaterial(0xffffff)); cap.position.set(mx - origin.x, y + h - origin.y, mz - origin.z); cap.updateMatrix();
363
+ const g = cap.geometry.toNonIndexed().applyMatrix4(cap.matrix), p = g.getAttribute('position'), n = g.getAttribute('normal');
364
+ for (let v = 0; v < p.count; v++) { out.push(p.getX(v), p.getY(v), p.getZ(v)); normals.push(n.getX(v), n.getY(v), n.getZ(v)); }
365
+ }
366
+ });
367
+ if (origin === undefined) throw new Error('mushroomCaps: no cap in tile 0/4/3');
368
+ const geometry = new BufferGeometry().setAttribute('position', new Float32BufferAttribute(out, 3)).setAttribute('normal', new Float32BufferAttribute(normals, 3))
369
+ .setAttribute('color', new Float32BufferAttribute(new Float32Array(out.length).fill(1), 3));
370
+ const mesh = new Mesh(geometry, new MeshStandardMaterial({ color: 0xffffff, vertexColors: true })); mesh.castShadow = false;
371
+ return { mesh, transform: new Matrix4().makeTranslation(origin.x, origin.y, origin.z) };
372
+ }
373
+
374
+ /**
375
+ * The moss gate (MH-2, LF1-0's form) at `layout.MOSSGATE`: two chunky square stone pillars with moss caps, a lintel between
376
+ * them and low wing walls running north and south, and across the 2.6 m gap a row of thick stone bars on a sill (the
377
+ * panel, with its own collider) that brazier A's field takes away. Vines hang down the pillars' yard faces; they are their
378
+ * own piece so the coarse (L1) tiles can skip them. You walk west through it.
379
+ */
380
+ export function mossGate(heightAt: (x: number, z: number) => number): { frame: Group; panel: Group; vines: Group; frameColliders: NonNullable<TemplatePart['colliders']>; panelColliders: NonNullable<TemplatePart['colliders']> } {
381
+ const { x, z } = layout.MOSSGATE, y = heightAt(x, z), frame = new Group(), panel = new Group(), vines = new Group(), frameColliders: NonNullable<TemplatePart['colliders']> = [];
382
+ const box = (bx: number, by: number, bz: number, hx: number, hy: number, hz: number): NonNullable<TemplatePart['colliders']>[number] => BoxCollider.fromData({ kind: 'box', x: bx, y: by, z: bz, hx, hy, hz, yaw: -0, surface: 'stone' }).toColliderData();
383
+ const GAP = 1.3, P = 1.1, H = 3.2;
384
+ for (const side of [-1, 1]) {
385
+ const pz = z + side * (GAP + P / 2);
386
+ // LF1-8: a thick moss cushion over each pillar (t1-06), the same box resized, so no bytes added in 0/3/3
387
+ frame.add(block(P, H, P, 1, x, y + H / 2, pz), block(P + 0.28, 0.36, P + 0.28, 2, x, y + H + 0.16, pz, jitter(side, 95) * 0.06), block(P + 0.12, 0.3, P + 0.12, 1, x, y + 0.15, pz));
388
+ frameColliders.push(box(x, y + H / 2, pz, P / 2, H / 2, P / 2));
389
+ const wz = z + side * 4.1;
390
+ frame.add(block(0.6, 1.5, 4.4, 1, x, y + 0.75, wz), block(0.7, 0.1, 4.5, 2, x, y + 1.55, wz));
391
+ frameColliders.push(box(x, y + 0.75, wz, 0.3, 0.75, 2.2));
392
+ // three vines down the pillar's yard (east) face, each a moss strand with two leaf tufts
393
+ for (let k = 0; k < 3; k++) {
394
+ const vz = pz + (k - 1) * 0.34 + jitter(k, 90 + side) * 0.06, len = 1.1 + (jitter(k, 92 + side) + 1) * 0.55, vx = x + P / 2 + 0.03;
395
+ vines.add(block(0.05, len, 0.09, 2, vx, y + H - len / 2, vz));
396
+ for (let t = 0; t < 2; t++) vines.add(block(0.08, 0.16, 0.2, 2, vx + 0.02, y + H - len * (0.35 + t * 0.45), vz + (t === 0 ? 0.07 : -0.07), 0, 0.3));
397
+ }
398
+ }
399
+ frame.add(block(0.8, 0.4, GAP * 2, 1, x, y + 2.85, z), block(0.96, 0.16, GAP * 2, 2, x, y + 3.13, z));
400
+ // LF1-8: four flagstones leading up to the sill from the yard (t1-06): flat quads, two triangles each (0/3/3 is near its bytes)
401
+ for (let k = 0; k < 4; k++) {
402
+ const fx = x + 1.25 + k * 1.05, fz = z + jitter(k, 96) * 0.22, w = 0.95 + jitter(k, 97) * 0.12, d = 1.15 + jitter(k, 98) * 0.15, slab = new Mesh(flagstone(w, d), foliageMaterial(STONE));
403
+ slab.position.set(fx, Math.max(...[[-1, -1], [-1, 1], [1, -1], [1, 1]].map(([sx = 0, sz = 0]) => heightAt(fx + sx * 0.75, fz + sz * 0.75))) + 0.03, fz);
404
+ slab.rotation.y = jitter(k, 99) * 0.25; frame.add(slab); // over its highest corner (Codex review), so no edge sinks into the ground
405
+ }
406
+ // the panel: five thick stone bars on a sill, under the lintel
407
+ panel.add(block(0.34, 0.2, GAP * 2, 1, x, y + 0.1, z));
408
+ for (let k = 0; k < 5; k++) panel.add(block(0.26, 2.45, 0.26, 1, x, y + 0.2 + 2.45 / 2, z - 1.04 + k * 0.52));
409
+ return { frame, panel, vines, frameColliders, panelColliders: [box(x, y + 1.6, z, 0.2, 1.6, GAP)] };
410
+ }
411
+
412
+ /**
413
+ * The moss bridge (MH-3): five stone pillars across the pond at `layout.POND` (radius 5, bed −3, water at 0), west to east.
414
+ * `raised` stands their moss-capped tops 0.1 m over the water, with colliders, for brazier B's field to show; `sunk` is the
415
+ * same pillars, a little thinner and 1.4 m under, with no collider, so before B the walk ends in the water.
416
+ */
417
+ export function pondStones(): { raised: Group; sunk: Group; colliders: Colliders } {
418
+ const { x: cx, z: cz } = layout.POND, raised = new Group(), sunk = new Group(), colliders: Colliders = [], BED = -3, w = 1.75;
419
+ for (let i = 0; i < 5; i++) {
420
+ const x = cx - 4.1 + i * 2.05, z = cz + jitter(i, 80) * 0.12, yaw = jitter(i, 81) * 0.1;
421
+ for (const [root, top, s] of [[raised, 0.1, w], [sunk, -1.4, w - 0.2]] as const) {
422
+ const h = top - BED - 0.1;
423
+ root.add(block(s, h, s, 1, x, BED + h / 2, z, yaw), block(s + 0.1, 0.1, s + 0.1, 2, x, top - 0.05, z, yaw));
424
+ }
425
+ colliders.push(stoneBox(x, (0.1 + BED) / 2, z, w / 2, (0.1 - BED) / 2, w / 2, yaw));
426
+ }
427
+ return { raised, sunk, colliders };
428
+ }
429
+ /** LF1-8: the pond's planting colours (the look's `tint` keeps them: reeds and pads trim green, cattails and flowers structure). */
430
+ export const REED = 0x5f8a32, CATTAIL = 0x6b4226, LILY = 0x4c8a3a, LILY_FLOWER = 0xf2a6c2;
431
+ /** LF1-8: the crossing's line (the MH-3 bridge walk runs along z = POND.z) and the half width kept clear of plants and lip. */
432
+ export const CROSSING_CLEAR = 1.5;
433
+ /** LF1-8: reed clumps round the pond: angle (degrees from +x), radius, size. Off the crossing line and B's pad. */
434
+ export const REEDS: readonly [number, number, number][] = [
435
+ [28, 5.3, 1.05], [52, 4.6, 0.9], [74, 5.4, 1.1], [101, 5.25, 0.95], [126, 4.7, 1.0], [152, 5.4, 1.1],
436
+ [205, 5.3, 1.0], [228, 4.6, 0.9], [251, 5.45, 1.1], [283, 5.2, 0.95], [306, 4.65, 1.05], [333, 5.35, 0.9],
437
+ ];
438
+ /** LF1-8: lily pads on the water: x and z off the pond's centre, radius; `flower` marks the three in bloom. */
439
+ export const LILIES: readonly [number, number, number, boolean][] = [
440
+ [-2.6, 2.4, 0.42, true], [-1.2, 3.3, 0.34, false], [1.4, 2.6, 0.4, false], [2.9, 1.9, 0.3, true], [0.2, 3.9, 0.28, false],
441
+ [-2.9, -2.1, 0.38, false], [-0.8, -3.2, 0.44, true], [1.8, -2.7, 0.32, false], [3.1, -1.8, 0.36, false], [-1.9, -3.6, 0.26, false],
442
+ ];
443
+ /** LF1-8: a flat, upward-facing w × d quad (a flagstone): two triangles, no grid. */
444
+ function flagstone(w: number, d: number): BufferGeometry {
445
+ const a = w / 2, b = d / 2, geometry = new BufferGeometry().setAttribute('position', new Float32BufferAttribute([-a, 0, -b, -a, 0, b, a, 0, b, -a, 0, -b, a, 0, b, a, 0, -b], 3));
446
+ geometry.computeVertexNormals(); return foliageUv(geometry, 1);
447
+ }
448
+ /** A flat, upward-facing fan (a lily pad): `n` wedges round (0, 0, 0) with one wedge left out as the notch. */
449
+ function lilyPad(r: number, notch: number): BufferGeometry {
450
+ const out: number[] = [], n = 9;
451
+ for (let k = 1; k < n; k++) {
452
+ const a = notch + (k / n) * Math.PI * 2, b = notch + ((k + 1) / n) * Math.PI * 2;
453
+ out.push(0, 0, 0, Math.cos(b) * r, 0, Math.sin(b) * r, Math.cos(a) * r, 0, Math.sin(a) * r);
454
+ }
455
+ const geometry = new BufferGeometry().setAttribute('position', new Float32BufferAttribute(out, 3)); geometry.computeVertexNormals();
456
+ return foliageUv(geometry, 2);
457
+ }
458
+ /** A reed clump at (x, y, z): six tall three-sided blades leaning out, and two cattail heads on stalks, `s` its size. */
459
+ function reedClump(x: number, y: number, z: number, s: number, i: number): Group {
460
+ const root = new Group(), blades: number[] = [];
461
+ root.position.set(x, y, z);
462
+ for (let k = 0; k < 6; k++) {
463
+ const a = (k / 6) * Math.PI * 2 + jitter(i, 120 + k) * 0.5, h = s * (1.05 + jitter(i, 126 + k) * 0.3), r = 0.035 * s, cx = Math.cos(a) * 0.09 * s, cz = Math.sin(a) * 0.09 * s;
464
+ const base = [0, 1, 2].map(c => new Vector3(cx + Math.cos(a + (c * 2 * Math.PI) / 3) * r, 0, cz + Math.sin(a + (c * 2 * Math.PI) / 3) * r));
465
+ const blade = tent([...base, new Vector3(cx + Math.cos(a) * h * 0.22, h, cz + Math.sin(a) * h * 0.22)], [[0, 1, 3], [1, 2, 3], [2, 0, 3]], new Vector3(cx, 0, cz), 2).getAttribute('position');
466
+ for (let v = 0; v < blade.count; v++) blades.push(blade.getX(v), blade.getY(v), blade.getZ(v));
467
+ }
468
+ const geometry = new BufferGeometry().setAttribute('position', new Float32BufferAttribute(blades, 3)); geometry.computeVertexNormals();
469
+ root.add(new Mesh(foliageUv(geometry, 2), foliageMaterial(REED)));
470
+ for (let k = 0; k < 2; k++) {
471
+ const dx = jitter(i, 140 + k) * 0.12, dz = jitter(i, 142 + k) * 0.12, h = s * (1.25 + k * 0.18);
472
+ const stalk = new Mesh(foliageUv(new CylinderGeometry(0.012, 0.016, h, 3, 1, true), 2), foliageMaterial(REED)); stalk.position.set(dx, h / 2, dz);
473
+ const head = new Mesh(foliageUv(new CylinderGeometry(0.035, 0.055, 0.26 * s, 4, 1, true), 1), foliageMaterial(CATTAIL)); head.position.set(dx, h + 0.1 * s, dz);
474
+ root.add(stalk, head);
475
+ }
476
+ return root;
477
+ }
478
+ /**
479
+ * LF1-8: the pond's planting and bank (t1-08 to t1-10): reed clumps round the rim and in the shallows, lily pads on the
480
+ * water with three pink flowers, and a low moss-capped stone lip round the bank that hides the crater's slanted edge,
481
+ * open where the crossing meets each bank. All in L0 tile 0/4/4's static draw (bytes, not draws: it is at 8). No
482
+ * colliders: the bridge walk and the swim are unchanged.
483
+ */
484
+ export function pondPlanting(heightAt: (x: number, z: number) => number): Group {
485
+ const { x: cx, z: cz } = layout.POND, root = new Group(), WATER = 0, R = 5;
486
+ REEDS.forEach(([deg, r, s], i) => {
487
+ const a = (deg * Math.PI) / 180, x = cx + Math.cos(a) * r, z = cz + Math.sin(a) * r;
488
+ // a clump in the shallows (inside the rim) stands up from just under the surface; one on the bank from the ground
489
+ root.add(reedClump(x, r < R ? WATER - 0.35 : heightAt(x, z), z, s, i));
490
+ });
491
+ const flowers = foliageMaterial(LILY_FLOWER), pads = foliageMaterial(LILY);
492
+ LILIES.forEach(([dx, dz, r, flower], i) => {
493
+ const pad = new Mesh(lilyPad(r, jitter(i, 150) * Math.PI), pads); pad.name = 'lily-pad'; pad.position.set(cx + dx, WATER + 0.03, cz + dz); root.add(pad);
494
+ if (!flower) return;
495
+ const points = [0, 1, 2, 3, 4].map(k => new Vector3(Math.cos((k / 5) * Math.PI * 2) * 0.13, 0, Math.sin((k / 5) * Math.PI * 2) * 0.13));
496
+ const bloom = new Mesh(tent([...points, new Vector3(0, 0.14, 0)], [[0, 1, 5], [1, 2, 5], [2, 3, 5], [3, 4, 5], [4, 0, 5]], new Vector3(0, 0.03, 0), 1), flowers);
497
+ bloom.position.set(cx + dx + 0.08, WATER + 0.05, cz + dz - 0.05); root.add(bloom);
498
+ });
499
+ // the lip: 20 segments of a moss-topped stone kerb over the rim (a top, an inner face down to the water and a short outer
500
+ // face, six triangles a segment), the ones the crossing passes through left out
501
+ const N = 20, RIN = R - 0.3, ROUT = R + 0.45, moss = foliageMaterial(MOSS), stone = foliageMaterial(STONE);
502
+ for (let k = 0; k < N; k++) {
503
+ const a0 = (k / N) * Math.PI * 2, a1 = ((k + 1) / N) * Math.PI * 2, am = (a0 + a1) / 2;
504
+ if (Math.abs(Math.sin(am) * R) < CROSSING_CLEAR) continue;
505
+ const at = (r: number, a: number, y: number): Vector3 => new Vector3(cx + Math.cos(a) * r, y, cz + Math.sin(a) * r);
506
+ const ground = heightAt(cx + Math.cos(am) * ROUT, cz + Math.sin(am) * ROUT) - 0.05, top = Math.max(ground + 0.17, WATER + 0.12); // the kerb stands proud of the water
507
+ const lid = [at(RIN, a0, top), at(ROUT, a0, top), at(ROUT, a1, top), at(RIN, a1, top)];
508
+ root.add(new Mesh(tent(lid, [[0, 1, 2], [0, 2, 3]], at((RIN + ROUT) / 2, am, top - 1), 2), moss));
509
+ const sides = [at(RIN, a0, top), at(RIN, a1, top), at(RIN, a1, WATER - 0.4), at(RIN, a0, WATER - 0.4), at(ROUT, a0, top), at(ROUT, a1, top), at(ROUT, a1, ground), at(ROUT, a0, ground)];
510
+ root.add(new Mesh(tent(sides, [[0, 1, 2], [0, 2, 3], [4, 5, 6], [4, 6, 7]], at((RIN + ROUT) / 2, am, (top + ground) / 2), 1), stone));
511
+ }
512
+ return root;
513
+ }
514
+
515
+ /**
516
+ * The arena (MH-3): a 3.2 m stone ring at `layout.ARENA` round the boss's floor, twenty segments with the one facing spawn
517
+ * left out as the way in. Two posts and a lintel frame it, and `gate` (bars, a panel with its own collider) shuts it
518
+ * until brazier C's field takes it away. It sits north-west of spawn so the gate's panel lands in L0 tile 0/3/4, the
519
+ * one tile there with two draws to spare.
520
+ */
521
+ export function arenaRing(heightAt: (x: number, z: number) => number): { wall: Group; gate: Group; wallColliders: Colliders; gateColliders: Colliders } {
522
+ const { x: cx, z: cz, radius: r } = layout.ARENA, wall = new Group(), gate = new Group(), wallColliders: Colliders = [], N = 20, H = 3.2;
523
+ const door = Math.atan2(-cx, -cz), len = 2 * r * Math.sin(Math.PI / N) + 0.2;
524
+ for (let k = 1; k < N; k++) {
525
+ const a = door + (k / N) * Math.PI * 2, x = cx + r * Math.sin(a), z = cz + r * Math.cos(a), y = heightAt(x, z) - 0.2;
526
+ wall.add(block(len, H, 0.7, 1, x, y + H / 2, z, a), block(len + 0.05, 0.14, 0.86, 2, x, y + H + 0.07, z, a));
527
+ wallColliders.push(stoneBox(x, y + H / 2, z, len / 2, H / 2, 0.35, a));
528
+ }
529
+ // the way in: posts at the gap's two ends, a lintel over it, and the bars between, all in the gap's own frame
530
+ const half = r * Math.sin(Math.PI / N), inner = r * Math.cos(Math.PI / N), at = (along: number): [number, number] =>
531
+ [cx + inner * Math.sin(door) + along * Math.cos(door), cz + inner * Math.cos(door) - along * Math.sin(door)];
532
+ const [gx, gz] = at(0), gy = heightAt(gx, gz) - 0.2;
533
+ for (const side of [-1, 1]) {
534
+ const [px, pz] = at(side * half);
535
+ wall.add(block(0.9, H + 0.8, 0.9, 1, px, gy + (H + 0.8) / 2, pz, door), block(1.0, 0.14, 1.0, 2, px, gy + H + 0.87, pz, door));
536
+ wallColliders.push(stoneBox(px, gy + (H + 0.8) / 2, pz, 0.45, (H + 0.8) / 2, 0.45, door));
537
+ }
538
+ wall.add(block(half * 2 + 0.9, 0.5, 0.8, 1, gx, gy + H + 0.55, gz, door));
539
+ for (let k = 0; k < 7; k++) { const [bx, bz] = at(-half + 0.45 + (k + 0.5) * (half * 2 - 0.9) / 7); gate.add(block(0.14, H - 0.1, 0.14, 2, bx, gy + (H - 0.1) / 2, bz, door)); }
540
+ for (const y of [0.5, 1.7, 2.8]) gate.add(block(half * 2 - 0.9, 0.12, 0.1, 2, gx, gy + y, gz, door));
541
+ return { wall, gate, wallColliders, gateColliders: [stoneBox(gx, gy + H / 2, gz, half - 0.45, H / 2, 0.15, door)] };
542
+ }
543
+
544
+ /** LF1-9: the arena floor's slate (the checker's dark squares; the light ones are moss) and its cell, in metres. */
545
+ export const SLATE = 0x4f4d52, FLOOR_MOSS = 0x4e6a2a, ARENA_CELL = 1.5;
546
+ /** LF1-9: the three braziers on the arena rim, as angles round `layout.ARENA` from the way in (across from it and either side). */
547
+ export const RIM_BRAZIERS: readonly number[] = [Math.PI - 0.72, Math.PI, Math.PI + 0.72];
548
+ /** LF1-9: the Warden's slam tell, a ring this far round `layout.BOSS` (MH-4's twelve anchors stood 3.5 m out). */
549
+ export const TELL_RADIUS = 3.5;
550
+ /** The arena's way in, as an angle round `layout.ARENA` (the gap faces spawn). */
551
+ const arenaDoor = (): number => Math.atan2(-layout.ARENA.x, -layout.ARENA.z);
552
+ /** A rim brazier's centre, on the wall cap's top. */
553
+ function rimBrazier(heightAt: (x: number, z: number) => number, k: number): [number, number, number] {
554
+ const { x: cx, z: cz, radius: r } = layout.ARENA, a = arenaDoor() + (RIM_BRAZIERS[k] ?? 0), x = cx + r * Math.sin(a), z = cz + r * Math.cos(a);
555
+ return [x, heightAt(x, z) - 0.2 + 3.2 + 0.14, z];
556
+ }
557
+ /**
558
+ * LF1-9 (t1-12 to t1-15): the arena's floor and rim, in its tile's (0/3/4) one static draw. A checker of flat 1.5 m squares,
559
+ * slate and moss, over the ground inside the ring (each square over its highest corner, no collider: the walk is the
560
+ * ground's); a jagged moss drip under each wall segment's cap on the inner face; and three stone braziers on the rim across
561
+ * from the way in, their flames a panel brazier C's field shows (`rimFlames`).
562
+ */
563
+ function arenaDressing(root: Group, heightAt: (x: number, z: number) => number): void {
564
+ const { x: cx, z: cz, radius: r } = layout.ARENA, door = arenaDoor(), N = 20, H = 3.2, slate = foliageMaterial(SLATE), moss = foliageMaterial(MOSS), floorMoss = foliageMaterial(FLOOR_MOSS);
565
+ const reach = r - 1.0, n = Math.ceil(reach / ARENA_CELL), s = ARENA_CELL / 2 - 0.04;
566
+ for (let i = -n; i <= n; i++) for (let j = -n; j <= n; j++) {
567
+ const x = cx + i * ARENA_CELL, z = cz + j * ARENA_CELL;
568
+ if (Math.hypot(Math.abs(i * ARENA_CELL) + ARENA_CELL / 2, Math.abs(j * ARENA_CELL) + ARENA_CELL / 2) > reach + 0.6) continue;
569
+ const y = Math.max(...[[-1, -1], [-1, 1], [1, -1], [1, 1]].map(([a = 0, b = 0]) => heightAt(x + a * s, z + b * s))) + 0.03;
570
+ const square = new Mesh(flagstone(s * 2, s * 2), (i + j) % 2 === 0 ? slate : floorMoss); square.position.set(x, y, z); root.add(square);
571
+ }
572
+ // the moss drip: under each segment's cap on the inner face, a strip whose lower edge hangs 0.2 to 0.9 m down
573
+ for (let k = 1; k < N; k++) {
574
+ // on the segment box's inner face (a chord `half` long each way, 0.35 m in from the ring), 2 cm proud of it
575
+ const am = door + (k / N) * Math.PI * 2, ri = r - 0.37, half = r * Math.sin(Math.PI / N) + 0.05;
576
+ const top = heightAt(cx + r * Math.sin(am), cz + r * Math.cos(am)) - 0.2 + H, at = (t: number, y: number): Vector3 => new Vector3(cx + ri * Math.sin(am) + t * Math.cos(am), y, cz + ri * Math.cos(am) - t * Math.sin(am));
577
+ const points: Vector3[] = [], tris: [number, number, number][] = [];
578
+ for (let c = 0; c <= 4; c++) { const t = -half + (half * 2 * c) / 4; points.push(at(t, top), at(t, top - 0.2 - (jitter(k, 160 + c) + 1) * 0.35)); }
579
+ for (let c = 0; c < 4; c++) tris.push([c * 2, c * 2 + 2, c * 2 + 1], [c * 2 + 1, c * 2 + 2, c * 2 + 3]);
580
+ root.add(new Mesh(tent(points, tris, new Vector3(cx + (r + 2) * Math.sin(am), top - 0.5, cz + (r + 2) * Math.cos(am)), 2), moss));
581
+ }
582
+ // the rim braziers: a plinth on the cap, a stem and a bowl, turned to the ring
583
+ RIM_BRAZIERS.forEach((da, k) => {
584
+ const [x, y, z] = rimBrazier(heightAt, k), yaw = door + da;
585
+ root.add(block(0.8, 0.3, 0.8, 1, x, y + 0.15, z, yaw, 0, STONE), block(0.46, 0.4, 0.46, 1, x, y + 0.5, z, yaw, 0, STONE), block(1.0, 0.24, 1.0, 1, x, y + 0.82, z, yaw, 0, 0x6c6264));
586
+ });
587
+ }
588
+ /** LF1-9: the rim braziers' flames, three faceted cones in each bowl, a panel brazier C's field (104) shows, in `mossgate.flame`. */
589
+ export function rimFlames(heightAt: (x: number, z: number) => number): Group {
590
+ const flames = new Group();
591
+ RIM_BRAZIERS.forEach((_, k) => {
592
+ const [x, y, z] = rimBrazier(heightAt, k);
593
+ for (const [i, [dx, dz, rr, h]] of ([[0, 0, 0.34, 1.05], [0.18, 0.1, 0.2, 0.7], [-0.16, -0.12, 0.2, 0.62]] as const).entries()) {
594
+ const cone = new Mesh(foliageUv(new CylinderGeometry(0, rr, h, 5), 1), foliageMaterial(0xffffff)); cone.position.set(x + dx, y + 0.94 + h / 2, z + dz); cone.rotation.y = jitter(k * 3 + i, 170) * 1.2; flames.add(cone);
595
+ }
596
+ });
597
+ return flames;
598
+ }
599
+ /**
600
+ * LF1-9: the Warden's slam tell, a glowing ring on the floor `TELL_RADIUS` round it (field 110 shows it), and its core, a
601
+ * faceted gem over its crown where it stands (field 111; a panel is fixed, so when the Warden steps toward a player in a
602
+ * window the gem stays over its spot). Panels in emissive materials with no shadow, one draw each in 0/3/4.
603
+ */
604
+ export function wardenTell(heightAt: (x: number, z: number) => number): { ring: Group; core: Group } {
605
+ const { x: bx, z: bz } = layout.BOSS, ring = new Group(), core = new Group(), points: Vector3[] = [], tris: [number, number, number][] = [], N = 48, W = 0.22;
606
+ for (let k = 0; k < N; k++) {
607
+ const a = (k / N) * Math.PI * 2;
608
+ for (const rr of [TELL_RADIUS - W, TELL_RADIUS + W]) { const x = bx + Math.cos(a) * rr, z = bz + Math.sin(a) * rr; points.push(new Vector3(x, heightAt(x, z) + 0.09, z)); }
609
+ const i = k * 2, j = ((k + 1) % N) * 2;
610
+ tris.push([i, j, i + 1], [i + 1, j, j + 1]);
611
+ }
612
+ // `tent` winds each face away from a point under the ring, so every triangle faces up
613
+ ring.add(new Mesh(tent(points, tris, new Vector3(bx, heightAt(bx, bz) - 5, bz), 1), foliageMaterial(0xffffff)));
614
+ const gem = new Mesh(foliageUv(new IcosahedronGeometry(0.42, 0), 1), foliageMaterial(0xffffff)); gem.position.set(bx, heightAt(bx, bz) + 3.5, bz); gem.scale.set(1.2, 1.8, 1.2); core.add(gem);
615
+ return { ring, core };
616
+ }
617
+
618
+ /** The jump course's three practice pads, `baseHeight` up at `x`. */
619
+ export function jumpCoursePads(baseHeight: number, x = 0): Group {
620
+ const root = new Group();
621
+ for (let i = 0; i < 3; i++) { const pad = cube(3, 0.3, 3); pad.position.set(x, baseHeight + i * 0.3, -i * 4); root.add(pad); }
622
+ return root;
623
+ }
624
+
625
+ /** The lantern as held (lamp and its unlit light, at the off-hand offset). */
626
+ export function lanternModel(): Group {
627
+ const model = new Group(), lamp = cube(0.12, 0.18, 0.12, 0x888888, 2);
628
+ model.add(lamp, new PointLight(0xffe1aa, 0, 8)); model.position.set(-0.3, -0.3, -0.55);
629
+ return model;
630
+ }