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.
Files changed (382) hide show
  1. cuju/render/__init__.py +759 -0
  2. cuju/render/__main__.py +1065 -0
  3. cuju/render/_export/__init__.py +3 -0
  4. cuju/render/_export/feed.py +542 -0
  5. cuju/render/_export/sizes.py +157 -0
  6. cuju/render/_export/video.py +1618 -0
  7. cuju/render/_export/video_jobs.py +408 -0
  8. cuju/render/_format/__init__.py +3 -0
  9. cuju/render/_format/annotations.py +235 -0
  10. cuju/render/_format/codec.py +307 -0
  11. cuju/render/_format/keep.py +121 -0
  12. cuju/render/_format/recording.py +860 -0
  13. cuju/render/_format/writer.py +54 -0
  14. cuju/render/_guide/__init__.py +3 -0
  15. cuju/render/_guide/doctor.py +523 -0
  16. cuju/render/_guide/help.py +62 -0
  17. cuju/render/_guide/tutorial.py +254 -0
  18. cuju/render/_http/__init__.py +3 -0
  19. cuju/render/_http/commands.py +57 -0
  20. cuju/render/_http/headers.py +103 -0
  21. cuju/render/_http/launch.py +500 -0
  22. cuju/render/_http/launchers.py +408 -0
  23. cuju/render/_http/pwa.py +128 -0
  24. cuju/render/_http/server.py +2105 -0
  25. cuju/render/_http/window.py +360 -0
  26. cuju/render/_moments/__init__.py +3 -0
  27. cuju/render/_moments/captions.py +284 -0
  28. cuju/render/_moments/events.py +1123 -0
  29. cuju/render/_moments/search.py +694 -0
  30. cuju/render/_packages/__init__.py +3 -0
  31. cuju/render/_packages/glsl.py +746 -0
  32. cuju/render/_packages/loudness.py +334 -0
  33. cuju/render/_packages/pack.py +1959 -0
  34. cuju/render/_packages/presentation.py +1376 -0
  35. cuju/render/_packages/vocabulary.py +609 -0
  36. cuju/render/_playing/__init__.py +3 -0
  37. cuju/render/_playing/achievements.py +463 -0
  38. cuju/render/_playing/bench.py +609 -0
  39. cuju/render/_playing/challenges.py +1813 -0
  40. cuju/render/_playing/demo.py +323 -0
  41. cuju/render/_playing/draw.py +211 -0
  42. cuju/render/_playing/errors.py +20 -0
  43. cuju/render/_playing/game.py +645 -0
  44. cuju/render/_playing/limits.py +339 -0
  45. cuju/render/_playing/play.py +926 -0
  46. cuju/render/_playing/policy_worker.py +250 -0
  47. cuju/render/_playing/strict.py +810 -0
  48. cuju/render/_registry/__init__.py +3 -0
  49. cuju/render/_registry/clips.py +394 -0
  50. cuju/render/_registry/joints.py +108 -0
  51. cuju/render/_registry/teams.py +2058 -0
  52. cuju/render/_store/__init__.py +3 -0
  53. cuju/render/_store/home.py +70 -0
  54. cuju/render/_store/library.py +604 -0
  55. cuju/render/_store/samples.py +163 -0
  56. cuju/render/_text/__init__.py +3 -0
  57. cuju/render/_text/languages.py +637 -0
  58. cuju/render/_text/messages.py +1396 -0
  59. cuju/render/_tournaments/__init__.py +3 -0
  60. cuju/render/_tournaments/results.py +547 -0
  61. cuju/render/_tournaments/tournament.py +2742 -0
  62. cuju/render/_tournaments/tournament_cli.py +587 -0
  63. cuju/render/_tournaments/tournament_runner.py +1975 -0
  64. cuju/render/_version.py +6 -0
  65. cuju/render/_watch/__init__.py +3 -0
  66. cuju/render/_watch/grid.py +265 -0
  67. cuju/render/_watch/live.py +664 -0
  68. cuju/render/_watch/notebook.py +79 -0
  69. cuju/render/_watch/show.py +171 -0
  70. cuju/render/samples/sample-11v11.cjr +0 -0
  71. cuju/render/samples/sample-5v5.cjr +0 -0
  72. cuju/render/samples/teams/starter/main.py +33 -0
  73. cuju/render/scenarios/benchmark_full_game_11_vs_11_easy.py +46 -0
  74. cuju/render/scenarios/benchmark_full_game_11_vs_11_hard.py +46 -0
  75. cuju/render/scenarios/benchmark_full_game_11_vs_11_medium.py +46 -0
  76. cuju/render/scenarios/benchmark_full_game_5_vs_5_easy.py +34 -0
  77. cuju/render/scenarios/benchmark_full_game_5_vs_5_hard.py +34 -0
  78. cuju/render/scenarios/benchmark_full_game_5_vs_5_medium.py +34 -0
  79. cuju/render/web/assets/adboard_polygon.webp +0 -0
  80. cuju/render/web/assets/adboard_your_ad_here.webp +0 -0
  81. cuju/render/web/assets/animations/kaykit-rig-medium-combatmelee.glb +0 -0
  82. cuju/render/web/assets/animations/kaykit-rig-medium-general.glb +0 -0
  83. cuju/render/web/assets/animations/kaykit-rig-medium-movementadvanced.glb +0 -0
  84. cuju/render/web/assets/animations/kaykit-rig-medium-movementbasic.glb +0 -0
  85. cuju/render/web/assets/animations/kaykit-rig-medium-simulation.glb +0 -0
  86. cuju/render/web/assets/animations/kaykit-rig-medium-special.glb +0 -0
  87. cuju/render/web/assets/ball.glb +0 -0
  88. cuju/render/web/assets/challenges/3_vs_1_with_keeper.mp4 +0 -0
  89. cuju/render/web/assets/challenges/3_vs_1_with_keeper.webp +0 -0
  90. cuju/render/web/assets/challenges/corner.mp4 +0 -0
  91. cuju/render/web/assets/challenges/corner.webp +0 -0
  92. cuju/render/web/assets/challenges/counterattack_easy.mp4 +0 -0
  93. cuju/render/web/assets/challenges/counterattack_easy.webp +0 -0
  94. cuju/render/web/assets/challenges/counterattack_hard.mp4 +0 -0
  95. cuju/render/web/assets/challenges/counterattack_hard.webp +0 -0
  96. cuju/render/web/assets/challenges/empty_goal.mp4 +0 -0
  97. cuju/render/web/assets/challenges/empty_goal.webp +0 -0
  98. cuju/render/web/assets/challenges/empty_goal_close.mp4 +0 -0
  99. cuju/render/web/assets/challenges/empty_goal_close.webp +0 -0
  100. cuju/render/web/assets/challenges/manifest.json +375 -0
  101. cuju/render/web/assets/challenges/one_on_one.mp4 +0 -0
  102. cuju/render/web/assets/challenges/one_on_one.webp +0 -0
  103. cuju/render/web/assets/challenges/one_on_one_hard.mp4 +0 -0
  104. cuju/render/web/assets/challenges/one_on_one_hard.webp +0 -0
  105. cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.mp4 +0 -0
  106. cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.webp +0 -0
  107. cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.mp4 +0 -0
  108. cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.webp +0 -0
  109. cuju/render/web/assets/challenges/run_to_score.mp4 +0 -0
  110. cuju/render/web/assets/challenges/run_to_score.webp +0 -0
  111. cuju/render/web/assets/challenges/run_to_score_with_keeper.mp4 +0 -0
  112. cuju/render/web/assets/challenges/run_to_score_with_keeper.webp +0 -0
  113. cuju/render/web/assets/challenges/single_goal_versus_lazy.mp4 +0 -0
  114. cuju/render/web/assets/challenges/single_goal_versus_lazy.webp +0 -0
  115. cuju/render/web/assets/crowd.webp +0 -0
  116. cuju/render/web/assets/crowd_normal.webp +0 -0
  117. cuju/render/web/assets/cuju-logo-384.png +0 -0
  118. cuju/render/web/assets/cuju-logo.png +0 -0
  119. cuju/render/web/assets/cuju-logo.svg +46 -0
  120. cuju/render/web/assets/cuju-mark-light.svg +33 -0
  121. cuju/render/web/assets/cuju-mark.svg +33 -0
  122. cuju/render/web/assets/goal.glb +0 -0
  123. cuju/render/web/assets/grass.webp +0 -0
  124. cuju/render/web/assets/hair_black.png +0 -0
  125. cuju/render/web/assets/hair_blonde.png +0 -0
  126. cuju/render/web/assets/hair_brown.png +0 -0
  127. cuju/render/web/assets/hair_darkblonde.png +0 -0
  128. cuju/render/web/assets/hair_long01.glb +0 -0
  129. cuju/render/web/assets/hair_long02.glb +0 -0
  130. cuju/render/web/assets/hair_medium01.glb +0 -0
  131. cuju/render/web/assets/hair_red.png +0 -0
  132. cuju/render/web/assets/hair_short01.glb +0 -0
  133. cuju/render/web/assets/hair_short02.glb +0 -0
  134. cuju/render/web/assets/icons/cuju-192.png +0 -0
  135. cuju/render/web/assets/icons/cuju-512.png +0 -0
  136. cuju/render/web/assets/icons/cuju-maskable-512.png +0 -0
  137. cuju/render/web/assets/kit_goalkeeper.webp +0 -0
  138. cuju/render/web/assets/kit_mask.png +0 -0
  139. cuju/render/web/assets/kit_normal.webp +0 -0
  140. cuju/render/web/assets/manifest.json +601 -0
  141. cuju/render/web/assets/models/kaykit-barbarian.glb +0 -0
  142. cuju/render/web/assets/models/kaykit-barbarian.json +23 -0
  143. cuju/render/web/assets/models/kaykit-knight.glb +0 -0
  144. cuju/render/web/assets/models/kaykit-knight.json +23 -0
  145. cuju/render/web/assets/models/kaykit-mage.glb +0 -0
  146. cuju/render/web/assets/models/kaykit-mage.json +23 -0
  147. cuju/render/web/assets/models/kaykit-mannequin-medium.glb +0 -0
  148. cuju/render/web/assets/models/kaykit-mannequin-medium.json +23 -0
  149. cuju/render/web/assets/models/kaykit-ranger.glb +0 -0
  150. cuju/render/web/assets/models/kaykit-ranger.json +23 -0
  151. cuju/render/web/assets/models/kaykit-rogue-hooded.glb +0 -0
  152. cuju/render/web/assets/models/kaykit-rogue-hooded.json +23 -0
  153. cuju/render/web/assets/models/kaykit-rogue.glb +0 -0
  154. cuju/render/web/assets/models/kaykit-rogue.json +23 -0
  155. cuju/render/web/assets/models/kaykit-skeleton-mage.glb +0 -0
  156. cuju/render/web/assets/models/kaykit-skeleton-mage.json +23 -0
  157. cuju/render/web/assets/models/kaykit-skeleton-minion.glb +0 -0
  158. cuju/render/web/assets/models/kaykit-skeleton-minion.json +23 -0
  159. cuju/render/web/assets/models/kaykit-skeleton-rogue.glb +0 -0
  160. cuju/render/web/assets/models/kaykit-skeleton-rogue.json +23 -0
  161. cuju/render/web/assets/models/kaykit-skeleton-warrior.glb +0 -0
  162. cuju/render/web/assets/models/kaykit-skeleton-warrior.json +23 -0
  163. cuju/render/web/assets/pitch.webp +0 -0
  164. cuju/render/web/assets/pitch_normal.webp +0 -0
  165. cuju/render/web/assets/player.glb +0 -0
  166. cuju/render/web/assets/shoe.webp +0 -0
  167. cuju/render/web/assets/shoe_sole.png +0 -0
  168. cuju/render/web/assets/skin_01.png +0 -0
  169. cuju/render/web/assets/skin_02.png +0 -0
  170. cuju/render/web/assets/skin_03.png +0 -0
  171. cuju/render/web/assets/skin_04.png +0 -0
  172. cuju/render/web/assets/sounds/applause.ogg +0 -0
  173. cuju/render/web/assets/sounds/beach-wave-1.ogg +0 -0
  174. cuju/render/web/assets/sounds/beach-wave-2.ogg +0 -0
  175. cuju/render/web/assets/sounds/beach-wave-3.ogg +0 -0
  176. cuju/render/web/assets/sounds/beach-wave-4.ogg +0 -0
  177. cuju/render/web/assets/sounds/city-horn.ogg +0 -0
  178. cuju/render/web/assets/sounds/city-loop.ogg +0 -0
  179. cuju/render/web/assets/sounds/city-siren.ogg +0 -0
  180. cuju/render/web/assets/sounds/crowd-cheer.ogg +0 -0
  181. cuju/render/web/assets/sounds/crowd-loop.ogg +0 -0
  182. cuju/render/web/assets/sounds/crowd-ooh.ogg +0 -0
  183. cuju/render/web/assets/sounds/gulls.ogg +0 -0
  184. cuju/render/web/assets/sounds/neon-sting.ogg +0 -0
  185. cuju/render/web/assets/sounds/rain-loop.ogg +0 -0
  186. cuju/render/web/assets/sounds/sounds.json +46 -0
  187. cuju/render/web/assets/sounds/space-beep.ogg +0 -0
  188. cuju/render/web/assets/sounds/space-hum.ogg +0 -0
  189. cuju/render/web/assets/sounds/space-radio.ogg +0 -0
  190. cuju/render/web/assets/sounds/whistle-long.ogg +0 -0
  191. cuju/render/web/assets/sounds/whistle-short.ogg +0 -0
  192. cuju/render/web/assets/sounds/wind-loop.ogg +0 -0
  193. cuju/render/web/easy.css +357 -0
  194. cuju/render/web/export.html +23 -0
  195. cuju/render/web/feed.css +262 -0
  196. cuju/render/web/feed.html +28 -0
  197. cuju/render/web/flat.css +120 -0
  198. cuju/render/web/home.css +837 -0
  199. cuju/render/web/index.html +373 -0
  200. cuju/render/web/js/boot.js +50 -0
  201. cuju/render/web/js/broadcast/audio.js +2141 -0
  202. cuju/render/web/js/broadcast/celebrate.js +1238 -0
  203. cuju/render/web/js/broadcast/decisions.js +609 -0
  204. cuju/render/web/js/broadcast/hud.js +352 -0
  205. cuju/render/web/js/broadcast/show.js +3614 -0
  206. cuju/render/web/js/broadcast/transition.js +2231 -0
  207. cuju/render/web/js/broadcast/voices.js +153 -0
  208. cuju/render/web/js/capture.js +101 -0
  209. cuju/render/web/js/core/accessibility.js +90 -0
  210. cuju/render/web/js/core/api.js +429 -0
  211. cuju/render/web/js/core/comfort.js +135 -0
  212. cuju/render/web/js/core/i18n.js +705 -0
  213. cuju/render/web/js/core/icons.js +167 -0
  214. cuju/render/web/js/core/input-settings.js +156 -0
  215. cuju/render/web/js/core/keys.js +277 -0
  216. cuju/render/web/js/core/language-ui.js +125 -0
  217. cuju/render/web/js/core/menu.js +853 -0
  218. cuju/render/web/js/core/names.js +113 -0
  219. cuju/render/web/js/core/page-structure.js +110 -0
  220. cuju/render/web/js/core/scenarios.js +109 -0
  221. cuju/render/web/js/core/spoilers.js +236 -0
  222. cuju/render/web/js/core/typeahead.js +38 -0
  223. cuju/render/web/js/export/dom-picture.js +330 -0
  224. cuju/render/web/js/export/export-host.js +97 -0
  225. cuju/render/web/js/export/feed-dialog.js +191 -0
  226. cuju/render/web/js/export/feed-params.js +266 -0
  227. cuju/render/web/js/export/feed.js +363 -0
  228. cuju/render/web/js/export/mp4-mux.js +295 -0
  229. cuju/render/web/js/export/photo-core.js +313 -0
  230. cuju/render/web/js/export/photo.js +1314 -0
  231. cuju/render/web/js/export/safe-frame.js +59 -0
  232. cuju/render/web/js/export/size-fields.js +103 -0
  233. cuju/render/web/js/export/sizes.js +178 -0
  234. cuju/render/web/js/export/video-boot.js +55 -0
  235. cuju/render/web/js/export/video-browser.js +325 -0
  236. cuju/render/web/js/export/video-export.js +417 -0
  237. cuju/render/web/js/export/video-plan.js +207 -0
  238. cuju/render/web/js/export/video-range.js +185 -0
  239. cuju/render/web/js/export/webm-mux.js +198 -0
  240. cuju/render/web/js/feed-boot.js +151 -0
  241. cuju/render/web/js/feed-frame.js +101 -0
  242. cuju/render/web/js/help/doctor.js +488 -0
  243. cuju/render/web/js/help/firstrun.js +379 -0
  244. cuju/render/web/js/help/help-center.js +438 -0
  245. cuju/render/web/js/help/install-offer.js +164 -0
  246. cuju/render/web/js/help/install-state.js +104 -0
  247. cuju/render/web/js/help/lessons-core.js +207 -0
  248. cuju/render/web/js/help/lessons.js +463 -0
  249. cuju/render/web/js/help/palette.js +584 -0
  250. cuju/render/web/js/help/pwa.js +257 -0
  251. cuju/render/web/js/help/tour-core.js +241 -0
  252. cuju/render/web/js/help/tour.js +461 -0
  253. cuju/render/web/js/main.js +2513 -0
  254. cuju/render/web/js/pages/draw.js +188 -0
  255. cuju/render/web/js/pages/fieldpage.js +530 -0
  256. cuju/render/web/js/pages/home.js +521 -0
  257. cuju/render/web/js/pages/matches.js +779 -0
  258. cuju/render/web/js/pages/moments-ui.js +359 -0
  259. cuju/render/web/js/pages/queue-filters.js +63 -0
  260. cuju/render/web/js/pages/recording-groups.js +80 -0
  261. cuju/render/web/js/pages/recordings.js +1069 -0
  262. cuju/render/web/js/play/bench.js +347 -0
  263. cuju/render/web/js/play/challenges.js +1302 -0
  264. cuju/render/web/js/play/medals.js +127 -0
  265. cuju/render/web/js/play/play.js +1953 -0
  266. cuju/render/web/js/play/teasers.js +196 -0
  267. cuju/render/web/js/play/touch.js +350 -0
  268. cuju/render/web/js/play/tournament-layout.js +487 -0
  269. cuju/render/web/js/play/tournament-results.js +441 -0
  270. cuju/render/web/js/play/tournament-strict.js +560 -0
  271. cuju/render/web/js/play/tournament.js +2585 -0
  272. cuju/render/web/js/players/animate.js +972 -0
  273. cuju/render/web/js/players/clips.js +224 -0
  274. cuju/render/web/js/players/kaykit.js +162 -0
  275. cuju/render/web/js/players/kits.js +676 -0
  276. cuju/render/web/js/players/number-patch.js +82 -0
  277. cuju/render/web/js/players/players.js +2694 -0
  278. cuju/render/web/js/players/recolor.js +893 -0
  279. cuju/render/web/js/players/retarget.js +325 -0
  280. cuju/render/web/js/players/rig-numbers.js +174 -0
  281. cuju/render/web/js/presentation/animator.js +231 -0
  282. cuju/render/web/js/presentation/assign.js +85 -0
  283. cuju/render/web/js/presentation/behaviors.js +440 -0
  284. cuju/render/web/js/presentation/budget.js +209 -0
  285. cuju/render/web/js/presentation/catalog.js +1674 -0
  286. cuju/render/web/js/presentation/clocks.js +72 -0
  287. cuju/render/web/js/presentation/commands.js +301 -0
  288. cuju/render/web/js/presentation/contract.js +240 -0
  289. cuju/render/web/js/presentation/effects.js +904 -0
  290. cuju/render/web/js/presentation/flash.js +605 -0
  291. cuju/render/web/js/presentation/freeze-worklet.js +22 -0
  292. cuju/render/web/js/presentation/glsl.js +464 -0
  293. cuju/render/web/js/presentation/host.js +323 -0
  294. cuju/render/web/js/presentation/index.js +2066 -0
  295. cuju/render/web/js/presentation/loudness-worklet.js +235 -0
  296. cuju/render/web/js/presentation/loudness.js +740 -0
  297. cuju/render/web/js/presentation/moments.js +536 -0
  298. cuju/render/web/js/presentation/post.js +327 -0
  299. cuju/render/web/js/presentation/preview.js +180 -0
  300. cuju/render/web/js/presentation/protocol.js +174 -0
  301. cuju/render/web/js/presentation/reach.js +158 -0
  302. cuju/render/web/js/presentation/rigging.js +130 -0
  303. cuju/render/web/js/presentation/sandbox.js +157 -0
  304. cuju/render/web/js/presentation/shaders.js +235 -0
  305. cuju/render/web/js/presentation/stage.js +402 -0
  306. cuju/render/web/js/presentation/teamaudio.js +722 -0
  307. cuju/render/web/js/presentation/tracks.js +197 -0
  308. cuju/render/web/js/presentation/values.js +81 -0
  309. cuju/render/web/js/recording/annotation-data.js +203 -0
  310. cuju/render/web/js/recording/captions.js +491 -0
  311. cuju/render/web/js/recording/codec.js +185 -0
  312. cuju/render/web/js/recording/decode-worker.js +70 -0
  313. cuju/render/web/js/recording/decode.js +94 -0
  314. cuju/render/web/js/recording/episodes.js +46 -0
  315. cuju/render/web/js/recording/format.js +461 -0
  316. cuju/render/web/js/recording/live.js +348 -0
  317. cuju/render/web/js/recording/moments-query.js +59 -0
  318. cuju/render/web/js/recording/moments.js +149 -0
  319. cuju/render/web/js/recording/pose.js +86 -0
  320. cuju/render/web/js/recording/timeline.js +275 -0
  321. cuju/render/web/js/teams/art.js +50 -0
  322. cuju/render/web/js/teams/clip-editor.js +293 -0
  323. cuju/render/web/js/teams/editor.js +1979 -0
  324. cuju/render/web/js/teams/library.js +344 -0
  325. cuju/render/web/js/teams/painter.js +633 -0
  326. cuju/render/web/js/teams/surprise-ui.js +195 -0
  327. cuju/render/web/js/teams/surprise.js +497 -0
  328. cuju/render/web/js/teams/team-check.js +127 -0
  329. cuju/render/web/js/watch/annotations.js +270 -0
  330. cuju/render/web/js/watch/flat.js +366 -0
  331. cuju/render/web/js/watch/grid.js +436 -0
  332. cuju/render/web/js/watch/pitch2d.js +289 -0
  333. cuju/render/web/js/watch/player-tools.js +192 -0
  334. cuju/render/web/js/watch/presets.js +201 -0
  335. cuju/render/web/js/world/arenas.js +997 -0
  336. cuju/render/web/js/world/ball.js +204 -0
  337. cuju/render/web/js/world/cameras.js +982 -0
  338. cuju/render/web/js/world/crowd.js +376 -0
  339. cuju/render/web/js/world/field.js +227 -0
  340. cuju/render/web/js/world/framing.js +145 -0
  341. cuju/render/web/js/world/occlusion.js +48 -0
  342. cuju/render/web/js/world/pitch.js +703 -0
  343. cuju/render/web/js/world/scene.js +395 -0
  344. cuju/render/web/js/world/sky.js +325 -0
  345. cuju/render/web/js/world/stadium.js +1262 -0
  346. cuju/render/web/js/world/vendor-sky.js +367 -0
  347. cuju/render/web/js/world/weather.js +264 -0
  348. cuju/render/web/languages/en.json +4750 -0
  349. cuju/render/web/lessons.json +137 -0
  350. cuju/render/web/manifest.webmanifest +23 -0
  351. cuju/render/web/style.css +8399 -0
  352. cuju/render/web/sw.js +235 -0
  353. cuju/render/web/vendor/fabric/LICENSE +16 -0
  354. cuju/render/web/vendor/fabric/fabric.min.mjs +1 -0
  355. cuju/render/web/vendor/lucide/LICENSE +43 -0
  356. cuju/render/web/vendor/lucide/icons.js +141 -0
  357. cuju/render/web/vendor/three/LICENSE +21 -0
  358. cuju/render/web/vendor/three/build/three.core.js +60586 -0
  359. cuju/render/web/vendor/three/build/three.module.js +19719 -0
  360. cuju/render/web/vendor/three/examples/jsm/loaders/GLTFLoader.js +4925 -0
  361. cuju/render/web/vendor/three/examples/jsm/postprocessing/EffectComposer.js +365 -0
  362. cuju/render/web/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  363. cuju/render/web/vendor/three/examples/jsm/postprocessing/OutputPass.js +148 -0
  364. cuju/render/web/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  365. cuju/render/web/vendor/three/examples/jsm/postprocessing/RenderPass.js +193 -0
  366. cuju/render/web/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  367. cuju/render/web/vendor/three/examples/jsm/postprocessing/UnrealBloomPass.js +541 -0
  368. cuju/render/web/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  369. cuju/render/web/vendor/three/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
  370. cuju/render/web/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  371. cuju/render/web/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1501 -0
  372. cuju/render/web/vendor/three/examples/jsm/utils/SkeletonUtils.js +496 -0
  373. cuju_render-0.1.0.dist-info/METADATA +116 -0
  374. cuju_render-0.1.0.dist-info/RECORD +382 -0
  375. cuju_render-0.1.0.dist-info/WHEEL +4 -0
  376. cuju_render-0.1.0.dist-info/licenses/LICENSE +202 -0
  377. cuju_render-0.1.0.dist-info/licenses/LICENSES/CC-BY-4.0.txt +396 -0
  378. cuju_render-0.1.0.dist-info/licenses/LICENSES/CC0-1.0.txt +127 -0
  379. cuju_render-0.1.0.dist-info/licenses/LICENSES/ISC.txt +16 -0
  380. cuju_render-0.1.0.dist-info/licenses/LICENSES/MIT.txt +24 -0
  381. cuju_render-0.1.0.dist-info/licenses/LICENSES/Unlicense.txt +13 -0
  382. cuju_render-0.1.0.dist-info/licenses/NOTICE +35 -0
