@wildshard/sdk 0.0.1 → 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 +13 -5
  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 +365 -3
  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,84 @@
1
+ import { BufferGeometry, Float32BufferAttribute, Matrix4, MeshBasicMaterial } from 'three';
2
+ import { WebIO } from '@gltf-transform/core';
3
+ import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
4
+ import { MeshoptDecoder } from 'meshoptimizer';
5
+ import { GeometryPackWriter } from '../kit/geometryPack';
6
+
7
+ class MapModelIO extends WebIO {
8
+ protected override readURI(uri: string, _type: 'view' | 'text'): Promise<never> {
9
+ return Promise.reject(new Error(`Map model must be self-contained: ${uri}`));
10
+ }
11
+ }
12
+
13
+ /** Decode one prepared mesh from owned GLB bytes, keeping its local pose unless world is explicit.
14
+ * External resources refuse; this build-only operation has no filesystem or URL authority. */
15
+ export async function mapModelBytes(bytes: Uint8Array, slot = 0, world = false): Promise<BufferGeometry> {
16
+ await MeshoptDecoder.ready;
17
+ const io = new MapModelIO().registerExtensions(ALL_EXTENSIONS).registerDependencies({ 'meshopt.decoder': MeshoptDecoder });
18
+ const doc = await io.readBinary(bytes);
19
+ const node = doc.getRoot().listNodes().filter(row => row.getMesh() !== null).at(slot), mesh = node?.getMesh();
20
+ if (mesh?.listPrimitives().length !== 1) throw new Error(`Map model needs one primitive: ${slot}`);
21
+ const primitive = mesh.listPrimitives()[0];
22
+ if (primitive === undefined) throw new Error(`Missing map primitive: ${slot}`);
23
+ const geometry = new BufferGeometry();
24
+ for (const [semantic, name] of [['POSITION', 'position'], ['COLOR_0', 'color']] as const) {
25
+ const source = primitive.getAttribute(semantic); if (source === null) continue;
26
+ const values: number[] = [];
27
+ for (let i = 0; i < source.getCount(); i++) values.push(...source.getElement(i, []).slice(0, 3));
28
+ geometry.setAttribute(name, new Float32BufferAttribute(values, 3));
29
+ }
30
+ const index = primitive.getIndices(); if (index !== null) {
31
+ const values = index.getArray(); if (values === null) throw new Error('Missing map primitive indices');
32
+ geometry.setIndex(Array.from(values));
33
+ }
34
+ if (world) {
35
+ if (node === undefined) throw new Error(`Missing map model node: ${slot}`);
36
+ geometry.applyMatrix4(new Matrix4().fromArray(node.getWorldMatrix()));
37
+ }
38
+ return geometry;
39
+ }
40
+
41
+ interface MapShape { name: string; geometry: BufferGeometry; material: MeshBasicMaterial }
42
+ interface MapNode {
43
+ id: string; kind: 'mesh'; name: string; geometry: string; material: string;
44
+ instances: number; matrices: number[];
45
+ }
46
+
47
+ /** Build-only ordered geometry and float32 placements for the existing private map scene.
48
+ * Geometry is borrowed until the caller disposes it; packing installs no reader or publisher. */
49
+ export class MapAssembly {
50
+ readonly shapes: MapShape[] = [];
51
+ readonly nodes: MapNode[] = [];
52
+ readonly inventory: Record<string, number> = {};
53
+
54
+ /** Append one source shape and its exact rendered instance matrices, retaining insertion order. */
55
+ add(name: string, geometry: BufferGeometry, matrices: readonly Matrix4[] = [new Matrix4()]): void {
56
+ if (matrices.length === 0 || geometry.getAttribute('position').count === 0) return;
57
+ const id = `part-${this.shapes.length}`;
58
+ const material = new MeshBasicMaterial({ vertexColors: geometry.hasAttribute('color') });
59
+ this.shapes.push({ name: id, geometry, material });
60
+ // InstancedMesh stores float32 matrices in play; retain that same rounding.
61
+ this.nodes.push({ id, kind: 'mesh', name, geometry: id, material: 'map', instances: matrices.length,
62
+ matrices: matrices.flatMap(matrix => Array.from(Float32Array.from(matrix.elements))) });
63
+ this.inventory[name] = (this.inventory[name] ?? 0) + matrices.length;
64
+ }
65
+
66
+ /** Return independently owned canonical scene JSON and raw packed geometry.
67
+ * Compression and file/image publication belong to the caller's explicit adapter. */
68
+ pack(): { json: Uint8Array; binary: Uint8Array } {
69
+ const pack = new GeometryPackWriter('map-assembly');
70
+ for (const shape of this.shapes) {
71
+ const geometry = new BufferGeometry();
72
+ geometry.setAttribute('position', shape.geometry.getAttribute('position'));
73
+ const source = shape.geometry.getAttribute('color'), colour = shape.material.color.toArray();
74
+ const count = geometry.getAttribute('position').count, values = new Float32Array(count * 3);
75
+ for (let i = 0; i < count; i++) for (let c = 0; c < 3; c++) values[i * 3 + c] = (source?.getComponent(i, c) ?? .45) * (colour[c] ?? Number.NaN);
76
+ geometry.setAttribute('color', new Float32BufferAttribute(values, 3)); geometry.setIndex(shape.geometry.getIndex());
77
+ pack.add(geometry); geometry.dispose();
78
+ }
79
+ const binary = pack.bytes();
80
+ const scene = { version: 1, root: 'root', nodes: [{ kind: 'group', id: 'root', children: this.nodes.map(row => row.id) }, ...this.nodes], materials: [{ id: 'map', kind: 'port', source: 'map' }] };
81
+ const json = new TextEncoder().encode(`${JSON.stringify({ version: 1, inventory: this.inventory, pack: { ...pack.rows(), names: this.shapes.map(row => row.name) }, scene })}\n`);
82
+ return { json, binary };
83
+ }
84
+ }
@@ -0,0 +1,173 @@
1
+ import { WebIO, type Document, type Node } from '@gltf-transform/core';
2
+ import { ALL_EXTENSIONS, type InstancedMesh } from '@gltf-transform/extensions';
3
+ import { MeshoptDecoder } from 'meshoptimizer';
4
+ import { Matrix4, Quaternion, Vector3, type BufferGeometry } from 'three';
5
+ import type { TerrainTileData } from '@wildshard/format/terrainTileBytes';
6
+ import type { MapPaletteRow } from '@wildshard/format/minimap';
7
+
8
+ /** Complete source-owned paint bands and ordered overlays before runtime map installation. */
9
+ export type AuthorMapPalette = MapPaletteRow;
10
+
11
+ const identity = new Matrix4();
12
+ const byte = (value: number): number => Math.max(0, Math.min(255, Math.round(value)));
13
+ const srgb = (value: number): number => byte(255 * (value <= .0031308 ? 12.92 * value : 1.055 * value ** (1 / 2.4) - .055));
14
+ function at<T>(values: ArrayLike<T>, index: number): T {
15
+ const value = values[index]; if (value === undefined) throw new Error('Incomplete map geometry'); return value;
16
+ }
17
+ type Pair = readonly [number, number];
18
+ type Triple = readonly [number, number, number];
19
+ const triple = (values: ArrayLike<number>): Triple => [at(values, 0), at(values, 1), at(values, 2)];
20
+
21
+ class ByteMapIO extends WebIO {
22
+ protected override readURI(uri: string, _type: 'view' | 'text'): Promise<never> {
23
+ return Promise.reject(new Error(`Map geometry must be self-contained: ${uri}`));
24
+ }
25
+ }
26
+ /** The same 500 m frame as the runtime map: +Z north, -X east. */
27
+ export function mapPixel(x: number, z: number, size = 1000): Pair { return [(250 - x) * size / 500, (250 - z) * size / 500]; }
28
+ /** Explicit byte resolution for retained file adapters; owned inputs need no reader. */
29
+ export type MapGeometryReader = (file: string) => Uint8Array;
30
+ /** Build-only projection of actual terrain, geometry and self-contained GLBs.
31
+ * No filesystem is reachable here; optional file identities resolve only through the caller's explicit reader. */
32
+ export class MapRaster {
33
+ readonly height: Int32Array;
34
+ readonly colour: Uint8Array;
35
+ triangles = 0;
36
+ private readonly documents = new Map<string | Uint8Array, Document>();
37
+ readonly size: number;
38
+ readonly clip: { clipBelow?: number; clipAbove?: number };
39
+ private readonly read: MapGeometryReader | undefined;
40
+ constructor(size = 1000, clip: { clipBelow?: number; clipAbove?: number } = {}, read?: MapGeometryReader) {
41
+ this.size = size; this.clip = clip; this.read = read;
42
+ this.height = new Int32Array(size * size).fill(-2147483648);
43
+ this.colour = new Uint8Array(size * size * 3);
44
+ }
45
+ /** Integer subpixel inclusion and post-interpolation height/colour quantization retain the original raster. */
46
+ triangle(points: readonly (readonly number[])[], colours: readonly (readonly number[])[]): void {
47
+ this.projectedTriangle(points, colours, false);
48
+ }
49
+ /** Projection depends only on the transformed vertex, so indexed faces share it. */
50
+ private project(x: number, y: number, z: number): Triple {
51
+ return [Math.round(((250 - x) * this.size / 500) * 1024), y,
52
+ Math.round(((250 - z) * this.size / 500) * 1024)];
53
+ }
54
+ private projectedTriangle(points: readonly (readonly number[])[], colours: readonly (readonly number[])[], projected = true): void {
55
+ this.triangles++;
56
+ const p0 = at(points, 0), p1 = at(points, 1), p2 = at(points, 2);
57
+ const x0 = projected ? at(p0, 0) : Math.round(((250 - at(p0, 0)) * this.size / 500) * 1024);
58
+ const y0 = projected ? at(p0, 2) : Math.round(((250 - at(p0, 2)) * this.size / 500) * 1024);
59
+ const x1 = projected ? at(p1, 0) : Math.round(((250 - at(p1, 0)) * this.size / 500) * 1024);
60
+ const y1 = projected ? at(p1, 2) : Math.round(((250 - at(p1, 2)) * this.size / 500) * 1024);
61
+ const x2 = projected ? at(p2, 0) : Math.round(((250 - at(p2, 0)) * this.size / 500) * 1024);
62
+ const y2 = projected ? at(p2, 2) : Math.round(((250 - at(p2, 2)) * this.size / 500) * 1024);
63
+ const area = (x1 - x0) * (y2 - y0) - (y1 - y0) * (x2 - x0);
64
+ if (area === 0) return;
65
+ const lowX = Math.min(x0, x1, x2), highX = Math.max(x0, x1, x2);
66
+ const lowY = Math.min(y0, y1, y2), highY = Math.max(y0, y1, y2);
67
+ // Internal projections are integer subpixels. In this bounded range all
68
+ // edge products are exact integers, and the retained 1e-12 edge allowance
69
+ // spans less than one subpixel. A centre outside this box cannot pass.
70
+ // Public triangle inputs and wider projections keep the original range.
71
+ const bounded = projected && lowX >= -1048576 && highX <= 1048576
72
+ && lowY >= -1048576 && highY <= 1048576;
73
+ const minX = Math.max(0, bounded ? Math.ceil((lowX - 512) / 1024) : Math.floor(lowX / 1024));
74
+ const maxX = Math.min(this.size - 1, bounded ? Math.floor((highX - 512) / 1024) : Math.ceil(highX / 1024));
75
+ const minY = Math.max(0, bounded ? Math.ceil((lowY - 512) / 1024) : Math.floor(lowY / 1024));
76
+ const maxY = Math.min(this.size - 1, bounded ? Math.floor((highY - 512) / 1024) : Math.ceil(highY / 1024));
77
+ for (let y = minY; y <= maxY; y++) for (let x = minX; x <= maxX; x++) {
78
+ const sx = x * 1024 + 512, sy = y * 1024 + 512;
79
+ const a = ((x2 - x1) * (sy - y1) - (y2 - y1) * (sx - x1)) / area,
80
+ b = ((x0 - x2) * (sy - y2) - (y0 - y2) * (sx - x2)) / area, c = 1 - a - b;
81
+ if (a < 0 || b < 0 || c < -1e-12) continue;
82
+ const h = a * at(p0, 1) + b * at(p1, 1) + c * at(p2, 1);
83
+ if (h < (this.clip.clipBelow ?? -Infinity) || h > (this.clip.clipAbove ?? Infinity)) continue;
84
+ const offset = y * this.size + x, fixed = Math.round(h * 65536);
85
+ if (fixed <= at(this.height, offset)) continue;
86
+ this.height[offset] = fixed;
87
+ for (let k = 0; k < 3; k++) this.colour[offset * 3 + k] = byte(a * at(at(colours, 0), k) + b * at(at(colours, 1), k) + c * at(at(colours, 2), k));
88
+ }
89
+ }
90
+ /** Original row-major rendered lattice, including vertex ground colours. */
91
+ terrain(tile: TerrainTileData): void {
92
+ const r = tile.resolution, offset = (x: number, z: number): number => z * r + x;
93
+ const point = (x: number, z: number): Triple => [tile.x + x * tile.size / (r - 1), at(tile.heights, offset(x, z)), tile.z + z * tile.size / (r - 1)];
94
+ const colour = (x: number, z: number): Triple => triple([0, 1, 2].map(k => srgb(tile.colours?.[offset(x, z) * 3 + k] ?? .5)));
95
+ for (let z = 0; z < r - 1; z++) for (let x = 0; x < r - 1; x++) {
96
+ for (const indices of [[[x, z], [x, z + 1], [x + 1, z]], [[x + 1, z + 1], [x + 1, z], [x, z + 1]]] as const)
97
+ this.triangle(indices.map(q => point(...q)), indices.map(q => colour(...q)));
98
+ }
99
+ }
100
+ /** Decode once per input identity; string identities cannot acquire implicit file access. */
101
+ async document(file: string | Uint8Array): Promise<Document> {
102
+ await MeshoptDecoder.ready;
103
+ const io = new ByteMapIO().registerExtensions(ALL_EXTENSIONS).registerDependencies({ 'meshopt.decoder': MeshoptDecoder });
104
+ let doc = this.documents.get(file);
105
+ if (doc === undefined) {
106
+ const bytes = file instanceof Uint8Array ? file : this.read?.(file);
107
+ if (bytes === undefined) throw new Error('Map geometry needs an explicit byte reader');
108
+ doc = await io.readBinary(bytes); this.documents.set(file, doc);
109
+ }
110
+ return doc;
111
+ }
112
+ /** Project exact source vertices and indices without resampling the geometry. */
113
+ geometry(geometry: BufferGeometry, matrix: Matrix4 = identity): void {
114
+ const position = geometry.getAttribute('position'), colour = geometry.getAttribute('color'), indices = geometry.getIndex();
115
+ if (position === undefined) throw new Error('Map geometry needs positions');
116
+ const points: Triple[] = [], colours: number[][] = [];
117
+ for (let i = 0; i < position.count; i++) {
118
+ const point = new Vector3().fromBufferAttribute(position, i).applyMatrix4(matrix);
119
+ points.push(this.project(point.x, point.y, point.z));
120
+ colours.push(colour === undefined ? [180, 180, 180] : [colour.getX(i), colour.getY(i), colour.getZ(i)].map(srgb));
121
+ }
122
+ const facePoints: (readonly number[])[] = [[], [], []], faceColours: number[][] = [[], [], []];
123
+ for (let i = 0; i < (indices?.count ?? position.count); i += 3) {
124
+ const a = indices?.getX(i) ?? i, b = indices?.getX(i + 1) ?? i + 1, c = indices?.getX(i + 2) ?? i + 2;
125
+ facePoints[0] = at(points, a); facePoints[1] = at(points, b); facePoints[2] = at(points, c);
126
+ faceColours[0] = at(colours, a); faceColours[1] = at(colours, b); faceColours[2] = at(colours, c);
127
+ this.projectedTriangle(facePoints, faceColours);
128
+ }
129
+ }
130
+ /** Keep native mesh order, selectors, local/world transforms and instanced placements. */
131
+ async glb(file: string | Uint8Array, placement?: Matrix4, select?: (node: Node, index: number) => boolean, options: { local?: boolean } = {}): Promise<void> {
132
+ const doc = await this.document(file);
133
+ let selected = 0, meshIndex = 0;
134
+ for (const node of doc.getRoot().listNodes()) {
135
+ const mesh = node.getMesh(); if (mesh === null) continue;
136
+ const index = meshIndex++; if (select !== undefined && !select(node, index)) continue;
137
+ selected++;
138
+ const world = new Matrix4().multiplyMatrices(placement ?? identity, options.local === true ? identity : new Matrix4().fromArray(node.getWorldMatrix()));
139
+ const instances = options.local === true ? null : node.getExtension<InstancedMesh>('EXT_mesh_gpu_instancing');
140
+ const translation = instances?.getAttribute('TRANSLATION'), rotation = instances?.getAttribute('ROTATION'), scale = instances?.getAttribute('SCALE');
141
+ const count = instances === null ? 1 : instances.listAttributes()[0]?.getCount() ?? 0;
142
+ for (let copy = 0; copy < count; copy++) {
143
+ const matrix = world.clone();
144
+ if (instances !== null) matrix.multiply(new Matrix4().compose(
145
+ new Vector3().fromArray(translation?.getElement(copy, []) ?? [0, 0, 0]),
146
+ new Quaternion().fromArray(rotation?.getElement(copy, []) ?? [0, 0, 0, 1]),
147
+ new Vector3().fromArray(scale?.getElement(copy, []) ?? [1, 1, 1])));
148
+ for (const primitive of mesh.listPrimitives()) {
149
+ if (primitive.getMode() !== 4) throw new Error(`${String(file)}: map requires triangles`);
150
+ const position = primitive.getAttribute('POSITION'), colour = primitive.getAttribute('COLOR_0'), indices = primitive.getIndices();
151
+ if (position === null) throw new Error(`${String(file)}: missing positions`);
152
+ const base = primitive.getMaterial()?.getBaseColorFactor() ?? [1, 1, 1, 1];
153
+ if (base[3] === 0) continue;
154
+ const points: Triple[] = [], colours: number[][] = [];
155
+ for (let i = 0; i < position.getCount(); i++) {
156
+ const point = new Vector3().fromArray(position.getElement(i, [])).applyMatrix4(matrix);
157
+ points.push(this.project(point.x, point.y, point.z));
158
+ const c = colour?.getElement(i, []) ?? [1, 1, 1];
159
+ colours.push([0, 1, 2].map(k => srgb(at(base, k) * at(c, k))));
160
+ }
161
+ const facePoints: (readonly number[])[] = [[], [], []], faceColours: number[][] = [[], [], []];
162
+ for (let i = 0; i < (indices?.getCount() ?? position.getCount()); i += 3) {
163
+ const a = indices?.getScalar(i) ?? i, b = indices?.getScalar(i + 1) ?? i + 1, c = indices?.getScalar(i + 2) ?? i + 2;
164
+ facePoints[0] = at(points, a); facePoints[1] = at(points, b); facePoints[2] = at(points, c);
165
+ faceColours[0] = at(colours, a); faceColours[1] = at(colours, b); faceColours[2] = at(colours, c);
166
+ this.projectedTriangle(facePoints, faceColours);
167
+ }
168
+ }
169
+ }
170
+ }
171
+ if (selected === 0 && select !== undefined) throw new Error(`${String(file)}: missing map geometry part`);
172
+ }
173
+ }
@@ -0,0 +1,57 @@
1
+ import { BufferGeometry, Group, InstancedMesh, MeshBasicMaterial } from 'three';
2
+ import { createClientChannelView, moverChannelValues } from '@wildshard/engine/game/plugin/clientChannelView';
3
+ import { parseClientChannels } from '@wildshard/format/clientChannels';
4
+ import type { MoverPose } from '@wildshard/engine/physics/mover';
5
+
6
+ /** Only the initial private transforms and instance slots used by the map projection. */
7
+ export interface MapRestNode {
8
+ readonly id: string;
9
+ readonly position?: readonly [number, number, number];
10
+ readonly rotation?: readonly [number, number, number];
11
+ readonly quaternion?: readonly [number, number, number, number];
12
+ readonly scale?: readonly [number, number, number];
13
+ readonly order?: 'XYZ' | 'YXZ' | 'ZXY' | 'ZYX' | 'YZX' | 'XZY';
14
+ readonly visible?: boolean;
15
+ readonly instances?: number;
16
+ readonly matrices?: readonly number[];
17
+ }
18
+ /** Initial presentation rows; all numbers retain the native CPU channel projection. */
19
+ export interface MapRestRows {
20
+ readonly version: 1;
21
+ readonly nodes: Readonly<Record<string, { position: number[]; quaternion: number[]; scale: number[]; visible: boolean; matrices?: number[] }>>;
22
+ }
23
+
24
+ /** Project declared mover rest poses without a renderer, physics installation or filesystem authority.
25
+ * Every instance slot must be initialized; missing movers and incomplete coverage refuse. */
26
+ export function mapSceneRest(scene: { readonly nodes: readonly MapRestNode[] }, input: unknown, poses: readonly (MoverPose & { readonly id: string })[]): MapRestRows {
27
+ const programs = parseClientChannels(input), targets = new Map<string, Group | InstancedMesh>(), coverage = new Map<string, Uint8Array>();
28
+ const nodes: Record<string, MapRestRows['nodes'][string]> = {}, movers = new Map(poses.map(pose => [pose.id, pose]));
29
+ const geometry = new BufferGeometry(), material = new MeshBasicMaterial();
30
+ try {
31
+ for (const row of scene.nodes) {
32
+ const target = row.instances === undefined ? new Group() : new InstancedMesh(geometry, material, row.instances);
33
+ if (row.position !== undefined) target.position.fromArray(row.position);
34
+ if (row.rotation !== undefined) target.rotation.set(...row.rotation, row.order ?? 'XYZ');
35
+ if (row.quaternion !== undefined) target.quaternion.fromArray(row.quaternion);
36
+ if (row.scale !== undefined) target.scale.fromArray(row.scale);
37
+ if (row.visible !== undefined) target.visible = row.visible;
38
+ if (row.matrices !== undefined && target instanceof InstancedMesh) target.instanceMatrix.array.set(row.matrices);
39
+ if (row.instances !== undefined) coverage.set(row.id, new Uint8Array(row.instances).fill(row.matrices === undefined ? 0 : 1));
40
+ targets.set(row.id, target);
41
+ }
42
+ for (const program of programs) {
43
+ if (program.mover === undefined) throw new Error(`Map rest needs a declared mover: ${program.id}`);
44
+ const pose = movers.get(program.mover); if (pose === undefined) throw new Error(`Missing map rest pose ${program.mover}`);
45
+ const view = createClientChannelView(program, targets);
46
+ view.evaluate({ time: 0, delta: 0, values: moverChannelValues(view.reads, pose, {}) });
47
+ for (const connector of program.connectors ?? []) {
48
+ const slots = coverage.get(connector.target), span = connector.instances;
49
+ if (slots !== undefined && span !== undefined) slots.fill(1, span.start, span.start + span.capacity);
50
+ }
51
+ }
52
+ for (const [id, slots] of coverage) if (slots.some(value => value === 0)) throw new Error(`Incomplete map rest instance slots ${id}`);
53
+ for (const [id, target] of targets) nodes[id] = { position: target.position.toArray(), quaternion: target.quaternion.toArray(), scale: target.scale.toArray(), visible: target.visible,
54
+ ...(target instanceof InstancedMesh ? { matrices: Array.from(target.instanceMatrix.array) } : {}) };
55
+ return { version: 1, nodes };
56
+ } finally { geometry.dispose(); material.dispose(); }
57
+ }
@@ -0,0 +1,234 @@
1
+ // oxlint-disable-next-line import/no-nodejs-modules -- Offline maps decode the existing deflated geometry packs.
2
+ import { inflateSync } from 'node:zlib';
3
+ import { Box3, Euler, Matrix4, Quaternion, Vector3 } from 'three';
4
+ import * as v from 'valibot';
5
+ import { GeometryPack, packedRows } from '@wildshard/sdk/kit/geometryPack';
6
+ import type { MapRaster } from './mapRaster';
7
+ import type { Node } from '@gltf-transform/core';
8
+ import { decodeTerrainTile } from '@wildshard/format/terrainTileBytes';
9
+
10
+ const vector = v.tuple([v.number(), v.number(), v.number()]);
11
+ const referenceSchema = v.object({ file: v.string(), path: v.exactOptional(v.array(v.string())) });
12
+ const fitSchema = v.object({ size: v.number(), yaw: v.exactOptional(v.number()), floor: v.exactOptional(v.number()), by: v.exactOptional(v.string()) });
13
+ const nodeSchema = v.object({ id: v.string(), kind: v.string(), name: v.exactOptional(v.string()),
14
+ children: v.exactOptional(v.array(v.string())), position: v.exactOptional(vector), rotation: v.exactOptional(vector), scale: v.exactOptional(vector),
15
+ quaternion: v.exactOptional(v.tuple([v.number(), v.number(), v.number(), v.number()])), matrix: v.exactOptional(v.array(v.number())),
16
+ order: v.exactOptional(v.picklist(['XYZ', 'YXZ', 'ZXY', 'ZYX', 'YZX', 'XZY'])), visible: v.exactOptional(v.boolean()),
17
+ geometry: v.exactOptional(v.string()), source: v.exactOptional(v.string()), material: v.exactOptional(v.string()),
18
+ instances: v.exactOptional(v.number()), matrices: v.exactOptional(v.array(v.number())) });
19
+ const materialSchema = v.object({ kind: v.string(), id: v.string(), source: v.exactOptional(v.string()),
20
+ properties: v.exactOptional(v.object({ transparent: v.exactOptional(v.boolean()), depthWrite: v.exactOptional(v.boolean()) })) });
21
+ const sceneSchema = v.object({ root: v.string(), nodes: v.array(nodeSchema), materials: v.optional(v.array(materialSchema), []) });
22
+ const imports = v.array(v.object({ id: v.string(), kind: v.string(), model: v.exactOptional(v.string()), fit: v.exactOptional(fitSchema),
23
+ piece: v.exactOptional(v.string()), only: v.exactOptional(v.record(v.string(), v.unknown())) }));
24
+ const configuration = v.object({ materials: v.exactOptional(v.array(referenceSchema)), models: v.exactOptional(v.array(referenceSchema)),
25
+ pools: v.exactOptional(v.array(v.union([v.string(), v.object({ file: v.string(), names: v.exactOptional(v.union([v.array(v.string()), referenceSchema])) })]))),
26
+ aliases: v.exactOptional(v.record(v.string(), v.string())),
27
+ packs: v.exactOptional(v.array(v.object({ file: v.string(), rows: referenceSchema, names: v.exactOptional(v.array(v.string())), deflated: v.exactOptional(v.boolean()) }))),
28
+ bakes: v.exactOptional(v.array(v.object({ rows: referenceSchema, directory: v.string(), piece: v.exactOptional(v.unknown()) }))),
29
+ recipes: v.array(v.object({ file: v.string(), path: v.exactOptional(v.array(v.string())), lights: v.exactOptional(v.array(v.string())), rest: v.exactOptional(v.string()) })) });
30
+ const visibility = v.object({ keep: v.exactOptional(v.array(v.string())), hide: v.exactOptional(v.array(v.string())),
31
+ heightHide: v.exactOptional(v.array(v.string())), hideStanding: v.exactOptional(v.array(v.string())) });
32
+ const surfaceSchema = v.object({ graph: v.exactOptional(v.object({ effectState: v.exactOptional(v.object({ blend: v.exactOptional(v.string()), depthWrite: v.exactOptional(v.boolean()) })) })) });
33
+ const packRows = v.object({ bytes: v.number(), geometries: v.array(v.object({ attrs: v.array(v.tuple([v.string(), v.number()])),
34
+ count: v.number(), unique: v.number(), own: v.nullable(v.string()), indexCount: v.number(),
35
+ groups: v.exactOptional(v.array(v.object({ start: v.number(), count: v.number(), materialIndex: v.number() }))) })) });
36
+ const pieceRows = v.object({ kinds: v.array(v.record(v.string(), v.unknown())) });
37
+ type Pose = v.InferOutput<typeof nodeSchema>;
38
+ type Fit = v.InferOutput<typeof fitSchema>;
39
+ interface Shape { bounds: Box3; draw: (matrix: Matrix4) => void | Promise<void> }
40
+ interface Draw { matrix: Matrix4; draw: Shape['draw']; bounds?: Box3; live?: boolean; standing?: boolean; instanced?: boolean }
41
+ interface Model { matrix: Matrix4; model: Fit; file: string }
42
+ /** Input authority stays with the caller; a file identity is usable only by an explicitly configured raster reader. */
43
+ export interface MapSceneReader {
44
+ input: (file: string) => string | Uint8Array;
45
+ /** Optional URL mapping belongs to the caller; otherwise models use their declared logical identity. */
46
+ model?: (url: string) => string | Uint8Array;
47
+ json: (file: string) => unknown;
48
+ bytes: (file: string) => Uint8Array;
49
+ }
50
+ function record(value: unknown): Record<string, unknown> { return v.parse(v.record(v.string(), v.unknown()), value); }
51
+ function required<T>(value: T | undefined, label: string): T { if (value === undefined) throw new Error(label); return value; }
52
+ const matches = (patterns: readonly string[], name: string): boolean => patterns.some(pattern => pattern.endsWith('*') ? name.startsWith(pattern.slice(0, -1)) : name === pattern);
53
+ const matrixOf = (row: Pose): Matrix4 => row.matrix === undefined ? new Matrix4().compose(new Vector3(...row.position ?? [0, 0, 0]),
54
+ row.quaternion === undefined ? new Quaternion().setFromEuler(new Euler(...row.rotation ?? [0, 0, 0], row.order ?? 'XYZ')) : new Quaternion(...row.quaternion),
55
+ new Vector3(...row.scale ?? [1, 1, 1])) : new Matrix4().fromArray(row.matrix);
56
+
57
+ /** A path is a declared JSON address; * expands an existing array in its order. */
58
+ export function mapRows(value: unknown, path: readonly string[] = []): unknown[] {
59
+ if (path.length === 0) return [value];
60
+ const [key, ...tail] = path;
61
+ if (key === '*') {
62
+ if (!Array.isArray(value)) throw new Error('Map scene wildcard requires an array');
63
+ const rows: unknown[] = value;
64
+ return rows.flatMap(row => mapRows(row, tail));
65
+ }
66
+ if (key === undefined || value === null || typeof value !== 'object' || !Object.hasOwn(value, key)) throw new Error(`Missing map scene data ${path.join('/')}`);
67
+ return mapRows(Reflect.get(value, key), tail);
68
+ }
69
+
70
+ /** Sources index real local geometry; recipes retain their exact placement
71
+ * doubles. Unknown geometry and imports refuse instead of silently losing it. */
72
+ export async function paintMapScenes(raster: MapRaster, input: unknown, style: unknown, data: MapSceneReader): Promise<void> {
73
+ const config = v.parse(configuration, input), settings = v.parse(visibility, style);
74
+ const shapes = new Map<string, Shape>(), bakes = new Map<string, { file: string; kinds: Record<string, unknown>[] }>(),
75
+ models = new Map<string, string>(), materials = new Map<string, unknown>(), records: (Draw | Model)[] = [];
76
+ for (const ref of config.materials ?? []) for (const [id, row] of Object.entries(record(mapRows(data.json(ref.file), ref.path)[0]))) materials.set(id, row);
77
+ for (const row of config.models ?? []) {
78
+ const source = v.parse(v.record(v.string(), v.string()), mapRows(data.json(row.file), row.path)[0]);
79
+ for (const [id, url] of Object.entries(source)) models.set(id, url);
80
+ }
81
+ for (const pool of config.pools ?? []) {
82
+ const file = typeof pool === 'string' ? pool : pool.file;
83
+ const names = typeof pool === 'string' || pool.names === undefined ? undefined : Array.isArray(pool.names) ? pool.names : v.parse(v.array(v.string()), mapRows(data.json(pool.names.file), pool.names.path));
84
+ const path = data.input(file), doc = await raster.document(path);
85
+ let index = 0;
86
+ for (const node of doc.getRoot().listNodes()) {
87
+ const mesh = node.getMesh(); if (mesh === null) continue;
88
+ const id = names?.[index++] ?? (node.getName() === '' ? mesh.getName() : node.getName());
89
+ if (id === '') throw new Error(`${file}: unnamed map pool geometry`);
90
+ if (shapes.has(id)) throw new Error(`Ambiguous map geometry ${id}`);
91
+ const bounds = new Box3();
92
+ for (const primitive of mesh.listPrimitives()) {
93
+ const position = primitive.getAttribute('POSITION'); if (position === null) throw new Error('Map pool needs positions');
94
+ bounds.union(new Box3(new Vector3(...position.getMin([])), new Vector3(...position.getMax([]))));
95
+ }
96
+ shapes.set(id, { bounds, draw: matrix => raster.glb(path, matrix, candidate => candidate === node, { local: true }) });
97
+ }
98
+ }
99
+ for (const [id, source] of Object.entries(config.aliases ?? {})) {
100
+ const shape = shapes.get(source); if (shape === undefined || shapes.has(id)) throw new Error(`Invalid map geometry alias ${id}`);
101
+ shapes.set(id, shape);
102
+ }
103
+ for (const row of config.packs ?? []) {
104
+ const source = mapRows(data.json(row.rows.file), row.rows.path)[0], names = mapRows(source, row.names)[0];
105
+ const metadata = v.parse(packRows, source);
106
+ if (!Array.isArray(names) || names.length !== metadata.geometries.length) throw new Error('Map geometry pack names differ');
107
+ const bytes = data.bytes(row.file);
108
+ const pack = new GeometryPack(row.deflated === true ? inflateSync(bytes) : bytes, packedRows(metadata), 'map');
109
+ for (const [index, id] of v.parse(v.array(v.unknown()), names).entries()) {
110
+ if (typeof id !== 'string' || shapes.has(id)) throw new Error('Map pack needs unique names');
111
+ const geometry = pack.geometry(index); geometry.computeBoundingBox();
112
+ if (geometry.boundingBox === null) throw new Error('Map pack needs bounds');
113
+ shapes.set(id, { bounds: geometry.boundingBox, draw: matrix => raster.geometry(geometry, matrix) });
114
+ }
115
+ }
116
+ for (const row of config.bakes ?? []) {
117
+ const selected = mapRows(data.json(row.rows.file), row.rows.path)[0];
118
+ if (row.piece !== undefined && (typeof row.piece !== 'string' || !/^[a-z][a-z0-9.-]{0,127}$/u.test(row.piece))) throw new Error('Map bake needs a bounded piece identity');
119
+ const source = row.piece === undefined ? selected : { [row.piece]: selected };
120
+ for (const [id, piece] of Object.entries(record(source))) bakes.set(id, { file: `${row.directory}/${id}.glb`, kinds: v.parse(pieceRows, piece).kinds });
121
+ }
122
+ for (const ref of config.recipes) for (const recipe of mapRows(data.json(ref.file), ref.path)) {
123
+ const recipeRecord = record(recipe), recipeScene = v.parse(sceneSchema, recipeRecord['scene'] ?? recipe),
124
+ importedRows = v.parse(imports, recipeRecord['imports'] ?? []), importedById = new Map(importedRows.map(row => [row.id, row]));
125
+ const lights = new Set(ref.lights === undefined ? [] : v.parse(v.array(v.object({ id: v.string() })), mapRows(data.json(ref.file), ref.lights).flat()).map(row => row.id));
126
+ const ghostMaterials = new Set(recipeScene.materials.flatMap(row => {
127
+ const surface = row.kind === 'port' ? materials.get(required(row.source, 'Map material needs a source').split(':')[0] ?? '') : undefined;
128
+ const effect = surface === undefined ? undefined : v.parse(surfaceSchema, surface).graph?.effectState;
129
+ return row.properties?.transparent === true && row.properties.depthWrite === false || effect?.blend === 'alpha' && effect.depthWrite === false ? [row.id] : [];
130
+ }));
131
+ const rest = ref.rest === undefined ? {} : record(record(data.json(ref.rest))['nodes']);
132
+ const nodes = new Map(recipeScene.nodes.map(row => [row.id, v.parse(nodeSchema, { ...row, ...record(rest[row.id] ?? {}) })])), visiting = new Set<string>();
133
+ const walk = (id: string, parent: Matrix4, names: readonly string[], visible: boolean, inheritedStanding = false): void => {
134
+ const node = nodes.get(id);
135
+ if (node === undefined || visiting.has(id)) throw new Error(`Invalid map scene hierarchy ${id}`);
136
+ visiting.add(id);
137
+ const chain = [...names, node.name ?? node.id], kept = chain.some(name => matches(settings.keep ?? [], name));
138
+ const hidden = !kept && matches([...(settings.hide ?? []), ...(settings.heightHide ?? [])], node.name ?? node.id);
139
+ const standing = inheritedStanding || hidden && matches(settings.hideStanding ?? [], node.name ?? node.id);
140
+ const matrix = new Matrix4().multiplyMatrices(parent, matrixOf(node));
141
+ const live = visible && node.visible !== false && !hidden;
142
+ if (node.kind === 'mesh' && node.material !== undefined && ghostMaterials.has(node.material)) {
143
+ // The browser height pass omits transparent, depth-off effects too.
144
+ } else if (node.kind === 'mesh' || node.kind === 'object') {
145
+ const source = (node.kind === 'mesh' ? node.geometry : node.source) ?? '', imported = importedById.get(source);
146
+ const shape = shapes.get(source);
147
+ if (node.kind === 'object' && imported !== undefined) {
148
+ if (imported.kind === 'model') {
149
+ const file = models.get(imported.model ?? ''); if (file === undefined) throw new Error(`Missing declared map model ${String(imported.model)}`);
150
+ if (live) records.push({ matrix, model: required(imported.fit, 'Map model needs a fit'), file });
151
+ for (const child of node.children ?? []) walk(child, matrix, chain, live, standing);
152
+ visiting.delete(id); return;
153
+ }
154
+ const baked = bakes.get(imported.piece ?? ''); if (baked === undefined) throw new Error(`Missing map bake ${String(imported.piece)}`);
155
+ if (live) records.push({ matrix, draw: (pose: Matrix4) => raster.glb(data.input(baked.file), pose,
156
+ (_node, index) => imported.only === undefined || Object.entries(imported.only).every(([key, value]) => baked.kinds[index]?.[key] === value)) });
157
+ } else if (shape === undefined && node.kind === 'object' && lights.has(source)) {
158
+ // A declared point light has no map footprint.
159
+ } else {
160
+ if (shape === undefined) throw new Error(`Missing declared map geometry ${source}`);
161
+ const count = node.instances ?? 1;
162
+ if (count > 1 && node.matrices === undefined) throw new Error(`Missing rest instance matrices ${node.id}`);
163
+ if (node.matrices !== undefined && node.matrices.length !== count * 16) throw new Error('Map instance matrices differ');
164
+ for (let i = 0; i < count; i++) {
165
+ const pose = node.matrices === undefined ? matrix : new Matrix4().multiplyMatrices(matrix, new Matrix4().fromArray(node.matrices, i * 16));
166
+ records.push({ matrix: pose, draw: shape.draw, bounds: shape.bounds, live, standing, instanced: node.instances !== undefined });
167
+ }
168
+ }
169
+ } else if (!['group', 'anchor', 'light'].includes(node.kind)) throw new Error(`Unsupported map scene node ${node.kind}`);
170
+ for (const child of node.children ?? []) walk(child, matrix, chain, live, standing);
171
+ visiting.delete(id);
172
+ };
173
+ walk(recipeScene.root, new Matrix4(), [], true);
174
+ }
175
+ // Preserve bake-maps' hideStanding rule: the same instanced vegetation rooted
176
+ // on a decorative island is omitted with that island, using its actual box.
177
+ const standing = records.filter((row): row is Draw => 'standing' in row && row.standing).map(row => {
178
+ const box = required(row.bounds, 'Standing map geometry needs bounds').clone().applyMatrix4(row.matrix), size = box.getSize(new Vector3());
179
+ return { position: new Vector3().setFromMatrixPosition(row.matrix), radius: 0.4 * Math.min(size.x, size.z) };
180
+ });
181
+ for (const row of records) {
182
+ if ('live' in row && !row.live) continue;
183
+ if ('instanced' in row && row.instanced) {
184
+ const p = new Vector3().setFromMatrixPosition(row.matrix);
185
+ if (standing.some(island => Math.hypot(p.x - island.position.x, p.z - island.position.z) <= island.radius && p.y >= island.position.y - 4 && p.y <= island.position.y + 6)) continue;
186
+ }
187
+ if ('model' in row) {
188
+ const file = (data.model ?? data.input)(row.file), doc = await raster.document(file), fit = row.model;
189
+ const turn = new Matrix4().makeRotationY(fit.yaw ?? 0), bounds = new Box3();
190
+ for (const node of doc.getRoot().listNodes()) for (const primitive of node.getMesh()?.listPrimitives() ?? []) {
191
+ const position = primitive.getAttribute('POSITION'); if (position === null) throw new Error('Map model needs positions');
192
+ const box = new Box3(new Vector3(...position.getMin([])), new Vector3(...position.getMax([])));
193
+ bounds.union(box.applyMatrix4(new Matrix4().multiplyMatrices(turn, new Matrix4().fromArray(node.getWorldMatrix()))));
194
+ }
195
+ const extent = bounds.getSize(new Vector3()), scale = fit.size / Math.max(1e-6, fit.by === 'height' ? extent.y : Math.max(extent.x, extent.z));
196
+ const matrix = row.matrix.clone().multiply(new Matrix4().makeTranslation(0, fit.floor ?? 0, 0)).multiply(new Matrix4().makeScale(scale, scale, scale))
197
+ .multiply(new Matrix4().makeTranslation(-(bounds.min.x + bounds.max.x) / 2, -bounds.min.y, -(bounds.min.z + bounds.max.z) / 2)).multiply(turn);
198
+ await raster.glb(file, matrix);
199
+ } else await row.draw(row.matrix);
200
+ }
201
+ }
202
+
203
+
204
+ const geometryDeclaration = v.object({ painter: v.object({ version: v.literal(1), terrain: v.exactOptional(v.array(v.string())),
205
+ props: v.exactOptional(v.array(v.string())), glbs: v.exactOptional(v.array(v.string())), scenes: v.exactOptional(v.unknown()) }),
206
+ outputs: v.exactOptional(v.record(v.string(), v.unknown())) });
207
+ const geometryOutput = v.object({ exclude: v.exactOptional(v.union([v.string(), v.array(v.string())])) });
208
+ const terrainRows = v.object({ terrain: v.object({ tiles: v.array(v.object({ lod: v.number(), file: v.string() })) }) });
209
+ const propsRows = v.object({ props: v.object({ wholeLibrary: v.exactOptional(v.unknown()),
210
+ tiles: v.array(v.object({ lod: v.number(), file: v.string(), additionalFiles: v.exactOptional(v.array(v.string())) })),
211
+ panels: v.array(v.object({ file: v.string(), visible: v.exactOptional(v.boolean()) })) }) });
212
+ /** The single declared terrain/props/GLB/private-scene placement loop, shared by source programs and retained file adapters. */
213
+ export async function paintMapGeometry(raster: MapRaster, input: unknown, data: MapSceneReader,
214
+ options: { output?: string; glbs?: readonly string[]; label?: string } = {}): Promise<void> {
215
+ const config = v.parse(geometryDeclaration, input), painter = config.painter, label = options.label ?? 'map';
216
+ for (const file of painter.terrain ?? []) {
217
+ const row = v.parse(terrainRows, data.json(file));
218
+ for (const tile of row.terrain.tiles.filter(entry => entry.lod === 0)) raster.terrain(decodeTerrainTile(data.bytes(`assets/${tile.file}`)));
219
+ }
220
+ for (const file of painter.props ?? []) {
221
+ const source = data.json(file), library = v.parse(v.object({ props: v.object({ wholeLibrary: v.exactOptional(v.unknown()) }) }), source);
222
+ if (library.props.wholeLibrary !== undefined) throw new Error(`${label}: whole-library props need an explicit map assembly`);
223
+ const { props } = v.parse(propsRows, source);
224
+ for (const tile of props.tiles.filter(entry => entry.lod === 0)) for (const ref of [tile.file, ...tile.additionalFiles ?? []]) await raster.glb(data.input(`assets/${ref}`));
225
+ for (const panel of props.panels.filter(entry => entry.visible !== false)) await raster.glb(data.input(`assets/${panel.file}`));
226
+ }
227
+ const selected = options.output === undefined ? undefined : config.outputs?.[options.output];
228
+ const own = selected === undefined ? undefined : v.parse(geometryOutput, selected), excluded = own?.exclude;
229
+ const exclude = typeof excluded === 'string' ? [excluded] : excluded ?? [];
230
+ const drawn = exclude.length === 0 ? undefined : (node: Node) => !exclude.some(prefix => node.getName().startsWith(prefix));
231
+ for (const file of options.glbs ?? painter.glbs ?? []) await raster.glb(data.input(file), undefined, drawn);
232
+ if (painter.scenes !== undefined) await paintMapScenes(raster, painter.scenes, input, data);
233
+ if (raster.triangles === 0) throw new Error(`${label}: data map is empty`);
234
+ }
@@ -0,0 +1,32 @@
1
+ import { validateGraph, type GraphIr, type GraphNode, type GraphRef, type GraphParam, type GraphStages, type GraphArrayParam } from '@wildshard/format/materialGraph';
2
+ import type { ScaledPostRow } from '@wildshard/format/scaledPost';
3
+ import type { PostGraphLookRow } from '@wildshard/format/postGraphLook';
4
+ import { COLOUR_LUT_EDGE } from '@wildshard/format/colourLut';
5
+
6
+ /** Map clamped display-sRGB to cube texel centres, preserving native graph arithmetic order. */
7
+ export function colourLutSampleTransform(): { readonly scale: number; readonly offset: number } {
8
+ return { scale: (COLOUR_LUT_EDGE - 1) / COLOUR_LUT_EDGE, offset: 0.5 / COLOUR_LUT_EDGE };
9
+ }
10
+
11
+ /** Portable authored graph grammar; no shader compiler, renderer or material is installed. */
12
+ export type AuthorGraph = GraphIr;
13
+ /** One ordered author node, retaining loops and exact numeric literals. */
14
+ export type AuthorGraphNode = GraphNode;
15
+ /** A declared node identity or native scalar/vector literal. */
16
+ export type AuthorGraphRef = GraphRef;
17
+ /** Typed authored parameter policy, including lent textures and bindings. */
18
+ export type AuthorGraphParam = GraphParam;
19
+ /** Original material, fog and post stage outputs. */
20
+ export type AuthorGraphStages = GraphStages;
21
+ /** Fixed-capacity authored array policy. */
22
+ export type AuthorGraphArrayParam = GraphArrayParam;
23
+ /** Data-only scaled post pass topology and resource wiring. */
24
+ export type AuthorScaledPost = ScaledPostRow;
25
+ /** Complete authored post look, including ordered pass topology and resource wiring. */
26
+ export type AuthorPostGraphLook = PostGraphLookRow;
27
+
28
+ /** Validate an offline author's complete graph under the existing trusted author budget.
29
+ * Keep diagnostics and graph normalization identical; runtime admission still owns its own caps. */
30
+ export function checkAuthorGraph(input: unknown): ReturnType<typeof validateGraph> {
31
+ return validateGraph(input, { trustedBudget: true });
32
+ }
@@ -0,0 +1,27 @@
1
+ import { GrassField, type GrassFieldPorts } from '@wildshard/engine/game/systems/looks/grassField';
2
+
3
+ /** An owned eight-channel native lattice snapshot and the original query state that produced it. */
4
+ export interface NativeMeadowField {
5
+ readonly resolution: number;
6
+ /** Row-major z rows: height, tone, flower drift, drift species, ground RGB, bloom. */
7
+ readonly values: Float32Array;
8
+ readonly baseHeightAt: (x: number, z: number, trailDistance?: number, exact?: boolean) => number;
9
+ readonly sample: (x: number, z: number, channel: number) => number;
10
+ readonly trailGrass: (height: number, trailDistance: number) => number;
11
+ }
12
+
13
+ /** Bake all original four-metre meadow corners from trusted explicit native samplers.
14
+ * Own the numeric snapshot and query state without selecting a page, installing a field or retaining scene objects.
15
+ * Snapshot edits never change the queries; separate builds share no mutable samples.
16
+ * The author includes every supplied policy/sampler in its native source cache key. */
17
+ export function bakeMeadowField(source: GrassFieldPorts): NativeMeadowField {
18
+ if (!Number.isSafeInteger(source.seed) || !Number.isFinite(source.half) || source.half <= 0 || source.half > 250)
19
+ throw new Error('Native meadow requires a finite seed and at most one 500 m chunk');
20
+ const resolution = Math.ceil(source.half * 2 / 4) + 1;
21
+ const field = new GrassField(source), values = new Float32Array(resolution * resolution * 8);
22
+ for (let z = 0; z < resolution; z++) for (let x = 0; x < resolution; x++) for (let ch = 0; ch < 8; ch++) {
23
+ values[(z * resolution + x) * 8 + ch] = field.sample(x * 4 - source.half, z * 4 - source.half, ch);
24
+ }
25
+ return { resolution, values, baseHeightAt: (x, z, td, exact) => field.baseHeightAt(x, z, td, exact),
26
+ sample: (x, z, channel) => field.sample(x, z, channel), trailGrass: (height, td) => field.trailGrass(height, td) };
27
+ }