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,1262 @@
1
+ // Copyright 2026 The cuju Authors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // A two tier bowl around the pitch. Each row of seats is a step with a painted card of people on
5
+ // it, the tiers are split by a walkway and a ribbon board, gangways run up through the seats and a
6
+ // roof on rafters covers the stands. Four floodlight towers stand behind the corners.
7
+
8
+ import * as THREE from 'three';
9
+ import { ATLAS, atlasTextures, grfCrowd, paintCrowd } from './crowd.js';
10
+ import { FULL_HALF_H, FULL_HALF_W } from './pitch.js';
11
+ import { hourOf, lightingAt } from './sky.js';
12
+
13
+ const INNER_HALF_X = FULL_HALF_W + 6;
14
+ const INNER_HALF_Z = FULL_HALF_H + 6;
15
+ const CORNER = 12;
16
+ // The shape of the stands in meters, out from the inner edge and up from the grass.
17
+ const FRONT_WALL = 1.5;
18
+ const TREAD = 0.8;
19
+ const LOWER = { rows: 18, rise: 0.38 };
20
+ const WALKWAY = 3;
21
+ const UPPER_WALL = 3.2;
22
+ const RIBBON = 1;
23
+ const UPPER = { rows: 26, rise: 0.5 };
24
+ const LOWER_END = LOWER.rows * TREAD;
25
+ const WALK_Y = FRONT_WALL + LOWER.rows * LOWER.rise;
26
+ const UPPER_D = LOWER_END + WALKWAY;
27
+ const UPPER_Y = WALK_Y + UPPER_WALL;
28
+ const DEPTH = UPPER_D + UPPER.rows * TREAD;
29
+ const TOP_Y = UPPER_Y + UPPER.rows * UPPER.rise;
30
+ // The roof rises a little towards its front edge, which pulls back at the corners so the light
31
+ // of the towers reaches the pitch over it.
32
+ const ROOF_BACK = TOP_Y + 4.6;
33
+ const ROOF_FRONT = ROOF_BACK + 2;
34
+ const ROOF_REACH = 10;
35
+ const ROOF_CORNER = 9;
36
+ // People sit a little behind the front of their tread, on a card leaning back slightly.
37
+ const CARD_AT = 0.35;
38
+ const CARD_TILT = 0.2;
39
+ // Gangways on each long side, each end and each corner, spaced evenly, and half their width.
40
+ const AISLES = { side: 8, end: 5, corner: 1 };
41
+ const AISLE_HALF = 0.6;
42
+ const PER_CORNER = 12;
43
+ // Seats taken from one stretch of the atlas before the next stretch is picked.
44
+ const CHUNK = 12;
45
+
46
+ // The floodlight masts stand just behind the corners of the stands, tall enough that their light
47
+ // clears the roof on its way to the near corner of the pitch.
48
+ const MAST_HEIGHT = 62;
49
+ const MAST_OUT = CORNER + DEPTH + 3;
50
+ // Each tower lights the whole pitch. A wide cone with a long soft edge and the physical fall off
51
+ // with distance keep the four together within about 15 percent of even.
52
+ const FLOOD_CANDELA = 14000;
53
+ const FLOOD_ANGLE = 0.7;
54
+ const FLOOD_PENUMBRA = 0.85;
55
+ // How many towers cast shadows, each one a shadow pass of its own. While the sun still casts the
56
+ // main shadow, at dusk, two towers are enough.
57
+ const FLOOD_SHADOWS = {
58
+ night: { low: 0, medium: 2, high: 4 },
59
+ dusk: { low: 0, medium: 1, high: 2 },
60
+ };
61
+ const FLOOD_SHADOW_MAP = { low: 512, medium: 1024, high: 2048 };
62
+
63
+ // Shirts for fans of a team the page knows nothing about.
64
+ const MIXED = ['#d8d8d8', '#202428', '#b3262e', '#2a56b8', '#e0b33a', '#3c8a4a', '#7a2b8a', '#e86a2a',
65
+ '#f2f2f2', '#9aa3ad', '#16365f', '#c43c3c'];
66
+ const MAX_COLORS = 12;
67
+ // How much of the light of the towers falls on the stands, at full strength.
68
+ const STAND_FLOOD = 0.3;
69
+
70
+ // Points around the bowl at a distance d out from its inner edge, counterclockwise seen from
71
+ // above, with the outward normal, the running length and the phase whose half integers are the
72
+ // middles of the gangways. Long sides and ends are cut at every whole phase, so the rafters sit
73
+ // on points.
74
+ function ring(d) {
75
+ const pts = [];
76
+ const hx = INNER_HALF_X - CORNER;
77
+ const hz = INNER_HALF_Z - CORNER;
78
+ const r = CORNER + d;
79
+ const corners = [[hx, hz, 0], [-hx, hz, Math.PI / 2], [-hx, -hz, Math.PI], [hx, -hz, Math.PI * 1.5]];
80
+ let phase = 0;
81
+ for (let c = 0; c < 4; c++) {
82
+ const [cx, cz, a0] = corners[c];
83
+ const arc = (r * Math.PI) / 2 / AISLES.corner;
84
+ for (let k = 0; k < PER_CORNER; k++) {
85
+ const t = k / PER_CORNER;
86
+ const a = a0 + (t * Math.PI) / 2;
87
+ pts.push({
88
+ x: cx + Math.cos(a) * r, z: cz + Math.sin(a) * r, nx: Math.cos(a), nz: Math.sin(a),
89
+ phase: phase + t * AISLES.corner, mpp: arc, corner: t,
90
+ });
91
+ }
92
+ phase += AISLES.corner;
93
+ const a1 = a0 + Math.PI / 2;
94
+ const nx = Math.cos(a1);
95
+ const nz = Math.sin(a1);
96
+ const [ncx, ncz] = corners[(c + 1) % 4];
97
+ const sx = cx + nx * r;
98
+ const sz = cz + nz * r;
99
+ const ex = ncx + nx * r;
100
+ const ez = ncz + nz * r;
101
+ const n = c % 2 === 0 ? AISLES.side : AISLES.end;
102
+ const mpp = Math.hypot(ex - sx, ez - sz) / n;
103
+ for (let k = 0; k < n; k++) {
104
+ const t = k / n;
105
+ pts.push({ x: sx + (ex - sx) * t, z: sz + (ez - sz) * t, nx, nz, phase: phase + k, mpp, corner: -1 });
106
+ }
107
+ phase += n;
108
+ }
109
+ pts.push({ ...pts[0], phase });
110
+ let run = 0;
111
+ pts.forEach((p, i) => {
112
+ if (i > 0) {
113
+ run += Math.hypot(p.x - pts[i - 1].x, p.z - pts[i - 1].z);
114
+ }
115
+ p.s = run;
116
+ });
117
+ return pts;
118
+ }
119
+
120
+ const rings = new Map();
121
+ function ringAt(d) {
122
+ const key = d.toFixed(3);
123
+ if (!rings.has(key)) {
124
+ rings.set(key, ring(d));
125
+ }
126
+ return rings.get(key);
127
+ }
128
+
129
+ // Vertices for the stands, each with its place along the row, its height or kind of surface,
130
+ // and the gangway phase with a third value that is a row seed or a wall height.
131
+ class Mesh {
132
+ constructor() {
133
+ this.pos = [];
134
+ this.crowd = [];
135
+ this.aisle = [];
136
+ this.place = [];
137
+ this.uv = [];
138
+ this.index = [];
139
+ this.count = 0;
140
+ }
141
+
142
+ // A band between two lines of the same number of vertices.
143
+ band(a, b) {
144
+ for (let i = 0; i < a.length; i++) {
145
+ for (const p of [a[i], b[i]]) {
146
+ this.pos.push(p.x, p.y, p.z);
147
+ this.crowd.push(p.s || 0, p.v || 0);
148
+ this.aisle.push(p.phase || 0, p.mpp || 1, p.w || 0);
149
+ this.place.push(p.nx || 0, p.nz || 0, p.d || 0);
150
+ this.uv.push(p.u || 0, p.uvv || 0);
151
+ }
152
+ if (i > 0) {
153
+ const k = this.count + (i - 1) * 2;
154
+ this.index.push(k, k + 2, k + 1, k + 1, k + 2, k + 3);
155
+ }
156
+ }
157
+ this.count += a.length * 2;
158
+ }
159
+
160
+ quad(p0, p1, p2, p3) {
161
+ this.band([p0, p1], [p3, p2]);
162
+ }
163
+
164
+ geometry(attrs = ['crowd', 'aisle']) {
165
+ const geo = new THREE.BufferGeometry();
166
+ geo.setAttribute('position', new THREE.Float32BufferAttribute(this.pos, 3));
167
+ if (attrs.includes('crowd')) {
168
+ geo.setAttribute('crowd', new THREE.Float32BufferAttribute(this.crowd, 2));
169
+ geo.setAttribute('aisle', new THREE.Float32BufferAttribute(this.aisle, 3));
170
+ geo.setAttribute('place', new THREE.Float32BufferAttribute(this.place, 3));
171
+ }
172
+ if (attrs.includes('uv')) {
173
+ geo.setAttribute('uv', new THREE.Float32BufferAttribute(this.uv, 2));
174
+ }
175
+ geo.setIndex(this.index);
176
+ geo.computeVertexNormals();
177
+ return geo;
178
+ }
179
+ }
180
+
181
+ // A line around the bowl at distance d and height y, with v naming the kind of surface.
182
+ function line(d, y, v, w = 0) {
183
+ return ringAt(d).map((p) => ({
184
+ x: p.x, y, z: p.z, s: p.s, v, phase: p.phase, mpp: p.mpp, w, nx: p.nx, nz: p.nz, d,
185
+ }));
186
+ }
187
+
188
+ // Treads, risers and the cards of people for a tier, front row first so the nearer rows fill the
189
+ // depth buffer before the rows behind are shaded.
190
+ function tier(steps, cards, startD, startY, rows, rise, seed) {
191
+ const lean = [Math.sin(CARD_TILT) * ATLAS.card, Math.cos(CARD_TILT) * ATLAS.card];
192
+ for (let i = 0; i < rows; i++) {
193
+ const d = startD + i * TREAD;
194
+ const y = startY + i * rise;
195
+ steps.band(line(d, y, 0), line(d + TREAD, y, 0.999));
196
+ steps.band(line(d + TREAD, y, 1), line(d + TREAD, y + rise, 1.999));
197
+ const bottom = line(d + CARD_AT, y, 0, seed + i * 1.618);
198
+ const top = ringAt(d + CARD_AT + lean[0]).map((p, k) => ({
199
+ ...bottom[k], x: p.x, y: y + lean[1], z: p.z, v: ATLAS.card,
200
+ }));
201
+ cards.band(bottom, top);
202
+ }
203
+ }
204
+
205
+ // The stands of the arenas other than the stadium, one along each touch line, of the same steps
206
+ // and painted people. half is the half length of a stand, at its distance from the middle of the
207
+ // pitch, rows, tread and rise its steps, front the wall before the first row, and group the
208
+ // meters between gangways, or between the gaps that split a crowd on flat ground into groups.
209
+ // A stand without steps stands its people on the ground. density, seats and seat give the
210
+ // share of places taken, whether an empty place shows a seat and its color, neon draws figures of
211
+ // light, and the step colors and glow dress the steps.
212
+ const ARENA_STANDS = {
213
+ beach: {
214
+ half: 48, at: 44.5, rows: 3, tread: 1.7, rise: 0, front: 0, group: 6, steps: false,
215
+ density: 0.6, seats: 1, seat: '#3f7fc6',
216
+ },
217
+ rooftop: {
218
+ half: 34, at: 46, rows: 6, tread: TREAD, rise: 0.42, front: 0.9, group: 8.5, steps: true,
219
+ concrete: '#7a7f86', wall: '#3b4048', facing: '#2c3138', nosing: '#d9b21e', seat: '#3a4250',
220
+ },
221
+ space: {
222
+ half: 42, at: 47, rows: 5, tread: 0.9, rise: 0.5, front: 1, group: 10.5, steps: true, glass: true,
223
+ concrete: '#5d6672', wall: '#2a3038', facing: '#1c232b', nosing: '#39d0ff', glow: 0.6, seat: '#d8dee6',
224
+ },
225
+ neon: {
226
+ half: 42, at: 46, rows: 5, tread: TREAD, rise: 0.36, front: 0.5, group: 10.5, steps: true, neon: true,
227
+ concrete: '#1a0f2a', wall: '#120a1e', facing: '#0d0716', nosing: '#ff2bd6', glow: 1.6, seats: 0,
228
+ },
229
+ };
230
+
231
+ // The steps and the people of an arena's stands. The steps mark their surfaces as the bowl does,
232
+ // the light needs no roof, so every point gets the place of one far inside it.
233
+ function buildArenaStands(spec) {
234
+ const steps = new Mesh();
235
+ const cards = new Mesh();
236
+ const lean = [Math.sin(CARD_TILT) * ATLAS.card, Math.cos(CARD_TILT) * ATLAS.card];
237
+ const x0 = -spec.half;
238
+ const x1 = spec.half;
239
+ for (const side of [-1, 1]) {
240
+ const at = (x, d, y, v, w = 0, open = true) => ({
241
+ x, y, z: side * (spec.at + d), s: x - x0, v, w, nx: 0, nz: 0, d: -1000,
242
+ phase: open ? (x - x0) / spec.group : 0, mpp: open ? spec.group : 1e4,
243
+ });
244
+ const row = (d, y, v, w = 0, open = true) => [at(x0, d, y, v, w, open), at(x1, d, y, v, w, open)];
245
+ const top = spec.front + (spec.rows - 1) * spec.rise;
246
+ const depth = spec.rows * spec.tread;
247
+ if (spec.steps) {
248
+ steps.band(row(0, 0, 4), row(0, spec.front, 4.999));
249
+ for (let i = 0; i < spec.rows; i++) {
250
+ const d = i * spec.tread;
251
+ const y = spec.front + i * spec.rise;
252
+ steps.band(row(d, y, 0), row(d + spec.tread, y, 0.999));
253
+ if (i < spec.rows - 1) {
254
+ steps.band(row(d + spec.tread, y, 1), row(d + spec.tread, y + spec.rise, 1.999));
255
+ }
256
+ // The ends of the stand, a step at a time.
257
+ for (const x of [x0, x1]) {
258
+ steps.quad(at(x, d, 0, 3, 0, false), at(x, d + spec.tread, 0, 3, 0, false),
259
+ at(x, d + spec.tread, y, 3.5, 0, false), at(x, d, y, 3.5, 0, false));
260
+ }
261
+ }
262
+ steps.band(row(depth, 0, 5, 0, false), row(depth, top + 1.1, 5.999, 0, false));
263
+ }
264
+ for (let i = 0; i < spec.rows; i++) {
265
+ const d = i * spec.tread + CARD_AT;
266
+ const y = spec.front + i * spec.rise;
267
+ const seed = side * 13.7 + i * 1.618 + 3.1;
268
+ const bottom = row(d, y, 0, seed);
269
+ const upper = row(d + lean[0], y + lean[1], ATLAS.card, seed);
270
+ cards.band(bottom, upper.map((p, k) => ({ ...bottom[k], y: p.y, z: p.z, v: ATLAS.card })));
271
+ }
272
+ }
273
+ return { steps: spec.steps ? steps.geometry() : null, cards: cards.geometry() };
274
+ }
275
+
276
+ function buildStands() {
277
+ const steps = new Mesh();
278
+ const cards = new Mesh();
279
+ steps.band(line(0, 0, 4), line(0, FRONT_WALL, 4.999));
280
+ tier(steps, cards, 0, FRONT_WALL, LOWER.rows, LOWER.rise, 3.1);
281
+ steps.band(line(LOWER_END, WALK_Y, 3), line(UPPER_D, WALK_Y, 3.999));
282
+ const wall = UPPER_WALL - RIBBON;
283
+ steps.band(line(UPPER_D, WALK_Y, 2, wall), line(UPPER_D, WALK_Y + wall, 2.999, wall));
284
+ tier(steps, cards, UPPER_D, UPPER_Y, UPPER.rows, UPPER.rise, 71.7);
285
+ steps.band(line(DEPTH, 0, 5), line(DEPTH, ROOF_BACK + 0.6, 5.999));
286
+ return { steps: steps.geometry(), cards: cards.geometry() };
287
+ }
288
+
289
+ // The ribbon board along the front of the upper tier, mapped like the boards around the pitch.
290
+ function buildRibbon(boardLength) {
291
+ const m = new Mesh();
292
+ const d = UPPER_D - 0.03;
293
+ const at = (y, v) => ringAt(d).map((p) => ({ x: p.x, y, z: p.z, u: p.s / boardLength, uvv: v }));
294
+ m.band(at(UPPER_Y - RIBBON, 0), at(UPPER_Y, 1));
295
+ return m.geometry(['uv']);
296
+ }
297
+
298
+ // How far out the front edge of the roof lies at a point of the inner edge.
299
+ function roofReach(p) {
300
+ return ROOF_REACH + (p.corner >= 0 ? ROOF_CORNER * Math.sin(Math.PI * p.corner) : 0);
301
+ }
302
+
303
+ function buildRoof() {
304
+ const base = ringAt(0);
305
+ const at = (p, d, y) => ({ x: p.x + p.nx * d, y, z: p.z + p.nz * d });
306
+ const top = new Mesh();
307
+ const under = new Mesh();
308
+ const fascia = new Mesh();
309
+ const strip = new Mesh();
310
+ // The ribs of the sheeting run from back to front, a texture repeat every two meters of the
311
+ // back edge.
312
+ const backRun = ringAt(DEPTH);
313
+ top.band(base.map((p, i) => ({ ...at(p, DEPTH + 0.4, ROOF_BACK + 0.6), u: backRun[i].s / 2, uvv: 0 })),
314
+ base.map((p, i) => ({ ...at(p, roofReach(p), ROOF_FRONT + 0.6), u: backRun[i].s / 2, uvv: 1 })));
315
+ under.band(base.map((p) => at(p, DEPTH, ROOF_BACK)), base.map((p) => at(p, roofReach(p), ROOF_FRONT)));
316
+ fascia.band(base.map((p) => at(p, roofReach(p) - 0.05, ROOF_FRONT - 0.9)), base.map((p) => at(p, roofReach(p) - 0.05, ROOF_FRONT + 0.8)));
317
+ strip.band(base.map((p) => at(p, roofReach(p) + 0.15, ROOF_FRONT - 0.92)), base.map((p) => at(p, roofReach(p) + 0.75, ROOF_FRONT - 0.88)));
318
+ // A rafter under the roof at every whole phase and in the middle of each corner, deep at the
319
+ // back wall and slim at the front edge.
320
+ const rafters = new Mesh();
321
+ for (const p of base.slice(0, -1)) {
322
+ if (!(p.corner < 0 || Math.abs(p.corner - 0.5) < 1e-6)) {
323
+ continue;
324
+ }
325
+ const tx = -p.nz * 0.22;
326
+ const tz = p.nx * 0.22;
327
+ const front = roofReach(p) + 0.3;
328
+ const corners = [];
329
+ for (const [d, y, depth] of [[DEPTH, ROOF_BACK, 2.6], [front, ROOF_FRONT, 0.5]]) {
330
+ for (const s of [-1, 1]) {
331
+ const x = p.x + p.nx * d + tx * s;
332
+ const z = p.z + p.nz * d + tz * s;
333
+ corners.push({ x, y: y - 0.02, z }, { x, y: y - depth, z });
334
+ }
335
+ }
336
+ // Back left top, back left bottom, back right top and bottom, then the same at the front.
337
+ const [blt, blb, brt, brb, flt, flb, frt, frb] = corners;
338
+ rafters.quad(blt, flt, flb, blb);
339
+ rafters.quad(brt, frt, frb, brb);
340
+ rafters.quad(blb, flb, frb, brb);
341
+ rafters.quad(flt, frt, frb, flb);
342
+ }
343
+ return {
344
+ top: top.geometry(['uv']), under: under.geometry([]), fascia: fascia.geometry([]),
345
+ strip: strip.geometry([]), rafters: rafters.geometry([]),
346
+ };
347
+ }
348
+
349
+ // Light and dark ribs of the roof sheeting.
350
+ function makeRibTexture() {
351
+ const canvas = document.createElement('canvas');
352
+ canvas.width = 32;
353
+ canvas.height = 4;
354
+ const ctx = canvas.getContext('2d');
355
+ ctx.fillStyle = '#d4d8dc';
356
+ ctx.fillRect(0, 0, 32, 4);
357
+ ctx.fillStyle = '#a3a9b0';
358
+ ctx.fillRect(0, 0, 6, 4);
359
+ ctx.fillStyle = '#eef0f2';
360
+ ctx.fillRect(6, 0, 2, 4);
361
+ const texture = new THREE.CanvasTexture(canvas);
362
+ texture.colorSpace = THREE.SRGBColorSpace;
363
+ texture.wrapS = THREE.RepeatWrapping;
364
+ texture.anisotropy = 4;
365
+ return texture;
366
+ }
367
+
368
+ const GLSL_COMMON = `
369
+ float cjHash(vec2 p) {
370
+ p = fract(p * vec2(0.1031, 0.1030));
371
+ p += dot(p, p.yx + 33.33);
372
+ return fract((p.x + p.y) * p.x * 43.17 + p.y);
373
+ }
374
+ `;
375
+
376
+ const VARYINGS = `
377
+ varying vec2 vCrowd;
378
+ varying vec3 vAisle;
379
+ varying float vCrowdX;
380
+ varying vec3 vPlace;
381
+ varying vec3 vStandN;
382
+ varying float vStandY;
383
+ `;
384
+
385
+ // The stands light themselves, from the sky, the sun and the floodlights, since each layer of
386
+ // people would otherwise pay for every light and shadow map of the scene. The roof shades a point
387
+ // when the way to the sun crosses the height of the roof inside its reach.
388
+ const STAND_LIGHT = `
389
+ uniform vec3 uSky;
390
+ uniform vec3 uGround;
391
+ uniform vec3 uSun;
392
+ uniform vec3 uSunDir;
393
+ uniform float uRoofY;
394
+ uniform float uRoofFront;
395
+ uniform float uFlood;
396
+ uniform float uLift;
397
+ vec3 standLight() {
398
+ vec3 n = normalize(vStandN) * (gl_FrontFacing ? 1.0 : -1.0);
399
+ vec3 sky = mix(uGround, uSky, 0.5 + 0.5 * n.y);
400
+ float ndl = max(dot(n, uSunDir), 0.0);
401
+ float t = (uRoofY - vStandY) / max(uSunDir.y, 0.05);
402
+ float reach = vPlace.z + t * dot(uSunDir.xz, vPlace.xy);
403
+ float lit = 1.0 - smoothstep(uRoofFront - 1.0, uRoofFront + 1.0, reach);
404
+ return (sky + uSun * ndl * lit) * RECIPROCAL_PI + uFlood + uLift;
405
+ }
406
+ `;
407
+
408
+ const VERTEX_CODE = `
409
+ vCrowd = crowd;
410
+ vAisle = aisle;
411
+ vCrowdX = position.x;
412
+ vPlace = place;
413
+ vStandN = normal;
414
+ vStandY = position.y;
415
+ `;
416
+
417
+ // A plain material with the stand attributes, whose color and light come from the code of the
418
+ // stands.
419
+ function standMaterial(params, uniforms, decl, body) {
420
+ const material = new THREE.MeshBasicMaterial(params);
421
+ material.onBeforeCompile = (shader) => {
422
+ Object.assign(shader.uniforms, uniforms);
423
+ shader.vertexShader = shader.vertexShader
424
+ .replace('#include <common>', `#include <common>\nattribute vec2 crowd;\nattribute vec3 aisle;\nattribute vec3 place;\n${VARYINGS}`)
425
+ .replace('#include <begin_vertex>', `#include <begin_vertex>\n${VERTEX_CODE}`);
426
+ shader.fragmentShader = shader.fragmentShader
427
+ .replace('#include <common>', `#include <common>\n${VARYINGS}\n${GLSL_COMMON}\n${STAND_LIGHT}\n${decl}`)
428
+ .replace('#include <map_fragment>', `vec3 cjEmit = vec3(0.0);\n${body}\ndiffuseColor.rgb = diffuseColor.rgb * standLight() + cjEmit;`);
429
+ };
430
+ return material;
431
+ }
432
+
433
+ const f = (x) => x.toFixed(5);
434
+
435
+ const CARD_DECL = `
436
+ uniform sampler2D uFigA;
437
+ uniform sampler2D uMaskA;
438
+ uniform sampler2D uFigB;
439
+ uniform sampler2D uMaskB;
440
+ uniform vec2 uTexSize;
441
+ uniform float uTime;
442
+ uniform float uBob;
443
+ uniform float uJump;
444
+ uniform float uCheer;
445
+ uniform float uDensity;
446
+ uniform float uMosaic;
447
+ uniform float uSeats;
448
+ uniform vec3 uLeft[${MAX_COLORS}];
449
+ uniform vec3 uRight[${MAX_COLORS}];
450
+ uniform vec2 uCounts;
451
+ uniform vec2 uDominant;
452
+ uniform vec2 uNeutral;
453
+ uniform float uMix;
454
+ uniform vec3 uSeatColor;
455
+ uniform float uAisleHalf;
456
+ uniform float uShirt;
457
+ uniform float uHard;
458
+ uniform float uNeon;
459
+ uniform vec3 uNeonTint;
460
+ const float SEAT_M = ${f(ATLAS.seat)};
461
+ const float CARD_M = ${f(ATLAS.card)};
462
+ const float STRIP_M = ${f(ATLAS.strip)};
463
+ const float SEATS = ${f(ATLAS.seats)};
464
+ const float STRIPS = ${f(ATLAS.strips)};
465
+ const float CHUNK = ${f(CHUNK)};
466
+ const float TALL_EVERY = ${f(ATLAS.tallEvery)};
467
+ const float SEATED_TOP = ${f(ATLAS.seatedTop)};
468
+ const float CALM_TOP = ${f(ATLAS.calmTop)};
469
+ const float GRF_TOP = ${f(ATLAS.grfTop)};
470
+ `;
471
+
472
+ const CARD_BODY = `
473
+ {
474
+ float open = smoothstep(uAisleHalf - 0.04, uAisleHalf + 0.04, abs(fract(vAisle.x) - 0.5) * vAisle.y);
475
+ float seed = vAisle.z;
476
+ float cs = vCrowd.x / SEAT_M;
477
+ float h = vCrowd.y;
478
+ float col = floor(cs);
479
+ float fx = cs - col;
480
+ float id = cjHash(vec2(col, seed));
481
+ float strip;
482
+ float tcol;
483
+ // Stretches of seats come from random places of the atlas, so no pattern repeats along a row.
484
+ if (uMosaic > 0.5) {
485
+ float chunk = floor(col / CHUNK);
486
+ strip = floor(cjHash(vec2(chunk, seed + 0.37)) * STRIPS);
487
+ tcol = mod(col + floor(cjHash(vec2(chunk + 7.1, seed)) * SEATS), SEATS) + fx;
488
+ } else {
489
+ strip = floor(cjHash(vec2(seed, 2.9)) * STRIPS);
490
+ tcol = cs + floor(cjHash(vec2(seed, 5.3)) * SEATS);
491
+ }
492
+ // After a goal each person gets up at a moment of their own and jumps.
493
+ bool up = uCheer > 0.1 + 0.8 * cjHash(vec2(id, 4.4));
494
+ float bob = uBob * sin(uTime * (1.2 + 1.8 * cjHash(vec2(id, 8.8))) + id * 40.0);
495
+ if (up) {
496
+ float j = max(0.0, sin(uTime * (6.0 + 2.5 * cjHash(vec2(id, 9.9))) + id * 31.0));
497
+ bob += uJump * j * j;
498
+ }
499
+ float hh = h - bob;
500
+ vec2 tuv = vec2(tcol / SEATS, (strip * STRIP_M + STRIP_M - hh) / (STRIPS * STRIP_M));
501
+ // Gradients of the unbroken coordinates keep the mip level steady across the jumps.
502
+ vec2 cuv = vec2(cs / SEATS, -h / (STRIPS * STRIP_M));
503
+ vec2 gx = dFdx(cuv);
504
+ vec2 gy = dFdy(cuv);
505
+ float w = fwidth(cs) + 0.001;
506
+ float wh = fwidth(h) + 0.001;
507
+ // Above the tallest person a column can hold there is only air, and in a gangway nothing.
508
+ float top = up ? CARD_M : uMosaic < 0.5 ? GRF_TOP
509
+ : mod(floor(tcol), TALL_EVERY) < 0.5 ? CALM_TOP : SEATED_TOP;
510
+ if (hh > top || open < 0.001) {
511
+ discard;
512
+ }
513
+ vec4 fig;
514
+ if (up) {
515
+ fig = textureGrad(uFigB, tuv, gx, gy);
516
+ } else {
517
+ fig = textureGrad(uFigA, tuv, gx, gy);
518
+ }
519
+ float present = step(cjHash(vec2(id, 1.3)), uDensity) * step(0.0, hh) * step(hh, CARD_M);
520
+ float a = fig.a * present;
521
+ // Up close the edges are cut sharp, far away the coverage of the mip levels is kept.
522
+ float texels = max(length(gx * uTexSize), length(gy * uTexSize));
523
+ float sharp = clamp((a - 0.5) / max(fwidth(a), 0.001) + 0.5, 0.0, 1.0);
524
+ a = uHard > 0.5 ? step(0.5, a) : mix(sharp, a, clamp(texels - 0.6, 0.0, 1.0));
525
+ // An empty seat shows its plastic back.
526
+ float sx = abs(fx - 0.5);
527
+ float back = (1.0 - smoothstep(0.4 - w, 0.4 + w, sx)) * smoothstep(0.42 - wh, 0.42 + wh, h)
528
+ * (1.0 - smoothstep(0.84 - wh, 0.84 + wh, h)) * uSeats;
529
+ float alpha = max(a, back) * open;
530
+ // Most of a card is air, leaving there skips the mask, the colors and the light of the rows
531
+ // seen through it.
532
+ if (alpha < 0.004) {
533
+ discard;
534
+ }
535
+ vec3 people = fig.rgb;
536
+ vec3 cloth = vec3(0.0);
537
+ if (a > 0.004) {
538
+ vec2 mk;
539
+ if (up) {
540
+ mk = textureGrad(uMaskB, tuv, gx, gy).rg;
541
+ } else {
542
+ mk = textureGrad(uMaskA, tuv, gx, gy).rg;
543
+ }
544
+ // Fans of the left team fill the left of the ground, mixing near the halfway line.
545
+ float side = step(0.0, vCrowdX + (cjHash(vec2(id, 2.2)) - 0.5) * 2.0 * uMix);
546
+ int n = int(mix(uCounts.x, uCounts.y, side) + 0.5);
547
+ float dom = mix(uDominant.x, uDominant.y, side);
548
+ int si = cjHash(vec2(id, 3.3)) < dom ? 0 : min(n - 1, int(cjHash(vec2(id, 5.5)) * float(n)));
549
+ int ai = n > 1 ? (si + 1 + min(n - 2, int(cjHash(vec2(id, 6.6)) * float(n - 1)))) % n : si;
550
+ vec3 shirt = side > 0.5 ? uRight[si] : uLeft[si];
551
+ vec3 acc = side > 0.5 ? uRight[ai] : uLeft[ai];
552
+ if (n < 2) {
553
+ acc = dot(shirt, vec3(0.2126, 0.7152, 0.0722)) > 0.2 ? vec3(0.015) : vec3(0.8);
554
+ }
555
+ if (cjHash(vec2(id, 7.7)) < mix(uNeutral.x, uNeutral.y, side)) {
556
+ int k = int(cjHash(vec2(id, 9.1)) * 5.0);
557
+ acc = shirt;
558
+ shirt = k == 0 ? vec3(0.82) : k == 1 ? vec3(0.3) : k == 2 ? vec3(0.018) : k == 3 ? vec3(0.03, 0.05, 0.12) : vec3(0.1, 0.18, 0.34);
559
+ }
560
+ float shade = fig.g / uShirt;
561
+ cloth = (shirt * mk.r + acc * mk.g) * shade;
562
+ people = fig.rgb * max(0.0, 1.0 - mk.r - mk.g) + cloth;
563
+ }
564
+ // Figures of light, dark bodies whose team colors glow, and up close outlines that shine.
565
+ if (uNeon > 0.5) {
566
+ float lum = dot(fig.rgb, vec3(0.2126, 0.7152, 0.0722));
567
+ float edge = clamp(fwidth(fig.a) * 2.0, 0.0, 1.0) * (1.0 - clamp(texels - 0.6, 0.0, 1.0));
568
+ people = vec3(0.012, 0.008, 0.03);
569
+ cjEmit = (cloth * 1.7 + uNeonTint * (lum * 0.03 + edge * 0.5)) * a;
570
+ }
571
+ vec3 seat = uSeatColor * (0.55 + 0.45 * clamp((h - 0.42) / 0.42, 0.0, 1.0));
572
+ diffuseColor.rgb *= mix(seat, people, a);
573
+ diffuseColor.a = alpha;
574
+ }
575
+ `;
576
+
577
+ const STEP_DECL = `
578
+ uniform vec3 uConcrete;
579
+ uniform vec3 uWall;
580
+ uniform vec3 uFront;
581
+ uniform vec3 uNosing;
582
+ uniform float uAisleHalf;
583
+ uniform float uStepGlow;
584
+ `;
585
+
586
+ // Kinds of surface by the whole part of v, tread, riser, the wall under the ribbon, the walkway,
587
+ // the wall along the pitch and the back of the stand.
588
+ const STEP_BODY = `
589
+ {
590
+ float aisleD = abs(fract(vAisle.x) - 0.5) * vAisle.y;
591
+ float inA = 1.0 - smoothstep(uAisleHalf - 0.04, uAisleHalf + 0.04, aisleD);
592
+ float v = vCrowd.y;
593
+ float kind = floor(v);
594
+ float t = v - kind;
595
+ float fw = fwidth(v) + 0.001;
596
+ vec3 c;
597
+ if (kind < 0.5) {
598
+ vec3 under = uConcrete * mix(0.7, 0.3, smoothstep(0.2, 0.95, t));
599
+ float mid = smoothstep(0.5 - fw, 0.5 + fw, t);
600
+ vec3 stair = uConcrete * mix(1.2, 0.95, mid);
601
+ float nose = max(1.0 - smoothstep(0.07 - fw, 0.07 + fw, t), mid * (1.0 - smoothstep(0.57 - fw, 0.57 + fw, t)));
602
+ c = mix(under, mix(stair, uNosing, nose), inA);
603
+ cjEmit = uNosing * uStepGlow * (1.0 - smoothstep(0.07 - fw, 0.07 + fw, t));
604
+ } else if (kind < 1.5) {
605
+ vec3 riser = mix(uConcrete * 0.55, uConcrete * 0.9, smoothstep(0.82 - fw, 0.82 + fw, t));
606
+ c = mix(riser, uConcrete * 0.85, inA);
607
+ } else if (kind < 2.5) {
608
+ float hm = t * vAisle.z;
609
+ float door = (1.0 - smoothstep(1.05, 1.15, aisleD)) * (1.0 - smoothstep(2.05, 2.15, hm));
610
+ c = mix(uWall, vec3(0.01), door);
611
+ } else if (kind < 3.5) {
612
+ c = uConcrete * 1.1;
613
+ } else if (kind < 4.5) {
614
+ c = mix(uFront, vec3(0.75), smoothstep(0.9 - fw, 0.9 + fw, t));
615
+ cjEmit = uNosing * uStepGlow * smoothstep(0.9 - fw, 0.9 + fw, t);
616
+ } else {
617
+ c = uConcrete * (0.8 + 0.12 * step(0.5, fract(t * 7.0)));
618
+ }
619
+ diffuseColor.rgb *= c;
620
+ }
621
+ `;
622
+
623
+ const linear = (hex) => new THREE.Color(hex);
624
+
625
+ function fanColors(list) {
626
+ return list.slice(0, MAX_COLORS).map((c) => (Array.isArray(c)
627
+ ? new THREE.Color().setRGB(c[0] / 255, c[1] / 255, c[2] / 255, THREE.SRGBColorSpace)
628
+ : new THREE.Color(c)));
629
+ }
630
+
631
+ function validFans(list) {
632
+ return Array.isArray(list) && list.length > 0
633
+ && list.every((c) => Array.isArray(c) && c.length >= 3 && c.every((v) => Number.isFinite(v)));
634
+ }
635
+
636
+ // The last fans a stadium was given, so a stadium built again when the art arrives keeps them.
637
+ let lastFans = [null, null];
638
+
639
+ // The cuju mark for the boards, null until it loads. The bare mark in light grays stands on the
640
+ // dark panel as the team names stand on theirs, printed on the board, where the logo's tile would
641
+ // be a box inside the panel.
642
+ let boardLogo = null;
643
+ const boardLogoReady = new Promise((resolve) => {
644
+ const img = new Image();
645
+ img.onload = () => {
646
+ boardLogo = img;
647
+ resolve(img);
648
+ };
649
+ img.onerror = () => resolve(null);
650
+ img.src = 'assets/cuju-mark.svg';
651
+ });
652
+
653
+ // LED boards, the cuju logo and the team names on colored panels, with the asset boards between
654
+ // them. The logo panel shows the word until the logo has loaded.
655
+ function makeBoardTexture(names, colors, images, sponsors) {
656
+ const h = 64;
657
+ const cuju = (fill) => (boardLogo ? { logo: boardLogo, fill } : { word: 'Cuju', fill });
658
+ const panels = sponsors.length ? [
659
+ cuju('#202124'),
660
+ ...sponsors.map((image) => ({ image })),
661
+ ] : [
662
+ cuju('#0e1a2b'),
663
+ { word: names[0], fill: colors[0] },
664
+ images[0] ? { image: images[0] } : { word: 'Google Research Football', fill: '#14301c' },
665
+ { word: names[1], fill: colors[1] },
666
+ ];
667
+ if (images[1]) {
668
+ panels.push({ image: images[1] });
669
+ }
670
+ const widths = panels.map((p) => {
671
+ if (p.image) {
672
+ return Math.round(p.image.width * (h / p.image.height));
673
+ }
674
+ return p.logo ? 256 : 512;
675
+ });
676
+ const canvas = document.createElement('canvas');
677
+ canvas.width = widths.reduce((a, b) => a + b, 0);
678
+ canvas.height = h;
679
+ const ctx = canvas.getContext('2d');
680
+ let x = 0;
681
+ panels.forEach((p, k) => {
682
+ const w = widths[k];
683
+ if (p.image) {
684
+ ctx.drawImage(p.image, x, 0, w, h);
685
+ } else if (p.logo) {
686
+ ctx.fillStyle = p.fill;
687
+ ctx.fillRect(x, 0, w, h);
688
+ const side = h - 12;
689
+ const width = Math.round(side * (p.logo.width / p.logo.height));
690
+ ctx.drawImage(p.logo, x + (w - width) / 2, 6, width, side);
691
+ } else {
692
+ ctx.fillStyle = p.fill;
693
+ ctx.fillRect(x, 0, w, h);
694
+ ctx.fillStyle = '#ffffff';
695
+ ctx.font = '600 34px system-ui, sans-serif';
696
+ ctx.textAlign = 'center';
697
+ ctx.textBaseline = 'middle';
698
+ ctx.fillText(p.word || '', x + w / 2, h / 2 + 2, w - 24);
699
+ }
700
+ x += w;
701
+ });
702
+ const texture = new THREE.CanvasTexture(canvas);
703
+ texture.colorSpace = THREE.SRGBColorSpace;
704
+ texture.wrapS = THREE.RepeatWrapping;
705
+ // The boards are 0.9 meters high, so the strip keeps its aspect at this length.
706
+ texture.userData.meters = (canvas.width / h) * 0.9;
707
+ return texture;
708
+ }
709
+
710
+ // A soft round glow, bright in the middle and fading out, for the glare of the lamps.
711
+ function makeHaloTexture() {
712
+ const size = 128;
713
+ const canvas = document.createElement('canvas');
714
+ canvas.width = size;
715
+ canvas.height = size;
716
+ const ctx = canvas.getContext('2d');
717
+ const g = ctx.createRadialGradient(size / 2, size / 2, 0, size / 2, size / 2, size / 2);
718
+ g.addColorStop(0, 'rgba(255,255,255,1)');
719
+ g.addColorStop(0.1, 'rgba(255,255,255,0.75)');
720
+ g.addColorStop(0.3, 'rgba(255,255,255,0.25)');
721
+ g.addColorStop(0.6, 'rgba(255,255,255,0.06)');
722
+ g.addColorStop(1, 'rgba(255,255,255,0)');
723
+ ctx.fillStyle = g;
724
+ ctx.fillRect(0, 0, size, size);
725
+ const texture = new THREE.CanvasTexture(canvas);
726
+ texture.colorSpace = THREE.SRGBColorSpace;
727
+ return texture;
728
+ }
729
+
730
+ // The lamp face of a floodlight head, rows of round lamps on a dark bank.
731
+ function makeLampTexture() {
732
+ const cols = 6;
733
+ const rows = 3;
734
+ const cell = 64;
735
+ const canvas = document.createElement('canvas');
736
+ canvas.width = cols * cell;
737
+ canvas.height = rows * cell;
738
+ const ctx = canvas.getContext('2d');
739
+ ctx.fillStyle = '#15181c';
740
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
741
+ for (let r = 0; r < rows; r++) {
742
+ for (let c = 0; c < cols; c++) {
743
+ const x = (c + 0.5) * cell;
744
+ const y = (r + 0.5) * cell;
745
+ const glow = ctx.createRadialGradient(x, y, 2, x, y, cell * 0.42);
746
+ glow.addColorStop(0, '#ffffff');
747
+ glow.addColorStop(0.55, '#e8eef8');
748
+ glow.addColorStop(1, '#5a6270');
749
+ ctx.fillStyle = glow;
750
+ ctx.beginPath();
751
+ ctx.arc(x, y, cell * 0.42, 0, Math.PI * 2);
752
+ ctx.fill();
753
+ }
754
+ }
755
+ const texture = new THREE.CanvasTexture(canvas);
756
+ texture.colorSpace = THREE.SRGBColorSpace;
757
+ return texture;
758
+ }
759
+
760
+ // Four towers at the corners, each a mast with a bank of lamps and a spot light aimed across the
761
+ // pitch. They light up at dusk and at night, and the quality decides how many cast shadows.
762
+ class Floodlights {
763
+ constructor(parent) {
764
+ this.group = new THREE.Group();
765
+ parent.add(this.group);
766
+ this.level = 0;
767
+ this.quality = 'medium';
768
+ const metal = new THREE.MeshStandardMaterial({ color: 0x3b4047, roughness: 0.55, metalness: 0.6 });
769
+ const lamps = makeLampTexture();
770
+ this.lampMaterial = new THREE.MeshStandardMaterial({
771
+ map: lamps, emissive: 0xfff8ee, emissiveMap: lamps, emissiveIntensity: 0, roughness: 0.3,
772
+ });
773
+ this.haloMaterial = new THREE.SpriteMaterial({
774
+ map: makeHaloTexture(), color: 0xf4f7ff, transparent: true, opacity: 0, depthWrite: false,
775
+ blending: THREE.AdditiveBlending, fog: false,
776
+ });
777
+ const mastGeo = new THREE.CylinderGeometry(0.45, 1.2, MAST_HEIGHT, 12);
778
+ const frameGeo = new THREE.BoxGeometry(10, 5.2, 0.8);
779
+ const panelGeo = new THREE.PlaneGeometry(9.4, 4.6);
780
+ const deckGeo = new THREE.BoxGeometry(10.5, 0.25, 2.2);
781
+ this.lights = [];
782
+ // Opposite corners come first, so two shadows cross from both sides.
783
+ for (const [sx, sz] of [[1, 1], [-1, -1], [-1, 1], [1, -1]]) {
784
+ const x = sx * (INNER_HALF_X - CORNER + MAST_OUT * Math.SQRT1_2);
785
+ const z = sz * (INNER_HALF_Z - CORNER + MAST_OUT * Math.SQRT1_2);
786
+ const mast = new THREE.Mesh(mastGeo, metal);
787
+ mast.position.set(x, MAST_HEIGHT / 2, z);
788
+ const aim = new THREE.Vector3(-sx * 5, 0, -sz * 3.5);
789
+ const head = new THREE.Group();
790
+ head.position.set(x, MAST_HEIGHT + 2.6, z);
791
+ head.lookAt(aim);
792
+ const frame = new THREE.Mesh(frameGeo, metal);
793
+ frame.position.z = -0.45;
794
+ const panel = new THREE.Mesh(panelGeo, this.lampMaterial);
795
+ panel.position.z = 0.02;
796
+ const deck = new THREE.Mesh(deckGeo, metal);
797
+ deck.position.set(0, -2.9, 0.4);
798
+ // A halo in front of the lamps, the glare of the lights at every quality, with or
799
+ // without the bloom.
800
+ const halo = new THREE.Sprite(this.haloMaterial);
801
+ halo.scale.set(44, 40, 1);
802
+ halo.position.z = 1.5;
803
+ head.add(frame, panel, deck, halo);
804
+ head.updateMatrixWorld();
805
+ const light = new THREE.SpotLight(0xf2f5ff, 0, 0, FLOOD_ANGLE, FLOOD_PENUMBRA, 2);
806
+ light.position.copy(head.localToWorld(new THREE.Vector3(0, 0, 1)));
807
+ light.target.position.copy(aim);
808
+ light.visible = false;
809
+ const shadow = light.shadow;
810
+ shadow.camera.near = 40;
811
+ shadow.camera.far = 240;
812
+ // The pitch fills about 85 percent of the cone, the shadow map need not cover the rest.
813
+ shadow.focus = 0.85;
814
+ shadow.bias = -0.0006;
815
+ shadow.normalBias = 0.05;
816
+ // Four lights share the work, so each shadow alone only darkens the grass a little.
817
+ shadow.intensity = 0.8;
818
+ this.lights.push(light);
819
+ this.group.add(mast, head, light, light.target);
820
+ }
821
+ }
822
+
823
+ // Shows or hides the masts and their lamps, the light itself stays.
824
+ setMasts(on) {
825
+ for (const child of this.group.children) {
826
+ if (child.isMesh || child.isGroup) {
827
+ child.visible = on;
828
+ }
829
+ }
830
+ }
831
+
832
+ // How far the lights are up, from 0 for off to 1 for full.
833
+ setLevel(level) {
834
+ this.level = THREE.MathUtils.clamp(level, 0, 1);
835
+ this.apply();
836
+ }
837
+
838
+ setQuality(quality) {
839
+ this.quality = quality;
840
+ this.apply();
841
+ }
842
+
843
+ apply() {
844
+ // Faint light casts no shadow, and the count changes only at whole steps, since each
845
+ // change rebuilds the shaders.
846
+ const level = this.level < 0.02 ? 0 : this.level;
847
+ const shadows = level >= 0.2 ? FLOOD_SHADOWS[level >= 0.75 ? 'night' : 'dusk'][this.quality] || 0 : 0;
848
+ const size = FLOOD_SHADOW_MAP[this.quality] || 1024;
849
+ this.lights.forEach((light, i) => {
850
+ light.visible = level > 0;
851
+ light.intensity = FLOOD_CANDELA * level;
852
+ if (light.shadow.mapSize.x !== size) {
853
+ light.shadow.mapSize.set(size, size);
854
+ if (light.shadow.map) {
855
+ light.shadow.map.dispose();
856
+ light.shadow.map = null;
857
+ }
858
+ }
859
+ light.shadow.radius = this.quality === 'high' ? 3 : 2;
860
+ light.castShadow = i < shadows;
861
+ light.shadow.autoUpdate = false;
862
+ light.shadow.needsUpdate = true;
863
+ });
864
+ // Bright enough that the bloom of the highest quality picks the lamps out.
865
+ this.lampMaterial.emissiveIntensity = level > 0 ? 4 + 10 * level : 0;
866
+ this.haloMaterial.opacity = 0.8 * level * level;
867
+ }
868
+
869
+ // Each shadow map is redrawn every other frame, half of them on each, which halves the cost
870
+ // of four shadows while players move only a few centimeters in between.
871
+ update() {
872
+ this.turn = 1 - (this.turn || 0);
873
+ this.lights.forEach((light, i) => {
874
+ if (light.castShadow && i % 2 === this.turn) {
875
+ light.shadow.needsUpdate = true;
876
+ }
877
+ });
878
+ }
879
+ }
880
+
881
+ export class Stadium {
882
+ constructor(scene, crowdImage = null, adboards = []) {
883
+ this.group = new THREE.Group();
884
+ scene.add(this.group);
885
+ this.scene = scene;
886
+ this.adboards = adboards;
887
+ this.crowdImage = crowdImage;
888
+ this.quality = 'medium';
889
+ this.mode = 'teams';
890
+ this.field = null;
891
+ this.fans = lastFans.slice();
892
+ this.atlasKey = '';
893
+ this.textures = null;
894
+ this.uniforms = {
895
+ uFigA: { value: null },
896
+ uMaskA: { value: null },
897
+ uFigB: { value: null },
898
+ uMaskB: { value: null },
899
+ uTexSize: { value: new THREE.Vector2(1, 1) },
900
+ uTime: { value: 0 },
901
+ uBob: { value: 0 },
902
+ uJump: { value: 0 },
903
+ uCheer: { value: 0 },
904
+ uDensity: { value: 0.9 },
905
+ uMosaic: { value: 1 },
906
+ uSeats: { value: 1 },
907
+ uLeft: { value: Array.from({ length: MAX_COLORS }, () => new THREE.Color()) },
908
+ uRight: { value: Array.from({ length: MAX_COLORS }, () => new THREE.Color()) },
909
+ uCounts: { value: new THREE.Vector2(1, 1) },
910
+ uDominant: { value: new THREE.Vector2(0, 0) },
911
+ uNeutral: { value: new THREE.Vector2(0, 0) },
912
+ uMix: { value: 8 },
913
+ uSeatColor: { value: linear('#26344a') },
914
+ uLift: { value: 0 },
915
+ uSky: { value: new THREE.Color(0xcfe3ff) },
916
+ uGround: { value: new THREE.Color(0x3a5a2a) },
917
+ uSun: { value: new THREE.Color(0xfff1dc).multiplyScalar(3) },
918
+ uSunDir: { value: new THREE.Vector3(-60, 110, -70).normalize() },
919
+ uRoofY: { value: (ROOF_BACK + ROOF_FRONT) / 2 },
920
+ uRoofFront: { value: ROOF_REACH },
921
+ uFlood: { value: 0 },
922
+ uAisleHalf: { value: AISLE_HALF },
923
+ uHard: { value: 0 },
924
+ uShirt: { value: new THREE.Color().setRGB(ATLAS.shirtGrey / 255, 0, 0, THREE.SRGBColorSpace).r },
925
+ uNeon: { value: 0 },
926
+ uNeonTint: { value: linear('#2be8ff') },
927
+ uStepGlow: { value: 0 },
928
+ uConcrete: { value: linear('#8c8f94') },
929
+ uWall: { value: linear('#3b424c') },
930
+ uFront: { value: linear('#1f2a24') },
931
+ uNosing: { value: linear('#d9b21e') },
932
+ };
933
+ const stands = buildStands();
934
+ this.stepsMesh = new THREE.Mesh(stands.steps, standMaterial({ side: THREE.DoubleSide }, this.uniforms, STEP_DECL, STEP_BODY));
935
+ this.cardMaterial = standMaterial({ side: THREE.DoubleSide, alphaToCoverage: true }, this.uniforms, CARD_DECL, CARD_BODY);
936
+ this.crowdMesh = new THREE.Mesh(stands.cards, this.cardMaterial);
937
+ // The people go first, so the steps behind them fail the depth test before shading.
938
+ this.crowdMesh.renderOrder = -2;
939
+ this.stepsMesh.renderOrder = -1;
940
+ this.group.add(this.stepsMesh, this.crowdMesh);
941
+ const roof = buildRoof();
942
+ const metal = new THREE.MeshStandardMaterial({
943
+ color: 0x7f8790, map: makeRibTexture(), roughness: 0.55, metalness: 0.45, side: THREE.DoubleSide,
944
+ });
945
+ // The underside faces the grass, a little light of its own keeps it from taking the
946
+ // green of the ground.
947
+ const under = new THREE.MeshStandardMaterial({
948
+ color: 0xc9cdd2, emissive: 0x16181b, roughness: 0.8, metalness: 0.1, side: THREE.DoubleSide,
949
+ });
950
+ const dark = new THREE.MeshStandardMaterial({ color: 0x2a2f36, roughness: 0.5, metalness: 0.5, side: THREE.DoubleSide });
951
+ const steel = new THREE.MeshStandardMaterial({ color: 0x8a9099, roughness: 0.5, metalness: 0.5, side: THREE.DoubleSide });
952
+ const roofTop = new THREE.Mesh(roof.top, metal);
953
+ roofTop.castShadow = true;
954
+ const roofUnder = new THREE.Mesh(roof.under, under);
955
+ roofUnder.receiveShadow = true;
956
+ const fascia = new THREE.Mesh(roof.fascia, dark);
957
+ fascia.castShadow = true;
958
+ this.rafters = new THREE.Mesh(roof.rafters, steel);
959
+ this.strip = new THREE.Mesh(roof.strip, new THREE.MeshStandardMaterial({
960
+ color: 0x111111, emissive: 0xfff4dd, emissiveIntensity: 2.2, side: THREE.DoubleSide,
961
+ }));
962
+ this.group.add(roofTop, roofUnder, fascia, this.rafters, this.strip);
963
+ this.floodlights = new Floodlights(this.group);
964
+ this.boardMaterial = new THREE.MeshStandardMaterial({
965
+ emissive: 0xffffff, emissiveIntensity: 0.55, roughness: 0.5, color: 0x222222, side: THREE.DoubleSide,
966
+ });
967
+ this.addBoards();
968
+ const ribbon = new THREE.Mesh(buildRibbon(this.boardLength), this.boardMaterial);
969
+ this.group.add(ribbon);
970
+ // The bowl, everything an arena without stands hides.
971
+ this.bowl = [this.stepsMesh, this.crowdMesh, roofTop, roofUnder, fascia, this.strip, ribbon];
972
+ this.arena = 'stadium';
973
+ // The stands of the other arenas, built when an arena first asks for them.
974
+ this.arenaStands = new Map();
975
+ this.arenaCardMaterials = [];
976
+ this.setTeams(['Left', 'Right'], ['#b3262e', '#2a56b8']);
977
+ this.applyCrowd();
978
+ }
979
+
980
+ addBoards() {
981
+ const height = 0.9;
982
+ const bx = FULL_HALF_W + 1.5;
983
+ const bz = FULL_HALF_H + 1.5;
984
+ this.boardLength = bx * 2 - 4;
985
+ const make = (length, x, z, rotY) => {
986
+ const geometry = new THREE.PlaneGeometry(length, height);
987
+ // The end boards are shorter, their texture coordinates shrink to match so the strip
988
+ // keeps its aspect on every side.
989
+ const uv = geometry.attributes.uv;
990
+ for (let i = 0; i < uv.count; i++) {
991
+ uv.setX(i, uv.getX(i) * (length / this.boardLength));
992
+ }
993
+ const mesh = new THREE.Mesh(geometry, this.boardMaterial);
994
+ mesh.position.set(x, height / 2, z);
995
+ mesh.rotation.y = rotY;
996
+ mesh.castShadow = true;
997
+ this.group.add(mesh);
998
+ const backing = new THREE.Mesh(
999
+ new THREE.BoxGeometry(length, height, 0.15),
1000
+ new THREE.MeshStandardMaterial({ color: 0x15181d, roughness: 0.8 }),
1001
+ );
1002
+ backing.position.set(x, height / 2, z);
1003
+ backing.rotation.y = rotY;
1004
+ backing.translateZ(-0.09);
1005
+ this.group.add(backing);
1006
+ };
1007
+ make(bx * 2 - 4, 0, -bz, 0);
1008
+ make(bx * 2 - 4, 0, bz, Math.PI);
1009
+ make(bz * 2 - 4, -bx, 0, Math.PI / 2);
1010
+ make(bz * 2 - 4, bx, 0, -Math.PI / 2);
1011
+ }
1012
+
1013
+ setTeams(names, colors, sponsors = []) {
1014
+ if (this.boardMaterial.map) {
1015
+ this.boardMaterial.map.dispose();
1016
+ }
1017
+ // Boards drawn before the logo loaded are drawn again once it has, unless newer teams
1018
+ // replaced them in between.
1019
+ const args = [names, colors, sponsors];
1020
+ this.lastTeams = args;
1021
+ if (!boardLogo) {
1022
+ boardLogoReady.then((logo) => {
1023
+ if (logo && !this.disposed && this.lastTeams === args) {
1024
+ this.setTeams(names, colors, sponsors);
1025
+ }
1026
+ });
1027
+ }
1028
+ const tex = makeBoardTexture(names, colors, this.adboards, sponsors);
1029
+ // Repeat the strip at its natural size along a long side, the end boards and the ribbon
1030
+ // follow it.
1031
+ tex.repeat.set(Math.max(1, Math.round(this.boardLength / tex.userData.meters)), 1);
1032
+ this.boardMaterial.map = tex;
1033
+ this.boardMaterial.emissiveMap = tex;
1034
+ this.boardMaterial.needsUpdate = true;
1035
+ }
1036
+
1037
+ // Frees every geometry, material and texture of the stands, for a stadium being replaced.
1038
+ dispose() {
1039
+ this.disposed = true;
1040
+ this.group.removeFromParent();
1041
+ const textures = new Set();
1042
+ this.group.traverse((obj) => {
1043
+ if (obj.geometry) {
1044
+ obj.geometry.dispose();
1045
+ }
1046
+ if (obj.material) {
1047
+ for (const key of ['map', 'emissiveMap']) {
1048
+ if (obj.material[key]) {
1049
+ textures.add(obj.material[key]);
1050
+ }
1051
+ }
1052
+ obj.material.dispose();
1053
+ }
1054
+ if (obj.isLight && obj.shadow && obj.shadow.map) {
1055
+ obj.shadow.map.dispose();
1056
+ }
1057
+ });
1058
+ textures.forEach((texture) => texture.dispose());
1059
+ this.freeAtlas();
1060
+ }
1061
+
1062
+ freeAtlas() {
1063
+ if (this.textures) {
1064
+ new Set(['calmColor', 'calmMask', 'cheerColor', 'cheerMask'].map((k) => this.textures[k]))
1065
+ .forEach((t) => t.dispose());
1066
+ this.textures = null;
1067
+ }
1068
+ }
1069
+
1070
+ // The fans of each team in one to four colors as RGB from 0 to 255, or null when unknown.
1071
+ setFans(left, right) {
1072
+ this.fans = [validFans(left) ? left : null, validFans(right) ? right : null];
1073
+ lastFans = this.fans.slice();
1074
+ this.applyCrowd();
1075
+ }
1076
+
1077
+ // Crowd from the field settings, the fans of the teams, painted people in chosen colors or
1078
+ // GRF's strip.
1079
+ setCrowd(field) {
1080
+ this.field = field;
1081
+ this.applyCrowd();
1082
+ }
1083
+
1084
+ applyCrowd() {
1085
+ const field = this.field || {};
1086
+ let mode = field.crowd || 'teams';
1087
+ if (mode === 'grf' && !this.crowdImage) {
1088
+ mode = 'teams';
1089
+ }
1090
+ this.mode = mode;
1091
+ const scale = this.quality === 'low' ? 0.5 : 1;
1092
+ const key = `${mode === 'grf' ? 'grf' : 'painted'}:${scale}`;
1093
+ if (key !== this.atlasKey) {
1094
+ this.freeAtlas();
1095
+ const atlas = mode === 'grf' ? grfCrowd(this.crowdImage, scale) : paintCrowd(scale);
1096
+ this.textures = atlasTextures(atlas, this.quality === 'low' ? 2 : 4);
1097
+ this.atlasKey = key;
1098
+ const u = this.uniforms;
1099
+ u.uFigA.value = this.textures.calmColor;
1100
+ u.uMaskA.value = this.textures.calmMask;
1101
+ u.uFigB.value = this.textures.cheerColor;
1102
+ u.uMaskB.value = this.textures.cheerMask;
1103
+ u.uTexSize.value.copy(this.textures.size);
1104
+ }
1105
+ const u = this.uniforms;
1106
+ const painted = mode !== 'grf';
1107
+ u.uMosaic.value = painted ? 1 : 0;
1108
+ u.uSeats.value = painted ? 1 : 0;
1109
+ u.uDensity.value = painted ? (Number.isFinite(field.crowdDensity) ? field.crowdDensity : 0.9) : 1;
1110
+ let sides;
1111
+ if (mode === 'custom' && Array.isArray(field.crowdColors) && field.crowdColors.length) {
1112
+ const list = fanColors(field.crowdColors);
1113
+ sides = [{ list, dominant: 0, neutral: 0 }, { list, dominant: 0, neutral: 0 }];
1114
+ } else {
1115
+ // Shirts mostly in the first color of the team, the others as accents, and a few
1116
+ // neutral coats among them.
1117
+ sides = this.fans.map((fans) => (fans
1118
+ ? { list: fanColors(fans), dominant: 0.62, neutral: 0.1 }
1119
+ : { list: fanColors(MIXED), dominant: 0, neutral: 0 }));
1120
+ }
1121
+ [u.uLeft, u.uRight].forEach((uniform, k) => {
1122
+ const list = sides[k].list;
1123
+ uniform.value.forEach((c, i) => c.copy(list[Math.min(i, list.length - 1)]));
1124
+ });
1125
+ u.uCounts.value.set(sides[0].list.length, sides[1].list.length);
1126
+ u.uDominant.value.set(sides[0].dominant, sides[1].dominant);
1127
+ u.uNeutral.value.set(sides[0].neutral, sides[1].neutral);
1128
+ }
1129
+
1130
+ // The lights under the roof glow brighter as the day goes, and the towers come up. Takes the
1131
+ // lighting from sky.js lightingAt, or an hour, or one of the old names day, dusk and night.
1132
+ setTime(time) {
1133
+ const L = time && typeof time === 'object' ? time : lightingAt(hourOf(time));
1134
+ const flood = L.flood;
1135
+ this.strip.material.emissiveIntensity = 2.2 + 1.8 * flood;
1136
+ this.boardMaterial.emissiveIntensity = 0.55 + 0.55 * flood;
1137
+ // Light from the concourses and the roof, and by day light bounced off the pitch, keeps
1138
+ // the stands in the shade of the roof readable.
1139
+ this.uniforms.uLift.value = L.lift;
1140
+ this.uniforms.uFlood.value = flood * STAND_FLOOD;
1141
+ this.followLights();
1142
+ this.floodlights.setLevel(flood);
1143
+ }
1144
+
1145
+ // Arenas other than the stadium keep the boards and the floodlight towers and take the bowl
1146
+ // away, with its crowd, and show stands of their own. An arena may hide the masts too and keep
1147
+ // their light, see arenas.js.
1148
+ setArena(name, masts = true) {
1149
+ this.arena = name || 'stadium';
1150
+ const bowl = this.arena === 'stadium';
1151
+ for (const part of this.bowl) {
1152
+ part.visible = bowl;
1153
+ }
1154
+ if (ARENA_STANDS[this.arena] && !this.arenaStands.has(this.arena)) {
1155
+ this.arenaStands.set(this.arena, this.buildArenaStands(ARENA_STANDS[this.arena]));
1156
+ }
1157
+ for (const [n, group] of this.arenaStands) {
1158
+ group.visible = n === this.arena;
1159
+ }
1160
+ this.rafters.visible = bowl && this.quality !== 'low';
1161
+ this.floodlights.setMasts(bowl || masts);
1162
+ }
1163
+
1164
+ // A small stand on each touch line, its people sharing the atlas, the fans and the cheer of the
1165
+ // bowl, with the seats, the density and the colors of its arena.
1166
+ buildArenaStands(spec) {
1167
+ const group = new THREE.Group();
1168
+ const geo = buildArenaStands(spec);
1169
+ const own = {
1170
+ uSeats: { value: spec.seats === undefined ? 1 : spec.seats },
1171
+ uSeatColor: { value: linear(spec.seat || '#26344a') },
1172
+ uNeon: { value: spec.neon ? 1 : 0 },
1173
+ uConcrete: { value: linear(spec.concrete || '#8c8f94') },
1174
+ uWall: { value: linear(spec.wall || '#3b424c') },
1175
+ uFront: { value: linear(spec.facing || '#1f2a24') },
1176
+ uNosing: { value: linear(spec.nosing || '#d9b21e') },
1177
+ uStepGlow: { value: spec.glow || 0 },
1178
+ };
1179
+ if (spec.density) {
1180
+ own.uDensity = { value: spec.density };
1181
+ }
1182
+ const uniforms = { ...this.uniforms, ...own };
1183
+ const material = standMaterial({ side: THREE.DoubleSide, alphaToCoverage: this.quality !== 'low' }, uniforms,
1184
+ CARD_DECL, CARD_BODY);
1185
+ this.arenaCardMaterials.push(material);
1186
+ const people = new THREE.Mesh(geo.cards, material);
1187
+ people.renderOrder = -2;
1188
+ group.add(people);
1189
+ if (geo.steps) {
1190
+ const steps = new THREE.Mesh(geo.steps, standMaterial({ side: THREE.DoubleSide }, uniforms, STEP_DECL, STEP_BODY));
1191
+ steps.renderOrder = -1;
1192
+ group.add(steps);
1193
+ }
1194
+ if (spec.glass) {
1195
+ // A pane of glass before each gallery, with a light along its top.
1196
+ const height = spec.front + 3.4;
1197
+ const pane = new THREE.MeshBasicMaterial({
1198
+ color: 0x9fdcff, transparent: true, opacity: 0.1, depthWrite: false, side: THREE.DoubleSide,
1199
+ });
1200
+ const rail = new THREE.MeshBasicMaterial({ color: 0x39d0ff });
1201
+ for (const side of [-1, 1]) {
1202
+ const glass = new THREE.Mesh(new THREE.PlaneGeometry(spec.half * 2, height), pane);
1203
+ glass.position.set(0, height / 2, side * (spec.at - 0.3));
1204
+ glass.renderOrder = 1;
1205
+ const edge = new THREE.Mesh(new THREE.BoxGeometry(spec.half * 2, 0.08, 0.08), rail);
1206
+ edge.position.set(0, height, side * (spec.at - 0.3));
1207
+ group.add(glass, edge);
1208
+ }
1209
+ }
1210
+ this.group.add(group);
1211
+ return group;
1212
+ }
1213
+
1214
+ setQuality(quality) {
1215
+ this.quality = quality;
1216
+ this.rafters.visible = quality !== 'low' && this.arena === 'stadium';
1217
+ // The low quality cuts the people out sharply.
1218
+ const low = quality === 'low';
1219
+ this.uniforms.uHard.value = low ? 1 : 0;
1220
+ for (const material of [this.cardMaterial, ...this.arenaCardMaterials]) {
1221
+ if (material.alphaToCoverage === low) {
1222
+ material.alphaToCoverage = !low;
1223
+ material.needsUpdate = true;
1224
+ }
1225
+ }
1226
+ this.floodlights.setQuality(quality);
1227
+ this.applyCrowd();
1228
+ }
1229
+
1230
+ // The crowd sways a little, more when it is excited, and stands and jumps after a goal while
1231
+ // cheer is high.
1232
+ update(time, excitement = 0, cheer = 0) {
1233
+ const u = this.uniforms;
1234
+ const lively = this.quality !== 'low' && this.mode !== 'grf';
1235
+ const c = Number.isFinite(cheer) ? THREE.MathUtils.clamp(cheer, 0, 1) : 0;
1236
+ u.uTime.value = time % 3600;
1237
+ u.uBob.value = lively ? 0.008 + 0.025 * (excitement || 0) : 0;
1238
+ u.uJump.value = lively ? 0.16 * c : 0;
1239
+ u.uCheer.value = this.mode === 'grf' ? 0 : c;
1240
+ this.followLights();
1241
+ this.floodlights.update();
1242
+ }
1243
+
1244
+ // The sky and the sun of the scene, as the view sets them for the time of day.
1245
+ followLights() {
1246
+ const u = this.uniforms;
1247
+ if (!this.sun || !this.sun.parent) {
1248
+ this.sun = this.scene.children.find((o) => o.isDirectionalLight) || null;
1249
+ }
1250
+ if (!this.hemi || !this.hemi.parent) {
1251
+ this.hemi = this.scene.children.find((o) => o.isHemisphereLight) || null;
1252
+ }
1253
+ if (this.hemi) {
1254
+ u.uSky.value.copy(this.hemi.color).multiplyScalar(this.hemi.intensity);
1255
+ u.uGround.value.copy(this.hemi.groundColor).multiplyScalar(this.hemi.intensity);
1256
+ }
1257
+ if (this.sun) {
1258
+ u.uSun.value.copy(this.sun.color).multiplyScalar(this.sun.visible ? this.sun.intensity : 0);
1259
+ u.uSunDir.value.subVectors(this.sun.position, this.sun.target.position).normalize();
1260
+ }
1261
+ }
1262
+ }