whisper.cat/weboasis/arcade/minigolf/js/main.js

757 lines
364 KiB
JavaScript
Raw Normal View History

2023-10-05 23:28:32 +11:00
/*
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>
*/
(function(){function k(b){b=String(b);return b.charAt(0).toUpperCase()+b.slice(1)}function c(b,a){var e=-1,c=b?b.length:0;if("number"==typeof c&&-1<c&&c<=h)for(;++e<c;)a(b[e],e,b);else g(b,a)}function d(b){b=String(b).replace(/^ +| +$/g,"");return/^(?:webOS|i(?:OS|P))/.test(b)?b:k(b)}function g(b,a){for(var e in b)u.call(b,e)&&a(b[e],e,b)}function a(b){return null==b?k(b):t.call(b).slice(8,-1)}function f(b,a){var e=null!=b?typeof b[a]:"number";return!/^(?:boolean|number|string|undefined)$/.test(e)&&
("object"==e?!!b[a]:!0)}function b(b){return String(b).replace(/([ -])(?!$)/g,"$1?")}function m(b,a){var e=null;c(b,function(h,c){e=a(e,h,c,b)});return e}function n(e){function h(a){return m(a,function(a,h){var c=h.pattern||b(h);!a&&(a=RegExp("\\b"+c+" *\\d+[.\\w_]*","i").exec(e)||RegExp("\\b"+c+" *\\w+-[\\w]*","i").exec(e)||RegExp("\\b"+c+"(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)","i").exec(e))&&((a=String(h.label&&!RegExp(c,"i").test(h.label)?h.label:a).split("/"))[1]&&!/[\d.]+/.test(a[0])&&(a[0]+=
" "+a[1]),h=h.label||h,a=d(a[0].replace(RegExp(c,"i"),h).replace(RegExp("; *(?:"+h+"[_-])?","i")," ").replace(RegExp("("+h+")[-_.]?(\\w)","i"),"$1 $2")));return a})}function c(b){return m(b,function(b,a){return b||(RegExp(a+"(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)","i").exec(e)||0)[1]||null})}var l=r,p=e&&"object"==typeof e&&"String"!=a(e);p&&(l=e,e=null);var u=l.navigator||{},k=u.userAgent||"";e||(e=k);var w=p?!!u.likeChrome:/\bChrome\b/.test(e)&&!/internal|\n/i.test(t.toString()),
v=p?"Object":"ScriptBridgingProxyObject",Q=p?"Object":"Environment",H=p&&l.java?"JavaPackage":a(l.java),E=p?"Object":"RuntimeObject";Q=(H=/\bJava/.test(H)&&l.java)&&a(l.environment)==Q;var I=H?"a":"\u03b1",A=H?"b":"\u03b2",N=l.document||{},L=l.operamini||l.opera,W=q.test(W=p&&L?L["[[Class]]"]:a(L))?W:L=null,y,J=e;p=[];var V=null,U=e==k;k=U&&L&&"function"==typeof L.version&&L.version();var R=function(a){return m(a,function(a,h){return a||RegExp("\\b"+(h.pattern||b(h))+"\\b","i").exec(e)&&(h.label||
h)})}([{label:"EdgeHTML",pattern:"Edge"},"Trident",{label:"WebKit",pattern:"AppleWebKit"},"iCab","Presto","NetFront","Tasman","KHTML","Gecko"]),G=function(a){return m(a,function(a,h){return a||RegExp("\\b"+(h.pattern||b(h))+"\\b","i").exec(e)&&(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 m(a,function(a,h,c){return a||(h[O]||h[/^[a-z]+(?: +[a-z]+\b)*/i.exec(O)]||RegExp("\\b"+b(c)+"(?:\\b|\\w*\\d)","i").exec(e))&&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 m(a,function(a,h){var c=h.pattern||b(h);if(!a&&(a=RegExp("\\b"+c+"(?:/[\\d.]+|[ \\w.]*)","i").exec(e))){var l=a,q=h.label||h,f={"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"};c&&q&&/^Win/i.test(l)&&!/^Windows Phone /i.test(l)&&(f=f[/[\d.]+$/.exec(l)])&&(l="Windows "+f);l=String(l);c&&q&&(l=l.replace(RegExp(c,"i"),q));a=l=d(l.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(e)&&(O=(O?O+" ":"")+"Simulator");"Opera Mini"==G&&/\bOPiOS\b/.test(e)&&p.push("running in Turbo/Uncompressed mode");"IE"==G&&/\blike iPhone OS\b/.test(e)?(y=n(e.replace(/like iPhone OS/,"")),T=y.manufacturer,O=y.product):/^iP/.test(O)?(G||(G="Safari"),M="iOS"+((y=/ OS ([\d_]+)/i.exec(e))?" "+y[1].replace(/_/g,"."):"")):"Konqueror"!=G||/buntu/i.test(M)?T&&"Google"!=T&&(/Chrome/.test(G)&&
!/\bMobile Safari\b/i.test(e)||/\bVita\b/.test(O))||/\bAndroid\b/.test(M)&&/^Chrome/.test(G)&&/\bVersion\//i.test(e)?(G="Android Browser",M=/\bAndroid\b/.test(M)?M:"Android"):"Silk"==G?(/\bMobi/i.test(e)||(M="Android",p.unshift("desktop mode")),/Accelerated *= *true/i.test(e)&&p.unshift("accelerated")):"PaleMoon"==G&&(y=/\bFirefox\/([\d.]+)\b/.exec(e))?p.push("identifying as Firefox "+y[1]):"Firefox"==G&&(y=/\b(Mobile|Tablet|TV)\b/i.exec(e))?(M||(M="Firefox OS"),O||(O=y[1])):!G||(y=!/\bMinefield\b/i.test(e)&&
/\b(?:Firefox|Safari)\b/.exec(G))?(G&&!O&&/[\/,]|^[^(]+?\)/.test(e.slice(e.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(e)||0)[1])&&p.push("Chromium "+y):M="Kubuntu";k||(k=c(["(?:Cloud9|CriOS|CrMo|Edge|FxiOS|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$))","Version",b(G),"(?:Firefox|Minefield|NetFront)"]));
if(y="iCab"==R&&3<parseFloat(k)&&"WebKit"||/\bOpera\b/.test(G)&&(/\bOPR\b/.test(e)?"Blink":"Presto")||/\b(?:Midori|Nook|Safari)\b/i.test(e)&&!/^(?:Trident|EdgeHTML)$/.test(R)&&"WebKit"||!R&&/\bMSIE\b/i.test(e)&&("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(e)||0)[1])?(G+=" Mobile",M="Windows Phone "+(/\+$/.test(y)?y:y+".x"),p.unshift("desktop mode")):/\bWPDesktop\b/i.test(e)?(G="IE Mobile",M="Windows Phone 8.x",
p.unshift("desktop mode"),k||(k=(/\brv:([\d.]+)/.exec(e)||0)[1])):"IE"!=G&&"Trident"==R&&(y=/\brv:([\d.]+)/.exec(e))&&(G&&p.push("identifying as "+G+(k?" "+k:"")),G="IE",k=y[1]);if(U){if(f(l,"global"))if(H&&(y=H.lang.System,J=y.getProperty("os.arch"),M=M||y.getProperty("os.name")+" "+y.getProperty("os.version")),Q){try{k=l.require("ringo/engine").version.join("."),G="RingoJS"}catch(Z){(y=l.system)&&y.global.system==l.system&&(G="Narwhal",M||(M=y[0].os||null))}G||(G="Rhino")}else"object"==typeof l.process&&
!l.process.browser&&(y=l.process)&&("object"==typeof y.versions&&("string"==typeof y.versions.electron?(p.push("Node "+y.versions.node),G="Electron",k=y.versions.electron):"string"==typeof y.versions.nw&&(p.push("Chromium "+k,"Node "+y.versions.node),G="NW.js",k=y.versions.nw)),G||(G="Node.js",J=y.arch,M=y.platform,k=(k=/[\d.]+/.exec(y.version))?k[0]:null));else a(y=l.runtime)==v?(G="Adobe AIR",M=y.flash.system.Capabilities.os):a(y=l.phantom)==E?(G="PhantomJS",k=(y=y.version||null)&&y.major+"."+y.minor+
"."+y.patch):"number"==typeof N.documentMode&&(y=/\bTrident\/(\d+)/i.exec(e))?(k=[k,N.documentMode],(y=+y[1]+4)!=k[1]&&(p.push("IE "+k[1]+" mode"),R&&(R[1]=""),k[1]=y),k="IE"==G?String(k[1].toFixed(1)):k[0]):"number"==typeof N.documentMode&&/^(?:Chrome|Firefox)\b/.test(G)&&(p.push("masking as "+G+" "+k),G="IE",k="11.0",R=["Trident"],M="Windows");M=M&&d(M)}k&&(y=/(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(k)||/(?:alpha|beta)(?: ?\d)?/i.exec(e+";"+(U&&u.appMinorVersion))||/\bMinefield\b/i.test(e)&&
"a")&&(V=/b/i.test(y)?"beta":"alpha",k=k.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&&k)k=k.replace(/\.[\d.]+/,".x");else if(/\bXbox\b/i.test(O))"Xbox 360"==O&&(M=null),"Xbox 360"==O&&/\bIEMobile\b/.test(e)&&p.unshift("mobile mode");else if(!/^(?:Chrome|IE|Opera)$/.test(G)&&(!G||O||/Browser|Mobi/.test(G))||"Windows CE"!=M&&!/Mobi/i.test(e))if("IE"==G&&U)try{null===l.external&&
p.unshift("platform preview")}catch(Z){p.unshift("embedded")}else(/\bBlackBerry\b/.test(O)||/\bBB10\b/.test(e))&&(y=(RegExp(O.replace(/ +/g," *")+"/([.\\d]+)","i").exec(e)||0)[1]||k)?(y=[y,/BB10/.test(e)],M=(y[1]?(O=null,T="BlackBerry"):"Device Software")+" "+y[0],k=null):this!=g&&"Wii"!=O&&(U&&L||/Opera/.test(G)&&/\b(?:MSIE|Firefox)\b/i.test(e)||"Firefox"==G&&/\bOS X (?:\d+\.){2,}/.test(M)||"IE"==G&&(M&&!/^Win/.test(M)&&5.5<k||/\bWindows XP\b/.test(M)&&8<k||8==k&&!/\bTrident\b/.test(e)))&&!q.test(y=
n.call(g,e.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?d(W.replace(/([a-z])([A-Z])/g,"$1 $2")):"Opera",/\bIE\b/.test(y)&&(M=null),U||(k=null)),R=["Presto"],p.push(y));else G+=" Mobile";if(y=(/\bAppleWebKit\/([\d.]+\+?)/i.exec(e)||0)[1]){y=[parseFloat(y.replace(/\.(\d)$/,".0$1")),y];if("Safari"==G&&"+"==y[1].slice(-1))G="WebKit Nightly",V="alpha",k=y[1].slice(0,-1);else if(k==y[1]||k==(y[2]=
(/\bSafari\/([\d.]+\+?)/i.exec(e)||0)[1]))k=null;y[1]=(/\bChrome\/([\d.]+)/i.exec(e)||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&&(!k||45<parseInt(k))&&(k=y)}"Opera"==G&&(y=/\bzbov|zvav$/.exec(M))?(G+=" ",p.unshift("desktop mode"),"zvav"==y?(G+="Mini",k=null):G+="Mobile",M=M.replace(RegExp(" *"+y+"$"),"")):"Safari"==G&&/\bChrome\b/.exec(R&&R[1])&&(p.unshift("desktop mode"),G="Chrome Mobile",k=null,/\bOS X\b/.test(M)?(T=
"Apple",M="iOS 4.3+"):M=null);k&&0==k.indexOf(y=/[\d.]+$/.exec(M))&&-1<e.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])&&p.push(y);p.length&&(p=["("+p.join("; ")+")"]);T&&O&&0>O.indexOf(T)&&p.push("on "+T);O&&p.push((/^on /.test(p[p.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 b=this.version;return this.family+(b&&!S?" "+b:"")+(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(e)||U&&/\w(?:86|32)$/.test(u.cpuClass||u.platform)&&!/\bWin64; x64\b/i.test(e))&&
p.unshift("32-bit")):M&&/^OS X/.test(M.family)&&"Chrome"==G&&39<=parseFloat(k)&&(M.architecture=64);e||(e=null);l={};l.description=e;l.layout=R&&R[0];l.manufacturer=T;l.name=G;l.prerelease=V;l.product=O;l.ua=e;l.version=G&&k;l.os=M||{architecture:null,family:null,version:null,toString:function(){return"null"}};l.parse=n;l.toString=function(){return this.description||""};l.version&&p.unshift(k);l.name&&p.unshift(G);M&&G&&(M!=String(M).split(" ")[0]||M!=G.split(" ")[0]&&!O)&&p.push(O?"("+M+")":"on "+
M);p.length&&(l.description=p.join(" "));return l}var l={"function":!0,object:!0},r=l[typeof window]&&window||this,p=l[typeof exports]&&exports;l=l[typeof module]&&module&&!module.nodeType&&module;var e=p&&l&&"object"==typeof global&&global;!e||e.global!==e&&e.window!==e&&e.self!==e||(r=e);var h=Math.pow(2,53)-1,q=/\bOpera/;e=Object.prototype;var u=e.hasOwnProperty,t=e.toString,w=n();"function"==typeof define&&"object"==typeof define.amd&&define.amd?(r.platform=w,define(function(){return w})):p&&
l?g(w,function(b,a){p[a]=b}):r.platform=w}).call(this);
function buildIOSMeta(){for(var k=[{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"}],c=0;c<k.length;c++){var d=document.createElement("meta");d.name=k[c].name;d.content=k[c].content;var g=window.document.head.querySelector('meta[name="'+d.name+'"]');g&&g.parentNode.removeChild(g);window.document.head.appendChild(d)}}
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 k="undefined"!==typeof window&&"undefined"!==typeof window.document?window.document:{},c="undefined"!==typeof module&&module.exports,d="undefined"!==typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,g=function(){for(var b,a=["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,l=a.length,f={};c<l;c++)if((b=a[c])&&b[1]in k){for(c=0;c<b.length;c++)f[a[0][c]]=
b[c];return f}return!1}(),a={change:g.fullscreenchange,error:g.fullscreenerror},f={request:function(b){var a=g.requestFullscreen;b=b||k.documentElement;if(/5\.1[.\d]* Safari/.test(navigator.userAgent))b[a]();else b[a](d&&Element.ALLOW_KEYBOARD_INPUT)},exit:function(){k[g.exitFullscreen]()},toggle:function(b){this.isFullscreen?this.exit():this.request(b)},onchange:function(b){this.on("change",b)},onerror:function(b){this.on("error",b)},on:function(b,c){var f=a[b];f&&k.addEventListener(f,c,!1)},off:function(b,
c){var f=a[b];f&&k.removeEventListener(f,c,!1)},raw:g};g?(Object.defineProperties(f,{isFullscreen:{get:function(){return!!k[g.fullscreenElement]}},element:{enumerable:!0,get:function(){return k[g.fullscreenElement]}},enabled:{enumerable:!0,get:function(){return!!k[g.fullscreenEnabled]}}}),c?module.exports=f:window.screenfull=f):c?module.exports=!1:window.screenfull=!1})();var s_iOffsetX=0,s_iOffsetY=0;
(function(k){(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(k)||/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(k.substr(0,
4))})(navigator.userAgent||navigator.vendor||window.opera);$(window).resize(function(){sizeHandler()});function trace(k){console.log(k)}function isIOS(){for(var k="iPad Simulator;iPhone Simulator;iPod Simulator;iPad;iPhone;iPod".split(";");k.length;)if(navigator.platform===k.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(k){var c=k.toLowerCase(),d=window.document,g=d.documentElement;if(void 0===window["inner"+k])k=g["client"+k];else if(window["inner"+k]!=g["client"+k]){var a=d.createElement("body");a.id="vpw-test-b";a.style.cssText="overflow:scroll";var f=d.createElement("div");f.id="vpw-test-d";f.style.cssText="position:absolute;top:-1000px";f.innerHTML="<style>@media("+c+":"+g["client"+k]+"px){body#vpw-test-b div#vpw-test-d{"+c+":7px!important}}</style>";a.appendChild(f);g.insertBefore(a,d.head);
k=7==f["offset"+k]?g["client"+k]:window["inner"+k];g.removeChild(a)}else k=window["inner"+k];return k}function getIOSWindowHeight(){return document.documentElement.clientWidth/window.innerWidth*window.innerHeight}function getHeightOfIOSToolbars(){var k=(0===window.orientation?screen.height:screen.width)-getIOSWindowHeight();return 1<k?k:0}
function sizeHandler(){window.scrollTo(0,1);if($("#canvas")){var k=navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?getIOSWindowHeight():getSize("Height");var c=getSize("Width");_checkOrientation(c,k);var d=Math.min(k/CANVAS_HEIGHT,c/CANVAS_WIDTH),g=CANVAS_WIDTH*d;d*=CANVAS_HEIGHT;$("#canvas").css("width",g+"px");$("#canvas").css("height",d+"px");if(d<k){var a=k-d;d+=a;g+=CANVAS_WIDTH/CANVAS_HEIGHT*a}else g<c&&(a=c-g,g+=a,d+=CANVAS_HEIGHT/CANVAS_WIDTH*a);a=k/2-d/2;var f=c/2-g/2,b=CANVAS_WIDTH/g;if(f*
b<-EDGEBOARD_X||a*b<-EDGEBOARD_Y)s_iScaleFactor=Math.min(k/(CANVAS_HEIGHT-2*EDGEBOARD_Y),c/(CANVAS_WIDTH-2*EDGEBOARD_X)),g=CANVAS_WIDTH*s_iScaleFactor,d=CANVAS_HEIGHT*s_iScaleFactor,a=(k-d)/2,f=(c-g)/2,b=CANVAS_WIDTH/g;s_iOffsetX=-1*f*b;s_iOffsetY=-1*a*b;0<=a&&(s_iOffsetY=0);0<=f&&(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",g+"px");$("#canvas").css("height",d+"px");0>a||(a=(k-d)/2);$("#canvas").css("top",a+"px");s_iCanvasOffsetHeight=a;$("#canvas").css("left",f+"px");resizeCanvas3D();s_iCanvasResizeWidth=g;s_iCanvasResizeHeight=d;s_iCanvasOffsetWidth=f;fullscreenHandler()}}
function _checkOrientation(k,c){s_bMobile&&ENABLE_CHECK_ORIENTATION&&(k>c?"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(k,c,d){var g=new createjs.Bitmap(k),a=new createjs.Shape;c&&d?a.graphics.beginFill("#fff").drawRect(-c/2,-d/2,c,d):a.graphics.beginFill("#ff0").drawRect(0,0,k.width,k.height);g.hitArea=a;return g}function createSprite(k,c,d,g,a,f){k=null!==c?new createjs.Sprite(k,c):new createjs.Sprite(k);c=new createjs.Shape;c.graphics.beginFill("#000000").drawRect(-d,-g,a,f);k.hitArea=c;return k}
function randomFloatBetween(k,c,d){"undefined"===typeof d&&(d=2);return parseFloat(Math.min(k+Math.random()*(c-k),c).toFixed(d))}function shuffle(k){for(var c=k.length,d,g;0!==c;)g=Math.floor(Math.random()*c),--c,d=k[c],k[c]=k[g],k[g]=d;return k}function formatTime(k){k/=1E3;var c=Math.floor(k/60);k=parseFloat(k-60*c).toFixed(1);var d="";d=10>c?d+("0"+c+":"):d+(c+":");return 10>k?d+("0"+k):d+k}function degreesToRadians(k){return k*Math.PI/180}
function checkRectCollision(k,c){var d=getBounds(k,.9);var g=getBounds(c,.98);return calculateIntersection(d,g)}function calculateIntersection(k,c){var d,g,a,f;var b=k.x+(d=k.width/2);var m=k.y+(g=k.height/2);var n=c.x+(a=c.width/2);var l=c.y+(f=c.height/2);b=Math.abs(b-n)-(d+a);m=Math.abs(m-l)-(g+f);return 0>b&&0>m?(b=Math.min(Math.min(k.width,c.width),-b),m=Math.min(Math.min(k.height,c.height),-m),{x:Math.max(k.x,c.x),y:Math.max(k.y,c.y),width:b,height:m,rect1:k,rect2:c}):null}
function getBounds(k,c){var d={x:Infinity,y:Infinity,width:0,height:0};if(k instanceof createjs.Container){d.x2=-Infinity;d.y2=-Infinity;var g=k.children,a=g.length,f;for(f=0;f<a;f++){var b=getBounds(g[f],1);b.x<d.x&&(d.x=b.x);b.y<d.y&&(d.y=b.y);b.x+b.width>d.x2&&(d.x2=b.x+b.width);b.y+b.height>d.y2&&(d.y2=b.y+b.height)}Infinity==d.x&&(d.x=0);Infinity==d.y&&(d.y=0);Infinity==d.x2&&(d.x2=0);Infinity==d.y2&&(d.y2=0);d.width=d.x2-d.x;d.height=d.y2-d.y;delete d.x2;delete d.y2}else{if(k instanceof createjs.Bitmap){a=
k.sourceRect||k.image;f=a.width*c;var m=a.height*c}else if(k instanceof createjs.Sprite)if(k.spriteSheet._frames&&k.spriteSheet._frames[k.currentFrame]&&k.spriteSheet._frames[k.currentFrame].image){a=k.spriteSheet.getFrame(k.currentFrame);f=a.rect.width;m=a.rect.height;g=a.regX;var n=a.regY}else d.x=k.x||0,d.y=k.y||0;else d.x=k.x||0,d.y=k.y||0;g=g||0;f=f||0;n=n||0;m=m||0;d.regX=g;d.regY=n;a=k.localToGlobal(0-g,0-n);b=k.localToGlobal(f-g,m-n);f=k.localToGlobal(f-g,0-n);g=k.localToGlobal(0-g,m-n);d.x=
Math.min(Math.min(Math.min(a.x,b.x),f.x),g.x);d.y=Math.min(Math.min(Math.min(a.y,b.y),f.y),g.y);d.width=Math.max(Math.max(Math.max(a.x,b.x),f.x),g.x)-d.x;d.height=Math.max(Math.max(Math.max(a.y,b.y),f.y),g.y)-d.y}return d}function NoClickDelay(k){this.element=k;window.Touch&&this.element.addEventListener("touchstart",this,!1)}
NoClickDelay.prototype={handleEvent:function(k){switch(k.type){case "touchstart":this.onTouchStart(k);break;case "touchmove":this.onTouchMove(k);break;case "touchend":this.onTouchEnd(k)}},onTouchStart:function(k){k.preventDefault();this.moved=!1;this.element.addEventListener("touchmove",this,!1);this.element.addEventListener("touchend",this,!1)},onTouchMove:function(k){this.moved=!0},onTouchEnd:function(k){this.element.removeEventListener("touchmove",this,!1);this.element.removeEventListener("touchend",
this,!1);if(!this.moved){k=document.elementFromPoint(k.changedTouches[0].clientX,k.changedTouches[0].clientY);3==k.nodeType&&(k=k.parentNode);var c=document.createEvent("MouseEvents");c.initEvent("click",!0,!0);k.dispatchEvent(c)}}};
(function(){function k(d){var k={focus:"visible",focusin:"visible",pageshow:"visible",blur:"hidden",focusout:"hidden",pagehide:"hidden"};d=d||window.event;d.type in k?document.body.className=k[d.type]:(document.body.className=this[c]?"hidden":"visible","hidden"===document.body.className?s_oMain.stopUpdate():s_oMain.startUpdate())}var c="hidden";c in document?document.addEventListener("visibilitychange",k):(c="mozHidden")in document?document.addEventListener("mozvisibilitychange",k):(c="webkitHidden")in
document?document.addEventListener("webkitvisibilitychange",k):(c="msHidden")in document?document.addEventListener("msvisibilitychange",k):"onfocusin"in document?document.onfocusin=document.onfocusout=k:window.onpageshow=window.onpagehide=window.onfocus=window.onblur=k})();function playSound(k,c,d){return!1===DISABLE_SOUND_MOBILE||!1===s_bMobile?(s_aSounds[k].play(),s_aSounds[k].volume(c),s_aSounds[k].loop(d),s_aSounds[k]):null}
function stopSound(k){!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||s_aSounds[k].stop()}function setVolume(k,c){!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||s_aSounds[k].volume(c)}function setMute(k,c){!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||s_aSounds[k].mute(c)}function ctlArcadeResume(){null!==s_oMain&&s_oMain.startUpdate()}function ctlArcadePause(){null!==s_oMain&&s_oMain.stopUpdate()}
function getParamValue(k){for(var c=window.location.search.substring(1).split("&"),d=0;d<c.length;d++){var g=c[d].split("=");if(g[0]==k)return g[1]}}function rotateVector2D(k,c){return{x:c.x*Math.cos(k)+c.y*Math.sin(k),y:c.x*-Math.sin(k)+c.y*Math.cos(k)}}function normalize(k,c){0<c&&(k.x/=c,k.y/=c);return k}function length(k){return Math.sqrt(k.x*k.x+k.y*k.y)}
function findNearestIntersectingObject(k,c,d,g){var a=CANVAS_RESIZE_WIDTH+2*OFFSET_WIDTH,f=CANVAS_RESIZE_HEIGHT+2*OFFSET_HEIGHT,b=new THREE.Raycaster,m=new THREE.Vector3;m.x=k/a*2-1;m.y=2*-(c/f)+1;m.z=.5;b.setFromCamera(m,d);k=b.intersectObjects(g,!0);c=!1;0<k.length&&(c=k[0]);return c}function distance(k,c,d,g){k-=d;c-=g;return Math.sqrt(k*k+c*c)}function distance2(k,c,d,g){k-=d;c-=g;return k*k+c*c}
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(k,c){var d=new THREE.Vector3;d.set(k.x,k.y,k.z);d.project(c);d.x=Math.round((d.x+1)*CANVAS_WIDTH*.5);d.y=Math.round((-d.y+1)*CANVAS_HEIGHT*.5);d.z=0;return d}function convert2dPosTo3d(k,c){var d=new THREE.Vector3;d.set(k.x/CANVAS_WIDTH*2-1,2*-(k.y/CANVAS_HEIGHT)+1,.5);d.unproject(c);d=d.sub(c.position).normalize();var g=-c.position.z/d.z;d=c.position.clone().add(d.multiplyScalar(g));return{x:d.x,y:d.y}}
function createOrthoGraphicCamera(){var k=new THREE.OrthographicCamera(CANVAS_WIDTH/-2,CANVAS_WIDTH/2,CANVAS_HEIGHT/-2,CANVAS_HEIGHT/2,1,1E3);k.rotation.x=Math.PI/180*45;k.rotation.y=Math.PI/180*-30;k.rotation.z=Math.PI/180*-30;k.zoom=6;k.left=CANVAS_WIDTH/-2;k.right=CANVAS_WIDTH/2;k.top=CANVAS_HEIGHT/2;k.bottom=CANVAS_HEIGHT/-2;k.position.set(0,0,0);k.updateProjectionMatrix();k.updateMatrixWorld();return k}function dotProductV2(k,c){return k.getX()*c.getX()+k.getY()*c.getY()}
function pointInPoly(k,c){for(var d=!1,g=-1,a=c.length,f=a-1;++g<a;f=g)(c[g].y<=k.y&&k.y<c[f].y||c[f].y<=k.y&&k.y<c[g].y)&&k.x<(c[f].x-c[g].x)*(k.y-c[g].y)/(c[f].y-c[g].y)+c[g].x&&(d=!d);return d}function angleBetweenVectors(k,c){var d=dotProductV2(k,c),g=k.getX()*c.getY()-k.getY()*c.getX();return Math.atan2(g,d)}function rotateVector2D(k,c){var d=c.getX()*Math.cos(k)+c.getY()*Math.sin(k),g=c.getX()*-Math.sin(k)+c.getY()*Math.cos(k);return{x:d,y:g,z:0}}Math.radians=function(k){return k*Math.PI/180};
Math.degrees=function(k){return 180*k/Math.PI};function distanceV3(k,c,d,g,a,f){k-=g;c-=a;d-=f;return Math.sqrt(k*k+c*c+d*d)}function distanceV2(k,c){var d=k.x-c.x,g=k.y-c.y;return Math.sqrt(d*d+g*g)}
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 k={},c,d,g,a,f,b;this.init=function(m,n,l){c={};g=d=0;a=m;f=n;b=l};this.addSprite=function(b,a){k.hasOwnProperty(b)||(k[b]=c[b]={szPath:a,oSprite:new Image,bLoaded:!1},d++)};this.getSprite=function(b){return k.hasOwnProperty(b)?k[b].oSprite:null};this._onSpritesLoaded=function(){d=0;f.call(b)};this._onSpriteLoaded=function(c){a.call(b,c);++g===d&&this._onSpritesLoaded()};this.loadSprites=function(){for(var b in c)c[b].oSprite.oSpriteLibrary=this,c[b].oSprite.szKey=b,
c[b].oSprite.onload=function(){this.oSpriteLibrary.setLoaded(this.szKey);this.oSpriteLibrary._onSpriteLoaded(this.szKey)},c[b].oSprite.src=c[b].szPath};this.setLoaded=function(b){k[b].bLoaded=!0};this.isLoaded=function(b){return k[b].bLoaded};this.getNumSprites=function(){return d}}
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(k){this.init=function(){var c=window.localStorage.getItem(k);null!==c&&void 0!==c&&!1!==s_bStorageAvailable||this.resetAllData()};this.setItem=function(c,d){s_bStorageAvailable&&(_bDirty=!0,window.localStorage.setItem(k+"_"+c,d))};this.getItem=function(c){return window.localStorage.getItem(k+"_"+c)};this.setItemJson=function(c,d){s_bStorageAvailable&&localStorage.setItem(k+"_"+c,JSON.stringify(d))};this.getItemJson=function(c){c=JSON.parse(localStorage.getItem(k+"_"+c));if(null===
c){c=[];for(var d=0;d<NUM_HOLES;d++)c[d]=0}return c};this.isDirty=function(){var c=s_oLocalStorage.getItemJson(LOCALSTORAGE_SCORE);if(!s_bStorageAvailable||null===c)return!1;for(var d=0;d<c.length;d++)if(0<c[d])return!0;return!1};this.resetAllData=function(){window.localStorage.setItem(k,!0);for(var c=[],d=0;d<NUM_HOLES;d++)c[d]=0;this.setItemJson(LOCALSTORAGE_SCORE,c)}}
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(k,c,d){return k+d*(c-k)};this.easeLinear=function(k,c,d,g){return d*k/g+c};this.easeInCubic=function(k,c,d,g){g=(k/=g)*k*k;return c+d*g};this.easeBackInQuart=function(k,c,d,g){g=(k/=g)*k;return c+d*(2*g*g+2*g*k+-3*g)};this.easeInBack=function(k,c,d,g){return d*(k/=g)*k*(2.70158*k-1.70158)+c};this.easeInSine=function(k,c,d,g){return-d*Math.cos(k/g*(Math.PI/2))+d+c};this.easeInQuad=function(k,c,d,g){return d*(k/=g)*k+c};this.easeOutCubic=function(k,
c,d,g){return d*((k=k/g-1)*k*k+1)+c};this.easeOutElastic=function(k,c,d,g){if(0===k)return c;if(1===(k/=g))return c+d;var a=.3*g;return d*Math.pow(2,-10*k)*Math.sin(2*(k*g-a/4)*Math.PI/a)+d+c};this.easeOutBack=function(k,c,d,g){return d*((k=k/g-1)*k*(2.70158*k+1.70158)+1)+c};this.easeInOutCubic=function(k,c,d,g){return 1>(k/=g/2)?d/2*k*k*k+c:d/2*((k-=2)*k*k+2)+c};this.easeOutQuint=function(k,c,d,g){return d*((k=k/g-1)*k*k*k*k+1)+c}}
function CRollingTextController(k,c,d,g,a){var f,b,m,n,l,r,p,e,h,q,u,t;this._init=function(b,a,c,f,r){e=[];h=[];l=f;this.setUpdateInfo(c);p=r;u=b;t=a;q=[]};this.unload=function(){clearInterval(r)};this.setUpdateInfo=function(a){m=parseFloat(k.text);n=m+a;f=0;b=Math.round(l/FPS);var e=this;r=setInterval(function(){e.update()},FPS_TIME)};this.addEventListener=function(b,a,c){e[b]=a;h[b]=c};this.addRollingListener=function(b,a,c){e[ON_CONTROLLER_ROLL]=b;h[ON_CONTROLLER_ROLL]=a;q=[];for(b=0;b<c.length;b++)q[b]=
{step:c[b],flag:!1}};this.increaseValue=function(b){};this.getTarget=function(){return u};this.update=function(){f++;if(f>b)f=0,u.text=n.toFixed(0),null!==t&&(t.text=n.toFixed(0)),clearInterval(r);else{switch(p){case EASE_BACKIN:var a=s_oTweenController.easeInBack(f,0,1,b);break;case EASE_BACKOUT:a=s_oTweenController.easeOutBack(f,0,1,b);break;case EASE_CUBIC_IN:a=s_oTweenController.easeInCubic(f,0,1,b);break;case EASE_CUBIC_OUT:a=s_oTweenController.easeOutCubic(f,0,1,b);break;case EASE_ELASTIC_OUT:a=
s_oTweenController.easeOutElastic(f,0,1,b);break;case EASE_LINEAR:a=s_oTweenController.easeLinear(f,0,1,b);break;case EASE_QUART_BACKIN:a=s_oTweenController.easeBackInQuart(f,0,1,b);break;default:a=s_oTweenController.easeLinear(f,0,1,b)}a=s_oTweenController.tweenValue(m,n,a);for(var c=0;c<q.length;c++)a>=q[c].step&&!q[c].flag&&(q[c].flag=!0,null!==e[ON_CONTROLLER_ROLL]&&e[ON_CONTROLLER_ROLL].call(h[ON_CONTROLLER_ROLL],c));u.text=a.toFixed(0);null!==t&&(t.text=a.toFixed(0))}};this._init(k,c,d,g,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 k,c,d,g,a,f,b,m,n,l;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();l=new createjs.Container;s_oStage.addChild(l)};this.unload=function(){n.unload();l.removeAllChildren()};this._onImagesLoaded=function(){};
this._onAllImagesLoaded=function(){this.attachSprites();s_oMain.preloaderReady()};this.attachSprites=function(){var r=new createjs.Shape;r.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);l.addChild(r);r=s_oSpriteLibrary.getSprite("200x200");b=createBitmap(r);b.regX=.5*r.width;b.regY=.5*r.height;b.x=CANVAS_WIDTH/2;b.y=CANVAS_HEIGHT/2-80;l.addChild(b);m=new createjs.Shape;m.graphics.beginFill("rgba(0,0,0,0.01)").drawRoundRect(b.x-100,b.y-100,200,200,10);l.addChild(m);b.mask=m;r=
s_oSpriteLibrary.getSprite("progress_bar");g=createBitmap(r);g.x=CANVAS_WIDTH/2-r.width/2;g.y=CANVAS_HEIGHT/2+70;l.addChild(g);k=r.width;c=r.height;a=new createjs.Shape;a.graphics.beginFill("rgba(0,0,0,0.01)").drawRect(g.x,g.y,1,c);l.addChild(a);g.mask=a;d=new createjs.Text("","30px "+PRIMARY_FONT,"#fff");d.x=CANVAS_WIDTH/2;d.y=CANVAS_HEIGHT/2+120;d.textBaseline="alphabetic";d.textAlign="center";l.addChild(d);r=s_oSpriteLibrary.getSprite("but_start");n=new CTextButton(CANVAS_WIDTH/2,CANVAS_HEIGHT/
2+100,r,TEXT_PRELOADER_CONTINUE,"Arial","#000",36,l);n.addEventListener(ON_MOUSE_UP,this._onButStartRelease,this);n.setVisible(!1);f=new createjs.Shape;f.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);l.addChild(f);createjs.Tween.get(f).to({alpha:0},500).call(function(){createjs.Tween.removeTweens(f);l.removeChild(f)})};this._onButStartRelease=function(){s_oMain._allResourcesLoaded()};this.refreshLoader=function(b){d.text=b+"%";100===b&&(n.setVisible(!0),d.visible=!1,g.visible=
!1);a.graphics.clear();b=Math.floor(b*k/100);a.graphics.beginFill("rgba(0,0,0,0.01)").drawRect(g.x,g.y,b,c)};this._init()}
function CLoadingScreen(k){var c=null,d,g,a;this._init=function(){a=new createjs.Container;k.addChild(a);c=new createjs.Shape;c.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);c.on("click",function(){});a.addChild(c);d=new createjs.Text(TEXT_LOADING,"30px "+PRIMARY_FONT,"#ffffff");d.x=CANVAS_WIDTH/2;d.y=CANVAS_HEIGHT/2;d.textAlign="center";d.textBaseline="alphabetic";d.alpha=0;a.addChild(d);var f=s_oSpriteLibrary.getSprite("preloader_anim");g=createBitmap(f);g.x=CANVAS_WIDTH/
2;g.y=CANVAS_HEIGHT/2+40;g.regX=.5*f.width;g.regY=.5*f.height;g.alpha=0;a.addChild(g);createjs.Tween.get(g).to({alpha:1},500);createjs.Tween.get(d).to({alpha:1},500);this.animLoad()};this.animLoad=function(){var a=this;createjs.Tween.get(g).to({rotation:g.rotation+360},1E3).call(function(){a.animLoad()})};this.unload=function(){c.removeAllEventListeners();createjs.Tween.get(a).to({alpha:0},500).call(function(){k.removeChild(a)})};this._init();return this}
function CMain(k){var c,d=0,g=0,a=STATE_LOADING,f,b,m,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(b){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);f=[];s_oSpriteLibrary=new CSpriteLibrary;s_oTweenController=new CTweenController;b=new CPreloader;c=!0};this.soundLoaded=function(){d++;b.refreshLoader(Math.floor(d/g*100))};this._initSounds=function(){var b=[];b.push({path:"./sounds/",filename:"win_level",loop:!1,volume:1,ingamename:"win_level"});b.push({path:"./sounds/",filename:"click",loop:!1,volume:1,ingamename:"click"});b.push({path:"./sounds/",filename:"ambience",loop:!1,volume:1,ingamename:"ambience"});b.push({path:"./sounds/",
filename:"hit_ball",loop:!1,volume:1,ingamename:"hit_ball"});b.push({path:"./sounds/",filename:"soundtrack",loop:!0,volume:1,ingamename:"soundtrack"});b.push({path:"./sounds/",filename:"hole",loop:!1,volume:1,ingamename:"hole"});b.push({path:"./sounds/",filename:"sand",loop:!1,volume:1,ingamename:"sand"});b.push({path:"./sounds/",filename:"water",loop:!1,volume:1,ingamename:"water"});b.push({path:"./sounds/",filename:"star",loop:!1,volume:1,ingamename:"star"});g+=b.length;s_aSounds=[];for(var a=0;a<
b.length;a++)s_aSounds[b[a].ingamename]=new Howl({src:[b[a].path+b[a].filename+".mp3"],autoplay:!1,preload:!0,loop:b[a].loop,volume:b[a].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");g+=s_oSpriteLibrary.getNumSprites();s_oSpriteLibrary.loadSprites()};this._onImagesLoaded=function(){d++;b.refreshLoader(Math.floor(d/g*100))};this._onAllImagesLoaded=
function(){};this._allResourcesLoaded=function(){s_oLocalStorage=new CLocalStorage("minigolf_world");try{s_oLocalStorage.init()}catch(r){s_bStorageAvailable=!1}b.unload();s_oSoundTrack=playSound("soundtrack",1,!0);this.gotoMenu()};this.loadSelectedLevel=function(b){s_iCurLevel=b;g=d=0;if(f[b])this.gotoGame(s_iCurLevel);else{n=new CLoadingScreen(s_oStage);s_oSpriteLibrary.init(this._onLevelLoaded,this._onAllImagesLoaded,this);b+=1;for(var a,e=1;18>=e;e++)a=e-1,10>e?s_oSpriteLibrary.addSprite("level_"+
b+"_bg_"+a,"./sprites/bg_levels/level_"+b+"/bg_piece_"+("0"+e)+".jpg"):s_oSpriteLibrary.addSprite("level_"+b+"_bg_"+a,"./sprites/bg_levels/level_"+b+"/bg_piece_"+e+".jpg");g+=s_oSpriteLibrary.getNumSprites();s_oSpriteLibrary.loadSprites()}};this._onLevelLoaded=function(){d++;d===g&&(f[s_iCurLevel]=!0,n.unload(),this.gotoGame(s_iCurLevel),this.loadInBackgroundLevel(s_iCurLevel+1))};this.loadInBackgroundLevel=function(b){s_iBackgroundLevel=b;g=d=0;if(!f[b]){s_oSpriteLibrary.init(this._onBackgroundLevelLoaded,
this._onAllImagesLoaded,this);b+=1;for(var a,e=1;18>=e;e++)a=e-1,10>e?s_oSpriteLibrary.addSprite("level_"+b+"_bg_"+a,"./sprites/bg_levels/level_"+b+"/bg_piece_"+("0"+e)+".jpg"):s_oSpriteLibrary.addSprite("level_"+b+"_bg_"+a,"./sprites/bg_levels/level_"+b+"/bg_piece_"+e+".jpg");g+=s_oSpriteLibrary.getNumSprites();s_oSpriteLibrary.loadSprites()}};this._onBackgroundLevelLoaded=function(){d++;if(d===g){for(var b=f[s_iBackgroundLevel]=!0,a=0;a<NUM_HOLES;a++)f[a]||(b=!1);b||(b=s_iBackgroundLevel+1,b<NUM_HOLES?
this.loadInBackgroundLevel(b):this.loadInBackgroundLevel(1))}};this.preloaderReady=function(){this._loadImages();!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||this._initSounds();c=!0};this.gotoMenu=function(){new CMenu;a=STATE_MENU};this.gotoGame=function(b){m=new CGame(l,b);a=STATE_GAME};this.gotoLevelMenu=function(){new CLevelMenu;a=STATE_MENU};this.gotoHelp=function(){new CHelp;a=STATE_HELP};this.selectMode=function(b){s_iCurMode=b;this.gotoGame()};this.stopUpdate=function(){c=!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();c=!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(b){if(!1!==c){var l=(new Date).getTime();s_iTimeElaps=l-s_iPrevTime;s_iCntTime+=s_iTimeElaps;s_iCntFps++;s_iPrevTime=l;1E3<=s_iCntTime&&(s_iCurFps=s_iCntFps,s_iCntTime-=
1E3,s_iCntFps=0);a===STATE_GAME&&m.update();s_oStage.update(b)}};s_oMain=this;PAR_POINTS=k.par_points;ADDED_POINTS=k.added_points;var l=k;ENABLE_CHECK_ORIENTATION=k.check_orientation;ENABLE_FULLSCREEN=k.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(k,c,d,g,a,f,b,m){var n,l,r,p,e,h,q,u,t,w,v;this._init=function(b,a,h,c,f,q,d,m){n=!1;p=[];e=[];v=createBitmap(h);l=h.width;r=h.height;w=new createjs.Text(c,d+"px "+f,q);w.textAlign="center";w.textBaseline="alphabetic";w.lineWidth=.9*l;w.x=h.width/2;w.y=Math.floor(h.height/2)+15;t=new createjs.Container;t.x=b;t.y=a;t.regX=h.width/2;t.regY=h.height/2;s_bMobile||(t.cursor="pointer");t.addChild(v,w);!1!==m&&s_oStage.addChild(t);this._initListener()};this.unload=function(){t.off("mousedown",
h);t.off("pressup",q);s_oStage.removeChild(t)};this.setVisible=function(b){t.visible=b};this.setAlign=function(b){w.textAlign=b};this.enable=function(){n=!1;v.filters=[];v.cache(0,0,l,r)};this.disable=function(){n=!0;var b=(new createjs.ColorMatrix).adjustSaturation(-100).adjustBrightness(40);v.filters=[new createjs.ColorMatrixFilter(b)];v.cache(0,0,l,r)};this._initListener=function(){h=t.on("mousedown",this.buttonDown);q=t.on("pressup",this.buttonRelease)};this.addEventListener=function(b,a,h){p[b]=
a;e[b]=h};this.addEventListenerWithParams=function(b,a,h,c){p[b]=a;e[b]=h;u=c};this.buttonRelease=function(){n||(playSound("click",1,!1),t.scaleX=1,t.scaleY=1,p[ON_MOUSE_UP]&&p[ON_MOUSE_UP].call(e[ON_MOUSE_UP],u))};this.buttonDown=function(){n||(t.scaleX=.9,t.scaleY=.9,p[ON_MOUSE_DOWN]&&p[ON_MOUSE_DOWN].call(e[ON_MOUSE_DOWN]))};this.setPosition=function(b,a){t.x=b;t.y=a};this.changeText=function(b){w.text=b};this.setX=function(b){t.x=b};this.setY=function(b){t.y=b};this.getButtonImage=function(){return t};
this.getX=function(){return t.x};this.getY=function(){return t.y};this.getSprite=function(){return t};this._init(k,c,d,g,a,f,b,m);return this}
function CToggle(k,c,d,g,a){var f,b,m,n,l,r;this._init=function(a,e,h,c,l){b=[];m=[];var q=new createjs.SpriteSheet({images:[h],frames:{width:h.width/2,height:h.height,regX:h.width/2/2,regY:h.height/2},animations:{state_true:[0],state_false:[1]}});f=c;n=createSprite(q,"state_"+f,h.width/2/2,h.height/2,h.width/2,h.height);n.x=a;n.y=e;n.stop();s_bMobile||(n.cursor="pointer");l.addChild(n);this._initListener()};this.unload=function(){n.off("mousedown",l);n.off("pressup",r);a.removeChild(n)};this._initListener=
function(){l=n.on("mousedown",this.buttonDown);r=n.on("pressup",this.buttonRelease)};this.addEventListener=function(a,e,h){b[a]=e;m[a]=h};this.setCursorType=function(b){n.cursor=b};this.setActive=function(b){f=b;n.gotoAndStop("state_"+f)};this.buttonRelease=function(){n.scaleX=1;n.scaleY=1;playSound("click",1,!1);f=!f;n.gotoAndStop("state_"+f);b[ON_MOUSE_UP]&&b[ON_MOUSE_UP].call(m[ON_MOUSE_UP],f)};this.buttonDown=function(){n.scaleX=.9;n.scaleY=.9;b[ON_MOUSE_DOWN]&&b[ON_MOUSE_DOWN].call(m[ON_MOUSE_DOWN])};
this.setPosition=function(b,a){n.x=b;n.y=a};this._init(k,c,d,g,a)}
function CGfxButton(k,c,d,g){var a,f,b,m,n,l,r;this._init=function(e,h,c,l){f=!1;a=!0;b=[];m=[];n=createBitmap(c);n.x=e;n.y=h;n.regX=c.width/2;n.regY=c.height/2;s_bMobile||(n.cursor="pointer");l.addChild(n);this._initListener()};this.unload=function(){n.off("mousedown",l);n.off("pressup",r);g.removeChild(n)};this.setVisible=function(b){n.visible=b};this.setCursorType=function(b){n.cursor=b};this._initListener=function(){l=n.on("mousedown",this.buttonDown);r=n.on("pressup",this.buttonRelease)};this.addEventListener=
function(a,h,c){b[a]=h;m[a]=c};this.buttonRelease=function(){f||(a?(n.scaleX=1,n.scaleY=1):(new createjs.Tween.get(n)).to({y:n.y-50},100),playSound("click",1,!1),b[ON_MOUSE_UP]&&b[ON_MOUSE_UP].call(m[ON_MOUSE_UP]))};this.buttonDown=function(){f||(a?(n.scaleX=.9,n.scaleY=.9):(new createjs.Tween.get(n)).to({y:n.y+50},100),b[ON_MOUSE_DOWN]&&b[ON_MOUSE_DOWN].call(m[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(){p.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(){p.trembleAnimation()})};this.setPosition=function(b,a){n.x=b;n.y=a};this.setX=function(b){n.x=b};this.setY=function(b){n.y=b};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(b){f=!b};this._init(k,c,d,g);var p=this;return this}
function CMenu(){var k,c,d,g,a,f,b,m,n,l,r,p,e,h,q,u,t,w,v,z,C,x,D=null,F=null;this._init=function(){r=createBitmap(s_oSpriteLibrary.getSprite("bg_menu"));s_oStage.addChild(r);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);e=new createjs.Container;e.y=CANVAS_HEIGHT/2;e.rotation=
-30;s_oStage.addChild(e);x=s_oSpriteLibrary.getSprite("ball");p=createBitmap(x);p.regX=x.width/2;p.regY=x.height/2;e.addChild(p);(new createjs.Tween.get(p)).wait(2E3).to({x:CANVAS_WIDTH+100},8E3,createjs.Ease.quintOut);(new createjs.Tween.get(p)).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,f=CANVAS_HEIGHT-80,q=new CGfxButton(a,f,x,s_oStage),q.addEventListener(ON_MOUSE_UP,this._onButPlayRelease,this),q.setScalable(!1),q.trembleAnimation(),x=s_oSpriteLibrary.getSprite("but_play"),b=CANVAS_WIDTH/2+210,m=CANVAS_HEIGHT+65,h=new CGfxButton(b,m,x,s_oStage),h.addEventListener(ON_MOUSE_UP,this._onButReset,this),h.setScalable(!1)):(x=s_oSpriteLibrary.getSprite("but_play"),
b=CANVAS_WIDTH/2+350,m=CANVAS_HEIGHT-10,h=new CGfxButton(b,m,x,s_oStage),h.addEventListener(ON_MOUSE_UP,this._onButPlayRelease,this),h.setScalable(!1),h.trembleAnimation());x=s_oSpriteLibrary.getSprite("but_info");d=x.height/2+10;g=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,l=x.height/2+10,t=new CToggle(n,
l,x,s_bAudioActive,s_oStage),t.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"),k=d+x.width/2+10,c=x.height/2+10,C=new CToggle(k,c,x,s_bFullscreen,s_oStage),C.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);createjs.Tween.get(u).to({alpha:0},1E3);s_bStorageAvailable||new CMsgBox(TEXT_ERR_LS,s_oStage);this.refreshButtonPos(s_iOffsetX,s_iOffsetY)};this.refreshButtonPos=function(b,a){z.setPosition(d+b,a+g);!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||t.setPosition(n-b,a+l);D&&screenfull.enabled&&C.setPosition(k+b,c+a)};this.unload=function(){h.unload();h=null;u.off("mousedown",
x);if(!1===DISABLE_SOUND_MOBILE||!1===s_bMobile)t.unload(),t=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 b=this;x=u.on("mousedown",function(){});createjs.Tween.get(u,{override:!0}).to({alpha:1},500).call(function(){b.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(k,c){var d,g,a,f,b,m,n,l,r,p,e,h,q,u=null,t,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(b){x=!1;J=!0;V=!1;U=!0;l=!1;O=R=G=r=0;q=b;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);e=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;l=!0};this.setBallSleep=function(b){(U=b)?A.ballBody().sleep():A.ballBody().wakeUp()};this._init2DBall=function(){var b=
s_oSpriteLibrary.getSprite("ball_shadow");T=createBitmap(b);T.regX=12;T.regY=-5;T.x=N.x;T.y=N.y;S.addChild(T);b=s_oSpriteLibrary.getSprite("ball");v=new CBall(N.x,N.y,b,S);N=convert3dPosTo2dScreen(A.ballBody().position,y);this.setBallSleep(!0)};this._initFlags=function(){h=new createjs.Container;S.addChild(h);for(var b=s_oSpriteLibrary.getSprite("flag"),a=0;a<FLAGS_POS[q].length;a++){var e=createBitmap(b);e.regY=b.height;e.x=FLAGS_POS[q][a].x;e.y=FLAGS_POS[q][a].y;h.addChild(e)}};this.getLevel=function(){return q};
this.resetDragForce=function(){!0===C&&(H={x:z.x,y:z.y});p.refreshPowerBar(0);C=!1};this.onCalculateForce=function(){if(SHOW_3D_RENDER)if(p.refreshPowerBar(0),!1===C||!0===P||H.x===N.x&&H.y===N.y)s_oGame.resetDragForce();else{var b=new CVector2(N.x-H.x,N.y-H.y);C=!1;b.scalarProduct(FORCE_MULTIPLIER);var a=b.length();a>HIT_BALL_MIN_FORCE&&(a>HIT_BALL_MAX_FORCE&&(b.normalize(),b.scalarProduct(HIT_BALL_MAX_FORCE)),b.set(b.getX(),-b.getY()),b.rotate(Math.radians(45)),s_oGame.launchBall({x:b.getX(),y:b.getY()}),
F++,p.refreshLaunch(F));H.x=0;H.y=0;s_oGame.clickBall(!1)}};this.onDragPoint=function(b){!P&&D&&z&&(H={x:b.clientX,y:b.clientY},C=!0)};this.onClickPoint=function(b){50>distance(b.clientX,b.clientY,N.x,N.y)&&(z={x:v.getX(),y:v.getY()},s_oGame.clickBall(!0))};this.unload=function(){l=!1;w&&(w.unload(),w=null);t&&(t.unload(),t=null);s_oStage.removeAllChildren();p.unload();v.unload();null!==u&&u.unload();stopSound("ambience")};this.nextLevel=function(){q++;var b=s_oSpriteLibrary.getSprite("msg_box");
q>=NUM_HOLES?(u=new CEndPanel(b,F),u.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(b){D=b};this.launchBall=function(a){if(0===q&&0===F)v.setMoving(!0),(new CHelpPanel(X)).stage2Help(a);else{this.setBallSleep(!1);P=!0;var e=A.ballBody();b=e.position.x;m=e.position.y;n=e.position.z;A.addImpulse(e,a);F++;p.refreshLaunch(F)}};this.onExit=function(){fa.unload();fa.unloadLevel();$(s_oMain).trigger("share_event",
r);$(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 e=A.ballBody();b=e.position.x;m=e.position.y;n=e.position.z;A.addImpulse(e,a);F++;p.refreshLaunch(F)};this.moveBall=function(){var b=N;v.setPosition(b.x,b.y)};this.levelComplete=function(){l=!1;$(s_oMain).trigger("end_level",q);var b=s_oSpriteLibrary.getSprite("msg_box");
K=new CLevelCompletePanel(b);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(b){R=A.ballBody().position.z;!J&&b&&(J=!0,(new createjs.Tween.get(T,{override:!0})).to({alpha:1},
100));J&&!b&&(J=!1,U||(new createjs.Tween.get(T,{override:!0})).to({alpha:0},100))};this.ballCollideWithSand=function(b){b&&!L?(playSound("sand",1,!1),A.setElementLinearDamping(A.ballBody(),BALL_LINEAR_DAMPING_SAND)):!b&&L&&A.setElementLinearDamping(A.ballBody(),BALL_LINEAR_DAMPING);L=b};this.ballCollideWithWater=function(b){E||(G=A.ballBody().position.z);(E=b)?(A.setElementLinearDamping(A.ballBody(),BALL_LINEAR_DAMPING_WATER),A.setGravity(-49.81),b=G-A.ballBody().position.z,v.setWaterMask(-(b/RESTART_WATER_DEPTH_VALUE)+
1),b>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(b){x||(G=A.ballBody().position.z);x=b;var a=G-A.ballBody().position.z;b?(T.visible=!1,v.setHoleMask(-(a/
(HOLE_DEPTH_VALUE+5))+1),a>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<a&&(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 b=new createjs.Shape;b.graphics.beginFill("rgba(0,0,0,1)").r(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);b.alpha=0;s_oStage.addChild(b);(new createjs.Tween.get(b)).to({alpha:1},
500).call(function(){(new createjs.Tween.get(b)).to({alpha:0},500).call(function(){s_oStage.removeChild(b)});fa.repeatLastLaunch()})}};this.repeatLastLaunch=function(){V=!1;v.blink();v.resetMask();O=0;v.pressIndicatorAnim();this.centerBallView();p.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(b,m,n+15);this._updateBall2DPosition()};this._updateInit=
function(){A.update();if(A.ballBody()){this._init2DBall();this._initFlags();p=new CInterface(Z);p.refreshHoleNum(q+1);p.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 c=convert3dPosTo2dScreen({x:START_CAMERA_POSITION.x,y:START_CAMERA_POSITION.y,z:START_CAMERA_POSITION.z},y),l=convert3dPosTo2dScreen(y.position,y);b=c.x-l.x;
c=c.y-l.y;e.setPos(CANVAS_WIDTH/2+b,CANVAS_HEIGHT/2+c);h.x=e.getPos().x;h.y=e.getPos().y;y.updateProjectionMatrix();y.updateMatrixWorld();d=e.getSize().width/2-CANVAS_WIDTH/2-b;g=-(e.getSize().width/2-CANVAS_WIDTH/2)-b;a=e.getSize().height/2-CANVAS_HEIGHT/2-c;f=-(e.getSize().height/2-CANVAS_HEIGHT/2)-c;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(){l&&(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,e){var h=-N.x+CANVAS_WIDTH/2+M.x+b-S.x;S.x+h<d&&S.x+h>g&&(M.x+=b);h=-N.y+CANVAS_HEIGHT/2+M.y+e-S.y;S.y+h<a&&S.y+h>f&&(M.y+=e)};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>d?S.x=d:S.x<g&&(S.x=g);S.y+=(-N.y+CANVAS_HEIGHT/2+M.y-S.y)*da;S.y>a?S.y=a:S.y<f&&(S.y=f)};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 b=s_oSpriteLibrary.getSprite("help_touch");Y=createBitmap(b);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=k.max_shot_power;160<MAX_SHOT_POWER&&(MAX_SHOT_POWER=160);PAR=k.stage_par;var fa=this;this._init(c)}var s_oGame;
function CInterface(k){var c,d,g,a,f,b,m,n,l,r,p,e,h,q,u,t,w,v,z,C,x,D,F,K,B,P,Q,H=null,E=null;this._init=function(k){h=CANVAS_WIDTH/2;q=72;B=new createjs.Text(TEXT_LAUNCH+": 0","40px "+PRIMARY_FONT,"#3e240b");B.x=h;B.y=q;B.outline=8;B.textAlign="center";B.textBaseline="alphabetic";k.addChild(B);z=new createjs.Text(TEXT_LAUNCH+": 0","40px "+PRIMARY_FONT,"#ffd800");z.x=h;z.y=q;z.textAlign="center";z.textBaseline="alphabetic";k.addChild(z);l=26;r=72;K=new createjs.Text(TEXT_PAR+": 0","40px "+PRIMARY_FONT,
"#3e240b");K.x=l;K.y=r;K.outline=8;K.textAlign="left";K.textBaseline="alphabetic";k.addChild(K);C=new createjs.Text(TEXT_PAR+": 0","40px "+PRIMARY_FONT,"#ffd800");C.x=l;C.y=r;C.textAlign="left";C.textBaseline="alphabetic";k.addChild(C);p=CANVAS_WIDTH-28;e=CANVAS_HEIGHT-35;P=new createjs.Text(TEXT_HOLE+": 1","40px "+PRIMARY_FONT,"#3e240b");P.x=p;P.y=e;P.outline=8;P.textAlign="right";P.textBaseline="alphabetic";k.addChild(P);x=new createjs.Text(TEXT_HOLE+": 1","40px "+PRIMARY_FONT,"#ffd800");x.x=p;
x.y=e;x.textAlign="right";x.textBaseline="alphabetic";k.addChild(x);var A=s_oSpriteLibrary.getSprite("but_exit");g=CANVAS_WIDTH-A.height/2-10;a=A.height/2+17;w=new CGfxButton(g,a,A,k);w.addEventListener(ON_MOUSE_UP,this._onExit,this);A=s_oSpriteLibrary.getSprite("but_restart_small");c=g-A.height-10;d=a;v=new CGfxButton(c,d,A,k);v.addEventListener(ON_MOUSE_UP,this._onRestart,this);!1===DISABLE_SOUND_MOBILE||!1===s_bMobile?(A=s_oSpriteLibrary.getSprite("audio_icon"),u=c-A.height-10,t=a,D=new CToggle(u,
t,A,s_bAudioActive,k),D.addEventListener(ON_MOUSE_UP,this._onAudioToggle,this),f=u-A.width/2-10,b=t):(f=c-A.width/2-10,b=d);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(f,b,A,s_bFullscreen,k),Q.addEventListener(ON_MOUSE_UP,
this._onFullscreenRelease,this));A=s_oSpriteLibrary.getSprite("but_center_view");m=A.height/2+10;n=CANVAS_HEIGHT-A.height/2-10;F=new CGfxButton(m,n,A,k);F.addEventListener(ON_MOUSE_UP,this._onCenterBall,this);F.setVisible(!1);this.refreshButtonPos(s_iOffsetX,s_iOffsetY)};this.refreshButtonPos=function(h,k){w.setPosition(g-h,k+a);v.setPosition(c-h,k+d);F.setPosition(m+h,n-k);!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||D.setPosition(u-h,k+t);H&&screenfull.enabled&&Q.setPosition(f-h,b+k);z.y=q+k;B.y=
z.y;x.x=p-h;x.y=e-k;P.x=x.x;P.y=x.y;C.x=l+h;C.y=r+k;K.x=C.x;K.y=C.y};this.refreshPowerBar=function(b){(void 0).graphics.clear();b=Math.floor(b*(void 0).width/100);(void 0).graphics.beginFill("rgba(255,255,255,0.01)").drawRect((void 0).x,(void 0).y,b,(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(b){z.text=TEXT_LAUNCH+": "+b;B.text=TEXT_LAUNCH+
": "+b};this.setParText=function(b){C.text=TEXT_PAR+": "+b;K.text=TEXT_PAR+": "+b};this.refreshHoleNum=function(b){x.text=TEXT_HOLE+": "+b;P.text=TEXT_HOLE+": "+b};this.setCenterBallViewVisible=function(b){F.setVisible(b)};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(k);return this}var s_oInterface=null;
function CCreditsPanel(){var k,c,d,g,a,f;this._init=function(){a=new createjs.Shape;a.graphics.beginFill("#0f0f0f").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);a.alpha=.01;f=a.on("click",this._onLogoButRelease);s_oStage.addChild(a);k=new createjs.Shape;k.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);k.alpha=0;s_oStage.addChild(k);(new createjs.Tween.get(k)).to({alpha:.7},500);c=new createjs.Container;s_oStage.addChild(c);var b=s_oSpriteLibrary.getSprite("msg_box"),m=createBitmap(b);
m.regX=b.width/2;m.regY=b.height/2;c.addChild(m);c.x=CANVAS_WIDTH/2;c.y=CANVAS_HEIGHT/2;c.alpha=0;(new createjs.Tween.get(c)).to({alpha:1},500);m=new createjs.Text(TEXT_DEVELOPED," 30px "+PRIMARY_FONT,"#3e240b");m.y=-b.height/2+175;m.textAlign="center";m.textBaseline="middle";m.lineWidth=500;m.outline=8;c.addChild(m);b=new createjs.Text(TEXT_DEVELOPED," 30px "+PRIMARY_FONT,"#ffd800");b.y=m.y;b.textAlign="center";b.textBaseline="middle";b.lineWidth=500;c.addChild(b);b=new createjs.Text("WebOas.is",
" 30px "+PRIMARY_FONT,"#3e240b");b.y=160;b.textAlign="center";b.textBaseline="middle";b.lineWidth=500;b.outline=8;c.addChild(b);m=new createjs.Text("WebOas.is"," 30px "+PRIMARY_FONT,"#ffd800");m.y=b.y;m.textAlign="center";m.textBaseline="middle";m.lineWidth=500;c.addChild(m);b=s_oSpriteLibrary.getSprite("ctl_logo");g=createBitmap(b);g.regX=b.width/2;g.regY=b.height/2;c.addChild(g);b=s_oSpriteLibrary.getSprite("but_exit");d=new CGfxButton(330,-200,b,c);d.addEventListener(ON_MOUSE_UP,this.unload,
this)};this.unload=function(){d.setClickable(!1);(new createjs.Tween.get(k)).to({alpha:0},500);(new createjs.Tween.get(c)).to({alpha:0},500).call(function(){s_oStage.removeChild(k);s_oStage.removeChild(c);d.unload()});a.off("click",f)};this._onLogoButRelease=function(){window.open("https://WebOas.is")};this._onMoreGamesReleased=function(){window.open("http://codecanyon.net/collections/5409142-games")};this._init()}
function CHelpPanel(k){var c,d,g,a,f,b;this._init=function(b){var l=s_bMobile?TEXT_HELP1_MOBILE:TEXT_HELP1_PC;d=new createjs.Text(l,"24px "+PRIMARY_FONT,"#3e240b");d.textAlign="center";d.lineWidth=500;d.textBaseline="alphabetic";d.outline=8;d.x=.5*CANVAS_WIDTH-200;d.y=.5*CANVAS_HEIGHT-180;c=new createjs.Text(l,"24px "+PRIMARY_FONT,"#ffd800");c.textAlign="center";c.lineWidth=500;c.textBaseline="alphabetic";c.x=d.x;c.y=d.y;a=new createjs.Shape;a.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,
CANVAS_HEIGHT);a.alpha=.7;g=new createjs.Container;g.x=0;g.y=0;g.addChild(a,d,c);b.addChild(g);s_oGame.getBall().setVisible(!1);b=s_oSpriteLibrary.getSprite("ball");f=new CBall(800,484,b,g);f.setHelpAnim();f.setMoving(!0)};this.unload=function(){k.removeChild(g);g.off("mousedown",b)};this.stage1Help=function(){var a=this;b=g.on("mousedown",function(){a._onExitHelp()})};this.stage2Help=function(n){d.text=TEXT_HELP2;c.text=TEXT_HELP2;d.visible=!1;c.visible=!1;g.off("mousedown",b);s_oGame.getBall().setVisible(!0);
f.unload();a.alpha=0;createjs.Tween.get(a).to({alpha:.7},1E3).call(function(){d.visible=!0;c.visible=!0;b=g.on("mousedown",function(){m._onExitHelp2(n)});s_oGame.panHelpAnim()})};this._onExitHelp=function(){this.unload();s_oGame._onExitHelp()};this._onExitHelp2=function(b){this.unload();s_oGame.stopPanAnim();s_oGame._onExitHelp2(b)};var m=this;this._init(k)}
function CEndPanel(k){var c,d,g,a,f,b;this._init=function(m){setVolume("soundtrack",1);b=new createjs.Shape;b.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);b.alpha=1;b.on("mousedown",function(){});s_oStage.addChild(b);c=createBitmap(m);c.regX=m.width/2;c.regY=m.height/2;c.x=CANVAS_WIDTH/2;c.y=CANVAS_HEIGHT/2;g=new createjs.Text("","50px "+PRIMARY_FONT,"#3e240b");g.x=CANVAS_WIDTH/2;g.y=CANVAS_HEIGHT/2-100;g.outline=10;g.textAlign="center";g.textBaseline="alphabetic";g.lineWidth=
500;d=new createjs.Text("","50px "+PRIMARY_FONT,"#ffd800");d.x=g.x;d.y=g.y;d.textAlign="center";d.textBaseline="alphabetic";d.lineWidth=500;a=new createjs.Container;a.alpha=0;a.visible=!1;a.addChild(c,g,d);m=s_oSpriteLibrary.getSprite("but_home");f=new CGfxButton(.5*CANVAS_WIDTH,.5*CANVAS_HEIGHT+180,m,a);f.addEventListener(ON_MOUSE_DOWN,this._onExit,this);s_oStage.addChild(a);$(s_oMain).trigger("show_interlevel_ad")};this.unload=function(){};this.show=function(c,f,l){g.text=TEXT_ALL_COMPLETE;d.text=
TEXT_ALL_COMPLETE;a.visible=!0;createjs.Tween.get(a).to({alpha:1},500);createjs.Tween.get(b).to({alpha:.7},500)};this._onExit=function(){s_oStage.removeChild(a);f.unload();f=null;s_oGame.onExit()};this._init(k);return this}
function CAreYouSurePanel(k){var c,d,g,a,f,b,m;this._init=function(l){g=new createjs.Shape;g.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);g.alpha=0;m=g.on("mousedown",function(){});s_oStage.addChild(g);(new createjs.Tween.get(g)).to({alpha:.7},500);b=new createjs.Container;s_oStage.addChild(b);l=s_oSpriteLibrary.getSprite("msg_box");var r=createBitmap(l);r.regX=l.width/2;r.regY=l.height/2;b.addChild(r);b.x=CANVAS_WIDTH/2;b.y=CANVAS_HEIGHT/2;b.alpha=0;(new createjs.Tween.get(b)).to({alpha:1},
500);a=new createjs.Text(TEXT_ARE_SURE," 30px "+PRIMARY_FONT,"#3e240b");a.y=-l.height/2+200;a.textAlign="center";a.textBaseline="middle";a.lineWidth=700;a.outline=8;b.addChild(a);f=new createjs.Text(TEXT_ARE_SURE," 30px "+PRIMARY_FONT,"#ffd800");f.y=a.y;f.textAlign="center";f.textBaseline="middle";f.lineWidth=a.lineWidth;b.addChild(f);c=new CGfxButton(110,180,s_oSpriteLibrary.getSprite("but_yes"),b);c.addEventListener(ON_MOUSE_UP,this._onButYes,this);d=new CGfxButton(-110,180,s_oSpriteLibrary.getSprite("but_not"),
b);d.addEventListener(ON_MOUSE_UP,this._onButNo,this);d.pulseAnimation()};this._onButYes=function(){d.setClickable(!1);c.setClickable(!1);(new createjs.Tween.get(g)).to({alpha:1},500);(new createjs.Tween.get(b)).to({alpha:0},500).call(function(){n.unload();k()})};this._onButNo=function(){d.setClickable(!1);c.setClickable(!1);(new createjs.Tween.get(g)).to({alpha:0},500);(new createjs.Tween.get(b)).to({alpha:0},500).call(function(){n.unload()})};this.unload=function(){d.unload();c.unload();s_oStage.removeChild(g);
s_oStage.removeChild(b);g.off("mousedown",m)};this.changeMessage=function(b){a.text=b;f.text=b};var n=this;this._init(k)}var STAR_EFFECT_ALPHA=0,STAR_EFFECT_SCALE=1;
function CAchievementStars(k,c,d,g,a){var f,b,m,n;this._init=function(a,c,e,h,l){f=3;n=new createjs.Container;n.x=c;n.y=e;h.addChild(n);c=a.width/2;e=a.height;a=new createjs.SpriteSheet({images:[a],frames:{width:c,height:e,regX:c/2,regY:e/2},animations:{lit:[0],unlit:[1]}});b=[];for(e=0;e<f;e++)b[e]=createSprite(a,"unlit",0,0,0,0),b[e].x=-((f-1)*(c+0))/2+e*(c+0),n.addChild(b[e]);m=[];for(e=0;e<f;e++)m[e]=createSprite(a,"lit",0,0,0,0),m[e].x=-((f-1)*(c+0))/2+e*(c+0),m[e].scaleX=m[e].scaleY=0,m[e].alpha=
0,n.addChild(m[e]);m[1].y=-10;m[0].y=10;m[2].y=10;b[1].y=-10;b[0].y=10;b[2].y=10};this.unload=function(){for(var b=0;b<f;b++)new createjs.Tween.removeTweens(m[b]);g.removeChild(n)};this.getContainer=function(){return n};this.startLitStar=function(b){for(var a=0;a<b;a++)m[a].scaleX=m[a].scaleY=1,m[a].alpha=1};this.playSequentialMode=function(b,a,e){a/=b-1;switch(e){case STAR_EFFECT_SCALE:for(e=0;e<f;e++)m[e].alpha=1;for(e=0;e<b;e++)(new createjs.Tween.get(m[e])).wait(e*a).call(function(){l._playSound()}).to({scaleX:1,
scaleY:1},1500,createjs.Ease.elasticOut);break;case STAR_EFFECT_ALPHA:for(e=0;e<f;e++)m[e].scaleX=m[e].scaleY=1;for(e=0;e<b;e++)(new createjs.Tween.get(m[e])).wait(e*a).call(function(){l._playSound()}).to({alpha:1},750)}};this.playManualMode=function(b,a){switch(a){case STAR_EFFECT_SCALE:m[b].alpha=1;(new createjs.Tween.get(m[b])).to({scaleX:1,scaleY:1},1500,createjs.Ease.elasticOut);break;case STAR_EFFECT_ALPHA:m[b].scaleX=m[b].scaleY=1,(new createjs.Tween.get(m[b])).to({alpha:1},750)}this._playSound()};
this._playSound=function(){playSound(a,1,!1)};var l=this;this._init(k,c,d,g,a)}
function CLevelCompletePanel(k){var c,d,g,a,f,b,m,n,l,r,p,e,h,q,u,t,w;this._init=function(e){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);d=createBitmap(e);d.regX=e.width/2;d.regY=e.height/2;d.x=CANVAS_WIDTH/2;d.y=CANVAS_HEIGHT/2;r=new createjs.Text("","50px "+PRIMARY_FONT,"#3e240b");r.x=CANVAS_WIDTH/2;r.y=CANVAS_HEIGHT/2-80;r.outline=10;r.textAlign="center";r.textBaseline=
"alphabetic";l=new createjs.Text("","50px "+PRIMARY_FONT,"#ffd800");l.x=r.x;l.y=r.y;l.textAlign="center";l.textBaseline="alphabetic";m=new createjs.Text("","30px "+PRIMARY_FONT,"#3e240b");m.x=CANVAS_WIDTH/2;m.y=r.y+100;m.outline=10;m.textAlign="center";m.textBaseline="alphabetic";n=new createjs.Text("","30px "+PRIMARY_FONT,"#ffd800");n.x=CANVAS_WIDTH/2;n.y=m.y;n.textAlign="center";n.textBaseline="alphabetic";g=new createjs.Text("","30px "+PRIMARY_FONT,"#3e240b");g.x=CANVAS_WIDTH/2-140;g.y=r.y+160;
g.outline=10;g.textAlign="center";g.textBaseline="alphabetic";a=new createjs.Text("","30px "+PRIMARY_FONT,"#ffd800");a.x=g.x;a.y=g.y;a.textAlign="center";a.textBaseline="alphabetic";f=new createjs.Text("0","30px "+PRIMARY_FONT,"#3e240b");f.x=CANVAS_WIDTH/2+140;f.y=g.y;f.outline=10;f.textAlign="center";f.textBaseline="alphabetic";b=new createjs.Text("0","30px "+PRIMARY_FONT,"#ffd800");b.x=f.x;b.y=a.y;b.textAlign="center";b.textBaseline="alphabetic";p=new createjs.Container;p.alpha=0;p.visible=!1;p.addChild(d,
g,a,r,l,m,n,f,b);s_oStage.addChild(p);$(s_oMain).trigger("show_interlevel_ad")};this._unload=function(){createjs.Tween.get(p).to({alpha:0},300).call(function(){s_oStage.removeChild(p);q.off("mousedown",w);s_oStage.removeChild(q);h.unload();h=null;e.unload();e=null})};this.show=function(c,d,k){r.text=TEXT_COMPLETE;l.text=TEXT_COMPLETE;d=c-PAR[k];c=this._scoreType(d,c);m.text=c;n.text=c;g.text=TEXT_SCORE+": ";a.text=TEXT_SCORE+": ";c=this._calculateScore(d);p.visible=!0;var w=this;createjs.Tween.get(p).to({alpha:1},
500).call(function(){var b=s_oSpriteLibrary.getSprite("but_continue_big");e=new CGfxButton(.5*CANVAS_WIDTH+100,.5*CANVAS_HEIGHT+180,b,p);e.addEventListener(ON_MOUSE_DOWN,w._onNext,this);b=s_oSpriteLibrary.getSprite("but_restart_big");h=new CGfxButton(.5*CANVAS_WIDTH-100,.5*CANVAS_HEIGHT+180,b,p);h.addEventListener(ON_MOUSE_DOWN,w._onRestart,this)});createjs.Tween.get(q).to({alpha:.7},500);d=s_oSpriteLibrary.getSprite("star");u=new CAchievementStars(d,CANVAS_WIDTH/2,CANVAS_HEIGHT/2-210,p,"star");t=
new CRollingTextController(b,f,c,8E3,EASE_CUBIC_OUT);t.addEventListener(ON_CONTROLLER_END,v._onFinishRolling);t.addEventListener(ON_CONTROLLER_REMOVE,v._onFinishRolling);t.addRollingListener(v._onRollingText,v,[0,PAR_POINTS-ADDED_POINTS,PAR_POINTS]);this._sendScore(k,c)};this._scoreType=function(b,a){switch(b){case -5:var e=TEXT_PHOENIX;break;case -4:e=TEXT_CONDOR;break;case -3:e=TEXT_ALBATROSS;break;case -2:e=TEXT_EAGLE;break;case -1:e=TEXT_BIRDIE;break;case 0:e=TEXT_PAR;break;case 1:e=TEXT_BOGEY;
break;case 2:e=TEXT_DOUBLE_BOGEY;break;default:e=TEXT_BOGEY+" "+b}1===a&&(e=TEXT_HOLEINONE);return e};this._findMinimumScore=function(){for(var b=PAR_POINTS,a=0;0<b;)a++,b-=ADDED_POINTS;b+=ADDED_POINTS;return{score:b,iter:a}};this._calculateScore=function(b){var a=PAR_POINTS-b*ADDED_POINTS;0>=a&&(a=this._findMinimumScore(),a=Math.floor(a.score/(b-a.iter+1)));return a};this._sendScore=function(b,a){var e=s_oLocalStorage.getItemJson(LOCALSTORAGE_SCORE);e[b]<a&&(e[b]=a,s_oLocalStorage.setItemJson(LOCALSTORAGE_SCORE,
e));for(var h=c=0;h<e.length;h++)c+=e[h];$(s_oMain).trigger("save_score",c)};this._onNext=function(){createjs.Tween.get(q).to({alpha:1},300);createjs.Tween.get(p).to({alpha:0},300).wait(100).call(function(){s_oStage.removeChild(p);q.off("mousedown",w);s_oStage.removeChild(q);h.unload();h=null;e.unload();e=null;s_oGame.nextLevel()})};this._onRestart=function(){createjs.Tween.get(q).to({alpha:1},300);createjs.Tween.get(p).to({alpha:0},300).wait(100).call(function(){s_oStage.removeChild(p);q.off("mousedown",
w);s_oStage.removeChild(q);h.unload();h=null;e.unload();e=null;s_oGame.restartLevel()})};this._onFinishRolling=function(){};this._onRollingRemoved=function(){};this._onRollingText=function(b){u.playManualMode(b,STAR_EFFECT_SCALE)};var v=this;this._init(k);return this}
!function(k){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=k();else{var c;"undefined"!=typeof window?c=window:"undefined"!=typeof global?c=global:"undefined"!=typeof self&&(c=self);c.CANNON=k()}}(function(){return function a(c,d,g){function f(m,l){if(!d[m]){if(!c[m]){var r="function"==typeof require&&require;if(!l&&r)return r(m,!0);if(b)return b(m,!0);throw Error("Cannot find module '"+m+"'");}r=d[m]={exports:{}};c[m][0].call(r.exports,function(b){var a=c[m][1][b];return f(a?
a:b)},r,r.exports,a,c,d,g)}return d[m].exports}for(var b="function"==typeof require&&require,m=0;m<g.length;m++)f(g[m]);return f}({1:[function(c,d,g){d.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(c,d,g){d.exports={version:c("../package.json").version,AABB:c("./collision/AABB"),ArrayCollisionMatrix:c("./collision/ArrayCollisionMatrix"),
Body:c("./objects/Body"),Box:c("./shapes/Box"),Broadphase:c("./collision/Broadphase"),Constraint:c("./constraints/Constraint"),ContactEquation:c("./equations/ContactEquation"),Narrowphase:c("./world/Narrowphase"),ConeTwistConstraint:c("./constraints/ConeTwistConstraint"),ContactMaterial:c("./material/ContactMaterial"),ConvexPolyhedron:c("./shapes/ConvexPolyhedron"),Cylinder:c("./shapes/Cylinder"),DistanceConstraint:c("./constraints/DistanceConstraint"),Equation:c("./equations/Equation"),EventTarget:c("./utils/EventTarget"),
FrictionEquation:c("./equations/FrictionEquation"),GSSolver:c("./solver/GSSolver"),GridBroadphase:c("./collision/GridBroadphase"),Heightfield:c("./shapes/Heightfield"),HingeConstraint:c("./constraints/HingeConstraint"),LockConstraint:c("./constraints/LockConstraint"),Mat3:c("./math/Mat3"),Material:c("./material/Material"),NaiveBroadphase:c("./collision/NaiveBroadphase"),ObjectCollisionMatrix:c("./collision/ObjectCollisionMatrix"),Pool:c("./utils/Pool"),Particle:c("./shapes/Particle"),Plane:c("./shapes/Plane"),
PointToPointConstraint:c("./constraints/PointToPointConstraint"),Quaternion:c("./math/Quaternion"),Ray:c("./collision/Ray"),RaycastVehicle:c("./objects/RaycastVehicle"),RaycastResult:c("./collision/RaycastResult"),RigidVehicle:c("./objects/RigidVehicle"),RotationalEquation:c("./equations/RotationalEquation"),RotationalMotorEquation:c("./equations/RotationalMotorEquation"),SAPBroadphase:c("./collision/SAPBroadphase"),SPHSystem:c("./objects/SPHSystem"),Shape:c("./shapes/Shape"),Solver:c("./solver/Solver"),
Sphere:c("./shapes/Sphere"),SplitSolver:c("./solver/SplitSolver"),Spring:c("./objects/Spring"),Trimesh:c("./shapes/Trimesh"),Vec3:c("./math/Vec3"),Vec3Pool:c("./utils/Vec3Pool"),World:c("./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(c,d,g){function a(b){b=b||{};
this.lowerBound=new f;b.lowerBound&&this.lowerBound.copy(b.lowerBound);this.upperBound=new f;b.upperBound&&this.upperBound.copy(b.upperBound)}var f=c("../math/Vec3");c("../utils/Utils");d.exports=a;var b=new f;a.prototype.setFromPoints=function(a,c,f,p){var e=this.lowerBound,h=this.upperBound;e.copy(a[0]);f&&f.vmult(e,e);h.copy(e);for(var l=1;l<a.length;l++){var d=a[l];f&&(f.vmult(d,b),d=b);d.x>h.x&&(h.x=d.x);d.x<e.x&&(e.x=d.x);d.y>h.y&&(h.y=d.y);d.y<e.y&&(e.y=d.y);d.z>h.z&&(h.z=d.z);d.z<e.z&&(e.z=
d.z)}c&&(c.vadd(e,e),c.vadd(h,h));p&&(e.x-=p,e.y-=p,e.z-=p,h.x+=p,h.y+=p,h.z+=p);return this};a.prototype.copy=function(b){this.lowerBound.copy(b.lowerBound);this.upperBound.copy(b.upperBound);return this};a.prototype.clone=function(){return(new a).copy(this)};a.prototype.extend=function(b){var a=b.lowerBound.x;this.lowerBound.x>a&&(this.lowerBound.x=a);a=b.upperBound.x;this.upperBound.x<a&&(this.upperBound.x=a);a=b.lowerBound.y;this.lowerBound.y>a&&(this.lowerBound.y=a);a=b.upperBound.y;this.upperBound.y<
a&&(this.upperBound.y=a);a=b.lowerBound.z;this.lowerBound.z>a&&(this.lowerBound.z=a);a=b.upperBound.z;this.upperBound.z<a&&(this.upperBound.z=a)};a.prototype.overlaps=function(b){var a=this.lowerBound,c=this.upperBound,f=b.lowerBound;b=b.upperBound;return(f.x<=c.x&&c.x<=b.x||a.x<=b.x&&b.x<=c.x)&&(f.y<=c.y&&c.y<=b.y||a.y<=b.y&&b.y<=c.y)&&(f.z<=c.z&&c.z<=b.z||a.z<=b.z&&b.z<=c.z)};a.prototype.contains=function(b){var a=this.lowerBound,c=this.upperBound,f=b.lowerBound;b=b.upperBound;return a.x<=f.x&&
c.x>=b.x&&a.y<=f.y&&c.y>=b.y&&a.z<=f.z&&c.z>=b.z};a.prototype.getCorners=function(b,a,c,f,e,h,q,d){var l=this.lowerBound,p=this.upperBound;b.copy(l);a.set(p.x,l.y,l.z);c.set(p.x,p.y,l.z);f.set(l.x,p.y,p.z);e.set(p.x,l.y,l.z);h.set(l.x,p.y,l.z);q.set(l.x,l.y,p.z);d.copy(p)};var m=[new f,new f,new f,new f,new f,new f,new f,new f];a.prototype.toLocalFrame=function(b,a){this.getCorners(m[0],m[1],m[2],m[3],m[4],m[5],m[6],m[7]);for(var c=0;8!==c;c++){var f=m[c];b.pointToLocal(f,f)}return a.setFromPoints(m)};
a.prototype.toWorldFrame=function(b,a){this.getCorners(m[0],m[1],m[2],m[3],m[4],m[5],m[6],m[7]);for(var c=0;8!==c;c++){var f=m[c];b.pointToWorld(f,f)}return a.setFromPoints(m)}},{"../math/Vec3":30,"../utils/Utils":53}],4:[function(c,d,g){function a(){this.matrix=[]}d.exports=a;a.prototype.get=function(a,b){a=a.index;b=b.index;if(b>a){var c=b;b=a;a=c}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 f=b;b=a;a=f}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(c,d,g){function a(){this.world=null;this.useBoundingBoxes=!1;this.dirty=!0}var f=c("../objects/Body");g=c("../math/Vec3");var b=c("../math/Quaternion");c("../shapes/Shape");c("../shapes/Plane");d.exports=a;a.prototype.collisionPairs=function(b,a,e){throw Error("collisionPairs not implemented for this BroadPhase class!");};var m=
f.STATIC|f.KINEMATIC;a.prototype.needBroadphaseCollision=function(b,a){return 0!==(b.collisionFilterGroup&a.collisionFilterMask)&&0!==(a.collisionFilterGroup&b.collisionFilterMask)&&(0===(b.type&m)&&b.sleepState!==f.SLEEPING||0===(a.type&m)&&a.sleepState!==f.SLEEPING)?!0:!1};a.prototype.intersectionTest=function(b,a,e,c){this.useBoundingBoxes?this.doBoundingBoxBroadphase(b,a,e,c):this.doBoundingSphereBroadphase(b,a,e,c)};var n=new g;new g;new b;new g;a.prototype.doBoundingSphereBroadphase=function(b,
a,e,c){a.position.vsub(b.position,n);var h=Math.pow(b.boundingRadius+a.boundingRadius,2);n.norm2()<h&&(e.push(b),c.push(a))};a.prototype.doBoundingBoxBroadphase=function(b,a,e,c){b.aabbNeedsUpdate&&b.computeAABB();a.aabbNeedsUpdate&&a.computeAABB();b.aabb.overlaps(a.aabb)&&(e.push(b),c.push(a))};var l={keys:[]},r=[],p=[];a.prototype.makePairsUnique=function(b,a){for(var e=b.length,c=0;c!==e;c++)r[c]=b[c],p[c]=a[c];b.length=0;for(c=a.length=0;c!==e;c++){var h=r[c].id,f=p[c].id;h=h<f?h+","+f:f+","+
h;l[h]=c;l.keys.push(h)}for(c=0;c!==l.keys.length;c++)h=l.keys.pop(),e=l[h],b.push(r[e]),a.push(p[e]),delete l[h]};a.prototype.setWorld=function(b){};var e=new g;a.boundingSphereCheck=function(b,a){b.position.vsub(a.position,e);return Math.pow(b.shape.boundingSphereRadius+a.shape.boundingSphereRadius,2)>e.norm2()};a.prototype.aabbQuery=function(b,a,e){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(c,d,g){function a(a,c,d,e,h){f.apply(this);this.nx=d||10;this.ny=e||10;this.nz=h||10;this.aabbMin=a||new b(100,100,100);this.aabbMax=c||new b(-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(c=0;c<a;c++)this.bins[c]=[],this.binLengths[c]=0}d.exports=a;var f=c("./Broadphase"),b=c("../math/Vec3"),m=c("../shapes/Shape");
a.prototype=new f;a.prototype.constructor=a;var n=new b;new b;a.prototype.collisionPairs=function(b,a,c){function e(b,a,e,c,h,f,l){b=(b-K)*Q|0;a=(a-B)*H|0;e=(e-P)*E|0;c=J((c-K)*Q);h=J((h-B)*H);f=J((f-P)*E);0>b?b=0:b>=d&&(b=d-1);0>a?a=0:a>=p&&(a=p-1);0>e?e=0:e>=r&&(e=r-1);0>c?c=0:c>=d&&(c=d-1);0>h?h=0:h>=p&&(h=p-1);0>f?f=0:f>=r&&(f=r-1);b*=g;a*=C;e*=1;c*=g;h*=C;for(f*=1;b<=c;b+=g)for(var q=a;q<=h;q+=C)for(var m=e;m<=f;m+=1){var n=b+q+m;W[n][y[n]++]=l}}var h=b.numObjects();b=b.bodies;var f=this.aabbMax,
l=this.aabbMin,d=this.nx,p=this.ny,r=this.nz,g=p*r,C=r,x=f.x,D=f.y,F=f.z,K=l.x,B=l.y,P=l.z,Q=d/(x-K),H=p/(D-B),E=r/(F-P);x=(x-K)/d;var I=(D-B)/p;F=(F-P)/r;var A=.5*Math.sqrt(x*x+I*I+F*F);D=m.types;var N=D.SPHERE,L=D.PLANE,W=this.bins,y=this.binLengths;D=this.bins.length;for(l=0;l!==D;l++)y[l]=0;var J=Math.ceil;l=Math.min;f=Math.max;for(l=0;l!==h;l++){f=b[l];var V=f.shape;switch(V.type){case N:var U=f.position.x,R=f.position.y,G=f.position.z;V=V.radius;e(U-V,R-V,G-V,U+V,R+V,G+V,f);break;case L:V.worldNormalNeedsUpdate&&
V.computeWorldNormal(f.quaternion);G=V.worldNormal;V=B+.5*I-f.position.y;var O=P+.5*F-f.position.z,T=n;T.set(K+.5*x-f.position.x,V,O);for(var M=U=0;U!==d;U++,M+=g,T.y=V,T.x+=x)for(var S=R=0;R!==p;R++,S+=C,T.z=O,T.y+=I)for(var Z=0,X=0;Z!==r;Z++,X+=1,T.z+=F)if(T.dot(G)<A){var ja=M+S+X;W[ja][y[ja]++]=f}break;default:f.aabbNeedsUpdate&&f.computeAABB(),e(f.aabb.lowerBound.x,f.aabb.lowerBound.y,f.aabb.lowerBound.z,f.aabb.upperBound.x,f.aabb.upperBound.y,f.aabb.upperBound.z,f)}}for(l=0;l!==D;l++)if(h=y[l],
1<h)for(b=W[l],U=0;U!==h;U++)for(f=b[U],R=0;R!==U;R++)x=b[R],this.needBroadphaseCollision(f,x)&&this.intersectionTest(f,x,a,c);this.makePairsUnique(a,c)}},{"../math/Vec3":30,"../shapes/Shape":43,"./Broadphase":5}],7:[function(c,d,g){function a(){f.apply(this)}d.exports=a;var f=c("./Broadphase");c=c("./AABB");a.prototype=new f;a.prototype.constructor=a;a.prototype.collisionPairs=function(b,a,c){b=b.bodies;var f=b.length,d,p;for(d=0;d!==f;d++)for(p=0;p!==d;p++){var e=b[d];var h=b[p];this.needBroadphaseCollision(e,
h)&&this.intersectionTest(e,h,a,c)}};new c;a.prototype.aabbQuery=function(b,a,c){c=c||[];for(var f=0;f<b.bodies.length;f++){var d=b.bodies[f];d.aabbNeedsUpdate&&d.computeAABB();d.aabb.overlaps(a)&&c.push(d)}return c}},{"./AABB":3,"./Broadphase":5}],8:[function(c,d,g){function a(){this.matrix={}}d.exports=a;a.prototype.get=function(a,b){a=a.id;b=b.id;if(b>a){var c=b;b=a;a=c}return a+"-"+b in this.matrix};a.prototype.set=function(a,b,c){a=a.id;b=b.id;if(b>a){var f=b;b=a;a=f}c?this.matrix[a+"-"+b]=!0:
delete this.matrix[a+"-"+b]};a.prototype.reset=function(){this.matrix={}};a.prototype.setNumObjects=function(a){}},{}],9:[function(c,d,g){function a(e,c){this.from=e?e.clone():new b;this.to=c?c.clone():new b;this._direction=new b;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(b){}}function f(b,a,c,h){h.vsub(a,N);c.vsub(a,p);b.vsub(a,e);b=N.dot(N);
a=N.dot(p);c=N.dot(e);h=p.dot(p);var f=p.dot(e),l,d;return 0<=(l=h*c-a*f)&&0<=(d=b*f-a*c)&&l+d<b*h-a*a}d.exports=a;var b=c("../math/Vec3");d=c("../math/Quaternion");var m=c("../math/Transform");c("../shapes/ConvexPolyhedron");c("../shapes/Box");var n=c("../collision/RaycastResult");g=c("../shapes/Shape");c=c("../collision/AABB");a.prototype.constructor=a;a.CLOSEST=1;a.ANY=2;a.ALL=4;var l=new c,r=[];a.prototype.intersectWorld=function(b,e){this.mode=e.mode||a.ANY;this.result=e.result||new n;this.skipBackfaces=
!!e.skipBackfaces;this.collisionFilterMask="undefined"!==typeof e.collisionFilterMask?e.collisionFilterMask:-1;this.collisionFilterGroup="undefined"!==typeof e.collisionFilterGroup?e.collisionFilterGroup:-1;e.from&&this.from.copy(e.from);e.to&&this.to.copy(e.to);this.callback=e.callback||function(){};this.hasHit=!1;this.result.reset();this._updateDirection();this.getAABB(l);r.length=0;b.broadphase.aabbQuery(b,l,r);this.intersectBodies(r);return this.hasHit};var p=new b,e=new b;a.pointInTriangle=f;
var h=new b,q=new d;a.prototype.intersectBody=function(b,a){a&&(this.result=a,this._updateDirection());var e=this.checkCollisionResponse;if((!e||b.collisionResponse)&&0!==(this.collisionFilterGroup&b.collisionFilterMask)&&0!==(b.collisionFilterGroup&this.collisionFilterMask))for(var c=0,f=b.shapes.length;c<f;c++){var l=b.shapes[c];if(!e||l.collisionResponse)if(b.quaternion.mult(b.shapeOrientations[c],q),b.quaternion.vmult(b.shapeOffsets[c],h),h.vadd(b.position,h),this.intersectShape(l,q,h,b),this.result._shouldStop)break}};
a.prototype.intersectBodies=function(b,a){a&&(this.result=a,this._updateDirection());for(var e=0,c=b.length;!this.result._shouldStop&&e<c;e++)this.intersectBody(b[e])};a.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction);this._direction.normalize()};a.prototype.intersectShape=function(b,a,e,c){var h=this.from,f=this._direction;e.vsub(h,N);var l=N.dot(f);f.mult(l,L);L.vadd(h,L);e.distanceTo(L)>b.boundingSphereRadius||(h=this[b.type])&&h.call(this,b,a,e,c)};new b;new b;var u=
new b,t=new b,w=new b,v=new b;new b;new n;a.prototype.intersectBox=function(b,a,e,c){return this.intersectConvex(b.convexPolyhedronRepresentation,a,e,c)};a.prototype[g.types.BOX]=a.prototype.intersectBox;a.prototype.intersectPlane=function(a,e,c,h){var f=this.from,l=this.to,d=this._direction,q=new b(0,0,1);e.vmult(q,q);var p=new b;f.vsub(c,p);e=p.dot(q);l.vsub(c,p);p=p.dot(q);if(!(0<e*p||f.distanceTo(l)<e||(p=q.dot(d),Math.abs(p)<this.precision))){var m=new b;l=new b;e=new b;f.vsub(c,m);c=-q.dot(m)/
p;d.scale(c,l);f.vadd(l,e);this.reportIntersection(q,e,a,h,-1)}};a.prototype[g.types.PLANE]=a.prototype.intersectPlane;a.prototype.getAABB=function(b){var a=this.to,e=this.from;b.lowerBound.x=Math.min(a.x,e.x);b.lowerBound.y=Math.min(a.y,e.y);b.lowerBound.z=Math.min(a.z,e.z);b.upperBound.x=Math.max(a.x,e.x);b.upperBound.y=Math.max(a.y,e.y);b.upperBound.z=Math.max(a.z,e.z)};var z={faceList:[0]};a.prototype.intersectHeightfield=function(e,c,h,f){var l=new b,d=new a(this.from,this.to);m.pointToLocalFrame(h,
c,d.from,d.from);m.pointToLocalFrame(h,c,d.to,d.to);var q=[],p=null,r=null,n=null,u=null,g=e.getIndexOfPosition(d.from.x,d.from.y,q,!1);g&&(p=q[0],r=q[1],n=q[0],u=q[1]);if(g=e.getIndexOfPosition(d.to.x,d.to.y,q,!1)){if(null===p||q[0]<p)p=q[0];if(null===n||q[0]>n)n=q[0];if(null===r||q[1]<r)r=q[1];if(null===u||q[1]>u)u=q[1]}if(null!==p)for(e.getRectMinMax(p,r,n,u,[]),d=p;d<=n;d++)for(q=r;q<=u;q++){if(this.result._shouldStop)return;e.getConvexTrianglePillar(d,q,!1);m.pointToWorldFrame(h,c,e.pillarOffset,
l);this.intersectConvex(e.pillarConvex,c,l,f,z);if(this.result._shouldStop)return;e.getConvexTrianglePillar(d,q,!0);m.pointToWorldFrame(h,c,e.pillarOffset,l);this.intersectConvex(e.pillarConvex,c,l,f,z)}};a.prototype[g.types.HEIGHTFIELD]=a.prototype.intersectHeightfield;var C=new b,x=new b;a.prototype.intersectSphere=function(b,a,e,c){a=this.from;var h=this.to,f=Math.pow(h.x-a.x,2)+Math.pow(h.y-a.y,2)+Math.pow(h.z-a.z,2),l=2*((h.x-a.x)*(a.x-e.x)+(h.y-a.y)*(a.y-e.y)+(h.z-a.z)*(a.z-e.z)),d=Math.pow(l,
2)-4*f*(Math.pow(a.x-e.x,2)+Math.pow(a.y-e.y,2)+Math.pow(a.z-e.z,2)-Math.pow(b.radius,2));if(!(0>d))if(0===d)a.lerp(h,d,C),C.vsub(e,x),x.normalize(),this.reportIntersection(x,C,b,c,-1);else{var q=(-l-Math.sqrt(d))/(2*f);f=(-l+Math.sqrt(d))/(2*f);0<=q&&1>=q&&(a.lerp(h,q,C),C.vsub(e,x),x.normalize(),this.reportIntersection(x,C,b,c,-1));!this.result._shouldStop&&0<=f&&1>=f&&(a.lerp(h,f,C),C.vsub(e,x),x.normalize(),this.reportIntersection(x,C,b,c,-1))}};a.prototype[g.types.SPHERE]=a.prototype.intersectSphere;
var D=new b;new b;new b;var F=new b;a.prototype.intersectConvex=function(b,a,e,c,h){h=h&&h.faceList||null;for(var l=b.faces,d=b.vertices,q=b.faceNormals,p=this._direction,m=this.from,r=m.distanceTo(this.to),n=h?h.length:l.length,g=this.result,y=0;!g._shouldStop&&y<n;y++){var x=h?h[y]:y,L=l[x],B=q[x],A=a,J=e;F.copy(d[L[0]]);A.vmult(F,F);F.vadd(J,F);F.vsub(m,F);A.vmult(B,D);B=p.dot(D);if(!(Math.abs(B)<this.precision||(B=D.dot(F)/B,0>B)))for(p.mult(B,u),u.vadd(m,u),t.copy(d[L[0]]),A.vmult(t,t),J.vadd(t,
t),B=1;!g._shouldStop&&B<L.length-1;B++){w.copy(d[L[B]]);v.copy(d[L[B+1]]);A.vmult(w,w);A.vmult(v,v);J.vadd(w,w);J.vadd(v,v);var z=u.distanceTo(m);!f(u,t,w,v)&&!f(u,w,t,v)||z>r||this.reportIntersection(D,u,b,c,x)}}};a.prototype[g.types.CONVEXPOLYHEDRON]=a.prototype.intersectConvex;var K=new b,B=new b,P=new b,Q=new b,H=new b,E=new b;new c;var I=[],A=new m;a.prototype.intersectTrimesh=function(b,a,e,c,h){h=b.indices;var l=this.from,d=this.to,q=this._direction;A.position.copy(e);A.quaternion.copy(a);
m.vectorToLocalFrame(e,a,q,B);m.pointToLocalFrame(e,a,l,P);m.pointToLocalFrame(e,a,d,Q);l=P.distanceSquared(Q);b.tree.rayQuery(this,A,I);d=0;for(q=I.length;!this.result._shouldStop&&d!==q;d++){var p=I[d];b.getNormal(p,K);b.getVertex(h[3*p],t);t.vsub(P,F);var r=B.dot(K);r=K.dot(F)/r;0>r||(B.scale(r,u),u.vadd(P,u),b.getVertex(h[3*p+1],w),b.getVertex(h[3*p+2],v),r=u.distanceSquared(P),!f(u,w,t,v)&&!f(u,t,w,v)||r>l||(m.vectorToWorldFrame(a,K,H),m.pointToWorldFrame(e,a,u,E),this.reportIntersection(H,E,
b,c,p)))}I.length=0};a.prototype[g.types.TRIMESH]=a.prototype.intersectTrimesh;a.prototype.reportIntersection=function(b,e,c,h,f){var l=this.from,d=this.to,q=l.distanceTo(e),p=this.result;if(!(this.skipBackfaces&&0<b.dot(this._direction)))switch(p.hitFaceIndex="undefined"!==typeof f?f:-1,this.mode){case a.ALL:this.hasHit=!0;p.set(l,d,b,e,c,h,q);p.hasHit=!0;this.callback(p);break;case a.CLOSEST:if(q<p.distance||!p.hasHit)this.hasHit=!0,p.hasHit=!0,p.set(l,d,b,e,c,h,q);break;case a.ANY:this.hasHit=
!0,p.hasHit=!0,p.set(l,d,b,e,c,h,q),p._shouldStop=!0}};var N=new b,L=new b},{"../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(c,d,g){function a(){this.rayFromWorld=new f;this.rayToWorld=new f;this.hitNormalWorld=new f;this.hitPointWorld=new f;this.hasHit=!1;this.body=this.shape=null;this.distance=this.hitFaceIndex=-1;this._shouldStop=!1}var f=
c("../math/Vec3");d.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(b,a,c,f,d,p,e){this.rayFromWorld.copy(b);this.rayToWorld.copy(a);this.hitNormalWorld.copy(c);this.hitPointWorld.copy(f);this.shape=d;this.body=p;this.distance=
e}},{"../math/Vec3":30}],11:[function(c,d,g){function a(b){f.apply(this);this.axisList=[];this.world=null;this.axisIndex=0;var a=this.axisList;this._addBodyHandler=function(b){a.push(b.body)};this._removeBodyHandler=function(b){b=a.indexOf(b.body);-1!==b&&a.splice(b,1)};b&&this.setWorld(b)}c("../shapes/Shape");var f=c("../collision/Broadphase");d.exports=a;a.prototype=new f;a.prototype.setWorld=function(b){for(var a=this.axisList.length=0;a<b.bodies.length;a++)this.axisList.push(b.bodies[a]);b.removeEventListener("addBody",
this._addBodyHandler);b.removeEventListener("removeBody",this._removeBodyHandler);b.addEventListener("addBody",this._addBodyHandler);b.addEventListener("removeBody",this._removeBodyHandler);this.world=b;this.dirty=!0};a.insertionSortX=function(b){for(var a=1,c=b.length;a<c;a++){for(var f=b[a],d=a-1;0<=d&&!(b[d].aabb.lowerBound.x<=f.aabb.lowerBound.x);d--)b[d+1]=b[d];b[d+1]=f}return b};a.insertionSortY=function(b){for(var a=1,c=b.length;a<c;a++){for(var f=b[a],d=a-1;0<=d&&!(b[d].aabb.lowerBound.y<=
f.aabb.lowerBound.y);d--)b[d+1]=b[d];b[d+1]=f}return b};a.insertionSortZ=function(b){for(var a=1,c=b.length;a<c;a++){for(var f=b[a],d=a-1;0<=d&&!(b[d].aabb.lowerBound.z<=f.aabb.lowerBound.z);d--)b[d+1]=b[d];b[d+1]=f}return b};a.prototype.collisionPairs=function(b,c,f){b=this.axisList;var l=b.length,d=this.axisIndex,p,e;this.dirty&&(this.sortList(),this.dirty=!1);for(p=0;p!==l;p++){var h=b[p];for(e=p+1;e<l;e++){var q=b[e];if(this.needBroadphaseCollision(h,q)){if(!a.checkBounds(h,q,d))break;this.intersectionTest(h,
q,c,f)}}}};a.prototype.sortList=function(){for(var b=this.axisList,c=this.axisIndex,f=b.length,l=0;l!==f;l++){var d=b[l];d.aabbNeedsUpdate&&d.computeAABB()}0===c?a.insertionSortX(b):1===c?a.insertionSortY(b):2===c&&a.insertionSortZ(b)};a.checkBounds=function(b,a,c){if(0===c){var f=b.position.x;var d=a.position.x}else 1===c?(f=b.position.y,d=a.position.y):2===c&&(f=b.position.z,d=a.position.z);return d-a.boundingRadius<f+b.boundingRadius};a.prototype.autoDetectAxis=function(){for(var b=0,a=0,c=0,f=
0,d=0,p=0,e=this.axisList,h=e.length,q=1/h,u=0;u!==h;u++){var g=e[u],w=g.position.x;b+=w;a+=w*w;w=g.position.y;c+=w;f+=w*w;g=g.position.z;d+=g;p+=g*g}b=a-b*b*q;c=f-c*c*q;d=p-d*d*q;this.axisIndex=b>c?b>d?0:2:c>d?1:2};a.prototype.aabbQuery=function(b,a,c){c=c||[];this.dirty&&(this.sortList(),this.dirty=!1);b=this.axisList;for(var f=0;f<b.length;f++){var d=b[f];d.aabbNeedsUpdate&&d.computeAABB();d.aabb.overlaps(a)&&c.push(d)}return c}},{"../collision/Broadphase":5,"../shapes/Shape":43}],12:[function(c,
d,g){function a(a,c,d){d=d||{};var e="undefined"!==typeof d.maxForce?d.maxForce:1E6,h=d.pivotA?d.pivotA.clone():new n,l=d.pivotB?d.pivotB.clone():new n;this.axisA=d.axisA?d.axisA.clone():new n;this.axisB=d.axisB?d.axisB.clone():new n;f.call(this,a,h,c,l,e);this.collideConnected=!!d.collideConnected;this.angle="undefined"!==typeof d.angle?d.angle:0;h=this.coneEquation=new b(a,c,d);a=this.twistEquation=new m(a,c,d);this.twistAngle="undefined"!==typeof d.twistAngle?d.twistAngle:0;h.maxForce=0;h.minForce=
-e;a.maxForce=0;a.minForce=-e;this.equations.push(h,a)}d.exports=a;c("./Constraint");var f=c("./PointToPointConstraint"),b=c("../equations/ConeEquation"),m=c("../equations/RotationalEquation");c("../equations/ContactEquation");var n=c("../math/Vec3");a.prototype=new f;a.constructor=a;new n;new n;a.prototype.update=function(){var b=this.bodyA,a=this.bodyB,c=this.coneEquation,e=this.twistEquation;f.prototype.update.call(this);b.vectorToWorldFrame(this.axisA,c.axisA);a.vectorToWorldFrame(this.axisB,
c.axisB);this.axisA.tangents(e.axisA,e.axisA);b.vectorToWorldFrame(e.axisA,e.axisA);this.axisB.tangents(e.axisB,e.axisB);a.vectorToWorldFrame(e.axisB,e.axisB);c.angle=this.angle;e.maxAngle=this.twistAngle}},{"../equations/ConeEquation":18,"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],13:[function(c,d,g){function a(b,c,d){d=f.defaults(d,{collideConnected:!0,wakeUpBodies:!0});this.equations=[];this.bodyA=b;
this.bodyB=c;this.id=a.idCounter++;this.collideConnected=d.collideConnected;d.wakeUpBodies&&(b&&b.wakeUp(),c&&c.wakeUp())}d.exports=a;var f=c("../utils/Utils");a.prototype.update=function(){throw Error("method update() not implmemented in this Constraint subclass!");};a.prototype.enable=function(){for(var b=this.equations,a=0;a<b.length;a++)b[a].enabled=!0};a.prototype.disable=function(){for(var b=this.equations,a=0;a<b.length;a++)b[a].enabled=!1};a.idCounter=0},{"../utils/Utils":53}],14:[function(c,
d,g){function a(a,c,d,r){f.call(this,a,c);"undefined"===typeof d&&(d=a.position.distanceTo(c.position));"undefined"===typeof r&&(r=1E6);this.distance=d;a=this.distanceEquation=new b(a,c);this.equations.push(a);a.minForce=-r;a.maxForce=r}d.exports=a;var f=c("./Constraint"),b=c("../equations/ContactEquation");a.prototype=new f;a.prototype.update=function(){var b=this.distanceEquation,a=.5*this.distance,c=b.ni;this.bodyB.position.vsub(this.bodyA.position,c);c.normalize();c.mult(a,b.ri);c.mult(-a,b.rj)}},
{"../equations/ContactEquation":19,"./Constraint":13}],15:[function(c,d,g){function a(a,e,c){c=c||{};var h="undefined"!==typeof c.maxForce?c.maxForce:1E6,d=c.pivotA?c.pivotA.clone():new n,l=c.pivotB?c.pivotB.clone():new n;f.call(this,a,d,e,l,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();d=this.rotationalEquation1=new b(a,e,c);c=this.rotationalEquation2=new b(a,e,c);a=this.motorEquation=new m(a,e,h);a.enabled=!1;this.equations.push(d,
c,a)}d.exports=a;c("./Constraint");var f=c("./PointToPointConstraint"),b=c("../equations/RotationalEquation"),m=c("../equations/RotationalMotorEquation");c("../equations/ContactEquation");var n=c("../math/Vec3");a.prototype=new f;a.constructor=a;a.prototype.enableMotor=function(){this.motorEquation.enabled=!0};a.prototype.disableMotor=function(){this.motorEquation.enabled=!1};a.prototype.setMotorSpeed=function(b){this.motorEquation.targetVelocity=b};a.prototype.setMotorMaxForce=function(b){this.motorEquation.maxForce=
b;this.motorEquation.minForce=-b};var l=new n,r=new n;a.prototype.update=function(){var b=this.bodyA,a=this.bodyB,c=this.motorEquation,d=this.rotationalEquation1,m=this.rotationalEquation2,g=this.axisA,n=this.axisB;f.prototype.update.call(this);b.quaternion.vmult(g,l);a.quaternion.vmult(n,r);l.tangents(d.axisA,m.axisA);d.axisB.copy(r);m.axisB.copy(r);this.motorEquation.enabled&&(b.quaternion.vmult(this.axisA,c.axisA),a.quaternion.vmult(this.axisB,c.axisB))}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,
"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],16:[function(c,d,g){function a(a,c,d){d=d||{};var l="undefined"!==typeof d.maxForce?d.maxForce:1E6,e=new m,h=new m,q=new m;a.position.vadd(c.position,q);q.scale(.5,q);c.pointToLocalFrame(q,h);a.pointToLocalFrame(q,e);f.call(this,a,e,c,h,l);l=this.rotationalEquation1=new b(a,c,d);e=this.rotationalEquation2=new b(a,c,d);a=this.rotationalEquation3=new b(a,c,d);this.equations.push(l,e,a)}d.exports=
a;c("./Constraint");var f=c("./PointToPointConstraint"),b=c("../equations/RotationalEquation");c("../equations/RotationalMotorEquation");c("../equations/ContactEquation");var m=c("../math/Vec3");a.prototype=new f;a.constructor=a;new m;new m;a.prototype.update=function(){var b=this.bodyA,a=this.bodyB,c=this.rotationalEquation1,d=this.rotationalEquation2,e=this.rotationalEquation3;f.prototype.update.call(this);b.vectorToWorldFrame(m.UNIT_X,c.axisA);a.vectorToWorldFrame(m.UNIT_Y,c.axisB);b.vectorToWorldFrame(m.UNIT_Y,
d.axisA);a.vectorToWorldFrame(m.UNIT_Z,d.axisB);b.vectorToWorldFrame(m.UNIT_Z,e.axisA);a.vectorToWorldFrame(m.UNIT_X,e.axisB)}},{"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../equations/RotationalMotorEquation":23,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],17:[function(c,d,g){function a(a,c,d,p,e){f.call(this,a,d);e="undefined"!==typeof e?e:1E6;this.pivotA=c?c.clone():new m;this.pivotB=p?p.clone():new m;c=this.equationX=new b(a,d);p=this.equationY=
new b(a,d);a=this.equationZ=new b(a,d);this.equations.push(c,p,a);c.minForce=p.minForce=a.minForce=-e;c.maxForce=p.maxForce=a.maxForce=e;c.ni.set(1,0,0);p.ni.set(0,1,0);a.ni.set(0,0,1)}d.exports=a;var f=c("./Constraint"),b=c("../equations/ContactEquation"),m=c("../math/Vec3");a.prototype=new f;a.prototype.update=function(){var b=this.bodyB,a=this.equationX,c=this.equationY,f=this.equationZ;this.bodyA.quaternion.vmult(this.pivotA,a.ri);b.quaternion.vmult(this.pivotB,a.rj);c.ri.copy(a.ri);c.rj.copy(a.rj);
f.ri.copy(a.ri);f.rj.copy(a.rj)}},{"../equations/ContactEquation":19,"../math/Vec3":30,"./Constraint":13}],18:[function(c,d,g){function a(a,c,d){d=d||{};var e="undefined"!==typeof d.maxForce?d.maxForce:1E6;b.call(this,a,c,-e,e);this.axisA=d.axisA?d.axisA.clone():new f(1,0,0);this.axisB=d.axisB?d.axisB.clone():new f(0,1,0);this.angle="undefined"!==typeof d.angle?d.angle:0}d.exports=a;var f=c("../math/Vec3");c("../math/Mat3");var b=c("./Equation");a.prototype=new b;a.prototype.constructor=a;var m=new f,
n=new f;a.prototype.computeB=function(b){var a=this.a,c=this.b,e=this.axisA,h=this.axisB,d=this.jacobianElementA,f=this.jacobianElementB;e.cross(h,m);h.cross(e,n);d.rotational.copy(n);f.rotational.copy(m);e=Math.cos(this.angle)-e.dot(h);h=this.computeGW();d=this.computeGiMf();return-e*a-h*c-b*d}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],19:[function(c,d,g){function a(a,e,c){f.call(this,a,e,0,"undefined"!==typeof c?c:1E6);this.restitution=0;this.ri=new b;this.rj=new b;this.ni=new b}d.exports=
a;var f=c("./Equation"),b=c("../math/Vec3");c("../math/Mat3");a.prototype=new f;a.prototype.constructor=a;var m=new b,n=new b,l=new b;a.prototype.computeB=function(b){var a=this.a,e=this.b,c=this.bi,h=this.bj,d=this.ri,f=this.rj,q=c.velocity,p=c.angularVelocity,g=h.velocity,u=h.angularVelocity,r=this.jacobianElementA,Q=this.jacobianElementB,H=this.ni;d.cross(H,m);f.cross(H,n);H.negate(r.spatial);m.negate(r.rotational);Q.spatial.copy(H);Q.rotational.copy(n);l.copy(h.position);l.vadd(f,l);l.vsub(c.position,
l);l.vsub(d,l);c=H.dot(l);h=this.restitution+1;q=h*g.dot(H)-h*q.dot(H)+u.dot(n)-p.dot(m);p=this.computeGiMf();return-c*a-q*e-b*p};var r=new b,p=new b,e=new b,h=new b,q=new b;a.prototype.getImpactVelocityAlongNormal=function(){this.bi.position.vadd(this.ri,e);this.bj.position.vadd(this.rj,h);this.bi.getVelocityAtWorldPoint(e,r);this.bj.getVelocityAtWorldPoint(h,p);r.vsub(p,q);return this.ni.dot(q)}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],20:[function(c,d,g){function a(b,e,c,d){this.id=
a.id++;this.minForce="undefined"===typeof c?-1E6:c;this.maxForce="undefined"===typeof d?1E6:d;this.bi=b;this.bj=e;this.eps=this.b=this.a=0;this.jacobianElementA=new f;this.jacobianElementB=new f;this.enabled=!0;this.setSpookParams(1E7,4,1/60)}d.exports=a;var f=c("../math/JacobianElement");c=c("../math/Vec3");a.prototype.constructor=a;a.id=0;a.prototype.setSpookParams=function(b,a,e){this.a=4/(e*(1+4*a));this.b=4*a/(1+4*a);this.eps=4/(e*e*b*(1+4*a))};a.prototype.computeB=function(b,a,e){var c=this.computeGW(),
h=this.computeGq(),d=this.computeGiMf();return-h*b-c*a-d*e};a.prototype.computeGq=function(){var b=this.jacobianElementB,a=this.bj.position;return this.jacobianElementA.spatial.dot(this.bi.position)+b.spatial.dot(a)};var b=new c;a.prototype.computeGW=function(){var a=this.jacobianElementB,e=this.bi,c=this.bj,d=c.velocity;c=c.angularVelocity||b;return this.jacobianElementA.multiplyVectors(e.velocity,e.angularVelocity||b)+a.multiplyVectors(d,c)};a.prototype.computeGWlambda=function(){var a=this.jacobianElementB,
e=this.bi,c=this.bj,d=c.vlambda;c=c.wlambda||b;return this.jacobianElementA.multiplyVectors(e.vlambda,e.wlambda||b)+a.multiplyVectors(d,c)};var m=new c,n=new c,l=new c,r=new c;a.prototype.computeGiMf=function(){var b=this.jacobianElementA,a=this.jacobianElementB,e=this.bi,c=this.bj,d=e.force,f=e.torque,p=c.force,g=c.torque,x=e.invMassSolve,D=c.invMassSolve;e.invInertiaWorldSolve?e.invInertiaWorldSolve.vmult(f,l):l.set(0,0,0);c.invInertiaWorldSolve?c.invInertiaWorldSolve.vmult(g,r):r.set(0,0,0);d.mult(x,
m);p.mult(D,n);return b.multiplyVectors(m,l)+a.multiplyVectors(n,r)};var p=new c;a.prototype.computeGiMGt=function(){var b=this.jacobianElementA,a=this.jacobianElementB,e=this.bi,c=this.bj,d=e.invInertiaWorldSolve,f=c.invInertiaWorldSolve;e=e.invMassSolve+c.invMassSolve;d&&(d.vmult(b.rotational,p),e+=p.dot(b.rotational));f&&(f.vmult(a.rotational,p),e+=p.dot(a.rotational));return e};var e=new c;new c;new c;new c;new c;new c;a.prototype.addToWlambda=function(b){var a=this.jacobianElementA,c=this.jacobianElementB,
h=this.bi,d=this.bj;a.spatial.mult(h.invMassSolve*b,e);h.vlambda.vadd(e,h.vlambda);c.spatial.mult(d.invMassSolve*b,e);d.vlambda.vadd(e,d.vlambda);h.invInertiaWorldSolve&&(h.invInertiaWorldSolve.vmult(a.rotational,e),e.mult(b,e),h.wlambda.vadd(e,h.wlambda));d.invInertiaWorldSolve&&(d.invInertiaWorldSolve.vmult(c.rotational,e),e.mult(b,e),d.wlambda.vadd(e,d.wlambda))};a.prototype.computeC=function(){return this.computeGiMGt()+this.eps}},{"../math/JacobianElement":26,"../math/Vec3":30}],21:[function(c,
d,g){function a(a,c,d){f.call(this,a,c,-d,d);this.ri=new b;this.rj=new b;this.t=new b}d.exports=a;var f=c("./Equation"),b=c("../math/Vec3");c("../math/Mat3");a.prototype=new f;a.prototype.constructor=a;var m=new b,n=new b;a.prototype.computeB=function(b){var a=this.b,c=this.rj,e=this.t;this.ri.cross(e,m);c.cross(e,n);c=this.jacobianElementA;var h=this.jacobianElementB;e.negate(c.spatial);m.negate(c.rotational);h.spatial.copy(e);h.rotational.copy(n);e=this.computeGW();c=this.computeGiMf();return-e*
a-b*c}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],22:[function(c,d,g){function a(a,c,d){d=d||{};var e="undefined"!==typeof d.maxForce?d.maxForce:1E6;b.call(this,a,c,-e,e);this.axisA=d.axisA?d.axisA.clone():new f(1,0,0);this.axisB=d.axisB?d.axisB.clone():new f(0,1,0);this.maxAngle=Math.PI/2}d.exports=a;var f=c("../math/Vec3");c("../math/Mat3");var b=c("./Equation");a.prototype=new b;a.prototype.constructor=a;var m=new f,n=new f;a.prototype.computeB=function(b){var a=this.a,c=this.b,e=
this.axisA,h=this.axisB,d=this.jacobianElementA,f=this.jacobianElementB;e.cross(h,m);h.cross(e,n);d.rotational.copy(n);f.rotational.copy(m);e=Math.cos(this.maxAngle)-e.dot(h);h=this.computeGW();d=this.computeGiMf();return-e*a-h*c-b*d}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],23:[function(c,d,g){function a(a,c,d){d="undefined"!==typeof d?d:1E6;b.call(this,a,c,-d,d);this.axisA=new f;this.axisB=new f;this.targetVelocity=0}d.exports=a;var f=c("../math/Vec3");c("../math/Mat3");var b=c("./Equation");
a.prototype=new b;a.prototype.constructor=a;a.prototype.computeB=function(b){var a=this.b,c=this.axisB,d=this.jacobianElementB;this.jacobianElementA.rotational.copy(this.axisA);c.negate(d.rotational);c=this.computeGW()-this.targetVelocity;d=this.computeGiMf();return-c*a-b*d}},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],24:[function(c,d,g){function a(b,c,d){d=f.defaults(d,{friction:.3,restitution:.3,contactEquationStiffness:1E7,contactEquationRelaxation:3,frictionEquationStiffness:1E7,frictionEquationRelaxation:3});
this.id=a.idCounter++;this.materials=[b,c];this.friction=d.friction;this.restitution=d.restitution;this.contactEquationStiffness=d.contactEquationStiffness;this.contactEquationRelaxation=d.contactEquationRelaxation;this.frictionEquationStiffness=d.frictionEquationStiffness;this.frictionEquationRelaxation=d.frictionEquationRelaxation}var f=c("../utils/Utils");d.exports=a;a.idCounter=0},{"../utils/Utils":53}],25:[function(c,d,g){function a(c){var b="";c=c||{};"string"===typeof c?(b=c,c={}):"object"===
typeof c&&(b="");this.name=b;this.id=a.idCounter++;this.friction="undefined"!==typeof c.friction?c.friction:-1;this.restitution="undefined"!==typeof c.restitution?c.restitution:-1}d.exports=a;a.idCounter=0},{}],26:[function(c,d,g){function a(){this.spatial=new f;this.rotational=new f}d.exports=a;var f=c("./Vec3");a.prototype.multiplyElement=function(b){return b.spatial.dot(this.spatial)+b.rotational.dot(this.rotational)};a.prototype.multiplyVectors=function(b,a){return b.dot(this.spatial)+a.dot(this.rotational)}},
{"./Vec3":30}],27:[function(c,d,g){function a(b){this.elements=b?b:[0,0,0,0,0,0,0,0,0]}d.exports=a;var f=c("./Vec3");a.prototype.identity=function(){var b=this.elements;b[0]=1;b[1]=0;b[2]=0;b[3]=0;b[4]=1;b[5]=0;b[6]=0;b[7]=0;b[8]=1};a.prototype.setZero=function(){var b=this.elements;b[0]=0;b[1]=0;b[2]=0;b[3]=0;b[4]=0;b[5]=0;b[6]=0;b[7]=0;b[8]=0};a.prototype.setTrace=function(b){var a=this.elements;a[0]=b.x;a[4]=b.y;a[8]=b.z};a.prototype.getTrace=function(b){b=b||new f;var a=this.elements;b.x=a[0];
b.y=a[4];b.z=a[8]};a.prototype.vmult=function(b,a){a=a||new f;var c=this.elements,d=b.x,m=b.y,p=b.z;a.x=c[0]*d+c[1]*m+c[2]*p;a.y=c[3]*d+c[4]*m+c[5]*p;a.z=c[6]*d+c[7]*m+c[8]*p;return a};a.prototype.smult=function(b){for(var a=0;a<this.elements.length;a++)this.elements[a]*=b};a.prototype.mmult=function(b,c){for(var d=c||new a,f=0;3>f;f++)for(var m=0;3>m;m++){for(var p=0,e=0;3>e;e++)p+=b.elements[f+3*e]*this.elements[e+3*m];d.elements[f+3*m]=p}return d};a.prototype.scale=function(b,c){c=c||new a;for(var d=
this.elements,f=c.elements,m=0;3!==m;m++)f[3*m]=b.x*d[3*m],f[3*m+1]=b.y*d[3*m+1],f[3*m+2]=b.z*d[3*m+2];return c};a.prototype.solve=function(b,a){a=a||new f;for(var c=[],d=0;12>d;d++)c.push(0);var g;for(d=0;3>d;d++)for(g=0;3>g;g++)c[d+4*g]=this.elements[d+3*g];c[3]=b.x;c[7]=b.y;c[11]=b.z;var p=3,e=p;do{d=e-p;if(0===c[d+4*d])for(g=d+1;g<e;g++)if(0!==c[d+4*g]){var h=4;do{var q=4-h;c[q+4*d]+=c[q+4*g]}while(--h);break}if(0!==c[d+4*d])for(g=d+1;g<e;g++){var m=c[d+4*g]/c[d+4*d];h=4;do q=4-h,c[q+4*g]=q<=
d?0:c[q+4*g]-c[q+4*d]*m;while(--h)}}while(--p);a.z=c[11]/c[10];a.y=(c[7]-c[6]*a.z)/c[5];a.x=(c[3]-c[2]*a.z-c[1]*a.y)/c[0];if(isNaN(a.x)||isNaN(a.y)||isNaN(a.z)||Infinity===a.x||Infinity===a.y||Infinity===a.z)throw"Could not solve equation! Got x=["+a.toString()+"], b=["+b.toString()+"], A=["+this.toString()+"]";return a};a.prototype.e=function(a,c,d){if(void 0===d)return this.elements[c+3*a];this.elements[c+3*a]=d};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="",c=0;9>c;c++)a+=this.elements[c]+",";return a};a.prototype.reverse=function(b){b=b||new a;for(var c=[],d=0;18>d;d++)c.push(0);var f;for(d=0;3>d;d++)for(f=0;3>f;f++)c[d+6*f]=this.elements[d+3*f];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 g=3,p=g;do{d=p-g;if(0===c[d+6*d])for(f=d+1;f<p;f++)if(0!==c[d+6*f]){var e=6;do{var h=6-e;c[h+6*d]+=c[h+6*f]}while(--e);break}if(0!==c[d+6*d])for(f=d+1;f<p;f++){var q=
c[d+6*f]/c[d+6*d];e=6;do h=6-e,c[h+6*f]=h<=d?0:c[h+6*f]-c[h+6*d]*q;while(--e)}}while(--g);d=2;do{f=d-1;do{q=c[d+6*f]/c[d+6*d];e=6;do h=6-e,c[h+6*f]-=c[h+6*d]*q;while(--e)}while(f--)}while(--d);d=2;do{q=1/c[d+6*d];e=6;do h=6-e,c[h+6*d]*=q;while(--e)}while(d--);d=2;do{f=2;do{h=c[3+f+6*d];if(isNaN(h)||Infinity===h)throw"Could not reverse! A=["+this.toString()+"]";b.e(d,f,h)}while(f--)}while(d--);return b};a.prototype.setRotationFromQuaternion=function(a){var b=a.x,c=a.y,d=a.z,f=a.w,p=b+b,e=c+c,h=d+d;
a=b*p;var q=b*e;b*=h;var g=c*e;c*=h;d*=h;p*=f;e*=f;f*=h;h=this.elements;h[0]=1-(g+d);h[1]=q-f;h[2]=b+e;h[3]=q+f;h[4]=1-(a+d);h[5]=c-p;h[6]=b-e;h[7]=c+p;h[8]=1-(a+g);return this};a.prototype.transpose=function(b){b=b||new a;for(var c=b.elements,d=this.elements,f=0;3!==f;f++)for(var g=0;3!==g;g++)c[3*f+g]=d[3*g+f];return b}},{"./Vec3":30}],28:[function(c,d,g){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}d.exports=a;var f=c("./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 f;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 b=new f,m=new f;a.prototype.setFromVectors=function(a,c){if(a.isAntiparallelTo(c))a.tangents(b,m),this.setFromAxisAngle(b,Math.PI);else{var e=a.cross(c);this.x=e.x;this.y=e.y;this.z=e.z;this.w=Math.sqrt(Math.pow(a.norm(),2)*Math.pow(c.norm(),2))+a.dot(c);this.normalize()}};var n=new f,l=new f,r=new f;a.prototype.mult=function(b,c){c=c||new a;var e=this.w;n.set(this.x,this.y,this.z);l.set(b.x,b.y,b.z);c.w=e*b.w-n.dot(l);n.cross(l,r);c.x=e*l.x+b.w*n.x+r.x;
c.y=e*l.y+b.w*n.y+r.y;c.z=e*l.z+b.w*n.z+r.z;return c};a.prototype.inverse=function(b){var c=this.x,d=this.y,f=this.z,l=this.w;b=b||new a;this.conjugate(b);c=1/(c*c+d*d+f*f+l*l);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 f;var c=a.x,e=a.y,d=a.z,l=this.x,g=this.y,p=this.z,m=this.w,r=m*c+g*d-p*e,n=m*e+p*c-l*d,D=m*d+l*e-g*c;c=-l*c-g*e-p*d;b.x=r*m+c*-l+n*-p-D*-g;b.y=n*m+c*-g+D*-l-r*-p;b.z=D*m+c*-p+r*-g-n*-l;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,e=this.y,d=this.z,f=this.w;switch(b){case "YZX":var l=c*e+d*f;if(.499<l){var g=2*Math.atan2(c,f);var p=Math.PI/2;var m=0}-.499>l&&(g=-2*Math.atan2(c,f),p=-Math.PI/2,m=0);isNaN(g)&&(m=d*d,g=Math.atan2(2*e*f-2*c*d,1-2*e*e-2*m),p=Math.asin(2*l),m=Math.atan2(2*c*f-2*e*d,1-2*c*c-2*m));break;default:throw Error("Euler order "+b+" not supported yet.");}a.y=g;a.z=p;a.x=m};a.prototype.setFromEuler=function(a,b,c,d){d=d||"XYZ";var e=Math.cos(a/2),f=
Math.cos(b/2),h=Math.cos(c/2);a=Math.sin(a/2);b=Math.sin(b/2);c=Math.sin(c/2);"XYZ"===d?(this.x=a*f*h+e*b*c,this.y=e*b*h-a*f*c,this.z=e*f*c+a*b*h,this.w=e*f*h-a*b*c):"YXZ"===d?(this.x=a*f*h+e*b*c,this.y=e*b*h-a*f*c,this.z=e*f*c-a*b*h,this.w=e*f*h+a*b*c):"ZXY"===d?(this.x=a*f*h-e*b*c,this.y=e*b*h+a*f*c,this.z=e*f*c+a*b*h,this.w=e*f*h-a*b*c):"ZYX"===d?(this.x=a*f*h-e*b*c,this.y=e*b*h+a*f*c,this.z=e*f*c-a*b*h,this.w=e*f*h+a*b*c):"YZX"===d?(this.x=a*f*h+e*b*c,this.y=e*b*h+a*f*c,this.z=e*f*c-a*b*h,this.w=
e*f*h-a*b*c):"XZY"===d&&(this.x=a*f*h-e*b*c,this.y=e*b*h-a*f*c,this.z=e*f*c+a*b*h,this.w=e*f*h+a*b*c);return this};a.prototype.clone=function(){return new a(this.x,this.y,this.z,this.w)}},{"./Vec3":30}],29:[function(c,d,g){function a(a){a=a||{};this.position=new f;a.position&&this.position.copy(a.position);this.quaternion=new b;a.quaternion&&this.quaternion.copy(a.quaternion)}var f=c("./Vec3"),b=c("./Quaternion");d.exports=a;var m=new b;a.pointToLocalFrame=function(a,b,c,d){d=d||new f;c.vsub(a,d);
b.conjugate(m);m.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 f;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 f;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 f;b.w*=-1;b.vmult(c,d);b.w*=-1;return d}},{"./Quaternion":28,"./Vec3":30}],30:[function(c,d,g){function a(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0}d.exports=a;var f=c("./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,f=b.z,q=this.x,l=this.y,g=this.z;c=c||new a;c.x=l*f-g*e;c.y=g*d-q*f;c.z=q*e-l*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 f([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,f=Math.sqrt(c*c+d*d+e*e);0<f?(f=1/f,b.x=c*f,b.y=d*f,b.z=e*f):(b.x=1,b.y=0,b.z=0);return b};a.prototype.norm=function(){var b=this.x,a=this.y,c=this.z;return Math.sqrt(b*b+a*a+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(b){var a=this.x,c=this.y,
e=this.z,d=b.x,f=b.y;b=b.z;return Math.sqrt((d-a)*(d-a)+(f-c)*(f-c)+(b-e)*(b-e))};a.prototype.distanceSquared=function(b){var a=this.x,c=this.y,e=this.z,d=b.x,f=b.y;b=b.z;return(d-a)*(d-a)+(f-c)*(f-c)+(b-e)*(b-e)};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(b){return this.x*b.x+this.y*b.y+this.z*b.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 b=new a,m=new a;a.prototype.tangents=function(a,c){var d=this.norm();0<d?(d=1/d,b.set(this.x*d,this.y*d,this.z*d),.9>Math.abs(b.x)?m.set(1,0,0):m.set(0,1,0),b.cross(m,a),b.cross(a,c)):(a.set(1,0,0),c.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(b){this.x=b.x;this.y=b.y;this.z=b.z;return this};a.prototype.lerp=
function(b,a,c){var e=this.x,d=this.y,f=this.z;c.x=e+(b.x-e)*a;c.y=d+(b.y-d)*a;c.z=f+(b.z-f)*a};a.prototype.almostEquals=function(b,a){void 0===a&&(a=1E-6);return Math.abs(this.x-b.x)>a||Math.abs(this.y-b.y)>a||Math.abs(this.z-b.z)>a?!1:!0};a.prototype.almostZero=function(b){void 0===b&&(b=1E-6);return Math.abs(this.x)>b||Math.abs(this.y)>b||Math.abs(this.z)>b?!1:!0};var n=new a;a.prototype.isAntiparallelTo=function(b,a){this.negate(n);return n.almostEquals(b,a)};a.prototype.clone=function(){return new a(this.x,
this.y,this.z)}},{"./Mat3":27}],31:[function(c,d,g){function a(c){c=c||{};f.apply(this);this.id=a.idCounter++;this.postStep=this.preStep=this.world=null;this.vlambda=new b;this.collisionFilterGroup="number"===typeof c.collisionFilterGroup?c.collisionFilterGroup:1;this.collisionFilterMask="number"===typeof c.collisionFilterMask?c.collisionFilterMask:1;this.collisionResponse=!0;this.position=new b;c.position&&this.position.copy(c.position);this.previousPosition=new b;this.initPosition=new b;this.velocity=
new b;c.velocity&&this.velocity.copy(c.velocity);this.initVelocity=new b;this.force=new b;var e="number"===typeof c.mass?c.mass:0;this.mass=e;this.invMass=0<e?1/e:0;this.material=c.material||null;this.linearDamping="number"===typeof c.linearDamping?c.linearDamping:.01;this.type=0>=e?a.STATIC:a.DYNAMIC;typeof c.type===typeof a.STATIC&&(this.type=c.type);this.allowSleep="undefined"!==typeof c.allowSleep?c.allowSleep:!0;this.sleepState=0;this.sleepSpeedLimit="undefined"!==typeof c.sleepSpeedLimit?c.sleepSpeedLimit:
.1;this.sleepTimeLimit="undefined"!==typeof c.sleepTimeLimit?c.sleepTimeLimit:1;this.timeLastSleepy=0;this._wakeUpAfterNarrowphase=!1;this.torque=new b;this.quaternion=new n;c.quaternion&&this.quaternion.copy(c.quaternion);this.initQuaternion=new n;this.angularVelocity=new b;c.angularVelocity&&this.angularVelocity.copy(c.angularVelocity);this.initAngularVelocity=new b;this.interpolatedPosition=new b;this.interpolatedQuaternion=new n;this.shapes=[];this.shapeOffsets=[];this.shapeOrientations=[];this.inertia=
new b;this.invInertia=new b;this.invInertiaWorld=new m;this.invMassSolve=0;this.invInertiaSolve=new b;this.invInertiaWorldSolve=new m;this.fixedRotation="undefined"!==typeof c.fixedRotation?c.fixedRotation:!1;this.angularDamping="undefined"!==typeof c.angularDamping?c.angularDamping:.01;this.aabb=new l;this.aabbNeedsUpdate=!0;this.wlambda=new b;c.shape&&this.addShape(c.shape);this.updateMassProperties()}d.exports=a;var f=c("../utils/EventTarget");c("../shapes/Shape");var b=c("../math/Vec3"),m=c("../math/Mat3"),
n=c("../math/Quaternion");c("../material/Material");var l=c("../collision/AABB"),r=c("../shapes/Box");a.prototype=new f;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,e=this.velocity.norm2()+this.angularVelocity.norm2(),d=Math.pow(this.sleepSpeedLimit,2);c===a.AWAKE&&e<d?(this.sleepState=a.SLEEPY,this.timeLastSleepy=b,this.dispatchEvent(a.sleepyEvent)):c===a.SLEEPY&&e>d?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,c){c=c||new b;a.vsub(this.position,c);this.quaternion.conjugate().vmult(c,c);return c};a.prototype.vectorToLocalFrame=function(a,c){c=c||new b;this.quaternion.conjugate().vmult(a,c);return c};a.prototype.pointToWorldFrame=function(a,
c){c=c||new b;this.quaternion.vmult(a,c);c.vadd(this.position,c);return c};a.prototype.vectorToWorldFrame=function(a,c){c=c||new b;this.quaternion.vmult(a,c);return c};var p=new b,e=new n;a.prototype.addShape=function(a,c,e){var d=new b,f=new n;c&&d.copy(c);e&&f.copy(e);this.shapes.push(a);this.shapeOffsets.push(d);this.shapeOrientations.push(f);this.updateMassProperties();this.updateBoundingRadius();this.aabbNeedsUpdate=!0;return this};a.prototype.updateBoundingRadius=function(){for(var b=this.shapes,
a=this.shapeOffsets,c=b.length,e=0,d=0;d!==c;d++){var f=b[d];f.updateBoundingSphereRadius();var h=a[d].norm();f=f.boundingSphereRadius;h+f>e&&(e=h+f)}this.boundingRadius=e};var h=new l;a.prototype.computeAABB=function(){for(var b=this.shapes,a=this.shapeOffsets,c=this.shapeOrientations,d=b.length,f=this.quaternion,q=this.aabb,g=0;g!==d;g++){var l=b[g];c[g].mult(f,e);e.vmult(a[g],p);p.vadd(this.position,p);l.calculateWorldAABB(p,e,h.lowerBound,h.upperBound);0===g?q.copy(h):q.extend(h)}this.aabbNeedsUpdate=
!1};var q=new m,u=new m;new m;a.prototype.updateInertiaWorld=function(b){var a=this.invInertia;if(a.x!==a.y||a.y!==a.z||b)q.setRotationFromQuaternion(this.quaternion),q.transpose(u),q.scale(a,q),q.mmult(u,this.invInertiaWorld)};var t=new b,w=new b;a.prototype.applyForce=function(b,c){this.type===a.DYNAMIC&&(c.vsub(this.position,t),t.cross(b,w),this.force.vadd(b,this.force),this.torque.vadd(w,this.torque))};var v=new b,z=new b;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 b,x=new b,D=new b;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 b,K=new b;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 b;a.prototype.updateMassProperties=function(){this.invMass=0<this.mass?1/this.mass:0;var b=this.inertia,a=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);r.calculateInertia(B,this.mass,b);this.invInertia.set(0<b.x&&!a?1/b.x:0,0<b.y&&!a?1/b.y:0,0<b.z&&!a?1/b.z:0);this.updateInertiaWorld(!0)};a.prototype.getVelocityAtWorldPoint=function(a,c){var e=
new b;a.vsub(this.position,e);this.angularVelocity.cross(e,c);this.velocity.vadd(c,c);return c}},{"../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(c,d,g){function a(b){this.chassisBody=b.chassisBody;this.wheelInfos=[];this.sliding=!1;this.world=null;this.indexRightAxis="undefined"!==typeof b.indexRightAxis?b.indexRightAxis:1;this.indexForwardAxis="undefined"!==
typeof b.indexForwardAxis?b.indexForwardAxis:0;this.indexUpAxis="undefined"!==typeof b.indexUpAxis?b.indexUpAxis:2}function f(b,a,c){var e=x,d=D,f=F,h=K;a.vsub(b.position,e);e.cross(c,d);b.invInertiaWorld.vmult(d,h);h.cross(e,f);return b.invMass+c.dot(f)}c("./Body");var b=c("../math/Vec3"),m=c("../math/Quaternion");c("../collision/RaycastResult");g=c("../collision/Ray");var n=c("../objects/WheelInfo");d.exports=a;new b;new b;new b;var l=new b,r=new b,p=new b;new g;a.prototype.addWheel=function(b){b=
b||{};b=new n(b);var a=this.wheelInfos.length;this.wheelInfos.push(b);return a};a.prototype.setSteeringValue=function(b,a){this.wheelInfos[a].steering=b};new b;a.prototype.applyEngineForce=function(b,a){this.wheelInfos[a].engineForce=b};a.prototype.setBrake=function(b,a){this.wheelInfos[a].brake=b};a.prototype.addToWorld=function(b){b.add(this.chassisBody);var a=this;this.preStepCallback=function(){a.updateVehicle(b.dt)};b.addEventListener("preStep",this.preStepCallback);this.world=b};a.prototype.getVehicleAxisWorld=
function(b,a){a.set(0===b?1:0,1===b?1:0,2===b?1:0);this.chassisBody.vectorToWorldFrame(a,a)};a.prototype.updateVehicle=function(a){for(var c=this.wheelInfos,e=c.length,d=this.chassisBody,f=0;f<e;f++)this.updateWheelTransform(f);this.currentVehicleSpeedKmHour=3.6*d.velocity.norm();f=new b;this.getVehicleAxisWorld(this.indexForwardAxis,f);0>f.dot(d.velocity)&&(this.currentVehicleSpeedKmHour*=-1);for(f=0;f<e;f++)this.castRay(c[f]);this.updateSuspension(a);var h=new b,q=new b;for(f=0;f<e;f++){var g=c[f],
l=g.suspensionForce;l>g.maxSuspensionForce&&(l=g.maxSuspensionForce);g.raycastResult.hitNormalWorld.scale(l*a,h);g.raycastResult.hitPointWorld.vsub(d.position,q);d.applyImpulse(h,g.raycastResult.hitPointWorld)}this.updateFriction(a);h=new b;q=new b;l=new b;for(f=0;f<e;f++){g=c[f];d.getVelocityAtWorldPoint(g.chassisConnectionPointWorld,l);var m=1;switch(this.indexUpAxis){case 1:m=-1}if(g.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,q);var p=q.dot(g.raycastResult.hitNormalWorld);g.raycastResult.hitNormalWorld.scale(p,
h);q.vsub(h,q);p=q.dot(l);g.deltaRotation=m*p*a/g.radius}!g.sliding&&g.isInContact||0===g.engineForce||!g.useCustomSlidingRotationalSpeed||(g.deltaRotation=(0<g.engineForce?1:-1)*g.customSlidingRotationalSpeed*a);Math.abs(g.brake)>Math.abs(g.engineForce)&&(g.deltaRotation=0);g.rotation+=g.deltaRotation;g.deltaRotation*=.99}};a.prototype.updateSuspension=function(b){b=this.chassisBody.mass;for(var a=this.wheelInfos,c=a.length,e=0;e<c;e++){var d=a[e];if(d.isInContact){var f=d.suspensionStiffness*(d.suspensionRestLength-
d.suspensionLength)*d.clippedInvContactDotSuspension;var h=d.suspensionRelativeVelocity;f-=(0>h?d.dampingCompression:d.dampingRelaxation)*h;d.suspensionForce=f*b;0>d.suspensionForce&&(d.suspensionForce=0)}else d.suspensionForce=0}};a.prototype.removeFromWorld=function(b){b.remove(this.chassisBody);b.removeEventListener("preStep",this.preStepCallback);this.world=null};var e=new b,h=new b;a.prototype.castRay=function(a){this.updateWheelTransformWorld(a);var c=this.chassisBody,d=-1;a.directionWorld.scale(a.suspensionRestLength+
a.radius,e);var f=a.chassisConnectionPointWorld;f.vadd(e,h);var q=a.raycastResult;q.reset();var g=c.collisionResponse;c.collisionResponse=!1;this.world.rayTest(f,h,q);c.collisionResponse=g;f=q.body;a.raycastResult.groundObject=0;f?(d=q.distance,a.raycastResult.hitNormalWorld=q.hitNormalWorld,a.isInContact=!0,a.suspensionLength=q.distance-a.radius,q=a.suspensionRestLength-a.maxSuspensionTravel,f=a.suspensionRestLength+a.maxSuspensionTravel,a.suspensionLength<q&&(a.suspensionLength=q),a.suspensionLength>
f&&(a.suspensionLength=f,a.raycastResult.reset()),q=a.raycastResult.hitNormalWorld.dot(a.directionWorld),f=new b,c.getVelocityAtWorldPoint(a.raycastResult.hitPointWorld,f),c=a.raycastResult.hitNormalWorld.dot(f),-.1<=q?(a.suspensionRelativeVelocity=0,a.clippedInvContactDotSuspension=10):(q=-1/q,a.suspensionRelativeVelocity=c*q,a.clippedInvContactDotSuspension=q)):(a.suspensionLength=a.suspensionRestLength+0*a.maxSuspensionTravel,a.suspensionRelativeVelocity=0,a.directionWorld.scale(-1,a.raycastResult.hitNormalWorld),
a.clippedInvContactDotSuspension=1);return d};a.prototype.updateWheelTransformWorld=function(b){b.isInContact=!1;var a=this.chassisBody;a.pointToWorldFrame(b.chassisConnectionPointLocal,b.chassisConnectionPointWorld);a.vectorToWorldFrame(b.directionLocal,b.directionWorld);a.vectorToWorldFrame(b.axleLocal,b.axleWorld)};a.prototype.updateWheelTransform=function(b){b=this.wheelInfos[b];this.updateWheelTransformWorld(b);b.directionLocal.scale(-1,l);r.copy(b.axleLocal);l.cross(r,p);p.normalize();r.normalize();
var a=b.steering,c=new m;c.setFromAxisAngle(l,a);a=new m;a.setFromAxisAngle(r,b.rotation);var e=b.worldTransform.quaternion;this.chassisBody.quaternion.mult(c,e);e.mult(a,e);e.normalize();c=b.worldTransform.position;c.copy(b.directionWorld);c.scale(b.suspensionLength,c);c.vadd(b.chassisConnectionPointWorld,c)};var q=[new b(1,0,0),new b(0,1,0),new b(0,0,1)];a.prototype.getWheelTransformWorld=function(b){return this.wheelInfos[b].worldTransform};var u=new b,t=[],w=[];a.prototype.updateFriction=function(a){for(var c=
this.wheelInfos,e=c.length,d=this.chassisBody,h=0,g=0;g<e;g++){var l=c[g],m=l.raycastResult.body;m&&h++;l.sideImpulse=0;l.forwardImpulse=0;w[g]||(w[g]=new b);t[g]||(t[g]=new b)}for(g=0;g<e;g++)if(l=c[g],m=l.raycastResult.body){var p=t[g];this.getWheelTransformWorld(g).vectorToWorldFrame(q[this.indexRightAxis],p);h=l.raycastResult.hitNormalWorld;var r=p.dot(h);h.scale(r,u);p.vsub(u,p);p.normalize();h.cross(p,w[g]);w[g].normalize();h=l;r=d;var n=l.raycastResult.hitPointWorld,x=l.raycastResult.hitPointWorld;
if(1.1<p.norm2())m=0;else{var F=B,D=P,K=Q;r.getVelocityAtWorldPoint(n,F);m.getVelocityAtWorldPoint(x,D);F.vsub(D,K);m=-.2*p.dot(K)*(1/(r.invMass+m.invMass))}h.sideImpulse=m;l.sideImpulse*=1}this.sliding=!1;for(g=0;g<e;g++){l=c[g];m=l.raycastResult.body;r=0;l.slipInfo=1;if(m){h=l.brake?l.brake:0;F=d;n=m;x=l.raycastResult.hitPointWorld;p=w[g];r=h;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=f(F,x,p);n=f(n,x,p);n=1/(F+n)*-D;r<n&&(n=r);n<-r&&
(n=-r);r=n;r+=l.engineForce*a;h/=r;l.slipInfo*=h}l.forwardImpulse=0;l.skidInfo=1;m&&(l.skidInfo=1,m=l.suspensionForce*a*l.frictionSlip,h=m*m,l.forwardImpulse=r,r=.5*l.forwardImpulse,n=1*l.sideImpulse,r=r*r+n*n,l.sliding=!1,r>h&&(this.sliding=!0,l.sliding=!0,h=m/Math.sqrt(r),l.skidInfo*=h))}if(this.sliding)for(g=0;g<e;g++)l=c[g],0!==l.sideImpulse&&1>l.skidInfo&&(l.forwardImpulse*=l.skidInfo,l.sideImpulse*=l.skidInfo);for(g=0;g<e;g++)l=c[g],a=new b,a.copy(l.raycastResult.hitPointWorld),0!==l.forwardImpulse&&
(m=new b,w[g].scale(l.forwardImpulse,m),d.applyImpulse(m,a)),0!==l.sideImpulse&&(m=l.raycastResult.body,h=new b,h.copy(l.raycastResult.hitPointWorld),r=new b,t[g].scale(l.sideImpulse,r),d.pointToLocalFrame(a,a),a["xyz"[this.indexUpAxis]]*=l.rollInfluence,d.pointToWorldFrame(a,a),d.applyImpulse(r,a),r.scale(-1,r),m.applyImpulse(r,h))};var v=new b,z=new b,C=new b,x=new b,D=new b,F=new b,K=new b,B=new b,P=new b,Q=new b},{"../collision/Ray":9,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Vec3":30,
"../objects/WheelInfo":36,"./Body":31}],33:[function(c,d,g){function a(b){this.wheelBodies=[];this.coordinateSystem="undefined"===typeof b.coordinateSystem?new n(1,2,3):b.coordinateSystem.clone();this.chassisBody=b.chassisBody;this.chassisBody||(b=new m(new n(5,2,.5)),this.chassisBody=new f(1,b));this.constraints=[];this.wheelAxes=[];this.wheelForces=[]}var f=c("./Body"),b=c("../shapes/Sphere"),m=c("../shapes/Box"),n=c("../math/Vec3"),l=c("../constraints/HingeConstraint");d.exports=a;a.prototype.addWheel=
function(a){a=a||{};var c=a.body;c||(c=new f(1,new b(1.2)));this.wheelBodies.push(c);this.wheelForces.push(0);new n;var e="undefined"!==typeof a.position?a.position.clone():new n,d=new n;this.chassisBody.pointToWorldFrame(e,d);c.position.set(d.x,d.y,d.z);a="undefined"!==typeof a.axis?a.axis.clone():new n(0,1,0);this.wheelAxes.push(a);c=new l(this.chassisBody,c,{pivotA:e,axisA:a,pivotB:n.ZERO,axisB:a,collideConnected:!1});this.constraints.push(c);return this.wheelBodies.length-1};a.prototype.setSteeringValue=
function(b,a){var c=this.wheelAxes[a],e=Math.cos(b),d=Math.sin(b),f=c.x;c=c.y;this.constraints[a].axisA.set(e*f-d*c,d*f+e*c,0)};a.prototype.setMotorSpeed=function(b,a){var c=this.constraints[a];c.enableMotor();c.motorTargetVelocity=b};a.prototype.disableMotor=function(b){this.constraints[b].disableMotor()};var r=new n;a.prototype.setWheelForce=function(b,a){this.wheelForces[a]=b};a.prototype.applyWheelForce=function(b,a){var c=this.wheelBodies[a],e=c.torque;this.wheelAxes[a].scale(b,r);c.vectorToWorldFrame(r,
r);e.vadd(r,e)};a.prototype.addToWorld=function(b){for(var a=this.constraints,c=this.wheelBodies.concat([this.chassisBody]),e=0;e<c.length;e++)b.add(c[e]);for(e=0;e<a.length;e++)b.addConstraint(a[e]);b.addEventListener("preStep",this._update.bind(this))};a.prototype._update=function(){for(var b=this.wheelForces,a=0;a<b.length;a++)this.applyWheelForce(b[a],a)};a.prototype.removeFromWorld=function(b){for(var a=this.constraints,c=this.wheelBodies.concat([this.chassisBody]),e=0;e<c.length;e++)b.remove(c[e]);
for(e=0;e<a.length;e++)b.removeConstraint(a[e])};var p=new n;a.prototype.getWheelSpeed=function(b){var a=this.wheelBodies[b].angularVelocity;this.chassisBody.vectorToWorldFrame(this.wheelAxes[b],p);return a.dot(p)}},{"../constraints/HingeConstraint":15,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Sphere":44,"./Body":31}],34:[function(c,d,g){function a(){this.particles=[];this.speedOfSound=this.smoothingRadius=this.density=1;this.viscosity=.01;this.eps=1E-6;this.pressures=[];this.densities=[];this.neighbors=
[]}d.exports=a;c("../shapes/Shape");d=c("../math/Vec3");c("../math/Quaternion");c("../shapes/Particle");c("../objects/Body");c("../material/Material");a.prototype.add=function(b){this.particles.push(b);this.neighbors.length<this.particles.length&&this.neighbors.push([])};a.prototype.remove=function(b){b=this.particles.indexOf(b);-1!==b&&(this.particles.splice(b,1),this.neighbors.length>this.particles.length&&this.neighbors.pop())};var f=new d;a.prototype.getNeighbors=function(b,a){for(var c=this.particles.length,
e=b.id,d=this.smoothingRadius*this.smoothingRadius,h=0;h!==c;h++){var g=this.particles[h];g.position.vsub(b.position,f);e!==g.id&&f.norm2()<d&&a.push(g)}};var b=new d,m=new d,n=new d,l=new d,r=new d,p=new d;a.prototype.update=function(){for(var a=this.particles.length,c=this.speedOfSound,d=this.eps,f=0;f!==a;f++){var g=this.particles[f],w=this.neighbors[f];w.length=0;this.getNeighbors(g,w);w.push(this.particles[f]);for(var v=w.length,z=0,C=0;C!==v;C++){g.position.vsub(w[C].position,b);var x=b.norm();
x=this.w(x);z+=w[C].mass*x}this.densities[f]=z;this.pressures[f]=c*c*(this.densities[f]-this.density)}for(f=0;f!==a;f++){c=this.particles[f];m.set(0,0,0);n.set(0,0,0);w=this.neighbors[f];v=w.length;for(C=0;C!==v;C++)z=w[C],c.position.vsub(z.position,r),x=r.norm(),g=-z.mass*(this.pressures[f]/(this.densities[f]*this.densities[f]+d)+this.pressures[C]/(this.densities[C]*this.densities[C]+d)),this.gradw(r,l),l.mult(g,l),m.vadd(l,m),z.velocity.vsub(c.velocity,p),p.mult(1/(1E-4+this.densities[f]*this.densities[C])*
this.viscosity*z.mass,p),g=this.nablaw(x),p.mult(g,p),n.vadd(p,n);n.mult(c.mass,n);m.mult(c.mass,m);c.force.vadd(n,c.force);c.force.vadd(m,c.force)}};a.prototype.w=function(b){var a=this.smoothingRadius;return 315/(64*Math.PI*Math.pow(a,9))*Math.pow(a*a-b*b,3)};a.prototype.gradw=function(b,a){var c=b.norm(),e=this.smoothingRadius;b.mult(945/(32*Math.PI*Math.pow(e,9))*Math.pow(e*e-c*c,2),a)};a.prototype.nablaw=function(b){var a=this.smoothingRadius;return 945/(32*Math.PI*Math.pow(a,9))*(a*a-b*b)*(7*
b*b-3*a*a)}},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Particle":41,"../shapes/Shape":43}],35:[function(c,d,g){function a(b,a,c){c=c||{};this.restLength="number"===typeof c.restLength?c.restLength:1;this.stiffness=c.stiffness||100;this.damping=c.damping||1;this.bodyA=b;this.bodyB=a;this.localAnchorA=new f;this.localAnchorB=new f;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 f=c("../math/Vec3");d.exports=a;a.prototype.setWorldAnchorA=function(b){this.bodyA.pointToLocalFrame(b,this.localAnchorA)};a.prototype.setWorldAnchorB=function(b){this.bodyB.pointToLocalFrame(b,this.localAnchorB)};a.prototype.getWorldAnchorA=function(b){this.bodyA.pointToWorldFrame(this.localAnchorA,b)};a.prototype.getWorldAnchorB=function(b){this.bodyB.pointToWorldFrame(this.localAnchorB,b)};var b=new f,
m=new f,n=new f,l=new f,r=new f,p=new f,e=new f,h=new f,q=new f,u=new f,t=new f;a.prototype.applyForce=function(){var a=this.stiffness,c=this.damping,d=this.restLength,f=this.bodyA,g=this.bodyB;this.getWorldAnchorA(r);this.getWorldAnchorB(p);r.vsub(f.position,e);p.vsub(g.position,h);p.vsub(r,b);var D=b.norm();m.copy(b);m.normalize();g.velocity.vsub(f.velocity,n);g.angularVelocity.cross(h,t);n.vadd(t,n);f.angularVelocity.cross(e,t);n.vsub(t,n);m.mult(-a*(D-d)-c*n.dot(m),l);f.force.vsub(l,f.force);
g.force.vadd(l,g.force);e.cross(l,q);h.cross(l,u);f.torque.vsub(q,f.torque);g.torque.vadd(u,g.torque)}},{"../math/Vec3":30}],36:[function(c,d,g){function a(a){a=n.defaults(a,{chassisConnectionPointLocal:new f,chassisConnectionPointWorld:new f,directionLocal:new f,directionWorld:new f,axleLocal:new f,axleWorld:new f,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 m;this.worldTransform=new b;this.isInContact=!1}var f=c("../math/Vec3"),b=c("../math/Transform"),m=c("../collision/RaycastResult"),
n=c("../utils/Utils");d.exports=a;var l=new f,r=new f;l=new f;a.prototype.updateWheel=function(a){var b=this.raycastResult;if(this.isInContact){var c=b.hitNormalWorld.dot(b.directionWorld);b.hitPointWorld.vsub(a.position,r);a.getVelocityAtWorldPoint(r,l);a=b.hitNormalWorld.dot(l);-.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(c,d,g){function a(a){f.call(this);this.type=f.types.BOX;this.halfExtents=a;this.convexPolyhedronRepresentation=null;this.updateConvexPolyhedronRepresentation();this.updateBoundingSphereRadius()}d.exports=a;var f=c("./Shape"),b=c("../math/Vec3"),m=c("./ConvexPolyhedron");a.prototype=new f;a.prototype.constructor=
a;a.prototype.updateConvexPolyhedronRepresentation=function(){var a=this.halfExtents.x,c=this.halfExtents.y,e=this.halfExtents.z;a=[new b(-a,-c,-e),new b(a,-c,-e),new b(a,c,-e),new b(-a,c,-e),new b(-a,-c,e),new b(a,-c,e),new b(a,c,e),new b(-a,c,e)];new b(0,0,1);new b(0,1,0);new b(1,0,0);this.convexPolyhedronRepresentation=a=new m(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(c,d){d=d||new b;a.calculateInertia(this.halfExtents,
c,d);return d};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 b;new b;a.prototype.forEachWorldCorner=function(a,b,c){var e=this.halfExtents;e=[[e.x,e.y,e.z],[-e.x,e.y,e.z],[-e.x,-e.y,e.z],[-e.x,-e.y,-e.z],[e.x,-e.y,-e.z],[e.x,e.y,-e.z],[-e.x,e.y,-e.z],[e.x,-e.y,e.z]];for(var d=0;d<e.length;d++)n.set(e[d][0],e[d][1],e[d][2]),b.vmult(n,n),a.vadd(n,n),c(n.x,n.y,n.z)};var l=[new b,new b,new b,new b,new b,new b,new b,new b];a.prototype.calculateWorldAABB=function(a,b,c,d){var e=this.halfExtents;
l[0].set(e.x,e.y,e.z);l[1].set(-e.x,e.y,e.z);l[2].set(-e.x,-e.y,e.z);l[3].set(-e.x,-e.y,-e.z);l[4].set(e.x,-e.y,-e.z);l[5].set(e.x,e.y,-e.z);l[6].set(-e.x,e.y,-e.z);l[7].set(e.x,-e.y,e.z);var f=l[0];b.vmult(f,f);a.vadd(f,f);d.copy(f);c.copy(f);for(e=1;8>e;e++){f=l[e];b.vmult(f,f);a.vadd(f,f);var h=f.x,g=f.y;f=f.z;h>d.x&&(d.x=h);g>d.y&&(d.y=g);f>d.z&&(d.z=f);h<c.x&&(c.x=h);g<c.y&&(c.y=g);f<c.z&&(c.z=f)}}},{"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],38:[function(c,d,g){function a(a,b,
c){f.call(this);this.type=f.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()}d.exports=a;var f=c("./Shape"),b=c("../math/Vec3");c("../math/Quaternion");var m=c("../math/Transform");a.prototype=new f;a.prototype.constructor=a;
var n=new b;a.prototype.computeEdges=function(){for(var a=this.faces,b=this.vertices,c=this.uniqueEdges,e=c.length=0;e!==a.length;e++)for(var d=a[e],f=d.length,h=0;h!==f;h++){b[d[h]].vsub(b[d[(h+1)%f]],n);n.normalize();for(var g=!1,q=0;q!==c.length;q++)if(c[q].almostEquals(n)||c[q].almostEquals(n)){g=!0;break}g||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 c=0;c<this.faces[a].length;c++)if(!this.vertices[this.faces[a][c]])throw Error("Vertex "+
this.faces[a][c]+" not found!");c=this.faceNormals[a]||new b;this.getFaceNormal(a,c);c.negate(c);this.faceNormals[a]=c;if(0>c.dot(this.vertices[this.faces[a][0]]))for(console.error(".faceNormals["+a+"] = Vec3("+c.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."),c=0;c<this.faces[a].length;c++)console.warn(".vertices["+this.faces[a][c]+"] = Vec3("+this.vertices[this.faces[a][c]].toString()+")")}};var l=
new b,r=new b;a.computeNormal=function(a,b,c,e){b.vsub(a,r);c.vsub(b,l);l.cross(r,e);e.isZero()||e.normalize()};a.prototype.getFaceNormal=function(b,c){var e=this.faces[b];return a.computeNormal(this.vertices[e[0]],this.vertices[e[1]],this.vertices[e[2]],c)};var p=new b;a.prototype.clipAgainstHull=function(a,c,e,d,f,h,g,q,l){for(var m=-1,u=-Number.MAX_VALUE,r=0;r<e.faces.length;r++){p.copy(e.faceNormals[r]);f.vmult(p,p);var n=p.dot(h);n>u&&(u=n,m=r)}u=[];r=e.faces[m];n=r.length;for(var t=0;t<n;t++){var y=
e.vertices[r[t]],x=new b;x.copy(y);f.vmult(x,x);d.vadd(x,x);u.push(x)}0<=m&&this.clipFaceAgainstHull(h,a,c,u,g,q,l)};var e=new b,h=new b,q=new b,u=new b,t=new b,w=new b;a.prototype.findSeparatingAxis=function(a,b,c,d,f,g,l,m){var p=Number.MAX_VALUE,r=0;if(this.uniqueAxes)for(y=0;y!==this.uniqueAxes.length;y++){c.vmult(this.uniqueAxes[y],e);x=this.testSepAxis(e,a,b,c,d,f);if(!1===x)return!1;x<p&&(p=x,g.copy(e))}else for(var n=l?l.length:this.faces.length,y=0;y<n;y++){x=l?l[y]:y;e.copy(this.faceNormals[x]);
c.vmult(e,e);var x=this.testSepAxis(e,a,b,c,d,f);if(!1===x)return!1;x<p&&(p=x,g.copy(e))}if(a.uniqueAxes)for(y=0;y!==a.uniqueAxes.length;y++){f.vmult(a.uniqueAxes[y],h);r++;x=this.testSepAxis(h,a,b,c,d,f);if(!1===x)return!1;x<p&&(p=x,g.copy(h))}else for(l=m?m.length:a.faces.length,y=0;y<l;y++){x=m?m[y]:y;h.copy(a.faceNormals[x]);f.vmult(h,h);r++;x=this.testSepAxis(h,a,b,c,d,f);if(!1===x)return!1;x<p&&(p=x,g.copy(h))}for(m=0;m!==this.uniqueEdges.length;m++)for(c.vmult(this.uniqueEdges[m],u),r=0;r!==
a.uniqueEdges.length;r++)if(f.vmult(a.uniqueEdges[r],t),u.cross(t,w),!w.almostZero()){w.normalize();y=this.testSepAxis(w,a,b,c,d,f);if(!1===y)return!1;y<p&&(p=y,g.copy(w))}d.vsub(b,q);0<q.dot(g)&&g.negate(g);return!0};var v=[],z=[];a.prototype.testSepAxis=function(b,c,e,d,f,h){a.project(this,b,e,d,v);a.project(c,b,f,h,z);e=v[0];b=v[1];c=z[0];d=z[1];if(e<d||c<b)return!1;e-=d;b=c-b;return e<b?e:b};var C=new b,x=new b;a.prototype.calculateLocalInertia=function(a,b){this.computeLocalAABB(C,x);var c=x.x-
C.x,e=x.y-C.y,d=x.z-C.z;b.x=1/12*a*(4*e*e+4*d*d);b.y=1/12*a*(4*c*c+4*d*d);b.z=1/12*a*(4*e*e+4*c*c)};a.prototype.getPlaneConstantOfFace=function(a){return-this.faceNormals[a].dot(this.vertices[this.faces[a][0]])};var D=new b,F=new b,K=new b,B=new b,P=new b,Q=new b,H=new b,E=new b;a.prototype.clipFaceAgainstHull=function(a,b,c,e,d,f,h){for(var g=[],q=-1,l=Number.MAX_VALUE,m=0;m<this.faces.length;m++){D.copy(this.faceNormals[m]);c.vmult(D,D);var p=D.dot(a);p<l&&(l=p,q=m)}if(!(0>q)){a=this.faces[q];a.connectedFaces=
[];for(l=0;l<this.faces.length;l++)for(m=0;m<this.faces[l].length;m++)-1!==a.indexOf(this.faces[l][m])&&l!==q&&-1===a.connectedFaces.indexOf(l)&&a.connectedFaces.push(l);l=a.length;for(m=0;m<l;m++){p=this.vertices[a[m]];p.vsub(this.vertices[a[(m+1)%l]],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[m];H.copy(this.faceNormals[p]);p=this.getPlaneConstantOfFace(p);E.copy(H);
c.vmult(E,E);p-=E.dot(b);for(this.clipFaceAgainstPlane(e,g,E,p);e.length;)e.shift();for(;g.length;)e.push(g.shift())}H.copy(this.faceNormals[q]);p=this.getPlaneConstantOfFace(q);E.copy(H);c.vmult(E,E);p-=E.dot(b);for(l=0;l<e.length;l++)b=E.dot(e[l])+p,b<=d&&(console.log("clamped: depth="+b+" to minDist="+(d+"")),b=d),b<=f&&(c=e[l],0>=b&&h.push({point:c,normal:E,depth:b}))}};a.prototype.clipFaceAgainstPlane=function(a,c,e,d){var f=a.length;if(2>f)return c;var h=a[a.length-1];var g=e.dot(h)+d;for(var q=
0;q<f;q++){var l=a[q];var m=e.dot(l)+d;if(0>g){if(0>m){var p=new b;p.copy(l)}else p=new b,h.lerp(l,g/(g-m),p);c.push(p)}else 0>m&&(p=new b,h.lerp(l,g/(g-m),p),c.push(p),c.push(l));h=l;g=m}return c};a.prototype.computeWorldVertices=function(a,c){for(var e=this.vertices.length;this.worldVertices.length<e;)this.worldVertices.push(new b);for(var d=this.vertices,f=this.worldVertices,h=0;h!==e;h++)c.vmult(d[h],f[h]),a.vadd(f[h],f[h]);this.worldVerticesNeedsUpdate=!1};new b;a.prototype.computeLocalAABB=
function(a,b){var c=this.vertices.length,e=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 d=0;d<c;d++){var f=e[d];f.x<a.x?a.x=f.x:f.x>b.x&&(b.x=f.x);f.y<a.y?a.y=f.y:f.y>b.y&&(b.y=f.y);f.z<a.z?a.z=f.z:f.z>b.z&&(b.z=f.z)}};a.prototype.computeWorldFaceNormals=function(a){for(var c=this.faceNormals.length;this.worldFaceNormals.length<c;)this.worldFaceNormals.push(new b);for(var e=this.faceNormals,d=this.worldFaceNormals,
f=0;f!==c;f++)a.vmult(e[f],d[f]);this.worldFaceNormalsNeedsUpdate=!1};a.prototype.updateBoundingSphereRadius=function(){for(var a=0,b=this.vertices,c=0,e=b.length;c!==e;c++){var d=b[c].norm2();d>a&&(a=d)}this.boundingSphereRadius=Math.sqrt(a)};var I=new b;a.prototype.calculateWorldAABB=function(a,b,c,e){for(var d=this.vertices.length,f=this.vertices,h,g,q,l,m,p,r=0;r<d;r++){I.copy(f[r]);b.vmult(I,I);a.vadd(I,I);var u=I;if(u.x<h||void 0===h)h=u.x;else if(u.x>l||void 0===l)l=u.x;if(u.y<g||void 0===
g)g=u.y;else if(u.y>m||void 0===m)m=u.y;if(u.z<q||void 0===q)q=u.z;else if(u.z>p||void 0===p)p=u.z}c.set(h,g,q);e.set(l,m,p)};a.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3};a.prototype.getAveragePointLocal=function(a){a=a||new b;for(var c=this.vertices.length,e=this.vertices,d=0;d<c;d++)a.vadd(e[d],a);a.mult(1/c,a);return a};a.prototype.transformAllPoints=function(a,b){var c=this.vertices.length,e=this.vertices;if(b){for(var d=0;d<c;d++){var f=e[d];b.vmult(f,f)}for(d=
0;d<this.faceNormals.length;d++)f=this.faceNormals[d],b.vmult(f,f)}if(a)for(d=0;d<c;d++)f=e[d],f.vadd(a,f)};var A=new b,N=new b,L=new b;a.prototype.pointIsInside=function(a){var b=this.vertices,c=this.faces,e=this.faceNormals,d=this.faces.length;this.getAveragePointLocal(A);for(var f=0;f<d;f++){var h=e[f];var g=b[c[f][0]],q=N;a.vsub(g,q);q=h.dot(q);var l=L;A.vsub(g,l);h=h.dot(l);if(0>q&&0<h||0<q&&0>h)return!1}return-1};new b;var W=new b,y=new b;a.project=function(a,b,c,e,d){var f=a.vertices.length;
a=a.vertices;y.setZero();m.vectorToLocalFrame(c,e,b,W);m.pointToLocalFrame(c,e,y,y);e=y.dot(W);c=b=a[0].dot(W);for(var h=1;h<f;h++){var g=a[h].dot(W);g>b&&(b=g);g<c&&(c=g)}c-=e;b-=e;c>b&&(f=c,c=b,b=f);d[0]=b;d[1]=c}},{"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"./Shape":43}],39:[function(c,d,g){function a(a,c,d,g){var e=[],h=[],q=[],l=[],p=[],r=Math.cos,n=Math.sin;e.push(new b(c*r(0),c*n(0),.5*-d));l.push(0);e.push(new b(a*r(0),a*n(0),.5*d));p.push(1);for(var z=0;z<g;z++){var C=
2*Math.PI/g*(z+1),x=2*Math.PI/g*(z+.5);z<g-1?(e.push(new b(c*r(C),c*n(C),.5*-d)),l.push(2*z+2),e.push(new b(a*r(C),a*n(C),.5*d)),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===g%2||z<g/2)&&h.push(new b(r(x),n(x),0))}q.push(p);h.push(new b(0,0,1));a=[];for(z=0;z<l.length;z++)a.push(l[l.length-z-1]);q.push(a);this.type=f.types.CONVEXPOLYHEDRON;m.call(this,e,q,h)}d.exports=a;var f=c("./Shape"),b=c("../math/Vec3");c("../math/Quaternion");var m=c("./ConvexPolyhedron");a.prototype=
new m},{"../math/Quaternion":28,"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],40:[function(c,d,g){function a(a,c){c=n.defaults(c,{maxValue:null,minValue:null,elementSize:1});this.data=a;this.maxValue=c.maxValue;this.minValue=c.minValue;this.elementSize=c.elementSize;null===c.minValue&&this.updateMinValue();null===c.maxValue&&this.updateMaxValue();this.cacheEnabled=!0;f.call(this);this.pillarConvex=new b;this.pillarOffset=new m;this.type=f.types.HEIGHTFIELD;this.updateBoundingSphereRadius();
this._cachedPillars={}}var f=c("./Shape"),b=c("./ConvexPolyhedron"),m=c("../math/Vec3"),n=c("../utils/Utils");d.exports=a;a.prototype=new f;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 e=0;e!==a[c].length;e++){var d=a[c][e];d<b&&(b=d)}this.minValue=b};a.prototype.updateMaxValue=function(){for(var a=this.data,b=a[0][0],c=0;c!==a.length;c++)for(var e=0;e!==a[c].length;e++){var d=a[c][e];d>b&&(b=
d)}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,e,d){d=d||[];for(var f=this.data,h=this.minValue;a<=c;a++)for(var g=
b;g<=e;g++){var l=f[a][g];l>h&&(h=l)}d[0]=this.minValue;d[1]=h};a.prototype.getIndexOfPosition=function(a,b,c,e){var d=this.elementSize,f=this.data;a=Math.floor(a/d);b=Math.floor(b/d);c[0]=a;c[1]=b;e&&(0>a&&(a=0),0>b&&(b=0),a>=f.length-1&&(a=f.length-1),b>=f[0].length-1&&(b=f[0].length-1));return 0>a||0>b||a>=f.length-1||b>=f[0].length-1?!1:!0};a.prototype.getHeightAt=function(a,b,c){var e=[];this.getIndexOfPosition(a,b,e,c);a=[];this.getRectMinMax(e[0],e[1]+1,e[0],e[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,e,d){this._cachedPillars[this.getCacheConvexTrianglePillarKey(a,b,c)]={convex:e,offset:d}};a.prototype.clearCachedConvexTrianglePillar=function(a,b,c){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(a,b,c)]};a.prototype.getConvexTrianglePillar=
function(a,c,d){var e=this.pillarConvex,f=this.pillarOffset;if(this.cacheEnabled){var g=this.getCachedConvexTrianglePillar(a,c,d);if(g){this.pillarConvex=g.convex;this.pillarOffset=g.offset;return}e=new b;f=new m;this.pillarConvex=e;this.pillarOffset=f}g=this.data;var l=this.elementSize,p=e.faces;e.vertices.length=6;for(var n=0;6>n;n++)e.vertices[n]||(e.vertices[n]=new m);p.length=5;for(n=0;5>n;n++)p[n]||(p[n]=[]);n=e.vertices;var r=(Math.min(g[a][c],g[a+1][c],g[a][c+1],g[a+1][c+1])-this.minValue)/
2+this.minValue;d?(f.set((a+.75)*l,(c+.75)*l,r),n[0].set(.25*l,.25*l,g[a+1][c+1]-r),n[1].set(-.75*l,.25*l,g[a][c+1]-r),n[2].set(.25*l,-.75*l,g[a+1][c]-r),n[3].set(.25*l,.25*l,-r-1),n[4].set(-.75*l,.25*l,-r-1),n[5].set(.25*l,-.75*l,-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)*l,(c+.25)*l,r),n[0].set(-.25*l,-.25*l,g[a][c]-r),n[1].set(.75*l,-.25*
l,g[a+1][c]-r),n[2].set(-.25*l,.75*l,g[a][c+1]-r),n[3].set(-.25*l,-.25*l,-r-1),n[4].set(.75*l,-.25*l,-r-1),n[5].set(-.25*l,.75*l,-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,c,d,e,f)};a.prototype.calculateLocalInertia=function(a,b){b=b||new m;b.set(0,0,0);
return b};a.prototype.volume=function(){return Number.MAX_VALUE};a.prototype.calculateWorldAABB=function(a,b,c,e){c.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);e.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)};a.prototype.updateBoundingSphereRadius=function(){var a=this.data,b=this.elementSize;this.boundingSphereRadius=(new m(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(c,d,g){function a(){f.call(this);this.type=f.types.PARTICLE}d.exports=a;var f=c("./Shape"),b=c("../math/Vec3");a.prototype=new f;a.prototype.constructor=a;a.prototype.calculateLocalInertia=function(a,c){c=c||new b;c.set(0,0,0);return c};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(c,
d,g){function a(){f.call(this);this.type=f.types.PLANE;this.worldNormal=new b;this.worldNormalNeedsUpdate=!0;this.boundingSphereRadius=Number.MAX_VALUE}d.exports=a;var f=c("./Shape"),b=c("../math/Vec3");a.prototype=new f;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,c){return c=c||new b};a.prototype.volume=function(){return Number.MAX_VALUE};var m=new b;
a.prototype.calculateWorldAABB=function(a,b,c,d){m.set(0,0,1);b.vmult(m,m);b=Number.MAX_VALUE;c.set(-b,-b,-b);d.set(b,b,b);1===m.x&&(d.x=a.x);1===m.y&&(d.y=a.y);1===m.z&&(d.z=a.z);-1===m.x&&(c.x=a.x);-1===m.y&&(c.y=a.y);-1===m.z&&(c.z=a.z)};a.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":30,"./Shape":43}],43:[function(c,d,g){function a(){this.id=a.idCounter++;this.boundingSphereRadius=this.type=0;this.collisionResponse=!0;this.material=
null}d.exports=a;a=c("./Shape");c("../math/Vec3");c("../math/Quaternion");c("../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(c,d,g){function a(a){f.call(this);this.radius=void 0!==a?Number(a):1;this.type=f.types.SPHERE;if(0>this.radius)throw Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}d.exports=a;var f=c("./Shape"),b=c("../math/Vec3");a.prototype=new f;a.prototype.constructor=a;a.prototype.calculateLocalInertia=
function(a,c){c=c||new b;var d=2*a*this.radius*this.radius/5;c.x=d;c.y=d;c.z=d;return c};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 f=["x","y","z"],e=0;e<f.length;e++){var h=f[e];c[h]=a[h]-b;d[h]=a[h]+b}}},{"../math/Vec3":30,"./Shape":43}],45:[function(c,d,g){function a(a,c){f.call(this);this.type=f.types.TRIMESH;this.vertices=
new Float32Array(a);this.indices=new Int16Array(c);this.normals=new Float32Array(c.length);this.aabb=new n;this.edges=null;this.scale=new b(1,1,1);this.tree=new l;this.updateEdges();this.updateNormals();this.updateAABB();this.updateBoundingSphereRadius();this.updateTree()}d.exports=a;var f=c("./Shape"),b=c("../math/Vec3");c("../math/Quaternion");var m=c("../math/Transform"),n=c("../collision/AABB"),l=c("../utils/Octree");a.prototype=new f;a.prototype.constructor=a;var r=new b;a.prototype.updateTree=
function(){var a=this.tree;a.reset();a.aabb.copy(this.aabb);var c=this.scale;a.aabb.lowerBound.x*=1/c.x;a.aabb.lowerBound.y*=1/c.y;a.aabb.lowerBound.z*=1/c.z;a.aabb.upperBound.x*=1/c.x;a.aabb.upperBound.y*=1/c.y;a.aabb.upperBound.z*=1/c.z;c=new n;for(var e=new b,d=new b,f=new b,h=[e,d,f],g=0;g<this.indices.length/3;g++){var q=3*g;this._getUnscaledVertex(this.indices[q],e);this._getUnscaledVertex(this.indices[q+1],d);this._getUnscaledVertex(this.indices[q+2],f);c.setFromPoints(h);a.insert(c,g)}a.removeEmptyNodes()};
var p=new n;a.prototype.getTrianglesInAABB=function(a,b){p.copy(a);var c=this.scale,e=c.x,d=c.y;c=c.z;var f=p.lowerBound,h=p.upperBound;f.x/=e;f.y/=d;f.z/=c;h.x/=e;h.y/=d;h.z/=c;return this.tree.aabbQuery(p,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 e=
3*c,d=this.indices[e+1],f=this.indices[e+2];this.getVertex(this.indices[e],t);this.getVertex(d,w);this.getVertex(f,v);a.computeNormal(w,t,v,r);b[e]=r.x;b[e+1]=r.y;b[e+2]=r.z}};a.prototype.updateEdges=function(){for(var a={},b=function(b,c){a[d<f?d+"_"+f:f+"_"+d]=!0},c=0;c<this.indices.length/3;c++){var e=3*c,d=this.indices[e],f=this.indices[e+1];e=this.indices[e+2];b(d,f);b(f,e);b(e,d)}b=Object.keys(a);this.edges=new Int16Array(2*b.length);for(c=0;c<b.length;c++)e=b[c].split("_"),this.edges[2*c]=
parseInt(e[0],10),this.edges[2*c+1]=parseInt(e[1],10)};a.prototype.getEdgeVertex=function(a,b,c){this.getVertex(this.edges[2*a+(b?1:0)],c)};var e=new b,h=new b;a.prototype.getEdgeVector=function(a,b){this.getEdgeVertex(a,0,e);this.getEdgeVertex(a,1,h);h.vsub(e,b)};var q=new b,u=new b;a.computeNormal=function(a,b,c,e){b.vsub(a,u);c.vsub(b,q);q.cross(u,e);e.isZero()||e.normalize()};var t=new b,w=new b,v=new b;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,e=this.vertices;return b.set(e[c],e[c+1],e[c+2])};a.prototype.getWorldVertex=function(a,b,c,e){this.getVertex(a,e);m.pointToWorldFrame(b,c,e,e);return e};a.prototype.getTriangleVertices=function(a,b,c,e){a*=3;this.getVertex(this.indices[a],b);this.getVertex(this.indices[a+1],c);this.getVertex(this.indices[a+2],e)};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,e=z.upperBound.y-z.lowerBound.y,d=z.upperBound.z-z.lowerBound.z;return b.set(1/12*a*(4*e*e+4*d*d),1/12*a*(4*c*c+4*d*d),1/12*a*(4*e*e+4*c*c))};var C=new b;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 e=0;e!==c;e++)this.getVertex(e,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,c=this.vertices,e=new b,d=0;for(c=c.length/3;d!==c;d++){this.getVertex(d,e);var f=e.norm2();f>a&&(a=f)}this.boundingSphereRadius=Math.sqrt(a)};new b;var x=new m,D=new n;a.prototype.calculateWorldAABB=function(a,b,c,e){x.position=a;x.quaternion=b;this.aabb.toWorldFrame(x,D);c.copy(D.lowerBound);e.copy(D.upperBound)};
a.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3};a.createTorus=function(b,c,e,d,f){b=b||1;c=c||.5;e=e||8;d=d||6;f=f||2*Math.PI;for(var h=[],g=[],q=0;q<=e;q++)for(var l=0;l<=d;l++){var m=l/d*f,p=q/e*Math.PI*2;h.push((b+c*Math.cos(p))*Math.cos(m),(b+c*Math.cos(p))*Math.sin(m),c*Math.sin(p))}for(q=1;q<=e;q++)for(l=1;l<=d;l++)b=(d+1)*(q-1)+l-1,c=(d+1)*(q-1)+l,f=(d+1)*q+l,g.push((d+1)*q+l-1,b,f),g.push(b,c,f);return new a(h,g)}},{"../collision/AABB":3,"../math/Quaternion":28,
"../math/Transform":29,"../math/Vec3":30,"../utils/Octree":50,"./Shape":43}],46:[function(c,d,g){function a(){f.call(this);this.iterations=10;this.tolerance=1E-7}d.exports=a;c("../math/Vec3");c("../math/Quaternion");var f=c("./Solver");a.prototype=new f;var b=[],m=[],n=[];a.prototype.solve=function(a,c){var d=0,e=this.iterations,f=this.tolerance*this.tolerance,g=this.equations,l=g.length,r=c.bodies,w=r.length,v;if(0!==l)for(v=0;v!==w;v++)r[v].updateSolveMassProperties();m.length=l;n.length=l;b.length=
l;for(v=0;v!==l;v++){var z=g[v];b[v]=0;n[v]=z.computeB(a);m[v]=1/z.computeC()}if(0!==l){for(v=0;v!==w;v++)z=r[v],d=z.wlambda,z.vlambda.set(0,0,0),d&&d.set(0,0,0);for(d=0;d!==e;d++){for(var C=v=0;C!==l;C++){z=g[C];var x=n[C];var D=m[C];var F=b[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);b[C]+=x;v+=0<x?x:-x;z.addToWlambda(x)}if(v*v<f)break}for(v=0;v!==w;v++)z=r[v],e=z.velocity,f=z.angularVelocity,e.vadd(z.vlambda,e),f&&f.vadd(z.wlambda,
f)}return d}},{"../math/Quaternion":28,"../math/Vec3":30,"./Solver":47}],47:[function(c,d,g){function a(){this.equations=[]}d.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(c,d,g){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 f(a){for(var b=a.length,c=0;c!==b;c++){var d=a[c];if(!(d.visited||d.body.type&e))return d}return!1}function b(a,b,c){b.push(a.body);b=a.eqs.length;for(var e=0;e!==b;e++){var d=a.eqs[e];-1===c.indexOf(d)&&c.push(d)}}function m(a,b){return b.id-a.id}d.exports=a;c("../math/Vec3");c("../math/Quaternion");var n=c("./Solver");c=c("../objects/Body");a.prototype=new n;var l=[],r=[],
p={bodies:[]},e=c.STATIC,h=[];a.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}};a.prototype.solve=function(a,c){for(var e=this.nodePool,d=c.bodies,g=this.equations,q=g.length,n=d.length,u=this.subsolver;e.length<n;)e.push(this.createNode());l.length=n;for(var D=0;D<n;D++)l[D]=e[D];for(D=0;D!==n;D++)e=l[D],e.body=d[D],e.children.length=0,e.eqs.length=0,e.visited=!1;for(n=0;n!==q;n++){e=g[n];D=d.indexOf(e.bi);var F=d.indexOf(e.bj);D=l[D];F=l[F];D.children.push(F);D.eqs.push(e);
F.children.push(D);F.eqs.push(e)}d=0;g=r;u.tolerance=this.tolerance;for(u.iterations=this.iterations;D=f(l);){g.length=0;p.bodies.length=0;e=D;D=b;q=p.bodies;n=g;h.push(e);e.visited=!0;for(D(e,q,n);h.length;)for(e=h.pop();F=f(e.children);)F.visited=!0,D(F,q,n),h.push(F);q=g.length;g=g.sort(m);for(D=0;D!==q;D++)u.addEquation(g[D]);u.solve(a,p);u.removeAllEquations();d++}return d}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"./Solver":47}],49:[function(c,d,g){c=function(){};d.exports=
c;c.prototype={constructor:c,addEventListener:function(a,c){void 0===this._listeners&&(this._listeners={});var b=this._listeners;void 0===b[a]&&(b[a]=[]);-1===b[a].indexOf(c)&&b[a].push(c);return this},hasEventListener:function(a,c){if(void 0===this._listeners)return!1;var b=this._listeners;return void 0!==b[a]&&-1!==b[a].indexOf(c)?!0:!1},removeEventListener:function(a,c){if(void 0===this._listeners)return this;var b=this._listeners;if(void 0===b[a])return this;var d=b[a].indexOf(c);-1!==d&&b[a].splice(d,
1);return this},dispatchEvent:function(a){if(void 0===this._listeners)return this;var c=this._listeners[a.type];if(void 0!==c){a.target=this;for(var b=0,d=c.length;b<d;b++)c[b].call(this,a)}return this}}},{}],50:[function(c,d,g){function a(a){a=a||{};this.root=a.root||null;this.aabb=a.aabb?a.aabb.clone():new b;this.data=[];this.children=[]}function f(b,c){c=c||{};c.root=null;c.aabb=b;a.call(this,c);this.maxDepth="undefined"!==typeof c.maxDepth?c.maxDepth:8}var b=c("../collision/AABB"),m=c("../math/Vec3");
d.exports=f;f.prototype=new a;a.prototype.reset=function(a,b){this.children.length=this.data.length=0};a.prototype.insert=function(a,b,c){var e=this.data;c=c||0;if(!this.aabb.contains(a))return!1;var d=this.children;if(c<(this.maxDepth||this.root.maxDepth)){var f=!1;d.length||(this.subdivide(),f=!0);for(var g=0;8!==g;g++)if(d[g].insert(a,b,c+1))return!0;f&&(d.length=0)}e.push(b);return!0};var n=new m;a.prototype.subdivide=function(){var c=this.aabb,d=c.lowerBound,e=c.upperBound;c=this.children;c.push(new a({aabb:new b({lowerBound:new m(0,
0,0)})}),new a({aabb:new b({lowerBound:new m(1,0,0)})}),new a({aabb:new b({lowerBound:new m(1,1,0)})}),new a({aabb:new b({lowerBound:new m(1,1,1)})}),new a({aabb:new b({lowerBound:new m(0,1,1)})}),new a({aabb:new b({lowerBound:new m(0,0,1)})}),new a({aabb:new b({lowerBound:new m(1,0,1)})}),new a({aabb:new b({lowerBound:new m(0,1,0)})}));e.vsub(d,n);n.scale(.5,n);e=this.root||this;for(var f=0;8!==f;f++){var g=c[f];g.root=e;var l=g.aabb.lowerBound;l.x*=n.x;l.y*=n.y;l.z*=n.z;l.vadd(d,l);l.vadd(n,g.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 l=new b;a.prototype.rayQuery=function(a,b,c){a.getAABB(l);l.toLocalFrame(b,l);this.aabbQuery(l,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(c,d,g){function a(){this.objects=[];this.type=Object}d.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(c,d,g){function a(){this.data={keys:[]}}
d.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(c,d,g){function a(){}d.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(c,d,g){function a(){b.call(this);this.type=
f}d.exports=a;var f=c("../math/Vec3"),b=c("./Pool");a.prototype=new b;a.prototype.constructObject=function(){return new f}},{"../math/Vec3":30,"./Pool":51}],55:[function(c,d,g){function a(a){this.contactPointPool=[];this.frictionEquationPool=[];this.result=[];this.frictionResult=[];this.v3pool=new l;this.world=a;this.currentContactMaterial=null;this.enableFrictionReduction=!1}d.exports=a;d=c("../collision/AABB");g=c("../shapes/Shape");var f=c("../collision/Ray"),b=c("../math/Vec3"),m=c("../math/Transform");
c("../shapes/ConvexPolyhedron");var n=c("../math/Quaternion");c("../solver/Solver");var l=c("../utils/Vec3Pool"),r=c("../equations/ContactEquation"),p=c("../equations/FrictionEquation");a.prototype.createContactEquation=function(a,b,c,e,d,f){if(this.contactPointPool.length){var h=this.contactPointPool.pop();h.bi=a;h.bj=b}else h=new r(a,b);h.enabled=a.collisionResponse&&b.collisionResponse&&c.collisionResponse&&e.collisionResponse;var g=this.currentContactMaterial;h.restitution=g.restitution;h.setSpookParams(g.contactEquationStiffness,
g.contactEquationRelaxation,this.world.dt);a=c.material||a.material;b=e.material||b.material;a&&b&&0<=a.restitution&&0<=b.restitution&&(h.restitution=a.restitution*b.restitution);h.si=d||c;h.sj=f||e;return h};a.prototype.createFrictionEquationsFromContact=function(a,b){var c=a.bi,e=a.bj,d=this.world,f=this.currentContactMaterial,h=f.friction,g=a.si.material||c.material,q=a.sj.material||e.material;g&&q&&0<=g.friction&&0<=q.friction&&(h=g.friction*q.friction);if(0<h){h*=d.gravity.length();g=c.invMass+
e.invMass;0<g&&(g=1/g);var l=this.frictionEquationPool;q=l.length?l.pop():new p(c,e,h*g);l=l.length?l.pop():new p(c,e,h*g);q.bi=l.bi=c;q.bj=l.bj=e;q.minForce=l.minForce=-h*g;q.maxForce=l.maxForce=h*g;q.ri.copy(a.ri);q.rj.copy(a.rj);l.ri.copy(a.ri);l.rj.copy(a.rj);a.ni.tangents(q.t,l.t);q.setSpookParams(f.frictionEquationStiffness,f.frictionEquationRelaxation,d.dt);l.setSpookParams(f.frictionEquationStiffness,f.frictionEquationRelaxation,d.dt);q.enabled=l.enabled=a.enabled;b.push(q,l);return!0}return!1};
var e=new b,h=new b,q=new b;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];e.setZero();h.setZero();q.setZero();for(var f=b.bi,g=0;g!==a;g++)b=this.result[this.result.length-1-g],b.bodyA!==f?(e.vadd(b.ni,e),h.vadd(b.ri,h),q.vadd(b.rj,q)):(e.vsub(b.ni,e),h.vadd(b.rj,h),q.vadd(b.ri,
q));a=1/a;h.scale(a,c.ri);q.scale(a,c.rj);d.ri.copy(c.ri);d.rj.copy(c.rj);e.normalize();e.tangents(c.t,d.t)}};var u=new b,t=new b,w=new n,v=new n;a.prototype.getContacts=function(a,b,c,e,d,f,h){this.contactPointPool=d;this.frictionEquationPool=h;this.result=e;this.frictionResult=f;e=0;for(d=a.length;e!==d;e++){f=a[e];h=b[e];var g=null;f.material&&h.material&&(g=c.getContactMaterial(f.material,h.material)||null);for(var q=0;q<f.shapes.length;q++){f.quaternion.mult(f.shapeOrientations[q],w);f.quaternion.vmult(f.shapeOffsets[q],
u);u.vadd(f.position,u);for(var l=f.shapes[q],m=0;m<h.shapes.length;m++){h.quaternion.mult(h.shapeOrientations[m],v);h.quaternion.vmult(h.shapeOffsets[m],t);t.vadd(h.position,t);var p=h.shapes[m];if(!(u.distanceTo(t)>l.boundingSphereRadius+p.boundingSphereRadius)){var n=null;l.material&&p.material&&(n=c.getContactMaterial(l.material,p.material)||null);this.currentContactMaterial=n||g||c.defaultContactMaterial;(n=this[l.type|p.type])&&(l.type<p.type?n.call(this,l,p,u,t,w,v,f,h,l,p):n.call(this,p,l,
t,u,v,w,h,f,l,p))}}}}};a.prototype[g.types.BOX|g.types.BOX]=a.prototype.boxBox=function(a,b,c,e,d,f,h,g){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,e,d,f,h,g,a,b)};a.prototype[g.types.BOX|g.types.CONVEXPOLYHEDRON]=
a.prototype.boxConvex=function(a,b,c,e,d,f,h,g){a.convexPolyhedronRepresentation.material=a.material;a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse;this.convexConvex(a.convexPolyhedronRepresentation,b,c,e,d,f,h,g,a,b)};a.prototype[g.types.BOX|g.types.PARTICLE]=a.prototype.boxParticle=function(a,b,c,e,d,f,h,g){a.convexPolyhedronRepresentation.material=a.material;a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse;this.convexParticle(a.convexPolyhedronRepresentation,
b,c,e,d,f,h,g,a,b)};a.prototype[g.types.SPHERE]=a.prototype.sphereSphere=function(a,b,c,e,d,f,h,g){d=this.createContactEquation(h,g,a,b);e.vsub(c,d.ni);d.ni.normalize();d.ri.copy(d.ni);d.rj.copy(d.ni);d.ri.mult(a.radius,d.ri);d.rj.mult(-b.radius,d.rj);d.ri.vadd(c,d.ri);d.ri.vsub(h.position,d.ri);d.rj.vadd(e,d.rj);d.rj.vsub(g.position,d.rj);this.result.push(d);this.createFrictionEquationsFromContact(d,this.frictionResult)};var z=new b,C=new b,x=new b;a.prototype[g.types.PLANE|g.types.TRIMESH]=a.prototype.planeTrimesh=
function(a,c,d,e,f,h,g,q){var l=new b;z.set(0,0,1);f.vmult(z,z);for(f=0;f<c.vertices.length/3;f++){c.getVertex(f,l);var p=new b;p.copy(l);m.pointToWorldFrame(e,h,p,l);p=C;l.vsub(d,p);if(0>=z.dot(p)){var n=this.createContactEquation(g,q,a,c);n.ni.copy(z);var u=x;z.scale(p.dot(z),u);l.vsub(u,u);n.ri.copy(u);n.ri.vsub(g.position,n.ri);n.rj.copy(l);n.rj.vsub(q.position,n.rj);this.result.push(n);this.createFrictionEquationsFromContact(n,this.frictionResult)}}};var D=new b,F=new b;new b;var K=new b,B=new b,
P=new b,Q=new b,H=new b,E=new b,I=new b,A=new b,N=new b,L=new b,W=new b,y=new d,J=[];a.prototype[g.types.SPHERE|g.types.TRIMESH]=a.prototype.sphereTrimesh=function(a,b,c,d,e,h,g,q){m.pointToLocalFrame(d,h,c,I);e=a.radius;y.lowerBound.set(I.x-e,I.y-e,I.z-e);y.upperBound.set(I.x+e,I.y+e,I.z+e);b.getTrianglesInAABB(y,J);var l=a.radius*a.radius;for(e=0;e<J.length;e++)for(var p=0;3>p;p++)if(b.getVertex(b.indices[3*J[e]+p],K),K.vsub(I,F),F.norm2()<=l){B.copy(K);m.pointToWorldFrame(d,h,B,K);K.vsub(c,F);
var n=this.createContactEquation(g,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(g.position,n.ri);n.rj.copy(K);n.rj.vsub(q.position,n.rj);this.result.push(n);this.createFrictionEquationsFromContact(n,this.frictionResult)}for(e=0;e<J.length;e++)for(p=0;3>p;p++)b.getVertex(b.indices[3*J[e]+p],P),b.getVertex(b.indices[3*J[e]+(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(g,q,a,b),A.vsub(I,n.ni),n.ni.normalize(),n.ni.scale(a.radius,n.ri),m.pointToWorldFrame(d,h,A,A),A.vsub(q.position,n.rj),m.vectorToWorldFrame(h,n.ni,n.ni),m.vectorToWorldFrame(h,n.ri,n.ri),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult)));e=0;for(p=J.length;e!==p;e++)b.getTriangleVertices(J[e],N,L,W),b.getNormal(J[e],D),I.vsub(N,A),c=A.dot(D),D.scale(c,A),I.vsub(A,A),c=
A.distanceTo(I),f.pointInTriangle(A,N,L,W)&&c<a.radius&&(n=this.createContactEquation(g,q,a,b),A.vsub(I,n.ni),n.ni.normalize(),n.ni.scale(a.radius,n.ri),m.pointToWorldFrame(d,h,A,A),A.vsub(q.position,n.rj),m.vectorToWorldFrame(h,n.ni,n.ni),m.vectorToWorldFrame(h,n.ri,n.ri),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult));J.length=0};var V=new b,U=new b;a.prototype[g.types.SPHERE|g.types.PLANE]=a.prototype.spherePlane=function(a,b,c,e,d,f,h,g){b=this.createContactEquation(h,
g,a,b);b.ni.set(0,0,1);f.vmult(b.ni,b.ni);b.ni.negate(b.ni);b.ni.normalize();b.ni.mult(a.radius,b.ri);c.vsub(e,V);b.ni.mult(b.ni.dot(V),U);V.vsub(U,b.rj);-V.dot(b.ni)<=a.radius&&(a=b.ri,f=b.rj,a.vadd(c,a),a.vsub(h.position,a),f.vadd(e,f),f.vsub(g.position,f),this.result.push(b),this.createFrictionEquationsFromContact(b,this.frictionResult))};var R=new b,G=new b,O=new b,T=new b,M=new b,S=new b,Z=new b,X=[new b,new b,new b,new b,new b,new b],ja=new b,ba=new b,Y=new b,da=new b;a.prototype[g.types.SPHERE|
g.types.BOX]=a.prototype.sphereBox=function(a,b,c,e,d,f,h,g){d=this.v3pool;c.vsub(e,T);b.getSideNormals(X,f);f=a.radius;for(var q=!1,l=null,m=0,p=0,n=0,u=null,r=0,y=X.length;r!==y&&!1===q;r++){var x=M;x.copy(X[r]);var t=x.norm();x.normalize();var v=T.dot(x);if(v<t+f&&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-t-f),null===u||v<u)&&(u=v,p=A,n=z,l=t,ba.copy(x),Y.copy(L),da.copy(w),
m++)}}m&&(q=!0,m=this.createContactEquation(h,g,a,b),ba.mult(-f,m.ri),m.ni.copy(ba),m.ni.negate(m.ni),ba.mult(l,ba),Y.mult(p,Y),ba.vadd(Y,ba),da.mult(n,da),ba.vadd(da,m.rj),m.ri.vadd(c,m.ri),m.ri.vsub(h.position,m.ri),m.rj.vadd(e,m.rj),m.rj.vsub(g.position,m.rj),this.result.push(m),this.createFrictionEquationsFromContact(m,this.frictionResult));v=d.get();for(l=0;2!==l&&!q;l++)for(p=0;2!==p&&!q;p++)for(n=0;2!==n&&!q;n++)v.set(0,0,0),l?v.vadd(X[0],v):v.vsub(X[0],v),p?v.vadd(X[1],v):v.vsub(X[1],v),n?
v.vadd(X[2],v):v.vsub(X[2],v),e.vadd(v,ja),ja.vsub(c,ja),ja.norm2()<f*f&&(q=!0,m=this.createContactEquation(h,g,a,b),m.ri.copy(ja),m.ri.normalize(),m.ni.copy(m.ri),m.ri.mult(f,m.ri),m.rj.copy(v),m.ri.vadd(c,m.ri),m.ri.vsub(h.position,m.ri),m.rj.vadd(e,m.rj),m.rj.vsub(g.position,m.rj),this.result.push(m),this.createFrictionEquationsFromContact(m,this.frictionResult));d.release(v);u=d.get();r=d.get();m=d.get();y=d.get();v=d.get();x=X.length;for(l=0;l!==x&&!q;l++)for(p=0;p!==x&&!q;p++)if(l%3!==p%3){X[p].cross(X[l],
u);u.normalize();X[l].vadd(X[p],r);m.copy(c);m.vsub(r,m);m.vsub(e,m);t=m.dot(u);u.mult(t,y);for(n=0;n===l%3||n===p%3;)n++;v.copy(c);v.vsub(y,v);v.vsub(r,v);v.vsub(e,v);t=Math.abs(t);L=v.norm();t<X[n].norm()&&L<f&&(q=!0,n=this.createContactEquation(h,g,a,b),r.vadd(y,n.rj),n.rj.copy(n.rj),v.negate(n.ni),n.ni.normalize(),n.ri.copy(n.rj),n.ri.vadd(e,n.ri),n.ri.vsub(c,n.ri),n.ri.normalize(),n.ri.mult(f,n.ri),n.ri.vadd(c,n.ri),n.ri.vsub(h.position,n.ri),n.rj.vadd(e,n.rj),n.rj.vsub(g.position,n.rj),this.result.push(n),
this.createFrictionEquationsFromContact(n,this.frictionResult))}d.release(u,r,m,y,v)};var fa=new b,ca=new b,ka=new b,ha=new b,ma=new b,oa=new b,la=new b,na=new b,va=new b,sa=new b;a.prototype[g.types.SPHERE|g.types.CONVEXPOLYHEDRON]=a.prototype.sphereConvex=function(a,b,c,e,d,f,h,g){d=this.v3pool;c.vsub(e,fa);for(var q=b.faceNormals,l=b.faces,m=b.vertices,p=a.radius,n=0;n!==m.length;n++){var u=ma;f.vmult(m[n],u);e.vadd(u,u);var r=ha;u.vsub(c,r);if(r.norm2()<p*p){a=this.createContactEquation(h,g,a,
b);a.ri.copy(r);a.ri.normalize();a.ni.copy(a.ri);a.ri.mult(p,a.ri);u.vsub(e,a.rj);a.ri.vadd(c,a.ri);a.ri.vsub(h.position,a.ri);a.rj.vadd(e,a.rj);a.rj.vsub(g.position,a.rj);this.result.push(a);this.createFrictionEquationsFromContact(a,this.frictionResult);return}}n=0;for(u=l.length;n!==u;n++){r=l[n];var y=oa;f.vmult(q[n],y);var x=la;f.vmult(m[r[0]],x);x.vadd(e,x);var v=na;y.mult(-p,v);c.vadd(v,v);var t=va;v.vsub(x,t);v=t.dot(y);t=sa;c.vsub(x,t);if(0>v&&0<t.dot(y)){x=[];t=0;for(var L=r.length;t!==L;t++){var w=
d.get();f.vmult(m[r[t]],w);e.vadd(w,w);x.push(w)}a:{t=x;L=y;w=c;for(var D=null,B=t.length,A=0;A!==B;A++){var z=t[A],F=R;t[(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{t=!1;break a}}t=!0}if(t){a=this.createContactEquation(h,g,a,b);y.mult(-p,a.ri);y.negate(a.ni);b=d.get();y.mult(-v,b);f=d.get();y.mult(-p,f);c.vsub(e,a.rj);a.rj.vadd(f,a.rj);a.rj.vadd(b,a.rj);a.rj.vadd(e,a.rj);a.rj.vsub(g.position,a.rj);a.ri.vadd(c,a.ri);
a.ri.vsub(h.position,a.ri);d.release(b);d.release(f);this.result.push(a);this.createFrictionEquationsFromContact(a,this.frictionResult);t=0;for(r=x.length;t!==r;t++)d.release(x[t]);break}else for(t=0;t!==r.length;t++){y=d.get();v=d.get();f.vmult(m[r[(t+1)%r.length]],y);f.vmult(m[r[(t+2)%r.length]],v);e.vadd(y,y);e.vadd(v,v);B=ca;v.vsub(y,B);D=ka;B.unit(D);L=d.get();w=d.get();c.vsub(y,w);A=w.dot(D);D.mult(A,L);L.vadd(y,L);D=d.get();L.vsub(c,D);if(0<A&&A*A<B.norm2()&&D.norm2()<p*p){a=this.createContactEquation(h,
g,a,b);L.vsub(e,a.rj);L.vsub(c,a.ni);a.ni.normalize();a.ni.mult(p,a.ri);a.rj.vadd(e,a.rj);a.rj.vsub(g.position,a.rj);a.ri.vadd(c,a.ri);a.ri.vsub(h.position,a.ri);this.result.push(a);this.createFrictionEquationsFromContact(a,this.frictionResult);t=0;for(r=x.length;t!==r;t++)d.release(x[t]);d.release(y);d.release(v);d.release(L);d.release(D);d.release(w);return}d.release(y);d.release(v);d.release(L);d.release(D);d.release(w)}t=0;for(r=x.length;t!==r;t++)d.release(x[t])}}};new b;new b;a.prototype[g.types.PLANE|
g.types.BOX]=a.prototype.planeBox=function(a,b,c,d,e,f,h,g){b.convexPolyhedronRepresentation.material=b.material;b.convexPolyhedronRepresentation.collisionResponse=b.collisionResponse;this.planeConvex(a,b.convexPolyhedronRepresentation,c,d,e,f,h,g)};var ia=new b,aa=new b,pa=new b,Sa=new b;a.prototype[g.types.PLANE|g.types.CONVEXPOLYHEDRON]=a.prototype.planeConvex=function(a,b,c,d,e,f,h,g){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]),f.vmult(ia,ia),
d.vadd(ia,ia),ia.vsub(c,pa),0>=aa.dot(pa)){var l=this.createContactEquation(h,g,a,b),m=Sa;aa.mult(aa.dot(pa),m);ia.vsub(m,m);m.vsub(c,l.ri);l.ni.copy(aa);ia.vsub(d,l.rj);l.ri.vadd(c,l.ri);l.ri.vsub(h.position,l.ri);l.rj.vadd(d,l.rj);l.rj.vsub(g.position,l.rj);this.result.push(l);e++;this.enableFrictionReduction||this.createFrictionEquationsFromContact(l,this.frictionResult)}this.enableFrictionReduction&&e&&this.createFrictionFromAverage(e)};var ab=new b,Ta=new b;a.prototype[g.types.CONVEXPOLYHEDRON]=
a.prototype.convexConvex=function(a,b,c,e,d,f,h,g,l,q,m,p){if(!(c.distanceTo(e)>a.boundingSphereRadius+b.boundingSphereRadius)&&a.findSeparatingAxis(b,c,d,e,f,ab,m,p)){m=[];a.clipAgainstHull(c,d,b,e,f,ab,-100,100,m);for(f=d=0;f!==m.length;f++){p=this.createContactEquation(h,g,a,b,l,q);var n=p.ri,u=p.rj;ab.negate(p.ni);m[f].normal.negate(Ta);Ta.mult(m[f].depth,Ta);m[f].point.vadd(Ta,n);u.copy(m[f].point);n.vsub(c,n);u.vsub(e,u);n.vadd(c,n);n.vsub(h.position,n);u.vadd(e,u);u.vsub(g.position,u);this.result.push(p);
d++;this.enableFrictionReduction||this.createFrictionEquationsFromContact(p,this.frictionResult)}this.enableFrictionReduction&&d&&this.createFrictionFromAverage(d)}};var Fa=new b,eb=new b,ea=new b;a.prototype[g.types.PLANE|g.types.PARTICLE]=a.prototype.planeParticle=function(a,b,c,d,e,f,h,g){Fa.set(0,0,1);h.quaternion.vmult(Fa,Fa);d.vsub(h.position,eb);0>=Fa.dot(eb)&&(a=this.createContactEquation(g,h,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 b;a.prototype[g.types.PARTICLE|g.types.SPHERE]=a.prototype.sphereParticle=function(a,b,c,d,e,f,h,g){Ba.set(0,0,1);d.vsub(c,Ba);Ba.norm2()<=a.radius*a.radius&&(b=this.createContactEquation(g,h,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 b;
new b;var Ia=new b,Ma=new b,Ca=new b;a.prototype[g.types.PARTICLE|g.types.CONVEXPOLYHEDRON]=a.prototype.convexParticle=function(a,b,c,d,e,f,h,g){var l=-1;f=null;var q=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 m=a.faces.length;e!==m;e++){var p=a.worldFaceNormals[e];d.vsub(a.worldVertices[a.faces[e][0]],Ma);var n=-p.dot(Ma);if(null===
f||Math.abs(n)<Math.abs(f))f=n,l=e,Ia.copy(p),q++}-1!==l?(a=this.createContactEquation(g,h,b,a),Ia.mult(f,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,f=a.rj,b.vadd(d,b),b.vsub(g.position,b),f.vadd(c,f),f.vsub(h.position,f),this.result.push(a),this.createFrictionEquationsFromContact(a,this.frictionResult)):console.warn("Point found inside convex, but did not find penetrating face!")}};a.prototype[g.types.BOX|g.types.HEIGHTFIELD]=a.prototype.boxHeightfield=function(a,
b,c,e,d,f,h,g){a.convexPolyhedronRepresentation.material=a.material;a.convexPolyhedronRepresentation.collisionResponse=a.collisionResponse;this.convexHeightfield(a.convexPolyhedronRepresentation,b,c,e,d,f,h,g)};var Da=new b,za=new b,Va=[0];a.prototype[g.types.CONVEXPOLYHEDRON|g.types.HEIGHTFIELD]=a.prototype.convexHeightfield=function(a,b,c,e,d,f,h,g){var l=b.data,q=b.elementSize,p=a.boundingSphereRadius;m.pointToLocalFrame(e,f,c,Da);var n=Math.floor((Da.x-p)/q)-1,u=Math.ceil((Da.x+p)/q)+1,r=Math.floor((Da.y-
p)/q)-1;q=Math.ceil((Da.y+p)/q)+1;if(!(0>u||0>q||n>l.length||r>l[0].length)){0>n&&(n=0);0>u&&(u=0);0>r&&(r=0);0>q&&(q=0);n>=l.length&&(n=l.length-1);u>=l.length&&(u=l.length-1);q>=l[0].length&&(q=l[0].length-1);r>=l[0].length&&(r=l[0].length-1);l=[];b.getRectMinMax(n,r,u,q,l);var y=l[0];if(!(Da.z-p>l[1]||Da.z+p<y))for(p=n;p<u;p++)for(n=r;n<q;n++)b.getConvexTrianglePillar(p,n,!1),m.pointToWorldFrame(e,f,b.pillarOffset,za),c.distanceTo(za)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&
this.convexConvex(a,b.pillarConvex,c,za,d,f,h,g,null,null,Va,null),b.getConvexTrianglePillar(p,n,!0),m.pointToWorldFrame(e,f,b.pillarOffset,za),c.distanceTo(za)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&this.convexConvex(a,b.pillarConvex,c,za,d,f,h,g,null,null,Va,null)}};var Ea=new b,wa=new b;a.prototype[g.types.SPHERE|g.types.HEIGHTFIELD]=a.prototype.sphereHeightfield=function(a,b,c,e,d,f,h,g){var l=b.data,q=a.radius,p=b.elementSize;m.pointToLocalFrame(e,f,c,Ea);var n=Math.floor((Ea.x-
q)/p)-1,u=Math.ceil((Ea.x+q)/p)+1,r=Math.floor((Ea.y-q)/p)-1;p=Math.ceil((Ea.y+q)/p)+1;if(!(0>u||0>p||n>l.length||p>l[0].length)){0>n&&(n=0);0>u&&(u=0);0>r&&(r=0);0>p&&(p=0);n>=l.length&&(n=l.length-1);u>=l.length&&(u=l.length-1);p>=l[0].length&&(p=l[0].length-1);r>=l[0].length&&(r=l[0].length-1);l=[];b.getRectMinMax(n,r,u,p,l);var y=l[0];if(!(Ea.z-q>l[1]||Ea.z+q<y))for(q=this.result;n<u;n++)for(l=r;l<p;l++)if(y=q.length,b.getConvexTrianglePillar(n,l,!1),m.pointToWorldFrame(e,f,b.pillarOffset,wa),
c.distanceTo(wa)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&this.sphereConvex(a,b.pillarConvex,c,wa,d,f,h,g),b.getConvexTrianglePillar(n,l,!0),m.pointToWorldFrame(e,f,b.pillarOffset,wa),c.distanceTo(wa)<b.pillarConvex.boundingSphereRadius+a.boundingSphereRadius&&this.sphereConvex(a,b.pillarConvex,c,wa,d,f,h,g),2<q.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(c,d,g){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 f;this.broadphase=new t;this.bodies=[];this.solver=new b;this.constraints=[];this.narrowphase=new m(this);this.collisionMatrix=new l;
this.collisionMatrixPrevious=new l;this.materials=[];this.contactmaterials=[];this.contactMaterialTable=new h;this.defaultMaterial=new r("default");this.defaultContactMaterial=new p(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}}d.exports=a;c("../shapes/Shape");
var f=c("../math/Vec3");d=c("../math/Quaternion");var b=c("../solver/GSSolver");c("../utils/Vec3Pool");c("../equations/ContactEquation");c("../equations/FrictionEquation");var m=c("./Narrowphase"),n=c("../utils/EventTarget"),l=c("../collision/ArrayCollisionMatrix"),r=c("../material/Material"),p=c("../material/ContactMaterial"),e=c("../objects/Body"),h=c("../utils/TupleDictionary"),q=c("../collision/RaycastResult");g=c("../collision/AABB");var u=c("../collision/Ray"),t=c("../collision/NaiveBroadphase");
a.prototype=new n;new g;var w=new u;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 e&&(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,e){c.mode=u.ALL;c.from=a;c.to=b;c.callback=e;return w.intersectWorld(this,c)};a.prototype.raycastAny=function(a,b,c,e){c.mode=u.ANY;c.from=a;c.to=b;c.result=e;return w.intersectWorld(this,c)};a.prototype.raycastClosest=function(a,b,c,e){c.mode=u.CLOSEST;c.from=a;c.to=b;c.result=e;return w.intersectWorld(this,c)};a.prototype.remove=function(a){a.world=
null;var b=this.bodies.length-1,c=this.bodies,e=c.indexOf(a);if(-1!==e){c.splice(e,1);for(e=0;e!==c.length;e++)c[e].index=e;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 f;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 f=0;f!==d&&!(this.internalStep(a),performance.now()-c>1E3*a);f++);this.time+=b;a=this.time%a/
a;b=this.bodies;for(d=0;d!==b.length;d++)c=b[d],c.type!==e.STATIC&&c.sleepState!==e.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 f;new f;new f;new f;new f;new f;new f;new f;new f;new d;var Q=new d,H=new d,E=new f;a.prototype.internalStep=function(a){this.dt=
a;var b=this.contacts,c=this.numObjects(),d=this.bodies,f=this.solver,h=this.gravity,g=this.doProfiling,l=this.profile,q=e.DYNAMIC,m,p=this.constraints;h.norm();var n=h.x,u=h.y,r=h.z;g&&(m=performance.now());for(h=0;h!==c;h++){var t=d[h];if(t.type&q){var v=t.force;t=t.mass;v.x+=t*n;v.y+=t*u;v.z+=t*r}}h=0;for(t=this.subsystems.length;h!==t;h++)this.subsystems[h].update();g&&(m=performance.now());B.length=0;P.length=0;this.broadphase.collisionPairs(this,B,P);g&&(l.broadphase=performance.now()-m);t=
p.length;for(h=0;h!==t;h++)if(n=p[h],!n.collideConnected)for(u=B.length-1;0<=u;--u)if(n.bodyA===B[u]&&n.bodyB===P[u]||n.bodyB===B[u]&&n.bodyA===P[u])B.splice(u,1),P.splice(u,1);this.collisionMatrixTick();g&&(m=performance.now());t=b.length;for(h=0;h!==t;h++)F.push(b[h]);b.length=0;t=this.frictionEquations.length;for(h=0;h!==t;h++)K.push(this.frictionEquations[h]);this.frictionEquations.length=0;this.narrowphase.getContacts(B,P,this,b,F,this.frictionEquations,K);g&&(l.narrowphase=performance.now()-
m);g&&(m=performance.now());for(h=0;h<this.frictionEquations.length;h++)f.addEquation(this.frictionEquations[h]);h=b.length;for(u=0;u!==h;u++)n=b[u],t=n.bi,r=n.bj,t.material&&r.material&&this.getContactMaterial(t.material,r.material),t.material&&r.material&&0<=t.material.restitution&&0<=r.material.restitution&&(n.restitution=t.material.restitution*r.material.restitution),f.addEquation(n),t.allowSleep&&t.type===e.DYNAMIC&&t.sleepState===e.SLEEPING&&r.sleepState===e.AWAKE&&r.type!==e.STATIC&&r.velocity.norm2()+
r.angularVelocity.norm2()>=2*Math.pow(r.sleepSpeedLimit,2)&&(t._wakeUpAfterNarrowphase=!0),r.allowSleep&&r.type===e.DYNAMIC&&r.sleepState===e.SLEEPING&&t.sleepState===e.AWAKE&&t.type!==e.STATIC&&t.velocity.norm2()+t.angularVelocity.norm2()>=2*Math.pow(t.sleepSpeedLimit,2)&&(r._wakeUpAfterNarrowphase=!0),this.collisionMatrix.set(t,r,!0),this.collisionMatrixPrevious.get(t,r)||(D.body=r,D.contact=n,t.dispatchEvent(D),D.body=t,r.dispatchEvent(D));g&&(l.makeContactConstraints=performance.now()-m,m=performance.now());
for(h=0;h!==c;h++)t=d[h],t._wakeUpAfterNarrowphase&&(t.wakeUp(),t._wakeUpAfterNarrowphase=!1);t=p.length;for(h=0;h!==t;h++)for(n=p[h],n.update(),u=0,b=n.equations.length;u!==b;u++)f.addEquation(n.equations[u]);f.solve(a,this);g&&(l.solve=performance.now()-m);f.removeAllEquations();f=Math.pow;for(h=0;h!==c;h++)if(t=d[h],t.type&q&&(p=f(1-t.linearDamping,a),b=t.velocity,b.mult(p,b),p=t.angularVelocity))b=f(1-t.angularDamping,a),p.mult(b,p);this.dispatchEvent(x);for(h=0;h!==c;h++)t=d[h],t.preStep&&t.preStep.call(t);
g&&(m=performance.now());q=e.DYNAMIC|e.KINEMATIC;f=0===this.stepnumber%(this.quatNormalizeSkip+1);p=this.quatNormalizeFast;b=.5*a;for(h=0;h!==c;h++)if(t=d[h],n=t.force,u=t.torque,t.type&q&&t.sleepState!==e.SLEEPING){r=t.velocity;v=t.angularVelocity;var w=t.position,z=t.quaternion,I=t.invMass,Y=t.invInertiaWorld;r.x+=n.x*I*a;r.y+=n.y*I*a;r.z+=n.z*I*a;t.angularVelocity&&(Y.vmult(u,E),E.mult(a,E),E.vadd(v,v));w.x+=r.x*a;w.y+=r.y*a;w.z+=r.z*a;t.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,f&&(p?z.normalizeFast():z.normalize()));t.aabb&&(t.aabbNeedsUpdate=!0);t.updateInertiaWorld&&t.updateInertiaWorld()}this.clearForces();this.broadphase.dirty=!0;g&&(l.integrate=performance.now()-m);this.time+=a;this.stepnumber+=1;this.dispatchEvent(C);for(h=0;h!==c;h++)t=d[h],(a=t.postStep)&&a.call(t);if(this.allowSleep)for(h=0;h!==c;h++)d[h].sleepTick(this.time)};a.prototype.clearForces=function(){for(var a=this.bodies,b=a.length,c=0;c!==b;c++){var e=a[c];e.force.set(0,
0,0);e.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(k){function c(){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 d(a){function b(a,c){a.material&&(a.material=c);for(var e=0;e<a.children.length;e++)b(a.children[e],c)}if(-1===V.indexOf(a))throw Error("Render mode "+a+" not found!");switch(a){case "solid":e.currentMaterial=K;U.intensity=1;R.color.setHex(2236962);break;case "wireframe":e.currentMaterial=
B,U.intensity=0,R.color.setHex(16777215)}for(var c=0;c<w.length;c++)b(w[c],e.currentMaterial);q.rendermode=a}function g(){for(var a=t.length,b=0;b<a;b++){var c=t[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 f(){for(var b=t.length,c=0;c<b;c++){var e=t[c],d=w[c];d.position.copy(e.position);
e.quaternion&&d.quaternion.copy(e.quaternion)}Q.restart();if(q.contacts)for(c=0;c<J.contacts.length;c++)for(b=0;2>b;b++){d=Q.request();var f=J.contacts[c];e=0===b?f.bi:f.bj;var h=0===b?f.ri:f.rj;d.position.set(e.position.x+h.x,e.position.y+h.y,e.position.z+h.z)}Q.hideCached();H.restart();if(q.cm2contact)for(c=0;c<J.contacts.length;c++)for(b=0;2>b;b++)d=H.request(),f=J.contacts[c],e=0===b?f.bi:f.bj,h=0===b?f.ri:f.rj,d.scale.set(h.x,h.y,h.z),a(d.scale),d.position.copy(e.position);H.hideCached();N.restart();
L.restart();if(q.constraints){for(c=0;c<J.constraints.length;c++)f=J.constraints[c],f instanceof CANNON.DistanceConstraint&&(e=f.equations.normal,b=e.bi,e=e.bj,d=N.request(),e=e.position?e.position:e,d.scale.set(e.x-b.position.x,e.y-b.position.y,e.z-b.position.z),a(d.scale),d.position.copy(b.position));for(c=0;c<J.constraints.length;c++)if(f=J.constraints[c],f instanceof CANNON.PointToPointConstraint){h=f.equations.normal;b=h.bi;e=h.bj;d=L.request();f=L.request();var g=L.request();d.scale.set(h.ri.x,
h.ri.y,h.ri.z);f.scale.set(h.rj.x,h.rj.y,h.rj.z);g.scale.set(-h.penetrationVec.x,-h.penetrationVec.y,-h.penetrationVec.z);a(d.scale);a(f.scale);a(g.scale);d.position.copy(b.position);f.position.copy(e.position);h.bj.position.vadd(h.rj,g.position)}}L.hideCached();N.hideCached();W.restart();if(q.normals)for(c=0;c<J.contacts.length;c++)f=J.contacts[c],b=f.bi,d=W.request(),h=f.ni,e=b,d.scale.set(h.x,h.y,h.z),a(d.scale),d.position.copy(e.position),f.ri.vadd(d.position,d.position);W.hideCached();y.restart();
if(q.axes)for(b=0;b<t.length;b++)e=t[b],d=y.request(),d.position.copy(e.position),e.quaternion&&d.quaternion.copy(e.quaternion);y.hideCached();A.restart();if(q.aabbs)for(c=0;c<t.length;c++)e=t[c],e.computeAABB&&(e.aabbNeedsUpdate&&e.computeAABB(),isFinite(e.aabb.lowerBound.x)&&isFinite(e.aabb.lowerBound.y)&&isFinite(e.aabb.lowerBound.z)&&isFinite(e.aabb.upperBound.x)&&isFinite(e.aabb.upperBound.y)&&isFinite(e.aabb.upperBound.z)&&0!=e.aabb.lowerBound.x-e.aabb.upperBound.x&&0!=e.aabb.lowerBound.y-e.aabb.upperBound.y&&
0!=e.aabb.lowerBound.z-e.aabb.upperBound.z&&(d=A.request(),d.scale.set(e.aabb.lowerBound.x-e.aabb.upperBound.x,e.aabb.lowerBound.y-e.aabb.upperBound.y,e.aabb.lowerBound.z-e.aabb.upperBound.z),d.position.set(.5*(e.aabb.lowerBound.x+e.aabb.upperBound.x),.5*(e.aabb.lowerBound.y+e.aabb.upperBound.y),.5*(e.aabb.lowerBound.z+e.aabb.upperBound.z))));A.hideCached()}function b(){requestAnimationFrame(b);if(!q.paused){f();var a=1/q.stepFrequency,c=Date.now()/1E3;Y?J.step(a,c-Y,q.maxSubSteps):J.step(a);Y=c}CAMERA_TEST&&
S.update();Z.clear();Z.render(e.scene,camera);G.update()}function m(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 l(a){e.dispatchEvent({type:"destroy"});q.paused=!1;c();r(a)}function r(a){for(var b=w.length,d=0;d<b;d++){J.remove(t.pop());var f=w.pop();e.scene.remove(f)}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;c();Q.restart();Q.hideCached();H.restart();H.hideCached();N.restart();N.hideCached();W.restart();W.hideCached()}function p(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 e=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(){l(c)};h.add(D,a)};this.restartCurrentScene=g;this.changeScene=l;this.start=function(){r(0)};var h,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};k=k||{};for(var u in k)u in q&&(q[u]=k[u]);if(0!==q.stepFrequency%60)throw Error("stepFrequency must be a multiple of 60.");var t=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 p(function(){return new THREE.Mesh(F,P)}),H=new p(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 p(function(){return new THREE.Mesh(E,I)}),N=new p(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 p(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 p(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 p(function(){var a=new THREE.Object3D,b=new THREE.Vector3(0,0,0),c=new THREE.Geometry,e=new THREE.Geometry,d=new THREE.Geometry;c.vertices.push(b);e.vertices.push(b);d.vertices.push(b);c.vertices.push(new THREE.Vector3(1,0,0));e.vertices.push(new THREE.Vector3(0,1,0));d.vertices.push(new THREE.Vector3(0,
0,1));b=new THREE.Line(c,new THREE.LineBasicMaterial({color:16711680}));e=new THREE.Line(e,new THREE.LineBasicMaterial({color:65280}));d=new THREE.Line(d,new THREE.LineBasicMaterial({color:255}));a.add(b);a.add(e);a.add(d);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=e.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",m);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 c=0;for(g in J.profile){var f=
a[c%a.length];b[g]=new TimeSeries({label:g,fillStyle:"rgb("+f[0]+","+f[1]+","+f[2]+")",maxDataLength:500});c++}J.addEventListener("postStep",function(a){for(var c in J.profile)b[c].append(1E3*J.time,J.profile[c])});c=0;for(g in J.profile)f=a[c%a.length],C.addTimeSeries(b[g],{strokeStyle:"rgb("+f[0]+","+f[1]+","+f[2]+")",lineWidth:2}),c++;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 g=z.addFolder("Rendering");g.add(q,"rendermode",{Solid:"solid",Wireframe:"wireframe"}).onChange(function(a){d(a)});g.add(q,"contacts");g.add(q,"cm2contact");g.add(q,"normals");g.add(q,"constraints");g.add(q,"axes");g.add(q,"particleSize").min(0).max(1).onChange(function(a){for(var b=0;b<w.length;b++)t[b]instanceof CANNON.Particle&&w[b].scale.set(a,a,a)});g.add(q,"shadows").onChange(function(a){a?Z.shadowMapAutoUpdate=
!0:(Z.shadowMapAutoUpdate=!1,Z.clearTarget(U.shadowMap))});g.add(q,"aabbs");g.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")});g=z.addFolder("World");g.add(q,"paused").onChange(function(a){});g.add(q,"stepFrequency",60,600).step(60);g.add(q,"gx",-100,100).onChange(function(a){isNaN(a)||J.gravity.set(a,q.gy,q.gz)});g.add(q,"gy",-100,100).onChange(function(a){isNaN(a)||J.gravity.set(q.gx,a,q.gz)});g.add(q,
"gz",-100,100).onChange(function(a){isNaN(a)||J.gravity.set(q.gx,q.gy,a)});g.add(q,"quatNormalizeSkip",0,50).step(1).onChange(function(a){isNaN(a)||(J.quatNormalizeSkip=a)});g.add(q,"quatNormalizeFast").onChange(function(a){J.quatNormalizeFast=!!a});g=z.addFolder("Solver");g.add(q,"iterations",1,50).step(1).onChange(function(a){J.solver.iterations=a});g.add(q,"k",10,1E7).onChange(function(a){e.setGlobalSpookParams(q.k,q.d,1/q.stepFrequency)});g.add(q,"d",0,20).step(.1).onChange(function(a){e.setGlobalSpookParams(q.k,
q.d,1/q.stepFrequency)});g.add(q,"tolerance",0,10).step(.01).onChange(function(a){J.solver.tolerance=a});h=z.addFolder("Scenes");h.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)})();b();var Y=0;document.addEventListener("keypress",function(a){if(a.keyCode)switch(a.keyCode){case 32:g();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;c();break;case 99:q.constraints=!q.constraints;c();break;case 112:q.paused=!q.paused;c();break;case 115:J.step(1/q.stepFrequency);f();break;case 109:a=V.indexOf(q.rendermode);a++;a%=V.length;d(V[a]);c();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/)&&
l(a.keyCode-49)}})};CANNON.Demo.prototype=new CANNON.EventTarget;CANNON.Demo.constructor=CANNON.Demo;
CANNON.Demo.prototype.setGlobalSpookParams=function(k,c,d){for(var g=this.world,a=0;a<g.constraints.length;a++)for(var f=g.constraints[a],b=0;b<f.equations.length;b++)f.equations[b].setSpookParams(k,c,d);for(a=0;a<g.contactmaterials.length;a++)d=g.contactmaterials[a],d.contactEquationStiffness=k,d.frictionEquationStiffness=k,d.contactEquationRelaxation=c,d.frictionEquationRelaxation=c;g.defaultContactMaterial.contactEquationStiffness=k;g.defaultContactMaterial.frictionEquationStiffness=k;g.defaultContactMaterial.contactEquationRelaxation=
c;g.defaultContactMaterial.frictionEquationRelaxation=c};CANNON.Demo.prototype.getWorld=function(){return this.world};CANNON.Demo.prototype.addVisual=function(k,c){var d;k instanceof CANNON.Body&&(d=this.shape2mesh(k,c));d&&(this.bodies.push(k),this.visuals.push(d),k.visualref=d,k.visualref.visualId=this.bodies.length-1,this.scene.add(d));return d};CANNON.Demo.prototype.addVisuals=function(k){for(var c=0;c<k.length;c++)this.addVisual(k[c])};
CANNON.Demo.prototype.removeVisual=function(k){if(k.visualref){for(var c=this.bodies,d=this.visuals,g=[],a=[],f=c.length,b=0;b<f;b++)g.unshift(c.pop()),a.unshift(d.pop());f=k.visualref.visualId;for(var m=0;m<g.length;m++)m!==f&&(b=m>f?m-1:m,c[b]=g[m],d[b]=a[m],c[b].visualref=g[m].visualref,c[b].visualref.visualId=b);k.visualref.visualId=null;this.scene.remove(k.visualref);k.visualref=null}};CANNON.Demo.prototype.removeAllVisuals=function(){for(;this.bodies.length;)this.removeVisual(this.bodies[0])};
CANNON.Demo.prototype.shape2mesh=function(k,c){for(var d=new THREE.Object3D,g=0;g<k.shapes.length;g++){var a=k.shapes[g];switch(a.type){case CANNON.Shape.types.SPHERE:var f=new THREE.SphereGeometry(a.radius,8,8);a=new THREE.Mesh(f,this.currentMaterial);break;case CANNON.Shape.types.PARTICLE:a=new THREE.Mesh(this.particleGeo,this.particleMaterial);f=this.settings;a.scale.set(f.particleSize,f.particleSize,f.particleSize);break;case CANNON.Shape.types.PLANE:var b=new THREE.PlaneGeometry(10,10,4,4);a=
new THREE.Object3D;f=new THREE.Object3D;b=new THREE.Mesh(b,this.currentMaterial);b.scale.set(100,100,100);f.add(b);b.castShadow=!0;b.receiveShadow=!0;a.add(f);break;case CANNON.Shape.types.BOX:f=new THREE.BoxGeometry(2*a.halfExtents.x,2*a.halfExtents.y,2*a.halfExtents.z);a=new THREE.Mesh(f,this.currentMaterial);break;case CANNON.Shape.types.CONVEXPOLYHEDRON:b=new THREE.Geometry;for(f=0;f<a.vertices.length;f++){var m=a.vertices[f];b.vertices.push(new THREE.Vector3(m.x,m.y,m.z))}for(f=0;f<a.faces.length;f++){var n=
a.faces[f],l=n[0];for(m=1;m<n.length-1;m++)b.faces.push(new THREE.Face3(l,n[m],n[m+1]))}b.computeBoundingSphere();b.computeFaceNormals();a=new THREE.Mesh(b,this.currentMaterial);break;case CANNON.Shape.types.HEIGHTFIELD:b=new THREE.Geometry;n=new CANNON.Vec3;l=new CANNON.Vec3;var r=new CANNON.Vec3;for(m=0;m<a.data.length-1;m++)for(var p=0;p<a.data[m].length-1;p++)for(var e=0;2>e;e++)a.getConvexTrianglePillar(m,p,0===e),n.copy(a.pillarConvex.vertices[0]),l.copy(a.pillarConvex.vertices[1]),r.copy(a.pillarConvex.vertices[2]),
n.vadd(a.pillarOffset,n),l.vadd(a.pillarOffset,l),r.vadd(a.pillarOffset,r),b.vertices.push(new THREE.Vector3(n.x,n.y,n.z),new THREE.Vector3(l.x,l.y,l.z),new THREE.Vector3(r.x,r.y,r.z)),f=b.vertices.length-3,b.faces.push(new THREE.Face3(f,f+1,f+2));b.computeBoundingSphere();b.computeFaceNormals();a=new THREE.Mesh(b,this.currentMaterial);break;case CANNON.Shape.types.TRIMESH:b=new THREE.Geometry;n=new CANNON.Vec3;l=new CANNON.Vec3;r=new CANNON.Vec3;for(f=0;f<a.indices.length/3;f++)a.getTriangleVertices(f,
n,l,r),b.vertices.push(new THREE.Vector3(n.x,n.y,n.z),new THREE.Vector3(l.x,l.y,l.z),new THREE.Vector3(r.x,r.y,r.z)),m=b.vertices.length-3,b.faces.push(new THREE.Face3(m,m+1,m+2));b.computeBoundingSphere();b.computeFaceNormals();f=11184810;c&&(f=c);f=new THREE.MeshPhongMaterial({color:f,specular:1118481,shininess:100});a=new THREE.Mesh(b,f);break;default:throw"Visual type not recognized: "+a.type;}a.receiveShadow=!0;a.castShadow=!0;if(a.children)for(f=0;f<a.children.length;f++)if(a.children[f].castShadow=
!0,a.children[f].receiveShadow=!0,a.children[f])for(m=0;m<a.children[f].length;m++)a.children[f].children[m].castShadow=!0,a.children[f].children[m].receiveShadow=!0;f=k.shapeOffsets[g];b=k.shapeOrientations[g];a.position.set(f.x,f.y,f.z);a.quaternion.set(b.x,b.y,b.z,b.w);d.add(a)}this.camera=function(){return camera};this.getScene=function(){return scene};return d};
function CLevelMenu(){var k,c,d,g,a,f,b,m,n=[],l,r,p,e,h,q=null,u=null,t,w;this._init=function(){b=0;r=createBitmap(s_oSpriteLibrary.getSprite("bg_menu"));s_oStage.addChild(r);t=new createjs.Shape;t.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);t.alpha=.7;s_oStage.addChild(t);m=new createjs.Container;m.x=0;m.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;m.addChild(v,w);s_oStage.addChild(m);v=.5*CANVAS_WIDTH-20;w=-200;var C=-100;l=s_oLocalStorage.getItemJson(LOCALSTORAGE_SCORE);for(var x=0;x<l.length;x++)0<l[x]&&b++;var D=0;for(x=0;x<l.length;x++)D+=l[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<l.length;x++,w+=170)700<w&&(w=-200,C+=150),x<=b?(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;f=v.height/2+17;p=new CGfxButton(a,f,v,s_oStage);p.addEventListener(ON_MOUSE_UP,this._onExit,this);if(!1===DISABLE_SOUND_MOBILE||!1===s_bMobile)v=s_oSpriteLibrary.getSprite("audio_icon"),d=a-v.height-10,g=f,e=new CToggle(d,g,v,s_bAudioActive,
s_oStage),e.addEventListener(ON_MOUSE_UP,this._onAudioToggle,this);v=window.document;w=v.documentElement;q=w.requestFullscreen||w.mozRequestFullScreen||w.webkitRequestFullScreen||w.msRequestFullscreen;u=v.exitFullscreen||v.mozCancelFullScreen||v.webkitExitFullscreen||v.msExitFullscreen;!1===ENABLE_FULLSCREEN&&(q=!1);q&&screenfull.enabled&&(v=s_oSpriteLibrary.getSprite("but_fullscreen"),k=v.width/4+10,c=f,h=new CToggle(k,c,v,s_bFullscreen,s_oStage),h.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);(new createjs.Tween.get(t)).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&&h.unload();t.off("mousedown",w);s_oLevelMenu=null;s_oStage.removeAllChildren()};this.refreshButtonPos=function(b,l){!1!==DISABLE_SOUND_MOBILE&&!1!==s_bMobile||e.setPosition(d-b,g+l);q&&screenfull.enabled&&
h.setPosition(k+b,c+l);p.setPosition(a-b,f+l)};this._setLevelInfo=function(){b<NUM_HOLES&&(n[b].enable(),n[b].pulseAnimation());for(var a=0;a<b;a++)n[a].enable(),0<l[a]&&l[a]<PAR_POINTS-ADDED_POINTS?n[a].addStar(1):l[a]>=PAR_POINTS-ADDED_POINTS&&l[a]<PAR_POINTS?n[a].addStar(2):n[a].addStar(3),n[a].addScore(l[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=t.on("mousedown",function(){});createjs.Tween.get(t,{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(){h.setActive(s_bFullscreen)};this._onFullscreenRelease=function(){s_bFullscreen?u.call(window.document):q.call(window.document.documentElement);sizeHandler()};s_oLevelMenu=this;this._init()}
var s_oLevelMenu=null;
function CLevelBut(k,c,d,g,a,f){var b,m,n,l,r=[],p,e,h=null,q=null,u,t,w,v,z;this._init=function(a,c,d,f){b=!1;m=1;n=[];l=[];p=new createjs.Container;p.x=a;p.y=c;p.scaleX=p.scaleY=m;f.addChild(p);e=new createjs.Container;e.x=a;e.y=c;e.scaleX=p.scaleY=m;f.addChild(e);a=d.width/2;c=d.height;d=new createjs.SpriteSheet({images:[d],frames:{width:a,height:c,regX:a/2,regY:c/2},animations:{on:[0],off:[1]}});u=createSprite(d,"on",a/2,c/2,a,c);p.addChild(u);g?u.gotoAndStop("on"):u.gotoAndStop("off");this._initListener()};
this.unload=function(){s_bMobile?p.off("mousedown",w):(p.off("mousedown",w),p.off("mouseover",v));p.off("pressup",z);f.removeChild(p)};this.setVisible=function(a){p.visible=a};this.enable=function(){u.gotoAndStop("on");b=!1;null!==q&&(h.color="#3e240b",q.color="#ffd800")};this.disable=function(){b=!0;u.gotoAndStop("off");null!==q&&(h.color="#000000",q.color="#a8a8a8")};this.setClickable=function(a){b=!a};this.addStar=function(a){var b=s_oSpriteLibrary.getSprite("star");t=new CAchievementStars(b,0,
-b.height/2-14,p);t.getContainer().scaleX=t.getContainer().scaleY=.4;t.startLitStar(a)};this.addScore=function(a){var b=new createjs.Text(a," 12px "+PRIMARY_FONT,"#3e240b");b.y=d.height/2-10;b.textAlign="center";b.textBaseline="middle";b.lineWidth=200;b.outline=4;e.addChild(b);a=new createjs.Text(a," 12px "+PRIMARY_FONT,"#ffd800");a.y=b.y;a.textAlign="center";a.textBaseline="middle";a.lineWidth=200;e.addChild(a)};this.addLevelText=function(a){h=new createjs.Text(a," 30px "+PRIMARY_FONT,"#3e240b");
h.y=5;h.textAlign="center";h.textBaseline="middle";h.lineWidth=200;h.outline=8;p.addChild(h);q=new createjs.Text(a," 30px "+PRIMARY_FONT,"#ffd800");q.y=5;q.textAlign="center";q.textBaseline="middle";q.lineWidth=200;p.addChild(q)};this._initListener=function(){s_bMobile?w=p.on("mousedown",this.buttonDown):(w=p.on("mousedown",this.buttonDown),v=p.on("mouseover",this.buttonOver));z=p.on("pressup",this.buttonRelease)};this.addEventListener=function(a,b,c){n[a]=b;l[a]=c};this.addEventListenerWithParams=
function(a,b,c,e){n[a]=b;l[a]=c;r=e};this.buttonRelease=function(){b||(p.scaleX=m,p.scaleY=m,n[ON_MOUSE_UP]&&n[ON_MOUSE_UP].call(l[ON_MOUSE_UP],r))};this.buttonDown=function(){b||(playSound("click",1,!1),p.scaleX=.9*m,p.scaleY=.9*m,n[ON_MOUSE_DOWN]&&n[ON_MOUSE_DOWN].call(l[ON_MOUSE_DOWN],r))};this.buttonOver=function(a){s_bMobile||b||(a.target.cursor="pointer")};this.pulseAnimation=function(){createjs.Tween.get(p).to({scaleX:.9*m,scaleY:.9*m},850,createjs.Ease.quadOut).to({scaleX:m,scaleY:m},650,
createjs.Ease.quadIn).call(function(){C.pulseAnimation()})};this.trembleAnimation=function(){createjs.Tween.get(p).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){p.x=a;p.y=b};this.setScale=function(a){m=a;p.scaleX=p.scaleY=a};this.setX=function(a){p.x=a};this.setY=function(a){p.y=a};this.getButtonImage=function(){return p};this.getX=function(){return p.x};
this.getY=function(){return p.y};var C=this;this._init(k,c,d,f);return this}
function CBall(k,c,d,g){var a,f,b,m,n,l,r,p,e,h,q,u,t,w,v,z,C,x,D,F,K,B,P,Q,H,E;this._init=function(a,b,c,d){n=!1;e=3;r=0;p=MAX_MOUSE_DISTANCE_POWER_ACTIVATED-MIN_MOUSE_DISTANCE_POWER_ACTIVATED;h=c.height;q=10;E=new CVector2(-.845,.534);u=new createjs.Container;u.x=a;u.y=b;d.addChild(u);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;u.addChild(K);w=new createjs.Shape;u.addChild(w);z=new createjs.Container;z.visible=!1;z.y=
q;u.addChild(z);a=s_oSpriteLibrary.getSprite("ball_water");F=createBitmap(a);F.regX=.54*a.width;F.regY=.5*a.height;u.addChild(F);t=createBitmap(c);t.regX=.5*c.width;t.regY=.5*c.height;u.addChild(t);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;u.addChild(C);D=new createjs.Shape;D.graphics.beginFill("rgba(255,0,0,0.01)").drawCircle(0,0,c.width/2);u.addChild(D);t.mask=x;v=new createjs.Shape;v.graphics.beginFill("rgba(255,0,0,0.01)").drawCircle(0,
0,100);u.addChild(v);P=u.on("mousedown",this._onClickPoint);Q=u.on("pressmove",this._onDragPoint);H=u.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(c){if(!n){z.visible=!0;var e=s_oGame.get3DBall().position.x,d=s_oGame.get3DBall().position.y,h=s_oGame.get3DBall().position.z,g=new CVector2(c.localX,c.localY),q=Math.degrees(angleBetweenVectors(E,g));g=rotateVector2D(Math.radians(0<q&&66>=q?13*-q/33+150:0>q&&-114<=q?13*q/56+150:66<q?13*Math.abs(q)/57+2070/
19:13*-q/34+1380/17),g);e=convert3dPosTo2dScreen({x:e+g.x,y:d-g.y,z:h},s_oGame.getCamera());a=e.x;f=e.y;b=g.x;m=g.y;l=Math.sqrt(c.localX*c.localX+c.localY*c.localY);r=(l-(s_bMobile?MIN_MOUSE_DISTANCE_POWER_ACTIVATED_MOBILE:MIN_MOUSE_DISTANCE_POWER_ACTIVATED))/p*MAX_SHOT_POWER;I._drawLine(c.localX,c.localY);I._drawArrow()}};this._onReleaseForce=function(a){n||(z.visible=!1,w.graphics.clear(),0>=r||(r>MAX_SHOT_POWER&&(r=MAX_SHOT_POWER),a=new CVector2(b,m),a.normalize(),a.scalarProduct(r),s_oGame.launchBall({x:a.getX(),
y:-a.getY()}),I.setMoving(!0),I.pressIndicatorStop(),r=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-u.x,f-u.y);b=Math.degrees(angleBetweenVectors(E,b));z.rotation=b;C.scaleX=r/MAX_SHOT_POWER*.83+.17};this.unload=function(){u.removeAllEventListeners();g.removeChild(u);
u.off("mousedown",P);u.off("mousemove",Q);u.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;u.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(u).to({alpha:0},100-15*e).to({alpha:1},300-45*e).wait(100-20*e).call(function(){e--;0<e?I.blink():e=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;t.mask=x;x.scaleY=1};this.setWaterMask=function(a){F.visible=!0;F.alpha=a;t.mask=D;D.y=h*a-h};this.setHoleMask=function(a){F.visible=
!1;t.mask=D;D.y=h*a-h};this.setVisible=function(a){u.visible=a};this.setPosition=function(a,b){u.x=a;u.y=b};this.setAlpha=function(a){u.alpha=a};this.setAngle=function(a){u.rotation=a};this.getX=function(){return u.x};this.getY=function(){return u.y};this.scale=function(a){u.scaleX=a;u.scaleY=a};this.getScale=function(){return u.scaleX};this.childIndex=function(a){g.setChildIndex(u,a)};this._init(k,c,d,g);var I=this;return this}
function CScenario(k){var c,d,g,a,f,b,m,n,l,r,p,e,h,q,u,t,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=t=null;r=[];h=[];q=[];c=SHOW_3D_RENDER?C.getWorld():new CANNON.World;c.gravity.set(0,0,-98.1);c.broadphase=new CANNON.NaiveBroadphase;c.solver.iterations=10;new CANNON.Material;d=new CANNON.Material;g=new CANNON.Material;var a=new CANNON.ContactMaterial(d,g,{friction:0,restitution:.4,contactEquationStiffness:1E8,contactEquationRelaxation:3,
frictionEquationStiffness:1E8,frictionEquationRegularizationTime:3});c.addContactMaterial(a);p=[];e=[];a=new THREE.LoadingManager;a.onProgress=function(a,b,c){console.log(a,b,c)};(new THREE.FBXLoader(a)).load("models/level_"+k+".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);l=new CANNON.Body({mass:0,material:g});l.addShape(n);a=new CANNON.Vec3(a.position.x,a.position.y,a.position.z);l.position.copy(a);l.addEventListener("collide",function(a){u=!0});c.addBody(l);SHOW_3D_RENDER&&C.addVisual(l)};this._createBallBody=function(e){a=
new CANNON.Sphere(BALL_RADIUS);f=new CANNON.Body({mass:BALL_MASS,material:d,linearDamping:BALL_LINEAR_DAMPING,angularDamping:BALL_LINEAR_DAMPING});e=new CANNON.Vec3(e.position.x,e.position.y,e.position.z);f.position.copy(e);f.previousPosition.copy(e);f.addShape(a);c.add(f);SHOW_3D_RENDER&&(b=C.addVisual(f))};this.testPosMesh=function(){return b};this._createHoleBody=function(a){m=new CANNON.Vec3(a.position.x,a.position.y,a.position.z);a=this.__extractMeshData(a);var b=q.length;q.push(new CANNON.Body({mass:0,
material:g}));q[b].collisionResponse=0;q[b].ID=b;q[b].addEventListener("collide",function(a){v=a.target.ID});q[b].addShape(a);q[b].position.copy(m);c.add(q[b]);SHOW_3D_RENDER&&C.addVisual(q[b],16711680)};this._createBigSandBody=function(a){var b=r.length;e[b]=new CANNON.Vec3(a.position.x,a.position.y,a.position.z);p[b]=this.__extractMeshData(a);r[b]=new CANNON.Body({mass:0,material:g});r[b].collisionResponse=0;r[b].ID=b;r[b].addEventListener("collide",function(a){t=a.target.ID});r[b].addShape(p[b]);
r[b].position.copy(e[b]);c.add(r[b]);SHOW_3D_RENDER&&C.addVisual(r[b],15636224)};this._createWaterBody=function(a){var b=new CANNON.Vec3(a.position.x,a.position.y,a.position.z);a=this.__extractMeshData(a);var e=h.length;h.push(new CANNON.Body({mass:0,material:g}));h[e].collisionResponse=0;h[e].ID=e;h[e].addEventListener("collide",function(a){w=a.target.ID});h[e].addShape(a);h[e].position.copy(b);c.add(h[e]);SHOW_3D_RENDER&&C.addVisual(h[e],255)};this.__extractMeshData=function(a){var b=a.geometry.faces;
a=a.geometry.vertices;for(var c=0;c<b.length;c++);var e=[],d=[];for(c=0;c<a.length;c++)e.push(1*a[c].x),e.push(1*a[c].y),e.push(1*a[c].z);for(c=0;c<b.length;c++)d.push(b[c].a),d.push(b[c].b),d.push(b[c].c);return new CANNON.Trimesh(e,d)};this.addImpulse=function(a,b){var c=new CANNON.Vec3(0,0,BALL_RADIUS),e=new CANNON.Vec3(b.x,b.y,0);a.applyImpulse(e,c)};this.getBodyVelocity=function(a){return a.velocity};this.ballBody=function(){return f};this.ballMesh=function(){return b};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){c.gravity.set(0,0,a)};this.update=function(){c.step(z);u&&this._checkTerrainCollision();null!==t&&this._checkSandCollision();null!==w&&this._checkWaterCollision();null!==v&&this._checkHoleCollision()};this._checkTerrainCollision=function(){for(var a=0;a<c.contacts.length;a++){var b=
c.contacts[a];if(b.bi===l&&b.bj===f||b.bi===f&&b.bj===l)return s_oGame.ballCollideWithTerrain(!0),!0}s_oGame.ballCollideWithTerrain(!1);return u=!1};this._checkSandCollision=function(){for(var a=0;a<c.contacts.length;a++){var b=c.contacts[a];if(b.bi===r[t]&&b.bj===f||b.bi===f&&b.bj===r[t])return s_oGame.ballCollideWithSand(!0),!0}s_oGame.ballCollideWithSand(!1);t=null;return!1};this._checkWaterCollision=function(){for(var a=0;a<c.contacts.length;a++){var b=c.contacts[a];if(b.bi===h[w]&&b.bj===f||
b.bi===f&&b.bj===h[w])return s_oGame.ballCollideWithWater(!0),!0}s_oGame.ballCollideWithWater(!1);w=null;return!1};this._checkHoleCollision=function(){for(var a=0;a<c.contacts.length;a++){var b=c.contacts[a];if(b.bi===q[v]&&b.bj===f||b.bi===f&&b.bj===q[v])return s_oGame.ballCollideWithHole(!0),!0}s_oGame.ballCollideWithHole(!1);v=null;return!1};this.getHolePosition=function(){return m};this.getAllBigSandsPosition=function(){return e};this.getBigSandPositionByID=function(a){return e[a]};this.getWorld=
function(){return c};this.getField=function(){return l};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(k){return!1}}(),workers:!!window.Worker,fileapi:window.File&&window.FileReader&&window.FileList&&window.Blob,getWebGLErrorMessage:function(){var k=document.createElement("div");k.id="webgl-error-message";k.style.fontFamily="monospace";k.style.fontSize="13px";k.style.fontWeight="normal";k.style.textAlign="center";k.style.background=
"#fff";k.style.color="#000";k.style.padding="1.5em";k.style.width="400px";k.style.margin="5em auto 0";this.webgl||(k.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 k},addGetWebGLMessage:function(k){k=k||{};var c=void 0!==k.parent?k.parent:document.body;k=void 0!==k.id?k.id:"oldie";var d=Detector.getWebGLErrorMessage();d.id=k;c.appendChild(d)}};
function TimeSeries(k){k=k||{};k.resetBoundsInterval=k.resetBoundsInterval||3E3;k.resetBounds=void 0===k.resetBounds?!0:k.resetBounds;this.options=k;this.data=[];this.label=k.label||"";this.maxDataLength=k.maxDataLength||1E3;this.dataPool=[];this.minValue=this.maxValue=Number.NaN;k.resetBounds&&(this.boundsTimer=setInterval(function(c){return function(){c.resetBounds()}}(this),k.resetBoundsInterval))}
TimeSeries.prototype.resetBounds=function(){this.minValue=this.maxValue=Number.NaN;for(var k=0;k<this.data.length;k++)this.maxValue=isNaN(this.maxValue)?this.data[k][1]:Math.max(this.maxValue,this.data[k][1]),this.minValue=isNaN(this.minValue)?this.data[k][1]:Math.min(this.minValue,this.data[k][1])};
TimeSeries.prototype.append=function(k,c){this.lastTimeStamp=k;var d=this.dataPool.length?this.dataPool.pop():[k,c];d[0]=k;d[1]=c;this.data.push(d);this.maxValue=isNaN(this.maxValue)?c:Math.max(this.maxValue,c);for(this.minValue=isNaN(this.minValue)?c:Math.min(this.minValue,c);this.data.length>this.maxDataLength;)this.dataPool.push(this.data.shift())};
function SmoothieChart(k){k=k||{};k.grid=k.grid||{fillStyle:"#000000",strokeStyle:"#777777",lineWidth:1,millisPerLine:1E3,verticalSections:2};k.millisPerPixel=k.millisPerPixel||20;k.fps=k.fps||50;k.maxValueScale=k.maxValueScale||1;k.minValue=k.minValue;k.maxValue=k.maxValue;k.labels=k.labels||{fillStyle:"#ffffff"};k.interpolation=k.interpolation||"bezier";k.scaleSmoothing=k.scaleSmoothing||.125;k.maxDataSetLength=k.maxDataSetLength||2;k.timestampFormatter=k.timestampFormatter||null;this.options=k;
this.seriesSet=[];this.currentValueRange=1;this.currentVisMinValue=0}SmoothieChart.prototype.addTimeSeries=function(k,c){this.seriesSet.push({timeSeries:k,options:c||{}})};SmoothieChart.prototype.removeTimeSeries=function(k){this.seriesSet.splice(this.seriesSet.indexOf(k),1)};SmoothieChart.prototype.streamTo=function(k,c){var d=this;this.render_on_tick=function(){d.render(k,d.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(k){function c(c){return(10>c?"0":"")+c}return c(k.getHours())+":"+c(k.getMinutes())+":"+c(k.getSeconds())};
SmoothieChart.prototype.render=function(k,c){var d=k.getContext("2d"),g=this.options,a=k.clientWidth,f=k.clientHeight;d.save();c-=c%g.millisPerPixel;d.translate(0,0);d.beginPath();d.rect(0,0,a,f);d.clip();d.save();d.fillStyle=g.grid.fillStyle;d.clearRect(0,0,a,f);d.fillRect(0,0,a,f);d.restore();d.save();d.lineWidth=g.grid.lineWidth||1;d.strokeStyle=g.grid.strokeStyle||"#ffffff";if(0<g.grid.millisPerLine)for(var b=c-c%g.grid.millisPerLine;b>=c-a*g.millisPerPixel;b-=g.grid.millisPerLine){d.beginPath();
var m=Math.round(a-(c-b)/g.millisPerPixel);d.moveTo(m,0);d.lineTo(m,f);d.stroke();if(g.timestampFormatter){var n=g.timestampFormatter(new Date(b)),l=d.measureText(n).width/2+d.measureText(v).width+4;m<a-l&&(d.fillStyle=g.labels.fillStyle,d.fillText(n,m-d.measureText(n).width/2,f-2))}d.closePath()}for(v=1;v<g.grid.verticalSections;v++)b=Math.round(v*f/g.grid.verticalSections),d.beginPath(),d.moveTo(0,b),d.lineTo(a,b),d.stroke(),d.closePath();d.beginPath();d.strokeRect(0,0,a,f);d.closePath();d.restore();
v=m=Number.NaN;for(n=0;n<this.seriesSet.length;n++){var r=this.seriesSet[n].timeSeries;isNaN(r.maxValue)||(m=isNaN(m)?r.maxValue:Math.max(m,r.maxValue));isNaN(r.minValue)||(v=isNaN(v)?r.minValue:Math.min(v,r.minValue))}if(!isNaN(m)||!isNaN(v)){m=null!=g.maxValue?g.maxValue:m*g.maxValueScale;null!=g.minValue&&(v=g.minValue);this.currentValueRange+=g.scaleSmoothing*(m-v-this.currentValueRange);this.currentVisMinValue+=g.scaleSmoothing*(v-this.currentVisMinValue);l=this.currentValueRange;var p=this.currentVisMinValue;
for(n=0;n<this.seriesSet.length;n++){d.save();r=this.seriesSet[n].timeSeries;r=r.data;for(var e=this.seriesSet[n].options;r.length>=g.maxDataSetLength&&r[1][0]<c-a*g.millisPerPixel;)r.splice(0,1);d.lineWidth=e.lineWidth||1;d.fillStyle=e.fillStyle;d.strokeStyle=e.strokeStyle||"#ffffff";d.beginPath();var h=0,q=0,u=0;for(b=0;b<r.length;b++){var t=Math.round(a-(c-r[b][0])/g.millisPerPixel),w=r[b][1]-p;w=Math.max(Math.min(f-(l?Math.round(w/l*f):0),f-1),1);if(0==b)h=t,d.moveTo(t,w);else switch(g.interpolation){case "line":d.lineTo(t,
w);break;default:d.bezierCurveTo(Math.round((q+t)/2),u,Math.round(q+t)/2,w,t,w)}q=t;u=w}0<r.length&&e.fillStyle&&(d.lineTo(a+e.lineWidth+1,u),d.lineTo(a+e.lineWidth+1,f+e.lineWidth+1),d.lineTo(h,f+e.lineWidth),d.fill());d.stroke();d.closePath();d.restore()}if(!g.labels.disabled){g.labelOffsetY||(g.labelOffsetY=0);d.fillStyle=g.labels.fillStyle;b=parseFloat(m).toFixed(2);var v=parseFloat(v).toFixed(2);d.fillText(b,a-d.measureText(b).width-2,10);d.fillText(v,a-d.measureText(v).width-2,f-2);for(b=0;b<
this.seriesSet.length;b++)r=this.seriesSet[b].timeSeries,a=r.label,d.fillStyle=r.options.fillStyle||"rgb(255,255,255)",a&&d.fillText(a,2,10*(b+1)+g.labelOffsetY)}}d.restore()};
var Stats=function(){var k=0,c=0,d=Date.now(),g=d,a=d,f=0,b=1E3,m=0,n=[[16,16,48],[0,255,255]],l=0,r=1E3,p=0,e=[[16,48,16],[0,255,0]];var h=document.createElement("div");h.style.cursor="pointer";h.style.width="80px";h.style.opacity="0.9";h.style.zIndex="10001";h.addEventListener("mousedown",function(a){a.preventDefault();k=(k+1)%2;0==k?(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";h.appendChild(q);var u=document.createElement("div");u.style.fontFamily="Helvetica, Arial, sans-serif";u.style.fontSize="9px";u.style.color="rgb("+n[1][0]+","+n[1][1]+","+n[1][2]+")";u.style.fontWeight="bold";u.innerHTML="FPS";q.appendChild(u);var t=document.createElement("div");t.style.position="relative";t.style.width="74px";t.style.height=
"30px";t.style.backgroundColor="rgb("+n[1][0]+","+n[1][1]+","+n[1][2]+")";for(q.appendChild(t);74>t.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]+")";t.appendChild(w)}var v=document.createElement("div");v.style.textAlign="left";v.style.lineHeight="1.2em";v.style.backgroundColor="rgb("+Math.floor(e[0][0]/2)+","+Math.floor(e[0][1]/2)+","+Math.floor(e[0][2]/2)+")";
v.style.padding="0 0 3px 3px";v.style.display="none";h.appendChild(v);var z=document.createElement("div");z.style.fontFamily="Helvetica, Arial, sans-serif";z.style.fontSize="9px";z.style.color="rgb("+e[1][0]+","+e[1][1]+","+e[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("+e[1][0]+","+e[1][1]+","+e[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("+e[0][0]+","+e[0][1]+","+e[0][2]+")",C.appendChild(w);return{domElement:h,update:function(){d=Date.now();l=d-g;r=Math.min(r,l);p=Math.max(p,l);z.textContent=l+" MS ("+r+"-"+p+")";var e=Math.min(30,30-l/200*30);C.appendChild(C.firstChild).style.height=e+"px";g=d;c++;d>a+1E3&&(f=Math.round(1E3*c/(d-a)),b=Math.min(b,f),m=Math.max(m,f),u.textContent=f+" FPS ("+
b+"-"+m+")",e=Math.min(30,30-f/100*30),t.appendChild(t.firstChild).style.height=e+"px",a=d,c=0)}}};
THREE.TrackballControls=function(k,c){function d(a){!1!==b.enabled&&(window.removeEventListener("keydown",d),r=l,l===m.NONE)&&(a.keyCode!==b.keys[m.ROTATE]||b.noRotate?a.keyCode!==b.keys[m.ZOOM]||b.noZoom?a.keyCode!==b.keys[m.PAN]||b.noPan||(l=m.PAN):l=m.ZOOM:l=m.ROTATE)}function g(a){!1!==b.enabled&&(a.preventDefault(),a.stopPropagation(),l!==m.ROTATE||b.noRotate?l!==m.ZOOM||b.noZoom?l!==m.PAN||b.noPan||z.copy(F(a.pageX,a.pageY)):u.copy(F(a.pageX,a.pageY)):h.copy(K(a.pageX,a.pageY)))}function a(c){!1!==
b.enabled&&(c.preventDefault(),c.stopPropagation(),l=m.NONE,document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",a),b.dispatchEvent(D))}function f(a){if(!1!==b.enabled){a.preventDefault();a.stopPropagation();var c=0;a.wheelDelta?c=a.wheelDelta/40:a.detail&&(c=-a.detail/3);q.y+=.01*c;b.dispatchEvent(x);b.dispatchEvent(D)}}var b=this,m={NONE:-1,ROTATE:0,ZOOM:1,PAN:2,TOUCH_ROTATE:3,TOUCH_ZOOM_PAN:4};this.object=k;this.domElement=void 0!==c?c: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,l=m.NONE,r=m.NONE,p=new THREE.Vector3,e=new THREE.Vector3,h=new THREE.Vector3,q=new THREE.Vector2,u=new THREE.Vector2,t=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(c,e){a.set((c-b.screen.left)/b.screen.width,(e-b.screen.top)/b.screen.height);return a}}(),K=function(){var a=new THREE.Vector3,c=new THREE.Vector3,e=new THREE.Vector3;return function(d,f){e.set((d-.5*b.screen.width-b.screen.left)/(.5*b.screen.width),(.5*b.screen.height+b.screen.top-f)/(.5*b.screen.height),
0);var h=e.length();b.noRoll?e.z=h<Math.SQRT1_2?Math.sqrt(1-h*h):.5/h:1<h?e.normalize():e.z=Math.sqrt(1-h*h);p.copy(b.object.position).sub(b.target);a.copy(b.object.up).setLength(e.y);a.add(c.copy(b.object.up).cross(p).setLength(e.x));a.add(p.setLength(e.z));return a}}();this.rotateCamera=function(){var a=new THREE.Vector3,c=new THREE.Quaternion;return function(){var d=Math.acos(e.dot(h)/e.length()/h.length());d&&(a.crossVectors(e,h).normalize(),d*=b.rotateSpeed,c.setFromAxisAngle(a,-d),p.applyQuaternion(c),
b.object.up.applyQuaternion(c),h.applyQuaternion(c),b.staticMoving?e.copy(h):(c.setFromAxisAngle(a,d*(b.dynamicDampingFactor-1)),e.applyQuaternion(c)))}}();this.zoomCamera=function(){if(l===m.TOUCH_ZOOM_PAN){var a=t/w;t=w;p.multiplyScalar(a)}else a=1+(u.y-q.y)*b.zoomSpeed,1!==a&&0<a&&(p.multiplyScalar(a),b.staticMoving?q.copy(u):q.y+=(u.y-q.y)*this.dynamicDampingFactor)};this.panCamera=function(){var a=new THREE.Vector2,c=new THREE.Vector3,e=new THREE.Vector3;return function(){a.copy(z).sub(v);a.lengthSq()&&
(a.multiplyScalar(p.length()*b.panSpeed),e.copy(p).cross(b.object.up).setLength(a.x),e.add(c.copy(b.object.up).setLength(a.y)),b.object.position.add(e),b.target.add(e),b.staticMoving?v.copy(z):v.add(a.subVectors(z,v).multiplyScalar(b.dynamicDampingFactor)))}}();this.checkDistances=function(){b.noZoom&&b.noPan||(p.lengthSq()>b.maxDistance*b.maxDistance&&b.object.position.addVectors(b.target,p.setLength(b.maxDistance)),p.lengthSq()<b.minDistance*b.minDistance&&b.object.position.addVectors(b.target,
p.setLength(b.minDistance)))};this.update=function(){p.subVectors(b.object.position,b.target);b.noRotate||b.rotateCamera();b.noZoom||b.zoomCamera();b.noPan||b.panCamera();b.object.position.addVectors(b.target,p);b.checkDistances();b.object.lookAt(b.target);1E-6<n.distanceToSquared(b.object.position)&&(b.dispatchEvent(C),n.copy(b.object.position))};this.reset=function(){r=l=m.NONE;b.target.copy(b.target0);b.object.position.copy(b.position0);b.object.up.copy(b.up0);p.subVectors(b.object.position,b.target);
b.object.lookAt(b.target);b.dispatchEvent(C);n.copy(b.object.position)};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},!1);this.domElement.addEventListener("mousedown",function(c){!1!==b.enabled&&(c.preventDefault(),c.stopPropagation(),l===m.NONE&&(l=c.button),l!==m.ROTATE||b.noRotate?l!==m.ZOOM||b.noZoom?l!==m.PAN||b.noPan||(v.copy(F(c.pageX,c.pageY)),z.copy(v)):(q.copy(F(c.pageX,c.pageY)),u.copy(q)):(e.copy(K(c.pageX,c.pageY)),h.copy(e)),document.addEventListener("mousemove",
g,!1),document.addEventListener("mouseup",a,!1),b.dispatchEvent(x))},!1);this.domElement.addEventListener("mousewheel",f,!1);this.domElement.addEventListener("DOMMouseScroll",f,!1);this.domElement.addEventListener("touchstart",function(a){if(!1!==b.enabled){switch(a.touches.length){case 1:l=m.TOUCH_ROTATE;e.copy(K(a.touches[0].pageX,a.touches[0].pageY));h.copy(e);break;case 2:l=m.TOUCH_ZOOM_PAN;var c=a.touches[0].pageX-a.touches[1].pageX,d=a.touches[0].pageY-a.touches[1].pageY;w=t=Math.sqrt(c*c+d*
d);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:l=m.NONE}b.dispatchEvent(x)}},!1);this.domElement.addEventListener("touchend",function(a){if(!1!==b.enabled){switch(a.touches.length){case 1:h.copy(K(a.touches[0].pageX,a.touches[0].pageY));e.copy(h);break;case 2:t=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)}l=m.NONE;b.dispatchEvent(D)}},!1);this.domElement.addEventListener("touchmove",
function(a){if(!1!==b.enabled)switch(a.preventDefault(),a.stopPropagation(),a.touches.length){case 1:h.copy(K(a.touches[0].pageX,a.touches[0].pageY));break;case 2:var c=a.touches[0].pageX-a.touches[1].pageX,e=a.touches[0].pageY-a.touches[1].pageY;w=Math.sqrt(c*c+e*e);z.copy(F((a.touches[0].pageX+a.touches[1].pageX)/2,(a.touches[0].pageY+a.touches[1].pageY)/2));break;default:l=m.NONE}},!1);window.addEventListener("keydown",d,!1);window.addEventListener("keyup",function(a){!1!==b.enabled&&(l=r,window.addEventListener("keydown",
d,!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(k,c){c=c||document;var d=c.createElement("link");d.type="text/css";d.rel="stylesheet";d.href=k;c.getElementsByTagName("head")[0].appendChild(d)},inject:function(k,c){c=c||document;var d=document.createElement("style");d.type="text/css";d.innerHTML=k;c.getElementsByTagName("head")[0].appendChild(d)}}}();
dat.utils.common=function(){var k=Array.prototype.forEach,c=Array.prototype.slice;return{BREAK:{},extend:function(d){this.each(c.call(arguments,1),function(c){for(var a in c)this.isUndefined(c[a])||(d[a]=c[a])},this);return d},defaults:function(d){this.each(c.call(arguments,1),function(c){for(var a in c)this.isUndefined(d[a])&&(d[a]=c[a])},this);return d},compose:function(){var d=c.call(arguments);return function(){for(var g=c.call(arguments),a=d.length-1;0<=a;a--)g=[d[a].apply(this,g)];return g[0]}},
each:function(c,g,a){if(k&&c.forEach===k)c.forEach(g,a);else if(c.length===c.length+0)for(var d=0,b=c.length;d<b&&!(d in c&&g.call(a,c[d],d)===this.BREAK);d++);else for(d in c)if(g.call(a,c[d],d)===this.BREAK)break},defer:function(c){setTimeout(c,0)},toArray:function(d){return d.toArray?d.toArray():c.call(d)},isUndefined:function(c){return void 0===c},isNull:function(c){return null===c},isNaN:function(c){return c!==c},isArray:Array.isArray||function(c){return c.constructor===Array},isObject:function(c){return c===
Object(c)},isNumber:function(c){return c===c+0},isString:function(c){return c===c+""},isBoolean:function(c){return!1===c||!0===c},isFunction:function(c){return"[object Function]"===Object.prototype.toString.call(c)}}}();
dat.controllers.Controller=function(k){var c=function(c,g){this.initialValue=c[g];this.domElement=document.createElement("div");this.object=c;this.property=g;this.__onFinishChange=this.__onChange=void 0};k.extend(c.prototype,{onChange:function(c){this.__onChange=c;return this},onFinishChange:function(c){this.__onFinishChange=c;return this},setValue:function(c){this.object[this.property]=c;this.__onChange&&this.__onChange.call(this,c);this.updateDisplay();return this},getValue:function(){return this.object[this.property]},
updateDisplay:function(){return this},isModified:function(){return this.initialValue!==this.getValue()}});return c}(dat.utils.common);
dat.dom.dom=function(k){function c(a){if("0"===a||k.isUndefined(a))return 0;a=a.match(g);return k.isNull(a)?0:parseFloat(a[1])}var d={};k.each({HTMLEvents:["change"],MouseEvents:["click","mousemove","mousedown","mouseup","mouseover"],KeyboardEvents:["keydown"]},function(a,b){k.each(a,function(a){d[a]=b})});var g=/(\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){k.isUndefined(b)&&(b=!0);k.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,c,g){c=c||{};var f=d[b];if(!f)throw Error("Event type "+b+" not supported.");var m=document.createEvent(f);switch(f){case "MouseEvents":m.initMouseEvent(b,c.bubbles||!1,c.cancelable||!0,window,c.clickCount||1,0,0,c.x||c.clientX||0,c.y||c.clientY||0,!1,
!1,!1,!1,0,null);break;case "KeyboardEvents":f=m.initKeyboardEvent||m.initKeyEvent;k.defaults(c,{cancelable:!0,ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1,keyCode:void 0,charCode:void 0});f(b,c.bubbles||!1,c.cancelable,window,c.ctrlKey,c.altKey,c.shiftKey,c.metaKey,c.keyCode,c.charCode);break;default:m.initEvent(b,c.bubbles||!1,c.cancelable||!0)}k.defaults(m,g);a.dispatchEvent(m)},bind:function(c,b,d,g){c.addEventListener?c.addEventListener(b,d,g||!1):c.attachEvent&&c.attachEvent("on"+b,d);return a},
unbind:function(c,b,d,g){c.removeEventListener?c.removeEventListener(b,d,g||!1):c.detachEvent&&c.detachEvent("on"+b,d);return a},addClass:function(c,b){if(void 0===c.className)c.className=b;else if(c.className!==b){var d=c.className.split(/ +/);-1==d.indexOf(b)&&(d.push(b),c.className=d.join(" ").replace(/^\s+/,"").replace(/\s+$/,""))}return a},removeClass:function(c,b){if(b){if(void 0!==c.className)if(c.className===b)c.removeAttribute("class");else{var d=c.className.split(/ +/),f=d.indexOf(b);-1!=
f&&(d.splice(f,1),c.className=d.join(" "))}}else c.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 c(a["border-left-width"])+c(a["border-right-width"])+c(a["padding-left"])+c(a["padding-right"])+c(a.width)},getHeight:function(a){a=getComputedStyle(a);return c(a["border-top-width"])+c(a["border-bottom-width"])+c(a["padding-top"])+c(a["padding-bottom"])+c(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(k,c,d){var g=function(a,f,b){g.superclass.call(this,a,f);var k=this;this.__select=document.createElement("select");if(d.isArray(b)){var n={};d.each(b,function(a){n[a]=a});b=n}d.each(b,function(a,b){var c=document.createElement("option");c.innerHTML=b;c.setAttribute("value",a);k.__select.appendChild(c)});this.updateDisplay();c.bind(this.__select,"change",function(){k.setValue(this.options[this.selectedIndex].value)});this.domElement.appendChild(this.__select)};
g.superclass=k;d.extend(g.prototype,k.prototype,{setValue:function(a){a=g.superclass.prototype.setValue.call(this,a);this.__onFinishChange&&this.__onFinishChange.call(this,this.getValue());return a},updateDisplay:function(){this.__select.value=this.getValue();return g.superclass.prototype.updateDisplay.call(this)}});return g}(dat.controllers.Controller,dat.dom.dom,dat.utils.common);
dat.controllers.NumberController=function(k,c){var d=function(g,a,f){d.superclass.call(this,g,a);f=f||{};this.__min=f.min;this.__max=f.max;this.__step=f.step;c.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;g=this.__impliedStep;g=g.toString();g=-1<g.indexOf(".")?g.length-g.indexOf(".")-1:0;this.__precision=g};d.superclass=k;c.extend(d.prototype,k.prototype,{setValue:function(c){void 0!==
this.__min&&c<this.__min?c=this.__min:void 0!==this.__max&&c>this.__max&&(c=this.__max);void 0!==this.__step&&0!=c%this.__step&&(c=Math.round(c/this.__step)*this.__step);return d.superclass.prototype.setValue.call(this,c)},min:function(c){this.__min=c;return this},max:function(c){this.__max=c;return this},step:function(c){this.__step=c;return this}});return d}(dat.controllers.Controller,dat.utils.common);
dat.controllers.NumberControllerBox=function(k,c,d){var g=function(a,f,b){function k(){var a=parseFloat(r.__input.value);d.isNaN(a)||r.setValue(a)}function n(a){var b=p-a.clientY;r.setValue(r.getValue()+b*r.__impliedStep);p=a.clientY}function l(){c.unbind(window,"mousemove",n);c.unbind(window,"mouseup",l)}this.__truncationSuspended=!1;g.superclass.call(this,a,f,b);var r=this,p;this.__input=document.createElement("input");this.__input.setAttribute("type","text");c.bind(this.__input,"change",k);c.bind(this.__input,
"blur",function(){k();r.__onFinishChange&&r.__onFinishChange.call(r,r.getValue())});c.bind(this.__input,"mousedown",function(a){c.bind(window,"mousemove",n);c.bind(window,"mouseup",l);p=a.clientY});c.bind(this.__input,"keydown",function(a){13===a.keyCode&&(r.__truncationSuspended=!0,this.blur(),r.__truncationSuspended=!1)});this.updateDisplay();this.domElement.appendChild(this.__input)};g.superclass=k;d.extend(g.prototype,k.prototype,{updateDisplay:function(){var a=this.__input;if(this.__truncationSuspended)var c=
this.getValue();else{c=this.getValue();var b=Math.pow(10,this.__precision);c=Math.round(c*b)/b}a.value=c;return g.superclass.prototype.updateDisplay.call(this)}});return g}(dat.controllers.NumberController,dat.dom.dom,dat.utils.common);
dat.controllers.NumberControllerSlider=function(k,c,d,g,a){function f(a,b,c,d,f){return d+(a-b)/(c-b)*(f-d)}var b=function(a,d,g,k,p){function e(a){a.preventDefault();var b=c.getOffset(q.__background),e=c.getWidth(q.__background);q.setValue(f(a.clientX,b.left,b.left+e,q.__min,q.__max));return!1}function h(){c.unbind(window,"mousemove",e);c.unbind(window,"mouseup",h);q.__onFinishChange&&q.__onFinishChange.call(q,q.getValue())}b.superclass.call(this,a,d,{min:g,max:k,step:p});var q=this;this.__background=
document.createElement("div");this.__foreground=document.createElement("div");c.bind(this.__background,"mousedown",function(a){c.bind(window,"mousemove",e);c.bind(window,"mouseup",h);e(a)});c.addClass(this.__background,"slider");c.addClass(this.__foreground,"slider-fg");this.updateDisplay();this.__background.appendChild(this.__foreground);this.domElement.appendChild(this.__background)};b.superclass=k;b.useDefaultStyles=function(){d.inject(a)};g.extend(b.prototype,k.prototype,{updateDisplay:function(){var a=
(this.getValue()-this.__min)/(this.__max-this.__min);this.__foreground.style.width=100*a+"%";return b.superclass.prototype.updateDisplay.call(this)}});return b}(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(k,c,d){var g=function(a,d,b){g.superclass.call(this,a,d);var f=this;this.__button=document.createElement("div");this.__button.innerHTML=void 0===b?"Fire":b;c.bind(this.__button,"click",function(a){a.preventDefault();f.fire();return!1});c.addClass(this.__button,"button");this.domElement.appendChild(this.__button)};g.superclass=k;d.extend(g.prototype,k.prototype,{fire:function(){this.__onChange&&this.__onChange.call(this);this.__onFinishChange&&this.__onFinishChange.call(this,
this.getValue());this.getValue().call(this.object)}});return g}(dat.controllers.Controller,dat.dom.dom,dat.utils.common);
dat.controllers.BooleanController=function(k,c,d){var g=function(a,d){g.superclass.call(this,a,d);var b=this;this.__prev=this.getValue();this.__checkbox=document.createElement("input");this.__checkbox.setAttribute("type","checkbox");c.bind(this.__checkbox,"change",function(){b.setValue(!b.__prev)},!1);this.domElement.appendChild(this.__checkbox);this.updateDisplay()};g.superclass=k;d.extend(g.prototype,k.prototype,{setValue:function(a){a=g.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 g.superclass.prototype.updateDisplay.call(this)}});return g}(dat.controllers.Controller,dat.dom.dom,dat.utils.common);
dat.color.toString=function(k){return function(c){if(1==c.a||k.isUndefined(c.a)){for(c=c.hex.toString(16);6>c.length;)c="0"+c;return"#"+c}return"rgba("+Math.round(c.r)+","+Math.round(c.g)+","+Math.round(c.b)+","+c.a+")"}}(dat.utils.common);
dat.color.interpret=function(k,c){var d,g,a=[{litmus:c.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:k},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:k},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:k},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:k}}},{litmus:c.isNumber,conversions:{HEX:{read:function(a){return{space:"HEX",hex:a,conversionName:"HEX"}},write:function(a){return a.hex}}}},{litmus:c.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:c.isObject,conversions:{RGBA_OBJ:{read:function(a){return c.isNumber(a.r)&&c.isNumber(a.g)&&c.isNumber(a.b)&&c.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 c.isNumber(a.r)&&
c.isNumber(a.g)&&c.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 c.isNumber(a.h)&&c.isNumber(a.s)&&c.isNumber(a.v)&&c.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 c.isNumber(a.h)&&c.isNumber(a.s)&&c.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(){g=!1;
var f=1<arguments.length?c.toArray(arguments):arguments[0];c.each(a,function(a){if(a.litmus(f))return c.each(a.conversions,function(a,b){d=a.read(f);if(!1===g&&!1!==d)return g=d,d.conversionName=b,d.conversion=a,c.BREAK}),c.BREAK});return g}}(dat.color.toString,dat.utils.common);
dat.GUI=dat.gui.GUI=function(k,c,d,g,a,f,b,m,n,l,r,p,e,h,q){function u(b,c,e,d){if(void 0===c[e])throw Error("Object "+c+' has no property "'+e+'"');d.color?c=new r(c,e):(c=[c,e].concat(d.factoryArgs),c=g.apply(b,c));d.before instanceof a&&(d.before=d.before.__li);v(b,c);h.addClass(c.domElement,"c");e=document.createElement("span");h.addClass(e,"property-name");e.innerHTML=c.property;var f=document.createElement("div");f.appendChild(e);f.appendChild(c.domElement);d=t(b,f,d.before);h.addClass(d,N.CLASS_CONTROLLER_ROW);
h.addClass(d,typeof c.getValue());w(b,d,c);b.__controllers.push(c);return c}function t(a,b,c){var e=document.createElement("li");b&&e.appendChild(b);c?a.__ul.insertBefore(e,params.before):a.__ul.appendChild(e);a.onResize();return e}function w(a,c,e){e.__li=c;e.__gui=a;q.extend(e,{options:function(b){if(1<arguments.length)return e.remove(),u(a,e.object,e.property,{before:e.__li.nextElementSibling,factoryArgs:[q.toArray(arguments)]});if(q.isArray(b)||q.isObject(b))return e.remove(),u(a,e.object,e.property,
{before:e.__li.nextElementSibling,factoryArgs:[b]})},name:function(a){e.__li.firstElementChild.firstElementChild.innerHTML=a;return e},listen:function(){e.__gui.listen(e);return e},remove:function(){e.__gui.remove(e);return e}});if(e instanceof n){var d=new m(e.object,e.property,{min:e.__min,max:e.__max,step:e.__step});q.each(["updateDisplay","onChange","onFinishChange"],function(a){var b=e[a],c=d[a];e[a]=d[a]=function(){var a=Array.prototype.slice.call(arguments);b.apply(e,a);return c.apply(d,a)}});
h.addClass(c,"has-slider");e.domElement.insertBefore(d.domElement,e.domElement.firstElementChild)}else if(e instanceof m){var g=function(b){return q.isNumber(e.__min)&&q.isNumber(e.__max)?(e.remove(),u(a,e.object,e.property,{before:e.__li.nextElementSibling,factoryArgs:[e.__min,e.__max,e.__step]})):b};e.min=q.compose(g,e.min);e.max=q.compose(g,e.max)}else e instanceof f?(h.bind(c,"click",function(){h.fakeEvent(e.__checkbox,"click")}),h.bind(e.__checkbox,"click",function(a){a.stopPropagation()})):
e instanceof b?(h.bind(c,"click",function(){h.fakeEvent(e.__button,"click")}),h.bind(c,"mouseover",function(){h.addClass(e.__button,"hover")}),h.bind(c,"mouseout",function(){h.removeClass(e.__button,"hover")})):e instanceof r&&(h.addClass(c,"color"),e.updateDisplay=q.compose(function(a){c.style.borderLeftColor=e.__color.toString();return a},e.updateDisplay),e.updateDisplay());e.setValue=q.compose(function(b){a.getRoot().__preset_select&&e.isModified()&&K(a.getRoot(),!0);return b},e.setValue)}function v(a,
b){var c=a.getRoot(),e=c.__rememberedObjects.indexOf(b.object);if(-1!=e){var d=c.__rememberedObjectIndecesToControllers[e];void 0===d&&(d={},c.__rememberedObjectIndecesToControllers[e]=d);d[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[e]&&void 0!==c[e][b.property]&&(e=c[e][b.property],b.initialValue=e,b.setValue(e))}}}function z(a){var b=a.__save_row=document.createElement("li");h.addClass(a.domElement,"has-save");
a.__ul.insertBefore(b,a.__ul.firstChild);h.addClass(b,"save-row");var c=document.createElement("span");c.innerHTML="&nbsp;";h.addClass(c,"button gears");var e=document.createElement("span");e.innerHTML="Save";h.addClass(e,"button");h.addClass(e,"save");var d=document.createElement("span");d.innerHTML="New";h.addClass(d,"button");h.addClass(d,"save-as");var f=document.createElement("span");f.innerHTML="Revert";h.addClass(f,"button");h.addClass(f,"revert");var g=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);h.bind(g,"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(g);b.appendChild(c);b.appendChild(e);b.appendChild(d);b.appendChild(f);if(P){var l=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");l();h.bind(b,"change",function(){a.useLocalStorage=!a.useLocalStorage;l()})}var m=document.getElementById("dg-new-constructor");h.bind(m,"keydown",function(a){!a.metaKey||67!==a.which&&67!=a.keyCode||Q.hide()});h.bind(c,"click",function(){m.innerHTML=JSON.stringify(a.getSaveObject(),void 0,2);Q.show();m.focus();m.select()});h.bind(e,
"click",function(){a.save()});h.bind(d,"click",function(){var b=prompt("Enter a new preset name.");b&&a.saveAs(b)});h.bind(f,"click",function(){a.revert()})}function C(a){function b(b){b.preventDefault();d=b.clientX;h.addClass(a.__closeButton,N.CLASS_DRAG);h.bind(window,"mousemove",c);h.bind(window,"mouseup",e);return!1}function c(b){b.preventDefault();a.width+=d-b.clientX;a.onResize();d=b.clientX;return!1}function e(){h.removeClass(a.__closeButton,N.CLASS_DRAG);h.unbind(window,"mousemove",c);h.unbind(window,
"mouseup",e)}a.__resize_handle=document.createElement("div");q.extend(a.__resize_handle.style,{width:"6px",marginLeft:"-3px",height:"200px",cursor:"ew-resize",position:"absolute"});var d;h.bind(a.__resize_handle,"mousedown",b);h.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(e,d){var f={};q.each(a.__rememberedObjectIndecesToControllers[d],function(a,c){f[c]=b?a.initialValue:a.getValue()});c[d]=f});return c}function F(a,b,c){var e=document.createElement("option");e.innerHTML=b;e.value=b;a.__preset_select.appendChild(e);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&&
p(function(){B(a)});q.each(a,function(a){a.updateDisplay()})}k.inject(d);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(e.getSaveObject()))}function c(){var a=e.getRoot();a.width+=1;q.defer(function(){--a.width})}var e=this;this.domElement=document.createElement("div");this.__ul=document.createElement("ul");this.domElement.appendChild(this.__ul);h.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 d=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 e.parent?e.getRoot().preset:a.load.preset},set:function(b){e.parent?e.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);e.revert()}},width:{get:function(){return a.width},set:function(b){a.width=b;x(e,b)}},name:{get:function(){return a.name},set:function(b){a.name=b;g&&(g.innerHTML=a.name)}},closed:{get:function(){return a.closed},set:function(b){a.closed=b;a.closed?h.addClass(e.__ul,N.CLASS_CLOSED):h.removeClass(e.__ul,N.CLASS_CLOSED);this.onResize();e.__closeButton&&(e.__closeButton.innerHTML=b?N.TEXT_OPEN:N.TEXT_CLOSED)}},load:{get:function(){return a.load}},useLocalStorage:{get:function(){return d},set:function(a){P&&
((d=a)?h.bind(window,"unload",b):h.unbind(window,"unload",b),localStorage.setItem(document.location.href+".isLocal",a))}}});if(q.isUndefined(a.parent)){a.closed=!1;h.addClass(this.domElement,N.CLASS_MAIN);h.makeSelectable(this.domElement,!1);if(P&&d){e.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;h.addClass(this.__closeButton,N.CLASS_CLOSE_BUTTON);this.domElement.appendChild(this.__closeButton);
h.bind(this.__closeButton,"click",function(){e.closed=!e.closed})}else{void 0===a.closed&&(a.closed=!0);var g=document.createTextNode(a.name);h.addClass(g,"controller-name");f=t(e,g);h.addClass(this.__ul,N.CLASS_CLOSED);h.addClass(f,"title");h.bind(f,"click",function(a){a.preventDefault();e.closed=!e.closed;return!1});a.closed||(this.closed=!1)}a.autoPlace&&(q.isUndefined(a.parent)&&(H&&(E=document.createElement("div"),h.addClass(E,"dg"),h.addClass(E,N.CLASS_AUTO_PLACE_CONTAINER),document.body.appendChild(E),
H=!1),E.appendChild(this.domElement),h.addClass(this.domElement,N.CLASS_AUTO_PLACE)),this.parent||x(e,a.width));h.bind(window,"resize",function(){e.onResize()});h.bind(this.__ul,"webkitTransitionEnd",function(){e.onResize()});h.bind(this.__ul,"transitionend",function(){e.onResize()});h.bind(this.__ul,"oTransitionEnd",function(){e.onResize()});this.onResize();a.resizable&&C(this);e.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";h.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 u(this,a,b,{factoryArgs:Array.prototype.slice.call(arguments,
2)})},addColor:function(a,b){return u(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=t(this,b.domElement);h.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=h.getOffset(a.__ul).top,c=0;q.each(a.__ul.childNodes,function(b){a.autoPlace&&b===a.__save_row||(c+=h.getHeight(b))});window.innerHeight-b-20<c?(h.addClass(a.domElement,N.CLASS_TOO_TALL),a.__ul.style.height=window.innerHeight-
b-20+"px"):(h.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 e,Q.domElement.innerHTML=c);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+f2LUAynwoIaNcz8
dat.controllers.factory=function(k,c,d,g,a,f,b){return function(m,n,l,r){var p=m[n];if(b.isArray(l)||b.isObject(l))return new k(m,n,l);if(b.isNumber(p))return b.isNumber(l)&&b.isNumber(r)?new d(m,n,l,r):new c(m,n,{min:l,max:r});if(b.isString(p))return new g(m,n);if(b.isFunction(p))return new a(m,n,"");if(b.isBoolean(p))return new f(m,n)}}(dat.controllers.OptionController,dat.controllers.NumberControllerBox,dat.controllers.NumberControllerSlider,dat.controllers.StringController=function(k,c,d){var g=
function(a,d){function b(){f.setValue(f.__input.value)}g.superclass.call(this,a,d);var f=this;this.__input=document.createElement("input");this.__input.setAttribute("type","text");c.bind(this.__input,"keyup",b);c.bind(this.__input,"change",b);c.bind(this.__input,"blur",function(){f.__onFinishChange&&f.__onFinishChange.call(f,f.getValue())});c.bind(this.__input,"keydown",function(a){13===a.keyCode&&this.blur()});this.updateDisplay();this.domElement.appendChild(this.__input)};g.superclass=k;d.extend(g.prototype,
k.prototype,{updateDisplay:function(){c.isActive(this.__input)||(this.__input.value=this.getValue());return g.superclass.prototype.updateDisplay.call(this)}});return g}(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(k,c,d,g,a){function f(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 b(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 m=function(l,k){function p(a){n(a);c.bind(window,"mousemove",n);c.bind(window,
"mouseup",e)}function e(){c.unbind(window,"mousemove",n);c.unbind(window,"mouseup",e)}function h(){var a=g(this.value);!1!==a?(w.__color.__state=a,w.setValue(w.__color.toOriginal())):this.value=w.__color.toString()}function q(){c.unbind(window,"mousemove",r);c.unbind(window,"mouseup",q)}function n(a){a.preventDefault();var b=c.getWidth(w.__saturation_field),e=c.getOffset(w.__saturation_field),d=(a.clientX-e.left+document.body.scrollLeft)/b;a=1-(a.clientY-e.top+document.body.scrollTop)/b;1<a?a=1:0>
a&&(a=0);1<d?d=1:0>d&&(d=0);w.__color.v=a;w.__color.s=d;w.setValue(w.__color.toOriginal());return!1}function r(a){a.preventDefault();var b=c.getHeight(w.__hue_field),e=c.getOffset(w.__hue_field);a=1-(a.clientY-e.top+document.body.scrollTop)/b;1<a?a=1:0>a&&(a=0);w.__color.h=360*a;w.setValue(w.__color.toOriginal());return!1}m.superclass.call(this,l,k);this.__color=new d(this.getValue());this.__temp=new d(0);var w=this;this.domElement=document.createElement("div");c.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 ";c.bind(this.__input,"keydown",function(a){13===a.keyCode&&h.call(this)});c.bind(this.__input,"blur",h);c.bind(this.__selector,"mousedown",function(a){c.addClass(this,"drag").bind(window,"mouseup",function(a){c.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"});f(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"});b(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)"});c.bind(this.__saturation_field,"mousedown",p);c.bind(this.__field_knob,"mousedown",p);c.bind(this.__hue_field,"mousedown",function(a){r(a);c.bind(window,
"mousemove",r);c.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()};m.superclass=k;a.extend(m.prototype,k.prototype,{updateDisplay:function(){var b=g(this.getValue());if(!1!==b){var c=!1;
a.each(d.COMPONENTS,function(e){if(!a.isUndefined(b[e])&&!a.isUndefined(this.__color.__state[e])&&b[e]!==this.__color.__state[e])return c=!0,{}},this);c&&a.extend(this.__color.__state,b)}a.extend(this.__temp.__state,this.__color.__state);this.__temp.a=1;var k=.5>this.__color.v||.5<this.__color.s?255:0,e=255-k;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("+k+
","+k+","+k+")"});this.__hue_knob.style.marginTop=100*(1-this.__color.h/360)+"px";this.__temp.s=1;this.__temp.v=1;f(this.__saturation_field,"left","#fff",this.__temp.toString());a.extend(this.__input.style,{backgroundColor:this.__input.value=this.__color.toString(),color:"rgb("+k+","+k+","+k+")",textShadow:this.__input_textShadow+"rgba("+e+","+e+","+e+",.7)"})}});var n=["-moz-","-o-","-webkit-","-ms-",""];return m}(dat.controllers.Controller,dat.dom.dom,dat.color.Color=function(k,c,d,g){function a(a,
c,d){Object.defineProperty(a,c,{get:function(){if("RGB"===this.__state.space)return this.__state[c];b(this,c,d);return this.__state[c]},set:function(a){"RGB"!==this.__state.space&&(b(this,c,d),this.__state.space="RGB");this.__state[c]=a}})}function f(a,b){Object.defineProperty(a,b,{get:function(){if("HSV"===this.__state.space)return this.__state[b];m(this);return this.__state[b]},set:function(a){"HSV"!==this.__state.space&&(m(this),this.__state.space="HSV");this.__state[b]=a}})}function b(a,b,d){if("HEX"===
a.__state.space)a.__state[b]=c.component_from_hex(a.__state.hex,d);else if("HSV"===a.__state.space)g.extend(a.__state,c.hsv_to_rgb(a.__state.h,a.__state.s,a.__state.v));else throw"Corrupted color state";}function m(a){var b=c.rgb_to_hsv(a.r,a.g,a.b);g.extend(a.__state,{s:b.s,v:b.v});g.isNaN(b.h)?g.isUndefined(a.__state.h)&&(a.__state.h=0):a.__state.h=b.h}var n=function(){this.__state=k.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(" ");g.extend(n.prototype,{toString:function(){return d(this)},toOriginal:function(){return this.__state.conversion.write(this)}});a(n.prototype,"r",2);a(n.prototype,"g",1);a(n.prototype,"b",0);f(n.prototype,"h");f(n.prototype,"s");f(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=c.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 k;return{hsv_to_rgb:function(c,d,g){var a=c/60-Math.floor(c/60),f=g*(1-d),b=g*(1-a*d);d=g*(1-(1-a)*d);c=[[g,d,f],[b,g,f],[f,g,d],[f,b,g],[d,f,g],[g,f,b]][Math.floor(c/60)%6];return{r:255*c[0],g:255*c[1],b:255*c[2]}},rgb_to_hsv:function(c,d,g){var a=Math.max(c,d,g),f=a-Math.min(c,d,g);if(0==a)return{h:NaN,s:0,v:0};c=(c==a?(d-g)/f:d==a?2+(g-c)/f:
4+(c-d)/f)/6;0>c&&(c+=1);return{h:360*c,s:f/a,v:a/255}},rgb_to_hex:function(c,d,g){c=this.hex_with_component(0,2,c);c=this.hex_with_component(c,1,d);return c=this.hex_with_component(c,0,g)},component_from_hex:function(c,d){return c>>8*d&255},hex_with_component:function(c,d,g){return g<<(k=8*d)|c&~(255<<k)}}}(),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(k,c){window.setTimeout(k,1E3/60)}}(),dat.dom.CenteredDiv=function(k,c){var d=function(){this.backgroundElement=document.createElement("div");c.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"});k.makeFullscreen(this.backgroundElement);this.backgroundElement.style.position="fixed";this.domElement=document.createElement("div");
c.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 d=this;k.bind(this.backgroundElement,"click",function(){d.hide()})};d.prototype.show=function(){var d=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();c.defer(function(){d.backgroundElement.style.opacity=1;d.domElement.style.opacity=1;d.domElement.style.webkitTransform="scale(1)"})};d.prototype.hide=function(){var c=this,a=function(){c.domElement.style.display="none";c.backgroundElement.style.display="none";k.unbind(c.domElement,"webkitTransitionEnd",a);k.unbind(c.domElement,"transitionend",a);k.unbind(c.domElement,"oTransitionEnd",a)};k.bind(this.domElement,"webkitTransitionEnd",a);k.bind(this.domElement,"transitionend",
a);k.bind(this.domElement,"oTransitionEnd",a);this.backgroundElement.style.opacity=0;this.domElement.style.opacity=0;this.domElement.style.webkitTransform="scale(1.1)"};d.prototype.layout=function(){this.domElement.style.left=window.innerWidth/2-k.getWidth(this.domElement)/2+"px";this.domElement.style.top=window.innerHeight/2-k.getHeight(this.domElement)/2+"px"};return d}(dat.dom.dom,dat.utils.common),dat.dom.dom,dat.utils.common);
(function(){function k(){}function c(){}function d(){this.skinIndices=[];this.skinWeights=[];this.matrices=[]}function g(){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 f(){this.index=this.node=this.ref=this.map=this.uv=null}function b(){this.index=this.node=this.ref=this.map=this.normal=null}function m(){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 l(){this.curves={};this.length=0;this.fps=30;this.frames=0}function r(){this.textures=[];this.perGeoMap={}}function p(){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 e=a[0];a=a.slice(b+1);b++;num=e;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 c).parse(a);console.timeEnd("FBXLoader: TextParser");console.time("FBXLoader: ObjectParser");this.hierarchy=(new g).parseHierarchy(a);this.weights=(new d).parse(a,this.hierarchy);this.animations=(new l).parse(a,this.hierarchy);this.textures=(new r).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 b=0;b<geometries.length;++b)void 0!==
geometries[b]&&a.add(geometries[b]);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 e=[];if(0<b)for(c in a.Objects.subNodes.Geometry)"Mesh"===a.Objects.subNodes.Geometry[c].attrType&&e.push(this.parseGeometry(a.Objects.subNodes.Geometry[c],a));else e.push(this.parseGeometry(a.Objects.subNodes.Geometry,a));return e};THREE.FBXLoader.prototype.parseGeometry=
function(b,c){geo=(new a).parse(b);geo.addBones(this.hierarchy.hierarchy);var e=new THREE.BufferGeometry;e.name=geo.name;e.addAttribute("position",new THREE.BufferAttribute(new Float32Array(geo.vertices),3));void 0!==geo.normals&&0<geo.normals.length&&e.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(geo.normals),3));void 0!==geo.uvs&&0<geo.uvs.length&&e.addAttribute("uv",new THREE.BufferAttribute(new Float32Array(geo.uvs),2));void 0!==geo.indices&&65535<geo.indices.length?e.setIndex(new THREE.BufferAttribute(new Uint32Array(geo.indices),
1)):void 0!==geo.indices&&e.setIndex(new THREE.BufferAttribute(new Uint16Array(geo.indices),1));e.verticesNeedUpdate=!0;e.computeBoundingSphere();e.computeBoundingBox();var d=this.textures.getById(c.searchConnectionParent(geo.id));if(void 0!==d&&0<d.length){null===this.textureLoader&&(this.textureLoader=new THREE.TextureLoader);var f=this.textureLoader.load(this.textureBasePath+"/"+d[0].fileName)}f=void 0!==f?new THREE.MeshBasicMaterial({map:f}):new THREE.MeshBasicMaterial({color:3342591});e=(new THREE.Geometry).fromBufferGeometry(e);
e.bones=geo.bones;e.skinIndices=this.weights.skinIndices;e.skinWeights=this.weights.skinWeights;if(void 0===geo.bones||void 0===geo.skins||void 0===this.animations||0===this.animations.length){e=new THREE.Mesh(e,f);d=c.Connections.properties.connections;var h=c.Objects.subNodes.Model;for(f=0;f<d.length;f++)if(d[f][0]===b.id){e.name=h[d[f][1]].attrName;if(h[d[f][1]].properties.Lcl_Translation){d=h[d[f][1]].properties.Lcl_Translation.value.split(",");for(f=0;f<d.length;f++)d[f]=parseFloat(d[f]);e.position.x=
d[0];e.position.y=d[1];e.position.z=d[2]}break}}else f.skinning=!0,e=new THREE.SkinnedMesh(e,f),this.addAnimation(e,this.weights.matrices,this.animations);return e};THREE.FBXLoader.prototype.addAnimation=function(a,b,c){b={name:"animationtest",fps:30,length:c.length,hierarchy:[]};for(var e=0;e<a.geometry.bones.length;++e){var d=a.geometry.bones[e].name;d=d.replace(/.*:/,"");b.hierarchy.push({parent:a.geometry.bones[e].parent,name:d,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},h=function(a,b){var c=void 0!==a.curves.y.values[b],e=void 0!==a.curves.z.values[b];return void 0!==a.curves.x.values[b]&&c&&e};d=function(a,b){var e={};e.time=frame/c.fps;e.pos=b.pos;e.rot=b.rotq;e.scl=b.scl;if(void 0===a)return e;try{if(f(a,"T")&&h(a.T,frame)){var d=new THREE.Vector3(a.T.curves.x.values[frame],
a.T.curves.y.values[frame],a.T.curves.z.values[frame]);e.pos=[d.x,d.y,d.z]}else delete e.pos;if(f(a,"R")&&h(a.R,frame)){var g=degToRad(a.R.curves.x.values[frame]),q=degToRad(a.R.curves.y.values[frame]),l=degToRad(a.R.curves.z.values[frame]),k=new THREE.Vector3(g,q,l),m=quatFromVec(k.x,k.y,k.z);e.rot=[m.x,m.y,m.z,m.w]}else delete e.rot;if(f(a,"S")&&h(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]);e.scl=[n.x,n.y,n.z]}else delete e.scl}catch(L){console.log(b),
console.log(L)}return e};var g=a.geometry.bones;for(frame=0;frame<c.frames;frame++)for(e=0;e<g.length;e++)for(var q=g[e],l=c.curves[e],k=0;k<b.hierarchy.length;k++)b.hierarchy[k].name===q.name&&b.hierarchy[k].keys.push(d(l,q));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 e=[];if(0<b)for(c in a.subNodes.Material)e.push(parseMaterial(a.subNodes.Material[c]));else e.push(parseMaterial(a.subNodes.Material));return e};THREE.FBXLoader.prototype.parseMaterial=function(a){};THREE.FBXLoader.prototype.loadFile=function(a,b,c,d,f){var e=new THREE.XHRLoader(this.manager);e.setResponseType(f);return e.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")};k.prototype.add=function(a,b){this[a]=b};k.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=[],e=0;e<b.length;++e)b[e][0]==a&&c.push(0===b[e][1]?-1:b[e][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]};k.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=[],e=0;e<b.length;++e)b[e][1]==a&&c.push(0===
b[e][0]?-1:b[e][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]};k.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 e=this.Connections.properties.connections,
d=0;d<e.length;++d)if(e[d][0]==a&&e[d][1]==b)return this.__cache_search_connection_type[c]=e[d][2],e[d][2];return this.__cache_search_connection_type[a]=null};c.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 k;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 e=match[1].trim().replace(/^"/,"").replace(/"$/,""),d=match[2].split(",").map(function(a){return a.trim().replace(/^"/,"").replace(/"$/,"")});this.parseNodeBegin(c,
e,d||null)}else(match=c.match(new RegExp("^\\t{"+this.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)")))?(e=match[1].replace(/^"/,"").replace(/"$/,"").trim(),d=match[2].replace(/^"/,"").replace(/"$/,"").trim(),this.parseNodeProperty(c,e,d)):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 e=this.parseNodeAttr(c),d=this.getCurrentNode();
if(0===this.currentIndent)this.allNodes.add(b,a);else if(b in d.subNodes){var f=d.subNodes[b];this.isFlattenNode(d.subNodes[b])&&(""===e.id?(d.subNodes[b]=[],d.subNodes[b].push(f)):(d.subNodes[b]={},d.subNodes[b][f.id]=f));""===e.id?d.subNodes[b].push(a):d.subNodes[b][e.id]=a}else d.subNodes[b]=a;c&&(a.id=e.id,a.attrName=e.name,a.attrType=e.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 e=a[2]}return{id:b,name:c||"",type:e||""}},parseNodeProperty:function(a,b,c){var e=this.getCurrentNode(),d=e.name;if(void 0!==d&&d.match(/Properties(\d)+/))this.parseNodeSpecialProperty(a,b,c);else{if("C"==b){b=c.split(",").slice(1);a=parseInt(b[0]);d=parseInt(b[1]);var f=c.split(",").slice(3);b="connections";c=[a,d];c=c.concat(f);void 0===e.properties[b]&&(e.properties[b]=[])}"Node"==b&&(a=parseInt(c),e.properties.id=a,e.id=a);b in e.properties?Array.isArray(e.properties[b])?e.properties[b].push(c):
e.properties[b]+=c:Array.isArray(e.properties[b])?e.properties[b].push(c):e.properties[b]=c;this.setCurrentProp(e.properties,b)}},parseNodePropertyContinued:function(a){this.currentProp[this.currentPropName]+=a},parseNodeSpecialProperty:function(a,b,c){var e=c.split('",').map(function(a){return a.trim().replace(/^"/,"").replace(/\s/,"_")});a=e[0];b=e[1];c=e[2];var d=e[3];e=e[4];switch(b){case "int":e=parseInt(e);break;case "double":e=parseFloat(e);break;case "ColorRGB":case "Vector3D":e=e.split(","),
e=new THREE.Vector3(e[0],e[1],e[2])}this.getPrevNode().properties[a]={type:b,type2:c,flag:d,value:e};this.setCurrentProp(this.getPrevNode().properties,a)},nodeEnd:function(a){this.popStack()},isFlattenNode:function(a){return"subNodes"in a&&"properties"in a?!0:!1}};d.prototype.parseCluster=function(a,b,c){a=a.searchConnectionParent(b);var e=toInt(c.subNodes.Indexes.properties.a.split(",")),d=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:e,weights:d,transform:f,transformlink:g,linkMode:c.properties.Mode}};d.prototype.parse=function(a,b){this.skinIndices=[];this.skinWeights=[];this.matrices=[];var c=a.Objects.subNodes.Deformer,e={};for(g in c)if("Cluster"===c[g].attrType&&"Indexes"in c[g].subNodes){var d=this.parseCluster(a,g,c[g]),f=a.searchConnectionChildren(d.id)[0];e[f]=d}c=[];var g=b.hierarchy;for(d=0;d<g.length;++d)if(f=
g[d].internalId,void 0===e[f])this.matrices.push(new THREE.Matrix4);else{f=e[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 l=a.searchConnectionChildren(f.id);1<l.length&&console.warn("FBXLoader: node "+f.id+" have many weight kids: "+l);c[f.indices[h]].joint.push(b.getBoneIdfromInternalId(a,l[0]));c[f.indices[h]].weight.push(f.weights[h])}}for(e=0;e<c.length;e++)g=new THREE.Vector4(c[e].joint[0]?
c[e].joint[0]:0,c[e].joint[1]?c[e].joint[1]:0,c[e].joint[2]?c[e].joint[2]:0,c[e].joint[3]?c[e].joint[3]:0),d=new THREE.Vector4(c[e].weight[0]?c[e].weight[0]:0,c[e].weight[1]?c[e].weight[1]:0,c[e].weight[2]?c[e].weight[2]:0,c[e].weight[3]?c[e].weight[3]:0),this.skinIndices.push(g),this.skinWeights.push(d);return this};g.prototype.parseHierarchy=function(a){var b=a.Objects.subNodes.Model,c=[];for(e in b)void 0!==b[e].attrType&&c.push(b[e]);this.hierarchy=[];for(b=0;b<c.length;++b){var e=c[b];var d=
a.searchConnectionParent(e.id)[0],f=[0,0,0],g=[0,0,0,1],l=[1,1,1];"Lcl_Translation"in e.properties&&(f=toFloat(e.properties.Lcl_Translation.value.split(",")));if("Lcl_Rotation"in e.properties){g=toRad(toFloat(e.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 e.properties&&(l=toFloat(e.properties.Lcl_Scaling.value.split(",")));k=e.attrName;k=k.replace(/:/,"");k=k.replace(/_/,"");k=k.replace(/-/,
"");this.hierarchy.push({parent:d,name:k,pos:f,rotq:g,scl:l,internalId:e.id})}this.reindexParentId();this.restoreBindPose(a);return this};g.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}};g.prototype.restoreBindPose=function(a){var b=a.Objects.subNodes.Pose;if(void 0!==b){var c=b.subNodes.PoseNode;b={};for(var e={},d=0;d<c.length;++d){var f=
toMat44(c[d].subNodes.Matrix.properties.a.split(",")),g=toMat44(c[d].subNodes.Matrix.properties.a.split(","));b[c[d].id]=f;e[c[d].id]=g}for(c=0;c<this.hierarchy.length;++c)if(d=this.hierarchy[c],f=d.internalId,void 0!==e[f]){g=new THREE.Vector3(0,0,0);for(var l=new THREE.Quaternion,k=new THREE.Vector3(1,1,1),m,n=a.searchConnectionParent(f),p=0;p<n.length;++p)if(this.isBoneNode(n[p])){m=n[p];break}void 0!==m&&void 0!==b[m]&&(n=new THREE.Matrix4,n.getInverse(e[m]),n.multiply(b[f]),b[f]=n);b[f].decompose(g,
l,k);d.pos=[g.x,g.y,g.z];d.rotq=[l.x,l.y,l.z,l.w];d.scl=[k.x,k.y,k.z]}}};g.prototype.searchRealId=function(a){for(var b=0;b<this.hierarchy.length;b++)if(a==this.hierarchy[b].internalId)return b;return-1};g.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};g.prototype.isBoneNode=function(a){for(var b=0;b<this.hierarchy.length;++b)if(a===this.hierarchy[b].internalId)return!0;return!1};g.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 f).parse(this.node,this),this.normals=(new b).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=[],f=0;f<a.length;++f){var g=parseInt(a[f]);0>g?(b>c&&(c=b),a[f]=g^-1,d.push(b),b=1):(a[f]=g,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=[],e=0,d=0,f;e<a.length;){f=b[d];for(var g=0;g<=f-3;g++)c.push(a[e]),c.push(a[e+(f-2-g)]),c.push(a[e+(f-1-g)]);d++;e+=f}return c};a.prototype.addBones=function(a){this.bones=a};f.prototype.getUV=function(a){return this.node&&this.uv&&this.map&&this.ref?this.uv:this._parseText(a)};f.prototype.getMap=function(a){this.node&&this.uv&&this.map&&this.ref||this._parseText(a);return this.map};f.prototype.getRef=function(a){this.node&&this.uv&&this.map&&
this.ref||this._parseText(a);return this.ref};f.prototype.getIndex=function(a){this.node&&this.uv&&this.map&&this.ref||this._parseText(a);return this.index};f.prototype.getNode=function(a){return null!==this.node?this.node:this.node=a.subNodes.LayerElementUV};f.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 e=a.properties.ReferenceInformationType;this.uv=toFloat(a.subNodes.UV.properties.a.split(","));this.index=toInt(c.split(","));this.map=b;this.ref=e;return this.uv};f.prototype.parse=function(a,b){this.uvNode=this.getNode(a);this.uv=this.getUV(a);var c=this.getMap(a),e=this.getRef(a),d=this.getIndex(a),f=b.getPolygonTopologyArray();switch(c){case "ByPolygonVertex":switch(e){case "Direct":this.uv=this.parseUV_ByPolygonVertex_Direct(this.uv,d,f,2);break;case "IndexToDirect":this.uv=this.parseUV_ByPolygonVertex_IndexToDirect(this.uv,
d)}var g=this.uv,h=b.getPolygonVertexIndices(a);c={};e=[];for(f=d=0;f<h.length;++f)if(!(h[f]in c)){c[h[f]]={};for(var l=0;2>l;++l)c[h[f]][l]=g[2*f+l];d=d<h[f]?h[f]:d}try{for(f=0;f<=d;f++)for(g=0;2>g;g++)e.push(c[f][g])}catch(x){}this.uv=e;break;case "ByPolygon":switch(e){case "Direct":this.uv=this.parseUV_ByPolygon_Direct();break;case "IndexToDirect":this.uv=this.parseUV_ByPolygon_IndexToDirect()}}return this.uv};f.prototype.parseUV_ByPolygonVertex_Direct=function(a,b,c,d){return parse_Data_ByPolygonVertex_Direct(a,
b,c,d)};f.prototype.parseUV_ByPolygonVertex_IndexToDirect=function(a,b){for(var c=[],e=0;e<b.length;++e)for(var d=0;2>d;++d)c.push(a[2*b[e]+d]);return c};f.prototype.parseUV_ByPolygon_Direct=function(a){console.warn("not implemented");return a};f.prototype.parseUV_ByPolygon_IndexToDirect=function(a){console.warn("not implemented");return a};f.prototype.parseUV_ByVertex_Direct=function(a){console.warn("not implemented");return a};b.prototype.getNormal=function(a){this.node&&this.normal&&this.map&&
this.ref||this._parseText(a);return this.normal};b.prototype.getMap=function(a){this.node&&this.normal&&this.map&&this.ref||this._parseText(a);return this.map};b.prototype.getRef=function(a){this.node&&this.normal&&this.map&&this.ref||this._parseText(a);return this.ref};b.prototype.getNode=function(a){return this.node?this.node:this.node=a.subNodes.LayerElementNormal};b.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}};b.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};b.prototype.parseNormal_ByPolygonVertex_Direct=function(a,b,c,d){return parse_Data_ByPolygonVertex_Direct(a,b,c,d)};b.prototype.parseNormal_ByPolygonVertex_IndexToDirect=function(a){console.warn("not implemented");return a};b.prototype.parseNormal_ByPolygon_Direct=function(a){console.warn("not implemented");return a};b.prototype.parseNormal_ByPolygon_IndexToDirect=
function(a){console.warn("not implemented");return a};b.prototype.parseNormal_ByVertex_Direct=function(a){console.warn("not implemented");return a};m.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};m.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)};l.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 m).fromNode(d[f]);g.push(h);e=h.getLength()?h.getLength():e;var l=a.searchConnectionParent(h.id)[0],k=a.searchConnectionType(h.id,l);k.match(/X/)&&(k="x");k.match(/Y/)&&(k="y");k.match(/Z/)&&(k="z");c[l].curves[k]=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};
r.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])};r.prototype.parse=function(a,b){var c=a.Objects.subNodes.Texture,d;for(d in c){var e=(new p).parse(c[d],a);this.add(e)}return this};r.prototype.getById=function(a){return this.perGeoMap[a]};p.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};p.prototype.parseFileName=function(a){if(void 0===a)return"";var b=a.split(/[\\\/]/);return 0<b.length?b[b.length-1]:a};p.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(k){THREE.Material.call(this);this.type="SpriteCanvasMaterial";this.color=new THREE.Color(16777215);this.program=function(c,d){};this.setValues(k)};THREE.SpriteCanvasMaterial.prototype=Object.create(THREE.Material.prototype);THREE.SpriteCanvasMaterial.prototype.constructor=THREE.SpriteCanvasMaterial;
THREE.SpriteCanvasMaterial.prototype.clone=function(){var k=new THREE.SpriteCanvasMaterial;k.copy(this);k.color.copy(this.color);k.program=this.program;return k};
THREE.CanvasRenderer=function(k){function c(a,b,c,d){n(b);l(c);r(d);p(a.getStyle());E.stroke();pa.expandByScalar(2*b)}function d(a){e(a.getStyle());E.fill()}function g(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,f,h,l,k,m,n,p,q,r){var t=ka[r.id];if(void 0===t||t.version!==r.version)t=g(r),ka[r.id]=t;if(void 0!==t.canvas){e(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;l=(l+t)*
v;k=(k+u)*r;c-=a;d-=b;f-=a;h-=b;m=(m+t)*v-l;n=(n+u)*r-k;p=(p+t)*v-l;q=(q+u)*r-k;r=m*q-p*n;0!==r&&(t=1/r,r=(q*c-n*f)*t,n=(q*d-n*h)*t,c=(m*f-p*c)*t,d=(m*h-p*d)*t,a=a-r*l-c*k,b=b-n*l-d*k,E.save(),E.transform(r,n,c,d,a,b),E.fill(),E.restore())}else e("rgba( 0, 0, 0, 1)"),E.fill()}function f(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 b(a){N!==a&&(N=E.globalAlpha=a)}function m(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 l(a){V!==a&&(V=E.lineCap=a)}function r(a){U!==a&&(U=E.lineJoin=a)}function p(a){W!==a&&(W=E.strokeStyle=a)}function e(a){y!==a&&(y=E.fillStyle=a)}function h(a){R.length!==a.length&&(E.setLineDash(a),R=a)}console.log("THREE.CanvasRenderer",THREE.REVISION);k=k||{};var q=this,u,t,w,v=new THREE.Projector,
z=void 0!==k.canvas?k.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===k.alpha}),I=new THREE.Color(0),A=!0===k.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&&(m(THREE.NormalBlending),b(1),e("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(k,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);u=v.projectScene(k,y,this.sortObjects,this.sortElements);t=u.elements;w=u.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=
t.length;z<A;z++){var J=t[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;b(I.opacity);m(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=g(U),ka[U.id]=J;if(void 0!==J.canvas){e(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 e(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&&(p(I.color.getStyle()),e(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,b(L.opacity),m(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);l(L.linecap);
r(L.linejoin);if(L.vertexColors!==THREE.VertexColors)p(L.color.getStyle());else if(J=R.vertexColors[0].getStyle(),R=R.vertexColors[1].getStyle(),J===R)p(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}p(Ua)}E.stroke();pa.expandByScalar(2*L.linewidth)}else L instanceof THREE.LineDashedMaterial&&(n(L.linewidth),l(L.linecap),r(L.linejoin),p(L.color.getStyle()),h([L.dashSize,
L.gapSize]),E.stroke(),pa.expandByScalar(2*L.linewidth),h([]))}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&&(f(G.positionScreen,O.positionScreen,N.overdraw),f(O.positionScreen,
T.positionScreen,N.overdraw),f(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++;b(H.opacity);m(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?c(Y,H.wireframeLinewidth,H.wireframeLinecap,H.wireframeLinejoin):d(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?c(Y,H.wireframeLinewidth,H.wireframeLinecap,H.wireframeLinejoin):d(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?c(Y,H.wireframeLinewidth,H.wireframeLinecap,H.wireframeLinejoin):d(Y))}}aa.union(pa)}}E.setTransform(1,0,0,1,0,0)}}};
THREE.SoftwareRenderer=function(k){function c(){for(var a=h*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;r.fillStyle=F.getStyle();r.fillRect(0,0,h,q)}function d(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 g(a,b,c,d,f,g,h,l,k){h=4*c;l=e[k.map.id];if(l.data){var m=l.width,n=m-1;l=l.data;f=4*((g*m&n)*m+(f*m&n));if(k.transparent){g=l[f+1];m=l[f+2];n=l[f+3]*k.opacity/255;var p=a[h+1],q=a[h+2];a[h]=l[f]*n+a[h]*(1-n);a[h+1]=g*n+p*(1-n);a[h+2]=m*n+q*(1-n);a[h+3]=(k.opacity<<8)-1;255==a[h+3]&&(b[c]=d)}else a[h]=l[f],a[h+1]=l[f+1],a[h+2]=l[f+2],a[h+3]=(k.opacity<<
8)-1,b[c]=d}}function a(a,b,c,d,f,g,h,l,k){l=4*c;var m=e[k.map.id];if(m.data){var n=m.width;h=3*(0<h?~~h:0);var p=n-1;m=m.data;f=4*((g*n&p)*n+(f*n&p));if(k.transparent){g=k.palette[h+1]*m[f+1];n=k.palette[h+2]*m[f+2];p=m[f+3]*k.opacity/256;var q=a[l+1],r=a[l+2];a[l]=k.palette[h]*m[f]*p+a[l]*(1-p);a[l+1]=g*p+q*(1-p);a[l+2]=n*p+r*(1-p);a[l+3]=(k.opacity<<8)-1;255==a[l+3]&&(b[c]=d)}else a[l]=k.palette[h]*m[f]>>8,a[l+1]=k.palette[h+1]*m[f+1]>>8,a[l+2]=k.palette[h+2]*m[f+2]>>8,a[l+3]=(k.opacity<<8)-1,
b[c]=d}}function f(a){a=a.target;a.removeEventListener("update",f);delete p[a.id]}function b(b){var c=b.id,h=p[c];h&&b.map&&!e[b.map.id]&&delete p[c];if(void 0===p[c]){b.addEventListener("update",f);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=d(b,!1)):b instanceof THREE.MeshPhongMaterial&&!b.palette&&(b.palette=d(b,!0)),b.map){h=
new THREE.SoftwareRenderer.Texture;h.fromImage(b.map.image);if(!h.data)return;e[b.map.id]=h;h=b instanceof THREE.MeshBasicMaterial||b instanceof THREE.SpriteMaterial?g: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;",
h=new Function("buffer, depthBuf, offset, depth, u, v, n, face, material",b);else h=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;");p[c]=h}return h}function m(a,b,c,d,e,f,g,l,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,t=c.x*w+C|0,G=a.y*v+x|0,F=b.y*v+x|0,M=c.y*v+x|0,O=l.vertexNormalsModel&&l.vertexNormalsModel.length,Y=d&&
e&&f,K=Math.max(Math.sqrt((p-r)*(p-r)+(G-F)*(G-F)),Math.sqrt((r-t)*(r-t)+(F-M)*(F-M)),Math.sqrt((t-p)*(t-p)+(M-G)*(M-G)));if(!(l instanceof THREE.RenderableSprite)&&1600<K){var L={vertexNormalsModel:[],color:l.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(l.vertexNormalsModel[0]).add(l.vertexNormalsModel[1]).normalize();W.copy(l.vertexNormalsModel[1]).add(l.vertexNormalsModel[2]).normalize();ia.copy(l.vertexNormalsModel[2]).add(l.vertexNormalsModel[0]).normalize()}O&&(L.vertexNormalsModel[0]=l.vertexNormalsModel[0],L.vertexNormalsModel[1]=ba,L.vertexNormalsModel[2]=ia);m(a,Q,S,d,N,X,g,L,k);O&&(L.vertexNormalsModel[0]=
l.vertexNormalsModel[1],L.vertexNormalsModel[1]=W,L.vertexNormalsModel[2]=ba);m(b,R,Q,e,T,N,g,L,k);O&&(L.vertexNormalsModel[0]=ba,L.vertexNormalsModel[1]=W,L.vertexNormalsModel[2]=ia);m(Q,R,S,N,T,X,g,L,k);O&&(L.vertexNormalsModel[0]=l.vertexNormalsModel[2],L.vertexNormalsModel[1]=ia,L.vertexNormalsModel[2]=W);m(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=l.vertexNormalsModel[0];
var rc=l.vertexNormalsModel[1];var sc=l.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-t,Ha=M-F,Aa=t-p,ya=G-M,$a=Math.max(Math.min(p,r,t)+15>>4,0),Sb=Math.min(Math.max(p,r,t)+15>>4,h),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-t)+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=h-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*u;if(!(H[sb]<Za+Wb)){var mc=E[sb];mc&2&&n(kc,lc);E[sb]=mc&-4;var Ra=Qa+Ob*h;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,l,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,l,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*h,d=4*c,e=h-A,f=4*e,g=0;g<A;g++){for(var l=0;l<A;l++)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);k=k||{};var l=void 0!==k.canvas?k.canvas:document.createElement("canvas"),r=l.getContext("2d",{alpha:!0===k.alpha}),p={},e={},h,q,u,t,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=
l;this.autoClear=!0;this.supportsVertexTextures=function(){};this.setFaceCulling=function(){};this.setClearColor=function(a,b){F.set(a);c()};this.setPixelRatio=function(){};this.setSize=function(a,b){u=Math.floor(a/A);t=Math.floor(b/A);h=u*A;q=t*A;w=16*h/2;v=-16*q/2;z=8388608;C=16*h/2+.5;x=16*q/2+.5;D=8388608.5;l.width=h;l.height=q;r.fillStyle=F.getStyle();r.fillRect(0,0,h,q);K=r.getImageData(0,0,h,q);B=K.data;P=new Int32Array(B.length/4);Q=u*t;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;c()};this.setSize(l.width,l.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,d){!0===this.autoClear&&this.clear();for(var e=M.projectScene(a,d,!1,!1).elements,f=0,g=e.length;f<g;f++){var k=e[f],p=k.material,da=b(p);if(da)if(k instanceof THREE.RenderableFace)k.uvs?m(k.v1.positionScreen,k.v2.positionScreen,k.v3.positionScreen,k.uvs[0],k.uvs[1],k.uvs[2],da,k,p):m(k.v1.positionScreen,
k.v2.positionScreen,k.v3.positionScreen,null,null,null,da,k,p);else if(k instanceof THREE.RenderableSprite){var fa=.5*k.scale.x,ca=.5*k.scale.y;S.copy(k);S.x-=fa;S.y+=ca;Z.copy(k);Z.x-=fa;Z.y-=ca;X.copy(k);X.x+=fa;X.y+=ca;p.map?(ja.set(0,1),ba.set(0,0),Y.set(1,1),m(S,Z,X,ja,ba,Y,da,k,p)):m(S,Z,X,null,null,null,da,k,p);S.copy(k);S.x+=fa;S.y+=ca;Z.copy(k);Z.x-=fa;Z.y-=ca;X.copy(k);X.x+=fa;X.y-=ca;p.map?(ja.set(1,1),ba.set(0,0),Y.set(1,0),m(S,Z,X,ja,ba,Y,da,k,p)):m(S,Z,X,null,null,null,da,k,p)}else if(k instanceof
THREE.RenderableLine){da=b(p);var ka=k.v1.positionScreen,ha=k.v2.positionScreen;fa=k.vertexColors[0];k=k.vertexColors[1];if(!N){N=!0;I=0;A=1<<I;ca=l.height;u=Math.floor(l.width/A);t=Math.floor(ca/A);h=u*A;q=t*A;w=16*h/2;v=-16*q/2;z=8388608;C=16*h/2+.5;x=16*q/2+.5;D=8388608.5;l.width=h;l.height=q;r.fillStyle=F.getStyle();r.fillRect(0,0,h,q);K=r.getImageData(0,0,h,q);B=K.data;P=new Int32Array(B.length/4);Q=u*t;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;c()}if(!(-1>ka.z||1<ka.z||-1>ha.z||1<ha.z)){ca=Math.floor(.5*(p.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,h);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*u;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*h;za<P[wa]&&da(B,P,wa,za,fa,k,p)}}}--ea}}}}for(f=e=0;f<t;f++)for(g=0;g<u;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&&r.putImageData(K,0,0,e,f,g,fa);R=y;G=J;O=V;T=U}};
THREE.SoftwareRenderer.Texture=function(){var k;this.fromImage=function(c){if(!(!c||0>=c.width||0>=c.height)){void 0===k&&(k=document.createElement("canvas"));var d=c.width>c.height?c.width:c.height;d=THREE.Math.nextPowerOfTwo(d);if(k.width!=d||k.height!=d)k.width=d,k.height=d;var g=k.getContext("2d");g.clearRect(0,0,d,d);g.drawImage(c,0,0,d,d);this.data=g.getImageData(0,0,d,d).data;this.height=this.width=d;this.srcUrl=c.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(k){this.positionWorld.copy(k.positionWorld);this.positionScreen.copy(k.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 k(){if(p===h){var a=new THREE.RenderableVertex;e.push(a);h++;p++;return a}return e[p++]}function c(){if(u===w){var a=new THREE.RenderableFace;t.push(a);w++;u++;return a}return t[u++]}function d(){if(z===x){var a=new THREE.RenderableLine;C.push(a);x++;z++;return a}return C[z++]}function g(){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 f(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 b,m,n=[],l=0,r,p,e=[],h=0,q,u,t=[],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 b(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 f(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 g=[],h=[],l=null,m=null,p=new THREE.Matrix3;return{setObject:function(a){l=a;m=l.material;p.getNormalMatrix(l.matrixWorld);g.length=0;h.length=0},projectVertex:a,checkTriangleVisibility:b,checkBackfaceCulling:f,pushVertex:function(b,c,d){r=k();r.position.set(b,c,d);a(r)},pushNormal:function(a,b,c){g.push(a,b,c)},pushUv:function(a,b){h.push(a,b)},pushLine:function(a,b){var c=e[a],f=e[b];v=d();v.id=l.id;v.v1.copy(c);
v.v2.copy(f);v.z=(c.positionScreen.z+f.positionScreen.z)/2;v.renderOrder=l.renderOrder;v.material=l.material;P.elements.push(v)},pushTriangle:function(a,d,k){var n=e[a],r=e[d],t=e[k];if(!1!==b(n,r,t)&&(m.side===THREE.DoubleSide||!0===f(n,r,t))){q=c();q.id=l.id;q.v1.copy(n);q.v2.copy(r);q.v3.copy(t);q.z=(n.positionScreen.z+r.positionScreen.z+t.positionScreen.z)/3;q.renderOrder=l.renderOrder;q.normalModel.fromArray(g,3*a);q.normalModel.applyMatrix3(p).normalize();for(n=0;3>n;n++)r=q.vertexNormalsModel[n],
r.fromArray(g,3*arguments[n]),r.applyMatrix3(p).normalize(),q.uvs[n].fromArray(h,2*arguments[n]);q.vertexNormalsLength=3;q.material=l.material;P.elements.push(q)}}}};this.projectScene=function(h,r,t,x){F=z=u=0;P.elements.length=0;!0===h.autoUpdate&&h.updateMatrixWorld();null===r.parent&&r.updateMatrixWorld();N.copy(r.matrixWorldInverse.getInverse(r.matrixWorld));L.multiplyMatrices(r.projectionMatrix,N);V.setFromMatrix(L);m=0;P.objects.length=0;P.lights.length=0;h.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(m===l){var c=new THREE.RenderableObject;n.push(c);l++;m++;b=c}else b=n[m++];b.id=a.id;b.object=a;Q.setFromMatrixPosition(a.matrixWorld);Q.applyProjection(L);b.z=Q.z;b.renderOrder=a.renderOrder;P.objects.push(b)}});!0===t&&P.objects.sort(a);h=0;for(t=P.objects.length;h<t;h++){var w=P.objects[h].object,A=w.geometry;
G.setObject(w);W=w.matrixWorld;p=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(h=0;h<w.length;h++)for(I=w[h],
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=e[S.a],T=e[S.b],oa=e[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=c();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=k(),A.positionScreen.copy(K[0]).applyMatrix4(y),C=w instanceof THREE.LineSegments?2:1,O=1,S=K.length;O<S;O++)A=k(),A.positionScreen.copy(K[O]).applyMatrix4(y),0<(O+1)%C||(T=e[p-2],U.copy(A.positionScreen),R.copy(T.positionScreen),!0===f(U,R)&&(U.multiplyScalar(1/U.w),R.multiplyScalar(1/R.w),v=d(),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=g(),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+r.projectionMatrix.elements[0])/
(H.w+r.projectionMatrix.elements[12])),D.scale.y=w.scale.y*Math.abs(D.y-(H.y+r.projectionMatrix.elements[5])/(H.w+r.projectionMatrix.elements[13])),D.material=w.material,P.elements.push(D)))}!0===x&&P.elements.sort(a);return P}};THREE.OBJLoader=function(k){this.manager=void 0!==k?k:THREE.DefaultLoadingManager;this.materials=null};
THREE.OBJLoader.prototype={constructor:THREE.OBJLoader,load:function(k,c,d,g){var a=this,f=new THREE.XHRLoader(a.manager);f.setPath(this.path);f.load(k,function(b){c(a.parse(b))},d,g)},setPath:function(k){this.path=k},setMaterials:function(k){this.materials=k},parse:function(k){function c(a){P={name:a,geometry:{vertices:[],normals:[],uvs:[]},material:{name:"",smooth:!0}};l.push(P)}function d(a){a=parseInt(a);return 3*(0<=a?a-1:a+p.length/3)}function g(a){a=parseInt(a);return 3*(0<=a?a-1:a+e.length/
3)}function a(a){a=parseInt(a);return 2*(0<=a?a-1:a+h.length/2)}function f(a,b,c){P.geometry.vertices.push(p[a],p[a+1],p[a+2],p[b],p[b+1],p[b+2],p[c],p[c+1],p[c+2])}function b(a,b,c){P.geometry.normals.push(e[a],e[a+1],e[a+2],e[b],e[b+1],e[b+2],e[c],e[c+1],e[c+2])}function m(a,b,c){P.geometry.uvs.push(h[a],h[a+1],h[b],h[b+1],h[c],h[c+1])}function n(c,e,h,l,k,p,n,q,r,t,u,v){c=d(c);e=d(e);h=d(h);if(void 0===l)f(c,e,h);else{var w=d(l);f(c,e,w);f(e,h,w)}void 0!==k&&(c=a(k),e=a(p),h=a(n),void 0===l?m(c,
e,h):(w=a(q),m(c,e,w),m(e,h,w)));void 0!==r&&(c=g(r),e=g(t),h=g(u),void 0===l?b(c,e,h):(w=g(v),b(c,e,w),b(e,h,w)))}console.time("OBJLoader");var l=[],r=!1,p=[],e=[],h=[];c("");var q=/^v\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,u=/^vn\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,t=/^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=k.split("\n");for(k=0;k<F.length;k++){var K=F[k];K=K.trim();var B;if(0!==K.length&&"#"!==K.charAt(0))if(null!==(B=q.exec(K)))p.push(parseFloat(B[1]),parseFloat(B[2]),parseFloat(B[3]));else if(null!==(B=u.exec(K)))e.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]));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===r?(r=!0,P.name=
K):c(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);}r=new THREE.Group;k=0;for(q=l.length;k<q;k++){var P=l[k];u=P.geometry;t=new THREE.BufferGeometry;t.addAttribute("position",new THREE.BufferAttribute(new Float32Array(u.vertices),3));0<u.normals.length?t.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(u.normals),3)):t.computeVertexNormals();
0<u.uvs.length&&t.addAttribute("uv",new THREE.BufferAttribute(new Float32Array(u.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;u=new THREE.Mesh(t,Q);u.name=P.name;r.add(u)}console.timeEnd("OBJLoader");return r}};
function CVector2(k,c){var d,g;this._init=function(a,c){d=a;g=c};this.add=function(a,c){d+=a;g+=c};this.addV=function(a){d+=a.getX();g+=a.getY()};this.scalarDivision=function(a){d/=a;g/=a};this.subV=function(a){d-=a.getX();g-=a.getY()};this.scalarProduct=function(a){d*=a;g*=a};this.invert=function(){d*=-1;g*=-1};this.dotProduct=function(a){return d*a.getX()+g*a.getY()};this.set=function(a,c){d=a;g=c};this.setV=function(a){d=a.getX();g=a.getY()};this.length=function(){return Math.sqrt(d*d+g*g)};this.length2=
function(){return d*d+g*g};this.normalize=function(){var a=this.length();0<a&&(d/=a,g/=a)};this.distance=function(a){var c=d-a.x;a=g-a.y;return Math.sqrt(c*c+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(d,g);a.normalize()};this.rot90CCW=function(){var a=d;d=-g;g=a};this.rot90CW=function(){var a=d;d=g;g=-a};this.getRotCCW=function(a){a.set(d,g);a.rot90CCW()};this.getRotCW=
function(a){a.set(d,g);a.rot90CW()};this.ceil=function(){d=Math.ceil(d);g=Math.ceil(g)};this.round=function(){d=Math.round(d);g=Math.round(g)};this.toString=function(){return"Vector2: "+d+", "+g};this.print=function(){trace("Vector2: "+d+", "+g)};this.getX=function(){return d};this.getY=function(){return g};this.rotate=function(a){var c=d,b=g;d=c*Math.cos(a)+b*Math.sin(a);g=c*-Math.sin(a)+b*Math.cos(a)};this._init(k,c)}
function CBackground(k,c){var d,g,a,f,b,m,n;this._init=function(c,d){a=new createjs.Container;d.addChild(a);f={width:3*CANVAS_WIDTH,height:3*CANVAS_HEIGHT};for(var g=c+1,e=0,h=0,l=0;18>l;l++){var k=s_oSpriteLibrary.getSprite("level_"+g+"_bg_"+l),r=createBitmap(k);e+=k.width;0===l%6&&(e=0,0!==l&&(h+=k.height));r.x=e;r.y=h;a.addChild(r)}a.regX=2400;a.regY=1452;null!==CAUSTICS_POS[c]&&(k=s_oSpriteLibrary.getSprite("caustics"),g=k.width/5,e=k.height/2,k=new createjs.SpriteSheet({framerate:FPS/3,images:[k],
frames:{width:g,height:e,regX:g/2,regY:e/2},animations:{idle:[0,9]}}),k=createSprite(k,"idle",g/2,e/2,g,e),k.x=CAUSTICS_POS[c].x+2400,k.y=CAUSTICS_POS[c].y+1452,k.scaleX=k.scaleY=CAUSTICS_POS[c].scale,a.addChild(k));b=a.on("mousedown",this._startPan);m=a.on("pressmove",this._movePan);n=a.on("pressup",this._endPan)};this.unload=function(){a.off("mousedown",b);a.off("pressmove",m);a.off("pressup",n);c.removeChild(a)};this._startPan=function(a){d=a.stageX;g=a.stageY;s_oInterface.setCenterBallViewVisible(!0)};
this._movePan=function(a){var b=a.stageX;a=a.stageY;var c=2*(b-d),e=2*(a-g);d=b;g=a;s_oGame.setPanPoint(c,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 f};this._init(k,c)}
function CMsgBox(k,c){var d,g,a,f;this._init=function(b){f=new createjs.Container;m.addChild(f);var c=new createjs.Shape;c.graphics.beginFill("black").drawRect(0,0,CANVAS_WIDTH,CANVAS_HEIGHT);c.alpha=.5;c.on("click",function(){});f.addChild(c);c=s_oSpriteLibrary.getSprite("msg_box");var k=createBitmap(c);k.x=.5*CANVAS_WIDTH;k.y=.5*CANVAS_HEIGHT;k.regX=.5*c.width;k.regY=.5*c.height;f.addChild(k);d=new createjs.Text(b,"23px "+PRIMARY_FONT,"#000");d.x=CANVAS_WIDTH/2;d.y=260;d.textAlign="center";d.textBaseline=
"middle";d.lineWidth=790;d.outline=2;f.addChild(d);g=new createjs.Text(d.text,"23px "+PRIMARY_FONT,"#ffd800");g.x=d.x;g.y=d.y;g.textAlign="center";g.textBaseline="middle";g.lineWidth=790;f.addChild(g);a=new CGfxButton(CANVAS_WIDTH/2,650,s_oSpriteLibrary.getSprite("but_yes"),f);a.addEventListener(ON_MOUSE_UP,this._onButOk,this)};this._onButOk=function(){b.unload()};this.unload=function(){a.unload();m.removeChild(f)};var b=this;var m=c;this._init(k)};