@@ -0,0 +1,2231 @@
1
+ // Copyright 2026 The cuju Authors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Restarts as on television. GRF moves every player to the spots of a restart within one step,
5
+ // right after the ball leaves the pitch. The viewer holds play on the last frame before that step
6
+ // while the ball runs on off the pitch and the players slow down and walk towards their spots, a
7
+ // logo wipe hides the step, the camera cuts to a view of the restart, the taker sets the ball, and
8
+ // play goes on. Half time gets a title card, and fouls, cards and offsides get the referee's
9
+ // replay from decisions.js before the restart.
10
+
11
+ import * as THREE from 'three';
12
+ import { fadeCover } from '../core/comfort.js';
13
+ import { narrowShare, turnBetween } from '../world/framing.js';
14
+ import { NODE_COUNT, NODE_FLOATS, NODE_PARENTS, NODES_FLOAT, PLAYER_FLOATS, episodeBoundary, isCut } from '../recording/format.js';
15
+ import { fullMatch } from '../recording/episodes.js';
16
+ import { teamNames } from './hud.js';
17
+ import { teamName } from '../core/names.js';
18
+ import { BALL_RADIUS, FULL_HALF_H, FULL_HALF_W, GOAL_DEPTH, GOAL_HALF_WIDTH, GOAL_HEIGHT, HALF_H, HALF_W, POST_RADIUS } from '../world/pitch.js';
19
+ import * as figures from '../players/players.js';
20
+ import * as timeline from '../recording/timeline.js';
21
+ import { t } from '../core/i18n.js';
22
+
23
+ export const HALF_TIME_MS = 45 * 60 * 1000;
24
+ // Seconds of the logo wipe, of the walk before it, of the walk before a goal's wipe and of the
25
+ // taker setting the ball after it, all in match time, so the playback speed scales them.
26
+ export const WIPE = 0.72;
27
+ const STAGE = 1.35;
28
+ const GOAL_STAGE = 1.8;
29
+ // The pre-roll after a restart is revealed, between these many seconds, before the first step.
30
+ const PREROLL_MIN = 1.5;
31
+ const PREROLL_MAX = 3;
32
+ const TITLE = 3.6;
33
+ // The farthest a player walks towards a new spot before the wipe hides the rest.
34
+ const PULL = 2.6;
35
+ const TAKER_PULL = 4.5;
36
+ // A player or the ball that moves farther than this in one step was moved by the engine.
37
+ const JUMP = 3;
38
+ const BOARD_X = FULL_HALF_W + 1.5;
39
+ const BOARD_Y = FULL_HALF_H + 1.5;
40
+ const BOARD_H = 0.9;
41
+ const BALL_RATE = 120;
42
+ const BALL_SECONDS = 6;
43
+
44
+ export const RESTART_NAMES = {
45
+ kickoff: t('transition.restart.kickoff'), goal_kick: t('transition.restart.goal_kick'),
46
+ free_kick: t('transition.restart.free_kick'), corner: t('transition.restart.corner'),
47
+ throw_in: t('transition.restart.throw_in'), penalty: t('transition.restart.penalty'),
48
+ halftime: t('transition.restart.halftime'),
49
+ };
50
+ const MODE_KINDS = [null, 'kickoff', 'goal_kick', 'free_kick', 'corner', 'throw_in', 'penalty'];
51
+
52
+ // The animation library of the figures may arrive later, the local poses stand in until then.
53
+ let animate = null;
54
+ import('../players/animate.js').then((m) => {
55
+ animate = m;
56
+ }).catch(() => {});
57
+
58
+ export const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
59
+ export const smooth = (x) => {
60
+ const t = clamp(x, 0, 1);
61
+ return t * t * (3 - 2 * t);
62
+ };
63
+
64
+ // Poses.
65
+
66
+ // Local rest positions of GRF's player skeleton, as players.js keeps them.
67
+ const REST = [
68
+ [0, 0, 0], [0, 0, 0.96], [0, 0, 0.15], [0, -0.03, 0.5], [0.16, -0.01, 0.48], [-0.01, 0, -0.33],
69
+ [-0.16, -0.01, 0.48], [0.01, 0, -0.33], [0.087, 0, -0.01], [0, 0, -0.42], [0, -0.04, -0.44],
70
+ [-0.087, 0, -0.01], [0, 0, -0.42], [0, -0.04, -0.44],
71
+ ];
72
+ const ANKLE_Z = 0.09;
73
+ const FOREARM = 0.29;
74
+
75
+ // Local joint turns of the poses that stand in for the animation library, each joint as turns
76
+ // about its own x and y axes. A turn about x below zero swings a limb forward.
77
+ const POSES = {
78
+ idle: { 4: [-0.05, -0.12], 6: [-0.05, 0.12], 5: [-0.3], 7: [-0.3], 9: [0.08], 12: [0.08] },
79
+ throw_in_hold: { 2: [-0.16], 3: [0.12], 4: [-2.75, -0.2], 6: [-2.75, 0.2], 5: [1.05], 7: [1.05], 9: [0.1], 12: [0.1] },
80
+ place_ball: {
81
+ 1: [0.3], 2: [0.7], 3: [-0.45], 4: [-1.0, -0.12], 6: [-1.0, 0.12], 5: [-0.25], 7: [-0.25],
82
+ 8: [-1.05], 9: [1.45], 10: [-0.35], 11: [-0.7], 12: [1.2], 13: [-0.45],
83
+ },
84
+ point: { 4: [-0.05, -0.12], 5: [-0.25], 6: [-1.5, 0.1], 7: [-0.05], 9: [0.05], 12: [0.05] },
85
+ whistle: { 3: [0.1], 4: [-0.05, -0.12], 5: [-0.25], 6: [-1.05, 0.5], 7: [-2.25], 9: [0.05], 12: [0.05] },
86
+ card_raise: { 2: [-0.05], 4: [-0.05, -0.12], 5: [-0.25], 6: [-2.95, 0.1], 7: [-0.08], 9: [0.05], 12: [0.05] },
87
+ hands_on_head: { 2: [0.15], 3: [0.25], 4: [-2.45, -0.6], 6: [-2.45, 0.6], 5: [-2.2], 7: [-2.2], 9: [0.12], 12: [0.12] },
88
+ };
89
+
90
+ const wq = Array.from({ length: NODE_COUNT }, () => new THREE.Quaternion());
91
+ const wp = Array.from({ length: NODE_COUNT }, () => new THREE.Vector3());
92
+ const lq = new THREE.Quaternion();
93
+ const eul = new THREE.Euler();
94
+ const tv = new THREE.Vector3();
95
+ const ZAXIS = new THREE.Vector3(0, 0, 1);
96
+ const NO_TURN = [0, 0];
97
+
98
+ // Writes one player's nodes into out at offset o from local joint turns, standing at x, y and
99
+ // facing heading, where heading zero faces engine minus y. With ground set, the lower ankle rests
100
+ // on the grass, so bent legs lower the body. Lift raises or lowers the body as a walk bobs.
101
+ export function fkPose(turns, heading, x, y, out, o = 0, ground = true, lift = 0) {
102
+ wq[0].setFromAxisAngle(ZAXIS, heading);
103
+ wp[0].set(x, y, 0);
104
+ for (let i = 1; i < NODE_COUNT; i++) {
105
+ const a = turns[i] || NO_TURN;
106
+ eul.set(a[0] || 0, a[1] || 0, a[2] || 0, 'XYZ');
107
+ lq.setFromEuler(eul);
108
+ const p = NODE_PARENTS[i];
109
+ tv.set(REST[i][0], REST[i][1], REST[i][2] + (i === 1 ? lift : 0)).applyQuaternion(wq[p]);
110
+ wp[i].copy(wp[p]).add(tv);
111
+ wq[i].copy(wq[p]).multiply(lq);
112
+ }
113
+ const dz = ground ? ANKLE_Z - Math.min(wp[10].z, wp[13].z) : 0;
114
+ for (let i = 0; i < NODE_COUNT; i++) {
115
+ const k = o + i * NODE_FLOATS;
116
+ out[k] = wp[i].x;
117
+ out[k + 1] = wp[i].y;
118
+ out[k + 2] = i === 0 ? 0 : wp[i].z + dz;
119
+ out[k + 3] = wq[i].x;
120
+ out[k + 4] = wq[i].y;
121
+ out[k + 5] = wq[i].z;
122
+ out[k + 6] = wq[i].w;
123
+ }
124
+ return out;
125
+ }
126
+
127
+ const walkTurns = Array.from({ length: NODE_COUNT }, () => [0, 0]);
128
+
129
+ // A walk or jog at speed meters per second, phase in radians, as players.js draws its walk.
130
+ export function walkPose(phase, speed, heading, x, y, out, o = 0) {
131
+ const stride = Math.min(1, speed / 6);
132
+ const s = Math.sin(phase);
133
+ const c = Math.cos(phase);
134
+ const bob = 0.035 * stride * Math.abs(c);
135
+ const t = walkTurns;
136
+ t[1][0] = 0.05 * stride;
137
+ t[2][0] = 0.1 * stride;
138
+ t[3][0] = -0.1 * stride;
139
+ t[4][0] = 0.55 * stride * s;
140
+ t[4][1] = -0.1;
141
+ t[5][0] = -0.45 - 0.6 * stride;
142
+ t[6][0] = -0.55 * stride * s;
143
+ t[6][1] = 0.1;
144
+ t[7][0] = -0.45 - 0.6 * stride;
145
+ t[8][0] = -0.6 * stride * s;
146
+ t[9][0] = 0.1 + 1.0 * stride * Math.max(0, -c);
147
+ t[10][0] = -0.2 * stride * s;
148
+ t[11][0] = 0.6 * stride * s;
149
+ t[12][0] = 0.1 + 1.0 * stride * Math.max(0, c);
150
+ t[13][0] = 0.2 * stride * s;
151
+ return fkPose(t, heading, x, y, out, o, false, -bob - 0.02 * stride);
152
+ }
153
+
154
+ // A named pose, from the animation library when it has one, else from the stand ins above.
155
+ export function namedPose(name, time, heading, x, y, out, o = 0) {
156
+ if (animate && typeof animate.pose === 'function' && (typeof animate.has !== 'function' || animate.has(name))) {
157
+ try {
158
+ const tmp = namedPose.tmp || (namedPose.tmp = new Float32Array(PLAYER_FLOATS));
159
+ if (animate.pose(name, time, tmp, { heading, x, y })) {
160
+ out.set(tmp, o);
161
+ return out;
162
+ }
163
+ } catch {
164
+ // A pose the library does not know falls back to the stand in.
165
+ }
166
+ }
167
+ return fkPose(POSES[name] || POSES.idle, heading, x, y, out, o, true);
168
+ }
169
+
170
+ // Blends two poses of one player, positions linearly and rotations by normalized lerp.
171
+ export function blendPose(a, ao, b, bo, w, out, oo) {
172
+ for (let i = 0; i < NODE_COUNT; i++) {
173
+ const pa = ao + i * NODE_FLOATS;
174
+ const pb = bo + i * NODE_FLOATS;
175
+ const po = oo + i * NODE_FLOATS;
176
+ out[po] = a[pa] + (b[pb] - a[pa]) * w;
177
+ out[po + 1] = a[pa + 1] + (b[pb + 1] - a[pa + 1]) * w;
178
+ out[po + 2] = a[pa + 2] + (b[pb + 2] - a[pa + 2]) * w;
179
+ const dot = a[pa + 3] * b[pb + 3] + a[pa + 4] * b[pb + 4] + a[pa + 5] * b[pb + 5] + a[pa + 6] * b[pb + 6];
180
+ const sb = dot < 0 ? -w : w;
181
+ const x = a[pa + 3] * (1 - w) + b[pb + 3] * sb;
182
+ const y = a[pa + 4] * (1 - w) + b[pb + 4] * sb;
183
+ const z = a[pa + 5] * (1 - w) + b[pb + 5] * sb;
184
+ const q = a[pa + 6] * (1 - w) + b[pb + 6] * sb;
185
+ const n = Math.hypot(x, y, z, q) || 1;
186
+ out[po + 3] = x / n;
187
+ out[po + 4] = y / n;
188
+ out[po + 5] = z / n;
189
+ out[po + 6] = q / n;
190
+ }
191
+ }
192
+
193
+ // The heading a player faces, read from the body node, since GRF keeps the root node turned the
194
+ // same way for a whole team.
195
+ export function headingOf(nodes, o) {
196
+ const b = o + NODE_FLOATS;
197
+ const x = nodes[b + 3];
198
+ const y = nodes[b + 4];
199
+ const z = nodes[b + 5];
200
+ const w = nodes[b + 6];
201
+ // The body's minus y axis, turned by its quaternion.
202
+ const fx = -(2 * (x * y - w * z));
203
+ const fy = -(1 - 2 * (x * x + z * z));
204
+ if (Math.abs(fx) + Math.abs(fy) < 1e-6) {
205
+ return 0;
206
+ }
207
+ return Math.atan2(fx, -fy);
208
+ }
209
+
210
+ export function headingTo(dx, dy) {
211
+ return Math.atan2(dx, -dy);
212
+ }
213
+
214
+ export function lerpAngle(a, b, w) {
215
+ let d = b - a;
216
+ while (d > Math.PI) {
217
+ d -= 2 * Math.PI;
218
+ }
219
+ while (d < -Math.PI) {
220
+ d += 2 * Math.PI;
221
+ }
222
+ return a + d * w;
223
+ }
224
+
225
+ // A hand of a pose, the end of the forearm below the elbow node, side 0 left and 1 right.
226
+ const hq = new THREE.Quaternion();
227
+ export function handOf(nodes, o, side, out) {
228
+ const e = o + (side ? 7 : 5) * NODE_FLOATS;
229
+ hq.set(nodes[e + 3], nodes[e + 4], nodes[e + 5], nodes[e + 6]);
230
+ out.set(0, 0, -FOREARM).applyQuaternion(hq);
231
+ out.x += nodes[e];
232
+ out.y += nodes[e + 1];
233
+ out.z += nodes[e + 2];
234
+ return out;
235
+ }
236
+
237
+ // Restarts in a store.
238
+
239
+ function rootJumps(a, b, players) {
240
+ let count = 0;
241
+ for (let k = 0; k < players; k++) {
242
+ if (!(a.playerFlags[k] & 1) || !(b.playerFlags[k] & 1)) {
243
+ continue;
244
+ }
245
+ const o = NODES_FLOAT + k * PLAYER_FLOATS;
246
+ if (Math.hypot(b.data[o] - a.data[o], b.data[o + 1] - a.data[o + 1]) > JUMP) {
247
+ count++;
248
+ }
249
+ }
250
+ return count;
251
+ }
252
+
253
+ // The referee's call behind a restart at index i, a foul that started within the three seconds
254
+ // before it, or an offside, which is a free kick without a foul while an attacker stands offside.
255
+ function findDecision(store, header, i, teleport, mode) {
256
+ for (let j = i + 1; j >= i - 30; j--) {
257
+ const f = store.get(j);
258
+ const g = store.get(j - 1);
259
+ if (!f || !g || isCut(g, f)) {
260
+ if (j <= i) {
261
+ break;
262
+ }
263
+ continue;
264
+ }
265
+ // A foul whose offender lies beyond the players of the header is no call of this match.
266
+ if (f.foul.type > 0 && g.foul.type === 0 && f.foul.player < header.players.length) {
267
+ const off = f.foul.player;
268
+ const secondYellow = f.foul.type === 2 && off >= 0 && !!(g.playerFlags[off] & 2);
269
+ const type = f.foul.type === 3 || secondYellow ? 'red' : (f.foul.type === 2 ? 'yellow' : 'foul');
270
+ return {
271
+ type,
272
+ offender: off,
273
+ victim: f.foul.victim < header.players.length ? f.foul.victim : -1,
274
+ call: j,
275
+ contact: j < i ? j : (teleport ? i - 1 : i),
276
+ secondYellow,
277
+ };
278
+ }
279
+ }
280
+ if (mode !== 3) {
281
+ return null;
282
+ }
283
+ let offender = -1;
284
+ for (const j of [i, i - 1, i + 1]) {
285
+ const f = store.get(j);
286
+ if (f && f.offside >= 0 && f.foul.type === 0 && (!header.offside_called || (f.flags & 4))) {
287
+ offender = f.offside;
288
+ break;
289
+ }
290
+ }
291
+ if (offender < 0 || offender >= header.players.length) {
292
+ return null;
293
+ }
294
+ // The pass. The referee marks the offside position from the pass until the call, so the
295
+ // pass is where that mark begins, else the last touch of a teammate before the call.
296
+ const team = header.players[offender].team;
297
+ let pass = -1;
298
+ let passer = -1;
299
+ for (let j = i - 1; j >= Math.max(store.first + 1, i - 80); j--) {
300
+ const f = store.get(j);
301
+ const g = store.get(j - 1);
302
+ if (!f || f.offside !== offender) {
303
+ break;
304
+ }
305
+ pass = j;
306
+ if (!g || isCut(g, f)) {
307
+ break;
308
+ }
309
+ }
310
+ if (pass >= 0) {
311
+ const f = store.get(pass);
312
+ for (let k = 0; k < header.players.length; k++) {
313
+ if (k !== offender && header.players[k].team === team && f.touches[k]) {
314
+ passer = k;
315
+ }
316
+ }
317
+ }
318
+ for (let j = i; pass < 0 && j >= Math.max(store.first + 1, i - 80); j--) {
319
+ const f = store.get(j);
320
+ const g = store.get(j - 1);
321
+ if (!f || !g || isCut(g, f)) {
322
+ break;
323
+ }
324
+ for (let k = 0; k < header.players.length; k++) {
325
+ if (k !== offender && header.players[k].team === team && f.touches[k]) {
326
+ pass = j;
327
+ passer = k;
328
+ break;
329
+ }
330
+ }
331
+ }
332
+ // The frame the engine moves things on shows the restart, so the pass is shown before it.
333
+ const contact = pass >= 0 && !(teleport && pass >= i) ? pass : i - 1;
334
+ return { type: 'offside', offender, victim: -1, passer, call: i, contact };
335
+ }
336
+
337
+ // Appends the restarts between frames from and to, each where the engine moves players or the
338
+ // ball to a restart, or where the referee stops play. Plain changes of game mode without a
339
+ // move need no transition and are left out.
340
+ export function scanRestarts(store, header, from, to, list) {
341
+ const players = header.players.length;
342
+ for (let i = Math.max(from, store.first + 1); i <= to; i++) {
343
+ const a = store.get(i - 1);
344
+ const b = store.get(i);
345
+ if (!a || !b || isCut(a, b)) {
346
+ // A new episode opens with its kick-off, which gets a pre-roll of its own.
347
+ if (a && b && episodeBoundary(a, b)) {
348
+ list.push(startEvent(i, b));
349
+ }
350
+ continue;
351
+ }
352
+ const last = list[list.length - 1];
353
+ if (last && i - last.index <= 2 && i > last.index) {
354
+ continue;
355
+ }
356
+ const next = store.get(i + 1);
357
+ const nextOk = next && !isCut(b, next);
358
+ const prev = store.get(i - 2);
359
+ const prevOk = prev && !isCut(prev, a);
360
+ const jumps = rootJumps(a, b, players);
361
+ const px = prevOk ? 2 * a.data[8] - prev.data[8] : a.data[8];
362
+ const py = prevOk ? 2 * a.data[9] - prev.data[9] : a.data[9];
363
+ const deviation = Math.hypot(b.data[8] - px, b.data[9] - py);
364
+ const goal = b.scoreLeft !== a.scoreLeft || b.scoreRight !== a.scoreRight;
365
+ let mode = b.gameMode !== a.gameMode && b.gameMode > 0 ? b.gameMode : 0;
366
+ if (!mode && nextOk && a.gameMode === 0 && b.gameMode === 0 && next.gameMode > 0 && (jumps || deviation > JUMP)) {
367
+ // Some sources write the new game mode one step after the move.
368
+ mode = next.gameMode;
369
+ }
370
+ const teleport = jumps >= 3 || ((jumps >= 1 || deviation > JUMP) && (mode > 0 || goal));
371
+ if (!teleport && !mode) {
372
+ continue;
373
+ }
374
+ const decision = findDecision(store, header, i, teleport, mode);
375
+ if (!teleport && !decision) {
376
+ continue;
377
+ }
378
+ list.push({
379
+ index: i,
380
+ mode,
381
+ kind: MODE_KINDS[mode] || 'kickoff',
382
+ teleport,
383
+ goal,
384
+ goalTeam: goal ? (b.scoreLeft > a.scoreLeft ? 0 : 1) : -1,
385
+ decision,
386
+ half: false,
387
+ taker: -1,
388
+ });
389
+ }
390
+ return list;
391
+ }
392
+
393
+ // The kick-off that opens an episode. Nothing moves into it, so it has no wipe, only a pre-roll.
394
+ export function startEvent(i, f) {
395
+ return {
396
+ index: i, mode: f.gameMode, kind: 'kickoff', teleport: false, start: true, goal: false,
397
+ goalTeam: -1, decision: null, half: false, taker: -1,
398
+ };
399
+ }
400
+
401
+ // A number from 0 to 1 that stays the same for the same seeds, for looks that replay alike.
402
+ export function hash01(a, b = 0) {
403
+ const v = Math.sin(a * 12.9898 + b * 78.233) * 43758.5453;
404
+ return v - Math.floor(v);
405
+ }
406
+
407
+ // The player who takes a restart, the first owner or toucher after it.
408
+ function takerOf(store, header, ev) {
409
+ if (ev.taker >= 0) {
410
+ return ev.taker;
411
+ }
412
+ for (let j = ev.index; j <= ev.index + 25; j++) {
413
+ const f = store.get(j);
414
+ if (!f) {
415
+ break;
416
+ }
417
+ if (f.ownedPlayer >= 0) {
418
+ ev.taker = f.ownedPlayer;
419
+ return ev.taker;
420
+ }
421
+ for (let k = 0; k < header.players.length; k++) {
422
+ if (f.touches[k]) {
423
+ ev.taker = k;
424
+ return ev.taker;
425
+ }
426
+ }
427
+ }
428
+ const f = store.get(ev.index);
429
+ let best = -1;
430
+ let bestD = Infinity;
431
+ for (let k = 0; f && k < header.players.length; k++) {
432
+ const o = NODES_FLOAT + k * PLAYER_FLOATS;
433
+ const d = Math.hypot(f.data[o] - f.data[8], f.data[o + 1] - f.data[9]);
434
+ if ((f.playerFlags[k] & 1) && d < bestD) {
435
+ bestD = d;
436
+ best = k;
437
+ }
438
+ }
439
+ return best;
440
+ }
441
+
442
+ // The ball after it leaves play. A short simulation from its last position and velocity, with
443
+ // gravity, bounces, rolling on the grass, the advertising boards and the goal nets, sampled at
444
+ // BALL_RATE per second with the distance rolled for its spin.
445
+ export function simulateBall(px, py, pz, vx, vy, vz, goal) {
446
+ const steps = BALL_SECONDS * BALL_RATE;
447
+ const out = new Float32Array((steps + 1) * 4);
448
+ const r = BALL_RADIUS;
449
+ const h = 1 / BALL_RATE;
450
+ let x = px;
451
+ let y = py;
452
+ let z = Math.max(r, pz);
453
+ let dist = 0;
454
+ let inNet = false;
455
+ let stopped = false;
456
+ // Touches of the net, each with its time, goal, point in three's frame and strength.
457
+ const impacts = [];
458
+ const touchNet = (s, side, px2, py2, pz2, speed) => {
459
+ const last = impacts[impacts.length - 1];
460
+ if (speed > 0.8 && (!last || s / BALL_RATE - last.time > 0.25)) {
461
+ impacts.push({ time: s / BALL_RATE, side: side > 0 ? 1 : 0, point: [px2, pz2, -py2], strength: clamp(speed / 22, 0.1, 1) });
462
+ }
463
+ };
464
+ const hit = POST_RADIUS + r;
465
+ // Knocks on the posts and the bar, for their sound.
466
+ const knocks = [];
467
+ const knock = (s, px2, py2, pz2, speed) => {
468
+ const last = knocks[knocks.length - 1];
469
+ if (speed > 1 && (!last || s / BALL_RATE - last.time > 0.2)) {
470
+ knocks.push({ time: s / BALL_RATE, point: [px2, pz2, -py2], strength: clamp(speed / 20, 0.15, 1) });
471
+ }
472
+ };
473
+ for (let s = 0; s <= steps; s++) {
474
+ out[s * 4] = x;
475
+ out[s * 4 + 1] = y;
476
+ out[s * 4 + 2] = z;
477
+ out[s * 4 + 3] = dist;
478
+ if (stopped) {
479
+ continue;
480
+ }
481
+ vz -= 9.81 * h;
482
+ const drag = 1 - 0.012 * h * Math.hypot(vx, vy, vz);
483
+ vx *= drag;
484
+ vy *= drag;
485
+ let nx = x + vx * h;
486
+ let ny = y + vy * h;
487
+ let nz = z + vz * h;
488
+ // The posts and the crossbar send the ball back, a goal from the frames always goes in.
489
+ if (!goal && Math.abs(Math.abs(nx) - HALF_W) < hit + 0.05) {
490
+ const gx = (Math.sign(nx) || 1) * HALF_W;
491
+ for (const py0 of [-GOAL_HALF_WIDTH, GOAL_HALF_WIDTH]) {
492
+ const dx = nx - gx;
493
+ const dy = ny - py0;
494
+ const d = Math.hypot(dx, dy);
495
+ if (d < hit && nz < GOAL_HEIGHT + POST_RADIUS && d > 1e-6) {
496
+ const ux = dx / d;
497
+ const uy = dy / d;
498
+ const vn = vx * ux + vy * uy;
499
+ if (vn < 0) {
500
+ knock(s, gx, py0, nz, -vn);
501
+ vx -= 1.6 * vn * ux;
502
+ vy -= 1.6 * vn * uy;
503
+ }
504
+ nx = gx + ux * hit;
505
+ ny = py0 + uy * hit;
506
+ }
507
+ }
508
+ if (Math.abs(ny) < GOAL_HALF_WIDTH) {
509
+ const dx = nx - gx;
510
+ const dz = nz - GOAL_HEIGHT;
511
+ const d = Math.hypot(dx, dz);
512
+ if (d < hit && d > 1e-6) {
513
+ const ux = dx / d;
514
+ const uz = dz / d;
515
+ const vn = vx * ux + vz * uz;
516
+ if (vn < 0) {
517
+ knock(s, gx, ny, GOAL_HEIGHT, -vn);
518
+ vx -= 1.6 * vn * ux;
519
+ vz -= 1.6 * vn * uz;
520
+ }
521
+ nx = gx + ux * hit;
522
+ nz = GOAL_HEIGHT + uz * hit;
523
+ }
524
+ }
525
+ }
526
+ if (!inNet && Math.abs(nx) > HALF_W && Math.abs(x) <= HALF_W) {
527
+ if (goal || (Math.abs(ny) < GOAL_HALF_WIDTH - r && nz < GOAL_HEIGHT - r)) {
528
+ inNet = true;
529
+ ny = clamp(ny, -GOAL_HALF_WIDTH + r + 0.15, GOAL_HALF_WIDTH - r - 0.15);
530
+ nz = Math.min(nz, GOAL_HEIGHT - r - 0.1);
531
+ }
532
+ }
533
+ if (inNet) {
534
+ const side = Math.sign(nx) || 1;
535
+ const back = HALF_W + GOAL_DEPTH * 0.92 - r;
536
+ if (Math.abs(nx) > back) {
537
+ // The net takes the pace off the ball and bulges where it was hit.
538
+ touchNet(s, side, side * (back + r), ny, nz, Math.hypot(vx, vy, vz));
539
+ nx = side * back;
540
+ vx = -vx * 0.1;
541
+ vy *= 0.5;
542
+ vz *= 0.4;
543
+ }
544
+ if (Math.abs(ny) > GOAL_HALF_WIDTH - r) {
545
+ touchNet(s, side, nx, Math.sign(ny) * GOAL_HALF_WIDTH, nz, Math.abs(vy) * 1.5);
546
+ ny = Math.sign(ny) * (GOAL_HALF_WIDTH - r);
547
+ vy = -vy * 0.2;
548
+ vx *= 0.7;
549
+ }
550
+ const roof = GOAL_HEIGHT * (1 - 0.15 * clamp((Math.abs(nx) - HALF_W) / GOAL_DEPTH, 0, 1)) - r;
551
+ if (nz > roof) {
552
+ touchNet(s, side, nx, ny, roof + r, Math.abs(vz) * 1.5);
553
+ nz = roof;
554
+ vz = Math.min(0, -vz * 0.2);
555
+ }
556
+ } else {
557
+ if (Math.abs(nx) > BOARD_X - r - 0.1 && Math.abs(x) <= BOARD_X - r - 0.1 && nz < BOARD_H) {
558
+ nx = Math.sign(nx) * (BOARD_X - r - 0.1);
559
+ vx = -vx * 0.4;
560
+ vy *= 0.8;
561
+ }
562
+ if (Math.abs(ny) > BOARD_Y - r - 0.1 && Math.abs(y) <= BOARD_Y - r - 0.1 && nz < BOARD_H) {
563
+ ny = Math.sign(ny) * (BOARD_Y - r - 0.1);
564
+ vy = -vy * 0.4;
565
+ vx *= 0.8;
566
+ }
567
+ // Over the boards the ball drops among the photographers and stays.
568
+ if (Math.abs(nx) > BOARD_X + 3 || Math.abs(ny) > BOARD_Y + 3) {
569
+ nx = clamp(nx, -BOARD_X - 3, BOARD_X + 3);
570
+ ny = clamp(ny, -BOARD_Y - 3, BOARD_Y + 3);
571
+ vx = 0;
572
+ vy = 0;
573
+ }
574
+ }
575
+ if (nz < r) {
576
+ nz = r;
577
+ if (vz < -0.8) {
578
+ vz = -vz * 0.5;
579
+ vx *= 0.85;
580
+ vy *= 0.85;
581
+ } else {
582
+ vz = 0;
583
+ const sp = Math.hypot(vx, vy);
584
+ const slow = Math.max(0, sp - (inNet ? 6 : 2.2) * h);
585
+ const k = sp > 1e-6 ? slow / sp : 0;
586
+ vx *= k;
587
+ vy *= k;
588
+ if (slow === 0) {
589
+ stopped = true;
590
+ }
591
+ }
592
+ }
593
+ dist += Math.hypot(nx - x, ny - y);
594
+ x = nx;
595
+ y = ny;
596
+ z = nz;
597
+ }
598
+ out.impacts = impacts;
599
+ out.knocks = knocks;
600
+ return out;
601
+ }
602
+
603
+ function sampleBall(track, time, out) {
604
+ const steps = track.length / 4 - 1;
605
+ const f = clamp(time * BALL_RATE, 0, steps);
606
+ const i = Math.min(steps - 1, Math.floor(f));
607
+ const w = f - i;
608
+ for (let c = 0; c < 4; c++) {
609
+ out[c] = track[i * 4 + c] + (track[(i + 1) * 4 + c] - track[i * 4 + c]) * w;
610
+ }
611
+ return out;
612
+ }
613
+
614
+ // The overlays, built here so the page's markup stays with its owner.
615
+
616
+ function el(tag, cls, parent, text) {
617
+ const e = document.createElement(tag);
618
+ if (cls) {
619
+ e.className = cls;
620
+ }
621
+ if (text != null) {
622
+ e.textContent = text;
623
+ }
624
+ if (parent) {
625
+ parent.appendChild(e);
626
+ }
627
+ return e;
628
+ }
629
+
630
+ export function rgb(c, alpha = 1) {
631
+ const [r, g, b] = Array.isArray(c) ? c : [128, 128, 128];
632
+ return alpha === 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${alpha})`;
633
+ }
634
+
635
+
636
+ // Shows the pointer for a moment that asks for a click or Enter, out of any pointer lock.
637
+ export function showPointer(on) {
638
+ if (on && document.pointerLockElement && document.exitPointerLock) {
639
+ document.exitPointerLock();
640
+ }
641
+ const app = document.getElementById('app');
642
+ if (app) {
643
+ app.classList.toggle('show-pointer', !!on);
644
+ }
645
+ }
646
+
647
+ class Wipe {
648
+ constructor(watch, hud) {
649
+ this.root = el('div', 'restart-wipe');
650
+ this.root.setAttribute('aria-hidden', 'true');
651
+ this.bands = [el('div', 'wipe-band lead', this.root), el('div', 'wipe-band mid', this.root), el('div', 'wipe-band trail', this.root)];
652
+ this.plate = el('div', 'wipe-plate', this.bands[1]);
653
+ // The bare mark rides the dark band, where the logo's tile would be a box in the picture.
654
+ const img = el('img', 'wipe-logo', this.plate);
655
+ img.src = 'assets/cuju-mark.svg';
656
+ img.alt = '';
657
+ this.label = el('div', 'wipe-label', this.plate);
658
+ watch.insertBefore(this.root, hud);
659
+ this.shown = false;
660
+ }
661
+
662
+ setTeams(styles) {
663
+ const c = (s, fallback) => (s && s.kit ? rgb(s.kit.primary) : fallback);
664
+ this.bands[0].style.background = c(styles && styles[0], '#b3262e');
665
+ this.bands[2].style.background = c(styles && styles[1], '#2a56b8');
666
+ }
667
+
668
+ // Progress p from 0 to 1, the screen is fully covered from about 0.3 to 0.7.
669
+ show(p, label) {
670
+ if (p == null || p <= 0 || p >= 1) {
671
+ if (this.shown) {
672
+ this.root.classList.remove('show');
673
+ this.shown = false;
674
+ }
675
+ return;
676
+ }
677
+ if (!this.shown) {
678
+ this.root.classList.add('show');
679
+ this.shown = true;
680
+ }
681
+ if (label != null && this.label.textContent !== label) {
682
+ this.label.textContent = label;
683
+ }
684
+ if (document.documentElement.classList.contains('reduced-motion')) {
685
+ // Reduced motion fades the middle band with the logo in and out in place.
686
+ this.root.style.opacity = fadeCover(p).toFixed(3);
687
+ this.bands.forEach((band, i) => {
688
+ band.style.transform = i === 1 ? 'none' : 'translateX(200vw)';
689
+ });
690
+ this.plate.style.opacity = '1';
691
+ this.plate.style.transform = 'translate(-50%, -50%)';
692
+ return;
693
+ }
694
+ this.root.style.opacity = '';
695
+ const w = this.root.clientWidth || window.innerWidth;
696
+ // The team bands lead and trail the middle band.
697
+ const lags = [0.07, 0, -0.07];
698
+ let mid = 0;
699
+ this.bands.forEach((band, i) => {
700
+ const q = clamp(p + lags[i], 0, 1);
701
+ let c;
702
+ // A band covers the screen while its centre is within a fifth of the width.
703
+ if (q < 0.33) {
704
+ c = 1.6 - 1.45 * smooth(q / 0.33);
705
+ } else if (q < 0.67) {
706
+ c = 0.15 - 0.3 * ((q - 0.33) / 0.34);
707
+ } else {
708
+ c = -0.15 - 1.45 * smooth((q - 0.67) / 0.33);
709
+ }
710
+ band.style.transform = `translateX(${(c * w).toFixed(1)}px) skewX(-14deg)`;
711
+ if (i === 1) {
712
+ mid = c;
713
+ }
714
+ });
715
+ const vis = smooth((p - 0.24) / 0.1) * (1 - smooth((p - 0.66) / 0.1));
716
+ this.plate.style.opacity = vis.toFixed(3);
717
+ // The logo rides the band in and out but holds near the middle while it covers.
718
+ const hold = -mid * w * 0.85;
719
+ this.plate.style.transform = `translate(calc(-50% + ${hold.toFixed(1)}px), -50%) skewX(14deg) scale(${(0.86 + 0.2 * p).toFixed(3)})`;
720
+ }
721
+ }
722
+
723
+ // The title card of half time and full time.
724
+ class TitleCard {
725
+ constructor(watch) {
726
+ this.root = el('div', 'title-card', watch);
727
+ this.root.hidden = true;
728
+ this.root.setAttribute('role', 'status');
729
+ const inner = el('div', 'tc-inner', this.root);
730
+ // The bare mark heads the card's dark panel, which is its surface, so it needs no tile.
731
+ const logo = el('img', 'tc-logo', inner);
732
+ logo.src = 'assets/cuju-mark.svg';
733
+ logo.alt = '';
734
+ this.kicker = el('div', 'tc-kicker', inner);
735
+ const row = el('div', 'tc-row', inner);
736
+ this.sides = [0, 1].map((side) => {
737
+ const team = el('div', `tc-team ${side ? 'right' : 'left'}`, row);
738
+ const badge = el('b', 'tc-badge', team);
739
+ const name = el('span', 'tc-name', team);
740
+ return { team, badge, name };
741
+ });
742
+ const score = el('div', 'tc-score', row);
743
+ this.scores = [el('span', '', score), el('span', '', score)];
744
+ row.insertBefore(score, this.sides[1].team);
745
+ this.foot = el('div', 'tc-foot', inner);
746
+ this.actions = el('div', 'tc-actions', inner);
747
+ }
748
+
749
+ // Shows the card, with buttons under it when actions are given.
750
+ show(kicker, header, styles, frame, foot, actions = []) {
751
+ this.kicker.textContent = kicker;
752
+ const names = header ? teamNames(header) : [t('transition.team.left'), t('transition.team.right')];
753
+ for (const side of [0, 1]) {
754
+ const s = this.sides[side];
755
+ const team = (header && header.teams[side]) || {};
756
+ const style = styles && styles[side];
757
+ s.name.textContent = names[side];
758
+ s.badge.textContent = (style && style.badge) || (teamName(team) || '?').slice(0, 1).toUpperCase();
759
+ const color = style ? rgb(style.kit.primary) : (side ? '#2a56b8' : '#b3262e');
760
+ const trim = style ? rgb(style.kit.secondary) : '#ffffff';
761
+ s.badge.style.background = color;
762
+ s.badge.style.color = trim;
763
+ s.team.style.setProperty('--team', color);
764
+ }
765
+ this.root.style.setProperty('--left', styles ? rgb(styles[0].kit.primary) : '#b3262e');
766
+ this.root.style.setProperty('--right', styles ? rgb(styles[1].kit.primary) : '#2a56b8');
767
+ this.scores[0].textContent = frame ? frame.scoreLeft : 0;
768
+ this.scores[1].textContent = frame ? frame.scoreRight : 0;
769
+ this.foot.textContent = foot || '';
770
+ this.actions.replaceChildren(...actions);
771
+ this.root.hidden = false;
772
+ showPointer(true);
773
+ // A frame later, so the entrance animates.
774
+ requestAnimationFrame(() => this.root.classList.add('show'));
775
+ }
776
+
777
+ hide() {
778
+ if (!this.root.hidden) {
779
+ showPointer(false);
780
+ }
781
+ this.root.classList.remove('show');
782
+ this.root.hidden = true;
783
+ }
784
+ }
785
+
786
+ // The referee, the figure from players.js when it has one, else a plain figure of capsules.
787
+ class SimpleReferee {
788
+ constructor(scene) {
789
+ this.group = new THREE.Group();
790
+ this.group.visible = false;
791
+ scene.add(this.group);
792
+ const shirt = new THREE.MeshStandardMaterial({ color: 0x15171c, roughness: 0.7 });
793
+ const skin = new THREE.MeshStandardMaterial({ color: 0xc89f7e, roughness: 0.8 });
794
+ const sock = new THREE.MeshStandardMaterial({ color: 0x0c0d10, roughness: 0.8 });
795
+ const limb = new THREE.CylinderGeometry(1, 1, 1, 10);
796
+ // Bones as pairs of nodes, with a radius and a material.
797
+ this.bones = [[1, 3, 0.15, shirt], [4, 5, 0.055, shirt], [6, 7, 0.055, shirt], [5, -5, 0.045, skin],
798
+ [7, -7, 0.045, skin], [8, 9, 0.075, shirt], [11, 12, 0.075, shirt], [9, 10, 0.055, sock], [12, 13, 0.055, sock]]
799
+ .map(([a, b, r, mat]) => {
800
+ const m = new THREE.Mesh(limb, mat);
801
+ m.castShadow = true;
802
+ m.userData = { a, b, r };
803
+ this.group.add(m);
804
+ return m;
805
+ });
806
+ this.head = new THREE.Mesh(new THREE.SphereGeometry(0.11, 14, 10), skin);
807
+ this.head.castShadow = true;
808
+ this.group.add(this.head);
809
+ this.card = new THREE.Mesh(new THREE.BoxGeometry(0.075, 0.105, 0.005), new THREE.MeshBasicMaterial({ color: 0xffd400 }));
810
+ this.card.visible = false;
811
+ this.group.add(this.card);
812
+ this.a = new THREE.Vector3();
813
+ this.b = new THREE.Vector3();
814
+ this.up = new THREE.Vector3(0, 1, 0);
815
+ this.hand = new THREE.Vector3();
816
+ }
817
+
818
+ point(nodes, i, out) {
819
+ if (i < 0) {
820
+ handOf(nodes, 0, i === -7 ? 1 : 0, tv);
821
+ return out.set(tv.x, tv.z, -tv.y);
822
+ }
823
+ const o = i * NODE_FLOATS;
824
+ return out.set(nodes[o], nodes[o + 2], -nodes[o + 1]);
825
+ }
826
+
827
+ update(nodes, visible) {
828
+ this.group.visible = !!visible;
829
+ if (!visible) {
830
+ return;
831
+ }
832
+ for (const m of this.bones) {
833
+ const { a, b, r } = m.userData;
834
+ this.point(nodes, a, this.a);
835
+ this.point(nodes, b, this.b);
836
+ const len = this.a.distanceTo(this.b);
837
+ m.position.addVectors(this.a, this.b).multiplyScalar(0.5);
838
+ m.quaternion.setFromUnitVectors(this.up, this.b.sub(this.a).normalize());
839
+ m.scale.set(r, len, r);
840
+ }
841
+ this.point(nodes, 3, this.a);
842
+ this.head.position.set(this.a.x, this.a.y + 0.14, this.a.z);
843
+ if (this.card.visible) {
844
+ this.point(nodes, -7, this.hand);
845
+ this.card.position.set(this.hand.x, this.hand.y + 0.06, this.hand.z);
846
+ }
847
+ }
848
+
849
+ setCard(kind) {
850
+ this.card.visible = !!kind;
851
+ if (kind) {
852
+ this.card.material.color.set(kind === 'red' ? 0xe0242b : 0xffd400);
853
+ }
854
+ }
855
+
856
+ dispose() {
857
+ this.group.removeFromParent();
858
+ }
859
+ }
860
+
861
+ // The referee's path through the match. Each frame's place follows from the frame before, a
862
+ // lagging average of the ball turned into a spot on the diagonal that referees run, kept clear of
863
+ // the ball and the players and reached through a spring of limited speed. Restarts put him at a
864
+ // spot near the ball, where he waits until play resumes. Every frame is computed once in order
865
+ // and kept, so any time on the timeline finds him where playing up to it leaves him.
866
+ const REF_TOP_SPEED = 7;
867
+ const REF_SPRING = 1.3;
868
+
869
+ export function refereeAnchor(ev, f) {
870
+ const sx = f.data[8];
871
+ const sy = f.data[9];
872
+ if (ev.kind === 'kickoff') {
873
+ return [sx - 3, sy - 11];
874
+ }
875
+ let cx = -sx;
876
+ let cy = -sy;
877
+ const cl = Math.hypot(cx, cy);
878
+ if (cl < 1) {
879
+ cx = 0;
880
+ cy = -1;
881
+ } else {
882
+ cx /= cl;
883
+ cy /= cl;
884
+ }
885
+ return [clamp(sx + cx * 9 - cy * 3, -HALF_W + 1, HALF_W - 1), clamp(sy + cy * 9 + cx * 3, -HALF_H + 1, HALF_H - 1)];
886
+ }
887
+
888
+ class RefereePath {
889
+ constructor() {
890
+ this.states = new WeakMap();
891
+ this.next = -1;
892
+ this.prev = null;
893
+ this.wait = null;
894
+ }
895
+
896
+ // The spot a referee wants for a ball, on the diagonal from the left corner of the far
897
+ // touch line to the right corner of the near one, leaning towards the ball and 9 m off it.
898
+ target(bx, by, ball, f, players) {
899
+ const ax = -32;
900
+ const ay = 22;
901
+ const dx = 64;
902
+ const dy = -44;
903
+ const t = clamp(((bx - ax) * dx + (by - ay) * dy) / (dx * dx + dy * dy), -0.1, 1.1);
904
+ let tx = ax + dx * t;
905
+ let ty = ay + dy * t;
906
+ tx += (bx - tx) * 0.35;
907
+ ty += (by - ty) * 0.35;
908
+ let ox = tx - ball[0];
909
+ let oy = ty - ball[1];
910
+ const od = Math.hypot(ox, oy);
911
+ if (od < 9) {
912
+ if (od < 1e-3) {
913
+ ox = 0;
914
+ oy = -1;
915
+ } else {
916
+ ox /= od;
917
+ oy /= od;
918
+ }
919
+ tx = ball[0] + ox * 9;
920
+ ty = ball[1] + oy * 9;
921
+ }
922
+ // Clear of the players, loosely.
923
+ for (let k = 0; k < players; k++) {
924
+ if (!(f.playerFlags[k] & 1)) {
925
+ continue;
926
+ }
927
+ const o = NODES_FLOAT + k * PLAYER_FLOATS;
928
+ const px = tx - f.data[o];
929
+ const py = ty - f.data[o + 1];
930
+ const d = Math.hypot(px, py);
931
+ if (d < 2.5 && d > 1e-3) {
932
+ tx += (px / d) * (2.5 - d);
933
+ ty += (py / d) * (2.5 - d);
934
+ }
935
+ }
936
+ return [clamp(tx, -HALF_W + 1, HALF_W - 1), clamp(ty, -HALF_H + 1, HALF_H - 1)];
937
+ }
938
+
939
+ // Computes the frames from the last one done up to to.
940
+ extend(store, header, to, eventAt, sps) {
941
+ const players = header.players.length;
942
+ const dt = 1 / sps;
943
+ let i = Math.max(this.next, store.first);
944
+ for (; i <= to; i++) {
945
+ const f = store.get(i);
946
+ if (!f) {
947
+ continue;
948
+ }
949
+ const g = this.prev && this.prev.index === i - 1 ? store.get(i - 1) : null;
950
+ const ball = [f.data[8], f.data[9]];
951
+ const ev = eventAt(i);
952
+ const s = new Float32Array(7);
953
+ const p = this.prev ? this.prev.state : null;
954
+ if (ev && (ev.teleport || ev.start)) {
955
+ // A restart places him, and he waits there until the ball is played.
956
+ const anchor = refereeAnchor(ev, f);
957
+ s.set([anchor[0], anchor[1], 0, 0, ball[0], ball[1], p ? p[6] : 0]);
958
+ let until = i + 8;
959
+ for (let j = i + 1; j <= i + 40; j++) {
960
+ const h = store.get(j);
961
+ if (!h) {
962
+ break;
963
+ }
964
+ if (h.gameMode === 0) {
965
+ until = j;
966
+ break;
967
+ }
968
+ }
969
+ this.wait = { anchor, until };
970
+ } else if (!p || !g || isCut(g, f)) {
971
+ const t = this.target(ball[0], ball[1], ball, f, players);
972
+ s.set([t[0], t[1], 0, 0, ball[0], ball[1], p ? p[6] : 0]);
973
+ this.wait = null;
974
+ } else {
975
+ const k = 1 - Math.exp(-dt / 1.1);
976
+ const bx = p[4] + (ball[0] - p[4]) * k;
977
+ const by = p[5] + (ball[1] - p[5]) * k;
978
+ let t;
979
+ if (this.wait && i <= this.wait.until) {
980
+ t = this.wait.anchor;
981
+ } else {
982
+ this.wait = null;
983
+ t = this.target(bx, by, ball, f, players);
984
+ }
985
+ let x = p[0];
986
+ let y = p[1];
987
+ let vx = p[2];
988
+ let vy = p[3];
989
+ const w = REF_SPRING;
990
+ const h = dt / 4;
991
+ for (let n = 0; n < 4; n++) {
992
+ vx += (w * w * (t[0] - x) - 2 * w * vx) * h;
993
+ vy += (w * w * (t[1] - y) - 2 * w * vy) * h;
994
+ const sp = Math.hypot(vx, vy);
995
+ if (sp > REF_TOP_SPEED) {
996
+ vx *= REF_TOP_SPEED / sp;
997
+ vy *= REF_TOP_SPEED / sp;
998
+ }
999
+ x += vx * h;
1000
+ y += vy * h;
1001
+ }
1002
+ s.set([x, y, vx, vy, bx, by, p[6] + Math.hypot(x - p[0], y - p[1])]);
1003
+ }
1004
+ this.states.set(f, s);
1005
+ this.prev = { index: i, state: s };
1006
+ }
1007
+ this.next = Math.max(this.next, i);
1008
+ }
1009
+
1010
+ get(store, i) {
1011
+ const f = store.get(i);
1012
+ return f ? this.states.get(f) || null : null;
1013
+ }
1014
+ }
1015
+
1016
+ export class Transitions {
1017
+ constructor(app) {
1018
+ this.app = app;
1019
+ this.store = null;
1020
+ this.events = [];
1021
+ this.scanned = 0;
1022
+ this.seq = null;
1023
+ this.after = null;
1024
+ this.passed = -1;
1025
+ this.prevT = null;
1026
+ this.ownSeek = false;
1027
+ this.referee = null;
1028
+ this.refNodes = new Float32Array(PLAYER_FLOATS);
1029
+ this.tmpA = new Float32Array(PLAYER_FLOATS);
1030
+ this.tmpB = new Float32Array(PLAYER_FLOATS);
1031
+ this.ballTmp = new Float32Array(4);
1032
+ this.vec = new THREE.Vector3();
1033
+ this.camera = null;
1034
+ this.decisions = null;
1035
+ this.refPath = new RefereePath();
1036
+ this.refDrawn = false;
1037
+ const watch = document.getElementById('watch');
1038
+ const hud = document.getElementById('hud');
1039
+ this.wipe = new Wipe(watch, hud);
1040
+ this.title = new TitleCard(watch);
1041
+ app.poseHooks.push((pose, sample, dt) => this.dress(pose, sample, dt));
1042
+ }
1043
+
1044
+ get active() {
1045
+ return !!this.seq;
1046
+ }
1047
+
1048
+ get skippable() {
1049
+ return !!this.seq;
1050
+ }
1051
+
1052
+ // Whether a sound or banner that main.js plays for frame j was already played here, the
1053
+ // restart whistle, the half time whistle, the goal and the kick of a teleported ball.
1054
+ suppress(j, kind) {
1055
+ const s = this.seq || this.after;
1056
+ if (kind === 'kick') {
1057
+ return this.events.some((e) => e.teleport && (j === e.index || j === e.index + 1));
1058
+ }
1059
+ if (!s) {
1060
+ return false;
1061
+ }
1062
+ if (kind === 'goal') {
1063
+ return !!s.goalAnnounced && s.T === j;
1064
+ }
1065
+ if (kind === 'half') {
1066
+ return !!s.halfWhistled && Math.abs(s.T - j) <= 25;
1067
+ }
1068
+ return s.T === j;
1069
+ }
1070
+
1071
+ // Event lists.
1072
+
1073
+ reset(store) {
1074
+ this.abort(false);
1075
+ this.store = store;
1076
+ this.events = [];
1077
+ this.scanned = store ? store.first + 1 : 0;
1078
+ this.passed = -1;
1079
+ this.after = null;
1080
+ this.halfIndex = -1;
1081
+ this.halfReal = false;
1082
+ this.halfPending = -1;
1083
+ this.halfTimes = new Set();
1084
+ this.refPath = new RefereePath();
1085
+ this.scan();
1086
+ // A match opened at its start plays the pre-roll of its first kick-off.
1087
+ const tl = this.app.timeline;
1088
+ this.prevT = tl && store && tl.t <= store.first + 1 ? store.first - 1e-3 : null;
1089
+ }
1090
+
1091
+ scan() {
1092
+ const store = this.store;
1093
+ if (!store || store.size < 3) {
1094
+ return;
1095
+ }
1096
+ const header = this.app.source.header;
1097
+ if (this.events.length && this.events[0].index < store.first) {
1098
+ this.events = this.events.filter((e) => e.index >= store.first);
1099
+ }
1100
+ // The last frame waits for its successor, which may carry the new game mode.
1101
+ const to = store.last - 1;
1102
+ if (to < this.scanned) {
1103
+ return;
1104
+ }
1105
+ if (this.scanned === store.first + 1 && !this.events.length) {
1106
+ const f = store.get(store.first);
1107
+ if (f && f.step === 0) {
1108
+ this.events.push(startEvent(store.first, f));
1109
+ }
1110
+ }
1111
+ scanRestarts(store, header, this.scanned, to, this.events);
1112
+ this.findHalf(this.scanned, to);
1113
+ this.scanned = to + 1;
1114
+ // A recording's last frame gets his place too, a live one waits for the next frame,
1115
+ // which may show a restart there.
1116
+ const tl = this.app.timeline;
1117
+ this.refPath.extend(store, header, tl && tl.live ? to : to + 1, (i) => this.eventAt(i), tl ? tl.sps : 10);
1118
+ }
1119
+
1120
+ // Half time, the first frame of the second half by the clock. Only a scenario with a second
1121
+ // half, such as 11_vs_11_kaggle, stops play there, and the engine moves the players to the
1122
+ // kick-off on the next step, while the game mode it reports stays at normal play. That move
1123
+ // shows the title card in place of the wipe. Elsewhere the clock runs on through 45 minutes
1124
+ // and the match has no half time.
1125
+ findHalf(from, to) {
1126
+ const store = this.store;
1127
+ const half = this.app.source.header.second_half;
1128
+ if (!(half > 0)) {
1129
+ return;
1130
+ }
1131
+ const halfTime = half * 1800;
1132
+ const start = this.halfPending >= 0 ? Math.min(from, this.halfPending) : from;
1133
+ this.halfPending = -1;
1134
+ for (let i = Math.max(start, store.first + 1); i <= to; i++) {
1135
+ const a = store.get(i - 1);
1136
+ const b = store.get(i);
1137
+ if (a && b && (b.step <= a.step || (b.flags & 2))) {
1138
+ this.halfIndex = -1;
1139
+ this.halfReal = false;
1140
+ }
1141
+ if (this.halfIndex < 0 && a && b && !isCut(a, b) && a.timeMs < halfTime && b.timeMs >= halfTime) {
1142
+ const near = this.events.find((e) => e.teleport && !e.goal && e.index >= i - 2 && e.index - i <= 20);
1143
+ if (!near && to - i < 20) {
1144
+ // The kick-off may still be on its way, so the frame is looked at again on the
1145
+ // next scan.
1146
+ this.halfPending = i;
1147
+ return;
1148
+ }
1149
+ this.halfIndex = i;
1150
+ this.halfReal = !!near;
1151
+ if (near) {
1152
+ near.half = true;
1153
+ this.halfTimes.add(i);
1154
+ }
1155
+ }
1156
+ }
1157
+ }
1158
+
1159
+ // Whether the frame is the start of a real half time, for the double whistle.
1160
+ isHalfTime(j) {
1161
+ return this.halfTimes.has(j);
1162
+ }
1163
+
1164
+ eventAt(index) {
1165
+ const list = this.events;
1166
+ let lo = 0;
1167
+ let hi = list.length - 1;
1168
+ while (lo <= hi) {
1169
+ const mid = (lo + hi) >> 1;
1170
+ if (list[mid].index === index) {
1171
+ return list[mid];
1172
+ }
1173
+ if (list[mid].index < index) {
1174
+ lo = mid + 1;
1175
+ } else {
1176
+ hi = mid - 1;
1177
+ }
1178
+ }
1179
+ return null;
1180
+ }
1181
+
1182
+ // The frame loop, called after the timeline moves and before it is sampled.
1183
+
1184
+ update(dt) {
1185
+ const app = this.app;
1186
+ const tl = app.timeline;
1187
+ if (!tl || !app.source) {
1188
+ return;
1189
+ }
1190
+ if (tl.store !== this.store) {
1191
+ this.reset(tl.store);
1192
+ }
1193
+ if (tl.live) {
1194
+ this.scan();
1195
+ }
1196
+ this.ownSeek = false;
1197
+ if (this.seq) {
1198
+ if (app.director.running || app.postMatch.running) {
1199
+ this.abort(true);
1200
+ } else {
1201
+ this.runSeq(dt);
1202
+ }
1203
+ } else {
1204
+ this.maybeStart();
1205
+ }
1206
+ this.updateAfter(dt);
1207
+ this.prevT = tl.t;
1208
+ }
1209
+
1210
+ enabled() {
1211
+ const s = this.app.settings;
1212
+ return s.transitions !== false;
1213
+ }
1214
+
1215
+ maybeStart() {
1216
+ const app = this.app;
1217
+ const tl = app.timeline;
1218
+ const t0 = this.prevT;
1219
+ const t1 = tl.t;
1220
+ if (t0 == null || !tl.playing || tl.direction <= 0 || t1 <= t0 || t1 - t0 > 8) {
1221
+ if (t0 != null && t1 < this.passed - 1) {
1222
+ this.passed = -1;
1223
+ }
1224
+ return;
1225
+ }
1226
+ if (app.director.running || app.postMatch.running) {
1227
+ return;
1228
+ }
1229
+ for (const ev of this.events) {
1230
+ if (ev.index - 1 > t1) {
1231
+ break;
1232
+ }
1233
+ if (ev.index <= this.passed) {
1234
+ continue;
1235
+ }
1236
+ // Play parked on a restart's first frame, as after a goal's replays, or the kick-off
1237
+ // that opens an episode, plays the pre-roll alone.
1238
+ const parked = (ev.teleport && Math.abs(t0 - ev.index) < 1e-6) || (ev.start && t0 <= ev.index && t1 > ev.index);
1239
+ const crossing = !ev.start && ev.index > t0 && t1 >= ev.index - 1;
1240
+ if (parked || crossing) {
1241
+ if (parked ? this.enabled() : this.wanted(ev)) {
1242
+ this.start(ev, parked);
1243
+ }
1244
+ this.passed = Math.max(this.passed, ev.index);
1245
+ return;
1246
+ }
1247
+ }
1248
+ }
1249
+
1250
+ // Decision replays and restart transitions each have a setting of their own.
1251
+ wanted(ev) {
1252
+ if (ev.decision && this.decisions && this.app.settings.decisionReplays !== false) {
1253
+ return true;
1254
+ }
1255
+ return this.enabled() && (ev.kind === 'halftime' || ev.teleport);
1256
+ }
1257
+
1258
+ // Sequences. A sequence is a run of scenes, each holding or driving the timeline and
1259
+ // dressing the pose, with a wipe on the boundaries that ask for one.
1260
+
1261
+ start(ev, prerollOnly = false) {
1262
+ const app = this.app;
1263
+ const tl = app.timeline;
1264
+ const store = tl.store;
1265
+ const header = app.source.header;
1266
+ const T = ev.index;
1267
+ takerOf(store, header, ev);
1268
+ const seq = {
1269
+ ev, T, clock: 0, idx: -1, scenes: [], starts: [], local: 0,
1270
+ following: tl.following, label: RESTART_NAMES[ev.kind] || '',
1271
+ preroll: PREROLL_MIN + (PREROLL_MAX - PREROLL_MIN) * hash01(T, 7),
1272
+ };
1273
+ this.wipe.setTeams(app.styles);
1274
+ this.prepareStage(seq);
1275
+ if (prerollOnly) {
1276
+ seq.prerollOnly = true;
1277
+ seq.scenes = [this.setupScene(seq, false)];
1278
+ } else if (ev.decision && this.decisions && app.settings.decisionReplays !== false) {
1279
+ seq.scenes = this.decisions.scenes(seq);
1280
+ } else {
1281
+ seq.scenes = this.restartScenes(seq);
1282
+ }
1283
+ let at = 0;
1284
+ for (const s of seq.scenes) {
1285
+ seq.starts.push(at);
1286
+ at += s.dur;
1287
+ }
1288
+ seq.total = at;
1289
+ this.seq = seq;
1290
+ this.after = null;
1291
+ this.enter(seq, 0);
1292
+ tl.t = seq.scenes[0].at(seq, 0);
1293
+ }
1294
+
1295
+ // The scenes of a restart. The walk, the wipe with the cut, the taker setting the ball.
1296
+ restartScenes(seq, options = {}) {
1297
+ const ev = seq.ev;
1298
+ const T = seq.T;
1299
+ const scenes = [];
1300
+ if (ev.kind === 'halftime') {
1301
+ // The clock reaches half time in open play. The card covers a held frame, and play
1302
+ // runs into the frame again under the wipe that takes it away.
1303
+ const sps = this.app.timeline.sps;
1304
+ return [
1305
+ { name: 'hold', dur: WIPE / 2, at: () => T - 1, dress: (pose, l) => this.dressStage(pose, seq, l, 0) },
1306
+ this.titleScene(seq, RESTART_NAMES.halftime, t('transition.halftime.foot')),
1307
+ { name: 'resume', dur: WIPE / 2, wipe: true, at: (s, l) => T - 1 - (WIPE / 2 - l) * sps, dress: () => {} },
1308
+ ];
1309
+ }
1310
+ if (!options.skipStage) {
1311
+ const stage = ev.goal ? GOAL_STAGE : (ev.teleport ? STAGE : 0.4);
1312
+ scenes.push({
1313
+ name: 'stage', dur: stage + WIPE / 2,
1314
+ at: () => T - 1,
1315
+ dress: (pose, l) => this.dressStage(pose, seq, l, 1),
1316
+ enter: () => {
1317
+ if (options.stopWhistle) {
1318
+ this.whistle([0.3]);
1319
+ }
1320
+ },
1321
+ });
1322
+ }
1323
+ if (ev.half) {
1324
+ scenes.push(this.titleScene(seq, RESTART_NAMES.halftime, t('transition.halftime.foot')));
1325
+ }
1326
+ scenes.push(this.setupScene(seq));
1327
+ return scenes;
1328
+ }
1329
+
1330
+ // The restart after the cut, with the camera on it, then the pre-roll, where the players idle
1331
+ // and wander a little, the taker sets the ball, and every one of them is back on the pose of
1332
+ // the restart's first step when the referee whistles. Without a wipe the scene is the
1333
+ // pre-roll alone, as at the kick-off that opens a match.
1334
+ setupScene(seq, wipe = true) {
1335
+ const tl = this.app.timeline;
1336
+ const lead = wipe ? WIPE / 2 : 0;
1337
+ seq.setupLead = lead;
1338
+ return {
1339
+ name: 'setup', dur: lead + seq.preroll, wipe, wipeLabel: seq.label,
1340
+ at: () => (seq.liveCut ? seq.liveT : seq.T),
1341
+ dress: (pose, l) => {
1342
+ if (!seq.liveCut) {
1343
+ this.dressSetup(pose, seq, l);
1344
+ }
1345
+ },
1346
+ enter: () => {
1347
+ // A live view that fell far behind during a replay goes back to live under the
1348
+ // wipe, as a broadcast returns to live play after a replay.
1349
+ const delay = typeof timeline.LIVE_DELAY_FRAMES === 'number' ? timeline.LIVE_DELAY_FRAMES : 4;
1350
+ if (seq.following && tl.live && seq.decision && tl.last - seq.T > delay + 40) {
1351
+ seq.liveCut = true;
1352
+ seq.liveT = Math.max(tl.first, tl.last - delay);
1353
+ seq.wipeLabel = t('transition.wipe.live');
1354
+ this.giveCamera(true);
1355
+ return;
1356
+ }
1357
+ if (wipe && !seq.ev.start) {
1358
+ this.takeCamera(this.restartShot(seq), true);
1359
+ }
1360
+ },
1361
+ };
1362
+ }
1363
+
1364
+ titleScene(seq, kicker, foot = '') {
1365
+ const T = seq.T;
1366
+ return {
1367
+ name: 'title', dur: WIPE / 2 + TITLE + WIPE / 2, wipe: true,
1368
+ at: () => (seq.ev.teleport ? T : T - 1),
1369
+ dress: () => {},
1370
+ enter: () => {
1371
+ const app = this.app;
1372
+ const frame = app.timeline.store.get(T);
1373
+ if (!seq.halfWhistled) {
1374
+ seq.halfWhistled = true;
1375
+ this.whistle([0.45, 0.9]);
1376
+ }
1377
+ this.title.show(kicker, app.source.header, app.styles, frame, foot);
1378
+ },
1379
+ exit: () => this.title.hide(),
1380
+ };
1381
+ }
1382
+
1383
+ enter(seq, idx) {
1384
+ seq.idx = idx;
1385
+ const scene = seq.scenes[idx];
1386
+ if (scene.enter) {
1387
+ scene.enter(seq);
1388
+ }
1389
+ }
1390
+
1391
+ runSeq(dt) {
1392
+ const app = this.app;
1393
+ const tl = app.timeline;
1394
+ const seq = this.seq;
1395
+ if (tl.playing && tl.direction < 0) {
1396
+ this.abort(true);
1397
+ return;
1398
+ }
1399
+ const d = tl.playing ? dt * Math.max(0.05, tl.speed) : 0;
1400
+ seq.clock += d;
1401
+ while (seq.idx < seq.scenes.length && seq.clock >= seq.starts[seq.idx] + seq.scenes[seq.idx].dur) {
1402
+ const done = seq.scenes[seq.idx];
1403
+ if (done.exit) {
1404
+ done.exit(seq);
1405
+ }
1406
+ if (seq.idx + 1 >= seq.scenes.length) {
1407
+ this.release(seq);
1408
+ return;
1409
+ }
1410
+ this.enter(seq, seq.idx + 1);
1411
+ }
1412
+ const scene = seq.scenes[seq.idx];
1413
+ seq.local = seq.clock - seq.starts[seq.idx];
1414
+ const t = scene.at(seq, seq.local);
1415
+ if (Math.abs(t - tl.t) > 5) {
1416
+ this.ownSeek = true;
1417
+ }
1418
+ tl.t = t;
1419
+ // The wipe, centred on each boundary that asks for one.
1420
+ let p = null;
1421
+ let label = seq.label;
1422
+ for (let i = 0; i < seq.scenes.length; i++) {
1423
+ if (seq.scenes[i].wipe && Math.abs(seq.clock - seq.starts[i]) < WIPE / 2) {
1424
+ p = (seq.clock - seq.starts[i] + WIPE / 2) / WIPE;
1425
+ if (seq.scenes[i].wipeLabel != null) {
1426
+ label = seq.scenes[i].wipeLabel;
1427
+ }
1428
+ if (seq.liveCut && i === seq.idx) {
1429
+ label = seq.wipeLabel;
1430
+ }
1431
+ break;
1432
+ }
1433
+ }
1434
+ this.wipe.show(p, label);
1435
+ if (scene.update) {
1436
+ scene.update(seq, seq.local, d);
1437
+ }
1438
+ }
1439
+
1440
+ // The end of a sequence, play goes on from the restart.
1441
+ release(seq) {
1442
+ const app = this.app;
1443
+ const tl = app.timeline;
1444
+ const ev = seq.ev;
1445
+ this.seq = null;
1446
+ this.wipe.show(null);
1447
+ this.title.hide();
1448
+ this.clearScore(seq);
1449
+ if (seq.liveCut) {
1450
+ if (this.decisions) {
1451
+ this.decisions.end(seq);
1452
+ }
1453
+ tl.goLive();
1454
+ this.ownSeek = true;
1455
+ this.passed = Math.max(this.passed, Math.ceil(tl.t));
1456
+ this.after = null;
1457
+ return;
1458
+ }
1459
+ tl.t = seq.T;
1460
+ this.passed = Math.max(this.passed, seq.T);
1461
+ const store = tl.store;
1462
+ // Play resumes once the game mode returns to normal after the restart.
1463
+ let resume = seq.T + 6;
1464
+ for (let j = seq.T; j <= seq.T + 40; j++) {
1465
+ const f = store.get(j);
1466
+ if (!f) {
1467
+ break;
1468
+ }
1469
+ if (f.gameMode === 0 && j > seq.T) {
1470
+ resume = j;
1471
+ break;
1472
+ }
1473
+ }
1474
+ this.after = {
1475
+ ev, T: seq.T, clock: 0, resume: resume + 4, taker: seq.setupTaker || null,
1476
+ ball: seq.setupBall || null, goalAnnounced: seq.goalAnnounced, halfWhistled: seq.halfWhistled,
1477
+ };
1478
+ if (this.decisions) {
1479
+ this.decisions.end(seq);
1480
+ }
1481
+ // The referee's whistle ends the pre-roll and play starts.
1482
+ if (ev.kind === 'kickoff') {
1483
+ this.whistle([0.35]);
1484
+ } else if (ev.mode > 0) {
1485
+ this.whistle([0.3]);
1486
+ }
1487
+ }
1488
+
1489
+ // Stops a sequence at once, after a seek, a reverse or a replay of the director. The view
1490
+ // stays where the timeline is.
1491
+ abort(restoreCamera) {
1492
+ const seq = this.seq;
1493
+ this.seq = null;
1494
+ this.after = null;
1495
+ this.wipe.show(null);
1496
+ this.title.hide();
1497
+ if (seq && this.decisions) {
1498
+ this.decisions.end(seq);
1499
+ }
1500
+ this.clearScore(seq);
1501
+ if (restoreCamera !== false) {
1502
+ this.giveCamera(true);
1503
+ } else {
1504
+ this.camera = null;
1505
+ }
1506
+ }
1507
+
1508
+ clearScore(seq) {
1509
+ if (seq && seq.scoreShown && typeof this.app.hud.scoreOf === 'function') {
1510
+ this.app.hud.scoreOf(null);
1511
+ }
1512
+ }
1513
+
1514
+ afterSeek() {
1515
+ if (this.ownSeek) {
1516
+ return;
1517
+ }
1518
+ if (this.seq || this.after) {
1519
+ this.abort(true);
1520
+ }
1521
+ this.passed = -1;
1522
+ this.prevT = this.app.timeline ? this.app.timeline.t : null;
1523
+ if (this.fullShown) {
1524
+ // A seek away from the end takes the full time card down and lets it show again.
1525
+ clearTimeout(this.fullTimer);
1526
+ this.title.hide();
1527
+ this.fullShown = null;
1528
+ }
1529
+ }
1530
+
1531
+ skip() {
1532
+ const seq = this.seq;
1533
+ if (!seq) {
1534
+ return;
1535
+ }
1536
+ for (let i = seq.idx; i < seq.scenes.length; i++) {
1537
+ if (seq.scenes[i].exit) {
1538
+ seq.scenes[i].exit(seq);
1539
+ }
1540
+ }
1541
+ this.release(seq);
1542
+ // A skip from a replay lands on the restart with its own view.
1543
+ if (this.camera && !seq.prerollOnly) {
1544
+ this.takeCamera(this.restartShot(seq), true);
1545
+ }
1546
+ this.app.cameras.jump();
1547
+ }
1548
+
1549
+ // After the release, the camera stays on the restart until play resumes, and the taker and
1550
+ // the ball blend back to the frames.
1551
+ updateAfter(dt) {
1552
+ const a = this.after;
1553
+ if (!a) {
1554
+ return;
1555
+ }
1556
+ const tl = this.app.timeline;
1557
+ a.clock += tl.playing ? dt * tl.speed : 0;
1558
+ if (this.camera && (tl.t >= a.resume || a.clock > 5)) {
1559
+ this.giveCamera(false);
1560
+ }
1561
+ if (a.clock > 2 && !this.camera) {
1562
+ this.after = null;
1563
+ }
1564
+ }
1565
+
1566
+ // A sound of the ball, which only a sequence playing forward makes.
1567
+ sound(name, position, strength) {
1568
+ const sound = this.app.sound;
1569
+ const tl = this.app.timeline;
1570
+ try {
1571
+ if (sound && typeof sound[name] === 'function' && tl && tl.playing && tl.speed <= 2.5) {
1572
+ sound[name](position, strength);
1573
+ }
1574
+ } catch {
1575
+ // Sound is a nicety.
1576
+ }
1577
+ }
1578
+
1579
+ whistle(blasts) {
1580
+ const sound = this.app.sound;
1581
+ try {
1582
+ if (sound && typeof sound.whistle === 'function') {
1583
+ sound.whistle(blasts);
1584
+ }
1585
+ } catch {
1586
+ // Sound is a nicety, a failure must not stop the show.
1587
+ }
1588
+ }
1589
+
1590
+ // Cameras.
1591
+
1592
+ takeCamera(shot, snap) {
1593
+ const cams = this.app.cameras;
1594
+ if (!this.camera) {
1595
+ if (cams.mode === 'scripted') {
1596
+ return;
1597
+ }
1598
+ this.camera = { mode: cams.mode };
1599
+ }
1600
+ cams.scripted = {
1601
+ pos: shot.pos, target: shot.target, fov: shot.fov || 40, rate: shot.rate || 3, snap: !!snap,
1602
+ };
1603
+ cams.setMode('scripted');
1604
+ }
1605
+
1606
+ // Hands the camera back to the viewer's mode, which eases there from the restart view.
1607
+ giveCamera(snap) {
1608
+ const cams = this.app.cameras;
1609
+ if (this.camera) {
1610
+ if (cams.mode === 'scripted') {
1611
+ cams.setMode(this.camera.mode);
1612
+ }
1613
+ if (snap) {
1614
+ cams.jump();
1615
+ }
1616
+ }
1617
+ this.camera = null;
1618
+ }
1619
+
1620
+ // A view of the restart, in three's frame, which is y up with engine y as minus z.
1621
+ restartShot(seq) {
1622
+ const ev = seq.ev;
1623
+ const app = this.app;
1624
+ const f = app.timeline.store.get(seq.T);
1625
+ const v = (x, y, z) => new THREE.Vector3(x, z, -y);
1626
+ const sx = f ? f.data[8] : 0;
1627
+ const sy = f ? f.data[9] : 0;
1628
+ const header = app.source.header;
1629
+ const taker = ev.taker >= 0 ? header.players[ev.taker] : null;
1630
+ const attack = taker ? (taker.team === 0 ? 1 : -1) : 1;
1631
+ switch (ev.kind) {
1632
+ case 'corner': {
1633
+ const ox = Math.sign(sx) || 1;
1634
+ const oy = Math.sign(sy) || 1;
1635
+ // From behind the flag, over the taker towards the near side of the box.
1636
+ return { pos: v(sx + ox * 6.5, sy + oy * 6.5, 4.2), target: v(ox * 47, oy * 17, 0.5), fov: 50 };
1637
+ }
1638
+ case 'throw_in': {
1639
+ const side = Math.sign(sy) || 1;
1640
+ return { pos: v(sx - attack * 15, side * (HALF_H + 4.5), 3.6), target: v(sx + attack * 7, side * (HALF_H - 9), 0.8), fov: 44 };
1641
+ }
1642
+ case 'goal_kick': {
1643
+ const side = Math.sign(sx) || 1;
1644
+ const shot = { pos: v(side * (HALF_W + 9), sy * 0.3, 4.6), target: v(side * (HALF_W - 30), 0, 0.5), fov: 46 };
1645
+ // A narrow picture turns the camera towards the ball, so the taker stays in it.
1646
+ turnBetween(shot.pos, shot.target, v(sx, sy, 0), shot.target, narrowShare(app.view.aspect));
1647
+ return shot;
1648
+ }
1649
+ case 'penalty':
1650
+ case 'free_kick': {
1651
+ const gx = attack * HALF_W;
1652
+ const dx = gx - sx;
1653
+ const dy = -sy;
1654
+ const d = Math.hypot(dx, dy) || 1;
1655
+ const back = ev.kind === 'penalty' ? 6 : 10;
1656
+ const lift = ev.kind === 'penalty' ? 2.2 : 3.6;
1657
+ const far = Math.min(18, d * 0.75);
1658
+ return {
1659
+ pos: v(sx - (dx / d) * back, sy - (dy / d) * back, lift),
1660
+ target: v(sx + (dx / d) * far, sy + (dy / d) * far, ev.kind === 'penalty' ? 1.1 : 0.5),
1661
+ fov: ev.kind === 'penalty' ? 36 : 42,
1662
+ };
1663
+ }
1664
+ default:
1665
+ return { pos: new THREE.Vector3(0, 21, 60), target: new THREE.Vector3(0, 0, 0), fov: 30 };
1666
+ }
1667
+ }
1668
+
1669
+ // Staging before the cut.
1670
+
1671
+ // Reads what the walk needs from the frames around the step, positions, velocities, the
1672
+ // spots the players walk towards and the ball's flight on.
1673
+ prepareStage(seq) {
1674
+ const app = this.app;
1675
+ const store = app.timeline.store;
1676
+ const header = app.source.header;
1677
+ const T = seq.T;
1678
+ const a = store.get(T - 1);
1679
+ const prev = store.get(T - 2);
1680
+ const b = store.get(T);
1681
+ // The kick-off that opens an episode has nothing before it to walk from.
1682
+ if (!a || !b || isCut(a, b)) {
1683
+ seq.stage = null;
1684
+ return;
1685
+ }
1686
+ const n = header.players.length;
1687
+ const sps = app.timeline.sps;
1688
+ const prevOk = prev && !isCut(prev, a);
1689
+ const st = {
1690
+ n, frame: a, x: new Float32Array(n), y: new Float32Array(n), vx: new Float32Array(n),
1691
+ vy: new Float32Array(n), dx: new Float32Array(n), dy: new Float32Array(n),
1692
+ h0: new Float32Array(n), vis: new Uint8Array(n),
1693
+ };
1694
+ const taker = seq.ev.taker;
1695
+ for (let k = 0; k < n; k++) {
1696
+ const o = NODES_FLOAT + k * PLAYER_FLOATS;
1697
+ st.vis[k] = a.playerFlags[k] & 1;
1698
+ st.x[k] = a.data[o];
1699
+ st.y[k] = a.data[o + 1];
1700
+ if (prevOk) {
1701
+ let vx = (a.data[o] - prev.data[o]) * sps;
1702
+ let vy = (a.data[o + 1] - prev.data[o + 1]) * sps;
1703
+ const sp = Math.hypot(vx, vy);
1704
+ if (sp > 9) {
1705
+ vx *= 9 / sp;
1706
+ vy *= 9 / sp;
1707
+ }
1708
+ st.vx[k] = vx;
1709
+ st.vy[k] = vy;
1710
+ }
1711
+ st.h0[k] = headingOf(a.data, o);
1712
+ // Each player walks towards the spot the engine gives him, the taker towards the ball.
1713
+ let tx = b && seq.ev.teleport ? b.data[o] : a.data[o];
1714
+ let ty = b && seq.ev.teleport ? b.data[o + 1] : a.data[o + 1];
1715
+ if (k === taker && b) {
1716
+ tx = clamp(b.data[8], -HALF_W, HALF_W);
1717
+ ty = clamp(b.data[9], -HALF_H, HALF_H);
1718
+ }
1719
+ const ddx = tx - st.x[k];
1720
+ const ddy = ty - st.y[k];
1721
+ const dist = Math.hypot(ddx, ddy);
1722
+ const cap = k === taker ? TAKER_PULL : PULL;
1723
+ const m = dist > 1e-3 ? Math.min(dist, cap) / dist : 0;
1724
+ st.dx[k] = ddx * m;
1725
+ st.dy[k] = ddy * m;
1726
+ }
1727
+ let bvx = 0;
1728
+ let bvy = 0;
1729
+ let bvz = 0;
1730
+ if (prevOk) {
1731
+ bvx = (a.data[8] - prev.data[8]) * sps;
1732
+ bvy = (a.data[9] - prev.data[9]) * sps;
1733
+ bvz = (a.data[10] - prev.data[10]) * sps;
1734
+ }
1735
+ st.ball = simulateBall(a.data[8], a.data[9], a.data[10], bvx, bvy, bvz, seq.ev.goal);
1736
+ st.ballAxis = new THREE.Vector3(-bvy, bvx, 0);
1737
+ st.ballAxis.lengthSq() > 1e-6 ? st.ballAxis.normalize() : st.ballAxis.set(1, 0, 0);
1738
+ st.ballQ = new THREE.Quaternion(a.data[11], a.data[12], a.data[13], a.data[14]);
1739
+ st.ballKnown = st.ballQ.lengthSq() > 1e-6;
1740
+ // The referee runs from his place on the path towards play, stops short and signals.
1741
+ const fx = clamp(a.data[8], -HALF_W + 3, HALF_W - 3);
1742
+ const fy = clamp(a.data[9], -HALF_H + 3, HALF_H - 3);
1743
+ const ref = this.refPath.get(store, T - 1);
1744
+ const from = ref ? [ref[0], ref[1]] : [fx, fy - 10];
1745
+ const rx = fx - from[0];
1746
+ const ry = fy - from[1];
1747
+ const rd = Math.hypot(rx, ry) || 1;
1748
+ const run = clamp(rd - 7, 0, 7);
1749
+ st.refFrom = from;
1750
+ st.refTo = [from[0] + (rx / rd) * run, from[1] + (ry / rd) * run];
1751
+ st.refDur = seq.ev.decision ? 0.8 : 1.25;
1752
+ st.spot = b ? [b.data[8], b.data[9]] : [fx, fy];
1753
+ st.focus = [fx, fy];
1754
+ seq.stage = st;
1755
+ }
1756
+
1757
+ // Root of player k at time l of the walk, its speed, and the distance walked.
1758
+ stagePos(st, k, l, pull, out) {
1759
+ const tc = 0.45;
1760
+ const dec = tc * (1 - Math.exp(-l / tc));
1761
+ const span = Math.max(0.3, st.span || 1.5);
1762
+ const w = smooth((l - 0.2) / span) * pull;
1763
+ out[0] = st.x[k] + st.vx[k] * dec + st.dx[k] * w;
1764
+ out[1] = st.y[k] + st.vy[k] * dec + st.dy[k] * w;
1765
+ out[2] = Math.hypot(st.vx[k], st.vy[k]) * dec + Math.hypot(st.dx[k], st.dy[k]) * w;
1766
+ return out;
1767
+ }
1768
+
1769
+ // The walk before the cut. Players ease from their last frame into a jog or walk, slow down
1770
+ // and head towards their spots by a few meters, the ball runs on and the referee comes in.
1771
+ dressStage(pose, seq, l, pull) {
1772
+ const st = seq.stage;
1773
+ if (!st) {
1774
+ return;
1775
+ }
1776
+ st.span = seq.scenes[0] ? seq.scenes[0].dur - 0.2 : 1.5;
1777
+ const nodes = pose.nodes;
1778
+ const p = this.stageP || (this.stageP = new Float64Array(3));
1779
+ const q = this.stageQ || (this.stageQ = new Float64Array(3));
1780
+ const fa = st.frame.data;
1781
+ const blendIn = smooth(l / 0.35);
1782
+ const bpos = sampleBall(st.ball, l, this.ballTmp);
1783
+ for (let k = 0; k < st.n; k++) {
1784
+ if (!st.vis[k]) {
1785
+ continue;
1786
+ }
1787
+ this.stagePos(st, k, l, pull, p);
1788
+ this.stagePos(st, k, l + 0.05, pull, q);
1789
+ const vx = (q[0] - p[0]) / 0.05;
1790
+ const vy = (q[1] - p[1]) / 0.05;
1791
+ const speed = Math.hypot(vx, vy);
1792
+ const toBall = headingTo(bpos[0] - p[0], bpos[1] - p[1]);
1793
+ const moving = smooth((speed - 0.25) / 0.8);
1794
+ let heading = lerpAngle(toBall, headingTo(vx, vy), moving);
1795
+ heading = lerpAngle(st.h0[k], heading, smooth(l / 0.5));
1796
+ const o = k * PLAYER_FLOATS;
1797
+ walkPose(p[2] * (2 * Math.PI / 1.45) + k * 1.3, speed, heading, p[0], p[1], this.tmpA, 0);
1798
+ // The frame's own pose, carried along with the root.
1799
+ const src = NODES_FLOAT + k * PLAYER_FLOATS;
1800
+ const sx = p[0] - st.x[k];
1801
+ const sy = p[1] - st.y[k];
1802
+ for (let i = 0; i < PLAYER_FLOATS; i += NODE_FLOATS) {
1803
+ this.tmpB[i] = fa[src + i] + sx;
1804
+ this.tmpB[i + 1] = fa[src + i + 1] + sy;
1805
+ this.tmpB[i + 2] = fa[src + i + 2];
1806
+ this.tmpB[i + 3] = fa[src + i + 3];
1807
+ this.tmpB[i + 4] = fa[src + i + 4];
1808
+ this.tmpB[i + 5] = fa[src + i + 5];
1809
+ this.tmpB[i + 6] = fa[src + i + 6];
1810
+ }
1811
+ // GRF turns the root node by team, the walk keeps that turn and the root's height.
1812
+ for (let c = 2; c < 7; c++) {
1813
+ this.tmpA[c] = this.tmpB[c];
1814
+ }
1815
+ blendPose(this.tmpB, 0, this.tmpA, 0, blendIn, nodes, o);
1816
+ }
1817
+ this.dressBall(pose, st, l);
1818
+ this.announceGoal(seq, bpos);
1819
+ this.stageReferee(seq, l);
1820
+ }
1821
+
1822
+ dressBall(pose, st, l) {
1823
+ const b = sampleBall(st.ball, l, this.ballTmp);
1824
+ // The net bulges where the ball hits it, once per touch.
1825
+ const impacts = st.ball.impacts || [];
1826
+ const pitch = this.app.pitch;
1827
+ while ((st.fired || 0) < impacts.length && impacts[st.fired || 0].time <= l) {
1828
+ const hit = impacts[st.fired || 0];
1829
+ st.fired = (st.fired || 0) + 1;
1830
+ const at = new THREE.Vector3(...hit.point);
1831
+ if (pitch && typeof pitch.netImpact === 'function') {
1832
+ try {
1833
+ pitch.netImpact(hit.side, at, hit.strength);
1834
+ } catch {
1835
+ // The net is a nicety.
1836
+ }
1837
+ }
1838
+ }
1839
+ pose.ball[0] = b[0];
1840
+ pose.ball[1] = b[1];
1841
+ pose.ball[2] = b[2];
1842
+ if (st.ballKnown) {
1843
+ const spin = this.spinQ || (this.spinQ = new THREE.Quaternion());
1844
+ spin.setFromAxisAngle(st.ballAxis, b[3] / BALL_RADIUS).multiply(st.ballQ);
1845
+ pose.ball[3] = spin.x;
1846
+ pose.ball[4] = spin.y;
1847
+ pose.ball[5] = spin.z;
1848
+ pose.ball[6] = spin.w;
1849
+ }
1850
+ }
1851
+
1852
+ // A goal is announced when the ball crosses the line, not when the engine moves the
1853
+ // players back for the kick-off.
1854
+ announceGoal(seq, b) {
1855
+ const ev = seq.ev;
1856
+ if (!ev.goal || seq.goalAnnounced || Math.abs(b[0]) < HALF_W - 0.05) {
1857
+ return;
1858
+ }
1859
+ seq.goalAnnounced = true;
1860
+ const app = this.app;
1861
+ try {
1862
+ if (app.sound && typeof app.sound.goal === 'function') {
1863
+ app.sound.goal(ev.goalTeam);
1864
+ }
1865
+ } catch {
1866
+ // Sound is optional.
1867
+ }
1868
+ app.goalBoost = 1;
1869
+ app.hud.showGoal(ev.goalTeam, true);
1870
+ // The scoreboard counts the goal now, though the frames add it at the kick-off.
1871
+ if (typeof app.hud.scoreOf === 'function') {
1872
+ app.hud.scoreOf(app.timeline.store.get(seq.T));
1873
+ seq.scoreShown = true;
1874
+ }
1875
+ }
1876
+
1877
+ // The referee. Created on first use, from players.js when it builds one.
1878
+ ensureReferee() {
1879
+ if (this.referee) {
1880
+ return this.referee;
1881
+ }
1882
+ const app = this.app;
1883
+ if (typeof figures.createReferee === 'function') {
1884
+ try {
1885
+ this.referee = figures.createReferee(app.view.scene, app.assets);
1886
+ } catch (err) {
1887
+ console.warn('referee figure failed, using a plain one', err);
1888
+ }
1889
+ }
1890
+ if (!this.referee) {
1891
+ this.referee = new SimpleReferee(app.view.scene);
1892
+ }
1893
+ return this.referee;
1894
+ }
1895
+
1896
+ showReferee(visible, card = null) {
1897
+ this.refDrawn = true;
1898
+ const ref = this.ensureReferee();
1899
+ if (this.refCard !== card) {
1900
+ this.refCard = card;
1901
+ ref.setCard(card);
1902
+ }
1903
+ ref.update(this.refNodes, visible);
1904
+ }
1905
+
1906
+ // Moves the referee along a path from a to b over dur seconds, then holds a gesture.
1907
+ refAlong(a, b, l, dur, faceX, faceY, gesture, gestureAt) {
1908
+ const w = smooth(l / dur);
1909
+ const x = a[0] + (b[0] - a[0]) * w;
1910
+ const y = a[1] + (b[1] - a[1]) * w;
1911
+ const w2 = smooth((l + 0.05) / dur);
1912
+ const speed = Math.hypot(b[0] - a[0], b[1] - a[1]) * Math.abs(w2 - w) / 0.05;
1913
+ const travel = Math.hypot(b[0] - a[0], b[1] - a[1]) * w;
1914
+ const moveHeading = headingTo(b[0] - a[0], b[1] - a[1]);
1915
+ const faceHeading = headingTo(faceX - x, faceY - y);
1916
+ const settle = smooth((l - dur + 0.25) / 0.35);
1917
+ const heading = lerpAngle(moveHeading, faceHeading, settle);
1918
+ walkPose(travel * (2 * Math.PI / 1.6), speed, heading, x, y, this.refNodes, 0);
1919
+ if (gesture && l > gestureAt) {
1920
+ namedPose(gesture, l - gestureAt, heading, x, y, this.tmpA, 0);
1921
+ blendPose(this.refNodes, 0, this.tmpA, 0, smooth((l - gestureAt) / 0.3), this.refNodes, 0);
1922
+ }
1923
+ return [x, y];
1924
+ }
1925
+
1926
+ stageReferee(seq, l) {
1927
+ const st = seq.stage;
1928
+ const ev = seq.ev;
1929
+ if (ev.goal || ev.kind === 'halftime') {
1930
+ return;
1931
+ }
1932
+ const gesture = ev.decision ? 'whistle' : 'point';
1933
+ const dur = st.refDur || 1;
1934
+ this.refAlong(st.refFrom, st.refTo, l, dur, ev.decision ? st.focus[0] : st.spot[0], ev.decision ? st.focus[1] : st.spot[1], gesture, dur - 0.05);
1935
+ this.showReferee(true);
1936
+ }
1937
+
1938
+ // After the cut, the pre-roll. Players idle, shift and glance about, wander up to about a
1939
+ // meter and come back, the taker sets the ball, and at the end every pose is the frame's own.
1940
+ dressSetup(pose, seq, l) {
1941
+ const app = this.app;
1942
+ const ev = seq.ev;
1943
+ const f = app.timeline.store.get(seq.T);
1944
+ if (!f) {
1945
+ return;
1946
+ }
1947
+ const end = seq.scenes[seq.idx] ? seq.scenes[seq.idx].dur : seq.preroll;
1948
+ const k = ev.taker;
1949
+ const dressed = k >= 0 && (f.playerFlags[k] & 1) && ev.kind !== 'kickoff';
1950
+ this.dressIdle(pose, seq, l, end, f, dressed ? k : -1);
1951
+ if (dressed) {
1952
+ const o = k * PLAYER_FLOATS;
1953
+ const x = pose.nodes[o];
1954
+ const y = pose.nodes[o + 1];
1955
+ const heading = headingOf(pose.nodes, o);
1956
+ const players = app.players;
1957
+ // A model with clips picks the ball up for a throw-in before holding it overhead.
1958
+ const lift = ev.kind === 'throw_in' ? smooth(l / 0.2) * (1 - smooth((l - 0.75) / 0.3)) : 0;
1959
+ const lifting = lift > 0 && players && typeof players.playClip === 'function'
1960
+ && players.playClip(k, 'clip:PickUp', Math.max(0, l - 0.05), lift);
1961
+ // The taker bounces the ball twice, then crouches to place it and stands behind it.
1962
+ const bounceEnd = 0.42 * end;
1963
+ const placeEnd = 0.78 * end;
1964
+ let name = null;
1965
+ let w = 0;
1966
+ if (ev.kind === 'throw_in') {
1967
+ name = 'throw_in_hold';
1968
+ w = lifting ? smooth((l - 0.75) / 0.3) : smooth(l / 0.3);
1969
+ } else {
1970
+ name = 'place_ball';
1971
+ w = smooth((l - bounceEnd + 0.15) / 0.3) * (1 - smooth((l - placeEnd) / 0.35));
1972
+ }
1973
+ if (w > 0) {
1974
+ namedPose(name, l, heading, x, y, this.tmpA, 0);
1975
+ for (let c = 2; c < 7; c++) {
1976
+ this.tmpA[c] = pose.nodes[o + c];
1977
+ }
1978
+ blendPose(pose.nodes, o, this.tmpA, 0, w, pose.nodes, o);
1979
+ }
1980
+ seq.setupTaker = seq.setupTaker || new Float32Array(PLAYER_FLOATS);
1981
+ seq.setupTaker.set(pose.nodes.subarray(o, o + PLAYER_FLOATS));
1982
+ if (ev.kind === 'throw_in') {
1983
+ const hl = handOf(pose.nodes, o, 0, this.vec).clone();
1984
+ const hr = handOf(pose.nodes, o, 1, this.vec);
1985
+ // From the ground into the hands as the taker stands up with it.
1986
+ const hold = lifting ? w : 1;
1987
+ pose.ball[0] += ((hl.x + hr.x) / 2 - pose.ball[0]) * hold;
1988
+ pose.ball[1] += ((hl.y + hr.y) / 2 - pose.ball[1]) * hold;
1989
+ pose.ball[2] += ((hl.z + hr.z) / 2 - pose.ball[2]) * hold;
1990
+ seq.setupBall = seq.setupBall || new Float32Array(3);
1991
+ seq.setupBall.set([pose.ball[0], pose.ball[1], pose.ball[2]]);
1992
+ } else if (l < placeEnd) {
1993
+ this.bounceBall(pose, x, y, heading, l, bounceEnd, placeEnd);
1994
+ }
1995
+ }
1996
+ if (ev.kind === 'halftime') {
1997
+ return;
1998
+ }
1999
+ this.setupReferee(seq, l, f, end);
2000
+ }
2001
+
2002
+ // The ball of a set piece before it is placed, two bounces beside the taker, then carried
2003
+ // low to the spot that the frame gives it.
2004
+ bounceBall(pose, x, y, heading, l, bounceEnd, placeEnd) {
2005
+ const fx = Math.sin(heading);
2006
+ const fy = -Math.cos(heading);
2007
+ const bx = x + fx * 0.38 - fy * 0.18;
2008
+ const by = y + fy * 0.38 + fx * 0.18;
2009
+ const sx = pose.ball[0];
2010
+ const sy = pose.ball[1];
2011
+ const sz = pose.ball[2];
2012
+ if (l < bounceEnd) {
2013
+ const half = bounceEnd / 2;
2014
+ const height = 0.75 * (1 - 0.35 * (l / bounceEnd));
2015
+ pose.ball[0] = bx;
2016
+ pose.ball[1] = by;
2017
+ pose.ball[2] = BALL_RADIUS + height * Math.abs(Math.sin(Math.PI * l / half));
2018
+ return;
2019
+ }
2020
+ const u = smooth((l - bounceEnd) / Math.max(0.1, placeEnd - bounceEnd));
2021
+ pose.ball[0] = bx + (sx - bx) * u;
2022
+ pose.ball[1] = by + (sy - by) * u;
2023
+ pose.ball[2] = BALL_RADIUS + (sz - BALL_RADIUS) * u + 0.22 * Math.sin(Math.PI * u);
2024
+ }
2025
+
2026
+ // Idle motion of every player but the taker, zero at the start and the end of the pre-roll.
2027
+ dressIdle(pose, seq, l, end, f, skip) {
2028
+ const n = this.app.source.header.players.length;
2029
+ const env = smooth(l / 0.8) * (1 - smooth((l - end + 0.95) / 0.8));
2030
+ if (env <= 0) {
2031
+ return;
2032
+ }
2033
+ const T = seq.T;
2034
+ const tau = 2 * Math.PI;
2035
+ for (let k = 0; k < n; k++) {
2036
+ if (k === skip || !(f.playerFlags[k] & 1)) {
2037
+ continue;
2038
+ }
2039
+ const r1 = hash01(T, k * 4 + 1);
2040
+ const r2 = hash01(T, k * 4 + 2);
2041
+ const r3 = hash01(T, k * 4 + 3);
2042
+ const r4 = hash01(T, k * 4 + 4);
2043
+ const amp = k === seq.ev.taker ? 0.15 : 0.35 + 0.35 * r1;
2044
+ const f1 = 0.14 + 0.12 * r2;
2045
+ const f2 = 0.11 + 0.12 * r3;
2046
+ const wander = (t) => [amp * Math.sin(tau * f1 * t + tau * r3), amp * Math.sin(tau * f2 * t + tau * r4)];
2047
+ const [ox, oy] = wander(l);
2048
+ const [qx, qy] = wander(l + 0.05);
2049
+ const speed = Math.hypot(qx - ox, qy - oy) / 0.05 * env;
2050
+ const o = k * PLAYER_FLOATS;
2051
+ const x0 = pose.nodes[o];
2052
+ const y0 = pose.nodes[o + 1];
2053
+ const h0 = headingOf(pose.nodes, o);
2054
+ // Glances about, a turn of the body that comes back.
2055
+ const heading = h0 + 0.5 * Math.sin(tau * (0.09 + 0.08 * r4) * l + tau * r1);
2056
+ const x = x0 + ox * env;
2057
+ const y = y0 + oy * env;
2058
+ const idle = r1 < 0.18 ? 'idle_confident' : (r1 > 0.85 ? 'idle_bounce' : 'idle');
2059
+ namedPose(idle, l + 5 * r2, heading, x, y, this.tmpA, 0);
2060
+ const step = smooth((speed - 0.1) / 0.35) * 0.8;
2061
+ if (step > 0) {
2062
+ walkPose(l * 6.5 + k, speed * 2, heading, x, y, this.tmpB, 0);
2063
+ blendPose(this.tmpA, 0, this.tmpB, 0, step, this.tmpA, 0);
2064
+ }
2065
+ for (let c = 2; c < 7; c++) {
2066
+ this.tmpA[c] = pose.nodes[o + c];
2067
+ }
2068
+ blendPose(pose.nodes, o, this.tmpA, 0, env, pose.nodes, o);
2069
+ // A model with clips shifts its weight with its own idle, over the same envelope, so
2070
+ // at the whistle it stands on the frame's pose.
2071
+ const players = this.app.players;
2072
+ if (players && typeof players.playClip === 'function') {
2073
+ players.playClip(k, r2 < 0.5 ? 'clip:Idle_A' : 'clip:Idle_B', l + 3 * r3, env * 0.9);
2074
+ }
2075
+ }
2076
+ }
2077
+
2078
+ // The referee during the pre-roll, at his place on the path, pointing to the spot, then
2079
+ // idling, then with the whistle up as it ends.
2080
+ setupReferee(seq, l, f, end) {
2081
+ const tl = this.app.timeline;
2082
+ const ref = this.refPath.get(tl.store, seq.T);
2083
+ if (!ref) {
2084
+ return;
2085
+ }
2086
+ const x = ref[0];
2087
+ const y = ref[1];
2088
+ const heading = headingTo(f.data[8] - x, f.data[9] - y);
2089
+ const idleT = seq.T / tl.sps;
2090
+ namedPose('idle', idleT, heading, x, y, this.refNodes, 0);
2091
+ const lead = seq.setupLead || 0;
2092
+ const point = smooth((l - lead - 0.1) / 0.3) * (1 - smooth((l - lead - 1.1) / 0.35));
2093
+ if (point > 0 && !seq.ev.start) {
2094
+ namedPose('point', l, heading, x, y, this.tmpB, 0);
2095
+ blendPose(this.refNodes, 0, this.tmpB, 0, point, this.refNodes, 0);
2096
+ }
2097
+ const whistleAt = Math.max(0.2, end - 0.6);
2098
+ // The whistle comes down again in the last moment so his pose meets the path's.
2099
+ const blow = smooth((l - whistleAt) / 0.25) * (1 - smooth((l - end + 0.12) / 0.1));
2100
+ if (blow > 0) {
2101
+ namedPose('whistle', l - whistleAt, heading, x, y, this.tmpB, 0);
2102
+ blendPose(this.refNodes, 0, this.tmpB, 0, blow, this.refNodes, 0);
2103
+ }
2104
+ this.showReferee(true);
2105
+ }
2106
+
2107
+ // The referee in open play, at his place on the path, jogging or walking with the distance
2108
+ // covered, facing the ball when slow and his way when fast.
2109
+ drawPathRef(pose, t) {
2110
+ const app = this.app;
2111
+ const tl = app.timeline;
2112
+ const store = tl.store;
2113
+ if (app.postMatch.running) {
2114
+ // He blows the final whistle where play left him and lowers it as play winds down,
2115
+ // then leaves the picture under the full time card.
2116
+ const r = app.postMatch.react;
2117
+ const at = r ? this.refPath.get(store, r.index) : null;
2118
+ if (!at || r.clock >= r.titleAt) {
2119
+ this.ensureReferee().update(this.refNodes, false);
2120
+ return;
2121
+ }
2122
+ const heading = headingTo(pose.ball[0] - at[0], pose.ball[1] - at[1]);
2123
+ namedPose('idle', r.clock, heading, at[0], at[1], this.refNodes, 0);
2124
+ const down = Math.max(0.3, r.titleAt - 0.8);
2125
+ const blow = smooth(r.clock / 0.25) * (1 - smooth((r.clock - down) / 0.8));
2126
+ if (blow > 0) {
2127
+ namedPose('whistle', r.clock, heading, at[0], at[1], this.tmpB, 0);
2128
+ blendPose(this.refNodes, 0, this.tmpB, 0, blow, this.refNodes, 0);
2129
+ }
2130
+ this.showReferee(true);
2131
+ return;
2132
+ }
2133
+ const i = Math.floor(t);
2134
+ const s0 = this.refPath.get(store, i);
2135
+ if (!s0) {
2136
+ this.ensureReferee().update(this.refNodes, false);
2137
+ return;
2138
+ }
2139
+ let s1 = this.refPath.get(store, i + 1);
2140
+ const next = store.get(i + 1);
2141
+ const ev = this.eventAt(i + 1);
2142
+ if (!s1 || !next || isCut(store.get(i), next) || (ev && (ev.teleport || ev.start))) {
2143
+ s1 = s0;
2144
+ }
2145
+ const w = s1 === s0 ? 0 : t - i;
2146
+ const x = s0[0] + (s1[0] - s0[0]) * w;
2147
+ const y = s0[1] + (s1[1] - s0[1]) * w;
2148
+ const vx = s0[2] + (s1[2] - s0[2]) * w;
2149
+ const vy = s0[3] + (s1[3] - s0[3]) * w;
2150
+ const dist = s0[6] + (s1[6] - s0[6]) * w;
2151
+ const speed = Math.hypot(vx, vy);
2152
+ const toBall = headingTo(pose.ball[0] - x, pose.ball[1] - y);
2153
+ const heading = speed > 0.05 ? lerpAngle(toBall, headingTo(vx, vy), smooth((speed - 2.5) / 2.5)) : toBall;
2154
+ walkPose(dist * (2 * Math.PI / 1.6), speed, heading, x, y, this.refNodes, 0);
2155
+ const still = 1 - smooth((speed - 0.15) / 0.5);
2156
+ if (still > 0) {
2157
+ // Held frames keep breathing on the sequence's clock.
2158
+ const breath = t / tl.sps + (this.seq ? this.seq.clock : 0);
2159
+ namedPose('idle', breath, heading, x, y, this.tmpB, 0);
2160
+ blendPose(this.refNodes, 0, this.tmpB, 0, still, this.refNodes, 0);
2161
+ }
2162
+ this.showReferee(true);
2163
+ }
2164
+
2165
+ // The pose hook.
2166
+
2167
+ dress(pose, sample, dt) {
2168
+ void dt;
2169
+ if (!this.store || !sample || !sample.a) {
2170
+ return;
2171
+ }
2172
+ this.refDrawn = false;
2173
+ // Never slide players across the pitch between the two frames around a teleport.
2174
+ if (sample.w > 0 && this.events.length) {
2175
+ const ev = this.eventAt(sample.index + 1);
2176
+ if (ev && ev.teleport) {
2177
+ pose.compute(sample.a, null, 0);
2178
+ }
2179
+ }
2180
+ const seq = this.seq;
2181
+ if (seq) {
2182
+ const scene = seq.scenes[seq.idx];
2183
+ if (scene && scene.dress) {
2184
+ scene.dress(pose, seq.local, seq, sample);
2185
+ }
2186
+ } else {
2187
+ this.dressAfter(pose, sample);
2188
+ }
2189
+ // The referee is on the pitch all match, wherever a scene does not place him itself.
2190
+ if (!this.refDrawn) {
2191
+ this.drawPathRef(pose, this.app.timeline.t);
2192
+ }
2193
+ }
2194
+
2195
+ dressAfter(pose, sample) {
2196
+ const a = this.after;
2197
+ if (!a || sample.index < a.T || sample.index > a.T + 30) {
2198
+ return;
2199
+ }
2200
+ const w = 1 - smooth(a.clock / 0.3);
2201
+ const k = a.ev.taker;
2202
+ if (w > 0 && a.taker && k >= 0) {
2203
+ blendPose(pose.nodes, k * PLAYER_FLOATS, a.taker, 0, w, pose.nodes, k * PLAYER_FLOATS);
2204
+ }
2205
+ if (w > 0 && a.ball) {
2206
+ for (let c = 0; c < 3; c++) {
2207
+ pose.ball[c] += (a.ball[c] - pose.ball[c]) * w;
2208
+ }
2209
+ }
2210
+ }
2211
+
2212
+ // Full time, a title card when no show after the match follows, or the end of an episode
2213
+ // outside a full match.
2214
+ fullTime() {
2215
+ const app = this.app;
2216
+ if (!app.source || app.director.running || (app.settings.podium && app.source.kind !== 'live')) {
2217
+ return;
2218
+ }
2219
+ const tl = app.timeline;
2220
+ if (this.fullShown === tl) {
2221
+ return;
2222
+ }
2223
+ this.fullShown = tl;
2224
+ const frame = tl ? tl.store.get(tl.index) : null;
2225
+ const title = fullMatch(app.source.header) ? t('transition.title.fulltime') : t('transition.title.episode');
2226
+ this.title.show(title, app.source.header, app.styles, frame, '',
2227
+ app.source.kind === 'live' ? [] : [app.postMatch.statsButton()]);
2228
+ clearTimeout(this.fullTimer);
2229
+ this.fullTimer = setTimeout(() => this.title.hide(), 4500);
2230
+ }
2231
+ }