@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,22 @@
1
+ import * as v from 'valibot';
2
+ import { NavmeshGroundSchema } from '@wildshard/format/navigation';
3
+ import { isJsonData } from '@wildshard/format/json';
4
+ import { readScalarLattice,type ScalarLatticeBindings } from '@wildshard/engine/world/scalarChannel';
5
+ import type { TerrainField } from '@wildshard/engine/level/data';
6
+
7
+ type Exclusion = (x: number,z: number,y: number) => boolean;
8
+ const legacy = v.strictObject({ excludeGroundAt: v.custom<Exclusion>(value => typeof value === 'function') });
9
+ const declared = v.strictObject({ ground: NavmeshGroundSchema });
10
+
11
+ /** Bake-only admission, before world construction. Retain the original live
12
+ * terrain receiver and water -> wet -> trail short circuit; decode once. */
13
+ export function navmeshGroundExclusion(input: unknown,terrain: Pick<TerrainField,'waterLevel' | 'trailDistance'> | undefined,scalars?:ScalarLatticeBindings): Exclusion | undefined {
14
+ if (input === undefined) return undefined;
15
+ if (input === null || typeof input !== 'object' || Object.getOwnPropertySymbols(input).length > 0
16
+ || !Object.values(Object.getOwnPropertyDescriptors(input)).every(row => row.enumerable && 'value' in row)) throw new Error('Invalid navmesh bake policy');
17
+ if (!isJsonData(input)) return v.parse(legacy,input).excludeGroundAt;
18
+ const { ground: row } = v.parse(declared,input);
19
+ if (terrain === undefined) throw new Error('Navmesh ground exclusion requires its bound terrain');
20
+ const wet = scalars===undefined?readScalarLattice(row.wet):scalars.lattice(row.wet);
21
+ return (x,z,y) => y <= terrain.waterLevel()+row.waterMargin || (wet(x,z) > row.wetThreshold && terrain.trailDistance(x,z) > row.trailClearance);
22
+ }
@@ -0,0 +1,331 @@
1
+ #!/usr/bin/env node
2
+ import { shardManifestPath } from '@wildshard/engine/scripts/authored-manifest.mjs';
3
+ import { decisionLegacyLines } from '@wildshard/engine/scripts/decision-legacy-lines.mjs';
4
+ // G342: bake one shard's near placeholder (public/assets/baked/<slug>/near.glb + near.json). Its drawn static world is
5
+ // built in Node from the shard's own authored world through the bake world host, as the physics bakes build it (no
6
+ // browser, no game page), harvested as prototypes with their placed copies, reduced by the SDK producer
7
+ // (`@wildshard/sdk/bake/nearPlaceholder`) to a low-LOD budget, and merged over its terrain at L1 density (17 × 17 per
8
+ // 125 m region) in its own far look: one draw, regions in TEXCOORD_0.x, no colliders.
9
+ // node --experimental-transform-types --import ./scripts/bake-loader.mjs scripts/bake/near-placeholder.mjs <slug> [--report]
10
+ //
11
+ // G348: why this runner stays beside `wildshard build` (which bakes any shardfile's near row from its own terrain
12
+ // collider and its L1 tiles' meshes, `projectPlaceholders`): the first-party hybrids (Driftwood, Nalati, Pine) have no
13
+ // world in their shardfiles yet (no terrain, no tiles; `public/shardfiles/<slug>/shard.json`). Their props and forests
14
+ // exist only when their TypeScript builders run, so the SDK build has nothing to harvest, and no shardfile input can
15
+ // reproduce these bytes (the coarsest built LOD of every placement, Pine's per-tree placements, the colour maps' mean
16
+ // texels). Nothing here is per shard (each declares its ground and tree stand-ins in data/placeholder.json); the grid
17
+ // prefers a shardfile's own `near` row and reads this runner's near.json only for a shard whose shardfile has none. It
18
+ // retires per shard as each one's world moves into its shardfile tiles.
19
+ import { spawnSync } from 'node:child_process';
20
+ import { createHash } from 'node:crypto';
21
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
22
+ import { resolve } from 'node:path';
23
+ import { pathToFileURL } from 'node:url';
24
+ import { installBakeEnvironment } from './environment.mjs';
25
+ import { visitAuthoredWorld } from './worldHost.mjs';
26
+ import { prepareNativeScalarBlocks } from './nativeWorld.mjs';
27
+ import { placeholderGridBytes, placeholderOf } from './placeholderShards.mjs';
28
+
29
+ const slug = process.argv.slice(2).find(value => !value.startsWith('--'));
30
+ if (typeof slug !== 'string') throw new Error('usage: near-placeholder.mjs <slug> [--report] [--ground-error=<m>] [--resident=<bytes>]');
31
+ const report = process.argv.includes('--report');
32
+ const root = resolve(import.meta.dirname, '../..');
33
+ const at = path => import(pathToFileURL(resolve(root, path)).href);
34
+ // a shardfile project (its shard.config.ts): what `wildshard build` reads, for its tiles, its look and its terrain; read
35
+ // before the bake environment's browser stand-ins exist (its behaviour compiler takes them for a browser)
36
+ // (its generation input roots as the author CLI declares them, scripts/wildshard.mjs: a generator listing its own files needs them)
37
+ const folder = resolve(root, 'src/shards', slug), manifestSource = { folder: slug, ...(existsSync(resolve(folder, 'manifest.json')) ? { file: resolve(folder, 'manifest.json') } : {}),
38
+ imageRoots: [{ prefix: `/src/shards/${slug}/`, directory: folder }, { prefix: '/assets/', directory: resolve(root, 'public/assets') }] };
39
+ const legacy = decisionLegacyLines(root, slug);
40
+ const project = existsSync(resolve(folder, 'shard.config.ts')) ? await (await at('src/sharddev/project.ts')).readProjectAssets(folder, undefined, manifestSource, legacy === undefined ? {} : { decisionLegacyLines: legacy }) : null;
41
+ const environment = installBakeEnvironment(root);
42
+ // G342: a colour map's mean colour, decoded from its encoded bytes (PNG / JPEG / WebP) by Pillow, so a textured prop keeps
43
+ // its own paint (Pine's cabins, Driftwood's huts) instead of a guessed wood tint; the bitmap is that one mean texel
44
+ const means = new Map();
45
+ const meanTexel = (bytes) => {
46
+ const key = createHash('sha256').update(bytes).digest('hex');
47
+ let rgb = means.get(key);
48
+ if (rgb === undefined) {
49
+ const out = spawnSync('python3', ['-I', '-c', 'import sys, io\nfrom PIL import Image\nim = Image.open(io.BytesIO(sys.stdin.buffer.read())).convert("RGBA").resize((1, 1), Image.Resampling.BOX)\nprint(*im.getpixel((0, 0)))'], { input: bytes });
50
+ rgb = out.status === 0 ? String(out.stdout).trim().split(/\s+/u).map(Number) : null;
51
+ if (rgb !== null && (rgb.length !== 4 || rgb.some(v => !Number.isFinite(v)))) rgb = null;
52
+ means.set(key, rgb);
53
+ }
54
+ return rgb;
55
+ };
56
+ Object.defineProperty(globalThis, 'createImageBitmap', { configurable: true, value: async (source) => {
57
+ const bytes = source instanceof Blob ? Buffer.from(await source.arrayBuffer()) : null, rgb = bytes === null ? null : meanTexel(bytes);
58
+ return rgb === null ? { width: 1, height: 1, close: () => undefined } : { width: 1, height: 1, data: Uint8ClampedArray.from(rgb), close: () => undefined };
59
+ } });
60
+ const element = () => Object.assign(environment.element(), { prepend: () => undefined, replaceChildren: () => undefined, contains: () => false, blur: () => undefined });
61
+ Object.defineProperty(document, 'createElement', { value: element, configurable: true });
62
+ Object.defineProperty(document, 'createElementNS', { value: (_ns, tag) => element(tag), configurable: true });
63
+ const noop = () => undefined;
64
+ const THREE = await import('three');
65
+ const sky = new Proxy({ setupMaterial: noop, csm: { lights: [new THREE.DirectionalLight()], update: noop },
66
+ hemi: new THREE.HemisphereLight(), sunDisc: new THREE.Mesh(new THREE.SphereGeometry(), new THREE.MeshBasicMaterial()),
67
+ planet: new THREE.Group(), clouds: null, dayNight: { dusk: 0, night: 0 }, viewCamera: new THREE.PerspectiveCamera(), sunDir: new THREE.Vector3(0, 1, 0) },
68
+ { get: (target, key) => key in target ? target[key] : typeof key === 'string' && key.endsWith('Color')
69
+ ? new THREE.Color(1, 1, 1) : typeof key === 'string' && key.endsWith('Dir') ? new THREE.Vector3(0, 1, 0) : undefined });
70
+ (await at('src/client/engine/core/tier.ts')).initializeTier('phone');
71
+ const { default: manifest } = await at(shardManifestPath(root, slug));
72
+ prepareNativeScalarBlocks(manifest, root);
73
+ (await at('src/client/game/shard/list.ts')).installShards([manifest]);
74
+ (await at('src/client/game/shard/registry.ts')).setActiveChunk(manifest.slug);
75
+ const { Terrain, terrainChunkGeometry } = await at('src/client/engine/world/Terrain.ts');
76
+ const terrainBin = resolve(root, 'public/assets/baked', slug, 'terrain.bin');
77
+ // G348: the shard's own data says where its ground comes from (its data/placeholder.json row); no slug branch here
78
+ const source = await placeholderOf(root, slug);
79
+ const groundFrom = source.ground;
80
+ // a shardfile-terrain shard (no terrain.bin, no ground row) builds its world on its own collider grid
81
+ const nativeTerrain = groundFrom === undefined ? existsSync(terrainBin) ? readFileSync(terrainBin) : undefined : (await at(`src/shards/${slug}/${groundFrom.generator}`))[groundFrom.export]();
82
+ if (nativeTerrain !== undefined && !(nativeTerrain instanceof Uint8Array)) throw new Error(`${slug}: placeholder ground ${JSON.stringify(groundFrom)} returned no bytes`);
83
+
84
+ // a manifest ground declared by key (`createBakedTerrainField`, Signal's) is its shardfile's own terrain collider: the bake
85
+ // installs it into the declared field as the session's required-ground loader would (`installProductGround`)
86
+ if (nativeTerrain === undefined && manifest.ground?.terrain !== undefined) {
87
+ const { bakedTerrainSource, installDeclaredBakedTerrain } = await at('src/shared/engine/world/bakedTerrainField.ts');
88
+ const declared = bakedTerrainSource(manifest.ground.terrain), collider = declared === null ? null : placeholderGridBytes(root, resolve(root, 'src/shards', slug), slug);
89
+ if (collider?.kind === 'collider') {
90
+ const { clientGround } = await at('src/shared/game/shardfile/clientGround.ts');
91
+ const ground = clientGround({ terrain: { collider: 'collider' }, meshCollision: null }, new Map([['collider', collider.bytes]]));
92
+ installDeclaredBakedTerrain(manifest.ground.terrain, { seed: declared.seed, heightAt: ground.heightAt, normalAt: ground.normalAt, splatAt: ground.splatAt });
93
+ }
94
+ }
95
+
96
+ /** Weathered wood (linear RGB): the stand-in for a colour map or a texture-only material Node does not decode. */
97
+ const WOOD = new THREE.Color(0.3, 0.21, 0.13);
98
+ /** A drawn thing's colour: its material colour times the mean of its colour map when the host decoded one. */
99
+ const colourOf = (material) => {
100
+ const m = Array.isArray(material) ? material[0] : material;
101
+ const c = m?.color instanceof THREE.Color ? m.color.clone() : new THREE.Color(0.6, 0.6, 0.6);
102
+ const img = m?.map?.image;
103
+ if (img?.data !== undefined && img.width > 0) {
104
+ let r = 0, g = 0, b = 0, n = 0; const d = img.data, stride = Math.max(4, Math.floor(d.length / 4 / 4096) * 4);
105
+ for (let i = 0; i + 3 < d.length; i += stride) { r += d[i]; g += d[i + 1]; b += d[i + 2]; n++; }
106
+ if (n > 0) c.multiply(new THREE.Color(r / n / 255, g / n / 255, b / n / 255).convertSRGBToLinear());
107
+ } else if (m?.map !== null && m?.map !== undefined) c.multiply(WOOD); // a colour map Node did not decode: the weathered wood most props are
108
+ return c;
109
+ };
110
+
111
+ const parts = [], rows = [];
112
+ let forestTrees = [];
113
+ /** One drawn mesh (model-space geometry, its material and its placed copies' matrices) as a producer prototype. */
114
+ const harvest = (label, geometry, materials, transforms, instanced) => {
115
+ const position = geometry?.getAttribute('position');
116
+ if (position === undefined || position.itemSize !== 3 || transforms.length === 0) return;
117
+ const material = Array.isArray(materials) ? materials[0] : materials;
118
+ if (material === undefined || material.transparent === true && material.opacity < 0.5 || material.visible === false) return;
119
+ const index = geometry.index, tri = index === null ? position.count / 3 : index.count / 3;
120
+ const colour = colourOf(materials), vc = geometry.getAttribute('color');
121
+ const base = new Float32Array(position.count * 3), colours = new Float32Array(position.count * 3);
122
+ for (let i = 0; i < position.count; i++) {
123
+ base.set([position.getX(i), position.getY(i), position.getZ(i)], i * 3);
124
+ const k = vc !== undefined && vc.itemSize >= 3 ? [vc.getX(i), vc.getY(i), vc.getZ(i)] : [1, 1, 1];
125
+ colours.set([colour.r * k[0], colour.g * k[1], colour.b * k[2]], i * 3);
126
+ }
127
+ const idx = index === null ? Uint32Array.from({ length: position.count }, (_, i) => i) : Uint32Array.from(index.array);
128
+ rows.push({ name: label, instanced, count: transforms.length, tri, total: tri * transforms.length, colour: colour.toArray().map(x => Number(x.toFixed(2))), map: material.map !== null && material.map !== undefined });
129
+ parts.push({ name: label, positions: base, colours, index: idx, transforms });
130
+ };
131
+ // Placed models (E315: huts, piers, lookouts …) are harvested where they are built, every copy, whatever their culler
132
+ // shows from one bake camera: each placement call keeps its coarsest non-empty level. Scene meshes drawing those
133
+ // models' materials are then skipped, so no copy is taken twice.
134
+ const modelMaterials = new Set(), modelBuilds = [];
135
+ const poseMatrix = (pl) => {
136
+ if (pl.matrix !== undefined) return pl.matrix.clone();
137
+ const s = pl.scale ?? 1, r = new THREE.Matrix4(), out = new THREE.Matrix4().makeScale(s, s, s);
138
+ if (pl.yaw !== undefined) out.premultiply(r.makeRotationY(pl.yaw));
139
+ if (pl.leanX !== undefined) out.premultiply(r.makeRotationX(pl.leanX));
140
+ if (pl.leanZ !== undefined) out.premultiply(r.makeRotationZ(pl.leanZ));
141
+ return out.premultiply(r.makeTranslation(pl.x, pl.y, pl.z));
142
+ };
143
+ const visitPlacement = (call) => {
144
+ if (call.drawnInto !== undefined || call.moving) return undefined;
145
+ const levels = new Map();
146
+ modelBuilds.push({ model: call.model, levels });
147
+ return (build) => {
148
+ const meshes = [];
149
+ if (Array.isArray(build.built)) for (const part of build.built) meshes.push({ geometry: part.geometry, material: part.material, local: null });
150
+ else if (build.built?.isObject3D === true) { build.built.updateMatrixWorld(true); build.built.traverse(n => { if (n.isMesh && !n.isSkinnedMesh) meshes.push({ geometry: n.geometry, material: n.material, local: n.matrixWorld.clone() }); }); }
151
+ for (const mesh of meshes) for (const mat of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) modelMaterials.add(mat);
152
+ if (meshes.length === 0 || build.kind !== 'model') return;
153
+ // copy now: a builder's geometry may be transformed or merged after this callback
154
+ const copies = meshes.map(mesh => ({ geometry: mesh.geometry.clone(), material: mesh.material, local: mesh.local }));
155
+ const byGroup = levels.get(build.placements) ?? new Map(); byGroup.set(build.level, copies); levels.set(build.placements, byGroup);
156
+ };
157
+ };
158
+ /** Harvest the placed models (their coarsest non-empty level, every copy); returns each copy's world box. */
159
+ const harvestModels = () => {
160
+ const boxes = [], b = new THREE.Box3();
161
+ if (report) console.log(` models: ${JSON.stringify(Object.entries(Object.groupBy(modelBuilds, x => x.model)).map(([k, v]) => `${k}:${v.length}/${v.reduce((n, x) => n + x.levels.size, 0)}`))}`);
162
+ for (const { model, levels } of modelBuilds) for (const [placements, byLevel] of levels) {
163
+ const level = Math.max(...[...byLevel.keys()].filter(l => (byLevel.get(l) ?? []).length > 0));
164
+ const poses = placements.map(poseMatrix);
165
+ for (const mesh of byLevel.get(level) ?? []) {
166
+ const transforms = poses.map(pose => mesh.local === null ? pose.clone() : pose.clone().multiply(mesh.local));
167
+ mesh.geometry.computeBoundingBox();
168
+ for (const t of transforms) if (mesh.geometry.boundingBox !== null) boxes.push(b.copy(mesh.geometry.boundingBox).applyMatrix4(t).expandByScalar(0.5).clone());
169
+ harvest(model, mesh.geometry, mesh.material, transforms.map(t => Array.from(t.elements)), false);
170
+ }
171
+ }
172
+ return boxes;
173
+ };
174
+ // a pure shardfile project has no authored plugin to build: its near placeholder is its terrain alone; a shard whose world
175
+ // is its shardfile tiles (`near.world: 'tiles'`, a world built from its product) has no authored host to visit either
176
+ if (typeof manifest.load === 'function' && source.near?.world !== 'tiles') await visitAuthoredWorld(manifest, { root, sky, element: environment.element, tier: 'phone', nativeTerrain, collectLate: true, visitPlacement,
177
+ createTerrain: async () => {
178
+ const field = await at('src/shared/engine/world/Heightfield.ts');
179
+ const terrain = new Terrain(); terrain.mesh = new THREE.Mesh(terrainChunkGeometry(field), new THREE.MeshBasicMaterial()); terrain.mesh.name = 'near-harvest-terrain';
180
+ return terrain;
181
+ },
182
+ visit: ({ scene, camera, late, forest }) => {
183
+ // a forest its shard's own tree model draws (Pine's, E315) has no meshes in Node: its placements are the trees
184
+ if (forest.drawer !== 'self') forestTrees = forest.trees.map(t => ({ x: t.x, y: t.y, z: t.z, rot: t.rot, height: t.height, scale: t.scale,
185
+ species: t.species ?? forest.factory.variants[t.variant]?.species ?? 'tree', tint: t.tint.getHSL({ h: 0, s: 0, l: 0 }).l }));
186
+ // pose the view over the whole cell from a neighbour's distance, so view-dependent repacks keep their far copies
187
+ camera.fov = 100; camera.near = 1; camera.far = 6000; camera.position.set(0, 650, 1); camera.lookAt(0, 0, 0);
188
+ camera.updateProjectionMatrix(); camera.updateMatrixWorld(true); scene.updateMatrixWorld(true);
189
+ for (let pass = 0; pass < 3; pass++) for (const fn of late) fn(1 / 30);
190
+ scene.updateMatrixWorld(true);
191
+ const m = new THREE.Matrix4(), modelBoxes = harvestModels(), centre = new THREE.Vector3(), cb = new THREE.Box3();
192
+ scene.traverse((node) => {
193
+ if (!node.isMesh || node.isSkinnedMesh || node.name === 'near-harvest-terrain' || !node.visible) return;
194
+ let hidden = false; for (let p = node.parent; p !== null; p = p.parent) if (!p.visible) hidden = true;
195
+ if (hidden) return;
196
+ // a copy drawing a placed model's material inside one of its harvested copies is that copy (taken above)
197
+ const shared = (Array.isArray(node.material) ? node.material : [node.material]).some(mat => modelMaterials.has(mat)), transforms = [];
198
+ if (shared) node.geometry.computeBoundingBox();
199
+ for (let k = 0; k < (node.isInstancedMesh ? node.count : 1); k++) {
200
+ if (node.isInstancedMesh) { node.getMatrixAt(k, m); m.premultiply(node.matrixWorld); } else m.copy(node.matrixWorld);
201
+ if (shared && node.geometry.boundingBox !== null && modelBoxes.some(box => box.containsPoint(cb.copy(node.geometry.boundingBox).applyMatrix4(m).getCenter(centre)))) continue;
202
+ transforms.push(Array.from(m.elements));
203
+ }
204
+ let label = node.name; for (let p = node.parent; label.length === 0 && p !== null; p = p.parent) label = p.name; // the nearest named ancestor
205
+ harvest(label, node.geometry, node.material, transforms, node.isInstancedMesh === true);
206
+ });
207
+ },
208
+ });
209
+ rows.sort((a, b) => b.total - a.total);
210
+ if (report) for (const r of rows.slice(0, 40)) console.log(JSON.stringify(r));
211
+ console.log(`${slug}: harvested ${rows.length} meshes, ${rows.reduce((sum, r) => sum + r.total, 0)} triangles`);
212
+
213
+ // the terrain and its water come from the far look's lattice; harvested ground, sea and sky meshes stay out
214
+ const SKIP = /terrain|seabed|ocean|water|\bsea\b|sky|cloud|horizon|backdrop|shadow|decal|fog|haze|sun|moon|star|grass-blades|splat/iu;
215
+ const mean = (c) => { let r = 0, g = 0, b = 0; const n = c.length / 3; for (let i = 0; i < c.length; i += 3) { r += c[i]; g += c[i + 1]; b += c[i + 2]; } return [r / n, g / n, b / n]; };
216
+ const box = (p) => {
217
+ const mm = new THREE.Matrix4().fromArray(p.transforms[0]), v = new THREE.Vector3(), b = new THREE.Box3();
218
+ for (let i = 0; i < p.positions.length; i += 3) b.expandByPoint(v.set(p.positions[i], p.positions[i + 1], p.positions[i + 2]).applyMatrix4(mm));
219
+ return `[${b.min.toArray().map(x => x.toFixed(0))}]..[${b.max.toArray().map(x => x.toFixed(0))}]`;
220
+ };
221
+ const prototypes = parts.filter((p) => {
222
+ const [r, g, b] = mean(p.colours), white = r > 0.97 && g > 0.97 && b > 0.97;
223
+ // a texture-only white mesh (Pine's cabins) is painted wood; a white sheet as wide as the world is a sea or sky plane
224
+ const giant = white && p.positions.length > 0 && (() => { let lo = Infinity, hi = -Infinity; for (let i = 0; i < p.positions.length; i += 3) { lo = Math.min(lo, p.positions[i]); hi = Math.max(hi, p.positions[i]); } return hi - lo > 400; })();
225
+ if (white && !giant) for (let i = 0; i < p.colours.length; i += 3) { p.colours[i] *= WOOD.r; p.colours[i + 1] *= WOOD.g; p.colours[i + 2] *= WOOD.b; }
226
+ const skip = SKIP.test(p.name) ? 'name' : giant ? 'white' : (r > 2 || g > 2 || b > 2) ? 'glow' : null;
227
+ if (report && p.transforms.length > 0) console.log(` ${skip === null ? "take" : "skip"} ${p.name} (${skip}) ${p.index.length / 3} tris x ${p.transforms.length} ${box(p)}`);
228
+ return skip === null; // ground / sea / sky come from the lattice; an unlit white or an emissive glow is not paint
229
+ });
230
+ // the far look, the grid and the bake are the generic ones (`@wildshard/sdk/bake/placeholders`, as `wildshard build`)
231
+ const sdk = await at('src/sharddev/bake/placeholders.ts');
232
+ const exported = async (ref) => { const value = (await at(`src/shards/${slug}/${ref.module}`))[ref.export]; if (value === undefined) throw new Error(`${slug}: ${ref.module} has no export ${ref.export}`); return value; };
233
+ // G380: a shard that declares no far look takes the generic one `wildshard build` gives any shardfile (`shardfileLook`)
234
+ if (source.far === undefined && project === null) throw new Error(`${slug}: no far row in its data/placeholder.json and no shardfile project`);
235
+ const look = source.far === undefined ? sdk.shardfileLook(project.shard) : await exported(source.far.look);
236
+ // a shard whose world lives in its shardfile tiles (Signal's sand and tower, a template's props, the Blender template's
237
+ // authored mesh world) has nothing the authored host builds: its coarse (L1) tiles' meshes are its world, harvested as
238
+ // `wildshard build` harvests them (`shardfileWorld`), in their own catalogue's colours; those tiles keep refining over it, so it never owns its cell (as `wildshard build`'s
239
+ // shardfile near row never does, `loadShardfileNear`)
240
+ const fromTiles = prototypes.length === 0 && project !== null;
241
+ if (fromTiles) {
242
+ // its coarse (L1) tiles, else its L0 tiles when it ships none (Nine Dragon's 64 L0 tiles: the bake reduces them to budget)
243
+ const coarse = await sdk.shardfileWorld(project.shard, project.assets), level = coarse.length > 0 ? 1 : 0;
244
+ prototypes.push(...(level === 1 ? coarse : await sdk.shardfileWorld(project.shard, project.assets, undefined, 0)));
245
+ console.log(`${slug}: ${prototypes.length} shardfile L${level} tile meshes`);
246
+ }
247
+ /**
248
+ * A tiles world raised off its declared floor (`near.base`, Nine Dragon's city at +125 m) stands on a stack: a column
249
+ * under every `cell`-metre square its content covers, from the floor up a metre into that square's lowest content (the
250
+ * footprint's enclosed gaps filled from their neighbours), its sides only where a neighbour stands lower, coloured from
251
+ * `foot` at the floor to `lip` at the stack's top. One prototype a 125 m region, each kept whole (a floor of its own).
252
+ */
253
+ const stackBase = (content, floorY, { cell, lip, foot }) => {
254
+ const n = Math.ceil(500 / cell), low = new Float32Array(n * n).fill(Infinity), cellOf = (v) => Math.min(n - 1, Math.max(0, Math.floor((v + 250) / cell)));
255
+ for (const p of content) for (const m of p.transforms) {
256
+ const world = (k) => [0, 1, 2].map(r => (m[r] ?? 0) * p.positions[k * 3] + (m[4 + r] ?? 0) * p.positions[k * 3 + 1] + (m[8 + r] ?? 0) * p.positions[k * 3 + 2] + (m[12 + r] ?? 0));
257
+ for (let t = 0; t < p.index.length; t += 3) {
258
+ const [a, b, c] = [p.index[t], p.index[t + 1], p.index[t + 2]].map(world), y = Math.min(a[1], b[1], c[1]);
259
+ for (let i = cellOf(Math.min(a[0], b[0], c[0])); i <= cellOf(Math.max(a[0], b[0], c[0])); i++) for (let j = cellOf(Math.min(a[2], b[2], c[2])); j <= cellOf(Math.max(a[2], b[2], c[2])); j++) low[j * n + i] = Math.min(low[j * n + i], y);
260
+ }
261
+ }
262
+ // the gaps the footprint encloses (streets between towers, courts) take their neighbours' lowest content
263
+ const outside = new Uint8Array(n * n), queue = [];
264
+ for (let k = 0; k < n; k++) for (const c of [k, (n - 1) * n + k, k * n, k * n + n - 1]) if (low[c] === Infinity && outside[c] === 0) { outside[c] = 1; queue.push(c); }
265
+ while (queue.length > 0) {
266
+ const c = queue.pop(), i = c % n, j = (c - i) / n;
267
+ for (const [di, dj] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) { const x = i + di, z = j + dj, d = z * n + x; if (x >= 0 && z >= 0 && x < n && z < n && low[d] === Infinity && outside[d] === 0) { outside[d] = 1; queue.push(d); } }
268
+ }
269
+ for (let pass = 0; pass < n; pass++) {
270
+ let open = 0;
271
+ for (let c = 0; c < n * n; c++) if (low[c] === Infinity && outside[c] === 0) {
272
+ const i = c % n, j = (c - i) / n, around = [[1, 0], [-1, 0], [0, 1], [0, -1]].map(([di, dj]) => (i + di >= 0 && j + dj >= 0 && i + di < n && j + dj < n ? low[(j + dj) * n + i + di] : Infinity)).filter(Number.isFinite);
273
+ if (around.length > 0) low[c] = Math.min(...around); else open++;
274
+ }
275
+ if (open === 0) break;
276
+ }
277
+ const top = (i, j) => (i < 0 || j < 0 || i >= n || j >= n || !Number.isFinite(low[j * n + i]) || low[j * n + i] < floorY + 1 ? floorY : low[j * n + i] + 1);
278
+ let peak = floorY; for (let c = 0; c < n * n; c++) peak = Math.max(peak, top(c % n, (c - (c % n)) / n));
279
+ const tint = (y) => { const k = peak > floorY ? (y - floorY) / (peak - floorY) : 1; return [0, 1, 2].map(r => foot[r] + (lip[r] - foot[r]) * k); };
280
+ const regions = new Map();
281
+ for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) {
282
+ const h = top(i, j);
283
+ if (h <= floorY) continue;
284
+ const x0 = -250 + i * cell, z0 = -250 + j * cell, x1 = Math.min(250, x0 + cell), z1 = Math.min(250, z0 + cell), key = `${Math.floor((x0 + 250) / 125)}-${Math.floor((z0 + 250) / 125)}`;
285
+ const region = regions.get(key) ?? { positions: [], colours: [], index: [], cx: -250 + Math.floor((x0 + 250) / 125) * 125 + 62.5, cz: -250 + Math.floor((z0 + 250) / 125) * 125 + 62.5 };
286
+ regions.set(key, region);
287
+ // the four sides, each outward (+x, -x, +z, -z), from the neighbour's top (or the floor) up to this column's
288
+ for (const { di, dj, ax, az, bx, bz } of [{ di: 1, dj: 0, ax: x1, az: z1, bx: x1, bz: z0 }, { di: -1, dj: 0, ax: x0, az: z0, bx: x0, bz: z1 },
289
+ { di: 0, dj: 1, ax: x0, az: z1, bx: x1, bz: z1 }, { di: 0, dj: -1, ax: x1, az: z0, bx: x0, bz: z0 }]) {
290
+ const from = Math.max(floorY, top(i + di, j + dj));
291
+ if (from >= h) continue;
292
+ const v = region.positions.length / 3;
293
+ for (const [x, y, z] of [[ax, from, az], [bx, from, bz], [bx, h, bz], [ax, h, az]]) { region.positions.push(x - region.cx, y, z - region.cz); region.colours.push(...tint(y)); }
294
+ region.index.push(v, v + 1, v + 2, v, v + 2, v + 3);
295
+ }
296
+ }
297
+ return [...regions.entries()].map(([key, r]) => ({ name: `stack-base-${key}`, positions: Float32Array.from(r.positions), colours: Float32Array.from(r.colours), index: Uint32Array.from(r.index), transforms: [[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, r.cx, 0, r.cz, 1]] }));
298
+ };
299
+ const base = source.near?.base === undefined || source.near.floor === undefined ? [] : stackBase(prototypes, source.near.floor.y, source.near.base);
300
+ if (base.length > 0) {
301
+ prototypes.push(...base);
302
+ console.log(`${slug}: stack base ${base.reduce((sum, p) => sum + p.index.length / 3, 0)} triangles in ${base.length} regions`);
303
+ }
304
+ // G380: a land of models (Sky Reach's islands, its far row's `parts`) is built with the SDK's shared model tools, at
305
+ // `NEAR_BAKE.modelScale` times the far share, and reduced to the near bake's land budget
306
+ const land = source.far?.parts === undefined ? [] : await (await exported(source.far.parts))(await sdk.placeholderModelTools(root, sdk.NEAR_BAKE.modelScale));
307
+ // the ground: a declared grid, else the baked terrain.bin or the shardfile's terrain collider; a world with no height
308
+ // field (a shardfile whose terrain is null, an authored mesh world) stands on the bake's flat floor (grid null)
309
+ // (a world that is its tiles, `near.world: 'tiles'`, stands on the flat floor too: its tiles carry its ground, so a far
310
+ // grid under them would only repeat their skyline as a crude height field)
311
+ const flat = source.near?.world === 'tiles' || source.far?.grid === undefined && project?.shard.terrain === null && !existsSync(terrainBin);
312
+ const ground = source.far?.grid !== undefined || flat ? null : placeholderGridBytes(root, resolve(root, 'src/shards', slug), slug);
313
+ // G630: a declared floor (near.floor) is that flat floor at its own height, in its own colour (the bake's floor stands under
314
+ // the lowest placed point, a well shaft's bottom, in the far look's colour there)
315
+ const floor = source.near?.floor;
316
+ const grid = floor !== undefined ? { res: 2, size: 500, heights: new Float32Array(4).fill(floor.y), splat: null }
317
+ : flat ? null : ground === null ? (await exported(source.far.grid))() : ground.kind === 'baked' ? sdk.bakedTerrainGrid(ground.bytes) : sdk.colliderGrid(ground.bytes);
318
+ // round 3: the ground at the height field's own density, reduced by geometric error (--ground-error=<m> to measure)
319
+ const arg = (name) => process.argv.find(value => value.startsWith(`--${name}=`))?.slice(name.length + 3);
320
+ const { bytes, manifest: baked, reduced } = await sdk.bakeNearPlaceholder({ grid, look: floor === undefined ? look : { ...look, quads: 1, colourAt: () => [...floor.colour] }, prototypes, parts: land, trees: forestTrees, stands: source.trees,
321
+ floors: base.length === 0 ? source.near?.floors : [...source.near?.floors ?? [], ...base.map(p => ({ prototype: p.name, triangles: p.index.length / 3 }))],
322
+ groundError: Number(arg('ground-error') ?? sdk.NEAR_BAKE.groundError), residentBytes: Number(arg('resident') ?? sdk.NEAR_BAKE.residentBytes), log: line => console.log(`${slug}: ${line}`) });
323
+ // G630: a shard that declares `near.owns` (its tiles draw lit only inside its world) keeps its near view over its tiles
324
+ const row = fromTiles && prototypes.length > 0 && source.near?.owns !== true ? { ...baked, near: { ...baked.near, tiles: true } } : baked;
325
+ const { file } = row, resident = file.decoded + file.gpu;
326
+ if (report) { console.log(` error ${reduced.error === undefined ? 'none (common ratio)' : `${reduced.error.toFixed(3)} m`}`); for (const k of reduced.kept) console.log(` keep ${k.name}: ${k.copies} x ${k.triangles}/${k.source}`); for (const d of reduced.dropped) console.log(` drop ${d.name}: ${d.why}`); }
327
+ const dir = resolve(root, 'public/assets/baked', slug);
328
+ mkdirSync(dir, { recursive: true });
329
+ writeFileSync(resolve(dir, 'near.glb'), bytes); writeFileSync(resolve(dir, 'near.json'), sdk.placeholderJson(row));
330
+ console.log(`${slug.padEnd(18)} near resident ${(resident / 1e6).toFixed(3)} MB wire ${(file.compressed / 1e3).toFixed(0)} KB ${file.triangles} tris (${reduced.triangles} content) ${file.draws} draw`);
331
+ process.exit(0);
@@ -0,0 +1,41 @@
1
+ // G348: the shards a placeholder bake serves, found from their own data, never a table here. A shard opts in by declaring
2
+ // JSON in `src/shards/<slug>/data/placeholder.json` (schema `@wildshard/format/placeholderSource`): its far look
3
+ // (and its grid or model parts when its land is not a height field), its ground source and its tree stand-ins.
4
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+
7
+ /** Every shard folder with a declared placeholder row, sorted by folder name: `{ slug, dir, source }`. */
8
+ export async function placeholderShards(root) {
9
+ const { placeholderSource } = await import('@wildshard/format/placeholderSource');
10
+ const out = [];
11
+ for (const slug of readdirSync(join(root, 'src/shards')).sort()) {
12
+ const file = join(root, 'src/shards', slug, 'data/placeholder.json');
13
+ if (!existsSync(file)) continue;
14
+ const PLACEHOLDER = JSON.parse(readFileSync(file, 'utf8'));
15
+ out.push({ slug, dir: join(root, 'src/shards', slug), source: placeholderSource(slug, PLACEHOLDER) });
16
+ }
17
+ return out;
18
+ }
19
+
20
+ /** One shard's declared placeholder row (`{}` when it declares none). */
21
+ export async function placeholderOf(root, slug) {
22
+ const file = join(root, 'src/shards', slug, 'data/placeholder.json');
23
+ const { placeholderSource } = await import('@wildshard/format/placeholderSource');
24
+ return placeholderSource(slug, existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : undefined);
25
+ }
26
+
27
+ /**
28
+ * The height grid a shard's placeholders stand on, when it declares no grid of its own: its baked `terrain.bin`, else its
29
+ * shardfile terrain collider (`data/terrain.json`'s or `data/tiles.json`'s `terrain.collider`, a tile in its `assets/`).
30
+ */
31
+ export function placeholderGridBytes(root, dir, slug) {
32
+ const baked = join(root, 'public/assets/baked', slug, 'terrain.bin');
33
+ if (existsSync(baked)) return { kind: 'baked', bytes: readFileSync(baked) };
34
+ // the shardfile's compiled terrain section: a template project's data/terrain.json, a hybrid's data/tiles.json
35
+ const file = ['data/terrain.json', 'data/tiles.json'].map(name => join(dir, name)).find(path => existsSync(path));
36
+ if (file === undefined) throw new Error(`${slug}: no terrain.bin and no shardfile terrain section`);
37
+ const row = JSON.parse(readFileSync(file, 'utf8'));
38
+ const collider = row?.terrain?.collider;
39
+ if (typeof collider !== 'string') throw new Error(`${slug}: no terrain.bin and no shardfile terrain collider`);
40
+ return { kind: 'collider', bytes: readFileSync(join(dir, 'assets', collider)) };
41
+ }
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ // Trusted SF9c export: procedural generators and pose closures become immutable GLB joints, weights and clips.
3
+ import { build } from 'vite';
4
+ import { mkdtempSync, rmSync, symlinkSync, copyFileSync } from 'node:fs';
5
+ import { tmpdir } from 'node:os';
6
+ import { join, resolve } from 'node:path';
7
+ import { pathToFileURL } from 'node:url';
8
+
9
+ const repo = resolve(import.meta.dirname, '../..'), scratch = mkdtempSync(join(tmpdir(), 'skin-export-'));
10
+ try {
11
+ process.chdir(repo); symlinkSync(join(repo, 'node_modules'), join(scratch, 'node_modules'));
12
+ await build({ configFile: false, logLevel: 'silent', build: { target: 'esnext', outDir: join(scratch, 'generator'), emptyOutDir: true, lib: { entry: join(repo, 'test/fixtures/sim-level/skins/build.ts'), formats: ['es'], fileName: 'build' }, rolldownOptions: { platform: 'node', external: [/^node:/u, 'vite', '@gltf-transform/core', '@gltf-transform/extensions', 'meshoptimizer'] } } });
13
+ const generator = await import(pathToFileURL(join(scratch, 'generator/build.js')).href), directory = join(repo, 'public/assets/baked/skin-fixture');
14
+ await generator.writeSkinFixtures(directory); copyFileSync(join(directory, 'skins.json'), join(repo, 'test/fixtures/sim-level/skins/skins.json'));
15
+ } finally { rmSync(scratch, { recursive: true, force: true }); }
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ // SHARD-PLATFORM SF16: the template's creature skins as shardfile content. Copies the SF9c exported grey blob and boar
3
+ // (public/assets/baked/skin-fixture, made by scripts/bake/skins.mjs) into the template's content-addressed assets: each
4
+ // GLB, plus one `json` skin file ({ row, binding }) that depends on it, and writes data/skins.json for shard.config.ts.
5
+ // P1-S1: it lives in scripts/, beside the fixture's own producer, since that fixture stays when the template moves out.
6
+ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
7
+ import { createHash } from 'node:crypto';
8
+ import { resolve } from 'node:path';
9
+
10
+ const root = resolve(import.meta.dirname, '../..'), source = resolve(root, 'public/assets/baked/skin-fixture'), project = resolve(root, 'src/shards/_template');
11
+ const rows = JSON.parse(readFileSync(resolve(source, 'skins.json'), 'utf8')), bindings = JSON.parse(readFileSync(resolve(source, 'bindings.json'), 'utf8'));
12
+ const sha = (bytes) => createHash('sha256').update(bytes).digest('hex');
13
+ // the template's species ids and the exported skin that draws each (the look ids are the legacy look rows')
14
+ const species = [{ species: 'grey-blob', look: 'template.look.greyBlob', skin: 'grey-blob' }, { species: 'boar', look: 'template.look.boar', skin: 'boar' }];
15
+ mkdirSync(resolve(project, 'assets'), { recursive: true });
16
+ const out = species.map(({ species: id, look, skin }) => {
17
+ const { motion: _motion, materialNote: _note, ...row } = rows.find((entry) => entry.id === skin) ?? {};
18
+ const binding = bindings.find((entry) => entry.skin === skin);
19
+ if (row.id !== skin || binding === undefined) throw new Error(`template skins: no exported ${skin}`);
20
+ const glb = readFileSync(resolve(source, row.file));
21
+ if (sha(glb) !== row.file) throw new Error(`template skins: ${skin} GLB hash`);
22
+ const json = Buffer.from(JSON.stringify({ row, binding })), hash = sha(json);
23
+ writeFileSync(resolve(project, 'assets', row.file), glb); writeFileSync(resolve(project, 'assets', hash), json);
24
+ return { species: id, look, skin: hash, glb: row.file,
25
+ files: [
26
+ // the parsed rows and layer tables: twice the text, over the plain JSON charge
27
+ { hash, kind: 'json', compressed: json.length, decoded: json.length * 2, gpu: 0, triangles: 0, draws: 0, dependencies: [row.file], critical: false },
28
+ // the row's declared cost already charges the layers' float buffers (SF9c)
29
+ { hash: row.file, kind: 'glb', compressed: glb.length, decoded: row.cost.decoded, gpu: row.cost.gpu, triangles: row.cost.triangles, draws: row.cost.draws, dependencies: [], critical: false },
30
+ ] };
31
+ });
32
+ writeFileSync(resolve(project, 'data/skins.json'), `${JSON.stringify(out, null, 2)}\n`);
33
+ console.info(`template skins: ${out.map((entry) => `${entry.species} ${entry.skin.slice(0, 8)}`).join(', ')}`);
@@ -0,0 +1,26 @@
1
+ import type { Pixels } from '@wildshard/engine/player/viewmodelTextures';
2
+
3
+ /** The result carries only dimensions and the names whose raw planes were uploaded. */
4
+ export interface ViewmodelBake { readonly w: number; readonly h: number; readonly planes: readonly ('col' | 'nrm' | 'arm')[] }
5
+
6
+ /** Send exact RGBA subviews; encoding and KTX2 cache policy remain in the Node baker. */
7
+ export async function sendViewmodelPixels(pixels: Pixels, byteUrl: string, send: typeof fetch = fetch): Promise<ViewmodelBake> {
8
+ if (!Number.isSafeInteger(pixels.w) || !Number.isSafeInteger(pixels.h) || pixels.w < 1 || pixels.h < 1 || pixels.w > 4096 || pixels.h > 4096)
9
+ throw new Error('Invalid viewmodel raster dimensions');
10
+ const expected = pixels.w * pixels.h * 4, planes: ('col' | 'nrm' | 'arm')[] = [];
11
+ for (const name of ['col', 'nrm', 'arm'] as const) {
12
+ const bytes = pixels[name];
13
+ if (bytes === null) continue;
14
+ if (bytes.byteLength !== expected || !(bytes.buffer instanceof ArrayBuffer)) throw new Error('Invalid viewmodel raster plane');
15
+ }
16
+ for (const name of ['col', 'nrm', 'arm'] as const) {
17
+ const bytes = pixels[name];
18
+ if (bytes === null) continue;
19
+ const buffer = bytes.buffer;
20
+ if (!(buffer instanceof ArrayBuffer)) throw new Error('Invalid viewmodel raster storage');
21
+ const response = await send(`${byteUrl}${name}`, { method: 'POST', body: new Uint8Array(buffer, bytes.byteOffset, bytes.byteLength) });
22
+ if (!response.ok) throw new Error(`Viewmodel ${name} byte handoff refused`);
23
+ planes.push(name);
24
+ }
25
+ return { w: pixels.w, h: pixels.h, planes };
26
+ }
@@ -0,0 +1,11 @@
1
+ import { makePixels, type SetName } from '@wildshard/engine/player/viewmodelTextures';
2
+ import { sendViewmodelPixels, type ViewmodelBake } from './viewmodelBytes';
3
+
4
+ declare global { interface Window { bakeViewmodelPixels: (name: SetName, byteUrl: string) => Promise<ViewmodelBake> } }
5
+ function canvas2d(width: number, height: number): CanvasRenderingContext2D {
6
+ const canvas = document.createElement('canvas'); canvas.width = width; canvas.height = height;
7
+ const context = canvas.getContext('2d');
8
+ if (context === null) throw new Error('no 2d context');
9
+ return context;
10
+ }
11
+ window.bakeViewmodelPixels = (name, byteUrl) => sendViewmodelPixels(makePixels(name, canvas2d), byteUrl);
@@ -0,0 +1,35 @@
1
+ import type { Scene } from 'three';
2
+ import type { SkyRig } from '@wildshard/engine/world/skyRig';
3
+ import type { Terrain } from '@wildshard/engine/world/Terrain';
4
+ import type { Forest } from '@wildshard/engine/world/forest/Forest';
5
+ import type { Physics } from '@wildshard/engine/physics/Physics';
6
+ import type { WorldRegistry, ColliderDesc } from '@wildshard/engine/world/registry';
7
+ import type { ModelPlacementVisitor } from '@wildshard/engine/models/model';
8
+ import type { ShardManifest } from '@wildshard/engine/game/shard/manifest';
9
+ import type { Tier } from '@wildshard/engine/core/tier';
10
+ import type { BakedGrid } from '@wildshard/engine/world/BakedTerrain';
11
+
12
+ /** Resources are borrowed only during capture; snapshot real geometry/placements before the host unloads. */
13
+ export interface AuthoredWorldCapture {
14
+ scene: Scene; sky: SkyRig; forest: Forest;
15
+ terrain: Pick<Terrain, 'mesh' | 'punch'>; physics: Physics; registry: WorldRegistry;
16
+ }
17
+ /** The CLI owns the inert DOM/fetch environment and a fresh sky. Geometry capture requires production terrain. */
18
+ export interface AuthoredWorldOptions {
19
+ root: string; sky: SkyRig; element: () => HTMLElement;
20
+ /** Match the shipping recipe's tier without creating a renderer. Defaults to desktop for navmesh. */
21
+ tier?: Tier;
22
+ /** Register the real engine practice room after the authored world, as the page does. */
23
+ practiceArena?: boolean;
24
+ /** Register native content rows during the real level.kit admission window. */
25
+ installKit?: () => void | Promise<void>;
26
+ /** Original WSTR payload; selected and installed before any terrain/forest/model reads. */
27
+ nativeTerrain?: Uint8Array;
28
+ createTerrain?: (input: { ground: Float32Array; forest: Forest; native: BakedGrid | null }) => Pick<Terrain, 'mesh' | 'punch'> | Promise<Pick<Terrain, 'mesh' | 'punch'>>;
29
+ visitPlacement?: ModelPlacementVisitor;
30
+ visit?: (world: AuthoredWorldCapture) => void | Promise<void>;
31
+ }
32
+ /** Execute the same owned authored world seam as the navmesh bake, then unload after capture or rejection. */
33
+ export function visitAuthoredWorld(def: ShardManifest, options: AuthoredWorldOptions): Promise<{
34
+ colliders: ColliderDesc[]; ground: Float32Array | null; counts: Record<string, number>;
35
+ }>;