@clockgrove/assetgrove 0.0.0-stage → 0.3.2
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/LICENSE +21 -0
- package/README.md +277 -2
- package/dist/animation/commands.d.ts +180 -0
- package/dist/animation/commands.js +515 -0
- package/dist/animation/facing.d.ts +44 -0
- package/dist/animation/facing.js +100 -0
- package/dist/animation/fix.d.ts +136 -0
- package/dist/animation/fix.js +529 -0
- package/dist/animation/flicker.d.ts +44 -0
- package/dist/animation/flicker.js +117 -0
- package/dist/animation/halo.d.ts +72 -0
- package/dist/animation/halo.js +253 -0
- package/dist/animation/holes.d.ts +122 -0
- package/dist/animation/holes.js +262 -0
- package/dist/animation/preview.d.ts +38 -0
- package/dist/animation/preview.js +161 -0
- package/dist/animation/qa.d.ts +57 -0
- package/dist/animation/qa.js +418 -0
- package/dist/animation/run.d.ts +109 -0
- package/dist/animation/run.js +182 -0
- package/dist/animation/strip.d.ts +13 -0
- package/dist/animation/strip.js +41 -0
- package/dist/animation/template-choice.d.ts +75 -0
- package/dist/animation/template-choice.js +153 -0
- package/dist/animation/templates.d.ts +39 -0
- package/dist/animation/templates.js +333 -0
- package/dist/animation/types.d.ts +257 -0
- package/dist/animation/types.js +1 -0
- package/dist/approvals.d.ts +156 -0
- package/dist/approvals.js +369 -0
- package/dist/audio/aac.d.ts +61 -0
- package/dist/audio/aac.js +152 -0
- package/dist/audio/checks.d.ts +38 -0
- package/dist/audio/checks.js +254 -0
- package/dist/audio/delivery.d.ts +52 -0
- package/dist/audio/delivery.js +105 -0
- package/dist/audio/engine.d.ts +65 -0
- package/dist/audio/engine.js +164 -0
- package/dist/audio/handoff.d.ts +75 -0
- package/dist/audio/handoff.js +185 -0
- package/dist/audio/kinds.d.ts +6 -0
- package/dist/audio/kinds.js +315 -0
- package/dist/audio/loudness.d.ts +22 -0
- package/dist/audio/loudness.js +72 -0
- package/dist/audio/ogg.d.ts +27 -0
- package/dist/audio/ogg.js +65 -0
- package/dist/audio/operations.d.ts +20 -0
- package/dist/audio/operations.js +335 -0
- package/dist/audio/opus.d.ts +40 -0
- package/dist/audio/opus.js +108 -0
- package/dist/audio/profile.d.ts +200 -0
- package/dist/audio/profile.js +126 -0
- package/dist/audio/run.d.ts +83 -0
- package/dist/audio/run.js +192 -0
- package/dist/audio/vorbis-comments.d.ts +25 -0
- package/dist/audio/vorbis-comments.js +243 -0
- package/dist/audio/waveform.d.ts +13 -0
- package/dist/audio/waveform.js +52 -0
- package/dist/audio-parameters.d.ts +17 -0
- package/dist/audio-parameters.js +45 -0
- package/dist/audit/bar.d.ts +65 -0
- package/dist/audit/bar.js +97 -0
- package/dist/audit/members.d.ts +40 -0
- package/dist/audit/members.js +119 -0
- package/dist/bible-view.d.ts +10 -0
- package/dist/bible-view.js +122 -0
- package/dist/bible.d.ts +272 -0
- package/dist/bible.js +641 -0
- package/dist/budget.d.ts +119 -0
- package/dist/budget.js +227 -0
- package/dist/call-parameters.d.ts +71 -0
- package/dist/call-parameters.js +90 -0
- package/dist/calls.d.ts +145 -0
- package/dist/calls.js +788 -0
- package/dist/cli/main.d.ts +22 -0
- package/dist/cli/main.js +137 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +5 -0
- package/dist/commands/animation-qa.d.ts +1 -0
- package/dist/commands/animation-qa.js +240 -0
- package/dist/commands/apply.d.ts +12 -0
- package/dist/commands/apply.js +181 -0
- package/dist/commands/audit.d.ts +92 -0
- package/dist/commands/audit.js +555 -0
- package/dist/commands/bible.d.ts +1 -0
- package/dist/commands/bible.js +39 -0
- package/dist/commands/browse.d.ts +12 -0
- package/dist/commands/browse.js +113 -0
- package/dist/commands/card.d.ts +3 -0
- package/dist/commands/card.js +445 -0
- package/dist/commands/compare.d.ts +1 -0
- package/dist/commands/compare.js +90 -0
- package/dist/commands/confirm.d.ts +1 -0
- package/dist/commands/confirm.js +267 -0
- package/dist/commands/context.d.ts +43 -0
- package/dist/commands/context.js +115 -0
- package/dist/commands/deliver.d.ts +1 -0
- package/dist/commands/deliver.js +99 -0
- package/dist/commands/disclosure.d.ts +1 -0
- package/dist/commands/disclosure.js +80 -0
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/doctor.js +112 -0
- package/dist/commands/estimate.d.ts +2 -0
- package/dist/commands/estimate.js +80 -0
- package/dist/commands/extensions.d.ts +2 -0
- package/dist/commands/extensions.js +70 -0
- package/dist/commands/fix-frame.d.ts +1 -0
- package/dist/commands/fix-frame.js +206 -0
- package/dist/commands/generate-sheet.d.ts +1 -0
- package/dist/commands/generate-sheet.js +245 -0
- package/dist/commands/identity-check.d.ts +1 -0
- package/dist/commands/identity-check.js +110 -0
- package/dist/commands/identity-eval.d.ts +1 -0
- package/dist/commands/identity-eval.js +197 -0
- package/dist/commands/import.d.ts +7 -0
- package/dist/commands/import.js +472 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +117 -0
- package/dist/commands/intake.d.ts +1 -0
- package/dist/commands/intake.js +56 -0
- package/dist/commands/labels.d.ts +1 -0
- package/dist/commands/labels.js +101 -0
- package/dist/commands/library.d.ts +9 -0
- package/dist/commands/library.js +711 -0
- package/dist/commands/lod.d.ts +1 -0
- package/dist/commands/lod.js +93 -0
- package/dist/commands/look-dev.d.ts +1 -0
- package/dist/commands/look-dev.js +148 -0
- package/dist/commands/materials.d.ts +1 -0
- package/dist/commands/materials.js +223 -0
- package/dist/commands/mcp.d.ts +1 -0
- package/dist/commands/mcp.js +53 -0
- package/dist/commands/migrate.d.ts +1 -0
- package/dist/commands/migrate.js +123 -0
- package/dist/commands/op.d.ts +5 -0
- package/dist/commands/op.js +114 -0
- package/dist/commands/ops.d.ts +1 -0
- package/dist/commands/ops.js +17 -0
- package/dist/commands/pick-batch.d.ts +24 -0
- package/dist/commands/pick-batch.js +343 -0
- package/dist/commands/pick.d.ts +48 -0
- package/dist/commands/pick.js +469 -0
- package/dist/commands/plan.d.ts +3 -0
- package/dist/commands/plan.js +156 -0
- package/dist/commands/recipe.d.ts +1 -0
- package/dist/commands/recipe.js +52 -0
- package/dist/commands/registry.d.ts +5 -0
- package/dist/commands/registry.js +121 -0
- package/dist/commands/render-sprite.d.ts +1 -0
- package/dist/commands/render-sprite.js +67 -0
- package/dist/commands/rendition.d.ts +1 -0
- package/dist/commands/rendition.js +56 -0
- package/dist/commands/request-change.d.ts +2 -0
- package/dist/commands/request-change.js +950 -0
- package/dist/commands/result.d.ts +34 -0
- package/dist/commands/result.js +237 -0
- package/dist/commands/review.d.ts +28 -0
- package/dist/commands/review.js +444 -0
- package/dist/commands/rig.d.ts +1 -0
- package/dist/commands/rig.js +74 -0
- package/dist/commands/runner.d.ts +45 -0
- package/dist/commands/runner.js +297 -0
- package/dist/commands/runs.d.ts +22 -0
- package/dist/commands/runs.js +159 -0
- package/dist/commands/search.d.ts +69 -0
- package/dist/commands/search.js +638 -0
- package/dist/commands/settings.d.ts +2 -0
- package/dist/commands/settings.js +284 -0
- package/dist/commands/spend.d.ts +2 -0
- package/dist/commands/spend.js +159 -0
- package/dist/commands/stage-source.d.ts +1 -0
- package/dist/commands/stage-source.js +58 -0
- package/dist/commands/stage.d.ts +9 -0
- package/dist/commands/stage.js +229 -0
- package/dist/commands/storage.d.ts +3 -0
- package/dist/commands/storage.js +200 -0
- package/dist/commands/turnaround.d.ts +1 -0
- package/dist/commands/turnaround.js +171 -0
- package/dist/commands/types.d.ts +195 -0
- package/dist/commands/types.js +7 -0
- package/dist/commands/vary.d.ts +2 -0
- package/dist/commands/vary.js +222 -0
- package/dist/commands/write-families.d.ts +14 -0
- package/dist/commands/write-families.js +158 -0
- package/dist/compare.d.ts +87 -0
- package/dist/compare.js +306 -0
- package/dist/confirm/delegation.d.ts +30 -0
- package/dist/confirm/delegation.js +31 -0
- package/dist/confirm/index.d.ts +84 -0
- package/dist/confirm/index.js +176 -0
- package/dist/confirm/mcp.d.ts +60 -0
- package/dist/confirm/mcp.js +253 -0
- package/dist/confirm/pending.d.ts +11 -0
- package/dist/confirm/pending.js +40 -0
- package/dist/confirm/prompt.d.ts +65 -0
- package/dist/confirm/prompt.js +68 -0
- package/dist/confirm/records.d.ts +17 -0
- package/dist/confirm/records.js +63 -0
- package/dist/contact.d.ts +80 -0
- package/dist/contact.js +224 -0
- package/dist/credentials.d.ts +170 -0
- package/dist/credentials.js +598 -0
- package/dist/dataflows.d.ts +32 -0
- package/dist/dataflows.js +42 -0
- package/dist/delivery.d.ts +89 -0
- package/dist/delivery.js +355 -0
- package/dist/disclosure.d.ts +84 -0
- package/dist/disclosure.js +397 -0
- package/dist/env.d.ts +90 -0
- package/dist/env.js +236 -0
- package/dist/errors.d.ts +90 -0
- package/dist/errors.js +105 -0
- package/dist/extension/api.d.ts +389 -0
- package/dist/extension/api.js +20 -0
- package/dist/extension/context.d.ts +9 -0
- package/dist/extension/context.js +60 -0
- package/dist/extension/helpers.d.ts +75 -0
- package/dist/extension/helpers.js +107 -0
- package/dist/extension/http.d.ts +32 -0
- package/dist/extension/http.js +104 -0
- package/dist/extension/setup.d.ts +53 -0
- package/dist/extension/setup.js +162 -0
- package/dist/extension/tools.d.ts +97 -0
- package/dist/extension/tools.js +235 -0
- package/dist/extensions/core.d.ts +7 -0
- package/dist/extensions/core.js +18 -0
- package/dist/extensions/errors.d.ts +22 -0
- package/dist/extensions/errors.js +34 -0
- package/dist/extensions/registry.d.ts +119 -0
- package/dist/extensions/registry.js +535 -0
- package/dist/extensions/version.d.ts +9 -0
- package/dist/extensions/version.js +57 -0
- package/dist/formats.d.ts +46 -0
- package/dist/formats.js +81 -0
- package/dist/frames.d.ts +58 -0
- package/dist/frames.js +80 -0
- package/dist/gateway/anthropic.d.ts +22 -0
- package/dist/gateway/anthropic.js +65 -0
- package/dist/gateway/elevenlabs.d.ts +36 -0
- package/dist/gateway/elevenlabs.js +192 -0
- package/dist/gateway/failure.d.ts +29 -0
- package/dist/gateway/failure.js +70 -0
- package/dist/gateway/openai-compatible.d.ts +20 -0
- package/dist/gateway/openai-compatible.js +76 -0
- package/dist/gateway/openai.d.ts +28 -0
- package/dist/gateway/openai.js +101 -0
- package/dist/gateway/provider.d.ts +380 -0
- package/dist/gateway/provider.js +5 -0
- package/dist/gateway/scripted.d.ts +252 -0
- package/dist/gateway/scripted.js +244 -0
- package/dist/gateway/stability.d.ts +38 -0
- package/dist/gateway/stability.js +232 -0
- package/dist/gateway/structured.d.ts +31 -0
- package/dist/gateway/structured.js +83 -0
- package/dist/gateway/tripo.d.ts +48 -0
- package/dist/gateway/tripo.js +374 -0
- package/dist/gateway/vercel.d.ts +52 -0
- package/dist/gateway/vercel.js +298 -0
- package/dist/generators/generator.d.ts +236 -0
- package/dist/generators/generator.js +12 -0
- package/dist/generators/image.d.ts +21 -0
- package/dist/generators/image.js +286 -0
- package/dist/generators/spec-schema.d.ts +29 -0
- package/dist/generators/spec-schema.js +21 -0
- package/dist/git-marker.d.ts +3 -0
- package/dist/git-marker.js +13 -0
- package/dist/gitlfs.d.ts +38 -0
- package/dist/gitlfs.js +171 -0
- package/dist/guard.d.ts +55 -0
- package/dist/guard.js +323 -0
- package/dist/handoff/current-profile.d.ts +48 -0
- package/dist/handoff/current-profile.js +127 -0
- package/dist/handoff/doctor.d.ts +26 -0
- package/dist/handoff/doctor.js +249 -0
- package/dist/handoff/mark-check.d.ts +17 -0
- package/dist/handoff/mark-check.js +66 -0
- package/dist/handoff/presets/aseprite-json.d.ts +5 -0
- package/dist/handoff/presets/aseprite-json.js +45 -0
- package/dist/handoff/presets/atlas-json.d.ts +44 -0
- package/dist/handoff/presets/atlas-json.js +195 -0
- package/dist/handoff/presets/atlas-pack.d.ts +14 -0
- package/dist/handoff/presets/atlas-pack.js +431 -0
- package/dist/handoff/presets/index.d.ts +273 -0
- package/dist/handoff/presets/index.js +58 -0
- package/dist/handoff/presets/manifest.d.ts +2 -0
- package/dist/handoff/presets/manifest.js +49 -0
- package/dist/handoff/usage.d.ts +27 -0
- package/dist/handoff/usage.js +159 -0
- package/dist/handoff.d.ts +345 -0
- package/dist/handoff.js +1221 -0
- package/dist/identity-eval.d.ts +156 -0
- package/dist/identity-eval.js +321 -0
- package/dist/identity.d.ts +293 -0
- package/dist/identity.js +675 -0
- package/dist/image/apply-style.d.ts +4 -0
- package/dist/image/apply-style.js +37 -0
- package/dist/image/digits.d.ts +5 -0
- package/dist/image/digits.js +40 -0
- package/dist/image/ktx2.d.ts +83 -0
- package/dist/image/ktx2.js +196 -0
- package/dist/image/raster.d.ts +23 -0
- package/dist/image/raster.js +77 -0
- package/dist/image/resample.d.ts +10 -0
- package/dist/image/resample.js +82 -0
- package/dist/image/webp.d.ts +17 -0
- package/dist/image/webp.js +323 -0
- package/dist/init.d.ts +132 -0
- package/dist/init.js +425 -0
- package/dist/inputs.d.ts +67 -0
- package/dist/inputs.js +151 -0
- package/dist/json.d.ts +7 -0
- package/dist/json.js +27 -0
- package/dist/keys.d.ts +34 -0
- package/dist/keys.js +198 -0
- package/dist/kind-schemas.d.ts +17 -0
- package/dist/kind-schemas.js +205 -0
- package/dist/library/actions.d.ts +76 -0
- package/dist/library/actions.js +212 -0
- package/dist/library/adopt.d.ts +177 -0
- package/dist/library/adopt.js +624 -0
- package/dist/library/canonical.d.ts +7 -0
- package/dist/library/canonical.js +29 -0
- package/dist/library/card.d.ts +138 -0
- package/dist/library/card.js +532 -0
- package/dist/library/credits.d.ts +70 -0
- package/dist/library/credits.js +222 -0
- package/dist/library/describe.d.ts +48 -0
- package/dist/library/describe.js +199 -0
- package/dist/library/diff.d.ts +26 -0
- package/dist/library/diff.js +208 -0
- package/dist/library/exact.d.ts +15 -0
- package/dist/library/exact.js +47 -0
- package/dist/library/extent.d.ts +56 -0
- package/dist/library/extent.js +205 -0
- package/dist/library/folder.d.ts +85 -0
- package/dist/library/folder.js +291 -0
- package/dist/library/labels.d.ts +29 -0
- package/dist/library/labels.js +112 -0
- package/dist/library/lfs.d.ts +42 -0
- package/dist/library/lfs.js +140 -0
- package/dist/library/maintain.d.ts +100 -0
- package/dist/library/maintain.js +750 -0
- package/dist/library/media-metadata.d.ts +19 -0
- package/dist/library/media-metadata.js +92 -0
- package/dist/library/paths.d.ts +7 -0
- package/dist/library/paths.js +65 -0
- package/dist/library/relations.d.ts +59 -0
- package/dist/library/relations.js +176 -0
- package/dist/library/review.d.ts +204 -0
- package/dist/library/review.js +545 -0
- package/dist/library/stale.d.ts +88 -0
- package/dist/library/stale.js +229 -0
- package/dist/library/suggestions.d.ts +37 -0
- package/dist/library/suggestions.js +146 -0
- package/dist/library/summary.d.ts +65 -0
- package/dist/library/summary.js +138 -0
- package/dist/library/undo.d.ts +18 -0
- package/dist/library/undo.js +141 -0
- package/dist/library/worklist.d.ts +42 -0
- package/dist/library/worklist.js +91 -0
- package/dist/library/write.d.ts +282 -0
- package/dist/library/write.js +790 -0
- package/dist/license.d.ts +67 -0
- package/dist/license.js +205 -0
- package/dist/limits.d.ts +51 -0
- package/dist/limits.js +100 -0
- package/dist/loop.d.ts +244 -0
- package/dist/loop.js +377 -0
- package/dist/material/core.d.ts +70 -0
- package/dist/material/core.js +238 -0
- package/dist/material/engine.d.ts +15 -0
- package/dist/material/engine.js +141 -0
- package/dist/material/flicker.d.ts +26 -0
- package/dist/material/flicker.js +71 -0
- package/dist/material/operations.d.ts +2 -0
- package/dist/material/operations.js +48 -0
- package/dist/material/pipeline.d.ts +51 -0
- package/dist/material/pipeline.js +431 -0
- package/dist/material/profile.d.ts +29 -0
- package/dist/material/profile.js +97 -0
- package/dist/material/rendition.d.ts +5 -0
- package/dist/material/rendition.js +76 -0
- package/dist/mcp.d.ts +72 -0
- package/dist/mcp.js +514 -0
- package/dist/media.d.ts +36 -0
- package/dist/media.js +46 -0
- package/dist/metadata.d.ts +61 -0
- package/dist/metadata.js +748 -0
- package/dist/model-declarations.d.ts +28 -0
- package/dist/model-declarations.js +14 -0
- package/dist/model3d/clip-map.d.ts +49 -0
- package/dist/model3d/clip-map.js +129 -0
- package/dist/model3d/core-checks.d.ts +61 -0
- package/dist/model3d/core-checks.js +278 -0
- package/dist/model3d/facing.d.ts +49 -0
- package/dist/model3d/facing.js +125 -0
- package/dist/model3d/generator.d.ts +19 -0
- package/dist/model3d/generator.js +482 -0
- package/dist/model3d/glb.d.ts +120 -0
- package/dist/model3d/glb.js +155 -0
- package/dist/model3d/handoff.d.ts +37 -0
- package/dist/model3d/handoff.js +131 -0
- package/dist/model3d/lod/chain.d.ts +50 -0
- package/dist/model3d/lod/chain.js +447 -0
- package/dist/model3d/lod/command.d.ts +38 -0
- package/dist/model3d/lod/command.js +377 -0
- package/dist/model3d/lod/qa.d.ts +36 -0
- package/dist/model3d/lod/qa.js +189 -0
- package/dist/model3d/lod/settings.d.ts +36 -0
- package/dist/model3d/lod/settings.js +137 -0
- package/dist/model3d/lod/simplify.d.ts +35 -0
- package/dist/model3d/lod/simplify.js +337 -0
- package/dist/model3d/lod/textures.d.ts +46 -0
- package/dist/model3d/lod/textures.js +190 -0
- package/dist/model3d/lookdev/command.d.ts +219 -0
- package/dist/model3d/lookdev/command.js +1795 -0
- package/dist/model3d/lookdev/edit.d.ts +44 -0
- package/dist/model3d/lookdev/edit.js +241 -0
- package/dist/model3d/lookdev/groom.d.ts +86 -0
- package/dist/model3d/lookdev/groom.js +462 -0
- package/dist/model3d/lookdev/markings.d.ts +98 -0
- package/dist/model3d/lookdev/markings.js +319 -0
- package/dist/model3d/lookdev/project.d.ts +100 -0
- package/dist/model3d/lookdev/project.js +721 -0
- package/dist/model3d/lookdev/settings.d.ts +65 -0
- package/dist/model3d/lookdev/settings.js +103 -0
- package/dist/model3d/lookdev/texels.d.ts +32 -0
- package/dist/model3d/lookdev/texels.js +192 -0
- package/dist/model3d/profile.d.ts +101 -0
- package/dist/model3d/profile.js +132 -0
- package/dist/model3d/prop.d.ts +29 -0
- package/dist/model3d/prop.js +317 -0
- package/dist/model3d/qa.d.ts +27 -0
- package/dist/model3d/qa.js +105 -0
- package/dist/model3d/render.d.ts +172 -0
- package/dist/model3d/render.js +791 -0
- package/dist/model3d/rig/build.d.ts +14 -0
- package/dist/model3d/rig/build.js +210 -0
- package/dist/model3d/rig/candidate.d.ts +50 -0
- package/dist/model3d/rig/candidate.js +132 -0
- package/dist/model3d/rig/command.d.ts +50 -0
- package/dist/model3d/rig/command.js +229 -0
- package/dist/model3d/rig/fit.d.ts +88 -0
- package/dist/model3d/rig/fit.js +568 -0
- package/dist/model3d/rig/gait.d.ts +105 -0
- package/dist/model3d/rig/gait.js +334 -0
- package/dist/model3d/rig/math.d.ts +27 -0
- package/dist/model3d/rig/math.js +92 -0
- package/dist/model3d/rig/motion.d.ts +26 -0
- package/dist/model3d/rig/motion.js +223 -0
- package/dist/model3d/rig/qa.d.ts +76 -0
- package/dist/model3d/rig/qa.js +357 -0
- package/dist/model3d/rig/rig.d.ts +55 -0
- package/dist/model3d/rig/rig.js +213 -0
- package/dist/model3d/rig/template.d.ts +195 -0
- package/dist/model3d/rig/template.js +456 -0
- package/dist/model3d/scene.d.ts +115 -0
- package/dist/model3d/scene.js +684 -0
- package/dist/model3d/views.d.ts +77 -0
- package/dist/model3d/views.js +190 -0
- package/dist/origin.d.ts +162 -0
- package/dist/origin.js +134 -0
- package/dist/paths.d.ts +53 -0
- package/dist/paths.js +240 -0
- package/dist/planning.d.ts +261 -0
- package/dist/planning.js +1470 -0
- package/dist/policy/blocklist.d.ts +28 -0
- package/dist/policy/blocklist.js +58 -0
- package/dist/policy/brief.d.ts +67 -0
- package/dist/policy/brief.js +110 -0
- package/dist/policy/cuts.d.ts +26 -0
- package/dist/policy/cuts.js +80 -0
- package/dist/policy/model.d.ts +69 -0
- package/dist/policy/model.js +202 -0
- package/dist/policy/text.d.ts +183 -0
- package/dist/policy/text.js +285 -0
- package/dist/postprocess.d.ts +68 -0
- package/dist/postprocess.js +302 -0
- package/dist/profile.d.ts +5 -0
- package/dist/profile.js +98 -0
- package/dist/project-rules.d.ts +54 -0
- package/dist/project-rules.js +105 -0
- package/dist/provenance-binding.d.ts +55 -0
- package/dist/provenance-binding.js +352 -0
- package/dist/providers/adapter.d.ts +176 -0
- package/dist/providers/adapter.js +418 -0
- package/dist/providers/index.d.ts +33 -0
- package/dist/providers/index.js +49 -0
- package/dist/providers/script.d.ts +13 -0
- package/dist/providers/script.js +65 -0
- package/dist/providers/set.d.ts +76 -0
- package/dist/providers/set.js +134 -0
- package/dist/pure-cbor.d.ts +1 -0
- package/dist/pure-cbor.js +8 -0
- package/dist/qa/stability.d.ts +215 -0
- package/dist/qa/stability.js +393 -0
- package/dist/qa/stability.json +32 -0
- package/dist/qa.d.ts +36 -0
- package/dist/qa.js +148 -0
- package/dist/reconcile.d.ts +111 -0
- package/dist/reconcile.js +416 -0
- package/dist/redact.d.ts +29 -0
- package/dist/redact.js +74 -0
- package/dist/regions.d.ts +49 -0
- package/dist/regions.js +113 -0
- package/dist/release-policy.d.ts +99 -0
- package/dist/release-policy.js +266 -0
- package/dist/request.d.ts +74 -0
- package/dist/request.js +249 -0
- package/dist/routes.d.ts +327 -0
- package/dist/routes.js +1166 -0
- package/dist/runs/dir.d.ts +33 -0
- package/dist/runs/dir.js +30 -0
- package/dist/runs/execute.d.ts +86 -0
- package/dist/runs/execute.js +422 -0
- package/dist/runs/journal.d.ts +150 -0
- package/dist/runs/journal.js +216 -0
- package/dist/runs/lock.d.ts +57 -0
- package/dist/runs/lock.js +322 -0
- package/dist/runs/plan.d.ts +261 -0
- package/dist/runs/plan.js +404 -0
- package/dist/search/near-match.d.ts +32 -0
- package/dist/search/near-match.js +86 -0
- package/dist/search/reader.d.ts +17 -0
- package/dist/search/reader.js +334 -0
- package/dist/search/sheet.d.ts +4 -0
- package/dist/search/sheet.js +28 -0
- package/dist/search/style-outliers.d.ts +77 -0
- package/dist/search/style-outliers.js +166 -0
- package/dist/settings-write.d.ts +78 -0
- package/dist/settings-write.js +374 -0
- package/dist/settings.d.ts +436 -0
- package/dist/settings.js +622 -0
- package/dist/shared-settings.d.ts +4 -0
- package/dist/shared-settings.js +24 -0
- package/dist/sheet/blobs.d.ts +33 -0
- package/dist/sheet/blobs.js +145 -0
- package/dist/sheet/generate.d.ts +71 -0
- package/dist/sheet/generate.js +278 -0
- package/dist/sheet/group.d.ts +20 -0
- package/dist/sheet/group.js +191 -0
- package/dist/sheet/import.d.ts +315 -0
- package/dist/sheet/import.js +832 -0
- package/dist/sheet/matte.d.ts +25 -0
- package/dist/sheet/matte.js +508 -0
- package/dist/sheet/media-import.d.ts +41 -0
- package/dist/sheet/media-import.js +118 -0
- package/dist/sheet/register.d.ts +17 -0
- package/dist/sheet/register.js +176 -0
- package/dist/sheet/slice.d.ts +73 -0
- package/dist/sheet/slice.js +912 -0
- package/dist/sheet/types.d.ts +225 -0
- package/dist/sheet/types.js +1 -0
- package/dist/source/aseprite.d.ts +14 -0
- package/dist/source/aseprite.js +124 -0
- package/dist/source/stage.d.ts +24 -0
- package/dist/source/stage.js +172 -0
- package/dist/spend.d.ts +220 -0
- package/dist/spend.js +436 -0
- package/dist/sprite/render.d.ts +22 -0
- package/dist/sprite/render.js +272 -0
- package/dist/storage.d.ts +135 -0
- package/dist/storage.js +405 -0
- package/dist/style.d.ts +19 -0
- package/dist/style.js +26 -0
- package/dist/template.d.ts +29 -0
- package/dist/template.js +98 -0
- package/dist/testing/aseprite.d.ts +54 -0
- package/dist/testing/aseprite.js +191 -0
- package/dist/testing/cli.d.ts +24 -0
- package/dist/testing/cli.js +91 -0
- package/dist/testing/conformance.d.ts +61 -0
- package/dist/testing/conformance.js +455 -0
- package/dist/testing/index.d.ts +23 -0
- package/dist/testing/index.js +15 -0
- package/dist/testing/mcp.d.ts +25 -0
- package/dist/testing/mcp.js +80 -0
- package/dist/testing/project.d.ts +81 -0
- package/dist/testing/project.js +215 -0
- package/dist/testing/samples.d.ts +42 -0
- package/dist/testing/samples.js +122 -0
- package/dist/transform/operations.d.ts +5 -0
- package/dist/transform/operations.js +320 -0
- package/dist/transform/raster-engine.d.ts +9 -0
- package/dist/transform/raster-engine.js +329 -0
- package/dist/transform/rendition.d.ts +65 -0
- package/dist/transform/rendition.js +317 -0
- package/dist/transform/run.d.ts +138 -0
- package/dist/transform/run.js +442 -0
- package/dist/transform/schema.d.ts +33 -0
- package/dist/transform/schema.js +73 -0
- package/dist/transform/types.d.ts +101 -0
- package/dist/transform/types.js +1 -0
- package/dist/tree/address.d.ts +18 -0
- package/dist/tree/address.js +59 -0
- package/dist/tree/list.d.ts +18 -0
- package/dist/tree/list.js +101 -0
- package/dist/tree/project.d.ts +61 -0
- package/dist/tree/project.js +145 -0
- package/dist/tree/read.d.ts +43 -0
- package/dist/tree/read.js +715 -0
- package/dist/tree/search.d.ts +20 -0
- package/dist/tree/search.js +44 -0
- package/dist/tree/serve.d.ts +79 -0
- package/dist/tree/serve.js +415 -0
- package/dist/tree/thumbs.d.ts +26 -0
- package/dist/tree/thumbs.js +134 -0
- package/dist/turnaround.d.ts +195 -0
- package/dist/turnaround.js +622 -0
- package/dist/types.d.ts +595 -0
- package/dist/types.js +1 -0
- package/package.json +112 -3
- package/policy/blocklist.json +47 -0
- package/policy/prompt-policy-cuts.json +15 -0
- package/skills/art-direction/SKILL.md +16 -0
- package/skills/art-direction/default.md +14 -0
- package/skills/art-direction/presets/cozy-storybook.md +121 -0
- package/skills/art-direction/presets/dark-gritty-isometric.md +121 -0
- package/skills/art-direction/presets/flat-cartoon-kids.md +121 -0
- package/skills/art-direction/references/bible-format.md +47 -0
- package/skills/assetgrove/SKILL.md +109 -0
- package/skills/assetgrove/references/commands.md +723 -0
|
@@ -0,0 +1,1795 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `assetgrove look-dev`: gives a picked, rigged 3D character a base colour in the target's
|
|
3
|
+
* character look on its own UVs, fur groom maps per season, and eyes that catch light, checks
|
|
4
|
+
* them, and stages the result as a one-candidate run that `pick` hands off (assetgrove#82;
|
|
5
|
+
* docs/look-dev.md). The mesh, UVs and rig are never regenerated. Assetgrove never approves it.
|
|
6
|
+
*/
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
9
|
+
import { basename, join, posix, resolve } from "node:path";
|
|
10
|
+
import { Budget, BudgetExceededError } from "../../budget.js";
|
|
11
|
+
import { Caller } from "../../calls.js";
|
|
12
|
+
import { InputError, ProviderError } from "../../errors.js";
|
|
13
|
+
import { checkWrites } from "../../paths.js";
|
|
14
|
+
import { identityReason, identitySettings3d, scoreIdentity } from "../../identity.js";
|
|
15
|
+
import { createRaster, decodeImage, encodePng } from "../../image/raster.js";
|
|
16
|
+
import { grantOf } from "../../license.js";
|
|
17
|
+
import { writeRun } from "../../loop.js";
|
|
18
|
+
import { DIGITAL_SOURCE_TYPES, embedDigitalSourceType, metadataStep, readDigitalSourceType, } from "../../metadata.js";
|
|
19
|
+
import { sha256, styleNotes, subjectOf } from "../../request.js";
|
|
20
|
+
import { IDENTITY_CAST_OPERATION, LOOKDEV_GROOM_OPERATION, LOOKDEV_LOCATE_OPERATION, LOOKDEV_MARKING_OPERATION, LOOKDEV_MARKINGS_OPERATION, LOOKDEV_OPERATION, } from "../../routes.js";
|
|
21
|
+
import { ledgerFor } from "../../spend.js";
|
|
22
|
+
import { GLB_MEDIA_TYPE, parseGlb, writeGlb } from "../glb.js";
|
|
23
|
+
import { CHARACTER_3D_KIND, characterSpec, model3dSettings, profileBudgets } from "../profile.js";
|
|
24
|
+
import { coreModelChecks, coreModelSettings } from "../core-checks.js";
|
|
25
|
+
import { qaPassed, validatorCheck } from "../qa.js";
|
|
26
|
+
import { TURNTABLE_VIEWS, closeUpCamera, framedCamera, figureMask, renderView, renderViewWithDepth, speckle, } from "../render.js";
|
|
27
|
+
import { profileSha256 } from "../rig/candidate.js";
|
|
28
|
+
import { declaresRig, loadRig } from "../rig/template.js";
|
|
29
|
+
import { boundsOf, clips, measure, posedPrimitives, worldMatrices, yawBetween } from "../scene.js";
|
|
30
|
+
import { EYE_MATERIAL, addExternalImage, baseColorImage, compactBin, nodePositions, replaceImage, setEmissiveAt, splitEyes, } from "./edit.js";
|
|
31
|
+
import { GROOM_REGIONS, groomMaps, groomMaskCheck, markerMask, padMask, texelRegions, } from "./groom.js";
|
|
32
|
+
import { depthMap, dilate, fillUnseen, projectViews, seamError } from "./project.js";
|
|
33
|
+
import { ReferenceViewCache, loadReferenceViews, planReferenceViews, requireFront, subjectBibleReferences, viewRecord, } from "../views.js";
|
|
34
|
+
import { bakeTexels } from "./texels.js";
|
|
35
|
+
import { deltaE, MARKING_VERDICTS, MAX_MARKINGS_JUDGED, markingCrop, markingDecisionPrompt, markingsPrompt, markingsFiltering, markingsReason, measureBox, parseMarkingsReply, } from "./markings.js";
|
|
36
|
+
import { lookdevSettings } from "./settings.js";
|
|
37
|
+
export const LOOKDEV_STEP = "lookdev";
|
|
38
|
+
/** The groom key used when the profile declares no seasons. */
|
|
39
|
+
export const SINGLE_GROOM = "default";
|
|
40
|
+
/**
|
|
41
|
+
* The views look-dev restyles and projects back, in the order it restyles them: the four turntable
|
|
42
|
+
* views, the other side, and a high view of the back. The square-on views come first, so each
|
|
43
|
+
* diagonal view continues markings that a square-on view already placed along the body
|
|
44
|
+
* (assetgrove#129: restyled before the side, a diagonal view placed markings the side view then
|
|
45
|
+
* redrew elsewhere, and the blend mixed the two).
|
|
46
|
+
*/
|
|
47
|
+
export const LOOKDEV_VIEWS = [
|
|
48
|
+
{ name: "front", yawDeg: 0, elevationDeg: 15 },
|
|
49
|
+
{ name: "side", yawDeg: 90, elevationDeg: 15 },
|
|
50
|
+
{ name: "other-side", yawDeg: 270, elevationDeg: 15 },
|
|
51
|
+
{ name: "back", yawDeg: 180, elevationDeg: 15 },
|
|
52
|
+
{ name: "three-quarter", yawDeg: 45, elevationDeg: 15 },
|
|
53
|
+
{ name: "other-three-quarter", yawDeg: 315, elevationDeg: 15 },
|
|
54
|
+
{ name: "top", yawDeg: 135, elevationDeg: 65 },
|
|
55
|
+
];
|
|
56
|
+
/**
|
|
57
|
+
* The detail pass: a view framed on the head (the rig template's head region, where the eyes and
|
|
58
|
+
* nose are), from the close-up's direction, restyled after the views above and projected with
|
|
59
|
+
* them. It sees the face at several times the turntable views' resolution, so the projection
|
|
60
|
+
* hands the face to it (assetgrove#143: the front view painted the face about 200 px across, and
|
|
61
|
+
* the close-up enlarged that). Without a head region it falls back to the close-up at the
|
|
62
|
+
* target's closest zoom. `reference` names the turnaround view it is restyled against. Close-ups
|
|
63
|
+
* from the diagonals were tried: each painted the cheeks its own way and took the face's sides
|
|
64
|
+
* from the front one, so the mask came out as a hard bar.
|
|
65
|
+
*/
|
|
66
|
+
export const LOOKDEV_DETAIL_VIEWS = [{ name: "close-up", yawDeg: 0, reference: "front" }];
|
|
67
|
+
/** The share of a restyled turntable view's larger side the figure's outline fills. */
|
|
68
|
+
const VIEW_FILL = 0.86;
|
|
69
|
+
/** The share of a detail view's larger side the head's outline fills. */
|
|
70
|
+
const DETAIL_FILL = 0.8;
|
|
71
|
+
/** Restyled views are rendered and projected at this edge. */
|
|
72
|
+
const VIEW_PX = 1024;
|
|
73
|
+
const CLOSE_UP_PX = 512;
|
|
74
|
+
const BACKGROUND = [216, 216, 216];
|
|
75
|
+
/**
|
|
76
|
+
* The least share of the visible texels (those some restyled view's camera sees, facing it and
|
|
77
|
+
* past its depth test) that must take colour from the restyled views. Hidden UV area is not in
|
|
78
|
+
* the share, so the limit can be high.
|
|
79
|
+
*/
|
|
80
|
+
const MIN_COVERAGE = 0.9;
|
|
81
|
+
/** The most speckle (impulse pixels, fur render minus bare render) a fur preview view may show. */
|
|
82
|
+
const MAX_FUR_SPECKLE = 0.005;
|
|
83
|
+
function seasonsOf(settings) {
|
|
84
|
+
return settings.seasons ?? [SINGLE_GROOM];
|
|
85
|
+
}
|
|
86
|
+
/** The calls one look-dev makes and their estimate, computed without spending anything. */
|
|
87
|
+
export function planLookdev(profile, routes, capUsd, viewCalls = []) {
|
|
88
|
+
model3dSettings(profile);
|
|
89
|
+
const settings = lookdevSettings(profile);
|
|
90
|
+
const cap = capUsd ?? settings.capUsd;
|
|
91
|
+
const calls = [];
|
|
92
|
+
const add = (operation) => {
|
|
93
|
+
const route = routes[operation];
|
|
94
|
+
if (!route)
|
|
95
|
+
throw new InputError(`no model route for operation "${operation}"`);
|
|
96
|
+
calls.push({ operation, model: route.model, estimatedCostUsd: route.estimatedCostUsd });
|
|
97
|
+
};
|
|
98
|
+
// Which view each undeclared reference shows: judged before the first restyle.
|
|
99
|
+
calls.push(...viewCalls);
|
|
100
|
+
for (let i = 0; i < LOOKDEV_VIEWS.length + LOOKDEV_DETAIL_VIEWS.length; i++) {
|
|
101
|
+
add(LOOKDEV_OPERATION);
|
|
102
|
+
}
|
|
103
|
+
add(LOOKDEV_LOCATE_OPERATION);
|
|
104
|
+
for (let i = 0; i < seasonsOf(settings).length; i++)
|
|
105
|
+
add(LOOKDEV_GROOM_OPERATION);
|
|
106
|
+
// At most one markings call per turntable view: only views with their own turnaround view call.
|
|
107
|
+
for (let i = 0; i < TURNTABLE_VIEWS.length; i++)
|
|
108
|
+
add(LOOKDEV_MARKINGS_OPERATION);
|
|
109
|
+
// One decision per marking, view and season, for up to MAX_MARKINGS_JUDGED markings per view. A
|
|
110
|
+
// view naming more is judged whole while the cap has room; a marking it cannot afford fails.
|
|
111
|
+
const judged = TURNTABLE_VIEWS.length * seasonsOf(settings).length * MAX_MARKINGS_JUDGED;
|
|
112
|
+
for (let i = 0; i < judged; i++)
|
|
113
|
+
add(LOOKDEV_MARKING_OPERATION);
|
|
114
|
+
// Identity never filters a 3D character, so no record check is forecast.
|
|
115
|
+
const identity = identitySettings3d(profile);
|
|
116
|
+
if (identity.mode !== "off") {
|
|
117
|
+
add(identity.question === "cast" ? IDENTITY_CAST_OPERATION : "identity");
|
|
118
|
+
}
|
|
119
|
+
const estimateUsd = calls.reduce((sum, c) => sum + c.estimatedCostUsd, 0);
|
|
120
|
+
return {
|
|
121
|
+
capUsd: cap,
|
|
122
|
+
calls,
|
|
123
|
+
estimateUsd,
|
|
124
|
+
withinCap: estimateUsd <= cap + 1e-9,
|
|
125
|
+
seasons: seasonsOf(settings),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/** The view calls a look-dev forecasts: one per reference of the spec's look with no declared view. */
|
|
129
|
+
export function lookdevViewCalls(spec, bible, routes) {
|
|
130
|
+
return planReferenceViews(subjectBibleReferences(spec, bible, { byLook: true }), routes);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Bible references of the subject for the spec's look, each with the view it shows (declared, or
|
|
134
|
+
* judged by a model and cached). A look-dev whose references show no front view is refused here,
|
|
135
|
+
* before the first restyle.
|
|
136
|
+
*/
|
|
137
|
+
async function subjectReferences(spec, bible, bibleDir, caller, cache) {
|
|
138
|
+
const refs = subjectBibleReferences(spec, bible, { byLook: true });
|
|
139
|
+
if (refs.length === 0) {
|
|
140
|
+
throw new InputError(`the style bible has no approved references for subject "${subjectOf(spec)}"`);
|
|
141
|
+
}
|
|
142
|
+
const viewed = await loadReferenceViews(caller, refs, bibleDir, cache);
|
|
143
|
+
requireFront(viewed);
|
|
144
|
+
return viewed;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The reference view each restyled, turntable or detail view is matched with: the side view (yaw
|
|
148
|
+
* 90°, the character's left) with the left reference, the other side with the right one.
|
|
149
|
+
*/
|
|
150
|
+
export function referenceViewFor(view) {
|
|
151
|
+
switch (view) {
|
|
152
|
+
case "side":
|
|
153
|
+
return "left";
|
|
154
|
+
case "other-side":
|
|
155
|
+
return "right";
|
|
156
|
+
case "back":
|
|
157
|
+
case "top":
|
|
158
|
+
return "back";
|
|
159
|
+
case "three-quarter":
|
|
160
|
+
case "other-three-quarter":
|
|
161
|
+
return "three-quarter";
|
|
162
|
+
default:
|
|
163
|
+
return "front";
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const AXIS_VECTORS = {
|
|
167
|
+
"+z": [0, 0, 1],
|
|
168
|
+
"-z": [0, 0, -1],
|
|
169
|
+
"+x": [1, 0, 0],
|
|
170
|
+
"-x": [-1, 0, 0],
|
|
171
|
+
};
|
|
172
|
+
function png(bytes) {
|
|
173
|
+
return { role: "render", path: "(render)", mediaType: "image/png", bytes, sha256: sha256(bytes) };
|
|
174
|
+
}
|
|
175
|
+
/** Bilinear resize to any width and height (each axis on its own scale). */
|
|
176
|
+
export function resize(src, width, height) {
|
|
177
|
+
const out = createRaster(width, height);
|
|
178
|
+
const sx = src.width / width;
|
|
179
|
+
const sy = src.height / height;
|
|
180
|
+
for (let y = 0; y < height; y++) {
|
|
181
|
+
const v = Math.min(src.height - 1, Math.max(0, (y + 0.5) * sy - 0.5));
|
|
182
|
+
const y0 = Math.floor(v);
|
|
183
|
+
const y1 = Math.min(src.height - 1, y0 + 1);
|
|
184
|
+
const fy = v - y0;
|
|
185
|
+
for (let x = 0; x < width; x++) {
|
|
186
|
+
const u = Math.min(src.width - 1, Math.max(0, (x + 0.5) * sx - 0.5));
|
|
187
|
+
const x0 = Math.floor(u);
|
|
188
|
+
const x1 = Math.min(src.width - 1, x0 + 1);
|
|
189
|
+
const fx = u - x0;
|
|
190
|
+
for (let c = 0; c < 4; c++) {
|
|
191
|
+
const a = src.data[(y0 * src.width + x0) * 4 + c];
|
|
192
|
+
const b = src.data[(y0 * src.width + x1) * 4 + c];
|
|
193
|
+
const d = src.data[(y1 * src.width + x0) * 4 + c];
|
|
194
|
+
const e = src.data[(y1 * src.width + x1) * 4 + c];
|
|
195
|
+
out.data[(y * width + x) * 4 + c] = Math.round((a * (1 - fx) + b * fx) * (1 - fy) + (d * (1 - fx) + e * fx) * fy);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
/** The bounding box of the set pixels of a `width`-wide mask. */
|
|
202
|
+
function maskBox(mask, width) {
|
|
203
|
+
let x0 = Infinity;
|
|
204
|
+
let y0 = Infinity;
|
|
205
|
+
let x1 = -Infinity;
|
|
206
|
+
let y1 = -Infinity;
|
|
207
|
+
for (let i = 0; i < mask.length; i++) {
|
|
208
|
+
if (!mask[i])
|
|
209
|
+
continue;
|
|
210
|
+
const x = i % width;
|
|
211
|
+
const y = (i - x) / width;
|
|
212
|
+
if (x < x0)
|
|
213
|
+
x0 = x;
|
|
214
|
+
if (y < y0)
|
|
215
|
+
y0 = y;
|
|
216
|
+
if (x > x1)
|
|
217
|
+
x1 = x;
|
|
218
|
+
if (y > y1)
|
|
219
|
+
y1 = y;
|
|
220
|
+
}
|
|
221
|
+
return x1 < x0 ? undefined : { x0, y0, x1: x1 + 1, y1: y1 + 1 };
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* The figure cut out with a margin of `margin` of its larger side, so a vision model boxes markings
|
|
225
|
+
* on the figure at its full resolution rather than on a small figure in a wide frame. The figure
|
|
226
|
+
* is the render's depth `mask`; the crop carries the mask cut the same way.
|
|
227
|
+
*/
|
|
228
|
+
export function figureCrop(raster, mask, margin = 0.08) {
|
|
229
|
+
const box = maskBox(mask, raster.width);
|
|
230
|
+
if (!box)
|
|
231
|
+
return { image: raster, mask };
|
|
232
|
+
const pad = Math.round(Math.max(box.x1 - box.x0, box.y1 - box.y0) * margin);
|
|
233
|
+
const x0 = Math.max(0, box.x0 - pad);
|
|
234
|
+
const y0 = Math.max(0, box.y0 - pad);
|
|
235
|
+
const x1 = Math.min(raster.width, box.x1 + pad);
|
|
236
|
+
const y1 = Math.min(raster.height, box.y1 + pad);
|
|
237
|
+
const out = createRaster(x1 - x0, y1 - y0);
|
|
238
|
+
const outMask = new Uint8Array(out.width * out.height);
|
|
239
|
+
for (let y = y0; y < y1; y++) {
|
|
240
|
+
out.data.set(raster.data.subarray((y * raster.width + x0) * 4, (y * raster.width + x1) * 4), (y - y0) * out.width * 4);
|
|
241
|
+
outMask.set(mask.subarray(y * raster.width + x0, y * raster.width + x1), (y - y0) * out.width);
|
|
242
|
+
}
|
|
243
|
+
return { image: out, mask: outMask };
|
|
244
|
+
}
|
|
245
|
+
/** The median colour of the image's border: the background an edited image ended up with. */
|
|
246
|
+
function borderColour(raster) {
|
|
247
|
+
const samples = [[], [], []];
|
|
248
|
+
const { width, height, data } = raster;
|
|
249
|
+
const push = (x, y) => {
|
|
250
|
+
const o = (y * width + x) * 4;
|
|
251
|
+
for (let c = 0; c < 3; c++)
|
|
252
|
+
samples[c].push(data[o + c]);
|
|
253
|
+
};
|
|
254
|
+
for (let x = 0; x < width; x += 4) {
|
|
255
|
+
push(x, 0);
|
|
256
|
+
push(x, height - 1);
|
|
257
|
+
}
|
|
258
|
+
for (let y = 0; y < height; y += 4) {
|
|
259
|
+
push(0, y);
|
|
260
|
+
push(width - 1, y);
|
|
261
|
+
}
|
|
262
|
+
return samples.map((s) => s.sort((a, b) => a - b)[s.length >> 1]);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The background an edited view left, as a mask: pixels connected to the image's border whose
|
|
266
|
+
* colour is within `tolerance` of the border colour, grown by `grow` pixels so the anti-aliased
|
|
267
|
+
* fringe of the drawn figure is left out too (one pixel by default). Only border-connected pixels count, so a pale coat
|
|
268
|
+
* inside the figure is never taken for background. With the view's flat `render`, a pixel the render
|
|
269
|
+
* itself draws in the background's colour is kept: there, the model's own surface looks like
|
|
270
|
+
* background, and the edit cannot be told apart from it.
|
|
271
|
+
*/
|
|
272
|
+
export function editedBackground(edited, render, tolerance = 24, grow = 1) {
|
|
273
|
+
const { width, height, data } = edited;
|
|
274
|
+
const bg = borderColour(edited);
|
|
275
|
+
const mask = new Uint8Array(width * height);
|
|
276
|
+
const near = (i) => Math.abs(data[i * 4] - bg[0]) +
|
|
277
|
+
Math.abs(data[i * 4 + 1] - bg[1]) +
|
|
278
|
+
Math.abs(data[i * 4 + 2] - bg[2]) <=
|
|
279
|
+
tolerance;
|
|
280
|
+
const stack = [];
|
|
281
|
+
const seed = (i) => {
|
|
282
|
+
if (!mask[i] && near(i)) {
|
|
283
|
+
mask[i] = 1;
|
|
284
|
+
stack.push(i);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
for (let x = 0; x < width; x++) {
|
|
288
|
+
seed(x);
|
|
289
|
+
seed((height - 1) * width + x);
|
|
290
|
+
}
|
|
291
|
+
for (let y = 0; y < height; y++) {
|
|
292
|
+
seed(y * width);
|
|
293
|
+
seed(y * width + width - 1);
|
|
294
|
+
}
|
|
295
|
+
while (stack.length > 0) {
|
|
296
|
+
const i = stack.pop();
|
|
297
|
+
const x = i % width;
|
|
298
|
+
if (x > 0)
|
|
299
|
+
seed(i - 1);
|
|
300
|
+
if (x < width - 1)
|
|
301
|
+
seed(i + 1);
|
|
302
|
+
if (i >= width)
|
|
303
|
+
seed(i - width);
|
|
304
|
+
if (i < (height - 1) * width)
|
|
305
|
+
seed(i + width);
|
|
306
|
+
}
|
|
307
|
+
let grown = mask;
|
|
308
|
+
for (let ring = 0; ring < grow; ring++) {
|
|
309
|
+
const next = Uint8Array.from(grown);
|
|
310
|
+
for (let i = 0; i < width * height; i++) {
|
|
311
|
+
if (grown[i])
|
|
312
|
+
continue;
|
|
313
|
+
const x = i % width;
|
|
314
|
+
if ((x > 0 && grown[i - 1]) ||
|
|
315
|
+
(x < width - 1 && grown[i + 1]) ||
|
|
316
|
+
(i >= width && grown[i - width]) ||
|
|
317
|
+
(i < (height - 1) * width && grown[i + width]))
|
|
318
|
+
next[i] = 1;
|
|
319
|
+
}
|
|
320
|
+
grown = next;
|
|
321
|
+
}
|
|
322
|
+
if (render && render.width === width && render.height === height) {
|
|
323
|
+
for (let i = 0; i < width * height; i++) {
|
|
324
|
+
if (!grown[i])
|
|
325
|
+
continue;
|
|
326
|
+
const o = i * 4;
|
|
327
|
+
const d = Math.abs(render.data[o] - bg[0]) +
|
|
328
|
+
Math.abs(render.data[o + 1] - bg[1]) +
|
|
329
|
+
Math.abs(render.data[o + 2] - bg[2]);
|
|
330
|
+
if (d <= tolerance)
|
|
331
|
+
grown[i] = 0;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return grown;
|
|
335
|
+
}
|
|
336
|
+
/** `mask` with every hole the figure encloses filled: 1 wherever the border cannot be reached through 0s. */
|
|
337
|
+
function filledSilhouette(mask, width, height) {
|
|
338
|
+
const outside = new Uint8Array(mask.length);
|
|
339
|
+
const stack = [];
|
|
340
|
+
const seed = (i) => {
|
|
341
|
+
if (!mask[i] && !outside[i]) {
|
|
342
|
+
outside[i] = 1;
|
|
343
|
+
stack.push(i);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
for (let x = 0; x < width; x++) {
|
|
347
|
+
seed(x);
|
|
348
|
+
seed((height - 1) * width + x);
|
|
349
|
+
}
|
|
350
|
+
for (let y = 0; y < height; y++) {
|
|
351
|
+
seed(y * width);
|
|
352
|
+
seed(y * width + width - 1);
|
|
353
|
+
}
|
|
354
|
+
while (stack.length > 0) {
|
|
355
|
+
const i = stack.pop();
|
|
356
|
+
const x = i % width;
|
|
357
|
+
if (x > 0)
|
|
358
|
+
seed(i - 1);
|
|
359
|
+
if (x < width - 1)
|
|
360
|
+
seed(i + 1);
|
|
361
|
+
if (i >= width)
|
|
362
|
+
seed(i - width);
|
|
363
|
+
if (i < (height - 1) * width)
|
|
364
|
+
seed(i + width);
|
|
365
|
+
}
|
|
366
|
+
return outside.map((v) => (v ? 0 : 1));
|
|
367
|
+
}
|
|
368
|
+
/** The overlap under which `lookdev-registration` names a view: recorded, never a filter. */
|
|
369
|
+
const MIN_OVERLAP = 0.9;
|
|
370
|
+
/**
|
|
371
|
+
* Registers an edited view onto its render. The render's figure is `mask` (its depth buffer). The
|
|
372
|
+
* edit's figure is what is not background connected to its border. The fit starts from the box
|
|
373
|
+
* of one onto the box of the other, then refines scale and offset in x and y to maximise the
|
|
374
|
+
* intersection over union of the two figures, so a soft shadow or a pale outline that moves the
|
|
375
|
+
* edit's box does not stretch the edit. `overlap` is that intersection over union at the fit:
|
|
376
|
+
* low, the edit moved or reshaped the figure.
|
|
377
|
+
*/
|
|
378
|
+
export function register(edited, render, mask) {
|
|
379
|
+
const size = render.width;
|
|
380
|
+
const height = render.height;
|
|
381
|
+
const sized = edited.width === size && edited.height === height ? edited : resize(edited, size, height);
|
|
382
|
+
// The edit's silhouette is all that its border-connected background is not. Its figure, as
|
|
383
|
+
// scored, is that silhouette less every enclosed region of the border colour (a gap between
|
|
384
|
+
// the legs), so the overlap with the exact mask is taken on every pixel and an edit that paints
|
|
385
|
+
// a gap solid is named. The filled silhouettes only set the fit's starting boxes and areas.
|
|
386
|
+
const filled = filledSilhouette(mask, size, height);
|
|
387
|
+
const target = maskBox(filled, size);
|
|
388
|
+
const background = editedBackground(sized, undefined, 24, 0);
|
|
389
|
+
const silhouette = new Uint8Array(background.length);
|
|
390
|
+
for (let i = 0; i < silhouette.length; i++)
|
|
391
|
+
silhouette[i] = background[i] ? 0 : 1;
|
|
392
|
+
const bg = borderColour(sized);
|
|
393
|
+
const foreground = new Uint8Array(silhouette.length);
|
|
394
|
+
for (let i = 0; i < foreground.length; i++) {
|
|
395
|
+
const o = i * 4;
|
|
396
|
+
const near = Math.abs(sized.data[o] - bg[0]) +
|
|
397
|
+
Math.abs(sized.data[o + 1] - bg[1]) +
|
|
398
|
+
Math.abs(sized.data[o + 2] - bg[2]) <=
|
|
399
|
+
24;
|
|
400
|
+
foreground[i] = silhouette[i] && !near ? 1 : 0;
|
|
401
|
+
}
|
|
402
|
+
const source = maskBox(silhouette, sized.width);
|
|
403
|
+
if (!target || !source)
|
|
404
|
+
return { image: sized, overlap: 0 };
|
|
405
|
+
const sampleAt = (p, x, y) => {
|
|
406
|
+
const u = Math.round(p[2] + p[0] * x);
|
|
407
|
+
const v = Math.round(p[3] + p[1] * y);
|
|
408
|
+
return u < 0 || v < 0 || u >= sized.width || v >= sized.height
|
|
409
|
+
? 0
|
|
410
|
+
: foreground[v * sized.width + u];
|
|
411
|
+
};
|
|
412
|
+
const iou = (p, stride) => {
|
|
413
|
+
let both = 0;
|
|
414
|
+
let either = 0;
|
|
415
|
+
for (let y = 0; y < height; y += stride) {
|
|
416
|
+
for (let x = 0; x < size; x += stride) {
|
|
417
|
+
const m = mask[y * size + x];
|
|
418
|
+
const f = sampleAt(p, x, y);
|
|
419
|
+
if (m && f)
|
|
420
|
+
both++;
|
|
421
|
+
if (m || f)
|
|
422
|
+
either++;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return either === 0 ? 0 : both / either;
|
|
426
|
+
};
|
|
427
|
+
// Two starts, each refined: the figures' boxes, and the figures' areas and centroids (a shadow
|
|
428
|
+
// moves the edit's box far more than its centroid).
|
|
429
|
+
const sx = (source.x1 - source.x0) / (target.x1 - target.x0);
|
|
430
|
+
const sy = (source.y1 - source.y0) / (target.y1 - target.y0);
|
|
431
|
+
const stats = (m, width) => {
|
|
432
|
+
let n = 0;
|
|
433
|
+
let cx = 0;
|
|
434
|
+
let cy = 0;
|
|
435
|
+
for (let i = 0; i < m.length; i++) {
|
|
436
|
+
if (!m[i])
|
|
437
|
+
continue;
|
|
438
|
+
n++;
|
|
439
|
+
cx += i % width;
|
|
440
|
+
cy += Math.floor(i / width);
|
|
441
|
+
}
|
|
442
|
+
return { n, cx: cx / n, cy: cy / n };
|
|
443
|
+
};
|
|
444
|
+
const t = stats(filled, size);
|
|
445
|
+
const f = stats(silhouette, sized.width);
|
|
446
|
+
const area = Math.sqrt(f.n / t.n);
|
|
447
|
+
const starts = [
|
|
448
|
+
[sx, sy, source.x0 - target.x0 * sx, source.y0 - target.y0 * sy],
|
|
449
|
+
[area, area, f.cx - t.cx * area, f.cy - t.cy * area],
|
|
450
|
+
];
|
|
451
|
+
let fit = starts[0];
|
|
452
|
+
let best = -1;
|
|
453
|
+
for (const start of starts) {
|
|
454
|
+
let at = start;
|
|
455
|
+
let score = iou(at, 2);
|
|
456
|
+
for (let step = 8; step >= 0.25; step /= 2) {
|
|
457
|
+
for (let improved = true; improved;) {
|
|
458
|
+
improved = false;
|
|
459
|
+
for (let k = 0; k < 4; k++) {
|
|
460
|
+
const delta = k < 2 ? step / size : step;
|
|
461
|
+
for (const sign of [1, -1]) {
|
|
462
|
+
const next = [...at];
|
|
463
|
+
next[k] = at[k] + sign * delta;
|
|
464
|
+
const nextScore = iou(next, 2);
|
|
465
|
+
if (nextScore > score + 1e-9) {
|
|
466
|
+
score = nextScore;
|
|
467
|
+
at = next;
|
|
468
|
+
improved = true;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (score > best) {
|
|
475
|
+
best = score;
|
|
476
|
+
fit = at;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const out = createRaster(size, height);
|
|
480
|
+
for (let y = 0; y < height; y++) {
|
|
481
|
+
const v = Math.min(sized.height - 1, Math.max(0, Math.round(fit[3] + fit[1] * y)));
|
|
482
|
+
for (let x = 0; x < size; x++) {
|
|
483
|
+
const u = Math.min(sized.width - 1, Math.max(0, Math.round(fit[2] + fit[0] * x)));
|
|
484
|
+
const from = (v * sized.width + u) * 4;
|
|
485
|
+
const to = (y * size + x) * 4;
|
|
486
|
+
out.data[to] = sized.data[from];
|
|
487
|
+
out.data[to + 1] = sized.data[from + 1];
|
|
488
|
+
out.data[to + 2] = sized.data[from + 2];
|
|
489
|
+
out.data[to + 3] = 255;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return { image: out, overlap: iou(fit, 1) };
|
|
493
|
+
}
|
|
494
|
+
function restylePrompt(spec, bible, view, referenceRoles, continued = false, detail = false) {
|
|
495
|
+
const subject = subjectOf(spec);
|
|
496
|
+
const description = bible.subjects?.[subject]?.description;
|
|
497
|
+
return [
|
|
498
|
+
"Repaint the surface colour of this 3D character render so it matches the approved references.",
|
|
499
|
+
`The first image is a flat-lit render (${view} view) of the character's 3D model; the others are its approved references (${referenceRoles.join("; ")}).`,
|
|
500
|
+
...(detail
|
|
501
|
+
? [
|
|
502
|
+
"The render is a close-up of the character's head: the figure runs on past the image's edges. Paint its identity markings and features at full detail, with the shape and clean edges the references give them. Leave out the fine strands the references draw standing off the face: paint the surface beneath them.",
|
|
503
|
+
]
|
|
504
|
+
: []),
|
|
505
|
+
...(continued
|
|
506
|
+
? [
|
|
507
|
+
"The render already carries colour painted from other views of the same model. Where a marking from that painting shows in this view, keep it where it is and continue it in the same colour; repaint what does not match the references.",
|
|
508
|
+
]
|
|
509
|
+
: []),
|
|
510
|
+
description ? `Subject: ${subject}, ${description}.` : `Subject: ${subject}.`,
|
|
511
|
+
`Style bible version ${bible.version}:`,
|
|
512
|
+
...styleNotes(spec, bible).map((n) => `- ${n}`),
|
|
513
|
+
"Keep the exact silhouette, pose, framing, camera and size of the render: change only the colour and texture painted on the surface, so it can be projected back onto the model.",
|
|
514
|
+
"The character's features (its eyes, nose and mouth, and any ears, limbs or tail it has) are where the render has them: keep each one exactly there, even where the model's proportions differ from the references, and do not draw a feature (such as an eye) anywhere the render does not show it.",
|
|
515
|
+
"Identity markings include broad colour regions (a paler or darker underside, limbs, back or face) as well as small marks, bands and rims. Keep every identity marking where the references have it relative to those features: each marking at the same place on the body, with the same shape, size, colour and contrast, and the same number of repeats where a marking repeats along a part. Where a part alternates bands of two colours, give each band the width the references give it against its neighbours (where the darker bands are broader than the paler ones in the references, keep them broader), and end the part in the colour the references end it in. A marking that surrounds or runs from a feature in the references (around an eye or running back from it) does so around or from that feature as the render places it. Do not soften, blur, shrink or blend a marking into the colour around it, and add none the references do not show.",
|
|
516
|
+
"Paint the colour as evenly lit albedo: no cast shadows, no highlights, no rim light, no background objects. Keep the plain background colour.",
|
|
517
|
+
"Paint nothing that stands off the surface, even where the references show it: no strands, bristles or stray hairs lying over the surface. They are not surface colour, and projected back they would break up the marking under them.",
|
|
518
|
+
].join("\n");
|
|
519
|
+
}
|
|
520
|
+
function locatePrompt(subject, description) {
|
|
521
|
+
return [
|
|
522
|
+
"The first image is a close-up front render of a 3D character's head, 1:1 pixels; the others are the character's approved references.",
|
|
523
|
+
description ? `Subject: ${subject}, ${description}.` : `Subject: ${subject}.`,
|
|
524
|
+
'Reply with JSON only: {"has": {"eyes": boolean, "nose": boolean, "pawPads": boolean}, "eyes": [{"x": number, "y": number, "r": number}], "nose": {"x": number, "y": number, "r": number} | null}.',
|
|
525
|
+
"has says whether the character, as the references show it, has each part: eyes; a bare nose (nose leather, not a beak or a muzzle covered in fur or scales); bare paw pads on its feet (not hooves, claws without pads, boots, fins or no feet).",
|
|
526
|
+
"x and y are the pixel centre of each eyeball and of the nose leather (the bare tip of the nose) in the first image, from the top-left corner; r is its radius in pixels.",
|
|
527
|
+
"List every visible eye. Use null for the nose if the character has none.",
|
|
528
|
+
].join("\n");
|
|
529
|
+
}
|
|
530
|
+
/** The parts the groom check asks a bare mask for, as the locate reply names them. */
|
|
531
|
+
export const BARE_PARTS = { eyes: "eyes", nose: "nose", pawPads: "paw pads" };
|
|
532
|
+
/**
|
|
533
|
+
* Whether the character has each bare part, from the locate reply's `has`: `false` only where the
|
|
534
|
+
* reply says so; a reply without it keeps every part.
|
|
535
|
+
*/
|
|
536
|
+
export function parseHas(text) {
|
|
537
|
+
let has;
|
|
538
|
+
try {
|
|
539
|
+
has = parseJsonReply(text, "locate")["has"];
|
|
540
|
+
}
|
|
541
|
+
catch {
|
|
542
|
+
has = undefined;
|
|
543
|
+
}
|
|
544
|
+
const h = (has ?? {});
|
|
545
|
+
return { eyes: h["eyes"] !== false, nose: h["nose"] !== false, pawPads: h["pawPads"] !== false };
|
|
546
|
+
}
|
|
547
|
+
function groomPrompt(spec, bible, season, traits, heightM) {
|
|
548
|
+
const subject = subjectOf(spec);
|
|
549
|
+
const description = bible.subjects?.[subject]?.description;
|
|
550
|
+
return [
|
|
551
|
+
`The images are the approved references of ${subject}, a real-time 3D game character about ${heightM.toFixed(2)} m tall.`,
|
|
552
|
+
description ? `Description: ${description}.` : "",
|
|
553
|
+
season === SINGLE_GROOM
|
|
554
|
+
? "Describe its fur groom."
|
|
555
|
+
: `Describe its fur groom in its ${season} coat: ${traits ?? "(no traits given)"}.`,
|
|
556
|
+
`Regions: ${GROOM_REGIONS.join(", ")} (face is the front of the head around the eyes and muzzle; cheek is the side of the head).`,
|
|
557
|
+
'Reply with JSON only: {"lengthMm": {<region>: number}, "density": {<region>: number from 0 to 1}, "tint": {"color": "#rrggbb", "tipWeight": number from 0 to 1} | null}.',
|
|
558
|
+
"lengthMm is the fur length in millimetres. tint is the colour the fur tips are multiplied by where this coat's colour differs from the references; null when it does not.",
|
|
559
|
+
]
|
|
560
|
+
.filter(Boolean)
|
|
561
|
+
.join("\n");
|
|
562
|
+
}
|
|
563
|
+
function parseJsonReply(text, what) {
|
|
564
|
+
const start = text.indexOf("{");
|
|
565
|
+
const end = text.lastIndexOf("}");
|
|
566
|
+
if (start < 0 || end < start)
|
|
567
|
+
throw new ProviderError(`the ${what} reply holds no JSON object`);
|
|
568
|
+
try {
|
|
569
|
+
return JSON.parse(text.slice(start, end + 1));
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
throw new ProviderError(`the ${what} reply is not valid JSON`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
/** One season's groom from the model's reply, clamped to sane ranges. */
|
|
576
|
+
export function parseSeasonGroom(text) {
|
|
577
|
+
const reply = parseJsonReply(text, "groom");
|
|
578
|
+
const lengths = (reply["lengthMm"] ?? {});
|
|
579
|
+
const densities = (reply["density"] ?? {});
|
|
580
|
+
const num = (v, fallback) => typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
581
|
+
const lengthMm = {};
|
|
582
|
+
const density = {};
|
|
583
|
+
for (const region of GROOM_REGIONS) {
|
|
584
|
+
lengthMm[region] = Math.min(300, Math.max(0.5, num(lengths[region], 10)));
|
|
585
|
+
density[region] = Math.min(1, Math.max(0.05, num(densities[region], 0.6)));
|
|
586
|
+
}
|
|
587
|
+
const tint = reply["tint"];
|
|
588
|
+
const hex = typeof tint?.color === "string" ? /^#?([0-9a-f]{6})$/i.exec(tint.color) : null;
|
|
589
|
+
return {
|
|
590
|
+
lengthMm,
|
|
591
|
+
density,
|
|
592
|
+
...(hex && {
|
|
593
|
+
tint: {
|
|
594
|
+
color: [0, 2, 4].map((i) => parseInt(hex[1].slice(i, i + 2), 16) / 255),
|
|
595
|
+
tipWeight: Math.min(1, Math.max(0, num(tint?.tipWeight, 0.5))),
|
|
596
|
+
},
|
|
597
|
+
}),
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
/** Eye and nose points on a camera's depth map: pixel points cast onto the surface. */
|
|
601
|
+
export function parseMarkers(text, camera, depth) {
|
|
602
|
+
const reply = parseJsonReply(text, "locate");
|
|
603
|
+
const size = camera.sizePx;
|
|
604
|
+
const cast = (p) => {
|
|
605
|
+
const q = p;
|
|
606
|
+
if (!q || typeof q.x !== "number" || typeof q.y !== "number")
|
|
607
|
+
return undefined;
|
|
608
|
+
const r = typeof q.r === "number" && q.r > 0 ? q.r : size / 40;
|
|
609
|
+
// The nearest surface pixel within the marker's radius.
|
|
610
|
+
let best;
|
|
611
|
+
const reach = Math.ceil(Math.max(2, r));
|
|
612
|
+
for (let dy = -reach; dy <= reach; dy++) {
|
|
613
|
+
for (let dx = -reach; dx <= reach; dx++) {
|
|
614
|
+
const x = Math.round(q.x) + dx;
|
|
615
|
+
const y = Math.round(q.y) + dy;
|
|
616
|
+
if (x < 0 || y < 0 || x >= size || y >= size)
|
|
617
|
+
continue;
|
|
618
|
+
const d = depth[y * size + x];
|
|
619
|
+
if (!Number.isFinite(d))
|
|
620
|
+
continue;
|
|
621
|
+
const off = dx * dx + dy * dy;
|
|
622
|
+
if (!best || off < (best.x - q.x) ** 2 + (best.y - q.y) ** 2)
|
|
623
|
+
best = { d, x, y };
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (!best)
|
|
627
|
+
return undefined;
|
|
628
|
+
const { eye, forward, right, up, focal } = camera;
|
|
629
|
+
const sx = ((best.x + 0.5 - size / 2) * best.d) / focal;
|
|
630
|
+
const sy = (-(best.y + 0.5 - size / 2) * best.d) / focal;
|
|
631
|
+
const point = [
|
|
632
|
+
eye[0] + forward[0] * best.d + right[0] * sx + up[0] * sy,
|
|
633
|
+
eye[1] + forward[1] * best.d + right[1] * sx + up[1] * sy,
|
|
634
|
+
eye[2] + forward[2] * best.d + right[2] * sx + up[2] * sy,
|
|
635
|
+
];
|
|
636
|
+
return { point, radius: (r * best.d) / focal };
|
|
637
|
+
};
|
|
638
|
+
const eyes = (Array.isArray(reply["eyes"]) ? reply["eyes"] : [])
|
|
639
|
+
.map(cast)
|
|
640
|
+
.filter((m) => m !== undefined);
|
|
641
|
+
const nose = [cast(reply["nose"])].filter((m) => m !== undefined);
|
|
642
|
+
return { eyes, nose };
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Paints a soft catch-light into each eye of a texture on the model's UVs: a small near-white
|
|
646
|
+
* spot on the eye's surface, offset from its centre toward the key light (above, in front, to the
|
|
647
|
+
* character's left, as the turntable light). Changes only texels inside the eye markers. Look-dev
|
|
648
|
+
* paints it into an emissive texture, never into the base colour. An eye whose texels are all
|
|
649
|
+
* farther from the spot's centre than its radius gets the nearest one. Returns, per eye in order,
|
|
650
|
+
* the indices of the texels it painted (none only for an eye with no texel inside it).
|
|
651
|
+
*/
|
|
652
|
+
export function paintCatchLights(albedo, texels, eyes, forward) {
|
|
653
|
+
const left = [forward[2], 0, -forward[0]];
|
|
654
|
+
const l = [0.8 * 0 + 0.6 * forward[0] + 0.3 * left[0], 0.8, 0.6 * forward[2] + 0.3 * left[2]];
|
|
655
|
+
const ll = Math.hypot(l[0], l[1], l[2]);
|
|
656
|
+
const light = [l[0] / ll, l[1] / ll, l[2] / ll];
|
|
657
|
+
const painted = [];
|
|
658
|
+
const size = texels.size;
|
|
659
|
+
for (const eye of eyes) {
|
|
660
|
+
const mine = [];
|
|
661
|
+
painted.push(mine);
|
|
662
|
+
// The eye's outward normal: the mean normal of its texels.
|
|
663
|
+
const n = [0, 0, 0];
|
|
664
|
+
const inside = [];
|
|
665
|
+
for (let i = 0; i < size * size; i++) {
|
|
666
|
+
if (!texels.covered[i])
|
|
667
|
+
continue;
|
|
668
|
+
const dx = texels.position[i * 3] - eye.point[0];
|
|
669
|
+
const dy = texels.position[i * 3 + 1] - eye.point[1];
|
|
670
|
+
const dz = texels.position[i * 3 + 2] - eye.point[2];
|
|
671
|
+
if (dx * dx + dy * dy + dz * dz > eye.radius * eye.radius)
|
|
672
|
+
continue;
|
|
673
|
+
inside.push(i);
|
|
674
|
+
for (let k = 0; k < 3; k++)
|
|
675
|
+
n[k] += texels.normal[i * 3 + k];
|
|
676
|
+
}
|
|
677
|
+
const nl = Math.hypot(...n);
|
|
678
|
+
if (inside.length === 0 || nl === 0)
|
|
679
|
+
continue;
|
|
680
|
+
const normal = [n[0] / nl, n[1] / nl, n[2] / nl];
|
|
681
|
+
const along = light[0] * normal[0] + light[1] * normal[1] + light[2] * normal[2];
|
|
682
|
+
const t = [
|
|
683
|
+
light[0] - normal[0] * along,
|
|
684
|
+
light[1] - normal[1] * along,
|
|
685
|
+
light[2] - normal[2] * along,
|
|
686
|
+
];
|
|
687
|
+
const tl = Math.hypot(...t) || 1;
|
|
688
|
+
const centre = [
|
|
689
|
+
eye.point[0] + (t[0] / tl) * eye.radius * 0.35,
|
|
690
|
+
eye.point[1] + (t[1] / tl) * eye.radius * 0.35,
|
|
691
|
+
eye.point[2] + (t[2] / tl) * eye.radius * 0.35,
|
|
692
|
+
];
|
|
693
|
+
const r = eye.radius * 0.3;
|
|
694
|
+
const paint = (i, w) => {
|
|
695
|
+
for (let c = 0; c < 3; c++) {
|
|
696
|
+
const o = i * 4 + c;
|
|
697
|
+
albedo.data[o] = Math.round(albedo.data[o] * (1 - w) + 250 * w);
|
|
698
|
+
}
|
|
699
|
+
mine.push(i);
|
|
700
|
+
};
|
|
701
|
+
let nearest = inside[0];
|
|
702
|
+
let nearestD = Infinity;
|
|
703
|
+
for (const i of inside) {
|
|
704
|
+
const d = Math.hypot(texels.position[i * 3] - centre[0], texels.position[i * 3 + 1] - centre[1], texels.position[i * 3 + 2] - centre[2]);
|
|
705
|
+
if (d < nearestD) {
|
|
706
|
+
nearest = i;
|
|
707
|
+
nearestD = d;
|
|
708
|
+
}
|
|
709
|
+
if (d >= r)
|
|
710
|
+
continue;
|
|
711
|
+
paint(i, 0.92 * (1 - (d / r) ** 2));
|
|
712
|
+
}
|
|
713
|
+
// An eye whose texels are coarser than the spot still gets one: the texel nearest its centre.
|
|
714
|
+
if (mine.length === 0)
|
|
715
|
+
paint(nearest, 0.92);
|
|
716
|
+
}
|
|
717
|
+
return painted;
|
|
718
|
+
}
|
|
719
|
+
/** The groom skeleton from the skin and, when the target declares one, its rig template. */
|
|
720
|
+
function groomSkeleton(glb, rig, forward) {
|
|
721
|
+
const json = glb.json;
|
|
722
|
+
const skin = json.skins?.[0];
|
|
723
|
+
const world = worldMatrices(json);
|
|
724
|
+
const roles = new Map(rig?.template.joints.map((j) => [j.name, j.role]) ?? []);
|
|
725
|
+
const feet = new Set(rig?.template.feet.flatMap((f) => f.joints) ?? []);
|
|
726
|
+
const parentOf = new Map();
|
|
727
|
+
for (const [i, node] of (json.nodes ?? []).entries()) {
|
|
728
|
+
for (const c of node.children ?? [])
|
|
729
|
+
parentOf.set(c, i);
|
|
730
|
+
}
|
|
731
|
+
const joints = (skin?.joints ?? []).map((node) => {
|
|
732
|
+
const name = json.nodes?.[node]?.name ?? `joint-${node}`;
|
|
733
|
+
const m = world.get(node);
|
|
734
|
+
const parentNode = parentOf.get(node);
|
|
735
|
+
const role = roles.get(name);
|
|
736
|
+
return {
|
|
737
|
+
name,
|
|
738
|
+
parent: parentNode === undefined ? -1 : skin.joints.indexOf(parentNode),
|
|
739
|
+
position: (m ? [m[12], m[13], m[14]] : [0, 0, 0]),
|
|
740
|
+
...(role !== undefined && { role }),
|
|
741
|
+
...(feet.has(name) && { foot: true }),
|
|
742
|
+
};
|
|
743
|
+
});
|
|
744
|
+
return { joints, forward };
|
|
745
|
+
}
|
|
746
|
+
/** The focus of the close-up: the centre of the head region, else the top front of the bounds. */
|
|
747
|
+
function headFocus(texels, regions, bounds, forward) {
|
|
748
|
+
const head = new Set(["face", "cheek", "head"].map((r) => GROOM_REGIONS.indexOf(r)));
|
|
749
|
+
const sum = [0, 0, 0];
|
|
750
|
+
let n = 0;
|
|
751
|
+
for (let i = 0; i < regions.length; i++) {
|
|
752
|
+
if (!texels.covered[i] || !head.has(regions[i]))
|
|
753
|
+
continue;
|
|
754
|
+
sum[0] += texels.position[i * 3];
|
|
755
|
+
sum[1] += texels.position[i * 3 + 1];
|
|
756
|
+
sum[2] += texels.position[i * 3 + 2];
|
|
757
|
+
n++;
|
|
758
|
+
}
|
|
759
|
+
if (n > 0)
|
|
760
|
+
return [sum[0] / n, sum[1] / n, sum[2] / n];
|
|
761
|
+
const { min, max } = bounds;
|
|
762
|
+
const c = [(min[0] + max[0]) / 2, min[1] + (max[1] - min[1]) * 0.75, (min[2] + max[2]) / 2];
|
|
763
|
+
const reach = Math.max(max[0] - min[0], max[2] - min[2]) * 0.4;
|
|
764
|
+
return [c[0] + forward[0] * reach, c[1], c[2] + forward[2] * reach];
|
|
765
|
+
}
|
|
766
|
+
/** The surface points of the head region (face, cheek and head texels), every `step`th texel. */
|
|
767
|
+
function headPoints(texels, regions, step = 7) {
|
|
768
|
+
const head = new Set(["face", "cheek", "head"].map((r) => GROOM_REGIONS.indexOf(r)));
|
|
769
|
+
const points = [];
|
|
770
|
+
for (let i = 0; i < regions.length; i += step) {
|
|
771
|
+
if (!texels.covered[i] || !head.has(regions[i]))
|
|
772
|
+
continue;
|
|
773
|
+
points.push(texels.position[i * 3], texels.position[i * 3 + 1], texels.position[i * 3 + 2]);
|
|
774
|
+
}
|
|
775
|
+
return Float64Array.from(points);
|
|
776
|
+
}
|
|
777
|
+
function sideBySide(images, height) {
|
|
778
|
+
const scaled = images.map((r) => r.height === height
|
|
779
|
+
? r
|
|
780
|
+
: resize(r, Math.max(1, Math.round((r.width * height) / r.height)), height));
|
|
781
|
+
const width = scaled.reduce((s, r) => s + r.width, 0);
|
|
782
|
+
const out = createRaster(width, height);
|
|
783
|
+
let x0 = 0;
|
|
784
|
+
for (const image of scaled) {
|
|
785
|
+
for (let y = 0; y < height; y++) {
|
|
786
|
+
out.data.set(image.data.subarray(y * image.width * 4, (y + 1) * image.width * 4), (y * width + x0) * 4);
|
|
787
|
+
}
|
|
788
|
+
x0 += image.width;
|
|
789
|
+
}
|
|
790
|
+
return out;
|
|
791
|
+
}
|
|
792
|
+
/** The share of pixels that differ between two same-size renders. */
|
|
793
|
+
function changedShare(a, b) {
|
|
794
|
+
let changed = 0;
|
|
795
|
+
for (let i = 0; i < a.data.length; i += 4) {
|
|
796
|
+
if (Math.abs(a.data[i] - b.data[i]) +
|
|
797
|
+
Math.abs(a.data[i + 1] - b.data[i + 1]) +
|
|
798
|
+
Math.abs(a.data[i + 2] - b.data[i + 2]) >
|
|
799
|
+
12)
|
|
800
|
+
changed++;
|
|
801
|
+
}
|
|
802
|
+
return changed / (a.width * a.height);
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Whether `amountUsd` beyond the forecast fits the cap and the cross-run limits while leaving
|
|
806
|
+
* `keepUsd` for the forecast calls still to come.
|
|
807
|
+
*/
|
|
808
|
+
/**
|
|
809
|
+
* The room a marking past the forecast must leave for the rest of the forecast: each later view's
|
|
810
|
+
* `lookdev-markings` box call, its forecast `lookdev-marking` decisions per season, and identity.
|
|
811
|
+
*/
|
|
812
|
+
export function markingsRoomKeptUsd(rest) {
|
|
813
|
+
const perView = rest.markingsUsd + MAX_MARKINGS_JUDGED * rest.seasons * rest.markingUsd;
|
|
814
|
+
return rest.viewsLeft * perView + rest.identityUsd;
|
|
815
|
+
}
|
|
816
|
+
export function canAfford(budget, amountUsd, keepUsd, what) {
|
|
817
|
+
try {
|
|
818
|
+
budget.check(amountUsd + keepUsd, what);
|
|
819
|
+
return true;
|
|
820
|
+
}
|
|
821
|
+
catch (e) {
|
|
822
|
+
if (e instanceof BudgetExceededError)
|
|
823
|
+
return false;
|
|
824
|
+
throw e;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Whether every located eye got its catch-light and the close-up can see it, exactly: per eye, the
|
|
829
|
+
* painted texels are more than zero and at least one of them projects inside the close-up and
|
|
830
|
+
* passes its depth test (its depth along the view axis within half the eye's radius of the
|
|
831
|
+
* nearest surface the close-up drew there). No brightness is measured: a pale eye or an eye
|
|
832
|
+
* smaller than one triangle passes when its catch-light was painted where the close-up sees it.
|
|
833
|
+
*/
|
|
834
|
+
export function catchLight(camera, depth, texels, eyes, painted) {
|
|
835
|
+
const size = camera.sizePx;
|
|
836
|
+
const perEye = eyes.map((eye, e) => {
|
|
837
|
+
const mine = painted[e] ?? [];
|
|
838
|
+
let visible = 0;
|
|
839
|
+
for (const i of mine) {
|
|
840
|
+
const [x, y, d] = camera.project(texels.position[i * 3], texels.position[i * 3 + 1], texels.position[i * 3 + 2]);
|
|
841
|
+
const px = Math.floor(x);
|
|
842
|
+
const py = Math.floor(y);
|
|
843
|
+
if (!(d > 0) || px < 0 || py < 0 || px >= size || py >= size)
|
|
844
|
+
continue;
|
|
845
|
+
if (d <= depth[py * size + px] + eye.radius * 0.5)
|
|
846
|
+
visible++;
|
|
847
|
+
}
|
|
848
|
+
return { painted: mine.length, visible };
|
|
849
|
+
});
|
|
850
|
+
const lit = perEye.filter((p) => p.painted > 0 && p.visible > 0).length;
|
|
851
|
+
return { found: eyes.length > 0 && lit === eyes.length, eyes: lit, perEye };
|
|
852
|
+
}
|
|
853
|
+
function greyMask(mask, size) {
|
|
854
|
+
const out = createRaster(size, size);
|
|
855
|
+
for (let i = 0; i < mask.length; i++) {
|
|
856
|
+
const v = mask[i] ? 255 : 0;
|
|
857
|
+
out.data[i * 4] = v;
|
|
858
|
+
out.data[i * 4 + 1] = v;
|
|
859
|
+
out.data[i * 4 + 2] = v;
|
|
860
|
+
out.data[i * 4 + 3] = 255;
|
|
861
|
+
}
|
|
862
|
+
return out;
|
|
863
|
+
}
|
|
864
|
+
const round = (v, places = 6) => Math.round(v * 10 ** places) / 10 ** places;
|
|
865
|
+
/** Mean luminance of the pixels set in `mask` (the figure, from the render's depth). */
|
|
866
|
+
export function figureLuminance(raster, mask) {
|
|
867
|
+
let sum = 0;
|
|
868
|
+
let n = 0;
|
|
869
|
+
for (let p = 0; p < mask.length; p++) {
|
|
870
|
+
if (!mask[p])
|
|
871
|
+
continue;
|
|
872
|
+
const i = p * 4;
|
|
873
|
+
sum += 0.2126 * raster.data[i] + 0.7152 * raster.data[i + 1] + 0.0722 * raster.data[i + 2];
|
|
874
|
+
n++;
|
|
875
|
+
}
|
|
876
|
+
return n === 0 ? 0 : sum / n;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* The run's preview lighting. With `exposure: "auto"`, one exposure for the whole run: the one
|
|
880
|
+
* that brings the source model's mean lit luminance over the four turntable views to its unlit
|
|
881
|
+
* (albedo) luminance. It depends on the source model alone, so before and after share it.
|
|
882
|
+
*/
|
|
883
|
+
function resolveLighting(settings, render) {
|
|
884
|
+
const lighting = {
|
|
885
|
+
ambient: settings.ambient,
|
|
886
|
+
key: settings.key,
|
|
887
|
+
keyDirection: settings.keyDirection,
|
|
888
|
+
exposure: 1,
|
|
889
|
+
};
|
|
890
|
+
if (settings.exposure !== "auto")
|
|
891
|
+
return { ...lighting, exposure: settings.exposure };
|
|
892
|
+
let lit = 0;
|
|
893
|
+
let unlit = 0;
|
|
894
|
+
for (let v = 0; v < TURNTABLE_VIEWS.length; v++) {
|
|
895
|
+
const albedo = render(undefined, true, v);
|
|
896
|
+
const mask = figureMask(albedo.depth);
|
|
897
|
+
lit += figureLuminance(render(lighting, false, v).raster, mask);
|
|
898
|
+
unlit += figureLuminance(albedo.raster, mask);
|
|
899
|
+
}
|
|
900
|
+
return { ...lighting, exposure: lit > 0 ? unlit / lit : 1 };
|
|
901
|
+
}
|
|
902
|
+
export async function lookDev(options) {
|
|
903
|
+
const { spec, profile, provenance, bible } = options;
|
|
904
|
+
if (spec.kind !== CHARACTER_3D_KIND) {
|
|
905
|
+
throw new InputError(`look-dev needs a ${CHARACTER_3D_KIND} spec, not "${spec.kind}"`);
|
|
906
|
+
}
|
|
907
|
+
characterSpec(spec);
|
|
908
|
+
const settings = model3dSettings(profile);
|
|
909
|
+
coreModelSettings(profile, spec);
|
|
910
|
+
const look = lookdevSettings(profile);
|
|
911
|
+
if (!provenance || typeof provenance !== "object" || !Array.isArray(provenance.calls)) {
|
|
912
|
+
throw new InputError("the provenance file is not an Assetgrove provenance record");
|
|
913
|
+
}
|
|
914
|
+
const plan = planLookdev(profile, options.routes, options.capUsd, lookdevViewCalls(spec, bible, options.routes));
|
|
915
|
+
const log = options.log ?? (() => { });
|
|
916
|
+
const rig = declaresRig(profile) ? await loadRig(profile, options.profileDir) : undefined;
|
|
917
|
+
const sourceSha256 = sha256(options.model.bytes);
|
|
918
|
+
const glb = parseGlb(options.model.bytes);
|
|
919
|
+
const textured = baseColorImage(glb.json);
|
|
920
|
+
if (!textured)
|
|
921
|
+
throw new InputError("the model has no base-colour texture to look-dev");
|
|
922
|
+
const sourceImage = glb.json.images?.[textured.image];
|
|
923
|
+
if (sourceImage?.bufferView === undefined) {
|
|
924
|
+
throw new InputError("the model's base-colour image is not embedded in the .glb");
|
|
925
|
+
}
|
|
926
|
+
const view = glb.json.bufferViews[sourceImage.bufferView];
|
|
927
|
+
const sourceTexture = decodeImage(glb.bin.subarray(view.byteOffset ?? 0, (view.byteOffset ?? 0) + view.byteLength));
|
|
928
|
+
const framing = boundsOf(posedPrimitives(glb));
|
|
929
|
+
if (!framing)
|
|
930
|
+
throw new InputError("the model has no triangle geometry");
|
|
931
|
+
const heightM = framing.max[1] - framing.min[1];
|
|
932
|
+
const facingDeg = (yawBetween("+z", settings.forward) * 180) / Math.PI;
|
|
933
|
+
const forward = AXIS_VECTORS[settings.forward];
|
|
934
|
+
const textureSize = Math.min(Math.max(sourceTexture.width, sourceTexture.height), profileBudgets(profile, spec).budgets.textureMaxPx);
|
|
935
|
+
const groomSize = look.sizePx ?? textureSize;
|
|
936
|
+
// Spend: the whole forecast must fit the cap and the cross-run limits before the first call.
|
|
937
|
+
const budget = new Budget(plan.capUsd, ledgerFor(options.ledger, options.provider, profile));
|
|
938
|
+
budget.check(plan.estimateUsd, "a look-dev of one character");
|
|
939
|
+
const caller = new Caller({
|
|
940
|
+
provider: options.provider,
|
|
941
|
+
...(options.providerName !== undefined && { providerName: options.providerName }),
|
|
942
|
+
budget,
|
|
943
|
+
routes: options.routes,
|
|
944
|
+
...(options.now && { now: options.now }),
|
|
945
|
+
log,
|
|
946
|
+
});
|
|
947
|
+
// The run directory exists before the first call, so a run that stops part-way keeps the
|
|
948
|
+
// views it already paid for.
|
|
949
|
+
const now = options.now ?? (() => new Date());
|
|
950
|
+
const runId = options.runId ??
|
|
951
|
+
`${now().toISOString().replace(/[:.]/g, "-")}-${randomBytes(3).toString("hex")}`;
|
|
952
|
+
const runDir = resolve(options.runsDir, runId);
|
|
953
|
+
const id = "c1";
|
|
954
|
+
const dir = `${id}-${CHARACTER_3D_KIND}`;
|
|
955
|
+
await mkdir(join(runDir, dir), { recursive: true });
|
|
956
|
+
// Which view each reference shows; no front view refuses the look-dev before the first restyle.
|
|
957
|
+
const references = await subjectReferences(spec, bible, options.bibleDir, caller, new ReferenceViewCache(options.stateDir));
|
|
958
|
+
const texels = bakeTexels(glb, textureSize, textured.image);
|
|
959
|
+
const skeleton = groomSkeleton(glb, rig, forward);
|
|
960
|
+
const regions = texelRegions(texels, skeleton);
|
|
961
|
+
const focus = headFocus(texels, regions, framing, forward);
|
|
962
|
+
const zoom = look.closestZoom;
|
|
963
|
+
// At another edge than the close-up's, the same framing: the character spans as much of it.
|
|
964
|
+
const closeUp = (yawDeg, sizePx = CLOSE_UP_PX) => closeUpCamera({
|
|
965
|
+
sizePx,
|
|
966
|
+
yawDeg: facingDeg + yawDeg,
|
|
967
|
+
focus,
|
|
968
|
+
heightM,
|
|
969
|
+
screenHeightPx: (zoom.screenHeightPx * sizePx) / CLOSE_UP_PX,
|
|
970
|
+
characterScreenFraction: zoom.characterScreenFraction,
|
|
971
|
+
});
|
|
972
|
+
// One preview lighting for every before and after render, every season.
|
|
973
|
+
const turntablePx = settings.turntablePx;
|
|
974
|
+
const lighting = resolveLighting(look.previewLighting, (l, unlit, v) => renderViewWithDepth(glb, {
|
|
975
|
+
sizePx: turntablePx,
|
|
976
|
+
yawDeg: facingDeg + TURNTABLE_VIEWS[v].yawDeg,
|
|
977
|
+
framing,
|
|
978
|
+
...(l && { lighting: l }),
|
|
979
|
+
unlit,
|
|
980
|
+
}));
|
|
981
|
+
const unlitView = (model, v) => renderViewWithDepth(model, {
|
|
982
|
+
sizePx: turntablePx,
|
|
983
|
+
yawDeg: facingDeg + TURNTABLE_VIEWS[v].yawDeg,
|
|
984
|
+
framing,
|
|
985
|
+
unlit: true,
|
|
986
|
+
});
|
|
987
|
+
// Before: the turntable views and the close-up of the model as picked.
|
|
988
|
+
const beforeViews = TURNTABLE_VIEWS.map((v) => renderView(glb, { sizePx: turntablePx, yawDeg: facingDeg + v.yawDeg, framing, lighting }));
|
|
989
|
+
const unlitBefore = TURNTABLE_VIEWS.map((_, i) => unlitView(glb, i).raster);
|
|
990
|
+
const beforeClose = renderView(glb, {
|
|
991
|
+
sizePx: CLOSE_UP_PX,
|
|
992
|
+
yawDeg: 0,
|
|
993
|
+
framing,
|
|
994
|
+
camera: closeUp(0),
|
|
995
|
+
lighting,
|
|
996
|
+
});
|
|
997
|
+
// 1. Albedo: restyle flat-lit renders and project them back onto the UVs. The views are
|
|
998
|
+
// restyled in turn: each later view starts from the model carrying what the earlier views
|
|
999
|
+
// painted, so it extends their markings instead of placing its own (assetgrove#122: restyled
|
|
1000
|
+
// independently, the side view put the eye mask where the three-quarter view put pale coat,
|
|
1001
|
+
// and the blend averaged the two to grey).
|
|
1002
|
+
const source = sourceTexture.width === textureSize && sourceTexture.height === textureSize
|
|
1003
|
+
? sourceTexture
|
|
1004
|
+
: resize(sourceTexture, textureSize, textureSize);
|
|
1005
|
+
const projected = [];
|
|
1006
|
+
const depths = [];
|
|
1007
|
+
const registration = {};
|
|
1008
|
+
const viewArtifacts = [];
|
|
1009
|
+
let painted = glb;
|
|
1010
|
+
// The turntable views framed on the figure's own outline, then the detail pass.
|
|
1011
|
+
const positions = posedPrimitives(glb).map((p) => p.positions);
|
|
1012
|
+
const head = headPoints(texels, regions);
|
|
1013
|
+
const restyleViews = [
|
|
1014
|
+
...LOOKDEV_VIEWS.map((v) => ({
|
|
1015
|
+
name: v.name,
|
|
1016
|
+
reference: referenceViewFor(v.name),
|
|
1017
|
+
detail: false,
|
|
1018
|
+
camera: framedCamera({
|
|
1019
|
+
sizePx: VIEW_PX,
|
|
1020
|
+
yawDeg: facingDeg + v.yawDeg,
|
|
1021
|
+
framing,
|
|
1022
|
+
elevationDeg: v.elevationDeg,
|
|
1023
|
+
positions,
|
|
1024
|
+
fill: VIEW_FILL,
|
|
1025
|
+
}),
|
|
1026
|
+
})),
|
|
1027
|
+
...LOOKDEV_DETAIL_VIEWS.map((v) => ({
|
|
1028
|
+
name: v.name,
|
|
1029
|
+
reference: v.reference,
|
|
1030
|
+
detail: true,
|
|
1031
|
+
camera: head.length > 0
|
|
1032
|
+
? framedCamera({
|
|
1033
|
+
sizePx: VIEW_PX,
|
|
1034
|
+
yawDeg: facingDeg + v.yawDeg,
|
|
1035
|
+
framing,
|
|
1036
|
+
positions: [head],
|
|
1037
|
+
fill: DETAIL_FILL,
|
|
1038
|
+
})
|
|
1039
|
+
: closeUp(v.yawDeg, VIEW_PX),
|
|
1040
|
+
})),
|
|
1041
|
+
];
|
|
1042
|
+
for (const [k, v] of restyleViews.entries()) {
|
|
1043
|
+
const { camera } = v;
|
|
1044
|
+
const flatView = renderViewWithDepth(painted, {
|
|
1045
|
+
sizePx: VIEW_PX,
|
|
1046
|
+
yawDeg: 0,
|
|
1047
|
+
framing,
|
|
1048
|
+
camera,
|
|
1049
|
+
unlit: true,
|
|
1050
|
+
background: BACKGROUND,
|
|
1051
|
+
});
|
|
1052
|
+
const flat = flatView.raster;
|
|
1053
|
+
const flatMask = figureMask(flatView.depth);
|
|
1054
|
+
const flatPng = encodePng(flat);
|
|
1055
|
+
const matching = references.filter((r) => r.view === v.reference);
|
|
1056
|
+
const refs = [...matching, ...references.filter((r) => !matching.includes(r))].slice(0, 3);
|
|
1057
|
+
const edited = await caller.image(LOOKDEV_OPERATION, restylePrompt(spec, bible, v.name, refs.map((r) => r.role), k > 0, v.detail), [{ ...png(flatPng), role: `flat-lit render, ${v.name} view` }, ...refs]);
|
|
1058
|
+
const { image: aligned, overlap } = register(decodeImage(edited.bytes), flat, flatMask);
|
|
1059
|
+
registration[v.name] = overlap;
|
|
1060
|
+
projected.push({ camera, image: aligned, background: editedBackground(aligned, flat) });
|
|
1061
|
+
depths.push(depthMap(glb, camera));
|
|
1062
|
+
if (k < restyleViews.length - 1) {
|
|
1063
|
+
const sofar = projectViews(glb, texels, projected, depths);
|
|
1064
|
+
painted = parseGlb(options.model.bytes);
|
|
1065
|
+
replaceImage(painted, textured.image, encodePng(dilate(fillUnseen(sofar, texels, source), texels.covered, 8)));
|
|
1066
|
+
}
|
|
1067
|
+
viewArtifacts.push({ name: `lookdev-view-${v.name}-render.png`, bytes: flatPng }, { name: `lookdev-view-${v.name}-restyled.png`, bytes: encodePng(aligned) });
|
|
1068
|
+
for (const a of viewArtifacts.slice(-2))
|
|
1069
|
+
await writeFile(join(runDir, dir, a.name), a.bytes);
|
|
1070
|
+
log(`look-dev: restyled the ${v.name} view`);
|
|
1071
|
+
}
|
|
1072
|
+
const projection = projectViews(glb, texels, projected, depths);
|
|
1073
|
+
const albedo = dilate(fillUnseen(projection, texels, source), texels.covered, 8);
|
|
1074
|
+
const albedoPng = encodePng(albedo);
|
|
1075
|
+
// The new albedo goes into the model before the eyes and close-ups are made.
|
|
1076
|
+
replaceImage(glb, textured.image, albedoPng);
|
|
1077
|
+
// 2. Eyes and nose: located on a close-up front render, cast onto the surface.
|
|
1078
|
+
const locateCamera = closeUp(0);
|
|
1079
|
+
const locateRender = renderView(glb, {
|
|
1080
|
+
sizePx: CLOSE_UP_PX,
|
|
1081
|
+
yawDeg: 0,
|
|
1082
|
+
framing,
|
|
1083
|
+
camera: locateCamera,
|
|
1084
|
+
lighting,
|
|
1085
|
+
});
|
|
1086
|
+
// The locate call also says which bare parts the character has, from its references.
|
|
1087
|
+
const subjectName = subjectOf(spec);
|
|
1088
|
+
const locateText = await caller.vision(LOOKDEV_LOCATE_OPERATION, locatePrompt(subjectName, bible.subjects?.[subjectName]?.description), [
|
|
1089
|
+
{ ...png(encodePng(locateRender)), role: "close-up front render" },
|
|
1090
|
+
...[
|
|
1091
|
+
...references.filter((r) => r.view === "front"),
|
|
1092
|
+
...references.filter((r) => r.view !== "front"),
|
|
1093
|
+
].slice(0, 3),
|
|
1094
|
+
]);
|
|
1095
|
+
const has = parseHas(locateText);
|
|
1096
|
+
let markers;
|
|
1097
|
+
try {
|
|
1098
|
+
markers = parseMarkers(locateText, locateCamera, depthMap(glb, locateCamera));
|
|
1099
|
+
}
|
|
1100
|
+
catch {
|
|
1101
|
+
markers = { eyes: [], nose: [] };
|
|
1102
|
+
}
|
|
1103
|
+
// 3. Groom: bare masks, then each season's maps.
|
|
1104
|
+
const groomTexels = groomSize === textureSize ? texels : bakeTexels(glb, groomSize, textured.image);
|
|
1105
|
+
const groomRegions = groomTexels === texels ? regions : texelRegions(groomTexels, skeleton);
|
|
1106
|
+
const eyeMask = markerMask(groomTexels, markers.eyes);
|
|
1107
|
+
const noseMask = markerMask(groomTexels, markers.nose);
|
|
1108
|
+
const world = worldMatrices(glb.json);
|
|
1109
|
+
const joints = nodePositions(glb, world);
|
|
1110
|
+
const feet = (rig?.template.feet ?? [])
|
|
1111
|
+
.map((f) => ({ ankle: joints.get(f.joints[2]), toe: joints.get(f.joints[3]) }))
|
|
1112
|
+
.filter((f) => f.ankle !== undefined && f.toe !== undefined);
|
|
1113
|
+
const padRadius = feet.length > 0
|
|
1114
|
+
? Math.max(...feet.map((f) => Math.hypot(f.toe[0] - f.ankle[0], f.toe[2] - f.ankle[2]) * 0.75 + 0.005))
|
|
1115
|
+
: 0;
|
|
1116
|
+
const pads = padMask(groomTexels, feet, padRadius);
|
|
1117
|
+
const bare = new Uint8Array(eyeMask.length);
|
|
1118
|
+
const count = (m) => m.reduce((s, v, i) => s + (v && groomTexels.covered[i] ? 1 : 0), 0);
|
|
1119
|
+
for (let i = 0; i < bare.length; i++)
|
|
1120
|
+
bare[i] = eyeMask[i] || noseMask[i] || pads[i] ? 1 : 0;
|
|
1121
|
+
// Each bare mask on its own: an empty one means that part has fur nobody checked. A part the
|
|
1122
|
+
// character lacks (the locate call says so) needs no mask; nor do paw pads on a profile with no
|
|
1123
|
+
// rig template, which leaves the feet unknown (decided from the profile, before any call).
|
|
1124
|
+
const bareCounts = { eyes: count(eyeMask), nose: count(noseMask), "paw pads": count(pads) };
|
|
1125
|
+
const parts = {
|
|
1126
|
+
eyes: has.eyes ? "required" : "absent",
|
|
1127
|
+
nose: has.nose ? "required" : "absent",
|
|
1128
|
+
pawPads: !has.pawPads ? "absent" : rig ? "required" : "not required",
|
|
1129
|
+
};
|
|
1130
|
+
const partOf = (name) => Object.keys(BARE_PARTS).find((p) => BARE_PARTS[p] === name);
|
|
1131
|
+
const emptyMasks = Object.entries(bareCounts)
|
|
1132
|
+
.filter(([name, n]) => n === 0 && parts[partOf(name)] === "required")
|
|
1133
|
+
.map(([name]) => name);
|
|
1134
|
+
const unrequired = Object.keys(BARE_PARTS)
|
|
1135
|
+
.filter((p) => parts[p] !== "required")
|
|
1136
|
+
.map((p) => parts[p] === "absent"
|
|
1137
|
+
? `; ${BARE_PARTS[p]}: absent (the locate call says the character has none), no mask required`
|
|
1138
|
+
: `; ${BARE_PARTS[p]}: not required (the profile declares no rig template, so the feet are unknown)`)
|
|
1139
|
+
.join("");
|
|
1140
|
+
const tooSmall = `no texel of the ${groomSize} px groom maps falls inside it`;
|
|
1141
|
+
const whyEmpty = {
|
|
1142
|
+
eyes: markers.eyes.length > 0 ? tooSmall : "the locate call found no eye",
|
|
1143
|
+
nose: markers.nose.length > 0 ? tooSmall : "the locate call found no nose",
|
|
1144
|
+
"paw pads": "no texel faces down under the rig template's feet",
|
|
1145
|
+
};
|
|
1146
|
+
const reasons = [];
|
|
1147
|
+
const sidecars = [];
|
|
1148
|
+
const asset = spec.assetId;
|
|
1149
|
+
const seasonGrooms = {};
|
|
1150
|
+
const seasonMaps = {};
|
|
1151
|
+
const groomReferences = references.slice(0, 4);
|
|
1152
|
+
for (const season of plan.seasons) {
|
|
1153
|
+
const text = await caller.vision(LOOKDEV_GROOM_OPERATION, groomPrompt(spec, bible, season, look.traits[season], heightM), groomReferences);
|
|
1154
|
+
const groom = parseSeasonGroom(text);
|
|
1155
|
+
seasonGrooms[season] = groom;
|
|
1156
|
+
const maps = groomMaps(groomTexels, groomRegions, bare, groom, skeleton, albedo);
|
|
1157
|
+
seasonMaps[season] = maps;
|
|
1158
|
+
const check = groomMaskCheck(maps.length, groomTexels, bare);
|
|
1159
|
+
const label = look.seasons ? `groom-${season}-masks` : "groom-masks";
|
|
1160
|
+
reasons.push({
|
|
1161
|
+
check: label,
|
|
1162
|
+
passed: check.ok && emptyMasks.length === 0,
|
|
1163
|
+
reason: `bare masks: ${Object.entries(bareCounts)
|
|
1164
|
+
.map(([name, n]) => `${name} ${n}`)
|
|
1165
|
+
.join(", ")} texel(s); ` +
|
|
1166
|
+
`${check.zeroOnBare} bare texel(s) with fur and ${check.zeroOutside} zero-length texel(s) outside the masks` +
|
|
1167
|
+
emptyMasks
|
|
1168
|
+
.map((m) => `; the ${m} mask is empty (${whyEmpty[m]}), so zero length there is unchecked`)
|
|
1169
|
+
.join("") +
|
|
1170
|
+
unrequired,
|
|
1171
|
+
source: "deterministic",
|
|
1172
|
+
});
|
|
1173
|
+
const key = look.seasons ? `${season}.` : "";
|
|
1174
|
+
for (const map of look.maps) {
|
|
1175
|
+
sidecars.push({
|
|
1176
|
+
name: `${asset}.groom.${key}${map}.png`,
|
|
1177
|
+
field: `groom.${key}${map}`,
|
|
1178
|
+
bytes: encodePng(maps[map]),
|
|
1179
|
+
...(map === "length" && { extra: { maxLengthM: round(maps.maxLengthM) } }),
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
if (maps.tint && look.seasons) {
|
|
1183
|
+
sidecars.push({
|
|
1184
|
+
name: `${asset}.tint.${season}.png`,
|
|
1185
|
+
field: `textures.tint.${season}`,
|
|
1186
|
+
bytes: encodePng(maps.tint),
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
// 4. The eye material and its mask.
|
|
1191
|
+
const eyeTriangles = splitEyes(glb, textured.material, markers.eyes);
|
|
1192
|
+
// The catch-light is an emissive texture, never the base colour, so the eyes read as
|
|
1193
|
+
// wet at the closest zoom whatever the eye geometry, while the base colour stays unlit albedo.
|
|
1194
|
+
// The target can keep it, or drop it and shade the eyes itself; the glossy eye material adds
|
|
1195
|
+
// the live highlight.
|
|
1196
|
+
// An eye smaller than one triangle moves no triangle into the eye material; its catch-light is
|
|
1197
|
+
// still painted, into the textured material's emissive texture (black everywhere else).
|
|
1198
|
+
const catchLightTexture = createRaster(textureSize, textureSize);
|
|
1199
|
+
for (let i = 3; i < catchLightTexture.data.length; i += 4)
|
|
1200
|
+
catchLightTexture.data[i] = 255;
|
|
1201
|
+
const catchLightTexels = paintCatchLights(catchLightTexture, texels, markers.eyes, forward);
|
|
1202
|
+
const catchLightOn = eyeTriangles > 0 ? EYE_MATERIAL : "textured";
|
|
1203
|
+
// With an eye split, the same texture is the emissive texture of both materials: an eye smaller
|
|
1204
|
+
// than one triangle beside a larger one has its painted texels on textured-material triangles,
|
|
1205
|
+
// and the texture is black there except inside the eyes.
|
|
1206
|
+
if (catchLightTexels.some((p) => p.length > 0)) {
|
|
1207
|
+
const index = setEmissiveAt(glb, textured.material, encodePng(catchLightTexture), "eyes.catchLight");
|
|
1208
|
+
if (eyeTriangles > 0) {
|
|
1209
|
+
const eye = glb.json.materials?.find((m) => m.name === EYE_MATERIAL);
|
|
1210
|
+
if (eye) {
|
|
1211
|
+
eye["emissiveTexture"] = { index };
|
|
1212
|
+
eye["emissiveFactor"] = [1, 1, 1];
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
const eyeMaskTexture = markerMask(texels, markers.eyes);
|
|
1217
|
+
sidecars.push({
|
|
1218
|
+
name: `${asset}.eyes.mask.png`,
|
|
1219
|
+
field: "eyes",
|
|
1220
|
+
bytes: encodePng(greyMask(eyeMaskTexture, textureSize)),
|
|
1221
|
+
extra: { material: EYE_MATERIAL },
|
|
1222
|
+
});
|
|
1223
|
+
sidecars.push({ name: `${asset}.baseColor.png`, field: "textures.baseColor", bytes: albedoPng });
|
|
1224
|
+
// Budgets are measured on the embedded model; the external maps are checked by their own size.
|
|
1225
|
+
compactBin(glb);
|
|
1226
|
+
const embeddedMeasures = measure(parseGlb(writeGlb(glb)));
|
|
1227
|
+
// External images: the groom maps, tints and eye mask beside the .glb, never embedded.
|
|
1228
|
+
const groomExtras = {};
|
|
1229
|
+
for (const s of sidecars) {
|
|
1230
|
+
if (s.field === "textures.baseColor")
|
|
1231
|
+
continue;
|
|
1232
|
+
const index = addExternalImage(glb.json, s.name, s.field);
|
|
1233
|
+
groomExtras[s.field] = { image: index, uri: s.name };
|
|
1234
|
+
}
|
|
1235
|
+
glb.json.asset.extras = {
|
|
1236
|
+
...glb.json.asset.extras,
|
|
1237
|
+
lookdev: {
|
|
1238
|
+
groom: {
|
|
1239
|
+
encoding: {
|
|
1240
|
+
length: "grey, 0 = no fur, 255 = maxLengthM",
|
|
1241
|
+
direction: "rest-pose model-space comb direction, rgb = d * 0.5 + 0.5",
|
|
1242
|
+
density: "grey, 0..1 of the material's strand density",
|
|
1243
|
+
tint: "rgb multiplies the base colour, alpha weights it toward the fur tips",
|
|
1244
|
+
},
|
|
1245
|
+
maxLengthM: Object.fromEntries(Object.entries(seasonMaps).map(([s, m]) => [s, round(m.maxLengthM)])),
|
|
1246
|
+
},
|
|
1247
|
+
images: groomExtras,
|
|
1248
|
+
eyes: {
|
|
1249
|
+
material: EYE_MATERIAL,
|
|
1250
|
+
catchLight: catchLightOn === EYE_MATERIAL
|
|
1251
|
+
? "the eye and textured materials' shared emissiveTexture"
|
|
1252
|
+
: "the textured material's emissiveTexture (no triangle lies wholly inside an eye)",
|
|
1253
|
+
},
|
|
1254
|
+
},
|
|
1255
|
+
};
|
|
1256
|
+
const raw = writeGlb(glb);
|
|
1257
|
+
const written = parseGlb(raw);
|
|
1258
|
+
const measures = {
|
|
1259
|
+
...embeddedMeasures,
|
|
1260
|
+
textureMaxPx: Math.max(embeddedMeasures.textureMaxPx ?? 0, groomSize),
|
|
1261
|
+
};
|
|
1262
|
+
// 5. After: per season, turntables with map-driven shell fur, and the close-up.
|
|
1263
|
+
const artifacts = [...viewArtifacts];
|
|
1264
|
+
const afterBySeason = {};
|
|
1265
|
+
const afterMaskBySeason = {};
|
|
1266
|
+
const afterClose = {};
|
|
1267
|
+
const unlitAfterViews = TURNTABLE_VIEWS.map((_, i) => unlitView(written, i));
|
|
1268
|
+
const unlitAfter = unlitAfterViews.map((u) => u.raster);
|
|
1269
|
+
const unlitAfterMask = unlitAfterViews.map((u) => figureMask(u.depth));
|
|
1270
|
+
const litToUnlit = {};
|
|
1271
|
+
const furSpeckle = {};
|
|
1272
|
+
for (const season of plan.seasons) {
|
|
1273
|
+
const maps = seasonMaps[season];
|
|
1274
|
+
const fur = {
|
|
1275
|
+
length: maps.length,
|
|
1276
|
+
direction: maps.direction,
|
|
1277
|
+
density: maps.density,
|
|
1278
|
+
...(maps.tint && { tint: maps.tint }),
|
|
1279
|
+
maxLengthM: maps.maxLengthM,
|
|
1280
|
+
// About one strand per two texels of the maps, so strands stay finer than a pixel at the closest zoom.
|
|
1281
|
+
strandsPerUv: Math.max(192, Math.round(groomSize / 2)),
|
|
1282
|
+
};
|
|
1283
|
+
const bare = TURNTABLE_VIEWS.map((v) => renderViewWithDepth(written, {
|
|
1284
|
+
sizePx: turntablePx,
|
|
1285
|
+
yawDeg: facingDeg + v.yawDeg,
|
|
1286
|
+
framing,
|
|
1287
|
+
lighting,
|
|
1288
|
+
}));
|
|
1289
|
+
const viewsDepth = TURNTABLE_VIEWS.map((v) => renderViewWithDepth(written, {
|
|
1290
|
+
sizePx: turntablePx,
|
|
1291
|
+
yawDeg: facingDeg + v.yawDeg,
|
|
1292
|
+
framing,
|
|
1293
|
+
fur,
|
|
1294
|
+
lighting,
|
|
1295
|
+
}));
|
|
1296
|
+
const views = viewsDepth.map((v) => v.raster);
|
|
1297
|
+
afterBySeason[season] = views;
|
|
1298
|
+
afterMaskBySeason[season] = viewsDepth.map((v) => figureMask(v.depth));
|
|
1299
|
+
const bareClose = renderViewWithDepth(written, {
|
|
1300
|
+
sizePx: CLOSE_UP_PX,
|
|
1301
|
+
yawDeg: 0,
|
|
1302
|
+
framing,
|
|
1303
|
+
camera: closeUp(0),
|
|
1304
|
+
lighting,
|
|
1305
|
+
});
|
|
1306
|
+
const furClose = renderViewWithDepth(written, {
|
|
1307
|
+
sizePx: CLOSE_UP_PX,
|
|
1308
|
+
yawDeg: 0,
|
|
1309
|
+
framing,
|
|
1310
|
+
camera: closeUp(0),
|
|
1311
|
+
fur,
|
|
1312
|
+
lighting,
|
|
1313
|
+
});
|
|
1314
|
+
afterClose[season] = furClose.raster;
|
|
1315
|
+
litToUnlit[season] = Object.fromEntries(TURNTABLE_VIEWS.map((v, i) => [
|
|
1316
|
+
v.name,
|
|
1317
|
+
round(figureLuminance(views[i], unlitAfterMask[i]) /
|
|
1318
|
+
Math.max(1e-6, figureLuminance(unlitAfter[i], unlitAfterMask[i])), 3),
|
|
1319
|
+
]));
|
|
1320
|
+
// Speckle the fur adds over the bare surface, in every view and the close-up.
|
|
1321
|
+
const speckles = {};
|
|
1322
|
+
TURNTABLE_VIEWS.forEach((v, i) => {
|
|
1323
|
+
speckles[v.name] = Math.max(0, speckle(views[i], afterMaskBySeason[season][i]) -
|
|
1324
|
+
speckle(bare[i].raster, figureMask(bare[i].depth)));
|
|
1325
|
+
});
|
|
1326
|
+
speckles["close-up"] = Math.max(0, speckle(furClose.raster, figureMask(furClose.depth)) -
|
|
1327
|
+
speckle(bareClose.raster, figureMask(bareClose.depth)));
|
|
1328
|
+
furSpeckle[season] = Object.fromEntries(Object.entries(speckles).map(([k, v]) => [k, round(v, 5)]));
|
|
1329
|
+
const worst = Object.entries(speckles).reduce((a, b) => (b[1] > a[1] ? b : a));
|
|
1330
|
+
const share = Math.max(...views.map((v, i) => changedShare(v, bare[i].raster)));
|
|
1331
|
+
reasons.push({
|
|
1332
|
+
check: look.seasons ? `groom-${season}-render` : "groom-render",
|
|
1333
|
+
passed: share > 0.01 && worst[1] <= MAX_FUR_SPECKLE,
|
|
1334
|
+
reason: `shell fur driven by the maps changes ${(share * 100).toFixed(1)}% of the pixels of a turntable view; ` +
|
|
1335
|
+
`speckle it adds: at most ${(worst[1] * 100).toFixed(2)}% of the figure's pixels (${worst[0]}; limit ${(MAX_FUR_SPECKLE * 100).toFixed(1)}%)`,
|
|
1336
|
+
source: "deterministic",
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
// Checks on the albedo.
|
|
1340
|
+
const visibleTexels = projection.visible.reduce((n, v) => n + v, 0);
|
|
1341
|
+
reasons.push({
|
|
1342
|
+
check: "lookdev-albedo-coverage",
|
|
1343
|
+
passed: projection.coverage >= MIN_COVERAGE,
|
|
1344
|
+
reason: `${(projection.coverage * 100).toFixed(1)}% of the ${visibleTexels} texels a restyled view's camera sees take colour from the restyled views ` +
|
|
1345
|
+
`(limit ${(MIN_COVERAGE * 100).toFixed(0)}%; ${(projection.uvCoverage * 100).toFixed(1)}% of all UV-covered texels); the rest keep the source texture, colour-matched`,
|
|
1346
|
+
source: "deterministic",
|
|
1347
|
+
});
|
|
1348
|
+
const overlaps = Object.entries(registration);
|
|
1349
|
+
const moved = overlaps.filter(([, o]) => o < MIN_OVERLAP).map(([k]) => k);
|
|
1350
|
+
reasons.push({
|
|
1351
|
+
check: "lookdev-registration",
|
|
1352
|
+
passed: moved.length === 0,
|
|
1353
|
+
reason: `recorded, never filters: overlap of each restyled view's figure with the render's figure (named under ${MIN_OVERLAP}): ` +
|
|
1354
|
+
overlaps.map(([k, o]) => `${k} ${o.toFixed(3)}`).join(", ") +
|
|
1355
|
+
(moved.length > 0
|
|
1356
|
+
? `; ${moved.join(", ")} under ${MIN_OVERLAP}: the edit moved or reshaped the figure`
|
|
1357
|
+
: ""),
|
|
1358
|
+
source: "deterministic",
|
|
1359
|
+
shadow: true,
|
|
1360
|
+
});
|
|
1361
|
+
const seamsBefore = seamError(parseGlb(options.model.bytes), source, textured.image);
|
|
1362
|
+
const seamsAfter = seamError(written, albedo, textured.image);
|
|
1363
|
+
reasons.push({
|
|
1364
|
+
check: "lookdev-seams",
|
|
1365
|
+
passed: seamsAfter.mean <= Math.max(8, seamsBefore.mean * 1.25),
|
|
1366
|
+
reason: `colour difference across ${seamsAfter.edges} UV seam edge(s): mean ${seamsAfter.mean.toFixed(1)}, ` +
|
|
1367
|
+
`95th percentile ${seamsAfter.p95.toFixed(1)} (0-255; the source texture: mean ${seamsBefore.mean.toFixed(1)}, ` +
|
|
1368
|
+
`95th percentile ${seamsBefore.p95.toFixed(1)})`,
|
|
1369
|
+
source: "deterministic",
|
|
1370
|
+
});
|
|
1371
|
+
// The close-up's depth buffer: the catch-light check is a depth test, not a brightness one.
|
|
1372
|
+
const { depth: closeDepth } = renderViewWithDepth(written, {
|
|
1373
|
+
sizePx: CLOSE_UP_PX,
|
|
1374
|
+
yawDeg: 0,
|
|
1375
|
+
framing,
|
|
1376
|
+
camera: closeUp(0),
|
|
1377
|
+
lighting,
|
|
1378
|
+
});
|
|
1379
|
+
const light = catchLight(closeUp(0), closeDepth, texels, markers.eyes, catchLightTexels);
|
|
1380
|
+
// A character the locate call says has no eyes (a robot with a visor) has no eye material to
|
|
1381
|
+
// light: recorded as absent, not as a failure, like its groom mask.
|
|
1382
|
+
reasons.push({
|
|
1383
|
+
check: "eyes-catch-light",
|
|
1384
|
+
passed: parts.eyes === "absent" || light.found,
|
|
1385
|
+
reason: (parts.eyes === "absent"
|
|
1386
|
+
? "eyes: absent (the locate call says the character has none), no eye material or catch-light required; "
|
|
1387
|
+
: "") +
|
|
1388
|
+
`${markers.eyes.length} eye(s) located, ${eyeTriangles} triangle(s) in the "${EYE_MATERIAL}" material; ` +
|
|
1389
|
+
`catch-light painted and seen by the close-up at the closest zoom in ${light.eyes} of ${markers.eyes.length} eye(s)` +
|
|
1390
|
+
(light.perEye.length > 0
|
|
1391
|
+
? ` (${light.perEye.map((p, e) => `eye ${e + 1}: ${p.painted} texel(s) painted, ${p.visible} passing the close-up's depth test`).join("; ")})`
|
|
1392
|
+
: "") +
|
|
1393
|
+
`; the catch-light is the ${catchLightOn === EYE_MATERIAL ? "eye and textured materials' shared" : "textured material's"} emissive texture, the base colour has none`,
|
|
1394
|
+
source: "deterministic",
|
|
1395
|
+
});
|
|
1396
|
+
reasons.push(await validatorCheck(raw, Object.fromEntries(sidecars.map((s) => [s.name, s.bytes]))));
|
|
1397
|
+
const missingClips = provenance.parameters?.["missingClips"];
|
|
1398
|
+
reasons.push(...(await coreModelChecks({
|
|
1399
|
+
bytes: raw,
|
|
1400
|
+
profile,
|
|
1401
|
+
spec,
|
|
1402
|
+
resources: Object.fromEntries(sidecars.map((s) => [s.name, s.bytes])),
|
|
1403
|
+
...(rig && { rig }),
|
|
1404
|
+
...(Array.isArray(missingClips) && {
|
|
1405
|
+
missing: missingClips,
|
|
1406
|
+
}),
|
|
1407
|
+
})));
|
|
1408
|
+
// Markings: each identity marking in the lit after renders against the matching turnaround view.
|
|
1409
|
+
const markingMeasures = [];
|
|
1410
|
+
const unmeasured = [];
|
|
1411
|
+
const unreadable = [];
|
|
1412
|
+
const unjudged = [];
|
|
1413
|
+
const identityUsd = plan.calls
|
|
1414
|
+
.filter((c) => c.operation === "identity" || c.operation === IDENTITY_CAST_OPERATION)
|
|
1415
|
+
.reduce((sum, c) => sum + c.estimatedCostUsd, 0);
|
|
1416
|
+
for (const [v, view] of TURNTABLE_VIEWS.entries()) {
|
|
1417
|
+
const wanted = referenceViewFor(view.name);
|
|
1418
|
+
const ref = references.find((r) => r.view === wanted);
|
|
1419
|
+
if (!ref) {
|
|
1420
|
+
unmeasured.push(`${view.name} (the references have no ${wanted} view)`);
|
|
1421
|
+
continue;
|
|
1422
|
+
}
|
|
1423
|
+
// Each render cut to its figure, so the boxes land on the figure at full resolution.
|
|
1424
|
+
const crops = plan.seasons.map((s) => figureCrop(afterBySeason[s][v], afterMaskBySeason[s][v]));
|
|
1425
|
+
const renders = crops.map((c) => c.image);
|
|
1426
|
+
const text = await caller.vision(LOOKDEV_MARKINGS_OPERATION, markingsPrompt({
|
|
1427
|
+
subject: subjectName,
|
|
1428
|
+
...(bible.subjects?.[subjectName]?.description !== undefined && {
|
|
1429
|
+
description: bible.subjects[subjectName].description,
|
|
1430
|
+
}),
|
|
1431
|
+
view: view.name,
|
|
1432
|
+
referenceRole: ref.role,
|
|
1433
|
+
seasons: plan.seasons,
|
|
1434
|
+
}), [
|
|
1435
|
+
ref,
|
|
1436
|
+
...renders.map((r, k) => ({
|
|
1437
|
+
...png(encodePng(r)),
|
|
1438
|
+
role: `lit render after look-dev, ${view.name} view, ${plan.seasons[k]}`,
|
|
1439
|
+
})),
|
|
1440
|
+
]);
|
|
1441
|
+
let markings;
|
|
1442
|
+
try {
|
|
1443
|
+
markings = parseMarkingsReply(text, renders.length + 1);
|
|
1444
|
+
}
|
|
1445
|
+
catch {
|
|
1446
|
+
unreadable.push(`${view.name} (the markings reply held no JSON)`);
|
|
1447
|
+
continue;
|
|
1448
|
+
}
|
|
1449
|
+
if (markings.length === 0)
|
|
1450
|
+
unmeasured.push(`${view.name} (no marking was named)`);
|
|
1451
|
+
const refImage = decodeImage(ref.bytes);
|
|
1452
|
+
for (const [n, m] of markings.entries()) {
|
|
1453
|
+
// Past the forecast's markings, a marking is judged only while the cap has room for its
|
|
1454
|
+
// decisions; one it cannot afford is unjudged and fails the check, never passes unseen.
|
|
1455
|
+
if (n >= MAX_MARKINGS_JUDGED) {
|
|
1456
|
+
const each = options.routes[LOOKDEV_MARKING_OPERATION]?.estimatedCostUsd ?? 0;
|
|
1457
|
+
const later = markingsRoomKeptUsd({
|
|
1458
|
+
viewsLeft: TURNTABLE_VIEWS.length - 1 - v,
|
|
1459
|
+
seasons: renders.length,
|
|
1460
|
+
markingUsd: each,
|
|
1461
|
+
markingsUsd: options.routes[LOOKDEV_MARKINGS_OPERATION]?.estimatedCostUsd ?? 0,
|
|
1462
|
+
identityUsd,
|
|
1463
|
+
});
|
|
1464
|
+
if (!canAfford(budget, each * renders.length, later, `the ${m.name} marking decisions`)) {
|
|
1465
|
+
unjudged.push(`${m.name} in ${view.name}`);
|
|
1466
|
+
continue;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
const refBoxes = m.boxes[0];
|
|
1470
|
+
const refMark = refBoxes && measureBox(refImage, refBoxes.mark, undefined);
|
|
1471
|
+
const refGround = refBoxes && measureBox(refImage, refBoxes.ground, undefined);
|
|
1472
|
+
if (!refMark || !refGround) {
|
|
1473
|
+
unmeasured.push(`${m.name} in ${view.name} (not located on the reference)`);
|
|
1474
|
+
continue;
|
|
1475
|
+
}
|
|
1476
|
+
const refCrop = {
|
|
1477
|
+
...png(encodePng(markingCrop(refImage, refBoxes))),
|
|
1478
|
+
role: `reference crop: ${m.name}, ${view.name}`,
|
|
1479
|
+
};
|
|
1480
|
+
for (const [k, crop] of crops.entries()) {
|
|
1481
|
+
const render = crop.image;
|
|
1482
|
+
const boxes = m.boxes[k + 1] ?? null;
|
|
1483
|
+
const image = plan.seasons[k];
|
|
1484
|
+
const renderMark = boxes && measureBox(render, boxes.mark, crop.mask);
|
|
1485
|
+
const { result, record } = await caller.decide(LOOKDEV_MARKING_OPERATION, markingDecisionPrompt({
|
|
1486
|
+
subject: subjectName,
|
|
1487
|
+
marking: m.name,
|
|
1488
|
+
against: m.against,
|
|
1489
|
+
view: view.name,
|
|
1490
|
+
season: image,
|
|
1491
|
+
}), [
|
|
1492
|
+
refCrop,
|
|
1493
|
+
{
|
|
1494
|
+
...png(encodePng(markingCrop(render, boxes))),
|
|
1495
|
+
role: `render crop: ${m.name}, ${view.name}, ${image}`,
|
|
1496
|
+
},
|
|
1497
|
+
], {
|
|
1498
|
+
type: "choice",
|
|
1499
|
+
instructions: "Is the marking still there in the render, in the same colour and contrast as in the reference?",
|
|
1500
|
+
options: MARKING_VERDICTS,
|
|
1501
|
+
});
|
|
1502
|
+
if (result.answer.type !== "choice" ||
|
|
1503
|
+
!Object.hasOwn(MARKING_VERDICTS, result.answer.choice)) {
|
|
1504
|
+
throw new ProviderError(`the marking decision for ${m.name} did not choose an option`);
|
|
1505
|
+
}
|
|
1506
|
+
const verdict = result.answer.choice;
|
|
1507
|
+
const probability = record.decision?.value;
|
|
1508
|
+
markingMeasures.push({
|
|
1509
|
+
marking: m.name,
|
|
1510
|
+
view: view.name,
|
|
1511
|
+
image,
|
|
1512
|
+
verdict,
|
|
1513
|
+
...(probability !== undefined && { probability }),
|
|
1514
|
+
...(renderMark && { deltaE: deltaE(refMark, renderMark) }),
|
|
1515
|
+
drifts: verdict !== "kept",
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
// lookdev-markings filters only where measured stable on the run's markings model.
|
|
1521
|
+
const markingsState = markingsFiltering(options.routes[LOOKDEV_MARKING_OPERATION]?.model);
|
|
1522
|
+
reasons.push(markingsReason(markingMeasures, { unmeasured, unreadable, unjudged }, markingsState));
|
|
1523
|
+
// 6. Identity lock on the looked-dev turntable (front and three-quarter), as for wave 0.
|
|
1524
|
+
let identity;
|
|
1525
|
+
const identityMode = identitySettings3d(profile);
|
|
1526
|
+
const firstSeason = plan.seasons[0];
|
|
1527
|
+
if (identityMode.mode !== "off") {
|
|
1528
|
+
const views = afterBySeason[firstSeason];
|
|
1529
|
+
const composite = encodePng(sideBySide([views[0], views[1]], turntablePx));
|
|
1530
|
+
const subject = subjectOf(spec);
|
|
1531
|
+
identity = await scoreIdentity({
|
|
1532
|
+
caller,
|
|
1533
|
+
record: {
|
|
1534
|
+
subject,
|
|
1535
|
+
version: bible.version,
|
|
1536
|
+
sha256: sha256(Buffer.from(JSON.stringify({ subject, description: bible.subjects?.[subject]?.description }))),
|
|
1537
|
+
fingerprint: {
|
|
1538
|
+
signatureFeatures: [bible.subjects?.[subject]?.description ?? subject],
|
|
1539
|
+
proportions: bible.subjects?.[subject]?.description ?? subject,
|
|
1540
|
+
palette: bible.palette,
|
|
1541
|
+
},
|
|
1542
|
+
references: references.map((r) => ({ role: r.role, path: r.path, sha256: r.sha256 })),
|
|
1543
|
+
},
|
|
1544
|
+
references,
|
|
1545
|
+
candidate: {
|
|
1546
|
+
role: "candidate turntable",
|
|
1547
|
+
path: "(front and three-quarter renders after look-dev)",
|
|
1548
|
+
mediaType: "image/png",
|
|
1549
|
+
bytes: composite,
|
|
1550
|
+
sha256: sha256(composite),
|
|
1551
|
+
},
|
|
1552
|
+
describe: "turntable renders of a 3D character model, front view on the left and three-quarter view on the right",
|
|
1553
|
+
settings: identityMode,
|
|
1554
|
+
});
|
|
1555
|
+
reasons.push(identityReason(identity));
|
|
1556
|
+
}
|
|
1557
|
+
// 7. Before and after beside the approved turnaround, for the person who approves.
|
|
1558
|
+
// Each compare image leads with the turnaround's matching view; one that has to borrow the
|
|
1559
|
+
// front view, or has no turnaround column at all, is named in a reason for the person.
|
|
1560
|
+
const substituted = [];
|
|
1561
|
+
const noColumn = [];
|
|
1562
|
+
const refFor = (name, wanted) => {
|
|
1563
|
+
let ref = references.find((r) => r.view === wanted);
|
|
1564
|
+
if (!ref) {
|
|
1565
|
+
ref = references.find((r) => r.view === "front");
|
|
1566
|
+
(ref ? substituted : noColumn).push(name);
|
|
1567
|
+
}
|
|
1568
|
+
return ref ? decodeImage(ref.bytes) : undefined;
|
|
1569
|
+
};
|
|
1570
|
+
const compareNames = [...TURNTABLE_VIEWS.map((v) => v.name), "close-up"];
|
|
1571
|
+
compareNames.forEach((name, i) => {
|
|
1572
|
+
const before = i < 4 ? beforeViews[i] : beforeClose;
|
|
1573
|
+
const afters = plan.seasons.map((s) => (i < 4 ? afterBySeason[s][i] : afterClose[s]));
|
|
1574
|
+
const ref = refFor(name, referenceViewFor(name));
|
|
1575
|
+
const height = before.height;
|
|
1576
|
+
artifacts.push({
|
|
1577
|
+
name: `compare-${name}.png`,
|
|
1578
|
+
bytes: encodePng(sideBySide([...(ref ? [ref] : []), before, ...afters], height)),
|
|
1579
|
+
});
|
|
1580
|
+
artifacts.push({ name: `before-${name}.png`, bytes: encodePng(before) });
|
|
1581
|
+
plan.seasons.forEach((s, k) => artifacts.push({ name: `after-${s}-${name}.png`, bytes: encodePng(afters[k]) }));
|
|
1582
|
+
});
|
|
1583
|
+
TURNTABLE_VIEWS.forEach((v, i) => {
|
|
1584
|
+
artifacts.push({ name: `unlit-before-${v.name}.png`, bytes: encodePng(unlitBefore[i]) });
|
|
1585
|
+
artifacts.push({ name: `unlit-after-${v.name}.png`, bytes: encodePng(unlitAfter[i]) });
|
|
1586
|
+
});
|
|
1587
|
+
const views = references.map((r) => r.view);
|
|
1588
|
+
reasons.push({
|
|
1589
|
+
check: "lookdev-compare",
|
|
1590
|
+
passed: noColumn.length === 0,
|
|
1591
|
+
reason: substituted.length === 0 && noColumn.length === 0
|
|
1592
|
+
? "every compare image leads with the matching view of the approved references"
|
|
1593
|
+
: [
|
|
1594
|
+
`the approved references show the view(s) ${views.length > 0 ? [...new Set(views)].join(", ") : "none"}`,
|
|
1595
|
+
...(substituted.length > 0
|
|
1596
|
+
? [`compare-${substituted.join(", compare-")} show(s) the front reference instead`]
|
|
1597
|
+
: []),
|
|
1598
|
+
...(noColumn.length > 0
|
|
1599
|
+
? [`compare-${noColumn.join(", compare-")} have no turnaround column`]
|
|
1600
|
+
: []),
|
|
1601
|
+
].join("; "),
|
|
1602
|
+
source: "deterministic",
|
|
1603
|
+
});
|
|
1604
|
+
// Stage the candidate. Its whole write set is checked first; the per-view renders already written
|
|
1605
|
+
// above (names fixed by Assetgrove) are among the artifacts and are checked with it.
|
|
1606
|
+
checkWrites([
|
|
1607
|
+
...artifacts.map((a) => posix.join(dir, a.name)),
|
|
1608
|
+
...sidecars.map((s) => posix.join(dir, s.name)),
|
|
1609
|
+
`${id}.glb`,
|
|
1610
|
+
]);
|
|
1611
|
+
const artifactNames = [];
|
|
1612
|
+
for (const a of artifacts) {
|
|
1613
|
+
await writeFile(join(runDir, dir, a.name), a.bytes);
|
|
1614
|
+
artifactNames.push(posix.join(dir, a.name));
|
|
1615
|
+
}
|
|
1616
|
+
const stagedSidecars = [];
|
|
1617
|
+
for (const s of sidecars) {
|
|
1618
|
+
const file = posix.join(dir, s.name);
|
|
1619
|
+
await writeFile(join(runDir, file), s.bytes);
|
|
1620
|
+
stagedSidecars.push({
|
|
1621
|
+
file,
|
|
1622
|
+
name: s.name,
|
|
1623
|
+
mediaType: "image/png",
|
|
1624
|
+
sha256: sha256(s.bytes),
|
|
1625
|
+
field: s.field,
|
|
1626
|
+
...(s.extra && { extra: s.extra }),
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
const digitalSourceType = provenance.digitalSourceType && provenance.digitalSourceType !== "undeclared"
|
|
1630
|
+
? provenance.digitalSourceType
|
|
1631
|
+
: (readDigitalSourceType(options.model.bytes, GLB_MEDIA_TYPE) ??
|
|
1632
|
+
DIGITAL_SOURCE_TYPES.generated);
|
|
1633
|
+
const bytes = embedDigitalSourceType(raw, GLB_MEDIA_TYPE, digitalSourceType);
|
|
1634
|
+
const calls = [...provenance.calls, ...caller.records];
|
|
1635
|
+
const outputGrant = grantOf(calls);
|
|
1636
|
+
const parameters = {
|
|
1637
|
+
...provenance.parameters,
|
|
1638
|
+
targetProfileSha256: profileSha256(profile),
|
|
1639
|
+
lookdev: {
|
|
1640
|
+
// The file name only: a local path would leak into the target's public provenance.
|
|
1641
|
+
sourceModel: basename(options.model.path),
|
|
1642
|
+
sourceModelSha256: sourceSha256,
|
|
1643
|
+
views: LOOKDEV_VIEWS,
|
|
1644
|
+
detailViews: LOOKDEV_DETAIL_VIEWS,
|
|
1645
|
+
textureSizePx: textureSize,
|
|
1646
|
+
groomSizePx: groomSize,
|
|
1647
|
+
seasons: plan.seasons,
|
|
1648
|
+
groom: seasonGrooms,
|
|
1649
|
+
eyes: markers.eyes.map((m) => ({
|
|
1650
|
+
point: m.point.map((v) => round(v)),
|
|
1651
|
+
radius: round(m.radius),
|
|
1652
|
+
})),
|
|
1653
|
+
nose: markers.nose.map((m) => ({
|
|
1654
|
+
point: m.point.map((v) => round(v)),
|
|
1655
|
+
radius: round(m.radius),
|
|
1656
|
+
})),
|
|
1657
|
+
padRadiusM: round(padRadius),
|
|
1658
|
+
referenceViews: viewRecord(references),
|
|
1659
|
+
parts,
|
|
1660
|
+
bareTexels: {
|
|
1661
|
+
eyes: bareCounts.eyes,
|
|
1662
|
+
nose: bareCounts.nose,
|
|
1663
|
+
pads: bareCounts["paw pads"],
|
|
1664
|
+
},
|
|
1665
|
+
closestZoom: look.closestZoom,
|
|
1666
|
+
lighting: {
|
|
1667
|
+
ambient: lighting.ambient,
|
|
1668
|
+
key: lighting.key,
|
|
1669
|
+
keyDirection: lighting.keyDirection,
|
|
1670
|
+
exposure: round(lighting.exposure, 4),
|
|
1671
|
+
auto: look.previewLighting.exposure === "auto",
|
|
1672
|
+
litToUnlit,
|
|
1673
|
+
},
|
|
1674
|
+
furSpeckle,
|
|
1675
|
+
markings: markingMeasures.map((m) => ({
|
|
1676
|
+
...m,
|
|
1677
|
+
...(m.deltaE !== undefined && { deltaE: round(m.deltaE, 2) }),
|
|
1678
|
+
})),
|
|
1679
|
+
coverage: round(projection.coverage, 4),
|
|
1680
|
+
uvCoverage: round(projection.uvCoverage, 4),
|
|
1681
|
+
registration: Object.fromEntries(Object.entries(registration).map(([k, o]) => [k, round(o, 4)])),
|
|
1682
|
+
costUsd: round(budget.spentUsd),
|
|
1683
|
+
},
|
|
1684
|
+
};
|
|
1685
|
+
const step = {
|
|
1686
|
+
op: LOOKDEV_STEP,
|
|
1687
|
+
params: {
|
|
1688
|
+
views: LOOKDEV_VIEWS.length + LOOKDEV_DETAIL_VIEWS.length,
|
|
1689
|
+
seasons: plan.seasons,
|
|
1690
|
+
targetProfileSha256: profileSha256(profile),
|
|
1691
|
+
},
|
|
1692
|
+
engine: { name: "assetgrove-lookdev", version: "1" },
|
|
1693
|
+
inputs: [sourceSha256],
|
|
1694
|
+
outputs: [sha256(raw)],
|
|
1695
|
+
};
|
|
1696
|
+
const record = {
|
|
1697
|
+
...provenance,
|
|
1698
|
+
models: [...new Set([...provenance.models, ...caller.records.map((c) => c.model)])],
|
|
1699
|
+
requestIds: [...provenance.requestIds, ...caller.records.map((c) => c.requestId)],
|
|
1700
|
+
providerTerms: [
|
|
1701
|
+
...new Set([
|
|
1702
|
+
...provenance.providerTerms,
|
|
1703
|
+
...caller.records.flatMap((c) => (c.providerTerms !== undefined ? [c.providerTerms] : [])),
|
|
1704
|
+
]),
|
|
1705
|
+
],
|
|
1706
|
+
referenceHashes: [
|
|
1707
|
+
...new Set([...provenance.referenceHashes, ...references.map((r) => r.sha256)]),
|
|
1708
|
+
],
|
|
1709
|
+
parameters,
|
|
1710
|
+
calls,
|
|
1711
|
+
costUsd: round((provenance.costUsd ?? 0) + budget.spentUsd),
|
|
1712
|
+
finishedAt: now().toISOString(),
|
|
1713
|
+
...(outputGrant && { outputGrant }),
|
|
1714
|
+
...(identity && { identity }),
|
|
1715
|
+
...(options.promptPolicy && { promptPolicy: options.promptPolicy }),
|
|
1716
|
+
digitalSourceType,
|
|
1717
|
+
steps: [...(provenance.steps ?? []), step, metadataStep(digitalSourceType, [])],
|
|
1718
|
+
};
|
|
1719
|
+
const p = provenance.parameters;
|
|
1720
|
+
const rigParams = p["rig"];
|
|
1721
|
+
const bodyLengthM = rigParams?.fit?.bodyLengthM;
|
|
1722
|
+
const assetExtras = written.json.asset.extras;
|
|
1723
|
+
const fields = {
|
|
1724
|
+
triangles: measures.triangles,
|
|
1725
|
+
textureMaxPx: measures.textureMaxPx,
|
|
1726
|
+
materials: measures.materials,
|
|
1727
|
+
bones: measures.bones,
|
|
1728
|
+
lods: measures.lods,
|
|
1729
|
+
clips: clips(written).map((c) => {
|
|
1730
|
+
const extras = (written.json.animations?.[c.index]?.["extras"] ?? {});
|
|
1731
|
+
const gait = rig?.gaits[c.name];
|
|
1732
|
+
return {
|
|
1733
|
+
name: c.name,
|
|
1734
|
+
durationMs: Math.round(c.durationS * 1000),
|
|
1735
|
+
loop: extras["loop"] === true,
|
|
1736
|
+
...(extras["generated"] === true && { generated: true }),
|
|
1737
|
+
...(extras["generated"] === true &&
|
|
1738
|
+
gait &&
|
|
1739
|
+
bodyLengthM !== undefined && {
|
|
1740
|
+
speedMps: round(gait.speedBodyLengthsPerSecond * bodyLengthM),
|
|
1741
|
+
}),
|
|
1742
|
+
// A declared motion stays put, as `rig` and `stage` report it.
|
|
1743
|
+
...(extras["generated"] === true && !gait && rig?.motions[c.name] && { speedMps: 0 }),
|
|
1744
|
+
};
|
|
1745
|
+
}),
|
|
1746
|
+
...(p["missingClips"] !== undefined && { missingClips: p["missingClips"] }),
|
|
1747
|
+
bounds: { min: framing.min.map((v) => round(v)), max: framing.max.map((v) => round(v)) },
|
|
1748
|
+
...(assetExtras?.["rig"] !== undefined && { rig: assetExtras["rig"] }),
|
|
1749
|
+
...(p["gait"] !== undefined && { gait: p["gait"] }),
|
|
1750
|
+
...(identity && { identity }),
|
|
1751
|
+
};
|
|
1752
|
+
const passed = qaPassed(reasons);
|
|
1753
|
+
const run = {
|
|
1754
|
+
runId,
|
|
1755
|
+
runDir,
|
|
1756
|
+
...(options.promptPolicy && { promptPolicy: options.promptPolicy }),
|
|
1757
|
+
createdAt: now().toISOString(),
|
|
1758
|
+
spec,
|
|
1759
|
+
specDir: resolve(options.specDir),
|
|
1760
|
+
profile,
|
|
1761
|
+
profileDir: resolve(options.profileDir),
|
|
1762
|
+
bibleVersion: bible.version,
|
|
1763
|
+
capUsd: plan.capUsd,
|
|
1764
|
+
estimateUsd: plan.estimateUsd,
|
|
1765
|
+
spentUsd: round(budget.spentUsd),
|
|
1766
|
+
requested: 1,
|
|
1767
|
+
candidates: [],
|
|
1768
|
+
filtered: passed ? 0 : 1,
|
|
1769
|
+
errors: [],
|
|
1770
|
+
filtering: [markingsState],
|
|
1771
|
+
};
|
|
1772
|
+
if (passed) {
|
|
1773
|
+
const file = `${id}.glb`;
|
|
1774
|
+
await writeFile(join(runDir, file), bytes);
|
|
1775
|
+
run.candidates.push({
|
|
1776
|
+
id,
|
|
1777
|
+
file,
|
|
1778
|
+
mediaType: GLB_MEDIA_TYPE,
|
|
1779
|
+
extension: "glb",
|
|
1780
|
+
sha256: sha256(bytes),
|
|
1781
|
+
reasons,
|
|
1782
|
+
fields,
|
|
1783
|
+
provenance: record,
|
|
1784
|
+
artifacts: artifactNames,
|
|
1785
|
+
sidecars: stagedSidecars,
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
else {
|
|
1789
|
+
run.rejections = [
|
|
1790
|
+
{ candidate: 1, reasons, costUsd: round(budget.spentUsd), artifacts: artifactNames },
|
|
1791
|
+
];
|
|
1792
|
+
}
|
|
1793
|
+
await writeRun(runDir, run);
|
|
1794
|
+
return { run, runDir, passed, plan };
|
|
1795
|
+
}
|