@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,571 @@
|
|
|
1
|
+
"""Clean an image-to-3D mesh into a game prop: Driftwood's low-poly, faceted, vertex-coloured hero props (the default),
|
|
2
|
+
or, with --keep-texture, a photoreal PBR prop (Pine Hollow, PINE-HOLLOW-REMASTER PH-0.3). Metres, pivot at the base.
|
|
3
|
+
|
|
4
|
+
blender -b -P scripts/img2mesh/driftwood_post.py -- --in ~/ml/img2mesh/out/driftwood/palm-a.glb \
|
|
5
|
+
--name palm-a --out public/assets/models/driftwood-hero --tris 1800 --fit height --size 9
|
|
6
|
+
|
|
7
|
+
What it does (headless, deterministic):
|
|
8
|
+
1. imports the generated glb (TRELLIS.2: ~40 k faces + a baked 1024² base-colour texture), joins it, drops floating
|
|
9
|
+
crumbs (< --min-part of the largest loose part);
|
|
10
|
+
2. --split: a sheet of several objects (the boulder set, the driftwood set, beach clutter) becomes one asset per
|
|
11
|
+
cluster of touching parts, named <name>-1..n left to right (or --names a,b,c);
|
|
12
|
+
3. collapse-decimates each asset to --tris triangles, flat shaded (the faceted look);
|
|
13
|
+
4. colours every low-poly FACE with the mean of the generated texture under it (4 samples through a BVH onto the
|
|
14
|
+
high mesh), then grades it (--sat, --val) and snaps it to --quant k-means colours: one flat colour per facet;
|
|
15
|
+
5. bakes Cycles ambient occlusion into the vertex colour ALPHA (the convention of scripts/blender/ and
|
|
16
|
+
src/shards/driftwood-isle/world/BlenderIsland.ts: RGB = albedo, A = AO);
|
|
17
|
+
6. scales so the largest asset's --fit (height | length) is --size metres (a set keeps its relative sizes), puts the
|
|
18
|
+
pivot at the centre of the lowest 3 % of the mesh (a leaning palm pivots on its trunk foot) at z = 0;
|
|
19
|
+
7. exports <out>/<asset>/<asset>.glb (no textures, COLOR_0 only) + <asset>.json (tris, size, colours).
|
|
20
|
+
Then scripts/img2mesh/build_props.py (build_driftwood.sh) meshopt-compresses the glbs with gltf-transform.
|
|
21
|
+
|
|
22
|
+
--keep-texture (PBR, a photoreal shard): no facet flattening. Steps 4-5 become: smooth shading (sharp past
|
|
23
|
+
--smooth-angle), the generated texture baked UNGRADED onto the low mesh's own UVs (--atlas, default 1024) plus a
|
|
24
|
+
tangent-space normal map from the high mesh (--normal-map N², default the atlas size; 0 = none); no vertex colour, no AO
|
|
25
|
+
bake. Step 7 exports <asset>.glb with that PBR material (WebP base colour + normal, --roughness), no .tex.glb.
|
|
26
|
+
|
|
27
|
+
--geo <mesh.obj> (HI3D-REFINE, E494): a Hi3D-refined mesh from scripts/img2mesh/hi3d_refine.py, already in the --in
|
|
28
|
+
GLB's frame. Its geometry is decimated in place of the generated mesh's and is the normal map's high mesh; the colour
|
|
29
|
+
(facets, atlas) still comes from the generated texture of --in.
|
|
30
|
+
"""
|
|
31
|
+
import argparse
|
|
32
|
+
import json
|
|
33
|
+
import math
|
|
34
|
+
import os
|
|
35
|
+
import sys
|
|
36
|
+
|
|
37
|
+
import bmesh
|
|
38
|
+
import bpy
|
|
39
|
+
import numpy as np
|
|
40
|
+
from mathutils import Vector
|
|
41
|
+
from mathutils.bvhtree import BVHTree
|
|
42
|
+
|
|
43
|
+
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
|
44
|
+
ap = argparse.ArgumentParser()
|
|
45
|
+
ap.add_argument("--in", dest="src", required=True)
|
|
46
|
+
ap.add_argument("--geo", default="", help="a Hi3D-refined mesh in --in's frame: its geometry, --in's colour")
|
|
47
|
+
ap.add_argument("--name", required=True)
|
|
48
|
+
ap.add_argument("--out", required=True)
|
|
49
|
+
ap.add_argument("--tris", default="1500", help="triangle budget per asset; a comma list gives one per --split asset")
|
|
50
|
+
ap.add_argument("--fit", choices=["height", "length"], default="height")
|
|
51
|
+
ap.add_argument("--size", type=float, required=True, help="metres of --fit on the largest asset")
|
|
52
|
+
ap.add_argument("--split", action="store_true")
|
|
53
|
+
ap.add_argument("--names", default="")
|
|
54
|
+
ap.add_argument("--min-part", type=float, default=0.01)
|
|
55
|
+
ap.add_argument("--seed", type=float, default=0.08, help="--split: a loose part this share of the largest is its own asset")
|
|
56
|
+
ap.add_argument("--quant", type=int, default=10)
|
|
57
|
+
ap.add_argument("--sat", type=float, default=1.15)
|
|
58
|
+
ap.add_argument("--val", type=float, default=1.05)
|
|
59
|
+
ap.add_argument("--ao", type=float, default=0.12, help="AO distance as a fraction of the asset size; 0 = no bake")
|
|
60
|
+
ap.add_argument("--up", default="", help="rotate before fitting: x90 / x-90 / y90 ... (if the generation lies down)")
|
|
61
|
+
ap.add_argument("--yaw", type=float, default=0.0, help="degrees about z applied before export")
|
|
62
|
+
ap.add_argument("--remesh", type=float, default=0.0, help="voxel-remesh first (voxel = this x size) for solid props")
|
|
63
|
+
ap.add_argument("--simplifier", choices=["fqmr", "blender"], default="fqmr",
|
|
64
|
+
help="fqmr = fast-simplification (quadric, ignores the generator's open borders); blender = collapse")
|
|
65
|
+
ap.add_argument("--planar", type=float, default=0.0, help="degrees: planar-dissolve what the collapse left over budget")
|
|
66
|
+
ap.add_argument("--solidify", type=float, default=0.0, help="thicken open shells by this x size before --remesh")
|
|
67
|
+
ap.add_argument("--atlas", type=int, default=0, help="also bake the generated texture to an N² WebP atlas (<name>.tex.glb)")
|
|
68
|
+
ap.add_argument("--keep-texture", action="store_true",
|
|
69
|
+
help="PBR mode (photoreal shards): keep the texture, no facet colours / grade / quant, smooth shading")
|
|
70
|
+
ap.add_argument("--normal-map", type=int, default=-1, help="--keep-texture: N² normal map baked from the high mesh (default the atlas size, 0 = none)")
|
|
71
|
+
ap.add_argument("--roughness", type=float, default=0.9, help="--keep-texture: the material's roughness")
|
|
72
|
+
ap.add_argument("--metal-off", action="store_true",
|
|
73
|
+
help="bake colour as if the generation had no metallic map (a TRELLIS creature's fur reads black)")
|
|
74
|
+
ap.add_argument("--recalc-normals", action="store_true",
|
|
75
|
+
help="after decimating, turn every face outward (a generation's patches of inside-out faces show as holes under back-face culling)")
|
|
76
|
+
ap.add_argument("--smooth-angle", type=float, default=40.0, help="--keep-texture: edges sharper than this (degrees) stay hard")
|
|
77
|
+
a = ap.parse_args(argv)
|
|
78
|
+
if a.keep_texture:
|
|
79
|
+
a.atlas = a.atlas or 1024
|
|
80
|
+
a.normal_map = a.atlas if a.normal_map < 0 else a.normal_map
|
|
81
|
+
|
|
82
|
+
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
83
|
+
bpy.ops.import_scene.gltf(filepath=os.path.expanduser(a.src))
|
|
84
|
+
meshes = [o for o in bpy.context.scene.objects if o.type == "MESH"]
|
|
85
|
+
bpy.ops.object.select_all(action="DESELECT")
|
|
86
|
+
for o in meshes:
|
|
87
|
+
o.select_set(True)
|
|
88
|
+
bpy.context.view_layer.objects.active = meshes[0]
|
|
89
|
+
if len(meshes) > 1:
|
|
90
|
+
bpy.ops.object.join()
|
|
91
|
+
hi = bpy.context.view_layer.objects.active
|
|
92
|
+
bpy.ops.object.parent_clear(type="CLEAR_KEEP_TRANSFORM")
|
|
93
|
+
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
|
94
|
+
if a.up:
|
|
95
|
+
ax, deg = a.up[0].upper(), float(a.up[1:])
|
|
96
|
+
hi.rotation_mode = "XYZ" # the glTF importer leaves objects in QUATERNION mode: euler edits would be ignored
|
|
97
|
+
hi.rotation_euler["XYZ".index(ax)] = math.radians(deg)
|
|
98
|
+
bpy.ops.object.transform_apply(rotation=True)
|
|
99
|
+
geo = None
|
|
100
|
+
if a.geo: # the OBJ importer's Y-up → Z-up matches the glTF importer's, so --geo lands on hi
|
|
101
|
+
bpy.ops.object.select_all(action="DESELECT")
|
|
102
|
+
bpy.ops.wm.obj_import(filepath=os.path.expanduser(a.geo), forward_axis="NEGATIVE_Z", up_axis="Y")
|
|
103
|
+
geo = bpy.context.selected_objects[0]
|
|
104
|
+
bpy.context.view_layer.objects.active = geo
|
|
105
|
+
if a.up:
|
|
106
|
+
geo.rotation_mode = "XYZ"
|
|
107
|
+
geo.rotation_euler["XYZ".index(ax)] = math.radians(deg)
|
|
108
|
+
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
|
109
|
+
geo.select_set(False)
|
|
110
|
+
|
|
111
|
+
# --- the generated texture as a numpy array (sRGB-encoded values, as stored) ---
|
|
112
|
+
def base_image(obj):
|
|
113
|
+
for slot in obj.material_slots:
|
|
114
|
+
m = slot.material
|
|
115
|
+
if not m or not m.use_nodes:
|
|
116
|
+
continue
|
|
117
|
+
for n in m.node_tree.nodes:
|
|
118
|
+
if n.type == "BSDF_PRINCIPLED":
|
|
119
|
+
link = n.inputs["Base Color"].links
|
|
120
|
+
if link and link[0].from_node.type == "TEX_IMAGE":
|
|
121
|
+
return link[0].from_node.image
|
|
122
|
+
for n in m.node_tree.nodes:
|
|
123
|
+
if n.type == "TEX_IMAGE":
|
|
124
|
+
return n.image
|
|
125
|
+
return None
|
|
126
|
+
|
|
127
|
+
img = base_image(hi)
|
|
128
|
+
if img is None:
|
|
129
|
+
sys.exit("no base colour texture on the input")
|
|
130
|
+
W, H = img.size
|
|
131
|
+
px = np.empty(W * H * 4, dtype=np.float32)
|
|
132
|
+
img.pixels.foreach_get(px)
|
|
133
|
+
px = px.reshape(H, W, 4)
|
|
134
|
+
if img.colorspace_settings.name != "sRGB": # pixels come back linear for a non-sRGB image: encode
|
|
135
|
+
px[..., :3] = np.where(px[..., :3] <= 0.0031308, px[..., :3] * 12.92, 1.055 * np.power(px[..., :3], 1 / 2.4) - 0.055)
|
|
136
|
+
|
|
137
|
+
# --- high mesh: triangulated, with per-triangle UVs, in a BVH ---
|
|
138
|
+
bm_hi = bmesh.new()
|
|
139
|
+
bm_hi.from_mesh(hi.data)
|
|
140
|
+
bmesh.ops.triangulate(bm_hi, faces=bm_hi.faces[:])
|
|
141
|
+
uv_layer = bm_hi.loops.layers.uv.active
|
|
142
|
+
bm_hi.faces.ensure_lookup_table()
|
|
143
|
+
tri_uv = np.array([[l[uv_layer].uv[:] for l in f.loops] for f in bm_hi.faces], dtype=np.float32)
|
|
144
|
+
tri_co = np.array([[l.vert.co[:] for l in f.loops] for f in bm_hi.faces], dtype=np.float32)
|
|
145
|
+
bvh = BVHTree.FromBMesh(bm_hi)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def sample(points):
|
|
149
|
+
"""sRGB colour of the generated texture at the surface nearest to each point."""
|
|
150
|
+
out = []
|
|
151
|
+
for p in points:
|
|
152
|
+
loc, _n, idx, _d = bvh.find_nearest(Vector(p))
|
|
153
|
+
if idx is None:
|
|
154
|
+
out.append((0.5, 0.5, 0.5))
|
|
155
|
+
continue
|
|
156
|
+
A, B, C = tri_co[idx]
|
|
157
|
+
v0, v1, v2 = B - A, C - A, np.array(loc) - A
|
|
158
|
+
d00, d01, d11 = v0 @ v0, v0 @ v1, v1 @ v1
|
|
159
|
+
d20, d21 = v2 @ v0, v2 @ v1
|
|
160
|
+
den = d00 * d11 - d01 * d01 or 1e-12
|
|
161
|
+
v = (d11 * d20 - d01 * d21) / den
|
|
162
|
+
w = (d00 * d21 - d01 * d20) / den
|
|
163
|
+
u = 1 - v - w
|
|
164
|
+
uv = u * tri_uv[idx][0] + v * tri_uv[idx][1] + w * tri_uv[idx][2]
|
|
165
|
+
x = int(np.clip(uv[0] % 1.0, 0, 0.9999) * W)
|
|
166
|
+
y = int(np.clip(uv[1] % 1.0, 0, 0.9999) * H)
|
|
167
|
+
out.append(tuple(px[y, x, :3]))
|
|
168
|
+
return np.array(out)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
# --- split into loose parts, drop crumbs, cluster touching parts into assets ---
|
|
172
|
+
bpy.ops.object.select_all(action="DESELECT")
|
|
173
|
+
src = geo or hi
|
|
174
|
+
src.select_set(True)
|
|
175
|
+
bpy.context.view_layer.objects.active = src
|
|
176
|
+
bpy.ops.object.duplicate()
|
|
177
|
+
work = bpy.context.view_layer.objects.active
|
|
178
|
+
# the baked glb is split along its UV seams: weld it first, or the seams read as loose parts and decimation stalls
|
|
179
|
+
bm_w = bmesh.new()
|
|
180
|
+
bm_w.from_mesh(work.data)
|
|
181
|
+
diag = max(work.dimensions)
|
|
182
|
+
bmesh.ops.remove_doubles(bm_w, verts=bm_w.verts[:], dist=1e-4 * diag)
|
|
183
|
+
bm_w.to_mesh(work.data)
|
|
184
|
+
bm_w.free()
|
|
185
|
+
bpy.ops.object.mode_set(mode="EDIT")
|
|
186
|
+
bpy.ops.mesh.select_all(action="SELECT")
|
|
187
|
+
bpy.ops.mesh.separate(type="LOOSE")
|
|
188
|
+
bpy.ops.object.mode_set(mode="OBJECT")
|
|
189
|
+
parts = [o for o in bpy.context.selected_objects]
|
|
190
|
+
sizes = {o.name: len(o.data.polygons) for o in parts}
|
|
191
|
+
big = max(sizes.values())
|
|
192
|
+
for o in list(parts):
|
|
193
|
+
if sizes[o.name] < a.min_part * big:
|
|
194
|
+
bpy.data.objects.remove(o, do_unlink=True)
|
|
195
|
+
parts.remove(o)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def bbox(o):
|
|
199
|
+
cs = [o.matrix_world @ Vector(c) for c in o.bound_box]
|
|
200
|
+
return Vector((min(c.x for c in cs), min(c.y for c in cs), min(c.z for c in cs))), \
|
|
201
|
+
Vector((max(c.x for c in cs), max(c.y for c in cs), max(c.z for c in cs)))
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if a.split:
|
|
205
|
+
# seeds = the big loose parts; a small part joins the seed it (nearly) touches, else it is its own asset
|
|
206
|
+
from mathutils.kdtree import KDTree
|
|
207
|
+
span = max(max(bbox(o)[1][k] for o in parts) - min(bbox(o)[0][k] for o in parts) for k in range(3))
|
|
208
|
+
big = max(len(o.data.polygons) for o in parts)
|
|
209
|
+
seeds = [o for o in parts if len(o.data.polygons) >= a.seed * big]
|
|
210
|
+
groups = {o.name: [o] for o in seeds}
|
|
211
|
+
trees = {}
|
|
212
|
+
for o in seeds:
|
|
213
|
+
vs = [o.matrix_world @ v.co for v in o.data.vertices]
|
|
214
|
+
t = KDTree(len(vs))
|
|
215
|
+
for i, v in enumerate(vs):
|
|
216
|
+
t.insert(v, i)
|
|
217
|
+
t.balance()
|
|
218
|
+
trees[o.name] = t
|
|
219
|
+
for o in parts:
|
|
220
|
+
if o in seeds:
|
|
221
|
+
continue
|
|
222
|
+
vs = [o.matrix_world @ v.co for v in o.data.vertices][::7] or [Vector()]
|
|
223
|
+
best, bd = None, 1e9
|
|
224
|
+
for nm, t in trees.items():
|
|
225
|
+
d = min(t.find(v)[2] for v in vs)
|
|
226
|
+
if d < bd:
|
|
227
|
+
best, bd = nm, d
|
|
228
|
+
if best is not None and bd < 0.03 * span:
|
|
229
|
+
groups[best].append(o)
|
|
230
|
+
else:
|
|
231
|
+
groups[o.name] = [o]
|
|
232
|
+
groups = sorted(groups.values(), key=lambda g: min(bbox(o)[0].x for o in g))
|
|
233
|
+
else:
|
|
234
|
+
groups = [parts]
|
|
235
|
+
|
|
236
|
+
names = [n for n in a.names.split(",") if n] or \
|
|
237
|
+
([f"{a.name}-{i + 1}" for i in range(len(groups))] if a.split else [a.name])
|
|
238
|
+
assets = []
|
|
239
|
+
for g, nm in zip(groups, names):
|
|
240
|
+
bpy.ops.object.select_all(action="DESELECT")
|
|
241
|
+
for o in g:
|
|
242
|
+
o.select_set(True)
|
|
243
|
+
bpy.context.view_layer.objects.active = g[0]
|
|
244
|
+
if len(g) > 1:
|
|
245
|
+
bpy.ops.object.join()
|
|
246
|
+
ob = bpy.context.view_layer.objects.active
|
|
247
|
+
ob.name = nm
|
|
248
|
+
assets.append(ob)
|
|
249
|
+
|
|
250
|
+
def bake_atlas(ob):
|
|
251
|
+
"""Cycles selected-to-active DIFFUSE colour bake from the generated mesh onto ob's own smart-project UVs."""
|
|
252
|
+
scene = bpy.context.scene
|
|
253
|
+
scene.render.engine = "CYCLES"
|
|
254
|
+
scene.cycles.device = "CPU"
|
|
255
|
+
scene.cycles.samples = 4
|
|
256
|
+
bpy.ops.object.select_all(action="DESELECT")
|
|
257
|
+
ob.select_set(True)
|
|
258
|
+
bpy.context.view_layer.objects.active = ob
|
|
259
|
+
ob.data.uv_layers.new(name="UVMap")
|
|
260
|
+
bpy.ops.object.mode_set(mode="EDIT")
|
|
261
|
+
bpy.ops.mesh.select_all(action="SELECT")
|
|
262
|
+
bpy.ops.uv.smart_project(angle_limit=math.radians(60), island_margin=0.004)
|
|
263
|
+
bpy.ops.object.mode_set(mode="OBJECT")
|
|
264
|
+
im = bpy.data.images.new(ob.name + "-albedo", a.atlas, a.atlas)
|
|
265
|
+
mat = bpy.data.materials.new(ob.name + "-tex")
|
|
266
|
+
mat.use_nodes = True
|
|
267
|
+
tn = mat.node_tree.nodes.new("ShaderNodeTexImage")
|
|
268
|
+
tn.image = im
|
|
269
|
+
mat.node_tree.nodes.active = tn
|
|
270
|
+
ob.data.materials.clear()
|
|
271
|
+
ob.data.materials.append(mat)
|
|
272
|
+
hi.hide_render = False
|
|
273
|
+
hi.select_set(True)
|
|
274
|
+
for slot in hi.material_slots: # Hunyuan3D-2 GLBs omit metallicFactor (glTF default 1): a DIFFUSE bake reads black
|
|
275
|
+
if slot.material and slot.material.use_nodes:
|
|
276
|
+
for n in slot.material.node_tree.nodes:
|
|
277
|
+
if n.type == "BSDF_PRINCIPLED" and a.metal_off:
|
|
278
|
+
for link in list(n.inputs["Metallic"].links):
|
|
279
|
+
slot.material.node_tree.links.remove(link)
|
|
280
|
+
if n.type == "BSDF_PRINCIPLED" and not n.inputs["Metallic"].links:
|
|
281
|
+
n.inputs["Metallic"].default_value = 0.0
|
|
282
|
+
size = max(ob.dimensions)
|
|
283
|
+
bk = scene.render.bake
|
|
284
|
+
bk.use_selected_to_active = True
|
|
285
|
+
bk.cage_extrusion = 0.01 * size
|
|
286
|
+
bk.max_ray_distance = 0.05 * size
|
|
287
|
+
bk.margin = 4
|
|
288
|
+
bk.target = "IMAGE_TEXTURES"
|
|
289
|
+
bk.use_pass_direct = bk.use_pass_indirect = False
|
|
290
|
+
bk.use_pass_color = True
|
|
291
|
+
bpy.ops.object.bake(type="DIFFUSE", pass_filter={"COLOR"})
|
|
292
|
+
if a.keep_texture and a.normal_map > 0: # PBR: the high mesh's detail as a tangent-space normal map
|
|
293
|
+
imn = bpy.data.images.new(ob.name + "-normal", a.normal_map, a.normal_map)
|
|
294
|
+
imn.colorspace_settings.name = "Non-Color"
|
|
295
|
+
nn = mat.node_tree.nodes.new("ShaderNodeTexImage")
|
|
296
|
+
nn.image = imn
|
|
297
|
+
mat.node_tree.nodes.active = nn
|
|
298
|
+
bk.normal_space = "TANGENT"
|
|
299
|
+
if geo: # --geo: the refined mesh's detail, not the generated one's
|
|
300
|
+
hi.select_set(False)
|
|
301
|
+
geo.select_set(True)
|
|
302
|
+
bpy.ops.object.bake(type="NORMAL")
|
|
303
|
+
if geo:
|
|
304
|
+
geo.select_set(False)
|
|
305
|
+
hi.select_set(True)
|
|
306
|
+
ob["normal"] = imn.name
|
|
307
|
+
bk.use_selected_to_active = False
|
|
308
|
+
hi.select_set(False)
|
|
309
|
+
ob["atlas"] = im.name
|
|
310
|
+
if a.keep_texture:
|
|
311
|
+
return # PBR: the texture as generated, no grade
|
|
312
|
+
# the same grade as the facet colours
|
|
313
|
+
n = a.atlas * a.atlas
|
|
314
|
+
pix = np.empty(n * 4, dtype=np.float32)
|
|
315
|
+
im.pixels.foreach_get(pix)
|
|
316
|
+
pix = pix.reshape(n, 4)
|
|
317
|
+
c = pix[:, :3]
|
|
318
|
+
mx, mn = c.max(1), c.min(1)
|
|
319
|
+
s_ = np.where(mx > 0, (mx - mn) / np.maximum(mx, 1e-6), 0)
|
|
320
|
+
c = mx[:, None] + (c - mx[:, None]) * (np.clip(s_ * a.sat, 0, 1) / np.maximum(s_, 1e-6))[:, None]
|
|
321
|
+
pix[:, :3] = np.clip(c * a.val, 0, 1)
|
|
322
|
+
im.pixels.foreach_set(pix.ravel())
|
|
323
|
+
im.update()
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
# --- one scale for the whole set: the largest asset's fit dimension = --size ---
|
|
327
|
+
def dims(o):
|
|
328
|
+
lo, hi_ = bbox(o)
|
|
329
|
+
d = hi_ - lo
|
|
330
|
+
return d, (d.z if a.fit == "height" else max(d.x, d.y))
|
|
331
|
+
|
|
332
|
+
scale = a.size / max(dims(o)[1] for o in assets)
|
|
333
|
+
report = []
|
|
334
|
+
out_root = os.path.abspath(os.path.expanduser(a.out))
|
|
335
|
+
budgets = [int(t) for t in a.tris.split(",")]
|
|
336
|
+
for ai, ob in enumerate(assets):
|
|
337
|
+
budget = budgets[min(ai, len(budgets) - 1)]
|
|
338
|
+
# decimate to the triangle budget, flat shaded
|
|
339
|
+
bpy.ops.object.select_all(action="DESELECT")
|
|
340
|
+
ob.select_set(True)
|
|
341
|
+
bpy.context.view_layer.objects.active = ob
|
|
342
|
+
tris_now = sum(len(p.vertices) - 2 for p in ob.data.polygons)
|
|
343
|
+
ob.data.validate()
|
|
344
|
+
if a.solidify > 0: # open thin shells (the wreck's planks): give them thickness so a voxel remesh keeps them
|
|
345
|
+
so = ob.modifiers.new("solid", "SOLIDIFY")
|
|
346
|
+
so.thickness = a.solidify * max(ob.dimensions)
|
|
347
|
+
so.offset = 0.0
|
|
348
|
+
bpy.ops.object.modifier_apply(modifier=so.name)
|
|
349
|
+
if a.remesh > 0: # solid props: a voxel remesh drops the generator's inner shells and slivers before decimating
|
|
350
|
+
rm = ob.modifiers.new("remesh", "REMESH")
|
|
351
|
+
rm.mode = "VOXEL"
|
|
352
|
+
rm.voxel_size = a.remesh * max(ob.dimensions)
|
|
353
|
+
rm.adaptivity = 0.0
|
|
354
|
+
bpy.ops.object.modifier_apply(modifier=rm.name)
|
|
355
|
+
tri0 = ob.modifiers.new("tri0", "TRIANGULATE")
|
|
356
|
+
bpy.ops.object.modifier_apply(modifier=tri0.name)
|
|
357
|
+
if a.simplifier == "fqmr" and len(ob.data.polygons) > budget:
|
|
358
|
+
# TRELLIS-mac meshes keep their holes (no cumesh hole filling): Blender's collapse will not cross the open
|
|
359
|
+
# borders and stalls at 3-5x the budget; a quadric simplifier without border locking gets there cleanly.
|
|
360
|
+
site = os.path.expanduser(os.environ.get("BLENDER_SITE", "~/ml/img2mesh/blender-site"))
|
|
361
|
+
if site not in sys.path:
|
|
362
|
+
sys.path.append(site)
|
|
363
|
+
import fast_simplification
|
|
364
|
+
me0 = ob.data
|
|
365
|
+
v = np.array([vv.co[:] for vv in me0.vertices], dtype=np.float32)
|
|
366
|
+
f = np.array([pp.vertices[:] for pp in me0.polygons], dtype=np.int64)
|
|
367
|
+
sv, sf = fast_simplification.simplify(v, f, target_reduction=1.0 - budget / len(f))
|
|
368
|
+
me0.clear_geometry()
|
|
369
|
+
me0.from_pydata(sv.tolist(), [], sf.tolist())
|
|
370
|
+
me0.update()
|
|
371
|
+
for _ in range(12): # blender: one big collapse stalls on generated meshes; step down x0.3 per pass
|
|
372
|
+
tris_now = sum(len(p.vertices) - 2 for p in ob.data.polygons)
|
|
373
|
+
if tris_now <= budget * 1.02:
|
|
374
|
+
break
|
|
375
|
+
mod = ob.modifiers.new("dec", "DECIMATE")
|
|
376
|
+
mod.decimate_type = "COLLAPSE"
|
|
377
|
+
mod.ratio = max(budget / tris_now, 0.3)
|
|
378
|
+
mod.use_collapse_triangulate = True
|
|
379
|
+
bpy.ops.object.modifier_apply(modifier=mod.name)
|
|
380
|
+
if a.planar > 0 and len(ob.data.polygons) > budget * 1.1: # still over: merge near-coplanar facets (keeps thin parts)
|
|
381
|
+
pl = ob.modifiers.new("planar", "DECIMATE")
|
|
382
|
+
pl.decimate_type = "DISSOLVE"
|
|
383
|
+
pl.angle_limit = math.radians(a.planar)
|
|
384
|
+
bpy.ops.object.modifier_apply(modifier=pl.name)
|
|
385
|
+
t2 = ob.modifiers.new("tri2", "TRIANGULATE")
|
|
386
|
+
bpy.ops.object.modifier_apply(modifier=t2.name)
|
|
387
|
+
print("DEC", ob.name, "->", len(ob.data.polygons), flush=True)
|
|
388
|
+
tri = ob.modifiers.new("tri", "TRIANGULATE")
|
|
389
|
+
bpy.ops.object.modifier_apply(modifier=tri.name)
|
|
390
|
+
if a.recalc_normals:
|
|
391
|
+
bm_n = bmesh.new()
|
|
392
|
+
bm_n.from_mesh(ob.data)
|
|
393
|
+
bmesh.ops.recalc_face_normals(bm_n, faces=bm_n.faces[:])
|
|
394
|
+
bm_n.to_mesh(ob.data)
|
|
395
|
+
bm_n.free()
|
|
396
|
+
for p in ob.data.polygons:
|
|
397
|
+
p.use_smooth = False
|
|
398
|
+
me = ob.data
|
|
399
|
+
if a.keep_texture: # PBR: smooth, hard only past --smooth-angle
|
|
400
|
+
me.shade_smooth()
|
|
401
|
+
me.set_sharp_from_angle(angle=math.radians(a.smooth_angle))
|
|
402
|
+
for uv in list(me.uv_layers):
|
|
403
|
+
me.uv_layers.remove(uv)
|
|
404
|
+
if a.atlas:
|
|
405
|
+
bake_atlas(ob)
|
|
406
|
+
|
|
407
|
+
if a.keep_texture:
|
|
408
|
+
palette = [] # PBR: the baked texture carries the colour
|
|
409
|
+
else:
|
|
410
|
+
# one colour per facet: mean of 4 texture samples under the face
|
|
411
|
+
co = np.array([v.co[:] for v in me.vertices], dtype=np.float32)
|
|
412
|
+
cols = []
|
|
413
|
+
for p in me.polygons:
|
|
414
|
+
vs = co[list(p.vertices)]
|
|
415
|
+
c = vs.mean(0)
|
|
416
|
+
pts = [c] + [0.6 * c + 0.4 * v for v in vs]
|
|
417
|
+
cols.append(sample(pts).mean(0))
|
|
418
|
+
cols = np.clip(np.array(cols), 0, 1)
|
|
419
|
+
|
|
420
|
+
# grade in HSV: a touch more saturation / value, like the painted concept
|
|
421
|
+
mx, mn = cols.max(1), cols.min(1)
|
|
422
|
+
s = np.where(mx > 0, (mx - mn) / np.maximum(mx, 1e-6), 0)
|
|
423
|
+
grey = mx[:, None]
|
|
424
|
+
cols = grey + (cols - grey) * (np.clip(s * a.sat, 0, 1) / np.maximum(s, 1e-6))[:, None]
|
|
425
|
+
cols = np.clip(cols * a.val, 0, 1)
|
|
426
|
+
|
|
427
|
+
# snap to k flat colours (k-means, area-weighted): the hand-painted facet palette
|
|
428
|
+
if a.quant > 0 and len(cols) > a.quant:
|
|
429
|
+
area = np.array([p.area for p in me.polygons]) + 1e-9
|
|
430
|
+
rng = np.random.default_rng(1)
|
|
431
|
+
cent = cols[rng.choice(len(cols), a.quant, replace=False, p=area / area.sum())]
|
|
432
|
+
for _ in range(20):
|
|
433
|
+
lab = ((cols[:, None, :] - cent[None]) ** 2).sum(2).argmin(1)
|
|
434
|
+
for k in range(a.quant):
|
|
435
|
+
m = lab == k
|
|
436
|
+
if m.any():
|
|
437
|
+
cent[k] = (cols[m] * area[m, None]).sum(0) / area[m].sum()
|
|
438
|
+
cols = cent[lab]
|
|
439
|
+
palette = sorted({"#%02x%02x%02x" % tuple(int(round(v * 255)) for v in c) for c in cent[np.unique(lab)]})
|
|
440
|
+
else:
|
|
441
|
+
palette = []
|
|
442
|
+
|
|
443
|
+
attr = me.color_attributes.new("Color", "FLOAT_COLOR", "CORNER")
|
|
444
|
+
for p, c in zip(me.polygons, cols):
|
|
445
|
+
for li in p.loop_indices:
|
|
446
|
+
attr.data[li].color_srgb = (float(c[0]), float(c[1]), float(c[2]), 1.0)
|
|
447
|
+
|
|
448
|
+
# scale + pivot: metres, the base of the prop at the origin
|
|
449
|
+
ob.scale = (scale, scale, scale)
|
|
450
|
+
bpy.ops.object.transform_apply(scale=True)
|
|
451
|
+
co = np.array([v.co[:] for v in me.vertices], dtype=np.float32)
|
|
452
|
+
zmin, zmax = co[:, 2].min(), co[:, 2].max()
|
|
453
|
+
foot = co[co[:, 2] <= zmin + 0.03 * (zmax - zmin)]
|
|
454
|
+
pivot = np.array([foot[:, 0].mean(), foot[:, 1].mean(), zmin])
|
|
455
|
+
for v in me.vertices:
|
|
456
|
+
v.co = Vector(np.array(v.co[:]) - pivot)
|
|
457
|
+
ob.location = (0, 0, 0)
|
|
458
|
+
if a.yaw:
|
|
459
|
+
ob.rotation_mode = "XYZ"
|
|
460
|
+
ob.rotation_euler[2] = math.radians(a.yaw)
|
|
461
|
+
bpy.ops.object.transform_apply(rotation=True)
|
|
462
|
+
report.append((ob, palette))
|
|
463
|
+
|
|
464
|
+
# --- AO into the vertex colour alpha (Cycles, per asset, alone in the scene; not in PBR mode: no vertex colour) ---
|
|
465
|
+
if a.ao > 0 and not a.keep_texture:
|
|
466
|
+
scene = bpy.context.scene
|
|
467
|
+
scene.render.engine = "CYCLES"
|
|
468
|
+
scene.cycles.device = "CPU"
|
|
469
|
+
scene.cycles.samples = 64
|
|
470
|
+
if scene.world is None:
|
|
471
|
+
scene.world = bpy.data.worlds.new("w")
|
|
472
|
+
mat = bpy.data.materials.new("bake")
|
|
473
|
+
mat.use_nodes = True
|
|
474
|
+
for ob, _ in report:
|
|
475
|
+
others = [o for o in scene.objects if o is not ob]
|
|
476
|
+
for o in others:
|
|
477
|
+
o.hide_render = True
|
|
478
|
+
ob.data.materials.clear()
|
|
479
|
+
ob.data.materials.append(mat)
|
|
480
|
+
d = max(ob.dimensions)
|
|
481
|
+
scene.world.light_settings.distance = max(0.05, a.ao * d)
|
|
482
|
+
ao = ob.data.color_attributes.new("AO", "FLOAT_COLOR", "CORNER")
|
|
483
|
+
ob.data.color_attributes.active_color = ao
|
|
484
|
+
bpy.ops.object.select_all(action="DESELECT")
|
|
485
|
+
ob.select_set(True)
|
|
486
|
+
bpy.context.view_layer.objects.active = ob
|
|
487
|
+
scene.render.bake.target = "VERTEX_COLORS"
|
|
488
|
+
bpy.ops.object.bake(type="AO")
|
|
489
|
+
col = ob.data.color_attributes["Color"]
|
|
490
|
+
for i in range(len(col.data)):
|
|
491
|
+
r, g, b, _ = col.data[i].color
|
|
492
|
+
aov = ao.data[i].color[0]
|
|
493
|
+
col.data[i].color = (r, g, b, 0.35 + 0.65 * aov)
|
|
494
|
+
ob.data.color_attributes.remove(ao)
|
|
495
|
+
ob.data.color_attributes.active_color = ob.data.color_attributes["Color"]
|
|
496
|
+
for o in others:
|
|
497
|
+
o.hide_render = False
|
|
498
|
+
|
|
499
|
+
# --- export: one glb per asset, a plain material that reads the vertex colour ---
|
|
500
|
+
out_mat = bpy.data.materials.new("driftwood-hero")
|
|
501
|
+
out_mat.use_nodes = True
|
|
502
|
+
nt = out_mat.node_tree
|
|
503
|
+
bsdf = nt.nodes["Principled BSDF"]
|
|
504
|
+
vc = nt.nodes.new("ShaderNodeVertexColor")
|
|
505
|
+
vc.layer_name = "Color"
|
|
506
|
+
nt.links.new(vc.outputs["Color"], bsdf.inputs["Base Color"])
|
|
507
|
+
bsdf.inputs["Roughness"].default_value = 0.9
|
|
508
|
+
summary = []
|
|
509
|
+
for ob, palette in report:
|
|
510
|
+
d = ob.dimensions
|
|
511
|
+
folder = os.path.join(out_root, ob.name)
|
|
512
|
+
os.makedirs(folder, exist_ok=True)
|
|
513
|
+
path = os.path.join(folder, ob.name + ".glb")
|
|
514
|
+
bpy.ops.object.select_all(action="DESELECT")
|
|
515
|
+
ob.select_set(True)
|
|
516
|
+
if a.keep_texture: # PBR: base colour + normal atlases, constant roughness, no COLOR_0
|
|
517
|
+
pm = bpy.data.materials.new(ob.name + "-pbr")
|
|
518
|
+
pm.use_nodes = True
|
|
519
|
+
pt = pm.node_tree
|
|
520
|
+
pb = pt.nodes["Principled BSDF"]
|
|
521
|
+
tn = pt.nodes.new("ShaderNodeTexImage")
|
|
522
|
+
tn.image = bpy.data.images[ob["atlas"]]
|
|
523
|
+
pt.links.new(tn.outputs["Color"], pb.inputs["Base Color"])
|
|
524
|
+
if "normal" in ob:
|
|
525
|
+
nt_ = pt.nodes.new("ShaderNodeTexImage")
|
|
526
|
+
nt_.image = bpy.data.images[ob["normal"]]
|
|
527
|
+
nm = pt.nodes.new("ShaderNodeNormalMap")
|
|
528
|
+
pt.links.new(nt_.outputs["Color"], nm.inputs["Color"])
|
|
529
|
+
pt.links.new(nm.outputs["Normal"], pb.inputs["Normal"])
|
|
530
|
+
pb.inputs["Roughness"].default_value = a.roughness
|
|
531
|
+
pb.inputs["Metallic"].default_value = 0.0
|
|
532
|
+
ob.data.materials.clear()
|
|
533
|
+
ob.data.materials.append(pm)
|
|
534
|
+
bpy.ops.export_scene.gltf(filepath=path, export_format="GLB", use_selection=True, export_yup=True,
|
|
535
|
+
export_vertex_color="NONE", export_normals=True, export_tangents="normal" in ob,
|
|
536
|
+
export_image_format="WEBP", export_image_quality=85)
|
|
537
|
+
info = {"name": ob.name, "source": os.path.basename(a.src), "tris": len(ob.data.polygons),
|
|
538
|
+
"size_m": [round(d.x, 2), round(d.y, 2), round(d.z, 2)], "pivot": "base centre, z=0 (Blender z-up; glTF y-up)",
|
|
539
|
+
"material": f"PBR: {a.atlas}² WebP base colour (ungraded)"
|
|
540
|
+
+ (f" + {a.normal_map}² tangent-space normal map" if "normal" in ob else "")
|
|
541
|
+
+ f", roughness {a.roughness}, smooth shading (hard past {a.smooth_angle}°), no COLOR_0",
|
|
542
|
+
"palette": palette}
|
|
543
|
+
json.dump(info, open(os.path.join(folder, ob.name + ".json"), "w"), indent=1)
|
|
544
|
+
summary.append(info)
|
|
545
|
+
continue
|
|
546
|
+
ob.data.materials.clear()
|
|
547
|
+
ob.data.materials.append(out_mat)
|
|
548
|
+
bpy.ops.export_scene.gltf(filepath=path, export_format="GLB", use_selection=True, export_yup=True,
|
|
549
|
+
export_vertex_color="ACTIVE", export_all_vertex_colors=False, export_normals=True,
|
|
550
|
+
export_image_format="NONE")
|
|
551
|
+
info = {"name": ob.name, "source": os.path.basename(a.src), "tris": len(ob.data.polygons),
|
|
552
|
+
"size_m": [round(d.x, 2), round(d.y, 2), round(d.z, 2)], "pivot": "base centre, z=0 (Blender z-up; glTF y-up)",
|
|
553
|
+
"vertex_colour": "COLOR_0 rgb = albedo (sRGB-graded, stored linear), a = Cycles AO (0.35..1)",
|
|
554
|
+
"palette": palette}
|
|
555
|
+
if a.atlas and "atlas" in ob:
|
|
556
|
+
tm = bpy.data.materials.new(ob.name + "-tex-out")
|
|
557
|
+
tm.use_nodes = True
|
|
558
|
+
tb = tm.node_tree.nodes["Principled BSDF"]
|
|
559
|
+
tn = tm.node_tree.nodes.new("ShaderNodeTexImage")
|
|
560
|
+
tn.image = bpy.data.images[ob["atlas"]]
|
|
561
|
+
tm.node_tree.links.new(tn.outputs["Color"], tb.inputs["Base Color"])
|
|
562
|
+
tb.inputs["Roughness"].default_value = 0.9
|
|
563
|
+
ob.data.materials.clear()
|
|
564
|
+
ob.data.materials.append(tm)
|
|
565
|
+
bpy.ops.export_scene.gltf(filepath=os.path.join(folder, ob.name + ".tex.glb"), export_format="GLB",
|
|
566
|
+
use_selection=True, export_yup=True, export_vertex_color="NONE",
|
|
567
|
+
export_normals=True, export_image_format="WEBP", export_image_quality=85)
|
|
568
|
+
info["atlas"] = f"{ob.name}.tex.glb: {a.atlas}² WebP base colour on smart-project UVs, no COLOR_0"
|
|
569
|
+
json.dump(info, open(os.path.join(folder, ob.name + ".json"), "w"), indent=1)
|
|
570
|
+
summary.append(info)
|
|
571
|
+
print("DRIFTWOOD_POST " + json.dumps([{k: s[k] for k in ("name", "tris", "size_m")} for s in summary]))
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# e304_faces.sh — E304: the face remaster for the models outside Nalati's camp (Pine Hollow's hamlet, the Drowned Captain):
|
|
3
|
+
#
|
|
4
|
+
# scripts/img2mesh/e304_faces.sh <hunyuan|hunyuanref|paint|sharp> <name …> (paint: the codex bust, no projection)
|
|
5
|
+
#
|
|
6
|
+
# Per name (scripts/img2mesh/faces-e304.json): the shipped body (desktop + phone, decoded by nalati-faces-decode.mjs) →
|
|
7
|
+
# Blender face_remaster.py (head-first re-UV + re-bake; hunyuan grafts the Hunyuan3D-2 bust ~/ml/img2mesh/out/e304-faces/
|
|
8
|
+
# hy/<bust>.glb made from the codex portrait, the portrait projected on its face; sharp only re-UVs; a PBR model also
|
|
9
|
+
# re-bakes its normal map) → gltf-transform: <dir>/faces-<variant>/<name>.glb (1024² WebP) + <name>.phone.glb (the
|
|
10
|
+
# phone body, a lighter head, 512² WebP), meshopt. CPU / Blender only (no model load, no lock). The busts come from the
|
|
11
|
+
# locked batch ~/ml/img2mesh/out/e304-faces/job.sh (portrait → BiRefNet cutout → Hunyuan3D-2 full).
|
|
12
|
+
set -euo pipefail
|
|
13
|
+
V=${1:?usage: e304_faces.sh <hunyuan|sharp> <name …>}; shift
|
|
14
|
+
REPO=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
|
|
15
|
+
W=$HOME/ml/img2mesh/out/e304-faces
|
|
16
|
+
GT=$REPO/node_modules/.bin/gltf-transform
|
|
17
|
+
mkdir -p "$W/body" "$W/final/$V"
|
|
18
|
+
for n in "$@"; do
|
|
19
|
+
mapfile -t CFG < <(python3 - "$REPO/scripts/img2mesh/faces-e304.json" "$n" <<'PY'
|
|
20
|
+
import json, sys
|
|
21
|
+
c = json.load(open(sys.argv[1]))["models"][sys.argv[2]]
|
|
22
|
+
print(c["body"]); print(c["phone"]); print(c["dir"]); print("1" if c.get("pbr") else "0"); print(c.get("bust", sys.argv[2]))
|
|
23
|
+
print(json.dumps(c))
|
|
24
|
+
PY
|
|
25
|
+
)
|
|
26
|
+
body=${CFG[0]} phone=${CFG[1]} dir=${CFG[2]} pbr=${CFG[3]} bust=${CFG[4]} json=${CFG[5]}
|
|
27
|
+
[ "$V" = hunyuanref ] && bust=$n # C: the bust from the model's own reference crop, not the codex portrait
|
|
28
|
+
out=$REPO/$dir/faces-$V; mkdir -p "$out"
|
|
29
|
+
for tier in desktop phone; do
|
|
30
|
+
src=$body; suf=""; tris=4000; tex=1024
|
|
31
|
+
if [ $tier = phone ]; then src=$phone; suf=".phone"; tris=2400; tex=1024; fi
|
|
32
|
+
[ -f "$W/body/$n$suf.glb" ] || node "$REPO/scripts/nalati-faces-decode.mjs" "$REPO/$src" "$W/body/$n$suf.glb" > /dev/null
|
|
33
|
+
mapfile -t A < <(python3 - "$json" "$V" "$W" "$bust" "$tris" "$pbr" <<'PY'
|
|
34
|
+
import json, sys
|
|
35
|
+
c, v, w, bust, tris, pbr = json.loads(sys.argv[1]), sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6] == "1"
|
|
36
|
+
out = ["--neck", str(c["neck"])]
|
|
37
|
+
if pbr:
|
|
38
|
+
out += ["--normal-map"]
|
|
39
|
+
if v.startswith("hunyuan") or v == "paint":
|
|
40
|
+
g = c.get("graft", {})
|
|
41
|
+
out += ["--graft", f"{w}/hy/{bust}.glb", "--bust-image", f"{w}/cut/{bust}.png", "--bust-neck", str(g.get("neck", 0.6)),
|
|
42
|
+
"--bust-clip", str(g.get("clip", 0.015)), "--bust-grow", str(g.get("grow", 1.0)), "--bust-dz", str(g.get("dz", 0.0)),
|
|
43
|
+
"--bust-dy", str(g.get("dy", 0.0)), "--head-tris", tris, "--smooth-face", str(g.get("smooth_face", 0.0 if pbr else 0.8))]
|
|
44
|
+
if v == "paint": # E339 D: Hunyuan3D-2's own all-round paint, no portrait projected
|
|
45
|
+
i = out.index("--bust-image"); del out[i:i + 2]
|
|
46
|
+
if g.get("v2", True): # E339 graft fix: the bust cut at its own neck, the ring blended, fragments dropped
|
|
47
|
+
out += ["--graft-v2", "--bust-neck-auto", "0.45", "0.8", "--bust-fit", g.get("fit", "height")]
|
|
48
|
+
if "beard" in g:
|
|
49
|
+
out += ["--bust-beard", str(g["beard"][0]), str(g["beard"][1])]
|
|
50
|
+
if "ptop" in g:
|
|
51
|
+
out += ["--project-top", str(g["ptop"])]
|
|
52
|
+
if "body_collar" in g:
|
|
53
|
+
out += ["--body-collar", str(g["body_collar"][0]), str(g["body_collar"][1])]
|
|
54
|
+
if "collar" in g:
|
|
55
|
+
out += ["--bust-collar", str(g["collar"][0]), str(g["collar"][1])]
|
|
56
|
+
print("\n".join(out))
|
|
57
|
+
PY
|
|
58
|
+
)
|
|
59
|
+
raw=$W/final/$V/$n$suf.raw.glb
|
|
60
|
+
/opt/homebrew/bin/blender -b -P "$REPO/scripts/img2mesh/face_remaster.py" -- --body "$W/body/$n$suf.glb" --out "$raw" --tex $tex \
|
|
61
|
+
--front "$W/final/$V/$n$suf.front.png" "${A[@]}" 2>&1 | grep -E '^\[face\]|Error|Traceback' || true
|
|
62
|
+
[ -f "$raw" ] || { echo "face_remaster failed for $n$suf ($V)"; exit 1; }
|
|
63
|
+
size=1024; [ $tier = phone ] && size=512
|
|
64
|
+
"$GT" optimize "$raw" "$out/$n$suf.glb" --compress meshopt --texture-compress webp --texture-size $size --simplify false --instance false > /dev/null
|
|
65
|
+
echo "[faces] $V/$n$suf: $(stat -f %z "$out/$n$suf.glb") B (was $(stat -f %z "$REPO/$src") B)"
|
|
66
|
+
done
|
|
67
|
+
done
|