@wildshard/sdk 0.0.1 → 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 +13 -5
- package/bin/wildshard.mjs +38 -0
- package/lint/declaration-config.d.mts +2 -0
- package/lint/declaration-config.mjs +19 -0
- package/lint/engine-plugin.d.mts +2 -0
- package/lint/engine-plugin.mjs +40 -0
- package/lint/host-callbacks.d.mts +6 -0
- package/lint/host-callbacks.mjs +123 -0
- package/lint/host-files.d.mts +1 -0
- package/lint/host-files.mjs +7 -0
- package/lint/layer-exports.d.mts +2 -0
- package/lint/layer-exports.mjs +21 -0
- package/lint/legacy-line-basis.json +995 -0
- package/lint/nine-tiling-baseline.json +35 -0
- package/lint/ratchet.json +11 -0
- package/lint/runtime-files.d.mts +12 -0
- package/lint/runtime-files.json +16 -0
- package/lint/runtime-files.mjs +69 -0
- package/lint/runtime-performance.d.mts +6 -0
- package/lint/runtime-performance.mjs +184 -0
- package/lint/sdk-plugin.d.mts +4 -0
- package/lint/sdk-plugin.mjs +134 -0
- package/lint/shardfile-boundaries.d.mts +10 -0
- package/lint/shardfile-boundaries.mjs +122 -0
- package/lint/tile-bake-debt.json +556 -0
- package/package.json +365 -3
- package/scripts/agent-parity.mjs +1524 -0
- package/scripts/agent-sync.mjs +518 -0
- package/scripts/apfs-clone.mjs +67 -0
- package/scripts/assert-store-layout.mjs +23 -0
- package/scripts/astc6-phone-cap.d.mts +3 -0
- package/scripts/astc6-phone-cap.mjs +137 -0
- package/scripts/audit-assets.d.mts +10 -0
- package/scripts/audit-assets.mjs +151 -0
- package/scripts/bake/coatFiles.d.mts +6 -0
- package/scripts/bake/coatFiles.mjs +37 -0
- package/scripts/bake/environment.d.mts +2 -0
- package/scripts/bake/environment.mjs +58 -0
- package/scripts/bake/far-proxies.mjs +45 -0
- package/scripts/bake/keyed-sky.d.mts +4 -0
- package/scripts/bake/keyed-sky.mjs +34 -0
- package/scripts/bake/movers.mjs +56 -0
- package/scripts/bake/nativeWorld.d.mts +6 -0
- package/scripts/bake/nativeWorld.mjs +43 -0
- package/scripts/bake/navmeshGround.ts +22 -0
- package/scripts/bake/near-placeholder.mjs +331 -0
- package/scripts/bake/placeholderShards.mjs +41 -0
- package/scripts/bake/skins.mjs +15 -0
- package/scripts/bake/template-skins.mjs +33 -0
- package/scripts/bake/viewmodelBytes.ts +26 -0
- package/scripts/bake/viewmodelPage.ts +11 -0
- package/scripts/bake/worldHost.d.mts +35 -0
- package/scripts/bake/worldHost.mjs +110 -0
- package/scripts/bake-astc6.cache.json +80 -0
- package/scripts/bake-astc6.far-reach.cache.json +23 -0
- package/scripts/bake-astc6.list.json +111 -0
- package/scripts/bake-astc6.mjs +279 -0
- package/scripts/bake-astc6.nalati-grasslands.cache.json +42 -0
- package/scripts/bake-catalogue.mjs +44 -0
- package/scripts/bake-check.mjs +54 -0
- package/scripts/bake-chunk.mjs +124 -0
- package/scripts/bake-cloud-field.mjs +24 -0
- package/scripts/bake-coats.mjs +110 -0
- package/scripts/bake-data-maps.d.mts +24 -0
- package/scripts/bake-data-maps.mjs +72 -0
- package/scripts/bake-entry-programs.mjs +117 -0
- package/scripts/bake-geometry.mjs +106 -0
- package/scripts/bake-hybrid-tiles.mjs +28 -0
- package/scripts/bake-ktx2.cache.json +276 -0
- package/scripts/bake-ktx2.list.json +365 -0
- package/scripts/bake-ktx2.mjs +477 -0
- package/scripts/bake-map-glb.mjs +127 -0
- package/scripts/bake-map-rest.d.mts +7 -0
- package/scripts/bake-map-rest.mjs +50 -0
- package/scripts/bake-maps.mjs +200 -0
- package/scripts/bake-navmesh.mjs +259 -0
- package/scripts/bake-packs.mjs +129 -0
- package/scripts/bake-pickups.mjs +102 -0
- package/scripts/bake-query-terrain.mjs +64 -0
- package/scripts/bake-recurve-pool.mjs +16 -0
- package/scripts/bake-section-schemas.d.mts +3 -0
- package/scripts/bake-template-shardfile.mjs +32 -0
- package/scripts/bake-textures.mjs +80 -0
- package/scripts/bake-viewmodel-sets.json +45 -0
- package/scripts/bake-viewmodel-sets.mjs +137 -0
- package/scripts/bake-voxel-ao.mjs +119 -0
- package/scripts/bake-water-ripples.mjs +25 -0
- package/scripts/blender/README.md +129 -0
- package/scripts/blender/build.sh +166 -0
- package/scripts/blender/lib/export-scene.mjs +129 -0
- package/scripts/blender/lib/glb-digest.mjs +188 -0
- package/scripts/blender/lib/glb.py +68 -0
- package/scripts/blender/lib/save_blend.py +17 -0
- package/scripts/blender/lib/world_fixture.py +55 -0
- package/scripts/blender/targets.json +591 -0
- package/scripts/build-sdk.mjs +95 -0
- package/scripts/build-shardfiles.d.mts +7 -0
- package/scripts/build-shardfiles.mjs +206 -0
- package/scripts/capture-hero.mjs +137 -0
- package/scripts/check-lift-review.mjs +23 -0
- package/scripts/chromium-keychain-check.mjs +139 -0
- package/scripts/chromium-keychain.d.mts +1 -0
- package/scripts/chromium-keychain.mjs +5 -0
- package/scripts/compile-script.d.mts +3 -0
- package/scripts/compile-script.mjs +8 -0
- package/scripts/creature-color.mjs +255 -0
- package/scripts/decide/calibrate.py +127 -0
- package/scripts/decide/calibration/2026-10-03/labels-s1.tsv +281 -0
- package/scripts/decide/calibration/2026-10-03/labels-s2.tsv +97 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3.tsv +48 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3b.tsv +26 -0
- package/scripts/decide/calibration/2026-10-03/res-capture-status-v1.jsonl +376 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-strings.jsonl +48 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-v1.jsonl +73 -0
- package/scripts/decide/decide.py +262 -0
- package/scripts/decide/decide.sh +50 -0
- package/scripts/decide/layer-purity-pilot.mjs +41 -0
- package/scripts/decide/sets/capture-status.json +46 -0
- package/scripts/decide/sets/layer-purity.json +28 -0
- package/scripts/decide/sets/text-garbled.json +17 -0
- package/scripts/decide/test_decide.py +37 -0
- package/scripts/docs.mjs +15 -0
- package/scripts/entry-reads/crawl.ts +152 -0
- package/scripts/entry-reads/tsconfig.json +25 -0
- package/scripts/gen-format-schema.d.mts +2 -0
- package/scripts/gen-format-schema.mjs +21 -0
- package/scripts/gen-host-catalogue.d.mts +14 -0
- package/scripts/gen-host-catalogue.mjs +108 -0
- package/scripts/gen-shard-layout-doc.d.mts +4 -0
- package/scripts/gen-shard-layout-doc.mjs +55 -0
- package/scripts/gen-shards.d.mts +17 -0
- package/scripts/gen-shards.mjs +311 -0
- package/scripts/goldens/capture-inputs.d.mts +4 -0
- package/scripts/goldens/capture-inputs.mjs +34 -0
- package/scripts/goldens/colour_shift.py +27 -0
- package/scripts/goldens/native-residency.d.mts +10 -0
- package/scripts/goldens/native-residency.mjs +104 -0
- package/scripts/goldens/plot-inputs.d.mts +12 -0
- package/scripts/goldens/plot-inputs.mjs +46 -0
- package/scripts/gpu-texmem.mjs +98 -0
- package/scripts/horizon-matte/config.py +24 -0
- package/scripts/horizon-matte/encode.py +91 -0
- package/scripts/horizon-matte/key.py +141 -0
- package/scripts/horizon-matte/mkjobs.py +33 -0
- package/scripts/horizon-matte/mkjobs_day2.py +11 -0
- package/scripts/horizon-matte/overlap.py +80 -0
- package/scripts/horizon-matte/run_codex.py +57 -0
- package/scripts/horizon-matte/stitch.py +133 -0
- package/scripts/img2mesh/CC0.md +105 -0
- package/scripts/img2mesh/README.md +209 -0
- package/scripts/img2mesh/ab_board.py +102 -0
- package/scripts/img2mesh/birds/birds.json +255 -0
- package/scripts/img2mesh/birds/birds_atlas.py +150 -0
- package/scripts/img2mesh/birds/birds_fix_preview.mjs +103 -0
- package/scripts/img2mesh/birds/birds_fix_render.py +75 -0
- package/scripts/img2mesh/birds/birds_pack.py +110 -0
- package/scripts/img2mesh/birds/birds_phone_b.py +112 -0
- package/scripts/img2mesh/birds/birds_post.py +550 -0
- package/scripts/img2mesh/birds/birds_render.py +125 -0
- package/scripts/img2mesh/birds/birds_sheet.py +33 -0
- package/scripts/img2mesh/birds/birds_view.py +60 -0
- package/scripts/img2mesh/board.py +100 -0
- package/scripts/img2mesh/build_cc0.sh +52 -0
- package/scripts/img2mesh/build_driftwood.sh +12 -0
- package/scripts/img2mesh/build_faces.sh +53 -0
- package/scripts/img2mesh/build_props.py +81 -0
- package/scripts/img2mesh/cc0_export.py +186 -0
- package/scripts/img2mesh/driftwood_post.py +571 -0
- package/scripts/img2mesh/e304_faces.sh +67 -0
- package/scripts/img2mesh/face_remaster.py +911 -0
- package/scripts/img2mesh/face_views.py +95 -0
- package/scripts/img2mesh/faces-e304.json +9 -0
- package/scripts/img2mesh/faces.json +30 -0
- package/scripts/img2mesh/head_cut.py +100 -0
- package/scripts/img2mesh/hi3d_paint.py +94 -0
- package/scripts/img2mesh/hi3d_refine.py +161 -0
- package/scripts/img2mesh/hunyuan_cpu_rasterizer.sh +42 -0
- package/scripts/img2mesh/pine_hollow_phone.sh +13 -0
- package/scripts/img2mesh/props/coral-arch.json +32 -0
- package/scripts/img2mesh/props/ember-furnace.json +30 -0
- package/scripts/img2mesh/props/night-market-gate.json +10 -0
- package/scripts/img2mesh/render_still.py +86 -0
- package/scripts/img2mesh/rig_strip.mjs +46 -0
- package/scripts/img2mesh/rig_transfer.mjs +104 -0
- package/scripts/img2mesh/split_sheet.py +48 -0
- package/scripts/img2mesh/trellis_batch.py +110 -0
- package/scripts/img2mesh/versus_board.py +114 -0
- package/scripts/import-bundle.d.mts +2 -0
- package/scripts/import-bundle.mjs +20 -0
- package/scripts/ktx2-ab-board.py +133 -0
- package/scripts/ktx2-ab.mjs +111 -0
- package/scripts/ktx2-settings.mjs +18 -0
- package/scripts/land.d.mts +14 -0
- package/scripts/land.mjs +809 -0
- package/scripts/lint-dispatch.mjs +14 -0
- package/scripts/map-bake-frames.d.mts +4 -0
- package/scripts/map-bake-frames.mjs +23 -0
- package/scripts/map-geometry.d.mts +9 -0
- package/scripts/map-geometry.mjs +29 -0
- package/scripts/map-world.mjs +162 -0
- package/scripts/mockup-local.sh +46 -0
- package/scripts/music/export-midi.mjs +68 -0
- package/scripts/music/gen/analyze.py +308 -0
- package/scripts/music/gen/audio_jobs.py +46 -0
- package/scripts/music/gen/briefs.json +51 -0
- package/scripts/music/gen/build_page.py +334 -0
- package/scripts/music/gen/folk.json +3187 -0
- package/scripts/music/gen/gen_ace_step.py +156 -0
- package/scripts/music/gen/gen_heartmula.py +187 -0
- package/scripts/music/gen/gen_minimax.py +143 -0
- package/scripts/music/gen/gen_sao.py +122 -0
- package/scripts/music/gen/gen_sao_small.py +104 -0
- package/scripts/music/gen/gen_sfx.py +98 -0
- package/scripts/music/gen/gen_sfx_ezaudio.py +112 -0
- package/scripts/music/gen/gen_sfx_moss.py +112 -0
- package/scripts/music/gen/models.json +61 -0
- package/scripts/music/gen/nalati-jobs.json +104 -0
- package/scripts/music/gen/nalati-score-build.json +119 -0
- package/scripts/music/gen/nalati-score.json +3448 -0
- package/scripts/music/gen/ob7-fit-decisions.json +38 -0
- package/scripts/music/gen/ob7-score-jobs.json +152 -0
- package/scripts/music/gen/ob7-sfx-jobs.json +897 -0
- package/scripts/music/gen/ob7_build.py +469 -0
- package/scripts/music/gen/ob7_generate.py +67 -0
- package/scripts/music/gen/ob7_run.sh +42 -0
- package/scripts/music/gen/orchestral.json +3187 -0
- package/scripts/music/gen/own_score.py +486 -0
- package/scripts/music/gen/ph-jobs.json +27 -0
- package/scripts/music/gen/ph_page.py +222 -0
- package/scripts/music/gen/piano.json +3175 -0
- package/scripts/music/gen/rank_v3.py +248 -0
- package/scripts/music/gen/sfx-best.json +2486 -0
- package/scripts/music/gen/sfx-ezaudio.json +4082 -0
- package/scripts/music/gen/sfx-jobs.json +57 -0
- package/scripts/music/gen/sfx-minimax-jobs.json +16 -0
- package/scripts/music/gen/sfx-minimax.json +289 -0
- package/scripts/music/gen/sfx-moss.json +4082 -0
- package/scripts/music/gen/sfx-nalati-b3-jobs.json +17 -0
- package/scripts/music/gen/sfx-nalati-jobs.json +338 -0
- package/scripts/music/gen/sfx-nalati.json +11202 -0
- package/scripts/music/gen/sfx-nd-jobs.json +57 -0
- package/scripts/music/gen/sfx-nd-moss.json +2097 -0
- package/scripts/music/gen/sfx-nd-sa3-medium.json +2097 -0
- package/scripts/music/gen/sfx-nd-summary.json +38 -0
- package/scripts/music/gen/sfx-peaks.json +7 -0
- package/scripts/music/gen/sfx-ph-jobs.json +169 -0
- package/scripts/music/gen/sfx-ph-moss.json +6564 -0
- package/scripts/music/gen/sfx-ph-sa3-medium.json +7239 -0
- package/scripts/music/gen/sfx-ph-summary.json +63 -0
- package/scripts/music/gen/sfx-sa3-medium.json +4082 -0
- package/scripts/music/gen/sfx-sa3.json +4082 -0
- package/scripts/music/gen/sfx-summary.json +107 -0
- package/scripts/music/gen/sfx_build.py +332 -0
- package/scripts/music/gen/sfx_merge.py +255 -0
- package/scripts/music/gen/sfx_minimax.py +61 -0
- package/scripts/music/gen/sfx_nalati.py +331 -0
- package/scripts/music/gen/sfx_sprite.py +424 -0
- package/scripts/music/gen/stems.py +539 -0
- package/scripts/music/gen/test_loop_meter.py +29 -0
- package/scripts/music/gen/test_ob7_provenance.py +77 -0
- package/scripts/music/gen/v3-folk-build.json +148 -0
- package/scripts/music/gen/v3-folk.json +1818 -0
- package/scripts/music/gen/v3-jobs.json +145 -0
- package/scripts/music/gen/v3-orchestral-build.json +148 -0
- package/scripts/music/gen/v3-orchestral.json +1813 -0
- package/scripts/music/gen/v3-ph-folk-build.json +94 -0
- package/scripts/music/gen/v3-ph-folk.json +1806 -0
- package/scripts/music/gen/v3-ph-orchestral-build.json +94 -0
- package/scripts/music/gen/v3-ph-orchestral.json +1824 -0
- package/scripts/music/gen/v3-ph-piano-build.json +94 -0
- package/scripts/music/gen/v3-ph-piano.json +1818 -0
- package/scripts/music/gen/v3-piano-build.json +148 -0
- package/scripts/music/gen/v3-piano.json +1813 -0
- package/scripts/music/wildshard-theme.mid +0 -0
- package/scripts/music/wildshard-trailer30.mid +0 -0
- package/scripts/named-blob-output.d.mts +8 -0
- package/scripts/named-blob-output.mjs +48 -0
- package/scripts/pack-all.mjs +15 -0
- package/scripts/pid-lock.d.mts +1 -0
- package/scripts/pid-lock.mjs +63 -0
- package/scripts/practice/bake_dummy.py +53 -0
- package/scripts/practice/build_dummies.sh +43 -0
- package/scripts/practice/dummy_parts.py +568 -0
- package/scripts/practice/dummy_rig_gate.py +139 -0
- package/scripts/practice/gate_sheet.py +36 -0
- package/scripts/practice/generate_dummy_unimate.py +132 -0
- package/scripts/practice/pack_dummy.mjs +59 -0
- package/scripts/practice/repair_dummy_weights.mjs +68 -0
- package/scripts/practice/rig_dummy.py +828 -0
- package/scripts/practice/verify_unimate_skin.mjs +356 -0
- package/scripts/preparation-seed.mjs +15 -0
- package/scripts/prepare-basis-tool.mjs +6 -0
- package/scripts/prepare-product.d.mts +14 -0
- package/scripts/prepare-product.mjs +101 -0
- package/scripts/product-build-tools.d.mts +3 -0
- package/scripts/product-build-tools.json +3 -0
- package/scripts/product-build-tools.mjs +31 -0
- package/scripts/publish-public.mjs +7 -0
- package/scripts/push-tables.d.mts +1 -0
- package/scripts/push-tables.mjs +28 -0
- package/scripts/record-shard-mounts.mjs +133 -0
- package/scripts/sdk-externals.d.mts +2 -0
- package/scripts/sdk-externals.mjs +2 -0
- package/scripts/section-inventory.ts +209 -0
- package/scripts/select-candidate.mjs +15 -0
- package/scripts/shard-build-pool.d.mts +4 -0
- package/scripts/shard-build-pool.mjs +53 -0
- package/scripts/shard-line-baseline.json +17 -0
- package/scripts/shard-milestones.d.mts +15 -0
- package/scripts/shard-milestones.mjs +105 -0
- package/scripts/shard-output-report.d.mts +9 -0
- package/scripts/shard-output-report.mjs +85 -0
- package/scripts/shard-platform-cli.mjs +93 -0
- package/scripts/shard-progress.mjs +212 -0
- package/scripts/shard-timelapse.py +102 -0
- package/scripts/shardfile-cold-boot.mjs +79 -0
- package/scripts/shardfile-vite.d.mts +4 -0
- package/scripts/shardfile-vite.mjs +20 -0
- package/scripts/simplify-models.mjs +24 -0
- package/scripts/site-facts.mjs +88 -0
- package/scripts/test-template-gate.mjs +44 -0
- package/scripts/test_golden_compare.py +68 -0
- package/scripts/tex-tiers.cache.json +181 -0
- package/scripts/tex-tiers.mjs +240 -0
- package/scripts/texmem-probe.mjs +184 -0
- package/scripts/unused-assets.mjs +173 -0
- package/scripts/vite-tmp.d.mts +23 -0
- package/scripts/vite-tmp.mjs +157 -0
- package/scripts/wave-line-baselines.json +32 -0
- package/scripts/wildshard.d.mts +4 -0
- package/scripts/wildshard.mjs +105 -0
- package/scripts/witness-checkpoints.d.mts +10 -0
- package/scripts/witness-checkpoints.mjs +84 -0
- package/scripts/witness-generation.d.mts +10 -0
- package/scripts/witness-generation.mjs +45 -0
- package/scripts/witness-manifests.d.mts +8 -0
- package/scripts/witness-manifests.mjs +157 -0
- package/scripts/worktree-ignore.d.mts +4 -0
- package/scripts/worktree-ignore.mjs +36 -0
- package/scripts/worktree-reap.mjs +214 -0
- package/scripts/worktree.mjs +396 -0
- package/scripts/worldclaw/capture-front.sh +28 -0
- package/scripts/worldclaw/design-template.md +62 -0
- package/scripts/worldclaw/spec-map.py +92 -0
- package/scripts/worldclaw/spec.ts +96 -0
- package/skills/wildshard/SKILL.md +50 -0
- package/skills/wildshard-goldens/SKILL.md +54 -0
- package/skills/wildshard-mockup-to-model/SKILL.md +56 -0
- package/skills/wildshard-upgrade/SKILL.md +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,443 @@
|
|
|
1
|
+
import { Box3, BufferAttribute, BufferGeometry, Float16BufferAttribute, Float32BufferAttribute, Matrix3, Matrix4, Mesh, MeshStandardMaterial, SkinnedMesh, Vector3, type Object3D } from 'three';
|
|
2
|
+
import { CONTENT_CAPS, CELL_ABOVE, CELL_BELOW } from '@wildshard/format/contentBounds';
|
|
3
|
+
import { PropsSchema, type ShardProps } from '@wildshard/format/props';
|
|
4
|
+
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
5
|
+
import * as v from 'valibot';
|
|
6
|
+
import { parseGlb, parseKtx2 } from '../assets';
|
|
7
|
+
import { hashImmutableBytes as contentHash } from '../immutable';
|
|
8
|
+
import { staticGlb, type GlbPrimitive } from './glb';
|
|
9
|
+
import { compressGlb } from './glbCompression';
|
|
10
|
+
import { tileGrid, tileGridTransform, type TileGrid } from './worldGeometry';
|
|
11
|
+
import { positionErrorScale, floatPositionError, gridPositionError } from './geometryError';
|
|
12
|
+
|
|
13
|
+
/** A reusable scatter shape and its world-local positive TRS matrices; generators run only at build time. */
|
|
14
|
+
export interface PropScatter { model: Object3D; transforms: readonly Matrix4[] }
|
|
15
|
+
/** Trusted static content. Named panels remain separate, and coarse/far replacements are optional build-time inputs. */
|
|
16
|
+
export interface PropsBakeSource {
|
|
17
|
+
static: Object3D; scatter?: readonly PropScatter[];
|
|
18
|
+
/** A panel draws in `materialName` (a `props.materials` name; omitted: the merged surfaces' own) and casts a shadow unless
|
|
19
|
+
* `castShadow` is false: a shadowless panel costs each L0 tile it touches one draw, not two. Omitted keeps native bytes. */
|
|
20
|
+
panels?: readonly { id: string; model: Object3D; visible?: boolean; materialName?: string; castShadow?: boolean }[]; colliders?: ShardProps['colliders']; models?: readonly { id: string; model: Object3D }[];
|
|
21
|
+
/** Achieved source simplification error in world metres, before tile storage rounding. */
|
|
22
|
+
coarseErrorMetres?: number;
|
|
23
|
+
coarse?: Object3D; far?: Object3D; family?: string; colourTexture?: Uint8Array;
|
|
24
|
+
/** GLB material name for merged surfaces; bind it through props.materials. Omitted keeps native unnamed bytes. */
|
|
25
|
+
materialName?: string;
|
|
26
|
+
/** Lossless meshopt tile transport, selected only when it reduces bytes.
|
|
27
|
+
* Library/panel/far bytes stay unchanged; omitted keeps pinned native bytes. */
|
|
28
|
+
tileCompression?: 'meshopt';
|
|
29
|
+
/** Optional named-tile transport, after geometry emission and before hash/cost derivation.
|
|
30
|
+
* Receives owned bytes; only tile files invoke it, never libraries, panels or far proxies.
|
|
31
|
+
* The compiler copies the returned bytes so retained encoder buffers cannot mutate output. */
|
|
32
|
+
encodeTileBlob?: (name: string, bytes: Uint8Array) => Uint8Array;
|
|
33
|
+
/** G748 / tile streaming T8: whole shapes simplified for the L1 tiles, each kept whole with its own channels in the L1 tile
|
|
34
|
+
* holding its origin (never partitioned; a shard whose look lives in custom channels keeps it far away too). */
|
|
35
|
+
coarseWhole?: readonly PropWhole[];
|
|
36
|
+
/** Shapes baked whole (`PropWhole`), each one named node in the L0 tile that holds its origin. */
|
|
37
|
+
whole?: readonly PropWhole[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A mesh kept whole in its own frame, never cut at a tile seam: one GLB node named `id` (a loader-safe identifier) at
|
|
41
|
+
* `transform` (positive TRS) with the mesh's own attributes and index (or none), owned by the L0 tile holding its origin (in no coarse tile
|
|
42
|
+
* and no far proxy: a whole shape is never decimated), so a runtime drawing it in its own material finds it by name and draws exactly the triangles it built. Its surface is opaque,
|
|
43
|
+
* untextured, nonmetal and white (the colour is the vertices'); the GLB keeps its roughness and its `castShadow`.
|
|
44
|
+
*/
|
|
45
|
+
export interface PropWhole {
|
|
46
|
+
id: string; mesh: Mesh; transform: Matrix4;
|
|
47
|
+
/** Accumulated achieved source simplification error, in the geometry's local metres. */
|
|
48
|
+
geometricError?: number;
|
|
49
|
+
/** Preserve an explicit receive-shadow flag; omitted keeps the tile reader's existing true default. */
|
|
50
|
+
receiveShadow?: boolean;
|
|
51
|
+
/** GLB surface name for this unchanged whole shape; overrides PropsBakeSource.materialName. */
|
|
52
|
+
materialName?: string;
|
|
53
|
+
/** Application semantic → source channel, retained whole beside positions, normals and colours. */
|
|
54
|
+
customAttributes?: GlbPrimitive['customAttributes'];
|
|
55
|
+
/** Preserve typed channels and source transform doubles in GLB node extras (see staticGlb). */
|
|
56
|
+
nativeAttributes?: true;
|
|
57
|
+
/** Assign each unchanged triangle to its world-space centroid's tile; extras retain exact assembly ordinals.
|
|
58
|
+
* `'runs'` writes those ordinals as `{ runs }` (`wholePartitionRuns`): the same assembly, far fewer JSON bytes. */
|
|
59
|
+
partition?: true | 'runs';
|
|
60
|
+
/** Declared visual edge allowance; default zero, hard capped at one metre. No vertex is clipped. */
|
|
61
|
+
overhang?: number;
|
|
62
|
+
/** iPhone downloads I3: ship a native shape's normals / colours as Int8 / Uint8 and, partitioned, its positions on one
|
|
63
|
+
* Int16 grid (`compactWholeChannels`, `wholeGrid`); its readers restore them within their storage step. Opt-in, so a
|
|
64
|
+
* producer whose retained tile hashes are pinned keeps its exact bytes. */
|
|
65
|
+
compact?: true;
|
|
66
|
+
/** With `compact`: a shape whose colours leave [0, 1] (a glow) still ships on its grid with Int8 normals, its colours
|
|
67
|
+
* float32 (`compactWholeNormals`). Opt-in apart, so a producer already on `compact` keeps its bytes. */
|
|
68
|
+
compactGlow?: true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** One exact subset of a whole geometry. Ordinals address the original vertices and triangles, not clipped fragments. */
|
|
72
|
+
export interface WholeGeometryPart { x: number; z: number; geometry: BufferGeometry; vertices: number[]; triangles: number[] }
|
|
73
|
+
interface PreparedWhole {
|
|
74
|
+
id: string; at: Vector3; castShadow: boolean; geometry: BufferGeometry; material: MeshStandardMaterial; transform: Matrix4;
|
|
75
|
+
customAttributes: GlbPrimitive['customAttributes']; nativeAttributes: GlbPrimitive['nativeAttributes'];
|
|
76
|
+
owner: { x: number; z: number } | null; extras: GlbPrimitive['extras'];
|
|
77
|
+
/** I3: the normals / colours are normalized Int8 / Uint8 on the wire (`compactWholeChannels`) */
|
|
78
|
+
quantized: boolean;
|
|
79
|
+
geometricError: number;
|
|
80
|
+
/** I3: the shape opted into `compact` (its native channels are written once, `nativeOnce`) */
|
|
81
|
+
compact: boolean;
|
|
82
|
+
/** I3: a partition's positions are unnormalized Int16 on its whole shape's one grid (node = transform x grid) */
|
|
83
|
+
grid?: TileGrid;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function subsetAttribute(attribute: BufferAttribute, selected: readonly number[]): BufferAttribute {
|
|
87
|
+
const array = attribute.array.slice(0, selected.length * attribute.itemSize);
|
|
88
|
+
// slice above may be smaller than the requested size only if callers repeat vertices (partitioning deduplicates).
|
|
89
|
+
if (array.length !== selected.length * attribute.itemSize) throw new Error('Whole geometry subset exceeds source vertices');
|
|
90
|
+
// Adjacent ordinals are copied as one raw run, preserving every storage bit.
|
|
91
|
+
for (let i = 0; i < selected.length;) {
|
|
92
|
+
const vertex = selected[i];
|
|
93
|
+
if (vertex === undefined) throw new Error('Missing whole geometry vertex');
|
|
94
|
+
let end = i + 1;
|
|
95
|
+
while (end < selected.length && selected[end] === vertex + end - i) end++;
|
|
96
|
+
array.set(attribute.array.subarray(vertex * attribute.itemSize, (vertex + end - i) * attribute.itemSize), i * attribute.itemSize);
|
|
97
|
+
i = end;
|
|
98
|
+
}
|
|
99
|
+
return attribute instanceof Float16BufferAttribute ? new Float16BufferAttribute(array, attribute.itemSize, attribute.normalized)
|
|
100
|
+
: new BufferAttribute(array, attribute.itemSize, attribute.normalized);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Run-length form of whole-partition ordinals: `[start, length, …]` for each ascending run of consecutive ordinals.
|
|
104
|
+
* The game's whole-geometry reader expands it to the identical list (`assembleWholeGeometryViews`). */
|
|
105
|
+
export function wholePartitionRuns(list: readonly number[]): { runs: number[] } {
|
|
106
|
+
const runs: number[] = [];
|
|
107
|
+
for (let at = 0; at < list.length;) {
|
|
108
|
+
const start = list[at]; if (start === undefined) break;
|
|
109
|
+
let length = 1;
|
|
110
|
+
while (list[at + length] === start + length) length++;
|
|
111
|
+
runs.push(start, length); at += length;
|
|
112
|
+
}
|
|
113
|
+
return { runs };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Partition triangles without clipping or rounding any source channel; world transforms affect ownership only. */
|
|
117
|
+
export function partitionWholeGeometry(sourceGeometry: BufferGeometry, transform: Matrix4 = new Matrix4(), overhang = 0): WholeGeometryPart[] {
|
|
118
|
+
if (!Number.isFinite(overhang) || overhang < 0 || overhang > 1) throw new Error('Invalid whole overhang');
|
|
119
|
+
const position = sourceGeometry.getAttribute('position'), index = sourceGeometry.getIndex(), count = index?.count ?? position.count;
|
|
120
|
+
if (count % 3 !== 0) throw new Error('Whole geometry requires triangles');
|
|
121
|
+
const groups = new Map<string, { x: number; z: number; vertices: number[]; triangles: number[]; indices: number[]; lookup: Map<number, number> }>();
|
|
122
|
+
const active = new Map<string, number>();
|
|
123
|
+
const point = new Vector3(), centroid = new Vector3();
|
|
124
|
+
for (let triangle = 0; triangle < count / 3; triangle++) {
|
|
125
|
+
const ids = [0, 1, 2].map(corner => index?.getX(triangle * 3 + corner) ?? triangle * 3 + corner);
|
|
126
|
+
centroid.set(0, 0, 0);
|
|
127
|
+
for (const vertex of ids) centroid.add(point.fromBufferAttribute(position, vertex).applyMatrix4(transform));
|
|
128
|
+
centroid.multiplyScalar(1 / 3);
|
|
129
|
+
const ownedAddress = (value: number): number => overhang === 0 ? Math.min(7, Math.floor((value + 250) / 62.5)) : Math.max(0, Math.min(7, Math.floor((value + 250) / 62.5)));
|
|
130
|
+
const x = ownedAddress(centroid.x), z = ownedAddress(centroid.z);
|
|
131
|
+
if (!Number.isFinite(centroid.x) || !Number.isFinite(centroid.z) || x < 0 || z < 0 || Math.abs(centroid.x) > 250 + overhang || Math.abs(centroid.z) > 250 + overhang) throw new Error('Whole triangle centroid outside the cell');
|
|
132
|
+
const address = `${x}/${z}`;
|
|
133
|
+
let segment = active.get(address) ?? 0;
|
|
134
|
+
if ((groups.get(`${address}/${segment}`)?.triangles.length ?? 0) >= 10000) { segment++; active.set(address, segment); }
|
|
135
|
+
const key = `${address}/${segment}`, group = groups.get(key) ?? { x, z, vertices: [], triangles: [], indices: [], lookup: new Map<number, number>() };
|
|
136
|
+
group.triangles.push(triangle);
|
|
137
|
+
for (const vertex of ids) {
|
|
138
|
+
let local = group.lookup.get(vertex);
|
|
139
|
+
if (local === undefined) { local = group.vertices.length; group.lookup.set(vertex, local); group.vertices.push(vertex); }
|
|
140
|
+
group.indices.push(local);
|
|
141
|
+
}
|
|
142
|
+
groups.set(key, group);
|
|
143
|
+
}
|
|
144
|
+
// Unreferenced authored vertices still belong to the exact source layout; carry them in the first occupied tile.
|
|
145
|
+
const first = groups.values().next().value;
|
|
146
|
+
if (first !== undefined) {
|
|
147
|
+
const referenced = new Set([...groups.values()].flatMap(group => group.vertices));
|
|
148
|
+
for (let vertex = 0; vertex < position.count; vertex++) if (!referenced.has(vertex)) first.vertices.push(vertex);
|
|
149
|
+
}
|
|
150
|
+
return [...groups.values()].sort((a, b) => a.x - b.x || a.z - b.z).map(group => {
|
|
151
|
+
const part = new BufferGeometry();
|
|
152
|
+
for (const [name, attribute] of Object.entries(sourceGeometry.attributes)) {
|
|
153
|
+
if (!(attribute instanceof BufferAttribute)) throw new Error('Whole geometry requires non-interleaved channels');
|
|
154
|
+
part.setAttribute(name, subsetAttribute(attribute, group.vertices));
|
|
155
|
+
}
|
|
156
|
+
if (index !== null) part.setIndex(new BufferAttribute(index.array instanceof Uint16Array ? new Uint16Array(group.indices) : new Uint32Array(group.indices), 1));
|
|
157
|
+
return { x: group.x, z: group.z, geometry: part, vertices: group.vertices, triangles: group.triangles };
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/** iPhone downloads I3: a native whole shape's float vec3 normals become normalized Int8 (within ~0.5 degree) and its
|
|
161
|
+
* float colours in [0, 1] normalized Uint8 (within 1/510), each written once as its own typed accessor
|
|
162
|
+
* (`quantizedChannels`); the shape's exact-copy readers restore those stored values. False, changing nothing, when a
|
|
163
|
+
* channel cannot be stored that way. A vec4 normal is a shader channel and stays as it is. */
|
|
164
|
+
/** I3: the shape's position grid in its own space (RM8.1's power-of-two grid: the finest step its extent fits in 16 bits),
|
|
165
|
+
* or none when a position is not plain float32. */
|
|
166
|
+
export function wholeGrid(g: BufferGeometry): TileGrid | undefined {
|
|
167
|
+
const position = g.getAttribute('position');
|
|
168
|
+
if (!(position instanceof BufferAttribute) || !(position.array instanceof Float32Array) || position.itemSize !== 3) return undefined;
|
|
169
|
+
const box = new Box3().setFromBufferAttribute(position);
|
|
170
|
+
try { return tileGrid(box); } catch { return undefined; }
|
|
171
|
+
}
|
|
172
|
+
/** A partition's float positions as unnormalized Int16 on `grid` (within half its step). */
|
|
173
|
+
export function gridPositions(g: BufferGeometry, grid: TileGrid): void {
|
|
174
|
+
const position = g.getAttribute('position'), out = new Int16Array(position.count * 3);
|
|
175
|
+
for (let i = 0; i < position.count; i++) for (let c = 0; c < 3; c++) out[i * 3 + c] = Math.round((position.getComponent(i, c) - (grid.origin[c] ?? 0)) / grid.step);
|
|
176
|
+
g.setAttribute('position', new BufferAttribute(out, 3));
|
|
177
|
+
}
|
|
178
|
+
/** I3: Int8 normals and Uint8 colours in place when every float value fits (false, unchanged, when neither does). */
|
|
179
|
+
export function compactWholeChannels(g: BufferGeometry): boolean {
|
|
180
|
+
const normal = g.hasAttribute('normal') ? g.getAttribute('normal') : undefined, colour = g.hasAttribute('color') ? g.getAttribute('color') : undefined;
|
|
181
|
+
const floatNormal = normal instanceof BufferAttribute && normal.itemSize === 3 && normal.array instanceof Float32Array;
|
|
182
|
+
const okNormal = normal === undefined || floatNormal || (normal instanceof BufferAttribute && normal.itemSize === 4)
|
|
183
|
+
|| (normal instanceof BufferAttribute && normal.array instanceof Int8Array && normal.normalized);
|
|
184
|
+
const floatColour = colour instanceof BufferAttribute && colour.array instanceof Float32Array && colour.array.every(value => value >= 0 && value <= 1);
|
|
185
|
+
const okColour = colour === undefined || floatColour || (colour instanceof BufferAttribute && colour.normalized && !(colour.array instanceof Float32Array));
|
|
186
|
+
if (!okNormal || !okColour || (!floatNormal && !floatColour)) return false;
|
|
187
|
+
if (floatNormal) g.setAttribute('normal', new BufferAttribute(Int8Array.from(normal.array, value => Math.max(-127, Math.min(127, Math.round(value * 127)))), 3, true));
|
|
188
|
+
if (floatColour) g.setAttribute('color', new BufferAttribute(Uint8Array.from(colour.array, value => Math.round(value * 255)), colour.itemSize, true));
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
/** I3: only the normals as normalized Int8 (within ~0.5 degree), for a shape whose colours leave [0, 1] (a glow): they stay
|
|
192
|
+
* float32 (staticGlb's `quantizedChannels` writes a float colour as it is). False, unchanged, without a float vec3 normal. */
|
|
193
|
+
export function compactWholeNormals(g: BufferGeometry): boolean {
|
|
194
|
+
const normal = g.hasAttribute('normal') ? g.getAttribute('normal') : undefined;
|
|
195
|
+
if (!(normal instanceof BufferAttribute) || normal.itemSize !== 3 || !(normal.array instanceof Float32Array)) return false;
|
|
196
|
+
g.setAttribute('normal', new BufferAttribute(Int8Array.from(normal.array, value => Math.max(-127, Math.min(127, Math.round(value * 127)))), 3, true));
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
/** The look graphs (id -> `{ nodes: { [id]: { op } } }`) that read a vertex's object-space position (`positionLocal` /
|
|
200
|
+
* `positionGeometry`): a shape drawn through one keeps its exact float positions, never a grid. */
|
|
201
|
+
export function objectSpaceLooks(graphs: Readonly<Record<string, unknown>>): Set<string> {
|
|
202
|
+
const reads = (graph: unknown): boolean => {
|
|
203
|
+
if (typeof graph !== 'object' || graph === null || !('nodes' in graph) || typeof graph.nodes !== 'object' || graph.nodes === null) return false;
|
|
204
|
+
return Object.values(graph.nodes).some((node: unknown) => typeof node === 'object' && node !== null && 'op' in node && (node.op === 'positionLocal' || node.op === 'positionGeometry'));
|
|
205
|
+
};
|
|
206
|
+
return new Set(Object.entries(graphs).filter(([, graph]) => reads(graph)).map(([id]) => id));
|
|
207
|
+
}
|
|
208
|
+
/** Content-addressed GLBs and tile rows, including actual budget numbers and an independent far proxy (none for whole shapes alone). */
|
|
209
|
+
export interface BakedProps {
|
|
210
|
+
props: ShardProps; tiles: Shardfile['tiles']; files: Shardfile['files']; library: string[];
|
|
211
|
+
far: NonNullable<Shardfile['far']> | null; assets: Map<string, Uint8Array>;
|
|
212
|
+
report: readonly { lod: number; x: number; z: number; resident: number; compressed: number; triangles: number; draws: number; warnings?: readonly string[] }[];
|
|
213
|
+
}
|
|
214
|
+
interface Vertex { p: Vector3; n: Vector3; c: Vector3; u: number; v: number }
|
|
215
|
+
function isMesh(object: Object3D): object is Mesh { return object instanceof Mesh; }
|
|
216
|
+
function vertices(root: Object3D, transform = new Matrix4(), rough = true): Vertex[][] {
|
|
217
|
+
root.updateMatrixWorld(true); const result: Vertex[][] = [];
|
|
218
|
+
root.traverse((object) => {
|
|
219
|
+
if (!isMesh(object)) return;
|
|
220
|
+
if (object instanceof SkinnedMesh || Array.isArray(object.material) || !(object.material instanceof MeshStandardMaterial) || object.material.transparent || object.material.metalness !== 0 || (rough && object.material.roughness !== 1) || object.material.map !== null) throw new Error('Static merge needs opaque untextured nonmetal rough surfaces; bake textured shapes as scatter');
|
|
221
|
+
const g = object.geometry; if (!g.hasAttribute('position') || !g.hasAttribute('normal')) throw new Error('Static prop needs positions and normals');
|
|
222
|
+
const p = g.getAttribute('position'), normal = g.getAttribute('normal'), uv = g.hasAttribute('uv') ? g.getAttribute('uv') : undefined, colour = g.hasAttribute('color') ? g.getAttribute('color') : undefined, index = g.getIndex();
|
|
223
|
+
const matrix = transform.clone().multiply(object.matrixWorld), n = index?.count ?? p.count;
|
|
224
|
+
if (n % 3 !== 0) throw new Error('Static prop needs triangles');
|
|
225
|
+
for (let i = 0; i < n; i += 3) {
|
|
226
|
+
const triangle: Vertex[] = [];
|
|
227
|
+
for (let j = 0; j < 3; j++) {
|
|
228
|
+
const at = index?.getX(i + j) ?? i + j, point = new Vector3().fromBufferAttribute(p, at).applyMatrix4(matrix);
|
|
229
|
+
if (![point.x, point.y, point.z].every(Number.isFinite) || Math.abs(point.x) > 250 || Math.abs(point.z) > 250 || point.y < -CELL_BELOW || point.y > CELL_ABOVE) throw new Error('Prop outside the cell');
|
|
230
|
+
const c = colour === undefined ? new Vector3(1, 1, 1) : new Vector3().fromBufferAttribute(colour, at);
|
|
231
|
+
c.multiply(new Vector3(...object.material.color));
|
|
232
|
+
triangle.push({ p: point, n: new Vector3().fromBufferAttribute(normal, at).applyNormalMatrix(new Matrix3().getNormalMatrix(matrix)), c, u: uv?.getX(at) ?? 0, v: uv?.getY(at) ?? 0 });
|
|
233
|
+
}
|
|
234
|
+
result.push(triangle);
|
|
235
|
+
}
|
|
236
|
+
}); return result;
|
|
237
|
+
}
|
|
238
|
+
function geometry(triangles: readonly Vertex[][], bounds?: readonly [number, number, number, number], storageError?: (metres: number) => void): BufferGeometry {
|
|
239
|
+
const positions: number[] = [], normals: number[] = [], colours: number[] = [], uvs: number[] = [];
|
|
240
|
+
for (const triangle of triangles) {
|
|
241
|
+
let polygon = [...triangle];
|
|
242
|
+
if (bounds !== undefined) for (const [axis, limit, direction] of [['x', bounds[0], 1], ['x', bounds[1], -1], ['z', bounds[2], 1], ['z', bounds[3], -1]] as const) {
|
|
243
|
+
const input = polygon; polygon = [];
|
|
244
|
+
for (let i = 0; i < input.length; i++) {
|
|
245
|
+
const a = input[i], b = input[(i + 1) % input.length]; if (a === undefined || b === undefined) continue;
|
|
246
|
+
const da = (a.p[axis] - limit) * direction, db = (b.p[axis] - limit) * direction;
|
|
247
|
+
if (da >= 0) polygon.push(a);
|
|
248
|
+
if ((da < 0) !== (db < 0)) { const t = da / (da - db); polygon.push({ p: a.p.clone().lerp(b.p, t), n: a.n.clone().lerp(b.n, t).normalize(), c: a.c.clone().lerp(b.c, t), u: a.u + (b.u - a.u) * t, v: a.v + (b.v - a.v) * t }); }
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (let i = 1; i + 1 < polygon.length; i++) {
|
|
252
|
+
const a = polygon[0], b = polygon[i], c = polygon[i + 1]; if (a === undefined || b === undefined || c === undefined || new Vector3().subVectors(b.p, a.p).cross(new Vector3().subVectors(c.p, a.p)).lengthSq() < 1e-16) continue;
|
|
253
|
+
for (const vertex of [a, b, c]) { positions.push(...vertex.p); normals.push(...vertex.n); colours.push(...vertex.c); uvs.push(vertex.u, vertex.v); }
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
storageError?.(floatPositionError(positions));
|
|
257
|
+
return new BufferGeometry().setAttribute('position', new Float32BufferAttribute(positions, 3)).setAttribute('normal', new Float32BufferAttribute(normals, 3)).setAttribute('color', new Float32BufferAttribute(colours, 3)).setAttribute('uv', new Float32BufferAttribute(uvs, 2));
|
|
258
|
+
}
|
|
259
|
+
const mergedMaterial = (name?: string): MeshStandardMaterial => {
|
|
260
|
+
const material = new MeshStandardMaterial({ color: 0xffffff, vertexColors: true });
|
|
261
|
+
material.name = name ?? ''; return material;
|
|
262
|
+
};
|
|
263
|
+
/** Merge props into the canonical 8×8 / 4×4 grid, instance L0 scatter, and refuse every over-budget output. */
|
|
264
|
+
export function bakeProps(source: PropsBakeSource, terrain: readonly Shardfile['tiles'][number][] = []): BakedProps {
|
|
265
|
+
if (!Number.isFinite(source.coarseErrorMetres ?? 0) || (source.coarseErrorMetres ?? 0) < 0) throw new Error('Invalid coarse source error');
|
|
266
|
+
const tileWarnings = new Map<string, readonly string[]>();
|
|
267
|
+
const files: Shardfile['files'] = [], assets = new Map<string, Uint8Array>(), library: string[] = [], tiles = terrain.map((t) => ({ ...t, files: [...t.files], bounds: { min: [...t.bounds.min] as [number, number, number], max: [...t.bounds.max] as [number, number, number] } }));
|
|
268
|
+
const section: ShardProps = { version: 1, family: source.family ?? 'pbr', tiles: [], panels: [], models: [], far: null, textures: [], colliders: source.colliders ?? [] };
|
|
269
|
+
const store = (bytes: Uint8Array, kind: 'glb' | 'ktx2'): Shardfile['files'][number] => {
|
|
270
|
+
const hash = contentHash(bytes), cost = kind === 'glb' ? parseGlb(bytes) : parseKtx2(bytes);
|
|
271
|
+
const row = { hash, kind, compressed: bytes.length, ...cost, dependencies: [] as string[], critical: false };
|
|
272
|
+
if (!assets.has(hash)) { assets.set(hash, bytes); files.push(row); } return row;
|
|
273
|
+
};
|
|
274
|
+
const texture = source.colourTexture === undefined ? null : store(source.colourTexture, 'ktx2');
|
|
275
|
+
const save = (primitives: readonly GlbPrimitive[], name: string, tile = false) => {
|
|
276
|
+
const original = staticGlb(primitives, name);
|
|
277
|
+
const packed = tile && source.tileCompression === 'meshopt' ? compressGlb(original) : original;
|
|
278
|
+
const selected = packed.length < original.length ? packed : original;
|
|
279
|
+
const encoded = tile && source.encodeTileBlob !== undefined ? source.encodeTileBlob(name, Uint8Array.from(selected)) : selected;
|
|
280
|
+
if (!(encoded instanceof Uint8Array) || !(encoded.buffer instanceof ArrayBuffer)) throw new Error('Tile encoder must return owned numeric bytes');
|
|
281
|
+
const row = store(tile && source.encodeTileBlob !== undefined ? Uint8Array.from(encoded) : encoded, 'glb');
|
|
282
|
+
if (texture !== null) { row.dependencies = [texture.hash]; const prior = files.find((f) => f.hash === row.hash); if (prior !== undefined) prior.dependencies = row.dependencies; section.textures.push({ model: row.hash, colour: texture.hash }); }
|
|
283
|
+
return row;
|
|
284
|
+
};
|
|
285
|
+
const overhang = Math.max(0, ...(source.whole ?? []).map(entry => entry.overhang ?? 0));
|
|
286
|
+
if (!Number.isFinite(overhang) || overhang > 1 || (source.whole ?? []).some(entry => !Number.isFinite(entry.overhang ?? 0) || (entry.overhang ?? 0) < 0)) throw new Error('Invalid whole overhang');
|
|
287
|
+
if (overhang > 0) section.overhang = overhang;
|
|
288
|
+
const prepareWhole = (entries: readonly PropWhole[]): PreparedWhole[] => entries.flatMap((entry): PreparedWhole[] => {
|
|
289
|
+
if (!Number.isFinite(entry.geometricError ?? 0) || (entry.geometricError ?? 0) < 0) throw new Error('Invalid whole source error');
|
|
290
|
+
const { mesh } = entry, at = new Vector3().setFromMatrixPosition(entry.transform), m = mesh.material;
|
|
291
|
+
if (!(at.x >= -250 && at.x < 250 && at.z >= -250 && at.z < 250)) throw new Error(`Whole prop ${entry.id} origin outside the cell`);
|
|
292
|
+
if (!(m instanceof MeshStandardMaterial) || m.transparent || m.metalness !== 0 || m.map !== null || m.color.getHex() !== 0xffffff) throw new Error(`Whole prop ${entry.id} needs one opaque untextured nonmetal white surface`);
|
|
293
|
+
if (entry.nativeAttributes === true || entry.partition !== undefined) {
|
|
294
|
+
// Native whole draws can be unlit, so normals are not a required source channel. Inspect bounds without
|
|
295
|
+
// constructing lit merge vertices or inventing shader attributes; the original channels reach the GLB unchanged.
|
|
296
|
+
if (mesh instanceof SkinnedMesh) throw new Error('Whole prop must be static');
|
|
297
|
+
const position: unknown = mesh.geometry.getAttribute('position'), index = mesh.geometry.getIndex(), point = new Vector3();
|
|
298
|
+
if (!(position instanceof BufferAttribute) || position.itemSize !== 3 || (index?.count ?? position.count) % 3 !== 0) throw new Error('Whole prop needs triangle positions');
|
|
299
|
+
for (let vertex = 0; vertex < position.count; vertex++) {
|
|
300
|
+
point.fromBufferAttribute(position, vertex).applyMatrix4(entry.transform);
|
|
301
|
+
if (![point.x, point.y, point.z].every(Number.isFinite) || Math.abs(point.x) > 250 + (entry.overhang ?? 0) || Math.abs(point.z) > 250 + (entry.overhang ?? 0) || point.y < -CELL_BELOW || point.y > CELL_ABOVE) throw new Error('Prop outside the cell');
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
const placed = new Mesh(mesh.geometry, m); placed.applyMatrix4(entry.transform); vertices(placed, new Matrix4(), false); // refuses a shape outside the cell
|
|
305
|
+
}
|
|
306
|
+
// the shape's own attributes and index, untouched: the runtime draws exactly the triangles it built
|
|
307
|
+
const g = new BufferGeometry();
|
|
308
|
+
const retain = entry.partition !== undefined || entry.nativeAttributes === true;
|
|
309
|
+
const channels = retain ? Object.keys(mesh.geometry.attributes) : ['position', 'normal', 'color', ...Object.values(entry.customAttributes ?? {})];
|
|
310
|
+
for (const key of channels) if (mesh.geometry.hasAttribute(key)) g.setAttribute(key, mesh.geometry.getAttribute(key));
|
|
311
|
+
g.setIndex(mesh.geometry.getIndex());
|
|
312
|
+
const quantized = retain && entry.compact === true && (compactWholeChannels(g) || (entry.compactGlow === true && compactWholeNormals(g)));
|
|
313
|
+
const automatic = Object.fromEntries(Object.keys(g.attributes)
|
|
314
|
+
.filter(key => !['position', 'normal', 'color', 'uv', 'tangent'].includes(key) && !Object.values(entry.customAttributes ?? {}).includes(key)).map((key, i) => [`_WS_CHANNEL_${i}`, key]));
|
|
315
|
+
const customAttributes = retain ? { ...automatic, ...entry.customAttributes } : entry.customAttributes;
|
|
316
|
+
const material = new MeshStandardMaterial({ color: 0xffffff, vertexColors: true, roughness: m.roughness });
|
|
317
|
+
material.name = entry.materialName ?? source.materialName ?? '';
|
|
318
|
+
const base = { id: entry.id, at, castShadow: mesh.castShadow, geometry: g, material, transform: entry.transform, customAttributes,
|
|
319
|
+
geometricError: (entry.geometricError ?? 0) * positionErrorScale(entry.transform),
|
|
320
|
+
nativeAttributes: entry.partition !== undefined ? true as const : entry.nativeAttributes, quantized, compact: entry.compact === true };
|
|
321
|
+
const shadowExtras = entry.receiveShadow === undefined ? {} : { receiveShadow: entry.receiveShadow };
|
|
322
|
+
if (entry.partition === undefined) return [{ ...base, owner: null, extras: entry.receiveShadow === undefined ? undefined : shadowExtras }];
|
|
323
|
+
const ordinals = entry.partition === 'runs' ? wholePartitionRuns : (list: number[]): number[] => list;
|
|
324
|
+
const preparedParts: PreparedWhole[] = [];
|
|
325
|
+
// I3: one grid for the whole shape in its own space, so a vertex two partitions share lands on the same grid point
|
|
326
|
+
const grid = quantized ? wholeGrid(g) : undefined;
|
|
327
|
+
for (const part of partitionWholeGeometry(g, entry.transform, entry.overhang ?? 0)) {
|
|
328
|
+
const storageError = grid === undefined ? 0 : gridPositionError(part.geometry, grid, entry.transform);
|
|
329
|
+
if (grid !== undefined) gridPositions(part.geometry, grid);
|
|
330
|
+
const prepared: PreparedWhole = { ...base, geometricError: base.geometricError + storageError, id: `${entry.id}_p${part.x}_${part.z}_n${preparedParts.length}`, geometry: part.geometry, ...(grid === undefined ? {} : { grid }),
|
|
331
|
+
owner: { x: part.x, z: part.z }, extras: { ...shadowExtras, wholePartition: { id: entry.id, vertices: ordinals(part.vertices), triangles: ordinals(part.triangles),
|
|
332
|
+
vertexCount: g.getAttribute('position').count, indexCount: g.getIndex()?.count ?? 0,
|
|
333
|
+
index: g.getIndex() === null ? 'none' : g.getIndex()?.array instanceof Uint16Array ? 'u16' : 'u32',
|
|
334
|
+
...(grid === undefined ? {} : { grid: { origin: [...grid.origin], step: grid.step } }) } } };
|
|
335
|
+
preparedParts.push(prepared);
|
|
336
|
+
}
|
|
337
|
+
return preparedParts;
|
|
338
|
+
});
|
|
339
|
+
const whole = prepareWhole(source.whole ?? []), coarseWhole = prepareWhole((source.coarseWhole ?? []).map(entry => {
|
|
340
|
+
if (entry.partition !== undefined) throw new Error(`Coarse whole prop ${entry.id} is never partitioned`);
|
|
341
|
+
return entry;
|
|
342
|
+
}));
|
|
343
|
+
const base = vertices(source.static), spill: Vertex[][] = [], eligible = new Map<PropScatter, Matrix4[]>();
|
|
344
|
+
for (const batch of source.scatter ?? []) {
|
|
345
|
+
const keep: Matrix4[] = [];
|
|
346
|
+
for (const matrix of batch.transforms) {
|
|
347
|
+
const triangles = vertices(batch.model, matrix), box = new Box3().setFromPoints(triangles.flat().map((vertex) => vertex.p)), p = new Vector3().setFromMatrixPosition(matrix), x = -250 + Math.floor((p.x + 250) / 62.5) * 62.5, z = -250 + Math.floor((p.z + 250) / 62.5) * 62.5;
|
|
348
|
+
if (box.min.x < x || box.max.x > x + 62.5 || box.min.z < z || box.max.z > z + 62.5) spill.push(...triangles); else keep.push(matrix);
|
|
349
|
+
}
|
|
350
|
+
eligible.set(batch, keep);
|
|
351
|
+
}
|
|
352
|
+
// Hidden panels remain controllable library objects; an unconditional proxy must never make them visible.
|
|
353
|
+
const scattered = (source.scatter ?? []).flatMap((s) => s.transforms.flatMap((m) => vertices(s.model, m))), panelTriangles = (source.panels ?? []).filter((p) => p.visible !== false).flatMap((p) => vertices(p.model)), coarse = source.coarse === undefined ? [...base, ...scattered, ...panelTriangles] : vertices(source.coarse);
|
|
354
|
+
const panelFiles = (source.panels ?? []).map((entry) => { let storageError = 0; const g = geometry(vertices(entry.model), undefined, metres => { storageError = metres; }), file = save([{ geometry: g, material: mergedMaterial(entry.materialName ?? source.materialName), ...(entry.castShadow === false ? { castShadow: false } : {}) }], entry.id); g.computeBoundingBox(); library.push(file.hash); section.panels.push({ id: entry.id, file: file.hash, visible: entry.visible ?? true }); return { file, bounds: g.boundingBox, storageError }; });
|
|
355
|
+
for (const lod of [0, 1] as const) {
|
|
356
|
+
const size = lod === 0 ? 62.5 : 125, count = 500 / size;
|
|
357
|
+
for (let z = 0; z < count; z++) for (let x = 0; x < count; x++) {
|
|
358
|
+
let tileError = lod === 0 ? 0 : source.coarseErrorMetres ?? 0;
|
|
359
|
+
const noteError = (metres: number): void => { tileError = Math.max(tileError, (lod === 0 ? 0 : source.coarseErrorMetres ?? 0) + metres); };
|
|
360
|
+
const x0 = -250 + x * size, z0 = -250 + z * size, bounds: [number, number, number, number] = [x0, x0 + size, z0, z0 + size], primitives: GlbPrimitive[] = [], g = geometry(lod === 0 ? [...base, ...spill] : coarse, bounds, noteError);
|
|
361
|
+
if (g.getAttribute('position').count > 0) primitives.push({ geometry: g, material: mergedMaterial(source.materialName), castShadow: lod === 0 });
|
|
362
|
+
if (lod === 0) for (const batch of source.scatter ?? []) {
|
|
363
|
+
const transforms = (eligible.get(batch) ?? []).filter((m) => { const p = new Vector3().setFromMatrixPosition(m); return p.x >= x0 && p.x < x0 + size && p.z >= z0 && p.z < z0 + size; });
|
|
364
|
+
if (transforms.length === 0) continue;
|
|
365
|
+
// Scatter keeps a model in one owning tile; its conservative bounds may extend into its neighbours.
|
|
366
|
+
let storageError = 0;
|
|
367
|
+
const local = geometry(vertices(batch.model), undefined, metres => { storageError = metres; });
|
|
368
|
+
tileError = Math.max(tileError, storageError * Math.max(...transforms.map(matrix => positionErrorScale(matrix))));
|
|
369
|
+
primitives.push({ geometry: local, material: mergedMaterial(source.materialName), instances: transforms });
|
|
370
|
+
}
|
|
371
|
+
for (const w of lod === 0 ? whole : coarseWhole) if (w.owner === null ? w.at.x >= x0 && w.at.x < x0 + size && w.at.z >= z0 && w.at.z < z0 + size : w.owner.x === x && w.owner.z === z) primitives.push({ geometry: w.geometry, material: w.material, castShadow: w.castShadow, name: w.id, transform: w.grid === undefined ? w.transform : w.transform.clone().multiply(tileGridTransform(w.grid)),
|
|
372
|
+
...(w.grid === undefined ? {} : { pose: w.transform, meshoptReady: true as const }), compactIndex: true, ...(w.customAttributes === undefined ? {} : { customAttributes: w.customAttributes }), ...(w.nativeAttributes === undefined ? {} : { nativeAttributes: w.nativeAttributes }), ...(w.quantized ? { quantizedChannels: true } : {}), ...(w.compact ? { nativeOnce: true as const } : {}), ...(w.extras === undefined ? {} : { extras: w.extras }) });
|
|
373
|
+
for (const w of lod === 0 ? whole : coarseWhole) if (w.owner === null ? w.at.x >= x0 && w.at.x < x0 + size && w.at.z >= z0 && w.at.z < z0 + size : w.owner.x === x && w.owner.z === z)
|
|
374
|
+
tileError = Math.max(tileError, w.geometricError);
|
|
375
|
+
const hasPanel = lod === 0 && panelFiles.some((p) => p.bounds !== null && p.bounds.max.x >= x0 && p.bounds.min.x <= x0 + size && p.bounds.max.z >= z0 && p.bounds.min.z <= z0 + size);
|
|
376
|
+
if (primitives.length === 0 && !hasPanel) continue;
|
|
377
|
+
const batches: GlbPrimitive[][] = [];
|
|
378
|
+
if ((source.whole ?? []).some(entry => entry.partition !== undefined)) {
|
|
379
|
+
let batch: GlbPrimitive[] = [];
|
|
380
|
+
for (const primitive of primitives) {
|
|
381
|
+
try { staticGlb([...batch, primitive], `props.${lod}.${x}.${z}`); batch.push(primitive); }
|
|
382
|
+
catch (error) {
|
|
383
|
+
if (!(error instanceof Error) || !['GLB resource cap', 'invalid GLB header'].includes(error.message) || batch.length === 0) throw error;
|
|
384
|
+
batches.push(batch); batch = [primitive];
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (batch.length > 0) batches.push(batch);
|
|
388
|
+
} else batches.push(primitives);
|
|
389
|
+
const tileFiles = batches.map((batch, i) => save(batch, batches.length === 1 ? `props.${lod}.${x}.${z}` : `props.${lod}.${x}.${z}.${i}`, true));
|
|
390
|
+
const file = tileFiles[0]; if (file === undefined) throw new Error('Props tile contains no file');
|
|
391
|
+
const cost = tileFiles.reduce((sum, part) => ({ decoded: sum.decoded + part.decoded, gpu: sum.gpu + part.gpu, triangles: sum.triangles + part.triangles, draws: sum.draws + part.draws }), { decoded: 0, gpu: 0, triangles: 0, draws: 0 });
|
|
392
|
+
if (texture !== null) { cost.gpu += texture.gpu; cost.decoded += texture.decoded; }
|
|
393
|
+
const prior = tiles.find((t) => t.lod === lod && t.x === x && t.z === z), row: Shardfile['tiles'][number] = prior ?? { lod, x, z, bounds: { min: [x0, 0, z0], max: [x0 + size, 0, z0 + size] }, geometricError: 0, files: [], compressed: 0, decoded: 0, gpu: 0, triangles: 0, draws: 0 };
|
|
394
|
+
row.geometricError = Math.max(row.geometricError, tileError);
|
|
395
|
+
if (overhang > 0) row.drawBounds = { min: [...row.bounds.min], max: [...row.bounds.max] };
|
|
396
|
+
row.files.push(...tileFiles.map(part => part.hash)); row.compressed += tileFiles.reduce((sum, part) => sum + part.compressed, 0) + (texture?.compressed ?? 0); row.decoded += cost.decoded; row.gpu += cost.gpu; row.triangles += cost.triangles; row.draws += cost.draws;
|
|
397
|
+
for (const primitive of primitives) { primitive.geometry.computeBoundingBox(); const box = primitive.geometry.boundingBox; if (box === null) continue;
|
|
398
|
+
for (const matrix of primitive.instances ?? [primitive.transform ?? new Matrix4()]) { const world = box.clone().applyMatrix4(matrix); row.bounds.min[1] = Math.min(row.bounds.min[1], world.min.y); row.bounds.max[1] = Math.max(row.bounds.max[1], world.max.y);
|
|
399
|
+
if (row.drawBounds !== undefined) for (const axis of [0, 1, 2] as const) {
|
|
400
|
+
const coordinate = axis === 0 ? 'x' : axis === 1 ? 'y' : 'z';
|
|
401
|
+
row.drawBounds.min[axis] = Math.min(row.drawBounds.min[axis], world.min[coordinate]);
|
|
402
|
+
row.drawBounds.max[axis] = Math.max(row.drawBounds.max[axis], world.max[coordinate]);
|
|
403
|
+
} }
|
|
404
|
+
}
|
|
405
|
+
if (lod === 0) for (const panel of panelFiles) { const box = panel.bounds; if (box === null || box.max.x < x0 || box.min.x > x0 + size || box.max.z < z0 || box.min.z > z0 + size) continue; row.geometricError = Math.max(row.geometricError, panel.storageError); row.files.push(panel.file.hash); row.triangles += panel.file.triangles; row.draws += panel.file.draws; row.bounds.min[1] = Math.min(row.bounds.min[1], box.min.y); row.bounds.max[1] = Math.max(row.bounds.max[1], box.max.y); }
|
|
406
|
+
const cap = lod === 0 ? CONTENT_CAPS.l0 : CONTENT_CAPS.l1;
|
|
407
|
+
const warnings = [
|
|
408
|
+
...(row.decoded + row.gpu > cap.resident ? [`resident ${row.decoded + row.gpu} > ${cap.resident}`] : []),
|
|
409
|
+
...(row.compressed > cap.compressed ? [`compressed ${row.compressed} > ${cap.compressed}`] : []),
|
|
410
|
+
...(row.triangles > cap.triangles ? [`triangles ${row.triangles} > ${cap.triangles}`] : []),
|
|
411
|
+
...(row.draws > cap.draws ? [`draws ${row.draws} > ${cap.draws}`] : []),
|
|
412
|
+
];
|
|
413
|
+
if (warnings.length > 0) {
|
|
414
|
+
tileWarnings.set(`${lod}/${x}/${z}`, warnings);
|
|
415
|
+
console.warn(`Props tile ${lod}/${x}/${z}: ${warnings.join('; ')} (provisional caps)`);
|
|
416
|
+
}
|
|
417
|
+
if (prior === undefined) tiles.push(row); section.tiles.push({ lod, x, z, file: file.hash,
|
|
418
|
+
...(tileFiles.length === 1 ? {} : { additionalFiles: tileFiles.slice(1).map(part => part.hash) }) });
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// a section of whole shapes only has no far proxy: a whole shape is never decimated, and the far proxy is one capped draw
|
|
422
|
+
const farTriangles = source.far === undefined ? [...base, ...scattered, ...panelTriangles] : vertices(source.far);
|
|
423
|
+
let far: BakedProps['far'] = null;
|
|
424
|
+
if (farTriangles.length > 0 || whole.length === 0) {
|
|
425
|
+
const farGeometry = geometry(farTriangles);
|
|
426
|
+
if (farGeometry.getAttribute('position').count === 0) throw new Error('Props far proxy must have geometry');
|
|
427
|
+
farGeometry.computeBoundingBox(); const farBox = farGeometry.boundingBox; if (farBox === null) throw new Error('Missing far bounds');
|
|
428
|
+
const farFile = save([{ geometry: farGeometry, material: mergedMaterial(source.materialName), castShadow: false }], 'props.far'), proxy = { bounds: { min: farBox.min.toArray(), max: farBox.max.toArray() }, files: [farFile.hash], compressed: farFile.compressed + (texture?.compressed ?? 0), decoded: farFile.decoded, gpu: farFile.gpu + (texture?.gpu ?? 0), triangles: farFile.triangles, draws: farFile.draws };
|
|
429
|
+
if (proxy.decoded + proxy.gpu > CONTENT_CAPS.far.resident || proxy.compressed > CONTENT_CAPS.far.compressed || proxy.triangles > CONTENT_CAPS.far.triangles || proxy.draws > CONTENT_CAPS.far.draws) throw new Error('Props far proxy exceeds content caps');
|
|
430
|
+
section.far = farFile.hash; far = proxy;
|
|
431
|
+
}
|
|
432
|
+
for (const [kind, entries] of [['models', source.models ?? []]] as const) for (const entry of entries) {
|
|
433
|
+
const file = save([{ geometry: geometry(vertices(entry.model)), material: mergedMaterial(source.materialName) }], entry.id); library.push(file.hash); section[kind].push({ id: entry.id, file: file.hash });
|
|
434
|
+
}
|
|
435
|
+
const libraryFiles = files.filter((f) => library.includes(f.hash) || (texture !== null && library.length > 0 && f.hash === texture.hash));
|
|
436
|
+
if (libraryFiles.reduce((n, f) => n + f.decoded + f.gpu, 0) > CONTENT_CAPS.library.resident || libraryFiles.reduce((n, f) => n + f.compressed, 0) > CONTENT_CAPS.library.compressed) throw new Error('Props library exceeds content caps');
|
|
437
|
+
const props = v.parse(PropsSchema, section), report = tiles.map((t) => {
|
|
438
|
+
const warnings = tileWarnings.get(`${t.lod}/${t.x}/${t.z}`);
|
|
439
|
+
return { lod: t.lod, x: t.x, z: t.z, resident: t.decoded + t.gpu, compressed: t.compressed, triangles: t.triangles, draws: t.draws,
|
|
440
|
+
...(warnings === undefined ? {} : { warnings }) };
|
|
441
|
+
});
|
|
442
|
+
return { props, tiles, files, library, far, assets, report };
|
|
443
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Offline quest placement compiler. All floors, frames and model anchors are explicit data/callback inputs. */
|
|
2
|
+
/** Generic authored placement; `world` selects untransformed coordinates. */
|
|
3
|
+
export interface AuthorQuestPlace {
|
|
4
|
+
poi: string;
|
|
5
|
+
x: number;
|
|
6
|
+
z: number;
|
|
7
|
+
/** facing in the POI's frame (radians about +Y; 0 = the model's front faces +Z) */
|
|
8
|
+
yaw?: number;
|
|
9
|
+
/** absolute world y — skips the floor lookup */
|
|
10
|
+
y?: number;
|
|
11
|
+
/** metres above the floor found at (x, z) */
|
|
12
|
+
dy?: number;
|
|
13
|
+
/** a model anchor name (`<poi>.<name>`, e.g. `frame.marker`); used instead of x / z / yaw when the model exports it */
|
|
14
|
+
anchor?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A borrowed world-space quest anchor; an explicit height bypasses floor lookup. */
|
|
18
|
+
export interface AuthorQuestAnchor { readonly x: number; readonly z: number; readonly y?: number; readonly yaw?: number }
|
|
19
|
+
/** Existing terrain, walkable floors and model anchors lent to a quest placement resolver. */
|
|
20
|
+
export interface AuthorQuestPlacementPorts {
|
|
21
|
+
readonly terrain: (x: number, z: number) => number;
|
|
22
|
+
readonly platforms?: readonly ((x: number, z: number) => number | undefined)[];
|
|
23
|
+
readonly registry?: { readonly floorAt: (x: number, z: number) => number | undefined };
|
|
24
|
+
/** Strict height difference above the current floor; omitted accepts any higher registered floor. */
|
|
25
|
+
readonly registryReach?: number;
|
|
26
|
+
readonly frames?: Readonly<Record<string, { readonly x: number; readonly z: number; readonly rot: number }>>;
|
|
27
|
+
readonly pois?: Readonly<Record<string, object | null>>;
|
|
28
|
+
}
|
|
29
|
+
const questNumber = (value: number): number => {
|
|
30
|
+
if (!Number.isFinite(value) || Math.abs(value) > 1000000) throw new RangeError('Invalid quest placement coordinate');
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
const questKey = (value: string): string => {
|
|
34
|
+
if (value.length === 0 || value.length > 256 || value.split('.').some(key => key === '__proto__' || key === 'prototype' || key === 'constructor')) throw new Error('Invalid quest anchor path');
|
|
35
|
+
return value;
|
|
36
|
+
};
|
|
37
|
+
function questAnchor(raw: unknown): AuthorQuestAnchor {
|
|
38
|
+
if (typeof raw !== 'object' || raw === null || !('x' in raw) || !('z' in raw) || typeof raw.x !== 'number' || typeof raw.z !== 'number') throw new Error('Invalid borrowed quest anchor');
|
|
39
|
+
const y = 'y' in raw ? raw.y : undefined, yaw = 'yaw' in raw ? raw.yaw : undefined;
|
|
40
|
+
if ((y !== undefined && typeof y !== 'number') || (yaw !== undefined && typeof yaw !== 'number')) throw new Error('Invalid quest anchor height or yaw');
|
|
41
|
+
return { x: questNumber(raw.x), z: questNumber(raw.z), ...(y === undefined ? {} : { y: questNumber(y) }), ...(yaw === undefined ? {} : { yaw: questNumber(yaw) }) };
|
|
42
|
+
}
|
|
43
|
+
/** Resolve bounded quest placements in their authored frames, with live borrowed floors.
|
|
44
|
+
* Explicit quest anchors precede model anchors; the former ignore dy, while model
|
|
45
|
+
* anchors add dy only when their height is omitted. No prompt, registry or save is owned.
|
|
46
|
+
*/
|
|
47
|
+
export function createAuthorQuestPlacements(ports: AuthorQuestPlacementPorts): {
|
|
48
|
+
readonly floorAt: (x: number, z: number) => number;
|
|
49
|
+
readonly place: (at: AuthorQuestPlace) => { x: number; y: number; z: number; yaw: number };
|
|
50
|
+
readonly setAnchor: (name: string, anchor: AuthorQuestAnchor) => void;
|
|
51
|
+
/** Borrow current validated anchors without introducing a second placement owner. */
|
|
52
|
+
readonly anchors: ReadonlyMap<string, Readonly<AuthorQuestAnchor>>;
|
|
53
|
+
} {
|
|
54
|
+
if (ports.registryReach !== undefined && (!Number.isFinite(ports.registryReach) || ports.registryReach <= 0)) throw new RangeError('Invalid quest registry reach');
|
|
55
|
+
if ((ports.platforms?.length ?? 0) > 4096) throw new RangeError('Too many quest floors');
|
|
56
|
+
if (Object.keys(ports.frames ?? {}).length > 4096) throw new RangeError('Too many quest frames');
|
|
57
|
+
for (const [id, frame] of Object.entries(ports.frames ?? {})) { questKey(id); questNumber(frame.x); questNumber(frame.z); questNumber(frame.rot); }
|
|
58
|
+
const own = new Map<string, AuthorQuestAnchor>();
|
|
59
|
+
const floorAt = (x: number, z: number): number => {
|
|
60
|
+
questNumber(x); questNumber(z);
|
|
61
|
+
let y = questNumber(ports.terrain(x, z));
|
|
62
|
+
for (const floor of ports.platforms ?? []) { const f = floor(x, z); if (f !== undefined && questNumber(f) > y) y = f; }
|
|
63
|
+
const registered = ports.registry?.floorAt(x, z);
|
|
64
|
+
if (registered !== undefined && questNumber(registered) > y && (ports.registryReach === undefined || registered - y < ports.registryReach)) y = registered;
|
|
65
|
+
return y;
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
anchors: own, floorAt,
|
|
69
|
+
setAnchor: (name, anchor) => {
|
|
70
|
+
questKey(name);
|
|
71
|
+
if (!own.has(name) && own.size >= 4096) throw new RangeError('Too many quest anchors');
|
|
72
|
+
own.set(name, questAnchor(anchor));
|
|
73
|
+
},
|
|
74
|
+
place: p => {
|
|
75
|
+
questKey(p.poi); questNumber(p.x); questNumber(p.z);
|
|
76
|
+
const dy = p.dy === undefined ? 0 : questNumber(p.dy);
|
|
77
|
+
if (p.anchor !== undefined) {
|
|
78
|
+
questKey(p.anchor);
|
|
79
|
+
const override = own.get(p.anchor);
|
|
80
|
+
if (override !== undefined) return { x: override.x, z: override.z, y: override.y ?? floorAt(override.x, override.z), yaw: override.yaw ?? 0 };
|
|
81
|
+
const [poi, name] = p.anchor.split('.');
|
|
82
|
+
const model: unknown = poi === undefined ? undefined : Reflect.get(ports.pois ?? {}, poi);
|
|
83
|
+
if (name !== undefined && typeof model === 'object' && model !== null && 'anchors' in model && typeof model.anchors === 'object' && model.anchors !== null && Object.hasOwn(model.anchors, name)) {
|
|
84
|
+
const a = questAnchor(Reflect.get(model.anchors, name));
|
|
85
|
+
return { x: a.x, z: a.z, y: a.y ?? floorAt(a.x, a.z) + dy, yaw: a.yaw ?? 0 };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
let x = p.x, z = p.z, yaw = p.yaw === undefined ? 0 : questNumber(p.yaw);
|
|
89
|
+
if (p.poi !== 'world') {
|
|
90
|
+
const frame = Object.hasOwn(ports.frames ?? {}, p.poi) ? ports.frames?.[p.poi] : undefined;
|
|
91
|
+
if (frame === undefined) throw new Error(`Missing quest frame ${p.poi}`);
|
|
92
|
+
const c = Math.cos(frame.rot), sin = Math.sin(frame.rot);
|
|
93
|
+
x = frame.x + p.x * c + p.z * sin; z = frame.z - p.x * sin + p.z * c; yaw += frame.rot;
|
|
94
|
+
}
|
|
95
|
+
return { x: questNumber(x), z: questNumber(z), y: p.y === undefined ? floorAt(x, z) + dy : questNumber(p.y), yaw };
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parseKtx2 } from '../assets';
|
|
2
|
+
import { encodeBuildBytes } from './byteCodec';
|
|
3
|
+
import type { ImagePixels } from './image';
|
|
4
|
+
|
|
5
|
+
/** Pack owned bounded RGBA pixels into the original single-level Zstd KTX2, without file/image services.
|
|
6
|
+
* Rows retain their supplied order. Linear stores numerical channels; the default transfer is sRGB.
|
|
7
|
+
* An optional trusted build encoder preserves the same Zstd level; raster and KTX2 admission always run here. */
|
|
8
|
+
export function bakeRawColourPixels(image: ImagePixels, options: { colourSpace?: 'srgb' | 'linear' } = {}, encode?: (input: Uint8Array, level: number) => Uint8Array): Uint8Array {
|
|
9
|
+
const { width, height, pixels } = image;
|
|
10
|
+
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 1 || height < 1 || width > 4096 || height > 4096
|
|
11
|
+
|| !(pixels instanceof Uint8ClampedArray) || !(pixels.buffer instanceof ArrayBuffer) || pixels.byteLength !== width * height * 4) throw new Error('Invalid bounded RGBA raster');
|
|
12
|
+
if (options.colourSpace !== undefined && !['srgb', 'linear'].includes(options.colourSpace)) throw new Error('Invalid texture colour space');
|
|
13
|
+
const linear = options.colourSpace === 'linear';
|
|
14
|
+
const input = new Uint8Array(pixels.buffer, pixels.byteOffset, pixels.byteLength);
|
|
15
|
+
const packed = encode === undefined ? encodeBuildBytes(input, 'zstd', 19) : encode(input, 19);
|
|
16
|
+
const descriptorSize = 92, offset = 104 + descriptorSize, out = new Uint8Array(offset + packed.length), view = new DataView(out.buffer);
|
|
17
|
+
out.set([171, 75, 84, 88, 32, 50, 48, 187, 13, 10, 26, 10]);
|
|
18
|
+
// RGBA8 with explicit transfer, one Zstd level. Descriptor and level bytes never overlap.
|
|
19
|
+
[linear ? 37 : 43, 1, width, height, 0, 0, 1, 1, 2, 104, descriptorSize].forEach((value, i) => { view.setUint32(12 + i * 4, value, true); });
|
|
20
|
+
view.setBigUint64(80, BigInt(offset), true); view.setBigUint64(88, BigInt(packed.length), true); view.setBigUint64(96, BigInt(pixels.length), true);
|
|
21
|
+
view.setUint32(104, descriptorSize, true); view.setUint16(112, 2, true); view.setUint16(114, descriptorSize - 4, true); out.set([1, 1, linear ? 1 : 2, 0], 116);
|
|
22
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
23
|
+
const at = 132 + channel * 16; view.setUint16(at, channel * 8, true); out[at + 2] = 7; out[at + 3] = channel === 3 ? 15 : channel; view.setUint32(at + 12, 255, true);
|
|
24
|
+
}
|
|
25
|
+
out.set(packed, offset); parseKtx2(out); return out;
|
|
26
|
+
}
|