@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,206 @@
|
|
|
1
|
+
import { MeshoptSimplifier } from 'meshoptimizer/simplifier';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* G342's near-placeholder producer: a shard's drawn static world (its own authored build, harvested in Node by
|
|
5
|
+
* `scripts/bake/near-placeholder.mjs`) reduced to a low-LOD, render-only set of parts inside a triangle budget. Each
|
|
6
|
+
* prototype is welded and simplified once, then placed at every instance; the copies are grouped by the 125 m region
|
|
7
|
+
* (x + 4z, the render rings' numbering) their origin stands in, so a region refined by L1 / L0 tiles hides exactly its
|
|
8
|
+
* own props. Tiny dressing (under `minSize` metres) is dropped: from a neighbour's road it is sub-pixel. No colliders.
|
|
9
|
+
*/
|
|
10
|
+
export interface NearPrototype {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
/** model-space positions and linear RGB, per vertex */
|
|
13
|
+
readonly positions: Float32Array; readonly colours: Float32Array; readonly index: Uint32Array;
|
|
14
|
+
/** column-major 4 × 4 cell-local matrices, one per placed copy */
|
|
15
|
+
readonly transforms: readonly (readonly number[])[];
|
|
16
|
+
}
|
|
17
|
+
/** One region's merged copies: cell-local metres, linear RGB, indexed (the far proxy's part shape). */
|
|
18
|
+
export interface NearPart { readonly positions: Float32Array; readonly colours: Float32Array; readonly index: Uint32Array }
|
|
19
|
+
/**
|
|
20
|
+
* How `nearPlaceholderParts` reduces a shard's harvested world: the cell-wide content triangle budget the prototypes
|
|
21
|
+
* share (each is simplified to one common world-space error, bisected to fit), the cell half-size that clips copies leaving the cell,
|
|
22
|
+
* the smallest copy worth keeping from a neighbour's road, and the floor a kept prototype is never simplified below.
|
|
23
|
+
*/
|
|
24
|
+
export interface NearPlaceholderOptions {
|
|
25
|
+
/** content triangle budget for the whole cell */
|
|
26
|
+
readonly triangles: number;
|
|
27
|
+
/** cell half-size (m); copies that leave the cell are dropped */
|
|
28
|
+
readonly half: number;
|
|
29
|
+
/** smallest copy (bounding-box diagonal, m) worth keeping */
|
|
30
|
+
readonly minSize?: number;
|
|
31
|
+
/** fewest triangles a kept prototype is simplified to */
|
|
32
|
+
readonly minTriangles?: number;
|
|
33
|
+
/** a higher floor for named prototypes (the shard's `placeholder.near.floors`): one is simplified to at least its
|
|
34
|
+
* floor, on top of `triangles`, so every other prototype keeps its share */
|
|
35
|
+
readonly floors?: readonly { readonly prototype: string; readonly triangles: number }[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What a near-placeholder reduction kept and dropped, for the bake's `--report`: each kept prototype with its placed
|
|
39
|
+
* copies and its triangles after / before simplification, each dropped one with why (malformed, a two-triangle card,
|
|
40
|
+
* every copy too small, or outside the cell), and the content triangles the parts carry in all.
|
|
41
|
+
*/
|
|
42
|
+
export interface NearPlaceholderReport { readonly kept: { name: string; copies: number; triangles: number; source: number }[]; readonly dropped: { name: string; why: string }[]; readonly triangles: number;
|
|
43
|
+
/** the world-space error (m) every prototype was simplified to; absent when round 3's common ratio was the fallback */
|
|
44
|
+
readonly error?: number }
|
|
45
|
+
|
|
46
|
+
const REGIONS = 4;
|
|
47
|
+
|
|
48
|
+
function weld(p: NearPrototype): { positions: Float32Array; colours: Float32Array; index: Uint32Array } {
|
|
49
|
+
const key = new Map<string, number>(), pos: number[] = [], sum: number[] = [], count: number[] = [], slot = new Uint32Array(p.positions.length / 3);
|
|
50
|
+
for (let v = 0; v < slot.length; v++) {
|
|
51
|
+
const x = p.positions[v * 3] ?? 0, y = p.positions[v * 3 + 1] ?? 0, z = p.positions[v * 3 + 2] ?? 0, k = `${x.toFixed(4)},${y.toFixed(4)},${z.toFixed(4)}`;
|
|
52
|
+
let s = key.get(k);
|
|
53
|
+
if (s === undefined) { s = count.length; key.set(k, s); pos.push(x, y, z); sum.push(0, 0, 0); count.push(0); }
|
|
54
|
+
slot[v] = s; sum[s * 3] = (sum[s * 3] ?? 0) + (p.colours[v * 3] ?? 0); sum[s * 3 + 1] = (sum[s * 3 + 1] ?? 0) + (p.colours[v * 3 + 1] ?? 0);
|
|
55
|
+
sum[s * 3 + 2] = (sum[s * 3 + 2] ?? 0) + (p.colours[v * 3 + 2] ?? 0); count[s] = (count[s] ?? 0) + 1;
|
|
56
|
+
}
|
|
57
|
+
const index = Uint32Array.from(p.index, i => slot[i] ?? 0);
|
|
58
|
+
return { positions: Float32Array.from(pos), colours: Float32Array.from(sum, (c, i) => c / (count[Math.floor(i / 3)] ?? 1)), index };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function simplify(mesh: { positions: Float32Array; index: Uint32Array }, triangles: number): Uint32Array {
|
|
62
|
+
if (mesh.index.length / 3 <= triangles) return mesh.index;
|
|
63
|
+
// no pruning: a palm's fronds and a tree's needles are small loose pieces, and they are its silhouette
|
|
64
|
+
const target = triangles * 3, [kept] = MeshoptSimplifier.simplify(mesh.index, mesh.positions, 3, target, 1);
|
|
65
|
+
if (kept.length <= target * 1.15 && kept.length > 0) return kept;
|
|
66
|
+
const [sloppy] = MeshoptSimplifier.simplifySloppy(mesh.index, mesh.positions, 3, null, target, 1);
|
|
67
|
+
return sloppy.length > 0 ? sloppy : kept.length > 0 ? kept : mesh.index;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Near round 6 (Nalati's crags read spiky against the sky from the road): a prototype simplified to a world-space
|
|
72
|
+
* geometric error instead of a share of its own triangles. One error for the whole cell is one screen error at one
|
|
73
|
+
* distance, so a 100 m ridge of rock fins keeps the vertices its skyline needs while a 1 m chest, sub-pixel from a
|
|
74
|
+
* neighbour's road, gives its triangles up; a common ratio cut both by the same 90 % and collapsed every fin to a sliver.
|
|
75
|
+
* `scale` is the copies' largest scale (model-space error is the world error over it).
|
|
76
|
+
*/
|
|
77
|
+
function atError(mesh: { positions: Float32Array; index: Uint32Array }, metres: number, scale: number): Uint32Array {
|
|
78
|
+
return MeshoptSimplifier.simplify(mesh.index, mesh.positions, 3, 0, metres / scale, ['ErrorAbsolute'])[0];
|
|
79
|
+
}
|
|
80
|
+
/** The largest scale among a prototype's copies (each matrix's longest basis column). */
|
|
81
|
+
const largestScale = (copies: readonly (readonly number[])[]): number => copies.reduce((s, m) => Math.max(s,
|
|
82
|
+
Math.hypot(m[0] ?? 0, m[1] ?? 0, m[2] ?? 0), Math.hypot(m[4] ?? 0, m[5] ?? 0, m[6] ?? 0), Math.hypot(m[8] ?? 0, m[9] ?? 0, m[10] ?? 0)), 1e-6);
|
|
83
|
+
/** The least share of its own triangles a prototype keeps under the error search (its thin sheets' silhouette). */
|
|
84
|
+
const RATIO_FLOOR = 0.04;
|
|
85
|
+
/** The error search's range (m): finer than a vertex weld, coarser than any cell needs. */
|
|
86
|
+
const ERROR_RANGE = { lo: 0.005, hi: 200, steps: 22 } as const;
|
|
87
|
+
|
|
88
|
+
const apply = (m: readonly number[], x: number, y: number, z: number): [number, number, number] => [
|
|
89
|
+
(m[0] ?? 0) * x + (m[4] ?? 0) * y + (m[8] ?? 0) * z + (m[12] ?? 0),
|
|
90
|
+
(m[1] ?? 0) * x + (m[5] ?? 0) * y + (m[9] ?? 0) * z + (m[13] ?? 0),
|
|
91
|
+
(m[2] ?? 0) * x + (m[6] ?? 0) * y + (m[10] ?? 0) * z + (m[14] ?? 0)];
|
|
92
|
+
|
|
93
|
+
/** How much a vertex's colour (linear RGB, 0–1) and normal deviation count in the ground's error, in metres a unit. */
|
|
94
|
+
export interface NearGroundWeights { readonly colour: number; readonly normal: number }
|
|
95
|
+
/** Round 4's weights: a 0.5 colour step or a 1.0 normal turn costs as much as 0.5 m of height. */
|
|
96
|
+
export const NEAR_GROUND_WEIGHTS: NearGroundWeights = { colour: 1, normal: 0.5 };
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* G342 round 3 (Jake: "the whole terrain and mountains of Nalati looks super low poly"): the near ground is sampled at
|
|
100
|
+
* the shard's own height-field density and reduced per region by geometric error, so a mountain keeps its ridges and a
|
|
101
|
+
* flat meadow or sea floor spends almost nothing. The region's border stays whole (its skirts hang from it). Pass the
|
|
102
|
+
* result to `buildFarProxy` as its `reduce`.
|
|
103
|
+
*/
|
|
104
|
+
export async function nearGroundReducer(errorMetres: number, weights: NearGroundWeights = NEAR_GROUND_WEIGHTS): Promise<(positions: Float32Array, index: Uint32Array, attributes?: Float32Array) => Uint32Array> {
|
|
105
|
+
if (!Number.isFinite(errorMetres) || errorMetres <= 0) throw new RangeError('Invalid near ground error');
|
|
106
|
+
if (!Number.isFinite(weights.colour) || weights.colour < 0 || !Number.isFinite(weights.normal) || weights.normal < 0) throw new RangeError('Invalid near ground weights');
|
|
107
|
+
await MeshoptSimplifier.ready;
|
|
108
|
+
return (positions, index, attributes) => {
|
|
109
|
+
// round 4: with the lattice's colours and normals (6 floats a vertex) the error also counts a painted patch, a snow
|
|
110
|
+
// line or a ridge's turn, so the shard's own colouring and creases keep their vertices instead of smearing
|
|
111
|
+
const [kept] = attributes === undefined || (weights.colour === 0 && weights.normal === 0)
|
|
112
|
+
? MeshoptSimplifier.simplify(index, positions, 3, 3, errorMetres, ['LockBorder', 'ErrorAbsolute'])
|
|
113
|
+
: MeshoptSimplifier.simplifyWithAttributes(index, positions, 3, attributes, 6, [weights.colour, weights.colour, weights.colour, weights.normal, weights.normal, weights.normal],
|
|
114
|
+
null, 3, errorMetres, ['LockBorder', 'ErrorAbsolute']);
|
|
115
|
+
return kept.length > 0 ? kept : index;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Reduce harvested prototypes to region-grouped parts inside the budget. Deterministic for the same input order. */
|
|
120
|
+
export async function nearPlaceholderParts(prototypes: readonly NearPrototype[], options: NearPlaceholderOptions): Promise<{ parts: NearPart[]; report: NearPlaceholderReport }> {
|
|
121
|
+
await MeshoptSimplifier.ready;
|
|
122
|
+
const { half } = options, minSize = options.minSize ?? 1.2, minTriangles = options.minTriangles ?? 6;
|
|
123
|
+
if (!Number.isFinite(options.triangles) || options.triangles <= 0 || !Number.isFinite(half) || half <= 0) throw new RangeError('Invalid near-placeholder budget');
|
|
124
|
+
const dropped: { name: string; why: string }[] = [];
|
|
125
|
+
const live: { name: string; mesh: ReturnType<typeof weld>; copies: (readonly number[])[]; source: number; floor: number }[] = [];
|
|
126
|
+
const floors = new Map((options.floors ?? []).map(f => [f.prototype, f.triangles]));
|
|
127
|
+
for (const p of prototypes) {
|
|
128
|
+
if (p.positions.length % 3 !== 0 || p.colours.length !== p.positions.length || p.index.length % 3 !== 0 || p.index.length === 0) { dropped.push({ name: p.name, why: 'malformed' }); continue; }
|
|
129
|
+
// a two-triangle card is a sprite (a decal, an impostor, a light shaft): untextured it draws as a grey slab
|
|
130
|
+
if (p.index.length <= 6) { dropped.push({ name: p.name, why: 'card' }); continue; }
|
|
131
|
+
const copies: (readonly number[])[] = [];
|
|
132
|
+
let small = 0;
|
|
133
|
+
for (const m of p.transforms) {
|
|
134
|
+
let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity, minZ = Infinity, maxZ = -Infinity;
|
|
135
|
+
for (let v = 0; v < p.positions.length; v += 3) {
|
|
136
|
+
const [x, y, z] = apply(m, p.positions[v] ?? 0, p.positions[v + 1] ?? 0, p.positions[v + 2] ?? 0);
|
|
137
|
+
minX = Math.min(minX, x); maxX = Math.max(maxX, x); minY = Math.min(minY, y); maxY = Math.max(maxY, y); minZ = Math.min(minZ, z); maxZ = Math.max(maxZ, z);
|
|
138
|
+
}
|
|
139
|
+
if (!Number.isFinite(minX) || minX < -half || maxX > half || minZ < -half || maxZ > half) continue;
|
|
140
|
+
if (Math.hypot(maxX - minX, maxY - minY, maxZ - minZ) < minSize) { small++; continue; }
|
|
141
|
+
copies.push(m);
|
|
142
|
+
}
|
|
143
|
+
if (copies.length === 0) { dropped.push({ name: p.name, why: small > 0 ? 'small' : 'outside' }); continue; }
|
|
144
|
+
live.push({ name: p.name, mesh: weld(p), copies, source: p.index.length / 3, floor: Math.max(minTriangles, floors.get(p.name) ?? 0) });
|
|
145
|
+
}
|
|
146
|
+
// round 6: one world-space error for every prototype, bisected (log-spaced) to the budget: the finest whose copies fit.
|
|
147
|
+
// A declared floor is applied after it, on top of the budget, so every other prototype keeps exactly what it has
|
|
148
|
+
// without the floors. Only a cell whose copies overflow the budget even at the coarsest error (thousands of copies of a
|
|
149
|
+
// closed mesh simplify no further) falls back to round 3's common ratio, which the sloppy simplifier can still meet.
|
|
150
|
+
// Thin sheets (a palm's fronds, a bush's leaves) lie within any error a whole cell can afford and would vanish, so no
|
|
151
|
+
// prototype keeps less than `RATIO_FLOOR` of its triangles (round 3's target simplifier, computed once).
|
|
152
|
+
const scales = live.map(l => largestScale(l.copies)), memo = live.map(() => new Map<number, Uint32Array>()), least: (Uint32Array | undefined)[] = [];
|
|
153
|
+
const reducedAt = (i: number, e: number): Uint32Array => {
|
|
154
|
+
const l = live[i], m = memo[i];
|
|
155
|
+
if (l === undefined || m === undefined) return new Uint32Array(0);
|
|
156
|
+
let index = m.get(e);
|
|
157
|
+
if (index === undefined) {
|
|
158
|
+
index = atError(l.mesh, e, scales[i] ?? 1);
|
|
159
|
+
const floor = Math.min(l.source, Math.max(minTriangles, Math.ceil(l.source * RATIO_FLOOR)));
|
|
160
|
+
if (index.length / 3 < floor) { least[i] ??= simplify(l.mesh, floor); index = least[i]; }
|
|
161
|
+
m.set(e, index);
|
|
162
|
+
}
|
|
163
|
+
return index;
|
|
164
|
+
};
|
|
165
|
+
const errorTotal = (e: number): number => live.reduce((sum, l, i) => sum + (reducedAt(i, e).length / 3) * l.copies.length, 0);
|
|
166
|
+
// round 3's fallback below: one scale for every prototype's share of its own triangles, bisected to the budget; a cell
|
|
167
|
+
// whose whole world fits the budget keeps every triangle (no error search)
|
|
168
|
+
const total = (s: number): number => live.reduce((sum, l) => sum + Math.min(l.source, Math.max(minTriangles, Math.floor(l.source * s))) * l.copies.length, 0);
|
|
169
|
+
let error: number | null = null;
|
|
170
|
+
if (total(1) > options.triangles && errorTotal(ERROR_RANGE.hi) <= options.triangles) {
|
|
171
|
+
let fine = Math.log(ERROR_RANGE.lo), coarse = Math.log(ERROR_RANGE.hi);
|
|
172
|
+
if (errorTotal(ERROR_RANGE.lo) <= options.triangles) coarse = fine;
|
|
173
|
+
else for (let k = 0; k < ERROR_RANGE.steps; k++) { const mid = (fine + coarse) / 2; if (errorTotal(Math.exp(mid)) <= options.triangles) coarse = mid; else fine = mid; }
|
|
174
|
+
error = Math.exp(coarse);
|
|
175
|
+
}
|
|
176
|
+
let lo = 0, hi = 1;
|
|
177
|
+
if (error !== null) lo = 1;
|
|
178
|
+
else if (total(1) > options.triangles) { for (let k = 0; k < 40; k++) { const mid = (lo + hi) / 2; if (total(mid) <= options.triangles) lo = mid; else hi = mid; } } else lo = 1;
|
|
179
|
+
const regions = Array.from({ length: REGIONS * REGIONS }, () => ({ positions: [] as number[], colours: [] as number[], index: [] as number[] }));
|
|
180
|
+
const kept: NearPlaceholderReport['kept'] = [];
|
|
181
|
+
let triangles = 0;
|
|
182
|
+
const size = (2 * half) / REGIONS, cell = (u: number): number => Math.min(REGIONS - 1, Math.max(0, Math.floor((u + half) / size)));
|
|
183
|
+
for (const [at, l] of live.entries()) {
|
|
184
|
+
// at the common error a declared floor still lifts its prototype on top of the budget
|
|
185
|
+
const atErr = error === null ? null : reducedAt(at, error), floor = floors.get(l.name) ?? 0;
|
|
186
|
+
const index = atErr === null ? simplify(l.mesh, Math.min(l.source, Math.max(l.floor, Math.floor(l.source * lo))))
|
|
187
|
+
: atErr.length / 3 >= Math.min(l.source, floor) ? atErr : simplify(l.mesh, Math.min(l.source, floor)), used = new Map<number, number>(), order: number[] = [];
|
|
188
|
+
for (const i of index) if (!used.has(i)) { used.set(i, order.length); order.push(i); }
|
|
189
|
+
const local = Uint32Array.from(index, i => used.get(i) ?? 0);
|
|
190
|
+
for (const m of l.copies) {
|
|
191
|
+
const region = regions[cell(m[12] ?? 0) + cell(m[14] ?? 0) * REGIONS];
|
|
192
|
+
if (region === undefined) continue;
|
|
193
|
+
const base = region.positions.length / 3;
|
|
194
|
+
for (const i of order) {
|
|
195
|
+
const [x, y, z] = apply(m, l.mesh.positions[i * 3] ?? 0, l.mesh.positions[i * 3 + 1] ?? 0, l.mesh.positions[i * 3 + 2] ?? 0);
|
|
196
|
+
region.positions.push(Math.min(half, Math.max(-half, x)), y, Math.min(half, Math.max(-half, z)));
|
|
197
|
+
region.colours.push(l.mesh.colours[i * 3] ?? 0, l.mesh.colours[i * 3 + 1] ?? 0, l.mesh.colours[i * 3 + 2] ?? 0);
|
|
198
|
+
}
|
|
199
|
+
for (const i of local) region.index.push(base + i);
|
|
200
|
+
}
|
|
201
|
+
triangles += (local.length / 3) * l.copies.length;
|
|
202
|
+
kept.push({ name: l.name, copies: l.copies.length, triangles: local.length / 3, source: l.source });
|
|
203
|
+
}
|
|
204
|
+
const parts = regions.filter(r => r.index.length > 0).map(r => ({ positions: Float32Array.from(r.positions), colours: Float32Array.from(r.colours), index: Uint32Array.from(r.index) }));
|
|
205
|
+
return { parts, report: { kept, dropped, triangles, ...(error === null ? {} : { error }) } };
|
|
206
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Format, NodeIO, type Accessor, type JSONDocument } from '@gltf-transform/core';
|
|
2
|
+
import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
|
|
3
|
+
import { MeshoptDecoder } from 'meshoptimizer';
|
|
4
|
+
import { hashImmutableBytes } from '../immutable';
|
|
5
|
+
|
|
6
|
+
/** Decode Meshopt into plain accessor buffers and externalize original embedded WebP/PNG/JPEG bytes.
|
|
7
|
+
* This is build-time glTF source, not an admitted product: the caller must declare and admit its texture files.
|
|
8
|
+
* Float32 vertex channels match the original GPU's normalized values; joint indices, skin weights, inverse binds,
|
|
9
|
+
* triangle order, hierarchy, animations, materials and samplers are retained. The no-op normalized flag on
|
|
10
|
+
* Float32 accessors is cleared without touching their values (integer normalization stays meaningful). No image is decoded or re-encoded.
|
|
11
|
+
* Resources have immutable SHA-256 names. Unknown extensions and external input resources refuse rather than vanish. */
|
|
12
|
+
export async function normalizeRigSource(glb: Uint8Array): Promise<JSONDocument> {
|
|
13
|
+
// Validate the complete header before either the JSON reader or extension decoder sees the source.
|
|
14
|
+
if (glb.length < 20 || glb.length > 64_000_000) throw new Error('Rig requires bounded GLB bytes');
|
|
15
|
+
const header = new DataView(glb.buffer, glb.byteOffset, glb.byteLength);
|
|
16
|
+
if (header.getUint32(0, true) !== 0x46546c67 || header.getUint32(4, true) !== 2 || header.getUint32(8, true) !== glb.byteLength) throw new Error('Rig requires complete GLB 2 bytes');
|
|
17
|
+
await MeshoptDecoder.ready;
|
|
18
|
+
const io = new NodeIO().registerExtensions(ALL_EXTENSIONS).registerDependencies({ 'meshopt.decoder': MeshoptDecoder });
|
|
19
|
+
const intake = await io.binaryToJSON(Uint8Array.from(glb)), original = intake.json;
|
|
20
|
+
const supported = new Set(['EXT_meshopt_compression', 'KHR_mesh_quantization', 'EXT_texture_webp']);
|
|
21
|
+
if ([...original.extensionsUsed ?? [], ...original.extensionsRequired ?? []].some(name => !supported.has(name))) throw new Error('Rig normalization requires an explicit extension compiler');
|
|
22
|
+
const checkExtensions = (value: unknown, depth = 0): void => {
|
|
23
|
+
if (depth > 128) throw new Error('Rig normalization exceeds declaration depth');
|
|
24
|
+
if (typeof value !== 'object' || value === null) return;
|
|
25
|
+
for (const [key, child] of Object.entries(value as Record<string, unknown>)) {
|
|
26
|
+
if (key === 'extensions' && typeof child === 'object' && child !== null && Object.keys(child).some(name => !supported.has(name))) throw new Error('Rig normalization requires an explicit extension compiler');
|
|
27
|
+
checkExtensions(child, depth + 1);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
checkExtensions(original);
|
|
31
|
+
if (original.buffers?.some(buffer => buffer.uri !== undefined) || original.images?.some(image => image.uri !== undefined)) throw new Error('Rig normalization requires embedded source resources');
|
|
32
|
+
const document = await io.readJSON(intake), root = document.getRoot();
|
|
33
|
+
if (root.listNodes().length > 4096 || root.listAccessors().length > 10000 || root.listTextures().length > 256) throw new Error('Rig normalization exceeds resource cap');
|
|
34
|
+
let elements = 0;
|
|
35
|
+
for (const accessor of root.listAccessors()) {
|
|
36
|
+
// glTF normalization applies only to integer encodings. Some retained sources mark Float32 weights too;
|
|
37
|
+
// Three treats that flag as a no-op, while bounded admission must see a canonical Float32 declaration.
|
|
38
|
+
if (accessor.getComponentType() === 5126) accessor.setNormalized(false);
|
|
39
|
+
elements += accessor.getCount() * accessor.getElementSize();
|
|
40
|
+
if (elements > 64_000_000) throw new Error('Rig normalization exceeds accessor cap');
|
|
41
|
+
}
|
|
42
|
+
const converted = new Set<Accessor>();
|
|
43
|
+
const convert = (accessor: Accessor): void => {
|
|
44
|
+
if (converted.has(accessor) || accessor.getComponentType() === 5126) return;
|
|
45
|
+
converted.add(accessor);
|
|
46
|
+
const values = new Float32Array(accessor.getCount() * accessor.getElementSize()), row: number[] = [];
|
|
47
|
+
for (let index = 0; index < accessor.getCount(); index++) {
|
|
48
|
+
accessor.getElement(index, row);
|
|
49
|
+
if (row.some(value => !Number.isFinite(value))) throw new Error('Rig normalization requires finite channels');
|
|
50
|
+
values.set(row, index * accessor.getElementSize());
|
|
51
|
+
}
|
|
52
|
+
accessor.setArray(values).setNormalized(false);
|
|
53
|
+
};
|
|
54
|
+
for (const mesh of root.listMeshes()) for (const primitive of mesh.listPrimitives()) {
|
|
55
|
+
for (const semantic of primitive.listSemantics()) {
|
|
56
|
+
const accessor = primitive.getAttribute(semantic);
|
|
57
|
+
// Skin weights stay in their original encoding: GLTFLoader normalizes them in-place after loading.
|
|
58
|
+
if (accessor !== null && !/^(?:JOINTS|WEIGHTS)_\d+$/u.test(semantic)) convert(accessor);
|
|
59
|
+
}
|
|
60
|
+
for (const target of primitive.listTargets()) for (const accessor of target.listAttributes()) convert(accessor);
|
|
61
|
+
}
|
|
62
|
+
for (const extension of root.listExtensionsUsed()) if (extension.extensionName === 'EXT_meshopt_compression' || extension.extensionName === 'KHR_mesh_quantization') extension.dispose();
|
|
63
|
+
const buffer = root.listBuffers()[0] ?? document.createBuffer();
|
|
64
|
+
for (const accessor of root.listAccessors()) accessor.setBuffer(buffer);
|
|
65
|
+
for (const other of root.listBuffers()) if (other !== buffer) other.dispose();
|
|
66
|
+
for (const texture of root.listTextures()) {
|
|
67
|
+
const bytes = texture.getImage(), mime = texture.getMimeType(), suffix = mime === 'image/webp' ? 'webp' : mime === 'image/png' ? 'png' : mime === 'image/jpeg' ? 'jpg' : null;
|
|
68
|
+
if (bytes === null || bytes.length === 0 || bytes.length > 4_000_000 || suffix === null) throw new Error('Rig normalization requires bounded original still-image bytes');
|
|
69
|
+
texture.setURI(`${hashImmutableBytes(bytes)}.${suffix}`);
|
|
70
|
+
}
|
|
71
|
+
const result = await io.writeJSON(document, { format: Format.GLTF });
|
|
72
|
+
for (const row of result.json.buffers ?? []) {
|
|
73
|
+
const uri = row.uri, bytes = uri === undefined ? undefined : result.resources[uri];
|
|
74
|
+
if (uri === undefined || bytes === undefined) throw new Error('Rig normalization lost a buffer');
|
|
75
|
+
const name = `${hashImmutableBytes(bytes)}.bin`; row.uri = name;
|
|
76
|
+
result.resources[name] = Uint8Array.from(bytes); if (name !== uri) delete result.resources[uri];
|
|
77
|
+
}
|
|
78
|
+
for (const [uri, bytes] of Object.entries(result.resources)) result.resources[uri] = Uint8Array.from(bytes);
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Trusted author tooling resolves only three's packaged transcoder artifacts.
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Temporary CommonJS glue is the packaged transcoder, removed after loading.
|
|
4
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The loader owns this unique portable temporary directory.
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Local dependency artifacts, never an author-supplied path.
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Level bodies take the same Zstandard supercompression KTX2 names.
|
|
10
|
+
import { constants, zstdCompressSync } from 'node:zlib';
|
|
11
|
+
import { parseKtx2 } from '../assets';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* DL9: a phone-tier UASTC KTX2 shipped already transcoded to ASTC 4×4. The phone's KTX2 loader has always turned these
|
|
15
|
+
* files into ASTC 4×4 at load (three's Basis transcoder in a worker); this runs that same packaged transcoder at build
|
|
16
|
+
* time, so the device uploads identical blocks with no transcode. Same dimensions, mips, transfer, orientation and
|
|
17
|
+
* key/values; each level is Zstandard-supercompressed raw ASTC (vkFormat 157 linear / 158 sRGB). Only for files a tier
|
|
18
|
+
* marks `phone`: ASTC samples on every iPhone, and a desktop tier keeps its Basis file.
|
|
19
|
+
*/
|
|
20
|
+
const UASTC_MODEL = 166, ASTC_MODEL = 162, ASTC_4X4_UNORM = 157, ASTC_4X4_SRGB = 158, TRANSCODE_ASTC_4X4 = 10, HEADER = 80, LEVEL_ROW = 24;
|
|
21
|
+
interface Ktx2File {
|
|
22
|
+
isValid: () => boolean; startTranscoding: () => boolean; getLevels: () => number; close: () => void; delete: () => void;
|
|
23
|
+
getImageTranscodedSizeInBytes: (level: number, layer: number, face: number, format: number) => number;
|
|
24
|
+
transcodeImage: (out: Uint8Array, level: number, layer: number, face: number, format: number, alpha: number, channel0: number, channel1: number) => boolean;
|
|
25
|
+
}
|
|
26
|
+
interface Transcoder { initializeBasis: () => void; KTX2File: new (bytes: Uint8Array) => unknown }
|
|
27
|
+
type TranscoderFactory = (options: { wasmBinary: Uint8Array; print: (text: string) => void; printErr: (text: string) => void }) => Promise<unknown>;
|
|
28
|
+
const fileMethods = ['isValid', 'startTranscoding', 'getLevels', 'close', 'delete', 'getImageTranscodedSizeInBytes', 'transcodeImage'] as const;
|
|
29
|
+
const factory = (value: unknown): value is TranscoderFactory => typeof value === 'function';
|
|
30
|
+
const transcoderApi = (value: unknown): value is Transcoder => typeof value === 'object' && value !== null
|
|
31
|
+
&& typeof Reflect.get(value, 'initializeBasis') === 'function' && typeof Reflect.get(value, 'KTX2File') === 'function';
|
|
32
|
+
const fileApi = (value: unknown): value is Ktx2File => typeof value === 'object' && value !== null && fileMethods.every(key => typeof Reflect.get(value, key) === 'function');
|
|
33
|
+
|
|
34
|
+
let transcoder: Promise<Transcoder> | undefined;
|
|
35
|
+
async function loadTranscoder(): Promise<Transcoder> {
|
|
36
|
+
const require = createRequire(join(import.meta.dirname, 'transcoder.cjs'));
|
|
37
|
+
const directory = join(dirname(require.resolve('three')), '../examples/jsm/libs/basis');
|
|
38
|
+
const glue = readFileSync(join(directory, 'basis_transcoder.js'), 'utf8'), wasm = Uint8Array.from(readFileSync(join(directory, 'basis_transcoder.wasm')));
|
|
39
|
+
// three ships the Emscripten glue as a browser global script; give it a CommonJS export to load it in Node.
|
|
40
|
+
const temporary = mkdtempSync(join(tmpdir(), 'wildshard-transcoder-'));
|
|
41
|
+
try {
|
|
42
|
+
const path = join(temporary, 'transcoder.cjs'); writeFileSync(path, `${glue}\nmodule.exports = BASIS;\n`);
|
|
43
|
+
// oxlint-disable-next-line import/no-dynamic-require -- Only three's packaged transcoder glue is loaded here.
|
|
44
|
+
const entry: unknown = require(path); if (!factory(entry)) throw new Error('Invalid packaged Basis transcoder');
|
|
45
|
+
const loaded = await entry({ wasmBinary: wasm, print: () => undefined, printErr: () => undefined });
|
|
46
|
+
if (!transcoderApi(loaded)) throw new Error('Invalid packaged Basis transcoder API');
|
|
47
|
+
loaded.initializeBasis(); return loaded;
|
|
48
|
+
} finally { rmSync(temporary, { recursive: true }); }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The phone tier's KTX2 for `input`: ASTC 4×4 for a UASTC file, any other file as it is. */
|
|
52
|
+
export async function phoneAstcKtx2(input: Uint8Array): Promise<Uint8Array> {
|
|
53
|
+
parseKtx2(input);
|
|
54
|
+
const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
|
|
55
|
+
const width = view.getUint32(20, true), height = view.getUint32(24, true), levels = view.getUint32(40, true);
|
|
56
|
+
const dfdOffset = view.getUint32(48, true), dfdLength = view.getUint32(52, true), kvdOffset = view.getUint32(56, true), kvdLength = view.getUint32(60, true);
|
|
57
|
+
if (view.getUint32(12, true) !== 0 || input[dfdOffset + 12] !== UASTC_MODEL || view.getUint32(44, true) === 1) return input;
|
|
58
|
+
if (view.getUint32(28, true) > 1 || view.getUint32(32, true) > 1 || view.getBigUint64(72, true) !== 0n) throw new Error('Phone ASTC takes one 2D UASTC image');
|
|
59
|
+
const srgb = input[dfdOffset + 14] === 2;
|
|
60
|
+
transcoder ??= loadTranscoder();
|
|
61
|
+
const module = await transcoder, file = new module.KTX2File(Uint8Array.from(input));
|
|
62
|
+
if (!fileApi(file)) throw new Error('Invalid packaged Basis transcoder file');
|
|
63
|
+
const bodies: Uint8Array[] = [], raw: number[] = [];
|
|
64
|
+
try {
|
|
65
|
+
if (!file.isValid() || !file.startTranscoding() || file.getLevels() !== levels) throw new Error('Basis transcoder refused the UASTC file');
|
|
66
|
+
for (let level = 0; level < levels; level++) {
|
|
67
|
+
const expected = Math.ceil(Math.max(1, width >> level) / 4) * Math.ceil(Math.max(1, height >> level) / 4) * 16;
|
|
68
|
+
if (file.getImageTranscodedSizeInBytes(level, 0, 0, TRANSCODE_ASTC_4X4) !== expected) throw new Error('ASTC 4x4 level size differs');
|
|
69
|
+
const blocks = new Uint8Array(expected);
|
|
70
|
+
if (!file.transcodeImage(blocks, level, 0, 0, TRANSCODE_ASTC_4X4, 0, -1, -1)) throw new Error('UASTC to ASTC transcode failed');
|
|
71
|
+
bodies.push(Uint8Array.from(zstdCompressSync(blocks, { params: { [constants.ZSTD_c_compressionLevel]: 19 } }))); raw.push(expected);
|
|
72
|
+
}
|
|
73
|
+
} finally { file.close(); file.delete(); }
|
|
74
|
+
// Header, level index, the source's descriptor (colour model ASTC) and key/values, then levels smallest first.
|
|
75
|
+
const dfdAt = HEADER + levels * LEVEL_ROW, kvdAt = dfdAt + dfdLength, dataAt = kvdAt + kvdLength;
|
|
76
|
+
const total = dataAt + bodies.reduce((sum, body) => sum + body.length, 0), output = new Uint8Array(total), out = new DataView(output.buffer);
|
|
77
|
+
output.set(input.subarray(0, HEADER));
|
|
78
|
+
out.setUint32(12, srgb ? ASTC_4X4_SRGB : ASTC_4X4_UNORM, true); out.setUint32(44, 2, true);
|
|
79
|
+
out.setUint32(48, dfdAt, true); out.setUint32(56, kvdLength === 0 ? 0 : kvdAt, true);
|
|
80
|
+
out.setBigUint64(64, 0n, true); out.setBigUint64(72, 0n, true);
|
|
81
|
+
output.set(input.subarray(dfdOffset, dfdOffset + dfdLength), dfdAt); output[dfdAt + 12] = ASTC_MODEL;
|
|
82
|
+
output.set(input.subarray(kvdOffset, kvdOffset + kvdLength), kvdAt);
|
|
83
|
+
let at = dataAt;
|
|
84
|
+
for (let level = levels - 1; level >= 0; level--) {
|
|
85
|
+
const body = bodies[level], row = HEADER + level * LEVEL_ROW, size = raw[level];
|
|
86
|
+
if (body === undefined || size === undefined) throw new Error('Missing ASTC level');
|
|
87
|
+
output.set(body, at);
|
|
88
|
+
out.setBigUint64(row, BigInt(at), true); out.setBigUint64(row + 8, BigInt(body.length), true); out.setBigUint64(row + 16, BigInt(size), true);
|
|
89
|
+
at += body.length;
|
|
90
|
+
}
|
|
91
|
+
parseKtx2(output);
|
|
92
|
+
return output;
|
|
93
|
+
}
|