@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,39 @@
|
|
|
1
|
+
import { isJsonData } from '@wildshard/format/json';
|
|
2
|
+
import { encodeCanonicalJson } from './immutable';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A value the shard's standalone `runtime/` keeps its own copy of in `runtime/const.ts` (G449: whatever the runtime needs
|
|
6
|
+
* is duplicated into it). `data/` declares the mirror next to the source value; the build checks the copy against it.
|
|
7
|
+
*/
|
|
8
|
+
export interface RuntimeMirror {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly value: unknown;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
14
|
+
|
|
15
|
+
/** Declare in `data/` that `runtime/const.ts` exports `name` with exactly this value (plain JSON, compared canonically). */
|
|
16
|
+
export function defineMirror(name: string, value: unknown): RuntimeMirror {
|
|
17
|
+
if (!NAME.test(name)) throw new Error(`Runtime mirror name must be an export identifier: ${name}`);
|
|
18
|
+
if (!isJsonData(value)) throw new Error(`Runtime mirror ${name} must be plain JSON`);
|
|
19
|
+
return { name, value };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Build step 5 (P2a spec §2.3): compare the mirrors `data/` declares with the module namespace of the copied
|
|
24
|
+
* `out/<slug>/runtime/const.ts`. Returns every issue (empty = consistent): a duplicate mirror, a missing export, or a
|
|
25
|
+
* value that differs from its source. Exports `data/` does not mirror (runtime-only numbers) are allowed.
|
|
26
|
+
*/
|
|
27
|
+
export function runtimeMirrorIssues(mirrors: readonly RuntimeMirror[], runtimeConst: Readonly<Record<string, unknown>>): readonly string[] {
|
|
28
|
+
const issues: string[] = [], seen = new Set<string>();
|
|
29
|
+
for (const mirror of mirrors) {
|
|
30
|
+
if (seen.has(mirror.name)) { issues.push(`${mirror.name}: declared twice in data/`); continue; }
|
|
31
|
+
seen.add(mirror.name);
|
|
32
|
+
if (!Object.hasOwn(runtimeConst, mirror.name)) { issues.push(`${mirror.name}: runtime/const.ts does not export it`); continue; }
|
|
33
|
+
const copy = runtimeConst[mirror.name];
|
|
34
|
+
if (!isJsonData(copy) || encodeCanonicalJson(copy) !== encodeCanonicalJson(mirror.value)) {
|
|
35
|
+
issues.push(`${mirror.name}: runtime/const.ts has ${JSON.stringify(copy)}, data/ has ${JSON.stringify(mirror.value)}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return issues;
|
|
39
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Author CLI inspects bounded local runtime source before building.
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Only canonical checkout paths may consume reviewed transition debt.
|
|
4
|
+
import { basename, relative, resolve } from 'node:path';
|
|
5
|
+
import { runtimePerformanceViolations, type RuntimePerformanceDebt } from '../../lint/runtime-performance.mjs';
|
|
6
|
+
import { readRuntimeFiles, runtimeFileCeiling, RUNTIME_FILE_DEFAULT } from '../../lint/runtime-files.mjs';
|
|
7
|
+
import { readBoundedFile } from './sourceReader';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Most runtime/ source files a project may hold. Outside projects, the Template and any shard without a line refuse above
|
|
11
|
+
* 128. A first-party checkout shard (policy 'warn', see performancePolicy.ts) reads its shrink-only ceiling from
|
|
12
|
+
* lint/runtime-files.json, seeded for the W2 client moves (G450 (5)) and lowered as W3 converts sim and data out.
|
|
13
|
+
*/
|
|
14
|
+
export function projectRuntimeFileCeiling(project: string, policy: 'warn' | 'refuse', root: string = resolve(import.meta.dirname, '../..')): number {
|
|
15
|
+
return policy === 'warn' ? runtimeFileCeiling(readRuntimeFiles(root), basename(realpathSync(project))) : RUNTIME_FILE_DEFAULT;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Syntax-only author guard: outside projects have zero allowance for unsafe custom runtime. */
|
|
19
|
+
export function checkProjectRuntime(project: string, policy: 'warn' | 'refuse', root: string = resolve(import.meta.dirname, '../..')): void {
|
|
20
|
+
const directory = resolve(project, 'runtime'); if (!existsSync(directory)) return;
|
|
21
|
+
const ceiling = projectRuntimeFileCeiling(project, policy, root);
|
|
22
|
+
const baseline = policy === 'warn' ? (JSON.parse(readFileSync(resolve(root, 'lint/runtime-performance.json'), 'utf8')) as { sites: Record<string, RuntimePerformanceDebt> }).sites : {};
|
|
23
|
+
const pending = [directory], decoder = new TextDecoder('utf-8', { fatal: true }); let files = 0, directories = 0;
|
|
24
|
+
while (pending.length > 0) {
|
|
25
|
+
const folder = pending.pop(); if (folder === undefined) break;
|
|
26
|
+
if (++directories > 128) throw new Error('Custom runtime exceeds source directory bound');
|
|
27
|
+
for (const entry of readdirSync(folder, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
28
|
+
const path = resolve(folder, entry.name);
|
|
29
|
+
if (entry.isSymbolicLink()) throw new Error('Custom runtime cannot escape through a symlink');
|
|
30
|
+
if (entry.isDirectory()) { pending.push(path); continue; }
|
|
31
|
+
if (!/\.[cm]?[jt]sx?$/u.test(entry.name) || entry.name.endsWith('.d.ts')) continue;
|
|
32
|
+
if (++files > ceiling) throw new Error(`Custom runtime exceeds source file bound (${ceiling}; lint/runtime-files.json)`);
|
|
33
|
+
const filename = relative(root, path).replaceAll('\\', '/');
|
|
34
|
+
const failures = runtimePerformanceViolations(decoder.decode(readBoundedFile(path, 1_000_000)), filename, baseline);
|
|
35
|
+
if (failures.length > 0) throw new Error(failures.map(site => `${filename}:${site.line}: ${site.kind}: ${site.message}`).join('\n'));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { AmbientLight, Bone, type BufferGeometry, DirectionalLight, Fog, FogExp2, HemisphereLight, InstancedMesh, InterleavedBufferAttribute, Light, Line, LOD, Material, Mesh, MeshBasicMaterial, MeshStandardMaterial, MeshToonMaterial, PointLight, Points, Scene, ShaderMaterial, SkinnedMesh, SpotLight, Sprite, Matrix4, Vector3, type Object3D, type Side } from 'three';
|
|
2
|
+
import { updateAuthoringMatrix } from './sceneTransform';
|
|
3
|
+
import { Collider, type ColliderData } from './physics';
|
|
4
|
+
import { Entry, type EntryData } from './entries';
|
|
5
|
+
import { PlayerStart, Spawn, spawnPlacement, type SpawnPlacement } from './spawns';
|
|
6
|
+
import { readSceneAnimations, readSceneSkin, type SceneAnimation, type SceneSkin } from './sceneAnimation';
|
|
7
|
+
import { AmbienceZone, Cue, Score } from './sceneAudio';
|
|
8
|
+
import type { AudioData } from './audio';
|
|
9
|
+
import { readSceneDeclaration, type SceneDeclaration } from './sceneDeclarations';
|
|
10
|
+
import { Grapple, Mount, Updraft, Zipline, Ladder } from './modes';
|
|
11
|
+
import { parseModes, type ModeRows } from '@wildshard/format/modes';
|
|
12
|
+
import { parseLightRows, type LightRow } from '@wildshard/format/lights';
|
|
13
|
+
import type { MaterialEntry } from '@wildshard/format/materials';
|
|
14
|
+
import { isCatalogueMaterial } from './materials';
|
|
15
|
+
/** One geometry channel, including normalized attributes and its original typed-array representation. */
|
|
16
|
+
export interface SceneAttribute {
|
|
17
|
+
itemSize: number;
|
|
18
|
+
normalized: boolean;
|
|
19
|
+
array: number[];
|
|
20
|
+
storage: string;
|
|
21
|
+
}
|
|
22
|
+
/** BufferGeometry data without transient three.js UUIDs or browser resources. */
|
|
23
|
+
export interface SceneGeometry {
|
|
24
|
+
attributes: Record<string, SceneAttribute>;
|
|
25
|
+
index: number[] | null;
|
|
26
|
+
groups: {
|
|
27
|
+
start: number;
|
|
28
|
+
count: number;
|
|
29
|
+
materialIndex?: number;
|
|
30
|
+
}[];
|
|
31
|
+
drawRange: {
|
|
32
|
+
start: number;
|
|
33
|
+
count: number | null;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Ordinary material parameters; arbitrary shader code and callbacks are never authoring data. */
|
|
37
|
+
export interface SceneMaterial {
|
|
38
|
+
type: string;
|
|
39
|
+
name: string;
|
|
40
|
+
color: number[];
|
|
41
|
+
opacity: number;
|
|
42
|
+
transparent: boolean;
|
|
43
|
+
side: Side;
|
|
44
|
+
vertexColors: boolean;
|
|
45
|
+
parameters: Record<string, number | boolean | number[]>;
|
|
46
|
+
/** The catalogue entry an SDK material (`@wildshard/sdk/materials`) bakes to: a family, a graph preset or a graph. */
|
|
47
|
+
entry?: MaterialEntry;
|
|
48
|
+
}
|
|
49
|
+
/** A graph node uses unique author names as identity; repeated display names receive deterministic traversal IDs. */
|
|
50
|
+
export interface SceneNode {
|
|
51
|
+
/** Original local SDK recipe; restored with this node's hierarchy and transform. */
|
|
52
|
+
declaration?: SceneDeclaration;
|
|
53
|
+
id: string;
|
|
54
|
+
parent: string | null;
|
|
55
|
+
name: string;
|
|
56
|
+
type: string;
|
|
57
|
+
matrix: number[];
|
|
58
|
+
transform?: { position: number[]; quaternion: number[]; scale: number[] };
|
|
59
|
+
visible: boolean;
|
|
60
|
+
castShadow: boolean;
|
|
61
|
+
receiveShadow: boolean;
|
|
62
|
+
geometry?: number;
|
|
63
|
+
materials?: number[];
|
|
64
|
+
instances?: number[][];
|
|
65
|
+
instanceColors?: number[][];
|
|
66
|
+
skin?: SceneSkin;
|
|
67
|
+
animations?: SceneAnimation[];
|
|
68
|
+
levels?: {
|
|
69
|
+
object: string;
|
|
70
|
+
distance: number;
|
|
71
|
+
hysteresis: number;
|
|
72
|
+
}[];
|
|
73
|
+
light?: {
|
|
74
|
+
color: number[];
|
|
75
|
+
intensity: number;
|
|
76
|
+
parameters: Record<string, number | number[] | string>;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Inspectable build intermediate. It contains no executable callbacks, handles or randomly generated UUIDs. */
|
|
80
|
+
export interface SceneDescription {
|
|
81
|
+
version: 1;
|
|
82
|
+
nodes: SceneNode[];
|
|
83
|
+
geometries: SceneGeometry[];
|
|
84
|
+
materials: SceneMaterial[];
|
|
85
|
+
colliders: {
|
|
86
|
+
id: string;
|
|
87
|
+
shape: ColliderData;
|
|
88
|
+
}[];
|
|
89
|
+
spawns: ({
|
|
90
|
+
id: string;
|
|
91
|
+
kind: string;
|
|
92
|
+
} & SpawnPlacement)[];
|
|
93
|
+
playerStart: SpawnPlacement | null;
|
|
94
|
+
entries: EntryData[];
|
|
95
|
+
audio?: AudioData;
|
|
96
|
+
/** Point and spot light rows (`@wildshard/format/lights`) in graph order, world space; absent when none is placed. */
|
|
97
|
+
lights?: LightRow[];
|
|
98
|
+
/** Admitted player-mode rows collected in graph order; absent when no mode is authored. */
|
|
99
|
+
modes?: ModeRows;
|
|
100
|
+
fog: {
|
|
101
|
+
kind: 'linear';
|
|
102
|
+
color: number[];
|
|
103
|
+
near: number;
|
|
104
|
+
far: number;
|
|
105
|
+
} | {
|
|
106
|
+
kind: 'exponential';
|
|
107
|
+
color: number[];
|
|
108
|
+
density: number;
|
|
109
|
+
} | null;
|
|
110
|
+
}
|
|
111
|
+
function isMesh(object: Object3D): object is Mesh { return object instanceof Mesh; }
|
|
112
|
+
function isSkin(object: Object3D): object is SkinnedMesh { return object instanceof SkinnedMesh; }
|
|
113
|
+
function isBone(object: Object3D): object is Bone { return object instanceof Bone; }
|
|
114
|
+
/** Preserve each scalar read and native ToLength behavior while avoiding a
|
|
115
|
+
* generic Array.from callback for ordinary bounded array lengths. */
|
|
116
|
+
function copyGeometryArray(length: number, read: (index: number) => number): number[] {
|
|
117
|
+
if (!Number.isSafeInteger(length) || length < 0 || length >= 2 ** 32)
|
|
118
|
+
return Array.from({ length }, (_, index) => read(index));
|
|
119
|
+
const values: number[] = [];
|
|
120
|
+
values.length = length;
|
|
121
|
+
for (let index = 0; index < length; index++) values[index] = read(index);
|
|
122
|
+
return values;
|
|
123
|
+
}
|
|
124
|
+
function geometryData(geometry: BufferGeometry): SceneGeometry {
|
|
125
|
+
const attributes: Record<string, SceneAttribute> = {};
|
|
126
|
+
for (const name of Object.keys(geometry.attributes).sort()) {
|
|
127
|
+
const attribute = geometry.getAttribute(name);
|
|
128
|
+
// Preserve integer storage, including normalized weights; component getters decode those integers.
|
|
129
|
+
const array = copyGeometryArray(attribute.count * attribute.itemSize, i => attribute instanceof InterleavedBufferAttribute
|
|
130
|
+
? attribute.data.array[Math.floor(i / attribute.itemSize) * attribute.data.stride + attribute.offset + i % attribute.itemSize] ?? Number.NaN
|
|
131
|
+
: attribute.array[i] ?? Number.NaN);
|
|
132
|
+
if (!array.every(Number.isFinite))
|
|
133
|
+
throw new Error(`Nonfinite geometry attribute ${name}`);
|
|
134
|
+
attributes[name] = { itemSize: attribute.itemSize, normalized: attribute.normalized, array, storage: attribute.array.constructor.name };
|
|
135
|
+
}
|
|
136
|
+
if (Object.keys(geometry.morphAttributes).length > 0)
|
|
137
|
+
throw new Error('Scene reader does not yet compile morph targets');
|
|
138
|
+
const index = geometry.getIndex();
|
|
139
|
+
return { attributes, index: index === null ? null : copyGeometryArray(index.count, i => index.getX(i)), groups: geometry.groups.map(group => ({ start: group.start, count: group.count, ...(group.materialIndex === undefined ? {} : { materialIndex: group.materialIndex }) })), drawRange: { start: geometry.drawRange.start, count: geometry.drawRange.count === Infinity ? null : geometry.drawRange.count } };
|
|
140
|
+
}
|
|
141
|
+
function materialData(material: Material): SceneMaterial {
|
|
142
|
+
if (material instanceof ShaderMaterial || material.onBeforeCompile !== Material.prototype.onBeforeCompile)
|
|
143
|
+
throw new Error('Raw shaders and material callbacks are trusted runtime code');
|
|
144
|
+
if (!(material instanceof MeshStandardMaterial) && !(material instanceof MeshToonMaterial) && !(material instanceof MeshBasicMaterial))
|
|
145
|
+
throw new Error(`Unsupported authoring material ${material.type}`);
|
|
146
|
+
if (material.type !== 'MeshStandardMaterial' && material.type !== 'MeshToonMaterial' && material.type !== 'MeshBasicMaterial')
|
|
147
|
+
throw new Error(`Material requires a dedicated compiler: ${material.type}`);
|
|
148
|
+
if (material.map !== null || material.alphaMap !== null || material.aoMap !== null || (!(material instanceof MeshBasicMaterial) && (material.normalMap !== null || material.emissiveMap !== null || material.bumpMap !== null || material.displacementMap !== null)) || (material instanceof MeshBasicMaterial && (material.envMap !== null || material.lightMap !== null || material.specularMap !== null)))
|
|
149
|
+
throw new Error('Scene reader requires independently compiled texture declarations');
|
|
150
|
+
if (material instanceof MeshStandardMaterial && (material.roughnessMap !== null || material.metalnessMap !== null) || material instanceof MeshToonMaterial && material.gradientMap !== null)
|
|
151
|
+
throw new Error('Scene reader requires independently compiled texture declarations');
|
|
152
|
+
const parameters: SceneMaterial['parameters'] = { flatShading: material instanceof MeshStandardMaterial && material.flatShading, alphaTest: material.alphaTest, ...(material instanceof MeshBasicMaterial ? {} : { emissive: [...material.emissive], emissiveIntensity: material.emissiveIntensity }) };
|
|
153
|
+
if (material instanceof MeshStandardMaterial) {
|
|
154
|
+
parameters['roughness'] = material.roughness;
|
|
155
|
+
parameters['metalness'] = material.metalness;
|
|
156
|
+
}
|
|
157
|
+
const row: SceneMaterial = { type: material.type, name: material.name, color: [...material.color], opacity: material.opacity, transparent: material.transparent, side: material.side, vertexColors: material.vertexColors, parameters };
|
|
158
|
+
if (isCatalogueMaterial(material)) row.entry = material.toMaterialEntry();
|
|
159
|
+
return row;
|
|
160
|
+
}
|
|
161
|
+
/** Walk an ordinary three.js hierarchy in Node. Updates world matrices; never installs services or draws a frame.
|
|
162
|
+
* Unsupported authoring features fail explicitly instead of silently changing a collider, material or spawn. */
|
|
163
|
+
export function readScene(scene: Object3D): SceneDescription {
|
|
164
|
+
updateAuthoringMatrix(scene);
|
|
165
|
+
scene.updateMatrixWorld(true);
|
|
166
|
+
const objects: Object3D[] = [];
|
|
167
|
+
scene.traverse(object => objects.push(object));
|
|
168
|
+
const ids = new Map<Object3D, string>(), counts = new Map<string, number>();
|
|
169
|
+
for (const object of objects) if (object.name) counts.set(object.name, (counts.get(object.name) ?? 0) + 1);
|
|
170
|
+
const used = new Set([...counts].filter(([, count]) => count === 1).map(([name]) => name));
|
|
171
|
+
for (const [index, object] of objects.entries()) {
|
|
172
|
+
if (object.name && counts.get(object.name) === 1) ids.set(object, object.name);
|
|
173
|
+
else {
|
|
174
|
+
let id = `node.${index}`;
|
|
175
|
+
while (used.has(id)) id += '.';
|
|
176
|
+
used.add(id); ids.set(object, id);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const out: SceneDescription = { version: 1, nodes: [], geometries: [], materials: [], colliders: [], spawns: [], playerStart: null, entries: [], fog: null };
|
|
180
|
+
const boneIds = new Map<Bone, string>();
|
|
181
|
+
for (const object of objects) if (isBone(object)) { const id = ids.get(object); if (id === undefined) throw new Error('Unindexed bone'); boneIds.set(object, id); }
|
|
182
|
+
const geometries = new Map<BufferGeometry, number>(), materials = new Map<Material, number>();
|
|
183
|
+
const lights: LightRow[] = [];
|
|
184
|
+
const cues: AudioData['cues'] = [], zones: NonNullable<AudioData['zones']>['zones'] = [];
|
|
185
|
+
const modes: ModeRows = { traverse: [] }, ride: NonNullable<ModeRows['ride']> = [], grapple: NonNullable<ModeRows['grapple']> = [];
|
|
186
|
+
let score: Score | undefined;
|
|
187
|
+
for (const object of objects) {
|
|
188
|
+
const id = ids.get(object);
|
|
189
|
+
if (id === undefined)
|
|
190
|
+
throw new Error('Unindexed scene node');
|
|
191
|
+
if (!object.matrix.elements.every(Number.isFinite))
|
|
192
|
+
throw new Error('Scene requires finite matrices');
|
|
193
|
+
if (object instanceof Line || object instanceof Points || object instanceof Sprite) throw new Error(`Unsupported draw primitive ${object.type}`);
|
|
194
|
+
const node: SceneNode = { id, parent: object === scene ? null : ids.get(object.parent ?? scene) ?? null, name: object.name, type: object.type, matrix: [...(object === scene ? object.matrixWorld : object.matrix).elements], visible: object.visible, castShadow: object.castShadow, receiveShadow: object.receiveShadow };
|
|
195
|
+
if (object.matrixAutoUpdate && (object !== scene || object.parent === null)) node.transform = { position: object.position.toArray(), quaternion: object.quaternion.toArray(), scale: object.scale.toArray() };
|
|
196
|
+
const declaration = readSceneDeclaration(object, ids);
|
|
197
|
+
if (declaration !== undefined) node.declaration = declaration;
|
|
198
|
+
if (object.animations.length > 0) node.animations = readSceneAnimations(object.animations);
|
|
199
|
+
if (isSkin(object)) node.skin = readSceneSkin(object, boneIds);
|
|
200
|
+
if (isMesh(object)) {
|
|
201
|
+
let geometry = geometries.get(object.geometry);
|
|
202
|
+
if (geometry === undefined) {
|
|
203
|
+
geometry = out.geometries.length;
|
|
204
|
+
geometries.set(object.geometry, geometry);
|
|
205
|
+
out.geometries.push(geometryData(object.geometry));
|
|
206
|
+
}
|
|
207
|
+
node.geometry = geometry;
|
|
208
|
+
node.materials = (Array.isArray(object.material) ? object.material : [object.material]).map(material => {
|
|
209
|
+
let index = materials.get(material);
|
|
210
|
+
if (index === undefined) {
|
|
211
|
+
index = out.materials.length;
|
|
212
|
+
materials.set(material, index);
|
|
213
|
+
out.materials.push(materialData(material));
|
|
214
|
+
}
|
|
215
|
+
return index;
|
|
216
|
+
});
|
|
217
|
+
if (object instanceof InstancedMesh) {
|
|
218
|
+
const matrix = new Matrix4();
|
|
219
|
+
node.instances = [];
|
|
220
|
+
for (let i = 0; i < object.count; i++) {
|
|
221
|
+
object.getMatrixAt(i, matrix);
|
|
222
|
+
if (!matrix.elements.every(Number.isFinite))
|
|
223
|
+
throw new Error('Nonfinite instance transform');
|
|
224
|
+
node.instances.push([...matrix.elements]);
|
|
225
|
+
}
|
|
226
|
+
const colors = object.instanceColor;
|
|
227
|
+
if (colors !== null)
|
|
228
|
+
node.instanceColors = Array.from({ length: object.count }, (_, i) => [colors.getX(i), colors.getY(i), colors.getZ(i)]);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (object instanceof LOD)
|
|
232
|
+
node.levels = object.levels.map(level => {
|
|
233
|
+
const target = ids.get(level.object);
|
|
234
|
+
if (target === undefined)
|
|
235
|
+
throw new Error('LOD object is outside the scene');
|
|
236
|
+
return { object: target, distance: level.distance, hysteresis: level.hysteresis };
|
|
237
|
+
});
|
|
238
|
+
if (object instanceof Light) {
|
|
239
|
+
if (!(object instanceof AmbientLight || object instanceof HemisphereLight || object instanceof DirectionalLight || object instanceof PointLight || object instanceof SpotLight))
|
|
240
|
+
throw new Error(`Unsupported authoring light ${object.type}`);
|
|
241
|
+
const parameters: NonNullable<SceneNode['light']>['parameters'] = {};
|
|
242
|
+
if (object instanceof HemisphereLight)
|
|
243
|
+
parameters['groundColor'] = [...object.groundColor];
|
|
244
|
+
if (object instanceof PointLight || object instanceof SpotLight) {
|
|
245
|
+
parameters['distance'] = object.distance;
|
|
246
|
+
parameters['decay'] = object.decay;
|
|
247
|
+
}
|
|
248
|
+
if (object instanceof SpotLight) {
|
|
249
|
+
parameters['angle'] = object.angle;
|
|
250
|
+
parameters['penumbra'] = object.penumbra;
|
|
251
|
+
}
|
|
252
|
+
if (object instanceof DirectionalLight || object instanceof SpotLight) {
|
|
253
|
+
updateAuthoringMatrix(object.target);
|
|
254
|
+
parameters['target'] = [object.target.matrixWorld.elements[12], object.target.matrixWorld.elements[13], object.target.matrixWorld.elements[14]];
|
|
255
|
+
}
|
|
256
|
+
node.light = { color: [...object.color], intensity: object.intensity, parameters };
|
|
257
|
+
if (object instanceof PointLight || object instanceof SpotLight) {
|
|
258
|
+
const base = { id, position: new Vector3().setFromMatrixPosition(object.matrixWorld).toArray(), colour: [object.color.r, object.color.g, object.color.b] as [number, number, number], intensity: object.intensity, distance: object.distance, decay: object.decay };
|
|
259
|
+
lights.push(object instanceof SpotLight
|
|
260
|
+
? { kind: 'spot', ...base, target: new Vector3().setFromMatrixPosition(object.target.matrixWorld).toArray(), angle: object.angle, penumbra: object.penumbra }
|
|
261
|
+
: { kind: 'point', ...base });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (object instanceof Collider) {
|
|
265
|
+
if (!object.name)
|
|
266
|
+
throw new Error('Collider requires a stable name');
|
|
267
|
+
if (out.colliders.some(row => row.id === object.name))
|
|
268
|
+
throw new Error(`Duplicate collider identity ${object.name}`);
|
|
269
|
+
out.colliders.push({ id: object.name, shape: object.toColliderData() });
|
|
270
|
+
}
|
|
271
|
+
if (object instanceof PlayerStart) {
|
|
272
|
+
if (out.playerStart !== null)
|
|
273
|
+
throw new Error('Scene permits only one player start');
|
|
274
|
+
out.playerStart = spawnPlacement(object);
|
|
275
|
+
}
|
|
276
|
+
if (object instanceof Spawn) {
|
|
277
|
+
if (!object.name)
|
|
278
|
+
throw new Error('Spawn requires a stable name');
|
|
279
|
+
if (object.kind.length === 0)
|
|
280
|
+
throw new Error('Spawn requires a kind');
|
|
281
|
+
if (out.spawns.some(row => row.id === object.name))
|
|
282
|
+
throw new Error(`Duplicate spawn identity ${object.name}`);
|
|
283
|
+
out.spawns.push({ id: object.name, kind: object.kind, ...spawnPlacement(object) });
|
|
284
|
+
}
|
|
285
|
+
if (object instanceof Entry)
|
|
286
|
+
out.entries.push(object.toEntryData());
|
|
287
|
+
if (object instanceof Cue) cues.push(object.toCueData());
|
|
288
|
+
if (object instanceof AmbienceZone) zones.push(object.toZoneData());
|
|
289
|
+
if (object instanceof Score) { if (score !== undefined) throw new Error('Scene permits one audio profile'); score = object; }
|
|
290
|
+
if (object instanceof Zipline || object instanceof Updraft || object instanceof Ladder) modes.traverse.push(object.toModeData());
|
|
291
|
+
if (object instanceof Mount) ride.push(object.toModeData());
|
|
292
|
+
if (object instanceof Grapple) grapple.push(object.toModeData());
|
|
293
|
+
out.nodes.push(node);
|
|
294
|
+
}
|
|
295
|
+
if (new Set(out.entries.map(entry => entry.edge)).size !== out.entries.length)
|
|
296
|
+
throw new Error('Duplicate entry edge');
|
|
297
|
+
if (lights.length > 0) out.lights = lights;
|
|
298
|
+
if (score !== undefined || cues.length > 0 || zones.length > 0) out.audio = (score ?? new Score()).toAudioData(cues, zones);
|
|
299
|
+
if (modes.traverse.length > 0 || ride.length > 0 || grapple.length > 0) out.modes = parseModes({ ...modes, ...(ride.length === 0 ? {} : { ride }), ...(grapple.length === 0 ? {} : { grapple }) });
|
|
300
|
+
if (scene instanceof Scene) {
|
|
301
|
+
if (scene.fog instanceof Fog)
|
|
302
|
+
out.fog = { kind: 'linear', color: [...scene.fog.color], near: scene.fog.near, far: scene.fog.far };
|
|
303
|
+
else if (scene.fog instanceof FogExp2)
|
|
304
|
+
out.fog = { kind: 'exponential', color: [...scene.fog.color], density: scene.fog.density };
|
|
305
|
+
}
|
|
306
|
+
if (!finiteData(out))
|
|
307
|
+
throw new Error('Scene description requires finite JSON data');
|
|
308
|
+
if (out.lights !== undefined) out.lights = parseLightRows(out.lights);
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
311
|
+
function finiteData(value: unknown): boolean {
|
|
312
|
+
if (typeof value === 'number')
|
|
313
|
+
return Number.isFinite(value);
|
|
314
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
315
|
+
return true;
|
|
316
|
+
if (Array.isArray(value))
|
|
317
|
+
return value.every(finiteData);
|
|
318
|
+
if (typeof value === 'object')
|
|
319
|
+
return Object.values(value).every(finiteData);
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AnimationClip, KeyframeTrack, type Bone, type SkinnedMesh, type AnimationBlendMode, type KeyframeTrackJSON } from 'three';
|
|
2
|
+
|
|
3
|
+
/** Ordered skeleton references and exact bind matrices, independent of randomly generated UUIDs. */
|
|
4
|
+
export interface SceneSkin {
|
|
5
|
+
bones: string[];
|
|
6
|
+
inverses: number[][];
|
|
7
|
+
bindMode: SkinnedMesh['bindMode'];
|
|
8
|
+
bindMatrix: number[];
|
|
9
|
+
bindMatrixInverse: number[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** An ordinary three.js clip with its authored order, duration, blend mode and typed keyframe laws. */
|
|
13
|
+
export interface SceneAnimation {
|
|
14
|
+
name: string;
|
|
15
|
+
duration: number;
|
|
16
|
+
blendMode: AnimationBlendMode;
|
|
17
|
+
tracks: KeyframeTrackJSON[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Serialize actual rest joints and weights; every joint must belong to the inspected hierarchy. */
|
|
21
|
+
export function readSceneSkin(mesh: SkinnedMesh, ids: ReadonlyMap<Bone, string>): SceneSkin {
|
|
22
|
+
const { bones, boneInverses } = mesh.skeleton;
|
|
23
|
+
if (bones.length === 0 || bones.length > 128 || boneInverses.length !== bones.length || new Set(bones).size !== bones.length) throw new Error('Scene skin requires distinct ordered joints and inverse binds');
|
|
24
|
+
const indices = mesh.geometry.getAttribute('skinIndex'), weights = mesh.geometry.getAttribute('skinWeight'), positions = mesh.geometry.getAttribute('position');
|
|
25
|
+
if (!mesh.geometry.hasAttribute('skinIndex') || !mesh.geometry.hasAttribute('skinWeight') || !mesh.geometry.hasAttribute('position') || indices.itemSize !== 4 || weights.itemSize !== 4 || indices.count !== positions.count || weights.count !== positions.count) throw new Error('Scene skin requires four weights and joint indices per vertex');
|
|
26
|
+
for (let vertex = 0; vertex < positions.count; vertex++) for (let component = 0; component < 4; component++) {
|
|
27
|
+
const index = indices.getComponent(vertex, component), weight = weights.getComponent(vertex, component);
|
|
28
|
+
if (!Number.isInteger(index) || index < 0 || index >= bones.length || !Number.isFinite(weight) || weight < 0) throw new Error('Invalid scene skin influence');
|
|
29
|
+
}
|
|
30
|
+
return { bones: bones.map(bone => { const id = ids.get(bone); if (id === undefined) throw new Error('Scene skin joint lies outside its hierarchy'); return id; }),
|
|
31
|
+
inverses: boneInverses.map(matrix => Array.from(matrix.elements)), bindMode: mesh.bindMode, bindMatrix: [...mesh.bindMatrix.elements], bindMatrixInverse: [...mesh.bindMatrixInverse.elements] };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Preserve standard track interpolation and values; UUID-bound targets and custom interpolants refuse. */
|
|
35
|
+
export function readSceneAnimations(clips: readonly AnimationClip[]): SceneAnimation[] {
|
|
36
|
+
if (clips.length > 32 || new Set(clips.map(clip => clip.name)).size !== clips.length) throw new Error('Scene clips require distinct names within the clip cap');
|
|
37
|
+
return clips.map(clip => {
|
|
38
|
+
if (!clip.name || !Number.isFinite(clip.duration) || clip.duration < 0 || clip.duration > 60 || !clip.validate()) throw new Error('Invalid scene animation');
|
|
39
|
+
const tracks = clip.tracks.map(track => {
|
|
40
|
+
if (/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/iu.test(track.name)) throw new Error('Animation must bind stable author names, never UUIDs');
|
|
41
|
+
if (track.times.length === 0 || track.times.length > 4097 || track.times.some((time, index) => !Number.isFinite(time) || time < 0 || time > clip.duration || index > 0 && time <= (track.times[index - 1] ?? Infinity))) throw new Error('Invalid bounded scene track times');
|
|
42
|
+
const row = KeyframeTrack.toJSON(track);
|
|
43
|
+
const restored = AnimationClip.parse({ name: clip.name, duration: clip.duration, blendMode: clip.blendMode, tracks: [row], uuid: '' }).tracks[0];
|
|
44
|
+
if (restored === undefined || !('createInterpolant' in restored) || !('createInterpolant' in track) || restored.createInterpolant !== track.createInterpolant) throw new Error('Custom animation interpolants require their own compiler');
|
|
45
|
+
return row;
|
|
46
|
+
});
|
|
47
|
+
return { name: clip.name, duration: clip.duration, blendMode: clip.blendMode, tracks };
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Reconstruct standard three.js clips without mutating, optimizing or resampling their authored channels. */
|
|
52
|
+
export function restoreSceneAnimations(clips: readonly SceneAnimation[]): AnimationClip[] {
|
|
53
|
+
return clips.map(clip => AnimationClip.parse({ ...clip, uuid: '' }));
|
|
54
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { parseAudioData as parseData, type AudioData as Data } from './audio';
|
|
3
|
+
import { AudioZonesSchema, type AudioZones } from '@wildshard/format/audioProfiles';
|
|
4
|
+
import { Matrix4, Object3D, Quaternion, Vector3 } from 'three';
|
|
5
|
+
import { updateAuthoringMatrix } from './sceneTransform';
|
|
6
|
+
|
|
7
|
+
/** A named event-to-catalogue voice binding in the author graph, never an AudioContext or a decoder. */
|
|
8
|
+
export class Cue extends Object3D {
|
|
9
|
+
/** The admitted voice identity used when the named cue fires. */
|
|
10
|
+
voice: string;
|
|
11
|
+
constructor(id = '', voice = '') { super(); this.name = id; this.voice = voice; }
|
|
12
|
+
/** Copy the voice together with ordinary graph transforms and children. */
|
|
13
|
+
override copy(source: this, recursive = true): this { super.copy(source, recursive); this.voice = source.voice; return this; }
|
|
14
|
+
/** Emit an existing cue row; its event owner, rather than this declaration, supplies any moving sound position. */
|
|
15
|
+
toCueData(): Data['cues'][number] {
|
|
16
|
+
const cue = parseData({ cues: [{ id: this.name, voice: this.voice }], ambience: null, score: 'silent' }).cues[0];
|
|
17
|
+
if (cue === undefined) throw new Error('Missing authored cue'); return cue;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** One horizontal ambience region, using the existing bounded zone/mixer wire contract. */
|
|
22
|
+
export class AmbienceZone extends Object3D {
|
|
23
|
+
private recipe: AudioZones['zones'][number];
|
|
24
|
+
constructor(recipe?: AudioZones['zones'][number]) { super(); const data = recipe ?? { id: 'zone', x: 0, z: 0, inner: 0, outer: 1, gain: 1 }; this.recipe = structuredClone(data); this.name = data.id; this.position.set(data.x, 0, data.z); }
|
|
25
|
+
/** Copy the zone recipe without aliasing mutable author objects. */
|
|
26
|
+
override copy(source: this, recursive = true): this { super.copy(source, recursive); this.recipe = structuredClone(source.recipe); return this; }
|
|
27
|
+
/** Horizontal similarity transforms move the centre and scale its radii once; tilted or elliptic zones refuse. */
|
|
28
|
+
toZoneData(): AudioZones['zones'][number] {
|
|
29
|
+
updateAuthoringMatrix(this);
|
|
30
|
+
const at = new Vector3(), rotation = new Quaternion(), scale = new Vector3(); this.matrixWorld.decompose(at, rotation, scale);
|
|
31
|
+
const composed = new Matrix4().compose(at, rotation, scale);
|
|
32
|
+
if (this.matrixWorld.elements.some((value, index) => Math.abs(value - (composed.elements[index] ?? Infinity)) > 1e-8)) throw new Error('Ambience zone requires an unsheared transform');
|
|
33
|
+
if (![...at, ...rotation, ...scale].every(Number.isFinite) || at.y !== 0 || Math.abs(rotation.x) > 1e-8 || Math.abs(rotation.z) > 1e-8 || scale.x <= 0 || Math.abs(scale.x - scale.z) > 1e-8) throw new Error('Ambience zone requires a horizontal circular transform');
|
|
34
|
+
return { ...this.recipe, id: this.name, x: at.x, z: at.z, inner: this.recipe.inner * scale.x, outer: this.recipe.outer * scale.x, ...(this.recipe.fade === undefined ? {} : { fade: this.recipe.fade * scale.x }) };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A retained audio profile plus graph cue/zone declarations. It emits data without loading or playing a sound. */
|
|
39
|
+
export class Score extends Object3D {
|
|
40
|
+
private recipe: Data;
|
|
41
|
+
constructor(recipe: Data = parseData({ cues: [], ambience: null, score: 'silent' })) { super(); this.recipe = structuredClone(parseData(recipe)); this.name = 'audio'; }
|
|
42
|
+
/** Adopt an existing profile with cue and zone objects in their exact original registration order. */
|
|
43
|
+
static fromData(recipe: Data): Score {
|
|
44
|
+
const data = parseData(recipe), score = new Score({ ...data, cues: [], ...(data.zones === undefined ? {} : { zones: { ...data.zones, zones: [] } }) });
|
|
45
|
+
score.add(...data.cues.map(cue => new Cue(cue.id, cue.voice)));
|
|
46
|
+
score.add(...(data.zones?.zones.map(zone => new AmbienceZone(zone)) ?? []));
|
|
47
|
+
return score;
|
|
48
|
+
}
|
|
49
|
+
/** Copy the data profile without sharing mutable rows with the original. */
|
|
50
|
+
override copy(source: this, recursive = true): this { super.copy(source, recursive); this.recipe = structuredClone(source.recipe); return this; }
|
|
51
|
+
/** Combine graph rows with the retained music/sample/mixer profile under the single defining format schema. */
|
|
52
|
+
toAudioData(cues?: readonly Data['cues'][number][], zones?: readonly AudioZones['zones'][number][]): Data {
|
|
53
|
+
const ownedCues: Data['cues'] = [], ownedZones: AudioZones['zones'] = [];
|
|
54
|
+
if (cues === undefined || zones === undefined) this.traverse(object => {
|
|
55
|
+
if (cues === undefined && object instanceof Cue) ownedCues.push(object.toCueData());
|
|
56
|
+
if (zones === undefined && object instanceof AmbienceZone) ownedZones.push(object.toZoneData());
|
|
57
|
+
});
|
|
58
|
+
const selectedCues = cues ?? ownedCues, selectedZones = zones ?? ownedZones;
|
|
59
|
+
if (selectedZones.length > 0 && this.recipe.zones === undefined) throw new Error('Ambience zones require a declared mixer profile');
|
|
60
|
+
const data = { ...this.recipe, cues: [...this.recipe.cues, ...selectedCues], ...(this.recipe.zones === undefined ? {} : { zones: { ...this.recipe.zones, zones: [...this.recipe.zones.zones, ...selectedZones] } }) };
|
|
61
|
+
if (data.zones !== undefined) v.parse(AudioZonesSchema, data.zones);
|
|
62
|
+
return parseData(data);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { BufferAttribute, BufferGeometry, Object3D, Vector3 } from 'three';
|
|
2
|
+
import { BoxCollider, CapsuleCollider, Collider, HullCollider, MeshCollider, type ColliderData } from './physics';
|
|
3
|
+
import { Entry, SocketLift, type EntryData } from './entries';
|
|
4
|
+
import { PlayerStart, Spawn } from './spawns';
|
|
5
|
+
import { AmbienceZone, Cue, Score } from './sceneAudio';
|
|
6
|
+
import type { AudioData } from './audio';
|
|
7
|
+
import { Director } from './director';
|
|
8
|
+
import type { DirectorStagesData } from '@wildshard/format/directorStages';
|
|
9
|
+
import { Mover, type MoverOptions } from './movers';
|
|
10
|
+
import { Grapple, Mount, Updraft, Zipline, Ladder, type LadderOptions, type UpdraftOptions, type ZiplineOptions } from './modes';
|
|
11
|
+
import type { GrappleMode, RideMode } from '@wildshard/format/modes';
|
|
12
|
+
import { readSceneAnimations, restoreSceneAnimations, type SceneAnimation } from './sceneAnimation';
|
|
13
|
+
|
|
14
|
+
/** Lossless local author parameters, distinct from transformed compiler rows and ordinary node TRS. */
|
|
15
|
+
export type SceneDeclaration =
|
|
16
|
+
| { kind: 'entry'; data: EntryData }
|
|
17
|
+
| { kind: 'playerStart' }
|
|
18
|
+
| { kind: 'spawn'; species: string }
|
|
19
|
+
| { kind: 'collider'; shape: ColliderData }
|
|
20
|
+
| { kind: 'cue'; voice: string }
|
|
21
|
+
| { kind: 'zone'; recipe: NonNullable<AudioData['zones']>['zones'][number] }
|
|
22
|
+
| { kind: 'score'; recipe: AudioData }
|
|
23
|
+
| { kind: 'director'; recipe: DirectorStagesData }
|
|
24
|
+
| { kind: 'mover'; body: string; options: Omit<MoverOptions, 'clip'>; clip?: SceneAnimation }
|
|
25
|
+
| { kind: 'zipline'; top: number[]; bottom: number[]; options: ZiplineOptions }
|
|
26
|
+
| { kind: 'updraft'; from: number[]; to: number[]; options: UpdraftOptions }
|
|
27
|
+
| { kind: 'ladder'; bottom: number[]; top: number[]; exit: number[]; normal: number[]; options: LadderOptions }
|
|
28
|
+
| { kind: 'mount'; gaits: RideMode['gaits'] }
|
|
29
|
+
| { kind: 'grapple'; options: Partial<Omit<GrappleMode, 'id'>> };
|
|
30
|
+
|
|
31
|
+
function identity<T extends Object3D>(object: T): T {
|
|
32
|
+
const copy = object.clone(false);
|
|
33
|
+
copy.matrixAutoUpdate = true; copy.position.set(0, 0, 0); copy.quaternion.identity(); copy.scale.set(1, 1, 1);
|
|
34
|
+
copy.updateMatrixWorld(true);
|
|
35
|
+
return copy;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Capture original local data, never reverse world scale/rotation from already-rounded compiler output. */
|
|
39
|
+
export function readSceneDeclaration(object: Object3D, ids: ReadonlyMap<Object3D, string>): SceneDeclaration | undefined {
|
|
40
|
+
if (object instanceof Entry) return { kind: 'entry', data: object.toEntryData() };
|
|
41
|
+
if (object instanceof PlayerStart) return { kind: 'playerStart' };
|
|
42
|
+
if (object instanceof Spawn) return { kind: 'spawn', species: object.kind };
|
|
43
|
+
if (object instanceof Collider) return { kind: 'collider', shape: identity(object).toColliderData() };
|
|
44
|
+
if (object instanceof Cue) return { kind: 'cue', voice: object.voice };
|
|
45
|
+
if (object instanceof AmbienceZone) return { kind: 'zone', recipe: identity(object).toZoneData() };
|
|
46
|
+
if (object instanceof Score) return { kind: 'score', recipe: object.toAudioData([], []) };
|
|
47
|
+
const director: unknown = object.userData['director'];
|
|
48
|
+
if (director instanceof Director) return { kind: 'director', recipe: director.toJSON() };
|
|
49
|
+
if (object instanceof Mover) {
|
|
50
|
+
const body = ids.get(object.body); if (body === undefined) throw new Error('Mover body is outside the scene');
|
|
51
|
+
object.toMotionData();
|
|
52
|
+
const { clip, ...options } = object.options;
|
|
53
|
+
const animation = clip === undefined ? undefined : readSceneAnimations([clip])[0];
|
|
54
|
+
return { kind: 'mover', body, options: structuredClone(options), ...(animation === undefined ? {} : { clip: animation }) };
|
|
55
|
+
}
|
|
56
|
+
if (object instanceof Zipline) return { kind: 'zipline', top: object.top.toArray(), bottom: object.bottom.toArray(), options: { ...object.options } };
|
|
57
|
+
if (object instanceof Updraft) return { kind: 'updraft', from: object.from.toArray(), to: object.to.toArray(), options: { ...object.options } };
|
|
58
|
+
if (object instanceof Ladder) return { kind: 'ladder', bottom: object.bottom.toArray(), top: object.top.toArray(), exit: object.exit.toArray(), normal: object.normal.toArray(), options: { ...object.options } };
|
|
59
|
+
if (object instanceof Mount) return { kind: 'mount', gaits: { ...object.gaits } };
|
|
60
|
+
if (object instanceof Grapple) return { kind: 'grapple', options: { ...object.options } };
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function collider(shape: ColliderData): Collider {
|
|
65
|
+
if (shape.kind === 'box') return BoxCollider.fromData(shape);
|
|
66
|
+
if (shape.kind === 'capsule') return new CapsuleCollider(shape.radius, shape.halfHeight * 2, shape.surface);
|
|
67
|
+
const geometry = new BufferGeometry();
|
|
68
|
+
geometry.setAttribute('position', new BufferAttribute(new Float64Array(shape.kind === 'hull' ? shape.points : shape.vertices), 3));
|
|
69
|
+
if (shape.kind === 'trimesh') geometry.setIndex(shape.indices);
|
|
70
|
+
return shape.kind === 'hull' ? new HullCollider(geometry, shape.surface) : new MeshCollider(geometry, shape.surface);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Recreate the defining SDK declaration without services, physics bodies, sound playback or gameplay grants. */
|
|
74
|
+
export function restoreSceneDeclaration(row: SceneDeclaration, node: (id: string) => Object3D): Object3D {
|
|
75
|
+
switch (row.kind) {
|
|
76
|
+
case 'entry': return row.data.kind === 'portalLink' ? new Entry(row.data.edge, 'portalLink', row.data.portal === undefined ? {} : { portal: row.data.portal }) : row.data.kind === 'socketLift' ? new SocketLift(row.data.edge, row.data.lift) : new Entry(row.data.edge, row.data.kind);
|
|
77
|
+
case 'playerStart': return new PlayerStart();
|
|
78
|
+
case 'spawn': return new Spawn(row.species);
|
|
79
|
+
case 'collider': return collider(row.shape);
|
|
80
|
+
case 'cue': return new Cue('', row.voice);
|
|
81
|
+
case 'zone': return new AmbienceZone(row.recipe);
|
|
82
|
+
case 'score': return new Score(row.recipe);
|
|
83
|
+
case 'director': {
|
|
84
|
+
const object = new Object3D(); object.userData['director'] = new Director(row.recipe); return object;
|
|
85
|
+
}
|
|
86
|
+
case 'mover': {
|
|
87
|
+
const clip = row.clip === undefined ? undefined : restoreSceneAnimations([row.clip])[0];
|
|
88
|
+
return new Mover(node(row.body), { ...structuredClone(row.options), ...(clip === undefined ? {} : { clip }) });
|
|
89
|
+
}
|
|
90
|
+
case 'zipline': return new Zipline(new Vector3().fromArray(row.top), new Vector3().fromArray(row.bottom), row.options);
|
|
91
|
+
case 'updraft': return new Updraft(new Vector3().fromArray(row.from), new Vector3().fromArray(row.to), row.options);
|
|
92
|
+
case 'ladder': {
|
|
93
|
+
const ladder = new Ladder(new Vector3().fromArray(row.bottom), new Vector3().fromArray(row.top), new Vector3().fromArray(row.exit), row.options);
|
|
94
|
+
ladder.normal.fromArray(row.normal); return ladder;
|
|
95
|
+
}
|
|
96
|
+
case 'mount': return new Mount(row.gaits);
|
|
97
|
+
case 'grapple': return new Grapple(row.options);
|
|
98
|
+
default: throw new Error('Unknown SDK scene declaration');
|
|
99
|
+
}
|
|
100
|
+
}
|