@wildshard/sdk 0.0.1 → 0.2.4
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 +895 -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 +47 -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 +39 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/delete/delete.ts +258 -0
- package/src/cli/help.ts +204 -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 +291 -0
- package/src/cli/report.ts +20 -0
- package/src/cli/shardfile/command.ts +49 -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/agentFiles.ts +127 -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 +118 -0
- package/src/sharddev/checkProject.ts +127 -0
- package/src/sharddev/cli.ts +200 -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 +226 -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 +29 -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 +304 -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,581 @@
|
|
|
1
|
+
import { NodeIO } from '@gltf-transform/core';
|
|
2
|
+
import { ALL_EXTENSIONS, EXTMeshoptCompression, KHRMeshQuantization } from '@gltf-transform/extensions';
|
|
3
|
+
import { MeshoptDecoder, MeshoptSimplifier } from 'meshoptimizer';
|
|
4
|
+
import sharp from 'sharp';
|
|
5
|
+
import { BufferAttribute, BufferGeometry, Color, Float32BufferAttribute, Matrix4, MeshBasicMaterial, MeshStandardMaterial, Quaternion, SRGBColorSpace, Vector3 } from 'three';
|
|
6
|
+
import { CONTENT_CAPS } from '@wildshard/engine/core/config';
|
|
7
|
+
import { parseBakedTerrain } from '@wildshard/engine/world/BakedTerrain';
|
|
8
|
+
import { decodeTerrainTile } from '@wildshard/format/terrainTileBytes';
|
|
9
|
+
import type { PlaceholderTree } from '@wildshard/format/placeholderSource';
|
|
10
|
+
import { NEAR_COLOUR, NEAR_LIGHT, NEAR_PLACEHOLDER_LIMITS } from '@wildshard/format/nearPlaceholder';
|
|
11
|
+
import { MEASURE_SLOT, parseFamilyMaterial, type FamilyMaterialParams } from '@wildshard/format/materialFamilies';
|
|
12
|
+
import { materialGraphIr } from '@wildshard/format/materials';
|
|
13
|
+
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
14
|
+
import { placeholderGeometry, placeholderLeanDrop, type PlaceholderGrid, type PlaceholderLook, type PlaceholderLookRuntime, type PlaceholderPart } from '@wildshard/engine/game/plugin/placeholderGeometry';
|
|
15
|
+
import { assetCost } from '@wildshard/format/product';
|
|
16
|
+
import { parseGlb } from '../assets';
|
|
17
|
+
import { encodeCanonicalJson, hashImmutableBytes } from '../immutable';
|
|
18
|
+
import { staticGlb } from './glb';
|
|
19
|
+
import { bakeFarImpostor } from './farImpostor';
|
|
20
|
+
import { nearGroundReducer, nearPlaceholderParts, type NearPlaceholderOptions, type NearPlaceholderReport, type NearPrototype } from './nearPlaceholder';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* G348 (Jake: *"near and far placeholders are generic things that we're doing inside the engine for arbitrary shards
|
|
24
|
+
* being loaded into the MMO"*): the far proxy (SF23) and the near placeholder (G342) of any shard, from its own height
|
|
25
|
+
* grid, its own look and its own world. `wildshard build` bakes both for every shardfile project
|
|
26
|
+
* (`projectPlaceholders`); the repo's runners (`scripts/bake/far-proxies.mjs`, `scripts/bake/near-placeholder.mjs`) call
|
|
27
|
+
* the same bakers with what a shard declares in `data/placeholder.ts` (`@wildshard/format/placeholderSource`). Nothing
|
|
28
|
+
* here knows a shard.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The near bake's budget (measured, G342): the ground sampled at the height field's own ~2 m (64 quads a 125 m region)
|
|
33
|
+
* and reduced to `groundError` metres (round 3), a content triangle budget, a sanity triangle cap and the per-cell
|
|
34
|
+
* resident ceiling. Round 3 (Jake: Nalati's terrain "super low poly") measured the dense ground at 0.5 m on 2026-10-12:
|
|
35
|
+
* Nalati 24k triangles / 1.9 MB, Pine 20k / 1.67 MB, Driftwood 16k / 1.38 MB (the L1-density ground was 10k / 0.77 MB);
|
|
36
|
+
* whole cells Nalati 5.47, Driftwood 5.81 and Pine 8.07 MB with its 40k props, so the ceiling went 6 → 8.5 MB
|
|
37
|
+
* (coordinator approval, G342 / E435): four cells 34 MB on the near line, inside the 1.0 GB Explorer envelope.
|
|
38
|
+
*/
|
|
39
|
+
export const NEAR_BAKE = { quads: 64, groundError: 0.5, contentTriangles: 42_000, triangles: 160_000, residentBytes: 8_500_000, landTriangles: 60_000, modelScale: 16 } as const;
|
|
40
|
+
/*
|
|
41
|
+
* G380: `landTriangles` is the budget of a shard whose land is models (Sky Reach's floating islands, its far row's
|
|
42
|
+
* `parts`), on top of the content budget as a height field's ground is; `modelScale` is how many times the far share
|
|
43
|
+
* of triangles its model tools keep for the near bake before that budget reduces them (`placeholderModelTools`).
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* G342 near round 5: the near ground leans back from the cell border (`FarEdgeLean`) instead of ending in a 60–120 m
|
|
47
|
+
* boundary face (Nalati's snow ring stands 100 m at its west edge, Pine's north ridge 62 m). `top` is the seam's tallest
|
|
48
|
+
* face (`SEAM_FACE_TOP`, 14 m: the seam's cliff carries the ground to it), `grade` 1.6 (58°) varied ±45 % along the border.
|
|
49
|
+
*/
|
|
50
|
+
export const NEAR_EDGE_LEAN = { top: 14, grade: 1.6, jitter: 0.45 } as const;
|
|
51
|
+
/** The forest's triangle budget inside the near placeholder (on top of the props' own content budget). */
|
|
52
|
+
export const NEAR_TREE_TRIANGLES = 30_000;
|
|
53
|
+
/** Half a cell (m): copies leaving it are dropped. */
|
|
54
|
+
const HALF = 250;
|
|
55
|
+
|
|
56
|
+
/** The paint a model's vertex samples: its base colour texture area-averaged to this square (a placeholder vertex stands
|
|
57
|
+
* for metres of paint), read bilinearly. */
|
|
58
|
+
const MODEL_PAINT = 96;
|
|
59
|
+
const linearOf = (c: number): number => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* SF49 / G380: the model tools a shard's declared model `parts` (`placeholder.far.parts`, a land of models such as
|
|
63
|
+
* floating islands) are built with, shared by the far and the near bake: `model` reads a GLB under `root` (every
|
|
64
|
+
* primitive in world space, welded by position with seams averaged, its base colour texture sampled per vertex, linear
|
|
65
|
+
* RGB) and `decimate` is meshoptimizer's simplifier toward a triangle count (the sloppy one when topology stops it short).
|
|
66
|
+
* `scale` multiplies every count `decimate` is asked for (the near bake keeps `NEAR_BAKE.modelScale` times the far share,
|
|
67
|
+
* then reduces the whole land to its own budget). Nothing here knows a shard.
|
|
68
|
+
*/
|
|
69
|
+
export async function placeholderModelTools(root: string, scale = 1): Promise<{
|
|
70
|
+
model: (path: string) => Promise<{ positions: Float32Array; colours: Float32Array; index: Uint32Array }>;
|
|
71
|
+
decimate: (positions: Float32Array, index: Uint32Array, triangles: number) => Uint32Array;
|
|
72
|
+
}> {
|
|
73
|
+
await MeshoptDecoder.ready; await MeshoptSimplifier.ready;
|
|
74
|
+
const io = new NodeIO().registerExtensions(ALL_EXTENSIONS).registerDependencies({ 'meshopt.decoder': MeshoptDecoder });
|
|
75
|
+
const paint = async (image: Uint8Array | null | undefined): Promise<((u: number, v: number) => [number, number, number]) | null> => {
|
|
76
|
+
if (image === null || image === undefined) return null;
|
|
77
|
+
const { data } = await sharp(image).resize(MODEL_PAINT, MODEL_PAINT, { fit: 'fill', kernel: 'cubic' }).removeAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
78
|
+
const at = (ix: number, iy: number, c: number): number => (data[(iy * MODEL_PAINT + ix) * 3 + c] ?? 0) / 255;
|
|
79
|
+
return (u, v) => {
|
|
80
|
+
const x = Math.min(MODEL_PAINT - 1.001, Math.max(0, (((u % 1) + 1) % 1) * MODEL_PAINT - 0.5)), y = Math.min(MODEL_PAINT - 1.001, Math.max(0, (((v % 1) + 1) % 1) * MODEL_PAINT - 0.5));
|
|
81
|
+
const ix = Math.floor(x), iy = Math.floor(y), fx = x - ix, fy = y - iy;
|
|
82
|
+
const ch = (c: number): number => linearOf((at(ix, iy, c) * (1 - fx) + at(ix + 1, iy, c) * fx) * (1 - fy) + (at(ix, iy + 1, c) * (1 - fx) + at(ix + 1, iy + 1, c) * fx) * fy);
|
|
83
|
+
return [ch(0), ch(1), ch(2)];
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const model = async (path: string): Promise<{ positions: Float32Array; colours: Float32Array; index: Uint32Array }> => {
|
|
87
|
+
const doc = await io.read(`${root.replace(/\/+$/u, '')}/${path}`), pos: number[] = [], col: number[] = [], idx: number[] = [];
|
|
88
|
+
for (const node of doc.getRoot().listNodes()) {
|
|
89
|
+
const mesh = node.getMesh(); if (mesh === null) continue;
|
|
90
|
+
const m = node.getWorldMatrix();
|
|
91
|
+
for (const prim of mesh.listPrimitives()) {
|
|
92
|
+
const p = prim.getAttribute('POSITION'), uv = prim.getAttribute('TEXCOORD_0'), index = prim.getIndices(), material = prim.getMaterial();
|
|
93
|
+
if (p === null) continue;
|
|
94
|
+
const sample = uv === null ? null : await paint(material?.getBaseColorTexture()?.getImage()), factor = material?.getBaseColorFactor() ?? [1, 1, 1, 1], base = pos.length / 3, e = [0, 0, 0], t = [0, 0];
|
|
95
|
+
for (let i = 0; i < p.getCount(); i++) {
|
|
96
|
+
p.getElement(i, e);
|
|
97
|
+
const [x = 0, y = 0, z = 0] = e;
|
|
98
|
+
pos.push(m[0] * x + m[4] * y + m[8] * z + m[12], m[1] * x + m[5] * y + m[9] * z + m[13], m[2] * x + m[6] * y + m[10] * z + m[14]);
|
|
99
|
+
const c = sample === null || uv === null ? [1, 1, 1] : (uv.getElement(i, t), sample(t[0] ?? 0, t[1] ?? 0));
|
|
100
|
+
col.push((c[0] ?? 1) * factor[0], (c[1] ?? 1) * factor[1], (c[2] ?? 1) * factor[2]);
|
|
101
|
+
}
|
|
102
|
+
const n = index === null ? p.getCount() : index.getCount();
|
|
103
|
+
for (let k = 0; k < n; k++) idx.push(base + (index === null ? k : index.getScalar(k)));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const positions = new Float32Array(pos), remap = MeshoptSimplifier.generatePositionRemap(positions, 3), first = new Map<number, number>(), out: number[] = [], sum: number[] = [], count: number[] = [], slot = new Uint32Array(remap.length);
|
|
107
|
+
for (let v = 0; v < remap.length; v++) {
|
|
108
|
+
const r = remap[v] ?? v; let s = first.get(r);
|
|
109
|
+
if (s === undefined) { s = out.length / 3; first.set(r, s); out.push(pos[v * 3] ?? 0, pos[v * 3 + 1] ?? 0, pos[v * 3 + 2] ?? 0); sum.push(0, 0, 0); count.push(0); }
|
|
110
|
+
slot[v] = s; sum[s * 3] = (sum[s * 3] ?? 0) + (col[v * 3] ?? 0); sum[s * 3 + 1] = (sum[s * 3 + 1] ?? 0) + (col[v * 3 + 1] ?? 0); sum[s * 3 + 2] = (sum[s * 3 + 2] ?? 0) + (col[v * 3 + 2] ?? 0); count[s] = (count[s] ?? 0) + 1;
|
|
111
|
+
}
|
|
112
|
+
return { positions: new Float32Array(out), colours: Float32Array.from(sum, (c, i) => c / (count[Math.floor(i / 3)] ?? 1)), index: Uint32Array.from(idx, k => slot[k] ?? 0) };
|
|
113
|
+
};
|
|
114
|
+
const decimate = (positions: Float32Array, index: Uint32Array, triangles: number): Uint32Array => {
|
|
115
|
+
const target = Math.round(triangles * scale) * 3, [kept] = MeshoptSimplifier.simplify(index, positions, 3, target, 1, ['Prune']);
|
|
116
|
+
return kept.length <= target * 1.15 ? kept : MeshoptSimplifier.simplifySloppy(index, positions, 3, null, target, 1)[0];
|
|
117
|
+
};
|
|
118
|
+
return { model, decimate };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** One immutable file row of a baked placeholder GLB. */
|
|
122
|
+
export type PlaceholderFile = Shardfile['files'][number];
|
|
123
|
+
/** far.json: the shardfile `far` row, the GLB's file row, its impostor image's file row (G539) and the runtime look. */
|
|
124
|
+
export interface FarManifest { far: NonNullable<Shardfile['far']>; file: PlaceholderFile; impostorFile: PlaceholderFile; look: PlaceholderLookRuntime }
|
|
125
|
+
/** near.json: the near GLB's cost row (with its content and forest counts), its file row and the runtime look. */
|
|
126
|
+
export interface NearManifest {
|
|
127
|
+
near: { files: string[]; compressed: number; decoded: number; gpu: number; triangles: number; draws: number; content: number; trees?: number; treeTriangles?: number;
|
|
128
|
+
/** its world is the shard's own coarse tiles (`shardfileWorld`): those tiles keep refining over it, so it never owns its cell */
|
|
129
|
+
tiles?: true };
|
|
130
|
+
file: PlaceholderFile; look: PlaceholderLookRuntime;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** A placeholder's json row (`far.json` / `near.json`): canonical, sorted keys. */
|
|
134
|
+
export function placeholderJson(manifest: FarManifest | NearManifest): string { return encodeCanonicalJson(manifest); }
|
|
135
|
+
|
|
136
|
+
function fileRow(bytes: Uint8Array): PlaceholderFile {
|
|
137
|
+
return { hash: hashImmutableBytes(bytes), kind: 'glb', compressed: bytes.length, ...parseGlb(bytes), dependencies: [], critical: false };
|
|
138
|
+
}
|
|
139
|
+
function oneDraw(geometry: ReturnType<typeof placeholderGeometry>, name: string): Uint8Array {
|
|
140
|
+
return staticGlb([{ geometry, material: new MeshStandardMaterial({ color: 0xffffff, vertexColors: true }), castShadow: false }], name);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Bake one far proxy (a single-draw GLB) and its impostor (G539: the camera-facing tile atlas the far tier draws past the
|
|
145
|
+
* proxy's band, `bakeFarImpostor`), refused over any §3.2 far cap. Only one of the two draws at a time; both are resident.
|
|
146
|
+
*/
|
|
147
|
+
export async function bakeFarPlaceholder(grid: PlaceholderGrid, look: PlaceholderLook, parts: readonly PlaceholderPart[] = []): Promise<{ manifest: FarManifest; bytes: Uint8Array; impostor: Uint8Array }> {
|
|
148
|
+
const geometry = placeholderGeometry(grid, look, parts);
|
|
149
|
+
const bytes = oneDraw(geometry, 'far-proxy'), file = fileRow(bytes);
|
|
150
|
+
geometry.computeBoundingBox(); const box = geometry.boundingBox; if (box === null) throw new Error('Missing far bounds');
|
|
151
|
+
const baked = await bakeFarImpostor(geometry, look.family);
|
|
152
|
+
// Admit the defining image envelope, including decode workspace and RGBA fallback; runtime packing stays RGBA 5551.
|
|
153
|
+
const impostorFile: PlaceholderFile = { hash: hashImmutableBytes(baked.png), kind: 'image', compressed: baked.png.length, ...assetCost('image', baked.png), dependencies: [], critical: false };
|
|
154
|
+
const far: NonNullable<Shardfile['far']> = { bounds: { min: box.min.toArray(), max: box.max.toArray() }, files: [file.hash, impostorFile.hash], impostor: { file: impostorFile.hash, ...baked.row },
|
|
155
|
+
compressed: file.compressed + impostorFile.compressed, decoded: file.decoded + impostorFile.decoded, gpu: file.gpu + impostorFile.gpu, triangles: file.triangles, draws: file.draws };
|
|
156
|
+
if (far.decoded + far.gpu > CONTENT_CAPS.far.resident || far.compressed > CONTENT_CAPS.far.compressed || far.triangles > CONTENT_CAPS.far.triangles || far.draws > CONTENT_CAPS.far.draws) throw new Error(`Far proxy exceeds content caps: ${JSON.stringify(far)}`);
|
|
157
|
+
return { manifest: { far, file, impostorFile, look: { family: look.family, haze: look.haze, ...(look.grade === undefined ? {} : { grade: look.grade }), ...(look.band === undefined ? {} : { band: look.band }) } }, bytes, impostor: baked.png };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** A baked `terrain.bin` (the WSTR lattice) as a placeholder grid. */
|
|
161
|
+
export function bakedTerrainGrid(raw: Uint8Array): PlaceholderGrid {
|
|
162
|
+
const grid = parseBakedTerrain(new Uint8Array(raw).buffer);
|
|
163
|
+
if (grid === null) throw new Error('Unreadable terrain.bin');
|
|
164
|
+
return { res: grid.res, size: grid.size, heights: grid.heights, splat: grid.splat.some((b, i) => i % 4 !== 0 && b > 0) ? grid.splat : null };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** A shardfile terrain collider tile (the whole cell, centred on its origin) as a placeholder grid. */
|
|
168
|
+
export function colliderGrid(tileBytes: Uint8Array): PlaceholderGrid {
|
|
169
|
+
const tile = decodeTerrainTile(tileBytes);
|
|
170
|
+
if (tile.x !== -tile.size / 2 || tile.z !== -tile.size / 2) throw new Error('Terrain collider is not one centred cell');
|
|
171
|
+
return { res: tile.resolution, size: tile.size, heights: tile.heights, splat: null };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** One placed tree of a forest its shard's own model draws: cell-local, its height (m) and its tint's lightness. */
|
|
175
|
+
export interface PlaceholderTreePlacement { readonly x: number; readonly y: number; readonly z: number; readonly rot: number; readonly height: number; readonly scale: number; readonly species: string; readonly tint: number }
|
|
176
|
+
interface TreeShape { readonly stem: readonly [number, number, Color] | null; readonly rings: readonly (readonly [number, number])[]; readonly crown: Color }
|
|
177
|
+
|
|
178
|
+
const srgb = ([r, g, b]: readonly [number, number, number]): Color => new Color().setRGB(r / 255, g / 255, b / 255, SRGBColorSpace);
|
|
179
|
+
/** The generic stand-in: a stemless two-ring conifer. */
|
|
180
|
+
const GENERIC_TREE: PlaceholderTree = { species: 'tree', stem: null, rings: [[0.06, 0.24], [0.45, 0.15]], crown: [76, 112, 66] };
|
|
181
|
+
const shapeFrom = (row: PlaceholderTree): TreeShape => ({ stem: row.stem === null ? null : [row.stem[0], row.stem[1], srgb(row.stem[2])], rings: row.rings, crown: srgb(row.crown) });
|
|
182
|
+
const trianglesOf = (shape: TreeShape): number => (shape.stem === null ? 0 : 8) + Math.max(0, shape.rings.length - 1) * 10 + (shape.rings.length > 0 ? 5 : 0);
|
|
183
|
+
|
|
184
|
+
function treePrototype(shape: TreeShape, shade: number, widen: number): { positions: Float32Array; colours: Float32Array; index: Uint32Array } {
|
|
185
|
+
const pos: number[] = [], col: number[] = [], idx: number[] = [];
|
|
186
|
+
const ring = (y: number, r: number, n: number, c: Color): number => { const b = pos.length / 3; for (let k = 0; k < n; k++) { const a = (k / n) * Math.PI * 2; pos.push(Math.cos(a) * r, y, Math.sin(a) * r); col.push(c.r, c.g, c.b); } return b; };
|
|
187
|
+
const side = (a: number, b: number, n: number): void => { for (let k = 0; k < n; k++) { const k1 = (k + 1) % n; idx.push(a + k, b + k, b + k1, a + k, b + k1, a + k1); } };
|
|
188
|
+
if (shape.stem !== null) { const [top, r, c] = shape.stem, a = ring(0, r, 4, c), b = ring(top, r, 4, c); side(a, b, 4); }
|
|
189
|
+
if (shape.rings.length > 0) {
|
|
190
|
+
const dark = shape.crown.clone().multiplyScalar(0.8 * shade), lit = shape.crown.clone().multiplyScalar(shade);
|
|
191
|
+
let prev = -1;
|
|
192
|
+
for (const [i, [y, r]] of shape.rings.entries()) { const b = ring(y, r * widen, 5, i === 0 ? dark : lit); if (prev >= 0) side(prev, b, 5); prev = b; }
|
|
193
|
+
const apex = pos.length / 3; pos.push(0, 1, 0); col.push(lit.r, lit.g, lit.b);
|
|
194
|
+
for (let k = 0; k < 5; k++) idx.push(prev + k, apex, prev + (k + 1) % 5);
|
|
195
|
+
}
|
|
196
|
+
return { positions: Float32Array.from(pos), colours: Float32Array.from(col), index: Uint32Array.from(idx) };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* G342: a forest's trees for the near placeholder. Each kept tree becomes a low-LOD stand-in (a unit-high stem and crown
|
|
201
|
+
* of 8-23 triangles, by species and tint band) at its own placement, thinned evenly to the triangle budget, the kept ones
|
|
202
|
+
* widened to cover the thinned ones' crowns. `stands` are the shard's declared shapes (`placeholder.trees`); a shard that
|
|
203
|
+
* declares none gets one generic conifer. Deterministic for the same placements.
|
|
204
|
+
*/
|
|
205
|
+
export function nearTreePrototypes(trees: readonly PlaceholderTreePlacement[], half: number, stands: readonly PlaceholderTree[] | undefined, budget: number = NEAR_TREE_TRIANGLES): { prototypes: NearPrototype[]; report: { placed: number; inside: number; kept: number; widen: number } } {
|
|
206
|
+
const rows = stands !== undefined && stands.length > 0 ? stands : [GENERIC_TREE], shapes = new Map(rows.map(row => [row.species, shapeFrom(row)]));
|
|
207
|
+
const fallback = rows[0]?.species ?? GENERIC_TREE.species, speciesOf = (t: PlaceholderTreePlacement): string => shapes.has(t.species) ? t.species : fallback;
|
|
208
|
+
const shapeOf = (species: string): TreeShape => shapes.get(species) ?? shapeFrom(GENERIC_TREE);
|
|
209
|
+
const inside = trees.filter(t => Math.abs(t.x) < half - 1 && Math.abs(t.z) < half - 1);
|
|
210
|
+
const total = inside.reduce((sum, t) => sum + trianglesOf(shapeOf(speciesOf(t))), 0), keep = Math.min(1, budget / Math.max(1, total));
|
|
211
|
+
// a hash of each placement picks the kept share evenly across the cell
|
|
212
|
+
const picked = inside.filter((t, i) => { const h = Math.sin(i * 12.9898 + t.x * 78.233 + t.z * 37.719) * 43758.5453; return h - Math.floor(h) < keep; });
|
|
213
|
+
const widen = Math.min(1.7, Math.sqrt(1 / keep)), groups = new Map<string, PlaceholderTreePlacement[]>();
|
|
214
|
+
for (const t of picked) {
|
|
215
|
+
const key = `${speciesOf(t)}:${t.tint < 0.45 ? 0 : t.tint < 0.55 ? 1 : 2}`;
|
|
216
|
+
const group = groups.get(key) ?? []; group.push(t); groups.set(key, group);
|
|
217
|
+
}
|
|
218
|
+
const m = new Matrix4(), q = new Quaternion(), up = new Vector3(0, 1, 0), prototypes: NearPrototype[] = [];
|
|
219
|
+
for (const key of [...groups.keys()].sort((a, b) => a.localeCompare(b))) {
|
|
220
|
+
const [species = fallback, band = '0'] = key.split(':'), shape = shapeOf(species);
|
|
221
|
+
const proto = treePrototype(shape, [0.82, 1, 1.18][Number(band)] ?? 1, shape.rings.length === 0 ? 1 : widen);
|
|
222
|
+
const transforms = (groups.get(key) ?? []).map((t) => {
|
|
223
|
+
const h = t.height > 0 ? t.height : 20 * t.scale;
|
|
224
|
+
return Array.from(m.compose(new Vector3(t.x, t.y, t.z), q.setFromAxisAngle(up, t.rot), new Vector3(h, h, h)).elements);
|
|
225
|
+
});
|
|
226
|
+
prototypes.push({ name: `tree-${key}`, ...proto, transforms });
|
|
227
|
+
}
|
|
228
|
+
return { prototypes, report: { placed: trees.length, inside: inside.length, kept: picked.length, widen: Number(widen.toFixed(2)) } };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** What `bakeNearPlaceholder` merges over the shard's ground. */
|
|
232
|
+
export interface NearPlaceholderInput {
|
|
233
|
+
/** the shard's height grid; null for a world with no height field (an authored mesh world): a flat floor then stands
|
|
234
|
+
* half a metre under the lowest point of its world, one quad a region */
|
|
235
|
+
readonly grid: PlaceholderGrid | null;
|
|
236
|
+
/** a land of models (its far row's `parts`, built with `placeholderModelTools`): cell-local parts reduced to their own
|
|
237
|
+
* budget (`NEAR_BAKE.landTriangles`), never sunk by the edge lean (they stand on no ground) */
|
|
238
|
+
readonly parts?: readonly PlaceholderPart[];
|
|
239
|
+
readonly look: PlaceholderLook;
|
|
240
|
+
/** the shard's drawn static world as prototypes with their placed copies (cell-local) */
|
|
241
|
+
readonly prototypes: readonly NearPrototype[];
|
|
242
|
+
/** a forest its own tree model draws, placement by placement (empty: none) */
|
|
243
|
+
readonly trees?: readonly PlaceholderTreePlacement[];
|
|
244
|
+
/** the shard's declared tree stand-ins (`placeholder.trees`) */
|
|
245
|
+
readonly stands?: readonly PlaceholderTree[] | undefined;
|
|
246
|
+
/** the ground's geometric error (m) and the cell's resident ceiling (bytes); default `NEAR_BAKE`'s */
|
|
247
|
+
readonly groundError?: number; readonly residentBytes?: number;
|
|
248
|
+
/** the shard's declared prototype floors (`placeholder.near.floors`), on top of the content budget */
|
|
249
|
+
readonly floors?: NearPlaceholderOptions['floors'];
|
|
250
|
+
/** progress lines (the runners print them) */
|
|
251
|
+
readonly log?: (line: string) => void;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** A model part (cell-local) as a near prototype placed once at its footprint's centre (the regions count copy origins). */
|
|
255
|
+
function landPrototype(part: PlaceholderPart, i: number): NearPrototype {
|
|
256
|
+
let minX = Infinity, maxX = -Infinity, minZ = Infinity, maxZ = -Infinity;
|
|
257
|
+
for (let v = 0; v < part.positions.length; v += 3) { const x = part.positions[v] ?? 0, z = part.positions[v + 2] ?? 0; minX = Math.min(minX, x); maxX = Math.max(maxX, x); minZ = Math.min(minZ, z); maxZ = Math.max(maxZ, z); }
|
|
258
|
+
const cx = Number.isFinite(minX) ? (minX + maxX) / 2 : 0, cz = Number.isFinite(minZ) ? (minZ + maxZ) / 2 : 0, positions = Float32Array.from(part.positions);
|
|
259
|
+
for (let v = 0; v < positions.length; v += 3) { positions[v] = (positions[v] ?? 0) - cx; positions[v + 2] = (positions[v + 2] ?? 0) - cz; }
|
|
260
|
+
return { name: `land-${String(i)}`, positions, colours: part.colours, index: part.index, transforms: [[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, cx, 0, cz, 1]] };
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Round 6: the widest copy (m, its world footprint) that sinks rigidly with the lean; a wider one is a merge of pieces. */
|
|
264
|
+
const RIGID_SPAN = 32;
|
|
265
|
+
const placed = (m: readonly number[], p: Float32Array, v: number): [number, number, number] => {
|
|
266
|
+
const x = p[v] ?? 0, y = p[v + 1] ?? 0, z = p[v + 2] ?? 0;
|
|
267
|
+
return [(m[0] ?? 0) * x + (m[4] ?? 0) * y + (m[8] ?? 0) * z + (m[12] ?? 0), (m[1] ?? 0) * x + (m[5] ?? 0) * y + (m[9] ?? 0) * z + (m[13] ?? 0),
|
|
268
|
+
(m[2] ?? 0) * x + (m[6] ?? 0) * y + (m[10] ?? 0) * z + (m[14] ?? 0)];
|
|
269
|
+
};
|
|
270
|
+
function wideCopy(p: NearPrototype, m: readonly number[]): boolean {
|
|
271
|
+
let minX = Infinity, maxX = -Infinity, minZ = Infinity, maxZ = -Infinity;
|
|
272
|
+
for (let v = 0; v < p.positions.length; v += 3) { const [x, , z] = placed(m, p.positions, v); minX = Math.min(minX, x); maxX = Math.max(maxX, x); minZ = Math.min(minZ, z); maxZ = Math.max(maxZ, z); }
|
|
273
|
+
return Math.max(maxX - minX, maxZ - minZ) > RIGID_SPAN;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* One wide copy as its own prototype in cell space, each connected piece (vertices joined by position) sunk rigidly by
|
|
277
|
+
* the lean under its own centre; null when no piece stands on a leaned flank (the copy stays an ordinary copy).
|
|
278
|
+
*/
|
|
279
|
+
function sinkPieces(p: NearPrototype, m: readonly number[], drop: (x: number, z: number) => number): NearPrototype | null {
|
|
280
|
+
const n = p.positions.length / 3, parent = Int32Array.from({ length: n }, (_, i) => i), byKey = new Map<string, number>();
|
|
281
|
+
const find = (start: number): number => { let r = start; while (parent[r] !== r) r = parent[r] ?? r; for (let i = start; parent[i] !== r;) { const next = parent[i] ?? r; parent[i] = r; i = next; } return r; };
|
|
282
|
+
const join = (a: number, b: number): void => { const ra = find(a), rb = find(b); if (ra !== rb) parent[ra] = rb; };
|
|
283
|
+
for (let v = 0; v < n; v++) {
|
|
284
|
+
const k = `${(p.positions[v * 3] ?? 0).toFixed(4)},${(p.positions[v * 3 + 1] ?? 0).toFixed(4)},${(p.positions[v * 3 + 2] ?? 0).toFixed(4)}`, at = byKey.get(k);
|
|
285
|
+
if (at === undefined) byKey.set(k, v); else join(v, at);
|
|
286
|
+
}
|
|
287
|
+
for (let t = 0; t + 2 < p.index.length; t += 3) { join(p.index[t] ?? 0, p.index[t + 1] ?? 0); join(p.index[t] ?? 0, p.index[t + 2] ?? 0); }
|
|
288
|
+
// each piece's footprint box: a piece wider than RIGID_SPAN itself (a road ribbon, a rope of flags) drapes vertex by
|
|
289
|
+
// vertex over the lean, every other piece sinks rigidly by the lean under its box's centre
|
|
290
|
+
const world = new Float32Array(p.positions.length), box = new Map<number, [number, number, number, number]>();
|
|
291
|
+
for (let v = 0; v < n; v++) {
|
|
292
|
+
const xyz = placed(m, p.positions, v * 3), r = find(v), b = box.get(r) ?? [Infinity, -Infinity, Infinity, -Infinity];
|
|
293
|
+
world.set(xyz, v * 3); b[0] = Math.min(b[0], xyz[0]); b[1] = Math.max(b[1], xyz[0]); b[2] = Math.min(b[2], xyz[2]); b[3] = Math.max(b[3], xyz[2]); box.set(r, b);
|
|
294
|
+
}
|
|
295
|
+
const sink = new Map<number, number | null>();
|
|
296
|
+
for (const [r, [x0, x1, z0, z1]] of box) sink.set(r, Math.max(x1 - x0, z1 - z0) > RIGID_SPAN ? null : drop((x0 + x1) / 2, (z0 + z1) / 2));
|
|
297
|
+
let moved = false;
|
|
298
|
+
for (let v = 0; v < n; v++) {
|
|
299
|
+
const rigid = sink.get(find(v)), d = rigid ?? drop(world[v * 3] ?? 0, world[v * 3 + 2] ?? 0);
|
|
300
|
+
if (d > 0) { world[v * 3 + 1] = (world[v * 3 + 1] ?? 0) - d; moved = true; }
|
|
301
|
+
}
|
|
302
|
+
if (!moved) return null;
|
|
303
|
+
return { name: p.name, positions: world, colours: p.colours, index: p.index, transforms: [[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]] };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** G380: the flat floor of a world with no height field, half a metre under the lowest point of its placed world. */
|
|
307
|
+
function floorUnder(prototypes: readonly NearPrototype[], parts: readonly PlaceholderPart[]): PlaceholderGrid {
|
|
308
|
+
let low = Infinity;
|
|
309
|
+
for (const p of prototypes) for (const m of p.transforms) for (let v = 0; v < p.positions.length; v += 3) {
|
|
310
|
+
const x = p.positions[v] ?? 0, y = p.positions[v + 1] ?? 0, z = p.positions[v + 2] ?? 0;
|
|
311
|
+
low = Math.min(low, (m[1] ?? 0) * x + (m[5] ?? 0) * y + (m[9] ?? 0) * z + (m[13] ?? 0));
|
|
312
|
+
}
|
|
313
|
+
for (const p of parts) for (let v = 1; v < p.positions.length; v += 3) low = Math.min(low, p.positions[v] ?? 0);
|
|
314
|
+
return { res: 2, size: HALF * 2, heights: new Float32Array(4).fill(Number.isFinite(low) ? low - 0.5 : 0), splat: null };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Bake one near placeholder: the ground at the height field's own density reduced by geometric error, in the shard's far
|
|
319
|
+
* look, with its world's prototypes and its forest's stand-ins merged in at a low LOD; one draw, regions in
|
|
320
|
+
* TEXCOORD_0.x, no colliders. The content budget steps down until the whole cell fits its resident ceiling.
|
|
321
|
+
*/
|
|
322
|
+
export async function bakeNearPlaceholder(input: NearPlaceholderInput): Promise<{ bytes: Uint8Array; manifest: NearManifest; reduced: NearPlaceholderReport }> {
|
|
323
|
+
const { look, log } = input, grid = input.grid ?? floorUnder(input.prototypes, input.parts ?? []);
|
|
324
|
+
// round 5: what stands on a leaned flank sinks with it (a ridge's trees, a hut on the snow ring), never floats
|
|
325
|
+
const drop = placeholderLeanDrop(grid, NEAR_EDGE_LEAN);
|
|
326
|
+
const trees: PlaceholderTreePlacement[] = [], prototypes: NearPrototype[] = [];
|
|
327
|
+
for (const t of input.trees ?? []) {
|
|
328
|
+
const d = drop(t.x, t.z), sunk: PlaceholderTreePlacement = { ...t, y: t.y - d };
|
|
329
|
+
trees.push(d > 0 ? sunk : t);
|
|
330
|
+
}
|
|
331
|
+
for (const p of input.prototypes) {
|
|
332
|
+
const rigid: (readonly number[])[] = [];
|
|
333
|
+
for (const m of p.transforms) {
|
|
334
|
+
// round 6: a copy wider than one piece (a merged ring of crag fins, a quadrant of dressing) sinks piece by piece:
|
|
335
|
+
// sunk by its origin, the fins on a leaned flank stood in the air over the leaned ground (Nalati's floating spikes)
|
|
336
|
+
const sunk = wideCopy(p, m) ? sinkPieces(p, m, drop) : null;
|
|
337
|
+
if (sunk !== null) { prototypes.push(sunk); continue; }
|
|
338
|
+
const d = drop(m[12] ?? 0, m[14] ?? 0); rigid.push(d > 0 ? m.map((v, i) => i === 13 ? v - d : v) : m);
|
|
339
|
+
}
|
|
340
|
+
if (rigid.length > 0) prototypes.push({ name: p.name, positions: p.positions, colours: p.colours, index: p.index, transforms: rigid });
|
|
341
|
+
}
|
|
342
|
+
const forest = trees.length === 0 ? null : nearTreePrototypes(trees, HALF, input.stands);
|
|
343
|
+
if (forest !== null) log?.(`forest ${JSON.stringify(forest.report)}`);
|
|
344
|
+
const treeParts = forest === null ? { parts: [], report: { triangles: 0 } }
|
|
345
|
+
: await nearPlaceholderParts(forest.prototypes, { triangles: NEAR_TREE_TRIANGLES * 2, half: HALF, minSize: 0 });
|
|
346
|
+
// G380: a land of models, each part re-centred on its own footprint so it falls in the region it stands over
|
|
347
|
+
const land = input.parts === undefined || input.parts.length === 0 ? { parts: [], report: { triangles: 0 } }
|
|
348
|
+
: await nearPlaceholderParts(input.parts.map(landPrototype), { triangles: NEAR_BAKE.landTriangles, half: HALF, minSize: 0 });
|
|
349
|
+
if (land.report.triangles > 0) log?.(`land ${String(land.report.triangles)} tris from ${String(input.parts?.length ?? 0)} model parts`);
|
|
350
|
+
// a forest placed tree by tree replaces its far look's canopy lift; a declared lattice (a cloud sea's one sheet, SF49) wins
|
|
351
|
+
const { canopyAt, ...bare } = look, quads = input.grid === null ? 1 : look.quads ?? NEAR_BAKE.quads,
|
|
352
|
+
nearLook: PlaceholderLook = forest === null || canopyAt === undefined ? { ...look, quads } : { ...bare, quads };
|
|
353
|
+
const groundError = input.groundError ?? NEAR_BAKE.groundError, residentCeiling = input.residentBytes ?? NEAR_BAKE.residentBytes;
|
|
354
|
+
const reduceGround = await nearGroundReducer(groundError);
|
|
355
|
+
if (log !== undefined) {
|
|
356
|
+
const cost = parseGlb(staticGlb([{ geometry: placeholderGeometry(grid, nearLook, [], NEAR_BAKE.triangles, reduceGround, NEAR_EDGE_LEAN), material: new MeshStandardMaterial({ vertexColors: true }), castShadow: false }], 'near-ground'));
|
|
357
|
+
log(`ground at ${groundError} m: ${cost.triangles} tris, resident ${((cost.decoded + cost.gpu) / 1e6).toFixed(3)} MB`);
|
|
358
|
+
}
|
|
359
|
+
let budget: number = NEAR_BAKE.contentTriangles;
|
|
360
|
+
for (;;) {
|
|
361
|
+
const { parts, report: reduced } = await nearPlaceholderParts(prototypes, { triangles: budget, half: HALF, ...(input.floors === undefined ? {} : { floors: input.floors }) });
|
|
362
|
+
const bytes = oneDraw(placeholderGeometry(grid, nearLook, [...parts, ...treeParts.parts, ...land.parts], NEAR_BAKE.triangles + treeParts.report.triangles + land.report.triangles, reduceGround, NEAR_EDGE_LEAN), 'near-placeholder');
|
|
363
|
+
const file = fileRow(bytes);
|
|
364
|
+
if (file.decoded + file.gpu <= residentCeiling) {
|
|
365
|
+
const near: NearManifest['near'] = { files: [file.hash], compressed: file.compressed, decoded: file.decoded, gpu: file.gpu, triangles: file.triangles, draws: file.draws, content: reduced.triangles + land.report.triangles,
|
|
366
|
+
...(forest === null ? {} : { trees: forest.report.kept, treeTriangles: treeParts.report.triangles }) };
|
|
367
|
+
return { bytes, reduced, manifest: { near, file, look: { family: look.family, haze: look.haze, ...(look.grade === undefined ? {} : { grade: look.grade }) } } };
|
|
368
|
+
}
|
|
369
|
+
if (budget < 4000) throw new Error(`Near placeholder terrain alone exceeds ${residentCeiling} B`);
|
|
370
|
+
budget = Math.floor(budget * 0.9);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
type Rgb = readonly [number, number, number];
|
|
375
|
+
const mixRgb = (a: Rgb, b: Rgb, t: number): Rgb => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* The far look of a shard that declares none (any shardfile, an uploaded unknown one included): its ground in its own
|
|
379
|
+
* ambient ground colour easing to a neutral rock on steep slopes, its cliff in that rock, its air its own first fog key's
|
|
380
|
+
* colour.
|
|
381
|
+
*/
|
|
382
|
+
export function shardfileLook(shard: Shardfile): PlaceholderLook {
|
|
383
|
+
const key = shard.look.keys[0], ground: Rgb = key?.ambient.ground ?? [0.32, 0.36, 0.24], rock: Rgb = [0.33, 0.31, 0.29];
|
|
384
|
+
const fog = key?.fog;
|
|
385
|
+
return {
|
|
386
|
+
family: 'pbr',
|
|
387
|
+
colourAt: (_x, _z, _h, slope) => mixRgb(ground, rock, Math.min(1, Math.max(0, (slope - 0.2) * 3))),
|
|
388
|
+
cliff: { lip: rock, foot: mixRgb(rock, [0, 0, 0], 0.4) },
|
|
389
|
+
haze: { colour: fog?.colour ?? [1, 1, 1] },
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** A bare family ID's entry, as the client's implicit family surfaces: plain, vertex-coloured, PBR dielectric. */
|
|
394
|
+
const familyDefault = (family: string): Record<string, unknown> => ({ family, vertexColours: true, ...(family === 'pbr' ? { metalness: 0 } : {}) });
|
|
395
|
+
/** sRGB to linear, one channel (the catalogue's colours are sRGB; the near bake's vertex colours linear). */
|
|
396
|
+
const srgbLinear = (c: number): number => c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
397
|
+
/**
|
|
398
|
+
* A coarse tile's surface as the client draws it by default (`installDeclaredProps`): the catalogue entry its GLB
|
|
399
|
+
* material's name binds (`props.materials[name].id`, else `props.family`) tints the GLB's own colour and vertex colours.
|
|
400
|
+
* A graph draws its preset, or its plain fallback, while Settings ▸ Debug ▸ Look ▸ "Graph materials" is off (its
|
|
401
|
+
* default). Returns the linear colour of one vertex from its GLB colour (base colour factor times vertex colour) and first
|
|
402
|
+
* UV: the entry's colour times it; a measure layer (SF56, the template's dev map) paints its role's flat colour from the
|
|
403
|
+
* measure UVs instead (structure orange, trim grey, floor light grey), as its shader does under the grid lines. Colour
|
|
404
|
+
* maps are not sampled.
|
|
405
|
+
*/
|
|
406
|
+
function tileSurfaces(shard: Shardfile, assets: ReadonlyMap<string, Uint8Array>): (name: string) => (colour: readonly number[], uv: readonly number[] | null) => [number, number, number] {
|
|
407
|
+
const entryOf = (id: string): FamilyMaterialParams => {
|
|
408
|
+
const entry = shard.look.materials[id];
|
|
409
|
+
if (entry === undefined) return parseFamilyMaterial(familyDefault(id));
|
|
410
|
+
if (entry.family !== 'graph') return entry;
|
|
411
|
+
if ('preset' in entry) return entry.preset;
|
|
412
|
+
return parseFamilyMaterial(materialGraphIr(entry, hash => assets.get(hash)).model === 'unlit' ? { family: 'emissive', vertexColours: true } : familyDefault('pbr'));
|
|
413
|
+
};
|
|
414
|
+
const surfaces = new Map<string, (colour: readonly number[], uv: readonly number[] | null) => [number, number, number]>();
|
|
415
|
+
return (name) => {
|
|
416
|
+
const id = shard.props?.materials?.[name]?.id ?? shard.props?.family ?? 'pbr', known = surfaces.get(id);
|
|
417
|
+
if (known !== undefined) return known;
|
|
418
|
+
const entry = entryOf(id), tint = entry.colour.map(srgbLinear);
|
|
419
|
+
const measure = entry.family === 'pbr' ? entry.measure : null;
|
|
420
|
+
const roles = measure === null ? null : [measure.floor, measure.structure, measure.trim, measure.floor].map(rgb => rgb.map(srgbLinear));
|
|
421
|
+
const surface = (colour: readonly number[], uv: readonly number[] | null): [number, number, number] => {
|
|
422
|
+
if (roles !== null) {
|
|
423
|
+
const role = roles[uv === null ? 0 : Math.floor((uv[0] ?? 0) / MEASURE_SLOT) % 4] ?? roles[0] ?? [1, 1, 1];
|
|
424
|
+
return [role[0] ?? 1, role[1] ?? 1, role[2] ?? 1];
|
|
425
|
+
}
|
|
426
|
+
const at = (k: number): number => (tint[k] ?? 1) * (colour[k] ?? 1);
|
|
427
|
+
return [at(0), at(1), at(2)];
|
|
428
|
+
};
|
|
429
|
+
surfaces.set(id, surface);
|
|
430
|
+
return surface;
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* A shardfile's drawn static world as near-placeholder prototypes: every mesh of its coarse (L1) tiles' GLBs, each
|
|
436
|
+
* primitive one prototype at its node's world matrix, coloured as the shard's own catalogue draws it (`tileSurfaces`).
|
|
437
|
+
*/
|
|
438
|
+
export async function shardfileWorld(shard: Shardfile, assets: ReadonlyMap<string, Uint8Array>, skip: (material: string) => boolean = () => false, lod: 0 | 1 = 1): Promise<NearPrototype[]> {
|
|
439
|
+
await MeshoptDecoder.ready;
|
|
440
|
+
const glbs = new Set(shard.files.filter(file => file.kind === 'glb').map(file => file.hash)),
|
|
441
|
+
// RM8.1: tiles carry quantized channels (KHR_mesh_quantization) and may be meshopt-compressed
|
|
442
|
+
io = new NodeIO().registerExtensions([EXTMeshoptCompression, KHRMeshQuantization]).registerDependencies({ 'meshopt.decoder': MeshoptDecoder }),
|
|
443
|
+
out: NearPrototype[] = [], surfaceOf = tileSurfaces(shard, assets);
|
|
444
|
+
for (const tile of shard.tiles) {
|
|
445
|
+
if (tile.lod !== lod) continue;
|
|
446
|
+
for (const ref of tile.files) {
|
|
447
|
+
const bytes = assets.get(ref);
|
|
448
|
+
if (!glbs.has(ref) || bytes === undefined) continue;
|
|
449
|
+
const document = await io.readBinary(Uint8Array.from(bytes));
|
|
450
|
+
for (const node of document.getRoot().listNodes()) {
|
|
451
|
+
const mesh = node.getMesh(); if (mesh === null) continue;
|
|
452
|
+
const matrix = Array.from(node.getWorldMatrix());
|
|
453
|
+
for (const [i, primitive] of mesh.listPrimitives().entries()) {
|
|
454
|
+
const position = primitive.getAttribute('POSITION'), indices = primitive.getIndices(), colour = primitive.getAttribute('COLOR_0'), uv = primitive.getAttribute('TEXCOORD_0');
|
|
455
|
+
if (position === null || primitive.getMode() !== 4 || skip(primitive.getMaterial()?.getName() ?? '')) continue;
|
|
456
|
+
const material = primitive.getMaterial(), surface = surfaceOf(material?.getName() ?? ''), factor = material?.getBaseColorFactor() ?? [1, 1, 1, 1];
|
|
457
|
+
const count = position.getCount(), p = [0, 0, 0], c = [1, 1, 1, 1], t = [0, 0];
|
|
458
|
+
const positions = new Float32Array(count * 3), colours = new Float32Array(count * 3);
|
|
459
|
+
for (let v = 0; v < count; v++) {
|
|
460
|
+
position.getElement(v, p); positions.set([p[0] ?? 0, p[1] ?? 0, p[2] ?? 0], v * 3);
|
|
461
|
+
if (colour !== null) colour.getElement(v, c);
|
|
462
|
+
if (uv !== null) uv.getElement(v, t);
|
|
463
|
+
colours.set(surface([factor[0] * (c[0] ?? 1), factor[1] * (c[1] ?? 1), factor[2] * (c[2] ?? 1)], uv === null ? null : t), v * 3);
|
|
464
|
+
}
|
|
465
|
+
const index = indices === null ? Uint32Array.from({ length: count }, (_, k) => k) : Uint32Array.from({ length: indices.getCount() }, (_, k) => indices.getScalar(k));
|
|
466
|
+
out.push({ name: `${ref.slice(0, 8)}:${node.getName()}:${String(i)}`, positions, colours, index, transforms: [matrix] });
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return out;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* G539: an authored mesh world's own far GLB (`props.far`) gets its impostor too, baked from the GLB's meshes (world
|
|
476
|
+
* positions and vertex colours, else each material's base colour); unchanged when it has one, or when the pair would
|
|
477
|
+
* breach a §3.2 far cap (the proxy then draws at every distance).
|
|
478
|
+
*/
|
|
479
|
+
async function authoredFarImpostor(shard: Shardfile, assets: Map<string, Uint8Array>): Promise<Shardfile> {
|
|
480
|
+
const far = shard.far, ref = shard.props?.far, glb = ref === null || ref === undefined ? undefined : assets.get(ref);
|
|
481
|
+
if (far === null || far.impostor !== undefined || glb === undefined) return shard;
|
|
482
|
+
await MeshoptDecoder.ready;
|
|
483
|
+
const doc = await new NodeIO().registerExtensions(ALL_EXTENSIONS).registerDependencies({ 'meshopt.decoder': MeshoptDecoder }).readBinary(glb);
|
|
484
|
+
const pos: number[] = [], col: number[] = [], idx: number[] = [], e = [0, 0, 0, 0];
|
|
485
|
+
for (const node of doc.getRoot().listNodes()) {
|
|
486
|
+
const mesh = node.getMesh(); if (mesh === null) continue;
|
|
487
|
+
const m = node.getWorldMatrix();
|
|
488
|
+
for (const prim of mesh.listPrimitives()) {
|
|
489
|
+
const p = prim.getAttribute('POSITION'), c = prim.getAttribute('COLOR_0'), index = prim.getIndices(), factor = prim.getMaterial()?.getBaseColorFactor() ?? [1, 1, 1, 1];
|
|
490
|
+
if (p === null) continue;
|
|
491
|
+
const base = pos.length / 3;
|
|
492
|
+
for (let i = 0; i < p.getCount(); i++) {
|
|
493
|
+
p.getElement(i, e);
|
|
494
|
+
const [x = 0, y = 0, z = 0] = e;
|
|
495
|
+
pos.push(m[0] * x + m[4] * y + m[8] * z + m[12], m[1] * x + m[5] * y + m[9] * z + m[13], m[2] * x + m[6] * y + m[10] * z + m[14]);
|
|
496
|
+
if (c === null) col.push(factor[0], factor[1], factor[2]); else { c.getElement(i, e); col.push((e[0] ?? 1) * factor[0], (e[1] ?? 1) * factor[1], (e[2] ?? 1) * factor[2]); }
|
|
497
|
+
}
|
|
498
|
+
const n = index === null ? p.getCount() : index.getCount();
|
|
499
|
+
for (let k = 0; k < n; k++) idx.push(base + (index === null ? k : index.getScalar(k)));
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (idx.length < 3) return shard;
|
|
503
|
+
const geometry = new BufferGeometry().setAttribute('position', new BufferAttribute(new Float32Array(pos), 3)).setAttribute('color', new BufferAttribute(new Float32Array(col), 3)).setIndex(idx);
|
|
504
|
+
const baked = await bakeFarImpostor(geometry, 'pbr');
|
|
505
|
+
const file: PlaceholderFile = { hash: hashImmutableBytes(baked.png), kind: 'image', compressed: baked.png.length, ...assetCost('image', baked.png), dependencies: [], critical: false };
|
|
506
|
+
const next = { ...far, files: [...far.files, file.hash], impostor: { file: file.hash, ...baked.row }, compressed: far.compressed + file.compressed, decoded: far.decoded + file.decoded, gpu: far.gpu + file.gpu };
|
|
507
|
+
if (next.decoded + next.gpu > CONTENT_CAPS.far.resident || next.compressed > CONTENT_CAPS.far.compressed) return shard;
|
|
508
|
+
assets.set(file.hash, baked.png);
|
|
509
|
+
return { ...shard, files: [...shard.files, file], far: next };
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** G380 / NM5: a world with no height field's near view from its own coarse tiles (`shardfileWorld`) over a flat floor
|
|
513
|
+
* under them; unchanged when it has none. */
|
|
514
|
+
export async function coarseNearView(shard: Shardfile, assets: Map<string, Uint8Array>, skip?: (material: string) => boolean, opaque?: (material: string) => boolean): Promise<Shardfile> {
|
|
515
|
+
const prototypes = await shardfileWorld(shard, assets, name => skip?.(name) === true || opaque?.(name) === true);
|
|
516
|
+
if (prototypes.length === 0) return shard;
|
|
517
|
+
const baked = await bakeNearPlaceholder({ grid: null, look: shardfileLook(shard), prototypes, residentBytes: Math.min(NEAR_BAKE.residentBytes, NEAR_PLACEHOLDER_LIMITS.contentBytes) });
|
|
518
|
+
const file = baked.manifest.file;
|
|
519
|
+
assets.set(file.hash, baked.bytes);
|
|
520
|
+
// NM13: what `skip` left out is light; it draws in its own additive layer over the near view (the grid's near loader
|
|
521
|
+
// keeps the mesh named NEAR_LIGHT apart from the lit draw)
|
|
522
|
+
const lightBytes = skip === undefined ? null : await nearLightGlb(shard, assets, name => skip(name) && opaque?.(name) !== true), lightFile = lightBytes === null ? null : fileRow(lightBytes);
|
|
523
|
+
if (lightBytes !== null && lightFile !== null) assets.set(lightFile.hash, lightBytes);
|
|
524
|
+
const colourBytes = opaque === undefined ? null : await nearLightGlb(shard, assets, opaque, NEAR_COLOUR), colourFile = colourBytes === null ? null : fileRow(colourBytes);
|
|
525
|
+
if (colourBytes !== null && colourFile !== null) assets.set(colourFile.hash, colourBytes);
|
|
526
|
+
const layers = [file, ...(lightFile === null ? [] : [lightFile]), ...(colourFile === null ? [] : [colourFile])];
|
|
527
|
+
const added = layers.filter(row => !shard.files.some(known => known.hash === row.hash));
|
|
528
|
+
return { ...shard, files: [...shard.files, ...added], near: { version: 1, terrain: [], content: layers.map(row => row.hash) } };
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** m²: light triangles smaller than this (a bulb, a firefly) leave the near light layer; pools, windows and lanterns stay */
|
|
532
|
+
const NEAR_LIGHT_MIN_AREA = 0.3;
|
|
533
|
+
/** The light primitives of the coarse tiles (`light` names their materials) as one non-indexed vertex-colour mesh. */
|
|
534
|
+
async function nearLightGlb(shard: Shardfile, assets: ReadonlyMap<string, Uint8Array>, light: (material: string) => boolean, nodeName = NEAR_LIGHT): Promise<Uint8Array | null> {
|
|
535
|
+
const prototypes = await shardfileWorld(shard, assets, name => !light(name)), positions: number[] = [], colours: number[] = [];
|
|
536
|
+
const m = new Matrix4(), a = new Vector3(), b = new Vector3(), c = new Vector3(), e1 = new Vector3(), e2 = new Vector3();
|
|
537
|
+
for (const p of prototypes) for (const t of p.transforms) {
|
|
538
|
+
m.fromArray(t);
|
|
539
|
+
for (let k = 0; k + 2 < p.index.length; k += 3) {
|
|
540
|
+
const ia = p.index[k] ?? 0, ib = p.index[k + 1] ?? 0, ic = p.index[k + 2] ?? 0;
|
|
541
|
+
a.fromArray(p.positions, ia * 3).applyMatrix4(m); b.fromArray(p.positions, ib * 3).applyMatrix4(m); c.fromArray(p.positions, ic * 3).applyMatrix4(m);
|
|
542
|
+
if (e1.subVectors(b, a).cross(e2.subVectors(c, a)).length() / 2 < NEAR_LIGHT_MIN_AREA) continue;
|
|
543
|
+
for (const [v, i] of [[a, ia], [b, ib], [c, ic]] as const) {
|
|
544
|
+
positions.push(v.x, v.y, v.z); colours.push(p.colours[i * 3] ?? 0, p.colours[i * 3 + 1] ?? 0, p.colours[i * 3 + 2] ?? 0);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (positions.length === 0) return null;
|
|
549
|
+
const geometry = new BufferGeometry();
|
|
550
|
+
geometry.setAttribute('position', new Float32BufferAttribute(positions, 3)); geometry.setAttribute('color', new Float32BufferAttribute(colours, 3));
|
|
551
|
+
return staticGlb([{ geometry, material: new MeshBasicMaterial({ vertexColors: true }), name: nodeName, castShadow: false }], nodeName);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* G348: `wildshard build`'s placeholders for any shardfile with a terrain: its far proxy when it ships none, and its near
|
|
556
|
+
* placeholder (one render-only GLB in `near.content`) when it declares none, both from its own terrain collider, its own
|
|
557
|
+
* coarse tiles' meshes and its own look. A shard without a height field (an authored mesh world ships its own far) keeps
|
|
558
|
+
* its far and gets its near view from its coarse tiles over a flat floor (G380). New files are added to `assets` and the returned shardfile.
|
|
559
|
+
*/
|
|
560
|
+
export async function projectPlaceholders(project: Shardfile, assets: Map<string, Uint8Array>): Promise<Shardfile> {
|
|
561
|
+
const shard = await authoredFarImpostor(project, assets);
|
|
562
|
+
const collider = shard.terrain === null ? undefined : assets.get(shard.terrain.collider);
|
|
563
|
+
// G380: a world with no height field (an authored mesh world, which ships its own far) gets its near view from its
|
|
564
|
+
// coarse tiles alone, over a flat floor under them; none when it has no coarse tile meshes
|
|
565
|
+
if (shard.terrain === null && shard.near === undefined) return coarseNearView(shard, assets);
|
|
566
|
+
if (collider === undefined || (shard.far !== null && shard.near !== undefined)) return shard;
|
|
567
|
+
const grid = colliderGrid(collider), look = shardfileLook(shard), files = [...shard.files];
|
|
568
|
+
let far = shard.far, near = shard.near;
|
|
569
|
+
if (far === null) {
|
|
570
|
+
const baked = await bakeFarPlaceholder(grid, look);
|
|
571
|
+
far = baked.manifest.far; files.push(baked.manifest.file, baked.manifest.impostorFile);
|
|
572
|
+
assets.set(baked.manifest.file.hash, baked.bytes); assets.set(baked.manifest.impostorFile.hash, baked.impostor);
|
|
573
|
+
}
|
|
574
|
+
if (near === undefined) {
|
|
575
|
+
const baked = await bakeNearPlaceholder({ grid, look, prototypes: await shardfileWorld(shard, assets), residentBytes: Math.min(NEAR_BAKE.residentBytes, NEAR_PLACEHOLDER_LIMITS.contentBytes) });
|
|
576
|
+
const file = baked.manifest.file;
|
|
577
|
+
if (!files.some(row => row.hash === file.hash)) files.push(file);
|
|
578
|
+
assets.set(file.hash, baked.bytes); near = { version: 1, terrain: [], content: [file.hash] };
|
|
579
|
+
}
|
|
580
|
+
return { ...shard, files, far, near };
|
|
581
|
+
}
|