cuju-render 0.1.0__py3-none-any.whl
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.
- cuju/render/__init__.py +759 -0
- cuju/render/__main__.py +1065 -0
- cuju/render/_export/__init__.py +3 -0
- cuju/render/_export/feed.py +542 -0
- cuju/render/_export/sizes.py +157 -0
- cuju/render/_export/video.py +1618 -0
- cuju/render/_export/video_jobs.py +408 -0
- cuju/render/_format/__init__.py +3 -0
- cuju/render/_format/annotations.py +235 -0
- cuju/render/_format/codec.py +307 -0
- cuju/render/_format/keep.py +121 -0
- cuju/render/_format/recording.py +860 -0
- cuju/render/_format/writer.py +54 -0
- cuju/render/_guide/__init__.py +3 -0
- cuju/render/_guide/doctor.py +523 -0
- cuju/render/_guide/help.py +62 -0
- cuju/render/_guide/tutorial.py +254 -0
- cuju/render/_http/__init__.py +3 -0
- cuju/render/_http/commands.py +57 -0
- cuju/render/_http/headers.py +103 -0
- cuju/render/_http/launch.py +500 -0
- cuju/render/_http/launchers.py +408 -0
- cuju/render/_http/pwa.py +128 -0
- cuju/render/_http/server.py +2105 -0
- cuju/render/_http/window.py +360 -0
- cuju/render/_moments/__init__.py +3 -0
- cuju/render/_moments/captions.py +284 -0
- cuju/render/_moments/events.py +1123 -0
- cuju/render/_moments/search.py +694 -0
- cuju/render/_packages/__init__.py +3 -0
- cuju/render/_packages/glsl.py +746 -0
- cuju/render/_packages/loudness.py +334 -0
- cuju/render/_packages/pack.py +1959 -0
- cuju/render/_packages/presentation.py +1376 -0
- cuju/render/_packages/vocabulary.py +609 -0
- cuju/render/_playing/__init__.py +3 -0
- cuju/render/_playing/achievements.py +463 -0
- cuju/render/_playing/bench.py +609 -0
- cuju/render/_playing/challenges.py +1813 -0
- cuju/render/_playing/demo.py +323 -0
- cuju/render/_playing/draw.py +211 -0
- cuju/render/_playing/errors.py +20 -0
- cuju/render/_playing/game.py +645 -0
- cuju/render/_playing/limits.py +339 -0
- cuju/render/_playing/play.py +926 -0
- cuju/render/_playing/policy_worker.py +250 -0
- cuju/render/_playing/strict.py +810 -0
- cuju/render/_registry/__init__.py +3 -0
- cuju/render/_registry/clips.py +394 -0
- cuju/render/_registry/joints.py +108 -0
- cuju/render/_registry/teams.py +2058 -0
- cuju/render/_store/__init__.py +3 -0
- cuju/render/_store/home.py +70 -0
- cuju/render/_store/library.py +604 -0
- cuju/render/_store/samples.py +163 -0
- cuju/render/_text/__init__.py +3 -0
- cuju/render/_text/languages.py +637 -0
- cuju/render/_text/messages.py +1396 -0
- cuju/render/_tournaments/__init__.py +3 -0
- cuju/render/_tournaments/results.py +547 -0
- cuju/render/_tournaments/tournament.py +2742 -0
- cuju/render/_tournaments/tournament_cli.py +587 -0
- cuju/render/_tournaments/tournament_runner.py +1975 -0
- cuju/render/_version.py +6 -0
- cuju/render/_watch/__init__.py +3 -0
- cuju/render/_watch/grid.py +265 -0
- cuju/render/_watch/live.py +664 -0
- cuju/render/_watch/notebook.py +79 -0
- cuju/render/_watch/show.py +171 -0
- cuju/render/samples/sample-11v11.cjr +0 -0
- cuju/render/samples/sample-5v5.cjr +0 -0
- cuju/render/samples/teams/starter/main.py +33 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_easy.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_hard.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_medium.py +46 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_easy.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_hard.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_medium.py +34 -0
- cuju/render/web/assets/adboard_polygon.webp +0 -0
- cuju/render/web/assets/adboard_your_ad_here.webp +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-combatmelee.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-general.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementadvanced.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementbasic.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-simulation.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-special.glb +0 -0
- cuju/render/web/assets/ball.glb +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/corner.mp4 +0 -0
- cuju/render/web/assets/challenges/corner.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.webp +0 -0
- cuju/render/web/assets/challenges/manifest.json +375 -0
- cuju/render/web/assets/challenges/one_on_one.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one.webp +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.webp +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.mp4 +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.webp +0 -0
- cuju/render/web/assets/crowd.webp +0 -0
- cuju/render/web/assets/crowd_normal.webp +0 -0
- cuju/render/web/assets/cuju-logo-384.png +0 -0
- cuju/render/web/assets/cuju-logo.png +0 -0
- cuju/render/web/assets/cuju-logo.svg +46 -0
- cuju/render/web/assets/cuju-mark-light.svg +33 -0
- cuju/render/web/assets/cuju-mark.svg +33 -0
- cuju/render/web/assets/goal.glb +0 -0
- cuju/render/web/assets/grass.webp +0 -0
- cuju/render/web/assets/hair_black.png +0 -0
- cuju/render/web/assets/hair_blonde.png +0 -0
- cuju/render/web/assets/hair_brown.png +0 -0
- cuju/render/web/assets/hair_darkblonde.png +0 -0
- cuju/render/web/assets/hair_long01.glb +0 -0
- cuju/render/web/assets/hair_long02.glb +0 -0
- cuju/render/web/assets/hair_medium01.glb +0 -0
- cuju/render/web/assets/hair_red.png +0 -0
- cuju/render/web/assets/hair_short01.glb +0 -0
- cuju/render/web/assets/hair_short02.glb +0 -0
- cuju/render/web/assets/icons/cuju-192.png +0 -0
- cuju/render/web/assets/icons/cuju-512.png +0 -0
- cuju/render/web/assets/icons/cuju-maskable-512.png +0 -0
- cuju/render/web/assets/kit_goalkeeper.webp +0 -0
- cuju/render/web/assets/kit_mask.png +0 -0
- cuju/render/web/assets/kit_normal.webp +0 -0
- cuju/render/web/assets/manifest.json +601 -0
- cuju/render/web/assets/models/kaykit-barbarian.glb +0 -0
- cuju/render/web/assets/models/kaykit-barbarian.json +23 -0
- cuju/render/web/assets/models/kaykit-knight.glb +0 -0
- cuju/render/web/assets/models/kaykit-knight.json +23 -0
- cuju/render/web/assets/models/kaykit-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.glb +0 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.json +23 -0
- cuju/render/web/assets/models/kaykit-ranger.glb +0 -0
- cuju/render/web/assets/models/kaykit-ranger.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.json +23 -0
- cuju/render/web/assets/pitch.webp +0 -0
- cuju/render/web/assets/pitch_normal.webp +0 -0
- cuju/render/web/assets/player.glb +0 -0
- cuju/render/web/assets/shoe.webp +0 -0
- cuju/render/web/assets/shoe_sole.png +0 -0
- cuju/render/web/assets/skin_01.png +0 -0
- cuju/render/web/assets/skin_02.png +0 -0
- cuju/render/web/assets/skin_03.png +0 -0
- cuju/render/web/assets/skin_04.png +0 -0
- cuju/render/web/assets/sounds/applause.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-1.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-2.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-3.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-4.ogg +0 -0
- cuju/render/web/assets/sounds/city-horn.ogg +0 -0
- cuju/render/web/assets/sounds/city-loop.ogg +0 -0
- cuju/render/web/assets/sounds/city-siren.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-cheer.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-loop.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-ooh.ogg +0 -0
- cuju/render/web/assets/sounds/gulls.ogg +0 -0
- cuju/render/web/assets/sounds/neon-sting.ogg +0 -0
- cuju/render/web/assets/sounds/rain-loop.ogg +0 -0
- cuju/render/web/assets/sounds/sounds.json +46 -0
- cuju/render/web/assets/sounds/space-beep.ogg +0 -0
- cuju/render/web/assets/sounds/space-hum.ogg +0 -0
- cuju/render/web/assets/sounds/space-radio.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-long.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-short.ogg +0 -0
- cuju/render/web/assets/sounds/wind-loop.ogg +0 -0
- cuju/render/web/easy.css +357 -0
- cuju/render/web/export.html +23 -0
- cuju/render/web/feed.css +262 -0
- cuju/render/web/feed.html +28 -0
- cuju/render/web/flat.css +120 -0
- cuju/render/web/home.css +837 -0
- cuju/render/web/index.html +373 -0
- cuju/render/web/js/boot.js +50 -0
- cuju/render/web/js/broadcast/audio.js +2141 -0
- cuju/render/web/js/broadcast/celebrate.js +1238 -0
- cuju/render/web/js/broadcast/decisions.js +609 -0
- cuju/render/web/js/broadcast/hud.js +352 -0
- cuju/render/web/js/broadcast/show.js +3614 -0
- cuju/render/web/js/broadcast/transition.js +2231 -0
- cuju/render/web/js/broadcast/voices.js +153 -0
- cuju/render/web/js/capture.js +101 -0
- cuju/render/web/js/core/accessibility.js +90 -0
- cuju/render/web/js/core/api.js +429 -0
- cuju/render/web/js/core/comfort.js +135 -0
- cuju/render/web/js/core/i18n.js +705 -0
- cuju/render/web/js/core/icons.js +167 -0
- cuju/render/web/js/core/input-settings.js +156 -0
- cuju/render/web/js/core/keys.js +277 -0
- cuju/render/web/js/core/language-ui.js +125 -0
- cuju/render/web/js/core/menu.js +853 -0
- cuju/render/web/js/core/names.js +113 -0
- cuju/render/web/js/core/page-structure.js +110 -0
- cuju/render/web/js/core/scenarios.js +109 -0
- cuju/render/web/js/core/spoilers.js +236 -0
- cuju/render/web/js/core/typeahead.js +38 -0
- cuju/render/web/js/export/dom-picture.js +330 -0
- cuju/render/web/js/export/export-host.js +97 -0
- cuju/render/web/js/export/feed-dialog.js +191 -0
- cuju/render/web/js/export/feed-params.js +266 -0
- cuju/render/web/js/export/feed.js +363 -0
- cuju/render/web/js/export/mp4-mux.js +295 -0
- cuju/render/web/js/export/photo-core.js +313 -0
- cuju/render/web/js/export/photo.js +1314 -0
- cuju/render/web/js/export/safe-frame.js +59 -0
- cuju/render/web/js/export/size-fields.js +103 -0
- cuju/render/web/js/export/sizes.js +178 -0
- cuju/render/web/js/export/video-boot.js +55 -0
- cuju/render/web/js/export/video-browser.js +325 -0
- cuju/render/web/js/export/video-export.js +417 -0
- cuju/render/web/js/export/video-plan.js +207 -0
- cuju/render/web/js/export/video-range.js +185 -0
- cuju/render/web/js/export/webm-mux.js +198 -0
- cuju/render/web/js/feed-boot.js +151 -0
- cuju/render/web/js/feed-frame.js +101 -0
- cuju/render/web/js/help/doctor.js +488 -0
- cuju/render/web/js/help/firstrun.js +379 -0
- cuju/render/web/js/help/help-center.js +438 -0
- cuju/render/web/js/help/install-offer.js +164 -0
- cuju/render/web/js/help/install-state.js +104 -0
- cuju/render/web/js/help/lessons-core.js +207 -0
- cuju/render/web/js/help/lessons.js +463 -0
- cuju/render/web/js/help/palette.js +584 -0
- cuju/render/web/js/help/pwa.js +257 -0
- cuju/render/web/js/help/tour-core.js +241 -0
- cuju/render/web/js/help/tour.js +461 -0
- cuju/render/web/js/main.js +2513 -0
- cuju/render/web/js/pages/draw.js +188 -0
- cuju/render/web/js/pages/fieldpage.js +530 -0
- cuju/render/web/js/pages/home.js +521 -0
- cuju/render/web/js/pages/matches.js +779 -0
- cuju/render/web/js/pages/moments-ui.js +359 -0
- cuju/render/web/js/pages/queue-filters.js +63 -0
- cuju/render/web/js/pages/recording-groups.js +80 -0
- cuju/render/web/js/pages/recordings.js +1069 -0
- cuju/render/web/js/play/bench.js +347 -0
- cuju/render/web/js/play/challenges.js +1302 -0
- cuju/render/web/js/play/medals.js +127 -0
- cuju/render/web/js/play/play.js +1953 -0
- cuju/render/web/js/play/teasers.js +196 -0
- cuju/render/web/js/play/touch.js +350 -0
- cuju/render/web/js/play/tournament-layout.js +487 -0
- cuju/render/web/js/play/tournament-results.js +441 -0
- cuju/render/web/js/play/tournament-strict.js +560 -0
- cuju/render/web/js/play/tournament.js +2585 -0
- cuju/render/web/js/players/animate.js +972 -0
- cuju/render/web/js/players/clips.js +224 -0
- cuju/render/web/js/players/kaykit.js +162 -0
- cuju/render/web/js/players/kits.js +676 -0
- cuju/render/web/js/players/number-patch.js +82 -0
- cuju/render/web/js/players/players.js +2694 -0
- cuju/render/web/js/players/recolor.js +893 -0
- cuju/render/web/js/players/retarget.js +325 -0
- cuju/render/web/js/players/rig-numbers.js +174 -0
- cuju/render/web/js/presentation/animator.js +231 -0
- cuju/render/web/js/presentation/assign.js +85 -0
- cuju/render/web/js/presentation/behaviors.js +440 -0
- cuju/render/web/js/presentation/budget.js +209 -0
- cuju/render/web/js/presentation/catalog.js +1674 -0
- cuju/render/web/js/presentation/clocks.js +72 -0
- cuju/render/web/js/presentation/commands.js +301 -0
- cuju/render/web/js/presentation/contract.js +240 -0
- cuju/render/web/js/presentation/effects.js +904 -0
- cuju/render/web/js/presentation/flash.js +605 -0
- cuju/render/web/js/presentation/freeze-worklet.js +22 -0
- cuju/render/web/js/presentation/glsl.js +464 -0
- cuju/render/web/js/presentation/host.js +323 -0
- cuju/render/web/js/presentation/index.js +2066 -0
- cuju/render/web/js/presentation/loudness-worklet.js +235 -0
- cuju/render/web/js/presentation/loudness.js +740 -0
- cuju/render/web/js/presentation/moments.js +536 -0
- cuju/render/web/js/presentation/post.js +327 -0
- cuju/render/web/js/presentation/preview.js +180 -0
- cuju/render/web/js/presentation/protocol.js +174 -0
- cuju/render/web/js/presentation/reach.js +158 -0
- cuju/render/web/js/presentation/rigging.js +130 -0
- cuju/render/web/js/presentation/sandbox.js +157 -0
- cuju/render/web/js/presentation/shaders.js +235 -0
- cuju/render/web/js/presentation/stage.js +402 -0
- cuju/render/web/js/presentation/teamaudio.js +722 -0
- cuju/render/web/js/presentation/tracks.js +197 -0
- cuju/render/web/js/presentation/values.js +81 -0
- cuju/render/web/js/recording/annotation-data.js +203 -0
- cuju/render/web/js/recording/captions.js +491 -0
- cuju/render/web/js/recording/codec.js +185 -0
- cuju/render/web/js/recording/decode-worker.js +70 -0
- cuju/render/web/js/recording/decode.js +94 -0
- cuju/render/web/js/recording/episodes.js +46 -0
- cuju/render/web/js/recording/format.js +461 -0
- cuju/render/web/js/recording/live.js +348 -0
- cuju/render/web/js/recording/moments-query.js +59 -0
- cuju/render/web/js/recording/moments.js +149 -0
- cuju/render/web/js/recording/pose.js +86 -0
- cuju/render/web/js/recording/timeline.js +275 -0
- cuju/render/web/js/teams/art.js +50 -0
- cuju/render/web/js/teams/clip-editor.js +293 -0
- cuju/render/web/js/teams/editor.js +1979 -0
- cuju/render/web/js/teams/library.js +344 -0
- cuju/render/web/js/teams/painter.js +633 -0
- cuju/render/web/js/teams/surprise-ui.js +195 -0
- cuju/render/web/js/teams/surprise.js +497 -0
- cuju/render/web/js/teams/team-check.js +127 -0
- cuju/render/web/js/watch/annotations.js +270 -0
- cuju/render/web/js/watch/flat.js +366 -0
- cuju/render/web/js/watch/grid.js +436 -0
- cuju/render/web/js/watch/pitch2d.js +289 -0
- cuju/render/web/js/watch/player-tools.js +192 -0
- cuju/render/web/js/watch/presets.js +201 -0
- cuju/render/web/js/world/arenas.js +997 -0
- cuju/render/web/js/world/ball.js +204 -0
- cuju/render/web/js/world/cameras.js +982 -0
- cuju/render/web/js/world/crowd.js +376 -0
- cuju/render/web/js/world/field.js +227 -0
- cuju/render/web/js/world/framing.js +145 -0
- cuju/render/web/js/world/occlusion.js +48 -0
- cuju/render/web/js/world/pitch.js +703 -0
- cuju/render/web/js/world/scene.js +395 -0
- cuju/render/web/js/world/sky.js +325 -0
- cuju/render/web/js/world/stadium.js +1262 -0
- cuju/render/web/js/world/vendor-sky.js +367 -0
- cuju/render/web/js/world/weather.js +264 -0
- cuju/render/web/languages/en.json +4750 -0
- cuju/render/web/lessons.json +137 -0
- cuju/render/web/manifest.webmanifest +23 -0
- cuju/render/web/style.css +8399 -0
- cuju/render/web/sw.js +235 -0
- cuju/render/web/vendor/fabric/LICENSE +16 -0
- cuju/render/web/vendor/fabric/fabric.min.mjs +1 -0
- cuju/render/web/vendor/lucide/LICENSE +43 -0
- cuju/render/web/vendor/lucide/icons.js +141 -0
- cuju/render/web/vendor/three/LICENSE +21 -0
- cuju/render/web/vendor/three/build/three.core.js +60586 -0
- cuju/render/web/vendor/three/build/three.module.js +19719 -0
- cuju/render/web/vendor/three/examples/jsm/loaders/GLTFLoader.js +4925 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/EffectComposer.js +365 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/OutputPass.js +148 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/RenderPass.js +193 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/UnrealBloomPass.js +541 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- cuju/render/web/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1501 -0
- cuju/render/web/vendor/three/examples/jsm/utils/SkeletonUtils.js +496 -0
- cuju_render-0.1.0.dist-info/METADATA +116 -0
- cuju_render-0.1.0.dist-info/RECORD +382 -0
- cuju_render-0.1.0.dist-info/WHEEL +4 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSE +202 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC-BY-4.0.txt +396 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC0-1.0.txt +127 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/ISC.txt +16 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/MIT.txt +24 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/Unlicense.txt +13 -0
- cuju_render-0.1.0.dist-info/licenses/NOTICE +35 -0
|
@@ -0,0 +1,893 @@
|
|
|
1
|
+
// Copyright 2026 The cuju Authors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// The colors present in a model and their replacement. A model's colors come from the base colors
|
|
5
|
+
// of its materials, the texels of its textures that the mesh actually samples, and its vertex
|
|
6
|
+
// colors, each weighted by the surface area that shows it. Textures are cut into regions of
|
|
7
|
+
// smoothly varying texels first, so a gradient cell of an atlas such as KayKit's counts as one
|
|
8
|
+
// color. A replacement shifts every texel of a color by the same step in Lab, which keeps the
|
|
9
|
+
// lightness variation of gradients and shading painted into the texture. Each color also learns
|
|
10
|
+
// the part of the figure it covers from the names of meshes and materials, which gives it the kit
|
|
11
|
+
// color it follows, see assignRoles.
|
|
12
|
+
|
|
13
|
+
import * as THREE from 'three';
|
|
14
|
+
import { fromHex, hex, labToRgb, rgbToLab } from './kits.js';
|
|
15
|
+
|
|
16
|
+
// At most this many colors are listed, the rest stay as they are.
|
|
17
|
+
const MAX_COLORS = 12;
|
|
18
|
+
// Colors closer than this, Euclidean in Lab, are taken as one.
|
|
19
|
+
const MERGE = 10;
|
|
20
|
+
// A color the team names matches the listed color within this distance.
|
|
21
|
+
const MATCH = 14;
|
|
22
|
+
// Neighbor texels closer than this in every channel belong to one region.
|
|
23
|
+
const SMOOTH = 7;
|
|
24
|
+
// A region whose sampled colors spread wider than this is cut up texel by texel.
|
|
25
|
+
const SPREAD = 12;
|
|
26
|
+
// Textures larger than this on a side are read and recolored at this size.
|
|
27
|
+
const MAX_SIDE = 2048;
|
|
28
|
+
// Colors covering less than this share of the surface are not listed.
|
|
29
|
+
const MIN_SHARE = 0.004;
|
|
30
|
+
|
|
31
|
+
const analyses = new WeakMap();
|
|
32
|
+
|
|
33
|
+
function srgbOf(color) {
|
|
34
|
+
const c = color.clone().convertLinearToSRGB();
|
|
35
|
+
return [c.r * 255, c.g * 255, c.b * 255];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function dist2(p, q) {
|
|
39
|
+
const a = p[0] - q[0];
|
|
40
|
+
const b = p[1] - q[1];
|
|
41
|
+
const c = p[2] - q[2];
|
|
42
|
+
return a * a + b * b + c * c;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function imagePixels(image) {
|
|
46
|
+
let w = image.width || image.videoWidth || 0;
|
|
47
|
+
let h = image.height || image.videoHeight || 0;
|
|
48
|
+
if (!w || !h) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const s = Math.min(1, MAX_SIDE / Math.max(w, h));
|
|
52
|
+
w = Math.max(1, Math.round(w * s));
|
|
53
|
+
h = Math.max(1, Math.round(h * s));
|
|
54
|
+
const canvas = document.createElement('canvas');
|
|
55
|
+
canvas.width = w;
|
|
56
|
+
canvas.height = h;
|
|
57
|
+
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
58
|
+
if (image.data && image.width && !image.getContext) {
|
|
59
|
+
// A DataTexture image holds raw RGBA bytes.
|
|
60
|
+
const img = new ImageData(new Uint8ClampedArray(image.data.buffer.slice(0)), image.width, image.height);
|
|
61
|
+
ctx.putImageData(img, 0, 0);
|
|
62
|
+
} else {
|
|
63
|
+
ctx.drawImage(image, 0, 0, w, h);
|
|
64
|
+
}
|
|
65
|
+
return ctx.getImageData(0, 0, w, h);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function find(parent, i) {
|
|
69
|
+
while (parent[i] !== i) {
|
|
70
|
+
parent[i] = parent[parent[i]];
|
|
71
|
+
i = parent[i];
|
|
72
|
+
}
|
|
73
|
+
return i;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Regions of smoothly varying texels by union find over the four neighbors.
|
|
77
|
+
function regions(pixels) {
|
|
78
|
+
const { width: w, height: h, data: d } = pixels;
|
|
79
|
+
const n = w * h;
|
|
80
|
+
const parent = new Int32Array(n);
|
|
81
|
+
for (let i = 0; i < n; i++) {
|
|
82
|
+
parent[i] = i;
|
|
83
|
+
}
|
|
84
|
+
const near = (a, b) => Math.abs(d[a] - d[b]) <= SMOOTH && Math.abs(d[a + 1] - d[b + 1]) <= SMOOTH
|
|
85
|
+
&& Math.abs(d[a + 2] - d[b + 2]) <= SMOOTH;
|
|
86
|
+
const join = (a, b) => {
|
|
87
|
+
const ra = find(parent, a);
|
|
88
|
+
const rb = find(parent, b);
|
|
89
|
+
if (ra !== rb) {
|
|
90
|
+
parent[Math.max(ra, rb)] = Math.min(ra, rb);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
for (let y = 0; y < h; y++) {
|
|
94
|
+
for (let x = 0; x < w; x++) {
|
|
95
|
+
const i = y * w + x;
|
|
96
|
+
if (x + 1 < w && near(i * 4, i * 4 + 4)) {
|
|
97
|
+
join(i, i + 1);
|
|
98
|
+
}
|
|
99
|
+
if (y + 1 < h && near(i * 4, (i + w) * 4)) {
|
|
100
|
+
join(i, i + w);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const label = new Int32Array(n);
|
|
105
|
+
const ids = new Map();
|
|
106
|
+
for (let i = 0; i < n; i++) {
|
|
107
|
+
const r = find(parent, i);
|
|
108
|
+
let id = ids.get(r);
|
|
109
|
+
if (id === undefined) {
|
|
110
|
+
id = ids.size;
|
|
111
|
+
ids.set(r, id);
|
|
112
|
+
}
|
|
113
|
+
label[i] = id;
|
|
114
|
+
}
|
|
115
|
+
return { label, count: ids.size };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// The parts of a figure that a color may cover. Legs split into shorts above and socks below.
|
|
119
|
+
const PARTS = ['shirt', 'legs', 'socks', 'trim', 'head', 'keep'];
|
|
120
|
+
// Names of meshes, materials and nodes that tell the part, the first match wins. KayKit names its
|
|
121
|
+
// meshes Body, ArmLeft, LegLeft, Cape, Head, Hat, Helmet, Eyes and so on, an uploaded model may name
|
|
122
|
+
// its materials shirt, pants or boots.
|
|
123
|
+
const PART_NAMES = [
|
|
124
|
+
['keep', /eye|glow|pupil|iris|teeth|tooth|mouth|tongue|skin|flesh|bone|metal|steel|iron|silver|gold|chrome|blade|sword|weapon/],
|
|
125
|
+
['head', /head|face|skull|jaw|hair|beard|nose/],
|
|
126
|
+
['trim', /hat|helmet|helm|hood|cap\b|crown|visor|mask|cape|cloak|scarf|mantle|quiver|collar|belt|trim/],
|
|
127
|
+
['socks', /boot|shoe|foot|feet|sock|toe|ankle|shin|calf/],
|
|
128
|
+
['legs', /pant|trouser|short|leg|thigh|hip|pelvis|skirt|kilt/],
|
|
129
|
+
['shirt', /shirt|jersey|body|torso|chest|spine|top|tunic|cloth|armou?r|coat|jacket|vest|robe|arm|sleeve|shoulder|hand/],
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
const LEGS = PARTS.indexOf('legs');
|
|
133
|
+
const SOCKS = PARTS.indexOf('socks');
|
|
134
|
+
|
|
135
|
+
function partByName(name) {
|
|
136
|
+
const lower = String(name || '').toLowerCase();
|
|
137
|
+
if (!lower) {
|
|
138
|
+
return -1;
|
|
139
|
+
}
|
|
140
|
+
for (const [part, re] of PART_NAMES) {
|
|
141
|
+
if (re.test(lower)) {
|
|
142
|
+
return PARTS.indexOf(part);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return -1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// The part of a mesh drawn with a material, by the material's name, then the mesh's, then its
|
|
149
|
+
// parents', or -1 when no name tells.
|
|
150
|
+
function partOf(mesh, mat) {
|
|
151
|
+
let p = partByName(mat && mat.name);
|
|
152
|
+
for (let o = mesh; p < 0 && o; o = o.parent) {
|
|
153
|
+
p = partByName(o.name);
|
|
154
|
+
}
|
|
155
|
+
return p;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Visits every triangle of a mesh with its corner indices, its area in world units, its material
|
|
159
|
+
// and the height of its centroid.
|
|
160
|
+
function triangles(mesh, visit) {
|
|
161
|
+
const g = mesh.geometry;
|
|
162
|
+
const pos = g.attributes.position;
|
|
163
|
+
if (!pos) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const index = g.index;
|
|
167
|
+
const count = index ? index.count : pos.count;
|
|
168
|
+
const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
|
|
169
|
+
const groups = g.groups && g.groups.length && Array.isArray(mesh.material) ? g.groups
|
|
170
|
+
: [{ start: 0, count, materialIndex: 0 }];
|
|
171
|
+
const A = new THREE.Vector3();
|
|
172
|
+
const B = new THREE.Vector3();
|
|
173
|
+
const C = new THREE.Vector3();
|
|
174
|
+
const m = mesh.matrixWorld;
|
|
175
|
+
for (const group of groups) {
|
|
176
|
+
const mat = mats[group.materialIndex || 0];
|
|
177
|
+
if (!mat) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const end = Math.min(count, group.start + group.count);
|
|
181
|
+
for (let t = group.start; t + 2 < end; t += 3) {
|
|
182
|
+
const a = index ? index.getX(t) : t;
|
|
183
|
+
const b = index ? index.getX(t + 1) : t + 1;
|
|
184
|
+
const c = index ? index.getX(t + 2) : t + 2;
|
|
185
|
+
A.fromBufferAttribute(pos, a).applyMatrix4(m);
|
|
186
|
+
B.fromBufferAttribute(pos, b).applyMatrix4(m);
|
|
187
|
+
C.fromBufferAttribute(pos, c).applyMatrix4(m);
|
|
188
|
+
const y = (A.y + B.y + C.y) / 3;
|
|
189
|
+
const area = B.sub(A).cross(C.sub(A)).length() / 2;
|
|
190
|
+
if (area > 0) {
|
|
191
|
+
visit(a, b, c, area, mat, y);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Builds the color items of a model, each a Lab color with a weight and where it lives.
|
|
198
|
+
function analyze(rig) {
|
|
199
|
+
const scene = rig.scene;
|
|
200
|
+
scene.updateMatrixWorld(true);
|
|
201
|
+
const textures = new Map();
|
|
202
|
+
const materials = new Map();
|
|
203
|
+
const vertex = new Map();
|
|
204
|
+
const items = [];
|
|
205
|
+
scene.traverse((obj) => {
|
|
206
|
+
if (!obj.isMesh || !obj.geometry) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const g = obj.geometry;
|
|
210
|
+
const uv = g.attributes.uv;
|
|
211
|
+
const colors = g.attributes.color;
|
|
212
|
+
// Legs show shorts on their upper part and socks or boots below, split at 40 percent of
|
|
213
|
+
// the height of the mesh.
|
|
214
|
+
const box = new THREE.Box3().setFromBufferAttribute(g.attributes.position).applyMatrix4(obj.matrixWorld);
|
|
215
|
+
const knee = box.min.y + (box.max.y - box.min.y) * 0.4;
|
|
216
|
+
const parts = new Map();
|
|
217
|
+
triangles(obj, (a, b, c, area, mat, y) => {
|
|
218
|
+
let part = parts.get(mat);
|
|
219
|
+
if (part === undefined) {
|
|
220
|
+
part = partOf(obj, mat);
|
|
221
|
+
parts.set(mat, part);
|
|
222
|
+
}
|
|
223
|
+
if (part === LEGS && y < knee) {
|
|
224
|
+
part = SOCKS;
|
|
225
|
+
}
|
|
226
|
+
if (colors && mat.vertexColors) {
|
|
227
|
+
let v = vertex.get(g);
|
|
228
|
+
if (!v) {
|
|
229
|
+
v = { geometry: g, weights: new Float32Array(colors.count), part: new Int8Array(colors.count).fill(-1) };
|
|
230
|
+
vertex.set(g, v);
|
|
231
|
+
}
|
|
232
|
+
v.weights[a] += area / 3;
|
|
233
|
+
v.weights[b] += area / 3;
|
|
234
|
+
v.weights[c] += area / 3;
|
|
235
|
+
v.part[a] = v.part[b] = v.part[c] = part;
|
|
236
|
+
} else if (mat.map && mat.map.image && uv) {
|
|
237
|
+
let t = textures.get(mat.map);
|
|
238
|
+
if (!t) {
|
|
239
|
+
const pixels = imagePixels(mat.map.image);
|
|
240
|
+
if (!pixels) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
t = { texture: mat.map, pixels, samples: [] };
|
|
244
|
+
textures.set(mat.map, t);
|
|
245
|
+
}
|
|
246
|
+
const u0 = uv.getX(a), v0 = uv.getY(a);
|
|
247
|
+
const u1 = uv.getX(b), v1 = uv.getY(b);
|
|
248
|
+
const u2 = uv.getX(c), v2 = uv.getY(c);
|
|
249
|
+
// The corners, the edge midpoints and the centroid, so a thin strip of UVs and a
|
|
250
|
+
// triangle squeezed to one point both sample what they show.
|
|
251
|
+
const w = area / 7;
|
|
252
|
+
const p = part;
|
|
253
|
+
t.samples.push(u0, v0, w, p, u1, v1, w, p, u2, v2, w, p, (u0 + u1) / 2, (v0 + v1) / 2, w, p,
|
|
254
|
+
(u1 + u2) / 2, (v1 + v2) / 2, w, p, (u0 + u2) / 2, (v0 + v2) / 2, w, p,
|
|
255
|
+
(u0 + u1 + u2) / 3, (v0 + v1 + v2) / 3, w, p);
|
|
256
|
+
} else if (mat.color) {
|
|
257
|
+
let e = materials.get(mat);
|
|
258
|
+
if (!e) {
|
|
259
|
+
e = { material: mat, weight: 0, parts: new Float64Array(PARTS.length) };
|
|
260
|
+
materials.set(mat, e);
|
|
261
|
+
}
|
|
262
|
+
e.weight += area;
|
|
263
|
+
if (part >= 0) {
|
|
264
|
+
e.parts[part] += area;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
for (const e of materials.values()) {
|
|
270
|
+
const lab = rgbToLab(srgbOf(e.material.color));
|
|
271
|
+
items.push({ lab, weight: e.weight, kind: 'material', material: e.material, parts: e.parts });
|
|
272
|
+
}
|
|
273
|
+
for (const t of textures.values()) {
|
|
274
|
+
analyzeTexture(t, items);
|
|
275
|
+
}
|
|
276
|
+
for (const v of vertex.values()) {
|
|
277
|
+
analyzeVertex(v, items);
|
|
278
|
+
}
|
|
279
|
+
return { textures: [...textures.values()], materials: [...materials.values()], vertex: [...vertex.values()], items };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function analyzeTexture(t, items) {
|
|
283
|
+
const { width: w, height: h, data: d } = t.pixels;
|
|
284
|
+
const reg = regions(t.pixels);
|
|
285
|
+
t.regions = reg;
|
|
286
|
+
const sw = new Float64Array(reg.count);
|
|
287
|
+
const sL = new Float64Array(reg.count * 3);
|
|
288
|
+
const sQ = new Float64Array(reg.count);
|
|
289
|
+
const NP = PARTS.length;
|
|
290
|
+
const sP = new Float64Array(reg.count * NP);
|
|
291
|
+
const lab = [0, 0, 0];
|
|
292
|
+
const s = t.samples;
|
|
293
|
+
const wrap = (x) => x - Math.floor(x);
|
|
294
|
+
const texelLab = new Map();
|
|
295
|
+
const labAt = (i) => {
|
|
296
|
+
let c = texelLab.get(i);
|
|
297
|
+
if (!c) {
|
|
298
|
+
c = rgbToLab([d[i * 4], d[i * 4 + 1], d[i * 4 + 2]]);
|
|
299
|
+
texelLab.set(i, c);
|
|
300
|
+
}
|
|
301
|
+
return c;
|
|
302
|
+
};
|
|
303
|
+
for (let k = 0; k < s.length; k += 4) {
|
|
304
|
+
const x = Math.min(w - 1, Math.floor(wrap(s[k]) * w));
|
|
305
|
+
const y = Math.min(h - 1, Math.floor(wrap(s[k + 1]) * h));
|
|
306
|
+
const i = y * w + x;
|
|
307
|
+
const r = reg.label[i];
|
|
308
|
+
const c = labAt(i);
|
|
309
|
+
const wt = s[k + 2];
|
|
310
|
+
sw[r] += wt;
|
|
311
|
+
if (s[k + 3] >= 0) {
|
|
312
|
+
sP[r * NP + s[k + 3]] += wt;
|
|
313
|
+
}
|
|
314
|
+
sL[r * 3] += c[0] * wt;
|
|
315
|
+
sL[r * 3 + 1] += c[1] * wt;
|
|
316
|
+
sL[r * 3 + 2] += c[2] * wt;
|
|
317
|
+
sQ[r] += (c[0] * c[0] * 0.25 + c[1] * c[1] + c[2] * c[2]) * wt;
|
|
318
|
+
}
|
|
319
|
+
t.samples = null;
|
|
320
|
+
t.regionItem = new Int32Array(reg.count).fill(-1);
|
|
321
|
+
t.mixed = new Uint8Array(reg.count);
|
|
322
|
+
const bins = new Map();
|
|
323
|
+
for (let k = 0; k < s.length; k += 4) {
|
|
324
|
+
const x = Math.min(w - 1, Math.floor(wrap(s[k]) * w));
|
|
325
|
+
const y = Math.min(h - 1, Math.floor(wrap(s[k + 1]) * h));
|
|
326
|
+
const i = y * w + x;
|
|
327
|
+
const r = reg.label[i];
|
|
328
|
+
if (!sw[r]) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
const mL = sL[r * 3] / sw[r];
|
|
332
|
+
const ma = sL[r * 3 + 1] / sw[r];
|
|
333
|
+
const mb = sL[r * 3 + 2] / sw[r];
|
|
334
|
+
const variance = sQ[r] / sw[r] - (mL * mL * 0.25 + ma * ma + mb * mb);
|
|
335
|
+
if (variance <= SPREAD * SPREAD) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
// A region of many colors, a photograph or a painted texture, counts texel by texel in
|
|
339
|
+
// bins of Lab.
|
|
340
|
+
t.mixed[r] = 1;
|
|
341
|
+
const c = labAt(i);
|
|
342
|
+
const key = `${Math.round(c[0] / 6)},${Math.round(c[1] / 6)},${Math.round(c[2] / 6)}`;
|
|
343
|
+
let b = bins.get(key);
|
|
344
|
+
if (!b) {
|
|
345
|
+
b = { lab: [0, 0, 0], weight: 0, kind: 'texels', texture: t, parts: new Float64Array(NP) };
|
|
346
|
+
bins.set(key, b);
|
|
347
|
+
}
|
|
348
|
+
b.lab[0] += c[0] * s[k + 2];
|
|
349
|
+
b.lab[1] += c[1] * s[k + 2];
|
|
350
|
+
b.lab[2] += c[2] * s[k + 2];
|
|
351
|
+
b.weight += s[k + 2];
|
|
352
|
+
if (s[k + 3] >= 0) {
|
|
353
|
+
b.parts[s[k + 3]] += s[k + 2];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
for (let r = 0; r < reg.count; r++) {
|
|
357
|
+
if (!sw[r] || t.mixed[r]) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
lab[0] = sL[r * 3] / sw[r];
|
|
361
|
+
lab[1] = sL[r * 3 + 1] / sw[r];
|
|
362
|
+
lab[2] = sL[r * 3 + 2] / sw[r];
|
|
363
|
+
t.regionItem[r] = items.length;
|
|
364
|
+
items.push({ lab: lab.slice(), weight: sw[r], kind: 'region', texture: t, region: r, parts: sP.slice(r * NP, r * NP + NP) });
|
|
365
|
+
}
|
|
366
|
+
for (const b of bins.values()) {
|
|
367
|
+
b.lab = b.lab.map((v) => v / b.weight);
|
|
368
|
+
items.push(b);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function analyzeVertex(v, items) {
|
|
373
|
+
const attr = v.geometry.attributes.color;
|
|
374
|
+
const c = new THREE.Color();
|
|
375
|
+
v.labs = new Float32Array(attr.count * 3);
|
|
376
|
+
const bins = new Map();
|
|
377
|
+
for (let i = 0; i < attr.count; i++) {
|
|
378
|
+
c.setRGB(attr.getX(i), attr.getY(i), attr.getZ(i));
|
|
379
|
+
const lab = rgbToLab(srgbOf(c));
|
|
380
|
+
v.labs.set(lab, i * 3);
|
|
381
|
+
const wt = v.weights[i];
|
|
382
|
+
if (!wt) {
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
const key = `${Math.round(lab[0] / 6)},${Math.round(lab[1] / 6)},${Math.round(lab[2] / 6)}`;
|
|
386
|
+
let b = bins.get(key);
|
|
387
|
+
if (!b) {
|
|
388
|
+
b = { lab: [0, 0, 0], weight: 0, kind: 'vertex', parts: new Float64Array(PARTS.length) };
|
|
389
|
+
bins.set(key, b);
|
|
390
|
+
}
|
|
391
|
+
b.lab[0] += lab[0] * wt;
|
|
392
|
+
b.lab[1] += lab[1] * wt;
|
|
393
|
+
b.lab[2] += lab[2] * wt;
|
|
394
|
+
b.weight += wt;
|
|
395
|
+
if (v.part[i] >= 0) {
|
|
396
|
+
b.parts[v.part[i]] += wt;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
for (const b of bins.values()) {
|
|
400
|
+
b.lab = b.lab.map((x) => x / b.weight);
|
|
401
|
+
items.push(b);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Merges the items greedily, heaviest first, into colors.
|
|
406
|
+
function cluster(items) {
|
|
407
|
+
const order = items.map((_, i) => i).sort((a, b) => items[b].weight - items[a].weight);
|
|
408
|
+
const clusters = [];
|
|
409
|
+
const of = new Int32Array(items.length).fill(-1);
|
|
410
|
+
for (const i of order) {
|
|
411
|
+
const it = items[i];
|
|
412
|
+
let best = -1;
|
|
413
|
+
let bestD = MERGE * MERGE;
|
|
414
|
+
for (let c = 0; c < clusters.length; c++) {
|
|
415
|
+
const d = dist2(clusters[c].lab, it.lab);
|
|
416
|
+
if (d < bestD) {
|
|
417
|
+
bestD = d;
|
|
418
|
+
best = c;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (best < 0) {
|
|
422
|
+
clusters.push({ lab: it.lab.slice(), weight: it.weight });
|
|
423
|
+
of[i] = clusters.length - 1;
|
|
424
|
+
} else {
|
|
425
|
+
const cl = clusters[best];
|
|
426
|
+
const total = cl.weight + it.weight;
|
|
427
|
+
for (let k = 0; k < 3; k++) {
|
|
428
|
+
cl.lab[k] = (cl.lab[k] * cl.weight + it.lab[k] * it.weight) / total;
|
|
429
|
+
}
|
|
430
|
+
cl.weight = total;
|
|
431
|
+
of[i] = best;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return { clusters, of };
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Skin tones, which a team rarely means to recolor, so they never lead as main colors.
|
|
438
|
+
export function skinLike(lab) {
|
|
439
|
+
return lab[0] > 35 && lab[0] < 92 && lab[1] > 8 && lab[1] < 36 && lab[2] > 12 && lab[2] < 42 && lab[2] > lab[1] * 0.7;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// Gray of little chroma, as armor, helmets and blades are painted.
|
|
443
|
+
function metalLike(lab) {
|
|
444
|
+
return Math.hypot(lab[1], lab[2]) < 7 && lab[0] > 30 && lab[0] < 80;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// The kit colors that roles follow.
|
|
448
|
+
export const ROLE_KIT = { shirt: 'primary', trim: 'secondary', shorts: 'shorts', socks: 'socks' };
|
|
449
|
+
const CLOTHING = { shirt: 'shirt', legs: 'shorts', socks: 'socks', trim: 'trim' };
|
|
450
|
+
|
|
451
|
+
// Gives each listed color the kit color it follows, shirt, trim, shorts or socks, by the part of
|
|
452
|
+
// the figure it covers most, or null for a color kept as it is, skin, bone, faces, eyes, hair,
|
|
453
|
+
// metal and small accents. The heaviest color above the legs takes the shirt, so the color that
|
|
454
|
+
// fills most of the figure shows the team, the other colors of the body, capes, hoods and hats
|
|
455
|
+
// the trim, and colors of the legs the shorts and socks. A model whose names tell nothing gives
|
|
456
|
+
// its colors the shirt, shorts, trim and socks by surface share.
|
|
457
|
+
function assignRoles(colors) {
|
|
458
|
+
const byShare = ['shirt', 'shorts', 'trim', 'socks'];
|
|
459
|
+
let unnamed = 0;
|
|
460
|
+
let shirt = false;
|
|
461
|
+
for (const c of [...colors].sort((x, y) => y.weight - x.weight)) {
|
|
462
|
+
const p = c.parts;
|
|
463
|
+
const head = p.head + p.keep;
|
|
464
|
+
const chroma = Math.hypot(c.lab[1], c.lab[2]);
|
|
465
|
+
c.role = null;
|
|
466
|
+
// A strong color on the head is a hood or a hat, a soft one is skin, bone or hair.
|
|
467
|
+
if (c.weight < 0.01 || p.keep >= 0.3 || (head >= 0.2 && (chroma < 30 || c.skin)) || (c.skin && head > 0.03)
|
|
468
|
+
|| metalLike(c.lab)) {
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
let best = null;
|
|
472
|
+
let bestShare = 0.05;
|
|
473
|
+
for (const part of Object.keys(CLOTHING)) {
|
|
474
|
+
if (p[part] > bestShare) {
|
|
475
|
+
bestShare = p[part];
|
|
476
|
+
best = part;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (!best) {
|
|
480
|
+
c.role = unnamed < byShare.length ? byShare[unnamed++] : null;
|
|
481
|
+
} else if (best === 'legs' || best === 'socks') {
|
|
482
|
+
c.role = CLOTHING[best];
|
|
483
|
+
} else {
|
|
484
|
+
c.role = shirt ? 'trim' : 'shirt';
|
|
485
|
+
}
|
|
486
|
+
shirt = shirt || c.role === 'shirt';
|
|
487
|
+
}
|
|
488
|
+
if (!shirt) {
|
|
489
|
+
// A figure dressed only in a cape or a hood shows the shirt color there.
|
|
490
|
+
const first = colors.find((c) => c.role);
|
|
491
|
+
if (first) {
|
|
492
|
+
first.role = 'shirt';
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// The color pairs that dress a model in a kit, each color with a role taking its kit color.
|
|
498
|
+
export function kitPairs(rig, kit) {
|
|
499
|
+
if (!rig || !kit) {
|
|
500
|
+
return {};
|
|
501
|
+
}
|
|
502
|
+
try {
|
|
503
|
+
const out = {};
|
|
504
|
+
for (const c of colorsOf(rig).colors) {
|
|
505
|
+
const target = c.role && kit[ROLE_KIT[c.role]];
|
|
506
|
+
if (target) {
|
|
507
|
+
out[c.hex] = hex(target);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return out;
|
|
511
|
+
} catch (err) {
|
|
512
|
+
console.warn('model colors not read', err);
|
|
513
|
+
return {};
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// The analysis of a rig, made once and kept while the rig lives.
|
|
518
|
+
function colorsOf(rig) {
|
|
519
|
+
let a = analyses.get(rig);
|
|
520
|
+
if (a) {
|
|
521
|
+
return a;
|
|
522
|
+
}
|
|
523
|
+
a = analyze(rig);
|
|
524
|
+
const { clusters, of } = cluster(a.items);
|
|
525
|
+
for (const c of clusters) {
|
|
526
|
+
c.parts = new Float64Array(PARTS.length);
|
|
527
|
+
}
|
|
528
|
+
a.items.forEach((it, i) => {
|
|
529
|
+
if (it.parts && of[i] >= 0) {
|
|
530
|
+
for (let p = 0; p < PARTS.length; p++) {
|
|
531
|
+
clusters[of[i]].parts[p] += it.parts[p];
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
const total = clusters.reduce((s, c) => s + c.weight, 0) || 1;
|
|
536
|
+
const ranked = clusters.map((c, i) => ({ ...c, i })).sort((x, y) => y.weight - x.weight)
|
|
537
|
+
.filter((c, n) => n < MAX_COLORS && c.weight / total >= MIN_SHARE);
|
|
538
|
+
const slot = new Int32Array(clusters.length).fill(-1);
|
|
539
|
+
ranked.forEach((c, n) => {
|
|
540
|
+
slot[c.i] = n;
|
|
541
|
+
});
|
|
542
|
+
// The two heaviest colors that are not skin lead as the main colors, the rest follow by area.
|
|
543
|
+
const main = ranked.filter((c) => !skinLike(c.lab)).slice(0, 2);
|
|
544
|
+
const ordered = [...main, ...ranked.filter((c) => !main.includes(c))];
|
|
545
|
+
a.colors = ordered.map((c) => {
|
|
546
|
+
const rgb = labToRgb(c.lab).map(Math.round);
|
|
547
|
+
const parts = {};
|
|
548
|
+
PARTS.forEach((p, k) => {
|
|
549
|
+
parts[p] = c.weight ? c.parts[k] / c.weight : 0;
|
|
550
|
+
});
|
|
551
|
+
return { hex: hex(rgb), weight: c.weight / total, lab: c.lab, main: main.includes(c), skin: skinLike(c.lab), parts };
|
|
552
|
+
});
|
|
553
|
+
assignRoles(a.colors);
|
|
554
|
+
ordered.forEach((c, n) => {
|
|
555
|
+
slot[c.i] = n;
|
|
556
|
+
});
|
|
557
|
+
a.items.forEach((it, i) => {
|
|
558
|
+
it.slot = slot[of[i]];
|
|
559
|
+
});
|
|
560
|
+
for (const t of a.textures) {
|
|
561
|
+
labelTexels(t, a);
|
|
562
|
+
}
|
|
563
|
+
for (const v of a.vertex) {
|
|
564
|
+
v.slots = new Int16Array(v.labs.length / 3).fill(-1);
|
|
565
|
+
for (let i = 0; i < v.slots.length; i++) {
|
|
566
|
+
v.slots[i] = nearest(a.colors, [v.labs[i * 3], v.labs[i * 3 + 1], v.labs[i * 3 + 2]]);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
analyses.set(rig, a);
|
|
570
|
+
return a;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function nearest(colors, lab, limit = MERGE * 1.5) {
|
|
574
|
+
let best = -1;
|
|
575
|
+
let bestD = limit * limit;
|
|
576
|
+
for (let c = 0; c < colors.length; c++) {
|
|
577
|
+
const d = dist2(colors[c].lab, lab);
|
|
578
|
+
if (d < bestD) {
|
|
579
|
+
bestD = d;
|
|
580
|
+
best = c;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return best;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// Gives every texel the color it belongs to and an index into a table of distinct pairs of texel
|
|
587
|
+
// color and color slot, so a recolor converts each distinct texel color once.
|
|
588
|
+
function labelTexels(t, a) {
|
|
589
|
+
const { width: w, height: h, data: d } = t.pixels;
|
|
590
|
+
const n = w * h;
|
|
591
|
+
const regionSlot = new Int16Array(t.regions.count).fill(-1);
|
|
592
|
+
for (let r = 0; r < t.regions.count; r++) {
|
|
593
|
+
const item = t.regionItem[r];
|
|
594
|
+
if (item >= 0) {
|
|
595
|
+
regionSlot[r] = a.items[item].slot;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const combo = new Int32Array(n).fill(-1);
|
|
599
|
+
const keys = new Map();
|
|
600
|
+
const comboSlot = [];
|
|
601
|
+
const comboRgb = [];
|
|
602
|
+
for (let i = 0; i < n; i++) {
|
|
603
|
+
const r = t.regions.label[i];
|
|
604
|
+
let s = regionSlot[r];
|
|
605
|
+
const rgb = (d[i * 4] << 16) | (d[i * 4 + 1] << 8) | d[i * 4 + 2];
|
|
606
|
+
if (t.mixed[r]) {
|
|
607
|
+
s = -2;
|
|
608
|
+
}
|
|
609
|
+
if (s === -1) {
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
const key = s * 16777216 + rgb;
|
|
613
|
+
let id = keys.get(key);
|
|
614
|
+
if (id === undefined) {
|
|
615
|
+
id = comboSlot.length;
|
|
616
|
+
keys.set(key, id);
|
|
617
|
+
comboSlot.push(s);
|
|
618
|
+
comboRgb.push(rgb);
|
|
619
|
+
}
|
|
620
|
+
combo[i] = id;
|
|
621
|
+
}
|
|
622
|
+
const m = comboSlot.length;
|
|
623
|
+
// Only the labeled texels are visited when recoloring.
|
|
624
|
+
let count = 0;
|
|
625
|
+
for (let i = 0; i < n; i++) {
|
|
626
|
+
if (combo[i] >= 0) {
|
|
627
|
+
count++;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
t.texels = new Int32Array(count);
|
|
631
|
+
t.texelCombo = new Int32Array(count);
|
|
632
|
+
for (let i = 0, j = 0; i < n; i++) {
|
|
633
|
+
if (combo[i] >= 0) {
|
|
634
|
+
t.texels[j] = i;
|
|
635
|
+
t.texelCombo[j++] = combo[i];
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
t.comboSlot = new Int16Array(m);
|
|
639
|
+
t.comboLab = new Float32Array(m * 3);
|
|
640
|
+
for (let c = 0; c < m; c++) {
|
|
641
|
+
const rgb = comboRgb[c];
|
|
642
|
+
const lab = rgbToLab([(rgb >> 16) & 255, (rgb >> 8) & 255, rgb & 255]);
|
|
643
|
+
t.comboLab.set(lab, c * 3);
|
|
644
|
+
// Texels of a mixed region join the nearest listed color, if any is close.
|
|
645
|
+
t.comboSlot[c] = comboSlot[c] === -2 ? nearest(a.colors, lab, MATCH) : comboSlot[c];
|
|
646
|
+
}
|
|
647
|
+
t.regions = null;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// The colors present in a model, each with its hex, its weight, the weights summing to about
|
|
651
|
+
// one, and whether it is a main color or a skin tone. The first two are the model's main colors,
|
|
652
|
+
// its two heaviest that are not skin, and the rest follow heaviest first.
|
|
653
|
+
export function modelColors(rig) {
|
|
654
|
+
if (!rig) {
|
|
655
|
+
return [];
|
|
656
|
+
}
|
|
657
|
+
try {
|
|
658
|
+
return colorsOf(rig).colors.map((c) => ({ hex: c.hex, weight: c.weight, main: c.main, skin: c.skin, role: c.role, parts: { ...c.parts } }));
|
|
659
|
+
} catch (err) {
|
|
660
|
+
console.warn('model colors not read', err);
|
|
661
|
+
return [];
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// The main colors of a model as hex strings, the heaviest first.
|
|
666
|
+
export function mainColors(rig, n = 2) {
|
|
667
|
+
return modelColors(rig).slice(0, n).map((c) => c.hex);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// The Lab step of every listed color for the pairs given, null for colors left alone.
|
|
671
|
+
function steps(a, pairs) {
|
|
672
|
+
const out = new Array(a.colors.length).fill(null);
|
|
673
|
+
for (const [from, to] of Object.entries(pairs || {})) {
|
|
674
|
+
const slot = nearest(a.colors, rgbToLab(fromHex(from)), MATCH);
|
|
675
|
+
if (slot < 0) {
|
|
676
|
+
continue;
|
|
677
|
+
}
|
|
678
|
+
const target = rgbToLab(fromHex(to));
|
|
679
|
+
const c = a.colors[slot].lab;
|
|
680
|
+
out[slot] = [target[0] - c[0], target[1] - c[1], target[2] - c[2]];
|
|
681
|
+
}
|
|
682
|
+
return out;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// The colors of a model as a team shows them, each listed color replaced by its pair.
|
|
686
|
+
export function shownColors(rig, pairs) {
|
|
687
|
+
const a = colorsOf(rig);
|
|
688
|
+
const st = steps(a, pairs);
|
|
689
|
+
return a.colors.map((c, i) => {
|
|
690
|
+
const s = st[i];
|
|
691
|
+
const lab = s ? [c.lab[0] + s[0], c.lab[1] + s[1], c.lab[2] + s[2]] : c.lab;
|
|
692
|
+
return { hex: hex(labToRgb(lab).map(Math.round)), weight: c.weight, lab, main: c.main, skin: c.skin };
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// Recolored materials and textures of one model for one team, shared by every instance of it.
|
|
697
|
+
// Changing the pairs rewrites them in place, so a preview follows a color picker quickly.
|
|
698
|
+
export class Recolor {
|
|
699
|
+
constructor(rig, pairs = {}) {
|
|
700
|
+
this.rig = rig;
|
|
701
|
+
this.analysis = colorsOf(rig);
|
|
702
|
+
this.copies = new Map();
|
|
703
|
+
this.geometries = new Map();
|
|
704
|
+
this.textures = new Map();
|
|
705
|
+
this.instances = [];
|
|
706
|
+
this.pairs = {};
|
|
707
|
+
this.set(pairs);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// Puts the recolored materials on an instance of the rig and remembers it for later changes.
|
|
711
|
+
apply(instance) {
|
|
712
|
+
this.instances.push(instance);
|
|
713
|
+
this.swap(instance.root);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
forget(instance) {
|
|
717
|
+
this.instances = this.instances.filter((i) => i !== instance);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
swap(root) {
|
|
721
|
+
root.traverse((obj) => {
|
|
722
|
+
if (!obj.isMesh) {
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
const pick = (m) => this.copies.get(m) || m;
|
|
726
|
+
obj.material = Array.isArray(obj.material) ? obj.material.map(pick) : pick(obj.material);
|
|
727
|
+
const g = this.geometries.get(obj.geometry);
|
|
728
|
+
if (g) {
|
|
729
|
+
obj.geometry = g;
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
set(pairs) {
|
|
735
|
+
this.pairs = { ...(pairs || {}) };
|
|
736
|
+
const a = this.analysis;
|
|
737
|
+
const st = steps(a, this.pairs);
|
|
738
|
+
const any = st.some((s) => s);
|
|
739
|
+
let added = false;
|
|
740
|
+
const rgb = [0, 0, 0];
|
|
741
|
+
const lab = [0, 0, 0];
|
|
742
|
+
for (const t of a.textures) {
|
|
743
|
+
const touched = st.some((s, i) => s && t.comboSlot.includes(i));
|
|
744
|
+
let tex = this.textures.get(t);
|
|
745
|
+
if (!touched && !tex) {
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
const { width: w, height: h, data: d } = t.pixels;
|
|
749
|
+
if (!tex) {
|
|
750
|
+
tex = new THREE.DataTexture(new Uint8Array(d.length), w, h, THREE.RGBAFormat);
|
|
751
|
+
const src = t.texture;
|
|
752
|
+
tex.colorSpace = src.colorSpace;
|
|
753
|
+
tex.wrapS = src.wrapS;
|
|
754
|
+
tex.wrapT = src.wrapT;
|
|
755
|
+
tex.magFilter = src.magFilter;
|
|
756
|
+
tex.minFilter = src.minFilter;
|
|
757
|
+
tex.anisotropy = src.anisotropy;
|
|
758
|
+
tex.flipY = false;
|
|
759
|
+
tex.generateMipmaps = true;
|
|
760
|
+
tex.channel = src.channel;
|
|
761
|
+
this.textures.set(t, tex);
|
|
762
|
+
added = true;
|
|
763
|
+
}
|
|
764
|
+
const out = tex.image.data;
|
|
765
|
+
out.set(d);
|
|
766
|
+
const m = t.comboSlot.length;
|
|
767
|
+
const packed = new Int32Array(m).fill(-1);
|
|
768
|
+
for (let c = 0; c < m; c++) {
|
|
769
|
+
const s = st[t.comboSlot[c]];
|
|
770
|
+
if (!s) {
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
lab[0] = t.comboLab[c * 3] + s[0];
|
|
774
|
+
lab[1] = t.comboLab[c * 3 + 1] + s[1];
|
|
775
|
+
lab[2] = t.comboLab[c * 3 + 2] + s[2];
|
|
776
|
+
labToRgb(lab, rgb);
|
|
777
|
+
packed[c] = (Math.round(rgb[0]) << 16) | (Math.round(rgb[1]) << 8) | Math.round(rgb[2]);
|
|
778
|
+
}
|
|
779
|
+
const texels = t.texels;
|
|
780
|
+
const combos = t.texelCombo;
|
|
781
|
+
for (let j = 0, n = texels.length; j < n; j++) {
|
|
782
|
+
const p = packed[combos[j]];
|
|
783
|
+
if (p < 0) {
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
const o = texels[j] * 4;
|
|
787
|
+
out[o] = p >> 16;
|
|
788
|
+
out[o + 1] = (p >> 8) & 255;
|
|
789
|
+
out[o + 2] = p & 255;
|
|
790
|
+
}
|
|
791
|
+
tex.needsUpdate = true;
|
|
792
|
+
}
|
|
793
|
+
for (const it of a.items) {
|
|
794
|
+
if (it.kind !== 'material') {
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
const s = it.slot >= 0 ? st[it.slot] : null;
|
|
798
|
+
let copy = this.copies.get(it.material);
|
|
799
|
+
if (!s && !copy) {
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
if (!copy) {
|
|
803
|
+
copy = it.material.clone();
|
|
804
|
+
this.copies.set(it.material, copy);
|
|
805
|
+
added = true;
|
|
806
|
+
}
|
|
807
|
+
const c = s ? labToRgb([it.lab[0] + s[0], it.lab[1] + s[1], it.lab[2] + s[2]]) : srgbOf(it.material.color);
|
|
808
|
+
copy.color.setRGB(c[0] / 255, c[1] / 255, c[2] / 255, THREE.SRGBColorSpace);
|
|
809
|
+
}
|
|
810
|
+
for (const v of a.vertex) {
|
|
811
|
+
const touched = st.some((s, i) => s && v.slots.includes(i));
|
|
812
|
+
let g = this.geometries.get(v.geometry);
|
|
813
|
+
if (!touched && !g) {
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
if (!g) {
|
|
817
|
+
g = v.geometry.clone();
|
|
818
|
+
this.geometries.set(v.geometry, g);
|
|
819
|
+
added = true;
|
|
820
|
+
}
|
|
821
|
+
const attr = g.attributes.color;
|
|
822
|
+
const c = new THREE.Color();
|
|
823
|
+
for (let i = 0; i < v.slots.length; i++) {
|
|
824
|
+
const s = v.slots[i] >= 0 ? st[v.slots[i]] : null;
|
|
825
|
+
if (s) {
|
|
826
|
+
labToRgb([v.labs[i * 3] + s[0], v.labs[i * 3 + 1] + s[1], v.labs[i * 3 + 2] + s[2]], rgb);
|
|
827
|
+
} else {
|
|
828
|
+
labToRgb([v.labs[i * 3], v.labs[i * 3 + 1], v.labs[i * 3 + 2]], rgb);
|
|
829
|
+
}
|
|
830
|
+
c.setRGB(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255, THREE.SRGBColorSpace);
|
|
831
|
+
attr.setXYZ(i, c.r, c.g, c.b);
|
|
832
|
+
}
|
|
833
|
+
attr.needsUpdate = true;
|
|
834
|
+
}
|
|
835
|
+
// Materials that sample a recolored texture take a copy that samples the new one.
|
|
836
|
+
for (const t of a.textures) {
|
|
837
|
+
const tex = this.textures.get(t);
|
|
838
|
+
if (!tex) {
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
this.rig.scene.traverse((obj) => {
|
|
842
|
+
if (!obj.isMesh) {
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
for (const m of [].concat(obj.material)) {
|
|
846
|
+
if (m.map === t.texture && !this.copies.has(m)) {
|
|
847
|
+
const copy = m.clone();
|
|
848
|
+
copy.map = tex;
|
|
849
|
+
this.copies.set(m, copy);
|
|
850
|
+
added = true;
|
|
851
|
+
} else if (m.map === t.texture && this.copies.get(m).map !== tex) {
|
|
852
|
+
this.copies.get(m).map = tex;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
if (added) {
|
|
858
|
+
for (const inst of this.instances) {
|
|
859
|
+
this.swap(inst.root);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
this.active = any;
|
|
863
|
+
return this;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
dispose() {
|
|
867
|
+
for (const m of this.copies.values()) {
|
|
868
|
+
m.dispose();
|
|
869
|
+
}
|
|
870
|
+
for (const t of this.textures.values()) {
|
|
871
|
+
t.dispose();
|
|
872
|
+
}
|
|
873
|
+
for (const g of this.geometries.values()) {
|
|
874
|
+
g.dispose();
|
|
875
|
+
}
|
|
876
|
+
this.copies.clear();
|
|
877
|
+
this.textures.clear();
|
|
878
|
+
this.geometries.clear();
|
|
879
|
+
this.instances = [];
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// Recolors one instance with pairs of its own, for a single figure. The recolor is kept on the
|
|
884
|
+
// instance as instance.recolor, and its dispose frees it.
|
|
885
|
+
export function recolorInstance(rig, instance, pairs) {
|
|
886
|
+
if (instance.recolor) {
|
|
887
|
+
instance.recolor.set(pairs);
|
|
888
|
+
return instance.recolor;
|
|
889
|
+
}
|
|
890
|
+
instance.recolor = new Recolor(rig, pairs);
|
|
891
|
+
instance.recolor.apply(instance);
|
|
892
|
+
return instance.recolor;
|
|
893
|
+
}
|