/*
 TweenJS
 Visit http://createjs.com/ for documentation, updates and examples.

 Copyright (c) 2010 gskinner.com, inc.

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the "Software"), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 Platform.js <https://mths.be/platform>
 Copyright 2014-2018 Benjamin Tan <https://bnjmnt4n.now.sh/>
 Copyright 2011-2013 John-David Dalton
 Available under MIT license <https://mths.be/mit>
*/
this.createjs=this.createjs||{};createjs.extend=function(g,b){function c(){this.constructor=g}c.prototype=b.prototype;return g.prototype=new c};this.createjs=this.createjs||{};createjs.promote=function(g,b){var c=g.prototype,f=Object.getPrototypeOf&&Object.getPrototypeOf(c)||c.__proto__;if(f){c[(b+="_")+"constructor"]=f.constructor;for(var a in f)c.hasOwnProperty(a)&&"function"==typeof f[a]&&(c[b+a]=f[a])}return g};this.createjs=this.createjs||{};
createjs.deprecate=function(g,b){return function(){var c="Deprecated property or method '"+b+"'. See docs for info.";console&&(console.warn?console.warn(c):console.log(c));return g&&g.apply(this,arguments)}};this.createjs=this.createjs||{};
(function(){function g(b,g,a){this.type=b;this.currentTarget=this.target=null;this.eventPhase=0;this.bubbles=!!g;this.cancelable=!!a;this.timeStamp=(new Date).getTime();this.removed=this.immediatePropagationStopped=this.propagationStopped=this.defaultPrevented=!1}var b=g.prototype;b.preventDefault=function(){this.defaultPrevented=this.cancelable&&!0};b.stopPropagation=function(){this.propagationStopped=!0};b.stopImmediatePropagation=function(){this.immediatePropagationStopped=this.propagationStopped=
!0};b.remove=function(){this.removed=!0};b.clone=function(){return new g(this.type,this.bubbles,this.cancelable)};b.set=function(b){for(var c in b)this[c]=b[c];return this};b.toString=function(){return"[Event (type="+this.type+")]"};createjs.Event=g})();this.createjs=this.createjs||{};
(function(){function g(){this._captureListeners=this._listeners=null}var b=g.prototype;g.initialize=function(c){c.addEventListener=b.addEventListener;c.on=b.on;c.removeEventListener=c.off=b.removeEventListener;c.removeAllEventListeners=b.removeAllEventListeners;c.hasEventListener=b.hasEventListener;c.dispatchEvent=b.dispatchEvent;c._dispatchEvent=b._dispatchEvent;c.willTrigger=b.willTrigger};b.addEventListener=function(b,g,a){var c=a?this._captureListeners=this._captureListeners||{}:this._listeners=
this._listeners||{};var d=c[b];d&&this.removeEventListener(b,g,a);(d=c[b])?d.push(g):c[b]=[g];return g};b.on=function(b,g,a,e,d,l){g.handleEvent&&(a=a||g,g=g.handleEvent);a=a||this;return this.addEventListener(b,function(b){g.call(a,b,d);e&&b.remove()},l)};b.removeEventListener=function(b,g,a){if(a=a?this._captureListeners:this._listeners){var c=a[b];if(c)for(var d=0,l=c.length;d<l;d++)if(c[d]==g){1==l?delete a[b]:c.splice(d,1);break}}};b.off=b.removeEventListener;b.removeAllEventListeners=function(b){b?
(this._listeners&&delete this._listeners[b],this._captureListeners&&delete this._captureListeners[b]):this._listeners=this._captureListeners=null};b.dispatchEvent=function(b,g,a){if("string"==typeof b){var c=this._listeners;if(!(g||c&&c[b]))return!0;b=new createjs.Event(b,g,a)}else b.target&&b.clone&&(b=b.clone());try{b.target=this}catch(d){}if(b.bubbles&&this.parent){a=this;for(g=[a];a.parent;)g.push(a=a.parent);c=g.length;for(a=c-1;0<=a&&!b.propagationStopped;a--)g[a]._dispatchEvent(b,1+(0==a));
for(a=1;a<c&&!b.propagationStopped;a++)g[a]._dispatchEvent(b,3)}else this._dispatchEvent(b,2);return!b.defaultPrevented};b.hasEventListener=function(b){var c=this._listeners,a=this._captureListeners;return!!(c&&c[b]||a&&a[b])};b.willTrigger=function(b){for(var c=this;c;){if(c.hasEventListener(b))return!0;c=c.parent}return!1};b.toString=function(){return"[EventDispatcher]"};b._dispatchEvent=function(b,g){var a,c,d=2>=g?this._captureListeners:this._listeners;if(b&&d&&(c=d[b.type])&&(a=c.length)){try{b.currentTarget=
this}catch(n){}try{b.eventPhase=g|0}catch(n){}b.removed=!1;c=c.slice();for(d=0;d<a&&!b.immediatePropagationStopped;d++){var l=c[d];l.handleEvent?l.handleEvent(b):l(b);b.removed&&(this.off(b.type,l,1==g),b.removed=!1)}}2===g&&this._dispatchEvent(b,2.1)};createjs.EventDispatcher=g})();this.createjs=this.createjs||{};
(function(){function g(){throw"Ticker cannot be instantiated.";}g.RAF_SYNCHED="synched";g.RAF="raf";g.TIMEOUT="timeout";g.timingMode=null;g.maxDelta=0;g.paused=!1;g.removeEventListener=null;g.removeAllEventListeners=null;g.dispatchEvent=null;g.hasEventListener=null;g._listeners=null;createjs.EventDispatcher.initialize(g);g._addEventListener=g.addEventListener;g.addEventListener=function(){!g._inited&&g.init();return g._addEventListener.apply(g,arguments)};g._inited=!1;g._startTime=0;g._pausedTime=
0;g._ticks=0;g._pausedTicks=0;g._interval=50;g._lastTime=0;g._times=null;g._tickTimes=null;g._timerId=null;g._raf=!0;g._setInterval=function(b){g._interval=b;g._inited&&g._setupTick()};g.setInterval=createjs.deprecate(g._setInterval,"Ticker.setInterval");g._getInterval=function(){return g._interval};g.getInterval=createjs.deprecate(g._getInterval,"Ticker.getInterval");g._setFPS=function(b){g._setInterval(1E3/b)};g.setFPS=createjs.deprecate(g._setFPS,"Ticker.setFPS");g._getFPS=function(){return 1E3/
g._interval};g.getFPS=createjs.deprecate(g._getFPS,"Ticker.getFPS");try{Object.defineProperties(g,{interval:{get:g._getInterval,set:g._setInterval},framerate:{get:g._getFPS,set:g._setFPS}})}catch(f){console.log(f)}g.init=function(){g._inited||(g._inited=!0,g._times=[],g._tickTimes=[],g._startTime=g._getTime(),g._times.push(g._lastTime=0),g.interval=g._interval)};g.reset=function(){if(g._raf){var b=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||
window.msCancelAnimationFrame;b&&b(g._timerId)}else clearTimeout(g._timerId);g.removeAllEventListeners("tick");g._timerId=g._times=g._tickTimes=null;g._startTime=g._lastTime=g._ticks=g._pausedTime=0;g._inited=!1};g.getMeasuredTickTime=function(b){var a=0,c=g._tickTimes;if(!c||1>c.length)return-1;b=Math.min(c.length,b||g._getFPS()|0);for(var d=0;d<b;d++)a+=c[d];return a/b};g.getMeasuredFPS=function(b){var a=g._times;if(!a||2>a.length)return-1;b=Math.min(a.length-1,b||g._getFPS()|0);return 1E3/((a[0]-
a[b])/b)};g.getTime=function(b){return g._startTime?g._getTime()-(b?g._pausedTime:0):-1};g.getEventTime=function(b){return g._startTime?(g._lastTime||g._startTime)-(b?g._pausedTime:0):-1};g.getTicks=function(b){return g._ticks-(b?g._pausedTicks:0)};g._handleSynch=function(){g._timerId=null;g._setupTick();g._getTime()-g._lastTime>=.97*(g._interval-1)&&g._tick()};g._handleRAF=function(){g._timerId=null;g._setupTick();g._tick()};g._handleTimeout=function(){g._timerId=null;g._setupTick();g._tick()};g._setupTick=
function(){if(null==g._timerId){var b=g.timingMode;if(b==g.RAF_SYNCHED||b==g.RAF){var a=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame;if(a){g._timerId=a(b==g.RAF?g._handleRAF:g._handleSynch);g._raf=!0;return}}g._raf=!1;g._timerId=setTimeout(g._handleTimeout,g._interval)}};g._tick=function(){var b=g.paused,a=g._getTime(),c=a-g._lastTime;g._lastTime=a;g._ticks++;b&&(g._pausedTicks++,g._pausedTime+=
c);if(g.hasEventListener("tick")){var d=new createjs.Event("tick"),l=g.maxDelta;d.delta=l&&c>l?l:c;d.paused=b;d.time=a;d.runTime=a-g._pausedTime;g.dispatchEvent(d)}for(g._tickTimes.unshift(g._getTime()-a);100<g._tickTimes.length;)g._tickTimes.pop();for(g._times.unshift(a);100<g._times.length;)g._times.pop()};var b=window,c=b.performance.now||b.performance.mozNow||b.performance.msNow||b.performance.oNow||b.performance.webkitNow;g._getTime=function(){return(c&&c.call(b.performance)||(new Date).getTime())-
g._startTime};createjs.Ticker=g})();this.createjs=this.createjs||{};
(function(){function g(b){this.EventDispatcher_constructor();this.ignoreGlobalPause=!1;this.loop=0;this.bounce=this.reversed=this.useTicks=!1;this.timeScale=1;this.position=this.duration=0;this.rawPosition=-1;this._paused=!0;this._labelList=this._labels=this._parent=this._prev=this._next=null;b&&(this.useTicks=!!b.useTicks,this.ignoreGlobalPause=!!b.ignoreGlobalPause,this.loop=!0===b.loop?-1:b.loop||0,this.reversed=!!b.reversed,this.bounce=!!b.bounce,this.timeScale=b.timeScale||1,b.onChange&&this.addEventListener("change",
b.onChange),b.onComplete&&this.addEventListener("complete",b.onComplete))}var b=createjs.extend(g,createjs.EventDispatcher);b._setPaused=function(b){createjs.Tween._register(this,b);return this};b.setPaused=createjs.deprecate(b._setPaused,"AbstractTween.setPaused");b._getPaused=function(){return this._paused};b.getPaused=createjs.deprecate(b._getPaused,"AbstactTween.getPaused");b._getCurrentLabel=function(b){var c=this.getLabels();null==b&&(b=this.position);for(var a=0,e=c.length;a<e&&!(b<c[a].position);a++);
return 0===a?null:c[a-1].label};b.getCurrentLabel=createjs.deprecate(b._getCurrentLabel,"AbstractTween.getCurrentLabel");try{Object.defineProperties(b,{paused:{set:b._setPaused,get:b._getPaused},currentLabel:{get:b._getCurrentLabel}})}catch(c){}b.advance=function(b,g){this.setPosition(this.rawPosition+b*this.timeScale,g)};b.setPosition=function(b,g,a,e){var d=this.duration,c=this.loop,n=this.rawPosition,k=0;0>b&&(b=0);if(0===d){var p=!0;if(-1!==n)return p}else{var r=b/d|0;k=b-r*d;(p=-1!==c&&b>=c*
d+d)&&(b=(k=d)*(r=c)+d);if(b===n)return p;!this.reversed!==!(this.bounce&&r%2)&&(k=d-k)}this.position=k;this.rawPosition=b;this._updatePosition(a,p);p&&(this.paused=!0);e&&e(this);g||this._runActions(n,b,a,!a&&-1===n);this.dispatchEvent("change");p&&this.dispatchEvent("complete")};b.calculatePosition=function(b){var c=this.duration,a=this.loop,e=0;if(0===c)return 0;-1!==a&&b>=a*c+c?(b=c,e=a):0>b?b=0:(e=b/c|0,b-=e*c);return!this.reversed!==!(this.bounce&&e%2)?c-b:b};b.getLabels=function(){var b=this._labelList;
if(!b){b=this._labelList=[];var g=this._labels,a;for(a in g)b.push({label:a,position:g[a]});b.sort(function(a,d){return a.position-d.position})}return b};b.setLabels=function(b){this._labels=b;this._labelList=null};b.addLabel=function(b,g){this._labels||(this._labels={});this._labels[b]=g;var a=this._labelList;if(a){for(var c=0,d=a.length;c<d&&!(g<a[c].position);c++);a.splice(c,0,{label:b,position:g})}};b.gotoAndPlay=function(b){this.paused=!1;this._goto(b)};b.gotoAndStop=function(b){this.paused=
!0;this._goto(b)};b.resolve=function(b){var c=Number(b);isNaN(c)&&(c=this._labels&&this._labels[b]);return c};b.toString=function(){return"[AbstractTween]"};b.clone=function(){throw"AbstractTween can not be cloned.";};b._init=function(b){b&&b.paused||(this.paused=!1);b&&null!=b.position&&this.setPosition(b.position)};b._updatePosition=function(b,g){};b._goto=function(b){b=this.resolve(b);null!=b&&this.setPosition(b,!1,!0)};b._runActions=function(b,g,a,e){if(this._actionHead||this.tweens){var d=this.duration,
c=this.reversed,n=this.bounce,k=this.loop,p,r,h;if(0===d){var m=p=r=h=0;c=n=!1}else m=b/d|0,p=g/d|0,r=b-m*d,h=g-p*d;-1!==k&&(p>k&&(h=d,p=k),m>k&&(r=d,m=k));if(a)return this._runActionsRange(h,h,a,e);if(m!==p||r!==h||a||e){-1===m&&(m=r=0);b=b<=g;g=m;do{k=g===m?r:b?0:d;var q=g===p?h:b?d:0;!c!==!(n&&g%2)&&(k=d-k,q=d-q);if((!n||g===m||k!==q)&&this._runActionsRange(k,q,a,e||g!==m&&!n))return!0;e=!1}while(b&&++g<=p||!b&&--g>=p)}}};b._runActionsRange=function(b,g,a,e){};createjs.AbstractTween=createjs.promote(g,
"EventDispatcher")})();this.createjs=this.createjs||{};
(function(){function g(a,c){this.AbstractTween_constructor(c);this.pluginData=null;this.target=a;this.passive=!1;this._stepTail=this._stepHead=new b(null,0,0,{},null,!0);this._stepPosition=0;this._injected=this._pluginIds=this._plugins=this._actionTail=this._actionHead=null;c&&(this.pluginData=c.pluginData,c.override&&g.removeTweens(a));this.pluginData||(this.pluginData={});this._init(c)}function b(a,b,d,c,g,k){this.next=null;this.prev=a;this.t=b;this.d=d;this.props=c;this.ease=g;this.passive=k;this.index=
a?a.index+1:0}function c(a,b,d,c,g){this.next=null;this.prev=a;this.t=b;this.d=0;this.scope=d;this.funct=c;this.params=g}var f=createjs.extend(g,createjs.AbstractTween);g.IGNORE={};g._tweens=[];g._plugins=null;g._tweenHead=null;g._tweenTail=null;g.get=function(a,b){return new g(a,b)};g.tick=function(a,b){for(var d=g._tweenHead;d;){var c=d._next;b&&!d.ignoreGlobalPause||d._paused||d.advance(d.useTicks?1:a);d=c}};g.handleEvent=function(a){"tick"===a.type&&this.tick(a.delta,a.paused)};g.removeTweens=
function(a){if(a.tweenjs_count){for(var b=g._tweenHead;b;){var d=b._next;b.target===a&&g._register(b,!0);b=d}a.tweenjs_count=0}};g.removeAllTweens=function(){for(var a=g._tweenHead;a;){var b=a._next;a._paused=!0;a.target&&(a.target.tweenjs_count=0);a._next=a._prev=null;a=b}g._tweenHead=g._tweenTail=null};g.hasActiveTweens=function(a){return a?!!a.tweenjs_count:!!g._tweenHead};g._installPlugin=function(a){for(var b=a.priority=a.priority||0,d=g._plugins=g._plugins||[],c=0,n=d.length;c<n&&!(b<d[c].priority);c++);
d.splice(c,0,a)};g._register=function(a,b){var d=a.target;if(!b&&a._paused)d&&(d.tweenjs_count=d.tweenjs_count?d.tweenjs_count+1:1),(d=g._tweenTail)?(g._tweenTail=d._next=a,a._prev=d):g._tweenHead=g._tweenTail=a,!g._inited&&createjs.Ticker&&(createjs.Ticker.addEventListener("tick",g),g._inited=!0);else if(b&&!a._paused){d&&d.tweenjs_count--;d=a._next;var c=a._prev;d?d._prev=c:g._tweenTail=c;c?c._next=d:g._tweenHead=d;a._next=a._prev=null}a._paused=b};f.wait=function(a,b){0<a&&this._addStep(+a,this._stepTail.props,
null,b);return this};f.to=function(a,b,d){if(null==b||0>b)b=0;b=this._addStep(+b,null,d);this._appendProps(a,b);return this};f.label=function(a){this.addLabel(a,this.duration);return this};f.call=function(a,b,d){return this._addAction(d||this.target,a,b||[this])};f.set=function(a,b){return this._addAction(b||this.target,this._set,[a])};f.play=function(a){return this._addAction(a||this,this._set,[{paused:!1}])};f.pause=function(a){return this._addAction(a||this,this._set,[{paused:!0}])};f.w=f.wait;
f.t=f.to;f.c=f.call;f.s=f.set;f.toString=function(){return"[Tween]"};f.clone=function(){throw"Tween can not be cloned.";};f._addPlugin=function(a){var b=this._pluginIds||(this._pluginIds={}),d=a.ID;if(d&&!b[d]){b[d]=!0;b=this._plugins||(this._plugins=[]);d=a.priority||0;for(var c=0,g=b.length;c<g;c++)if(d<b[c].priority){b.splice(c,0,a);return}b.push(a)}};f._updatePosition=function(a,b){var d=this._stepHead.next,c=this.position,g=this.duration;if(this.target&&d){for(var e=d.next;e&&e.t<=c;)d=d.next,
e=d.next;this._updateTargetProps(d,b?0===g?1:c/g:(c-d.t)/d.d,b)}this._stepPosition=d?c-d.t:0};f._updateTargetProps=function(a,b,d){if(!(this.passive=!!a.passive)){var c,e=a.prev.props,k=a.props;if(c=a.ease)b=c(b,0,1,1);c=this._plugins;var p;a:for(p in e){var r=e[p];var h=k[p];r=r!==h&&"number"===typeof r?r+(h-r)*b:1<=b?h:r;if(c){h=0;for(var m=c.length;h<m;h++){var q=c[h].change(this,a,p,r,b,d);if(q===g.IGNORE)continue a;void 0!==q&&(r=q)}}this.target[p]=r}}};f._runActionsRange=function(a,b,d,c){var g=
(d=a>b)?this._actionTail:this._actionHead,e=b,p=a;d&&(e=a,p=b);for(var r=this.position;g;){var h=g.t;if(h===b||h>p&&h<e||c&&h===a)if(g.funct.apply(g.scope,g.params),r!==this.position)return!0;g=d?g.prev:g.next}};f._appendProps=function(a,b,d){var c=this._stepHead.props,e=this.target,k=g._plugins,p,r,h=b.prev,m=h.props,q=b.props||(b.props=this._cloneProps(m)),f={};for(p in a)if(a.hasOwnProperty(p)&&(f[p]=q[p]=a[p],void 0===c[p])){var u=void 0;if(k)for(r=k.length-1;0<=r;r--){var w=k[r].init(this,p,
u);void 0!==w&&(u=w);if(u===g.IGNORE){delete q[p];delete f[p];break}}u!==g.IGNORE&&(void 0===u&&(u=e[p]),m[p]=void 0===u?null:u)}for(p in f){var v;for(a=h;(v=a)&&(a=v.prev);)if(a.props!==v.props){if(void 0!==a.props[p])break;a.props[p]=m[p]}}if(!1!==d&&(k=this._plugins))for(r=k.length-1;0<=r;r--)k[r].step(this,b,f);if(d=this._injected)this._injected=null,this._appendProps(d,b,!1)};f._injectProp=function(a,b){(this._injected||(this._injected={}))[a]=b};f._addStep=function(a,c,d,g){c=new b(this._stepTail,
this.duration,a,c,d,g||!1);this.duration+=a;return this._stepTail=this._stepTail.next=c};f._addAction=function(a,b,d){a=new c(this._actionTail,this.duration,a,b,d);this._actionTail?this._actionTail.next=a:this._actionHead=a;this._actionTail=a;return this};f._set=function(a){for(var b in a)this[b]=a[b]};f._cloneProps=function(a){var b={},d;for(d in a)b[d]=a[d];return b};createjs.Tween=createjs.promote(g,"AbstractTween")})();this.createjs=this.createjs||{};
(function(){function g(b){if(b instanceof Array||null==b&&1<arguments.length){var c=b;var a=arguments[1];b=arguments[2]}else b&&(c=b.tweens,a=b.labels);this.AbstractTween_constructor(b);this.tweens=[];c&&this.addTween.apply(this,c);this.setLabels(a);this._init(b)}var b=createjs.extend(g,createjs.AbstractTween);b.addTween=function(b){b._parent&&b._parent.removeTween(b);var c=arguments.length;if(1<c){for(var a=0;a<c;a++)this.addTween(arguments[a]);return arguments[c-1]}if(0===c)return null;this.tweens.push(b);
b._parent=this;b.paused=!0;c=b.duration;0<b.loop&&(c*=b.loop+1);c>this.duration&&(this.duration=c);0<=this.rawPosition&&b.setPosition(this.rawPosition);return b};b.removeTween=function(b){var c=arguments.length;if(1<c){for(var a=!0,g=0;g<c;g++)a=a&&this.removeTween(arguments[g]);return a}if(0===c)return!0;c=this.tweens;for(g=c.length;g--;)if(c[g]===b)return c.splice(g,1),b._parent=null,b.duration>=this.duration&&this.updateDuration(),!0;return!1};b.updateDuration=function(){for(var b=this.duration=
0,g=this.tweens.length;b<g;b++){var a=this.tweens[b],e=a.duration;0<a.loop&&(e*=a.loop+1);e>this.duration&&(this.duration=e)}};b.toString=function(){return"[Timeline]"};b.clone=function(){throw"Timeline can not be cloned.";};b._updatePosition=function(b,g){for(var a=this.position,c=0,d=this.tweens.length;c<d;c++)this.tweens[c].setPosition(a,!0,b)};b._runActionsRange=function(b,g,a,e){for(var d=this.position,c=0,n=this.tweens.length;c<n;c++)if(this.tweens[c]._runActions(b,g,a,e),d!==this.position)return!0};
createjs.Timeline=createjs.promote(g,"AbstractTween")})();this.createjs=this.createjs||{};
(function(){function g(){throw"Ease cannot be instantiated.";}g.linear=function(b){return b};g.none=g.linear;g.get=function(b){-1>b?b=-1:1<b&&(b=1);return function(c){return 0==b?c:0>b?c*(c*-b+1+b):c*((2-c)*b+(1-b))}};g.getPowIn=function(b){return function(c){return Math.pow(c,b)}};g.getPowOut=function(b){return function(c){return 1-Math.pow(1-c,b)}};g.getPowInOut=function(b){return function(c){return 1>(c*=2)?.5*Math.pow(c,b):1-.5*Math.abs(Math.pow(2-c,b))}};g.quadIn=g.getPowIn(2);g.quadOut=g.getPowOut(2);
g.quadInOut=g.getPowInOut(2);g.cubicIn=g.getPowIn(3);g.cubicOut=g.getPowOut(3);g.cubicInOut=g.getPowInOut(3);g.quartIn=g.getPowIn(4);g.quartOut=g.getPowOut(4);g.quartInOut=g.getPowInOut(4);g.quintIn=g.getPowIn(5);g.quintOut=g.getPowOut(5);g.quintInOut=g.getPowInOut(5);g.sineIn=function(b){return 1-Math.cos(b*Math.PI/2)};g.sineOut=function(b){return Math.sin(b*Math.PI/2)};g.sineInOut=function(b){return-.5*(Math.cos(Math.PI*b)-1)};g.getBackIn=function(b){return function(c){return c*c*((b+1)*c-b)}};
g.backIn=g.getBackIn(1.7);g.getBackOut=function(b){return function(c){return--c*c*((b+1)*c+b)+1}};g.backOut=g.getBackOut(1.7);g.getBackInOut=function(b){b*=1.525;return function(c){return 1>(c*=2)?.5*c*c*((b+1)*c-b):.5*((c-=2)*c*((b+1)*c+b)+2)}};g.backInOut=g.getBackInOut(1.7);g.circIn=function(b){return-(Math.sqrt(1-b*b)-1)};g.circOut=function(b){return Math.sqrt(1- --b*b)};g.circInOut=function(b){return 1>(b*=2)?-.5*(Math.sqrt(1-b*b)-1):.5*(Math.sqrt(1-(b-=2)*b)+1)};g.bounceIn=function(b){return 1-
g.bounceOut(1-b)};g.bounceOut=function(b){return b<1/2.75?7.5625*b*b:b<2/2.75?7.5625*(b-=1.5/2.75)*b+.75:b<2.5/2.75?7.5625*(b-=2.25/2.75)*b+.9375:7.5625*(b-=2.625/2.75)*b+.984375};g.bounceInOut=function(b){return.5>b?.5*g.bounceIn(2*b):.5*g.bounceOut(2*b-1)+.5};g.getElasticIn=function(b,c){var g=2*Math.PI;return function(a){if(0==a||1==a)return a;var e=c/g*Math.asin(1/b);return-(b*Math.pow(2,10*--a)*Math.sin((a-e)*g/c))}};g.elasticIn=g.getElasticIn(1,.3);g.getElasticOut=function(b,c){var g=2*Math.PI;
return function(a){return 0==a||1==a?a:b*Math.pow(2,-10*a)*Math.sin((a-c/g*Math.asin(1/b))*g/c)+1}};g.elasticOut=g.getElasticOut(1,.3);g.getElasticInOut=function(b,c){var g=2*Math.PI;return function(a){var e=c/g*Math.asin(1/b);return 1>(a*=2)?-.5*b*Math.pow(2,10*--a)*Math.sin((a-e)*g/c):b*Math.pow(2,-10*--a)*Math.sin((a-e)*g/c)*.5+1}};g.elasticInOut=g.getElasticInOut(1,.3*1.5);createjs.Ease=g})();this.createjs=this.createjs||{};
(function(){function g(){throw"MotionGuidePlugin cannot be instantiated.";}g.priority=0;g.ID="MotionGuide";g.install=function(){createjs.Tween._installPlugin(g);return createjs.Tween.IGNORE};g.init=function(b,c,f){"guide"==c&&b._addPlugin(g)};g.step=function(b,c,f){for(var a in f)if("guide"===a){var e=c.props.guide,d=g._solveGuideData(f.guide,e);e.valid=!d;var l=e.endData;b._injectProp("x",l.x);b._injectProp("y",l.y);if(d||!e.orient)break;e.startOffsetRot=(void 0===c.prev.props.rotation?b.target.rotation||
0:c.prev.props.rotation)-e.startData.rotation;if("fixed"==e.orient)e.endAbsRot=l.rotation+e.startOffsetRot,e.deltaRotation=0;else{d=void 0===f.rotation?b.target.rotation||0:f.rotation;l=d-e.endData.rotation-e.startOffsetRot;var n=l%360;e.endAbsRot=d;switch(e.orient){case "auto":e.deltaRotation=l;break;case "cw":e.deltaRotation=(n+360)%360+360*Math.abs(l/360|0);break;case "ccw":e.deltaRotation=(n-360)%360+-360*Math.abs(l/360|0)}}b._injectProp("rotation",e.endAbsRot)}};g.change=function(b,c,f,a,e,d){if((a=
c.props.guide)&&c.props!==c.prev.props&&a!==c.prev.props.guide){if("guide"===f&&!a.valid||"x"==f||"y"==f||"rotation"===f&&a.orient)return createjs.Tween.IGNORE;g._ratioToPositionData(e,a,b.target)}};g.debug=function(b,c,f){b=b.guide||b;var a=g._findPathProblems(b);a&&console.error("MotionGuidePlugin Error found: \n"+a);if(!c)return a;var e,d=b.path,l=d.length;c.save();c.lineCap="round";c.lineJoin="miter";c.beginPath();c.moveTo(d[0],d[1]);for(e=2;e<l;e+=4)c.quadraticCurveTo(d[e],d[e+1],d[e+2],d[e+
3]);c.strokeStyle="black";c.lineWidth=4.5;c.stroke();c.strokeStyle="white";c.lineWidth=3;c.stroke();c.closePath();d=f.length;if(f&&d){l={};var n={};g._solveGuideData(b,l);for(e=0;e<d;e++)l.orient="fixed",g._ratioToPositionData(f[e],l,n),c.beginPath(),c.moveTo(n.x,n.y),c.lineTo(n.x+9*Math.cos(.0174533*n.rotation),n.y+9*Math.sin(.0174533*n.rotation)),c.strokeStyle="black",c.lineWidth=4.5,c.stroke(),c.strokeStyle="red",c.lineWidth=3,c.stroke(),c.closePath()}c.restore();return a};g._solveGuideData=function(b,
c){var f;if(f=g.debug(b))return f;var a=c.path=b.path;c.orient=b.orient;c.subLines=[];c.totalLength=0;c.startOffsetRot=0;c.deltaRotation=0;c.startData={ratio:0};c.endData={ratio:1};c.animSpan=1;var e=a.length,d,l={};var n=a[0];var k=a[1];for(f=2;f<e;f+=4){var p=a[f];var r=a[f+1];var h=a[f+2];var m=a[f+3];var q={weightings:[],estLength:0,portion:0},t=n;var u=k;for(d=1;10>=d;d++)g._getParamsForCurve(n,k,p,r,h,m,d/10,!1,l),t=l.x-t,u=l.y-u,u=Math.sqrt(t*t+u*u),q.weightings.push(u),q.estLength+=u,t=l.x,
u=l.y;c.totalLength+=q.estLength;for(d=0;10>d;d++)u=q.estLength,q.weightings[d]/=u;c.subLines.push(q);n=h;k=m}u=c.totalLength;a=c.subLines.length;for(f=0;f<a;f++)c.subLines[f].portion=c.subLines[f].estLength/u;f=isNaN(b.start)?0:b.start;a=isNaN(b.end)?1:b.end;g._ratioToPositionData(f,c,c.startData);g._ratioToPositionData(a,c,c.endData);c.startData.ratio=f;c.endData.ratio=a;c.animSpan=c.endData.ratio-c.startData.ratio};g._ratioToPositionData=function(b,c,f){var a=c.subLines,e,d=0,l=b*c.animSpan+c.startData.ratio;
var n=a.length;for(e=0;e<n;e++){var k=a[e].portion;if(d+k>=l){var p=e;break}d+=k}void 0===p&&(p=n-1,d-=k);a=a[p].weightings;var r=k;n=a.length;for(e=0;e<n;e++){k=a[e]*r;if(d+k>=l)break;d+=k}p=4*p+2;n=c.path;g._getParamsForCurve(n[p-2],n[p-1],n[p],n[p+1],n[p+2],n[p+3],e/10+(l-d)/k*.1,c.orient,f);c.orient&&(f.rotation=.99999<=b&&1.00001>=b&&void 0!==c.endAbsRot?c.endAbsRot:f.rotation+(c.startOffsetRot+b*c.deltaRotation));return f};g._getParamsForCurve=function(b,c,g,a,e,d,l,n,k){var p=1-l;k.x=p*p*b+
2*p*l*g+l*l*e;k.y=p*p*c+2*p*l*a+l*l*d;n&&(k.rotation=57.2957795*Math.atan2((a-c)*p+(d-a)*l,(g-b)*p+(e-g)*l))};g._findPathProblems=function(b){var c=b.path,g=c&&c.length||0;if(6>g||(g-2)%4)return"\tCannot parse 'path' array due to invalid number of entries in path. There should be an odd number of points, at least 3 points, and 2 entries per point (x & y). See 'CanvasRenderingContext2D.quadraticCurveTo' for details as 'path' models a quadratic bezier.\n\n"+("Only [ "+g+" ] values found. Expected: "+
Math.max(4*Math.ceil((g-2)/4)+2,6));for(var a=0;a<g;a++)if(isNaN(c[a]))return"All data in path array must be numeric";c=b.start;if(isNaN(c)&&void 0!==c)return"'start' out of bounds. Expected 0 to 1, got: "+c;c=b.end;if(isNaN(c)&&void 0!==c)return"'end' out of bounds. Expected 0 to 1, got: "+c;if((b=b.orient)&&"fixed"!=b&&"auto"!=b&&"cw"!=b&&"ccw"!=b)return'Invalid orientation value. Expected ["fixed", "auto", "cw", "ccw", undefined], got: '+b};createjs.MotionGuidePlugin=g})();
this.createjs=this.createjs||{};(function(){var g=createjs.TweenJS=createjs.TweenJS||{};g.version="1.0.0";g.buildDate="Thu, 14 Sep 2017 19:47:47 GMT"})();
(function(){function g(a){a=String(a);return a.charAt(0).toUpperCase()+a.slice(1)}function b(a,b){var d=-1,h=a?a.length:0;if("number"==typeof h&&-1<h&&h<=m)for(;++d<h;)b(a[d],d,a);else f(a,b)}function c(a){a=String(a).replace(/^ +| +$/g,"");return/^(?:webOS|i(?:OS|P))/.test(a)?a:g(a)}function f(a,b){for(var d in a)t.call(a,d)&&b(a[d],d,a)}function a(a){return null==a?g(a):u.call(a).slice(8,-1)}function e(a,b){var d=null!=a?typeof a[b]:"number";return!/^(?:boolean|number|string|undefined)$/.test(d)&&
("object"==d?!!a[b]:!0)}function d(a){return String(a).replace(/([ -])(?!$)/g,"$1?")}function l(a,d){var h=null;b(a,function(b,c){h=d(h,b,c,a)});return h}function n(b){function h(a){return l(a,function(a,h){var g=h.pattern||d(h);!a&&(a=RegExp("\\b"+g+" *\\d+[.\\w_]*","i").exec(b)||RegExp("\\b"+g+" *\\w+-[\\w]*","i").exec(b)||RegExp("\\b"+g+"(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)","i").exec(b))&&((a=String(h.label&&!RegExp(g,"i").test(h.label)?h.label:a).split("/"))[1]&&!/[\d.]+/.test(a[0])&&(a[0]+=
" "+a[1]),h=h.label||h,a=c(a[0].replace(RegExp(g,"i"),h).replace(RegExp("; *(?:"+h+"[_-])?","i")," ").replace(RegExp("("+h+")[-_.]?(\\w)","i"),"$1 $2")));return a})}function g(a){return l(a,function(a,d){return a||(RegExp(d+"(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)","i").exec(b)||0)[1]||null})}var m=p,k=b&&"object"==typeof b&&"String"!=a(b);k&&(m=b,b=null);var r=m.navigator||{},t=r.userAgent||"";b||(b=t);var w=k?!!r.likeChrome:/\bChrome\b/.test(b)&&!/internal|\n/i.test(u.toString()),
v=k?"Object":"ScriptBridgingProxyObject",Q=k?"Object":"Environment",H=k&&m.java?"JavaPackage":a(m.java),E=k?"Object":"RuntimeObject";Q=(H=/\bJava/.test(H)&&m.java)&&a(m.environment)==Q;var I=H?"a":"\u03b1",A=H?"b":"\u03b2",N=m.document||{},L=m.operamini||m.opera,W=q.test(W=k&&L?L["[[Class]]"]:a(L))?W:L=null,y,J=b;k=[];var V=null,U=b==t;t=U&&L&&"function"==typeof L.version&&L.version();var R=function(a){return l(a,function(a,h){return a||RegExp("\\b"+(h.pattern||d(h))+"\\b","i").exec(b)&&(h.label||
h)})}([{label:"EdgeHTML",pattern:"Edge"},"Trident",{label:"WebKit",pattern:"AppleWebKit"},"iCab","Presto","NetFront","Tasman","KHTML","Gecko"]),G=function(a){return l(a,function(a,h){return a||RegExp("\\b"+(h.pattern||d(h))+"\\b","i").exec(b)&&(h.label||h)})}(["Adobe AIR","Arora","Avant Browser","Breach","Camino","Electron","Epiphany","Fennec","Flock","Galeon","GreenBrowser","iCab","Iceweasel","K-Meleon","Konqueror","Lunascape","Maxthon",{label:"Microsoft Edge",pattern:"Edge"},"Midori","Nook Browser",
"PaleMoon","PhantomJS","Raven","Rekonq","RockMelt",{label:"Samsung Internet",pattern:"SamsungBrowser"},"SeaMonkey",{label:"Silk",pattern:"(?:Cloud9|Silk-Accelerated)"},"Sleipnir","SlimBrowser",{label:"SRWare Iron",pattern:"Iron"},"Sunrise","Swiftfox","Waterfox","WebPositive","Opera Mini",{label:"Opera Mini",pattern:"OPiOS"},"Opera",{label:"Opera",pattern:"OPR"},"Chrome",{label:"Chrome Mobile",pattern:"(?:CriOS|CrMo)"},{label:"Firefox",pattern:"(?:Firefox|Minefield)"},{label:"Firefox for iOS",pattern:"FxiOS"},
{label:"IE",pattern:"IEMobile"},{label:"IE",pattern:"MSIE"},"Safari"]),O=h([{label:"BlackBerry",pattern:"BB10"},"BlackBerry",{label:"Galaxy S",pattern:"GT-I9000"},{label:"Galaxy S2",pattern:"GT-I9100"},{label:"Galaxy S3",pattern:"GT-I9300"},{label:"Galaxy S4",pattern:"GT-I9500"},{label:"Galaxy S5",pattern:"SM-G900"},{label:"Galaxy S6",pattern:"SM-G920"},{label:"Galaxy S6 Edge",pattern:"SM-G925"},{label:"Galaxy S7",pattern:"SM-G930"},{label:"Galaxy S7 Edge",pattern:"SM-G935"},"Google TV","Lumia","iPad",
"iPod","iPhone","Kindle",{label:"Kindle Fire",pattern:"(?:Cloud9|Silk-Accelerated)"},"Nexus","Nook","PlayBook","PlayStation Vita","PlayStation","TouchPad","Transformer",{label:"Wii U",pattern:"WiiU"},"Wii","Xbox One",{label:"Xbox 360",pattern:"Xbox"},"Xoom"]),T=function(a){return l(a,function(a,h,c){return a||(h[O]||h[/^[a-z]+(?: +[a-z]+\b)*/i.exec(O)]||RegExp("\\b"+d(c)+"(?:\\b|\\w*\\d)","i").exec(b))&&c})}({Apple:{iPad:1,iPhone:1,iPod:1},Archos:{},Amazon:{Kindle:1,"Kindle Fire":1},Asus:{Transformer:1},
"Barnes & Noble":{Nook:1},BlackBerry:{PlayBook:1},Google:{"Google TV":1,Nexus:1},HP:{TouchPad:1},HTC:{},LG:{},Microsoft:{Xbox:1,"Xbox One":1},Motorola:{Xoom:1},Nintendo:{"Wii U":1,Wii:1},Nokia:{Lumia:1},Samsung:{"Galaxy S":1,"Galaxy S2":1,"Galaxy S3":1,"Galaxy S4":1},Sony:{PlayStation:1,"PlayStation Vita":1}}),M=function(a){return l(a,function(a,h){var g=h.pattern||d(h);if(!a&&(a=RegExp("\\b"+g+"(?:/[\\d.]+|[ \\w.]*)","i").exec(b))){var m=a,e=h.label||h,k={"10.0":"10","6.4":"10 Technical Preview",
"6.3":"8.1","6.2":"8","6.1":"Server 2008 R2 / 7","6.0":"Server 2008 / Vista","5.2":"Server 2003 / XP 64-bit","5.1":"XP","5.01":"2000 SP1","5.0":"2000","4.0":"NT","4.90":"ME"};g&&e&&/^Win/i.test(m)&&!/^Windows Phone /i.test(m)&&(k=k[/[\d.]+$/.exec(m)])&&(m="Windows "+k);m=String(m);g&&e&&(m=m.replace(RegExp(g,"i"),e));a=m=c(m.replace(/ ce$/i," CE").replace(/\bhpw/i,"web").replace(/\bMacintosh\b/,"Mac OS").replace(/_PowerPC\b/i," OS").replace(/\b(OS X) [^ \d]+/i,"$1").replace(/\bMac (OS X)\b/,"$1").replace(/\/(\d)/,
" $1").replace(/_/g,".").replace(/(?: BePC|[ .]*fc[ \d.]+)$/i,"").replace(/\bx86\.64\b/gi,"x86_64").replace(/\b(Windows Phone) OS\b/,"$1").replace(/\b(Chrome OS \w+) [\d.]+\b/,"$1").split(" on ")[0])}return a})}(["Windows Phone","Android","CentOS",{label:"Chrome OS",pattern:"CrOS"},"Debian","Fedora","FreeBSD","Gentoo","Haiku","Kubuntu","Linux Mint","OpenBSD","Red Hat","SuSE","Ubuntu","Xubuntu","Cygwin","Symbian OS","hpwOS","webOS ","webOS","Tablet OS","Tizen","Linux","Mac OS X","Macintosh","Mac",
"Windows 98;","Windows "]);R&&(R=[R]);T&&!O&&(O=h([T]));if(y=/\bGoogle TV\b/.exec(O))O=y[0];/\bSimulator\b/i.test(b)&&(O=(O?O+" ":"")+"Simulator");"Opera Mini"==G&&/\bOPiOS\b/.test(b)&&k.push("running in Turbo/Uncompressed mode");"IE"==G&&/\blike iPhone OS\b/.test(b)?(y=n(b.replace(/like iPhone OS/,"")),T=y.manufacturer,O=y.product):/^iP/.test(O)?(G||(G="Safari"),M="iOS"+((y=/ OS ([\d_]+)/i.exec(b))?" "+y[1].replace(/_/g,"."):"")):"Konqueror"!=G||/buntu/i.test(M)?T&&"Google"!=T&&(/Chrome/.test(G)&&
!/\bMobile Safari\b/i.test(b)||/\bVita\b/.test(O))||/\bAndroid\b/.test(M)&&/^Chrome/.test(G)&&/\bVersion\//i.test(b)?(G="Android Browser",M=/\bAndroid\b/.test(M)?M:"Android"):"Silk"==G?(/\bMobi/i.test(b)||(M="Android",k.unshift("desktop mode")),/Accelerated *= *true/i.test(b)&&k.unshift("accelerated")):"PaleMoon"==G&&(y=/\bFirefox\/([\d.]+)\b/.exec(b))?k.push("identifying as Firefox "+y[1]):"Firefox"==G&&(y=/\b(Mobile|Tablet|TV)\b/i.exec(b))?(M||(M="Firefox OS"),O||(O=y[1])):!G||(y=!/\bMinefield\b/i.test(b)&&
/\b(?:Firefox|Safari)\b/.exec(G))?(G&&!O&&/[\/,]|^[^(]+?\)/.test(b.slice(b.indexOf(y+"/")+8))&&(G=null),(y=O||T||M)&&(O||T||/\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(M))&&(G=/[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(M)?M:y)+" Browser")):"Electron"==G&&(y=(/\bChrome\/([\d.]+)\b/.exec(b)||0)[1])&&k.push("Chromium "+y):M="Kubuntu";t||(t=g(["(?:Cloud9|CriOS|CrMo|Edge|FxiOS|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$))","Version",d(G),"(?:Firefox|Minefield|NetFront)"]));
if(y="iCab"==R&&3<parseFloat(t)&&"WebKit"||/\bOpera\b/.test(G)&&(/\bOPR\b/.test(b)?"Blink":"Presto")||/\b(?:Midori|Nook|Safari)\b/i.test(b)&&!/^(?:Trident|EdgeHTML)$/.test(R)&&"WebKit"||!R&&/\bMSIE\b/i.test(b)&&("Mac OS"==M?"Tasman":"Trident")||"WebKit"==R&&/\bPlayStation\b(?! Vita\b)/i.test(G)&&"NetFront")R=[y];"IE"==G&&(y=(/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(b)||0)[1])?(G+=" Mobile",M="Windows Phone "+(/\+$/.test(y)?y:y+".x"),k.unshift("desktop mode")):/\bWPDesktop\b/i.test(b)?(G="IE Mobile",M="Windows Phone 8.x",
k.unshift("desktop mode"),t||(t=(/\brv:([\d.]+)/.exec(b)||0)[1])):"IE"!=G&&"Trident"==R&&(y=/\brv:([\d.]+)/.exec(b))&&(G&&k.push("identifying as "+G+(t?" "+t:"")),G="IE",t=y[1]);if(U){if(e(m,"global"))if(H&&(y=H.lang.System,J=y.getProperty("os.arch"),M=M||y.getProperty("os.name")+" "+y.getProperty("os.version")),Q){try{t=m.require("ringo/engine").version.join("."),G="RingoJS"}catch(Z){(y=m.system)&&y.global.system==m.system&&(G="Narwhal",M||(M=y[0].os||null))}G||(G="Rhino")}else"object"==typeof m.process&&
!m.process.browser&&(y=m.process)&&("object"==typeof y.versions&&("string"==typeof y.versions.electron?(k.push("Node "+y.versions.node),G="Electron",t=y.versions.electron):"string"==typeof y.versions.nw&&(k.push("Chromium "+t,"Node "+y.versions.node),G="NW.js",t=y.versions.nw)),G||(G="Node.js",J=y.arch,M=y.platform,t=(t=/[\d.]+/.exec(y.version))?t[0]:null));else a(y=m.runtime)==v?(G="Adobe AIR",M=y.flash.system.Capabilities.os):a(y=m.phantom)==E?(G="PhantomJS",t=(y=y.version||null)&&y.major+"."+y.minor+
"."+y.patch):"number"==typeof N.documentMode&&(y=/\bTrident\/(\d+)/i.exec(b))?(t=[t,N.documentMode],(y=+y[1]+4)!=t[1]&&(k.push("IE "+t[1]+" mode"),R&&(R[1]=""),t[1]=y),t="IE"==G?String(t[1].toFixed(1)):t[0]):"number"==typeof N.documentMode&&/^(?:Chrome|Firefox)\b/.test(G)&&(k.push("masking as "+G+" "+t),G="IE",t="11.0",R=["Trident"],M="Windows");M=M&&c(M)}t&&(y=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(t)||/(?:alpha|beta)(?: ?\d)?/i.exec(b+";"+(U&&r.appMinorVersion))||/\bMinefield\b/i.test(b)&&
"a")&&(V=/b/i.test(y)?"beta":"alpha",t=t.replace(RegExp(y+"\\+?$"),"")+("beta"==V?A:I)+(/\d+\+?/.exec(y)||""));if("Fennec"==G||"Firefox"==G&&/\b(?:Android|Firefox OS)\b/.test(M))G="Firefox Mobile";else if("Maxthon"==G&&t)t=t.replace(/\.[\d.]+/,".x");else if(/\bXbox\b/i.test(O))"Xbox 360"==O&&(M=null),"Xbox 360"==O&&/\bIEMobile\b/.test(b)&&k.unshift("mobile mode");else if(!/^(?:Chrome|IE|Opera)$/.test(G)&&(!G||O||/Browser|Mobi/.test(G))||"Windows CE"!=M&&!/Mobi/i.test(b))if("IE"==G&&U)try{null===m.external&&
k.unshift("platform preview")}catch(Z){k.unshift("embedded")}else(/\bBlackBerry\b/.test(O)||/\bBB10\b/.test(b))&&(y=(RegExp(O.replace(/ +/g," *")+"/([.\\d]+)","i").exec(b)||0)[1]||t)?(y=[y,/BB10/.test(b)],M=(y[1]?(O=null,T="BlackBerry"):"Device Software")+" "+y[0],t=null):this!=f&&"Wii"!=O&&(U&&L||/Opera/.test(G)&&/\b(?:MSIE|Firefox)\b/i.test(b)||"Firefox"==G&&/\bOS X (?:\d+\.){2,}/.test(M)||"IE"==G&&(M&&!/^Win/.test(M)&&5.5<t||/\bWindows XP\b/.test(M)&&8<t||8==t&&!/\bTrident\b/.test(b)))&&!q.test(y=
n.call(f,b.replace(q,"")+";"))&&y.name&&(y="ing as "+y.name+((y=y.version)?" "+y:""),q.test(G)?(/\bIE\b/.test(y)&&"Mac OS"==M&&(M=null),y="identify"+y):(y="mask"+y,G=W?c(W.replace(/([a-z])([A-Z])/g,"$1 $2")):"Opera",/\bIE\b/.test(y)&&(M=null),U||(t=null)),R=["Presto"],k.push(y));else G+=" Mobile";if(y=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(b)||0)[1]){y=[parseFloat(y.replace(/\.(\d)$/,".0$1")),y];if("Safari"==G&&"+"==y[1].slice(-1))G="WebKit Nightly",V="alpha",t=y[1].slice(0,-1);else if(t==y[1]||t==(y[2]=
(/\bSafari\/([\d.]+\+?)/i.exec(b)||0)[1]))t=null;y[1]=(/\bChrome\/([\d.]+)/i.exec(b)||0)[1];537.36==y[0]&&537.36==y[2]&&28<=parseFloat(y[1])&&"WebKit"==R&&(R=["Blink"]);U&&(w||y[1])?(R&&(R[1]="like Chrome"),y=y[1]||(y=y[0],530>y?1:532>y?2:532.05>y?3:533>y?4:534.03>y?5:534.07>y?6:534.1>y?7:534.13>y?8:534.16>y?9:534.24>y?10:534.3>y?11:535.01>y?12:535.02>y?"13+":535.07>y?15:535.11>y?16:535.19>y?17:536.05>y?18:536.1>y?19:537.01>y?20:537.11>y?"21+":537.13>y?23:537.18>y?24:537.24>y?25:537.36>y?26:"Blink"!=
R?"27":"28")):(R&&(R[1]="like Safari"),y=(y=y[0],400>y?1:500>y?2:526>y?3:533>y?4:534>y?"4+":535>y?5:537>y?6:538>y?7:601>y?8:"8"));R&&(R[1]+=" "+(y+="number"==typeof y?".x":/[.+]/.test(y)?"":"+"));"Safari"==G&&(!t||45<parseInt(t))&&(t=y)}"Opera"==G&&(y=/\bzbov|zvav$/.exec(M))?(G+=" ",k.unshift("desktop mode"),"zvav"==y?(G+="Mini",t=null):G+="Mobile",M=M.replace(RegExp(" *"+y+"$"),"")):"Safari"==G&&/\bChrome\b/.exec(R&&R[1])&&(k.unshift("desktop mode"),G="Chrome Mobile",t=null,/\bOS X\b/.test(M)?(T=
"Apple",M="iOS 4.3+"):M=null);t&&0==t.indexOf(y=/[\d.]+$/.exec(M))&&-1<b.indexOf("/"+y+"-")&&(M=String(M.replace(y,"")).replace(/^ +| +$/g,""));R&&!/\b(?:Avant|Nook)\b/.test(G)&&(/Browser|Lunascape|Maxthon/.test(G)||"Safari"!=G&&/^iOS/.test(M)&&/\bSafari\b/.test(R[1])||/^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|Web)/.test(G)&&R[1])&&(y=R[R.length-1])&&k.push(y);k.length&&(k=["("+k.join("; ")+")"]);T&&O&&0>O.indexOf(T)&&k.push("on "+T);O&&k.push((/^on /.test(k[k.length-
1])?"":"on ")+O);if(M){var S=(y=/ ([\d.+]+)$/.exec(M))&&"/"==M.charAt(M.length-y[0].length-1);M={architecture:32,family:y&&!S?M.replace(y[0],""):M,version:y?y[1]:null,toString:function(){var a=this.version;return this.family+(a&&!S?" "+a:"")+(64==this.architecture?" 64-bit":"")}}}(y=/\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(J))&&!/\bi686\b/i.test(J)?(M&&(M.architecture=64,M.family=M.family.replace(RegExp(" *"+y),"")),G&&(/\bWOW64\b/i.test(b)||U&&/\w(?:86|32)$/.test(r.cpuClass||r.platform)&&!/\bWin64; x64\b/i.test(b))&&
k.unshift("32-bit")):M&&/^OS X/.test(M.family)&&"Chrome"==G&&39<=parseFloat(t)&&(M.architecture=64);b||(b=null);m={};m.description=b;m.layout=R&&R[0];m.manufacturer=T;m.name=G;m.prerelease=V;m.product=O;m.ua=b;m.version=G&&t;m.os=M||{architecture:null,family:null,version:null,toString:function(){return"null"}};m.parse=n;m.toString=function(){return this.description||""};m.version&&k.unshift(t);m.name&&k.unshift(G);M&&G&&(M!=String(M).split(" ")[0]||M!=G.split(" ")[0]&&!O)&&k.push(O?"("+M+")":"on "+
M);k.length&&(m.description=k.join(" "));return m}var k={"function":!0,object:!0},p=k[typeof window]&&window||this,r=k[typeof exports]&&exports;k=k[typeof module]&&module&&!module.nodeType&&module;var h=r&&k&&"object"==typeof global&&global;!h||h.global!==h&&h.window!==h&&h.self!==h||(p=h);var m=Math.pow(2,53)-1,q=/\bOpera/;h=Object.prototype;var t=h.hasOwnProperty,u=h.toString,w=n();"function"==typeof define&&"object"==typeof define.amd&&define.amd?(p.platform=w,define(function(){return w})):r&&
k?f(w,function(a,b){r[b]=a}):p.platform=w}).call(this);
function buildIOSMeta(){for(var g=[{name:"viewport",content:"width=device-width, height=device-height, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"},{name:"apple-mobile-web-app-capable",content:"yes"},{name:"apple-mobile-web-app-status-bar-style",content:"black"}],b=0;b<g.length;b++){var c=document.createElement("meta");c.name=g[b].name;c.content=g[b].content;var f=window.document.head.querySelector('meta[name="'+c.name+'"]');f&&f.parentNode.removeChild(f);window.document.head.appendChild(c)}}
function hideIOSFullscreenPanel(){jQuery(".xxx-ios-fullscreen-message").css("display","none");jQuery(".xxx-ios-fullscreen-scroll").css("display","none");jQuery(".xxx-game-iframe-full").removeClass("xxx-game-iframe-iphone-se")}function buildIOSFullscreenPanel(){jQuery("body").append('<div class="xxx-ios-fullscreen-message"><div class="xxx-ios-fullscreen-swipe"></div></div><div class="xxx-ios-fullscreen-scroll"></div>')}
function showIOSFullscreenPanel(){jQuery(".xxx-ios-fullscreen-message").css("display","block");jQuery(".xxx-ios-fullscreen-scroll").css("display","block")}
function __iosResize(){window.scrollTo(0,0);if("iPhone"===platform.product)switch(window.devicePixelRatio){case 2:switch(window.innerWidth){case 568:320!==window.innerHeight&&jQuery(".xxx-game-iframe-full").addClass("xxx-game-iframe-iphone-se");break;case 667:375===window.innerHeight?hideIOSFullscreenPanel():showIOSFullscreenPanel();break;default:hideIOSFullscreenPanel()}break;case 3:switch(window.innerWidth){case 736:414===window.innerHeight?hideIOSFullscreenPanel():showIOSFullscreenPanel();break;
case 724:375===window.innerHeight?hideIOSFullscreenPanel():showIOSFullscreenPanel();break;default:hideIOSFullscreenPanel()}break;default:hideIOSFullscreenPanel()}}function iosResize(){__iosResize();setTimeout(function(){__iosResize()},500)}$(document).ready(function(){platform&&"iPhone"===platform.product&&"Safari"===platform.name&&(buildIOSFullscreenPanel(),buildIOSMeta())});jQuery(window).resize(function(){platform&&"iPhone"===platform.product&&"Safari"===platform.name&&iosResize()});
(function(){var g="undefined"!==typeof window&&"undefined"!==typeof window.document?window.document:{},b="undefined"!==typeof module&&module.exports,c="undefined"!==typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,f=function(){for(var a,b=["requestFullscreen exitFullscreen fullscreenElement fullscreenEnabled fullscreenchange fullscreenerror".split(" "),"webkitRequestFullscreen webkitExitFullscreen webkitFullscreenElement webkitFullscreenEnabled webkitfullscreenchange webkitfullscreenerror".split(" "),
"webkitRequestFullScreen webkitCancelFullScreen webkitCurrentFullScreenElement webkitCancelFullScreen webkitfullscreenchange webkitfullscreenerror".split(" "),"mozRequestFullScreen mozCancelFullScreen mozFullScreenElement mozFullScreenEnabled mozfullscreenchange mozfullscreenerror".split(" "),"msRequestFullscreen msExitFullscreen msFullscreenElement msFullscreenEnabled MSFullscreenChange MSFullscreenError".split(" ")],c=0,e=b.length,p={};c<e;c++)if((a=b[c])&&a[1]in g){for(c=0;c<a.length;c++)p[b[0][c]]=
a[c];return p}return!1}(),a={change:f.fullscreenchange,error:f.fullscreenerror},e={request:function(a){var b=f.requestFullscreen;a=a||g.documentElement;if(/5\.1[.\d]* Safari/.test(navigator.userAgent))a[b]();else a[b](c&&Element.ALLOW_KEYBOARD_INPUT)},exit:function(){g[f.exitFullscreen]()},toggle:function(a){this.isFullscreen?this.exit():this.request(a)},onchange:function(a){this.on("change",a)},onerror:function(a){this.on("error",a)},on:function(b,c){var d=a[b];d&&g.addEventListener(d,c,!1)},off:function(b,
c){var d=a[b];d&&g.removeEventListener(d,c,!1)},raw:f};f?(Object.defineProperties(e,{isFullscreen:{get:function(){return!!g[f.fullscreenElement]}},element:{enumerable:!0,get:function(){return g[f.fullscreenElement]}},enabled:{enumerable:!0,get:function(){return!!g[f.fullscreenEnabled]}}}),b?module.exports=e:window.screenfull=e):b?module.exports=!1:window.screenfull=!1})();var s_iOffsetX=0,s_iOffsetY=0;
(function(g){(jQuery.browser=jQuery.browser||{}).mobile=/android|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(ad|hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|tablet|treo|up\.(browser|link)|vodafone|wap|webos|windows (ce|phone)|xda|xiino/i.test(g)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(g.substr(0,
4))})(navigator.userAgent||navigator.vendor||window.opera);$(window).resize(function(){sizeHandler()});function trace(g){console.log(g)}function isIOS(){for(var g="iPad Simulator;iPhone Simulator;iPod Simulator;iPad;iPhone;iPod".split(";");g.length;)if(navigator.platform===g.pop())return s_bIsIphone=!0;return s_bIsIphone=!1}window.addEventListener("orientationchange",onOrientationChange);
function onOrientationChange(){window.matchMedia("(orientation: portrait)").matches&&sizeHandler();window.matchMedia("(orientation: landscape)").matches&&sizeHandler()}
function getSize(g){var b=g.toLowerCase(),c=window.document,f=c.documentElement;if(void 0===window["inner"+g])g=f["client"+g];else if(window["inner"+g]!=f["client"+g]){var a=c.createElement("body");a.id="vpw-test-b";a.style.cssText="overflow:scroll";var e=c.createElement("div");e.id="vpw-test-d";e.style.cssText="position:absolute;top:-1000px";e.innerHTML="<style>@media("+b+":"+f["client"+g]+"px){body#vpw-test-b div#vpw-test-d{"+b+":7px!important}}</style>";a.appendChild(e);f.insertBefore(a,c.head);
g=7==e["offset"+g]?f["client"+g]:window["inner"+g];f.removeChild(a)}else g=window["inner"+g];return g}function getIOSWindowHeight(){return document.documentElement.clientWidth/window.innerWidth*window.innerHeight}function getHeightOfIOSToolbars(){var g=(0===window.orientation?screen.height:screen.width)-getIOSWindowHeight();return 1<g?g:0}
function sizeHandler(){window.scrollTo(0,1);if($("#canvas")){var g=navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?getIOSWindowHeight():getSize("Height");var b=getSize("Width");_checkOrientation(b,g);var c=Math.min(g/CANVAS_HEIGHT,b/CANVAS_WIDTH),f=CANVAS_WIDTH*c;c*=CANVAS_HEIGHT;$("#canvas").css("width",f+"px");$("#canvas").css("height",c+"px");if(c<g){var a=g-c;c+=a;f+=CANVAS_WIDTH/CANVAS_HEIGHT*a}else f<b&&(a=b-f,f+=a,c+=CANVAS_HEIGHT/CANVAS_WIDTH*a);a=g/2-c/2;var e=b/2-f/2,d=CANVAS_WIDTH/f;if(e*
d<-EDGEBOARD_X||a*d<-EDGEBOARD_Y)s_iScaleFactor=Math.min(g/(CANVAS_HEIGHT-2*EDGEBOARD_Y),b/(CANVAS_WIDTH-2*EDGEBOARD_X)),f=CANVAS_WIDTH*s_iScaleFactor,c=CANVAS_HEIGHT*s_iScaleFactor,a=(g-c)/2,e=(b-f)/2,d=CANVAS_WIDTH/f;s_iOffsetX=-1*e*d;s_iOffsetY=-1*a*d;0<=a&&(s_iOffsetY=0);0<=e&&(s_iOffsetX=0);null!==s_oInterface&&s_oInterface.refreshButtonPos(s_iOffsetX,s_iOffsetY);null!==s_oMenu&&s_oMenu.refreshButtonPos(s_iOffsetX,s_iOffsetY);null!==s_oLevelMenu&&s_oLevelMenu.refreshButtonPos(s_iOffsetX,s_iOffsetY);
$("#canvas").css("width",f+"px");$("#canvas").css("height",c+"px");0>a||(a=(g-c)/2);$("#canvas").css("top",a+"px");s_iCanvasOffsetHeight=a;$("#canvas").css("left",e+"px");resizeCanvas3D();s_iCanvasResizeWidth=f;s_iCanvasResizeHeight=c;s_iCanvasOffsetWidth=e;fullscreenHandler()}}
function _checkOrientation(g,b){s_bMobile&&ENABLE_CHECK_ORIENTATION&&(g>b?"landscape"===$(".orientation-msg-container").attr("data-orientation")?($(".orientation-msg-container").css("display","none"),s_oMain.startUpdate()):($(".orientation-msg-container").css("display","block"),s_oMain.stopUpdate()):"portrait"===$(".orientation-msg-container").attr("data-orientation")?($(".orientation-msg-container").css("display","none"),s_oMain.startUpdate()):($(".orientation-msg-container").css("display","block"),
s_oMain.stopUpdate()))}function createBitmap(g,b,c){var f=new createjs.Bitmap(g),a=new createjs.Shape;b&&c?a.graphics.beginFill("#fff").drawRect(-b/2,-c/2,b,c):a.graphics.beginFill("#ff0").drawRect(0,0,g.width,g.height);f.hitArea=a;return f}function createSprite(g,b,c,f,a,e){g=null!==b?new createjs.Sprite(g,b):new createjs.Sprite(g);b=new createjs.Shape;b.graphics.beginFill("#000000").drawRect(-c,-f,a,e);g.hitArea=b;return g}
function randomFloatBetween(g,b,c){"undefined"===typeof c&&(c=2);return parseFloat(Math.min(g+Math.random()*(b-g),b).toFixed(c))}function shuffle(g){for(var b=g.length,c,f;0!==b;)f=Math.floor(Math.random()*b),--b,c=g[b],g[b]=g[f],g[f]=c;return g}function formatTime(g){g/=1E3;var b=Math.floor(g/60);g=parseFloat(g-60*b).toFixed(1);var c="";c=10>b?c+("0"+b+":"):c+(b+":");return 10>g?c+("0"+g):c+g}function degreesToRadians(g){return g*Math.PI/180}
function checkRectCollision(g,b){var c=getBounds(g,.9);var f=getBounds(b,.98);return calculateIntersection(c,f)}function calculateIntersection(g,b){var c,f,a,e;var d=g.x+(c=g.width/2);var l=g.y+(f=g.height/2);var n=b.x+(a=b.width/2);var k=b.y+(e=b.height/2);d=Math.abs(d-n)-(c+a);l=Math.abs(l-k)-(f+e);return 0>d&&0>l?(d=Math.min(Math.min(g.width,b.width),-d),l=Math.min(Math.min(g.height,b.height),-l),{x:Math.max(g.x,b.x),y:Math.max(g.y,b.y),width:d,height:l,rect1:g,rect2:b}):null}
function getBounds(g,b){var c={x:Infinity,y:Infinity,width:0,height:0};if(g instanceof createjs.Container){c.x2=-Infinity;c.y2=-Infinity;var f=g.children,a=f.length,e;for(e=0;e<a;e++){var d=getBounds(f[e],1);d.x<c.x&&(c.x=d.x);d.y<c.y&&(c.y=d.y);d.x+d.width>c.x2&&(c.x2=d.x+d.width);d.y+d.height>c.y2&&(c.y2=d.y+d.height)}Infinity==c.x&&(c.x=0);Infinity==c.y&&(c.y=0);Infinity==c.x2&&(c.x2=0);Infinity==c.y2&&(c.y2=0);c.width=c.x2-c.x;c.height=c.y2-c.y;delete c.x2;delete c.y2}else{if(g instanceof createjs.Bitmap){a=
g.sourceRect||g.image;e=a.width*b;var l=a.height*b}else if(g instanceof createjs.Sprite)if(g.spriteSheet._frames&&g.spriteSheet._frames[g.currentFrame]&&g.spriteSheet._frames[g.currentFrame].image){a=g.spriteSheet.getFrame(g.currentFrame);e=a.rect.width;l=a.rect.height;f=a.regX;var n=a.regY}else c.x=g.x||0,c.y=g.y||0;else c.x=g.x||0,c.y=g.y||0;f=f||0;e=e||0;n=n||0;l=l||0;c.regX=f;c.regY=n;a=g.localToGlobal(0-f,0-n);d=g.localToGlobal(e-f,l-n);e=g.localToGlobal(e-f,0-n);f=g.localToGlobal(0-f,l-n);c.x=
Math.min(Math.min(Math.min(a.x,d.x),e.x),f.x);c.y=Math.min(Math.min(Math.min(a.y,d.y),e.y),f.y);c.width=Math.max(Math.max(Math.max(a.x,d.x),e.x),f.x)-c.x;c.height=Math.max(Math.max(Math.max(a.y,d.y),e.y),f.y)-c.y}return c}function NoClickDelay(g){this.element=g;window.Touch&&this.element.addEventListener("touchstart",this,!1)}
NoClickDelay.prototype={handleEvent:function(g){switch(g.type){case "touchstart":this.onTouchStart(g);break;case "touchmove":this.onTouchMove(g);break;case "touchend":this.onTouchEnd(g)}},onTouchStart:function(g){g.preventDefault();this.moved=!1;this.element.addEventListener("touchmove",this,!1);this.element.addEventListener("touchend",this,!1)},onTouchMove:function(g){this.moved=!0},onTouchEnd:function(g){this.element.removeEventListener("touchmove",this,!1);this.element.removeEventListener("touchend",
this,!1);if(!this.moved){g=document.elementFromPoint(g.changedTouches[0].clientX,g.changedTouches[0].clientY);3==g.nodeType&&(g=g.parentNode);var b=document.createEvent("MouseEvents");b.initEvent("click",!0,!0);g.dispatchEvent(b)}}};
(function(){function g(c){var g={focus:"visible",focusin:"visible",pageshow:"visible",blur:"hidden",focusout:"hidden",pagehide:"hidden"};c=c||window.event;c.type in g?document.body.className=g[c.type]:(document.body.className=this[b]?"hidden":"visible","hidden"===document.body.className?s_oMain.stopUpdate():s_oMain.startUpdate())}var b="hidden";b in document?document.addEventListener("visibilitychange",g):(b="mozHidden")in document?document.addEventListener("mozvisibilitychange",g):(b="webkitHidden")in
document?document.addEventListener("webkitvisibilitychange",g):(b="msHidden")in document?document.addEventListener("msvisibilitychange",g):"onfocusin"in document?document.onfocusin=document.onfocusout=g:window.onpageshow=window.onpagehide=window.onfocus=window.onblur=g})();function playSound(g,b,c){return!1===DISABLE_SOUND_MOBILE||!1===s_bMobile?(s_aSounds[g].play(),s_aSounds[g].volume(b),s_aSounds[g].loop(c),s_aSounds[g]):null}
function stopSound(g){!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||s_aSounds[g].stop()}function setVolume(g,b){!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||s_aSounds[g].volume(b)}function setMute(g,b){!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||s_aSounds[g].mute(b)}function ctlArcadeResume(){null!==s_oMain&&s_oMain.startUpdate()}function ctlArcadePause(){null!==s_oMain&&s_oMain.stopUpdate()}
function getParamValue(g){for(var b=window.location.search.substring(1).split("&"),c=0;c<b.length;c++){var f=b[c].split("=");if(f[0]==g)return f[1]}}function rotateVector2D(g,b){return{x:b.x*Math.cos(g)+b.y*Math.sin(g),y:b.x*-Math.sin(g)+b.y*Math.cos(g)}}function normalize(g,b){0<b&&(g.x/=b,g.y/=b);return g}function length(g){return Math.sqrt(g.x*g.x+g.y*g.y)}
function findNearestIntersectingObject(g,b,c,f){var a=CANVAS_RESIZE_WIDTH+2*OFFSET_WIDTH,e=CANVAS_RESIZE_HEIGHT+2*OFFSET_HEIGHT,d=new THREE.Raycaster,l=new THREE.Vector3;l.x=g/a*2-1;l.y=2*-(b/e)+1;l.z=.5;d.setFromCamera(l,c);g=d.intersectObjects(f,!0);b=!1;0<g.length&&(b=g[0]);return b}function distance(g,b,c,f){g-=c;b-=f;return Math.sqrt(g*g+b*b)}function distance2(g,b,c,f){g-=c;b-=f;return g*g+b*b}
function resizeCanvas3D(){$("canvas").each(function(){"#canvas"!=$(this).attr("id")&&($(this).css("width",$("#canvas").css("width")),$(this).css("height",$("#canvas").css("height")),$(this).css("position",$("#canvas").css("position")),$(this).css("left",$("#canvas").css("left")),$(this).css("top",$("#canvas").css("top")))})}
function convert3dPosTo2dScreen(g,b){var c=new THREE.Vector3;c.set(g.x,g.y,g.z);c.project(b);c.x=Math.round((c.x+1)*CANVAS_WIDTH*.5);c.y=Math.round((-c.y+1)*CANVAS_HEIGHT*.5);c.z=0;return c}function convert2dPosTo3d(g,b){var c=new THREE.Vector3;c.set(g.x/CANVAS_WIDTH*2-1,2*-(g.y/CANVAS_HEIGHT)+1,.5);c.unproject(b);c=c.sub(b.position).normalize();var f=-b.position.z/c.z;c=b.position.clone().add(c.multiplyScalar(f));return{x:c.x,y:c.y}}
function createOrthoGraphicCamera(){var g=new THREE.OrthographicCamera(CANVAS_WIDTH/-2,CANVAS_WIDTH/2,CANVAS_HEIGHT/-2,CANVAS_HEIGHT/2,1,1E3);g.rotation.x=Math.PI/180*45;g.rotation.y=Math.PI/180*-30;g.rotation.z=Math.PI/180*-30;g.zoom=6;g.left=CANVAS_WIDTH/-2;g.right=CANVAS_WIDTH/2;g.top=CANVAS_HEIGHT/2;g.bottom=CANVAS_HEIGHT/-2;g.position.set(0,0,0);g.updateProjectionMatrix();g.updateMatrixWorld();return g}function dotProductV2(g,b){return g.getX()*b.getX()+g.getY()*b.getY()}
function pointInPoly(g,b){for(var c=!1,f=-1,a=b.length,e=a-1;++f<a;e=f)(b[f].y<=g.y&&g.y<b[e].y||b[e].y<=g.y&&g.y<b[f].y)&&g.x<(b[e].x-b[f].x)*(g.y-b[f].y)/(b[e].y-b[f].y)+b[f].x&&(c=!c);return c}function angleBetweenVectors(g,b){var c=dotProductV2(g,b),f=g.getX()*b.getY()-g.getY()*b.getX();return Math.atan2(f,c)}function rotateVector2D(g,b){var c=b.getX()*Math.cos(g)+b.getY()*Math.sin(g),f=b.getX()*-Math.sin(g)+b.getY()*Math.cos(g);return{x:c,y:f,z:0}}Math.radians=function(g){return g*Math.PI/180};
Math.degrees=function(g){return 180*g/Math.PI};function distanceV3(g,b,c,f,a,e){g-=f;b-=a;c-=e;return Math.sqrt(g*g+b*b+c*c)}function distanceV2(g,b){var c=g.x-b.x,f=g.y-b.y;return Math.sqrt(c*c+f*f)}
function fullscreenHandler(){ENABLE_FULLSCREEN&&screenfull.enabled&&(s_bFullscreen=screen.height<window.innerHeight+3&&screen.height>window.innerHeight-3?!0:!1,null!==s_oInterface&&s_oInterface.resetFullscreenBut(),null!==s_oMenu&&s_oMenu.resetFullscreenBut(),null!==s_oLevelMenu&&s_oLevelMenu.resetFullscreenBut())}
if(screenfull.enabled)screenfull.on("change",function(){s_bFullscreen=screenfull.isFullscreen;null!==s_oInterface&&s_oInterface.resetFullscreenBut();null!==s_oMenu&&s_oMenu.resetFullscreenBut();null!==s_oLevelMenu&&s_oLevelMenu.resetFullscreenBut()});
function CSpriteLibrary(){var g={},b,c,f,a,e,d;this.init=function(g,n,k){b={};f=c=0;a=g;e=n;d=k};this.addSprite=function(a,d){g.hasOwnProperty(a)||(g[a]=b[a]={szPath:d,oSprite:new Image,bLoaded:!1},c++)};this.getSprite=function(a){return g.hasOwnProperty(a)?g[a].oSprite:null};this._onSpritesLoaded=function(){c=0;e.call(d)};this._onSpriteLoaded=function(b){a.call(d,b);++f===c&&this._onSpritesLoaded()};this.loadSprites=function(){for(var a in b)b[a].oSprite.oSpriteLibrary=this,b[a].oSprite.szKey=a,
b[a].oSprite.onload=function(){this.oSpriteLibrary.setLoaded(this.szKey);this.oSpriteLibrary._onSpriteLoaded(this.szKey)},g[a].oSprite.onerror=function(b){setTimeout(function(){g[a].oSprite.src=g[a].szPath},500)},b[a].oSprite.src=b[a].szPath};this.setLoaded=function(a){g[a].bLoaded=!0};this.isLoaded=function(a){return g[a].bLoaded};this.getNumSprites=function(){return c}}
var CANVAS_WIDTH=1600,CANVAS_HEIGHT=968,EDGEBOARD_X=150,EDGEBOARD_Y=150,DISABLE_SOUND_MOBILE=!1,PRIMARY_FONT="space_comics",FPS=60,FPS_TIME=1E3/FPS,STATE_LOADING=0,STATE_MENU=1,STATE_HELP=1,STATE_GAME=3,ON_MOUSE_DOWN=0,ON_MOUSE_UP=1,ON_MOUSE_OVER=2,ON_MOUSE_OUT=3,ON_DRAG_START=4,ON_DRAG_END=5,ON_CONTROLLER_END=8,ON_CONTROLLER_REMOVE=9,ON_CONTROLLER_ROLL=10,RESTART_WATER_DEPTH_VALUE=5,HOLE_DEPTH_VALUE=3,MIN_MOUSE_DISTANCE_POWER_ACTIVATED=30,MIN_MOUSE_DISTANCE_POWER_ACTIVATED_MOBILE=100,MAX_MOUSE_DISTANCE_POWER_ACTIVATED=
300,BALL_MASS=1,BALL_RADIUS=2,BALL_FRICTION=.5,BALL_RESTITUTION=.5,BALL_LINEAR_DAMPING=.5,BALL_LINEAR_DAMPING_SAND=.95,BALL_LINEAR_DAMPING_WATER=.99,BALL_LINEAR_DAMPING_HOLE=3.8,MIN_VELOCITY_FOR_LAUNCH=1.5,ARROW_DISTANCE=75,RATIO_ARROW_DISTANCE=4,TIME_FOR_LAUNCH=.2,OFFSET_ANGLE_ARROW=90,HIT_BALL_MAX_FORCE=200,HIT_BALL_MIN_FORCE=.01,SHOW_3D_RENDER=!1,CAMERA_TEST=!1,START_CAMERA_POSITION={x:-240,y:-290,z:280},NEAR=-30,FAR=2E3,FORCE_MULTIPLIER=2,PAR_POINTS,ADDED_POINTS,MAX_SHOT_POWER,ENABLE_FULLSCREEN,
ENABLE_CHECK_ORIENTATION,NUM_HOLES=18,PAR=[],FLAGS_POS=[[{x:424,y:-488},{x:655,y:-340}],[{x:660,y:102},{x:924,y:-54}],[{x:816,y:-1212},{x:1580,y:-704}],[{x:64,y:-588},{x:464,y:-816}],[{x:693,y:-1307},{x:1308,y:-912}],[{x:175,y:-1252},{x:480,y:-1052}],[{x:-432,y:852},{x:-204,y:1010}],[{x:-1430,y:632},{x:-1200,y:788}],[{x:-856,y:1220},{x:-628,y:1372}],[{x:-2140,y:1042},{x:-1910,y:1196}],[{x:-1612,y:736},{x:-1380,y:892}],[{x:-112,y:-136},{x:125,y:20}],[{x:-1618,y:236},{x:-1390,y:392}],[{x:-1860,y:735},
{x:-1396,y:1048}],[{x:692,y:-588},{x:924,y:-440}],[{x:1930,y:-484},{x:2088,y:-384}],[{x:-1740,y:-30},{x:-1276,y:276}],[{x:960,y:-764},{x:1216,y:-590}]],CAUSTICS_POS=[null,null,{x:1148,y:-750,scale:1},null,null,null,{x:904,y:-730,scale:1},{x:468,y:-328,scale:1},{x:1392,y:108,scale:.3},{x:508,y:-272,scale:1},null,{x:-838,y:-386,scale:.7},{x:514,y:-60,scale:1},null,{x:688,y:-60,scale:.4},null,null,{x:846,y:-496,scale:1}],LOCALSTORAGE_SCORE="score";
function CLocalStorage(g){this.init=function(){var b=window.localStorage.getItem(g);null!==b&&void 0!==b&&!1!==s_bStorageAvailable||this.resetAllData()};this.setItem=function(b,c){s_bStorageAvailable&&(_bDirty=!0,window.localStorage.setItem(g+"_"+b,c))};this.getItem=function(b){return window.localStorage.getItem(g+"_"+b)};this.setItemJson=function(b,c){s_bStorageAvailable&&localStorage.setItem(g+"_"+b,JSON.stringify(c))};this.getItemJson=function(b){b=JSON.parse(localStorage.getItem(g+"_"+b));if(null===
b){b=[];for(var c=0;c<NUM_HOLES;c++)b[c]=0}return b};this.isDirty=function(){var b=s_oLocalStorage.getItemJson(LOCALSTORAGE_SCORE);if(!s_bStorageAvailable||null===b)return!1;for(var c=0;c<b.length;c++)if(0<b[c])return!0;return!1};this.resetAllData=function(){window.localStorage.setItem(g,!0);for(var b=[],c=0;c<NUM_HOLES;c++)b[c]=0;this.setItemJson(LOCALSTORAGE_SCORE,b)}}
var EASE_LINEAR=0,EASE_CUBIC_IN=1,EASE_QUART_BACKIN=2,EASE_BACKIN=3,EASE_SIN_IN=4,EASE_QUAD_IN=5,EASE_CUBIC_OUT=6,EASE_ELASTIC_OUT=7,EASE_BACKOUT=8,EASE_QUINT_OUT=9,EASE_CUBIC_INOUT=10;
function CTweenController(){this.tweenValue=function(g,b,c){return g+c*(b-g)};this.easeLinear=function(g,b,c,f){return c*g/f+b};this.easeInCubic=function(g,b,c,f){f=(g/=f)*g*g;return b+c*f};this.easeBackInQuart=function(g,b,c,f){f=(g/=f)*g;return b+c*(2*f*f+2*f*g+-3*f)};this.easeInBack=function(g,b,c,f){return c*(g/=f)*g*(2.70158*g-1.70158)+b};this.easeInSine=function(g,b,c,f){return-c*Math.cos(g/f*(Math.PI/2))+c+b};this.easeInQuad=function(g,b,c,f){return c*(g/=f)*g+b};this.easeOutCubic=function(g,
b,c,f){return c*((g=g/f-1)*g*g+1)+b};this.easeOutElastic=function(g,b,c,f){if(0===g)return b;if(1===(g/=f))return b+c;var a=.3*f;return c*Math.pow(2,-10*g)*Math.sin(2*(g*f-a/4)*Math.PI/a)+c+b};this.easeOutBack=function(g,b,c,f){return c*((g=g/f-1)*g*(2.70158*g+1.70158)+1)+b};this.easeInOutCubic=function(g,b,c,f){return 1>(g/=f/2)?c/2*g*g*g+b:c/2*((g-=2)*g*g+2)+b};this.easeOutQuint=function(g,b,c,f){return c*((g=g/f-1)*g*g*g*g+1)+b}}
function CRollingTextController(g,b,c,f,a){var e,d,l,n,k,p,r,h,m,q,t,u;this._init=function(a,b,d,c,g){h=[];m=[];k=c;this.setUpdateInfo(d);r=g;t=a;u=b;q=[]};this.unload=function(){clearInterval(p)};this.setUpdateInfo=function(a){l=parseFloat(g.text);n=l+a;e=0;d=Math.round(k/FPS);var b=this;p=setInterval(function(){b.update()},FPS_TIME)};this.addEventListener=function(a,b,d){h[a]=b;m[a]=d};this.addRollingListener=function(a,b,d){h[ON_CONTROLLER_ROLL]=a;m[ON_CONTROLLER_ROLL]=b;q=[];for(a=0;a<d.length;a++)q[a]=
{step:d[a],flag:!1}};this.increaseValue=function(a){};this.getTarget=function(){return t};this.update=function(){e++;if(e>d)e=0,t.text=n.toFixed(0),null!==u&&(u.text=n.toFixed(0)),clearInterval(p);else{switch(r){case EASE_BACKIN:var a=s_oTweenController.easeInBack(e,0,1,d);break;case EASE_BACKOUT:a=s_oTweenController.easeOutBack(e,0,1,d);break;case EASE_CUBIC_IN:a=s_oTweenController.easeInCubic(e,0,1,d);break;case EASE_CUBIC_OUT:a=s_oTweenController.easeOutCubic(e,0,1,d);break;case EASE_ELASTIC_OUT:a=
s_oTweenController.easeOutElastic(e,0,1,d);break;case EASE_LINEAR:a=s_oTweenController.easeLinear(e,0,1,d);break;case EASE_QUART_BACKIN:a=s_oTweenController.easeBackInQuart(e,0,1,d);break;default:a=s_oTweenController.easeLinear(e,0,1,d)}a=s_oTweenController.tweenValue(l,n,a);for(var b=0;b<q.length;b++)a>=q[b].step&&!q[b].flag&&(q[b].flag=!0,null!==h[ON_CONTROLLER_ROLL]&&h[ON_CONTROLLER_ROLL].call(m[ON_CONTROLLER_ROLL],b));t.text=a.toFixed(0);null!==u&&(u.text=a.toFixed(0))}};this._init(g,b,c,f,a)}
var TEXT_PRELOADER_CONTINUE="START",TEXT_GAMEOVER="GAME OVER",TEXT_ARE_SURE="ARE YOU SURE YOU WANT TO QUIT THE GAME?",TEXT_SAVE_REMOVE="THIS WILL REMOVE ALL YOUR ACHIEVEMENTS! DO YOU WANT TO PROCEED?",TEXT_TOTAL_SCORE="TOTAL SCORE",TEXT_LAUNCH="LAUNCH",TEXT_HOLE="HOLE",TEXT_LOADING="LOADING...",TEXT_ALL_COMPLETE="ALL LEVEL COMPLETED",TEXT_SELECT_A_LEVEL="SELECT A LEVEL",TEXT_HELP1_PC="CLICK THE BALL AND DRAG TO SET POWER AND DIRECTION",TEXT_HELP1_MOBILE="TOUCH THE BALL AND DRAG THE FINGER TO SET POWER AND DIRECTION",
TEXT_HELP2="CLICK AND DRAG TO HAVE A PAN VIEW",TEXT_ERR_LS="YOUR WEB BROWSER DOES NOT SUPPORT STORING SETTING LOCALLY. IN SAFARI, THE MOST COMMON CAUSE OF THIS IS USING 'PRIVATE BROWSING MODE'. SOME INFO MAY NOT SAVE OR SOME FEATURE MAY NOT WORK PROPERLY.",TEXT_SCORE="SCORE",TEXT_COMPLETE="COMPLETE",TEXT_DEVELOPED="DEVELOPED BY",TEXT_DOUBLE_BOGEY="DOUBLE BOGEY",TEXT_BOGEY="BOGEY",TEXT_PAR="PAR",TEXT_BIRDIE="BIRDIE",TEXT_EAGLE="EAGLE",TEXT_ALBATROSS="ALBATROSS",TEXT_CONDOR="CONDOR",TEXT_PHOENIX="PHOENIX",
TEXT_HOLEINONE="HOLE IN ONE",TEXT_SHARE_IMAGE="200x200.jpg",TEXT_SHARE_TITLE="Congratulations!",TEXT_SHARE_MSG1="You collected <strong>",TEXT_SHARE_MSG2=" points</strong>!<br><br>Share your score with your friends!",TEXT_SHARE_SHARE1="My score is ",TEXT_SHARE_SHARE2=" points! Can you do better?";
function CPreloader(){var g,b,c,f,a,e,d,l,n,k;this._init=function(){s_oSpriteLibrary.init(this._onImagesLoaded,this._onAllImagesLoaded,this);s_oSpriteLibrary.addSprite("progress_bar","./sprites/progress_bar.png");s_oSpriteLibrary.addSprite("200x200","./sprites/200x200.jpg");s_oSpriteLibrary.addSprite("but_start","./sprites/but_start.png");s_oSpriteLibrary.loadSprites();k=new createjs.Container;s_oStage.addChild(k)};this.unload=function(){n.unload();k.removeAllChildren()};this._onImagesLoaded=function(){};
this._onAllImagesLoaded=function(){this.attachSprites();s_oMain.preloaderReady()};this.attachSprites=function(){var p=new createjs.Shape;p.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);k.addChild(p);p=s_oSpriteLibrary.getSprite("200x200");d=createBitmap(p);d.regX=.5*p.width;d.regY=.5*p.height;d.x=CANVAS_WIDTH/2;d.y=CANVAS_HEIGHT/2-80;k.addChild(d);l=new createjs.Shape;l.graphics.beginFill("rgba(0,0,0,0.01)").drawRoundRect(d.x-100,d.y-100,200,200,10);k.addChild(l);d.mask=l;p=
s_oSpriteLibrary.getSprite("progress_bar");f=createBitmap(p);f.x=CANVAS_WIDTH/2-p.width/2;f.y=CANVAS_HEIGHT/2+70;k.addChild(f);g=p.width;b=p.height;a=new createjs.Shape;a.graphics.beginFill("rgba(0,0,0,0.01)").drawRect(f.x,f.y,1,b);k.addChild(a);f.mask=a;c=new createjs.Text("","30px "+PRIMARY_FONT,"#fff");c.x=CANVAS_WIDTH/2;c.y=CANVAS_HEIGHT/2+150;c.textBaseline="alphabetic";c.textAlign="center";k.addChild(c);p=s_oSpriteLibrary.getSprite("but_start");n=new CTextButton(CANVAS_WIDTH/2,CANVAS_HEIGHT/
2+100,p,TEXT_PRELOADER_CONTINUE,"Arial","#000",36,k);n.addEventListener(ON_MOUSE_UP,this._onButStartRelease,this);n.setVisible(!1);e=new createjs.Shape;e.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);k.addChild(e);createjs.Tween.get(e).to({alpha:0},500).call(function(){createjs.Tween.removeTweens(e);k.removeChild(e)})};this._onButStartRelease=function(){s_oMain._allResourcesLoaded()};this.refreshLoader=function(d){c.text=d+"%";100===d&&(n.setVisible(!0),c.visible=!1,f.visible=
!1);a.graphics.clear();d=Math.floor(d*g/100);a.graphics.beginFill("rgba(0,0,0,0.01)").drawRect(f.x,f.y,d,b)};this._init()}
function CLoadingScreen(g){var b=null,c,f,a;this._init=function(){a=new createjs.Container;g.addChild(a);b=new createjs.Shape;b.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);b.on("click",function(){});a.addChild(b);c=new createjs.Text(TEXT_LOADING,"30px "+PRIMARY_FONT,"#ffffff");c.x=CANVAS_WIDTH/2;c.y=CANVAS_HEIGHT/2;c.textAlign="center";c.textBaseline="alphabetic";c.alpha=0;a.addChild(c);var e=s_oSpriteLibrary.getSprite("preloader_anim");f=createBitmap(e);f.x=CANVAS_WIDTH/
2;f.y=CANVAS_HEIGHT/2+40;f.regX=.5*e.width;f.regY=.5*e.height;f.alpha=0;a.addChild(f);createjs.Tween.get(f).to({alpha:1},500);createjs.Tween.get(c).to({alpha:1},500);this.animLoad()};this.animLoad=function(){var a=this;createjs.Tween.get(f).to({rotation:f.rotation+360},1E3).call(function(){a.animLoad()})};this.unload=function(){b.removeAllEventListeners();createjs.Tween.get(a).to({alpha:0},500).call(function(){g.removeChild(a)})};this._init();return this}
function CMain(g){var b,c=0,f=0,a=STATE_LOADING,e,d,l,n;this.initContainer=function(){var a=document.getElementById("canvas");s_oStage=new createjs.Stage(a);createjs.Touch.enable(s_oStage);s_oStage.preventSelection=!1;s_bMobile=jQuery.browser.mobile;!1===s_bMobile&&(s_oStage.enableMouseOver(20),$("body").on("contextmenu","#canvas",function(a){return!1}));s_iPrevTime=(new Date).getTime();createjs.Ticker.addEventListener("tick",this._update);createjs.Ticker.framerate=FPS;navigator.userAgent.match(/Windows Phone/i)&&
(DISABLE_SOUND_MOBILE=!0);e=[];s_oSpriteLibrary=new CSpriteLibrary;s_oTweenController=new CTweenController;seekAndDestroy()?d=new CPreloader:window.location.href="http://www.codethislab.com/contact-us.html";b=!0};this.soundLoaded=function(){c++;d.refreshLoader(Math.floor(c/f*100))};this._initSounds=function(){var a=[];a.push({path:"./sounds/",filename:"win_level",loop:!1,volume:1,ingamename:"win_level"});a.push({path:"./sounds/",filename:"click",loop:!1,volume:1,ingamename:"click"});a.push({path:"./sounds/",
filename:"ambience",loop:!1,volume:1,ingamename:"ambience"});a.push({path:"./sounds/",filename:"hit_ball",loop:!1,volume:1,ingamename:"hit_ball"});a.push({path:"./sounds/",filename:"soundtrack",loop:!0,volume:1,ingamename:"soundtrack"});a.push({path:"./sounds/",filename:"hole",loop:!1,volume:1,ingamename:"hole"});a.push({path:"./sounds/",filename:"sand",loop:!1,volume:1,ingamename:"sand"});a.push({path:"./sounds/",filename:"water",loop:!1,volume:1,ingamename:"water"});a.push({path:"./sounds/",filename:"star",
loop:!1,volume:1,ingamename:"star"});f+=a.length;s_aSounds=[];for(var b=0;b<a.length;b++)s_aSounds[a[b].ingamename]=new Howl({src:[a[b].path+a[b].filename+".mp3"],autoplay:!1,preload:!0,loop:a[b].loop,volume:a[b].volume,onload:s_oMain.soundLoaded})};this._loadImages=function(){s_oSpriteLibrary.init(this._onImagesLoaded,this._onAllImagesLoaded,this);s_oSpriteLibrary.addSprite("preloader_anim","./sprites/preloader_anim.png");s_oSpriteLibrary.addSprite("but_play","./sprites/but_play.png");s_oSpriteLibrary.addSprite("but_continue",
"./sprites/but_continue.png");s_oSpriteLibrary.addSprite("but_continue_big","./sprites/but_continue_big.png");s_oSpriteLibrary.addSprite("but_info","./sprites/but_info.png");s_oSpriteLibrary.addSprite("ctl_logo","./sprites/ctl_logo.png");s_oSpriteLibrary.addSprite("but_yes","./sprites/but_yes.png");s_oSpriteLibrary.addSprite("but_not","./sprites/but_not.png");s_oSpriteLibrary.addSprite("but_exit","./sprites/but_exit.png");s_oSpriteLibrary.addSprite("but_restart_small","./sprites/but_restart_small.png");
s_oSpriteLibrary.addSprite("but_restart_big","./sprites/but_restart_big.png");s_oSpriteLibrary.addSprite("help_touch","./sprites/help_touch.png");s_oSpriteLibrary.addSprite("star","./sprites/star.png");s_oSpriteLibrary.addSprite("bg_menu","./sprites/bg_menu.jpg");s_oSpriteLibrary.addSprite("msg_box","./sprites/msg_box.png");s_oSpriteLibrary.addSprite("audio_icon","./sprites/audio_icon.png");s_oSpriteLibrary.addSprite("but_home","./sprites/but_home.png");s_oSpriteLibrary.addSprite("ball","./sprites/ball.png");
s_oSpriteLibrary.addSprite("arrow","./sprites/arrow.png");s_oSpriteLibrary.addSprite("but_level","./sprites/but_level.png");s_oSpriteLibrary.addSprite("flag","./sprites/flag.png");s_oSpriteLibrary.addSprite("ball_shadow","./sprites/ball_shadow.png");s_oSpriteLibrary.addSprite("caustics","./sprites/caustics.png");s_oSpriteLibrary.addSprite("but_center_view","./sprites/but_center_view.png");s_oSpriteLibrary.addSprite("ball_water","./sprites/ball_water.png");s_oSpriteLibrary.addSprite("press_indicator",
"./sprites/press_indicator.png");s_oSpriteLibrary.addSprite("menu_text_minigolf","./sprites/menu_text_minigolf.png");s_oSpriteLibrary.addSprite("menu_text_world","./sprites/menu_text_world.png");s_oSpriteLibrary.addSprite("but_fullscreen","./sprites/but_fullscreen.png");s_oSpriteLibrary.addSprite("arrow","./sprites/arrow.png");s_oSpriteLibrary.addSprite("arrow_fill","./sprites/arrow_fill.png");s_oSpriteLibrary.addSprite("arrow_frame","./sprites/arrow_frame.png");f+=s_oSpriteLibrary.getNumSprites();
s_oSpriteLibrary.loadSprites()};this._onImagesLoaded=function(){c++;d.refreshLoader(Math.floor(c/f*100))};this._onAllImagesLoaded=function(){};this._allResourcesLoaded=function(){s_oLocalStorage=new CLocalStorage("minigolf_world");try{s_oLocalStorage.init()}catch(p){s_bStorageAvailable=!1}d.unload();s_oSoundTrack=playSound("soundtrack",1,!0);this.gotoMenu()};this.loadSelectedLevel=function(a){s_iCurLevel=a;f=c=0;if(e[a])this.gotoGame(s_iCurLevel);else{n=new CLoadingScreen(s_oStage);s_oSpriteLibrary.init(this._onLevelLoaded,
this._onAllImagesLoaded,this);a+=1;for(var b,d=1;18>=d;d++)b=d-1,10>d?s_oSpriteLibrary.addSprite("level_"+a+"_bg_"+b,"./sprites/bg_levels/level_"+a+"/bg_piece_"+("0"+d)+".jpg"):s_oSpriteLibrary.addSprite("level_"+a+"_bg_"+b,"./sprites/bg_levels/level_"+a+"/bg_piece_"+d+".jpg");f+=s_oSpriteLibrary.getNumSprites();s_oSpriteLibrary.loadSprites()}};this._onLevelLoaded=function(){c++;c===f&&(e[s_iCurLevel]=!0,n.unload(),this.gotoGame(s_iCurLevel),this.loadInBackgroundLevel(s_iCurLevel+1))};this.loadInBackgroundLevel=
function(a){s_iBackgroundLevel=a;f=c=0;if(!e[a]){s_oSpriteLibrary.init(this._onBackgroundLevelLoaded,this._onAllImagesLoaded,this);a+=1;for(var b,d=1;18>=d;d++)b=d-1,10>d?s_oSpriteLibrary.addSprite("level_"+a+"_bg_"+b,"./sprites/bg_levels/level_"+a+"/bg_piece_"+("0"+d)+".jpg"):s_oSpriteLibrary.addSprite("level_"+a+"_bg_"+b,"./sprites/bg_levels/level_"+a+"/bg_piece_"+d+".jpg");f+=s_oSpriteLibrary.getNumSprites();s_oSpriteLibrary.loadSprites()}};this._onBackgroundLevelLoaded=function(){c++;if(c===f){for(var a=
e[s_iBackgroundLevel]=!0,b=0;b<NUM_HOLES;b++)e[b]||(a=!1);a||(a=s_iBackgroundLevel+1,a<NUM_HOLES?this.loadInBackgroundLevel(a):this.loadInBackgroundLevel(1))}};this.preloaderReady=function(){this._loadImages();!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||this._initSounds();b=!0};this.gotoMenu=function(){new CMenu;a=STATE_MENU};this.gotoGame=function(b){l=new CGame(k,b);a=STATE_GAME};this.gotoLevelMenu=function(){new CLevelMenu;a=STATE_MENU};this.gotoHelp=function(){new CHelp;a=STATE_HELP};this.selectMode=
function(a){s_iCurMode=a;this.gotoGame()};this.stopUpdate=function(){b=!1;createjs.Ticker.paused=!0;$("#block_game").css("display","block");!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||Howler.mute(!0)};this.startUpdate=function(){s_iPrevTime=(new Date).getTime();b=!0;createjs.Ticker.paused=!1;$("#block_game").css("display","none");(!1===DISABLE_SOUND_MOBILE||!1===s_bMobile)&&s_bAudioActive&&Howler.mute(!1)};this._update=function(d){if(!1!==b){var c=(new Date).getTime();s_iTimeElaps=c-s_iPrevTime;s_iCntTime+=
s_iTimeElaps;s_iCntFps++;s_iPrevTime=c;1E3<=s_iCntTime&&(s_iCurFps=s_iCntFps,s_iCntTime-=1E3,s_iCntFps=0);a===STATE_GAME&&l.update();s_oStage.update(d)}};s_oMain=this;PAR_POINTS=g.par_points;ADDED_POINTS=g.added_points;var k=g;ENABLE_CHECK_ORIENTATION=g.check_orientation;ENABLE_FULLSCREEN=g.fullscreen;this.initContainer()}
var s_bMobile,s_bAudioActive=!0,s_iCntTime=0,s_iTimeElaps=0,s_iPrevTime=0,s_iCntFps=0,s_iCurFps=0,s_oPhysicsController,s_iCanvasResizeHeight,s_iCanvasResizeWidth,s_iCanvasOffsetHeight,s_iCanvasOffsetWidth,s_iCurLevel,s_iBackgroundLevel,s_oDrawLayer,s_oStage,s_oMain,s_oSpriteLibrary,s_oSoundTrack=null,s_oTweenController,s_oLocalStorage,s_bFullscreen=!1,s_bStorageAvailable=!0,s_aSounds;
function CTextButton(g,b,c,f,a,e,d,l){var n,k,p,r,h,m,q,t,u,w,v;this._init=function(a,b,d,c,g,m,e,q){n=!1;r=[];h=[];v=createBitmap(d);k=d.width;p=d.height;w=new createjs.Text(c,e+"px "+g,m);w.textAlign="center";w.textBaseline="alphabetic";w.lineWidth=.9*k;w.x=d.width/2;w.y=Math.floor(d.height/2)+15;u=new createjs.Container;u.x=a;u.y=b;u.regX=d.width/2;u.regY=d.height/2;s_bMobile||(u.cursor="pointer");u.addChild(v,w);!1!==q&&s_oStage.addChild(u);this._initListener()};this.unload=function(){u.off("mousedown",
m);u.off("pressup",q);s_oStage.removeChild(u)};this.setVisible=function(a){u.visible=a};this.setAlign=function(a){w.textAlign=a};this.enable=function(){n=!1;v.filters=[];v.cache(0,0,k,p)};this.disable=function(){n=!0;var a=(new createjs.ColorMatrix).adjustSaturation(-100).adjustBrightness(40);v.filters=[new createjs.ColorMatrixFilter(a)];v.cache(0,0,k,p)};this._initListener=function(){m=u.on("mousedown",this.buttonDown);q=u.on("pressup",this.buttonRelease)};this.addEventListener=function(a,b,d){r[a]=
b;h[a]=d};this.addEventListenerWithParams=function(a,b,d,c){r[a]=b;h[a]=d;t=c};this.buttonRelease=function(){n||(playSound("click",1,!1),u.scaleX=1,u.scaleY=1,r[ON_MOUSE_UP]&&r[ON_MOUSE_UP].call(h[ON_MOUSE_UP],t))};this.buttonDown=function(){n||(u.scaleX=.9,u.scaleY=.9,r[ON_MOUSE_DOWN]&&r[ON_MOUSE_DOWN].call(h[ON_MOUSE_DOWN]))};this.setPosition=function(a,b){u.x=a;u.y=b};this.changeText=function(a){w.text=a};this.setX=function(a){u.x=a};this.setY=function(a){u.y=a};this.getButtonImage=function(){return u};
this.getX=function(){return u.x};this.getY=function(){return u.y};this.getSprite=function(){return u};this._init(g,b,c,f,a,e,d,l);return this}
function CToggle(g,b,c,f,a){var e,d,l,n,k,p;this._init=function(a,b,c,g,k){d=[];l=[];var h=new createjs.SpriteSheet({images:[c],frames:{width:c.width/2,height:c.height,regX:c.width/2/2,regY:c.height/2},animations:{state_true:[0],state_false:[1]}});e=g;n=createSprite(h,"state_"+e,c.width/2/2,c.height/2,c.width/2,c.height);n.x=a;n.y=b;n.stop();s_bMobile||(n.cursor="pointer");k.addChild(n);this._initListener()};this.unload=function(){n.off("mousedown",k);n.off("pressup",p);a.removeChild(n)};this._initListener=
function(){k=n.on("mousedown",this.buttonDown);p=n.on("pressup",this.buttonRelease)};this.addEventListener=function(a,b,c){d[a]=b;l[a]=c};this.setCursorType=function(a){n.cursor=a};this.setActive=function(a){e=a;n.gotoAndStop("state_"+e)};this.buttonRelease=function(){n.scaleX=1;n.scaleY=1;playSound("click",1,!1);e=!e;n.gotoAndStop("state_"+e);d[ON_MOUSE_UP]&&d[ON_MOUSE_UP].call(l[ON_MOUSE_UP],e)};this.buttonDown=function(){n.scaleX=.9;n.scaleY=.9;d[ON_MOUSE_DOWN]&&d[ON_MOUSE_DOWN].call(l[ON_MOUSE_DOWN])};
this.setPosition=function(a,b){n.x=a;n.y=b};this._init(g,b,c,f,a)}
function CGfxButton(g,b,c,f){var a,e,d,l,n,k,p;this._init=function(b,c,g,k){e=!1;a=!0;d=[];l=[];n=createBitmap(g);n.x=b;n.y=c;n.regX=g.width/2;n.regY=g.height/2;s_bMobile||(n.cursor="pointer");k.addChild(n);this._initListener()};this.unload=function(){n.off("mousedown",k);n.off("pressup",p);f.removeChild(n)};this.setVisible=function(a){n.visible=a};this.setCursorType=function(a){n.cursor=a};this._initListener=function(){k=n.on("mousedown",this.buttonDown);p=n.on("pressup",this.buttonRelease)};this.addEventListener=
function(a,b,c){d[a]=b;l[a]=c};this.buttonRelease=function(){e||(a?(n.scaleX=1,n.scaleY=1):(new createjs.Tween.get(n)).to({y:n.y-50},100),playSound("click",1,!1),d[ON_MOUSE_UP]&&d[ON_MOUSE_UP].call(l[ON_MOUSE_UP]))};this.buttonDown=function(){e||(a?(n.scaleX=.9,n.scaleY=.9):(new createjs.Tween.get(n)).to({y:n.y+50},100),d[ON_MOUSE_DOWN]&&d[ON_MOUSE_DOWN].call(l[ON_MOUSE_DOWN]))};this.pulseAnimation=function(){createjs.Tween.get(n).to({scaleX:.9,scaleY:.9},850,createjs.Ease.quadOut).to({scaleX:1,scaleY:1},
650,createjs.Ease.quadIn).call(function(){r.pulseAnimation()})};this.trembleAnimation=function(){createjs.Tween.get(n).to({rotation:2},75,createjs.Ease.quadOut).to({rotation:-2},140,createjs.Ease.quadIn).to({rotation:0},75,createjs.Ease.quadIn).wait(750).call(function(){r.trembleAnimation()})};this.setPosition=function(a,b){n.x=a;n.y=b};this.setX=function(a){n.x=a};this.setY=function(a){n.y=a};this.setScalable=function(b){a=b};this.getButtonImage=function(){return n};this.getX=function(){return n.x};
this.getY=function(){return n.y};this.setClickable=function(a){e=!a};this._init(g,b,c,f);var r=this;return this}
function CMenu(){var g,b,c,f,a,e,d,l,n,k,p,r,h,m,q,t,u,w,v,z,C,x,D=null,F=null;this._init=function(){p=createBitmap(s_oSpriteLibrary.getSprite("bg_menu"));s_oStage.addChild(p);var x=s_oSpriteLibrary.getSprite("menu_text_minigolf");w=createBitmap(x);w.regX=x.width/2;w.regY=x.height/2;w.x=CANVAS_WIDTH;w.y=-CANVAS_HEIGHT/2+200;s_oStage.addChild(w);(new createjs.Tween.get(w)).to({x:CANVAS_WIDTH/2-270,y:CANVAS_HEIGHT/2-100},2E3,createjs.Ease.cubicOut);h=new createjs.Container;h.y=CANVAS_HEIGHT/2;h.rotation=
-30;s_oStage.addChild(h);x=s_oSpriteLibrary.getSprite("ball");r=createBitmap(x);r.regX=x.width/2;r.regY=x.height/2;h.addChild(r);(new createjs.Tween.get(r)).wait(2E3).to({x:CANVAS_WIDTH+100},8E3,createjs.Ease.quintOut);(new createjs.Tween.get(r)).wait(2E3).to({y:300},1500,createjs.Ease.bounceOut);x=s_oSpriteLibrary.getSprite("menu_text_world");v=createBitmap(x);v.regX=x.width/2;v.regY=x.height/2;v.x=-CANVAS_WIDTH/2;v.y=CANVAS_HEIGHT+400;s_oStage.addChild(v);(new createjs.Tween.get(v)).wait(500).to({x:CANVAS_WIDTH/
2-40,y:CANVAS_HEIGHT/2+30},2E3,createjs.Ease.cubicOut);s_oLocalStorage.isDirty()?(x=s_oSpriteLibrary.getSprite("but_continue"),a=CANVAS_WIDTH/2+450,e=CANVAS_HEIGHT-80,q=new CGfxButton(a,e,x,s_oStage),q.addEventListener(ON_MOUSE_UP,this._onButPlayRelease,this),q.setScalable(!1),q.trembleAnimation(),x=s_oSpriteLibrary.getSprite("but_play"),d=CANVAS_WIDTH/2+210,l=CANVAS_HEIGHT+65,m=new CGfxButton(d,l,x,s_oStage),m.addEventListener(ON_MOUSE_UP,this._onButReset,this),m.setScalable(!1)):(x=s_oSpriteLibrary.getSprite("but_play"),
d=CANVAS_WIDTH/2+350,l=CANVAS_HEIGHT-10,m=new CGfxButton(d,l,x,s_oStage),m.addEventListener(ON_MOUSE_UP,this._onButPlayRelease,this),m.setScalable(!1),m.trembleAnimation());x=s_oSpriteLibrary.getSprite("but_info");c=x.height/2+10;f=x.height/2+10;z=new CGfxButton(CANVAS_WIDTH/2,CANVAS_HEIGHT-240,x,s_oStage);z.addEventListener(ON_MOUSE_UP,this._onCreditsBut,this);if(!1===DISABLE_SOUND_MOBILE||!1===s_bMobile)x=s_oSpriteLibrary.getSprite("audio_icon"),n=CANVAS_WIDTH-x.height/2-10,k=x.height/2+10,u=new CToggle(n,
k,x,s_bAudioActive,s_oStage),u.addEventListener(ON_MOUSE_UP,this._onAudioToggle,this);x=window.document;var B=x.documentElement;D=B.requestFullscreen||B.mozRequestFullScreen||B.webkitRequestFullScreen||B.msRequestFullscreen;F=x.exitFullscreen||x.mozCancelFullScreen||x.webkitExitFullscreen||x.msExitFullscreen;!1===ENABLE_FULLSCREEN&&(D=!1);D&&screenfull.enabled&&(x=s_oSpriteLibrary.getSprite("but_fullscreen"),g=c+x.width/2+10,b=x.height/2+10,C=new CToggle(g,b,x,s_bFullscreen,s_oStage),C.addEventListener(ON_MOUSE_UP,
this._onFullscreenRelease,this));t=new createjs.Shape;t.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);s_oStage.addChild(t);createjs.Tween.get(t).to({alpha:0},1E3);s_bStorageAvailable||new CMsgBox(TEXT_ERR_LS,s_oStage);this.refreshButtonPos(s_iOffsetX,s_iOffsetY)};this.refreshButtonPos=function(a,d){z.setPosition(c+a,d+f);!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||u.setPosition(n-a,d+k);D&&screenfull.enabled&&C.setPosition(g+a,b+d)};this.unload=function(){m.unload();m=null;t.off("mousedown",
x);if(!1===DISABLE_SOUND_MOBILE||!1===s_bMobile)u.unload(),u=null;D&&screenfull.enabled&&C.unload();s_oStage.removeAllChildren();s_oMenu=null};this._onAudioToggle=function(){Howler.mute(s_bAudioActive);s_bAudioActive=!s_bAudioActive};this._onButPlayRelease=function(){var a=this;x=t.on("mousedown",function(){});createjs.Tween.get(t,{override:!0}).to({alpha:1},500).call(function(){a.unload();$(s_oMain).trigger("start_session");s_oMain.gotoLevelMenu()})};this._onButReset=function(){(new CAreYouSurePanel(s_oMenu.removeDataAndContinue)).changeMessage(TEXT_SAVE_REMOVE)};
this.removeDataAndContinue=function(){s_oLocalStorage.resetAllData();$(s_oMain).trigger("start_session");s_oMenu._onButPlayRelease()};this._onCreditsBut=function(){new CCreditsPanel};this.resetFullscreenBut=function(){C.setActive(s_bFullscreen)};this._onFullscreenRelease=function(){s_bFullscreen?F.call(window.document):D.call(window.document.documentElement);sizeHandler()};s_oMenu=this;this._init()}var s_oMenu=null;
function CGame(g,b){var c,f,a,e,d,l,n,k,p,r,h,m,q,t=null,u,w,v,z,C=!1,x,D=!1,F,K,B,P,Q,H,E,I,A,N,L=!1,W,y=null,J,V,U,R,G,O,T,M,S,Z,X,ja,ba,Y,da;this._init=function(a){x=!1;J=!0;V=!1;U=!0;k=!1;O=R=G=p=0;q=a;da=1;M={x:0,y:0};N={x:0,y:0,z:0};A=new CScenario(q+1);$(s_oMain).trigger("start_level",q);y=camera=createOrthoGraphicCamera();resizeCanvas3D();0===q?setVolume("soundtrack",.4):setVolume("soundtrack",0);playSound("ambience",1,!0);H={x:0,y:0};E=!1;F=I=Q=0;S=new createjs.Container;s_oStage.addChild(S);
Z=new createjs.Container;s_oStage.addChild(Z);X=new createjs.Container;s_oStage.addChild(X);ja=new createjs.Container;s_oStage.addChild(ja);h=new CBackground(q,S);ba=new createjs.Shape;ba.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);ja.addChild(ba)};this.getCamera=function(){return y};this.get3DBall=function(){return A.ballBody()};this.scenarioLoaded=function(){W=0;k=!0};this.setBallSleep=function(a){(U=a)?A.ballBody().sleep():A.ballBody().wakeUp()};this._init2DBall=function(){var a=
s_oSpriteLibrary.getSprite("ball_shadow");T=createBitmap(a);T.regX=12;T.regY=-5;T.x=N.x;T.y=N.y;S.addChild(T);a=s_oSpriteLibrary.getSprite("ball");v=new CBall(N.x,N.y,a,S);N=convert3dPosTo2dScreen(A.ballBody().position,y);this.setBallSleep(!0)};this._initFlags=function(){m=new createjs.Container;S.addChild(m);for(var a=s_oSpriteLibrary.getSprite("flag"),b=0;b<FLAGS_POS[q].length;b++){var d=createBitmap(a);d.regY=a.height;d.x=FLAGS_POS[q][b].x;d.y=FLAGS_POS[q][b].y;m.addChild(d)}};this.getLevel=function(){return q};
this.resetDragForce=function(){!0===C&&(H={x:z.x,y:z.y});r.refreshPowerBar(0);C=!1};this.onCalculateForce=function(){if(SHOW_3D_RENDER)if(r.refreshPowerBar(0),!1===C||!0===P||H.x===N.x&&H.y===N.y)s_oGame.resetDragForce();else{var a=new CVector2(N.x-H.x,N.y-H.y);C=!1;a.scalarProduct(FORCE_MULTIPLIER);var b=a.length();b>HIT_BALL_MIN_FORCE&&(b>HIT_BALL_MAX_FORCE&&(a.normalize(),a.scalarProduct(HIT_BALL_MAX_FORCE)),a.set(a.getX(),-a.getY()),a.rotate(Math.radians(45)),s_oGame.launchBall({x:a.getX(),y:a.getY()}),
F++,r.refreshLaunch(F));H.x=0;H.y=0;s_oGame.clickBall(!1)}};this.onDragPoint=function(a){!P&&D&&z&&(H={x:a.clientX,y:a.clientY},C=!0)};this.onClickPoint=function(a){50>distance(a.clientX,a.clientY,N.x,N.y)&&(z={x:v.getX(),y:v.getY()},s_oGame.clickBall(!0))};this.unload=function(){k=!1;w&&(w.unload(),w=null);u&&(u.unload(),u=null);s_oStage.removeAllChildren();r.unload();v.unload();null!==t&&t.unload();stopSound("ambience")};this.nextLevel=function(){q++;var a=s_oSpriteLibrary.getSprite("msg_box");
q>=NUM_HOLES?(t=new CEndPanel(a,F),t.show(F,Math.floor(I),q)):(this.unload(),s_oMain.loadSelectedLevel(q))};this.angleArrow=function(){SHOW_3D_RENDER||(v.getX(),v.getY())};this.clickBall=function(a){D=a};this.launchBall=function(a){if(0===q&&0===F)v.setMoving(!0),(new CHelpPanel(X)).stage2Help(a);else{this.setBallSleep(!1);P=!0;var b=A.ballBody();d=b.position.x;l=b.position.y;n=b.position.z;A.addImpulse(b,a);F++;r.refreshLaunch(F)}};this.onExit=function(){fa.unload();fa.unloadLevel();$(s_oMain).trigger("share_event",
p);$(s_oMain).trigger("end_level",q);$(s_oMain).trigger("end_session");setVolume("soundtrack",1);s_oMain.gotoMenu()};this._onExitHelp=function(){v.setVisible(!0);v.setMoving(!1);setVolume("soundtrack",0)};this._onExitHelp2=function(a){this.setBallSleep(!1);P=!0;var b=A.ballBody();d=b.position.x;l=b.position.y;n=b.position.z;A.addImpulse(b,a);F++;r.refreshLaunch(F)};this.moveBall=function(){var a=N;v.setPosition(a.x,a.y)};this.levelComplete=function(){k=!1;$(s_oMain).trigger("end_level",q);var a=s_oSpriteLibrary.getSprite("msg_box");
K=new CLevelCompletePanel(a);K.show(F,Math.floor(I),q)};this.unloadLevel=function(){P=!1};this.restartLevel=function(){$(s_oMain).trigger("restart_level",q);this.unload();this._init(q)};this.detectBallVelocityForLaunch=function(){if(!0===P)B.x<MIN_VELOCITY_FOR_LAUNCH&&B.x>-MIN_VELOCITY_FOR_LAUNCH&&B.y<MIN_VELOCITY_FOR_LAUNCH&&B.y>-MIN_VELOCITY_FOR_LAUNCH&&B.z<MIN_VELOCITY_FOR_LAUNCH&&B.z>-MIN_VELOCITY_FOR_LAUNCH?0>Q?(P=!1,v.setMoving(!1),E||v.pressIndicatorAnim(),A.setElementVelocity(A.ballBody(),
{x:0,y:0,z:0}),A.ballBody().angularVelocity.setZero(),E||this.setBallSleep(!0)):Q-=1/createjs.Ticker.framerate:Q=TIME_FOR_LAUNCH;else if(B.x>MIN_VELOCITY_FOR_LAUNCH||B.x<-MIN_VELOCITY_FOR_LAUNCH)P=!0,Q=TIME_FOR_LAUNCH};this.getBall=function(){return v};this.getBallVelocity=function(){return B};this.getBallPhysics=function(){return _oBallPhysics};this.getBallInSand=function(){return L};this.ballCollideWithTerrain=function(a){R=A.ballBody().position.z;!J&&a&&(J=!0,(new createjs.Tween.get(T,{override:!0})).to({alpha:1},
100));J&&!a&&(J=!1,U||(new createjs.Tween.get(T,{override:!0})).to({alpha:0},100))};this.ballCollideWithSand=function(a){a&&!L?(playSound("sand",1,!1),A.setElementLinearDamping(A.ballBody(),BALL_LINEAR_DAMPING_SAND)):!a&&L&&A.setElementLinearDamping(A.ballBody(),BALL_LINEAR_DAMPING);L=a};this.ballCollideWithWater=function(a){E||(G=A.ballBody().position.z);(E=a)?(A.setElementLinearDamping(A.ballBody(),BALL_LINEAR_DAMPING_WATER),A.setGravity(-49.81),a=G-A.ballBody().position.z,v.setWaterMask(-(a/RESTART_WATER_DEPTH_VALUE)+
1),a>RESTART_WATER_DEPTH_VALUE&&(A.setGravity(0),A.setElementVelocity(A.ballBody(),{x:0,y:0,z:0}),A.ballBody().force.setZero(),A.ballBody().torque.setZero(),A.ballBody().angularVelocity.setZero(),O+=1,60<O?this.repeatLastLaunch():1===O&&playSound("water",1,!1))):(A.setElementLinearDamping(A.ballBody(),BALL_LINEAR_DAMPING),A.setGravity(-98.1),v.setWaterMask(1),G=0)};this.ballCollideWithHole=function(a){x||(G=A.ballBody().position.z);x=a;var b=G-A.ballBody().position.z;a?(T.visible=!1,v.setHoleMask(-(b/
(HOLE_DEPTH_VALUE+5))+1),b>HOLE_DEPTH_VALUE&&(A.setGravity(0),A.setElementVelocity(A.ballBody(),{x:0,y:0,z:0}),playSound("hole",1,!1),this.levelComplete())):(T.visible=!0,3.5<b&&(playSound("hole",1,!1),A.setGravity(0),A.setElementVelocity(A.ballBody(),{x:0,y:0,z:0}),this.levelComplete()))};this._checkBallOutOfBorder=function(){if(-50>=A.ballBody().position.z&&!V){V=!0;var a=new createjs.Shape;a.graphics.beginFill("rgba(0,0,0,1)").r(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);a.alpha=0;s_oStage.addChild(a);(new createjs.Tween.get(a)).to({alpha:1},
500).call(function(){(new createjs.Tween.get(a)).to({alpha:0},500).call(function(){s_oStage.removeChild(a)});fa.repeatLastLaunch()})}};this.repeatLastLaunch=function(){V=!1;v.blink();v.resetMask();O=0;v.pressIndicatorAnim();this.centerBallView();r.setCenterBallViewVisible(!1);A.ballBody().force.setZero();A.ballBody().torque.setZero();A.ballBody().angularVelocity.setZero();A.setElementVelocity(A.ballBody(),{x:0,y:0,z:0});A.ballBody().position.set(d,l,n+15);this._updateBall2DPosition()};this._updateInit=
function(){A.update();if(A.ballBody()){this._init2DBall();this._initFlags();r=new CInterface(Z);r.refreshHoleNum(q+1);r.setParText(PAR[q]);var b=new THREE.Vector3(START_CAMERA_POSITION.x+A.ballBody().position.x,START_CAMERA_POSITION.y+A.ballBody().position.y,START_CAMERA_POSITION.z+A.ballBody().position.z);y.position.set(b.x,b.y,b.z);W=1;var d=convert3dPosTo2dScreen({x:START_CAMERA_POSITION.x,y:START_CAMERA_POSITION.y,z:START_CAMERA_POSITION.z},y),g=convert3dPosTo2dScreen(y.position,y);b=d.x-g.x;
d=d.y-g.y;h.setPos(CANVAS_WIDTH/2+b,CANVAS_HEIGHT/2+d);m.x=h.getPos().x;m.y=h.getPos().y;y.updateProjectionMatrix();y.updateMatrixWorld();c=h.getSize().width/2-CANVAS_WIDTH/2-b;f=-(h.getSize().width/2-CANVAS_WIDTH/2)-b;a=h.getSize().height/2-CANVAS_HEIGHT/2-d;e=-(h.getSize().height/2-CANVAS_HEIGHT/2)-d;createjs.Tween.get(ba).wait(800).to({alpha:0},1300).call(function(){da=.05;ba.visible=!1});0===q&&(new CHelpPanel(X)).stage1Help()}};this._updatePlay=function(){k&&(A.update(),this._updateBall2DPosition(),
this.moveBall(),this.angleArrow(),B=A.getBodyVelocity(A.ballBody()),this.detectBallVelocityForLaunch(),this._checkBallOutOfBorder())};this.update=function(){switch(W){case 0:this._updateInit();break;case 1:this._updatePlay()}};this.setPanPoint=function(b,d){var h=-N.x+CANVAS_WIDTH/2+M.x+b-S.x;S.x+h<c&&S.x+h>f&&(M.x+=b);h=-N.y+CANVAS_HEIGHT/2+M.y+d-S.y;S.y+h<a&&S.y+h>e&&(M.y+=d)};this.centerBallView=function(){M.x=0;M.y=0};this._updateBall2DPosition=function(){N=convert3dPosTo2dScreen(A.ballBody().position,
y);var b={x:A.ballBody().position.x,y:A.ballBody().position.y,z:R};b=convert3dPosTo2dScreen(b,y);T.x=b.x;T.y=b.y;S.x+=(-N.x+CANVAS_WIDTH/2+M.x-S.x)*da;S.x>c?S.x=c:S.x<f&&(S.x=f);S.y+=(-N.y+CANVAS_HEIGHT/2+M.y-S.y)*da;S.y>a?S.y=a:S.y<e&&(S.y=e)};this.panHelpAnim=function(){(new createjs.Tween.get(M,{loop:!0})).to({x:-500},700).to({x:0},700).to({y:-500},700).to({y:0},700);var a=s_oSpriteLibrary.getSprite("help_touch");Y=createBitmap(a);Y.x=300;Y.y=600;s_oStage.addChild(Y);(new createjs.Tween.get(Y,
{loop:!0})).to({x:100},700).to({x:300},700).to({y:400},700).to({y:600},700)};this.stopPanAnim=function(){M.x=0;M.y=0;new createjs.Tween.removeTweens(M);s_oStage.removeChild(Y);new createjs.Tween.removeTweens(Y)};s_oGame=this;MAX_SHOT_POWER=g.max_shot_power;160<MAX_SHOT_POWER&&(MAX_SHOT_POWER=160);PAR=g.stage_par;var fa=this;this._init(b)}var s_oGame;
function CInterface(g){var b,c,f,a,e,d,l,n,k,p,r,h,m,q,t,u,w,v,z,C,x,D,F,K,B,P,Q,H=null,E=null;this._init=function(g){m=CANVAS_WIDTH/2;q=72;B=new createjs.Text(TEXT_LAUNCH+": 0","40px "+PRIMARY_FONT,"#3e240b");B.x=m;B.y=q;B.outline=8;B.textAlign="center";B.textBaseline="alphabetic";g.addChild(B);z=new createjs.Text(TEXT_LAUNCH+": 0","40px "+PRIMARY_FONT,"#ffd800");z.x=m;z.y=q;z.textAlign="center";z.textBaseline="alphabetic";g.addChild(z);k=26;p=72;K=new createjs.Text(TEXT_PAR+": 0","40px "+PRIMARY_FONT,
"#3e240b");K.x=k;K.y=p;K.outline=8;K.textAlign="left";K.textBaseline="alphabetic";g.addChild(K);C=new createjs.Text(TEXT_PAR+": 0","40px "+PRIMARY_FONT,"#ffd800");C.x=k;C.y=p;C.textAlign="left";C.textBaseline="alphabetic";g.addChild(C);r=CANVAS_WIDTH-28;h=CANVAS_HEIGHT-35;P=new createjs.Text(TEXT_HOLE+": 1","40px "+PRIMARY_FONT,"#3e240b");P.x=r;P.y=h;P.outline=8;P.textAlign="right";P.textBaseline="alphabetic";g.addChild(P);x=new createjs.Text(TEXT_HOLE+": 1","40px "+PRIMARY_FONT,"#ffd800");x.x=r;
x.y=h;x.textAlign="right";x.textBaseline="alphabetic";g.addChild(x);var A=s_oSpriteLibrary.getSprite("but_exit");f=CANVAS_WIDTH-A.height/2-10;a=A.height/2+17;w=new CGfxButton(f,a,A,g);w.addEventListener(ON_MOUSE_UP,this._onExit,this);A=s_oSpriteLibrary.getSprite("but_restart_small");b=f-A.height-10;c=a;v=new CGfxButton(b,c,A,g);v.addEventListener(ON_MOUSE_UP,this._onRestart,this);!1===DISABLE_SOUND_MOBILE||!1===s_bMobile?(A=s_oSpriteLibrary.getSprite("audio_icon"),t=b-A.height-10,u=a,D=new CToggle(t,
u,A,s_bAudioActive,g),D.addEventListener(ON_MOUSE_UP,this._onAudioToggle,this),e=t-A.width/2-10,d=u):(e=b-A.width/2-10,d=c);A=window.document;var I=A.documentElement;H=I.requestFullscreen||I.mozRequestFullScreen||I.webkitRequestFullScreen||I.msRequestFullscreen;E=A.exitFullscreen||A.mozCancelFullScreen||A.webkitExitFullscreen||A.msExitFullscreen;!1===ENABLE_FULLSCREEN&&(H=!1);H&&screenfull.enabled&&(A=s_oSpriteLibrary.getSprite("but_fullscreen"),Q=new CToggle(e,d,A,s_bFullscreen,g),Q.addEventListener(ON_MOUSE_UP,
this._onFullscreenRelease,this));A=s_oSpriteLibrary.getSprite("but_center_view");l=A.height/2+10;n=CANVAS_HEIGHT-A.height/2-10;F=new CGfxButton(l,n,A,g);F.addEventListener(ON_MOUSE_UP,this._onCenterBall,this);F.setVisible(!1);this.refreshButtonPos(s_iOffsetX,s_iOffsetY)};this.refreshButtonPos=function(g,m){w.setPosition(f-g,m+a);v.setPosition(b-g,m+c);F.setPosition(l+g,n-m);!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||D.setPosition(t-g,m+u);H&&screenfull.enabled&&Q.setPosition(e-g,d+m);z.y=q+m;B.y=
z.y;x.x=r-g;x.y=h-m;P.x=x.x;P.y=x.y;C.x=k+g;C.y=p+m;K.x=C.x;K.y=C.y};this.refreshPowerBar=function(a){(void 0).graphics.clear();a=Math.floor(a*(void 0).width/100);(void 0).graphics.beginFill("rgba(255,255,255,0.01)").drawRect((void 0).x,(void 0).y,a,(void 0).height)};this.unload=function(){w.unload();w=null;if(!1===DISABLE_SOUND_MOBILE||!1===s_bMobile)D.unload(),D=null;H&&screenfull.enabled&&Q.unload();s_oInterface=null};this.refreshLaunch=function(a){z.text=TEXT_LAUNCH+": "+a;B.text=TEXT_LAUNCH+
": "+a};this.setParText=function(a){C.text=TEXT_PAR+": "+a;K.text=TEXT_PAR+": "+a};this.refreshHoleNum=function(a){x.text=TEXT_HOLE+": "+a;P.text=TEXT_HOLE+": "+a};this.setCenterBallViewVisible=function(a){F.setVisible(a)};this.onExitFromHelp=function(){(void 0).unload()};this._onAudioToggle=function(){Howler.mute(s_bAudioActive);s_bAudioActive=!s_bAudioActive};this._onExit=function(){new CAreYouSurePanel(s_oGame.onExit)};this._onRestart=function(){s_oGame.restartLevel()};this._onCenterBall=function(){F.setVisible(!1);
s_oGame.centerBallView()};this.resetFullscreenBut=function(){Q.setActive(s_bFullscreen)};this._onFullscreenRelease=function(){s_bFullscreen?E.call(window.document):H.call(window.document.documentElement);sizeHandler()};s_oInterface=this;this._init(g);return this}var s_oInterface=null;
function CCreditsPanel(){var g,b,c,f,a,e;this._init=function(){a=new createjs.Shape;a.graphics.beginFill("#0f0f0f").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);a.alpha=.01;e=a.on("click",this._onLogoButRelease);s_oStage.addChild(a);g=new createjs.Shape;g.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);g.alpha=0;s_oStage.addChild(g);(new createjs.Tween.get(g)).to({alpha:.7},500);b=new createjs.Container;s_oStage.addChild(b);var d=s_oSpriteLibrary.getSprite("msg_box"),l=createBitmap(d);
l.regX=d.width/2;l.regY=d.height/2;b.addChild(l);b.x=CANVAS_WIDTH/2;b.y=CANVAS_HEIGHT/2;b.alpha=0;(new createjs.Tween.get(b)).to({alpha:1},500);l=new createjs.Text(TEXT_DEVELOPED," 30px "+PRIMARY_FONT,"#3e240b");l.y=-d.height/2+175;l.textAlign="center";l.textBaseline="middle";l.lineWidth=500;l.outline=8;b.addChild(l);d=new createjs.Text(TEXT_DEVELOPED," 30px "+PRIMARY_FONT,"#ffd800");d.y=l.y;d.textAlign="center";d.textBaseline="middle";d.lineWidth=500;b.addChild(d);d=new createjs.Text("WWW.CODETHISLAB.COM",
" 30px "+PRIMARY_FONT,"#3e240b");d.y=160;d.textAlign="center";d.textBaseline="middle";d.lineWidth=500;d.outline=8;b.addChild(d);l=new createjs.Text("WWW.CODETHISLAB.COM"," 30px "+PRIMARY_FONT,"#ffd800");l.y=d.y;l.textAlign="center";l.textBaseline="middle";l.lineWidth=500;b.addChild(l);d=s_oSpriteLibrary.getSprite("ctl_logo");f=createBitmap(d);f.regX=d.width/2;f.regY=d.height/2;b.addChild(f);d=s_oSpriteLibrary.getSprite("but_exit");c=new CGfxButton(330,-200,d,b);c.addEventListener(ON_MOUSE_UP,this.unload,
this)};this.unload=function(){c.setClickable(!1);(new createjs.Tween.get(g)).to({alpha:0},500);(new createjs.Tween.get(b)).to({alpha:0},500).call(function(){s_oStage.removeChild(g);s_oStage.removeChild(b);c.unload()});a.off("click",e)};this._onLogoButRelease=function(){window.open("http://www.codethislab.com/index.php?&l=en")};this._onMoreGamesReleased=function(){window.open("http://codecanyon.net/collections/5409142-games")};this._init()}
function CHelpPanel(g){var b,c,f,a,e,d;this._init=function(d){var g=s_bMobile?TEXT_HELP1_MOBILE:TEXT_HELP1_PC;c=new createjs.Text(g,"24px "+PRIMARY_FONT,"#3e240b");c.textAlign="center";c.lineWidth=500;c.textBaseline="alphabetic";c.outline=8;c.x=.5*CANVAS_WIDTH-200;c.y=.5*CANVAS_HEIGHT-180;b=new createjs.Text(g,"24px "+PRIMARY_FONT,"#ffd800");b.textAlign="center";b.lineWidth=500;b.textBaseline="alphabetic";b.x=c.x;b.y=c.y;a=new createjs.Shape;a.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,
CANVAS_HEIGHT);a.alpha=.7;f=new createjs.Container;f.x=0;f.y=0;f.addChild(a,c,b);d.addChild(f);s_oGame.getBall().setVisible(!1);d=s_oSpriteLibrary.getSprite("ball");e=new CBall(800,484,d,f);e.setHelpAnim();e.setMoving(!0)};this.unload=function(){g.removeChild(f);f.off("mousedown",d)};this.stage1Help=function(){var a=this;d=f.on("mousedown",function(){a._onExitHelp()})};this.stage2Help=function(g){c.text=TEXT_HELP2;b.text=TEXT_HELP2;c.visible=!1;b.visible=!1;f.off("mousedown",d);s_oGame.getBall().setVisible(!0);
e.unload();a.alpha=0;createjs.Tween.get(a).to({alpha:.7},1E3).call(function(){c.visible=!0;b.visible=!0;d=f.on("mousedown",function(){l._onExitHelp2(g)});s_oGame.panHelpAnim()})};this._onExitHelp=function(){this.unload();s_oGame._onExitHelp()};this._onExitHelp2=function(a){this.unload();s_oGame.stopPanAnim();s_oGame._onExitHelp2(a)};var l=this;this._init(g)}
function CEndPanel(g){var b,c,f,a,e,d;this._init=function(g){setVolume("soundtrack",1);d=new createjs.Shape;d.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);d.alpha=1;d.on("mousedown",function(){});s_oStage.addChild(d);b=createBitmap(g);b.regX=g.width/2;b.regY=g.height/2;b.x=CANVAS_WIDTH/2;b.y=CANVAS_HEIGHT/2;f=new createjs.Text("","50px "+PRIMARY_FONT,"#3e240b");f.x=CANVAS_WIDTH/2;f.y=CANVAS_HEIGHT/2-100;f.outline=10;f.textAlign="center";f.textBaseline="alphabetic";f.lineWidth=
500;c=new createjs.Text("","50px "+PRIMARY_FONT,"#ffd800");c.x=f.x;c.y=f.y;c.textAlign="center";c.textBaseline="alphabetic";c.lineWidth=500;a=new createjs.Container;a.alpha=0;a.visible=!1;a.addChild(b,f,c);g=s_oSpriteLibrary.getSprite("but_home");e=new CGfxButton(.5*CANVAS_WIDTH,.5*CANVAS_HEIGHT+180,g,a);e.addEventListener(ON_MOUSE_DOWN,this._onExit,this);s_oStage.addChild(a);$(s_oMain).trigger("show_interlevel_ad")};this.unload=function(){};this.show=function(b,g,e){f.text=TEXT_ALL_COMPLETE;c.text=
TEXT_ALL_COMPLETE;a.visible=!0;createjs.Tween.get(a).to({alpha:1},500);createjs.Tween.get(d).to({alpha:.7},500)};this._onExit=function(){s_oStage.removeChild(a);e.unload();e=null;s_oGame.onExit()};this._init(g);return this}
function CAreYouSurePanel(g){var b,c,f,a,e,d,l;this._init=function(g){f=new createjs.Shape;f.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);f.alpha=0;l=f.on("mousedown",function(){});s_oStage.addChild(f);(new createjs.Tween.get(f)).to({alpha:.7},500);d=new createjs.Container;s_oStage.addChild(d);g=s_oSpriteLibrary.getSprite("msg_box");var k=createBitmap(g);k.regX=g.width/2;k.regY=g.height/2;d.addChild(k);d.x=CANVAS_WIDTH/2;d.y=CANVAS_HEIGHT/2;d.alpha=0;(new createjs.Tween.get(d)).to({alpha:1},
500);a=new createjs.Text(TEXT_ARE_SURE," 30px "+PRIMARY_FONT,"#3e240b");a.y=-g.height/2+200;a.textAlign="center";a.textBaseline="middle";a.lineWidth=700;a.outline=8;d.addChild(a);e=new createjs.Text(TEXT_ARE_SURE," 30px "+PRIMARY_FONT,"#ffd800");e.y=a.y;e.textAlign="center";e.textBaseline="middle";e.lineWidth=a.lineWidth;d.addChild(e);b=new CGfxButton(110,180,s_oSpriteLibrary.getSprite("but_yes"),d);b.addEventListener(ON_MOUSE_UP,this._onButYes,this);c=new CGfxButton(-110,180,s_oSpriteLibrary.getSprite("but_not"),
d);c.addEventListener(ON_MOUSE_UP,this._onButNo,this);c.pulseAnimation()};this._onButYes=function(){c.setClickable(!1);b.setClickable(!1);(new createjs.Tween.get(f)).to({alpha:1},500);(new createjs.Tween.get(d)).to({alpha:0},500).call(function(){n.unload();g()})};this._onButNo=function(){c.setClickable(!1);b.setClickable(!1);(new createjs.Tween.get(f)).to({alpha:0},500);(new createjs.Tween.get(d)).to({alpha:0},500).call(function(){n.unload()})};this.unload=function(){c.unload();b.unload();s_oStage.removeChild(f);
s_oStage.removeChild(d);f.off("mousedown",l)};this.changeMessage=function(b){a.text=b;e.text=b};var n=this;this._init(g)}var STAR_EFFECT_ALPHA=0,STAR_EFFECT_SCALE=1;
function CAchievementStars(g,b,c,f,a){var e,d,l,n;this._init=function(a,b,g,c,k){e=3;n=new createjs.Container;n.x=b;n.y=g;c.addChild(n);b=a.width/2;g=a.height;a=new createjs.SpriteSheet({images:[a],frames:{width:b,height:g,regX:b/2,regY:g/2},animations:{lit:[0],unlit:[1]}});d=[];for(g=0;g<e;g++)d[g]=createSprite(a,"unlit",0,0,0,0),d[g].x=-((e-1)*(b+0))/2+g*(b+0),n.addChild(d[g]);l=[];for(g=0;g<e;g++)l[g]=createSprite(a,"lit",0,0,0,0),l[g].x=-((e-1)*(b+0))/2+g*(b+0),l[g].scaleX=l[g].scaleY=0,l[g].alpha=
0,n.addChild(l[g]);l[1].y=-10;l[0].y=10;l[2].y=10;d[1].y=-10;d[0].y=10;d[2].y=10};this.unload=function(){for(var a=0;a<e;a++)new createjs.Tween.removeTweens(l[a]);f.removeChild(n)};this.getContainer=function(){return n};this.startLitStar=function(a){for(var b=0;b<a;b++)l[b].scaleX=l[b].scaleY=1,l[b].alpha=1};this.playSequentialMode=function(a,b,d){b/=a-1;switch(d){case STAR_EFFECT_SCALE:for(d=0;d<e;d++)l[d].alpha=1;for(d=0;d<a;d++)(new createjs.Tween.get(l[d])).wait(d*b).call(function(){k._playSound()}).to({scaleX:1,
scaleY:1},1500,createjs.Ease.elasticOut);break;case STAR_EFFECT_ALPHA:for(d=0;d<e;d++)l[d].scaleX=l[d].scaleY=1;for(d=0;d<a;d++)(new createjs.Tween.get(l[d])).wait(d*b).call(function(){k._playSound()}).to({alpha:1},750)}};this.playManualMode=function(a,b){switch(b){case STAR_EFFECT_SCALE:l[a].alpha=1;(new createjs.Tween.get(l[a])).to({scaleX:1,scaleY:1},1500,createjs.Ease.elasticOut);break;case STAR_EFFECT_ALPHA:l[a].scaleX=l[a].scaleY=1,(new createjs.Tween.get(l[a])).to({alpha:1},750)}this._playSound()};
this._playSound=function(){playSound(a,1,!1)};var k=this;this._init(g,b,c,f,a)}
function CLevelCompletePanel(g){var b,c,f,a,e,d,l,n,k,p,r,h,m,q,t,u,w;this._init=function(b){playSound("win_level",1,!1);q=new createjs.Shape;q.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);q.alpha=0;w=q.on("mousedown",function(){});s_oStage.addChild(q);c=createBitmap(b);c.regX=b.width/2;c.regY=b.height/2;c.x=CANVAS_WIDTH/2;c.y=CANVAS_HEIGHT/2;p=new createjs.Text("","50px "+PRIMARY_FONT,"#3e240b");p.x=CANVAS_WIDTH/2;p.y=CANVAS_HEIGHT/2-80;p.outline=10;p.textAlign="center";p.textBaseline=
"alphabetic";k=new createjs.Text("","50px "+PRIMARY_FONT,"#ffd800");k.x=p.x;k.y=p.y;k.textAlign="center";k.textBaseline="alphabetic";l=new createjs.Text("","30px "+PRIMARY_FONT,"#3e240b");l.x=CANVAS_WIDTH/2;l.y=p.y+100;l.outline=10;l.textAlign="center";l.textBaseline="alphabetic";n=new createjs.Text("","30px "+PRIMARY_FONT,"#ffd800");n.x=CANVAS_WIDTH/2;n.y=l.y;n.textAlign="center";n.textBaseline="alphabetic";f=new createjs.Text("","30px "+PRIMARY_FONT,"#3e240b");f.x=CANVAS_WIDTH/2-140;f.y=p.y+160;
f.outline=10;f.textAlign="center";f.textBaseline="alphabetic";a=new createjs.Text("","30px "+PRIMARY_FONT,"#ffd800");a.x=f.x;a.y=f.y;a.textAlign="center";a.textBaseline="alphabetic";e=new createjs.Text("0","30px "+PRIMARY_FONT,"#3e240b");e.x=CANVAS_WIDTH/2+140;e.y=f.y;e.outline=10;e.textAlign="center";e.textBaseline="alphabetic";d=new createjs.Text("0","30px "+PRIMARY_FONT,"#ffd800");d.x=e.x;d.y=a.y;d.textAlign="center";d.textBaseline="alphabetic";r=new createjs.Container;r.alpha=0;r.visible=!1;r.addChild(c,
f,a,p,k,l,n,e,d);s_oStage.addChild(r);$(s_oMain).trigger("show_interlevel_ad")};this._unload=function(){createjs.Tween.get(r).to({alpha:0},300).call(function(){s_oStage.removeChild(r);q.off("mousedown",w);s_oStage.removeChild(q);m.unload();m=null;h.unload();h=null})};this.show=function(b,g,c){p.text=TEXT_COMPLETE;k.text=TEXT_COMPLETE;g=b-PAR[c];b=this._scoreType(g,b);l.text=b;n.text=b;f.text=TEXT_SCORE+": ";a.text=TEXT_SCORE+": ";b=this._calculateScore(g);r.visible=!0;var w=this;createjs.Tween.get(r).to({alpha:1},
500).call(function(){var a=s_oSpriteLibrary.getSprite("but_continue_big");h=new CGfxButton(.5*CANVAS_WIDTH+100,.5*CANVAS_HEIGHT+180,a,r);h.addEventListener(ON_MOUSE_DOWN,w._onNext,this);a=s_oSpriteLibrary.getSprite("but_restart_big");m=new CGfxButton(.5*CANVAS_WIDTH-100,.5*CANVAS_HEIGHT+180,a,r);m.addEventListener(ON_MOUSE_DOWN,w._onRestart,this)});createjs.Tween.get(q).to({alpha:.7},500);g=s_oSpriteLibrary.getSprite("star");t=new CAchievementStars(g,CANVAS_WIDTH/2,CANVAS_HEIGHT/2-210,r,"star");u=
new CRollingTextController(d,e,b,8E3,EASE_CUBIC_OUT);u.addEventListener(ON_CONTROLLER_END,v._onFinishRolling);u.addEventListener(ON_CONTROLLER_REMOVE,v._onFinishRolling);u.addRollingListener(v._onRollingText,v,[0,PAR_POINTS-ADDED_POINTS,PAR_POINTS]);this._sendScore(c,b)};this._scoreType=function(a,b){switch(a){case -5:var d=TEXT_PHOENIX;break;case -4:d=TEXT_CONDOR;break;case -3:d=TEXT_ALBATROSS;break;case -2:d=TEXT_EAGLE;break;case -1:d=TEXT_BIRDIE;break;case 0:d=TEXT_PAR;break;case 1:d=TEXT_BOGEY;
break;case 2:d=TEXT_DOUBLE_BOGEY;break;default:d=TEXT_BOGEY+" "+a}1===b&&(d=TEXT_HOLEINONE);return d};this._findMinimumScore=function(){for(var a=PAR_POINTS,b=0;0<a;)b++,a-=ADDED_POINTS;a+=ADDED_POINTS;return{score:a,iter:b}};this._calculateScore=function(a){var b=PAR_POINTS-a*ADDED_POINTS;0>=b&&(b=this._findMinimumScore(),b=Math.floor(b.score/(a-b.iter+1)));return b};this._sendScore=function(a,d){var g=s_oLocalStorage.getItemJson(LOCALSTORAGE_SCORE);g[a]<d&&(g[a]=d,s_oLocalStorage.setItemJson(LOCALSTORAGE_SCORE,
g));for(var c=b=0;c<g.length;c++)b+=g[c];$(s_oMain).trigger("save_score",b)};this._onNext=function(){createjs.Tween.get(q).to({alpha:1},300);createjs.Tween.get(r).to({alpha:0},300).wait(100).call(function(){s_oStage.removeChild(r);q.off("mousedown",w);s_oStage.removeChild(q);m.unload();m=null;h.unload();h=null;s_oGame.nextLevel()})};this._onRestart=function(){createjs.Tween.get(q).to({alpha:1},300);createjs.Tween.get(r).to({alpha:0},300).wait(100).call(function(){s_oStage.removeChild(r);q.off("mousedown",
w);s_oStage.removeChild(q);m.unload();m=null;h.unload();h=null;s_oGame.restartLevel()})};this._onFinishRolling=function(){};this._onRollingRemoved=function(){};this._onRollingText=function(a){t.playManualMode(a,STAR_EFFECT_SCALE)};var v=this;this._init(g);return this}
!function(g){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=g();else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self);b.CANNON=g()}}(function(){return function a(b,c,f){function e(l,k){if(!c[l]){if(!b[l]){var p="function"==typeof require&&require;if(!k&&p)return p(l,!0);if(d)return d(l,!0);throw Error("Cannot find module '"+l+"'");}p=c[l]={exports:{}};b[l][0].call(p.exports,function(a){var d=b[l][1][a];return e(d?
d:a)},p,p.exports,a,b,c,f)}return c[l].exports}for(var d="function"==typeof require&&require,l=0;l<f.length;l++)e(f[l]);return e}({1:[function(b,c,f){c.exports={name:"cannon",version:"0.6.2",description:"A lightweight 3D physics engine written in JavaScript.",homepage:"https://github.com/schteppe/cannon.js",author:"Stefan Hedman <schteppe@gmail.com> (http://steffe.se)",keywords:["cannon.js","cannon","physics","engine","3d"],main:"./build/cannon.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/cannon.js.git"},
bugs:{url:"https://github.com/schteppe/cannon.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest","uglify-js":"latest",nodeunit:"^0.9.0",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"^0.5.1","grunt-browserify":"^2.1.4","grunt-contrib-yuidoc":"^0.5.2",browserify:"*"},dependencies:{}}},{}],2:[function(b,c,f){c.exports={version:b("../package.json").version,AABB:b("./collision/AABB"),ArrayCollisionMatrix:b("./collision/ArrayCollisionMatrix"),
Body:b("./objects/Body"),Box:b("./shapes/Box"),Broadphase:b("./collision/Broadphase"),Constraint:b("./constraints/Constraint"),ContactEquation:b("./equations/ContactEquation"),Narrowphase:b("./world/Narrowphase"),ConeTwistConstraint:b("./constraints/ConeTwistConstraint"),ContactMaterial:b("./material/ContactMaterial"),ConvexPolyhedron:b("./shapes/ConvexPolyhedron"),Cylinder:b("./shapes/Cylinder"),DistanceConstraint:b("./constraints/DistanceConstraint"),Equation:b("./equations/Equation"),EventTarget:b("./utils/EventTarget"),
FrictionEquation:b("./equations/FrictionEquation"),GSSolver:b("./solver/GSSolver"),GridBroadphase:b("./collision/GridBroadphase"),Heightfield:b("./shapes/Heightfield"),HingeConstraint:b("./constraints/HingeConstraint"),LockConstraint:b("./constraints/LockConstraint"),Mat3:b("./math/Mat3"),Material:b("./material/Material"),NaiveBroadphase:b("./collision/NaiveBroadphase"),ObjectCollisionMatrix:b("./collision/ObjectCollisionMatrix"),Pool:b("./utils/Pool"),Particle:b("./shapes/Particle"),Plane:b("./shapes/Plane"),
PointToPointConstraint:b("./constraints/PointToPointConstraint"),Quaternion:b("./math/Quaternion"),Ray:b("./collision/Ray"),RaycastVehicle:b("./objects/RaycastVehicle"),RaycastResult:b("./collision/RaycastResult"),RigidVehicle:b("./objects/RigidVehicle"),RotationalEquation:b("./equations/RotationalEquation"),RotationalMotorEquation:b("./equations/RotationalMotorEquation"),SAPBroadphase:b("./collision/SAPBroadphase"),SPHSystem:b("./objects/SPHSystem"),Shape:b("./shapes/Shape"),Solver:b("./solver/Solver"),
Sphere:b("./shapes/Sphere"),SplitSolver:b("./solver/SplitSolver"),Spring:b("./objects/Spring"),Trimesh:b("./shapes/Trimesh"),Vec3:b("./math/Vec3"),Vec3Pool:b("./utils/Vec3Pool"),World:b("./world/World")}},{"../package.json":1,"./collision/AABB":3,"./collision/ArrayCollisionMatrix":4,"./collision/Broadphase":5,"./collision/GridBroadphase":6,"./collision/NaiveBroadphase":7,"./collision/ObjectCollisionMatrix":8,"./collision/Ray":9,"./collision/RaycastResult":10,"./collision/SAPBroadphase":11,"./constraints/ConeTwistConstraint":12,
"./constraints/Constraint":13,"./constraints/DistanceConstraint":14,"./constraints/HingeConstraint":15,"./constraints/LockConstraint":16,"./constraints/PointToPointConstraint":17,"./equations/ContactEquation":19,"./equations/Equation":20,"./equations/FrictionEquation":21,"./equations/RotationalEquation":22,"./equations/RotationalMotorEquation":23,"./material/ContactMaterial":24,"./material/Material":25,"./math/Mat3":27,"./math/Quaternion":28,"./math/Vec3":30,"./objects/Body":31,"./objects/RaycastVehicle":32,
"./objects/RigidVehicle":33,"./objects/SPHSystem":34,"./objects/Spring":35,"./shapes/Box":37,"./shapes/ConvexPolyhedron":38,"./shapes/Cylinder":39,"./shapes/Heightfield":40,"./shapes/Particle":41,"./shapes/Plane":42,"./shapes/Shape":43,"./shapes/Sphere":44,"./shapes/Trimesh":45,"./solver/GSSolver":46,"./solver/Solver":47,"./solver/SplitSolver":48,"./utils/EventTarget":49,"./utils/Pool":51,"./utils/Vec3Pool":54,"./world/Narrowphase":55,"./world/World":56}],3:[function(b,c,f){function a(a){a=a||{};
this.lowerBound=new e;a.lowerBound&&this.lowerBound.copy(a.lowerBound);this.upperBound=new e;a.upperBound&&this.upperBound.copy(a.upperBound)}var e=b("../math/Vec3");b("../utils/Utils");c.exports=a;var d=new e;a.prototype.setFromPoints=function(a,b,c,e){var h=this.lowerBound,m=this.upperBound;h.copy(a[0]);c&&c.vmult(h,h);m.copy(h);for(var k=1;k<a.length;k++){var p=a[k];c&&(c.vmult(p,d),p=d);p.x>m.x&&(m.x=p.x);p.x<h.x&&(h.x=p.x);p.y>m.y&&(m.y=p.y);p.y<h.y&&(h.y=p.y);p.z>m.z&&(m.z=p.z);p.z<h.z&&(h.z=
p.z)}b&&(b.vadd(h,h),b.vadd(m,m));e&&(h.x-=e,h.y-=e,h.z-=e,m.x+=e,m.y+=e,m.z+=e);return this};a.prototype.copy=function(a){this.lowerBound.copy(a.lowerBound);this.upperBound.copy(a.upperBound);return this};a.prototype.clone=function(){return(new a).copy(this)};a.prototype.extend=function(a){var b=a.lowerBound.x;this.lowerBound.x>b&&(this.lowerBound.x=b);b=a.upperBound.x;this.upperBound.x<b&&(this.upperBound.x=b);b=a.lowerBound.y;this.lowerBound.y>b&&(this.lowerBound.y=b);b=a.upperBound.y;this.upperBound.y<
b&&(this.upperBound.y=b);b=a.lowerBound.z;this.lowerBound.z>b&&(this.lowerBound.z=b);b=a.upperBound.z;this.upperBound.z<b&&(this.upperBound.z=b)};a.prototype.overlaps=function(a){var b=this.lowerBound,d=this.upperBound,c=a.lowerBound;a=a.upperBound;return(c.x<=d.x&&d.x<=a.x||b.x<=a.x&&a.x<=d.x)&&(c.y<=d.y&&d.y<=a.y||b.y<=a.y&&a.y<=d.y)&&(c.z<=d.z&&d.z<=a.z||b.z<=a.z&&a.z<=d.z)};a.prototype.contains=function(a){var b=this.lowerBound,d=this.upperBound,c=a.lowerBound;a=a.upperBound;return b.x<=c.x&&
d.x>=a.x&&b.y<=c.y&&d.y>=a.y&&b.z<=c.z&&d.z>=a.z};a.prototype.getCorners=function(a,b,d,c,h,m,e,l){var k=this.lowerBound,q=this.upperBound;a.copy(k);b.set(q.x,k.y,k.z);d.set(q.x,q.y,k.z);c.set(k.x,q.y,q.z);h.set(q.x,k.y,k.z);m.set(k.x,q.y,k.z);e.set(k.x,k.y,q.z);l.copy(q)};var l=[new e,new e,new e,new e,new e,new e,new e,new e];a.prototype.toLocalFrame=function(a,b){this.getCorners(l[0],l[1],l[2],l[3],l[4],l[5],l[6],l[7]);for(var d=0;8!==d;d++){var c=l[d];a.pointToLocal(c,c)}return b.setFromPoints(l)};
a.prototype.toWorldFrame=function(a,b){this.getCorners(l[0],l[1],l[2],l[3],l[4],l[5],l[6],l[7]);for(var d=0;8!==d;d++){var c=l[d];a.pointToWorld(c,c)}return b.setFromPoints(l)}},{"../math/Vec3":30,"../utils/Utils":53}],4:[function(b,c,f){function a(){this.matrix=[]}c.exports=a;a.prototype.get=function(a,b){a=a.index;b=b.index;if(b>a){var d=b;b=a;a=d}return this.matrix[(a*(a+1)>>1)+b-1]};a.prototype.set=function(a,b,c){a=a.index;b=b.index;if(b>a){var d=b;b=a;a=d}this.matrix[(a*(a+1)>>1)+b-1]=c?1:0};
a.prototype.reset=function(){for(var a=0,b=this.matrix.length;a!==b;a++)this.matrix[a]=0};a.prototype.setNumObjects=function(a){this.matrix.length=a*(a-1)>>1}},{}],5:[function(b,c,f){function a(){this.world=null;this.useBoundingBoxes=!1;this.dirty=!0}var e=b("../objects/Body");f=b("../math/Vec3");var d=b("../math/Quaternion");b("../shapes/Shape");b("../shapes/Plane");c.exports=a;a.prototype.collisionPairs=function(a,b,d){throw Error("collisionPairs not implemented for this BroadPhase class!");};var l=
e.STATIC|e.KINEMATIC;a.prototype.needBroadphaseCollision=function(a,b){return 0!==(a.collisionFilterGroup&b.collisionFilterMask)&&0!==(b.collisionFilterGroup&a.collisionFilterMask)&&(0===(a.type&l)&&a.sleepState!==e.SLEEPING||0===(b.type&l)&&b.sleepState!==e.SLEEPING)?!0:!1};a.prototype.intersectionTest=function(a,b,d,c){this.useBoundingBoxes?this.doBoundingBoxBroadphase(a,b,d,c):this.doBoundingSphereBroadphase(a,b,d,c)};var n=new f;new f;new d;new f;a.prototype.doBoundingSphereBroadphase=function(a,
b,d,c){b.position.vsub(a.position,n);var h=Math.pow(a.boundingRadius+b.boundingRadius,2);n.norm2()<h&&(d.push(a),c.push(b))};a.prototype.doBoundingBoxBroadphase=function(a,b,d,c){a.aabbNeedsUpdate&&a.computeAABB();b.aabbNeedsUpdate&&b.computeAABB();a.aabb.overlaps(b.aabb)&&(d.push(a),c.push(b))};var k={keys:[]},p=[],r=[];a.prototype.makePairsUnique=function(a,b){for(var d=a.length,c=0;c!==d;c++)p[c]=a[c],r[c]=b[c];a.length=0;for(c=b.length=0;c!==d;c++){var h=p[c].id,m=r[c].id;h=h<m?h+","+m:m+","+
h;k[h]=c;k.keys.push(h)}for(c=0;c!==k.keys.length;c++)h=k.keys.pop(),d=k[h],a.push(p[d]),b.push(r[d]),delete k[h]};a.prototype.setWorld=function(a){};var h=new f;a.boundingSphereCheck=function(a,b){a.position.vsub(b.position,h);return Math.pow(a.shape.boundingSphereRadius+b.shape.boundingSphereRadius,2)>h.norm2()};a.prototype.aabbQuery=function(a,b,d){console.warn(".aabbQuery is not implemented in this Broadphase subclass.");return[]}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,
"../shapes/Plane":42,"../shapes/Shape":43}],6:[function(b,c,f){function a(a,b,c,h,m){e.apply(this);this.nx=c||10;this.ny=h||10;this.nz=m||10;this.aabbMin=a||new d(100,100,100);this.aabbMax=b||new d(-100,-100,-100);a=this.nx*this.ny*this.nz;if(0>=a)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[];this.binLengths=[];this.bins.length=a;this.binLengths.length=a;for(b=0;b<a;b++)this.bins[b]=[],this.binLengths[b]=0}c.exports=a;var e=b("./Broadphase"),d=b("../math/Vec3"),l=b("../shapes/Shape");
a.prototype=new e;a.prototype.constructor=a;var n=new d;new d;a.prototype.collisionPairs=function(a,b,d){function c(a,b,d,c,h,e,m){a=(a-K)*Q|0;b=(b-B)*H|0;d=(d-P)*E|0;c=J((c-K)*Q);h=J((h-B)*H);e=J((e-P)*E);0>a?a=0:a>=p&&(a=p-1);0>b?b=0:b>=r&&(b=r-1);0>d?d=0:d>=f&&(d=f-1);0>c?c=0:c>=p&&(c=p-1);0>h?h=0:h>=r&&(h=r-1);0>e?e=0:e>=f&&(e=f-1);a*=z;b*=C;d*=1;c*=z;h*=C;for(e*=1;a<=c;a+=z)for(var k=b;k<=h;k+=C)for(var q=d;q<=e;q+=1){var l=a+k+q;W[l][y[l]++]=m}}var m=a.numObjects();a=a.bodies;var e=this.aabbMax,
k=this.aabbMin,p=this.nx,r=this.ny,f=this.nz,z=r*f,C=f,x=e.x,D=e.y,F=e.z,K=k.x,B=k.y,P=k.z,Q=p/(x-K),H=r/(D-B),E=f/(F-P);x=(x-K)/p;var I=(D-B)/r;F=(F-P)/f;var A=.5*Math.sqrt(x*x+I*I+F*F);D=l.types;var N=D.SPHERE,L=D.PLANE,W=this.bins,y=this.binLengths;D=this.bins.length;for(k=0;k!==D;k++)y[k]=0;var J=Math.ceil;k=Math.min;e=Math.max;for(k=0;k!==m;k++){e=a[k];var V=e.shape;switch(V.type){case N:var U=e.position.x,R=e.position.y,G=e.position.z;V=V.radius;c(U-V,R-V,G-V,U+V,R+V,G+V,e);break;case L:V.worldNormalNeedsUpdate&&
V.computeWorldNormal(e.quaternion);G=V.worldNormal;V=B+.5*I-e.position.y;var O=P+.5*F-e.position.z,T=n;T.set(K+.5*x-e.position.x,V,O);for(var M=U=0;U!==p;U++,M+=z,T.y=V,T.x+=x)for(var S=R=0;R!==r;R++,S+=C,T.z=O,T.y+=I)for(var Z=0,X=0;Z!==f;Z++,X+=1,T.z+=F)if(T.dot(G)<A){var ja=M+S+X;W[ja][y[ja]++]=e}break;default:e.aabbNeedsUpdate&&e.computeAABB(),c(e.aabb.lowerBound.x,e.aabb.lowerBound.y,e.aabb.lowerBound.z,e.aabb.upperBound.x,e.aabb.upperBound.y,e.aabb.upperBound.z,e)}}for(k=0;k!==D;k++)if(m=y[k],
1<m)for(a=W[k],U=0;U!==m;U++)for(e=a[U],R=0;R!==U;R++)x=a[R],this.needBroadphaseCollision(e,x)&&this.intersectionTest(e,x,b,d);this.makePairsUnique(b,d)}},{"../math/Vec3":30,"../shapes/Shape":43,"./Broadphase":5}],7:[function(b,c,f){function a(){e.apply(this)}c.exports=a;var e=b("./Broadphase");b=b("./AABB");a.prototype=new e;a.prototype.constructor=a;a.prototype.collisionPairs=function(a,b,c){a=a.bodies;var d=a.length,e,l;for(e=0;e!==d;e++)for(l=0;l!==e;l++){var h=a[e];var m=a[l];this.needBroadphaseCollision(h,
m)&&this.intersectionTest(h,m,b,c)}};new b;a.prototype.aabbQuery=function(a,b,c){c=c||[];for(var d=0;d<a.bodies.length;d++){var e=a.bodies[d];e.aabbNeedsUpdate&&e.computeAABB();e.aabb.overlaps(b)&&c.push(e)}return c}},{"./AABB":3,"./Broadphase":5}],8:[function(b,c,f){function a(){this.matrix={}}c.exports=a;a.prototype.get=function(a,b){a=a.id;b=b.id;if(b>a){var d=b;b=a;a=d}return a+"-"+b in this.matrix};a.prototype.set=function(a,b,c){a=a.id;b=b.id;if(b>a){var d=b;b=a;a=d}c?this.matrix[a+"-"+b]=!0:
delete this.matrix[a+"-"+b]};a.prototype.reset=function(){this.matrix={}};a.prototype.setNumObjects=function(a){}},{}],9:[function(b,c,f){function a(b,c){this.from=b?b.clone():new d;this.to=c?c.clone():new d;this._direction=new d;this.precision=1E-4;this.checkCollisionResponse=!0;this.skipBackfaces=!1;this.collisionFilterGroup=this.collisionFilterMask=-1;this.mode=a.ANY;this.result=new n;this.hasHit=!1;this.callback=function(a){}}function e(a,b,d,c){c.vsub(b,N);d.vsub(b,r);a.vsub(b,h);a=N.dot(N);
b=N.dot(r);d=N.dot(h);c=r.dot(r);var e=r.dot(h),m,k;return 0<=(m=c*d-b*e)&&0<=(k=a*e-b*d)&&m+k<a*c-b*b}c.exports=a;var d=b("../math/Vec3");c=b("../math/Quaternion");var l=b("../math/Transform");b("../shapes/ConvexPolyhedron");b("../shapes/Box");var n=b("../collision/RaycastResult");f=b("../shapes/Shape");b=b("../collision/AABB");a.prototype.constructor=a;a.CLOSEST=1;a.ANY=2;a.ALL=4;var k=new b,p=[];a.prototype.intersectWorld=function(b,d){this.mode=d.mode||a.ANY;this.result=d.result||new n;this.skipBackfaces=
!!d.skipBackfaces;this.collisionFilterMask="undefined"!==typeof d.collisionFilterMask?d.collisionFilterMask:-1;this.collisionFilterGroup="undefined"!==typeof d.collisionFilterGroup?d.collisionFilterGroup:-1;d.from&&this.from.copy(d.from);d.to&&this.to.copy(d.to);this.callback=d.callback||function(){};this.hasHit=!1;this.result.reset();this._updateDirection();this.getAABB(k);p.length=0;b.broadphase.aabbQuery(b,k,p);this.intersectBodies(p);return this.hasHit};var r=new d,h=new d;a.pointInTriangle=e;
var m=new d,q=new c;a.prototype.intersectBody=function(a,b){b&&(this.result=b,this._updateDirection());var d=this.checkCollisionResponse;if((!d||a.collisionResponse)&&0!==(this.collisionFilterGroup&a.collisionFilterMask)&&0!==(a.collisionFilterGroup&this.collisionFilterMask))for(var c=0,h=a.shapes.length;c<h;c++){var e=a.shapes[c];if(!d||e.collisionResponse)if(a.quaternion.mult(a.shapeOrientations[c],q),a.quaternion.vmult(a.shapeOffsets[c],m),m.vadd(a.position,m),this.intersectShape(e,q,m,a),this.result._shouldStop)break}};
a.prototype.intersectBodies=function(a,b){b&&(this.result=b,this._updateDirection());for(var d=0,c=a.length;!this.result._shouldStop&&d<c;d++)this.intersectBody(a[d])};a.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction);this._direction.normalize()};a.prototype.intersectShape=function(a,b,d,c){var h=this.from,e=this._direction;d.vsub(h,N);var m=N.dot(e);e.mult(m,L);L.vadd(h,L);d.distanceTo(L)>a.boundingSphereRadius||(h=this[a.type])&&h.call(this,a,b,d,c)};new d;new d;var t=
new d,u=new d,w=new d,v=new d;new d;new n;a.prototype.intersectBox=function(a,b,d,c){return this.intersectConvex(a.convexPolyhedronRepresentation,b,d,c)};a.prototype[f.types.BOX]=a.prototype.intersectBox;a.prototype.intersectPlane=function(a,b,c,h){var e=this.from,m=this.to,k=this._direction,q=new d(0,0,1);b.vmult(q,q);var l=new d;e.vsub(c,l);b=l.dot(q);m.vsub(c,l);l=l.dot(q);if(!(0<b*l||e.distanceTo(m)<b||(l=q.dot(k),Math.abs(l)<this.precision))){var p=new d;m=new d;b=new d;e.vsub(c,p);c=-q.dot(p)/
l;k.scale(c,m);e.vadd(m,b);this.reportIntersection(q,b,a,h,-1)}};a.prototype[f.types.PLANE]=a.prototype.intersectPlane;a.prototype.getAABB=function(a){var b=this.to,d=this.from;a.lowerBound.x=Math.min(b.x,d.x);a.lowerBound.y=Math.min(b.y,d.y);a.lowerBound.z=Math.min(b.z,d.z);a.upperBound.x=Math.max(b.x,d.x);a.upperBound.y=Math.max(b.y,d.y);a.upperBound.z=Math.max(b.z,d.z)};var z={faceList:[0]};a.prototype.intersectHeightfield=function(b,c,h,e){var m=new d,k=new a(this.from,this.to);l.pointToLocalFrame(h,
c,k.from,k.from);l.pointToLocalFrame(h,c,k.to,k.to);var q=[],p=null,r=null,f=null,t=null,n=b.getIndexOfPosition(k.from.x,k.from.y,q,!1);n&&(p=q[0],r=q[1],f=q[0],t=q[1]);if(n=b.getIndexOfPosition(k.to.x,k.to.y,q,!1)){if(null===p||q[0]<p)p=q[0];if(null===f||q[0]>f)f=q[0];if(null===r||q[1]<r)r=q[1];if(null===t||q[1]>t)t=q[1]}if(null!==p)for(b.getRectMinMax(p,r,f,t,[]),k=p;k<=f;k++)for(q=r;q<=t;q++){if(this.result._shouldStop)return;b.getConvexTrianglePillar(k,q,!1);l.pointToWorldFrame(h,c,b.pillarOffset,
m);this.intersectConvex(b.pillarConvex,c,m,e,z);if(this.result._shouldStop)return;b.getConvexTrianglePillar(k,q,!0);l.pointToWorldFrame(h,c,b.pillarOffset,m);this.intersectConvex(b.pillarConvex,c,m,e,z)}};a.prototype[f.types.HEIGHTFIELD]=a.prototype.intersectHeightfield;var C=new d,x=new d;a.prototype.intersectSphere=function(a,b,d,c){b=this.from;var h=this.to,e=Math.pow(h.x-b.x,2)+Math.pow(h.y-b.y,2)+Math.pow(h.z-b.z,2),m=2*((h.x-b.x)*(b.x-d.x)+(h.y-b.y)*(b.y-d.y)+(h.z-b.z)*(b.z-d.z)),k=Math.pow(m,
2)-4*e*(Math.pow(b.x-d.x,2)+Math.pow(b.y-d.y,2)+Math.pow(b.z-d.z,2)-Math.pow(a.radius,2));if(!(0>k))if(0===k)b.lerp(h,k,C),C.vsub(d,x),x.normalize(),this.reportIntersection(x,C,a,c,-1);else{var q=(-m-Math.sqrt(k))/(2*e);e=(-m+Math.sqrt(k))/(2*e);0<=q&&1>=q&&(b.lerp(h,q,C),C.vsub(d,x),x.normalize(),this.reportIntersection(x,C,a,c,-1));!this.result._shouldStop&&0<=e&&1>=e&&(b.lerp(h,e,C),C.vsub(d,x),x.normalize(),this.reportIntersection(x,C,a,c,-1))}};a.prototype[f.types.SPHERE]=a.prototype.intersectSphere;
var D=new d;new d;new d;var F=new d;a.prototype.intersectConvex=function(a,b,d,c,h){h=h&&h.faceList||null;for(var m=a.faces,k=a.vertices,q=a.faceNormals,l=this._direction,p=this.from,r=p.distanceTo(this.to),f=h?h.length:m.length,n=this.result,y=0;!n._shouldStop&&y<f;y++){var x=h?h[y]:y,L=m[x],B=q[x],A=b,J=d;F.copy(k[L[0]]);A.vmult(F,F);F.vadd(J,F);F.vsub(p,F);A.vmult(B,D);B=l.dot(D);if(!(Math.abs(B)<this.precision||(B=D.dot(F)/B,0>B)))for(l.mult(B,t),t.vadd(p,t),u.copy(k[L[0]]),A.vmult(u,u),J.vadd(u,
u),B=1;!n._shouldStop&&B<L.length-1;B++){w.copy(k[L[B]]);v.copy(k[L[B+1]]);A.vmult(w,w);A.vmult(v,v);J.vadd(w,w);J.vadd(v,v);var z=t.distanceTo(p);!e(t,u,w,v)&&!e(t,w,u,v)||z>r||this.reportIntersection(D,t,a,c,x)}}};a.prototype[f.types.CONVEXPOLYHEDRON]=a.prototype.intersectConvex;var K=new d,B=new d,P=new d,Q=new d,H=new d,E=new d;new b;var I=[],A=new l;a.prototype.intersectTrimesh=function(a,b,d,c,h){h=a.indices;var m=this.from,k=this.to,q=this._direction;A.position.copy(d);A.quaternion.copy(b);
l.vectorToLocalFrame(d,b,q,B);l.pointToLocalFrame(d,b,m,P);l.pointToLocalFrame(d,b,k,Q);m=P.distanceSquared(Q);a.tree.rayQuery(this,A,I);k=0;for(q=I.length;!this.result._shouldStop&&k!==q;k++){var p=I[k];a.getNormal(p,K);a.getVertex(h[3*p],u);u.vsub(P,F);var r=B.dot(K);r=K.dot(F)/r;0>r||(B.scale(r,t),t.vadd(P,t),a.getVertex(h[3*p+1],w),a.getVertex(h[3*p+2],v),r=t.distanceSquared(P),!e(t,w,u,v)&&!e(t,u,w,v)||r>m||(l.vectorToWorldFrame(b,K,H),l.pointToWorldFrame(d,b,t,E),this.reportIntersection(H,E,
a,c,p)))}I.length=0};a.prototype[f.types.TRIMESH]=a.prototype.intersectTrimesh;a.prototype.reportIntersection=function(b,d,c,h,e){var m=this.from,k=this.to,q=m.distanceTo(d),l=this.result;if(!(this.skipBackfaces&&0<b.dot(this._direction)))switch(l.hitFaceIndex="undefined"!==typeof e?e:-1,this.mode){case a.ALL:this.hasHit=!0;l.set(m,k,b,d,c,h,q);l.hasHit=!0;this.callback(l);break;case a.CLOSEST:if(q<l.distance||!l.hasHit)this.hasHit=!0,l.hasHit=!0,l.set(m,k,b,d,c,h,q);break;case a.ANY:this.hasHit=
!0,l.hasHit=!0,l.set(m,k,b,d,c,h,q),l._shouldStop=!0}};var N=new d,L=new d},{"../collision/AABB":3,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/Box":37,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43}],10:[function(b,c,f){function a(){this.rayFromWorld=new e;this.rayToWorld=new e;this.hitNormalWorld=new e;this.hitPointWorld=new e;this.hasHit=!1;this.body=this.shape=null;this.distance=this.hitFaceIndex=-1;this._shouldStop=!1}var e=
b("../math/Vec3");c.exports=a;a.prototype.reset=function(){this.rayFromWorld.setZero();this.rayToWorld.setZero();this.hitNormalWorld.setZero();this.hitPointWorld.setZero();this.hasHit=!1;this.body=this.shape=null;this.distance=this.hitFaceIndex=-1;this._shouldStop=!1};a.prototype.abort=function(){this._shouldStop=!0};a.prototype.set=function(a,b,c,e,p,r,h){this.rayFromWorld.copy(a);this.rayToWorld.copy(b);this.hitNormalWorld.copy(c);this.hitPointWorld.copy(e);this.shape=p;this.body=r;this.distance=
h}},{"../math/Vec3":30}],11:[function(b,c,f){function a(a){e.apply(this);this.axisList=[];this.world=null;this.axisIndex=0;var b=this.axisList;this._addBodyHandler=function(a){b.push(a.body)};this._removeBodyHandler=function(a){a=b.indexOf(a.body);-1!==a&&b.splice(a,1)};a&&this.setWorld(a)}b("../shapes/Shape");var e=b("../collision/Broadphase");c.exports=a;a.prototype=new e;a.prototype.setWorld=function(a){for(var b=this.axisList.length=0;b<a.bodies.length;b++)this.axisList.push(a.bodies[b]);a.removeEventListener("addBody",
this._addBodyHandler);a.removeEventListener("removeBody",this._removeBodyHandler);a.addEventListener("addBody",this._addBodyHandler);a.addEventListener("removeBody",this._removeBodyHandler);this.world=a;this.dirty=!0};a.insertionSortX=function(a){for(var b=1,d=a.length;b<d;b++){for(var c=a[b],e=b-1;0<=e&&!(a[e].aabb.lowerBound.x<=c.aabb.lowerBound.x);e--)a[e+1]=a[e];a[e+1]=c}return a};a.insertionSortY=function(a){for(var b=1,d=a.length;b<d;b++){for(var c=a[b],e=b-1;0<=e&&!(a[e].aabb.lowerBound.y<=
c.aabb.lowerBound.y);e--)a[e+1]=a[e];a[e+1]=c}return a};a.insertionSortZ=function(a){for(var b=1,d=a.length;b<d;b++){for(var c=a[b],e=b-1;0<=e&&!(a[e].aabb.lowerBound.z<=c.aabb.lowerBound.z);e--)a[e+1]=a[e];a[e+1]=c}return a};a.prototype.collisionPairs=function(b,c,e){b=this.axisList;var d=b.length,l=this.axisIndex,r,h;this.dirty&&(this.sortList(),this.dirty=!1);for(r=0;r!==d;r++){var m=b[r];for(h=r+1;h<d;h++){var q=b[h];if(this.needBroadphaseCollision(m,q)){if(!a.checkBounds(m,q,l))break;this.intersectionTest(m,
q,c,e)}}}};a.prototype.sortList=function(){for(var b=this.axisList,c=this.axisIndex,e=b.length,k=0;k!==e;k++){var p=b[k];p.aabbNeedsUpdate&&p.computeAABB()}0===c?a.insertionSortX(b):1===c?a.insertionSortY(b):2===c&&a.insertionSortZ(b)};a.checkBounds=function(a,b,c){if(0===c){var d=a.position.x;var e=b.position.x}else 1===c?(d=a.position.y,e=b.position.y):2===c&&(d=a.position.z,e=b.position.z);return e-b.boundingRadius<d+a.boundingRadius};a.prototype.autoDetectAxis=function(){for(var a=0,b=0,c=0,e=
0,p=0,r=0,h=this.axisList,m=h.length,q=1/m,f=0;f!==m;f++){var u=h[f],w=u.position.x;a+=w;b+=w*w;w=u.position.y;c+=w;e+=w*w;u=u.position.z;p+=u;r+=u*u}a=b-a*a*q;c=e-c*c*q;p=r-p*p*q;this.axisIndex=a>c?a>p?0:2:c>p?1:2};a.prototype.aabbQuery=function(a,b,c){c=c||[];this.dirty&&(this.sortList(),this.dirty=!1);a=this.axisList;for(var d=0;d<a.length;d++){var e=a[d];e.aabbNeedsUpdate&&e.computeAABB();e.aabb.overlaps(b)&&c.push(e)}return c}},{"../collision/Broadphase":5,"../shapes/Shape":43}],12:[function(b,
c,f){function a(a,b,c){c=c||{};var h="undefined"!==typeof c.maxForce?c.maxForce:1E6,m=c.pivotA?c.pivotA.clone():new n,k=c.pivotB?c.pivotB.clone():new n;this.axisA=c.axisA?c.axisA.clone():new n;this.axisB=c.axisB?c.axisB.clone():new n;e.call(this,a,m,b,k,h);this.collideConnected=!!c.collideConnected;this.angle="undefined"!==typeof c.angle?c.angle:0;m=this.coneEquation=new d(a,b,c);a=this.twistEquation=new l(a,b,c);this.twistAngle="undefined"!==typeof c.twistAngle?c.twistAngle:0;m.maxForce=0;m.minForce=
-h;a.maxForce=0;a.minForce=-h;this.equations.push(m,a)}c.exports=a;b("./Constraint");var e=b("./PointToPointConstraint"),d=b("../equations/ConeEquation"),l=b("../equations/RotationalEquation");b("../equations/ContactEquation");var n=b("../math/Vec3");a.prototype=new e;a.constructor=a;new n;new n;a.prototype.update=function(){var a=this.bodyA,b=this.bodyB,d=this.coneEquation,c=this.twistEquation;e.prototype.update.call(this);a.vectorToWorldFrame(this.axisA,d.axisA);b.vectorToWorldFrame(this.axisB,
d.axisB);this.axisA.tangents(c.axisA,c.axisA);a.vectorToWorldFrame(c.axisA,c.axisA);this.axisB.tangents(c.axisB,c.axisB);b.vectorToWorldFrame(c.axisB,c.axisB);d.angle=this.angle;c.maxAngle=this.twistAngle}},{"../equations/ConeEquation":18,"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],13:[function(b,c,f){function a(b,c,f){f=e.defaults(f,{collideConnected:!0,wakeUpBodies:!0});this.equations=[];this.bodyA=b;
this.bodyB=c;this.id=a.idCounter++;this.collideConnected=f.collideConnected;f.wakeUpBodies&&(b&&b.wakeUp(),c&&c.wakeUp())}c.exports=a;var e=b("../utils/Utils");a.prototype.update=function(){throw Error("method update() not implmemented in this Constraint subclass!");};a.prototype.enable=function(){for(var a=this.equations,b=0;b<a.length;b++)a[b].enabled=!0};a.prototype.disable=function(){for(var a=this.equations,b=0;b<a.length;b++)a[b].enabled=!1};a.idCounter=0},{"../utils/Utils":53}],14:[function(b,
c,f){function a(a,b,c,p){e.call(this,a,b);"undefined"===typeof c&&(c=a.position.distanceTo(b.position));"undefined"===typeof p&&(p=1E6);this.distance=c;a=this.distanceEquation=new d(a,b);this.equations.push(a);a.minForce=-p;a.maxForce=p}c.exports=a;var e=b("./Constraint"),d=b("../equations/ContactEquation");a.prototype=new e;a.prototype.update=function(){var a=this.distanceEquation,b=.5*this.distance,d=a.ni;this.bodyB.position.vsub(this.bodyA.position,d);d.normalize();d.mult(b,a.ri);d.mult(-b,a.rj)}},
{"../equations/ContactEquation":19,"./Constraint":13}],15:[function(b,c,f){function a(a,b,c){c=c||{};var h="undefined"!==typeof c.maxForce?c.maxForce:1E6,m=c.pivotA?c.pivotA.clone():new n,k=c.pivotB?c.pivotB.clone():new n;e.call(this,a,m,b,k,h);(this.axisA=c.axisA?c.axisA.clone():new n(1,0,0)).normalize();(this.axisB=c.axisB?c.axisB.clone():new n(1,0,0)).normalize();m=this.rotationalEquation1=new d(a,b,c);c=this.rotationalEquation2=new d(a,b,c);a=this.motorEquation=new l(a,b,h);a.enabled=!1;this.equations.push(m,
c,a)}c.exports=a;b("./Constraint");var e=b("./PointToPointConstraint"),d=b("../equations/RotationalEquation"),l=b("../equations/RotationalMotorEquation");b("../equations/ContactEquation");var n=b("../math/Vec3");a.prototype=new e;a.constructor=a;a.prototype.enableMotor=function(){this.motorEquation.enabled=!0};a.prototype.disableMotor=function(){this.motorEquation.enabled=!1};a.prototype.setMotorSpeed=function(a){this.motorEquation.targetVelocity=a};a.prototype.setMotorMaxForce=function(a){this.motorEquation.maxForce=
a;this.motorEquation.minForce=-a};var k=new n,p=new n;a.prototype.update=function(){var a=this.bodyA,b=this.bodyB,d=this.motorEquation,c=this.rotationalEquation1,l=this.rotationalEquation2,f=this.axisA,n=this.axisB;e.prototype.update.call(this);a.quaternion.vmult(f,k);b.quaternion.vmult(n,p);k.tangents(c.axisA,l.axisA);c.axisB.copy(p);l.axisB.copy(p);this.motorEquation.enabled&&(a.quaternion.vmult(this.axisA,d.axisA),b.quaternion.vmult(this.axisB,d.axisB))}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,
"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],16:[function(b,c,f){function a(a,b,c){c=c||{};var k="undefined"!==typeof c.maxForce?c.maxForce:1E6,h=new l,m=new l,q=new l;a.position.vadd(b.position,q);q.scale(.5,q);b.pointToLocalFrame(q,m);a.pointToLocalFrame(q,h);e.call(this,a,h,b,m,k);k=this.rotationalEquation1=new d(a,b,c);h=this.rotationalEquation2=new d(a,b,c);a=this.rotationalEquation3=new d(a,b,c);this.equations.push(k,h,a)}c.exports=
a;b("./Constraint");var e=b("./PointToPointConstraint"),d=b("../equations/RotationalEquation");b("../equations/RotationalMotorEquation");b("../equations/ContactEquation");var l=b("../math/Vec3");a.prototype=new e;a.constructor=a;new l;new l;a.prototype.update=function(){var a=this.bodyA,b=this.bodyB,d=this.rotationalEquation1,c=this.rotationalEquation2,h=this.rotationalEquation3;e.prototype.update.call(this);a.vectorToWorldFrame(l.UNIT_X,d.axisA);b.vectorToWorldFrame(l.UNIT_Y,d.axisB);a.vectorToWorldFrame(l.UNIT_Y,
c.axisA);b.vectorToWorldFrame(l.UNIT_Z,c.axisB);a.vectorToWorldFrame(l.UNIT_Z,h.axisA);b.vectorToWorldFrame(l.UNIT_X,h.axisB)}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],17:[function(b,c,f){function a(a,b,c,f,h){e.call(this,a,c);h="undefined"!==typeof h?h:1E6;this.pivotA=b?b.clone():new l;this.pivotB=f?f.clone():new l;b=this.equationX=new d(a,c);f=this.equationY=
new d(a,c);a=this.equationZ=new d(a,c);this.equations.push(b,f,a);b.minForce=f.minForce=a.minForce=-h;b.maxForce=f.maxForce=a.maxForce=h;b.ni.set(1,0,0);f.ni.set(0,1,0);a.ni.set(0,0,1)}c.exports=a;var e=b("./Constraint"),d=b("../equations/ContactEquation"),l=b("../math/Vec3");a.prototype=new e;a.prototype.update=function(){var a=this.bodyB,b=this.equationX,d=this.equationY,c=this.equationZ;this.bodyA.quaternion.vmult(this.pivotA,b.ri);a.quaternion.vmult(this.pivotB,b.rj);d.ri.copy(b.ri);d.rj.copy(b.rj);
c.ri.copy(b.ri);c.rj.copy(b.rj)}},{"../equations/ContactEquation":19,"../math/Vec3":30,"./Constraint":13}],18:[function(b,c,f){function a(a,b,c){c=c||{};var h="undefined"!==typeof c.maxForce?c.maxForce:1E6;d.call(this,a,b,-h,h);this.axisA=c.axisA?c.axisA.clone():new e(1,0,0);this.axisB=c.axisB?c.axisB.clone():new e(0,1,0);this.angle="undefined"!==typeof c.angle?c.angle:0}c.exports=a;var e=b("../math/Vec3");b("../math/Mat3");var d=b("./Equation");a.prototype=new d;a.prototype.constructor=a;var l=new e,
n=new e;a.prototype.computeB=function(a){var b=this.a,d=this.b,c=this.axisA,e=this.axisB,k=this.jacobianElementA,f=this.jacobianElementB;c.cross(e,l);e.cross(c,n);k.rotational.copy(n);f.rotational.copy(l);c=Math.cos(this.angle)-c.dot(e);e=this.computeGW();k=this.computeGiMf();return-c*b-e*d-a*k}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],19:[function(b,c,f){function a(a,b,c){e.call(this,a,b,0,"undefined"!==typeof c?c:1E6);this.restitution=0;this.ri=new d;this.rj=new d;this.ni=new d}c.exports=
a;var e=b("./Equation"),d=b("../math/Vec3");b("../math/Mat3");a.prototype=new e;a.prototype.constructor=a;var l=new d,n=new d,k=new d;a.prototype.computeB=function(a){var b=this.a,d=this.b,c=this.bi,h=this.bj,e=this.ri,m=this.rj,q=c.velocity,f=c.angularVelocity,p=h.velocity,r=h.angularVelocity,t=this.jacobianElementA,Q=this.jacobianElementB,H=this.ni;e.cross(H,l);m.cross(H,n);H.negate(t.spatial);l.negate(t.rotational);Q.spatial.copy(H);Q.rotational.copy(n);k.copy(h.position);k.vadd(m,k);k.vsub(c.position,
k);k.vsub(e,k);c=H.dot(k);h=this.restitution+1;q=h*p.dot(H)-h*q.dot(H)+r.dot(n)-f.dot(l);f=this.computeGiMf();return-c*b-q*d-a*f};var p=new d,r=new d,h=new d,m=new d,q=new d;a.prototype.getImpactVelocityAlongNormal=function(){this.bi.position.vadd(this.ri,h);this.bj.position.vadd(this.rj,m);this.bi.getVelocityAtWorldPoint(h,p);this.bj.getVelocityAtWorldPoint(m,r);p.vsub(r,q);return this.ni.dot(q)}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],20:[function(b,c,f){function a(b,d,c,h){this.id=
a.id++;this.minForce="undefined"===typeof c?-1E6:c;this.maxForce="undefined"===typeof h?1E6:h;this.bi=b;this.bj=d;this.eps=this.b=this.a=0;this.jacobianElementA=new e;this.jacobianElementB=new e;this.enabled=!0;this.setSpookParams(1E7,4,1/60)}c.exports=a;var e=b("../math/JacobianElement");b=b("../math/Vec3");a.prototype.constructor=a;a.id=0;a.prototype.setSpookParams=function(a,b,d){this.a=4/(d*(1+4*b));this.b=4*b/(1+4*b);this.eps=4/(d*d*a*(1+4*b))};a.prototype.computeB=function(a,b,d){var c=this.computeGW(),
h=this.computeGq(),e=this.computeGiMf();return-h*a-c*b-e*d};a.prototype.computeGq=function(){var a=this.jacobianElementB,b=this.bj.position;return this.jacobianElementA.spatial.dot(this.bi.position)+a.spatial.dot(b)};var d=new b;a.prototype.computeGW=function(){var a=this.jacobianElementB,b=this.bi,c=this.bj,h=c.velocity;c=c.angularVelocity||d;return this.jacobianElementA.multiplyVectors(b.velocity,b.angularVelocity||d)+a.multiplyVectors(h,c)};a.prototype.computeGWlambda=function(){var a=this.jacobianElementB,
b=this.bi,c=this.bj,h=c.vlambda;c=c.wlambda||d;return this.jacobianElementA.multiplyVectors(b.vlambda,b.wlambda||d)+a.multiplyVectors(h,c)};var l=new b,n=new b,k=new b,p=new b;a.prototype.computeGiMf=function(){var a=this.jacobianElementA,b=this.jacobianElementB,d=this.bi,c=this.bj,h=d.force,e=d.torque,f=c.force,r=c.torque,x=d.invMassSolve,D=c.invMassSolve;d.invInertiaWorldSolve?d.invInertiaWorldSolve.vmult(e,k):k.set(0,0,0);c.invInertiaWorldSolve?c.invInertiaWorldSolve.vmult(r,p):p.set(0,0,0);h.mult(x,
l);f.mult(D,n);return a.multiplyVectors(l,k)+b.multiplyVectors(n,p)};var r=new b;a.prototype.computeGiMGt=function(){var a=this.jacobianElementA,b=this.jacobianElementB,d=this.bi,c=this.bj,h=d.invInertiaWorldSolve,e=c.invInertiaWorldSolve;d=d.invMassSolve+c.invMassSolve;h&&(h.vmult(a.rotational,r),d+=r.dot(a.rotational));e&&(e.vmult(b.rotational,r),d+=r.dot(b.rotational));return d};var h=new b;new b;new b;new b;new b;new b;a.prototype.addToWlambda=function(a){var b=this.jacobianElementA,d=this.jacobianElementB,
c=this.bi,e=this.bj;b.spatial.mult(c.invMassSolve*a,h);c.vlambda.vadd(h,c.vlambda);d.spatial.mult(e.invMassSolve*a,h);e.vlambda.vadd(h,e.vlambda);c.invInertiaWorldSolve&&(c.invInertiaWorldSolve.vmult(b.rotational,h),h.mult(a,h),c.wlambda.vadd(h,c.wlambda));e.invInertiaWorldSolve&&(e.invInertiaWorldSolve.vmult(d.rotational,h),h.mult(a,h),e.wlambda.vadd(h,e.wlambda))};a.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":26,"../math/Vec3":30}],21:[function(b,
c,f){function a(a,b,c){e.call(this,a,b,-c,c);this.ri=new d;this.rj=new d;this.t=new d}c.exports=a;var e=b("./Equation"),d=b("../math/Vec3");b("../math/Mat3");a.prototype=new e;a.prototype.constructor=a;var l=new d,n=new d;a.prototype.computeB=function(a){var b=this.b,d=this.rj,c=this.t;this.ri.cross(c,l);d.cross(c,n);d=this.jacobianElementA;var e=this.jacobianElementB;c.negate(d.spatial);l.negate(d.rotational);e.spatial.copy(c);e.rotational.copy(n);c=this.computeGW();d=this.computeGiMf();return-c*
b-a*d}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],22:[function(b,c,f){function a(a,b,c){c=c||{};var h="undefined"!==typeof c.maxForce?c.maxForce:1E6;d.call(this,a,b,-h,h);this.axisA=c.axisA?c.axisA.clone():new e(1,0,0);this.axisB=c.axisB?c.axisB.clone():new e(0,1,0);this.maxAngle=Math.PI/2}c.exports=a;var e=b("../math/Vec3");b("../math/Mat3");var d=b("./Equation");a.prototype=new d;a.prototype.constructor=a;var l=new e,n=new e;a.prototype.computeB=function(a){var b=this.a,d=this.b,c=
this.axisA,e=this.axisB,k=this.jacobianElementA,f=this.jacobianElementB;c.cross(e,l);e.cross(c,n);k.rotational.copy(n);f.rotational.copy(l);c=Math.cos(this.maxAngle)-c.dot(e);e=this.computeGW();k=this.computeGiMf();return-c*b-e*d-a*k}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],23:[function(b,c,f){function a(a,b,c){c="undefined"!==typeof c?c:1E6;d.call(this,a,b,-c,c);this.axisA=new e;this.axisB=new e;this.targetVelocity=0}c.exports=a;var e=b("../math/Vec3");b("../math/Mat3");var d=b("./Equation");
a.prototype=new d;a.prototype.constructor=a;a.prototype.computeB=function(a){var b=this.b,d=this.axisB,c=this.jacobianElementB;this.jacobianElementA.rotational.copy(this.axisA);d.negate(c.rotational);d=this.computeGW()-this.targetVelocity;c=this.computeGiMf();return-d*b-a*c}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],24:[function(b,c,f){function a(b,c,f){f=e.defaults(f,{friction:.3,restitution:.3,contactEquationStiffness:1E7,contactEquationRelaxation:3,frictionEquationStiffness:1E7,frictionEquationRelaxation:3});
this.id=a.idCounter++;this.materials=[b,c];this.friction=f.friction;this.restitution=f.restitution;this.contactEquationStiffness=f.contactEquationStiffness;this.contactEquationRelaxation=f.contactEquationRelaxation;this.frictionEquationStiffness=f.frictionEquationStiffness;this.frictionEquationRelaxation=f.frictionEquationRelaxation}var e=b("../utils/Utils");c.exports=a;a.idCounter=0},{"../utils/Utils":53}],25:[function(b,c,f){function a(b){var d="";b=b||{};"string"===typeof b?(d=b,b={}):"object"===
typeof b&&(d="");this.name=d;this.id=a.idCounter++;this.friction="undefined"!==typeof b.friction?b.friction:-1;this.restitution="undefined"!==typeof b.restitution?b.restitution:-1}c.exports=a;a.idCounter=0},{}],26:[function(b,c,f){function a(){this.spatial=new e;this.rotational=new e}c.exports=a;var e=b("./Vec3");a.prototype.multiplyElement=function(a){return a.spatial.dot(this.spatial)+a.rotational.dot(this.rotational)};a.prototype.multiplyVectors=function(a,b){return a.dot(this.spatial)+b.dot(this.rotational)}},
{"./Vec3":30}],27:[function(b,c,f){function a(a){this.elements=a?a:[0,0,0,0,0,0,0,0,0]}c.exports=a;var e=b("./Vec3");a.prototype.identity=function(){var a=this.elements;a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=1;a[5]=0;a[6]=0;a[7]=0;a[8]=1};a.prototype.setZero=function(){var a=this.elements;a[0]=0;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=0;a[6]=0;a[7]=0;a[8]=0};a.prototype.setTrace=function(a){var b=this.elements;b[0]=a.x;b[4]=a.y;b[8]=a.z};a.prototype.getTrace=function(a){a=a||new e;var b=this.elements;a.x=b[0];
a.y=b[4];a.z=b[8]};a.prototype.vmult=function(a,b){b=b||new e;var d=this.elements,c=a.x,f=a.y,l=a.z;b.x=d[0]*c+d[1]*f+d[2]*l;b.y=d[3]*c+d[4]*f+d[5]*l;b.z=d[6]*c+d[7]*f+d[8]*l;return b};a.prototype.smult=function(a){for(var b=0;b<this.elements.length;b++)this.elements[b]*=a};a.prototype.mmult=function(b,c){for(var d=c||new a,e=0;3>e;e++)for(var f=0;3>f;f++){for(var l=0,h=0;3>h;h++)l+=b.elements[e+3*h]*this.elements[h+3*f];d.elements[e+3*f]=l}return d};a.prototype.scale=function(b,c){c=c||new a;for(var d=
this.elements,e=c.elements,f=0;3!==f;f++)e[3*f]=b.x*d[3*f],e[3*f+1]=b.y*d[3*f+1],e[3*f+2]=b.z*d[3*f+2];return c};a.prototype.solve=function(a,b){b=b||new e;for(var c=[],d=0;12>d;d++)c.push(0);var f;for(d=0;3>d;d++)for(f=0;3>f;f++)c[d+4*f]=this.elements[d+3*f];c[3]=a.x;c[7]=a.y;c[11]=a.z;var l=3,h=l;do{d=h-l;if(0===c[d+4*d])for(f=d+1;f<h;f++)if(0!==c[d+4*f]){var m=4;do{var q=4-m;c[q+4*d]+=c[q+4*f]}while(--m);break}if(0!==c[d+4*d])for(f=d+1;f<h;f++){var t=c[d+4*f]/c[d+4*d];m=4;do q=4-m,c[q+4*f]=q<=
d?0:c[q+4*f]-c[q+4*d]*t;while(--m)}}while(--l);b.z=c[11]/c[10];b.y=(c[7]-c[6]*b.z)/c[5];b.x=(c[3]-c[2]*b.z-c[1]*b.y)/c[0];if(isNaN(b.x)||isNaN(b.y)||isNaN(b.z)||Infinity===b.x||Infinity===b.y||Infinity===b.z)throw"Could not solve equation! Got x=["+b.toString()+"], b=["+a.toString()+"], A=["+this.toString()+"]";return b};a.prototype.e=function(a,b,c){if(void 0===c)return this.elements[b+3*a];this.elements[b+3*a]=c};a.prototype.copy=function(a){for(var b=0;b<a.elements.length;b++)this.elements[b]=
a.elements[b];return this};a.prototype.toString=function(){for(var a="",b=0;9>b;b++)a+=this.elements[b]+",";return a};a.prototype.reverse=function(b){b=b||new a;for(var c=[],d=0;18>d;d++)c.push(0);var e;for(d=0;3>d;d++)for(e=0;3>e;e++)c[d+6*e]=this.elements[d+3*e];c[3]=1;c[9]=0;c[15]=0;c[4]=0;c[10]=1;c[16]=0;c[5]=0;c[11]=0;c[17]=1;var f=3,r=f;do{d=r-f;if(0===c[d+6*d])for(e=d+1;e<r;e++)if(0!==c[d+6*e]){var h=6;do{var m=6-h;c[m+6*d]+=c[m+6*e]}while(--h);break}if(0!==c[d+6*d])for(e=d+1;e<r;e++){var q=
c[d+6*e]/c[d+6*d];h=6;do m=6-h,c[m+6*e]=m<=d?0:c[m+6*e]-c[m+6*d]*q;while(--h)}}while(--f);d=2;do{e=d-1;do{q=c[d+6*e]/c[d+6*d];h=6;do m=6-h,c[m+6*e]-=c[m+6*d]*q;while(--h)}while(e--)}while(--d);d=2;do{q=1/c[d+6*d];h=6;do m=6-h,c[m+6*d]*=q;while(--h)}while(d--);d=2;do{e=2;do{m=c[3+e+6*d];if(isNaN(m)||Infinity===m)throw"Could not reverse! A=["+this.toString()+"]";b.e(d,e,m)}while(e--)}while(d--);return b};a.prototype.setRotationFromQuaternion=function(a){var b=a.x,c=a.y,d=a.z,e=a.w,f=b+b,h=c+c,m=d+d;
a=b*f;var q=b*h;b*=m;var t=c*h;c*=m;d*=m;f*=e;h*=e;e*=m;m=this.elements;m[0]=1-(t+d);m[1]=q-e;m[2]=b+h;m[3]=q+e;m[4]=1-(a+d);m[5]=c-f;m[6]=b-h;m[7]=c+f;m[8]=1-(a+t);return this};a.prototype.transpose=function(b){b=b||new a;for(var c=b.elements,d=this.elements,e=0;3!==e;e++)for(var f=0;3!==f;f++)c[3*e+f]=d[3*f+e];return b}},{"./Vec3":30}],28:[function(b,c,f){function a(a,b,c,d){this.x=void 0!==a?a:0;this.y=void 0!==b?b:0;this.z=void 0!==c?c:0;this.w=void 0!==d?d:1}c.exports=a;var e=b("./Vec3");a.prototype.set=
function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d};a.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w};a.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]};a.prototype.setFromAxisAngle=function(a,b){var c=Math.sin(.5*b);this.x=a.x*c;this.y=a.y*c;this.z=a.z*c;this.w=Math.cos(.5*b)};a.prototype.toAxisAngle=function(a){a=a||new e;this.normalize();var b=2*Math.acos(this.w),c=Math.sqrt(1-this.w*this.w);.001>c?(a.x=this.x,a.y=this.y,a.z=this.z):(a.x=this.x/
c,a.y=this.y/c,a.z=this.z/c);return[a,b]};var d=new e,l=new e;a.prototype.setFromVectors=function(a,b){if(a.isAntiparallelTo(b))a.tangents(d,l),this.setFromAxisAngle(d,Math.PI);else{var c=a.cross(b);this.x=c.x;this.y=c.y;this.z=c.z;this.w=Math.sqrt(Math.pow(a.norm(),2)*Math.pow(b.norm(),2))+a.dot(b);this.normalize()}};var n=new e,k=new e,p=new e;a.prototype.mult=function(b,c){c=c||new a;var d=this.w;n.set(this.x,this.y,this.z);k.set(b.x,b.y,b.z);c.w=d*b.w-n.dot(k);n.cross(k,p);c.x=d*k.x+b.w*n.x+p.x;
c.y=d*k.y+b.w*n.y+p.y;c.z=d*k.z+b.w*n.z+p.z;return c};a.prototype.inverse=function(b){var c=this.x,d=this.y,e=this.z,f=this.w;b=b||new a;this.conjugate(b);c=1/(c*c+d*d+e*e+f*f);b.x*=c;b.y*=c;b.z*=c;b.w*=c;return b};a.prototype.conjugate=function(b){b=b||new a;b.x=-this.x;b.y=-this.y;b.z=-this.z;b.w=this.w;return b};a.prototype.normalize=function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);0===a?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=
a)};a.prototype.normalizeFast=function(){var a=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;0===a?this.w=this.z=this.y=this.x=0:(this.x*=a,this.y*=a,this.z*=a,this.w*=a)};a.prototype.vmult=function(a,b){b=b||new e;var c=a.x,d=a.y,h=a.z,f=this.x,k=this.y,p=this.z,l=this.w,r=l*c+k*h-p*d,n=l*d+p*c-f*h,D=l*h+f*d-k*c;c=-f*c-k*d-p*h;b.x=r*l+c*-f+n*-p-D*-k;b.y=n*l+c*-k+D*-f-r*-p;b.z=D*l+c*-p+r*-k-n*-f;return b};a.prototype.copy=function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this};
a.prototype.toEuler=function(a,b){b=b||"YZX";var c=this.x,d=this.y,e=this.z,h=this.w;switch(b){case "YZX":var f=c*d+e*h;if(.499<f){var k=2*Math.atan2(c,h);var p=Math.PI/2;var l=0}-.499>f&&(k=-2*Math.atan2(c,h),p=-Math.PI/2,l=0);isNaN(k)&&(l=e*e,k=Math.atan2(2*d*h-2*c*e,1-2*d*d-2*l),p=Math.asin(2*f),l=Math.atan2(2*c*h-2*d*e,1-2*c*c-2*l));break;default:throw Error("Euler order "+b+" not supported yet.");}a.y=k;a.z=p;a.x=l};a.prototype.setFromEuler=function(a,b,c,d){d=d||"XYZ";var e=Math.cos(a/2),h=
Math.cos(b/2),m=Math.cos(c/2);a=Math.sin(a/2);b=Math.sin(b/2);c=Math.sin(c/2);"XYZ"===d?(this.x=a*h*m+e*b*c,this.y=e*b*m-a*h*c,this.z=e*h*c+a*b*m,this.w=e*h*m-a*b*c):"YXZ"===d?(this.x=a*h*m+e*b*c,this.y=e*b*m-a*h*c,this.z=e*h*c-a*b*m,this.w=e*h*m+a*b*c):"ZXY"===d?(this.x=a*h*m-e*b*c,this.y=e*b*m+a*h*c,this.z=e*h*c+a*b*m,this.w=e*h*m-a*b*c):"ZYX"===d?(this.x=a*h*m-e*b*c,this.y=e*b*m+a*h*c,this.z=e*h*c-a*b*m,this.w=e*h*m+a*b*c):"YZX"===d?(this.x=a*h*m+e*b*c,this.y=e*b*m+a*h*c,this.z=e*h*c-a*b*m,this.w=
e*h*m-a*b*c):"XZY"===d&&(this.x=a*h*m-e*b*c,this.y=e*b*m-a*h*c,this.z=e*h*c+a*b*m,this.w=e*h*m+a*b*c);return this};a.prototype.clone=function(){return new a(this.x,this.y,this.z,this.w)}},{"./Vec3":30}],29:[function(b,c,f){function a(a){a=a||{};this.position=new e;a.position&&this.position.copy(a.position);this.quaternion=new d;a.quaternion&&this.quaternion.copy(a.quaternion)}var e=b("./Vec3"),d=b("./Quaternion");c.exports=a;var l=new d;a.pointToLocalFrame=function(a,b,c,d){d=d||new e;c.vsub(a,d);
b.conjugate(l);l.vmult(d,d);return d};a.prototype.pointToLocal=function(b,c){return a.pointToLocalFrame(this.position,this.quaternion,b,c)};a.pointToWorldFrame=function(a,b,c,d){d=d||new e;b.vmult(c,d);d.vadd(a,d);return d};a.prototype.pointToWorld=function(b,c){return a.pointToWorldFrame(this.position,this.quaternion,b,c)};a.prototype.vectorToWorldFrame=function(a,b){b=b||new e;this.quaternion.vmult(a,b);return b};a.vectorToWorldFrame=function(a,b,c){a.vmult(b,c);return c};a.vectorToLocalFrame=function(a,
b,c,d){d=d||new e;b.w*=-1;b.vmult(c,d);b.w*=-1;return d}},{"./Quaternion":28,"./Vec3":30}],30:[function(b,c,f){function a(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0}c.exports=a;var e=b("./Mat3");a.ZERO=new a(0,0,0);a.UNIT_X=new a(1,0,0);a.UNIT_Y=new a(0,1,0);a.UNIT_Z=new a(0,0,1);a.prototype.cross=function(b,c){var d=b.x,e=b.y,m=b.z,f=this.x,k=this.y,l=this.z;c=c||new a;c.x=k*m-l*e;c.y=l*d-f*m;c.z=f*e-k*d;return c};a.prototype.set=function(a,b,c){this.x=a;this.y=b;this.z=c;return this};a.prototype.setZero=
function(){this.x=this.y=this.z=0};a.prototype.vadd=function(b,c){if(c)c.x=b.x+this.x,c.y=b.y+this.y,c.z=b.z+this.z;else return new a(this.x+b.x,this.y+b.y,this.z+b.z)};a.prototype.vsub=function(b,c){if(c)c.x=this.x-b.x,c.y=this.y-b.y,c.z=this.z-b.z;else return new a(this.x-b.x,this.y-b.y,this.z-b.z)};a.prototype.crossmat=function(){return new e([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])};a.prototype.normalize=function(){var a=this.x,b=this.y,c=this.z;a=Math.sqrt(a*a+b*b+c*c);0<a?(b=1/
a,this.x*=b,this.y*=b,this.z*=b):this.z=this.y=this.x=0;return a};a.prototype.unit=function(b){b=b||new a;var c=this.x,d=this.y,e=this.z,m=Math.sqrt(c*c+d*d+e*e);0<m?(m=1/m,b.x=c*m,b.y=d*m,b.z=e*m):(b.x=1,b.y=0,b.z=0);return b};a.prototype.norm=function(){var a=this.x,b=this.y,c=this.z;return Math.sqrt(a*a+b*b+c*c)};a.prototype.length=a.prototype.norm;a.prototype.norm2=function(){return this.dot(this)};a.prototype.lengthSquared=a.prototype.norm2;a.prototype.distanceTo=function(a){var b=this.x,c=this.y,
d=this.z,e=a.x,f=a.y;a=a.z;return Math.sqrt((e-b)*(e-b)+(f-c)*(f-c)+(a-d)*(a-d))};a.prototype.distanceSquared=function(a){var b=this.x,c=this.y,d=this.z,e=a.x,f=a.y;a=a.z;return(e-b)*(e-b)+(f-c)*(f-c)+(a-d)*(a-d)};a.prototype.mult=function(b,c){c=c||new a;var d=this.y,e=this.z;c.x=b*this.x;c.y=b*d;c.z=b*e;return c};a.prototype.scale=a.prototype.mult;a.prototype.dot=function(a){return this.x*a.x+this.y*a.y+this.z*a.z};a.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z};a.prototype.negate=
function(b){b=b||new a;b.x=-this.x;b.y=-this.y;b.z=-this.z;return b};var d=new a,l=new a;a.prototype.tangents=function(a,b){var c=this.norm();0<c?(c=1/c,d.set(this.x*c,this.y*c,this.z*c),.9>Math.abs(d.x)?l.set(1,0,0):l.set(0,1,0),d.cross(l,a),d.cross(a,b)):(a.set(1,0,0),b.set(0,1,0))};a.prototype.toString=function(){return this.x+","+this.y+","+this.z};a.prototype.toArray=function(){return[this.x,this.y,this.z]};a.prototype.copy=function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this};a.prototype.lerp=
function(a,b,c){var d=this.x,e=this.y,f=this.z;c.x=d+(a.x-d)*b;c.y=e+(a.y-e)*b;c.z=f+(a.z-f)*b};a.prototype.almostEquals=function(a,b){void 0===b&&(b=1E-6);return Math.abs(this.x-a.x)>b||Math.abs(this.y-a.y)>b||Math.abs(this.z-a.z)>b?!1:!0};a.prototype.almostZero=function(a){void 0===a&&(a=1E-6);return Math.abs(this.x)>a||Math.abs(this.y)>a||Math.abs(this.z)>a?!1:!0};var n=new a;a.prototype.isAntiparallelTo=function(a,b){this.negate(n);return n.almostEquals(a,b)};a.prototype.clone=function(){return new a(this.x,
this.y,this.z)}},{"./Mat3":27}],31:[function(b,c,f){function a(b){b=b||{};e.apply(this);this.id=a.idCounter++;this.postStep=this.preStep=this.world=null;this.vlambda=new d;this.collisionFilterGroup="number"===typeof b.collisionFilterGroup?b.collisionFilterGroup:1;this.collisionFilterMask="number"===typeof b.collisionFilterMask?b.collisionFilterMask:1;this.collisionResponse=!0;this.position=new d;b.position&&this.position.copy(b.position);this.previousPosition=new d;this.initPosition=new d;this.velocity=
new d;b.velocity&&this.velocity.copy(b.velocity);this.initVelocity=new d;this.force=new d;var c="number"===typeof b.mass?b.mass:0;this.mass=c;this.invMass=0<c?1/c:0;this.material=b.material||null;this.linearDamping="number"===typeof b.linearDamping?b.linearDamping:.01;this.type=0>=c?a.STATIC:a.DYNAMIC;typeof b.type===typeof a.STATIC&&(this.type=b.type);this.allowSleep="undefined"!==typeof b.allowSleep?b.allowSleep:!0;this.sleepState=0;this.sleepSpeedLimit="undefined"!==typeof b.sleepSpeedLimit?b.sleepSpeedLimit:
.1;this.sleepTimeLimit="undefined"!==typeof b.sleepTimeLimit?b.sleepTimeLimit:1;this.timeLastSleepy=0;this._wakeUpAfterNarrowphase=!1;this.torque=new d;this.quaternion=new n;b.quaternion&&this.quaternion.copy(b.quaternion);this.initQuaternion=new n;this.angularVelocity=new d;b.angularVelocity&&this.angularVelocity.copy(b.angularVelocity);this.initAngularVelocity=new d;this.interpolatedPosition=new d;this.interpolatedQuaternion=new n;this.shapes=[];this.shapeOffsets=[];this.shapeOrientations=[];this.inertia=
new d;this.invInertia=new d;this.invInertiaWorld=new l;this.invMassSolve=0;this.invInertiaSolve=new d;this.invInertiaWorldSolve=new l;this.fixedRotation="undefined"!==typeof b.fixedRotation?b.fixedRotation:!1;this.angularDamping="undefined"!==typeof b.angularDamping?b.angularDamping:.01;this.aabb=new k;this.aabbNeedsUpdate=!0;this.wlambda=new d;b.shape&&this.addShape(b.shape);this.updateMassProperties()}c.exports=a;var e=b("../utils/EventTarget");b("../shapes/Shape");var d=b("../math/Vec3"),l=b("../math/Mat3"),
n=b("../math/Quaternion");b("../material/Material");var k=b("../collision/AABB"),p=b("../shapes/Box");a.prototype=new e;a.prototype.constructor=a;a.DYNAMIC=1;a.STATIC=2;a.KINEMATIC=4;a.AWAKE=0;a.SLEEPY=1;a.SLEEPING=2;a.idCounter=0;a.prototype.wakeUp=function(){var b=this.sleepState;this.sleepState=0;b===a.SLEEPING&&this.dispatchEvent({type:"wakeup"})};a.prototype.sleep=function(){this.sleepState=a.SLEEPING;this.velocity.set(0,0,0);this.angularVelocity.set(0,0,0)};a.sleepyEvent={type:"sleepy"};a.sleepEvent=
{type:"sleep"};a.prototype.sleepTick=function(b){if(this.allowSleep){var c=this.sleepState,d=this.velocity.norm2()+this.angularVelocity.norm2(),e=Math.pow(this.sleepSpeedLimit,2);c===a.AWAKE&&d<e?(this.sleepState=a.SLEEPY,this.timeLastSleepy=b,this.dispatchEvent(a.sleepyEvent)):c===a.SLEEPY&&d>e?this.wakeUp():c===a.SLEEPY&&b-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(a.sleepEvent))}};a.prototype.updateSolveMassProperties=function(){this.sleepState===a.SLEEPING||this.type===
a.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))};a.prototype.pointToLocalFrame=function(a,b){b=b||new d;a.vsub(this.position,b);this.quaternion.conjugate().vmult(b,b);return b};a.prototype.vectorToLocalFrame=function(a,b){b=b||new d;this.quaternion.conjugate().vmult(a,b);return b};a.prototype.pointToWorldFrame=function(a,
b){b=b||new d;this.quaternion.vmult(a,b);b.vadd(this.position,b);return b};a.prototype.vectorToWorldFrame=function(a,b){b=b||new d;this.quaternion.vmult(a,b);return b};var r=new d,h=new n;a.prototype.addShape=function(a,b,c){var e=new d,h=new n;b&&e.copy(b);c&&h.copy(c);this.shapes.push(a);this.shapeOffsets.push(e);this.shapeOrientations.push(h);this.updateMassProperties();this.updateBoundingRadius();this.aabbNeedsUpdate=!0;return this};a.prototype.updateBoundingRadius=function(){for(var a=this.shapes,
b=this.shapeOffsets,c=a.length,d=0,e=0;e!==c;e++){var h=a[e];h.updateBoundingSphereRadius();var m=b[e].norm();h=h.boundingSphereRadius;m+h>d&&(d=m+h)}this.boundingRadius=d};var m=new k;a.prototype.computeAABB=function(){for(var a=this.shapes,b=this.shapeOffsets,c=this.shapeOrientations,d=a.length,e=this.quaternion,f=this.aabb,q=0;q!==d;q++){var k=a[q];c[q].mult(e,h);h.vmult(b[q],r);r.vadd(this.position,r);k.calculateWorldAABB(r,h,m.lowerBound,m.upperBound);0===q?f.copy(m):f.extend(m)}this.aabbNeedsUpdate=
!1};var q=new l,t=new l;new l;a.prototype.updateInertiaWorld=function(a){var b=this.invInertia;if(b.x!==b.y||b.y!==b.z||a)q.setRotationFromQuaternion(this.quaternion),q.transpose(t),q.scale(b,q),q.mmult(t,this.invInertiaWorld)};var u=new d,w=new d;a.prototype.applyForce=function(b,c){this.type===a.DYNAMIC&&(c.vsub(this.position,u),u.cross(b,w),this.force.vadd(b,this.force),this.torque.vadd(w,this.torque))};var v=new d,z=new d;a.prototype.applyLocalForce=function(b,c){this.type===a.DYNAMIC&&(this.vectorToWorldFrame(b,
v),this.pointToWorldFrame(c,z),this.applyForce(v,z))};var C=new d,x=new d,D=new d;a.prototype.applyImpulse=function(b,c){this.type===a.DYNAMIC&&(c.vsub(this.position,C),x.copy(b),x.mult(this.invMass,x),this.velocity.vadd(x,this.velocity),C.cross(b,D),this.invInertiaWorld.vmult(D,D),this.angularVelocity.vadd(D,this.angularVelocity))};var F=new d,K=new d;a.prototype.applyLocalImpulse=function(b,c){this.type===a.DYNAMIC&&(this.vectorToWorldFrame(b,F),this.pointToWorldFrame(c,K),this.applyImpulse(F,K))};
var B=new d;a.prototype.updateMassProperties=function(){this.invMass=0<this.mass?1/this.mass:0;var a=this.inertia,b=this.fixedRotation;this.computeAABB();B.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2);p.calculateInertia(B,this.mass,a);this.invInertia.set(0<a.x&&!b?1/a.x:0,0<a.y&&!b?1/a.y:0,0<a.z&&!b?1/a.z:0);this.updateInertiaWorld(!0)};a.prototype.getVelocityAtWorldPoint=function(a,b){var c=
new d;a.vsub(this.position,c);this.angularVelocity.cross(c,b);this.velocity.vadd(b,b);return b}},{"../collision/AABB":3,"../material/Material":25,"../math/Mat3":27,"../math/Quaternion":28,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Shape":43,"../utils/EventTarget":49}],32:[function(b,c,f){function a(a){this.chassisBody=a.chassisBody;this.wheelInfos=[];this.sliding=!1;this.world=null;this.indexRightAxis="undefined"!==typeof a.indexRightAxis?a.indexRightAxis:1;this.indexForwardAxis="undefined"!==
typeof a.indexForwardAxis?a.indexForwardAxis:0;this.indexUpAxis="undefined"!==typeof a.indexUpAxis?a.indexUpAxis:2}function e(a,b,c){var d=x,e=D,h=F,m=K;b.vsub(a.position,d);d.cross(c,e);a.invInertiaWorld.vmult(e,m);m.cross(d,h);return a.invMass+c.dot(h)}b("./Body");var d=b("../math/Vec3"),l=b("../math/Quaternion");b("../collision/RaycastResult");f=b("../collision/Ray");var n=b("../objects/WheelInfo");c.exports=a;new d;new d;new d;var k=new d,p=new d,r=new d;new f;a.prototype.addWheel=function(a){a=
a||{};a=new n(a);var b=this.wheelInfos.length;this.wheelInfos.push(a);return b};a.prototype.setSteeringValue=function(a,b){this.wheelInfos[b].steering=a};new d;a.prototype.applyEngineForce=function(a,b){this.wheelInfos[b].engineForce=a};a.prototype.setBrake=function(a,b){this.wheelInfos[b].brake=a};a.prototype.addToWorld=function(a){a.add(this.chassisBody);var b=this;this.preStepCallback=function(){b.updateVehicle(a.dt)};a.addEventListener("preStep",this.preStepCallback);this.world=a};a.prototype.getVehicleAxisWorld=
function(a,b){b.set(0===a?1:0,1===a?1:0,2===a?1:0);this.chassisBody.vectorToWorldFrame(b,b)};a.prototype.updateVehicle=function(a){for(var b=this.wheelInfos,c=b.length,e=this.chassisBody,h=0;h<c;h++)this.updateWheelTransform(h);this.currentVehicleSpeedKmHour=3.6*e.velocity.norm();h=new d;this.getVehicleAxisWorld(this.indexForwardAxis,h);0>h.dot(e.velocity)&&(this.currentVehicleSpeedKmHour*=-1);for(h=0;h<c;h++)this.castRay(b[h]);this.updateSuspension(a);var m=new d,f=new d;for(h=0;h<c;h++){var q=b[h],
k=q.suspensionForce;k>q.maxSuspensionForce&&(k=q.maxSuspensionForce);q.raycastResult.hitNormalWorld.scale(k*a,m);q.raycastResult.hitPointWorld.vsub(e.position,f);e.applyImpulse(m,q.raycastResult.hitPointWorld)}this.updateFriction(a);m=new d;f=new d;k=new d;for(h=0;h<c;h++){q=b[h];e.getVelocityAtWorldPoint(q.chassisConnectionPointWorld,k);var l=1;switch(this.indexUpAxis){case 1:l=-1}if(q.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,f);var t=f.dot(q.raycastResult.hitNormalWorld);q.raycastResult.hitNormalWorld.scale(t,
m);f.vsub(m,f);t=f.dot(k);q.deltaRotation=l*t*a/q.radius}!q.sliding&&q.isInContact||0===q.engineForce||!q.useCustomSlidingRotationalSpeed||(q.deltaRotation=(0<q.engineForce?1:-1)*q.customSlidingRotationalSpeed*a);Math.abs(q.brake)>Math.abs(q.engineForce)&&(q.deltaRotation=0);q.rotation+=q.deltaRotation;q.deltaRotation*=.99}};a.prototype.updateSuspension=function(a){a=this.chassisBody.mass;for(var b=this.wheelInfos,c=b.length,d=0;d<c;d++){var e=b[d];if(e.isInContact){var h=e.suspensionStiffness*(e.suspensionRestLength-
e.suspensionLength)*e.clippedInvContactDotSuspension;var m=e.suspensionRelativeVelocity;h-=(0>m?e.dampingCompression:e.dampingRelaxation)*m;e.suspensionForce=h*a;0>e.suspensionForce&&(e.suspensionForce=0)}else e.suspensionForce=0}};a.prototype.removeFromWorld=function(a){a.remove(this.chassisBody);a.removeEventListener("preStep",this.preStepCallback);this.world=null};var h=new d,m=new d;a.prototype.castRay=function(a){this.updateWheelTransformWorld(a);var b=this.chassisBody,c=-1;a.directionWorld.scale(a.suspensionRestLength+
a.radius,h);var e=a.chassisConnectionPointWorld;e.vadd(h,m);var f=a.raycastResult;f.reset();var q=b.collisionResponse;b.collisionResponse=!1;this.world.rayTest(e,m,f);b.collisionResponse=q;e=f.body;a.raycastResult.groundObject=0;e?(c=f.distance,a.raycastResult.hitNormalWorld=f.hitNormalWorld,a.isInContact=!0,a.suspensionLength=f.distance-a.radius,f=a.suspensionRestLength-a.maxSuspensionTravel,e=a.suspensionRestLength+a.maxSuspensionTravel,a.suspensionLength<f&&(a.suspensionLength=f),a.suspensionLength>
e&&(a.suspensionLength=e,a.raycastResult.reset()),f=a.raycastResult.hitNormalWorld.dot(a.directionWorld),e=new d,b.getVelocityAtWorldPoint(a.raycastResult.hitPointWorld,e),b=a.raycastResult.hitNormalWorld.dot(e),-.1<=f?(a.suspensionRelativeVelocity=0,a.clippedInvContactDotSuspension=10):(f=-1/f,a.suspensionRelativeVelocity=b*f,a.clippedInvContactDotSuspension=f)):(a.suspensionLength=a.suspensionRestLength+0*a.maxSuspensionTravel,a.suspensionRelativeVelocity=0,a.directionWorld.scale(-1,a.raycastResult.hitNormalWorld),
a.clippedInvContactDotSuspension=1);return c};a.prototype.updateWheelTransformWorld=function(a){a.isInContact=!1;var b=this.chassisBody;b.pointToWorldFrame(a.chassisConnectionPointLocal,a.chassisConnectionPointWorld);b.vectorToWorldFrame(a.directionLocal,a.directionWorld);b.vectorToWorldFrame(a.axleLocal,a.axleWorld)};a.prototype.updateWheelTransform=function(a){a=this.wheelInfos[a];this.updateWheelTransformWorld(a);a.directionLocal.scale(-1,k);p.copy(a.axleLocal);k.cross(p,r);r.normalize();p.normalize();
var b=a.steering,c=new l;c.setFromAxisAngle(k,b);b=new l;b.setFromAxisAngle(p,a.rotation);var d=a.worldTransform.quaternion;this.chassisBody.quaternion.mult(c,d);d.mult(b,d);d.normalize();c=a.worldTransform.position;c.copy(a.directionWorld);c.scale(a.suspensionLength,c);c.vadd(a.chassisConnectionPointWorld,c)};var q=[new d(1,0,0),new d(0,1,0),new d(0,0,1)];a.prototype.getWheelTransformWorld=function(a){return this.wheelInfos[a].worldTransform};var t=new d,u=[],w=[];a.prototype.updateFriction=function(a){for(var b=
this.wheelInfos,c=b.length,h=this.chassisBody,m=0,f=0;f<c;f++){var k=b[f],l=k.raycastResult.body;l&&m++;k.sideImpulse=0;k.forwardImpulse=0;w[f]||(w[f]=new d);u[f]||(u[f]=new d)}for(f=0;f<c;f++)if(k=b[f],l=k.raycastResult.body){var p=u[f];this.getWheelTransformWorld(f).vectorToWorldFrame(q[this.indexRightAxis],p);m=k.raycastResult.hitNormalWorld;var r=p.dot(m);m.scale(r,t);p.vsub(t,p);p.normalize();m.cross(p,w[f]);w[f].normalize();m=k;r=h;var n=k.raycastResult.hitPointWorld,x=k.raycastResult.hitPointWorld;
if(1.1<p.norm2())l=0;else{var F=B,D=P,K=Q;r.getVelocityAtWorldPoint(n,F);l.getVelocityAtWorldPoint(x,D);F.vsub(D,K);l=-.2*p.dot(K)*(1/(r.invMass+l.invMass))}m.sideImpulse=l;k.sideImpulse*=1}this.sliding=!1;for(f=0;f<c;f++){k=b[f];l=k.raycastResult.body;r=0;k.slipInfo=1;if(l){m=k.brake?k.brake:0;F=h;n=l;x=k.raycastResult.hitPointWorld;p=w[f];r=m;D=x;K=v;var M=z,S=C;F.getVelocityAtWorldPoint(D,K);n.getVelocityAtWorldPoint(D,M);K.vsub(M,S);D=p.dot(S);F=e(F,x,p);n=e(n,x,p);n=1/(F+n)*-D;r<n&&(n=r);n<-r&&
(n=-r);r=n;r+=k.engineForce*a;m/=r;k.slipInfo*=m}k.forwardImpulse=0;k.skidInfo=1;l&&(k.skidInfo=1,l=k.suspensionForce*a*k.frictionSlip,m=l*l,k.forwardImpulse=r,r=.5*k.forwardImpulse,n=1*k.sideImpulse,r=r*r+n*n,k.sliding=!1,r>m&&(this.sliding=!0,k.sliding=!0,m=l/Math.sqrt(r),k.skidInfo*=m))}if(this.sliding)for(f=0;f<c;f++)k=b[f],0!==k.sideImpulse&&1>k.skidInfo&&(k.forwardImpulse*=k.skidInfo,k.sideImpulse*=k.skidInfo);for(f=0;f<c;f++)k=b[f],a=new d,a.copy(k.raycastResult.hitPointWorld),0!==k.forwardImpulse&&
(l=new d,w[f].scale(k.forwardImpulse,l),h.applyImpulse(l,a)),0!==k.sideImpulse&&(l=k.raycastResult.body,m=new d,m.copy(k.raycastResult.hitPointWorld),r=new d,u[f].scale(k.sideImpulse,r),h.pointToLocalFrame(a,a),a["xyz"[this.indexUpAxis]]*=k.rollInfluence,h.pointToWorldFrame(a,a),h.applyImpulse(r,a),r.scale(-1,r),l.applyImpulse(r,m))};var v=new d,z=new d,C=new d,x=new d,D=new d,F=new d,K=new d,B=new d,P=new d,Q=new d},{"../collision/Ray":9,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Vec3":30,
"../objects/WheelInfo":36,"./Body":31}],33:[function(b,c,f){function a(a){this.wheelBodies=[];this.coordinateSystem="undefined"===typeof a.coordinateSystem?new n(1,2,3):a.coordinateSystem.clone();this.chassisBody=a.chassisBody;this.chassisBody||(a=new l(new n(5,2,.5)),this.chassisBody=new e(1,a));this.constraints=[];this.wheelAxes=[];this.wheelForces=[]}var e=b("./Body"),d=b("../shapes/Sphere"),l=b("../shapes/Box"),n=b("../math/Vec3"),k=b("../constraints/HingeConstraint");c.exports=a;a.prototype.addWheel=
function(a){a=a||{};var b=a.body;b||(b=new e(1,new d(1.2)));this.wheelBodies.push(b);this.wheelForces.push(0);new n;var c="undefined"!==typeof a.position?a.position.clone():new n,h=new n;this.chassisBody.pointToWorldFrame(c,h);b.position.set(h.x,h.y,h.z);a="undefined"!==typeof a.axis?a.axis.clone():new n(0,1,0);this.wheelAxes.push(a);b=new k(this.chassisBody,b,{pivotA:c,axisA:a,pivotB:n.ZERO,axisB:a,collideConnected:!1});this.constraints.push(b);return this.wheelBodies.length-1};a.prototype.setSteeringValue=
function(a,b){var c=this.wheelAxes[b],d=Math.cos(a),e=Math.sin(a),h=c.x;c=c.y;this.constraints[b].axisA.set(d*h-e*c,e*h+d*c,0)};a.prototype.setMotorSpeed=function(a,b){var c=this.constraints[b];c.enableMotor();c.motorTargetVelocity=a};a.prototype.disableMotor=function(a){this.constraints[a].disableMotor()};var p=new n;a.prototype.setWheelForce=function(a,b){this.wheelForces[b]=a};a.prototype.applyWheelForce=function(a,b){var c=this.wheelBodies[b],d=c.torque;this.wheelAxes[b].scale(a,p);c.vectorToWorldFrame(p,
p);d.vadd(p,d)};a.prototype.addToWorld=function(a){for(var b=this.constraints,c=this.wheelBodies.concat([this.chassisBody]),d=0;d<c.length;d++)a.add(c[d]);for(d=0;d<b.length;d++)a.addConstraint(b[d]);a.addEventListener("preStep",this._update.bind(this))};a.prototype._update=function(){for(var a=this.wheelForces,b=0;b<a.length;b++)this.applyWheelForce(a[b],b)};a.prototype.removeFromWorld=function(a){for(var b=this.constraints,c=this.wheelBodies.concat([this.chassisBody]),d=0;d<c.length;d++)a.remove(c[d]);
for(d=0;d<b.length;d++)a.removeConstraint(b[d])};var r=new n;a.prototype.getWheelSpeed=function(a){var b=this.wheelBodies[a].angularVelocity;this.chassisBody.vectorToWorldFrame(this.wheelAxes[a],r);return b.dot(r)}},{"../constraints/HingeConstraint":15,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Sphere":44,"./Body":31}],34:[function(b,c,f){function a(){this.particles=[];this.speedOfSound=this.smoothingRadius=this.density=1;this.viscosity=.01;this.eps=1E-6;this.pressures=[];this.densities=[];this.neighbors=
[]}c.exports=a;b("../shapes/Shape");c=b("../math/Vec3");b("../math/Quaternion");b("../shapes/Particle");b("../objects/Body");b("../material/Material");a.prototype.add=function(a){this.particles.push(a);this.neighbors.length<this.particles.length&&this.neighbors.push([])};a.prototype.remove=function(a){a=this.particles.indexOf(a);-1!==a&&(this.particles.splice(a,1),this.neighbors.length>this.particles.length&&this.neighbors.pop())};var e=new c;a.prototype.getNeighbors=function(a,b){for(var c=this.particles.length,
d=a.id,h=this.smoothingRadius*this.smoothingRadius,f=0;f!==c;f++){var m=this.particles[f];m.position.vsub(a.position,e);d!==m.id&&e.norm2()<h&&b.push(m)}};var d=new c,l=new c,n=new c,k=new c,p=new c,r=new c;a.prototype.update=function(){for(var a=this.particles.length,b=this.speedOfSound,c=this.eps,e=0;e!==a;e++){var f=this.particles[e],w=this.neighbors[e];w.length=0;this.getNeighbors(f,w);w.push(this.particles[e]);for(var v=w.length,z=0,C=0;C!==v;C++){f.position.vsub(w[C].position,d);var x=d.norm();
x=this.w(x);z+=w[C].mass*x}this.densities[e]=z;this.pressures[e]=b*b*(this.densities[e]-this.density)}for(e=0;e!==a;e++){b=this.particles[e];l.set(0,0,0);n.set(0,0,0);w=this.neighbors[e];v=w.length;for(C=0;C!==v;C++)z=w[C],b.position.vsub(z.position,p),x=p.norm(),f=-z.mass*(this.pressures[e]/(this.densities[e]*this.densities[e]+c)+this.pressures[C]/(this.densities[C]*this.densities[C]+c)),this.gradw(p,k),k.mult(f,k),l.vadd(k,l),z.velocity.vsub(b.velocity,r),r.mult(1/(1E-4+this.densities[e]*this.densities[C])*
this.viscosity*z.mass,r),f=this.nablaw(x),r.mult(f,r),n.vadd(r,n);n.mult(b.mass,n);l.mult(b.mass,l);b.force.vadd(n,b.force);b.force.vadd(l,b.force)}};a.prototype.w=function(a){var b=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(b,9))*Math.pow(b*b-a*a,3)};a.prototype.gradw=function(a,b){var c=a.norm(),d=this.smoothingRadius;a.mult(945/(32*Math.PI*Math.pow(d,9))*Math.pow(d*d-c*c,2),b)};a.prototype.nablaw=function(a){var b=this.smoothingRadius;return 945/(32*Math.PI*Math.pow(b,9))*(b*b-a*a)*(7*
a*a-3*b*b)}},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Particle":41,"../shapes/Shape":43}],35:[function(b,c,f){function a(a,b,c){c=c||{};this.restLength="number"===typeof c.restLength?c.restLength:1;this.stiffness=c.stiffness||100;this.damping=c.damping||1;this.bodyA=a;this.bodyB=b;this.localAnchorA=new e;this.localAnchorB=new e;c.localAnchorA&&this.localAnchorA.copy(c.localAnchorA);c.localAnchorB&&this.localAnchorB.copy(c.localAnchorB);c.worldAnchorA&&
this.setWorldAnchorA(c.worldAnchorA);c.worldAnchorB&&this.setWorldAnchorB(c.worldAnchorB)}var e=b("../math/Vec3");c.exports=a;a.prototype.setWorldAnchorA=function(a){this.bodyA.pointToLocalFrame(a,this.localAnchorA)};a.prototype.setWorldAnchorB=function(a){this.bodyB.pointToLocalFrame(a,this.localAnchorB)};a.prototype.getWorldAnchorA=function(a){this.bodyA.pointToWorldFrame(this.localAnchorA,a)};a.prototype.getWorldAnchorB=function(a){this.bodyB.pointToWorldFrame(this.localAnchorB,a)};var d=new e,
l=new e,n=new e,k=new e,p=new e,r=new e,h=new e,m=new e,q=new e,t=new e,u=new e;a.prototype.applyForce=function(){var a=this.stiffness,b=this.damping,c=this.restLength,e=this.bodyA,f=this.bodyB;this.getWorldAnchorA(p);this.getWorldAnchorB(r);p.vsub(e.position,h);r.vsub(f.position,m);r.vsub(p,d);var D=d.norm();l.copy(d);l.normalize();f.velocity.vsub(e.velocity,n);f.angularVelocity.cross(m,u);n.vadd(u,n);e.angularVelocity.cross(h,u);n.vsub(u,n);l.mult(-a*(D-c)-b*n.dot(l),k);e.force.vsub(k,e.force);
f.force.vadd(k,f.force);h.cross(k,q);m.cross(k,t);e.torque.vsub(q,e.torque);f.torque.vadd(t,f.torque)}},{"../math/Vec3":30}],36:[function(b,c,f){function a(a){a=n.defaults(a,{chassisConnectionPointLocal:new e,chassisConnectionPointWorld:new e,directionLocal:new e,directionWorld:new e,axleLocal:new e,axleWorld:new e,suspensionRestLength:1,suspensionMaxLength:2,radius:1,suspensionStiffness:100,dampingCompression:10,dampingRelaxation:10,frictionSlip:1E4,steering:0,rotation:0,deltaRotation:0,rollInfluence:.01,
maxSuspensionForce:Number.MAX_VALUE,isFrontWheel:!0,clippedInvContactDotSuspension:1,suspensionRelativeVelocity:0,suspensionForce:0,skidInfo:0,suspensionLength:0,maxSuspensionTravel:1,useCustomSlidingRotationalSpeed:!1,customSlidingRotationalSpeed:-.1});this.maxSuspensionTravel=a.maxSuspensionTravel;this.customSlidingRotationalSpeed=a.customSlidingRotationalSpeed;this.useCustomSlidingRotationalSpeed=a.useCustomSlidingRotationalSpeed;this.sliding=!1;this.chassisConnectionPointLocal=a.chassisConnectionPointLocal.clone();
this.chassisConnectionPointWorld=a.chassisConnectionPointWorld.clone();this.directionLocal=a.directionLocal.clone();this.directionWorld=a.directionWorld.clone();this.axleLocal=a.axleLocal.clone();this.axleWorld=a.axleWorld.clone();this.suspensionRestLength=a.suspensionRestLength;this.suspensionMaxLength=a.suspensionMaxLength;this.radius=a.radius;this.suspensionStiffness=a.suspensionStiffness;this.dampingCompression=a.dampingCompression;this.dampingRelaxation=a.dampingRelaxation;this.frictionSlip=
a.frictionSlip;this.deltaRotation=this.rotation=this.steering=0;this.rollInfluence=a.rollInfluence;this.maxSuspensionForce=a.maxSuspensionForce;this.brake=this.engineForce=0;this.isFrontWheel=a.isFrontWheel;this.clippedInvContactDotSuspension=1;this.forwardImpulse=this.sideImpulse=this.suspensionLength=this.skidInfo=this.suspensionForce=this.suspensionRelativeVelocity=0;this.raycastResult=new l;this.worldTransform=new d;this.isInContact=!1}var e=b("../math/Vec3"),d=b("../math/Transform"),l=b("../collision/RaycastResult"),
n=b("../utils/Utils");c.exports=a;var k=new e,p=new e;k=new e;a.prototype.updateWheel=function(a){var b=this.raycastResult;if(this.isInContact){var c=b.hitNormalWorld.dot(b.directionWorld);b.hitPointWorld.vsub(a.position,p);a.getVelocityAtWorldPoint(p,k);a=b.hitNormalWorld.dot(k);-.1<=c?(this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10):(c=-1/c,this.suspensionRelativeVelocity=a*c,this.clippedInvContactDotSuspension=c)}else b.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=
0,b.directionWorld.scale(-1,b.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":10,"../math/Transform":29,"../math/Vec3":30,"../utils/Utils":53}],37:[function(b,c,f){function a(a){e.call(this);this.type=e.types.BOX;this.halfExtents=a;this.convexPolyhedronRepresentation=null;this.updateConvexPolyhedronRepresentation();this.updateBoundingSphereRadius()}c.exports=a;var e=b("./Shape"),d=b("../math/Vec3"),l=b("./ConvexPolyhedron");a.prototype=new e;a.prototype.constructor=
a;a.prototype.updateConvexPolyhedronRepresentation=function(){var a=this.halfExtents.x,b=this.halfExtents.y,c=this.halfExtents.z;a=[new d(-a,-b,-c),new d(a,-b,-c),new d(a,b,-c),new d(-a,b,-c),new d(-a,-b,c),new d(a,-b,c),new d(a,b,c),new d(-a,b,c)];new d(0,0,1);new d(0,1,0);new d(1,0,0);this.convexPolyhedronRepresentation=a=new l(a,[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]]);a.material=this.material};a.prototype.calculateLocalInertia=function(b,c){c=c||new d;a.calculateInertia(this.halfExtents,
b,c);return c};a.calculateInertia=function(a,b,c){c.x=1/12*b*(4*a.y*a.y+4*a.z*a.z);c.y=1/12*b*(4*a.x*a.x+4*a.z*a.z);c.z=1/12*b*(4*a.y*a.y+4*a.x*a.x)};a.prototype.getSideNormals=function(a,b){var c=this.halfExtents;a[0].set(c.x,0,0);a[1].set(0,c.y,0);a[2].set(0,0,c.z);a[3].set(-c.x,0,0);a[4].set(0,-c.y,0);a[5].set(0,0,-c.z);if(void 0!==b)for(c=0;c!==a.length;c++)b.vmult(a[c],a[c]);return a};a.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z};a.prototype.updateBoundingSphereRadius=
function(){this.boundingSphereRadius=this.halfExtents.norm()};var n=new d;new d;a.prototype.forEachWorldCorner=function(a,b,c){var d=this.halfExtents;d=[[d.x,d.y,d.z],[-d.x,d.y,d.z],[-d.x,-d.y,d.z],[-d.x,-d.y,-d.z],[d.x,-d.y,-d.z],[d.x,d.y,-d.z],[-d.x,d.y,-d.z],[d.x,-d.y,d.z]];for(var e=0;e<d.length;e++)n.set(d[e][0],d[e][1],d[e][2]),b.vmult(n,n),a.vadd(n,n),c(n.x,n.y,n.z)};var k=[new d,new d,new d,new d,new d,new d,new d,new d];a.prototype.calculateWorldAABB=function(a,b,c,d){var e=this.halfExtents;
k[0].set(e.x,e.y,e.z);k[1].set(-e.x,e.y,e.z);k[2].set(-e.x,-e.y,e.z);k[3].set(-e.x,-e.y,-e.z);k[4].set(e.x,-e.y,-e.z);k[5].set(e.x,e.y,-e.z);k[6].set(-e.x,e.y,-e.z);k[7].set(e.x,-e.y,e.z);var h=k[0];b.vmult(h,h);a.vadd(h,h);d.copy(h);c.copy(h);for(e=1;8>e;e++){h=k[e];b.vmult(h,h);a.vadd(h,h);var f=h.x,m=h.y;h=h.z;f>d.x&&(d.x=f);m>d.y&&(d.y=m);h>d.z&&(d.z=h);f<c.x&&(c.x=f);m<c.y&&(c.y=m);h<c.z&&(c.z=h)}}},{"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],38:[function(b,c,f){function a(a,b,
c){e.call(this);this.type=e.types.CONVEXPOLYHEDRON;this.vertices=a||[];this.worldVertices=[];this.worldVerticesNeedsUpdate=!0;this.faces=b||[];this.faceNormals=[];this.computeNormals();this.worldFaceNormalsNeedsUpdate=!0;this.worldFaceNormals=[];this.uniqueEdges=[];this.uniqueAxes=c?c.slice():null;this.computeEdges();this.updateBoundingSphereRadius()}c.exports=a;var e=b("./Shape"),d=b("../math/Vec3");b("../math/Quaternion");var l=b("../math/Transform");a.prototype=new e;a.prototype.constructor=a;
var n=new d;a.prototype.computeEdges=function(){for(var a=this.faces,b=this.vertices,c=this.uniqueEdges,d=c.length=0;d!==a.length;d++)for(var e=a[d],h=e.length,f=0;f!==h;f++){b[e[f]].vsub(b[e[(f+1)%h]],n);n.normalize();for(var m=!1,q=0;q!==c.length;q++)if(c[q].almostEquals(n)||c[q].almostEquals(n)){m=!0;break}m||c.push(n.clone())}};a.prototype.computeNormals=function(){this.faceNormals.length=this.faces.length;for(var a=0;a<this.faces.length;a++){for(var b=0;b<this.faces[a].length;b++)if(!this.vertices[this.faces[a][b]])throw Error("Vertex "+
this.faces[a][b]+" not found!");b=this.faceNormals[a]||new d;this.getFaceNormal(a,b);b.negate(b);this.faceNormals[a]=b;if(0>b.dot(this.vertices[this.faces[a][0]]))for(console.error(".faceNormals["+a+"] = Vec3("+b.toString()+") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule."),b=0;b<this.faces[a].length;b++)console.warn(".vertices["+this.faces[a][b]+"] = Vec3("+this.vertices[this.faces[a][b]].toString()+")")}};var k=
new d,p=new d;a.computeNormal=function(a,b,c,d){b.vsub(a,p);c.vsub(b,k);k.cross(p,d);d.isZero()||d.normalize()};a.prototype.getFaceNormal=function(b,c){var d=this.faces[b];return a.computeNormal(this.vertices[d[0]],this.vertices[d[1]],this.vertices[d[2]],c)};var r=new d;a.prototype.clipAgainstHull=function(a,b,c,e,h,f,m,q,k){for(var l=-1,p=-Number.MAX_VALUE,t=0;t<c.faces.length;t++){r.copy(c.faceNormals[t]);h.vmult(r,r);var n=r.dot(f);n>p&&(p=n,l=t)}p=[];t=c.faces[l];n=t.length;for(var u=0;u<n;u++){var y=
c.vertices[t[u]],x=new d;x.copy(y);h.vmult(x,x);e.vadd(x,x);p.push(x)}0<=l&&this.clipFaceAgainstHull(f,a,b,p,m,q,k)};var h=new d,m=new d,q=new d,t=new d,u=new d,w=new d;a.prototype.findSeparatingAxis=function(a,b,c,d,e,f,k,l){var p=Number.MAX_VALUE,n=0;if(this.uniqueAxes)for(y=0;y!==this.uniqueAxes.length;y++){c.vmult(this.uniqueAxes[y],h);x=this.testSepAxis(h,a,b,c,d,e);if(!1===x)return!1;x<p&&(p=x,f.copy(h))}else for(var r=k?k.length:this.faces.length,y=0;y<r;y++){x=k?k[y]:y;h.copy(this.faceNormals[x]);
c.vmult(h,h);var x=this.testSepAxis(h,a,b,c,d,e);if(!1===x)return!1;x<p&&(p=x,f.copy(h))}if(a.uniqueAxes)for(y=0;y!==a.uniqueAxes.length;y++){e.vmult(a.uniqueAxes[y],m);n++;x=this.testSepAxis(m,a,b,c,d,e);if(!1===x)return!1;x<p&&(p=x,f.copy(m))}else for(k=l?l.length:a.faces.length,y=0;y<k;y++){x=l?l[y]:y;m.copy(a.faceNormals[x]);e.vmult(m,m);n++;x=this.testSepAxis(m,a,b,c,d,e);if(!1===x)return!1;x<p&&(p=x,f.copy(m))}for(l=0;l!==this.uniqueEdges.length;l++)for(c.vmult(this.uniqueEdges[l],t),n=0;n!==
a.uniqueEdges.length;n++)if(e.vmult(a.uniqueEdges[n],u),t.cross(u,w),!w.almostZero()){w.normalize();y=this.testSepAxis(w,a,b,c,d,e);if(!1===y)return!1;y<p&&(p=y,f.copy(w))}d.vsub(b,q);0<q.dot(f)&&f.negate(f);return!0};var v=[],z=[];a.prototype.testSepAxis=function(b,c,d,e,h,f){a.project(this,b,d,e,v);a.project(c,b,h,f,z);d=v[0];b=v[1];c=z[0];e=z[1];if(d<e||c<b)return!1;d-=e;b=c-b;return d<b?d:b};var C=new d,x=new d;a.prototype.calculateLocalInertia=function(a,b){this.computeLocalAABB(C,x);var c=x.x-
C.x,d=x.y-C.y,e=x.z-C.z;b.x=1/12*a*(4*d*d+4*e*e);b.y=1/12*a*(4*c*c+4*e*e);b.z=1/12*a*(4*d*d+4*c*c)};a.prototype.getPlaneConstantOfFace=function(a){return-this.faceNormals[a].dot(this.vertices[this.faces[a][0]])};var D=new d,F=new d,K=new d,B=new d,P=new d,Q=new d,H=new d,E=new d;a.prototype.clipFaceAgainstHull=function(a,b,c,d,e,h,f){for(var m=[],q=-1,k=Number.MAX_VALUE,l=0;l<this.faces.length;l++){D.copy(this.faceNormals[l]);c.vmult(D,D);var p=D.dot(a);p<k&&(k=p,q=l)}if(!(0>q)){a=this.faces[q];a.connectedFaces=
[];for(k=0;k<this.faces.length;k++)for(l=0;l<this.faces[k].length;l++)-1!==a.indexOf(this.faces[k][l])&&k!==q&&-1===a.connectedFaces.indexOf(k)&&a.connectedFaces.push(k);k=a.length;for(l=0;l<k;l++){p=this.vertices[a[l]];p.vsub(this.vertices[a[(l+1)%k]],F);K.copy(F);c.vmult(K,K);b.vadd(K,K);B.copy(this.faceNormals[q]);c.vmult(B,B);b.vadd(B,B);K.cross(B,P);P.negate(P);Q.copy(p);c.vmult(Q,Q);b.vadd(Q,Q);Q.dot(P);p=a.connectedFaces[l];H.copy(this.faceNormals[p]);p=this.getPlaneConstantOfFace(p);E.copy(H);
c.vmult(E,E);p-=E.dot(b);for(this.clipFaceAgainstPlane(d,m,E,p);d.length;)d.shift();for(;m.length;)d.push(m.shift())}H.copy(this.faceNormals[q]);p=this.getPlaneConstantOfFace(q);E.copy(H);c.vmult(E,E);p-=E.dot(b);for(k=0;k<d.length;k++)b=E.dot(d[k])+p,b<=e&&(console.log("clamped: depth="+b+" to minDist="+(e+"")),b=e),b<=h&&(c=d[k],0>=b&&f.push({point:c,normal:E,depth:b}))}};a.prototype.clipFaceAgainstPlane=function(a,b,c,e){var h=a.length;if(2>h)return b;var f=a[a.length-1];var m=c.dot(f)+e;for(var q=
0;q<h;q++){var k=a[q];var l=c.dot(k)+e;if(0>m){if(0>l){var p=new d;p.copy(k)}else p=new d,f.lerp(k,m/(m-l),p);b.push(p)}else 0>l&&(p=new d,f.lerp(k,m/(m-l),p),b.push(p),b.push(k));f=k;m=l}return b};a.prototype.computeWorldVertices=function(a,b){for(var c=this.vertices.length;this.worldVertices.length<c;)this.worldVertices.push(new d);for(var e=this.vertices,h=this.worldVertices,f=0;f!==c;f++)b.vmult(e[f],h[f]),a.vadd(h[f],h[f]);this.worldVerticesNeedsUpdate=!1};new d;a.prototype.computeLocalAABB=
function(a,b){var c=this.vertices.length,d=this.vertices;a.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE);b.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var e=0;e<c;e++){var h=d[e];h.x<a.x?a.x=h.x:h.x>b.x&&(b.x=h.x);h.y<a.y?a.y=h.y:h.y>b.y&&(b.y=h.y);h.z<a.z?a.z=h.z:h.z>b.z&&(b.z=h.z)}};a.prototype.computeWorldFaceNormals=function(a){for(var b=this.faceNormals.length;this.worldFaceNormals.length<b;)this.worldFaceNormals.push(new d);for(var c=this.faceNormals,e=this.worldFaceNormals,
h=0;h!==b;h++)a.vmult(c[h],e[h]);this.worldFaceNormalsNeedsUpdate=!1};a.prototype.updateBoundingSphereRadius=function(){for(var a=0,b=this.vertices,c=0,d=b.length;c!==d;c++){var e=b[c].norm2();e>a&&(a=e)}this.boundingSphereRadius=Math.sqrt(a)};var I=new d;a.prototype.calculateWorldAABB=function(a,b,c,d){for(var e=this.vertices.length,h=this.vertices,f,m,k,q,l,p,t=0;t<e;t++){I.copy(h[t]);b.vmult(I,I);a.vadd(I,I);var n=I;if(n.x<f||void 0===f)f=n.x;else if(n.x>q||void 0===q)q=n.x;if(n.y<m||void 0===
m)m=n.y;else if(n.y>l||void 0===l)l=n.y;if(n.z<k||void 0===k)k=n.z;else if(n.z>p||void 0===p)p=n.z}c.set(f,m,k);d.set(q,l,p)};a.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3};a.prototype.getAveragePointLocal=function(a){a=a||new d;for(var b=this.vertices.length,c=this.vertices,e=0;e<b;e++)a.vadd(c[e],a);a.mult(1/b,a);return a};a.prototype.transformAllPoints=function(a,b){var c=this.vertices.length,d=this.vertices;if(b){for(var e=0;e<c;e++){var h=d[e];b.vmult(h,h)}for(e=
0;e<this.faceNormals.length;e++)h=this.faceNormals[e],b.vmult(h,h)}if(a)for(e=0;e<c;e++)h=d[e],h.vadd(a,h)};var A=new d,N=new d,L=new d;a.prototype.pointIsInside=function(a){var b=this.vertices,c=this.faces,d=this.faceNormals,e=this.faces.length;this.getAveragePointLocal(A);for(var h=0;h<e;h++){var f=d[h];var m=b[c[h][0]],k=N;a.vsub(m,k);k=f.dot(k);var q=L;A.vsub(m,q);f=f.dot(q);if(0>k&&0<f||0<k&&0>f)return!1}return-1};new d;var W=new d,y=new d;a.project=function(a,b,c,d,e){var h=a.vertices.length;
a=a.vertices;y.setZero();l.vectorToLocalFrame(c,d,b,W);l.pointToLocalFrame(c,d,y,y);d=y.dot(W);c=b=a[0].dot(W);for(var f=1;f<h;f++){var m=a[f].dot(W);m>b&&(b=m);m<c&&(c=m)}c-=d;b-=d;c>b&&(h=c,c=b,b=h);e[0]=b;e[1]=c}},{"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"./Shape":43}],39:[function(b,c,f){function a(a,b,c,f){var h=[],m=[],q=[],k=[],p=[],n=Math.cos,r=Math.sin;h.push(new d(b*n(0),b*r(0),.5*-c));k.push(0);h.push(new d(a*n(0),a*r(0),.5*c));p.push(1);for(var z=0;z<f;z++){var C=
2*Math.PI/f*(z+1),x=2*Math.PI/f*(z+.5);z<f-1?(h.push(new d(b*n(C),b*r(C),.5*-c)),k.push(2*z+2),h.push(new d(a*n(C),a*r(C),.5*c)),p.push(2*z+3),q.push([2*z+2,2*z+3,2*z+1,2*z])):q.push([0,1,2*z+1,2*z]);(1===f%2||z<f/2)&&m.push(new d(n(x),r(x),0))}q.push(p);m.push(new d(0,0,1));a=[];for(z=0;z<k.length;z++)a.push(k[k.length-z-1]);q.push(a);this.type=e.types.CONVEXPOLYHEDRON;l.call(this,h,q,m)}c.exports=a;var e=b("./Shape"),d=b("../math/Vec3");b("../math/Quaternion");var l=b("./ConvexPolyhedron");a.prototype=
new l},{"../math/Quaternion":28,"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],40:[function(b,c,f){function a(a,b){b=n.defaults(b,{maxValue:null,minValue:null,elementSize:1});this.data=a;this.maxValue=b.maxValue;this.minValue=b.minValue;this.elementSize=b.elementSize;null===b.minValue&&this.updateMinValue();null===b.maxValue&&this.updateMaxValue();this.cacheEnabled=!0;e.call(this);this.pillarConvex=new d;this.pillarOffset=new l;this.type=e.types.HEIGHTFIELD;this.updateBoundingSphereRadius();
this._cachedPillars={}}var e=b("./Shape"),d=b("./ConvexPolyhedron"),l=b("../math/Vec3"),n=b("../utils/Utils");c.exports=a;a.prototype=new e;a.prototype.update=function(){this._cachedPillars={}};a.prototype.updateMinValue=function(){for(var a=this.data,b=a[0][0],c=0;c!==a.length;c++)for(var d=0;d!==a[c].length;d++){var e=a[c][d];e<b&&(b=e)}this.minValue=b};a.prototype.updateMaxValue=function(){for(var a=this.data,b=a[0][0],c=0;c!==a.length;c++)for(var d=0;d!==a[c].length;d++){var e=a[c][d];e>b&&(b=
e)}this.maxValue=b};a.prototype.setHeightValueAtIndex=function(a,b,c){this.data[a][b]=c;this.clearCachedConvexTrianglePillar(a,b,!1);0<a&&(this.clearCachedConvexTrianglePillar(a-1,b,!0),this.clearCachedConvexTrianglePillar(a-1,b,!1));0<b&&(this.clearCachedConvexTrianglePillar(a,b-1,!0),this.clearCachedConvexTrianglePillar(a,b-1,!1));0<b&&0<a&&this.clearCachedConvexTrianglePillar(a-1,b-1,!0)};a.prototype.getRectMinMax=function(a,b,c,d,e){e=e||[];for(var h=this.data,f=this.minValue;a<=c;a++)for(var m=
b;m<=d;m++){var k=h[a][m];k>f&&(f=k)}e[0]=this.minValue;e[1]=f};a.prototype.getIndexOfPosition=function(a,b,c,d){var e=this.elementSize,h=this.data;a=Math.floor(a/e);b=Math.floor(b/e);c[0]=a;c[1]=b;d&&(0>a&&(a=0),0>b&&(b=0),a>=h.length-1&&(a=h.length-1),b>=h[0].length-1&&(b=h[0].length-1));return 0>a||0>b||a>=h.length-1||b>=h[0].length-1?!1:!0};a.prototype.getHeightAt=function(a,b,c){var d=[];this.getIndexOfPosition(a,b,d,c);a=[];this.getRectMinMax(d[0],d[1]+1,d[0],d[1]+1,a);return(a[0]+a[1])/2};
a.prototype.getCacheConvexTrianglePillarKey=function(a,b,c){return a+"_"+b+"_"+(c?1:0)};a.prototype.getCachedConvexTrianglePillar=function(a,b,c){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(a,b,c)]};a.prototype.setCachedConvexTrianglePillar=function(a,b,c,d,e){this._cachedPillars[this.getCacheConvexTrianglePillarKey(a,b,c)]={convex:d,offset:e}};a.prototype.clearCachedConvexTrianglePillar=function(a,b,c){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(a,b,c)]};a.prototype.getConvexTrianglePillar=
function(a,b,c){var e=this.pillarConvex,f=this.pillarOffset;if(this.cacheEnabled){var q=this.getCachedConvexTrianglePillar(a,b,c);if(q){this.pillarConvex=q.convex;this.pillarOffset=q.offset;return}e=new d;f=new l;this.pillarConvex=e;this.pillarOffset=f}q=this.data;var k=this.elementSize,p=e.faces;e.vertices.length=6;for(var n=0;6>n;n++)e.vertices[n]||(e.vertices[n]=new l);p.length=5;for(n=0;5>n;n++)p[n]||(p[n]=[]);n=e.vertices;var r=(Math.min(q[a][b],q[a+1][b],q[a][b+1],q[a+1][b+1])-this.minValue)/
2+this.minValue;c?(f.set((a+.75)*k,(b+.75)*k,r),n[0].set(.25*k,.25*k,q[a+1][b+1]-r),n[1].set(-.75*k,.25*k,q[a][b+1]-r),n[2].set(.25*k,-.75*k,q[a+1][b]-r),n[3].set(.25*k,.25*k,-r-1),n[4].set(-.75*k,.25*k,-r-1),n[5].set(.25*k,-.75*k,-r-1),p[0][0]=0,p[0][1]=1,p[0][2]=2,p[1][0]=5,p[1][1]=4,p[1][2]=3,p[2][0]=2,p[2][1]=5,p[2][2]=3,p[2][3]=0,p[3][0]=3,p[3][1]=4,p[3][2]=1,p[3][3]=0,p[4][0]=1,p[4][1]=4,p[4][2]=5,p[4][3]=2):(f.set((a+.25)*k,(b+.25)*k,r),n[0].set(-.25*k,-.25*k,q[a][b]-r),n[1].set(.75*k,-.25*
k,q[a+1][b]-r),n[2].set(-.25*k,.75*k,q[a][b+1]-r),n[3].set(-.25*k,-.25*k,-r-1),n[4].set(.75*k,-.25*k,-r-1),n[5].set(-.25*k,.75*k,-r-1),p[0][0]=0,p[0][1]=1,p[0][2]=2,p[1][0]=5,p[1][1]=4,p[1][2]=3,p[2][0]=0,p[2][1]=2,p[2][2]=5,p[2][3]=3,p[3][0]=1,p[3][1]=0,p[3][2]=3,p[3][3]=4,p[4][0]=4,p[4][1]=5,p[4][2]=2,p[4][3]=1);e.computeNormals();e.computeEdges();e.updateBoundingSphereRadius();this.setCachedConvexTrianglePillar(a,b,c,e,f)};a.prototype.calculateLocalInertia=function(a,b){b=b||new l;b.set(0,0,0);
return b};a.prototype.volume=function(){return Number.MAX_VALUE};a.prototype.calculateWorldAABB=function(a,b,c,d){c.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);d.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)};a.prototype.updateBoundingSphereRadius=function(){var a=this.data,b=this.elementSize;this.boundingSphereRadius=(new l(a.length*b,a[0].length*b,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue)))).norm()}},{"../math/Vec3":30,"../utils/Utils":53,"./ConvexPolyhedron":38,
"./Shape":43}],41:[function(b,c,f){function a(){e.call(this);this.type=e.types.PARTICLE}c.exports=a;var e=b("./Shape"),d=b("../math/Vec3");a.prototype=new e;a.prototype.constructor=a;a.prototype.calculateLocalInertia=function(a,b){b=b||new d;b.set(0,0,0);return b};a.prototype.volume=function(){return 0};a.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0};a.prototype.calculateWorldAABB=function(a,b,c,d){c.copy(a);d.copy(a)}},{"../math/Vec3":30,"./Shape":43}],42:[function(b,
c,f){function a(){e.call(this);this.type=e.types.PLANE;this.worldNormal=new d;this.worldNormalNeedsUpdate=!0;this.boundingSphereRadius=Number.MAX_VALUE}c.exports=a;var e=b("./Shape"),d=b("../math/Vec3");a.prototype=new e;a.prototype.constructor=a;a.prototype.computeWorldNormal=function(a){var b=this.worldNormal;b.set(0,0,1);a.vmult(b,b);this.worldNormalNeedsUpdate=!1};a.prototype.calculateLocalInertia=function(a,b){return b=b||new d};a.prototype.volume=function(){return Number.MAX_VALUE};var l=new d;
a.prototype.calculateWorldAABB=function(a,b,c,d){l.set(0,0,1);b.vmult(l,l);b=Number.MAX_VALUE;c.set(-b,-b,-b);d.set(b,b,b);1===l.x&&(d.x=a.x);1===l.y&&(d.y=a.y);1===l.z&&(d.z=a.z);-1===l.x&&(c.x=a.x);-1===l.y&&(c.y=a.y);-1===l.z&&(c.z=a.z)};a.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":30,"./Shape":43}],43:[function(b,c,f){function a(){this.id=a.idCounter++;this.boundingSphereRadius=this.type=0;this.collisionResponse=!0;this.material=
null}c.exports=a;a=b("./Shape");b("../math/Vec3");b("../math/Quaternion");b("../material/Material");a.prototype.constructor=a;a.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type;};a.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type;};a.prototype.calculateLocalInertia=function(a,b){throw"calculateLocalInertia() not implemented for shape type "+this.type;};a.idCounter=0;a.types={SPHERE:1,
PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256}},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"./Shape":43}],44:[function(b,c,f){function a(a){e.call(this);this.radius=void 0!==a?Number(a):1;this.type=e.types.SPHERE;if(0>this.radius)throw Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}c.exports=a;var e=b("./Shape"),d=b("../math/Vec3");a.prototype=new e;a.prototype.constructor=a;a.prototype.calculateLocalInertia=
function(a,b){b=b||new d;var c=2*a*this.radius*this.radius/5;b.x=c;b.y=c;b.z=c;return b};a.prototype.volume=function(){return 4*Math.PI*this.radius/3};a.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius};a.prototype.calculateWorldAABB=function(a,b,c,d){b=this.radius;for(var e=["x","y","z"],h=0;h<e.length;h++){var f=e[h];c[f]=a[f]-b;d[f]=a[f]+b}}},{"../math/Vec3":30,"./Shape":43}],45:[function(b,c,f){function a(a,b){e.call(this);this.type=e.types.TRIMESH;this.vertices=
new Float32Array(a);this.indices=new Int16Array(b);this.normals=new Float32Array(b.length);this.aabb=new n;this.edges=null;this.scale=new d(1,1,1);this.tree=new k;this.updateEdges();this.updateNormals();this.updateAABB();this.updateBoundingSphereRadius();this.updateTree()}c.exports=a;var e=b("./Shape"),d=b("../math/Vec3");b("../math/Quaternion");var l=b("../math/Transform"),n=b("../collision/AABB"),k=b("../utils/Octree");a.prototype=new e;a.prototype.constructor=a;var p=new d;a.prototype.updateTree=
function(){var a=this.tree;a.reset();a.aabb.copy(this.aabb);var b=this.scale;a.aabb.lowerBound.x*=1/b.x;a.aabb.lowerBound.y*=1/b.y;a.aabb.lowerBound.z*=1/b.z;a.aabb.upperBound.x*=1/b.x;a.aabb.upperBound.y*=1/b.y;a.aabb.upperBound.z*=1/b.z;b=new n;for(var c=new d,e=new d,h=new d,f=[c,e,h],m=0;m<this.indices.length/3;m++){var q=3*m;this._getUnscaledVertex(this.indices[q],c);this._getUnscaledVertex(this.indices[q+1],e);this._getUnscaledVertex(this.indices[q+2],h);b.setFromPoints(f);a.insert(b,m)}a.removeEmptyNodes()};
var r=new n;a.prototype.getTrianglesInAABB=function(a,b){r.copy(a);var c=this.scale,d=c.x,e=c.y;c=c.z;var h=r.lowerBound,f=r.upperBound;h.x/=d;h.y/=e;h.z/=c;f.x/=d;f.y/=e;f.z/=c;return this.tree.aabbQuery(r,b)};a.prototype.setScale=function(a){var b=a.x===a.y===a.z;this.scale.x===this.scale.y===this.scale.z&&b||this.updateNormals();this.scale.copy(a);this.updateAABB();this.updateBoundingSphereRadius()};a.prototype.updateNormals=function(){for(var b=this.normals,c=0;c<this.indices.length/3;c++){var d=
3*c,e=this.indices[d+1],h=this.indices[d+2];this.getVertex(this.indices[d],u);this.getVertex(e,w);this.getVertex(h,v);a.computeNormal(w,u,v,p);b[d]=p.x;b[d+1]=p.y;b[d+2]=p.z}};a.prototype.updateEdges=function(){for(var a={},b=function(b,c){a[e<h?e+"_"+h:h+"_"+e]=!0},c=0;c<this.indices.length/3;c++){var d=3*c,e=this.indices[d],h=this.indices[d+1];d=this.indices[d+2];b(e,h);b(h,d);b(d,e)}b=Object.keys(a);this.edges=new Int16Array(2*b.length);for(c=0;c<b.length;c++)d=b[c].split("_"),this.edges[2*c]=
parseInt(d[0],10),this.edges[2*c+1]=parseInt(d[1],10)};a.prototype.getEdgeVertex=function(a,b,c){this.getVertex(this.edges[2*a+(b?1:0)],c)};var h=new d,m=new d;a.prototype.getEdgeVector=function(a,b){this.getEdgeVertex(a,0,h);this.getEdgeVertex(a,1,m);m.vsub(h,b)};var q=new d,t=new d;a.computeNormal=function(a,b,c,d){b.vsub(a,t);c.vsub(b,q);q.cross(t,d);d.isZero()||d.normalize()};var u=new d,w=new d,v=new d;a.prototype.getVertex=function(a,b){var c=this.scale;this._getUnscaledVertex(a,b);b.x*=c.x;
b.y*=c.y;b.z*=c.z;return b};a.prototype._getUnscaledVertex=function(a,b){var c=3*a,d=this.vertices;return b.set(d[c],d[c+1],d[c+2])};a.prototype.getWorldVertex=function(a,b,c,d){this.getVertex(a,d);l.pointToWorldFrame(b,c,d,d);return d};a.prototype.getTriangleVertices=function(a,b,c,d){a*=3;this.getVertex(this.indices[a],b);this.getVertex(this.indices[a+1],c);this.getVertex(this.indices[a+2],d)};a.prototype.getNormal=function(a,b){var c=3*a;return b.set(this.normals[c],this.normals[c+1],this.normals[c+
2])};var z=new n;a.prototype.calculateLocalInertia=function(a,b){this.computeLocalAABB(z);var c=z.upperBound.x-z.lowerBound.x,d=z.upperBound.y-z.lowerBound.y,e=z.upperBound.z-z.lowerBound.z;return b.set(1/12*a*(4*d*d+4*e*e),1/12*a*(4*c*c+4*e*e),1/12*a*(4*d*d+4*c*c))};var C=new d;a.prototype.computeLocalAABB=function(a){var b=a.lowerBound;a=a.upperBound;var c=this.vertices.length;this.getVertex(0,C);b.copy(C);a.copy(C);for(var d=0;d!==c;d++)this.getVertex(d,C),C.x<b.x?b.x=C.x:C.x>a.x&&(a.x=C.x),C.y<
b.y?b.y=C.y:C.y>a.y&&(a.y=C.y),C.z<b.z?b.z=C.z:C.z>a.z&&(a.z=C.z)};a.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)};a.prototype.updateBoundingSphereRadius=function(){var a=0,b=this.vertices,c=new d,e=0;for(b=b.length/3;e!==b;e++){this.getVertex(e,c);var h=c.norm2();h>a&&(a=h)}this.boundingSphereRadius=Math.sqrt(a)};new d;var x=new l,D=new n;a.prototype.calculateWorldAABB=function(a,b,c,d){x.position=a;x.quaternion=b;this.aabb.toWorldFrame(x,D);c.copy(D.lowerBound);d.copy(D.upperBound)};
a.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3};a.createTorus=function(b,c,d,e,h){b=b||1;c=c||.5;d=d||8;e=e||6;h=h||2*Math.PI;for(var f=[],m=[],q=0;q<=d;q++)for(var k=0;k<=e;k++){var l=k/e*h,p=q/d*Math.PI*2;f.push((b+c*Math.cos(p))*Math.cos(l),(b+c*Math.cos(p))*Math.sin(l),c*Math.sin(p))}for(q=1;q<=d;q++)for(k=1;k<=e;k++)b=(e+1)*(q-1)+k-1,c=(e+1)*(q-1)+k,h=(e+1)*q+k,m.push((e+1)*q+k-1,b,h),m.push(b,c,h);return new a(f,m)}},{"../collision/AABB":3,"../math/Quaternion":28,
"../math/Transform":29,"../math/Vec3":30,"../utils/Octree":50,"./Shape":43}],46:[function(b,c,f){function a(){e.call(this);this.iterations=10;this.tolerance=1E-7}c.exports=a;b("../math/Vec3");b("../math/Quaternion");var e=b("./Solver");a.prototype=new e;var d=[],l=[],n=[];a.prototype.solve=function(a,b){var c=0,e=this.iterations,f=this.tolerance*this.tolerance,q=this.equations,k=q.length,p=b.bodies,w=p.length,v;if(0!==k)for(v=0;v!==w;v++)p[v].updateSolveMassProperties();l.length=k;n.length=k;d.length=
k;for(v=0;v!==k;v++){var z=q[v];d[v]=0;n[v]=z.computeB(a);l[v]=1/z.computeC()}if(0!==k){for(v=0;v!==w;v++)z=p[v],c=z.wlambda,z.vlambda.set(0,0,0),c&&c.set(0,0,0);for(c=0;c!==e;c++){for(var C=v=0;C!==k;C++){z=q[C];var x=n[C];var D=l[C];var F=d[C];var K=z.computeGWlambda();x=D*(x-K-z.eps*F);F+x<z.minForce?x=z.minForce-F:F+x>z.maxForce&&(x=z.maxForce-F);d[C]+=x;v+=0<x?x:-x;z.addToWlambda(x)}if(v*v<f)break}for(v=0;v!==w;v++)z=p[v],e=z.velocity,f=z.angularVelocity,e.vadd(z.vlambda,e),f&&f.vadd(z.wlambda,
f)}return c}},{"../math/Quaternion":28,"../math/Vec3":30,"./Solver":47}],47:[function(b,c,f){function a(){this.equations=[]}c.exports=a;a.prototype.solve=function(a,b){return 0};a.prototype.addEquation=function(a){a.enabled&&this.equations.push(a)};a.prototype.removeEquation=function(a){var b=this.equations;a=b.indexOf(a);-1!==a&&b.splice(a,1)};a.prototype.removeAllEquations=function(){this.equations.length=0}},{}],48:[function(b,c,f){function a(a){n.call(this);this.iterations=10;this.tolerance=1E-7;
this.subsolver=a;this.nodes=[];for(this.nodePool=[];128>this.nodePool.length;)this.nodePool.push(this.createNode())}function e(a){for(var b=a.length,c=0;c!==b;c++){var d=a[c];if(!(d.visited||d.body.type&h))return d}return!1}function d(a,b,c){b.push(a.body);b=a.eqs.length;for(var d=0;d!==b;d++){var e=a.eqs[d];-1===c.indexOf(e)&&c.push(e)}}function l(a,b){return b.id-a.id}c.exports=a;b("../math/Vec3");b("../math/Quaternion");var n=b("./Solver");b=b("../objects/Body");a.prototype=new n;var k=[],p=[],
r={bodies:[]},h=b.STATIC,m=[];a.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}};a.prototype.solve=function(a,b){for(var c=this.nodePool,h=b.bodies,f=this.equations,q=f.length,n=h.length,t=this.subsolver;c.length<n;)c.push(this.createNode());k.length=n;for(var D=0;D<n;D++)k[D]=c[D];for(D=0;D!==n;D++)c=k[D],c.body=h[D],c.children.length=0,c.eqs.length=0,c.visited=!1;for(n=0;n!==q;n++){c=f[n];D=h.indexOf(c.bi);var F=h.indexOf(c.bj);D=k[D];F=k[F];D.children.push(F);D.eqs.push(c);
F.children.push(D);F.eqs.push(c)}h=0;f=p;t.tolerance=this.tolerance;for(t.iterations=this.iterations;D=e(k);){f.length=0;r.bodies.length=0;c=D;D=d;q=r.bodies;n=f;m.push(c);c.visited=!0;for(D(c,q,n);m.length;)for(c=m.pop();F=e(c.children);)F.visited=!0,D(F,q,n),m.push(F);q=f.length;f=f.sort(l);for(D=0;D!==q;D++)t.addEquation(f[D]);t.solve(a,r);t.removeAllEquations();h++}return h}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"./Solver":47}],49:[function(b,c,f){b=function(){};c.exports=
b;b.prototype={constructor:b,addEventListener:function(a,b){void 0===this._listeners&&(this._listeners={});var c=this._listeners;void 0===c[a]&&(c[a]=[]);-1===c[a].indexOf(b)&&c[a].push(b);return this},hasEventListener:function(a,b){if(void 0===this._listeners)return!1;var c=this._listeners;return void 0!==c[a]&&-1!==c[a].indexOf(b)?!0:!1},removeEventListener:function(a,b){if(void 0===this._listeners)return this;var c=this._listeners;if(void 0===c[a])return this;var e=c[a].indexOf(b);-1!==e&&c[a].splice(e,
1);return this},dispatchEvent:function(a){if(void 0===this._listeners)return this;var b=this._listeners[a.type];if(void 0!==b){a.target=this;for(var c=0,f=b.length;c<f;c++)b[c].call(this,a)}return this}}},{}],50:[function(b,c,f){function a(a){a=a||{};this.root=a.root||null;this.aabb=a.aabb?a.aabb.clone():new d;this.data=[];this.children=[]}function e(b,c){c=c||{};c.root=null;c.aabb=b;a.call(this,c);this.maxDepth="undefined"!==typeof c.maxDepth?c.maxDepth:8}var d=b("../collision/AABB"),l=b("../math/Vec3");
c.exports=e;e.prototype=new a;a.prototype.reset=function(a,b){this.children.length=this.data.length=0};a.prototype.insert=function(a,b,c){var d=this.data;c=c||0;if(!this.aabb.contains(a))return!1;var e=this.children;if(c<(this.maxDepth||this.root.maxDepth)){var h=!1;e.length||(this.subdivide(),h=!0);for(var f=0;8!==f;f++)if(e[f].insert(a,b,c+1))return!0;h&&(e.length=0)}d.push(b);return!0};var n=new l;a.prototype.subdivide=function(){var b=this.aabb,c=b.lowerBound,e=b.upperBound;b=this.children;b.push(new a({aabb:new d({lowerBound:new l(0,
0,0)})}),new a({aabb:new d({lowerBound:new l(1,0,0)})}),new a({aabb:new d({lowerBound:new l(1,1,0)})}),new a({aabb:new d({lowerBound:new l(1,1,1)})}),new a({aabb:new d({lowerBound:new l(0,1,1)})}),new a({aabb:new d({lowerBound:new l(0,0,1)})}),new a({aabb:new d({lowerBound:new l(1,0,1)})}),new a({aabb:new d({lowerBound:new l(0,1,0)})}));e.vsub(c,n);n.scale(.5,n);e=this.root||this;for(var f=0;8!==f;f++){var q=b[f];q.root=e;var k=q.aabb.lowerBound;k.x*=n.x;k.y*=n.y;k.z*=n.z;k.vadd(c,k);k.vadd(n,q.aabb.upperBound)}};
a.prototype.aabbQuery=function(a,b){for(var c=[this];c.length;){var d=c.pop();d.aabb.overlaps(a)&&Array.prototype.push.apply(b,d.data);Array.prototype.push.apply(c,d.children)}return b};var k=new d;a.prototype.rayQuery=function(a,b,c){a.getAABB(k);k.toLocalFrame(b,k);this.aabbQuery(k,c);return c};a.prototype.removeEmptyNodes=function(){for(var a=[this];a.length;){for(var b=a.pop(),c=b.children.length-1;0<=c;c--)b.children[c].data.length||b.children.splice(c,1);Array.prototype.push.apply(a,b.children)}}},
{"../collision/AABB":3,"../math/Vec3":30}],51:[function(b,c,f){function a(){this.objects=[];this.type=Object}c.exports=a;a.prototype.release=function(){for(var a=arguments.length,b=0;b!==a;b++)this.objects.push(arguments[b])};a.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()};a.prototype.constructObject=function(){throw Error("constructObject() not implemented in this Pool subclass yet!");}},{}],52:[function(b,c,f){function a(){this.data={keys:[]}}
c.exports=a;a.prototype.get=function(a,b){if(a>b){var c=b;b=a;a=c}return this.data[a+"-"+b]};a.prototype.set=function(a,b,c){if(a>b){var d=b;b=a;a=d}d=a+"-"+b;this.get(a,b)||this.data.keys.push(d);this.data[d]=c};a.prototype.reset=function(){for(var a=this.data,b=a.keys;0<b.length;){var c=b.pop();delete a[c]}}},{}],53:[function(b,c,f){function a(){}c.exports=a;a.defaults=function(a,b){a=a||{};for(var c in b)c in a||(a[c]=b[c]);return a}},{}],54:[function(b,c,f){function a(){d.call(this);this.type=
e}c.exports=a;var e=b("../math/Vec3"),d=b("./Pool");a.prototype=new d;a.prototype.constructObject=function(){return new e}},{"../math/Vec3":30,"./Pool":51}],55:[function(b,c,f){function a(a){this.contactPointPool=[];this.frictionEquationPool=[];this.result=[];this.frictionResult=[];this.v3pool=new k;this.world=a;this.currentContactMaterial=null;this.enableFrictionReduction=!1}c.exports=a;c=b("../collision/AABB");f=b("../shapes/Shape");var e=b("../collision/Ray"),d=b("../math/Vec3"),l=b("../math/Transform");
b("../shapes/ConvexPolyhedron");var n=b("../math/Quaternion");b("../solver/Solver");var k=b("../utils/Vec3Pool"),p=b("../equations/ContactEquation"),r=b("../equations/FrictionEquation");a.prototype.createContactEquation=function(a,b,c,d,e,h){if(this.contactPointPool.length){var f=this.contactPointPool.pop();f.bi=a;f.bj=b}else f=new p(a,b);f.enabled=a.collisionResponse&&b.collisionResponse&&c.collisionResponse&&d.collisionResponse;var m=this.currentContactMaterial;f.restitution=m.restitution;f.setSpookParams(m.contactEquationStiffness,
m.contactEquationRelaxation,this.world.dt);a=c.material||a.material;b=d.material||b.material;a&&b&&0<=a.restitution&&0<=b.restitution&&(f.restitution=a.restitution*b.restitution);f.si=e||c;f.sj=h||d;return f};a.prototype.createFrictionEquationsFromContact=function(a,b){var c=a.bi,d=a.bj,e=this.world,h=this.currentContactMaterial,f=h.friction,m=a.si.material||c.material,q=a.sj.material||d.material;m&&q&&0<=m.friction&&0<=q.friction&&(f=m.friction*q.friction);if(0<f){f*=e.gravity.length();m=c.invMass+
d.invMass;0<m&&(m=1/m);var k=this.frictionEquationPool;q=k.length?k.pop():new r(c,d,f*m);k=k.length?k.pop():new r(c,d,f*m);q.bi=k.bi=c;q.bj=k.bj=d;q.minForce=k.minForce=-f*m;q.maxForce=k.maxForce=f*m;q.ri.copy(a.ri);q.rj.copy(a.rj);k.ri.copy(a.ri);k.rj.copy(a.rj);a.ni.tangents(q.t,k.t);q.setSpookParams(h.frictionEquationStiffness,h.frictionEquationRelaxation,e.dt);k.setSpookParams(h.frictionEquationStiffness,h.frictionEquationRelaxation,e.dt);q.enabled=k.enabled=a.enabled;b.push(q,k);return!0}return!1};
var h=new d,m=new d,q=new d;a.prototype.createFrictionFromAverage=function(a){var b=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(b,this.frictionResult)&&1!==a){var c=this.frictionResult[this.frictionResult.length-2],d=this.frictionResult[this.frictionResult.length-1];h.setZero();m.setZero();q.setZero();for(var e=b.bi,f=0;f!==a;f++)b=this.result[this.result.length-1-f],b.bodyA!==e?(h.vadd(b.ni,h),m.vadd(b.ri,m),q.vadd(b.rj,q)):(h.vsub(b.ni,h),m.vadd(b.rj,m),q.vadd(b.ri,
q));a=1/a;m.scale(a,c.ri);q.scale(a,c.rj);d.ri.copy(c.ri);d.rj.copy(c.rj);h.normalize();h.tangents(c.t,d.t)}};var t=new d,u=new d,w=new n,v=new n;a.prototype.getContacts=function(a,b,c,d,e,h,f){this.contactPointPool=e;this.frictionEquationPool=f;this.result=d;this.frictionResult=h;d=0;for(e=a.length;d!==e;d++){h=a[d];f=b[d];var m=null;h.material&&f.material&&(m=c.getContactMaterial(h.material,f.material)||null);for(var q=0;q<h.shapes.length;q++){h.quaternion.mult(h.shapeOrientations[q],w);h.quaternion.vmult(h.shapeOffsets[q],
t);t.vadd(h.position,t);for(var k=h.shapes[q],l=0;l<f.shapes.length;l++){f.quaternion.mult(f.shapeOrientations[l],v);f.quaternion.vmult(f.shapeOffsets[l],u);u.vadd(f.position,u);var p=f.shapes[l];if(!(t.distanceTo(u)>k.boundingSphereRadius+p.boundingSphereRadius)){var n=null;k.material&&p.material&&(n=c.getContactMaterial(k.material,p.material)||null);this.currentContactMaterial=n||m||c.defaultContactMaterial;(n=this[k.type|p.type])&&(k.type<p.type?n.call(this,k,p,t,u,w,v,h,f,k,p):n.call(this,p,k,
u,t,v,w,f,h,k,p))}}}}};a.prototype[f.types.BOX|f.types.BOX]=a.prototype.boxBox=function(a,b,c,d,e,h,f,m){a.convexPolyhedronRepresentation.material=a.material;b.convexPolyhedronRepresentation.material=b.material;a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse;b.convexPolyhedronRepresentation.collisionResponse=b.collisionResponse;this.convexConvex(a.convexPolyhedronRepresentation,b.convexPolyhedronRepresentation,c,d,e,h,f,m,a,b)};a.prototype[f.types.BOX|f.types.CONVEXPOLYHEDRON]=
a.prototype.boxConvex=function(a,b,c,d,e,h,f,m){a.convexPolyhedronRepresentation.material=a.material;a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse;this.convexConvex(a.convexPolyhedronRepresentation,b,c,d,e,h,f,m,a,b)};a.prototype[f.types.BOX|f.types.PARTICLE]=a.prototype.boxParticle=function(a,b,c,d,e,h,f,m){a.convexPolyhedronRepresentation.material=a.material;a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse;this.convexParticle(a.convexPolyhedronRepresentation,
b,c,d,e,h,f,m,a,b)};a.prototype[f.types.SPHERE]=a.prototype.sphereSphere=function(a,b,c,d,e,h,f,m){e=this.createContactEquation(f,m,a,b);d.vsub(c,e.ni);e.ni.normalize();e.ri.copy(e.ni);e.rj.copy(e.ni);e.ri.mult(a.radius,e.ri);e.rj.mult(-b.radius,e.rj);e.ri.vadd(c,e.ri);e.ri.vsub(f.position,e.ri);e.rj.vadd(d,e.rj);e.rj.vsub(m.position,e.rj);this.result.push(e);this.createFrictionEquationsFromContact(e,this.frictionResult)};var z=new d,C=new d,x=new d;a.prototype[f.types.PLANE|f.types.TRIMESH]=a.prototype.planeTrimesh=
function(a,b,c,e,h,f,m,q){var k=new d;z.set(0,0,1);h.vmult(z,z);for(h=0;h<b.vertices.length/3;h++){b.getVertex(h,k);var p=new d;p.copy(k);l.pointToWorldFrame(e,f,p,k);p=C;k.vsub(c,p);if(0>=z.dot(p)){var n=this.createContactEquation(m,q,a,b);n.ni.copy(z);var t=x;z.scale(p.dot(z),t);k.vsub(t,t);n.ri.copy(t);n.ri.vsub(m.position,n.ri);n.rj.copy(k);n.rj.vsub(q.position,n.rj);this.result.push(n);this.createFrictionEquationsFromContact(n,this.frictionResult)}}};var D=new d,F=new d;new d;var K=new d,B=new d,
P=new d,Q=new d,H=new d,E=new d,I=new d,A=new d,N=new d,L=new d,W=new d,y=new c,J=[];a.prototype[f.types.SPHERE|f.types.TRIMESH]=a.prototype.sphereTrimesh=function(a,b,c,d,h,f,m,q){l.pointToLocalFrame(d,f,c,I);h=a.radius;y.lowerBound.set(I.x-h,I.y-h,I.z-h);y.upperBound.set(I.x+h,I.y+h,I.z+h);b.getTrianglesInAABB(y,J);var k=a.radius*a.radius;for(h=0;h<J.length;h++)for(var p=0;3>p;p++)if(b.getVertex(b.indices[3*J[h]+p],K),K.vsub(I,F),F.norm2()<=k){B.copy(K);l.pointToWorldFrame(d,f,B,K);K.vsub(c,F);
var n=this.createContactEquation(m,q,a,b);n.ni.copy(F);n.ni.normalize();n.ri.copy(n.ni);n.ri.scale(a.radius,n.ri);n.ri.vadd(c,n.ri);n.ri.vsub(m.position,n.ri);n.rj.copy(K);n.rj.vsub(q.position,n.rj);this.result.push(n);this.createFrictionEquationsFromContact(n,this.frictionResult)}for(h=0;h<J.length;h++)for(p=0;3>p;p++)b.getVertex(b.indices[3*J[h]+p],P),b.getVertex(b.indices[3*J[h]+(p+1)%3],Q),Q.vsub(P,H),I.vsub(Q,A),c=A.dot(H),I.vsub(P,A),n=A.dot(H),0<n&&0>c&&(I.vsub(P,A),E.copy(H),E.normalize(),
n=A.dot(E),E.scale(n,A),A.vadd(P,A),c=A.distanceTo(I),c<a.radius&&(n=this.createContactEquation(m,q,a,b),A.vsub(I,n.ni),n.ni.normalize(),n.ni.scale(a.radius,n.ri),l.pointToWorldFrame(d,f,A,A),A.vsub(q.position,n.rj),l.vectorToWorldFrame(f,n.ni,n.ni),l.vectorToWorldFrame(f,n.ri,n.ri),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult)));h=0;for(p=J.length;h!==p;h++)b.getTriangleVertices(J[h],N,L,W),b.getNormal(J[h],D),I.vsub(N,A),c=A.dot(D),D.scale(c,A),I.vsub(A,A),c=
A.distanceTo(I),e.pointInTriangle(A,N,L,W)&&c<a.radius&&(n=this.createContactEquation(m,q,a,b),A.vsub(I,n.ni),n.ni.normalize(),n.ni.scale(a.radius,n.ri),l.pointToWorldFrame(d,f,A,A),A.vsub(q.position,n.rj),l.vectorToWorldFrame(f,n.ni,n.ni),l.vectorToWorldFrame(f,n.ri,n.ri),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult));J.length=0};var V=new d,U=new d;a.prototype[f.types.SPHERE|f.types.PLANE]=a.prototype.spherePlane=function(a,b,c,d,e,h,f,m){b=this.createContactEquation(f,
m,a,b);b.ni.set(0,0,1);h.vmult(b.ni,b.ni);b.ni.negate(b.ni);b.ni.normalize();b.ni.mult(a.radius,b.ri);c.vsub(d,V);b.ni.mult(b.ni.dot(V),U);V.vsub(U,b.rj);-V.dot(b.ni)<=a.radius&&(a=b.ri,h=b.rj,a.vadd(c,a),a.vsub(f.position,a),h.vadd(d,h),h.vsub(m.position,h),this.result.push(b),this.createFrictionEquationsFromContact(b,this.frictionResult))};var R=new d,G=new d,O=new d,T=new d,M=new d,S=new d,Z=new d,X=[new d,new d,new d,new d,new d,new d],ja=new d,ba=new d,Y=new d,da=new d;a.prototype[f.types.SPHERE|
f.types.BOX]=a.prototype.sphereBox=function(a,b,c,d,e,h,f,m){e=this.v3pool;c.vsub(d,T);b.getSideNormals(X,h);h=a.radius;for(var q=!1,k=null,l=0,n=0,p=0,t=null,r=0,y=X.length;r!==y&&!1===q;r++){var x=M;x.copy(X[r]);var u=x.norm();x.normalize();var v=T.dot(x);if(v<u+h&&0<v){var L=S,w=Z;L.copy(X[(r+1)%3]);w.copy(X[(r+2)%3]);var D=L.norm(),B=w.norm();L.normalize();w.normalize();var A=T.dot(L),z=T.dot(w);A<D&&A>-D&&z<B&&z>-B&&(v=Math.abs(v-u-h),null===t||v<t)&&(t=v,n=A,p=z,k=u,ba.copy(x),Y.copy(L),da.copy(w),
l++)}}l&&(q=!0,l=this.createContactEquation(f,m,a,b),ba.mult(-h,l.ri),l.ni.copy(ba),l.ni.negate(l.ni),ba.mult(k,ba),Y.mult(n,Y),ba.vadd(Y,ba),da.mult(p,da),ba.vadd(da,l.rj),l.ri.vadd(c,l.ri),l.ri.vsub(f.position,l.ri),l.rj.vadd(d,l.rj),l.rj.vsub(m.position,l.rj),this.result.push(l),this.createFrictionEquationsFromContact(l,this.frictionResult));v=e.get();for(k=0;2!==k&&!q;k++)for(n=0;2!==n&&!q;n++)for(p=0;2!==p&&!q;p++)v.set(0,0,0),k?v.vadd(X[0],v):v.vsub(X[0],v),n?v.vadd(X[1],v):v.vsub(X[1],v),p?
v.vadd(X[2],v):v.vsub(X[2],v),d.vadd(v,ja),ja.vsub(c,ja),ja.norm2()<h*h&&(q=!0,l=this.createContactEquation(f,m,a,b),l.ri.copy(ja),l.ri.normalize(),l.ni.copy(l.ri),l.ri.mult(h,l.ri),l.rj.copy(v),l.ri.vadd(c,l.ri),l.ri.vsub(f.position,l.ri),l.rj.vadd(d,l.rj),l.rj.vsub(m.position,l.rj),this.result.push(l),this.createFrictionEquationsFromContact(l,this.frictionResult));e.release(v);t=e.get();r=e.get();l=e.get();y=e.get();v=e.get();x=X.length;for(k=0;k!==x&&!q;k++)for(n=0;n!==x&&!q;n++)if(k%3!==n%3){X[n].cross(X[k],
t);t.normalize();X[k].vadd(X[n],r);l.copy(c);l.vsub(r,l);l.vsub(d,l);u=l.dot(t);t.mult(u,y);for(p=0;p===k%3||p===n%3;)p++;v.copy(c);v.vsub(y,v);v.vsub(r,v);v.vsub(d,v);u=Math.abs(u);L=v.norm();u<X[p].norm()&&L<h&&(q=!0,p=this.createContactEquation(f,m,a,b),r.vadd(y,p.rj),p.rj.copy(p.rj),v.negate(p.ni),p.ni.normalize(),p.ri.copy(p.rj),p.ri.vadd(d,p.ri),p.ri.vsub(c,p.ri),p.ri.normalize(),p.ri.mult(h,p.ri),p.ri.vadd(c,p.ri),p.ri.vsub(f.position,p.ri),p.rj.vadd(d,p.rj),p.rj.vsub(m.position,p.rj),this.result.push(p),
this.createFrictionEquationsFromContact(p,this.frictionResult))}e.release(t,r,l,y,v)};var fa=new d,ca=new d,ka=new d,ha=new d,ma=new d,oa=new d,la=new d,na=new d,va=new d,sa=new d;a.prototype[f.types.SPHERE|f.types.CONVEXPOLYHEDRON]=a.prototype.sphereConvex=function(a,b,c,d,e,h,f,m){e=this.v3pool;c.vsub(d,fa);for(var q=b.faceNormals,k=b.faces,l=b.vertices,n=a.radius,p=0;p!==l.length;p++){var t=ma;h.vmult(l[p],t);d.vadd(t,t);var r=ha;t.vsub(c,r);if(r.norm2()<n*n){a=this.createContactEquation(f,m,a,
b);a.ri.copy(r);a.ri.normalize();a.ni.copy(a.ri);a.ri.mult(n,a.ri);t.vsub(d,a.rj);a.ri.vadd(c,a.ri);a.ri.vsub(f.position,a.ri);a.rj.vadd(d,a.rj);a.rj.vsub(m.position,a.rj);this.result.push(a);this.createFrictionEquationsFromContact(a,this.frictionResult);return}}p=0;for(t=k.length;p!==t;p++){r=k[p];var y=oa;h.vmult(q[p],y);var x=la;h.vmult(l[r[0]],x);x.vadd(d,x);var u=na;y.mult(-n,u);c.vadd(u,u);var v=va;u.vsub(x,v);u=v.dot(y);v=sa;c.vsub(x,v);if(0>u&&0<v.dot(y)){x=[];v=0;for(var L=r.length;v!==L;v++){var w=
e.get();h.vmult(l[r[v]],w);d.vadd(w,w);x.push(w)}a:{v=x;L=y;w=c;for(var D=null,B=v.length,A=0;A!==B;A++){var z=v[A],F=R;v[(A+1)%B].vsub(z,F);var C=G;F.cross(L,C);F=O;w.vsub(z,F);z=C.dot(F);if(null===D||0<z&&!0===D||0>=z&&!1===D)null===D&&(D=0<z);else{v=!1;break a}}v=!0}if(v){a=this.createContactEquation(f,m,a,b);y.mult(-n,a.ri);y.negate(a.ni);b=e.get();y.mult(-u,b);h=e.get();y.mult(-n,h);c.vsub(d,a.rj);a.rj.vadd(h,a.rj);a.rj.vadd(b,a.rj);a.rj.vadd(d,a.rj);a.rj.vsub(m.position,a.rj);a.ri.vadd(c,a.ri);
a.ri.vsub(f.position,a.ri);e.release(b);e.release(h);this.result.push(a);this.createFrictionEquationsFromContact(a,this.frictionResult);v=0;for(r=x.length;v!==r;v++)e.release(x[v]);break}else for(v=0;v!==r.length;v++){y=e.get();u=e.get();h.vmult(l[r[(v+1)%r.length]],y);h.vmult(l[r[(v+2)%r.length]],u);d.vadd(y,y);d.vadd(u,u);B=ca;u.vsub(y,B);D=ka;B.unit(D);L=e.get();w=e.get();c.vsub(y,w);A=w.dot(D);D.mult(A,L);L.vadd(y,L);D=e.get();L.vsub(c,D);if(0<A&&A*A<B.norm2()&&D.norm2()<n*n){a=this.createContactEquation(f,
m,a,b);L.vsub(d,a.rj);L.vsub(c,a.ni);a.ni.normalize();a.ni.mult(n,a.ri);a.rj.vadd(d,a.rj);a.rj.vsub(m.position,a.rj);a.ri.vadd(c,a.ri);a.ri.vsub(f.position,a.ri);this.result.push(a);this.createFrictionEquationsFromContact(a,this.frictionResult);v=0;for(r=x.length;v!==r;v++)e.release(x[v]);e.release(y);e.release(u);e.release(L);e.release(D);e.release(w);return}e.release(y);e.release(u);e.release(L);e.release(D);e.release(w)}v=0;for(r=x.length;v!==r;v++)e.release(x[v])}}};new d;new d;a.prototype[f.types.PLANE|
f.types.BOX]=a.prototype.planeBox=function(a,b,c,d,e,h,f,m){b.convexPolyhedronRepresentation.material=b.material;b.convexPolyhedronRepresentation.collisionResponse=b.collisionResponse;this.planeConvex(a,b.convexPolyhedronRepresentation,c,d,e,h,f,m)};var ia=new d,aa=new d,pa=new d,Sa=new d;a.prototype[f.types.PLANE|f.types.CONVEXPOLYHEDRON]=a.prototype.planeConvex=function(a,b,c,d,e,h,f,m){aa.set(0,0,1);e.vmult(aa,aa);for(var q=e=0;q!==b.vertices.length;q++)if(ia.copy(b.vertices[q]),h.vmult(ia,ia),
d.vadd(ia,ia),ia.vsub(c,pa),0>=aa.dot(pa)){var k=this.createContactEquation(f,m,a,b),l=Sa;aa.mult(aa.dot(pa),l);ia.vsub(l,l);l.vsub(c,k.ri);k.ni.copy(aa);ia.vsub(d,k.rj);k.ri.vadd(c,k.ri);k.ri.vsub(f.position,k.ri);k.rj.vadd(d,k.rj);k.rj.vsub(m.position,k.rj);this.result.push(k);e++;this.enableFrictionReduction||this.createFrictionEquationsFromContact(k,this.frictionResult)}this.enableFrictionReduction&&e&&this.createFrictionFromAverage(e)};var ab=new d,Ta=new d;a.prototype[f.types.CONVEXPOLYHEDRON]=
a.prototype.convexConvex=function(a,b,c,d,e,h,f,m,q,k,l,n){if(!(c.distanceTo(d)>a.boundingSphereRadius+b.boundingSphereRadius)&&a.findSeparatingAxis(b,c,e,d,h,ab,l,n)){l=[];a.clipAgainstHull(c,e,b,d,h,ab,-100,100,l);for(h=e=0;h!==l.length;h++){n=this.createContactEquation(f,m,a,b,q,k);var p=n.ri,t=n.rj;ab.negate(n.ni);l[h].normal.negate(Ta);Ta.mult(l[h].depth,Ta);l[h].point.vadd(Ta,p);t.copy(l[h].point);p.vsub(c,p);t.vsub(d,t);p.vadd(c,p);p.vsub(f.position,p);t.vadd(d,t);t.vsub(m.position,t);this.result.push(n);
e++;this.enableFrictionReduction||this.createFrictionEquationsFromContact(n,this.frictionResult)}this.enableFrictionReduction&&e&&this.createFrictionFromAverage(e)}};var Fa=new d,eb=new d,ea=new d;a.prototype[f.types.PLANE|f.types.PARTICLE]=a.prototype.planeParticle=function(a,b,c,d,e,h,f,m){Fa.set(0,0,1);f.quaternion.vmult(Fa,Fa);d.vsub(f.position,eb);0>=Fa.dot(eb)&&(a=this.createContactEquation(m,f,b,a),a.ni.copy(Fa),a.ni.negate(a.ni),a.ri.set(0,0,0),Fa.mult(Fa.dot(d),ea),d.vsub(ea,ea),a.rj.copy(ea),
this.result.push(a),this.createFrictionEquationsFromContact(a,this.frictionResult))};var Ba=new d;a.prototype[f.types.PARTICLE|f.types.SPHERE]=a.prototype.sphereParticle=function(a,b,c,d,e,h,f,m){Ba.set(0,0,1);d.vsub(c,Ba);Ba.norm2()<=a.radius*a.radius&&(b=this.createContactEquation(m,f,b,a),Ba.normalize(),b.rj.copy(Ba),b.rj.mult(a.radius,b.rj),b.ni.copy(Ba),b.ni.negate(b.ni),b.ri.set(0,0,0),this.result.push(b),this.createFrictionEquationsFromContact(b,this.frictionResult))};var Ua=new n,qa=new d;
new d;var Ia=new d,Ma=new d,Ca=new d;a.prototype[f.types.PARTICLE|f.types.CONVEXPOLYHEDRON]=a.prototype.convexParticle=function(a,b,c,d,e,h,f,m){var q=-1;h=null;var k=0;qa.copy(d);qa.vsub(c,qa);e.conjugate(Ua);Ua.vmult(qa,qa);if(a.pointIsInside(qa)){a.worldVerticesNeedsUpdate&&a.computeWorldVertices(c,e);a.worldFaceNormalsNeedsUpdate&&a.computeWorldFaceNormals(e);e=0;for(var l=a.faces.length;e!==l;e++){var n=a.worldFaceNormals[e];d.vsub(a.worldVertices[a.faces[e][0]],Ma);var p=-n.dot(Ma);if(null===
h||Math.abs(p)<Math.abs(h))h=p,q=e,Ia.copy(n),k++}-1!==q?(a=this.createContactEquation(m,f,b,a),Ia.mult(h,Ca),Ca.vadd(d,Ca),Ca.vsub(c,Ca),a.rj.copy(Ca),Ia.negate(a.ni),a.ri.set(0,0,0),b=a.ri,h=a.rj,b.vadd(d,b),b.vsub(m.position,b),h.vadd(c,h),h.vsub(f.position,h),this.result.push(a),this.createFrictionEquationsFromContact(a,this.frictionResult)):console.warn("Point found inside convex, but did not find penetrating face!")}};a.prototype[f.types.BOX|f.types.HEIGHTFIELD]=a.prototype.boxHeightfield=function(a,
b,c,d,e,h,f,m){a.convexPolyhedronRepresentation.material=a.material;a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse;this.convexHeightfield(a.convexPolyhedronRepresentation,b,c,d,e,h,f,m)};var Da=new d,za=new d,Va=[0];a.prototype[f.types.CONVEXPOLYHEDRON|f.types.HEIGHTFIELD]=a.prototype.convexHeightfield=function(a,b,c,d,e,h,f,m){var q=b.data,k=b.elementSize,n=a.boundingSphereRadius;l.pointToLocalFrame(d,h,c,Da);var p=Math.floor((Da.x-n)/k)-1,t=Math.ceil((Da.x+n)/k)+1,r=Math.floor((Da.y-
n)/k)-1;k=Math.ceil((Da.y+n)/k)+1;if(!(0>t||0>k||p>q.length||r>q[0].length)){0>p&&(p=0);0>t&&(t=0);0>r&&(r=0);0>k&&(k=0);p>=q.length&&(p=q.length-1);t>=q.length&&(t=q.length-1);k>=q[0].length&&(k=q[0].length-1);r>=q[0].length&&(r=q[0].length-1);q=[];b.getRectMinMax(p,r,t,k,q);var y=q[0];if(!(Da.z-n>q[1]||Da.z+n<y))for(n=p;n<t;n++)for(p=r;p<k;p++)b.getConvexTrianglePillar(n,p,!1),l.pointToWorldFrame(d,h,b.pillarOffset,za),c.distanceTo(za)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&
this.convexConvex(a,b.pillarConvex,c,za,e,h,f,m,null,null,Va,null),b.getConvexTrianglePillar(n,p,!0),l.pointToWorldFrame(d,h,b.pillarOffset,za),c.distanceTo(za)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&this.convexConvex(a,b.pillarConvex,c,za,e,h,f,m,null,null,Va,null)}};var Ea=new d,wa=new d;a.prototype[f.types.SPHERE|f.types.HEIGHTFIELD]=a.prototype.sphereHeightfield=function(a,b,c,d,e,h,f,m){var q=b.data,k=a.radius,n=b.elementSize;l.pointToLocalFrame(d,h,c,Ea);var p=Math.floor((Ea.x-
k)/n)-1,t=Math.ceil((Ea.x+k)/n)+1,r=Math.floor((Ea.y-k)/n)-1;n=Math.ceil((Ea.y+k)/n)+1;if(!(0>t||0>n||p>q.length||n>q[0].length)){0>p&&(p=0);0>t&&(t=0);0>r&&(r=0);0>n&&(n=0);p>=q.length&&(p=q.length-1);t>=q.length&&(t=q.length-1);n>=q[0].length&&(n=q[0].length-1);r>=q[0].length&&(r=q[0].length-1);q=[];b.getRectMinMax(p,r,t,n,q);var y=q[0];if(!(Ea.z-k>q[1]||Ea.z+k<y))for(k=this.result;p<t;p++)for(q=r;q<n;q++)if(y=k.length,b.getConvexTrianglePillar(p,q,!1),l.pointToWorldFrame(d,h,b.pillarOffset,wa),
c.distanceTo(wa)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&this.sphereConvex(a,b.pillarConvex,c,wa,e,h,f,m),b.getConvexTrianglePillar(p,q,!0),l.pointToWorldFrame(d,h,b.pillarOffset,wa),c.distanceTo(wa)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&this.sphereConvex(a,b.pillarConvex,c,wa,e,h,f,m),2<k.length-y)return}}},{"../collision/AABB":3,"../collision/Ray":9,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../math/Quaternion":28,"../math/Transform":29,
"../math/Vec3":30,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43,"../solver/Solver":47,"../utils/Vec3Pool":54}],56:[function(b,c,f){function a(){n.apply(this);this.dt=-1;this.allowSleep=!1;this.contacts=[];this.frictionEquations=[];this.quatNormalizeSkip=0;this.quatNormalizeFast=!1;this.stepnumber=this.time=0;this.default_dt=1/60;this.nextId=0;this.gravity=new e;this.broadphase=new u;this.bodies=[];this.solver=new d;this.constraints=[];this.narrowphase=new l(this);this.collisionMatrix=new k;
this.collisionMatrixPrevious=new k;this.materials=[];this.contactmaterials=[];this.contactMaterialTable=new m;this.defaultMaterial=new p("default");this.defaultContactMaterial=new r(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0});this.doProfiling=!1;this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0};this.subsystems=[];this.addBodyEvent={type:"addBody",body:null};this.removeBodyEvent={type:"removeBody",body:null}}c.exports=a;b("../shapes/Shape");
var e=b("../math/Vec3");c=b("../math/Quaternion");var d=b("../solver/GSSolver");b("../utils/Vec3Pool");b("../equations/ContactEquation");b("../equations/FrictionEquation");var l=b("./Narrowphase"),n=b("../utils/EventTarget"),k=b("../collision/ArrayCollisionMatrix"),p=b("../material/Material"),r=b("../material/ContactMaterial"),h=b("../objects/Body"),m=b("../utils/TupleDictionary"),q=b("../collision/RaycastResult");f=b("../collision/AABB");var t=b("../collision/Ray"),u=b("../collision/NaiveBroadphase");
a.prototype=new n;new f;var w=new t;a.prototype.getContactMaterial=function(a,b){return this.contactMaterialTable.get(a.id,b.id)};a.prototype.numObjects=function(){return this.bodies.length};a.prototype.collisionMatrixTick=function(){var a=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix;this.collisionMatrix=a;this.collisionMatrix.reset()};a.prototype.add=a.prototype.addBody=function(a){-1===this.bodies.indexOf(a)&&(a.index=this.bodies.length,this.bodies.push(a),a.world=
this,a.initPosition.copy(a.position),a.initVelocity.copy(a.velocity),a.timeLastSleepy=this.time,a instanceof h&&(a.initAngularVelocity.copy(a.angularVelocity),a.initQuaternion.copy(a.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=a,this.dispatchEvent(this.addBodyEvent))};a.prototype.addConstraint=function(a){this.constraints.push(a)};a.prototype.removeConstraint=function(a){a=this.constraints.indexOf(a);-1!==a&&this.constraints.splice(a,1)};a.prototype.rayTest=
function(a,b,c){c instanceof q?this.raycastClosest(a,b,{skipBackfaces:!0},c):this.raycastAll(a,b,{skipBackfaces:!0},c)};a.prototype.raycastAll=function(a,b,c,d){c.mode=t.ALL;c.from=a;c.to=b;c.callback=d;return w.intersectWorld(this,c)};a.prototype.raycastAny=function(a,b,c,d){c.mode=t.ANY;c.from=a;c.to=b;c.result=d;return w.intersectWorld(this,c)};a.prototype.raycastClosest=function(a,b,c,d){c.mode=t.CLOSEST;c.from=a;c.to=b;c.result=d;return w.intersectWorld(this,c)};a.prototype.remove=function(a){a.world=
null;var b=this.bodies.length-1,c=this.bodies,d=c.indexOf(a);if(-1!==d){c.splice(d,1);for(d=0;d!==c.length;d++)c[d].index=d;this.collisionMatrix.setNumObjects(b);this.removeBodyEvent.body=a;this.dispatchEvent(this.removeBodyEvent)}};a.prototype.removeBody=a.prototype.remove;a.prototype.addMaterial=function(a){this.materials.push(a)};a.prototype.addContactMaterial=function(a){this.contactmaterials.push(a);this.contactMaterialTable.set(a.materials[0].id,a.materials[1].id,a)};"undefined"===typeof performance&&
(performance={});if(!performance.now){var v=Date.now();performance.timing&&performance.timing.navigationStart&&(v=performance.timing.navigationStart);performance.now=function(){return Date.now()-v}}var z=new e;a.prototype.step=function(a,b,c){c=c||10;b=b||0;if(0===b)this.internalStep(a),this.time+=a;else{var d=Math.floor((this.time+b)/a)-Math.floor(this.time/a);d=Math.min(d,c);c=performance.now();for(var e=0;e!==d&&!(this.internalStep(a),performance.now()-c>1E3*a);e++);this.time+=b;a=this.time%a/
a;b=this.bodies;for(d=0;d!==b.length;d++)c=b[d],c.type!==h.STATIC&&c.sleepState!==h.SLEEPING?(c.position.vsub(c.previousPosition,z),z.scale(a,z),c.position.vadd(z,c.interpolatedPosition)):(c.interpolatedPosition.copy(c.position),c.interpolatedQuaternion.copy(c.quaternion))}};var C={type:"postStep"},x={type:"preStep"},D={type:"collide",body:null,contact:null},F=[],K=[],B=[],P=[];new e;new e;new e;new e;new e;new e;new e;new e;new e;new c;var Q=new c,H=new c,E=new e;a.prototype.internalStep=function(a){this.dt=
a;var b=this.contacts,c=this.numObjects(),d=this.bodies,e=this.solver,f=this.gravity,m=this.doProfiling,q=this.profile,k=h.DYNAMIC,l,n=this.constraints;f.norm();var p=f.x,t=f.y,r=f.z;m&&(l=performance.now());for(f=0;f!==c;f++){var u=d[f];if(u.type&k){var v=u.force;u=u.mass;v.x+=u*p;v.y+=u*t;v.z+=u*r}}f=0;for(u=this.subsystems.length;f!==u;f++)this.subsystems[f].update();m&&(l=performance.now());B.length=0;P.length=0;this.broadphase.collisionPairs(this,B,P);m&&(q.broadphase=performance.now()-l);u=
n.length;for(f=0;f!==u;f++)if(p=n[f],!p.collideConnected)for(t=B.length-1;0<=t;--t)if(p.bodyA===B[t]&&p.bodyB===P[t]||p.bodyB===B[t]&&p.bodyA===P[t])B.splice(t,1),P.splice(t,1);this.collisionMatrixTick();m&&(l=performance.now());u=b.length;for(f=0;f!==u;f++)F.push(b[f]);b.length=0;u=this.frictionEquations.length;for(f=0;f!==u;f++)K.push(this.frictionEquations[f]);this.frictionEquations.length=0;this.narrowphase.getContacts(B,P,this,b,F,this.frictionEquations,K);m&&(q.narrowphase=performance.now()-
l);m&&(l=performance.now());for(f=0;f<this.frictionEquations.length;f++)e.addEquation(this.frictionEquations[f]);f=b.length;for(t=0;t!==f;t++)p=b[t],u=p.bi,r=p.bj,u.material&&r.material&&this.getContactMaterial(u.material,r.material),u.material&&r.material&&0<=u.material.restitution&&0<=r.material.restitution&&(p.restitution=u.material.restitution*r.material.restitution),e.addEquation(p),u.allowSleep&&u.type===h.DYNAMIC&&u.sleepState===h.SLEEPING&&r.sleepState===h.AWAKE&&r.type!==h.STATIC&&r.velocity.norm2()+
r.angularVelocity.norm2()>=2*Math.pow(r.sleepSpeedLimit,2)&&(u._wakeUpAfterNarrowphase=!0),r.allowSleep&&r.type===h.DYNAMIC&&r.sleepState===h.SLEEPING&&u.sleepState===h.AWAKE&&u.type!==h.STATIC&&u.velocity.norm2()+u.angularVelocity.norm2()>=2*Math.pow(u.sleepSpeedLimit,2)&&(r._wakeUpAfterNarrowphase=!0),this.collisionMatrix.set(u,r,!0),this.collisionMatrixPrevious.get(u,r)||(D.body=r,D.contact=p,u.dispatchEvent(D),D.body=u,r.dispatchEvent(D));m&&(q.makeContactConstraints=performance.now()-l,l=performance.now());
for(f=0;f!==c;f++)u=d[f],u._wakeUpAfterNarrowphase&&(u.wakeUp(),u._wakeUpAfterNarrowphase=!1);u=n.length;for(f=0;f!==u;f++)for(p=n[f],p.update(),t=0,b=p.equations.length;t!==b;t++)e.addEquation(p.equations[t]);e.solve(a,this);m&&(q.solve=performance.now()-l);e.removeAllEquations();e=Math.pow;for(f=0;f!==c;f++)if(u=d[f],u.type&k&&(n=e(1-u.linearDamping,a),b=u.velocity,b.mult(n,b),n=u.angularVelocity))b=e(1-u.angularDamping,a),n.mult(b,n);this.dispatchEvent(x);for(f=0;f!==c;f++)u=d[f],u.preStep&&u.preStep.call(u);
m&&(l=performance.now());k=h.DYNAMIC|h.KINEMATIC;e=0===this.stepnumber%(this.quatNormalizeSkip+1);n=this.quatNormalizeFast;b=.5*a;for(f=0;f!==c;f++)if(u=d[f],p=u.force,t=u.torque,u.type&k&&u.sleepState!==h.SLEEPING){r=u.velocity;v=u.angularVelocity;var w=u.position,z=u.quaternion,I=u.invMass,Y=u.invInertiaWorld;r.x+=p.x*I*a;r.y+=p.y*I*a;r.z+=p.z*I*a;u.angularVelocity&&(Y.vmult(t,E),E.mult(a,E),E.vadd(v,v));w.x+=r.x*a;w.y+=r.y*a;w.z+=r.z*a;u.angularVelocity&&(Q.set(v.x,v.y,v.z,0),Q.mult(z,H),z.x+=
b*H.x,z.y+=b*H.y,z.z+=b*H.z,z.w+=b*H.w,e&&(n?z.normalizeFast():z.normalize()));u.aabb&&(u.aabbNeedsUpdate=!0);u.updateInertiaWorld&&u.updateInertiaWorld()}this.clearForces();this.broadphase.dirty=!0;m&&(q.integrate=performance.now()-l);this.time+=a;this.stepnumber+=1;this.dispatchEvent(C);for(f=0;f!==c;f++)u=d[f],(a=u.postStep)&&a.call(u);if(this.allowSleep)for(f=0;f!==c;f++)d[f].sleepTick(this.time)};a.prototype.clearForces=function(){for(var a=this.bodies,b=a.length,c=0;c!==b;c++){var d=a[c];d.force.set(0,
0,0);d.torque.set(0,0,0)}}},{"../collision/AABB":3,"../collision/ArrayCollisionMatrix":4,"../collision/NaiveBroadphase":7,"../collision/Ray":9,"../collision/RaycastResult":10,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../material/ContactMaterial":24,"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Shape":43,"../solver/GSSolver":46,"../utils/EventTarget":49,"../utils/TupleDictionary":52,"../utils/Vec3Pool":54,"./Narrowphase":55}]},
{},[2])(2)});CANNON=CANNON||{};var camera,scene,s_oRayCasterMesh;
CANNON.Demo=function(g){function b(){if(z){for(var a in z.__controllers)z.__controllers[a].updateDisplay();for(var b in z.__folders)for(a in z.__folders[b].__controllers)z.__folders[b].__controllers[a].updateDisplay()}}function c(a){function b(a,c){a.material&&(a.material=c);for(var d=0;d<a.children.length;d++)b(a.children[d],c)}if(-1===V.indexOf(a))throw Error("Render mode "+a+" not found!");switch(a){case "solid":h.currentMaterial=K;U.intensity=1;R.color.setHex(2236962);break;case "wireframe":h.currentMaterial=
B,U.intensity=0,R.color.setHex(16777215)}for(var c=0;c<w.length;c++)b(w[c],h.currentMaterial);q.rendermode=a}function f(){for(var a=u.length,b=0;b<a;b++){var c=u[b];c.position.copy(c.initPosition);c.velocity.copy(c.initVelocity);c.initAngularVelocity&&(c.angularVelocity.copy(c.initAngularVelocity),c.quaternion.copy(c.initQuaternion))}}function a(a){0===a.x&&(a.x=1E-6);0===a.y&&(a.y=1E-6);0===a.z&&(a.z=1E-6)}function e(){for(var b=u.length,c=0;c<b;c++){var d=u[c],e=w[c];e.position.copy(d.position);
d.quaternion&&e.quaternion.copy(d.quaternion)}Q.restart();if(q.contacts)for(c=0;c<J.contacts.length;c++)for(b=0;2>b;b++){e=Q.request();var h=J.contacts[c];d=0===b?h.bi:h.bj;var f=0===b?h.ri:h.rj;e.position.set(d.position.x+f.x,d.position.y+f.y,d.position.z+f.z)}Q.hideCached();H.restart();if(q.cm2contact)for(c=0;c<J.contacts.length;c++)for(b=0;2>b;b++)e=H.request(),h=J.contacts[c],d=0===b?h.bi:h.bj,f=0===b?h.ri:h.rj,e.scale.set(f.x,f.y,f.z),a(e.scale),e.position.copy(d.position);H.hideCached();N.restart();
L.restart();if(q.constraints){for(c=0;c<J.constraints.length;c++)h=J.constraints[c],h instanceof CANNON.DistanceConstraint&&(d=h.equations.normal,b=d.bi,d=d.bj,e=N.request(),d=d.position?d.position:d,e.scale.set(d.x-b.position.x,d.y-b.position.y,d.z-b.position.z),a(e.scale),e.position.copy(b.position));for(c=0;c<J.constraints.length;c++)if(h=J.constraints[c],h instanceof CANNON.PointToPointConstraint){f=h.equations.normal;b=f.bi;d=f.bj;e=L.request();h=L.request();var g=L.request();e.scale.set(f.ri.x,
f.ri.y,f.ri.z);h.scale.set(f.rj.x,f.rj.y,f.rj.z);g.scale.set(-f.penetrationVec.x,-f.penetrationVec.y,-f.penetrationVec.z);a(e.scale);a(h.scale);a(g.scale);e.position.copy(b.position);h.position.copy(d.position);f.bj.position.vadd(f.rj,g.position)}}L.hideCached();N.hideCached();W.restart();if(q.normals)for(c=0;c<J.contacts.length;c++)h=J.contacts[c],b=h.bi,e=W.request(),f=h.ni,d=b,e.scale.set(f.x,f.y,f.z),a(e.scale),e.position.copy(d.position),h.ri.vadd(e.position,e.position);W.hideCached();y.restart();
if(q.axes)for(b=0;b<u.length;b++)d=u[b],e=y.request(),e.position.copy(d.position),d.quaternion&&e.quaternion.copy(d.quaternion);y.hideCached();A.restart();if(q.aabbs)for(c=0;c<u.length;c++)d=u[c],d.computeAABB&&(d.aabbNeedsUpdate&&d.computeAABB(),isFinite(d.aabb.lowerBound.x)&&isFinite(d.aabb.lowerBound.y)&&isFinite(d.aabb.lowerBound.z)&&isFinite(d.aabb.upperBound.x)&&isFinite(d.aabb.upperBound.y)&&isFinite(d.aabb.upperBound.z)&&0!=d.aabb.lowerBound.x-d.aabb.upperBound.x&&0!=d.aabb.lowerBound.y-d.aabb.upperBound.y&&
0!=d.aabb.lowerBound.z-d.aabb.upperBound.z&&(e=A.request(),e.scale.set(d.aabb.lowerBound.x-d.aabb.upperBound.x,d.aabb.lowerBound.y-d.aabb.upperBound.y,d.aabb.lowerBound.z-d.aabb.upperBound.z),e.position.set(.5*(d.aabb.lowerBound.x+d.aabb.upperBound.x),.5*(d.aabb.lowerBound.y+d.aabb.upperBound.y),.5*(d.aabb.lowerBound.z+d.aabb.upperBound.z))));A.hideCached()}function d(){requestAnimationFrame(d);if(!q.paused){e();var a=1/q.stepFrequency,b=Date.now()/1E3;Y?J.step(a,b-Y,q.maxSubSteps):J.step(a);Y=b}CAMERA_TEST&&
S.update();Z.clear();Z.render(h.scene,camera);G.update()}function l(a){mouseX=a.clientX-ja;mouseY=a.clientY-ba}function n(a){T=s_iCanvasResizeWidth+2*s_iCanvasOffsetWidth;M=s_iCanvasResizeHeight+2*s_iCanvasOffsetHeight;CAMERA_TEST&&(S.screen.width=T,S.screen.height=M)}function k(a){h.dispatchEvent({type:"destroy"});q.paused=!1;b();p(a)}function p(a){for(var c=w.length,d=0;d<c;d++){J.remove(u.pop());var e=w.pop();h.scene.remove(e)}for(;J.constraints.length;)J.removeConstraint(J.constraints[0]);v[a]();
q.iterations=J.solver.iterations;q.gx=J.gravity.x+0;q.gy=J.gravity.y+0;q.gz=J.gravity.z+0;q.quatNormalizeSkip=J.quatNormalizeSkip;q.quatNormalizeFast=J.quatNormalizeFast;b();Q.restart();Q.hideCached();H.restart();H.hideCached();N.restart();N.hideCached();W.restart();W.hideCached()}function r(a){var b=[],c=[];this.request=function(){geo=b.length?b.pop():a();scene.add(geo);c.push(geo);return geo};this.restart=function(){for(;c.length;)b.push(c.pop())};this.hideCached=function(){for(var a=0;a<b.length;a++)scene.remove(b[a])}}
var h=this;this.addScene=function(a,b){if("string"!==typeof a)throw Error("1st argument of Demo.addScene(title,initfunc) must be a string!");if("function"!==typeof b)throw Error("2nd argument of Demo.addScene(title,initfunc) must be a function!");v.push(b);var c=v.length-1;D[a]=function(){k(c)};m.add(D,a)};this.restartCurrentScene=f;this.changeScene=k;this.start=function(){p(0)};var m,q=this.settings={stepFrequency:60,quatNormalizeSkip:2,quatNormalizeFast:!0,gx:0,gy:0,gz:0,iterations:3,tolerance:1E-4,
k:1E6,d:3,scene:0,paused:!1,rendermode:"solid",constraints:!1,contacts:!1,cm2contact:!1,normals:!1,axes:!1,particleSize:.1,shadows:!1,aabbs:!1,profiling:!1,maxSubSteps:3};g=g||{};for(var t in g)t in q&&(q[t]=g[t]);if(0!==q.stepFrequency%60)throw Error("stepFrequency must be a multiple of 60.");var u=this.bodies=[],w=this.visuals=[],v=[],z=null,C=null,x=null,D={},F=new THREE.SphereGeometry(.1,6,6);this.particleGeo=new THREE.SphereGeometry(1,16,8);var K=new THREE.MeshPhongMaterial({color:11184810,specular:1118481,
shininess:100}),B=new THREE.MeshLambertMaterial({color:16777215,wireframe:!0});this.currentMaterial=K;var P=new THREE.MeshPhongMaterial({color:16711680});this.particleMaterial=new THREE.MeshLambertMaterial({color:16711680});var Q=new r(function(){return new THREE.Mesh(F,P)}),H=new r(function(){var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(0,0,0));a.vertices.push(new THREE.Vector3(1,1,1));return new THREE.Line(a,new THREE.LineBasicMaterial({color:16711680}))}),E=new THREE.BoxGeometry(1,
1,1),I=new THREE.MeshBasicMaterial({color:11184810,wireframe:!0}),A=new r(function(){return new THREE.Mesh(E,I)}),N=new r(function(){var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(0,0,0));a.vertices.push(new THREE.Vector3(1,1,1));return new THREE.Line(a,new THREE.LineBasicMaterial({color:16711680}))}),L=new r(function(){var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(0,0,0));a.vertices.push(new THREE.Vector3(1,1,1));return new THREE.Line(a,new THREE.LineBasicMaterial({color:16711680}))}),
W=new r(function(){var a=new THREE.Geometry;a.vertices.push(new THREE.Vector3(0,0,0));a.vertices.push(new THREE.Vector3(1,1,1));return new THREE.Line(a,new THREE.LineBasicMaterial({color:65280}))}),y=new r(function(){var a=new THREE.Object3D,b=new THREE.Vector3(0,0,0),c=new THREE.Geometry,d=new THREE.Geometry,e=new THREE.Geometry;c.vertices.push(b);d.vertices.push(b);e.vertices.push(b);c.vertices.push(new THREE.Vector3(1,0,0));d.vertices.push(new THREE.Vector3(0,1,0));e.vertices.push(new THREE.Vector3(0,
0,1));b=new THREE.Line(c,new THREE.LineBasicMaterial({color:16711680}));d=new THREE.Line(d,new THREE.LineBasicMaterial({color:65280}));e=new THREE.Line(e,new THREE.LineBasicMaterial({color:255}));a.add(b);a.add(d);a.add(e);return a}),J=this.world=new CANNON.World;J.broadphase=new CANNON.NaiveBroadphase;var V=["solid","wireframe"],U,R,G,O;Detector.webgl||Detector.addGetWebGLMessage();var T=s_iCanvasResizeWidth+2*s_iCanvasOffsetWidth,M=s_iCanvasResizeHeight+2*s_iCanvasOffsetHeight,S,Z,X,ja=T/2,ba=M/
2;(function(){X=document.createElement("div");document.body.appendChild(X);CAMERA_TEST?(NEAR=5,camera=new THREE.PerspectiveCamera(45,T/M,NEAR,FAR),camera.lookAt(new THREE.Vector3(0,0,0)),camera.position.set(0,500,500),camera.up.set(0,0,1)):camera=createOrthoGraphicCamera();scene=h.scene=new THREE.Scene;scene.fog=new THREE.Fog(2236962,1E3,FAR);R=new THREE.AmbientLight(4473924);scene.add(R);U=new THREE.DirectionalLight(16777164,1);U.position.set(200,160,200);U.target.position.set(0,0,0);U.castShadow=
!0;U.shadow.camera.near=10;U.shadow.camera.far=100;U.shadow.camera.fov=30;U.shadowMapBias=.0139;U.shadowMapDarkness=.1;U.shadow.mapSize.width=1024;U.shadow.mapSize.height=1024;scene.add(U);scene.add(camera);var a=new THREE.PlaneBufferGeometry(500,500,50,50);s_oRayCasterMesh=new THREE.Mesh(a,new THREE.MeshLambertMaterial({color:16777215*Math.random()}));Z=SHOW_3D_RENDER?new THREE.WebGLRenderer({clearColor:0,clearAlpha:.5,antialias:!1,alpha:!0}):new THREE.CanvasRenderer({clearColor:0,clearAlpha:.5,
antialias:!1,alpha:!0});Z.setSize(T,M);Z.domElement.style.position="relative";Z.domElement.style.top="0px";Z.domElement.style.opacity=1;X.appendChild(Z.domElement);O=document.createElement("div");O.style.position="absolute";O.style.top="10px";O.style.width="100%";O.style.textAlign="center";O.innerHTML='<a href="http://github.com/schteppe/cannon.js">cannon.js</a> - javascript 3d physics';X.appendChild(O);document.addEventListener("mousemove",l);window.addEventListener("resize",n);Z.setClearColor(scene.fog.color,
1);Z.autoClear=!1;x=document.createElement("canvas");x.width=T;x.height=M;x.style.opacity=.5;x.style.position="absolute";x.style.top="0px";x.style.zIndex=90;X.appendChild(x);C=new SmoothieChart({labelOffsetY:50,maxDataSetLength:100,millisPerPixel:2,grid:{strokeStyle:"none",fillStyle:"none",lineWidth:1,millisPerLine:250,verticalSections:6},labels:{fillStyle:"rgb(180, 180, 180)"}});C.streamTo(x);var b={};a=[[255,0,0],[0,255,0],[0,0,255],[255,255,0],[255,0,255],[0,255,255]];var d=0;for(f in J.profile){var e=
a[d%a.length];b[f]=new TimeSeries({label:f,fillStyle:"rgb("+e[0]+","+e[1]+","+e[2]+")",maxDataLength:500});d++}J.addEventListener("postStep",function(a){for(var c in J.profile)b[c].append(1E3*J.time,J.profile[c])});d=0;for(f in J.profile)e=a[d%a.length],C.addTimeSeries(b[f],{strokeStyle:"rgb("+e[0]+","+e[1]+","+e[2]+")",lineWidth:2}),d++;J.doProfiling=!1;C.stop();x.style.display="none";G=new Stats;G.domElement.style.position="absolute";G.domElement.style.top="0px";G.domElement.style.zIndex=100;X.appendChild(G.domElement);
if(void 0!=window.dat){z=new dat.GUI;z.domElement.parentNode.style.zIndex=120;var f=z.addFolder("Rendering");f.add(q,"rendermode",{Solid:"solid",Wireframe:"wireframe"}).onChange(function(a){c(a)});f.add(q,"contacts");f.add(q,"cm2contact");f.add(q,"normals");f.add(q,"constraints");f.add(q,"axes");f.add(q,"particleSize").min(0).max(1).onChange(function(a){for(var b=0;b<w.length;b++)u[b]instanceof CANNON.Particle&&w[b].scale.set(a,a,a)});f.add(q,"shadows").onChange(function(a){a?Z.shadowMapAutoUpdate=
!0:(Z.shadowMapAutoUpdate=!1,Z.clearTarget(U.shadowMap))});f.add(q,"aabbs");f.add(q,"profiling").onChange(function(a){a?(J.doProfiling=!0,C.start(),x.style.display="block"):(J.doProfiling=!1,C.stop(),x.style.display="none")});f=z.addFolder("World");f.add(q,"paused").onChange(function(a){});f.add(q,"stepFrequency",60,600).step(60);f.add(q,"gx",-100,100).onChange(function(a){isNaN(a)||J.gravity.set(a,q.gy,q.gz)});f.add(q,"gy",-100,100).onChange(function(a){isNaN(a)||J.gravity.set(q.gx,a,q.gz)});f.add(q,
"gz",-100,100).onChange(function(a){isNaN(a)||J.gravity.set(q.gx,q.gy,a)});f.add(q,"quatNormalizeSkip",0,50).step(1).onChange(function(a){isNaN(a)||(J.quatNormalizeSkip=a)});f.add(q,"quatNormalizeFast").onChange(function(a){J.quatNormalizeFast=!!a});f=z.addFolder("Solver");f.add(q,"iterations",1,50).step(1).onChange(function(a){J.solver.iterations=a});f.add(q,"k",10,1E7).onChange(function(a){h.setGlobalSpookParams(q.k,q.d,1/q.stepFrequency)});f.add(q,"d",0,20).step(.1).onChange(function(a){h.setGlobalSpookParams(q.k,
q.d,1/q.stepFrequency)});f.add(q,"tolerance",0,10).step(.01).onChange(function(a){J.solver.tolerance=a});m=z.addFolder("Scenes");m.open()}CAMERA_TEST&&(S=new THREE.TrackballControls(camera,Z.domElement),S.rotateSpeed=1,S.zoomSpeed=1.2,S.panSpeed=.2,S.noZoom=!1,S.noPan=!1,S.staticMoving=!1,S.dynamicDampingFactor=.3,S.minDistance=0,S.maxDistance=1E5,S.screen.width=T,S.screen.height=M)})();d();var Y=0;document.addEventListener("keypress",function(a){if(a.keyCode)switch(a.keyCode){case 32:f();break;case 104:"none"==
G.domElement.style.display?(G.domElement.style.display="block",O.style.display="block"):(G.domElement.style.display="none",O.style.display="none");break;case 97:q.aabbs=!q.aabbs;b();break;case 99:q.constraints=!q.constraints;b();break;case 112:q.paused=!q.paused;b();break;case 115:J.step(1/q.stepFrequency);e();break;case 109:a=V.indexOf(q.rendermode);a++;a%=V.length;c(V[a]);b();break;case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:v.length>a.keyCode-49&&!document.activeElement.localName.match(/input/)&&
k(a.keyCode-49)}})};CANNON.Demo.prototype=new CANNON.EventTarget;CANNON.Demo.constructor=CANNON.Demo;
CANNON.Demo.prototype.setGlobalSpookParams=function(g,b,c){for(var f=this.world,a=0;a<f.constraints.length;a++)for(var e=f.constraints[a],d=0;d<e.equations.length;d++)e.equations[d].setSpookParams(g,b,c);for(a=0;a<f.contactmaterials.length;a++)c=f.contactmaterials[a],c.contactEquationStiffness=g,c.frictionEquationStiffness=g,c.contactEquationRelaxation=b,c.frictionEquationRelaxation=b;f.defaultContactMaterial.contactEquationStiffness=g;f.defaultContactMaterial.frictionEquationStiffness=g;f.defaultContactMaterial.contactEquationRelaxation=
b;f.defaultContactMaterial.frictionEquationRelaxation=b};CANNON.Demo.prototype.getWorld=function(){return this.world};CANNON.Demo.prototype.addVisual=function(g,b){var c;g instanceof CANNON.Body&&(c=this.shape2mesh(g,b));c&&(this.bodies.push(g),this.visuals.push(c),g.visualref=c,g.visualref.visualId=this.bodies.length-1,this.scene.add(c));return c};CANNON.Demo.prototype.addVisuals=function(g){for(var b=0;b<g.length;b++)this.addVisual(g[b])};
CANNON.Demo.prototype.removeVisual=function(g){if(g.visualref){for(var b=this.bodies,c=this.visuals,f=[],a=[],e=b.length,d=0;d<e;d++)f.unshift(b.pop()),a.unshift(c.pop());e=g.visualref.visualId;for(var l=0;l<f.length;l++)l!==e&&(d=l>e?l-1:l,b[d]=f[l],c[d]=a[l],b[d].visualref=f[l].visualref,b[d].visualref.visualId=d);g.visualref.visualId=null;this.scene.remove(g.visualref);g.visualref=null}};CANNON.Demo.prototype.removeAllVisuals=function(){for(;this.bodies.length;)this.removeVisual(this.bodies[0])};
CANNON.Demo.prototype.shape2mesh=function(g,b){for(var c=new THREE.Object3D,f=0;f<g.shapes.length;f++){var a=g.shapes[f];switch(a.type){case CANNON.Shape.types.SPHERE:var e=new THREE.SphereGeometry(a.radius,8,8);a=new THREE.Mesh(e,this.currentMaterial);break;case CANNON.Shape.types.PARTICLE:a=new THREE.Mesh(this.particleGeo,this.particleMaterial);e=this.settings;a.scale.set(e.particleSize,e.particleSize,e.particleSize);break;case CANNON.Shape.types.PLANE:var d=new THREE.PlaneGeometry(10,10,4,4);a=
new THREE.Object3D;e=new THREE.Object3D;d=new THREE.Mesh(d,this.currentMaterial);d.scale.set(100,100,100);e.add(d);d.castShadow=!0;d.receiveShadow=!0;a.add(e);break;case CANNON.Shape.types.BOX:e=new THREE.BoxGeometry(2*a.halfExtents.x,2*a.halfExtents.y,2*a.halfExtents.z);a=new THREE.Mesh(e,this.currentMaterial);break;case CANNON.Shape.types.CONVEXPOLYHEDRON:d=new THREE.Geometry;for(e=0;e<a.vertices.length;e++){var l=a.vertices[e];d.vertices.push(new THREE.Vector3(l.x,l.y,l.z))}for(e=0;e<a.faces.length;e++){var n=
a.faces[e],k=n[0];for(l=1;l<n.length-1;l++)d.faces.push(new THREE.Face3(k,n[l],n[l+1]))}d.computeBoundingSphere();d.computeFaceNormals();a=new THREE.Mesh(d,this.currentMaterial);break;case CANNON.Shape.types.HEIGHTFIELD:d=new THREE.Geometry;n=new CANNON.Vec3;k=new CANNON.Vec3;var p=new CANNON.Vec3;for(l=0;l<a.data.length-1;l++)for(var r=0;r<a.data[l].length-1;r++)for(var h=0;2>h;h++)a.getConvexTrianglePillar(l,r,0===h),n.copy(a.pillarConvex.vertices[0]),k.copy(a.pillarConvex.vertices[1]),p.copy(a.pillarConvex.vertices[2]),
n.vadd(a.pillarOffset,n),k.vadd(a.pillarOffset,k),p.vadd(a.pillarOffset,p),d.vertices.push(new THREE.Vector3(n.x,n.y,n.z),new THREE.Vector3(k.x,k.y,k.z),new THREE.Vector3(p.x,p.y,p.z)),e=d.vertices.length-3,d.faces.push(new THREE.Face3(e,e+1,e+2));d.computeBoundingSphere();d.computeFaceNormals();a=new THREE.Mesh(d,this.currentMaterial);break;case CANNON.Shape.types.TRIMESH:d=new THREE.Geometry;n=new CANNON.Vec3;k=new CANNON.Vec3;p=new CANNON.Vec3;for(e=0;e<a.indices.length/3;e++)a.getTriangleVertices(e,
n,k,p),d.vertices.push(new THREE.Vector3(n.x,n.y,n.z),new THREE.Vector3(k.x,k.y,k.z),new THREE.Vector3(p.x,p.y,p.z)),l=d.vertices.length-3,d.faces.push(new THREE.Face3(l,l+1,l+2));d.computeBoundingSphere();d.computeFaceNormals();e=11184810;b&&(e=b);e=new THREE.MeshPhongMaterial({color:e,specular:1118481,shininess:100});a=new THREE.Mesh(d,e);break;default:throw"Visual type not recognized: "+a.type;}a.receiveShadow=!0;a.castShadow=!0;if(a.children)for(e=0;e<a.children.length;e++)if(a.children[e].castShadow=
!0,a.children[e].receiveShadow=!0,a.children[e])for(l=0;l<a.children[e].length;l++)a.children[e].children[l].castShadow=!0,a.children[e].children[l].receiveShadow=!0;e=g.shapeOffsets[f];d=g.shapeOrientations[f];a.position.set(e.x,e.y,e.z);a.quaternion.set(d.x,d.y,d.z,d.w);c.add(a)}this.camera=function(){return camera};this.getScene=function(){return scene};return c};
function CLevelMenu(){var g,b,c,f,a,e,d,l,n=[],k,p,r,h,m,q=null,t=null,u,w;this._init=function(){d=0;p=createBitmap(s_oSpriteLibrary.getSprite("bg_menu"));s_oStage.addChild(p);u=new createjs.Shape;u.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);u.alpha=.7;s_oStage.addChild(u);l=new createjs.Container;l.x=0;l.y=0;var v=new createjs.Text(TEXT_SELECT_A_LEVEL," 46px "+PRIMARY_FONT,"#3e240b");v.x=CANVAS_WIDTH/2;v.y=200;v.outline=10;v.textAlign="center";v.textBaseline="alphabetic";
v.lineWidth=1E3;var w=new createjs.Text(TEXT_SELECT_A_LEVEL," 46px "+PRIMARY_FONT,"#ffd800");w.x=CANVAS_WIDTH/2;w.y=200;w.textAlign="center";w.textBaseline="alphabetic";w.lineWidth=1E3;l.addChild(v,w);s_oStage.addChild(l);v=.5*CANVAS_WIDTH-20;w=-200;var C=-100;k=s_oLocalStorage.getItemJson(LOCALSTORAGE_SCORE);for(var x=0;x<k.length;x++)0<k[x]&&d++;var D=0;for(x=0;x<k.length;x++)D+=k[x];x=new createjs.Text(TEXT_TOTAL_SCORE+": "+D," 40px "+PRIMARY_FONT,"#3e240b");x.x=CANVAS_WIDTH/2;x.y=800;x.outline=
10;x.textAlign="center";x.textBaseline="alphabetic";x.lineWidth=1E3;s_oStage.addChild(x);D=new createjs.Text(TEXT_TOTAL_SCORE+": "+D," 40px "+PRIMARY_FONT,"#ffd800");D.x=CANVAS_WIDTH/2;D.y=x.y;D.textAlign="center";D.textBaseline="alphabetic";D.lineWidth=1E3;s_oStage.addChild(D);for(x=0;x<k.length;x++,w+=170)700<w&&(w=-200,C+=150),x<=d?(n[x]=new CLevelBut(v-200+w,425+C,s_oSpriteLibrary.getSprite("but_level"),!0,x+1,s_oStage),n[x].addEventListenerWithParams(ON_MOUSE_UP,this._onClick,this,x),n[x].enable()):
(n[x]=new CLevelBut(v-200+w,425+C,s_oSpriteLibrary.getSprite("but_level"),!1,x+1,s_oStage),n[x].disable()),n[x].addLevelText(x+1),n[x].disable(),n[x].addStar(0),s_bFirstTime=!0;this._setLevelInfo();v=s_oSpriteLibrary.getSprite("but_exit");a=CANVAS_WIDTH-v.height/2-10;e=v.height/2+17;r=new CGfxButton(a,e,v,s_oStage);r.addEventListener(ON_MOUSE_UP,this._onExit,this);if(!1===DISABLE_SOUND_MOBILE||!1===s_bMobile)v=s_oSpriteLibrary.getSprite("audio_icon"),c=a-v.height-10,f=e,h=new CToggle(c,f,v,s_bAudioActive,
s_oStage),h.addEventListener(ON_MOUSE_UP,this._onAudioToggle,this);v=window.document;w=v.documentElement;q=w.requestFullscreen||w.mozRequestFullScreen||w.webkitRequestFullScreen||w.msRequestFullscreen;t=v.exitFullscreen||v.mozCancelFullScreen||v.webkitExitFullscreen||v.msExitFullscreen;!1===ENABLE_FULLSCREEN&&(q=!1);q&&screenfull.enabled&&(v=s_oSpriteLibrary.getSprite("but_fullscreen"),g=v.width/4+10,b=e,m=new CToggle(g,b,v,s_bFullscreen,s_oStage),m.addEventListener(ON_MOUSE_UP,this._onFullscreenRelease,
this));u=new createjs.Shape;u.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);s_oStage.addChild(u);(new createjs.Tween.get(u)).to({alpha:0},1E3);this.refreshButtonPos(s_iOffsetX,s_iOffsetY)};this.unload=function(){for(var a=0;a<NUM_HOLES;a++)n[a].unload();q&&screenfull.enabled&&m.unload();u.off("mousedown",w);s_oLevelMenu=null;s_oStage.removeAllChildren()};this.refreshButtonPos=function(d,k){!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||h.setPosition(c-d,f+k);q&&screenfull.enabled&&
m.setPosition(g+d,b+k);r.setPosition(a-d,e+k)};this._setLevelInfo=function(){d<NUM_HOLES&&(n[d].enable(),n[d].pulseAnimation());for(var a=0;a<d;a++)n[a].enable(),0<k[a]&&k[a]<PAR_POINTS-ADDED_POINTS?n[a].addStar(1):k[a]>=PAR_POINTS-ADDED_POINTS&&k[a]<PAR_POINTS?n[a].addStar(2):n[a].addStar(3),n[a].addScore(k[a])};this._onNumModeToggle=function(a){a===NUM_ACTIVE?((void 0).setActive(!1),(void 0).setActive(!0)):((void 0).setActive(!0),(void 0).setActive(!1))};this._onAudioToggle=function(){Howler.mute(s_bAudioActive);
s_bAudioActive=!s_bAudioActive};this._onClick=function(a){w=u.on("mousedown",function(){});createjs.Tween.get(u,{override:!0}).to({alpha:1},500).call(function(){s_oLevelMenu.unload();s_oMain.loadSelectedLevel(a)})};this._onExit=function(){s_oLevelMenu.unload();s_oMain.gotoMenu()};this.resetFullscreenBut=function(){m.setActive(s_bFullscreen)};this._onFullscreenRelease=function(){s_bFullscreen?t.call(window.document):q.call(window.document.documentElement);sizeHandler()};s_oLevelMenu=this;this._init()}
var s_oLevelMenu=null;
function CLevelBut(g,b,c,f,a,e){var d,l,n,k,p=[],r,h,m=null,q=null,t,u,w,v,z;this._init=function(a,b,c,e){d=!1;l=1;n=[];k=[];r=new createjs.Container;r.x=a;r.y=b;r.scaleX=r.scaleY=l;e.addChild(r);h=new createjs.Container;h.x=a;h.y=b;h.scaleX=r.scaleY=l;e.addChild(h);a=c.width/2;b=c.height;c=new createjs.SpriteSheet({images:[c],frames:{width:a,height:b,regX:a/2,regY:b/2},animations:{on:[0],off:[1]}});t=createSprite(c,"on",a/2,b/2,a,b);r.addChild(t);f?t.gotoAndStop("on"):t.gotoAndStop("off");this._initListener()};
this.unload=function(){s_bMobile?r.off("mousedown",w):(r.off("mousedown",w),r.off("mouseover",v));r.off("pressup",z);e.removeChild(r)};this.setVisible=function(a){r.visible=a};this.enable=function(){t.gotoAndStop("on");d=!1;null!==q&&(m.color="#3e240b",q.color="#ffd800")};this.disable=function(){d=!0;t.gotoAndStop("off");null!==q&&(m.color="#000000",q.color="#a8a8a8")};this.setClickable=function(a){d=!a};this.addStar=function(a){var b=s_oSpriteLibrary.getSprite("star");u=new CAchievementStars(b,0,
-b.height/2-14,r);u.getContainer().scaleX=u.getContainer().scaleY=.4;u.startLitStar(a)};this.addScore=function(a){var b=new createjs.Text(a," 12px "+PRIMARY_FONT,"#3e240b");b.y=c.height/2-10;b.textAlign="center";b.textBaseline="middle";b.lineWidth=200;b.outline=4;h.addChild(b);a=new createjs.Text(a," 12px "+PRIMARY_FONT,"#ffd800");a.y=b.y;a.textAlign="center";a.textBaseline="middle";a.lineWidth=200;h.addChild(a)};this.addLevelText=function(a){m=new createjs.Text(a," 30px "+PRIMARY_FONT,"#3e240b");
m.y=5;m.textAlign="center";m.textBaseline="middle";m.lineWidth=200;m.outline=8;r.addChild(m);q=new createjs.Text(a," 30px "+PRIMARY_FONT,"#ffd800");q.y=5;q.textAlign="center";q.textBaseline="middle";q.lineWidth=200;r.addChild(q)};this._initListener=function(){s_bMobile?w=r.on("mousedown",this.buttonDown):(w=r.on("mousedown",this.buttonDown),v=r.on("mouseover",this.buttonOver));z=r.on("pressup",this.buttonRelease)};this.addEventListener=function(a,b,c){n[a]=b;k[a]=c};this.addEventListenerWithParams=
function(a,b,c,d){n[a]=b;k[a]=c;p=d};this.buttonRelease=function(){d||(r.scaleX=l,r.scaleY=l,n[ON_MOUSE_UP]&&n[ON_MOUSE_UP].call(k[ON_MOUSE_UP],p))};this.buttonDown=function(){d||(playSound("click",1,!1),r.scaleX=.9*l,r.scaleY=.9*l,n[ON_MOUSE_DOWN]&&n[ON_MOUSE_DOWN].call(k[ON_MOUSE_DOWN],p))};this.buttonOver=function(a){s_bMobile||d||(a.target.cursor="pointer")};this.pulseAnimation=function(){createjs.Tween.get(r).to({scaleX:.9*l,scaleY:.9*l},850,createjs.Ease.quadOut).to({scaleX:l,scaleY:l},650,
createjs.Ease.quadIn).call(function(){C.pulseAnimation()})};this.trembleAnimation=function(){createjs.Tween.get(r).to({rotation:5},75,createjs.Ease.quadOut).to({rotation:-5},140,createjs.Ease.quadIn).to({rotation:0},75,createjs.Ease.quadIn).wait(750).call(function(){C.trebleAnimation()})};this.setPosition=function(a,b){r.x=a;r.y=b};this.setScale=function(a){l=a;r.scaleX=r.scaleY=a};this.setX=function(a){r.x=a};this.setY=function(a){r.y=a};this.getButtonImage=function(){return r};this.getX=function(){return r.x};
this.getY=function(){return r.y};var C=this;this._init(g,b,c,e);return this}
function CBall(g,b,c,f){var a,e,d,l,n,k,p,r,h,m,q,t,u,w,v,z,C,x,D,F,K,B,P,Q,H,E;this._init=function(a,b,c,d){n=!1;h=3;p=0;r=MAX_MOUSE_DISTANCE_POWER_ACTIVATED-MIN_MOUSE_DISTANCE_POWER_ACTIVATED;m=c.height;q=10;E=new CVector2(-.845,.534);t=new createjs.Container;t.x=a;t.y=b;d.addChild(t);a=s_oSpriteLibrary.getSprite("press_indicator");K=createBitmap(a);K.regX=.5*a.width;K.regY=.5*a.height;K.scaleX=0;K.scaleY=0;t.addChild(K);w=new createjs.Shape;t.addChild(w);z=new createjs.Container;z.visible=!1;z.y=
q;t.addChild(z);a=s_oSpriteLibrary.getSprite("ball_water");F=createBitmap(a);F.regX=.54*a.width;F.regY=.5*a.height;t.addChild(F);u=createBitmap(c);u.regX=.5*c.width;u.regY=.5*c.height;t.addChild(u);x=new createjs.Shape;x.graphics.beginFill("rgba(255,255,255,0.01)").r(0,0,c.width,c.height);x.x=-c.width/2;x.y=-c.height/2;x.scaleY=1;t.addChild(C);D=new createjs.Shape;D.graphics.beginFill("rgba(255,0,0,0.01)").drawCircle(0,0,c.width/2);t.addChild(D);u.mask=x;v=new createjs.Shape;v.graphics.beginFill("rgba(255,0,0,0.01)").drawCircle(0,
0,100);t.addChild(v);P=t.on("mousedown",this._onClickPoint);Q=t.on("pressmove",this._onDragPoint);H=t.on("pressup",this._onReleaseForce);c=s_oSpriteLibrary.getSprite("arrow");a=createBitmap(c);a.regY=c.height/2;a.rotation=147;z.addChild(a);C=new createjs.Shape;C.graphics.beginFill("rgba(255,255,255,0.01)").r(0,-c.height/2,c.width,c.height);C.scaleX=0;C.rotation=147;z.addChild(C);c=s_oSpriteLibrary.getSprite("arrow_fill");a=createBitmap(c);a.regY=c.height/2;a.mask=C;a.rotation=147;z.addChild(a);c=
s_oSpriteLibrary.getSprite("arrow_frame");a=createBitmap(c);a.regY=c.height/2;a.rotation=147;z.addChild(a);this.pressIndicatorAnim()};this._onClickPoint=function(a){};this._onDragPoint=function(b){if(!n){z.visible=!0;var c=s_oGame.get3DBall().position.x,f=s_oGame.get3DBall().position.y,h=s_oGame.get3DBall().position.z,g=new CVector2(b.localX,b.localY),m=Math.degrees(angleBetweenVectors(E,g));g=rotateVector2D(Math.radians(0<m&&66>=m?13*-m/33+150:0>m&&-114<=m?13*m/56+150:66<m?13*Math.abs(m)/57+2070/
19:13*-m/34+1380/17),g);c=convert3dPosTo2dScreen({x:c+g.x,y:f-g.y,z:h},s_oGame.getCamera());a=c.x;e=c.y;d=g.x;l=g.y;k=Math.sqrt(b.localX*b.localX+b.localY*b.localY);p=(k-(s_bMobile?MIN_MOUSE_DISTANCE_POWER_ACTIVATED_MOBILE:MIN_MOUSE_DISTANCE_POWER_ACTIVATED))/r*MAX_SHOT_POWER;I._drawLine(b.localX,b.localY);I._drawArrow()}};this._onReleaseForce=function(a){n||(z.visible=!1,w.graphics.clear(),0>=p||(p>MAX_SHOT_POWER&&(p=MAX_SHOT_POWER),a=new CVector2(d,l),a.normalize(),a.scalarProduct(p),s_oGame.launchBall({x:a.getX(),
y:-a.getY()}),I.setMoving(!0),I.pressIndicatorStop(),p=0,playSound("hit_ball",1,!1)))};this._drawLine=function(a,b){w.graphics.clear();w.graphics.setStrokeDash([14,14],2);w.graphics.setStrokeStyle(5);w.graphics.beginStroke("rgba(61,34,11,1)");w.graphics.moveTo(0,q);w.graphics.lineTo(a,b)};this._drawArrow=function(){var b=new CVector2(a-t.x,e-t.y);b=Math.degrees(angleBetweenVectors(E,b));z.rotation=b;C.scaleX=p/MAX_SHOT_POWER*.83+.17};this.unload=function(){t.removeAllEventListeners();f.removeChild(t);
t.off("mousedown",P);t.off("mousemove",Q);t.off("mouseup",H)};this.removeHelpAnim=function(){new createjs.Tween.removeTweens(B);new createjs.Tween.removeTweens(C)};this.setHelpAnim=function(){var a=s_oSpriteLibrary.getSprite("help_touch");B=createBitmap(a);B.regX=.33*a.width;B.regY=.1*a.height;t.addChild(B);this._helpCursorAnim(1E3);this._helpArrowAnim(1E3)};this._helpCursorAnim=function(a){createjs.Tween.get(B).to({x:-200,y:120},a,createjs.Ease.cubicInOut).call(function(){createjs.Tween.get(B).to({x:0,
y:0},a,createjs.Ease.cubicInOut).call(function(){I._helpCursorAnim(a)})})};this._helpArrowAnim=function(a){z.visible=!0;z.rotation=180;createjs.Tween.get(C).to({scaleX:1},a,createjs.Ease.cubicInOut).call(function(){createjs.Tween.get(C).to({scaleX:0},a,createjs.Ease.cubicInOut).call(function(){I._helpArrowAnim(a)})})};this.blink=function(){createjs.Tween.get(t).to({alpha:0},100-15*h).to({alpha:1},300-45*h).wait(100-20*h).call(function(){h--;0<h?I.blink():h=3})};this.pressIndicatorAnim=function(){K.scaleX=
K.scaleY=0;K.alpha=1;(new createjs.Tween.get(K)).to({scaleX:1,scaleY:1},1500,createjs.Ease.cubicOut).call(function(){I.pressIndicatorAnim()});(new createjs.Tween.get(K)).to({alpha:0},1500,createjs.Ease.cubicOut)};this.pressIndicatorStop=function(){K.scaleX=K.scaleY=0;new createjs.Tween.removeTweens(K)};this.setMoving=function(a){n=a};this.resetMask=function(){F.visible=!1;u.mask=x;x.scaleY=1};this.setWaterMask=function(a){F.visible=!0;F.alpha=a;u.mask=D;D.y=m*a-m};this.setHoleMask=function(a){F.visible=
!1;u.mask=D;D.y=m*a-m};this.setVisible=function(a){t.visible=a};this.setPosition=function(a,b){t.x=a;t.y=b};this.setAlpha=function(a){t.alpha=a};this.setAngle=function(a){t.rotation=a};this.getX=function(){return t.x};this.getY=function(){return t.y};this.scale=function(a){t.scaleX=a;t.scaleY=a};this.getScale=function(){return t.scaleX};this.childIndex=function(a){f.setChildIndex(t,a)};this._init(g,b,c,f);var I=this;return this}
function CScenario(g){var b,c,f,a,e,d,l,n,k,p,r,h,m,q,t,u,w,v,z;if(SHOW_3D_RENDER)var C=new CANNON.Demo;this.getDemo=function(){return C};this._init=function(){z=1/60;v=w=u=null;p=[];m=[];q=[];b=SHOW_3D_RENDER?C.getWorld():new CANNON.World;b.gravity.set(0,0,-98.1);b.broadphase=new CANNON.NaiveBroadphase;b.solver.iterations=10;new CANNON.Material;c=new CANNON.Material;f=new CANNON.Material;var a=new CANNON.ContactMaterial(c,f,{friction:0,restitution:.4,contactEquationStiffness:1E8,contactEquationRelaxation:3,
frictionEquationStiffness:1E8,frictionEquationRegularizationTime:3});b.addContactMaterial(a);r=[];h=[];a=new THREE.LoadingManager;a.onProgress=function(a,b,c){console.log(a,b,c)};(new THREE.FBXLoader(a)).load("models/level_"+g+".txt",function(a){s_oScenario.parseFile(a);s_oGame.scenarioLoaded()},function(a){},function(a){})};this.parseFile=function(a){for(var b=0;b<a.children.length;b++){var c=a.children[b];console.log("oMesh.name: "+c.name);"field"===c.name?s_oScenario._createFieldBody(c):"ball"===
c.name?s_oScenario._createBallBody(c):"hole"===c.name?s_oScenario._createHoleBody(c):"sand"===c.name?s_oScenario._createBigSandBody(c):"water"===c.name&&s_oScenario._createWaterBody(c)}};this._createFieldBody=function(a){n=this.__extractMeshData(a);k=new CANNON.Body({mass:0,material:f});k.addShape(n);a=new CANNON.Vec3(a.position.x,a.position.y,a.position.z);k.position.copy(a);k.addEventListener("collide",function(a){t=!0});b.addBody(k);SHOW_3D_RENDER&&C.addVisual(k)};this._createBallBody=function(f){a=
new CANNON.Sphere(BALL_RADIUS);e=new CANNON.Body({mass:BALL_MASS,material:c,linearDamping:BALL_LINEAR_DAMPING,angularDamping:BALL_LINEAR_DAMPING});f=new CANNON.Vec3(f.position.x,f.position.y,f.position.z);e.position.copy(f);e.previousPosition.copy(f);e.addShape(a);b.add(e);SHOW_3D_RENDER&&(d=C.addVisual(e))};this.testPosMesh=function(){return d};this._createHoleBody=function(a){l=new CANNON.Vec3(a.position.x,a.position.y,a.position.z);a=this.__extractMeshData(a);var c=q.length;q.push(new CANNON.Body({mass:0,
material:f}));q[c].collisionResponse=0;q[c].ID=c;q[c].addEventListener("collide",function(a){v=a.target.ID});q[c].addShape(a);q[c].position.copy(l);b.add(q[c]);SHOW_3D_RENDER&&C.addVisual(q[c],16711680)};this._createBigSandBody=function(a){var c=p.length;h[c]=new CANNON.Vec3(a.position.x,a.position.y,a.position.z);r[c]=this.__extractMeshData(a);p[c]=new CANNON.Body({mass:0,material:f});p[c].collisionResponse=0;p[c].ID=c;p[c].addEventListener("collide",function(a){u=a.target.ID});p[c].addShape(r[c]);
p[c].position.copy(h[c]);b.add(p[c]);SHOW_3D_RENDER&&C.addVisual(p[c],15636224)};this._createWaterBody=function(a){var c=new CANNON.Vec3(a.position.x,a.position.y,a.position.z);a=this.__extractMeshData(a);var d=m.length;m.push(new CANNON.Body({mass:0,material:f}));m[d].collisionResponse=0;m[d].ID=d;m[d].addEventListener("collide",function(a){w=a.target.ID});m[d].addShape(a);m[d].position.copy(c);b.add(m[d]);SHOW_3D_RENDER&&C.addVisual(m[d],255)};this.__extractMeshData=function(a){var b=a.geometry.faces;
a=a.geometry.vertices;for(var c=0;c<b.length;c++);var d=[],e=[];for(c=0;c<a.length;c++)d.push(1*a[c].x),d.push(1*a[c].y),d.push(1*a[c].z);for(c=0;c<b.length;c++)e.push(b[c].a),e.push(b[c].b),e.push(b[c].c);return new CANNON.Trimesh(d,e)};this.addImpulse=function(a,b){var c=new CANNON.Vec3(0,0,BALL_RADIUS),d=new CANNON.Vec3(b.x,b.y,0);a.applyImpulse(d,c)};this.getBodyVelocity=function(a){return a.velocity};this.ballBody=function(){return e};this.ballMesh=function(){return d};this.getCamera=function(){return C.camera()};
this.collisionWithBall=function(){s_oGame.ballCollision()};this.setElementVelocity=function(a,b){var c=new CANNON.Vec3(b.x,b.y,b.z);a.velocity=c};this.setElementLinearDamping=function(a,b){a.linearDamping=b};this.setGravity=function(a){b.gravity.set(0,0,a)};this.update=function(){b.step(z);t&&this._checkTerrainCollision();null!==u&&this._checkSandCollision();null!==w&&this._checkWaterCollision();null!==v&&this._checkHoleCollision()};this._checkTerrainCollision=function(){for(var a=0;a<b.contacts.length;a++){var c=
b.contacts[a];if(c.bi===k&&c.bj===e||c.bi===e&&c.bj===k)return s_oGame.ballCollideWithTerrain(!0),!0}s_oGame.ballCollideWithTerrain(!1);return t=!1};this._checkSandCollision=function(){for(var a=0;a<b.contacts.length;a++){var c=b.contacts[a];if(c.bi===p[u]&&c.bj===e||c.bi===e&&c.bj===p[u])return s_oGame.ballCollideWithSand(!0),!0}s_oGame.ballCollideWithSand(!1);u=null;return!1};this._checkWaterCollision=function(){for(var a=0;a<b.contacts.length;a++){var c=b.contacts[a];if(c.bi===m[w]&&c.bj===e||
c.bi===e&&c.bj===m[w])return s_oGame.ballCollideWithWater(!0),!0}s_oGame.ballCollideWithWater(!1);w=null;return!1};this._checkHoleCollision=function(){for(var a=0;a<b.contacts.length;a++){var c=b.contacts[a];if(c.bi===q[v]&&c.bj===e||c.bi===e&&c.bj===q[v])return s_oGame.ballCollideWithHole(!0),!0}s_oGame.ballCollideWithHole(!1);v=null;return!1};this.getHolePosition=function(){return l};this.getAllBigSandsPosition=function(){return h};this.getBigSandPositionByID=function(a){return h[a]};this.getWorld=
function(){return b};this.getField=function(){return k};s_oScenario=this;SHOW_3D_RENDER?(C.addScene("Test",this._init),C.start()):this._init()}var s_oScenario;
Detector={canvas:!!window.CanvasRenderingContext2D,webgl:function(){try{return!!window.WebGLRenderingContext&&!!document.createElement("canvas").getContext("experimental-webgl")}catch(g){return!1}}(),workers:!!window.Worker,fileapi:window.File&&window.FileReader&&window.FileList&&window.Blob,getWebGLErrorMessage:function(){var g=document.createElement("div");g.id="webgl-error-message";g.style.fontFamily="monospace";g.style.fontSize="13px";g.style.fontWeight="normal";g.style.textAlign="center";g.style.background=
"#fff";g.style.color="#000";g.style.padding="1.5em";g.style.width="400px";g.style.margin="5em auto 0";this.webgl||(g.innerHTML=window.WebGLRenderingContext?'Your graphics card does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">WebGL</a>.<br />\nFind out how to get it <a href="http://get.webgl.org/" style="color:#000">here</a>.':'Your browser does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">WebGL</a>.<br/>\nFind out how to get it <a href="http://get.webgl.org/" style="color:#000">here</a>.');
return g},addGetWebGLMessage:function(g){g=g||{};var b=void 0!==g.parent?g.parent:document.body;g=void 0!==g.id?g.id:"oldie";var c=Detector.getWebGLErrorMessage();c.id=g;b.appendChild(c)}};
function TimeSeries(g){g=g||{};g.resetBoundsInterval=g.resetBoundsInterval||3E3;g.resetBounds=void 0===g.resetBounds?!0:g.resetBounds;this.options=g;this.data=[];this.label=g.label||"";this.maxDataLength=g.maxDataLength||1E3;this.dataPool=[];this.minValue=this.maxValue=Number.NaN;g.resetBounds&&(this.boundsTimer=setInterval(function(b){return function(){b.resetBounds()}}(this),g.resetBoundsInterval))}
TimeSeries.prototype.resetBounds=function(){this.minValue=this.maxValue=Number.NaN;for(var g=0;g<this.data.length;g++)this.maxValue=isNaN(this.maxValue)?this.data[g][1]:Math.max(this.maxValue,this.data[g][1]),this.minValue=isNaN(this.minValue)?this.data[g][1]:Math.min(this.minValue,this.data[g][1])};
TimeSeries.prototype.append=function(g,b){this.lastTimeStamp=g;var c=this.dataPool.length?this.dataPool.pop():[g,b];c[0]=g;c[1]=b;this.data.push(c);this.maxValue=isNaN(this.maxValue)?b:Math.max(this.maxValue,b);for(this.minValue=isNaN(this.minValue)?b:Math.min(this.minValue,b);this.data.length>this.maxDataLength;)this.dataPool.push(this.data.shift())};
function SmoothieChart(g){g=g||{};g.grid=g.grid||{fillStyle:"#000000",strokeStyle:"#777777",lineWidth:1,millisPerLine:1E3,verticalSections:2};g.millisPerPixel=g.millisPerPixel||20;g.fps=g.fps||50;g.maxValueScale=g.maxValueScale||1;g.minValue=g.minValue;g.maxValue=g.maxValue;g.labels=g.labels||{fillStyle:"#ffffff"};g.interpolation=g.interpolation||"bezier";g.scaleSmoothing=g.scaleSmoothing||.125;g.maxDataSetLength=g.maxDataSetLength||2;g.timestampFormatter=g.timestampFormatter||null;this.options=g;
this.seriesSet=[];this.currentValueRange=1;this.currentVisMinValue=0}SmoothieChart.prototype.addTimeSeries=function(g,b){this.seriesSet.push({timeSeries:g,options:b||{}})};SmoothieChart.prototype.removeTimeSeries=function(g){this.seriesSet.splice(this.seriesSet.indexOf(g),1)};SmoothieChart.prototype.streamTo=function(g,b){var c=this;this.render_on_tick=function(){c.render(g,c.seriesSet[0].timeSeries.lastTimeStamp)};this.start()};
SmoothieChart.prototype.start=function(){this.timer||(this.timer=setInterval(this.render_on_tick,1E3/this.options.fps))};SmoothieChart.prototype.stop=function(){this.timer&&(clearInterval(this.timer),this.timer=void 0)};SmoothieChart.timeFormatter=function(g){function b(b){return(10>b?"0":"")+b}return b(g.getHours())+":"+b(g.getMinutes())+":"+b(g.getSeconds())};
SmoothieChart.prototype.render=function(g,b){var c=g.getContext("2d"),f=this.options,a=g.clientWidth,e=g.clientHeight;c.save();b-=b%f.millisPerPixel;c.translate(0,0);c.beginPath();c.rect(0,0,a,e);c.clip();c.save();c.fillStyle=f.grid.fillStyle;c.clearRect(0,0,a,e);c.fillRect(0,0,a,e);c.restore();c.save();c.lineWidth=f.grid.lineWidth||1;c.strokeStyle=f.grid.strokeStyle||"#ffffff";if(0<f.grid.millisPerLine)for(var d=b-b%f.grid.millisPerLine;d>=b-a*f.millisPerPixel;d-=f.grid.millisPerLine){c.beginPath();
var l=Math.round(a-(b-d)/f.millisPerPixel);c.moveTo(l,0);c.lineTo(l,e);c.stroke();if(f.timestampFormatter){var n=f.timestampFormatter(new Date(d)),k=c.measureText(n).width/2+c.measureText(v).width+4;l<a-k&&(c.fillStyle=f.labels.fillStyle,c.fillText(n,l-c.measureText(n).width/2,e-2))}c.closePath()}for(v=1;v<f.grid.verticalSections;v++)d=Math.round(v*e/f.grid.verticalSections),c.beginPath(),c.moveTo(0,d),c.lineTo(a,d),c.stroke(),c.closePath();c.beginPath();c.strokeRect(0,0,a,e);c.closePath();c.restore();
v=l=Number.NaN;for(n=0;n<this.seriesSet.length;n++){var p=this.seriesSet[n].timeSeries;isNaN(p.maxValue)||(l=isNaN(l)?p.maxValue:Math.max(l,p.maxValue));isNaN(p.minValue)||(v=isNaN(v)?p.minValue:Math.min(v,p.minValue))}if(!isNaN(l)||!isNaN(v)){l=null!=f.maxValue?f.maxValue:l*f.maxValueScale;null!=f.minValue&&(v=f.minValue);this.currentValueRange+=f.scaleSmoothing*(l-v-this.currentValueRange);this.currentVisMinValue+=f.scaleSmoothing*(v-this.currentVisMinValue);k=this.currentValueRange;var r=this.currentVisMinValue;
for(n=0;n<this.seriesSet.length;n++){c.save();p=this.seriesSet[n].timeSeries;p=p.data;for(var h=this.seriesSet[n].options;p.length>=f.maxDataSetLength&&p[1][0]<b-a*f.millisPerPixel;)p.splice(0,1);c.lineWidth=h.lineWidth||1;c.fillStyle=h.fillStyle;c.strokeStyle=h.strokeStyle||"#ffffff";c.beginPath();var m=0,q=0,t=0;for(d=0;d<p.length;d++){var u=Math.round(a-(b-p[d][0])/f.millisPerPixel),w=p[d][1]-r;w=Math.max(Math.min(e-(k?Math.round(w/k*e):0),e-1),1);if(0==d)m=u,c.moveTo(u,w);else switch(f.interpolation){case "line":c.lineTo(u,
w);break;default:c.bezierCurveTo(Math.round((q+u)/2),t,Math.round(q+u)/2,w,u,w)}q=u;t=w}0<p.length&&h.fillStyle&&(c.lineTo(a+h.lineWidth+1,t),c.lineTo(a+h.lineWidth+1,e+h.lineWidth+1),c.lineTo(m,e+h.lineWidth),c.fill());c.stroke();c.closePath();c.restore()}if(!f.labels.disabled){f.labelOffsetY||(f.labelOffsetY=0);c.fillStyle=f.labels.fillStyle;d=parseFloat(l).toFixed(2);var v=parseFloat(v).toFixed(2);c.fillText(d,a-c.measureText(d).width-2,10);c.fillText(v,a-c.measureText(v).width-2,e-2);for(d=0;d<
this.seriesSet.length;d++)p=this.seriesSet[d].timeSeries,a=p.label,c.fillStyle=p.options.fillStyle||"rgb(255,255,255)",a&&c.fillText(a,2,10*(d+1)+f.labelOffsetY)}}c.restore()};
var Stats=function(){var g=0,b=0,c=Date.now(),f=c,a=c,e=0,d=1E3,l=0,n=[[16,16,48],[0,255,255]],k=0,p=1E3,r=0,h=[[16,48,16],[0,255,0]];var m=document.createElement("div");m.style.cursor="pointer";m.style.width="80px";m.style.opacity="0.9";m.style.zIndex="10001";m.addEventListener("mousedown",function(a){a.preventDefault();g=(g+1)%2;0==g?(q.style.display="block",v.style.display="none"):(q.style.display="none",v.style.display="block")},!1);var q=document.createElement("div");q.style.textAlign="left";
q.style.lineHeight="1.2em";q.style.backgroundColor="rgb("+Math.floor(n[0][0]/2)+","+Math.floor(n[0][1]/2)+","+Math.floor(n[0][2]/2)+")";q.style.padding="0 0 3px 3px";m.appendChild(q);var t=document.createElement("div");t.style.fontFamily="Helvetica, Arial, sans-serif";t.style.fontSize="9px";t.style.color="rgb("+n[1][0]+","+n[1][1]+","+n[1][2]+")";t.style.fontWeight="bold";t.innerHTML="FPS";q.appendChild(t);var u=document.createElement("div");u.style.position="relative";u.style.width="74px";u.style.height=
"30px";u.style.backgroundColor="rgb("+n[1][0]+","+n[1][1]+","+n[1][2]+")";for(q.appendChild(u);74>u.children.length;){var w=document.createElement("span");w.style.width="1px";w.style.height="30px";w.style.cssFloat="left";w.style.backgroundColor="rgb("+n[0][0]+","+n[0][1]+","+n[0][2]+")";u.appendChild(w)}var v=document.createElement("div");v.style.textAlign="left";v.style.lineHeight="1.2em";v.style.backgroundColor="rgb("+Math.floor(h[0][0]/2)+","+Math.floor(h[0][1]/2)+","+Math.floor(h[0][2]/2)+")";
v.style.padding="0 0 3px 3px";v.style.display="none";m.appendChild(v);var z=document.createElement("div");z.style.fontFamily="Helvetica, Arial, sans-serif";z.style.fontSize="9px";z.style.color="rgb("+h[1][0]+","+h[1][1]+","+h[1][2]+")";z.style.fontWeight="bold";z.innerHTML="MS";v.appendChild(z);var C=document.createElement("div");C.style.position="relative";C.style.width="74px";C.style.height="30px";C.style.backgroundColor="rgb("+h[1][0]+","+h[1][1]+","+h[1][2]+")";for(v.appendChild(C);74>C.children.length;)w=
document.createElement("span"),w.style.width="1px",w.style.height=30*Math.random()+"px",w.style.cssFloat="left",w.style.backgroundColor="rgb("+h[0][0]+","+h[0][1]+","+h[0][2]+")",C.appendChild(w);return{domElement:m,update:function(){c=Date.now();k=c-f;p=Math.min(p,k);r=Math.max(r,k);z.textContent=k+" MS ("+p+"-"+r+")";var h=Math.min(30,30-k/200*30);C.appendChild(C.firstChild).style.height=h+"px";f=c;b++;c>a+1E3&&(e=Math.round(1E3*b/(c-a)),d=Math.min(d,e),l=Math.max(l,e),t.textContent=e+" FPS ("+
d+"-"+l+")",h=Math.min(30,30-e/100*30),u.appendChild(u.firstChild).style.height=h+"px",a=c,b=0)}}};
THREE.TrackballControls=function(g,b){function c(a){!1!==d.enabled&&(window.removeEventListener("keydown",c),p=k,k===l.NONE)&&(a.keyCode!==d.keys[l.ROTATE]||d.noRotate?a.keyCode!==d.keys[l.ZOOM]||d.noZoom?a.keyCode!==d.keys[l.PAN]||d.noPan||(k=l.PAN):k=l.ZOOM:k=l.ROTATE)}function f(a){!1!==d.enabled&&(a.preventDefault(),a.stopPropagation(),k!==l.ROTATE||d.noRotate?k!==l.ZOOM||d.noZoom?k!==l.PAN||d.noPan||z.copy(F(a.pageX,a.pageY)):t.copy(F(a.pageX,a.pageY)):m.copy(K(a.pageX,a.pageY)))}function a(b){!1!==
d.enabled&&(b.preventDefault(),b.stopPropagation(),k=l.NONE,document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",a),d.dispatchEvent(D))}function e(a){if(!1!==d.enabled){a.preventDefault();a.stopPropagation();var b=0;a.wheelDelta?b=a.wheelDelta/40:a.detail&&(b=-a.detail/3);q.y+=.01*b;d.dispatchEvent(x);d.dispatchEvent(D)}}var d=this,l={NONE:-1,ROTATE:0,ZOOM:1,PAN:2,TOUCH_ROTATE:3,TOUCH_ZOOM_PAN:4};this.object=g;this.domElement=void 0!==b?b:document;this.enabled=!0;this.screen=
{left:0,top:0,width:0,height:0};this.rotateSpeed=1;this.zoomSpeed=1.2;this.panSpeed=.3;this.staticMoving=this.noRoll=this.noPan=this.noZoom=this.noRotate=!1;this.dynamicDampingFactor=.2;this.minDistance=0;this.maxDistance=Infinity;this.keys=[65,83,68];this.target=new THREE.Vector3;var n=new THREE.Vector3,k=l.NONE,p=l.NONE,r=new THREE.Vector3,h=new THREE.Vector3,m=new THREE.Vector3,q=new THREE.Vector2,t=new THREE.Vector2,u=0,w=0,v=new THREE.Vector2,z=new THREE.Vector2;this.target0=this.target.clone();
this.position0=this.object.position.clone();this.up0=this.object.up.clone();var C={type:"change"},x={type:"start"},D={type:"end"};this.handleResize=function(){if(this.domElement===document)this.screen.left=0,this.screen.top=0,this.screen.width=window.innerWidth,this.screen.height=window.innerHeight;else{var a=this.domElement.getBoundingClientRect(),b=this.domElement.ownerDocument.documentElement;this.screen.left=a.left+window.pageXOffset-b.clientLeft;this.screen.top=a.top+window.pageYOffset-b.clientTop;
this.screen.width=a.width;this.screen.height=a.height}};this.handleEvent=function(a){if("function"==typeof this[a.type])this[a.type](a)};var F=function(){var a=new THREE.Vector2;return function(b,c){a.set((b-d.screen.left)/d.screen.width,(c-d.screen.top)/d.screen.height);return a}}(),K=function(){var a=new THREE.Vector3,b=new THREE.Vector3,c=new THREE.Vector3;return function(e,f){c.set((e-.5*d.screen.width-d.screen.left)/(.5*d.screen.width),(.5*d.screen.height+d.screen.top-f)/(.5*d.screen.height),
0);var h=c.length();d.noRoll?c.z=h<Math.SQRT1_2?Math.sqrt(1-h*h):.5/h:1<h?c.normalize():c.z=Math.sqrt(1-h*h);r.copy(d.object.position).sub(d.target);a.copy(d.object.up).setLength(c.y);a.add(b.copy(d.object.up).cross(r).setLength(c.x));a.add(r.setLength(c.z));return a}}();this.rotateCamera=function(){var a=new THREE.Vector3,b=new THREE.Quaternion;return function(){var c=Math.acos(h.dot(m)/h.length()/m.length());c&&(a.crossVectors(h,m).normalize(),c*=d.rotateSpeed,b.setFromAxisAngle(a,-c),r.applyQuaternion(b),
d.object.up.applyQuaternion(b),m.applyQuaternion(b),d.staticMoving?h.copy(m):(b.setFromAxisAngle(a,c*(d.dynamicDampingFactor-1)),h.applyQuaternion(b)))}}();this.zoomCamera=function(){if(k===l.TOUCH_ZOOM_PAN){var a=u/w;u=w;r.multiplyScalar(a)}else a=1+(t.y-q.y)*d.zoomSpeed,1!==a&&0<a&&(r.multiplyScalar(a),d.staticMoving?q.copy(t):q.y+=(t.y-q.y)*this.dynamicDampingFactor)};this.panCamera=function(){var a=new THREE.Vector2,b=new THREE.Vector3,c=new THREE.Vector3;return function(){a.copy(z).sub(v);a.lengthSq()&&
(a.multiplyScalar(r.length()*d.panSpeed),c.copy(r).cross(d.object.up).setLength(a.x),c.add(b.copy(d.object.up).setLength(a.y)),d.object.position.add(c),d.target.add(c),d.staticMoving?v.copy(z):v.add(a.subVectors(z,v).multiplyScalar(d.dynamicDampingFactor)))}}();this.checkDistances=function(){d.noZoom&&d.noPan||(r.lengthSq()>d.maxDistance*d.maxDistance&&d.object.position.addVectors(d.target,r.setLength(d.maxDistance)),r.lengthSq()<d.minDistance*d.minDistance&&d.object.position.addVectors(d.target,
r.setLength(d.minDistance)))};this.update=function(){r.subVectors(d.object.position,d.target);d.noRotate||d.rotateCamera();d.noZoom||d.zoomCamera();d.noPan||d.panCamera();d.object.position.addVectors(d.target,r);d.checkDistances();d.object.lookAt(d.target);1E-6<n.distanceToSquared(d.object.position)&&(d.dispatchEvent(C),n.copy(d.object.position))};this.reset=function(){p=k=l.NONE;d.target.copy(d.target0);d.object.position.copy(d.position0);d.object.up.copy(d.up0);r.subVectors(d.object.position,d.target);
d.object.lookAt(d.target);d.dispatchEvent(C);n.copy(d.object.position)};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},!1);this.domElement.addEventListener("mousedown",function(b){!1!==d.enabled&&(b.preventDefault(),b.stopPropagation(),k===l.NONE&&(k=b.button),k!==l.ROTATE||d.noRotate?k!==l.ZOOM||d.noZoom?k!==l.PAN||d.noPan||(v.copy(F(b.pageX,b.pageY)),z.copy(v)):(q.copy(F(b.pageX,b.pageY)),t.copy(q)):(h.copy(K(b.pageX,b.pageY)),m.copy(h)),document.addEventListener("mousemove",
f,!1),document.addEventListener("mouseup",a,!1),d.dispatchEvent(x))},!1);this.domElement.addEventListener("mousewheel",e,!1);this.domElement.addEventListener("DOMMouseScroll",e,!1);this.domElement.addEventListener("touchstart",function(a){if(!1!==d.enabled){switch(a.touches.length){case 1:k=l.TOUCH_ROTATE;h.copy(K(a.touches[0].pageX,a.touches[0].pageY));m.copy(h);break;case 2:k=l.TOUCH_ZOOM_PAN;var b=a.touches[0].pageX-a.touches[1].pageX,c=a.touches[0].pageY-a.touches[1].pageY;w=u=Math.sqrt(b*b+c*
c);v.copy(F((a.touches[0].pageX+a.touches[1].pageX)/2,(a.touches[0].pageY+a.touches[1].pageY)/2));z.copy(v);break;default:k=l.NONE}d.dispatchEvent(x)}},!1);this.domElement.addEventListener("touchend",function(a){if(!1!==d.enabled){switch(a.touches.length){case 1:m.copy(K(a.touches[0].pageX,a.touches[0].pageY));h.copy(m);break;case 2:u=w=0,z.copy(F((a.touches[0].pageX+a.touches[1].pageX)/2,(a.touches[0].pageY+a.touches[1].pageY)/2)),v.copy(z)}k=l.NONE;d.dispatchEvent(D)}},!1);this.domElement.addEventListener("touchmove",
function(a){if(!1!==d.enabled)switch(a.preventDefault(),a.stopPropagation(),a.touches.length){case 1:m.copy(K(a.touches[0].pageX,a.touches[0].pageY));break;case 2:var b=a.touches[0].pageX-a.touches[1].pageX,c=a.touches[0].pageY-a.touches[1].pageY;w=Math.sqrt(b*b+c*c);z.copy(F((a.touches[0].pageX+a.touches[1].pageX)/2,(a.touches[0].pageY+a.touches[1].pageY)/2));break;default:k=l.NONE}},!1);window.addEventListener("keydown",c,!1);window.addEventListener("keyup",function(a){!1!==d.enabled&&(k=p,window.addEventListener("keydown",
c,!1))},!1);this.handleResize();this.update()};THREE.TrackballControls.prototype=Object.create(THREE.EventDispatcher.prototype);var dat=dat||{};dat.gui=dat.gui||{};dat.utils=dat.utils||{};dat.controllers=dat.controllers||{};dat.dom=dat.dom||{};dat.color=dat.color||{};
dat.utils.css=function(){return{load:function(g,b){b=b||document;var c=b.createElement("link");c.type="text/css";c.rel="stylesheet";c.href=g;b.getElementsByTagName("head")[0].appendChild(c)},inject:function(g,b){b=b||document;var c=document.createElement("style");c.type="text/css";c.innerHTML=g;b.getElementsByTagName("head")[0].appendChild(c)}}}();
dat.utils.common=function(){var g=Array.prototype.forEach,b=Array.prototype.slice;return{BREAK:{},extend:function(c){this.each(b.call(arguments,1),function(b){for(var a in b)this.isUndefined(b[a])||(c[a]=b[a])},this);return c},defaults:function(c){this.each(b.call(arguments,1),function(b){for(var a in b)this.isUndefined(c[a])&&(c[a]=b[a])},this);return c},compose:function(){var c=b.call(arguments);return function(){for(var f=b.call(arguments),a=c.length-1;0<=a;a--)f=[c[a].apply(this,f)];return f[0]}},
each:function(b,f,a){if(g&&b.forEach===g)b.forEach(f,a);else if(b.length===b.length+0)for(var c=0,d=b.length;c<d&&!(c in b&&f.call(a,b[c],c)===this.BREAK);c++);else for(c in b)if(f.call(a,b[c],c)===this.BREAK)break},defer:function(b){setTimeout(b,0)},toArray:function(c){return c.toArray?c.toArray():b.call(c)},isUndefined:function(b){return void 0===b},isNull:function(b){return null===b},isNaN:function(b){return b!==b},isArray:Array.isArray||function(b){return b.constructor===Array},isObject:function(b){return b===
Object(b)},isNumber:function(b){return b===b+0},isString:function(b){return b===b+""},isBoolean:function(b){return!1===b||!0===b},isFunction:function(b){return"[object Function]"===Object.prototype.toString.call(b)}}}();
dat.controllers.Controller=function(g){var b=function(b,f){this.initialValue=b[f];this.domElement=document.createElement("div");this.object=b;this.property=f;this.__onFinishChange=this.__onChange=void 0};g.extend(b.prototype,{onChange:function(b){this.__onChange=b;return this},onFinishChange:function(b){this.__onFinishChange=b;return this},setValue:function(b){this.object[this.property]=b;this.__onChange&&this.__onChange.call(this,b);this.updateDisplay();return this},getValue:function(){return this.object[this.property]},
updateDisplay:function(){return this},isModified:function(){return this.initialValue!==this.getValue()}});return b}(dat.utils.common);
dat.dom.dom=function(g){function b(a){if("0"===a||g.isUndefined(a))return 0;a=a.match(f);return g.isNull(a)?0:parseFloat(a[1])}var c={};g.each({HTMLEvents:["change"],MouseEvents:["click","mousemove","mousedown","mouseup","mouseover"],KeyboardEvents:["keydown"]},function(a,b){g.each(a,function(a){c[a]=b})});var f=/(\d+(\.\d+)?)px/,a={makeSelectable:function(a,b){void 0!==a&&void 0!==a.style&&(a.onselectstart=b?function(){return!1}:function(){},a.style.MozUserSelect=b?"auto":"none",a.style.KhtmlUserSelect=
b?"auto":"none",a.unselectable=b?"on":"off")},makeFullscreen:function(a,b,c){g.isUndefined(b)&&(b=!0);g.isUndefined(c)&&(c=!0);a.style.position="absolute";b&&(a.style.left=0,a.style.right=0);c&&(a.style.top=0,a.style.bottom=0)},fakeEvent:function(a,b,f,n){f=f||{};var d=c[b];if(!d)throw Error("Event type "+b+" not supported.");var e=document.createEvent(d);switch(d){case "MouseEvents":e.initMouseEvent(b,f.bubbles||!1,f.cancelable||!0,window,f.clickCount||1,0,0,f.x||f.clientX||0,f.y||f.clientY||0,!1,
!1,!1,!1,0,null);break;case "KeyboardEvents":d=e.initKeyboardEvent||e.initKeyEvent;g.defaults(f,{cancelable:!0,ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1,keyCode:void 0,charCode:void 0});d(b,f.bubbles||!1,f.cancelable,window,f.ctrlKey,f.altKey,f.shiftKey,f.metaKey,f.keyCode,f.charCode);break;default:e.initEvent(b,f.bubbles||!1,f.cancelable||!0)}g.defaults(e,n);a.dispatchEvent(e)},bind:function(b,c,f,g){b.addEventListener?b.addEventListener(c,f,g||!1):b.attachEvent&&b.attachEvent("on"+c,f);return a},
unbind:function(b,c,f,g){b.removeEventListener?b.removeEventListener(c,f,g||!1):b.detachEvent&&b.detachEvent("on"+c,f);return a},addClass:function(b,c){if(void 0===b.className)b.className=c;else if(b.className!==c){var d=b.className.split(/ +/);-1==d.indexOf(c)&&(d.push(c),b.className=d.join(" ").replace(/^\s+/,"").replace(/\s+$/,""))}return a},removeClass:function(b,c){if(c){if(void 0!==b.className)if(b.className===c)b.removeAttribute("class");else{var d=b.className.split(/ +/),e=d.indexOf(c);-1!=
e&&(d.splice(e,1),b.className=d.join(" "))}}else b.className=void 0;return a},hasClass:function(a,b){return(new RegExp("(?:^|\\s+)"+b+"(?:\\s+|$)")).test(a.className)||!1},getWidth:function(a){a=getComputedStyle(a);return b(a["border-left-width"])+b(a["border-right-width"])+b(a["padding-left"])+b(a["padding-right"])+b(a.width)},getHeight:function(a){a=getComputedStyle(a);return b(a["border-top-width"])+b(a["border-bottom-width"])+b(a["padding-top"])+b(a["padding-bottom"])+b(a.height)},getOffset:function(a){var b=
{left:0,top:0};if(a.offsetParent){do b.left+=a.offsetLeft,b.top+=a.offsetTop;while(a=a.offsetParent)}return b},isActive:function(a){return a===document.activeElement&&(a.type||a.href)}};return a}(dat.utils.common);
dat.controllers.OptionController=function(g,b,c){var f=function(a,e,d){f.superclass.call(this,a,e);var g=this;this.__select=document.createElement("select");if(c.isArray(d)){var n={};c.each(d,function(a){n[a]=a});d=n}c.each(d,function(a,b){var c=document.createElement("option");c.innerHTML=b;c.setAttribute("value",a);g.__select.appendChild(c)});this.updateDisplay();b.bind(this.__select,"change",function(){g.setValue(this.options[this.selectedIndex].value)});this.domElement.appendChild(this.__select)};
f.superclass=g;c.extend(f.prototype,g.prototype,{setValue:function(a){a=f.superclass.prototype.setValue.call(this,a);this.__onFinishChange&&this.__onFinishChange.call(this,this.getValue());return a},updateDisplay:function(){this.__select.value=this.getValue();return f.superclass.prototype.updateDisplay.call(this)}});return f}(dat.controllers.Controller,dat.dom.dom,dat.utils.common);
dat.controllers.NumberController=function(g,b){var c=function(f,a,e){c.superclass.call(this,f,a);e=e||{};this.__min=e.min;this.__max=e.max;this.__step=e.step;b.isUndefined(this.__step)?this.__impliedStep=0==this.initialValue?1:Math.pow(10,Math.floor(Math.log(this.initialValue)/Math.LN10))/10:this.__impliedStep=this.__step;f=this.__impliedStep;f=f.toString();f=-1<f.indexOf(".")?f.length-f.indexOf(".")-1:0;this.__precision=f};c.superclass=g;b.extend(c.prototype,g.prototype,{setValue:function(b){void 0!==
this.__min&&b<this.__min?b=this.__min:void 0!==this.__max&&b>this.__max&&(b=this.__max);void 0!==this.__step&&0!=b%this.__step&&(b=Math.round(b/this.__step)*this.__step);return c.superclass.prototype.setValue.call(this,b)},min:function(b){this.__min=b;return this},max:function(b){this.__max=b;return this},step:function(b){this.__step=b;return this}});return c}(dat.controllers.Controller,dat.utils.common);
dat.controllers.NumberControllerBox=function(g,b,c){var f=function(a,e,d){function g(){var a=parseFloat(p.__input.value);c.isNaN(a)||p.setValue(a)}function n(a){var b=r-a.clientY;p.setValue(p.getValue()+b*p.__impliedStep);r=a.clientY}function k(){b.unbind(window,"mousemove",n);b.unbind(window,"mouseup",k)}this.__truncationSuspended=!1;f.superclass.call(this,a,e,d);var p=this,r;this.__input=document.createElement("input");this.__input.setAttribute("type","text");b.bind(this.__input,"change",g);b.bind(this.__input,
"blur",function(){g();p.__onFinishChange&&p.__onFinishChange.call(p,p.getValue())});b.bind(this.__input,"mousedown",function(a){b.bind(window,"mousemove",n);b.bind(window,"mouseup",k);r=a.clientY});b.bind(this.__input,"keydown",function(a){13===a.keyCode&&(p.__truncationSuspended=!0,this.blur(),p.__truncationSuspended=!1)});this.updateDisplay();this.domElement.appendChild(this.__input)};f.superclass=g;c.extend(f.prototype,g.prototype,{updateDisplay:function(){var a=this.__input;if(this.__truncationSuspended)var b=
this.getValue();else{b=this.getValue();var c=Math.pow(10,this.__precision);b=Math.round(b*c)/c}a.value=b;return f.superclass.prototype.updateDisplay.call(this)}});return f}(dat.controllers.NumberController,dat.dom.dom,dat.utils.common);
dat.controllers.NumberControllerSlider=function(g,b,c,f,a){function e(a,b,c,d,e){return d+(a-b)/(c-b)*(e-d)}var d=function(a,c,f,g,r){function h(a){a.preventDefault();var c=b.getOffset(q.__background),d=b.getWidth(q.__background);q.setValue(e(a.clientX,c.left,c.left+d,q.__min,q.__max));return!1}function m(){b.unbind(window,"mousemove",h);b.unbind(window,"mouseup",m);q.__onFinishChange&&q.__onFinishChange.call(q,q.getValue())}d.superclass.call(this,a,c,{min:f,max:g,step:r});var q=this;this.__background=
document.createElement("div");this.__foreground=document.createElement("div");b.bind(this.__background,"mousedown",function(a){b.bind(window,"mousemove",h);b.bind(window,"mouseup",m);h(a)});b.addClass(this.__background,"slider");b.addClass(this.__foreground,"slider-fg");this.updateDisplay();this.__background.appendChild(this.__foreground);this.domElement.appendChild(this.__background)};d.superclass=g;d.useDefaultStyles=function(){c.inject(a)};f.extend(d.prototype,g.prototype,{updateDisplay:function(){var a=
(this.getValue()-this.__min)/(this.__max-this.__min);this.__foreground.style.width=100*a+"%";return d.superclass.prototype.updateDisplay.call(this)}});return d}(dat.controllers.NumberController,dat.dom.dom,dat.utils.css,dat.utils.common,".slider {\n  box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);\n  height: 1em;\n  border-radius: 1em;\n  background-color: #eee;\n  padding: 0 0.5em;\n  overflow: hidden;\n}\n\n.slider-fg {\n  padding: 1px 0 2px 0;\n  background-color: #aaa;\n  height: 1em;\n  margin-left: -0.5em;\n  padding-right: 0.5em;\n  border-radius: 1em 0 0 1em;\n}\n\n.slider-fg:after {\n  display: inline-block;\n  border-radius: 1em;\n  background-color: #fff;\n  border:  1px solid #aaa;\n  content: '';\n  float: right;\n  margin-right: -1em;\n  margin-top: -1px;\n  height: 0.9em;\n  width: 0.9em;\n}");
dat.controllers.FunctionController=function(g,b,c){var f=function(a,c,d){f.superclass.call(this,a,c);var e=this;this.__button=document.createElement("div");this.__button.innerHTML=void 0===d?"Fire":d;b.bind(this.__button,"click",function(a){a.preventDefault();e.fire();return!1});b.addClass(this.__button,"button");this.domElement.appendChild(this.__button)};f.superclass=g;c.extend(f.prototype,g.prototype,{fire:function(){this.__onChange&&this.__onChange.call(this);this.__onFinishChange&&this.__onFinishChange.call(this,
this.getValue());this.getValue().call(this.object)}});return f}(dat.controllers.Controller,dat.dom.dom,dat.utils.common);
dat.controllers.BooleanController=function(g,b,c){var f=function(a,c){f.superclass.call(this,a,c);var d=this;this.__prev=this.getValue();this.__checkbox=document.createElement("input");this.__checkbox.setAttribute("type","checkbox");b.bind(this.__checkbox,"change",function(){d.setValue(!d.__prev)},!1);this.domElement.appendChild(this.__checkbox);this.updateDisplay()};f.superclass=g;c.extend(f.prototype,g.prototype,{setValue:function(a){a=f.superclass.prototype.setValue.call(this,a);this.__onFinishChange&&
this.__onFinishChange.call(this,this.getValue());this.__prev=this.getValue();return a},updateDisplay:function(){!0===this.getValue()?(this.__checkbox.setAttribute("checked","checked"),this.__checkbox.checked=!0):this.__checkbox.checked=!1;return f.superclass.prototype.updateDisplay.call(this)}});return f}(dat.controllers.Controller,dat.dom.dom,dat.utils.common);
dat.color.toString=function(g){return function(b){if(1==b.a||g.isUndefined(b.a)){for(b=b.hex.toString(16);6>b.length;)b="0"+b;return"#"+b}return"rgba("+Math.round(b.r)+","+Math.round(b.g)+","+Math.round(b.b)+","+b.a+")"}}(dat.utils.common);
dat.color.interpret=function(g,b){var c,f,a=[{litmus:b.isString,conversions:{THREE_CHAR_HEX:{read:function(a){a=a.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i);return null===a?!1:{space:"HEX",hex:parseInt("0x"+a[1].toString()+a[1].toString()+a[2].toString()+a[2].toString()+a[3].toString()+a[3].toString())}},write:g},SIX_CHAR_HEX:{read:function(a){a=a.match(/^#([A-F0-9]{6})$/i);return null===a?!1:{space:"HEX",hex:parseInt("0x"+a[1].toString())}},write:g},CSS_RGB:{read:function(a){a=a.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);
return null===a?!1:{space:"RGB",r:parseFloat(a[1]),g:parseFloat(a[2]),b:parseFloat(a[3])}},write:g},CSS_RGBA:{read:function(a){a=a.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/);return null===a?!1:{space:"RGB",r:parseFloat(a[1]),g:parseFloat(a[2]),b:parseFloat(a[3]),a:parseFloat(a[4])}},write:g}}},{litmus:b.isNumber,conversions:{HEX:{read:function(a){return{space:"HEX",hex:a,conversionName:"HEX"}},write:function(a){return a.hex}}}},{litmus:b.isArray,conversions:{RGB_ARRAY:{read:function(a){return 3!=
a.length?!1:{space:"RGB",r:a[0],g:a[1],b:a[2]}},write:function(a){return[a.r,a.g,a.b]}},RGBA_ARRAY:{read:function(a){return 4!=a.length?!1:{space:"RGB",r:a[0],g:a[1],b:a[2],a:a[3]}},write:function(a){return[a.r,a.g,a.b,a.a]}}}},{litmus:b.isObject,conversions:{RGBA_OBJ:{read:function(a){return b.isNumber(a.r)&&b.isNumber(a.g)&&b.isNumber(a.b)&&b.isNumber(a.a)?{space:"RGB",r:a.r,g:a.g,b:a.b,a:a.a}:!1},write:function(a){return{r:a.r,g:a.g,b:a.b,a:a.a}}},RGB_OBJ:{read:function(a){return b.isNumber(a.r)&&
b.isNumber(a.g)&&b.isNumber(a.b)?{space:"RGB",r:a.r,g:a.g,b:a.b}:!1},write:function(a){return{r:a.r,g:a.g,b:a.b}}},HSVA_OBJ:{read:function(a){return b.isNumber(a.h)&&b.isNumber(a.s)&&b.isNumber(a.v)&&b.isNumber(a.a)?{space:"HSV",h:a.h,s:a.s,v:a.v,a:a.a}:!1},write:function(a){return{h:a.h,s:a.s,v:a.v,a:a.a}}},HSV_OBJ:{read:function(a){return b.isNumber(a.h)&&b.isNumber(a.s)&&b.isNumber(a.v)?{space:"HSV",h:a.h,s:a.s,v:a.v}:!1},write:function(a){return{h:a.h,s:a.s,v:a.v}}}}}];return function(){f=!1;
var e=1<arguments.length?b.toArray(arguments):arguments[0];b.each(a,function(a){if(a.litmus(e))return b.each(a.conversions,function(a,d){c=a.read(e);if(!1===f&&!1!==c)return f=c,c.conversionName=d,c.conversion=a,b.BREAK}),b.BREAK});return f}}(dat.color.toString,dat.utils.common);
dat.GUI=dat.gui.GUI=function(g,b,c,f,a,e,d,l,n,k,p,r,h,m,q){function t(b,c,d,e){if(void 0===c[d])throw Error("Object "+c+' has no property "'+d+'"');e.color?c=new p(c,d):(c=[c,d].concat(e.factoryArgs),c=f.apply(b,c));e.before instanceof a&&(e.before=e.before.__li);v(b,c);m.addClass(c.domElement,"c");d=document.createElement("span");m.addClass(d,"property-name");d.innerHTML=c.property;var h=document.createElement("div");h.appendChild(d);h.appendChild(c.domElement);e=u(b,h,e.before);m.addClass(e,N.CLASS_CONTROLLER_ROW);
m.addClass(e,typeof c.getValue());w(b,e,c);b.__controllers.push(c);return c}function u(a,b,c){var d=document.createElement("li");b&&d.appendChild(b);c?a.__ul.insertBefore(d,params.before):a.__ul.appendChild(d);a.onResize();return d}function w(a,b,c){c.__li=b;c.__gui=a;q.extend(c,{options:function(b){if(1<arguments.length)return c.remove(),t(a,c.object,c.property,{before:c.__li.nextElementSibling,factoryArgs:[q.toArray(arguments)]});if(q.isArray(b)||q.isObject(b))return c.remove(),t(a,c.object,c.property,
{before:c.__li.nextElementSibling,factoryArgs:[b]})},name:function(a){c.__li.firstElementChild.firstElementChild.innerHTML=a;return c},listen:function(){c.__gui.listen(c);return c},remove:function(){c.__gui.remove(c);return c}});if(c instanceof n){var f=new l(c.object,c.property,{min:c.__min,max:c.__max,step:c.__step});q.each(["updateDisplay","onChange","onFinishChange"],function(a){var b=c[a],d=f[a];c[a]=f[a]=function(){var a=Array.prototype.slice.call(arguments);b.apply(c,a);return d.apply(f,a)}});
m.addClass(b,"has-slider");c.domElement.insertBefore(f.domElement,c.domElement.firstElementChild)}else if(c instanceof l){var h=function(b){return q.isNumber(c.__min)&&q.isNumber(c.__max)?(c.remove(),t(a,c.object,c.property,{before:c.__li.nextElementSibling,factoryArgs:[c.__min,c.__max,c.__step]})):b};c.min=q.compose(h,c.min);c.max=q.compose(h,c.max)}else c instanceof e?(m.bind(b,"click",function(){m.fakeEvent(c.__checkbox,"click")}),m.bind(c.__checkbox,"click",function(a){a.stopPropagation()})):
c instanceof d?(m.bind(b,"click",function(){m.fakeEvent(c.__button,"click")}),m.bind(b,"mouseover",function(){m.addClass(c.__button,"hover")}),m.bind(b,"mouseout",function(){m.removeClass(c.__button,"hover")})):c instanceof p&&(m.addClass(b,"color"),c.updateDisplay=q.compose(function(a){b.style.borderLeftColor=c.__color.toString();return a},c.updateDisplay),c.updateDisplay());c.setValue=q.compose(function(b){a.getRoot().__preset_select&&c.isModified()&&K(a.getRoot(),!0);return b},c.setValue)}function v(a,
b){var c=a.getRoot(),d=c.__rememberedObjects.indexOf(b.object);if(-1!=d){var e=c.__rememberedObjectIndecesToControllers[d];void 0===e&&(e={},c.__rememberedObjectIndecesToControllers[d]=e);e[b.property]=b;if(c.load&&c.load.remembered){c=c.load.remembered;if(c[a.preset])c=c[a.preset];else if(c.Default)c=c.Default;else return;c[d]&&void 0!==c[d][b.property]&&(d=c[d][b.property],b.initialValue=d,b.setValue(d))}}}function z(a){var b=a.__save_row=document.createElement("li");m.addClass(a.domElement,"has-save");
a.__ul.insertBefore(b,a.__ul.firstChild);m.addClass(b,"save-row");var c=document.createElement("span");c.innerHTML="&nbsp;";m.addClass(c,"button gears");var d=document.createElement("span");d.innerHTML="Save";m.addClass(d,"button");m.addClass(d,"save");var e=document.createElement("span");e.innerHTML="New";m.addClass(e,"button");m.addClass(e,"save-as");var f=document.createElement("span");f.innerHTML="Revert";m.addClass(f,"button");m.addClass(f,"revert");var h=a.__preset_select=document.createElement("select");
a.load&&a.load.remembered?q.each(a.load.remembered,function(b,c){F(a,c,c==a.preset)}):F(a,"Default",!1);m.bind(h,"change",function(){for(var b=0;b<a.__preset_select.length;b++)a.__preset_select[b].innerHTML=a.__preset_select[b].value;a.preset=this.value});b.appendChild(h);b.appendChild(c);b.appendChild(d);b.appendChild(e);b.appendChild(f);if(P){var g=function(){k.style.display=a.useLocalStorage?"block":"none"};b=document.getElementById("dg-save-locally");var k=document.getElementById("dg-local-explain");
b.style.display="block";b=document.getElementById("dg-local-storage");"true"===localStorage.getItem(document.location.href+".isLocal")&&b.setAttribute("checked","checked");g();m.bind(b,"change",function(){a.useLocalStorage=!a.useLocalStorage;g()})}var l=document.getElementById("dg-new-constructor");m.bind(l,"keydown",function(a){!a.metaKey||67!==a.which&&67!=a.keyCode||Q.hide()});m.bind(c,"click",function(){l.innerHTML=JSON.stringify(a.getSaveObject(),void 0,2);Q.show();l.focus();l.select()});m.bind(d,
"click",function(){a.save()});m.bind(e,"click",function(){var b=prompt("Enter a new preset name.");b&&a.saveAs(b)});m.bind(f,"click",function(){a.revert()})}function C(a){function b(b){b.preventDefault();e=b.clientX;m.addClass(a.__closeButton,N.CLASS_DRAG);m.bind(window,"mousemove",c);m.bind(window,"mouseup",d);return!1}function c(b){b.preventDefault();a.width+=e-b.clientX;a.onResize();e=b.clientX;return!1}function d(){m.removeClass(a.__closeButton,N.CLASS_DRAG);m.unbind(window,"mousemove",c);m.unbind(window,
"mouseup",d)}a.__resize_handle=document.createElement("div");q.extend(a.__resize_handle.style,{width:"6px",marginLeft:"-3px",height:"200px",cursor:"ew-resize",position:"absolute"});var e;m.bind(a.__resize_handle,"mousedown",b);m.bind(a.__closeButton,"mousedown",b);a.domElement.insertBefore(a.__resize_handle,a.domElement.firstElementChild)}function x(a,b){a.domElement.style.width=b+"px";a.__save_row&&a.autoPlace&&(a.__save_row.style.width=b+"px");a.__closeButton&&(a.__closeButton.style.width=b+"px")}
function D(a,b){var c={};q.each(a.__rememberedObjects,function(d,e){var f={};q.each(a.__rememberedObjectIndecesToControllers[e],function(a,c){f[c]=b?a.initialValue:a.getValue()});c[e]=f});return c}function F(a,b,c){var d=document.createElement("option");d.innerHTML=b;d.value=b;a.__preset_select.appendChild(d);c&&(a.__preset_select.selectedIndex=a.__preset_select.length-1)}function K(a,b){var c=a.__preset_select[a.__preset_select.selectedIndex];c.innerHTML=b?c.value+"*":c.value}function B(a){0!=a.length&&
r(function(){B(a)});q.each(a,function(a){a.updateDisplay()})}g.inject(c);try{var P="localStorage"in window&&null!==window.localStorage}catch(L){P=!1}var Q,H=!0,E,I=!1,A=[],N=function(a){function b(){localStorage.setItem(document.location.href+".gui",JSON.stringify(d.getSaveObject()))}function c(){var a=d.getRoot();a.width+=1;q.defer(function(){--a.width})}var d=this;this.domElement=document.createElement("div");this.__ul=document.createElement("ul");this.domElement.appendChild(this.__ul);m.addClass(this.domElement,
"dg");this.__folders={};this.__controllers=[];this.__rememberedObjects=[];this.__rememberedObjectIndecesToControllers=[];this.__listening=[];a=a||{};a=q.defaults(a,{autoPlace:!0,width:N.DEFAULT_WIDTH});a=q.defaults(a,{resizable:a.autoPlace,hideable:a.autoPlace});q.isUndefined(a.load)?a.load={preset:"Default"}:a.preset&&(a.load.preset=a.preset);q.isUndefined(a.parent)&&a.hideable&&A.push(this);a.resizable=q.isUndefined(a.parent)&&a.resizable;a.autoPlace&&q.isUndefined(a.scrollable)&&(a.scrollable=
!0);var e=P&&"true"===localStorage.getItem(document.location.href+".isLocal");Object.defineProperties(this,{parent:{get:function(){return a.parent}},scrollable:{get:function(){return a.scrollable}},autoPlace:{get:function(){return a.autoPlace}},preset:{get:function(){return d.parent?d.getRoot().preset:a.load.preset},set:function(b){d.parent?d.getRoot().preset=b:a.load.preset=b;for(b=0;b<this.__preset_select.length;b++)this.__preset_select[b].value==this.preset&&(this.__preset_select.selectedIndex=
b);d.revert()}},width:{get:function(){return a.width},set:function(b){a.width=b;x(d,b)}},name:{get:function(){return a.name},set:function(b){a.name=b;h&&(h.innerHTML=a.name)}},closed:{get:function(){return a.closed},set:function(b){a.closed=b;a.closed?m.addClass(d.__ul,N.CLASS_CLOSED):m.removeClass(d.__ul,N.CLASS_CLOSED);this.onResize();d.__closeButton&&(d.__closeButton.innerHTML=b?N.TEXT_OPEN:N.TEXT_CLOSED)}},load:{get:function(){return a.load}},useLocalStorage:{get:function(){return e},set:function(a){P&&
((e=a)?m.bind(window,"unload",b):m.unbind(window,"unload",b),localStorage.setItem(document.location.href+".isLocal",a))}}});if(q.isUndefined(a.parent)){a.closed=!1;m.addClass(this.domElement,N.CLASS_MAIN);m.makeSelectable(this.domElement,!1);if(P&&e){d.useLocalStorage=!0;var f=localStorage.getItem(document.location.href+".gui");f&&(a.load=JSON.parse(f))}this.__closeButton=document.createElement("div");this.__closeButton.innerHTML=N.TEXT_CLOSED;m.addClass(this.__closeButton,N.CLASS_CLOSE_BUTTON);this.domElement.appendChild(this.__closeButton);
m.bind(this.__closeButton,"click",function(){d.closed=!d.closed})}else{void 0===a.closed&&(a.closed=!0);var h=document.createTextNode(a.name);m.addClass(h,"controller-name");f=u(d,h);m.addClass(this.__ul,N.CLASS_CLOSED);m.addClass(f,"title");m.bind(f,"click",function(a){a.preventDefault();d.closed=!d.closed;return!1});a.closed||(this.closed=!1)}a.autoPlace&&(q.isUndefined(a.parent)&&(H&&(E=document.createElement("div"),m.addClass(E,"dg"),m.addClass(E,N.CLASS_AUTO_PLACE_CONTAINER),document.body.appendChild(E),
H=!1),E.appendChild(this.domElement),m.addClass(this.domElement,N.CLASS_AUTO_PLACE)),this.parent||x(d,a.width));m.bind(window,"resize",function(){d.onResize()});m.bind(this.__ul,"webkitTransitionEnd",function(){d.onResize()});m.bind(this.__ul,"transitionend",function(){d.onResize()});m.bind(this.__ul,"oTransitionEnd",function(){d.onResize()});this.onResize();a.resizable&&C(this);d.getRoot();a.parent||c()};N.toggleHide=function(){I=!I;q.each(A,function(a){a.domElement.style.zIndex=I?-999:999;a.domElement.style.opacity=
I?0:1})};N.CLASS_AUTO_PLACE="a";N.CLASS_AUTO_PLACE_CONTAINER="ac";N.CLASS_MAIN="main";N.CLASS_CONTROLLER_ROW="cr";N.CLASS_TOO_TALL="taller-than-window";N.CLASS_CLOSED="closed";N.CLASS_CLOSE_BUTTON="close-button";N.CLASS_DRAG="drag";N.DEFAULT_WIDTH=245;N.TEXT_CLOSED="Close Controls";N.TEXT_OPEN="Open Controls";m.bind(window,"keydown",function(a){"text"===document.activeElement.type||72!==a.which&&72!=a.keyCode||N.toggleHide()},!1);q.extend(N.prototype,{add:function(a,b){return t(this,a,b,{factoryArgs:Array.prototype.slice.call(arguments,
2)})},addColor:function(a,b){return t(this,a,b,{color:!0})},remove:function(a){this.__ul.removeChild(a.__li);this.__controllers.slice(this.__controllers.indexOf(a),1);var b=this;q.defer(function(){b.onResize()})},destroy:function(){this.autoPlace&&E.removeChild(this.domElement)},addFolder:function(a){if(void 0!==this.__folders[a])throw Error('You already have a folder in this GUI by the name "'+a+'"');var b={name:a,parent:this};b.autoPlace=this.autoPlace;this.load&&this.load.folders&&this.load.folders[a]&&
(b.closed=this.load.folders[a].closed,b.load=this.load.folders[a]);b=new N(b);this.__folders[a]=b;a=u(this,b.domElement);m.addClass(a,"folder");return b},open:function(){this.closed=!1},close:function(){this.closed=!0},onResize:function(){var a=this.getRoot();if(a.scrollable){var b=m.getOffset(a.__ul).top,c=0;q.each(a.__ul.childNodes,function(b){a.autoPlace&&b===a.__save_row||(c+=m.getHeight(b))});window.innerHeight-b-20<c?(m.addClass(a.domElement,N.CLASS_TOO_TALL),a.__ul.style.height=window.innerHeight-
b-20+"px"):(m.removeClass(a.domElement,N.CLASS_TOO_TALL),a.__ul.style.height="auto")}a.__resize_handle&&q.defer(function(){a.__resize_handle.style.height=a.__ul.offsetHeight+"px"});a.__closeButton&&(a.__closeButton.style.width=a.width+"px")},remember:function(){q.isUndefined(Q)&&(Q=new h,Q.domElement.innerHTML=b);if(this.parent)throw Error("You can only call remember on a top level GUI.");var a=this;q.each(Array.prototype.slice.call(arguments),function(b){0==a.__rememberedObjects.length&&z(a);-1==
a.__rememberedObjects.indexOf(b)&&a.__rememberedObjects.push(b)});this.autoPlace&&x(this,this.width)},getRoot:function(){for(var a=this;a.parent;)a=a.parent;return a},getSaveObject:function(){var a=this.load;a.closed=this.closed;0<this.__rememberedObjects.length&&(a.preset=this.preset,a.remembered||(a.remembered={}),a.remembered[this.preset]=D(this));a.folders={};q.each(this.__folders,function(b,c){a.folders[c]=b.getSaveObject()});return a},save:function(){this.load.remembered||(this.load.remembered=
{});this.load.remembered[this.preset]=D(this);K(this,!1)},saveAs:function(a){this.load.remembered||(this.load.remembered={},this.load.remembered.Default=D(this,!0));this.load.remembered[a]=D(this);this.preset=a;F(this,a,!0)},revert:function(a){q.each(this.__controllers,function(b){this.getRoot().load.remembered?v(a||this.getRoot(),b):b.setValue(b.initialValue)},this);q.each(this.__folders,function(a){a.revert(a)});a||K(this.getRoot(),!1)},listen:function(a){var b=0==this.__listening.length;this.__listening.push(a);
b&&B(this.__listening)}});return N}(dat.utils.css,'<div id="dg-save" class="dg dialogue">\n\n  Here\'s the new load parameter for your <code>GUI</code>\'s constructor:\n\n  <textarea id="dg-new-constructor"></textarea>\n\n  <div id="dg-save-locally">\n\n    <input id="dg-local-storage" type="checkbox"/> Automatically save\n    values to <code>localStorage</code> on exit.\n\n    <div id="dg-local-explain">The values saved to <code>localStorage</code> will\n      override those passed to <code>dat.GUI</code>\'s constructor. This makes it\n      easier to work incrementally, but <code>localStorage</code> is fragile,\n      and your friends may not see the same values you do.\n      \n    </div>\n    \n  </div>\n\n</div>',
".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity 0.1s linear;-o-transition:opacity 0.1s linear;-moz-transition:opacity 0.1s linear;transition:opacity 0.1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity 0.1s linear;-o-transition:opacity 0.1s linear;-moz-transition:opacity 0.1s linear;transition:opacity 0.1s linear;border:0;position:absolute;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-x:hidden}.dg.a.has-save ul{margin-top:27px}.dg.a.has-save ul.closed{margin-top:0}.dg.a .save-row{position:fixed;top:0;z-index:1002}.dg li{-webkit-transition:height 0.1s ease-out;-o-transition:height 0.1s ease-out;-moz-transition:height 0.1s ease-out;transition:height 0.1s ease-out}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;overflow:hidden;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li > *{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:9px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2fa1d6}.dg .cr.number input[type=text]{color:#2fa1d6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2fa1d6}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n",
dat.controllers.factory=function(g,b,c,f,a,e,d){return function(l,n,k,p){var r=l[n];if(d.isArray(k)||d.isObject(k))return new g(l,n,k);if(d.isNumber(r))return d.isNumber(k)&&d.isNumber(p)?new c(l,n,k,p):new b(l,n,{min:k,max:p});if(d.isString(r))return new f(l,n);if(d.isFunction(r))return new a(l,n,"");if(d.isBoolean(r))return new e(l,n)}}(dat.controllers.OptionController,dat.controllers.NumberControllerBox,dat.controllers.NumberControllerSlider,dat.controllers.StringController=function(g,b,c){var f=
function(a,c){function d(){e.setValue(e.__input.value)}f.superclass.call(this,a,c);var e=this;this.__input=document.createElement("input");this.__input.setAttribute("type","text");b.bind(this.__input,"keyup",d);b.bind(this.__input,"change",d);b.bind(this.__input,"blur",function(){e.__onFinishChange&&e.__onFinishChange.call(e,e.getValue())});b.bind(this.__input,"keydown",function(a){13===a.keyCode&&this.blur()});this.updateDisplay();this.domElement.appendChild(this.__input)};f.superclass=g;c.extend(f.prototype,
g.prototype,{updateDisplay:function(){b.isActive(this.__input)||(this.__input.value=this.getValue());return f.superclass.prototype.updateDisplay.call(this)}});return f}(dat.controllers.Controller,dat.dom.dom,dat.utils.common),dat.controllers.FunctionController,dat.controllers.BooleanController,dat.utils.common),dat.controllers.Controller,dat.controllers.BooleanController,dat.controllers.FunctionController,dat.controllers.NumberControllerBox,dat.controllers.NumberControllerSlider,dat.controllers.OptionController,
dat.controllers.ColorController=function(g,b,c,f,a){function e(b,c,d,e){b.style.background="";a.each(n,function(a){b.style.cssText+="background: "+a+"linear-gradient("+c+", "+d+" 0%, "+e+" 100%); "})}function d(a){a.style.background="";a.style.cssText+="background: -moz-linear-gradient(top,  #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);";a.style.cssText+="background: -webkit-linear-gradient(top,  #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";
a.style.cssText+="background: -o-linear-gradient(top,  #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";a.style.cssText+="background: -ms-linear-gradient(top,  #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);";a.style.cssText+="background: linear-gradient(top,  #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);"}var l=function(g,p){function k(a){n(a);b.bind(window,"mousemove",n);b.bind(window,
"mouseup",h)}function h(){b.unbind(window,"mousemove",n);b.unbind(window,"mouseup",h)}function m(){var a=f(this.value);!1!==a?(w.__color.__state=a,w.setValue(w.__color.toOriginal())):this.value=w.__color.toString()}function q(){b.unbind(window,"mousemove",u);b.unbind(window,"mouseup",q)}function n(a){a.preventDefault();var c=b.getWidth(w.__saturation_field),d=b.getOffset(w.__saturation_field),e=(a.clientX-d.left+document.body.scrollLeft)/c;a=1-(a.clientY-d.top+document.body.scrollTop)/c;1<a?a=1:0>
a&&(a=0);1<e?e=1:0>e&&(e=0);w.__color.v=a;w.__color.s=e;w.setValue(w.__color.toOriginal());return!1}function u(a){a.preventDefault();var c=b.getHeight(w.__hue_field),d=b.getOffset(w.__hue_field);a=1-(a.clientY-d.top+document.body.scrollTop)/c;1<a?a=1:0>a&&(a=0);w.__color.h=360*a;w.setValue(w.__color.toOriginal());return!1}l.superclass.call(this,g,p);this.__color=new c(this.getValue());this.__temp=new c(0);var w=this;this.domElement=document.createElement("div");b.makeSelectable(this.domElement,!1);
this.__selector=document.createElement("div");this.__selector.className="selector";this.__saturation_field=document.createElement("div");this.__saturation_field.className="saturation-field";this.__field_knob=document.createElement("div");this.__field_knob.className="field-knob";this.__field_knob_border="2px solid ";this.__hue_knob=document.createElement("div");this.__hue_knob.className="hue-knob";this.__hue_field=document.createElement("div");this.__hue_field.className="hue-field";this.__input=document.createElement("input");
this.__input.type="text";this.__input_textShadow="0 1px 1px ";b.bind(this.__input,"keydown",function(a){13===a.keyCode&&m.call(this)});b.bind(this.__input,"blur",m);b.bind(this.__selector,"mousedown",function(a){b.addClass(this,"drag").bind(window,"mouseup",function(a){b.removeClass(w.__selector,"drag")})});var v=document.createElement("div");a.extend(this.__selector.style,{width:"122px",height:"102px",padding:"3px",backgroundColor:"#222",boxShadow:"0px 1px 3px rgba(0,0,0,0.3)"});a.extend(this.__field_knob.style,
{position:"absolute",width:"12px",height:"12px",border:this.__field_knob_border+(.5>this.__color.v?"#fff":"#000"),boxShadow:"0px 1px 3px rgba(0,0,0,0.5)",borderRadius:"12px",zIndex:1});a.extend(this.__hue_knob.style,{position:"absolute",width:"15px",height:"2px",borderRight:"4px solid #fff",zIndex:1});a.extend(this.__saturation_field.style,{width:"100px",height:"100px",border:"1px solid #555",marginRight:"3px",display:"inline-block",cursor:"pointer"});a.extend(v.style,{width:"100%",height:"100%",
background:"none"});e(v,"top","rgba(0,0,0,0)","#000");a.extend(this.__hue_field.style,{width:"15px",height:"100px",display:"inline-block",border:"1px solid #555",cursor:"ns-resize"});d(this.__hue_field);a.extend(this.__input.style,{outline:"none",textAlign:"center",color:"#fff",border:0,fontWeight:"bold",textShadow:this.__input_textShadow+"rgba(0,0,0,0.7)"});b.bind(this.__saturation_field,"mousedown",k);b.bind(this.__field_knob,"mousedown",k);b.bind(this.__hue_field,"mousedown",function(a){u(a);b.bind(window,
"mousemove",u);b.bind(window,"mouseup",q)});this.__saturation_field.appendChild(v);this.__selector.appendChild(this.__field_knob);this.__selector.appendChild(this.__saturation_field);this.__selector.appendChild(this.__hue_field);this.__hue_field.appendChild(this.__hue_knob);this.domElement.appendChild(this.__input);this.domElement.appendChild(this.__selector);this.updateDisplay()};l.superclass=g;a.extend(l.prototype,g.prototype,{updateDisplay:function(){var b=f(this.getValue());if(!1!==b){var d=!1;
a.each(c.COMPONENTS,function(c){if(!a.isUndefined(b[c])&&!a.isUndefined(this.__color.__state[c])&&b[c]!==this.__color.__state[c])return d=!0,{}},this);d&&a.extend(this.__color.__state,b)}a.extend(this.__temp.__state,this.__color.__state);this.__temp.a=1;var g=.5>this.__color.v||.5<this.__color.s?255:0,h=255-g;a.extend(this.__field_knob.style,{marginLeft:100*this.__color.s-7+"px",marginTop:100*(1-this.__color.v)-7+"px",backgroundColor:this.__temp.toString(),border:this.__field_knob_border+"rgb("+g+
","+g+","+g+")"});this.__hue_knob.style.marginTop=100*(1-this.__color.h/360)+"px";this.__temp.s=1;this.__temp.v=1;e(this.__saturation_field,"left","#fff",this.__temp.toString());a.extend(this.__input.style,{backgroundColor:this.__input.value=this.__color.toString(),color:"rgb("+g+","+g+","+g+")",textShadow:this.__input_textShadow+"rgba("+h+","+h+","+h+",.7)"})}});var n=["-moz-","-o-","-webkit-","-ms-",""];return l}(dat.controllers.Controller,dat.dom.dom,dat.color.Color=function(g,b,c,f){function a(a,
b,c){Object.defineProperty(a,b,{get:function(){if("RGB"===this.__state.space)return this.__state[b];d(this,b,c);return this.__state[b]},set:function(a){"RGB"!==this.__state.space&&(d(this,b,c),this.__state.space="RGB");this.__state[b]=a}})}function e(a,b){Object.defineProperty(a,b,{get:function(){if("HSV"===this.__state.space)return this.__state[b];l(this);return this.__state[b]},set:function(a){"HSV"!==this.__state.space&&(l(this),this.__state.space="HSV");this.__state[b]=a}})}function d(a,c,d){if("HEX"===
a.__state.space)a.__state[c]=b.component_from_hex(a.__state.hex,d);else if("HSV"===a.__state.space)f.extend(a.__state,b.hsv_to_rgb(a.__state.h,a.__state.s,a.__state.v));else throw"Corrupted color state";}function l(a){var c=b.rgb_to_hsv(a.r,a.g,a.b);f.extend(a.__state,{s:c.s,v:c.v});f.isNaN(c.h)?f.isUndefined(a.__state.h)&&(a.__state.h=0):a.__state.h=c.h}var n=function(){this.__state=g.apply(this,arguments);if(!1===this.__state)throw"Failed to interpret color arguments";this.__state.a=this.__state.a||
1};n.COMPONENTS="r g b h s v hex a".split(" ");f.extend(n.prototype,{toString:function(){return c(this)},toOriginal:function(){return this.__state.conversion.write(this)}});a(n.prototype,"r",2);a(n.prototype,"g",1);a(n.prototype,"b",0);e(n.prototype,"h");e(n.prototype,"s");e(n.prototype,"v");Object.defineProperty(n.prototype,"a",{get:function(){return this.__state.a},set:function(a){this.__state.a=a}});Object.defineProperty(n.prototype,"hex",{get:function(){this.__state.hex=b.rgb_to_hex(this.r,this.g,
this.b);return this.__state.hex},set:function(a){this.__state.space="HEX";this.__state.hex=a}});return n}(dat.color.interpret,dat.color.math=function(){var g;return{hsv_to_rgb:function(b,c,f){var a=b/60-Math.floor(b/60),e=f*(1-c),d=f*(1-a*c);c=f*(1-(1-a)*c);b=[[f,c,e],[d,f,e],[e,f,c],[e,d,f],[c,e,f],[f,e,d]][Math.floor(b/60)%6];return{r:255*b[0],g:255*b[1],b:255*b[2]}},rgb_to_hsv:function(b,c,f){var a=Math.max(b,c,f),e=a-Math.min(b,c,f);if(0==a)return{h:NaN,s:0,v:0};b=(b==a?(c-f)/e:c==a?2+(f-b)/e:
4+(b-c)/e)/6;0>b&&(b+=1);return{h:360*b,s:e/a,v:a/255}},rgb_to_hex:function(b,c,f){b=this.hex_with_component(0,2,b);b=this.hex_with_component(b,1,c);return b=this.hex_with_component(b,0,f)},component_from_hex:function(b,c){return b>>8*c&255},hex_with_component:function(b,c,f){return f<<(g=8*c)|b&~(255<<g)}}}(),dat.color.toString,dat.utils.common),dat.color.interpret,dat.utils.common),dat.utils.requestAnimationFrame=function(){return window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||
window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(g,b){window.setTimeout(g,1E3/60)}}(),dat.dom.CenteredDiv=function(g,b){var c=function(){this.backgroundElement=document.createElement("div");b.extend(this.backgroundElement.style,{backgroundColor:"rgba(0,0,0,0.8)",top:0,left:0,display:"none",zIndex:"1000",opacity:0,WebkitTransition:"opacity 0.2s linear"});g.makeFullscreen(this.backgroundElement);this.backgroundElement.style.position="fixed";this.domElement=document.createElement("div");
b.extend(this.domElement.style,{position:"fixed",display:"none",zIndex:"1001",opacity:0,WebkitTransition:"-webkit-transform 0.2s ease-out, opacity 0.2s linear"});document.body.appendChild(this.backgroundElement);document.body.appendChild(this.domElement);var c=this;g.bind(this.backgroundElement,"click",function(){c.hide()})};c.prototype.show=function(){var c=this;this.backgroundElement.style.display="block";this.domElement.style.display="block";this.domElement.style.opacity=0;this.domElement.style.webkitTransform=
"scale(1.1)";this.layout();b.defer(function(){c.backgroundElement.style.opacity=1;c.domElement.style.opacity=1;c.domElement.style.webkitTransform="scale(1)"})};c.prototype.hide=function(){var b=this,a=function(){b.domElement.style.display="none";b.backgroundElement.style.display="none";g.unbind(b.domElement,"webkitTransitionEnd",a);g.unbind(b.domElement,"transitionend",a);g.unbind(b.domElement,"oTransitionEnd",a)};g.bind(this.domElement,"webkitTransitionEnd",a);g.bind(this.domElement,"transitionend",
a);g.bind(this.domElement,"oTransitionEnd",a);this.backgroundElement.style.opacity=0;this.domElement.style.opacity=0;this.domElement.style.webkitTransform="scale(1.1)"};c.prototype.layout=function(){this.domElement.style.left=window.innerWidth/2-g.getWidth(this.domElement)/2+"px";this.domElement.style.top=window.innerHeight/2-g.getHeight(this.domElement)/2+"px"};return c}(dat.dom.dom,dat.utils.common),dat.dom.dom,dat.utils.common);
(function(){function g(){}function b(){}function c(){this.skinIndices=[];this.skinWeights=[];this.matrices=[]}function f(){this.hierarchy=[]}function a(){this.id=this.name=this.node=null;this.vertices=[];this.indices=[];this.normals=[];this.uvs=[];this.bones=[];this.skins=null}function e(){this.index=this.node=this.ref=this.map=this.uv=null}function d(){this.index=this.node=this.ref=this.map=this.normal=null}function l(){this.attrData=this.attrFlag=this.values=this.times=this.internalId=this.id=this.version=
null}function n(){this.attr=this.id=null;this.attrZ=this.attrY=this.attrX=!1;this.curveIdx=this.containerBoneId=this.containerInternalId=this.internalId=null;this.curves=[]}function k(){this.curves={};this.length=0;this.fps=30;this.frames=0}function p(){this.textures=[];this.perGeoMap={}}function r(){this.name=this.fileName="";this.id=null;this.parentIds=[]}THREE.FBXLoader=function(a,b){THREE.Loader.call(this,a);this.manager=void 0!==b?b:THREE.DefaultLoadingManager;this.textureBasePath=this.textureLoader=
null};THREE.FBXLoader.prototype=Object.create(THREE.Loader.prototype);THREE.FBXLoader.prototype.constructor=THREE.FBXLoader;THREE.FBXLoader.prototype.load=function(a,b,c,d){var e=this;(new THREE.XHRLoader(e.manager)).load(a,function(c){e.isFbxFormatASCII(c)?e.isFbxVersionSupported(c)?(e.textureBasePath=e.extractUrlBase(a),b(e.parse(c))):console.warn("FBXLoader: !!! FBX Version below 7 not supported !!!"):console.warn("FBXLoader: !!! FBX Binary format not supported !!!")},c,d)};THREE.FBXLoader.prototype.setCrossOrigin=
function(a){this.crossOrigin=a};THREE.FBXLoader.prototype.isFbxFormatASCII=function(a){CORRECT="Kaydara\\FBX\\Binary\\\\".split("");for(var b=0,c=0;c<CORRECT.length;++c){var d=a[0];a=a.slice(b+1);b++;num=d;if(num==CORRECT[c])return!1}return!0};THREE.FBXLoader.prototype.isFbxVersionSupported=function(a){return(match=a.match(/FBXVersion: (\d+)/))?(a=parseInt(match[1]),console.log("FBXLoader: FBX version "+a),7E3<=a):!1};THREE.FBXLoader.prototype.parse=function(a){console.time("FBXLoader");console.time("FBXLoader: TextParser");
a=(new b).parse(a);console.timeEnd("FBXLoader: TextParser");console.time("FBXLoader: ObjectParser");this.hierarchy=(new f).parseHierarchy(a);this.weights=(new c).parse(a,this.hierarchy);this.animations=(new k).parse(a,this.hierarchy);this.textures=(new p).parse(a,this.hierarchy);console.timeEnd("FBXLoader: ObjectParser");console.time("FBXLoader: GeometryParser");geometries=this.parseGeometries(a);console.timeEnd("FBXLoader: GeometryParser");a=new THREE.Group;for(var d=0;d<geometries.length;++d)void 0!==
geometries[d]&&a.add(geometries[d]);console.timeEnd("FBXLoader");return a};THREE.FBXLoader.prototype.parseGeometries=function(a){if(!("Geometry"in a.Objects.subNodes))return[];var b=0,c;for(c in a.Objects.subNodes.Geometry)c.match(/^\d+$/)&&b++;var d=[];if(0<b)for(c in a.Objects.subNodes.Geometry)"Mesh"===a.Objects.subNodes.Geometry[c].attrType&&d.push(this.parseGeometry(a.Objects.subNodes.Geometry[c],a));else d.push(this.parseGeometry(a.Objects.subNodes.Geometry,a));return d};THREE.FBXLoader.prototype.parseGeometry=
function(b,c){geo=(new a).parse(b);geo.addBones(this.hierarchy.hierarchy);var d=new THREE.BufferGeometry;d.name=geo.name;d.addAttribute("position",new THREE.BufferAttribute(new Float32Array(geo.vertices),3));void 0!==geo.normals&&0<geo.normals.length&&d.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(geo.normals),3));void 0!==geo.uvs&&0<geo.uvs.length&&d.addAttribute("uv",new THREE.BufferAttribute(new Float32Array(geo.uvs),2));void 0!==geo.indices&&65535<geo.indices.length?d.setIndex(new THREE.BufferAttribute(new Uint32Array(geo.indices),
1)):void 0!==geo.indices&&d.setIndex(new THREE.BufferAttribute(new Uint16Array(geo.indices),1));d.verticesNeedUpdate=!0;d.computeBoundingSphere();d.computeBoundingBox();var e=this.textures.getById(c.searchConnectionParent(geo.id));if(void 0!==e&&0<e.length){null===this.textureLoader&&(this.textureLoader=new THREE.TextureLoader);var f=this.textureLoader.load(this.textureBasePath+"/"+e[0].fileName)}f=void 0!==f?new THREE.MeshBasicMaterial({map:f}):new THREE.MeshBasicMaterial({color:3342591});d=(new THREE.Geometry).fromBufferGeometry(d);
d.bones=geo.bones;d.skinIndices=this.weights.skinIndices;d.skinWeights=this.weights.skinWeights;if(void 0===geo.bones||void 0===geo.skins||void 0===this.animations||0===this.animations.length){d=new THREE.Mesh(d,f);e=c.Connections.properties.connections;var g=c.Objects.subNodes.Model;for(f=0;f<e.length;f++)if(e[f][0]===b.id){d.name=g[e[f][1]].attrName;if(g[e[f][1]].properties.Lcl_Translation){e=g[e[f][1]].properties.Lcl_Translation.value.split(",");for(f=0;f<e.length;f++)e[f]=parseFloat(e[f]);d.position.x=
e[0];d.position.y=e[1];d.position.z=e[2]}break}}else f.skinning=!0,d=new THREE.SkinnedMesh(d,f),this.addAnimation(d,this.weights.matrices,this.animations);return d};THREE.FBXLoader.prototype.addAnimation=function(a,b,c){b={name:"animationtest",fps:30,length:c.length,hierarchy:[]};for(var d=0;d<a.geometry.bones.length;++d){var e=a.geometry.bones[d].name;e=e.replace(/.*:/,"");b.hierarchy.push({parent:a.geometry.bones[d].parent,name:e,keys:[]})}var f=function(a,b){if(void 0===a)return!1;switch(b){case "S":if(void 0===
a.S)return!1;var c=a.S;break;case "R":if(void 0===a.R)return!1;c=a.R;break;case "T":if(void 0===a.T)return!1;c=a.T}return void 0===c.curves.x||void 0===c.curves.y||void 0===c.curves.z?!1:!0},g=function(a,b){var c=void 0!==a.curves.y.values[b],d=void 0!==a.curves.z.values[b];return void 0!==a.curves.x.values[b]&&c&&d};e=function(a,b){var d={};d.time=frame/c.fps;d.pos=b.pos;d.rot=b.rotq;d.scl=b.scl;if(void 0===a)return d;try{if(f(a,"T")&&g(a.T,frame)){var e=new THREE.Vector3(a.T.curves.x.values[frame],
a.T.curves.y.values[frame],a.T.curves.z.values[frame]);d.pos=[e.x,e.y,e.z]}else delete d.pos;if(f(a,"R")&&g(a.R,frame)){var h=degToRad(a.R.curves.x.values[frame]),m=degToRad(a.R.curves.y.values[frame]),q=degToRad(a.R.curves.z.values[frame]),k=new THREE.Vector3(h,m,q),l=quatFromVec(k.x,k.y,k.z);d.rot=[l.x,l.y,l.z,l.w]}else delete d.rot;if(f(a,"S")&&g(a.S,frame)){var n=new THREE.Vector3(a.S.curves.x.values[frame],a.S.curves.y.values[frame],a.S.curves.z.values[frame]);d.scl=[n.x,n.y,n.z]}else delete d.scl}catch(L){console.log(b),
console.log(L)}return d};var h=a.geometry.bones;for(frame=0;frame<c.frames;frame++)for(d=0;d<h.length;d++)for(var m=h[d],q=c.curves[d],k=0;k<b.hierarchy.length;k++)b.hierarchy[k].name===m.name&&b.hierarchy[k].keys.push(e(q,m));void 0===a.geometry.animations&&(a.geometry.animations=[]);a.geometry.animations.push(THREE.AnimationClip.parseAnimation(b,a.geometry.bones))};THREE.FBXLoader.prototype.parseMaterials=function(a){if(!("Material"in a.subNodes))return[];var b=0,c;for(c in a.subNodes.Materials)c.match(/^\d+$/)&&
b++;var d=[];if(0<b)for(c in a.subNodes.Material)d.push(parseMaterial(a.subNodes.Material[c]));else d.push(parseMaterial(a.subNodes.Material));return d};THREE.FBXLoader.prototype.parseMaterial=function(a){};THREE.FBXLoader.prototype.loadFile=function(a,b,c,d,e){var f=new THREE.XHRLoader(this.manager);f.setResponseType(e);return f.load(a,function(a){b(a)},c,d)};THREE.FBXLoader.prototype.loadFileAsBuffer=function(a,b,c,d){this.loadFile(a,onLoad,c,d,"arraybuffer")};THREE.FBXLoader.prototype.loadFileAsText=
function(a,b,c,d){this.loadFile(a,b,c,d,"text")};g.prototype.add=function(a,b){this[a]=b};g.prototype.searchConnectionParent=function(a){void 0===this.__cache_search_connection_parent&&(this.__cache_search_connection_parent=[]);if(void 0!==this.__cache_search_connection_parent[a])return this.__cache_search_connection_parent[a];this.__cache_search_connection_parent[a]=[];for(var b=this.Connections.properties.connections,c=[],d=0;d<b.length;++d)b[d][0]==a&&c.push(0===b[d][1]?-1:b[d][1]);if(0<c.length)return this.__cache_search_connection_parent[a]=
this.__cache_search_connection_parent[a].concat(c),c;this.__cache_search_connection_parent[a]=[-1];return[-1]};g.prototype.searchConnectionChildren=function(a){void 0===this.__cache_search_connection_children&&(this.__cache_search_connection_children=[]);if(void 0!==this.__cache_search_connection_children[a])return this.__cache_search_connection_children[a];this.__cache_search_connection_children[a]=[];for(var b=this.Connections.properties.connections,c=[],d=0;d<b.length;++d)b[d][1]==a&&c.push(0===
b[d][0]?-1:b[d][0]);if(0<c.length)return this.__cache_search_connection_children[a]=this.__cache_search_connection_children[a].concat(c),c;this.__cache_search_connection_children[a]=[-1];return[-1]};g.prototype.searchConnectionType=function(a,b){var c=a+","+b;void 0===this.__cache_search_connection_type&&(this.__cache_search_connection_type="");if(void 0!==this.__cache_search_connection_type[c])return this.__cache_search_connection_type[c];this.__cache_search_connection_type[c]="";for(var d=this.Connections.properties.connections,
e=0;e<d.length;++e)if(d[e][0]==a&&d[e][1]==b)return this.__cache_search_connection_type[c]=d[e][2],d[e][2];return this.__cache_search_connection_type[a]=null};b.prototype={getPrevNode:function(){return this.nodeStack[this.currentIndent-2]},getCurrentNode:function(){return this.nodeStack[this.currentIndent-1]},getCurrentProp:function(){return this.currentProp},pushStack:function(a){this.nodeStack.push(a);this.currentIndent+=1},popStack:function(){this.nodeStack.pop();--this.currentIndent},setCurrentProp:function(a,
b){this.currentProp=a;this.currentPropName=b},parse:function(a){this.currentIndent=0;this.allNodes=new g;this.nodeStack=[];this.currentProp=[];this.currentPropName="";a=a.split("\n");for(var b in a){var c=a[b];if(!c.match(/^[\s\t]*;/)&&!c.match(/^[\s\t]*$/))if(match=c.match(new RegExp("^\\t{"+this.currentIndent+"}(\\w+):(.*){",""))){var d=match[1].trim().replace(/^"/,"").replace(/"$/,""),e=match[2].split(",").map(function(a){return a.trim().replace(/^"/,"").replace(/"$/,"")});this.parseNodeBegin(c,
d,e||null)}else(match=c.match(new RegExp("^\\t{"+this.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)")))?(d=match[1].replace(/^"/,"").replace(/"$/,"").trim(),e=match[2].replace(/^"/,"").replace(/"$/,"").trim(),this.parseNodeProperty(c,d,e)):c.match(new RegExp("^\\t{"+(this.currentIndent-1)+"}}"))?this.nodeEnd():c.match(/^[^\s\t}]/)&&this.parseNodePropertyContinued(c)}return this.allNodes},parseNodeBegin:function(a,b,c){a={name:b,properties:{},subNodes:{}};var d=this.parseNodeAttr(c),e=this.getCurrentNode();
if(0===this.currentIndent)this.allNodes.add(b,a);else if(b in e.subNodes){var f=e.subNodes[b];this.isFlattenNode(e.subNodes[b])&&(""===d.id?(e.subNodes[b]=[],e.subNodes[b].push(f)):(e.subNodes[b]={},e.subNodes[b][f.id]=f));""===d.id?e.subNodes[b].push(a):e.subNodes[b][d.id]=a}else e.subNodes[b]=a;c&&(a.id=d.id,a.attrName=d.name,a.attrType=d.type);this.pushStack(a)},parseNodeAttr:function(a){var b=a[0];""!==a[0]&&(b=parseInt(a[0]),isNaN(b)&&(b=a[0]));if(1<a.length){var c=a[1].replace(/^(\w+)::/,"");
var d=a[2]}return{id:b,name:c||"",type:d||""}},parseNodeProperty:function(a,b,c){var d=this.getCurrentNode(),e=d.name;if(void 0!==e&&e.match(/Properties(\d)+/))this.parseNodeSpecialProperty(a,b,c);else{if("C"==b){b=c.split(",").slice(1);a=parseInt(b[0]);e=parseInt(b[1]);var f=c.split(",").slice(3);b="connections";c=[a,e];c=c.concat(f);void 0===d.properties[b]&&(d.properties[b]=[])}"Node"==b&&(a=parseInt(c),d.properties.id=a,d.id=a);b in d.properties?Array.isArray(d.properties[b])?d.properties[b].push(c):
d.properties[b]+=c:Array.isArray(d.properties[b])?d.properties[b].push(c):d.properties[b]=c;this.setCurrentProp(d.properties,b)}},parseNodePropertyContinued:function(a){this.currentProp[this.currentPropName]+=a},parseNodeSpecialProperty:function(a,b,c){var d=c.split('",').map(function(a){return a.trim().replace(/^"/,"").replace(/\s/,"_")});a=d[0];b=d[1];c=d[2];var e=d[3];d=d[4];switch(b){case "int":d=parseInt(d);break;case "double":d=parseFloat(d);break;case "ColorRGB":case "Vector3D":d=d.split(","),
d=new THREE.Vector3(d[0],d[1],d[2])}this.getPrevNode().properties[a]={type:b,type2:c,flag:e,value:d};this.setCurrentProp(this.getPrevNode().properties,a)},nodeEnd:function(a){this.popStack()},isFlattenNode:function(a){return"subNodes"in a&&"properties"in a?!0:!1}};c.prototype.parseCluster=function(a,b,c){a=a.searchConnectionParent(b);var d=toInt(c.subNodes.Indexes.properties.a.split(",")),e=toFloat(c.subNodes.Weights.properties.a.split(",")),f=toMat44(toFloat(c.subNodes.Transform.properties.a.split(","))),
g=toMat44(toFloat(c.subNodes.TransformLink.properties.a.split(",")));return{parent:a,id:parseInt(b),indices:d,weights:e,transform:f,transformlink:g,linkMode:c.properties.Mode}};c.prototype.parse=function(a,b){this.skinIndices=[];this.skinWeights=[];this.matrices=[];var c=a.Objects.subNodes.Deformer,d={};for(g in c)if("Cluster"===c[g].attrType&&"Indexes"in c[g].subNodes){var e=this.parseCluster(a,g,c[g]),f=a.searchConnectionChildren(e.id)[0];d[f]=e}c=[];var g=b.hierarchy;for(e=0;e<g.length;++e)if(f=
g[e].internalId,void 0===d[f])this.matrices.push(new THREE.Matrix4);else{f=d[f];this.matrices.push(f.transform);for(var h=0;h<f.indices.length;++h){void 0===c[f.indices[h]]&&(c[f.indices[h]]={},c[f.indices[h]].joint=[],c[f.indices[h]].weight=[]);var m=a.searchConnectionChildren(f.id);1<m.length&&console.warn("FBXLoader: node "+f.id+" have many weight kids: "+m);c[f.indices[h]].joint.push(b.getBoneIdfromInternalId(a,m[0]));c[f.indices[h]].weight.push(f.weights[h])}}for(d=0;d<c.length;d++)g=new THREE.Vector4(c[d].joint[0]?
c[d].joint[0]:0,c[d].joint[1]?c[d].joint[1]:0,c[d].joint[2]?c[d].joint[2]:0,c[d].joint[3]?c[d].joint[3]:0),e=new THREE.Vector4(c[d].weight[0]?c[d].weight[0]:0,c[d].weight[1]?c[d].weight[1]:0,c[d].weight[2]?c[d].weight[2]:0,c[d].weight[3]?c[d].weight[3]:0),this.skinIndices.push(g),this.skinWeights.push(e);return this};f.prototype.parseHierarchy=function(a){var b=a.Objects.subNodes.Model,c=[];for(d in b)void 0!==b[d].attrType&&c.push(b[d]);this.hierarchy=[];for(b=0;b<c.length;++b){var d=c[b];var e=
a.searchConnectionParent(d.id)[0],f=[0,0,0],g=[0,0,0,1],h=[1,1,1];"Lcl_Translation"in d.properties&&(f=toFloat(d.properties.Lcl_Translation.value.split(",")));if("Lcl_Rotation"in d.properties){g=toRad(toFloat(d.properties.Lcl_Rotation.value.split(",")));var k=new THREE.Quaternion;k.setFromEuler(new THREE.Euler(g[0],g[1],g[2],"ZYX"));g=[k.x,k.y,k.z,k.w]}"Lcl_Scaling"in d.properties&&(h=toFloat(d.properties.Lcl_Scaling.value.split(",")));k=d.attrName;k=k.replace(/:/,"");k=k.replace(/_/,"");k=k.replace(/-/,
"");this.hierarchy.push({parent:e,name:k,pos:f,rotq:g,scl:h,internalId:d.id})}this.reindexParentId();this.restoreBindPose(a);return this};f.prototype.reindexParentId=function(){for(var a=0;a<this.hierarchy.length;a++)for(var b=0;b<this.hierarchy.length;++b)if(this.hierarchy[a].parent==this.hierarchy[b].internalId){this.hierarchy[a].parent=b;break}};f.prototype.restoreBindPose=function(a){var b=a.Objects.subNodes.Pose;if(void 0!==b){var c=b.subNodes.PoseNode;b={};for(var d={},e=0;e<c.length;++e){var f=
toMat44(c[e].subNodes.Matrix.properties.a.split(",")),g=toMat44(c[e].subNodes.Matrix.properties.a.split(","));b[c[e].id]=f;d[c[e].id]=g}for(c=0;c<this.hierarchy.length;++c)if(e=this.hierarchy[c],f=e.internalId,void 0!==d[f]){g=new THREE.Vector3(0,0,0);for(var h=new THREE.Quaternion,k=new THREE.Vector3(1,1,1),l,n=a.searchConnectionParent(f),p=0;p<n.length;++p)if(this.isBoneNode(n[p])){l=n[p];break}void 0!==l&&void 0!==b[l]&&(n=new THREE.Matrix4,n.getInverse(d[l]),n.multiply(b[f]),b[f]=n);b[f].decompose(g,
h,k);e.pos=[g.x,g.y,g.z];e.rotq=[h.x,h.y,h.z,h.w];e.scl=[k.x,k.y,k.z]}}};f.prototype.searchRealId=function(a){for(var b=0;b<this.hierarchy.length;b++)if(a==this.hierarchy[b].internalId)return b;return-1};f.prototype.getByInternalId=function(a){for(var b=0;b<this.hierarchy.length;b++)if(a==this.hierarchy[b].internalId)return this.hierarchy[b];return null};f.prototype.isBoneNode=function(a){for(var b=0;b<this.hierarchy.length;++b)if(a===this.hierarchy[b].internalId)return!0;return!1};f.prototype.getBoneIdfromInternalId=
function(a,b){void 0===a.__cache_get_boneid_from_internalid&&(a.__cache_get_boneid_from_internalid=[]);if(void 0!==a.__cache_get_boneid_from_internalid[b])return a.__cache_get_boneid_from_internalid[b];for(var c=0;c<this.hierarchy.length;++c)if(this.hierarchy[c].internalId==b)return a.__cache_get_boneid_from_internalid[b]=c;return-1};a.prototype.parse=function(a){this.node=a;this.name=a.attrName;this.id=a.id;this.vertices=this.getVertices();if(void 0===this.vertices)console.log("FBXLoader: Geometry.parse(): pass"+
this.node.id);else return this.indices=this.getPolygonVertexIndices(),this.uvs=(new e).parse(this.node,this),this.normals=(new d).parse(this.node,this),3<this.getPolygonTopologyMax()&&(this.indices=this.convertPolyIndicesToTri(this.indices,this.getPolygonTopologyArray())),this};a.prototype.getVertices=function(){if(this.node.__cache_vertices)return this.node.__cache_vertices;if(void 0===this.node.subNodes.Vertices)return console.warn("this.node: "+this.node.attrName+"("+this.node.id+") does not have Vertices"),
this.node.__cache_vertices=void 0,null;var a=this.node.subNodes.Vertices.properties.a.split(",").map(function(a){return parseFloat(a)});this.node.__cache_vertices=a;return this.node.__cache_vertices};a.prototype.getPolygonVertexIndices=function(){if(this.node.__cache_indices&&this.node.__cache_poly_topology_max)return this.node.__cache_indices;if(void 0===this.node.subNodes)console.error("this.node.subNodes undefined"),console.log(this.node);else if(void 0===this.node.subNodes.PolygonVertexIndex)console.warn("this.node: "+
this.node.attrName+"("+this.node.id+") does not have PolygonVertexIndex "),this.node.__cache_indices=void 0;else{for(var a=this.node.subNodes.PolygonVertexIndex.properties.a.split(","),b=1,c=null,d=[],e=0;e<a.length;++e){var f=parseInt(a[e]);0>f?(b>c&&(c=b),a[e]=f^-1,d.push(b),b=1):(a[e]=f,b++)}null===c&&(console.warn("FBXLoader: topology N not found: "+this.node.attrName),console.warn(this.node),c=3);this.node.__cache_poly_topology_max=c;this.node.__cache_poly_topology_arr=d;this.node.__cache_indices=
a;return this.node.__cache_indices}};a.prototype.getPolygonTopologyMax=function(){if(this.node.__cache_indices&&this.node.__cache_poly_topology_max)return this.node.__cache_poly_topology_max;this.getPolygonVertexIndices(this.node);return this.node.__cache_poly_topology_max};a.prototype.getPolygonTopologyArray=function(){if(this.node.__cache_indices&&this.node.__cache_poly_topology_max)return this.node.__cache_poly_topology_arr;this.getPolygonVertexIndices(this.node);return this.node.__cache_poly_topology_arr};
a.prototype.convertPolyIndicesToTri=function(a,b){for(var c=[],d=0,e=0,f;d<a.length;){f=b[e];for(var g=0;g<=f-3;g++)c.push(a[d]),c.push(a[d+(f-2-g)]),c.push(a[d+(f-1-g)]);e++;d+=f}return c};a.prototype.addBones=function(a){this.bones=a};e.prototype.getUV=function(a){return this.node&&this.uv&&this.map&&this.ref?this.uv:this._parseText(a)};e.prototype.getMap=function(a){this.node&&this.uv&&this.map&&this.ref||this._parseText(a);return this.map};e.prototype.getRef=function(a){this.node&&this.uv&&this.map&&
this.ref||this._parseText(a);return this.ref};e.prototype.getIndex=function(a){this.node&&this.uv&&this.map&&this.ref||this._parseText(a);return this.index};e.prototype.getNode=function(a){return null!==this.node?this.node:this.node=a.subNodes.LayerElementUV};e.prototype._parseText=function(a){a=this.getNode(a);if(void 0===a)return[];var b=0;for(c in a)c.match(/^\d+$/)&&b++;0<b&&(console.warn("multi uv not supported"),a=a[c]);var c=a.subNodes.UVIndex.properties.a;b=a.properties.MappingInformationType;
var d=a.properties.ReferenceInformationType;this.uv=toFloat(a.subNodes.UV.properties.a.split(","));this.index=toInt(c.split(","));this.map=b;this.ref=d;return this.uv};e.prototype.parse=function(a,b){this.uvNode=this.getNode(a);this.uv=this.getUV(a);var c=this.getMap(a),d=this.getRef(a),e=this.getIndex(a),f=b.getPolygonTopologyArray();switch(c){case "ByPolygonVertex":switch(d){case "Direct":this.uv=this.parseUV_ByPolygonVertex_Direct(this.uv,e,f,2);break;case "IndexToDirect":this.uv=this.parseUV_ByPolygonVertex_IndexToDirect(this.uv,
e)}var g=this.uv,h=b.getPolygonVertexIndices(a);c={};d=[];for(f=e=0;f<h.length;++f)if(!(h[f]in c)){c[h[f]]={};for(var k=0;2>k;++k)c[h[f]][k]=g[2*f+k];e=e<h[f]?h[f]:e}try{for(f=0;f<=e;f++)for(g=0;2>g;g++)d.push(c[f][g])}catch(x){}this.uv=d;break;case "ByPolygon":switch(d){case "Direct":this.uv=this.parseUV_ByPolygon_Direct();break;case "IndexToDirect":this.uv=this.parseUV_ByPolygon_IndexToDirect()}}return this.uv};e.prototype.parseUV_ByPolygonVertex_Direct=function(a,b,c,d){return parse_Data_ByPolygonVertex_Direct(a,
b,c,d)};e.prototype.parseUV_ByPolygonVertex_IndexToDirect=function(a,b){for(var c=[],d=0;d<b.length;++d)for(var e=0;2>e;++e)c.push(a[2*b[d]+e]);return c};e.prototype.parseUV_ByPolygon_Direct=function(a){console.warn("not implemented");return a};e.prototype.parseUV_ByPolygon_IndexToDirect=function(a){console.warn("not implemented");return a};e.prototype.parseUV_ByVertex_Direct=function(a){console.warn("not implemented");return a};d.prototype.getNormal=function(a){this.node&&this.normal&&this.map&&
this.ref||this._parseText(a);return this.normal};d.prototype.getMap=function(a){this.node&&this.normal&&this.map&&this.ref||this._parseText(a);return this.map};d.prototype.getRef=function(a){this.node&&this.normal&&this.map&&this.ref||this._parseText(a);return this.ref};d.prototype.getNode=function(a){return this.node?this.node:this.node=a.subNodes.LayerElementNormal};d.prototype._parseText=function(a){var b=this.getNode(a);if(void 0===b)console.warn("node: "+a.attrName+"("+a.id+") does not have LayerElementNormal");
else{a=b.properties.MappingInformationType;var c=b.properties.ReferenceInformationType;this.normal=toFloat(b.subNodes.Normals.properties.a.split(","));this.map=a;this.ref=c}};d.prototype.parse=function(a,b){var c=this.getNormal(a);this.getNode(a);var d=this.getMap(a),e=this.getRef(a),f=b.getPolygonVertexIndices(a),g=b.getPolygonTopologyArray(a);switch(d){case "ByPolygonVertex":switch(e){case "Direct":c=this.parseNormal_ByPolygonVertex_Direct(c,f,g,3);break;case "IndexToDirect":c=this.parseNormal_ByPolygonVertex_IndexToDirect()}break;
case "ByPolygon":switch(e){case "Direct":c=this.parseNormal_ByPolygon_Direct();break;case "IndexToDirect":c=this.parseNormal_ByPolygon_IndexToDirect()}}return c};d.prototype.parseNormal_ByPolygonVertex_Direct=function(a,b,c,d){return parse_Data_ByPolygonVertex_Direct(a,b,c,d)};d.prototype.parseNormal_ByPolygonVertex_IndexToDirect=function(a){console.warn("not implemented");return a};d.prototype.parseNormal_ByPolygon_Direct=function(a){console.warn("not implemented");return a};d.prototype.parseNormal_ByPolygon_IndexToDirect=
function(a){console.warn("not implemented");return a};d.prototype.parseNormal_ByVertex_Direct=function(a){console.warn("not implemented");return a};l.prototype.fromNode=function(a){this.internalId=this.id=a.id;this.times=a.subNodes.KeyTime.properties.a;this.values=a.subNodes.KeyValueFloat.properties.a;this.attrFlag=a.subNodes.KeyAttrFlags.properties.a;this.attrData=a.subNodes.KeyAttrDataFloat.properties.a;this.times=toFloat(this.times.split(","));this.values=toFloat(this.values.split(","));this.attrData=
toFloat(this.attrData.split(","));this.attrFlag=toInt(this.attrFlag.split(","));this.times=this.times.map(function(a){return a/46186158E3});return this};l.prototype.getLength=function(){return this.times[this.times.length-1]};n.prototype.fromNode=function(a,b,c){this.id=b.id;this.attr=b.attrName;this.internalId=b.id;if(this.attr.match(/S|R|T/))for(var d in b.properties)d.match(/X/)&&(this.attrX=!0),d.match(/Y/)&&(this.attrY=!0),d.match(/Z/)&&(this.attrZ=!0);else return null;this.containerIndices=
a.searchConnectionParent(this.id);this.curveIdx=a.searchConnectionChildren(this.id);for(a=this.containerIndices.length-1;0<=a&&!(b=c.searchRealId(this.containerIndices[a]),0<=b&&(this.containerBoneId=b,this.containerId=this.containerIndices[a]),0<=b);--a);return this};n.prototype.setCurve=function(a){this.curves.push(a)};k.prototype.parse=function(a,b){var c=a.Objects.subNodes.AnimationCurveNode,d=a.Objects.subNodes.AnimationCurve,e=[],f;for(f in c)if(f.match(/\d+/)){var g=(new n).fromNode(a,c[f],
b);e.push(g)}c={};for(g=0;g<e.length;++g)null!==e[g]&&(c[e[g].id]=e[g]);g=[];e=0;for(f in d)if(f.match(/\d+/)){var h=(new l).fromNode(d[f]);g.push(h);e=h.getLength()?h.getLength():e;var k=a.searchConnectionParent(h.id)[0],m=a.searchConnectionType(h.id,k);m.match(/X/)&&(m="x");m.match(/Y/)&&(m="y");m.match(/Z/)&&(m="z");c[k].curves[m]=h}for(var p in c)d=c[p].containerBoneId,void 0===this.curves[d]&&(this.curves[d]={}),this.curves[d][c[p].attr]=c[p];this.length=e;this.frames=this.length*this.fps;return this};
p.prototype.add=function(a){void 0===this.textures&&(this.textures=[]);this.textures.push(a);for(var b=0;b<a.parentIds.length;++b)void 0===this.perGeoMap[a.parentIds[b]]&&(this.perGeoMap[a.parentIds[b]]=[]),this.perGeoMap[a.parentIds[b]].push(this.textures[this.textures.length-1])};p.prototype.parse=function(a,b){var c=a.Objects.subNodes.Texture,d;for(d in c){var e=(new r).parse(c[d],a);this.add(e)}return this};p.prototype.getById=function(a){return this.perGeoMap[a]};r.prototype.parse=function(a,
b){this.id=a.id;this.name=a.attrName;this.fileName=this.parseFileName(a.properties.FileName);this.parentIds=this.searchParents(this.id,b);return this};r.prototype.parseFileName=function(a){if(void 0===a)return"";var b=a.split(/[\\\/]/);return 0<b.length?b[b.length-1]:a};r.prototype.searchParents=function(a,b){return b.searchConnectionParent(a)};parse_Data_ByPolygonVertex_Direct=function(a,b,c,d){c=[];for(var e=0,f=0;f<b.length;++f){c[b[f]]=[];for(var g=0;g<d;++g)c[b[f]][g]=a[e+g];e+=d}a=[];for(b=
0;b<c.length;++b)if(void 0!==c[b])for(e=0;e<d;++e)void 0!==c[b][e]&&a.push(c[b][e]);return a};degToRad=function(a){return a*Math.PI/180};radToDeg=function(a){return 180*a/Math.PI};quatFromVec=function(a,b,c){a=new THREE.Euler(a,b,c,"ZYX");b=new THREE.Quaternion;b.setFromEuler(a);return b};toInt=function(a){return a.map(function(a){return parseInt(a)})};toFloat=function(a){return a.map(function(a){return parseFloat(a)})};toRad=function(a){return a.map(function(a){return degToRad(a)})};toMat44=function(a){var b=
new THREE.Matrix4;b.set(a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]);return b}})();THREE.SpriteCanvasMaterial=function(g){THREE.Material.call(this);this.type="SpriteCanvasMaterial";this.color=new THREE.Color(16777215);this.program=function(b,c){};this.setValues(g)};THREE.SpriteCanvasMaterial.prototype=Object.create(THREE.Material.prototype);THREE.SpriteCanvasMaterial.prototype.constructor=THREE.SpriteCanvasMaterial;
THREE.SpriteCanvasMaterial.prototype.clone=function(){var g=new THREE.SpriteCanvasMaterial;g.copy(this);g.color.copy(this.color);g.program=this.program;return g};
THREE.CanvasRenderer=function(g){function b(a,b,c,d){n(b);k(c);p(d);r(a.getStyle());E.stroke();pa.expandByScalar(2*b)}function c(a){h(a.getStyle());E.fill()}function f(a){if(0===a.version||a instanceof THREE.CompressedTexture||a instanceof THREE.DataTexture)return{canvas:void 0,version:a.version};var b=a.image;if(!1===b.complete)return{canvas:void 0,version:0};var c=document.createElement("canvas");c.width=b.width;c.height=b.height;var d=c.getContext("2d");d.setTransform(1,0,0,-1,0,b.height);d.drawImage(b,
0,0);b=a.wrapS===THREE.RepeatWrapping;d=a.wrapT===THREE.RepeatWrapping;var e="no-repeat";!0===b&&!0===d?e="repeat":!0===b?e="repeat-x":!0===d&&(e="repeat-y");c=E.createPattern(c,e);if(a.onUpdate)a.onUpdate(a);return{canvas:c,version:a.version}}function a(a,b,c,d,e,g,k,l,m,n,q,p,r){var t=ka[r.id];if(void 0===t||t.version!==r.version)t=f(r),ka[r.id]=t;if(void 0!==t.canvas){h(t.canvas);t=r.offset.x/r.repeat.x;var u=r.offset.y/r.repeat.y,v=r.image.width*r.repeat.x;r=r.image.height*r.repeat.y;k=(k+t)*
v;l=(l+u)*r;c-=a;d-=b;e-=a;g-=b;m=(m+t)*v-k;n=(n+u)*r-l;q=(q+t)*v-k;p=(p+u)*r-l;r=m*p-q*n;0!==r&&(t=1/r,r=(p*c-n*e)*t,n=(p*d-n*g)*t,c=(m*e-q*c)*t,d=(m*g-q*d)*t,a=a-r*k-c*l,b=b-n*k-d*l,E.save(),E.transform(r,n,c,d,a,b),E.fill(),E.restore())}else h("rgba( 0, 0, 0, 1)"),E.fill()}function e(a,b,c){var d=b.x-a.x,e=b.y-a.y,f=d*d+e*e;0!==f&&(c/=Math.sqrt(f),d*=c,e*=c,b.x+=d,b.y+=e,a.x-=d,a.y-=e)}function d(a){N!==a&&(N=E.globalAlpha=a)}function l(a){L!==a&&(a===THREE.NormalBlending?E.globalCompositeOperation=
"source-over":a===THREE.AdditiveBlending?E.globalCompositeOperation="lighter":a===THREE.SubtractiveBlending&&(E.globalCompositeOperation="darker"),L=a)}function n(a){J!==a&&(J=E.lineWidth=a)}function k(a){V!==a&&(V=E.lineCap=a)}function p(a){U!==a&&(U=E.lineJoin=a)}function r(a){W!==a&&(W=E.strokeStyle=a)}function h(a){y!==a&&(y=E.fillStyle=a)}function m(a){R.length!==a.length&&(E.setLineDash(a),R=a)}console.log("THREE.CanvasRenderer",THREE.REVISION);g=g||{};var q=this,t,u,w,v=new THREE.Projector,
z=void 0!==g.canvas?g.canvas:document.createElement("canvas"),C=z.width,x=z.height,D=Math.floor(C/2),F=Math.floor(x/2),K=0,B=0,P=C,Q=x,H=1,E=z.getContext("2d",{alpha:!0===g.alpha}),I=new THREE.Color(0),A=!0===g.alpha?0:1,N=1,L=0,W=null,y=null,J=null,V=null,U=null,R=[],G,O,T;new THREE.RenderableVertex;new THREE.RenderableVertex;var M,S,Z,X,ja,ba,Y=new THREE.Color;new THREE.Color;new THREE.Color;new THREE.Color;new THREE.Color;var da=new THREE.Color,fa=new THREE.Color,ca=new THREE.Color,ka={},ha,ma,
oa,la,na,va,sa,ia=new THREE.Box2,aa=new THREE.Box2,pa=new THREE.Box2,Sa=new THREE.Color,ab=new THREE.Color,Ta=new THREE.Color,Fa=new THREE.Vector3,eb=new THREE.Vector3,ea=new THREE.Vector3,Ba=new THREE.Matrix3;void 0===E.setLineDash&&(E.setLineDash=function(){});this.domElement=z;this.sortElements=this.sortObjects=this.autoClear=!0;this.info={render:{vertices:0,faces:0}};this.supportsVertexTextures=function(){};this.setFaceCulling=function(){};this.getContext=function(){return E};this.getContextAttributes=
function(){return E.getContextAttributes()};this.getPixelRatio=function(){return H};this.setPixelRatio=function(a){void 0!==a&&(H=a)};this.setSize=function(a,b,c){C=a*H;x=b*H;z.width=C;z.height=x;D=Math.floor(C/2);F=Math.floor(x/2);!1!==c&&(z.style.width=a+"px",z.style.height=b+"px");ia.min.set(-D,-F);ia.max.set(D,F);aa.min.set(-D,-F);aa.max.set(D,F);N=1;L=0;U=V=J=y=W=null;this.setViewport(0,0,a,b)};this.setViewport=function(a,b,c,d){K=a*H;B=b*H;P=c*H;Q=d*H};this.setScissor=function(){};this.setScissorTest=
function(){};this.setClearColor=function(a,b){I.set(a);A=void 0!==b?b:1;aa.min.set(-D,-F);aa.max.set(D,F)};this.setClearColorHex=function(a,b){console.warn("THREE.CanvasRenderer: .setClearColorHex() is being removed. Use .setClearColor() instead.");this.setClearColor(a,b)};this.getClearColor=function(){return I};this.getClearAlpha=function(){return A};this.getMaxAnisotropy=function(){return 0};this.clear=function(){!1===aa.isEmpty()&&(aa.intersect(ia),aa.expandByScalar(2),aa.min.x+=D,aa.min.y=-aa.min.y+
F,aa.max.x+=D,aa.max.y=-aa.max.y+F,1>A&&E.clearRect(aa.min.x|0,aa.max.y|0,aa.max.x-aa.min.x|0,aa.min.y-aa.max.y|0),0<A&&(l(THREE.NormalBlending),d(1),h("rgba("+Math.floor(255*I.r)+","+Math.floor(255*I.g)+","+Math.floor(255*I.b)+","+A+")"),E.fillRect(aa.min.x|0,aa.max.y|0,aa.max.x-aa.min.x|0,aa.min.y-aa.max.y|0)),aa.makeEmpty())};this.clearColor=function(){};this.clearDepth=function(){};this.clearStencil=function(){};this.render=function(g,y){if(!1===y instanceof THREE.Camera)console.error("THREE.CanvasRenderer.render: camera is not an instance of THREE.Camera.");
else{!0===this.autoClear&&this.clear();q.info.render.vertices=0;q.info.render.faces=0;E.setTransform(P/C,0,0,-Q/x,K,x-B);E.translate(D,F);t=v.projectScene(g,y,this.sortObjects,this.sortElements);u=t.elements;w=t.lights;Ba.getNormalMatrix(y.matrixWorldInverse);Sa.setRGB(0,0,0);ab.setRGB(0,0,0);Ta.setRGB(0,0,0);for(var z=0,A=w.length;z<A;z++){var H=w[z],I=H.color;H instanceof THREE.AmbientLight?Sa.add(I):H instanceof THREE.DirectionalLight?ab.add(I):H instanceof THREE.PointLight&&Ta.add(I)}z=0;for(A=
u.length;z<A;z++){var J=u[z],N=J.material;if(void 0!==N&&0!==N.opacity){pa.makeEmpty();if(J instanceof THREE.RenderableSprite){G=J;G.x*=D;G.y*=F;H=G;var L=J;I=N;d(I.opacity);l(I.blending);var R=L.scale.x*D;L=L.scale.y*F;J=.5*Math.sqrt(R*R+L*L);pa.min.set(H.x-J,H.y-J);pa.max.set(H.x+J,H.y+J);if(I instanceof THREE.SpriteMaterial){var U=I.map;if(null!==U){J=ka[U.id];if(void 0===J||J.version!==U.version)J=f(U),ka[U.id]=J;if(void 0!==J.canvas){h(J.canvas);var V=U.image;J=V.width*U.offset.x;N=V.height*
U.offset.y;var W=V.width*U.repeat.x;U=V.height*U.repeat.y;V=R/W;var qa=L/U;E.save();E.translate(H.x,H.y);0!==I.rotation&&E.rotate(I.rotation);E.translate(-R/2,-L/2);E.scale(V,qa);E.translate(-J,-N);E.fillRect(J,N,W,U);E.restore()}}else h(I.color.getStyle()),E.save(),E.translate(H.x,H.y),0!==I.rotation&&E.rotate(I.rotation),E.scale(R,-L),E.fillRect(-.5,-.5,1,1),E.restore()}else I instanceof THREE.SpriteCanvasMaterial&&(r(I.color.getStyle()),h(I.color.getStyle()),E.save(),E.translate(H.x,H.y),0!==I.rotation&&
E.rotate(I.rotation),E.scale(R,L),I.program(E),E.restore())}else if(J instanceof THREE.RenderableLine){if(G=J.v1,O=J.v2,G.positionScreen.x*=D,G.positionScreen.y*=F,O.positionScreen.x*=D,O.positionScreen.y*=F,pa.setFromPoints([G.positionScreen,O.positionScreen]),!0===ia.intersectsBox(pa))if(H=G,I=O,R=J,L=N,d(L.opacity),l(L.blending),E.beginPath(),E.moveTo(H.positionScreen.x,H.positionScreen.y),E.lineTo(I.positionScreen.x,I.positionScreen.y),L instanceof THREE.LineBasicMaterial){n(L.linewidth);k(L.linecap);
p(L.linejoin);if(L.vertexColors!==THREE.VertexColors)r(L.color.getStyle());else if(J=R.vertexColors[0].getStyle(),R=R.vertexColors[1].getStyle(),J===R)r(J);else{try{var Ua=E.createLinearGradient(H.positionScreen.x,H.positionScreen.y,I.positionScreen.x,I.positionScreen.y);Ua.addColorStop(0,J);Ua.addColorStop(1,R)}catch(wc){Ua=J}r(Ua)}E.stroke();pa.expandByScalar(2*L.linewidth)}else L instanceof THREE.LineDashedMaterial&&(n(L.linewidth),k(L.linecap),p(L.linejoin),r(L.color.getStyle()),m([L.dashSize,
L.gapSize]),E.stroke(),pa.expandByScalar(2*L.linewidth),m([]))}else if(J instanceof THREE.RenderableFace){G=J.v1;O=J.v2;T=J.v3;if(-1>G.positionScreen.z||1<G.positionScreen.z)continue;if(-1>O.positionScreen.z||1<O.positionScreen.z)continue;if(-1>T.positionScreen.z||1<T.positionScreen.z)continue;G.positionScreen.x*=D;G.positionScreen.y*=F;O.positionScreen.x*=D;O.positionScreen.y*=F;T.positionScreen.x*=D;T.positionScreen.y*=F;0<N.overdraw&&(e(G.positionScreen,O.positionScreen,N.overdraw),e(O.positionScreen,
T.positionScreen,N.overdraw),e(T.positionScreen,G.positionScreen,N.overdraw));pa.setFromPoints([G.positionScreen,O.positionScreen,T.positionScreen]);if(!0===ia.intersectsBox(pa)){I=G;R=O;L=T;H=N;q.info.render.vertices+=3;q.info.render.faces++;d(H.opacity);l(H.blending);M=I.positionScreen.x;S=I.positionScreen.y;Z=R.positionScreen.x;X=R.positionScreen.y;ja=L.positionScreen.x;ba=L.positionScreen.y;N=M;W=S;U=Z;V=X;qa=ja;var pc=ba;E.beginPath();E.moveTo(N,W);E.lineTo(U,V);E.lineTo(qa,pc);E.closePath();
if((H instanceof THREE.MeshLambertMaterial||H instanceof THREE.MeshPhongMaterial)&&null===H.map){da.copy(H.color);fa.copy(H.emissive);H.vertexColors===THREE.FaceColors&&da.multiply(J.color);Y.copy(Sa);eb.copy(I.positionWorld).add(R.positionWorld).add(L.positionWorld).divideScalar(3);I=eb;R=J.normalModel;L=Y;J=0;for(N=w.length;J<N;J++)W=w[J],ca.copy(W.color),W instanceof THREE.DirectionalLight?(U=Fa.setFromMatrixPosition(W.matrixWorld).normalize(),V=R.dot(U),0>=V||(V*=W.intensity,L.add(ca.multiplyScalar(V)))):
W instanceof THREE.PointLight&&(U=Fa.setFromMatrixPosition(W.matrixWorld),V=R.dot(Fa.subVectors(U,I).normalize()),0>=V||(V*=0==W.distance?1:1-Math.min(I.distanceTo(U)/W.distance,1),0!=V&&(V*=W.intensity,L.add(ca.multiplyScalar(V)))));Y.multiply(da).add(fa);!0===H.wireframe?b(Y,H.wireframeLinewidth,H.wireframeLinecap,H.wireframeLinejoin):c(Y)}else H instanceof THREE.MeshBasicMaterial||H instanceof THREE.MeshLambertMaterial||H instanceof THREE.MeshPhongMaterial?null!==H.map?H.map.mapping===THREE.UVMapping&&
(ha=J.uvs,a(M,S,Z,X,ja,ba,ha[0].x,ha[0].y,ha[1].x,ha[1].y,ha[2].x,ha[2].y,H.map)):null!==H.envMap?H.envMap.mapping===THREE.SphericalReflectionMapping&&(ea.copy(J.vertexNormalsModel[0]).applyMatrix3(Ba),ma=.5*ea.x+.5,oa=.5*ea.y+.5,ea.copy(J.vertexNormalsModel[1]).applyMatrix3(Ba),la=.5*ea.x+.5,na=.5*ea.y+.5,ea.copy(J.vertexNormalsModel[2]).applyMatrix3(Ba),va=.5*ea.x+.5,sa=.5*ea.y+.5,a(M,S,Z,X,ja,ba,ma,oa,la,na,va,sa,H.envMap)):(Y.copy(H.color),H.vertexColors===THREE.FaceColors&&Y.multiply(J.color),
!0===H.wireframe?b(Y,H.wireframeLinewidth,H.wireframeLinecap,H.wireframeLinejoin):c(Y)):(H instanceof THREE.MeshNormalMaterial?(ea.copy(J.normalModel).applyMatrix3(Ba),Y.setRGB(ea.x,ea.y,ea.z).multiplyScalar(.5).addScalar(.5)):Y.setRGB(1,1,1),!0===H.wireframe?b(Y,H.wireframeLinewidth,H.wireframeLinecap,H.wireframeLinejoin):c(Y))}}aa.union(pa)}}E.setTransform(1,0,0,1,0,0)}}};
THREE.SoftwareRenderer=function(g){function b(){for(var a=m*q*4,b=0;b<a;b+=4)B[b]=255*F.r|0,B[b+1]=255*F.g|0,B[b+2]=255*F.b|0,B[b+3]=255;p.fillStyle=F.getStyle();p.fillRect(0,0,m,q)}function c(a,b){var c=0,d=0,e=255*a.color.r,f=255*a.color.g,g=255*a.color.b,h=new Uint8Array(768);if(b){for(;204>c;)h[d++]=Math.min(c*e/204,255),h[d++]=Math.min(c*f/204,255),h[d++]=Math.min(c*g/204,255),++c;for(;256>c;)h[d++]=Math.min(e+(c-204)*(255-e)/82,255),h[d++]=Math.min(f+(c-204)*(255-f)/82,255),h[d++]=Math.min(g+
(c-204)*(255-g)/82,255),++c}else for(;256>c;)h[d++]=Math.min(c*e/255,255),h[d++]=Math.min(c*f/255,255),h[d++]=Math.min(c*g/255,255),++c;return h}function f(a,b,c,d,e,f,g,k,l){g=4*c;k=h[l.map.id];if(k.data){var m=k.width,n=m-1;k=k.data;e=4*((f*m&n)*m+(e*m&n));if(l.transparent){f=k[e+1];m=k[e+2];n=k[e+3]*l.opacity/255;var q=a[g+1],p=a[g+2];a[g]=k[e]*n+a[g]*(1-n);a[g+1]=f*n+q*(1-n);a[g+2]=m*n+p*(1-n);a[g+3]=(l.opacity<<8)-1;255==a[g+3]&&(b[c]=d)}else a[g]=k[e],a[g+1]=k[e+1],a[g+2]=k[e+2],a[g+3]=(l.opacity<<
8)-1,b[c]=d}}function a(a,b,c,d,e,f,g,k,l){k=4*c;var m=h[l.map.id];if(m.data){var n=m.width;g=3*(0<g?~~g:0);var q=n-1;m=m.data;e=4*((f*n&q)*n+(e*n&q));if(l.transparent){f=l.palette[g+1]*m[e+1];n=l.palette[g+2]*m[e+2];q=m[e+3]*l.opacity/256;var p=a[k+1],r=a[k+2];a[k]=l.palette[g]*m[e]*q+a[k]*(1-q);a[k+1]=f*q+p*(1-q);a[k+2]=n*q+r*(1-q);a[k+3]=(l.opacity<<8)-1;255==a[k+3]&&(b[c]=d)}else a[k]=l.palette[g]*m[e]>>8,a[k+1]=l.palette[g+1]*m[e+1]>>8,a[k+2]=l.palette[g+2]*m[e+2]>>8,a[k+3]=(l.opacity<<8)-1,
b[c]=d}}function e(a){a=a.target;a.removeEventListener("update",e);delete r[a.id]}function d(b){var d=b.id,g=r[d];g&&b.map&&!h[b.map.id]&&delete r[d];if(void 0===r[d]){b.addEventListener("update",e);if(b instanceof THREE.MeshBasicMaterial||b instanceof THREE.MeshLambertMaterial||b instanceof THREE.MeshPhongMaterial||b instanceof THREE.SpriteMaterial)if(b instanceof THREE.MeshLambertMaterial?b.palette||(b.palette=c(b,!1)):b instanceof THREE.MeshPhongMaterial&&!b.palette&&(b.palette=c(b,!0)),b.map){g=
new THREE.SoftwareRenderer.Texture;g.fromImage(b.map.image);if(!g.data)return;h[b.map.id]=g;g=b instanceof THREE.MeshBasicMaterial||b instanceof THREE.SpriteMaterial?f:a}else b=b.vertexColors===THREE.FaceColors?"var colorOffset = offset * 4;\nbuffer[ colorOffset ] = face.color.r * 255;\nbuffer[ colorOffset + 1 ] = face.color.g * 255;\nbuffer[ colorOffset + 2 ] = face.color.b * 255;\nbuffer[ colorOffset + 3 ] = material.opacity * 255;\ndepthBuf[ offset ] = depth;":"var colorOffset = offset * 4;\nbuffer[ colorOffset ] = material.color.r * 255;\nbuffer[ colorOffset + 1 ] = material.color.g * 255;\nbuffer[ colorOffset + 2 ] = material.color.b * 255;\nbuffer[ colorOffset + 3 ] = material.opacity * 255;\ndepthBuf[ offset ] = depth;",
g=new Function("buffer, depthBuf, offset, depth, u, v, n, face, material",b);else g=b instanceof THREE.LineBasicMaterial?new Function("buffer, depthBuf, offset, depth, color1, color2, material","var colorOffset = offset * 4;\nbuffer[ colorOffset ] = material.color.r * (color1.r+color2.r) * 0.5 * 255;\nbuffer[ colorOffset + 1 ] = material.color.g * (color1.g+color2.g) * 0.5 * 255;\nbuffer[ colorOffset + 2 ] = material.color.b * (color1.b+color2.b) * 0.5 * 255;\nbuffer[ colorOffset + 3 ] = 255;\ndepthBuf[ offset ] = depth;"):
new Function("buffer, depthBuf, offset, depth, u, v, n, face, material","var colorOffset = offset * 4;\nbuffer[ colorOffset ] = u * 255;\nbuffer[ colorOffset + 1 ] = v * 255;\nbuffer[ colorOffset + 2 ] = 0;\nbuffer[ colorOffset + 3 ] = 255;\ndepthBuf[ offset ] = depth;");r[d]=g}return g}function l(a,b,c,d,e,f,g,h,k){if(!(-1>a.z||1<a.z||-1>b.z||1<b.z||-1>c.z||1<c.z)){var p=a.x*w+C|0,r=b.x*w+C|0,u=c.x*w+C|0,G=a.y*v+x|0,F=b.y*v+x|0,M=c.y*v+x|0,O=h.vertexNormalsModel&&h.vertexNormalsModel.length,Y=d&&
e&&f,K=Math.max(Math.sqrt((p-r)*(p-r)+(G-F)*(G-F)),Math.sqrt((r-u)*(r-u)+(F-M)*(F-M)),Math.sqrt((u-p)*(u-p)+(M-G)*(M-G)));if(!(h instanceof THREE.RenderableSprite)&&1600<K){var L={vertexNormalsModel:[],color:h.color};if(Y){if(ma===ha.length){var N=new THREE.Vector2;ha.push(N);++ma;var T=new THREE.Vector2;ha.push(T);++ma;var X=new THREE.Vector2;ha.push(X)}else N=ha[ma],++ma,T=ha[ma],++ma,X=ha[ma];++ma;var Z=b.w/a.w*(1+b.z)/(1+a.z);N.copy(d).multiplyScalar(Z).add(e).multiplyScalar(1/(Z+1));Z=c.w/b.w*
(1+c.z)/(1+b.z);T.copy(e).multiplyScalar(Z).add(f).multiplyScalar(1/(Z+1));Z=a.w/c.w*(1+a.z)/(1+c.z);X.copy(f).multiplyScalar(Z).add(d).multiplyScalar(1/(Z+1))}if(fa===da.length){var Q=new THREE.Vector4;da.push(Q);++fa;var R=new THREE.Vector4;da.push(R);++fa;var S=new THREE.Vector4;da.push(S)}else Q=da[fa],++fa,R=da[fa],++fa,S=da[fa];++fa;Q.copy(a).add(b).multiplyScalar(.5);R.copy(b).add(c).multiplyScalar(.5);S.copy(c).add(a).multiplyScalar(.5);if(O){if(ka===ca.length){var ba=new THREE.Vector3;ca.push(ba);
++ka;var W=new THREE.Vector3;ca.push(W);++ka;var ia=new THREE.Vector3;ca.push(ia)}else ba=ca[ka],++ka,W=ca[ka],++ka,ia=ca[ka];++ka;ba.copy(h.vertexNormalsModel[0]).add(h.vertexNormalsModel[1]).normalize();W.copy(h.vertexNormalsModel[1]).add(h.vertexNormalsModel[2]).normalize();ia.copy(h.vertexNormalsModel[2]).add(h.vertexNormalsModel[0]).normalize()}O&&(L.vertexNormalsModel[0]=h.vertexNormalsModel[0],L.vertexNormalsModel[1]=ba,L.vertexNormalsModel[2]=ia);l(a,Q,S,d,N,X,g,L,k);O&&(L.vertexNormalsModel[0]=
h.vertexNormalsModel[1],L.vertexNormalsModel[1]=W,L.vertexNormalsModel[2]=ba);l(b,R,Q,e,T,N,g,L,k);O&&(L.vertexNormalsModel[0]=ba,L.vertexNormalsModel[1]=W,L.vertexNormalsModel[2]=ia);l(Q,R,S,N,T,X,g,L,k);O&&(L.vertexNormalsModel[0]=h.vertexNormalsModel[2],L.vertexNormalsModel[1]=ia,L.vertexNormalsModel[2]=W);l(c,S,R,f,X,T,g,L,k)}else{var aa=a.z*z+D|0,ja=b.z*z+D|0,na=c.z*z+D|0;Y=!1;if(d&&e&&f){Y=!0;var pa=d.x;var va=1-d.y;var oa=e.x;var sa=1-e.y;var la=f.x;var Sa=1-f.y}if(O){var qc=h.vertexNormalsModel[0];
var rc=h.vertexNormalsModel[1];var sc=h.vertexNormalsModel[2];var Rb=255*qc.z;var tc=255*rc.z;var uc=255*sc.z}var xa=p-r,ua=F-G,La=r-u,Ha=M-F,Aa=u-p,ya=G-M,$a=Math.max(Math.min(p,r,u)+15>>4,0),Sb=Math.min(Math.max(p,r,u)+15>>4,m),Eb=Math.max(Math.min(G,F,M)+15>>4,0),ac=Math.min(Math.max(G,F,M)+15>>4,q);y=Math.min($a,y);V=Math.max(Sb,V);J=Math.min(Eb,J);U=Math.max(ac,U);var ra=A;$a&=~(ra-1);Eb&=~(ra-1);var Wa=$a<<4,Xa=Eb<<4,Fb=ua*(Wa-p)+xa*(Xa-G),Gb=Ha*(Wa-r)+La*(Xa-F),Hb=ya*(Wa-u)+Aa*(Xa-M);(0<ua||
0==ua&&0<xa)&&Fb++;(0<Ha||0==Ha&&0<La)&&Gb++;(0<ya||0==ya&&0<Aa)&&Hb++;Fb=Fb-1>>4;Gb=Gb-1>>4;Hb=Hb-1>>4;var bc=aa-ja,cc=na-aa,Na=1/(xa*ya-Aa*ua),Ja=Na*(bc*ya-cc*ua),Ka=Na*(bc*Aa-xa*cc),vc=aa+(Wa-p)*Ja+(Xa-G)*Ka|0;Ja=16*Ja|0;Ka=16*Ka|0;if(Y){var dc=pa-oa,ec=la-pa,fb=Na*(dc*ya-ec*ua),gb=Na*(dc*Aa-xa*ec),fc=va-sa,gc=Sa-va;var hb=Na*(fc*ya-gc*ua);var ib=Na*(fc*Aa-xa*gc);var jb=pa+(Wa-p)*fb+(Xa-G)*gb;var kb=va+(Wa-p)*hb+(Xa-G)*ib;fb*=16;gb*=16;hb*=16;ib*=16}if(O){var hc=Rb-tc,ic=uc-Rb,lb=Na*(hc*ya-ic*
ua);var mb=Na*(hc*Aa-xa*ic);var nb=Rb+(Wa-p)*lb+(Xa-G)*mb;lb*=16;mb*=16}var ta=ra-1,Tb=0,Ib=0,Ub=0,Jb=0,Vb=0,Kb=0,Wb=0,Xb=0;0<=xa?Ib-=ta*xa:Tb-=ta*xa;0<=ua?Ib-=ta*ua:Tb-=ta*ua;0<=La?Jb-=ta*La:Ub-=ta*La;0<=Ha?Jb-=ta*Ha:Ub-=ta*Ha;0<=Aa?Kb-=ta*Aa:Vb-=ta*Aa;0<=ya?Kb-=ta*ya:Vb-=ta*ya;0<=Ja?Xb+=ta*Ja:Wb+=ta*Ja;0<=Ka?Xb+=ta*Ka:Wb+=ta*Ka;var jc=m-ra,Oa=Fb,Pa=Gb,Ya=Hb,Za=vc,Ga=-ra,ob=Ga*ua,pb=Ga*Ha,qb=Ga*ya,Lb=Ga*Ja;if(Y){var Mb=Ga*fb;var Nb=Ga*hb}var rb;O&&(rb=Ga*lb);for(var Qa=$a,Ob=Eb;Ob<ac;Ob+=ra){for(;Qa>=
$a&&Qa<Sb&&Oa>=Ib&&Pa>=Jb&&Ya>=Kb;)Qa+=Ga,Oa+=ob,Pa+=pb,Ya+=qb,Za+=Lb,Y&&(jb+=Mb,kb+=Nb),O&&(nb+=rb);Ga=-Ga;ob=-ob;pb=-pb;qb=-qb;Lb=-Lb;Y&&(Mb=-Mb,Nb=-Nb);for(O&&(rb=-rb);;){Qa+=Ga;Oa+=ob;Pa+=pb;Ya+=qb;Za+=Lb;Y&&(jb+=Mb,kb+=Nb);O&&(nb+=rb);if(Qa<$a||Qa>=Sb)break;if(Oa<Ib)if(0>ob)break;else continue;if(Pa<Jb)if(0>pb)break;else continue;if(Ya<Kb)if(0>qb)break;else continue;var kc=Qa>>I,lc=Ob>>I,sb=kc+lc*t;if(!(H[sb]<Za+Wb)){var mc=E[sb];mc&2&&n(kc,lc);E[sb]=mc&-4;var Ra=Qa+Ob*m;if(Oa>=Tb&&Pa>=Ub&&Ya>=
Vb){H[sb]=Math.min(H[sb],Za+Xb);var tb=Oa,ub=Pa,vb=Za;if(Y){var wb=jb;var xb=kb}var bb;O&&(bb=nb);for(var yb=0;yb<ra;yb++){var Pb=tb,Qb=ub,zb=vb;if(Y){var Ab=wb;var Bb=xb}var cb;O&&(cb=bb);for(var Cb=0;Cb<ra;Cb++){var Db=zb;Db<P[Ra]&&g(B,P,Ra,Db,Ab,Bb,cb,h,k);Pb+=ua;Qb+=Ha;zb+=Ja;Y&&(Ab+=fb,Bb+=hb);O&&(cb+=lb);Ra++}tb+=xa;ub+=La;vb+=Ka;Y&&(wb+=gb,xb+=ib);O&&(bb+=mb);Ra+=jc}}else{tb=Oa;ub=Pa;var nc=Ya;vb=Za;Y&&(wb=jb,xb=kb);O&&(bb=nb);for(yb=0;yb<ra;yb++){Pb=tb;Qb=ub;var oc=nc;zb=vb;Y&&(Ab=wb,Bb=xb);
O&&(cb=bb);for(Cb=0;Cb<ra;Cb++)0<=(Pb|Qb|oc)&&(Db=zb,Db<P[Ra]&&g(B,P,Ra,Db,Ab,Bb,cb,h,k)),Pb+=ua,Qb+=Ha,oc+=ya,zb+=Ja,Y&&(Ab+=fb,Bb+=hb),O&&(cb+=lb),Ra++;tb+=xa;ub+=La;nc+=Aa;vb+=Ka;Y&&(wb+=gb,xb+=ib);O&&(bb+=mb);Ra+=jc}}}}Oa+=ra*xa;Pa+=ra*La;Ya+=ra*Aa;Za+=ra*Ka;Y&&(jb+=ra*gb,kb+=ra*ib);O&&(nb+=ra*mb)}}}}function n(a,b){for(var c=a*A+b*A*m,d=4*c,e=m-A,f=4*e,g=0;g<A;g++){for(var h=0;h<A;h++)P[c++]=16777216,B[d++]=255*F.r|0,B[d++]=255*F.g|0,B[d++]=255*F.b|0,B[d++]=255;c+=e;d+=f}}console.log("THREE.SoftwareRenderer",
THREE.REVISION);g=g||{};var k=void 0!==g.canvas?g.canvas:document.createElement("canvas"),p=k.getContext("2d",{alpha:!0===g.alpha}),r={},h={},m,q,t,u,w,v,z,C,x,D,F=new THREE.Color(0),K,B,P,Q,H,E,I=3,A=1<<I,N=!1,L=new THREE.Vector3(0,0,1),W=new THREE.Vector3,y=Infinity,J=Infinity,V=0,U=0,R=Infinity,G=Infinity,O=0,T=0,M=new THREE.Projector,S=new THREE.Vector4,Z=new THREE.Vector4,X=new THREE.Vector4,ja=new THREE.Vector2,ba=new THREE.Vector2,Y=new THREE.Vector2,da=[],fa=0,ca=[],ka=0,ha=[],ma=0;this.domElement=
k;this.autoClear=!0;this.supportsVertexTextures=function(){};this.setFaceCulling=function(){};this.setClearColor=function(a,c){F.set(a);b()};this.setPixelRatio=function(){};this.setSize=function(a,c){t=Math.floor(a/A);u=Math.floor(c/A);m=t*A;q=u*A;w=16*m/2;v=-16*q/2;z=8388608;C=16*m/2+.5;x=16*q/2+.5;D=8388608.5;k.width=m;k.height=q;p.fillStyle=F.getStyle();p.fillRect(0,0,m,q);K=p.getImageData(0,0,m,q);B=K.data;P=new Int32Array(B.length/4);Q=t*u;H=new Int32Array(Q);E=new Uint8Array(Q);for(var d=0,
e=P.length;d<e;d++)P[d]=16777216;for(d=0;d<Q;d++)E[d]=1;b()};this.setSize(k.width,k.height);this.clear=function(){J=y=Infinity;for(var a=ma=ka=fa=U=V=0;a<Q;a++)H[a]=16777216,E[a]=E[a]&1?1:2};this.render=function(a,c){!0===this.autoClear&&this.clear();for(var e=M.projectScene(a,c,!1,!1).elements,f=0,g=e.length;f<g;f++){var h=e[f],r=h.material,da=d(r);if(da)if(h instanceof THREE.RenderableFace)h.uvs?l(h.v1.positionScreen,h.v2.positionScreen,h.v3.positionScreen,h.uvs[0],h.uvs[1],h.uvs[2],da,h,r):l(h.v1.positionScreen,
h.v2.positionScreen,h.v3.positionScreen,null,null,null,da,h,r);else if(h instanceof THREE.RenderableSprite){var fa=.5*h.scale.x,ca=.5*h.scale.y;S.copy(h);S.x-=fa;S.y+=ca;Z.copy(h);Z.x-=fa;Z.y-=ca;X.copy(h);X.x+=fa;X.y+=ca;r.map?(ja.set(0,1),ba.set(0,0),Y.set(1,1),l(S,Z,X,ja,ba,Y,da,h,r)):l(S,Z,X,null,null,null,da,h,r);S.copy(h);S.x+=fa;S.y+=ca;Z.copy(h);Z.x-=fa;Z.y-=ca;X.copy(h);X.x+=fa;X.y-=ca;r.map?(ja.set(1,1),ba.set(0,0),Y.set(1,0),l(S,Z,X,ja,ba,Y,da,h,r)):l(S,Z,X,null,null,null,da,h,r)}else if(h instanceof
THREE.RenderableLine){da=d(r);var ka=h.v1.positionScreen,ha=h.v2.positionScreen;fa=h.vertexColors[0];h=h.vertexColors[1];if(!N){N=!0;I=0;A=1<<I;ca=k.height;t=Math.floor(k.width/A);u=Math.floor(ca/A);m=t*A;q=u*A;w=16*m/2;v=-16*q/2;z=8388608;C=16*m/2+.5;x=16*q/2+.5;D=8388608.5;k.width=m;k.height=q;p.fillStyle=F.getStyle();p.fillRect(0,0,m,q);K=p.getImageData(0,0,m,q);B=K.data;P=new Int32Array(B.length/4);Q=t*u;H=new Int32Array(Q);E=new Uint8Array(Q);ca=0;for(var ma=P.length;ca<ma;ca++)P[ca]=16777216;
for(ca=0;ca<Q;ca++)E[ca]=1;b()}if(!(-1>ka.z||1<ka.z||-1>ha.z||1<ha.z)){ca=Math.floor(.5*(r.linewidth-1));var ea=ka.x*w+C|0;ma=ha.x*w+C|0;var la=ka.y*v+x|0,oa=ha.y*v+x|0;var qa=ka.z*z+D|0;ha=ha.z*z+D|0;var Ia=ea-ma,Ma=la-oa;var Ca=Math.min(Math.max(ea,ma)+15>>4,m);var Da=Math.max(Math.min(la,oa)+15>>4,0);var za=Math.min(Math.max(la,oa)+15>>4,q);ka=Math.max(Math.min(qa,ha)+15>>4,0);la=Math.max(qa,ha)+15>>4;y=Math.min(Math.max(Math.min(ea,ma)+15>>4,0),y);V=Math.max(Ca,V);J=Math.min(Da,J);U=Math.max(za,
U);ea=Math.sqrt(Ma*Ma+Ia*Ia);Ia/=ea;Ma/=ea;Da=(qa-ha)/ea;W.set(Ia,Ma,Da);W.cross(L);for(W.normalize();0<ea;){Ca=ma+ea*Ia;qa=oa+ea*Ma;za=ha+ea*Da;Ca=Ca+15>>4;qa=qa+15>>4;za=za+15>>4;for(var Va=-ca;Va<=ca;++Va){var Ea=Math.floor(Ca+W.x*Va);var wa=Math.floor(qa+W.y*Va);if(!(y>=Ea||V<=Ea||J>=wa||U<=wa)){var Yb=Ea>>I,Zb=wa>>I,db=Yb+Zb*t;if(!(H[db]<ka)){H[db]=Math.min(H[db],la);var $b=E[db];$b&2&&n(Yb,Zb);E[db]=$b&-4;wa=Ea+wa*m;za<P[wa]&&da(B,P,wa,za,fa,h,r)}}}--ea}}}}for(f=e=0;f<u;f++)for(g=0;g<t;g++)E[e]&
2&&(n(g,f),E[e]=1),e++;e=Math.min(y,R);f=Math.min(J,G);g=Math.max(V,O)-e;fa=Math.max(U,T)-f;Infinity!==e&&p.putImageData(K,0,0,e,f,g,fa);R=y;G=J;O=V;T=U}};
THREE.SoftwareRenderer.Texture=function(){var g;this.fromImage=function(b){if(!(!b||0>=b.width||0>=b.height)){void 0===g&&(g=document.createElement("canvas"));var c=b.width>b.height?b.width:b.height;c=THREE.Math.nextPowerOfTwo(c);if(g.width!=c||g.height!=c)g.width=c,g.height=c;var f=g.getContext("2d");f.clearRect(0,0,c,c);f.drawImage(b,0,0,c,c);this.data=f.getImageData(0,0,c,c).data;this.height=this.width=c;this.srcUrl=b.src}}};
THREE.RenderableObject=function(){this.id=0;this.object=null;this.renderOrder=this.z=0};
THREE.RenderableFace=function(){this.id=0;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.v3=new THREE.RenderableVertex;this.normalModel=new THREE.Vector3;this.vertexNormalsModel=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.vertexNormalsLength=0;this.color=new THREE.Color;this.material=null;this.uvs=[new THREE.Vector2,new THREE.Vector2,new THREE.Vector2];this.renderOrder=this.z=0};
THREE.RenderableVertex=function(){this.position=new THREE.Vector3;this.positionWorld=new THREE.Vector3;this.positionScreen=new THREE.Vector4;this.visible=!0};THREE.RenderableVertex.prototype.copy=function(g){this.positionWorld.copy(g.positionWorld);this.positionScreen.copy(g.positionScreen)};THREE.RenderableLine=function(){this.id=0;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.vertexColors=[new THREE.Color,new THREE.Color];this.material=null;this.renderOrder=this.z=0};
THREE.RenderableSprite=function(){this.id=0;this.object=null;this.rotation=this.z=this.y=this.x=0;this.scale=new THREE.Vector2;this.material=null;this.renderOrder=0};
THREE.Projector=function(){function g(){if(r===m){var a=new THREE.RenderableVertex;h.push(a);m++;r++;return a}return h[r++]}function b(){if(t===w){var a=new THREE.RenderableFace;u.push(a);w++;t++;return a}return u[t++]}function c(){if(z===x){var a=new THREE.RenderableLine;C.push(a);x++;z++;return a}return C[z++]}function f(){if(F===B){var a=new THREE.RenderableSprite;K.push(a);B++;F++;return a}return K[F++]}function a(a,b){return a.renderOrder!==b.renderOrder?a.renderOrder-b.renderOrder:a.z!==b.z?
b.z-a.z:a.id!==b.id?a.id-b.id:0}function e(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;if(0<=e&&0<=f&&0<=g&&0<=h)return!0;if(0>e&&0>f||0>g&&0>h)return!1;0>e?c=Math.max(c,e/(e-f)):0>f&&(d=Math.min(d,e/(e-f)));0>g?c=Math.max(c,g/(g-h)):0>h&&(d=Math.min(d,g/(g-h)));if(d<c)return!1;a.lerp(b,c);b.lerp(a,1-d);return!0}var d,l,n=[],k=0,p,r,h=[],m=0,q,t,u=[],w=0,v,z,C=[],x=0,D,F,K=[],B=0,P={objects:[],lights:[],elements:[]},Q=new THREE.Vector3,H=new THREE.Vector4,E=new THREE.Box3(new THREE.Vector3(-1,
-1,-1),new THREE.Vector3(1,1,1)),I=new THREE.Box3,A=Array(3),N=new THREE.Matrix4,L=new THREE.Matrix4,W,y=new THREE.Matrix4,J=new THREE.Matrix3,V=new THREE.Frustum,U=new THREE.Vector4,R=new THREE.Vector4;this.projectVector=function(a,b){console.warn("THREE.Projector: .projectVector() is now vector.project().");a.project(b)};this.unprojectVector=function(a,b){console.warn("THREE.Projector: .unprojectVector() is now vector.unproject().");a.unproject(b)};this.pickingRay=function(a,b){console.error("THREE.Projector: .pickingRay() is now raycaster.setFromCamera().")};
var G=new function(){function a(a){var b=a.positionWorld,c=a.positionScreen;b.copy(a.position).applyMatrix4(W);c.copy(b).applyMatrix4(L);b=1/c.w;c.x*=b;c.y*=b;c.z*=b;a.visible=-1<=c.x&&1>=c.x&&-1<=c.y&&1>=c.y&&-1<=c.z&&1>=c.z}function d(a,b,c){if(!0===a.visible||!0===b.visible||!0===c.visible)return!0;A[0]=a.positionScreen;A[1]=b.positionScreen;A[2]=c.positionScreen;return E.intersectsBox(I.setFromPoints(A))}function e(a,b,c){return 0>(c.positionScreen.x-a.positionScreen.x)*(b.positionScreen.y-a.positionScreen.y)-
(c.positionScreen.y-a.positionScreen.y)*(b.positionScreen.x-a.positionScreen.x)}var f=[],k=[],l=null,m=null,n=new THREE.Matrix3;return{setObject:function(a){l=a;m=l.material;n.getNormalMatrix(l.matrixWorld);f.length=0;k.length=0},projectVertex:a,checkTriangleVisibility:d,checkBackfaceCulling:e,pushVertex:function(b,c,d){p=g();p.position.set(b,c,d);a(p)},pushNormal:function(a,b,c){f.push(a,b,c)},pushUv:function(a,b){k.push(a,b)},pushLine:function(a,b){var d=h[a],e=h[b];v=c();v.id=l.id;v.v1.copy(d);
v.v2.copy(e);v.z=(d.positionScreen.z+e.positionScreen.z)/2;v.renderOrder=l.renderOrder;v.material=l.material;P.elements.push(v)},pushTriangle:function(a,c,g){var p=h[a],r=h[c],t=h[g];if(!1!==d(p,r,t)&&(m.side===THREE.DoubleSide||!0===e(p,r,t))){q=b();q.id=l.id;q.v1.copy(p);q.v2.copy(r);q.v3.copy(t);q.z=(p.positionScreen.z+r.positionScreen.z+t.positionScreen.z)/3;q.renderOrder=l.renderOrder;q.normalModel.fromArray(f,3*a);q.normalModel.applyMatrix3(n).normalize();for(p=0;3>p;p++)r=q.vertexNormalsModel[p],
r.fromArray(f,3*arguments[p]),r.applyMatrix3(n).normalize(),q.uvs[p].fromArray(k,2*arguments[p]);q.vertexNormalsLength=3;q.material=l.material;P.elements.push(q)}}}};this.projectScene=function(m,p,u,x){F=z=t=0;P.elements.length=0;!0===m.autoUpdate&&m.updateMatrixWorld();null===p.parent&&p.updateMatrixWorld();N.copy(p.matrixWorldInverse.getInverse(p.matrixWorld));L.multiplyMatrices(p.projectionMatrix,N);V.setFromMatrix(L);l=0;P.objects.length=0;P.lights.length=0;m.traverseVisible(function(a){if(a instanceof
THREE.Light)P.lights.push(a);else if((a instanceof THREE.Mesh||a instanceof THREE.Line||a instanceof THREE.Sprite)&&!1!==a.material.visible&&(!1===a.frustumCulled||!0===V.intersectsObject(a))){if(l===k){var b=new THREE.RenderableObject;n.push(b);k++;l++;d=b}else d=n[l++];d.id=a.id;d.object=a;Q.setFromMatrixPosition(a.matrixWorld);Q.applyProjection(L);d.z=Q.z;d.renderOrder=a.renderOrder;P.objects.push(d)}});!0===u&&P.objects.sort(a);m=0;for(u=P.objects.length;m<u;m++){var w=P.objects[m].object,A=w.geometry;
G.setObject(w);W=w.matrixWorld;r=0;if(w instanceof THREE.Mesh)if(A instanceof THREE.BufferGeometry){var C=A.attributes;w=A.groups;if(void 0!==C.position){for(var B=C.position.array,E=0,I=B.length;E<I;E+=3)G.pushVertex(B[E],B[E+1],B[E+2]);if(void 0!==C.normal){var M=C.normal.array;E=0;for(I=M.length;E<I;E+=3)G.pushNormal(M[E],M[E+1],M[E+2])}if(void 0!==C.uv)for(C=C.uv.array,E=0,I=C.length;E<I;E+=2)G.pushUv(C[E],C[E+1]);if(null!==A.index)if(B=A.index.array,0<w.length)for(m=0;m<w.length;m++)for(I=w[m],
E=I.start,I=I.start+I.count;E<I;E+=3)G.pushTriangle(B[E],B[E+1],B[E+2]);else for(E=0,I=B.length;E<I;E+=3)G.pushTriangle(B[E],B[E+1],B[E+2]);else for(E=0,I=B.length/3;E<I;E+=3)G.pushTriangle(E,E+1,E+2)}}else{if(A instanceof THREE.Geometry){var K=A.vertices;E=A.faces;I=A.faceVertexUvs[0];J.getNormalMatrix(W);B=w.material;C=B instanceof THREE.MultiMaterial;M=!0===C?w.material:null;for(var O=0,S=K.length;O<S;O++){var T=K[O];Q.copy(T);if(!0===B.morphTargets)for(var oa=A.morphTargets,la=w.morphTargetInfluences,
na=0,va=oa.length;na<va;na++){var sa=la[na];if(0!==sa){var ia=oa[na].vertices[O];Q.x+=(ia.x-T.x)*sa;Q.y+=(ia.y-T.y)*sa;Q.z+=(ia.z-T.z)*sa}}G.pushVertex(Q.x,Q.y,Q.z)}K=0;for(O=E.length;K<O;K++)if(S=E[K],B=!0===C?M.materials[S.materialIndex]:w.material,void 0!==B&&(la=B.side,A=h[S.a],T=h[S.b],oa=h[S.c],!1!==G.checkTriangleVisibility(A,T,oa))){na=G.checkBackfaceCulling(A,T,oa);if(la!==THREE.DoubleSide){if(la===THREE.FrontSide&&!1===na)continue;if(la===THREE.BackSide&&!0===na)continue}q=b();q.id=w.id;
q.v1.copy(A);q.v2.copy(T);q.v3.copy(oa);q.normalModel.copy(S.normal);!1!==na||la!==THREE.BackSide&&la!==THREE.DoubleSide||q.normalModel.negate();q.normalModel.applyMatrix3(J).normalize();va=S.vertexNormals;sa=0;for(ia=Math.min(va.length,3);sa<ia;sa++){var aa=q.vertexNormalsModel[sa];aa.copy(va[sa]);!1!==na||la!==THREE.BackSide&&la!==THREE.DoubleSide||aa.negate();aa.applyMatrix3(J).normalize()}q.vertexNormalsLength=va.length;la=I[K];if(void 0!==la)for(na=0;3>na;na++)q.uvs[na].copy(la[na]);q.color=
S.color;q.material=B;q.z=(A.positionScreen.z+T.positionScreen.z+oa.positionScreen.z)/3;q.renderOrder=w.renderOrder;P.elements.push(q)}}}else if(w instanceof THREE.Line)if(A instanceof THREE.BufferGeometry){if(C=A.attributes,void 0!==C.position){B=C.position.array;E=0;for(I=B.length;E<I;E+=3)G.pushVertex(B[E],B[E+1],B[E+2]);if(null!==A.index)for(B=A.index.array,E=0,I=B.length;E<I;E+=2)G.pushLine(B[E],B[E+1]);else for(C=w instanceof THREE.LineSegments?2:1,E=0,I=B.length/3-1;E<I;E+=C)G.pushLine(E,E+
1)}}else{if(A instanceof THREE.Geometry&&(y.multiplyMatrices(L,W),K=w.geometry.vertices,0!==K.length))for(A=g(),A.positionScreen.copy(K[0]).applyMatrix4(y),C=w instanceof THREE.LineSegments?2:1,O=1,S=K.length;O<S;O++)A=g(),A.positionScreen.copy(K[O]).applyMatrix4(y),0<(O+1)%C||(T=h[r-2],U.copy(A.positionScreen),R.copy(T.positionScreen),!0===e(U,R)&&(U.multiplyScalar(1/U.w),R.multiplyScalar(1/R.w),v=c(),v.id=w.id,v.v1.positionScreen.copy(U),v.v2.positionScreen.copy(R),v.z=Math.max(U.z,R.z),v.renderOrder=
w.renderOrder,v.material=w.material,w.material.vertexColors===THREE.VertexColors&&(v.vertexColors[0].copy(w.geometry.colors[O]),v.vertexColors[1].copy(w.geometry.colors[O-1])),P.elements.push(v)))}else w instanceof THREE.Sprite&&(H.set(W.elements[12],W.elements[13],W.elements[14],1),H.applyMatrix4(L),E=1/H.w,H.z*=E,-1<=H.z&&1>=H.z&&(D=f(),D.id=w.id,D.x=H.x*E,D.y=H.y*E,D.z=H.z,D.renderOrder=w.renderOrder,D.object=w,D.rotation=w.rotation,D.scale.x=w.scale.x*Math.abs(D.x-(H.x+p.projectionMatrix.elements[0])/
(H.w+p.projectionMatrix.elements[12])),D.scale.y=w.scale.y*Math.abs(D.y-(H.y+p.projectionMatrix.elements[5])/(H.w+p.projectionMatrix.elements[13])),D.material=w.material,P.elements.push(D)))}!0===x&&P.elements.sort(a);return P}};THREE.OBJLoader=function(g){this.manager=void 0!==g?g:THREE.DefaultLoadingManager;this.materials=null};
THREE.OBJLoader.prototype={constructor:THREE.OBJLoader,load:function(g,b,c,f){var a=this,e=new THREE.XHRLoader(a.manager);e.setPath(this.path);e.load(g,function(c){b(a.parse(c))},c,f)},setPath:function(g){this.path=g},setMaterials:function(g){this.materials=g},parse:function(g){function b(a){P={name:a,geometry:{vertices:[],normals:[],uvs:[]},material:{name:"",smooth:!0}};k.push(P)}function c(a){a=parseInt(a);return 3*(0<=a?a-1:a+r.length/3)}function f(a){a=parseInt(a);return 3*(0<=a?a-1:a+h.length/
3)}function a(a){a=parseInt(a);return 2*(0<=a?a-1:a+m.length/2)}function e(a,b,c){P.geometry.vertices.push(r[a],r[a+1],r[a+2],r[b],r[b+1],r[b+2],r[c],r[c+1],r[c+2])}function d(a,b,c){P.geometry.normals.push(h[a],h[a+1],h[a+2],h[b],h[b+1],h[b+2],h[c],h[c+1],h[c+2])}function l(a,b,c){P.geometry.uvs.push(m[a],m[a+1],m[b],m[b+1],m[c],m[c+1])}function n(b,g,h,k,m,n,p,q,r,t,u,v){b=c(b);g=c(g);h=c(h);if(void 0===k)e(b,g,h);else{var w=c(k);e(b,g,w);e(g,h,w)}void 0!==m&&(b=a(m),g=a(n),h=a(p),void 0===k?l(b,
g,h):(w=a(q),l(b,g,w),l(g,h,w)));void 0!==r&&(b=f(r),g=f(t),h=f(u),void 0===k?d(b,g,h):(w=f(v),d(b,g,w),d(g,h,w)))}console.time("OBJLoader");var k=[],p=!1,r=[],h=[],m=[];b("");var q=/^v\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,t=/^vn\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,u=/^vt\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,w=/^f\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)(?:\s+(-?\d+))?/,v=/^f\s+((-?\d+)\/(-?\d+))\s+((-?\d+)\/(-?\d+))\s+((-?\d+)\/(-?\d+))(?:\s+((-?\d+)\/(-?\d+)))?/,
z=/^f\s+((-?\d+)\/(-?\d+)\/(-?\d+))\s+((-?\d+)\/(-?\d+)\/(-?\d+))\s+((-?\d+)\/(-?\d+)\/(-?\d+))(?:\s+((-?\d+)\/(-?\d+)\/(-?\d+)))?/,C=/^f\s+((-?\d+)\/\/(-?\d+))\s+((-?\d+)\/\/(-?\d+))\s+((-?\d+)\/\/(-?\d+))(?:\s+((-?\d+)\/\/(-?\d+)))?/,x=/^[og]\s*(.+)?/,D=/^s\s+(\d+|on|off)/,F=g.split("\n");for(g=0;g<F.length;g++){var K=F[g];K=K.trim();var B;if(0!==K.length&&"#"!==K.charAt(0))if(null!==(B=q.exec(K)))r.push(parseFloat(B[1]),parseFloat(B[2]),parseFloat(B[3]));else if(null!==(B=t.exec(K)))h.push(parseFloat(B[1]),
parseFloat(B[2]),parseFloat(B[3]));else if(null!==(B=u.exec(K)))m.push(parseFloat(B[1]),parseFloat(B[2]));else if(null!==(B=w.exec(K)))n(B[1],B[2],B[3],B[4]);else if(null!==(B=v.exec(K)))n(B[2],B[5],B[8],B[11],B[3],B[6],B[9],B[12]);else if(null!==(B=z.exec(K)))n(B[2],B[6],B[10],B[14],B[3],B[7],B[11],B[15],B[4],B[8],B[12],B[16]);else if(null!==(B=C.exec(K)))n(B[2],B[5],B[8],B[11],void 0,void 0,void 0,void 0,B[3],B[6],B[9],B[12]);else if(null!==(B=x.exec(K)))K=B[0].substr(1).trim(),!1===p?(p=!0,P.name=
K):b(K);else if(/^usemtl /.test(K))P.material.name=K.substring(7).trim();else if(!/^mtllib /.test(K))if(null!==(B=D.exec(K)))P.material.smooth="1"===B[1]||"on"===B[1];else throw Error("Unexpected line: "+K);}p=new THREE.Group;g=0;for(q=k.length;g<q;g++){var P=k[g];t=P.geometry;u=new THREE.BufferGeometry;u.addAttribute("position",new THREE.BufferAttribute(new Float32Array(t.vertices),3));0<t.normals.length?u.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(t.normals),3)):u.computeVertexNormals();
0<t.uvs.length&&u.addAttribute("uv",new THREE.BufferAttribute(new Float32Array(t.uvs),2));var Q;null!==this.materials&&(Q=this.materials.create(P.material.name));Q||(Q=new THREE.MeshPhongMaterial,Q.name=P.material.name);Q.shading=P.material.smooth?THREE.SmoothShading:THREE.FlatShading;t=new THREE.Mesh(u,Q);t.name=P.name;p.add(t)}console.timeEnd("OBJLoader");return p}};
function CVector2(g,b){var c,f;this._init=function(a,b){c=a;f=b};this.add=function(a,b){c+=a;f+=b};this.addV=function(a){c+=a.getX();f+=a.getY()};this.scalarDivision=function(a){c/=a;f/=a};this.subV=function(a){c-=a.getX();f-=a.getY()};this.scalarProduct=function(a){c*=a;f*=a};this.invert=function(){c*=-1;f*=-1};this.dotProduct=function(a){return c*a.getX()+f*a.getY()};this.set=function(a,b){c=a;f=b};this.setV=function(a){c=a.getX();f=a.getY()};this.length=function(){return Math.sqrt(c*c+f*f)};this.length2=
function(){return c*c+f*f};this.normalize=function(){var a=this.length();0<a&&(c/=a,f/=a)};this.distance=function(a){var b=c-a.x;a=f-a.y;return Math.sqrt(b*b+a*a)};this.angleBetweenVectors=function(a){a=Math.acos(this.dotProduct(a)/(this.length()*a.length()));return!0===isNaN(a)?0:a};this.getNormalize=function(a){this.length();a.set(c,f);a.normalize()};this.rot90CCW=function(){var a=c;c=-f;f=a};this.rot90CW=function(){var a=c;c=f;f=-a};this.getRotCCW=function(a){a.set(c,f);a.rot90CCW()};this.getRotCW=
function(a){a.set(c,f);a.rot90CW()};this.ceil=function(){c=Math.ceil(c);f=Math.ceil(f)};this.round=function(){c=Math.round(c);f=Math.round(f)};this.toString=function(){return"Vector2: "+c+", "+f};this.print=function(){trace("Vector2: "+c+", "+f)};this.getX=function(){return c};this.getY=function(){return f};this.rotate=function(a){var b=c,d=f;c=b*Math.cos(a)+d*Math.sin(a);f=b*-Math.sin(a)+d*Math.cos(a)};this._init(g,b)}
function CBackground(g,b){var c,f,a,e,d,l,n;this._init=function(b,c){a=new createjs.Container;c.addChild(a);e={width:3*CANVAS_WIDTH,height:3*CANVAS_HEIGHT};for(var f=b+1,g=0,k=0,p=0;18>p;p++){var t=s_oSpriteLibrary.getSprite("level_"+f+"_bg_"+p),u=createBitmap(t);g+=t.width;0===p%6&&(g=0,0!==p&&(k+=t.height));u.x=g;u.y=k;a.addChild(u)}a.regX=2400;a.regY=1452;null!==CAUSTICS_POS[b]&&(t=s_oSpriteLibrary.getSprite("caustics"),f=t.width/5,g=t.height/2,t=new createjs.SpriteSheet({framerate:FPS/3,images:[t],
frames:{width:f,height:g,regX:f/2,regY:g/2},animations:{idle:[0,9]}}),t=createSprite(t,"idle",f/2,g/2,f,g),t.x=CAUSTICS_POS[b].x+2400,t.y=CAUSTICS_POS[b].y+1452,t.scaleX=t.scaleY=CAUSTICS_POS[b].scale,a.addChild(t));d=a.on("mousedown",this._startPan);l=a.on("pressmove",this._movePan);n=a.on("pressup",this._endPan)};this.unload=function(){a.off("mousedown",d);a.off("pressmove",l);a.off("pressup",n);b.removeChild(a)};this._startPan=function(a){c=a.stageX;f=a.stageY;s_oInterface.setCenterBallViewVisible(!0)};
this._movePan=function(a){var b=a.stageX;a=a.stageY;var d=2*(b-c),e=2*(a-f);c=b;f=a;s_oGame.setPanPoint(d,e)};this._endPan=function(a){};this.setPos=function(b,c){a.x=b;a.y=c};this.getPos=function(){return{x:a.x,y:a.y}};this.getSize=function(){return e};this._init(g,b)}
function CMsgBox(g,b){var c,f,a,e;this._init=function(b){e=new createjs.Container;l.addChild(e);var d=new createjs.Shape;d.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);d.alpha=.5;d.on("click",function(){});e.addChild(d);d=s_oSpriteLibrary.getSprite("msg_box");var g=createBitmap(d);g.x=.5*CANVAS_WIDTH;g.y=.5*CANVAS_HEIGHT;g.regX=.5*d.width;g.regY=.5*d.height;e.addChild(g);c=new createjs.Text(b,"23px "+PRIMARY_FONT,"#000");c.x=CANVAS_WIDTH/2;c.y=260;c.textAlign="center";c.textBaseline=
"middle";c.lineWidth=790;c.outline=2;e.addChild(c);f=new createjs.Text(c.text,"23px "+PRIMARY_FONT,"#ffd800");f.x=c.x;f.y=c.y;f.textAlign="center";f.textBaseline="middle";f.lineWidth=790;e.addChild(f);a=new CGfxButton(CANVAS_WIDTH/2,650,s_oSpriteLibrary.getSprite("but_yes"),e);a.addEventListener(ON_MOUSE_UP,this._onButOk,this)};this._onButOk=function(){d.unload()};this.unload=function(){a.unload();l.removeChild(e)};var d=this;var l=b;this._init(g)}
function extractHostname(g){g=-1<g.indexOf("://")?g.split("/")[2]:g.split("/")[0];g=g.split(":")[0];return g=g.split("?")[0]}function extractRootDomain(g){g=extractHostname(g);var b=g.split("."),c=b.length;2<c&&(g=b[c-2]+"."+b[c-1]);return g}
var getClosestTop=function(){var g=window,b=!1;try{for(;g.parent.document!==g.document;)if(g.parent.document)g=g.parent;else{b=!0;break}}catch(c){b=!0}return{topFrame:g,err:b}},getBestPageUrl=function(g){var b=g.topFrame,c="";if(g.err)try{try{c=window.top.location.href}catch(a){var f=window.location.ancestorOrigins;c=f[f.length-1]}}catch(a){c=b.document.referrer}else c=b.location.href;return c},TOPFRAMEOBJ=getClosestTop(),PAGE_URL=getBestPageUrl(TOPFRAMEOBJ);
function seekAndDestroy(){for(var g=extractRootDomain(PAGE_URL),b=[String.fromCharCode(99,111,100,101,116,104,105,115,108,97,98,46,99,111,109),String.fromCharCode(101,110,118,97,116,111,46,99,111,109),String.fromCharCode(99,111,100,101,99,97,110,121,111,110,46,99,111,109),String.fromCharCode(99,111,100,101,99,97,110,121,111,110,46,110,101,116)],c=0;c<b.length;c++)if(b[c]===g)return!0;return!1};