@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.
- package/GUIDE.md +790 -0
- package/README.md +14 -4
- 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 +371 -4
- 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 +46 -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 +24 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/delete/delete.ts +258 -0
- package/src/cli/help.ts +196 -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 +292 -0
- package/src/cli/report.ts +16 -0
- package/src/cli/shardfile/command.ts +50 -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/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 +117 -0
- package/src/sharddev/checkProject.ts +126 -0
- package/src/sharddev/cli.ts +191 -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 +247 -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 +18 -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 +234 -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,123 @@
|
|
|
1
|
+
import { Matrix4, Quaternion, Vector3 } from 'three';
|
|
2
|
+
import { isJsonData } from '@wildshard/format/json';
|
|
3
|
+
|
|
4
|
+
interface Intake { matrices: Matrix4[]; parents: (number | undefined)[]; roots: number[] }
|
|
5
|
+
const object = (input: unknown): Record<string, unknown> => {
|
|
6
|
+
if (typeof input !== 'object' || input === null || Array.isArray(input)) throw new Error('World GLB object required');
|
|
7
|
+
return input as Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
const list = (input: unknown): unknown[] => {
|
|
10
|
+
if (!Array.isArray(input) || input.length > 10000) throw new Error('World GLB array cap');
|
|
11
|
+
return input;
|
|
12
|
+
};
|
|
13
|
+
const count = (input: unknown, max: number): number => {
|
|
14
|
+
if (typeof input !== 'number' || !Number.isSafeInteger(input) || input < 0 || input > max) throw new Error('World GLB count outside cap');
|
|
15
|
+
return input;
|
|
16
|
+
};
|
|
17
|
+
function vector(input: unknown, fallback: readonly number[]): number[] {
|
|
18
|
+
const values = input === undefined ? [...fallback] : list(input);
|
|
19
|
+
if (values.length !== fallback.length || values.some((value) => typeof value !== 'number' || !Number.isFinite(value))) throw new Error('World GLB finite transform required');
|
|
20
|
+
return values.map(Number);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Bound self-contained author bytes and hierarchy before glTF-Transform allocates accessor arrays. */
|
|
24
|
+
export function preflightWorldGlb(bytes: Uint8Array): Intake {
|
|
25
|
+
if (bytes.length < 28 || bytes.length > 256_000_000) throw new Error('World GLB wire cap or truncated header');
|
|
26
|
+
const header = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), jsonBytes = header.getUint32(12, true);
|
|
27
|
+
if (header.getUint32(0, true) !== 0x46546c67 || header.getUint32(4, true) !== 2 || header.getUint32(8, true) !== bytes.length || header.getUint32(16, true) !== 0x4e4f534a || jsonBytes > 2_000_000 || jsonBytes % 4 !== 0 || jsonBytes + 28 > bytes.length) throw new Error('World GLB header or JSON cap');
|
|
28
|
+
const binBytes = header.getUint32(20 + jsonBytes, true);
|
|
29
|
+
if (header.getUint32(24 + jsonBytes, true) !== 0x004e4942 || binBytes % 4 !== 0 || 28 + jsonBytes + binBytes !== bytes.length) throw new Error('World GLB binary chunk');
|
|
30
|
+
const input: unknown = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(20, 20 + jsonBytes)));
|
|
31
|
+
if (!isJsonData(input)) throw new Error('World GLB finite bounded JSON required');
|
|
32
|
+
const doc = object(input);
|
|
33
|
+
if (object(doc['asset'])['version'] !== '2.0') throw new Error('World GLB version');
|
|
34
|
+
const pending: unknown[] = [doc];
|
|
35
|
+
while (pending.length > 0) {
|
|
36
|
+
const value = pending.pop();
|
|
37
|
+
if (typeof value !== 'object' || value === null) continue;
|
|
38
|
+
if (!Array.isArray(value) && Object.hasOwn(value, 'extensions') && Object.keys(object(Reflect.get(value, 'extensions'))).length > 0) throw new Error('World GLB unsupported extension');
|
|
39
|
+
const children: unknown[] = Object.values(value);
|
|
40
|
+
pending.push(...children);
|
|
41
|
+
}
|
|
42
|
+
if (list(doc['extensionsRequired'] ?? []).length > 0 || list(doc['extensionsUsed'] ?? []).length > 0 || list(doc['skins'] ?? []).length > 0 || list(doc['animations'] ?? []).length > 0 || list(doc['cameras'] ?? []).length > 0) throw new Error('World GLB unsupported extension, skin, animation or camera');
|
|
43
|
+
const buffers = list(doc['buffers'] ?? []).map(object);
|
|
44
|
+
if (buffers.length !== 1 || buffers.some((buffer) => buffer['uri'] !== undefined || count(buffer['byteLength'], binBytes) < binBytes - 3)) throw new Error('World GLB needs one embedded buffer');
|
|
45
|
+
const views = list(doc['bufferViews'] ?? []).map(object);
|
|
46
|
+
for (const view of views) if (count(view['buffer'], 0) !== 0 || count(view['byteOffset'] ?? 0, binBytes) + count(view['byteLength'], binBytes) > count(buffers[0]?.['byteLength'], binBytes)) throw new Error('World GLB buffer view outside buffer');
|
|
47
|
+
const accessors = list(doc['accessors'] ?? []);
|
|
48
|
+
let aggregate = 0;
|
|
49
|
+
for (const entry of accessors) {
|
|
50
|
+
const accessor = object(entry), view = views[count(accessor['bufferView'], views.length)];
|
|
51
|
+
const width = new Map([[5120, 1], [5121, 1], [5122, 2], [5123, 2], [5125, 4], [5126, 4]]).get(Number(accessor['componentType']));
|
|
52
|
+
const dimension = new Map([['SCALAR', 1], ['VEC2', 2], ['VEC3', 3], ['VEC4', 4]]).get(String(accessor['type']));
|
|
53
|
+
const n = count(accessor['count'], 12_000_000);
|
|
54
|
+
if (view === undefined || width === undefined || dimension === undefined || accessor['sparse'] !== undefined) throw new Error('World GLB unsupported accessor');
|
|
55
|
+
const size = width * dimension, stride = count(view['byteStride'] ?? size, 252), offset = count(accessor['byteOffset'] ?? 0, binBytes);
|
|
56
|
+
aggregate += n * dimension;
|
|
57
|
+
if (aggregate > 64_000_000 || stride < size || stride % width !== 0 || offset % width !== 0 || offset + (n === 0 ? 0 : (n - 1) * stride + size) > count(view['byteLength'], binBytes)) throw new Error('World GLB accessor range or aggregate cap');
|
|
58
|
+
}
|
|
59
|
+
const images = list(doc['images'] ?? []);
|
|
60
|
+
for (const entry of images) {
|
|
61
|
+
const image = object(entry);
|
|
62
|
+
if (image['uri'] !== undefined || views[count(image['bufferView'], views.length)] === undefined || !['image/png', 'image/jpeg', 'image/webp'].includes(String(image['mimeType']))) throw new Error('World GLB image must be embedded PNG, JPEG or WebP');
|
|
63
|
+
}
|
|
64
|
+
const meshes = list(doc['meshes'] ?? []);
|
|
65
|
+
const materials = list(doc['materials'] ?? []);
|
|
66
|
+
const textures = list(doc['textures'] ?? []), samplers = list(doc['samplers'] ?? []);
|
|
67
|
+
for (const entry of textures) {
|
|
68
|
+
const texture = object(entry);
|
|
69
|
+
if (images[count(texture['source'], images.length)] === undefined || (texture['sampler'] !== undefined && samplers[count(texture['sampler'], samplers.length)] === undefined)) throw new Error('World GLB texture references missing image or sampler');
|
|
70
|
+
}
|
|
71
|
+
for (const entry of materials) {
|
|
72
|
+
const material = object(entry);
|
|
73
|
+
if (typeof material['name'] !== 'string' || material['name'].length === 0 || material['name'].length > 128) throw new Error('World GLB material needs a bounded explicit name');
|
|
74
|
+
const pbr = object(material['pbrMetallicRoughness'] ?? {});
|
|
75
|
+
for (const value of [pbr['baseColorTexture'], pbr['metallicRoughnessTexture'], material['normalTexture'], material['occlusionTexture'], material['emissiveTexture']]) if (value !== undefined && textures[count(object(value)['index'], textures.length)] === undefined) throw new Error(`World GLB material ${material['name']} references missing texture`);
|
|
76
|
+
}
|
|
77
|
+
for (const mesh of meshes) for (const entry of list(object(mesh)['primitives'])) {
|
|
78
|
+
const primitive = object(entry);
|
|
79
|
+
if ((primitive['mode'] ?? 4) !== 4 || list(primitive['targets'] ?? []).length > 0) throw new Error('World GLB needs static triangles without morph targets');
|
|
80
|
+
for (const index of Object.values(object(primitive['attributes']))) if (accessors[count(index, accessors.length)] === undefined) throw new Error('World GLB missing attribute accessor');
|
|
81
|
+
if (primitive['indices'] !== undefined && accessors[count(primitive['indices'], accessors.length)] === undefined) throw new Error('World GLB missing index accessor');
|
|
82
|
+
if (primitive['material'] === undefined || materials[count(primitive['material'], materials.length)] === undefined) throw new Error('World GLB primitive needs an explicit material');
|
|
83
|
+
}
|
|
84
|
+
const nodes = list(doc['nodes'] ?? []).map(object), parents: (number | undefined)[] = Array.from({ length: nodes.length }), local: Matrix4[] = [];
|
|
85
|
+
nodes.forEach((node, index) => {
|
|
86
|
+
if (node['mesh'] !== undefined && meshes[count(node['mesh'], meshes.length)] === undefined) throw new Error(`World GLB node ${index} references missing mesh`);
|
|
87
|
+
if (node['name'] !== undefined && (typeof node['name'] !== 'string' || node['name'].length > 128)) throw new Error(`World GLB node ${index} name cap`);
|
|
88
|
+
if (node['skin'] !== undefined || node['camera'] !== undefined || node['weights'] !== undefined) throw new Error(`World GLB node ${typeof node['name'] === 'string' ? node['name'] : index} is not static geometry`);
|
|
89
|
+
for (const entry of list(node['children'] ?? [])) {
|
|
90
|
+
const child = count(entry, nodes.length - 1);
|
|
91
|
+
if (parents[child] !== undefined) throw new Error('World GLB node has multiple parents');
|
|
92
|
+
parents[child] = index;
|
|
93
|
+
}
|
|
94
|
+
if (node['matrix'] !== undefined) {
|
|
95
|
+
if (['translation', 'rotation', 'scale'].some((key) => node[key] !== undefined)) throw new Error('World GLB node has matrix and TRS');
|
|
96
|
+
const matrix = vector(node['matrix'], new Matrix4().elements);
|
|
97
|
+
if (matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0 || matrix[15] !== 1) throw new Error('World GLB transform must be affine');
|
|
98
|
+
local.push(new Matrix4().fromArray(matrix));
|
|
99
|
+
} else {
|
|
100
|
+
const translation = vector(node['translation'], [0, 0, 0]), rotation = vector(node['rotation'], [0, 0, 0, 1]), scale = vector(node['scale'], [1, 1, 1]);
|
|
101
|
+
if (Math.abs(rotation.reduce((sum, value) => sum + value * value, 0) - 1) > 1e-5) throw new Error('World GLB unit quaternion required');
|
|
102
|
+
local.push(new Matrix4().compose(new Vector3().fromArray(translation), new Quaternion().fromArray(rotation), new Vector3().fromArray(scale)));
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const scenes = list(doc['scenes'] ?? []).map(object);
|
|
106
|
+
if (scenes.length !== 1 || (doc['scene'] ?? 0) !== 0) throw new Error('World GLB requires exactly one scene');
|
|
107
|
+
const roots = list(scenes[0]?.['nodes'] ?? []).map((entry) => count(entry, nodes.length - 1));
|
|
108
|
+
if (new Set(roots).size !== roots.length || roots.some((root) => parents[root] !== undefined)) throw new Error('World GLB scene root hierarchy');
|
|
109
|
+
const matrices: Matrix4[] = [];
|
|
110
|
+
nodes.forEach((_node, index) => {
|
|
111
|
+
const chain: number[] = []; let at: number | undefined = index;
|
|
112
|
+
while (at !== undefined) {
|
|
113
|
+
if (chain.includes(at) || chain.length >= 64) throw new Error('World GLB node cycle or hierarchy depth');
|
|
114
|
+
chain.push(at); at = parents[at];
|
|
115
|
+
}
|
|
116
|
+
if (!roots.includes(chain.at(-1) ?? -1)) throw new Error('World GLB node outside scene');
|
|
117
|
+
const matrix = new Matrix4();
|
|
118
|
+
for (const id of chain.reverse()) { const transform = local[id]; if (transform === undefined) throw new Error('World GLB missing transform'); matrix.multiply(transform); }
|
|
119
|
+
if (!matrix.elements.every(Number.isFinite) || !Number.isFinite(matrix.determinant()) || matrix.determinant() === 0) throw new Error(`World GLB node ${index} has singular transform`);
|
|
120
|
+
matrices.push(matrix);
|
|
121
|
+
});
|
|
122
|
+
return { matrices, parents, roots };
|
|
123
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import sharp from 'sharp';
|
|
2
|
+
|
|
3
|
+
/** Bounded still raster header used before pixel decode by authored-world normalization and texture baking. */
|
|
4
|
+
export async function worldImageInfo(bytes: Uint8Array): Promise<{ mime: string; width: number; height: number }> {
|
|
5
|
+
if (bytes.length === 0 || bytes.length > 25_000_000) throw new Error('World texture must be a bounded embedded PNG/JPEG/WebP');
|
|
6
|
+
const header = await sharp(bytes, { limitInputPixels: 4096 * 4096, failOn: 'warning' }).metadata();
|
|
7
|
+
const { format, width, height, pages } = header;
|
|
8
|
+
if ((format !== 'png' && format !== 'jpeg' && format !== 'webp')
|
|
9
|
+
|| !Number.isInteger(width) || !Number.isInteger(height) || width < 1 || height < 1 || width > 4096 || height > 4096
|
|
10
|
+
|| (pages !== undefined && pages !== 1)) throw new Error('World texture must be a bounded still PNG/JPEG/WebP');
|
|
11
|
+
return { mime: `image/${format}`, width, height };
|
|
12
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { MeshoptSimplifier } from 'meshoptimizer/simplifier';
|
|
2
|
+
import type { WorldPrimitive } from './world';
|
|
3
|
+
import type { NativeLatticeTile } from './nativeLattice';
|
|
4
|
+
|
|
5
|
+
/** Actual triangle count and the tool's absolute appearance-error estimate, including float-position allowance. */
|
|
6
|
+
export interface WorldLod { primitive: WorldPrimitive; errorMetres: number; sourceTriangles: number; triangles: number }
|
|
7
|
+
/** Native render-only L1 result; actual counts can exceed the requested ratio because every border remains locked. */
|
|
8
|
+
export interface NativeLatticeLod { tile: NativeLatticeTile; errorMetres: number; sourceTriangles: number; triangles: number }
|
|
9
|
+
|
|
10
|
+
function attributes(primitive: WorldPrimitive, vertices: number): { data: Float32Array; stride: number; weights: number[] } {
|
|
11
|
+
const rows: { data: Float32Array; width: number }[] = [];
|
|
12
|
+
if (primitive.colours !== null && ![3, 4].includes(primitive.colours.length / vertices)) throw new Error('World LOD invalid colour attributes');
|
|
13
|
+
for (const [data, width] of [[primitive.normals, 3], [primitive.uv, 2], [primitive.colours, primitive.colours === null ? 3 : primitive.colours.length / vertices], [primitive.tangents, 4]] as const) {
|
|
14
|
+
if (data === null) continue;
|
|
15
|
+
if (!(data instanceof Float32Array) || ![2, 3, 4].includes(width) || data.length !== vertices * width || data.some(value => !Number.isFinite(value))) throw new Error('World LOD invalid vertex attributes');
|
|
16
|
+
rows.push({ data, width });
|
|
17
|
+
}
|
|
18
|
+
const stride = rows.reduce((sum, row) => sum + row.width, 0), data = new Float32Array(vertices * stride);
|
|
19
|
+
for (let vertex = 0; vertex < vertices; vertex++) {
|
|
20
|
+
let offset = vertex * stride;
|
|
21
|
+
for (const row of rows) { data.set(row.data.subarray(vertex * row.width, (vertex + 1) * row.width), offset); offset += row.width; }
|
|
22
|
+
}
|
|
23
|
+
return { data, stride, weights: Array.from({ length: stride }, () => 1) };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function compact(source: WorldPrimitive, selected: Uint32Array): WorldPrimitive {
|
|
27
|
+
const vertices = source.positions.length / 3, remap = new Uint32Array(vertices).fill(0xffffffff), kept: number[] = [], indices = new Uint32Array(selected.length);
|
|
28
|
+
selected.forEach((vertex, i) => {
|
|
29
|
+
let at = remap[vertex];
|
|
30
|
+
if (at === undefined) throw new Error('World LOD output index outside source');
|
|
31
|
+
if (at === 0xffffffff) { at = kept.length; kept.push(vertex); remap[vertex] = at; }
|
|
32
|
+
indices[i] = at;
|
|
33
|
+
});
|
|
34
|
+
const copy = (data: Float32Array | null, width: number): Float32Array | null => {
|
|
35
|
+
if (data === null) return null;
|
|
36
|
+
const output = new Float32Array(kept.length * width);
|
|
37
|
+
kept.forEach((vertex, i) => output.set(data.subarray(vertex * width, (vertex + 1) * width), i * width));
|
|
38
|
+
return output;
|
|
39
|
+
};
|
|
40
|
+
const positions = new Float64Array(kept.length * 3);
|
|
41
|
+
kept.forEach((vertex, i) => positions.set(source.positions.subarray(vertex * 3, vertex * 3 + 3), i * 3));
|
|
42
|
+
return { ...source, positions, indices, normals: copy(source.normals, 3), uv: copy(source.uv, 2), colours: copy(source.colours, source.colours === null ? 3 : source.colours.length / vertices), tangents: copy(source.tangents, 4) };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Simplify one material primitive without moving vertices, flattening overhangs or crossing attribute/border seams.
|
|
46
|
+
* The ratio is a target, not a promise: error/topology locks may retain more triangles. Error is meshopt's estimate,
|
|
47
|
+
* not an independently measured Hausdorff bound. Callers must charge the actual returned geometry.
|
|
48
|
+
*/
|
|
49
|
+
export async function simplifyWorldPrimitive(source: WorldPrimitive, targetRatio: number, maxErrorMetres: number): Promise<WorldLod> {
|
|
50
|
+
const vertices = source.positions.length / 3, indices = source.indices;
|
|
51
|
+
if (!(source.positions instanceof Float64Array) || !Number.isInteger(vertices) || vertices < 3 || vertices > 4_000_000 || source.positions.some(value => !Number.isFinite(value) || Math.abs(value) > 1000) || !(indices instanceof Uint32Array) || indices.length < 3 || indices.length > 12_000_000 || indices.length % 3 !== 0 || indices.some(index => index >= vertices)) throw new Error('World LOD invalid bounded triangle geometry');
|
|
52
|
+
if (!Number.isFinite(targetRatio) || targetRatio <= 0 || targetRatio > 1 || !Number.isFinite(maxErrorMetres) || maxErrorMetres <= 0 || maxErrorMetres > 500) throw new Error('World LOD invalid ratio or error');
|
|
53
|
+
const packed = attributes(source, vertices), positions = Float32Array.from(source.positions);
|
|
54
|
+
let quantization = 0;
|
|
55
|
+
for (let i = 0; i < positions.length; i += 3) quantization = Math.max(quantization, Math.hypot((positions[i] ?? 0) - (source.positions[i] ?? 0), (positions[i + 1] ?? 0) - (source.positions[i + 1] ?? 0), (positions[i + 2] ?? 0) - (source.positions[i + 2] ?? 0)));
|
|
56
|
+
const allowance = quantization * 2, target = Math.max(3, Math.floor(indices.length / 3 * targetRatio) * 3);
|
|
57
|
+
let selected: Uint32Array = Uint32Array.from(indices);
|
|
58
|
+
let errorMetres = 0;
|
|
59
|
+
if (target < indices.length && allowance < maxErrorMetres) {
|
|
60
|
+
if (!MeshoptSimplifier.supported) throw new Error('World LOD WASM is unavailable');
|
|
61
|
+
await MeshoptSimplifier.ready;
|
|
62
|
+
const [output, error] = MeshoptSimplifier.simplifyWithAttributes(indices, positions, 3, packed.data, packed.stride, packed.weights, null, target, maxErrorMetres - allowance, ['LockBorder', 'ErrorAbsolute']);
|
|
63
|
+
if (!Number.isFinite(error) || error < 0 || error + allowance > maxErrorMetres || output.length < 3 || output.length > indices.length || output.length % 3 !== 0) throw new Error('World LOD invalid simplifier output');
|
|
64
|
+
selected = output;
|
|
65
|
+
if (output.length < indices.length) errorMetres = error + allowance;
|
|
66
|
+
}
|
|
67
|
+
return { primitive: compact(source, selected), errorMetres, sourceTriangles: indices.length / 3, triangles: selected.length / 3 };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Simplify an already clipped native L1 tile with the pinned WASM tool, retaining exact surviving vertices and channels.
|
|
71
|
+
* Tile and hole borders stay locked; collision and L0 are never changed. All channels participate with unit weights
|
|
72
|
+
* (at most 32 components, the tool's limit). The absolute appearance-error estimate includes float32 conversion;
|
|
73
|
+
* it is not a measured Hausdorff bound or a promise to reach the ratio. Charge the returned geometry, not the target.
|
|
74
|
+
*/
|
|
75
|
+
export async function simplifyNativeLatticeTile(source: NativeLatticeTile, targetRatio: number, maxErrorMetres: number): Promise<NativeLatticeLod> {
|
|
76
|
+
const vertices = source.positions.length / 3, indices = source.indices;
|
|
77
|
+
if (source.lod !== 1 || source.size !== 125 || ![source.x, source.z].every(value => Number.isInteger(value) && value >= 0 && value < 4)
|
|
78
|
+
|| !(source.positions instanceof Float64Array) || !Number.isInteger(vertices) || vertices > 100_000
|
|
79
|
+
|| source.positions.some(value => !Number.isFinite(value) || Math.abs(value) > 250) || !(indices instanceof Uint32Array)
|
|
80
|
+
|| indices.length > 600_000 || indices.length % 3 !== 0 || indices.some(index => index >= vertices)
|
|
81
|
+
|| (indices.length === 0 && vertices !== 0)) throw new Error('Native L1 invalid bounded tile');
|
|
82
|
+
const minX = -250 + source.x * 125, minZ = -250 + source.z * 125;
|
|
83
|
+
if ([...source.bounds.min, ...source.bounds.max].some(value => !Number.isFinite(value) || Math.abs(value) > 250)
|
|
84
|
+
|| source.bounds.min[0] !== minX || source.bounds.max[0] !== minX + 125 || source.bounds.min[2] !== minZ || source.bounds.max[2] !== minZ + 125
|
|
85
|
+
|| source.bounds.min[1] > source.bounds.max[1] || source.positions.some((value, at) => value < (source.bounds.min[at % 3] ?? Infinity) || value > (source.bounds.max[at % 3] ?? -Infinity))) throw new Error('Native L1 invalid tile bounds');
|
|
86
|
+
if (!Number.isFinite(targetRatio) || targetRatio <= 0 || targetRatio > 1 || !Number.isFinite(maxErrorMetres) || maxErrorMetres <= 0 || maxErrorMetres > 500) throw new Error('Native L1 invalid ratio or error');
|
|
87
|
+
const channels = Object.entries(source.attributes).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
88
|
+
const stride = channels.reduce((sum, [, channel]) => sum + channel.itemSize, 0);
|
|
89
|
+
if (channels.length > 16 || stride > 32) throw new Error('Native L1 simplifier attribute cap (32 components)');
|
|
90
|
+
for (const [name, channel] of channels) if (!/^[a-zA-Z][a-zA-Z0-9_]{0,63}$/u.test(name) || name === 'position'
|
|
91
|
+
|| !Number.isInteger(channel.itemSize) || channel.itemSize < 1 || channel.itemSize > 4 || !(channel.values instanceof Float64Array)
|
|
92
|
+
|| channel.values.length !== vertices * channel.itemSize || channel.values.some(value => !Number.isFinite(Math.fround(value)))) throw new Error(`Native L1 invalid channel ${name}`);
|
|
93
|
+
const positions = Float32Array.from(source.positions), data = new Float32Array(vertices * stride);
|
|
94
|
+
let quantization = 0;
|
|
95
|
+
for (let vertex = 0; vertex < vertices; vertex++) {
|
|
96
|
+
let squared = 0, offset = 0;
|
|
97
|
+
for (let c = 0; c < 3; c++) squared += ((source.positions[vertex * 3 + c] ?? 0) - (positions[vertex * 3 + c] ?? 0)) ** 2;
|
|
98
|
+
for (const [, channel] of channels) for (let c = 0; c < channel.itemSize; c++) {
|
|
99
|
+
const value = channel.values[vertex * channel.itemSize + c] ?? 0, rounded = Math.fround(value);
|
|
100
|
+
data[vertex * stride + offset++] = rounded; squared += (value - rounded) ** 2;
|
|
101
|
+
}
|
|
102
|
+
quantization = Math.max(quantization, Math.sqrt(squared));
|
|
103
|
+
}
|
|
104
|
+
const allowance = quantization * 2, target = Math.max(3, Math.floor(indices.length / 3 * targetRatio) * 3);
|
|
105
|
+
let selected = Uint32Array.from(indices), errorMetres = 0;
|
|
106
|
+
if (target < indices.length && allowance < maxErrorMetres) {
|
|
107
|
+
if (!MeshoptSimplifier.supported) throw new Error('Native L1 WASM is unavailable');
|
|
108
|
+
await MeshoptSimplifier.ready;
|
|
109
|
+
const [output, error] = MeshoptSimplifier.simplifyWithAttributes(indices, positions, 3, data, stride, Array.from({ length: stride }, () => 1), null, target, maxErrorMetres - allowance, ['LockBorder', 'ErrorAbsolute']);
|
|
110
|
+
if (!Number.isFinite(error) || error < 0 || error + allowance > maxErrorMetres || output.length < 3 || output.length > indices.length || output.length % 3 !== 0) throw new Error('Native L1 invalid simplifier output');
|
|
111
|
+
selected = Uint32Array.from(output); if (output.length < indices.length) errorMetres = error + allowance;
|
|
112
|
+
}
|
|
113
|
+
const remap = new Map<number, number>(), kept: number[] = [];
|
|
114
|
+
const compactIndices = selected.map(vertex => {
|
|
115
|
+
let at = remap.get(vertex);
|
|
116
|
+
if (at === undefined) { at = kept.length; remap.set(vertex, at); kept.push(vertex); }
|
|
117
|
+
return at;
|
|
118
|
+
});
|
|
119
|
+
const copy = (values: Float64Array, width: number): Float64Array => {
|
|
120
|
+
const output = new Float64Array(kept.length * width);
|
|
121
|
+
kept.forEach((vertex, at) => output.set(values.subarray(vertex * width, (vertex + 1) * width), at * width));
|
|
122
|
+
return output;
|
|
123
|
+
};
|
|
124
|
+
const outputAttributes: NativeLatticeTile['attributes'] = {};
|
|
125
|
+
for (const [name, channel] of channels) outputAttributes[name] = { itemSize: channel.itemSize, values: copy(channel.values, channel.itemSize) };
|
|
126
|
+
return { tile: { ...source, positions: copy(source.positions, 3), indices: compactIndices, attributes: outputAttributes,
|
|
127
|
+
bounds: { min: [...source.bounds.min], max: [...source.bounds.max] } }, errorMetres, sourceTriangles: indices.length / 3, triangles: selected.length / 3 };
|
|
128
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
2
|
+
import { PropsSchema, type ShardProps } from '@wildshard/format/props';
|
|
3
|
+
import * as v from 'valibot';
|
|
4
|
+
import { assetCost } from '../assets';
|
|
5
|
+
import { ownAssetBytes } from '../assetOwner';
|
|
6
|
+
import type { NativeLatticeTile } from './nativeLattice';
|
|
7
|
+
import { checkStaticMaterialDependencies, staticMaterialNames } from './staticMaterials';
|
|
8
|
+
import { checkTileMaterialNames, splatTextureRefs } from '@wildshard/format/splatTerrain';
|
|
9
|
+
|
|
10
|
+
type FileRow = Shardfile['files'][number];
|
|
11
|
+
type TileRow = Shardfile['tiles'][number];
|
|
12
|
+
/** One final self-contained tile GLB, from native ground, authored props, or their combined geometry. */
|
|
13
|
+
export interface WorldTileEntry {
|
|
14
|
+
lod: 0 | 1; x: number; z: number; bytes: Uint8Array;
|
|
15
|
+
bounds: TileRow['bounds']; geometricError?: number; dependencies?: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
/** Native ground producers hand their unchanged GLB to the same row packing used for static authored placements. */
|
|
18
|
+
export interface WorldGroundEntry { tile: Pick<NativeLatticeTile, 'lod' | 'x' | 'z' | 'bounds'>; bytes: Uint8Array }
|
|
19
|
+
/** Ordinary compiled rows. This render-only packer neither creates collision nor asserts product admission. */
|
|
20
|
+
export interface BakedWorldRows {
|
|
21
|
+
files: Shardfile['files']; tiles: Shardfile['tiles']; props: ShardProps;
|
|
22
|
+
critical: string[]; assets: Map<string, Uint8Array>;
|
|
23
|
+
}
|
|
24
|
+
const order = (a: string, b: string): number => a < b ? -1 : a > b ? 1 : 0;
|
|
25
|
+
const copyFile = (row: FileRow): FileRow => ({ ...row, dependencies: [...row.dependencies] });
|
|
26
|
+
const copyTile = (row: TileRow): TileRow => ({ ...row, files: [...row.files], bounds: { min: [...row.bounds.min], max: [...row.bounds.max] } });
|
|
27
|
+
|
|
28
|
+
/** Hash actual immutable bytes once, derive their costs, and pack ground/props through one deterministic file table.
|
|
29
|
+
* Supply dependencies before their users. One final GLB owns each tile address: duplicate different GLBs refuse,
|
|
30
|
+
* so a later prop pass cannot silently replace terrain. Combine authored geometry before submitting that address. */
|
|
31
|
+
export class WorldBakeRows {
|
|
32
|
+
private readonly files = new Map<string, FileRow>();
|
|
33
|
+
private readonly assets = new Map<string, Uint8Array>();
|
|
34
|
+
private readonly tiles = new Map<string, TileRow>();
|
|
35
|
+
private readonly models = new Map<string, ShardProps['tiles'][number]>();
|
|
36
|
+
|
|
37
|
+
/** Store an admitted payload with byte-derived cost; repeat bytes deduplicate, conflicting metadata refuses. */
|
|
38
|
+
asset(input: Uint8Array, kind: FileRow['kind'], dependencies: readonly string[] = [], critical = false): FileRow {
|
|
39
|
+
const owned = ownAssetBytes(input), bytes = owned.bytes, hash = owned.hash, refs = [...new Set(dependencies)].sort(order);
|
|
40
|
+
if (refs.length !== dependencies.length || refs.some(ref => !this.files.has(ref) || ref === hash)) throw new Error('World asset needs unique previously packed dependencies');
|
|
41
|
+
const known = this.files.get(hash);
|
|
42
|
+
if (known !== undefined) {
|
|
43
|
+
if (known.kind !== kind || JSON.stringify(known.dependencies) !== JSON.stringify(refs)) throw new Error('Conflicting world asset metadata');
|
|
44
|
+
if (critical) known.critical = true;
|
|
45
|
+
return copyFile(known);
|
|
46
|
+
}
|
|
47
|
+
const row: FileRow = { hash, kind, compressed: bytes.length, ...assetCost(kind, bytes), dependencies: refs, critical };
|
|
48
|
+
this.files.set(hash, row); this.assets.set(hash, bytes);
|
|
49
|
+
return copyFile(row);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Convenience seam for a native-lattice ground producer; preserves its GLB and exact clipped bounds. */
|
|
53
|
+
ground(entry: WorldGroundEntry, dependencies: readonly string[] = []): ShardProps['tiles'][number] {
|
|
54
|
+
return this.tile({ ...entry.tile, bytes: entry.bytes, dependencies });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Pack an ordinary GLB tile and the whole distinct dependency closure, without applying category cap refusals. */
|
|
58
|
+
tile(entry: WorldTileEntry): ShardProps['tiles'][number] {
|
|
59
|
+
const { lod, x, z, bounds } = entry, count = lod === 0 ? 8 : 4, size = 500 / count, error = entry.geometricError ?? 0;
|
|
60
|
+
if (!Number.isInteger(x) || !Number.isInteger(z) || x < 0 || z < 0 || x >= count || z >= count
|
|
61
|
+
|| [...bounds.min, ...bounds.max, error].some(n => !Number.isFinite(n)) || error < 0
|
|
62
|
+
|| bounds.min.some((n, i) => n > (bounds.max[i] ?? -Infinity))
|
|
63
|
+
|| bounds.min[0] < -250 + x * size || bounds.max[0] > -250 + (x + 1) * size || bounds.min[2] < -250 + z * size || bounds.max[2] > -250 + (z + 1) * size) throw new Error('Invalid world tile address or bounds');
|
|
64
|
+
const key = `${lod}/${x}/${z}`;
|
|
65
|
+
if (this.tiles.has(key)) throw new Error(`World tile ${key} already packed; combine ground and props before packing`);
|
|
66
|
+
const file = this.asset(entry.bytes, 'glb', entry.dependencies), closure = new Set<string>(), pending = [file.hash];
|
|
67
|
+
const sums = { compressed: 0, decoded: 0, gpu: 0, triangles: 0, draws: 0 };
|
|
68
|
+
while (pending.length > 0) {
|
|
69
|
+
const ref = pending.pop(); if (ref === undefined || closure.has(ref)) continue;
|
|
70
|
+
const row = this.files.get(ref); if (row === undefined) throw new Error('Missing world dependency');
|
|
71
|
+
closure.add(ref); pending.push(...row.dependencies);
|
|
72
|
+
for (const component of ['compressed', 'decoded', 'gpu', 'triangles', 'draws'] as const) sums[component] += row[component];
|
|
73
|
+
}
|
|
74
|
+
this.tiles.set(key, { lod, x, z, bounds: { min: [...bounds.min], max: [...bounds.max] }, geometricError: error, files: [file.hash], ...sums });
|
|
75
|
+
const model = { lod, x, z, file: file.hash }; this.models.set(key, model); return { ...model };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Snapshot deterministic rows. Named packing checks every GLB material and its own texture dependencies; family remains the legacy fallback. */
|
|
79
|
+
finish(family: string, named?: { materials?: NonNullable<ShardProps['materials']>; splat?: NonNullable<ShardProps['splat']> }): BakedWorldRows {
|
|
80
|
+
if (!/^[a-z][a-z0-9.-]{0,127}$/.test(family)) throw new Error('Invalid world material catalogue ID');
|
|
81
|
+
const files = [...this.files.values()].sort((a, b) => order(a.hash, b.hash)).map(copyFile);
|
|
82
|
+
const tiles = [...this.tiles.values()].sort((a, b) => a.lod - b.lod || a.z - b.z || a.x - b.x).map(copyTile);
|
|
83
|
+
const props: ShardProps = { version: 1, family, tiles: tiles.map(row => {
|
|
84
|
+
const model = this.models.get(`${row.lod}/${row.x}/${row.z}`); if (model === undefined) throw new Error('Missing world model'); return { ...model };
|
|
85
|
+
}), panels: [], models: [], textures: [], colliders: [], far: null };
|
|
86
|
+
const admittedProps = named === undefined ? props : v.parse(PropsSchema, { ...props,
|
|
87
|
+
...(named.materials === undefined ? {} : { materials: named.materials }), ...(named.splat === undefined ? {} : { splat: named.splat }) });
|
|
88
|
+
if (named !== undefined) for (const file of files) if (file.kind === 'glb') {
|
|
89
|
+
const bytes = this.assets.get(file.hash); if (bytes === undefined) throw new Error('Missing named world GLB');
|
|
90
|
+
checkTileMaterialNames(named.materials, named.splat, bytes);
|
|
91
|
+
if (named.materials !== undefined) {
|
|
92
|
+
const slots = named.splat === undefined ? named.materials : { ...named.materials, [named.splat.material]: { id: family, colour: null, normal: null, metallicRoughness: null, occlusion: null, emissive: null } };
|
|
93
|
+
checkStaticMaterialDependencies(bytes, slots, file.dependencies);
|
|
94
|
+
}
|
|
95
|
+
if (named.splat !== undefined && staticMaterialNames(bytes).includes(named.splat.material)
|
|
96
|
+
&& splatTextureRefs(named.splat).some(ref => !file.dependencies.includes(ref))) throw new Error('Splat terrain GLB must directly declare every layer dependency');
|
|
97
|
+
}
|
|
98
|
+
return { files, tiles, props: admittedProps, critical: files.filter(row => row.critical).map(row => row.hash), assets: new Map(files.map(row => {
|
|
99
|
+
const bytes = this.assets.get(row.hash); if (bytes === undefined) throw new Error('Missing world bytes'); return [row.hash, ownAssetBytes(bytes).bytes];
|
|
100
|
+
})) };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- A trusted build-only cache owns its immutable encoder results.
|
|
2
|
+
import {lstatSync,mkdirSync,readFileSync,readdirSync,renameSync,rmSync,writeFileSync} from 'node:fs';
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Keys, never author paths, select cache files.
|
|
4
|
+
import {join} from 'node:path';
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Concurrent publishers use unique temporary files, without locks or waits.
|
|
6
|
+
import {randomBytes} from 'node:crypto';
|
|
7
|
+
import * as v from 'valibot';
|
|
8
|
+
import {hashImmutableBytes} from '../immutable';
|
|
9
|
+
|
|
10
|
+
const digest=v.pipe(v.string(),v.regex(/^[a-f0-9]{64}$/u));
|
|
11
|
+
const headerBytes=144,magic='WSWTEX02';
|
|
12
|
+
const maximumWire=25_000_000,maximumEntry=headerBytes+maximumWire,maximumCache=128*1024*1024;
|
|
13
|
+
const filename=/^[a-f0-9]{64}\.bin$/u,legacyFilename=/^[a-f0-9]{64}\.json$/u;
|
|
14
|
+
|
|
15
|
+
function trim(directory:string):void {
|
|
16
|
+
const files=readdirSync(directory,{withFileTypes:true});
|
|
17
|
+
// Version-one JSON is optional memo data, never an input to the binary reader.
|
|
18
|
+
for(const row of files)if(row.isFile()&&legacyFilename.test(row.name))rmSync(join(directory,row.name),{force:true});
|
|
19
|
+
const rows=files.filter(row=>row.isFile()&&filename.test(row.name)).map(row=>{
|
|
20
|
+
const path=join(directory,row.name),stat=lstatSync(path);return {path,size:stat.size,time:stat.mtimeMs};
|
|
21
|
+
}).sort((a,b)=>b.time-a.time||a.path.localeCompare(b.path));
|
|
22
|
+
let bytes=0,kept=0;
|
|
23
|
+
for(const row of rows){
|
|
24
|
+
if(kept>=128||bytes+row.size>maximumCache)rmSync(row.path,{force:true});
|
|
25
|
+
else{bytes+=row.size;kept++;}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Pure transform memo only. Every caller still admits the exact cached bytes.
|
|
30
|
+
* Missing, corrupt or unwritable storage encodes normally; failed encodes never publish. */
|
|
31
|
+
export function cachedWorldTexture(directory:string|undefined,key:string,encode:()=>Uint8Array,admit:(bytes:Uint8Array)=>unknown):Uint8Array {
|
|
32
|
+
v.parse(digest,key);
|
|
33
|
+
const file=directory===undefined?undefined:join(directory,`${key}.bin`);
|
|
34
|
+
if(file!==undefined)try{
|
|
35
|
+
const stat=lstatSync(file);
|
|
36
|
+
if(stat.isFile()&&!stat.isSymbolicLink()&&stat.size>headerBytes&&stat.size<=maximumEntry){
|
|
37
|
+
const wire=readFileSync(file),text=new TextDecoder('utf-8',{fatal:true});
|
|
38
|
+
if(wire.length>headerBytes&&wire.length<=maximumEntry){
|
|
39
|
+
const header=new DataView(wire.buffer,wire.byteOffset,headerBytes),bytes=wire.subarray(headerBytes);
|
|
40
|
+
if(text.decode(wire.subarray(0,8))===magic&&text.decode(wire.subarray(8,72))===key&&
|
|
41
|
+
header.getUint32(136,true)===bytes.length&&header.getUint32(140,true)===0&&
|
|
42
|
+
hashImmutableBytes(bytes)===text.decode(wire.subarray(72,136))){
|
|
43
|
+
admit(bytes);return Uint8Array.from(bytes);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}catch{/* A cache is never authority for an invalid or unavailable texture. */}
|
|
48
|
+
const bytes=encode();admit(bytes);
|
|
49
|
+
if(bytes.length===0||bytes.length>maximumWire)throw new Error('World texture memo wire cap exceeded');
|
|
50
|
+
if(file!==undefined&&directory!==undefined){
|
|
51
|
+
const temporary=`${file}.${randomBytes(8).toString('hex')}.tmp`;
|
|
52
|
+
try{
|
|
53
|
+
mkdirSync(directory,{recursive:true});
|
|
54
|
+
const wire=new Uint8Array(headerBytes+bytes.length),text=new TextEncoder(),header=new DataView(wire.buffer);
|
|
55
|
+
wire.set(text.encode(magic));wire.set(text.encode(key),8);wire.set(text.encode(hashImmutableBytes(bytes)),72);
|
|
56
|
+
header.setUint32(136,bytes.length,true);wire.set(bytes,headerBytes);
|
|
57
|
+
writeFileSync(temporary,wire);
|
|
58
|
+
renameSync(temporary,file);trim(directory);
|
|
59
|
+
}catch{/* An optional memo write cannot turn a valid encode into a failure. */}
|
|
60
|
+
finally{try{rmSync(temporary,{force:true});}catch{/* Failed cache cleanup leaves no reusable entry. */}}
|
|
61
|
+
}
|
|
62
|
+
return bytes;
|
|
63
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The build host keys native compression by exact content.
|
|
2
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Optional build storage lives outside the authored product.
|
|
4
|
+
import { mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The default cache is the existing build-cache root.
|
|
6
|
+
import { homedir } from 'node:os';
|
|
7
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Cache paths use only trusted roots and hashes.
|
|
8
|
+
import { resolve } from 'node:path';
|
|
9
|
+
import { reportBuildCache } from '../buildCacheMetrics';
|
|
10
|
+
import { readBoundedFile } from '../sourceReader';
|
|
11
|
+
import { encodeBuildBytes } from './byteCodec';
|
|
12
|
+
|
|
13
|
+
const sha = (bytes: string | Uint8Array): string => createHash('sha256').update(bytes).digest('hex');
|
|
14
|
+
const codec = sha(JSON.stringify({ schema: 'native-zstd/1', node: process.version, zstd: process.versions['zstd'],
|
|
15
|
+
zlib: process.versions.zlib, platform: process.platform, arch: process.arch, implementation: encodeBuildBytes.toString() }));
|
|
16
|
+
|
|
17
|
+
/** Exact native build Zstd bytes, shared only when the complete input, level and codec match.
|
|
18
|
+
* Missing, damaged or unwritable storage recomputes with the original encoder. Every call returns owned bytes. */
|
|
19
|
+
export function encodeZstdBytesMemo(input: Uint8Array, level = 19): Uint8Array<ArrayBuffer> {
|
|
20
|
+
if (!(input instanceof Uint8Array) || !(input.buffer instanceof ArrayBuffer) || input.byteLength > 256_000_000)
|
|
21
|
+
throw new Error('Build codec requires bounded unshared bytes');
|
|
22
|
+
if (!Number.isInteger(level) || level < 1 || level > 22) throw new Error('Zstd level must be an integer from 1 to 22');
|
|
23
|
+
const owned = new Uint8Array(input);
|
|
24
|
+
const root = process.env['WILDSHARD_ZSTD_BYTES_CACHE'] ?? resolve(homedir(), '.cache/wildshard/gen/native-zstd/1');
|
|
25
|
+
const key = sha(`${codec}\0${level}\0${owned.byteLength}\0${sha(owned)}`);
|
|
26
|
+
const body = resolve(root, `${key}.bin`), meta = resolve(root, `${key}.json`);
|
|
27
|
+
reportBuildCache({cache:'zstd-bytes',event:'lookup',bytes:0});
|
|
28
|
+
try {
|
|
29
|
+
const saved: unknown = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(readBoundedFile(meta, 1000)));
|
|
30
|
+
if (typeof saved === 'object' && saved !== null && 'key' in saved && saved.key === key
|
|
31
|
+
&& 'hash' in saved && typeof saved.hash === 'string' && /^[a-f0-9]{64}$/u.test(saved.hash)) {
|
|
32
|
+
const bytes = readBoundedFile(body, 256_000_000);
|
|
33
|
+
if (sha(bytes) === saved.hash) {
|
|
34
|
+
reportBuildCache({cache:'zstd-bytes',event:'disk-hit',bytes:bytes.byteLength});
|
|
35
|
+
return Uint8Array.from(bytes);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch { /* An optional memo never replaces the original encoder's admission. */ }
|
|
39
|
+
reportBuildCache({cache:'zstd-bytes',event:'miss',bytes:0});
|
|
40
|
+
const bytes = encodeBuildBytes(owned, 'zstd', level);
|
|
41
|
+
reportBuildCache({cache:'zstd-bytes',event:'computed',bytes:bytes.byteLength});
|
|
42
|
+
let populated=false;
|
|
43
|
+
const suffix = `.${process.pid}.${randomBytes(8).toString('hex')}.tmp`;
|
|
44
|
+
try {
|
|
45
|
+
mkdirSync(root, { recursive: true });
|
|
46
|
+
writeFileSync(body + suffix, bytes, { flag: 'wx' }); renameSync(body + suffix, body);
|
|
47
|
+
writeFileSync(meta + suffix, JSON.stringify({ key, hash: sha(bytes) }), { flag: 'wx' }); renameSync(meta + suffix, meta); populated=true;
|
|
48
|
+
} catch { /* Storage availability does not change the build. */ }
|
|
49
|
+
finally { for (const file of [body + suffix, meta + suffix]) try { rmSync(file, { force: true }); } catch { /* Own temporaries only. */ } }
|
|
50
|
+
reportBuildCache({cache:'zstd-bytes',event:populated?'population':'write-failure',bytes:populated?bytes.byteLength:0});
|
|
51
|
+
return Uint8Array.from(bytes);
|
|
52
|
+
}
|