· 8 years ago · Apr 02, 2018, 10:30 AM
1// --------------------------------------
2//
3// _ _ _/ . _ _/ /_ _ _ _
4// /_|/_ / /|//_ / / //_ /_// /_/
5// http://activetheory.net _/
6//
7// --------------------------------------
8// 4/2/18 3:00a
9// --------------------------------------
10window.Global = {};
11window.getURL = function(url, target) {
12 if (!target) target = "_blank";
13 window.open(url, target)
14};
15if (typeof console === "undefined") {
16 window.console = {};
17 console.log = console.error = console.info = console.debug = console.warn = console.trace = function() {}
18}
19if (!window.requestAnimationFrame) {
20 window.requestAnimationFrame = function() {
21 return window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback, element) {
22 window.setTimeout(callback, 1e3 / 60)
23 }
24 }()
25}
26window.performance = function() {
27 if (window.performance && window.performance.now) return window.performance;
28 else return Date
29}();
30Date.now = Date.now || function() {
31 return +new Date
32};
33window.Class = function(_class, _type) {
34 var _this = this || window;
35 var _string = _class.toString();
36 var _name = _class.toString().match(/function ([^\(]+)/)[1];
37 var _static = null;
38 if (typeof _type === "function") {
39 _static = _type;
40 _type = null
41 }
42 _type = (_type || "").toLowerCase();
43 _class.prototype.__call = function() {
44 if (this.events) this.events.scope(this)
45 };
46 if (!_type) {
47 _this[_name] = _class;
48 _static && _static()
49 } else {
50 if (_type == "static") {
51 _this[_name] = new _class
52 } else if (_type == "singleton") {
53 _this[_name] = function() {
54 var __this = {};
55 var _instance;
56 __this.instance = function(a, b, c) {
57 if (!_instance) _instance = new _class(a, b, c);
58 return _instance
59 };
60 return __this
61 }()
62 }
63 }
64 if (this !== window) {
65 if (!this.__namespace) this.__namespace = this.constructor.toString().match(/function ([^\(]+)/)[1];
66 this[_name]._namespace = this.__namespace
67 }
68};
69window.Inherit = function(child, parent, param) {
70 if (typeof param === "undefined") param = child;
71 var p = new parent(param, true);
72 var save = {};
73 for (var method in p) {
74 child[method] = p[method];
75 save[method] = p[method]
76 }
77 if (child.__call) child.__call();
78 defer(function() {
79 for (method in p) {
80 if (child[method] && save[method] && child[method] !== save[method]) {
81 child["_" + method] = save[method]
82 }
83 }
84 p = save = null;
85 child = parent = param = null
86 })
87};
88window.Implement = function(cl, intr) {
89 Render.nextFrame(function() {
90 var intrface = new intr;
91 for (var property in intrface) {
92 if (typeof cl[property] === "undefined") {
93 throw "Interface Error: Missing Property: " + property + " ::: " + intr
94 } else {
95 var type = typeof intrface[property];
96 if (typeof cl[property] != type) throw "Interface Error: Property " + property + " is Incorrect Type ::: " + intr
97 }
98 }
99 })
100};
101window.Namespace = function(name) {
102 if (typeof name === "string") window[name] = {
103 Class: window.Class
104 };
105 else name.Class = window.Class
106};
107window.Interface = function(display) {
108 var name = display.toString().match(/function ([^\(]+)/)[1];
109 Hydra.INTERFACES[name] = display
110};
111window.THREAD = false;
112Class(function HydraObject(_selector, _type, _exists, _useFragment) {
113 this._children = new LinkedList;
114 this.__useFragment = _useFragment;
115 this._initSelector(_selector, _type, _exists)
116}, () => {
117 var prototype = HydraObject.prototype;
118 prototype._initSelector = function(_selector, _type, _exists) {
119 if (_selector && typeof _selector !== "string") {
120 this.div = _selector
121 } else {
122 var first = _selector ? _selector.charAt(0) : null;
123 var name = _selector ? _selector.slice(1) : null;
124 if (first != "." && first != "#") {
125 name = _selector;
126 first = "."
127 }
128 if (!_exists) {
129 this._type = _type || "div";
130 if (this._type == "svg") {
131 this.div = document.createElementNS("http://www.w3.org/2000/svg", this._type);
132 this.div.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink")
133 } else {
134 this.div = document.createElement(this._type);
135 if (first) {
136 if (first == "#") this.div.id = name;
137 else this.div.className = name
138 }
139 }
140 } else {
141 if (first != "#") throw "Hydra Selectors Require #ID";
142 this.div = document.getElementById(name)
143 }
144 }
145 this.div.hydraObject = this
146 };
147 prototype.addChild = prototype.add = function(child) {
148 var div = this.div;
149 var createFrag = function() {
150 if (this.__useFragment) {
151 if (!this._fragment) {
152 this._fragment = document.createDocumentFragment();
153 var _this = this;
154 defer(function() {
155 if (!_this._fragment || !_this.div) return _this._fragment = null;
156 _this.div.appendChild(_this._fragment);
157 _this._fragment = null
158 })
159 }
160 div = this._fragment
161 }
162 };
163 if (child.element && child.element instanceof HydraObject) {
164 createFrag();
165 div.appendChild(child.element.div);
166 this._children.push(child.element);
167 child.element._parent = this;
168 child.element.div.parentNode = this.div
169 } else if (child.div) {
170 createFrag();
171 div.appendChild(child.div);
172 this._children.push(child);
173 child._parent = this;
174 child.div.parentNode = this.div
175 } else if (child.nodeName) {
176 createFrag();
177 div.appendChild(child);
178 child.parentNode = this.div
179 }
180 return this
181 };
182 prototype.clone = function() {
183 return $(this.div.cloneNode(true))
184 };
185 prototype.create = function(name, type) {
186 var $obj = $(name, type);
187 this.addChild($obj);
188 if (this.__root) {
189 this.__root.__append[name] = $obj;
190 $obj.__root = this.__root
191 }
192 return $obj
193 };
194 prototype.empty = function() {
195 var child = this._children.start();
196 while (child) {
197 if (child && child.remove) child.remove();
198 child = this._children.next()
199 }
200 this.div.innerHTML = "";
201 return this
202 };
203 prototype.parent = function() {
204 return this._parent
205 };
206 prototype.children = function() {
207 return this.div.children ? this.div.children : this.div.childNodes
208 };
209 prototype.append = function(callback, params) {
210 if (!this.__root) {
211 this.__root = this;
212 this.__append = {}
213 }
214 return callback.apply(this, params)
215 };
216 prototype.removeChild = function(object, keep) {
217 try {
218 object.div.parentNode.removeChild(object.div)
219 } catch (e) {};
220 if (!keep) this._children.remove(object)
221 };
222 prototype.remove = prototype.destroy = function() {
223 this.removed = true;
224 var parent = this._parent;
225 if (!!(parent && !parent.removed && parent.removeChild)) parent.removeChild(this, true);
226 var child = this._children.start();
227 while (child) {
228 if (child && child.remove) child.remove();
229 child = this._children.next()
230 }
231 this._children.destroy();
232 this.div.hydraObject = null;
233 Utils.nullObject(this)
234 }
235});
236Class(function Hydra() {
237 var _this = this;
238 var _inter, _pool;
239 var _readyCallbacks = [];
240 this.READY = false;
241 this.HASH = window.location.hash.slice(1);
242 this.LOCAL = !window._BUILT_ && (location.hostname.indexOf("local") > -1 || location.hostname.split(".")[0] == "10" || location.hostname.split(".")[0] == "192");
243 (function() {
244 initLoad()
245 }());
246
247 function initLoad() {
248 if (!document || !window) return setTimeout(initLoad, 1);
249 if (window._NODE_ || window._GLES_) {
250 _this.addEvent = "addEventListener";
251 _this.removeEvent = "removeEventListener";
252 return setTimeout(loaded, 1)
253 }
254 if (window.addEventListener) {
255 _this.addEvent = "addEventListener";
256 _this.removeEvent = "removeEventListener";
257 window.addEventListener("load", loaded, false)
258 } else {
259 _this.addEvent = "attachEvent";
260 _this.removeEvent = "detachEvent";
261 window.attachEvent("onload", loaded)
262 }
263 }
264
265 function loaded() {
266 if (window.removeEventListener) window.removeEventListener("load", loaded, false);
267 if (!_readyCallbacks) return;
268 for (var i = 0; i < _readyCallbacks.length; i++) {
269 _readyCallbacks[i]()
270 }
271 _readyCallbacks = null;
272 _this.READY = true;
273 if (window.Main) Hydra.Main = new window.Main
274 }
275 this.development = function(flag, array) {
276 var matchArray = function(prop) {
277 if (!array) return false;
278 for (var i = 0; i < array.length; i++) {
279 if (prop.strpos(array[i])) return true
280 }
281 return false
282 };
283 clearInterval(_inter);
284 if (flag) {
285 _inter = setInterval(function() {
286 for (var prop in window) {
287 if (prop.strpos("webkit")) continue;
288 var obj = window[prop];
289 if (typeof obj !== "function" && prop.length > 2) {
290 if (prop.strpos("_ga") || prop.strpos("_typeface_js") || matchArray(prop)) continue;
291 var char1 = prop.charAt(0);
292 var char2 = prop.charAt(1);
293 if (char1 == "_" || char1 == "$") {
294 if (char2 !== char2.toUpperCase()) {
295 console.log(window[prop]);
296 throw "Hydra Warning:: " + prop + " leaking into global scope"
297 }
298 }
299 }
300 }
301 }, 1e3)
302 }
303 };
304 this.getArguments = function(value) {
305 var saved = this.arguments;
306 var args = [];
307 for (var i = 1; i < saved.length; i++) {
308 if (saved[i] !== null) args.push(saved[i])
309 }
310 return args
311 };
312 this.getClassName = function(obj) {
313 return obj.constructor.name || obj.constructor.toString().match(/function ([^\(]+)/)[1]
314 };
315 this.ready = function(callback) {
316 if (this.READY) return callback();
317 _readyCallbacks.push(callback)
318 };
319 this.$ = function(selector, type, exists) {
320 return new HydraObject(selector, type, exists)
321 };
322 this.__triggerReady = function() {
323 loaded()
324 };
325 this.setPageOffset = function(x, y) {
326 _this.__offset = {
327 x: x,
328 y: y
329 };
330 Stage.css({
331 left: x,
332 top: y,
333 width: Stage.width - x,
334 height: Stage.height - y
335 })
336 };
337 this.INTERFACES = {};
338 this.HTML = {};
339 this.JSON = {};
340 this.SVG = {};
341 this.$.fn = HydraObject.prototype;
342 window.$ = this.$;
343 window.ready = this.ready
344}, "Static");
345Hydra.ready(function() {
346 window.__window = $(window);
347 window.__document = $(document);
348 window.__body = $(document.getElementsByTagName("body")[0]);
349 window.Stage = window.Stage ? $(window.Stage) : __body.create("#Stage");
350 Stage.size("100%");
351 Stage.__useFragment = true;
352 Stage.width = document.body.clientWidth || document.documentElement.offsetWidth || window.innerWidth;
353 Stage.height = document.body.clientHeight || document.documentElement.offsetHeight || window.innerHeight;
354 (function() {
355 var _time = Date.now();
356 var _last;
357 setTimeout(function() {
358 var list = ["hidden", "msHidden", "webkitHidden"];
359 var hidden, eventName;
360 (function() {
361 for (var key in list) {
362 if (document[list[key]] !== "undefined") {
363 hidden = list[key];
364 switch (hidden) {
365 case "hidden":
366 eventName = "visibilitychange";
367 break;
368 case "msHidden":
369 eventName = "msvisibilitychange";
370 break;
371 case "webkitHidden":
372 eventName = "webkitvisibilitychange";
373 break
374 }
375 return
376 }
377 }
378 }());
379 if (typeof document[hidden] === "undefined") {
380 if (Device.browser.ie) {
381 document.onfocus = onfocus;
382 document.onblur = onblur
383 } else {
384 window.onfocus = onfocus;
385 window.onblur = onblur
386 }
387 } else {
388 document.addEventListener(eventName, function() {
389 var time = Date.now();
390 if (time - _time > 10) {
391 if (document[hidden] === false) onfocus();
392 else onblur()
393 }
394 _time = time
395 })
396 }
397 }, 250);
398
399 function onfocus() {
400 if (_last != "focus") HydraEvents._fireEvent(HydraEvents.BROWSER_FOCUS, {
401 type: "focus"
402 });
403 _last = "focus"
404 }
405
406 function onblur() {
407 if (_last != "blur") HydraEvents._fireEvent(HydraEvents.BROWSER_FOCUS, {
408 type: "blur"
409 });
410 _last = "blur"
411 }
412 }());
413 window.onresize = function() {
414 if (!Device.mobile) {
415 Stage.width = document.body.clientWidth || document.documentElement.offsetWidth || window.innerWidth;
416 Stage.height = document.body.clientHeight || document.documentElement.offsetHeight || window.innerHeight;
417 if (Hydra.__offset) {
418 Stage.width -= Hydra.__offset.x;
419 Stage.height -= Hydra.__offset.y;
420 Stage.css({
421 width: Stage.width,
422 height: Stage.height
423 })
424 }
425 HydraEvents._fireEvent(HydraEvents.RESIZE)
426 }
427 }
428});
429(function() {
430 $.fn.text = function(text) {
431 if (typeof text !== "undefined") {
432 if (this.__cacheText != text) this.div.textContent = text;
433 this.__cacheText = text;
434 return this
435 } else {
436 return this.div.textContent
437 }
438 };
439 $.fn.html = function(text, force) {
440 if (text && !text.strpos("<") && !force) return this.text(text);
441 if (typeof text !== "undefined") {
442 this.div.innerHTML = text;
443 return this
444 } else {
445 return this.div.innerHTML
446 }
447 };
448 $.fn.hide = function() {
449 this.div.style.display = "none";
450 return this
451 };
452 $.fn.show = function() {
453 this.div.style.display = "";
454 return this
455 };
456 $.fn.visible = function() {
457 this.div.style.visibility = "visible";
458 return this
459 };
460 $.fn.invisible = function() {
461 this.div.style.visibility = "hidden";
462 return this
463 };
464 $.fn.setZ = function(z) {
465 this.div.style.zIndex = z;
466 return this
467 };
468 $.fn.clearAlpha = function() {
469 this.div.style.opacity = "";
470 return this
471 };
472 $.fn.size = function(w, h, noScale) {
473 if (typeof w === "string") {
474 if (typeof h === "undefined") h = "100%";
475 else if (typeof h !== "string") h = h + "px";
476 this.div.style.width = w;
477 this.div.style.height = h
478 } else {
479 this.div.style.width = w + "px";
480 this.div.style.height = h + "px";
481 if (!noScale) this.div.style.backgroundSize = w + "px " + h + "px"
482 }
483 this.width = w;
484 this.height = h;
485 return this
486 };
487 $.fn.mouseEnabled = function(bool) {
488 this.div.style.pointerEvents = bool ? "auto" : "none";
489 return this
490 };
491 $.fn.fontStyle = function(family, size, color, style) {
492 var font = {};
493 if (family) font.fontFamily = family;
494 if (size) font.fontSize = size;
495 if (color) font.color = color;
496 if (style) font.fontStyle = style;
497 this.css(font);
498 return this
499 };
500 $.fn.bg = function(src, x, y, repeat) {
501 if (!src) return this;
502 if (src.strpos(".")) src = Images.getPath(src);
503 if (!src.strpos(".")) this.div.style.backgroundColor = src;
504 else this.div.style.backgroundImage = "url(" + src + ")";
505 if (typeof x !== "undefined") {
506 x = typeof x == "number" ? x + "px" : x;
507 y = typeof y == "number" ? y + "px" : y;
508 this.div.style.backgroundPosition = x + " " + y
509 }
510 if (repeat) {
511 this.div.style.backgroundSize = "";
512 this.div.style.backgroundRepeat = repeat
513 }
514 if (x == "cover" || x == "contain") {
515 this.div.style.backgroundSize = x;
516 this.div.style.backgroundPosition = typeof y != "undefined" ? y + " " + repeat : "center"
517 }
518 return this
519 };
520 $.fn.center = function(x, y, noPos) {
521 var css = {};
522 if (typeof x === "undefined") {
523 css.left = "50%";
524 css.top = "50%";
525 css.marginLeft = -this.width / 2;
526 css.marginTop = -this.height / 2
527 } else {
528 if (x) {
529 css.left = "50%";
530 css.marginLeft = -this.width / 2
531 }
532 if (y) {
533 css.top = "50%";
534 css.marginTop = -this.height / 2
535 }
536 }
537 if (noPos) {
538 delete css.left;
539 delete css.top
540 }
541 this.css(css);
542 return this
543 };
544 $.fn.mask = function(arg, x, y, w, h) {
545 this.div.style[CSS.prefix("Mask")] = (arg.strpos(".") ? "url(" + arg + ")" : arg) + " no-repeat";
546 this.div.style[CSS.prefix("MaskSize")] = "contain";
547 return this
548 };
549 $.fn.blendMode = function(mode, bg) {
550 if (bg) {
551 this.div.style["background-blend-mode"] = mode
552 } else {
553 this.div.style["mix-blend-mode"] = mode
554 }
555 return this
556 };
557 $.fn.css = function(obj, value) {
558 if (typeof value == "boolean") {
559 skip = value;
560 value = null
561 }
562 if (typeof obj !== "object") {
563 if (!value) {
564 var style = this.div.style[obj];
565 if (typeof style !== "number") {
566 if (style.strpos("px")) style = Number(style.slice(0, -2));
567 if (obj == "opacity") style = !isNaN(Number(this.div.style.opacity)) ? Number(this.div.style.opacity) : 1
568 }
569 if (!style) style = 0;
570 return style
571 } else {
572 this.div.style[obj] = value;
573 return this
574 }
575 }
576 TweenManager.clearCSSTween(this);
577 for (var type in obj) {
578 var val = obj[type];
579 if (!(typeof val === "string" || typeof val === "number")) continue;
580 if (typeof val !== "string" && type != "opacity" && type != "zIndex") val += "px";
581 this.div.style[type] = val
582 }
583 return this
584 };
585 $.fn.transform = function(props) {
586 if (this.multiTween && this.cssTweens && this._cssTweens.length > 1 && this.__transformTime && Render.TIME - this.__transformTime < 15) return;
587 this.__transformTime = Render.TIME;
588 TweenManager.clearCSSTween(this);
589 if (Device.tween.css2d) {
590 if (!props) {
591 props = this
592 } else {
593 for (var key in props) {
594 if (typeof props[key] === "number") this[key] = props[key]
595 }
596 }
597 var transformString;
598 if (!this._matrix) {
599 transformString = TweenManager.parseTransform(props)
600 } else {
601 if (this._matrix.type == "matrix2") {
602 this._matrix.setTRS(this.x, this.y, this.rotation, this.scaleX || this.scale, this.scaleY || this.scale)
603 } else {
604 this._matrix.setTRS(this.x, this.y, this.z, this.rotationX, this.rotationY, this.rotationZ, this.scaleX || this.scale, this.scaleY || this.scale, this.scaleZ || this.scale)
605 }
606 transformString = this._matrix.getCSS()
607 }
608 if (this.__transformCache != transformString) {
609 this.div.style[Device.styles.vendorTransform] = transformString;
610 this.__transformCache = transformString
611 }
612 }
613 return this
614 };
615 $.fn.useMatrix3D = function() {
616 this._matrix = new Matrix4;
617 this.x = 0;
618 this.y = 0;
619 this.z = 0;
620 this.rotationX = 0;
621 this.rotationY = 0;
622 this.rotationZ = 0;
623 this.scale = 1;
624 return this
625 };
626 $.fn.useMatrix2D = function() {
627 this._matrix = new Matrix2;
628 this.x = 0;
629 this.y = 0;
630 this.rotation = 0;
631 this.scale = 1;
632 return this
633 };
634 $.fn.willChange = function(props) {
635 if (typeof props === "boolean") {
636 if (props === true) this._willChangeLock = true;
637 else this._willChangeLock = false
638 } else {
639 if (this._willChangeLock) return
640 }
641 var string = typeof props === "string";
642 if ((!this._willChange || string) && typeof props !== "null") {
643 this._willChange = true;
644 this.div.style["will-change"] = string ? props : Device.transformProperty + ", opacity"
645 } else {
646 this._willChange = false;
647 this.div.style["will-change"] = ""
648 }
649 };
650 $.fn.backfaceVisibility = function(visible) {
651 if (visible) this.div.style[CSS.prefix("BackfaceVisibility")] = "visible";
652 else this.div.style[CSS.prefix("BackfaceVisibility")] = "hidden"
653 };
654 $.fn.enable3D = function(perspective, x, y) {
655 this.div.style[CSS.prefix("TransformStyle")] = "preserve-3d";
656 if (perspective) this.div.style[CSS.prefix("Perspective")] = perspective + "px";
657 if (typeof x !== "undefined") {
658 x = typeof x === "number" ? x + "px" : x;
659 y = typeof y === "number" ? y + "px" : y;
660 this.div.style[CSS.prefix("PerspectiveOrigin")] = x + " " + y
661 }
662 return this
663 };
664 $.fn.disable3D = function() {
665 this.div.style[CSS.prefix("TransformStyle")] = "";
666 this.div.style[CSS.prefix("Perspective")] = "";
667 return this
668 };
669 $.fn.transformPoint = function(x, y, z) {
670 var origin = "";
671 if (typeof x !== "undefined") origin += typeof x === "number" ? x + "px " : x + " ";
672 if (typeof y !== "undefined") origin += typeof y === "number" ? y + "px " : y + " ";
673 if (typeof z !== "undefined") origin += typeof z === "number" ? z + "px" : z;
674 this.div.style[CSS.prefix("TransformOrigin")] = origin;
675 return this
676 };
677 $.fn.tween = function(props, time, ease, delay, callback, manual) {
678 if (typeof delay === "boolean") {
679 manual = delay;
680 delay = 0;
681 callback = null
682 } else if (typeof delay === "function") {
683 callback = delay;
684 delay = 0
685 }
686 if (typeof callback === "boolean") {
687 manual = callback;
688 callback = null
689 }
690 if (!delay) delay = 0;
691 var usePromise = null;
692 if (callback && callback instanceof Promise) {
693 usePromise = callback;
694 callback = callback.resolve
695 }
696 var tween = TweenManager._detectTween(this, props, time, ease, delay, callback, manual);
697 return usePromise || tween
698 };
699 $.fn.clearTransform = function() {
700 if (typeof this.x === "number") this.x = 0;
701 if (typeof this.y === "number") this.y = 0;
702 if (typeof this.z === "number") this.z = 0;
703 if (typeof this.scale === "number") this.scale = 1;
704 if (typeof this.scaleX === "number") this.scaleX = 1;
705 if (typeof this.scaleY === "number") this.scaleY = 1;
706 if (typeof this.rotation === "number") this.rotation = 0;
707 if (typeof this.rotationX === "number") this.rotationX = 0;
708 if (typeof this.rotationY === "number") this.rotationY = 0;
709 if (typeof this.rotationZ === "number") this.rotationZ = 0;
710 if (typeof this.skewX === "number") this.skewX = 0;
711 if (typeof this.skewY === "number") this.skewY = 0;
712 this.div.style[Device.styles.vendorTransform] = "";
713 return this
714 };
715 $.fn.stopTween = function() {
716 if (this._cssTween) this._cssTween.stop();
717 if (this._mathTween) this._mathTween.stop();
718 return this
719 };
720 $.fn.keypress = function(callback) {
721 this.div.onkeypress = function(e) {
722 e = e || window.event;
723 e.code = e.keyCode ? e.keyCode : e.charCode;
724 if (callback) callback(e)
725 }
726 };
727 $.fn.keydown = function(callback) {
728 this.div.onkeydown = function(e) {
729 e = e || window.event;
730 e.code = e.keyCode;
731 if (callback) callback(e)
732 }
733 };
734 $.fn.keyup = function(callback) {
735 this.div.onkeyup = function(e) {
736 e = e || window.event;
737 e.code = e.keyCode;
738 if (callback) callback(e)
739 }
740 };
741 $.fn.attr = function(attr, value) {
742 if (attr && value) {
743 if (value == "") this.div.removeAttribute(attr);
744 else this.div.setAttribute(attr, value)
745 } else if (attr) {
746 return this.div.getAttribute(attr)
747 }
748 return this
749 };
750 $.fn.val = function(value) {
751 if (typeof value === "undefined") {
752 return this.div.value
753 } else {
754 this.div.value = value
755 }
756 return this
757 };
758 $.fn.change = function(callback) {
759 var _this = this;
760 if (this._type == "select") {
761 this.div.onchange = function() {
762 callback({
763 object: _this,
764 value: _this.div.value || ""
765 })
766 }
767 }
768 };
769 $.fn.svgSymbol = function(id, width, height) {
770 var config = SVG.getSymbolConfig(id);
771 var svgHTML = '<svg viewBox="0 0 ' + config.width + " " + config.height + '" width="' + width + '" height="' + height + '">' + '<use xlink:href="#' + config.id + '" x="0" y="0" />' + "</svg>";
772 this.html(svgHTML, true)
773 }
774}());
775(function() {
776 var windowsPointer = !!window.MSGesture;
777 var translateEvent = function(evt) {
778 if (Hydra.addEvent == "attachEvent") {
779 switch (evt) {
780 case "click":
781 return "onclick";
782 break;
783 case "mouseover":
784 return "onmouseover";
785 break;
786 case "mouseout":
787 return "onmouseleave";
788 break;
789 case "mousedown":
790 return "onmousedown";
791 break;
792 case "mouseup":
793 return "onmouseup";
794 break;
795 case "mousemove":
796 return "onmousemove";
797 break
798 }
799 }
800 if (windowsPointer) {
801 switch (evt) {
802 case "touchstart":
803 return "pointerdown";
804 break;
805 case "touchmove":
806 return "MSGestureChange";
807 break;
808 case "touchend":
809 return "pointerup";
810 break
811 }
812 }
813 return evt
814 };
815 $.fn.click = function(callback) {
816 var _this = this;
817
818 function click(e) {
819 if (!_this.div) return false;
820 if (Mouse._preventClicks) return false;
821 e.object = _this.div.className == "hit" ? _this.parent() : _this;
822 e.action = "click";
823 if (!e.pageX) {
824 e.pageX = e.clientX;
825 e.pageY = e.clientY
826 }
827 if (callback) callback(e);
828 if (Mouse.autoPreventClicks) Mouse.preventClicks()
829 }
830 this.div[Hydra.addEvent](translateEvent("click"), click, true);
831 this.div.style.cursor = "pointer";
832 return this
833 };
834 $.fn.hover = function(callback) {
835 var _this = this;
836 var _over = false;
837 var _time;
838
839 function hover(e) {
840 if (!_this.div) return false;
841 var time = Date.now();
842 var original = e.toElement || e.relatedTarget;
843 if (_time && time - _time < 5) {
844 _time = time;
845 return false
846 }
847 _time = time;
848 e.object = _this.div.className == "hit" ? _this.parent() : _this;
849 switch (e.type) {
850 case "mouseout":
851 e.action = "out";
852 break;
853 case "mouseleave":
854 e.action = "out";
855 break;
856 default:
857 e.action = "over";
858 break
859 }
860 if (_over) {
861 if (Mouse._preventClicks) return false;
862 if (e.action == "over") return false;
863 if (e.action == "out") {
864 if (isAChild(_this.div, original)) return false
865 }
866 _over = false
867 } else {
868 if (e.action == "out") return false;
869 _over = true
870 }
871 if (!e.pageX) {
872 e.pageX = e.clientX;
873 e.pageY = e.clientY
874 }
875 if (callback) callback(e)
876 }
877
878 function isAChild(div, object) {
879 var len = div.children.length - 1;
880 for (var i = len; i > -1; i--) {
881 if (object == div.children[i]) return true
882 }
883 for (i = len; i > -1; i--) {
884 if (isAChild(div.children[i], object)) return true
885 }
886 }
887 this.div[Hydra.addEvent](translateEvent("mouseover"), hover, true);
888 this.div[Hydra.addEvent](translateEvent("mouseout"), hover, true);
889 return this
890 };
891 $.fn.press = function(callback) {
892 var _this = this;
893
894 function press(e) {
895 if (!_this.div) return false;
896 e.object = _this.div.className == "hit" ? _this.parent() : _this;
897 switch (e.type) {
898 case "mousedown":
899 e.action = "down";
900 break;
901 default:
902 e.action = "up";
903 break
904 }
905 if (!e.pageX) {
906 e.pageX = e.clientX;
907 e.pageY = e.clientY
908 }
909 if (callback) callback(e)
910 }
911 this.div[Hydra.addEvent](translateEvent("mousedown"), press, true);
912 this.div[Hydra.addEvent](translateEvent("mouseup"), press, true);
913 return this
914 };
915 $.fn.bind = function(evt, callback) {
916 if (!this._events) this._events = {};
917 if (windowsPointer && this == __window) {
918 return Stage.bind(evt, callback)
919 }
920 if (evt == "touchstart") {
921 if (!Device.mobile) evt = "mousedown"
922 } else if (evt == "touchmove") {
923 if (!Device.mobile) evt = "mousemove";
924 if (windowsPointer && !this.div.msGesture) {
925 this.div.msGesture = new MSGesture;
926 this.div.msGesture.target = this.div
927 }
928 } else if (evt == "touchend") {
929 if (!Device.mobile) evt = "mouseup"
930 }
931 this._events["bind_" + evt] = this._events["bind_" + evt] || [];
932 var _events = this._events["bind_" + evt];
933 var e = {};
934 var target = this.div;
935 e.callback = callback;
936 e.target = this.div;
937 _events.push(e);
938
939 function touchEvent(e) {
940 if (windowsPointer && target.msGesture && evt == "touchstart") {
941 target.msGesture.addPointer(e.pointerId)
942 }
943 var touch = Utils.touchEvent(e);
944 if (windowsPointer) {
945 var windowsEvt = e;
946 e = {};
947 e.x = Number(windowsEvt.pageX || windowsEvt.clientX);
948 e.y = Number(windowsEvt.pageY || windowsEvt.clientY);
949 e.target = windowsEvt.target;
950 e.currentTarget = windowsEvt.currentTarget;
951 e.path = [];
952 var node = e.target;
953 while (node) {
954 e.path.push(node);
955 node = node.parentElement || null
956 }
957 e.windowsPointer = true
958 } else {
959 e.x = touch.x;
960 e.y = touch.y
961 }
962 for (var i = 0; i < _events.length; i++) {
963 var ev = _events[i];
964 if (ev.target == e.currentTarget) {
965 ev.callback(e)
966 }
967 }
968 }
969 if (!this._events["fn_" + evt]) {
970 this._events["fn_" + evt] = touchEvent;
971 this.div[Hydra.addEvent](translateEvent(evt), touchEvent, true)
972 }
973 return this
974 };
975 $.fn.unbind = function(evt, callback) {
976 if (!this._events) this._events = {};
977 if (windowsPointer && this == __window) {
978 return Stage.unbind(evt, callback)
979 }
980 if (evt == "touchstart") {
981 if (!Device.mobile) evt = "mousedown"
982 } else if (evt == "touchmove") {
983 if (!Device.mobile) evt = "mousemove"
984 } else if (evt == "touchend") {
985 if (!Device.mobile) evt = "mouseup"
986 }
987 var _events = this._events["bind_" + evt];
988 if (!_events) return this;
989 for (var i = 0; i < _events.length; i++) {
990 var ev = _events[i];
991 if (ev.callback == callback) _events.splice(i, 1)
992 }
993 if (this._events["fn_" + evt] && !_events.length) {
994 this.div[Hydra.removeEvent](translateEvent(evt), this._events["fn_" + evt], true);
995 this._events["fn_" + evt] = null
996 }
997 return this
998 };
999 $.fn.interact = function(overCallback, clickCallback) {
1000 if (!this.hit) {
1001 this.hit = $(".hit");
1002 this.hit.css({
1003 width: "100%",
1004 height: "100%",
1005 zIndex: 99999,
1006 top: 0,
1007 left: 0,
1008 position: "absolute"
1009 });
1010 this.addChild(this.hit)
1011 }
1012 if (!Device.mobile) this.hit.hover(overCallback).click(clickCallback);
1013 else this.hit.touchClick(overCallback, clickCallback)
1014 };
1015 $.fn.touchSwipe = function(callback, distance) {
1016 if (!window.addEventListener) return this;
1017 var _this = this;
1018 var _distance = distance || 75;
1019 var _startX, _startY;
1020 var _moving = false;
1021 var _move = {};
1022 if (Device.mobile) {
1023 this.div.addEventListener(translateEvent("touchstart"), touchStart);
1024 this.div.addEventListener(translateEvent("touchend"), touchEnd);
1025 this.div.addEventListener(translateEvent("touchcancel"), touchEnd)
1026 }
1027
1028 function touchStart(e) {
1029 var touch = Utils.touchEvent(e);
1030 if (!_this.div) return false;
1031 if (e.touches.length == 1) {
1032 _startX = touch.x;
1033 _startY = touch.y;
1034 _moving = true;
1035 _this.div.addEventListener(translateEvent("touchmove"), touchMove)
1036 }
1037 }
1038
1039 function touchMove(e) {
1040 if (!_this.div) return false;
1041 if (_moving) {
1042 var touch = Utils.touchEvent(e);
1043 var dx = _startX - touch.x;
1044 var dy = _startY - touch.y;
1045 _move.direction = null;
1046 _move.moving = null;
1047 _move.x = null;
1048 _move.y = null;
1049 _move.evt = e;
1050 if (Math.abs(dx) >= _distance) {
1051 touchEnd();
1052 if (dx > 0) {
1053 _move.direction = "left"
1054 } else {
1055 _move.direction = "right"
1056 }
1057 } else if (Math.abs(dy) >= _distance) {
1058 touchEnd();
1059 if (dy > 0) {
1060 _move.direction = "up"
1061 } else {
1062 _move.direction = "down"
1063 }
1064 } else {
1065 _move.moving = true;
1066 _move.x = dx;
1067 _move.y = dy
1068 }
1069 if (callback) callback(_move, e)
1070 }
1071 }
1072
1073 function touchEnd(e) {
1074 if (!_this.div) return false;
1075 _startX = _startY = _moving = false;
1076 _this.div.removeEventListener(translateEvent("touchmove"), touchMove)
1077 }
1078 return this
1079 };
1080 $.fn.touchClick = function(hover, click) {
1081 if (!window.addEventListener) return this;
1082 var _this = this;
1083 var _time, _move;
1084 var _start = {};
1085 var _touch = {};
1086 if (Device.mobile) {
1087 this.div.addEventListener(translateEvent("touchmove"), touchMove, false);
1088 this.div.addEventListener(translateEvent("touchstart"), touchStart, false);
1089 this.div.addEventListener(translateEvent("touchend"), touchEnd, false)
1090 }
1091
1092 function touchMove(e) {
1093 if (!_this.div) return false;
1094 _touch = Utils.touchEvent(e);
1095 if (Utils.findDistance(_start, _touch) > 5) {
1096 _move = true
1097 } else {
1098 _move = false
1099 }
1100 }
1101
1102 function setTouch(e) {
1103 var touch = Utils.touchEvent(e);
1104 e.touchX = touch.x;
1105 e.touchY = touch.y;
1106 _start.x = e.touchX;
1107 _start.y = e.touchY
1108 }
1109
1110 function touchStart(e) {
1111 if (!_this.div) return false;
1112 _time = Date.now();
1113 e.action = "over";
1114 e.object = _this.div.className == "hit" ? _this.parent() : _this;
1115 setTouch(e);
1116 if (hover && !_move) hover(e)
1117 }
1118
1119 function touchEnd(e) {
1120 if (!_this.div) return false;
1121 var time = Date.now();
1122 var clicked = false;
1123 e.object = _this.div.className == "hit" ? _this.parent() : _this;
1124 setTouch(e);
1125 if (_time && time - _time < 750) {
1126 if (Mouse._preventClicks) return false;
1127 if (click && !_move) {
1128 clicked = true;
1129 e.action = "click";
1130 if (click && !_move) click(e);
1131 if (Mouse.autoPreventClicks) Mouse.preventClicks()
1132 }
1133 }
1134 if (hover) {
1135 e.action = "out";
1136 if (!Mouse._preventFire) hover(e)
1137 }
1138 _move = false
1139 }
1140 return this
1141 }
1142}());
1143Class(function MVC() {
1144 Inherit(this, Events);
1145 var _setters = {};
1146 var _active = {};
1147 var _timers = [];
1148 this.classes = {};
1149
1150 function defineSetter(_this, prop) {
1151 _setters[prop] = {};
1152 Object.defineProperty(_this, prop, {
1153 set: function(v) {
1154 if (_setters[prop] && _setters[prop].s) _setters[prop].s.call(_this, v);
1155 v = null
1156 },
1157 get: function() {
1158 if (_setters[prop] && _setters[prop].g) return _setters[prop].g.apply(_this)
1159 }
1160 })
1161 }
1162 this.set = function(prop, callback) {
1163 if (!_setters[prop]) defineSetter(this, prop);
1164 _setters[prop].s = callback
1165 };
1166 this.get = function(prop, callback) {
1167 if (!_setters[prop]) defineSetter(this, prop);
1168 _setters[prop].g = callback
1169 };
1170 this.delayedCall = function(callback, time, params) {
1171 var _this = this;
1172 var timer = Timer.create(function() {
1173 if (_this.destroy) {
1174 callback && callback(params)
1175 }
1176 _this = callback = null
1177 }, time || 0);
1178 _timers.push(timer);
1179 if (_timers.length > 20) _timers.shift();
1180 return timer
1181 };
1182 this.initClass = function(clss, a, b, c, d, e, f, g) {
1183 var name = Utils.timestamp();
1184 if (window.Hydra) Hydra.arguments = arguments;
1185 var child = new clss(a, b, c, d, e, f, g);
1186 if (window.Hydra) Hydra.arguments = null;
1187 child.parent = this;
1188 if (child.destroy) {
1189 this.classes[name] = child;
1190 this.classes[name].__id = name
1191 }
1192 var lastArg = arguments[arguments.length - 1];
1193 if (Array.isArray(lastArg) && lastArg.length == 1 && lastArg[0] instanceof HydraObject) lastArg[0].addChild(child);
1194 else if (this.element && lastArg !== null) this.element.addChild(child);
1195 return child
1196 };
1197 this.destroy = function() {
1198 if (this.onDestroy) this.onDestroy();
1199 if (this.__renderLoop) Render.stop(this.__renderLoop);
1200 for (var i in this.classes) {
1201 var clss = this.classes[i];
1202 if (clss && clss.destroy) clss.destroy()
1203 }
1204 this.clearTimers && this.clearTimers();
1205 this.classes = null;
1206 if (this.events) this.events = this.events.destroy();
1207 if (this.element && this.element.remove) this.element = this.container = this.element.remove();
1208 if (this.parent && this.parent.__destroyChild) this.parent.__destroyChild(this.__id);
1209 return Utils.nullObject(this)
1210 };
1211 this.clearTimers = function() {
1212 for (let i = 0; i < _timers.length; i++) clearTimeout(_timers[i]);
1213 _timers.length = 0
1214 };
1215 this.active = function(name, value, time) {
1216 if (typeof value !== "undefined") {
1217 _active[name] = value;
1218 if (time) {
1219 this.delayedCall(function() {
1220 _active[name] = !_active[name]
1221 }, time)
1222 }
1223 } else {
1224 return _active[name]
1225 }
1226 };
1227 this.wait = function(callback, object, key) {
1228 var _this = this;
1229 if (!!object[key]) callback();
1230 else _this.delayedCall(function() {
1231 _this.wait(callback, object, key)
1232 }, 100)
1233 };
1234 this.__destroyChild = function(name) {
1235 delete this.classes[name]
1236 }
1237});
1238Class(function Model(name) {
1239 Inherit(this, MVC);
1240 var _storage = {};
1241 var _data = 0;
1242 var _triggered = 0;
1243 this.push = function(name, val) {
1244 _storage[name] = val
1245 };
1246 this.pull = function(name) {
1247 return _storage[name]
1248 };
1249 this.waitForData = function(num = 1) {
1250 _data += num
1251 };
1252 this.fulfillData = function() {
1253 _triggered++;
1254 if (_triggered == _data) {
1255 this.dataReady = true
1256 }
1257 };
1258 this.onReady = function(callback) {
1259 let promise = Promise.create();
1260 if (callback) promise.then(callback);
1261 this.wait(() => promise.resolve(), this, "dataReady");
1262 return promise
1263 };
1264 this.initWithData = function(data) {
1265 this.STATIC_DATA = data;
1266 for (var key in this) {
1267 var model = this[key];
1268 var init = false;
1269 for (var i in data) {
1270 if (i.toLowerCase().replace(/-/g, "") == key.toLowerCase()) {
1271 init = true;
1272 if (model.init) model.init(data[i])
1273 }
1274 }
1275 if (!init && model.init) model.init()
1276 }
1277 };
1278 this.loadData = function(url, callback) {
1279 var _this = this;
1280 XHR.get(url + "?" + Utils.timestamp(), function(d) {
1281 defer(function() {
1282 _this.initWithData(d);
1283 callback(d)
1284 })
1285 })
1286 };
1287 this.Class = function(model) {
1288 var name = model.toString().match(/function ([^\(]+)/)[1];
1289 this[name] = new model
1290 }
1291});
1292Class(function View(_child) {
1293 Inherit(this, MVC);
1294 var _resize;
1295 var name = Hydra.getClassName(_child);
1296 this.element = $("." + name);
1297 this.element.__useFragment = true;
1298 this.css = function(obj) {
1299 this.element.css(obj);
1300 return this
1301 };
1302 this.transform = function(obj) {
1303 this.element.transform(obj || this);
1304 return this
1305 };
1306 this.tween = function(props, time, ease, delay, callback, manual) {
1307 return this.element.tween(props, time, ease, delay, callback, manual)
1308 };
1309 this.startRender = function(callback) {
1310 this.__renderLoop = callback;
1311 Render.start(callback)
1312 };
1313 this.stopRender = function(callback) {
1314 this.__renderLoop = null;
1315 Render.stop(callback)
1316 };
1317 var inter = Hydra.INTERFACES[name] || Hydra.INTERFACES[name + "UI"];
1318 if (inter) {
1319 this.ui = {};
1320 var params = Hydra.getArguments();
1321 params.push(_child);
1322 _resize = this.element.append(inter, params);
1323 var append = this.element.__append;
1324 for (var key in append) this.ui[key] = append[key];
1325 if (_resize) {
1326 this.resize = function() {
1327 _resize.apply(this.ui, arguments)
1328 }
1329 }
1330 }
1331 this.__call = function() {
1332 this.events.scope(this)
1333 }
1334});
1335Class(function Controller(name) {
1336 Inherit(this, MVC);
1337 name = Hydra.getClassName(name);
1338 this.element = this.container = $("#" + name);
1339 this.element.__useFragment = true;
1340 this.css = function(obj) {
1341 this.container.css(obj)
1342 }
1343});
1344Class(function Component() {
1345 Inherit(this, MVC);
1346 this.startRender = function(callback) {
1347 this.__renderLoop = callback;
1348 Render.start(callback)
1349 };
1350 this.stopRender = function(callback) {
1351 this.__renderLoop = null;
1352 Render.stop(callback)
1353 };
1354 this.__call = function() {
1355 this.events.scope(this);
1356 delete this.__call
1357 }
1358});
1359Class(function Utils() {
1360 var _this = this;
1361 var _obj = {};
1362 if (typeof Float32Array == "undefined") Float32Array = Array;
1363
1364 function rand(min, max) {
1365 return lerp(Math.random(), min, max)
1366 }
1367
1368 function lerp(ratio, start, end) {
1369 return start + (end - start) * ratio
1370 }
1371 this.doRandom = function(min, max, precision) {
1372 if (typeof precision == "number") {
1373 var p = Math.pow(10, precision);
1374 return Math.round(rand(min, max) * p) / p
1375 } else {
1376 return Math.round(rand(min - .5, max + .5))
1377 }
1378 };
1379 this.headsTails = function(heads, tails) {
1380 return !_this.doRandom(0, 1) ? heads : tails
1381 };
1382 this.toDegrees = function(rad) {
1383 return rad * (180 / Math.PI)
1384 };
1385 this.toRadians = function(deg) {
1386 return deg * (Math.PI / 180)
1387 };
1388 this.findDistance = function(p1, p2) {
1389 var dx = p2.x - p1.x;
1390 var dy = p2.y - p1.y;
1391 return Math.sqrt(dx * dx + dy * dy)
1392 };
1393 this.timestamp = function() {
1394 var num = Date.now() + _this.doRandom(0, 99999);
1395 return num.toString()
1396 };
1397 this.hitTestObject = function(obj1, obj2) {
1398 var x1 = obj1.x,
1399 y1 = obj1.y,
1400 w = obj1.width,
1401 h = obj1.height;
1402 var xp1 = obj2.x,
1403 yp1 = obj2.y,
1404 wp = obj2.width,
1405 hp = obj2.height;
1406 var x2 = x1 + w,
1407 y2 = y1 + h,
1408 xp2 = xp1 + wp,
1409 yp2 = yp1 + hp;
1410 if (xp1 >= x1 && xp1 <= x2) {
1411 if (yp1 >= y1 && yp1 <= y2) {
1412 return true
1413 } else if (y1 >= yp1 && y1 <= yp2) {
1414 return true
1415 }
1416 } else if (x1 >= xp1 && x1 <= xp2) {
1417 if (yp1 >= y1 && yp1 <= y2) {
1418 return true
1419 } else if (y1 >= yp1 && y1 <= yp2) {
1420 return true
1421 }
1422 }
1423 return false
1424 };
1425 this.randomColor = function() {
1426 var color = "#" + Math.floor(Math.random() * 16777215).toString(16);
1427 if (color.length < 7) color = this.randomColor();
1428 return color
1429 };
1430 this.touchEvent = function(e) {
1431 var touchEvent = {};
1432 touchEvent.x = 0;
1433 touchEvent.y = 0;
1434 if (e.windowsPointer) return e;
1435 if (!e) return touchEvent;
1436 if (Device.mobile && (e.touches || e.changedTouches)) {
1437 if (e.touches.length) {
1438 touchEvent.x = e.touches[0].pageX;
1439 touchEvent.y = e.touches[0].pageY - Mobile.scrollTop
1440 } else {
1441 touchEvent.x = e.changedTouches[0].pageX;
1442 touchEvent.y = e.changedTouches[0].pageY - Mobile.scrollTop
1443 }
1444 } else {
1445 touchEvent.x = e.pageX;
1446 touchEvent.y = e.pageY
1447 }
1448 if (Mobile.orientationSet && Mobile.orientation !== Mobile.orientationSet) {
1449 if (window.orientation == 90 || window.orientation === 0) {
1450 var x = touchEvent.y;
1451 touchEvent.y = touchEvent.x;
1452 touchEvent.x = Stage.width - x
1453 }
1454 if (window.orientation == -90 || window.orientation === 180) {
1455 var y = touchEvent.x;
1456 touchEvent.x = touchEvent.y;
1457 touchEvent.y = Stage.height - y
1458 }
1459 }
1460 return touchEvent
1461 };
1462 this.clamp = function(num, min, max) {
1463 return Math.min(Math.max(num, min), max)
1464 };
1465 this.constrain = function(num, min, max) {
1466 return Math.min(Math.max(num, Math.min(min, max)), Math.max(min, max))
1467 };
1468 this.nullObject = function(object) {
1469 if (object.destroy || object.div) {
1470 for (var key in object) {
1471 if (typeof object[key] !== "undefined") object[key] = null
1472 }
1473 }
1474 return null
1475 };
1476 this.convertRange = this.range = function(oldValue, oldMin, oldMax, newMin, newMax, clamped) {
1477 var oldRange = oldMax - oldMin;
1478 var newRange = newMax - newMin;
1479 var newValue = (oldValue - oldMin) * newRange / oldRange + newMin;
1480 if (clamped) return _this.clamp(newValue, Math.min(newMin, newMax), Math.max(newMin, newMax));
1481 return newValue
1482 };
1483 this.cloneObject = function(obj) {
1484 return JSON.parse(JSON.stringify(obj))
1485 };
1486 this.mergeObject = function() {
1487 var obj = {};
1488 for (var i = 0; i < arguments.length; i++) {
1489 var o = arguments[i];
1490 for (var key in o) {
1491 obj[key] = o[key]
1492 }
1493 }
1494 return obj
1495 };
1496 this.mix = function(from, to, alpha) {
1497 return from * (1 - alpha) + to * alpha
1498 };
1499 this.numberWithCommas = function(num) {
1500 return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
1501 };
1502 this.query = function(key) {
1503 return decodeURI(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURI(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"))
1504 };
1505 this.smoothstep = function(min, max, value) {
1506 var x = Math.max(0, Math.min(1, (value - min) / (max - min)));
1507 return x * x * (3 - 2 * x)
1508 };
1509 String.prototype.strpos = function(str) {
1510 if (Array.isArray(str)) {
1511 for (var i = 0; i < str.length; i++) {
1512 if (this.indexOf(str[i]) > -1) return true
1513 }
1514 return false
1515 } else {
1516 return this.indexOf(str) != -1
1517 }
1518 };
1519 String.prototype.clip = function(num, end) {
1520 return this.length > num ? this.slice(0, num) + end : this
1521 };
1522 String.prototype.capitalize = function() {
1523 return this.charAt(0).toUpperCase() + this.slice(1)
1524 };
1525 Array.prototype.findAndRemove = function(reference) {
1526 if (!this.indexOf) return;
1527 var index = this.indexOf(reference);
1528 if (index > -1) return this.splice(index, 1)
1529 };
1530 Array.prototype.getRandom = function() {
1531 return this[_this.doRandom(0, this.length - 1)]
1532 };
1533 Promise.create = function() {
1534 var promise = new Promise(function(resolve, reject) {
1535 _obj.resolve = resolve;
1536 _obj.reject = reject
1537 });
1538 promise.resolve = _obj.resolve;
1539 promise.reject = _obj.reject;
1540 if (arguments.length) {
1541 var fn = arguments[0];
1542 var params = [];
1543 for (var i = 1; i < arguments.length; i++) params.push(arguments[i]);
1544 params.push(promise.resolve);
1545 fn.apply(fn, params)
1546 }
1547 _obj.resolve = _obj.reject = null;
1548 return promise
1549 }
1550}, "Static");
1551Class(function CSS() {
1552 var _this = this;
1553 var _obj, _style, _needsUpdate;
1554 Hydra.ready(function() {
1555 _style = "";
1556 _obj = document.createElement("style");
1557 _obj.type = "text/css";
1558 document.getElementsByTagName("head")[0].appendChild(_obj)
1559 });
1560
1561 function objToCSS(key) {
1562 var match = key.match(/[A-Z]/);
1563 var camelIndex = match ? match.index : null;
1564 if (camelIndex) {
1565 var start = key.slice(0, camelIndex);
1566 var end = key.slice(camelIndex);
1567 key = start + "-" + end.toLowerCase()
1568 }
1569 return key
1570 }
1571
1572 function cssToObj(key) {
1573 var match = key.match(/\-/);
1574 var camelIndex = match ? match.index : null;
1575 if (camelIndex) {
1576 var start = key.slice(0, camelIndex);
1577 var end = key.slice(camelIndex).slice(1);
1578 var letter = end.charAt(0);
1579 end = end.slice(1);
1580 end = letter.toUpperCase() + end;
1581 key = start + end
1582 }
1583 return key
1584 }
1585
1586 function setHTML() {
1587 _obj.innerHTML = _style;
1588 _needsUpdate = false
1589 }
1590 this._read = function() {
1591 return _style
1592 };
1593 this._write = function(css) {
1594 _style = css;
1595 if (!_needsUpdate) {
1596 _needsUpdate = true;
1597 defer(setHTML)
1598 }
1599 };
1600 this._toCSS = objToCSS;
1601 this.style = function(selector, obj) {
1602 var s = selector + " {";
1603 for (var key in obj) {
1604 var prop = objToCSS(key);
1605 var val = obj[key];
1606 if (typeof val !== "string" && key != "opacity") val += "px";
1607 s += prop + ":" + val + "!important;"
1608 }
1609 s += "}";
1610 _obj.innerHTML += s
1611 };
1612 this.get = function(selector, prop) {
1613 var values = new Object;
1614 var string = _obj.innerHTML.split(selector + " {");
1615 for (var i = 0; i < string.length; i++) {
1616 var str = string[i];
1617 if (!str.length) continue;
1618 var split = str.split("!important;");
1619 for (var j in split) {
1620 if (split[j].strpos(":")) {
1621 var fsplit = split[j].split(":");
1622 if (fsplit[1].slice(-2) == "px") {
1623 fsplit[1] = Number(fsplit[1].slice(0, -2))
1624 }
1625 values[cssToObj(fsplit[0])] = fsplit[1]
1626 }
1627 }
1628 }
1629 if (!prop) return values;
1630 else return values[prop]
1631 };
1632 this.textSize = function($obj) {
1633 var $clone = $obj.clone();
1634 $clone.css({
1635 position: "relative",
1636 cssFloat: "left",
1637 styleFloat: "left",
1638 marginTop: -99999,
1639 width: "",
1640 height: ""
1641 });
1642 __body.addChild($clone);
1643 var width = $clone.div.offsetWidth;
1644 var height = $clone.div.offsetHeight;
1645 $clone.remove();
1646 return {
1647 width: width,
1648 height: height
1649 }
1650 };
1651 this.prefix = function(style) {
1652 return Device.styles.vendor == "" ? style.charAt(0).toLowerCase() + style.slice(1) : Device.styles.vendor + style
1653 }
1654}, "Static");
1655Class(function Device() {
1656 var _this = this;
1657 var _tagDiv;
1658 this.agent = navigator.userAgent.toLowerCase();
1659 this.detect = function(array) {
1660 if (typeof array === "string") array = [array];
1661 for (var i = 0; i < array.length; i++) {
1662 if (this.agent.strpos(array[i])) return true
1663 }
1664 return false
1665 };
1666 var prefix = function() {
1667 var pre = "";
1668 if (!window._NODE_ && !window._GLES_) {
1669 var styles = window.getComputedStyle(document.documentElement, "");
1670 pre = (Array.prototype.slice.call(styles).join("").match(/-(moz|webkit|ms)-/) || styles.OLink === "" && ["", "o"])[1];
1671 var dom = "WebKit|Moz|MS|O".match(new RegExp("(" + pre + ")", "i"))[1]
1672 } else {
1673 pre = "webkit"
1674 }
1675 var IE = _this.detect("trident");
1676 return {
1677 unprefixed: IE && !_this.detect("msie 9"),
1678 dom: dom,
1679 lowercase: pre,
1680 css: "-" + pre + "-",
1681 js: (IE ? pre[0] : pre[0].toUpperCase()) + pre.substr(1)
1682 }
1683 }();
1684
1685 function checkForTag(prop) {
1686 var div = _tagDiv || document.createElement("div"),
1687 vendors = "Khtml ms O Moz Webkit".split(" "),
1688 len = vendors.length;
1689 _tagDiv = div;
1690 if (prop in div.style) return true;
1691 prop = prop.replace(/^[a-z]/, function(val) {
1692 return val.toUpperCase()
1693 });
1694 while (len--) {
1695 if (vendors[len] + prop in div.style) {
1696 return true
1697 }
1698 }
1699 return false
1700 }
1701 this.mobile = !window._NODE_ && (!!("ontouchstart" in window || "onpointerdown" in window) && this.detect(["ios", "iphone", "ipad", "windows", "android", "blackberry"])) ? {} : false;
1702 if (this.mobile && this.detect("windows") && !this.detect("touch")) this.mobile = false;
1703 if (this.mobile) {
1704 this.mobile.tablet = Math.max(screen.width, screen.height) > 1e3;
1705 this.mobile.phone = !this.mobile.tablet
1706 }
1707 this.browser = {};
1708 this.browser.ie = function() {
1709 if (_this.detect("msie")) return true;
1710 if (_this.detect("trident") && _this.detect("rv:")) return true;
1711 if (_this.detect("windows") && _this.detect("edge")) return true
1712 }();
1713 this.browser.chrome = !this.browser.ie && this.detect("chrome");
1714 this.browser.safari = !this.browser.chrome && !this.browser.ie && this.detect("safari");
1715 this.browser.firefox = this.detect("firefox");
1716 this.browser.version = function() {
1717 try {
1718 if (_this.browser.chrome) return Number(_this.agent.split("chrome/")[1].split(".")[0]);
1719 if (_this.browser.firefox) return Number(_this.agent.split("firefox/")[1].split(".")[0]);
1720 if (_this.browser.safari) return Number(_this.agent.split("version/")[1].split(".")[0].split(".")[0]);
1721 if (_this.browser.ie) {
1722 if (_this.detect("msie")) return Number(_this.agent.split("msie ")[1].split(".")[0]);
1723 if (_this.detect("rv:")) return Number(_this.agent.split("rv:")[1].split(".")[0]);
1724 return Number(_this.agent.split("edge/")[1].split(".")[0])
1725 }
1726 } catch (e) {
1727 return -1
1728 }
1729 }();
1730 this.vendor = prefix.css;
1731 this.transformProperty = function() {
1732 switch (prefix.lowercase) {
1733 case "moz":
1734 return "-moz-transform";
1735 break;
1736 case "webkit":
1737 return "-webkit-transform";
1738 break;
1739 case "o":
1740 return "-o-transform";
1741 break;
1742 case "ms":
1743 return "-ms-transform";
1744 break;
1745 default:
1746 return "transform";
1747 break
1748 }
1749 }();
1750 this.system = {};
1751 this.system.retina = window.devicePixelRatio > 1;
1752 this.system.webworker = typeof window.Worker !== "undefined";
1753 this.system.offline = typeof window.applicationCache !== "undefined";
1754 if (!window._NODE_) {
1755 this.system.geolocation = typeof navigator.geolocation !== "undefined";
1756 this.system.pushstate = typeof window.history.pushState !== "undefined"
1757 }
1758 this.system.webcam = !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
1759 this.system.language = window.navigator.userLanguage || window.navigator.language;
1760 this.system.webaudio = typeof window.AudioContext !== "undefined";
1761 this.system.vr = !!window.VRDisplay;
1762 try {
1763 this.system.localStorage = typeof window.localStorage !== "undefined"
1764 } catch (e) {
1765 this.system.localStorage = false
1766 }
1767 this.system.fullscreen = typeof document[prefix.lowercase + "CancelFullScreen"] !== "undefined";
1768 this.system.os = function() {
1769 if (_this.detect("mac os")) return "mac";
1770 else if (_this.detect("windows nt 6.3")) return "windows8.1";
1771 else if (_this.detect("windows nt 6.2")) return "windows8";
1772 else if (_this.detect("windows nt 6.1")) return "windows7";
1773 else if (_this.detect("windows nt 6.0")) return "windowsvista";
1774 else if (_this.detect("windows nt 5.1")) return "windowsxp";
1775 else if (_this.detect("windows")) return "windows";
1776 else if (_this.detect("linux")) return "linux";
1777 return "undetected"
1778 }();
1779 this.pixelRatio = window.devicePixelRatio;
1780 this.media = {};
1781 this.media.audio = function() {
1782 if (!!document.createElement("audio").canPlayType) {
1783 return _this.detect(["firefox", "opera"]) ? "ogg" : "mp3"
1784 } else {
1785 return false
1786 }
1787 }();
1788 this.media.video = function() {
1789 var vid = document.createElement("video");
1790 if (!!vid.canPlayType) {
1791 if (Device.mobile) return "mp4";
1792 if (_this.browser.chrome) return "webm";
1793 if (_this.browser.firefox || _this.browser.opera) {
1794 if (vid.canPlayType('video/webm; codecs="vorbis,vp8"')) return "webm";
1795 return "ogv"
1796 }
1797 return "mp4"
1798 } else {
1799 return false
1800 }
1801 }();
1802 this.graphics = {};
1803 this.graphics.webgl = function() {
1804 try {
1805 var gl;
1806 var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
1807 var canvas = document.createElement("canvas");
1808 for (var i = 0; i < names.length; i++) {
1809 gl = canvas.getContext(names[i]);
1810 if (gl) break
1811 }
1812 var info = gl.getExtension("WEBGL_debug_renderer_info");
1813 var output = {};
1814 if (info) {
1815 var gpu = info.UNMASKED_RENDERER_WEBGL;
1816 output.gpu = gl.getParameter(gpu).toLowerCase()
1817 }
1818 output.renderer = gl.getParameter(gl.RENDERER).toLowerCase();
1819 output.version = gl.getParameter(gl.VERSION).toLowerCase();
1820 output.glsl = gl.getParameter(gl.SHADING_LANGUAGE_VERSION).toLowerCase();
1821 output.extensions = gl.getSupportedExtensions();
1822 output.detect = function(matches) {
1823 if (output.gpu && output.gpu.toLowerCase().strpos(matches)) return true;
1824 if (output.version && output.version.toLowerCase().strpos(matches)) return true;
1825 for (var i = 0; i < output.extensions.length; i++) {
1826 if (output.extensions[i].toLowerCase().strpos(matches)) return true
1827 }
1828 return false
1829 };
1830 return output
1831 } catch (e) {
1832 return false
1833 };
1834 }();
1835 this.graphics.canvas = function() {
1836 var canvas = document.createElement("canvas");
1837 return canvas.getContext ? true : false
1838 }();
1839 this.styles = {};
1840 this.styles.filter = checkForTag("filter");
1841 this.styles.blendMode = checkForTag("mix-blend-mode");
1842 this.styles.vendor = prefix.unprefixed ? "" : prefix.js;
1843 this.styles.vendorTransition = this.styles.vendor.length ? this.styles.vendor + "Transition" : "transition";
1844 this.styles.vendorTransform = this.styles.vendor.length ? this.styles.vendor + "Transform" : "transform";
1845 this.tween = {};
1846 this.tween.transition = checkForTag("transition");
1847 this.tween.css2d = checkForTag("transform");
1848 this.tween.css3d = checkForTag("perspective");
1849 this.tween.complete = function() {
1850 if (prefix.unprefixed) return "transitionend";
1851 return prefix.lowercase + "TransitionEnd"
1852 }();
1853 this.test = function(name, test) {
1854 this[name] = test()
1855 };
1856
1857 function checkFullscreen() {
1858 if (!_this.getFullscreen()) {
1859 HydraEvents._fireEvent(HydraEvents.FULLSCREEN, {
1860 fullscreen: false
1861 });
1862 Render.stop(checkFullscreen)
1863 }
1864 }
1865 this.openFullscreen = function(obj) {
1866 obj = obj || __body;
1867 if (obj && _this.system.fullscreen) {
1868 if (obj == __body) obj.css({
1869 top: 0
1870 });
1871 obj.div[prefix.lowercase + "RequestFullScreen"]();
1872 HydraEvents._fireEvent(HydraEvents.FULLSCREEN, {
1873 fullscreen: true
1874 });
1875 Render.start(checkFullscreen, 10)
1876 }
1877 };
1878 this.closeFullscreen = function() {
1879 if (_this.system.fullscreen) document[prefix.lowercase + "CancelFullScreen"]();
1880 Render.stop(checkFullscreen)
1881 };
1882 this.getFullscreen = function() {
1883 if (_this.browser.firefox) return document.mozFullScreen;
1884 return document[prefix.lowercase + "IsFullScreen"]
1885 }
1886}, "Static");
1887Class(function DynamicObject(_properties) {
1888 var prototype = DynamicObject.prototype;
1889 if (_properties) {
1890 for (var key in _properties) {
1891 this[key] = _properties[key]
1892 }
1893 }
1894 this._tweens = {};
1895 if (typeof prototype.tween !== "undefined") return;
1896 prototype.tween = function(properties, time, ease, delay, update, complete) {
1897 if (typeof delay !== "number") {
1898 complete = update;
1899 update = delay;
1900 delay = 0
1901 }
1902 if (!this.multiTween) this.stopTween();
1903 if (typeof complete !== "function") complete = null;
1904 if (typeof update !== "function") update = null;
1905 this._tween = TweenManager.tween(this, properties, time, ease, delay, complete, update);
1906 return this._tween
1907 };
1908 prototype.stopTween = function(tween) {
1909 var _tween = tween || this._tween;
1910 if (_tween && _tween.stop) _tween.stop()
1911 };
1912 prototype.pause = function() {
1913 var _tween = this._tween;
1914 if (_tween && _tween.pause) _tween.pause()
1915 };
1916 prototype.resume = function() {
1917 var _tween = this._tween;
1918 if (_tween && _tween.resume) _tween.resume()
1919 };
1920 prototype.copy = function(pool) {
1921 var c = pool && pool.get ? pool.get() : new DynamicObject;
1922 for (var key in this) {
1923 if (typeof this[key] === "number") c[key] = this[key]
1924 }
1925 return c
1926 };
1927 prototype.copyFrom = function(obj) {
1928 for (var key in obj) {
1929 if (typeof obj[key] == "number") this[key] = obj[key]
1930 }
1931 };
1932 prototype.copyTo = function(obj) {
1933 for (var key in obj) {
1934 if (typeof this[key] == "number") obj[key] = this[key]
1935 }
1936 };
1937 prototype.clear = function() {
1938 for (var key in this) {
1939 if (typeof this[key] !== "function") delete this[key]
1940 }
1941 return this
1942 }
1943});
1944Class(function ObjectPool(_type, _number) {
1945 var _this = this;
1946 var _pool = [];
1947 (function() {
1948 if (_type) {
1949 _number = _number || 10;
1950 _type = _type || Object;
1951 for (var i = 0; i < _number; i++) {
1952 _pool.push(new _type)
1953 }
1954 }
1955 }());
1956 this.get = function() {
1957 return _pool.shift() || (_type ? new _type : null)
1958 };
1959 this.empty = function() {
1960 _pool.length = 0
1961 };
1962 this.put = function(obj) {
1963 if (obj) _pool.push(obj)
1964 };
1965 this.insert = function(array) {
1966 if (typeof array.push === "undefined") array = [array];
1967 for (var i = 0; i < array.length; i++) {
1968 _pool.push(array[i])
1969 }
1970 };
1971 this.length = function() {
1972 return _pool.length
1973 };
1974 this.destroy = function() {
1975 for (var i = 0; i < _pool.length; i++) {
1976 if (_pool[i].destroy) _pool[i].destroy()
1977 }
1978 _pool = null
1979 }
1980});
1981Class(function LinkedList() {
1982 var prototype = LinkedList.prototype;
1983 this.length = 0;
1984 this.first = null;
1985 this.last = null;
1986 this.current = null;
1987 this.prev = null;
1988 if (typeof prototype.push !== "undefined") return;
1989 prototype.push = function(obj) {
1990 if (!this.first) {
1991 this.first = obj;
1992 this.last = obj;
1993 obj.__prev = obj;
1994 obj.__next = obj
1995 } else {
1996 obj.__next = this.first;
1997 obj.__prev = this.last;
1998 this.last.__next = obj;
1999 this.last = obj
2000 }
2001 this.length++
2002 };
2003 prototype.remove = function(obj) {
2004 if (!obj || !obj.__next) return;
2005 if (this.length <= 1) {
2006 this.empty()
2007 } else {
2008 if (obj == this.first) {
2009 this.first = obj.__next;
2010 this.last.__next = this.first;
2011 this.first.__prev = this.last
2012 } else if (obj == this.last) {
2013 this.last = obj.__prev;
2014 this.last.__next = this.first;
2015 this.first.__prev = this.last
2016 } else {
2017 obj.__prev.__next = obj.__next;
2018 obj.__next.__prev = obj.__prev
2019 }
2020 this.length--
2021 }
2022 obj.__prev = null;
2023 obj.__next = null
2024 };
2025 prototype.empty = function() {
2026 this.first = null;
2027 this.last = null;
2028 this.current = null;
2029 this.prev = null;
2030 this.length = 0
2031 };
2032 prototype.start = function() {
2033 this.current = this.first;
2034 this.prev = this.current;
2035 return this.current
2036 };
2037 prototype.next = function() {
2038 if (!this.current) return;
2039 this.current = this.current.__next;
2040 if (this.length == 1 || this.prev.__next == this.first) return;
2041 this.prev = this.current;
2042 return this.current
2043 };
2044 prototype.destroy = function() {
2045 Utils.nullObject(this);
2046 return null
2047 }
2048});
2049Class(function Mouse() {
2050 var _this = this;
2051 var _capturing;
2052 this.x = 0;
2053 this.y = 0;
2054 this.lastX = 0;
2055 this.lastY = 0;
2056 this.moveX = 0;
2057 this.moveY = 0;
2058 this.autoPreventClicks = false;
2059
2060 function moved(e) {
2061 _this.lastX = _this.x;
2062 _this.lastY = _this.y;
2063 _this.ready = true;
2064 if (e.windowsPointer) {
2065 _this.x = e.x;
2066 _this.y = e.y
2067 } else {
2068 var convert = Utils.touchEvent(e);
2069 _this.x = convert.x;
2070 _this.y = convert.y
2071 }
2072 _this.moveX = _this.x - _this.lastX;
2073 _this.moveY = _this.y - _this.lastY;
2074 defer(resetMove)
2075 }
2076 this.capture = function(x, y) {
2077 if (_capturing) return false;
2078 _capturing = true;
2079 _this.x = x || 0;
2080 _this.y = y || 0;
2081 if (!Device.mobile) {
2082 __window.bind("mousemove", moved)
2083 } else {
2084 __window.bind("touchmove", moved);
2085 __window.bind("touchstart", moved)
2086 }
2087 };
2088 this.stop = function() {
2089 if (!_capturing) return false;
2090 _capturing = false;
2091 _this.x = 0;
2092 _this.y = 0;
2093 if (!Device.mobile) {
2094 __window.unbind("mousemove", moved)
2095 } else {
2096 __window.unbind("touchmove", moved);
2097 __window.unbind("touchstart", moved)
2098 }
2099 };
2100 this.preventClicks = function() {
2101 _this._preventClicks = true;
2102 Timer.create(function() {
2103 _this._preventClicks = false
2104 }, 300)
2105 };
2106 this.preventFireAfterClick = function() {
2107 _this._preventFire = true
2108 };
2109
2110 function resetMove() {
2111 _this.moveX = 0;
2112 _this.moveY = 0
2113 }
2114}, "Static");
2115Class(function Timer() {
2116 var _this = this;
2117 var _clearTimeout, _created;
2118 var _callbacks = [];
2119 var _completed = [];
2120 var _pool = new ObjectPool(Object, 100);
2121
2122 function loop(t, tsl, delta) {
2123 var len = _completed.length;
2124 for (var i = 0; i < len; i++) {
2125 var obj = _completed[i];
2126 obj.callback = null;
2127 _callbacks.findAndRemove(obj);
2128 _pool.put(obj)
2129 }
2130 if (len > 0) _completed.length = 0;
2131 if (delta > 70) return;
2132 len = _callbacks.length;
2133 for (var i = 0; i < len; i++) {
2134 var obj = _callbacks[i];
2135 if (!obj) continue;
2136 if (obj.frames) {
2137 ++obj.current;
2138 if (obj.current >= obj.frames) {
2139 obj.callback();
2140 _completed.push(obj)
2141 }
2142 }
2143 if (obj.time) {
2144 obj.current += delta;
2145 if (obj.current >= obj.time) {
2146 obj.callback();
2147 _completed.push(obj)
2148 }
2149 }
2150 }
2151 }
2152
2153 function find(ref) {
2154 for (var i = _callbacks.length - 1; i > -1; i--) {
2155 var c = _callbacks[i];
2156 if (c.ref == ref) return c
2157 }
2158 }
2159
2160 function create() {
2161 _created = true;
2162 Render.start(loop)
2163 }
2164 _clearTimeout = window.clearTimeout;
2165 window.clearTimeout = function(ref) {
2166 var c = find(ref);
2167 if (c) {
2168 _callbacks.findAndRemove(c)
2169 } else {
2170 _clearTimeout(ref)
2171 }
2172 };
2173 this.create = function(callback, time) {
2174 if (!_created) create();
2175 if (window._NODE_) return setTimeout(callback, time);
2176 if (time <= 0) return callback();
2177 var obj = _pool.get();
2178 obj.time = time;
2179 obj.current = 0;
2180 obj.ref = Utils.timestamp();
2181 obj.callback = callback;
2182 _callbacks.push(obj);
2183 return obj.ref
2184 };
2185 this.waitFrames = function(callback, frames) {
2186 var obj = _pool.get();
2187 obj.frames = frames;
2188 obj.current = 0;
2189 obj.callback = callback;
2190 _callbacks.push(obj)
2191 }
2192}, "static");
2193Class(function Render() {
2194 var _this = this;
2195 var _timer, _last, _timerName;
2196 var _render = [];
2197 var _time = Date.now();
2198 var _timeSinceRender = 0;
2199 this.TIME = Date.now();
2200 this.TARGET_FPS = 60;
2201 (function() {
2202 if (!THREAD) {
2203 requestAnimationFrame(render);
2204 Hydra.ready(addListeners)
2205 }
2206 }());
2207
2208 function render() {
2209 var t = Date.now();
2210 var timeSinceLoad = t - _time;
2211 var diff = 0;
2212 var fps = 60;
2213 if (_last) {
2214 diff = t - _last;
2215 fps = 1e3 / diff
2216 }
2217 _last = t;
2218 _this.FPS = fps;
2219 _this.TIME = t;
2220 _this.DELTA = diff;
2221 _this.TSL = timeSinceLoad;
2222 for (var i = _render.length - 1; i > -1; i--) {
2223 var callback = _render[i];
2224 if (!callback) continue;
2225 if (callback.fps) {
2226 _timeSinceRender += diff > 200 ? 0 : diff;
2227 if (_timeSinceRender < 1e3 / callback.fps) continue;
2228 _timeSinceRender -= 1e3 / callback.fps
2229 }
2230 callback(t, timeSinceLoad, diff, fps, callback.frameCount++)
2231 }
2232 if (!THREAD) requestAnimationFrame(render)
2233 }
2234
2235 function addListeners() {
2236 HydraEvents._addEvent(HydraEvents.BROWSER_FOCUS, focus, _this)
2237 }
2238
2239 function focus(e) {
2240 if (e.type == "focus") {
2241 _last = Date.now()
2242 }
2243 }
2244 this.startRender = this.start = function(callback, fps) {
2245 var allowed = true;
2246 var count = _render.length - 1;
2247 if (this.TARGET_FPS < 60) fps = this.TARGET_FPS;
2248 if (typeof fps == "number") callback.fps = fps;
2249 callback.frameCount = 0;
2250 if (_render.indexOf(callback) == -1) _render.push(callback)
2251 };
2252 this.stopRender = this.stop = function(callback) {
2253 var i = _render.indexOf(callback);
2254 if (i > -1) _render.splice(i, 1)
2255 };
2256 this.startTimer = function(name) {
2257 _timerName = name || "Timer";
2258 if (console.time && !window._NODE_) console.time(_timerName);
2259 else _timer = Date.now()
2260 };
2261 this.stopTimer = function() {
2262 if (console.time && !window._NODE_) console.timeEnd(_timerName);
2263 else console.log("Render " + _timerName + ": " + (Date.now() - _timer))
2264 };
2265 this.nextFrame = function(callback) {
2266 Timer.create(callback, 2)
2267 };
2268 this.tick = function() {
2269 render()
2270 };
2271 this.onIdle = function(callback, max) {
2272 if (window.requestIdleCallback) {
2273 if (max) max = {
2274 timeout: max
2275 };
2276 return window.requestIdleCallback(callback, max)
2277 } else {
2278 var start = _this.TIME;
2279 return defer(function() {
2280 callback({
2281 didTimeout: false,
2282 timeRemaining: function() {
2283 return Math.max(0, 50 - (_this.TIME - start))
2284 }
2285 })
2286 })
2287 }
2288 };
2289 window.defer = this.nextFrame;
2290 window.onIdle = this.onIdle
2291}, "Static");
2292Class(function HydraEvents() {
2293 var _events = [];
2294 var _e = {};
2295 this.BROWSER_FOCUS = "hydra_focus";
2296 this.HASH_UPDATE = "hydra_hash_update";
2297 this.COMPLETE = "hydra_complete";
2298 this.PROGRESS = "hydra_progress";
2299 this.UPDATE = "hydra_update";
2300 this.LOADED = "hydra_loaded";
2301 this.END = "hydra_end";
2302 this.FAIL = "hydra_fail";
2303 this.SELECT = "hydra_select";
2304 this.ERROR = "hydra_error";
2305 this.READY = "hydra_ready";
2306 this.RESIZE = "hydra_resize";
2307 this.CLICK = "hydra_click";
2308 this.HOVER = "hydra_hover";
2309 this.MESSAGE = "hydra_message";
2310 this.ORIENTATION = "orientation";
2311 this.BACKGROUND = "background";
2312 this.BACK = "hydra_back";
2313 this.PREVIOUS = "hydra_previous";
2314 this.NEXT = "hydra_next";
2315 this.RELOAD = "hydra_reload";
2316 this.FULLSCREEN = "hydra_fullscreen";
2317 this._checkDefinition = function(evt) {
2318 if (typeof evt == "undefined") {
2319 throw "Undefined event"
2320 }
2321 };
2322 this._addEvent = function(e, callback, object) {
2323 if (this._checkDefinition) this._checkDefinition(e);
2324 var add = new Object;
2325 add.evt = e;
2326 add.object = object;
2327 add.callback = callback;
2328 _events.push(add)
2329 };
2330 this._removeEvent = function(eventString, callback) {
2331 if (this._checkDefinition) this._checkDefinition(eventString);
2332 defer(function() {
2333 for (var i = _events.length - 1; i > -1; i--) {
2334 if (_events[i].evt == eventString && _events[i].callback == callback) {
2335 _events[i] = null;
2336 _events.splice(i, 1)
2337 }
2338 }
2339 })
2340 };
2341 this._destroyEvents = function(object) {
2342 for (var i = _events.length - 1; i > -1; i--) {
2343 if (_events[i].object == object) {
2344 _events[i] = null;
2345 _events.splice(i, 1)
2346 }
2347 }
2348 };
2349 this._fireEvent = function(eventString, obj) {
2350 if (this._checkDefinition) this._checkDefinition(eventString);
2351 var fire = true;
2352 obj = obj || _e;
2353 obj.cancel = function() {
2354 fire = false
2355 };
2356 for (var i = 0; i < _events.length; i++) {
2357 if (_events[i].evt == eventString) {
2358 if (fire) _events[i].callback(obj);
2359 else return false
2360 }
2361 }
2362 };
2363 this._consoleEvents = function() {
2364 console.log(_events)
2365 };
2366 this.createLocalEmitter = function(child) {
2367 var events = new HydraEvents;
2368 child.on = events._addEvent;
2369 child.off = events._removeEvent;
2370 child.fire = events._fireEvent
2371 }
2372}, "Static");
2373Class(function Events(_this) {
2374 this.events = {};
2375 var _events = {};
2376 var _e = {};
2377 this.events.subscribe = function(evt, callback) {
2378 HydraEvents._addEvent(evt, !!callback.resolve ? callback.resolve : callback, _this);
2379 return callback
2380 };
2381 this.events.unsubscribe = function(evt, callback) {
2382 HydraEvents._removeEvent(evt, !!callback.resolve ? callback.resolve : callback)
2383 };
2384 this.events.fire = function(evt, obj, skip) {
2385 obj = obj || _e;
2386 HydraEvents._checkDefinition(evt);
2387 if (_events[evt]) {
2388 obj.target = obj.target || _this;
2389 _events[evt](obj);
2390 obj.target = null
2391 } else {
2392 if (!skip) HydraEvents._fireEvent(evt, obj)
2393 }
2394 };
2395 this.events.add = function(evt, callback) {
2396 HydraEvents._checkDefinition(evt);
2397 _events[evt] = !!callback.resolve ? callback.resolve : callback;
2398 return callback
2399 };
2400 this.events.remove = function(evt) {
2401 HydraEvents._checkDefinition(evt);
2402 if (_events[evt]) delete _events[evt]
2403 };
2404 this.events.bubble = function(object, evt) {
2405 HydraEvents._checkDefinition(evt);
2406 var _this = this;
2407 object.events.add(evt, function(e) {
2408 _this.fire(evt, e)
2409 })
2410 };
2411 this.events.scope = function(ref) {
2412 _this = ref
2413 };
2414 this.events.destroy = function() {
2415 HydraEvents._destroyEvents(_this);
2416 _events = null;
2417 _this = null;
2418 return null
2419 }
2420});
2421Class(function Dispatch() {
2422 var _this = this;
2423 var _callbacks = {};
2424 var _instances = {};
2425
2426 function empty() {}
2427 this.register = function(object, method) {
2428 defer(function() {
2429 _callbacks[Hydra.getClassName(object) + "-" + method] = object[method]
2430 })
2431 };
2432 this.instance = function(object) {
2433 _instances[Hydra.getClassName(object)] = object
2434 };
2435 this.find = function(object, method, args) {
2436 let name = object.toString().match(/function ([^\(]+)/)[1];
2437 if (!method) return _instances[name] || console.error(`No instance ${name} found`);
2438 let path = name + "-" + method;
2439 if (_callbacks[path]) {
2440 return _callbacks[path]
2441 } else {
2442 delete _callbacks[path];
2443 return empty
2444 }
2445 }
2446}, "static");
2447Class(function Mobile() {
2448 Inherit(this, Component);
2449 var _this = this;
2450 var _lastTime;
2451 var _cancelScroll = true;
2452 var _scrollTarget = {};
2453 var _orientationPrevent, _type, _lastWidth;
2454 this.sleepTime = 1e4;
2455 this.scrollTop = 0;
2456 this.autoResizeReload = true;
2457 this.disableScrollManagement = false;
2458 Mobile.ScreenLock;
2459 if (Device.mobile) {
2460 for (var b in Device.browser) {
2461 Device.browser[b] = false
2462 }
2463 setInterval(checkTime, 250);
2464 this.phone = Device.mobile.phone;
2465 this.tablet = Device.mobile.tablet;
2466 this.orientation = window.innerWidth > window.innerHeight ? "landscape" : "portrait";
2467 this.os = function() {
2468 if (Device.detect("windows", "iemobile")) return "Windows";
2469 if (Device.detect(["ipad", "iphone"])) return "iOS";
2470 if (Device.detect(["android", "kindle"])) return "Android";
2471 if (Device.detect("blackberry")) return "Blackberry";
2472 return "Unknown"
2473 }();
2474 this.version = function() {
2475 try {
2476 if (_this.os == "iOS") {
2477 var num = Device.agent.split("os ")[1].split("_");
2478 var main = num[0];
2479 var sub = num[1].split(" ")[0];
2480 return Number(main + "." + sub)
2481 }
2482 if (_this.os == "Android") {
2483 var version = Device.agent.split("android ")[1].split(";")[0];
2484 if (version.length > 3) version = version.slice(0, -2);
2485 if (version.charAt(version.length - 1) == ".") version = version.slice(0, -1);
2486 return Number(version)
2487 }
2488 if (_this.os == "Windows") {
2489 if (Device.agent.strpos("rv:11")) return 11;
2490 return Number(Device.agent.split("windows phone ")[1].split(";")[0])
2491 }
2492 } catch (e) {}
2493 return -1
2494 }();
2495 this.browser = function() {
2496 if (_this.os == "iOS") {
2497 if (Device.detect(["twitter", "fbios"])) return "Social";
2498 if (Device.detect("crios")) return "Chrome";
2499 if (Device.detect("safari")) return "Safari";
2500 return "Unknown"
2501 }
2502 if (_this.os == "Android") {
2503 if (Device.detect(["twitter", "fb", "facebook"])) return "Social";
2504 if (Device.detect("chrome")) return "Chrome";
2505 if (Device.detect("firefox")) return "Firefox";
2506 return "Browser"
2507 }
2508 if (_this.os == "Windows") return "IE";
2509 return "Unknown"
2510 }();
2511 if (this.os == "Android" && this.browser == "Chrome") {
2512 this.browserVersion = Number(Device.agent.split("chrome/")[1].split(".")[0])
2513 }
2514 Hydra.ready(function() {
2515 window.addEventListener("orientationchange", orientationChange);
2516 window.onresize = resizeHandler;
2517 if (_this.browser == "Safari" && (!_this.NativeCore || !_this.NativeCore.active)) {
2518 document.body.scrollTop = 0;
2519 __body.css({
2520 height: "101%"
2521 })
2522 }
2523 setHeight();
2524 _this.orientation = Stage.width > Stage.height ? "landscape" : "portrait";
2525 if (!(_this.NativeCore && _this.NativeCore.active)) {
2526 window.addEventListener("touchstart", touchStart)
2527 } else {
2528 Stage.css({
2529 overflow: "hidden"
2530 })
2531 }
2532 determineType();
2533 _type = _this.phone ? "phone" : "tablet";
2534 _lastWidth = Stage.width
2535 });
2536
2537 function determineType() {
2538 Device.mobile.tablet = function() {
2539 if (Stage.width > Stage.height) return document.body.clientWidth > 1e3;
2540 else return document.body.clientHeight > 1e3
2541 }();
2542 Device.mobile.phone = !Device.mobile.tablet;
2543 _this.phone = Device.mobile.phone;
2544 _this.tablet = Device.mobile.tablet
2545 }
2546
2547 function setHeight() {
2548 Stage.width = document.body.clientWidth;
2549 Stage.height = document.body.clientHeight;
2550 if (Hydra.__offset) {
2551 Stage.width -= Hydra.__offset.x;
2552 Stage.height -= Hydra.__offset.y;
2553 Stage.css({
2554 width: Stage.width,
2555 height: Stage.height
2556 })
2557 }
2558 if (_this.browser == "Social" && _this.os == "iOS") {
2559 Stage.width = window.innerWidth;
2560 Stage.height = window.innerHeight
2561 }
2562 }
2563
2564 function resizeHandler() {
2565 clearTimeout(_this.fireResize);
2566 if (!_this.allowScroll) document.body.scrollTop = 0;
2567 _this.fireResize = _this.delayedCall(function() {
2568 setHeight();
2569 determineType();
2570 var type = _this.phone ? "phone" : "tablet";
2571 if ((_this.os == "iOS" || _this.os == "Android" && _this.version >= 7) && type != _type && _lastWidth != Stage.width && _this.autoResizeReload) window.location.reload();
2572 _this.orientation = window.innerWidth > window.innerHeight ? "landscape" : "portrait";
2573 _this.events.fire(HydraEvents.RESIZE);
2574 _lastWidth = Stage.width
2575 }, 32)
2576 }
2577
2578 function orientationChange() {
2579 _this.events.fire(HydraEvents.ORIENTATION)
2580 }
2581
2582 function touchStart(e) {
2583 if (_this.disableScrollManagemenet) return;
2584 var touch = Utils.touchEvent(e);
2585 var target = e.target;
2586 var inputElement = target.nodeName == "INPUT" || target.nodeName == "TEXTAREA" || target.nodeName == "SELECT" || target.nodeName == "A";
2587 if (inputElement) return;
2588 if (_cancelScroll) return e.preventDefault();
2589 var prevent = true;
2590 target = e.target;
2591 while (target.parentNode) {
2592 if (target._scrollParent) {
2593 prevent = false;
2594 _scrollTarget.target = target;
2595 _scrollTarget.y = touch.y;
2596 target.hydraObject.__preventY = touch.y
2597 }
2598 target = target.parentNode
2599 }
2600 if (prevent) e.preventDefault()
2601 }
2602 }
2603
2604 function checkTime() {
2605 var time = Date.now();
2606 if (_lastTime) {
2607 if (time - _lastTime > _this.sleepTime) {
2608 _this.events.fire(HydraEvents.BACKGROUND)
2609 }
2610 }
2611 _lastTime = time
2612 }
2613 this.Class = window.Class;
2614 this.fullscreen = function() {
2615 if (_this.NativeCore && _this.NativeCore.active) return;
2616 if (_this.os == "Android") {
2617 __window.bind("touchstart", function() {
2618 Device.openFullscreen()
2619 });
2620 if (_this.orientationSet) _this.events.fire(HydraEvents.RESIZE);
2621 return true
2622 }
2623 return false
2624 };
2625 this.overflowScroll = function($object, dir) {
2626 if (!Device.mobile) return false;
2627 var x = !!dir.x;
2628 var y = !!dir.y;
2629 var overflow = {
2630 "-webkit-overflow-scrolling": "touch"
2631 };
2632 if (!x && !y || x && y) overflow.overflow = "scroll";
2633 if (!x && y) {
2634 overflow.overflowY = "scroll";
2635 overflow.overflowX = "hidden"
2636 }
2637 if (x && !y) {
2638 overflow.overflowX = "scroll";
2639 overflow.overflowY = "hidden"
2640 }
2641 $object.css(overflow);
2642 $object.div._scrollParent = true;
2643 _cancelScroll = false;
2644 $object.div._preventEvent = function(e) {
2645 if ($object.maxScroll) {
2646 var touch = Utils.touchEvent(e);
2647 var delta = touch.y - $object.__preventY < 0 ? 1 : -1;
2648 if ($object.div.scrollTop < 2) {
2649 if (delta == -1) e.preventDefault();
2650 else e.stopPropagation()
2651 } else if ($object.div.scrollTop > $object.maxScroll - 2) {
2652 if (delta == 1) e.preventDefault();
2653 else e.stopPropagation()
2654 }
2655 } else {
2656 e.stopPropagation()
2657 }
2658 };
2659 if (!_this.isNative()) $object.div.addEventListener("touchmove", $object.div._preventEvent)
2660 };
2661 this.removeOverflowScroll = function($object) {
2662 $object.css({
2663 overflow: "hidden",
2664 overflowX: "",
2665 overflowY: "",
2666 "-webkit-overflow-scrolling": ""
2667 });
2668 $object.div.removeEventListener("touchmove", $object.div._preventEvent)
2669 };
2670 this.setOrientation = function(type) {
2671 if (_this.System && _this.NativeCore.active) {
2672 _this.System.orientation = _this.System[type.toUpperCase()];
2673 return
2674 }
2675 if (Device.mobile) {
2676 _this.ScreenLock.lock(type)
2677 }
2678 _this.orientationSet = type
2679 };
2680 this.vibrate = function(time) {
2681 navigator.vibrate && navigator.vibrate(time)
2682 };
2683 this.isNative = function() {
2684 return _this.NativeCore && _this.NativeCore.active
2685 }
2686}, "Static");
2687Class(function Modules() {
2688 var _this = this;
2689 var _modules = {};
2690 (function() {
2691 defer(exec)
2692 }());
2693
2694 function exec() {
2695 for (var m in _modules) {
2696 for (var key in _modules[m]) {
2697 var module = _modules[m][key];
2698 if (module._ready) continue;
2699 module._ready = true;
2700 if (module.exec) module.exec()
2701 }
2702 }
2703 }
2704
2705 function requireModule(root, path) {
2706 var module = _modules[root][path];
2707 if (!module._ready) {
2708 module._ready = true;
2709 if (module.exec) module.exec()
2710 }
2711 return module
2712 }
2713 this.push = function(module) {};
2714 this.Module = function(module) {
2715 var m = new module;
2716 var name = module.toString().slice(0, 100).match(/function ([^\(]+)/);
2717 if (name) {
2718 m._ready = true;
2719 name = name[1];
2720 _modules[name] = {
2721 index: m
2722 }
2723 } else {
2724 if (!_modules[m.module]) _modules[m.module] = {};
2725 _modules[m.module][m.path] = m
2726 }
2727 };
2728 this.require = function(path) {
2729 var root;
2730 if (!path.strpos("/")) {
2731 root = path;
2732 path = "index"
2733 } else {
2734 root = path.split("/")[0];
2735 path = path.replace(root + "/", "")
2736 }
2737 return requireModule(root, path).exports
2738 };
2739 window.Module = this.Module;
2740 if (!window._NODE_) {
2741 window.requireNative = window.require;
2742 window.require = this.require
2743 }
2744}, "Static");
2745Class(function Color(_value) {
2746 Inherit(this, Component);
2747 var _this = this;
2748 var _hsl, _array;
2749 this.r = 1;
2750 this.g = 1;
2751 this.b = 1;
2752 (function() {
2753 set(_value)
2754 }());
2755
2756 function set(value) {
2757 if (value instanceof Color) {
2758 copy(value)
2759 } else if (typeof value === "number") {
2760 setHex(value)
2761 } else if (Array.isArray(value)) {
2762 setRGB(value)
2763 } else {
2764 setHex(Number("0x" + value.slice(1)))
2765 }
2766 }
2767
2768 function copy(color) {
2769 _this.r = color.r;
2770 _this.g = color.g;
2771 _this.b = color.b
2772 }
2773
2774 function setHex(hex) {
2775 hex = Math.floor(hex);
2776 _this.r = (hex >> 16 & 255) / 255;
2777 _this.g = (hex >> 8 & 255) / 255;
2778 _this.b = (hex & 255) / 255
2779 }
2780
2781 function setRGB(values) {
2782 _this.r = values[0];
2783 _this.g = values[1];
2784 _this.b = values[2]
2785 }
2786
2787 function hue2rgb(p, q, t) {
2788 if (t < 0) t += 1;
2789 if (t > 1) t -= 1;
2790 if (t < 1 / 6) return p + (q - p) * 6 * t;
2791 if (t < 1 / 2) return q;
2792 if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
2793 return p
2794 }
2795 this.set = function(value) {
2796 set(value);
2797 return this
2798 };
2799 this.setRGB = function(r, g, b) {
2800 this.r = r;
2801 this.g = g;
2802 this.b = b;
2803 return this
2804 };
2805 this.setHSL = function(h, s, l) {
2806 if (s === 0) {
2807 this.r = this.g = this.b = l
2808 } else {
2809 var p = l <= .5 ? l * (1 + s) : l + s - l * s;
2810 var q = 2 * l - p;
2811 this.r = hue2rgb(q, p, h + 1 / 3);
2812 this.g = hue2rgb(q, p, h);
2813 this.b = hue2rgb(q, p, h - 1 / 3)
2814 }
2815 return this
2816 };
2817 this.offsetHSL = function(h, s, l) {
2818 var hsl = this.getHSL();
2819 hsl.h += h;
2820 hsl.s += s;
2821 hsl.l += l;
2822 this.setHSL(hsl.h, hsl.s, hsl.l);
2823 return this
2824 };
2825 this.getStyle = function() {
2826 return "rgb(" + (this.r * 255 | 0) + "," + (this.g * 255 | 0) + "," + (this.b * 255 | 0) + ")"
2827 };
2828 this.getHex = function() {
2829 return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0
2830 };
2831 this.getHexString = function() {
2832 return "#" + ("000000" + this.getHex().toString(16)).slice(-6)
2833 };
2834 this.getHSL = function() {
2835 _hsl = _hsl || {
2836 h: 0,
2837 s: 0,
2838 l: 0
2839 };
2840 var hsl = _hsl;
2841 var r = this.r,
2842 g = this.g,
2843 b = this.b;
2844 var max = Math.max(r, g, b);
2845 var min = Math.min(r, g, b);
2846 var hue, saturation;
2847 var lightness = (min + max) / 2;
2848 if (min === max) {
2849 hue = 0;
2850 saturation = 0
2851 } else {
2852 var delta = max - min;
2853 saturation = lightness <= .5 ? delta / (max + min) : delta / (2 - max - min);
2854 switch (max) {
2855 case r:
2856 hue = (g - b) / delta + (g < b ? 6 : 0);
2857 break;
2858 case g:
2859 hue = (b - r) / delta + 2;
2860 break;
2861 case b:
2862 hue = (r - g) / delta + 4;
2863 break
2864 }
2865 hue /= 6
2866 }
2867 hsl.h = hue;
2868 hsl.s = saturation;
2869 hsl.l = lightness;
2870 return hsl
2871 };
2872 this.add = function(color) {
2873 this.r += color.r;
2874 this.g += color.g;
2875 this.b += color.b
2876 };
2877 this.mix = function(color, percent) {
2878 this.r = this.r * (1 - percent) + color.r * percent;
2879 this.g = this.g * (1 - percent) + color.g * percent;
2880 this.b = this.b * (1 - percent) + color.b * percent
2881 };
2882 this.addScalar = function(s) {
2883 this.r += s;
2884 this.g += s;
2885 this.b += s
2886 };
2887 this.multiply = function(color) {
2888 this.r *= color.r;
2889 this.g *= color.g;
2890 this.b *= color.b
2891 };
2892 this.multiplyScalar = function(s) {
2893 this.r *= s;
2894 this.g *= s;
2895 this.b *= s
2896 };
2897 this.clone = function() {
2898 return new Color([this.r, this.g, this.b])
2899 };
2900 this.toArray = function() {
2901 if (!_array) _array = [];
2902 _array[0] = this.r;
2903 _array[1] = this.g;
2904 _array[2] = this.b;
2905 return _array
2906 }
2907});
2908Class(function Matrix2() {
2909 var _this = this;
2910 var prototype = Matrix2.prototype;
2911 var a11, a12, a13, a21, a22, a23, a31, a32, a33;
2912 var b11, b12, b13, b21, b22, b23, b31, b32, b33;
2913 this.type = "matrix2";
2914 this.data = new Float32Array(9);
2915 (function() {
2916 identity()
2917 }());
2918
2919 function identity(d) {
2920 d = d || _this.data;
2921 d[0] = 1, d[1] = 0, d[2] = 0;
2922 d[3] = 0, d[4] = 1, d[5] = 0;
2923 d[6] = 0, d[7] = 0, d[8] = 1
2924 }
2925
2926 function noE(n) {
2927 n = Math.abs(n) < .000001 ? 0 : n;
2928 return n
2929 }
2930 if (typeof prototype.identity !== "undefined") return;
2931 prototype.identity = function(d) {
2932 identity(d);
2933 return this
2934 };
2935 prototype.transformVector = function(v) {
2936 var d = this.data;
2937 var x = v.x;
2938 var y = v.y;
2939 v.x = d[0] * x + d[1] * y + d[2];
2940 v.y = d[3] * x + d[4] * y + d[5];
2941 return v
2942 };
2943 prototype.setTranslation = function(tx, ty, m) {
2944 var d = m || this.data;
2945 d[0] = 1, d[1] = 0, d[2] = tx;
2946 d[3] = 0, d[4] = 1, d[5] = ty;
2947 d[6] = 0, d[7] = 0, d[8] = 1;
2948 return this
2949 };
2950 prototype.getTranslation = function(v) {
2951 var d = this.data;
2952 v = v || new Vector2;
2953 v.x = d[2];
2954 v.y = d[5];
2955 return v
2956 };
2957 prototype.setScale = function(sx, sy, m) {
2958 var d = m || this.data;
2959 d[0] = sx, d[1] = 0, d[2] = 0;
2960 d[3] = 0, d[4] = sy, d[5] = 0;
2961 d[6] = 0, d[7] = 0, d[8] = 1;
2962 return this
2963 };
2964 prototype.setShear = function(sx, sy, m) {
2965 var d = m || this.data;
2966 d[0] = 1, d[1] = sx, d[2] = 0;
2967 d[3] = sy, d[4] = 1, d[5] = 0;
2968 d[6] = 0, d[7] = 0, d[8] = 1;
2969 return this
2970 };
2971 prototype.setRotation = function(a, m) {
2972 var d = m || this.data;
2973 var r0 = Math.cos(a);
2974 var r1 = Math.sin(a);
2975 d[0] = r0, d[1] = -r1, d[2] = 0;
2976 d[3] = r1, d[4] = r0, d[5] = 0;
2977 d[6] = 0, d[7] = 0, d[8] = 1;
2978 return this
2979 };
2980 prototype.setTRS = function(tx, ty, a, sx, sy) {
2981 var d = this.data;
2982 var r0 = Math.cos(a);
2983 var r1 = Math.sin(a);
2984 d[0] = r0 * sx, d[1] = -r1 * sy, d[2] = tx;
2985 d[3] = r1 * sx, d[4] = r0 * sy, d[5] = ty;
2986 d[6] = 0, d[7] = 0, d[8] = 1;
2987 return this
2988 };
2989 prototype.translate = function(tx, ty) {
2990 this.identity(Matrix2.__TEMP__);
2991 this.setTranslation(tx, ty, Matrix2.__TEMP__);
2992 return this.multiply(Matrix2.__TEMP__)
2993 };
2994 prototype.rotate = function(a) {
2995 this.identity(Matrix2.__TEMP__);
2996 this.setTranslation(a, Matrix2.__TEMP__);
2997 return this.multiply(Matrix2.__TEMP__)
2998 };
2999 prototype.scale = function(sx, sy) {
3000 this.identity(Matrix2.__TEMP__);
3001 this.setScale(sx, sy, Matrix2.__TEMP__);
3002 return this.multiply(Matrix2.__TEMP__)
3003 };
3004 prototype.shear = function(sx, sy) {
3005 this.identity(Matrix2.__TEMP__);
3006 this.setRotation(sx, sy, Matrix2.__TEMP__);
3007 return this.multiply(Matrix2.__TEMP__)
3008 };
3009 prototype.multiply = function(m) {
3010 var a = this.data;
3011 var b = m.data || m;
3012 a11 = a[0], a12 = a[1], a13 = a[2];
3013 a21 = a[3], a22 = a[4], a23 = a[5];
3014 a31 = a[6], a32 = a[7], a33 = a[8];
3015 b11 = b[0], b12 = b[1], b13 = b[2];
3016 b21 = b[3], b22 = b[4], b23 = b[5];
3017 b31 = b[6], b32 = b[7], b33 = b[8];
3018 a[0] = a11 * b11 + a12 * b21 + a13 * b31;
3019 a[1] = a11 * b12 + a12 * b22 + a13 * b32;
3020 a[2] = a11 * b13 + a12 * b23 + a13 * b33;
3021 a[3] = a21 * b11 + a22 * b21 + a23 * b31;
3022 a[4] = a21 * b12 + a22 * b22 + a23 * b32;
3023 a[5] = a21 * b13 + a22 * b23 + a23 * b33;
3024 return this
3025 };
3026 prototype.inverse = function(m) {
3027 m = m || this;
3028 var a = m.data;
3029 var b = this.data;
3030 a11 = a[0], a12 = a[1], a13 = a[2];
3031 a21 = a[3], a22 = a[4], a23 = a[5];
3032 a31 = a[6], a32 = a[7], a33 = a[8];
3033 var det = m.determinant();
3034 if (Math.abs(det) < 1e-7) {}
3035 var invdet = 1 / det;
3036 b[0] = (a22 * a33 - a32 * a23) * invdet;
3037 b[1] = (a13 * a32 - a12 * a33) * invdet;
3038 b[2] = (a12 * a23 - a13 * a22) * invdet;
3039 b[3] = (a23 * a31 - a21 * a33) * invdet;
3040 b[4] = (a11 * a33 - a13 * a31) * invdet;
3041 b[5] = (a21 * a13 - a11 * a23) * invdet;
3042 b[6] = (a21 * a32 - a31 * a22) * invdet;
3043 b[7] = (a31 * a12 - a11 * a32) * invdet;
3044 b[8] = (a11 * a22 - a21 * a12) * invdet;
3045 return m
3046 };
3047 prototype.determinant = function() {
3048 var a = this.data;
3049 a11 = a[0], a12 = a[1], a13 = a[2];
3050 a21 = a[3], a22 = a[4], a23 = a[5];
3051 a31 = a[6], a32 = a[7], a33 = a[8];
3052 return a11 * (a22 * a33 - a32 * a23) - a12 * (a21 * a33 - a23 * a31) + a13 * (a21 * a32 * a22 * a31)
3053 };
3054 prototype.copyTo = function(m) {
3055 var a = this.data;
3056 var b = m.data || m;
3057 b[0] = a[0], b[1] = a[1], b[2] = a[2];
3058 b[3] = a[3], b[4] = a[4], b[5] = a[5];
3059 b[6] = a[6], b[7] = a[7], b[8] = a[8];
3060 return m
3061 };
3062 prototype.copyFrom = function(m) {
3063 var a = this.data;
3064 var b = m.data || m;
3065 b[0] = a[0], b[1] = a[1], b[2] = a[2];
3066 b[3] = a[3], b[4] = a[4], b[5] = a[5];
3067 b[6] = a[6], b[7] = a[7], b[8] = a[8];
3068 return this
3069 };
3070 prototype.getCSS = function(force2D) {
3071 var d = this.data;
3072 if (Device.tween.css3d && !force2D) {
3073 return "matrix3d(" + noE(d[0]) + ", " + noE(d[3]) + ", 0, 0, " + noE(d[1]) + ", " + noE(d[4]) + ", 0, 0, 0, 0, 1, 0, " + noE(d[2]) + ", " + noE(d[5]) + ", 0, 1)"
3074 } else {
3075 return "matrix(" + noE(d[0]) + ", " + noE(d[3]) + ", " + noE(d[1]) + ", " + noE(d[4]) + ", " + noE(d[2]) + ", " + noE(d[5]) + ")"
3076 }
3077 }
3078}, function() {
3079 Matrix2.__TEMP__ = (new Matrix2).data
3080});
3081Class(function Matrix4() {
3082 var _this = this;
3083 var prototype = Matrix4.prototype;
3084 this.type = "matrix4";
3085 this.data = new Float32Array(16);
3086 (function() {
3087 identity()
3088 }());
3089
3090 function identity(m) {
3091 var d = m || _this.data;
3092 d[0] = 1, d[4] = 0, d[8] = 0, d[12] = 0;
3093 d[1] = 0, d[5] = 1, d[9] = 0, d[13] = 0;
3094 d[2] = 0, d[6] = 0, d[10] = 1, d[14] = 0;
3095 d[3] = 0, d[7] = 0, d[11] = 0, d[15] = 1
3096 }
3097
3098 function noE(n) {
3099 return Math.abs(n) < .000001 ? 0 : n
3100 }
3101 if (typeof prototype.identity !== "undefined") return;
3102 prototype.identity = function() {
3103 identity();
3104 return this
3105 };
3106 prototype.transformVector = function(v, pv) {
3107 var d = this.data;
3108 var x = v.x,
3109 y = v.y,
3110 z = v.z,
3111 w = v.w;
3112 pv = pv || v;
3113 pv.x = d[0] * x + d[4] * y + d[8] * z + d[12] * w;
3114 pv.y = d[1] * x + d[5] * y + d[9] * z + d[13] * w;
3115 pv.z = d[2] * x + d[6] * y + d[10] * z + d[14] * w;
3116 return pv
3117 };
3118 prototype.multiply = function(m, d) {
3119 var a = this.data;
3120 var b = m.data || m;
3121 var a00, a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, a11, a12, a13, a14, a15;
3122 var b00, b01, b02, b03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15;
3123 a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
3124 a04 = a[4], a05 = a[5], a06 = a[6], a07 = a[7];
3125 a08 = a[8], a09 = a[9], a10 = a[10], a11 = a[11];
3126 a12 = a[12], a13 = a[13], a14 = a[14], a15 = a[15];
3127 b00 = b[0], b01 = b[1], b02 = b[2], b03 = b[3];
3128 b04 = b[4], b05 = b[5], b06 = b[6], b07 = b[7];
3129 b08 = b[8], b09 = b[9], b10 = b[10], b11 = b[11];
3130 b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
3131 a[0] = a00 * b00 + a04 * b01 + a08 * b02 + a12 * b03;
3132 a[1] = a01 * b00 + a05 * b01 + a09 * b02 + a13 * b03;
3133 a[2] = a02 * b00 + a06 * b01 + a10 * b02 + a14 * b03;
3134 a[3] = a03 * b00 + a07 * b01 + a11 * b02 + a15 * b03;
3135 a[4] = a00 * b04 + a04 * b05 + a08 * b06 + a12 * b07;
3136 a[5] = a01 * b04 + a05 * b05 + a09 * b06 + a13 * b07;
3137 a[6] = a02 * b04 + a06 * b05 + a10 * b06 + a14 * b07;
3138 a[7] = a03 * b04 + a07 * b05 + a11 * b06 + a15 * b07;
3139 a[8] = a00 * b08 + a04 * b09 + a08 * b10 + a12 * b11;
3140 a[9] = a01 * b08 + a05 * b09 + a09 * b10 + a13 * b11;
3141 a[10] = a02 * b08 + a06 * b09 + a10 * b10 + a14 * b11;
3142 a[11] = a03 * b08 + a07 * b09 + a11 * b10 + a15 * b11;
3143 a[12] = a00 * b12 + a04 * b13 + a08 * b14 + a12 * b15;
3144 a[13] = a01 * b12 + a05 * b13 + a09 * b14 + a13 * b15;
3145 a[14] = a02 * b12 + a06 * b13 + a10 * b14 + a14 * b15;
3146 a[15] = a03 * b12 + a07 * b13 + a11 * b14 + a15 * b15;
3147 return this
3148 };
3149 prototype.setTRS = function(tx, ty, tz, rx, ry, rz, sx, sy, sz, m) {
3150 m = m || this;
3151 var d = m.data;
3152 identity(m);
3153 var six = Math.sin(rx);
3154 var cox = Math.cos(rx);
3155 var siy = Math.sin(ry);
3156 var coy = Math.cos(ry);
3157 var siz = Math.sin(rz);
3158 var coz = Math.cos(rz);
3159 d[0] = (coy * coz + siy * six * siz) * sx;
3160 d[1] = (-coy * siz + siy * six * coz) * sx;
3161 d[2] = siy * cox * sx;
3162 d[4] = siz * cox * sy;
3163 d[5] = coz * cox * sy;
3164 d[6] = -six * sy;
3165 d[8] = (-siy * coz + coy * six * siz) * sz;
3166 d[9] = (siz * siy + coy * six * coz) * sz;
3167 d[10] = coy * cox * sz;
3168 d[12] = tx;
3169 d[13] = ty;
3170 d[14] = tz;
3171 return m
3172 };
3173 prototype.setScale = function(sx, sy, sz, m) {
3174 m = m || this;
3175 var d = m.data || m;
3176 identity(m);
3177 d[0] = sx, d[5] = sy, d[10] = sz;
3178 return m
3179 };
3180 prototype.setTranslation = function(tx, ty, tz, m) {
3181 m = m || this;
3182 var d = m.data || m;
3183 identity(m);
3184 d[12] = tx, d[13] = ty, d[14] = tz;
3185 return m
3186 };
3187 prototype.setRotation = function(rx, ry, rz, m) {
3188 m = m || this;
3189 var d = m.data || m;
3190 identity(m);
3191 var sx = Math.sin(rx);
3192 var cx = Math.cos(rx);
3193 var sy = Math.sin(ry);
3194 var cy = Math.cos(ry);
3195 var sz = Math.sin(rz);
3196 var cz = Math.cos(rz);
3197 d[0] = cy * cz + sy * sx * sz;
3198 d[1] = -cy * sz + sy * sx * cz;
3199 d[2] = sy * cx;
3200 d[4] = sz * cx;
3201 d[5] = cz * cx;
3202 d[6] = -sx;
3203 d[8] = -sy * cz + cy * sx * sz;
3204 d[9] = sz * sy + cy * sx * cz;
3205 d[10] = cy * cx;
3206 return m
3207 };
3208 prototype.setLookAt = function(eye, center, up, m) {
3209 m = m || this;
3210 var d = m.data || m;
3211 var f = D3.m4v31;
3212 var s = D3.m4v32;
3213 var u = D3.m4v33;
3214 f.subVectors(center, eye).normalize();
3215 s.cross(f, up).normalize();
3216 u.cross(s, f);
3217 d[0] = s.x;
3218 d[1] = u.x;
3219 d[2] = -f.x;
3220 d[3] = 0;
3221 d[4] = s.y;
3222 d[5] = u.y;
3223 d[6] = -f.y;
3224 d[7] = 0;
3225 d[8] = s.z;
3226 d[9] = u.z;
3227 d[10] = -f.z;
3228 d[11] = 0;
3229 d[12] = 0;
3230 d[13] = 0;
3231 d[14] = 0;
3232 d[15] = 1;
3233 this.translate(-eye.x, -eye.y, -eye.z);
3234 return this
3235 };
3236 prototype.setPerspective = function(fovy, aspect, near, far, m) {
3237 var e, rd, s, ct;
3238 if (near === far || aspect === 0) {
3239 throw "null frustum"
3240 }
3241 if (near <= 0) {
3242 throw "near <= 0"
3243 }
3244 if (far <= 0) {
3245 throw "far <= 0"
3246 }
3247 fovy = Math.PI * fovy / 180 / 2;
3248 s = Math.sin(fovy);
3249 if (s === 0) {
3250 throw "null frustum"
3251 }
3252 rd = 1 / (far - near);
3253 ct = Math.cos(fovy) / s;
3254 e = m ? m.data || m : this.data;
3255 e[0] = ct / aspect;
3256 e[1] = 0;
3257 e[2] = 0;
3258 e[3] = 0;
3259 e[4] = 0;
3260 e[5] = ct;
3261 e[6] = 0;
3262 e[7] = 0;
3263 e[8] = 0;
3264 e[9] = 0;
3265 e[10] = -(far + near) * rd;
3266 e[11] = -1;
3267 e[12] = 0;
3268 e[13] = 0;
3269 e[14] = -2 * near * far * rd;
3270 e[15] = 0
3271 };
3272 prototype.setRotationFromQuaternion = function(q) {
3273 var d = this.data;
3274 var x = q.x,
3275 y = q.y,
3276 z = q.z,
3277 w = q.w;
3278 var x2 = x + x,
3279 y2 = y + y,
3280 z2 = z + z;
3281 var xx = x * x2,
3282 xy = x * y2,
3283 xz = x * z2;
3284 var yy = y * y2,
3285 yz = y * z2,
3286 zz = z * z2;
3287 var wx = w * x2,
3288 wy = w * y2,
3289 wz = w * z2;
3290 d[0] = 1 - (yy + zz);
3291 d[4] = xy - wz;
3292 d[8] = xz + wy;
3293 d[1] = xy + wz;
3294 d[5] = 1 - (xx + zz);
3295 d[9] = yz - wx;
3296 d[2] = xz - wy;
3297 d[6] = yz + wx;
3298 d[10] = 1 - (xx + yy);
3299 d[3] = 0;
3300 d[7] = 0;
3301 d[11] = 0;
3302 d[12] = 0;
3303 d[13] = 0;
3304 d[14] = 0;
3305 d[15] = 1;
3306 return this
3307 }, prototype.perspective = function(fov, aspect, near, far) {
3308 this.setPerspective(fov, aspect, near, far, Matrix4.__TEMP__);
3309 return this.multiply(Matrix4.__TEMP__)
3310 };
3311 prototype.lookAt = function(eye, center, up) {
3312 this.setLookAt(eye, center, up, Matrix4.__TEMP__);
3313 return this.multiply(Matrix4.__TEMP__)
3314 };
3315 prototype.translate = function(tx, ty, tz) {
3316 this.setTranslation(tx, ty, tz, Matrix4.__TEMP__);
3317 return this.multiply(Matrix4.__TEMP__)
3318 };
3319 prototype.rotate = function(rx, ry, rz) {
3320 this.setRotation(rx, ry, rz, Matrix4.__TEMP__);
3321 return this.multiply(Matrix4.__TEMP__)
3322 };
3323 prototype.scale = function(sx, sy, sz) {
3324 this.setScale(sx, sy, sz, Matrix4.__TEMP__);
3325 return this.multiply(Matrix4.__TEMP__)
3326 };
3327 prototype.copyTo = function(m) {
3328 var a = this.data;
3329 var b = m.data || m;
3330 for (var i = 0; i < 16; i++) b[i] = a[i]
3331 };
3332 prototype.copyFrom = function(m) {
3333 var a = this.data;
3334 var b = m.data || m;
3335 for (var i = 0; i < 16; i++) a[i] = b[i];
3336 return this
3337 };
3338 prototype.copyRotationTo = function(m) {
3339 var a = this.data;
3340 var b = m.data || m;
3341 b[0] = a[0];
3342 b[1] = a[1];
3343 b[2] = a[2];
3344 b[3] = a[4];
3345 b[4] = a[5];
3346 b[5] = a[6];
3347 b[6] = a[8];
3348 b[7] = a[9];
3349 b[8] = a[10];
3350 return m
3351 };
3352 prototype.copyPosition = function(m) {
3353 var to = this.data;
3354 var from = m.data || m;
3355 to[12] = from[12];
3356 to[13] = from[13];
3357 to[14] = from[14];
3358 return this
3359 };
3360 prototype.getCSS = function() {
3361 var d = this.data;
3362 return "matrix3d(" + noE(d[0]) + "," + noE(d[1]) + "," + noE(d[2]) + "," + noE(d[3]) + "," + noE(d[4]) + "," + noE(d[5]) + "," + noE(d[6]) + "," + noE(d[7]) + "," + noE(d[8]) + "," + noE(d[9]) + "," + noE(d[10]) + "," + noE(d[11]) + "," + noE(d[12]) + "," + noE(d[13]) + "," + noE(d[14]) + "," + noE(d[15]) + ")"
3363 };
3364 prototype.extractPosition = function(v) {
3365 v = v || new Vector3;
3366 var d = this.data;
3367 v.set(d[12], d[13], d[14]);
3368 return v
3369 };
3370 prototype.determinant = function() {
3371 var d = this.data;
3372 return d[0] * (d[5] * d[10] - d[9] * d[6]) + d[4] * (d[9] * d[2] - d[1] * d[10]) + d[8] * (d[1] * d[6] - d[5] * d[2])
3373 };
3374 prototype.inverse = function(m) {
3375 var d = this.data;
3376 var a = m ? m.data || m : this.data;
3377 var det = this.determinant();
3378 if (Math.abs(det) < .0001) {
3379 console.warn("Attempt to inverse a singular Matrix4. ", this.data);
3380 console.trace();
3381 return m
3382 }
3383 var d0 = d[0],
3384 d4 = d[4],
3385 d8 = d[8],
3386 d12 = d[12],
3387 d1 = d[1],
3388 d5 = d[5],
3389 d9 = d[9],
3390 d13 = d[13],
3391 d2 = d[2],
3392 d6 = d[6],
3393 d10 = d[10],
3394 d14 = d[14];
3395 det = 1 / det;
3396 a[0] = (d5 * d10 - d9 * d6) * det;
3397 a[1] = (d8 * d6 - d4 * d10) * det;
3398 a[2] = (d4 * d9 - d8 * d5) * det;
3399 a[4] = (d9 * d2 - d1 * d10) * det;
3400 a[5] = (d0 * d10 - d8 * d2) * det;
3401 a[6] = (d8 * d1 - d0 * d9) * det;
3402 a[8] = (d1 * d6 - d5 * d2) * det;
3403 a[9] = (d4 * d2 - d0 * d6) * det;
3404 a[10] = (d0 * d5 - d4 * d1) * det;
3405 a[12] = -(d12 * a[0] + d13 * a[4] + d14 * a[8]);
3406 a[13] = -(d12 * a[1] + d13 * a[5] + d14 * a[9]);
3407 a[14] = -(d12 * a[2] + d13 * a[6] + d14 * a[10]);
3408 return m
3409 };
3410 prototype.transpose = function(m) {
3411 var d = this.data;
3412 var a = m ? m.data || m : this.data;
3413 var d0 = d[0],
3414 d4 = d[4],
3415 d8 = d[8],
3416 d1 = d[1],
3417 d5 = d[5],
3418 d9 = d[9],
3419 d2 = d[2],
3420 d6 = d[6],
3421 d10 = d[10];
3422 a[0] = d0;
3423 a[1] = d4;
3424 a[2] = d8;
3425 a[4] = d1;
3426 a[5] = d5;
3427 a[6] = d9;
3428 a[8] = d2;
3429 a[9] = d6;
3430 a[10] = d10
3431 }
3432}, function() {
3433 Matrix4.__TEMP__ = (new Matrix4).data
3434});
3435Class(function Vector2(_x, _y) {
3436 var _this = this;
3437 var prototype = Vector2.prototype;
3438 this.x = typeof _x == "number" ? _x : 0;
3439 this.y = typeof _y == "number" ? _y : 0;
3440 this.type = "vector2";
3441 if (typeof prototype.set !== "undefined") return;
3442 prototype.set = function(x, y) {
3443 this.x = x;
3444 this.y = y;
3445 return this
3446 };
3447 prototype.clear = function() {
3448 this.x = 0;
3449 this.y = 0;
3450 return this
3451 };
3452 prototype.copyTo = function(v) {
3453 v.x = this.x;
3454 v.y = this.y;
3455 return this
3456 };
3457 prototype.copyFrom = prototype.copy = function(v) {
3458 this.x = v.x;
3459 this.y = v.y;
3460 return this
3461 };
3462 prototype.addVectors = function(a, b) {
3463 this.x = a.x + b.x;
3464 this.y = a.y + b.y;
3465 return this
3466 };
3467 prototype.subVectors = function(a, b) {
3468 this.x = a.x - b.x;
3469 this.y = a.y - b.y;
3470 return this
3471 };
3472 prototype.multiplyVectors = function(a, b) {
3473 this.x = a.x * b.x;
3474 this.y = a.y * b.y;
3475 return this
3476 };
3477 prototype.add = function(v) {
3478 this.x += v.x;
3479 this.y += v.y;
3480 return this
3481 };
3482 prototype.sub = function(v) {
3483 this.x -= v.x;
3484 this.y -= v.y;
3485 return this
3486 };
3487 prototype.multiply = function(v) {
3488 this.x *= v;
3489 this.y *= v;
3490 return this
3491 };
3492 prototype.divide = function(v) {
3493 this.x /= v;
3494 this.y /= v;
3495 return this
3496 };
3497 prototype.lengthSq = function() {
3498 return this.x * this.x + this.y * this.y || .00001
3499 };
3500 prototype.length = function() {
3501 return Math.sqrt(this.lengthSq())
3502 };
3503 prototype.setLength = function(length) {
3504 this.normalize().multiply(length);
3505 return this
3506 };
3507 prototype.normalize = function() {
3508 var length = this.length();
3509 this.x /= length;
3510 this.y /= length;
3511 return this
3512 };
3513 prototype.perpendicular = function(a, b) {
3514 var tx = this.x;
3515 var ty = this.y;
3516 this.x = -ty;
3517 this.y = tx;
3518 return this
3519 };
3520 prototype.lerp = function(v, alpha) {
3521 this.x += (v.x - this.x) * alpha;
3522 this.y += (v.y - this.y) * alpha;
3523 return this
3524 };
3525 prototype.interp = function(v, alpha, ease) {
3526 var a = 0;
3527 var f = TweenManager.Interpolation.convertEase(ease);
3528 var calc = Vector2.__TEMP__;
3529 calc.subVectors(this, v);
3530 var dist = Utils.clamp(Utils.range(calc.lengthSq(), 0, 5e3 * 5e3, 1, 0), 0, 1) * (alpha / 10);
3531 if (typeof f === "function") a = f(dist);
3532 else a = TweenManager.Interpolation.solve(f, dist);
3533 this.x += (v.x - this.x) * a;
3534 this.y += (v.y - this.y) * a
3535 };
3536 prototype.setAngleRadius = function(a, r) {
3537 this.x = Math.cos(a) * r;
3538 this.y = Math.sin(a) * r;
3539 return this
3540 };
3541 prototype.addAngleRadius = function(a, r) {
3542 this.x += Math.cos(a) * r;
3543 this.y += Math.sin(a) * r;
3544 return this
3545 };
3546 prototype.clone = function() {
3547 return new Vector2(this.x, this.y)
3548 };
3549 prototype.dot = function(a, b) {
3550 b = b || this;
3551 return a.x * b.x + a.y * b.y
3552 };
3553 prototype.distanceTo = function(v, noSq) {
3554 var dx = this.x - v.x;
3555 var dy = this.y - v.y;
3556 if (!noSq) return Math.sqrt(dx * dx + dy * dy);
3557 return dx * dx + dy * dy
3558 };
3559 prototype.solveAngle = function(a, b) {
3560 if (!b) b = this;
3561 return Math.atan2(a.y - b.y, a.x - b.x)
3562 };
3563 prototype.equals = function(v) {
3564 return this.x == v.x && this.y == v.y
3565 };
3566 prototype.console = function() {
3567 console.log(this.x, this.y)
3568 };
3569 prototype.toString = function(split) {
3570 split = split || " ";
3571 return this.x + split + this.y
3572 }
3573}, function() {
3574 Vector2.__TEMP__ = new Vector2;
3575 Vector2.__TEMP2__ = new Vector2
3576});
3577Class(function Vector3(_x, _y, _z, _w) {
3578 var _this = this;
3579 var prototype = Vector3.prototype;
3580 this.x = typeof _x === "number" ? _x : 0;
3581 this.y = typeof _y === "number" ? _y : 0;
3582 this.z = typeof _z === "number" ? _z : 0;
3583 this.w = typeof _w === "number" ? _w : 1;
3584 this.type = "vector3";
3585 if (typeof prototype.set !== "undefined") return;
3586 prototype.set = function(x, y, z, w) {
3587 this.x = x || 0;
3588 this.y = y || 0;
3589 this.z = z || 0;
3590 this.w = w || 1;
3591 return this
3592 };
3593 prototype.clear = function() {
3594 this.x = 0;
3595 this.y = 0;
3596 this.z = 0;
3597 this.w = 1;
3598 return this
3599 };
3600 prototype.copyTo = function(p) {
3601 p.x = this.x;
3602 p.y = this.y;
3603 p.z = this.z;
3604 p.w = this.w;
3605 return p
3606 };
3607 prototype.copyFrom = prototype.copy = function(p) {
3608 this.x = p.x || 0;
3609 this.y = p.y || 0;
3610 this.z = p.z || 0;
3611 this.w = p.w || 1;
3612 return this
3613 };
3614 prototype.lengthSq = function() {
3615 return this.x * this.x + this.y * this.y + this.z * this.z
3616 };
3617 prototype.length = function() {
3618 return Math.sqrt(this.lengthSq())
3619 };
3620 prototype.normalize = function() {
3621 var m = 1 / this.length();
3622 this.set(this.x * m, this.y * m, this.z * m);
3623 return this
3624 };
3625 prototype.setLength = function(length) {
3626 this.normalize().multiply(length);
3627 return this
3628 };
3629 prototype.addVectors = function(a, b) {
3630 this.x = a.x + b.x;
3631 this.y = a.y + b.y;
3632 this.z = a.z + b.z;
3633 return this
3634 };
3635 prototype.subVectors = function(a, b) {
3636 this.x = a.x - b.x;
3637 this.y = a.y - b.y;
3638 this.z = a.z - b.z;
3639 return this
3640 };
3641 prototype.multiplyVectors = function(a, b) {
3642 this.x = a.x * b.x;
3643 this.y = a.y * b.y;
3644 this.z = a.z * b.z;
3645 return this
3646 };
3647 prototype.add = function(v) {
3648 this.x += v.x;
3649 this.y += v.y;
3650 this.z += v.z;
3651 return this
3652 };
3653 prototype.sub = function(v) {
3654 this.x -= v.x;
3655 this.y -= v.y;
3656 this.z -= v.z;
3657 return this
3658 };
3659 prototype.multiply = function(v) {
3660 this.x *= v;
3661 this.y *= v;
3662 this.z *= v;
3663 return this
3664 };
3665 prototype.divide = function(v) {
3666 this.x /= v;
3667 this.y /= v;
3668 this.z /= v;
3669 return this
3670 };
3671 prototype.limit = function(max) {
3672 if (this.length() > max) {
3673 this.normalize();
3674 this.multiply(max)
3675 }
3676 };
3677 prototype.heading2D = function() {
3678 var angle = Math.atan2(-this.y, this.x);
3679 return -angle
3680 };
3681 prototype.lerp = function(v, alpha) {
3682 this.x += (v.x - this.x) * alpha;
3683 this.y += (v.y - this.y) * alpha;
3684 this.z += (v.z - this.z) * alpha;
3685 return this
3686 };
3687 prototype.deltaLerp = function(v, alpha, delta) {
3688 delta = delta || 1;
3689 for (var i = 0; i < delta; i++) {
3690 var f = alpha;
3691 this.x += (v.x - this.x) * alpha;
3692 this.y += (v.y - this.y) * alpha;
3693 this.z += (v.z - this.z) * alpha
3694 }
3695 return this
3696 };
3697 prototype.interp = function(v, alpha, ease, dist) {
3698 if (!Vector3.__TEMP__) Vector3.__TEMP__ = new Vector3;
3699 dist = dist || 5e3;
3700 var a = 0;
3701 var f = TweenManager.Interpolation.convertEase(ease);
3702 var calc = Vector3.__TEMP__;
3703 calc.subVectors(this, v);
3704 var dist = Utils.clamp(Utils.range(calc.lengthSq(), 0, dist * dist, 1, 0), 0, 1) * (alpha / 10);
3705 if (typeof f === "function") a = f(dist);
3706 else a = TweenManager.Interpolation.solve(f, dist);
3707 this.x += (v.x - this.x) * a;
3708 this.y += (v.y - this.y) * a;
3709 this.z += (v.z - this.z) * a
3710 };
3711 prototype.setAngleRadius = function(a, r) {
3712 this.x = Math.cos(a) * r;
3713 this.y = Math.sin(a) * r;
3714 this.z = Math.sin(a) * r;
3715 return this
3716 };
3717 prototype.addAngleRadius = function(a, r) {
3718 this.x += Math.cos(a) * r;
3719 this.y += Math.sin(a) * r;
3720 this.z += Math.sin(a) * r;
3721 return this
3722 };
3723 prototype.dot = function(a, b) {
3724 b = b || this;
3725 return a.x * b.x + a.y * b.y + a.z * b.z
3726 };
3727 prototype.clone = function() {
3728 return new Vector3(this.x, this.y, this.z)
3729 };
3730 prototype.cross = function(a, b) {
3731 if (!b) b = this;
3732 var x = a.y * b.z - a.z * b.y;
3733 var y = a.z * b.x - a.x * b.z;
3734 var z = a.x * b.y - a.y * b.x;
3735 this.set(x, y, z, this.w);
3736 return this
3737 };
3738 prototype.distanceTo = function(v, noSq) {
3739 var dx = this.x - v.x;
3740 var dy = this.y - v.y;
3741 var dz = this.z - v.z;
3742 if (!noSq) return Math.sqrt(dx * dx + dy * dy + dz * dz);
3743 return dx * dx + dy * dy + dz * dz
3744 };
3745 prototype.solveAngle = function(a, b) {
3746 if (!b) b = this;
3747 return Math.acos(a.dot(b) / (a.length() * b.length() || .00001))
3748 };
3749 prototype.solveAngle2D = function(a, b) {
3750 if (!b) b = this;
3751 Vector2.__TEMP__.copy(a);
3752 Vector2.__TEMP2__.copy(b);
3753 return Vector2.__TEMP__.solveAngle(Vector2.__TEMP2__)
3754 };
3755 prototype.equals = function(v) {
3756 return this.x == v.x && this.y == v.y && this.z == v.z
3757 };
3758 prototype.console = function() {
3759 console.log(this.x, this.y, this.z)
3760 };
3761 prototype.toString = function(split) {
3762 split = split || " ";
3763 return this.x + split + this.y + split + this.z
3764 };
3765 prototype.applyQuaternion = function(q) {
3766 var x = this.x,
3767 y = this.y,
3768 z = this.z;
3769 var qx = q.x,
3770 qy = q.y,
3771 qz = q.z,
3772 qw = q.w;
3773 var ix = qw * x + qy * z - qz * y;
3774 var iy = qw * y + qz * x - qx * z;
3775 var iz = qw * z + qx * y - qy * x;
3776 var iw = -qx * x - qy * y - qz * z;
3777 this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
3778 this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
3779 this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
3780 return this
3781 }
3782}, function() {
3783 Vector3.__TEMP__ = new Vector3
3784});
3785Mobile.Class(function ScreenLock() {
3786 Inherit(this, Component);
3787 var _this = this;
3788 var _lockedNodes = [];
3789 (function() {
3790 addListeners()
3791 }());
3792
3793 function addListeners() {
3794 _this.events.subscribe(HydraEvents.RESIZE, orientationChange)
3795 }
3796
3797 function orientationChange() {
3798 var width = document.body.clientWidth;
3799 var height = document.body.clientHeight;
3800 _lockedNodes.forEach(function(e) {
3801 if (Device.getFullscreen() && window.screen && window.screen.orientation.lock) {
3802 window.screen.orientation.lock(e.orientation == "portrait" ? "portrait" : "landscape");
3803 if (!Mobile.ScreenLock.FORCE_LOCK) return;
3804 e.object.size(width, height);
3805 e.object.div.style.transformOrigin = "";
3806 e.object.div.style.transform = "";
3807 return
3808 }
3809 if (!Mobile.ScreenLock.FORCE_LOCK) return;
3810 if (width < height) {
3811 e.object.size(width, height);
3812 e.object.div.style.transformOrigin = "";
3813 e.object.div.style.transform = ""
3814 } else {
3815 var w = width;
3816 var h = height;
3817 width = Math.max(w, h);
3818 height = Math.min(w, h);
3819 e.object.size(height, width);
3820 e.object.div.style.transformOrigin = "0% 0%";
3821 if (window.orientation == -90 || window.orientation == 180) {
3822 e.object.div.style.transform = "translateX(" + width + "px) rotate(90deg)"
3823 } else {
3824 e.object.div.style.transform = "translateY(" + height + "px) rotate(-90deg)"
3825 }
3826 }
3827 })
3828 }
3829 this.lock = function(orientation) {
3830 _lockedNodes.push({
3831 object: Stage,
3832 orientation: orientation
3833 });
3834 orientationChange()
3835 };
3836 this.unlock = function() {
3837 var obj = Stage;
3838 _lockedNodes.every(function(o, i) {
3839 if (o.object == obj) {
3840 _lockedNodes.splice(i, 1);
3841 return false
3842 }
3843 return true
3844 })
3845 };
3846 this.forceOrientationChange = orientationChange
3847}, "static");
3848Class(function Interaction() {
3849 Namespace(this)
3850}, "static");
3851Interaction.Class(function Input(_object) {
3852 Inherit(this, Component);
3853 var _this = this;
3854 var _hold = new Vector2;
3855 var _diff = new Vector2;
3856 var _lastMove = new Vector2;
3857 var _distance = new Vector2;
3858 var _delta = Render.TIME;
3859 var _lastTime = Render.TIME;
3860 this.velocity = new Vector2;
3861 this.clickLimit = 20;
3862 (function() {
3863 if (_object instanceof HydraObject) addListeners()
3864 }());
3865
3866 function addListeners() {
3867 if (_object == Stage || _object == __window) Interaction.Input.bind("touchstart", touchStart);
3868 else _object.bind("touchstart", touchStart);
3869 Interaction.Input.bind("touchmove", touchMove);
3870 Interaction.Input.bind("touchend", touchEnd)
3871 }
3872
3873 function touchStart(e) {
3874 _this.touching = true;
3875 _this.velocity.clear();
3876 _distance.clear();
3877 _hold.copyFrom(e);
3878 _lastMove.copyFrom(e);
3879 if (_this.onStart) {
3880 _this.onStart(e)
3881 }
3882 }
3883
3884 function touchMove(e) {
3885 if (!_this.touching) return;
3886 _diff.subVectors(e, _hold);
3887 _delta = Render.TIME - _lastTime || .01;
3888 if (_delta >= 16) {
3889 _this.velocity.subVectors(e, _lastMove);
3890 _distance.x += Math.abs(_this.velocity.x);
3891 _distance.y += Math.abs(_this.velocity.y);
3892 _this.velocity.divide(_delta);
3893 _lastTime = Render.TIME;
3894 _lastMove.copyFrom(e)
3895 }
3896 if (_this.onUpdate) {
3897 _this.onUpdate(_diff, e)
3898 }
3899 }
3900
3901 function touchEnd(e) {
3902 if (!_this.touching) return;
3903 _this.touching = false;
3904 if (_this.onEnd) {
3905 _this.onEnd(e)
3906 }
3907 if (_distance.length() < _this.clickLimit && _this.onClick) {
3908 _this.onClick(e)
3909 }
3910 }
3911 this.attach = function(object) {
3912 if (_object instanceof HydraObject) _object.unbind("touchstart", touchStart);
3913 _object = object;
3914 addListeners()
3915 };
3916 this.touchStart = function(e) {
3917 touchStart({
3918 x: Mouse.x,
3919 y: Mouse.y
3920 })
3921 };
3922 this.end = this.touchEnd = function() {
3923 touchEnd()
3924 };
3925 this.destroy = function() {
3926 Interaction.Input.unbind("touchmove", touchMove);
3927 Interaction.Input.unbind("touchstart", touchStart);
3928 Interaction.Input.unbind("touchend", touchEnd);
3929 _object && _object.unbind && _object.unbind("touchstart", touchStart);
3930 return this._destroy()
3931 }
3932}, () => {
3933 var _events = {
3934 touchstart: [],
3935 touchmove: [],
3936 touchend: []
3937 };
3938 var _bound;
3939
3940 function bind() {
3941 _bound = true;
3942 __window.bind("touchstart", touchStart);
3943 __window.bind("touchmove", touchMove);
3944 __window.bind("touchend", touchEnd);
3945 __window.bind("touchcancel", touchEnd);
3946 __window.bind("contextmenu", touchEnd)
3947 }
3948
3949 function touchMove(e) {
3950 _events.touchmove.forEach(function(callback) {
3951 callback(e)
3952 })
3953 }
3954
3955 function touchStart(e) {
3956 _events.touchstart.forEach(function(callback) {
3957 callback(e)
3958 })
3959 }
3960
3961 function touchEnd(e) {
3962 _events.touchend.forEach(function(callback) {
3963 callback(e)
3964 })
3965 }
3966 Interaction.Input.bind = function(evt, callback) {
3967 _events[evt].push(callback);
3968 if (!_bound) bind()
3969 };
3970 Interaction.Input.unbind = function(evt, callback) {
3971 _events[evt].findAndRemove(callback)
3972 }
3973});
3974Class(function ParticlePhysics(_integrator) {
3975 Inherit(this, Component);
3976 var _this = this;
3977 _integrator = _integrator || new EulerIntegrator;
3978 var _timestep = 1 / 60;
3979 var _time = 0;
3980 var _step = 0;
3981 var _clock = null;
3982 var _buffer = 0;
3983 var _toDelete = [];
3984 this.friction = 1;
3985 this.maxSteps = 1;
3986 this.emitters = new LinkedList;
3987 this.initializers = new LinkedList;
3988 this.behaviors = new LinkedList;
3989 this.particles = new LinkedList;
3990 this.springs = new LinkedList;
3991
3992 function init(p) {
3993 var i = _this.initializers.start();
3994 while (i) {
3995 i(p);
3996 i = _this.initializers.next()
3997 }
3998 }
3999
4000 function updateSprings(dt) {
4001 var s = _this.springs.start();
4002 while (s) {
4003 s.update(dt);
4004 s = _this.springs.next()
4005 }
4006 }
4007
4008 function deleteParticles() {
4009 for (var i = _toDelete.length - 1; i > -1; i--) {
4010 var particle = _toDelete[i];
4011 _this.particles.remove(particle);
4012 particle.system = null
4013 }
4014 _toDelete.length = 0
4015 }
4016
4017 function updateParticles(dt) {
4018 var index = 0;
4019 var p = _this.particles.start();
4020 while (p) {
4021 if (p.enabled) {
4022 var b = _this.behaviors.start();
4023 while (b) {
4024 b.applyBehavior(p, dt, index);
4025 b = _this.behaviors.next()
4026 }
4027 if (p.behaviors.length) p.update(dt, index)
4028 }
4029 index++;
4030 p = _this.particles.next()
4031 }
4032 }
4033
4034 function integrate(dt) {
4035 updateParticles(dt);
4036 if (_this.springs.length) updateSprings(dt);
4037 if (!_this.skipIntegration) _integrator.integrate(_this.particles, dt, _this.friction)
4038 }
4039 this.addEmitter = function(emitter) {
4040 if (!(emitter instanceof Emitter)) throw "Emitter must be Emitter";
4041 this.emitters.push(emitter);
4042 emitter.parent = emitter.system = this
4043 };
4044 this.removeEmitter = function(emitter) {
4045 if (!(emitter instanceof Emitter)) throw "Emitter must be Emitter";
4046 this.emitters.remove(emitter);
4047 emitter.parent = emitter.system = null
4048 };
4049 this.addInitializer = function(init) {
4050 if (typeof init !== "function") throw "Initializer must be a function";
4051 this.initializers.push(init)
4052 };
4053 this.removeInitializer = function(init) {
4054 this.initializers.remove(init)
4055 };
4056 this.addBehavior = function(b) {
4057 this.behaviors.push(b);
4058 b.system = this
4059 };
4060 this.removeBehavior = function(b) {
4061 this.behaviors.remove(b)
4062 };
4063 this.addParticle = function(p) {
4064 if (!_integrator.type) {
4065 if (typeof p.pos.z === "number") _integrator.type = "3D";
4066 else _integrator.type = "2D"
4067 }
4068 p.system = this;
4069 this.particles.push(p);
4070 if (this.initializers.length) init(p)
4071 };
4072 this.removeParticle = function(p) {
4073 p.system = null;
4074 _toDelete.push(p)
4075 };
4076 this.addSpring = function(s) {
4077 s.system = this;
4078 this.springs.push(s)
4079 };
4080 this.removeSpring = function(s) {
4081 s.system = null;
4082 this.springs.remove(s)
4083 };
4084 this.update = function(force) {
4085 if (!_clock) _clock = THREAD ? Date.now() : Render.TIME;
4086 var time = THREAD ? Date.now() : Render.TIME;
4087 var delta = time - _clock;
4088 if (!force && delta <= 0) return;
4089 delta *= .001;
4090 _clock = time;
4091 _buffer += delta;
4092 if (!force) {
4093 var i = 0;
4094 while (_buffer >= _timestep && i++ < _this.maxSteps) {
4095 integrate(_timestep);
4096 _buffer -= _timestep;
4097 _time += _timestep
4098 }
4099 } else {
4100 integrate(.016)
4101 }
4102 _step = Date.now() - time;
4103 if (_toDelete.length) deleteParticles()
4104 }
4105});
4106Class(function Particle(_pos, _mass, _radius) {
4107 var _this = this;
4108 var _vel, _acc, _old;
4109 var prototype = Particle.prototype;
4110 this.mass = _mass || 1;
4111 this.massInv = 1 / this.mass;
4112 this.radius = _radius || 1;
4113 this.radiusSq = this.radius * this.radius;
4114 this.behaviors = new LinkedList;
4115 this.fixed = false;
4116 (function() {
4117 initVectors()
4118 }());
4119
4120 function initVectors() {
4121 var Vector = typeof _pos.z === "number" ? Vector3 : Vector2;
4122 _pos = _pos || new Vector;
4123 _vel = new Vector;
4124 _acc = new Vector;
4125 _old = {};
4126 _old.pos = new Vector;
4127 _old.acc = new Vector;
4128 _old.vel = new Vector;
4129 _old.pos.copyFrom(_pos);
4130 _this.pos = _this.position = _pos;
4131 _this.vel = _this.velocity = _vel;
4132 _this.acc = _this.acceleration = _acc;
4133 _this.old = _old
4134 }
4135 this.moveTo = function(pos) {
4136 _pos.copyFrom(pos);
4137 _old.pos.copyFrom(_pos);
4138 _acc.clear();
4139 _vel.clear()
4140 };
4141 if (typeof prototype.setMass !== "undefined") return;
4142 prototype.setMass = function(mass) {
4143 this.mass = mass || 1;
4144 this.massInv = 1 / this.mass
4145 };
4146 prototype.setRadius = function(radius) {
4147 this.radius = radius;
4148 this.radiusSq = radius * radius
4149 };
4150 prototype.update = function(dt) {
4151 if (!this.behaviors.length) return;
4152 var b = this.behaviors.start();
4153 while (b) {
4154 b.applyBehavior(this, dt);
4155 b = this.behaviors.next()
4156 }
4157 };
4158 prototype.applyForce = function(force) {
4159 this.acc.add(force)
4160 };
4161 prototype.addBehavior = function(behavior) {
4162 if (!behavior || typeof behavior.applyBehavior === "undefined") throw "Behavior must have applyBehavior method";
4163 this.behaviors.push(behavior)
4164 };
4165 prototype.removeBehavior = function(behavior) {
4166 if (!behavior || typeof behavior.applyBehavior === "undefined") throw "Behavior must have applyBehavior method";
4167 this.behaviors.remove(behavior)
4168 }
4169});
4170Class(function EulerIntegrator() {
4171 Inherit(this, Component);
4172 var _this = this;
4173 var _vel, _accel;
4174 this.useDeltaTime = false;
4175 (function() {}());
4176
4177 function createVectors() {
4178 var Vector = _this.type == "3D" ? Vector3 : Vector2;
4179 _vel = new Vector;
4180 _accel = new Vector
4181 }
4182 this.integrate = function(particles, dt, drag) {
4183 if (!_vel) createVectors();
4184 var dtSq = dt * dt;
4185 var p = particles.start();
4186 while (p) {
4187 if (!p.fixed && !p.disabled) {
4188 p.old.pos.copyFrom(p.pos);
4189 p.acc.multiply(p.massInv);
4190 _vel.copyFrom(p.vel);
4191 _accel.copyFrom(p.acc);
4192 if (this.useDeltaTime) {
4193 p.pos.add(_vel.multiply(dt)).add(_accel.multiply(.5 * dtSq));
4194 p.vel.add(p.acc.multiply(dt))
4195 } else {
4196 p.pos.add(_vel).add(_accel.multiply(.5));
4197 p.vel.add(p.acc)
4198 }
4199 if (drag) p.vel.multiply(drag);
4200 p.acc.clear()
4201 }
4202 if (p.saveTo) p.pos.copyTo(p.saveTo);
4203 p = particles.next()
4204 }
4205 }
4206});
4207Class(function Emitter(_position, _startNumber) {
4208 Inherit(this, Component);
4209 var _this = this;
4210 var _pool;
4211 var _total = 0;
4212 var Vector = _position.type == "vector3" ? Vector3 : Vector2;
4213 this.initializers = [];
4214 this.position = _position;
4215 this.autoEmit = 1;
4216 (function() {
4217 initObjectPool();
4218 if (_startNumber != 0) addParticles(_startNumber || 100)
4219 }());
4220
4221 function initObjectPool() {
4222 _pool = _this.initClass(ObjectPool)
4223 }
4224
4225 function addParticles(total) {
4226 _total += total;
4227 var particles = [];
4228 for (var i = 0; i < total; i++) {
4229 particles.push(new Particle)
4230 }
4231 _pool.insert(particles)
4232 }
4233 this.addInitializer = function(callback) {
4234 if (typeof callback !== "function") throw "Initializer must be a function";
4235 this.initializers.push(callback)
4236 };
4237 this.removeInitializer = function(callback) {
4238 var index = this.initializers.indexOf(callback);
4239 if (index > -1) this.initializers.splice(index, 1)
4240 };
4241 this.emit = function(num) {
4242 if (!this.parent) throw "Emitter needs to be added to a System";
4243 num = num || this.autoEmit;
4244 for (var i = 0; i < num; i++) {
4245 var p = _pool.get();
4246 if (!p) return;
4247 p.moveTo(this.position);
4248 p.emitter = this;
4249 p.enabled = true;
4250 if (!p.system) this.parent.addParticle(p);
4251 for (var j = 0; j < this.initializers.length; j++) {
4252 this.initializers[j](p, i / num)
4253 }
4254 }
4255 };
4256 this.remove = function(particle) {
4257 _pool.put(particle);
4258 if (!_this.persist) _this.parent.removeParticle(particle);
4259 particle.enabled = false
4260 };
4261 this.addToPool = function(particle) {
4262 _pool.put(particle);
4263 if (!_this.persist && particle.system) _this.parent.removeParticle(particle);
4264 particle.enabled = false
4265 }
4266});
4267Class(function SplitTextfield() {
4268 var _style = {
4269 display: "block",
4270 position: "relative",
4271 padding: 0,
4272 margin: 0,
4273 cssFloat: "left",
4274 styleFloat: "left",
4275 width: "auto",
4276 height: "auto"
4277 };
4278
4279 function splitLetter($obj) {
4280 var _array = [];
4281 var text = $obj.div.innerHTML;
4282 var split = text.split("");
4283 $obj.div.innerHTML = "";
4284 for (var i = 0; i < split.length; i++) {
4285 if (split[i] == " ") split[i] = " ";
4286 var letter = $("t", "span");
4287 letter.html(split[i], true).css(_style);
4288 _array.push(letter);
4289 $obj.addChild(letter)
4290 }
4291 return _array
4292 }
4293
4294 function splitWord($obj) {
4295 var _array = [];
4296 var text = $obj.div.innerHTML;
4297 var split = text.split(" ");
4298 $obj.empty();
4299 for (var i = 0; i < split.length; i++) {
4300 var word = $("t", "span");
4301 var empty = $("t", "span");
4302 word.html(split[i]).css(_style);
4303 empty.html(" ", true).css(_style);
4304 _array.push(word);
4305 _array.push(empty);
4306 $obj.addChild(word);
4307 $obj.addChild(empty)
4308 }
4309 return _array
4310 }
4311 this.split = function($obj, by) {
4312 if (by == "word") return splitWord($obj);
4313 else return splitLetter($obj)
4314 }
4315}, "Static");
4316Class(function TweenManager() {
4317 Namespace(this);
4318 var _this = this;
4319 var _tweens = [];
4320 (function() {
4321 if (window.Hydra) Hydra.ready(initPools);
4322 if (window.Render) Render.startRender(updateTweens)
4323 }());
4324
4325 function initPools() {
4326 _this._dynamicPool = new ObjectPool(DynamicObject, 100);
4327 _this._arrayPool = new ObjectPool(Array, 100);
4328 _this._dynamicPool.debug = true
4329 }
4330
4331 function updateTweens(time) {
4332 for (var i = 0; i < _tweens.length; i++) {
4333 _tweens[i].update(time)
4334 }
4335 }
4336
4337 function stringToValues(str) {
4338 var values = str.split("(")[1].slice(0, -1).split(",");
4339 for (var i = 0; i < values.length; i++) values[i] = parseFloat(values[i]);
4340 return values
4341 }
4342
4343 function findEase(name) {
4344 var eases = _this.CSSEases;
4345 for (var i = eases.length - 1; i > -1; i--) {
4346 if (eases[i].name == name) {
4347 return eases[i]
4348 }
4349 }
4350 return false
4351 }
4352 this._addMathTween = function(tween) {
4353 _tweens.push(tween)
4354 };
4355 this._removeMathTween = function(tween) {
4356 _tweens.findAndRemove(tween)
4357 };
4358 this._detectTween = function(object, props, time, ease, delay, callback) {
4359 if (ease === "spring") {
4360 return new SpringTween(object, props, time, ease, delay, callback)
4361 }
4362 if (!_this.useCSSTrans(props, ease, object)) {
4363 return new FrameTween(object, props, time, ease, delay, callback)
4364 } else {
4365 if (Device.tween.webAnimation) {
4366 return new CSSWebAnimation(object, props, time, ease, delay, callback)
4367 } else {
4368 return new CSSTransition(object, props, time, ease, delay, callback)
4369 }
4370 }
4371 };
4372 this.tween = function(obj, props, time, ease, delay, complete, update, manual) {
4373 if (typeof delay !== "number") {
4374 update = complete;
4375 complete = delay;
4376 delay = 0
4377 }
4378 var tween;
4379 if (ease === "spring") {
4380 tween = new SpringTween(obj, props, time, ease, delay, update, complete)
4381 } else {
4382 tween = new MathTween(obj, props, time, ease, delay, update, complete, manual)
4383 }
4384 var usePromise = null;
4385 if (complete && complete instanceof Promise) {
4386 usePromise = complete;
4387 complete = complete.resolve
4388 }
4389 return usePromise || tween
4390 };
4391 this.iterate = function(array, props, time, ease, offset, delay, callback) {
4392 if (typeof delay !== "number") {
4393 callback = delay;
4394 delay = 0
4395 }
4396 props = new DynamicObject(props);
4397 if (!array.length) throw "TweenManager.iterate :: array is empty";
4398 var len = array.length;
4399 for (var i = 0; i < len; i++) {
4400 var obj = array[i];
4401 var complete = i == len - 1 ? callback : null;
4402 obj.tween(props.copy(), time, ease, delay + offset * i, complete)
4403 }
4404 };
4405 this.clearTween = function(obj) {
4406 if (obj._mathTween && obj._mathTween.stop) obj._mathTween.stop();
4407 if (obj._mathTweens) {
4408 var tweens = obj._mathTweens;
4409 for (var i = 0; i < tweens.length; i++) {
4410 var tw = tweens[i];
4411 if (tw && tw.stop) tw.stop()
4412 }
4413 obj._mathTweens = null
4414 }
4415 };
4416 this.clearCSSTween = function(obj) {
4417 if (obj && !obj._cssTween && obj.div._transition && !obj.persistTween) {
4418 obj.div.style[Device.styles.vendorTransition] = "";
4419 obj.div._transition = false;
4420 obj._cssTween = null
4421 }
4422 };
4423 this.checkTransform = function(key) {
4424 var index = _this.Transforms.indexOf(key);
4425 return index > -1
4426 };
4427 this.addCustomEase = function(ease) {
4428 var add = true;
4429 if (typeof ease !== "object" || !ease.name || !ease.curve) throw "TweenManager :: addCustomEase requires {name, curve}";
4430 for (var i = _this.CSSEases.length - 1; i > -1; i--) {
4431 if (ease.name == _this.CSSEases[i].name) {
4432 add = false
4433 }
4434 }
4435 if (add) {
4436 if (ease.curve.charAt(0).toLowerCase() == "m") ease.path = new EasingPath(ease.curve);
4437 else ease.values = stringToValues(ease.curve);
4438 _this.CSSEases.push(ease)
4439 }
4440 return ease
4441 };
4442 this.getEase = function(name, values) {
4443 if (Array.isArray(name)) {
4444 var c1 = findEase(name[0]);
4445 var c2 = findEase(name[1]);
4446 if (!c1 || !c2) throw "Multi-ease tween missing values " + JSON.stringify(name);
4447 if (!c1.values) c1.values = stringToValues(c1.curve);
4448 if (!c2.values) c2.values = stringToValues(c2.curve);
4449 if (values) return [c1.values[0], c1.values[1], c2.values[2], c2.values[3]];
4450 return "cubic-bezier(" + c1.values[0] + "," + c1.values[1] + "," + c2.values[2] + "," + c2.values[3] + ")"
4451 } else {
4452 var ease = findEase(name);
4453 if (!ease) return false;
4454 if (values) {
4455 return ease.path ? ease.path.solve : ease.values
4456 } else {
4457 return ease.curve
4458 }
4459 }
4460 };
4461 this.inspectEase = function(name) {
4462 return findEase(name)
4463 };
4464 this.getAllTransforms = function(object) {
4465 var obj = {};
4466 for (var i = _this.Transforms.length - 1; i > -1; i--) {
4467 var tf = _this.Transforms[i];
4468 var val = object[tf];
4469 if (val !== 0 && typeof val === "number") {
4470 obj[tf] = val
4471 }
4472 }
4473 return obj
4474 };
4475 this.parseTransform = function(props) {
4476 var transforms = "";
4477 var translate = "";
4478 if (props.perspective > 0) transforms += "perspective(" + props.perspective + "px)";
4479 if (typeof props.x !== "undefined" || typeof props.y !== "undefined" || typeof props.z !== "undefined") {
4480 var x = props.x || 0;
4481 var y = props.y || 0;
4482 var z = props.z || 0;
4483 translate += x + "px, ";
4484 translate += y + "px";
4485 if (Device.tween.css3d) {
4486 translate += ", " + z + "px";
4487 transforms += "translate3d(" + translate + ")"
4488 } else {
4489 transforms += "translate(" + translate + ")"
4490 }
4491 }
4492 if (typeof props.scale !== "undefined") {
4493 transforms += "scale(" + props.scale + ")"
4494 } else {
4495 if (typeof props.scaleX !== "undefined") transforms += "scaleX(" + props.scaleX + ")";
4496 if (typeof props.scaleY !== "undefined") transforms += "scaleY(" + props.scaleY + ")"
4497 }
4498 if (typeof props.rotation !== "undefined") transforms += "rotate(" + props.rotation + "deg)";
4499 if (typeof props.rotationX !== "undefined") transforms += "rotateX(" + props.rotationX + "deg)";
4500 if (typeof props.rotationY !== "undefined") transforms += "rotateY(" + props.rotationY + "deg)";
4501 if (typeof props.rotationZ !== "undefined") transforms += "rotateZ(" + props.rotationZ + "deg)";
4502 if (typeof props.skewX !== "undefined") transforms += "skewX(" + props.skewX + "deg)";
4503 if (typeof props.skewY !== "undefined") transforms += "skewY(" + props.skewY + "deg)";
4504 return transforms
4505 };
4506 this.interpolate = function(num, alpha, ease) {
4507 var fn = _this.Interpolation.convertEase(ease);
4508 return num * (typeof fn == "function" ? fn(alpha) : _this.Interpolation.solve(fn, alpha))
4509 };
4510 this.interpolateValues = function(start, end, alpha, ease) {
4511 var fn = _this.Interpolation.convertEase(ease);
4512 return start + (end - start) * (typeof fn == "function" ? fn(alpha) : _this.Interpolation.solve(fn, alpha))
4513 }
4514}, "Static");
4515(function() {
4516 TweenManager.Transforms = ["scale", "scaleX", "scaleY", "x", "y", "z", "rotation", "rotationX", "rotationY", "rotationZ", "skewX", "skewY", "perspective"];
4517 TweenManager.CSSEases = [{
4518 name: "easeOutCubic",
4519 curve: "cubic-bezier(0.215, 0.610, 0.355, 1.000)"
4520 }, {
4521 name: "easeOutQuad",
4522 curve: "cubic-bezier(0.250, 0.460, 0.450, 0.940)"
4523 }, {
4524 name: "easeOutQuart",
4525 curve: "cubic-bezier(0.165, 0.840, 0.440, 1.000)"
4526 }, {
4527 name: "easeOutQuint",
4528 curve: "cubic-bezier(0.230, 1.000, 0.320, 1.000)"
4529 }, {
4530 name: "easeOutSine",
4531 curve: "cubic-bezier(0.390, 0.575, 0.565, 1.000)"
4532 }, {
4533 name: "easeOutExpo",
4534 curve: "cubic-bezier(0.190, 1.000, 0.220, 1.000)"
4535 }, {
4536 name: "easeOutCirc",
4537 curve: "cubic-bezier(0.075, 0.820, 0.165, 1.000)"
4538 }, {
4539 name: "easeOutBack",
4540 curve: "cubic-bezier(0.175, 0.885, 0.320, 1.275)"
4541 }, {
4542 name: "easeInCubic",
4543 curve: "cubic-bezier(0.550, 0.055, 0.675, 0.190)"
4544 }, {
4545 name: "easeInQuad",
4546 curve: "cubic-bezier(0.550, 0.085, 0.680, 0.530)"
4547 }, {
4548 name: "easeInQuart",
4549 curve: "cubic-bezier(0.895, 0.030, 0.685, 0.220)"
4550 }, {
4551 name: "easeInQuint",
4552 curve: "cubic-bezier(0.755, 0.050, 0.855, 0.060)"
4553 }, {
4554 name: "easeInSine",
4555 curve: "cubic-bezier(0.470, 0.000, 0.745, 0.715)"
4556 }, {
4557 name: "easeInCirc",
4558 curve: "cubic-bezier(0.600, 0.040, 0.980, 0.335)"
4559 }, {
4560 name: "easeInBack",
4561 curve: "cubic-bezier(0.600, -0.280, 0.735, 0.045)"
4562 }, {
4563 name: "easeInOutCubic",
4564 curve: "cubic-bezier(0.645, 0.045, 0.355, 1.000)"
4565 }, {
4566 name: "easeInOutQuad",
4567 curve: "cubic-bezier(0.455, 0.030, 0.515, 0.955)"
4568 }, {
4569 name: "easeInOutQuart",
4570 curve: "cubic-bezier(0.770, 0.000, 0.175, 1.000)"
4571 }, {
4572 name: "easeInOutQuint",
4573 curve: "cubic-bezier(0.860, 0.000, 0.070, 1.000)"
4574 }, {
4575 name: "easeInOutSine",
4576 curve: "cubic-bezier(0.445, 0.050, 0.550, 0.950)"
4577 }, {
4578 name: "easeInOutExpo",
4579 curve: "cubic-bezier(1.000, 0.000, 0.000, 1.000)"
4580 }, {
4581 name: "easeInOutCirc",
4582 curve: "cubic-bezier(0.785, 0.135, 0.150, 0.860)"
4583 }, {
4584 name: "easeInOutBack",
4585 curve: "cubic-bezier(0.680, -0.550, 0.265, 1.550)"
4586 }, {
4587 name: "easeInOut",
4588 curve: "cubic-bezier(.42,0,.58,1)"
4589 }, {
4590 name: "linear",
4591 curve: "linear"
4592 }];
4593 TweenManager.useCSSTrans = function(props, ease, object) {
4594 if (props.math) return false;
4595 if (typeof ease === "string" && (ease.strpos("Elastic") || ease.strpos("Bounce"))) return false;
4596 if (object.multiTween || TweenManager.inspectEase(ease).path) return false;
4597 if (!Device.tween.transition) return false;
4598 return true
4599 }
4600}());
4601Class(function CSSTransition(_object, _props, _time, _ease, _delay, _callback) {
4602 var _this = this;
4603 var _transformProps, _transitionProps, _stack, _totalStacks;
4604 var _startTransform, _startProps;
4605 this.playing = true;
4606 (function() {
4607 if (typeof _time !== "number") throw "CSSTween Requires object, props, time, ease";
4608 initProperties();
4609 if (typeof _ease == "object" && !Array.isArray(_ease)) initStack();
4610 else initCSSTween()
4611 }());
4612
4613 function killed() {
4614 return !_this || _this.kill || !_object || !_object.div
4615 }
4616
4617 function initProperties() {
4618 var transform = TweenManager.getAllTransforms(_object);
4619 var properties = [];
4620 for (var key in _props) {
4621 if (TweenManager.checkTransform(key)) {
4622 transform.use = true;
4623 transform[key] = _props[key];
4624 delete _props[key]
4625 } else {
4626 if (typeof _props[key] === "number" || key.strpos("-")) properties.push(key)
4627 }
4628 }
4629 if (transform.use) properties.push(Device.transformProperty);
4630 delete transform.use;
4631 _transformProps = transform;
4632 _transitionProps = properties
4633 }
4634
4635 function initStack() {
4636 initStart();
4637 var prevTime = 0;
4638 var interpolate = function(start, end, alpha, ease, prev, ke) {
4639 var last = prev[key];
4640 if (last) start += last;
4641 return TweenManager.interpolateValues(start, end, alpha, ease)
4642 };
4643 _stack = [];
4644 _totalStacks = 0;
4645 for (var p in _ease) {
4646 var perc = p.strpos("%") ? Number(p.replace("%", "")) / 100 : (Number(p) + 1) / _ease.length;
4647 if (isNaN(perc)) continue;
4648 var ease = _ease[p];
4649 _totalStacks++;
4650 var transform = {};
4651 var props = {};
4652 var last = _stack[_stack.length - 1];
4653 var pr = last ? last.props : {};
4654 var zeroOut = !last;
4655 for (var key in _transformProps) {
4656 if (!_startTransform[key]) _startTransform[key] = key.strpos("scale") ? 1 : 0;
4657 transform[key] = interpolate(_startTransform[key], _transformProps[key], perc, ease, pr, key);
4658 if (zeroOut) pr[key] = _startTransform[key]
4659 }
4660 for (key in _props) {
4661 props[key] = interpolate(_startProps[key], _props[key], perc, ease, pr, key);
4662 if (zeroOut) pr[key] = _startProps[key]
4663 }
4664 var time = perc * _time - prevTime;
4665 prevTime += time;
4666 _stack.push({
4667 percent: perc,
4668 ease: ease,
4669 transform: transform,
4670 props: props,
4671 delay: _totalStacks == 1 ? _delay : 0,
4672 time: time
4673 })
4674 }
4675 initCSSTween(_stack.shift())
4676 }
4677
4678 function initStart() {
4679 _startTransform = TweenManager.getAllTransforms(_object);
4680 var transform = TweenManager.parseTransform(_startTransform);
4681 if (!transform.length) {
4682 for (var i = TweenManager.Transforms.length - 1; i > -1; i--) {
4683 var key = TweenManager.Transforms[i];
4684 _startTransform[key] = key == "scale" ? 1 : 0
4685 }
4686 }
4687 _startProps = {};
4688 for (key in _props) {
4689 _startProps[key] = _object.css(key)
4690 }
4691 }
4692
4693 function initCSSTween(values) {
4694 if (killed()) return;
4695 if (_object._cssTween) _object._cssTween.kill = true;
4696 _object._cssTween = _this;
4697 _object.div._transition = true;
4698 var strings = function() {
4699 if (!values) {
4700 return buildStrings(_time, _ease, _delay)
4701 } else {
4702 return buildStrings(values.time, values.ease, values.delay)
4703 }
4704 }();
4705 _object.willChange(strings.props);
4706 var time = values ? values.time : _time;
4707 var delay = values ? values.delay : _delay;
4708 var props = values ? values.props : _props;
4709 var transformProps = values ? values.transform : _transformProps;
4710 Timer.create(function() {
4711 if (killed()) return;
4712 _object.div.style[Device.styles.vendorTransition] = strings.transition;
4713 _this.playing = true;
4714 if (Device.browser.safari) {
4715 Timer.create(function() {
4716 if (killed()) return;
4717 _object.css(props);
4718 _object.transform(transformProps)
4719 }, 16)
4720 } else {
4721 _object.css(props);
4722 _object.transform(transformProps)
4723 }
4724 Timer.create(function() {
4725 if (killed()) return;
4726 if (!_stack) {
4727 clearCSSTween();
4728 if (_callback) _callback()
4729 } else {
4730 executeNextInStack()
4731 }
4732 }, time + delay)
4733 }, 50)
4734 }
4735
4736 function executeNextInStack() {
4737 if (killed()) return;
4738 var values = _stack.shift();
4739 if (!values) {
4740 clearCSSTween();
4741 if (_callback) _callback
4742 } else {
4743 var strings = buildStrings(values.time, values.ease, values.delay);
4744 _object.div.style[Device.styles.vendorTransition] = strings.transition;
4745 _object.css(values.props);
4746 _object.transform(values.transform);
4747 Timer.create(executeNextInStack, values.time)
4748 }
4749 }
4750
4751 function buildStrings(time, ease, delay) {
4752 var props = "";
4753 var str = "";
4754 var len = _transitionProps.length;
4755 for (var i = 0; i < len; i++) {
4756 var transitionProp = _transitionProps[i];
4757 props += (props.length ? ", " : "") + transitionProp;
4758 str += (str.length ? ", " : "") + transitionProp + " " + time + "ms " + TweenManager.getEase(ease) + " " + delay + "ms"
4759 }
4760 return {
4761 props: props,
4762 transition: str
4763 }
4764 }
4765
4766 function clearCSSTween() {
4767 if (killed()) return;
4768 _this.playing = false;
4769 _object._cssTween = null;
4770 _object.willChange(null);
4771 _object = _props = null;
4772 _this = null;
4773 Utils.nullObject(this)
4774 }
4775
4776 function tweenComplete() {
4777 if (!_callback && _this.playing) clearCSSTween()
4778 }
4779 this.stop = function() {
4780 if (!this.playing) return;
4781 this.kill = true;
4782 this.playing = false;
4783 _object.div.style[Device.styles.vendorTransition] = "";
4784 _object.div._transition = false;
4785 _object.willChange(null);
4786 _object._cssTween = null;
4787 _this = null;
4788 Utils.nullObject(this)
4789 }
4790});
4791Class(function FrameTween(_object, _props, _time, _ease, _delay, _callback, _manual) {
4792 var _this = this;
4793 var _endValues, _transformEnd, _transformStart, _startValues;
4794 var _isTransform, _isCSS, _transformProps;
4795 var _cssTween, _transformTween;
4796 this.playing = true;
4797 (function() {
4798 if (typeof _ease === "object") _ease = "easeOutCubic";
4799 if (_object && _props) {
4800 if (typeof _time !== "number") throw "FrameTween Requires object, props, time, ease";
4801 initValues();
4802 startTween()
4803 }
4804 }());
4805
4806 function killed() {
4807 return _this.kill || !_object || !_object.div
4808 }
4809
4810 function initValues() {
4811 if (_props.math) delete _props.math;
4812 if (Device.tween.transition && _object.div._transition) {
4813 _object.div.style[Device.styles.vendorTransition] = "";
4814 _object.div._transition = false
4815 }
4816 _endValues = new DynamicObject;
4817 _transformEnd = new DynamicObject;
4818 _transformStart = new DynamicObject;
4819 _startValues = new DynamicObject;
4820 if (!_object.multiTween) {
4821 if (typeof _props.x === "undefined") _props.x = _object.x;
4822 if (typeof _props.y === "undefined") _props.y = _object.y;
4823 if (typeof _props.z === "undefined") _props.z = _object.z
4824 }
4825 for (var key in _props) {
4826 if (TweenManager.checkTransform(key)) {
4827 _isTransform = true;
4828 _transformStart[key] = _object[key] || (key == "scale" ? 1 : 0);
4829 _transformEnd[key] = _props[key]
4830 } else {
4831 _isCSS = true;
4832 var v = _props[key];
4833 if (typeof v === "string") {
4834 _object.div.style[key] = v
4835 } else if (typeof v === "number") {
4836 _startValues[key] = Number(_object.css(key));
4837 _endValues[key] = v
4838 }
4839 }
4840 }
4841 }
4842
4843 function startTween() {
4844 if (_object._cssTween && !_manual && !_object.multiTween) _object._cssTween.kill = true;
4845 if (_object.multiTween) {
4846 if (!_object._cssTweens) _object._cssTweens = [];
4847 _object._cssTweens.push(_this)
4848 }
4849 _object._cssTween = _this;
4850 _this.playing = true;
4851 _props = _startValues.copy();
4852 _transformProps = _transformStart.copy();
4853 if (_isCSS) _cssTween = TweenManager.tween(_props, _endValues, _time, _ease, _delay, tweenComplete, update, _manual);
4854 if (_isTransform) _transformTween = TweenManager.tween(_transformProps, _transformEnd, _time, _ease, _delay, !_isCSS ? tweenComplete : null, !_isCSS ? update : null, _manual)
4855 }
4856
4857 function clear() {
4858 if (_object._cssTweens) {
4859 _object._cssTweens.findAndRemove(_this)
4860 }
4861 _this.playing = false;
4862 _object._cssTween = null;
4863 _object = _props = null
4864 }
4865
4866 function update() {
4867 if (killed()) return;
4868 if (_isCSS) _object.css(_props);
4869 if (_isTransform) {
4870 if (_object.multiTween) {
4871 for (var key in _transformProps) {
4872 if (typeof _transformProps[key] === "number") _object[key] = _transformProps[key]
4873 }
4874 _object.transform()
4875 } else {
4876 _object.transform(_transformProps)
4877 }
4878 }
4879 }
4880
4881 function tweenComplete() {
4882 if (_this.playing) {
4883 clear();
4884 if (_callback) _callback()
4885 }
4886 }
4887 this.stop = function() {
4888 if (!this.playing) return;
4889 if (_cssTween && _cssTween.stop) _cssTween.stop();
4890 if (_transformTween && _transformTween.stop) _transformTween.stop();
4891 clear()
4892 };
4893 this.interpolate = function(elapsed) {
4894 if (_cssTween) _cssTween.interpolate(elapsed);
4895 if (_transformTween) _transformTween.interpolate(elapsed);
4896 update()
4897 };
4898 this.getValues = function() {
4899 return {
4900 start: _startValues,
4901 transformStart: _transformStart,
4902 end: _endValues,
4903 transformEnd: _transformEnd
4904 }
4905 };
4906 this.setEase = function(ease) {
4907 if (_cssTween) _cssTween.setEase(ease);
4908 if (_transformTween) _transformTween.setEase(ease)
4909 }
4910});
4911TweenManager.Class(function Interpolation() {
4912 function calculateBezier(aT, aA1, aA2) {
4913 return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT
4914 }
4915
4916 function getTForX(aX, mX1, mX2) {
4917 var aGuessT = aX;
4918 for (var i = 0; i < 4; i++) {
4919 var currentSlope = getSlope(aGuessT, mX1, mX2);
4920 if (currentSlope == 0) return aGuessT;
4921 var currentX = calculateBezier(aGuessT, mX1, mX2) - aX;
4922 aGuessT -= currentX / currentSlope
4923 }
4924 return aGuessT
4925 }
4926
4927 function getSlope(aT, aA1, aA2) {
4928 return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1)
4929 }
4930
4931 function A(aA1, aA2) {
4932 return 1 - 3 * aA2 + 3 * aA1
4933 }
4934
4935 function B(aA1, aA2) {
4936 return 3 * aA2 - 6 * aA1
4937 }
4938
4939 function C(aA1) {
4940 return 3 * aA1
4941 }
4942 this.convertEase = function(ease) {
4943 var fn = function() {
4944 switch (ease) {
4945 case "easeInQuad":
4946 return TweenManager.Interpolation.Quad.In;
4947 break;
4948 case "easeInCubic":
4949 return TweenManager.Interpolation.Cubic.In;
4950 break;
4951 case "easeInQuart":
4952 return TweenManager.Interpolation.Quart.In;
4953 break;
4954 case "easeInQuint":
4955 return TweenManager.Interpolation.Quint.In;
4956 break;
4957 case "easeInSine":
4958 return TweenManager.Interpolation.Sine.In;
4959 break;
4960 case "easeInExpo":
4961 return TweenManager.Interpolation.Expo.In;
4962 break;
4963 case "easeInCirc":
4964 return TweenManager.Interpolation.Circ.In;
4965 break;
4966 case "easeInElastic":
4967 return TweenManager.Interpolation.Elastic.In;
4968 break;
4969 case "easeInBack":
4970 return TweenManager.Interpolation.Back.In;
4971 break;
4972 case "easeInBounce":
4973 return TweenManager.Interpolation.Bounce.In;
4974 break;
4975 case "easeOutQuad":
4976 return TweenManager.Interpolation.Quad.Out;
4977 break;
4978 case "easeOutCubic":
4979 return TweenManager.Interpolation.Cubic.Out;
4980 break;
4981 case "easeOutQuart":
4982 return TweenManager.Interpolation.Quart.Out;
4983 break;
4984 case "easeOutQuint":
4985 return TweenManager.Interpolation.Quint.Out;
4986 break;
4987 case "easeOutSine":
4988 return TweenManager.Interpolation.Sine.Out;
4989 break;
4990 case "easeOutExpo":
4991 return TweenManager.Interpolation.Expo.Out;
4992 break;
4993 case "easeOutCirc":
4994 return TweenManager.Interpolation.Circ.Out;
4995 break;
4996 case "easeOutElastic":
4997 return TweenManager.Interpolation.Elastic.Out;
4998 break;
4999 case "easeOutBack":
5000 return TweenManager.Interpolation.Back.Out;
5001 break;
5002 case "easeOutBounce":
5003 return TweenManager.Interpolation.Bounce.Out;
5004 break;
5005 case "easeInOutQuad":
5006 return TweenManager.Interpolation.Quad.InOut;
5007 break;
5008 case "easeInOutCubic":
5009 return TweenManager.Interpolation.Cubic.InOut;
5010 break;
5011 case "easeInOutQuart":
5012 return TweenManager.Interpolation.Quart.InOut;
5013 break;
5014 case "easeInOutQuint":
5015 return TweenManager.Interpolation.Quint.InOut;
5016 break;
5017 case "easeInOutSine":
5018 return TweenManager.Interpolation.Sine.InOut;
5019 break;
5020 case "easeInOutExpo":
5021 return TweenManager.Interpolation.Expo.InOut;
5022 break;
5023 case "easeInOutCirc":
5024 return TweenManager.Interpolation.Circ.InOut;
5025 break;
5026 case "easeInOutElastic":
5027 return TweenManager.Interpolation.Elastic.InOut;
5028 break;
5029 case "easeInOutBack":
5030 return TweenManager.Interpolation.Back.InOut;
5031 break;
5032 case "easeInOutBounce":
5033 return TweenManager.Interpolation.Bounce.InOut;
5034 break;
5035 case "linear":
5036 return TweenManager.Interpolation.Linear.None;
5037 break
5038 }
5039 }();
5040 if (!fn) {
5041 var curve = TweenManager.getEase(ease, true);
5042 if (curve) fn = curve;
5043 else fn = TweenManager.Interpolation.Cubic.Out
5044 }
5045 return fn
5046 };
5047 this.solve = function(values, elapsed) {
5048 if (values[0] == values[1] && values[2] == values[3]) return elapsed;
5049 return calculateBezier(getTForX(elapsed, values[0], values[2]), values[1], values[3])
5050 };
5051 this.Linear = {
5052 None: function(k) {
5053 return k
5054 }
5055 };
5056 this.Quad = {
5057 In: function(k) {
5058 return k * k
5059 },
5060 Out: function(k) {
5061 return k * (2 - k)
5062 },
5063 InOut: function(k) {
5064 if ((k *= 2) < 1) return .5 * k * k;
5065 return -.5 * (--k * (k - 2) - 1)
5066 }
5067 };
5068 this.Cubic = {
5069 In: function(k) {
5070 return k * k * k
5071 },
5072 Out: function(k) {
5073 return --k * k * k + 1
5074 },
5075 InOut: function(k) {
5076 if ((k *= 2) < 1) return .5 * k * k * k;
5077 return .5 * ((k -= 2) * k * k + 2)
5078 }
5079 };
5080 this.Quart = {
5081 In: function(k) {
5082 return k * k * k * k
5083 },
5084 Out: function(k) {
5085 return 1 - --k * k * k * k
5086 },
5087 InOut: function(k) {
5088 if ((k *= 2) < 1) return .5 * k * k * k * k;
5089 return -.5 * ((k -= 2) * k * k * k - 2)
5090 }
5091 };
5092 this.Quint = {
5093 In: function(k) {
5094 return k * k * k * k * k
5095 },
5096 Out: function(k) {
5097 return --k * k * k * k * k + 1
5098 },
5099 InOut: function(k) {
5100 if ((k *= 2) < 1) return .5 * k * k * k * k * k;
5101 return .5 * ((k -= 2) * k * k * k * k + 2)
5102 }
5103 };
5104 this.Sine = {
5105 In: function(k) {
5106 return 1 - Math.cos(k * Math.PI / 2)
5107 },
5108 Out: function(k) {
5109 return Math.sin(k * Math.PI / 2)
5110 },
5111 InOut: function(k) {
5112 return .5 * (1 - Math.cos(Math.PI * k))
5113 }
5114 };
5115 this.Expo = {
5116 In: function(k) {
5117 return k === 0 ? 0 : Math.pow(1024, k - 1)
5118 },
5119 Out: function(k) {
5120 return k === 1 ? 1 : 1 - Math.pow(2, -10 * k)
5121 },
5122 InOut: function(k) {
5123 if (k === 0) return 0;
5124 if (k === 1) return 1;
5125 if ((k *= 2) < 1) return .5 * Math.pow(1024, k - 1);
5126 return .5 * (-Math.pow(2, -10 * (k - 1)) + 2)
5127 }
5128 };
5129 this.Circ = {
5130 In: function(k) {
5131 return 1 - Math.sqrt(1 - k * k)
5132 },
5133 Out: function(k) {
5134 return Math.sqrt(1 - --k * k)
5135 },
5136 InOut: function(k) {
5137 if ((k *= 2) < 1) return -.5 * (Math.sqrt(1 - k * k) - 1);
5138 return .5 * (Math.sqrt(1 - (k -= 2) * k) + 1)
5139 }
5140 };
5141 this.Elastic = {
5142 In: function(k) {
5143 var s, a = .1,
5144 p = .4;
5145 if (k === 0) return 0;
5146 if (k === 1) return 1;
5147 if (!a || a < 1) {
5148 a = 1;
5149 s = p / 4
5150 } else s = p * Math.asin(1 / a) / (2 * Math.PI);
5151 return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p))
5152 },
5153 Out: function(k) {
5154 var s, a = .1,
5155 p = .4;
5156 if (k === 0) return 0;
5157 if (k === 1) return 1;
5158 if (!a || a < 1) {
5159 a = 1;
5160 s = p / 4
5161 } else s = p * Math.asin(1 / a) / (2 * Math.PI);
5162 return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1
5163 },
5164 InOut: function(k) {
5165 var s, a = .1,
5166 p = .4;
5167 if (k === 0) return 0;
5168 if (k === 1) return 1;
5169 if (!a || a < 1) {
5170 a = 1;
5171 s = p / 4
5172 } else s = p * Math.asin(1 / a) / (2 * Math.PI);
5173 if ((k *= 2) < 1) return -.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
5174 return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * .5 + 1
5175 }
5176 };
5177 this.Back = {
5178 In: function(k) {
5179 var s = 1.70158;
5180 return k * k * ((s + 1) * k - s)
5181 },
5182 Out: function(k) {
5183 var s = 1.70158;
5184 return --k * k * ((s + 1) * k + s) + 1
5185 },
5186 InOut: function(k) {
5187 var s = 1.70158 * 1.525;
5188 if ((k *= 2) < 1) return .5 * (k * k * ((s + 1) * k - s));
5189 return .5 * ((k -= 2) * k * ((s + 1) * k + s) + 2)
5190 }
5191 };
5192 this.Bounce = {
5193 In: function(k) {
5194 return 1 - this.Bounce.Out(1 - k)
5195 },
5196 Out: function(k) {
5197 if (k < 1 / 2.75) {
5198 return 7.5625 * k * k
5199 } else if (k < 2 / 2.75) {
5200 return 7.5625 * (k -= 1.5 / 2.75) * k + .75
5201 } else if (k < 2.5 / 2.75) {
5202 return 7.5625 * (k -= 2.25 / 2.75) * k + .9375
5203 } else {
5204 return 7.5625 * (k -= 2.625 / 2.75) * k + .984375
5205 }
5206 },
5207 InOut: function(k) {
5208 if (k < .5) return this.Bounce.In(k * 2) * .5;
5209 return this.Bounce.Out(k * 2 - 1) * .5 + .5
5210 }
5211 }
5212}, "Static");
5213Class(function EasingPath(_curve) {
5214 Inherit(this, Component);
5215 var _this = this;
5216 var _path, _boundsStartIndex, _pathLength, _pool;
5217 var _precompute = 145e1;
5218 var _step = 1 / _precompute;
5219 var _rect = 100;
5220 var _approximateMax = 5;
5221 var _eps = .001;
5222 var _boundsPrevProgress = -1;
5223 var _prevBounds = {};
5224 var _newPoint = {};
5225 var _samples = [];
5226 var _using = [];
5227 (function() {
5228 initPool();
5229 initPath();
5230 preSample()
5231 }());
5232
5233 function initPool() {
5234 _pool = _this.initClass(ObjectPool, Object, 100)
5235 }
5236
5237 function initPath() {
5238 _path = document.createElementNS("http://www.w3.org/2000/svg", "path");
5239 _path.setAttributeNS(null, "d", normalizePath(_curve));
5240 _pathLength = _path.getTotalLength()
5241 }
5242
5243 function preSample() {
5244 var i, j, length, point, progress, ref;
5245 for (i = j = 0, ref = _precompute; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
5246 progress = i * _step;
5247 length = _pathLength * progress;
5248 point = _path.getPointAtLength(length);
5249 _samples.push({
5250 point: point,
5251 length: length,
5252 progress: progress
5253 })
5254 }
5255 }
5256
5257 function normalizePath(path) {
5258 var svgRegex = /[M|L|H|V|C|S|Q|T|A]/gim;
5259 var points = path.split(svgRegex);
5260 points.shift();
5261 var commands = path.match(svgRegex);
5262 var startIndex = 0;
5263 points[startIndex] = normalizeSegment(points[startIndex], 0);
5264 var endIndex = points.length - 1;
5265 points[endIndex] = normalizeSegment(points[endIndex], _rect);
5266 return joinNormalizedPath(commands, points)
5267 }
5268
5269 function normalizeSegment(segment, value) {
5270 value = value || 0;
5271 segment = segment.trim();
5272 var nRgx = /(-|\+)?((\d+(\.(\d|\e(-|\+)?)+)?)|(\.?(\d|\e|(\-|\+))+))/gim;
5273 var pairs = getSegmentPairs(segment.match(nRgx));
5274 var lastPoint = pairs[pairs.length - 1];
5275 var x = lastPoint[0];
5276 var parsedX = Number(x);
5277 if (parsedX !== value) {
5278 segment = "";
5279 lastPoint[0] = value;
5280 for (var i = 0; i < pairs.length; i++) {
5281 var point = pairs[i];
5282 var space = i === 0 ? "" : " ";
5283 segment += "" + space + point[0] + "," + point[1]
5284 }
5285 }
5286 return segment
5287 }
5288
5289 function joinNormalizedPath(commands, points) {
5290 var normalizedPath = "";
5291 for (var i = 0; i < commands.length; i++) {
5292 var command = commands[i];
5293 var space = i === 0 ? "" : " ";
5294 normalizedPath += "" + space + command + points[i].trim()
5295 }
5296 return normalizedPath
5297 }
5298
5299 function getSegmentPairs(array) {
5300 if (array.length % 2 !== 0) throw "EasingPath :: Failed to parse path -- segment pairs are not even.";
5301 var newArray = [];
5302 for (var i = 0; i < array.length; i += 2) {
5303 var value = array[i];
5304 var pair = [array[i], array[i + 1]];
5305 newArray.push(pair)
5306 }
5307 return newArray
5308 }
5309
5310 function findBounds(array, p) {
5311 if (p == _boundsPrevProgress) return _prevBounds;
5312 if (!_boundsStartIndex) _boundsStartIndex = 0;
5313 var len = array.length;
5314 var loopEnd, direction, start;
5315 if (_boundsPrevProgress > p) {
5316 loopEnd = 0;
5317 direction = "reverse"
5318 } else {
5319 loopEnd = len;
5320 direction = "forward"
5321 }
5322 if (direction == "forward") {
5323 start = array[0];
5324 end = array[array.length - 1]
5325 } else {
5326 start = array[array.length - 1];
5327 end = array[0]
5328 }
5329 var i, j, ref, ref1, buffer;
5330 for (i = j = ref = _boundsStartIndex, ref1 = loopEnd; ref <= ref1 ? j < ref1 : j > ref1; i = ref <= ref1 ? ++j : --j) {
5331 var value = array[i];
5332 var pointX = value.point.x / _rect;
5333 var pointP = p;
5334 if (direction == "reverse") {
5335 buffer = pointX;
5336 pointX = pointP;
5337 pointP = buffer
5338 }
5339 if (pointX < pointP) {
5340 start = value;
5341 _boundsStartIndex = i
5342 } else {
5343 end = value;
5344 break
5345 }
5346 }
5347 _boundsPrevProgress = p;
5348 _prevBounds.start = start;
5349 _prevBounds.end = end;
5350 return _prevBounds
5351 }
5352
5353 function checkIfBoundsCloseEnough(p, bounds) {
5354 var point;
5355 var y = checkIfPointCloseEnough(p, bounds.start.point);
5356 if (y) return y;
5357 return checkIfPointCloseEnough(p, bounds.end.point)
5358 }
5359
5360 function findApproximate(p, start, end, approximateMax) {
5361 approximateMax = approximateMax || _approximateMax;
5362 var approximation = approximate(start, end, p);
5363 var point = _path.getPointAtLength(approximation);
5364 var x = point.x / _rect;
5365 if (closeEnough(p, x)) {
5366 return resolveY(point)
5367 } else {
5368 if (approximateMax-- < 1) {
5369 return resolveY(point)
5370 }
5371 var newPoint = _pool.get();
5372 newPoint.point = point;
5373 newPoint.length = approximation;
5374 _using.push(newPoint);
5375 if (p < x) return findApproximate(p, start, newPoint, approximateMax);
5376 else return findApproximate(p, newPoint, end, approximateMax)
5377 }
5378 }
5379
5380 function approximate(start, end, p) {
5381 var deltaP = end.point.x - start.point.x;
5382 var percentP = (p - start.point.x / _rect) / (deltaP / _rect);
5383 return start.length + percentP * (end.length - start.length)
5384 }
5385
5386 function checkIfPointCloseEnough(p, point) {
5387 if (closeEnough(p, point.x / _rect)) return resolveY(point)
5388 }
5389
5390 function closeEnough(n1, n2) {
5391 return Math.abs(n1 - n2) < _eps
5392 }
5393
5394 function resolveY(point) {
5395 return 1 - point.y / _rect
5396 }
5397
5398 function cleanUpObjects() {
5399 for (var i = _using.length - 1; i > -1; i--) {
5400 _pool.put(_using[i])
5401 }
5402 _using.length = 0
5403 }
5404 this.solve = function(p) {
5405 p = Utils.clamp(p, 0, 1);
5406 var bounds = findBounds(_samples, p);
5407 var res = checkIfBoundsCloseEnough(p, bounds);
5408 var output = res;
5409 if (!output) output = findApproximate(p, bounds.start, bounds.end);
5410 cleanUpObjects();
5411 return output
5412 }
5413});
5414Class(function MathTween(_object, _props, _time, _ease, _delay, _update, _callback, _manual) {
5415 var _this = this;
5416 var _startTime, _startValues, _endValues, _currentValues;
5417 var _easeFunction, _paused, _newEase, _stack, _current;
5418 var _elapsed = 0;
5419 (function() {
5420 if (_object && _props) {
5421 if (typeof _time !== "number") throw "MathTween Requires object, props, time, ease";
5422 start();
5423 if (typeof _ease == "object" && !Array.isArray(_ease)) initStack()
5424 }
5425 }());
5426
5427 function start() {
5428 if (!_object.multiTween && _object._mathTween && !_manual) TweenManager.clearTween(_object);
5429 if (!_manual) TweenManager._addMathTween(_this);
5430 _object._mathTween = _this;
5431 if (_object.multiTween) {
5432 if (!_object._mathTweens) _object._mathTweens = [];
5433 _object._mathTweens.push(_this)
5434 }
5435 if (typeof _ease == "string") {
5436 _ease = TweenManager.Interpolation.convertEase(_ease);
5437 _easeFunction = typeof _ease === "function"
5438 } else if (Array.isArray(_ease)) {
5439 _easeFunction = false;
5440 _ease = TweenManager.getEase(_ease, true)
5441 }
5442 _startTime = Date.now();
5443 _startTime += _delay;
5444 _endValues = _props;
5445 _startValues = {};
5446 _this.startValues = _startValues;
5447 for (var prop in _endValues) {
5448 if (typeof _object[prop] === "number") _startValues[prop] = _object[prop]
5449 }
5450 }
5451
5452 function initStack() {
5453 var prevTime = 0;
5454 var interpolate = function(start, end, alpha, ease, prev, key) {
5455 var last = prev[key];
5456 if (last) start += last;
5457 return TweenManager.interpolateValues(start, end, alpha, ease)
5458 };
5459 _stack = [];
5460 for (var p in _ease) {
5461 var perc = p.strpos("%") ? Number(p.replace("%", "")) / 100 : (Number(p) + 1) / _ease.length;
5462 if (isNaN(perc)) continue;
5463 var ease = _ease[p];
5464 var last = _stack[_stack.length - 1];
5465 var props = {};
5466 var pr = last ? last.end : {};
5467 var zeroOut = !last;
5468 for (var key in _startValues) {
5469 props[key] = interpolate(_startValues[key], _endValues[key], perc, ease, pr, key);
5470 if (zeroOut) pr[key] = _startValues[key]
5471 }
5472 var time = perc * _time - prevTime;
5473 prevTime += time;
5474 _stack.push({
5475 percent: perc,
5476 ease: ease,
5477 start: pr,
5478 end: props,
5479 time: time
5480 })
5481 }
5482 _currentValues = _stack.shift()
5483 }
5484
5485 function clear() {
5486 if (!_object && !_props) return false;
5487 _object._mathTween = null;
5488 TweenManager._removeMathTween(_this);
5489 Utils.nullObject(_this);
5490 if (_object._mathTweens) {
5491 _object._mathTweens.findAndRemove(_this)
5492 }
5493 }
5494
5495 function updateSingle(time) {
5496 _elapsed = (time - _startTime) / _time;
5497 _elapsed = _elapsed > 1 ? 1 : _elapsed;
5498 var delta = _easeFunction ? _ease(_elapsed) : TweenManager.Interpolation.solve(_ease, _elapsed);
5499 for (var prop in _startValues) {
5500 if (typeof _startValues[prop] === "number") {
5501 var start = _startValues[prop];
5502 var end = _endValues[prop];
5503 _object[prop] = start + (end - start) * delta
5504 }
5505 }
5506 if (_update) _update(delta);
5507 if (_elapsed == 1) {
5508 if (_callback) _callback();
5509 clear()
5510 }
5511 }
5512
5513 function updateStack(time) {
5514 var v = _currentValues;
5515 if (!v.elapsed) {
5516 v.elapsed = 0;
5517 v.timer = 0
5518 }
5519 v.timer += Render.DELTA;
5520 v.elapsed = v.timer / v.time;
5521 if (v.elapsed < 1) {
5522 for (var prop in v.start) {
5523 _object[prop] = TweenManager.interpolateValues(v.start[prop], v.end[prop], v.elapsed, v.ease)
5524 }
5525 if (_update) _update(v.elapsed)
5526 } else {
5527 _currentValues = _stack.shift();
5528 if (!_currentValues) {
5529 if (_callback) _callback();
5530 clear()
5531 }
5532 }
5533 }
5534 this.update = function(time) {
5535 if (_paused || time < _startTime) return;
5536 if (_stack) updateStack(time);
5537 else updateSingle(time)
5538 };
5539 this.pause = function() {
5540 _paused = true
5541 };
5542 this.resume = function() {
5543 _paused = false;
5544 _startTime = Date.now() - _elapsed * _time
5545 };
5546 this.stop = function() {
5547 _this.stopped = true;
5548 clear();
5549 return null
5550 };
5551 this.setEase = function(ease) {
5552 if (_newEase != ease) {
5553 _newEase = ease;
5554 _ease = TweenManager.Interpolation.convertEase(ease);
5555 _easeFunction = typeof _ease === "function"
5556 }
5557 };
5558 this.getValues = function() {
5559 return {
5560 start: _startValues,
5561 end: _endValues
5562 }
5563 };
5564 this.interpolate = function(elapsed) {
5565 var delta = _easeFunction ? _ease(elapsed) : TweenManager.Interpolation.solve(_ease, elapsed);
5566 for (var prop in _startValues) {
5567 if (typeof _startValues[prop] === "number" && typeof _endValues[prop] === "number") {
5568 var start = _startValues[prop];
5569 var end = _endValues[prop];
5570 _object[prop] = start + (end - start) * delta
5571 }
5572 }
5573 }
5574});
5575Class(function SpringTween(_object, _props, _friction, _ease, _delay, _update, _callback) {
5576 var _this = this;
5577 var _startTime, _velocityValues, _endValues, _startValues;
5578 var _damping, _friction, _count, _paused;
5579 (function() {
5580 if (_object && _props) {
5581 if (typeof _friction !== "number") throw "SpringTween Requires object, props, time, ease";
5582 start()
5583 }
5584 }());
5585
5586 function start() {
5587 TweenManager.clearTween(_object);
5588 _object._mathTween = _this;
5589 TweenManager._addMathTween(_this);
5590 _startTime = Date.now();
5591 _startTime += _delay;
5592 _endValues = {};
5593 _startValues = {};
5594 _velocityValues = {};
5595 if (_props.x || _props.y || _props.z) {
5596 if (typeof _props.x === "undefined") _props.x = _object.x;
5597 if (typeof _props.y === "undefined") _props.y = _object.y;
5598 if (typeof _props.z === "undefined") _props.z = _object.z
5599 }
5600 _count = 0;
5601 _damping = _props.damping || .5;
5602 delete _props.damping;
5603 for (var prop in _props) {
5604 if (typeof _props[prop] === "number") {
5605 _velocityValues[prop] = 0;
5606 _endValues[prop] = _props[prop]
5607 }
5608 }
5609 for (prop in _props) {
5610 if (typeof _object[prop] === "number") {
5611 _startValues[prop] = _object[prop] || 0;
5612 _props[prop] = _startValues[prop]
5613 }
5614 }
5615 }
5616
5617 function clear(stop) {
5618 if (_object) {
5619 _object._mathTween = null;
5620 if (!stop) {
5621 for (var prop in _endValues) {
5622 if (typeof _endValues[prop] === "number") _object[prop] = _endValues[prop]
5623 }
5624 if (_object.transform) _object.transform()
5625 }
5626 }
5627 TweenManager._removeMathTween(_this)
5628 }
5629 this.update = function(time) {
5630 if (time < _startTime || _paused) return;
5631 var vel;
5632 for (var prop in _startValues) {
5633 if (typeof _startValues[prop] === "number") {
5634 var start = _startValues[prop];
5635 var end = _endValues[prop];
5636 var val = _props[prop];
5637 var d = end - val;
5638 var a = d * _damping;
5639 _velocityValues[prop] += a;
5640 _velocityValues[prop] *= _friction;
5641 _props[prop] += _velocityValues[prop];
5642 _object[prop] = _props[prop];
5643 vel = _velocityValues[prop]
5644 }
5645 }
5646 if (Math.abs(vel) < .1) {
5647 _count++;
5648 if (_count > 30) {
5649 if (_callback) _callback.apply(_object);
5650 clear()
5651 }
5652 }
5653 if (_update) _update(time);
5654 if (_object.transform) _object.transform()
5655 };
5656 this.pause = function() {
5657 _paused = true
5658 };
5659 this.stop = function() {
5660 clear(true);
5661 return null
5662 }
5663});
5664Class(function TweenTimeline() {
5665 Inherit(this, Component);
5666 var _this = this;
5667 var _tween;
5668 var _total = 0;
5669 var _tweens = [];
5670 var _fallbacks = [];
5671 this.elapsed = 0;
5672 (function() {}());
5673
5674 function calculate() {
5675 _tweens.sort(function(a, b) {
5676 var ta = a.time + a.delay;
5677 var tb = b.time + b.delay;
5678 return tb - ta
5679 });
5680 var first = _tweens[0];
5681 _total = first.time + first.delay
5682 }
5683
5684 function loop() {
5685 var time = _this.elapsed * _total;
5686 for (var i = _tweens.length - 1; i > -1; i--) {
5687 var t = _tweens[i];
5688 var relativeTime = time - t.delay;
5689 var elapsed = Utils.clamp(relativeTime / t.time, 0, 1);
5690 t.interpolate(elapsed)
5691 }
5692 if (_this.onUpdate) _this.onUpdate(_this.elapsed)
5693 }
5694 this.add = function(object, props, time, ease, delay) {
5695 var tween;
5696 if (object instanceof HydraObject) tween = new FrameTween(object, props, time, ease, delay, null, true);
5697 else tween = new MathTween(object, props, time, ease, delay, null, null, true);
5698 _tweens.push(tween);
5699 _fallbacks.push({
5700 object: object,
5701 props: props,
5702 time: time,
5703 ease: ease,
5704 delay: delay
5705 });
5706 tween.time = time;
5707 tween.delay = delay || 0;
5708 calculate();
5709 return tween
5710 };
5711 this.tween = function(to, time, ease, delay, callback) {
5712 this.stopTween();
5713 _tween = TweenManager.tween(_this, {
5714 elapsed: to
5715 }, time, ease, delay, callback, loop)
5716 };
5717 this.stopTween = function() {
5718 if (_tween && _tween.stop) _tween.stop()
5719 };
5720 this.startRender = function() {
5721 Render.startRender(loop)
5722 };
5723 this.stopRender = function() {
5724 Render.stopRender(loop)
5725 };
5726 this.update = function() {
5727 loop()
5728 };
5729 this.calculateRemainingTime = function() {
5730 return _total - _this.elapsed * _total
5731 };
5732 this.fallback = function(dir) {
5733 _fallbacks.forEach(function(config, index) {
5734 var fTween = _tweens[index].getValues();
5735 var props = null;
5736 if (config.object instanceof HydraObject) {
5737 if (dir == 1) props = Utils.mergeObject(fTween.end, fTween.transformEnd);
5738 else props = Utils.mergeObject(fTween.start, fTween.transformStart);
5739 for (var key in props) {
5740 if (typeof props[key] != "number") delete props[key]
5741 }
5742 config.object.tween(props, config.time, config.ease, config.delay)
5743 } else {
5744 if (dir == 1) props = Utils.mergeObject(fTween.end);
5745 else props = Utils.mergeObject(fTween.start);
5746 for (var key in props) {
5747 if (typeof props[key] != "number") delete props[key]
5748 }
5749 TweenManager.tween(config.object, props, config.time, config.ease, config.delay)
5750 }
5751 })
5752 };
5753 this.destroy = function() {
5754 Render.stopRender(loop);
5755 for (var i = 0; i < _tweens.length; i++) _tweens[i].stop();
5756 return this._destroy()
5757 }
5758});
5759Class(function Shaders() {
5760 Inherit(this, MVC);
5761 var _this = this;
5762 (function() {}());
5763
5764 function parseCompiled(shaders) {
5765 var split = shaders.split("{@}");
5766 split.shift();
5767 for (var i = 0; i < split.length; i += 2) {
5768 var name = split[i];
5769 var text = split[i + 1];
5770 _this[name] = text
5771 }
5772 }
5773
5774 function parseRequirements() {
5775 for (var key in _this) {
5776 var obj = _this[key];
5777 if (typeof obj === "string") {
5778 _this[key] = require(obj)
5779 }
5780 }
5781 }
5782
5783 function require(shader) {
5784 if (!shader.strpos("require")) return shader;
5785 shader = shader.replace(/# require/g, "#require");
5786 while (shader.strpos("#require")) {
5787 var split = shader.split("#require(");
5788 var name = split[1].split(")")[0];
5789 name = name.replace(/ /g, "");
5790 if (!_this[name]) throw "Shader required " + name + ", but not found in compiled shaders.\n" + shader;
5791 shader = shader.replace("#require(" + name + ")", _this[name])
5792 }
5793 return shader
5794 }
5795 this.parse = function(code, file) {
5796 if (!code.strpos("{@}")) {
5797 file = file.split("/");
5798 file = file[file.length - 1];
5799 _this[file] = code
5800 } else {
5801 parseCompiled(code);
5802 parseRequirements()
5803 }
5804 _this.shadersParsed = true
5805 };
5806 this.onReady = function(callback) {
5807 let promise = Promise.create();
5808 if (callback) promise.then(callback);
5809 this.wait(() => promise.resolve(), this, "shadersParsed");
5810 return promise
5811 };
5812 this.getShader = function(string) {
5813 if (_this.FALLBACKS) {
5814 if (_this.FALLBACKS[string]) {
5815 string = _this.FALLBACKS[string]
5816 }
5817 }
5818 var code = _this[string];
5819 if (code) {
5820 while (code.strpos("#test ")) {
5821 try {
5822 var test = code.split("#test ")[1];
5823 var name = test.split("\n")[0];
5824 var glsl = code.split("#test " + name + "\n")[1].split("#endtest")[0];
5825 if (!eval(name)) {
5826 code = code.replace(glsl, "")
5827 }
5828 code = code.replace("#test " + name + "\n", "");
5829 code = code.replace("#endtest", "")
5830 } catch (e) {
5831 throw "Error parsing test :: " + string
5832 }
5833 }
5834 }
5835 return code
5836 }
5837}, "static");
5838Class(function RenderPerformance() {
5839 Inherit(this, Component);
5840 var _this = this;
5841 var _time;
5842 var _times = [];
5843 var _fps = [];
5844 this.enabled = true;
5845 this.pastFrames = 60;
5846 this.time = function() {
5847 if (!this.enabled) return;
5848 if (!_time) {
5849 _time = performance.now()
5850 } else {
5851 var t = performance.now() - _time;
5852 _time = null;
5853 _times.unshift(t);
5854 if (_times.length > this.pastFrames) _times.pop();
5855 _fps.unshift(Render.FPS);
5856 if (_fps.length > this.pastFrames) _fps.pop();
5857 this.average = 0;
5858 var len = _times.length;
5859 for (var i = 0; i < len; i++) {
5860 this.average += _times[i]
5861 }
5862 this.average /= len;
5863 this.averageFPS = 0;
5864 len = _fps.length;
5865 for (i = 0; i < len; i++) {
5866 this.averageFPS += _fps[i]
5867 }
5868 this.averageFPS /= len
5869 }
5870 };
5871 this.clear = function() {
5872 _times.length = 0
5873 };
5874 this.dump = function() {
5875 console.log(_times)
5876 };
5877 this.get("times", function() {
5878 return _times
5879 });
5880 this.get("median", function() {
5881 _times.sort(function(a, b) {
5882 return a - b
5883 });
5884 return _times[~~(_times.length / 2)]
5885 })
5886});
5887Class(function Video(_params) {
5888 Inherit(this, Component);
5889 var _this = this;
5890 var _inter, _time, _lastTime, _buffering, _seekTo, _loop, _forceRender;
5891 var _tick = 0;
5892 var _event = {};
5893 this.loop = false;
5894 this.playing = false;
5895 this.loaded = {
5896 start: 0,
5897 end: 0,
5898 percent: 0
5899 };
5900 this.width = _params.width || 0;
5901 this.height = _params.height || 0;
5902 (function() {
5903 createDiv();
5904 if (_params.preload !== false) preload()
5905 }());
5906
5907 function createDiv() {
5908 var src = _params.src;
5909 if (src && !src.strpos("webm") && !src.strpos("mp4") && !src.strpos("ogv")) src += "." + Device.media.video;
5910 _this.div = document.createElement("video");
5911 if (src) _this.div.src = src;
5912 _this.div.controls = _params.controls;
5913 _this.div.id = _params.id || "";
5914 _this.div.width = _params.width;
5915 _this.div.height = _params.height;
5916 _loop = _this.div.loop = _params.loop;
5917 _this.object = $(_this.div);
5918 _this.width = _params.width;
5919 _this.height = _params.height;
5920 _this.object.size(_this.width, _this.height);
5921 if (Device.mobile) {
5922 _this.object.attr("webkit-playsinline", true);
5923 _this.object.attr("playsinline", true)
5924 }
5925 }
5926
5927 function preload() {
5928 _this.div.preload = "auto";
5929 _this.div.load()
5930 }
5931
5932 function tick() {
5933 if (!_this.div || !_this.events) return Render.stopRender(tick);
5934 _this.duration = _this.div.duration;
5935 _this.time = _this.div.currentTime;
5936 if (_this.div.currentTime == _lastTime) {
5937 _tick++;
5938 if (_tick > 30 && !_buffering) {
5939 _buffering = true;
5940 _this.events.fire(HydraEvents.ERROR, null, true)
5941 }
5942 } else {
5943 _tick = 0;
5944 if (_buffering) {
5945 _this.events.fire(HydraEvents.READY, null, true);
5946 _buffering = false
5947 }
5948 }
5949 _lastTime = _this.div.currentTime;
5950 if (_this.div.currentTime >= (_this.duration || _this.div.duration) - .001) {
5951 if (!_loop) {
5952 if (!_forceRender) Render.stopRender(tick);
5953 _this.events.fire(HydraEvents.COMPLETE, null, true)
5954 }
5955 }
5956 _event.time = _this.div.currentTime;
5957 _event.duration = _this.div.duration;
5958 _event.loaded = _this.loaded;
5959 _this.events.fire(HydraEvents.UPDATE, _event, true)
5960 }
5961
5962 function checkReady() {
5963 if (!_this.div) return false;
5964 if (!_seekTo) {
5965 _this.buffered = _this.div.readyState == _this.div.HAVE_ENOUGH_DATA
5966 } else {
5967 var max = -1;
5968 var seekable = _this.div.seekable;
5969 if (seekable) {
5970 for (var i = 0; i < seekable.length; i++) {
5971 if (seekable.start(i) < _seekTo) {
5972 max = seekable.end(i) - .5
5973 }
5974 }
5975 if (max >= _seekTo) _this.buffered = true
5976 } else {
5977 _this.buffered = true
5978 }
5979 }
5980 if (_this.buffered) {
5981 Render.stopRender(checkReady);
5982 _this.events.fire(HydraEvents.READY, null, true)
5983 }
5984 }
5985
5986 function handleProgress() {
5987 if (!_this.ready()) return;
5988 var range = 0;
5989 var bf = _this.div.buffered;
5990 var time = _this.div.currentTime;
5991 while (!(bf.start(range) <= time && time <= bf.end(range))) {
5992 range += 1
5993 }
5994 _this.loaded.start = bf.start(range) / _this.div.duration;
5995 _this.loaded.end = bf.end(range) / _this.div.duration;
5996 _this.loaded.percent = _this.loaded.end - _this.loaded.start;
5997 _this.events.fire(HydraEvents.PROGRESS, _this.loaded, true)
5998 }
5999 this.set("loop", function(bool) {
6000 if (!_this.div) return;
6001 _loop = bool;
6002 _this.div.loop = bool
6003 });
6004 this.get("loop", function() {
6005 return _loop
6006 });
6007 this.set("src", function(src) {
6008 if (src && !src.strpos("webm") && !src.strpos("mp4") && !src.strpos("ogv")) src += "." + Device.media.video;
6009 _this.div.src = src
6010 });
6011 this.get("src", function() {
6012 return _this.div.src
6013 });
6014 this.play = function() {
6015 if (!_this.div) return false;
6016 _this.playing = true;
6017 _this.div.play();
6018 Render.startRender(tick)
6019 };
6020 this.pause = function() {
6021 if (!_this.div) return false;
6022 _this.playing = false;
6023 _this.div.pause();
6024 Render.stopRender(tick)
6025 };
6026 this.stop = function() {
6027 _this.playing = false;
6028 Render.stopRender(tick);
6029 if (!_this.div) return false;
6030 _this.div.pause();
6031 if (_this.ready()) _this.div.currentTime = 0
6032 };
6033 this.volume = function(v) {
6034 if (!_this.div) return false;
6035 _this.div.volume = v;
6036 if (_this.muted) {
6037 _this.muted = false;
6038 _this.div.removeAttribute("muted")
6039 }
6040 };
6041 this.mute = function() {
6042 if (!_this.div) return false;
6043 _this.volume(0);
6044 _this.muted = true;
6045 _this.object.attr("muted", true)
6046 };
6047 this.seek = function(t) {
6048 if (!_this.div) return false;
6049 if (_this.div.readyState <= 1) {
6050 Timer.create(function() {
6051 _this.seek && _this.seek(t)
6052 }, 32);
6053 return
6054 }
6055 _this.div.currentTime = t
6056 };
6057 this.canPlayTo = function(t) {
6058 _seekTo = null;
6059 if (t) _seekTo = t;
6060 if (!_this.div) return false;
6061 if (!_this.buffered) Render.startRender(checkReady);
6062 return this.buffered
6063 };
6064 this.ready = function() {
6065 if (!_this.div) return false;
6066 return _this.div.readyState >= 2
6067 };
6068 this.size = function(w, h) {
6069 if (!_this.div) return false;
6070 this.div.width = this.width = w;
6071 this.div.height = this.height = h;
6072 this.object.css({
6073 width: w,
6074 height: h
6075 })
6076 };
6077 this.forceRender = function() {
6078 _forceRender = true;
6079 Render.startRender(tick)
6080 };
6081 this.trackProgress = function() {
6082 _this.div.addEventListener("progress", handleProgress)
6083 };
6084 this.destroy = function() {
6085 this.stop();
6086 this.object.remove();
6087 this.div.src = "";
6088 return this._destroy()
6089 };
6090 this.onReady = function() {
6091 var promise = Promise.create();
6092 let loop = function() {
6093 if (_this.ready()) {
6094 promise.resolve();
6095 Render.stop(loop)
6096 }
6097 };
6098 Render.start(loop);
6099 return promise
6100 }
6101});
6102Class(function AssetLoader(_assets, _complete) {
6103 Inherit(this, Component);
6104 var _this = this;
6105 var _total = 0;
6106 var _loaded = 0;
6107 var _added = 0;
6108 var _triggered = 0;
6109 var _queueLength = 2;
6110 var _lastTriggered = 0;
6111 var _queue, _qLoad, _currentQueue;
6112 var _output, _loadedFiles;
6113 var _id = Utils.timestamp();
6114 if (typeof _complete === "number") {
6115 _queueLength = _complete;
6116 _complete = null
6117 }(function() {
6118 _queue = {};
6119 _loadedFiles = [];
6120 prepareAssets();
6121 startLoading()
6122 }());
6123
6124 function prepareAssets() {
6125 var perQueue = _assets.length / _queueLength;
6126 var count = 0;
6127 var index = 0;
6128 for (var i = 0; i < _assets.length; i++) {
6129 if (typeof _assets[i] !== "undefined") {
6130 if (!_queue[index]) _queue[index] = [];
6131 var queue = _queue[index];
6132 _total++;
6133 count++;
6134 if (count >= perQueue) {
6135 index += 1;
6136 count = 0
6137 }
6138 queue.push(_assets[i])
6139 }
6140 }
6141 }
6142
6143 function startLoading() {
6144 _currentQueue = 0;
6145 loadQueue()
6146 }
6147
6148 function loadQueue() {
6149 var queue = _queue[_currentQueue];
6150 if (!queue) return;
6151 _qLoad = 0;
6152 for (var i = 0; i < queue.length; i++) {
6153 loadAsset(queue[i])
6154 }
6155 }
6156
6157 function checkQ() {
6158 if (!_queue) return;
6159 var queue = _queue[_currentQueue];
6160 if (!queue) return;
6161 var length = queue.length;
6162 _qLoad++;
6163 if (_qLoad == length) {
6164 _currentQueue++;
6165 loadQueue()
6166 }
6167 }
6168
6169 function missingFiles() {
6170 if (!_queue) return;
6171 var missing = [];
6172 for (var i = 0; i < _queue.length; i++) {
6173 var loaded = false;
6174 for (var j = 0; j < _loadedFiles.length; j++) {
6175 if (_loadedFiles[j] == _queue[i]) loaded = true
6176 }
6177 if (!loaded) missing.push(_queue[i])
6178 }
6179 if (missing.length) {
6180 console.log("AssetLoader Files Failed To Load:");
6181 console.log(missing)
6182 }
6183 }
6184
6185 function wrapXHR(xhr) {
6186 xhr.onError = function(e) {
6187 _this.events.fire(HydraEvents.ERROR, e)
6188 }
6189 }
6190
6191 function loadAsset(asset) {
6192 if (!asset) return;
6193 var name = asset.split("/");
6194 name = name[name.length - 1];
6195 var split = name.split(".");
6196 var ext = split[split.length - 1].split("?")[0];
6197 switch (ext) {
6198 case "html":
6199 wrapXHR(XHR.get(asset, function(contents) {
6200 Hydra.HTML[split[0]] = contents;
6201 assetLoaded(asset)
6202 }, "text"));
6203 break;
6204 case "js":
6205 case "php":
6206 case undefined:
6207 wrapXHR(XHR.get(asset, function(script) {
6208 script = script.replace("use strict", "");
6209 eval.call(window, script);
6210 assetLoaded(asset)
6211 }, "text"));
6212 break;
6213 case "fnt":
6214 case "json":
6215 wrapXHR(XHR.get(asset, function(contents) {
6216 Hydra.JSON[split[0]] = contents;
6217 assetLoaded(asset)
6218 }, ext == "fnt" ? "text" : null));
6219 break;
6220 case "svg":
6221 wrapXHR(XHR.get(asset, function(contents) {
6222 Hydra.SVG[split[0]] = contents;
6223 assetLoaded(asset)
6224 }, "text"));
6225 break;
6226 case "fs":
6227 case "vs":
6228 wrapXHR(XHR.get(asset, function(contents) {
6229 Shaders.parse(contents, asset);
6230 assetLoaded(asset)
6231 }, "text"));
6232 break;
6233 default:
6234 var image = Images.createImg(asset);
6235 if (image.complete) {
6236 assetLoaded(asset);
6237 return
6238 }
6239 image.onload = function() {
6240 assetLoaded(asset)
6241 };
6242 break
6243 }
6244 }
6245
6246 function assetLoaded(asset) {
6247 _loaded++;
6248 if (_this.events) _this.events.fire(HydraEvents.PROGRESS, {
6249 percent: _loaded / _total
6250 });
6251 _loadedFiles.push(asset);
6252 clearTimeout(_output);
6253 checkQ();
6254 if (_loaded == _total) {
6255 _this.complete = true;
6256 if (_this.events) _this.events.fire(HydraEvents.COMPLETE, null, true);
6257 if (typeof _complete === "function") _complete()
6258 } else {
6259 if (!window.THREAD && _this.delayedCall) _output = _this.delayedCall(missingFiles, 5e3)
6260 }
6261 }
6262 this.add = function(num) {
6263 _total += num;
6264 _added += num
6265 };
6266 this.trigger = function(num) {
6267 num = num || 1;
6268 for (var i = 0; i < num; i++) assetLoaded("trigger")
6269 };
6270 this.triggerPercent = function(percent, num) {
6271 num = num || _added;
6272 var trigger = Math.ceil(num * percent);
6273 if (trigger > _lastTriggered) this.trigger(trigger - _lastTriggered);
6274 _lastTriggered = trigger
6275 };
6276 this.destroy = function() {
6277 _assets = null;
6278 _loaded = null;
6279 _queue = null;
6280 _qLoad = null;
6281 return this._destroy && this._destroy()
6282 }
6283}, function() {
6284 AssetLoader.loadAllAssets = function(callback, cdn) {
6285 let promise = Promise.create();
6286 if (!callback) callback = promise.resolve;
6287 cdn = cdn || "";
6288 var list = [];
6289 for (var i = 0; i < ASSETS.length; i++) {
6290 list.push(cdn + ASSETS[i])
6291 }
6292 var assets = new AssetLoader(list, function() {
6293 if (callback) callback();
6294 if (assets && assets.destroy) assets = assets.destroy()
6295 });
6296 return promise
6297 };
6298 AssetLoader.loadAssets = function(list, callback) {
6299 let promise = Promise.create();
6300 if (!callback) callback = promise.resolve;
6301 var assets = new AssetLoader(list, function() {
6302 if (callback) callback();
6303 if (assets && assets.destroy) assets = assets.destroy()
6304 });
6305 return promise
6306 };
6307 AssetLoader.waitForLib = function(name, callback) {
6308 let promise = Promise.create();
6309 if (!callback) callback = promise.resolve;
6310 var interval = setInterval(function() {
6311 if (window[name]) {
6312 clearInterval(interval);
6313 callback && callback();
6314 interval = callback = null
6315 }
6316 }, 100);
6317 return promise
6318 }
6319});
6320Class(function AssetUtil() {
6321 var _this = this;
6322 var _assets = {};
6323 var _exclude = ["!!!"];
6324 this.PATH = "";
6325
6326 function canInclude(asset, match) {
6327 for (var i = 0; i < _exclude.length; i++) {
6328 var excl = _exclude[i];
6329 if (asset.strpos(excl) && match != excl) return false
6330 }
6331 return true
6332 }
6333 this.getAssets = this.loadAssets = function(list) {
6334 if (Hydra.CDN && !_this.PATH.length) _this.PATH = Hydra.CDN;
6335 var assets = this.get(list);
6336 var output = [];
6337 for (var i = assets.length - 1; i > -1; i--) {
6338 var asset = assets[i];
6339 if (!_assets[asset]) {
6340 output.push(asset.strpos("http") ? asset : _this.PATH + asset);
6341 _assets[asset] = 1
6342 }
6343 }
6344 return output
6345 };
6346 this.get = function(list) {
6347 if (!Array.isArray(list)) list = [list];
6348 var assets = [];
6349 for (var i = ASSETS.length - 1; i > -1; i--) {
6350 var asset = ASSETS[i];
6351 for (var j = list.length - 1; j > -1; j--) {
6352 var match = list[j];
6353 if (asset.strpos(match)) {
6354 if (canInclude(asset, match)) assets.push(asset)
6355 }
6356 }
6357 }
6358 return assets
6359 };
6360 this.exclude = function(list) {
6361 if (!Array.isArray(list)) list = [list];
6362 for (var i = 0; i < list.length; i++) _exclude.push(list[i])
6363 };
6364 this.removeExclude = function(list) {
6365 if (!Array.isArray(list)) list = [list];
6366 for (var i = 0; i < list.length; i++) _exclude.findAndRemove(list[i])
6367 };
6368 this.loadAllAssets = this.getAllAssets = function(list) {
6369 var assets = _this.loadAssets(list || "/");
6370 var loader = new AssetLoader(assets)
6371 };
6372 this.exists = function(match) {
6373 for (var i = ASSETS.length - 1; i > -1; i--) {
6374 var asset = ASSETS[i];
6375 if (asset.strpos(match)) return true
6376 }
6377 return false
6378 };
6379 this.prependPath = function(path, files) {
6380 if (!Array.isArray(files)) files = [files];
6381 for (var i = ASSETS.length - 1; i > -1; i--) {
6382 var asset = ASSETS[i];
6383 files.forEach(function(file) {
6384 if (asset.strpos(file)) ASSETS[i] = path + asset
6385 })
6386 }
6387 }
6388}, "Static");
6389Class(function Images() {
6390 var _this = this;
6391 this.inMemory = false;
6392 this.store = {};
6393 this.useCORS = false;
6394
6395 function parseResolution(path) {
6396 if (!ASSETS.RES) return path;
6397 var res = ASSETS.RES[path];
6398 var ratio = Math.min(Device.pixelRatio, 3);
6399 if (res) {
6400 if (res["x" + ratio]) {
6401 var split = path.split("/");
6402 var file = split[split.length - 1];
6403 split = file.split(".");
6404 return path.replace(file, split[0] + "-" + ratio + "x." + split[1])
6405 } else {
6406 return path
6407 }
6408 } else {
6409 return path
6410 }
6411 }
6412 this.getPath = function(path) {
6413 if (path.strpos("http")) return path;
6414 path = parseResolution(path);
6415 return (Hydra.CDN || "") + path
6416 };
6417 this.createImg = function(path) {
6418 var cors = _this.useCORS;
6419 if (!path.strpos("http")) {
6420 path = parseResolution(path);
6421 path = (Hydra.CDN || "") + path
6422 }
6423 var img = new Image;
6424 if (cors) img.crossOrigin = "";
6425 img.src = path;
6426 if (this.store) this.storeImg(img);
6427 return img
6428 };
6429 this.storeImg = function(img) {
6430 if (this.inMemory) this.store[img.src] = img
6431 };
6432 this.releaseImg = function(path) {
6433 path = path.src ? path.src : path;
6434 delete this.store[path]
6435 }
6436}, "static");
6437Class(function XHR() {
6438 var _this = this;
6439 var _serial;
6440 var _android = window.location.href.strpos("file://");
6441 this.headers = {};
6442 this.options = {};
6443
6444 function serialize(key, data) {
6445 if (typeof data === "object") {
6446 for (var i in data) {
6447 var newKey = key + "[" + i + "]";
6448 if (typeof data[i] === "object") serialize(newKey, data[i]);
6449 else _serial.push(newKey + "=" + data[i])
6450 }
6451 } else {
6452 _serial.push(key + "=" + data)
6453 }
6454 }
6455 this.get = function(url, data, callback, type) {
6456 if (typeof data === "function") {
6457 type = callback;
6458 callback = data;
6459 data = null
6460 } else if (typeof data === "object") {
6461 var string = "?";
6462 for (var key in data) {
6463 string += key + "=" + data[key] + "&"
6464 }
6465 string = string.slice(0, -1);
6466 url += string
6467 }
6468 var xhr = new XMLHttpRequest;
6469 xhr.open("GET", url, true);
6470 if (type == "text") xhr.overrideMimeType("text/plain");
6471 if (type == "json") xhr.setRequestHeader("Accept", "application/json");
6472 for (var key in _this.headers) {
6473 xhr.setRequestHeader(key, _this.headers[key])
6474 }
6475 for (var key in _this.options) {
6476 xhr[key] = _this.options[key]
6477 }
6478 var promise = Promise.create();
6479 callback = callback || promise.resolve;
6480 xhr.send();
6481 xhr.onreadystatechange = function() {
6482 if (xhr.readyState == 4 && (_android || xhr.status == 200)) {
6483 if (typeof callback === "function") {
6484 var data = xhr.responseText;
6485 if (type == "text") {
6486 callback(data)
6487 } else {
6488 try {
6489 callback(JSON.parse(data))
6490 } catch (e) {
6491 throw e
6492 }
6493 }
6494 }
6495 }
6496 if (xhr.status == 0 || xhr.status == 401 || xhr.status == 404 || xhr.status == 500) promise.reject(xhr.status + " " + xhr.responseText)
6497 };
6498 return promise
6499 };
6500 this.post = function(url, data, callback, type, header) {
6501 if (typeof data === "function") {
6502 header = type;
6503 type = callback;
6504 callback = data;
6505 data = null
6506 } else if (typeof data === "object") {
6507 if (callback == "json" || type == "json" || header == "json") {
6508 data = JSON.stringify(data);
6509 header = "json"
6510 } else {
6511 _serial = new Array;
6512 for (var key in data) serialize(key, data[key]);
6513 data = _serial.join("&");
6514 data = data.replace(/\[/g, "%5B");
6515 data = data.replace(/\]/g, "%5D");
6516 _serial = null
6517 }
6518 }
6519 var xhr = new XMLHttpRequest;
6520 xhr.open("POST", url, true);
6521 if (type == "text") xhr.overrideMimeType("text/plain");
6522 if (type == "json") xhr.setRequestHeader("Accept", "application/json");
6523 switch (header) {
6524 case "upload":
6525 header = "application/upload";
6526 break;
6527 case "json":
6528 header = "application/json";
6529 break;
6530 default:
6531 header = "application/x-www-form-urlencoded";
6532 break
6533 }
6534 xhr.setRequestHeader("Content-type", header);
6535 for (var key in _this.headers) {
6536 xhr.setRequestHeader(key, _this.headers[key])
6537 }
6538 for (var key in _this.options) {
6539 xhr[key] = _this.options[key]
6540 }
6541 var promise = Promise.create();
6542 callback = callback || promise.resolve;
6543 xhr.onreadystatechange = function() {
6544 if (xhr.readyState == 4 && (_android || xhr.status == 200)) {
6545 if (typeof callback === "function") {
6546 var data = xhr.responseText;
6547 if (type == "text") {
6548 callback(data)
6549 } else {
6550 try {
6551 callback(JSON.parse(data))
6552 } catch (e) {
6553 throw e
6554 }
6555 }
6556 }
6557 }
6558 if (xhr.status == 0 || xhr.status == 401 || xhr.status == 404 || xhr.status == 500) promise.reject(xhr.status + " " + xhr.responseText)
6559 };
6560 xhr.send(data);
6561 return promise
6562 }
6563}, "Static");
6564Class(function Storage() {
6565 var _this = this;
6566 var _storage;
6567 (function() {
6568 testStorage()
6569 }());
6570
6571 function testStorage() {
6572 try {
6573 if (window.localStorage) {
6574 try {
6575 window.localStorage["test"] = 1;
6576 window.localStorage.removeItem("test");
6577 _storage = true
6578 } catch (e) {
6579 _storage = false
6580 }
6581 } else {
6582 _storage = false
6583 }
6584 } catch (e) {
6585 _storage = false
6586 }
6587 }
6588
6589 function cookie(key, value, expires) {
6590 var options;
6591 if (arguments.length > 1 && (value === null || typeof value !== "object")) {
6592 options = {};
6593 options.path = "/";
6594 options.expires = expires || 1;
6595 if (value === null) {
6596 options.expires = -1
6597 }
6598 if (typeof options.expires === "number") {
6599 var days = options.expires,
6600 t = options.expires = new Date;
6601 t.setDate(t.getDate() + days)
6602 }
6603 return document.cookie = [encodeURIComponent(key), "=", options.raw ? String(value) : encodeURIComponent(String(value)), options.expires ? "; expires=" + options.expires.toUTCString() : "", options.path ? "; path=" + options.path : "", options.domain ? "; domain=" + options.domain : "", options.secure ? "; secure" : ""].join("")
6604 }
6605 options = value || {};
6606 var result, decode = options.raw ? function(s) {
6607 return s
6608 } : decodeURIComponent;
6609 return (result = new RegExp("(?:^|; )" + encodeURIComponent(key) + "=([^;]*)").exec(document.cookie)) ? decode(result[1]) : null
6610 }
6611 this.setCookie = function(key, value, expires) {
6612 cookie(key, value, expires)
6613 };
6614 this.getCookie = function(key) {
6615 return cookie(key)
6616 };
6617 this.set = function(key, value) {
6618 if (value != null && typeof value === "object") value = JSON.stringify(value);
6619 if (_storage) {
6620 if (value === null) window.localStorage.removeItem(key);
6621 else window.localStorage[key] = value
6622 } else {
6623 cookie(key, value, 365)
6624 }
6625 };
6626 this.get = function(key) {
6627 var val;
6628 if (_storage) val = window.localStorage[key];
6629 else val = cookie(key);
6630 if (val) {
6631 var char0;
6632 if (val.charAt) char0 = val.charAt(0);
6633 if (char0 == "{" || char0 == "[") val = JSON.parse(val);
6634 if (val == "true" || val == "false") val = val == "true" ? true : false
6635 }
6636 return val
6637 }
6638}, "Static");
6639Class(function Dev() {
6640 var _this = this;
6641 var _post, _alert;
6642 var _id = Utils.timestamp();
6643 (function() {
6644 if (Hydra.LOCAL) Hydra.development(true)
6645 }());
6646
6647 function catchErrors() {
6648 window.onerror = function(message, file, line) {
6649 var string = message + " ::: " + file + " : " + line;
6650 if (_alert) alert(string);
6651 if (_post) XHR.post(_post + "/api/data/debug", getDebugInfo(string));
6652 if (_this.onError) _this.onError(message, file, line)
6653 }
6654 }
6655
6656 function getDebugInfo(string) {
6657 var obj = {};
6658 obj.time = (new Date).toString();
6659 obj.deviceId = _id;
6660 obj.err = string;
6661 obj.ua = Device.agent;
6662 obj.width = Stage.width;
6663 obj.height = Stage.height;
6664 obj.screenWidth = screen.width;
6665 obj.screenHeight = screen.height;
6666 return obj
6667 }
6668 this.alertErrors = function(url) {
6669 _alert = true;
6670 if (typeof url === "string") url = [url];
6671 for (var i = 0; i < url.length; i++) {
6672 if (location.href.strpos(url[i]) || location.hash.strpos(url[i])) return catchErrors()
6673 }
6674 };
6675 this.postErrors = function(url, post) {
6676 _post = post;
6677 if (typeof url === "string") url = [url];
6678 for (var i = 0; i < url.length; i++) {
6679 if (location.href.strpos(url[i])) return catchErrors()
6680 }
6681 };
6682 this.expose = function(name, val, force) {
6683 if (Hydra.LOCAL || force) window[name] = val
6684 };
6685 this.logServer = function(msg) {
6686 if (_post) XHR.post(_post + "/api/data/debug", getDebugInfo(msg))
6687 };
6688 this.unsupported = function(needsAlert) {
6689 if (needsAlert) alert("Hi! This build is not yet ready for this device, things may not work as expected. Refer to build schedule for when this device will be supported.")
6690 }
6691}, "Static");
6692window.ASSETS = ["assets/images/background/dust.jpg", "assets/images/common/noise.jpg", "assets/images/common/pattern1.jpg", "assets/images/common/pattern2.jpg", "assets/images/common/pattern3.jpg", "assets/images/fallback/bg.jpg", "assets/images/fonts/gotham-light.fnt", "assets/images/fonts/gotham-light.png", "assets/images/intro/logo.jpg", "assets/images/intro/triangles.jpg", "assets/images/landscape/mountain-height.jpg", "assets/images/landscape/mountain-normal.jpg", "assets/images/schedule/big-o.jpg", "assets/images/schedule/cowboy-bebop.jpg", "assets/images/schedule/dragon-ball-super.jpg", "assets/images/schedule/dragon-ball-z-kai.jpg", "assets/images/schedule/ghost-in-the-shell.jpg", "assets/images/schedule/hunter-x-hunter.jpg", "assets/images/schedule/jojos-bizarre-adventure.jpg", "assets/images/schedule/mobile-suit-gundam-iron-blooded-orphans.jpg", "assets/images/schedule/mobile-suit-gundam-unicorn.jpg", "assets/images/schedule/naruto-shippuden.jpg", "assets/images/schedule/one-piece.jpg", "assets/images/schedule/one-punch-man.jpg", "assets/images/schedule/parasyte.jpg", "assets/images/schedule/samurai-champloo.jpg", "assets/images/schedule/samurai-jack.jpg", "assets/images/schedule/scavengers.jpg", "assets/images/schedule/space-dandy.jpg", "assets/images/schedule/the-children-who-chase-lost-voices.jpg", "assets/images/ui/close/close.png", "assets/images/ui/close/fill.png", "assets/images/ui/close/outline.png", "assets/images/ui/down-black.png", "assets/images/ui/down-white.png", "assets/images/ui/download.png", "assets/images/ui/logo-mobile.png", "assets/images/ui/logo.png", "assets/images/ui/mute.png", "assets/images/ui/pause.png", "assets/images/ui/play.png", "assets/images/ui/share/fb.png", "assets/images/ui/share/tw.png", "assets/images/ui/unmute.png", "assets/images/vfx/dust-overlay.jpg", "assets/images/vfx/logo.jpg", "assets/images/vfx/titles-sprite.jpg", "assets/js/lib/howler.js", "assets/js/lib/three.min.js", "assets/shaders/compiled.vs"];
6693ASSETS.SW = ["assets/fonts/GothamRnd-Bold.eot", "assets/fonts/GothamRnd-Bold.svg", "assets/fonts/GothamRnd-Bold.ttf", "assets/fonts/GothamRnd-Bold.woff", "assets/fonts/GothamRnd-Book.eot", "assets/fonts/GothamRnd-Book.svg", "assets/fonts/GothamRnd-Book.ttf", "assets/fonts/GothamRnd-Book.woff", "assets/fonts/GothamRnd-Light.eot", "assets/fonts/GothamRnd-Light.svg", "assets/fonts/GothamRnd-Light.ttf", "assets/fonts/GothamRnd-Light.woff", "assets/css/fallback.css", "assets/css/style.css", "assets/js/app.js"];
6694Class(function Config() {
6695 var _this = this;
6696 this.CDN = function() {
6697 if (window._CDN_) return window._CDN_;
6698 return ""
6699 }();
6700 this.API = function() {
6701 let DATA = "http://adultswim-streaming-toonami-api.prod.services.ec2.dmtio.net:3000/v1/all";
6702 if (location.hostname.indexOf("stage") > -1) {
6703 DATA = "http://adultswim-streaming-toonami-api.dev.services.ec2.dmtio.net:3000/v1/all"
6704 }
6705 let ENDPOINT;
6706 if (Hydra.LOCAL) ENDPOINT = "https://toonami-prod.s3.amazonaws.com/";
6707 else ENDPOINT = _this.CDN;
6708 return {
6709 data: DATA + "?" + Date.now(),
6710 tumblr: ENDPOINT + "tumblr.json?" + Date.now(),
6711 videos: ENDPOINT + "videos.json?" + Date.now(),
6712 share: "https://toonami-prod.s3.amazonaws.com/assets/share/share.jpg"
6713 }
6714 }();
6715 this.GRADIENT = ["#a9eeaa", "#7ee3c3", "#96eaf2", "#83bdf8"];
6716 this.BG_COLORS = [
6717 ["#00000f", "#000919", "#011c21", "#022121"],
6718 ["#00000f", "#000919", "#011c21", "#022121"],
6719 ["#00000f", "#000919", "#011621", "#021721"],
6720 ["#00000f", "#000919", "#010e21", "#05101d"]
6721 ];
6722 this.LINE_COLORS = [
6723 ["#77e992", "#589545", "#37a05d", "#0f925c", "#114f2a"],
6724 ["#77e9b9", "#53b36e", "#37a05d", "#006f69", "#084c34"],
6725 ["#37a097", "#6fe5f6", "#bdfff2", "#3cc8c0", "#88fff5"],
6726 ["#7dbcda", "#51b0f3", "#9bcfff", "#a4e3f3", "#8fb4e7"]
6727 ];
6728 this.CLOSEST_SECTION = 0
6729}, "static");
6730Class(function ToonamiEvents() {
6731 this.THREE_LOADED = "three_loaded";
6732 this.LIGHTBOX_OPEN = "lightbox_open";
6733 this.LIGHTBOX_CLOSE = "lightbox_close";
6734 this.INTRO_FINISHED = "intro_finished"
6735}, "static");
6736Class(function Cursor() {
6737 Inherit(this, Component);
6738 var _this = this;
6739 (function() {
6740 Hydra.ready(init)
6741 }());
6742
6743 function init() {
6744 _this.startRender(loop)
6745 }
6746
6747 function loop() {
6748 if (_this.isPointer) {
6749 Stage.div.style.cursor = "pointer"
6750 } else if (_this.isNone) {
6751 Stage.div.style.cursor = "none"
6752 } else {
6753 Stage.div.style.cursor = "auto"
6754 }
6755 _this.isPointer = false;
6756 _this.isNone = false
6757 }
6758 this.pointer = () => {
6759 _this.isPointer = true
6760 };
6761 this.none = () => {
6762 _this.isNone = true
6763 }
6764}, "static");
6765Class(function GPU() {
6766 Inherit(this, MVC);
6767 var _this = this;
6768 var _split = {};
6769 Timer.create(() => {
6770 _this.detect = function(match) {
6771 if (!Device.graphics.webgl) return;
6772 return Device.graphics.webgl.detect(match)
6773 };
6774 _this.detectAll = function() {
6775 if (!Device.graphics.webgl) return;
6776 var match = true;
6777 for (var i = 0; i < arguments.length; i++) {
6778 if (!Device.graphics.webgl.detect(arguments[i])) match = false
6779 }
6780 return match
6781 };
6782 _this.gpu = Device.graphics.webgl ? Device.graphics.webgl.gpu : "";
6783
6784 function splitGPU(string) {
6785 if (_split[string]) return _split[string];
6786 if (!_this.detect(string)) return -1;
6787 try {
6788 var num = Number(_this.gpu.split(string)[1].split(" ")[0]);
6789 _split[string] = num;
6790 return num
6791 } catch (e) {
6792 return -1
6793 }
6794 }
6795 Mobile.iOS = require("iOSDevices").find();
6796 _this.BLACKLIST = require("GPUBlacklist").match();
6797 _this.T0 = function() {
6798 if (Device.mobile) return false;
6799 if (_this.BLACKLIST) return true;
6800 if (_this.detectAll("intel", "hd")) {
6801 var intel = splitGPU("hd graphics ");
6802 if (intel == 0) return true;
6803 if (intel > -1) return intel > 1e3 && intel < 4e3
6804 }
6805 return false
6806 }();
6807 _this.T1 = function() {
6808 if (Device.mobile) return false;
6809 if (_this.T0) return false;
6810 if (!_this.detect(["nvidia", "amd"])) return true;
6811 return false
6812 }();
6813 _this.T2 = function() {
6814 if (Device.mobile) return false;
6815 if (_this.T0) return false;
6816 if (_this.detect(["nvidia", "amd"])) return true;
6817 return false
6818 }();
6819 _this.T3 = function() {
6820 if (Device.mobile) return false;
6821 if (_this.detect(["titan"])) return true;
6822 return false
6823 }();
6824 _this.MT0 = function() {
6825 if (!Device.mobile) return false;
6826 if (Mobile.iOS.strpos(["legacy", "ipad mini 1", "5x", "ipad 4"])) return true;
6827 var adreno = splitGPU("adreno (tm) ");
6828 if (adreno > -1) {
6829 return adreno <= 330
6830 }
6831 var mali = splitGPU("mali-t");
6832 if (mali > -1) {
6833 return mali < 628
6834 }
6835 return false
6836 }();
6837 _this.MT1 = function() {
6838 if (!Device.mobile) return false;
6839 if (Mobile.iOS.strpos(["5s", "ipad air 1"])) return true;
6840 if (Mobile.os == "Android" && !_this.MT0) return true;
6841 return false
6842 }();
6843 _this.MT2 = function() {
6844 if (!Device.mobile) return false;
6845 if (Mobile.iOS.strpos(["6x", "ipad air 2"])) return true;
6846 var adreno = splitGPU("adreno (tm) ");
6847 if (adreno > -1 && Mobile.os == "Android" && Mobile.browserVersion >= 53) {
6848 return adreno > 400
6849 }
6850 return false
6851 }();
6852 _this.MT3 = function() {
6853 if (!Device.mobile) return false;
6854 if (Mobile.iOS.strpos(["6s", "ipad pro", "7x"])) return true;
6855 if (_this.detect("nvidia tegra") && Device.detect("pixel c")) {
6856 _this.MT1 = false;
6857 _this.MT2 = false;
6858 _this.MT0 = false;
6859 return true
6860 }
6861 return false
6862 }();
6863 _this.lt = function(num) {
6864 if (_this.TIER > -1) {
6865 return _this.TIER <= num
6866 }
6867 return false
6868 };
6869 _this.gt = function(num) {
6870 if (_this.TIER > -1) {
6871 return _this.TIER >= num
6872 }
6873 return false
6874 };
6875 _this.eq = function(num) {
6876 if (_this.TIER > -1) {
6877 return _this.TIER == num
6878 }
6879 return false
6880 };
6881 _this.mobileEq = function(num) {
6882 if (_this.M_TIER > -1) {
6883 return _this.M_TIER == num
6884 }
6885 return false
6886 };
6887 _this.mobileLT = function(num) {
6888 if (_this.M_TIER > -1) {
6889 return _this.M_TIER <= num
6890 }
6891 return false
6892 };
6893 _this.mobileGT = function(num) {
6894 if (_this.M_TIER > -1) {
6895 return _this.M_TIER >= num
6896 }
6897 return false
6898 };
6899 for (var key in _this) {
6900 if (key.charAt(0) == "T" && _this[key] === true) _this.TIER = Number(key.charAt(1));
6901 if (key.slice(0, 2) == "MT" && _this[key] === true) _this.M_TIER = Number(key.charAt(2))
6902 }
6903 _this.OVERSIZED = !Device.mobile && _this.TIER < 2 && Math.max(window.innerWidth, window.innerHeight) > 144e1;
6904 _this.initialized = true
6905 }, 100);
6906 this.ready = function() {
6907 let promise = Promise.create();
6908 _this.wait(() => promise.resolve(), _this, "initialized");
6909 return promise
6910 }
6911}, "static");
6912Module(function GPUBlacklist() {
6913 this.exports = {
6914 match: function() {
6915 if (!Device.graphics.webgl) return true;
6916 return Device.graphics.webgl.detect(["radeon hd 6490m", "radeon hd 6630m", "radeon hd 5750", "radeon hd 5670", "radeon hd 4850", "radeon hd 4870", "radeon hd 4670", "geforce 9400m", "geforce 320m", "geforce 330m", "geforce gt 130", "geforce gt 120", "geforce gtx 285", "geforce 8600", "geforce 9600m", "geforce 9400m", "geforce 8800 gs", "geforce 8800 gt", "quadro fx 5", "quadro fx 4", "radeon hd 2600", "radeon hd 2400", "radeon hd 2600", "radeon r9 200", "mali-4", "mali-3", "mali-2"])
6917 }
6918 }
6919});
6920Class(function Lighting() {
6921 Inherit(this, Component);
6922 var _this = this;
6923 var _particleDepthShader;
6924 var _lights = [];
6925 (function() {}());
6926
6927 function loop() {
6928 decomposeLights(_lights)
6929 }
6930
6931 function decomposeLights(lights) {
6932 for (var i = lights.length - 1; i > -1; i--) {
6933 var light = lights[i];
6934 if (!light.parent) light.updateMatrixWorld();
6935 else if (!light.parent.parent) light.parent.updateMatrixWorld();
6936 if (!light._world) light._world = new THREE.Vector3;
6937 light.getWorldPosition(light._world)
6938 }
6939 }
6940
6941 function updateArrays(shader) {
6942 var lights = shader.lights;
6943 var lighting = shader.__lighting;
6944 var light;
6945 lighting.position.length = 0;
6946 lighting.color.length = 0;
6947 lighting.intensity.length = 0;
6948 lighting.distance.length = 0;
6949 for (var i = 0; i < lights.length; i++) {
6950 light = lights[i];
6951 lighting.position.push(light._world);
6952 lighting.color.push(light.color.r, light.color.g, light.color.b);
6953 lighting.intensity.push(light.intensity);
6954 lighting.distance.push(light.distance)
6955 }
6956 for (i = 0; i < _lights.length; i++) {
6957 light = _lights[i];
6958 lighting.position.push(light._world);
6959 lighting.color.push(light.color.r, light.color.g, light.color.b);
6960 lighting.intensity.push(light.intensity);
6961 lighting.distance.push(light.distance)
6962 }
6963 }
6964 this.add = function(light) {
6965 _lights.push(light);
6966 Render.start(loop)
6967 };
6968 this.remove = function(light) {
6969 _lights.findAndRemove(light)
6970 };
6971 this.getLighting = function(shader, force) {
6972 if (shader.__lighting && !force) return shader.__lighting;
6973 var lighting = {
6974 position: [],
6975 color: [],
6976 intensity: [],
6977 distance: []
6978 };
6979 shader.__lighting = lighting;
6980 if (_lights[0] && !_lights[0]._world) decomposeLights(_lights);
6981 decomposeLights(shader.lights);
6982 updateArrays(shader);
6983 return lighting
6984 };
6985 this.update = function(shader) {
6986 decomposeLights(shader.lights);
6987 updateArrays(shader)
6988 };
6989 this.getParticleDepthShader = function(light, size) {
6990 if (!_particleDepthShader) {
6991 _particleDepthShader = new Shader("ParticleDepth");
6992 _particleDepthShader.uniforms = {
6993 pointSize: {
6994 type: "f",
6995 value: size || 5
6996 },
6997 lightPos: {
6998 type: "v3",
6999 value: light.position
7000 },
7001 far: {
7002 type: "f",
7003 value: light.shadow.camera.far
7004 }
7005 };
7006 _particleDepthShader.receiveShadow = true
7007 }
7008 var shader = _particleDepthShader.clone();
7009 shader.set("pointSize", size || 5);
7010 shader.set("lightPos", light.position);
7011 shader.set("far", light.shadow.camera.far);
7012 return shader
7013 }
7014}, "static");
7015Class(function BasicPass() {
7016 Inherit(this, NukePass);
7017 var _this = this;
7018 this.fragmentShader = ["varying vec2 vUv;", "uniform sampler2D tDiffuse;", "void main() {", "gl_FragColor = texture2D(tDiffuse, vUv);", "}"];
7019 this.init(this.fragmentShader)
7020});
7021Class(function FXLayer(_parentNuke, _pass) {
7022 Inherit(this, Component);
7023 var _this = this;
7024 var _nuke, _rt;
7025 var _scene = new THREE.Scene;
7026 var _objects = [];
7027 var _rts = {};
7028 var _id = Utils.timestamp();
7029 this.resolution = 1;
7030 this.autoVisible = true;
7031
7032 function addListeners() {
7033 _this.events.subscribe(HydraEvents.RESIZE, resizeHandler)
7034 }
7035
7036 function resizeHandler() {
7037 _rt.setSize(_nuke.stage.width * _this.resolution * _nuke.dpr, _nuke.stage.height * _this.resolution * _nuke.dpr)
7038 }
7039
7040 function initRT() {
7041 _rt = Utils3D.createRT(_nuke.stage.width * _this.resolution * _nuke.dpr, _nuke.stage.height * _this.resolution * _nuke.dpr);
7042 _this.rt = _rt
7043 }
7044
7045 function updateTopParent(obj) {
7046 var parent = obj.parent;
7047 while (parent) {
7048 parent.updateMatrixWorld();
7049 parent = parent.parent
7050 }
7051 }
7052 this.create = function(nuke, pass) {
7053 _this = this;
7054 _nuke = _this.initClass(Nuke, nuke.stage, {
7055 renderer: nuke.renderer,
7056 camera: nuke.camera,
7057 scene: _scene,
7058 dpr: nuke.dpr
7059 });
7060 _nuke.parentNuke = nuke;
7061 if (pass) _nuke.add(pass);
7062 _this.nuke = _nuke;
7063 initRT();
7064 addListeners()
7065 };
7066 this.addObject = function(object) {
7067 var clone = object.clone();
7068 object["clone_" + _id] = clone;
7069 _scene.add(clone);
7070 _objects.push(object);
7071 return clone
7072 };
7073 this.removeObject = function(object) {
7074 _scene.remove(object["clone_" + _id]);
7075 _objects.findAndRemove(object);
7076 delete object["clone_" + _id]
7077 };
7078 this.render = this.draw = function(stage, camera) {
7079 if (stage) {
7080 _nuke.stage = stage;
7081 _this.setSize(stage.width, stage.height)
7082 }
7083 if (camera) {
7084 _nuke.camera = camera
7085 }
7086 for (var i = _objects.length - 1; i > -1; i--) {
7087 var obj = _objects[i];
7088 var clone = obj["clone_" + _id];
7089 if (_this.autoVisible) {
7090 clone.material.visible = true;
7091 var parent = obj;
7092 while (parent) {
7093 if (parent.visible == false || parent.material && parent.material.visible == false) {
7094 clone.material.visible = false
7095 }
7096 parent = parent.parent
7097 }
7098 }
7099 obj.updateMatrixWorld();
7100 Utils3D.decompose(obj, clone)
7101 }
7102 _nuke.rtt = _rt;
7103 _nuke.render()
7104 };
7105 this.addPass = function(pass) {
7106 _nuke.add(pass)
7107 };
7108 this.removePass = function(pass) {
7109 _nuke.remove(pass)
7110 };
7111 this.setSize = function(width, height) {
7112 if (_rt.width == width && _rt.height == height) return;
7113 _this.events.unsubscribe(HydraEvents.RESIZE, resizeHandler);
7114 _rt.setSize(width * _this.resolution * _nuke.dpr, height * _this.resolution * _nuke.dpr);
7115 _nuke.setSize(width * _this.resolution * _nuke.dpr, height * _this.resolution * _nuke.dpr)
7116 };
7117 this.setDPR = function(dpr) {
7118 _nuke.dpr = dpr
7119 };
7120 if (_parentNuke instanceof Nuke) this.create(_parentNuke, _pass)
7121});
7122Namespace("FX");
7123Class(function Nuke(_stage, _params) {
7124 Inherit(this, Component);
7125 var _this = this;
7126 if (!_params.renderer) console.error("Nuke :: Must define renderer");
7127 _this.stage = _stage;
7128 _this.renderer = _params.renderer;
7129 _this.camera = _params.camera;
7130 _this.scene = _params.scene;
7131 _this.rtt = _params.rtt;
7132 _this.enabled = _params.enabled == false ? false : true;
7133 _this.passes = _params.passes || [];
7134 var _dpr = _params.dpr || 1;
7135 var _rts = {};
7136 var _rtStack = [];
7137 var _rttPing, _rttPong, _nukeScene, _nukeMesh, _rttCamera;
7138 (function() {
7139 initNuke();
7140 addListeners()
7141 }());
7142
7143 function initNuke() {
7144 var width = _this.stage.width * _dpr;
7145 var height = _this.stage.height * _dpr;
7146 _rttPing = Nuke.getRT(width, height, "ping");
7147 _rttPong = Nuke.getRT(width, height, "pong");
7148 _rttCamera = new THREE.OrthographicCamera(_this.stage.width / -2, _this.stage.width / 2, _this.stage.height / 2, _this.stage.height / -2, 1, 1e3);
7149 _nukeScene = new THREE.Scene;
7150 _nukeMesh = new THREE.Mesh(Nuke.getPlaneGeom(), new THREE.MeshBasicMaterial);
7151 _nukeScene.add(_nukeMesh)
7152 }
7153
7154 function finalRender(scene, camera) {
7155 if (_this.rtt) {
7156 _this.renderer.render(scene, camera || _this.camera, _this.rtt)
7157 } else {
7158 _this.renderer.render(scene, camera || _this.camera)
7159 }
7160 }
7161
7162 function addListeners() {
7163 _this.events.subscribe(HydraEvents.RESIZE, resizeHandler)
7164 }
7165
7166 function resizeHandler() {
7167 var width = _this.stage.width * _dpr;
7168 var height = _this.stage.height * _dpr;
7169 _rttPing.setSize(width);
7170 _rttPong.setSize(height);
7171 _rttCamera.left = _this.stage.width / -2;
7172 _rttCamera.right = _this.stage.width / 2;
7173 _rttCamera.top = _this.stage.height / 2;
7174 _rttCamera.bottom = _this.stage.height / -2;
7175 _rttCamera.updateProjectionMatrix()
7176 }
7177 _this.add = function(pass, index) {
7178 if (!pass.pass) {
7179 defer(function() {
7180 _this.add(pass, index)
7181 });
7182 return
7183 }
7184 if (typeof index == "number") {
7185 _this.passes.splice(index, 0, pass);
7186 return
7187 }
7188 _this.passes.push(pass)
7189 };
7190 _this.remove = function(pass) {
7191 if (typeof pass == "number") {
7192 _this.passes.splice(pass)
7193 } else {
7194 _this.passes.findAndRemove(pass)
7195 }
7196 };
7197 _this.renderToTexture = function(clear, rtt) {
7198 _this.renderer.render(_this.scene, _this.camera, rtt || _rttPing, typeof clear == "boolean" ? clear : true)
7199 };
7200 _this.render = function() {
7201 if (!_this.enabled || !_this.passes.length) {
7202 finalRender(_this.scene);
7203 return
7204 }
7205 if (!_this.multiRender) {
7206 _this.renderer.render(_this.scene, _this.camera, _rttPing, true)
7207 }
7208 var pingPong = true;
7209 for (var i = 0; i < _this.passes.length - 1; i++) {
7210 _nukeMesh.material = _this.passes[i].pass;
7211 _nukeMesh.material.uniforms.tDiffuse.value = pingPong ? _rttPing.texture : _rttPong.texture;
7212 _this.renderer.render(_nukeScene, _rttCamera, pingPong ? _rttPong : _rttPing);
7213 pingPong = !pingPong
7214 }
7215 _nukeMesh.material = _this.passes[_this.passes.length - 1].pass;
7216 _nukeMesh.material.uniforms.tDiffuse.value = pingPong ? _rttPing.texture : _rttPong.texture;
7217 finalRender(_nukeScene, _rttCamera)
7218 };
7219 _this.setSize = function(width, height) {
7220 _this.events.unsubscribe(HydraEvents.RESIZE, resizeHandler);
7221 if (!_rts[width + "_" + height]) {
7222 var rttPing = Nuke.getRT(width * _dpr, height * _dpr, "ping");
7223 var rttPong = Nuke.getRT(width * _dpr, height * _dpr, "pong");
7224 _rts[width + "_" + height] = {
7225 ping: rttPing,
7226 pong: rttPong,
7227 name: width + "_" + height
7228 };
7229 _rtStack.push(_rts[width + "_" + height]);
7230 if (_rtStack.length > 3) {
7231 let rts = _rtStack.shift();
7232 delete _rts[rts.name];
7233 rts.ping.dispose();
7234 rts.pong.dispose()
7235 }
7236 }
7237 var rts = _rts[width + "_" + height];
7238 _rttPing = rts.ping;
7239 _rttPong = rts.pong
7240 };
7241 _this.set("dpr", function(v) {
7242 _dpr = v || Device.pixelRatio;
7243 resizeHandler()
7244 });
7245 _this.get("dpr", function() {
7246 return _dpr
7247 })
7248}, function() {
7249 var _plane;
7250 var _rts = {};
7251 Nuke.getPlaneGeom = function() {
7252 if (!_plane) _plane = new THREE.PlaneBufferGeometry(2, 2, 1, 1);
7253 return _plane
7254 };
7255 Nuke.getRT = function(width, height, type) {
7256 return Utils3D.createRT(width, height)
7257 }
7258});
7259Class(function NukePass(_fs, _vs, _pass) {
7260 Inherit(this, Component);
7261 var _this = this;
7262
7263 function prefix(code) {
7264 var pre = "";
7265 pre += "precision highp float;\n";
7266 pre += "precision highp int;\n";
7267 if (!code.strpos("uniform sampler2D tDiffuse")) {
7268 pre += "uniform sampler2D tDiffuse;\n";
7269 pre += "varying vec2 vUv;\n"
7270 }
7271 code = pre + code;
7272 return code
7273 }
7274
7275 function getVS() {
7276 return `
7277 precision highp float;
7278 precision highp int;
7279
7280 varying vec2 vUv;
7281
7282 attribute vec2 uv;
7283 attribute vec3 position;
7284
7285 void main() {
7286 vUv = uv;
7287 gl_Position = vec4(position, 1.0);
7288 }
7289 `
7290 }
7291 this.init = function(fs) {
7292 if (_this.pass) return;
7293 _this = this;
7294 var name = fs || this.constructor.toString().match(/function ([^\(]+)/)[1];
7295 var fragmentShader = Array.isArray(fs) ? fs.join("") : null;
7296 _this.uniforms = _this.uniforms || {};
7297 _this.uniforms.tDiffuse = {
7298 type: "t",
7299 value: null
7300 };
7301 _this.pass = new THREE.RawShaderMaterial({
7302 uniforms: _this.uniforms,
7303 vertexShader: typeof _vs === "string" ? Shaders.getShader(name + ".vs") : getVS(),
7304 fragmentShader: fragmentShader || prefix(Shaders.getShader(name + ".fs"))
7305 });
7306 _this.uniforms = _this.pass.uniforms
7307 };
7308 this.set = function(key, value) {
7309 TweenManager.clearTween(_this.uniforms[key]);
7310 this.uniforms[key].value = value
7311 };
7312 this.tween = function(key, value, time, ease, delay, callback, update) {
7313 TweenManager.tween(_this.uniforms[key], {
7314 value: value
7315 }, time, ease, delay, callback, update)
7316 };
7317 this.clone = function() {
7318 if (!_this.pass) _this.init(_fs);
7319 return new NukePass(null, null, _this.pass.clone())
7320 };
7321 if (typeof _fs === "string") {
7322 defer(function() {
7323 _this.init(_fs)
7324 })
7325 } else if (_pass) {
7326 _this.pass = _pass;
7327 _this.uniforms = _pass.uniforms
7328 }
7329});
7330Class(function Raycaster(_camera) {
7331 Inherit(this, Component);
7332 var _this = this;
7333 var _mouse = new THREE.Vector3;
7334 var _raycaster = new THREE.Raycaster;
7335 var _debug = null;
7336 (function() {}());
7337
7338 function intersect(objects) {
7339 var hit;
7340 if (Array.isArray(objects)) {
7341 hit = _raycaster.intersectObjects(objects)
7342 } else {
7343 hit = _raycaster.intersectObject(objects)
7344 }
7345 if (_debug) updateDebug();
7346 return hit
7347 }
7348
7349 function updateDebug() {
7350 var vertices = _debug.geometry.vertices;
7351 vertices[0].copy(_raycaster.ray.origin.clone());
7352 vertices[1].copy(_raycaster.ray.origin.clone().add(_raycaster.ray.direction.clone().multiplyScalar(1e4)));
7353 _debug.geometry.verticesNeedUpdate = true
7354 }
7355 this.set("camera", camera => {
7356 _camera = camera
7357 });
7358 this.set("pointsThreshold", value => {
7359 _raycaster.params.Points.threshold = value
7360 });
7361 this.debug = scene => {
7362 var geom = new THREE.Geometry;
7363 geom.vertices.push(new THREE.Vector3(-100, 0, 0));
7364 geom.vertices.push(new THREE.Vector3(100, 0, 0));
7365 var mat = new THREE.LineBasicMaterial({
7366 color: 1671168e1
7367 });
7368 _debug = new THREE.Line(geom, mat);
7369 scene.add(_debug)
7370 };
7371 this.checkHit = (objects, mouse) => {
7372 mouse = mouse || Mouse;
7373 var rect = _this.rect || Stage;
7374 _mouse.x = mouse.x / rect.width * 2 - 1;
7375 _mouse.y = -(mouse.y / rect.height) * 2 + 1;
7376 _raycaster.setFromCamera(_mouse, _camera);
7377 return intersect(objects)
7378 };
7379 this.checkFromValues = (objects, origin, direction) => {
7380 _raycaster.set(origin, direction, 0, Number.POSITIVE_INFINITY);
7381 return intersect(objects)
7382 }
7383});
7384Class(function ScreenProjection(_camera) {
7385 Inherit(this, Component);
7386 var _this = this;
7387 var _v3 = new THREE.Vector3;
7388 var _value = new THREE.Vector3;
7389 (function() {}());
7390 this.set("camera", function(v) {
7391 _camera = v
7392 });
7393 this.unproject = function(mouse, distance) {
7394 var rect = _this.rect || Stage;
7395 _v3.set(mouse.x / rect.width * 2 - 1, -(mouse.y / rect.height) * 2 + 1, .5);
7396 _v3.unproject(_camera);
7397 var pos = _camera.position;
7398 _v3.sub(pos).normalize();
7399 var dist = distance || -pos.z / _v3.z;
7400 _value.copy(pos).add(_v3.multiplyScalar(dist));
7401 return _value
7402 };
7403 this.project = function(pos, screen) {
7404 screen = screen || Stage;
7405 if (pos instanceof THREE.Object3D) {
7406 pos.updateMatrixWorld();
7407 _v3.set(0, 0, 0).setFromMatrixPosition(pos.matrixWorld)
7408 } else {
7409 _v3.copy(pos)
7410 }
7411 _v3.project(_camera);
7412 _v3.x = (_v3.x + 1) / 2 * screen.width;
7413 _v3.y = -(_v3.y - 1) / 2 * screen.height;
7414 return _v3
7415 }
7416});
7417Class(function RandomEulerRotation(_container) {
7418 var _this = this;
7419 var _euler = ["x", "y", "z"];
7420 var _rot;
7421 this.speed = 1;
7422 (function() {
7423 initRotation()
7424 }());
7425
7426 function initRotation() {
7427 _rot = {};
7428 _rot.x = Utils.doRandom(0, 2);
7429 _rot.y = Utils.doRandom(0, 2);
7430 _rot.z = Utils.doRandom(0, 2);
7431 _rot.vx = Utils.doRandom(-5, 5) * .0025;
7432 _rot.vy = Utils.doRandom(-5, 5) * .0025;
7433 _rot.vz = Utils.doRandom(-5, 5) * .0025
7434 }
7435 this.update = function() {
7436 var time = Render.TIME;
7437 for (var i = 0; i < 3; i++) {
7438 var v = _euler[i];
7439 switch (_rot[v]) {
7440 case 0:
7441 _container.rotation[v] += Math.cos(Math.sin(time * .25)) * _rot["v" + v] * _this.speed;
7442 break;
7443 case 1:
7444 _container.rotation[v] += Math.cos(Math.sin(time * .25)) * _rot["v" + v] * _this.speed;
7445 break;
7446 case 2:
7447 _container.rotation[v] += Math.cos(Math.cos(time * .25)) * _rot["v" + v] * _this.speed;
7448 break
7449 }
7450 }
7451 };
7452 this.startRender = function() {
7453 Render.start(_this.update)
7454 };
7455 this.stopRender = function() {
7456 Render.stop(_this.update)
7457 };
7458 this.onDestroy = function() {
7459 this.stopRender()
7460 }
7461});
7462Class(function Shader(_vertexShader, _fragmentShader, _name, _material) {
7463 Inherit(this, Component);
7464 var _this = this;
7465 this.receiveShadow = false;
7466 this.receiveLight = false;
7467 this.lights = [];
7468 (function() {
7469 if (!_fragmentShader) _fragmentShader = _vertexShader;
7470 if (Hydra.LOCAL && _name) expose();
7471 if (_material) {
7472 _this.uniforms = _material.uniforms;
7473 _this.attributes = _material.attributes;
7474 defer(function() {
7475 if (_this.receiveLight) {
7476 initLights();
7477 Render.start(updateLights)
7478 }
7479 })
7480 }
7481 }());
7482
7483 function expose() {
7484 Dev.expose(_name, _this)
7485 }
7486
7487 function process(code, type) {
7488 var lights = initLights();
7489 var header;
7490 if (type == "vs") {
7491 header = ["precision highp float;", "precision highp int;", "attribute vec2 uv;", "attribute vec3 position;", "attribute vec3 normal;", "uniform mat4 modelViewMatrix;", "uniform mat4 projectionMatrix;", "uniform mat4 modelMatrix;", "uniform mat4 viewMatrix;", "uniform mat3 normalMatrix;", "uniform vec3 cameraPosition;", ""].join("\n")
7492 } else {
7493 header = [code.strpos("dFdx") ? "#extension GL_OES_standard_derivatives : enable" : "", "precision highp float;", "precision highp int;", "uniform mat4 modelViewMatrix;", "uniform mat4 projectionMatrix;", "uniform mat4 modelMatrix;", "uniform mat4 viewMatrix;", "uniform mat3 normalMatrix;", "uniform vec3 cameraPosition;", ""].join("\n")
7494 }
7495 code = lights + code;
7496 if (!_this.receiveShadow && !_this.useShaderMaterial) code = header + code;
7497 var threeChunk = function(a, b) {
7498 return THREE.ShaderChunk[b] + "\n"
7499 };
7500 return code.replace(/#s?chunk\(\s?(\w+)\s?\);/g, threeChunk)
7501 }
7502
7503 function initLights() {
7504 if (!_this.receiveLight) return "";
7505 var lighting = Lighting.getLighting(_this);
7506 var numLights = lighting.position.length;
7507 if (numLights == 0) {
7508 if (!Shader.disableWarnings) console.warn("Lighting enabled but 0 lights added. Be sure to add them before calling shader.material");
7509 return ""
7510 }
7511 return ["#define NUM_LIGHTS " + numLights, "uniform vec3 lightPos[" + numLights + "];", "uniform vec3 lightColor[" + numLights + "];", "uniform float lightIntensity[" + numLights + "];", "uniform float lightDistance[" + numLights + "];", ""].join("\n")
7512 }
7513
7514 function updateMaterialLight(lighting) {
7515 _material.uniforms.lightPos = {
7516 type: "v3v",
7517 value: lighting.position
7518 };
7519 _material.uniforms.lightColor = {
7520 type: "fv",
7521 value: lighting.color
7522 };
7523 _material.uniforms.lightIntensity = {
7524 type: "fv1",
7525 value: lighting.intensity
7526 };
7527 _material.uniforms.lightDistance = {
7528 type: "fv1",
7529 value: lighting.distance
7530 };
7531 Render.start(updateLights)
7532 }
7533
7534 function updateLights() {
7535 if (_material.visible !== false) Lighting.update(_this, true)
7536 }
7537 this.get("material", function() {
7538 if (!_material) {
7539 var params = {};
7540 params.vertexShader = process(Shaders.getShader(_vertexShader + ".vs") || _vertexShader, "vs");
7541 params.fragmentShader = process(Shaders.getShader(_fragmentShader + ".fs") || _fragmentShader, "fs");
7542 if (_this.attributes) params.attributes = _this.attributes;
7543 if (_this.uniforms) params.uniforms = _this.uniforms;
7544 if (_this.receiveShadow) params.uniforms = THREE.UniformsUtils.merge([THREE.UniformsLib.lights, params.uniforms]);
7545 _material = _this.receiveShadow || _this.useShaderMaterial ? new THREE.ShaderMaterial(params) : new THREE.RawShaderMaterial(params);
7546 _material.shader = _this;
7547 _this.uniforms = _material.uniforms;
7548 if (_this.receiveLight) updateMaterialLight(_this.__lighting);
7549 if (_this.receiveShadow) _material.lights = true
7550 }
7551 return _material
7552 });
7553 this.set = function(key, value) {
7554 if (typeof value !== "undefined") _this.uniforms[key].value = value;
7555 return _this.uniforms[key].value
7556 };
7557 this.getValues = function() {
7558 var out = {};
7559 for (var key in _this.uniforms) {
7560 out[key] = _this.uniforms[key].value
7561 }
7562 return out
7563 };
7564 this.copyUniformsTo = function(obj) {
7565 for (var key in _this.uniforms) {
7566 obj.uniforms[key] = _this.uniforms[key]
7567 }
7568 };
7569 this.tween = function(key, value, time, ease, delay, callback, update) {
7570 return TweenManager.tween(_this.uniforms[key], {
7571 value: value
7572 }, time, ease, delay, callback, update)
7573 };
7574 this.clone = function(name) {
7575 var shader = new Shader(_vertexShader, _fragmentShader, name || _name, _this.material.clone());
7576 shader.receiveLight = this.receiveLight;
7577 shader.receiveShadow = this.receiveShadow;
7578 shader.lights = this.lights;
7579 return shader
7580 };
7581 this.updateLighting = function() {
7582 var lighting = Lighting.getLighting(_this, true);
7583 _material.uniforms.lightPos.value = lighting.position;
7584 _material.uniforms.lightColor.value = lighting.color;
7585 _material.uniforms.lightIntensity.value = lighting.intensity;
7586 _material.uniforms.lightDistance.value = lighting.distance
7587 };
7588 this.onDestroy = function() {
7589 Render.stop(updateLights);
7590 _material && _material.dispose && _material.dispose()
7591 }
7592});
7593Class(function Utils3D() {
7594 var _this = this;
7595 var _objectLoader, _geomLoader, _bufferGeomLoader;
7596 var _textures = {};
7597 this.PATH = "";
7598 this.decompose = function(local, world) {
7599 local.matrixWorld.decompose(world.position, world.quaternion, world.scale)
7600 };
7601 this.createDebug = function(size, color) {
7602 var geom = new THREE.IcosahedronGeometry(size || 40, 1);
7603 var mat = color ? new THREE.MeshBasicMaterial({
7604 color: color
7605 }) : new THREE.MeshNormalMaterial;
7606 return new THREE.Mesh(geom, mat)
7607 };
7608 this.createRT = function(width, height) {
7609 var params = {
7610 minFilter: THREE.LinearFilter,
7611 magFilter: THREE.LinearFilter,
7612 format: THREE.RGBAFormat,
7613 stencilBuffer: false
7614 };
7615 return new THREE.WebGLRenderTarget(width, height, params)
7616 };
7617 this.getTexture = function(path) {
7618 if (!_textures[path]) {
7619 var img = new Image;
7620 img.crossOrigin = "anonymous";
7621 img.src = _this.PATH + path;
7622 var texture = new THREE.Texture(img);
7623 img.onload = function() {
7624 texture.needsUpdate = true;
7625 if (texture.onload) {
7626 texture.onload();
7627 texture.onload = null
7628 }
7629 if (!THREE.Math.isPowerOfTwo(img.width * img.height)) texture.minFilter = THREE.LinearFilter
7630 };
7631 _textures[path] = texture
7632 }
7633 return _textures[path]
7634 };
7635 this.setInfinity = function(v) {
7636 var inf = Number.POSITIVE_INFINITY;
7637 v.set(inf, inf, inf);
7638 return v
7639 };
7640 this.freezeMatrix = function(mesh) {
7641 mesh.matrixAutoUpdate = false;
7642 mesh.updateMatrix()
7643 };
7644 this.getCubemap = function(src) {
7645 var path = "cube_" + (Array.isArray(src) ? src[0] : src);
7646 if (!_textures[path]) {
7647 var images = [];
7648 for (var i = 0; i < 6; i++) {
7649 var img = new Image;
7650 img.crossOrigin = "";
7651 img.src = _this.PATH + (Array.isArray(src) ? src[i] : src);
7652 images.push(img);
7653 img.onload = function() {
7654 _textures[path].needsUpdate = true
7655 }
7656 }
7657 _textures[path] = new THREE.Texture;
7658 _textures[path].image = images;
7659 _textures[path].minFilter = THREE.LinearFilter
7660 }
7661 return _textures[path]
7662 };
7663 this.loadObject = function(name) {
7664 if (!_objectLoader) _objectLoader = new THREE.ObjectLoader;
7665 return _objectLoader.parse(Hydra.JSON[name])
7666 };
7667 this.loadGeometry = function(name) {
7668 if (!_geomLoader) _geomLoader = new THREE.JSONLoader;
7669 if (!_bufferGeomLoader) _bufferGeomLoader = new THREE.BufferGeometryLoader;
7670 var json = Hydra.JSON[name];
7671 if (json.type == "BufferGeometry") {
7672 return _bufferGeomLoader.parse(json)
7673 } else {
7674 return _geomLoader.parse(json.data).geometry
7675 }
7676 };
7677 this.disposeAllTextures = function() {
7678 for (var key in _textures) {
7679 _textures[key].dispose()
7680 }
7681 };
7682 this.disableWarnings = function() {
7683 window.console.warn = function(str, msg) {
7684 if (str.strpos("getProgramInfo")) console.log(msg)
7685 };
7686 window.console.error = function() {}
7687 };
7688 this.detectGPU = function(matches) {
7689 var gpu = _this.GPU_INFO;
7690 if (gpu.gpu && gpu.gpu.strpos(matches)) return true;
7691 if (gpu.version && gpu.version.strpos(matches)) return true;
7692 return false
7693 };
7694 this.loadBufferGeometry = function(name) {
7695 var data = Hydra.JSON[name];
7696 var geometry = new THREE.BufferGeometry;
7697 geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array(data.position), 3));
7698 geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(data.normal), 3));
7699 geometry.addAttribute("uv", new THREE.BufferAttribute(new Float32Array(data.uv), 2));
7700 return geometry
7701 };
7702 this.loadSkinnedGeometry = function(name) {
7703 var data = Hydra.JSON[name];
7704 var geometry = new THREE.BufferGeometry;
7705 geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array(data.position), 3));
7706 geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(data.normal), 3));
7707 geometry.addAttribute("uv", new THREE.BufferAttribute(new Float32Array(data.uv), 2));
7708 geometry.addAttribute("skinIndex", new THREE.BufferAttribute(new Float32Array(data.skinIndices), 4));
7709 geometry.addAttribute("skinWeight", new THREE.BufferAttribute(new Float32Array(data.skinWeights), 4));
7710 geometry.bones = data.bones;
7711 return geometry
7712 };
7713 this.loadCurve = function(obj) {
7714 if (typeof obj === "string") obj = Hydra.JSON[obj];
7715 var data = obj;
7716 var points = [];
7717 for (var j = 0; j < data.length; j += 3) {
7718 points.push(new THREE.Vector3(data[j + 0], data[j + 1], data[j + 2]))
7719 }
7720 return new THREE.CatmullRomCurve3(points)
7721 };
7722 this.setLightCamera = function(light, size, near, far, texture) {
7723 light.shadow.camera.left = -size;
7724 light.shadow.camera.right = size;
7725 light.shadow.camera.top = size;
7726 light.shadow.camera.bottom = -size;
7727 light.castShadow = true;
7728 if (near) light.shadow.camera.near = near;
7729 if (far) light.shadow.camera.far = far;
7730 if (texture) light.shadow.mapSize.width = light.shadow.mapSize.height = texture;
7731 light.shadow.camera.updateProjectionMatrix()
7732 };
7733 this.getRepeatTexture = function(src) {
7734 var texture = this.getTexture(src);
7735 texture.onload = function() {
7736 texture.wrapS = texture.wrapT = THREE.RepeatWrapping
7737 };
7738 return texture
7739 }
7740}, "static");
7741Module(function iOSDevices() {
7742 this.exports = {
7743 find: function() {
7744 if (Mobile.os != "iOS") return "";
7745 if (!Device.graphics.webgl) return "legacy";
7746 var detect = Device.graphics.webgl.detect;
7747 if (detect(["a9", "a10", "a11", "a12", "a13", "a14"]) || navigator.platform.toLowerCase().strpos("mac")) return Mobile.phone ? "6s, 7x" : "ipad pro";
7748 if (detect("a8")) return Mobile.phone ? "6x" : "ipad air 2, ipad mini 4";
7749 if (detect("a7")) return Mobile.phone ? "5s" : "ipad air 1, ipad mini 2, ipad mini 3";
7750 if (detect(["sgx554", "sgx 554"])) return Mobile.phone ? "" : "ipad 4";
7751 if (detect(["sgx543", "sgx 543"])) return Mobile.phone ? "5x, 5c, 4s" : "ipad mini 1, ipad 2";
7752 return "legacy"
7753 }
7754 }
7755});
7756Class(function KeyboardUtil() {
7757 Inherit(this, Component);
7758 var _this = this;
7759 _this.DOWN = "keyboard_down";
7760 _this.PRESS = "keyboard_press";
7761 _this.UP = "keyboard_up";
7762 (function() {
7763 Hydra.ready(addListeners)
7764 }());
7765
7766 function addListeners() {
7767 __window.keydown(keydown);
7768 __window.keyup(keyup);
7769 __window.keypress(keypress)
7770 }
7771
7772 function keydown(e) {
7773 _this.events.fire(_this.DOWN, e)
7774 }
7775
7776 function keyup(e) {
7777 _this.events.fire(_this.UP, e)
7778 }
7779
7780 function keypress(e) {
7781 _this.events.fire(_this.PRESS, e)
7782 }
7783}, "static");
7784Class(function ScrollUtil() {
7785 Inherit(this, Component);
7786 var _this = this;
7787 var _divide;
7788 var _callbacks = [];
7789 var _time = Date.now();
7790 var _touch = {
7791 y: 0,
7792 save: 0
7793 };
7794 var _wheel = false;
7795 var _delta = {};
7796 (function() {
7797 initDivide();
7798 Hydra.ready(addListeners)
7799 }());
7800
7801 function initDivide() {
7802 if (Device.browser.ie) return _divide = 2;
7803 if (Device.system.os == "mac") {
7804 if (Device.browser.chrome || Device.browser.safari) _divide = 40;
7805 else _divide = 1
7806 } else {
7807 if (Device.browser.chrome) _divide = 15;
7808 else _divide = .5
7809 }
7810 }
7811
7812 function addListeners() {
7813 if (!Device.mobile) {
7814 window.addEventListener("wheel", scroll)
7815 } else {
7816 __window.bind("touchstart", touchStart);
7817 __window.bind("touchend", touchEnd);
7818 __window.bind("touchcancel", touchEnd)
7819 }
7820 }
7821
7822 function touchStart(e) {
7823 _touch.y = e.y;
7824 _touch.time = Date.now();
7825 _touch.velocity = 0;
7826 __window.bind("touchmove", touchMove)
7827 }
7828
7829 function touchMove(e) {
7830 var diff = e.y - _touch.y;
7831 _touch.y = e.y;
7832 _touch.velocity = diff / (_touch.time - Date.now());
7833 _touch.time = Date.now();
7834 callback(-diff)
7835 }
7836
7837 function touchEnd(e) {
7838 __window.unbind("touchmove", touchMove);
7839 callback(_touch.velocity * 100 || 0, _touch)
7840 }
7841
7842 function keyPress(e) {
7843 var value = 750;
7844 if (e.code == 40) scroll({
7845 deltaY: value,
7846 deltaX: 0,
7847 key: true
7848 });
7849 if (e.code == 39) scroll({
7850 deltaY: 0,
7851 deltaX: value,
7852 key: true
7853 });
7854 if (e.code == 38) scroll({
7855 deltaY: -value,
7856 deltaX: 0,
7857 key: true
7858 });
7859 if (e.code == 37) scroll({
7860 deltaY: 0,
7861 deltaX: -value,
7862 key: true
7863 })
7864 }
7865
7866 function scroll(e) {
7867 if (e.preventDefault) e.preventDefault();
7868 var value = e.wheelDelta || -e.detail;
7869 var timeDelta = Render.TIME - _time;
7870 if (typeof e.deltaX !== "undefined" || e.key) {
7871 _delta.x = -e.deltaX * .4;
7872 _delta.y = e.deltaY * .4;
7873 if (Device.browser.firefox && Device.system.os == "mac") {
7874 _delta.y *= .5;
7875 if (timeDelta < 50) _delta.y *= 30
7876 }
7877 } else {
7878 _delta.x = 0;
7879 var delta = Math.ceil(-value / _divide);
7880 if (e.preventDefault) e.preventDefault();
7881 if (delta <= 0) delta -= 1;
7882 delta = Utils.clamp(delta, -60, 60);
7883 _delta.y = delta * 3.5
7884 }
7885 callback(_delta);
7886 _time = Render.TIME
7887 }
7888
7889 function callback(delta) {
7890 for (var i = 0; i < _callbacks.length; i++) _callbacks[i](delta)
7891 }
7892 this.reset = function() {
7893 this.value = 0
7894 };
7895 this.link = function(callback) {
7896 _callbacks.push(callback)
7897 };
7898 this.unlink = function(callback) {
7899 var index = _callbacks.indexOf(callback);
7900 if (index > -1) _callbacks.splice(index, 1)
7901 }
7902}, "Static");
7903Class(function Share() {
7904 var _this = this;
7905 var ShareConfig;
7906 let _title = "Toonami";
7907 let _copy = "Watch Toonami Saturday Nights on Adult Swim http://toonami.com #Toonami";
7908 let _url = "http://toonami.com";
7909 let _image = Config.API.share;
7910 (function() {
7911 defer(initTags)
7912 }());
7913
7914 function initTags() {
7915 ShareConfig = require("ShareConfig");
7916 var config = {
7917 Facebook: {
7918 appId: "1891352854426159"
7919 }
7920 };
7921 ShareConfig.init(config)
7922 }
7923 this.click = type => {
7924 let data = {
7925 type,
7926 title: _title,
7927 text: _copy,
7928 url: _url,
7929 image: _image
7930 };
7931 ShareConfig.share(data)
7932 }
7933}, "Static");
7934Module(function ShareConfig() {
7935 var _this = this;
7936 var _gplusOptions;
7937 var popWindow = function(url, name, w, h) {
7938 var nw = window.open(url, name, "height=" + h + ",width=" + w + ",scrollbars=yes");
7939 if (window.focus) nw.focus();
7940 return false
7941 };
7942 var encode = function(str) {
7943 return encodeURIComponent(str)
7944 };
7945 var tags = {
7946 Facebook: function(config) {
7947 window.fbAsyncInit = function() {
7948 FB.init({
7949 appId: config.Facebook.appId,
7950 xfbml: true,
7951 version: "v2.6"
7952 })
7953 };
7954 (function(d, s, id) {
7955 var js, fjs = d.getElementsByTagName(s)[0];
7956 if (d.getElementById(id)) {
7957 return
7958 }
7959 js = d.createElement(s);
7960 js.id = id;
7961 js.src = "//connect.facebook.net/en_US/sdk.js";
7962 fjs.parentNode.insertBefore(js, fjs)
7963 }(document, "script", "facebook-jssdk"))
7964 },
7965 GooglePlus: function() {
7966 var gPlusScript = docurment.createElement("script");
7967 gPlusScript.setAttribute("src", "https://apis.google.com/js/platform.js");
7968 gPlusScript.setAttribute("async", "true");
7969 gPlusScript.setAttribute("defer", "true");
7970 document.head.appendChild(gPlusScript);
7971 var gPlusBtn = document.createElement("div");
7972 gPlusBtn.id = "G-Plus-Share";
7973 gPlusBtn.style.left = "-10000px";
7974 gPlusBtn.style.top = "-10000px";
7975 document.body.parentNode.insertBefore(gPlusBtn, document.body.nextSibling);
7976 var initGP = function() {
7977 if (typeof gapi !== "undefined") {
7978 _gplusOptions = {
7979 contenturl: _share.url,
7980 clientid: "714900688898-9n4urd545mqs8kabn9j14a18daosm9l0.apps.googleusercontent.com",
7981 cookiepolicy: "single_host_origin",
7982 prefilltext: _share.generic,
7983 calltoactionlabel: "VISIT",
7984 calltoactionurl: _share.url
7985 };
7986 gapi.interactivepost.render("G-Plus-Share", _gplusOptions)
7987 } else {
7988 setTimeout(initGP, 200)
7989 }
7990 };
7991 Hydra.ready(initGP)
7992 }
7993 };
7994 var share = {
7995 Email: function(data) {
7996 var text = encode(data.text);
7997 window.location.href = "mailto:?subject=" + data.subject + "&body=" + text
7998 },
7999 Facebook: function(data) {
8000 if (!window.FB) return;
8001 FB.ui({
8002 method: "feed",
8003 name: data.title,
8004 picture: data.image,
8005 link: data.url,
8006 description: data.text
8007 }, function() {})
8008 },
8009 GooglePlus: function(data) {
8010 _gplusOptions.prefilltext = data.text;
8011 gapi.interactivepost.render("G-Plus-Share", _gplusOptions);
8012 var btn = document.getElementById("G-Plus-Share");
8013 btn.click()
8014 },
8015 Tumblr: function(data) {
8016 var createTumblrURL = function(url, image, desc, tags) {
8017 var link, i;
8018 var b = "http://tumblr.com/widgets/share/tool?";
8019 var u = "canonicalUrl=" + encode(url);
8020 var d = "caption=" + encode(desc);
8021 if (image) i = "content=" + encode(image);
8022 else i = "content=" + encode(url);
8023 var t = "title=" + encode(_share.title);
8024 var l = "tags=" + encode(tags);
8025 link = b + "posttype=link&" + u + "&" + t + "&" + i + "&" + d + "&" + l + "&shareSource=tumblr_share_button";
8026 return link
8027 };
8028 var url = createTumblrURL(data.url, null, data.text, data.tags);
8029 popWindow(url, data.title, 540, 600)
8030 },
8031 Twitter: function(data) {
8032 var height = 400;
8033 var width = 500;
8034 var url = "https://twitter.com/intent/tweet?text=" + encode(data.text);
8035 popWindow(url, "share", width, height)
8036 }
8037 };
8038 this.exports = {
8039 init: function(config) {
8040 for (var key in config) {
8041 if (!tags[key]) throw "No key " + key + " found in ShareTags";
8042 else tags[key](config)
8043 }
8044 },
8045 share: function(data) {
8046 for (var key in share) {
8047 if (!share[key]) throw "No key " + key + " found in Share";
8048 if (data.type === key.toLowerCase()) share[key](data)
8049 }
8050 }
8051 }
8052});
8053Class(function Sounds() {
8054 Inherit(this, Model);
8055 var _this = this;
8056 var _sounds = [];
8057 var _lastSound;
8058 (function() {
8059 addHandlers()
8060 }());
8061
8062 function addHandlers() {
8063 _this.events.subscribe(HydraEvents.BROWSER_FOCUS, focusHandler)
8064 }
8065
8066 function focusHandler(e) {
8067 if (e.type == "blur") {
8068 _this.forced = Howler.volume();
8069 _this.mute()
8070 } else if (_this.forced) {
8071 _this.unmute()
8072 }
8073 }
8074 this.loadSounds = data => {
8075 data.forEach((d, i) => {
8076 _sounds.push(new Howl({
8077 src: [d.mp3, d.ogg]
8078 }))
8079 })
8080 };
8081 this.mute = function() {
8082 if (!Howler) return;
8083 Howler.mute(true)
8084 };
8085 this.unmute = function() {
8086 if (!Howler) return;
8087 Howler.mute(false)
8088 };
8089 this.play = function(index) {
8090 var sound = _sounds[index];
8091 sound.volume(1);
8092 if (!sound.playing()) sound.play();
8093 if (_lastSound && _lastSound !== sound && _lastSound.playing()) _lastSound.fade(1, 0, 400);
8094 _lastSound = sound
8095 }
8096}, "Static");
8097Class(function TrackUtil() {
8098 Inherit(this, Model);
8099 var _this = this;
8100 var _debug = Storage.get("analytic_debug") || false;
8101 var _dataLayer = [];
8102 var Analytics;
8103 (function() {
8104 initDebug();
8105 defer(initTags)
8106 }());
8107
8108 function initDebug() {
8109 Dev.expose("analyticDebug", setSetBug)
8110 }
8111
8112 function initTags() {
8113 Analytics = require("TrackingTags");
8114 var config = {
8115 Omniture: true
8116 };
8117 Analytics.init(config);
8118 if (Analytics.GoogleTagManager) initDataLayer()
8119 }
8120
8121 function initDataLayer() {}
8122
8123 function setSetBug(bool) {
8124 _debug = bool;
8125 Storage.set("analytic_debug", bool)
8126 }
8127
8128 function trackingRouter(data) {
8129 let name = data.name;
8130 let dynamic = data.dynamic ? data.dynamic : "";
8131 switch (name) {
8132 case "links":
8133 if (dynamic.match(/twitter|facebook|google|tumblr/gi)) {
8134 data.type = "social-click";
8135 data.data = {
8136 social_name: (strPageName.match(/index/gi) ? strSectionName : strPageName) + " : links : " + dynamic
8137 }
8138 } else {
8139 data.type = "promo-interaction";
8140 data.data = {
8141 promo_interaction_name: (strPageName.match(/index/gi) ? strSectionName : strPageName) + " : links : " + dynamic
8142 }
8143 }
8144 break;
8145 case "latest":
8146 data.type = "promo-interaction";
8147 data.data = {
8148 promo_interaction_name: (strPageName.match(/index/gi) ? strSectionName : strPageName) + " : latest" + dynamic
8149 };
8150 break;
8151 case "schedule":
8152 data.type = "promo-interaction";
8153 data.data = {
8154 promo_interaction_name: (strPageName.match(/index/gi) ? strSectionName : strPageName) + " : schedule : " + dynamic
8155 };
8156 break;
8157 case "gallery":
8158 data.type = "promo-interaction";
8159 data.data = {
8160 promo_interaction_name: (strPageName.match(/index/gi) ? strSectionName : strPageName) + " : gallery" + dynamic
8161 };
8162 break;
8163 case "downloads":
8164 data.type = "promo-interaction";
8165 data.data = {
8166 promo_interaction_name: (strPageName.match(/index/gi) ? strSectionName : strPageName) + " : downloads : " + dynamic
8167 };
8168 break;
8169 default:
8170 data.type = "promo-interaction";
8171 data.data = {
8172 promo_interaction_name: (strPageName.match(/index/gi) ? strSectionName : strPageName) + " : " + (dynamic ? name + " : " + dynamic : name)
8173 };
8174 break
8175 }
8176 try {
8177 delete data.name;
8178 delete data.dynamic;
8179 window.trackMetrics(data)
8180 } catch (e) {
8181 console.log("JSMD Error:", e)
8182 }
8183 }
8184 this.page = function(section) {
8185 if (typeof ga !== "undefined") {
8186 if (Analytics.GoogleTagManager) _dataLayer.push({
8187 pageCategory: section
8188 });
8189 if (Analytics.GoogleAnalytics) ga("send", "pageview", section)
8190 }
8191 if (_debug) console.log("EVENT TRACKING>>>>>>>>>>> ", "pageview", section)
8192 };
8193 this.event = function(params) {
8194 if (typeof ga !== "undefined") {
8195 if (Analytics.GoogleTagManager) _dataLayer.push(params);
8196 if (Analytics.GoogleAnalytics) {
8197 var category = params.category;
8198 var action = params.action;
8199 var label = params.label;
8200 ga("send", "event", category, action, label, 0)
8201 }
8202 }
8203 if (Analytics.Omniture) {
8204 trackingRouter(params)
8205 }
8206 if (_debug) {
8207 console.log(">>>>>>>>>>>>>>>>>>>> New Event <<<<<<<<<<<<<<<<<<<");
8208 for (var obj in params) {
8209 var type = params[obj];
8210 console.log(obj + " " + type)
8211 }
8212 console.log(">>>>>>>>>>>>>>>>>>>> End Event <<<<<<<<<<<<<<<<<<<")
8213 }
8214 }
8215}, "Static");
8216Module(function TrackingTags() {
8217 Inherit(this, Component);
8218 var _this = this;
8219 var tags = {
8220 GoogleAnalytics: function(id) {
8221 (function(i, s, o, g, r, a, m) {
8222 i["GoogleAnalyticsObject"] = r;
8223 i[r] = i[r] || function() {
8224 (i[r].q = i[r].q || []).push(arguments)
8225 }, i[r].l = 1 * new Date;
8226 a = s.createElement(o), m = s.getElementsByTagName(o)[0];
8227 a.async = 1;
8228 a.src = g;
8229 m.parentNode.insertBefore(a, m)
8230 }(window, document, "script", "https://www.google-analytics.com/analytics.js", "ga"));
8231 ga("create", id, "auto");
8232 ga("send", "pageview")
8233 },
8234 GoogleTagManager: function(id) {
8235 var iframe = document.createElement("iframe");
8236 iframe.setAttribute("src", "//www.googletagmanager.com/ns.html?id=" + id);
8237 iframe.style.height = 0 + "px";
8238 iframe.style.width = 0 + "px";
8239 iframe.style.display = "none";
8240 iframe.style.visibility = "hidden";
8241 document.body.parentNode.insertBefore(iframe, document.body.nextSibling);
8242 (function(w, d, s, l, i) {
8243 w[l] = w[l] || [];
8244 w[l].push({
8245 "gtm.start": (new Date).getTime(),
8246 event: "gtm.js"
8247 });
8248 var f = d.getElementsByTagName(s)[0],
8249 j = d.createElement(s),
8250 dl = l != "dataLayer" ? "&l=" + l : "";
8251 j.async = true;
8252 j.src = "//www.googletagmanager.com/gtm.js?id=" + i + dl;
8253 f.parentNode.insertBefore(j, f)
8254 }(window, document, "script", "dataLayer", id))
8255 },
8256 Omniture: function() {
8257 var script = document.createElement("script");
8258 script.setAttribute("src", "//www.adultswim.com/.element/js/3.0/jsmd-adbp.js");
8259 document.body.parentNode.insertBefore(script, document.body.nextSibling);
8260 var init = function() {
8261 if (!window.hasOwnProperty("_jsmd")) return _this.delayedCall(init, 250);
8262 window.jsmd = _jsmd.init();
8263 window.pageURL = window.location.href;
8264 window.strPageName = "Index";
8265 window.strSectionName = "Toonami";
8266 window.strSubSectionName = "";
8267 (function() {
8268 "use strict";
8269 var send = true;
8270 var blacklist = ["/.element/ssi/ads.iframes/", "/doubleclick/dartiframe.html", "?fb_xd_fragment#?=&", "/eyeblaster/"];
8271 var i = 0;
8272 while (send && i < blacklist.length) {
8273 if (pageURL.indexOf(blacklist[i]) !== -1) send = false;
8274 i++
8275 }
8276 }())
8277 };
8278 init()
8279 }
8280 };
8281 this.exports = {
8282 init: function(config) {
8283 for (var key in config) {
8284 if (!tags[key]) throw "No key " + key + " found in Analytics";
8285 tags[key](config[key]);
8286 _this.exports[key] = true
8287 }
8288 }
8289 }
8290});
8291Class(function WebGLText(_options) {
8292 Inherit(this, Component);
8293 var _this = this;
8294 var _data, _texture, _shader, _text, _mesh;
8295 var _params = {
8296 font: _options.font,
8297 image: _options.image,
8298 text: _options.text,
8299 vs: _options.vs || "SDFText",
8300 fs: _options.fs || "SDFText",
8301 opacity: _options.opacity && typeof _options.opacity == "number" ? _options.opacity : 1,
8302 color: _options.color || "#fff",
8303 width: _options.width || 1e3,
8304 align: _options.align || "center",
8305 verticalAlign: _options.verticalAlign || "bottom",
8306 letterSpacing: _options.letterSpacing || 0,
8307 lineHeight: _options.lineHeight || null
8308 };
8309 (function() {
8310 initData();
8311 initTexture();
8312 initGeometry();
8313 initShader();
8314 initMesh()
8315 }());
8316
8317 function initData() {
8318 _data = WebGLText.getFont(_params.font)
8319 }
8320
8321 function initTexture() {
8322 _texture = Utils3D.getTexture(_params.image);
8323 _texture.minFilter = THREE.LinearMipMapLinearFilter;
8324 _texture.magFilter = THREE.LinearFilter;
8325 _texture.generateMipmaps = true;
8326 _texture.anisotropy = 16
8327 }
8328
8329 function initGeometry() {
8330 _text = new BMFontText({
8331 text: _params.text,
8332 font: _data,
8333 width: _params.width,
8334 align: _params.align,
8335 letterSpacing: _params.letterSpacing,
8336 lineHeight: _params.lineHeight
8337 });
8338 _text.geometry.rotateZ(Math.PI);
8339 var x = (_params.align == "left" ? 0 : _params.align == "right" ? 1 : .5) * _params.width;
8340 var y = 0;
8341 if (_params.verticalAlign == "top") y = -_text.height;
8342 if (_params.verticalAlign == "middle") y = -.5 * _text.height;
8343 _text.geometry.translate(x, y, 0);
8344 _this.height = _text.height
8345 }
8346
8347 function initShader() {
8348 var combine = function(parent, child) {
8349 if (parent == child) {
8350 parent = parent.replace("#params", "");
8351 parent = parent.replace("#main", "")
8352 } else {
8353 var split = child.split("void main() {");
8354 parent = parent.replace("#params", split[0]);
8355 parent = parent.replace("#main", split[1].slice(0, -1))
8356 }
8357 return parent
8358 };
8359 var vs = Shaders.getShader(_params.vs + ".vs");
8360 var fs = Shaders.getShader(_params.fs + ".fs");
8361 _shader = WebGLText.getShader(vs, fs, _params);
8362 _shader.uniforms.map.value = _texture;
8363 _shader.uniforms.opacity.value = _params.opacity;
8364 _shader.uniforms.count.value = _text.geometry.attributes.letter.count / 4;
8365 _shader.uniforms.color.value = new THREE.Color(_params.color);
8366 _this.shader = _shader
8367 }
8368
8369 function initMesh() {
8370 _mesh = new THREE.Mesh(_text.geometry, _shader.material);
8371 _mesh.frustumCulled = false
8372 }
8373 this.get("mesh", function() {
8374 return _mesh
8375 });
8376 this.get("shader", function() {
8377 return _shader
8378 })
8379}, function() {
8380 var _fonts = {};
8381 var _shaders = {};
8382 WebGLText.getFont = function(font) {
8383 if (_fonts[font]) return _fonts[font];
8384 _fonts[font] = (new BMFontParser).parse(font);
8385 return _fonts[font]
8386 };
8387 WebGLText.getShader = function(vs, fs, params) {
8388 if (_shaders[params.fs + "_" + params.vs]) return _shaders[params.fs + "_" + params.vs].clone();
8389 var shader = new Shader(vs, fs);
8390 shader.uniforms = {
8391 map: {
8392 type: "t",
8393 value: null
8394 },
8395 opacity: {
8396 type: "f",
8397 value: 1
8398 },
8399 count: {
8400 type: "f",
8401 value: 1
8402 },
8403 color: {
8404 type: "c",
8405 value: null
8406 }
8407 };
8408 shader.material.side = THREE.DoubleSide;
8409 shader.material.transparent = true;
8410 shader.material.extensions.derivatives = true;
8411 _shaders[params.fs + "_" + params.vs] = shader;
8412 return shader
8413 }
8414});
8415Class(function BMFontLayout() {
8416 var _this = this;
8417 var prototype = BMFontLayout.prototype;
8418 var X_HEIGHTS = ["x", "e", "a", "o", "n", "s", "r", "c", "u", "m", "v", "w", "z"];
8419 var M_WIDTHS = ["m", "w"];
8420 var CAP_HEIGHTS = ["H", "I", "N", "E", "F", "K", "L", "T", "U", "V", "W", "X", "Y", "Z"];
8421 var TAB_ID = " ".charCodeAt(0);
8422 var SPACE_ID = " ".charCodeAt(0);
8423 var ALIGN_LEFT = 0,
8424 ALIGN_CENTER = 1,
8425 ALIGN_RIGHT = 2;
8426 var wordWrap = new BMFontWordWrap;
8427 var xtend = function(target) {
8428 for (var i = 1; i < arguments.length; i++) {
8429 var source = arguments[i];
8430 for (var key in source) {
8431 if (hasOwnProperty.call(source, key)) {
8432 target[key] = source[key]
8433 }
8434 }
8435 }
8436 return target
8437 };
8438 var findChar = function(property) {
8439 if (!property || typeof property !== "string") throw new Error("must specify property for indexof search");
8440 return new Function("array", "value", "start", ["start = start || 0", "for (var i=start; i<array.length; i++)", ' if (array[i]["' + property + '"] === value)', " return i", "return -1"].join("\n"))
8441 }("id");
8442 var number = function(num, def) {
8443 return typeof num === "number" ? num : typeof def === "number" ? def : 0
8444 };
8445 prototype.init = function(opt) {
8446 this.glyphs = [];
8447 this._measure = this.computeMetrics.bind(this);
8448 this.update(opt)
8449 };
8450 prototype.update = function(opt) {
8451 opt = xtend({
8452 measure: this._measure
8453 }, opt);
8454 this._opt = opt;
8455 this._opt.tabSize = number(this._opt.tabSize, 4);
8456 if (!opt.font) throw new Error("must provide a valid bitmap font");
8457 var glyphs = this.glyphs;
8458 var text = opt.text || "";
8459 var font = opt.font;
8460 this._setupSpaceGlyphs(font);
8461 var lines = wordWrap.lines(text, opt);
8462 var minWidth = opt.width || 0;
8463 glyphs.length = 0;
8464 var maxLineWidth = lines.reduce(function(prev, line) {
8465 return Math.max(prev, line.width, minWidth)
8466 }, 0);
8467 var x = 0;
8468 var y = 0;
8469 var lineHeight = number(opt.lineHeight, font.common.lineHeight);
8470 var baseline = font.common.base;
8471 var descender = lineHeight - baseline;
8472 var letterSpacing = opt.letterSpacing || 0;
8473 var height = lineHeight * lines.length - descender;
8474 var align = getAlignType(this._opt.align);
8475 _this.height = height;
8476 y -= height;
8477 this._width = maxLineWidth;
8478 this._height = height;
8479 this._descender = lineHeight - baseline;
8480 this._baseline = baseline;
8481 this._xHeight = getXHeight(font);
8482 this._capHeight = getCapHeight(font);
8483 this._lineHeight = lineHeight;
8484 this._ascender = lineHeight - descender - this._xHeight;
8485 var self = this;
8486 lines.forEach(function(line, lineIndex) {
8487 var start = line.start;
8488 var end = line.end;
8489 var lineWidth = line.width;
8490 var lastGlyph;
8491 for (var i = start; i < end; i++) {
8492 var id = text.charCodeAt(i);
8493 var glyph = self.getGlyph(font, id);
8494 if (glyph) {
8495 if (lastGlyph) x += getKerning(font, lastGlyph.id, glyph.id);
8496 var tx = x;
8497 if (align === ALIGN_CENTER) tx += (maxLineWidth - lineWidth) / 2;
8498 else if (align === ALIGN_RIGHT) tx += maxLineWidth - lineWidth;
8499 glyphs.push({
8500 position: [tx, y],
8501 data: glyph,
8502 index: i,
8503 line: lineIndex
8504 });
8505 x += glyph.xadvance + letterSpacing;
8506 lastGlyph = glyph
8507 }
8508 }
8509 y += lineHeight;
8510 x = 0
8511 });
8512 this._linesTotal = lines.length;;
8513 };
8514 prototype._setupSpaceGlyphs = function(font) {
8515 this._fallbackSpaceGlyph = null;
8516 this._fallbackTabGlyph = null;
8517 if (!font.chars || font.chars.length === 0) return;
8518 space = getMGlyph(font);
8519 var tabWidth = this._opt.tabSize * space.xadvance;
8520 this._fallbackSpaceGlyph = space;
8521 this._fallbackSpaceGlyph = space;
8522 this._fallbackTabGlyph = xtend(space, {
8523 x: 0,
8524 y: 0,
8525 xadvance: tabWidth,
8526 id: TAB_ID,
8527 xoffset: 0,
8528 yoffset: 0,
8529 width: 0,
8530 height: 0
8531 })
8532 };
8533 prototype.getGlyph = function(font, id) {
8534 var glyph = getGlyphById(font, id);
8535 if (glyph) return glyph;
8536 else if (id === TAB_ID) return this._fallbackTabGlyph;
8537 else if (id === SPACE_ID) return this._fallbackSpaceGlyph;
8538 return null
8539 };
8540 prototype.computeMetrics = function(text, start, end, width) {
8541 var letterSpacing = this._opt.letterSpacing || 0;
8542 var font = this._opt.font;
8543 var curPen = 0;
8544 var curWidth = 0;
8545 var count = 0;
8546 var glyph, lastGlyph;
8547 if (!font.chars || font.chars.length === 0) {
8548 return {
8549 start: start,
8550 end: start,
8551 width: 0
8552 }
8553 }
8554 end = Math.min(text.length, end);
8555 for (var i = start; i < end; i++) {
8556 var id = text.charCodeAt(i);
8557 var glyph = this.getGlyph(font, id);
8558 if (glyph) {
8559 var xoff = glyph.xoffset;
8560 var kern = lastGlyph ? getKerning(font, lastGlyph.id, glyph.id) : 0;
8561 curPen += kern;
8562 var nextPen = curPen + glyph.xadvance + letterSpacing;
8563 var nextWidth = curPen + glyph.width;
8564 if (nextWidth >= width || nextPen >= width) break;
8565 curPen = nextPen;
8566 curWidth = nextWidth;
8567 lastGlyph = glyph
8568 }
8569 count++
8570 }
8571 if (lastGlyph) curWidth += lastGlyph.xoffset;
8572 return {
8573 start: start,
8574 end: start + count,
8575 width: curWidth
8576 }
8577 };
8578 ["width", "height", "descender", "ascender", "xHeight", "baseline", "capHeight", "lineHeight"].forEach(addGetter);
8579
8580 function addGetter(name) {
8581 Object.defineProperty(prototype, name, {
8582 get: wrapper(name),
8583 configurable: true
8584 })
8585 }
8586
8587 function wrapper(name) {
8588 return new Function(["return function " + name + "() {", " return this._" + name, "}"].join("\n"))()
8589 }
8590
8591 function getGlyphById(font, id) {
8592 if (!font.chars || font.chars.length === 0) return null;
8593 var glyphIdx = findChar(font.chars, id);
8594 if (glyphIdx >= 0) return font.chars[glyphIdx];
8595 return null
8596 }
8597
8598 function getXHeight(font) {
8599 for (var i = 0; i < X_HEIGHTS.length; i++) {
8600 var id = X_HEIGHTS[i].charCodeAt(0);
8601 var idx = findChar(font.chars, id);
8602 if (idx >= 0) return font.chars[idx].height
8603 }
8604 return 0
8605 }
8606
8607 function getMGlyph(font) {
8608 return 0
8609 }
8610
8611 function getCapHeight(font) {
8612 for (var i = 0; i < CAP_HEIGHTS.length; i++) {
8613 var id = CAP_HEIGHTS[i].charCodeAt(0);
8614 var idx = findChar(font.chars, id);
8615 if (idx >= 0) return font.chars[idx].height
8616 }
8617 return 0
8618 }
8619
8620 function getKerning(font, left, right) {
8621 if (!font.kernings || font.kernings.length === 0) return 0;
8622 var table = font.kernings;
8623 for (var i = 0; i < table.length; i++) {
8624 var kern = table[i];
8625 if (kern.first === left && kern.second === right) return kern.amount
8626 }
8627 return 0
8628 }
8629
8630 function getAlignType(align) {
8631 if (align === "center") return ALIGN_CENTER;
8632 else if (align === "right") return ALIGN_RIGHT;
8633 return ALIGN_LEFT
8634 }
8635});
8636Class(function BMFontParser() {
8637 Inherit(this, Component);
8638 var _this = this;
8639 (function() {}());
8640
8641 function parse(data) {
8642 if (!data) throw new Error("no data provided");
8643 data = data.toString().trim();
8644 var output = {
8645 pages: [],
8646 chars: [],
8647 kernings: []
8648 };
8649 var lines = data.split(/\r\n?|\n/g);
8650 if (lines.length === 0) throw new Error("no data in BMFont file");
8651 for (var i = 0; i < lines.length; i++) {
8652 var lineData = splitLine(lines[i], i);
8653 if (!lineData) continue;
8654 if (lineData.key === "page") {
8655 if (typeof lineData.data.id !== "number") throw new Error("malformed file at line " + i + " -- needs page id=N");
8656 if (typeof lineData.data.file !== "string") throw new Error("malformed file at line " + i + ' -- needs page file="path"');
8657 output.pages[lineData.data.id] = lineData.data.file
8658 } else if (lineData.key === "chars" || lineData.key === "kernings") {} else if (lineData.key === "char") {
8659 output.chars.push(lineData.data)
8660 } else if (lineData.key === "kerning") {
8661 output.kernings.push(lineData.data)
8662 } else {
8663 output[lineData.key] = lineData.data
8664 }
8665 }
8666 return output
8667 }
8668
8669 function splitLine(line, idx) {
8670 line = line.replace(/\t+/g, " ").trim();
8671 if (!line) return null;
8672 var space = line.indexOf(" ");
8673 if (space === -1) throw new Error("no named row at line " + idx);
8674 var key = line.substring(0, space);
8675 line = line.substring(space + 1);
8676 line = line.replace(/letter=[\'\"]\S+[\'\"]/gi, "");
8677 line = line.split("=");
8678 line = line.map(function(str) {
8679 return str.trim().match(/(".*?"|[^"\s]+)+(?=\s*|\s*$)/g)
8680 });
8681 var data = [];
8682 for (var i = 0; i < line.length; i++) {
8683 var dt = line[i];
8684 if (i === 0) {
8685 data.push({
8686 key: dt[0],
8687 data: ""
8688 })
8689 } else if (i === line.length - 1) {
8690 data[data.length - 1].data = parseData(dt[0])
8691 } else {
8692 data[data.length - 1].data = parseData(dt[0]);
8693 data.push({
8694 key: dt[1],
8695 data: ""
8696 })
8697 }
8698 }
8699 var out = {
8700 key: key,
8701 data: {}
8702 };
8703 data.forEach(function(v) {
8704 out.data[v.key] = v.data
8705 });
8706 return out
8707 }
8708
8709 function parseData(data) {
8710 if (!data || data.length === 0) return "";
8711 if (data.indexOf('"') === 0 || data.indexOf("'") === 0) return data.substring(1, data.length - 1);
8712 if (data.indexOf(",") !== -1) return parseIntList(data);
8713 return parseInt(data, 10)
8714 }
8715
8716 function parseIntList(data) {
8717 return data.split(",").map(function(val) {
8718 return parseInt(val, 10)
8719 })
8720 }
8721 this.parse = function(font) {
8722 var data = Hydra.JSON[font];
8723 if (!data) return console.error("Font has not been loaded:", font);
8724 return parse(data)
8725 }
8726});
8727Class(function BMFontText(_opt) {
8728 Inherit(this, Component);
8729 var _this = this;
8730 var _layout;
8731 (function() {
8732 update()
8733 }());
8734
8735 function update() {
8736 if (!_opt.font) throw new TypeError("must specify a { font } in options");
8737 _layout = new BMFontLayout;
8738 _layout.init(_opt);
8739 _this.height = _layout.height;
8740 var flipY = _opt.flipY !== false;
8741 var font = _opt.font;
8742 var texWidth = font.common.scaleW;
8743 var texHeight = font.common.scaleH;
8744 var glyphs = _layout.glyphs.filter(function(glyph) {
8745 var bitmap = glyph.data;
8746 return bitmap.width * bitmap.height > 0
8747 });
8748 this.visibleGlyphs = glyphs;
8749 var positions = getPositions(glyphs);
8750 var uvs = getUvs(glyphs, texWidth, texHeight, flipY);
8751 var indices = createQuadElements({
8752 clockwise: true,
8753 type: "uint16",
8754 count: glyphs.length
8755 });
8756 var letters = [];
8757 var offsets = [];
8758 var orientations = [];
8759 var scales = [];
8760 var newPositions = [];
8761 var newUvs = [];
8762 indices.forEach(function(index) {
8763 newPositions.push(positions[index * 3 + 0]);
8764 newPositions.push(positions[index * 3 + 1]);
8765 newPositions.push(positions[index * 3 + 2]);
8766 newUvs.push(uvs[index * 2 + 0]);
8767 newUvs.push(uvs[index * 2 + 1]);
8768 letters.push(Math.floor(index / 4) + 1);
8769 offsets.push(0);
8770 offsets.push(0);
8771 offsets.push(0);
8772 orientations.push(0);
8773 orientations.push(0);
8774 orientations.push(0);
8775 orientations.push(1);
8776 scales.push(1)
8777 });
8778 _this.geometry = new THREE.BufferGeometry;
8779 var position = new THREE.BufferAttribute(new Float32Array(newPositions), 3);
8780 var uv = new THREE.BufferAttribute(new Float32Array(newUvs), 2);
8781 var letter = new THREE.BufferAttribute(new Float32Array(letters), 1);
8782 var offset = new THREE.BufferAttribute(new Float32Array(offsets), 3);
8783 var orientation = new THREE.BufferAttribute(new Float32Array(orientations), 4);
8784 var scale = new THREE.BufferAttribute(new Float32Array(scales), 1);
8785 _this.geometry.addAttribute("position", position);
8786 _this.geometry.addAttribute("uv", uv);
8787 _this.geometry.addAttribute("letter", letter);
8788 _this.geometry.addAttribute("offset", offset);
8789 _this.geometry.addAttribute("orientation", orientation);
8790 _this.geometry.addAttribute("scale", scale);
8791 _this.geometry.computeBoundingSphere = computeBoundingSphere;
8792 _this.geometry.computeBoundingBox = computeBoundingBox
8793 }
8794
8795 function pages(glyphs) {
8796 var pages = new Float32Array(glyphs.length * 4 * 1);
8797 var i = 0;
8798 glyphs.forEach(function(glyph) {
8799 var id = glyph.data.page || 0;
8800 pages[i++] = id;
8801 pages[i++] = id;
8802 pages[i++] = id;
8803 pages[i++] = id
8804 });
8805 return pages
8806 }
8807
8808 function getUvs(glyphs, texWidth, texHeight, flipY) {
8809 var uvs = new Float32Array(glyphs.length * 4 * 2);
8810 var i = 0;
8811 glyphs.forEach(function(glyph) {
8812 var bitmap = glyph.data;
8813 var bw = bitmap.x + bitmap.width;
8814 var bh = bitmap.y + bitmap.height;
8815 var u0 = bitmap.x / texWidth;
8816 var u1 = bw / texWidth;
8817 var v1 = (texHeight - bitmap.y) / texHeight;
8818 var v0 = (texHeight - bh) / texHeight;
8819 uvs[i++] = u0;
8820 uvs[i++] = v1;
8821 uvs[i++] = u0;
8822 uvs[i++] = v0;
8823 uvs[i++] = u1;
8824 uvs[i++] = v0;
8825 uvs[i++] = u1;
8826 uvs[i++] = v1
8827 });
8828 return uvs
8829 }
8830
8831 function getPositions(glyphs) {
8832 var positions = new Float32Array(glyphs.length * 3 * 4);
8833 var i = 0;
8834 glyphs.forEach(function(glyph) {
8835 var bitmap = glyph.data;
8836 var x = glyph.position[0] + bitmap.xoffset;
8837 var y = glyph.position[1] + bitmap.yoffset;
8838 var w = bitmap.width;
8839 var h = bitmap.height;
8840 positions[i++] = x;
8841 positions[i++] = y;
8842 positions[i++] = 0;
8843 positions[i++] = x;
8844 positions[i++] = y + h;
8845 positions[i++] = 0;
8846 positions[i++] = x + w;
8847 positions[i++] = y + h;
8848 positions[i++] = 0;
8849 positions[i++] = x + w;
8850 positions[i++] = y;
8851 positions[i++] = 0
8852 });
8853 return positions
8854 }
8855
8856 function dtype(dtype) {
8857 switch (dtype) {
8858 case "int8":
8859 return Int8Array;
8860 case "int16":
8861 return Int16Array;
8862 case "int32":
8863 return Int32Array;
8864 case "uint8":
8865 return Uint8Array;
8866 case "uint16":
8867 return Uint16Array;
8868 case "uint32":
8869 return Uint32Array;
8870 case "float32":
8871 return Float32Array;
8872 case "float64":
8873 return Float64Array;
8874 case "array":
8875 return Array;
8876 case "uint8_clamped":
8877 return Uint8ClampedArray
8878 }
8879 }
8880
8881 function createQuadElements(opt) {
8882 var CW = [0, 2, 3];
8883 var CCW = [2, 1, 3];
8884 var array = null;
8885 var type = typeof opt.type === "string" ? opt.type : "uint16";
8886 var count = typeof opt.count === "number" ? opt.count : 1;
8887 var start = opt.start || 0;
8888 var dir = opt.clockwise !== false ? CW : CCW,
8889 a = dir[0],
8890 b = dir[1],
8891 c = dir[2];
8892 var numIndices = count * 6;
8893 var indices = [];
8894 for (var i = 0, j = 0; i < numIndices; i += 6, j += 4) {
8895 var x = i + start;
8896 indices[x + 0] = j + 0;
8897 indices[x + 1] = j + 1;
8898 indices[x + 2] = j + 2;
8899 indices[x + 3] = j + a;
8900 indices[x + 4] = j + b;
8901 indices[x + 5] = j + c
8902 }
8903 return indices
8904 }
8905 var itemSize = 2;
8906 var box = {
8907 min: [0, 0],
8908 max: [0, 0]
8909 };
8910
8911 function bounds(positions) {
8912 var count = positions.length / itemSize;
8913 box.min[0] = positions[0];
8914 box.min[1] = positions[1];
8915 box.max[0] = positions[0];
8916 box.max[1] = positions[1];
8917 for (var i = 0; i < count; i++) {
8918 var x = positions[i * itemSize + 0];
8919 var y = positions[i * itemSize + 1];
8920 box.min[0] = Math.min(x, box.min[0]);
8921 box.min[1] = Math.min(y, box.min[1]);
8922 box.max[0] = Math.max(x, box.max[0]);
8923 box.max[1] = Math.max(y, box.max[1])
8924 }
8925 }
8926
8927 function computeBoundingSphere() {
8928 if (this.boundingSphere === null) {
8929 this.boundingSphere = new THREE.Sphere
8930 }
8931 var positions = this.attributes.position.array;
8932 var itemSize = this.attributes.position.itemSize;
8933 if (!positions || !itemSize || positions.length < 2) {
8934 this.boundingSphere.radius = 0;
8935 this.boundingSphere.center.set(0, 0, 0);
8936 return
8937 }
8938 var computeSphere = function(positions, output) {
8939 bounds(positions);
8940 var minX = box.min[0];
8941 var minY = box.min[1];
8942 var maxX = box.max[0];
8943 var maxY = box.max[1];
8944 var width = maxX - minX;
8945 var height = maxY - minY;
8946 var length = Math.sqrt(width * width + height * height);
8947 output.center.set(minX + width / 2, minY + height / 2, 0);
8948 output.radius = length / 2
8949 };
8950 computeSphere(positions, this.boundingSphere);
8951 if (isNaN(this.boundingSphere.radius)) {
8952 console.error("THREE.BufferGeometry.computeBoundingSphere(): " + "Computed radius is NaN. The " + '"position" attribute is likely to have NaN values.')
8953 }
8954 }
8955
8956 function computeBoundingBox() {
8957 if (this.boundingBox === null) {
8958 this.boundingBox = new THREE.Box3
8959 }
8960 var bbox = this.boundingBox;
8961 var positions = this.attributes.position.array;
8962 var itemSize = this.attributes.position.itemSize;
8963 if (!positions || !itemSize || positions.length < 2) {
8964 bbox.makeEmpty();
8965 return
8966 }
8967 var computeBox = function(positions, output) {
8968 bounds(positions);
8969 output.min.set(box.min[0], box.min[1], 0);
8970 output.max.set(box.max[0], box.max[1], 0)
8971 };
8972 computeBox(positions, bbox)
8973 }
8974});
8975Class(function BMFontWordWrap() {
8976 var _this = this;
8977 var newline = /\n/;
8978 var newlineChar = "\n";
8979 var whitespace = /\s/;
8980
8981 function idxOf(text, chr, start, end) {
8982 var idx = text.indexOf(chr, start);
8983 if (idx === -1 || idx > end) return end;
8984 return idx
8985 }
8986
8987 function isWhitespace(chr) {
8988 return whitespace.test(chr)
8989 }
8990
8991 function pre(measure, text, start, end, width) {
8992 var lines = [];
8993 var lineStart = start;
8994 for (var i = start; i < end && i < text.length; i++) {
8995 var chr = text.charAt(i);
8996 var isNewline = newline.test(chr);
8997 if (isNewline || i === end - 1) {
8998 var lineEnd = isNewline ? i : i + 1;
8999 var measured = measure(text, lineStart, lineEnd, width);
9000 lines.push(measured);
9001 lineStart = i + 1
9002 }
9003 }
9004 return lines
9005 }
9006
9007 function greedy(measure, text, start, end, width, mode) {
9008 var lines = [];
9009 var testWidth = width;
9010 if (mode === "nowrap") testWidth = Number.MAX_VALUE;
9011 while (start < end && start < text.length) {
9012 var newLine = idxOf(text, newlineChar, start, end);
9013 while (start < newLine) {
9014 if (!isWhitespace(text.charAt(start))) break;
9015 start++
9016 }
9017 var measured = measure(text, start, newLine, testWidth);
9018 var lineEnd = start + (measured.end - measured.start);
9019 var nextStart = lineEnd + newlineChar.length;
9020 if (lineEnd < newLine) {
9021 while (lineEnd > start) {
9022 if (isWhitespace(text.charAt(lineEnd))) break;
9023 lineEnd--
9024 }
9025 if (lineEnd === start) {
9026 if (nextStart > start + newlineChar.length) nextStart--;
9027 lineEnd = nextStart
9028 } else {
9029 nextStart = lineEnd;
9030 while (lineEnd > start) {
9031 if (!isWhitespace(text.charAt(lineEnd - newlineChar.length))) break;
9032 lineEnd--
9033 }
9034 }
9035 }
9036 if (lineEnd >= start) {
9037 var result = measure(text, start, lineEnd, testWidth);
9038 lines.push(result)
9039 }
9040 start = nextStart
9041 }
9042 return lines
9043 }
9044
9045 function monospace(text, start, end, width) {
9046 var glyphs = Math.min(width, end - start);
9047 return {
9048 start: start,
9049 end: start + glyphs
9050 }
9051 }
9052 this.lines = function(text, opt) {
9053 opt = opt || {};
9054 if (opt.width === 0 && opt.mode !== "nowrap") return [];
9055 text = text || "";
9056 var width = typeof opt.width === "number" ? opt.width : Number.MAX_VALUE;
9057 var start = Math.max(0, opt.start || 0);
9058 var end = typeof opt.end === "number" ? opt.end : text.length;
9059 var mode = opt.mode;
9060 var measure = opt.measure || monospace;
9061 if (mode === "pre") return pre(measure, text, start, end, width);
9062 else return greedy(measure, text, start, end, width, mode)
9063 }
9064});
9065Class(function Hardware() {
9066 Inherit(this, Component);
9067 var _this = this;
9068 _this.delayedCall(function() {
9069 _this.BAD_MBP = Device.system.os == "mac" && !Device.graphics.webgl.detect(["nvidia", "amd"]);
9070 _this.NEXUS_4 = GPU.gpu == "adreno (tm) 320";
9071 _this.NEXUS_5 = GPU.gpu == "adreno (tm) 330";
9072 _this.NEXUS_5X = GPU.gpu == "adreno (tm) 418";
9073 _this.NEXUS_6 = GPU.gpu == "adreno (tm) 420";
9074 _this.NEXUS_9 = false;
9075 _this.IPAD_MINI_2 = GPU.gpu == "apple a7 gpu";
9076
9077 function iOSversion() {
9078 if (/iP(hone|od|ad)/.test(navigator.platform)) {
9079 var v = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
9080 return parseInt(v[1], 10)
9081 }
9082 }
9083 _this.IOS_VERSION = iOSversion()
9084 }, 100)
9085}, "Static");
9086Class(function Tests() {
9087 var _this = this;
9088 this.getDPR = () => {
9089 if (GPU.mobileLT(1)) return 1;
9090 if (Hardware.NEXUS_4) return 1;
9091 if (Hardware.IPAD_MINI_2) return 1;
9092 if (Hardware.NEXUS_9) return 1;
9093 if (Device.mobile) return Math.min(Device.pixelRatio, 1.5);
9094 return 1
9095 };
9096 this.isReducedBlur = () => {
9097 if (GPU.lt(1)) return true;
9098 if (Hardware.BAD_MBP) return true;
9099 if (Device.mobile) return true;
9100 return false
9101 };
9102 this.isSmallTimeline = () => {
9103 if (Device.mobile) return true;
9104 return false
9105 };
9106 this.isPermanentPrompts = () => {
9107 if (Device.mobile) return true;
9108 return false
9109 };
9110 this.isWebm = () => {
9111 if (Device.browser.safari) return false;
9112 if (Mobile.os == "iOS") return false;
9113 if (Device.mobile) return true;
9114 if (Device.browser.firefox) return true;
9115 return false
9116 };
9117 this.isDustParticles = () => {
9118 if (GPU.lt(1)) return false;
9119 if (GPU.mobileLT(2)) return false;
9120 if (Hardware.IPAD_MINI_2) return false;
9121 if (Mobile.phone) return false;
9122 return true
9123 };
9124 this.isOverlay = () => {
9125 if (Hardware.NEXUS_4) return false;
9126 return true
9127 };
9128 this.isDustOverlay = () => {
9129 if (GPU.lt(1)) return false;
9130 if (Device.mobile) return false;
9131 return true
9132 };
9133 this.isFallbackBackgroundLinesNoise = () => {
9134 if (GPU.lt(0)) return true;
9135 if (Device.mobile) return true;
9136 return false
9137 };
9138 this.isReducedBackgroundLinesGeometry = () => {
9139 if (GPU.lt(1)) return true;
9140 if (Hardware.BAD_MBP) return true;
9141 if (Device.mobile) return true;
9142 return false
9143 };
9144 this.isReducedMaskSize = () => {
9145 if (GPU.lt(1)) return true;
9146 if (Hardware.BAD_MBP) return true;
9147 if (Device.mobile) return true;
9148 return false
9149 };
9150 this.isRingtoneCircleFallback = () => {
9151 if (GPU.lt(0)) return true;
9152 if (GPU.mobileLT(1)) return true;
9153 if (Hardware.NEXUS_9) return true;
9154 return false
9155 };
9156 this.scrollMultiplier = () => {
9157 if (Device.system.os == "windows" && Device.browser.firefox) return 40;
9158 return 1
9159 };
9160 this.pauseRenderLoaderFade = () => {
9161 if (GPU.lt(0)) return true;
9162 if (GPU.mobileLT(1)) return true;
9163 if (Hardware.NEXUS_9) return true;
9164 if (Hardware.NEXUS_6) return true;
9165 if (Hardware.NEXUS_5) return true;
9166 return false
9167 };
9168 this.includeRingtonesSection = () => {
9169 if (Hardware.NEXUS_9) return false;
9170 return true
9171 };
9172 this.isLessThanIOS10 = () => {
9173 if (Hardware.IOS_VERSION < 10) return true;
9174 return false
9175 };
9176 this.preventVideo = function() {
9177 if (!Device.mobile && Device.browser.safari) return true;
9178 return false
9179 }
9180}, "static");
9181Class(function Data() {
9182 Inherit(this, Model);
9183 var _this = this;
9184 var _data, _tumblr, _videos;
9185 (function() {
9186 _this.waitForData();
9187 loadData()
9188 }());
9189
9190 function loadData() {
9191 let promise = Promise.all([getData(), getTumblr(), getVideos()]);
9192 promise.then(ready)
9193 }
9194
9195 function ready() {
9196 _data.tumblr = _tumblr;
9197 for (var i = 0; i < _data.videos.length; i++) {
9198 if (_data.videos[i].type === "video") {
9199 var id = _data.videos[i].source_mp4;
9200 id = id.split("/");
9201 id = id[id.length - 1].split(".");
9202 id = id[id.length - 2];
9203 for (var j = 0; j < _videos.length; j++) {
9204 if (id === _videos[j].id) {
9205 if (_videos[j].snippet_mp4) _data.videos[i].snippet_mp4 = _videos[j].snippet_mp4;
9206 if (_videos[j].snippet_webm) _data.videos[i].snippet_webm = _videos[j].snippet_webm
9207 }
9208 }
9209 }
9210 }
9211 _this.fulfillData()
9212 }
9213
9214 function getData() {
9215 let promise = Promise.create();
9216 XHR.get(Config.API.data, data => {
9217 _data = data;
9218 var links = _data.menu;
9219 if (links.social && !Array.isArray(links.social)) {
9220 var arr = [];
9221 for (var key in links.social) arr.push({
9222 text: key,
9223 url: links.social[key]
9224 });
9225 links.social = arr
9226 }
9227 for (var key in _data.downloads.ringtones) {
9228 if (_data.downloads.ringtones[key].url) _data.downloads.ringtones[key].mp3 = _data.downloads.ringtones[key].url
9229 }
9230 if (links.questions && !Array.isArray(links.questions)) links.questions = [links.questions];
9231 if (links.boards && !Array.isArray(links.questions)) links.boards = [links.boards];
9232 if (Utils.query("cards")) {
9233 let videos = _this.getVideos();
9234 _data.downloads.cards = videos.slice(Math.max(videos.length - 4))
9235 }
9236 promise.resolve(_data)
9237 });
9238 return promise
9239 }
9240
9241 function getTumblr() {
9242 let promise = Promise.create();
9243 XHR.get(Config.API.tumblr, data => {
9244 _tumblr = data;
9245 promise.resolve()
9246 });
9247 return promise
9248 }
9249
9250 function getVideos() {
9251 let promise = Promise.create();
9252 XHR.get(Config.API.videos, data => {
9253 _videos = data;
9254 promise.resolve()
9255 });
9256 return promise
9257 }
9258 this.getHero = function() {
9259 return Utils.cloneObject(_data.hero)
9260 };
9261 this.getLinks = function() {
9262 return Utils.cloneObject(_data.menu)
9263 };
9264 this.getSchedule = function() {
9265 return Utils.cloneObject(_data.schedule)
9266 };
9267 this.getVideos = function() {
9268 return Utils.cloneObject(_data.videos)
9269 };
9270 this.getTumblr = function() {
9271 return Utils.cloneObject(_data.tumblr)
9272 };
9273 this.getDownloads = function() {
9274 return Utils.cloneObject(_data.downloads)
9275 };
9276 this.getRingtonesDownload = function() {
9277 return _data.downloads.ringtonesDownload.url
9278 }
9279}, "static");
9280Class(function Container() {
9281 Inherit(this, Controller);
9282 var _this = this;
9283 var $container;
9284 var _loader;
9285 (function() {
9286 initContainer();
9287 initLoader();
9288 addHandlers()
9289 }());
9290
9291 function initContainer() {
9292 $container = _this.container;
9293 $container.css({
9294 position: "static"
9295 });
9296 Stage.add($container);
9297 if (Mobile.os == "Android") {}
9298 }
9299
9300 function initLoader() {
9301 _loader = _this.initClass(Loader)
9302 }
9303
9304 function addHandlers() {
9305 _loader.events.add(HydraEvents.COMPLETE, loaded);
9306 _loader.events.add(ToonamiEvents.THREE_LOADED, preloadWebGL)
9307 }
9308
9309 function preloadWebGL() {
9310 World.instance();
9311 Camera.instance();
9312 Lightbox.instance();
9313 $container.add(World.ELEMENT);
9314 Sections.instance().preload();
9315 Intro.instance().preload()
9316 }
9317
9318 function loaded() {
9319 Intro.instance().loaded();
9320 _loader.animateOut(() => _loader = _loader.destroy());
9321 VFX.instance().loaded()
9322 }
9323}, "singleton");
9324Class(function Intro() {
9325 Inherit(this, Component);
9326 var _this = this;
9327 var _logo, _sphere;
9328 this.group = new THREE.Group;
9329 (function() {
9330 addHandlers()
9331 }());
9332
9333 function init() {
9334 initSphere();
9335 initLogo();
9336 Camera.instance().introSetup();
9337 VFX.instance().introSetup();
9338 if (Tests.isDustParticles()) Dust.instance().introSetup();
9339 BackgroundLines.instance().introSetup();
9340 Sections.instance().introSetup();
9341 World.SCENE.add(_this.group)
9342 }
9343
9344 function initSphere() {
9345 _sphere = _this.initClass(UISphere);
9346 _this.group.add(_sphere.group)
9347 }
9348
9349 function initLogo() {
9350 _logo = _this.initClass(IntroLogo);
9351 _this.group.add(_logo.group)
9352 }
9353
9354 function skipIntro() {
9355 Sections.instance().skipIntro()
9356 }
9357
9358 function addHandlers() {
9359 _this.events.subscribe(ToonamiEvents.INTRO_FINISHED, endIntro)
9360 }
9361
9362 function endIntro() {
9363 World.SCENE.remove(_this.group);
9364 _sphere = _sphere.destroy();
9365 _logo = _logo.destroy()
9366 }
9367 this.preload = () => {
9368 if (Utils.query("skip")) return;
9369 init()
9370 };
9371 this.loaded = () => {
9372 if (Utils.query("skip")) {
9373 skipIntro();
9374 return
9375 }
9376 _this.delayedCall(function() {
9377 Camera.instance().introAnimate();
9378 VFX.instance().introAnimate();
9379 if (Tests.isDustParticles()) Dust.instance().introAnimate();
9380 _sphere.animateIn();
9381 _logo.animateIn();
9382 _this.delayedCall(() => {
9383 _sphere.animateOut();
9384 Camera.instance().introEnd();
9385 VFX.instance().introEnd();
9386 BackgroundLines.instance().introEnd();
9387 _this.delayedCall(() => {
9388 Sections.instance().introEnd()
9389 }, 1e3)
9390 }, 55e2);
9391 _this.group.position.z = .05;
9392 _this.group.position.y = -.01;
9393 TweenManager.tween(_this.group.position, {
9394 z: -.05
9395 }, 7e3, "linear")
9396 }, Tests.pauseRenderLoaderFade() ? 500 : 0)
9397 }
9398}, "singleton");
9399Class(function Lightbox() {
9400 Inherit(this, Controller);
9401 var _this = this;
9402 var $container;
9403 var _view;
9404 (function() {
9405 initContainer();
9406 initView();
9407 addListeners()
9408 }());
9409
9410 function initContainer() {
9411 $container = _this.container;
9412 $container.size("100%").hide().setZ(10);
9413 Stage.add($container)
9414 }
9415
9416 function initView() {
9417 _view = _this.initClass(LightboxView)
9418 }
9419
9420 function addListeners() {
9421 _this.events.subscribe(ToonamiEvents.LIGHTBOX_CLOSE, close);
9422 _this.events.subscribe(ToonamiEvents.LIGHTBOX_OPEN, open)
9423 }
9424
9425 function open(e) {
9426 Global.LIGHTBOX_OPEN = true;
9427 $container.show();
9428 _view.element.mouseEnabled(false);
9429 _this.delayedCall(_view.animateIn, 800, e)
9430 }
9431
9432 function close() {
9433 _view.animateOut();
9434 _this.delayedCall(function() {
9435 Global.LIGHTBOX_OPEN = false;
9436 $container.hide()
9437 }, 700)
9438 }
9439 this.animateIn = function() {
9440 open({
9441 src: ""
9442 })
9443 }
9444}, "Singleton");
9445Class(function Loader() {
9446 Inherit(this, View);
9447 var _this = this;
9448 var _loader, _view;
9449 var $this;
9450 (function() {
9451 initHTML();
9452 initView();
9453 initLoader();
9454 addHandlers()
9455 }());
9456
9457 function initHTML() {
9458 $this = _this.element;
9459 $this.css({
9460 position: "static"
9461 })
9462 }
9463
9464 function initView() {
9465 _view = _this.initClass(LoaderView)
9466 }
9467
9468 function initLoader() {
9469 var assets = AssetUtil.getAssets(getAssetList());
9470 _loader = _this.initClass(AssetLoader, assets);
9471 _loader.add(1);
9472 Data.onReady().then(_loader.trigger);
9473 _loader.add(1);
9474 AssetLoader.waitForLib("THREE", () => {
9475 Shaders.onReady().then(() => {
9476 Data.onReady().then(() => {
9477 _this.delayedCall(function() {
9478 _this.events.fire(ToonamiEvents.THREE_LOADED);
9479 _this.delayedCall(_loader.trigger, 100)
9480 }, 100)
9481 })
9482 })
9483 })
9484 }
9485
9486 function getAssetList() {
9487 return ["assets"]
9488 }
9489
9490 function addHandlers() {
9491 _loader.events.add(HydraEvents.PROGRESS, progress);
9492 _loader.events.add(HydraEvents.ERROR, loaderError);
9493 _loader.events.add(HydraEvents.COMPLETE, loaded)
9494 }
9495
9496 function progress(e) {
9497 _view.update(e.percent)
9498 }
9499
9500 function loaderError() {
9501 location.reload()
9502 }
9503
9504 function loaded() {
9505 _loader = null;
9506 _this.events.fire(HydraEvents.COMPLETE)
9507 }
9508 this.animateOut = callback => {
9509 _view.animateOut(callback)
9510 }
9511});
9512Class(function Playground() {
9513 Inherit(this, Controller);
9514 var _this = this;
9515 var $container;
9516 var _view;
9517 (function() {
9518 Global.PLAYGROUND = true;
9519 initContainer();
9520 initThree();
9521 initView()
9522 }());
9523
9524 function initContainer() {
9525 $container = _this.container;
9526 $container.size("100%");
9527 Stage.add($container)
9528 }
9529
9530 function initThree() {
9531 World.instance();
9532 $container.add(World.ELEMENT)
9533 }
9534
9535 function initView() {
9536 var view = "Playground" + Utils.query("playground");
9537 if (!window[view]) throw "No Playground class " + view + " found.";
9538 _view = _this.initClass(window[view]);
9539 World.SCENE.add(_view.group)
9540 }
9541}, "singleton");
9542Class(function Sections() {
9543 Inherit(this, Component);
9544 var _this = this;
9545 var _lines, _dust, _news, _schedule, _gallery, _downloads, _timeline, _nav;
9546 this.group = new THREE.Group;
9547 (function() {}());
9548
9549 function init() {
9550 initBackgroundElements();
9551 initNews();
9552 initSchedule();
9553 initGallery();
9554 initDownloads();
9555 initTimeline();
9556 initNav();
9557 World.SCENE.add(_this.group)
9558 }
9559
9560 function initBackgroundElements() {
9561 _lines = BackgroundLines.instance();
9562 if (Tests.isDustParticles()) {
9563 _dust = Dust.instance();
9564 _dust.init(_this.group)
9565 }
9566 }
9567
9568 function initNews() {
9569 _news = _this.initClass(News);
9570 _this.group.add(_news.group)
9571 }
9572
9573 function initSchedule() {
9574 _schedule = _this.initClass(Schedule);
9575 _this.group.add(_schedule.group)
9576 }
9577
9578 function initGallery() {
9579 _gallery = _this.initClass(Gallery);
9580 _this.group.add(_gallery.group)
9581 }
9582
9583 function initDownloads() {
9584 _downloads = _this.initClass(Downloads);
9585 _this.group.add(_downloads.group)
9586 }
9587
9588 function initTimeline() {
9589 _timeline = SectionsTimeline.instance();
9590 _timeline.init(_this.group, _lines, [_news, _schedule, _gallery, _downloads])
9591 }
9592
9593 function initNav() {
9594 _nav = _this.initClass(Tests.isSmallTimeline() ? NavMobile : Nav, [Stage])
9595 }
9596 this.preload = () => {
9597 init()
9598 };
9599 this.skipIntro = () => {
9600 _timeline.skipIntro();
9601 _this.delayedCall(_nav.animateIn, 500, true)
9602 };
9603 this.introSetup = () => {
9604 _timeline.introSetup()
9605 };
9606 this.introEnd = () => {
9607 _timeline.introEnd();
9608 _this.delayedCall(_nav.animateIn, 15e2)
9609 }
9610}, "singleton");
9611Class(function SectionsTimeline() {
9612 Inherit(this, Component);
9613 var _this = this;
9614 var _group, _lines, _sections;
9615 var _scrollTimer, _titles;
9616 var _conversion = 1 / 170;
9617 var _scrollMultiplier = Tests.scrollMultiplier();
9618 var _num = 0;
9619 var _innerStep = .7;
9620 var _outerStep = 8;
9621 var _views = [];
9622 var _active = 0;
9623 var _lastDelta = 0;
9624 var _speedLimit = .05;
9625 var _time = {
9626 target: 0,
9627 ease: 0
9628 };
9629 var _exploredSection = 1;
9630 this.isSnapped = true;
9631 (function() {}());
9632
9633 function init(group, lines, sections) {
9634 _group = group;
9635 _lines = lines;
9636 _sections = sections;
9637 layout();
9638 initTimeline();
9639 initTitles();
9640 World.CONTROLS.enableZoom = false;
9641 if (Device.mobile) World.CONTROLS.enabled = false;
9642 Mouse.capture()
9643 }
9644
9645 function layout() {
9646 var z = 0;
9647 _sections.forEach((section, sectionIndex) => {
9648 section.min = 1e3;
9649 section.max = 0;
9650 section.startIndex = _num;
9651 section.views.forEach((view, viewIndex) => {
9652 view.timelineIndex = [sectionIndex, viewIndex, section.views.length];
9653 _num++;
9654 view.group.position.z = z;
9655 _views.push(view);
9656 section.min = Math.min(z, section.min);
9657 section.max = Math.max(z, section.max);
9658 z += _innerStep
9659 });
9660 z -= _innerStep;
9661 z += _outerStep
9662 });
9663 VFX.instance().setSections([_sections[0].views.length, _sections[2].views.length, _sections[3].views.length])
9664 }
9665
9666 function initTimeline() {
9667 _time.target = 0;
9668 _time.ease = 0
9669 }
9670
9671 function initTitles() {
9672 _titles = _this.initClass(Titles, _sections, _group)
9673 }
9674
9675 function loop() {
9676 _time.target = Math.max(0, _time.target);
9677 if (_exploredSection < _sections.length) {
9678 _time.target = Math.min(_sections[_exploredSection].startIndex, _time.target)
9679 } else {
9680 _time.target = Math.min(_num - 1, _time.target)
9681 }
9682 var closest = Math.round(_time.target);
9683 _time.target += (closest - _time.target) * (_active == closest ? .02 : .07) * (_this.isScrolling ? .5 : 1);
9684 _time.ease += (_time.target - _time.ease) * .1;
9685 if (!_views[closest]) console.log(closest);
9686 VFX.instance().updateTimeline(_views[closest].timelineIndex, (_time.target - _time.ease) * (getSectionHover(true) === null ? 1 : 0));
9687 Config.CLOSEST_SECTION = _views[closest].timelineIndex[0];
9688 var lower = Math.max(0, Math.min(_num - 1, Math.floor(_time.ease)));
9689 var upper = Math.max(0, Math.min(_num - 1, Math.ceil(_time.ease)));
9690 var perc = _time.ease - lower;
9691 _group.position.z = perc * _views[upper].group.position.z + (1 - perc) * _views[lower].group.position.z;
9692 _group.position.z *= -1;
9693 _sections.every(section => {
9694 if (!section.isActive) return true;
9695 if (_this.isSnapped) return true;
9696 if (_group.position.z < section.min - _innerStep) section.deactivate();
9697 if (_group.position.z > section.max + _innerStep) section.deactivate();
9698 return true
9699 });
9700 _lines.update(_group.position.z);
9701 var speed = Math.abs(_time.ease - _time.target);
9702 Global.SCROLLING = speed > .15;
9703 if (!_this.isScrolling && speed < _speedLimit && !_this.isSnapped && closest >= 0 && closest <= _num - 1) {
9704 _active = closest;
9705 _this.isSnapped = true;
9706 movementEnd()
9707 } else if (speed > _speedLimit && _this.isSnapped) {
9708 _this.isSnapped = false;
9709 movementStart()
9710 }
9711 _views.forEach(view => {
9712 view.updatePosition(_group.position.z)
9713 });
9714 updateTimelineHovers()
9715 }
9716
9717 function updateTimelineHovers() {
9718 if (getSectionHover(true) !== null) Cursor.pointer()
9719 }
9720
9721 function getSectionHover(isQuick) {
9722 var y = Mouse.y / Stage.height;
9723 var step = 12 / Stage.height;
9724 var sectionHeight = 100 / Stage.height;
9725 var spread = Tests.isSmallTimeline() ? .54 : .42;
9726 if (Mobile.phone && Stage.width > Stage.height) spread = .68;
9727 var min = (1 - spread) * .5;
9728 var max = 1 - min;
9729 var width = Tests.isSmallTimeline() ? 60 : 110;
9730 if (Mouse.x > Stage.width - (width - 10) && y > min - sectionHeight * .5 && y < max + sectionHeight * .5) {
9731 if (isQuick) return true;
9732 let closestSection = Math.round(Utils.range(y, min, max, 0, 1, true) * 3);
9733 if (!Tests.isSmallTimeline() && Mouse.x > Stage.width - 60) {
9734 return _sections[closestSection].startIndex
9735 }
9736 let numViews = _sections[closestSection].views.length;
9737 let halfSectionHeight = step * (numViews - 1) * .5;
9738 let sectionY = min + closestSection * (spread / 3);
9739 let closestView = Math.round(Utils.range(y, sectionY - halfSectionHeight, sectionY + halfSectionHeight, 0, 1, true) * (numViews - 1));
9740 return _sections[closestSection].startIndex + closestView
9741 }
9742 return null
9743 }
9744
9745 function addHandlers() {
9746 ScrollUtil.link(onScroll);
9747 _this.events.subscribe(World.CLICK, click);
9748 _this.events.subscribe(KeyboardUtil.UP, keyPress)
9749 }
9750
9751 function onScroll(e) {
9752 if (Global.LIGHTBOX_OPEN) return;
9753 var delta = typeof e.y == "number" ? e.y : e;
9754 var isGreater = Math.abs(delta) > Math.abs(_lastDelta);
9755 _lastDelta = delta;
9756 if (!isGreater && Math.abs(delta) < 50) return;
9757 _this.isScrolling = true;
9758 if (_scrollTimer) clearTimeout(_scrollTimer);
9759 _scrollTimer = _this.delayedCall(scrollEnd, 200);
9760 _time.target += delta * _conversion * _scrollMultiplier
9761 }
9762
9763 function scrollEnd() {
9764 _this.isScrolling = false
9765 }
9766
9767 function movementStart() {
9768 _views.forEach(view => {
9769 if (view.isActive) view.deactivate()
9770 });
9771 _titles.animateIn()
9772 }
9773
9774 function movementEnd() {
9775 _views[_active].activate();
9776 _titles.animateOut();
9777 if (_exploredSection < _sections.length && _active == _sections[_exploredSection].startIndex) _exploredSection++
9778 }
9779
9780 function click() {
9781 var sectionHover = getSectionHover();
9782 if (sectionHover !== null) {
9783 _exploredSection = _sections.length;
9784 _time.target = sectionHover
9785 }
9786 }
9787
9788 function keyPress(e) {
9789 if (e.key == "ArrowUp") _time.target--;
9790 if (e.key == "ArrowLeft") _time.target--;
9791 if (e.key == "ArrowDown") _time.target++;
9792 if (e.key == "ArrowRight") _time.target++;
9793 _time.target = Math.max(0, Math.min(_views.length - 1, _time.target))
9794 }
9795 this.init = init;
9796 this.skipIntro = () => {
9797 defer(() => {
9798 _views[_active].activate()
9799 });
9800 addHandlers();
9801 _this.startRender(loop)
9802 };
9803 this.introSetup = () => {
9804 _group.position.z = 5;
9805 _lines.update(_group.position.z);
9806 _views[_active].introSetup()
9807 };
9808 this.introEnd = () => {
9809 _titles.animateIn();
9810 _views[_active].activate();
9811 var onUpdate = () => {
9812 _views.forEach(view => {
9813 view.updatePosition(_group.position.z)
9814 });
9815 _lines.update(_group.position.z)
9816 };
9817 var onComplete = () => {
9818 _titles.animateOut();
9819 _views[_active].introEnd();
9820 addHandlers();
9821 _this.startRender(loop);
9822 _this.events.fire(ToonamiEvents.INTRO_FINISHED)
9823 };
9824 TweenManager.tween(_group.position, {
9825 z: 0
9826 }, 3e3, "easeOutCubic", 0, onComplete, onUpdate)
9827 };
9828 this.toSection = index => {
9829 _exploredSection = _sections.length;
9830 _time.target = _sections[index].startIndex
9831 }
9832}, "singleton");
9833Class(function Downloads() {
9834 Inherit(this, Component);
9835 var _this = this;
9836 var _cardsData;
9837 var _wallpaperData;
9838 var _ringtoneData;
9839 var _views = [];
9840 this.group = new THREE.Group;
9841 (function() {
9842 initData();
9843 initViews();
9844 if (Tests.includeRingtonesSection()) initRingtones()
9845 }());
9846
9847 function initData() {
9848 _cardsData = Data.getDownloads().cards;
9849 _wallpaperData = Data.getDownloads().wallpapers;
9850 _ringtoneData = Data.getDownloads().ringtones
9851 }
9852
9853 function initViews() {
9854 while (_cardsData.length) {
9855 var view = _this.initClass(DownloadsView, _cardsData.splice(0, 2));
9856 _this.group.add(view.group);
9857 _views.push(view)
9858 }
9859 while (_wallpaperData.length) {
9860 var view = _this.initClass(DownloadsView, _wallpaperData.splice(0, 2));
9861 _this.group.add(view.group);
9862 _views.push(view)
9863 }
9864 _this.views = _views
9865 }
9866
9867 function initRingtones() {
9868 var view = _this.initClass(RingtonesView, _ringtoneData);
9869 _this.group.add(view.group);
9870 _views.push(view)
9871 }
9872 this.activate = () => {
9873 if (_this.isActive) return;
9874 _this.isActive = true;
9875 _views.forEach(view => {
9876 view.sectionActivate()
9877 })
9878 };
9879 this.deactivate = () => {
9880 _this.isActive = false;
9881 _views.forEach(view => {
9882 view.sectionDeactivate()
9883 })
9884 }
9885});
9886Class(function Gallery() {
9887 Inherit(this, Component);
9888 var _this = this;
9889 var _data;
9890 var _views = [];
9891 this.group = new THREE.Group;
9892 (function() {
9893 initData();
9894 initViews()
9895 }());
9896
9897 function initData() {
9898 _data = Data.getTumblr().slice(0, 12)
9899 }
9900
9901 function initViews() {
9902 while (_data.length) {
9903 var view = _this.initClass(GalleryView, _data.splice(0, 2));
9904 _this.group.add(view.group);
9905 _views.push(view)
9906 }
9907 _this.views = _views
9908 }
9909 this.activate = () => {
9910 if (_this.isActive) return;
9911 _this.isActive = true;
9912 _views.forEach(view => {
9913 view.sectionActivate()
9914 })
9915 };
9916 this.deactivate = () => {
9917 _this.isActive = false;
9918 _views.forEach(view => {
9919 view.sectionDeactivate()
9920 })
9921 }
9922});
9923Class(function HamburgerButton() {
9924 Inherit(this, Controller);
9925 var _this = this;
9926 var $container;
9927 var _lines;
9928 (function() {
9929 initContainer();
9930 initLines();
9931 addListeners();
9932 resizeHandler()
9933 }());
9934
9935 function initContainer() {
9936 $container = _this.container;
9937 $container.size(34, 34).css({
9938 border: "1px solid #a3d8ad",
9939 top: 32,
9940 right: 11
9941 }).bg("#00000f").setZ(500).invisible();
9942 Stage.add($container)
9943 }
9944
9945 function initLines() {
9946 _lines = [];
9947 for (var i = 0; i < 3; i++) {
9948 var $line = $container.create(".line");
9949 $line.size(16, 2).center().bg("#a3d8ad").css({
9950 marginTop: -5 + 4 * i
9951 });
9952 _lines.push($line)
9953 }
9954 }
9955
9956 function addListeners() {
9957 $container.interact(hover, click);
9958 _this.events.subscribe(HydraEvents.RESIZE, resizeHandler);
9959 _this.events.subscribe(ToonamiEvents.LIGHTBOX_CLOSE, lightboxClose);
9960 _this.events.subscribe(ToonamiEvents.LIGHTBOX_OPEN, lightboxOpen)
9961 }
9962
9963 function resizeHandler() {
9964 if (Stage.width > Stage.height) {
9965 $container.css({
9966 top: 20,
9967 right: "",
9968 left: 20
9969 })
9970 } else {
9971 $container.css({
9972 top: 32,
9973 right: 11,
9974 left: ""
9975 })
9976 }
9977 }
9978
9979 function lightboxClose() {
9980 $container.tween({
9981 opacity: 1
9982 }, 600, "easeOutSine")
9983 }
9984
9985 function lightboxOpen() {
9986 $container.tween({
9987 opacity: 0
9988 }, 600, "easeOutSine")
9989 }
9990
9991 function hover() {}
9992
9993 function click() {
9994 if (MobileMenu.instance().visible) MobileMenu.instance().animateOut();
9995 else MobileMenu.instance().animateIn()
9996 }
9997 this.animateIn = function() {
9998 $container.visible().transform({
9999 scale: .5
10000 }).css({
10001 opacity: 0
10002 }).tween({
10003 opacity: 1,
10004 scale: 1
10005 }, 1e3, "easeOutCubic");
10006 for (var i = 0; i < _lines.length; i++) {
10007 _lines[i].transform({
10008 scaleX: 0
10009 }).tween({
10010 scaleX: 1
10011 }, 600, "easeInOutCubic", i * 200 + 200)
10012 }
10013 };
10014 this.activate = function() {
10015 _lines[0].tween({
10016 rotation: 45,
10017 y: 4
10018 }, 500, "easeOutCubic");
10019 _lines[1].tween({
10020 opacity: 0
10021 }, 500, "easeOutCubic");
10022 _lines[2].tween({
10023 rotation: -45,
10024 y: -4
10025 }, 500, "easeOutCubic")
10026 };
10027 this.deactivate = function() {
10028 _lines[0].tween({
10029 rotation: 0,
10030 y: 0
10031 }, 500, "easeOutCubic");
10032 _lines[1].tween({
10033 opacity: 1
10034 }, 500, "easeOutCubic");
10035 _lines[2].tween({
10036 rotation: 0,
10037 y: 0
10038 }, 500, "easeOutCubic")
10039 }
10040}, "Singleton");
10041Class(function MobileMenu() {
10042 Inherit(this, Controller);
10043 var _this = this;
10044 var $container, $bg;
10045 var _view;
10046 (function() {
10047 initContainer();
10048 initView()
10049 }());
10050
10051 function initContainer() {
10052 $container = _this.container;
10053 $container.size("100%").hide().setZ(20);
10054 Stage.add($container);
10055 $bg = $container.create(".bg");
10056 $bg.size("100%").bg("#000").css({
10057 opacity: .85
10058 })
10059 }
10060
10061 function initView() {
10062 _view = _this.initClass(MobileMenuView)
10063 }
10064 this.animateIn = function() {
10065 _this.visible = true;
10066 HamburgerButton.instance().activate();
10067 _view.animateIn();
10068 $container.show().css({
10069 opacity: 0
10070 }).transform({
10071 scale: 1.1
10072 }).tween({
10073 opacity: 1,
10074 scale: 1
10075 }, 500, "easeOutSine")
10076 };
10077 this.animateOut = function() {
10078 _this.visible = false;
10079 HamburgerButton.instance().deactivate();
10080 $container.tween({
10081 opacity: 0,
10082 scale: 1.1
10083 }, 500, "easeOutSine", function() {
10084 $container.hide()
10085 })
10086 }
10087}, "Singleton");
10088Class(function Nav() {
10089 Inherit(this, Controller);
10090 var _this = this;
10091 var $container, $logo, $time;
10092 var _main, _links, _fansites, _share, _timeline;
10093 var _scale = .38;
10094 (function() {
10095 initContainer();
10096 initLogo();
10097 initViews();
10098 initShare();
10099 initTimeline();
10100 addListeners()
10101 }());
10102
10103 function initContainer() {
10104 $container = _this.container;
10105 $container.css({
10106 position: "static"
10107 }).invisible()
10108 }
10109
10110 function initLogo() {
10111 $logo = $container.create(".logo");
10112 $logo.size(11e2 * _scale, 140 * _scale).bg(Config.CDN + "assets/images/ui/logo.png").css({
10113 top: 27,
10114 left: 27
10115 });
10116 $time = $logo.create(".time");
10117 $time.fontStyle("GothamRnd", 12, "#89f8e5");
10118 $time.size(145, 140 * _scale).css({
10119 top: 35 * _scale,
10120 right: 0,
10121 letterSpacing: 1.5,
10122 opacity: .5
10123 })
10124 }
10125
10126 function initViews() {
10127 var data = Data.getLinks();
10128 var main = [];
10129 for (var i = 0; i < data.top.length; i++) main.push(data.top[i]);
10130 main.push({
10131 text: "LINKS",
10132 dropdown: true
10133 });
10134 main.push({
10135 text: "FAN SITES",
10136 dropdown: true
10137 });
10138 _main = _this.initClass(NavView, main);
10139 var fansites = [];
10140 for (var i = 0; i < data.fan_sites.length; i++) fansites.push(data.fan_sites[i]);
10141 _fansites = _this.initClass(NavView, fansites);
10142 _fansites.element.css({
10143 top: 90
10144 });
10145 var links = [];
10146 if (data.links)
10147 for (var i = 0; i < data.links.length; i++) links.push(data.links[i]);
10148 _links = _this.initClass(NavView, links);
10149 _links.element.css({
10150 top: 90
10151 })
10152 }
10153
10154 function initShare() {
10155 _share = _this.initClass(NavShare)
10156 }
10157
10158 function initTimeline() {
10159 _timeline = _this.initClass(NavTimeline)
10160 }
10161
10162 function addListeners() {
10163 _this.events.subscribe(HydraEvents.RESIZE, resize);
10164 resize();
10165 _main.events.add(HydraEvents.HOVER, mainHover);
10166 _this.events.subscribe(ToonamiEvents.LIGHTBOX_CLOSE, lightboxClose);
10167 _this.events.subscribe(ToonamiEvents.LIGHTBOX_OPEN, lightboxOpen);
10168 Stage.bind("touchmove", move)
10169 }
10170
10171 function resize() {
10172 var data = Data.getSchedule();
10173 let textInput;
10174 if (Stage.width > 1e3) {
10175 textInput = `${data.block_day} ${data.block_times}`;
10176 $time.css({
10177 width: 230,
10178 top: 20,
10179 right: -80
10180 })
10181 } else {
10182 textInput = `${data.block_day}<br />${data.block_times}`;
10183 $time.css({
10184 width: 145,
10185 top: 35 * _scale,
10186 right: 0
10187 })
10188 }
10189 textInput = textInput.toUpperCase();
10190 $time.div.innerHTML = textInput
10191 }
10192
10193 function lightboxClose() {
10194 $container.visible().tween({
10195 opacity: 1
10196 }, 1e3, "easeInOutSine", 500)
10197 }
10198
10199 function lightboxOpen() {
10200 $container.tween({
10201 opacity: 0
10202 }, 1e3, "easeInOutSine", function() {
10203 $container.invisible()
10204 })
10205 }
10206
10207 function mainHover(e) {
10208 if (e.action == "over") {
10209 if (e.text == "LINKS" && !_links.visible) {
10210 _main.activate(e.text);
10211 _links.animateIn();
10212 if (_fansites.visible) _fansites.animateOut()
10213 } else if (e.text == "FAN SITES" && !_fansites.visible) {
10214 _main.activate(e.text);
10215 _fansites.animateIn();
10216 if (_links.visible) _links.animateOut()
10217 }
10218 }
10219 if (e.text !== "LINKS" && e.text !== "FAN SITES") {
10220 _main.deactivate();
10221 if (_fansites.visible) _fansites.animateOut();
10222 if (_links.visible) _links.animateOut()
10223 }
10224 }
10225
10226 function move() {
10227 if ((Mouse.x < Stage.width - 600 || Mouse.y > 170) && (_links.visible || _fansites.visible)) {
10228 _main.deactivate();
10229 _links.animateOut();
10230 _fansites.animateOut()
10231 }
10232 }
10233 this.animateIn = function(skip) {
10234 $container.visible();
10235 $logo.css({
10236 opacity: 0
10237 }).tween({
10238 opacity: 1
10239 }, 2e3, "easeOutSine");
10240 _this.delayedCall(_main.animateIn, 200);
10241 _this.delayedCall(_share.animateIn, 300);
10242 _this.delayedCall(_timeline.animateIn, skip ? 300 : 1e3)
10243 }
10244});
10245Class(function NavMobile() {
10246 Inherit(this, Controller);
10247 var _this = this;
10248 var $container, $logo1, $logo2;
10249 var _main, _sub, _share, _timeline;
10250 (function() {
10251 initContainer();
10252 initLogo();
10253 addListeners();
10254 resizeHandler()
10255 }());
10256
10257 function initContainer() {
10258 $container = _this.container;
10259 $container.css({
10260 position: "static"
10261 }).setZ(2).invisible()
10262 }
10263
10264 function initLogo() {
10265 var scale = .27;
10266 $logo1 = $container.create(".logo");
10267 $logo1.size(800 * scale, 200 * scale).center(1, 0).bg(Config.CDN + "assets/images/ui/logo-mobile.png").css({
10268 marginLeft: -400 * scale - 10,
10269 top: 25
10270 });
10271 Global.MOBILE_LOGO = $logo1;
10272 var data = Data.getSchedule();
10273 var textInput = data.block_day + " " + data.block_times;
10274 textInput = textInput.toUpperCase();
10275 var $time = $logo1.create(".time");
10276 $time.fontStyle("GothamRnd", 9, "#95dba9");
10277 $time.size("100%", 15).css({
10278 bottom: 0,
10279 textAlign: "center",
10280 letterSpacing: 1.5,
10281 opacity: .5
10282 });
10283 $time.html(textInput)
10284 }
10285
10286 function addListeners() {
10287 _this.events.subscribe(ToonamiEvents.LIGHTBOX_CLOSE, lightboxClose);
10288 _this.events.subscribe(ToonamiEvents.LIGHTBOX_OPEN, lightboxOpen);
10289 _this.events.subscribe(HydraEvents.RESIZE, resizeHandler)
10290 }
10291
10292 function resizeHandler() {
10293 if (Stage.width > Stage.height) {
10294 $logo1.css({
10295 top: 15
10296 })
10297 } else {
10298 $logo1.css({
10299 opacity: 1,
10300 top: 25
10301 })
10302 }
10303 }
10304
10305 function lightboxClose() {
10306 $logo1.show();
10307 $logo1.tween({
10308 opacity: 1
10309 }, 600, "easeOutSine")
10310 }
10311
10312 function lightboxOpen() {
10313 $logo1.tween({
10314 opacity: 0
10315 }, 600, "easeOutSine", function() {
10316 $logo1.hide()
10317 })
10318 }
10319 this.animateIn = function() {
10320 $container.visible();
10321 HamburgerButton.instance().animateIn();
10322 $logo1.css({
10323 opacity: 0
10324 }).tween({
10325 opacity: 1
10326 }, 2e3, "easeOutSine")
10327 }
10328});
10329Class(function News() {
10330 Inherit(this, Component);
10331 var _this = this;
10332 var _data;
10333 var _views = [];
10334 this.group = new THREE.Group;
10335 (function() {
10336 initData();
10337 initViews()
10338 }());
10339
10340 function initData() {
10341 _data = Data.getVideos()
10342 }
10343
10344 function initViews() {
10345 while (_data.length) {
10346 var view = _this.initClass(NewsView, _data.splice(0, 2));
10347 _this.group.add(view.group);
10348 _views.push(view)
10349 }
10350 _this.views = _views
10351 }
10352 this.activate = () => {
10353 if (_this.isActive) return;
10354 _this.isActive = true;
10355 _views.forEach(view => {
10356 view.sectionActivate()
10357 })
10358 };
10359 this.deactivate = () => {
10360 _this.isActive = false;
10361 _views.forEach(view => {
10362 view.sectionDeactivate()
10363 })
10364 }
10365});
10366Class(function Schedule() {
10367 Inherit(this, Component);
10368 var _this = this;
10369 var _data, _nav;
10370 var _views = [];
10371 this.group = new THREE.Group;
10372 (function() {
10373 initData();
10374 initViews()
10375 }());
10376
10377 function initData() {
10378 _data = Data.getSchedule().schedule
10379 }
10380
10381 function initViews() {
10382 var view = _this.initClass(ScheduleView, _data);
10383 _this.group.add(view.group);
10384 _views.push(view);
10385 _this.views = _views;
10386 _nav = _this.initClass(ScheduleNav, view, [Stage])
10387 }
10388 this.activate = () => {
10389 if (_this.isActive) return;
10390 _this.isActive = true;
10391 _views.forEach(view => {
10392 view.sectionActivate()
10393 });
10394 if (_nav) _nav.animateIn()
10395 };
10396 this.deactivate = () => {
10397 _this.isActive = false;
10398 _views.forEach(view => {
10399 view.sectionDeactivate()
10400 });
10401 if (_nav) _nav.animateOut()
10402 }
10403});
10404Class(function Camera() {
10405 Inherit(this, Component);
10406 var _this = this;
10407 var _camera;
10408 var _initial = new THREE.Vector3;
10409 var _cameraMouse = new THREE.Vector3;
10410 var _targetShake = new THREE.Vector3;
10411 var _cameraLightbox = new THREE.Vector3;
10412 var _targetLightbox = new THREE.Vector3;
10413 var _cameraEase = new THREE.Vector3;
10414 var _targetEase = new THREE.Vector3;
10415 var _cameraResize = new THREE.Vector3;
10416 var _anim = new DynamicObject({
10417 targetOffset: .02,
10418 ease: .05
10419 });
10420 (function() {
10421 initCamera();
10422 _this.startRender(loop);
10423 addHandlers();
10424 resize()
10425 }());
10426
10427 function initCamera() {
10428 _camera = World.CAMERA;
10429 _camera.target = new THREE.Vector3;
10430 _initial.copy(_camera.position);
10431 _cameraLightbox.copy(_camera.position);
10432 World.CONTROLS.enabled = false
10433 }
10434
10435 function loop(t, dt) {
10436 var shiftY = .3;
10437 var mouseY = _initial.y + Utils.range(Mouse.y, 0, Stage.height, -shiftY, 0);
10438 _cameraMouse.y += (mouseY - _cameraMouse.y) * .005;
10439 var shakeX = .02;
10440 var shakeY = .02;
10441 var targetX = Math.sin(dt * .0005) * shakeX + _anim.targetOffset;
10442 var targetY = Math.sin(dt * .00065 + 2.34) * shakeY;
10443 _targetShake.x += (targetX - _targetShake.x) * .01;
10444 _targetShake.y += (targetY - _targetShake.y) * .01;
10445 _cameraEase.copy(_cameraLightbox);
10446 _targetEase.copy(_targetLightbox);
10447 _cameraEase.add(_cameraMouse);
10448 _targetEase.add(_targetShake);
10449 _cameraEase.add(_cameraResize);
10450 _camera.position.lerp(_cameraEase, _anim.ease);
10451 _camera.target.lerp(_targetEase, .05);
10452 _camera.lookAt(_camera.target)
10453 }
10454
10455 function addHandlers() {
10456 _this.events.subscribe(HydraEvents.RESIZE, resize);
10457 _this.events.subscribe(ToonamiEvents.LIGHTBOX_OPEN, toLightbox);
10458 _this.events.subscribe(ToonamiEvents.LIGHTBOX_CLOSE, fromLightbox)
10459 }
10460
10461 function resize() {
10462 var ratio = Stage.width / Stage.height;
10463 var portrait = Device.mobile && Stage.width < Stage.height;
10464 if (!Device.mobile) {
10465 _cameraResize.z = Utils.range(ratio, 1, 1.4, .4, 0, true);
10466 if (ratio > 1.5) _cameraResize.z = Utils.range(ratio, 1.5, 2, 0, -.25, true)
10467 }
10468 if (Device.mobile && portrait) _cameraResize.z = Utils.range(ratio, .5, 1, .6, .3, true);
10469 if (Device.mobile && !portrait) _cameraResize.z = 0;
10470 if (!Device.mobile) _cameraResize.z += .1
10471 }
10472
10473 function toLightbox() {
10474 TweenManager.tween(_cameraLightbox, {
10475 y: _initial.y - .8,
10476 z: _initial.z
10477 }, 600, "easeInOutQuart");
10478 TweenManager.tween(_targetLightbox, {
10479 y: 0,
10480 z: -1.5
10481 }, 600, "easeInOutQuart")
10482 }
10483
10484 function fromLightbox() {
10485 TweenManager.tween(_cameraLightbox, {
10486 y: _initial.y,
10487 z: _initial.z
10488 }, 600, "easeInOutQuart");
10489 TweenManager.tween(_targetLightbox, {
10490 y: 0,
10491 z: 0
10492 }, 600, "easeInOutQuart")
10493 }
10494 this.introSetup = () => {
10495 _anim.ease = .1;
10496 _anim.targetOffset = 0;
10497 _cameraLightbox.z = _initial.z - .28
10498 };
10499 this.introAnimate = () => {
10500 TweenManager.tween(_cameraLightbox, {
10501 z: _initial.z
10502 }, 15e2, "easeInOutQuart", 15e2)
10503 };
10504 this.introEnd = () => {
10505 _anim.tween({
10506 ease: .05,
10507 targetOffset: .02
10508 }, 3e3, "easeInOutCubic")
10509 }
10510}, "singleton");
10511Class(function World() {
10512 Inherit(this, Component);
10513 var _this = this;
10514 var _renderer, _scene, _camera, _controls, _vfx;
10515 (function() {
10516 initWorld();
10517 initVFX();
10518 initControls();
10519 initBackground();
10520 addHandlers();
10521 Render.start(loop)
10522 }());
10523
10524 function initWorld() {
10525 _renderer = new THREE.WebGLRenderer({
10526 antialias: false
10527 });
10528 _renderer.setPixelRatio(Tests.getDPR());
10529 _renderer.setSize(Stage.width, Stage.height);
10530 _renderer.setClearColor("#00000f");
10531 _scene = new THREE.Scene;
10532 _camera = new THREE.PerspectiveCamera(45, Stage.width / Stage.height, .01, 50);
10533 _scene.add(_camera);
10534 World.SCENE = _scene;
10535 World.RENDERER = _renderer;
10536 World.ELEMENT = $(_renderer.domElement);
10537 World.CAMERA = _camera;
10538 World.TIME = {
10539 value: 0
10540 }
10541 }
10542
10543 function initVFX() {
10544 _vfx = VFX.instance(_renderer, _scene, _camera)
10545 }
10546
10547 function initControls() {
10548 _camera.position.set(0, .2, .95);
10549 _controls = new THREE.OrbitControls(_camera, World.ELEMENT.div);
10550 _this.initClass(WorldInteraction);
10551 World.CONTROLS = _controls
10552 }
10553
10554 function initBackground() {
10555 Background.instance()
10556 }
10557
10558 function addHandlers() {
10559 _this.events.subscribe(HydraEvents.RESIZE, resize)
10560 }
10561
10562 function resize() {
10563 _renderer.setSize(Stage.width, Stage.height);
10564 _camera.aspect = Stage.width / Stage.height;
10565 _camera.updateProjectionMatrix()
10566 }
10567
10568 function loop(t, dt, delta) {
10569 _this.TIME = dt;
10570 World.TIME.value += delta * .001;
10571 if (_this.isPaused) return;
10572 if (_controls && _controls.enabled) _controls.update();
10573 _vfx.render()
10574 }
10575 this.pause = () => {
10576 _this.isPaused = true
10577 };
10578 this.resume = () => {
10579 _this.isPaused = false
10580 }
10581}, function() {
10582 World.CLICK = "world_click";
10583 var _instance;
10584 World.instance = function() {
10585 if (!_instance) _instance = new World;
10586 return _instance
10587 }
10588});
10589Class(function WorldInteraction() {
10590 Inherit(this, Component);
10591 var _this = this;
10592 var _interaction;
10593 (function() {
10594 initInteraction();
10595 addHandlers()
10596 }());
10597
10598 function initInteraction() {
10599 _interaction = _this.initClass(Interaction.Input, World.ELEMENT)
10600 }
10601
10602 function addHandlers() {
10603 _interaction.onStart = onStart;
10604 _interaction.onUpdate = onUpdate;
10605 _interaction.onEnd = onEnd;
10606 _interaction.onClick = onClick
10607 }
10608
10609 function onStart(e) {}
10610
10611 function onUpdate(e) {}
10612
10613 function onEnd(e) {}
10614
10615 function onClick(e) {
10616 _this.events.fire(World.CLICK, e)
10617 }
10618});
10619Class(function Background() {
10620 Inherit(this, Component);
10621 var _this = this;
10622 var _geometry, _shader, _mesh;
10623 var _targetColor1 = new THREE.Color(Config.BG_COLORS[0][0]);
10624 var _targetColor2 = new THREE.Color(Config.BG_COLORS[0][0]);
10625 var _targetColor3 = new THREE.Color(Config.BG_COLORS[0][0]);
10626 var _targetColor4 = new THREE.Color(Config.BG_COLORS[0][0]);
10627 (function() {
10628 initGeometry();
10629 initShader();
10630 initMesh();
10631 _this.startRender(loop)
10632 }());
10633
10634 function initGeometry() {
10635 _geometry = new THREE.PlaneBufferGeometry(2, 2)
10636 }
10637
10638 function initShader() {
10639 _shader = _this.initClass(Shader, "Background", "Background");
10640 _shader.uniforms = {
10641 fTime: {
10642 type: "f",
10643 value: 0
10644 },
10645 uColor1: {
10646 type: "c",
10647 value: new THREE.Color(Config.BG_COLORS[0][0])
10648 },
10649 uColor2: {
10650 type: "c",
10651 value: new THREE.Color(Config.BG_COLORS[0][1])
10652 },
10653 uColor3: {
10654 type: "c",
10655 value: new THREE.Color(Config.BG_COLORS[0][2])
10656 },
10657 uColor4: {
10658 type: "c",
10659 value: new THREE.Color(Config.BG_COLORS[0][3])
10660 }
10661 };
10662 _shader.material.depthWrite = false
10663 }
10664
10665 function initMesh() {
10666 _mesh = new THREE.Mesh(_geometry, _shader.material);
10667 World.SCENE.add(_mesh)
10668 }
10669
10670 function loop(t, dt) {
10671 _shader.set("fTime", dt * .001);
10672 updateColors()
10673 }
10674
10675 function updateColors() {
10676 if (_targetColor1.current !== Config.CLOSEST_SECTION) {
10677 _targetColor1.current = Config.CLOSEST_SECTION;
10678 _targetColor1.set(Config.BG_COLORS[Config.CLOSEST_SECTION][0]);
10679 _targetColor2.set(Config.BG_COLORS[Config.CLOSEST_SECTION][1]);
10680 _targetColor3.set(Config.BG_COLORS[Config.CLOSEST_SECTION][2]);
10681 _targetColor4.set(Config.BG_COLORS[Config.CLOSEST_SECTION][3])
10682 }
10683 _shader.uniforms.uColor1.value.lerp(_targetColor1, .01);
10684 _shader.uniforms.uColor2.value.lerp(_targetColor2, .01);
10685 _shader.uniforms.uColor3.value.lerp(_targetColor3, .01);
10686 _shader.uniforms.uColor4.value.lerp(_targetColor4, .01)
10687 }
10688}, "singleton");
10689Class(function BackgroundLines() {
10690 Inherit(this, Component);
10691 var _this = this;
10692 var _raycaster, _geometry, _shader, _mesh, _hitMesh;
10693 var _progess = 0;
10694 var _mouseUV = new THREE.Vector2(-1, -1);
10695 var _velocity = 0;
10696 var _timescale = 1;
10697 var _targetColor1 = new THREE.Color(Config.LINE_COLORS[0][0]);
10698 var _targetColor2 = new THREE.Color(Config.LINE_COLORS[0][0]);
10699 var _targetColor3 = new THREE.Color(Config.LINE_COLORS[0][0]);
10700 var _targetColor4 = new THREE.Color(Config.LINE_COLORS[0][0]);
10701 var _targetColor5 = new THREE.Color(Config.LINE_COLORS[0][0]);
10702 (function() {
10703 initRaycaster();
10704 initGeometry();
10705 initShader();
10706 initMesh();
10707 _this.startRender(loop);
10708 addHandlers();
10709 Mouse.capture()
10710 }());
10711
10712 function initRaycaster() {
10713 _raycaster = _this.initClass(Raycaster, World.CAMERA);
10714 _hitMesh = new THREE.Mesh(new THREE.PlaneBufferGeometry(4, 8, 1, 1), new THREE.MeshBasicMaterial);
10715 var group = new THREE.Group;
10716 group.add(_hitMesh);
10717 group.visible = false;
10718 World.SCENE.add(group)
10719 }
10720
10721 function initGeometry() {
10722 var w = 200;
10723 var h = 400;
10724 if (Tests.isReducedBackgroundLinesGeometry()) {
10725 w = 80;
10726 h = 160
10727 }
10728 _geometry = new THREE.PlaneBufferGeometry(8, 10, w, h)
10729 }
10730
10731 function initShader() {
10732 _shader = _this.initClass(Shader, "BackgroundLines", "BackgroundLines");
10733 _shader.uniforms = {
10734 fTime: {
10735 type: "f",
10736 value: 0
10737 },
10738 fProgress: {
10739 type: "f",
10740 value: 0
10741 },
10742 uMouse: {
10743 type: "v2",
10744 value: new THREE.Vector2(-1, -1)
10745 },
10746 fVelocity: {
10747 type: "f",
10748 value: 0
10749 },
10750 fFade: {
10751 type: "f",
10752 value: 1
10753 },
10754 uColor1: {
10755 type: "c",
10756 value: new THREE.Color(Config.LINE_COLORS[0][0])
10757 },
10758 uColor2: {
10759 type: "c",
10760 value: new THREE.Color(Config.LINE_COLORS[0][1])
10761 },
10762 uColor3: {
10763 type: "c",
10764 value: new THREE.Color(Config.LINE_COLORS[0][2])
10765 },
10766 uColor4: {
10767 type: "c",
10768 value: new THREE.Color(Config.LINE_COLORS[0][3])
10769 },
10770 uColor5: {
10771 type: "c",
10772 value: new THREE.Color(Config.LINE_COLORS[0][4])
10773 }
10774 };
10775 _shader.material.side = THREE.DoubleSide;
10776 _shader.material.depthTest = false;
10777 _shader.material.transparent = true
10778 }
10779
10780 function initMesh() {
10781 _mesh = new THREE.Mesh(_geometry, _shader.material);
10782 _mesh.frustumCulled = false;
10783 _mesh.position.z = -3;
10784 _mesh.position.y = -.8;
10785 _mesh.rotation.x = -1.45;
10786 World.SCENE.add(_mesh)
10787 }
10788
10789 function loop(t, dt, delta) {
10790 _shader.uniforms.fTime.value += delta * .001 * _timescale;
10791 _shader.uniforms.fProgress.value += (_progess - _shader.uniforms.fProgress.value) * .05;
10792 _shader.uniforms.fVelocity.value += (_velocity * .01 - _shader.uniforms.fVelocity.value) * .1;
10793 _velocity *= .98;
10794 _hitMesh.position.copy(_mesh.position);
10795 _hitMesh.rotation.copy(_mesh.rotation);
10796 _shader.uniforms.uMouse.value.lerp(_mouseUV, .05);
10797 updateColors()
10798 }
10799
10800 function updateColors() {
10801 if (_targetColor1.current !== Config.CLOSEST_SECTION) {
10802 _targetColor1.current = Config.CLOSEST_SECTION;
10803 _targetColor1.set(Config.LINE_COLORS[Config.CLOSEST_SECTION][0]);
10804 _targetColor2.set(Config.LINE_COLORS[Config.CLOSEST_SECTION][1]);
10805 _targetColor3.set(Config.LINE_COLORS[Config.CLOSEST_SECTION][2]);
10806 _targetColor4.set(Config.LINE_COLORS[Config.CLOSEST_SECTION][3]);
10807 _targetColor5.set(Config.LINE_COLORS[Config.CLOSEST_SECTION][4])
10808 }
10809 _shader.uniforms.uColor1.value.lerp(_targetColor1, .02);
10810 _shader.uniforms.uColor2.value.lerp(_targetColor2, .02);
10811 _shader.uniforms.uColor3.value.lerp(_targetColor3, .02);
10812 _shader.uniforms.uColor4.value.lerp(_targetColor4, .02);
10813 _shader.uniforms.uColor5.value.lerp(_targetColor5, .02)
10814 }
10815
10816 function addHandlers() {
10817 __window.bind("mousemove", mouseMove);
10818 _this.events.subscribe(ToonamiEvents.LIGHTBOX_OPEN, toLightbox);
10819 _this.events.subscribe(ToonamiEvents.LIGHTBOX_CLOSE, fromLightbox)
10820 }
10821
10822 function toLightbox() {
10823 TweenManager.tween(_mesh.rotation, {
10824 x: -1.75
10825 }, 800, "easeInOutQuart");
10826 TweenManager.tween(_mesh.position, {
10827 y: -.6
10828 }, 800, "easeInOutQuart", 0, null, e => {
10829 _timescale = 1 - e * .8
10830 })
10831 }
10832
10833 function fromLightbox() {
10834 _timescale = 1;
10835 TweenManager.tween(_mesh.rotation, {
10836 x: -1.45
10837 }, 800, "easeInOutQuart");
10838 TweenManager.tween(_mesh.position, {
10839 y: -.8
10840 }, 800, "easeInOutQuart")
10841 }
10842
10843 function mouseMove() {
10844 defer(function() {
10845 hoverInteraction()
10846 })
10847 }
10848
10849 function hoverInteraction() {
10850 _velocity = Math.min(100, Math.max(_velocity, Math.max(Math.abs(Mouse.moveX), Math.abs(Mouse.moveY))));
10851 var hit = _raycaster.checkHit(_hitMesh);
10852 if (!hit.length) return;
10853 _mouseUV.copy(hit[0].uv)
10854 }
10855 this.update = value => {
10856 _progess = value * .5
10857 };
10858 this.introSetup = () => {
10859 _shader.set("fFade", 0);
10860 _mesh.rotation.x = 0;
10861 _mesh.rotation.z = -2;
10862 _mesh.position.z = -8
10863 };
10864 this.introEnd = () => {
10865 TweenManager.tween(_mesh.rotation, {
10866 x: -1.45,
10867 z: 0
10868 }, 25e2, "easeOutQuart", 1e3);
10869 TweenManager.tween(_mesh.position, {
10870 z: -3
10871 }, 25e2, "easeOutQuart", 1e3);
10872 _shader.tween("fFade", 1, 500, "easeInOutCubic", 1e3)
10873 }
10874}, "singleton");
10875Class(function Dust() {
10876 Inherit(this, Component);
10877 var _this = this;
10878 var _group, _geometry, _points, _shader;
10879 var _system;
10880 var _numParticles = 100;
10881 (function() {
10882 initGeometry();
10883 initShader();
10884 initPoints();
10885 initParticleSystem();
10886 _this.startRender(loop)
10887 }());
10888
10889 function initGeometry() {
10890 _geometry = new THREE.BufferGeometry;
10891 var vertices = new Float32Array(_numParticles * 3);
10892 var params = new Float32Array(_numParticles * 3);
10893 _geometry.addAttribute("position", new THREE.BufferAttribute(vertices, 3));
10894 _geometry.addAttribute("params", new THREE.BufferAttribute(params, 3))
10895 }
10896
10897 function initShader() {
10898 _shader = _this.initClass(Shader, "Dust", "Dust");
10899 _shader.uniforms = {
10900 tMap: {
10901 type: "t",
10902 value: Utils3D.getTexture("assets/images/background/dust.jpg")
10903 }
10904 };
10905 _shader.material.transparent = true;
10906 _shader.material.blending = THREE.AdditiveBlending;
10907 _shader.material.depthTest = false
10908 }
10909
10910 function initPoints() {
10911 _points = new THREE.Points(_geometry, _shader.material);
10912 _points.frustumCulled = false;
10913 World.SCENE.add(_points)
10914 }
10915
10916 function initParticleSystem() {
10917 initSystem();
10918 initBehaviour();
10919 initParticles()
10920 }
10921
10922 function initSystem() {
10923 _system = _this.initClass(ParticlePhysics)
10924 }
10925
10926 function initBehaviour() {
10927 _system.addBehavior({
10928 applyBehavior: p => {
10929 if (p.origin.z + _points.position.z > 1) {
10930 p.origin.z -= 6
10931 }
10932 if (p.origin.z + _points.position.z < -5) {
10933 p.origin.z += 6
10934 }
10935 p.pos.x = p.origin.x + Math.sin(Global.TIME * .0005 * p.random + p.random * 3) * p.random * .5;
10936 p.pos.y = p.origin.y + Math.cos(Global.TIME * .001 * p.random + p.random * 2) * p.random * .2;
10937 p.pos.z = p.origin.z
10938 }
10939 })
10940 }
10941
10942 function initParticles() {
10943 for (var i = 0; i < _numParticles; i++) {
10944 var p = new Particle(new Vector3(Utils.doRandom(-1, 1, 3) * 1.5, Utils.doRandom(-1, 1, 3) * .7, Utils.doRandom(-5, 0, 3)), 0, 0);
10945 _system.addParticle(p);
10946 p.origin = (new Vector3).copyFrom(p.pos);
10947 p.random = Utils.doRandom(.1, 1, 4);
10948 _geometry.attributes.params.setXY(i, p.random, Utils.doRandom(.1, 1, 4))
10949 }
10950 _geometry.attributes.params.needsUpdate = true
10951 }
10952
10953 function loop() {
10954 if (!_group) return;
10955 _points.position.z += (_group.position.z - _points.position.z) * .05;
10956 Global.TIME = Date.now();
10957 _system.update();
10958 var p = _system.particles.start();
10959 var i = 0;
10960 while (p) {
10961 _geometry.attributes.position.setXYZ(i, p.pos.x, p.pos.y, p.pos.z);
10962 p = _system.particles.next();
10963 i++
10964 }
10965 _geometry.attributes.position.needsUpdate = true
10966 }
10967 this.init = group => {
10968 _group = group
10969 };
10970 this.introSetup = () => {
10971 _points.rotation.z = Math.PI / 2
10972 };
10973 this.introAnimate = () => {
10974 TweenManager.tween(_points.rotation, {
10975 z: 0
10976 }, 15e2, "easeInOutQuart", 15e2)
10977 }
10978}, "singleton");
10979Class(function IntroLogo() {
10980 Inherit(this, Component);
10981 var _this = this;
10982 var _geometry, _shader, _mesh, _schedule;
10983 this.group = new THREE.Group;
10984 (function() {
10985 initGeometry();
10986 initShader();
10987 initMesh();
10988 initSchedule();
10989 _this.startRender(loop)
10990 }());
10991
10992 function initGeometry() {
10993 var s = .15;
10994 _geometry = new THREE.PlaneBufferGeometry(4 * s, 1 * s, 1, 1)
10995 }
10996
10997 function initShader() {
10998 var texture = Utils3D.getTexture("assets/images/intro/logo.jpg");
10999 _shader = _this.initClass(Shader, "IntroLogo", "IntroLogo");
11000 _shader.uniforms = {
11001 fTime: {
11002 type: "f",
11003 value: 0
11004 },
11005 tMap: {
11006 type: "t",
11007 value: texture
11008 },
11009 fTransition: {
11010 type: "f",
11011 value: 0
11012 }
11013 };
11014 _shader.material.blending = THREE.AdditiveBlending;
11015 _shader.material.transparent = true;
11016 _shader.material.depthTest = false;
11017 _shader.material.depthRender = false
11018 }
11019
11020 function initMesh() {
11021 _mesh = new THREE.Mesh(_geometry, _shader.material);
11022 _this.group.position.y = -.03;
11023 _this.group.position.z = .07;
11024 _this.group.rotation.x = -.25;
11025 _this.group.add(_mesh)
11026 }
11027
11028 function initSchedule() {
11029 _schedule = _this.initClass(IntroSchedule);
11030 _this.group.add(_schedule.group)
11031 }
11032
11033 function loop(t, dt) {
11034 _shader.set("fTime", dt * .001)
11035 }
11036 this.animateIn = () => {
11037 _schedule.animateIn();
11038 _shader.tween("fTransition", 1, 35e2, "easeInOutQuart", 15e2, () => {
11039 _shader.tween("fTransition", 0, 700, "easeInOutCubic", 600)
11040 });
11041 TweenManager.tween(_this.group.position, {
11042 y: .02,
11043 z: .04
11044 }, 2e3, "easeOutCubic", 2e3, () => {
11045 TweenManager.tween(_this.group.position, {
11046 y: .04,
11047 z: .01
11048 }, 700, "easeInCubic", 2e3)
11049 })
11050 };
11051 this.onDestroy = () => {
11052 _geometry.dispose();
11053 _shader.material.dispose()
11054 }
11055});
11056Class(function IntroSchedule() {
11057 Inherit(this, Component);
11058 var _this = this;
11059 var _data, _text, _shader, _mesh;
11060 this.group = new THREE.Group;
11061 (function() {
11062 _data = Data.getSchedule();
11063 initMesh();
11064 _this.startRender(loop)
11065 }());
11066
11067 function initMesh() {
11068 var textInput = [_data.block_day, _data.block_times].join(" ");
11069 textInput = textInput.toUpperCase();
11070 _text = _this.initClass(WebGLText, {
11071 font: "gotham-light",
11072 image: "assets/images/fonts/gotham-light.png",
11073 vs: "IntroSchedule",
11074 fs: "IntroSchedule",
11075 text: textInput,
11076 width: 1e3,
11077 align: "center",
11078 verticalAlign: "top",
11079 letterSpacing: 5,
11080 lineHeight: 80,
11081 color: "#fff",
11082 opacity: 1
11083 });
11084 var s = .001 * .38;
11085 _text.mesh.scale.set(s, s, s);
11086 _text.mesh.position.set(0, -.05, 0);
11087 _text.mesh.rotation.y = Math.PI;
11088 _shader = _text.shader;
11089 _shader.uniforms.fTime = {
11090 type: "f",
11091 value: 0
11092 };
11093 _shader.uniforms.fTransition = {
11094 type: "f",
11095 value: 0
11096 };
11097 _shader.uniforms.uColor1 = {
11098 type: "c",
11099 value: new THREE.Color("#98e3c3")
11100 };
11101 _shader.uniforms.uColor2 = {
11102 type: "c",
11103 value: new THREE.Color("#759caa")
11104 };
11105 _shader.material.transparent = true;
11106 _shader.material.blending = THREE.AdditiveBlending;
11107 _shader.material.depthTest = false;
11108 _shader.material.depthRender = false;
11109 _mesh = _text.mesh;
11110 _mesh.frustumCulled = false;
11111 _this.group.add(_mesh)
11112 }
11113
11114 function loop(t, dt) {
11115 _shader.set("fTime", dt * .001)
11116 }
11117 this.animateIn = function() {
11118 _shader.tween("fTransition", 1, 35e2, "easeInOutQuart", 15e2, () => {
11119 _shader.tween("fTransition", 0, 700, "easeInOutCubic", 600)
11120 })
11121 };
11122 this.onDestroy = () => {
11123 _text.mesh.geometry.dispose();
11124 _shader.material.dispose()
11125 }
11126});
11127Class(function UISphere() {
11128 Inherit(this, Component);
11129 var _this = this;
11130 var _halo, _globe, _orbits, _squares, _circles, _mountain;
11131 var _anim = new DynamicObject({
11132 mouseStrength: 0
11133 });
11134 this.group = new THREE.Group;
11135 this.inner = new THREE.Group;
11136 (function() {
11137 initGroup();
11138 initHalo();
11139 initGlobe();
11140 initOrbits();
11141 initSquares();
11142 initCircles();
11143 initMountain();
11144 _this.startRender(loop)
11145 }());
11146
11147 function initGroup() {
11148 _this.group.rotation.reorder("XYZ");
11149 _this.inner.rotation.reorder("YXZ");
11150 _this.inner.rotation.z = .03;
11151 _this.inner.rotation.x = .3;
11152 var s = .3;
11153 _this.inner.scale.set(s, s, s);
11154 _this.group.add(_this.inner);
11155 _this.group.rotation.z = Math.PI / 2 * .9;
11156 _this.group.rotation.y = .2
11157 }
11158
11159 function initHalo() {
11160 _halo = _this.initClass(UISphereHalo, _this.inner)
11161 }
11162
11163 function initGlobe() {
11164 _globe = _this.initClass(UISphereGlobe);
11165 _this.inner.add(_globe.group)
11166 }
11167
11168 function initOrbits() {
11169 _orbits = _this.initClass(UISphereOrbits);
11170 _this.inner.add(_orbits.group)
11171 }
11172
11173 function initSquares() {
11174 _squares = _this.initClass(UISphereSquares);
11175 _this.inner.add(_squares.group)
11176 }
11177
11178 function initCircles() {
11179 _circles = _this.initClass(UISphereCircles);
11180 _this.inner.add(_circles.group)
11181 }
11182
11183 function initMountain() {
11184 _mountain = _this.initClass(UISphereMountain);
11185 _this.inner.add(_mountain.group)
11186 }
11187
11188 function loop(t, dt) {
11189 _this.inner.rotation.y = Math.sin(dt * .0001) * .5 + .5;
11190 if (!Mouse) return;
11191 var x = Utils.range(Mouse.x, 0, Stage.width, -1, 1) * .4;
11192 _this.group.rotation.y += (x - _this.group.rotation.y) * .01 * _anim.mouseStrength;
11193 var y = Utils.range(Mouse.y, 0, Stage.height, -1, 1) * .1 - .1;
11194 _this.group.rotation.x += (y - _this.group.rotation.x) * .01 * _anim.mouseStrength
11195 }
11196
11197 function straightenUp() {
11198 TweenManager.tween(_this.group.rotation, {
11199 z: 0
11200 }, 15e2, "easeInOutCubic", 15e2);
11201 _anim.tween({
11202 mouseStrength: 1
11203 }, 4e3, "easeInOutSine", 15e2)
11204 }
11205
11206 function zoomIn() {
11207 TweenManager.tween(_this.group.rotation, {
11208 z: -2
11209 }, 15e2, "easeInQuint");
11210 TweenManager.tween(_this.group.position, {
11211 z: 1.5,
11212 y: .15
11213 }, 15e2, "easeInQuint")
11214 }
11215 this.animateIn = () => {
11216 straightenUp();
11217 _halo.animateIn();
11218 _globe.animateIn();
11219 _orbits.animateIn();
11220 _squares.animateIn();
11221 _circles.animateIn();
11222 _mountain.animateIn()
11223 };
11224 this.animateOut = () => {
11225 zoomIn();
11226 _globe.animateOut();
11227 _this.delayedCall(() => {
11228 _halo = _halo.destroy()
11229 }, 1e3);
11230 _this.delayedCall(() => {
11231 _this.inner.remove(_orbits.group);
11232 _this.inner.remove(_squares.group);
11233 _this.inner.remove(_circles.group);
11234 _this.inner.remove(_mountain.group)
11235 }, 15e2)
11236 }
11237});
11238Class(function UISphereCircles() {
11239 Inherit(this, Component);
11240 var _this = this;
11241 var _geometry, _shader, _mesh, _shiftTimer;
11242 var _numInstances = 20;
11243 var _rotEul = new THREE.Euler;
11244 var _rotQuat = new THREE.Quaternion;
11245 this.group = new THREE.Group;
11246 (function() {
11247 initGeometry();
11248 initInstances();
11249 initShader();
11250 initMesh();
11251 shiftSquares()
11252 }());
11253
11254 function initGeometry() {
11255 _geometry = new THREE.InstancedBufferGeometry;
11256 _geometry.maxInstancedCount = _numInstances;
11257 var plane1 = new THREE.PlaneGeometry(.05, .05);
11258 plane1.translate(0, 0, 1.02);
11259 var plane = (new THREE.BufferGeometry).fromGeometry(plane1);
11260 plane1.dispose();
11261 var data = plane.attributes;
11262 _geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array(data.position.array), 3));
11263 _geometry.addAttribute("uv", new THREE.BufferAttribute(new Float32Array(data.uv.array), 2));
11264 _geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(data.normal.array), 3));
11265 plane.dispose()
11266 }
11267
11268 function initInstances() {
11269 var orientation = new THREE.InstancedBufferAttribute(new Float32Array(_numInstances * 4), 4);
11270 var scale = new THREE.InstancedBufferAttribute(new Float32Array(_numInstances * 2), 2);
11271 for (var i = 0; i < _numInstances; i++) {
11272 orientation.setXYZW(i, 0, 0, 0, 1);
11273 var s = Utils.doRandom(.5, 1, 2) * 4;
11274 scale.setXY(i, s, s)
11275 }
11276 _geometry.addAttribute("orientation", orientation);
11277 _geometry.addAttribute("scale", scale)
11278 }
11279
11280 function initShader() {
11281 _shader = _this.initClass(Shader, "UISphereCircles", "UISphereCircles");
11282 _shader.uniforms = {
11283 uColor: {
11284 type: "c",
11285 value: new THREE.Color("#4ed19d")
11286 },
11287 fTransition: {
11288 type: "f",
11289 value: 0
11290 },
11291 uTime: World.TIME
11292 };
11293 _shader.material.transparent = true
11294 }
11295
11296 function initMesh() {
11297 _mesh = new THREE.Mesh(_geometry, _shader.material);
11298 _this.group.add(_mesh)
11299 }
11300
11301 function shiftSquares() {
11302 for (var i = 0; i < _numInstances; i++) {
11303 _rotEul.set(Utils.doRandom(0, Math.PI * 2, 3), Utils.doRandom(0, Math.PI * 2, 3), Utils.doRandom(0, Math.PI * 2, 3));
11304 _rotQuat.setFromEuler(_rotEul);
11305 _geometry.attributes.orientation.setXYZW(i, _rotQuat.x, _rotQuat.y, _rotQuat.z, _rotQuat.w)
11306 }
11307 _geometry.attributes.orientation.needsUpdate = true;
11308 _shiftTimer = _this.delayedCall(shiftSquares, 1e3)
11309 }
11310 this.onDestroy = () => {
11311 _shader.material.dispose();
11312 _geometry.dispose();
11313 if (_shiftTimer) clearTimeout(_shiftTimer)
11314 };
11315 this.animateIn = () => {
11316 _shader.tween("fTransition", 1, 25e2, "easeInOutCubic", 15e2)
11317 }
11318});
11319Class(function UISphereGlobe() {
11320 Inherit(this, Component);
11321 var _this = this;
11322 var _geometry, _shader, _mesh;
11323 this.group = new THREE.Group;
11324 (function() {
11325 initGeometry();
11326 initShader();
11327 initMesh();
11328 _this.startRender(loop)
11329 }());
11330
11331 function initGeometry() {
11332 _geometry = new THREE.SphereBufferGeometry(1, 40, 20)
11333 }
11334
11335 function initShader() {
11336 var texture = Utils3D.getTexture("assets/images/intro/triangles.jpg");
11337 texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
11338 _shader = _this.initClass(Shader, "UISphere", "UISphere");
11339 _shader.uniforms = {
11340 tMap: {
11341 type: "t",
11342 value: texture
11343 },
11344 fTime: {
11345 type: "f",
11346 value: 0
11347 },
11348 fFade: {
11349 type: "f",
11350 value: 1
11351 },
11352 uColor: {
11353 type: "c",
11354 value: new THREE.Color("#00000f")
11355 },
11356 uLightColor: {
11357 type: "c",
11358 value: new THREE.Color("#55aa9d")
11359 },
11360 fTransition: {
11361 type: "f",
11362 value: 0
11363 }
11364 };
11365 _shader.material.transparent = true
11366 }
11367
11368 function initMesh() {
11369 _mesh = new THREE.Mesh(_geometry, _shader.material);
11370 _this.group.add(_mesh)
11371 }
11372
11373 function loop(t, dt) {
11374 _shader.set("fTime", dt * .001)
11375 }
11376 this.onDestroy = () => {
11377 _shader.material.dispose();
11378 _geometry.dispose()
11379 };
11380 this.animateIn = () => {
11381 _shader.tween("fTransition", 1, 15e2, "easeInOutCubic", 15e2)
11382 };
11383 this.animateOut = () => {
11384 _shader.tween("fFade", 0, 500, "easeInOutCubic", 1e3)
11385 }
11386});
11387Class(function UISphereHalo(_group) {
11388 Inherit(this, Component);
11389 var _this = this;
11390 var _geometry, _shader, _mesh;
11391 this.group = new THREE.Group;
11392 this.inner = new THREE.Group;
11393 (function() {
11394 initGroup();
11395 initGeometry();
11396 initShader();
11397 initMesh();
11398 _this.startRender(loop)
11399 }());
11400
11401 function initGroup() {
11402 _this.group.add(_this.inner);
11403 _this.inner.rotation.z = Math.PI / 2
11404 }
11405
11406 function initGeometry() {
11407 _geometry = new THREE.PlaneBufferGeometry(3, 1.5)
11408 }
11409
11410 function initShader() {
11411 _shader = _this.initClass(Shader, "UISphereHalo", "UISphereHalo");
11412 _shader.uniforms = {
11413 fTime: {
11414 type: "f",
11415 value: 0
11416 },
11417 uColor: {
11418 type: "c",
11419 value: new THREE.Color("#89b1a3")
11420 },
11421 tNoise: {
11422 type: "t",
11423 value: Utils3D.getRepeatTexture("assets/images/common/noise.jpg")
11424 }
11425 };
11426 _shader.material.transparent = true;
11427 _shader.material.blending = THREE.AdditiveBlending;
11428 _shader.material.depthRender = false
11429 }
11430
11431 function initMesh() {
11432 _mesh = new THREE.Mesh(_geometry, _shader.material);
11433 _this.inner.add(_mesh);
11434 _mesh.position.y = .95;
11435 _mesh.position.z = 0;
11436 var mesh2 = new THREE.Mesh(_geometry, _shader.material);
11437 _this.inner.add(mesh2);
11438 mesh2.position.y = -.95;
11439 mesh2.position.z = 0;
11440 mesh2.scale.set(.9, 1.1, 1);
11441 World.SCENE.add(_this.group);
11442 var s = .3;
11443 _this.group.scale.set(s, s, s)
11444 }
11445
11446 function loop(t, dt) {
11447 _shader.set("fTime", dt * .001);
11448 _this.group.quaternion.copy(World.CAMERA.quaternion)
11449 }
11450 this.onDestroy = () => {
11451 World.SCENE.remove(_this.group);
11452 _shader.material.dispose();
11453 _geometry.dispose()
11454 };
11455 this.animateIn = () => {
11456 TweenManager.tween(_this.inner.rotation, {
11457 z: 0
11458 }, 15e2, "easeInOutQuart", 15e2)
11459 }
11460});
11461Class(function UISphereMountain() {
11462 Inherit(this, Component);
11463 var _this = this;
11464 var _geometry, _shader, _mesh;
11465 this.group = new THREE.Group;
11466 (function() {
11467 initGeometry();
11468 initShader();
11469 initMesh();
11470 _this.group.rotation.z = -.03;
11471 _this.group.rotation.y = -.5;
11472 _this.group.rotation.x = -.5
11473 }());
11474
11475 function initGeometry() {
11476 _geometry = new THREE.SphereGeometry(1, 80, 40, Math.PI / 4, Math.PI / 2, Math.PI / 2, Math.PI / 4)
11477 }
11478
11479 function initShader() {
11480 var displacementTexture = Utils3D.getTexture("assets/images/landscape/mountain-height.jpg");
11481 var normalTexture = Utils3D.getTexture("assets/images/landscape/mountain-normal.jpg");
11482 displacementTexture.wrapS = displacementTexture.wrapT = THREE.RepeatWrapping;
11483 normalTexture.wrapS = normalTexture.wrapT = THREE.RepeatWrapping;
11484 _shader = _this.initClass(Shader, "UISphereMountain", "UISphereMountain");
11485 _shader.uniforms = {
11486 bumpMap: {
11487 type: "t",
11488 value: displacementTexture
11489 },
11490 normalMap: {
11491 type: "t",
11492 value: normalTexture
11493 },
11494 normalScale: {
11495 type: "v2",
11496 value: new THREE.Vector2(.1, 1)
11497 },
11498 uColor: {
11499 type: "c",
11500 value: new THREE.Color("#00000f")
11501 },
11502 uLightColor1: {
11503 type: "c",
11504 value: new THREE.Color("#74e4bb")
11505 },
11506 uLightColor2: {
11507 type: "c",
11508 value: new THREE.Color("#436c6e")
11509 },
11510 fTransition: {
11511 type: "f",
11512 value: 0
11513 }
11514 }
11515 }
11516
11517 function initMesh() {
11518 var s = .6;
11519 _mesh = new THREE.Mesh(_geometry, _shader.material);
11520 _mesh.rotation.z = Math.PI;
11521 _mesh.rotation.x = -Math.PI / 4 * s;
11522 _this.group.add(_mesh)
11523 }
11524 this.onDestroy = () => {
11525 _shader.material.dispose();
11526 _geometry.dispose()
11527 };
11528 this.animateIn = () => {
11529 _shader.tween("fTransition", 1, 4e3, "easeOutCubic", 500)
11530 }
11531});
11532Class(function UISphereOrbits() {
11533 Inherit(this, Component);
11534 var _this = this;
11535 var _circleGeometry, _orbitGeometry, _circleShader, _orbitShader;
11536 var _circles = [];
11537 this.group = new THREE.Group;
11538 (function() {
11539 initGeometry();
11540 initShader();
11541 initCircles();
11542 _this.startRender(loop)
11543 }());
11544
11545 function initGeometry() {
11546 var points = [];
11547 var radius = 1.03;
11548 var num = 40;
11549 for (var i = 0; i < num; i++) {
11550 let angle = i / (num - 1) * Math.PI * 2;
11551 let x = radius * Math.sin(angle);
11552 let z = radius * Math.cos(angle);
11553 let point = new THREE.Vector3(x, 0, z);
11554 points.push(point)
11555 }
11556 var curve = new THREE.CatmullRomCurve3(points);
11557 _circleGeometry = new THREE.Geometry;
11558 _circleGeometry.vertices = curve.getPoints(100);
11559 _orbitGeometry = new THREE.Geometry;
11560 var s = .02;
11561 _orbitGeometry.vertices.push(new THREE.Vector3(0, 0, s), new THREE.Vector3(0, -s, 0), new THREE.Vector3(0, s, 0));
11562 _orbitGeometry.faces.push(new THREE.Face3(0, 1, 2));
11563 _orbitGeometry.translate(0, 0, 1.03)
11564 }
11565
11566 function initShader() {
11567 _circleShader = _this.initClass(Shader, "UISphereLine", "UISphereLine");
11568 _circleShader.uniforms = {
11569 uTime: World.TIME,
11570 uColor: {
11571 type: "c",
11572 value: new THREE.Color("#4ed19d")
11573 },
11574 fTransition: {
11575 type: "f",
11576 value: 0
11577 }
11578 };
11579 _circleShader.material.transparent = true;
11580 _circleShader.material.blending = THREE.AdditiveBlending;
11581 _orbitShader = _circleShader.clone();
11582 _orbitShader.material.wireframe = true
11583 }
11584
11585 function addCircle() {
11586 var line = new THREE.Line(_circleGeometry, _circleShader.material);
11587 var group = new THREE.Group;
11588 group.add(line);
11589 _this.group.add(group);
11590 return group
11591 }
11592
11593 function initCircles() {
11594 for (var i = 0; i < 6; i++) {
11595 var circle = addCircle();
11596 var rotation = new THREE.Vector3(Utils.doRandom(0, 6, 3), Utils.doRandom(0, 6, 3), Utils.doRandom(0, 6, 3));
11597 var spin = new THREE.Vector3(Utils.doRandom(0, 6, 3), Utils.doRandom(0, 6, 3), Utils.doRandom(0, 6, 3));
11598 spin.multiplyScalar(Utils.doRandom(.0005, .001, 3));
11599 circle.rotation.set(rotation.x, rotation.y, rotation.z);
11600 var orbits = [];
11601 for (var j = 0; j < Utils.doRandom(3, 6); j++) {
11602 var orbit = addOrbit();
11603 circle.add(orbit);
11604 orbits.push(orbit)
11605 }
11606 _circles.push({
11607 line: circle,
11608 rotation: rotation,
11609 spin: spin,
11610 orbits: orbits
11611 })
11612 }
11613 }
11614
11615 function addOrbit() {
11616 var mesh = new THREE.Mesh(_orbitGeometry, _orbitShader.material);
11617 mesh.rotation.y = Utils.doRandom(0, Math.PI * 2, 3);
11618 mesh.speed = Utils.doRandom(.005, .015, 3) * Utils.headsTails(-1, 1);
11619 return mesh
11620 }
11621
11622 function loop(t, dt) {
11623 _circles.forEach(function(circle) {
11624 circle.line.rotation.x += circle.spin.x;
11625 circle.line.rotation.y += circle.spin.y;
11626 circle.line.rotation.z += circle.spin.z;
11627 circle.orbits.forEach(function(orbit) {
11628 orbit.rotation.y += orbit.speed
11629 })
11630 })
11631 }
11632 this.onDestroy = () => {
11633 _circleShader.material.dispose();
11634 _orbitShader.material.dispose();
11635 _circleGeometry.dispose();
11636 _orbitGeometry.dispose()
11637 };
11638 this.animateIn = () => {
11639 _circleShader.tween("fTransition", 1, 25e2, "easeInOutCubic", 15e2);
11640 _orbitShader.tween("fTransition", 1, 25e2, "easeInOutCubic", 15e2)
11641 }
11642});
11643Class(function UISphereSquares() {
11644 Inherit(this, Component);
11645 var _this = this;
11646 var _geometry, _shader, _mesh, _shiftTimer;
11647 var _numInstances = 100;
11648 var _rotEul = new THREE.Euler;
11649 var _rotQuat = new THREE.Quaternion;
11650 this.group = new THREE.Group;
11651 (function() {
11652 initGeometry();
11653 initInstances();
11654 initShader();
11655 initMesh();
11656 shiftSquares()
11657 }());
11658
11659 function initGeometry() {
11660 _geometry = new THREE.InstancedBufferGeometry;
11661 _geometry.maxInstancedCount = _numInstances;
11662 var plane1 = new THREE.PlaneGeometry(.05, .05);
11663 plane1.translate(0, 0, 1.02);
11664 var plane = (new THREE.BufferGeometry).fromGeometry(plane1);
11665 plane1.dispose();
11666 var data = plane.attributes;
11667 _geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array(data.position.array), 3));
11668 _geometry.addAttribute("uv", new THREE.BufferAttribute(new Float32Array(data.uv.array), 2));
11669 _geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(data.normal.array), 3));
11670 plane.dispose()
11671 }
11672
11673 function initInstances() {
11674 var orientation = new THREE.InstancedBufferAttribute(new Float32Array(_numInstances * 4), 4);
11675 var scale = new THREE.InstancedBufferAttribute(new Float32Array(_numInstances * 2), 2);
11676 for (var i = 0; i < _numInstances; i++) {
11677 orientation.setXYZW(i, 0, 0, 0, 1);
11678 var s = Utils.doRandom(.5, .75, 2);
11679 scale.setXY(i, s, s)
11680 }
11681 _geometry.addAttribute("orientation", orientation);
11682 _geometry.addAttribute("scale", scale)
11683 }
11684
11685 function initShader() {
11686 _shader = _this.initClass(Shader, "UISphereSquares", "UISphereSquares");
11687 _shader.uniforms = {
11688 uColor: {
11689 type: "c",
11690 value: new THREE.Color("#4ed19d")
11691 },
11692 fTransition: {
11693 type: "f",
11694 value: 0
11695 }
11696 };
11697 _shader.material.transparent = true
11698 }
11699
11700 function initMesh() {
11701 _mesh = new THREE.Mesh(_geometry, _shader.material);
11702 _this.group.add(_mesh)
11703 }
11704
11705 function shiftSquares() {
11706 for (var i = 0; i < _numInstances; i++) {
11707 _rotEul.set(Utils.doRandom(0, Math.PI * 2, 3), Utils.doRandom(0, Math.PI * 2, 3), Utils.doRandom(0, Math.PI * 2, 3));
11708 _rotQuat.setFromEuler(_rotEul);
11709 _geometry.attributes.orientation.setXYZW(i, _rotQuat.x, _rotQuat.y, _rotQuat.z, _rotQuat.w)
11710 }
11711 _geometry.attributes.orientation.needsUpdate = true;
11712 _shiftTimer = _this.delayedCall(shiftSquares, 1e3)
11713 }
11714 this.onDestroy = () => {
11715 _shader.material.dispose();
11716 _geometry.dispose();
11717 if (_shiftTimer) clearTimeout(_shiftTimer)
11718 };
11719 this.animateIn = () => {
11720 _shader.tween("fTransition", 1, 25e2, "easeInOutCubic", 15e2)
11721 }
11722});
11723Class(function LightboxView() {
11724 Inherit(this, View);
11725 var _this = this;
11726 var $this, $behind, $video;
11727 var _video, _title, _close;
11728 (function() {
11729 initHTML();
11730 initVideo();
11731 initClose();
11732 addListeners();
11733 defer(resizeHandler)
11734 }());
11735
11736 function initHTML() {
11737 $this = _this.element;
11738 $this.size("100%").invisible();
11739 $this.enable3D(2e3);
11740 $behind = $this.create(".behind");
11741 $behind.size("100%").setZ(1).css({
11742 opacity: 0
11743 }).bg("#000")
11744 }
11745
11746 function initVideo() {
11747 $video = $this.create(".video");
11748 $video.size(600, 400).center().bg("#000").css({
11749 overflow: "hidden",
11750 boxShadow: "0 0 50px rgba(0,0,0,0.3)",
11751 opacity: 0
11752 }).setZ(2).mouseEnabled(false);
11753 _video = _this.initClass(LightboxVideo, [$video])
11754 }
11755
11756 function initClose() {
11757 _close = _this.initClass(LightboxClose)
11758 }
11759
11760 function loop() {}
11761
11762 function addListeners() {
11763 _this.events.subscribe(HydraEvents.RESIZE, resizeHandler);
11764 _close.events.add(HydraEvents.CLICK, close);
11765 _video.events.add(HydraEvents.COMPLETE, close);
11766 $behind.interact(null, close);
11767 if (!Device.mobile) ScrollUtil.link(close)
11768 }
11769
11770 function close(e) {
11771 if (!_this.visible) return;
11772 _this.events.fire(ToonamiEvents.LIGHTBOX_CLOSE)
11773 }
11774
11775 function resizeHandler() {
11776 var gap = Mobile.phone ? 30 : 50;
11777 var vidH = 720;
11778 var w = Stage.width - gap * 2;
11779 w = Utils.clamp(w, 300, 11e2);
11780 var h = w * (vidH / 128e1);
11781 var offset = Mobile.phone ? 160 : 230;
11782 if (Mobile.phone && Stage.width > Stage.height) offset = Utils.convertRange(Stage.width / Stage.height, 1.4, 3, 160, 80);
11783 if (h > Stage.height - offset) {
11784 h = Stage.height - offset;
11785 w = h * (128e1 / vidH)
11786 }
11787 $video.size(w, h).center().css({
11788 marginTop: -h / 2 - 15
11789 });
11790 _video.resize(w, h);
11791 _close.element.center().css({
11792 marginTop: -h / 2 - 40,
11793 marginLeft: w / 2 - 25
11794 });
11795 if (Mobile.phone) _close.element.center().css({
11796 marginTop: -h / 2 - 75
11797 });
11798 _this.width = w;
11799 _this.height = h;
11800 var extra = Mobile.phone ? 0 : 10;
11801 if (_title) _title.element.size(w, 60).center().css({
11802 marginTop: h / 2 + extra
11803 });
11804 if (Mobile.phone && Stage.width > Stage.height) {
11805 $video.size(w, h).center().css({
11806 left: 50,
11807 marginLeft: ""
11808 });
11809 if (_title) _title.element.size(Stage.width - w - 110, 60).center().css({
11810 marginTop: "",
11811 top: (Stage.height - h) / 2 + 70,
11812 left: "",
11813 marginLeft: "",
11814 right: 40
11815 });
11816 if (_close) _close.element.center().css({
11817 marginTop: "",
11818 top: (Stage.height - h) / 2,
11819 marginLeft: "",
11820 marginLeft: "",
11821 left: "",
11822 right: (Stage.width - w) / 2 - 40
11823 })
11824 }
11825 }
11826 this.animateIn = function(e) {
11827 _this.visible = true;
11828 $this.visible();
11829 $video.mouseEnabled(false);
11830 $video.transformPoint("50%", "20%").transform({
11831 rotationX: -90,
11832 scaleX: .7,
11833 scaleY: .7
11834 }).css({
11835 opacity: 0
11836 }).tween({
11837 y: 0,
11838 rotationX: 0,
11839 scaleX: 1,
11840 scaleY: 1,
11841 opacity: 1
11842 }, 1e3, "easeOutQuart", function() {
11843 $video.mouseEnabled(true);
11844 $this.mouseEnabled(true)
11845 });
11846 _video.set(e.src);
11847 _title = _this.initClass(LightboxTitle, e);
11848 resizeHandler();
11849 $behind.tween({
11850 opacity: 0
11851 }, 25e2, "easeInOutSine");
11852 _title.animateIn(400);
11853 _close.animateIn(800)
11854 };
11855 this.animateOut = function() {
11856 _this.visible = false;
11857 _video.pause();
11858 _title.animateOut();
11859 _close.animateOut();
11860 $behind.tween({
11861 opacity: 0
11862 }, 500, "easeOutSine");
11863 $video.transformPoint("50%", "100%").tween({
11864 scaleX: .8,
11865 scaleY: .8,
11866 rotationX: 90,
11867 y: Stage.height * .2,
11868 opacity: 0
11869 }, 500, "easeInCubic", function() {
11870 _video.pause();
11871 _close.element.invisible();
11872 _title = _title.destroy();
11873 $this.invisible()
11874 })
11875 }
11876});
11877Class(function LightboxClose() {
11878 Inherit(this, View);
11879 var _this = this;
11880 var $this;
11881 var $outline, $wrapper, $outline2, $fill, $close;
11882 (function() {
11883 initHTML();
11884 initElements();
11885 addListeners()
11886 }());
11887
11888 function initHTML() {
11889 $this = _this.element;
11890 $this.size(50, 50).invisible().setZ(100)
11891 }
11892
11893 function initElements() {
11894 $wrapper = $this.create(".wrapper");
11895 $wrapper.size(50, 50).css({
11896 opacity: 0
11897 });
11898 $outline = $wrapper.create(".outline");
11899 $outline.size(50, 50).bg("assets/images/ui/close/outline.png");
11900 $outline2 = $wrapper.create(".outline");
11901 $outline2.size(50, 50).bg("assets/images/ui/close/outline.png").css({
11902 opacity: 0
11903 });
11904 $fill = $wrapper.create(".fill");
11905 $fill.size(50, 50).bg("assets/images/ui/close/fill.png");
11906 $close = $this.create(".close");
11907 $close.size(50, 50).bg("assets/images/ui/close/close.png")
11908 }
11909
11910 function addListeners() {
11911 $this.interact(hover, click)
11912 }
11913
11914 function hover(e) {
11915 if (_this.clicked) return;
11916 switch (e.action) {
11917 case "over":
11918 $outline2.stopTween().transform({
11919 scale: 1
11920 }).css({
11921 opacity: .7
11922 }).tween({
11923 opacity: 0,
11924 scale: 1.6
11925 }, 1e3, "easeOutQuart");
11926 $outline.tween({
11927 opacity: 1
11928 }, 300, "easeOutCubic");
11929 $wrapper.stopTween().transform({
11930 rotation: 0
11931 }).tween({
11932 rotation: -60,
11933 scale: 1.1
11934 }, 300, "easeOutQuart");
11935 $fill.tween({
11936 opacity: 1
11937 }, 100, "easeOutSine");
11938 break;
11939 case "out":
11940 $outline.tween({
11941 opacity: .8
11942 }, 300, "easeOutSine");
11943 $wrapper.tween({
11944 rotation: -60,
11945 scale: 1
11946 }, 300, "easeOutQuart");
11947 $fill.tween({
11948 opacity: .2
11949 }, 300, "easeOutSine");
11950 break
11951 }
11952 }
11953
11954 function click() {
11955 _this.clicked = true;
11956 $close.stopTween().tween({
11957 opacity: 0
11958 }, 300, "easeOutSine");
11959 _this.events.fire(HydraEvents.CLICK)
11960 }
11961 this.animateIn = function(delay) {
11962 $this.visible();
11963 _this.clicked = false;
11964 $wrapper.transform({
11965 scale: 1.5
11966 }).css({
11967 opacity: 0
11968 }).tween({
11969 scale: 1,
11970 opacity: .8
11971 }, 500, "easeOutCubic", delay);
11972 $close.css({
11973 opacity: 0
11974 }).tween({
11975 opacity: 1
11976 }, 500, "easeOutSine", delay)
11977 };
11978 this.animateOut = function() {
11979 $wrapper.tween({
11980 scale: .8,
11981 opacity: 0
11982 }, 400, "easeOutCubic", function() {
11983 $this.invisible()
11984 });
11985 $close.tween({
11986 opacity: 0
11987 }, 300, "easeoutSine")
11988 }
11989});
11990Class(function LightboxTitle(_data) {
11991 Inherit(this, View);
11992 var _this = this;
11993 var $this, $title, $text;
11994 var _title, _text;
11995 (function() {
11996 initHTML();
11997 initText()
11998 }());
11999
12000 function initHTML() {
12001 $this = _this.element;
12002 $this.size("100%", 60).invisible().setZ(10).css({
12003 textAlign: "center",
12004 opacity: .9
12005 })
12006 }
12007
12008 function initText() {
12009 var size = Mobile.phone ? 12 : 16;
12010 $title = $this.create(".text");
12011 $title.fontStyle("GothamRnd", size * 1.2, "#fff");
12012 $title.css({
12013 width: "100%",
12014 fontWeight: "bold",
12015 position: "relative",
12016 display: "block",
12017 letterSpacing: 2
12018 });
12019 $title.text(_data.title.toUpperCase());
12020 $text = $this.create(".text");
12021 $text.fontStyle("GothamRnd", size, "#fff");
12022 $text.css({
12023 width: "100%",
12024 fontWeight: "300",
12025 position: "relative",
12026 display: "block",
12027 marginTop: 5,
12028 letterSpacing: 2
12029 });
12030 $text.text(_data.text.toUpperCase());
12031 if (!Mobile.phone) {
12032 _title = SplitTextfield.split($title);
12033 for (var i = 0; i < _title.length; i++) {
12034 _title[i].css({
12035 position: "relative",
12036 float: "",
12037 cssFloat: "",
12038 styleFloat: "",
12039 display: "inline-block"
12040 })
12041 }
12042 _text = SplitTextfield.split($text);
12043 for (var i = 0; i < _text.length; i++) {
12044 _text[i].css({
12045 position: "relative",
12046 float: "",
12047 cssFloat: "",
12048 styleFloat: "",
12049 display: "inline-block"
12050 })
12051 }
12052 }
12053 }
12054 this.animateIn = function(delay) {
12055 $this.visible();
12056 if (!Mobile.phone) {
12057 for (var i = 0; i < _title.length; i++) {
12058 _title[i].css({
12059 opacity: 0
12060 }).tween({
12061 opacity: 1
12062 }, Utils.doRandom(15e2, 4e3), "easeInOutSine", delay + Utils.doRandom(0, 1e3))
12063 }
12064 for (var i = 0; i < _text.length; i++) {
12065 _text[i].css({
12066 opacity: 0
12067 }).tween({
12068 opacity: 1
12069 }, Utils.doRandom(15e2, 4e3), "easeInOutSine", delay + Utils.doRandom(0, 1e3))
12070 }
12071 } else {
12072 $title.css({
12073 opacity: 0
12074 }).tween({
12075 opacity: 1
12076 }, 2e3, "easeInOutSine");
12077 $text.css({
12078 opacity: 0
12079 }).tween({
12080 opacity: 1
12081 }, 2e3, "easeInOutSine", 500)
12082 }
12083 };
12084 this.animateOut = function() {
12085 $this.tween({
12086 opacity: 0
12087 }, 300, "easeOutSine")
12088 }
12089});
12090Class(function LightboxVideo() {
12091 Inherit(this, View);
12092 var _this = this;
12093 var $this, $video;
12094 var _video, _controls, _timeout, _timeout2;
12095 var _src = "http://ht.cdn.turner.com/adultswim/big/toonami/index/2XKG9_ToonamiMV_YNA.mp4";
12096 (function() {
12097 initHTML();
12098 initVideo();
12099 addListeners()
12100 }());
12101
12102 function initHTML() {
12103 $this = _this.element;
12104 $this.size("100%")
12105 }
12106
12107 function initVideo() {
12108 $video = $this.create(".video");
12109 $video.size("100%").setZ(1);
12110 _video = _this.initClass(Video, {
12111 src: _src,
12112 width: 128e1,
12113 height: 720
12114 });
12115 $video.add(_video);
12116 _video.volume(.7);
12117 _video.object.div.controls = true
12118 }
12119
12120 function initControls() {
12121 _controls = _this.initClass(LightboxVideoControls)
12122 }
12123
12124 function addListeners() {
12125 _this.events.bubble(_video, HydraEvents.COMPLETE)
12126 }
12127
12128 function move() {
12129 _controls.animateIn();
12130 clearTimeout(_timeout);
12131 _timeout = _this.delayedCall(_controls.animateOut, 13e2)
12132 }
12133
12134 function controlUpdate(e) {
12135 if (e.type == "seek") {
12136 if (!_video.playing) playPause();
12137 move();
12138 _video.seek(e.perc * _video.duration);
12139 clearTimeout(_timeout2);
12140 _timeout2 = _this.delayedCall(function() {
12141 _video.play()
12142 }, 200)
12143 } else {
12144 _video.volume(e.perc)
12145 }
12146 }
12147
12148 function update(e) {
12149 var perc = Utils.clamp(e.time / e.duration, 0, 1);
12150 _controls.update(perc)
12151 }
12152
12153 function playPause() {
12154 move();
12155 if (_video.playing) {
12156 _video.pause();
12157 _controls.pause()
12158 } else {
12159 _video.play();
12160 _controls.play()
12161 }
12162 }
12163 this.set = function(s) {
12164 src = s || "http://ht.cdn.turner.com/adultswim/big/toonami/index/2XKG9_ToonamiMV_YNA.mp4";
12165 if (_src !== src) {
12166 _src = src;
12167 _video.object.div.src = _src;
12168 _video.object.div.load()
12169 } else {
12170 _video.seek(0)
12171 }
12172 if (Mobile.phone) _video.play();
12173 else _this.delayedCall(_video.play, 400)
12174 };
12175 this.pause = function() {
12176 _video.pause()
12177 };
12178 this.resize = function(w, h) {
12179 $this.size(w, h).center();
12180 _video.size(w, h)
12181 };
12182 this.animateIn = function() {}
12183});
12184Class(function LightboxVideoControls() {
12185 Inherit(this, View);
12186 var _this = this;
12187 var $this, $bg;
12188 var _playpause, _seek, _volume, _fullscreen;
12189 (function() {
12190 initHTML();
12191 initSeek();
12192 initVolume();
12193 initButtons()
12194 }());
12195
12196 function initHTML() {
12197 $this = _this.element;
12198 $this.size("100%", 60).css({
12199 bottom: 0,
12200 opacity: 0
12201 }).setZ(10);
12202 $bg = $this.create(".bg");
12203 $bg.size("100%").bg("#000").css({
12204 opacity: .7
12205 })
12206 }
12207
12208 function initButtons() {
12209 _playpause = _this.initClass(LightboxVideoControlsPlaypause);
12210 _this.events.bubble(_playpause, HydraEvents.CLICK)
12211 }
12212
12213 function initSeek() {
12214 _seek = _this.initClass(LightboxVideoControlsSeek);
12215 _this.events.bubble(_seek, HydraEvents.UPDATE)
12216 }
12217
12218 function initVolume() {
12219 _volume = _this.initClass(LightboxVideoControlsVolume);
12220 _this.events.bubble(_volume, HydraEvents.UPDATE)
12221 }
12222 this.play = function() {
12223 _playpause.play()
12224 };
12225 this.pause = function() {
12226 _playpause.pause()
12227 };
12228 this.animateIn = function() {
12229 if (_this.visible) return;
12230 _this.visible = true;
12231 $this.tween({
12232 opacity: 1,
12233 y: 0
12234 }, 500, "easeOutCubic")
12235 };
12236 this.animateOut = function() {
12237 if (!_this.visible) return;
12238 _this.visible = false;
12239 $this.tween({
12240 opacity: 0,
12241 y: 8
12242 }, 700, "easeInCubic")
12243 };
12244 this.resize = function(w) {
12245 _seek.resize(w - 270);
12246 _volume.resize(w);
12247 $this.size(w + 1, 60)
12248 };
12249 this.update = function(perc) {
12250 _seek.update(perc)
12251 }
12252});
12253Class(function LightboxVideoControlsPlaypause() {
12254 Inherit(this, View);
12255 var _this = this;
12256 var $this, $play, $pause;
12257 (function() {
12258 initHTML();
12259 initIcons();
12260 addListeners()
12261 }());
12262
12263 function initHTML() {
12264 $this = _this.element;
12265 $this.size(50, 50).center(0, 1).css({
12266 left: 10,
12267 opacity: .7
12268 })
12269 }
12270
12271 function initIcons() {
12272 $play = $this.create(".play");
12273 $play.size(36, 36).center().bg("assets/images/ui/play.png").css({
12274 opacity: 0
12275 });
12276 $pause = $this.create(".play");
12277 $pause.size(36, 36).center().bg("assets/images/ui/pause.png")
12278 }
12279
12280 function addListeners() {
12281 $this.interact(hover, click)
12282 }
12283
12284 function hover(e) {
12285 switch (e.action) {
12286 case "over":
12287 $this.tween({
12288 opacity: 1
12289 }, 300, "easeOutSine");
12290 break;
12291 case "out":
12292 $this.tween({
12293 opacity: .7
12294 }, 300, "easeOutSine");
12295 break
12296 }
12297 }
12298
12299 function click() {
12300 _this.events.fire(HydraEvents.CLICK)
12301 }
12302 this.pause = function() {
12303 $play.tween({
12304 opacity: 1
12305 }, 200, "easeInOutSine");
12306 $pause.tween({
12307 opacity: 0
12308 }, 200, "easeOutSine")
12309 };
12310 this.play = function() {
12311 $play.tween({
12312 opacity: 0
12313 }, 200, "easeOutSine");
12314 $pause.tween({
12315 opacity: 1
12316 }, 200, "easeInOutSine")
12317 };
12318 this.animateIn = function() {}
12319});
12320Class(function LightboxVideoControlsSeek(_color) {
12321 Inherit(this, View);
12322 var _this = this;
12323 var $this, $bar, $inner;
12324 var _position = new Vector2(0, 0);
12325 var _move = new Vector2(0, 0);
12326 (function() {
12327 initHTML();
12328 initBar();
12329 Render.start(loop);
12330 addListeners()
12331 }());
12332
12333 function initHTML() {
12334 $this = _this.element;
12335 $this.size("100%")
12336 }
12337
12338 function initBar() {
12339 $bar = $this.create(".bar");
12340 $bar.size("100%").css({
12341 overflow: "hidden"
12342 });
12343 var $bg = $bar.create(".bg");
12344 $bg.size("100%").bg("#fff").css({
12345 opacity: .3
12346 });
12347 $inner = $bar.create(".inner");
12348 $inner.size("100%").bg(_color || "#46d39e").css({
12349 left: "-100%"
12350 })
12351 }
12352
12353 function loop() {
12354 _move.lerp(_position, .5);
12355 $inner.x = _move.x;
12356 $inner.transform()
12357 }
12358
12359 function addListeners() {
12360 $this.bind("touchstart", start);
12361 $this.bind("touchmove", move);
12362 $this.bind("touchend", end)
12363 }
12364
12365 function start(e) {
12366 _this.down = true;
12367 move(e)
12368 }
12369
12370 function move(e) {
12371 if (!_this.down) return;
12372 var perc = Utils.clamp(e.layerX / _this.width, 0, 1);
12373 _position.x = _this.width * perc || 0;
12374 _this.events.fire(HydraEvents.UPDATE, {
12375 type: "seek",
12376 perc: perc
12377 })
12378 }
12379
12380 function end() {
12381 _this.down = false
12382 }
12383 this.animateIn = function() {};
12384 this.update = function(perc) {
12385 _position.x = _this.width * perc || 0
12386 };
12387 this.resize = function(w) {
12388 _this.width = w;
12389 $this.size(_this.width, "100%").css({
12390 left: 60
12391 });
12392 $bar.size(_this.width, 2).center();
12393 $inner.size(_this.width, 2)
12394 }
12395});
12396Class(function LightboxVideoControlsVolume() {
12397 Inherit(this, View);
12398 var _this = this;
12399 var $this, $mute, $button, $unmute;
12400 var _bar;
12401 var _volume = .7;
12402 (function() {
12403 initHTML();
12404 initIcons();
12405 initBar();
12406 addListeners()
12407 }());
12408
12409 function initHTML() {
12410 $this = _this.element;
12411 $this.size(160, 50).center(0, 1).css({
12412 right: 40,
12413 opacity: .7
12414 })
12415 }
12416
12417 function initIcons() {
12418 $button = $this.create(".button");
12419 $button.size(50, 50).css({
12420 left: 20
12421 });
12422 $mute = $button.create(".play");
12423 $mute.size(36, 36).center(0, 1).bg("assets/images/ui/mute.png");
12424 $unmute = $button.create(".play");
12425 $unmute.size(36, 36).center(0, 1).bg("assets/images/ui/unmute.png").css({
12426 opacity: 0
12427 })
12428 }
12429
12430 function initBar() {
12431 _bar = _this.initClass(LightboxVideoControlsSeek, "#71c5ff");
12432 _bar.resize(100);
12433 _bar.update(_volume);
12434 _bar.css({
12435 left: 60
12436 })
12437 }
12438
12439 function addListeners() {
12440 $button.interact(hover, click);
12441 _bar.events.add(HydraEvents.UPDATE, update)
12442 }
12443
12444 function hover(e) {
12445 switch (e.action) {
12446 case "over":
12447 $this.tween({
12448 opacity: 1
12449 }, 300, "easeOutSine");
12450 break;
12451 case "out":
12452 $this.tween({
12453 opacity: .7
12454 }, 300, "easeOutSine");
12455 break
12456 }
12457 }
12458
12459 function click() {
12460 if (_this.muted) {
12461 _bar.update(_volume);
12462 _this.muted = false;
12463 $mute.tween({
12464 opacity: 1
12465 }, 200, "easeInOutSine");
12466 $unmute.tween({
12467 opacity: 0
12468 }, 200, "easeOutSine");
12469 _this.events.fire(HydraEvents.UPDATE, {
12470 type: "volume",
12471 perc: _volume
12472 })
12473 } else {
12474 _this.muted = true;
12475 _bar.update(0);
12476 $mute.tween({
12477 opacity: 0
12478 }, 200, "easeOutSine");
12479 $unmute.tween({
12480 opacity: 1
12481 }, 200, "easeInOutSine");
12482 _this.events.fire(HydraEvents.UPDATE, {
12483 type: "volume",
12484 perc: 0
12485 })
12486 }
12487 }
12488
12489 function update(e) {
12490 _volume = e.perc;
12491 if (_this.muted) {
12492 click()
12493 } else {
12494 _bar.update(_volume);
12495 _this.events.fire(HydraEvents.UPDATE, {
12496 type: "volume",
12497 perc: _volume
12498 })
12499 }
12500 }
12501 this.resize = function() {};
12502 this.animateIn = function() {}
12503});
12504Class(function LoaderCircleReveal(_radius, _flippedX, _flippedY) {
12505 Inherit(this, View);
12506 var _this = this;
12507 var $this, $circle;
12508 var _thickness = 2;
12509 var _gap = 20;
12510 (function() {
12511 initHTML();
12512 style()
12513 }());
12514
12515 function initHTML() {
12516 $this = _this.element;
12517 $circle = $this.create("Circle")
12518 }
12519
12520 function style() {
12521 $this.size(_radius * 2, _radius * 2).center().css({
12522 overflow: "hidden",
12523 marginLeft: _gap,
12524 transformOrigin: -_gap + "px 60px",
12525 webkitTransformOrigin: -_gap + "px 60px"
12526 });
12527 $circle.css({
12528 left: _thickness - _radius - _gap + "px",
12529 top: _thickness + "px",
12530 opacity: .4,
12531 padding: _radius - _thickness,
12532 borderRadius: "1000px",
12533 boxShadow: "0px 0px 0px " + _thickness + "px #4ed19d"
12534 });
12535 $this.transform({
12536 y: _radius * 2 * (_flippedY ? -1 : 1),
12537 scaleX: _flippedX ? -1 : 1
12538 });
12539 $circle.transform({
12540 y: _radius * -2 * (_flippedY ? -1 : 1)
12541 })
12542 }
12543 this.animate = function() {
12544 $this.tween({
12545 y: 0
12546 }, 1e3, "easeInOutCubic");
12547 $circle.tween({
12548 y: 0
12549 }, 1e3, "easeInOutCubic")
12550 }
12551});
12552Class(function LoaderDottedCircle(_circleRadius, _num, _gutter) {
12553 Inherit(this, View);
12554 var _this = this;
12555 var $this;
12556 var _dots = [];
12557 var _radius = 2;
12558 (function() {
12559 initHTML();
12560 style();
12561 initDots()
12562 }());
12563
12564 function initHTML() {
12565 $this = _this.element
12566 }
12567
12568 function style() {
12569 $this.size(0, 0).center()
12570 }
12571
12572 function initDots() {
12573 for (var i = 0; i < _num; i++) {
12574 var dot = createDot(i / _num);
12575 _dots.push(dot)
12576 }
12577 }
12578
12579 function createDot(perc) {
12580 var $dot = $this.create("Dot");
12581 var angle = perc * Math.PI * 2 + Math.PI * .5;
12582 $dot.css({
12583 padding: _radius,
12584 margin: -_radius,
12585 borderRadius: 1e3,
12586 background: "rgba(78, 209, 157, 0.7)",
12587 left: Math.cos(angle) * _circleRadius,
12588 top: Math.sin(angle) * _circleRadius,
12589 display: Math.abs(Math.cos(angle)) < _gutter ? "none" : "block",
12590 opacity: 0
12591 });
12592 return $dot
12593 }
12594 this.fadeIn = function() {
12595 _dots.every(($dot, i) => {
12596 if (i % 4 !== 0) return true;
12597 $dot.css({
12598 opacity: 1
12599 });
12600 return true
12601 });
12602 _this.delayedCall(() => {
12603 _dots.every(($dot, i) => {
12604 if ((i + 1) % 3 == 0) return true;
12605 $dot.css({
12606 opacity: 1
12607 });
12608 return true
12609 })
12610 }, 300);
12611 _this.delayedCall(() => {
12612 _dots.every(($dot, i) => {
12613 $dot.css({
12614 opacity: 1
12615 });
12616 return true
12617 })
12618 }, 500)
12619 };
12620 this.animate = () => {
12621 _dots.forEach(function($dot, i) {
12622 var perc = i / _num;
12623 var angle = perc * Math.PI * 2 + Math.PI * .5;
12624 $dot.tween({
12625 x: Math.cos(angle) * -230,
12626 y: Math.sin(angle) * -230
12627 }, 15e2, "easeInOutQuint")
12628 });
12629 _this.delayedCall(() => {
12630 _dots.every(($dot, i) => {
12631 if (i % 2 !== 0) return true;
12632 $dot.css({
12633 display: "none"
12634 });
12635 return true
12636 })
12637 }, 800);
12638 _this.delayedCall(() => {
12639 _dots.every(($dot, i) => {
12640 if ((i + 1) % 4 !== 0) return true;
12641 $dot.css({
12642 display: "none"
12643 });
12644 return true
12645 })
12646 }, 1e3)
12647 }
12648});
12649Class(function LoaderDottedLine() {
12650 Inherit(this, View);
12651 var _this = this;
12652 var $this;
12653 var _dots = [];
12654 var _height = 1e3;
12655 var _num = 36;
12656 var _radius = 2;
12657 (function() {
12658 initHTML();
12659 style();
12660 initDots()
12661 }());
12662
12663 function initHTML() {
12664 $this = _this.element
12665 }
12666
12667 function style() {
12668 $this.size(0, _height).center()
12669 }
12670
12671 function initDots() {
12672 for (var i = 0; i < _num; i++) {
12673 var dot = createDot(i / (_num - 1));
12674 _dots.push(dot)
12675 }
12676 }
12677
12678 function createDot(perc) {
12679 var $dot = $this.create("Dot");
12680 $dot.css({
12681 padding: _radius,
12682 margin: -_radius,
12683 borderRadius: 1e3,
12684 background: "rgba(78, 209, 157, 0.7)",
12685 top: perc * 100 + "%",
12686 opacity: 0
12687 });
12688 return $dot
12689 }
12690 this.fadeIn = function() {
12691 _dots.every(($dot, i) => {
12692 if (i % 4 !== 0) return true;
12693 $dot.css({
12694 opacity: 1
12695 });
12696 return true
12697 });
12698 _this.delayedCall(() => {
12699 _dots.every(($dot, i) => {
12700 if ((i + 1) % 3 == 0) return true;
12701 $dot.css({
12702 opacity: 1
12703 });
12704 return true
12705 })
12706 }, 200);
12707 _this.delayedCall(() => {
12708 _dots.every(($dot, i) => {
12709 $dot.css({
12710 opacity: 1
12711 });
12712 return true
12713 })
12714 }, 300)
12715 }
12716});
12717Class(function LoaderTextCircle(_text, _size, _range, _flipped) {
12718 Inherit(this, View);
12719 var _this = this;
12720 var $this;
12721 var _letters = [];
12722 var _radius = 160;
12723 var _arc = _range * Math.PI * 2;
12724 (function() {
12725 initHTML();
12726 style();
12727 initLetters()
12728 }());
12729
12730 function initHTML() {
12731 $this = _this.element
12732 }
12733
12734 function style() {
12735 $this.size(0, 0).center();
12736 $this.html(_text).css({
12737 fontSize: _size,
12738 color: "rgba(78, 209, 157, 0.25)"
12739 });
12740 $this.hide()
12741 }
12742
12743 function initLetters() {
12744 _letters = SplitTextfield.split($this);
12745 _letters.forEach((letter, i) => {
12746 var perc = i / (_letters.length - 1);
12747 var angle = perc * _arc - _arc * .5;
12748 if (_flipped) angle = Math.PI - angle;
12749 letter.css({
12750 position: "absolute",
12751 left: Math.sin(angle) * _radius,
12752 top: Math.cos(angle) * _radius,
12753 margin: -.33 * _size
12754 })
12755 })
12756 }
12757 this.animate = function(range, callback) {
12758 var arc2 = range * Math.PI * 2;
12759 _letters.forEach((letter, i) => {
12760 var perc = i / (_letters.length - 1);
12761 var angle1 = perc * _arc - _arc * .5;
12762 if (_flipped) angle1 = Math.PI - angle1;
12763 var angle2 = perc * arc2 - arc2 * .5;
12764 if (_flipped) angle2 = Math.PI - angle2;
12765 var x0 = Math.sin(angle1) * _radius;
12766 var y0 = Math.cos(angle1) * _radius;
12767 var x1 = Math.sin(angle2) * _radius;
12768 var y1 = Math.cos(angle2) * _radius;
12769 letter.tween({
12770 x: x1 - x0,
12771 y: y1 - y0
12772 }, 700, "easeInOutQuint", () => {
12773 if (callback) callback()
12774 })
12775 })
12776 }
12777});
12778Class(function LoaderTextSeparating(_text, _radius) {
12779 Inherit(this, View);
12780 var _this = this;
12781 var $this;
12782 var _letters = [];
12783 var _size = 10;
12784 (function() {
12785 initHTML();
12786 style();
12787 initLetters()
12788 }());
12789
12790 function initHTML() {
12791 $this = _this.element
12792 }
12793
12794 function style() {
12795 $this.size(0, _size).center();
12796 $this.html(_text).css({
12797 fontSize: _size,
12798 color: "rgba(78, 209, 157, 0.25)"
12799 });
12800 $this.hide()
12801 }
12802
12803 function initLetters() {
12804 _letters = SplitTextfield.split($this);
12805 _letters.forEach(($letter, i) => {
12806 var perc = i / (_letters.length - 1);
12807 $letter.css({
12808 position: "absolute",
12809 left: perc * _radius * 2 - _radius,
12810 top: 0,
12811 margin: -.33 * _size
12812 })
12813 })
12814 }
12815 this.animate = () => {
12816 var spread = 90;
12817 _letters.forEach(($letter, i) => {
12818 var perc = i / (_letters.length - 1);
12819 $letter.tween({
12820 x: perc * spread * 2 - spread
12821 }, 500, "easeInOutQuint")
12822 })
12823 }
12824});
12825Class(function LoaderTextVertical() {
12826 Inherit(this, View);
12827 var _this = this;
12828 var $this;
12829 var _letters = [];
12830 var _radius = 190;
12831 var _size = 10;
12832 (function() {
12833 initHTML();
12834 style();
12835 initLetters()
12836 }());
12837
12838 function initHTML() {
12839 $this = _this.element
12840 }
12841
12842 function style() {
12843 $this.size(0, _size).center();
12844 $this.html("GEOGRAPHY").css({
12845 fontSize: _size,
12846 color: "rgba(78, 209, 157, 0.25)"
12847 });
12848 $this.hide()
12849 }
12850
12851 function initLetters() {
12852 _letters = SplitTextfield.split($this);
12853 _letters.forEach((letter, i) => {
12854 var perc = i / (_letters.length - 1);
12855 letter.css({
12856 position: "absolute",
12857 top: perc * _radius * 2 - _radius,
12858 margin: -.33 * _size
12859 })
12860 })
12861 }
12862});
12863Class(function LoaderView() {
12864 Inherit(this, View);
12865 var _this = this;
12866 var $this, $container;
12867 var _dottedLine, _dottedCircle1, _dottedCircle2;
12868 var _circles = [];
12869 var _texts = [];
12870 (function() {
12871 initHTML();
12872 style();
12873 initCircles();
12874 initDots();
12875 initText()
12876 }());
12877
12878 function initHTML() {
12879 $this = _this.element;
12880 $container = $this.create("LoaderScaleContainer")
12881 }
12882
12883 function style() {
12884 $this.size("100%").setZ(20);
12885 $container.size("100%");
12886 if (Mobile.phone) $container.transform({
12887 scale: .7
12888 });
12889 $this.css({
12890 opacity: 0
12891 }).transform({
12892 scale: 1.15
12893 }).tween({
12894 opacity: 1,
12895 scale: 1
12896 }, 800, "easeOutCubic")
12897 }
12898
12899 function initCircles() {
12900 [
12901 [102, true, false],
12902 [102, false, false],
12903 [110, true, true],
12904 [110, false, true]
12905 ].forEach(data => {
12906 var circle = _this.initClass(LoaderCircleReveal, data[0], data[1], data[2], [$container]);
12907 _circles.push(circle)
12908 })
12909 }
12910
12911 function initDots() {
12912 _dottedLine = _this.initClass(LoaderDottedLine, [$container]);
12913 _dottedCircle1 = _this.initClass(LoaderDottedCircle, 300, 50, .2, [$container]);
12914 _dottedCircle2 = _this.initClass(LoaderDottedCircle, 200, 36, .3, [$container])
12915 }
12916
12917 function initText() {
12918 [
12919 ["BOOTUP", 90],
12920 ["ANALYZING", 180]
12921 ].forEach(data => {
12922 _texts.push(_this.initClass(LoaderTextSeparating, data[0], data[1], [$container]))
12923 });
12924 _texts.push(_this.initClass(LoaderTextVertical, [$container]));
12925 [
12926 ["MAPPING", 10, .35, true],
12927 ["SURFACE", 10, .35, false],
12928 ["TOONAMI", 14, .35, true],
12929 ["TOONAMI", 14, .35, false]
12930 ].forEach(data => {
12931 _texts.push(_this.initClass(LoaderTextCircle, data[0], data[1], data[2], data[3], [$container]))
12932 })
12933 }
12934
12935 function textAnimation1() {
12936 if (_this.isTextAnim1) return;
12937 _this.isTextAnim1 = true;
12938 _texts[0].element.show();
12939 _texts[0].animate();
12940 _this.delayedCall(() => {
12941 _texts[0].element.hide();
12942 _texts[1].element.show()
12943 }, 600)
12944 }
12945
12946 function textAnimation2() {
12947 if (_this.isTextAnim2) return;
12948 _this.isTextAnim2 = true;
12949 _this.delayedCall(() => {
12950 _texts[2].element.show()
12951 }, 0)
12952 }
12953
12954 function textAnimation3() {
12955 if (_this.isTextAnim3) return;
12956 _this.isTextAnim3 = true;
12957 _this.delayedCall(() => {
12958 _texts[1].element.hide()
12959 }, 800)
12960 }
12961
12962 function textAnimation4() {
12963 if (_this.isTextAnim4) return;
12964 _this.isTextAnim4 = true;
12965 _this.delayedCall(() => {
12966 _texts[2].element.hide()
12967 }, 200)
12968 }
12969
12970 function textAnimation5() {
12971 if (_this.isTextAnim5) return;
12972 _this.isTextAnim5 = true;
12973 _this.delayedCall(() => {
12974 _texts[3].element.show();
12975 _texts[4].element.show()
12976 }, 0)
12977 }
12978
12979 function textAnimation6() {
12980 if (_this.isTextAnim6) return;
12981 _this.isTextAnim6 = true;
12982 _this.delayedCall(() => {
12983 _texts[3].animate(.2);
12984 _texts[4].animate(.2, () => {
12985 if (_this.delayedCall) _this.delayedCall(() => {
12986 _texts[3].element.hide();
12987 _texts[4].element.hide()
12988 }, 100)
12989 })
12990 }, 300)
12991 }
12992
12993 function textAnimation7() {
12994 if (_this.isTextAnim7) return;
12995 _this.isTextAnim7 = true;
12996 _this.delayedCall(() => {
12997 _texts[5].element.show();
12998 _texts[6].element.show()
12999 }, 12e2)
13000 }
13001
13002 function dotsAnimation1() {
13003 if (_this.isDotsAnim1) return;
13004 _this.isDotsAnim1 = true;
13005 _dottedCircle2.fadeIn()
13006 }
13007
13008 function dotsAnimation2() {
13009 if (_this.isDotsAnim2) return;
13010 _this.isDotsAnim2 = true;
13011 _this.delayedCall(() => {
13012 _dottedLine.fadeIn()
13013 }, 0)
13014 }
13015
13016 function dotsAnimation3() {
13017 if (_this.isDotsAnim3) return;
13018 _this.isDotsAnim3 = true;
13019 _this.delayedCall(() => {
13020 _dottedCircle1.fadeIn()
13021 }, 0);
13022 _this.delayedCall(() => {
13023 _dottedCircle1.animate()
13024 }, 500)
13025 }
13026
13027 function circleAnimation() {
13028 if (_this.isCircleAnim) return;
13029 _this.isCircleAnim = true;
13030 _this.delayedCall(() => {
13031 _circles[0].animate();
13032 _circles[1].animate()
13033 }, 800);
13034 _this.delayedCall(() => {
13035 _circles[2].animate();
13036 _circles[3].animate()
13037 }, 600)
13038 }
13039 this.update = progress => {
13040 if (progress > .1) textAnimation1();
13041 if (progress > .2) textAnimation2();
13042 if (progress > .3) textAnimation3();
13043 if (progress > .4) textAnimation4();
13044 if (progress > .6) textAnimation5();
13045 if (progress > .7) textAnimation6();
13046 if (progress > .9) textAnimation7();
13047 if (progress > .1) dotsAnimation1();
13048 if (progress > .2) dotsAnimation2();
13049 if (progress > .9) dotsAnimation3();
13050 if (progress > .8) circleAnimation()
13051 };
13052 this.animateOut = callback => {
13053 if (!Tests.pauseRenderLoaderFade()) {
13054 $this.tween({
13055 opacity: 0,
13056 scale: 1.1,
13057 rotation: 0
13058 }, Utils.query("skip") ? 1e3 : 2e3, "easeInOutCubic", 700, callback)
13059 } else {
13060 _this.delayedCall(() => {
13061 $this.tween({
13062 opacity: 0,
13063 scale: 1.1,
13064 rotation: 0
13065 }, 500, "easeInOutCubic", () => {
13066 callback()
13067 })
13068 }, 900)
13069 }
13070 }
13071});
13072Class(function NavView(_data) {
13073 Inherit(this, View);
13074 var _this = this;
13075 var $this, $outline;
13076 var _items, _dropdowns;
13077 _this.width = 350;
13078 _this.height = 36;
13079 (function() {
13080 initHTML();
13081 initOutline();
13082 initItems();
13083 _this.delayedCall(setWidths, 50)
13084 }());
13085
13086 function initHTML() {
13087 $this = _this.element;
13088 $this.size(_this.width, _this.height).css({
13089 right: 110,
13090 top: 35
13091 }).invisible()
13092 }
13093
13094 function initOutline() {
13095 $outline = $this.create(".outline");
13096 $outline.size(_this.width - 2, _this.height - 2).css({
13097 border: "1px solid #fff",
13098 opacity: .12
13099 }).setZ(1)
13100 }
13101
13102 function initItems() {
13103 _items = [];
13104 _dropdowns = [];
13105 for (var i = 0; i < _data.length; i++) {
13106 _data[i].height = _this.height;
13107 var item = _this.initClass(NavItem, _data[i]);
13108 item.type = _data[i].text;
13109 if (_data[i].dropdown) _dropdowns.push(item);
13110 _this.events.bubble(item, HydraEvents.HOVER);
13111 _items.push(item)
13112 }
13113 }
13114
13115 function setWidths() {
13116 _this.width = 0;
13117 $outline.html("");
13118 for (var i = 0; i < _items.length; i++) {
13119 var width = _items[i].text.width;
13120 _items[i].css({
13121 width: _items[i].text.width,
13122 left: _this.width
13123 });
13124 var $line = $outline.create(".line");
13125 $line.css({
13126 width: 1,
13127 height: "100%",
13128 left: _this.width - 2
13129 }).bg("#fff");
13130 _this.width += _items[i].text.width + 1
13131 }
13132 $this.size(_this.width, _this.height);
13133 $outline.size(_this.width - 2, _this.height - 2)
13134 }
13135 this.activate = function(text) {
13136 for (var i = 0; i < _dropdowns.length; i++) {
13137 if (_dropdowns[i].type == text) _dropdowns[i].activate();
13138 else _dropdowns[i].deactivate()
13139 }
13140 };
13141 this.deactivate = function() {
13142 for (var i = 0; i < _dropdowns.length; i++) {
13143 _dropdowns[i].deactivate()
13144 }
13145 };
13146 this.animateIn = function() {
13147 _this.visible = true;
13148 $this.visible();
13149 $outline.stopTween().css({
13150 opacity: 0
13151 }).transform({
13152 scaleY: 0
13153 }).tween({
13154 opacity: .1,
13155 scaleY: 1
13156 }, 600, "easeOutQuart");
13157 for (var i = 0; i < _items.length; i++) {
13158 _items[i].animateIn(i * 50)
13159 }
13160 };
13161 this.animateOut = function() {
13162 _this.visible = false;
13163 for (var i = 0; i < _items.length; i++) {
13164 _items[i].animateOut(i * 30)
13165 }
13166 $outline.tween({
13167 opacity: 0,
13168 scaleY: 0
13169 }, 400, "easeOutQuart", function() {
13170 $this.invisible()
13171 })
13172 }
13173});
13174Class(function NavItem(_data) {
13175 Inherit(this, View);
13176 var _this = this;
13177 var $this, $line, $solid, $wrap, $glow;
13178 var _text, _over;
13179 (function() {
13180 initHTML();
13181 initText();
13182 initOver();
13183 if (_data.dropdown) defer(initDropdown);
13184 addListeners()
13185 }());
13186
13187 function initHTML() {
13188 $this = _this.element;
13189 $this.size("100%", _data.height).invisible().setZ(10);
13190 $wrap = $this.create(".wrap");
13191 $wrap.size("100%").css({
13192 overflow: "hidden"
13193 });
13194 $glow = $this.create(".glow");
13195 $glow.size("100%").css({
13196 boxShadow: "0 0 50px #e4ffec",
13197 opacity: 0
13198 })
13199 }
13200
13201 function initText() {
13202 _text = _this.initClass(NavItemText, _data, "#e4ffec", [$wrap]);
13203 _text.element.css({
13204 opacity: .5
13205 });
13206 _this.text = _text
13207 }
13208
13209 function initOver() {
13210 $solid = $wrap.create(".solid");
13211 $solid.size("100%").bg("#edfff2").css({
13212 top: "100%",
13213 opacity: .7
13214 }).transform({
13215 y: -_data.height * 2
13216 });
13217 _over = _this.initClass(NavItemText, _data, "#052223", [$wrap]);
13218 _over.hidden = true;
13219 _over.element.css({
13220 opacity: 0,
13221 fontWeight: "bold"
13222 })
13223 }
13224
13225 function initDropdown() {
13226 $line = $this.create(".line");
13227 $line.size(1, 20).bg("#fff").center(1, 0).css({
13228 bottom: -20,
13229 opacity: .3
13230 }).transformPoint("50%", "0%").transform({
13231 scaleY: 0
13232 });
13233 _text.css({
13234 left: -7
13235 });
13236 var $arrow = _text.element.create(".arrow");
13237 $arrow.size(10, 10).bg("assets/images/ui/down-white.png").center(0, 1).css({
13238 right: 10,
13239 marginTop: -6
13240 });
13241 _over.css({
13242 left: -7
13243 });
13244 var $arrow = _over.element.create(".arrow");
13245 $arrow.size(9, 9).bg("assets/images/ui/down-black.png").center(0, 1).css({
13246 right: 10,
13247 marginTop: -6
13248 })
13249 }
13250
13251 function addListeners() {
13252 $this.interact(hover, click)
13253 }
13254
13255 function hover(e) {
13256 if (_this.isActive) return;
13257 _this.events.fire(HydraEvents.HOVER, {
13258 action: e.action,
13259 text: _data.text
13260 });
13261 switch (e.action) {
13262 case "over":
13263 _over.hidden = false;
13264 _text.hidden = true;
13265 $solid.stopTween().transform({
13266 y: 0
13267 }).tween({
13268 y: -_data.height,
13269 opacity: 1
13270 }, 300, "easeOutQuart");
13271 _over.glitch();
13272 _over.element.tween({
13273 opacity: 1
13274 }, 200, "easeOutSine");
13275 $glow.tween({
13276 opacity: .7
13277 }, 300, "easeOutSine");
13278 break;
13279 case "out":
13280 _text.hidden = false;
13281 _over.hidden = true;
13282 $solid.tween({
13283 y: -_data.height * 2,
13284 opacity: .7
13285 }, 400, "easeOutQuart");
13286 _over.element.tween({
13287 opacity: 0
13288 }, 200, "easeOutSine");
13289 $glow.tween({
13290 opacity: 0
13291 }, 400, "easeOutSine");
13292 break
13293 }
13294 }
13295
13296 function click() {
13297 if (_data.url) {
13298 getURL(_data.url, "_blank");
13299 hover({
13300 action: "out"
13301 })
13302 } else {}
13303 let text = _data.text.toLowerCase();
13304 let name, dynamic;
13305 if (text == "toonami stream") {
13306 name = text;
13307 dynamic = "";
13308 TrackUtil.event({
13309 name: name,
13310 dynamic: dynamic
13311 })
13312 } else if (text == "toonami fan" || text == "toonami digital arsenal" || text == "toonami faithful") {
13313 name = "fan sites";
13314 dynamic = _data.text;
13315 TrackUtil.event({
13316 name: name,
13317 dynamic: dynamic
13318 })
13319 } else if (text == "submit a question") {
13320 name = "links";
13321 dynamic = _data.text;
13322 TrackUtil.event({
13323 name: name,
13324 dynamic: dynamic
13325 });
13326 TrackUtil.event({
13327 name: "menu",
13328 dynamic: dynamic
13329 })
13330 } else if (text == "facebook" || text == "tumblr") {
13331 name = "links";
13332 dynamic = text;
13333 TrackUtil.event({
13334 name: name,
13335 dynamic: dynamic
13336 })
13337 }
13338 if (text != "submit a question") TrackUtil.event({
13339 name: "menu",
13340 dynamic: text
13341 })
13342 }
13343 this.activate = function() {
13344 _this.isActive = true;
13345 $line.tween({
13346 scaleY: 1
13347 }, 400, "easeOutCubic")
13348 };
13349 this.deactivate = function() {
13350 _this.isActive = false;
13351 hover({
13352 action: "out"
13353 });
13354 $line.tween({
13355 scaleY: 0
13356 }, 400, "easeOutCubic")
13357 };
13358 this.animateIn = function() {
13359 $this.visible();
13360 _text.glitch();
13361 $this.css({
13362 opacity: 0
13363 }).tween({
13364 opacity: 1
13365 }, 300, "easeOutSine")
13366 };
13367 this.animateOut = function() {
13368 $this.tween({
13369 opacity: 0
13370 }, 300, "easeOutSine", function() {
13371 $this.invisible()
13372 })
13373 }
13374});
13375Class(function NavItemText(_data, _color) {
13376 Inherit(this, View);
13377 var _this = this;
13378 var $this;
13379 var _letters, _timeout;
13380 var _chars = "ABCDEFGHIJKLNOPQRSTUVXYZ0123456789".split("");
13381 (function() {
13382 initHTML();
13383 Render.start(loop)
13384 }());
13385
13386 function initHTML() {
13387 $this = _this.element;
13388 $this.fontStyle("GothamRnd", 9, _color);
13389 $this.css({
13390 textAlign: "center",
13391 top: "50%",
13392 letterSpacing: 1,
13393 marginTop: -5
13394 });
13395 $this.text(_data.text.toUpperCase());
13396 defer(function() {
13397 _this.width = CSS.textSize($this).width + (_data.dropdown ? 50 : 34);
13398 $this.css({
13399 width: _this.width
13400 });
13401 _letters = SplitTextfield.split($this);
13402 for (var i = 0; i < _letters.length; i++) {
13403 _letters[i].css({
13404 position: "relative",
13405 float: "",
13406 cssFloat: "",
13407 styleFloat: "",
13408 display: "inline-block"
13409 });
13410 _letters[i].base = _letters[i].div.innerHTML;
13411 _letters[i].canGlitch = _letters[i].div.innerHTML.length < 2 && _letters[i].div.innerHTML !== "-"
13412 }
13413 })
13414 }
13415
13416 function loop(t) {
13417 if (_this.hidden || !_this.animating || t - _this.time < 60) return;
13418 _this.time = t;
13419 for (var i = 0; i < _letters.length; i++) {
13420 var $letter = _letters[i];
13421 if ($letter.canGlitch) {
13422 if (Utils.doRandom(0, 1) == 0 && $letter.glitching) {
13423 $letter.reset = false;
13424 var letter = _chars[Utils.doRandom(0, _chars.length - 1)];
13425 _letters[i].html(letter)
13426 } else {
13427 if (!$letter.reset) {
13428 $letter.reset = true;
13429 $letter.html($letter.base)
13430 }
13431 }
13432 }
13433 }
13434 }
13435 this.glitch = function() {
13436 clearTimeout(_timeout);
13437 _this.animating = true;
13438 for (var i = 0; i < _letters.length; i++) {
13439 if (_letters[i].canGlitch) glitchLetter(_letters[i], Utils.doRandom(0, 8))
13440 }
13441
13442 function glitchLetter($letter, amount) {
13443 $letter.glitching = true;
13444 _this.delayedCall(function() {
13445 $letter.glitching = false
13446 }, amount * 40)
13447 }
13448 _timeout = _this.delayedCall(function() {
13449 _this.animating = false
13450 }, 400)
13451 };
13452 this.onDestroy = function() {
13453 Render.stop(loop)
13454 }
13455});
13456Class(function NavShare() {
13457 Inherit(this, View);
13458 var _this = this;
13459 var $this;
13460 var _tw, _fb;
13461 (function() {
13462 initHTML();
13463 initIcons()
13464 }());
13465
13466 function initHTML() {
13467 $this = _this.element;
13468 $this.size(60, 30).css({
13469 right: 7,
13470 top: 38
13471 }).invisible()
13472 }
13473
13474 function initIcons() {
13475 _tw = _this.initClass(NavShareIcon, "tw");
13476 _tw.css({
13477 left: 25
13478 });
13479 _fb = _this.initClass(NavShareIcon, "fb");
13480 _fb.css({})
13481 }
13482 this.animateIn = function() {
13483 $this.visible().css({
13484 opacity: 0
13485 }).tween({
13486 opacity: 1
13487 }, 1e3, "easeOutSine")
13488 }
13489});
13490Class(function NavShareIcon(_type) {
13491 Inherit(this, View);
13492 var _this = this;
13493 var $this, $icon;
13494 (function() {
13495 initHTML();
13496 addListeners()
13497 }());
13498
13499 function initHTML() {
13500 $this = _this.element;
13501 $this.size(30, 30);
13502 $icon = $this.create(".icon");
13503 $icon.size(17, 17).center().bg("assets/images/ui/share/" + _type + ".png").css({
13504 opacity: .4
13505 })
13506 }
13507
13508 function addListeners() {
13509 $this.interact(hover, click)
13510 }
13511
13512 function hover(e) {
13513 switch (e.action) {
13514 case "over":
13515 $icon.tween({
13516 opacity: 1
13517 }, 200, "easeOutSine");
13518 break;
13519 case "out":
13520 $icon.tween({
13521 opacity: .4
13522 }, 200, "easeOutSine");
13523 break
13524 }
13525 }
13526
13527 function click() {
13528 let type = _type;
13529 if (_type === "fb") type = "facebook";
13530 if (_type === "tw") type = "twitter";
13531 Share.click(type);
13532 TrackUtil.event({
13533 name: "social",
13534 dynamic: type
13535 })
13536 }
13537 this.animateIn = function() {}
13538});
13539Class(function NavTimeline() {
13540 Inherit(this, View);
13541 var _this = this;
13542 var $this;
13543 var _items;
13544 var _current = -1;
13545 (function() {
13546 initHTML();
13547 initItems();
13548 addListeners();
13549 defer(resizeHandler);
13550 Render.start(loop)
13551 }());
13552
13553 function initHTML() {
13554 $this = _this.element;
13555 $this.size(100, 600).center(0, 1).css({
13556 right: 0
13557 }).invisible().transform({
13558 x: 0
13559 }).mouseEnabled(false)
13560 }
13561
13562 function initItems() {
13563 var items = [{
13564 text: "LATEST",
13565 color: "#a9eeaa",
13566 height: 60
13567 }, {
13568 text: "SCHEDULE",
13569 color: "#7ee3c3",
13570 height: 75
13571 }, {
13572 text: "GALLERY",
13573 color: "#96eaf2",
13574 height: 70
13575 }, {
13576 text: "DOWNLOADS",
13577 color: "#83bdf8",
13578 height: 95
13579 }];
13580 _items = [];
13581 for (var i = 0; i < items.length; i++) {
13582 var item = _this.initClass(NavTimelineItem, items[i]);
13583 item.css({
13584 top: i * 150
13585 });
13586 _items.push(item)
13587 }
13588 }
13589
13590 function loop() {
13591 if (_current !== Config.CLOSEST_SECTION) {
13592 _current = Config.CLOSEST_SECTION;
13593 for (var i = 0; i < _items.length; i++) {
13594 if (i == _current) _items[i].activate();
13595 else _items[i].deactivate()
13596 }
13597 }
13598 }
13599
13600 function addListeners() {
13601 _this.events.subscribe(HydraEvents.RESIZE, resizeHandler)
13602 }
13603
13604 function resizeHandler() {
13605 var size = Math.round(Stage.height * .141);
13606 var fontSize = Utils.convertRange(size, 60, 140, 8, 12);
13607 for (var i = 0; i < _items.length; i++) {
13608 _items[i].css({
13609 height: size,
13610 top: i * size
13611 });
13612 _items[i].text.css({
13613 fontSize: fontSize,
13614 top: Math.round(size / 2) - 23
13615 })
13616 }
13617 $this.size(100, size * _items.length).center(0, 1)
13618 }
13619 this.animateIn = function() {
13620 $this.visible();
13621 for (var i = 0; i < _items.length; i++) {
13622 _this.delayedCall(_items[i].animateIn, i * 100)
13623 }
13624 }
13625});
13626Class(function NavTimelineItem(_config) {
13627 Inherit(this, View);
13628 var _this = this;
13629 var $this, $text, $behind, $bar;
13630 (function() {
13631 initHTML();
13632 initText();
13633 initBar();
13634 addListeners()
13635 }());
13636
13637 function initHTML() {
13638 $this = _this.element;
13639 $this.size(100, 150).invisible()
13640 }
13641
13642 function initText() {
13643 $text = $this.create(".text");
13644 $text.fontStyle("GothamRnd", 12, _config.color);
13645 $text.size(200, 50).css({
13646 top: 32,
13647 left: -45,
13648 opacity: .5,
13649 textAlign: "center",
13650 letterSpacing: 1.5,
13651 fontWeight: "bold"
13652 }).transform({
13653 rotation: 90
13654 });
13655 $text.text(_config.text);
13656 _this.text = $text
13657 }
13658
13659 function initBar() {
13660 $behind = $this.create(".bar");
13661 $behind.css({
13662 height: "82%",
13663 top: "9%",
13664 width: 6,
13665 right: 0,
13666 opacity: .2
13667 }).bg(_config.color);
13668 $bar = $this.create(".bar");
13669 $bar.css({
13670 height: "82%",
13671 top: "9%",
13672 width: 6,
13673 right: 0,
13674 opacity: 1
13675 }).bg(_config.color).transform({
13676 x: 6
13677 })
13678 }
13679
13680 function addListeners() {
13681 $this.interact(hover, click);
13682 $this.hit.mouseEnabled(true)
13683 }
13684
13685 function hover(e) {
13686 if (_this.isActive) return;
13687 switch (e.action) {
13688 case "over":
13689 $text.tween({
13690 opacity: 1
13691 }, 200, "easeOutSine");
13692 $bar.tween({
13693 x: 0
13694 }, 200, "easeOutQuart");
13695 break;
13696 case "out":
13697 $text.tween({
13698 opacity: .5
13699 }, 300, "easeOutSine");
13700 $bar.tween({
13701 x: 6
13702 }, 400, "easeOutQuart");
13703 break
13704 }
13705 }
13706
13707 function click() {
13708 _this.events.fire(World.CLICK);
13709 let text = _config.text.toLowerCase();
13710 let name, dynamic;
13711 if (text == "latest" || text == "gallery") {
13712 name = text;
13713 dynamic = "";
13714 TrackUtil.event({
13715 name: name,
13716 dynamic: dynamic
13717 })
13718 }
13719 TrackUtil.event({
13720 name: "menu",
13721 dynamic: text
13722 })
13723 }
13724 this.activate = function() {
13725 if (_this.isActive) return;
13726 _this.isActive = true;
13727 $text.tween({
13728 opacity: 1
13729 }, 200, "easeOutSine");
13730 $bar.tween({
13731 x: 0
13732 }, 200, "easeOutQuart")
13733 };
13734 this.deactivate = function() {
13735 if (!_this.isActive) return;
13736 _this.isActive = false;
13737 $text.tween({
13738 opacity: .5
13739 }, 300, "easeOutSine");
13740 $bar.tween({
13741 x: 6
13742 }, 400, "easeOutQuart")
13743 };
13744 this.animateIn = function() {
13745 $this.visible();
13746 $this.transform({
13747 x: 30
13748 }).tween({
13749 x: 0
13750 }, 1e3, "easeOutQuart")
13751 }
13752});
13753Class(function PlaygroundBackground() {
13754 Inherit(this, Component);
13755 var _this = this;
13756 this.group = new THREE.Group;
13757 (function() {}())
13758});
13759Class(function PlaygroundCSSLoader() {
13760 Inherit(this, View);
13761 var _this = this;
13762 var $this;
13763 var _dottedLine, _dottedCircle1, _dottedCircle2;
13764 var _circles = [];
13765 var _texts = [];
13766 var _perf = new RenderPerformance;
13767 this.group = new THREE.Group;
13768 (function() {
13769 initHTML();
13770 style();
13771 initCircles();
13772 initDots();
13773 initText();
13774 animate()
13775 }());
13776
13777 function initHTML() {
13778 $this = _this.element
13779 }
13780
13781 function style() {
13782 $this.size("100%").css({
13783 background: "#00000f"
13784 })
13785 }
13786
13787 function initCircles() {
13788 [
13789 [102, true, false],
13790 [102, false, false],
13791 [110, true, true],
13792 [110, false, true]
13793 ].forEach(data => {
13794 var circle = _this.initClass(LoaderCircleReveal, data[0], data[1], data[2]);
13795 _circles.push(circle)
13796 })
13797 }
13798
13799 function initDots() {
13800 _dottedLine = _this.initClass(LoaderDottedLine);
13801 _dottedCircle1 = _this.initClass(LoaderDottedCircle, 300, 50, .2);
13802 _dottedCircle2 = _this.initClass(LoaderDottedCircle, 200, 36, .3)
13803 }
13804
13805 function initText() {
13806 [
13807 ["BOOTUP", 90],
13808 ["ANALYZING", 180]
13809 ].forEach(data => {
13810 _texts.push(_this.initClass(LoaderTextSeparating, data[0], data[1]))
13811 });
13812 _texts.push(_this.initClass(LoaderTextVertical));
13813 [
13814 ["MAPPING", 10, .35, true],
13815 ["SURFACE", 10, .35, false],
13816 ["TOONAMI", 14, .35, true],
13817 ["TOONAMI", 14, .35, false]
13818 ].forEach(data => {
13819 _texts.push(_this.initClass(LoaderTextCircle, data[0], data[1], data[2], data[3]))
13820 })
13821 }
13822
13823 function animate() {
13824 textAnimation();
13825 dotsAnimation();
13826 circleAnimation()
13827 }
13828
13829 function textAnimation() {
13830 _texts[0].element.show();
13831 _texts[0].animate();
13832 _this.delayedCall(() => {
13833 _texts[0].element.hide();
13834 _texts[1].element.show()
13835 }, 1e3);
13836 _this.delayedCall(() => {
13837 _texts[2].element.show()
13838 }, 13e2);
13839 _this.delayedCall(() => {
13840 _texts[1].element.hide()
13841 }, 18e2);
13842 _this.delayedCall(() => {
13843 _texts[2].element.hide()
13844 }, 24e2);
13845 _this.delayedCall(() => {
13846 _texts[3].element.show();
13847 _texts[4].element.show()
13848 }, 28e2);
13849 _this.delayedCall(() => {
13850 _texts[3].animate(.2);
13851 _texts[4].animate(.2)
13852 }, 3e3);
13853 _this.delayedCall(() => {
13854 _texts[3].element.hide();
13855 _texts[4].element.hide()
13856 }, 45e2);
13857 _this.delayedCall(() => {
13858 _texts[5].element.show();
13859 _texts[6].element.show();
13860 animateOut()
13861 }, 48e2)
13862 }
13863
13864 function dotsAnimation() {
13865 _dottedCircle2.fadeIn();
13866 _this.delayedCall(() => {
13867 _dottedLine.fadeIn()
13868 }, 2e3);
13869 _this.delayedCall(() => {
13870 _dottedCircle1.fadeIn()
13871 }, 3e3);
13872 _this.delayedCall(() => {
13873 _dottedCircle1.animate()
13874 }, 35e2)
13875 }
13876
13877 function circleAnimation() {
13878 _this.delayedCall(() => {
13879 _circles[0].animate();
13880 _circles[1].animate()
13881 }, 38e2);
13882 _this.delayedCall(() => {
13883 _circles[2].animate();
13884 _circles[3].animate()
13885 }, 3e3)
13886 }
13887
13888 function animateOut() {
13889 $this.tween({
13890 opacity: 0
13891 }, 1e3, "easeInOutQuart", 1e3)
13892 }
13893});
13894Class(function PlaygroundCaption() {
13895 Inherit(this, Component);
13896 var _this = this;
13897 this.group = new THREE.Group;
13898 (function() {
13899 initCaption()
13900 }());
13901
13902 function initCaption() {
13903 var caption = _this.initClass(Caption, {
13904 text: "Winter is coming"
13905 });
13906 _this.group.add(caption.group)
13907 }
13908});
13909Class(function PlaygroundLandscape() {
13910 Inherit(this, Component);
13911 var _this = this;
13912 var _geometry, _shader, _mesh;
13913 this.group = new THREE.Group;
13914 (function() {
13915 initLights();
13916 initGeometry();
13917 initShader();
13918 initMesh();
13919 Render.start(loop)
13920 }());
13921
13922 function initLights() {
13923 var directionalLight = new THREE.DirectionalLight(16777215, .5);
13924 directionalLight.position.set(0, .5, 1);
13925 World.SCENE.add(directionalLight)
13926 }
13927
13928 function initGeometry() {
13929 _geometry = new THREE.PlaneBufferGeometry(3, 3, 1, 1)
13930 }
13931
13932 function initShader() {
13933 var displacementTexture = Utils3D.getRepeatTexture("assets/images/landscape/mountain-height.png");
13934 var normalTexture = Utils3D.getRepeatTexture("assets/images/landscape/mountain-normal.png");
13935 _shader = _this.initClass(Shader, "Parallax", "Parallax");
13936 _shader.uniforms = {
13937 fTime: {
13938 type: "f",
13939 value: 0
13940 },
13941 bumpMap: {
13942 type: "t",
13943 value: displacementTexture
13944 },
13945 map: {
13946 type: "t",
13947 value: displacementTexture
13948 },
13949 parallaxScale: {
13950 type: "f",
13951 value: -.2
13952 },
13953 parallaxMinLayers: {
13954 type: "f",
13955 value: 20
13956 },
13957 parallaxMaxLayers: {
13958 type: "f",
13959 value: 30
13960 },
13961 normalMap: {
13962 type: "t",
13963 value: normalTexture
13964 },
13965 normalScale: {
13966 type: "v2",
13967 value: new THREE.Vector2(.1, 1)
13968 }
13969 };
13970 _shader.material.side = THREE.DoubleSide
13971 }
13972
13973 function initMesh() {
13974 _mesh = new THREE.Mesh(_geometry, _shader.material);
13975 _mesh.rotation.x = -Math.PI / 2;
13976 World.SCENE.add(_mesh)
13977 }
13978
13979 function loop(t, dt) {
13980 _shader.set("fTime", dt * .001)
13981 }
13982});
13983Class(function PlaygroundLoader() {
13984 Inherit(this, Component);
13985 var _this = this;
13986 var _geometry, _shader, _mesh;
13987 this.group = new THREE.Group;
13988 (function() {
13989 initLights();
13990 initGeometry();
13991 initShader();
13992 initMesh();
13993 Render.start(loop)
13994 }());
13995
13996 function initLights() {
13997 var directionalLight = new THREE.DirectionalLight(16777215, .5);
13998 directionalLight.position.set(0, .5, 1);
13999 World.SCENE.add(directionalLight)
14000 }
14001
14002 function initGeometry() {
14003 _geometry = new THREE.SphereGeometry(1, 80, 40, Math.PI / 4, Math.PI / 2, Math.PI / 2, Math.PI / 4);
14004 World.SCENE.add(new THREE.Mesh(new THREE.SphereGeometry(1, 40, 20), new THREE.MeshBasicMaterial({
14005 color: "#000"
14006 })))
14007 }
14008
14009 function initShader() {
14010 var displacementTexture = Utils3D.getTexture("assets/images/landscape/mountain-height.jpg");
14011 var normalTexture = Utils3D.getTexture("assets/images/landscape/mountain-normal.jpg");
14012 displacementTexture.wrapS = displacementTexture.wrapT = THREE.RepeatWrapping;
14013 normalTexture.wrapS = normalTexture.wrapT = THREE.RepeatWrapping;
14014 _shader = _this.initClass(Shader, "Parallax", "Parallax");
14015 _shader.uniforms = {
14016 fTime: {
14017 type: "f",
14018 value: 0
14019 },
14020 bumpMap: {
14021 type: "t",
14022 value: displacementTexture
14023 },
14024 map: {
14025 type: "t",
14026 value: displacementTexture
14027 },
14028 parallaxScale: {
14029 type: "f",
14030 value: 0
14031 },
14032 parallaxMinLayers: {
14033 type: "f",
14034 value: 20
14035 },
14036 parallaxMaxLayers: {
14037 type: "f",
14038 value: 30
14039 },
14040 normalMap: {
14041 type: "t",
14042 value: normalTexture
14043 },
14044 normalScale: {
14045 type: "v2",
14046 value: new THREE.Vector2(.1, 1)
14047 }
14048 };
14049 _shader.material.side = THREE.DoubleSide
14050 }
14051
14052 function initMesh() {
14053 var s = .6;
14054 _mesh = new THREE.Mesh(_geometry, _shader.material);
14055 _mesh.rotation.z = Math.PI;
14056 _mesh.rotation.x = -Math.PI / 4 * s;
14057 _this.group.add(_mesh)
14058 }
14059
14060 function loop(t, dt) {
14061 _shader.set("fTime", dt * .001)
14062 }
14063});
14064Class(function PlaygroundNoise() {
14065 Inherit(this, Component);
14066 var _this = this;
14067 var _geometry, _shader, _mesh;
14068 this.group = new THREE.Group;
14069 (function() {
14070 initGeometry();
14071 initShader();
14072 initMesh();
14073 Render.start(loop)
14074 }());
14075
14076 function initGeometry() {
14077 _geometry = new THREE.PlaneBufferGeometry(3, 3, 10, 10)
14078 }
14079
14080 function initShader() {
14081 _shader = _this.initClass(Shader, "Noise", "Noise");
14082 _shader.uniforms = {
14083 fTime: {
14084 type: "f",
14085 value: 0
14086 }
14087 };
14088 _shader.material.side = THREE.DoubleSide
14089 }
14090
14091 function initMesh() {
14092 _mesh = new THREE.Mesh(_geometry, _shader.material);
14093 World.SCENE.add(_mesh)
14094 }
14095
14096 function loop(t, dt) {
14097 _shader.set("fTime", dt * .001)
14098 }
14099});
14100Class(function PlaygroundSDFLines() {
14101 Inherit(this, Component);
14102 var _this = this;
14103 this.group = new THREE.Group;
14104 (function() {
14105 initLines()
14106 }());
14107
14108 function initLines() {
14109 BackgroundLines.instance()
14110 }
14111});
14112Class(function PlaygroundScroll() {
14113 Inherit(this, Component);
14114 var _this = this;
14115 var _lines, _scrollTimer;
14116 var _conversion = 1 / 170;
14117 var _spread = 5;
14118 var _active = 0;
14119 var _time = 0;
14120 var _lastDelta = 0;
14121 var _speedLimit = .5;
14122 var _innerStep = 1;
14123 var _outerStep = 5;
14124 var _sectionsData = [
14125 ["news", 2],
14126 ["schedule", 1],
14127 ["gallery", 4],
14128 ["downloads", 2]
14129 ];
14130 var _sections = [];
14131 var _num = 0;
14132 var _meshes = [];
14133 this.group = new THREE.Group;
14134 this.isParked = true;
14135 (function() {
14136 initLines();
14137 initSections();
14138 initTimeline();
14139 initScroll();
14140 addHandlers();
14141 _this.startRender(loop)
14142 }());
14143
14144 function initLines() {
14145 _lines = _this.initClass(BackgroundLines)
14146 }
14147
14148 function initSections() {
14149 var position = 0;
14150 _sectionsData.forEach(section => {
14151 for (var i = 0; i < section[1]; i++) {
14152 _num++;
14153 var mesh = new THREE.Mesh(new THREE.PlaneBufferGeometry(.4, .25, .01), new THREE.MeshBasicMaterial);
14154 mesh.position.z = position;
14155 position -= _innerStep;
14156 _this.group.add(mesh);
14157 _sections.push(mesh)
14158 }
14159 position += _innerStep;
14160 position -= _outerStep
14161 });
14162 World.SCENE.add(_this.group);
14163 World.CONTROLS.enableZoom = false;
14164 if (Device.mobile) World.CONTROLS.enabled = false
14165 }
14166
14167 function initContent() {
14168 for (var i = 0; i < _num; i++) {
14169 var mesh = new THREE.Mesh(new THREE.PlaneBufferGeometry(.4, .25, 5, 5), new THREE.MeshBasicMaterial({
14170 wireframe: false
14171 }));
14172 mesh.position.z = i * -_spread;
14173 _meshes.push(mesh)
14174 }
14175 }
14176
14177 function initTimeline() {
14178 _time = 0
14179 }
14180
14181 function initScroll() {
14182 _this.group.target = new THREE.Vector3
14183 }
14184
14185 function loop() {
14186 if (_time < 0) {
14187 _time += (0 - _time) * .15
14188 }
14189 if (_time > _num - 1) {
14190 _time += (_num - 1 - _time) * .15
14191 }
14192 var closest = Math.round(_time);
14193 _time += (closest - _time) * (_active == closest ? .02 : .1) * (_this.isScrolling ? .5 : 1);
14194 if (Math.abs(_this.group.position.z - _this.group.target.z) < .01) _active = closest;
14195 var lower = Math.max(0, Math.min(_num - 1, Math.floor(_time)));
14196 var upper = Math.max(0, Math.min(_num - 1, Math.ceil(_time)));
14197 var perc = _time - lower;
14198 _this.group.target.z = perc * _sections[upper].position.z + (1 - perc) * _sections[lower].position.z;
14199 _this.group.target.z *= -1;
14200 _this.group.position.lerp(_this.group.target, .2);
14201 _lines.update(_this.group.position.z / _spread);
14202 var speed = Math.abs(_this.group.target.z - _this.group.position.z);
14203 if (speed < _speedLimit && !_this.isParked && Math.round(_time) >= 0 && Math.round(_time) <= _num - 1) {
14204 _this.isParked = true;
14205 movementEnd()
14206 } else if (speed > _speedLimit && _this.isParked) {
14207 _this.isParked = false;
14208 movementStart()
14209 }
14210 }
14211
14212 function addHandlers() {
14213 ScrollUtil.link(onScroll)
14214 }
14215
14216 function onScroll(e) {
14217 var delta = typeof e.y == "number" ? e.y : e;
14218 var isGreater = Math.abs(delta) > Math.abs(_lastDelta);
14219 _lastDelta = delta;
14220 if (!isGreater && Math.abs(delta) < 50) return;
14221 _time -= delta * _conversion;
14222 _this.isScrolling = true;
14223 if (_scrollTimer) clearTimeout(_scrollTimer);
14224 _scrollTimer = _this.delayedCall(scrollEnd, 100)
14225 }
14226
14227 function scrollEnd() {
14228 _this.isScrolling = false
14229 }
14230
14231 function movementStart() {}
14232
14233 function movementEnd() {}
14234});
14235Class(function PlaygroundSection() {
14236 Inherit(this, Component);
14237 var _this = this;
14238 this.group = new THREE.Group;
14239 (function() {
14240 Data.onReady().then(() => {
14241 initSection()
14242 })
14243 }());
14244
14245 function initSection() {
14246 var view = Utils.query("section");
14247 var section = _this.initClass(window[view]);
14248 section.activate();
14249 World.SCENE.add(section.group)
14250 }
14251
14252 function initLines() {
14253 _this.initClass(BackgroundLines)
14254 }
14255});
14256Class(function PlaygroundSphere() {
14257 Inherit(this, Component);
14258 var _this = this;
14259 var _geometry, _shader, _mesh;
14260 this.group = new THREE.Group;
14261 (function() {
14262 initGeometry();
14263 initShader();
14264 initMesh();
14265 _this.startRender(loop)
14266 }());
14267
14268 function initGeometry() {
14269 _geometry = new THREE.SphereBufferGeometry(.5, 40, 20)
14270 }
14271
14272 function initShader() {
14273 _shader = _this.initClass(Shader, "RingtoneSphere", "RingtoneSphere");
14274 _shader.uniforms = {
14275 fTime: {
14276 type: "f",
14277 value: 0
14278 }
14279 };
14280 _shader.material.side = THREE.DoubleSide
14281 }
14282
14283 function initMesh() {
14284 _mesh = new THREE.Mesh(_geometry, _shader.material);
14285 _this.group.add(_mesh)
14286 }
14287
14288 function loop(t, dt) {
14289 _mesh.rotation.y += .02;
14290 _shader.set("fTime", dt * .001)
14291 }
14292});
14293Class(function PlaygroundTimeline() {
14294 Inherit(this, Component);
14295 var _this = this;
14296 var _innerStep = 2;
14297 var _outerStep = 10;
14298 var _sections = [
14299 ["news", 2],
14300 ["schedule", 1],
14301 ["gallery", 4],
14302 ["downloads", 2]
14303 ];
14304 var _num = 0;
14305 var _current = 0;
14306 this.group = new THREE.Group;
14307 (function() {
14308 initSections();
14309 initTimeline()
14310 }());
14311
14312 function initSections() {
14313 _sections.forEach(section => {
14314 for (var i = 0; i < section[1]; i++) {
14315 var mesh = new THREE.Mesh(new THREE.BoxGeometry(.4, .2, .01), new THREE.MeshNormalMaterial);
14316 mesh.position.z = _num * -2;
14317 _this.group.add(mesh);
14318 _num++
14319 }
14320 });
14321 console.log(_num)
14322 }
14323
14324 function initTimeline() {}
14325});
14326Class(function PlaygroundTitles() {
14327 Inherit(this, Component);
14328 var _this = this;
14329 this.group = new THREE.Group;
14330 (function() {
14331 initLines();
14332 initTitle()
14333 }());
14334
14335 function initLines() {
14336 BackgroundLines.instance()
14337 }
14338
14339 function initTitle() {
14340 var title = _this.initClass(Title);
14341 _this.group.add(title.group)
14342 }
14343});
14344Class(function PlaygroundUISphere() {
14345 Inherit(this, Component);
14346 var _this = this;
14347 this.group = new THREE.Group;
14348 (function() {
14349 initGlobe()
14350 }());
14351
14352 function initGlobe() {
14353 var globe = _this.initClass(UISphere);
14354 _this.group.add(globe.group)
14355 }
14356});
14357Class(function PlaygroundVideos() {
14358 Inherit(this, Component);
14359 var _this = this;
14360 var _data, _geometry, _texture, _video, _shader, _mesh;
14361 var _type = ["tumblr"];
14362 var _index = 0;
14363 var _size = new THREE.Vector3(.5, .3, .01);
14364 this.group = new THREE.Group;
14365 (function() {
14366 Data.onReady().then(() => {
14367 _data = Data.getTumblr()[8];
14368 init()
14369 })
14370 }());
14371
14372 function init() {
14373 initGeometry();
14374 initTexture();
14375 initShader();
14376 initMesh();
14377 activate()
14378 }
14379
14380 function initGeometry() {
14381 _geometry = new THREE.PlaneBufferGeometry(_size.x, _size.y, 10, 10)
14382 }
14383
14384 function initTexture() {
14385 initVideoTexture(_data.video_mp4);
14386 console.log(_data.video_mp4)
14387 }
14388
14389 function initVideoTexture(src) {
14390 _video = _this.initClass(Video, {
14391 width: 400,
14392 height: 300,
14393 src: src,
14394 loop: true,
14395 preload: true
14396 });
14397 _video.mute();
14398 var mobileTouchStart = () => {
14399 _video.play();
14400 _this.delayedCall(() => {
14401 if (!_this.isActive) _video.pause()
14402 }, 100);
14403 defer(() => {
14404 __window.unbind("touchstart", mobileTouchStart)
14405 })
14406 };
14407 if (Device.mobile && !Tests.isLessThanIOS10()) __window.bind("touchstart", mobileTouchStart);
14408 _video.div.crossOrigin = "anonymous";
14409 _texture = new THREE.Texture(_video.div);
14410 _texture.minFilter = THREE.LinearFilter;
14411 _texture.magFilter = THREE.LinearFilter
14412 }
14413
14414 function updateVideoTexture() {
14415 _texture.needsUpdate = true
14416 }
14417
14418 function initShader() {
14419 var pattern1 = Utils3D.getRepeatTexture("assets/images/common/pattern1.jpg");
14420 var pattern2 = Utils3D.getRepeatTexture("assets/images/common/pattern2.jpg");
14421 var noise = Utils3D.getRepeatTexture("assets/images/common/noise.jpg");
14422 var sprite = Utils3D.getTexture("assets/images/vfx/titles-sprite.jpg");
14423 _shader = Card.getShader();
14424 _shader.uniforms.tMap.value = _texture;
14425 _shader.uniforms.tPattern1.value = pattern1;
14426 _shader.uniforms.tPattern2.value = pattern2;
14427 _shader.uniforms.tNoise.value = noise;
14428 _shader.uniforms.tSprite.value = sprite;
14429 _shader.uniforms.uSize.value = _size;
14430 _shader.uniforms.fIndex.value = _index;
14431 var tintIndex = _type[0] == "news" ? 0 : _type[0] == "tumblr" ? 2 : 3;
14432 var cursorOffset = _type[0] == "downloads" ? .8 : _type[0] == "news" && _type[1] == "video" ? .4 : .6;
14433 var typeValue = _type[0] == "downloads" ? 2 : _type[0] == "news" && _type[1] == "video" ? 1 : 0;
14434 _shader.uniforms.fType.value = typeValue;
14435 _shader.uniforms.uTint.value = new THREE.Color(Config.GRADIENT[tintIndex]);
14436 _shader.uniforms.fCursor.value = cursorOffset
14437 }
14438
14439 function initMesh() {
14440 _mesh = new THREE.Mesh(_geometry, _shader.material);
14441 _mesh.frustumCulled = false;
14442 _this.group.add(_mesh);
14443 _this.mesh = _mesh;
14444 _this.group.rotation.reorder("YXZ")
14445 }
14446
14447 function activate() {
14448 _this.isActive = true;
14449 if (_video) {
14450 _video.play();
14451 _this.startRender(updateVideoTexture)
14452 }
14453 _shader.tween("fFade1", 1, 500, "easeOutSine");
14454 _shader.tween("fFade2", 1, 500, "easeOutSine", 250)
14455 }
14456});
14457Class(function Caption(_data, _type) {
14458 Inherit(this, Component);
14459 var _this = this;
14460 var _text, _shader, _mesh;
14461 var _text2, _shader2, _mesh2;
14462 this.group = new THREE.Group;
14463 var _alpha = Mobile.phone ? 1.4 : Device.mobile ? 1 : .55;
14464 (function() {
14465 initMesh();
14466 _this.startRender(loop)
14467 }());
14468
14469 function initMesh() {
14470 var text = _data.title || _data.caption;
14471 if (_data.caption) {
14472 text = text.replace("<p>", "");
14473 text = text.replace("</p>", "")
14474 }
14475 text = text.toUpperCase();
14476 text = text.replace("‘", "'");
14477 text = text.replace("’", "'");
14478 _text = _this.initClass(WebGLText, {
14479 font: "gotham-light",
14480 image: "assets/images/fonts/gotham-light.png",
14481 vs: "Caption",
14482 fs: "Caption",
14483 text: text,
14484 width: 15e2,
14485 align: "center",
14486 verticalAlign: "top",
14487 letterSpacing: 5,
14488 lineHeight: 78,
14489 color: Config.GRADIENT[_data.group_index],
14490 opacity: 1
14491 });
14492 var s = Mobile.phone ? .00037 : .00033;
14493 _text.mesh.scale.set(s * .94, s, s);
14494 _text.mesh.position.set(0, -.175, 0);
14495 _text.mesh.rotation.y = Math.PI;
14496 _shader = _text.shader;
14497 _shader.set("opacity", 0);
14498 _shader.uniforms.fHover = {
14499 type: "f",
14500 value: 1
14501 };
14502 _shader.uniforms.fTime = {
14503 type: "f",
14504 value: 0
14505 };
14506 _shader.uniforms.fBold = {
14507 type: "f",
14508 value: 0
14509 };
14510 _shader.uniforms.fTransition = {
14511 type: "f",
14512 value: 0
14513 };
14514 _shader.uniforms.tNoise = {
14515 type: "t",
14516 value: Utils3D.getRepeatTexture("assets/images/common/noise.jpg")
14517 };
14518 _shader.material.blending = THREE.AdditiveBlending;
14519 _mesh = _text.mesh;
14520 _mesh.frustumCulled = false;
14521 _this.group.add(_mesh);
14522 FX.BlurMask.instance().add(_mesh);
14523 defer(() => {
14524 _this.group.visible = false
14525 });
14526 if (_data.text) {
14527 text = _data.text;
14528 text = text.toUpperCase();
14529 text = text.replace("‘", "'");
14530 text = text.replace("’", "'");
14531 _text2 = _this.initClass(WebGLText, {
14532 font: "gotham-light",
14533 image: "assets/images/fonts/gotham-light.png",
14534 vs: "Caption",
14535 fs: "Caption",
14536 text: text,
14537 width: 15e2,
14538 align: "center",
14539 verticalAlign: "top",
14540 letterSpacing: 7,
14541 lineHeight: 78,
14542 color: "#efffef",
14543 opacity: 1
14544 });
14545 _text2.mesh.position.set(0, -.189 - _text.height * s, 0);
14546 s = Mobile.phone ? .0003 : .00025;
14547 _text2.mesh.scale.set(s * .94, s, s);
14548 _text2.mesh.rotation.y = Math.PI;
14549 _shader2 = _text2.shader;
14550 _shader2.set("opacity", 0);
14551 _shader2.uniforms.fHover = {
14552 type: "f",
14553 value: 1
14554 };
14555 _shader2.uniforms.fTime = {
14556 type: "f",
14557 value: 0
14558 };
14559 _shader2.uniforms.fBold = {
14560 type: "f",
14561 value: 1
14562 };
14563 _shader2.uniforms.fTransition = {
14564 type: "f",
14565 value: 0
14566 };
14567 _shader2.uniforms.tNoise = {
14568 type: "t",
14569 value: Utils3D.getRepeatTexture("assets/images/common/noise.jpg")
14570 };
14571 _shader2.material.blending = THREE.AdditiveBlending;
14572 _mesh2 = _text2.mesh;
14573 _mesh2.frustumCulled = false;
14574 _this.group.add(_mesh2);
14575 FX.BlurMask.instance().add(_mesh2)
14576 }
14577 }
14578
14579 function loop(t, dt) {
14580 _shader.set("fTime", dt * .001);
14581 if (_shader2) _shader2.set("fTime", dt * .001)
14582 }
14583 this.animateIn = () => {
14584 _this.group.visible = true;
14585 _shader.tween("opacity", 1, 500, "easeOutSine");
14586 _shader.tween("fTransition", _alpha, 1e3, "easeInSine", 300);
14587 if (!_shader2) return;
14588 _shader2.tween("opacity", 1, 500, "easeOutSine");
14589 _shader2.tween("fTransition", _alpha, 1e3, "easeInSine", 300)
14590 };
14591 this.animateOut = () => {
14592 _shader.tween("fTransition", 0, 300, "easeOutSine");
14593 _shader.tween("opacity", 0, 300, "easeOutSine", 200, () => _this.group.visible = false);
14594 if (!_shader2) return;
14595 _shader2.tween("fTransition", 0, 300, "easeOutSine");
14596 _shader2.tween("opacity", 0, 300, "easeOutSine", 200)
14597 };
14598 this.hoverIn = () => {
14599 _shader.tween("opacity", 1, 200, "easeOutSine");
14600 _shader.tween("fTransition", 1.5, 500, "easeOutSine");
14601 if (_shader2) _shader2.tween("opacity", 1, 200, "easeOutSine");
14602 if (_shader2) _shader2.tween("fTransition", 1.5, 500, "easeOutSine");
14603 TweenManager.tween(_this.group.position, {
14604 y: 0,
14605 z: .015
14606 }, 500, "easeOutBack")
14607 };
14608 this.hoverOut = () => {
14609 _shader.tween("opacity", 1, 500, "easeOutSine");
14610 _shader.tween("fTransition", _alpha, 500, "easeOutSine");
14611 if (_shader2) _shader2.tween("opacity", 1, 500, "easeOutSine");
14612 if (_shader2) _shader2.tween("fTransition", _alpha, 500, "easeOutSine");
14613 TweenManager.tween(_this.group.position, {
14614 y: 0,
14615 z: 0
14616 }, 500, "easeOutBack")
14617 }
14618});
14619Class(function Card(_data, _scale, _index) {
14620 Inherit(this, Component);
14621 var _this = this;
14622 var _geometry, _texture, _shader, _mesh, _backShader, _backMesh, _caption, _video, _maskMaterial;
14623 var _type = [];
14624 var _size = new THREE.Vector3(.5 * _scale, .3 * _scale, .01);
14625 var _anim = new DynamicObject({
14626 cardEase: .1
14627 });
14628 var _targetBackColor = new THREE.Color(Config.BG_COLORS[0][3]);
14629 this.group = new THREE.Group;
14630 (function() {
14631 initType();
14632 initGeometry();
14633 initTexture();
14634 initShader();
14635 initBackplate();
14636 initMesh();
14637 initMask();
14638 initCaption();
14639 _this.startRender(loop);
14640 addHandlers();
14641 resize()
14642 }());
14643
14644 function initType() {
14645 if (_data.media) {
14646 _type[0] = "tumblr"
14647 } else if (_data.thumbnail) {
14648 _type[0] = "downloads"
14649 } else {
14650 _type[0] = "news";
14651 _type[1] = _data.type == "image" ? "link" : "video"
14652 }
14653 }
14654
14655 function initGeometry() {
14656 _geometry = new THREE.PlaneBufferGeometry(_size.x, _size.y, 10, 10)
14657 }
14658
14659 function initTexture() {
14660 if (_type[0] == "tumblr") {
14661 if (Tests.isLessThanIOS10() || Mobile.browser == "Social" || Tests.preventVideo()) {
14662 _texture = Utils3D.getTexture(_data.image_jpg);
14663 return
14664 }
14665 initVideoTexture(Tests.isWebm() ? _data.video_webm : _data.video_mp4)
14666 } else if (_type[0] == "news") {
14667 if (_data.snippet_mp4 && !Tests.isLessThanIOS10() && Mobile.browser !== "Social" && !Tests.preventVideo()) {
14668 initVideoTexture(Tests.isWebm() ? _data.snippet_webm : _data.snippet_mp4);
14669 return
14670 }
14671 _texture = Utils3D.getTexture(_data.image)
14672 } else if (_type[0] == "downloads") {
14673 _texture = Utils3D.getTexture(_data.thumbnail)
14674 }
14675 }
14676
14677 function initVideoTexture(src) {
14678 _video = _this.initClass(Video, {
14679 width: 400,
14680 height: 300,
14681 src: src,
14682 loop: true,
14683 preload: true
14684 });
14685 _video.mute();
14686 var mobileTouchStart = () => {
14687 _video.play();
14688 _this.delayedCall(() => {
14689 if (!_this.isActive) _video.pause()
14690 }, 100);
14691 defer(() => {
14692 __window.unbind("touchstart", mobileTouchStart)
14693 })
14694 };
14695 if (Device.mobile && !Tests.isLessThanIOS10()) __window.bind("touchstart", mobileTouchStart);
14696 _video.div.crossOrigin = "anonymous";
14697 _texture = new THREE.Texture(_video.div);
14698 _texture.minFilter = THREE.LinearFilter;
14699 _texture.magFilter = THREE.LinearFilter
14700 }
14701
14702 function updateVideoTexture() {
14703 _texture.needsUpdate = true
14704 }
14705
14706 function initShader() {
14707 var pattern1 = Utils3D.getRepeatTexture("assets/images/common/pattern1.jpg");
14708 var pattern2 = Utils3D.getRepeatTexture("assets/images/common/pattern3.jpg");
14709 var noise = Utils3D.getRepeatTexture("assets/images/common/noise.jpg");
14710 var sprite = Utils3D.getTexture("assets/images/vfx/titles-sprite.jpg");
14711 _shader = Card.getShader();
14712 _shader.uniforms.tMap.value = _texture;
14713 _shader.uniforms.tPattern1.value = pattern1;
14714 _shader.uniforms.tPattern2.value = pattern2;
14715 _shader.uniforms.tNoise.value = noise;
14716 _shader.uniforms.tSprite.value = sprite;
14717 _shader.uniforms.uSize.value = _size;
14718 _shader.uniforms.fIndex.value = _index;
14719 var tintIndex = _type[0] == "news" ? 0 : _type[0] == "tumblr" ? 2 : 3;
14720 var cursorOffset = _type[0] == "downloads" ? .8 : _type[0] == "news" && _type[1] == "video" ? .4 : .6;
14721 var typeValue = _type[0] == "downloads" ? 2 : _type[0] == "news" && _type[1] == "video" ? 1 : 0;
14722 _shader.uniforms.fType.value = typeValue;
14723 _shader.uniforms.uTint.value = new THREE.Color(Config.GRADIENT[tintIndex]);
14724 _shader.uniforms.fCursor.value = cursorOffset;
14725 _shader.material.transparent = true;
14726 _shader.material.blending = THREE.AdditiveBlending;
14727 _shader.material.depthTest = false
14728 }
14729
14730 function initBackplate() {
14731 var noise = Utils3D.getRepeatTexture("assets/images/common/noise.jpg");
14732 _backShader = Card.getBackShader();
14733 _backShader.uniforms.tNoise.value = noise;
14734 _backShader.uniforms.uSize.value = _size;
14735 _backShader.uniforms.fIndex.value = _index;
14736 _backShader.uniforms.uColor.value = new THREE.Color(Config.BG_COLORS[0][3]);
14737 _backShader.material.transparent = true;
14738 _backMesh = new THREE.Mesh(_geometry, _backShader.material);
14739 _this.group.add(_backMesh)
14740 }
14741
14742 function initMesh() {
14743 _mesh = new THREE.Mesh(_geometry, _shader.material);
14744 _mesh.frustumCulled = false;
14745 _this.group.add(_mesh);
14746 _this.mesh = _mesh;
14747 _this.group.rotation.reorder("YXZ");
14748 let y = .7 * 2 * (_index === 0 ? 1 : -1);
14749 _this.group.rotation.y = y;
14750 let x = .8 * (_index === 0 ? -1 : 1);
14751 _this.group.position.x = x
14752 }
14753
14754 function initMask() {
14755 _maskMaterial = new THREE.MeshBasicMaterial({
14756 color: new THREE.Color(1, 0, 0)
14757 });
14758 FX.BlurMask.instance().add(_mesh, _maskMaterial)
14759 }
14760
14761 function initCaption() {
14762 if (_type[0] == "downloads" && Tests.isPermanentPrompts()) return;
14763 if (_type[0] == "downloads") {
14764 _caption = _this.initClass(DownloadCaptions, _data)
14765 } else {
14766 _caption = _this.initClass(Caption, _data, _type)
14767 }
14768 _this.group.add(_caption.group)
14769 }
14770
14771 function loop(t, dt) {
14772 _shader.set("fTime", dt * .001);
14773 _backShader.set("fTime", dt * .001);
14774 updateColors()
14775 }
14776
14777 function updateColors() {
14778 if (_targetBackColor.current !== Config.CLOSEST_SECTION) {
14779 _targetBackColor.current = Config.CLOSEST_SECTION;
14780 _targetBackColor.set(Config.BG_COLORS[Config.CLOSEST_SECTION][3])
14781 }
14782 _backShader.uniforms.uColor.value.lerp(_targetBackColor, .01)
14783 }
14784
14785 function addHandlers() {
14786 _this.events.subscribe(HydraEvents.RESIZE, resize);
14787 _this.events.subscribe(ToonamiEvents.LIGHTBOX_OPEN, toLightbox);
14788 _this.events.subscribe(ToonamiEvents.LIGHTBOX_CLOSE, fromLightbox)
14789 }
14790
14791 function resize() {
14792 var portrait = Device.mobile && Stage.width < Stage.height;
14793 if (portrait) {
14794 _this.group.position.set(0, _this.group.position.y, 0);
14795 _this.group.rotation.set(_this.group.rotation.x, 0, 0)
14796 } else {
14797 _this.group.position.set(_this.group.position.x, .02, 0);
14798 _this.group.rotation.set(-.15, _this.group.rotation.y, _index === 0 ? -.08 : .08)
14799 }
14800 }
14801
14802 function toLightbox() {
14803 if (!_this.isActive) return;
14804 if (_caption) _caption.animateOut();
14805 TweenManager.tween(_maskMaterial.color, {
14806 r: 1
14807 }, 700, "easeInOutCubic");
14808 _shader.tween("fFade1", 0, 1e3, "easeOutSine");
14809 _shader.tween("fFade2", 0, 1e3, "easeOutSine");
14810 _backShader.tween("fFade1", 0, 1e3, "easeOutSine");
14811 _backShader.tween("fFade2", 0, 1e3, "easeOutSine")
14812 }
14813
14814 function fromLightbox() {
14815 if (!_this.isActive) return;
14816 if (_caption) _caption.animateIn();
14817 TweenManager.tween(_maskMaterial.color, {
14818 r: 0
14819 }, 700, "easeInOutCubic");
14820 _shader.tween("fFade1", 1, 500, "easeOutSine");
14821 _shader.tween("fFade2", 1, 500, "easeOutSine", 250);
14822 _backShader.tween("fFade1", 1, 500, "easeOutSine");
14823 _backShader.tween("fFade2", 1, 500, "easeOutSine", 250)
14824 }
14825
14826 function click() {
14827 if (!_this.isHover || Global.LIGHTBOX_OPEN) return;
14828 if (!_this.isHover) return;
14829 if (Mouse.x > Stage.width - 100) return;
14830 if (_type[0] == "tumblr") {
14831 getURL(_data.url, "_blank")
14832 } else if (_type[0] == "news" && _type[1] == "link") {
14833 getURL(_data.link, "_blank")
14834 } else if (_type[0] == "news" && _type[1] == "video") {
14835 _this.events.fire(ToonamiEvents.LIGHTBOX_OPEN, {
14836 src: _data.source_mp4,
14837 title: _data.title,
14838 text: _data.text
14839 });
14840 _this.isHover = false;
14841 if (Tests.isPermanentPrompts()) return;
14842 _shader.tween("fHover", 0, 100, "easeOutSine");
14843 _shader.tween("fHover2", 0, 500, "easeInOutCubic");
14844 _backShader.tween("fHover", 0, 100, "easeOutSine");
14845 _backShader.tween("fHover2", 0, 500, "easeInOutCubic")
14846 } else if (_type[0] == "downloads") {
14847 if (Tests.isPermanentPrompts()) {
14848 var imageURL = _data.mobile_large;
14849 getURL(imageURL, "_blank");
14850 return
14851 }
14852 if (_caption) _caption.click()
14853 }
14854 }
14855
14856 function focusHandler(e) {
14857 if (e.type == "blur") return
14858 }
14859 this.updateMouse = uv => {
14860 if (Tests.isPermanentPrompts()) {
14861 _shader.uniforms.vMouse.value.set(.5, .5);
14862 _shader.set("fHover", 1);
14863 _shader.set("fHover2", 1);
14864 _backShader.set("fHover", 1);
14865 _backShader.set("fHover2", 1)
14866 } else if (uv) {
14867 _shader.uniforms.vMouse.value.copy(uv);
14868 _backShader.uniforms.vMouse.value.copy(uv)
14869 }
14870 if (!uv && _this.isHover && !Global.LIGHTBOX_OPEN) {
14871 _this.isHover = false;
14872 if (Tests.isPermanentPrompts()) return;
14873 _shader.tween("fHover", 0, 100, "easeOutSine");
14874 _shader.tween("fHover2", 0, 500, "easeInOutCubic");
14875 _backShader.tween("fHover", 0, 100, "easeOutSine");
14876 _backShader.tween("fHover2", 0, 500, "easeInOutCubic");
14877 if (_caption) _caption.hoverOut();
14878 return
14879 }
14880 if (uv && !_this.isHover && !Global.LIGHTBOX_OPEN) {
14881 _this.isHover = true;
14882 if (Tests.isPermanentPrompts()) return;
14883 _shader.tween("fHover", 1, 500, "easeOutElastic");
14884 _shader.tween("fHover2", 1, 500, "easeInOutCubic");
14885 _backShader.tween("fHover", 1, 500, "easeOutElastic");
14886 _backShader.tween("fHover2", 1, 500, "easeInOutCubic");
14887 if (_caption) _caption.hoverIn()
14888 }
14889 if (_type[0] == "downloads" && _this.isHover && uv && _caption) _caption.hoverX = uv.x
14890 };
14891 this.activate = () => {
14892 _this.isActive = true;
14893 if (_caption) _caption.animateIn();
14894 if (_video && !Tests.isLessThanIOS10()) {
14895 _video.play();
14896 _this.startRender(updateVideoTexture)
14897 }
14898 _shader.tween("fFade1", 1, 500, "easeOutSine");
14899 _shader.tween("fFade2", 1, 500, "easeOutSine", 250);
14900 _backShader.tween("fFade1", 1, 500, "easeOutSine");
14901 _backShader.tween("fFade2", 1, 500, "easeOutSine", 250);
14902 TweenManager.tween(_maskMaterial.color, {
14903 r: 0
14904 }, 700, "easeInOutSine");
14905 _this.events.subscribe(World.CLICK, click)
14906 };
14907 this.deactivate = () => {
14908 _this.isActive = false;
14909 if (_caption) _caption.animateOut();
14910 if (_video && !Tests.isLessThanIOS10()) {
14911 _video.pause();
14912 _this.stopRender(updateVideoTexture)
14913 }
14914 _shader.tween("fFade1", 0, 300, "easeInOutSine");
14915 _shader.tween("fFade2", 0, 300, "easeInOutSine");
14916 _backShader.tween("fFade1", 0, 300, "easeInOutSine");
14917 _backShader.tween("fFade2", 0, 300, "easeInOutSine");
14918 TweenManager.tween(_maskMaterial.color, {
14919 r: 1
14920 }, 300, "easeInOutSine");
14921 _this.events.unsubscribe(World.CLICK, click)
14922 };
14923 this.sectionActivate = () => {};
14924 this.sectionDeactivate = () => {};
14925 this.updatePosition = d => {
14926 var distance = Math.abs(d);
14927 var portrait = Device.mobile && Stage.width < Stage.height;
14928 if (portrait) {
14929 let x = Utils.range(distance, .2, 1, .2, d < 0 ? 1.4 : 1.4, true) * (_index === 0 ? 1 : -1);
14930 _this.group.rotation.x += (x - _this.group.rotation.x) * _anim.cardEase;
14931 let y = Utils.range(distance, .2, 1, .215, d < 0 ? .7 : .7, true) * (_index === 0 ? 1 : -1) - .035;
14932 _this.group.position.y += (y - _this.group.position.y) * _anim.cardEase
14933 } else {
14934 let y = Utils.range(distance, .2, 1, .25 * 2, (d < 0 ? .7 : .5) * 2, true) * (_index === 0 ? 1 : -1);
14935 _this.group.rotation.y += (y - _this.group.rotation.y) * _anim.cardEase;
14936 let x = Utils.range(distance, .2, 1, .28, d < 0 ? .8 : .35, true) * (_index === 0 ? -1 : 1);
14937 _this.group.position.x += (x - _this.group.position.x) * _anim.cardEase
14938 }
14939 };
14940 this.introSetup = () => {
14941 _anim.cardEase = .03
14942 };
14943 this.introEnd = () => {
14944 _anim.tween({
14945 cardEase: .1
14946 }, 1e3, "easeInOutCubic")
14947 }
14948}, function() {
14949 var _shader, _backShader;
14950 Card.getShader = () => {
14951 if (_shader) return _shader.clone();
14952 _shader = new Shader("Card", "Card");
14953 _shader.uniforms = {
14954 tMap: {
14955 type: "t",
14956 value: null
14957 },
14958 tPattern1: {
14959 type: "t",
14960 value: null
14961 },
14962 tPattern2: {
14963 type: "t",
14964 value: null
14965 },
14966 tNoise: {
14967 type: "t",
14968 value: null
14969 },
14970 tSprite: {
14971 type: "t",
14972 value: null
14973 },
14974 uSize: {
14975 type: "v3",
14976 value: null
14977 },
14978 fTime: {
14979 type: "f",
14980 value: 0
14981 },
14982 vMouse: {
14983 type: "v2",
14984 value: new THREE.Vector2
14985 },
14986 fHover: {
14987 type: "f",
14988 value: 0
14989 },
14990 fHover2: {
14991 type: "f",
14992 value: 0
14993 },
14994 fIndex: {
14995 type: "f",
14996 value: 0
14997 },
14998 fType: {
14999 type: "f",
15000 value: 0
15001 },
15002 fFade1: {
15003 type: "f",
15004 value: 0
15005 },
15006 fFade2: {
15007 type: "f",
15008 value: 0
15009 },
15010 fCursor: {
15011 type: "f",
15012 value: 0
15013 },
15014 uTint: {
15015 type: "c",
15016 value: null
15017 }
15018 };
15019 return _shader.clone()
15020 };
15021 Card.getBackShader = () => {
15022 if (_backShader) return _backShader.clone();
15023 _backShader = new Shader("Card", "CardBack");
15024 _backShader.uniforms = {
15025 tNoise: {
15026 type: "t",
15027 value: null
15028 },
15029 uSize: {
15030 type: "v3",
15031 value: null
15032 },
15033 fTime: {
15034 type: "f",
15035 value: 0
15036 },
15037 vMouse: {
15038 type: "v2",
15039 value: new THREE.Vector2
15040 },
15041 fHover: {
15042 type: "f",
15043 value: 0
15044 },
15045 fHover2: {
15046 type: "f",
15047 value: 0
15048 },
15049 fIndex: {
15050 type: "f",
15051 value: 0
15052 },
15053 fFade1: {
15054 type: "f",
15055 value: 0
15056 },
15057 fFade2: {
15058 type: "f",
15059 value: 0
15060 },
15061 uColor: {
15062 type: "c",
15063 value: null
15064 }
15065 };
15066 return _backShader.clone()
15067 }
15068});
15069Class(function Title(_data) {
15070 Inherit(this, Component);
15071 var _this = this;
15072 var _text, _shader, _mesh;
15073 this.group = new THREE.Group;
15074 var _targetColor1 = new THREE.Color(Config.LINE_COLORS[0][0]);
15075 var _targetColor2 = new THREE.Color(Config.LINE_COLORS[0][0]);
15076 (function() {
15077 initMesh();
15078 _this.startRender(loop)
15079 }());
15080
15081 function initMesh() {
15082 _text = _this.initClass(WebGLText, {
15083 font: "gotham-light",
15084 image: "assets/images/fonts/gotham-light.png",
15085 vs: "Title",
15086 fs: "Title",
15087 text: _data,
15088 width: 13e2,
15089 align: "center",
15090 verticalAlign: "top",
15091 letterSpacing: 5,
15092 lineHeight: 80,
15093 color: "#fff",
15094 opacity: 1
15095 });
15096 var s = .0017;
15097 _text.mesh.scale.set(s, s, s);
15098 _text.mesh.position.set(0, .05, -.3);
15099 _text.mesh.rotation.y = Math.PI;
15100 _text.mesh.rotation.x = -.2;
15101 _shader = _text.shader;
15102 _shader.set("opacity", 0);
15103 _shader.uniforms.fTime = {
15104 type: "f",
15105 value: 0
15106 };
15107 _shader.uniforms.fMask = {
15108 type: "f",
15109 value: 0
15110 };
15111 _shader.uniforms.fTransition = {
15112 type: "f",
15113 value: 0
15114 };
15115 _shader.uniforms.uColor1 = {
15116 type: "c",
15117 value: new THREE.Color(Config.LINE_COLORS[0][0])
15118 };
15119 _shader.uniforms.uColor2 = {
15120 type: "c",
15121 value: new THREE.Color(Config.LINE_COLORS[0][1])
15122 };
15123 _shader.material.blending = THREE.AdditiveBlending;
15124 _shader.material.depthTest = false;
15125 _mesh = _text.mesh;
15126 _mesh.frustumCulled = false;;
15127 _this.group.add(_mesh);
15128 defer(() => {
15129 _this.group.visible = false
15130 })
15131 }
15132
15133 function loop(t, dt) {
15134 _shader.set("fTime", dt * .001);
15135 updateColors()
15136 }
15137
15138 function updateColors() {
15139 if (_targetColor1.current !== Config.CLOSEST_SECTION) {
15140 _targetColor1.current = Config.CLOSEST_SECTION;
15141 _targetColor1.set(Config.GRADIENT[Config.CLOSEST_SECTION]);
15142 _targetColor2.set(Config.GRADIENT[Config.CLOSEST_SECTION])
15143 }
15144 _shader.uniforms.uColor1.value.lerp(_targetColor1, .02);
15145 _shader.uniforms.uColor2.value.lerp(_targetColor2, .02)
15146 }
15147 this.animateIn = function() {
15148 _this.group.visible = true;
15149 _shader.tween("opacity", .5, 300, "easeOutSine")
15150 };
15151 this.animateOut = function() {
15152 _shader.tween("opacity", 0, 500, "easeInSine", 100, () => {
15153 _this.group.visible = false
15154 })
15155 }
15156});
15157Class(function Titles(_sections, _group) {
15158 Inherit(this, Component);
15159 var _this = this;
15160 var _titles = [];
15161 this.group = new THREE.Group;
15162 (function() {
15163 initTitles();
15164 _this.startRender(loop)
15165 }());
15166
15167 function initTitles() {
15168 ["LATEST", "SCHEDULE", "GALLERY", "DOWNLOADS"].forEach((text, i) => {
15169 var title = _this.initClass(Title, text);
15170 _titles.push(title);
15171 title.group.position.z = _sections[i].min;
15172 _this.group.add(title.group)
15173 });
15174 World.SCENE.add(_this.group);
15175 let obj = new DynamicObject({
15176 v: 0
15177 });
15178 obj.multiTween = true;
15179 obj.tween({
15180 v: 1
15181 }, 500, "ease")
15182 }
15183
15184 function loop() {
15185 _this.group.position.lerp(_group.position, .15);
15186 _titles.forEach(title => {})
15187 }
15188 this.animateIn = () => {
15189 _titles.forEach(title => {
15190 title.animateIn()
15191 })
15192 };
15193 this.animateOut = () => {
15194 _titles.forEach(title => {
15195 title.animateOut()
15196 })
15197 }
15198});
15199Class(function DownloadCaptions(_data) {
15200 Inherit(this, Component);
15201 var _this = this;
15202 var _captions = [];
15203 var _imageURLs = [_data.large, _data.medium, _data.small];
15204 this.hoverX = 0;
15205 this.group = new THREE.Group;
15206 (function() {
15207 initCaptions();
15208 _this.startRender(loop)
15209 }());
15210
15211 function initCaptions() {
15212 var x = .14;
15213 [
15214 ["1920x1080", -x],
15215 ["1440x900", 0],
15216 ["1280x720", x]
15217 ].forEach((d, i) => {
15218 var caption = addCaption(d);
15219 _captions.push(caption)
15220 });
15221 _this.group.visible = false
15222 }
15223
15224 function addCaption(d) {
15225 var text = _this.initClass(WebGLText, {
15226 font: "gotham-light",
15227 image: "assets/images/fonts/gotham-light.png",
15228 vs: "Caption",
15229 fs: "Caption",
15230 text: d[0],
15231 width: 13e2,
15232 align: "center",
15233 verticalAlign: "top",
15234 letterSpacing: 5,
15235 lineHeight: 80,
15236 color: Config.GRADIENT[3],
15237 opacity: 1
15238 });
15239 var s = .00033;
15240 text.mesh.scale.set(s * .92, s, s);
15241 text.mesh.position.set(d[1], -.175, 0);
15242 text.mesh.rotation.y = Math.PI;
15243 var shader = text.shader;
15244 shader.set("opacity", 0);
15245 shader.uniforms.fHover = {
15246 type: "f",
15247 value: .1
15248 };
15249 shader.uniforms.fTime = {
15250 type: "f",
15251 value: 0
15252 };
15253 shader.uniforms.fBold = {
15254 type: "f",
15255 value: .5
15256 };
15257 shader.uniforms.fTransition = {
15258 type: "f",
15259 value: 0
15260 };
15261 shader.material.blending = THREE.AdditiveBlending;
15262 shader.material.depthTest = false;
15263 var mesh = text.mesh;
15264 _this.group.add(mesh);
15265 FX.BlurMask.instance().add(mesh);
15266 return text
15267 }
15268
15269 function loop(t, dt) {
15270 _captions.forEach((caption, i) => {
15271 caption.shader.set("fTime", dt * .001);
15272 let alpha = _this.isHover && Math.floor(_this.hoverX * _captions.length) === i ? 1.5 : .3;
15273 caption.shader.uniforms.fHover.value += (alpha - caption.shader.uniforms.fHover.value) * .1
15274 })
15275 }
15276 this.animateIn = () => {
15277 _this.group.visible = true;
15278 _captions.forEach(caption => {
15279 caption.shader.tween("opacity", 1, 500, "easeOutSine");
15280 caption.shader.tween("fTransition", 1, 1e3, "easeInSine", 300)
15281 })
15282 };
15283 this.animateOut = () => {
15284 _captions.forEach((caption, i) => {
15285 caption.shader.tween("fTransition", 0, 300, "easeOutSine");
15286 caption.shader.tween("opacity", 0, 300, "easeOutSine", 200, i === 0 ? () => _this.group.visible = false : null)
15287 })
15288 };
15289 this.hoverIn = () => {
15290 _this.isHover = true
15291 };
15292 this.hoverOut = () => {
15293 _this.isHover = false
15294 };
15295 this.click = () => {
15296 var imageURL = _imageURLs[Math.floor(_this.hoverX * _captions.length)];
15297 getURL(imageURL, "_blank");
15298 let components = imageURL.split("_");
15299 let dynamic = "wallpaper " + components[2][0] + ": " + components[1];
15300 TrackUtil.event({
15301 name: "downloads",
15302 dynamic: dynamic
15303 })
15304 }
15305});
15306Class(function DownloadsView(_data) {
15307 Inherit(this, Component);
15308 var _this = this;
15309 var _raycaster, _hideTimer;
15310 var _cards = [];
15311 var _meshes = [];
15312 this.group = new THREE.Group;
15313 (function() {
15314 initRaycaster();
15315 initCards();
15316 Mouse.capture();
15317 _this.startRender(mouseMove)
15318 }());
15319
15320 function initRaycaster() {
15321 _raycaster = _this.initClass(Raycaster, World.CAMERA)
15322 }
15323
15324 function initCards() {
15325 _data.forEach((d, i) => {
15326 d.group_index = 3;
15327 var card = _this.initClass(Card, d, 1, i);
15328 _this.group.add(card.group);
15329 _cards.push(card);
15330 _meshes.push(card.mesh)
15331 });
15332 defer(() => {
15333 _this.group.visible = false
15334 })
15335 }
15336
15337 function mouseMove() {
15338 if (!_this.isActive) return;
15339 hoverInteraction()
15340 }
15341
15342 function hoverInteraction() {
15343 var hit = _raycaster.checkHit(_meshes);
15344 var isHover = !!hit.length;
15345 VFX.instance().updateMouse(isHover);
15346 if (!isHover) {
15347 _cards.forEach((card, i) => {
15348 card.updateMouse(null)
15349 });
15350 return
15351 }
15352 Cursor.none();
15353 var index = _meshes.indexOf(hit[0].object);
15354 _cards.forEach((card, i) => {
15355 card.updateMouse(i === index ? hit[0].uv : null)
15356 })
15357 }
15358 this.activate = () => {
15359 _this.isActive = true;
15360 _this.group.visible = true;
15361 _this.parent.activate();
15362 _cards.forEach(card => {
15363 card.activate()
15364 })
15365 };
15366 this.deactivate = () => {
15367 _this.isActive = false;
15368 VFX.instance().updateMouse(null);
15369 _cards.forEach((card, i) => {
15370 card.updateMouse(null)
15371 });
15372 _cards.forEach(card => {
15373 card.deactivate()
15374 })
15375 };
15376 this.sectionActivate = () => {
15377 if (_hideTimer) clearTimeout(_hideTimer);
15378 _this.group.visible = true;
15379 _cards.forEach(card => {
15380 card.sectionActivate()
15381 })
15382 };
15383 this.sectionDeactivate = () => {
15384 if (_hideTimer) clearTimeout(_hideTimer);
15385 _hideTimer = _this.delayedCall(() => {
15386 _this.group.visible = false
15387 }, 800);
15388 _cards.forEach(card => {
15389 card.sectionDeactivate()
15390 })
15391 };
15392 this.updatePosition = pos => {
15393 _cards.forEach(card => {
15394 card.updatePosition(-_this.group.position.z - pos)
15395 })
15396 }
15397});
15398Class(function RingtonesView(_data) {
15399 Inherit(this, Component);
15400 var _this = this;
15401 var _raycaster, _projector, _hideTimer, _glow, _circle, _rings, _nodes, _ui, _touchTimer;
15402 this.group = new THREE.Group;
15403 this.group.worldPosition = new THREE.Vector3;
15404 var _offscreen = new THREE.Vector2(-1e3, -1e3);
15405 (function() {
15406 initSound();
15407 initRaycaster();
15408 initProjector();
15409 initUI();
15410 initElements();
15411 Mouse.capture();
15412 _this.startRender(loop);
15413 addHandlers()
15414 }());
15415
15416 function initSound() {
15417 Sounds.loadSounds(_data)
15418 }
15419
15420 function initRaycaster() {
15421 _raycaster = _this.initClass(Raycaster, World.CAMERA);
15422 _raycaster.pointsThreshold = .02
15423 }
15424
15425 function initProjector() {
15426 _projector = _this.initClass(ScreenProjection, World.CAMERA)
15427 }
15428
15429 function initUI() {
15430 _ui = _this.initClass(RingtoneUI, _data, [Stage])
15431 }
15432
15433 function initElements() {
15434 _glow = _this.initClass(RingtoneCircleGlow);
15435 _this.group.add(_glow.group);
15436 if (Tests.isRingtoneCircleFallback()) {
15437 _circle = _this.initClass(RingtoneCircle)
15438 } else {
15439 _circle = _this.initClass(RingtoneSphere)
15440 }
15441 _this.group.add(_circle.group);
15442 _rings = _this.initClass(RingtoneRings);
15443 _this.group.add(_rings.group);
15444 _nodes = _this.initClass(RingtoneNodes, _data, _ui, _glow, _rings);
15445 _this.group.add(_nodes.group);
15446 defer(() => {
15447 _this.group.visible = false
15448 })
15449 }
15450
15451 function loop(t, dt) {
15452 mouseMove();
15453 _this.group.rotation.z = Math.sin(dt * .0002) * .2;
15454 _this.group.rotation.x = Math.sin(dt * .00035) * .1 + .1;
15455 _this.group.worldPosition.copy(_this.group.position);
15456 _this.group.worldPosition.setFromMatrixPosition(_this.group.matrixWorld);
15457 if (_this.group.visible) {
15458 _ui.updatePosition(_this.isBehind ? _offscreen : _projector.project(_this.group.worldPosition))
15459 }
15460 }
15461
15462 function addHandlers() {
15463 if (!Device.mobile) return;
15464 __window.bind("touchstart", down);
15465 __window.bind("touchend", up);
15466 __window.bind("touchcancel", up)
15467 }
15468
15469 function down() {
15470 if (_touchTimer) clearTimeout(_touchTimer);
15471 _this.isDown = true
15472 }
15473
15474 function up() {
15475 if (_touchTimer) clearTimeout(_touchTimer);
15476 _touchTimer = _this.delayedCall(() => {
15477 _this.isDown = false
15478 }, 1e3)
15479 }
15480
15481 function mouseMove() {
15482 if (!_this.isActive) return;
15483 hoverInteraction()
15484 }
15485
15486 function hoverInteraction() {
15487 var hit = _raycaster.checkHit(_nodes.mesh);
15488 var isHover = !!hit.length;
15489 _nodes.setHover(Device.mobile && !_this.isDown ? null : hit[0]);
15490 if (isHover) Cursor.pointer()
15491 }
15492 this.activate = () => {
15493 _this.isActive = true;
15494 _this.group.visible = true;
15495 _this.parent.activate();
15496 _ui.animateIn();
15497 _glow.activate();
15498 _circle.activate();
15499 _nodes.activate();
15500 _rings.activate()
15501 };
15502 this.deactivate = () => {
15503 _this.isActive = false;
15504 _ui.animateOut();
15505 _glow.deactivate();
15506 _circle.deactivate();
15507 _nodes.deactivate();
15508 _rings.deactivate()
15509 };
15510 this.sectionActivate = () => {
15511 if (_hideTimer) clearTimeout(_hideTimer);
15512 _this.group.visible = true
15513 };
15514 this.sectionDeactivate = () => {
15515 if (_hideTimer) clearTimeout(_hideTimer);
15516 _hideTimer = _this.delayedCall(() => {
15517 _this.group.visible = false
15518 }, 800)
15519 };
15520 this.updatePosition = pos => {
15521 _this.isBehind = Math.abs(-_this.group.position.z - pos) > 1
15522 }
15523});
15524Class(function RingtoneCircle() {
15525 Inherit(this, Component);
15526 var _this = this;
15527 var _geometry, _shader, _mesh;
15528 this.group = new THREE.Group;
15529 (function() {
15530 initGeometry();
15531 initShader();
15532 initMesh()
15533 }());
15534
15535 function initGeometry() {
15536 _geometry = new THREE.PlaneBufferGeometry(.45, .45, 1, 1)
15537 }
15538
15539 function initShader() {
15540 _shader = _this.initClass(Shader, "RingtoneCircle", "RingtoneCircle");
15541 _shader.uniforms = {
15542 fTransition: {
15543 type: "f",
15544 value: 0
15545 }
15546 };
15547 _shader.material.transparent = true
15548 }
15549
15550 function initMesh() {
15551 _mesh = new THREE.Mesh(_geometry, _shader.material);
15552 _mesh.scale.x = .95;
15553 _this.group.add(_mesh)
15554 }
15555 this.activate = () => {
15556 _shader.tween("fTransition", 1, 1e3, "easeInOutCubic")
15557 };
15558 this.deactivate = () => {
15559 _shader.tween("fTransition", 0, 500, "easeInOutCubic")
15560 }
15561});
15562Class(function RingtoneCircleGlow() {
15563 Inherit(this, Component);
15564 var _this = this;
15565 var _geometry, _shader, _mesh;
15566 this.group = new THREE.Group;
15567 (function() {
15568 initGeometry();
15569 initShader();
15570 initMesh()
15571 }());
15572
15573 function initGeometry() {
15574 _geometry = new THREE.PlaneBufferGeometry(1, 1, 1, 1)
15575 }
15576
15577 function initShader() {
15578 _shader = _this.initClass(Shader, "RingtoneCircle", "RingtoneCircleGlow");
15579 _shader.uniforms = {
15580 fTransition: {
15581 type: "f",
15582 value: 0
15583 }
15584 };
15585 _shader.material.transparent = true;
15586 _shader.material.depthRender = false;
15587 _shader.material.depthTest = false;
15588 _shader.material.blending = THREE.AdditiveBlending
15589 }
15590
15591 function initMesh() {
15592 _mesh = new THREE.Mesh(_geometry, _shader.material);
15593 _mesh.position.z = -.01;
15594 _this.group.add(_mesh)
15595 }
15596 this.activate = () => {
15597 _shader.tween("fTransition", .6, 25e2, "easeInOutSine")
15598 };
15599 this.deactivate = () => {
15600 _shader.tween("fTransition", 0, 500, "easeOutSine")
15601 };
15602 this.hoverIn = () => {
15603 _shader.tween("fTransition", 1.3, 300, "easeOutSine")
15604 };
15605 this.hoverOut = () => {
15606 _shader.tween("fTransition", .6, 3e3, "easeInOutSine")
15607 }
15608});
15609Class(function RingtoneNodes(_data, _ui, _glow, _rings) {
15610 Inherit(this, Component);
15611 var _this = this;
15612 var _geometry, _shader, _points;
15613 var _numParticles = _data.length;
15614 var _rotMat = new THREE.Matrix4;
15615 var _rotPos = new THREE.Vector3;
15616 var _hoverIndex = null;
15617 var _timescale = new DynamicObject({
15618 x: 1
15619 });
15620 this.group = new THREE.Group;
15621 (function() {
15622 initGeometry();
15623 initShader();
15624 initPoints();
15625 _this.startRender(loop)
15626 }());
15627
15628 function initGeometry() {
15629 _geometry = new THREE.BufferGeometry;
15630 _geometry.addAttribute("initialposition", new THREE.BufferAttribute(new Float32Array(_numParticles * 3), 3));
15631 _geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array(_numParticles * 3), 3));
15632 _geometry.addAttribute("speed", new THREE.BufferAttribute(new Float32Array(_numParticles), 1));
15633 _geometry.addAttribute("type", new THREE.BufferAttribute(new Float32Array(_numParticles), 1));
15634 _geometry.addAttribute("hover", new THREE.BufferAttribute(new Float32Array(_numParticles), 1));
15635 var radiuses = [.3, .32, .35, .365, .39, .425];
15636 for (var i = 0; i < _numParticles; i++) {
15637 var angle = Utils.doRandom(-2 * Math.PI, 2 * Math.PI, 3);
15638 var radius = radiuses.getRandom();
15639 var x = radius * Math.sin(angle);
15640 var z = radius * Math.cos(angle);
15641 _geometry.attributes.initialposition.setXYZ(i, x, 0, z);
15642 _geometry.attributes.position.setXYZ(i, x, 0, z);
15643 _geometry.attributes.speed.setX(i, Utils.doRandom(.5, 1.5, 3) * Utils.headsTails(1, -1));
15644 _geometry.attributes.type.setX(i, _data[i].voice == "tom" ? 0 : 1);
15645 _geometry.attributes.hover.setX(i, 0)
15646 }
15647 }
15648
15649 function initShader() {
15650 _shader = _this.initClass(Shader, "RingtoneNodes", "RingtoneNodes");
15651 _shader.uniforms = {
15652 fTime: {
15653 type: "f",
15654 value: 0
15655 },
15656 fTransition: {
15657 type: "f",
15658 value: 0
15659 }
15660 };
15661 _shader.material.side = THREE.DoubleSide;
15662 _shader.material.transparent = true;
15663 _shader.material.depthRender = false
15664 }
15665
15666 function initPoints() {
15667 _points = new THREE.Points(_geometry, _shader.material);
15668 _points.frustumCulled = false;
15669 _this.group.add(_points);
15670 _this.mesh = _points
15671 }
15672
15673 function loop(t, dt, delta) {
15674 _shader.uniforms.fTime.value += delta * .0002 * _timescale.x;
15675 var time = _shader.uniforms.fTime.value;
15676 for (var i = 0; i < _numParticles; i++) {
15677 let speed = _geometry.attributes.speed.array[i];
15678 let angle = time * speed;
15679 _rotMat.makeRotationY(angle);
15680 _rotPos.fromArray(_geometry.attributes.initialposition.array, i * 3);
15681 _rotPos.applyMatrix4(_rotMat);
15682 _geometry.attributes.position.setXYZ(i, _rotPos.x, 0, _rotPos.z)
15683 }
15684 _geometry.attributes.position.needsUpdate = true
15685 }
15686
15687 function removeHover(index) {
15688 _geometry.attributes.hover.setX(index, 0);
15689 _geometry.attributes.hover.needsUpdate = true;
15690 _timescale.tween({
15691 x: 1
15692 }, 3e3, "easeInOutSine");
15693 _ui.hideTitle();
15694 _glow.hoverOut();
15695 _rings.hoverOut()
15696 }
15697
15698 function addHover(index) {
15699 _geometry.attributes.hover.setX(index, 1);
15700 _geometry.attributes.hover.needsUpdate = true;
15701 _timescale.tween({
15702 x: 0
15703 }, 200, "easeOutSine");
15704 _ui.showTitle();
15705 _glow.hoverIn();
15706 _rings.hoverIn()
15707 }
15708 this.setHover = hit => {
15709 if (!hit) {
15710 if (typeof _hoverIndex == "number") {
15711 _ui.updateText(null);
15712 removeHover(_hoverIndex)
15713 }
15714 _hoverIndex = null;
15715 return
15716 }
15717 if (_hoverIndex == hit.index) return;
15718 if (_hoverIndex !== null) removeHover(_hoverIndex);
15719 _hoverIndex = hit.index;
15720 addHover(_hoverIndex);
15721 Sounds.play(_hoverIndex);
15722 _ui.updateText(_hoverIndex)
15723 };
15724 this.activate = () => {
15725 _shader.tween("fTransition", 1, 25e2, "easeInOutSine")
15726 };
15727 this.deactivate = () => {
15728 _shader.tween("fTransition", 0, 500, "easeInOutCubic")
15729 }
15730});
15731Class(function RingtoneRings() {
15732 Inherit(this, Component);
15733 var _this = this;
15734 var _geometry, _shader, _mesh;
15735 this.group = new THREE.Group;
15736 (function() {
15737 initGeometry();
15738 initShader();
15739 initMesh();
15740 initMask()
15741 }());
15742
15743 function initGeometry() {
15744 _geometry = new THREE.PlaneBufferGeometry(1, 1, 1, 1)
15745 }
15746
15747 function initShader() {
15748 _shader = _this.initClass(Shader, "RingtoneRings", "RingtoneRings");
15749 _shader.uniforms = {
15750 fTransition: {
15751 type: "f",
15752 value: 0
15753 }
15754 };
15755 _shader.material.transparent = true;
15756 _shader.material.blending = THREE.AdditiveBlending
15757 }
15758
15759 function initMesh() {
15760 _mesh = new THREE.Mesh(_geometry, _shader.material);
15761 _this.group.add(_mesh);
15762 _mesh.rotation.set(-.5 * Math.PI, 0, 0)
15763 }
15764
15765 function initMask() {}
15766 this.activate = () => {
15767 _shader.tween("fTransition", .8, 1e3, "easeOutSine")
15768 };
15769 this.deactivate = () => {
15770 _shader.tween("fTransition", 0, 500, "easeOutSine")
15771 };
15772 this.hoverIn = () => {
15773 _shader.tween("fTransition", 1, 300, "easeOutSine")
15774 };
15775 this.hoverOut = () => {
15776 _shader.tween("fTransition", .8, 3e3, "easeInOutSine")
15777 }
15778});
15779Class(function RingtoneSphere() {
15780 Inherit(this, Component);
15781 var _this = this;
15782 var _geometry, _shader, _mesh;
15783 this.group = new THREE.Group;
15784 (function() {
15785 initGeometry();
15786 initShader();
15787 initMesh();
15788 _this.startRender(loop)
15789 }());
15790
15791 function initGeometry() {
15792 _geometry = new THREE.SphereBufferGeometry(.2, 40, 20)
15793 }
15794
15795 function initShader() {
15796 _shader = _this.initClass(Shader, "RingtoneSphere", "RingtoneSphere");
15797 _shader.uniforms = {
15798 fTime: {
15799 type: "f",
15800 value: 0
15801 },
15802 fTransition: {
15803 type: "f",
15804 value: 0
15805 }
15806 };
15807 _shader.material.side = THREE.DoubleSide;
15808 _shader.material.transparent = true
15809 }
15810
15811 function initMesh() {
15812 _mesh = new THREE.Mesh(_geometry, _shader.material);
15813 _this.group.add(_mesh);
15814 _mesh.rotation.reorder("XYZ");
15815 _mesh.rotation.x = -.5
15816 }
15817
15818 function loop(t, dt) {
15819 _mesh.rotation.y += .02;
15820 _shader.set("fTime", dt * .001)
15821 }
15822 this.activate = () => {
15823 _shader.tween("fTransition", 1, 17e2, "easeOutSine")
15824 };
15825 this.deactivate = () => {
15826 _shader.tween("fTransition", 0, 500, "linear")
15827 }
15828});
15829Class(function RingtoneUI(_data) {
15830 Inherit(this, View);
15831 var _this = this;
15832 var $this, $prompt, $heading, $title;
15833 var _title;
15834 (function() {
15835 initHTML();
15836 style();
15837 addHandlers();
15838 resizeHandler()
15839 }());
15840
15841 function initHTML() {
15842 $this = _this.element;
15843 $prompt = $this.create("DownloadPrompt");
15844 $heading = $this.create("RingtoneHeading");
15845 $title = $this.create("Title")
15846 }
15847
15848 function style() {
15849 $this.css({
15850 left: 0,
15851 top: 0
15852 });
15853 if (!Device.mobile) {
15854 $prompt.size(60, 60).center(1, 0).css({
15855 top: -140,
15856 borderRadius: 1e3,
15857 opacity: .8
15858 }).bg(Config.CDN + "assets/images/ui/download.png")
15859 }
15860 $heading.html(Device.mobile ? "DOWNLOAD<br/>ON DESKTOP" : "DOWNLOAD ALL").css({
15861 top: Mobile.phone ? -90 : -72,
15862 fontSize: Mobile.phone ? 15 : 9,
15863 letterSpacing: 2,
15864 lineHeight: 18,
15865 opacity: .8,
15866 width: 200,
15867 textAlign: "center",
15868 marginLeft: -100,
15869 fontWeight: "bold"
15870 });
15871 $title.css({
15872 top: -30,
15873 fontSize: 40,
15874 letterSpacing: 3,
15875 width: 300,
15876 textAlign: "center",
15877 marginLeft: -150,
15878 color: "#83bdf8",
15879 fontWeight: "300",
15880 lineHeight: "1.02em"
15881 });
15882 $title.text("RINGTONES");
15883 _title = _this.initClass(RingtoneUITitle);
15884 $this.css({
15885 opacity: 0
15886 }).hide()
15887 }
15888
15889 function addHandlers() {
15890 if ($prompt) $prompt.interact(hover, click);
15891 _this.events.subscribe(HydraEvents.RESIZE, resizeHandler)
15892 }
15893
15894 function hover(e) {
15895 switch (e.action) {
15896 case "over":
15897 $prompt.tween({
15898 opacity: 1
15899 }, 200, "easeOutSine");
15900 $heading.tween({
15901 opacity: 1
15902 }, 200, "easeOutSine");
15903 break;
15904 case "out":
15905 $prompt.tween({
15906 opacity: .8
15907 }, 400, "easeOutSine");
15908 $heading.tween({
15909 opacity: .8
15910 }, 400, "easeOutSine");
15911 break
15912 }
15913 }
15914
15915 function resizeHandler() {
15916 var scaleX = Utils.convertRange(Stage.width, 0, 800, 0, 1, true);
15917 var scaleY = Utils.convertRange(Stage.height, 0, 800, 0, 1, true);
15918 var scale = Math.min(scaleX, scaleY);
15919 $this.transform({
15920 scale: scale
15921 })
15922 }
15923
15924 function click() {
15925 $prompt.tween({
15926 opacity: .8
15927 }, 400, "easeOutSine");
15928 $heading.tween({
15929 opacity: .8
15930 }, 400, "easeOutSine");
15931 getURL(Data.getRingtonesDownload(), "_blank");
15932 TrackUtil.event({
15933 name: "downloads",
15934 dynamic: "ringtones"
15935 })
15936 }
15937 this.updatePosition = pos => {
15938 $this.x = pos.x;
15939 $this.y = pos.y;
15940 $this.transform()
15941 };
15942 this.updateText = index => {
15943 if (index == null) {
15944 return
15945 }
15946 _title.update(_data[index].title.toUpperCase(), _data[index].voice)
15947 };
15948 this.animateIn = () => {
15949 $this.show();
15950 $this.tween({
15951 opacity: 1
15952 }, 25e2, "easeInOutSine")
15953 };
15954 this.animateOut = () => {
15955 $this.tween({
15956 opacity: 0
15957 }, 300, "easeInOutCubic", () => $this.hide())
15958 };
15959 this.showTitle = () => {
15960 $title.tween({
15961 opacity: 0
15962 }, 300, "easeOutSine");
15963 _title.animateIn()
15964 };
15965 this.hideTitle = () => {
15966 $title.tween({
15967 opacity: 1
15968 }, 2e3, "easeInOutSine", 200);
15969 _title.animateOut()
15970 }
15971});
15972Class(function RingtoneUITitle() {
15973 Inherit(this, View);
15974 var _this = this;
15975 var $this, $text;
15976 var _split;
15977 (function() {
15978 initHTML()
15979 }());
15980
15981 function initHTML() {
15982 $this = _this.element;
15983 $this.size(280, 200).center().css({
15984 marginTop: -32,
15985 opacity: 0
15986 })
15987 }
15988 this.animateIn = function() {
15989 $this.tween({
15990 opacity: 1
15991 }, 300, "easeOutSine")
15992 };
15993 this.animateOut = function() {
15994 $this.tween({
15995 opacity: 0
15996 }, 1e3, "easeOutSine")
15997 };
15998 this.update = function(text, voice) {
15999 var size = Utils.convertRange(text.length, 10, 30, 42, 32);
16000 var longest = 0;
16001 var split = text.split(" ");
16002 for (var i = 0; i < split.length; i++) {
16003 longest = Math.max(longest, split[i].length)
16004 }
16005 var max = Utils.convertRange(longest, 5, 15, 42, 30);
16006 size = Math.min(size, max);
16007 size *= .95;
16008 if ($text) $text.destroy();
16009 $text = $this.create(".text");
16010 $text.fontStyle("GothamRnd", size, voice !== "tom" ? "#24fff2" : "#86ffba");
16011 $text.css({
16012 letterSpacing: 3,
16013 lineHeight: size * 1.05,
16014 width: "100%",
16015 textAlign: "center",
16016 fontWeight: "300"
16017 });
16018 $text.html(text).invisible();
16019 _split = SplitTextfield.split($text, "word");
16020 defer(function() {
16021 $text.visible();
16022 for (var i = 0; i < _split.length; i++) {
16023 _split[i].css({
16024 position: "relative",
16025 float: "",
16026 cssFloat: "",
16027 styleFloat: "",
16028 display: "inline-block"
16029 });
16030 _split[i].css({
16031 opacity: 0
16032 }).transform({
16033 y: 10
16034 }).tween({
16035 opacity: 1,
16036 y: 0
16037 }, 1e3, "easeOutCubic", i * 50)
16038 }
16039 })
16040 }
16041});
16042Class(function GalleryView(_data) {
16043 Inherit(this, Component);
16044 var _this = this;
16045 var _raycaster, _hideTimer;
16046 var _cards = [];
16047 var _meshes = [];
16048 this.group = new THREE.Group;
16049 (function() {
16050 initRaycaster();
16051 initCards();
16052 Mouse.capture();
16053 _this.startRender(mouseMove)
16054 }());
16055
16056 function initRaycaster() {
16057 _raycaster = _this.initClass(Raycaster, World.CAMERA)
16058 }
16059
16060 function initCards() {
16061 _data.forEach((d, i) => {
16062 d.group_index = 2;
16063 var card = _this.initClass(Card, d, 1, i);
16064 _this.group.add(card.group);
16065 _cards.push(card);
16066 _meshes.push(card.mesh)
16067 });
16068 defer(() => {
16069 _this.group.visible = false
16070 })
16071 }
16072
16073 function mouseMove() {
16074 if (!_this.isActive) return;
16075 hoverInteraction()
16076 }
16077
16078 function hoverInteraction() {
16079 var hit = _raycaster.checkHit(_meshes);
16080 var isHover = !!hit.length;
16081 VFX.instance().updateMouse(isHover);
16082 if (!isHover) {
16083 _cards.forEach((card, i) => {
16084 card.updateMouse(null)
16085 });
16086 return
16087 }
16088 Cursor.none();
16089 var index = _meshes.indexOf(hit[0].object);
16090 _cards.forEach((card, i) => {
16091 card.updateMouse(i === index ? hit[0].uv : null)
16092 })
16093 }
16094 this.activate = () => {
16095 _this.isActive = true;
16096 _this.group.visible = true;
16097 _this.parent.activate();
16098 _cards.forEach(card => {
16099 card.activate()
16100 })
16101 };
16102 this.deactivate = () => {
16103 _this.isActive = false;
16104 VFX.instance().updateMouse(null);
16105 _cards.forEach((card, i) => {
16106 card.updateMouse(null)
16107 });
16108 _cards.forEach(card => {
16109 card.deactivate()
16110 })
16111 };
16112 this.sectionActivate = () => {
16113 if (_hideTimer) clearTimeout(_hideTimer);
16114 _this.group.visible = true;
16115 _cards.forEach(card => {
16116 card.sectionActivate()
16117 })
16118 };
16119 this.sectionDeactivate = () => {
16120 if (_hideTimer) clearTimeout(_hideTimer);
16121 _hideTimer = _this.delayedCall(() => {
16122 _this.group.visible = false
16123 }, 2e3);
16124 _cards.forEach(card => {
16125 card.sectionDeactivate()
16126 })
16127 };
16128 this.updatePosition = pos => {
16129 _cards.forEach(card => {
16130 card.updatePosition(-_this.group.position.z - pos)
16131 })
16132 }
16133});
16134Class(function MobileMenuView() {
16135 Inherit(this, View);
16136 var _this = this;
16137 var $this, $nav, $links, _share;
16138 var _elements = [];
16139 (function() {
16140 initHTML();
16141 initNav();
16142 initLinks();
16143 initShare();
16144 addListeners();
16145 resizeHandler()
16146 }());
16147
16148 function initHTML() {
16149 $this = _this.element;
16150 $this.size(400, 320).center()
16151 }
16152
16153 function initNav() {
16154 $nav = $this.create(".nav");
16155 $nav.css({
16156 position: "relative",
16157 display: "block"
16158 });
16159 var items = [{
16160 text: "LATEST",
16161 color: "#a9eeaa"
16162 }, {
16163 text: "SCHEDULE",
16164 color: "#7ee3c3"
16165 }, {
16166 text: "GALLERY",
16167 color: "#96eaf2"
16168 }, {
16169 text: "DOWNLOADS",
16170 color: "#83bdf8"
16171 }];
16172 for (var i = 0; i < items.length; i++) {
16173 items[i].index = i;
16174 var item = _this.initClass(MobileMenuItem, items[i], [$nav]);
16175 _elements.push(item);
16176 item.events.add(HydraEvents.CLICK, navClick)
16177 }
16178 }
16179
16180 function initLinks() {
16181 $links = $this.create(".nav");
16182 $links.css({
16183 position: "relative",
16184 display: "block",
16185 marginTop: 20
16186 });
16187 var $text = $links.create(".text");
16188 $text.fontStyle("GothamRnd", 10, "#666");
16189 $text.css({
16190 width: 60,
16191 borderBottom: "1px solid #666",
16192 margin: "0 auto",
16193 paddingBottom: 6,
16194 fontWeight: "bold",
16195 textAlign: "center",
16196 position: "relative",
16197 marginBottom: 20,
16198 display: "block",
16199 letterSpacing: 2,
16200 opacity: .7
16201 });
16202 $text.text("LINKS");
16203 _elements.push($text);
16204 var data = Data.getLinks();
16205 var links = [];
16206 for (var i in data) {
16207 for (var j in data[i]) {
16208 if (data[i][j].url) links.push(data[i][j])
16209 }
16210 }
16211 for (var i = 0; i < links.length; i++) {
16212 var item = _this.initClass(MobileMenuItem, links[i], [$links]);
16213 _elements.push(item)
16214 }
16215 }
16216
16217 function initShare() {
16218 _share = _this.initClass(NavShare);
16219 _share.element.center(1, 0).css({
16220 top: -50
16221 })
16222 }
16223
16224 function addListeners() {
16225 _this.events.subscribe(HydraEvents.RESIZE, resizeHandler)
16226 }
16227
16228 function resizeHandler() {
16229 if (Stage.width > Stage.height) {
16230 $nav.css({
16231 position: "absolute",
16232 width: 200,
16233 left: "50%",
16234 marginLeft: -220,
16235 top: 102
16236 });
16237 $links.css({
16238 position: "absolute",
16239 width: 200,
16240 left: "50%",
16241 marginLeft: 20,
16242 top: 45
16243 });
16244 _share.element.center(1, 0).css({
16245 top: 60,
16246 marginLeft: -150
16247 })
16248 } else {
16249 $nav.css({
16250 position: "relative",
16251 width: "",
16252 left: "",
16253 marginLeft: "",
16254 top: ""
16255 });
16256 $links.css({
16257 position: "relative",
16258 width: "",
16259 left: "",
16260 marginLeft: "",
16261 top: ""
16262 });
16263 _share.element.center(1, 0).css({
16264 top: -50
16265 })
16266 }
16267 var scale = Utils.convertRange(Stage.height, 480, 0, 1, 0, true);
16268 $this.transform({
16269 scale: scale
16270 })
16271 }
16272
16273 function navClick(e) {
16274 SectionsTimeline.instance().toSection(e.index);
16275 MobileMenu.instance().animateOut()
16276 }
16277 this.animateIn = function() {
16278 _share.animateIn();
16279 for (var i = 0; i < _elements.length; i++) {
16280 _elements[i].css({
16281 opacity: 0
16282 }).transform({
16283 y: 10
16284 }).tween({
16285 opacity: 1,
16286 y: 0
16287 }, 700, "easeOutCubic", i * 50 + 300)
16288 }
16289 }
16290});
16291Class(function MobileMenuItem(_config) {
16292 Inherit(this, View);
16293 var _this = this;
16294 var $this, $text;
16295 (function() {
16296 initHTML();
16297 initText();
16298 addListeners()
16299 }());
16300
16301 function initHTML() {
16302 $this = _this.element;
16303 $this.size("100%", _config.color ? 32 : 22).css({
16304 position: "relative",
16305 display: "block"
16306 })
16307 }
16308
16309 function initText() {
16310 $text = $this.create(".text");
16311 $text.fontStyle("GothamRnd", _config.color ? 19 : 10, _config.color || "#eee");
16312 $text.css({
16313 width: "100%",
16314 textAlign: "center",
16315 letterSpacing: 2,
16316 opacity: .75
16317 });
16318 $text.text(_config.text.toUpperCase())
16319 }
16320
16321 function addListeners() {
16322 $this.interact(hover, click)
16323 }
16324
16325 function hover(e) {
16326 switch (e.action) {
16327 case "over":
16328 $text.tween({
16329 opacity: 1
16330 }, 200, "easeOutSine");
16331 break;
16332 case "out":
16333 $text.tween({
16334 opacity: .75
16335 }, 200, "easeOutSine");
16336 break
16337 }
16338 }
16339
16340 function click() {
16341 if (_config.url) {
16342 getURL(_config.url, "_blank")
16343 } else {
16344 _this.events.fire(HydraEvents.CLICK, _config)
16345 }
16346 }
16347 this.animateIn = function() {}
16348});
16349Class(function NewsView(_data) {
16350 Inherit(this, Component);
16351 var _this = this;
16352 var _raycaster, _hideTimer;
16353 var _cards = [];
16354 var _meshes = [];
16355 this.group = new THREE.Group;
16356 (function() {
16357 initRaycaster();
16358 initCards();
16359 Mouse.capture();
16360 _this.startRender(mouseMove)
16361 }());
16362
16363 function initRaycaster() {
16364 _raycaster = _this.initClass(Raycaster, World.CAMERA)
16365 }
16366
16367 function initCards() {
16368 _data.forEach((d, i) => {
16369 d.group_index = 0;
16370 var card = _this.initClass(Card, d, 1, i);
16371 _this.group.add(card.group);
16372 _cards.push(card);
16373 _meshes.push(card.mesh)
16374 });
16375 defer(() => {
16376 _this.group.visible = false
16377 })
16378 }
16379
16380 function mouseMove() {
16381 if (!_this.isActive) return;
16382 hoverInteraction()
16383 }
16384
16385 function hoverInteraction() {
16386 var hit = _raycaster.checkHit(_meshes);
16387 var isHover = !!hit.length;
16388 VFX.instance().updateMouse(isHover);
16389 if (!isHover) {
16390 _cards.forEach((card, i) => {
16391 card.updateMouse(null)
16392 });
16393 return
16394 }
16395 Cursor.none();
16396 var index = _meshes.indexOf(hit[0].object);
16397 _cards.forEach((card, i) => {
16398 card.updateMouse(i === index ? hit[0].uv : null)
16399 })
16400 }
16401 this.activate = () => {
16402 _this.isActive = true;
16403 _this.group.visible = true;
16404 _this.parent.activate();
16405 _cards.forEach(card => {
16406 card.activate()
16407 })
16408 };
16409 this.deactivate = () => {
16410 _this.isActive = false;
16411 VFX.instance().updateMouse(null);
16412 _cards.forEach((card, i) => {
16413 card.updateMouse(null)
16414 });
16415 _cards.forEach(card => {
16416 card.deactivate()
16417 })
16418 };
16419 this.sectionActivate = () => {
16420 if (_hideTimer) clearTimeout(_hideTimer);
16421 _this.group.visible = true;
16422 _cards.forEach(card => {
16423 card.sectionActivate()
16424 })
16425 };
16426 this.sectionDeactivate = () => {
16427 if (_hideTimer) clearTimeout(_hideTimer);
16428 _hideTimer = _this.delayedCall(() => {
16429 _this.group.visible = false
16430 }, 700);
16431 _cards.forEach(card => {
16432 card.sectionDeactivate()
16433 })
16434 };
16435 this.updatePosition = pos => {
16436 _cards.forEach(card => {
16437 card.updatePosition(-_this.group.position.z - pos)
16438 })
16439 };
16440 this.introSetup = () => {
16441 _cards.forEach(card => {
16442 card.introSetup()
16443 })
16444 };
16445 this.introEnd = () => {
16446 _cards.forEach(card => {
16447 card.introEnd()
16448 })
16449 }
16450});
16451Class(function ScheduleView(_data) {
16452 Inherit(this, Component);
16453 var _this = this;
16454 var _raycaster, _hideTimer, _geometry, _shader, _mesh, _maskShader, _mobileSwitch;
16455 var _textures = [];
16456 var _mobileIndex = 0;
16457 this.group = new THREE.Group;
16458 _this.prevIndex = 0;
16459 (function() {
16460 initRaycaster();
16461 initGeometry();
16462 initTextures();
16463 initShader();
16464 initMesh();
16465 initMask();
16466 _this.startRender(loop)
16467 }());
16468
16469 function initRaycaster() {
16470 _raycaster = _this.initClass(Raycaster, World.CAMERA)
16471 }
16472
16473 function initGeometry() {
16474 var s = .6;
16475 _geometry = new THREE.PlaneBufferGeometry(s * 2, s * 1, 1, 1)
16476 }
16477
16478 function initTextures() {
16479 _data.forEach(d => {
16480 var image = d.media || Config.CDN + "assets/images/schedule/" + d.id + ".jpg";
16481 var texture = Utils3D.getTexture(image);
16482 _textures.push(texture)
16483 })
16484 }
16485
16486 function initShader() {
16487 var pattern1 = Utils3D.getRepeatTexture("assets/images/common/pattern1.jpg");
16488 var pattern2 = Utils3D.getRepeatTexture("assets/images/common/pattern2.jpg");
16489 var noise = Utils3D.getRepeatTexture("assets/images/common/noise.jpg");
16490 _shader = _this.initClass(Shader, "Schedule", "Schedule");
16491 _shader.uniforms = {
16492 tMap: {
16493 type: "t",
16494 value: _textures[0]
16495 },
16496 tMap2: {
16497 type: "t",
16498 value: _textures[1]
16499 },
16500 tPattern1: {
16501 type: "t",
16502 value: pattern1
16503 },
16504 tPattern2: {
16505 type: "t",
16506 value: pattern2
16507 },
16508 tNoise: {
16509 type: "t",
16510 value: noise
16511 },
16512 fTime: {
16513 type: "f",
16514 value: 0
16515 },
16516 fFade: {
16517 type: "f",
16518 value: 0
16519 },
16520 fTransition: {
16521 type: "f",
16522 value: 0
16523 },
16524 fTint: {
16525 type: "c",
16526 value: new THREE.Color(Config.GRADIENT[1])
16527 }
16528 };
16529 _shader.material.transparent = true;
16530 _shader.material.blending = THREE.AdditiveBlending
16531 }
16532
16533 function initMesh() {
16534 _mesh = new THREE.Mesh(_geometry, _shader.material);
16535 _mesh.frustumCulled = false;
16536 _this.group.add(_mesh);
16537 var s = 4;
16538 _mesh.scale.set(s * .75, s, s);
16539 _mesh.position.set(-.1, -.25, -.7);
16540 _mesh.rotation.x = -1.48;
16541 _mesh.rotation.y = 0;
16542 defer(() => {
16543 _this.group.visible = false
16544 })
16545 }
16546
16547 function initMask() {
16548 _maskShader = _this.initClass(Shader, "Schedule", "ScheduleMask");
16549 _maskShader.uniforms = {
16550 fTime: {
16551 type: "f",
16552 value: 0
16553 },
16554 fFade: {
16555 type: "f",
16556 value: 0
16557 }
16558 }
16559 }
16560
16561 function loop(t, dt) {
16562 _shader.set("fTime", dt * .001);
16563 _maskShader.set("fTime", dt * .001)
16564 }
16565 this.activate = () => {
16566 _this.isActive = true;
16567 _this.group.visible = true;
16568 _this.parent.activate();
16569 _shader.tween("fFade", 1, 2e3, "easeOutCubic");
16570 _maskShader.tween("fFade", 1, 2e3, "easeOutCubic")
16571 };
16572 this.deactivate = () => {
16573 if (_mobileSwitch) clearTimeout(_mobileSwitch);
16574 _this.isActive = false;
16575 _shader.tween("fFade", 0, 300, "easeInCubic");
16576 _maskShader.tween("fFade", 0, 300, "easeInCubic")
16577 };
16578 this.sectionActivate = () => {
16579 if (_hideTimer) clearTimeout(_hideTimer);
16580 _this.group.visible = true
16581 };
16582 this.sectionDeactivate = () => {
16583 if (_hideTimer) clearTimeout(_hideTimer);
16584 _hideTimer = _this.delayedCall(() => {
16585 _this.group.visible = false
16586 }, 700)
16587 };
16588 this.updatePosition = pos => {
16589 var distance = Math.abs(-_this.group.position.z - pos);
16590 var y = Utils.range(distance, 0, 1, 0, -1, true)
16591 };
16592 this.change = (index, slow) => {
16593 index = index % _textures.length;
16594 _shader.set("tMap", _textures[_this.prevIndex]);
16595 _this.prevIndex = index;
16596 _shader.set("tMap2", _textures[index]);
16597 _shader.set("fTransition", 0);
16598 _shader.tween("fTransition", 1, slow ? 3e3 : 800, slow ? "easeOutSine" : "easeOutCubic", function() {
16599 _shader.set("tMap", _textures[index])
16600 })
16601 }
16602});
16603Class(function ScheduleNav(_view) {
16604 Inherit(this, View);
16605 var _this = this;
16606 var $this;
16607 var _items, _timeout, _interval, _index = 0;
16608 (function() {
16609 initHTML();
16610 initItems();
16611 addListeners();
16612 resizeHandler()
16613 }());
16614
16615 function initHTML() {
16616 $this = _this.element;
16617 $this.size(300, 400).css({
16618 right: 140
16619 }).setZ(10).mouseEnabled(false)
16620 }
16621
16622 function initItems() {
16623 var data = Data.getSchedule();
16624 var top = 0;
16625 _items = [];
16626 for (var i = 0; i < data.schedule.length; i++) {
16627 data.schedule[i].index = i;
16628 if (i == data.schedule.length - 1) data.schedule[i].last = true;
16629 var item = _this.initClass(ScheduleNavItem, data.schedule[i]);
16630 item.css({
16631 top: top
16632 });
16633 var base = Mobile.phone ? 40 : 50;
16634 top += item.double ? base + 20 : base;
16635 _items.push(item)
16636 }
16637 top -= 20;
16638 $this.size(400, top).center(0, 1)
16639 }
16640
16641 function addListeners() {
16642 _this.events.add(HydraEvents.RESIZE, resizeHandler);
16643 if (Device.mobile) return;
16644 for (var i = 0; i < _items.length; i++) {
16645 _items[i].events.add(HydraEvents.HOVER, itemHover)
16646 }
16647 }
16648
16649 function resizeHandler() {
16650 if (Mobile.phone) {
16651 var scaleX = Utils.convertRange(Stage.width, 250, 600, .6, 1, true);
16652 var scaleY = Utils.convertRange(Stage.height, 100, 500, .2, 1, true);
16653 var scale = Math.min(scaleX, scaleY);
16654 $this.transformPoint("70%", "50%").transform({
16655 scale: scale
16656 }).css({
16657 right: 20 * scale
16658 })
16659 }
16660 }
16661
16662 function itemHover(e) {
16663 clearTimeout(_timeout);
16664 clearTimeout(_interval);
16665 switch (e.action) {
16666 case "over":
16667 _index = e.index;
16668 for (var i = 0; i < _items.length; i++) {
16669 _items[i].wrap.tween({
16670 opacity: i == e.index ? 1 : .7
16671 }, 600, "easeOutSine")
16672 }
16673 setActive();
16674 break;
16675 case "out":
16676 _timeout = _this.delayedCall(function() {
16677 for (var i = 0; i < _items.length; i++) {
16678 _items[i].wrap.tween({
16679 y: 0,
16680 opacity: .85
16681 }, 1e3, "easeOutSine")
16682 }
16683 }, 50);
16684 _interval = _this.delayedCall(changeIndex, 4e3);
16685 break
16686 }
16687 }
16688
16689 function changeIndex() {
16690 _index++;
16691 if (_index > _items.length - 1) _index = 0;
16692 setActive(true);
16693 _interval = _this.delayedCall(changeIndex, 4e3)
16694 }
16695
16696 function setActive(slow) {
16697 for (var i = 0; i < _items.length; i++) {
16698 if (i !== _index) _items[i].deactivate()
16699 }
16700 _items[_index].activate();
16701 _view.change(_index, slow)
16702 }
16703 this.animateIn = function() {
16704 if (_this.visible) return;
16705 _this.visible = true;
16706 if (Global.MOBILE_LOGO && Stage.height < 500) Global.MOBILE_LOGO.tween({
16707 opacity: 0
16708 }, 500, "easeOutSine");
16709 for (var i = 0; i < _items.length; i++) {
16710 _items[i].animateIn(i * 120)
16711 }
16712 clearTimeout(_interval);
16713 _interval = _this.delayedCall(changeIndex, 3e3)
16714 };
16715 this.animateOut = function() {
16716 if (!_this.visible) return;
16717 _this.visible = false;
16718 if (Global.MOBILE_LOGO) Global.MOBILE_LOGO.tween({
16719 opacity: 1
16720 }, 500, "easeOutSine");
16721 clearTimeout(_interval);
16722 for (var i = 0; i < _items.length; i++) {
16723 _items[i].animateOut(i * 30 + 200)
16724 }
16725 }
16726});
16727Class(function ScheduleNavItem(_data) {
16728 Inherit(this, View);
16729 var _this = this;
16730 var $this, $wrap, $title, $time, $line, $box;
16731 (function() {
16732 initHTML();
16733 initText();
16734 initBox();
16735 addListeners()
16736 }());
16737
16738 function initHTML() {
16739 $this = _this.element;
16740 $this.size("100%", Mobile.phone ? 40 : 50).setZ(10).invisible();
16741 $wrap = $this.create(".wrap");
16742 $wrap.size("100%").css({
16743 opacity: .85,
16744 top: 10
16745 });
16746 _this.wrap = $wrap
16747 }
16748
16749 function initText() {
16750 $title = $wrap.create(".title");
16751 $title.fontStyle("GothamRnd", 14, "#daffeb");
16752 $title.css({
16753 letterSpacing: 1,
16754 whiteSpace: "nowrap",
16755 width: "",
16756 textTransform: "uppercase",
16757 right: 140,
16758 textAlign: "right"
16759 });
16760 var text = (_data.title || _data.name).toUpperCase();
16761 text = text.replace(": ", ":<br/>");
16762 text = text.replace("WHO", "WHO<br/>");
16763 $title.html(text);
16764 $title.line = $title.create(".line");
16765 $title.line.size(200, 2).css({
16766 bottom: -3,
16767 right: 0,
16768 overflow: "hidden"
16769 });
16770 $title.lineInner = $title.line.create(".inner");
16771 $title.lineInner.size("100%").css({
16772 left: "100%"
16773 }).bg(Config.GRADIENT[1]);
16774 if (text.strpos("<br/>") > 0) {
16775 _this.double = true;
16776 $this.css({
16777 height: 70
16778 })
16779 }
16780 $time = $wrap.create(".title");
16781 $time.fontStyle("GothamRnd", 14, Config.GRADIENT[1]);
16782 $time.css({
16783 opacity: .8,
16784 letterSpacing: 1,
16785 whiteSpace: "nowrap",
16786 width: 100,
16787 textTransform: "uppercase",
16788 right: 0,
16789 textAlign: "left"
16790 });
16791 var split = _data.time.split(" ");
16792 var number = split[3];
16793 var ampm = split[4];
16794 $time.text(number + "" + ampm);
16795 _this.delayedCall(function() {
16796 $title.lineWidth = CSS.textSize($title).width;
16797 $title.line.css({
16798 width: $title.lineWidth
16799 })
16800 }, 200)
16801 }
16802
16803 function initBox() {
16804 $box = $wrap.create(".box");
16805 $box.size(9, 9).css({
16806 right: 115,
16807 top: 1,
16808 opacity: .5,
16809 border: "1px solid #daffeb"
16810 });
16811 $box.inner = $box.create(".line");
16812 $box.inner.size(30, 1).center().bg("#daffeb").transform({
16813 scaleX: 0
16814 });
16815 $box.fill = $box.create(".fill");
16816 $box.fill.size("100%").bg("#daffeb").css({
16817 opacity: 0,
16818 boxShadow: "0 0 50px #daffeb"
16819 });
16820 if (!_data.last) {
16821 $line = $this.create(".line");
16822 var base = Mobile.phone ? 20 : 30;
16823 $line.transformPoint("50%", "0%").size(1, _this.double ? base + 28 : base + 8).css({
16824 top: 23,
16825 right: 120,
16826 opacity: .3
16827 }).bg("#daffeb")
16828 }
16829 }
16830
16831 function addListeners() {
16832 $this.interact(hover, click);
16833 $this.hit.mouseEnabled(true)
16834 }
16835
16836 function hover(e) {
16837 if (!_this.visible) return;
16838 _this.events.fire(HydraEvents.HOVER, {
16839 action: e.action,
16840 index: _data.index
16841 });
16842 switch (e.action) {
16843 case "over":
16844 $box.inner.tween({
16845 scaleX: 1
16846 }, 300, "easeOutCubic");
16847 $title.tween({
16848 x: -8
16849 }, 300, "easeOutCubic");
16850 $time.tween({
16851 x: 8
16852 }, 300, "easeOutCubic");
16853 $title.lineInner.stopTween().transform({
16854 x: 0
16855 }).tween({
16856 x: -$title.lineWidth
16857 }, 300, "easeOutCubic");
16858 break;
16859 case "out":
16860 $box.inner.tween({
16861 scaleX: 0
16862 }, 400, "easeOutCubic");
16863 $title.tween({
16864 x: 0
16865 }, 400, "easeOutCubic");
16866 $time.tween({
16867 x: 0
16868 }, 400, "easeOutCubic");
16869 $title.lineInner.tween({
16870 x: -$title.lineWidth * 2
16871 }, 400, "easeOutCubic");
16872 break
16873 }
16874 }
16875
16876 function click() {
16877 if (!_this.visible) return;
16878 hover({
16879 action: "out"
16880 });
16881 getURL(_data.url, "_blank");
16882 TrackUtil.event({
16883 name: "schedule",
16884 dynamic: _data.name
16885 })
16886 }
16887 this.activate = function() {
16888 $box.fill.tween({
16889 opacity: 1
16890 }, 100, "easeOutSine");
16891 $box.tween({
16892 opacity: 1
16893 }, 200, "easeOutSine")
16894 };
16895 this.deactivate = function() {
16896 $box.fill.tween({
16897 opacity: 0
16898 }, 300, "easeOutSine");
16899 $box.tween({
16900 opacity: .5
16901 }, 400, "easeOutSine")
16902 };
16903 this.animateIn = function(delay) {
16904 $this.stopTween().clearAlpha().visible().transform({
16905 y: 20
16906 }).tween({
16907 y: 0
16908 }, 800, "easeOutCubic", delay, function() {
16909 _this.visible = true
16910 });
16911 $title.lineInner.stopTween().transform({
16912 x: 0
16913 });
16914 $box.inner.stopTween().transform({
16915 scaleX: 0
16916 });
16917 $box.stopTween().transform({
16918 y: 20
16919 }).css({
16920 opacity: 0
16921 }).tween({
16922 y: 0,
16923 opacity: 1
16924 }, 500, "easeOutCubic", delay);
16925 $title.stopTween().transform({
16926 x: -30
16927 }).css({
16928 opacity: 0
16929 }).tween({
16930 x: 0,
16931 opacity: 1
16932 }, 700, "easeOutCubic", delay);
16933 $time.stopTween().transform({
16934 x: 30
16935 }).css({
16936 opacity: 0
16937 }).tween({
16938 x: 0,
16939 opacity: 1
16940 }, 700, "easeOutCubic", delay);
16941 if ($line) $line.stopTween().transform({
16942 scaleY: 0
16943 }).tween({
16944 scaleY: 1
16945 }, 500, "easeOutCubic", delay + 400)
16946 };
16947 this.animateOut = function(delay) {
16948 _this.visible = false;
16949 $this.tween({
16950 opacity: 0,
16951 y: -10
16952 }, 500, "easeOutCubic", delay, function() {
16953 $this.clearAlpha().invisible()
16954 })
16955 }
16956});
16957Class(function UICaption() {
16958 Inherit(this, View);
16959 var _this = this;
16960 var $this;
16961 var _data;
16962 (function() {
16963 _data = Data.getVideos()[0];
16964 initHTML();
16965 style();
16966 resize();
16967 addHandlers()
16968 }());
16969
16970 function initHTML() {
16971 $this = _this.element
16972 }
16973
16974 function style() {
16975 $this.html(_data.text);
16976 $this.css({
16977 fontWeight: "300",
16978 left: 0,
16979 right: 0,
16980 margin: "auto",
16981 bottom: "15%",
16982 width: "40%",
16983 padding: "20px 25px",
16984 lineHeight: "1.4em",
16985 background: "rgba(0, 0, 0, 0.2)",
16986 boxShadow: "0px 0px 0px 1px #179558"
16987 })
16988 }
16989
16990 function addHandlers() {
16991 _this.events.subscribe(HydraEvents.RESIZE, resize)
16992 }
16993
16994 function resize() {
16995 $this.css({
16996 fontSize: Utils.range(Stage.width, 600, 14e2, 16, 20, true)
16997 })
16998 }
16999});
17000FX.Class(function BlurMask(_nuke) {
17001 Inherit(this, FXLayer);
17002 var _this = this;
17003 var _material = new THREE.MeshBasicMaterial({
17004 color: "#000000"
17005 });
17006 this.resolution = Tests.isReducedMaskSize() ? .25 : .5;
17007 (function() {
17008 _this.create(_nuke)
17009 }());
17010 this.add = function(mesh, material) {
17011 var obj = _this.addObject(mesh);
17012 obj.material = material || _material.clone();
17013 obj.material.side = THREE.DoubleSide
17014 };
17015 this.render = function(stage, camera) {
17016 var clear = _nuke.renderer.getClearColor();
17017 _nuke.renderer.setClearColor(16777215);
17018 _this.draw(stage, camera);
17019 _nuke.renderer.setClearColor(clear)
17020 }
17021}, "singleton");
17022Class(function VFX(_renderer, _scene, _camera) {
17023 Inherit(this, Component);
17024 var _this = this;
17025 var _nuke, _blurMask, _composite;
17026 (function() {
17027 initNuke();
17028 initBlurMask();
17029 initPass();
17030 addHandlers();
17031 defer(() => {
17032 Render.start(loop)
17033 })
17034 }());
17035
17036 function initNuke() {
17037 _nuke = _this.initClass(Nuke, Stage, {
17038 renderer: _renderer,
17039 scene: _scene,
17040 camera: _camera,
17041 dpr: Tests.getDPR()
17042 });
17043 World.ELEMENT.hide()
17044 }
17045
17046 function initBlurMask() {
17047 _blurMask = FX.BlurMask.instance(_nuke)
17048 }
17049
17050 function initPass() {
17051 _composite = _this.initClass(NukePass, "Post");
17052 _composite.uniforms = {
17053 resolution: {
17054 type: "v2",
17055 value: new THREE.Vector2(Stage.width * Tests.getDPR(), Stage.height * Tests.getDPR())
17056 },
17057 fTime: {
17058 type: "f",
17059 value: 0
17060 },
17061 tBlurMask: {
17062 type: "t",
17063 value: _blurMask.rt.texture
17064 },
17065 tDust: {
17066 type: "t",
17067 value: Tests.isDustOverlay() ? Utils3D.getTexture("assets/images/vfx/dust-overlay.jpg") : null
17068 },
17069 fDPR: {
17070 type: "f",
17071 value: Tests.getDPR()
17072 },
17073 fUIFade: {
17074 type: "f",
17075 value: 1
17076 },
17077 fTiltShift: {
17078 type: "f",
17079 value: .35
17080 },
17081 fBlurStrength: {
17082 type: "f",
17083 value: .025
17084 },
17085 uColor1: {
17086 type: "c",
17087 value: new THREE.Color(Config.GRADIENT[0])
17088 },
17089 uColor2: {
17090 type: "c",
17091 value: new THREE.Color(Config.GRADIENT[1])
17092 },
17093 uColor3: {
17094 type: "c",
17095 value: new THREE.Color(Config.GRADIENT[2])
17096 },
17097 uColor4: {
17098 type: "c",
17099 value: new THREE.Color(Config.GRADIENT[3])
17100 },
17101 uBGColor: {
17102 type: "c",
17103 value: new THREE.Color("#00000f")
17104 },
17105 fLoaderFade: {
17106 type: "f",
17107 value: 1
17108 },
17109 fTimelineSpread: {
17110 type: "f",
17111 value: Mobile.phone && Stage.width > Stage.height ? .68 : Tests.isSmallTimeline() ? .54 : .42
17112 },
17113 fTimelineProgress: {
17114 type: "f",
17115 value: .72
17116 },
17117 fTimelineMouse: {
17118 type: "v2",
17119 value: new THREE.Vector2
17120 },
17121 fTimelineVelocity: {
17122 type: "f",
17123 value: 0
17124 },
17125 fTimelineTransition: {
17126 type: "f",
17127 value: 1
17128 },
17129 uSectionsCount: {
17130 type: "v3",
17131 value: new THREE.Vector3
17132 }
17133 };
17134 _nuke.add(_composite)
17135 }
17136
17137 function loop(t, dt) {
17138 _composite.set("fTime", dt * .001);
17139 _composite.uniforms.fTimelineMouse.value.x += (Mouse.x / Stage.width - _composite.uniforms.fTimelineMouse.value.x) * .2;
17140 _composite.uniforms.fTimelineMouse.value.y += (1 - Mouse.y / Stage.height - _composite.uniforms.fTimelineMouse.value.y) * .2
17141 }
17142
17143 function addHandlers() {
17144 _this.events.subscribe(HydraEvents.RESIZE, resize);
17145 _this.events.subscribe(ToonamiEvents.LIGHTBOX_OPEN, toLightbox);
17146 _this.events.subscribe(ToonamiEvents.LIGHTBOX_CLOSE, fromLightbox)
17147 }
17148
17149 function resize() {
17150 _composite.uniforms.resolution.value.set(Stage.width * Tests.getDPR(), Stage.height * Tests.getDPR());
17151 _nuke.setSize(Stage.width, Stage.height);
17152 _composite.set("fDPR", Tests.getDPR())
17153 }
17154
17155 function toLightbox() {
17156 _composite.tween("fUIFade", 0, 2e3, "easeInOutSine")
17157 }
17158
17159 function fromLightbox() {
17160 _composite.tween("fUIFade", 1, 2e3, "easeInOutSine")
17161 }
17162 this.render = () => {
17163 if (!_this.isReady) checkReady();
17164 _blurMask.render(Stage, _camera);
17165 _nuke.render()
17166 };
17167
17168 function checkReady() {
17169 if (!_nuke.passes.length) return;
17170 _this.isReady = true;
17171 World.ELEMENT.show()
17172 }
17173 this.updateMouse = active => {};
17174 this.setSections = sections => {
17175 _composite.uniforms.uSectionsCount.value.set(sections[0], sections[1], sections[2])
17176 };
17177 this.updateTimeline = (activeSection, velocity) => {
17178 var direction = velocity < 0 ? -1 : 1;
17179 var value = Utils.range(Math.abs(velocity), 0, 1, 0, 1, true);
17180 value = value * value;
17181 _composite.uniforms.fTimelineVelocity.value += (value * direction - _composite.uniforms.fTimelineVelocity.value) * .1;
17182 var spread = Tests.isSmallTimeline() ? .54 : .42;
17183 if (Mobile.phone && Stage.width > Stage.height) spread = .68;
17184 _composite.set("fTimelineSpread", spread);
17185 var offset = (1 - spread) * .5;
17186 var step = 12 / Stage.height;
17187 var sectionHeight = (activeSection[2] - 1) * step;
17188 var sectionProgress = activeSection[2] == 1 ? 0 : activeSection[1] / (activeSection[2] - 1) * sectionHeight;
17189 var progress = 1 - (activeSection[0] / 3 * spread - .5 * sectionHeight + sectionProgress + offset);
17190 _composite.uniforms.fTimelineProgress.value += (progress - _composite.uniforms.fTimelineProgress.value) * .1
17191 };
17192 this.introSetup = () => {
17193 _composite.set("fTiltShift", .5);
17194 _composite.set("fBlurStrength", .005);
17195 _composite.set("fTimelineTransition", 0)
17196 };
17197 this.introAnimate = () => {
17198 _composite.tween("fBlurStrength", .03, 1e3, "easeInQuart", 15e2, () => {
17199 _composite.tween("fBlurStrength", .005, 2e3, "easeOutQuart", 1e3)
17200 })
17201 };
17202 this.introEnd = () => {
17203 _composite.tween("fTiltShift", .35, 3e3, "easeInOutQuart");
17204 _composite.tween("fBlurStrength", .1, 2e3, "easeInOutQuart", 0, () => {
17205 _composite.tween("fBlurStrength", .025, 2e3, "easeInOutQuart", 0)
17206 });
17207 _composite.tween("fTimelineTransition", 1, 2e3, "easeInOutQuart", 2e3)
17208 };
17209 this.loaded = () => {
17210 _composite.tween("fLoaderFade", 0, Utils.query("skip") ? 1e3 : 2e3, "easeInOutQuart", 700)
17211 }
17212}, "singleton");
17213Class(function Main() {
17214 Inherit(this, MVC);
17215 var _this = this;
17216 (function() {
17217 if (Hydra.LOCAL) Hydra.development(true, ["_jsmd_default", "_jsmd"]);
17218 if (!Device.graphics.webgl) window.location = "fallback.html";
17219 GPU.ready().then(() => {
17220 if (!Device.graphics.webgl || Mobile.iOS.strpos(["ipad 2", "ipad 4", "legacy"]) || GPU.detect("mali-450 mp") || GPU.detect("mali-400 mp") || GPU.BLACKLIST || Mobile.browser == "Browser" || Mobile.os == "Android" && Mobile.browser == "Chrome" && Mobile.browserVersion < 48) window.location = "fallback.html";
17221 init()
17222 })
17223 }());
17224
17225 function init() {
17226 if (Utils.query("playground")) {
17227 AssetLoader.loadAllAssets(function() {
17228 Playground.instance()
17229 });
17230 return
17231 }
17232 Hydra.CDN = Config.CDN;
17233 AssetUtil.PATH = Config.CDN;
17234 Utils3D.PATH = Config.CDN;
17235 Container.instance();
17236 if (Mobile.os && Mobile.os.toLowerCase() == "android") {
17237 __window.bind("touchstart", function() {
17238 document.body.webkitRequestFullScreen();
17239 window.top.postMessage("fullscreen", "*")
17240 })
17241 }
17242 }
17243})
17244window._MINIFIED_ = true;
17245window._BUILT_ = true;