@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,149 @@
|
|
|
1
|
+
import { BufferAttribute, BufferGeometry, Float16BufferAttribute, type Matrix4, Vector3, type TypedArrayConstructor } from 'three';
|
|
2
|
+
|
|
3
|
+
/** Private build evidence: ordinals address the joined oracle, not a new runtime protocol. */
|
|
4
|
+
export interface SlabGeometryChunk {
|
|
5
|
+
geometry: BufferGeometry; triangles: number[]; bytes: number;
|
|
6
|
+
worldHeight: number; maxTriangleHeight: number;
|
|
7
|
+
}
|
|
8
|
+
interface Triangle { ordinal: number; corners: [number, number, number]; minY: number; maxY: number }
|
|
9
|
+
interface Bucket { quadrant: number; band: number; triangles: Triangle[]; minY: number; maxY: number }
|
|
10
|
+
|
|
11
|
+
/** Upload bytes of exactly the final native geometry, including the index width. */
|
|
12
|
+
export function slabGeometryBytes(geometry: BufferGeometry): number {
|
|
13
|
+
let bytes = geometry.index?.array.byteLength ?? 0;
|
|
14
|
+
for (const attribute of Object.values(geometry.attributes)) {
|
|
15
|
+
if (!(attribute instanceof BufferAttribute)) throw new Error('Slab geometry needs plain native channels');
|
|
16
|
+
bytes += attribute.array.byteLength;
|
|
17
|
+
}
|
|
18
|
+
return bytes;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Compare the same raw bits in native words when both owned views align.
|
|
22
|
+
* Shared, empty and unaligned views retain the original byte read order. */
|
|
23
|
+
function verifySlabChannelCopy(before: Uint8Array, after: Uint8Array, selected: readonly number[], bytes: number): void {
|
|
24
|
+
if (bytes > 0 && bytes % 4 === 0 && selected.length > 0
|
|
25
|
+
&& before.buffer instanceof ArrayBuffer && after.buffer instanceof ArrayBuffer
|
|
26
|
+
&& before.byteLength > 0 && after.byteLength > 0
|
|
27
|
+
&& before.byteOffset % 4 === 0 && after.byteOffset % 4 === 0
|
|
28
|
+
&& before.byteLength % 4 === 0 && after.byteLength % 4 === 0) {
|
|
29
|
+
const input = new Uint32Array(before.buffer, before.byteOffset, before.byteLength / 4);
|
|
30
|
+
const output = new Uint32Array(after.buffer, after.byteOffset, after.byteLength / 4);
|
|
31
|
+
const words = bytes / 4;
|
|
32
|
+
selected.forEach((vertex, at) => { for (let word = 0; word < words; word++)
|
|
33
|
+
if (input[vertex * words + word] !== output[at * words + word]) throw new Error('Slab channel copy differs'); });
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
selected.forEach((vertex, at) => { for (let byte = 0; byte < bytes; byte++)
|
|
37
|
+
if (before[vertex * bytes + byte] !== after[at * bytes + byte]) throw new Error('Slab channel copy differs'); });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function subset(source: BufferGeometry, selected: readonly number[], indices: readonly number[]): BufferGeometry {
|
|
41
|
+
const output = new BufferGeometry();
|
|
42
|
+
try {
|
|
43
|
+
for (const [name, attribute] of Object.entries(source.attributes)) {
|
|
44
|
+
if (!(attribute instanceof BufferAttribute)) throw new Error('Slab geometry needs plain native channels');
|
|
45
|
+
const Storage = attribute.array.constructor as TypedArrayConstructor;
|
|
46
|
+
const values = new Storage(selected.length * attribute.itemSize), width = attribute.itemSize;
|
|
47
|
+
selected.forEach((vertex, at) => values.set(attribute.array.subarray(vertex * width, (vertex + 1) * width), at * width));
|
|
48
|
+
const copied = attribute instanceof Float16BufferAttribute && values instanceof Uint16Array
|
|
49
|
+
? new Float16BufferAttribute(values, width, attribute.normalized) : new BufferAttribute(values, width, attribute.normalized);
|
|
50
|
+
copied.gpuType = attribute.gpuType;
|
|
51
|
+
// Check raw storage, including signed zero and raw half-float words. This is independent of numeric getters.
|
|
52
|
+
const before = new Uint8Array(attribute.array.buffer, attribute.array.byteOffset, attribute.array.byteLength);
|
|
53
|
+
const after = new Uint8Array(copied.array.buffer, copied.array.byteOffset, copied.array.byteLength);
|
|
54
|
+
const bytes = attribute.itemSize * attribute.array.BYTES_PER_ELEMENT;
|
|
55
|
+
verifySlabChannelCopy(before, after, selected, bytes);
|
|
56
|
+
output.setAttribute(name, copied);
|
|
57
|
+
}
|
|
58
|
+
output.setIndex(new BufferAttribute(selected.length > 65535 ? Uint32Array.from(indices) : Uint16Array.from(indices), 1));
|
|
59
|
+
return output;
|
|
60
|
+
} catch (error) { output.dispose(); throw error; }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Keep one chunk per tile/key while it fits; split oversized content by quadrant, then height and bytes.
|
|
64
|
+
* A resident cell packs in source order across tiles, splitting only at the byte cap.
|
|
65
|
+
* A tall original triangle is never split.
|
|
66
|
+
* Displacements and normals have already passed through the original whole-piece join's exact transform order. */
|
|
67
|
+
export function partitionSlabGeometry(source: BufferGeometry, tile: number, world: Matrix4, maximumBytes = 4_000_000, residentCell = false): SlabGeometryChunk[] {
|
|
68
|
+
if (!Number.isInteger(tile) || tile < 0 || tile > 63 || !Number.isSafeInteger(maximumBytes) || maximumBytes < 1 || maximumBytes > 4_000_000
|
|
69
|
+
|| world.elements.some(value => !Number.isFinite(value))) throw new Error('Invalid slab partition budget or tile');
|
|
70
|
+
const position = source.getAttribute('position'), index = source.index;
|
|
71
|
+
if (!(position instanceof BufferAttribute) || position.itemSize !== 3 || position.normalized || !(position.array instanceof Float32Array)
|
|
72
|
+
|| Object.keys(source.morphAttributes).length > 0 || source.groups.length > 0) throw new Error('Slab needs rigid float32 positions');
|
|
73
|
+
const count = index?.count ?? position.count;
|
|
74
|
+
if (count % 3 !== 0) throw new Error('Slab needs complete triangles');
|
|
75
|
+
let stride = 0;
|
|
76
|
+
for (const attribute of Object.values(source.attributes)) {
|
|
77
|
+
if (!(attribute instanceof BufferAttribute) || attribute.count !== position.count) throw new Error('Slab channel layout differs');
|
|
78
|
+
stride += attribute.itemSize * attribute.array.BYTES_PER_ELEMENT;
|
|
79
|
+
}
|
|
80
|
+
const x0 = -250 + tile % 8 * 62.5, z0 = -250 + Math.floor(tile / 8) * 62.5;
|
|
81
|
+
const buckets = new Map<string, Bucket>(), point = new Vector3();
|
|
82
|
+
for (let offset = 0; offset < count; offset += 3) {
|
|
83
|
+
const a = index?.getX(offset) ?? offset, b = index?.getX(offset + 1) ?? offset + 1, c = index?.getX(offset + 2) ?? offset + 2;
|
|
84
|
+
if (![a, b, c].every(vertex => Number.isInteger(vertex) && vertex >= 0 && vertex < position.count)) throw new Error('Slab index outside source');
|
|
85
|
+
let x = 0, z = 0, y = 0, minY = Infinity, maxY = -Infinity;
|
|
86
|
+
for (const vertex of [a, b, c]) {
|
|
87
|
+
point.fromBufferAttribute(position, vertex).applyMatrix4(world);
|
|
88
|
+
if (![point.x, point.y, point.z].every(Number.isFinite)) throw new Error('Slab position is not finite');
|
|
89
|
+
x += point.x / 3; y += point.y / 3; z += point.z / 3; minY = Math.min(minY, point.y); maxY = Math.max(maxY, point.y);
|
|
90
|
+
}
|
|
91
|
+
const quadrant = (z >= z0 + 31.25 ? 2 : 0) + (x >= x0 + 31.25 ? 1 : 0), band = Math.floor(y / 62.5), key = `${quadrant}:${band}`;
|
|
92
|
+
const bucket = buckets.get(key) ?? { quadrant, band, triangles: [], minY: Infinity, maxY: -Infinity };
|
|
93
|
+
bucket.triangles.push({ ordinal: offset / 3, corners: [a, b, c], minY, maxY });
|
|
94
|
+
bucket.minY = Math.min(bucket.minY, minY); bucket.maxY = Math.max(bucket.maxY, maxY); buckets.set(key, bucket);
|
|
95
|
+
}
|
|
96
|
+
const byteCost = (triangles: readonly Triangle[]): number => {
|
|
97
|
+
const vertices = new Set<number>(); for (const triangle of triangles) for (const vertex of triangle.corners) vertices.add(vertex);
|
|
98
|
+
return vertices.size * stride + triangles.length * 3 * (vertices.size > 65535 ? 4 : 2);
|
|
99
|
+
};
|
|
100
|
+
const bands = [...buckets.values()].sort((a, b) => a.quadrant - b.quadrant || a.band - b.band), all = bands.flatMap(bucket => bucket.triangles).sort((a, b) => a.ordinal - b.ordinal);
|
|
101
|
+
const combined = (triangles: Triangle[], quadrant: number): Bucket => ({ quadrant, band: 0, triangles,
|
|
102
|
+
minY: triangles.reduce((value, triangle) => Math.min(value, triangle.minY), Infinity), maxY: triangles.reduce((value, triangle) => Math.max(value, triangle.maxY), -Infinity) });
|
|
103
|
+
const groups: Bucket[] = [];
|
|
104
|
+
if (residentCell || byteCost(all) <= maximumBytes) groups.push(combined(all, 0));
|
|
105
|
+
else for (const quadrant of [0, 1, 2, 3]) {
|
|
106
|
+
const rows = bands.filter(bucket => bucket.quadrant === quadrant), triangles = rows.flatMap(bucket => bucket.triangles).sort((a, b) => a.ordinal - b.ordinal);
|
|
107
|
+
if (triangles.length === 0) continue;
|
|
108
|
+
if (byteCost(triangles) <= maximumBytes) { groups.push(combined(triangles, quadrant)); continue; }
|
|
109
|
+
// Height is a split axis for oversized content, never a reason to create many tiny draws.
|
|
110
|
+
let previous: Bucket | undefined;
|
|
111
|
+
for (const bucket of rows) {
|
|
112
|
+
if (previous !== undefined && byteCost([...previous.triangles, ...bucket.triangles]) <= maximumBytes) {
|
|
113
|
+
for (const triangle of bucket.triangles) previous.triangles.push(triangle);
|
|
114
|
+
previous.minY = Math.min(previous.minY, bucket.minY); previous.maxY = Math.max(previous.maxY, bucket.maxY);
|
|
115
|
+
} else { groups.push(bucket); previous = bucket; }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const chunks: SlabGeometryChunk[] = [], covered = new Uint8Array(count / 3);
|
|
119
|
+
try {
|
|
120
|
+
for (const group of groups) {
|
|
121
|
+
let vertices: number[] = [], corners: number[] = [], triangles: number[] = [], remap = new Map<number, number>();
|
|
122
|
+
let minY = Infinity, maxY = -Infinity, maxTriangleHeight = 0;
|
|
123
|
+
const flush = (): void => {
|
|
124
|
+
if (triangles.length === 0) return;
|
|
125
|
+
const geometry = subset(source, vertices, corners), bytes = slabGeometryBytes(geometry);
|
|
126
|
+
if (bytes > maximumBytes) { geometry.dispose(); throw new Error('Slab upload exceeds budget'); }
|
|
127
|
+
for (const triangle of triangles) { if (covered[triangle] !== 0) { geometry.dispose(); throw new Error('Slab triangle appears twice'); } covered[triangle] = 1; }
|
|
128
|
+
geometry.computeBoundingBox(); geometry.computeBoundingSphere();
|
|
129
|
+
chunks.push({ geometry, triangles, bytes, worldHeight: maxY - minY, maxTriangleHeight });
|
|
130
|
+
vertices = []; corners = []; triangles = []; remap = new Map(); minY = Infinity; maxY = -Infinity; maxTriangleHeight = 0;
|
|
131
|
+
};
|
|
132
|
+
for (const triangle of group.triangles) {
|
|
133
|
+
const added = new Set(triangle.corners.filter(vertex => !remap.has(vertex))).size, vertexCount = vertices.length + added;
|
|
134
|
+
const bytes = vertexCount * stride + (corners.length + 3) * (vertexCount > 65535 ? 4 : 2);
|
|
135
|
+
if (triangles.length > 0 && bytes > maximumBytes) flush();
|
|
136
|
+
for (const vertex of triangle.corners) {
|
|
137
|
+
let local = remap.get(vertex);
|
|
138
|
+
if (local === undefined) { local = vertices.length; vertices.push(vertex); remap.set(vertex, local); }
|
|
139
|
+
corners.push(local);
|
|
140
|
+
}
|
|
141
|
+
triangles.push(triangle.ordinal); minY = Math.min(minY, triangle.minY); maxY = Math.max(maxY, triangle.maxY);
|
|
142
|
+
maxTriangleHeight = Math.max(maxTriangleHeight, triangle.maxY - triangle.minY);
|
|
143
|
+
}
|
|
144
|
+
flush();
|
|
145
|
+
}
|
|
146
|
+
if (covered.some(value => value !== 1)) throw new Error('Slab partition omits a source triangle');
|
|
147
|
+
return chunks;
|
|
148
|
+
} catch (error) { for (const chunk of chunks) chunk.geometry.dispose(); throw error; }
|
|
149
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { BufferAttribute, type BufferGeometry, Float16BufferAttribute, Group, Matrix4, Mesh, MeshStandardMaterial, Vector3, type Object3D } from 'three';
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
import { mergeGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
4
|
+
import { NativeAttributesSchema } from '@wildshard/engine/models/nativeGeometry';
|
|
5
|
+
import { wholeGeometryPieces } from '@wildshard/engine/game/shardfile/wholeGeometryPieces';
|
|
6
|
+
import type { WholeGeometryPiece } from '@wildshard/engine/game/plugin/geometry';
|
|
7
|
+
import { joinWholePieceSteps } from './wholePieceJoin';
|
|
8
|
+
import { WorldSceneSlabsSchema, type WorldSceneSlabChunk, type WorldSceneSlabFile, type WorldSceneSlabKey, type WorldSceneSlabLibrary } from '@wildshard/format/worldSceneSlabs';
|
|
9
|
+
import { parseWorldSceneWeld, type WorldSceneWeld, type WorldSceneWeldNode } from '@wildshard/format/worldSceneWeld';
|
|
10
|
+
import type { WorldScenesSection } from '@wildshard/format/worldScenes';
|
|
11
|
+
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
12
|
+
import { prepareGlbBuffers } from '@wildshard/format/glbBuffers';
|
|
13
|
+
import { hashImmutableBytes } from '../immutable';
|
|
14
|
+
import { staticGlb, type GlbPrimitive } from './glb';
|
|
15
|
+
import { compressGlb } from './glbCompression';
|
|
16
|
+
import { parseGlb } from '../assets';
|
|
17
|
+
import { readSourceModel } from './skinned';
|
|
18
|
+
import { positionErrorScale } from './geometryError';
|
|
19
|
+
import { partitionSlabGeometry, type SlabGeometryChunk } from './slabChunks';
|
|
20
|
+
|
|
21
|
+
// Every native slab mounts as one identity instance with a white RGB colour.
|
|
22
|
+
// Its first draw uploads those two native attributes as well as the geometry.
|
|
23
|
+
const INSTANCE_UPLOAD_BYTES = (16 + 3) * Float32Array.BYTES_PER_ELEMENT;
|
|
24
|
+
const GEOMETRY_UPLOAD_BYTES = 4_000_000 - INSTANCE_UPLOAD_BYTES;
|
|
25
|
+
|
|
26
|
+
type WholeLibrary = Exclude<Extract<WorldScenesSection['libraries'][number], { kind: 'whole' }>, { storage: 'slabs' }>;
|
|
27
|
+
type Draw = Extract<WorldSceneWeldNode, { kind: 'mesh' }>;
|
|
28
|
+
interface Source { node: Draw; model: WholeLibrary['models'][number]; forceIdentity: boolean; frame: Matrix4; owners: readonly string[] }
|
|
29
|
+
interface Chunk { key: WorldSceneSlabKey; part: SlabGeometryChunk; custom: Readonly<Record<string, string>>; error: number }
|
|
30
|
+
interface GroupedKey { key: WorldSceneSlabKey; signature: string }
|
|
31
|
+
/** Actual partition and upload census. Oversized height is explained by an unchanged source triangle, never a clipped one. */
|
|
32
|
+
export interface SlabBakeTileReport {
|
|
33
|
+
tile: number; sourceTriangles: number; triangles: number; chunks: number; files: number; bytes: number;
|
|
34
|
+
maxHeight: number; maxTriangleHeight: number;
|
|
35
|
+
}
|
|
36
|
+
/** New staged data only; callers keep the original whole library and every existing asset unchanged. */
|
|
37
|
+
export interface WholeSlabBake {
|
|
38
|
+
library: WorldSceneSlabLibrary; assets: ReadonlyMap<string, Uint8Array>; report: readonly SlabBakeTileReport[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function matrixWords(matrix: Matrix4): number[] { return Array.from(new Uint32Array(Float64Array.from(matrix.elements).buffer)); }
|
|
42
|
+
function anchorFrames(weld: WorldSceneWeld): ReadonlyMap<string, Matrix4> {
|
|
43
|
+
const nodes = new Map(weld.nodes.map(node => [node.id, node])), frames = new Map<string, Matrix4>([[weld.root, new Matrix4()]]), active = new Set<string>();
|
|
44
|
+
const frame = (id: string): Matrix4 => {
|
|
45
|
+
const known = frames.get(id); if (known !== undefined) return known;
|
|
46
|
+
const row = nodes.get(id); if (row === undefined || active.has(id)) throw new Error('Slab anchor has an unknown or cyclic parent');
|
|
47
|
+
active.add(id);
|
|
48
|
+
const object = new Group(); object.matrixAutoUpdate = row.matrixAutoUpdate;
|
|
49
|
+
if (row.transformBits !== undefined) {
|
|
50
|
+
const values = new Float64Array(Uint32Array.from(row.transformBits).buffer);
|
|
51
|
+
object.position.fromArray(values); object.quaternion.fromArray(values, 3); object.scale.fromArray(values, 7);
|
|
52
|
+
}
|
|
53
|
+
if (row.matrixBits !== undefined) object.matrix.fromArray(new Float64Array(Uint32Array.from(row.matrixBits).buffer));
|
|
54
|
+
if (object.matrixAutoUpdate) object.updateMatrix();
|
|
55
|
+
const world = frame(row.parent).clone().multiply(object.matrix); frames.set(id, world); active.delete(id); return world;
|
|
56
|
+
};
|
|
57
|
+
for (const row of weld.nodes) frame(row.id);
|
|
58
|
+
return frames;
|
|
59
|
+
}
|
|
60
|
+
function sources(library: WholeLibrary, weld: WorldSceneWeld): Source[] {
|
|
61
|
+
if (library.load !== 'refine') throw new Error('Slabs require a fine whole library');
|
|
62
|
+
const frames = anchorFrames(weld), models = new Map(library.models.map(model => [model.id, model])), nodes = new Map(weld.nodes.map(node => [node.id, node]));
|
|
63
|
+
const handed = new Set<string>(), transforms = new Map<string, boolean>(), output: Source[] = [];
|
|
64
|
+
for (const node of weld.nodes) if ('geometry' in node && node.geometry.library === library.id) {
|
|
65
|
+
if (node.kind !== 'mesh') throw new Error('Slabs require plain static refine anchors');
|
|
66
|
+
const model = models.get(node.geometry.model), frame = frames.get(node.id);
|
|
67
|
+
if (model === undefined || frame === undefined) throw new Error('Slab anchor omits its whole model');
|
|
68
|
+
let forceIdentity = transforms.get(model.id);
|
|
69
|
+
if (forceIdentity === undefined) { forceIdentity = handed.has(model.part); transforms.set(model.id, forceIdentity); handed.add(model.part); }
|
|
70
|
+
const ancestors = new Set<string>([node.id]); let parent = node.parent;
|
|
71
|
+
while (parent !== weld.root) {
|
|
72
|
+
const ancestor = nodes.get(parent); if (ancestor === undefined || ancestors.has(parent)) throw new Error('Slab anchor has an unknown or cyclic owner');
|
|
73
|
+
ancestors.add(parent); parent = ancestor.parent;
|
|
74
|
+
}
|
|
75
|
+
// Equal poses alone do not make independently culled or hidden anchors interchangeable.
|
|
76
|
+
// Keep the original parent and each cull-root slot, including its original distance origin.
|
|
77
|
+
const owners = [node.parent, ...weld.culls.flatMap((cull, cullIndex) => cull.roots.flatMap((root, origin) => ancestors.has(root) ? [`${cullIndex}:${origin}`] : []))];
|
|
78
|
+
output.push({ node, model, frame, forceIdentity, owners });
|
|
79
|
+
}
|
|
80
|
+
if (output.length === 0) throw new Error('Slabs require a covered fine draw');
|
|
81
|
+
return output;
|
|
82
|
+
}
|
|
83
|
+
function drawKey(source: Source, id: string): WorldSceneSlabKey {
|
|
84
|
+
const row = source.node;
|
|
85
|
+
return { id, node: row.id, material: row.material, castShadow: row.castShadow, receiveShadow: row.receiveShadow,
|
|
86
|
+
...(row.castFrom === undefined ? {} : { castFrom: row.castFrom }), ...(row.until === undefined ? {} : { until: row.until }),
|
|
87
|
+
renderOrder: row.renderOrder, layers: row.layers, frustumCulled: row.frustumCulled, visible: row.visible, sources: [source.model.id] };
|
|
88
|
+
}
|
|
89
|
+
function compatibleSignature(source: Source, geometry: BufferGeometry, custom: Readonly<Record<string, string>>): string {
|
|
90
|
+
const { id: _id, node: _node, sources: _sources, ...key } = drawKey(source, 'key');
|
|
91
|
+
return JSON.stringify([key, source.owners, matrixWords(source.frame), geometry.index !== null, Object.entries(geometry.attributes).map(([name, attribute]) => [name,
|
|
92
|
+
attribute.array.constructor.name, attribute.constructor.name, attribute.itemSize, attribute.normalized, attribute instanceof BufferAttribute ? attribute.gpuType : null]), custom]);
|
|
93
|
+
}
|
|
94
|
+
function joined(pieces: readonly WholeGeometryPiece[], source: Source): BufferGeometry {
|
|
95
|
+
const steps = joinWholePieceSteps(pieces, source.model.matrix, source.forceIdentity);
|
|
96
|
+
for (;;) { const next = steps.next(); if (next.done) { if (next.value === undefined) throw new Error('Slab join did not complete'); return next.value; } }
|
|
97
|
+
}
|
|
98
|
+
function concatenate(geometries: readonly BufferGeometry[]): BufferGeometry {
|
|
99
|
+
const first = geometries[0]; if (first === undefined) throw new Error('Slab key has no geometry');
|
|
100
|
+
const mergedGeometry = mergeGeometries([...geometries], false);
|
|
101
|
+
if (mergedGeometry === null) throw new Error('Slab key channel layout differs');
|
|
102
|
+
// Three's merger preserves raw words but drops the half-float attribute class.
|
|
103
|
+
for (const [name, attribute] of Object.entries(first.attributes)) if (attribute instanceof Float16BufferAttribute) {
|
|
104
|
+
const merged = mergedGeometry.getAttribute(name);
|
|
105
|
+
if (!(merged instanceof BufferAttribute) || !(merged.array instanceof Uint16Array)) { mergedGeometry.dispose(); throw new Error('Slab half storage differs'); }
|
|
106
|
+
const half = new Float16BufferAttribute(merged.array, merged.itemSize, merged.normalized); half.gpuType = attribute.gpuType; mergedGeometry.setAttribute(name, half);
|
|
107
|
+
}
|
|
108
|
+
return mergedGeometry;
|
|
109
|
+
}
|
|
110
|
+
function joinError(pieces: readonly WholeGeometryPiece[], source: Source, tileError: number): number {
|
|
111
|
+
const pose = source.model.matrix === undefined ? undefined : new Matrix4().fromArray(source.model.matrix), scale = pose === undefined ? 1 : positionErrorScale(pose);
|
|
112
|
+
let maximum = 0;
|
|
113
|
+
const identity = new Matrix4(), point = new Vector3();
|
|
114
|
+
for (const piece of pieces) {
|
|
115
|
+
const position = piece.geometry.getAttribute('position');
|
|
116
|
+
for (let vertex = 0; vertex < position.count; vertex++) {
|
|
117
|
+
point.fromBufferAttribute(position, vertex); let error = 0;
|
|
118
|
+
if (source.forceIdentity || pose !== undefined || !piece.matrix.equals(identity)) {
|
|
119
|
+
point.applyMatrix4(piece.matrix);
|
|
120
|
+
error = Math.hypot(point.x - Math.fround(point.x), point.y - Math.fround(point.y), point.z - Math.fround(point.z));
|
|
121
|
+
point.set(Math.fround(point.x), Math.fround(point.y), Math.fround(point.z));
|
|
122
|
+
}
|
|
123
|
+
if (pose !== undefined) {
|
|
124
|
+
point.applyMatrix4(pose);
|
|
125
|
+
error = error * scale + Math.hypot(point.x - Math.fround(point.x), point.y - Math.fround(point.y), point.z - Math.fround(point.z));
|
|
126
|
+
}
|
|
127
|
+
maximum = Math.max(maximum, error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return (tileError * scale + maximum) * positionErrorScale(source.frame);
|
|
131
|
+
}
|
|
132
|
+
function isMesh(node: Object3D): node is Mesh { return node instanceof Mesh; }
|
|
133
|
+
async function decode(bytes: Uint8Array): Promise<WholeGeometryPiece[]> {
|
|
134
|
+
const { gltf } = await readSourceModel(bytes), meshes: Mesh[] = [];
|
|
135
|
+
gltf.scene.traverse(node => { if (isMesh(node)) meshes.push(node); });
|
|
136
|
+
try { return wholeGeometryPieces(meshes); }
|
|
137
|
+
finally {
|
|
138
|
+
const geometry = new Set(meshes.map(mesh => mesh.geometry)), materials = new Set(meshes.flatMap(mesh => [mesh.material].flat()));
|
|
139
|
+
for (const item of geometry) item.dispose(); for (const material of materials) material.dispose();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function options(chunk: Chunk, tile: number, index: number): GlbPrimitive {
|
|
143
|
+
const geometry = chunk.part.geometry, normal = geometry.getAttribute('normal'), colour = geometry.getAttribute('color');
|
|
144
|
+
const quantized = (normal === undefined || normal instanceof BufferAttribute && normal.itemSize === 3 && normal.array instanceof Int8Array && normal.normalized)
|
|
145
|
+
&& (colour === undefined || colour instanceof BufferAttribute && (colour.array instanceof Uint8Array || colour.array instanceof Uint16Array) && colour.normalized);
|
|
146
|
+
// named as its key's material: a product with props.materials admits only named GLB materials (the runtime draws a chunk with
|
|
147
|
+
// its anchor's material, never this one)
|
|
148
|
+
const material = new MeshStandardMaterial({ color: 0xffffff, vertexColors: true, roughness: 1, metalness: 0 }); material.name = chunk.key.material;
|
|
149
|
+
return { geometry, material, name: `${chunk.key.id}-chunk_${index}`, castShadow: chunk.key.castShadow, customAttributes: chunk.custom,
|
|
150
|
+
nativeAttributes: true, nativeOnce: true, compactIndex: true, ...(quantized ? { quantizedChannels: true } : {}),
|
|
151
|
+
extras: { slab: { key: chunk.key.id, tile, chunk: index } } };
|
|
152
|
+
}
|
|
153
|
+
function chunkRow(chunk: Chunk): WorldSceneSlabChunk {
|
|
154
|
+
const box = chunk.part.geometry.boundingBox, sphere = chunk.part.geometry.boundingSphere;
|
|
155
|
+
if (box === null || sphere === null) throw new Error('Slab chunk omits its frozen bounds');
|
|
156
|
+
for (const point of [box.min, box.max]) if (![point.x, point.y, point.z].every(Number.isFinite)) throw new Error('Invalid slab chunk bounds');
|
|
157
|
+
return { key: chunk.key.id, bytes: chunk.part.bytes, geometricError: chunk.error,
|
|
158
|
+
box: [box.min.x, box.min.y, box.min.z, box.max.x, box.max.y, box.max.z], sphere: [sphere.center.x, sphere.center.y, sphere.center.z, sphere.radius] };
|
|
159
|
+
}
|
|
160
|
+
function encodeFiles(tile: number, chunks: readonly Chunk[], assets: Map<string, Uint8Array>): WorldSceneSlabFile[] {
|
|
161
|
+
const result: WorldSceneSlabFile[] = [];
|
|
162
|
+
const emit = (rows: readonly Chunk[]): void => {
|
|
163
|
+
const primitives = rows.map((chunk, index) => options(chunk, tile, index));
|
|
164
|
+
let bytes: Uint8Array;
|
|
165
|
+
try { bytes = staticGlb(primitives, `slab_tile_${tile}`); }
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (!(error instanceof Error) || !['GLB resource cap', 'invalid GLB header'].includes(error.message) || rows.length < 2) throw error;
|
|
168
|
+
const mid = Math.floor(rows.length / 2); emit(rows.slice(0, mid)); emit(rows.slice(mid)); return;
|
|
169
|
+
} finally { for (const primitive of primitives) primitive.material.dispose(); }
|
|
170
|
+
const packed = compressGlb(bytes);
|
|
171
|
+
if (packed.length < bytes.length) {
|
|
172
|
+
try { parseGlb(packed); bytes = packed; }
|
|
173
|
+
catch (error) { if (!(error instanceof Error) || error.message !== 'GLB resource cap') throw error; }
|
|
174
|
+
}
|
|
175
|
+
parseGlb(bytes);
|
|
176
|
+
const hash = hashImmutableBytes(bytes); assets.set(hash, bytes);
|
|
177
|
+
result.push({ file: hash, chunks: rows.map(chunkRow) });
|
|
178
|
+
};
|
|
179
|
+
let batch: Chunk[] = [], bytes = 0;
|
|
180
|
+
for (const chunk of chunks) {
|
|
181
|
+
if (batch.length > 0 && bytes + chunk.part.bytes > 12_000_000) { emit(batch); batch = []; bytes = 0; }
|
|
182
|
+
batch.push(chunk); bytes += chunk.part.bytes;
|
|
183
|
+
}
|
|
184
|
+
if (batch.length > 0) emit(batch);
|
|
185
|
+
if (result.length > 16) throw new Error('Slab tile exceeds its file budget');
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Validate cached slab metadata through its defining bounded grammar; author folders need no format/parser imports. */
|
|
190
|
+
export function readSlabLibrary(bytes: Uint8Array): WorldSceneSlabLibrary {
|
|
191
|
+
return v.parse(WorldSceneSlabsSchema, JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Prejoin the declared fine whole pieces in their original draw frames. The runtime is not activated by this writer.
|
|
195
|
+
* Every source triangle is charged once; attribute copies are bit-checked before files enter the returned map. */
|
|
196
|
+
export async function bakeWholeSlabs(input: {
|
|
197
|
+
readonly id: string; readonly library: WholeLibrary; readonly weld: unknown;
|
|
198
|
+
readonly shardfile: Pick<Shardfile, 'tiles' | 'files' | 'ring'>; readonly assets: ReadonlyMap<string, Uint8Array>;
|
|
199
|
+
}): Promise<WholeSlabBake> {
|
|
200
|
+
await prepareGlbBuffers();
|
|
201
|
+
const weld = parseWorldSceneWeld(input.weld), draws = sources(input.library, weld), keys: GroupedKey[] = [], assets = new Map<string, Uint8Array>();
|
|
202
|
+
const sourceKeys = new Map<string, WorldSceneSlabKey>(), output: WorldSceneSlabLibrary['tiles'] = [], report: SlabBakeTileReport[] = [];
|
|
203
|
+
const wanted = new Set(draws.flatMap(source => source.model.files)), declared = new Map(input.shardfile.files.map(file => [file.hash, file]));
|
|
204
|
+
const available = new Set(input.shardfile.tiles.filter(tile => tile.lod === 0).flatMap(tile => tile.files));
|
|
205
|
+
for (const hash of wanted) if (!available.has(hash) || declared.get(hash)?.kind !== 'glb') throw new Error('Slab source needs a declared fine GLB');
|
|
206
|
+
const fine = [...input.shardfile.tiles].filter(row => row.lod === 0 && row.files.some(hash => wanted.has(hash))).sort((a, b) => a.z - b.z || a.x - b.x);
|
|
207
|
+
const owner = fine[0], cell = input.shardfile.ring === 'cell';
|
|
208
|
+
// A resident cell retains the lowest owned tile from every viewing position. Ring worlds keep their individual
|
|
209
|
+
// tile owners; grouping those would retire geometry still needed by another tile.
|
|
210
|
+
const partitions = cell && owner !== undefined ? [{ ...owner, files: [...new Set(fine.flatMap(tile => tile.files))],
|
|
211
|
+
geometricError: Math.max(...fine.map(tile => tile.geometricError)) }] : fine;
|
|
212
|
+
for (const tile of partitions) {
|
|
213
|
+
const files = tile.files.filter(hash => wanted.has(hash)); if (files.length === 0) continue;
|
|
214
|
+
const pieces = new Map<string, readonly WholeGeometryPiece[]>(), staging: WholeGeometryPiece[] = [], chunks: Chunk[] = [];
|
|
215
|
+
const groups = new Map<string, { key: WorldSceneSlabKey; geometries: BufferGeometry[]; frame: Matrix4; custom: Readonly<Record<string, string>>; error: number }>();
|
|
216
|
+
let sourceTriangles = 0;
|
|
217
|
+
try {
|
|
218
|
+
for (const hash of files) {
|
|
219
|
+
const bytes = input.assets.get(hash), file = declared.get(hash);
|
|
220
|
+
if (bytes === undefined || file === undefined || bytes.length !== file.compressed || hashImmutableBytes(bytes) !== hash) throw new Error('Slab source bytes differ');
|
|
221
|
+
const read = await decode(bytes); pieces.set(hash, read); staging.push(...read);
|
|
222
|
+
}
|
|
223
|
+
for (const source of draws) {
|
|
224
|
+
const selected = source.model.files.flatMap(hash => pieces.get(hash) ?? []).filter(piece => piece.part === source.model.part);
|
|
225
|
+
if (selected.length === 0) { if (source.model.files.some(hash => files.includes(hash))) throw new Error('Slab source file omits its declared part'); continue; }
|
|
226
|
+
const geometry = joined(selected, source);
|
|
227
|
+
try {
|
|
228
|
+
const first = selected[0]; if (first === undefined) throw new Error('Slab source has no channels');
|
|
229
|
+
const channels = v.parse(NativeAttributesSchema, JSON.parse(first.layout));
|
|
230
|
+
const custom = Object.fromEntries(Object.entries(channels).filter(([name]) => !['position', 'normal', 'color', 'uv', 'uv1', 'tangent'].includes(name)).map(([name, row]) => [row.semantic, name]));
|
|
231
|
+
let key = sourceKeys.get(source.node.id);
|
|
232
|
+
if (key === undefined) {
|
|
233
|
+
const signature = compatibleSignature(source, geometry, custom), known = keys.find(entry => entry.signature === signature && !entry.key.sources.includes(source.model.id));
|
|
234
|
+
if (known === undefined) { key = drawKey(source, `k${keys.length}`); keys.push({ key, signature }); }
|
|
235
|
+
else { key = known.key; key.sources.push(source.model.id); }
|
|
236
|
+
sourceKeys.set(source.node.id, key);
|
|
237
|
+
}
|
|
238
|
+
const signature = compatibleSignature(source, geometry, custom);
|
|
239
|
+
if (!keys.some(entry => entry.key === key && entry.signature === signature)) throw new Error('Slab draw key differs between tiles');
|
|
240
|
+
const count = (geometry.index?.count ?? geometry.getAttribute('position').count) / 3;
|
|
241
|
+
sourceTriangles += count;
|
|
242
|
+
const error = joinError(selected, source, tile.geometricError), group = groups.get(key.id);
|
|
243
|
+
if (group === undefined) groups.set(key.id, { key, geometries: [geometry], frame: source.frame, custom, error });
|
|
244
|
+
else { group.geometries.push(geometry); group.error = Math.max(group.error, error); }
|
|
245
|
+
} catch (error) { geometry.dispose(); throw error; }
|
|
246
|
+
}
|
|
247
|
+
for (const group of groups.values()) {
|
|
248
|
+
const geometry = concatenate(group.geometries);
|
|
249
|
+
try {
|
|
250
|
+
for (const part of partitionSlabGeometry(geometry, tile.z * 8 + tile.x, group.frame, GEOMETRY_UPLOAD_BYTES, cell)) chunks.push({ key: group.key, part, custom: group.custom, error: group.error });
|
|
251
|
+
} finally { geometry.dispose(); }
|
|
252
|
+
}
|
|
253
|
+
if (chunks.length === 0 || chunks.length > 64) throw new Error('Slab tile exceeds its chunk budget');
|
|
254
|
+
const triangles = chunks.reduce((sum, chunk) => sum + chunk.part.triangles.length, 0);
|
|
255
|
+
if (triangles !== sourceTriangles) throw new Error('Slab triangle partition differs');
|
|
256
|
+
const packed = encodeFiles(tile.z * 8 + tile.x, chunks, assets); output.push({ tile: tile.z * 8 + tile.x, files: packed });
|
|
257
|
+
report.push({ tile: tile.z * 8 + tile.x, sourceTriangles, triangles, chunks: chunks.length, files: packed.length,
|
|
258
|
+
bytes: chunks.reduce((sum, chunk) => sum + chunk.part.bytes, 0), maxHeight: Math.max(...chunks.map(chunk => chunk.part.worldHeight)), maxTriangleHeight: Math.max(...chunks.map(chunk => chunk.part.maxTriangleHeight)) });
|
|
259
|
+
} finally { for (const piece of staging) piece.geometry.dispose(); for (const group of groups.values()) for (const geometry of group.geometries) geometry.dispose(); for (const chunk of chunks) chunk.part.geometry.dispose(); }
|
|
260
|
+
}
|
|
261
|
+
const library = v.parse(WorldSceneSlabsSchema, { id: input.id, kind: 'slabs', of: input.library.id, keys: keys.map(entry => entry.key), tiles: output });
|
|
262
|
+
return { library, assets, report };
|
|
263
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Node authoring resolution only: no app identity, service installers, simulation bindings or browser shims.
|
|
2
|
+
import '@wildshard/engine/scripts/format-hook.mjs';
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The authoring CLI installs only Node source resolution.
|
|
4
|
+
import { registerHooks } from 'node:module';
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Resolve regular files in the isolated authoring tree.
|
|
6
|
+
import { existsSync, statSync } from 'node:fs';
|
|
7
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Confine recipe imports to their source tree.
|
|
8
|
+
import { relative, resolve, sep } from 'node:path';
|
|
9
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Inspect resolved module URLs before loading source.
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The generator argument identifies its single shard owner.
|
|
12
|
+
import process from 'node:process';
|
|
13
|
+
|
|
14
|
+
const root = process.cwd(); // P4: the shard repo. A tool in an installed package passes the /node_modules/ rule below.
|
|
15
|
+
// Node normalises the script argument to an absolute path before preloads run.
|
|
16
|
+
const script = process.argv.at(1);
|
|
17
|
+
const driver = script === undefined ? '' : relative(root, resolve(script)).split(sep).join('/');
|
|
18
|
+
// Confined SDK drivers name their source explicitly; direct producers own their script path.
|
|
19
|
+
const source = /src\/sharddev\/bake\/(?:navigation-)?json\.mjs$/u.test(driver) ? process.argv.at(2) : script;
|
|
20
|
+
const candidate = source === undefined ? '' : relative(root, resolve(source)).split(sep).join('/');
|
|
21
|
+
const entry = /^src\/shards\/[^/]+\/generators\//u.test(candidate) ? candidate : undefined;
|
|
22
|
+
const shard = entry?.split('/')[2];
|
|
23
|
+
if (shard === undefined) throw new Error('Authoring loader requires an explicit shard-owned generator');
|
|
24
|
+
const folders = new Set(['generators', 'data', 'quests', 'blender', 'assets', 'behaviour']);
|
|
25
|
+
|
|
26
|
+
/** Refuse even computed imports into trusted code after Node resolves workspace links. @param {string} url */
|
|
27
|
+
function authoringOnly(url) {
|
|
28
|
+
if (!url.startsWith('file:')) return;
|
|
29
|
+
const file = relative(root, fileURLToPath(url)).split(sep).join('/');
|
|
30
|
+
if (file.startsWith('../') && !file.includes('/node_modules/')) throw new Error(`Authoring dependency escapes the source tree: ${file}`);
|
|
31
|
+
if (!file.startsWith('src/')) return; // Node and installed third-party dependencies are build infrastructure.
|
|
32
|
+
const parts = file.split('/'), layer = parts[1];
|
|
33
|
+
if (parts.includes('runtime') || parts.some(part => part.endsWith('-legacy')) ||
|
|
34
|
+
(layer === 'shards' ? parts[2] !== shard || !folders.has(parts[3]) : !['sdk', 'sharddev', 'commons', 'format'].includes(layer))) {
|
|
35
|
+
throw new Error(`Non-authoring dependency refused: ${file}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
registerHooks({
|
|
40
|
+
resolve(specifier, context, next) {
|
|
41
|
+
if (specifier.startsWith('.') && context.parentURL?.startsWith('file:')) {
|
|
42
|
+
const base = new URL(specifier, context.parentURL);
|
|
43
|
+
for (const suffix of ['', '.ts', '.mjs', '.js']) {
|
|
44
|
+
const url = new URL(base.href + suffix);
|
|
45
|
+
if (existsSync(fileURLToPath(url)) && statSync(fileURLToPath(url)).isFile()) {
|
|
46
|
+
authoringOnly(url.href);
|
|
47
|
+
return { url: url.href, shortCircuit: true };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const result = next(specifier, context);
|
|
52
|
+
authoringOnly(result.url);
|
|
53
|
+
return result;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import type { NamedBlobKind } from '../blobs';
|
|
3
|
+
|
|
4
|
+
/** Cached author metadata, prior to actual byte/cost admission by nameBlob. */
|
|
5
|
+
export interface CachedBlobSource<K extends NamedBlobKind> {
|
|
6
|
+
name: string;
|
|
7
|
+
kind: K;
|
|
8
|
+
source: string;
|
|
9
|
+
options: { decoded: number; gpu: number; triangles: number; draws: number; critical: boolean; dependencies: string[] };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Re-admit owned cached metadata for an explicit set of file kinds.
|
|
13
|
+
* The envelope strips unrelated cache fields; rows/options reject unknown fields
|
|
14
|
+
* unless an earlier cache stage explicitly requests native stripping.
|
|
15
|
+
* Costs keep the recording grammar; nameBlob validates their actual byte claims. */
|
|
16
|
+
export function cachedBlobSources<const K extends readonly NamedBlobKind[]>(input: unknown, kinds: K, unknownFields: 'reject' | 'strip' = 'reject'): CachedBlobSource<K[number]>[] {
|
|
17
|
+
const costs = { decoded: v.number(), gpu: v.number(), triangles: v.number(), draws: v.number(),
|
|
18
|
+
critical: v.boolean(), dependencies: v.array(v.string()) };
|
|
19
|
+
const fields = { name: v.string(), kind: v.picklist(kinds), source: v.string(),
|
|
20
|
+
options: unknownFields === 'strip' ? v.object(costs) : v.strictObject(costs) };
|
|
21
|
+
return v.parse(v.object({ sources: v.array(unknownFields === 'strip' ? v.object(fields) : v.strictObject(fields)) }), input).sources;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const finite = v.pipe(v.number(), v.finite());
|
|
25
|
+
const point = v.object({ x: finite, y: finite, z: finite });
|
|
26
|
+
const plantedModel = v.object({ x: finite, z: finite, h: finite, lean: finite, leanDir: finite, rot: finite, fronds: finite });
|
|
27
|
+
|
|
28
|
+
/** Admit complete cached prototype observations and planted-model transforms.
|
|
29
|
+
* Unknown metadata is stripped, with the original finite bounds and field order. */
|
|
30
|
+
export function modelPrototypeFacts(input: unknown): {
|
|
31
|
+
protos: { name: string; present: boolean; empty: boolean; min: { x: number; y: number; z: number }; max: { x: number; y: number; z: number }; half: number; top: number }[];
|
|
32
|
+
extraPalms: { x: number; z: number; h: number; lean: number; leanDir: number; rot: number; fronds: number }[];
|
|
33
|
+
bake: { bounceGain: number; sunY: number };
|
|
34
|
+
} {
|
|
35
|
+
return v.parse(v.object({ protos: v.array(v.object({ name: v.string(), present: v.boolean(), empty: v.boolean(),
|
|
36
|
+
min: point, max: point, half: finite, top: finite })), extraPalms: v.array(plantedModel),
|
|
37
|
+
bake: v.object({ bounceGain: finite, sunY: finite }) }), input);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Admit source model names, LOD numbers, authored transforms and bake lighting.
|
|
41
|
+
* LOD values keep their recording grammar; transform and light components stay finite. */
|
|
42
|
+
export function modelSourceMetadata(input: unknown): {
|
|
43
|
+
protos: { name: string }[]; lod: Record<string, number>;
|
|
44
|
+
extraPalms: { x: number; z: number; h: number; lean: number; leanDir: number; rot: number; fronds: number }[];
|
|
45
|
+
bake: { bounceGain: number; refSun: [number, number, number] };
|
|
46
|
+
} {
|
|
47
|
+
return v.parse(v.object({ protos: v.array(v.object({ name: v.string() })), lod: v.record(v.string(), v.number()),
|
|
48
|
+
extraPalms: v.array(plantedModel), bake: v.object({ bounceGain: finite, refSun: v.tuple([finite, finite, finite]) }) }), input);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Admit ordered cover prototype names/kinds and the original mandatory prefix count. */
|
|
52
|
+
export function modelCoverMetadata(input: unknown): { protos: { name: string; kind: string }[]; mustDraw: number } {
|
|
53
|
+
return v.parse(v.object({ protos: v.array(v.object({ name: v.string(), kind: v.string() })), mustDraw: v.number() }), input);
|
|
54
|
+
}
|