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,2066 @@
|
|
|
1
|
+
// Copyright 2026 The cuju Authors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// Team presentation packages on the page, as docs/presentation.md describes them. The page calls
|
|
5
|
+
// in at a few places, prepare as it resolves a team, attach once the players are built, update
|
|
6
|
+
// before they are drawn, pose for each player of a package as it is drawn, afterPose once the
|
|
7
|
+
// ball is drawn, afterRender once the picture is drawn, timeScale as the timeline plays, reset
|
|
8
|
+
// after a seek and reveal at the show's fanfares. Everything else of the contract lives in this
|
|
9
|
+
// folder, the effects, shaders, passes, sound, moments and reach of contract 1.1 in modules of
|
|
10
|
+
// their own.
|
|
11
|
+
|
|
12
|
+
import * as THREE from 'three';
|
|
13
|
+
import { NODES_FLOAT, PLAYER_FLOATS, isCut } from '../recording/format.js';
|
|
14
|
+
import { guessJoints, parseModel, rigFromGltf, skinnedBones } from '../players/players.js';
|
|
15
|
+
import { Animator, preferred } from './animator.js';
|
|
16
|
+
import { BehaviourSet, checkBehaviour, emptyOutputs } from './behaviors.js';
|
|
17
|
+
import { Budget, LADDER } from './budget.js';
|
|
18
|
+
import { CONTACT_KINDS, Catalog, contactEstimate } from './catalog.js';
|
|
19
|
+
import { Clocks } from './clocks.js';
|
|
20
|
+
import { SAFETY, checkOverlay, dispatch, dropped, handlerOf, reflexActions, reflexesFor, register } from './commands.js';
|
|
21
|
+
import {
|
|
22
|
+
CONTRACT, FEATURES, driverOf, level, modelOf, normalize, pickClip, roleOf, seed, seedBase, selects,
|
|
23
|
+
} from './contract.js';
|
|
24
|
+
import { evaluate as evaluateCurve } from './values.js';
|
|
25
|
+
import { ModuleHost } from './host.js';
|
|
26
|
+
import { MAXIMUM_COMMANDS, appendLog, checkResponse, frameMessage, helloMessage } from './protocol.js';
|
|
27
|
+
import {
|
|
28
|
+
anchorOf, applyLook, applyOutputs, boneIndex, disposeObject, matches, measure, poseLayers, rootFrame, socketMatrix,
|
|
29
|
+
stopLayers, writeBones,
|
|
30
|
+
} from './stage.js';
|
|
31
|
+
import { Custody, Ledger } from './tracks.js';
|
|
32
|
+
import { clamp, hash, wrap } from './values.js';
|
|
33
|
+
import { Effects } from './effects.js';
|
|
34
|
+
import { FlashCounter, FlashGovernor } from './flash.js';
|
|
35
|
+
import { Moments } from './moments.js';
|
|
36
|
+
import { Post, TEAM_LAYERS } from './post.js';
|
|
37
|
+
import { bendBall, checkGeometry, reachWeight } from './reach.js';
|
|
38
|
+
import { chainOf, maskLayers, reach } from './rigging.js';
|
|
39
|
+
import { checkShader, extendMaterial, shaderMaterial, teamUniforms, tryCompile } from './shaders.js';
|
|
40
|
+
import { TeamAudio } from './teamaudio.js';
|
|
41
|
+
import { SIDES, readSides } from './assign.js';
|
|
42
|
+
import { labelText, t } from '../core/i18n.js';
|
|
43
|
+
|
|
44
|
+
const LINEUP_LENGTH = 9;
|
|
45
|
+
const tmpMatrix = new THREE.Matrix4();
|
|
46
|
+
const tmpVector = new THREE.Vector3();
|
|
47
|
+
|
|
48
|
+
function fileUrl(teamId, file) {
|
|
49
|
+
return `/api/teams/${encodeURIComponent(teamId)}/presentation/${file.split('/').map(encodeURIComponent).join('/')}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function fetchFile(teamId, file, kind = 'arrayBuffer') {
|
|
53
|
+
const res = await fetch(fileUrl(teamId, file), { cache: 'no-store' });
|
|
54
|
+
if (!res.ok) {
|
|
55
|
+
throw new Error(`${file} answered ${res.status}`);
|
|
56
|
+
}
|
|
57
|
+
return res[kind]();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The contact marker of each clip of a glTF file, from extras.cuju.markers of its animations.
|
|
61
|
+
function markersOf(gltf) {
|
|
62
|
+
const out = new Map();
|
|
63
|
+
const json = gltf.parser && gltf.parser.json;
|
|
64
|
+
for (const a of (json && json.animations) || []) {
|
|
65
|
+
const m = a.extras && a.extras.cuju && a.extras.cuju.markers;
|
|
66
|
+
if (a.name && m && Number.isFinite(Number(m.contact))) {
|
|
67
|
+
out.set(a.name, Number(m.contact));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// One team's package as loaded, shared by every rebuild of the players while it stays the same.
|
|
74
|
+
class TeamPackage {
|
|
75
|
+
constructor(side, team, served, manifest, key) {
|
|
76
|
+
this.side = side;
|
|
77
|
+
this.teamId = team.id;
|
|
78
|
+
this.teamModel = team.model || null;
|
|
79
|
+
this.key = key;
|
|
80
|
+
this.served = served;
|
|
81
|
+
this.manifest = manifest;
|
|
82
|
+
this.developer = !!served.developer;
|
|
83
|
+
this.files = new Set(served.files || []);
|
|
84
|
+
this.levels = level(manifest);
|
|
85
|
+
this.budget = new Budget('medium');
|
|
86
|
+
this.rigs = new Map();
|
|
87
|
+
this.markers = new Map();
|
|
88
|
+
this.scenes = new Map();
|
|
89
|
+
this.host = null;
|
|
90
|
+
this.instanceId = null;
|
|
91
|
+
this.status = 'loading';
|
|
92
|
+
this.detail = '';
|
|
93
|
+
this.events = [];
|
|
94
|
+
this.errors = [];
|
|
95
|
+
this.cues = new Map();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async loadModel(file, joints) {
|
|
99
|
+
const gltf = await parseModel(await fetchFile(this.teamId, file));
|
|
100
|
+
let mapping = joints;
|
|
101
|
+
if (!mapping || !mapping.body) {
|
|
102
|
+
const names = skinnedBones(gltf.scene).map((b) => b.name);
|
|
103
|
+
mapping = { ...guessJoints(names), ...(mapping || {}) };
|
|
104
|
+
if (!mapping.body && names.length) {
|
|
105
|
+
mapping.body = names[0];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const rig = rigFromGltf(gltf, mapping, { onlyKit: true });
|
|
109
|
+
this.markers.set(file, markersOf(gltf));
|
|
110
|
+
rig.presentationFile = file;
|
|
111
|
+
return rig;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async load() {
|
|
115
|
+
const m = this.manifest;
|
|
116
|
+
const files = new Set([m.models.outfield, m.models.goalkeeper, ...Object.values(m.models.byNumber || {})].filter(Boolean));
|
|
117
|
+
const joints = m.rig.joints || (this.teamModel && this.teamModel.joints) || null;
|
|
118
|
+
// Each model file parses once, for its attachments and its mesh effects alike.
|
|
119
|
+
const scenes = new Map();
|
|
120
|
+
const sceneOf = (file) => {
|
|
121
|
+
if (!scenes.has(file)) {
|
|
122
|
+
scenes.set(file, fetchFile(this.teamId, file).then(parseModel).then((gltf) => gltf.scene));
|
|
123
|
+
}
|
|
124
|
+
return scenes.get(file);
|
|
125
|
+
};
|
|
126
|
+
const models = [...files].map(async (file) => {
|
|
127
|
+
try {
|
|
128
|
+
this.rigs.set(file, await this.loadModel(file, joints));
|
|
129
|
+
} catch (err) {
|
|
130
|
+
this.errors.push(`model ${file} not used, ${err.message || err}`);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const attachments = Object.entries(m.rig.attachments || {}).map(async ([name, a]) => {
|
|
134
|
+
try {
|
|
135
|
+
this.scenes.set(name, (await sceneOf(a.file)).clone(true));
|
|
136
|
+
} catch (err) {
|
|
137
|
+
this.errors.push(`attachment ${name} not used, ${err.message || err}`);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
// The text of every shader the package names, checked again before anything compiles.
|
|
141
|
+
this.shaders = new Map();
|
|
142
|
+
const sources = new Map();
|
|
143
|
+
for (const look of Object.values(m.materials || {})) {
|
|
144
|
+
if (look && look.shader) {
|
|
145
|
+
sources.set(look.shader, look.mode || 'chunks');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const e of Object.values(m.effects || {})) {
|
|
149
|
+
if (e && e.shader) {
|
|
150
|
+
sources.set(e.shader, 'material');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (m.post && m.post.layer && m.post.layer.shader) {
|
|
154
|
+
sources.set(m.post.layer.shader, 'material');
|
|
155
|
+
}
|
|
156
|
+
const shaders = [...sources].map(async ([file, mode]) => {
|
|
157
|
+
try {
|
|
158
|
+
const text = await fetchFile(this.teamId, file, 'text');
|
|
159
|
+
const problems = checkShader(text, mode);
|
|
160
|
+
if (problems.length) {
|
|
161
|
+
throw new Error(problems.join(', '));
|
|
162
|
+
}
|
|
163
|
+
this.shaders.set(file, text);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
this.errors.push(`shader ${file} not used, ${err.message || err}`);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
this.effectScenes = new Map();
|
|
169
|
+
const meshes = Object.values(m.effects || {}).filter((e) => e && e.type === 'mesh' && e.file).map(async (e) => {
|
|
170
|
+
try {
|
|
171
|
+
this.effectScenes.set(e.file, await sceneOf(e.file));
|
|
172
|
+
} catch (err) {
|
|
173
|
+
this.errors.push(`effect model ${e.file} not used, ${err.message || err}`);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
this.textures = new Map();
|
|
177
|
+
const textures = Object.values(m.materials || {}).flatMap((look) => Object.values((look && look.textures) || {})).map(async (file) => {
|
|
178
|
+
try {
|
|
179
|
+
const bitmap = await createImageBitmap(new Blob([await fetchFile(this.teamId, file)]));
|
|
180
|
+
const t = new THREE.Texture(bitmap);
|
|
181
|
+
t.colorSpace = THREE.SRGBColorSpace;
|
|
182
|
+
t.flipY = false;
|
|
183
|
+
t.needsUpdate = true;
|
|
184
|
+
this.textures.set(file, t);
|
|
185
|
+
} catch (err) {
|
|
186
|
+
this.errors.push(`texture ${file} not used, ${err.message || err}`);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
await Promise.all([...models, ...attachments, ...shaders, ...meshes, ...textures]);
|
|
190
|
+
this.status = 'ready';
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
dispose() {
|
|
194
|
+
this.disposed = true;
|
|
195
|
+
if (this.host) {
|
|
196
|
+
this.host.dispose();
|
|
197
|
+
this.host = null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// The presentation of one player of a package, his stable identity, seeds, behaviours, animator,
|
|
203
|
+
// bounds and attachments.
|
|
204
|
+
class Entity {
|
|
205
|
+
constructor(pkg, entry, header, styles, base) {
|
|
206
|
+
const p = header.players[entry.k];
|
|
207
|
+
const style = styles[p.team] || styles[0];
|
|
208
|
+
const roster = style && style.players ? style.players[p.index] : null;
|
|
209
|
+
this.pkg = pkg;
|
|
210
|
+
this.k = entry.k;
|
|
211
|
+
this.id = `p${entry.k}`;
|
|
212
|
+
this.side = p.team;
|
|
213
|
+
this.index = p.index;
|
|
214
|
+
this.goalkeeper = !!p.goalkeeper;
|
|
215
|
+
this.number = roster && Number.isInteger(roster.number) ? roster.number : p.index + 1;
|
|
216
|
+
this.roster = { name: roster ? roster.name || null : null, number: this.number, goalkeeper: this.goalkeeper, celebration: roster ? roster.celebration || null : null };
|
|
217
|
+
const m = pkg.manifest;
|
|
218
|
+
// GRF's figure plays no clip of a package, so it keeps GRF's own driver.
|
|
219
|
+
this.driver = entry.rig && entry.rig.grf ? 'grf' : driverOf(m, this);
|
|
220
|
+
this.seeds = { entity: seed(base, this.side, this.id), number: hash(`number:${this.number}`), index: hash(`index:${this.index}`) };
|
|
221
|
+
this.envelope = m.rig.bounds ? { radius: m.rig.bounds.radius, height: m.rig.bounds.height } : null;
|
|
222
|
+
this.current = null;
|
|
223
|
+
this.behaviours = new BehaviourSet(this.seeds);
|
|
224
|
+
for (const [i, spec] of m.behaviours.entries()) {
|
|
225
|
+
if (selects(spec.when, this)) {
|
|
226
|
+
try {
|
|
227
|
+
this.behaviours.set(checkBehaviour(spec, i), 'manifest');
|
|
228
|
+
} catch (err) {
|
|
229
|
+
pkg.errors.push(`behaviour ${i} left out, ${err.message}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const rig = entry.rig;
|
|
234
|
+
const markers = pkg.markers.get(rig.presentationFile) || new Map();
|
|
235
|
+
this.animator = this.driver === 'team' || this.driver === 'worker'
|
|
236
|
+
? new Animator(m, (name) => {
|
|
237
|
+
const c = rig.clip(name);
|
|
238
|
+
return c ? { duration: c.duration, marker: markers.get(name) } : null;
|
|
239
|
+
}, this.seeds.entity)
|
|
240
|
+
: null;
|
|
241
|
+
this.cosmetic = new THREE.Matrix4();
|
|
242
|
+
this.frame = new THREE.Matrix4();
|
|
243
|
+
this.anchor = [0, 0, 0];
|
|
244
|
+
this.lastAnchor = null;
|
|
245
|
+
this.ceremonyVelocity = [0, 0, 0];
|
|
246
|
+
this.facing = 0;
|
|
247
|
+
this.inputs = {};
|
|
248
|
+
this.overlay = null;
|
|
249
|
+
this.overlayWeight = 0;
|
|
250
|
+
this.lastOverlay = null;
|
|
251
|
+
this.outputs = emptyOutputs();
|
|
252
|
+
this.attachments = [];
|
|
253
|
+
this.visible = true;
|
|
254
|
+
this.posed = false;
|
|
255
|
+
this.distance = 0;
|
|
256
|
+
this.lastDistance = null;
|
|
257
|
+
// The contacts this player meets, for the reach of his chains.
|
|
258
|
+
this.contacts = [];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
bounds() {
|
|
262
|
+
return this.current || this.envelope;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export class Presentation {
|
|
267
|
+
constructor(app) {
|
|
268
|
+
this.app = app;
|
|
269
|
+
this.clocks = new Clocks();
|
|
270
|
+
this.ledger = new Ledger();
|
|
271
|
+
this.custody = new Custody();
|
|
272
|
+
this.packages = [null, null];
|
|
273
|
+
this.loading = [null, null];
|
|
274
|
+
this.entities = new Map();
|
|
275
|
+
this.epoch = 0;
|
|
276
|
+
this.resetInfo = { reason: 'source', fromT: 0, toT: 0 };
|
|
277
|
+
this.frameId = 0;
|
|
278
|
+
this.instances = 0;
|
|
279
|
+
this.catalog = null;
|
|
280
|
+
this.distances = null;
|
|
281
|
+
this.open = new Map();
|
|
282
|
+
this.memory = {};
|
|
283
|
+
this.lastIndex = -1;
|
|
284
|
+
this.mode = null;
|
|
285
|
+
this.drop = { stale: 0, foreign: 0, malformed: 0, rejected: 0 };
|
|
286
|
+
this.statusShown = new Set();
|
|
287
|
+
// metering false holds every team at its rung, for authors and checks on slow machines.
|
|
288
|
+
// bendBall auto bends the ball's drawn path while a package names bend.ball, true always.
|
|
289
|
+
this.settings = { fullLookahead: false, metering: true, bendBall: 'auto', flashCheck: true };
|
|
290
|
+
this.effects = new Effects(this);
|
|
291
|
+
this.post = new Post(this);
|
|
292
|
+
this.audio = new TeamAudio(this);
|
|
293
|
+
this.moments = new Moments(this);
|
|
294
|
+
this.flash = new FlashGovernor();
|
|
295
|
+
this.counter = new FlashCounter(64, 36);
|
|
296
|
+
this.flashCounts = { general: 0, red: 0 };
|
|
297
|
+
this.uniforms = [teamUniforms(), teamUniforms()];
|
|
298
|
+
this.pulse = [0, 0];
|
|
299
|
+
this.recent = new Map();
|
|
300
|
+
this.geometries = new Map();
|
|
301
|
+
this.materialsBySide = [new Map(), new Map()];
|
|
302
|
+
try {
|
|
303
|
+
this.settings.fullLookahead = JSON.parse(localStorage.getItem('cuju.fullLookahead') || 'false') === true;
|
|
304
|
+
} catch {
|
|
305
|
+
// Storage can be unavailable, the setting then keeps its default.
|
|
306
|
+
}
|
|
307
|
+
// The handlers of every kind of command, the core's and those of contract 1.1.
|
|
308
|
+
register('claims', (c, ctx) => this.claim(ctx.pkg, c));
|
|
309
|
+
register('audio', (c, ctx) => this.audio.command(ctx.pkg, c, ctx.event));
|
|
310
|
+
register('effects', (c, ctx) => this.effects.command(ctx.pkg, c, ctx.event));
|
|
311
|
+
register('camera', (c, ctx) => this.hasFeature(ctx.pkg, 'camera.suggest') && this.moments.suggestCamera(ctx.pkg, c));
|
|
312
|
+
register('time', (c, ctx) => this.hasFeature(ctx.pkg, 'time.suggest') && this.moments.suggestTime(ctx.pkg, c));
|
|
313
|
+
register('environment', (c, ctx) => this.moments.moment(ctx.pkg, c));
|
|
314
|
+
register('overlays', (c, ctx) => this.hasFeature(ctx.pkg, 'overlay.offscreen') && this.moments.overlay(ctx.pkg, c, ctx.bitmap || null));
|
|
315
|
+
register('resources', (c, ctx) => this.resource(ctx.pkg, c));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// The url and the bytes of a file of a package.
|
|
319
|
+
fileUrl(pkg, file) {
|
|
320
|
+
return fileUrl(pkg.teamId, file);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
fetchFile(pkg, file, kind = 'arrayBuffer') {
|
|
324
|
+
return fetchFile(pkg.teamId, file, kind);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Whether a package names a feature among those it requires or prefers, which turns on the
|
|
328
|
+
// parts of contract 1.1 that change shared things.
|
|
329
|
+
hasFeature(pkg, feature) {
|
|
330
|
+
const m = pkg && pkg.manifest;
|
|
331
|
+
return !!m && (m.requires.includes(feature) || m.prefers.includes(feature));
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
sharedUniforms(side) {
|
|
335
|
+
return this.uniforms[side];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
shaderSource(pkg, file) {
|
|
339
|
+
return pkg.shaders ? pkg.shaders.get(file) || null : null;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// A whole shader material of a package, once per file, counted against its shader budget and
|
|
343
|
+
// compiled before it draws. A shader that fails falls back with a notice.
|
|
344
|
+
customMaterial(pkg, file, options = {}) {
|
|
345
|
+
if (!this.hasFeature(pkg, 'shader.custom') || pkg.budget.past('standardMaterials')) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
pkg.customMaterials = pkg.customMaterials || new Map();
|
|
349
|
+
const key = `${file}:${options.blending || 'normal'}`;
|
|
350
|
+
if (pkg.customMaterials.has(key)) {
|
|
351
|
+
return pkg.customMaterials.get(key);
|
|
352
|
+
}
|
|
353
|
+
const source = this.shaderSource(pkg, file);
|
|
354
|
+
let material = null;
|
|
355
|
+
if (source && this.program(pkg, file, 'material')) {
|
|
356
|
+
material = shaderMaterial(source, { shared: this.uniforms[pkg.side], seed: hash(`${pkg.side}:${file}`), ...options });
|
|
357
|
+
if (!tryCompile(this.app.view && this.app.view.renderer, material, this.app.view && this.app.view.camera)) {
|
|
358
|
+
this.notice(t('presentation.notice.shader', { team: pkg.manifest.name || t('presentation.notice.aTeam') }));
|
|
359
|
+
pkg.errors.push(`shader ${file} did not compile`);
|
|
360
|
+
material.dispose();
|
|
361
|
+
material = null;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
pkg.customMaterials.set(key, material);
|
|
365
|
+
return material;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Takes a program of the shader budget for a file and mode once, returns whether it fits.
|
|
369
|
+
program(pkg, file, mode) {
|
|
370
|
+
pkg.programs = pkg.programs || new Set();
|
|
371
|
+
const key = `${file}:${mode}`;
|
|
372
|
+
if (pkg.programs.has(key)) {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
if (!pkg.budget.take({ shaders: 1 })) {
|
|
376
|
+
pkg.errors.push(`shader ${file} is past the team's budget of programs`);
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
pkg.programs.add(key);
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// The flash governor's factor on every team effect now, 1 unless its backstop clamps.
|
|
384
|
+
flashFactor() {
|
|
385
|
+
return this.flash.factor(this.clocks.cosmetic);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// The occlusion rule is relaxed while the ball is dead and in ceremonies.
|
|
389
|
+
relaxed() {
|
|
390
|
+
const tl = this.app.timeline;
|
|
391
|
+
const f = tl && tl.store ? tl.store.get(tl.index) : null;
|
|
392
|
+
return this.clocks.ceremonyStep > 0 || !!(f && f.gameMode !== 0);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Whether the package's team had one of these events within the last seconds of play.
|
|
396
|
+
recentOwn(pkg, kinds, seconds) {
|
|
397
|
+
for (const e of this.recent.values()) {
|
|
398
|
+
if (e.team === pkg.side && kinds.includes(e.kind) && this.clocks.cosmetic - (e.seenAt ?? -Infinity) <= seconds) {
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Where a sound of a package plays from in three's frame, its socket or player, or null.
|
|
406
|
+
audioPosition(pkg, c, event) {
|
|
407
|
+
if (!c.attach || !this.effects.teams[pkg.side]) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
const v = this.effects.resolve(this.effects.teams[pkg.side], { attach: c.attach, event, params: {} }, new THREE.Vector3());
|
|
411
|
+
return v ? { x: v.x, y: v.y, z: v.z } : null;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// The lights of the manifest on this drawing, one for each visible player each selects.
|
|
415
|
+
manifestLights(pkg) {
|
|
416
|
+
const out = [];
|
|
417
|
+
const lights = pkg.manifest.lights || {};
|
|
418
|
+
if (!Object.keys(lights).length) {
|
|
419
|
+
return out;
|
|
420
|
+
}
|
|
421
|
+
for (const entity of this.entities.values()) {
|
|
422
|
+
if (entity.pkg !== pkg || !entity.visible) {
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
const entry = this.entryOf(entity.k);
|
|
426
|
+
for (const [name, l] of Object.entries(lights)) {
|
|
427
|
+
if (!selects(l.when, entity)) {
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
const socket = l.socket !== 'root' ? pkg.manifest.rig.sockets[l.socket] : null;
|
|
431
|
+
if (socket && entry) {
|
|
432
|
+
socketMatrix(entry.rig, entry.instance, socket, entity.cosmetic, tmpMatrix);
|
|
433
|
+
} else {
|
|
434
|
+
tmpMatrix.copy(entity.cosmetic);
|
|
435
|
+
}
|
|
436
|
+
const pos = new THREE.Vector3(...l.offset).applyMatrix4(tmpMatrix);
|
|
437
|
+
let intensity = l.intensity;
|
|
438
|
+
let distance = l.distance;
|
|
439
|
+
for (const o of entity.outputs.lights || []) {
|
|
440
|
+
if (o.light === name) {
|
|
441
|
+
if (o.param === 'distance') {
|
|
442
|
+
distance += (o.value - distance) * o.weight;
|
|
443
|
+
} else {
|
|
444
|
+
intensity += (o.value - intensity) * o.weight;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
out.push({ id: `${entity.id}:${name}`, pos, color: l.color, intensity: Math.max(0, intensity), distance: Math.max(0.5, distance), decay: l.decay, kind: l.kind });
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return out;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// The local lights of a team in the view space of the camera, for its materials.
|
|
455
|
+
setLocalLights(side, list) {
|
|
456
|
+
const u = this.uniforms[side];
|
|
457
|
+
const camera = this.app.view ? this.app.view.camera : null;
|
|
458
|
+
if (!camera) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
camera.updateMatrixWorld();
|
|
462
|
+
const view = camera.matrixWorldInverse;
|
|
463
|
+
for (let i = 0; i < u.cujuLocalPos.value.length; i++) {
|
|
464
|
+
const l = list[i];
|
|
465
|
+
if (l) {
|
|
466
|
+
u.cujuLocalPos.value[i].copy(l.pos).applyMatrix4(view);
|
|
467
|
+
const c = l.color;
|
|
468
|
+
const k = l.level / 4;
|
|
469
|
+
u.cujuLocalColor.value[i].set((c[0] / 255) ** 2.2 * k, (c[1] / 255) ** 2.2 * k, (c[2] / 255) ** 2.2 * k);
|
|
470
|
+
u.cujuLocalRange.value[i] = l.distance;
|
|
471
|
+
} else {
|
|
472
|
+
u.cujuLocalColor.value[i].set(0, 0, 0);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// A resource of a worker, a geometry it built, checked and counted, or the end of one.
|
|
478
|
+
resource(pkg, c) {
|
|
479
|
+
if (c.op === 'dispose') {
|
|
480
|
+
const g = this.geometries.get(`${pkg.side}:${c.id}`);
|
|
481
|
+
if (g) {
|
|
482
|
+
this.dropGeometry(pkg, `${pkg.side}:${c.id}`, g);
|
|
483
|
+
}
|
|
484
|
+
return !!g;
|
|
485
|
+
}
|
|
486
|
+
if (c.op !== 'geometry' || !this.hasFeature(pkg, 'geometry.worker')) {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
let geo;
|
|
490
|
+
try {
|
|
491
|
+
geo = checkGeometry(c);
|
|
492
|
+
} catch (err) {
|
|
493
|
+
pkg.errors.push(`geometry ${c.id} refused, ${err.message}`);
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
const key = `${pkg.side}:${geo.id}`;
|
|
497
|
+
const old = this.geometries.get(key);
|
|
498
|
+
if (old) {
|
|
499
|
+
this.dropGeometry(pkg, key, old);
|
|
500
|
+
}
|
|
501
|
+
if (!pkg.budget.take({ triangles: geo.triangles, geometryBytes: geo.bytes, drawCalls: 1 })) {
|
|
502
|
+
pkg.errors.push(`geometry ${geo.id} is past the team's budget`);
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
const g = new THREE.BufferGeometry();
|
|
506
|
+
g.setAttribute('position', new THREE.BufferAttribute(geo.positions, 3));
|
|
507
|
+
if (geo.normals) {
|
|
508
|
+
g.setAttribute('normal', new THREE.BufferAttribute(geo.normals, 3));
|
|
509
|
+
}
|
|
510
|
+
if (geo.uvs) {
|
|
511
|
+
g.setAttribute('uv', new THREE.BufferAttribute(geo.uvs, 2));
|
|
512
|
+
}
|
|
513
|
+
if (geo.colors) {
|
|
514
|
+
g.setAttribute('color', new THREE.BufferAttribute(geo.colors, geo.colorSize));
|
|
515
|
+
}
|
|
516
|
+
if (geo.indices) {
|
|
517
|
+
g.setIndex(new THREE.BufferAttribute(geo.indices, 1));
|
|
518
|
+
}
|
|
519
|
+
if (!geo.normals) {
|
|
520
|
+
g.computeVertexNormals();
|
|
521
|
+
}
|
|
522
|
+
const spec = c.material && typeof c.material === 'object' ? c.material : {};
|
|
523
|
+
const color = Array.isArray(spec.color) ? spec.color : [220, 220, 220];
|
|
524
|
+
const emissive = Array.isArray(spec.emissive) ? spec.emissive : [0, 0, 0];
|
|
525
|
+
let material = spec.shader ? this.customMaterial(pkg, String(spec.shader)) : null;
|
|
526
|
+
if (material) {
|
|
527
|
+
material = material.clone();
|
|
528
|
+
} else {
|
|
529
|
+
material = new THREE.MeshStandardMaterial({ vertexColors: !!geo.colors, transparent: (spec.opacity ?? 1) < 1, opacity: clamp(Number(spec.opacity ?? 1) || 0, 0, 1) });
|
|
530
|
+
material.color.setRGB(...color.map((x) => clamp(Number(x) || 0, 0, 255) / 255), THREE.SRGBColorSpace);
|
|
531
|
+
material.emissive.setRGB(...emissive.map((x) => clamp(Number(x) || 0, 0, 255) / 255), THREE.SRGBColorSpace);
|
|
532
|
+
}
|
|
533
|
+
const mesh = new THREE.Mesh(g, material);
|
|
534
|
+
mesh.matrixAutoUpdate = false;
|
|
535
|
+
mesh.frustumCulled = false;
|
|
536
|
+
mesh.layers.enable(TEAM_LAYERS[pkg.side]);
|
|
537
|
+
this.app.view.scene.add(mesh);
|
|
538
|
+
this.geometries.set(key, { mesh, attach: c.attach || 'self', entity: c.entity || null, socket: typeof c.attach === 'string' && c.attach.startsWith('socket:') ? c.attach.slice(7) : null, cost: { triangles: geo.triangles, geometryBytes: geo.bytes, drawCalls: 1 }, pkg });
|
|
539
|
+
return true;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
dropGeometry(pkg, key, g) {
|
|
543
|
+
g.mesh.removeFromParent();
|
|
544
|
+
g.mesh.geometry.dispose();
|
|
545
|
+
g.mesh.material.dispose();
|
|
546
|
+
pkg.budget.give(g.cost);
|
|
547
|
+
this.geometries.delete(key);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Loads the package of the team on side, or drops it, while the page resolves the team, and
|
|
551
|
+
// adds the rigs of its models to the team's table of rigs.
|
|
552
|
+
async prepare(side, team, style, table) {
|
|
553
|
+
const read = async (id) => {
|
|
554
|
+
try {
|
|
555
|
+
const res = await fetch(`/api/teams/${encodeURIComponent(id)}/presentation`, { cache: 'no-store' });
|
|
556
|
+
return res.ok ? await res.json() : null;
|
|
557
|
+
} catch {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
// A side may draw the package of a team the viewer chose for it, section Q11. The choice
|
|
562
|
+
// and the playing team's package are read together.
|
|
563
|
+
const [sides, own] = await Promise.all([
|
|
564
|
+
side === 0 || !this.sides ? readSides() : this.sides,
|
|
565
|
+
team && team.id ? read(team.id) : null,
|
|
566
|
+
]);
|
|
567
|
+
this.sides = sides;
|
|
568
|
+
let served = own;
|
|
569
|
+
const chosen = sides[SIDES[side]];
|
|
570
|
+
if (chosen && (!team || team.id !== chosen)) {
|
|
571
|
+
team = { id: chosen, name: team && team.name, model: null, assigned: true };
|
|
572
|
+
served = await read(chosen);
|
|
573
|
+
}
|
|
574
|
+
const manifest = served ? normalize(served.manifest) : null;
|
|
575
|
+
const key = manifest ? `${team.id}:${JSON.stringify(served)}` : null;
|
|
576
|
+
let pkg = this.packages[side];
|
|
577
|
+
if (pkg && (pkg.key !== key || pkg.developer)) {
|
|
578
|
+
pkg.dispose();
|
|
579
|
+
pkg = null;
|
|
580
|
+
this.packages[side] = null;
|
|
581
|
+
}
|
|
582
|
+
if (!pkg && manifest) {
|
|
583
|
+
// Rebuilds that overlap share one load of the same package.
|
|
584
|
+
let pending = this.loading[side];
|
|
585
|
+
if (!pending || pending.key !== key) {
|
|
586
|
+
pending = { key, promise: this.load(side, team, served, manifest, key) };
|
|
587
|
+
this.loading[side] = pending;
|
|
588
|
+
}
|
|
589
|
+
pkg = await pending.promise;
|
|
590
|
+
if (this.loading[side] === pending) {
|
|
591
|
+
this.loading[side] = null;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (this.packages[side] && this.packages[side] !== pkg) {
|
|
595
|
+
this.packages[side].dispose();
|
|
596
|
+
}
|
|
597
|
+
this.packages[side] = pkg || null;
|
|
598
|
+
if (!pkg) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
for (const [file, rig] of pkg.rigs) {
|
|
602
|
+
table.set(`pkg:${file}`, rig);
|
|
603
|
+
}
|
|
604
|
+
style.presentation = { developer: pkg.developer, pkg };
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
async load(side, team, served, manifest, key) {
|
|
608
|
+
const pkg = new TeamPackage(side, team, served, manifest, key);
|
|
609
|
+
if (pkg.levels.level === 'stock') {
|
|
610
|
+
this.notice(t('presentation.notice.stock', { team: team.name || t('presentation.notice.aTeam'), missing: pkg.levels.missing.join(', ') }));
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
await pkg.load();
|
|
614
|
+
for (const w of [...(served.warnings || []), ...pkg.errors]) {
|
|
615
|
+
console.warn(`presentation of ${team.name || team.id}:`, w);
|
|
616
|
+
}
|
|
617
|
+
if (pkg.levels.missing.length) {
|
|
618
|
+
this.notice(t('presentation.notice.noWorker', { team: team.name || t('presentation.notice.aTeam'), missing: pkg.levels.missing.join(', ') }));
|
|
619
|
+
}
|
|
620
|
+
return pkg;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// A notice for people, as a text or as the id and values of a message, which a module that
|
|
624
|
+
// loads without the page's messages sends.
|
|
625
|
+
notice(text) {
|
|
626
|
+
if (text && typeof text === 'object') {
|
|
627
|
+
text = t(text.id, text.values);
|
|
628
|
+
}
|
|
629
|
+
if (!this.statusShown.has(text)) {
|
|
630
|
+
this.statusShown.add(text);
|
|
631
|
+
if (this.app.hud) {
|
|
632
|
+
this.app.hud.toast(text, 'info', 4000);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// The model a header player draws by his team's package, or null for the team's choice.
|
|
638
|
+
modelFor(p, style) {
|
|
639
|
+
const pkg = style && style.presentation ? style.presentation.pkg : null;
|
|
640
|
+
if (!pkg) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
const roster = style.players ? style.players[p.index] : null;
|
|
644
|
+
const number = roster && Number.isInteger(roster.number) ? roster.number : p.index + 1;
|
|
645
|
+
const file = modelOf(pkg.manifest, { goalkeeper: !!p.goalkeeper, number, index: p.index });
|
|
646
|
+
return file && pkg.rigs.has(file) ? `pkg:${file}` : null;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// Builds the presentation of every player of a package once the page built its players.
|
|
650
|
+
attach(players, header, styles) {
|
|
651
|
+
this.players = players;
|
|
652
|
+
this.header = header;
|
|
653
|
+
this.styles = styles;
|
|
654
|
+
this.entities.clear();
|
|
655
|
+
this.base = seedBase(header);
|
|
656
|
+
const tl = this.app.timeline;
|
|
657
|
+
const any = !!(this.packages[0] || this.packages[1]);
|
|
658
|
+
this.catalog = tl && any ? new Catalog(tl.store, { fullLookahead: this.settings.fullLookahead, live: !!tl.live }) : null;
|
|
659
|
+
this.distances = new Map();
|
|
660
|
+
this.ledger = new Ledger();
|
|
661
|
+
this.custody.reset();
|
|
662
|
+
this.open.clear();
|
|
663
|
+
this.memory = {};
|
|
664
|
+
this.lastIndex = -1;
|
|
665
|
+
this.newEpoch('source');
|
|
666
|
+
const quality = this.app.settings ? this.app.settings.quality : 'medium';
|
|
667
|
+
for (const pkg of this.packages) {
|
|
668
|
+
if (pkg) {
|
|
669
|
+
pkg.budget.setQuality(quality);
|
|
670
|
+
pkg.budget.used = Object.fromEntries(Object.keys(pkg.budget.used).map((k) => [k, 0]));
|
|
671
|
+
pkg.programs = new Set();
|
|
672
|
+
this.startWorker(pkg);
|
|
673
|
+
// The meter reads the package once it settled, after its worker's first answer,
|
|
674
|
+
// or a second after the players were built for a package without a worker, so
|
|
675
|
+
// the page's own loading never counts against the team.
|
|
676
|
+
pkg.budget.arm(pkg.host || pkg.hostPending ? Infinity : this.clocks.cosmetic + 1);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const entries = players.packageEntries ? players.packageEntries() : [];
|
|
680
|
+
for (const { entry: e, group } of entries) {
|
|
681
|
+
const pkg = this.packages[e.team];
|
|
682
|
+
if (!pkg) {
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
const entity = new Entity(pkg, e, header, styles, this.base);
|
|
686
|
+
e.presentation = entity;
|
|
687
|
+
this.entities.set(entity.id, entity);
|
|
688
|
+
this.dress(pkg, entity, e, group);
|
|
689
|
+
this.emit({ kind: 'appearance', team: entity.side, player: entity.k, data: { player: entity.k } });
|
|
690
|
+
}
|
|
691
|
+
for (const pkg of this.packages) {
|
|
692
|
+
if (pkg && pkg.developer) {
|
|
693
|
+
this.notice(t('presentation.notice.developer', { team: pkg.manifest.name || t('presentation.notice.aTeam') }));
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
for (const [key, g] of this.geometries) {
|
|
697
|
+
this.dropGeometry(g.pkg, key, g);
|
|
698
|
+
}
|
|
699
|
+
this.moments.end();
|
|
700
|
+
this.moments.disposeSlots();
|
|
701
|
+
if (this.app.view) {
|
|
702
|
+
this.effects.attach(this.app.view.scene, this.packages);
|
|
703
|
+
for (const team of this.effects.teams) {
|
|
704
|
+
if (team) {
|
|
705
|
+
team.group.traverse((o) => o.layers.enable(TEAM_LAYERS[team.side]));
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
this.post.attach(this.packages);
|
|
710
|
+
this.audio.attach(this.packages);
|
|
711
|
+
styles.forEach((style, side) => {
|
|
712
|
+
const kit = style && style.kit;
|
|
713
|
+
if (kit && Array.isArray(kit.primary)) {
|
|
714
|
+
this.uniforms[side].uTeamColor.value.setRGB(...kit.primary.map((c) => c / 255), THREE.SRGBColorSpace);
|
|
715
|
+
}
|
|
716
|
+
if (kit && Array.isArray(kit.secondary)) {
|
|
717
|
+
this.uniforms[side].uTeamColor2.value.setRGB(...kit.secondary.map((c) => c / 255), THREE.SRGBColorSpace);
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// What the page draws of player k for a package, the entry of his rigged model or of GRF's
|
|
723
|
+
// figure, or null.
|
|
724
|
+
entryOf(k) {
|
|
725
|
+
return this.players && this.players.packageEntry ? this.players.packageEntry(k) : null;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// A player's look, the material looks that select him, his shaders and his attachments.
|
|
729
|
+
dress(pkg, entity, e, parent) {
|
|
730
|
+
for (const [name, look] of Object.entries(pkg.manifest.materials)) {
|
|
731
|
+
if (look && Array.isArray(look.rules) && selects(look.when, entity)) {
|
|
732
|
+
applyLook(e.instance, look.rules);
|
|
733
|
+
} else if (look && !look.rules && selects(look.when, entity)) {
|
|
734
|
+
applyLook(e.instance, [{ match: look.match || name, ...look }]);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
this.shade(pkg, entity, e.instance, e.rig);
|
|
738
|
+
e.instance.root.traverse((o) => o.layers.enable(TEAM_LAYERS[pkg.side]));
|
|
739
|
+
for (const [name, spec] of Object.entries(pkg.manifest.rig.attachments || {})) {
|
|
740
|
+
const scene = pkg.scenes.get(name);
|
|
741
|
+
if (!scene || !selects(spec.when, entity)) {
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
const object = scene.clone(true);
|
|
745
|
+
const cost = measure(object);
|
|
746
|
+
if (!pkg.budget.take({ drawCalls: cost.drawCalls, triangles: cost.triangles, textureBytes: cost.textureBytes })) {
|
|
747
|
+
pkg.errors.push(`attachment ${name} is past the team's budget`);
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
object.matrixAutoUpdate = false;
|
|
751
|
+
object.traverse((obj) => {
|
|
752
|
+
obj.layers.enable(TEAM_LAYERS[pkg.side]);
|
|
753
|
+
if (obj.isMesh) {
|
|
754
|
+
obj.castShadow = spec.shadows !== false;
|
|
755
|
+
obj.receiveShadow = spec.shadows !== false;
|
|
756
|
+
obj.frustumCulled = false;
|
|
757
|
+
// Each attachment owns its materials, which behaviours may drive.
|
|
758
|
+
obj.material = Array.isArray(obj.material) ? obj.material.map((m) => m.clone()) : obj.material.clone();
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
this.shade(pkg, entity, { root: object, materials: [] }, null);
|
|
762
|
+
parent.add(object);
|
|
763
|
+
const r = (spec.rotation || [0, 0, 0]).map((d) => d * Math.PI / 180);
|
|
764
|
+
const s = spec.scale || 1;
|
|
765
|
+
const local = new THREE.Matrix4().compose(new THREE.Vector3(...(spec.offset || [0, 0, 0])), new THREE.Quaternion().setFromEuler(new THREE.Euler(...r)), new THREE.Vector3(s, s, s));
|
|
766
|
+
entity.attachments.push({ name, object, socket: spec.socket || 'root', local, cost });
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// Gives the standard materials of an instance the team's chunk, the hooks of its chunks
|
|
771
|
+
// shaders and its local lights, on copies the instance owns, kept beside the originals so the
|
|
772
|
+
// degrade ladder can hand back the standard look.
|
|
773
|
+
shade(pkg, entity, instance, rig) {
|
|
774
|
+
const m = pkg.manifest;
|
|
775
|
+
const lights = Object.values(m.lights || {}).length > 0 || Object.values(m.effects || {}).some((x) => x.type === 'light');
|
|
776
|
+
const looks = Object.entries(m.materials || {}).filter(([, look]) => look && look.shader && (look.mode || 'chunks') === 'chunks' && selects(look.when, entity));
|
|
777
|
+
const custom = this.hasFeature(pkg, 'shader.custom') && !pkg.budget.past('standardMaterials');
|
|
778
|
+
if (!lights && !(custom && looks.length)) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
const originals = instance.cujuOriginals || (instance.cujuOriginals = []);
|
|
782
|
+
instance.root.traverse((obj) => {
|
|
783
|
+
if (!obj.isMesh) {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
const swap = (mat) => {
|
|
787
|
+
if (!mat || !mat.isMeshStandardMaterial || (mat.userData && mat.userData.cuju)) {
|
|
788
|
+
return mat;
|
|
789
|
+
}
|
|
790
|
+
let hit = custom ? looks.find(([name, look]) => matches({ match: look.match || name }, mat.name)) : null;
|
|
791
|
+
let source = hit ? this.shaderSource(pkg, hit[1].shader) : null;
|
|
792
|
+
if (hit && source && !this.program(pkg, hit[1].shader, 'chunks')) {
|
|
793
|
+
return mat;
|
|
794
|
+
}
|
|
795
|
+
const textures = hit ? Object.fromEntries(Object.entries(hit[1].textures || {}).map(([k, f]) => [k, pkg.textures && pkg.textures.get(f)]).filter(([, t]) => t)) : null;
|
|
796
|
+
const options = () => ({
|
|
797
|
+
shared: this.uniforms[pkg.side], seed: entity.seeds.entity, source,
|
|
798
|
+
spec: hit ? { ...hit[1], seeds: entity.seeds } : null, textures, key: hit ? `${pkg.side}:${hit[1].shader}` : `${pkg.side}:local`,
|
|
799
|
+
});
|
|
800
|
+
// A chunks shader that does not compile leaves the material standard, with only
|
|
801
|
+
// the local lights when the package has lights, and the page names it once.
|
|
802
|
+
if (hit && source && !this.chunksCompile(pkg, hit[1].shader, mat, options())) {
|
|
803
|
+
hit = null;
|
|
804
|
+
source = null;
|
|
805
|
+
if (!lights) {
|
|
806
|
+
return mat;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
const copy = extendMaterial(mat, options());
|
|
810
|
+
// GRF's figure keeps its own edit of the program, the head it hides.
|
|
811
|
+
if (instance.repatch) {
|
|
812
|
+
instance.repatch(mat, copy);
|
|
813
|
+
}
|
|
814
|
+
originals.push({ obj, original: mat, copy });
|
|
815
|
+
if (instance.materials) {
|
|
816
|
+
instance.materials.push(copy);
|
|
817
|
+
}
|
|
818
|
+
this.materialsBySide[pkg.side].set(copy, entity);
|
|
819
|
+
return copy;
|
|
820
|
+
};
|
|
821
|
+
obj.material = Array.isArray(obj.material) ? obj.material.map(swap) : swap(obj.material);
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// Whether a chunks shader of a package compiles, tried once for each file on a copy of the
|
|
826
|
+
// first material it extends. A shader that fails is named in a notice and in the package's
|
|
827
|
+
// errors, and the materials it would extend stay standard.
|
|
828
|
+
chunksCompile(pkg, file, material, options) {
|
|
829
|
+
pkg.chunksCompiled = pkg.chunksCompiled || new Map();
|
|
830
|
+
if (!pkg.chunksCompiled.has(file)) {
|
|
831
|
+
const copy = extendMaterial(material, options);
|
|
832
|
+
const view = this.app.view;
|
|
833
|
+
const logs = [];
|
|
834
|
+
const ok = tryCompile(view && view.renderer, copy, view && view.camera, null, logs);
|
|
835
|
+
copy.dispose();
|
|
836
|
+
if (!ok) {
|
|
837
|
+
this.notice(t('presentation.notice.shader', { team: pkg.manifest.name || t('presentation.notice.aTeam') }));
|
|
838
|
+
pkg.errors.push(`shader ${file} did not compile`);
|
|
839
|
+
console.warn(`presentation of ${pkg.manifest.name || pkg.teamId}: shader ${file} did not compile`, ...logs);
|
|
840
|
+
}
|
|
841
|
+
pkg.chunksCompiled.set(file, ok);
|
|
842
|
+
}
|
|
843
|
+
return pkg.chunksCompiled.get(file);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
// Hands the standard materials back to every player of a package, the ladder's rung
|
|
847
|
+
// standardMaterials.
|
|
848
|
+
unshade(pkg) {
|
|
849
|
+
for (const entity of this.entities.values()) {
|
|
850
|
+
if (entity.pkg !== pkg) {
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
const entry = this.entryOf(entity.k);
|
|
854
|
+
for (const o of (entry && entry.instance.cujuOriginals) || []) {
|
|
855
|
+
o.obj.material = Array.isArray(o.obj.material) ? o.obj.material.map((m) => (m === o.copy ? o.original : m)) : (o.obj.material === o.copy ? o.original : o.obj.material);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// Gives the package's own materials back to every player of a package, as the ladder climbs
|
|
861
|
+
// back past standardMaterials.
|
|
862
|
+
reshade(pkg) {
|
|
863
|
+
for (const entity of this.entities.values()) {
|
|
864
|
+
if (entity.pkg !== pkg) {
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
const entry = this.entryOf(entity.k);
|
|
868
|
+
for (const o of (entry && entry.instance.cujuOriginals) || []) {
|
|
869
|
+
o.obj.material = Array.isArray(o.obj.material) ? o.obj.material.map((m) => (m === o.original ? o.copy : m)) : (o.obj.material === o.original ? o.copy : o.obj.material);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
startWorker(pkg) {
|
|
875
|
+
const m = pkg.manifest;
|
|
876
|
+
if (!m.worker || pkg.levels.level !== 'worker' || pkg.budget.past('noWorker') || ((pkg.host || pkg.hostPending) && !pkg.developer)) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
if (pkg.host) {
|
|
880
|
+
pkg.host.dispose();
|
|
881
|
+
pkg.host = null;
|
|
882
|
+
}
|
|
883
|
+
// Only the newest start of a package creates its host, an older one that resolves late
|
|
884
|
+
// leaves it alone.
|
|
885
|
+
const token = (pkg.starting || 0) + 1;
|
|
886
|
+
pkg.starting = token;
|
|
887
|
+
pkg.hostPending = true;
|
|
888
|
+
this.instances += 1;
|
|
889
|
+
pkg.instanceId = `${pkg.side}.${this.instances}`;
|
|
890
|
+
pkg.events = [];
|
|
891
|
+
const start = (source) => {
|
|
892
|
+
if (pkg.starting !== token || pkg.disposed) {
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
pkg.hostPending = false;
|
|
896
|
+
pkg.host = new ModuleHost({
|
|
897
|
+
source,
|
|
898
|
+
url: fileUrl(pkg.teamId, m.worker),
|
|
899
|
+
instanceId: pkg.instanceId,
|
|
900
|
+
developer: pkg.developer,
|
|
901
|
+
context: pkg.developer ? { app: this.app, THREE } : null,
|
|
902
|
+
hello: this.hello(pkg),
|
|
903
|
+
onResponse: (msg) => this.respond(pkg, msg),
|
|
904
|
+
onStatus: (status, detail, label) => this.workerStatus(pkg, status, detail, label),
|
|
905
|
+
});
|
|
906
|
+
};
|
|
907
|
+
if (pkg.developer) {
|
|
908
|
+
start(null);
|
|
909
|
+
} else {
|
|
910
|
+
fetchFile(pkg.teamId, m.worker, 'text').then(start).catch((err) => {
|
|
911
|
+
pkg.hostPending = false;
|
|
912
|
+
const detail = `the worker did not load, ${err.message}`;
|
|
913
|
+
this.workerStatus(pkg, 'failed', detail, { id: 'presentation.reason.load', text: detail, values: { error: String(err.message) } });
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
hello(pkg) {
|
|
919
|
+
const header = this.header;
|
|
920
|
+
const style = this.styles ? this.styles[pkg.side] : null;
|
|
921
|
+
return helloMessage({
|
|
922
|
+
features: Object.keys(FEATURES), lacking: pkg.levels.lacking, limits: pkg.budget.limits, quality: pkg.budget.quality,
|
|
923
|
+
reducedMotion: !!this.app.reducedMotion, instanceId: pkg.instanceId, team: pkg.side, attack: pkg.side === 0 ? 1 : -1,
|
|
924
|
+
roster: header.players.map((p, k) => ({ player: k, team: p.team, index: p.index, goalkeeper: !!p.goalkeeper }))
|
|
925
|
+
.filter((p) => p.team === pkg.side).map((p) => ({ ...p, ...(style && style.players && style.players[p.index] ? { name: style.players[p.index].name, number: style.players[p.index].number } : {}) })),
|
|
926
|
+
header: { format: header.players.length > 10 ? '11v11' : '5v5', scenario: header.scenario || null, sps: header.steps_per_second || 10, provenance: header.provenance || null },
|
|
927
|
+
seedBase: this.base,
|
|
928
|
+
slots: Object.keys(pkg.manifest.overlays || {}),
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// A worker that failed or restarts hands what it drove back to the manifest's own look,
|
|
933
|
+
// faded so nothing snaps.
|
|
934
|
+
workerStatus(pkg, status, detail, label = null) {
|
|
935
|
+
// A worker that failed for good keeps its status and reason, a later disposal included.
|
|
936
|
+
if (pkg.status === 'failed') {
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
pkg.status = status;
|
|
940
|
+
pkg.detail = detail;
|
|
941
|
+
if (status === 'failed') {
|
|
942
|
+
// The team draws its manifest alone from now on, and the viewer learns why.
|
|
943
|
+
pkg.levels.level = pkg.levels.level === 'stock' ? 'stock' : 'manifest';
|
|
944
|
+
// The viewer reads the reason in the page's language, the English one stays in detail.
|
|
945
|
+
const reason = label ? labelText(label) : detail;
|
|
946
|
+
this.notice(t('presentation.notice.workerStopped', { team: pkg.manifest.name || t('presentation.notice.aTeam'), detail: reason }));
|
|
947
|
+
}
|
|
948
|
+
if (status === 'stopped') {
|
|
949
|
+
this.notice(t('presentation.notice.workerResting', { team: pkg.manifest.name || t('presentation.notice.aTeam') }));
|
|
950
|
+
}
|
|
951
|
+
if (status === 'failed' || status === 'stopped') {
|
|
952
|
+
// The meter goes on reading the package without its worker.
|
|
953
|
+
pkg.budget.armAt = Math.min(pkg.budget.armAt, this.clocks.cosmetic + 1);
|
|
954
|
+
}
|
|
955
|
+
if (status === 'restarting' || status === 'failed' || status === 'stopped') {
|
|
956
|
+
console.warn(`presentation worker of ${pkg.manifest.name || pkg.teamId} ${status}, ${detail}`);
|
|
957
|
+
for (const entity of this.entities.values()) {
|
|
958
|
+
if (entity.pkg === pkg) {
|
|
959
|
+
entity.behaviours.stopSource('worker', 0.5);
|
|
960
|
+
entity.current = null;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
this.ledger.dropSource(`worker:${pkg.side}`);
|
|
964
|
+
if (status === 'failed') {
|
|
965
|
+
pkg.budget.stopWorker(detail);
|
|
966
|
+
}
|
|
967
|
+
this.newEpoch('package', false);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// A new epoch for a reason. Transient effects die, tracks and persistent behaviours survive.
|
|
972
|
+
newEpoch(reason, catalog = true) {
|
|
973
|
+
this.epoch += 1;
|
|
974
|
+
const t = this.app.timeline ? this.app.timeline.t / (this.app.timeline.sps || 10) : 0;
|
|
975
|
+
this.resetInfo = { reason, fromT: this.clocks.sim, toT: t };
|
|
976
|
+
this.resetPending = true;
|
|
977
|
+
if (catalog && this.catalog && reason !== 'source') {
|
|
978
|
+
this.pushEvents(this.catalog.reset(reason));
|
|
979
|
+
}
|
|
980
|
+
this.custody.reset();
|
|
981
|
+
for (const entity of this.entities.values()) {
|
|
982
|
+
entity.behaviours.reset();
|
|
983
|
+
entity.lastAnchor = null;
|
|
984
|
+
entity.ceremonyVelocity = [0, 0, 0];
|
|
985
|
+
}
|
|
986
|
+
for (const pkg of this.packages) {
|
|
987
|
+
if (pkg) {
|
|
988
|
+
pkg.events = pkg.events.filter((e) => e.phase === 'cancel');
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
this.effects.endTransient();
|
|
992
|
+
this.post.endTransient();
|
|
993
|
+
this.moments.end();
|
|
994
|
+
this.audio.stop();
|
|
995
|
+
for (const entity of this.entities.values()) {
|
|
996
|
+
entity.contacts = [];
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
// A seek of the page, after the timeline moved.
|
|
1001
|
+
reset(reason = 'seek') {
|
|
1002
|
+
this.clocks.seek();
|
|
1003
|
+
this.newEpoch(reason);
|
|
1004
|
+
this.resync = true;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// A presentation or transport event, with an id stable across replays.
|
|
1008
|
+
emit(e) {
|
|
1009
|
+
const step = this.app.timeline ? Math.floor(this.app.timeline.t) : 0;
|
|
1010
|
+
const event = {
|
|
1011
|
+
id: `${e.kind}:${step}:${hash(`${e.kind}|${step}|${e.player ?? e.team ?? ''}|${e.key || ''}`).toString(16)}`,
|
|
1012
|
+
kind: e.kind, phase: 'occur', revision: 0, step, t: this.clocks.sim, lead: 0,
|
|
1013
|
+
team: e.team, player: e.player, subjects: e.subjects, provenance: e.provenance || 'presentation',
|
|
1014
|
+
replay: this.replaying ? { of: this.replayOf || null, angle: null, speed: this.app.timeline ? this.app.timeline.speed : 1 } : undefined,
|
|
1015
|
+
data: e.data || {},
|
|
1016
|
+
};
|
|
1017
|
+
this.pushEvents([event]);
|
|
1018
|
+
return event;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
pushEvents(events) {
|
|
1022
|
+
for (const event of events) {
|
|
1023
|
+
if (event.phase === 'occur' || event.phase === 'forecast') {
|
|
1024
|
+
this.recent.set(event.id, { ...event, seenAt: this.clocks.cosmetic });
|
|
1025
|
+
while (this.recent.size > 128) {
|
|
1026
|
+
this.recent.delete(this.recent.keys().next().value);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
if (event.phase === 'occur' && (event.team === 0 || event.team === 1) && ['touch', 'goal', 'shot', 'save', 'celebration.begin', 'winner.reveal', 'mvp.reveal'].includes(event.kind)) {
|
|
1030
|
+
this.pulse[event.team] = 1;
|
|
1031
|
+
}
|
|
1032
|
+
if (event.kind === 'halftime' && event.phase === 'occur') {
|
|
1033
|
+
this.effects.halftime();
|
|
1034
|
+
}
|
|
1035
|
+
for (const pkg of this.packages) {
|
|
1036
|
+
if (pkg) {
|
|
1037
|
+
this.audio.event(pkg, event);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
for (const pkg of this.packages) {
|
|
1041
|
+
if (!pkg) {
|
|
1042
|
+
continue;
|
|
1043
|
+
}
|
|
1044
|
+
if (pkg.host) {
|
|
1045
|
+
pkg.events.push(event);
|
|
1046
|
+
if (pkg.events.length > 1024) {
|
|
1047
|
+
pkg.events.shift();
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
this.react(pkg, event);
|
|
1051
|
+
}
|
|
1052
|
+
this.custody.observe([event], this.clocks.sim);
|
|
1053
|
+
if (event.phase === 'cancel') {
|
|
1054
|
+
for (const entity of this.entities.values()) {
|
|
1055
|
+
if (entity.animator) {
|
|
1056
|
+
entity.animator.cancel(event.id, this.clocks.sim);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
this.schedule(event);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// Starts the action clip of a contact event on the player who meets the ball.
|
|
1065
|
+
schedule(event) {
|
|
1066
|
+
if (event.player == null || (event.phase !== 'forecast' && event.phase !== 'occur') || !CONTACT_KINDS.includes(event.kind)) {
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
const entity = this.entities.get(`p${event.player}`);
|
|
1070
|
+
if (entity && entity.pkg.manifest.rig.ik && Object.keys(entity.pkg.manifest.rig.ik).length) {
|
|
1071
|
+
const t = event.data && event.data.contactT != null ? event.data.contactT : event.t;
|
|
1072
|
+
if (!entity.contacts.some((c) => Math.abs(c.t - t) < 1e-6)) {
|
|
1073
|
+
entity.contacts.push({ t, kind: event.kind, data: event.data });
|
|
1074
|
+
entity.contacts = entity.contacts.slice(-8);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
if (!entity || !entity.animator) {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
const same = this.catalog ? this.catalog.eventsAt(event.step).filter((x) => x.player === event.player && CONTACT_KINDS.includes(x.kind)) : [event];
|
|
1081
|
+
const best = preferred(same.length ? same : [event]);
|
|
1082
|
+
if (best.id === event.id || !same.some((x) => x.id === best.id)) {
|
|
1083
|
+
const frame = this.app.timeline ? this.app.timeline.store.get(event.step) : null;
|
|
1084
|
+
entity.animator.schedule(event, event.phase === 'forecast' ? event.lead : 0, frame ? frame.gameMode : 0);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// Runs the reflexes of a package for an event.
|
|
1089
|
+
react(pkg, event) {
|
|
1090
|
+
const own = new Set([...this.entities.values()].filter((e) => e.pkg === pkg).map((e) => e.id));
|
|
1091
|
+
for (const reflex of reflexesFor(pkg.manifest, event, pkg.side, this.header ? this.header.players : null)) {
|
|
1092
|
+
for (const { kind, command } of reflexActions(reflex, event, own)) {
|
|
1093
|
+
this.run(pkg, kind, command, event);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// Runs one checked command, the core's own kinds here and the rest through the registry.
|
|
1099
|
+
run(pkg, kind, command, event = null) {
|
|
1100
|
+
if (kind === 'clip') {
|
|
1101
|
+
const targets = command.on === 'team' ? [...this.entities.values()].filter((e) => e.pkg === pkg)
|
|
1102
|
+
: [this.entities.get(`p${event && event.player}`)].filter((e) => e && e.pkg === pkg);
|
|
1103
|
+
for (const entity of targets) {
|
|
1104
|
+
const entry = pickClip(pkg.manifest, command.role, entity.seeds.entity);
|
|
1105
|
+
const rig = this.players ? this.players.rigOf(entity.k) : null;
|
|
1106
|
+
const clip = entry && rig ? rig.clip(entry.clip) : null;
|
|
1107
|
+
if (clip) {
|
|
1108
|
+
const clock = event && event.provenance !== 'presentation' ? 'sim' : 'ceremony';
|
|
1109
|
+
const from = clock === 'sim' ? event.t : this.clocks.ceremony;
|
|
1110
|
+
this.ledger.put({ id: `${event ? event.id : 'clip'}:${entity.id}`, entity: entity.id, event: event ? event.id : null, from, to: from + clip.duration, clock, content: { kind: 'clip', role: command.role, clip: entry.clip }, seed: entity.seeds.entity, replay: 'repeat', rate: 1, source: `reflex:${pkg.side}` });
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
if (kind === 'behaviour') {
|
|
1116
|
+
for (const entity of this.entities.values()) {
|
|
1117
|
+
if (entity.pkg === pkg && (command.on === 'team' || (event && entity.k === event.player))) {
|
|
1118
|
+
try {
|
|
1119
|
+
entity.behaviours.set(checkBehaviour(command.spec), 'reflex');
|
|
1120
|
+
} catch {
|
|
1121
|
+
this.drop.rejected += 1;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
if (kind === 'claim') {
|
|
1128
|
+
this.claim(pkg, command);
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
dispatch(kind, command, { pkg, event, presentation: this });
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
// A claim of custody of the ball on a team's own touch, section 6.
|
|
1135
|
+
claim(pkg, c) {
|
|
1136
|
+
if (c.target !== 'ball' || !this.catalog) {
|
|
1137
|
+
return false;
|
|
1138
|
+
}
|
|
1139
|
+
const step = Number(String(c.event).split(':')[1]);
|
|
1140
|
+
const touches = Number.isFinite(step) ? this.catalog.eventsAt(step).filter((e) => e.kind === 'touch') : [];
|
|
1141
|
+
const event = touches.find((e) => e.team === pkg.side) || null;
|
|
1142
|
+
return this.custody.claim(pkg.side, event, touches);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// An event of the team on side made up at once, for the preview of a package. It carries the
|
|
1146
|
+
// ball where it is drawn as its contact and the team's first visible player, and reaches the
|
|
1147
|
+
// reflexes, the worker and the effects as a real event would. Returns the event.
|
|
1148
|
+
inject(side, kind) {
|
|
1149
|
+
const entity = [...this.entities.values()].find((e) => e.side === side && e.visible) || null;
|
|
1150
|
+
const ball = this.app.ball ? this.app.ball.mesh.position : null;
|
|
1151
|
+
const point = ball ? [ball.x, -ball.z, ball.y] : [0, 0, 0.11];
|
|
1152
|
+
this.injected = (this.injected || 0) + 1;
|
|
1153
|
+
const step = this.app.timeline ? Math.floor(this.app.timeline.t) : 0;
|
|
1154
|
+
const event = {
|
|
1155
|
+
id: `${kind}:${step}:preview${this.injected}`, kind, phase: 'occur', revision: 0, step, t: this.clocks.sim, lead: 0,
|
|
1156
|
+
team: side, player: entity ? entity.k : undefined, provenance: 'presentation',
|
|
1157
|
+
data: { kind: 'kick', contactT: this.clocks.sim, contactPoint: point, scoringTeam: side, team: side, preview: true },
|
|
1158
|
+
};
|
|
1159
|
+
this.pushEvents([event]);
|
|
1160
|
+
return event;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
// A reveal of the show after the match. A package that answers it with a moment of its own
|
|
1164
|
+
// sound replaces the renderer's fanfare for its team. Returns whether one did.
|
|
1165
|
+
reveal(kind, team) {
|
|
1166
|
+
const event = this.emit({ kind: kind === 'mvp' ? 'mvp.reveal' : 'winner.reveal', team, data: { team } });
|
|
1167
|
+
let replaced = false;
|
|
1168
|
+
for (const pkg of this.packages) {
|
|
1169
|
+
if (pkg && pkg.side === team) {
|
|
1170
|
+
for (const reflex of reflexesFor(pkg.manifest, event, pkg.side)) {
|
|
1171
|
+
replaced = (reflex.do || []).some((a) => a.audio != null && (a.class || 'action') === 'moment') || replaced;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return replaced && !!(this.app.sound && this.app.sound.audible);
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
// The distance player k covered from the start of the store to timeline index t, a prefix
|
|
1179
|
+
// sum of the steps of his root, cuts left out.
|
|
1180
|
+
distanceAt(k, t) {
|
|
1181
|
+
const store = this.app.timeline.store;
|
|
1182
|
+
let table = this.distances.get(k);
|
|
1183
|
+
if (!table) {
|
|
1184
|
+
table = { first: store.first, values: [0] };
|
|
1185
|
+
this.distances.set(k, table);
|
|
1186
|
+
}
|
|
1187
|
+
const i = Math.floor(t);
|
|
1188
|
+
while (table.first + table.values.length - 1 < Math.min(i + 1, store.last)) {
|
|
1189
|
+
const j = table.first + table.values.length;
|
|
1190
|
+
const a = store.get(j - 1);
|
|
1191
|
+
const b = store.get(j);
|
|
1192
|
+
const o = NODES_FLOAT + k * PLAYER_FLOATS;
|
|
1193
|
+
const d = a && b && !isCut(a, b) ? Math.hypot(b.data[o] - a.data[o], b.data[o + 1] - a.data[o + 1]) : 0;
|
|
1194
|
+
table.values.push(table.values[table.values.length - 1] + d);
|
|
1195
|
+
}
|
|
1196
|
+
const at = (j) => table.values[clamp(j - table.first, 0, table.values.length - 1)];
|
|
1197
|
+
return at(i) + (at(i + 1) - at(i)) * (t - i);
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
// The state of the timeline and the director on this drawing, before the players are drawn.
|
|
1201
|
+
update(dt, sample) {
|
|
1202
|
+
const app = this.app;
|
|
1203
|
+
const tl = app.timeline;
|
|
1204
|
+
// A match without a package costs the page nothing.
|
|
1205
|
+
if (!tl || !this.players || !this.header || (!this.packages[0] && !this.packages[1])) {
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
const drawn = performance.now();
|
|
1209
|
+
this.drawingMs = this.lastDrawing == null ? 0 : drawn - this.lastDrawing;
|
|
1210
|
+
this.lastDrawing = drawn;
|
|
1211
|
+
const director = app.director;
|
|
1212
|
+
const ceremony = !!(director && director.running) || !!(app.postMatch && app.postMatch.running);
|
|
1213
|
+
this.clocks.advance({ dt, t: tl.t, sps: tl.sps || 10, ceremony, held: !!app.userPaused && ceremony, audio: app.sound && app.sound.ctx ? app.sound.ctx.currentTime : null });
|
|
1214
|
+
this.observeTransport(tl);
|
|
1215
|
+
const replaying = !!(director && director.active);
|
|
1216
|
+
if (replaying !== !!this.replaying) {
|
|
1217
|
+
this.replaying = replaying;
|
|
1218
|
+
this.emit({ kind: replaying ? 'replay.begin' : 'replay.end', data: {} });
|
|
1219
|
+
this.reset(replaying ? 'replay' : 'resume');
|
|
1220
|
+
}
|
|
1221
|
+
if (!this.catalog || this.catalog.store !== tl.store) {
|
|
1222
|
+
this.catalog = new Catalog(tl.store, { fullLookahead: this.settings.fullLookahead, live: !!tl.live });
|
|
1223
|
+
}
|
|
1224
|
+
if (this.catalog) {
|
|
1225
|
+
const before = this.catalog.epoch;
|
|
1226
|
+
const events = this.catalog.update({ t: tl.t, playing: tl.playing, direction: tl.direction, speed: tl.speed, ahead: tl.live ? tl.behindLive : null, dt: app.playDt || dt });
|
|
1227
|
+
if (this.catalog.epoch !== before && this.catalog.resetReason) {
|
|
1228
|
+
this.newEpoch(this.catalog.resetReason === 'seek' ? 'seek' : this.catalog.resetReason, false);
|
|
1229
|
+
}
|
|
1230
|
+
if (this.resync) {
|
|
1231
|
+
this.resync = false;
|
|
1232
|
+
events.push(...this.catalog.window(tl.t));
|
|
1233
|
+
}
|
|
1234
|
+
for (const e of events) {
|
|
1235
|
+
if (replaying) {
|
|
1236
|
+
e.replay = { of: this.replayOf || null, angle: null, speed: tl.speed };
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
this.pushEvents(events);
|
|
1240
|
+
}
|
|
1241
|
+
this.observePresentation(sample);
|
|
1242
|
+
this.updateInputs(sample, tl);
|
|
1243
|
+
this.bend(sample, tl);
|
|
1244
|
+
this.updateUniforms();
|
|
1245
|
+
this.moments.update();
|
|
1246
|
+
this.moments.updateSlots();
|
|
1247
|
+
this.audio.update(this.entities.values());
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// The share of real time the timeline plays this drawing, a team's time suggestion.
|
|
1251
|
+
timeScale(dt) {
|
|
1252
|
+
return this.packages[0] || this.packages[1] ? this.moments.timeScale(dt) : 1;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
// Bends the drawn ball through the estimated contact of a touch in the interval on screen,
|
|
1256
|
+
// while a package names bend.ball, or always with the setting true. It moves the drawn ball
|
|
1257
|
+
// alone, after every hook of the page placed it, and only where the ball is still where the
|
|
1258
|
+
// frames put it.
|
|
1259
|
+
bend(sample, tl) {
|
|
1260
|
+
const on = this.settings.bendBall === true || (this.settings.bendBall === 'auto' && this.packages.some((p) => p && this.hasFeature(p, 'bend.ball')));
|
|
1261
|
+
const pose = this.app.pose;
|
|
1262
|
+
if (!on || !pose || !sample.b || isCut(sample.a, sample.b) || !(sample.b.touches && sample.b.touches.some((x) => x))) {
|
|
1263
|
+
this.bent = null;
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
const i = sample.index + 1;
|
|
1267
|
+
const est = contactEstimate(tl.store, i);
|
|
1268
|
+
if (!est || est.method !== 'intersection' || est.step !== sample.index) {
|
|
1269
|
+
this.bent = null;
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
const pa = [sample.a.data[8], sample.a.data[9], sample.a.data[10]];
|
|
1273
|
+
const pb = [sample.b.data[8], sample.b.data[9], sample.b.data[10]];
|
|
1274
|
+
const w = sample.w;
|
|
1275
|
+
const straight = [0, 1, 2].map((k) => pa[k] + (pb[k] - pa[k]) * w);
|
|
1276
|
+
if (Math.hypot(pose.ball[0] - straight[0], pose.ball[1] - straight[1], pose.ball[2] - straight[2]) > 1e-3) {
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
const p = bendBall(pa, pb, est.point, est.fraction, w);
|
|
1280
|
+
pose.ball[0] = p[0];
|
|
1281
|
+
pose.ball[1] = p[1];
|
|
1282
|
+
pose.ball[2] = p[2];
|
|
1283
|
+
this.bent = { step: i, fraction: est.fraction, point: est.point, drawn: p };
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
// The uniforms every shader of a team reads, the clocks, the ball, the pulse of its last own
|
|
1287
|
+
// event and the factor of the flash governor.
|
|
1288
|
+
updateUniforms() {
|
|
1289
|
+
const ball = this.app.ball ? this.app.ball.mesh.position : null;
|
|
1290
|
+
const renderer = this.app.view ? this.app.view.renderer : null;
|
|
1291
|
+
const high = this.app.view && this.app.view.quality === 'high';
|
|
1292
|
+
for (const side of [0, 1]) {
|
|
1293
|
+
const u = this.uniforms[side];
|
|
1294
|
+
const pkg = this.packages[side];
|
|
1295
|
+
this.pulse[side] *= Math.exp(-3 * this.clocks.cosmeticStep);
|
|
1296
|
+
u.uTime.value = this.clocks.cosmetic;
|
|
1297
|
+
u.uSim.value = this.clocks.sim;
|
|
1298
|
+
u.uCeremony.value = this.clocks.ceremony;
|
|
1299
|
+
u.uPulse.value = this.pulse[side] * (this.app.reducedMotion ? 0.5 : 1);
|
|
1300
|
+
u.uExcitement.value = this.app.excitement || 0;
|
|
1301
|
+
u.uIntensity.value = this.flashFactor();
|
|
1302
|
+
if (ball) {
|
|
1303
|
+
u.uBall.value.copy(ball);
|
|
1304
|
+
}
|
|
1305
|
+
if (renderer) {
|
|
1306
|
+
renderer.getDrawingBufferSize(u.uResolution.value);
|
|
1307
|
+
}
|
|
1308
|
+
// The frame drawn so far reaches a package that names shader.sceneColor at high quality.
|
|
1309
|
+
u.uSceneColor.value = pkg && high && this.hasFeature(pkg, 'shader.sceneColor') && this.app.view.frame ? this.app.view.frame : u.uLayer.value;
|
|
1310
|
+
}
|
|
1311
|
+
for (const entity of this.entities.values()) {
|
|
1312
|
+
const entry = this.entryOf(entity.k);
|
|
1313
|
+
for (const o of (entry && entry.instance.cujuOriginals) || []) {
|
|
1314
|
+
o.copy.userData.cuju.instance.uSpeed.value = entity.inputs.speed || 0;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// Transport events, and the epochs that a change of direction starts.
|
|
1320
|
+
observeTransport(tl) {
|
|
1321
|
+
const mode = !tl.playing ? 'pause' : tl.direction < 0 ? 'reverse' : 'play';
|
|
1322
|
+
if (this.mode !== null && mode !== this.mode) {
|
|
1323
|
+
this.emit({ kind: mode === 'reverse' ? 'reverse' : mode, data: { speed: tl.speed } });
|
|
1324
|
+
if (mode === 'reverse' || this.mode === 'reverse') {
|
|
1325
|
+
this.newEpoch('reverse');
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
if (this.speed != null && tl.speed !== this.speed) {
|
|
1329
|
+
this.emit({ kind: 'speed', data: { speed: tl.speed } });
|
|
1330
|
+
}
|
|
1331
|
+
this.mode = mode;
|
|
1332
|
+
this.speed = tl.speed;
|
|
1333
|
+
const motion = !!this.app.reducedMotion;
|
|
1334
|
+
if (this.motion != null && motion !== this.motion) {
|
|
1335
|
+
this.emit({ kind: 'reducedMotion', data: { on: motion } });
|
|
1336
|
+
}
|
|
1337
|
+
this.motion = motion;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
// The presentation events of the director and the show, from the edges of their state.
|
|
1341
|
+
observePresentation(sample) {
|
|
1342
|
+
const app = this.app;
|
|
1343
|
+
const director = app.director;
|
|
1344
|
+
const edge = (key, on, begin, end, data) => {
|
|
1345
|
+
if (on && !this.open.has(key)) {
|
|
1346
|
+
this.open.set(key, { event: this.emit({ kind: begin, ...data() }), ceremony: this.clocks.ceremony });
|
|
1347
|
+
} else if (!on && this.open.has(key)) {
|
|
1348
|
+
const opened = this.open.get(key);
|
|
1349
|
+
this.open.delete(key);
|
|
1350
|
+
if (end) {
|
|
1351
|
+
this.emit({ kind: end, team: opened.event.team, data: { begin: opened.event.id } });
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
edge('lineup', !!(director && director.lineup), 'lineup.begin', 'lineup.end', () => ({ data: { duration: LINEUP_LENGTH } }));
|
|
1356
|
+
const cel = director ? director.cel : null;
|
|
1357
|
+
edge('celebration', !!cel, 'celebration.begin', 'celebration.end', () => ({ team: cel.goal.team, player: cel.celebrant, data: { celebrant: cel.celebrant, duration: 9.4 } }));
|
|
1358
|
+
const react = app.postMatch && app.postMatch.running ? app.postMatch.react : null;
|
|
1359
|
+
edge('reaction', !!react, 'reaction.begin', 'reaction.end', () => ({
|
|
1360
|
+
data: { outcome: [0, 1].map((t) => (react.winner < 0 ? 'draw' : react.winner === t ? 'win' : 'loss')), hero: react.hero, beaten: react.beaten },
|
|
1361
|
+
}));
|
|
1362
|
+
const seen = this.memory.visible || (this.memory.visible = new Map());
|
|
1363
|
+
for (const entity of this.entities.values()) {
|
|
1364
|
+
const on = !!(sample.a.playerFlags[entity.k] & 1);
|
|
1365
|
+
const was = seen.get(entity.id);
|
|
1366
|
+
if (was !== undefined && was && !on) {
|
|
1367
|
+
this.emit({ kind: 'entity.remove', team: entity.side, player: entity.k, data: { entity: entity.id } });
|
|
1368
|
+
}
|
|
1369
|
+
seen.set(entity.id, on);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
// The inputs of every entity, from the simulation's frames and the ceremonies on screen.
|
|
1374
|
+
updateInputs(sample, tl) {
|
|
1375
|
+
const store = tl.store;
|
|
1376
|
+
const a = sample.a;
|
|
1377
|
+
let b = store.get(sample.index + 1);
|
|
1378
|
+
let from = a;
|
|
1379
|
+
let to = b;
|
|
1380
|
+
if (!b || isCut(a, b)) {
|
|
1381
|
+
to = a;
|
|
1382
|
+
from = store.get(sample.index - 1);
|
|
1383
|
+
if (!from || isCut(from, a)) {
|
|
1384
|
+
from = a;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
const back = store.get(sample.index - 1);
|
|
1388
|
+
const sps = tl.sps || 10;
|
|
1389
|
+
const ball = this.app.ball ? this.app.ball.mesh.position : null;
|
|
1390
|
+
const lineup = this.open.get('lineup');
|
|
1391
|
+
for (const entity of this.entities.values()) {
|
|
1392
|
+
const o = NODES_FLOAT + entity.k * PLAYER_FLOATS;
|
|
1393
|
+
const vx = (to.data[o] - from.data[o]) * sps;
|
|
1394
|
+
const vy = (to.data[o + 1] - from.data[o + 1]) * sps;
|
|
1395
|
+
entity.velocity = [vx, vy];
|
|
1396
|
+
const speed = Math.hypot(vx, vy);
|
|
1397
|
+
const before = back && !isCut(back, a) ? Math.hypot(a.data[o] - back.data[o], a.data[o + 1] - back.data[o + 1]) * sps : speed;
|
|
1398
|
+
entity.decel = (before - speed) * sps;
|
|
1399
|
+
entity.turnRate = wrap(headingOf(to.data, o) - headingOf(from.data, o)) * sps;
|
|
1400
|
+
entity.action = a.actions ? a.actions[entity.k] : 0;
|
|
1401
|
+
entity.touch = a.touches ? a.touches[entity.k] : 0;
|
|
1402
|
+
entity.owner = a.ownedPlayer === entity.k;
|
|
1403
|
+
entity.gameMode = a.gameMode;
|
|
1404
|
+
const distance = this.distanceAt(entity.k, tl.t);
|
|
1405
|
+
entity.distanceStep = entity.lastDistance == null ? 0 : distance - entity.lastDistance;
|
|
1406
|
+
entity.lastDistance = distance;
|
|
1407
|
+
entity.distance = distance;
|
|
1408
|
+
// The ceremony this entity takes part in, the lineups, a clip a reflex started, or a pose
|
|
1409
|
+
// of the worker driver.
|
|
1410
|
+
let overlay = null;
|
|
1411
|
+
if (lineup) {
|
|
1412
|
+
const clip = pickClip(entity.pkg.manifest, 'lineup', entity.seeds.entity);
|
|
1413
|
+
if (clip) {
|
|
1414
|
+
overlay = { role: 'lineup', clip: clip.clip, time: Math.max(0, this.clocks.ceremony - lineup.ceremony) * (clip.rate || 1), weight: 1 };
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
for (const { track, local } of this.ledger.active(this.clocks, { replay: !!this.replaying, entity: entity.id })) {
|
|
1418
|
+
const c = track.content;
|
|
1419
|
+
if ((c.kind === 'clip' || c.kind === 'pose') && c.clip) {
|
|
1420
|
+
overlay = { role: c.role || 'worker', clip: c.clip, time: c.time != null ? c.time : local * track.rate, weight: c.weight != null ? clamp(c.weight, 0, 1) : 1 };
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
entity.overlay = overlay;
|
|
1424
|
+
if (overlay) {
|
|
1425
|
+
entity.lastOverlay = overlay;
|
|
1426
|
+
}
|
|
1427
|
+
entity.overlayWeight += ((overlay ? overlay.weight : 0) - entity.overlayWeight) * -Math.expm1(-8 * this.clocks.cosmeticStep);
|
|
1428
|
+
const anchor = entity.anchor;
|
|
1429
|
+
const ballDistance = ball ? Math.hypot(ball.x - anchor[0], ball.z - anchor[2]) : 1e3;
|
|
1430
|
+
const attack = entity.side === 0 ? 1 : -1;
|
|
1431
|
+
entity.inputs = {
|
|
1432
|
+
speed,
|
|
1433
|
+
accel: -entity.decel,
|
|
1434
|
+
ballDistance,
|
|
1435
|
+
excitement: this.app.excitement || 0,
|
|
1436
|
+
'ceremony.amount': Math.max(entity.overlayWeight, this.clocks.ceremonyStep > 0 ? 1 : 0),
|
|
1437
|
+
'ballX.attack': ball ? ball.x * attack : 0,
|
|
1438
|
+
alert: ballDistance < 15 || (a.ownedTeam >= 0 && a.ownedTeam !== entity.side) ? 1 : 0,
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// Poses one player of a package as Rigged draws it, returning false to leave him to the
|
|
1444
|
+
// renderer's own drawing.
|
|
1445
|
+
pose(e, nodes, base) {
|
|
1446
|
+
const entity = e.presentation;
|
|
1447
|
+
if (!entity || !this.entities.has(entity.id) || entity.pkg.budget.past('stock')) {
|
|
1448
|
+
return false;
|
|
1449
|
+
}
|
|
1450
|
+
// What posing costs counts against the team's main thread budget, apart from the page's
|
|
1451
|
+
// own pose of the figure, which it draws without a package too.
|
|
1452
|
+
const started = performance.now();
|
|
1453
|
+
let own = 0;
|
|
1454
|
+
const rig = e.rig;
|
|
1455
|
+
const instance = e.instance;
|
|
1456
|
+
const m = entity.pkg.manifest;
|
|
1457
|
+
const frame = rootFrame(nodes, base, entity.frame);
|
|
1458
|
+
entity.facing = Math.atan2(frame.elements[8], frame.elements[10]);
|
|
1459
|
+
const request = e.request;
|
|
1460
|
+
let overlay = entity.overlay;
|
|
1461
|
+
if (request && request.weight > 0) {
|
|
1462
|
+
overlay = { role: 'celebration', clip: request.clip.name, time: request.t, weight: request.weight };
|
|
1463
|
+
} else if (!entity.animator) {
|
|
1464
|
+
// GRF's nodes fade into and out of a ceremony's clip.
|
|
1465
|
+
overlay = entity.overlayWeight > 0.01 && entity.lastOverlay ? { ...entity.lastOverlay, weight: entity.overlayWeight } : null;
|
|
1466
|
+
}
|
|
1467
|
+
let layers = [];
|
|
1468
|
+
if (entity.animator) {
|
|
1469
|
+
const ceremony = this.clocks.ceremonyStep > 0;
|
|
1470
|
+
layers = entity.animator.layers({
|
|
1471
|
+
sim: this.clocks.sim,
|
|
1472
|
+
speed: ceremony ? Math.hypot(entity.ceremonyVelocity[0], entity.ceremonyVelocity[2]) : entity.inputs.speed,
|
|
1473
|
+
distance: entity.distance, decel: entity.decel, turnRate: entity.turnRate,
|
|
1474
|
+
alert: !!entity.inputs.alert, cosmetic: this.clocks.cosmetic, overlay,
|
|
1475
|
+
});
|
|
1476
|
+
Object.assign(entity.inputs, Animator.roleWeights(layers));
|
|
1477
|
+
} else if (overlay) {
|
|
1478
|
+
entity.inputs[`role:${overlay.role}`] = overlay.weight;
|
|
1479
|
+
}
|
|
1480
|
+
this.evaluate(entity);
|
|
1481
|
+
for (const l of layers) {
|
|
1482
|
+
if (entity.outputs.clipTime.has(l.clip)) {
|
|
1483
|
+
l.time = entity.outputs.clipTime.get(l.clip);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
if (layers.length) {
|
|
1487
|
+
poseLayers(rig, instance, layers, frame, m.rig.rootMotion === 'cosmetic' ? 'vertical' : 'ignore');
|
|
1488
|
+
} else {
|
|
1489
|
+
stopLayers(instance);
|
|
1490
|
+
const clip = overlay ? rig.clip(overlay.clip) : null;
|
|
1491
|
+
const before = performance.now();
|
|
1492
|
+
if (clip) {
|
|
1493
|
+
const time = entity.outputs.clipTime.has(clip.name) ? entity.outputs.clipTime.get(clip.name) : overlay.time;
|
|
1494
|
+
rig.poseClip(instance, clip, time % (clip.duration || 1), overlay.weight, nodes, base, false);
|
|
1495
|
+
} else {
|
|
1496
|
+
rig.pose(instance, nodes, base, false);
|
|
1497
|
+
}
|
|
1498
|
+
own += performance.now() - before;
|
|
1499
|
+
if (entity.driver === 'grf+layers' && (m.rig.layers || []).length && !overlay) {
|
|
1500
|
+
maskLayers(rig, instance, m.rig.layers.map((l) => {
|
|
1501
|
+
const entry = l.clip ? { clip: l.clip } : pickClip(m, l.role, entity.seeds.entity);
|
|
1502
|
+
const c = entry ? rig.clip(entry.clip) : null;
|
|
1503
|
+
return { mask: l.mask, clip: entry ? entry.clip : null, weight: clamp(evaluateCurve(l.weight, entity.inputs), 0, 1), time: c ? (this.clocks.cosmetic * (l.rate || 1)) % (c.duration || 1) : 0 };
|
|
1504
|
+
}), frame);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
this.reachFor(entity, rig, instance);
|
|
1508
|
+
const pivot = m.rig.sockets.root && !m.rig.sockets.root.node ? tmpVector.fromArray(m.rig.sockets.root.offset || [0, 0, 0]) : tmpVector.set(0, 0, 0);
|
|
1509
|
+
applyOutputs(rig, instance, frame, entity.outputs, pivot, m.rig.sockets.gaze || null, entity.cosmetic);
|
|
1510
|
+
const before = performance.now();
|
|
1511
|
+
if (rig.write) {
|
|
1512
|
+
rig.write(instance);
|
|
1513
|
+
} else {
|
|
1514
|
+
writeBones(rig, instance, e.hideHead);
|
|
1515
|
+
}
|
|
1516
|
+
own += performance.now() - before;
|
|
1517
|
+
entity.posed = true;
|
|
1518
|
+
entity.pkg.spent = (entity.pkg.spent || 0) + performance.now() - started - own;
|
|
1519
|
+
return true;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
// Reaches each chain of the rig toward the drawn ball over the window around a contact.
|
|
1523
|
+
reachFor(entity, rig, instance) {
|
|
1524
|
+
const chains = entity.pkg.manifest.rig.ik || {};
|
|
1525
|
+
const ball = this.app.ball ? this.app.ball.mesh.position : null;
|
|
1526
|
+
if (!ball || !entity.contacts.length || !this.hasFeature(entity.pkg, 'ik.fabrik')) {
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
for (const [name, chain] of Object.entries(chains)) {
|
|
1530
|
+
if (!selects(chain.when, entity)) {
|
|
1531
|
+
continue;
|
|
1532
|
+
}
|
|
1533
|
+
let weight = 0;
|
|
1534
|
+
for (const c of entity.contacts) {
|
|
1535
|
+
weight = Math.max(weight, reachWeight(this.clocks.sim, c.t, chain.window ?? 0.15));
|
|
1536
|
+
}
|
|
1537
|
+
weight *= chain.weight ?? 1;
|
|
1538
|
+
if (weight <= 0.001) {
|
|
1539
|
+
continue;
|
|
1540
|
+
}
|
|
1541
|
+
rig.cujuChains = rig.cujuChains || new Map();
|
|
1542
|
+
if (!rig.cujuChains.has(name)) {
|
|
1543
|
+
rig.cujuChains.set(name, chainOf(rig, chain.chain));
|
|
1544
|
+
}
|
|
1545
|
+
const bones = rig.cujuChains.get(name);
|
|
1546
|
+
if (bones) {
|
|
1547
|
+
entity.reach = { chain: name, weight, left: reach(rig, instance, bones, ball, weight, chain.iterations || 8) };
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
// The behaviours of one entity on this drawing, read against its anchors of the last drawing.
|
|
1553
|
+
evaluate(entity) {
|
|
1554
|
+
const h = entity.facing;
|
|
1555
|
+
const [vx, vy] = entity.velocity || [0, 0];
|
|
1556
|
+
// The simulation's velocity in three's frame is x and minus y.
|
|
1557
|
+
const tx = vx;
|
|
1558
|
+
const tz = -vy;
|
|
1559
|
+
const eyeHeight = entity.bounds() ? entity.bounds().height * 0.6 : 1.2;
|
|
1560
|
+
const eye = [entity.anchor[0], entity.anchor[1] + eyeHeight, entity.anchor[2]];
|
|
1561
|
+
const toward = (p) => {
|
|
1562
|
+
const dx = p.x - eye[0];
|
|
1563
|
+
const dy = p.y - eye[1];
|
|
1564
|
+
const dz = p.z - eye[2];
|
|
1565
|
+
const lx = Math.cos(h) * dx - Math.sin(h) * dz;
|
|
1566
|
+
const lz = Math.sin(h) * dx + Math.cos(h) * dz;
|
|
1567
|
+
return { yaw: Math.atan2(lx, lz), pitch: Math.atan2(dy, Math.hypot(lx, lz)) };
|
|
1568
|
+
};
|
|
1569
|
+
const app = this.app;
|
|
1570
|
+
const target = (name) => {
|
|
1571
|
+
if (name === 'ball') {
|
|
1572
|
+
return app.ball && app.ball.mesh.visible !== false ? app.ball.mesh.position : null;
|
|
1573
|
+
}
|
|
1574
|
+
if (name === 'camera') {
|
|
1575
|
+
return app.view ? app.view.camera.position : null;
|
|
1576
|
+
}
|
|
1577
|
+
if (/^p\d+$/.test(String(name)) && this.players && app.pose) {
|
|
1578
|
+
const k = Number(name.slice(1));
|
|
1579
|
+
return this.players.position(app.pose, k, new THREE.Vector3()).setY(1.2);
|
|
1580
|
+
}
|
|
1581
|
+
return null;
|
|
1582
|
+
};
|
|
1583
|
+
entity.outputs = entity.behaviours.evaluate({
|
|
1584
|
+
dt: this.clocks.cosmeticStep,
|
|
1585
|
+
distance: entity.distanceStep || 0,
|
|
1586
|
+
inputs: entity.inputs,
|
|
1587
|
+
velocity: { forward: tx * Math.sin(h) + tz * Math.cos(h), lateral: tx * Math.cos(h) - tz * Math.sin(h) },
|
|
1588
|
+
looks: (name) => {
|
|
1589
|
+
const p = target(name);
|
|
1590
|
+
return p ? toward(p) : null;
|
|
1591
|
+
},
|
|
1592
|
+
follow: (name) => {
|
|
1593
|
+
const p = target(name);
|
|
1594
|
+
if (!p) {
|
|
1595
|
+
return null;
|
|
1596
|
+
}
|
|
1597
|
+
const dx = p.x - entity.anchor[0];
|
|
1598
|
+
const dz = p.z - entity.anchor[2];
|
|
1599
|
+
return [Math.cos(h) * dx - Math.sin(h) * dz, p.y - entity.anchor[1], Math.sin(h) * dx + Math.cos(h) * dz];
|
|
1600
|
+
},
|
|
1601
|
+
clocks: this.clocks,
|
|
1602
|
+
reducedMotion: app.reducedMotion ? entity.pkg.manifest.reducedMotion.amplitude : 1,
|
|
1603
|
+
});
|
|
1604
|
+
// Material parameters of the core, a numeric property of the entity's own materials.
|
|
1605
|
+
for (const p of entity.outputs.materials) {
|
|
1606
|
+
const entry = this.entryOf(entity.k);
|
|
1607
|
+
if (p.attachment) {
|
|
1608
|
+
const a = entity.attachments.find((x) => x.name === p.attachment);
|
|
1609
|
+
if (a) {
|
|
1610
|
+
setMaterialParam({ root: a.object, materials: a.materials || (a.materials = []) }, p);
|
|
1611
|
+
}
|
|
1612
|
+
} else if (entry && !(handlerOf('materials') && dispatch('materials', p, { pkg: entity.pkg, entity, presentation: this }))) {
|
|
1613
|
+
setMaterialParam(entry.instance, p);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
// The bounds a package gives a figure, for camera framing and ceremony spacing.
|
|
1619
|
+
size(e) {
|
|
1620
|
+
const entity = e.presentation;
|
|
1621
|
+
return entity && this.entities.has(entity.id) ? entity.bounds() : null;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
// The clip name a role plays on player k, for the choreographies' still poses.
|
|
1625
|
+
roleClip(k, role) {
|
|
1626
|
+
const entity = this.entities.get(`p${k}`);
|
|
1627
|
+
if (!entity) {
|
|
1628
|
+
return null;
|
|
1629
|
+
}
|
|
1630
|
+
const entry = pickClip(entity.pkg.manifest, role, entity.seeds.entity);
|
|
1631
|
+
return entry ? `clip:${entry.clip}` : null;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
// Frees what one player of a package holds, as the page disposes him.
|
|
1635
|
+
release(e) {
|
|
1636
|
+
const entity = e.presentation;
|
|
1637
|
+
if (!entity) {
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
for (const a of entity.attachments) {
|
|
1641
|
+
disposeObject(a.object);
|
|
1642
|
+
entity.pkg.budget.give({ drawCalls: a.cost.drawCalls, triangles: a.cost.triangles, textureBytes: a.cost.textureBytes });
|
|
1643
|
+
}
|
|
1644
|
+
entity.attachments = [];
|
|
1645
|
+
if (this.entities.get(entity.id) === entity) {
|
|
1646
|
+
this.entities.delete(entity.id);
|
|
1647
|
+
this.emit({ kind: 'entity.remove', team: entity.side, player: entity.k, data: { entity: entity.id } });
|
|
1648
|
+
}
|
|
1649
|
+
e.presentation = null;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
// Once the players and the ball are drawn, sockets and attachments follow the final poses
|
|
1653
|
+
// and each worker gets the rendered state of this drawing.
|
|
1654
|
+
afterPose() {
|
|
1655
|
+
if (!this.players || (!this.packages[0] && !this.packages[1])) {
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
const step = this.clocks.cosmeticStep;
|
|
1659
|
+
for (const entity of this.entities.values()) {
|
|
1660
|
+
const started = performance.now();
|
|
1661
|
+
const entry = this.entryOf(entity.k);
|
|
1662
|
+
const visible = !!(entry && entry.instance.root.visible && entity.posed);
|
|
1663
|
+
entity.visible = visible;
|
|
1664
|
+
if (visible) {
|
|
1665
|
+
anchorOf(entity.cosmetic, entity.anchor);
|
|
1666
|
+
if (entity.lastAnchor && step > 0) {
|
|
1667
|
+
for (let i = 0; i < 3; i++) {
|
|
1668
|
+
entity.ceremonyVelocity[i] += ((entity.anchor[i] - entity.lastAnchor[i]) / step - entity.ceremonyVelocity[i]) * -Math.expm1(-8 * step);
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
entity.lastAnchor = entity.anchor.slice();
|
|
1672
|
+
}
|
|
1673
|
+
for (const a of entity.attachments) {
|
|
1674
|
+
a.object.visible = visible && !entry.hideHead;
|
|
1675
|
+
if (!a.object.visible) {
|
|
1676
|
+
continue;
|
|
1677
|
+
}
|
|
1678
|
+
const socket = a.socket === 'root' ? null : entity.pkg.manifest.rig.sockets[a.socket];
|
|
1679
|
+
if (socket) {
|
|
1680
|
+
socketMatrix(entry.rig, entry.instance, socket, entity.cosmetic, tmpMatrix);
|
|
1681
|
+
} else {
|
|
1682
|
+
tmpMatrix.copy(entity.cosmetic);
|
|
1683
|
+
}
|
|
1684
|
+
a.object.matrix.copy(tmpMatrix).multiply(a.local);
|
|
1685
|
+
const o = entity.outputs.attachments && entity.outputs.attachments.get(a.name);
|
|
1686
|
+
if (o) {
|
|
1687
|
+
a.object.matrix.multiply(attachmentOffset(o));
|
|
1688
|
+
}
|
|
1689
|
+
a.object.matrixWorldNeedsUpdate = true;
|
|
1690
|
+
}
|
|
1691
|
+
entity.posed = false;
|
|
1692
|
+
entity.pkg.spent = (entity.pkg.spent || 0) + performance.now() - started;
|
|
1693
|
+
}
|
|
1694
|
+
const now = this.clocks.cosmetic;
|
|
1695
|
+
for (const pkg of this.packages) {
|
|
1696
|
+
if (!pkg) {
|
|
1697
|
+
continue;
|
|
1698
|
+
}
|
|
1699
|
+
pkg.lastSpent = pkg.spent || 0;
|
|
1700
|
+
const rung = this.settings.metering ? pkg.budget.meter(pkg.lastSpent, now, this.drawingMs || 0) : null;
|
|
1701
|
+
pkg.spent = 0;
|
|
1702
|
+
if (rung && pkg.budget.stepped === 'up') {
|
|
1703
|
+
// A team that ran well under its budget for a while climbs back one rung.
|
|
1704
|
+
console.info(`presentation of ${pkg.manifest.name || pkg.teamId} steps up to ${rung}`);
|
|
1705
|
+
if (!pkg.budget.past('standardMaterials')) {
|
|
1706
|
+
this.reshade(pkg);
|
|
1707
|
+
}
|
|
1708
|
+
if (!pkg.budget.past('noWorker') && !pkg.host && pkg.status === 'stopped') {
|
|
1709
|
+
this.startWorker(pkg);
|
|
1710
|
+
}
|
|
1711
|
+
} else if (rung) {
|
|
1712
|
+
console.warn(`presentation of ${pkg.manifest.name || pkg.teamId} steps down to ${rung}`);
|
|
1713
|
+
this.effects.degrade(pkg);
|
|
1714
|
+
if (pkg.budget.past('standardMaterials')) {
|
|
1715
|
+
this.unshade(pkg);
|
|
1716
|
+
}
|
|
1717
|
+
// The ladder rests the worker, which starts again when the team climbs back.
|
|
1718
|
+
if (pkg.budget.past('noWorker') && pkg.host && pkg.host.status !== 'failed') {
|
|
1719
|
+
pkg.host.dispose();
|
|
1720
|
+
pkg.host = null;
|
|
1721
|
+
this.workerStatus(pkg, 'stopped', 'the team is past its time budget');
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
if (pkg.host && pkg.host.wants()) {
|
|
1725
|
+
const sent = performance.now();
|
|
1726
|
+
pkg.host.send(this.frame(pkg));
|
|
1727
|
+
pkg.spent += performance.now() - sent;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
this.effects.update(this.clocks.cosmeticStep);
|
|
1731
|
+
const started = performance.now();
|
|
1732
|
+
this.placeGeometries();
|
|
1733
|
+
const placed = performance.now() - started;
|
|
1734
|
+
// Each team's effects count against its own budget, and the geometries of the workers
|
|
1735
|
+
// against the teams that hold them.
|
|
1736
|
+
const holders = new Set([...this.geometries.values()].map((g) => g.pkg));
|
|
1737
|
+
for (const pkg of this.packages) {
|
|
1738
|
+
if (pkg) {
|
|
1739
|
+
const team = this.effects.teams[pkg.side];
|
|
1740
|
+
pkg.spent = (pkg.spent || 0) + (team ? team.spent || 0 : 0) + (holders.has(pkg) ? placed / holders.size : 0);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
// The worker's geometries follow their sockets, players or the world.
|
|
1746
|
+
placeGeometries() {
|
|
1747
|
+
for (const g of this.geometries.values()) {
|
|
1748
|
+
const team = this.effects.teams[g.pkg.side];
|
|
1749
|
+
if (!team) {
|
|
1750
|
+
continue;
|
|
1751
|
+
}
|
|
1752
|
+
const attach = g.attach === 'world' ? { to: 'world' } : g.socket ? { to: 'entity', entity: g.entity, socket: g.socket } : { to: 'entity', entity: g.entity };
|
|
1753
|
+
const at = this.effects.resolve(team, { attach, event: null, params: {} }, new THREE.Vector3(), tmpMatrix);
|
|
1754
|
+
if (attach.to === 'world') {
|
|
1755
|
+
g.mesh.matrix.identity();
|
|
1756
|
+
} else if (at) {
|
|
1757
|
+
g.mesh.matrix.copy(tmpMatrix);
|
|
1758
|
+
}
|
|
1759
|
+
g.mesh.visible = attach.to === 'world' || !!at;
|
|
1760
|
+
g.mesh.matrixWorldNeedsUpdate = true;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
// After the picture is drawn, the team passes draw over it and the flash backstop reads a small
|
|
1765
|
+
// copy of it, while any team effect, light, pass or moment is on.
|
|
1766
|
+
afterRender(renderer, scene, camera) {
|
|
1767
|
+
if (!this.packages[0] && !this.packages[1]) {
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
this.post.render(renderer, scene, camera);
|
|
1771
|
+
const busy = this.effects.teams.some((t) => t && (t.instances.size || t.poolCount || t.localCount))
|
|
1772
|
+
|| this.post.active() || !!this.moments.environment;
|
|
1773
|
+
if (!busy || !this.settings.flashCheck) {
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
try {
|
|
1777
|
+
const canvas = this.flashCanvas || (this.flashCanvas = Object.assign(document.createElement('canvas'), { width: 64, height: 36 }));
|
|
1778
|
+
const ctx = this.flashContext || (this.flashContext = canvas.getContext('2d', { willReadFrequently: true }));
|
|
1779
|
+
ctx.drawImage(renderer.domElement, 0, 0, 64, 36);
|
|
1780
|
+
const counts = this.counter.push(this.clocks.cosmetic, ctx.getImageData(0, 0, 64, 36).data);
|
|
1781
|
+
this.flashCounts = { general: counts.general, red: counts.red };
|
|
1782
|
+
this.flash.observe(this.clocks.cosmetic, counts);
|
|
1783
|
+
} catch {
|
|
1784
|
+
// A canvas that cannot be read leaves the envelopes of the governor alone.
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
// The rendered state of this drawing as a Frame for one package, in the pitch frame.
|
|
1789
|
+
frame(pkg) {
|
|
1790
|
+
const app = this.app;
|
|
1791
|
+
const tl = app.timeline;
|
|
1792
|
+
const store = tl.store;
|
|
1793
|
+
const s = tl.sample();
|
|
1794
|
+
const a = s.a;
|
|
1795
|
+
const sps = tl.sps || 10;
|
|
1796
|
+
this.frameId += 1;
|
|
1797
|
+
const pose = app.pose;
|
|
1798
|
+
const players = this.header.players.map((p, k) => {
|
|
1799
|
+
const entity = this.entities.get(`p${k}`);
|
|
1800
|
+
const style = this.styles ? this.styles[p.team] : null;
|
|
1801
|
+
const roster = style && style.players ? style.players[p.index] : null;
|
|
1802
|
+
const o = k * PLAYER_FLOATS;
|
|
1803
|
+
const root = entity && entity.visible
|
|
1804
|
+
? [entity.anchor[0], -entity.anchor[2], entity.anchor[1]]
|
|
1805
|
+
: [pose.nodes[o], pose.nodes[o + 1], pose.nodes[o + 2]];
|
|
1806
|
+
const hidden = this.players.hidden ? ['none', 'head', 'all'][this.players.hidden[k]] || 'none' : 'none';
|
|
1807
|
+
const velocity = entity ? entity.velocity.map((v) => v / sps) : [0, 0];
|
|
1808
|
+
return {
|
|
1809
|
+
entity: `p${k}`, player: k, team: p.team,
|
|
1810
|
+
roster: { name: roster ? roster.name || null : null, number: roster ? roster.number : null, goalkeeper: !!p.goalkeeper, celebration: roster ? roster.celebration || null : null },
|
|
1811
|
+
onPitch: !!(a.playerFlags[k] & 1), visible: entity ? entity.visible : !!this.players.visible[k], hidden,
|
|
1812
|
+
root, facing: pitchHeading(pose.nodes, o), velocity, speed: entity ? entity.inputs.speed || 0 : 0,
|
|
1813
|
+
distance: entity ? entity.distance : this.distanceAt(k, tl.t), action: a.actions ? a.actions[k] : 0,
|
|
1814
|
+
touch: a.touches ? a.touches[k] : 0, owner: a.ownedPlayer === k,
|
|
1815
|
+
driver: entity ? entity.driver : 'stock', mode: entity && entity.overlay ? 'ceremony' : 'locomotion',
|
|
1816
|
+
ceremonyRole: entity && entity.overlay ? entity.overlay.role : null, bounds: entity ? entity.bounds() : null,
|
|
1817
|
+
own: p.team === pkg.side,
|
|
1818
|
+
};
|
|
1819
|
+
});
|
|
1820
|
+
const ball = pose.ball;
|
|
1821
|
+
const next = store.get(s.index + 1);
|
|
1822
|
+
const bv = next && !isCut(a, next) ? [0, 1, 2].map((i) => next.data[8 + i] - a.data[8 + i]) : [0, 0, 0];
|
|
1823
|
+
const director = app.director;
|
|
1824
|
+
const context = director && director.active ? 'replay' : director && director.cel ? 'celebration' : director && director.lineup ? 'lineup'
|
|
1825
|
+
: app.postMatch && app.postMatch.running ? 'post' : app.transition && app.transition.active ? 'transition' : 'play';
|
|
1826
|
+
const message = frameMessage({
|
|
1827
|
+
instanceId: pkg.instanceId,
|
|
1828
|
+
epoch: this.epoch,
|
|
1829
|
+
frameId: this.frameId,
|
|
1830
|
+
reset: this.resetPending ? { ...this.resetInfo } : null,
|
|
1831
|
+
clocks: this.clocks.snapshot(),
|
|
1832
|
+
playback: { playing: tl.playing, direction: tl.direction, speed: tl.speed, live: !!tl.live, ahead: tl.live ? tl.behindLive : (tl.last - tl.t) / sps, context },
|
|
1833
|
+
quality: pkg.budget.quality,
|
|
1834
|
+
reducedMotion: !!app.reducedMotion,
|
|
1835
|
+
audible: !!(app.sound && app.sound.audible),
|
|
1836
|
+
players,
|
|
1837
|
+
ball: { pos: [ball[0], ball[1], ball[2]], rot: [ball[3], ball[4], ball[5], ball[6]], velocity: bv, owner: a.ownedPlayer, custody: this.custody.holder ? { team: this.custody.holder.team, event: this.custody.holder.event } : null },
|
|
1838
|
+
game: { mode: a.gameMode, score: [a.scoreLeft, a.scoreRight], clockMs: a.timeMs, ownedTeam: a.ownedTeam, attack: [1, -1], excitement: app.excitement || 0 },
|
|
1839
|
+
events: pkg.events,
|
|
1840
|
+
camera: app.view ? { pos: toPitch(app.view.camera.position), target: toPitch(app.view.camera.getWorldDirection(new THREE.Vector3()).add(app.view.camera.position)), fov: app.view.camera.fov, mode: app.cameras ? app.cameras.mode : null } : null,
|
|
1841
|
+
});
|
|
1842
|
+
this.resetPending = false;
|
|
1843
|
+
pkg.events = [];
|
|
1844
|
+
return message;
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
// A reply of a worker, checked, then applied when it answers this epoch. The time it takes
|
|
1848
|
+
// counts against the team's budget, and the first answer arms the team's meter.
|
|
1849
|
+
respond(pkg, message) {
|
|
1850
|
+
const started = performance.now();
|
|
1851
|
+
try {
|
|
1852
|
+
this.apply(pkg, message);
|
|
1853
|
+
} finally {
|
|
1854
|
+
pkg.spent = (pkg.spent || 0) + performance.now() - started;
|
|
1855
|
+
if (pkg.budget.armAt === Infinity) {
|
|
1856
|
+
pkg.budget.arm(this.clocks.cosmetic + 0.5);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
apply(pkg, message) {
|
|
1862
|
+
const own = new Set([...this.entities.values()].filter((e) => e.pkg === pkg).map((e) => e.id));
|
|
1863
|
+
const checked = checkResponse(message, {
|
|
1864
|
+
instanceId: pkg.instanceId, epoch: this.epoch, own, files: pkg.files,
|
|
1865
|
+
envelope: (id) => (this.entities.get(id) ? this.entities.get(id).envelope : null),
|
|
1866
|
+
});
|
|
1867
|
+
if (!checked.ok) {
|
|
1868
|
+
this.drop[checked.reason] = (this.drop[checked.reason] || 0) + 1;
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1871
|
+
const r = checked.response;
|
|
1872
|
+
this.drop.rejected += r.rejected;
|
|
1873
|
+
pkg.lastResponse = { frameId: r.sourceFrameId, ms: r.ms, roundTrip: message.roundTrip || 0 };
|
|
1874
|
+
// The log keeps the newest lines across replies, and each line shows in the console.
|
|
1875
|
+
if (r.log.length) {
|
|
1876
|
+
pkg.log = appendLog(pkg.log, r.log);
|
|
1877
|
+
for (const line of r.log) {
|
|
1878
|
+
console.info(`presentation worker of ${pkg.manifest.name || pkg.teamId}: ${line}`);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
const mine = (id) => (id == null ? [...this.entities.values()].filter((e) => e.pkg === pkg) : [this.entities.get(id)].filter((e) => e && e.pkg === pkg));
|
|
1882
|
+
for (const b of r.behaviours) {
|
|
1883
|
+
for (const entity of mine(b.entity)) {
|
|
1884
|
+
if (b.op === 'set') {
|
|
1885
|
+
entity.behaviours.set(b.behaviour, 'worker');
|
|
1886
|
+
} else if (b.op === 'update') {
|
|
1887
|
+
entity.behaviours.update(b.id, b.patch);
|
|
1888
|
+
} else {
|
|
1889
|
+
entity.behaviours.stop(b.id, b.fadeOut);
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
for (const t of r.tracks) {
|
|
1894
|
+
const entity = this.entities.get(t.entity);
|
|
1895
|
+
if (t.entity === 'world' || (entity && entity.pkg === pkg)) {
|
|
1896
|
+
this.ledger.put({ ...t, source: `worker:${pkg.side}` });
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
for (const b of r.bounds) {
|
|
1900
|
+
const entity = this.entities.get(b.entity);
|
|
1901
|
+
if (entity && entity.pkg === pkg) {
|
|
1902
|
+
entity.current = b.current;
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
const context = { pkg, presentation: this, event: null };
|
|
1906
|
+
for (const c of r.claims) {
|
|
1907
|
+
dispatch('claims', c, context);
|
|
1908
|
+
}
|
|
1909
|
+
for (const c of r.effects) {
|
|
1910
|
+
dispatch('effects', c, context);
|
|
1911
|
+
}
|
|
1912
|
+
for (const c of r.audio) {
|
|
1913
|
+
dispatch('audio', c, context);
|
|
1914
|
+
}
|
|
1915
|
+
// The overlays the check kept, in order, each beside the raw command it came from.
|
|
1916
|
+
const raws = Array.isArray(message.overlays) ? message.overlays.slice(0, MAXIMUM_COMMANDS).filter((o) => checkOverlay(o)) : [];
|
|
1917
|
+
r.overlays.forEach((c, i) => {
|
|
1918
|
+
const raw = raws[i] || null;
|
|
1919
|
+
const bitmap = raw && typeof ImageBitmap !== 'undefined' && raw.bitmap instanceof ImageBitmap ? raw.bitmap : null;
|
|
1920
|
+
dispatch('overlays', c, { ...context, bitmap });
|
|
1921
|
+
});
|
|
1922
|
+
for (const c of r.resources) {
|
|
1923
|
+
dispatch('resources', c, context);
|
|
1924
|
+
}
|
|
1925
|
+
if (r.camera) {
|
|
1926
|
+
dispatch('camera', r.camera, context);
|
|
1927
|
+
}
|
|
1928
|
+
if (r.time) {
|
|
1929
|
+
dispatch('time', r.time, context);
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
// A summary of the packages on screen, for the page check and for authors.
|
|
1934
|
+
status() {
|
|
1935
|
+
return {
|
|
1936
|
+
contract: CONTRACT,
|
|
1937
|
+
epoch: this.epoch,
|
|
1938
|
+
reset: this.resetInfo,
|
|
1939
|
+
clocks: this.clocks.snapshot(),
|
|
1940
|
+
dropped: { ...this.drop, commands: { ...dropped } },
|
|
1941
|
+
effects: this.effects.snapshot(),
|
|
1942
|
+
post: this.post.snapshot(),
|
|
1943
|
+
audio: this.audio.snapshot(),
|
|
1944
|
+
moments: this.moments.snapshot(),
|
|
1945
|
+
flash: { counts: { ...this.flashCounts }, clamped: this.flash.clamped, factor: this.flashFactor(), events: this.flash.events.slice(-8) },
|
|
1946
|
+
bent: this.bent || null,
|
|
1947
|
+
geometries: [...this.geometries.keys()],
|
|
1948
|
+
custody: this.custody.holder,
|
|
1949
|
+
tracks: this.ledger.tracks.size,
|
|
1950
|
+
safety: SAFETY,
|
|
1951
|
+
ladder: LADDER,
|
|
1952
|
+
packages: this.packages.map((pkg) => (pkg ? {
|
|
1953
|
+
team: pkg.teamId, side: pkg.side, name: pkg.manifest.name || null, developer: pkg.developer, status: pkg.status,
|
|
1954
|
+
detail: pkg.detail, level: pkg.levels.level, missing: pkg.levels.missing, lacking: pkg.levels.lacking,
|
|
1955
|
+
worker: !!pkg.manifest.worker, starting: !!pkg.hostPending, sealed: pkg.host ? pkg.host.sealed : null, late: pkg.host ? pkg.host.late : 0,
|
|
1956
|
+
answered: pkg.host ? pkg.host.answered : 0, failures: pkg.host ? pkg.host.failures.slice() : [],
|
|
1957
|
+
budget: pkg.budget.snapshot(), spentMs: pkg.lastSpent || 0, lastResponse: pkg.lastResponse || null, log: pkg.log || [],
|
|
1958
|
+
warnings: pkg.served.warnings || [], errors: pkg.errors.slice(),
|
|
1959
|
+
} : null)),
|
|
1960
|
+
entities: [...this.entities.values()].map((e) => ({
|
|
1961
|
+
id: e.id, side: e.side, number: e.number, goalkeeper: e.goalkeeper, seed: e.seeds.entity, driver: e.driver,
|
|
1962
|
+
bounds: e.bounds(), envelope: e.envelope, anchor: e.anchor.slice(), distance: e.distance,
|
|
1963
|
+
behaviours: [...e.behaviours.items.keys()], attachments: e.attachments.map((a) => a.name),
|
|
1964
|
+
overlay: e.overlay ? e.overlay.role : null, visible: e.visible, reach: e.reach || null,
|
|
1965
|
+
actions: e.animator ? [...e.animator.actions.values()].slice(-3).map((x) => ({ role: x.role, clip: x.clip, contactT: x.contactT, rate: x.schedule.rate })) : [],
|
|
1966
|
+
})),
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
dispose() {
|
|
1971
|
+
for (const pkg of this.packages) {
|
|
1972
|
+
if (pkg) {
|
|
1973
|
+
pkg.dispose();
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
this.effects.dispose();
|
|
1977
|
+
this.post.dispose();
|
|
1978
|
+
this.audio.dispose();
|
|
1979
|
+
this.moments.end();
|
|
1980
|
+
this.moments.disposeSlots();
|
|
1981
|
+
this.packages = [null, null];
|
|
1982
|
+
this.entities.clear();
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
// The matrix of the behaviours' offset of an attachment in its socket frame.
|
|
1987
|
+
function attachmentOffset(o) {
|
|
1988
|
+
const q = new THREE.Quaternion().setFromEuler(new THREE.Euler(o.rotX, o.rotY, o.rotZ, 'XYZ'));
|
|
1989
|
+
for (const spin of o.spins) {
|
|
1990
|
+
q.multiply(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(...spin.axis).normalize(), spin.angle));
|
|
1991
|
+
}
|
|
1992
|
+
const s = Math.max(0.05, 1 + o.scale);
|
|
1993
|
+
return new THREE.Matrix4().compose(new THREE.Vector3(o.x, o.y, o.z), q, new THREE.Vector3(s, s, s));
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
// A numeric property of the entity's own materials that a materialParam behaviour drives, such
|
|
1997
|
+
// as emissiveIntensity or opacity, on copies the entity owns.
|
|
1998
|
+
function setMaterialParam(instance, p) {
|
|
1999
|
+
const owned = instance.presentationParams || (instance.presentationParams = new Map());
|
|
2000
|
+
instance.root.traverse((obj) => {
|
|
2001
|
+
if (!obj.isMesh) {
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
const list = Array.isArray(obj.material) ? obj.material : [obj.material];
|
|
2005
|
+
list.forEach((mat, i) => {
|
|
2006
|
+
const own = mat.userData && mat.userData.cuju && mat.userData.cuju.own && mat.userData.cuju.own[p.uniform];
|
|
2007
|
+
if ((p.material === '*' || mat.name === p.material) && own && typeof own.value === 'number') {
|
|
2008
|
+
// A package uniform of a custom shader, which the material owns already.
|
|
2009
|
+
if (mat.userData.cujuBase === undefined || !(p.uniform in mat.userData.cujuBase)) {
|
|
2010
|
+
mat.userData.cujuBase = { ...(mat.userData.cujuBase || {}), [p.uniform]: own.value };
|
|
2011
|
+
}
|
|
2012
|
+
own.value = mat.userData.cujuBase[p.uniform] + (p.value - mat.userData.cujuBase[p.uniform]) * p.weight;
|
|
2013
|
+
return;
|
|
2014
|
+
}
|
|
2015
|
+
if (!(p.material === '*' || mat.name === p.material) || typeof mat[p.uniform] !== 'number') {
|
|
2016
|
+
return;
|
|
2017
|
+
}
|
|
2018
|
+
let copy = owned.get(mat);
|
|
2019
|
+
if (!copy && !instance.materials.includes(mat)) {
|
|
2020
|
+
copy = mat.clone();
|
|
2021
|
+
instance.materials.push(copy);
|
|
2022
|
+
owned.set(mat, copy);
|
|
2023
|
+
if (Array.isArray(obj.material)) {
|
|
2024
|
+
obj.material[i] = copy;
|
|
2025
|
+
} else {
|
|
2026
|
+
obj.material = copy;
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
const target = copy || mat;
|
|
2030
|
+
if (target.userData.presentationBase === undefined) {
|
|
2031
|
+
target.userData.presentationBase = target[p.uniform];
|
|
2032
|
+
}
|
|
2033
|
+
target[p.uniform] = target.userData.presentationBase + (p.value - target.userData.presentationBase) * p.weight;
|
|
2034
|
+
});
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
// The heading of a player's forward in three's frame, from the frame data.
|
|
2039
|
+
function headingOf(data, o) {
|
|
2040
|
+
const x = data[o + 3];
|
|
2041
|
+
const y = data[o + 4];
|
|
2042
|
+
const z = data[o + 5];
|
|
2043
|
+
const w = data[o + 6];
|
|
2044
|
+
const fx = 2 * (x * y - w * z);
|
|
2045
|
+
const fy = 1 - 2 * (x * x + z * z);
|
|
2046
|
+
return Math.atan2(-fx, fy);
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
// The heading of a player's forward in the pitch frame, the angle from positive x toward
|
|
2050
|
+
// positive y.
|
|
2051
|
+
function pitchHeading(nodes, o) {
|
|
2052
|
+
const x = nodes[o + 3];
|
|
2053
|
+
const y = nodes[o + 4];
|
|
2054
|
+
const z = nodes[o + 5];
|
|
2055
|
+
const w = nodes[o + 6];
|
|
2056
|
+
// GRF's player faces along minus y of his own frame.
|
|
2057
|
+
const fx = -2 * (x * y - w * z);
|
|
2058
|
+
const fy = -(1 - 2 * (x * x + z * z));
|
|
2059
|
+
return Math.atan2(fy, fx);
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
function toPitch(v) {
|
|
2063
|
+
return [v.x, -v.z, v.y];
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
export { boneIndex, roleOf };
|