@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,828 @@
|
|
|
1
|
+
"""Orient, clean and rig one training dummy (E285): a humanoid skeleton on a post, heat weights, one skinned draw.
|
|
2
|
+
|
|
3
|
+
blender -b -P scripts/practice/rig_dummy.py -- <baked.glb> <rigged.glb> --variant straw-cloth [--report r.json]
|
|
4
|
+
blender -b -P scripts/practice/rig_dummy.py -- <baked.glb> <normal.glb> --variant straw-cloth --stage normalize
|
|
5
|
+
|
|
6
|
+
<baked.glb> is scripts/practice/bake_dummy.py's closed, volume-textured TRELLIS.2 figure: one metre, Z-up, front along
|
|
7
|
+
--front (TRELLIS picks the facing per generation: -y, x, -x or y; the E215 bakes faced +X).
|
|
8
|
+
The game needs a 2.65 m figure standing at Y = 0 and facing +Z in three.js (Blender -Y): the code scales it by
|
|
9
|
+
TRAINING_DUMMY_SCALE = 1.8 / 2.65. `--stage normalize` stops after orienting and cleaning (for measuring joints).
|
|
10
|
+
|
|
11
|
+
Cleanup: weld, drop crumbs, delete the inner shells the narrow-band remesh leaves inside every closed part (they are
|
|
12
|
+
invisible and would double the triangle count), then decimate to the phone budget (--faces, 45k by default).
|
|
13
|
+
|
|
14
|
+
The skeleton, by the exact names src/client/engine/practice/TrainingDummy.ts reads (DUMMY_BONE_NAMES):
|
|
15
|
+
Root (the post foot, at the origin)
|
|
16
|
+
Pelvis > Spine > Chest > Neck > Head
|
|
17
|
+
Chest > {Left,Right}Shoulder > ...UpperArm > ...ForeArm > ...Hand
|
|
18
|
+
{Left,Right}Thigh > ...Shin (the legs hang from Root: the figure stands on its post and the upper body
|
|
19
|
+
sways from Pelvis / Spine without lifting the feet off the base)
|
|
20
|
+
Left is the figure's own left: +X in three.js when it faces +Z. Every bone's local Y runs along the bone; the spine
|
|
21
|
+
chain's local X is the figure's left and local Z its front, so rotation.x pitches it forward / back and rotation.z
|
|
22
|
+
leans it sideways. Arm bones are rolled so local Z points to the figure's front.
|
|
23
|
+
|
|
24
|
+
Weights: geodesic voxel binding (distance through the solid, see the weights section), then the post and base forced onto Root, the legs limited to their
|
|
25
|
+
own side's thigh / shin (with Pelvis only at the hip), arm and hand bones kept off the other side, the fists made
|
|
26
|
+
rigid on the hand, at most four influences, normalised. The joint positions per variant (JOINTS) were measured on
|
|
27
|
+
the E285 bakes with a metre grid; depth (Y) is taken from the mesh itself at each joint.
|
|
28
|
+
"""
|
|
29
|
+
import json
|
|
30
|
+
import math
|
|
31
|
+
import os
|
|
32
|
+
import sys
|
|
33
|
+
|
|
34
|
+
import bmesh
|
|
35
|
+
import bpy
|
|
36
|
+
from mathutils import Matrix, Vector
|
|
37
|
+
from mathutils.bvhtree import BVHTree
|
|
38
|
+
|
|
39
|
+
HEIGHT = 2.65
|
|
40
|
+
argv = sys.argv[sys.argv.index("--") + 1:]
|
|
41
|
+
source, target = argv[:2]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def opt(name, default=None):
|
|
45
|
+
return argv[argv.index(name) + 1] if name in argv else default
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
VARIANT = opt("--variant")
|
|
49
|
+
STAGE = opt("--stage", "rig")
|
|
50
|
+
FACES = int(opt("--faces", "45000"))
|
|
51
|
+
REPORT = opt("--report")
|
|
52
|
+
SOURCE_FRONT = opt("--front", "-y") # where the baked figure faces in Blender: -y | x | -x | y
|
|
53
|
+
|
|
54
|
+
# Figure-left joints (x >= 0) in metres after normalisation: (x, z). The right side mirrors them.
|
|
55
|
+
# post_r: half-width of the post + a margin; base_top: the top of the cross-foot base (everything under it is Root);
|
|
56
|
+
# hem: the skirt's lower edge; target: (z, radius) of the painted face target (straw and wood); helm: (bottom, top)
|
|
57
|
+
# of a closed great helm to line dark and plug (steel).
|
|
58
|
+
JOINTS = {
|
|
59
|
+
"straw-cloth": dict(pelvis=1.30, spine=1.55, chest=1.85, neck=2.17, head=2.27, crown=2.64,
|
|
60
|
+
clavicle=(0.07, 2.09), shoulder=(0.32, 2.02), elbow=(0.44, 1.72), wrist=(0.57, 1.47),
|
|
61
|
+
fist=(0.63, 1.27), hip=(0.19, 1.20), knee=(0.24, 0.83), ankle=(0.26, 0.27),
|
|
62
|
+
post_r=0.06, base_top=0.14, hem=1.00, target=(2.43, 0.105),
|
|
63
|
+
smooth=[(0.0, 2.15, 0.14), (0.63, 1.27, 0.11), (-0.63, 1.27, 0.11)], neck_plug=(1.9, 2.25)),
|
|
64
|
+
"wood": dict(pelvis=1.30, spine=1.55, chest=1.85, neck=2.17, head=2.29, crown=2.64,
|
|
65
|
+
clavicle=(0.07, 2.09), shoulder=(0.33, 2.02), elbow=(0.47, 1.73), wrist=(0.57, 1.48),
|
|
66
|
+
fist=(0.63, 1.27), hip=(0.20, 1.20), knee=(0.26, 0.92), ankle=(0.28, 0.32),
|
|
67
|
+
post_r=0.06, base_top=0.14, hem=1.00, target=(2.425, 0.10)),
|
|
68
|
+
"wood-steel": dict(pelvis=1.30, spine=1.55, chest=1.85, neck=2.17, head=2.22, crown=2.64,
|
|
69
|
+
clavicle=(0.07, 2.09), shoulder=(0.32, 2.02), elbow=(0.47, 1.76), wrist=(0.57, 1.50),
|
|
70
|
+
fist=(0.59, 1.30), hip=(0.19, 1.20), knee=(0.24, 0.86), ankle=(0.29, 0.30),
|
|
71
|
+
post_r=0.06, base_top=0.14, hem=1.00, helm=(2.22, 2.64), weather=True), # E289: great helm
|
|
72
|
+
}
|
|
73
|
+
if VARIANT not in JOINTS:
|
|
74
|
+
raise SystemExit(f"--variant must be one of {sorted(JOINTS)}")
|
|
75
|
+
J = JOINTS[VARIANT]
|
|
76
|
+
report = {"variant": VARIANT, "source": source}
|
|
77
|
+
|
|
78
|
+
# ---------------------------------------------------------------- import + orient
|
|
79
|
+
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
80
|
+
bpy.ops.import_scene.gltf(filepath=source)
|
|
81
|
+
meshes = [o for o in bpy.context.scene.objects if o.type == "MESH"]
|
|
82
|
+
if not meshes:
|
|
83
|
+
raise RuntimeError("no mesh in " + source)
|
|
84
|
+
for o in bpy.context.scene.objects:
|
|
85
|
+
o.select_set(o in meshes)
|
|
86
|
+
bpy.context.view_layer.objects.active = meshes[0]
|
|
87
|
+
if len(meshes) > 1:
|
|
88
|
+
bpy.ops.object.join()
|
|
89
|
+
mesh = bpy.context.view_layer.objects.active
|
|
90
|
+
bpy.ops.object.parent_clear(type="CLEAR_KEEP_TRANSFORM")
|
|
91
|
+
for o in list(bpy.context.scene.objects):
|
|
92
|
+
if o is not mesh:
|
|
93
|
+
bpy.data.objects.remove(o)
|
|
94
|
+
mesh.select_set(True)
|
|
95
|
+
bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
|
|
96
|
+
me = mesh.data
|
|
97
|
+
# The importer keeps the generator's split normals as custom normals, and they would not follow any vertex this
|
|
98
|
+
# script moves (spike relax, smoothing, the flattened face): drop them, the mesh's own smooth normals take over.
|
|
99
|
+
if me.has_custom_normals:
|
|
100
|
+
bpy.ops.mesh.customdata_custom_splitnormals_clear()
|
|
101
|
+
|
|
102
|
+
# TRELLIS picks the figure's facing per generation; turn it to face Blender -Y (glTF / three.js +Z).
|
|
103
|
+
TURN = {"-y": 0.0, "x": -90.0, "-x": 90.0, "y": 180.0}[SOURCE_FRONT]
|
|
104
|
+
if TURN:
|
|
105
|
+
me.transform(Matrix.Rotation(math.radians(TURN), 4, "Z"))
|
|
106
|
+
zs = [v.co.z for v in me.vertices]
|
|
107
|
+
zmin, zmax = min(zs), max(zs)
|
|
108
|
+
s = HEIGHT / (zmax - zmin)
|
|
109
|
+
base = [v.co for v in me.vertices if v.co.z < zmin + 0.10 * (zmax - zmin)]
|
|
110
|
+
cx = (min(p.x for p in base) + max(p.x for p in base)) / 2
|
|
111
|
+
cy = (min(p.y for p in base) + max(p.y for p in base)) / 2
|
|
112
|
+
me.transform(Matrix.Scale(s, 4) @ Matrix.Translation((-cx, -cy, -zmin)))
|
|
113
|
+
me.update()
|
|
114
|
+
mesh.name = "TrainingDummy"
|
|
115
|
+
me.name = "TrainingDummy"
|
|
116
|
+
|
|
117
|
+
# ---------------------------------------------------------------- cleanup
|
|
118
|
+
bm = bmesh.new()
|
|
119
|
+
bm.from_mesh(me)
|
|
120
|
+
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=1e-5)
|
|
121
|
+
bm.faces.ensure_lookup_table()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def components(bm):
|
|
125
|
+
seen = set()
|
|
126
|
+
out = []
|
|
127
|
+
for f in bm.faces:
|
|
128
|
+
if f.index in seen:
|
|
129
|
+
continue
|
|
130
|
+
stack, comp = [f], []
|
|
131
|
+
seen.add(f.index)
|
|
132
|
+
while stack:
|
|
133
|
+
g = stack.pop()
|
|
134
|
+
comp.append(g)
|
|
135
|
+
for e in g.edges:
|
|
136
|
+
for h in e.link_faces:
|
|
137
|
+
if h.index not in seen:
|
|
138
|
+
seen.add(h.index)
|
|
139
|
+
stack.append(h)
|
|
140
|
+
out.append(comp)
|
|
141
|
+
return out
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
comps = components(bm)
|
|
145
|
+
report["components_in"] = len(comps)
|
|
146
|
+
face_comp = {}
|
|
147
|
+
for ci, comp in enumerate(comps):
|
|
148
|
+
for f in comp:
|
|
149
|
+
face_comp[f.index] = ci
|
|
150
|
+
bvh = BVHTree.FromBMesh(bm)
|
|
151
|
+
dirs = [Vector(d) for d in ((1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1),
|
|
152
|
+
(0.577, 0.577, 0.577), (-0.577, -0.577, 0.577))]
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def enclosed(point, ci):
|
|
156
|
+
for d in dirs:
|
|
157
|
+
o = point + d * 1e-4
|
|
158
|
+
hit_other = False
|
|
159
|
+
for _ in range(64):
|
|
160
|
+
loc, _n, fi, _dist = bvh.ray_cast(o, d)
|
|
161
|
+
if loc is None:
|
|
162
|
+
break
|
|
163
|
+
if face_comp[fi] != ci:
|
|
164
|
+
hit_other = True
|
|
165
|
+
break
|
|
166
|
+
o = loc + d * 1e-4
|
|
167
|
+
if not hit_other:
|
|
168
|
+
return False
|
|
169
|
+
return True
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
drop = set()
|
|
173
|
+
crumbs = inner = 0
|
|
174
|
+
for ci, comp in enumerate(comps):
|
|
175
|
+
area = sum(f.calc_area() for f in comp)
|
|
176
|
+
if len(comp) < 40 or area < 2e-4:
|
|
177
|
+
drop.add(ci)
|
|
178
|
+
crumbs += 1
|
|
179
|
+
continue
|
|
180
|
+
if len(comp) == max(len(c) for c in comps):
|
|
181
|
+
continue
|
|
182
|
+
step = max(1, len(comp) // 24)
|
|
183
|
+
samples = [comp[i].calc_center_median() for i in range(0, len(comp), step)]
|
|
184
|
+
if sum(enclosed(p, ci) for p in samples) >= 0.85 * len(samples):
|
|
185
|
+
drop.add(ci)
|
|
186
|
+
inner += 1
|
|
187
|
+
bmesh.ops.delete(bm, geom=[f for ci in drop for f in comps[ci]], context="FACES")
|
|
188
|
+
|
|
189
|
+
# Pinholes: the remesh's clean-up leaves a few small open loops; with the inner wall culled below they would be
|
|
190
|
+
# see-through. Fill every open loop of up to 24 edges, UVs borrowed from each vertex's neighbouring face.
|
|
191
|
+
boundary = [e for e in bm.edges if e.is_boundary]
|
|
192
|
+
before = set(bm.faces)
|
|
193
|
+
bmesh.ops.holes_fill(bm, edges=boundary, sides=24)
|
|
194
|
+
uv = bm.loops.layers.uv.active
|
|
195
|
+
filled = [f for f in bm.faces if f not in before]
|
|
196
|
+
for f in filled:
|
|
197
|
+
for loop in f.loops:
|
|
198
|
+
for other in loop.vert.link_loops:
|
|
199
|
+
if other.face not in filled and other.face.is_valid:
|
|
200
|
+
loop[uv].uv = other[uv].uv.copy()
|
|
201
|
+
break
|
|
202
|
+
bmesh.ops.triangulate(bm, faces=[f for f in filled if len(f.verts) > 3])
|
|
203
|
+
report["filled_holes"] = len(filled)
|
|
204
|
+
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
205
|
+
|
|
206
|
+
# Hidden faces: the remesh thickens every crust into a shell, so a closed part keeps an inner wall no camera can
|
|
207
|
+
# see. A face is kept when any of 160 rays (a Fibonacci sphere, from just off either side of it) escapes the figure.
|
|
208
|
+
bm.faces.ensure_lookup_table()
|
|
209
|
+
bvh = BVHTree.FromBMesh(bm)
|
|
210
|
+
K = 160
|
|
211
|
+
golden = math.pi * (3 - math.sqrt(5))
|
|
212
|
+
sphere = []
|
|
213
|
+
for k in range(K):
|
|
214
|
+
zk = 1 - 2 * (k + 0.5) / K
|
|
215
|
+
rk = math.sqrt(1 - zk * zk)
|
|
216
|
+
sphere.append(Vector((math.cos(golden * k) * rk, math.sin(golden * k) * rk, zk)))
|
|
217
|
+
hidden = []
|
|
218
|
+
for f in bm.faces:
|
|
219
|
+
c = f.calc_center_median()
|
|
220
|
+
n = f.normal
|
|
221
|
+
seen = False
|
|
222
|
+
for d in sphere:
|
|
223
|
+
o = c + (n if d.dot(n) >= 0 else -n) * 2e-4 + d * 1e-4
|
|
224
|
+
if bvh.ray_cast(o, d)[0] is None:
|
|
225
|
+
seen = True
|
|
226
|
+
break
|
|
227
|
+
if not seen:
|
|
228
|
+
hidden.append(f)
|
|
229
|
+
# A culled face that would leave a pinhole in a kept surface (two or more of its edges border kept faces) is a false
|
|
230
|
+
# positive of the ray test (grazing slivers); put it back, repeatedly, until no pinhole is left.
|
|
231
|
+
hidden = set(hidden)
|
|
232
|
+
while True:
|
|
233
|
+
back = [f for f in hidden if sum(1 for e in f.edges if any(g not in hidden and g is not f for g in e.link_faces)) >= 2]
|
|
234
|
+
if not back:
|
|
235
|
+
break
|
|
236
|
+
hidden.difference_update(back)
|
|
237
|
+
hidden = list(hidden)
|
|
238
|
+
report["dropped_hidden_faces"] = len(hidden)
|
|
239
|
+
bmesh.ops.delete(bm, geom=hidden, context="FACES")
|
|
240
|
+
loose = [v for v in bm.verts if not v.link_faces]
|
|
241
|
+
bmesh.ops.delete(bm, geom=loose, context="VERTS")
|
|
242
|
+
# The cull can open a pit the rays could not see into (the straw fists, the collar, E289): close every open loop of up
|
|
243
|
+
# to 80 edges the cull left, UVs borrowed from the neighbouring faces.
|
|
244
|
+
before = set(bm.faces)
|
|
245
|
+
bmesh.ops.holes_fill(bm, edges=[e for e in bm.edges if e.is_boundary], sides=80)
|
|
246
|
+
refilled = [f for f in bm.faces if f not in before]
|
|
247
|
+
for f in refilled:
|
|
248
|
+
for loop in f.loops:
|
|
249
|
+
for other in loop.vert.link_loops:
|
|
250
|
+
if other.face not in refilled and other.face.is_valid:
|
|
251
|
+
loop[uv].uv = other[uv].uv.copy()
|
|
252
|
+
break
|
|
253
|
+
bmesh.ops.triangulate(bm, faces=[f for f in refilled if len(f.verts) > 3])
|
|
254
|
+
report["refilled_after_cull"] = len(refilled)
|
|
255
|
+
|
|
256
|
+
# Winding: TRELLIS's shells come back with mixed winding (the material is double-sided, so it only showed as dark
|
|
257
|
+
# patches where smooth normals of opposite faces cancel: the straw collar and fists, E289). Every face turns to the
|
|
258
|
+
# side it can be seen from: of 16 rays on each side of it, the side more of them escape from is outside.
|
|
259
|
+
bm.faces.ensure_lookup_table()
|
|
260
|
+
bm.normal_update()
|
|
261
|
+
tree = BVHTree.FromBMesh(bm)
|
|
262
|
+
hemi = sphere[::10]
|
|
263
|
+
flipped = 0
|
|
264
|
+
for f in bm.faces:
|
|
265
|
+
c = f.calc_center_median()
|
|
266
|
+
n = f.normal
|
|
267
|
+
if n.length < 1e-8:
|
|
268
|
+
continue
|
|
269
|
+
plus = minus = 0
|
|
270
|
+
for d in hemi[:16]:
|
|
271
|
+
dd = d if d.dot(n) >= 0 else -d
|
|
272
|
+
if tree.ray_cast(c + n * 2e-4 + dd * 1e-4, dd)[0] is None:
|
|
273
|
+
plus += 1
|
|
274
|
+
if tree.ray_cast(c - n * 2e-4 - dd * 1e-4, -dd)[0] is None:
|
|
275
|
+
minus += 1
|
|
276
|
+
if minus > plus:
|
|
277
|
+
f.normal_flip()
|
|
278
|
+
flipped += 1
|
|
279
|
+
report["faces_flipped_outward"] = flipped
|
|
280
|
+
report["dropped_crumbs"] = crumbs
|
|
281
|
+
report["dropped_inner_shells"] = inner
|
|
282
|
+
|
|
283
|
+
# Needles: the remesh leaves single-vertex spikes on thin rims (helmet brim, pauldron edges). A vertex sitting more
|
|
284
|
+
# than 0.75 mean edge lengths off the average of its neighbours (a needle: every neighbour on one side) is pulled
|
|
285
|
+
# most of the way back, twice.
|
|
286
|
+
spikes = 0
|
|
287
|
+
for _ in range(2):
|
|
288
|
+
moves = []
|
|
289
|
+
for v in bm.verts:
|
|
290
|
+
if len(v.link_edges) < 3 or v.is_boundary: # a ragged hem keeps its rags
|
|
291
|
+
continue
|
|
292
|
+
nb = [e.other_vert(v).co for e in v.link_edges]
|
|
293
|
+
avg = sum(nb, Vector()) / len(nb)
|
|
294
|
+
mean_len = sum((c - v.co).length for c in nb) / len(nb)
|
|
295
|
+
if (avg - v.co).length > 0.75 * mean_len:
|
|
296
|
+
moves.append((v, v.co.lerp(avg, 0.8)))
|
|
297
|
+
for v, co in moves:
|
|
298
|
+
v.co = co
|
|
299
|
+
spikes += len(moves)
|
|
300
|
+
report["spikes_relaxed"] = spikes
|
|
301
|
+
bm.to_mesh(me)
|
|
302
|
+
bm.free()
|
|
303
|
+
me.update()
|
|
304
|
+
tris = sum(len(p.vertices) - 2 for p in me.polygons)
|
|
305
|
+
report["tris_after_clean"] = tris
|
|
306
|
+
if tris > FACES:
|
|
307
|
+
dec = mesh.modifiers.new("budget", "DECIMATE")
|
|
308
|
+
dec.ratio = FACES / tris
|
|
309
|
+
dec.use_collapse_triangulate = True
|
|
310
|
+
bpy.ops.object.modifier_apply(modifier=dec.name)
|
|
311
|
+
report["tris"] = sum(len(p.vertices) - 2 for p in me.polygons)
|
|
312
|
+
report["verts"] = len(me.vertices)
|
|
313
|
+
for p in me.polygons:
|
|
314
|
+
p.use_smooth = True
|
|
315
|
+
|
|
316
|
+
if STAGE == "normalize":
|
|
317
|
+
bpy.ops.export_scene.gltf(filepath=target, export_format="GLB", export_yup=True, export_animations=False)
|
|
318
|
+
print("REPORT", json.dumps(report))
|
|
319
|
+
raise SystemExit(0)
|
|
320
|
+
|
|
321
|
+
# ---------------------------------------------------------------- skeleton
|
|
322
|
+
verts = [v.co.copy() for v in me.vertices]
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def depth(x, z, r=0.06):
|
|
326
|
+
"""The mesh's own front-back centre near (x, z): bones sit inside the figure, not on its front plane."""
|
|
327
|
+
ys = [p.y for p in verts if abs(p.x - x) < r and abs(p.z - z) < r]
|
|
328
|
+
if not ys:
|
|
329
|
+
return 0.0
|
|
330
|
+
return (min(ys) + max(ys)) / 2
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def P(x, z):
|
|
334
|
+
return Vector((x, depth(x, z), z))
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
# ---------------------------------------------------------------- E289 finishing passes (scripts/practice/dummy_parts.py)
|
|
338
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
339
|
+
import dummy_parts as parts # noqa: E402
|
|
340
|
+
|
|
341
|
+
parts.squeeze_atlas(me)
|
|
342
|
+
if J.get("smooth"): # the straw neck and fists: pull the remesh flakes in
|
|
343
|
+
spheres = [((x, depth(x, z, 0.08), z), r) for x, z, r in J["smooth"]]
|
|
344
|
+
report["smoothed_verts"] = parts.smooth_regions(me, spheres)
|
|
345
|
+
parts.despeckle(me, spheres, report)
|
|
346
|
+
if J.get("neck_plug"):
|
|
347
|
+
fists = [((x, depth(x, z, 0.08), z), r) for x, z, r in J.get("smooth", []) if abs(x) > 0.3]
|
|
348
|
+
parts.neck_plug(me, *J["neck_plug"], report, fists=fists)
|
|
349
|
+
if J.get("target"): # the dent under the face target
|
|
350
|
+
report["face_flattened_verts"] = parts.flatten_face(me, J["target"][0], J["target"][1], depth(0.0, J["target"][0], 0.08))
|
|
351
|
+
if J.get("weather"):
|
|
352
|
+
parts.weather_steel(me, report)
|
|
353
|
+
BASE_IDX = parts.replace_base(me, J, depth, report)
|
|
354
|
+
verts = [v.co.copy() for v in me.vertices]
|
|
355
|
+
|
|
356
|
+
# ---------------------------------------------------------------- the face target
|
|
357
|
+
# TRELLIS draws the painted target from one front view and smears it: lopsided rings with a diamond or a spiral in
|
|
358
|
+
# the middle (E285). Repaint it into the base-colour texture as the approved sheets have it: red dot, white, red
|
|
359
|
+
# ring, white, red ring, projected flat from the front onto the front of the head. The cloth / wood grain of the
|
|
360
|
+
# Around the new rings the old smear fades to the plain surface (the median texel further out), grain kept.
|
|
361
|
+
def paint_target(cz, radius):
|
|
362
|
+
import numpy as np
|
|
363
|
+
mat = me.materials[0]
|
|
364
|
+
tex = next(n for n in mat.node_tree.nodes if n.type == "TEX_IMAGE" and any(
|
|
365
|
+
l.to_socket.name == "Base Color" for l in n.outputs["Color"].links))
|
|
366
|
+
img = tex.image
|
|
367
|
+
W_, H_ = img.size
|
|
368
|
+
px = np.empty(W_ * H_ * 4, np.float32)
|
|
369
|
+
img.pixels.foreach_get(px)
|
|
370
|
+
px = px.reshape(H_, W_, 4)
|
|
371
|
+
red, white = np.array([0.66, 0.12, 0.09]), np.array([0.90, 0.87, 0.80])
|
|
372
|
+
bands = [(0.00, 0.19, red), (0.19, 0.38, white), (0.38, 0.58, red), (0.58, 0.77, white), (0.77, 0.97, red)]
|
|
373
|
+
uv = me.uv_layers.active.data
|
|
374
|
+
head_y = depth(0.0, cz, 0.08)
|
|
375
|
+
|
|
376
|
+
def texel_patches():
|
|
377
|
+
"""(slice, inside mask, r) for every front-of-head triangle near the target, in texture space."""
|
|
378
|
+
for poly in me.polygons:
|
|
379
|
+
c = poly.center
|
|
380
|
+
if abs(c.x) > radius * 1.9 or abs(c.z - cz) > radius * 1.9 or c.y > head_y or (
|
|
381
|
+
poly.normal.y > -0.25 and math.hypot(c.x, c.z - cz) > radius): # inside the disc: every face
|
|
382
|
+
continue
|
|
383
|
+
if len(poly.vertices) != 3:
|
|
384
|
+
continue
|
|
385
|
+
P3 = [me.vertices[i].co for i in poly.vertices]
|
|
386
|
+
T2 = [uv[li].uv for li in poly.loop_indices]
|
|
387
|
+
xs = [t.x * W_ for t in T2]
|
|
388
|
+
ys = [t.y * H_ for t in T2]
|
|
389
|
+
x0, x1 = max(0, int(min(xs)) - 2), min(W_ - 1, int(max(xs)) + 2)
|
|
390
|
+
y0, y1 = max(0, int(min(ys)) - 2), min(H_ - 1, int(max(ys)) + 2)
|
|
391
|
+
gx, gy = np.meshgrid(np.arange(x0, x1 + 1) + 0.5, np.arange(y0, y1 + 1) + 0.5)
|
|
392
|
+
(ax, ay), (bx, by), (qx, qy) = zip(xs, ys)
|
|
393
|
+
den = (by - qy) * (ax - qx) + (qx - bx) * (ay - qy)
|
|
394
|
+
if abs(den) < 1e-9:
|
|
395
|
+
continue
|
|
396
|
+
l0 = ((by - qy) * (gx - qx) + (qx - bx) * (gy - qy)) / den
|
|
397
|
+
l1 = ((qy - ay) * (gx - qx) + (ax - qx) * (gy - qy)) / den
|
|
398
|
+
l2 = 1 - l0 - l1
|
|
399
|
+
inside = (l0 > -0.08) & (l1 > -0.08) & (l2 > -0.08) # a texel of gutter too, so mips do not bleed
|
|
400
|
+
if not inside.any():
|
|
401
|
+
continue
|
|
402
|
+
X = l0 * P3[0].x + l1 * P3[1].x + l2 * P3[2].x
|
|
403
|
+
Z = l0 * P3[0].z + l1 * P3[1].z + l2 * P3[2].z
|
|
404
|
+
yield (slice(y0, y1 + 1), slice(x0, x1 + 1)), inside, np.hypot(X, Z - cz) / radius
|
|
405
|
+
|
|
406
|
+
# the plain surface around the old smear (hood cloth / bare wood): an unpainted texel just outside it
|
|
407
|
+
def plain_texels(sl, m, r):
|
|
408
|
+
t = px[sl][..., :3]
|
|
409
|
+
unpainted = (t[..., 1] > 0.6 * t[..., 0]) & (t.mean(-1) > 0.25)
|
|
410
|
+
return t[m & (r > 1.0) & (r < 1.6) & unpainted]
|
|
411
|
+
ring = [plain_texels(sl, m, r) for sl, m, r in texel_patches()]
|
|
412
|
+
ring = np.concatenate([x for x in ring if len(x)]) if any(len(x) for x in ring) else np.array([[0.8, 0.8, 0.8]])
|
|
413
|
+
surface = np.percentile(ring, 75, axis=0) # the lit cloth / wood, not the grey smudges round the old rings
|
|
414
|
+
s_lum = float(surface.mean())
|
|
415
|
+
painted = 0
|
|
416
|
+
for sl, inside, r in texel_patches():
|
|
417
|
+
region = px[sl][..., :3]
|
|
418
|
+
# past the new outer ring the old smeared rings fade to the plain surface, keeping the grain's light / dark
|
|
419
|
+
lum = region.mean(-1, keepdims=True)
|
|
420
|
+
old_paint = (region[..., 1:2] < 0.6 * region[..., 0:1]) | (lum < 0.25)
|
|
421
|
+
plain = np.where(old_paint, surface, surface * np.clip(lum / s_lum, 0.9, 1.08))
|
|
422
|
+
fade = np.clip((1.45 - r) / 0.2, 0, 1)[..., None]
|
|
423
|
+
base = region * (1 - fade) + plain * fade
|
|
424
|
+
colour = np.zeros_like(region)
|
|
425
|
+
alpha = np.zeros(r.shape, np.float32)
|
|
426
|
+
for lo_, hi_, col in bands:
|
|
427
|
+
edge = 0.025
|
|
428
|
+
a_ = np.clip((r - lo_ + edge) / (2 * edge), 0, 1) * np.clip((hi_ - r + edge) / (2 * edge), 0, 1)
|
|
429
|
+
colour += a_[..., None] * col
|
|
430
|
+
alpha = np.maximum(alpha, a_)
|
|
431
|
+
out = base * (1 - alpha[..., None]) + np.clip(colour, 0, 1) * alpha[..., None]
|
|
432
|
+
m = inside[..., None]
|
|
433
|
+
px[sl][..., :3] = np.where(m, out, region)
|
|
434
|
+
painted += 1
|
|
435
|
+
img.pixels.foreach_set(px.ravel())
|
|
436
|
+
img.pack()
|
|
437
|
+
return painted, [round(float(c), 3) for c in surface]
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
if J.get("target"):
|
|
441
|
+
report["target_faces_painted"] = paint_target(*J["target"])
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
# ---------------------------------------------------------------- a closed helm (E289)
|
|
445
|
+
# The great helm's eye slit and breaths look into the helm. TRELLIS leaves its inside lit steel, and through the slit
|
|
446
|
+
# (which wraps round the front corners) the room shows straight through the head. So: every inward-facing helm face
|
|
447
|
+
# takes a dark texel, and a dark plug (a 16-sided cylinder at 70 % of the helm's inner width) fills the head, so a
|
|
448
|
+
# slit only ever shows shadow. The dark texel is an 8x8 block painted in a free corner of the atlas.
|
|
449
|
+
def close_helm(z0, z1):
|
|
450
|
+
import numpy as np
|
|
451
|
+
mat = me.materials[0]
|
|
452
|
+
tex = next(n for n in mat.node_tree.nodes if n.type == "TEX_IMAGE" and any(
|
|
453
|
+
l.to_socket.name == "Base Color" for l in n.outputs["Color"].links))
|
|
454
|
+
img = tex.image
|
|
455
|
+
W_, H_ = img.size
|
|
456
|
+
uv = me.uv_layers.active.data
|
|
457
|
+
# a free 8x8 texel cell: no triangle's UV box touches it or its neighbours
|
|
458
|
+
cell = 8
|
|
459
|
+
used = np.zeros((H_ // cell + 2, W_ // cell + 2), bool)
|
|
460
|
+
for poly in me.polygons:
|
|
461
|
+
us = [uv[li].uv for li in poly.loop_indices]
|
|
462
|
+
cx0, cx1 = int(min(u.x for u in us) * W_) // cell, int(max(u.x for u in us) * W_) // cell
|
|
463
|
+
cy0, cy1 = int(min(u.y for u in us) * H_) // cell, int(max(u.y for u in us) * H_) // cell
|
|
464
|
+
used[max(0, cy0 - 1):cy1 + 2, max(0, cx0 - 1):cx1 + 2] = True
|
|
465
|
+
free = np.argwhere(~used[1:-1, 1:-1])
|
|
466
|
+
if len(free) == 0:
|
|
467
|
+
raise RuntimeError("no free texel cell for the helm's dark lining")
|
|
468
|
+
fy, fx = free[len(free) // 2]
|
|
469
|
+
px = np.empty(W_ * H_ * 4, np.float32)
|
|
470
|
+
img.pixels.foreach_get(px)
|
|
471
|
+
px = px.reshape(H_, W_, 4)
|
|
472
|
+
px[fy * cell:(fy + 1) * cell, fx * cell:(fx + 1) * cell, :3] = 0.035
|
|
473
|
+
img.pixels.foreach_set(px.ravel())
|
|
474
|
+
img.pack()
|
|
475
|
+
dark = Vector(((fx + 0.5) * cell / W_, (fy + 0.5) * cell / H_))
|
|
476
|
+
|
|
477
|
+
band = [v.co for v in me.vertices if z0 + 0.04 < v.co.z < z1 - 0.06]
|
|
478
|
+
xs, ys = [p.x for p in band], [p.y for p in band]
|
|
479
|
+
cx, cy = (min(xs) + max(xs)) / 2, (min(ys) + max(ys)) / 2
|
|
480
|
+
rx, ry = (max(xs) - min(xs)) / 2, (max(ys) - min(ys)) / 2
|
|
481
|
+
# Inner lining: a helm face whose outward (away from the head's axis) ray runs into another wall. The normals
|
|
482
|
+
# cannot tell (TRELLIS shells come back with mixed winding and render double-sided).
|
|
483
|
+
helm_bvh = BVHTree.FromPolygons([v.co for v in me.vertices], [p.vertices for p in me.polygons])
|
|
484
|
+
lined = 0
|
|
485
|
+
for poly in me.polygons:
|
|
486
|
+
c = poly.center
|
|
487
|
+
if not (z0 < c.z < z1 and abs(c.x - cx) < rx * 1.05 and abs(c.y - cy) < ry * 1.05):
|
|
488
|
+
continue
|
|
489
|
+
out = Vector((c.x - cx, c.y - cy, 0.0))
|
|
490
|
+
if out.length < 1e-6:
|
|
491
|
+
continue
|
|
492
|
+
out.normalize()
|
|
493
|
+
hit = helm_bvh.ray_cast(c + out * 0.002, out, 0.5)[0]
|
|
494
|
+
up = helm_bvh.ray_cast(c + Vector((0, 0, 0.002)), Vector((0, 0, 1)), 0.5)[0] if c.z > z1 - 0.12 else True
|
|
495
|
+
# the wall it meets must be the helm's own (a face on the rim looking out at a pauldron is outside, E289)
|
|
496
|
+
own = hit is not None and abs(hit.x - cx) < rx * 1.08 and abs(hit.y - cy) < ry * 1.08 and z0 + 0.02 < hit.z
|
|
497
|
+
if own and up is not None and c.z > z0 + 0.03:
|
|
498
|
+
for li in poly.loop_indices:
|
|
499
|
+
uv[li].uv = dark
|
|
500
|
+
lined += 1
|
|
501
|
+
|
|
502
|
+
# the plug: a tube that hugs the helm's inside. Per ring height and per angle, a ray from the head's axis finds
|
|
503
|
+
# the wall; the plug vertex sits 1.8 cm short of the nearest wall at that angle and the rings either side. Rays that leave through the slit or a breath take the
|
|
504
|
+
# neighbouring angles' distance, so the plug fills the slit's back without poking out of it.
|
|
505
|
+
N = 32
|
|
506
|
+
ring_z = [z0 + 0.03 + (z1 - 0.07 - z0 - 0.03) * k / 9 for k in range(10)]
|
|
507
|
+
dist, opens = [], []
|
|
508
|
+
for z in ring_z:
|
|
509
|
+
ts = []
|
|
510
|
+
for k in range(N):
|
|
511
|
+
a_ = 2 * math.pi * k / N
|
|
512
|
+
d = Vector((math.cos(a_), math.sin(a_), 0.0))
|
|
513
|
+
hit = helm_bvh.ray_cast(Vector((cx, cy, z)) + d * 0.005, d, 0.6)
|
|
514
|
+
ts.append(hit[3] + 0.005 if hit[0] is not None and hit[3] > 0.02 else None)
|
|
515
|
+
open_ = [t is None for t in ts]
|
|
516
|
+
for _ in range(N): # fill the escapes (and the hits on the old core) from the neighbours
|
|
517
|
+
for k in range(N):
|
|
518
|
+
if ts[k] is None:
|
|
519
|
+
nb = [t for t in (ts[k - 1], ts[(k + 1) % N]) if t is not None]
|
|
520
|
+
if nb:
|
|
521
|
+
ts[k] = max(nb)
|
|
522
|
+
dist.append([t if t is not None else 0.05 for t in ts])
|
|
523
|
+
opens.append(open_)
|
|
524
|
+
rings = []
|
|
525
|
+
for r, z in enumerate(ring_z): # the nearest wall over this ring and its neighbours: the tube never cuts a recess
|
|
526
|
+
rings.append([])
|
|
527
|
+
for k in range(N):
|
|
528
|
+
if opens[r][k]: # behind the slit / a breath: reach into it (shadow fills the opening)
|
|
529
|
+
t = dist[r][k]
|
|
530
|
+
else:
|
|
531
|
+
t = min(dist[rr][kk] for rr in (r - 1, r, r + 1) if 0 <= rr < len(dist) for kk in (k - 1, k, (k + 1) % N)
|
|
532
|
+
if not opens[rr][kk])
|
|
533
|
+
a_ = 2 * math.pi * k / N
|
|
534
|
+
rings[-1].append(Vector((cx + math.cos(a_) * max(0.01, t - 0.018), cy + math.sin(a_) * max(0.01, t - 0.018), z)))
|
|
535
|
+
bm_ = bmesh.new()
|
|
536
|
+
bm_.from_mesh(me)
|
|
537
|
+
uvl = bm_.loops.layers.uv.active
|
|
538
|
+
vr = [[bm_.verts.new(p_) for p_ in ring] for ring in rings]
|
|
539
|
+
faces = []
|
|
540
|
+
for r0, r1 in zip(vr, vr[1:]):
|
|
541
|
+
for k in range(N):
|
|
542
|
+
faces.append(bm_.faces.new((r0[k], r0[(k + 1) % N], r1[(k + 1) % N], r1[k])))
|
|
543
|
+
faces.append(bm_.faces.new(list(reversed(vr[0]))))
|
|
544
|
+
faces.append(bm_.faces.new(vr[-1]))
|
|
545
|
+
for f in faces:
|
|
546
|
+
f.smooth = True
|
|
547
|
+
for loop in f.loops:
|
|
548
|
+
loop[uvl].uv = dark
|
|
549
|
+
faces = set(faces)
|
|
550
|
+
bmesh.ops.triangulate(bm_, faces=list(faces))
|
|
551
|
+
bm_.to_mesh(me)
|
|
552
|
+
bm_.free()
|
|
553
|
+
me.update()
|
|
554
|
+
return lined, len(faces)
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
if J.get("helm"):
|
|
558
|
+
report["helm_lined_faces"], report["helm_plug_faces"] = close_helm(*J["helm"])
|
|
559
|
+
verts = [v.co.copy() for v in me.vertices]
|
|
560
|
+
report["tris"] = sum(len(p.vertices) - 2 for p in me.polygons)
|
|
561
|
+
|
|
562
|
+
arm_data = bpy.data.armatures.new("TrainingDummyRig")
|
|
563
|
+
arm = bpy.data.objects.new("TrainingDummyRig", arm_data)
|
|
564
|
+
bpy.context.collection.objects.link(arm)
|
|
565
|
+
bpy.context.view_layer.objects.active = arm
|
|
566
|
+
for o in bpy.context.scene.objects:
|
|
567
|
+
o.select_set(o is arm)
|
|
568
|
+
bpy.ops.object.mode_set(mode="EDIT")
|
|
569
|
+
FRONT = Vector((0, -1, 0))
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
def bone(name, head, tail, parent=None, connect=False, roll_to=FRONT):
|
|
573
|
+
b = arm_data.edit_bones.new(name)
|
|
574
|
+
b.head, b.tail = head, tail
|
|
575
|
+
b.align_roll(roll_to) if roll_to is not None else None
|
|
576
|
+
if parent:
|
|
577
|
+
b.parent = arm_data.edit_bones[parent]
|
|
578
|
+
b.use_connect = connect
|
|
579
|
+
return b
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
# The spine chain: roll so the bone's Z axis is the figure's front (-Y) and X its left (+X).
|
|
583
|
+
yc = depth(0.0, J["chest"], 0.08)
|
|
584
|
+
bone("Root", Vector((0, 0, 0)), Vector((0, 0, J["base_top"])))
|
|
585
|
+
bone("Pelvis", Vector((0, depth(0, J["pelvis"], 0.1), J["pelvis"])), Vector((0, depth(0, J["spine"], 0.1), J["spine"])), "Root")
|
|
586
|
+
bone("Spine", arm_data.edit_bones["Pelvis"].tail.copy(), Vector((0, yc, J["chest"])), "Pelvis", True)
|
|
587
|
+
bone("Chest", arm_data.edit_bones["Spine"].tail.copy(), Vector((0, depth(0, J["neck"], 0.05), J["neck"])), "Spine", True)
|
|
588
|
+
bone("Neck", arm_data.edit_bones["Chest"].tail.copy(), Vector((0, depth(0, J["head"], 0.06), J["head"])), "Chest", True)
|
|
589
|
+
bone("Head", arm_data.edit_bones["Neck"].tail.copy(), Vector((0, depth(0, J["head"], 0.06), J["crown"])), "Neck", True)
|
|
590
|
+
for side, sx in (("Left", 1.0), ("Right", -1.0)):
|
|
591
|
+
def M(key):
|
|
592
|
+
x, z = J[key]
|
|
593
|
+
return P(sx * x, z)
|
|
594
|
+
clav = Vector((sx * J["clavicle"][0], yc, J["clavicle"][1]))
|
|
595
|
+
bone(f"{side}Shoulder", clav, M("shoulder"), "Chest")
|
|
596
|
+
bone(f"{side}UpperArm", M("shoulder"), M("elbow"), f"{side}Shoulder", True)
|
|
597
|
+
bone(f"{side}ForeArm", M("elbow"), M("wrist"), f"{side}UpperArm", True)
|
|
598
|
+
bone(f"{side}Hand", M("wrist"), M("fist"), f"{side}ForeArm", True)
|
|
599
|
+
bone(f"{side}Thigh", M("hip"), M("knee"), "Root")
|
|
600
|
+
bone(f"{side}Shin", M("knee"), M("ankle"), f"{side}Thigh", True)
|
|
601
|
+
bpy.ops.object.mode_set(mode="OBJECT")
|
|
602
|
+
NAMES = [b.name for b in arm_data.bones]
|
|
603
|
+
report["bones"] = NAMES
|
|
604
|
+
|
|
605
|
+
# ---------------------------------------------------------------- weights
|
|
606
|
+
# Geodesic voxel binding (Dionne & de Lasa 2013, the img2-character skill's rig_geodesic_skinning, in numpy):
|
|
607
|
+
# Blender's bone heat fails outright on these surfaces (thin cloth, culled inner walls). Voxelise the figure at
|
|
608
|
+
# VOXEL m, flood the outside in from the grid border, call everything else solid, and measure each bone's distance
|
|
609
|
+
# THROUGH the solid. A fist near the skirt is then far from the pelvis (the path runs up the arm), so nothing leaks
|
|
610
|
+
# across an air gap. Weight = exp(-(d - d_nearest) / SIGMA) over the four nearest bones: a vertex belongs to its
|
|
611
|
+
# nearest bone and blends only within a few centimetres of a joint.
|
|
612
|
+
import numpy as np # noqa: E402
|
|
613
|
+
|
|
614
|
+
VOXEL, SIGMA, ITER = 0.02, 0.035, 140
|
|
615
|
+
for o in bpy.context.scene.objects:
|
|
616
|
+
o.select_set(o in (mesh, arm))
|
|
617
|
+
bpy.context.view_layer.objects.active = arm
|
|
618
|
+
bpy.ops.object.parent_set(type="ARMATURE_NAME") # the Skin modifier + one empty group per bone
|
|
619
|
+
me.calc_loop_triangles()
|
|
620
|
+
V = np.empty(len(me.vertices) * 3, np.float64)
|
|
621
|
+
me.vertices.foreach_get("co", V)
|
|
622
|
+
V = V.reshape(-1, 3)
|
|
623
|
+
T = np.empty(len(me.loop_triangles) * 3, np.int64)
|
|
624
|
+
me.loop_triangles.foreach_get("vertices", T)
|
|
625
|
+
T = T.reshape(-1, 3)
|
|
626
|
+
bary = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [1 / 3, 1 / 3, 1 / 3], [.5, .5, 0], [0, .5, .5], [.5, 0, .5],
|
|
627
|
+
[2 / 3, 1 / 6, 1 / 6], [1 / 6, 2 / 3, 1 / 6], [1 / 6, 1 / 6, 2 / 3]])
|
|
628
|
+
S = np.einsum("kj,tjd->tkd", bary, V[T]).reshape(-1, 3)
|
|
629
|
+
lo = V.min(0) - 3 * VOXEL
|
|
630
|
+
shape = tuple(int(n) for n in np.ceil((V.max(0) + 3 * VOXEL - lo) / VOXEL))
|
|
631
|
+
surf = np.zeros(shape, bool)
|
|
632
|
+
ix = np.floor((S - lo) / VOXEL).astype(int)
|
|
633
|
+
surf[ix[:, 0], ix[:, 1], ix[:, 2]] = True
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
def shifted_or(a):
|
|
637
|
+
out = a.copy()
|
|
638
|
+
out[1:] |= a[:-1]; out[:-1] |= a[1:]
|
|
639
|
+
out[:, 1:] |= a[:, :-1]; out[:, :-1] |= a[:, 1:]
|
|
640
|
+
out[:, :, 1:] |= a[:, :, :-1]; out[:, :, :-1] |= a[:, :, 1:]
|
|
641
|
+
return out
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
ext = np.zeros(shape, bool)
|
|
645
|
+
ext[0], ext[-1], ext[:, 0], ext[:, -1], ext[:, :, 0], ext[:, :, -1] = True, True, True, True, True, True
|
|
646
|
+
ext &= ~surf
|
|
647
|
+
while True:
|
|
648
|
+
grown = shifted_or(ext) & ~surf
|
|
649
|
+
if grown.sum() == ext.sum():
|
|
650
|
+
break
|
|
651
|
+
ext = grown
|
|
652
|
+
solid = ~ext
|
|
653
|
+
bone_list = [b for b in arm_data.bones]
|
|
654
|
+
B = len(bone_list)
|
|
655
|
+
D = np.full((B,) + shape, np.inf, np.float32)
|
|
656
|
+
for k, b in enumerate(bone_list):
|
|
657
|
+
h, t = np.array(b.head_local), np.array(b.tail_local)
|
|
658
|
+
n = max(2, int(np.linalg.norm(t - h) / (VOXEL / 3)))
|
|
659
|
+
pts = h + (t - h) * np.linspace(0, 1, n)[:, None]
|
|
660
|
+
bi = np.clip(np.floor((pts - lo) / VOXEL).astype(int), 0, np.array(shape) - 1)
|
|
661
|
+
solid[bi[:, 0], bi[:, 1], bi[:, 2]] = True # the bone itself is solid, so a hollow limb still conducts
|
|
662
|
+
D[k, bi[:, 0], bi[:, 1], bi[:, 2]] = 0.0
|
|
663
|
+
# The torso is wide and the arms hang close to it: measured from the spine's centre line, the side of a
|
|
664
|
+
# breastplate is nearer the elbow (through the few centimetres where arm and torso touch) than the spine, and an
|
|
665
|
+
# arm swing drags the tassets along. So the spine chain seeds the whole torso core: every solid voxel within
|
|
666
|
+
# TORSO_HALF of the midline, from the skirt hem up to the neck, belongs to Pelvis / Spine / Chest by height.
|
|
667
|
+
TORSO_HALF = 0.20
|
|
668
|
+
gx = lo[0] + (np.arange(shape[0]) + 0.5) * VOXEL
|
|
669
|
+
gz = lo[2] + (np.arange(shape[2]) + 0.5) * VOXEL
|
|
670
|
+
core_x = np.abs(gx) < TORSO_HALF
|
|
671
|
+
for k, b in enumerate(bone_list):
|
|
672
|
+
if b.name not in ("Pelvis", "Spine", "Chest"):
|
|
673
|
+
continue
|
|
674
|
+
z0 = J["hem"] if b.name == "Pelvis" else b.head_local.z
|
|
675
|
+
band_z = (gz >= z0) & (gz < b.tail_local.z)
|
|
676
|
+
core = solid & core_x[:, None, None] & band_z[None, None, :]
|
|
677
|
+
D[k][core] = 0.0
|
|
678
|
+
blocked = ~solid
|
|
679
|
+
offsets = [(dx, dy, dz, math.sqrt(dx * dx + dy * dy + dz * dz)) for dx in (-1, 0, 1) for dy in (-1, 0, 1)
|
|
680
|
+
for dz in (-1, 0, 1) if (dx, dy, dz) != (0, 0, 0)]
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
def sl(d, n):
|
|
684
|
+
return (slice(d, n), slice(0, n - d)) if d > 0 else ((slice(0, n + d), slice(-d, n)) if d < 0 else (slice(0, n), slice(0, n)))
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
for it in range(ITER):
|
|
688
|
+
prev = D.copy() if it % 10 == 9 else None
|
|
689
|
+
for dx, dy, dz, c in offsets:
|
|
690
|
+
(xd, xs), (yd, ys), (zd, zs) = sl(dx, shape[0]), sl(dy, shape[1]), sl(dz, shape[2])
|
|
691
|
+
np.minimum(D[:, xd, yd, zd], D[:, xs, ys, zs] + c, out=D[:, xd, yd, zd])
|
|
692
|
+
D[:, blocked] = np.inf
|
|
693
|
+
if prev is not None and np.array_equal(np.isfinite(prev), np.isfinite(D)) and np.allclose(prev[np.isfinite(prev)], D[np.isfinite(D)]):
|
|
694
|
+
break
|
|
695
|
+
report["geodesic_iterations"] = it + 1
|
|
696
|
+
report["voxels"] = [int(n) for n in shape]
|
|
697
|
+
vi = np.clip(np.floor((V - lo) / VOXEL).astype(int), 0, np.array(shape) - 1)
|
|
698
|
+
Dv = D[:, vi[:, 0], vi[:, 1], vi[:, 2]].T * VOXEL # metres, (verts, bones)
|
|
699
|
+
bad = ~np.isfinite(Dv).any(1)
|
|
700
|
+
report["geodesic_unreached"] = int(bad.sum())
|
|
701
|
+
Dv[~np.isfinite(Dv)] = 1e3
|
|
702
|
+
Wv = np.exp(-(Dv - Dv.min(1, keepdims=True)) / SIGMA)
|
|
703
|
+
names_by_k = [b.name for b in bone_list]
|
|
704
|
+
W = [] # per-vertex {bone: weight}
|
|
705
|
+
for i in range(len(V)):
|
|
706
|
+
row = Wv[i]
|
|
707
|
+
top = np.argsort(-row)[:4]
|
|
708
|
+
W.append({names_by_k[k]: float(row[k]) for k in top})
|
|
709
|
+
del D
|
|
710
|
+
vg = {g.name: g for g in mesh.vertex_groups}
|
|
711
|
+
|
|
712
|
+
bones = {b.name: (arm.matrix_world @ b.head_local, arm.matrix_world @ b.tail_local) for b in arm_data.bones}
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
def seg_dist(p, a, b):
|
|
716
|
+
ab = b - a
|
|
717
|
+
t = max(0.0, min(1.0, (p - a).dot(ab) / ab.length_squared))
|
|
718
|
+
return (a + ab * t - p).length
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
def smoothstep(e0, e1, x):
|
|
722
|
+
t = max(0.0, min(1.0, (x - e0) / (e1 - e0)))
|
|
723
|
+
return t * t * (3 - 2 * t)
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
hip_z = J["hip"][1]
|
|
727
|
+
for i, p in enumerate(verts):
|
|
728
|
+
w = W[i]
|
|
729
|
+
x, y, z = p
|
|
730
|
+
side = "Left" if x >= 0 else "Right"
|
|
731
|
+
other = "Right" if side == "Left" else "Left"
|
|
732
|
+
# Unweighted by heat: nearest bone.
|
|
733
|
+
if not w:
|
|
734
|
+
best = min(NAMES, key=lambda n: seg_dist(p, *bones[n]))
|
|
735
|
+
w = {best: 1.0}
|
|
736
|
+
# The base and the post: rigid on Root.
|
|
737
|
+
on_post = abs(x) < J["post_r"] and z < J["pelvis"] - 0.05 and abs(y - depth(0, z, 0.1)) < J["post_r"] * 1.5
|
|
738
|
+
feet = z < J["ankle"][1] + 0.04 and abs(abs(x) - J["ankle"][0]) < 0.2
|
|
739
|
+
if z < J["base_top"] or on_post or feet or i in BASE_IDX:
|
|
740
|
+
w = {"Root": 1.0}
|
|
741
|
+
else:
|
|
742
|
+
# Nothing crosses the midline: the other side's limbs never pull this vertex.
|
|
743
|
+
w = {n: v for n, v in w.items() if not n.startswith(other)}
|
|
744
|
+
# The legs hang from Root: above the hem (the skirt, the waist) they have no say, Pelvis does.
|
|
745
|
+
if z >= J["hem"]:
|
|
746
|
+
moved = sum(v for n, v in w.items() if n.endswith(("Thigh", "Shin")))
|
|
747
|
+
if moved:
|
|
748
|
+
w = {n: v for n, v in w.items() if not n.endswith(("Thigh", "Shin"))}
|
|
749
|
+
w["Pelvis"] = w.get("Pelvis", 0) + moved
|
|
750
|
+
# The torso is armour and stuffing, not flesh: it bends in horizontal bands. Whatever share the spine chain
|
|
751
|
+
# holds is re-split by height alone, 8 cm blends at each joint (the geodesic split of a hollow breastplate
|
|
752
|
+
# is blotchy, and let the neck claim the middle of the chest).
|
|
753
|
+
chain = ("Pelvis", "Spine", "Chest", "Neck", "Head")
|
|
754
|
+
share = sum(w.get(n, 0.0) for n in chain)
|
|
755
|
+
if share > 0:
|
|
756
|
+
cuts = (J["spine"], J["chest"], J["neck"], J["head"])
|
|
757
|
+
band = [1.0, 0.0, 0.0, 0.0, 0.0]
|
|
758
|
+
for k, c in enumerate(cuts):
|
|
759
|
+
t = smoothstep(c - 0.04, c + 0.04, z)
|
|
760
|
+
band[k + 1] = band[k] * t
|
|
761
|
+
band[k] *= 1 - t
|
|
762
|
+
w = {n: v for n, v in w.items() if n not in chain}
|
|
763
|
+
for n, b in zip(chain, band):
|
|
764
|
+
if b > 1e-4:
|
|
765
|
+
w[n] = w.get(n, 0.0) + share * b
|
|
766
|
+
# The collar bone moves the shoulder, not the breastplate: fade it out towards the midline.
|
|
767
|
+
sh = f"{side}Shoulder"
|
|
768
|
+
if sh in w:
|
|
769
|
+
f = smoothstep(0.10, 0.20, abs(x))
|
|
770
|
+
if f < 1:
|
|
771
|
+
w["Chest"] = w.get("Chest", 0) + w[sh] * (1 - f)
|
|
772
|
+
w[sh] *= f
|
|
773
|
+
# Below the skirt hem: only this side's leg bones and Root; the top of the leg blends into Pelvis over 12 cm
|
|
774
|
+
# under the hem, so a pelvis sway bends the hip instead of tearing the skirt off the legs.
|
|
775
|
+
hem = J["hem"]
|
|
776
|
+
if z < hem and abs(abs(x) - J["hip"][0]) < 0.16:
|
|
777
|
+
keep = {f"{side}Thigh", f"{side}Shin", "Root"}
|
|
778
|
+
leg = {n: v for n, v in w.items() if n in keep} or {f"{side}Thigh": 1.0}
|
|
779
|
+
pel = smoothstep(hem - 0.12, hem, z)
|
|
780
|
+
tot = sum(leg.values())
|
|
781
|
+
w = {n: v / tot * (1 - pel) for n, v in leg.items()}
|
|
782
|
+
if pel > 0:
|
|
783
|
+
w["Pelvis"] = pel
|
|
784
|
+
# The fist is rigid on the hand; the wrist blends over 6 cm.
|
|
785
|
+
wx, wz = J["wrist"]
|
|
786
|
+
fist_dir = (Vector((J["fist"][0], 0, J["fist"][1])) - Vector((wx, 0, wz))).normalized()
|
|
787
|
+
along = (Vector((abs(x), 0, z)) - Vector((wx, 0, wz))).dot(fist_dir)
|
|
788
|
+
arm_share = sum(v for n, v in w.items() if n.startswith(side) and n.endswith(("Arm", "Hand")))
|
|
789
|
+
near_fist = seg_dist(Vector((abs(x), 0, z)), Vector((wx, 0, wz)), Vector((J["fist"][0], 0, J["fist"][1]))) < 0.10
|
|
790
|
+
if arm_share > 0.5 and along > -0.06 and near_fist:
|
|
791
|
+
h = smoothstep(-0.06, 0.0, along)
|
|
792
|
+
rest = {n: v for n, v in w.items() if n != f"{side}Hand"}
|
|
793
|
+
tot = sum(rest.values()) or 1.0
|
|
794
|
+
w = {n: v / tot * (1 - h) for n, v in rest.items()}
|
|
795
|
+
w[f"{side}Hand"] = w.get(f"{side}Hand", 0) + h
|
|
796
|
+
# Four influences, normalised.
|
|
797
|
+
top = sorted(w.items(), key=lambda kv: -kv[1])[:4]
|
|
798
|
+
tot = sum(v for _, v in top)
|
|
799
|
+
W[i] = {n: v / tot for n, v in top if v / tot > 0.01}
|
|
800
|
+
|
|
801
|
+
for g in mesh.vertex_groups:
|
|
802
|
+
g.remove(list(range(len(me.vertices))))
|
|
803
|
+
for i, w in enumerate(W):
|
|
804
|
+
tot = sum(w.values())
|
|
805
|
+
for n, v in w.items():
|
|
806
|
+
vg[n].add([i], v / tot, "REPLACE")
|
|
807
|
+
|
|
808
|
+
counts = {n: 0 for n in NAMES}
|
|
809
|
+
for w in W:
|
|
810
|
+
for n in w:
|
|
811
|
+
counts[n] += 1
|
|
812
|
+
report["verts_per_bone"] = counts
|
|
813
|
+
report["max_influences"] = max(len(w) for w in W)
|
|
814
|
+
|
|
815
|
+
next(m for m in mesh.modifiers if m.type == "ARMATURE").name = "Skin"
|
|
816
|
+
for d in me.uv_layers.active.data: # pack_dummy.mjs quantizes UVs to 16 bits: they must sit inside [0, 1]
|
|
817
|
+
d.uv = (min(1.0, max(0.0, d.uv.x)), min(1.0, max(0.0, d.uv.y)))
|
|
818
|
+
arm.data.display_type = "STICK"
|
|
819
|
+
os.makedirs(os.path.dirname(os.path.abspath(target)), exist_ok=True)
|
|
820
|
+
if target.endswith(".blend"):
|
|
821
|
+
bpy.ops.wm.save_as_mainfile(filepath=target)
|
|
822
|
+
else:
|
|
823
|
+
bpy.ops.export_scene.gltf(filepath=target, export_format="GLB", export_yup=True, export_animations=False,
|
|
824
|
+
export_skins=True, export_def_bones=False, export_apply=False)
|
|
825
|
+
report["out"] = target
|
|
826
|
+
print("REPORT", json.dumps(report))
|
|
827
|
+
if REPORT:
|
|
828
|
+
json.dump(report, open(REPORT, "w"), indent=1)
|