@wildshard/sdk 0.0.1 → 0.2.4
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.
- package/GUIDE.md +895 -0
- package/README.md +13 -5
- package/bin/wildshard.mjs +38 -0
- package/lint/declaration-config.d.mts +2 -0
- package/lint/declaration-config.mjs +19 -0
- package/lint/engine-plugin.d.mts +2 -0
- package/lint/engine-plugin.mjs +40 -0
- package/lint/host-callbacks.d.mts +6 -0
- package/lint/host-callbacks.mjs +123 -0
- package/lint/host-files.d.mts +1 -0
- package/lint/host-files.mjs +7 -0
- package/lint/layer-exports.d.mts +2 -0
- package/lint/layer-exports.mjs +21 -0
- package/lint/legacy-line-basis.json +995 -0
- package/lint/nine-tiling-baseline.json +35 -0
- package/lint/ratchet.json +11 -0
- package/lint/runtime-files.d.mts +12 -0
- package/lint/runtime-files.json +16 -0
- package/lint/runtime-files.mjs +69 -0
- package/lint/runtime-performance.d.mts +6 -0
- package/lint/runtime-performance.mjs +184 -0
- package/lint/sdk-plugin.d.mts +4 -0
- package/lint/sdk-plugin.mjs +134 -0
- package/lint/shardfile-boundaries.d.mts +10 -0
- package/lint/shardfile-boundaries.mjs +122 -0
- package/lint/tile-bake-debt.json +556 -0
- package/package.json +365 -3
- package/scripts/agent-parity.mjs +1524 -0
- package/scripts/agent-sync.mjs +518 -0
- package/scripts/apfs-clone.mjs +67 -0
- package/scripts/assert-store-layout.mjs +23 -0
- package/scripts/astc6-phone-cap.d.mts +3 -0
- package/scripts/astc6-phone-cap.mjs +137 -0
- package/scripts/audit-assets.d.mts +10 -0
- package/scripts/audit-assets.mjs +151 -0
- package/scripts/bake/coatFiles.d.mts +6 -0
- package/scripts/bake/coatFiles.mjs +37 -0
- package/scripts/bake/environment.d.mts +2 -0
- package/scripts/bake/environment.mjs +58 -0
- package/scripts/bake/far-proxies.mjs +45 -0
- package/scripts/bake/keyed-sky.d.mts +4 -0
- package/scripts/bake/keyed-sky.mjs +34 -0
- package/scripts/bake/movers.mjs +56 -0
- package/scripts/bake/nativeWorld.d.mts +6 -0
- package/scripts/bake/nativeWorld.mjs +43 -0
- package/scripts/bake/navmeshGround.ts +22 -0
- package/scripts/bake/near-placeholder.mjs +331 -0
- package/scripts/bake/placeholderShards.mjs +41 -0
- package/scripts/bake/skins.mjs +15 -0
- package/scripts/bake/template-skins.mjs +33 -0
- package/scripts/bake/viewmodelBytes.ts +26 -0
- package/scripts/bake/viewmodelPage.ts +11 -0
- package/scripts/bake/worldHost.d.mts +35 -0
- package/scripts/bake/worldHost.mjs +110 -0
- package/scripts/bake-astc6.cache.json +80 -0
- package/scripts/bake-astc6.far-reach.cache.json +23 -0
- package/scripts/bake-astc6.list.json +111 -0
- package/scripts/bake-astc6.mjs +279 -0
- package/scripts/bake-astc6.nalati-grasslands.cache.json +42 -0
- package/scripts/bake-catalogue.mjs +44 -0
- package/scripts/bake-check.mjs +54 -0
- package/scripts/bake-chunk.mjs +124 -0
- package/scripts/bake-cloud-field.mjs +24 -0
- package/scripts/bake-coats.mjs +110 -0
- package/scripts/bake-data-maps.d.mts +24 -0
- package/scripts/bake-data-maps.mjs +72 -0
- package/scripts/bake-entry-programs.mjs +117 -0
- package/scripts/bake-geometry.mjs +106 -0
- package/scripts/bake-hybrid-tiles.mjs +28 -0
- package/scripts/bake-ktx2.cache.json +276 -0
- package/scripts/bake-ktx2.list.json +365 -0
- package/scripts/bake-ktx2.mjs +477 -0
- package/scripts/bake-map-glb.mjs +127 -0
- package/scripts/bake-map-rest.d.mts +7 -0
- package/scripts/bake-map-rest.mjs +50 -0
- package/scripts/bake-maps.mjs +200 -0
- package/scripts/bake-navmesh.mjs +259 -0
- package/scripts/bake-packs.mjs +129 -0
- package/scripts/bake-pickups.mjs +102 -0
- package/scripts/bake-query-terrain.mjs +64 -0
- package/scripts/bake-recurve-pool.mjs +16 -0
- package/scripts/bake-section-schemas.d.mts +3 -0
- package/scripts/bake-template-shardfile.mjs +32 -0
- package/scripts/bake-textures.mjs +80 -0
- package/scripts/bake-viewmodel-sets.json +45 -0
- package/scripts/bake-viewmodel-sets.mjs +137 -0
- package/scripts/bake-voxel-ao.mjs +119 -0
- package/scripts/bake-water-ripples.mjs +25 -0
- package/scripts/blender/README.md +129 -0
- package/scripts/blender/build.sh +166 -0
- package/scripts/blender/lib/export-scene.mjs +129 -0
- package/scripts/blender/lib/glb-digest.mjs +188 -0
- package/scripts/blender/lib/glb.py +68 -0
- package/scripts/blender/lib/save_blend.py +17 -0
- package/scripts/blender/lib/world_fixture.py +55 -0
- package/scripts/blender/targets.json +591 -0
- package/scripts/build-sdk.mjs +95 -0
- package/scripts/build-shardfiles.d.mts +7 -0
- package/scripts/build-shardfiles.mjs +206 -0
- package/scripts/capture-hero.mjs +137 -0
- package/scripts/check-lift-review.mjs +23 -0
- package/scripts/chromium-keychain-check.mjs +139 -0
- package/scripts/chromium-keychain.d.mts +1 -0
- package/scripts/chromium-keychain.mjs +5 -0
- package/scripts/compile-script.d.mts +3 -0
- package/scripts/compile-script.mjs +8 -0
- package/scripts/creature-color.mjs +255 -0
- package/scripts/decide/calibrate.py +127 -0
- package/scripts/decide/calibration/2026-10-03/labels-s1.tsv +281 -0
- package/scripts/decide/calibration/2026-10-03/labels-s2.tsv +97 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3.tsv +48 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3b.tsv +26 -0
- package/scripts/decide/calibration/2026-10-03/res-capture-status-v1.jsonl +376 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-strings.jsonl +48 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-v1.jsonl +73 -0
- package/scripts/decide/decide.py +262 -0
- package/scripts/decide/decide.sh +50 -0
- package/scripts/decide/layer-purity-pilot.mjs +41 -0
- package/scripts/decide/sets/capture-status.json +46 -0
- package/scripts/decide/sets/layer-purity.json +28 -0
- package/scripts/decide/sets/text-garbled.json +17 -0
- package/scripts/decide/test_decide.py +37 -0
- package/scripts/docs.mjs +15 -0
- package/scripts/entry-reads/crawl.ts +152 -0
- package/scripts/entry-reads/tsconfig.json +25 -0
- package/scripts/gen-format-schema.d.mts +2 -0
- package/scripts/gen-format-schema.mjs +21 -0
- package/scripts/gen-host-catalogue.d.mts +14 -0
- package/scripts/gen-host-catalogue.mjs +108 -0
- package/scripts/gen-shard-layout-doc.d.mts +4 -0
- package/scripts/gen-shard-layout-doc.mjs +55 -0
- package/scripts/gen-shards.d.mts +17 -0
- package/scripts/gen-shards.mjs +311 -0
- package/scripts/goldens/capture-inputs.d.mts +4 -0
- package/scripts/goldens/capture-inputs.mjs +34 -0
- package/scripts/goldens/colour_shift.py +27 -0
- package/scripts/goldens/native-residency.d.mts +10 -0
- package/scripts/goldens/native-residency.mjs +104 -0
- package/scripts/goldens/plot-inputs.d.mts +12 -0
- package/scripts/goldens/plot-inputs.mjs +46 -0
- package/scripts/gpu-texmem.mjs +98 -0
- package/scripts/horizon-matte/config.py +24 -0
- package/scripts/horizon-matte/encode.py +91 -0
- package/scripts/horizon-matte/key.py +141 -0
- package/scripts/horizon-matte/mkjobs.py +33 -0
- package/scripts/horizon-matte/mkjobs_day2.py +11 -0
- package/scripts/horizon-matte/overlap.py +80 -0
- package/scripts/horizon-matte/run_codex.py +57 -0
- package/scripts/horizon-matte/stitch.py +133 -0
- package/scripts/img2mesh/CC0.md +105 -0
- package/scripts/img2mesh/README.md +209 -0
- package/scripts/img2mesh/ab_board.py +102 -0
- package/scripts/img2mesh/birds/birds.json +255 -0
- package/scripts/img2mesh/birds/birds_atlas.py +150 -0
- package/scripts/img2mesh/birds/birds_fix_preview.mjs +103 -0
- package/scripts/img2mesh/birds/birds_fix_render.py +75 -0
- package/scripts/img2mesh/birds/birds_pack.py +110 -0
- package/scripts/img2mesh/birds/birds_phone_b.py +112 -0
- package/scripts/img2mesh/birds/birds_post.py +550 -0
- package/scripts/img2mesh/birds/birds_render.py +125 -0
- package/scripts/img2mesh/birds/birds_sheet.py +33 -0
- package/scripts/img2mesh/birds/birds_view.py +60 -0
- package/scripts/img2mesh/board.py +100 -0
- package/scripts/img2mesh/build_cc0.sh +52 -0
- package/scripts/img2mesh/build_driftwood.sh +12 -0
- package/scripts/img2mesh/build_faces.sh +53 -0
- package/scripts/img2mesh/build_props.py +81 -0
- package/scripts/img2mesh/cc0_export.py +186 -0
- package/scripts/img2mesh/driftwood_post.py +571 -0
- package/scripts/img2mesh/e304_faces.sh +67 -0
- package/scripts/img2mesh/face_remaster.py +911 -0
- package/scripts/img2mesh/face_views.py +95 -0
- package/scripts/img2mesh/faces-e304.json +9 -0
- package/scripts/img2mesh/faces.json +30 -0
- package/scripts/img2mesh/head_cut.py +100 -0
- package/scripts/img2mesh/hi3d_paint.py +94 -0
- package/scripts/img2mesh/hi3d_refine.py +161 -0
- package/scripts/img2mesh/hunyuan_cpu_rasterizer.sh +42 -0
- package/scripts/img2mesh/pine_hollow_phone.sh +13 -0
- package/scripts/img2mesh/props/coral-arch.json +32 -0
- package/scripts/img2mesh/props/ember-furnace.json +30 -0
- package/scripts/img2mesh/props/night-market-gate.json +10 -0
- package/scripts/img2mesh/render_still.py +86 -0
- package/scripts/img2mesh/rig_strip.mjs +46 -0
- package/scripts/img2mesh/rig_transfer.mjs +104 -0
- package/scripts/img2mesh/split_sheet.py +48 -0
- package/scripts/img2mesh/trellis_batch.py +110 -0
- package/scripts/img2mesh/versus_board.py +114 -0
- package/scripts/import-bundle.d.mts +2 -0
- package/scripts/import-bundle.mjs +20 -0
- package/scripts/ktx2-ab-board.py +133 -0
- package/scripts/ktx2-ab.mjs +111 -0
- package/scripts/ktx2-settings.mjs +18 -0
- package/scripts/land.d.mts +14 -0
- package/scripts/land.mjs +809 -0
- package/scripts/lint-dispatch.mjs +14 -0
- package/scripts/map-bake-frames.d.mts +4 -0
- package/scripts/map-bake-frames.mjs +23 -0
- package/scripts/map-geometry.d.mts +9 -0
- package/scripts/map-geometry.mjs +29 -0
- package/scripts/map-world.mjs +162 -0
- package/scripts/mockup-local.sh +46 -0
- package/scripts/music/export-midi.mjs +68 -0
- package/scripts/music/gen/analyze.py +308 -0
- package/scripts/music/gen/audio_jobs.py +46 -0
- package/scripts/music/gen/briefs.json +51 -0
- package/scripts/music/gen/build_page.py +334 -0
- package/scripts/music/gen/folk.json +3187 -0
- package/scripts/music/gen/gen_ace_step.py +156 -0
- package/scripts/music/gen/gen_heartmula.py +187 -0
- package/scripts/music/gen/gen_minimax.py +143 -0
- package/scripts/music/gen/gen_sao.py +122 -0
- package/scripts/music/gen/gen_sao_small.py +104 -0
- package/scripts/music/gen/gen_sfx.py +98 -0
- package/scripts/music/gen/gen_sfx_ezaudio.py +112 -0
- package/scripts/music/gen/gen_sfx_moss.py +112 -0
- package/scripts/music/gen/models.json +61 -0
- package/scripts/music/gen/nalati-jobs.json +104 -0
- package/scripts/music/gen/nalati-score-build.json +119 -0
- package/scripts/music/gen/nalati-score.json +3448 -0
- package/scripts/music/gen/ob7-fit-decisions.json +38 -0
- package/scripts/music/gen/ob7-score-jobs.json +152 -0
- package/scripts/music/gen/ob7-sfx-jobs.json +897 -0
- package/scripts/music/gen/ob7_build.py +469 -0
- package/scripts/music/gen/ob7_generate.py +67 -0
- package/scripts/music/gen/ob7_run.sh +42 -0
- package/scripts/music/gen/orchestral.json +3187 -0
- package/scripts/music/gen/own_score.py +486 -0
- package/scripts/music/gen/ph-jobs.json +27 -0
- package/scripts/music/gen/ph_page.py +222 -0
- package/scripts/music/gen/piano.json +3175 -0
- package/scripts/music/gen/rank_v3.py +248 -0
- package/scripts/music/gen/sfx-best.json +2486 -0
- package/scripts/music/gen/sfx-ezaudio.json +4082 -0
- package/scripts/music/gen/sfx-jobs.json +57 -0
- package/scripts/music/gen/sfx-minimax-jobs.json +16 -0
- package/scripts/music/gen/sfx-minimax.json +289 -0
- package/scripts/music/gen/sfx-moss.json +4082 -0
- package/scripts/music/gen/sfx-nalati-b3-jobs.json +17 -0
- package/scripts/music/gen/sfx-nalati-jobs.json +338 -0
- package/scripts/music/gen/sfx-nalati.json +11202 -0
- package/scripts/music/gen/sfx-nd-jobs.json +57 -0
- package/scripts/music/gen/sfx-nd-moss.json +2097 -0
- package/scripts/music/gen/sfx-nd-sa3-medium.json +2097 -0
- package/scripts/music/gen/sfx-nd-summary.json +38 -0
- package/scripts/music/gen/sfx-peaks.json +7 -0
- package/scripts/music/gen/sfx-ph-jobs.json +169 -0
- package/scripts/music/gen/sfx-ph-moss.json +6564 -0
- package/scripts/music/gen/sfx-ph-sa3-medium.json +7239 -0
- package/scripts/music/gen/sfx-ph-summary.json +63 -0
- package/scripts/music/gen/sfx-sa3-medium.json +4082 -0
- package/scripts/music/gen/sfx-sa3.json +4082 -0
- package/scripts/music/gen/sfx-summary.json +107 -0
- package/scripts/music/gen/sfx_build.py +332 -0
- package/scripts/music/gen/sfx_merge.py +255 -0
- package/scripts/music/gen/sfx_minimax.py +61 -0
- package/scripts/music/gen/sfx_nalati.py +331 -0
- package/scripts/music/gen/sfx_sprite.py +424 -0
- package/scripts/music/gen/stems.py +539 -0
- package/scripts/music/gen/test_loop_meter.py +29 -0
- package/scripts/music/gen/test_ob7_provenance.py +77 -0
- package/scripts/music/gen/v3-folk-build.json +148 -0
- package/scripts/music/gen/v3-folk.json +1818 -0
- package/scripts/music/gen/v3-jobs.json +145 -0
- package/scripts/music/gen/v3-orchestral-build.json +148 -0
- package/scripts/music/gen/v3-orchestral.json +1813 -0
- package/scripts/music/gen/v3-ph-folk-build.json +94 -0
- package/scripts/music/gen/v3-ph-folk.json +1806 -0
- package/scripts/music/gen/v3-ph-orchestral-build.json +94 -0
- package/scripts/music/gen/v3-ph-orchestral.json +1824 -0
- package/scripts/music/gen/v3-ph-piano-build.json +94 -0
- package/scripts/music/gen/v3-ph-piano.json +1818 -0
- package/scripts/music/gen/v3-piano-build.json +148 -0
- package/scripts/music/gen/v3-piano.json +1813 -0
- package/scripts/music/wildshard-theme.mid +0 -0
- package/scripts/music/wildshard-trailer30.mid +0 -0
- package/scripts/named-blob-output.d.mts +8 -0
- package/scripts/named-blob-output.mjs +48 -0
- package/scripts/pack-all.mjs +15 -0
- package/scripts/pid-lock.d.mts +1 -0
- package/scripts/pid-lock.mjs +63 -0
- package/scripts/practice/bake_dummy.py +53 -0
- package/scripts/practice/build_dummies.sh +43 -0
- package/scripts/practice/dummy_parts.py +568 -0
- package/scripts/practice/dummy_rig_gate.py +139 -0
- package/scripts/practice/gate_sheet.py +36 -0
- package/scripts/practice/generate_dummy_unimate.py +132 -0
- package/scripts/practice/pack_dummy.mjs +59 -0
- package/scripts/practice/repair_dummy_weights.mjs +68 -0
- package/scripts/practice/rig_dummy.py +828 -0
- package/scripts/practice/verify_unimate_skin.mjs +356 -0
- package/scripts/preparation-seed.mjs +15 -0
- package/scripts/prepare-basis-tool.mjs +6 -0
- package/scripts/prepare-product.d.mts +14 -0
- package/scripts/prepare-product.mjs +101 -0
- package/scripts/product-build-tools.d.mts +3 -0
- package/scripts/product-build-tools.json +3 -0
- package/scripts/product-build-tools.mjs +31 -0
- package/scripts/publish-public.mjs +7 -0
- package/scripts/push-tables.d.mts +1 -0
- package/scripts/push-tables.mjs +28 -0
- package/scripts/record-shard-mounts.mjs +133 -0
- package/scripts/sdk-externals.d.mts +2 -0
- package/scripts/sdk-externals.mjs +2 -0
- package/scripts/section-inventory.ts +209 -0
- package/scripts/select-candidate.mjs +15 -0
- package/scripts/shard-build-pool.d.mts +4 -0
- package/scripts/shard-build-pool.mjs +53 -0
- package/scripts/shard-line-baseline.json +17 -0
- package/scripts/shard-milestones.d.mts +15 -0
- package/scripts/shard-milestones.mjs +105 -0
- package/scripts/shard-output-report.d.mts +9 -0
- package/scripts/shard-output-report.mjs +85 -0
- package/scripts/shard-platform-cli.mjs +93 -0
- package/scripts/shard-progress.mjs +212 -0
- package/scripts/shard-timelapse.py +102 -0
- package/scripts/shardfile-cold-boot.mjs +79 -0
- package/scripts/shardfile-vite.d.mts +4 -0
- package/scripts/shardfile-vite.mjs +20 -0
- package/scripts/simplify-models.mjs +24 -0
- package/scripts/site-facts.mjs +88 -0
- package/scripts/test-template-gate.mjs +44 -0
- package/scripts/test_golden_compare.py +68 -0
- package/scripts/tex-tiers.cache.json +181 -0
- package/scripts/tex-tiers.mjs +240 -0
- package/scripts/texmem-probe.mjs +184 -0
- package/scripts/unused-assets.mjs +173 -0
- package/scripts/vite-tmp.d.mts +23 -0
- package/scripts/vite-tmp.mjs +157 -0
- package/scripts/wave-line-baselines.json +32 -0
- package/scripts/wildshard.d.mts +4 -0
- package/scripts/wildshard.mjs +105 -0
- package/scripts/witness-checkpoints.d.mts +10 -0
- package/scripts/witness-checkpoints.mjs +84 -0
- package/scripts/witness-generation.d.mts +10 -0
- package/scripts/witness-generation.mjs +45 -0
- package/scripts/witness-manifests.d.mts +8 -0
- package/scripts/witness-manifests.mjs +157 -0
- package/scripts/worktree-ignore.d.mts +4 -0
- package/scripts/worktree-ignore.mjs +36 -0
- package/scripts/worktree-reap.mjs +214 -0
- package/scripts/worktree.mjs +396 -0
- package/scripts/worldclaw/capture-front.sh +28 -0
- package/scripts/worldclaw/design-template.md +62 -0
- package/scripts/worldclaw/spec-map.py +92 -0
- package/scripts/worldclaw/spec.ts +96 -0
- package/skills/wildshard/SKILL.md +50 -0
- package/skills/wildshard-goldens/SKILL.md +54 -0
- package/skills/wildshard-mockup-to-model/SKILL.md +56 -0
- package/skills/wildshard-upgrade/SKILL.md +47 -0
- package/src/.oxfmtrc.json +50 -0
- package/src/.oxlintrc.json +173 -0
- package/src/cli/account/account.ts +199 -0
- package/src/cli/account/command.ts +193 -0
- package/src/cli/account/key.ts +154 -0
- package/src/cli/args.ts +97 -0
- package/src/cli/audio/audio.ts +39 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/delete/delete.ts +258 -0
- package/src/cli/help.ts +204 -0
- package/src/cli/hero/adopt.ts +103 -0
- package/src/cli/hero/hero.ts +112 -0
- package/src/cli/hero/stamp.ts +298 -0
- package/src/cli/main.ts +291 -0
- package/src/cli/report.ts +20 -0
- package/src/cli/shardfile/command.ts +49 -0
- package/src/cli/shardfile/shardfile.ts +192 -0
- package/src/cli/upload/api.ts +246 -0
- package/src/cli/upload/compress.ts +55 -0
- package/src/cli/upload/hero.ts +62 -0
- package/src/cli/upload/placement.ts +115 -0
- package/src/cli/upload/provenance.ts +192 -0
- package/src/cli/upload/signature.ts +30 -0
- package/src/cli/upload/upload.ts +269 -0
- package/src/cli/upload/validate.ts +74 -0
- package/src/cli/upload/wire.ts +147 -0
- package/src/cli/version.ts +63 -0
- package/src/commons/bake/portableMath.ts +187 -0
- package/src/commons/catalogue.ts +10 -0
- package/src/commons/courseProgram.ts +32 -0
- package/src/commons/practiceCourse.ts +16 -0
- package/src/commons/scripts/abi.as +14 -0
- package/src/commons/scripts/bridge.as +14 -0
- package/src/commons/scripts/course.as +63 -0
- package/src/scripts/ask-new.sh +29 -0
- package/src/scripts/asks.mjs +141 -0
- package/src/scripts/herdr-prompt.sh +34 -0
- package/src/scripts/herdr-question-open.sh +67 -0
- package/src/scripts/md-wrap.mjs +229 -0
- package/src/server/app.ts +19 -0
- package/src/server/serve.ts +49 -0
- package/src/sharddev/admission.ts +7 -0
- package/src/sharddev/agentFiles.ts +127 -0
- package/src/sharddev/arenaView.ts +15 -0
- package/src/sharddev/as/groupBankV2.ts +36 -0
- package/src/sharddev/as/groupStepV2.ts +13 -0
- package/src/sharddev/as/ws.ts +30 -0
- package/src/sharddev/as/wsV2.ts +180 -0
- package/src/sharddev/assemblyscriptCompiler.d.mts +5 -0
- package/src/sharddev/assemblyscriptCompiler.mjs +14 -0
- package/src/sharddev/assetHandle.ts +84 -0
- package/src/sharddev/assetOwner.ts +70 -0
- package/src/sharddev/assetScope.ts +30 -0
- package/src/sharddev/assets.ts +21 -0
- package/src/sharddev/audio.ts +9 -0
- package/src/sharddev/audioEncode.ts +211 -0
- package/src/sharddev/author.ts +3 -0
- package/src/sharddev/authorError.ts +28 -0
- package/src/sharddev/authorManifest.ts +39 -0
- package/src/sharddev/bake/annulus.ts +19 -0
- package/src/sharddev/bake/assemblyscriptMemo.ts +76 -0
- package/src/sharddev/bake/assemblyscriptMemoPort.ts +4 -0
- package/src/sharddev/bake/authoredWorld.ts +201 -0
- package/src/sharddev/bake/basisEncoder.ts +95 -0
- package/src/sharddev/bake/basisGlb.ts +85 -0
- package/src/sharddev/bake/basisTool.ts +74 -0
- package/src/sharddev/bake/basisToolInputs.ts +476 -0
- package/src/sharddev/bake/byteCodec.ts +33 -0
- package/src/sharddev/bake/canvasAtlas.ts +406 -0
- package/src/sharddev/bake/coarseCopy.ts +59 -0
- package/src/sharddev/bake/colliders.ts +87 -0
- package/src/sharddev/bake/compactGlb.ts +224 -0
- package/src/sharddev/bake/compileScript.ts +119 -0
- package/src/sharddev/bake/compileScriptV2.ts +75 -0
- package/src/sharddev/bake/contactRows.ts +84 -0
- package/src/sharddev/bake/creaturePlacement.ts +117 -0
- package/src/sharddev/bake/export.ts +67 -0
- package/src/sharddev/bake/facetedGeometry.ts +379 -0
- package/src/sharddev/bake/farImpostor.ts +120 -0
- package/src/sharddev/bake/forest.ts +100 -0
- package/src/sharddev/bake/format-hook.mjs +2 -0
- package/src/sharddev/bake/generatorGlb.ts +23 -0
- package/src/sharddev/bake/geometryBounds.ts +77 -0
- package/src/sharddev/bake/geometryError.ts +48 -0
- package/src/sharddev/bake/glb.ts +355 -0
- package/src/sharddev/bake/glbCompression.ts +143 -0
- package/src/sharddev/bake/gltfSource.ts +59 -0
- package/src/sharddev/bake/groundMap.ts +142 -0
- package/src/sharddev/bake/image.ts +20 -0
- package/src/sharddev/bake/isleMap.ts +64 -0
- package/src/sharddev/bake/json.mjs +84 -0
- package/src/sharddev/bake/keyedSky.ts +47 -0
- package/src/sharddev/bake/keyedSkyMemo.ts +39 -0
- package/src/sharddev/bake/kinds.ts +137 -0
- package/src/sharddev/bake/lightSources.ts +31 -0
- package/src/sharddev/bake/mapAssembly.ts +84 -0
- package/src/sharddev/bake/mapRaster.ts +173 -0
- package/src/sharddev/bake/mapRest.ts +57 -0
- package/src/sharddev/bake/mapScenes.ts +234 -0
- package/src/sharddev/bake/materialGraph.ts +32 -0
- package/src/sharddev/bake/meadow.ts +27 -0
- package/src/sharddev/bake/meshoptChoiceMemo.ts +34 -0
- package/src/sharddev/bake/nativeInteractionFacts.ts +5 -0
- package/src/sharddev/bake/nativeLattice.ts +178 -0
- package/src/sharddev/bake/nativeRaster.ts +106 -0
- package/src/sharddev/bake/nativeTerrainField.ts +11 -0
- package/src/sharddev/bake/navigation-json.mjs +38 -0
- package/src/sharddev/bake/navigation.ts +113 -0
- package/src/sharddev/bake/navigationAsset.ts +18 -0
- package/src/sharddev/bake/nearPlaceholder.ts +206 -0
- package/src/sharddev/bake/normalizeRig.ts +80 -0
- package/src/sharddev/bake/phoneAstc.ts +93 -0
- package/src/sharddev/bake/placeholders.ts +581 -0
- package/src/sharddev/bake/placement.ts +80 -0
- package/src/sharddev/bake/portableBytes.ts +18 -0
- package/src/sharddev/bake/portableBytesMemo.ts +50 -0
- package/src/sharddev/bake/practiceCourse.ts +49 -0
- package/src/sharddev/bake/primitives.ts +96 -0
- package/src/sharddev/bake/props.ts +443 -0
- package/src/sharddev/bake/questPlacement.ts +98 -0
- package/src/sharddev/bake/rawTexture.ts +26 -0
- package/src/sharddev/bake/riderArms.ts +97 -0
- package/src/sharddev/bake/rig.ts +95 -0
- package/src/sharddev/bake/riggedHullRecipes.ts +40 -0
- package/src/sharddev/bake/signPlacements.ts +25 -0
- package/src/sharddev/bake/simplifier.ts +52 -0
- package/src/sharddev/bake/skinned.ts +312 -0
- package/src/sharddev/bake/slabChunks.ts +149 -0
- package/src/sharddev/bake/slabs.ts +263 -0
- package/src/sharddev/bake/source-loader.mjs +55 -0
- package/src/sharddev/bake/sourceMetadata.ts +54 -0
- package/src/sharddev/bake/species.ts +368 -0
- package/src/sharddev/bake/specimenCatalogue.ts +47 -0
- package/src/sharddev/bake/splatGround.ts +141 -0
- package/src/sharddev/bake/staticMaterials.ts +171 -0
- package/src/sharddev/bake/terrain.ts +195 -0
- package/src/sharddev/bake/texture.ts +33 -0
- package/src/sharddev/bake/textureWasm.ts +81 -0
- package/src/sharddev/bake/tileEncoder.ts +11 -0
- package/src/sharddev/bake/tileGrid.ts +62 -0
- package/src/sharddev/bake/v2Finite.ts +160 -0
- package/src/sharddev/bake/v2Fuel.ts +71 -0
- package/src/sharddev/bake/wholePartition.ts +74 -0
- package/src/sharddev/bake/wholePieceJoin.ts +147 -0
- package/src/sharddev/bake/world.ts +173 -0
- package/src/sharddev/bake/worldCollision.ts +128 -0
- package/src/sharddev/bake/worldGeometry.ts +237 -0
- package/src/sharddev/bake/worldGlb.ts +123 -0
- package/src/sharddev/bake/worldImage.ts +12 -0
- package/src/sharddev/bake/worldLod.ts +128 -0
- package/src/sharddev/bake/worldRows.ts +102 -0
- package/src/sharddev/bake/worldTextureMemo.ts +63 -0
- package/src/sharddev/bake/zstdBytesMemo.ts +52 -0
- package/src/sharddev/bake.ts +193 -0
- package/src/sharddev/bakePublication.ts +31 -0
- package/src/sharddev/behaviourSource.ts +94 -0
- package/src/sharddev/bin/wildshard.mjs +7 -0
- package/src/sharddev/blobBytes.ts +65 -0
- package/src/sharddev/blobs.ts +138 -0
- package/src/sharddev/bootInventory.ts +129 -0
- package/src/sharddev/bossProfiles.ts +18 -0
- package/src/sharddev/buildBehaviour.ts +77 -0
- package/src/sharddev/buildCacheMetrics.ts +17 -0
- package/src/sharddev/buildDecisionScripts.ts +122 -0
- package/src/sharddev/check.ts +118 -0
- package/src/sharddev/checkProject.ts +127 -0
- package/src/sharddev/cli.ts +200 -0
- package/src/sharddev/clientChannels.ts +169 -0
- package/src/sharddev/clientScripts.ts +10 -0
- package/src/sharddev/commons.ts +77 -0
- package/src/sharddev/commonsCosts.ts +11 -0
- package/src/sharddev/compileMovers.ts +11 -0
- package/src/sharddev/configBoundary.ts +6 -0
- package/src/sharddev/cookInput.ts +40 -0
- package/src/sharddev/crowds.ts +6 -0
- package/src/sharddev/decisionBindingMap.ts +11 -0
- package/src/sharddev/decisionScriptBindings.ts +117 -0
- package/src/sharddev/decisionScripts.ts +28 -0
- package/src/sharddev/decisionSource.ts +51 -0
- package/src/sharddev/dev.ts +113 -0
- package/src/sharddev/director.ts +26 -0
- package/src/sharddev/directorAbi.ts +77 -0
- package/src/sharddev/discoveryDocument.ts +97 -0
- package/src/sharddev/draft.ts +11 -0
- package/src/sharddev/eliteEntryRows.ts +29 -0
- package/src/sharddev/entries.ts +76 -0
- package/src/sharddev/entryReads.ts +73 -0
- package/src/sharddev/executeBundle.ts +55 -0
- package/src/sharddev/finds.ts +5 -0
- package/src/sharddev/formatJsonSchema.ts +3 -0
- package/src/sharddev/generationCache.ts +257 -0
- package/src/sharddev/generationRecipe.ts +94 -0
- package/src/sharddev/handwritten.ts +110 -0
- package/src/sharddev/immutable.ts +14 -0
- package/src/sharddev/interactions.ts +38 -0
- package/src/sharddev/kit/bakedGeometry.ts +16 -0
- package/src/sharddev/kit/geometryPack.ts +110 -0
- package/src/sharddev/ledger.ts +13 -0
- package/src/sharddev/looks/tileField.ts +67 -0
- package/src/sharddev/materialGraphFiles.ts +57 -0
- package/src/sharddev/materials.ts +574 -0
- package/src/sharddev/measure.ts +18 -0
- package/src/sharddev/modes.ts +115 -0
- package/src/sharddev/moverPrograms.ts +213 -0
- package/src/sharddev/movers.ts +75 -0
- package/src/sharddev/nativePopulationRows.ts +46 -0
- package/src/sharddev/newProject.ts +226 -0
- package/src/sharddev/noise.ts +54 -0
- package/src/sharddev/outputProduct.ts +188 -0
- package/src/sharddev/outputRuntime.ts +66 -0
- package/src/sharddev/performancePolicy.ts +29 -0
- package/src/sharddev/phasedBoss.ts +34 -0
- package/src/sharddev/physics.ts +194 -0
- package/src/sharddev/platformSections.ts +42 -0
- package/src/sharddev/plumbing.ts +8 -0
- package/src/sharddev/productOutput.ts +128 -0
- package/src/sharddev/project.ts +337 -0
- package/src/sharddev/projectCompilerIdentity.ts +94 -0
- package/src/sharddev/projectDecisions.ts +66 -0
- package/src/sharddev/projectEntryProof.ts +32 -0
- package/src/sharddev/projectGeneration.ts +219 -0
- package/src/sharddev/projectInputFiles.ts +47 -0
- package/src/sharddev/projectManifest.ts +108 -0
- package/src/sharddev/projectMap.ts +35 -0
- package/src/sharddev/projectOutput.ts +242 -0
- package/src/sharddev/projectPolicy.ts +17 -0
- package/src/sharddev/projectSections.ts +27 -0
- package/src/sharddev/questGraph.ts +25 -0
- package/src/sharddev/quests.ts +65 -0
- package/src/sharddev/random.ts +61 -0
- package/src/sharddev/refusals.ts +304 -0
- package/src/sharddev/reportCard.ts +13 -0
- package/src/sharddev/returnProjectionV2.ts +81 -0
- package/src/sharddev/rows.ts +192 -0
- package/src/sharddev/runtimeImports.ts +38 -0
- package/src/sharddev/runtimeMirrors.ts +39 -0
- package/src/sharddev/runtimePerformance.ts +38 -0
- package/src/sharddev/scene.ts +321 -0
- package/src/sharddev/sceneAnimation.ts +54 -0
- package/src/sharddev/sceneAudio.ts +64 -0
- package/src/sharddev/sceneDeclarations.ts +100 -0
- package/src/sharddev/sceneGraph.ts +139 -0
- package/src/sharddev/sceneTransform.ts +12 -0
- package/src/sharddev/schemaValidation.ts +61 -0
- package/src/sharddev/sections.ts +47 -0
- package/src/sharddev/shardSource.ts +59 -0
- package/src/sharddev/sourceReader.ts +26 -0
- package/src/sharddev/spawns.ts +38 -0
- package/src/sharddev/species/clips.ts +24 -0
- package/src/sharddev/species.ts +29 -0
- package/src/sharddev/speciesBrains.ts +19 -0
- package/src/sharddev/synth.ts +66 -0
- package/src/sharddev/test/compileDualScriptV2.ts +71 -0
- package/src/sharddev/test/compileSimV2.ts +21 -0
- package/src/sharddev/test/diskScriptScenario.ts +86 -0
- package/src/sharddev/test/scriptScenario.ts +249 -0
- package/src/sharddev/test/scriptSource.ts +12 -0
- package/src/sharddev/version.ts +4 -0
- package/src/sharddev/weapons/bowProfile.ts +20 -0
- package/src/sharddev/weapons/firearmRows.ts +11 -0
- package/src/sharddev/weapons/meleeProfile.ts +71 -0
- package/src/sharddev/weapons/thrownProfile.ts +10 -0
- package/src/sharddev/worldScenes.ts +308 -0
- package/src/sharddev/worldSource.ts +82 -0
- package/src/shards/_template/README.md +78 -0
- package/src/shards/_template/assets/2bf489fdb15f1734ddb4c4f32d500ec6da85c765ec7a4eb28dc6781160e7ec8c +0 -0
- package/src/shards/_template/assets/97ec4d8f75f5fa6239ee919444d6dc19fd35896bb305930c1f050ac6e0e0e6a6 +1 -0
- package/src/shards/_template/assets/a6a587a31327f936b1b04c05ade818c73fc8964260918662db43539465e27586 +0 -0
- package/src/shards/_template/assets/b4fbde0422e125b498c3dc8b9a5cc2516c8598f09e9d0e5f6b639b32f98179e6 +0 -0
- package/src/shards/_template/assets/bfa4dfc9c18979f904557ee8deab0058b8a399be10266f5fb1578b403f482fd4 +1 -0
- package/src/shards/_template/assets/ef3b7ff4fd22715771cb7d68a3977a903c5e7c3dc293542687d04b3ef3ace2cb +0 -0
- package/src/shards/_template/assets/f2db05998615ce1cb79ea96be32c168842eb6a2b34ec01feb86d36404603ee54 +0 -0
- package/src/shards/_template/assets/fef98ebb7fce6f66b26e78ac699e5c90f9bdcfaf8cabeb2b58125347eea8b4ab +0 -0
- package/src/shards/_template/behaviour/boss.as +39 -0
- package/src/shards/_template/behaviour/door.as +32 -0
- package/src/shards/_template/behaviour/hooks.json +129 -0
- package/src/shards/_template/behaviour/idle.as +75 -0
- package/src/shards/_template/behaviour/items.as +22 -0
- package/src/shards/_template/card/landscape.jpg +0 -0
- package/src/shards/_template/card/portrait.jpg +0 -0
- package/src/shards/_template/card/thumb.jpg +0 -0
- package/src/shards/_template/data/audio.json +45 -0
- package/src/shards/_template/data/bossDecision.json +83 -0
- package/src/shards/_template/data/budgets.json +70 -0
- package/src/shards/_template/data/card.json +281 -0
- package/src/shards/_template/data/clientScripts.json +987 -0
- package/src/shards/_template/data/creatures.json +65 -0
- package/src/shards/_template/data/director.json +39 -0
- package/src/shards/_template/data/encounters.json +96 -0
- package/src/shards/_template/data/items.json +172 -0
- package/src/shards/_template/data/layout.json +66 -0
- package/src/shards/_template/data/ledger.json +32 -0
- package/src/shards/_template/data/look.json +521 -0
- package/src/shards/_template/data/map.json +64 -0
- package/src/shards/_template/data/moves.json +16 -0
- package/src/shards/_template/data/placeholder.json +8 -0
- package/src/shards/_template/data/plumbing.json +32 -0
- package/src/shards/_template/data/quests.json +223 -0
- package/src/shards/_template/data/rows.json +423 -0
- package/src/shards/_template/data/skins.json +66 -0
- package/src/shards/_template/data/spawn.json +6 -0
- package/src/shards/_template/data/targets.json +150 -0
- package/src/shards/_template/data/text.json +12 -0
- package/src/shards/_template/data/ui.json +33 -0
- package/src/shards/_template/data/water.json +13 -0
- package/src/shards/_template/generators/behaviour.ts +34 -0
- package/src/shards/_template/generators/boss.ts +29 -0
- package/src/shards/_template/generators/buildOptions.ts +2 -0
- package/src/shards/_template/generators/cell.ts +224 -0
- package/src/shards/_template/generators/districts.ts +215 -0
- package/src/shards/_template/generators/farLook.ts +15 -0
- package/src/shards/_template/generators/generate.ts +27 -0
- package/src/shards/_template/generators/ground.ts +15 -0
- package/src/shards/_template/generators/kit.ts +69 -0
- package/src/shards/_template/generators/landscape.ts +59 -0
- package/src/shards/_template/generators/landscapeNoise.ts +62 -0
- package/src/shards/_template/generators/mapInputs.ts +10 -0
- package/src/shards/_template/generators/product.ts +100 -0
- package/src/shards/_template/generators/productOutput.ts +18 -0
- package/src/shards/_template/generators/props.ts +9 -0
- package/src/shards/_template/generators/templatePropsSource.ts +58 -0
- package/src/shards/_template/generators/terrain.ts +17 -0
- package/src/shards/_template/generators/world.ts +630 -0
- package/src/shards/_template/hero.json +10 -0
- package/src/shards/_template/look/entry-reads.json +20 -0
- package/src/shards/_template/manifest.json +281 -0
- package/src/shards/_template/shard.config.ts +10 -0
- package/src/shared/health.ts +10 -0
- package/src/tools/build-web.ts +59 -0
- package/src/tsconfig.json +30 -0
- package/src/web/app.tsx +53 -0
- package/src/web/index.html +12 -0
- package/src/web/main.tsx +10 -0
- package/src/web/tsconfig.json +13 -0
- package/tsconfig.author.json +23 -0
- package/tsconfig.commons.json +21 -0
- package/tsconfig.json +47 -0
- package/tsconfig.sharddev.json +20 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Box3, DoubleSide, Float32BufferAttribute, Mesh, MeshStandardMaterial, Raycaster, Vector3, type BufferGeometry } from 'three';
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
import { isJsonData } from '@wildshard/format/json';
|
|
4
|
+
import { FAMILY_IDS, PbrMaterialSchema } from '@wildshard/format/materialFamilies';
|
|
5
|
+
import { MaterialsSchema, materialGraphIr } from '@wildshard/format/materials';
|
|
6
|
+
import { parseShardfile, type Shardfile } from '@wildshard/engine/host/shardfile';
|
|
7
|
+
import { normalizeWorldGlb, type NormalizedWorld, type WorldPrimitive } from './world';
|
|
8
|
+
import { parseWorldSource } from '../worldSource';
|
|
9
|
+
import { bakeWorldTexture } from './textureWasm';
|
|
10
|
+
import { StaticMaterialCatalogue } from './staticMaterials';
|
|
11
|
+
import { compactTileGeometry, modelGrid, tileGrid, tileGridTransform, worldGeometry, mergeWorldGeometry } from './worldGeometry';
|
|
12
|
+
import { compressGlb } from './glbCompression';
|
|
13
|
+
import { staticGlb, type GlbPrimitive } from './glb';
|
|
14
|
+
import { simplifyWorldPrimitive } from './worldLod';
|
|
15
|
+
import { bakeWorldCollision } from './worldCollision';
|
|
16
|
+
import { WorldBakeRows } from './worldRows';
|
|
17
|
+
import { coarseNearView } from './placeholders';
|
|
18
|
+
import { completeL0Tiles } from './tileGrid';
|
|
19
|
+
import { gridPositionError } from './geometryError';
|
|
20
|
+
|
|
21
|
+
/** In-memory authored-world result; the project loader reads source bytes and the build writes only the product. */
|
|
22
|
+
export interface AuthoredWorldProduct { shard: Shardfile; assets: Map<string, Uint8Array> }
|
|
23
|
+
function record(input: unknown): Record<string, unknown> {
|
|
24
|
+
if (typeof input !== 'object' || input === null || Array.isArray(input) || !isJsonData(input)) throw new Error('Authored world config needs plain JSON data');
|
|
25
|
+
return input as Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Sample the real authored ground boundary with Three's offline raycaster, never a synthetic flat edge.
|
|
29
|
+
* Missing boundary ground refuses. ws_terrain selects the sampling surface when present; all collision stays WMC1. */
|
|
30
|
+
function edges(world: NormalizedWorld): Shardfile['edge'] {
|
|
31
|
+
const material = new MeshStandardMaterial({ side: DoubleSide }), terrain = [...world.static, ...world.undrawn].filter(row => row.terrain);
|
|
32
|
+
const primitives = terrain.length === 0 ? world.collision : terrain, meshes = primitives.map(row => new Mesh(worldGeometry(row), material));
|
|
33
|
+
meshes.forEach(mesh => mesh.updateMatrixWorld(true));
|
|
34
|
+
const ray = new Raycaster(new Vector3(), new Vector3(0, -1, 0), 0, 501);
|
|
35
|
+
try {
|
|
36
|
+
const side = (name: 'north' | 'south' | 'east' | 'west'): Shardfile['edge']['north'] => {
|
|
37
|
+
const heights: number[] = [], colours: [number, number, number][] = [];
|
|
38
|
+
for (let at = 0; at < 257; at++) {
|
|
39
|
+
const coordinate = -250 + at * 500 / 256;
|
|
40
|
+
ray.ray.origin.set(name === 'east' ? 250 : name === 'west' ? -250 : coordinate, 250, name === 'north' ? 250 : name === 'south' ? -250 : coordinate);
|
|
41
|
+
const hit = ray.intersectObjects(meshes, false)[0];
|
|
42
|
+
if (hit === undefined) throw new Error(`World GLB ${name} boundary sample ${at} has no permanent ground`);
|
|
43
|
+
const primitive = primitives.find((_row, index) => meshes[index] === hit.object), surface = primitive === undefined ? undefined : world.materials[primitive.material];
|
|
44
|
+
heights.push(Math.fround(hit.point.y)); colours.push([surface?.colour[0] ?? 0.5, surface?.colour[1] ?? 0.5, surface?.colour[2] ?? 0.5]);
|
|
45
|
+
}
|
|
46
|
+
return { heights, colours, roadHeight: 0 };
|
|
47
|
+
};
|
|
48
|
+
return { north: side('north'), east: side('east'), south: side('south'), west: side('west') };
|
|
49
|
+
} finally { meshes.forEach(mesh => mesh.geometry.dispose()); material.dispose(); }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The far proxy's source rows: every static, undrawn and far-only node (the default), or the far-only nodes alone (`replace`, NM0);
|
|
53
|
+
* never an additive light surface (`light`: material indices). */
|
|
54
|
+
export function farSources(world: Pick<NormalizedWorld, 'static' | 'undrawn' | 'far'>, light: ReadonlySet<number>, mode?: 'replace'): WorldPrimitive[] {
|
|
55
|
+
return (mode === 'replace' ? world.far : [...world.static, ...world.undrawn, ...world.far]).filter(row => !light.has(row.material));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Build a static authored GLB through the pinned texture/LOD tools and the normal render/collision row packers.
|
|
59
|
+
* The default config is a compiled declaration plus `world`; this build-only key is removed before format parsing.
|
|
60
|
+
* Existing compiled world sections refuse rather than being silently replaced.
|
|
61
|
+
* Vacant L0 squares have zero-cost metadata without fabricated GLBs or model rows.
|
|
62
|
+
* No repository bake script is needed. */
|
|
63
|
+
export async function bakeAuthoredWorld(input: unknown, bytes: Uint8Array, graphFiles: (hash: string) => Uint8Array | undefined = () => undefined): Promise<AuthoredWorldProduct> {
|
|
64
|
+
const source = record(input), { world: declaration, ...data } = source, authored = parseWorldSource(declaration);
|
|
65
|
+
for (const key of ['terrain', 'meshCollision', 'props', 'far', 'runtime']) if (data[key] !== undefined && data[key] !== null) throw new Error(`Authored world cannot replace compiled ${key}`);
|
|
66
|
+
if (Array.isArray(data['tiles']) && data['tiles'].length > 0) throw new Error('Authored world cannot replace compiled tiles');
|
|
67
|
+
const look = record(data['look']), materials = { ...v.parse(MaterialsSchema, look['materials'] ?? {}) };
|
|
68
|
+
// D74: a graph entry's IR from its graph file (`graphFiles`: the build's lowered graph bytes)
|
|
69
|
+
const graphs = new Map(Object.entries(materials).flatMap(([id, entry]) => entry.family === 'graph' && !('preset' in entry) ? [[id, materialGraphIr(entry, graphFiles)] as const] : []));
|
|
70
|
+
const world = await normalizeWorldGlb(bytes, authored, [...Object.keys(materials), ...FAMILY_IDS]);
|
|
71
|
+
// Platform defaults are made explicit for the named transport catalogue.
|
|
72
|
+
for (const row of world.materials) if (materials[row.id] === undefined) {
|
|
73
|
+
if (row.id !== 'pbr') throw new Error(`World GLB material ${row.name} needs an explicit ${row.id} look entry`);
|
|
74
|
+
materials[row.id] = v.parse(PbrMaterialSchema, { family: 'pbr' });
|
|
75
|
+
}
|
|
76
|
+
const encoded = new Map<string, Uint8Array>();
|
|
77
|
+
for (const material of world.materials) for (const [slot, map] of Object.entries(material.maps)) {
|
|
78
|
+
if (map === null) continue;
|
|
79
|
+
const role = slot === 'colour' || slot === 'emissive' ? 'srgb' : 'linear', key = `${map.image}/${role}`;
|
|
80
|
+
if (encoded.has(key)) continue;
|
|
81
|
+
const image = world.images.find(row => row.hash === map.image); if (image === undefined) throw new Error('World GLB missing embedded texture');
|
|
82
|
+
encoded.set(key, await bakeWorldTexture(image.bytes, role));
|
|
83
|
+
}
|
|
84
|
+
const catalogue = new StaticMaterialCatalogue(world.materials, materials, graphs, (map, role) => {
|
|
85
|
+
const texture = encoded.get(`${map.image}/${role}`); if (texture === undefined) throw new Error('World GLB missing encoded texture'); return texture;
|
|
86
|
+
});
|
|
87
|
+
const pack = new WorldBakeRows(), geometry: BufferGeometry[] = [], library: string[] = [];
|
|
88
|
+
try {
|
|
89
|
+
const bindings = catalogue.snapshot();
|
|
90
|
+
for (const texture of bindings.textures.values()) pack.asset(texture, 'ktx2');
|
|
91
|
+
// RM8.2: detail rows draw only at L0; the coarse rows stand in for them at L1, as they are
|
|
92
|
+
const detail = new Set(world.detail), coarse = await Promise.all(world.static.filter(row => !detail.has(row)).map(row => simplifyWorldPrimitive(row, 0.5, 0.25)));
|
|
93
|
+
const sourceErrors = new Map(coarse.map(row => [row.primitive, row.errorMetres]));
|
|
94
|
+
const emit = (rows: readonly WorldPrimitive[], bounds?: readonly [number, number, number, number], transform?: readonly number[], castShadow = true): { bytes: Uint8Array; dependencies: string[]; box: Box3; storageError: number; sourceError: number } => {
|
|
95
|
+
const groups = new Map<string, BufferGeometry[]>(), box = new Box3(), transient: BufferGeometry[] = [];
|
|
96
|
+
let storageError = 0, sourceError = 0;
|
|
97
|
+
try {
|
|
98
|
+
for (const row of rows) {
|
|
99
|
+
const name = world.materials[row.material]?.name; if (name === undefined) throw new Error('World GLB missing material slot');
|
|
100
|
+
const part = worldGeometry(row, bounds, transform, metres => { storageError = Math.max(storageError, metres); }); transient.push(part);
|
|
101
|
+
if (part.getAttribute('position').count === 0) continue;
|
|
102
|
+
sourceError = Math.max(sourceError, sourceErrors.get(row) ?? 0);
|
|
103
|
+
part.computeBoundingBox(); if (part.boundingBox !== null) box.union(part.boundingBox);
|
|
104
|
+
const list = groups.get(name) ?? []; list.push(part); groups.set(name, list);
|
|
105
|
+
}
|
|
106
|
+
const primitives: GlbPrimitive[] = [];
|
|
107
|
+
// RM8.1: a tile's positions are Int16 on the shared grid, dequantized by its node, and the tile is meshopt-packed
|
|
108
|
+
const grid = bounds === undefined || box.isEmpty() ? undefined : tileGrid(box);
|
|
109
|
+
const floatError = storageError;
|
|
110
|
+
for (const [name, parts] of groups) {
|
|
111
|
+
const merged = mergeWorldGeometry(parts); transient.push(merged);
|
|
112
|
+
// RM8.1a: welded, 16-bit indexed, Int8 normals and Uint16 colours (KHR_mesh_quantization) on the wire
|
|
113
|
+
// RM8.1e: a model-space graph (the open plots' turning hologram) gets a grid pinned at its model origin: on the tile's
|
|
114
|
+
// grid its positions were grid units about the tile centre, and its turn about the origin swung 512x (cyan sheets)
|
|
115
|
+
const own = grid === undefined ? undefined : catalogue.modelSpace(name) ? modelGrid(modelBox(merged)) : grid;
|
|
116
|
+
if (own !== undefined) storageError = Math.max(storageError, floatError + gridPositionError(merged, own));
|
|
117
|
+
const primitive = catalogue.primitive(name, merged, { castShadow }), compact = compactTileGeometry(primitive.geometry, own); transient.push(compact);
|
|
118
|
+
primitives.push({ ...primitive, geometry: compact, quantizedChannels: true, compactIndex: true,
|
|
119
|
+
...(own === undefined ? {} : { meshoptReady: true, transform: tileGridTransform(own) }) });
|
|
120
|
+
}
|
|
121
|
+
const glb = primitives.length === 0 ? new Uint8Array() : staticGlb(primitives);
|
|
122
|
+
return { bytes: grid === undefined || glb.length === 0 ? glb : compressGlb(glb), dependencies: catalogue.dependencies([...groups.keys()]), box, storageError, sourceError };
|
|
123
|
+
} finally { transient.forEach(part => part.dispose()); }
|
|
124
|
+
};
|
|
125
|
+
for (const lod of [0, 1] as const) {
|
|
126
|
+
const size = lod === 0 ? 62.5 : 125, count = 500 / size, rows = lod === 0 ? world.static : [...coarse.map(row => row.primitive), ...world.coarse];
|
|
127
|
+
for (let z = 0; z < count; z++) for (let x = 0; x < count; x++) {
|
|
128
|
+
const cell = [-250 + x * size, -250 + (x + 1) * size, -250 + z * size, -250 + (z + 1) * size] as const, output = emit(rows, cell, undefined, lod === 0);
|
|
129
|
+
if (output.bytes.length === 0) continue;
|
|
130
|
+
// a tile spans its whole cell; its content sets only its height (an `undrawn` ground leaves cells partly empty)
|
|
131
|
+
pack.tile({ lod, x, z, bytes: output.bytes, dependencies: output.dependencies, bounds: { min: [cell[0], output.box.min.y, cell[2]], max: [cell[1], output.box.max.y, cell[3]] }, geometricError: output.storageError + output.sourceError });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const panels = world.panels.map(panel => {
|
|
135
|
+
const output = emit(panel.primitives, undefined, panel.transform), file = pack.asset(output.bytes, 'glb', output.dependencies);
|
|
136
|
+
library.push(file.hash); return { id: panel.id, file: file.hash, visible: true };
|
|
137
|
+
});
|
|
138
|
+
// The far proxy is an independently measured vertex-colour approximation, one draw and no interactive panels.
|
|
139
|
+
// additive graph surfaces (a hologram) are light without a far silhouette; the world's far-only nodes (its source's
|
|
140
|
+
// `far` prefix) stand in for them here (G608)
|
|
141
|
+
const light = new Set(world.materials.flatMap((row, index) => { const entry = materials[row.id];
|
|
142
|
+
return graphs.get(row.id)?.effectState?.blend === 'additive' || (entry?.family === 'emissive' && entry.blend === 'additive') ? [index] : []; }));
|
|
143
|
+
const farRows = await Promise.all(farSources(world, light, authored.farMode).map(row => simplifyWorldPrimitive(row, 0.1, 2)));
|
|
144
|
+
const farParts = farRows.map(row => {
|
|
145
|
+
const part = worldGeometry(row.primitive), colour = world.materials[row.primitive.material]?.colour ?? [1, 1, 1];
|
|
146
|
+
const n = part.getAttribute('position').count, values: number[] = [], original = part.hasAttribute('color') ? part.getAttribute('color') : null;
|
|
147
|
+
for (let at = 0; at < n; at++) for (let c = 0; c < 3; c++) values.push((original?.getComponent(at, c) ?? 1) * (colour[c] ?? 1));
|
|
148
|
+
part.setAttribute('color', new Float32BufferAttribute(values, 3)); part.deleteAttribute('uv'); part.deleteAttribute('tangent'); geometry.push(part); return part;
|
|
149
|
+
});
|
|
150
|
+
const farGeometry = mergeWorldGeometry(farParts); geometry.push(farGeometry); farGeometry.computeBoundingBox();
|
|
151
|
+
const farBox = farGeometry.boundingBox; if (farBox === null) throw new Error('World GLB far proxy has no bounds');
|
|
152
|
+
const farMaterial = new MeshStandardMaterial({ vertexColors: true, roughness: 1 }); farMaterial.name = 'ws.far';
|
|
153
|
+
let farFile: Shardfile['files'][number];
|
|
154
|
+
try { farFile = pack.asset(staticGlb([{ geometry: farGeometry, material: farMaterial, castShadow: false }]), 'glb'); }
|
|
155
|
+
finally { farMaterial.dispose(); }
|
|
156
|
+
materials['ws.far'] = v.parse(PbrMaterialSchema, { family: 'pbr', vertexColours: true });
|
|
157
|
+
bindings.materials['ws.far'] = { id: 'ws.far', colour: null, normal: null, metallicRoughness: null, occlusion: null, emissive: null };
|
|
158
|
+
const collision = bakeWorldCollision(world);
|
|
159
|
+
for (const payload of collision.assets.values()) pack.asset(payload, 'binary', [], true);
|
|
160
|
+
const baked = pack.finish(world.materials[0]?.id ?? 'pbr', { materials: bindings.materials });
|
|
161
|
+
const panelCollision = collision.panels.map(row => ({ id: row.colliderId, panel: row.id, file: row.file, initialActive: true }));
|
|
162
|
+
const oldFiles = v.parse(v.array(v.unknown()), data['files'] ?? []);
|
|
163
|
+
const oldLibrary = v.parse(v.array(v.string()), data['library'] ?? []), oldCritical = v.parse(v.array(v.string()), data['critical'] ?? []);
|
|
164
|
+
const budgets = record(data['budgets']), previous = record(budgets['library']), simBudget = record(budgets['sim']), closure = new Set<string>(), pending = [...library];
|
|
165
|
+
let resident = 0, compressed = 0;
|
|
166
|
+
while (pending.length > 0) {
|
|
167
|
+
const hash = pending.pop(); if (hash === undefined || closure.has(hash)) continue;
|
|
168
|
+
const file = baked.files.find(row => row.hash === hash); if (file === undefined) throw new Error('World panel dependency missing');
|
|
169
|
+
closure.add(hash); pending.push(...file.dependencies); resident += file.decoded + file.gpu; compressed += file.compressed;
|
|
170
|
+
}
|
|
171
|
+
const criticalFiles = baked.files.filter(row => row.critical), criticalResident = criticalFiles.reduce((sum, row) => sum + row.decoded + row.gpu, 0);
|
|
172
|
+
const server = record(data['serverBudget']);
|
|
173
|
+
const shard = parseShardfile({ ...data, look: { ...look, materials }, files: [...oldFiles, ...baked.files], tiles: completeL0Tiles(baked.tiles),
|
|
174
|
+
budgets: { ...budgets, library: { resident: v.parse(v.number(), previous['resident']) + resident, compressed: v.parse(v.number(), previous['compressed']) + compressed },
|
|
175
|
+
sim: { resident: v.parse(v.number(), simBudget['resident']) + criticalResident,
|
|
176
|
+
compressed: v.parse(v.number(), simBudget['compressed']) + criticalFiles.reduce((sum, row) => sum + row.compressed, 0) } },
|
|
177
|
+
serverBudget: { ...server, memory: v.parse(v.number(), server['memory']) + criticalResident },
|
|
178
|
+
props: { ...baked.props, panels, far: farFile.hash }, library: [...new Set([...oldLibrary, ...library])], critical: [...new Set([...oldCritical, ...baked.critical])],
|
|
179
|
+
meshCollision: { version: 1, tiles: collision.tiles.map(({ x, z, file }) => ({ x, z, file })), panels: panelCollision },
|
|
180
|
+
far: { bounds: { min: farBox.min.toArray(), max: farBox.max.toArray() }, files: [farFile.hash], compressed: farFile.compressed, decoded: farFile.decoded, gpu: farFile.gpu, triangles: farFile.triangles, draws: farFile.draws }, edge: edges(world) });
|
|
181
|
+
// NM5: its own near view from its coarse tiles (a first-party product builds with no placeholders)
|
|
182
|
+
// its light (additive pools, unlit or emissive glows) has no lit vertex-colour form: the near view draws it in its own
|
|
183
|
+
// additive light layer (NM13, `coarseNearView`)
|
|
184
|
+
const lightNames = new Set(world.materials.flatMap((row, index) => { const entry = materials[row.id];
|
|
185
|
+
return light.has(index) || entry?.family === 'emissive' || graphs.get(row.id)?.model === 'unlit' ? [row.name, row.id] : []; }));
|
|
186
|
+
const colourNames = new Set(world.materials.flatMap(row => { const graph = graphs.get(row.id);
|
|
187
|
+
return graph?.model === 'unlit'
|
|
188
|
+
&& Object.values(graph.nodes).some(node => node.op === 'meshMap' && node.name === 'colourOrVertex') ? [row.name, row.id] : []; }));
|
|
189
|
+
// the near view reads its graph surfaces from their files
|
|
190
|
+
for (const entry of Object.values(materials)) if (entry.family === 'graph' && 'file' in entry) { const file = graphFiles(entry.file); if (file !== undefined) baked.assets.set(entry.file, file); }
|
|
191
|
+
if (authored.near === 'coarse') return { shard: await coarseNearView(shard, baked.assets, name => lightNames.has(name), name => colourNames.has(name)), assets: baked.assets };
|
|
192
|
+
return { shard, assets: baked.assets };
|
|
193
|
+
} finally { catalogue.dispose(); geometry.forEach(part => part.dispose()); }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A primitive's own bounding box (its positions, in its model space). */
|
|
197
|
+
function modelBox(geometry: BufferGeometry): Box3 {
|
|
198
|
+
geometry.computeBoundingBox();
|
|
199
|
+
const box = geometry.boundingBox; if (box === null) throw new Error('World primitive has no positions');
|
|
200
|
+
return box.clone();
|
|
201
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Only the trusted host executes its verified native encoder.
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Fingerprint actual installed decoder binaries and shared libraries.
|
|
4
|
+
import { readdirSync, realpathSync } from 'node:fs';
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Resolve the installed decoder from the trusted SDK, never an author path.
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Package-relative names, not installation paths, enter the fingerprint.
|
|
8
|
+
import { dirname, extname, relative, resolve, sep } from 'node:path';
|
|
9
|
+
import sharp from 'sharp';
|
|
10
|
+
import * as v from 'valibot';
|
|
11
|
+
import { compilerPackageInputs } from '../projectCompilerIdentity';
|
|
12
|
+
import { encodeCanonicalJson, hashImmutableBytes } from '../immutable';
|
|
13
|
+
import { readBoundedFile } from '../sourceReader';
|
|
14
|
+
import { readImagePixels, writeImagePixels } from './image';
|
|
15
|
+
import { bakeColourTexture } from './texture';
|
|
16
|
+
import { prepareBasisTool } from './basisTool';
|
|
17
|
+
import type { GlbBasisEncoder, GlbBasisImage } from './basisGlb';
|
|
18
|
+
|
|
19
|
+
/** Build-only capability; its identity covers actual encoder/decoder artifacts and executable recipe. */
|
|
20
|
+
export interface BasisEncoder { readonly identity: string; readonly encode: GlbBasisEncoder }
|
|
21
|
+
const text = new TextEncoder();
|
|
22
|
+
interface DecoderIdentityHost {
|
|
23
|
+
readonly require: typeof createRequire;
|
|
24
|
+
readonly names: (path: string) => readonly string[];
|
|
25
|
+
readonly entries: (path: string) => readonly { readonly name: string; readonly directory: boolean }[];
|
|
26
|
+
readonly realpath: (path: string) => string;
|
|
27
|
+
readonly read: typeof readBoundedFile;
|
|
28
|
+
}
|
|
29
|
+
const decoderHost: DecoderIdentityHost = {
|
|
30
|
+
require: createRequire, names: path => readdirSync(path),
|
|
31
|
+
entries: path => readdirSync(path, { withFileTypes: true }).map(row => ({ name: row.name, directory: row.isDirectory() })),
|
|
32
|
+
realpath: path => realpathSync(path), read: readBoundedFile,
|
|
33
|
+
};
|
|
34
|
+
/** Internal host identity, independent of an isolated worker's module-cache view.
|
|
35
|
+
* The factory always uses its concrete host; injected ports exercise strict artifact refusals. */
|
|
36
|
+
export function decoderIdentity(host: DecoderIdentityHost = decoderHost): string {
|
|
37
|
+
const require = host.require(resolve(import.meta.dirname, 'basis-decoder.cjs')), entry = require.resolve('sharp');
|
|
38
|
+
const installed = host.require(entry);
|
|
39
|
+
const platform = v.parse(v.object({ runtimePlatformArch: v.custom<() => unknown>(value => typeof value === 'function') }), installed(resolve(dirname(entry), `libvips${extname(entry)}`)));
|
|
40
|
+
const runtime = v.parse(v.pipe(v.string(), v.regex(/^[a-z0-9]+-[a-z0-9]+$/u)), platform.runtimePlatformArch());
|
|
41
|
+
let publicEntry: string, nativeRoot: string;
|
|
42
|
+
try {
|
|
43
|
+
publicEntry = host.realpath(installed.resolve(`@img/sharp-${runtime}/sharp.node`));
|
|
44
|
+
nativeRoot = host.realpath(resolve(dirname(installed.resolve(`@img/sharp-${runtime}/package`)), 'lib'));
|
|
45
|
+
} catch (error: unknown) { throw new Error('Missing exact packaged Sharp decoder', { cause: error }); }
|
|
46
|
+
const binaries = host.names(nativeRoot).filter(name => /^sharp-[^/]+\.node$/u.test(name));
|
|
47
|
+
if (binaries.length !== 1) throw new Error('Missing exact packaged Sharp decoder');
|
|
48
|
+
const binary = host.realpath(resolve(nativeRoot, binaries[0] ?? ''));
|
|
49
|
+
if (!binary.startsWith(nativeRoot + sep) || !nativeRoot.endsWith(`/@img/sharp-${runtime}/lib`)) throw new Error('Missing exact packaged Sharp decoder');
|
|
50
|
+
const binding: unknown = installed(resolve(dirname(entry), `sharp${extname(entry)}`));
|
|
51
|
+
if (installed(publicEntry) !== binding || installed(binary) !== binding) throw new Error('Sharp decoder binding differs');
|
|
52
|
+
const roots = [nativeRoot, dirname(installed.resolve(`@img/sharp-libvips-${runtime}/lib`))];
|
|
53
|
+
const files: [string, string][] = [...compilerPackageInputs([{ name: 'sharp', from: entry },
|
|
54
|
+
{ name: `@img/sharp-${runtime}`, from: entry, specifier: `@img/sharp-${runtime}/sharp.node` }])];
|
|
55
|
+
let total = 0, count = 0;
|
|
56
|
+
for (const [index, root] of roots.entries()) {
|
|
57
|
+
const base = host.realpath(root);
|
|
58
|
+
const walk = (directory: string): void => {
|
|
59
|
+
for (const row of host.entries(directory)) {
|
|
60
|
+
const path = host.realpath(resolve(directory, row.name));
|
|
61
|
+
if (!path.startsWith(base + sep)) throw new Error('Sharp dependency escaped package');
|
|
62
|
+
if (row.directory) walk(path);
|
|
63
|
+
else {
|
|
64
|
+
const bytes = host.read(path, 64_000_000); total += bytes.length;
|
|
65
|
+
if (++count > 256 || total > 128_000_000) throw new Error('Sharp artifact identity exceeds cap');
|
|
66
|
+
files.push([`native-${String(index)}/${relative(base, path).replaceAll('\\', '/')}`, hashImmutableBytes(bytes)]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
walk(base);
|
|
71
|
+
}
|
|
72
|
+
files.sort(([a], [b]) => a.localeCompare(b));
|
|
73
|
+
return hashImmutableBytes(text.encode(encodeCanonicalJson({ files, versions: sharp.versions })));
|
|
74
|
+
}
|
|
75
|
+
async function encodeImage(image: GlbBasisImage, encoder: string): Promise<Uint8Array> {
|
|
76
|
+
const decoded = await readImagePixels(new Uint8Array(image.bytes));
|
|
77
|
+
if (decoded.width !== image.width || decoded.height !== image.height) throw new Error('Basis source dimensions differ');
|
|
78
|
+
return bakeColourTexture(await writeImagePixels(decoded), encoder);
|
|
79
|
+
}
|
|
80
|
+
/** Supply the original native UASTC recipe without adding file/process/decoder imports to authored programs.
|
|
81
|
+
* The checked host installs only pinned upstream sources. Corrupt artifacts and missing build tools refuse. */
|
|
82
|
+
export async function createBasisEncoder(): Promise<BasisEncoder> {
|
|
83
|
+
const tool = await prepareBasisTool(), binary = hashImmutableBytes(readBoundedFile(tool.file, 64_000_000));
|
|
84
|
+
const version = execFileSync(tool.file, ['-version'], { timeout: 10000, maxBuffer: 1_000_000 }).toString();
|
|
85
|
+
if (!/v2\.50\.0\b/u.test(version)) throw new Error('Basis encoder version differs');
|
|
86
|
+
const decoder = decoderIdentity();
|
|
87
|
+
const identity = hashImmutableBytes(text.encode(encodeCanonicalJson({ tool: tool.identity, binary, version, decoder,
|
|
88
|
+
recipe: [encodeImage.toString(), readImagePixels.toString(), writeImagePixels.toString(), bakeColourTexture.toString()] })));
|
|
89
|
+
return { identity, encode: async image => {
|
|
90
|
+
if (hashImmutableBytes(readBoundedFile(tool.file, 64_000_000)) !== binary || decoderIdentity() !== decoder) throw new Error('Basis encoder dependencies changed');
|
|
91
|
+
const result = await encodeImage(image, tool.file);
|
|
92
|
+
if (hashImmutableBytes(readBoundedFile(tool.file, 64_000_000)) !== binary) throw new Error('Basis executable changed during encode');
|
|
93
|
+
return result;
|
|
94
|
+
} };
|
|
95
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { parseGlbData, prepareGlbCost } from '@wildshard/format/glbCost';
|
|
2
|
+
import { glbBuffers } from '@wildshard/format/glbBuffers';
|
|
3
|
+
import { parseKtx2 } from '@wildshard/format/ktx2Cost';
|
|
4
|
+
import { parseStillImage } from '@wildshard/format/stillImage';
|
|
5
|
+
|
|
6
|
+
/** An owned colour image; the caller supplies its original encoding recipe without file/process imports here. */
|
|
7
|
+
export interface GlbBasisImage { readonly index: number; readonly bytes: Uint8Array; readonly width: number; readonly height: number }
|
|
8
|
+
/** Encode one source image into a complete Basis LDR KTX2 mip chain with identical dimensions. */
|
|
9
|
+
export type GlbBasisEncoder = (image: GlbBasisImage) => Uint8Array | Promise<Uint8Array>;
|
|
10
|
+
const MAX = 25_000_000, MESHOPT = 'EXT_meshopt_compression', WEBP = 'EXT_texture_webp', BASIS = 'KHR_texture_basisu';
|
|
11
|
+
const object = (value: unknown): Record<string, unknown> => {
|
|
12
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) throw new Error('GLB variant object required');
|
|
13
|
+
return value as Record<string, unknown>;
|
|
14
|
+
};
|
|
15
|
+
const rows = (value: unknown): Record<string, unknown>[] => {
|
|
16
|
+
if (!Array.isArray(value)) throw new Error('GLB variant rows required');
|
|
17
|
+
return value.map(object);
|
|
18
|
+
};
|
|
19
|
+
const integer = (value: unknown): number => {
|
|
20
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0 || value > MAX) throw new Error('GLB variant range required');
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Producer-only byte rewrite: preserve every decoded geometry/skin/clip view and all non-storage JSON.
|
|
25
|
+
* Replace embedded WebP with injected Basis KTX2, removing meshopt storage for the original raw variant form.
|
|
26
|
+
* Both complete GLBs cross normal admission; there is no public-artifact, file, encoder or compiler fallback. */
|
|
27
|
+
export async function basisGlbVariant(source: Uint8Array, encode: GlbBasisEncoder): Promise<Uint8Array> {
|
|
28
|
+
if (!(source instanceof Uint8Array) || source.byteLength > MAX) throw new Error('GLB variant source cap');
|
|
29
|
+
const input = new Uint8Array(source);
|
|
30
|
+
await prepareGlbCost(); parseGlbData(input);
|
|
31
|
+
const header = new DataView(input.buffer, input.byteOffset, input.byteLength), jsonLength = header.getUint32(12, true);
|
|
32
|
+
const doc = object(JSON.parse(new TextDecoder().decode(input.subarray(20, 20 + jsonLength))));
|
|
33
|
+
for (const key of ['extensionsUsed', 'extensionsRequired']) {
|
|
34
|
+
const extensions = doc[key] ?? [];
|
|
35
|
+
if (!Array.isArray(extensions) || extensions.some(value => value !== MESHOPT && value !== WEBP)) throw new Error('Unsupported GLB variant extension');
|
|
36
|
+
}
|
|
37
|
+
const images = rows(doc['images'] ?? []), textures = rows(doc['textures'] ?? []);
|
|
38
|
+
if (images.length === 0 || textures.length === 0) throw new Error('GLB variant needs embedded WebP paint');
|
|
39
|
+
const buffers = rows(doc['buffers']), physical = buffers[0];
|
|
40
|
+
if (physical === undefined || buffers.slice(1).some(buffer => Object.keys(buffer).some(key => key !== 'byteLength' && key !== 'extensions'))) throw new Error('Unsupported GLB variant fallback metadata');
|
|
41
|
+
const data = glbBuffers(doc, input.subarray(28 + jsonLength)), accessors = rows(doc['accessors'] ?? []);
|
|
42
|
+
const replacements = new Map<number, Uint8Array>();
|
|
43
|
+
for (const [index, image] of images.entries()) {
|
|
44
|
+
const id = integer(image['bufferView']), view = data.views[id];
|
|
45
|
+
if (image['mimeType'] !== 'image/webp' || view === undefined || replacements.has(id)
|
|
46
|
+
|| accessors.some(accessor => accessor['bufferView'] === id)) throw new Error('GLB variant requires independent WebP image views');
|
|
47
|
+
const offset = integer(view['byteOffset'] ?? 0), length = integer(view['byteLength']);
|
|
48
|
+
const bytes = new Uint8Array(data.bytes.subarray(offset, offset + length)), paint = parseStillImage(bytes);
|
|
49
|
+
const encoded = await encode({ index, bytes, width: paint.width, height: paint.height });
|
|
50
|
+
parseKtx2(encoded);
|
|
51
|
+
const ktx = new DataView(encoded.buffer, encoded.byteOffset, encoded.byteLength), model = ktx.getUint8(ktx.getUint32(48, true) + 12);
|
|
52
|
+
if (ktx.getUint32(12, true) !== 0 || (model !== 163 && model !== 166)
|
|
53
|
+
|| ktx.getUint32(20, true) !== paint.width || ktx.getUint32(24, true) !== paint.height
|
|
54
|
+
|| ktx.getUint32(40, true) !== Math.floor(Math.log2(Math.max(paint.width, paint.height))) + 1) throw new Error('Basis variant dimensions, encoding or mip chain differ');
|
|
55
|
+
replacements.set(id, new Uint8Array(encoded)); image['mimeType'] = 'image/ktx2';
|
|
56
|
+
}
|
|
57
|
+
let length = 0;
|
|
58
|
+
const chunks = data.views.map((view, index) => {
|
|
59
|
+
const offset = integer(view['byteOffset'] ?? 0), size = integer(view['byteLength']);
|
|
60
|
+
const bytes = replacements.get(index) ?? data.bytes.subarray(offset, offset + size);
|
|
61
|
+
const padded = Math.ceil(bytes.length / 4) * 4;
|
|
62
|
+
length += padded;
|
|
63
|
+
if (length > MAX) throw new Error('GLB variant buffer cap');
|
|
64
|
+
const extensions = view['extensions'] === undefined ? {} : object(view['extensions']);
|
|
65
|
+
if (Object.keys(extensions).some(key => key !== MESHOPT)) throw new Error('Unsupported GLB variant view extension');
|
|
66
|
+
view['buffer'] = 0; view['byteOffset'] = length - padded; view['byteLength'] = bytes.length; delete view['extensions'];
|
|
67
|
+
return bytes;
|
|
68
|
+
});
|
|
69
|
+
physical['byteLength'] = length;
|
|
70
|
+
doc['bufferViews'] = data.views; doc['buffers'] = [physical];
|
|
71
|
+
for (const texture of textures) {
|
|
72
|
+
const binding = object(object(texture['extensions'])[WEBP]);
|
|
73
|
+
texture['extensions'] = { [BASIS]: { source: integer(binding['source']) } };
|
|
74
|
+
}
|
|
75
|
+
for (const key of ['extensionsUsed', 'extensionsRequired']) doc[key] = [BASIS];
|
|
76
|
+
const json = new TextEncoder().encode(JSON.stringify(doc)), padded = Math.ceil(json.length / 4) * 4;
|
|
77
|
+
if (json.length > 2_000_000 || 28 + padded + length > MAX) throw new Error('GLB variant wire cap');
|
|
78
|
+
const output = new Uint8Array(28 + padded + length), result = new DataView(output.buffer);
|
|
79
|
+
result.setUint32(0, 0x46546c67, true); result.setUint32(4, 2, true); result.setUint32(8, output.length, true);
|
|
80
|
+
result.setUint32(12, padded, true); result.setUint32(16, 0x4e4f534a, true); output.fill(32, 20, 20 + padded); output.set(json, 20);
|
|
81
|
+
result.setUint32(20 + padded, length, true); result.setUint32(24 + padded, 0x004e4942, true);
|
|
82
|
+
let at = 28 + padded;
|
|
83
|
+
for (const bytes of chunks) { output.set(bytes, at); at += Math.ceil(bytes.length / 4) * 4; }
|
|
84
|
+
parseGlbData(output); return output;
|
|
85
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Only the checked build host installs its pinned compiler tool.
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Atomic tool installation and verification stay outside author bundles.
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The trusted tool cache belongs to the build user.
|
|
6
|
+
import { homedir } from 'node:os';
|
|
7
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Only pinned relative source names enter these paths.
|
|
8
|
+
import { dirname, resolve } from 'node:path';
|
|
9
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Native compiler flags and tool cache keys name the actual host.
|
|
10
|
+
import process from 'node:process';
|
|
11
|
+
import * as v from 'valibot';
|
|
12
|
+
import { BASIS_INPUTS, BASIS_REVISION } from './basisToolInputs';
|
|
13
|
+
import { encodeCanonicalJson, hashImmutableBytes } from '../immutable';
|
|
14
|
+
import { readBoundedFile } from '../sourceReader';
|
|
15
|
+
|
|
16
|
+
const digest = v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u));
|
|
17
|
+
const Receipt = v.strictObject({ key: digest, binary: digest });
|
|
18
|
+
const flags = ['-ffp-contract=on'];
|
|
19
|
+
const text = new TextEncoder();
|
|
20
|
+
/** Compiler recipe is part of the installed artifact identity, including the original fused arithmetic. */
|
|
21
|
+
export function basisToolRecipe(platform: string, arch: string): readonly string[] {
|
|
22
|
+
if (!['darwin', 'linux'].includes(platform) || !['arm64', 'x64'].includes(arch)) throw new Error('Unsupported Basis build host');
|
|
23
|
+
return [...flags, ...(arch === 'x64' ? ['-mfma'] : [])];
|
|
24
|
+
}
|
|
25
|
+
/** Pin source, compiler recipe and resulting executable. Missing/corrupt published tools refuse, never use PATH. */
|
|
26
|
+
export async function prepareBasisTool(cacheRoot: string = resolve(homedir(), '.cache/wildshard/basis')): Promise<{ readonly file: string; readonly identity: string }> {
|
|
27
|
+
const recipe = { revision: BASIS_REVISION, inputs: BASIS_INPUTS, platform: process.platform, arch: process.arch,
|
|
28
|
+
flags: basisToolRecipe(process.platform, process.arch), compiler: 'clang', configuration: 'Release', examples: false, sse: false };
|
|
29
|
+
const key = hashImmutableBytes(text.encode(encodeCanonicalJson(recipe))), directory = resolve(cacheRoot, key), file = resolve(directory, 'source/bin/basisu');
|
|
30
|
+
const verify = (): { readonly file: string; readonly identity: string } => {
|
|
31
|
+
const receipt = v.parse(Receipt, JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(readBoundedFile(resolve(directory, 'receipt.json'), 1024))));
|
|
32
|
+
const binary = hashImmutableBytes(readBoundedFile(file, 64_000_000));
|
|
33
|
+
if (receipt.key !== key || receipt.binary !== binary) throw new Error('Pinned Basis executable identity differs');
|
|
34
|
+
return { file, identity: hashImmutableBytes(text.encode(encodeCanonicalJson({ key, binary }))) };
|
|
35
|
+
};
|
|
36
|
+
if (existsSync(directory)) return verify();
|
|
37
|
+
mkdirSync(cacheRoot, { recursive: true });
|
|
38
|
+
const temporary = mkdtempSync(resolve(cacheRoot, '.building-')), source = resolve(temporary, 'source');
|
|
39
|
+
try {
|
|
40
|
+
let cursor = 0;
|
|
41
|
+
const downloads = await Promise.allSettled(Array.from({ length: 4 }, async () => {
|
|
42
|
+
for (;;) {
|
|
43
|
+
const row = BASIS_INPUTS[cursor++]; if (row === undefined) return;
|
|
44
|
+
const [name, expected] = row;
|
|
45
|
+
const response = await fetch(`https://raw.githubusercontent.com/BinomialLLC/basis_universal/${BASIS_REVISION}/${name}`, { signal: AbortSignal.timeout(30000) });
|
|
46
|
+
if (!response.ok || response.body === null) throw new Error(`Missing pinned Basis source: ${name}`);
|
|
47
|
+
const reader = response.body.getReader(), chunks: Uint8Array[] = []; let size = 0;
|
|
48
|
+
try {
|
|
49
|
+
for (;;) { const next = await reader.read(); if (next.done) break; size += next.value.length;
|
|
50
|
+
if (size > 4_000_000) throw new Error('Basis source exceeds file cap'); chunks.push(next.value); }
|
|
51
|
+
} finally { await reader.cancel(); }
|
|
52
|
+
const bytes = new Uint8Array(size); let at = 0;
|
|
53
|
+
for (const chunk of chunks) { bytes.set(chunk, at); at += chunk.length; }
|
|
54
|
+
if (hashImmutableBytes(bytes) !== expected) throw new Error(`Pinned Basis source identity differs: ${name}`);
|
|
55
|
+
const path = resolve(source, name); mkdirSync(dirname(path), { recursive: true }); writeFileSync(path, bytes);
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
for (const download of downloads) if (download.status === 'rejected') throw download.reason;
|
|
59
|
+
const nativeFlags = recipe.flags.join(' '), build = resolve(temporary, 'build');
|
|
60
|
+
execFileSync('cmake', ['-S', source, '-B', build, '-DCMAKE_BUILD_TYPE=Release', '-DBASISU_EXAMPLES=OFF', '-DBASISU_SSE=OFF',
|
|
61
|
+
'-DCMAKE_C_COMPILER=clang', '-DCMAKE_CXX_COMPILER=clang++', `-DCMAKE_C_FLAGS=${nativeFlags}`, `-DCMAKE_CXX_FLAGS=${nativeFlags}`,
|
|
62
|
+
...(process.platform === 'darwin' ? [`-DCMAKE_OSX_ARCHITECTURES=${process.arch === 'x64' ? 'x86_64' : 'arm64'}`] : [])], { timeout: 120000, maxBuffer: 2_000_000 });
|
|
63
|
+
// Cold clang builds exceed two minutes on the two-core Linux runner.
|
|
64
|
+
// Ring 2 prepares this verified prerequisite; Ring 3 reuses its receipt.
|
|
65
|
+
execFileSync('cmake', ['--build', build, '--target', 'basisu', '-j4'], { timeout: 300000, maxBuffer: 2_000_000 });
|
|
66
|
+
const binary = hashImmutableBytes(readBoundedFile(resolve(source, 'bin/basisu'), 64_000_000));
|
|
67
|
+
writeFileSync(resolve(temporary, 'receipt.json'), encodeCanonicalJson({ key, binary }));
|
|
68
|
+
// Only the source, license and resulting executable are needed after compilation.
|
|
69
|
+
rmSync(build, { recursive: true });
|
|
70
|
+
try { renameSync(temporary, directory); }
|
|
71
|
+
catch (error) { if (!(error instanceof Error && 'code' in error && ['EEXIST', 'ENOTEMPTY'].includes(String(error.code)))) throw error; }
|
|
72
|
+
return verify();
|
|
73
|
+
} finally { rmSync(temporary, { recursive: true, force: true }); }
|
|
74
|
+
}
|