diff --git a/Gruntfile.js b/Gruntfile.js
index 729f0cce..d361f4d3 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -68,7 +68,7 @@ module.exports = function(grunt) {
"* Author: Nicolas Kassis\n" +
"* Author: Paul Mougel\n" +
"*\n" +
- "* three.js (c) 2010-2014 three.js authors, used under the MIT license" +
+ "* three.js (c) 2010-2014 three.js authors, used under the MIT license\n" +
"*/\n"
},
surface: {
diff --git a/build/brainbrowser-2.2.0/brainbrowser.surface-viewer.min.js b/build/brainbrowser-2.2.0/brainbrowser.surface-viewer.min.js
new file mode 100644
index 00000000..10ee9aba
--- /dev/null
+++ b/build/brainbrowser-2.2.0/brainbrowser.surface-viewer.min.js
@@ -0,0 +1,45 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";var a="2.2.0";a=a.indexOf("BRAINBROWSER_VERSION")>0?"D.E.V":a,window.BrainBrowser={version:a},window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return window.setTimeout(a,1e3/60)},window.cancelAnimationFrame=window.cancelAnimationFrame||function(a){window.clearTimeout(a)}}(),function(){"use strict";function a(b,c,d,e){return c>d?e(b):void Object.keys(b).forEach(function(f){a(b[f],c+1,d,e)})}BrainBrowser.createTreeStore=function(){var b={};return{set:function(){var a,c,d,e,f=arguments[arguments.length-1],g=Array.prototype.slice.call(arguments,0,arguments.length-1),h=b;for(c=0,d=g.length-1;d>c;c++){if(a=g[c],h[a]&&"object"!=typeof h[a])throw e="Hash key '["+g.slice(0,c+1).join("][")+"]' has already been set to a non-object value.\nCannot set '["+g.join("][")+"]'",BrainBrowser.events.triggerEvent("error",{message:e}),new Error(e);h[a]||(h[a]={}),h=h[a]}a=g[c],h[a]=f},get:function(){var a,c,d,e=Array.prototype.slice.call(arguments),f=b;if(0===e.length)return b;for(c=0,d=e.length-1;d>c;c++){if(a=e[c],void 0===f[a])return null;f=f[a]}return a=e[c],void 0!==f[a]?f[a]:null},remove:function(){var a,c,d,e,f=Array.prototype.slice.call(arguments),g=b;for(c=0,d=f.length-1;d>c;c++){if(a=f[c],void 0===g[a])return null;g=g[a]}return a=f[c],e=g[a],g[a]=void 0,e},reset:function(a){a=a&&"object"==typeof a?a:{},b=a},forEach:function(c,d){c=c>0?c:1,a(b,1,c,d)}}}}(),function(){"use strict";BrainBrowser.createColorMap=function(a,b){function c(a,b,c,d,e,f,g){var h;return(b>a||a>c)&&!e?-1:(h=Math.floor(Math.max(0,Math.min((a-b)*d,g-1))),f&&(h=g-1-h),h*=4)}function d(a,b,c){var d,e,f,g=document.createElement("canvas"),h=new Array(256);for(g.width=256,g.height=c,d=0;256>d;d++)h[d]=d;for(f=r.scale,r.scale=255,a=r.mapColors(h),r.scale=f,e=g.getContext("2d"),d=0;256>d;d++)e.fillStyle="rgb("+Math.floor(a[4*d])+", "+Math.floor(a[4*d+1])+", "+Math.floor(a[4*d+2])+")",e.fillRect(d,0,1,b);return g}b=b||{};var e,f,g,h,i,j,k,l,m=void 0===b.clamp?!0:b.clamp,n=b.flip||!1,o=b.scale||1,p=b.contrast||1,q=b.brightness||0;if(a)for(f=a.trim().split(/\n/),e=new Float32Array(4*f.length),k=0,i=0,g=f.length;g>i;i++)if(l=f[i].trim().split(/\s+/).slice(0,4),h=l.length,!(3>h)){for(j=0;h>j;j++)e[k+j]=parseFloat(l[j]);4>h&&(e[k+3]=1),k+=4}var r={colors:e,clamp:m,flip:n,scale:o,contrast:p,brightness:q,mapColors:function(a,b){b=b||{};var d,e,f,g,h,i,j=void 0===b.min?0:b.min,k=void 0===b.max?255:b.max,l=b.default_colors||[0,0,0,1],m=b.destination||new Float32Array(4*a.length),n=r.colors,o=r.colors.length/4,p=void 0===b.scale?r.scale:b.scale,q=void 0===b.clamp?r.clamp:b.clamp,s=void 0===b.flip?r.flip:b.flip,t=void 0===b.brightness?r.brightness:b.brightness,u=void 0===b.contrast?r.contrast:b.contrast,v=4===l.length?0:1,w=k-j,x=o/w;for(t*=p,u*=p,e=0,h=a.length;h>e;e++)d=a[e],f=4*e,i=c(d,j,k,x,q,s,o),0>i?(g=f*v,m[f]=u*l[g]+t,m[f+1]=u*l[g+1]+t,m[f+2]=u*l[g+2]+t,m[f+3]=p*l[g+3]):(m[f]=u*n[i]+t,m[f+1]=u*n[i+1]+t,m[f+2]=u*n[i+2]+t,m[f+3]=p*n[i+3]);return m},colorFromValue:function(a,b){b=b||{};var d,e=b.hex||!1,f=void 0===b.min?0:b.min,g=void 0===b.max?255:b.max,h=void 0===b.scale?r.scale:b.scale,i=void 0===b.brightness?r.brightness:b.brightness,j=void 0===b.contrast?r.contrast:b.contrast,k=g-f,l=r.colors.length/4,m=l/k,n=c(a,f,g,m,r.clamp,r.flip,l);return d=n>=0?Array.prototype.slice.call(r.colors,n,n+4):[0,0,0,1],d[0]=Math.max(0,Math.min(j*d[0]+i,1)),d[1]=Math.max(0,Math.min(j*d[1]+i,1)),d[2]=Math.max(0,Math.min(j*d[2]+i,1)),e?(d[0]=Math.floor(255*d[0]),d[1]=Math.floor(255*d[1]),d[2]=Math.floor(255*d[2]),d[3]=Math.floor(255*d[3]),d[0]=("0"+d[0].toString(16)).slice(-2),d[1]=("0"+d[1].toString(16)).slice(-2),d[2]=("0"+d[2].toString(16)).slice(-2),d=d.slice(0,3).join("")):(d[0]=d[0]*h,d[1]=d[1]*h,d[2]=d[2]*h,d[3]=d[3]*h),d},createElement:function(a,b){var c,e,f=r.colors,g=b-a;return c=d(f,20,40,n),e=c.getContext("2d"),e.fillStyle="#FFA000",e.fillRect(.5,20,1,10),e.fillText(a.toPrecision(3),.5,40),e.fillRect(c.width/4,20,1,10),e.fillText((a+.25*g).toPrecision(3),.25*c.width,40),e.fillRect(c.width/2,20,1,10),e.fillText((a+.5*g).toPrecision(3),.5*c.width,40),e.fillRect(3*c.width/4,20,1,10),e.fillText((a+.75*g).toPrecision(3),.75*c.width,40),e.fillRect(c.width-.5,20,1,10),e.fillText(b.toPrecision(3),c.width-20,40),c}};return r}}(),function(){"use strict";var a=BrainBrowser.createTreeStore();BrainBrowser.config={set:function(b,c){b=b||"";var d=b.split(".");d.push(c),a.set.apply(a,d)},get:function(b){b=b||"";var c=b.split(".");return a.get.apply(a,c)}}}(),function(){"use strict";function a(a,b){try{a.call(b.target,b)}catch(c){console.error("Error in event handler for: ",b.name),console.error(c.stack||c.message||c)}}var b=["eventmodelcleanup"];BrainBrowser.events={unpropagatedEvent:function(a){b.push(a)},addEventModel:function(c){var d=[],e={};c.addEventListener=function(a,b){d[a]||(d[a]=[]),d[a].push(b)},c.triggerEvent=function(e,f){var g=this,h=c.directPropagationTargets(e);f=f||{},f.name=e,f.target=g,d[e]&&d[e].forEach(function(b){a(b,f)}),d["*"]&&d["*"].forEach(function(b){a(b,f)}),-1===b.indexOf(e)&&(h.forEach(function(a){a.triggerEvent.call(g,e,f)}),0===h.length&&c!==BrainBrowser.events&&BrainBrowser.events.triggerEvent.call(g,e,f))},c.propagateEventTo=function(a,b){if(!BrainBrowser.utils.isFunction(b.allPropagationTargets))throw new Error("Propagation target doesn't seem to have an event model.");if(c===BrainBrowser.events||-1!==b.allPropagationTargets(a).indexOf(c))throw new Error("Propagating event '"+a+"' would cause a cycle.");e[a]=e[a]||[],-1===c.directPropagationTargets().indexOf(b)&&b.addEventListener("eventmodelcleanup",function(){this===b&&c.stopPropagatingTo(b)}),-1===e[a].indexOf(b)&&e[a].push(b)},c.propagateEventFrom=function(a,b){b.propagateEventTo(a,c)},c.stopPropagatingTo=function(a){Object.keys(e).forEach(function(b){e[b]=e[b].filter(function(b){return b!==a})})},c.directPropagationTargets=function(a){var b=[],c=void 0===a?Object.keys(e):[a,"*"];return c.forEach(function(a){var c=e[a]||[];c.forEach(function(a){-1===b.indexOf(a)&&b.push(a)})}),b},c.allPropagationTargets=function(a){var b=c.directPropagationTargets(a),d=Array.prototype.slice.call(b);return b.forEach(function(b){b.allPropagationTargets(a).forEach(function(a){-1===d.indexOf(a)&&d.push(a)})}),d}}},BrainBrowser.events.addEventModel(BrainBrowser.events)}(),function(){"use strict";var a=BrainBrowser.loader={loadFromURL:function(b,c,d){d=d||{};var e,f=new XMLHttpRequest,g=d.result_type,h=b.split("/"),i=h[h.length-1];f.open("GET",b),"arraybuffer"===g&&(f.responseType="arraybuffer"),f.onreadystatechange=function(){if(4===f.readyState){if(e=f.status,!(e>=200&&300>e||304===e)){var g="error loading URL: "+b+"\nHTTP Response: "+f.status+"\nHTTP Status: "+f.statusText+"\nResponse was: \n"+f.response;throw BrainBrowser.events.triggerEvent("error",{message:g}),new Error(g)}a.checkCancel(d)||c(f.response,i,d)}},f.send()},loadFromFile:function(a,b,c){var d=a.files;if(0!==d.length){c=c||{};var e=c.result_type,f=new FileReader,g=a.value.split("\\"),h=g[g.length-1];f.file=d[0],f.onloadend=function(a){b(a.target.result,h,c)},f.onerror=function(){var a="error reading file: "+h;throw BrainBrowser.events.triggerEvent("error",{message:a}),new Error(a)},"arraybuffer"===e?f.readAsArrayBuffer(d[0]):f.readAsText(d[0])}},loadColorMapFromURL:function(b,c,d){a.loadFromURL(b,function(a,b,d){c(BrainBrowser.createColorMap(a,d),b,d)},d)},loadColorMapFromFile:function(b,c,d){a.loadFromFile(b,function(a,b,d){c(BrainBrowser.createColorMap(a,d),b,d)},d)},checkCancel:function(a){a=a||{},BrainBrowser.utils.isFunction(a)&&(a={test:a});var b=a.test,c=a.cleanup,d=!1;return b&&b()&&(d=!0,c&&c()),d}}}(),function(){"use strict";BrainBrowser.utils={canvasEnabled:function(){return!!document.createElement("canvas")},webglEnabled:function(){var a=document.createElement("canvas");try{return!(!a||!window.WebGLRenderingContext||!a.getContext("webgl")&&!a.getContext("experimental-webgl"))}catch(b){return!1}},webWorkersEnabled:function(){return!!window.Worker},webGLErrorMessage:function(){var a,b='BrainBrowser requires WebGL.
';return b+=window.WebGLRenderingContext?"Your browser seems to support it, but it is
disabled or unavailable.
":"Your browser does not seem to support it.
",b+='Test your browser\'s WebGL support here.',a=document.createElement("div"),a.id="webgl-error",a.innerHTML=b,a},isFunction:function(a){return a instanceof Function||"function"==typeof a},isNumeric:function(a){return!isNaN(parseFloat(a))},createDataURL:function(a,b){if(!window.URL||!window.URL.createObjectURL)throw new Error("createDataURL requires URL.createObjectURL which does not seem to be available is this browser.");return window.URL.createObjectURL(new Blob([a],{type:b||"text/plain"}))},min:function(){var a=Array.prototype.slice.call(arguments);a=1===a.length&&BrainBrowser.utils.isNumeric(a[0].length)?a[0]:a;var b,c,d=a[0];for(b=1,c=a.length;c>b;b++)a[b]b;b++)a[b]>d&&(d=a[b]);return d},getOffset:function(a){for(var b=0,c=0;a.offsetParent;)b+=a.offsetTop,c+=a.offsetLeft,a=a.offsetParent;return{top:b,left:c}},captureMouse:function(a){var b={x:0,y:0,left:!1,middle:!1,right:!1};return document.addEventListener("mousemove",function(c){var d,e,f=BrainBrowser.utils.getOffset(a);void 0!==c.pageX?(d=c.pageX,e=c.pageY):(d=c.clientX+window.pageXOffset,e=c.clientY+window.pageYOffset),b.x=d-f.left,b.y=e-f.top},!1),a.addEventListener("mousedown",function(a){a.preventDefault(),0===a.button&&(b.left=!0),1===a.button&&(b.middle=!0),2===a.button&&(b.right=!0)},!1),a.addEventListener("mouseup",function(a){a.preventDefault(),0===a.button&&(b.left=!1),1===a.button&&(b.middle=!1),2===a.button&&(b.right=!1)},!1),a.addEventListener("mouseleave",function(a){a.preventDefault(),b.left=b.middle=b.right=!1},!1),a.addEventListener("contextmenu",function(a){a.preventDefault()},!1),b},captureTouch:function(a){function b(b){var d,e,f,g,h,i=BrainBrowser.utils.getOffset(a);for(c.length=g=b.touches.length,f=0;g>f;f++)h=b.touches[f],void 0!==h.pageX?(d=h.pageX,e=h.pageY):(d=h.clientX+window.pageXOffset,e=h.clientY+window.pageYOffset),c[f]=c[f]||{},c[f].x=d-i.left,c[f].y=e-i.top}var c=[];return a.addEventListener("touchstart",b,!1),a.addEventListener("touchmove",b,!1),a.addEventListener("touchend",b,!1),c}}}(),function(){"use strict";function a(a){var c,d=BrainBrowser.config.get("worker_dir");if(null===d)throw c="error in SurfaceViewer configuration.\nBrainBrowser configuration parameter 'worker_dir' not defined.\nUse 'BrainBrowser.config.set(\"worker_dir\", ...)' to set it.",BrainBrowser.events.triggerEvent("error",{message:c}),new Error(c);var e,f={deindex:"deindex.worker.js",wireframe:"wireframe.worker.js"},g=0,h=BrainBrowser.config.get("model_types"),i=BrainBrowser.config.get("intensity_data_types");return null!==h&&Object.keys(h).forEach(function(a){f[a+"_model"]=h[a].worker}),null!==i&&Object.keys(i).forEach(function(a){f[a+"_intensity"]=i[a].worker}),e=Object.keys(f),0===e.length?void a():void(window.URL&&window.URL.createObjectURL?e.forEach(function(c){var h,i=d+"/"+f[c],j=new XMLHttpRequest;j.open("GET",i),j.onreadystatechange=function(){4===j.readyState&&(h=j.status,b.worker_urls[c]=h>=200&&300>h||304===h?BrainBrowser.utils.createDataURL(j.response,"application/javascript"):i,++g===e.length&&a())},j.send()}):(e.forEach(function(a){b.worker_urls[a]=d+"/"+f[a]}),a()))}var b=BrainBrowser.SurfaceViewer={start:function(c,d){if(console.log("BrainBrowser Surface Viewer v"+BrainBrowser.version),!BrainBrowser.utils.webWorkersEnabled())return void alert("Can't find web workers. Exiting.");if(!BrainBrowser.utils.webglEnabled())return void alert("Can't get WebGL context. Exiting.");var e,f={};e="string"==typeof c?document.getElementById(c):c;var g={dom_element:e,model:null,model_data:null,mouse:BrainBrowser.utils.captureMouse(e),touches:BrainBrowser.utils.captureTouch(e),updated:!0,zoom:1,autorotate:{x:!1,y:!1,z:!1},getAttribute:function(a){return f[a]},setAttribute:function(a,b){f[a]=b},getVertex:function(a,c){c=c||{};var d=g.model_data.get(c.model_name).vertices,e=3*a;return new b.THREE.Vector3(d[e],d[e+1],d[e+2])}};return Object.keys(b.modules).forEach(function(a){b.modules[a](g)}),BrainBrowser.events.addEventModel(g),BrainBrowser.events.addEventListener("*",function(a){"draw"!==a&&(g.updated=!0)}),a(function(){d(g)}),g}};b.modules={},b.worker_urls={},BrainBrowser.config.set("model_types.json.worker","json.worker.js"),BrainBrowser.config.set("model_types.mniobj.worker","mniobj.worker.js"),BrainBrowser.config.set("model_types.wavefrontobj.worker","wavefrontobj.worker.js"),BrainBrowser.config.set("model_types.freesurferbin.worker","freesurferbin.worker.js"),BrainBrowser.config.set("model_types.freesurferbin.binary",!0),BrainBrowser.config.set("model_types.freesurferasc.worker","freesurferasc.worker.js"),BrainBrowser.config.set("intensity_data_types.mniobj.worker","mniobj.intensity.worker.js"),BrainBrowser.config.set("intensity_data_types.freesurferbin.worker","freesurferbin.intensity.worker.js"),BrainBrowser.config.set("intensity_data_types.freesurferbin.binary",!0),BrainBrowser.config.set("intensity_data_types.freesurferasc.worker","freesurferasc.intensity.worker.js")}(),BrainBrowser.SurfaceViewer.parseIntensityData=function(a,b,c){"use strict";var d,e=b+"_intensity";if(!BrainBrowser.SurfaceViewer.worker_urls[e])throw d="error in SurfaceViewer configuration.\nIntensity data worker URL for "+b+" not defined.\nUse 'BrainBrowser.config.set(\"intensity_data_types."+b+".worker\", ...)' to set it.",BrainBrowser.events.triggerEvent("error",{message:d}),new Error(d);var f=new Worker(BrainBrowser.SurfaceViewer.worker_urls[e]);f.addEventListener("message",function(a){c(a.data),f.terminate()}),f.postMessage({cmd:"parse",data:a})},function(){"use strict";var a=BrainBrowser.SurfaceViewer.THREE={REVISION:"66"};self.console=self.console||{info:function(){},log:function(){},debug:function(){},warn:function(){},error:function(){}},function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c>16&255)/255,this.g=(a>>8&255)/255,this.b=(255&a)/255,this},setRGB:function(a,b,c){return this.r=a,this.g=b,this.b=c,this},setHSL:function(a,b,c){if(0===b)this.r=this.g=this.b=c;else{var d=function(a,b,c){return 0>c&&(c+=1),c>1&&(c-=1),1/6>c?a+6*(b-a)*c:.5>c?b:2/3>c?a+6*(b-a)*(2/3-c):a},e=.5>=c?c*(1+b):c+b-c*b,f=2*c-e;this.r=d(f,e,a+1/3),this.g=d(f,e,a),this.b=d(f,e,a-1/3)}return this},setStyle:function(b){if(/^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.test(b)){var c=/^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.exec(b);return this.r=Math.min(255,parseInt(c[1],10))/255,this.g=Math.min(255,parseInt(c[2],10))/255,this.b=Math.min(255,parseInt(c[3],10))/255,this}if(/^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.test(b)){var c=/^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.exec(b);return this.r=Math.min(100,parseInt(c[1],10))/100,this.g=Math.min(100,parseInt(c[2],10))/100,this.b=Math.min(100,parseInt(c[3],10))/100,this}if(/^\#([0-9a-f]{6})$/i.test(b)){var c=/^\#([0-9a-f]{6})$/i.exec(b);return this.setHex(parseInt(c[1],16)),this}if(/^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.test(b)){var c=/^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(b);return this.setHex(parseInt(c[1]+c[1]+c[2]+c[2]+c[3]+c[3],16)),this}return/^(\w+)$/i.test(b)?(this.setHex(a.ColorKeywords[b]),this):void 0},copy:function(a){return this.r=a.r,this.g=a.g,this.b=a.b,this},copyGammaToLinear:function(a){return this.r=a.r*a.r,this.g=a.g*a.g,this.b=a.b*a.b,this},copyLinearToGamma:function(a){return this.r=Math.sqrt(a.r),this.g=Math.sqrt(a.g),this.b=Math.sqrt(a.b),this},convertGammaToLinear:function(){var a=this.r,b=this.g,c=this.b;return this.r=a*a,this.g=b*b,this.b=c*c,this},convertLinearToGamma:function(){return this.r=Math.sqrt(this.r),this.g=Math.sqrt(this.g),this.b=Math.sqrt(this.b),this},getHex:function(){return 255*this.r<<16^255*this.g<<8^255*this.b<<0},getHexString:function(){return("000000"+this.getHex().toString(16)).slice(-6)},getHSL:function(a){var b,c,d=a||{h:0,s:0,l:0},e=this.r,f=this.g,g=this.b,h=Math.max(e,f,g),i=Math.min(e,f,g),j=(i+h)/2;if(i===h)b=0,c=0;else{var k=h-i;switch(c=.5>=j?k/(h+i):k/(2-h-i),h){case e:b=(f-g)/k+(g>f?6:0);break;case f:b=(g-e)/k+2;break;case g:b=(e-f)/k+4}b/=6}return d.h=b,d.s=c,d.l=j,d},getStyle:function(){return"rgb("+(255*this.r|0)+","+(255*this.g|0)+","+(255*this.b|0)+")"},offsetHSL:function(a,b,c){var d=this.getHSL();return d.h+=a,d.s+=b,d.l+=c,this.setHSL(d.h,d.s,d.l),this},add:function(a){return this.r+=a.r,this.g+=a.g,this.b+=a.b,this},addColors:function(a,b){return this.r=a.r+b.r,this.g=a.g+b.g,this.b=a.b+b.b,this},addScalar:function(a){return this.r+=a,this.g+=a,this.b+=a,this},multiply:function(a){return this.r*=a.r,this.g*=a.g,this.b*=a.b,this},multiplyScalar:function(a){return this.r*=a,this.g*=a,this.b*=a,this},lerp:function(a,b){return this.r+=(a.r-this.r)*b,this.g+=(a.g-this.g)*b,this.b+=(a.b-this.b)*b,this},equals:function(a){return a.r===this.r&&a.g===this.g&&a.b===this.b},fromArray:function(a){return this.r=a[0],this.g=a[1],this.b=a[2],this},toArray:function(){return[this.r,this.g,this.b]},clone:function(){return(new a.Color).setRGB(this.r,this.g,this.b)}},a.ColorKeywords={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},a.Quaternion=function(a,b,c,d){this._x=a||0,this._y=b||0,this._z=c||0,this._w=void 0!==d?d:1},a.Quaternion.prototype={constructor:a.Quaternion,_x:0,_y:0,_z:0,_w:0,_euler:void 0,_updateEuler:function(){void 0!==this._euler&&this._euler.setFromQuaternion(this,void 0,!1)},get x(){return this._x},set x(a){this._x=a,this._updateEuler()},get y(){return this._y},set y(a){this._y=a,this._updateEuler()},get z(){return this._z},set z(a){this._z=a,this._updateEuler()},get w(){return this._w},set w(a){this._w=a,this._updateEuler()},set:function(a,b,c,d){return this._x=a,this._y=b,this._z=c,this._w=d,this._updateEuler(),this},copy:function(a){return this._x=a._x,this._y=a._y,this._z=a._z,this._w=a._w,this._updateEuler(),this},setFromEuler:function(b,c){if(b instanceof a.Euler==!1)throw new Error("ERROR: Quaternion's .setFromEuler() now expects a Euler rotation rather than a Vector3 and order. Please update your code.");var d=Math.cos(b._x/2),e=Math.cos(b._y/2),f=Math.cos(b._z/2),g=Math.sin(b._x/2),h=Math.sin(b._y/2),i=Math.sin(b._z/2);return"XYZ"===b.order?(this._x=g*e*f+d*h*i,this._y=d*h*f-g*e*i,this._z=d*e*i+g*h*f,this._w=d*e*f-g*h*i):"YXZ"===b.order?(this._x=g*e*f+d*h*i,this._y=d*h*f-g*e*i,this._z=d*e*i-g*h*f,this._w=d*e*f+g*h*i):"ZXY"===b.order?(this._x=g*e*f-d*h*i,this._y=d*h*f+g*e*i,this._z=d*e*i+g*h*f,this._w=d*e*f-g*h*i):"ZYX"===b.order?(this._x=g*e*f-d*h*i,this._y=d*h*f+g*e*i,this._z=d*e*i-g*h*f,this._w=d*e*f+g*h*i):"YZX"===b.order?(this._x=g*e*f+d*h*i,this._y=d*h*f+g*e*i,this._z=d*e*i-g*h*f,this._w=d*e*f-g*h*i):"XZY"===b.order&&(this._x=g*e*f-d*h*i,this._y=d*h*f-g*e*i,this._z=d*e*i+g*h*f,this._w=d*e*f+g*h*i),c!==!1&&this._updateEuler(),this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c);return this._x=a.x*d,this._y=a.y*d,this._z=a.z*d,this._w=Math.cos(c),this._updateEuler(),this},setFromRotationMatrix:function(a){var b,c=a.elements,d=c[0],e=c[4],f=c[8],g=c[1],h=c[5],i=c[9],j=c[2],k=c[6],l=c[10],m=d+h+l;return m>0?(b=.5/Math.sqrt(m+1),this._w=.25/b,this._x=(k-i)*b,this._y=(f-j)*b,this._z=(g-e)*b):d>h&&d>l?(b=2*Math.sqrt(1+d-h-l),this._w=(k-i)/b,this._x=.25*b,this._y=(e+g)/b,this._z=(f+j)/b):h>l?(b=2*Math.sqrt(1+h-d-l),this._w=(f-j)/b,this._x=(e+g)/b,this._y=.25*b,this._z=(i+k)/b):(b=2*Math.sqrt(1+l-d-h),this._w=(g-e)/b,this._x=(f+j)/b,this._y=(i+k)/b,this._z=.25*b),this._updateEuler(),this},inverse:function(){return this.conjugate().normalize(),this},conjugate:function(){return this._x*=-1,this._y*=-1,this._z*=-1,this._updateEuler(),this},lengthSq:function(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w},length:function(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)},normalize:function(){var a=this.length();return 0===a?(this._x=0,this._y=0,this._z=0,this._w=1):(a=1/a,this._x=this._x*a,this._y=this._y*a,this._z=this._z*a,this._w=this._w*a),this},multiply:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Quaternion's .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead."),this.multiplyQuaternions(a,b)):this.multiplyQuaternions(this,a)},multiplyQuaternions:function(a,b){var c=a._x,d=a._y,e=a._z,f=a._w,g=b._x,h=b._y,i=b._z,j=b._w;return this._x=c*j+f*g+d*i-e*h,this._y=d*j+f*h+e*g-c*i,this._z=e*j+f*i+c*h-d*g,this._w=f*j-c*g-d*h-e*i,this._updateEuler(),this},multiplyVector3:function(a){return console.warn("DEPRECATED: Quaternion's .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead."),a.applyQuaternion(this)},slerp:function(a,b){var c=this._x,d=this._y,e=this._z,f=this._w,g=f*a._w+c*a._x+d*a._y+e*a._z;if(0>g?(this._w=-a._w,this._x=-a._x,this._y=-a._y,this._z=-a._z,g=-g):this.copy(a),g>=1)return this._w=f,this._x=c,this._y=d,this._z=e,this;var h=Math.acos(g),i=Math.sqrt(1-g*g);if(Math.abs(i)<.001)return this._w=.5*(f+this._w),this._x=.5*(c+this._x),this._y=.5*(d+this._y),this._z=.5*(e+this._z),this;var j=Math.sin((1-b)*h)/i,k=Math.sin(b*h)/i;return this._w=f*j+this._w*k,this._x=c*j+this._x*k,this._y=d*j+this._y*k,this._z=e*j+this._z*k,this._updateEuler(),this},equals:function(a){return a._x===this._x&&a._y===this._y&&a._z===this._z&&a._w===this._w},fromArray:function(a){return this._x=a[0],this._y=a[1],this._z=a[2],this._w=a[3],this._updateEuler(),this},toArray:function(){return[this._x,this._y,this._z,this._w]},clone:function(){return new a.Quaternion(this._x,this._y,this._z,this._w)}},a.Quaternion.slerp=function(a,b,c,d){return c.copy(a).slerp(b,d)},a.Vector2=function(a,b){this.x=a||0,this.y=b||0},a.Vector2.prototype={constructor:a.Vector2,set:function(a,b){return this.x=a,this.y=b,this},setX:function(a){return this.x=a,this},setY:function(a){return this.y=a,this},setComponent:function(a,b){switch(a){case 0:this.x=b;break;case 1:this.y=b;break;default:throw new Error("index is out of range: "+a)}},getComponent:function(a){switch(a){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+a)}},copy:function(a){return this.x=a.x,this.y=a.y,this},add:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector2's .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(a,b)):(this.x+=a.x,this.y+=a.y,this)},addVectors:function(a,b){return this.x=a.x+b.x,this.y=a.y+b.y,this},addScalar:function(a){return this.x+=a,this.y+=a,this},sub:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector2's .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(a,b)):(this.x-=a.x,this.y-=a.y,this)},subVectors:function(a,b){return this.x=a.x-b.x,this.y=a.y-b.y,this},multiplyScalar:function(a){return this.x*=a,this.y*=a,this},divideScalar:function(a){if(0!==a){var b=1/a;this.x*=b,this.y*=b}else this.x=0,this.y=0;return this},min:function(a){return this.x>a.x&&(this.x=a.x),this.y>a.y&&(this.y=a.y),this},max:function(a){return this.xb.x&&(this.x=b.x),this.yb.y&&(this.y=b.y),this},clampScalar:function(){var b,c;return function(d,e){return void 0===b&&(b=new a.Vector2,c=new a.Vector2),b.set(d,d),c.set(e,e),this.clamp(b,c)}}(),floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,c=this.y-a.y;return b*b+c*c},setLength:function(a){var b=this.length();return 0!==b&&a!==b&&this.multiplyScalar(a/b),this},lerp:function(a,b){return this.x+=(a.x-this.x)*b,this.y+=(a.y-this.y)*b,this},equals:function(a){return a.x===this.x&&a.y===this.y},fromArray:function(a){return this.x=a[0],this.y=a[1],this},toArray:function(){return[this.x,this.y]},clone:function(){return new a.Vector2(this.x,this.y)}},a.Vector3=function(a,b,c){this.x=a||0,this.y=b||0,this.z=c||0},a.Vector3.prototype={constructor:a.Vector3,set:function(a,b,c){return this.x=a,this.y=b,this.z=c,this},setX:function(a){return this.x=a,this},setY:function(a){return this.y=a,this},setZ:function(a){return this.z=a,this},setComponent:function(a,b){switch(a){case 0:this.x=b;break;case 1:this.y=b;break;case 2:this.z=b;break;default:throw new Error("index is out of range: "+a)}},getComponent:function(a){switch(a){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+a)}},copy:function(a){return this.x=a.x,this.y=a.y,this.z=a.z,this},add:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector3's .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(a,b)):(this.x+=a.x,this.y+=a.y,this.z+=a.z,this)},addScalar:function(a){return this.x+=a,this.y+=a,this.z+=a,this},addVectors:function(a,b){return this.x=a.x+b.x,this.y=a.y+b.y,this.z=a.z+b.z,this},sub:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector3's .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(a,b)):(this.x-=a.x,this.y-=a.y,this.z-=a.z,this)},subVectors:function(a,b){return this.x=a.x-b.x,this.y=a.y-b.y,this.z=a.z-b.z,this},multiply:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector3's .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead."),this.multiplyVectors(a,b)):(this.x*=a.x,this.y*=a.y,this.z*=a.z,this)},multiplyScalar:function(a){return this.x*=a,this.y*=a,this.z*=a,this},multiplyVectors:function(a,b){return this.x=a.x*b.x,this.y=a.y*b.y,this.z=a.z*b.z,this},applyEuler:function(){var b;return function(c){return c instanceof a.Euler==!1&&console.error("ERROR: Vector3's .applyEuler() now expects a Euler rotation rather than a Vector3 and order. Please update your code."),void 0===b&&(b=new a.Quaternion),this.applyQuaternion(b.setFromEuler(c)),this
+}}(),applyAxisAngle:function(){var b;return function(c,d){return void 0===b&&(b=new a.Quaternion),this.applyQuaternion(b.setFromAxisAngle(c,d)),this}}(),applyMatrix3:function(a){var b=this.x,c=this.y,d=this.z,e=a.elements;return this.x=e[0]*b+e[3]*c+e[6]*d,this.y=e[1]*b+e[4]*c+e[7]*d,this.z=e[2]*b+e[5]*c+e[8]*d,this},applyMatrix4:function(a){var b=this.x,c=this.y,d=this.z,e=a.elements;return this.x=e[0]*b+e[4]*c+e[8]*d+e[12],this.y=e[1]*b+e[5]*c+e[9]*d+e[13],this.z=e[2]*b+e[6]*c+e[10]*d+e[14],this},applyProjection:function(a){var b=this.x,c=this.y,d=this.z,e=a.elements,f=1/(e[3]*b+e[7]*c+e[11]*d+e[15]);return this.x=(e[0]*b+e[4]*c+e[8]*d+e[12])*f,this.y=(e[1]*b+e[5]*c+e[9]*d+e[13])*f,this.z=(e[2]*b+e[6]*c+e[10]*d+e[14])*f,this},applyQuaternion:function(a){var b=this.x,c=this.y,d=this.z,e=a.x,f=a.y,g=a.z,h=a.w,i=h*b+f*d-g*c,j=h*c+g*b-e*d,k=h*d+e*c-f*b,l=-e*b-f*c-g*d;return this.x=i*h+l*-e+j*-g-k*-f,this.y=j*h+l*-f+k*-e-i*-g,this.z=k*h+l*-g+i*-f-j*-e,this},transformDirection:function(a){var b=this.x,c=this.y,d=this.z,e=a.elements;return this.x=e[0]*b+e[4]*c+e[8]*d,this.y=e[1]*b+e[5]*c+e[9]*d,this.z=e[2]*b+e[6]*c+e[10]*d,this.normalize(),this},divide:function(a){return this.x/=a.x,this.y/=a.y,this.z/=a.z,this},divideScalar:function(a){if(0!==a){var b=1/a;this.x*=b,this.y*=b,this.z*=b}else this.x=0,this.y=0,this.z=0;return this},min:function(a){return this.x>a.x&&(this.x=a.x),this.y>a.y&&(this.y=a.y),this.z>a.z&&(this.z=a.z),this},max:function(a){return this.xb.x&&(this.x=b.x),this.yb.y&&(this.y=b.y),this.zb.z&&(this.z=b.z),this},clampScalar:function(){var b,c;return function(d,e){return void 0===b&&(b=new a.Vector3,c=new a.Vector3),b.set(d,d,d),c.set(e,e,e),this.clamp(b,c)}}(),floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){var b=this.length();return 0!==b&&a!==b&&this.multiplyScalar(a/b),this},lerp:function(a,b){return this.x+=(a.x-this.x)*b,this.y+=(a.y-this.y)*b,this.z+=(a.z-this.z)*b,this},cross:function(a,b){if(void 0!==b)return console.warn("DEPRECATED: Vector3's .cross() now only accepts one argument. Use .crossVectors( a, b ) instead."),this.crossVectors(a,b);var c=this.x,d=this.y,e=this.z;return this.x=d*a.z-e*a.y,this.y=e*a.x-c*a.z,this.z=c*a.y-d*a.x,this},crossVectors:function(a,b){var c=a.x,d=a.y,e=a.z,f=b.x,g=b.y,h=b.z;return this.x=d*h-e*g,this.y=e*f-c*h,this.z=c*g-d*f,this},projectOnVector:function(){var b,c;return function(d){return void 0===b&&(b=new a.Vector3),b.copy(d).normalize(),c=this.dot(b),this.copy(b).multiplyScalar(c)}}(),projectOnPlane:function(){var b;return function(c){return void 0===b&&(b=new a.Vector3),b.copy(this).projectOnVector(c),this.sub(b)}}(),reflect:function(){var b;return function(c){return void 0===b&&(b=new a.Vector3),this.sub(b.copy(c).multiplyScalar(2*this.dot(c)))}}(),angleTo:function(b){var c=this.dot(b)/(this.length()*b.length());return Math.acos(a.Math.clamp(c,-1,1))},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,c=this.y-a.y,d=this.z-a.z;return b*b+c*c+d*d},setEulerFromRotationMatrix:function(){console.error("REMOVED: Vector3's setEulerFromRotationMatrix has been removed in favor of Euler.setFromRotationMatrix(), please update your code.")},setEulerFromQuaternion:function(){console.error("REMOVED: Vector3's setEulerFromQuaternion: has been removed in favor of Euler.setFromQuaternion(), please update your code.")},getPositionFromMatrix:function(a){return console.warn("DEPRECATED: Vector3's .getPositionFromMatrix() has been renamed to .setFromMatrixPosition(). Please update your code."),this.setFromMatrixPosition(a)},getScaleFromMatrix:function(a){return console.warn("DEPRECATED: Vector3's .getScaleFromMatrix() has been renamed to .setFromMatrixScale(). Please update your code."),this.setFromMatrixScale(a)},getColumnFromMatrix:function(a,b){return console.warn("DEPRECATED: Vector3's .getColumnFromMatrix() has been renamed to .setFromMatrixColumn(). Please update your code."),this.setFromMatrixColumn(a,b)},setFromMatrixPosition:function(a){return this.x=a.elements[12],this.y=a.elements[13],this.z=a.elements[14],this},setFromMatrixScale:function(a){var b=this.set(a.elements[0],a.elements[1],a.elements[2]).length(),c=this.set(a.elements[4],a.elements[5],a.elements[6]).length(),d=this.set(a.elements[8],a.elements[9],a.elements[10]).length();return this.x=b,this.y=c,this.z=d,this},setFromMatrixColumn:function(a,b){var c=4*a,d=b.elements;return this.x=d[c],this.y=d[c+1],this.z=d[c+2],this},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},fromArray:function(a){return this.x=a[0],this.y=a[1],this.z=a[2],this},toArray:function(){return[this.x,this.y,this.z]},clone:function(){return new a.Vector3(this.x,this.y,this.z)}},a.Vector4=function(a,b,c,d){this.x=a||0,this.y=b||0,this.z=c||0,this.w=void 0!==d?d:1},a.Vector4.prototype={constructor:a.Vector4,set:function(a,b,c,d){return this.x=a,this.y=b,this.z=c,this.w=d,this},setX:function(a){return this.x=a,this},setY:function(a){return this.y=a,this},setZ:function(a){return this.z=a,this},setW:function(a){return this.w=a,this},setComponent:function(a,b){switch(a){case 0:this.x=b;break;case 1:this.y=b;break;case 2:this.z=b;break;case 3:this.w=b;break;default:throw new Error("index is out of range: "+a)}},getComponent:function(a){switch(a){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+a)}},copy:function(a){return this.x=a.x,this.y=a.y,this.z=a.z,this.w=void 0!==a.w?a.w:1,this},add:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector4's .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(a,b)):(this.x+=a.x,this.y+=a.y,this.z+=a.z,this.w+=a.w,this)},addScalar:function(a){return this.x+=a,this.y+=a,this.z+=a,this.w+=a,this},addVectors:function(a,b){return this.x=a.x+b.x,this.y=a.y+b.y,this.z=a.z+b.z,this.w=a.w+b.w,this},sub:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector4's .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(a,b)):(this.x-=a.x,this.y-=a.y,this.z-=a.z,this.w-=a.w,this)},subVectors:function(a,b){return this.x=a.x-b.x,this.y=a.y-b.y,this.z=a.z-b.z,this.w=a.w-b.w,this},multiplyScalar:function(a){return this.x*=a,this.y*=a,this.z*=a,this.w*=a,this},applyMatrix4:function(a){var b=this.x,c=this.y,d=this.z,e=this.w,f=a.elements;return this.x=f[0]*b+f[4]*c+f[8]*d+f[12]*e,this.y=f[1]*b+f[5]*c+f[9]*d+f[13]*e,this.z=f[2]*b+f[6]*c+f[10]*d+f[14]*e,this.w=f[3]*b+f[7]*c+f[11]*d+f[15]*e,this},divideScalar:function(a){if(0!==a){var b=1/a;this.x*=b,this.y*=b,this.z*=b,this.w*=b}else this.x=0,this.y=0,this.z=0,this.w=1;return this},setAxisAngleFromQuaternion:function(a){this.w=2*Math.acos(a.w);var b=Math.sqrt(1-a.w*a.w);return 1e-4>b?(this.x=1,this.y=0,this.z=0):(this.x=a.x/b,this.y=a.y/b,this.z=a.z/b),this},setAxisAngleFromRotationMatrix:function(a){var b,c,d,e,f=.01,g=.1,h=a.elements,i=h[0],j=h[4],k=h[8],l=h[1],m=h[5],n=h[9],o=h[2],p=h[6],q=h[10];if(Math.abs(j-l)s&&r>t?f>r?(c=0,d=.707106781,e=.707106781):(c=Math.sqrt(r),d=u/c,e=v/c):s>t?f>s?(c=.707106781,d=0,e=.707106781):(d=Math.sqrt(s),c=u/d,e=w/d):f>t?(c=.707106781,d=.707106781,e=0):(e=Math.sqrt(t),c=v/e,d=w/e),this.set(c,d,e,b),this}var x=Math.sqrt((p-n)*(p-n)+(k-o)*(k-o)+(l-j)*(l-j));return Math.abs(x)<.001&&(x=1),this.x=(p-n)/x,this.y=(k-o)/x,this.z=(l-j)/x,this.w=Math.acos((i+m+q-1)/2),this},min:function(a){return this.x>a.x&&(this.x=a.x),this.y>a.y&&(this.y=a.y),this.z>a.z&&(this.z=a.z),this.w>a.w&&(this.w=a.w),this},max:function(a){return this.xb.x&&(this.x=b.x),this.yb.y&&(this.y=b.y),this.zb.z&&(this.z=b.z),this.wb.w&&(this.w=b.w),this},clampScalar:function(){var b,c;return function(d,e){return void 0===b&&(b=new a.Vector4,c=new a.Vector4),b.set(d,d,d,d),c.set(e,e,e,e),this.clamp(b,c)}}(),floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this.w=this.w<0?Math.ceil(this.w):Math.floor(this.w),this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){var b=this.length();return 0!==b&&a!==b&&this.multiplyScalar(a/b),this},lerp:function(a,b){return this.x+=(a.x-this.x)*b,this.y+=(a.y-this.y)*b,this.z+=(a.z-this.z)*b,this.w+=(a.w-this.w)*b,this},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z&&a.w===this.w},fromArray:function(a){return this.x=a[0],this.y=a[1],this.z=a[2],this.w=a[3],this},toArray:function(){return[this.x,this.y,this.z,this.w]},clone:function(){return new a.Vector4(this.x,this.y,this.z,this.w)}},a.Euler=function(b,c,d,e){this._x=b||0,this._y=c||0,this._z=d||0,this._order=e||a.Euler.DefaultOrder},a.Euler.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"],a.Euler.DefaultOrder="XYZ",a.Euler.prototype={constructor:a.Euler,_x:0,_y:0,_z:0,_order:a.Euler.DefaultOrder,_quaternion:void 0,_updateQuaternion:function(){void 0!==this._quaternion&&this._quaternion.setFromEuler(this,!1)},get x(){return this._x},set x(a){this._x=a,this._updateQuaternion()},get y(){return this._y},set y(a){this._y=a,this._updateQuaternion()},get z(){return this._z},set z(a){this._z=a,this._updateQuaternion()},get order(){return this._order},set order(a){this._order=a,this._updateQuaternion()},set:function(a,b,c,d){return this._x=a,this._y=b,this._z=c,this._order=d||this._order,this._updateQuaternion(),this},copy:function(a){return this._x=a._x,this._y=a._y,this._z=a._z,this._order=a._order,this._updateQuaternion(),this},setFromRotationMatrix:function(a,b){function c(a){return Math.min(Math.max(a,-1),1)}var d=a.elements,e=d[0],f=d[4],g=d[8],h=d[1],i=d[5],j=d[9],k=d[2],l=d[6],m=d[10];return b=b||this._order,"XYZ"===b?(this._y=Math.asin(c(g)),Math.abs(g)<.99999?(this._x=Math.atan2(-j,m),this._z=Math.atan2(-f,e)):(this._x=Math.atan2(l,i),this._z=0)):"YXZ"===b?(this._x=Math.asin(-c(j)),Math.abs(j)<.99999?(this._y=Math.atan2(g,m),this._z=Math.atan2(h,i)):(this._y=Math.atan2(-k,e),this._z=0)):"ZXY"===b?(this._x=Math.asin(c(l)),Math.abs(l)<.99999?(this._y=Math.atan2(-k,m),this._z=Math.atan2(-f,i)):(this._y=0,this._z=Math.atan2(h,e))):"ZYX"===b?(this._y=Math.asin(-c(k)),Math.abs(k)<.99999?(this._x=Math.atan2(l,m),this._z=Math.atan2(h,e)):(this._x=0,this._z=Math.atan2(-f,i))):"YZX"===b?(this._z=Math.asin(c(h)),Math.abs(h)<.99999?(this._x=Math.atan2(-j,i),this._y=Math.atan2(-k,e)):(this._x=0,this._y=Math.atan2(g,m))):"XZY"===b?(this._z=Math.asin(-c(f)),Math.abs(f)<.99999?(this._x=Math.atan2(l,i),this._y=Math.atan2(g,e)):(this._x=Math.atan2(-j,m),this._y=0)):console.warn("WARNING: Euler.setFromRotationMatrix() given unsupported order: "+b),this._order=b,this._updateQuaternion(),this},setFromQuaternion:function(a,b,c){function d(a){return Math.min(Math.max(a,-1),1)}var e=a.x*a.x,f=a.y*a.y,g=a.z*a.z,h=a.w*a.w;return b=b||this._order,"XYZ"===b?(this._x=Math.atan2(2*(a.x*a.w-a.y*a.z),h-e-f+g),this._y=Math.asin(d(2*(a.x*a.z+a.y*a.w))),this._z=Math.atan2(2*(a.z*a.w-a.x*a.y),h+e-f-g)):"YXZ"===b?(this._x=Math.asin(d(2*(a.x*a.w-a.y*a.z))),this._y=Math.atan2(2*(a.x*a.z+a.y*a.w),h-e-f+g),this._z=Math.atan2(2*(a.x*a.y+a.z*a.w),h-e+f-g)):"ZXY"===b?(this._x=Math.asin(d(2*(a.x*a.w+a.y*a.z))),this._y=Math.atan2(2*(a.y*a.w-a.z*a.x),h-e-f+g),this._z=Math.atan2(2*(a.z*a.w-a.x*a.y),h-e+f-g)):"ZYX"===b?(this._x=Math.atan2(2*(a.x*a.w+a.z*a.y),h-e-f+g),this._y=Math.asin(d(2*(a.y*a.w-a.x*a.z))),this._z=Math.atan2(2*(a.x*a.y+a.z*a.w),h+e-f-g)):"YZX"===b?(this._x=Math.atan2(2*(a.x*a.w-a.z*a.y),h-e+f-g),this._y=Math.atan2(2*(a.y*a.w-a.x*a.z),h+e-f-g),this._z=Math.asin(d(2*(a.x*a.y+a.z*a.w)))):"XZY"===b?(this._x=Math.atan2(2*(a.x*a.w+a.y*a.z),h-e+f-g),this._y=Math.atan2(2*(a.x*a.z+a.y*a.w),h+e-f-g),this._z=Math.asin(d(2*(a.z*a.w-a.x*a.y)))):console.warn("WARNING: Euler.setFromQuaternion() given unsupported order: "+b),this._order=b,c!==!1&&this._updateQuaternion(),this},reorder:function(){var b=new a.Quaternion;return function(a){b.setFromEuler(this),this.setFromQuaternion(b,a)}}(),fromArray:function(a){return this._x=a[0],this._y=a[1],this._z=a[2],void 0!==a[3]&&(this._order=a[3]),this._updateQuaternion(),this},toArray:function(){return[this._x,this._y,this._z,this._order]},equals:function(a){return a._x===this._x&&a._y===this._y&&a._z===this._z&&a._order===this._order},clone:function(){return new a.Euler(this._x,this._y,this._z,this._order)}},a.Line3=function(b,c){this.start=void 0!==b?b:new a.Vector3,this.end=void 0!==c?c:new a.Vector3},a.Line3.prototype={constructor:a.Line3,set:function(a,b){return this.start.copy(a),this.end.copy(b),this},copy:function(a){return this.start.copy(a.start),this.end.copy(a.end),this},center:function(b){var c=b||new a.Vector3;return c.addVectors(this.start,this.end).multiplyScalar(.5)},delta:function(b){var c=b||new a.Vector3;return c.subVectors(this.end,this.start)},distanceSq:function(){return this.start.distanceToSquared(this.end)},distance:function(){return this.start.distanceTo(this.end)},at:function(b,c){var d=c||new a.Vector3;return this.delta(d).multiplyScalar(b).add(this.start)},closestPointToPointParameter:function(){var b=new a.Vector3,c=new a.Vector3;return function(d,e){b.subVectors(d,this.start),c.subVectors(this.end,this.start);var f=c.dot(c),g=c.dot(b),h=g/f;return e&&(h=a.Math.clamp(h,0,1)),h}}(),closestPointToPoint:function(b,c,d){var e=this.closestPointToPointParameter(b,c),f=d||new a.Vector3;return this.delta(f).multiplyScalar(e).add(this.start)},applyMatrix4:function(a){return this.start.applyMatrix4(a),this.end.applyMatrix4(a),this},equals:function(a){return a.start.equals(this.start)&&a.end.equals(this.end)},clone:function(){return(new a.Line3).copy(this)}},a.Box2=function(b,c){this.min=void 0!==b?b:new a.Vector2(1/0,1/0),this.max=void 0!==c?c:new a.Vector2(-1/0,-1/0)},a.Box2.prototype={constructor:a.Box2,set:function(a,b){return this.min.copy(a),this.max.copy(b),this},setFromPoints:function(a){if(a.length>0){var b=a[0];this.min.copy(b),this.max.copy(b);for(var c=1,d=a.length;d>c;c++)b=a[c],b.xthis.max.x&&(this.max.x=b.x),b.ythis.max.y&&(this.max.y=b.y)}else this.makeEmpty();return this},setFromCenterAndSize:function(){var b=new a.Vector2;return function(a,c){var d=b.copy(c).multiplyScalar(.5);return this.min.copy(a).sub(d),this.max.copy(a).add(d),this}}(),copy:function(a){return this.min.copy(a.min),this.max.copy(a.max),this},makeEmpty:function(){return this.min.x=this.min.y=1/0,this.max.x=this.max.y=-1/0,this},empty:function(){return this.max.xthis.max.x||a.ythis.max.y?!1:!0},containsBox:function(a){return this.min.x<=a.min.x&&a.max.x<=this.max.x&&this.min.y<=a.min.y&&a.max.y<=this.max.y?!0:!1},getParameter:function(b,c){var d=c||new a.Vector2;return d.set((b.x-this.min.x)/(this.max.x-this.min.x),(b.y-this.min.y)/(this.max.y-this.min.y))},isIntersectionBox:function(a){return a.max.xthis.max.x||a.max.ythis.max.y?!1:!0},clampPoint:function(b,c){var d=c||new a.Vector2;return d.copy(b).clamp(this.min,this.max)},distanceToPoint:function(){var b=new a.Vector2;return function(a){var c=b.copy(a).clamp(this.min,this.max);return c.sub(a).length()}}(),intersect:function(a){return this.min.max(a.min),this.max.min(a.max),this},union:function(a){return this.min.min(a.min),this.max.max(a.max),this},translate:function(a){return this.min.add(a),this.max.add(a),this},equals:function(a){return a.min.equals(this.min)&&a.max.equals(this.max)},clone:function(){return(new a.Box2).copy(this)}},a.Box3=function(b,c){this.min=void 0!==b?b:new a.Vector3(1/0,1/0,1/0),this.max=void 0!==c?c:new a.Vector3(-1/0,-1/0,-1/0)},a.Box3.prototype={constructor:a.Box3,set:function(a,b){return this.min.copy(a),this.max.copy(b),this},addPoint:function(a){a.xthis.max.x&&(this.max.x=a.x),a.ythis.max.y&&(this.max.y=a.y),a.zthis.max.z&&(this.max.z=a.z)},setFromPoints:function(a){if(a.length>0){var b=a[0];this.min.copy(b),this.max.copy(b);for(var c=1,d=a.length;d>c;c++)this.addPoint(a[c])}else this.makeEmpty();return this},setFromCenterAndSize:function(){var b=new a.Vector3;return function(a,c){var d=b.copy(c).multiplyScalar(.5);return this.min.copy(a).sub(d),this.max.copy(a).add(d),this}}(),setFromObject:function(){var b=new a.Vector3;return function(a){var c=this;return a.updateMatrixWorld(!0),this.makeEmpty(),a.traverse(function(a){if(void 0!==a.geometry&&void 0!==a.geometry.vertices)for(var d=a.geometry.vertices,e=0,f=d.length;f>e;e++)b.copy(d[e]),b.applyMatrix4(a.matrixWorld),c.expandByPoint(b)}),this}}(),copy:function(a){return this.min.copy(a.min),this.max.copy(a.max),this},makeEmpty:function(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this},empty:function(){return this.max.xthis.max.x||a.ythis.max.y||a.zthis.max.z?!1:!0},containsBox:function(a){return this.min.x<=a.min.x&&a.max.x<=this.max.x&&this.min.y<=a.min.y&&a.max.y<=this.max.y&&this.min.z<=a.min.z&&a.max.z<=this.max.z?!0:!1},getParameter:function(b,c){var d=c||new a.Vector3;return d.set((b.x-this.min.x)/(this.max.x-this.min.x),(b.y-this.min.y)/(this.max.y-this.min.y),(b.z-this.min.z)/(this.max.z-this.min.z))},isIntersectionBox:function(a){return a.max.xthis.max.x||a.max.ythis.max.y||a.max.zthis.max.z?!1:!0},clampPoint:function(b,c){var d=c||new a.Vector3;return d.copy(b).clamp(this.min,this.max)},distanceToPoint:function(){var b=new a.Vector3;return function(a){var c=b.copy(a).clamp(this.min,this.max);return c.sub(a).length()}}(),getBoundingSphere:function(){var b=new a.Vector3;return function(c){var d=c||new a.Sphere;return d.center=this.center(),d.radius=.5*this.size(b).length(),d}}(),intersect:function(a){return this.min.max(a.min),this.max.min(a.max),this},union:function(a){return this.min.min(a.min),this.max.max(a.max),this},applyMatrix4:function(){var b=[new a.Vector3,new a.Vector3,new a.Vector3,new a.Vector3,new a.Vector3,new a.Vector3,new a.Vector3,new a.Vector3];return function(a){return b[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(a),b[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(a),b[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(a),b[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(a),b[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(a),b[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(a),b[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(a),b[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(a),this.makeEmpty(),this.setFromPoints(b),this}}(),translate:function(a){return this.min.add(a),this.max.add(a),this},equals:function(a){return a.min.equals(this.min)&&a.max.equals(this.max)},clone:function(){return(new a.Box3).copy(this)}},a.Matrix3=function(a,b,c,d,e,f,g,h,i){this.elements=new Float32Array(9),this.set(void 0!==a?a:1,b||0,c||0,d||0,void 0!==e?e:1,f||0,g||0,h||0,void 0!==i?i:1)},a.Matrix3.prototype={constructor:a.Matrix3,set:function(a,b,c,d,e,f,g,h,i){var j=this.elements;return j[0]=a,j[3]=b,j[6]=c,j[1]=d,j[4]=e,j[7]=f,j[2]=g,j[5]=h,j[8]=i,this},identity:function(){return this.set(1,0,0,0,1,0,0,0,1),this},copy:function(a){var b=a.elements;return this.set(b[0],b[3],b[6],b[1],b[4],b[7],b[2],b[5],b[8]),this},multiplyVector3:function(a){return console.warn("DEPRECATED: Matrix3's .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead."),a.applyMatrix3(this)},multiplyVector3Array:function(){var b=new a.Vector3;return function(a){for(var c=0,d=a.length;d>c;c+=3)b.x=a[c],b.y=a[c+1],b.z=a[c+2],b.applyMatrix3(this),a[c]=b.x,a[c+1]=b.y,a[c+2]=b.z;return a}}(),multiplyScalar:function(a){var b=this.elements;return b[0]*=a,b[3]*=a,b[6]*=a,b[1]*=a,b[4]*=a,b[7]*=a,b[2]*=a,b[5]*=a,b[8]*=a,this},determinant:function(){var a=this.elements,b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],i=a[7],j=a[8];return b*f*j-b*g*i-c*e*j+c*g*h+d*e*i-d*f*h},getInverse:function(a,b){var c=a.elements,d=this.elements;d[0]=c[10]*c[5]-c[6]*c[9],d[1]=-c[10]*c[1]+c[2]*c[9],d[2]=c[6]*c[1]-c[2]*c[5],d[3]=-c[10]*c[4]+c[6]*c[8],d[4]=c[10]*c[0]-c[2]*c[8],d[5]=-c[6]*c[0]+c[2]*c[4],d[6]=c[9]*c[4]-c[5]*c[8],d[7]=-c[9]*c[0]+c[1]*c[8],d[8]=c[5]*c[0]-c[1]*c[4];var e=c[0]*d[0]+c[1]*d[3]+c[2]*d[6];if(0===e){var f="Matrix3.getInverse(): can't invert matrix, determinant is 0";if(b)throw new Error(f);return console.warn(f),this.identity(),this}return this.multiplyScalar(1/e),this},transpose:function(){var a,b=this.elements;return a=b[1],b[1]=b[3],b[3]=a,a=b[2],b[2]=b[6],b[6]=a,a=b[5],b[5]=b[7],b[7]=a,this},getNormalMatrix:function(a){return this.getInverse(a).transpose(),this},transposeIntoArray:function(a){var b=this.elements;return a[0]=b[0],a[1]=b[3],a[2]=b[6],a[3]=b[1],a[4]=b[4],a[5]=b[7],a[6]=b[2],a[7]=b[5],a[8]=b[8],this},fromArray:function(a){return this.elements.set(a),this},toArray:function(){var a=this.elements;return[a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]]},clone:function(){var b=this.elements;return new a.Matrix3(b[0],b[3],b[6],b[1],b[4],b[7],b[2],b[5],b[8])}},a.Matrix4=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){this.elements=new Float32Array(16);var q=this.elements;q[0]=void 0!==a?a:1,q[4]=b||0,q[8]=c||0,q[12]=d||0,q[1]=e||0,q[5]=void 0!==f?f:1,q[9]=g||0,q[13]=h||0,q[2]=i||0,q[6]=j||0,q[10]=void 0!==k?k:1,q[14]=l||0,q[3]=m||0,q[7]=n||0,q[11]=o||0,q[15]=void 0!==p?p:1},a.Matrix4.prototype={constructor:a.Matrix4,set:function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){var q=this.elements;return q[0]=a,q[4]=b,q[8]=c,q[12]=d,q[1]=e,q[5]=f,q[9]=g,q[13]=h,q[2]=i,q[6]=j,q[10]=k,q[14]=l,q[3]=m,q[7]=n,q[11]=o,q[15]=p,this},identity:function(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this},copy:function(a){return this.elements.set(a.elements),this},extractPosition:function(a){return console.warn("DEPRECATED: Matrix4's .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(a)},copyPosition:function(a){var b=this.elements,c=a.elements;return b[12]=c[12],b[13]=c[13],b[14]=c[14],this},extractRotation:function(){var b=new a.Vector3;return function(a){var c=this.elements,d=a.elements,e=1/b.set(d[0],d[1],d[2]).length(),f=1/b.set(d[4],d[5],d[6]).length(),g=1/b.set(d[8],d[9],d[10]).length();return c[0]=d[0]*e,c[1]=d[1]*e,c[2]=d[2]*e,c[4]=d[4]*f,c[5]=d[5]*f,c[6]=d[6]*f,c[8]=d[8]*g,c[9]=d[9]*g,c[10]=d[10]*g,this}}(),makeRotationFromEuler:function(b){b instanceof a.Euler==!1&&console.error("ERROR: Matrix's .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order. Please update your code.");var c=this.elements,d=b.x,e=b.y,f=b.z,g=Math.cos(d),h=Math.sin(d),i=Math.cos(e),j=Math.sin(e),k=Math.cos(f),l=Math.sin(f);if("XYZ"===b.order){var m=g*k,n=g*l,o=h*k,p=h*l;c[0]=i*k,c[4]=-i*l,c[8]=j,c[1]=n+o*j,c[5]=m-p*j,c[9]=-h*i,c[2]=p-m*j,c[6]=o+n*j,c[10]=g*i}else if("YXZ"===b.order){var q=i*k,r=i*l,s=j*k,t=j*l;c[0]=q+t*h,c[4]=s*h-r,c[8]=g*j,c[1]=g*l,c[5]=g*k,c[9]=-h,c[2]=r*h-s,c[6]=t+q*h,c[10]=g*i}else if("ZXY"===b.order){var q=i*k,r=i*l,s=j*k,t=j*l;c[0]=q-t*h,c[4]=-g*l,c[8]=s+r*h,c[1]=r+s*h,c[5]=g*k,c[9]=t-q*h,c[2]=-g*j,c[6]=h,c[10]=g*i}else if("ZYX"===b.order){var m=g*k,n=g*l,o=h*k,p=h*l;c[0]=i*k,c[4]=o*j-n,c[8]=m*j+p,c[1]=i*l,c[5]=p*j+m,c[9]=n*j-o,c[2]=-j,c[6]=h*i,c[10]=g*i}else if("YZX"===b.order){var u=g*i,v=g*j,w=h*i,x=h*j;c[0]=i*k,c[4]=x-u*l,c[8]=w*l+v,c[1]=l,c[5]=g*k,c[9]=-h*k,c[2]=-j*k,c[6]=v*l+w,c[10]=u-x*l}else if("XZY"===b.order){var u=g*i,v=g*j,w=h*i,x=h*j;c[0]=i*k,c[4]=-l,c[8]=j*k,c[1]=u*l+x,c[5]=g*k,c[9]=v*l-w,c[2]=w*l-v,c[6]=h*k,c[10]=x*l+u}return c[3]=0,c[7]=0,c[11]=0,c[12]=0,c[13]=0,c[14]=0,c[15]=1,this},setRotationFromQuaternion:function(a){return console.warn("DEPRECATED: Matrix4's .setRotationFromQuaternion() has been deprecated in favor of makeRotationFromQuaternion. Please update your code."),this.makeRotationFromQuaternion(a)},makeRotationFromQuaternion:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w,g=c+c,h=d+d,i=e+e,j=c*g,k=c*h,l=c*i,m=d*h,n=d*i,o=e*i,p=f*g,q=f*h,r=f*i;return b[0]=1-(m+o),b[4]=k-r,b[8]=l+q,b[1]=k+r,b[5]=1-(j+o),b[9]=n-p,b[2]=l-q,b[6]=n+p,b[10]=1-(j+m),b[3]=0,b[7]=0,b[11]=0,b[12]=0,b[13]=0,b[14]=0,b[15]=1,this},lookAt:function(){var b=new a.Vector3,c=new a.Vector3,d=new a.Vector3;return function(a,e,f){var g=this.elements;return d.subVectors(a,e).normalize(),0===d.length()&&(d.z=1),b.crossVectors(f,d).normalize(),0===b.length()&&(d.x+=1e-4,b.crossVectors(f,d).normalize()),c.crossVectors(d,b),g[0]=b.x,g[4]=c.x,g[8]=d.x,g[1]=b.y,g[5]=c.y,g[9]=d.y,g[2]=b.z,g[6]=c.z,g[10]=d.z,this}}(),multiply:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Matrix4's .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead."),this.multiplyMatrices(a,b)):this.multiplyMatrices(this,a)},multiplyMatrices:function(a,b){var c=a.elements,d=b.elements,e=this.elements,f=c[0],g=c[4],h=c[8],i=c[12],j=c[1],k=c[5],l=c[9],m=c[13],n=c[2],o=c[6],p=c[10],q=c[14],r=c[3],s=c[7],t=c[11],u=c[15],v=d[0],w=d[4],x=d[8],y=d[12],z=d[1],A=d[5],B=d[9],C=d[13],D=d[2],E=d[6],F=d[10],G=d[14],H=d[3],I=d[7],J=d[11],K=d[15];return e[0]=f*v+g*z+h*D+i*H,e[4]=f*w+g*A+h*E+i*I,e[8]=f*x+g*B+h*F+i*J,e[12]=f*y+g*C+h*G+i*K,e[1]=j*v+k*z+l*D+m*H,e[5]=j*w+k*A+l*E+m*I,e[9]=j*x+k*B+l*F+m*J,e[13]=j*y+k*C+l*G+m*K,e[2]=n*v+o*z+p*D+q*H,e[6]=n*w+o*A+p*E+q*I,e[10]=n*x+o*B+p*F+q*J,e[14]=n*y+o*C+p*G+q*K,e[3]=r*v+s*z+t*D+u*H,e[7]=r*w+s*A+t*E+u*I,e[11]=r*x+s*B+t*F+u*J,e[15]=r*y+s*C+t*G+u*K,this},multiplyToArray:function(a,b,c){var d=this.elements;return this.multiplyMatrices(a,b),c[0]=d[0],c[1]=d[1],c[2]=d[2],c[3]=d[3],c[4]=d[4],c[5]=d[5],c[6]=d[6],c[7]=d[7],c[8]=d[8],c[9]=d[9],c[10]=d[10],c[11]=d[11],c[12]=d[12],c[13]=d[13],c[14]=d[14],c[15]=d[15],this},multiplyScalar:function(a){var b=this.elements;return b[0]*=a,b[4]*=a,b[8]*=a,b[12]*=a,b[1]*=a,b[5]*=a,b[9]*=a,b[13]*=a,b[2]*=a,b[6]*=a,b[10]*=a,b[14]*=a,b[3]*=a,b[7]*=a,b[11]*=a,b[15]*=a,this},multiplyVector3:function(a){return console.warn("DEPRECATED: Matrix4's .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead."),a.applyProjection(this)},multiplyVector4:function(a){return console.warn("DEPRECATED: Matrix4's .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead."),a.applyMatrix4(this)},multiplyVector3Array:function(){var b=new a.Vector3;return function(a){for(var c=0,d=a.length;d>c;c+=3)b.x=a[c],b.y=a[c+1],b.z=a[c+2],b.applyProjection(this),a[c]=b.x,a[c+1]=b.y,a[c+2]=b.z;return a}}(),rotateAxis:function(a){console.warn("DEPRECATED: Matrix4's .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead."),a.transformDirection(this)},crossVector:function(a){return console.warn("DEPRECATED: Matrix4's .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead."),a.applyMatrix4(this)},determinant:function(){var a=this.elements,b=a[0],c=a[4],d=a[8],e=a[12],f=a[1],g=a[5],h=a[9],i=a[13],j=a[2],k=a[6],l=a[10],m=a[14],n=a[3],o=a[7],p=a[11],q=a[15];return n*(+e*h*k-d*i*k-e*g*l+c*i*l+d*g*m-c*h*m)+o*(+b*h*m-b*i*l+e*f*l-d*f*m+d*i*j-e*h*j)+p*(+b*i*k-b*g*m-e*f*k+c*f*m+e*g*j-c*i*j)+q*(-d*g*j-b*h*k+b*g*l+d*f*k-c*f*l+c*h*j)},transpose:function(){var a,b=this.elements;return a=b[1],b[1]=b[4],b[4]=a,a=b[2],b[2]=b[8],b[8]=a,a=b[6],b[6]=b[9],b[9]=a,a=b[3],b[3]=b[12],b[12]=a,a=b[7],b[7]=b[13],b[13]=a,a=b[11],b[11]=b[14],b[14]=a,this},flattenToArray:function(a){var b=this.elements;return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a[4]=b[4],a[5]=b[5],a[6]=b[6],a[7]=b[7],a[8]=b[8],a[9]=b[9],a[10]=b[10],a[11]=b[11],a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15],a},flattenToArrayOffset:function(a,b){var c=this.elements;return a[b]=c[0],a[b+1]=c[1],a[b+2]=c[2],a[b+3]=c[3],a[b+4]=c[4],a[b+5]=c[5],a[b+6]=c[6],a[b+7]=c[7],a[b+8]=c[8],a[b+9]=c[9],a[b+10]=c[10],a[b+11]=c[11],a[b+12]=c[12],a[b+13]=c[13],a[b+14]=c[14],a[b+15]=c[15],a},getPosition:function(){var b=new a.Vector3;return function(){console.warn("DEPRECATED: Matrix4's .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.");var a=this.elements;return b.set(a[12],a[13],a[14])}}(),setPosition:function(a){var b=this.elements;return b[12]=a.x,b[13]=a.y,b[14]=a.z,this},getInverse:function(a,b){var c=this.elements,d=a.elements,e=d[0],f=d[4],g=d[8],h=d[12],i=d[1],j=d[5],k=d[9],l=d[13],m=d[2],n=d[6],o=d[10],p=d[14],q=d[3],r=d[7],s=d[11],t=d[15];c[0]=k*p*r-l*o*r+l*n*s-j*p*s-k*n*t+j*o*t,c[4]=h*o*r-g*p*r-h*n*s+f*p*s+g*n*t-f*o*t,c[8]=g*l*r-h*k*r+h*j*s-f*l*s-g*j*t+f*k*t,c[12]=h*k*n-g*l*n-h*j*o+f*l*o+g*j*p-f*k*p,c[1]=l*o*q-k*p*q-l*m*s+i*p*s+k*m*t-i*o*t,c[5]=g*p*q-h*o*q+h*m*s-e*p*s-g*m*t+e*o*t,c[9]=h*k*q-g*l*q-h*i*s+e*l*s+g*i*t-e*k*t,c[13]=g*l*m-h*k*m+h*i*o-e*l*o-g*i*p+e*k*p,c[2]=j*p*q-l*n*q+l*m*r-i*p*r-j*m*t+i*n*t,c[6]=h*n*q-f*p*q-h*m*r+e*p*r+f*m*t-e*n*t,c[10]=f*l*q-h*j*q+h*i*r-e*l*r-f*i*t+e*j*t,c[14]=h*j*m-f*l*m-h*i*n+e*l*n+f*i*p-e*j*p,c[3]=k*n*q-j*o*q-k*m*r+i*o*r+j*m*s-i*n*s,c[7]=f*o*q-g*n*q+g*m*r-e*o*r-f*m*s+e*n*s,c[11]=g*j*q-f*k*q-g*i*r+e*k*r+f*i*s-e*j*s,c[15]=f*k*m-g*j*m+g*i*n-e*k*n-f*i*o+e*j*o;
+var u=e*c[0]+i*c[4]+m*c[8]+q*c[12];if(0==u){var v="Matrix4.getInverse(): can't invert matrix, determinant is 0";if(b)throw new Error(v);return console.warn(v),this.identity(),this}return this.multiplyScalar(1/u),this},translate:function(){console.warn("DEPRECATED: Matrix4's .translate() has been removed.")},rotateX:function(){console.warn("DEPRECATED: Matrix4's .rotateX() has been removed.")},rotateY:function(){console.warn("DEPRECATED: Matrix4's .rotateY() has been removed.")},rotateZ:function(){console.warn("DEPRECATED: Matrix4's .rotateZ() has been removed.")},rotateByAxis:function(){console.warn("DEPRECATED: Matrix4's .rotateByAxis() has been removed.")},scale:function(a){var b=this.elements,c=a.x,d=a.y,e=a.z;return b[0]*=c,b[4]*=d,b[8]*=e,b[1]*=c,b[5]*=d,b[9]*=e,b[2]*=c,b[6]*=d,b[10]*=e,b[3]*=c,b[7]*=d,b[11]*=e,this},getMaxScaleOnAxis:function(){var a=this.elements,b=a[0]*a[0]+a[1]*a[1]+a[2]*a[2],c=a[4]*a[4]+a[5]*a[5]+a[6]*a[6],d=a[8]*a[8]+a[9]*a[9]+a[10]*a[10];return Math.sqrt(Math.max(b,Math.max(c,d)))},makeTranslation:function(a,b,c){return this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1),this},makeRotationX:function(a){var b=Math.cos(a),c=Math.sin(a);return this.set(1,0,0,0,0,b,-c,0,0,c,b,0,0,0,0,1),this},makeRotationY:function(a){var b=Math.cos(a),c=Math.sin(a);return this.set(b,0,c,0,0,1,0,0,-c,0,b,0,0,0,0,1),this},makeRotationZ:function(a){var b=Math.cos(a),c=Math.sin(a);return this.set(b,-c,0,0,c,b,0,0,0,0,1,0,0,0,0,1),this},makeRotationAxis:function(a,b){var c=Math.cos(b),d=Math.sin(b),e=1-c,f=a.x,g=a.y,h=a.z,i=e*f,j=e*g;return this.set(i*f+c,i*g-d*h,i*h+d*g,0,i*g+d*h,j*g+c,j*h-d*f,0,i*h-d*g,j*h+d*f,e*h*h+c,0,0,0,0,1),this},makeScale:function(a,b,c){return this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1),this},compose:function(a,b,c){return this.makeRotationFromQuaternion(b),this.scale(c),this.setPosition(a),this},decompose:function(){var b=new a.Vector3,c=new a.Matrix4;return function(a,d,e){var f=this.elements,g=b.set(f[0],f[1],f[2]).length(),h=b.set(f[4],f[5],f[6]).length(),i=b.set(f[8],f[9],f[10]).length(),j=this.determinant();0>j&&(g=-g),a.x=f[12],a.y=f[13],a.z=f[14],c.elements.set(this.elements);var k=1/g,l=1/h,m=1/i;return c.elements[0]*=k,c.elements[1]*=k,c.elements[2]*=k,c.elements[4]*=l,c.elements[5]*=l,c.elements[6]*=l,c.elements[8]*=m,c.elements[9]*=m,c.elements[10]*=m,d.setFromRotationMatrix(c),e.x=g,e.y=h,e.z=i,this}}(),makeFrustum:function(a,b,c,d,e,f){var g=this.elements,h=2*e/(b-a),i=2*e/(d-c),j=(b+a)/(b-a),k=(d+c)/(d-c),l=-(f+e)/(f-e),m=-2*f*e/(f-e);return g[0]=h,g[4]=0,g[8]=j,g[12]=0,g[1]=0,g[5]=i,g[9]=k,g[13]=0,g[2]=0,g[6]=0,g[10]=l,g[14]=m,g[3]=0,g[7]=0,g[11]=-1,g[15]=0,this},makePerspective:function(b,c,d,e){var f=d*Math.tan(a.Math.degToRad(.5*b)),g=-f,h=g*c,i=f*c;return this.makeFrustum(h,i,g,f,d,e)},makeOrthographic:function(a,b,c,d,e,f){var g=this.elements,h=b-a,i=c-d,j=f-e,k=(b+a)/h,l=(c+d)/i,m=(f+e)/j;return g[0]=2/h,g[4]=0,g[8]=0,g[12]=-k,g[1]=0,g[5]=2/i,g[9]=0,g[13]=-l,g[2]=0,g[6]=0,g[10]=-2/j,g[14]=-m,g[3]=0,g[7]=0,g[11]=0,g[15]=1,this},fromArray:function(a){return this.elements.set(a),this},toArray:function(){var a=this.elements;return[a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]]},clone:function(){var b=this.elements;return new a.Matrix4(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15])}},a.Ray=function(b,c){this.origin=void 0!==b?b:new a.Vector3,this.direction=void 0!==c?c:new a.Vector3},a.Ray.prototype={constructor:a.Ray,set:function(a,b){return this.origin.copy(a),this.direction.copy(b),this},copy:function(a){return this.origin.copy(a.origin),this.direction.copy(a.direction),this},at:function(b,c){var d=c||new a.Vector3;return d.copy(this.direction).multiplyScalar(b).add(this.origin)},recast:function(){var b=new a.Vector3;return function(a){return this.origin.copy(this.at(a,b)),this}}(),closestPointToPoint:function(b,c){var d=c||new a.Vector3;d.subVectors(b,this.origin);var e=d.dot(this.direction);return 0>e?d.copy(this.origin):d.copy(this.direction).multiplyScalar(e).add(this.origin)},distanceToPoint:function(){var b=new a.Vector3;return function(a){var c=b.subVectors(a,this.origin).dot(this.direction);return 0>c?this.origin.distanceTo(a):(b.copy(this.direction).multiplyScalar(c).add(this.origin),b.distanceTo(a))}}(),distanceSqToSegment:function(a,b,c,d){var e,f,g,h,i=a.clone().add(b).multiplyScalar(.5),j=b.clone().sub(a).normalize(),k=.5*a.distanceTo(b),l=this.origin.clone().sub(i),m=-this.direction.dot(j),n=l.dot(this.direction),o=-l.dot(j),p=l.lengthSq(),q=Math.abs(1-m*m);if(q>=0)if(e=m*o-n,f=m*n-o,h=k*q,e>=0)if(f>=-h)if(h>=f){var r=1/q;e*=r,f*=r,g=e*(e+m*f+2*n)+f*(m*e+f+2*o)+p}else f=k,e=Math.max(0,-(m*f+n)),g=-e*e+f*(f+2*o)+p;else f=-k,e=Math.max(0,-(m*f+n)),g=-e*e+f*(f+2*o)+p;else-h>=f?(e=Math.max(0,-(-m*k+n)),f=e>0?-k:Math.min(Math.max(-k,-o),k),g=-e*e+f*(f+2*o)+p):h>=f?(e=0,f=Math.min(Math.max(-k,-o),k),g=f*(f+2*o)+p):(e=Math.max(0,-(m*k+n)),f=e>0?k:Math.min(Math.max(-k,-o),k),g=-e*e+f*(f+2*o)+p);else f=m>0?-k:k,e=Math.max(0,-(m*f+n)),g=-e*e+f*(f+2*o)+p;return c&&c.copy(this.direction.clone().multiplyScalar(e).add(this.origin)),d&&d.copy(j.clone().multiplyScalar(f).add(i)),g},isIntersectionSphere:function(a){return this.distanceToPoint(a.center)<=a.radius},isIntersectionPlane:function(a){var b=a.distanceToPoint(this.origin);if(0===b)return!0;var c=a.normal.dot(this.direction);return 0>c*b?!0:!1},distanceToPlane:function(a){var b=a.normal.dot(this.direction);if(0==b)return 0==a.distanceToPoint(this.origin)?0:null;var c=-(this.origin.dot(a.normal)+a.constant)/b;return c>=0?c:null},intersectPlane:function(a,b){var c=this.distanceToPlane(a);return null===c?null:this.at(c,b)},isIntersectionBox:function(){var b=new a.Vector3;return function(a){return null!==this.intersectBox(a,b)}}(),intersectBox:function(a,b){var c,d,e,f,g,h,i=1/this.direction.x,j=1/this.direction.y,k=1/this.direction.z,l=this.origin;return i>=0?(c=(a.min.x-l.x)*i,d=(a.max.x-l.x)*i):(c=(a.max.x-l.x)*i,d=(a.min.x-l.x)*i),j>=0?(e=(a.min.y-l.y)*j,f=(a.max.y-l.y)*j):(e=(a.max.y-l.y)*j,f=(a.min.y-l.y)*j),c>f||e>d?null:((e>c||c!==c)&&(c=e),(d>f||d!==d)&&(d=f),k>=0?(g=(a.min.z-l.z)*k,h=(a.max.z-l.z)*k):(g=(a.max.z-l.z)*k,h=(a.min.z-l.z)*k),c>h||g>d?null:((g>c||c!==c)&&(c=g),(d>h||d!==d)&&(d=h),0>d?null:this.at(c>=0?c:d,b)))},intersectTriangle:function(){var b=new a.Vector3,c=new a.Vector3,d=new a.Vector3,e=new a.Vector3;return function(a,f,g,h,i){c.subVectors(f,a),d.subVectors(g,a),e.crossVectors(c,d);var j,k=this.direction.dot(e);if(k>0){if(h)return null;j=1}else{if(!(0>k))return null;j=-1,k=-k}b.subVectors(this.origin,a);var l=j*this.direction.dot(d.crossVectors(b,d));if(0>l)return null;var m=j*this.direction.dot(c.cross(b));if(0>m)return null;if(l+m>k)return null;var n=-j*b.dot(e);return 0>n?null:this.at(n/k,i)}}(),applyMatrix4:function(a){return this.direction.add(this.origin).applyMatrix4(a),this.origin.applyMatrix4(a),this.direction.sub(this.origin),this.direction.normalize(),this},equals:function(a){return a.origin.equals(this.origin)&&a.direction.equals(this.direction)},clone:function(){return(new a.Ray).copy(this)}},a.Sphere=function(b,c){this.center=void 0!==b?b:new a.Vector3,this.radius=void 0!==c?c:0},a.Sphere.prototype={constructor:a.Sphere,set:function(a,b){return this.center.copy(a),this.radius=b,this},setFromPoints:function(){var b=new a.Box3;return function(a,c){var d=this.center;void 0!==c?d.copy(c):b.setFromPoints(a).center(d);for(var e=0,f=0,g=a.length;g>f;f++)e=Math.max(e,d.distanceToSquared(a[f]));return this.radius=Math.sqrt(e),this}}(),copy:function(a){return this.center.copy(a.center),this.radius=a.radius,this},empty:function(){return this.radius<=0},containsPoint:function(a){return a.distanceToSquared(this.center)<=this.radius*this.radius},distanceToPoint:function(a){return a.distanceTo(this.center)-this.radius},intersectsSphere:function(a){var b=this.radius+a.radius;return a.center.distanceToSquared(this.center)<=b*b},clampPoint:function(b,c){var d=this.center.distanceToSquared(b),e=c||new a.Vector3;return e.copy(b),d>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e},getBoundingBox:function(b){var c=b||new a.Box3;return c.set(this.center,this.center),c.expandByScalar(this.radius),c},applyMatrix4:function(a){return this.center.applyMatrix4(a),this.radius=this.radius*a.getMaxScaleOnAxis(),this},translate:function(a){return this.center.add(a),this},equals:function(a){return a.center.equals(this.center)&&a.radius===this.radius},clone:function(){return(new a.Sphere).copy(this)}},a.Frustum=function(b,c,d,e,f,g){this.planes=[void 0!==b?b:new a.Plane,void 0!==c?c:new a.Plane,void 0!==d?d:new a.Plane,void 0!==e?e:new a.Plane,void 0!==f?f:new a.Plane,void 0!==g?g:new a.Plane]},a.Frustum.prototype={constructor:a.Frustum,set:function(a,b,c,d,e,f){var g=this.planes;return g[0].copy(a),g[1].copy(b),g[2].copy(c),g[3].copy(d),g[4].copy(e),g[5].copy(f),this},copy:function(a){for(var b=this.planes,c=0;6>c;c++)b[c].copy(a.planes[c]);return this},setFromMatrix:function(a){var b=this.planes,c=a.elements,d=c[0],e=c[1],f=c[2],g=c[3],h=c[4],i=c[5],j=c[6],k=c[7],l=c[8],m=c[9],n=c[10],o=c[11],p=c[12],q=c[13],r=c[14],s=c[15];return b[0].setComponents(g-d,k-h,o-l,s-p).normalize(),b[1].setComponents(g+d,k+h,o+l,s+p).normalize(),b[2].setComponents(g+e,k+i,o+m,s+q).normalize(),b[3].setComponents(g-e,k-i,o-m,s-q).normalize(),b[4].setComponents(g-f,k-j,o-n,s-r).normalize(),b[5].setComponents(g+f,k+j,o+n,s+r).normalize(),this},intersectsObject:function(){var b=new a.Sphere;return function(a){var c=a.geometry;return null===c.boundingSphere&&c.computeBoundingSphere(),b.copy(c.boundingSphere),b.applyMatrix4(a.matrixWorld),this.intersectsSphere(b)}}(),intersectsSphere:function(a){for(var b=this.planes,c=a.center,d=-a.radius,e=0;6>e;e++){var f=b[e].distanceToPoint(c);if(d>f)return!1}return!0},intersectsBox:function(){var b=new a.Vector3,c=new a.Vector3;return function(a){for(var d=this.planes,e=0;6>e;e++){var f=d[e];b.x=f.normal.x>0?a.min.x:a.max.x,c.x=f.normal.x>0?a.max.x:a.min.x,b.y=f.normal.y>0?a.min.y:a.max.y,c.y=f.normal.y>0?a.max.y:a.min.y,b.z=f.normal.z>0?a.min.z:a.max.z,c.z=f.normal.z>0?a.max.z:a.min.z;var g=f.distanceToPoint(b),h=f.distanceToPoint(c);if(0>g&&0>h)return!1}return!0}}(),containsPoint:function(a){for(var b=this.planes,c=0;6>c;c++)if(b[c].distanceToPoint(a)<0)return!1;return!0},clone:function(){return(new a.Frustum).copy(this)}},a.Plane=function(b,c){this.normal=void 0!==b?b:new a.Vector3(1,0,0),this.constant=void 0!==c?c:0},a.Plane.prototype={constructor:a.Plane,set:function(a,b){return this.normal.copy(a),this.constant=b,this},setComponents:function(a,b,c,d){return this.normal.set(a,b,c),this.constant=d,this},setFromNormalAndCoplanarPoint:function(a,b){return this.normal.copy(a),this.constant=-b.dot(this.normal),this},setFromCoplanarPoints:function(){var b=new a.Vector3,c=new a.Vector3;return function(a,d,e){var f=b.subVectors(e,d).cross(c.subVectors(a,d)).normalize();return this.setFromNormalAndCoplanarPoint(f,a),this}}(),copy:function(a){return this.normal.copy(a.normal),this.constant=a.constant,this},normalize:function(){var a=1/this.normal.length();return this.normal.multiplyScalar(a),this.constant*=a,this},negate:function(){return this.constant*=-1,this.normal.negate(),this},distanceToPoint:function(a){return this.normal.dot(a)+this.constant},distanceToSphere:function(a){return this.distanceToPoint(a.center)-a.radius},projectPoint:function(a,b){return this.orthoPoint(a,b).sub(a).negate()},orthoPoint:function(b,c){var d=this.distanceToPoint(b),e=c||new a.Vector3;return e.copy(this.normal).multiplyScalar(d)},isIntersectionLine:function(a){var b=this.distanceToPoint(a.start),c=this.distanceToPoint(a.end);return 0>b&&c>0||0>c&&b>0},intersectLine:function(){var b=new a.Vector3;return function(c,d){var e=d||new a.Vector3,f=c.delta(b),g=this.normal.dot(f);if(0==g)return 0==this.distanceToPoint(c.start)?e.copy(c.start):void 0;var h=-(c.start.dot(this.normal)+this.constant)/g;return 0>h||h>1?void 0:e.copy(f).multiplyScalar(h).add(c.start)}}(),coplanarPoint:function(b){var c=b||new a.Vector3;return c.copy(this.normal).multiplyScalar(-this.constant)},applyMatrix4:function(){var b=new a.Vector3,c=new a.Vector3,d=new a.Matrix3;return function(a,e){var f=e||d.getNormalMatrix(a),g=b.copy(this.normal).applyMatrix3(f),h=this.coplanarPoint(c);return h.applyMatrix4(a),this.setFromNormalAndCoplanarPoint(g,h),this}}(),translate:function(a){return this.constant=this.constant-a.dot(this.normal),this},equals:function(a){return a.normal.equals(this.normal)&&a.constant==this.constant},clone:function(){return(new a.Plane).copy(this)}},a.Math={PI2:2*Math.PI,generateUUID:function(){var a,b="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),c=new Array(36),d=0;return function(){for(var e=0;36>e;e++)8==e||13==e||18==e||23==e?c[e]="-":14==e?c[e]="4":(2>=d&&(d=33554432+16777216*Math.random()|0),a=15&d,d>>=4,c[e]=b[19==e?3&a|8:a]);return c.join("")}}(),clamp:function(a,b,c){return b>a?b:a>c?c:a},clampBottom:function(a,b){return b>a?b:a},mapLinear:function(a,b,c,d,e){return d+(a-b)*(e-d)/(c-b)},smoothstep:function(a,b,c){return b>=a?0:a>=c?1:(a=(a-b)/(c-b),a*a*(3-2*a))},smootherstep:function(a,b,c){return b>=a?0:a>=c?1:(a=(a-b)/(c-b),a*a*a*(a*(6*a-15)+10))},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(a,b){return a+Math.floor(Math.random()*(b-a+1))},randFloat:function(a,b){return a+Math.random()*(b-a)},randFloatSpread:function(a){return a*(.5-Math.random())},sign:function(a){return 0>a?-1:a>0?1:0},degToRad:function(){var a=Math.PI/180;return function(b){return b*a}}(),radToDeg:function(){var a=180/Math.PI;return function(b){return b*a}}(),isPowerOfTwo:function(a){return 0===(a&a-1)&&0!==a}},a.Spline=function(b){function c(a,b,c,d,e,f,g){var h=.5*(c-a),i=.5*(d-b);return(2*(b-c)+h+i)*g+(-3*(b-c)-2*h-i)*f+h*e+b}this.points=b;var d,e,f,g,h,i,j,k,l,m=[],n={x:0,y:0,z:0};this.initFromArray=function(a){this.points=[];for(var b=0;bthis.points.length-2?this.points.length-1:e+1,m[3]=e>this.points.length-3?this.points.length-1:e+2,i=this.points[m[0]],j=this.points[m[1]],k=this.points[m[2]],l=this.points[m[3]],g=f*f,h=f*g,n.x=c(i.x,j.x,k.x,l.x,f,g,h),n.y=c(i.y,j.y,k.y,l.y,f,g,h),n.z=c(i.z,j.z,k.z,l.z,f,g,h),n},this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;c>a;a++)b=this.points[a],d[a]=[b.x,b.y,b.z];return d},this.getLength=function(b){var c,d,e,f,g=0,h=0,i=0,j=new a.Vector3,k=new a.Vector3,l=[],m=0;for(l[0]=0,b||(b=100),e=this.points.length*b,j.copy(this.points[0]),c=1;e>c;c++)d=c/e,f=this.getPoint(d),k.copy(f),m+=k.distanceTo(j),j.copy(f),g=(this.points.length-1)*d,h=Math.floor(g),h!=i&&(l[h]=m,i=h);return l[l.length]=m,{chunks:l,total:m}},this.reparametrizeByArcLength=function(b){var c,d,e,f,g,h,i,j,k=[],l=new a.Vector3,m=this.getLength();for(k.push(l.copy(this.points[0]).clone()),c=1;cd;d++)e=f+d*(1/i)*(g-f),j=this.getPoint(e),k.push(l.copy(j).clone());k.push(l.copy(this.points[c]).clone())}this.points=k}},a.Triangle=function(b,c,d){this.a=void 0!==b?b:new a.Vector3,this.b=void 0!==c?c:new a.Vector3,this.c=void 0!==d?d:new a.Vector3},a.Triangle.normal=function(){var b=new a.Vector3;return function(c,d,e,f){var g=f||new a.Vector3;g.subVectors(e,d),b.subVectors(c,d),g.cross(b);var h=g.lengthSq();return h>0?g.multiplyScalar(1/Math.sqrt(h)):g.set(0,0,0)}}(),a.Triangle.barycoordFromPoint=function(){var b=new a.Vector3,c=new a.Vector3,d=new a.Vector3;return function(e,f,g,h,i){b.subVectors(h,f),c.subVectors(g,f),d.subVectors(e,f);var j=b.dot(b),k=b.dot(c),l=b.dot(d),m=c.dot(c),n=c.dot(d),o=j*m-k*k,p=i||new a.Vector3;if(0==o)return p.set(-2,-1,-1);var q=1/o,r=(m*l-k*n)*q,s=(j*n-k*l)*q;return p.set(1-r-s,s,r)}}(),a.Triangle.containsPoint=function(){var b=new a.Vector3;return function(c,d,e,f){var g=a.Triangle.barycoordFromPoint(c,d,e,f,b);return g.x>=0&&g.y>=0&&g.x+g.y<=1}}(),a.Triangle.prototype={constructor:a.Triangle,set:function(a,b,c){return this.a.copy(a),this.b.copy(b),this.c.copy(c),this},setFromPointsAndIndices:function(a,b,c,d){return this.a.copy(a[b]),this.b.copy(a[c]),this.c.copy(a[d]),this},copy:function(a){return this.a.copy(a.a),this.b.copy(a.b),this.c.copy(a.c),this},area:function(){var b=new a.Vector3,c=new a.Vector3;return function(){return b.subVectors(this.c,this.b),c.subVectors(this.a,this.b),.5*b.cross(c).length()}}(),midpoint:function(b){var c=b||new a.Vector3;return c.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)},normal:function(b){return a.Triangle.normal(this.a,this.b,this.c,b)},plane:function(b){var c=b||new a.Plane;return c.setFromCoplanarPoints(this.a,this.b,this.c)},barycoordFromPoint:function(b,c){return a.Triangle.barycoordFromPoint(b,this.a,this.b,this.c,c)},containsPoint:function(b){return a.Triangle.containsPoint(b,this.a,this.b,this.c)},equals:function(a){return a.a.equals(this.a)&&a.b.equals(this.b)&&a.c.equals(this.c)},clone:function(){return(new a.Triangle).copy(this)}},a.Vertex=function(a){return console.warn("THREE.Vertex has been DEPRECATED. Use THREE.Vector3 instead."),a},a.UV=function(b,c){return console.warn("THREE.UV has been DEPRECATED. Use THREE.Vector2 instead."),new a.Vector2(b,c)},a.Clock=function(a){this.autoStart=void 0!==a?a:!0,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1},a.Clock.prototype={constructor:a.Clock,start:function(){this.startTime=void 0!==self.performance&&void 0!==self.performance.now?self.performance.now():Date.now(),this.oldTime=this.startTime,this.running=!0},stop:function(){this.getElapsedTime(),this.running=!1},getElapsedTime:function(){return this.getDelta(),this.elapsedTime},getDelta:function(){var a=0;if(this.autoStart&&!this.running&&this.start(),this.running){var b=void 0!==self.performance&&void 0!==self.performance.now?self.performance.now():Date.now();a=.001*(b-this.oldTime),this.oldTime=b,this.elapsedTime+=a}return a}},a.EventDispatcher=function(){},a.EventDispatcher.prototype={constructor:a.EventDispatcher,apply:function(b){b.addEventListener=a.EventDispatcher.prototype.addEventListener,b.hasEventListener=a.EventDispatcher.prototype.hasEventListener,b.removeEventListener=a.EventDispatcher.prototype.removeEventListener,b.dispatchEvent=a.EventDispatcher.prototype.dispatchEvent},addEventListener:function(a,b){void 0===this._listeners&&(this._listeners={});var c=this._listeners;void 0===c[a]&&(c[a]=[]),-1===c[a].indexOf(b)&&c[a].push(b)},hasEventListener:function(a,b){if(void 0===this._listeners)return!1;var c=this._listeners;return void 0!==c[a]&&-1!==c[a].indexOf(b)?!0:!1},removeEventListener:function(a,b){if(void 0!==this._listeners){var c=this._listeners,d=c[a];if(void 0!==d){var e=d.indexOf(b);-1!==e&&d.splice(e,1)}}},dispatchEvent:function(){var a=[];return function(b){if(void 0!==this._listeners){var c=this._listeners,d=c[b.type];if(void 0!==d){b.target=this;for(var e=d.length,f=0;e>f;f++)a[f]=d[f];for(var f=0;e>f;f++)a[f].call(this,b)}}}}()},function(a){a.Raycaster=function(b,c,d,e){this.ray=new a.Ray(b,c),this.near=d||0,this.far=e||1/0};var b=new a.Sphere,c=new a.Ray,d=(new a.Plane,new a.Vector3,new a.Vector3),e=new a.Matrix4,f=function(a,b){return a.distance-b.distance},g=new a.Vector3,h=new a.Vector3,i=new a.Vector3,j=function(f,k,l){if(f instanceof a.Sprite){d.setFromMatrixPosition(f.matrixWorld);var m=k.ray.distanceToPoint(d);if(m>f.scale.x)return l;l.push({distance:m,point:f.position,face:null,object:f})}else if(f instanceof a.LOD){d.setFromMatrixPosition(f.matrixWorld);var m=k.ray.origin.distanceTo(d);j(f.getObjectForDistance(m),k,l)}else if(f instanceof a.Mesh){var n=f.geometry;if(null===n.boundingSphere&&n.computeBoundingSphere(),b.copy(n.boundingSphere),b.applyMatrix4(f.matrixWorld),k.ray.isIntersectionSphere(b)===!1)return l;if(e.getInverse(f.matrixWorld),c.copy(k.ray).applyMatrix4(e),null!==n.boundingBox&&c.isIntersectionBox(n.boundingBox)===!1)return l;if(n instanceof a.BufferGeometry){var o=f.material;if(void 0===o)return l;var p,q,r,s=n.attributes,t=k.precision;if(void 0!==s.index)for(var u=n.offsets,v=s.index.array,w=s.position.array,x=0,y=u.length;y>x;++x)for(var z=u[x].start,A=u[x].count,B=u[x].index,C=z,D=z+A;D>C;C+=3){if(p=B+v[C],q=B+v[C+1],r=B+v[C+2],g.set(w[3*p],w[3*p+1],w[3*p+2]),h.set(w[3*q],w[3*q+1],w[3*q+2]),i.set(w[3*r],w[3*r+1],w[3*r+2]),o.side===a.BackSide)var E=c.intersectTriangle(i,h,g,!0);else var E=c.intersectTriangle(g,h,i,o.side!==a.DoubleSide);if(null!==E){E.applyMatrix4(f.matrixWorld);var m=k.ray.origin.distanceTo(E);t>m||mk.far||l.push({distance:m,point:E,indices:[p,q,r],face:null,faceIndex:null,object:f})}}else for(var u=n.offsets,w=s.position.array,C=0,D=s.position.array.length;D>C;C+=3){if(p=C,q=C+1,r=C+2,g.set(w[3*p],w[3*p+1],w[3*p+2]),h.set(w[3*q],w[3*q+1],w[3*q+2]),i.set(w[3*r],w[3*r+1],w[3*r+2]),o.side===a.BackSide)var E=c.intersectTriangle(i,h,g,!0);else var E=c.intersectTriangle(g,h,i,o.side!==a.DoubleSide);if(null!==E){E.applyMatrix4(f.matrixWorld);var m=k.ray.origin.distanceTo(E);t>m||mk.far||l.push({distance:m,point:E,indices:[p,q,r],face:null,faceIndex:null,object:f})}}}else if(n instanceof a.Geometry)for(var p,q,r,F=f.material instanceof a.MeshFaceMaterial,G=F===!0?f.material.materials:null,t=k.precision,H=n.vertices,I=0,J=n.faces.length;J>I;I++){var K=n.faces[I],o=F===!0?G[K.materialIndex]:f.material;if(void 0!==o){if(p=H[K.a],q=H[K.b],r=H[K.c],o.morphTargets===!0){var L=n.morphTargets,M=f.morphTargetInfluences;g.set(0,0,0),h.set(0,0,0),i.set(0,0,0);for(var N=0,O=L.length;O>N;N++){var P=M[N];if(0!==P){var Q=L[N].vertices;g.x+=(Q[K.a].x-p.x)*P,g.y+=(Q[K.a].y-p.y)*P,g.z+=(Q[K.a].z-p.z)*P,h.x+=(Q[K.b].x-q.x)*P,h.y+=(Q[K.b].y-q.y)*P,h.z+=(Q[K.b].z-q.z)*P,i.x+=(Q[K.c].x-r.x)*P,i.y+=(Q[K.c].y-r.y)*P,i.z+=(Q[K.c].z-r.z)*P}}g.add(p),h.add(q),i.add(r),p=g,q=h,r=i}if(o.side===a.BackSide)var E=c.intersectTriangle(r,q,p,!0);else var E=c.intersectTriangle(p,q,r,o.side!==a.DoubleSide);if(null!==E){E.applyMatrix4(f.matrixWorld);var m=k.ray.origin.distanceTo(E);t>m||mk.far||l.push({distance:m,point:E,face:K,faceIndex:I,object:f})}}}}else if(f instanceof a.Line){var t=k.linePrecision,R=t*t,n=f.geometry;if(null===n.boundingSphere&&n.computeBoundingSphere(),b.copy(n.boundingSphere),b.applyMatrix4(f.matrixWorld),k.ray.isIntersectionSphere(b)===!1)return l;if(e.getInverse(f.matrixWorld),c.copy(k.ray).applyMatrix4(e),n instanceof a.Geometry)for(var H=n.vertices,S=H.length,T=new a.Vector3,U=new a.Vector3,V=f.type===a.LineStrip?1:2,C=0;S-1>C;C+=V){var W=c.distanceSqToSegment(H[C],H[C+1],U,T);if(!(W>R)){var m=c.origin.distanceTo(U);mk.far||l.push({distance:m,point:T.clone().applyMatrix4(f.matrixWorld),face:null,faceIndex:null,object:f})}}}},k=function(a,b,c){for(var d=a.getDescendants(),e=0,f=d.length;f>e;e++)j(d[e],b,c)};a.Raycaster.prototype.precision=1e-4,a.Raycaster.prototype.linePrecision=1,a.Raycaster.prototype.set=function(a,b){this.ray.set(a,b)},a.Raycaster.prototype.intersectObject=function(a,b){var c=[];return b===!0&&k(a,this,c),j(a,this,c),c.sort(f),c},a.Raycaster.prototype.intersectObjects=function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)j(a[d],this,c),b===!0&&k(a[d],this,c);return c.sort(f),c}}(a),a.Object3D=function(){this.id=a.Object3DIdCount++,this.uuid=a.Math.generateUUID(),this.name="",this.parent=void 0,this.children=[],this.up=new a.Vector3(0,1,0),this.position=new a.Vector3,this._rotation=new a.Euler,this._quaternion=new a.Quaternion,this.scale=new a.Vector3(1,1,1),this._rotation._quaternion=this.quaternion,this._quaternion._euler=this.rotation,this.renderDepth=null,this.rotationAutoUpdate=!0,this.matrix=new a.Matrix4,this.matrixWorld=new a.Matrix4,this.matrixAutoUpdate=!0,this.matrixWorldNeedsUpdate=!0,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.userData={}},a.Object3D.prototype={constructor:a.Object3D,get rotation(){return this._rotation},set rotation(a){this._rotation=a,this._rotation._quaternion=this._quaternion,this._quaternion._euler=this._rotation,this._rotation._updateQuaternion()},get quaternion(){return this._quaternion},set quaternion(a){this._quaternion=a,this._quaternion._euler=this._rotation,this._rotation._quaternion=this._quaternion,this._quaternion._updateEuler()},get eulerOrder(){return console.warn("DEPRECATED: Object3D's .eulerOrder has been moved to Object3D's .rotation.order."),this.rotation.order},set eulerOrder(a){console.warn("DEPRECATED: Object3D's .eulerOrder has been moved to Object3D's .rotation.order."),this.rotation.order=a},get useQuaternion(){console.warn("DEPRECATED: Object3D's .useQuaternion has been removed. The library now uses quaternions by default.")},set useQuaternion(a){console.warn("DEPRECATED: Object3D's .useQuaternion has been removed. The library now uses quaternions by default.")},applyMatrix:function(a){this.matrix.multiplyMatrices(a,this.matrix),this.matrix.decompose(this.position,this.quaternion,this.scale)},setRotationFromAxisAngle:function(a,b){this.quaternion.setFromAxisAngle(a,b)},setRotationFromEuler:function(a){this.quaternion.setFromEuler(a,!0)},setRotationFromMatrix:function(a){this.quaternion.setFromRotationMatrix(a)},setRotationFromQuaternion:function(a){this.quaternion.copy(a)},rotateOnAxis:function(){var b=new a.Quaternion;return function(a,c){return b.setFromAxisAngle(a,c),this.quaternion.multiply(b),this}}(),rotateX:function(){var b=new a.Vector3(1,0,0);return function(a){return this.rotateOnAxis(b,a)}}(),rotateY:function(){var b=new a.Vector3(0,1,0);return function(a){return this.rotateOnAxis(b,a)}}(),rotateZ:function(){var b=new a.Vector3(0,0,1);return function(a){return this.rotateOnAxis(b,a)}}(),translateOnAxis:function(){var b=new a.Vector3;return function(a,c){return b.copy(a),b.applyQuaternion(this.quaternion),this.position.add(b.multiplyScalar(c)),this}}(),translate:function(a,b){return console.warn("DEPRECATED: Object3D's .translate() has been removed. Use .translateOnAxis( axis, distance ) instead. Note args have been changed."),this.translateOnAxis(b,a)},translateX:function(){var b=new a.Vector3(1,0,0);return function(a){return this.translateOnAxis(b,a)}}(),translateY:function(){var b=new a.Vector3(0,1,0);return function(a){return this.translateOnAxis(b,a)}}(),translateZ:function(){var b=new a.Vector3(0,0,1);return function(a){return this.translateOnAxis(b,a)}}(),localToWorld:function(a){return a.applyMatrix4(this.matrixWorld)},worldToLocal:function(){var b=new a.Matrix4;return function(a){return a.applyMatrix4(b.getInverse(this.matrixWorld))}}(),lookAt:function(){var b=new a.Matrix4;return function(a){b.lookAt(a,this.position,this.up),this.quaternion.setFromRotationMatrix(b)}}(),add:function(b){if(b===this)return void console.warn("THREE.Object3D.add: An object can't be added as a child of itself.");if(b instanceof a.Object3D){void 0!==b.parent&&b.parent.remove(b),b.parent=this,b.dispatchEvent({type:"added"}),this.children.push(b);for(var c=this;void 0!==c.parent;)c=c.parent;void 0!==c&&c instanceof a.Scene&&c.__addObject(b)}},remove:function(b){var c=this.children.indexOf(b);if(-1!==c){b.parent=void 0,b.dispatchEvent({type:"removed"}),this.children.splice(c,1);for(var d=this;void 0!==d.parent;)d=d.parent;void 0!==d&&d instanceof a.Scene&&d.__removeObject(b)}},traverse:function(a){a(this);for(var b=0,c=this.children.length;c>b;b++)this.children[b].traverse(a)},getObjectById:function(a,b){for(var c=0,d=this.children.length;d>c;c++){var e=this.children[c];if(e.id===a)return e;if(b===!0&&(e=e.getObjectById(a,b),void 0!==e))return e}return void 0},getObjectByName:function(a,b){for(var c=0,d=this.children.length;d>c;c++){var e=this.children[c];if(e.name===a)return e;if(b===!0&&(e=e.getObjectByName(a,b),void 0!==e))return e}return void 0},getChildByName:function(a,b){return console.warn("DEPRECATED: Object3D's .getChildByName() has been renamed to .getObjectByName()."),this.getObjectByName(a,b)},getDescendants:function(a){void 0===a&&(a=[]),Array.prototype.push.apply(a,this.children);for(var b=0,c=this.children.length;c>b;b++)this.children[b].getDescendants(a);return a},updateMatrix:function(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0},updateMatrixWorld:function(a){this.matrixAutoUpdate===!0&&this.updateMatrix(),(this.matrixWorldNeedsUpdate===!0||a===!0)&&(void 0===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1,a=!0);for(var b=0,c=this.children.length;c>b;b++)this.children[b].updateMatrixWorld(a)},clone:function(b,c){if(void 0===b&&(b=new a.Object3D),void 0===c&&(c=!0),b.name=this.name,b.up.copy(this.up),b.position.copy(this.position),b.quaternion.copy(this.quaternion),b.scale.copy(this.scale),b.renderDepth=this.renderDepth,b.rotationAutoUpdate=this.rotationAutoUpdate,b.matrix.copy(this.matrix),b.matrixWorld.copy(this.matrixWorld),b.matrixAutoUpdate=this.matrixAutoUpdate,b.matrixWorldNeedsUpdate=this.matrixWorldNeedsUpdate,b.visible=this.visible,b.castShadow=this.castShadow,b.receiveShadow=this.receiveShadow,b.frustumCulled=this.frustumCulled,b.userData=JSON.parse(JSON.stringify(this.userData)),c===!0)for(var d=0;d=0&&f>=0&&g>=0&&h>=0?!0:0>e&&0>f||0>g&&0>h?!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))),c>d?!1:(a.lerp(b,c),b.lerp(a,1-d),!0))}var i,j,k,l,m,n,o,p,q,r,s,t=[],u=0,v=[],w=0,x=[],y=0,z=[],A=0,B=[],C=0,D={objects:[],lights:[],elements:[]},E=new a.Vector3,F=new a.Vector3,G=new a.Vector3,H=new a.Vector3,I=new a.Vector4,J=new a.Box3(new a.Vector3(-1,-1,-1),new a.Vector3(1,1,1)),K=new a.Box3,L=new Array(3),M=(new Array(4),new a.Matrix4),N=new a.Matrix4,O=new a.Matrix4,P=new a.Matrix3,Q=new a.Frustum,R=new a.Vector4,S=new a.Vector4;this.projectVector=function(a,b){return b.matrixWorldInverse.getInverse(b.matrixWorld),N.multiplyMatrices(b.projectionMatrix,b.matrixWorldInverse),a.applyProjection(N)},this.unprojectVector=function(){var b=new a.Matrix4;return function(a,c){return b.getInverse(c.projectionMatrix),N.multiplyMatrices(c.matrixWorld,b),a.applyProjection(N)}}(),this.pickingRay=function(b,c){b.z=-1;var d=new a.Vector3(b.x,b.y,1);return this.unprojectVector(b,c),this.unprojectVector(d,c),d.sub(b).normalize(),new a.Raycaster(b,d)};var T=function(c){if(c.visible!==!1){c instanceof a.Light?D.lights.push(c):(c instanceof a.Mesh||c instanceof a.Line||c instanceof a.Sprite)&&(c.frustumCulled===!1||Q.intersectsObject(c)===!0)&&(i=b(),i.id=c.id,i.object=c,null!==c.renderDepth?i.z=c.renderDepth:(H.setFromMatrixPosition(c.matrixWorld),H.applyProjection(N),i.z=H.z),D.objects.push(i));for(var d=0,e=c.children.length;e>d;d++)T(c.children[d])}},U=function(a,b){j=0,D.objects.length=0,D.lights.length=0,T(a),b===!0&&D.objects.sort(g)},V=function(){var b=[],f=null,g=new a.Matrix3,h=function(a){f=a,g.getNormalMatrix(f.matrixWorld),b.length=0
+},i=function(a){var b=a.position,c=a.positionWorld,d=a.positionScreen;c.copy(b).applyMatrix4(s),d.copy(c).applyMatrix4(N);var e=1/d.w;d.x*=e,d.y*=e,d.z*=e,a.visible=d.x>=-1&&d.x<=1&&d.y>=-1&&d.y<=1&&d.z>=-1&&d.z<=1},j=function(a,b,d){k=c(),k.position.set(a,b,d),i(k)},l=function(a,c,d){b.push(a,c,d)},n=function(a,b,c){return L[0]=a.positionScreen,L[1]=b.positionScreen,L[2]=c.positionScreen,a.visible===!0||b.visible===!0||c.visible===!0||J.isIntersectionBox(K.setFromPoints(L))?(c.positionScreen.x-a.positionScreen.x)*(b.positionScreen.y-a.positionScreen.y)-(c.positionScreen.y-a.positionScreen.y)*(b.positionScreen.x-a.positionScreen.x)<0:!1},p=function(a,b){var c=v[a],d=v[b];o=e(),o.id=f.id,o.v1.copy(c),o.v2.copy(d),o.z=(c.positionScreen.z+d.positionScreen.z)/2,o.material=f.material,D.elements.push(o)},q=function(a,c,e){var h=v[a],i=v[c],j=v[e];if(n(h,i,j)===!0){m=d(),m.id=f.id,m.v1.copy(h),m.v2.copy(i),m.v3.copy(j),m.z=(h.positionScreen.z+i.positionScreen.z+j.positionScreen.z)/3;for(var k=0;3>k;k++){var l=3*arguments[k],o=m.vertexNormalsModel[k];o.set(b[l+0],b[l+1],b[l+2]),o.applyMatrix3(g).normalize()}m.vertexNormalsLength=3,m.material=f.material,D.elements.push(m)}};return{setObject:h,projectVertex:i,checkTriangleVisibility:n,pushVertex:j,pushNormal:l,pushLine:p,pushTriangle:q}},W=new V;this.projectScene=function(b,i,j,k){var t,u,w,x,y,z,A,B,C,H;n=0,p=0,r=0,D.elements.length=0,b.autoUpdate===!0&&b.updateMatrixWorld(),void 0===i.parent&&i.updateMatrixWorld(),M.copy(i.matrixWorldInverse.getInverse(i.matrixWorld)),N.multiplyMatrices(i.projectionMatrix,M),Q.setFromMatrix(N),U(b,j);for(var J=0,K=D.objects.length;K>J;J++)if(t=D.objects[J].object,u=t.geometry,W.setObject(t),s=t.matrixWorld,l=0,t instanceof a.Mesh){if(u instanceof a.BufferGeometry){var L=u.attributes,T=u.offsets;if(void 0===L.position)continue;for(var V=L.position.array,X=0,Y=V.length;Y>X;X+=3)W.pushVertex(V[X],V[X+1],V[X+2]);for(var Z=L.normal.array,X=0,Y=Z.length;Y>X;X+=3)W.pushNormal(Z[X],Z[X+1],Z[X+2]);if(void 0!==L.index){var $=L.index.array;if(T.length>0)for(var J=0;JX;X+=3)W.pushTriangle($[X]+ab,$[X+1]+ab,$[X+2]+ab);else for(var X=0,Y=$.length;Y>X;X+=3)W.pushTriangle($[X],$[X+1],$[X+2])}else for(var X=0,Y=V.length/3;Y>X;X+=3)W.pushTriangle(X,X+1,X+2)}else if(u instanceof a.Geometry){w=u.vertices,x=u.faces,A=u.faceVertexUvs,P.getNormalMatrix(s),C=t.material instanceof a.MeshFaceMaterial,H=C===!0?t.material:null;for(var bb=0,cb=w.length;cb>bb;bb++){var db=w[bb];W.pushVertex(db.x,db.y,db.z)}for(var eb=0,fb=x.length;fb>eb;eb++){y=x[eb];var gb=C===!0?H.materials[y.materialIndex]:t.material;if(void 0!==gb){var hb=gb.side,ib=v[y.a],jb=v[y.b],kb=v[y.c];if(gb.morphTargets===!0){var lb=u.morphTargets,mb=t.morphTargetInfluences,nb=ib.position,ob=jb.position,pb=kb.position;E.set(0,0,0),F.set(0,0,0),G.set(0,0,0);for(var qb=0,rb=lb.length;rb>qb;qb++){var sb=mb[qb];if(0!==sb){var tb=lb[qb].vertices;E.x+=(tb[y.a].x-nb.x)*sb,E.y+=(tb[y.a].y-nb.y)*sb,E.z+=(tb[y.a].z-nb.z)*sb,F.x+=(tb[y.b].x-ob.x)*sb,F.y+=(tb[y.b].y-ob.y)*sb,F.z+=(tb[y.b].z-ob.z)*sb,G.x+=(tb[y.c].x-pb.x)*sb,G.y+=(tb[y.c].y-pb.y)*sb,G.z+=(tb[y.c].z-pb.z)*sb}}ib.position.add(E),jb.position.add(F),kb.position.add(G),W.projectVertex(ib),W.projectVertex(jb),W.projectVertex(kb)}var ub=W.checkTriangleVisibility(ib,jb,kb);if(!(ub===!1&&hb===a.FrontSide||ub===!0&&hb===a.BackSide)){m=d(),m.id=t.id,m.v1.copy(ib),m.v2.copy(jb),m.v3.copy(kb),m.normalModel.copy(y.normal),ub!==!1||hb!==a.BackSide&&hb!==a.DoubleSide||m.normalModel.negate(),m.normalModel.applyMatrix3(P).normalize(),m.centroidModel.copy(y.centroid).applyMatrix4(s),z=y.vertexNormals;for(var vb=0,wb=Math.min(z.length,3);wb>vb;vb++){var xb=m.vertexNormalsModel[vb];xb.copy(z[vb]),ub!==!1||hb!==a.BackSide&&hb!==a.DoubleSide||xb.negate(),xb.applyMatrix3(P).normalize()}m.vertexNormalsLength=z.length;for(var yb=0,zb=Math.min(A.length,3);zb>yb;yb++)if(B=A[yb][eb],void 0!==B)for(var Ab=0,Bb=B.length;Bb>Ab;Ab++)m.uvs[yb][Ab]=B[Ab];m.color=y.color,m.material=gb,m.z=(ib.positionScreen.z+jb.positionScreen.z+kb.positionScreen.z)/3,D.elements.push(m)}}}}}else if(t instanceof a.Line){if(u instanceof a.BufferGeometry){var L=u.attributes;if(void 0!==L.position){for(var V=L.position.array,X=0,Y=V.length;Y>X;X+=3)W.pushVertex(V[X],V[X+1],V[X+2]);if(void 0!==L.index)for(var $=L.index.array,X=0,Y=$.length;Y>X;X+=2)W.pushLine($[X],$[X+1]);else for(var X=0,Y=V.length/3-1;Y>X;X++)W.pushLine(X,X+1)}}else if(u instanceof a.Geometry){if(O.multiplyMatrices(N,s),w=t.geometry.vertices,0===w.length)continue;ib=c(),ib.positionScreen.copy(w[0]).applyMatrix4(O);for(var Cb=t.type===a.LinePieces?2:1,bb=1,cb=w.length;cb>bb;bb++)ib=c(),ib.positionScreen.copy(w[bb]).applyMatrix4(O),(bb+1)%Cb>0||(jb=v[l-2],R.copy(ib.positionScreen),S.copy(jb.positionScreen),h(R,S)===!0&&(R.multiplyScalar(1/R.w),S.multiplyScalar(1/S.w),o=e(),o.id=t.id,o.v1.positionScreen.copy(R),o.v2.positionScreen.copy(S),o.z=Math.max(R.z,S.z),o.material=t.material,t.material.vertexColors===a.VertexColors&&(o.vertexColors[0].copy(t.geometry.colors[bb]),o.vertexColors[1].copy(t.geometry.colors[bb-1])),D.elements.push(o)))}}else if(t instanceof a.Sprite){I.set(s.elements[12],s.elements[13],s.elements[14],1),I.applyMatrix4(N);var Db=1/I.w;I.z*=Db,I.z>=-1&&I.z<=1&&(q=f(),q.id=t.id,q.x=I.x*Db,q.y=I.y*Db,q.z=I.z,q.object=t,q.rotation=t.rotation,q.scale.x=t.scale.x*Math.abs(q.x-(I.x+i.projectionMatrix.elements[0])/(I.w+i.projectionMatrix.elements[12])),q.scale.y=t.scale.y*Math.abs(q.y-(I.y+i.projectionMatrix.elements[5])/(I.w+i.projectionMatrix.elements[13])),q.material=t.material,D.elements.push(q))}return k===!0&&D.elements.sort(g),D}},a.Face3=function(b,c,d,e,f,g){this.a=b,this.b=c,this.c=d,this.normal=e instanceof a.Vector3?e:new a.Vector3,this.vertexNormals=e instanceof Array?e:[],this.color=f instanceof a.Color?f:new a.Color,this.vertexColors=f instanceof Array?f:[],this.vertexTangents=[],this.materialIndex=void 0!==g?g:0,this.centroid=new a.Vector3},a.Face3.prototype={constructor:a.Face3,clone:function(){var b=new a.Face3(this.a,this.b,this.c);b.normal.copy(this.normal),b.color.copy(this.color),b.centroid.copy(this.centroid),b.materialIndex=this.materialIndex;var c,d;for(c=0,d=this.vertexNormals.length;d>c;c++)b.vertexNormals[c]=this.vertexNormals[c].clone();for(c=0,d=this.vertexColors.length;d>c;c++)b.vertexColors[c]=this.vertexColors[c].clone();for(c=0,d=this.vertexTangents.length;d>c;c++)b.vertexTangents[c]=this.vertexTangents[c].clone();return b}},a.Face4=function(b,c,d,e,f,g,h){return console.warn("THREE.Face4 has been removed. A THREE.Face3 will be created instead."),new a.Face3(b,c,d,f,g,h)},a.BufferGeometry=function(){this.id=a.GeometryIdCount++,this.uuid=a.Math.generateUUID(),this.name="",this.attributes={},this.offsets=[],this.boundingBox=null,this.boundingSphere=null},a.BufferGeometry.prototype={constructor:a.BufferGeometry,addAttribute:function(a,b,c,d){return this.attributes[a]={array:new b(c*d),itemSize:d},this.attributes[a]},applyMatrix:function(b){var c=this.attributes.position;void 0!==c&&(b.multiplyVector3Array(c.array),c.needsUpdate=!0);var d=this.attributes.normal;if(void 0!==d){var e=(new a.Matrix3).getNormalMatrix(b);e.multiplyVector3Array(d.array),d.needsUpdate=!0}},computeBoundingBox:function(){null===this.boundingBox&&(this.boundingBox=new a.Box3);var b=this.attributes.position.array;if(b){var c=this.boundingBox;b.length>=3&&(c.min.x=c.max.x=b[0],c.min.y=c.max.y=b[1],c.min.z=c.max.z=b[2]);for(var d=3,e=b.length;e>d;d+=3){var f=b[d],g=b[d+1],h=b[d+2];fc.max.x&&(c.max.x=f),gc.max.y&&(c.max.y=g),hc.max.z&&(c.max.z=h)}}(void 0===b||0===b.length)&&(this.boundingBox.min.set(0,0,0),this.boundingBox.max.set(0,0,0))},computeBoundingSphere:function(){var b=new a.Box3,c=new a.Vector3;return function(){null===this.boundingSphere&&(this.boundingSphere=new a.Sphere);var d=this.attributes.position.array;if(d){b.makeEmpty();for(var e=this.boundingSphere.center,f=0,g=d.length;g>f;f+=3)c.set(d[f],d[f+1],d[f+2]),b.addPoint(c);b.center(e);for(var h=0,f=0,g=d.length;g>f;f+=3)c.set(d[f],d[f+1],d[f+2]),h=Math.max(h,e.distanceToSquared(c));this.boundingSphere.radius=Math.sqrt(h)}}}(),computeVertexNormals:function(){if(this.attributes.position){var b,c,d,e,f=this.attributes.position.array.length;if(void 0===this.attributes.normal)this.attributes.normal={itemSize:3,array:new Float32Array(f)};else for(b=0,c=this.attributes.normal.array.length;c>b;b++)this.attributes.normal.array[b]=0;var g,h,i,j,k,l,m=this.attributes.position.array,n=this.attributes.normal.array,o=new a.Vector3,p=new a.Vector3,q=new a.Vector3,r=new a.Vector3,s=new a.Vector3;if(this.attributes.index){var t=this.attributes.index.array,u=this.offsets;for(d=0,e=u.length;e>d;++d){var v=u[d].start,w=u[d].count,x=u[d].index;for(b=v,c=v+w;c>b;b+=3)g=x+t[b],h=x+t[b+1],i=x+t[b+2],j=m[3*g],k=m[3*g+1],l=m[3*g+2],o.set(j,k,l),j=m[3*h],k=m[3*h+1],l=m[3*h+2],p.set(j,k,l),j=m[3*i],k=m[3*i+1],l=m[3*i+2],q.set(j,k,l),r.subVectors(q,p),s.subVectors(o,p),r.cross(s),n[3*g]+=r.x,n[3*g+1]+=r.y,n[3*g+2]+=r.z,n[3*h]+=r.x,n[3*h+1]+=r.y,n[3*h+2]+=r.z,n[3*i]+=r.x,n[3*i+1]+=r.y,n[3*i+2]+=r.z}}else for(b=0,c=m.length;c>b;b+=9)j=m[b],k=m[b+1],l=m[b+2],o.set(j,k,l),j=m[b+3],k=m[b+4],l=m[b+5],p.set(j,k,l),j=m[b+6],k=m[b+7],l=m[b+8],q.set(j,k,l),r.subVectors(q,p),s.subVectors(o,p),r.cross(s),n[b]=r.x,n[b+1]=r.y,n[b+2]=r.z,n[b+3]=r.x,n[b+4]=r.y,n[b+5]=r.z,n[b+6]=r.x,n[b+7]=r.y,n[b+8]=r.z;this.normalizeNormals(),this.normalsNeedUpdate=!0}},normalizeNormals:function(){for(var a,b,c,d,e=this.attributes.normal.array,f=0,g=e.length;g>f;f+=3)a=e[f],b=e[f+1],c=e[f+2],d=1/Math.sqrt(a*a+b*b+c*c),e[f]*=d,e[f+1]*=d,e[f+2]*=d},computeTangents:function(){function b(a,b,c){n=e[3*a],o=e[3*a+1],p=e[3*a+2],q=e[3*b],r=e[3*b+1],s=e[3*b+2],t=e[3*c],u=e[3*c+1],v=e[3*c+2],w=g[2*a],x=g[2*a+1],y=g[2*b],z=g[2*b+1],A=g[2*c],B=g[2*c+1],C=q-n,D=t-n,E=r-o,F=u-o,G=s-p,H=v-p,I=y-w,J=A-w,K=z-x,L=B-x,M=1/(I*L-J*K),U.set((L*C-K*D)*M,(L*E-K*F)*M,(L*G-K*H)*M),V.set((I*D-J*C)*M,(I*F-J*E)*M,(I*H-J*G)*M),k[a].add(U),k[b].add(U),k[c].add(U),l[a].add(V),l[b].add(V),l[c].add(V)}function c(a){db.x=f[3*a],db.y=f[3*a+1],db.z=f[3*a+2],eb.copy(db),_=k[a],bb.copy(_),bb.sub(db.multiplyScalar(db.dot(_))).normalize(),cb.crossVectors(eb,_),ab=cb.dot(l[a]),$=0>ab?-1:1,j[4*a]=bb.x,j[4*a+1]=bb.y,j[4*a+2]=bb.z,j[4*a+3]=$}if(void 0===this.attributes.index||void 0===this.attributes.position||void 0===this.attributes.normal||void 0===this.attributes.uv)return void console.warn("Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()");var d=this.attributes.index.array,e=this.attributes.position.array,f=this.attributes.normal.array,g=this.attributes.uv.array,h=e.length/3;if(void 0===this.attributes.tangent){var i=4*h;this.attributes.tangent={itemSize:4,array:new Float32Array(i)}}for(var j=this.attributes.tangent.array,k=[],l=[],m=0;h>m;m++)k[m]=new a.Vector3,l[m]=new a.Vector3;var n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U=new a.Vector3,V=new a.Vector3,W=this.offsets;for(P=0,Q=W.length;Q>P;++P){var X=W[P].start,Y=W[P].count,Z=W[P].index;for(N=X,O=X+Y;O>N;N+=3)R=Z+d[N],S=Z+d[N+1],T=Z+d[N+2],b(R,S,T)}var $,_,ab,bb=new a.Vector3,cb=new a.Vector3,db=new a.Vector3,eb=new a.Vector3;for(P=0,Q=W.length;Q>P;++P){var X=W[P].start,Y=W[P].count,Z=W[P].index;for(N=X,O=X+Y;O>N;N+=3)R=Z+d[N],S=Z+d[N+1],T=Z+d[N+2],c(R),c(S),c(T)}},computeOffsets:function(a){var b=a;void 0===a&&(b=65535);for(var c=(Date.now(),this.attributes.index.array),d=this.attributes.position.array,e=(d.length/3,c.length/3),f=new Uint16Array(c.length),g=0,h=0,i=[{start:0,count:0,index:0}],j=i[0],k=0,l=0,m=new Int32Array(6),n=new Int32Array(d.length),o=new Int32Array(d.length),p=0;pq;q++){l=0;for(var r=0;3>r;r++){var s=c[3*q+r];-1==n[s]?(m[2*r]=s,m[2*r+1]=-1,l++):n[s]j.index+b){var u={start:g,count:0,index:h};i.push(u),j=u;for(var v=0;6>v;v+=2){var w=m[v+1];w>-1&&wv;v+=2){var s=m[v],w=m[v+1];-1===w&&(w=h++),n[s]=w,o[w]=s,f[g++]=w-j.index,j.count++}}return this.reorderBuffers(f,o,h),this.offsets=i,i},reorderBuffers:function(a,b,c){var d={},e=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];for(var f in this.attributes)if("index"!=f)for(var g=this.attributes[f].array,h=0,i=e.length;i>h;h++){var j=e[h];if(g instanceof j){d[f]=new j(this.attributes[f].itemSize*c);break}}for(var k=0;c>k;k++){var l=b[k];for(var f in this.attributes)if("index"!=f)for(var m=this.attributes[f].array,n=this.attributes[f].itemSize,o=d[f],p=0;n>p;p++)o[k*n+p]=m[l*n+p]}this.attributes.index.array=a;for(var f in this.attributes)"index"!=f&&(this.attributes[f].array=d[f],this.attributes[f].numItems=this.attributes[f].itemSize*c)},clone:function(){var b=new a.BufferGeometry,c=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];for(var d in this.attributes){for(var e=this.attributes[d],f=e.array,g={itemSize:e.itemSize,array:null},h=0,i=c.length;i>h;h++){var j=c[h];if(f instanceof j){g.array=new j(f);break}}b.attributes[d]=g}for(var h=0,i=this.offsets.length;i>h;h++){var k=this.offsets[h];b.offsets.push({start:k.start,index:k.index,count:k.count})}return b},dispose:function(){this.dispatchEvent({type:"dispose"})}},a.EventDispatcher.prototype.apply(a.BufferGeometry.prototype),a.Geometry=function(){this.id=a.GeometryIdCount++,this.uuid=a.Math.generateUUID(),this.name="",this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphColors=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.hasTangents=!1,this.dynamic=!0,this.verticesNeedUpdate=!1,this.elementsNeedUpdate=!1,this.uvsNeedUpdate=!1,this.normalsNeedUpdate=!1,this.tangentsNeedUpdate=!1,this.colorsNeedUpdate=!1,this.lineDistancesNeedUpdate=!1,this.buffersNeedUpdate=!1},a.Geometry.prototype={constructor:a.Geometry,applyMatrix:function(b){for(var c=(new a.Matrix3).getNormalMatrix(b),d=0,e=this.vertices.length;e>d;d++){var f=this.vertices[d];f.applyMatrix4(b)}for(var d=0,e=this.faces.length;e>d;d++){var g=this.faces[d];g.normal.applyMatrix3(c).normalize();for(var h=0,i=g.vertexNormals.length;i>h;h++)g.vertexNormals[h].applyMatrix3(c).normalize();g.centroid.applyMatrix4(b)}this.boundingBox instanceof a.Box3&&this.computeBoundingBox(),this.boundingSphere instanceof a.Sphere&&this.computeBoundingSphere()},computeCentroids:function(){var a,b,c;for(a=0,b=this.faces.length;b>a;a++)c=this.faces[a],c.centroid.set(0,0,0),c.centroid.add(this.vertices[c.a]),c.centroid.add(this.vertices[c.b]),c.centroid.add(this.vertices[c.c]),c.centroid.divideScalar(3)},computeFaceNormals:function(){for(var b=new a.Vector3,c=new a.Vector3,d=0,e=this.faces.length;e>d;d++){var f=this.faces[d],g=this.vertices[f.a],h=this.vertices[f.b],i=this.vertices[f.c];b.subVectors(i,h),c.subVectors(g,h),b.cross(c),b.normalize(),f.normal.copy(b)}},computeVertexNormals:function(b){var c,d,e,f,g,h;for(h=new Array(this.vertices.length),c=0,d=this.vertices.length;d>c;c++)h[c]=new a.Vector3;if(b){{var i,j,k,l=new a.Vector3,m=new a.Vector3;new a.Vector3,new a.Vector3,new a.Vector3}for(e=0,f=this.faces.length;f>e;e++)g=this.faces[e],i=this.vertices[g.a],j=this.vertices[g.b],k=this.vertices[g.c],l.subVectors(k,j),m.subVectors(i,j),l.cross(m),h[g.a].add(l),h[g.b].add(l),h[g.c].add(l)}else for(e=0,f=this.faces.length;f>e;e++)g=this.faces[e],h[g.a].add(g.normal),h[g.b].add(g.normal),h[g.c].add(g.normal);for(c=0,d=this.vertices.length;d>c;c++)h[c].normalize();for(e=0,f=this.faces.length;f>e;e++)g=this.faces[e],g.vertexNormals[0]=h[g.a].clone(),g.vertexNormals[1]=h[g.b].clone(),g.vertexNormals[2]=h[g.c].clone()},computeMorphNormals:function(){var b,c,d,e,f;for(d=0,e=this.faces.length;e>d;d++)for(f=this.faces[d],f.__originalFaceNormal?f.__originalFaceNormal.copy(f.normal):f.__originalFaceNormal=f.normal.clone(),f.__originalVertexNormals||(f.__originalVertexNormals=[]),b=0,c=f.vertexNormals.length;c>b;b++)f.__originalVertexNormals[b]?f.__originalVertexNormals[b].copy(f.vertexNormals[b]):f.__originalVertexNormals[b]=f.vertexNormals[b].clone();var g=new a.Geometry;for(g.faces=this.faces,b=0,c=this.morphTargets.length;c>b;b++){if(!this.morphNormals[b]){this.morphNormals[b]={},this.morphNormals[b].faceNormals=[],this.morphNormals[b].vertexNormals=[];var h,i,j=this.morphNormals[b].faceNormals,k=this.morphNormals[b].vertexNormals;for(d=0,e=this.faces.length;e>d;d++)f=this.faces[d],h=new a.Vector3,i={a:new a.Vector3,b:new a.Vector3,c:new a.Vector3},j.push(h),k.push(i)}var l=this.morphNormals[b];g.vertices=this.morphTargets[b].vertices,g.computeFaceNormals(),g.computeVertexNormals();var h,i;for(d=0,e=this.faces.length;e>d;d++)f=this.faces[d],h=l.faceNormals[d],i=l.vertexNormals[d],h.copy(f.normal),i.a.copy(f.vertexNormals[0]),i.b.copy(f.vertexNormals[1]),i.c.copy(f.vertexNormals[2])}for(d=0,e=this.faces.length;e>d;d++)f=this.faces[d],f.normal=f.__originalFaceNormal,f.vertexNormals=f.__originalVertexNormals},computeTangents:function(){function b(a,b,c,d,e,f,g){k=a.vertices[b],l=a.vertices[c],m=a.vertices[d],n=j[e],o=j[f],p=j[g],q=l.x-k.x,r=m.x-k.x,s=l.y-k.y,t=m.y-k.y,u=l.z-k.z,v=m.z-k.z,w=o.x-n.x,x=p.x-n.x,y=o.y-n.y,z=p.y-n.y,A=1/(w*z-x*y),G.set((z*q-y*r)*A,(z*s-y*t)*A,(z*u-y*v)*A),H.set((w*r-x*q)*A,(w*t-x*s)*A,(w*v-x*u)*A),E[b].add(G),E[c].add(G),E[d].add(G),F[b].add(H),F[c].add(H),F[d].add(H)}var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E=[],F=[],G=new a.Vector3,H=new a.Vector3,I=new a.Vector3,J=new a.Vector3,K=new a.Vector3;for(e=0,f=this.vertices.length;f>e;e++)E[e]=new a.Vector3,F[e]=new a.Vector3;for(c=0,d=this.faces.length;d>c;c++)i=this.faces[c],j=this.faceVertexUvs[0][c],b(this,i.a,i.b,i.c,0,1,2);var L=["a","b","c","d"];for(c=0,d=this.faces.length;d>c;c++)for(i=this.faces[c],g=0;gC?-1:1,i.vertexTangents[g]=new a.Vector4(I.x,I.y,I.z,D);this.hasTangents=!0},computeLineDistances:function(){for(var a=0,b=this.vertices,c=0,d=b.length;d>c;c++)c>0&&(a+=b[c].distanceTo(b[c-1])),this.lineDistances[c]=a},computeBoundingBox:function(){null===this.boundingBox&&(this.boundingBox=new a.Box3),this.boundingBox.setFromPoints(this.vertices)},computeBoundingSphere:function(){null===this.boundingSphere&&(this.boundingSphere=new a.Sphere),this.boundingSphere.setFromPoints(this.vertices)},mergeVertices:function(){var a,b,c,d,e,f,g,h,i={},j=[],k=[],l=4,m=Math.pow(10,l);for(c=0,d=this.vertices.length;d>c;c++)a=this.vertices[c],b=Math.round(a.x*m)+"_"+Math.round(a.y*m)+"_"+Math.round(a.z*m),void 0===i[b]?(i[b]=c,j.push(this.vertices[c]),k[c]=j.length-1):k[c]=k[i[b]];var n=[];for(c=0,d=this.faces.length;d>c;c++){e=this.faces[c],e.a=k[e.a],e.b=k[e.b],e.c=k[e.c],f=[e.a,e.b,e.c];for(var o=-1,p=0;3>p;p++)if(f[p]==f[(p+1)%3]){o=p,n.push(c);break}}for(c=n.length-1;c>=0;c--){var q=n[c];for(this.faces.splice(q,1),g=0,h=this.faceVertexUvs.length;h>g;g++)this.faceVertexUvs[g].splice(q,1)}var r=this.vertices.length-j.length;return this.vertices=j,r},makeGroups:function(){var a=0;return function(b){var c,d,e,f,g,h={},i=this.morphTargets.length,j=this.morphNormals.length;for(this.geometryGroups={},c=0,d=this.faces.length;d>c;c++)e=this.faces[c],f=b?e.materialIndex:0,f in h||(h[f]={hash:f,counter:0}),g=h[f].hash+"_"+h[f].counter,g in this.geometryGroups||(this.geometryGroups[g]={faces3:[],materialIndex:f,vertices:0,numMorphTargets:i,numMorphNormals:j}),this.geometryGroups[g].vertices+3>65535&&(h[f].counter+=1,g=h[f].hash+"_"+h[f].counter,g in this.geometryGroups||(this.geometryGroups[g]={faces3:[],materialIndex:f,vertices:0,numMorphTargets:i,numMorphNormals:j})),this.geometryGroups[g].faces3.push(c),this.geometryGroups[g].vertices+=3;this.geometryGroupsList=[];for(var k in this.geometryGroups)this.geometryGroups[k].id=a++,this.geometryGroupsList.push(this.geometryGroups[k])}}(),clone:function(){for(var b=new a.Geometry,c=this.vertices,d=0,e=c.length;e>d;d++)b.vertices.push(c[d].clone());for(var f=this.faces,d=0,e=f.length;e>d;d++)b.faces.push(f[d].clone());for(var g=this.faceVertexUvs[0],d=0,e=g.length;e>d;d++){for(var h=g[d],i=[],j=0,k=h.length;k>j;j++)i.push(new a.Vector2(h[j].x,h[j].y));b.faceVertexUvs[0].push(i)}return b},dispose:function(){this.dispatchEvent({type:"dispose"})}},a.EventDispatcher.prototype.apply(a.Geometry.prototype),a.GeometryIdCount=0,a.Geometry2=function(b){a.BufferGeometry.call(this),this.vertices=this.addAttribute("position",Float32Array,b,3).array,this.normals=this.addAttribute("normal",Float32Array,b,3).array,this.uvs=this.addAttribute("uv",Float32Array,b,2).array,this.boundingBox=null,this.boundingSphere=null},a.Geometry2.prototype=Object.create(a.BufferGeometry.prototype),a.Camera=function(){a.Object3D.call(this),this.matrixWorldInverse=new a.Matrix4,this.projectionMatrix=new a.Matrix4},a.Camera.prototype=Object.create(a.Object3D.prototype),a.Camera.prototype.lookAt=function(){var b=new a.Matrix4;return function(a){b.lookAt(this.position,a,this.up),this.quaternion.setFromRotationMatrix(b)}}(),a.Camera.prototype.clone=function(b){return void 0===b&&(b=new a.Camera),a.Object3D.prototype.clone.call(this,b),b.matrixWorldInverse.copy(this.matrixWorldInverse),b.projectionMatrix.copy(this.projectionMatrix),b},a.OrthographicCamera=function(b,c,d,e,f,g){a.Camera.call(this),this.left=b,this.right=c,this.top=d,this.bottom=e,this.near=void 0!==f?f:.1,this.far=void 0!==g?g:2e3,this.updateProjectionMatrix()},a.OrthographicCamera.prototype=Object.create(a.Camera.prototype),a.OrthographicCamera.prototype.updateProjectionMatrix=function(){this.projectionMatrix.makeOrthographic(this.left,this.right,this.top,this.bottom,this.near,this.far)},a.OrthographicCamera.prototype.clone=function(){var b=new a.OrthographicCamera;return a.Camera.prototype.clone.call(this,b),b.left=this.left,b.right=this.right,b.top=this.top,b.bottom=this.bottom,b.near=this.near,b.far=this.far,b},a.PerspectiveCamera=function(b,c,d,e){a.Camera.call(this),this.fov=void 0!==b?b:50,this.aspect=void 0!==c?c:1,this.near=void 0!==d?d:.1,this.far=void 0!==e?e:2e3,this.updateProjectionMatrix()},a.PerspectiveCamera.prototype=Object.create(a.Camera.prototype),a.PerspectiveCamera.prototype.setLens=function(b,c){void 0===c&&(c=24),this.fov=2*a.Math.radToDeg(Math.atan(c/(2*b))),this.updateProjectionMatrix()},a.PerspectiveCamera.prototype.setViewOffset=function(a,b,c,d,e,f){this.fullWidth=a,this.fullHeight=b,this.x=c,this.y=d,this.width=e,this.height=f,this.updateProjectionMatrix()},a.PerspectiveCamera.prototype.updateProjectionMatrix=function(){if(this.fullWidth){var b=this.fullWidth/this.fullHeight,c=Math.tan(a.Math.degToRad(.5*this.fov))*this.near,d=-c,e=b*d,f=b*c,g=Math.abs(f-e),h=Math.abs(c-d);this.projectionMatrix.makeFrustum(e+this.x*g/this.fullWidth,e+(this.x+this.width)*g/this.fullWidth,c-(this.y+this.height)*h/this.fullHeight,c-this.y*h/this.fullHeight,this.near,this.far)}else this.projectionMatrix.makePerspective(this.fov,this.aspect,this.near,this.far)},a.PerspectiveCamera.prototype.clone=function(){var b=new a.PerspectiveCamera;return a.Camera.prototype.clone.call(this,b),b.fov=this.fov,b.aspect=this.aspect,b.near=this.near,b.far=this.far,b},a.Light=function(b){a.Object3D.call(this),this.color=new a.Color(b)},a.Light.prototype=Object.create(a.Object3D.prototype),a.Light.prototype.clone=function(b){return void 0===b&&(b=new a.Light),a.Object3D.prototype.clone.call(this,b),b.color.copy(this.color),b},a.AmbientLight=function(b){a.Light.call(this,b)},a.AmbientLight.prototype=Object.create(a.Light.prototype),a.AmbientLight.prototype.clone=function(){var b=new a.AmbientLight;return a.Light.prototype.clone.call(this,b),b},a.AreaLight=function(b,c){a.Light.call(this,b),this.normal=new a.Vector3(0,-1,0),this.right=new a.Vector3(1,0,0),this.intensity=void 0!==c?c:1,this.width=1,this.height=1,this.constantAttenuation=1.5,this.linearAttenuation=.5,this.quadraticAttenuation=.1},a.AreaLight.prototype=Object.create(a.Light.prototype),a.DirectionalLight=function(b,c){a.Light.call(this,b),this.position.set(0,1,0),this.target=new a.Object3D,this.intensity=void 0!==c?c:1,this.castShadow=!1,this.onlyShadow=!1,this.shadowCameraNear=50,this.shadowCameraFar=5e3,this.shadowCameraLeft=-500,this.shadowCameraRight=500,this.shadowCameraTop=500,this.shadowCameraBottom=-500,this.shadowCameraVisible=!1,this.shadowBias=0,this.shadowDarkness=.5,this.shadowMapWidth=512,this.shadowMapHeight=512,this.shadowCascade=!1,this.shadowCascadeOffset=new a.Vector3(0,0,-1e3),this.shadowCascadeCount=2,this.shadowCascadeBias=[0,0,0],this.shadowCascadeWidth=[512,512,512],this.shadowCascadeHeight=[512,512,512],this.shadowCascadeNearZ=[-1,.99,.998],this.shadowCascadeFarZ=[.99,.998,1],this.shadowCascadeArray=[],this.shadowMap=null,this.shadowMapSize=null,this.shadowCamera=null,this.shadowMatrix=null},a.DirectionalLight.prototype=Object.create(a.Light.prototype),a.DirectionalLight.prototype.clone=function(){var b=new a.DirectionalLight;return a.Light.prototype.clone.call(this,b),b.target=this.target.clone(),b.intensity=this.intensity,b.castShadow=this.castShadow,b.onlyShadow=this.onlyShadow,b},a.HemisphereLight=function(b,c,d){a.Light.call(this,b),this.position.set(0,100,0),this.groundColor=new a.Color(c),this.intensity=void 0!==d?d:1},a.HemisphereLight.prototype=Object.create(a.Light.prototype),a.HemisphereLight.prototype.clone=function(){var b=new a.HemisphereLight;return a.Light.prototype.clone.call(this,b),b.groundColor.copy(this.groundColor),b.intensity=this.intensity,b},a.PointLight=function(b,c,d){a.Light.call(this,b),this.intensity=void 0!==c?c:1,this.distance=void 0!==d?d:0},a.PointLight.prototype=Object.create(a.Light.prototype),a.PointLight.prototype.clone=function(){var b=new a.PointLight;return a.Light.prototype.clone.call(this,b),b.intensity=this.intensity,b.distance=this.distance,b},a.SpotLight=function(b,c,d,e,f){a.Light.call(this,b),this.position.set(0,1,0),this.target=new a.Object3D,this.intensity=void 0!==c?c:1,this.distance=void 0!==d?d:0,this.angle=void 0!==e?e:Math.PI/3,this.exponent=void 0!==f?f:10,this.castShadow=!1,this.onlyShadow=!1,this.shadowCameraNear=50,this.shadowCameraFar=5e3,this.shadowCameraFov=50,this.shadowCameraVisible=!1,this.shadowBias=0,this.shadowDarkness=.5,this.shadowMapWidth=512,this.shadowMapHeight=512,this.shadowMap=null,this.shadowMapSize=null,this.shadowCamera=null,this.shadowMatrix=null},a.SpotLight.prototype=Object.create(a.Light.prototype),a.SpotLight.prototype.clone=function(){var b=new a.SpotLight;return a.Light.prototype.clone.call(this,b),b.target=this.target.clone(),b.intensity=this.intensity,b.distance=this.distance,b.angle=this.angle,b.exponent=this.exponent,b.castShadow=this.castShadow,b.onlyShadow=this.onlyShadow,b},a.Loader=function(b){this.showStatus=b,this.statusDomElement=b?a.Loader.prototype.addStatusElement():null,this.onLoadStart=function(){},this.onLoadProgress=function(){},this.onLoadComplete=function(){}},a.Loader.prototype={constructor:a.Loader,crossOrigin:void 0,addStatusElement:function(){var a=document.createElement("div");return a.style.position="absolute",a.style.right="0px",a.style.top="0px",a.style.fontSize="0.8em",a.style.textAlign="left",a.style.background="rgba(0,0,0,0.25)",a.style.color="#fff",a.style.width="120px",a.style.padding="0.5em 0.5em 0.5em 0.5em",a.style.zIndex=1e3,a.innerHTML="Loading ...",a},updateProgress:function(a){var b="Loaded ";b+=a.total?(100*a.loaded/a.total).toFixed(0)+"%":(a.loaded/1e3).toFixed(2)+" KB",this.statusDomElement.innerHTML=b},extractUrlBase:function(a){var b=a.split("/");return 1===b.length?"./":(b.pop(),b.join("/")+"/")},initMaterials:function(b,c){for(var d=[],e=0;ec;c++){var e=b[c];if(e instanceof a.ShaderMaterial)return!0}return!1},createMaterial:function(b,c){function d(a){var b=Math.log(a)/Math.LN2;return Math.floor(b)==b}function e(a){var b=Math.log(a)/Math.LN2;return Math.pow(2,Math.round(b))}function f(a,b){var c=new Image;c.onload=function(){if(d(this.width)&&d(this.height))a.image=this;else{var b=e(this.width),c=e(this.height);a.image.width=b,a.image.height=c,a.image.getContext("2d").drawImage(this,0,0,b,c)}a.needsUpdate=!0},void 0!==i.crossOrigin&&(c.crossOrigin=i.crossOrigin),c.src=b}function g(b,d,e,g,h,i,j){var k=/\.dds$/i.test(e),l=c+e;if(k){var m=a.ImageUtils.loadCompressedTexture(l);b[d]=m}else{var m=document.createElement("canvas");b[d]=new a.Texture(m)}if(b[d].sourceFile=e,g&&(b[d].repeat.set(g[0],g[1]),1!==g[0]&&(b[d].wrapS=a.RepeatWrapping),1!==g[1]&&(b[d].wrapT=a.RepeatWrapping)),h&&b[d].offset.set(h[0],h[1]),i){var n={repeat:a.RepeatWrapping,mirror:a.MirroredRepeatWrapping};void 0!==n[i[0]]&&(b[d].wrapS=n[i[0]]),void 0!==n[i[1]]&&(b[d].wrapT=n[i[1]])}j&&(b[d].anisotropy=j),k||f(b[d],l)}function h(a){return(255*a[0]<<16)+(255*a[1]<<8)+255*a[2]}var i=this,j="MeshLambertMaterial",k={color:15658734,opacity:1,map:null,lightMap:null,normalMap:null,bumpMap:null,wireframe:!1};if(b.shading){var l=b.shading.toLowerCase();"phong"===l?j="MeshPhongMaterial":"basic"===l&&(j="MeshBasicMaterial")}if(void 0!==b.blending&&void 0!==a[b.blending]&&(k.blending=a[b.blending]),(void 0!==b.transparent||b.opacity<1)&&(k.transparent=b.transparent),void 0!==b.depthTest&&(k.depthTest=b.depthTest),void 0!==b.depthWrite&&(k.depthWrite=b.depthWrite),void 0!==b.visible&&(k.visible=b.visible),void 0!==b.flipSided&&(k.side=a.BackSide),void 0!==b.doubleSided&&(k.side=a.DoubleSide),void 0!==b.wireframe&&(k.wireframe=b.wireframe),void 0!==b.vertexColors&&("face"===b.vertexColors?k.vertexColors=a.FaceColors:b.vertexColors&&(k.vertexColors=a.VertexColors)),b.colorDiffuse?k.color=h(b.colorDiffuse):b.DbgColor&&(k.color=b.DbgColor),b.colorSpecular&&(k.specular=h(b.colorSpecular)),b.colorAmbient&&(k.ambient=h(b.colorAmbient)),b.transparency&&(k.opacity=b.transparency),b.specularCoef&&(k.shininess=b.specularCoef),b.mapDiffuse&&c&&g(k,"map",b.mapDiffuse,b.mapDiffuseRepeat,b.mapDiffuseOffset,b.mapDiffuseWrap,b.mapDiffuseAnisotropy),b.mapLight&&c&&g(k,"lightMap",b.mapLight,b.mapLightRepeat,b.mapLightOffset,b.mapLightWrap,b.mapLightAnisotropy),b.mapBump&&c&&g(k,"bumpMap",b.mapBump,b.mapBumpRepeat,b.mapBumpOffset,b.mapBumpWrap,b.mapBumpAnisotropy),b.mapNormal&&c&&g(k,"normalMap",b.mapNormal,b.mapNormalRepeat,b.mapNormalOffset,b.mapNormalWrap,b.mapNormalAnisotropy),b.mapSpecular&&c&&g(k,"specularMap",b.mapSpecular,b.mapSpecularRepeat,b.mapSpecularOffset,b.mapSpecularWrap,b.mapSpecularAnisotropy),b.mapBumpScale&&(k.bumpScale=b.mapBumpScale),b.mapNormal){var m=a.ShaderLib.normalmap,n=a.UniformsUtils.clone(m.uniforms);n.tNormal.value=k.normalMap,b.mapNormalFactor&&n.uNormalScale.value.set(b.mapNormalFactor,b.mapNormalFactor),k.map&&(n.tDiffuse.value=k.map,n.enableDiffuse.value=!0),k.specularMap&&(n.tSpecular.value=k.specularMap,n.enableSpecular.value=!0),k.lightMap&&(n.tAO.value=k.lightMap,n.enableAO.value=!0),n.diffuse.value.setHex(k.color),n.specular.value.setHex(k.specular),n.ambient.value.setHex(k.ambient),n.shininess.value=k.shininess,void 0!==k.opacity&&(n.opacity.value=k.opacity);var o={fragmentShader:m.fragmentShader,vertexShader:m.vertexShader,uniforms:n,lights:!0,fog:!0},p=new a.ShaderMaterial(o);k.transparent&&(p.transparent=!0)}else var p=new a[j](k);return void 0!==b.DbgName&&(p.name=b.DbgName),p}},a.XHRLoader=function(b){this.manager=void 0!==b?b:a.DefaultLoadingManager},a.XHRLoader.prototype={constructor:a.XHRLoader,load:function(a,b,c,d){var e=this,f=new XMLHttpRequest;void 0!==b&&f.addEventListener("load",function(c){b(c.target.responseText),e.manager.itemEnd(a)
+},!1),void 0!==c&&f.addEventListener("progress",function(a){c(a)},!1),void 0!==d&&f.addEventListener("error",function(a){d(a)},!1),void 0!==this.crossOrigin&&(f.crossOrigin=this.crossOrigin),f.open("GET",a,!0),f.send(null),e.manager.itemStart(a)},setCrossOrigin:function(a){this.crossOrigin=a}},a.ImageLoader=function(b){this.manager=void 0!==b?b:a.DefaultLoadingManager},a.ImageLoader.prototype={constructor:a.ImageLoader,load:function(a,b,c,d){var e=this,f=document.createElement("img");return void 0!==b&&f.addEventListener("load",function(){e.manager.itemEnd(a),b(this)},!1),void 0!==c&&f.addEventListener("progress",function(a){c(a)},!1),void 0!==d&&f.addEventListener("error",function(a){d(a)},!1),void 0!==this.crossOrigin&&(f.crossOrigin=this.crossOrigin),f.src=a,e.manager.itemStart(a),f},setCrossOrigin:function(a){this.crossOrigin=a}},a.JSONLoader=function(b){a.Loader.call(this,b),this.withCredentials=!1},a.JSONLoader.prototype=Object.create(a.Loader.prototype),a.JSONLoader.prototype.load=function(a,b,c){c=c&&"string"==typeof c?c:this.extractUrlBase(a),this.onLoadStart(),this.loadAjaxJSON(this,a,b,c)},a.JSONLoader.prototype.loadAjaxJSON=function(a,b,c,d,e){var f=new XMLHttpRequest,g=0;f.onreadystatechange=function(){if(f.readyState===f.DONE)if(200===f.status||0===f.status){if(f.responseText){var h=JSON.parse(f.responseText);if("scene"===h.metadata.type)return void console.error('THREE.JSONLoader: "'+b+'" seems to be a Scene. Use THREE.SceneLoader instead.');var i=a.parse(h,d);c(i.geometry,i.materials)}else console.error('THREE.JSONLoader: "'+b+'" seems to be unreachable or the file is empty.');a.onLoadComplete()}else console.error("THREE.JSONLoader: Couldn't load \""+b+'" ('+f.status+")");else f.readyState===f.LOADING?e&&(0===g&&(g=f.getResponseHeader("Content-Length")),e({total:g,loaded:f.responseText.length})):f.readyState===f.HEADERS_RECEIVED&&void 0!==e&&(g=f.getResponseHeader("Content-Length"))},f.open("GET",b,!0),f.withCredentials=this.withCredentials,f.send(null)},a.JSONLoader.prototype.parse=function(b,c){function d(c){function d(a,b){return a&1<e;e++)g.faceVertexUvs[e]=[]}for(i=0,j=H.length;j>i;)w=new a.Vector3,w.x=H[i++]*c,w.y=H[i++]*c,w.z=H[i++]*c,g.vertices.push(w);for(i=0,j=G.length;j>i;)if(o=G[i++],p=d(o,0),q=d(o,1),r=d(o,3),s=d(o,4),t=d(o,5),u=d(o,6),v=d(o,7),p){if(y=new a.Face3,y.a=G[i],y.b=G[i+1],y.c=G[i+3],z=new a.Face3,z.a=G[i+1],z.b=G[i+2],z.c=G[i+3],i+=4,q&&(n=G[i++],y.materialIndex=n,z.materialIndex=n),h=g.faces.length,r)for(e=0;K>e;e++)for(C=b.uvs[e],g.faceVertexUvs[e][h]=[],g.faceVertexUvs[e][h+1]=[],f=0;4>f;f++)m=G[i++],E=C[2*m],F=C[2*m+1],D=new a.Vector2(E,F),2!==f&&g.faceVertexUvs[e][h].push(D),0!==f&&g.faceVertexUvs[e][h+1].push(D);if(s&&(l=3*G[i++],y.normal.set(I[l++],I[l++],I[l]),z.normal.copy(y.normal)),t)for(e=0;4>e;e++)l=3*G[i++],B=new a.Vector3(I[l++],I[l++],I[l]),2!==e&&y.vertexNormals.push(B),0!==e&&z.vertexNormals.push(B);if(u&&(k=G[i++],A=J[k],y.color.setHex(A),z.color.setHex(A)),v)for(e=0;4>e;e++)k=G[i++],A=J[k],2!==e&&y.vertexColors.push(new a.Color(A)),0!==e&&z.vertexColors.push(new a.Color(A));g.faces.push(y),g.faces.push(z)}else{if(x=new a.Face3,x.a=G[i++],x.b=G[i++],x.c=G[i++],q&&(n=G[i++],x.materialIndex=n),h=g.faces.length,r)for(e=0;K>e;e++)for(C=b.uvs[e],g.faceVertexUvs[e][h]=[],f=0;3>f;f++)m=G[i++],E=C[2*m],F=C[2*m+1],D=new a.Vector2(E,F),g.faceVertexUvs[e][h].push(D);if(s&&(l=3*G[i++],x.normal.set(I[l++],I[l++],I[l])),t)for(e=0;3>e;e++)l=3*G[i++],B=new a.Vector3(I[l++],I[l++],I[l]),x.vertexNormals.push(B);if(u&&(k=G[i++],x.color.setHex(J[k])),v)for(e=0;3>e;e++)k=G[i++],x.vertexColors.push(new a.Color(J[k]));g.faces.push(x)}}function e(){if(b.skinWeights)for(var c=0,d=b.skinWeights.length;d>c;c+=2){var e=b.skinWeights[c],f=b.skinWeights[c+1],h=0,i=0;g.skinWeights.push(new a.Vector4(e,f,h,i))}if(b.skinIndices)for(var c=0,d=b.skinIndices.length;d>c;c+=2){var j=b.skinIndices[c],k=b.skinIndices[c+1],l=0,m=0;g.skinIndices.push(new a.Vector4(j,k,l,m))}g.bones=b.bones,g.bones&&g.bones.length>0&&(g.skinWeights.length!==g.skinIndices.length||g.skinIndices.length!==g.vertices.length)&&console.warn("When skinning, number of vertices ("+g.vertices.length+"), skinIndices ("+g.skinIndices.length+"), and skinWeights ("+g.skinWeights.length+") should match."),g.animation=b.animation,g.animations=b.animations}function f(c){if(void 0!==b.morphTargets){var d,e,f,h,i,j;for(d=0,e=b.morphTargets.length;e>d;d++)for(g.morphTargets[d]={},g.morphTargets[d].name=b.morphTargets[d].name,g.morphTargets[d].vertices=[],i=g.morphTargets[d].vertices,j=b.morphTargets[d].vertices,f=0,h=j.length;h>f;f+=3){var k=new a.Vector3;k.x=j[f]*c,k.y=j[f+1]*c,k.z=j[f+2]*c,i.push(k)}}if(void 0!==b.morphColors){var d,e,l,m,n,o,p;for(d=0,e=b.morphColors.length;e>d;d++)for(g.morphColors[d]={},g.morphColors[d].name=b.morphColors[d].name,g.morphColors[d].colors=[],n=g.morphColors[d].colors,o=b.morphColors[d].colors,l=0,m=o.length;m>l;l+=3)p=new a.Color(16755200),p.setRGB(o[l],o[l+1],o[l+2]),n.push(p)}}var g=new a.Geometry,h=void 0!==b.scale?1/b.scale:1;if(d(h),e(),f(h),g.computeCentroids(),g.computeFaceNormals(),g.computeBoundingSphere(),void 0===b.materials)return{geometry:g};var i=this.initMaterials(b.materials,c);return this.needsTangents(i)&&g.computeTangents(),{geometry:g,materials:i}},a.LoadingManager=function(a,b,c){var d=this,e=0,f=0;this.onLoad=a,this.onProgress=b,this.onError=c,this.itemStart=function(){f++},this.itemEnd=function(a){e++,void 0!==d.onProgress&&d.onProgress(a,e,f),e===f&&void 0!==d.onLoad&&d.onLoad()}},a.DefaultLoadingManager=new a.LoadingManager,a.BufferGeometryLoader=function(b){this.manager=void 0!==b?b:a.DefaultLoadingManager},a.BufferGeometryLoader.prototype={constructor:a.BufferGeometryLoader,load:function(b,c){var d=this,e=new a.XHRLoader;e.setCrossOrigin(this.crossOrigin),e.load(b,function(a){c(d.parse(JSON.parse(a)))})},setCrossOrigin:function(a){this.crossOrigin=a},parse:function(b){var c=new a.BufferGeometry,d=b.attributes,e=b.offsets,f=b.boundingSphere;for(var g in d){var h=d[g];c.attributes[g]={itemSize:h.itemSize,array:new self[h.type](h.array)}}return void 0!==e&&(c.offsets=JSON.parse(JSON.stringify(e))),void 0!==f&&(c.boundingSphere=new a.Sphere((new a.Vector3).fromArray(void 0!==f.center?f.center:[0,0,0]),f.radius)),c}},a.Geometry2Loader=function(b){this.manager=void 0!==b?b:a.DefaultLoadingManager},a.Geometry2Loader.prototype={constructor:a.Geometry2Loader,load:function(b,c){var d=this,e=new a.XHRLoader;e.setCrossOrigin(this.crossOrigin),e.load(b,function(a){c(d.parse(JSON.parse(a)))})},setCrossOrigin:function(a){this.crossOrigin=a},parse:function(b){var c=new a.Geometry2(b.vertices.length/3),d=["vertices","normals","uvs"],e=b.boundingSphere;for(var f in d){var g=d[f];c[g].set(b[g])}return void 0!==e&&(c.boundingSphere=new a.Sphere((new a.Vector3).fromArray(void 0!==e.center?e.center:[0,0,0]),e.radius)),c}},a.MaterialLoader=function(b){this.manager=void 0!==b?b:a.DefaultLoadingManager},a.MaterialLoader.prototype={constructor:a.MaterialLoader,load:function(b,c){var d=this,e=new a.XHRLoader;e.setCrossOrigin(this.crossOrigin),e.load(b,function(a){c(d.parse(JSON.parse(a)))})},setCrossOrigin:function(a){this.crossOrigin=a},parse:function(b){var c=new a[b.type];if(void 0!==b.color&&c.color.setHex(b.color),void 0!==b.ambient&&c.ambient.setHex(b.ambient),void 0!==b.emissive&&c.emissive.setHex(b.emissive),void 0!==b.specular&&c.specular.setHex(b.specular),void 0!==b.shininess&&(c.shininess=b.shininess),void 0!==b.vertexColors&&(c.vertexColors=b.vertexColors),void 0!==b.blending&&(c.blending=b.blending),void 0!==b.side&&(c.side=b.side),void 0!==b.opacity&&(c.opacity=b.opacity),void 0!==b.transparent&&(c.transparent=b.transparent),void 0!==b.wireframe&&(c.wireframe=b.wireframe),void 0!==b.materials)for(var d=0,e=b.materials.length;e>d;d++)c.materials.push(this.parse(b.materials[d]));return c}},a.ObjectLoader=function(b){this.manager=void 0!==b?b:a.DefaultLoadingManager},a.ObjectLoader.prototype={constructor:a.ObjectLoader,load:function(b,c){var d=this,e=new a.XHRLoader(d.manager);e.setCrossOrigin(this.crossOrigin),e.load(b,function(a){c(d.parse(JSON.parse(a)))})},setCrossOrigin:function(a){this.crossOrigin=a},parse:function(a){var b=this.parseGeometries(a.geometries),c=this.parseMaterials(a.materials),d=this.parseObject(a.object,b,c);return d},parseGeometries:function(b){var c={};if(void 0!==b)for(var d=new a.JSONLoader,e=new a.Geometry2Loader,f=new a.BufferGeometryLoader,g=0,h=b.length;h>g;g++){var i,j=b[g];switch(j.type){case"PlaneGeometry":i=new a.PlaneGeometry(j.width,j.height,j.widthSegments,j.heightSegments);break;case"BoxGeometry":case"CubeGeometry":i=new a.BoxGeometry(j.width,j.height,j.depth,j.widthSegments,j.heightSegments,j.depthSegments);break;case"CircleGeometry":i=new a.CircleGeometry(j.radius,j.segments);break;case"CylinderGeometry":i=new a.CylinderGeometry(j.radiusTop,j.radiusBottom,j.height,j.radialSegments,j.heightSegments,j.openEnded);break;case"SphereGeometry":i=new a.SphereGeometry(j.radius,j.widthSegments,j.heightSegments,j.phiStart,j.phiLength,j.thetaStart,j.thetaLength);break;case"IcosahedronGeometry":i=new a.IcosahedronGeometry(j.radius,j.detail);break;case"TorusGeometry":i=new a.TorusGeometry(j.radius,j.tube,j.radialSegments,j.tubularSegments,j.arc);break;case"TorusKnotGeometry":i=new a.TorusKnotGeometry(j.radius,j.tube,j.radialSegments,j.tubularSegments,j.p,j.q,j.heightScale);break;case"BufferGeometry":i=f.parse(j.data);break;case"Geometry2":i=e.parse(j.data);break;case"Geometry":i=d.parse(j.data).geometry}i.uuid=j.uuid,void 0!==j.name&&(i.name=j.name),c[j.uuid]=i}return c},parseMaterials:function(b){var c={};if(void 0!==b)for(var d=new a.MaterialLoader,e=0,f=b.length;f>e;e++){var g=b[e],h=d.parse(g);h.uuid=g.uuid,void 0!==g.name&&(h.name=g.name),c[g.uuid]=h}return c},parseObject:function(){var b=new a.Matrix4;return function(c,d,e){var f;switch(c.type){case"Scene":f=new a.Scene;break;case"PerspectiveCamera":f=new a.PerspectiveCamera(c.fov,c.aspect,c.near,c.far);break;case"OrthographicCamera":f=new a.OrthographicCamera(c.left,c.right,c.top,c.bottom,c.near,c.far);break;case"AmbientLight":f=new a.AmbientLight(c.color);break;case"DirectionalLight":f=new a.DirectionalLight(c.color,c.intensity);break;case"PointLight":f=new a.PointLight(c.color,c.intensity,c.distance);break;case"SpotLight":f=new a.SpotLight(c.color,c.intensity,c.distance,c.angle,c.exponent);break;case"HemisphereLight":f=new a.HemisphereLight(c.color,c.groundColor,c.intensity);break;case"Mesh":var g=d[c.geometry],h=e[c.material];void 0===g&&console.error("THREE.ObjectLoader: Undefined geometry "+c.geometry),void 0===h&&console.error("THREE.ObjectLoader: Undefined material "+c.material),f=new a.Mesh(g,h);break;case"Sprite":var h=e[c.material];void 0===h&&console.error("THREE.ObjectLoader: Undefined material "+c.material),f=new a.Sprite(h);break;default:f=new a.Object3D}if(f.uuid=c.uuid,void 0!==c.name&&(f.name=c.name),void 0!==c.matrix?(b.fromArray(c.matrix),b.decompose(f.position,f.quaternion,f.scale)):(void 0!==c.position&&f.position.fromArray(c.position),void 0!==c.rotation&&f.rotation.fromArray(c.rotation),void 0!==c.scale&&f.scale.fromArray(c.scale)),void 0!==c.visible&&(f.visible=c.visible),void 0!==c.userData&&(f.userData=c.userData),void 0!==c.children)for(var i in c.children)f.add(this.parseObject(c.children[i],d,e));return f}}()},a.SceneLoader=function(){this.onLoadStart=function(){},this.onLoadProgress=function(){},this.onLoadComplete=function(){},this.callbackSync=function(){},this.callbackProgress=function(){},this.geometryHandlers={},this.hierarchyHandlers={},this.addGeometryHandler("ascii",a.JSONLoader)},a.SceneLoader.prototype={constructor:a.SceneLoader,load:function(b,c){var d=this,e=new a.XHRLoader(d.manager);e.setCrossOrigin(this.crossOrigin),e.load(b,function(a){d.parse(JSON.parse(a),c,b)})},setCrossOrigin:function(a){this.crossOrigin=a},addGeometryHandler:function(a,b){this.geometryHandlers[a]={loaderClass:b}},addHierarchyHandler:function(a,b){this.hierarchyHandlers[a]={loaderClass:b}},parse:function(b,c,d){function e(a,b){return"relativeToHTML"==b?a:C+a}function f(){g(A.scene,E.objects)}function g(b,c){var d,f,h,i,j;for(var l in c){var m=A.objects[l],n=c[l];if(void 0===m){if(n.type&&n.type in B.hierarchyHandlers){if(void 0===n.loading){var o={type:1,url:1,material:1,position:1,rotation:1,scale:1,visible:1,children:1,userData:1,skin:1,morph:1,mirroredLoop:1,duration:1},s={};for(var t in n)t in o||(s[t]=n[t]);q=A.materials[n.material],n.loading=!0;var u=B.hierarchyHandlers[n.type].loaderObject;u.options?u.load(e(n.url,E.urlBaseType),k(l,b,q,n)):u.load(e(n.url,E.urlBaseType),k(l,b,q,n),s)}}else if(void 0!==n.geometry){if(p=A.geometries[n.geometry]){var w=!1;if(q=A.materials[n.material],w=q instanceof a.ShaderMaterial,f=n.position,h=n.rotation,i=n.scale,d=n.matrix,j=n.quaternion,n.material||(q=new a.MeshFaceMaterial(A.face_materials[n.geometry])),q instanceof a.MeshFaceMaterial&&0===q.materials.length&&(q=new a.MeshFaceMaterial(A.face_materials[n.geometry])),q instanceof a.MeshFaceMaterial)for(var x=0;xbb;bb++)ab[bb]=e(Z.url[bb],E.urlBaseType);var cb=/\.dds$/i.test(ab[0]);t=cb?a.ImageUtils.loadCompressedTextureCube(ab,Z.mapping,N(_)):a.ImageUtils.loadTextureCube(ab,Z.mapping,N(_))}else{var cb=/\.dds$/i.test(Z.url),db=e(Z.url,E.urlBaseType),eb=N(1);if(t=cb?a.ImageUtils.loadCompressedTexture(db,Z.mapping,eb):a.ImageUtils.loadTexture(db,Z.mapping,eb),void 0!==a[Z.minFilter]&&(t.minFilter=a[Z.minFilter]),void 0!==a[Z.magFilter]&&(t.magFilter=a[Z.magFilter]),Z.anisotropy&&(t.anisotropy=Z.anisotropy),Z.repeat&&(t.repeat.set(Z.repeat[0],Z.repeat[1]),1!==Z.repeat[0]&&(t.wrapS=a.RepeatWrapping),1!==Z.repeat[1]&&(t.wrapT=a.RepeatWrapping)),Z.offset&&t.offset.set(Z.offset[0],Z.offset[1]),Z.wrap){var fb={repeat:a.RepeatWrapping,mirror:a.MirroredRepeatWrapping};void 0!==fb[Z.wrap[0]]&&(t.wrapS=fb[Z.wrap[0]]),void 0!==fb[Z.wrap[1]]&&(t.wrapT=fb[Z.wrap[1]])}}A.textures[Y]=t}var gb,hb,ib;for(gb in E.materials){hb=E.materials[gb];for(ib in hb.parameters)if("envMap"===ib||"map"===ib||"lightMap"===ib||"bumpMap"===ib)hb.parameters[ib]=A.textures[hb.parameters[ib]];else if("shading"===ib)hb.parameters[ib]="flat"===hb.parameters[ib]?a.FlatShading:a.SmoothShading;else if("side"===ib)hb.parameters[ib]="double"==hb.parameters[ib]?a.DoubleSide:"back"==hb.parameters[ib]?a.BackSide:a.FrontSide;else if("blending"===ib)hb.parameters[ib]=hb.parameters[ib]in a?a[hb.parameters[ib]]:a.NormalBlending;else if("combine"===ib)hb.parameters[ib]=hb.parameters[ib]in a?a[hb.parameters[ib]]:a.MultiplyOperation;else if("vertexColors"===ib)"face"==hb.parameters[ib]?hb.parameters[ib]=a.FaceColors:hb.parameters[ib]&&(hb.parameters[ib]=a.VertexColors);else if("wrapRGB"===ib){var jb=hb.parameters[ib];hb.parameters[ib]=new a.Vector3(jb[0],jb[1],jb[2])}if(void 0!==hb.parameters.opacity&&hb.parameters.opacity<1&&(hb.parameters.transparent=!0),hb.parameters.normalMap){var kb=a.ShaderLib.normalmap,lb=a.UniformsUtils.clone(kb.uniforms),mb=hb.parameters.color,nb=hb.parameters.specular,ob=hb.parameters.ambient,pb=hb.parameters.shininess;lb.tNormal.value=A.textures[hb.parameters.normalMap],hb.parameters.normalScale&&lb.uNormalScale.value.set(hb.parameters.normalScale[0],hb.parameters.normalScale[1]),hb.parameters.map&&(lb.tDiffuse.value=hb.parameters.map,lb.enableDiffuse.value=!0),hb.parameters.envMap&&(lb.tCube.value=hb.parameters.envMap,lb.enableReflection.value=!0,lb.reflectivity.value=hb.parameters.reflectivity),hb.parameters.lightMap&&(lb.tAO.value=hb.parameters.lightMap,lb.enableAO.value=!0),hb.parameters.specularMap&&(lb.tSpecular.value=A.textures[hb.parameters.specularMap],lb.enableSpecular.value=!0),hb.parameters.displacementMap&&(lb.tDisplacement.value=A.textures[hb.parameters.displacementMap],lb.enableDisplacement.value=!0,lb.uDisplacementBias.value=hb.parameters.displacementBias,lb.uDisplacementScale.value=hb.parameters.displacementScale),lb.diffuse.value.setHex(mb),lb.specular.value.setHex(nb),lb.ambient.value.setHex(ob),lb.shininess.value=pb,hb.parameters.opacity&&(lb.opacity.value=hb.parameters.opacity);var qb={fragmentShader:kb.fragmentShader,vertexShader:kb.vertexShader,uniforms:lb,lights:!0,fog:!0};q=new a.ShaderMaterial(qb)}else q=new a[hb.type](hb.parameters);q.name=gb,A.materials[gb]=q}for(gb in E.materials)if(hb=E.materials[gb],hb.parameters.materials){for(var rb=[],bb=0;bb0){this.morphTargetBase=-1,this.morphTargetForcedOrder=[],this.morphTargetInfluences=[],this.morphTargetDictionary={};for(var a=0,b=this.geometry.morphTargets.length;b>a;a++)this.morphTargetInfluences.push(0),this.morphTargetDictionary[this.geometry.morphTargets[a].name]=a}},a.Mesh.prototype.getMorphTargetIndexByName=function(a){return void 0!==this.morphTargetDictionary[a]?this.morphTargetDictionary[a]:(console.log("THREE.Mesh.getMorphTargetIndexByName: morph target "+a+" does not exist. Returning 0."),0)},a.Mesh.prototype.clone=function(b){return void 0===b&&(b=new a.Mesh(this.geometry,this.material)),a.Object3D.prototype.clone.call(this,b),b},a.Bone=function(b){a.Object3D.call(this),this.skin=b,this.skinMatrix=new a.Matrix4},a.Bone.prototype=Object.create(a.Object3D.prototype),a.Bone.prototype.update=function(a,b){this.matrixAutoUpdate&&(b|=this.updateMatrix()),(b||this.matrixWorldNeedsUpdate)&&(a?this.skinMatrix.multiplyMatrices(a,this.matrix):this.skinMatrix.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,b=!0);var c,d=this.children.length;for(c=0;d>c;c++)this.children[c].update(this.skinMatrix,b)},a.SkinnedMesh=function(b,c,d){a.Mesh.call(this,b,c),this.useVertexTexture=void 0!==d?d:!0,this.identityMatrix=new a.Matrix4,this.bones=[],this.boneMatrices=[];var e,f,g,h,i,j;if(this.geometry&&void 0!==this.geometry.bones){for(e=0;e256?64:k>64?32:k>16?16:8,this.boneTextureWidth=l,this.boneTextureHeight=l,this.boneMatrices=new Float32Array(this.boneTextureWidth*this.boneTextureHeight*4),this.boneTexture=new a.DataTexture(this.boneMatrices,this.boneTextureWidth,this.boneTextureHeight,a.RGBAFormat,a.FloatType),this.boneTexture.minFilter=a.NearestFilter,this.boneTexture.magFilter=a.NearestFilter,this.boneTexture.generateMipmaps=!1,this.boneTexture.flipY=!1}else this.boneMatrices=new Float32Array(16*k);this.pose()}},a.SkinnedMesh.prototype=Object.create(a.Mesh.prototype),a.SkinnedMesh.prototype.addBone=function(b){return void 0===b&&(b=new a.Bone(this)),this.bones.push(b),b},a.SkinnedMesh.prototype.updateMatrixWorld=function(){var b=new a.Matrix4;return function(c){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||c)&&(this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,c=!0);for(var d=0,e=this.children.length;e>d;d++){var f=this.children[d];f instanceof a.Bone?f.update(this.identityMatrix,!1):f.updateMatrixWorld(!0)}if(void 0==this.boneInverses){this.boneInverses=[];for(var g=0,h=this.bones.length;h>g;g++){var i=new a.Matrix4;i.getInverse(this.bones[g].skinMatrix),this.boneInverses.push(i)}}for(var g=0,h=this.bones.length;h>g;g++)b.multiplyMatrices(this.bones[g].skinMatrix,this.boneInverses[g]),b.flattenToArrayOffset(this.boneMatrices,16*g);this.useVertexTexture&&(this.boneTexture.needsUpdate=!0)}}(),a.SkinnedMesh.prototype.pose=function(){this.updateMatrixWorld(!0),this.normalizeSkinWeights()},a.SkinnedMesh.prototype.normalizeSkinWeights=function(){if(this.geometry instanceof a.Geometry)for(var b=0;be;e++){var g=a.morphTargets[e],h=g.name.match(d);if(h&&h.length>1){{var i=h[1];h[2]}c[i]||(c[i]={start:1/0,end:-1/0});var j=c[i];ej.end&&(j.end=e),b||(b=i)}}a.firstAnimation=b},a.MorphAnimMesh.prototype.setAnimationLabel=function(a,b,c){this.geometry.animations||(this.geometry.animations={}),this.geometry.animations[a]={start:b,end:c}},a.MorphAnimMesh.prototype.playAnimation=function(a,b){var c=this.geometry.animations[a];c?(this.setFrameRange(c.start,c.end),this.duration=1e3*((c.end-c.start)/b),this.time=0):console.warn("animation["+a+"] undefined")},a.MorphAnimMesh.prototype.updateAnimation=function(b){var c=this.duration/this.length;this.time+=this.direction*b,this.mirroredLoop?(this.time>this.duration||this.time<0)&&(this.direction*=-1,this.time>this.duration&&(this.time=this.duration,this.directionBackwards=!0),this.time<0&&(this.time=0,this.directionBackwards=!1)):(this.time=this.time%this.duration,this.time<0&&(this.time+=this.duration));var d=this.startKeyframe+a.Math.clamp(Math.floor(this.time/c),0,this.length-1);d!==this.currentKeyframe&&(this.morphTargetInfluences[this.lastKeyframe]=0,this.morphTargetInfluences[this.currentKeyframe]=1,this.morphTargetInfluences[d]=0,this.lastKeyframe=this.currentKeyframe,this.currentKeyframe=d);var e=this.time%c/c;this.directionBackwards&&(e=1-e),this.morphTargetInfluences[this.currentKeyframe]=e,this.morphTargetInfluences[this.lastKeyframe]=1-e},a.MorphAnimMesh.prototype.clone=function(b){return void 0===b&&(b=new a.MorphAnimMesh(this.geometry,this.material)),b.duration=this.duration,b.mirroredLoop=this.mirroredLoop,b.time=this.time,b.lastKeyframe=this.lastKeyframe,b.currentKeyframe=this.currentKeyframe,b.direction=this.direction,b.directionBackwards=this.directionBackwards,a.Mesh.prototype.clone.call(this,b),b},a.LOD=function(){a.Object3D.call(this),this.objects=[]},a.LOD.prototype=Object.create(a.Object3D.prototype),a.LOD.prototype.addLevel=function(a,b){void 0===b&&(b=0),b=Math.abs(b);for(var c=0;cb&&!(a1){b.setFromMatrixPosition(a.matrixWorld),c.setFromMatrixPosition(this.matrixWorld);var d=b.distanceTo(c);this.objects[0].object.visible=!0;for(var e=1,f=this.objects.length;f>e&&d>=this.objects[e].distance;e++)this.objects[e-1].object.visible=!1,this.objects[e].object.visible=!0;for(;f>e;e++)this.objects[e].object.visible=!1}}}(),a.LOD.prototype.clone=function(b){void 0===b&&(b=new a.LOD),a.Object3D.prototype.clone.call(this,b);for(var c=0,d=this.objects.length;d>c;c++){var e=this.objects[c].object.clone();e.visible=0===c,b.addLevel(e,this.objects[c].distance)}return b},a.Sprite=function(){var b=new a.Geometry2(3);return b.vertices.set([-.5,-.5,0,.5,-.5,0,.5,.5,0]),function(c){a.Object3D.call(this),this.geometry=b,this.material=void 0!==c?c:new a.SpriteMaterial}}(),a.Sprite.prototype=Object.create(a.Object3D.prototype),a.Sprite.prototype.updateMatrix=function(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0},a.Sprite.prototype.clone=function(b){return void 0===b&&(b=new a.Sprite(this.material)),a.Object3D.prototype.clone.call(this,b),b},a.Particle=a.Sprite,a.Scene=function(){a.Object3D.call(this),this.fog=null,this.overrideMaterial=null,this.autoUpdate=!0,this.matrixAutoUpdate=!1,this.__lights=[],this.__objectsAdded=[],this.__objectsRemoved=[]},a.Scene.prototype=Object.create(a.Object3D.prototype),a.Scene.prototype.__addObject=function(b){if(b instanceof a.Light)-1===this.__lights.indexOf(b)&&this.__lights.push(b),b.target&&void 0===b.target.parent&&this.add(b.target);else if(!(b instanceof a.Camera||b instanceof a.Bone)){this.__objectsAdded.push(b);var c=this.__objectsRemoved.indexOf(b);-1!==c&&this.__objectsRemoved.splice(c,1)}this.dispatchEvent({type:"objectAdded",object:b}),b.dispatchEvent({type:"addedToScene",scene:this});for(var d=0;db;b++){var d=B[b],e=d.color;d instanceof a.AmbientLight?Fb.add(e):d instanceof a.DirectionalLight?Gb.add(e):d instanceof a.PointLight&&Hb.add(e)}}function d(b,c,d){for(var e=0,f=B.length;f>e;e++){var g=B[e];if(Ab.copy(g.color),g instanceof a.DirectionalLight){var h=Ib.setFromMatrixPosition(g.matrixWorld).normalize(),i=c.dot(h);if(0>=i)continue;i*=g.intensity,d.add(Ab.multiplyScalar(i))}else if(g instanceof a.PointLight){var h=Ib.setFromMatrixPosition(g.matrixWorld),i=c.dot(Ib.subVectors(h,b).normalize());if(0>=i)continue;if(i*=0==g.distance?1:1-Math.min(b.distanceTo(h)/g.distance,1),0==i)continue;i*=g.intensity,d.add(Ab.multiplyScalar(i))}}}function e(b,c,d){q(d.opacity),r(d.blending);var e=c.scale.x*fb,f=c.scale.y*gb,g=.5*Math.sqrt(e*e+f*f);if(Eb.min.set(b.x-g,b.y-g),Eb.max.set(b.x+g,b.y+g),d instanceof a.SpriteMaterial||d instanceof a.ParticleSystemMaterial){var h=d.map;if(null!==h){h.hasEventListener("update",k)===!1&&(void 0!==h.image&&h.image.width>0&&l(h),h.addEventListener("update",k));var i=Bb[h.id];w(void 0!==i?i:"rgba( 0, 0, 0, 1 )");var j=h.image,m=j.width*h.offset.x,n=j.height*h.offset.y,o=j.width*h.repeat.x,p=j.height*h.repeat.y,s=e/o,t=f/p;hb.save(),hb.translate(b.x,b.y),0!==d.rotation&&hb.rotate(d.rotation),hb.translate(-e/2,-f/2),hb.scale(s,t),hb.translate(-m,-n),hb.fillRect(m,n,o,p),hb.restore()}else w(d.color.getStyle()),hb.save(),hb.translate(b.x,b.y),0!==d.rotation&&hb.rotate(d.rotation),hb.scale(e,-f),hb.fillRect(-.5,-.5,1,1),hb.restore()}else d instanceof a.SpriteCanvasMaterial&&(v(d.color.getStyle()),w(d.color.getStyle()),hb.save(),hb.translate(b.x,b.y),0!==d.rotation&&hb.rotate(d.rotation),hb.scale(e,f),d.program(hb),hb.restore())}function f(b,c,d,e){if(q(e.opacity),r(e.blending),hb.beginPath(),hb.moveTo(b.positionScreen.x,b.positionScreen.y),hb.lineTo(c.positionScreen.x,c.positionScreen.y),e instanceof a.LineBasicMaterial){if(s(e.linewidth),t(e.linecap),u(e.linejoin),e.vertexColors!==a.VertexColors)v(e.color.getStyle());else{var f=d.vertexColors[0].getStyle(),g=d.vertexColors[1].getStyle();if(f===g)v(f);else{try{var h=hb.createLinearGradient(b.positionScreen.x,b.positionScreen.y,c.positionScreen.x,c.positionScreen.y);h.addColorStop(0,f),h.addColorStop(1,g)}catch(i){h=f}v(h)}}hb.stroke(),Eb.expandByScalar(2*e.linewidth)}else e instanceof a.LineDashedMaterial&&(s(e.linewidth),t(e.linecap),u(e.linejoin),v(e.color.getStyle()),x(e.dashSize,e.gapSize),hb.stroke(),Eb.expandByScalar(2*e.linewidth),x(null,null))}function g(b,c,e,f,g,k,l,p){ab.info.render.vertices+=3,ab.info.render.faces++,q(p.opacity),r(p.blending),G=b.positionScreen.x,H=b.positionScreen.y,I=c.positionScreen.x,J=c.positionScreen.y,K=e.positionScreen.x,L=e.positionScreen.y,h(G,H,I,J,K,L),(p instanceof a.MeshLambertMaterial||p instanceof a.MeshPhongMaterial)&&null===p.map?(yb.copy(p.color),zb.copy(p.emissive),p.vertexColors===a.FaceColors&&yb.multiply(l.color),p.wireframe===!1&&p.shading===a.SmoothShading&&3===l.vertexNormalsLength?(ub.copy(Fb),vb.copy(Fb),wb.copy(Fb),d(l.v1.positionWorld,l.vertexNormalsModel[0],ub),d(l.v2.positionWorld,l.vertexNormalsModel[1],vb),d(l.v3.positionWorld,l.vertexNormalsModel[2],wb),ub.multiply(yb).add(zb),vb.multiply(yb).add(zb),wb.multiply(yb).add(zb),xb.addColors(vb,wb).multiplyScalar(.5),O=o(ub,vb,wb,xb),n(G,H,I,J,K,L,0,0,1,0,0,1,O)):(tb.copy(Fb),d(l.centroidModel,l.normalModel,tb),tb.multiply(yb).add(zb),p.wireframe===!0?i(tb,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):j(tb))):p instanceof a.MeshBasicMaterial||p instanceof a.MeshLambertMaterial||p instanceof a.MeshPhongMaterial?null!==p.map?p.map.mapping instanceof a.UVMapping&&(P=l.uvs[0],m(G,H,I,J,K,L,P[f].x,P[f].y,P[g].x,P[g].y,P[k].x,P[k].y,p.map)):null!==p.envMap?p.envMap.mapping instanceof a.SphericalReflectionMapping&&(Jb.copy(l.vertexNormalsModel[f]).applyMatrix3(Kb),Q=.5*Jb.x+.5,R=.5*Jb.y+.5,Jb.copy(l.vertexNormalsModel[g]).applyMatrix3(Kb),S=.5*Jb.x+.5,T=.5*Jb.y+.5,Jb.copy(l.vertexNormalsModel[k]).applyMatrix3(Kb),U=.5*Jb.x+.5,V=.5*Jb.y+.5,m(G,H,I,J,K,L,Q,R,S,T,U,V,p.envMap)):(tb.copy(p.color),p.vertexColors===a.FaceColors&&tb.multiply(l.color),p.wireframe===!0?i(tb,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):j(tb)):p instanceof a.MeshDepthMaterial?(M=C.near,N=C.far,ub.r=ub.g=ub.b=1-y(b.positionScreen.z*b.positionScreen.w,M,N),vb.r=vb.g=vb.b=1-y(c.positionScreen.z*c.positionScreen.w,M,N),wb.r=wb.g=wb.b=1-y(e.positionScreen.z*e.positionScreen.w,M,N),xb.addColors(vb,wb).multiplyScalar(.5),O=o(ub,vb,wb,xb),n(G,H,I,J,K,L,0,0,1,0,0,1,O)):p instanceof a.MeshNormalMaterial&&(p.shading===a.FlatShading?(Jb.copy(l.normalModel).applyMatrix3(Kb),tb.setRGB(Jb.x,Jb.y,Jb.z).multiplyScalar(.5).addScalar(.5),p.wireframe===!0?i(tb,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):j(tb)):p.shading===a.SmoothShading&&(Jb.copy(l.vertexNormalsModel[f]).applyMatrix3(Kb),ub.setRGB(Jb.x,Jb.y,Jb.z).multiplyScalar(.5).addScalar(.5),Jb.copy(l.vertexNormalsModel[g]).applyMatrix3(Kb),vb.setRGB(Jb.x,Jb.y,Jb.z).multiplyScalar(.5).addScalar(.5),Jb.copy(l.vertexNormalsModel[k]).applyMatrix3(Kb),wb.setRGB(Jb.x,Jb.y,Jb.z).multiplyScalar(.5).addScalar(.5),xb.addColors(vb,wb).multiplyScalar(.5),O=o(ub,vb,wb,xb),n(G,H,I,J,K,L,0,0,1,0,0,1,O)))}function h(a,b,c,d,e,f){hb.beginPath(),hb.moveTo(a,b),hb.lineTo(c,d),hb.lineTo(e,f),hb.closePath()}function i(a,b,c,d){s(b),t(c),u(d),v(a.getStyle()),hb.stroke(),Eb.expandByScalar(2*b)}function j(a){w(a.getStyle()),hb.fill()}function k(a){l(a.target)}function l(b){var c=b.wrapS===a.RepeatWrapping,d=b.wrapT===a.RepeatWrapping,e=b.image,f=document.createElement("canvas");f.width=e.width,f.height=e.height;var g=f.getContext("2d");g.setTransform(1,0,0,-1,0,e.height),g.drawImage(e,0,0),Bb[b.id]=hb.createPattern(f,c===!0&&d===!0?"repeat":c===!0&&d===!1?"repeat-x":c===!1&&d===!0?"repeat-y":"no-repeat")}function m(b,c,d,e,f,g,h,i,j,m,n,o,p){if(!(p instanceof a.DataTexture)){p.hasEventListener("update",k)===!1&&(void 0!==p.image&&p.image.width>0&&l(p),p.addEventListener("update",k));var q=Bb[p.id];if(void 0===q)return w("rgba(0,0,0,1)"),void hb.fill();w(q);var r,s,t,u,v,x,y,z,A=p.offset.x/p.repeat.x,B=p.offset.y/p.repeat.y,C=p.image.width*p.repeat.x,D=p.image.height*p.repeat.y;h=(h+A)*C,i=(i+B)*D,j=(j+A)*C,m=(m+B)*D,n=(n+A)*C,o=(o+B)*D,d-=b,e-=c,f-=b,g-=c,j-=h,m-=i,n-=h,o-=i,y=j*o-n*m,0!==y&&(z=1/y,r=(o*d-m*f)*z,s=(o*e-m*g)*z,t=(j*f-n*d)*z,u=(j*g-n*e)*z,v=b-r*h-t*i,x=c-s*h-u*i,hb.save(),hb.transform(r,s,t,u,v,x),hb.fill(),hb.restore())}}function n(a,b,c,d,e,f,g,h,i,j,k,l,m){var n,o,p,q,r,s,t,u,v=m.width-1,w=m.height-1;g*=v,h*=w,i*=v,j*=w,k*=v,l*=w,c-=a,d-=b,e-=a,f-=b,i-=g,j-=h,k-=g,l-=h,t=i*l-k*j,u=1/t,n=(l*c-j*e)*u,o=(l*d-j*f)*u,p=(i*e-k*c)*u,q=(i*f-k*d)*u,r=a-n*g-p*h,s=b-o*g-q*h,hb.save(),hb.transform(n,o,p,q,r,s),hb.clip(),hb.drawImage(m,0,0),hb.restore()}function o(a,b,c,d){return Z[0]=255*a.r|0,Z[1]=255*a.g|0,Z[2]=255*a.b|0,Z[4]=255*b.r|0,Z[5]=255*b.g|0,Z[6]=255*b.b|0,Z[8]=255*c.r|0,Z[9]=255*c.g|0,Z[10]=255*c.b|0,Z[12]=255*d.r|0,Z[13]=255*d.g|0,Z[14]=255*d.b|0,X.putImageData(Y,0,0),_.drawImage(W,0,0),$}function p(a,b,c){var d,e=b.x-a.x,f=b.y-a.y,g=e*e+f*f;0!==g&&(d=c/Math.sqrt(g),e*=d,f*=d,b.x+=e,b.y+=f,a.x-=e,a.y-=f)}function q(a){kb!==a&&(hb.globalAlpha=a,kb=a)}function r(b){lb!==b&&(b===a.NormalBlending?hb.globalCompositeOperation="source-over":b===a.AdditiveBlending?hb.globalCompositeOperation="lighter":b===a.SubtractiveBlending&&(hb.globalCompositeOperation="darker"),lb=b)}function s(a){ob!==a&&(hb.lineWidth=a,ob=a)}function t(a){pb!==a&&(hb.lineCap=a,pb=a)}function u(a){qb!==a&&(hb.lineJoin=a,qb=a)}function v(a){mb!==a&&(hb.strokeStyle=a,mb=a)}function w(a){nb!==a&&(hb.fillStyle=a,nb=a)}function x(a,b){(rb!==a||sb!==b)&&(hb.setLineDash([a,b]),rb=a,sb=b)}console.log("THREE.CanvasRenderer",a.REVISION);var y=a.Math.smoothstep;b=b||{};var z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,ab=this,bb=new a.Projector,cb=void 0!==b.canvas?b.canvas:document.createElement("canvas"),db=cb.width,eb=cb.height,fb=Math.floor(db/2),gb=Math.floor(eb/2),hb=cb.getContext("2d",{alpha:b.alpha===!0}),ib=new a.Color(0),jb=0,kb=1,lb=0,mb=null,nb=null,ob=null,pb=null,qb=null,rb=null,sb=0,tb=(new a.RenderableVertex,new a.RenderableVertex,new a.Color),ub=new a.Color,vb=new a.Color,wb=new a.Color,xb=new a.Color,yb=new a.Color,zb=new a.Color,Ab=new a.Color,Bb={},Cb=new a.Box2,Db=new a.Box2,Eb=new a.Box2,Fb=new a.Color,Gb=new a.Color,Hb=new a.Color,Ib=new a.Vector3,Jb=new a.Vector3,Kb=new a.Matrix3,Lb=16;W=document.createElement("canvas"),W.width=W.height=2,X=W.getContext("2d"),X.fillStyle="rgba(0,0,0,1)",X.fillRect(0,0,2,2),Y=X.getImageData(0,0,2,2),Z=Y.data,$=document.createElement("canvas"),$.width=$.height=Lb,_=$.getContext("2d"),_.translate(-Lb/2,-Lb/2),_.scale(Lb,Lb),Lb--,void 0===hb.setLineDash&&(hb.setLineDash=void 0!==hb.mozDash?function(a){hb.mozDash=null!==a[0]?a:null}:function(){}),this.domElement=cb,this.devicePixelRatio=void 0!==b.devicePixelRatio?b.devicePixelRatio:void 0!==self.devicePixelRatio?self.devicePixelRatio:1,this.autoClear=!0,this.sortObjects=!0,this.sortElements=!0,this.info={render:{vertices:0,faces:0}},this.supportsVertexTextures=function(){},this.setFaceCulling=function(){},this.setSize=function(a,b,c){db=a*this.devicePixelRatio,eb=b*this.devicePixelRatio,fb=Math.floor(db/2),gb=Math.floor(eb/2),cb.width=db,cb.height=eb,1!==this.devicePixelRatio&&c!==!1&&(cb.style.width=a+"px",cb.style.height=b+"px"),Cb.min.set(-fb,-gb),Cb.max.set(fb,gb),Db.min.set(-fb,-gb),Db.max.set(fb,gb),kb=1,lb=0,mb=null,nb=null,ob=null,pb=null,qb=null},this.setClearColor=function(a,b){ib.set(a),jb=void 0!==b?b:1,Db.min.set(-fb,-gb),Db.max.set(fb,gb)},this.setClearColorHex=function(a,b){console.warn("DEPRECATED: .setClearColorHex() is being removed. Use .setClearColor() instead."),this.setClearColor(a,b)},this.getMaxAnisotropy=function(){return 0},this.clear=function(){hb.setTransform(1,0,0,-1,fb,gb),Db.empty()===!1&&(Db.intersect(Cb),Db.expandByScalar(2),1>jb&&hb.clearRect(0|Db.min.x,0|Db.min.y,Db.max.x-Db.min.x|0,Db.max.y-Db.min.y|0),jb>0&&(r(a.NormalBlending),q(1),w("rgba("+Math.floor(255*ib.r)+","+Math.floor(255*ib.g)+","+Math.floor(255*ib.b)+","+jb+")"),hb.fillRect(0|Db.min.x,0|Db.min.y,Db.max.x-Db.min.x|0,Db.max.y-Db.min.y|0)),Db.makeEmpty())},this.clearColor=function(){},this.clearDepth=function(){},this.clearStencil=function(){},this.render=function(b,d){if(d instanceof a.Camera==!1)return void console.error("THREE.CanvasRenderer.render: camera is not an instance of THREE.Camera.");this.autoClear===!0&&this.clear(),hb.setTransform(1,0,0,-1,fb,gb),ab.info.render.vertices=0,ab.info.render.faces=0,z=bb.projectScene(b,d,this.sortObjects,this.sortElements),A=z.elements,B=z.lights,C=d,Kb.getNormalMatrix(d.matrixWorldInverse),c();for(var h=0,i=A.length;i>h;h++){var j=A[h],k=j.material;if(void 0!==k&&k.visible!==!1){if(Eb.makeEmpty(),j instanceof a.RenderableSprite)D=j,D.x*=fb,D.y*=gb,e(D,j,k);else if(j instanceof a.RenderableLine)D=j.v1,E=j.v2,D.positionScreen.x*=fb,D.positionScreen.y*=gb,E.positionScreen.x*=fb,E.positionScreen.y*=gb,Eb.setFromPoints([D.positionScreen,E.positionScreen]),Cb.isIntersectionBox(Eb)===!0&&f(D,E,j,k);else if(j instanceof a.RenderableFace){if(D=j.v1,E=j.v2,F=j.v3,D.positionScreen.z<-1||D.positionScreen.z>1)continue;if(E.positionScreen.z<-1||E.positionScreen.z>1)continue;if(F.positionScreen.z<-1||F.positionScreen.z>1)continue;D.positionScreen.x*=fb,D.positionScreen.y*=gb,E.positionScreen.x*=fb,E.positionScreen.y*=gb,F.positionScreen.x*=fb,F.positionScreen.y*=gb,k.overdraw>0&&(p(D.positionScreen,E.positionScreen,k.overdraw),p(E.positionScreen,F.positionScreen,k.overdraw),p(F.positionScreen,D.positionScreen,k.overdraw)),Eb.setFromPoints([D.positionScreen,E.positionScreen,F.positionScreen]),Cb.isIntersectionBox(Eb)===!0&&g(D,E,F,0,1,2,j,k)}Db.union(Eb)}}hb.setTransform(1,0,0,1,0,0)}},a.ShaderChunk={fog_pars_fragment:["#ifdef USE_FOG","uniform vec3 fogColor;","#ifdef FOG_EXP2","uniform float fogDensity;","#else","uniform float fogNear;","uniform float fogFar;","#endif","#endif"].join("\n"),fog_fragment:["#ifdef USE_FOG","float depth = gl_FragCoord.z / gl_FragCoord.w;","#ifdef FOG_EXP2","const float LOG2 = 1.442695;","float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );","fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );","#else","float fogFactor = smoothstep( fogNear, fogFar, depth );","#endif","gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );","#endif"].join("\n"),envmap_pars_fragment:["#ifdef USE_ENVMAP","uniform float reflectivity;","uniform samplerCube envMap;","uniform float flipEnvMap;","uniform int combine;","#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )","uniform bool useRefract;","uniform float refractionRatio;","#else","varying vec3 vReflect;","#endif","#endif"].join("\n"),envmap_fragment:["#ifdef USE_ENVMAP","vec3 reflectVec;","#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )","vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );","if ( useRefract ) {","reflectVec = refract( cameraToVertex, normal, refractionRatio );","} else { ","reflectVec = reflect( cameraToVertex, normal );","}","#else","reflectVec = vReflect;","#endif","#ifdef DOUBLE_SIDED","float flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );","vec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );","#else","vec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );","#endif","#ifdef GAMMA_INPUT","cubeColor.xyz *= cubeColor.xyz;","#endif","if ( combine == 1 ) {","gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularStrength * reflectivity );","} else if ( combine == 2 ) {","gl_FragColor.xyz += cubeColor.xyz * specularStrength * reflectivity;","} else {","gl_FragColor.xyz = mix( gl_FragColor.xyz, gl_FragColor.xyz * cubeColor.xyz, specularStrength * reflectivity );","}","#endif"].join("\n"),envmap_pars_vertex:["#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP )","varying vec3 vReflect;","uniform float refractionRatio;","uniform bool useRefract;","#endif"].join("\n"),worldpos_vertex:["#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )","#ifdef USE_SKINNING","vec4 worldPosition = modelMatrix * skinned;","#endif","#if defined( USE_MORPHTARGETS ) && ! defined( USE_SKINNING )","vec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );","#endif","#if ! defined( USE_MORPHTARGETS ) && ! defined( USE_SKINNING )","vec4 worldPosition = modelMatrix * vec4( position, 1.0 );","#endif","#endif"].join("\n"),envmap_vertex:["#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP )","vec3 worldNormal = mat3( modelMatrix[ 0 ].xyz, modelMatrix[ 1 ].xyz, modelMatrix[ 2 ].xyz ) * objectNormal;","worldNormal = normalize( worldNormal );","vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );","if ( useRefract ) {","vReflect = refract( cameraToVertex, worldNormal, refractionRatio );","} else {","vReflect = reflect( cameraToVertex, worldNormal );","}","#endif"].join("\n"),map_particle_pars_fragment:["#ifdef USE_MAP","uniform sampler2D map;","#endif"].join("\n"),map_particle_fragment:["#ifdef USE_MAP","gl_FragColor = gl_FragColor * texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) );","#endif"].join("\n"),map_pars_vertex:["#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP )","varying vec2 vUv;","uniform vec4 offsetRepeat;","#endif"].join("\n"),map_pars_fragment:["#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP )","varying vec2 vUv;","#endif","#ifdef USE_MAP","uniform sampler2D map;","#endif"].join("\n"),map_vertex:["#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP )","vUv = uv * offsetRepeat.zw + offsetRepeat.xy;","#endif"].join("\n"),map_fragment:["#ifdef USE_MAP","vec4 texelColor = texture2D( map, vUv );","#ifdef GAMMA_INPUT","texelColor.xyz *= texelColor.xyz;","#endif","gl_FragColor = gl_FragColor * texelColor;","#endif"].join("\n"),lightmap_pars_fragment:["#ifdef USE_LIGHTMAP","varying vec2 vUv2;","uniform sampler2D lightMap;","#endif"].join("\n"),lightmap_pars_vertex:["#ifdef USE_LIGHTMAP","varying vec2 vUv2;","#endif"].join("\n"),lightmap_fragment:["#ifdef USE_LIGHTMAP","gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );","#endif"].join("\n"),lightmap_vertex:["#ifdef USE_LIGHTMAP","vUv2 = uv2;","#endif"].join("\n"),bumpmap_pars_fragment:["#ifdef USE_BUMPMAP","uniform sampler2D bumpMap;","uniform float bumpScale;","vec2 dHdxy_fwd() {","vec2 dSTdx = dFdx( vUv );","vec2 dSTdy = dFdy( vUv );","float Hll = bumpScale * texture2D( bumpMap, vUv ).x;","float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;","float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;","return vec2( dBx, dBy );","}","vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {","vec3 vSigmaX = dFdx( surf_pos );","vec3 vSigmaY = dFdy( surf_pos );","vec3 vN = surf_norm;","vec3 R1 = cross( vSigmaY, vN );","vec3 R2 = cross( vN, vSigmaX );","float fDet = dot( vSigmaX, R1 );","vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );","return normalize( abs( fDet ) * surf_norm - vGrad );","}","#endif"].join("\n"),normalmap_pars_fragment:["#ifdef USE_NORMALMAP","uniform sampler2D normalMap;","uniform vec2 normalScale;","vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {","vec3 q0 = dFdx( eye_pos.xyz );","vec3 q1 = dFdy( eye_pos.xyz );","vec2 st0 = dFdx( vUv.st );","vec2 st1 = dFdy( vUv.st );","vec3 S = normalize( q0 * st1.t - q1 * st0.t );","vec3 T = normalize( -q0 * st1.s + q1 * st0.s );","vec3 N = normalize( surf_norm );","vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;","mapN.xy = normalScale * mapN.xy;","mat3 tsn = mat3( S, T, N );","return normalize( tsn * mapN );","}","#endif"].join("\n"),specularmap_pars_fragment:["#ifdef USE_SPECULARMAP","uniform sampler2D specularMap;","#endif"].join("\n"),specularmap_fragment:["float specularStrength;","#ifdef USE_SPECULARMAP","vec4 texelSpecular = texture2D( specularMap, vUv );","specularStrength = texelSpecular.r;","#else","specularStrength = 1.0;","#endif"].join("\n"),lights_lambert_pars_vertex:["uniform vec3 ambient;","uniform vec3 diffuse;","uniform vec3 emissive;","uniform vec3 ambientLightColor;","#if MAX_DIR_LIGHTS > 0","uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];","uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];","#endif","#if MAX_HEMI_LIGHTS > 0","uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];","uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];","uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];","#endif","#if MAX_POINT_LIGHTS > 0","uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];","uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];","uniform float pointLightDistance[ MAX_POINT_LIGHTS ];","#endif","#if MAX_SPOT_LIGHTS > 0","uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];","uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];","uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];","uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];","uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];","uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];","#endif","#ifdef WRAP_AROUND","uniform vec3 wrapRGB;","#endif"].join("\n"),lights_lambert_vertex:["vLightFront = vec3( 0.0 );","#ifdef DOUBLE_SIDED","vLightBack = vec3( 0.0 );","#endif","transformedNormal = normalize( transformedNormal );","#if MAX_DIR_LIGHTS > 0","for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {","vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );","vec3 dirVector = normalize( lDirection.xyz );","float dotProduct = dot( transformedNormal, dirVector );","vec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );","#ifdef DOUBLE_SIDED","vec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );","#ifdef WRAP_AROUND","vec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );","#endif","#endif","#ifdef WRAP_AROUND","vec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );","directionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );","#ifdef DOUBLE_SIDED","directionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );","#endif","#endif","vLightFront += directionalLightColor[ i ] * directionalLightWeighting;","#ifdef DOUBLE_SIDED","vLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;","#endif","}","#endif","#if MAX_POINT_LIGHTS > 0","for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {","vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );","vec3 lVector = lPosition.xyz - mvPosition.xyz;","float lDistance = 1.0;","if ( pointLightDistance[ i ] > 0.0 )","lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );","lVector = normalize( lVector );","float dotProduct = dot( transformedNormal, lVector );","vec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );","#ifdef DOUBLE_SIDED","vec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );","#ifdef WRAP_AROUND","vec3 pointLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );","#endif","#endif","#ifdef WRAP_AROUND","vec3 pointLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );","pointLightWeighting = mix( pointLightWeighting, pointLightWeightingHalf, wrapRGB );","#ifdef DOUBLE_SIDED","pointLightWeightingBack = mix( pointLightWeightingBack, pointLightWeightingHalfBack, wrapRGB );","#endif","#endif","vLightFront += pointLightColor[ i ] * pointLightWeighting * lDistance;","#ifdef DOUBLE_SIDED","vLightBack += pointLightColor[ i ] * pointLightWeightingBack * lDistance;","#endif","}","#endif","#if MAX_SPOT_LIGHTS > 0","for( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {","vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );","vec3 lVector = lPosition.xyz - mvPosition.xyz;","float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - worldPosition.xyz ) );","if ( spotEffect > spotLightAngleCos[ i ] ) {","spotEffect = max( pow( spotEffect, spotLightExponent[ i ] ), 0.0 );","float lDistance = 1.0;","if ( spotLightDistance[ i ] > 0.0 )","lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );","lVector = normalize( lVector );","float dotProduct = dot( transformedNormal, lVector );","vec3 spotLightWeighting = vec3( max( dotProduct, 0.0 ) );","#ifdef DOUBLE_SIDED","vec3 spotLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );","#ifdef WRAP_AROUND","vec3 spotLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );","#endif","#endif","#ifdef WRAP_AROUND","vec3 spotLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );","spotLightWeighting = mix( spotLightWeighting, spotLightWeightingHalf, wrapRGB );","#ifdef DOUBLE_SIDED","spotLightWeightingBack = mix( spotLightWeightingBack, spotLightWeightingHalfBack, wrapRGB );","#endif","#endif","vLightFront += spotLightColor[ i ] * spotLightWeighting * lDistance * spotEffect;","#ifdef DOUBLE_SIDED","vLightBack += spotLightColor[ i ] * spotLightWeightingBack * lDistance * spotEffect;","#endif","}","}","#endif","#if MAX_HEMI_LIGHTS > 0","for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {","vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );","vec3 lVector = normalize( lDirection.xyz );","float dotProduct = dot( transformedNormal, lVector );","float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;","float hemiDiffuseWeightBack = -0.5 * dotProduct + 0.5;","vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );","#ifdef DOUBLE_SIDED","vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );","#endif","}","#endif","vLightFront = vLightFront * diffuse + ambient * ambientLightColor + emissive;","#ifdef DOUBLE_SIDED","vLightBack = vLightBack * diffuse + ambient * ambientLightColor + emissive;","#endif"].join("\n"),lights_phong_pars_vertex:["#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP )","varying vec3 vWorldPosition;","#endif"].join("\n"),lights_phong_vertex:["#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP )","vWorldPosition = worldPosition.xyz;","#endif"].join("\n"),lights_phong_pars_fragment:["uniform vec3 ambientLightColor;","#if MAX_DIR_LIGHTS > 0","uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];","uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];","#endif","#if MAX_HEMI_LIGHTS > 0","uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];","uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];","uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];","#endif","#if MAX_POINT_LIGHTS > 0","uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];","uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];","uniform float pointLightDistance[ MAX_POINT_LIGHTS ];","#endif","#if MAX_SPOT_LIGHTS > 0","uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];","uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];","uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];","uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];","uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];","uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];","#endif","#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP )","varying vec3 vWorldPosition;","#endif","#ifdef WRAP_AROUND","uniform vec3 wrapRGB;","#endif","varying vec3 vViewPosition;","varying vec3 vNormal;"].join("\n"),lights_phong_fragment:["vec3 normal = normalize( vNormal );","vec3 viewPosition = normalize( vViewPosition );","#ifdef DOUBLE_SIDED","normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );","#endif","#ifdef USE_NORMALMAP","normal = perturbNormal2Arb( -vViewPosition, normal );","#elif defined( USE_BUMPMAP )","normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );","#endif","#if MAX_POINT_LIGHTS > 0","vec3 pointDiffuse = vec3( 0.0 );","vec3 pointSpecular = vec3( 0.0 );","for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {","vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );","vec3 lVector = lPosition.xyz + vViewPosition.xyz;","float lDistance = 1.0;","if ( pointLightDistance[ i ] > 0.0 )","lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );","lVector = normalize( lVector );","float dotProduct = dot( normal, lVector );","#ifdef WRAP_AROUND","float pointDiffuseWeightFull = max( dotProduct, 0.0 );","float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );","vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );","#else","float pointDiffuseWeight = max( dotProduct, 0.0 );","#endif","pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;","vec3 pointHalfVector = normalize( lVector + viewPosition );","float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );","float pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );","float specularNormalization = ( shininess + 2.0001 ) / 8.0;","vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, pointHalfVector ), 0.0 ), 5.0 );","pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;","}","#endif","#if MAX_SPOT_LIGHTS > 0","vec3 spotDiffuse = vec3( 0.0 );","vec3 spotSpecular = vec3( 0.0 );","for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {","vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );","vec3 lVector = lPosition.xyz + vViewPosition.xyz;","float lDistance = 1.0;","if ( spotLightDistance[ i ] > 0.0 )","lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );","lVector = normalize( lVector );","float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );","if ( spotEffect > spotLightAngleCos[ i ] ) {","spotEffect = max( pow( spotEffect, spotLightExponent[ i ] ), 0.0 );","float dotProduct = dot( normal, lVector );","#ifdef WRAP_AROUND","float spotDiffuseWeightFull = max( dotProduct, 0.0 );","float spotDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );","vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );","#else","float spotDiffuseWeight = max( dotProduct, 0.0 );","#endif","spotDiffuse += diffuse * spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;","vec3 spotHalfVector = normalize( lVector + viewPosition );","float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );","float spotSpecularWeight = specularStrength * max( pow( spotDotNormalHalf, shininess ), 0.0 );","float specularNormalization = ( shininess + 2.0001 ) / 8.0;","vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, spotHalfVector ), 0.0 ), 5.0 );","spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * specularNormalization * spotEffect;","}","}","#endif","#if MAX_DIR_LIGHTS > 0","vec3 dirDiffuse = vec3( 0.0 );","vec3 dirSpecular = vec3( 0.0 );","for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {","vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );","vec3 dirVector = normalize( lDirection.xyz );","float dotProduct = dot( normal, dirVector );","#ifdef WRAP_AROUND","float dirDiffuseWeightFull = max( dotProduct, 0.0 );","float dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );","vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );","#else","float dirDiffuseWeight = max( dotProduct, 0.0 );","#endif","dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;","vec3 dirHalfVector = normalize( dirVector + viewPosition );","float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );","float dirSpecularWeight = specularStrength * max( pow( dirDotNormalHalf, shininess ), 0.0 );","float specularNormalization = ( shininess + 2.0001 ) / 8.0;","vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );","dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;","}","#endif","#if MAX_HEMI_LIGHTS > 0","vec3 hemiDiffuse = vec3( 0.0 );","vec3 hemiSpecular = vec3( 0.0 );","for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {","vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );","vec3 lVector = normalize( lDirection.xyz );","float dotProduct = dot( normal, lVector );","float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;","vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );","hemiDiffuse += diffuse * hemiColor;","vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );","float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;","float hemiSpecularWeightSky = specularStrength * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );","vec3 lVectorGround = -lVector;","vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );","float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;","float hemiSpecularWeightGround = specularStrength * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );","float dotProductGround = dot( normal, lVectorGround );","float specularNormalization = ( shininess + 2.0001 ) / 8.0;","vec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, hemiHalfVectorSky ), 0.0 ), 5.0 );","vec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 0.0 ), 5.0 );","hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );","}","#endif","vec3 totalDiffuse = vec3( 0.0 );","vec3 totalSpecular = vec3( 0.0 );","#if MAX_DIR_LIGHTS > 0","totalDiffuse += dirDiffuse;","totalSpecular += dirSpecular;","#endif","#if MAX_HEMI_LIGHTS > 0","totalDiffuse += hemiDiffuse;","totalSpecular += hemiSpecular;","#endif","#if MAX_POINT_LIGHTS > 0","totalDiffuse += pointDiffuse;","totalSpecular += pointSpecular;","#endif","#if MAX_SPOT_LIGHTS > 0","totalDiffuse += spotDiffuse;","totalSpecular += spotSpecular;","#endif","#ifdef METAL","gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );","#else","gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;","#endif"].join("\n"),color_pars_fragment:["#ifdef USE_COLOR","varying vec3 vColor;","#endif"].join("\n"),color_fragment:["#ifdef USE_COLOR","gl_FragColor = gl_FragColor * vec4( vColor, 1.0 );","#endif"].join("\n"),color_pars_vertex:["#ifdef USE_COLOR","varying vec3 vColor;","#endif"].join("\n"),color_vertex:["#ifdef USE_COLOR","#ifdef GAMMA_INPUT","vColor = color * color;","#else","vColor = color;","#endif","#endif"].join("\n"),skinning_pars_vertex:["#ifdef USE_SKINNING","#ifdef BONE_TEXTURE","uniform sampler2D boneTexture;","uniform int boneTextureWidth;","uniform int boneTextureHeight;","mat4 getBoneMatrix( const in float i ) {","float j = i * 4.0;","float x = mod( j, float( boneTextureWidth ) );","float y = floor( j / float( boneTextureWidth ) );","float dx = 1.0 / float( boneTextureWidth );","float dy = 1.0 / float( boneTextureHeight );","y = dy * ( y + 0.5 );","vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );","vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );","vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );","vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );","mat4 bone = mat4( v1, v2, v3, v4 );","return bone;","}","#else","uniform mat4 boneGlobalMatrices[ MAX_BONES ];","mat4 getBoneMatrix( const in float i ) {","mat4 bone = boneGlobalMatrices[ int(i) ];","return bone;","}","#endif","#endif"].join("\n"),skinbase_vertex:["#ifdef USE_SKINNING","mat4 boneMatX = getBoneMatrix( skinIndex.x );","mat4 boneMatY = getBoneMatrix( skinIndex.y );","mat4 boneMatZ = getBoneMatrix( skinIndex.z );","mat4 boneMatW = getBoneMatrix( skinIndex.w );","#endif"].join("\n"),skinning_vertex:["#ifdef USE_SKINNING","#ifdef USE_MORPHTARGETS","vec4 skinVertex = vec4( morphed, 1.0 );","#else","vec4 skinVertex = vec4( position, 1.0 );","#endif","vec4 skinned = boneMatX * skinVertex * skinWeight.x;","skinned += boneMatY * skinVertex * skinWeight.y;","skinned += boneMatZ * skinVertex * skinWeight.z;","skinned += boneMatW * skinVertex * skinWeight.w;","#endif"].join("\n"),morphtarget_pars_vertex:["#ifdef USE_MORPHTARGETS","#ifndef USE_MORPHNORMALS","uniform float morphTargetInfluences[ 8 ];","#else","uniform float morphTargetInfluences[ 4 ];","#endif","#endif"].join("\n"),morphtarget_vertex:["#ifdef USE_MORPHTARGETS","vec3 morphed = vec3( 0.0 );","morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];","morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];","morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];","morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];","#ifndef USE_MORPHNORMALS","morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];","morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];","morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];","morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];","#endif","morphed += position;","#endif"].join("\n"),default_vertex:["vec4 mvPosition;","#ifdef USE_SKINNING","mvPosition = modelViewMatrix * skinned;","#endif","#if !defined( USE_SKINNING ) && defined( USE_MORPHTARGETS )","mvPosition = modelViewMatrix * vec4( morphed, 1.0 );","#endif","#if !defined( USE_SKINNING ) && ! defined( USE_MORPHTARGETS )","mvPosition = modelViewMatrix * vec4( position, 1.0 );","#endif","gl_Position = projectionMatrix * mvPosition;"].join("\n"),morphnormal_vertex:["#ifdef USE_MORPHNORMALS","vec3 morphedNormal = vec3( 0.0 );","morphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];","morphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];","morphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];","morphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];","morphedNormal += normal;","#endif"].join("\n"),skinnormal_vertex:["#ifdef USE_SKINNING","mat4 skinMatrix = skinWeight.x * boneMatX;","skinMatrix += skinWeight.y * boneMatY;","#ifdef USE_MORPHNORMALS","vec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );","#else","vec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );","#endif","#endif"].join("\n"),defaultnormal_vertex:["vec3 objectNormal;","#ifdef USE_SKINNING","objectNormal = skinnedNormal.xyz;","#endif","#if !defined( USE_SKINNING ) && defined( USE_MORPHNORMALS )","objectNormal = morphedNormal;","#endif","#if !defined( USE_SKINNING ) && ! defined( USE_MORPHNORMALS )","objectNormal = normal;","#endif","#ifdef FLIP_SIDED","objectNormal = -objectNormal;","#endif","vec3 transformedNormal = normalMatrix * objectNormal;"].join("\n"),shadowmap_pars_fragment:["#ifdef USE_SHADOWMAP","uniform sampler2D shadowMap[ MAX_SHADOWS ];","uniform vec2 shadowMapSize[ MAX_SHADOWS ];","uniform float shadowDarkness[ MAX_SHADOWS ];","uniform float shadowBias[ MAX_SHADOWS ];","varying vec4 vShadowCoord[ MAX_SHADOWS ];","float unpackDepth( const in vec4 rgba_depth ) {","const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );","float depth = dot( rgba_depth, bit_shift );","return depth;","}","#endif"].join("\n"),shadowmap_fragment:["#ifdef USE_SHADOWMAP","#ifdef SHADOWMAP_DEBUG","vec3 frustumColors[3];","frustumColors[0] = vec3( 1.0, 0.5, 0.0 );","frustumColors[1] = vec3( 0.0, 1.0, 0.8 );","frustumColors[2] = vec3( 0.0, 0.5, 1.0 );","#endif","#ifdef SHADOWMAP_CASCADE","int inFrustumCount = 0;","#endif","float fDepth;","vec3 shadowColor = vec3( 1.0 );","for( int i = 0; i < MAX_SHADOWS; i ++ ) {","vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;","bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );","bool inFrustum = all( inFrustumVec );","#ifdef SHADOWMAP_CASCADE","inFrustumCount += int( inFrustum );","bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );","#else","bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );","#endif","bool frustumTest = all( frustumTestVec );","if ( frustumTest ) {","shadowCoord.z += shadowBias[ i ];","#if defined( SHADOWMAP_TYPE_PCF )","float shadow = 0.0;","const float shadowDelta = 1.0 / 9.0;","float xPixelOffset = 1.0 / shadowMapSize[ i ].x;","float yPixelOffset = 1.0 / shadowMapSize[ i ].y;","float dx0 = -1.25 * xPixelOffset;","float dy0 = -1.25 * yPixelOffset;","float dx1 = 1.25 * xPixelOffset;","float dy1 = 1.25 * yPixelOffset;","fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );","if ( fDepth < shadowCoord.z ) shadow += shadowDelta;","fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );","if ( fDepth < shadowCoord.z ) shadow += shadowDelta;","fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );","if ( fDepth < shadowCoord.z ) shadow += shadowDelta;","fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );","if ( fDepth < shadowCoord.z ) shadow += shadowDelta;","fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );","if ( fDepth < shadowCoord.z ) shadow += shadowDelta;","fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );","if ( fDepth < shadowCoord.z ) shadow += shadowDelta;","fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );","if ( fDepth < shadowCoord.z ) shadow += shadowDelta;","fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );","if ( fDepth < shadowCoord.z ) shadow += shadowDelta;","fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );","if ( fDepth < shadowCoord.z ) shadow += shadowDelta;","shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );","#elif defined( SHADOWMAP_TYPE_PCF_SOFT )","float shadow = 0.0;","float xPixelOffset = 1.0 / shadowMapSize[ i ].x;","float yPixelOffset = 1.0 / shadowMapSize[ i ].y;","float dx0 = -1.0 * xPixelOffset;","float dy0 = -1.0 * yPixelOffset;","float dx1 = 1.0 * xPixelOffset;","float dy1 = 1.0 * yPixelOffset;","mat3 shadowKernel;","mat3 depthKernel;","depthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );","depthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );","depthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );","depthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );","depthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );","depthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );","depthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );","depthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );","depthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );","vec3 shadowZ = vec3( shadowCoord.z );","shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));","shadowKernel[0] *= vec3(0.25);","shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));","shadowKernel[1] *= vec3(0.25);","shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));","shadowKernel[2] *= vec3(0.25);","vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );","shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );","shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );","vec4 shadowValues;","shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );","shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );","shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );","shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );","shadow = dot( shadowValues, vec4( 1.0 ) );","shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );","#else","vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );","float fDepth = unpackDepth( rgbaDepth );","if ( fDepth < shadowCoord.z )","shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );","#endif","}","#ifdef SHADOWMAP_DEBUG","#ifdef SHADOWMAP_CASCADE","if ( inFrustum && inFrustumCount == 1 ) gl_FragColor.xyz *= frustumColors[ i ];","#else","if ( inFrustum ) gl_FragColor.xyz *= frustumColors[ i ];","#endif","#endif","}","#ifdef GAMMA_OUTPUT","shadowColor *= shadowColor;","#endif","gl_FragColor.xyz = gl_FragColor.xyz * shadowColor;","#endif"].join("\n"),shadowmap_pars_vertex:["#ifdef USE_SHADOWMAP","varying vec4 vShadowCoord[ MAX_SHADOWS ];","uniform mat4 shadowMatrix[ MAX_SHADOWS ];","#endif"].join("\n"),shadowmap_vertex:["#ifdef USE_SHADOWMAP","for( int i = 0; i < MAX_SHADOWS; i ++ ) {","vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;","}","#endif"].join("\n"),alphatest_fragment:["#ifdef ALPHATEST","if ( gl_FragColor.a < ALPHATEST ) discard;","#endif"].join("\n"),linear_to_gamma_fragment:["#ifdef GAMMA_OUTPUT","gl_FragColor.xyz = sqrt( gl_FragColor.xyz );","#endif"].join("\n")},a.UniformsUtils={merge:function(a){var b,c,d,e={};
+for(b=0;b dashSize ) {","discard;","}","gl_FragColor = vec4( diffuse, opacity );",a.ShaderChunk.color_fragment,a.ShaderChunk.fog_fragment,"}"].join("\n")},depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2e3},opacity:{type:"f",value:1}},vertexShader:["void main() {","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform float mNear;","uniform float mFar;","uniform float opacity;","void main() {","float depth = gl_FragCoord.z / gl_FragCoord.w;","float color = 1.0 - smoothstep( mNear, mFar, depth );","gl_FragColor = vec4( vec3( color ), opacity );","}"].join("\n")},normal:{uniforms:{opacity:{type:"f",value:1}},vertexShader:["varying vec3 vNormal;",a.ShaderChunk.morphtarget_pars_vertex,"void main() {","vNormal = normalize( normalMatrix * normal );",a.ShaderChunk.morphtarget_vertex,a.ShaderChunk.default_vertex,"}"].join("\n"),fragmentShader:["uniform float opacity;","varying vec3 vNormal;","void main() {","gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );","}"].join("\n")},normalmap:{uniforms:a.UniformsUtils.merge([a.UniformsLib.fog,a.UniformsLib.lights,a.UniformsLib.shadowmap,{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},enableSpecular:{type:"i",value:0},enableReflection:{type:"i",value:0},enableDisplacement:{type:"i",value:0},tDisplacement:{type:"t",value:null},tDiffuse:{type:"t",value:null},tCube:{type:"t",value:null},tNormal:{type:"t",value:null},tSpecular:{type:"t",value:null},tAO:{type:"t",value:null},uNormalScale:{type:"v2",value:new a.Vector2(1,1)},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},diffuse:{type:"c",value:new a.Color(16777215)},specular:{type:"c",value:new a.Color(1118481)},ambient:{type:"c",value:new a.Color(16777215)},shininess:{type:"f",value:30},opacity:{type:"f",value:1},useRefract:{type:"i",value:0},refractionRatio:{type:"f",value:.98},reflectivity:{type:"f",value:.5},uOffset:{type:"v2",value:new a.Vector2(0,0)},uRepeat:{type:"v2",value:new a.Vector2(1,1)},wrapRGB:{type:"v3",value:new a.Vector3(1,1,1)}}]),fragmentShader:["uniform vec3 ambient;","uniform vec3 diffuse;","uniform vec3 specular;","uniform float shininess;","uniform float opacity;","uniform bool enableDiffuse;","uniform bool enableSpecular;","uniform bool enableAO;","uniform bool enableReflection;","uniform sampler2D tDiffuse;","uniform sampler2D tNormal;","uniform sampler2D tSpecular;","uniform sampler2D tAO;","uniform samplerCube tCube;","uniform vec2 uNormalScale;","uniform bool useRefract;","uniform float refractionRatio;","uniform float reflectivity;","varying vec3 vTangent;","varying vec3 vBinormal;","varying vec3 vNormal;","varying vec2 vUv;","uniform vec3 ambientLightColor;","#if MAX_DIR_LIGHTS > 0","uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];","uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];","#endif","#if MAX_HEMI_LIGHTS > 0","uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];","uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];","uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];","#endif","#if MAX_POINT_LIGHTS > 0","uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];","uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];","uniform float pointLightDistance[ MAX_POINT_LIGHTS ];","#endif","#if MAX_SPOT_LIGHTS > 0","uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];","uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];","uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];","uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];","uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];","uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];","#endif","#ifdef WRAP_AROUND","uniform vec3 wrapRGB;","#endif","varying vec3 vWorldPosition;","varying vec3 vViewPosition;",a.ShaderChunk.shadowmap_pars_fragment,a.ShaderChunk.fog_pars_fragment,"void main() {","gl_FragColor = vec4( vec3( 1.0 ), opacity );","vec3 specularTex = vec3( 1.0 );","vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;","normalTex.xy *= uNormalScale;","normalTex = normalize( normalTex );","if( enableDiffuse ) {","#ifdef GAMMA_INPUT","vec4 texelColor = texture2D( tDiffuse, vUv );","texelColor.xyz *= texelColor.xyz;","gl_FragColor = gl_FragColor * texelColor;","#else","gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );","#endif","}","if( enableAO ) {","#ifdef GAMMA_INPUT","vec4 aoColor = texture2D( tAO, vUv );","aoColor.xyz *= aoColor.xyz;","gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;","#else","gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;","#endif","}","if( enableSpecular )","specularTex = texture2D( tSpecular, vUv ).xyz;","mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );","vec3 finalNormal = tsb * normalTex;","#ifdef FLIP_SIDED","finalNormal = -finalNormal;","#endif","vec3 normal = normalize( finalNormal );","vec3 viewPosition = normalize( vViewPosition );","#if MAX_POINT_LIGHTS > 0","vec3 pointDiffuse = vec3( 0.0 );","vec3 pointSpecular = vec3( 0.0 );","for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {","vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );","vec3 pointVector = lPosition.xyz + vViewPosition.xyz;","float pointDistance = 1.0;","if ( pointLightDistance[ i ] > 0.0 )","pointDistance = 1.0 - min( ( length( pointVector ) / pointLightDistance[ i ] ), 1.0 );","pointVector = normalize( pointVector );","#ifdef WRAP_AROUND","float pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );","float pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );","vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );","#else","float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );","#endif","pointDiffuse += pointDistance * pointLightColor[ i ] * diffuse * pointDiffuseWeight;","vec3 pointHalfVector = normalize( pointVector + viewPosition );","float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );","float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, shininess ), 0.0 );","float specularNormalization = ( shininess + 2.0001 ) / 8.0;","vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );","pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;","}","#endif","#if MAX_SPOT_LIGHTS > 0","vec3 spotDiffuse = vec3( 0.0 );","vec3 spotSpecular = vec3( 0.0 );","for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {","vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );","vec3 spotVector = lPosition.xyz + vViewPosition.xyz;","float spotDistance = 1.0;","if ( spotLightDistance[ i ] > 0.0 )","spotDistance = 1.0 - min( ( length( spotVector ) / spotLightDistance[ i ] ), 1.0 );","spotVector = normalize( spotVector );","float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );","if ( spotEffect > spotLightAngleCos[ i ] ) {","spotEffect = max( pow( spotEffect, spotLightExponent[ i ] ), 0.0 );","#ifdef WRAP_AROUND","float spotDiffuseWeightFull = max( dot( normal, spotVector ), 0.0 );","float spotDiffuseWeightHalf = max( 0.5 * dot( normal, spotVector ) + 0.5, 0.0 );","vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );","#else","float spotDiffuseWeight = max( dot( normal, spotVector ), 0.0 );","#endif","spotDiffuse += spotDistance * spotLightColor[ i ] * diffuse * spotDiffuseWeight * spotEffect;","vec3 spotHalfVector = normalize( spotVector + viewPosition );","float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );","float spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, shininess ), 0.0 );","float specularNormalization = ( shininess + 2.0001 ) / 8.0;","vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( spotVector, spotHalfVector ), 5.0 );","spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;","}","}","#endif","#if MAX_DIR_LIGHTS > 0","vec3 dirDiffuse = vec3( 0.0 );","vec3 dirSpecular = vec3( 0.0 );","for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {","vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );","vec3 dirVector = normalize( lDirection.xyz );","#ifdef WRAP_AROUND","float directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );","float directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );","vec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );","#else","float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );","#endif","dirDiffuse += directionalLightColor[ i ] * diffuse * dirDiffuseWeight;","vec3 dirHalfVector = normalize( dirVector + viewPosition );","float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );","float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, shininess ), 0.0 );","float specularNormalization = ( shininess + 2.0001 ) / 8.0;","vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );","dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;","}","#endif","#if MAX_HEMI_LIGHTS > 0","vec3 hemiDiffuse = vec3( 0.0 );","vec3 hemiSpecular = vec3( 0.0 );","for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {","vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );","vec3 lVector = normalize( lDirection.xyz );","float dotProduct = dot( normal, lVector );","float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;","vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );","hemiDiffuse += diffuse * hemiColor;","vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );","float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;","float hemiSpecularWeightSky = specularTex.r * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );","vec3 lVectorGround = -lVector;","vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );","float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;","float hemiSpecularWeightGround = specularTex.r * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );","float dotProductGround = dot( normal, lVectorGround );","float specularNormalization = ( shininess + 2.0001 ) / 8.0;","vec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, hemiHalfVectorSky ), 5.0 );","vec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 5.0 );","hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );","}","#endif","vec3 totalDiffuse = vec3( 0.0 );","vec3 totalSpecular = vec3( 0.0 );","#if MAX_DIR_LIGHTS > 0","totalDiffuse += dirDiffuse;","totalSpecular += dirSpecular;","#endif","#if MAX_HEMI_LIGHTS > 0","totalDiffuse += hemiDiffuse;","totalSpecular += hemiSpecular;","#endif","#if MAX_POINT_LIGHTS > 0","totalDiffuse += pointDiffuse;","totalSpecular += pointSpecular;","#endif","#if MAX_SPOT_LIGHTS > 0","totalDiffuse += spotDiffuse;","totalSpecular += spotSpecular;","#endif","#ifdef METAL","gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient + totalSpecular );","#else","gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient ) + totalSpecular;","#endif","if ( enableReflection ) {","vec3 vReflect;","vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );","if ( useRefract ) {","vReflect = refract( cameraToVertex, normal, refractionRatio );","} else {","vReflect = reflect( cameraToVertex, normal );","}","vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );","#ifdef GAMMA_INPUT","cubeColor.xyz *= cubeColor.xyz;","#endif","gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * reflectivity );","}",a.ShaderChunk.shadowmap_fragment,a.ShaderChunk.linear_to_gamma_fragment,a.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:["attribute vec4 tangent;","uniform vec2 uOffset;","uniform vec2 uRepeat;","uniform bool enableDisplacement;","#ifdef VERTEX_TEXTURES","uniform sampler2D tDisplacement;","uniform float uDisplacementScale;","uniform float uDisplacementBias;","#endif","varying vec3 vTangent;","varying vec3 vBinormal;","varying vec3 vNormal;","varying vec2 vUv;","varying vec3 vWorldPosition;","varying vec3 vViewPosition;",a.ShaderChunk.skinning_pars_vertex,a.ShaderChunk.shadowmap_pars_vertex,"void main() {",a.ShaderChunk.skinbase_vertex,a.ShaderChunk.skinnormal_vertex,"#ifdef USE_SKINNING","vNormal = normalize( normalMatrix * skinnedNormal.xyz );","vec4 skinnedTangent = skinMatrix * vec4( tangent.xyz, 0.0 );","vTangent = normalize( normalMatrix * skinnedTangent.xyz );","#else","vNormal = normalize( normalMatrix * normal );","vTangent = normalize( normalMatrix * tangent.xyz );","#endif","vBinormal = normalize( cross( vNormal, vTangent ) * tangent.w );","vUv = uv * uRepeat + uOffset;","vec3 displacedPosition;","#ifdef VERTEX_TEXTURES","if ( enableDisplacement ) {","vec3 dv = texture2D( tDisplacement, uv ).xyz;","float df = uDisplacementScale * dv.x + uDisplacementBias;","displacedPosition = position + normalize( normal ) * df;","} else {","#ifdef USE_SKINNING","vec4 skinVertex = vec4( position, 1.0 );","vec4 skinned = boneMatX * skinVertex * skinWeight.x;","skinned += boneMatY * skinVertex * skinWeight.y;","displacedPosition = skinned.xyz;","#else","displacedPosition = position;","#endif","}","#else","#ifdef USE_SKINNING","vec4 skinVertex = vec4( position, 1.0 );","vec4 skinned = boneMatX * skinVertex * skinWeight.x;","skinned += boneMatY * skinVertex * skinWeight.y;","displacedPosition = skinned.xyz;","#else","displacedPosition = position;","#endif","#endif","vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );","vec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );","gl_Position = projectionMatrix * mvPosition;","vWorldPosition = worldPosition.xyz;","vViewPosition = -mvPosition.xyz;","#ifdef USE_SHADOWMAP","for( int i = 0; i < MAX_SHADOWS; i ++ ) {","vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;","}","#endif","}"].join("\n")},cube:{uniforms:{tCube:{type:"t",value:null},tFlip:{type:"f",value:-1}},vertexShader:["varying vec3 vWorldPosition;","void main() {","vec4 worldPosition = modelMatrix * vec4( position, 1.0 );","vWorldPosition = worldPosition.xyz;","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform samplerCube tCube;","uniform float tFlip;","varying vec3 vWorldPosition;","void main() {","gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );","}"].join("\n")},depthRGBA:{uniforms:{},vertexShader:[a.ShaderChunk.morphtarget_pars_vertex,a.ShaderChunk.skinning_pars_vertex,"void main() {",a.ShaderChunk.skinbase_vertex,a.ShaderChunk.morphtarget_vertex,a.ShaderChunk.skinning_vertex,a.ShaderChunk.default_vertex,"}"].join("\n"),fragmentShader:["vec4 pack_depth( const in float depth ) {","const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );","const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );","vec4 res = fract( depth * bit_shift );","res -= res.xxyz * bit_mask;","return res;","}","void main() {","gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );","}"].join("\n")}},a.WebGLRenderer=function(b){function c(a){a.__webglVertexBuffer=Jb.createBuffer(),a.__webglColorBuffer=Jb.createBuffer(),Pb.info.memory.geometries++}function d(a){a.__webglVertexBuffer=Jb.createBuffer(),a.__webglColorBuffer=Jb.createBuffer(),a.__webglLineDistanceBuffer=Jb.createBuffer(),Pb.info.memory.geometries++}function e(a){a.__webglVertexBuffer=Jb.createBuffer(),a.__webglNormalBuffer=Jb.createBuffer(),a.__webglTangentBuffer=Jb.createBuffer(),a.__webglColorBuffer=Jb.createBuffer(),a.__webglUVBuffer=Jb.createBuffer(),a.__webglUV2Buffer=Jb.createBuffer(),a.__webglSkinIndicesBuffer=Jb.createBuffer(),a.__webglSkinWeightsBuffer=Jb.createBuffer(),a.__webglFaceBuffer=Jb.createBuffer(),a.__webglLineBuffer=Jb.createBuffer();var b,c;if(a.numMorphTargets)for(a.__webglMorphTargetsBuffers=[],b=0,c=a.numMorphTargets;c>b;b++)a.__webglMorphTargetsBuffers.push(Jb.createBuffer());if(a.numMorphNormals)for(a.__webglMorphNormalsBuffers=[],b=0,c=a.numMorphNormals;c>b;b++)a.__webglMorphNormalsBuffers.push(Jb.createBuffer());Pb.info.memory.geometries++}function f(a,b){var c=a.vertices.length,d=b.material;if(d.attributes){void 0===a.__webglCustomAttributesList&&(a.__webglCustomAttributesList=[]);for(var e in d.attributes){var f=d.attributes[e];if(!f.__webglInitialized||f.createUniqueBuffers){f.__webglInitialized=!0;var g=1;"v2"===f.type?g=2:"v3"===f.type?g=3:"v4"===f.type?g=4:"c"===f.type&&(g=3),f.size=g,f.array=new Float32Array(c*g),f.buffer=Jb.createBuffer(),f.buffer.belongsToAttribute=e,f.needsUpdate=!0}a.__webglCustomAttributesList.push(f)}}}function g(a,b){var c=a.vertices.length;a.__vertexArray=new Float32Array(3*c),a.__colorArray=new Float32Array(3*c),a.__sortArray=[],a.__webglParticleCount=c,f(a,b)}function h(a,b){var c=a.vertices.length;a.__vertexArray=new Float32Array(3*c),a.__colorArray=new Float32Array(3*c),a.__lineDistanceArray=new Float32Array(1*c),a.__webglLineCount=c,f(a,b)}function i(a,b){var c=b.geometry,d=a.faces3,e=3*d.length,f=1*d.length,g=3*d.length,h=j(b,a),i=n(h),k=l(h),o=m(h);a.__vertexArray=new Float32Array(3*e),k&&(a.__normalArray=new Float32Array(3*e)),c.hasTangents&&(a.__tangentArray=new Float32Array(4*e)),o&&(a.__colorArray=new Float32Array(3*e)),i&&(c.faceVertexUvs.length>0&&(a.__uvArray=new Float32Array(2*e)),c.faceVertexUvs.length>1&&(a.__uv2Array=new Float32Array(2*e))),b.geometry.skinWeights.length&&b.geometry.skinIndices.length&&(a.__skinIndexArray=new Float32Array(4*e),a.__skinWeightArray=new Float32Array(4*e)),a.__faceArray=new Uint16Array(3*f),a.__lineArray=new Uint16Array(2*g);var p,q;if(a.numMorphTargets)for(a.__morphTargetsArrays=[],p=0,q=a.numMorphTargets;q>p;p++)a.__morphTargetsArrays.push(new Float32Array(3*e));if(a.numMorphNormals)for(a.__morphNormalsArrays=[],p=0,q=a.numMorphNormals;q>p;p++)a.__morphNormalsArrays.push(new Float32Array(3*e));if(a.__webglFaceCount=3*f,a.__webglLineCount=2*g,h.attributes){void 0===a.__webglCustomAttributesList&&(a.__webglCustomAttributesList=[]);for(var r in h.attributes){var s=h.attributes[r],t={};for(var u in s)t[u]=s[u];if(!t.__webglInitialized||t.createUniqueBuffers){t.__webglInitialized=!0;var v=1;"v2"===t.type?v=2:"v3"===t.type?v=3:"v4"===t.type?v=4:"c"===t.type&&(v=3),t.size=v,t.array=new Float32Array(e*v),t.buffer=Jb.createBuffer(),t.buffer.belongsToAttribute=r,s.needsUpdate=!0,t.__original=s}a.__webglCustomAttributesList.push(t)}}a.__inittedArrays=!0}function j(b,c){return b.material instanceof a.MeshFaceMaterial?b.material.materials[c.materialIndex]:b.material}function k(b){return b&&void 0!==b.shading&&b.shading===a.SmoothShading}function l(b){return b instanceof a.MeshBasicMaterial&&!b.envMap||b instanceof a.MeshDepthMaterial?!1:k(b)?a.SmoothShading:a.FlatShading}function m(a){return a.vertexColors?a.vertexColors:!1}function n(b){return b.map||b.lightMap||b.bumpMap||b.normalMap||b.specularMap||b instanceof a.ShaderMaterial?!0:!1}function o(a){var b,c,d;for(b in a.attributes)d="index"===b?Jb.ELEMENT_ARRAY_BUFFER:Jb.ARRAY_BUFFER,c=a.attributes[b],c.buffer=Jb.createBuffer(),Jb.bindBuffer(d,c.buffer),Jb.bufferData(d,c.array,Jb.STATIC_DRAW)}function p(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p=a.vertices,q=p.length,r=a.colors,s=r.length,t=a.__vertexArray,u=a.__colorArray,v=a.__sortArray,w=a.verticesNeedUpdate,x=(a.elementsNeedUpdate,a.colorsNeedUpdate),z=a.__webglCustomAttributesList;if(c.sortParticles){for(rc.copy(qc),rc.multiply(c.matrixWorld),d=0;q>d;d++)f=p[d],sc.copy(f),sc.applyProjection(rc),v[d]=[sc.z,d];for(v.sort(y),d=0;q>d;d++)f=p[v[d][1]],g=3*d,t[g]=f.x,t[g+1]=f.y,t[g+2]=f.z;for(e=0;s>e;e++)g=3*e,i=r[v[e][1]],u[g]=i.r,u[g+1]=i.g,u[g+2]=i.b;if(z)for(j=0,k=z.length;k>j;j++)if(o=z[j],void 0===o.boundTo||"vertices"===o.boundTo)if(g=0,m=o.value.length,1===o.size)for(l=0;m>l;l++)h=v[l][1],o.array[l]=o.value[h];else if(2===o.size)for(l=0;m>l;l++)h=v[l][1],n=o.value[h],o.array[g]=n.x,o.array[g+1]=n.y,g+=2;else if(3===o.size)if("c"===o.type)for(l=0;m>l;l++)h=v[l][1],n=o.value[h],o.array[g]=n.r,o.array[g+1]=n.g,o.array[g+2]=n.b,g+=3;else for(l=0;m>l;l++)h=v[l][1],n=o.value[h],o.array[g]=n.x,o.array[g+1]=n.y,o.array[g+2]=n.z,g+=3;else if(4===o.size)for(l=0;m>l;l++)h=v[l][1],n=o.value[h],o.array[g]=n.x,o.array[g+1]=n.y,o.array[g+2]=n.z,o.array[g+3]=n.w,g+=4}else{if(w)for(d=0;q>d;d++)f=p[d],g=3*d,t[g]=f.x,t[g+1]=f.y,t[g+2]=f.z;if(x)for(e=0;s>e;e++)i=r[e],g=3*e,u[g]=i.r,u[g+1]=i.g,u[g+2]=i.b;if(z)for(j=0,k=z.length;k>j;j++)if(o=z[j],o.needsUpdate&&(void 0===o.boundTo||"vertices"===o.boundTo))if(m=o.value.length,g=0,1===o.size)for(l=0;m>l;l++)o.array[l]=o.value[l];else if(2===o.size)for(l=0;m>l;l++)n=o.value[l],o.array[g]=n.x,o.array[g+1]=n.y,g+=2;else if(3===o.size)if("c"===o.type)for(l=0;m>l;l++)n=o.value[l],o.array[g]=n.r,o.array[g+1]=n.g,o.array[g+2]=n.b,g+=3;else for(l=0;m>l;l++)n=o.value[l],o.array[g]=n.x,o.array[g+1]=n.y,o.array[g+2]=n.z,g+=3;else if(4===o.size)for(l=0;m>l;l++)n=o.value[l],o.array[g]=n.x,o.array[g+1]=n.y,o.array[g+2]=n.z,o.array[g+3]=n.w,g+=4}if((w||c.sortParticles)&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,a.__webglVertexBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,t,b)),(x||c.sortParticles)&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,a.__webglColorBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,u,b)),z)for(j=0,k=z.length;k>j;j++)o=z[j],(o.needsUpdate||c.sortParticles)&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,o.buffer),Jb.bufferData(Jb.ARRAY_BUFFER,o.array,b))}function q(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o=a.vertices,p=a.colors,q=a.lineDistances,r=o.length,s=p.length,t=q.length,u=a.__vertexArray,v=a.__colorArray,w=a.__lineDistanceArray,x=a.verticesNeedUpdate,y=a.colorsNeedUpdate,z=a.lineDistancesNeedUpdate,A=a.__webglCustomAttributesList;
+if(x){for(c=0;r>c;c++)f=o[c],g=3*c,u[g]=f.x,u[g+1]=f.y,u[g+2]=f.z;Jb.bindBuffer(Jb.ARRAY_BUFFER,a.__webglVertexBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,u,b)}if(y){for(d=0;s>d;d++)h=p[d],g=3*d,v[g]=h.r,v[g+1]=h.g,v[g+2]=h.b;Jb.bindBuffer(Jb.ARRAY_BUFFER,a.__webglColorBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,v,b)}if(z){for(e=0;t>e;e++)w[e]=q[e];Jb.bindBuffer(Jb.ARRAY_BUFFER,a.__webglLineDistanceBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,w,b)}if(A)for(i=0,j=A.length;j>i;i++)if(n=A[i],n.needsUpdate&&(void 0===n.boundTo||"vertices"===n.boundTo)){if(g=0,l=n.value.length,1===n.size)for(k=0;l>k;k++)n.array[k]=n.value[k];else if(2===n.size)for(k=0;l>k;k++)m=n.value[k],n.array[g]=m.x,n.array[g+1]=m.y,g+=2;else if(3===n.size)if("c"===n.type)for(k=0;l>k;k++)m=n.value[k],n.array[g]=m.r,n.array[g+1]=m.g,n.array[g+2]=m.b,g+=3;else for(k=0;l>k;k++)m=n.value[k],n.array[g]=m.x,n.array[g+1]=m.y,n.array[g+2]=m.z,g+=3;else if(4===n.size)for(k=0;l>k;k++)m=n.value[k],n.array[g]=m.x,n.array[g+1]=m.y,n.array[g+2]=m.z,n.array[g+3]=m.w,g+=4;Jb.bindBuffer(Jb.ARRAY_BUFFER,n.buffer),Jb.bufferData(Jb.ARRAY_BUFFER,n.array,b)}}function r(b,c,d,e,f){if(b.__inittedArrays){var g,h,i,j,k,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z=l(f),$=m(f),_=n(f),ab=Z===a.SmoothShading,bb=0,cb=0,db=0,eb=0,fb=0,gb=0,hb=0,ib=0,jb=0,kb=0,lb=0,mb=0,nb=0,ob=b.__vertexArray,pb=b.__uvArray,qb=b.__uv2Array,rb=b.__normalArray,sb=b.__tangentArray,tb=b.__colorArray,ub=b.__skinIndexArray,vb=b.__skinWeightArray,wb=b.__morphTargetsArrays,xb=b.__morphNormalsArrays,yb=b.__webglCustomAttributesList,zb=b.__faceArray,Ab=b.__lineArray,Bb=c.geometry,Cb=Bb.verticesNeedUpdate,Db=Bb.elementsNeedUpdate,Eb=Bb.uvsNeedUpdate,Fb=Bb.normalsNeedUpdate,Gb=Bb.tangentsNeedUpdate,Hb=Bb.colorsNeedUpdate,Ib=Bb.morphTargetsNeedUpdate,Kb=Bb.vertices,Lb=b.faces3,Mb=Bb.faces,Nb=Bb.faceVertexUvs[0],Ob=Bb.faceVertexUvs[1],Pb=(Bb.colors,Bb.skinIndices),Qb=Bb.skinWeights,Rb=Bb.morphTargets,Sb=Bb.morphNormals;if(Cb){for(g=0,h=Lb.length;h>g;g++)j=Mb[Lb[g]],u=Kb[j.a],v=Kb[j.b],w=Kb[j.c],ob[cb]=u.x,ob[cb+1]=u.y,ob[cb+2]=u.z,ob[cb+3]=v.x,ob[cb+4]=v.y,ob[cb+5]=v.z,ob[cb+6]=w.x,ob[cb+7]=w.y,ob[cb+8]=w.z,cb+=9;Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglVertexBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,ob,d)}if(Ib)for(R=0,S=Rb.length;S>R;R++){for(lb=0,g=0,h=Lb.length;h>g;g++)V=Lb[g],j=Mb[V],u=Rb[R].vertices[j.a],v=Rb[R].vertices[j.b],w=Rb[R].vertices[j.c],T=wb[R],T[lb]=u.x,T[lb+1]=u.y,T[lb+2]=u.z,T[lb+3]=v.x,T[lb+4]=v.y,T[lb+5]=v.z,T[lb+6]=w.x,T[lb+7]=w.y,T[lb+8]=w.z,f.morphNormals&&(ab?(W=Sb[R].vertexNormals[V],A=W.a,B=W.b,C=W.c):(A=Sb[R].faceNormals[V],B=A,C=A),U=xb[R],U[lb]=A.x,U[lb+1]=A.y,U[lb+2]=A.z,U[lb+3]=B.x,U[lb+4]=B.y,U[lb+5]=B.z,U[lb+6]=C.x,U[lb+7]=C.y,U[lb+8]=C.z),lb+=9;Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglMorphTargetsBuffers[R]),Jb.bufferData(Jb.ARRAY_BUFFER,wb[R],d),f.morphNormals&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglMorphNormalsBuffers[R]),Jb.bufferData(Jb.ARRAY_BUFFER,xb[R],d))}if(Qb.length){for(g=0,h=Lb.length;h>g;g++)j=Mb[Lb[g]],G=Qb[j.a],H=Qb[j.b],I=Qb[j.c],vb[kb]=G.x,vb[kb+1]=G.y,vb[kb+2]=G.z,vb[kb+3]=G.w,vb[kb+4]=H.x,vb[kb+5]=H.y,vb[kb+6]=H.z,vb[kb+7]=H.w,vb[kb+8]=I.x,vb[kb+9]=I.y,vb[kb+10]=I.z,vb[kb+11]=I.w,J=Pb[j.a],K=Pb[j.b],L=Pb[j.c],ub[kb]=J.x,ub[kb+1]=J.y,ub[kb+2]=J.z,ub[kb+3]=J.w,ub[kb+4]=K.x,ub[kb+5]=K.y,ub[kb+6]=K.z,ub[kb+7]=K.w,ub[kb+8]=L.x,ub[kb+9]=L.y,ub[kb+10]=L.z,ub[kb+11]=L.w,kb+=12;kb>0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglSkinIndicesBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,ub,d),Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglSkinWeightsBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,vb,d))}if(Hb&&$){for(g=0,h=Lb.length;h>g;g++)j=Mb[Lb[g]],p=j.vertexColors,q=j.color,3===p.length&&$===a.VertexColors?(D=p[0],E=p[1],F=p[2]):(D=q,E=q,F=q),tb[jb]=D.r,tb[jb+1]=D.g,tb[jb+2]=D.b,tb[jb+3]=E.r,tb[jb+4]=E.g,tb[jb+5]=E.b,tb[jb+6]=F.r,tb[jb+7]=F.g,tb[jb+8]=F.b,jb+=9;jb>0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglColorBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,tb,d))}if(Gb&&Bb.hasTangents){for(g=0,h=Lb.length;h>g;g++)j=Mb[Lb[g]],r=j.vertexTangents,x=r[0],y=r[1],z=r[2],sb[hb]=x.x,sb[hb+1]=x.y,sb[hb+2]=x.z,sb[hb+3]=x.w,sb[hb+4]=y.x,sb[hb+5]=y.y,sb[hb+6]=y.z,sb[hb+7]=y.w,sb[hb+8]=z.x,sb[hb+9]=z.y,sb[hb+10]=z.z,sb[hb+11]=z.w,hb+=12;Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglTangentBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,sb,d)}if(Fb&&Z){for(g=0,h=Lb.length;h>g;g++)if(j=Mb[Lb[g]],k=j.vertexNormals,o=j.normal,3===k.length&&ab)for(M=0;3>M;M++)O=k[M],rb[gb]=O.x,rb[gb+1]=O.y,rb[gb+2]=O.z,gb+=3;else for(M=0;3>M;M++)rb[gb]=o.x,rb[gb+1]=o.y,rb[gb+2]=o.z,gb+=3;Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglNormalBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,rb,d)}if(Eb&&Nb&&_){for(g=0,h=Lb.length;h>g;g++)if(i=Lb[g],s=Nb[i],void 0!==s)for(M=0;3>M;M++)P=s[M],pb[db]=P.x,pb[db+1]=P.y,db+=2;db>0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglUVBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,pb,d))}if(Eb&&Ob&&_){for(g=0,h=Lb.length;h>g;g++)if(i=Lb[g],t=Ob[i],void 0!==t)for(M=0;3>M;M++)Q=t[M],qb[eb]=Q.x,qb[eb+1]=Q.y,eb+=2;eb>0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglUV2Buffer),Jb.bufferData(Jb.ARRAY_BUFFER,qb,d))}if(Db){for(g=0,h=Lb.length;h>g;g++)zb[fb]=bb,zb[fb+1]=bb+1,zb[fb+2]=bb+2,fb+=3,Ab[ib]=bb,Ab[ib+1]=bb+1,Ab[ib+2]=bb,Ab[ib+3]=bb+2,Ab[ib+4]=bb+1,Ab[ib+5]=bb+2,ib+=6,bb+=3;Jb.bindBuffer(Jb.ELEMENT_ARRAY_BUFFER,b.__webglFaceBuffer),Jb.bufferData(Jb.ELEMENT_ARRAY_BUFFER,zb,d),Jb.bindBuffer(Jb.ELEMENT_ARRAY_BUFFER,b.__webglLineBuffer),Jb.bufferData(Jb.ELEMENT_ARRAY_BUFFER,Ab,d)}if(yb)for(M=0,N=yb.length;N>M;M++)if(Y=yb[M],Y.__original.needsUpdate){if(mb=0,nb=0,1===Y.size){if(void 0===Y.boundTo||"vertices"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)j=Mb[Lb[g]],Y.array[mb]=Y.value[j.a],Y.array[mb+1]=Y.value[j.b],Y.array[mb+2]=Y.value[j.c],mb+=3;else if("faces"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)X=Y.value[Lb[g]],Y.array[mb]=X,Y.array[mb+1]=X,Y.array[mb+2]=X,mb+=3}else if(2===Y.size){if(void 0===Y.boundTo||"vertices"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)j=Mb[Lb[g]],u=Y.value[j.a],v=Y.value[j.b],w=Y.value[j.c],Y.array[mb]=u.x,Y.array[mb+1]=u.y,Y.array[mb+2]=v.x,Y.array[mb+3]=v.y,Y.array[mb+4]=w.x,Y.array[mb+5]=w.y,mb+=6;else if("faces"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)X=Y.value[Lb[g]],u=X,v=X,w=X,Y.array[mb]=u.x,Y.array[mb+1]=u.y,Y.array[mb+2]=v.x,Y.array[mb+3]=v.y,Y.array[mb+4]=w.x,Y.array[mb+5]=w.y,mb+=6}else if(3===Y.size){var Tb;if(Tb="c"===Y.type?["r","g","b"]:["x","y","z"],void 0===Y.boundTo||"vertices"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)j=Mb[Lb[g]],u=Y.value[j.a],v=Y.value[j.b],w=Y.value[j.c],Y.array[mb]=u[Tb[0]],Y.array[mb+1]=u[Tb[1]],Y.array[mb+2]=u[Tb[2]],Y.array[mb+3]=v[Tb[0]],Y.array[mb+4]=v[Tb[1]],Y.array[mb+5]=v[Tb[2]],Y.array[mb+6]=w[Tb[0]],Y.array[mb+7]=w[Tb[1]],Y.array[mb+8]=w[Tb[2]],mb+=9;else if("faces"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)X=Y.value[Lb[g]],u=X,v=X,w=X,Y.array[mb]=u[Tb[0]],Y.array[mb+1]=u[Tb[1]],Y.array[mb+2]=u[Tb[2]],Y.array[mb+3]=v[Tb[0]],Y.array[mb+4]=v[Tb[1]],Y.array[mb+5]=v[Tb[2]],Y.array[mb+6]=w[Tb[0]],Y.array[mb+7]=w[Tb[1]],Y.array[mb+8]=w[Tb[2]],mb+=9;else if("faceVertices"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)X=Y.value[Lb[g]],u=X[0],v=X[1],w=X[2],Y.array[mb]=u[Tb[0]],Y.array[mb+1]=u[Tb[1]],Y.array[mb+2]=u[Tb[2]],Y.array[mb+3]=v[Tb[0]],Y.array[mb+4]=v[Tb[1]],Y.array[mb+5]=v[Tb[2]],Y.array[mb+6]=w[Tb[0]],Y.array[mb+7]=w[Tb[1]],Y.array[mb+8]=w[Tb[2]],mb+=9}else if(4===Y.size)if(void 0===Y.boundTo||"vertices"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)j=Mb[Lb[g]],u=Y.value[j.a],v=Y.value[j.b],w=Y.value[j.c],Y.array[mb]=u.x,Y.array[mb+1]=u.y,Y.array[mb+2]=u.z,Y.array[mb+3]=u.w,Y.array[mb+4]=v.x,Y.array[mb+5]=v.y,Y.array[mb+6]=v.z,Y.array[mb+7]=v.w,Y.array[mb+8]=w.x,Y.array[mb+9]=w.y,Y.array[mb+10]=w.z,Y.array[mb+11]=w.w,mb+=12;else if("faces"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)X=Y.value[Lb[g]],u=X,v=X,w=X,Y.array[mb]=u.x,Y.array[mb+1]=u.y,Y.array[mb+2]=u.z,Y.array[mb+3]=u.w,Y.array[mb+4]=v.x,Y.array[mb+5]=v.y,Y.array[mb+6]=v.z,Y.array[mb+7]=v.w,Y.array[mb+8]=w.x,Y.array[mb+9]=w.y,Y.array[mb+10]=w.z,Y.array[mb+11]=w.w,mb+=12;else if("faceVertices"===Y.boundTo)for(g=0,h=Lb.length;h>g;g++)X=Y.value[Lb[g]],u=X[0],v=X[1],w=X[2],Y.array[mb]=u.x,Y.array[mb+1]=u.y,Y.array[mb+2]=u.z,Y.array[mb+3]=u.w,Y.array[mb+4]=v.x,Y.array[mb+5]=v.y,Y.array[mb+6]=v.z,Y.array[mb+7]=v.w,Y.array[mb+8]=w.x,Y.array[mb+9]=w.y,Y.array[mb+10]=w.z,Y.array[mb+11]=w.w,mb+=12;Jb.bindBuffer(Jb.ARRAY_BUFFER,Y.buffer),Jb.bufferData(Jb.ARRAY_BUFFER,Y.array,d)}e&&(delete b.__inittedArrays,delete b.__colorArray,delete b.__normalArray,delete b.__tangentArray,delete b.__uvArray,delete b.__uv2Array,delete b.__faceArray,delete b.__vertexArray,delete b.__lineArray,delete b.__skinIndexArray,delete b.__skinWeightArray)}}function s(a,b,c,d){var e,f,g,h;for(f in b)g=b[f],e=c[f],g>=0&&(e?(h=e.itemSize,Jb.bindBuffer(Jb.ARRAY_BUFFER,e.buffer),u(g),Jb.vertexAttribPointer(g,h,Jb.FLOAT,!1,0,d*h*4)):a.defaultAttributeValues&&(2===a.defaultAttributeValues[f].length?Jb.vertexAttrib2fv(g,a.defaultAttributeValues[f]):3===a.defaultAttributeValues[f].length&&Jb.vertexAttrib3fv(g,a.defaultAttributeValues[f])))}function t(a,b){var c,d,e=a.attributes;for(c in e)d=e[c],d.needsUpdate&&("index"===c?(Jb.bindBuffer(Jb.ELEMENT_ARRAY_BUFFER,d.buffer),Jb.bufferData(Jb.ELEMENT_ARRAY_BUFFER,d.array,b)):(Jb.bindBuffer(Jb.ARRAY_BUFFER,d.buffer),Jb.bufferData(Jb.ARRAY_BUFFER,d.array,b)),d.needsUpdate=!1)}function u(a){0===oc[a]&&(Jb.enableVertexAttribArray(a),oc[a]=1)}function v(){for(var a in oc)1===oc[a]&&(Jb.disableVertexAttribArray(a),oc[a]=0)}function w(a,b,c){var d=a.program.attributes;if(-1!==c.morphTargetBase&&d.position>=0?(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglMorphTargetsBuffers[c.morphTargetBase]),u(d.position),Jb.vertexAttribPointer(d.position,3,Jb.FLOAT,!1,0,0)):d.position>=0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglVertexBuffer),u(d.position),Jb.vertexAttribPointer(d.position,3,Jb.FLOAT,!1,0,0)),c.morphTargetForcedOrder.length)for(var e=0,f=c.morphTargetForcedOrder,g=c.morphTargetInfluences;e=0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglMorphTargetsBuffers[f[e]]),u(d["morphTarget"+e]),Jb.vertexAttribPointer(d["morphTarget"+e],3,Jb.FLOAT,!1,0,0)),d["morphNormal"+e]>=0&&a.morphNormals&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglMorphNormalsBuffers[f[e]]),u(d["morphNormal"+e]),Jb.vertexAttribPointer(d["morphNormal"+e],3,Jb.FLOAT,!1,0,0)),c.__webglMorphTargetInfluences[e]=g[f[e]],e++;else{var h,i,j=[],g=c.morphTargetInfluences,k=g.length;for(i=0;k>i;i++)h=g[i],h>0&&j.push([h,i]);j.length>a.numSupportedMorphTargets?(j.sort(y),j.length=a.numSupportedMorphTargets):j.length>a.numSupportedMorphNormals?j.sort(y):0===j.length&&j.push([0,0]);for(var l,e=0;e=0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglMorphTargetsBuffers[l]),u(d["morphTarget"+e]),Jb.vertexAttribPointer(d["morphTarget"+e],3,Jb.FLOAT,!1,0,0)),d["morphNormal"+e]>=0&&a.morphNormals&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglMorphNormalsBuffers[l]),u(d["morphNormal"+e]),Jb.vertexAttribPointer(d["morphNormal"+e],3,Jb.FLOAT,!1,0,0)),c.__webglMorphTargetInfluences[e]=g[l]):c.__webglMorphTargetInfluences[e]=0,e++}null!==a.program.uniforms.morphTargetInfluences&&Jb.uniform1fv(a.program.uniforms.morphTargetInfluences,c.__webglMorphTargetInfluences)}function x(a,b){return a.z!==b.z?b.z-a.z:a.id-b.id}function y(a,b){return b[0]-a[0]}function z(a,b,c){if(a.length)for(var d=0,e=a.length;e>d;d++)Sb=null,Wb=null,$b=-1,cc=-1,dc=-1,Yb=-1,Zb=-1,Vb=-1,Ub=-1,uc=!0,a[d].render(b,c,mc,nc),Sb=null,Wb=null,$b=-1,cc=-1,dc=-1,Yb=-1,Zb=-1,Vb=-1,Ub=-1,uc=!0}function A(b,c,d,e,f,g,h,i){var j,k,l,m,n,o,p;c?(n=b.length-1,o=-1,p=-1):(n=0,o=b.length,p=1);for(var q=n;q!==o;q+=p)if(j=b[q],j.render){if(k=j.object,l=j.buffer,i)m=i;else{if(m=j[d],!m)continue;h&&Pb.setBlending(m.blending,m.blendEquation,m.blendSrc,m.blendDst),Pb.setDepthTest(m.depthTest),Pb.setDepthWrite(m.depthWrite),eb(m.polygonOffset,m.polygonOffsetFactor,m.polygonOffsetUnits)}Pb.setMaterialFaces(m),l instanceof a.BufferGeometry?Pb.renderBufferDirect(e,f,g,m,l,k):Pb.renderBuffer(e,f,g,m,l,k)}}function B(a,b,c,d,e,f,g){for(var h,i,j,k=0,l=a.length;l>k;k++)if(h=a[k],i=h.object,i.visible){if(g)j=g;else{if(j=h[b],!j)continue;f&&Pb.setBlending(j.blending,j.blendEquation,j.blendSrc,j.blendDst),Pb.setDepthTest(j.depthTest),Pb.setDepthWrite(j.depthWrite),eb(j.polygonOffset,j.polygonOffsetFactor,j.polygonOffsetUnits)}Pb.renderImmediateObject(c,d,e,j,i)}}function C(a){var b=a.object,c=b.material;c.transparent?(a.transparent=c,a.opaque=null):(a.opaque=c,a.transparent=null)}function D(b){var c=b.object,d=b.buffer,e=c.geometry,f=c.material;if(f instanceof a.MeshFaceMaterial){var g=e instanceof a.BufferGeometry?0:d.materialIndex;f=f.materials[g],f.transparent?(b.transparent=f,b.opaque=null):(b.opaque=f,b.transparent=null)}else f&&(f.transparent?(b.transparent=f,b.opaque=null):(b.opaque=f,b.transparent=null))}function E(b,f){var j,k,l,m;if(void 0===b.__webglInit)if(b.__webglInit=!0,b._modelViewMatrix=new a.Matrix4,b._normalMatrix=new a.Matrix3,void 0!==b.geometry&&void 0===b.geometry.__webglInit&&(b.geometry.__webglInit=!0,b.geometry.addEventListener("dispose",Ic)),k=b.geometry,void 0===k);else if(k instanceof a.BufferGeometry)o(k);else if(b instanceof a.Mesh){l=b.material,void 0===k.geometryGroups&&k.makeGroups(l instanceof a.MeshFaceMaterial);for(j in k.geometryGroups)m=k.geometryGroups[j],m.__webglVertexBuffer||(e(m),i(m,b),k.verticesNeedUpdate=!0,k.morphTargetsNeedUpdate=!0,k.elementsNeedUpdate=!0,k.uvsNeedUpdate=!0,k.normalsNeedUpdate=!0,k.tangentsNeedUpdate=!0,k.colorsNeedUpdate=!0)}else b instanceof a.Line?k.__webglVertexBuffer||(d(k),h(k,b),k.verticesNeedUpdate=!0,k.colorsNeedUpdate=!0,k.lineDistancesNeedUpdate=!0):b instanceof a.ParticleSystem&&(k.__webglVertexBuffer||(c(k),g(k,b),k.verticesNeedUpdate=!0,k.colorsNeedUpdate=!0));if(void 0===b.__webglActive){if(b instanceof a.Mesh){if(k=b.geometry,k instanceof a.BufferGeometry)F(f.__webglObjects,k,b);else if(k instanceof a.Geometry)for(j in k.geometryGroups)m=k.geometryGroups[j],F(f.__webglObjects,m,b)}else b instanceof a.Line||b instanceof a.ParticleSystem?(k=b.geometry,F(f.__webglObjects,k,b)):b instanceof a.ImmediateRenderObject||b.immediateRenderCallback?G(f.__webglObjectsImmediate,b):b instanceof a.Sprite?f.__webglSprites.push(b):b instanceof a.LensFlare&&f.__webglFlares.push(b);b.__webglActive=!0}}function F(a,b,c){a.push({id:null,buffer:b,object:c,opaque:null,transparent:null,z:0})}function G(a,b){a.push({id:null,object:b,opaque:null,transparent:null,z:0})}function H(b){var c,d,e,f=b.geometry;if(f instanceof a.BufferGeometry)t(f,Jb.DYNAMIC_DRAW);else if(b instanceof a.Mesh){for(var g=0,h=f.geometryGroupsList.length;h>g;g++)c=f.geometryGroupsList[g],e=j(b,c),f.buffersNeedUpdate&&i(c,b),d=e.attributes&&I(e),(f.verticesNeedUpdate||f.morphTargetsNeedUpdate||f.elementsNeedUpdate||f.uvsNeedUpdate||f.normalsNeedUpdate||f.colorsNeedUpdate||f.tangentsNeedUpdate||d)&&r(c,b,Jb.DYNAMIC_DRAW,!f.dynamic,e);f.verticesNeedUpdate=!1,f.morphTargetsNeedUpdate=!1,f.elementsNeedUpdate=!1,f.uvsNeedUpdate=!1,f.normalsNeedUpdate=!1,f.colorsNeedUpdate=!1,f.tangentsNeedUpdate=!1,f.buffersNeedUpdate=!1,e.attributes&&J(e)}else b instanceof a.Line?(e=j(b,f),d=e.attributes&&I(e),(f.verticesNeedUpdate||f.colorsNeedUpdate||f.lineDistancesNeedUpdate||d)&&q(f,Jb.DYNAMIC_DRAW),f.verticesNeedUpdate=!1,f.colorsNeedUpdate=!1,f.lineDistancesNeedUpdate=!1,e.attributes&&J(e)):b instanceof a.ParticleSystem&&(e=j(b,f),d=e.attributes&&I(e),(f.verticesNeedUpdate||f.colorsNeedUpdate||b.sortParticles||d)&&p(f,Jb.DYNAMIC_DRAW,b),f.verticesNeedUpdate=!1,f.colorsNeedUpdate=!1,e.attributes&&J(e))}function I(a){for(var b in a.attributes)if(a.attributes[b].needsUpdate)return!0;return!1}function J(a){for(var b in a.attributes)a.attributes[b].needsUpdate=!1}function K(b,c){b instanceof a.Mesh||b instanceof a.ParticleSystem||b instanceof a.Line?L(c.__webglObjects,b):b instanceof a.Sprite?M(c.__webglSprites,b):b instanceof a.LensFlare?M(c.__webglFlares,b):(b instanceof a.ImmediateRenderObject||b.immediateRenderCallback)&&L(c.__webglObjectsImmediate,b),delete b.__webglActive}function L(a,b){for(var c=a.length-1;c>=0;c--)a[c].object===b&&a.splice(c,1)}function M(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function N(b,c){b.uniforms=a.UniformsUtils.clone(c.uniforms),b.vertexShader=c.vertexShader,b.fragmentShader=c.fragmentShader}function O(b,c,d,e,f){Xb=0,e.needsUpdate&&(e.program&&Qc(e),Pb.initMaterial(e,c,d,f),e.needsUpdate=!1),e.morphTargets&&(f.__webglMorphTargetInfluences||(f.__webglMorphTargetInfluences=new Float32Array(Pb.maxMorphTargets)));var g=!1,h=e.program,i=h.uniforms,j=e.uniforms;if(h!==Sb&&(Jb.useProgram(h),Sb=h,g=!0),e.id!==Ub&&(Ub=e.id,g=!0),(g||b!==Wb)&&(Jb.uniformMatrix4fv(i.projectionMatrix,!1,b.projectionMatrix.elements),b!==Wb&&(Wb=b)),e.skinning)if(Bc&&f.useVertexTexture){if(null!==i.boneTexture){var k=Z();Jb.uniform1i(i.boneTexture,k),Pb.setTexture(f.boneTexture,k)}null!==i.boneTextureWidth&&Jb.uniform1i(i.boneTextureWidth,f.boneTextureWidth),null!==i.boneTextureHeight&&Jb.uniform1i(i.boneTextureHeight,f.boneTextureHeight)}else null!==i.boneGlobalMatrices&&Jb.uniformMatrix4fv(i.boneGlobalMatrices,!1,f.boneMatrices);return g&&(d&&e.fog&&T(j,d),(e instanceof a.MeshPhongMaterial||e instanceof a.MeshLambertMaterial||e.lights)&&(uc&&(cb(h,c),uc=!1),W(j,vc)),(e instanceof a.MeshBasicMaterial||e instanceof a.MeshLambertMaterial||e instanceof a.MeshPhongMaterial)&&P(j,e),e instanceof a.LineBasicMaterial?Q(j,e):e instanceof a.LineDashedMaterial?(Q(j,e),R(j,e)):e instanceof a.ParticleSystemMaterial?S(j,e):e instanceof a.MeshPhongMaterial?U(j,e):e instanceof a.MeshLambertMaterial?V(j,e):e instanceof a.MeshDepthMaterial?(j.mNear.value=b.near,j.mFar.value=b.far,j.opacity.value=e.opacity):e instanceof a.MeshNormalMaterial&&(j.opacity.value=e.opacity),f.receiveShadow&&!e._shadowPass&&X(j,c),$(h,e.uniformsList),(e instanceof a.ShaderMaterial||e instanceof a.MeshPhongMaterial||e.envMap)&&null!==i.cameraPosition&&(sc.setFromMatrixPosition(b.matrixWorld),Jb.uniform3f(i.cameraPosition,sc.x,sc.y,sc.z)),(e instanceof a.MeshPhongMaterial||e instanceof a.MeshLambertMaterial||e instanceof a.ShaderMaterial||e.skinning)&&null!==i.viewMatrix&&Jb.uniformMatrix4fv(i.viewMatrix,!1,b.matrixWorldInverse.elements)),Y(i,f),null!==i.modelMatrix&&Jb.uniformMatrix4fv(i.modelMatrix,!1,f.matrixWorld.elements),h}function P(b,c){b.opacity.value=c.opacity,Pb.gammaInput?b.diffuse.value.copyGammaToLinear(c.color):b.diffuse.value=c.color,b.map.value=c.map,b.lightMap.value=c.lightMap,b.specularMap.value=c.specularMap,c.bumpMap&&(b.bumpMap.value=c.bumpMap,b.bumpScale.value=c.bumpScale),c.normalMap&&(b.normalMap.value=c.normalMap,b.normalScale.value.copy(c.normalScale));var d;if(c.map?d=c.map:c.specularMap?d=c.specularMap:c.normalMap?d=c.normalMap:c.bumpMap&&(d=c.bumpMap),void 0!==d){var e=d.offset,f=d.repeat;b.offsetRepeat.value.set(e.x,e.y,f.x,f.y)}b.envMap.value=c.envMap,b.flipEnvMap.value=c.envMap instanceof a.WebGLRenderTargetCube?1:-1,b.reflectivity.value=Pb.gammaInput?c.reflectivity:c.reflectivity,b.refractionRatio.value=c.refractionRatio,b.combine.value=c.combine,b.useRefract.value=c.envMap&&c.envMap.mapping instanceof a.CubeRefractionMapping}function Q(a,b){a.diffuse.value=b.color,a.opacity.value=b.opacity}function R(a,b){a.dashSize.value=b.dashSize,a.totalSize.value=b.dashSize+b.gapSize,a.scale.value=b.scale}function S(a,b){a.psColor.value=b.color,a.opacity.value=b.opacity,a.size.value=b.size,a.scale.value=zb.height/2,a.map.value=b.map}function T(b,c){b.fogColor.value=c.color,c instanceof a.Fog?(b.fogNear.value=c.near,b.fogFar.value=c.far):c instanceof a.FogExp2&&(b.fogDensity.value=c.density)}function U(a,b){a.shininess.value=b.shininess,Pb.gammaInput?(a.ambient.value.copyGammaToLinear(b.ambient),a.emissive.value.copyGammaToLinear(b.emissive),a.specular.value.copyGammaToLinear(b.specular)):(a.ambient.value=b.ambient,a.emissive.value=b.emissive,a.specular.value=b.specular),b.wrapAround&&a.wrapRGB.value.copy(b.wrapRGB)}function V(a,b){Pb.gammaInput?(a.ambient.value.copyGammaToLinear(b.ambient),a.emissive.value.copyGammaToLinear(b.emissive)):(a.ambient.value=b.ambient,a.emissive.value=b.emissive),b.wrapAround&&a.wrapRGB.value.copy(b.wrapRGB)}function W(a,b){a.ambientLightColor.value=b.ambient,a.directionalLightColor.value=b.directional.colors,a.directionalLightDirection.value=b.directional.positions,a.pointLightColor.value=b.point.colors,a.pointLightPosition.value=b.point.positions,a.pointLightDistance.value=b.point.distances,a.spotLightColor.value=b.spot.colors,a.spotLightPosition.value=b.spot.positions,a.spotLightDistance.value=b.spot.distances,a.spotLightDirection.value=b.spot.directions,a.spotLightAngleCos.value=b.spot.anglesCos,a.spotLightExponent.value=b.spot.exponents,a.hemisphereLightSkyColor.value=b.hemi.skyColors,a.hemisphereLightGroundColor.value=b.hemi.groundColors,a.hemisphereLightDirection.value=b.hemi.positions}function X(b,c){if(b.shadowMatrix)for(var d=0,e=0,f=c.length;f>e;e++){var g=c[e];g.castShadow&&(g instanceof a.SpotLight||g instanceof a.DirectionalLight&&!g.shadowCascade)&&(b.shadowMap.value[d]=g.shadowMap,b.shadowMapSize.value[d]=g.shadowMapSize,b.shadowMatrix.value[d]=g.shadowMatrix,b.shadowDarkness.value[d]=g.shadowDarkness,b.shadowBias.value[d]=g.shadowBias,d++)}}function Y(a,b){Jb.uniformMatrix4fv(a.modelViewMatrix,!1,b._modelViewMatrix.elements),a.normalMatrix&&Jb.uniformMatrix3fv(a.normalMatrix,!1,b._normalMatrix.elements)}function Z(){var a=Xb;return a>=wc&&console.warn("WebGLRenderer: trying to use "+a+" texture units while this GPU supports only "+wc),Xb+=1,a}function $(b,c){var d,e,f,g,h,i,j,k,l,m,n;for(l=0,m=c.length;m>l;l++)if(g=b.uniforms[c[l][1]])if(d=c[l][0],f=d.type,e=d.value,"i"===f)Jb.uniform1i(g,e);else if("f"===f)Jb.uniform1f(g,e);else if("v2"===f)Jb.uniform2f(g,e.x,e.y);else if("v3"===f)Jb.uniform3f(g,e.x,e.y,e.z);else if("v4"===f)Jb.uniform4f(g,e.x,e.y,e.z,e.w);else if("c"===f)Jb.uniform3f(g,e.r,e.g,e.b);else if("iv1"===f)Jb.uniform1iv(g,e);else if("iv"===f)Jb.uniform3iv(g,e);else if("fv1"===f)Jb.uniform1fv(g,e);else if("fv"===f)Jb.uniform3fv(g,e);else if("v2v"===f){for(void 0===d._array&&(d._array=new Float32Array(2*e.length)),j=0,k=e.length;k>j;j++)n=2*j,d._array[n]=e[j].x,d._array[n+1]=e[j].y;Jb.uniform2fv(g,d._array)}else if("v3v"===f){for(void 0===d._array&&(d._array=new Float32Array(3*e.length)),j=0,k=e.length;k>j;j++)n=3*j,d._array[n]=e[j].x,d._array[n+1]=e[j].y,d._array[n+2]=e[j].z;Jb.uniform3fv(g,d._array)}else if("v4v"===f){for(void 0===d._array&&(d._array=new Float32Array(4*e.length)),j=0,k=e.length;k>j;j++)n=4*j,d._array[n]=e[j].x,d._array[n+1]=e[j].y,d._array[n+2]=e[j].z,d._array[n+3]=e[j].w;Jb.uniform4fv(g,d._array)}else if("m4"===f)void 0===d._array&&(d._array=new Float32Array(16)),e.flattenToArray(d._array),Jb.uniformMatrix4fv(g,!1,d._array);else if("m4v"===f){for(void 0===d._array&&(d._array=new Float32Array(16*e.length)),j=0,k=e.length;k>j;j++)e[j].flattenToArrayOffset(d._array,16*j);Jb.uniformMatrix4fv(g,!1,d._array)}else if("t"===f){if(h=e,i=Z(),Jb.uniform1i(g,i),!h)continue;h.image instanceof Array&&6===h.image.length?nb(h,i):h instanceof a.WebGLRenderTargetCube?ob(h,i):Pb.setTexture(h,i)}else if("tv"===f){for(void 0===d._array&&(d._array=[]),j=0,k=d.value.length;k>j;j++)d._array[j]=Z();for(Jb.uniform1iv(g,d._array),j=0,k=d.value.length;k>j;j++)h=d.value[j],i=d._array[j],h&&Pb.setTexture(h,i)}else console.warn("THREE.WebGLRenderer: Unknown uniform type: "+f)}function _(a,b){a._modelViewMatrix.multiplyMatrices(b.matrixWorldInverse,a.matrixWorld),a._normalMatrix.getNormalMatrix(a._modelViewMatrix)}function ab(a,b,c,d){a[b]=c.r*c.r*d,a[b+1]=c.g*c.g*d,a[b+2]=c.b*c.b*d}function bb(a,b,c,d){a[b]=c.r*d,a[b+1]=c.g*d,a[b+2]=c.b*d}function cb(b,c){var d,e,f,g,h,i,j,k,l,m=0,n=0,o=0,p=vc,q=p.directional.colors,r=p.directional.positions,s=p.point.colors,t=p.point.positions,u=p.point.distances,v=p.spot.colors,w=p.spot.positions,x=p.spot.distances,y=p.spot.directions,z=p.spot.anglesCos,A=p.spot.exponents,B=p.hemi.skyColors,C=p.hemi.groundColors,D=p.hemi.positions,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0;for(d=0,e=c.length;e>d;d++)if(f=c[d],!f.onlyShadow)if(g=f.color,j=f.intensity,l=f.distance,f instanceof a.AmbientLight){if(!f.visible)continue;Pb.gammaInput?(m+=g.r*g.r,n+=g.g*g.g,o+=g.b*g.b):(m+=g.r,n+=g.g,o+=g.b)}else if(f instanceof a.DirectionalLight){if(I+=1,!f.visible)continue;if(tc.setFromMatrixPosition(f.matrixWorld),sc.setFromMatrixPosition(f.target.matrixWorld),tc.sub(sc),tc.normalize(),0===tc.x&&0===tc.y&&0===tc.z)continue;M=3*E,r[M]=tc.x,r[M+1]=tc.y,r[M+2]=tc.z,Pb.gammaInput?ab(q,M,g,j*j):bb(q,M,g,j),E+=1}else if(f instanceof a.PointLight){if(J+=1,!f.visible)continue;N=3*F,Pb.gammaInput?ab(s,N,g,j*j):bb(s,N,g,j),sc.setFromMatrixPosition(f.matrixWorld),t[N]=sc.x,t[N+1]=sc.y,t[N+2]=sc.z,u[F]=l,F+=1}else if(f instanceof a.SpotLight){if(K+=1,!f.visible)continue;O=3*G,Pb.gammaInput?ab(v,O,g,j*j):bb(v,O,g,j),sc.setFromMatrixPosition(f.matrixWorld),w[O]=sc.x,w[O+1]=sc.y,w[O+2]=sc.z,x[G]=l,tc.copy(sc),sc.setFromMatrixPosition(f.target.matrixWorld),tc.sub(sc),tc.normalize(),y[O]=tc.x,y[O+1]=tc.y,y[O+2]=tc.z,z[G]=Math.cos(f.angle),A[G]=f.exponent,G+=1}else if(f instanceof a.HemisphereLight){if(L+=1,!f.visible)continue;if(tc.setFromMatrixPosition(f.matrixWorld),tc.normalize(),0===tc.x&&0===tc.y&&0===tc.z)continue;P=3*H,D[P]=tc.x,D[P+1]=tc.y,D[P+2]=tc.z,h=f.color,i=f.groundColor,Pb.gammaInput?(k=j*j,ab(B,P,h,k),ab(C,P,i,k)):(bb(B,P,h,j),bb(C,P,i,j)),H+=1}for(d=3*E,e=Math.max(q.length,3*I);e>d;d++)q[d]=0;for(d=3*F,e=Math.max(s.length,3*J);e>d;d++)s[d]=0;for(d=3*G,e=Math.max(v.length,3*K);e>d;d++)v[d]=0;for(d=3*H,e=Math.max(B.length,3*L);e>d;d++)B[d]=0;for(d=3*H,e=Math.max(C.length,3*L);e>d;d++)C[d]=0;p.directional.length=E,p.point.length=F,p.spot.length=G,p.hemi.length=H,p.ambient[0]=m,p.ambient[1]=n,p.ambient[2]=o}function db(a){a!==hc&&(Jb.lineWidth(a),hc=a)}function eb(a,b,c){ec!==a&&(a?Jb.enable(Jb.POLYGON_OFFSET_FILL):Jb.disable(Jb.POLYGON_OFFSET_FILL),ec=a),!a||fc===b&&gc===c||(Jb.polygonOffset(b,c),fc=b,gc=c)}function fb(a){var b,c,d=[];for(var e in a)b=a[e],b!==!1&&(c="#define "+e+" "+b,d.push(c));return d.join("\n")}function gb(b,c,d,e,f,g,h,i){var j,k,l,m,n,o=[];b?o.push(b):(o.push(c),o.push(d));for(l in g)o.push(l),o.push(g[l]);for(j in h)o.push(j),o.push(h[j]);for(n=o.join(),j=0,k=Qb.length;k>j;j++){var p=Qb[j];if(p.code===n)return p.usedTimes++,p.program}var q="SHADOWMAP_TYPE_BASIC";h.shadowMapType===a.PCFShadowMap?q="SHADOWMAP_TYPE_PCF":h.shadowMapType===a.PCFSoftShadowMap&&(q="SHADOWMAP_TYPE_PCF_SOFT");var r=fb(g);m=Jb.createProgram();var s=["precision "+Bb+" float;","precision "+Bb+" int;",r,Ac?"#define VERTEX_TEXTURES":"",Pb.gammaInput?"#define GAMMA_INPUT":"",Pb.gammaOutput?"#define GAMMA_OUTPUT":"","#define MAX_DIR_LIGHTS "+h.maxDirLights,"#define MAX_POINT_LIGHTS "+h.maxPointLights,"#define MAX_SPOT_LIGHTS "+h.maxSpotLights,"#define MAX_HEMI_LIGHTS "+h.maxHemiLights,"#define MAX_SHADOWS "+h.maxShadows,"#define MAX_BONES "+h.maxBones,h.map?"#define USE_MAP":"",h.envMap?"#define USE_ENVMAP":"",h.lightMap?"#define USE_LIGHTMAP":"",h.bumpMap?"#define USE_BUMPMAP":"",h.normalMap?"#define USE_NORMALMAP":"",h.specularMap?"#define USE_SPECULARMAP":"",h.vertexColors?"#define USE_COLOR":"",h.skinning?"#define USE_SKINNING":"",h.useVertexTexture?"#define BONE_TEXTURE":"",h.morphTargets?"#define USE_MORPHTARGETS":"",h.morphNormals?"#define USE_MORPHNORMALS":"",h.wrapAround?"#define WRAP_AROUND":"",h.doubleSided?"#define DOUBLE_SIDED":"",h.flipSided?"#define FLIP_SIDED":"",h.shadowMapEnabled?"#define USE_SHADOWMAP":"",h.shadowMapEnabled?"#define "+q:"",h.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",h.shadowMapCascade?"#define SHADOWMAP_CASCADE":"",h.sizeAttenuation?"#define USE_SIZEATTENUATION":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","attribute vec2 uv2;","#ifdef USE_COLOR","attribute vec3 color;","#endif","#ifdef USE_MORPHTARGETS","attribute vec3 morphTarget0;","attribute vec3 morphTarget1;","attribute vec3 morphTarget2;","attribute vec3 morphTarget3;","#ifdef USE_MORPHNORMALS","attribute vec3 morphNormal0;","attribute vec3 morphNormal1;","attribute vec3 morphNormal2;","attribute vec3 morphNormal3;","#else","attribute vec3 morphTarget4;","attribute vec3 morphTarget5;","attribute vec3 morphTarget6;","attribute vec3 morphTarget7;","#endif","#endif","#ifdef USE_SKINNING","attribute vec4 skinIndex;","attribute vec4 skinWeight;","#endif",""].join("\n"),t=["precision "+Bb+" float;","precision "+Bb+" int;",h.bumpMap||h.normalMap?"#extension GL_OES_standard_derivatives : enable":"",r,"#define MAX_DIR_LIGHTS "+h.maxDirLights,"#define MAX_POINT_LIGHTS "+h.maxPointLights,"#define MAX_SPOT_LIGHTS "+h.maxSpotLights,"#define MAX_HEMI_LIGHTS "+h.maxHemiLights,"#define MAX_SHADOWS "+h.maxShadows,h.alphaTest?"#define ALPHATEST "+h.alphaTest:"",Pb.gammaInput?"#define GAMMA_INPUT":"",Pb.gammaOutput?"#define GAMMA_OUTPUT":"",h.useFog&&h.fog?"#define USE_FOG":"",h.useFog&&h.fogExp?"#define FOG_EXP2":"",h.map?"#define USE_MAP":"",h.envMap?"#define USE_ENVMAP":"",h.lightMap?"#define USE_LIGHTMAP":"",h.bumpMap?"#define USE_BUMPMAP":"",h.normalMap?"#define USE_NORMALMAP":"",h.specularMap?"#define USE_SPECULARMAP":"",h.vertexColors?"#define USE_COLOR":"",h.metal?"#define METAL":"",h.wrapAround?"#define WRAP_AROUND":"",h.doubleSided?"#define DOUBLE_SIDED":"",h.flipSided?"#define FLIP_SIDED":"",h.shadowMapEnabled?"#define USE_SHADOWMAP":"",h.shadowMapEnabled?"#define "+q:"",h.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",h.shadowMapCascade?"#define SHADOWMAP_CASCADE":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;",""].join("\n"),u=kb("vertex",s+d),v=kb("fragment",t+c);Jb.attachShader(m,u),Jb.attachShader(m,v),void 0!==i&&Jb.bindAttribLocation(m,0,i),Jb.linkProgram(m),Jb.getProgramParameter(m,Jb.LINK_STATUS)===!1&&(console.error("Could not initialise shader"),console.error("gl.VALIDATE_STATUS",Jb.getProgramParameter(m,Jb.VALIDATE_STATUS)),console.error("gl.getError()",Jb.getError())),""!==Jb.getProgramInfoLog(m)&&console.error("gl.getProgramInfoLog()",Jb.getProgramInfoLog(m)),Jb.deleteShader(v),Jb.deleteShader(u),m.uniforms={},m.attributes={};var w,x,y,z;w=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","modelMatrix","cameraPosition","morphTargetInfluences"],h.useVertexTexture?(w.push("boneTexture"),w.push("boneTextureWidth"),w.push("boneTextureHeight")):w.push("boneGlobalMatrices");for(x in e)w.push(x);for(hb(m,w),w=["position","normal","uv","uv2","tangent","color","skinIndex","skinWeight","lineDistance"],z=0;zc;c++)e=b[c],a.uniforms[e]=Jb.getUniformLocation(a,e)}function ib(a,b){var c,d,e;for(c=0,d=b.length;d>c;c++)e=b[c],a.attributes[e]=Jb.getAttribLocation(a,e)}function jb(a){for(var b=a.split("\n"),c=0,d=b.length;d>c;c++)b[c]=c+1+": "+b[c];return b.join("\n")}function kb(a,b){var c;return"fragment"===a?c=Jb.createShader(Jb.FRAGMENT_SHADER):"vertex"===a&&(c=Jb.createShader(Jb.VERTEX_SHADER)),Jb.shaderSource(c,b),Jb.compileShader(c),Jb.getShaderParameter(c,Jb.COMPILE_STATUS)?c:(console.error(Jb.getShaderInfoLog(c)),console.error(jb(b)),null)}function lb(b,c,d){d?(Jb.texParameteri(b,Jb.TEXTURE_WRAP_S,tb(c.wrapS)),Jb.texParameteri(b,Jb.TEXTURE_WRAP_T,tb(c.wrapT)),Jb.texParameteri(b,Jb.TEXTURE_MAG_FILTER,tb(c.magFilter)),Jb.texParameteri(b,Jb.TEXTURE_MIN_FILTER,tb(c.minFilter))):(Jb.texParameteri(b,Jb.TEXTURE_WRAP_S,Jb.CLAMP_TO_EDGE),Jb.texParameteri(b,Jb.TEXTURE_WRAP_T,Jb.CLAMP_TO_EDGE),Jb.texParameteri(b,Jb.TEXTURE_MAG_FILTER,sb(c.magFilter)),Jb.texParameteri(b,Jb.TEXTURE_MIN_FILTER,sb(c.minFilter))),Nb&&c.type!==a.FloatType&&(c.anisotropy>1||c.__oldAnisotropy)&&(Jb.texParameterf(b,Nb.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(c.anisotropy,zc)),c.__oldAnisotropy=c.anisotropy)
+}function mb(a,b){if(a.width<=b&&a.height<=b)return a;var c=Math.max(a.width,a.height),d=Math.floor(a.width*b/c),e=Math.floor(a.height*b/c),f=document.createElement("canvas");f.width=d,f.height=e;var g=f.getContext("2d");return g.drawImage(a,0,0,a.width,a.height,0,0,d,e),f}function nb(b,c){if(6===b.image.length)if(b.needsUpdate){b.image.__webglTextureCube||(b.addEventListener("dispose",Jc),b.image.__webglTextureCube=Jb.createTexture(),Pb.info.memory.textures++),Jb.activeTexture(Jb.TEXTURE0+c),Jb.bindTexture(Jb.TEXTURE_CUBE_MAP,b.image.__webglTextureCube),Jb.pixelStorei(Jb.UNPACK_FLIP_Y_WEBGL,b.flipY);for(var d=b instanceof a.CompressedTexture,e=[],f=0;6>f;f++)e[f]=Pb.autoScaleCubemaps&&!d?mb(b.image[f],yc):b.image[f];var g=e[0],h=a.Math.isPowerOfTwo(g.width)&&a.Math.isPowerOfTwo(g.height),i=tb(b.format),j=tb(b.type);lb(Jb.TEXTURE_CUBE_MAP,b,h);for(var f=0;6>f;f++)if(d)for(var k,l=e[f].mipmaps,m=0,n=l.length;n>m;m++)k=l[m],b.format!==a.RGBAFormat?Jb.compressedTexImage2D(Jb.TEXTURE_CUBE_MAP_POSITIVE_X+f,m,i,k.width,k.height,0,k.data):Jb.texImage2D(Jb.TEXTURE_CUBE_MAP_POSITIVE_X+f,m,i,k.width,k.height,0,i,j,k.data);else Jb.texImage2D(Jb.TEXTURE_CUBE_MAP_POSITIVE_X+f,0,i,i,j,e[f]);b.generateMipmaps&&h&&Jb.generateMipmap(Jb.TEXTURE_CUBE_MAP),b.needsUpdate=!1,b.onUpdate&&b.onUpdate()}else Jb.activeTexture(Jb.TEXTURE0+c),Jb.bindTexture(Jb.TEXTURE_CUBE_MAP,b.image.__webglTextureCube)}function ob(a,b){Jb.activeTexture(Jb.TEXTURE0+b),Jb.bindTexture(Jb.TEXTURE_CUBE_MAP,a.__webglTexture)}function pb(a,b,c){Jb.bindFramebuffer(Jb.FRAMEBUFFER,a),Jb.framebufferTexture2D(Jb.FRAMEBUFFER,Jb.COLOR_ATTACHMENT0,c,b.__webglTexture,0)}function qb(a,b){Jb.bindRenderbuffer(Jb.RENDERBUFFER,a),b.depthBuffer&&!b.stencilBuffer?(Jb.renderbufferStorage(Jb.RENDERBUFFER,Jb.DEPTH_COMPONENT16,b.width,b.height),Jb.framebufferRenderbuffer(Jb.FRAMEBUFFER,Jb.DEPTH_ATTACHMENT,Jb.RENDERBUFFER,a)):b.depthBuffer&&b.stencilBuffer?(Jb.renderbufferStorage(Jb.RENDERBUFFER,Jb.DEPTH_STENCIL,b.width,b.height),Jb.framebufferRenderbuffer(Jb.FRAMEBUFFER,Jb.DEPTH_STENCIL_ATTACHMENT,Jb.RENDERBUFFER,a)):Jb.renderbufferStorage(Jb.RENDERBUFFER,Jb.RGBA4,b.width,b.height)}function rb(b){b instanceof a.WebGLRenderTargetCube?(Jb.bindTexture(Jb.TEXTURE_CUBE_MAP,b.__webglTexture),Jb.generateMipmap(Jb.TEXTURE_CUBE_MAP),Jb.bindTexture(Jb.TEXTURE_CUBE_MAP,null)):(Jb.bindTexture(Jb.TEXTURE_2D,b.__webglTexture),Jb.generateMipmap(Jb.TEXTURE_2D),Jb.bindTexture(Jb.TEXTURE_2D,null))}function sb(b){return b===a.NearestFilter||b===a.NearestMipMapNearestFilter||b===a.NearestMipMapLinearFilter?Jb.NEAREST:Jb.LINEAR}function tb(b){if(b===a.RepeatWrapping)return Jb.REPEAT;if(b===a.ClampToEdgeWrapping)return Jb.CLAMP_TO_EDGE;if(b===a.MirroredRepeatWrapping)return Jb.MIRRORED_REPEAT;if(b===a.NearestFilter)return Jb.NEAREST;if(b===a.NearestMipMapNearestFilter)return Jb.NEAREST_MIPMAP_NEAREST;if(b===a.NearestMipMapLinearFilter)return Jb.NEAREST_MIPMAP_LINEAR;if(b===a.LinearFilter)return Jb.LINEAR;if(b===a.LinearMipMapNearestFilter)return Jb.LINEAR_MIPMAP_NEAREST;if(b===a.LinearMipMapLinearFilter)return Jb.LINEAR_MIPMAP_LINEAR;if(b===a.UnsignedByteType)return Jb.UNSIGNED_BYTE;if(b===a.UnsignedShort4444Type)return Jb.UNSIGNED_SHORT_4_4_4_4;if(b===a.UnsignedShort5551Type)return Jb.UNSIGNED_SHORT_5_5_5_1;if(b===a.UnsignedShort565Type)return Jb.UNSIGNED_SHORT_5_6_5;if(b===a.ByteType)return Jb.BYTE;if(b===a.ShortType)return Jb.SHORT;if(b===a.UnsignedShortType)return Jb.UNSIGNED_SHORT;if(b===a.IntType)return Jb.INT;if(b===a.UnsignedIntType)return Jb.UNSIGNED_INT;if(b===a.FloatType)return Jb.FLOAT;if(b===a.AlphaFormat)return Jb.ALPHA;if(b===a.RGBFormat)return Jb.RGB;if(b===a.RGBAFormat)return Jb.RGBA;if(b===a.LuminanceFormat)return Jb.LUMINANCE;if(b===a.LuminanceAlphaFormat)return Jb.LUMINANCE_ALPHA;if(b===a.AddEquation)return Jb.FUNC_ADD;if(b===a.SubtractEquation)return Jb.FUNC_SUBTRACT;if(b===a.ReverseSubtractEquation)return Jb.FUNC_REVERSE_SUBTRACT;if(b===a.ZeroFactor)return Jb.ZERO;if(b===a.OneFactor)return Jb.ONE;if(b===a.SrcColorFactor)return Jb.SRC_COLOR;if(b===a.OneMinusSrcColorFactor)return Jb.ONE_MINUS_SRC_COLOR;if(b===a.SrcAlphaFactor)return Jb.SRC_ALPHA;if(b===a.OneMinusSrcAlphaFactor)return Jb.ONE_MINUS_SRC_ALPHA;if(b===a.DstAlphaFactor)return Jb.DST_ALPHA;if(b===a.OneMinusDstAlphaFactor)return Jb.ONE_MINUS_DST_ALPHA;if(b===a.DstColorFactor)return Jb.DST_COLOR;if(b===a.OneMinusDstColorFactor)return Jb.ONE_MINUS_DST_COLOR;if(b===a.SrcAlphaSaturateFactor)return Jb.SRC_ALPHA_SATURATE;if(void 0!==Ob){if(b===a.RGB_S3TC_DXT1_Format)return Ob.COMPRESSED_RGB_S3TC_DXT1_EXT;if(b===a.RGBA_S3TC_DXT1_Format)return Ob.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(b===a.RGBA_S3TC_DXT3_Format)return Ob.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(b===a.RGBA_S3TC_DXT5_Format)return Ob.COMPRESSED_RGBA_S3TC_DXT5_EXT}return 0}function ub(b){if(Bc&&b&&b.useVertexTexture)return 1024;var c=Jb.getParameter(Jb.MAX_VERTEX_UNIFORM_VECTORS),d=Math.floor((c-20)/4),e=d;return void 0!==b&&b instanceof a.SkinnedMesh&&(e=Math.min(b.bones.length,e),eg;g++){var i=b[g];i.onlyShadow||i.visible===!1||(i instanceof a.DirectionalLight&&c++,i instanceof a.PointLight&&d++,i instanceof a.SpotLight&&e++,i instanceof a.HemisphereLight&&f++)}return{directional:c,point:d,spot:e,hemi:f}}function wb(b){for(var c=0,d=0,e=b.length;e>d;d++){var f=b[d];f.castShadow&&(f instanceof a.SpotLight&&c++,f instanceof a.DirectionalLight&&!f.shadowCascade&&c++)}return c}function xb(){try{var a={alpha:Cb,premultipliedAlpha:Db,antialias:Eb,stencil:Fb,preserveDrawingBuffer:Gb};if(Jb=Ab||zb.getContext("webgl",a)||zb.getContext("experimental-webgl",a),null===Jb)throw"Error creating WebGL context."}catch(b){console.error(b)}Kb=Jb.getExtension("OES_texture_float"),Lb=Jb.getExtension("OES_texture_float_linear"),Mb=Jb.getExtension("OES_standard_derivatives"),Nb=Jb.getExtension("EXT_texture_filter_anisotropic")||Jb.getExtension("MOZ_EXT_texture_filter_anisotropic")||Jb.getExtension("WEBKIT_EXT_texture_filter_anisotropic"),Ob=Jb.getExtension("WEBGL_compressed_texture_s3tc")||Jb.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||Jb.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"),Kb||console.log("THREE.WebGLRenderer: Float textures not supported."),Mb||console.log("THREE.WebGLRenderer: Standard derivatives not supported."),Nb||console.log("THREE.WebGLRenderer: Anisotropic texture filtering not supported."),Ob||console.log("THREE.WebGLRenderer: S3TC compressed textures not supported."),void 0===Jb.getShaderPrecisionFormat&&(Jb.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}})}function yb(){Jb.clearColor(0,0,0,1),Jb.clearDepth(1),Jb.clearStencil(0),Jb.enable(Jb.DEPTH_TEST),Jb.depthFunc(Jb.LEQUAL),Jb.frontFace(Jb.CCW),Jb.cullFace(Jb.BACK),Jb.enable(Jb.CULL_FACE),Jb.enable(Jb.BLEND),Jb.blendEquation(Jb.FUNC_ADD),Jb.blendFunc(Jb.SRC_ALPHA,Jb.ONE_MINUS_SRC_ALPHA),Jb.viewport(ic,jc,kc,lc),Jb.clearColor(Hb.r,Hb.g,Hb.b,Ib)}console.log("THREE.WebGLRenderer",a.REVISION),b=b||{};var zb=void 0!==b.canvas?b.canvas:document.createElement("canvas"),Ab=void 0!==b.context?b.context:null,Bb=void 0!==b.precision?b.precision:"highp",Cb=void 0!==b.alpha?b.alpha:!1,Db=void 0!==b.premultipliedAlpha?b.premultipliedAlpha:!0,Eb=void 0!==b.antialias?b.antialias:!1,Fb=void 0!==b.stencil?b.stencil:!0,Gb=void 0!==b.preserveDrawingBuffer?b.preserveDrawingBuffer:!1,Hb=new a.Color(0),Ib=0;this.domElement=zb,this.context=null,this.devicePixelRatio=void 0!==b.devicePixelRatio?b.devicePixelRatio:void 0!==self.devicePixelRatio?self.devicePixelRatio:1,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.autoUpdateObjects=!0,this.gammaInput=!1,this.gammaOutput=!1,this.shadowMapEnabled=!1,this.shadowMapAutoUpdate=!0,this.shadowMapType=a.PCFShadowMap,this.shadowMapCullFace=a.CullFaceFront,this.shadowMapDebug=!1,this.shadowMapCascade=!1,this.maxMorphTargets=8,this.maxMorphNormals=4,this.autoScaleCubemaps=!0,this.renderPluginsPre=[],this.renderPluginsPost=[],this.info={memory:{programs:0,geometries:0,textures:0},render:{calls:0,vertices:0,faces:0,points:0}};var Jb,Kb,Lb,Mb,Nb,Ob,Pb=this,Qb=[],Rb=0,Sb=null,Tb=null,Ub=-1,Vb=null,Wb=null,Xb=0,Yb=-1,Zb=-1,$b=-1,_b=-1,ac=-1,bc=-1,cc=-1,dc=-1,ec=null,fc=null,gc=null,hc=null,ic=0,jc=0,kc=zb.width,lc=zb.height,mc=0,nc=0,oc=new Uint8Array(16),pc=new a.Frustum,qc=new a.Matrix4,rc=new a.Matrix4,sc=new a.Vector3,tc=new a.Vector3,uc=!0,vc={ambient:[0,0,0],directional:{length:0,colors:new Array,positions:new Array},point:{length:0,colors:new Array,positions:new Array,distances:new Array},spot:{length:0,colors:new Array,positions:new Array,distances:new Array,directions:new Array,anglesCos:new Array,exponents:new Array},hemi:{length:0,skyColors:new Array,groundColors:new Array,positions:new Array}};xb(),yb(),this.context=Jb;var wc=Jb.getParameter(Jb.MAX_TEXTURE_IMAGE_UNITS),xc=Jb.getParameter(Jb.MAX_VERTEX_TEXTURE_IMAGE_UNITS),yc=(Jb.getParameter(Jb.MAX_TEXTURE_SIZE),Jb.getParameter(Jb.MAX_CUBE_MAP_TEXTURE_SIZE)),zc=Nb?Jb.getParameter(Nb.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0,Ac=xc>0,Bc=Ac&&Kb,Cc=(Ob?Jb.getParameter(Jb.COMPRESSED_TEXTURE_FORMATS):[],Jb.getShaderPrecisionFormat(Jb.VERTEX_SHADER,Jb.HIGH_FLOAT)),Dc=Jb.getShaderPrecisionFormat(Jb.VERTEX_SHADER,Jb.MEDIUM_FLOAT),Ec=(Jb.getShaderPrecisionFormat(Jb.VERTEX_SHADER,Jb.LOW_FLOAT),Jb.getShaderPrecisionFormat(Jb.FRAGMENT_SHADER,Jb.HIGH_FLOAT)),Fc=Jb.getShaderPrecisionFormat(Jb.FRAGMENT_SHADER,Jb.MEDIUM_FLOAT),Gc=(Jb.getShaderPrecisionFormat(Jb.FRAGMENT_SHADER,Jb.LOW_FLOAT),Jb.getShaderPrecisionFormat(Jb.VERTEX_SHADER,Jb.HIGH_INT),Jb.getShaderPrecisionFormat(Jb.VERTEX_SHADER,Jb.MEDIUM_INT),Jb.getShaderPrecisionFormat(Jb.VERTEX_SHADER,Jb.LOW_INT),Jb.getShaderPrecisionFormat(Jb.FRAGMENT_SHADER,Jb.HIGH_INT),Jb.getShaderPrecisionFormat(Jb.FRAGMENT_SHADER,Jb.MEDIUM_INT),Jb.getShaderPrecisionFormat(Jb.FRAGMENT_SHADER,Jb.LOW_INT),Cc.precision>0&&Ec.precision>0),Hc=Dc.precision>0&&Fc.precision>0;"highp"!==Bb||Gc||(Hc?(Bb="mediump",console.warn("WebGLRenderer: highp not supported, using mediump")):(Bb="lowp",console.warn("WebGLRenderer: highp and mediump not supported, using lowp"))),"mediump"!==Bb||Hc||(Bb="lowp",console.warn("WebGLRenderer: mediump not supported, using lowp")),this.getContext=function(){return Jb},this.supportsVertexTextures=function(){return Ac},this.supportsFloatTextures=function(){return Kb},this.supportsStandardDerivatives=function(){return Mb},this.supportsCompressedTextureS3TC=function(){return Ob},this.getMaxAnisotropy=function(){return zc},this.getPrecision=function(){return Bb},this.setSize=function(a,b,c){zb.width=a*this.devicePixelRatio,zb.height=b*this.devicePixelRatio,1!==this.devicePixelRatio&&c!==!1&&(zb.style.width=a+"px",zb.style.height=b+"px"),this.setViewport(0,0,a,b)},this.setViewport=function(a,b,c,d){ic=a*this.devicePixelRatio,jc=b*this.devicePixelRatio,kc=c*this.devicePixelRatio,lc=d*this.devicePixelRatio,Jb.viewport(ic,jc,kc,lc)},this.setScissor=function(a,b,c,d){Jb.scissor(a*this.devicePixelRatio,b*this.devicePixelRatio,c*this.devicePixelRatio,d*this.devicePixelRatio)},this.enableScissorTest=function(a){a?Jb.enable(Jb.SCISSOR_TEST):Jb.disable(Jb.SCISSOR_TEST)},this.setClearColor=function(a,b){Hb.set(a),Ib=void 0!==b?b:1,Jb.clearColor(Hb.r,Hb.g,Hb.b,Ib)},this.setClearColorHex=function(a,b){console.warn("DEPRECATED: .setClearColorHex() is being removed. Use .setClearColor() instead."),this.setClearColor(a,b)},this.getClearColor=function(){return Hb},this.getClearAlpha=function(){return Ib},this.clear=function(a,b,c){var d=0;(void 0===a||a)&&(d|=Jb.COLOR_BUFFER_BIT),(void 0===b||b)&&(d|=Jb.DEPTH_BUFFER_BIT),(void 0===c||c)&&(d|=Jb.STENCIL_BUFFER_BIT),Jb.clear(d)},this.clearColor=function(){Jb.clear(Jb.COLOR_BUFFER_BIT)},this.clearDepth=function(){Jb.clear(Jb.DEPTH_BUFFER_BIT)},this.clearStencil=function(){Jb.clear(Jb.STENCIL_BUFFER_BIT)},this.clearTarget=function(a,b,c,d){this.setRenderTarget(a),this.clear(b,c,d)},this.addPostPlugin=function(a){a.init(this),this.renderPluginsPost.push(a)},this.addPrePlugin=function(a){a.init(this),this.renderPluginsPre.push(a)},this.updateShadowMap=function(a,b){Sb=null,$b=-1,cc=-1,dc=-1,Vb=-1,Ub=-1,uc=!0,Yb=-1,Zb=-1,this.shadowMapPlugin.update(a,b)};var Ic=function(a){var b=a.target;b.removeEventListener("dispose",Ic),Nc(b)},Jc=function(a){var b=a.target;b.removeEventListener("dispose",Jc),Oc(b),Pb.info.memory.textures--},Kc=function(a){var b=a.target;b.removeEventListener("dispose",Kc),Pc(b),Pb.info.memory.textures--},Lc=function(a){var b=a.target;b.removeEventListener("dispose",Lc),Qc(b)},Mc=function(a){if(void 0!==a.__webglVertexBuffer&&Jb.deleteBuffer(a.__webglVertexBuffer),void 0!==a.__webglNormalBuffer&&Jb.deleteBuffer(a.__webglNormalBuffer),void 0!==a.__webglTangentBuffer&&Jb.deleteBuffer(a.__webglTangentBuffer),void 0!==a.__webglColorBuffer&&Jb.deleteBuffer(a.__webglColorBuffer),void 0!==a.__webglUVBuffer&&Jb.deleteBuffer(a.__webglUVBuffer),void 0!==a.__webglUV2Buffer&&Jb.deleteBuffer(a.__webglUV2Buffer),void 0!==a.__webglSkinIndicesBuffer&&Jb.deleteBuffer(a.__webglSkinIndicesBuffer),void 0!==a.__webglSkinWeightsBuffer&&Jb.deleteBuffer(a.__webglSkinWeightsBuffer),void 0!==a.__webglFaceBuffer&&Jb.deleteBuffer(a.__webglFaceBuffer),void 0!==a.__webglLineBuffer&&Jb.deleteBuffer(a.__webglLineBuffer),void 0!==a.__webglLineDistanceBuffer&&Jb.deleteBuffer(a.__webglLineDistanceBuffer),void 0!==a.__webglCustomAttributesList)for(var b in a.__webglCustomAttributesList)Jb.deleteBuffer(a.__webglCustomAttributesList[b].buffer);Pb.info.memory.geometries--},Nc=function(b){if(b.__webglInit=void 0,b instanceof a.BufferGeometry){var c=b.attributes;for(var d in c)void 0!==c[d].buffer&&Jb.deleteBuffer(c[d].buffer);Pb.info.memory.geometries--}else if(void 0!==b.geometryGroups)for(var e in b.geometryGroups){var f=b.geometryGroups[e];if(void 0!==f.numMorphTargets)for(var g=0,h=f.numMorphTargets;h>g;g++)Jb.deleteBuffer(f.__webglMorphTargetsBuffers[g]);if(void 0!==f.numMorphNormals)for(var g=0,h=f.numMorphNormals;h>g;g++)Jb.deleteBuffer(f.__webglMorphNormalsBuffers[g]);Mc(f)}else Mc(b)},Oc=function(a){if(a.image&&a.image.__webglTextureCube)Jb.deleteTexture(a.image.__webglTextureCube);else{if(!a.__webglInit)return;a.__webglInit=!1,Jb.deleteTexture(a.__webglTexture)}},Pc=function(b){if(b&&b.__webglTexture)if(Jb.deleteTexture(b.__webglTexture),b instanceof a.WebGLRenderTargetCube)for(var c=0;6>c;c++)Jb.deleteFramebuffer(b.__webglFramebuffer[c]),Jb.deleteRenderbuffer(b.__webglRenderbuffer[c]);else Jb.deleteFramebuffer(b.__webglFramebuffer),Jb.deleteRenderbuffer(b.__webglRenderbuffer)},Qc=function(a){var b=a.program;if(void 0!==b){a.program=void 0;var c,d,e,f=!1;for(c=0,d=Qb.length;d>c;c++)if(e=Qb[c],e.program===b){e.usedTimes--,0===e.usedTimes&&(f=!0);break}if(f===!0){var g=[];for(c=0,d=Qb.length;d>c;c++)e=Qb[c],e.program!==b&&g.push(e);Qb=g,Jb.deleteProgram(b),Pb.info.memory.programs--}}};this.renderBufferImmediate=function(b,c,d){if(b.hasPositions&&!b.__webglVertexBuffer&&(b.__webglVertexBuffer=Jb.createBuffer()),b.hasNormals&&!b.__webglNormalBuffer&&(b.__webglNormalBuffer=Jb.createBuffer()),b.hasUvs&&!b.__webglUvBuffer&&(b.__webglUvBuffer=Jb.createBuffer()),b.hasColors&&!b.__webglColorBuffer&&(b.__webglColorBuffer=Jb.createBuffer()),b.hasPositions&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglVertexBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,b.positionArray,Jb.DYNAMIC_DRAW),Jb.enableVertexAttribArray(c.attributes.position),Jb.vertexAttribPointer(c.attributes.position,3,Jb.FLOAT,!1,0,0)),b.hasNormals){if(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglNormalBuffer),d.shading===a.FlatShading){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s=3*b.count;for(r=0;s>r;r+=9)q=b.normalArray,h=q[r],k=q[r+1],n=q[r+2],i=q[r+3],l=q[r+4],o=q[r+5],j=q[r+6],m=q[r+7],p=q[r+8],e=(h+i+j)/3,f=(k+l+m)/3,g=(n+o+p)/3,q[r]=e,q[r+1]=f,q[r+2]=g,q[r+3]=e,q[r+4]=f,q[r+5]=g,q[r+6]=e,q[r+7]=f,q[r+8]=g}Jb.bufferData(Jb.ARRAY_BUFFER,b.normalArray,Jb.DYNAMIC_DRAW),Jb.enableVertexAttribArray(c.attributes.normal),Jb.vertexAttribPointer(c.attributes.normal,3,Jb.FLOAT,!1,0,0)}b.hasUvs&&d.map&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglUvBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,b.uvArray,Jb.DYNAMIC_DRAW),Jb.enableVertexAttribArray(c.attributes.uv),Jb.vertexAttribPointer(c.attributes.uv,2,Jb.FLOAT,!1,0,0)),b.hasColors&&d.vertexColors!==a.NoColors&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,b.__webglColorBuffer),Jb.bufferData(Jb.ARRAY_BUFFER,b.colorArray,Jb.DYNAMIC_DRAW),Jb.enableVertexAttribArray(c.attributes.color),Jb.vertexAttribPointer(c.attributes.color,3,Jb.FLOAT,!1,0,0)),Jb.drawArrays(Jb.TRIANGLES,0,b.count),b.count=0},this.renderBufferDirect=function(b,c,d,e,f,g){if(e.visible!==!1){var h,i,j,k,l=O(b,c,d,e,g),m=l.attributes,n=f.attributes,o=!1,p=e.wireframe?1:0,q=16777215*f.id+2*l.id+p;if(q!==Vb&&(Vb=q,o=!0),o&&v(),g instanceof a.Mesh){var r=n.index;if(r){var t=f.offsets;t.length>1&&(o=!0);for(var w=0,x=t.length;x>w;w++){var y=t[w].index;if(o){for(i in m)j=m[i],h=n[i],j>=0&&(h?(k=h.itemSize,Jb.bindBuffer(Jb.ARRAY_BUFFER,h.buffer),u(j),Jb.vertexAttribPointer(j,k,Jb.FLOAT,!1,0,y*k*4)):e.defaultAttributeValues&&(2===e.defaultAttributeValues[i].length?Jb.vertexAttrib2fv(j,e.defaultAttributeValues[i]):3===e.defaultAttributeValues[i].length&&Jb.vertexAttrib3fv(j,e.defaultAttributeValues[i])));Jb.bindBuffer(Jb.ELEMENT_ARRAY_BUFFER,r.buffer)}Jb.drawElements(Jb.TRIANGLES,t[w].count,Jb.UNSIGNED_SHORT,2*t[w].start),Pb.info.render.calls++,Pb.info.render.vertices+=t[w].count,Pb.info.render.faces+=t[w].count/3}}else{if(o)for(i in m)"index"!==i&&(j=m[i],h=n[i],j>=0&&(h?(k=h.itemSize,Jb.bindBuffer(Jb.ARRAY_BUFFER,h.buffer),u(j),Jb.vertexAttribPointer(j,k,Jb.FLOAT,!1,0,0)):e.defaultAttributeValues&&e.defaultAttributeValues[i]&&(2===e.defaultAttributeValues[i].length?Jb.vertexAttrib2fv(j,e.defaultAttributeValues[i]):3===e.defaultAttributeValues[i].length&&Jb.vertexAttrib3fv(j,e.defaultAttributeValues[i]))));var z=f.attributes.position;Jb.drawArrays(Jb.TRIANGLES,0,z.array.length/3),Pb.info.render.calls++,Pb.info.render.vertices+=z.array.length/3,Pb.info.render.faces+=z.array.length/3/3}}else if(g instanceof a.ParticleSystem){if(o)for(i in m)j=m[i],h=n[i],j>=0&&(h?(k=h.itemSize,Jb.bindBuffer(Jb.ARRAY_BUFFER,h.buffer),u(j),Jb.vertexAttribPointer(j,k,Jb.FLOAT,!1,0,0)):e.defaultAttributeValues&&e.defaultAttributeValues[i]&&(2===e.defaultAttributeValues[i].length?Jb.vertexAttrib2fv(j,e.defaultAttributeValues[i]):3===e.defaultAttributeValues[i].length&&Jb.vertexAttrib3fv(j,e.defaultAttributeValues[i])));var z=n.position;Jb.drawArrays(Jb.POINTS,0,z.array.length/3),Pb.info.render.calls++,Pb.info.render.points+=z.array.length/3}else if(g instanceof a.Line){var A=g.type===a.LineStrip?Jb.LINE_STRIP:Jb.LINES;db(e.linewidth);var r=n.index;if(r){var t=f.offsets;t.length>1&&(o=!0);for(var w=0,x=t.length;x>w;w++){var y=t[w].index;o&&(s(e,m,n,y),Jb.bindBuffer(Jb.ELEMENT_ARRAY_BUFFER,r.buffer)),Jb.drawElements(Jb.LINES,t[w].count,Jb.UNSIGNED_SHORT,2*t[w].start),Pb.info.render.calls++,Pb.info.render.vertices+=t[w].count}}else{o&&s(e,m,n,0);var z=n.position;Jb.drawArrays(A,0,z.array.length/3),Pb.info.render.calls++,Pb.info.render.points+=z.array.length}}}},this.renderBuffer=function(b,c,d,e,f,g){if(e.visible!==!1){var h,i,j,k=O(b,c,d,e,g),l=k.attributes,m=!1,n=e.wireframe?1:0,o=16777215*f.id+2*k.id+n;if(o!==Vb&&(Vb=o,m=!0),m&&v(),!e.morphTargets&&l.position>=0?m&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,f.__webglVertexBuffer),u(l.position),Jb.vertexAttribPointer(l.position,3,Jb.FLOAT,!1,0,0)):g.morphTargetBase&&w(e,f,g),m){if(f.__webglCustomAttributesList)for(i=0,j=f.__webglCustomAttributesList.length;j>i;i++)h=f.__webglCustomAttributesList[i],l[h.buffer.belongsToAttribute]>=0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,h.buffer),u(l[h.buffer.belongsToAttribute]),Jb.vertexAttribPointer(l[h.buffer.belongsToAttribute],h.size,Jb.FLOAT,!1,0,0));l.color>=0&&(g.geometry.colors.length>0||g.geometry.faces.length>0?(Jb.bindBuffer(Jb.ARRAY_BUFFER,f.__webglColorBuffer),u(l.color),Jb.vertexAttribPointer(l.color,3,Jb.FLOAT,!1,0,0)):e.defaultAttributeValues&&Jb.vertexAttrib3fv(l.color,e.defaultAttributeValues.color)),l.normal>=0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,f.__webglNormalBuffer),u(l.normal),Jb.vertexAttribPointer(l.normal,3,Jb.FLOAT,!1,0,0)),l.tangent>=0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,f.__webglTangentBuffer),u(l.tangent),Jb.vertexAttribPointer(l.tangent,4,Jb.FLOAT,!1,0,0)),l.uv>=0&&(g.geometry.faceVertexUvs[0]?(Jb.bindBuffer(Jb.ARRAY_BUFFER,f.__webglUVBuffer),u(l.uv),Jb.vertexAttribPointer(l.uv,2,Jb.FLOAT,!1,0,0)):e.defaultAttributeValues&&Jb.vertexAttrib2fv(l.uv,e.defaultAttributeValues.uv)),l.uv2>=0&&(g.geometry.faceVertexUvs[1]?(Jb.bindBuffer(Jb.ARRAY_BUFFER,f.__webglUV2Buffer),u(l.uv2),Jb.vertexAttribPointer(l.uv2,2,Jb.FLOAT,!1,0,0)):e.defaultAttributeValues&&Jb.vertexAttrib2fv(l.uv2,e.defaultAttributeValues.uv2)),e.skinning&&l.skinIndex>=0&&l.skinWeight>=0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,f.__webglSkinIndicesBuffer),u(l.skinIndex),Jb.vertexAttribPointer(l.skinIndex,4,Jb.FLOAT,!1,0,0),Jb.bindBuffer(Jb.ARRAY_BUFFER,f.__webglSkinWeightsBuffer),u(l.skinWeight),Jb.vertexAttribPointer(l.skinWeight,4,Jb.FLOAT,!1,0,0)),l.lineDistance>=0&&(Jb.bindBuffer(Jb.ARRAY_BUFFER,f.__webglLineDistanceBuffer),u(l.lineDistance),Jb.vertexAttribPointer(l.lineDistance,1,Jb.FLOAT,!1,0,0))}if(g instanceof a.Mesh)e.wireframe?(db(e.wireframeLinewidth),m&&Jb.bindBuffer(Jb.ELEMENT_ARRAY_BUFFER,f.__webglLineBuffer),Jb.drawElements(Jb.LINES,f.__webglLineCount,Jb.UNSIGNED_SHORT,0)):(m&&Jb.bindBuffer(Jb.ELEMENT_ARRAY_BUFFER,f.__webglFaceBuffer),Jb.drawElements(Jb.TRIANGLES,f.__webglFaceCount,Jb.UNSIGNED_SHORT,0)),Pb.info.render.calls++,Pb.info.render.vertices+=f.__webglFaceCount,Pb.info.render.faces+=f.__webglFaceCount/3;else if(g instanceof a.Line){var p=g.type===a.LineStrip?Jb.LINE_STRIP:Jb.LINES;db(e.linewidth),Jb.drawArrays(p,0,f.__webglLineCount),Pb.info.render.calls++}else g instanceof a.ParticleSystem&&(Jb.drawArrays(Jb.POINTS,0,f.__webglParticleCount),Pb.info.render.calls++,Pb.info.render.points+=f.__webglParticleCount)}},this.render=function(b,c,d,e){if(c instanceof a.Camera==!1)return void console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");var f,g,h,i,j,k=b.__lights,l=b.fog;for(Ub=-1,uc=!0,b.autoUpdate===!0&&b.updateMatrixWorld(),void 0===c.parent&&c.updateMatrixWorld(),c.matrixWorldInverse.getInverse(c.matrixWorld),qc.multiplyMatrices(c.projectionMatrix,c.matrixWorldInverse),pc.setFromMatrix(qc),this.autoUpdateObjects&&this.initWebGLObjects(b),z(this.renderPluginsPre,b,c),Pb.info.render.calls=0,Pb.info.render.vertices=0,Pb.info.render.faces=0,Pb.info.render.points=0,this.setRenderTarget(d),(this.autoClear||e)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil),j=b.__webglObjects,f=0,g=j.length;g>f;f++)h=j[f],i=h.object,h.id=f,h.render=!1,i.visible&&((i instanceof a.Mesh||i instanceof a.ParticleSystem)&&i.frustumCulled&&!pc.intersectsObject(i)||(_(i,c),D(h),h.render=!0,this.sortObjects===!0&&(null!==i.renderDepth?h.z=i.renderDepth:(sc.setFromMatrixPosition(i.matrixWorld),sc.applyProjection(qc),h.z=sc.z))));for(this.sortObjects&&j.sort(x),j=b.__webglObjectsImmediate,f=0,g=j.length;g>f;f++)h=j[f],i=h.object,i.visible&&(_(i,c),C(h));if(b.overrideMaterial){var m=b.overrideMaterial;this.setBlending(m.blending,m.blendEquation,m.blendSrc,m.blendDst),this.setDepthTest(m.depthTest),this.setDepthWrite(m.depthWrite),eb(m.polygonOffset,m.polygonOffsetFactor,m.polygonOffsetUnits),A(b.__webglObjects,!1,"",c,k,l,!0,m),B(b.__webglObjectsImmediate,"",c,k,l,!1,m)}else{var m=null;this.setBlending(a.NoBlending),A(b.__webglObjects,!0,"opaque",c,k,l,!1,m),B(b.__webglObjectsImmediate,"opaque",c,k,l,!1,m),A(b.__webglObjects,!1,"transparent",c,k,l,!0,m),B(b.__webglObjectsImmediate,"transparent",c,k,l,!0,m)}z(this.renderPluginsPost,b,c),d&&d.generateMipmaps&&d.minFilter!==a.NearestFilter&&d.minFilter!==a.LinearFilter&&rb(d),this.setDepthTest(!0),this.setDepthWrite(!0)},this.renderImmediateObject=function(a,b,c,d,e){var f=O(a,b,c,d,e);Vb=-1,Pb.setMaterialFaces(d),e.immediateRenderCallback?e.immediateRenderCallback(f,Jb,pc):e.render(function(a){Pb.renderBufferImmediate(a,f,d)})},this.initWebGLObjects=function(a){for(a.__webglObjects||(a.__webglObjects=[],a.__webglObjectsImmediate=[],a.__webglSprites=[],a.__webglFlares=[]);a.__objectsAdded.length;)E(a.__objectsAdded[0],a),a.__objectsAdded.splice(0,1);for(;a.__objectsRemoved.length;)K(a.__objectsRemoved[0],a),a.__objectsRemoved.splice(0,1);for(var b=0,c=a.__webglObjects.length;c>b;b++){var d=a.__webglObjects[b].object;void 0===d.__webglInit&&(void 0!==d.__webglActive&&K(d,a),E(d,a)),H(d)}},this.initMaterial=function(b,c,d,e){b.addEventListener("dispose",Lc);var f,g,h,i,j,k,l;b instanceof a.MeshDepthMaterial?l="depth":b instanceof a.MeshNormalMaterial?l="normal":b instanceof a.MeshBasicMaterial?l="basic":b instanceof a.MeshLambertMaterial?l="lambert":b instanceof a.MeshPhongMaterial?l="phong":b instanceof a.LineBasicMaterial?l="basic":b instanceof a.LineDashedMaterial?l="dashed":b instanceof a.ParticleSystemMaterial&&(l="particle_basic"),l&&N(b,a.ShaderLib[l]),i=vb(c),k=wb(c),j=ub(e),h={map:!!b.map,envMap:!!b.envMap,lightMap:!!b.lightMap,bumpMap:!!b.bumpMap,normalMap:!!b.normalMap,specularMap:!!b.specularMap,vertexColors:b.vertexColors,fog:d,useFog:b.fog,fogExp:d instanceof a.FogExp2,sizeAttenuation:b.sizeAttenuation,skinning:b.skinning,maxBones:j,useVertexTexture:Bc&&e&&e.useVertexTexture,morphTargets:b.morphTargets,morphNormals:b.morphNormals,maxMorphTargets:this.maxMorphTargets,maxMorphNormals:this.maxMorphNormals,maxDirLights:i.directional,maxPointLights:i.point,maxSpotLights:i.spot,maxHemiLights:i.hemi,maxShadows:k,shadowMapEnabled:this.shadowMapEnabled&&e.receiveShadow&&k>0,shadowMapType:this.shadowMapType,shadowMapDebug:this.shadowMapDebug,shadowMapCascade:this.shadowMapCascade,alphaTest:b.alphaTest,metal:b.metal,wrapAround:b.wrapAround,doubleSided:b.side===a.DoubleSide,flipSided:b.side===a.BackSide},b.program=gb(l,b.fragmentShader,b.vertexShader,b.uniforms,b.attributes,b.defines,h,b.index0AttributeName);var m=b.program.attributes;if(b.morphTargets){b.numSupportedMorphTargets=0;var n,o="morphTarget";for(g=0;g=0&&b.numSupportedMorphTargets++}if(b.morphNormals){b.numSupportedMorphNormals=0;var n,o="morphNormal";for(g=0;g=0&&b.numSupportedMorphNormals++}b.uniformsList=[];for(f in b.uniforms)b.uniformsList.push([b.uniforms[f],f])},this.setFaceCulling=function(b,c){b===a.CullFaceNone?Jb.disable(Jb.CULL_FACE):(Jb.frontFace(c===a.FrontFaceDirectionCW?Jb.CW:Jb.CCW),Jb.cullFace(b===a.CullFaceBack?Jb.BACK:b===a.CullFaceFront?Jb.FRONT:Jb.FRONT_AND_BACK),Jb.enable(Jb.CULL_FACE))},this.setMaterialFaces=function(b){var c=b.side===a.DoubleSide,d=b.side===a.BackSide;Yb!==c&&(c?Jb.disable(Jb.CULL_FACE):Jb.enable(Jb.CULL_FACE),Yb=c),Zb!==d&&(Jb.frontFace(d?Jb.CW:Jb.CCW),Zb=d)},this.setDepthTest=function(a){cc!==a&&(a?Jb.enable(Jb.DEPTH_TEST):Jb.disable(Jb.DEPTH_TEST),cc=a)},this.setDepthWrite=function(a){dc!==a&&(Jb.depthMask(a),dc=a)},this.setBlending=function(b,c,d,e){b!==$b&&(b===a.NoBlending?Jb.disable(Jb.BLEND):b===a.AdditiveBlending?(Jb.enable(Jb.BLEND),Jb.blendEquation(Jb.FUNC_ADD),Jb.blendFunc(Jb.SRC_ALPHA,Jb.ONE)):b===a.SubtractiveBlending?(Jb.enable(Jb.BLEND),Jb.blendEquation(Jb.FUNC_ADD),Jb.blendFunc(Jb.ZERO,Jb.ONE_MINUS_SRC_COLOR)):b===a.MultiplyBlending?(Jb.enable(Jb.BLEND),Jb.blendEquation(Jb.FUNC_ADD),Jb.blendFunc(Jb.ZERO,Jb.SRC_COLOR)):b===a.CustomBlending?Jb.enable(Jb.BLEND):(Jb.enable(Jb.BLEND),Jb.blendEquationSeparate(Jb.FUNC_ADD,Jb.FUNC_ADD),Jb.blendFuncSeparate(Jb.SRC_ALPHA,Jb.ONE_MINUS_SRC_ALPHA,Jb.ONE,Jb.ONE_MINUS_SRC_ALPHA)),$b=b),b===a.CustomBlending?(c!==_b&&(Jb.blendEquation(tb(c)),_b=c),(d!==ac||e!==bc)&&(Jb.blendFunc(tb(d),tb(e)),ac=d,bc=e)):(_b=null,ac=null,bc=null)},this.setTexture=function(b,c){if(b.needsUpdate){b.__webglInit||(b.__webglInit=!0,b.addEventListener("dispose",Jc),b.__webglTexture=Jb.createTexture(),Pb.info.memory.textures++),Jb.activeTexture(Jb.TEXTURE0+c),Jb.bindTexture(Jb.TEXTURE_2D,b.__webglTexture),Jb.pixelStorei(Jb.UNPACK_FLIP_Y_WEBGL,b.flipY),Jb.pixelStorei(Jb.UNPACK_PREMULTIPLY_ALPHA_WEBGL,b.premultiplyAlpha),Jb.pixelStorei(Jb.UNPACK_ALIGNMENT,b.unpackAlignment);var d=b.image,e=a.Math.isPowerOfTwo(d.width)&&a.Math.isPowerOfTwo(d.height),f=tb(b.format),g=tb(b.type);lb(Jb.TEXTURE_2D,b,e);var h,i=b.mipmaps;if(b instanceof a.DataTexture)if(i.length>0&&e){for(var j=0,k=i.length;k>j;j++)h=i[j],Jb.texImage2D(Jb.TEXTURE_2D,j,f,h.width,h.height,0,f,g,h.data);b.generateMipmaps=!1}else Jb.texImage2D(Jb.TEXTURE_2D,0,f,d.width,d.height,0,f,g,d.data);else if(b instanceof a.CompressedTexture)for(var j=0,k=i.length;k>j;j++)h=i[j],b.format!==a.RGBAFormat?Jb.compressedTexImage2D(Jb.TEXTURE_2D,j,f,h.width,h.height,0,h.data):Jb.texImage2D(Jb.TEXTURE_2D,j,f,h.width,h.height,0,f,g,h.data);else if(i.length>0&&e){for(var j=0,k=i.length;k>j;j++)h=i[j],Jb.texImage2D(Jb.TEXTURE_2D,j,f,f,g,h);b.generateMipmaps=!1}else Jb.texImage2D(Jb.TEXTURE_2D,0,f,f,g,b.image);b.generateMipmaps&&e&&Jb.generateMipmap(Jb.TEXTURE_2D),b.needsUpdate=!1,b.onUpdate&&b.onUpdate()}else Jb.activeTexture(Jb.TEXTURE0+c),Jb.bindTexture(Jb.TEXTURE_2D,b.__webglTexture)},this.setRenderTarget=function(b){var c=b instanceof a.WebGLRenderTargetCube;if(b&&!b.__webglFramebuffer){void 0===b.depthBuffer&&(b.depthBuffer=!0),void 0===b.stencilBuffer&&(b.stencilBuffer=!0),b.addEventListener("dispose",Kc),b.__webglTexture=Jb.createTexture(),Pb.info.memory.textures++;var d=a.Math.isPowerOfTwo(b.width)&&a.Math.isPowerOfTwo(b.height),e=tb(b.format),f=tb(b.type);if(c){b.__webglFramebuffer=[],b.__webglRenderbuffer=[],Jb.bindTexture(Jb.TEXTURE_CUBE_MAP,b.__webglTexture),lb(Jb.TEXTURE_CUBE_MAP,b,d);for(var g=0;6>g;g++)b.__webglFramebuffer[g]=Jb.createFramebuffer(),b.__webglRenderbuffer[g]=Jb.createRenderbuffer(),Jb.texImage2D(Jb.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,e,b.width,b.height,0,e,f,null),pb(b.__webglFramebuffer[g],b,Jb.TEXTURE_CUBE_MAP_POSITIVE_X+g),qb(b.__webglRenderbuffer[g],b);d&&Jb.generateMipmap(Jb.TEXTURE_CUBE_MAP)}else b.__webglFramebuffer=Jb.createFramebuffer(),b.__webglRenderbuffer=b.shareDepthFrom?b.shareDepthFrom.__webglRenderbuffer:Jb.createRenderbuffer(),Jb.bindTexture(Jb.TEXTURE_2D,b.__webglTexture),lb(Jb.TEXTURE_2D,b,d),Jb.texImage2D(Jb.TEXTURE_2D,0,e,b.width,b.height,0,e,f,null),pb(b.__webglFramebuffer,b,Jb.TEXTURE_2D),b.shareDepthFrom?b.depthBuffer&&!b.stencilBuffer?Jb.framebufferRenderbuffer(Jb.FRAMEBUFFER,Jb.DEPTH_ATTACHMENT,Jb.RENDERBUFFER,b.__webglRenderbuffer):b.depthBuffer&&b.stencilBuffer&&Jb.framebufferRenderbuffer(Jb.FRAMEBUFFER,Jb.DEPTH_STENCIL_ATTACHMENT,Jb.RENDERBUFFER,b.__webglRenderbuffer):qb(b.__webglRenderbuffer,b),d&&Jb.generateMipmap(Jb.TEXTURE_2D);c?Jb.bindTexture(Jb.TEXTURE_CUBE_MAP,null):Jb.bindTexture(Jb.TEXTURE_2D,null),Jb.bindRenderbuffer(Jb.RENDERBUFFER,null),Jb.bindFramebuffer(Jb.FRAMEBUFFER,null)}var h,i,j,k,l;b?(h=c?b.__webglFramebuffer[b.activeCubeFace]:b.__webglFramebuffer,i=b.width,j=b.height,k=0,l=0):(h=null,i=kc,j=lc,k=ic,l=jc),h!==Tb&&(Jb.bindFramebuffer(Jb.FRAMEBUFFER,h),Jb.viewport(k,l,i,j),Tb=h),mc=i,nc=j},this.shadowMapPlugin=new a.ShadowMapPlugin,this.addPrePlugin(this.shadowMapPlugin),this.addPostPlugin(new a.SpritePlugin),this.addPostPlugin(new a.LensFlarePlugin)},a.WebGLRenderTarget=function(b,c,d){this.width=b,this.height=c,d=d||{},this.wrapS=void 0!==d.wrapS?d.wrapS:a.ClampToEdgeWrapping,this.wrapT=void 0!==d.wrapT?d.wrapT:a.ClampToEdgeWrapping,this.magFilter=void 0!==d.magFilter?d.magFilter:a.LinearFilter,this.minFilter=void 0!==d.minFilter?d.minFilter:a.LinearMipMapLinearFilter,this.anisotropy=void 0!==d.anisotropy?d.anisotropy:1,this.offset=new a.Vector2(0,0),this.repeat=new a.Vector2(1,1),this.format=void 0!==d.format?d.format:a.RGBAFormat,this.type=void 0!==d.type?d.type:a.UnsignedByteType,this.depthBuffer=void 0!==d.depthBuffer?d.depthBuffer:!0,this.stencilBuffer=void 0!==d.stencilBuffer?d.stencilBuffer:!0,this.generateMipmaps=!0,this.shareDepthFrom=null
+},a.WebGLRenderTarget.prototype={constructor:a.WebGLRenderTarget,clone:function(){var b=new a.WebGLRenderTarget(this.width,this.height);return b.wrapS=this.wrapS,b.wrapT=this.wrapT,b.magFilter=this.magFilter,b.minFilter=this.minFilter,b.anisotropy=this.anisotropy,b.offset.copy(this.offset),b.repeat.copy(this.repeat),b.format=this.format,b.type=this.type,b.depthBuffer=this.depthBuffer,b.stencilBuffer=this.stencilBuffer,b.generateMipmaps=this.generateMipmaps,b.shareDepthFrom=this.shareDepthFrom,b},dispose:function(){this.dispatchEvent({type:"dispose"})}},a.EventDispatcher.prototype.apply(a.WebGLRenderTarget.prototype),a.WebGLRenderTargetCube=function(b,c,d){a.WebGLRenderTarget.call(this,b,c,d),this.activeCubeFace=0},a.WebGLRenderTargetCube.prototype=Object.create(a.WebGLRenderTarget.prototype),a.RenderableVertex=function(){this.position=new a.Vector3,this.positionWorld=new a.Vector3,this.positionScreen=new a.Vector4,this.visible=!0},a.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld),this.positionScreen.copy(a.positionScreen)},a.RenderableFace=function(){this.id=0,this.v1=new a.RenderableVertex,this.v2=new a.RenderableVertex,this.v3=new a.RenderableVertex,this.centroidModel=new a.Vector3,this.normalModel=new a.Vector3,this.vertexNormalsModel=[new a.Vector3,new a.Vector3,new a.Vector3],this.vertexNormalsLength=0,this.color=null,this.material=null,this.uvs=[[]],this.z=0},a.RenderableObject=function(){this.id=0,this.object=null,this.z=0},a.RenderableSprite=function(){this.id=0,this.object=null,this.x=0,this.y=0,this.z=0,this.rotation=0,this.scale=new a.Vector2,this.material=null},a.RenderableLine=function(){this.id=0,this.v1=new a.RenderableVertex,this.v2=new a.RenderableVertex,this.vertexColors=[new a.Color,new a.Color],this.material=null,this.z=0},a.GeometryUtils={merge:function(b,c,d){var e,f,g=b.vertices.length,h=(b.faceVertexUvs[0].length,c instanceof a.Mesh?c.geometry:c),i=b.vertices,j=h.vertices,k=b.faces,l=h.faces,m=b.faceVertexUvs[0],n=h.faceVertexUvs[0];void 0===d&&(d=0),c instanceof a.Mesh&&(c.matrixAutoUpdate&&c.updateMatrix(),e=c.matrix,f=(new a.Matrix3).getNormalMatrix(e));for(var o=0,p=j.length;p>o;o++){var q=j[o],r=q.clone();e&&r.applyMatrix4(e),i.push(r)}for(o=0,p=l.length;p>o;o++){var s,t,u,v=l[o],w=v.vertexNormals,x=v.vertexColors;s=new a.Face3(v.a+g,v.b+g,v.c+g),s.normal.copy(v.normal),f&&s.normal.applyMatrix3(f).normalize();for(var y=0,z=w.length;z>y;y++)t=w[y].clone(),f&&t.applyMatrix3(f).normalize(),s.vertexNormals.push(t);s.color.copy(v.color);for(var y=0,z=x.length;z>y;y++)u=x[y],s.vertexColors.push(u.clone());s.materialIndex=v.materialIndex+d,s.centroid.copy(v.centroid),e&&s.centroid.applyMatrix4(e),k.push(s)}for(o=0,p=n.length;p>o;o++){for(var A=n[o],B=[],y=0,z=A.length;z>y;y++)B.push(new a.Vector2(A[y].x,A[y].y));m.push(B)}},randomPointInTriangle:function(){var b=new a.Vector3;return function(c,d,e){var f=new a.Vector3,g=a.Math.random16(),h=a.Math.random16();g+h>1&&(g=1-g,h=1-h);var i=1-g-h;return f.copy(c),f.multiplyScalar(g),b.copy(d),b.multiplyScalar(h),f.add(b),b.copy(e),b.multiplyScalar(i),f.add(b),f}}(),randomPointInFace:function(b,c){var d,e,f;return d=c.vertices[b.a],e=c.vertices[b.b],f=c.vertices[b.c],a.GeometryUtils.randomPointInTriangle(d,e,f)},randomPointsInGeometry:function(b,c){function d(a){function b(c,d){if(c>d)return c;var e=c+Math.floor((d-c)/2);return n[e]>a?b(c,e-1):n[e]f;f++)e=j[f],g=k[e.a],h=k[e.b],i=k[e.c],e._area=a.GeometryUtils.triangleArea(g,h,i),m+=e._area,n[f]=m;var o,p,q=[],r={};for(f=0;c>f;f++)o=a.Math.random16()*m,p=d(o),q[f]=a.GeometryUtils.randomPointInFace(j[p],b,!0),r[p]?r[p]+=1:r[p]=1;return q},triangleArea:function(){var b=new a.Vector3,c=new a.Vector3;return function(a,d,e){return b.subVectors(d,a),c.subVectors(e,a),b.cross(c),.5*b.length()}}(),center:function(b){b.computeBoundingBox();var c=b.boundingBox,d=new a.Vector3;return d.addVectors(c.min,c.max),d.multiplyScalar(-.5),b.applyMatrix((new a.Matrix4).makeTranslation(d.x,d.y,d.z)),b.computeBoundingBox(),d},triangulateQuads:function(a){var b,c,d,e,f=[],g=[];for(b=0,c=a.faceVertexUvs.length;c>b;b++)g[b]=[];for(b=0,c=a.faces.length;c>b;b++){var h=a.faces[b];for(f.push(h),d=0,e=a.faceVertexUvs.length;e>d;d++)g[d].push(a.faceVertexUvs[d][b])}a.faces=f,a.faceVertexUvs=g,a.computeCentroids(),a.computeFaceNormals(),a.computeVertexNormals(),a.hasTangents&&a.computeTangents()}},a.ImageUtils={crossOrigin:void 0,loadTexture:function(b,c,d){var e=new a.ImageLoader;e.crossOrigin=this.crossOrigin;var f=new a.Texture(void 0,c),g=e.load(b,function(){f.needsUpdate=!0,d&&d(f)});return f.image=g,f.sourceFile=b,f},loadCompressedTexture:function(b,c,d,e){var f=new a.CompressedTexture;f.mapping=c;var g=new XMLHttpRequest;return g.onload=function(){var b=g.response,c=a.ImageUtils.parseDDS(b,!0);f.format=c.format,f.mipmaps=c.mipmaps,f.image.width=c.width,f.image.height=c.height,f.generateMipmaps=!1,f.needsUpdate=!0,d&&d(f)},g.onerror=e,g.open("GET",b,!0),g.responseType="arraybuffer",g.send(null),f},loadTextureCube:function(b,c,d,e){var f=[];f.loadCount=0;var g=new a.Texture;g.image=f,void 0!==c&&(g.mapping=c),g.flipY=!1;for(var h=0,i=b.length;i>h;++h){var j=new Image;f[h]=j,j.onload=function(){f.loadCount+=1,6===f.loadCount&&(g.needsUpdate=!0,d&&d(g))},j.onerror=e,j.crossOrigin=this.crossOrigin,j.src=b[h]}return g},loadCompressedTextureCube:function(b,c,d,e){var f=[];f.loadCount=0;var g=new a.CompressedTexture;g.image=f,void 0!==c&&(g.mapping=c),g.flipY=!1,g.generateMipmaps=!1;var h=function(b,c){return function(){var e=b.response,h=a.ImageUtils.parseDDS(e,!0);c.format=h.format,c.mipmaps=h.mipmaps,c.width=h.width,c.height=h.height,f.loadCount+=1,6===f.loadCount&&(g.format=h.format,g.needsUpdate=!0,d&&d(g))}};if(b instanceof Array)for(var i=0,j=b.length;j>i;++i){var k={};f[i]=k;var l=new XMLHttpRequest;l.onload=h(l,k),l.onerror=e;var m=b[i];l.open("GET",m,!0),l.responseType="arraybuffer",l.send(null)}else{var m=b,l=new XMLHttpRequest;l.onload=function(){var b=l.response,c=a.ImageUtils.parseDDS(b,!0);if(c.isCubemap){for(var e=c.mipmaps.length/c.mipmapCount,h=0;e>h;h++){f[h]={mipmaps:[]};for(var i=0;ii;i++){f[i]={mipmaps:[]};for(var j=0;j>8&255,a>>16&255,a>>24&255)}function f(a,b,c,d){for(var e=c*d*4,f=new Uint8Array(a,b,e),g=new Uint8Array(e),h=0,i=0,j=0;d>j;j++)for(var k=0;c>k;k++){var l=f[i];i++;var m=f[i];i++;var n=f[i];i++;var o=f[i];i++,g[h]=n,h++,g[h]=m,h++,g[h]=l,h++,g[h]=o,h++}return g}var g={mipmaps:[],width:0,height:0,format:null,mipmapCount:1},h=542327876,i=131072,j=512,k=4,l=d("DXT1"),m=d("DXT3"),n=d("DXT5"),o=31,p=0,q=1,r=2,s=3,t=4,u=7,v=20,w=21,x=22,y=23,z=24,A=25,B=26,C=28,D=new Int32Array(b,0,o);if(D[p]!==h)return console.error("ImageUtils.parseDDS(): Invalid magic number in DDS header"),g;if(!D[v]&k)return console.error("ImageUtils.parseDDS(): Unsupported format, must contain a FourCC code"),g;var E,F=D[w],G=!1;switch(F){case l:E=8,g.format=a.RGB_S3TC_DXT1_Format;break;case m:E=16,g.format=a.RGBA_S3TC_DXT3_Format;break;case n:E=16,g.format=a.RGBA_S3TC_DXT5_Format;break;default:if(!(32==D[x]&&16711680&D[y]&&65280&D[z]&&255&D[A]&&4278190080&D[B]))return console.error("ImageUtils.parseDDS(): Unsupported FourCC code: ",e(F)),g;G=!0,E=64,g.format=a.RGBAFormat}g.mipmapCount=1,D[r]&i&&c!==!1&&(g.mipmapCount=Math.max(1,D[u])),g.isCubemap=D[C]&j?!0:!1,g.width=D[t],g.height=D[s];for(var H=D[q]+4,I=g.width,J=g.height,K=g.isCubemap?6:1,L=0;K>L;L++){for(var M=0;Mm;m++)for(var n=0;g>n;n++){var o=0>n-1?0:n-1,p=n+1>g-1?g-1:n+1,q=0>m-1?0:m-1,r=m+1>f-1?f-1:m+1,s=[],t=[0,0,j[4*(n*f+m)]/255*b];s.push([-1,0,j[4*(n*f+q)]/255*b]),s.push([-1,-1,j[4*(o*f+q)]/255*b]),s.push([0,-1,j[4*(o*f+m)]/255*b]),s.push([1,-1,j[4*(o*f+r)]/255*b]),s.push([1,0,j[4*(n*f+r)]/255*b]),s.push([1,1,j[4*(p*f+r)]/255*b]),s.push([0,1,j[4*(p*f+m)]/255*b]),s.push([-1,1,j[4*(p*f+q)]/255*b]);for(var u=[],v=s.length,w=0;v>w;w++){var x=s[w],y=s[(w+1)%v];x=d(x,t),y=d(y,t),u.push(e(c(x,y)))}for(var z=[0,0,0],w=0;wj;j++)f[3*j]=g,f[3*j+1]=h,f[3*j+2]=i;var k=new a.DataTexture(f,b,c,a.RGBFormat);return k.needsUpdate=!0,k}},a.SceneUtils={createMultiMaterialObject:function(b,c){for(var d=new a.Object3D,e=0,f=c.length;f>e;e++)d.add(new a.Mesh(b,c[e]));return d},detach:function(a,b,c){a.applyMatrix(b.matrixWorld),b.remove(a),c.add(a)},attach:function(b,c,d){var e=new a.Matrix4;e.getInverse(d.matrixWorld),b.applyMatrix(e),c.remove(b),d.add(b)}},a.FontUtils={faces:{},face:"helvetiker",weight:"normal",style:"normal",size:150,divisions:10,getFace:function(){return this.faces[this.face][this.weight][this.style]},loadFace:function(a){var b=a.familyName.toLowerCase(),c=this;c.faces[b]=c.faces[b]||{},c.faces[b][a.cssFontWeight]=c.faces[b][a.cssFontWeight]||{},c.faces[b][a.cssFontWeight][a.cssFontStyle]=a;c.faces[b][a.cssFontWeight][a.cssFontStyle]=a;return a},drawText:function(b){var c,d=this.getFace(),e=this.size/d.resolution,f=0,g=String(b).split(""),h=g.length,i=[];for(c=0;h>c;c++){var j=new a.Path,k=this.extractGlyphPoints(g[c],d,e,f,j);f+=k.offset,i.push(k.path)}var l=f/2;return{paths:i,offset:l}},extractGlyphPoints:function(b,c,d,e,f){var g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z=[],A=c.glyphs[b]||c.glyphs["?"];if(A){if(A.o)for(j=A._cachedOutline||(A._cachedOutline=A.o.split(" ")),l=j.length,m=d,n=d,g=0;l>g;)switch(k=j[g++]){case"m":o=j[g++]*m+e,p=j[g++]*n,f.moveTo(o,p);break;case"l":o=j[g++]*m+e,p=j[g++]*n,f.lineTo(o,p);break;case"q":if(q=j[g++]*m+e,r=j[g++]*n,u=j[g++]*m+e,v=j[g++]*n,f.quadraticCurveTo(u,v,q,r),y=z[z.length-1])for(s=y.x,t=y.y,h=1,i=this.divisions;i>=h;h++){var B=h/i;a.Shape.Utils.b2(B,s,u,q),a.Shape.Utils.b2(B,t,v,r)}break;case"b":if(q=j[g++]*m+e,r=j[g++]*n,u=j[g++]*m+e,v=j[g++]*-n,w=j[g++]*m+e,x=j[g++]*-n,f.bezierCurveTo(q,r,u,v,w,x),y=z[z.length-1])for(s=y.x,t=y.y,h=1,i=this.divisions;i>=h;h++){var B=h/i;a.Shape.Utils.b3(B,s,u,w,q),a.Shape.Utils.b3(B,t,v,x,r)}}return{offset:A.ha*d,path:f}}}},a.FontUtils.generateShapes=function(b,c){c=c||{};var d=void 0!==c.size?c.size:100,e=void 0!==c.curveSegments?c.curveSegments:4,f=void 0!==c.font?c.font:"helvetiker",g=void 0!==c.weight?c.weight:"normal",h=void 0!==c.style?c.style:"normal";a.FontUtils.size=d,a.FontUtils.divisions=e,a.FontUtils.face=f,a.FontUtils.weight=g,a.FontUtils.style=h;for(var i=a.FontUtils.drawText(b),j=i.paths,k=[],l=0,m=j.length;m>l;l++)Array.prototype.push.apply(k,j[l].toShapes());return k},function(a){var b=1e-10,c=function(a,b){var c=a.length;if(3>c)return null;var f,g,h,i=[],j=[],k=[];if(d(a)>0)for(g=0;c>g;g++)j[g]=g;else for(g=0;c>g;g++)j[g]=c-1-g;var l=c,m=2*l;for(g=l-1;l>2;){if(m--<=0)return console.log("Warning, unable to triangulate polygon!"),b?k:i;if(f=g,f>=l&&(f=0),g=f+1,g>=l&&(g=0),h=g+1,h>=l&&(h=0),e(a,f,g,h,l,j)){var n,o,p,q,r;for(n=j[f],o=j[g],p=j[h],i.push([a[n],a[o],a[p]]),k.push([j[f],j[g],j[h]]),q=g,r=g+1;l>r;q++,r++)j[q]=j[r];l--,m=2*l}}return b?k:i},d=function(a){for(var b=a.length,c=0,d=b-1,e=0;b>e;d=e++)c+=a[d].x*a[e].y-a[e].x*a[d].y;return.5*c},e=function(a,c,d,e,f,g){var h,i,j,k,l,m,n,o,p;if(i=a[g[c]].x,j=a[g[c]].y,k=a[g[d]].x,l=a[g[d]].y,m=a[g[e]].x,n=a[g[e]].y,b>(k-i)*(n-j)-(l-j)*(m-i))return!1;var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E;for(q=m-k,r=n-l,s=i-m,t=j-n,u=k-i,v=l-j,h=0;f>h;h++)if(o=a[g[h]].x,p=a[g[h]].y,!(o===i&&p===j||o===k&&p===l||o===m&&p===n)&&(w=o-i,x=p-j,y=o-k,z=p-l,A=o-m,B=p-n,E=q*z-r*y,C=u*x-v*w,D=s*B-t*A,E>=-b&&D>=-b&&C>=-b))return!1;return!0};return a.Triangulate=c,a.Triangulate.area=d,a}(a.FontUtils),self._typeface_js={faces:a.FontUtils.faces,loadFace:a.FontUtils.loadFace},a.typeface_js=self._typeface_js,a.Curve=function(){},a.Curve.prototype.getPoint=function(){return console.log("Warning, getPoint() not implemented!"),null},a.Curve.prototype.getPointAt=function(a){var b=this.getUtoTmapping(a);return this.getPoint(b)},a.Curve.prototype.getPoints=function(a){a||(a=5);var b,c=[];for(b=0;a>=b;b++)c.push(this.getPoint(b/a));return c},a.Curve.prototype.getSpacedPoints=function(a){a||(a=5);var b,c=[];for(b=0;a>=b;b++)c.push(this.getPointAt(b/a));return c},a.Curve.prototype.getLength=function(){var a=this.getLengths();return a[a.length-1]},a.Curve.prototype.getLengths=function(a){if(a||(a=this.__arcLengthDivisions?this.__arcLengthDivisions:200),this.cacheArcLengths&&this.cacheArcLengths.length==a+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var b,c,d=[],e=this.getPoint(0),f=0;for(d.push(0),c=1;a>=c;c++)b=this.getPoint(c/a),f+=b.distanceTo(e),d.push(f),e=b;return this.cacheArcLengths=d,d},a.Curve.prototype.updateArcLengths=function(){this.needsUpdate=!0,this.getLengths()},a.Curve.prototype.getUtoTmapping=function(a,b){var c,d=this.getLengths(),e=0,f=d.length;c=b?b:a*d[f-1];for(var g,h=0,i=f-1;i>=h;)if(e=Math.floor(h+(i-h)/2),g=d[e]-c,0>g)h=e+1;else{if(!(g>0)){i=e;break}i=e-1}if(e=i,d[e]==c){var j=e/(f-1);return j}var k=d[e],l=d[e+1],m=l-k,n=(c-k)/m,j=(e+n)/(f-1);return j},a.Curve.prototype.getTangent=function(a){var b=1e-4,c=a-b,d=a+b;0>c&&(c=0),d>1&&(d=1);var e=this.getPoint(c),f=this.getPoint(d),g=f.clone().sub(e);return g.normalize()},a.Curve.prototype.getTangentAt=function(a){var b=this.getUtoTmapping(a);return this.getTangent(b)},a.Curve.Utils={tangentQuadraticBezier:function(a,b,c,d){return 2*(1-a)*(c-b)+2*a*(d-c)},tangentCubicBezier:function(a,b,c,d,e){return-3*b*(1-a)*(1-a)+3*c*(1-a)*(1-a)-6*a*c*(1-a)+6*a*d*(1-a)-3*a*a*d+3*a*a*e},tangentSpline:function(a){var b=6*a*a-6*a,c=3*a*a-4*a+1,d=-6*a*a+6*a,e=3*a*a-2*a;return b+c+d+e},interpolate:function(a,b,c,d,e){var f=.5*(c-a),g=.5*(d-b),h=e*e,i=e*h;return(2*b-2*c+f+g)*i+(-3*b+3*c-2*f-g)*h+f*e+b}},a.Curve.create=function(b,c){return b.prototype=Object.create(a.Curve.prototype),b.prototype.getPoint=c,b},a.CurvePath=function(){this.curves=[],this.bends=[],this.autoClose=!1},a.CurvePath.prototype=Object.create(a.Curve.prototype),a.CurvePath.prototype.add=function(a){this.curves.push(a)},a.CurvePath.prototype.checkConnection=function(){},a.CurvePath.prototype.closePath=function(){var b=this.curves[0].getPoint(0),c=this.curves[this.curves.length-1].getPoint(1);b.equals(c)||this.curves.push(new a.LineCurve(c,b))},a.CurvePath.prototype.getPoint=function(a){for(var b,c,d=a*this.getLength(),e=this.getCurveLengths(),f=0;f=d){b=e[f]-d,c=this.curves[f];var g=1-b/c.getLength();return c.getPointAt(g)}f++}return null},a.CurvePath.prototype.getLength=function(){var a=this.getCurveLengths();return a[a.length-1]},a.CurvePath.prototype.getCurveLengths=function(){if(this.cacheLengths&&this.cacheLengths.length==this.curves.length)return this.cacheLengths;var a,b=[],c=0,d=this.curves.length;for(a=0;d>a;a++)c+=this.curves[a].getLength(),b.push(c);return this.cacheLengths=b,b},a.CurvePath.prototype.getBoundingBox=function(){var b,c,d,e,f,g,h=this.getPoints();b=c=Number.NEGATIVE_INFINITY,e=f=Number.POSITIVE_INFINITY;var i,j,k,l,m=h[0]instanceof a.Vector3;for(l=m?new a.Vector3:new a.Vector2,j=0,k=h.length;k>j;j++)i=h[j],i.x>b?b=i.x:i.xc?c=i.y:i.yd?d=i.z:i.zc;c++)e=this.getWrapPoints(e,b[c]);return e},a.CurvePath.prototype.getTransformedSpacedPoints=function(a,b){var c,d,e=this.getSpacedPoints(a);for(b||(b=this.bends),c=0,d=b.length;d>c;c++)e=this.getWrapPoints(e,b[c]);return e},a.CurvePath.prototype.getWrapPoints=function(a,b){var c,d,e,f,g,h,i=this.getBoundingBox();for(c=0,d=a.length;d>c;c++){e=a[c],f=e.x,g=e.y,h=f/i.maxX,h=b.getUtoTmapping(h,f);var j=b.getPoint(h),k=b.getTangent(h);k.set(-k.y,k.x).multiplyScalar(g),e.x=j.x+k.x,e.y=j.y+k.y}return a},a.Gyroscope=function(){a.Object3D.call(this)},a.Gyroscope.prototype=Object.create(a.Object3D.prototype),a.Gyroscope.prototype.updateMatrixWorld=function(a){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||a)&&(this.parent?(this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorld.decompose(this.translationWorld,this.quaternionWorld,this.scaleWorld),this.matrix.decompose(this.translationObject,this.quaternionObject,this.scaleObject),this.matrixWorld.compose(this.translationWorld,this.quaternionObject,this.scaleWorld)):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,a=!0);for(var b=0,c=this.children.length;c>b;b++)this.children[b].updateMatrixWorld(a)},a.Gyroscope.prototype.translationWorld=new a.Vector3,a.Gyroscope.prototype.translationObject=new a.Vector3,a.Gyroscope.prototype.quaternionWorld=new a.Quaternion,a.Gyroscope.prototype.quaternionObject=new a.Quaternion,a.Gyroscope.prototype.scaleWorld=new a.Vector3,a.Gyroscope.prototype.scaleObject=new a.Vector3,a.Path=function(b){a.CurvePath.call(this),this.actions=[],b&&this.fromPoints(b)},a.Path.prototype=Object.create(a.CurvePath.prototype),a.PathActions={MOVE_TO:"moveTo",LINE_TO:"lineTo",QUADRATIC_CURVE_TO:"quadraticCurveTo",BEZIER_CURVE_TO:"bezierCurveTo",CSPLINE_THRU:"splineThru",ARC:"arc",ELLIPSE:"ellipse"},a.Path.prototype.fromPoints=function(a){this.moveTo(a[0].x,a[0].y);for(var b=1,c=a.length;c>b;b++)this.lineTo(a[b].x,a[b].y)},a.Path.prototype.moveTo=function(){var b=Array.prototype.slice.call(arguments);this.actions.push({action:a.PathActions.MOVE_TO,args:b})},a.Path.prototype.lineTo=function(b,c){var d=Array.prototype.slice.call(arguments),e=this.actions[this.actions.length-1].args,f=e[e.length-2],g=e[e.length-1],h=new a.LineCurve(new a.Vector2(f,g),new a.Vector2(b,c));this.curves.push(h),this.actions.push({action:a.PathActions.LINE_TO,args:d})},a.Path.prototype.quadraticCurveTo=function(b,c,d,e){var f=Array.prototype.slice.call(arguments),g=this.actions[this.actions.length-1].args,h=g[g.length-2],i=g[g.length-1],j=new a.QuadraticBezierCurve(new a.Vector2(h,i),new a.Vector2(b,c),new a.Vector2(d,e));this.curves.push(j),this.actions.push({action:a.PathActions.QUADRATIC_CURVE_TO,args:f})},a.Path.prototype.bezierCurveTo=function(b,c,d,e,f,g){var h=Array.prototype.slice.call(arguments),i=this.actions[this.actions.length-1].args,j=i[i.length-2],k=i[i.length-1],l=new a.CubicBezierCurve(new a.Vector2(j,k),new a.Vector2(b,c),new a.Vector2(d,e),new a.Vector2(f,g));this.curves.push(l),this.actions.push({action:a.PathActions.BEZIER_CURVE_TO,args:h})},a.Path.prototype.splineThru=function(b){var c=Array.prototype.slice.call(arguments),d=this.actions[this.actions.length-1].args,e=d[d.length-2],f=d[d.length-1],g=[new a.Vector2(e,f)];Array.prototype.push.apply(g,b);var h=new a.SplineCurve(g);this.curves.push(h),this.actions.push({action:a.PathActions.CSPLINE_THRU,args:c})},a.Path.prototype.arc=function(a,b,c,d,e,f){var g=this.actions[this.actions.length-1].args,h=g[g.length-2],i=g[g.length-1];this.absarc(a+h,b+i,c,d,e,f)},a.Path.prototype.absarc=function(a,b,c,d,e,f){this.absellipse(a,b,c,c,d,e,f)},a.Path.prototype.ellipse=function(a,b,c,d,e,f,g){var h=this.actions[this.actions.length-1].args,i=h[h.length-2],j=h[h.length-1];this.absellipse(a+i,b+j,c,d,e,f,g)},a.Path.prototype.absellipse=function(b,c,d,e,f,g,h){var i=Array.prototype.slice.call(arguments),j=new a.EllipseCurve(b,c,d,e,f,g,h);this.curves.push(j);var k=j.getPoint(1);i.push(k.x),i.push(k.y),this.actions.push({action:a.PathActions.ELLIPSE,args:i})},a.Path.prototype.getSpacedPoints=function(a){a||(a=40);for(var b=[],c=0;a>c;c++)b.push(this.getPoint(c/a));return b},a.Path.prototype.getPoints=function(b,c){if(this.useSpacedPoints)return console.log("tata"),this.getSpacedPoints(b,c);b=b||12;var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v=[];for(d=0,e=this.actions.length;e>d;d++)switch(f=this.actions[d],g=f.action,h=f.args,g){case a.PathActions.MOVE_TO:v.push(new a.Vector2(h[0],h[1]));break;case a.PathActions.LINE_TO:v.push(new a.Vector2(h[0],h[1]));break;case a.PathActions.QUADRATIC_CURVE_TO:for(i=h[2],j=h[3],m=h[0],n=h[1],v.length>0?(q=v[v.length-1],o=q.x,p=q.y):(q=this.actions[d-1].args,o=q[q.length-2],p=q[q.length-1]),r=1;b>=r;r++)s=r/b,t=a.Shape.Utils.b2(s,o,m,i),u=a.Shape.Utils.b2(s,p,n,j),v.push(new a.Vector2(t,u));break;case a.PathActions.BEZIER_CURVE_TO:for(i=h[4],j=h[5],m=h[0],n=h[1],k=h[2],l=h[3],v.length>0?(q=v[v.length-1],o=q.x,p=q.y):(q=this.actions[d-1].args,o=q[q.length-2],p=q[q.length-1]),r=1;b>=r;r++)s=r/b,t=a.Shape.Utils.b3(s,o,m,k,i),u=a.Shape.Utils.b3(s,p,n,l,j),v.push(new a.Vector2(t,u));break;case a.PathActions.CSPLINE_THRU:q=this.actions[d-1].args;var w=new a.Vector2(q[q.length-2],q[q.length-1]),x=[w],y=b*h[0].length;x=x.concat(h[0]);var z=new a.SplineCurve(x);for(r=1;y>=r;r++)v.push(z.getPointAt(r/y));break;case a.PathActions.ARC:var A,B=h[0],C=h[1],D=h[2],E=h[3],F=h[4],G=!!h[5],H=F-E,I=2*b;for(r=1;I>=r;r++)s=r/I,G||(s=1-s),A=E+s*H,t=B+D*Math.cos(A),u=C+D*Math.sin(A),v.push(new a.Vector2(t,u));break;case a.PathActions.ELLIPSE:var A,B=h[0],C=h[1],J=h[2],K=h[3],E=h[4],F=h[5],G=!!h[6],H=F-E,I=2*b;for(r=1;I>=r;r++)s=r/I,G||(s=1-s),A=E+s*H,t=B+J*Math.cos(A),u=C+K*Math.sin(A),v.push(new a.Vector2(t,u))}var L=v[v.length-1],M=1e-10;return Math.abs(L.x-v[0].x)g;f=g++){var h=b[f],i=b[g],j=i.x-h.x,k=i.y-h.y;if(Math.abs(k)>c){if(0>k&&(h=b[g],j=-j,i=b[f],k=-k),a.yi.y)continue;if(a.y==h.y){if(a.x==h.x)return!0}else{var l=k*(a.x-h.x)-j*(a.y-h.y);if(0==l)return!0;if(0>l)continue;e=!e}}else{if(a.y!=h.y)continue;if(i.x<=a.x&&a.x<=h.x||h.x<=a.x&&a.x<=i.x)return!0}}return e}var d,e,f,g,h,i=[],j=new a.Path;for(d=0,e=this.actions.length;e>d;d++)f=this.actions[d],h=f.args,g=f.action,g==a.PathActions.MOVE_TO&&0!=j.actions.length&&(i.push(j),j=new a.Path),j[g].apply(j,h);if(0!=j.actions.length&&i.push(j),0==i.length)return[];var k,l,m,n=[];if(1==i.length)return l=i[0],m=new a.Shape,m.actions=l.actions,m.curves=l.curves,n.push(m),n;var o=!a.Shape.Utils.isClockWise(i[0].getPoints());o=b?!o:o;var p,q=[],r=[],s=[],t=0;for(r[t]=void 0,s[t]=[],d=0,e=i.length;e>d;d++)l=i[d],p=l.getPoints(),k=a.Shape.Utils.isClockWise(p),k=b?!k:k,k?(!o&&r[t]&&t++,r[t]={s:new a.Shape,p:p},r[t].s.actions=l.actions,r[t].s.curves=l.curves,o&&t++,s[t]=[]):s[t].push({h:l,p:p[0]});if(r.length>1){for(var u=!1,v=[],w=0,x=r.length;x>w;w++)q[w]=[];for(var w=0,x=r.length;x>w;w++)for(var y=(r[w],s[w]),z=0;z0&&(u||(s=q))}var D,E,F;for(d=0,e=r.length;e>d;d++)for(m=r[d].s,n.push(m),D=s[d],E=0,F=D.length;F>E;E++)m.holes.push(D[E].h);return n},a.Shape=function(){a.Path.apply(this,arguments),this.holes=[]},a.Shape.prototype=Object.create(a.Path.prototype),a.Shape.prototype.extrude=function(b){var c=new a.ExtrudeGeometry(this,b);return c},a.Shape.prototype.makeGeometry=function(b){var c=new a.ShapeGeometry(this,b);return c},a.Shape.prototype.getPointsHoles=function(a){var b,c=this.holes.length,d=[];for(b=0;c>b;b++)d[b]=this.holes[b].getTransformedPoints(a,this.bends);return d},a.Shape.prototype.getSpacedPointsHoles=function(a){var b,c=this.holes.length,d=[];for(b=0;c>b;b++)d[b]=this.holes[b].getTransformedSpacedPoints(a,this.bends);return d},a.Shape.prototype.extractAllPoints=function(a){return{shape:this.getTransformedPoints(a),holes:this.getPointsHoles(a)}},a.Shape.prototype.extractPoints=function(a){return this.useSpacedPoints?this.extractAllSpacedPoints(a):this.extractAllPoints(a)},a.Shape.prototype.extractAllSpacedPoints=function(a){return{shape:this.getTransformedSpacedPoints(a),holes:this.getSpacedPointsHoles(a)}},a.Shape.Utils={triangulateShape:function(b,c){function d(a,b,c){return a.x!=b.x?a.xg){var p;if(n>0){if(0>o||o>n)return[];if(p=k*l-j*m,0>p||p>n)return[]}else{if(o>0||n>o)return[];if(p=k*l-j*m,p>0||n>p)return[]}if(0==p)return!f||0!=o&&o!=n?[a]:[];if(p==n)return!f||0!=o&&o!=n?[b]:[];if(0==o)return[c];if(o==n)return[e];var q=p/n;return[{x:a.x+q*h,y:a.y+q*i}]}if(0!=o||k*l!=j*m)return[];var r=0==h&&0==i,s=0==j&&0==k;if(r&&s)return a.x!=c.x||a.y!=c.y?[]:[a];if(r)return d(c,e,a)?[a]:[];if(s)return d(a,b,c)?[c]:[];var t,u,v,w,x,y,z,A;return 0!=h?(a.x=v?z>w?[]:w==z?f?[]:[x]:A>=w?[x,u]:[x,y]:v>A?[]:v==A?f?[]:[t]:A>=w?[t,u]:[t,y]}function f(a,b,c,d){var e=1e-10,f=b.x-a.x,g=b.y-a.y,h=c.x-a.x,i=c.y-a.y,j=d.x-a.x,k=d.y-a.y,l=f*i-g*h,m=f*k-g*j;if(Math.abs(l)>e){var n=j*i-k*h;return l>0?m>=0&&n>=0:m>=0||n>=0}return m>0}function g(a,b){function c(a,b){var c=s.length-1,d=a-1;0>d&&(d=c);var e=a+1;e>c&&(e=0);var g=f(s[a],s[d],s[e],h[b]);if(!g)return!1;var i=h.length-1,j=b-1;0>j&&(j=i);var k=b+1;return k>i&&(k=0),g=f(h[b],h[j],h[k],s[a]),g?!0:!1}function d(a,b){var c,d,f;for(c=0;c0)return!0;return!1}function g(a,c){var d,f,g,h,i;for(d=0;d0)return!0;return!1}for(var h,i,j,k,l,m,n,o,p,q,r,s=a.concat(),t=[],u=[],v=0,w=b.length;w>v;v++)t.push(v);for(var x=2*t.length;t.length>0;){if(x--,0>x){console.log("Infinite Loop! Holes left:"+t.length+", Probably Hole outside Shape!");break}for(j=0;j=0)break;u[n]=!0}if(i>=0)break}}return s}for(var h,i,j,k,l,m,n={},o=b.concat(),p=0,q=c.length;q>p;p++)Array.prototype.push.apply(o,c[p]);for(h=0,i=o.length;i>h;h++)l=o[h].x+":"+o[h].y,void 0!==n[l]&&console.log("Duplicate point",l),n[l]=h;var r=g(b,c),s=a.FontUtils.Triangulate(r,!1);for(h=0,i=s.length;i>h;h++)for(k=s[h],j=0;3>j;j++)l=k[j].x+":"+k[j].y,m=n[l],void 0!==m&&(k[j]=m);return s.concat()},isClockWise:function(b){return a.FontUtils.Triangulate.area(b)<0},b2p0:function(a,b){var c=1-a;return c*c*b},b2p1:function(a,b){return 2*(1-a)*a*b},b2p2:function(a,b){return a*a*b},b2:function(a,b,c,d){return this.b2p0(a,b)+this.b2p1(a,c)+this.b2p2(a,d)},b3p0:function(a,b){var c=1-a;return c*c*c*b},b3p1:function(a,b){var c=1-a;return 3*c*c*a*b},b3p2:function(a,b){var c=1-a;return 3*c*a*a*b},b3p3:function(a,b){return a*a*a*b},b3:function(a,b,c,d,e){return this.b3p0(a,b)+this.b3p1(a,c)+this.b3p2(a,d)+this.b3p3(a,e)}},a.LineCurve=function(a,b){this.v1=a,this.v2=b},a.LineCurve.prototype=Object.create(a.Curve.prototype),a.LineCurve.prototype.getPoint=function(a){var b=this.v2.clone().sub(this.v1);return b.multiplyScalar(a).add(this.v1),b},a.LineCurve.prototype.getPointAt=function(a){return this.getPoint(a)},a.LineCurve.prototype.getTangent=function(){var a=this.v2.clone().sub(this.v1);return a.normalize()},a.QuadraticBezierCurve=function(a,b,c){this.v0=a,this.v1=b,this.v2=c},a.QuadraticBezierCurve.prototype=Object.create(a.Curve.prototype),a.QuadraticBezierCurve.prototype.getPoint=function(b){var c,d;return c=a.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x),d=a.Shape.Utils.b2(b,this.v0.y,this.v1.y,this.v2.y),new a.Vector2(c,d)},a.QuadraticBezierCurve.prototype.getTangent=function(b){var c,d;c=a.Curve.Utils.tangentQuadraticBezier(b,this.v0.x,this.v1.x,this.v2.x),d=a.Curve.Utils.tangentQuadraticBezier(b,this.v0.y,this.v1.y,this.v2.y);var e=new a.Vector2(c,d);return e.normalize(),e},a.CubicBezierCurve=function(a,b,c,d){this.v0=a,this.v1=b,this.v2=c,this.v3=d},a.CubicBezierCurve.prototype=Object.create(a.Curve.prototype),a.CubicBezierCurve.prototype.getPoint=function(b){var c,d;return c=a.Shape.Utils.b3(b,this.v0.x,this.v1.x,this.v2.x,this.v3.x),d=a.Shape.Utils.b3(b,this.v0.y,this.v1.y,this.v2.y,this.v3.y),new a.Vector2(c,d)},a.CubicBezierCurve.prototype.getTangent=function(b){var c,d;c=a.Curve.Utils.tangentCubicBezier(b,this.v0.x,this.v1.x,this.v2.x,this.v3.x),d=a.Curve.Utils.tangentCubicBezier(b,this.v0.y,this.v1.y,this.v2.y,this.v3.y);var e=new a.Vector2(c,d);return e.normalize(),e},a.SplineCurve=function(a){this.points=void 0==a?[]:a},a.SplineCurve.prototype=Object.create(a.Curve.prototype),a.SplineCurve.prototype.getPoint=function(b){var c,d,e,f=new a.Vector2,g=[],h=this.points;return c=(h.length-1)*b,d=Math.floor(c),e=c-d,g[0]=0==d?d:d-1,g[1]=d,g[2]=d>h.length-2?h.length-1:d+1,g[3]=d>h.length-3?h.length-1:d+2,f.x=a.Curve.Utils.interpolate(h[g[0]].x,h[g[1]].x,h[g[2]].x,h[g[3]].x,e),f.y=a.Curve.Utils.interpolate(h[g[0]].y,h[g[1]].y,h[g[2]].y,h[g[3]].y,e),f},a.EllipseCurve=function(a,b,c,d,e,f,g){this.aX=a,this.aY=b,this.xRadius=c,this.yRadius=d,this.aStartAngle=e,this.aEndAngle=f,this.aClockwise=g},a.EllipseCurve.prototype=Object.create(a.Curve.prototype),a.EllipseCurve.prototype.getPoint=function(b){var c,d=this.aEndAngle-this.aStartAngle;0>d&&(d+=2*Math.PI),d>2*Math.PI&&(d-=2*Math.PI),c=this.aClockwise===!0?this.aEndAngle+(1-b)*(2*Math.PI-d):this.aStartAngle+b*d;
+var e=this.aX+this.xRadius*Math.cos(c),f=this.aY+this.yRadius*Math.sin(c);return new a.Vector2(e,f)},a.ArcCurve=function(b,c,d,e,f,g){a.EllipseCurve.call(this,b,c,d,d,e,f,g)},a.ArcCurve.prototype=Object.create(a.EllipseCurve.prototype),a.LineCurve3=a.Curve.create(function(a,b){this.v1=a,this.v2=b},function(b){var c=new a.Vector3;return c.subVectors(this.v2,this.v1),c.multiplyScalar(b),c.add(this.v1),c}),a.QuadraticBezierCurve3=a.Curve.create(function(a,b,c){this.v0=a,this.v1=b,this.v2=c},function(b){var c,d,e;return c=a.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x),d=a.Shape.Utils.b2(b,this.v0.y,this.v1.y,this.v2.y),e=a.Shape.Utils.b2(b,this.v0.z,this.v1.z,this.v2.z),new a.Vector3(c,d,e)}),a.CubicBezierCurve3=a.Curve.create(function(a,b,c,d){this.v0=a,this.v1=b,this.v2=c,this.v3=d},function(b){var c,d,e;return c=a.Shape.Utils.b3(b,this.v0.x,this.v1.x,this.v2.x,this.v3.x),d=a.Shape.Utils.b3(b,this.v0.y,this.v1.y,this.v2.y,this.v3.y),e=a.Shape.Utils.b3(b,this.v0.z,this.v1.z,this.v2.z,this.v3.z),new a.Vector3(c,d,e)}),a.SplineCurve3=a.Curve.create(function(a){this.points=void 0==a?[]:a},function(b){var c,d,e,f=new a.Vector3,g=[],h=this.points;c=(h.length-1)*b,d=Math.floor(c),e=c-d,g[0]=0==d?d:d-1,g[1]=d,g[2]=d>h.length-2?h.length-1:d+1,g[3]=d>h.length-3?h.length-1:d+2;var i=h[g[0]],j=h[g[1]],k=h[g[2]],l=h[g[3]];return f.x=a.Curve.Utils.interpolate(i.x,j.x,k.x,l.x,e),f.y=a.Curve.Utils.interpolate(i.y,j.y,k.y,l.y,e),f.z=a.Curve.Utils.interpolate(i.z,j.z,k.z,l.z,e),f}),a.ClosedSplineCurve3=a.Curve.create(function(a){this.points=void 0==a?[]:a},function(b){var c,d,e,f=new a.Vector3,g=[],h=this.points;return c=(h.length-0)*b,d=Math.floor(c),e=c-d,d+=d>0?0:(Math.floor(Math.abs(d)/h.length)+1)*h.length,g[0]=(d-1)%h.length,g[1]=d%h.length,g[2]=(d+1)%h.length,g[3]=(d+2)%h.length,f.x=a.Curve.Utils.interpolate(h[g[0]].x,h[g[1]].x,h[g[2]].x,h[g[3]].x,e),f.y=a.Curve.Utils.interpolate(h[g[0]].y,h[g[1]].y,h[g[2]].y,h[g[3]].y,e),f.z=a.Curve.Utils.interpolate(h[g[0]].z,h[g[1]].z,h[g[2]].z,h[g[3]].z,e),f}),a.AnimationHandler=function(){var b=[],c={},d={};d.update=function(a){for(var c=0;cb;b++){var d=this.hierarchy[b];d.matrixAutoUpdate=!0,void 0===d.animationCache&&(d.animationCache={},d.animationCache.prevKey={pos:0,rot:0,scl:0},d.animationCache.nextKey={pos:0,rot:0,scl:0},d.animationCache.originalMatrix=d instanceof a.Bone?d.skinMatrix:d.matrix);var e=d.animationCache.prevKey,f=d.animationCache.nextKey;e.pos=this.data.hierarchy[b].keys[0],e.rot=this.data.hierarchy[b].keys[0],e.scl=this.data.hierarchy[b].keys[0],f.pos=this.getNextKeyWith("pos",b,1),f.rot=this.getNextKeyWith("rot",b,1),f.scl=this.getNextKeyWith("scl",b,1)}},a.Animation.prototype.update=function(){var b=[],c=new a.Vector3,d=function(a,b){var c,d,f,g,h,i,j,k,l,m=[],n=[];return c=(a.length-1)*b,d=Math.floor(c),f=c-d,m[0]=0===d?d:d-1,m[1]=d,m[2]=d>a.length-2?d:d+1,m[3]=d>a.length-3?d:d+2,i=a[m[0]],j=a[m[1]],k=a[m[2]],l=a[m[3]],g=f*f,h=f*g,n[0]=e(i[0],j[0],k[0],l[0],f,g,h),n[1]=e(i[1],j[1],k[1],l[1],f,g,h),n[2]=e(i[2],j[2],k[2],l[2],f,g,h),n},e=function(a,b,c,d,e,f,g){var h=.5*(c-a),i=.5*(d-b);return(2*(b-c)+h+i)*g+(-3*(b-c)-2*h-i)*f+h*e+b};return function(e){if(this.isPlaying!==!1){this.currentTime+=e*this.timeScale;var f,g=["pos","rot","scl"],h=this.data.length;if(this.loop===!0&&this.currentTime>h)this.currentTime%=h,this.reset();else if(this.loop===!1&&this.currentTime>h)return void this.stop();this.currentTime=Math.min(this.currentTime,h);for(var i=0,j=this.hierarchy.length;j>i;i++)for(var k=this.hierarchy[i],l=k.animationCache,m=0;3>m;m++){var n=g[m],o=l.prevKey[n],p=l.nextKey[n];if(p.time<=this.currentTime){for(o=this.data.hierarchy[i].keys[0],p=this.getNextKeyWith(n,i,1);p.timeo.index;)o=p,p=this.getNextKeyWith(n,i,p.index+1);l.prevKey[n]=o,l.nextKey[n]=p}k.matrixAutoUpdate=!0,k.matrixWorldNeedsUpdate=!0;var q=(this.currentTime-o.time)/(p.time-o.time),r=o[n],s=p[n];if(0>q&&(q=0),q>1&&(q=1),"pos"===n){if(f=k.position,this.interpolationType===a.AnimationHandler.LINEAR)f.x=r[0]+(s[0]-r[0])*q,f.y=r[1]+(s[1]-r[1])*q,f.z=r[2]+(s[2]-r[2])*q;else if(this.interpolationType===a.AnimationHandler.CATMULLROM||this.interpolationType===a.AnimationHandler.CATMULLROM_FORWARD){b[0]=this.getPrevKeyWith("pos",i,o.index-1).pos,b[1]=r,b[2]=s,b[3]=this.getNextKeyWith("pos",i,p.index+1).pos,q=.33*q+.33;var t=d(b,q);if(f.x=t[0],f.y=t[1],f.z=t[2],this.interpolationType===a.AnimationHandler.CATMULLROM_FORWARD){var u=d(b,1.01*q);c.set(u[0],u[1],u[2]),c.sub(f),c.y=0,c.normalize();var v=Math.atan2(c.x,c.z);k.rotation.set(0,v,0)}}}else"rot"===n?a.Quaternion.slerp(r,s,k.quaternion,q):"scl"===n&&(f=k.scale,f.x=r[0]+(s[0]-r[0])*q,f.y=r[1]+(s[1]-r[1])*q,f.z=r[2]+(s[2]-r[2])*q)}}}}(),a.Animation.prototype.getNextKeyWith=function(b,c,d){var e=this.data.hierarchy[c].keys;for(this.interpolationType===a.AnimationHandler.CATMULLROM||this.interpolationType===a.AnimationHandler.CATMULLROM_FORWARD?d=d0?d:0:d>=0?d:d+e.length;d>=0;d--)if(void 0!==e[d][b])return e[d];return this.data.hierarchy[c].keys[e.length-1]},a.KeyFrameAnimation=function(b,c){this.root=b,this.data=a.AnimationHandler.get(c),this.hierarchy=a.AnimationHandler.parse(b),this.currentTime=0,this.timeScale=.001,this.isPlaying=!1,this.isPaused=!0,this.loop=!0;for(var d=0,e=this.hierarchy.length;e>d;d++){var f=this.data.hierarchy[d].keys,g=this.data.hierarchy[d].sids,h=this.hierarchy[d];if(f.length&&g){for(var i=0;ic;c++){d=this.hierarchy[c],e=this.data.hierarchy[c],void 0===e.animationCache&&(e.animationCache={},e.animationCache.prevKey=null,e.animationCache.nextKey=null,e.animationCache.originalMatrix=d instanceof a.Bone?d.skinMatrix:d.matrix);var g=this.data.hierarchy[c].keys;g.length&&(e.animationCache.prevKey=g[0],e.animationCache.nextKey=g[1],this.startTime=Math.min(g[0].time,this.startTime),this.endTime=Math.max(g[g.length-1].time,this.endTime))}this.update(0)}this.isPaused=!1,a.AnimationHandler.addToUpdate(this)},a.KeyFrameAnimation.prototype.pause=function(){this.isPaused?a.AnimationHandler.addToUpdate(this):a.AnimationHandler.removeFromUpdate(this),this.isPaused=!this.isPaused},a.KeyFrameAnimation.prototype.stop=function(){this.isPlaying=!1,this.isPaused=!1,a.AnimationHandler.removeFromUpdate(this);for(var b=0;bb&&(this.currentTime%=b),this.currentTime=Math.min(this.currentTime,b);for(var c=0,d=this.hierarchy.length;d>c;c++){var e=this.hierarchy[c],f=this.data.hierarchy[c],g=f.keys,h=f.animationCache;if(g.length){var i=h.prevKey,j=h.nextKey;if(j.time<=this.currentTime){for(;j.timei.index;)i=j,j=g[i.index+1];h.prevKey=i,h.nextKey=j}j.time>=this.currentTime?i.interpolate(j,this.currentTime):i.interpolate(j,j.time),this.data.hierarchy[c].node.updateMatrix(),e.matrixWorldNeedsUpdate=!0}}}},a.KeyFrameAnimation.prototype.getNextKeyWith=function(a,b,c){var d=this.data.hierarchy[b].keys;for(c%=d.length;c=0?c:c+d.length;c>=0;c--)if(d[c].hasTarget(a))return d[c];return d[d.length-1]},a.MorphAnimation=function(a){this.mesh=a,this.frames=a.morphTargetInfluences.length,this.currentTime=0,this.duration=1e3,this.loop=!0,this.isPlaying=!1},a.MorphAnimation.prototype={play:function(){this.isPlaying=!0},pause:function(){this.isPlaying=!1},update:function(){var a=0,b=0;return function(c){if(this.isPlaying!==!1){this.currentTime+=c,this.loop===!0&&this.currentTime>this.duration&&(this.currentTime%=this.duration),this.currentTime=Math.min(this.currentTime,this.duration);var d=this.duration/this.frames,e=Math.floor(this.currentTime/d);e!=b&&(this.mesh.morphTargetInfluences[a]=0,this.mesh.morphTargetInfluences[b]=1,this.mesh.morphTargetInfluences[e]=0,a=b,b=e),this.mesh.morphTargetInfluences[e]=this.currentTime%d/d,this.mesh.morphTargetInfluences[a]=1-this.mesh.morphTargetInfluences[e]}}}()},a.CubeCamera=function(b,c,d){a.Object3D.call(this);var e=90,f=1,g=new a.PerspectiveCamera(e,f,b,c);g.up.set(0,-1,0),g.lookAt(new a.Vector3(1,0,0)),this.add(g);var h=new a.PerspectiveCamera(e,f,b,c);h.up.set(0,-1,0),h.lookAt(new a.Vector3(-1,0,0)),this.add(h);var i=new a.PerspectiveCamera(e,f,b,c);i.up.set(0,0,1),i.lookAt(new a.Vector3(0,1,0)),this.add(i);var j=new a.PerspectiveCamera(e,f,b,c);j.up.set(0,0,-1),j.lookAt(new a.Vector3(0,-1,0)),this.add(j);var k=new a.PerspectiveCamera(e,f,b,c);k.up.set(0,-1,0),k.lookAt(new a.Vector3(0,0,1)),this.add(k);var l=new a.PerspectiveCamera(e,f,b,c);l.up.set(0,-1,0),l.lookAt(new a.Vector3(0,0,-1)),this.add(l),this.renderTarget=new a.WebGLRenderTargetCube(d,d,{format:a.RGBFormat,magFilter:a.LinearFilter,minFilter:a.LinearFilter}),this.updateCubeMap=function(a,b){var c=this.renderTarget,d=c.generateMipmaps;c.generateMipmaps=!1,c.activeCubeFace=0,a.render(b,g,c),c.activeCubeFace=1,a.render(b,h,c),c.activeCubeFace=2,a.render(b,i,c),c.activeCubeFace=3,a.render(b,j,c),c.activeCubeFace=4,a.render(b,k,c),c.generateMipmaps=d,c.activeCubeFace=5,a.render(b,l,c)}},a.CubeCamera.prototype=Object.create(a.Object3D.prototype),a.CombinedCamera=function(b,c,d,e,f,g,h){a.Camera.call(this),this.fov=d,this.left=-b/2,this.right=b/2,this.top=c/2,this.bottom=-c/2,this.cameraO=new a.OrthographicCamera(b/-2,b/2,c/2,c/-2,g,h),this.cameraP=new a.PerspectiveCamera(d,b/c,e,f),this.zoom=1,this.toPerspective()},a.CombinedCamera.prototype=Object.create(a.Camera.prototype),a.CombinedCamera.prototype.toPerspective=function(){this.near=this.cameraP.near,this.far=this.cameraP.far,this.cameraP.fov=this.fov/this.zoom,this.cameraP.updateProjectionMatrix(),this.projectionMatrix=this.cameraP.projectionMatrix,this.inPerspectiveMode=!0,this.inOrthographicMode=!1},a.CombinedCamera.prototype.toOrthographic=function(){var a=this.fov,b=this.cameraP.aspect,c=this.cameraP.near,d=this.cameraP.far,e=(c+d)/2,f=Math.tan(a/2)*e,g=2*f,h=g*b,i=h/2;f/=this.zoom,i/=this.zoom,this.cameraO.left=-i,this.cameraO.right=i,this.cameraO.top=f,this.cameraO.bottom=-f,this.cameraO.updateProjectionMatrix(),this.near=this.cameraO.near,this.far=this.cameraO.far,this.projectionMatrix=this.cameraO.projectionMatrix,this.inPerspectiveMode=!1,this.inOrthographicMode=!0},a.CombinedCamera.prototype.setSize=function(a,b){this.cameraP.aspect=a/b,this.left=-a/2,this.right=a/2,this.top=b/2,this.bottom=-b/2},a.CombinedCamera.prototype.setFov=function(a){this.fov=a,this.inPerspectiveMode?this.toPerspective():this.toOrthographic()},a.CombinedCamera.prototype.updateProjectionMatrix=function(){this.inPerspectiveMode?this.toPerspective():(this.toPerspective(),this.toOrthographic())},a.CombinedCamera.prototype.setLens=function(b,c){void 0===c&&(c=24);var d=2*a.Math.radToDeg(Math.atan(c/(2*b)));return this.setFov(d),d},a.CombinedCamera.prototype.setZoom=function(a){this.zoom=a,this.inPerspectiveMode?this.toPerspective():this.toOrthographic()},a.CombinedCamera.prototype.toFrontView=function(){this.rotation.x=0,this.rotation.y=0,this.rotation.z=0,this.rotationAutoUpdate=!1},a.CombinedCamera.prototype.toBackView=function(){this.rotation.x=0,this.rotation.y=Math.PI,this.rotation.z=0,this.rotationAutoUpdate=!1},a.CombinedCamera.prototype.toLeftView=function(){this.rotation.x=0,this.rotation.y=-Math.PI/2,this.rotation.z=0,this.rotationAutoUpdate=!1},a.CombinedCamera.prototype.toRightView=function(){this.rotation.x=0,this.rotation.y=Math.PI/2,this.rotation.z=0,this.rotationAutoUpdate=!1},a.CombinedCamera.prototype.toTopView=function(){this.rotation.x=-Math.PI/2,this.rotation.y=0,this.rotation.z=0,this.rotationAutoUpdate=!1},a.CombinedCamera.prototype.toBottomView=function(){this.rotation.x=Math.PI/2,this.rotation.y=0,this.rotation.z=0,this.rotationAutoUpdate=!1},a.BoxGeometry=function(b,c,d,e,f,g){function h(b,c,d,e,f,g,h,j){var k,l,m,n=i.widthSegments,o=i.heightSegments,p=f/2,q=g/2,r=i.vertices.length;"x"===b&&"y"===c||"y"===b&&"x"===c?k="z":"x"===b&&"z"===c||"z"===b&&"x"===c?(k="y",o=i.depthSegments):("z"===b&&"y"===c||"y"===b&&"z"===c)&&(k="x",n=i.depthSegments);var s=n+1,t=o+1,u=f/n,v=g/o,w=new a.Vector3;for(w[k]=h>0?1:-1,m=0;t>m;m++)for(l=0;s>l;l++){var x=new a.Vector3;x[b]=(l*u-p)*d,x[c]=(m*v-q)*e,x[k]=h,i.vertices.push(x)}for(m=0;o>m;m++)for(l=0;n>l;l++){var y=l+s*m,z=l+s*(m+1),A=l+1+s*(m+1),B=l+1+s*m,C=new a.Vector2(l/n,1-m/o),D=new a.Vector2(l/n,1-(m+1)/o),E=new a.Vector2((l+1)/n,1-(m+1)/o),F=new a.Vector2((l+1)/n,1-m/o),G=new a.Face3(y+r,z+r,B+r);G.normal.copy(w),G.vertexNormals.push(w.clone(),w.clone(),w.clone()),G.materialIndex=j,i.faces.push(G),i.faceVertexUvs[0].push([C,D,F]),G=new a.Face3(z+r,A+r,B+r),G.normal.copy(w),G.vertexNormals.push(w.clone(),w.clone(),w.clone()),G.materialIndex=j,i.faces.push(G),i.faceVertexUvs[0].push([D.clone(),E,F.clone()])}}a.Geometry.call(this);var i=this;this.width=b,this.height=c,this.depth=d,this.widthSegments=e||1,this.heightSegments=f||1,this.depthSegments=g||1;var j=this.width/2,k=this.height/2,l=this.depth/2;h("z","y",-1,-1,this.depth,this.height,j,0),h("z","y",1,-1,this.depth,this.height,-j,1),h("x","z",1,1,this.width,this.depth,k,2),h("x","z",1,-1,this.width,this.depth,-k,3),h("x","y",1,-1,this.width,this.height,l,4),h("x","y",-1,-1,this.width,this.height,-l,5),this.computeCentroids(),this.mergeVertices()},a.BoxGeometry.prototype=Object.create(a.Geometry.prototype),a.CircleGeometry=function(b,c,d,e){a.Geometry.call(this),this.radius=b=b||50,this.segments=c=void 0!==c?Math.max(3,c):8,this.thetaStart=d=void 0!==d?d:0,this.thetaLength=e=void 0!==e?e:2*Math.PI;var f,g=[],h=new a.Vector3,i=new a.Vector2(.5,.5);for(this.vertices.push(h),g.push(i),f=0;c>=f;f++){var j=new a.Vector3,k=d+f/c*e;j.x=b*Math.cos(k),j.y=b*Math.sin(k),this.vertices.push(j),g.push(new a.Vector2((j.x/b+1)/2,(j.y/b+1)/2))}var l=new a.Vector3(0,0,1);for(f=1;c>=f;f++){var m=f,n=f+1,o=0;this.faces.push(new a.Face3(m,n,o,[l.clone(),l.clone(),l.clone()])),this.faceVertexUvs[0].push([g[f].clone(),g[f+1].clone(),i.clone()])}this.computeCentroids(),this.computeFaceNormals(),this.boundingSphere=new a.Sphere(new a.Vector3,b)},a.CircleGeometry.prototype=Object.create(a.Geometry.prototype),a.CubeGeometry=a.BoxGeometry,a.CylinderGeometry=function(b,c,d,e,f,g){a.Geometry.call(this),this.radiusTop=b=void 0!==b?b:20,this.radiusBottom=c=void 0!==c?c:20,this.height=d=void 0!==d?d:100,this.radialSegments=e=e||8,this.heightSegments=f=f||1,this.openEnded=g=void 0!==g?g:!1;var h,i,j=d/2,k=[],l=[];for(i=0;f>=i;i++){var m=[],n=[],o=i/f,p=o*(c-b)+b;for(h=0;e>=h;h++){var q=h/e,r=new a.Vector3;r.x=p*Math.sin(q*Math.PI*2),r.y=-o*d+j,r.z=p*Math.cos(q*Math.PI*2),this.vertices.push(r),m.push(this.vertices.length-1),n.push(new a.Vector2(q,1-o))}k.push(m),l.push(n)}var s,t,u=(c-b)/d;for(h=0;e>h;h++)for(0!==b?(s=this.vertices[k[0][h]].clone(),t=this.vertices[k[0][h+1]].clone()):(s=this.vertices[k[1][h]].clone(),t=this.vertices[k[1][h+1]].clone()),s.setY(Math.sqrt(s.x*s.x+s.z*s.z)*u).normalize(),t.setY(Math.sqrt(t.x*t.x+t.z*t.z)*u).normalize(),i=0;f>i;i++){var v=k[i][h],w=k[i+1][h],x=k[i+1][h+1],y=k[i][h+1],z=s.clone(),A=s.clone(),B=t.clone(),C=t.clone(),D=l[i][h].clone(),E=l[i+1][h].clone(),F=l[i+1][h+1].clone(),G=l[i][h+1].clone();this.faces.push(new a.Face3(v,w,y,[z,A,C])),this.faceVertexUvs[0].push([D,E,G]),this.faces.push(new a.Face3(w,x,y,[A.clone(),B,C.clone()])),this.faceVertexUvs[0].push([E.clone(),F,G.clone()])}if(g===!1&&b>0)for(this.vertices.push(new a.Vector3(0,j,0)),h=0;e>h;h++){var v=k[0][h],w=k[0][h+1],x=this.vertices.length-1,z=new a.Vector3(0,1,0),A=new a.Vector3(0,1,0),B=new a.Vector3(0,1,0),D=l[0][h].clone(),E=l[0][h+1].clone(),F=new a.Vector2(E.x,0);this.faces.push(new a.Face3(v,w,x,[z,A,B])),this.faceVertexUvs[0].push([D,E,F])}if(g===!1&&c>0)for(this.vertices.push(new a.Vector3(0,-j,0)),h=0;e>h;h++){var v=k[i][h+1],w=k[i][h],x=this.vertices.length-1,z=new a.Vector3(0,-1,0),A=new a.Vector3(0,-1,0),B=new a.Vector3(0,-1,0),D=l[i][h+1].clone(),E=l[i][h].clone(),F=new a.Vector2(E.x,1);this.faces.push(new a.Face3(v,w,x,[z,A,B])),this.faceVertexUvs[0].push([D,E,F])}this.computeCentroids(),this.computeFaceNormals()},a.CylinderGeometry.prototype=Object.create(a.Geometry.prototype),a.ExtrudeGeometry=function(b,c){return"undefined"==typeof b?void(b=[]):(a.Geometry.call(this),b=b instanceof Array?b:[b],this.shapebb=b[b.length-1].getBoundingBox(),this.addShapeList(b,c),this.computeCentroids(),void this.computeFaceNormals())},a.ExtrudeGeometry.prototype=Object.create(a.Geometry.prototype),a.ExtrudeGeometry.prototype.addShapeList=function(a,b){for(var c=a.length,d=0;c>d;d++){var e=a[d];this.addShape(e,b)}},a.ExtrudeGeometry.prototype.addShape=function(b,c){function d(a,b,c){return b||console.log("die"),b.clone().multiplyScalar(c).add(a)}function e(b,c,d){var e,f,g=1e-10,h=a.Math.sign,i=1,j=b.x-c.x,k=b.y-c.y,l=d.x-b.x,m=d.y-b.y,n=j*j+k*k,o=j*m-k*l;if(Math.abs(o)>g){var p=Math.sqrt(n),q=Math.sqrt(l*l+m*m),r=c.x-k/p,s=c.y+j/p,t=d.x-m/q,u=d.y+l/q,v=((t-r)*m-(u-s)*l)/(j*m-k*l);e=r+j*v-b.x,f=s+k*v-b.y;var w=e*e+f*f;if(2>=w)return new a.Vector2(e,f);i=Math.sqrt(w/2)}else{var x=!1;j>g?l>g&&(x=!0):-g>j?-g>l&&(x=!0):h(k)==h(m)&&(x=!0),x?(e=-k,f=j,i=Math.sqrt(n)):(e=j,f=k,i=Math.sqrt(n/2))}return new a.Vector2(e/i,f/i)}function f(){if(u){var a=0,b=T*a;for(W=0;U>W;W++)S=L[W],j(S[2]+b,S[1]+b,S[0]+b,!0);for(a=w+2*t,b=T*a,W=0;U>W;W++)S=L[W],j(S[0]+b,S[1]+b,S[2]+b,!1)}else{for(W=0;U>W;W++)S=L[W],j(S[2],S[1],S[0],!0);for(W=0;U>W;W++)S=L[W],j(S[0]+T*w,S[1]+T*w,S[2]+T*w,!1)}}function g(){var a=0;for(h(M,a),a+=M.length,D=0,E=J.length;E>D;D++)C=J[D],h(C,a),a+=C.length}function h(a,b){var c,d;for(W=a.length;--W>=0;){c=W,d=W-1,0>d&&(d=a.length-1);var e=0,f=w+2*t;for(e=0;f>e;e++){var g=T*e,h=T*(e+1),i=b+c+g,j=b+d+g,l=b+d+h,m=b+c+h;k(i,j,l,m,a,e,f,c,d)}}}function i(b,c,d){F.vertices.push(new a.Vector3(b,c,d))}function j(d,e,f,g){d+=G,e+=G,f+=G,F.faces.push(new a.Face3(d,e,f,null,null,z));var h=g?B.generateBottomUV(F,b,c,d,e,f):B.generateTopUV(F,b,c,d,e,f);F.faceVertexUvs[0].push(h)}function k(d,e,f,g,h,i,j,k,l){d+=G,e+=G,f+=G,g+=G,F.faces.push(new a.Face3(d,e,g,null,null,A)),F.faces.push(new a.Face3(e,f,g,null,null,A));var m=B.generateSideWallUV(F,b,h,c,d,e,f,g,i,j,k,l);F.faceVertexUvs[0].push([m[0],m[1],m[3]]),F.faceVertexUvs[0].push([m[1],m[2],m[3]])}{var l,m,n,o,p,q=void 0!==c.amount?c.amount:100,r=void 0!==c.bevelThickness?c.bevelThickness:6,s=void 0!==c.bevelSize?c.bevelSize:r-2,t=void 0!==c.bevelSegments?c.bevelSegments:3,u=void 0!==c.bevelEnabled?c.bevelEnabled:!0,v=void 0!==c.curveSegments?c.curveSegments:12,w=void 0!==c.steps?c.steps:1,x=c.extrudePath,y=!1,z=c.material,A=c.extrudeMaterial,B=void 0!==c.UVGenerator?c.UVGenerator:a.ExtrudeGeometry.WorldUVGenerator;this.shapebb}x&&(l=x.getSpacedPoints(w),y=!0,u=!1,m=void 0!==c.frames?c.frames:new a.TubeGeometry.FrenetFrames(x,w,!1),n=new a.Vector3,o=new a.Vector3,p=new a.Vector3),u||(t=0,r=0,s=0);var C,D,E,F=this,G=this.vertices.length,H=b.extractPoints(v),I=H.shape,J=H.holes,K=!a.Shape.Utils.isClockWise(I);if(K){for(I=I.reverse(),D=0,E=J.length;E>D;D++)C=J[D],a.Shape.Utils.isClockWise(C)&&(J[D]=C.reverse());K=!1}var L=a.Shape.Utils.triangulateShape(I,J),M=I;for(D=0,E=J.length;E>D;D++)C=J[D],I=I.concat(C);for(var N,O,P,Q,R,S,T=I.length,U=L.length,V=(M.length,180/Math.PI,[]),W=0,X=M.length,Y=X-1,Z=W+1;X>W;W++,Y++,Z++){Y===X&&(Y=0),Z===X&&(Z=0);{M[W],M[Y],M[Z]}V[W]=e(M[W],M[Y],M[Z])}var $,_=[],ab=V.concat();for(D=0,E=J.length;E>D;D++){for(C=J[D],$=[],W=0,X=C.length,Y=X-1,Z=W+1;X>W;W++,Y++,Z++)Y===X&&(Y=0),Z===X&&(Z=0),$[W]=e(C[W],C[Y],C[Z]);_.push($),ab=ab.concat($)}for(N=0;t>N;N++){for(P=N/t,Q=r*(1-P),O=s*Math.sin(P*Math.PI/2),W=0,X=M.length;X>W;W++)R=d(M[W],V[W],O),i(R.x,R.y,-Q);for(D=0,E=J.length;E>D;D++)for(C=J[D],$=_[D],W=0,X=C.length;X>W;W++)R=d(C[W],$[W],O),i(R.x,R.y,-Q)}for(O=s,W=0;T>W;W++)R=u?d(I[W],ab[W],O):I[W],y?(o.copy(m.normals[0]).multiplyScalar(R.x),n.copy(m.binormals[0]).multiplyScalar(R.y),p.copy(l[0]).add(o).add(n),i(p.x,p.y,p.z)):i(R.x,R.y,0);var bb;for(bb=1;w>=bb;bb++)for(W=0;T>W;W++)R=u?d(I[W],ab[W],O):I[W],y?(o.copy(m.normals[bb]).multiplyScalar(R.x),n.copy(m.binormals[bb]).multiplyScalar(R.y),p.copy(l[bb]).add(o).add(n),i(p.x,p.y,p.z)):i(R.x,R.y,q/w*bb);for(N=t-1;N>=0;N--){for(P=N/t,Q=r*(1-P),O=s*Math.sin(P*Math.PI/2),W=0,X=M.length;X>W;W++)R=d(M[W],V[W],O),i(R.x,R.y,q+Q);for(D=0,E=J.length;E>D;D++)for(C=J[D],$=_[D],W=0,X=C.length;X>W;W++)R=d(C[W],$[W],O),y?i(R.x,R.y+l[w-1].y,l[w-1].x+Q):i(R.x,R.y,q+Q)}f(),g()},a.ExtrudeGeometry.WorldUVGenerator={generateTopUV:function(b,c,d,e,f,g){var h=b.vertices[e].x,i=b.vertices[e].y,j=b.vertices[f].x,k=b.vertices[f].y,l=b.vertices[g].x,m=b.vertices[g].y;return[new a.Vector2(h,i),new a.Vector2(j,k),new a.Vector2(l,m)]},generateBottomUV:function(a,b,c,d,e,f){return this.generateTopUV(a,b,c,d,e,f)},generateSideWallUV:function(b,c,d,e,f,g,h,i){var j=b.vertices[f].x,k=b.vertices[f].y,l=b.vertices[f].z,m=b.vertices[g].x,n=b.vertices[g].y,o=b.vertices[g].z,p=b.vertices[h].x,q=b.vertices[h].y,r=b.vertices[h].z,s=b.vertices[i].x,t=b.vertices[i].y,u=b.vertices[i].z;return Math.abs(k-n)<.01?[new a.Vector2(j,1-l),new a.Vector2(m,1-o),new a.Vector2(p,1-r),new a.Vector2(s,1-u)]:[new a.Vector2(k,1-l),new a.Vector2(n,1-o),new a.Vector2(q,1-r),new a.Vector2(t,1-u)]}},a.ExtrudeGeometry.__v1=new a.Vector2,a.ExtrudeGeometry.__v2=new a.Vector2,a.ExtrudeGeometry.__v3=new a.Vector2,a.ExtrudeGeometry.__v4=new a.Vector2,a.ExtrudeGeometry.__v5=new a.Vector2,a.ExtrudeGeometry.__v6=new a.Vector2,a.ShapeGeometry=function(b,c){a.Geometry.call(this),b instanceof Array==!1&&(b=[b]),this.shapebb=b[b.length-1].getBoundingBox(),this.addShapeList(b,c),this.computeCentroids(),this.computeFaceNormals()},a.ShapeGeometry.prototype=Object.create(a.Geometry.prototype),a.ShapeGeometry.prototype.addShapeList=function(a,b){for(var c=0,d=a.length;d>c;c++)this.addShape(a[c],b);return this},a.ShapeGeometry.prototype.addShape=function(b,c){void 0===c&&(c={});var d,e,f,g=void 0!==c.curveSegments?c.curveSegments:12,h=c.material,i=void 0===c.UVGenerator?a.ExtrudeGeometry.WorldUVGenerator:c.UVGenerator,j=(this.shapebb,this.vertices.length),k=b.extractPoints(g),l=k.shape,m=k.holes,n=!a.Shape.Utils.isClockWise(l);if(n){for(l=l.reverse(),d=0,e=m.length;e>d;d++)f=m[d],a.Shape.Utils.isClockWise(f)&&(m[d]=f.reverse());n=!1}var o=a.Shape.Utils.triangulateShape(l,m),p=l;for(d=0,e=m.length;e>d;d++)f=m[d],l=l.concat(f);{var q,r,s=l.length,t=o.length;p.length}for(d=0;s>d;d++)q=l[d],this.vertices.push(new a.Vector3(q.x,q.y,0));for(d=0;t>d;d++){r=o[d];var u=r[0]+j,v=r[1]+j,w=r[2]+j;this.faces.push(new a.Face3(u,v,w,null,null,h)),this.faceVertexUvs[0].push(i.generateBottomUV(this,b,c,u,v,w))}},a.LatheGeometry=function(b,c,d,e){a.Geometry.call(this),c=c||12,d=d||0,e=e||2*Math.PI;for(var f=1/(b.length-1),g=1/c,h=0,i=c;i>=h;h++)for(var j=d+h*g*e,k=Math.cos(j),l=Math.sin(j),m=0,n=b.length;n>m;m++){var o=b[m],p=new a.Vector3;p.x=k*o.x-l*o.y,p.y=l*o.x+k*o.y,p.z=o.z,this.vertices.push(p)}for(var q=b.length,h=0,i=c;i>h;h++)for(var m=0,n=b.length-1;n>m;m++){var r=m+q*h,s=r,t=r+q,k=r+1+q,u=r+1,v=h*g,w=m*f,x=v+g,y=w+f;this.faces.push(new a.Face3(s,t,u)),this.faceVertexUvs[0].push([new a.Vector2(v,w),new a.Vector2(x,w),new a.Vector2(v,y)]),this.faces.push(new a.Face3(t,k,u)),this.faceVertexUvs[0].push([new a.Vector2(x,w),new a.Vector2(x,y),new a.Vector2(v,y)])}this.mergeVertices(),this.computeCentroids(),this.computeFaceNormals(),this.computeVertexNormals()},a.LatheGeometry.prototype=Object.create(a.Geometry.prototype),a.PlaneGeometry=function(b,c,d,e){a.Geometry.call(this),this.width=b,this.height=c,this.widthSegments=d||1,this.heightSegments=e||1;var f,g,h=b/2,i=c/2,j=this.widthSegments,k=this.heightSegments,l=j+1,m=k+1,n=this.width/j,o=this.height/k,p=new a.Vector3(0,0,1);for(g=0;m>g;g++)for(f=0;l>f;f++){var q=f*n-h,r=g*o-i;this.vertices.push(new a.Vector3(q,-r,0))}for(g=0;k>g;g++)for(f=0;j>f;f++){var s=f+l*g,t=f+l*(g+1),u=f+1+l*(g+1),v=f+1+l*g,w=new a.Vector2(f/j,1-g/k),x=new a.Vector2(f/j,1-(g+1)/k),y=new a.Vector2((f+1)/j,1-(g+1)/k),z=new a.Vector2((f+1)/j,1-g/k),A=new a.Face3(s,t,v);A.normal.copy(p),A.vertexNormals.push(p.clone(),p.clone(),p.clone()),this.faces.push(A),this.faceVertexUvs[0].push([w,x,z]),A=new a.Face3(t,u,v),A.normal.copy(p),A.vertexNormals.push(p.clone(),p.clone(),p.clone()),this.faces.push(A),this.faceVertexUvs[0].push([x.clone(),y,z.clone()])}this.computeCentroids()},a.PlaneGeometry.prototype=Object.create(a.Geometry.prototype),a.RingGeometry=function(b,c,d,e,f,g){a.Geometry.call(this),b=b||0,c=c||50,f=void 0!==f?f:0,g=void 0!==g?g:2*Math.PI,d=void 0!==d?Math.max(3,d):8,e=void 0!==e?Math.max(3,e):8;var h,i,j=[],k=b,l=(c-b)/e;for(h=0;e>=h;h++){for(i=0;d>=i;i++){var m=new a.Vector3,n=f+i/d*g;m.x=k*Math.cos(n),m.y=k*Math.sin(n),this.vertices.push(m),j.push(new a.Vector2((m.x/c+1)/2,(m.y/c+1)/2))}k+=l}var o=new a.Vector3(0,0,1);for(h=0;e>h;h++){var p=h*d;for(i=0;d>=i;i++){var n=i+p,q=n+h,r=n+d+h,s=n+d+1+h;this.faces.push(new a.Face3(q,r,s,[o.clone(),o.clone(),o.clone()])),this.faceVertexUvs[0].push([j[q].clone(),j[r].clone(),j[s].clone()]),q=n+h,r=n+d+1+h,s=n+1+h,this.faces.push(new a.Face3(q,r,s,[o.clone(),o.clone(),o.clone()])),this.faceVertexUvs[0].push([j[q].clone(),j[r].clone(),j[s].clone()])}}this.computeCentroids(),this.computeFaceNormals(),this.boundingSphere=new a.Sphere(new a.Vector3,k)},a.RingGeometry.prototype=Object.create(a.Geometry.prototype),a.SphereGeometry=function(b,c,d,e,f,g,h){a.Geometry.call(this),this.radius=b=b||50,this.widthSegments=c=Math.max(3,Math.floor(c)||8),this.heightSegments=d=Math.max(2,Math.floor(d)||6),this.phiStart=e=void 0!==e?e:0,this.phiLength=f=void 0!==f?f:2*Math.PI,this.thetaStart=g=void 0!==g?g:0,this.thetaLength=h=void 0!==h?h:Math.PI;var i,j,k=[],l=[];for(j=0;d>=j;j++){var m=[],n=[];for(i=0;c>=i;i++){var o=i/c,p=j/d,q=new a.Vector3;q.x=-b*Math.cos(e+o*f)*Math.sin(g+p*h),q.y=b*Math.cos(g+p*h),q.z=b*Math.sin(e+o*f)*Math.sin(g+p*h),this.vertices.push(q),m.push(this.vertices.length-1),n.push(new a.Vector2(o,1-p))}k.push(m),l.push(n)}for(j=0;jp;p++)for(this.grid[p]=[],k=p/(C-1),o=b.getPointAt(k),h=F[p],i=G[p],j=H[p],q=0;q=h&&(g=h,m.set(1,0,0)),g>=i&&(g=i,m.set(0,1,0)),g>=j&&m.set(0,0,1),q.crossVectors(n[0],m).normalize(),o[0].crossVectors(n[0],q),p[0].crossVectors(n[0],o[0])}var f,g,h,i,j,k,l,m=(new a.Vector3,new a.Vector3),n=(new a.Vector3,[]),o=[],p=[],q=new a.Vector3,r=new a.Matrix4,s=c+1,t=1e-4;for(this.tangents=n,this.normals=o,this.binormals=p,k=0;s>k;k++)l=k/(s-1),n[k]=b.getTangentAt(l),n[k].normalize();for(e(),k=1;s>k;k++)o[k]=o[k-1].clone(),p[k]=p[k-1].clone(),q.crossVectors(n[k-1],n[k]),q.length()>t&&(q.normalize(),f=Math.acos(a.Math.clamp(n[k-1].dot(n[k]),-1,1)),o[k].applyMatrix4(r.makeRotationAxis(q,f))),p[k].crossVectors(n[k],o[k]);if(d)for(f=Math.acos(a.Math.clamp(o[0].dot(o[s-1]),-1,1)),f/=s-1,n[0].dot(q.crossVectors(o[0],o[s-1]))>0&&(f=-f),k=1;s>k;k++)o[k].applyMatrix4(r.makeRotationAxis(n[k],f*k)),p[k].crossVectors(n[k],o[k])},a.PolyhedronGeometry=function(b,c,d,e){function f(b){var c=b.normalize().clone();c.index=l.vertices.push(c)-1;var d=i(b)/2/Math.PI+.5,e=j(b)/Math.PI+.5;return c.uv=new a.Vector2(d,1-e),c}function g(b,c,d){var e=new a.Face3(b.index,c.index,d.index,[b.clone(),c.clone(),d.clone()]);e.centroid.add(b).add(c).add(d).divideScalar(3),l.faces.push(e);var f=i(e.centroid);l.faceVertexUvs[0].push([k(b.uv,b,f),k(c.uv,c,f),k(d.uv,d,f)])}function h(a,b){for(var c=Math.pow(2,b),d=(Math.pow(4,b),f(l.vertices[a.a])),e=f(l.vertices[a.b]),h=f(l.vertices[a.c]),i=[],j=0;c>=j;j++){i[j]=[];for(var k=f(d.clone().lerp(h,j/c)),m=f(e.clone().lerp(h,j/c)),n=c-j,o=0;n>=o;o++)i[j][o]=0==o&&j==c?k:f(k.clone().lerp(m,o/n))}for(var j=0;c>j;j++)for(var o=0;2*(c-j)-1>o;o++){var p=Math.floor(o/2);o%2==0?g(i[j][p+1],i[j+1][p],i[j][p]):g(i[j][p+1],i[j+1][p+1],i[j+1][p])}}function i(a){return Math.atan2(a.z,-a.x)}function j(a){return Math.atan2(-a.y,Math.sqrt(a.x*a.x+a.z*a.z))}function k(b,c,d){return 0>d&&1===b.x&&(b=new a.Vector2(b.x-1,b.y)),0===c.x&&0===c.z&&(b=new a.Vector2(d/2/Math.PI+.5,b.y)),b.clone()}a.Geometry.call(this),d=d||1,e=e||0;for(var l=this,m=0,n=b.length;n>m;m++)f(new a.Vector3(b[m][0],b[m][1],b[m][2]));for(var o=this.vertices,p=[],m=0,n=c.length;n>m;m++){var q=o[c[m][0]],r=o[c[m][1]],s=o[c[m][2]];p[m]=new a.Face3(q.index,r.index,s.index,[q.clone(),r.clone(),s.clone()])}for(var m=0,n=p.length;n>m;m++)h(p[m],e);for(var m=0,n=this.faceVertexUvs[0].length;n>m;m++){var t=this.faceVertexUvs[0][m],u=t[0].x,v=t[1].x,w=t[2].x,x=Math.max(u,Math.max(v,w)),y=Math.min(u,Math.min(v,w));x>.9&&.1>y&&(.2>u&&(t[0].x+=1),.2>v&&(t[1].x+=1),.2>w&&(t[2].x+=1))}for(var m=0,n=this.vertices.length;n>m;m++)this.vertices[m].multiplyScalar(d);this.mergeVertices(),this.computeCentroids(),this.computeFaceNormals(),this.boundingSphere=new a.Sphere(new a.Vector3,d)},a.PolyhedronGeometry.prototype=Object.create(a.Geometry.prototype),a.IcosahedronGeometry=function(b,c){this.radius=b,this.detail=c;var d=(1+Math.sqrt(5))/2,e=[[-1,d,0],[1,d,0],[-1,-d,0],[1,-d,0],[0,-1,d],[0,1,d],[0,-1,-d],[0,1,-d],[d,0,-1],[d,0,1],[-d,0,-1],[-d,0,1]],f=[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]];a.PolyhedronGeometry.call(this,e,f,b,c)},a.IcosahedronGeometry.prototype=Object.create(a.Geometry.prototype),a.OctahedronGeometry=function(b,c){var d=[[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]],e=[[0,2,4],[0,4,3],[0,3,5],[0,5,2],[1,2,5],[1,5,3],[1,3,4],[1,4,2]];a.PolyhedronGeometry.call(this,d,e,b,c)},a.OctahedronGeometry.prototype=Object.create(a.Geometry.prototype),a.TetrahedronGeometry=function(b,c){var d=[[1,1,1],[-1,-1,1],[-1,1,-1],[1,-1,-1]],e=[[2,1,0],[0,3,2],[1,3,0],[2,3,1]];a.PolyhedronGeometry.call(this,d,e,b,c)},a.TetrahedronGeometry.prototype=Object.create(a.Geometry.prototype),a.ParametricGeometry=function(b,c,d){a.Geometry.call(this);var e,f,g,h,i,j=this.vertices,k=this.faces,l=this.faceVertexUvs[0],m=c+1;for(e=0;d>=e;e++)for(i=e/d,f=0;c>=f;f++)h=f/c,g=b(h,i),j.push(g);var n,o,p,q,r,s,t,u;for(e=0;d>e;e++)for(f=0;c>f;f++)n=e*m+f,o=e*m+f+1,p=(e+1)*m+f+1,q=(e+1)*m+f,r=new a.Vector2(f/c,e/d),s=new a.Vector2((f+1)/c,e/d),t=new a.Vector2((f+1)/c,(e+1)/d),u=new a.Vector2(f/c,(e+1)/d),k.push(new a.Face3(n,o,q)),l.push([r,s,u]),k.push(new a.Face3(o,p,q)),l.push([s.clone(),t,u.clone()]);this.computeCentroids(),this.computeFaceNormals(),this.computeVertexNormals()},a.ParametricGeometry.prototype=Object.create(a.Geometry.prototype),a.AxisHelper=function(b){b=b||1;var c=new a.Geometry;c.vertices.push(new a.Vector3,new a.Vector3(b,0,0),new a.Vector3,new a.Vector3(0,b,0),new a.Vector3,new a.Vector3(0,0,b)),c.colors.push(new a.Color(16711680),new a.Color(16755200),new a.Color(65280),new a.Color(11206400),new a.Color(255),new a.Color(43775));var d=new a.LineBasicMaterial({vertexColors:a.VertexColors});a.Line.call(this,c,d,a.LinePieces)},a.AxisHelper.prototype=Object.create(a.Line.prototype),a.ArrowHelper=function(b,c,d,e,f,g){a.Object3D.call(this),void 0===e&&(e=16776960),void 0===d&&(d=1),void 0===f&&(f=.2*d),void 0===g&&(g=.2*f),this.position=c;var h=new a.Geometry;h.vertices.push(new a.Vector3(0,0,0)),h.vertices.push(new a.Vector3(0,1,0)),this.line=new a.Line(h,new a.LineBasicMaterial({color:e})),this.line.matrixAutoUpdate=!1,this.add(this.line);var i=new a.CylinderGeometry(0,.5,1,5,1);i.applyMatrix((new a.Matrix4).makeTranslation(0,-.5,0)),this.cone=new a.Mesh(i,new a.MeshBasicMaterial({color:e})),this.cone.matrixAutoUpdate=!1,this.add(this.cone),this.setDirection(b),this.setLength(d,f,g)},a.ArrowHelper.prototype=Object.create(a.Object3D.prototype),a.ArrowHelper.prototype.setDirection=function(){var b,c=new a.Vector3;return function(a){a.y>.99999?this.quaternion.set(0,0,0,1):a.y<-.99999?this.quaternion.set(1,0,0,0):(c.set(a.z,0,-a.x).normalize(),b=Math.acos(a.y),this.quaternion.setFromAxisAngle(c,b))}}(),a.ArrowHelper.prototype.setLength=function(a,b,c){void 0===b&&(b=.2*a),void 0===c&&(c=.2*b),this.line.scale.set(1,a,1),this.line.updateMatrix(),this.cone.scale.set(c,b,c),this.cone.position.y=a,this.cone.updateMatrix()},a.ArrowHelper.prototype.setColor=function(a){this.line.material.color.setHex(a),this.cone.material.color.setHex(a)},a.BoxHelper=function(b){var c=[new a.Vector3(1,1,1),new a.Vector3(-1,1,1),new a.Vector3(-1,-1,1),new a.Vector3(1,-1,1),new a.Vector3(1,1,-1),new a.Vector3(-1,1,-1),new a.Vector3(-1,-1,-1),new a.Vector3(1,-1,-1)];this.vertices=c;var d=new a.Geometry;d.vertices.push(c[0],c[1],c[1],c[2],c[2],c[3],c[3],c[0],c[4],c[5],c[5],c[6],c[6],c[7],c[7],c[4],c[0],c[4],c[1],c[5],c[2],c[6],c[3],c[7]),a.Line.call(this,d,new a.LineBasicMaterial({color:16776960}),a.LinePieces),void 0!==b&&this.update(b)},a.BoxHelper.prototype=Object.create(a.Line.prototype),a.BoxHelper.prototype.update=function(a){var b=a.geometry;null===b.boundingBox&&b.computeBoundingBox();var c=b.boundingBox.min,d=b.boundingBox.max,e=this.vertices;e[0].set(d.x,d.y,d.z),e[1].set(c.x,d.y,d.z),e[2].set(c.x,c.y,d.z),e[3].set(d.x,c.y,d.z),e[4].set(d.x,d.y,c.z),e[5].set(c.x,d.y,c.z),e[6].set(c.x,c.y,c.z),e[7].set(d.x,c.y,c.z),this.geometry.computeBoundingSphere(),this.geometry.verticesNeedUpdate=!0,this.matrixAutoUpdate=!1,this.matrixWorld=a.matrixWorld},a.BoundingBoxHelper=function(b,c){var d=void 0!==c?c:8947848;this.object=b,this.box=new a.Box3,a.Mesh.call(this,new a.BoxGeometry(1,1,1),new a.MeshBasicMaterial({color:d,wireframe:!0}))},a.BoundingBoxHelper.prototype=Object.create(a.Mesh.prototype),a.BoundingBoxHelper.prototype.update=function(){this.box.setFromObject(this.object),this.box.size(this.scale),this.box.center(this.position)},a.CameraHelper=function(b){function c(a,b,c){d(a,c),d(b,c)}function d(b,c){e.vertices.push(new a.Vector3),e.colors.push(new a.Color(c)),void 0===g[b]&&(g[b]=[]),g[b].push(e.vertices.length-1)}var e=new a.Geometry,f=new a.LineBasicMaterial({color:16777215,vertexColors:a.FaceColors}),g={},h=16755200,i=16711680,j=43775,k=16777215,l=3355443;c("n1","n2",h),c("n2","n4",h),c("n4","n3",h),c("n3","n1",h),c("f1","f2",h),c("f2","f4",h),c("f4","f3",h),c("f3","f1",h),c("n1","f1",h),c("n2","f2",h),c("n3","f3",h),c("n4","f4",h),c("p","n1",i),c("p","n2",i),c("p","n3",i),c("p","n4",i),c("u1","u2",j),c("u2","u3",j),c("u3","u1",j),c("c","t",k),c("p","c",l),c("cn1","cn2",l),c("cn3","cn4",l),c("cf1","cf2",l),c("cf3","cf4",l),a.Line.call(this,e,f,a.LinePieces),this.camera=b,this.matrixWorld=b.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=g,this.update()},a.CameraHelper.prototype=Object.create(a.Line.prototype),a.CameraHelper.prototype.update=function(){var b=new a.Vector3,c=new a.Camera,d=new a.Projector;return function(){function a(a,f,g,h){b.set(f,g,h),d.unprojectVector(b,c);var i=e.pointMap[a];if(void 0!==i)for(var j=0,k=i.length;k>j;j++)e.geometry.vertices[i[j]].copy(b)}var e=this,f=1,g=1;c.projectionMatrix.copy(this.camera.projectionMatrix),a("c",0,0,-1),a("t",0,0,1),a("n1",-f,-g,-1),a("n2",f,-g,-1),a("n3",-f,g,-1),a("n4",f,g,-1),a("f1",-f,-g,1),a("f2",f,-g,1),a("f3",-f,g,1),a("f4",f,g,1),a("u1",.7*f,1.1*g,-1),a("u2",.7*-f,1.1*g,-1),a("u3",0,2*g,-1),a("cf1",-f,0,1),a("cf2",f,0,1),a("cf3",0,-g,1),a("cf4",0,g,1),a("cn1",-f,0,-1),a("cn2",f,0,-1),a("cn3",0,-g,-1),a("cn4",0,g,-1),this.geometry.verticesNeedUpdate=!0}}(),a.DirectionalLightHelper=function(b,c){a.Object3D.call(this),this.light=b,this.light.updateMatrixWorld(),this.matrixWorld=b.matrixWorld,this.matrixAutoUpdate=!1,c=c||1;var d=new a.PlaneGeometry(c,c),e=new a.MeshBasicMaterial({wireframe:!0,fog:!1});e.color.copy(this.light.color).multiplyScalar(this.light.intensity),this.lightPlane=new a.Mesh(d,e),this.add(this.lightPlane),d=new a.Geometry,d.vertices.push(new a.Vector3),d.vertices.push(new a.Vector3),e=new a.LineBasicMaterial({fog:!1}),e.color.copy(this.light.color).multiplyScalar(this.light.intensity),this.targetLine=new a.Line(d,e),this.add(this.targetLine),this.update()},a.DirectionalLightHelper.prototype=Object.create(a.Object3D.prototype),a.DirectionalLightHelper.prototype.dispose=function(){this.lightPlane.geometry.dispose(),this.lightPlane.material.dispose(),this.targetLine.geometry.dispose(),this.targetLine.material.dispose()},a.DirectionalLightHelper.prototype.update=function(){var b=new a.Vector3,c=new a.Vector3,d=new a.Vector3;return function(){b.setFromMatrixPosition(this.light.matrixWorld),c.setFromMatrixPosition(this.light.target.matrixWorld),d.subVectors(c,b),this.lightPlane.lookAt(d),this.lightPlane.material.color.copy(this.light.color).multiplyScalar(this.light.intensity),this.targetLine.geometry.vertices[1].copy(d),this.targetLine.geometry.verticesNeedUpdate=!0,this.targetLine.material.color.copy(this.lightPlane.material.color)}}(),a.EdgesHelper=function(b,c){var d=void 0!==c?c:16777215,e=[0,0],f={},g=function(a,b){return a-b},h=["a","b","c"],i=new a.BufferGeometry,j=b.geometry.clone();j.mergeVertices(),j.computeFaceNormals();for(var k=j.vertices,l=j.faces,m=0,n=0,o=l.length;o>n;n++)for(var p=l[n],q=0;3>q;q++){e[0]=p[h[q]],e[1]=p[h[(q+1)%3]],e.sort(g);var r=e.toString();void 0===f[r]?(f[r]={vert1:e[0],vert2:e[1],face1:n,face2:void 0},m++):f[r].face2=n}i.addAttribute("position",Float32Array,2*m,3);var s=i.attributes.position.array,t=0;for(var r in f){var u=f[r];if(void 0===u.face2||l[u.face1].normal.dot(l[u.face2].normal)<.9999){var v=k[u.vert1];s[t++]=v.x,s[t++]=v.y,s[t++]=v.z,v=k[u.vert2],s[t++]=v.x,s[t++]=v.y,s[t++]=v.z}}a.Line.call(this,i,new a.LineBasicMaterial({color:d}),a.LinePieces),this.matrixAutoUpdate=!1,this.matrixWorld=b.matrixWorld},a.EdgesHelper.prototype=Object.create(a.Line.prototype),a.FaceNormalsHelper=function(b,c,d,e){this.object=b,this.size=void 0!==c?c:1;for(var f=void 0!==d?d:16776960,g=void 0!==e?e:1,h=new a.Geometry,i=this.object.geometry.faces,j=0,k=i.length;k>j;j++)h.vertices.push(new a.Vector3),h.vertices.push(new a.Vector3);a.Line.call(this,h,new a.LineBasicMaterial({color:f,linewidth:g}),a.LinePieces),this.matrixAutoUpdate=!1,this.normalMatrix=new a.Matrix3,this.update()},a.FaceNormalsHelper.prototype=Object.create(a.Line.prototype),a.FaceNormalsHelper.prototype.update=function(){var b=new a.Vector3;return function(){this.object.updateMatrixWorld(!0),this.normalMatrix.getNormalMatrix(this.object.matrixWorld);for(var a=this.geometry.vertices,c=this.object.geometry.faces,d=this.object.matrixWorld,e=0,f=c.length;f>e;e++){var g=c[e];b.copy(g.normal).applyMatrix3(this.normalMatrix).normalize().multiplyScalar(this.size);var h=2*e;a[h].copy(g.centroid).applyMatrix4(d),a[h+1].addVectors(a[h],b)}return this.geometry.verticesNeedUpdate=!0,this}}(),a.GridHelper=function(b,c){var d=new a.Geometry,e=new a.LineBasicMaterial({vertexColors:a.VertexColors});this.color1=new a.Color(4473924),this.color2=new a.Color(8947848);for(var f=-b;b>=f;f+=c){d.vertices.push(new a.Vector3(-b,0,f),new a.Vector3(b,0,f),new a.Vector3(f,0,-b),new a.Vector3(f,0,b));var g=0===f?this.color1:this.color2;d.colors.push(g,g,g,g)}a.Line.call(this,d,e,a.LinePieces)},a.GridHelper.prototype=Object.create(a.Line.prototype),a.GridHelper.prototype.setColors=function(a,b){this.color1.set(a),this.color2.set(b),this.geometry.colorsNeedUpdate=!0},a.HemisphereLightHelper=function(b,c){a.Object3D.call(this),this.light=b,this.light.updateMatrixWorld(),this.matrixWorld=b.matrixWorld,this.matrixAutoUpdate=!1,this.colors=[new a.Color,new a.Color];var d=new a.SphereGeometry(c,4,2);d.applyMatrix((new a.Matrix4).makeRotationX(-Math.PI/2));for(var e=0,f=8;f>e;e++)d.faces[e].color=this.colors[4>e?0:1];var g=new a.MeshBasicMaterial({vertexColors:a.FaceColors,wireframe:!0});this.lightSphere=new a.Mesh(d,g),this.add(this.lightSphere),this.update()},a.HemisphereLightHelper.prototype=Object.create(a.Object3D.prototype),a.HemisphereLightHelper.prototype.dispose=function(){this.lightSphere.geometry.dispose(),this.lightSphere.material.dispose()},a.HemisphereLightHelper.prototype.update=function(){var b=new a.Vector3;return function(){this.colors[0].copy(this.light.color).multiplyScalar(this.light.intensity),this.colors[1].copy(this.light.groundColor).multiplyScalar(this.light.intensity),this.lightSphere.lookAt(b.setFromMatrixPosition(this.light.matrixWorld).negate()),this.lightSphere.geometry.colorsNeedUpdate=!0}}(),a.PointLightHelper=function(b,c){this.light=b,this.light.updateMatrixWorld();var d=new a.SphereGeometry(c,4,2),e=new a.MeshBasicMaterial({wireframe:!0,fog:!1});e.color.copy(this.light.color).multiplyScalar(this.light.intensity),a.Mesh.call(this,d,e),this.matrixWorld=this.light.matrixWorld,this.matrixAutoUpdate=!1},a.PointLightHelper.prototype=Object.create(a.Mesh.prototype),a.PointLightHelper.prototype.dispose=function(){this.geometry.dispose(),this.material.dispose()},a.PointLightHelper.prototype.update=function(){this.material.color.copy(this.light.color).multiplyScalar(this.light.intensity)},a.SpotLightHelper=function(b){a.Object3D.call(this),this.light=b,this.light.updateMatrixWorld(),this.matrixWorld=b.matrixWorld,this.matrixAutoUpdate=!1;var c=new a.CylinderGeometry(0,1,1,8,1,!0);c.applyMatrix((new a.Matrix4).makeTranslation(0,-.5,0)),c.applyMatrix((new a.Matrix4).makeRotationX(-Math.PI/2));var d=new a.MeshBasicMaterial({wireframe:!0,fog:!1});this.cone=new a.Mesh(c,d),this.add(this.cone),this.update()},a.SpotLightHelper.prototype=Object.create(a.Object3D.prototype),a.SpotLightHelper.prototype.dispose=function(){this.cone.geometry.dispose(),this.cone.material.dispose()},a.SpotLightHelper.prototype.update=function(){var b=new a.Vector3,c=new a.Vector3;return function(){var a=this.light.distance?this.light.distance:1e4,d=a*Math.tan(this.light.angle);this.cone.scale.set(d,d,a),b.setFromMatrixPosition(this.light.matrixWorld),c.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(c.sub(b)),this.cone.material.color.copy(this.light.color).multiplyScalar(this.light.intensity)}}(),a.VertexNormalsHelper=function(b,c,d,e){this.object=b,this.size=void 0!==c?c:1;for(var f=void 0!==d?d:16711680,g=void 0!==e?e:1,h=new a.Geometry,i=(b.geometry.vertices,b.geometry.faces),j=0,k=i.length;k>j;j++)for(var l=i[j],m=0,n=l.vertexNormals.length;n>m;m++)h.vertices.push(new a.Vector3),h.vertices.push(new a.Vector3);a.Line.call(this,h,new a.LineBasicMaterial({color:f,linewidth:g}),a.LinePieces),this.matrixAutoUpdate=!1,this.normalMatrix=new a.Matrix3,this.update()},a.VertexNormalsHelper.prototype=Object.create(a.Line.prototype),a.VertexNormalsHelper.prototype.update=function(){var b=new a.Vector3;return function(){var a=["a","b","c","d"];this.object.updateMatrixWorld(!0),this.normalMatrix.getNormalMatrix(this.object.matrixWorld);for(var c=this.geometry.vertices,d=this.object.geometry.vertices,e=this.object.geometry.faces,f=this.object.matrixWorld,g=0,h=0,i=e.length;i>h;h++)for(var j=e[h],k=0,l=j.vertexNormals.length;l>k;k++){var m=j[a[k]],n=d[m],o=j.vertexNormals[k];c[g].copy(n).applyMatrix4(f),b.copy(o).applyMatrix3(this.normalMatrix).normalize().multiplyScalar(this.size),b.add(c[g]),g+=1,c[g].copy(b),g+=1}return this.geometry.verticesNeedUpdate=!0,this}}(),a.VertexTangentsHelper=function(b,c,d,e){this.object=b,this.size=void 0!==c?c:1;for(var f=void 0!==d?d:255,g=void 0!==e?e:1,h=new a.Geometry,i=(b.geometry.vertices,b.geometry.faces),j=0,k=i.length;k>j;j++)for(var l=i[j],m=0,n=l.vertexTangents.length;n>m;m++)h.vertices.push(new a.Vector3),h.vertices.push(new a.Vector3);a.Line.call(this,h,new a.LineBasicMaterial({color:f,linewidth:g}),a.LinePieces),this.matrixAutoUpdate=!1,this.update()},a.VertexTangentsHelper.prototype=Object.create(a.Line.prototype),a.VertexTangentsHelper.prototype.update=function(){var b=new a.Vector3;return function(){var a=["a","b","c","d"];this.object.updateMatrixWorld(!0);for(var c=this.geometry.vertices,d=this.object.geometry.vertices,e=this.object.geometry.faces,f=this.object.matrixWorld,g=0,h=0,i=e.length;i>h;h++)for(var j=e[h],k=0,l=j.vertexTangents.length;l>k;k++){var m=j[a[k]],n=d[m],o=j.vertexTangents[k];c[g].copy(n).applyMatrix4(f),b.copy(o).transformDirection(f).multiplyScalar(this.size),b.add(c[g]),g+=1,c[g].copy(b),g+=1}return this.geometry.verticesNeedUpdate=!0,this}}(),a.WireframeHelper=function(b,c){var d=void 0!==c?c:16777215,e=[0,0],f={},g=function(a,b){return a-b},h=["a","b","c"],i=new a.BufferGeometry;if(b.geometry instanceof a.Geometry){for(var j=b.geometry.vertices,k=b.geometry.faces,l=0,m=new Uint32Array(6*k.length),n=0,o=k.length;o>n;n++)for(var p=k[n],q=0;3>q;q++){e[0]=p[h[q]],e[1]=p[h[(q+1)%3]],e.sort(g);var r=e.toString();void 0===f[r]&&(m[2*l]=e[0],m[2*l+1]=e[1],f[r]=!0,l++)}i.addAttribute("position",Float32Array,2*l,3);for(var s=i.attributes.position.array,n=0,o=l;o>n;n++)for(var q=0;2>q;q++){var t=j[m[2*n+q]],u=6*n+3*q;s[u+0]=t.x,s[u+1]=t.y,s[u+2]=t.z}}else if(b.geometry instanceof a.BufferGeometry&&void 0!==b.geometry.attributes.index){for(var j=b.geometry.attributes.position.array,v=b.geometry.attributes.index.array,w=b.geometry.offsets,l=0,m=new Uint32Array(2*v.length),x=0,y=w.length;y>x;++x)for(var z=w[x].start,A=w[x].count,u=w[x].index,n=z,B=z+A;B>n;n+=3)for(var q=0;3>q;q++){e[0]=u+v[n+q],e[1]=u+v[n+(q+1)%3],e.sort(g);var r=e.toString();void 0===f[r]&&(m[2*l]=e[0],m[2*l+1]=e[1],f[r]=!0,l++)}i.addAttribute("position",Float32Array,2*l,3);for(var s=i.attributes.position.array,n=0,o=l;o>n;n++)for(var q=0;2>q;q++){var u=6*n+3*q,C=3*m[2*n+q];s[u+0]=j[C],s[u+1]=j[C+1],s[u+2]=j[C+2]}}else if(b.geometry instanceof a.BufferGeometry){var j=b.geometry.attributes.position.array,l=j.length/3,D=l/3;i.addAttribute("position",Float32Array,2*l,3);for(var s=i.attributes.position.array,n=0,o=D;o>n;n++)for(var q=0;3>q;q++){var u=18*n+6*q,E=9*n+3*q;s[u+0]=j[E],s[u+1]=j[E+1],s[u+2]=j[E+2];var C=9*n+3*((q+1)%3);s[u+3]=j[C],s[u+4]=j[C+1],s[u+5]=j[C+2]}}a.Line.call(this,i,new a.LineBasicMaterial({color:d}),a.LinePieces),this.matrixAutoUpdate=!1,this.matrixWorld=b.matrixWorld},a.WireframeHelper.prototype=Object.create(a.Line.prototype),a.ImmediateRenderObject=function(){a.Object3D.call(this),this.render=function(){}},a.ImmediateRenderObject.prototype=Object.create(a.Object3D.prototype),a.LensFlare=function(b,c,d,e,f){a.Object3D.call(this),this.lensFlares=[],this.positionScreen=new a.Vector3,this.customUpdateCallback=void 0,void 0!==b&&this.add(b,c,d,e,f)},a.LensFlare.prototype=Object.create(a.Object3D.prototype),a.LensFlare.prototype.add=function(b,c,d,e,f,g){void 0===c&&(c=-1),void 0===d&&(d=0),void 0===g&&(g=1),void 0===f&&(f=new a.Color(16777215)),void 0===e&&(e=a.NormalBlending),d=Math.min(d,Math.max(0,d)),this.lensFlares.push({texture:b,size:c,distance:d,x:0,y:0,z:0,scale:1,rotation:1,opacity:g,color:f,blending:e})},a.LensFlare.prototype.updateLensFlares=function(){var a,b,c=this.lensFlares.length,d=2*-this.positionScreen.x,e=2*-this.positionScreen.y;for(a=0;c>a;a++)b=this.lensFlares[a],b.x=this.positionScreen.x+d*b.distance,b.y=this.positionScreen.y+e*b.distance,b.wantedRotation=b.x*Math.PI*.25,b.rotation+=.25*(b.wantedRotation-b.rotation)},a.MorphBlendMesh=function(b,c){a.Mesh.call(this,b,c),this.animationsMap={},this.animationsList=[];var d=this.geometry.morphTargets.length,e="__default",f=0,g=d-1,h=d/1;this.createAnimation(e,f,g,h),this.setAnimationWeight(e,1)},a.MorphBlendMesh.prototype=Object.create(a.Mesh.prototype),a.MorphBlendMesh.prototype.createAnimation=function(a,b,c,d){var e={startFrame:b,endFrame:c,length:c-b+1,fps:d,duration:(c-b)/d,lastFrame:0,currentFrame:0,active:!1,time:0,direction:1,weight:1,directionBackwards:!1,mirroredLoop:!1};this.animationsMap[a]=e,this.animationsList.push(e)},a.MorphBlendMesh.prototype.autoCreateAnimations=function(a){for(var b,c=/([a-z]+)(\d+)/,d={},e=this.geometry,f=0,g=e.morphTargets.length;g>f;f++){var h=e.morphTargets[f],i=h.name.match(c);if(i&&i.length>1){{var j=i[1];i[2]}d[j]||(d[j]={start:1/0,end:-1/0});var k=d[j];fk.end&&(k.end=f),b||(b=j)}}for(var j in d){var k=d[j];this.createAnimation(j,k.start,k.end,a)}this.firstAnimation=b},a.MorphBlendMesh.prototype.setAnimationDirectionForward=function(a){var b=this.animationsMap[a];b&&(b.direction=1,b.directionBackwards=!1)},a.MorphBlendMesh.prototype.setAnimationDirectionBackward=function(a){var b=this.animationsMap[a];b&&(b.direction=-1,b.directionBackwards=!0)},a.MorphBlendMesh.prototype.setAnimationFPS=function(a,b){var c=this.animationsMap[a];c&&(c.fps=b,c.duration=(c.end-c.start)/c.fps)},a.MorphBlendMesh.prototype.setAnimationDuration=function(a,b){var c=this.animationsMap[a];c&&(c.duration=b,c.fps=(c.end-c.start)/c.duration)},a.MorphBlendMesh.prototype.setAnimationWeight=function(a,b){var c=this.animationsMap[a];c&&(c.weight=b)},a.MorphBlendMesh.prototype.setAnimationTime=function(a,b){var c=this.animationsMap[a];c&&(c.time=b)},a.MorphBlendMesh.prototype.getAnimationTime=function(a){var b=0,c=this.animationsMap[a];return c&&(b=c.time),b},a.MorphBlendMesh.prototype.getAnimationDuration=function(a){var b=-1,c=this.animationsMap[a];return c&&(b=c.duration),b},a.MorphBlendMesh.prototype.playAnimation=function(a){var b=this.animationsMap[a];b?(b.time=0,b.active=!0):console.warn("animation["+a+"] undefined")},a.MorphBlendMesh.prototype.stopAnimation=function(a){var b=this.animationsMap[a];b&&(b.active=!1)},a.MorphBlendMesh.prototype.update=function(b){for(var c=0,d=this.animationsList.length;d>c;c++){var e=this.animationsList[c];if(e.active){var f=e.duration/e.length;e.time+=e.direction*b,e.mirroredLoop?(e.time>e.duration||e.time<0)&&(e.direction*=-1,e.time>e.duration&&(e.time=e.duration,e.directionBackwards=!0),e.time<0&&(e.time=0,e.directionBackwards=!1)):(e.time=e.time%e.duration,e.time<0&&(e.time+=e.duration));var g=e.startFrame+a.Math.clamp(Math.floor(e.time/f),0,e.length-1),h=e.weight;g!==e.currentFrame&&(this.morphTargetInfluences[e.lastFrame]=0,this.morphTargetInfluences[e.currentFrame]=1*h,this.morphTargetInfluences[g]=0,e.lastFrame=e.currentFrame,e.currentFrame=g);var i=e.time%f/f;e.directionBackwards&&(i=1-i),this.morphTargetInfluences[e.currentFrame]=i*h,this.morphTargetInfluences[e.lastFrame]=(1-i)*h}}},a.LensFlarePlugin=function(){function b(a,b){var d=c.createProgram(),e=c.createShader(c.FRAGMENT_SHADER),f=c.createShader(c.VERTEX_SHADER),g="precision "+b+" float;\n";return c.shaderSource(e,g+a.fragmentShader),c.shaderSource(f,g+a.vertexShader),c.compileShader(e),c.compileShader(f),c.attachShader(d,e),c.attachShader(d,f),c.linkProgram(d),d}var c,d,e,f={};this.init=function(g){c=g.context,d=g,e=g.getPrecision(),f.vertices=new Float32Array(16),f.faces=new Uint16Array(6);var h=0;f.vertices[h++]=-1,f.vertices[h++]=-1,f.vertices[h++]=0,f.vertices[h++]=0,f.vertices[h++]=1,f.vertices[h++]=-1,f.vertices[h++]=1,f.vertices[h++]=0,f.vertices[h++]=1,f.vertices[h++]=1,f.vertices[h++]=1,f.vertices[h++]=1,f.vertices[h++]=-1,f.vertices[h++]=1,f.vertices[h++]=0,f.vertices[h++]=1,h=0,f.faces[h++]=0,f.faces[h++]=1,f.faces[h++]=2,f.faces[h++]=0,f.faces[h++]=2,f.faces[h++]=3,f.vertexBuffer=c.createBuffer(),f.elementBuffer=c.createBuffer(),c.bindBuffer(c.ARRAY_BUFFER,f.vertexBuffer),c.bufferData(c.ARRAY_BUFFER,f.vertices,c.STATIC_DRAW),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,f.elementBuffer),c.bufferData(c.ELEMENT_ARRAY_BUFFER,f.faces,c.STATIC_DRAW),f.tempTexture=c.createTexture(),f.occlusionTexture=c.createTexture(),c.bindTexture(c.TEXTURE_2D,f.tempTexture),c.texImage2D(c.TEXTURE_2D,0,c.RGB,16,16,0,c.RGB,c.UNSIGNED_BYTE,null),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST),c.bindTexture(c.TEXTURE_2D,f.occlusionTexture),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,16,16,0,c.RGBA,c.UNSIGNED_BYTE,null),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,c.NEAREST),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,c.NEAREST),c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)<=0?(f.hasVertexTexture=!1,f.program=b(a.ShaderFlares.lensFlare,e)):(f.hasVertexTexture=!0,f.program=b(a.ShaderFlares.lensFlareVertexTexture,e)),f.attributes={},f.uniforms={},f.attributes.vertex=c.getAttribLocation(f.program,"position"),f.attributes.uv=c.getAttribLocation(f.program,"uv"),f.uniforms.renderType=c.getUniformLocation(f.program,"renderType"),f.uniforms.map=c.getUniformLocation(f.program,"map"),f.uniforms.occlusionMap=c.getUniformLocation(f.program,"occlusionMap"),f.uniforms.opacity=c.getUniformLocation(f.program,"opacity"),f.uniforms.color=c.getUniformLocation(f.program,"color"),f.uniforms.scale=c.getUniformLocation(f.program,"scale"),f.uniforms.rotation=c.getUniformLocation(f.program,"rotation"),f.uniforms.screenPosition=c.getUniformLocation(f.program,"screenPosition")},this.render=function(b,e,g,h){var i=b.__webglFlares,j=i.length;if(j){var k=new a.Vector3,l=h/g,m=.5*g,n=.5*h,o=16/h,p=new a.Vector2(o*l,o),q=new a.Vector3(1,1,0),r=new a.Vector2(1,1),s=f.uniforms,t=f.attributes;c.useProgram(f.program),c.enableVertexAttribArray(f.attributes.vertex),c.enableVertexAttribArray(f.attributes.uv),c.uniform1i(s.occlusionMap,0),c.uniform1i(s.map,1),c.bindBuffer(c.ARRAY_BUFFER,f.vertexBuffer),c.vertexAttribPointer(t.vertex,2,c.FLOAT,!1,16,0),c.vertexAttribPointer(t.uv,2,c.FLOAT,!1,16,8),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,f.elementBuffer),c.disable(c.CULL_FACE),c.depthMask(!1);var u,v,w,x,y;for(u=0;j>u;u++)if(o=16/h,p.set(o*l,o),x=i[u],k.set(x.matrixWorld.elements[12],x.matrixWorld.elements[13],x.matrixWorld.elements[14]),k.applyMatrix4(e.matrixWorldInverse),k.applyProjection(e.projectionMatrix),q.copy(k),r.x=q.x*m+m,r.y=q.y*n+n,f.hasVertexTexture||r.x>0&&r.x0&&r.yv;v++)y=x.lensFlares[v],y.opacity>.001&&y.scale>.001&&(q.x=y.x,q.y=y.y,q.z=y.z,o=y.size*y.scale/h,p.x=o*l,p.y=o,c.uniform3f(s.screenPosition,q.x,q.y,q.z),c.uniform2f(s.scale,p.x,p.y),c.uniform1f(s.rotation,y.rotation),c.uniform1f(s.opacity,y.opacity),c.uniform3f(s.color,y.color.r,y.color.g,y.color.b),d.setBlending(y.blending,y.blendEquation,y.blendSrc,y.blendDst),d.setTexture(y.texture,1),c.drawElements(c.TRIANGLES,6,c.UNSIGNED_SHORT,0));
+c.enable(c.CULL_FACE),c.enable(c.DEPTH_TEST),c.depthMask(!0)}}},a.ShadowMapPlugin=function(){function b(b,c){var d=new a.DirectionalLight;d.isVirtual=!0,d.onlyShadow=!0,d.castShadow=!0,d.shadowCameraNear=b.shadowCameraNear,d.shadowCameraFar=b.shadowCameraFar,d.shadowCameraLeft=b.shadowCameraLeft,d.shadowCameraRight=b.shadowCameraRight,d.shadowCameraBottom=b.shadowCameraBottom,d.shadowCameraTop=b.shadowCameraTop,d.shadowCameraVisible=b.shadowCameraVisible,d.shadowDarkness=b.shadowDarkness,d.shadowBias=b.shadowCascadeBias[c],d.shadowMapWidth=b.shadowCascadeWidth[c],d.shadowMapHeight=b.shadowCascadeHeight[c],d.pointsWorld=[],d.pointsFrustum=[];for(var e=d.pointsWorld,f=d.pointsFrustum,g=0;8>g;g++)e[g]=new a.Vector3,f[g]=new a.Vector3;var h=b.shadowCascadeNearZ[c],i=b.shadowCascadeFarZ[c];return f[0].set(-1,-1,h),f[1].set(1,-1,h),f[2].set(-1,1,h),f[3].set(1,1,h),f[4].set(-1,-1,i),f[5].set(1,-1,i),f[6].set(-1,1,i),f[7].set(1,1,i),d}function c(a,b){var c=a.shadowCascadeArray[b];c.position.copy(a.position),c.target.position.copy(a.target.position),c.lookAt(c.target),c.shadowCameraVisible=a.shadowCameraVisible,c.shadowDarkness=a.shadowDarkness,c.shadowBias=a.shadowCascadeBias[b];var d=a.shadowCascadeNearZ[b],e=a.shadowCascadeFarZ[b],f=c.pointsFrustum;f[0].z=d,f[1].z=d,f[2].z=d,f[3].z=d,f[4].z=e,f[5].z=e,f[6].z=e,f[7].z=e}function d(b,c){var d=c.shadowCamera,e=c.pointsFrustum,f=c.pointsWorld;n.set(1/0,1/0,1/0),o.set(-1/0,-1/0,-1/0);for(var g=0;8>g;g++){var h=f[g];h.copy(e[g]),a.ShadowMapPlugin.__projector.unprojectVector(h,b),h.applyMatrix4(d.matrixWorldInverse),h.xo.x&&(o.x=h.x),h.yo.y&&(o.y=h.y),h.zo.z&&(o.z=h.z)}d.left=n.x,d.right=o.x,d.top=o.y,d.bottom=n.y,d.updateProjectionMatrix()}function e(b){return b.material instanceof a.MeshFaceMaterial?b.material.materials[0]:b.material}var f,g,h,i,j,k,l=new a.Frustum,m=new a.Matrix4,n=new a.Vector3,o=new a.Vector3,p=new a.Vector3;this.init=function(b){f=b.context,g=b;var c=a.ShaderLib.depthRGBA,d=a.UniformsUtils.clone(c.uniforms);h=new a.ShaderMaterial({fragmentShader:c.fragmentShader,vertexShader:c.vertexShader,uniforms:d}),i=new a.ShaderMaterial({fragmentShader:c.fragmentShader,vertexShader:c.vertexShader,uniforms:d,morphTargets:!0}),j=new a.ShaderMaterial({fragmentShader:c.fragmentShader,vertexShader:c.vertexShader,uniforms:d,skinning:!0}),k=new a.ShaderMaterial({fragmentShader:c.fragmentShader,vertexShader:c.vertexShader,uniforms:d,morphTargets:!0,skinning:!0}),h._shadowPass=!0,i._shadowPass=!0,j._shadowPass=!0,k._shadowPass=!0},this.render=function(a,b){g.shadowMapEnabled&&g.shadowMapAutoUpdate&&this.update(a,b)},this.update=function(n,o){var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E=[],F=0,G=null;for(f.clearColor(1,1,1,1),f.disable(f.BLEND),f.enable(f.CULL_FACE),f.frontFace(f.CCW),f.cullFace(g.shadowMapCullFace===a.CullFaceFront?f.FRONT:f.BACK),g.setDepthTest(!0),q=0,r=n.__lights.length;r>q;q++)if(C=n.__lights[q],C.castShadow)if(C instanceof a.DirectionalLight&&C.shadowCascade)for(u=0;uq;q++){if(C=E[q],!C.shadowMap){var J=a.LinearFilter;g.shadowMapType===a.PCFSoftShadowMap&&(J=a.NearestFilter);var K={minFilter:J,magFilter:J,format:a.RGBAFormat};C.shadowMap=new a.WebGLRenderTarget(C.shadowMapWidth,C.shadowMapHeight,K),C.shadowMapSize=new a.Vector2(C.shadowMapWidth,C.shadowMapHeight),C.shadowMatrix=new a.Matrix4}if(!C.shadowCamera){if(C instanceof a.SpotLight)C.shadowCamera=new a.PerspectiveCamera(C.shadowCameraFov,C.shadowMapWidth/C.shadowMapHeight,C.shadowCameraNear,C.shadowCameraFar);else{if(!(C instanceof a.DirectionalLight)){console.error("Unsupported light type for shadow");continue}C.shadowCamera=new a.OrthographicCamera(C.shadowCameraLeft,C.shadowCameraRight,C.shadowCameraTop,C.shadowCameraBottom,C.shadowCameraNear,C.shadowCameraFar)}n.add(C.shadowCamera),n.autoUpdate===!0&&n.updateMatrixWorld()}for(C.shadowCameraVisible&&!C.cameraHelper&&(C.cameraHelper=new a.CameraHelper(C.shadowCamera),C.shadowCamera.add(C.cameraHelper)),C.isVirtual&&H.originalCamera==o&&d(o,C),v=C.shadowMap,w=C.shadowMatrix,x=C.shadowCamera,x.position.setFromMatrixPosition(C.matrixWorld),p.setFromMatrixPosition(C.target.matrixWorld),x.lookAt(p),x.updateMatrixWorld(),x.matrixWorldInverse.getInverse(x.matrixWorld),C.cameraHelper&&(C.cameraHelper.visible=C.shadowCameraVisible),C.shadowCameraVisible&&C.cameraHelper.update(),w.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),w.multiply(x.projectionMatrix),w.multiply(x.matrixWorldInverse),m.multiplyMatrices(x.projectionMatrix,x.matrixWorldInverse),l.setFromMatrix(m),g.setRenderTarget(v),g.clear(),D=n.__webglObjects,s=0,t=D.length;t>s;s++)A=D[s],B=A.object,A.render=!1,B.visible&&B.castShadow&&((B instanceof a.Mesh||B instanceof a.ParticleSystem)&&B.frustumCulled&&!l.intersectsObject(B)||(B._modelViewMatrix.multiplyMatrices(x.matrixWorldInverse,B.matrixWorld),A.render=!0));var L,M,N;for(s=0,t=D.length;t>s;s++)A=D[s],A.render&&(B=A.object,y=A.buffer,L=e(B),M=void 0!==B.geometry.morphTargets&&B.geometry.morphTargets.length>0&&L.morphTargets,N=B instanceof a.SkinnedMesh&&L.skinning,z=B.customDepthMaterial?B.customDepthMaterial:N?M?k:j:M?i:h,y instanceof a.BufferGeometry?g.renderBufferDirect(x,n.__lights,G,z,y,B):g.renderBuffer(x,n.__lights,G,z,y,B));for(D=n.__webglObjectsImmediate,s=0,t=D.length;t>s;s++)A=D[s],B=A.object,B.visible&&B.castShadow&&(B._modelViewMatrix.multiplyMatrices(x.matrixWorldInverse,B.matrixWorld),g.renderImmediateObject(x,n.__lights,G,h,B))}var O=g.getClearColor(),P=g.getClearAlpha();f.clearColor(O.r,O.g,O.b,P),f.enable(f.BLEND),g.shadowMapCullFace===a.CullFaceFront&&f.cullFace(f.BACK)}},a.ShadowMapPlugin.__projector=new a.Projector,a.SpritePlugin=function(){function b(){var a=d.createProgram(),b=d.createShader(d.VERTEX_SHADER),c=d.createShader(d.FRAGMENT_SHADER);return d.shaderSource(b,["precision "+e.getPrecision()+" float;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform float rotation;","uniform vec2 scale;","uniform vec2 uvOffset;","uniform vec2 uvScale;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","void main() {","vUV = uvOffset + uv * uvScale;","vec2 alignedPosition = position * scale;","vec2 rotatedPosition;","rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;","rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;","vec4 finalPosition;","finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );","finalPosition.xy += rotatedPosition;","finalPosition = projectionMatrix * finalPosition;","gl_Position = finalPosition;","}"].join("\n")),d.shaderSource(c,["precision "+e.getPrecision()+" float;","uniform vec3 color;","uniform sampler2D map;","uniform float opacity;","uniform int fogType;","uniform vec3 fogColor;","uniform float fogDensity;","uniform float fogNear;","uniform float fogFar;","uniform float alphaTest;","varying vec2 vUV;","void main() {","vec4 texture = texture2D( map, vUV );","if ( texture.a < alphaTest ) discard;","gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );","if ( fogType > 0 ) {","float depth = gl_FragCoord.z / gl_FragCoord.w;","float fogFactor = 0.0;","if ( fogType == 1 ) {","fogFactor = smoothstep( fogNear, fogFar, depth );","} else {","const float LOG2 = 1.442695;","float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );","fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );","}","gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );","}","}"].join("\n")),d.compileShader(b),d.compileShader(c),d.attachShader(a,b),d.attachShader(a,c),d.linkProgram(a),a}function c(a,b){return a.z!==b.z?b.z-a.z:b.id-a.id}var d,e,f,g,h,i,j,k,l,m;this.init=function(c){d=c.context,e=c,g=new Float32Array([-.5,-.5,0,0,.5,-.5,1,0,.5,.5,1,1,-.5,.5,0,1]),h=new Uint16Array([0,1,2,0,2,3]),i=d.createBuffer(),j=d.createBuffer(),d.bindBuffer(d.ARRAY_BUFFER,i),d.bufferData(d.ARRAY_BUFFER,g,d.STATIC_DRAW),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,j),d.bufferData(d.ELEMENT_ARRAY_BUFFER,h,d.STATIC_DRAW),k=b(),l={position:d.getAttribLocation(k,"position"),uv:d.getAttribLocation(k,"uv")},m={uvOffset:d.getUniformLocation(k,"uvOffset"),uvScale:d.getUniformLocation(k,"uvScale"),rotation:d.getUniformLocation(k,"rotation"),scale:d.getUniformLocation(k,"scale"),color:d.getUniformLocation(k,"color"),map:d.getUniformLocation(k,"map"),opacity:d.getUniformLocation(k,"opacity"),modelViewMatrix:d.getUniformLocation(k,"modelViewMatrix"),projectionMatrix:d.getUniformLocation(k,"projectionMatrix"),fogType:d.getUniformLocation(k,"fogType"),fogDensity:d.getUniformLocation(k,"fogDensity"),fogNear:d.getUniformLocation(k,"fogNear"),fogFar:d.getUniformLocation(k,"fogFar"),fogColor:d.getUniformLocation(k,"fogColor"),alphaTest:d.getUniformLocation(k,"alphaTest")};var n=document.createElement("canvas");n.width=8,n.height=8;var o=n.getContext("2d");o.fillStyle="#ffffff",o.fillRect(0,0,n.width,n.height),f=new a.Texture(n),f.needsUpdate=!0},this.render=function(b,g){var h=b.__webglSprites,n=h.length;if(n){d.useProgram(k),d.enableVertexAttribArray(l.position),d.enableVertexAttribArray(l.uv),d.disable(d.CULL_FACE),d.enable(d.BLEND),d.bindBuffer(d.ARRAY_BUFFER,i),d.vertexAttribPointer(l.position,2,d.FLOAT,!1,16,0),d.vertexAttribPointer(l.uv,2,d.FLOAT,!1,16,8),d.bindBuffer(d.ELEMENT_ARRAY_BUFFER,j),d.uniformMatrix4fv(m.projectionMatrix,!1,g.projectionMatrix.elements),d.activeTexture(d.TEXTURE0),d.uniform1i(m.map,0);var o=0,p=0,q=b.fog;q?(d.uniform3f(m.fogColor,q.color.r,q.color.g,q.color.b),q instanceof a.Fog?(d.uniform1f(m.fogNear,q.near),d.uniform1f(m.fogFar,q.far),d.uniform1i(m.fogType,1),o=1,p=1):q instanceof a.FogExp2&&(d.uniform1f(m.fogDensity,q.density),d.uniform1i(m.fogType,2),o=2,p=2)):(d.uniform1i(m.fogType,0),o=0,p=0);var r,s,t,u,v=[];for(r=0;n>r;r++)s=h[r],t=s.material,s.visible!==!1&&(s._modelViewMatrix.multiplyMatrices(g.matrixWorldInverse,s.matrixWorld),s.z=-s._modelViewMatrix.elements[14]);for(h.sort(c),r=0;n>r;r++)s=h[r],s.visible!==!1&&(t=s.material,d.uniform1f(m.alphaTest,t.alphaTest),d.uniformMatrix4fv(m.modelViewMatrix,!1,s._modelViewMatrix.elements),v[0]=s.scale.x,v[1]=s.scale.y,u=b.fog&&t.fog?p:0,o!==u&&(d.uniform1i(m.fogType,u),o=u),null!==t.map?(d.uniform2f(m.uvOffset,t.map.offset.x,t.map.offset.y),d.uniform2f(m.uvScale,t.map.repeat.x,t.map.repeat.y)):(d.uniform2f(m.uvOffset,0,0),d.uniform2f(m.uvScale,1,1)),d.uniform1f(m.opacity,t.opacity),d.uniform3f(m.color,t.color.r,t.color.g,t.color.b),d.uniform1f(m.rotation,t.rotation),d.uniform2fv(m.scale,v),e.setBlending(t.blending,t.blendEquation,t.blendSrc,t.blendDst),e.setDepthTest(t.depthTest),e.setDepthWrite(t.depthWrite),t.map&&t.map.image&&t.map.image.width?e.setTexture(t.map,0):e.setTexture(f,0),d.drawElements(d.TRIANGLES,6,d.UNSIGNED_SHORT,0));d.enable(d.CULL_FACE)}}},a.DepthPassPlugin=function(){function b(b){return b.material instanceof a.MeshFaceMaterial?b.material.materials[0]:b.material}this.enabled=!1,this.renderTarget=null;var c,d,e,f,g,h,i=new a.Frustum,j=new a.Matrix4;this.init=function(b){c=b.context,d=b;var i=a.ShaderLib.depthRGBA,j=a.UniformsUtils.clone(i.uniforms);e=new a.ShaderMaterial({fragmentShader:i.fragmentShader,vertexShader:i.vertexShader,uniforms:j}),f=new a.ShaderMaterial({fragmentShader:i.fragmentShader,vertexShader:i.vertexShader,uniforms:j,morphTargets:!0}),g=new a.ShaderMaterial({fragmentShader:i.fragmentShader,vertexShader:i.vertexShader,uniforms:j,skinning:!0}),h=new a.ShaderMaterial({fragmentShader:i.fragmentShader,vertexShader:i.vertexShader,uniforms:j,morphTargets:!0,skinning:!0}),e._shadowPass=!0,f._shadowPass=!0,g._shadowPass=!0,h._shadowPass=!0},this.render=function(a,b){this.enabled&&this.update(a,b)},this.update=function(k,l){var m,n,o,p,q,r,s,t=null;for(c.clearColor(1,1,1,1),c.disable(c.BLEND),d.setDepthTest(!0),k.autoUpdate===!0&&k.updateMatrixWorld(),l.matrixWorldInverse.getInverse(l.matrixWorld),j.multiplyMatrices(l.projectionMatrix,l.matrixWorldInverse),i.setFromMatrix(j),d.setRenderTarget(this.renderTarget),d.clear(),s=k.__webglObjects,m=0,n=s.length;n>m;m++)q=s[m],r=q.object,q.render=!1,r.visible&&((r instanceof a.Mesh||r instanceof a.ParticleSystem)&&r.frustumCulled&&!i.intersectsObject(r)||(r._modelViewMatrix.multiplyMatrices(l.matrixWorldInverse,r.matrixWorld),q.render=!0));var u,v,w;for(m=0,n=s.length;n>m;m++)if(q=s[m],q.render){if(r=q.object,o=q.buffer,r instanceof a.ParticleSystem&&!r.customDepthMaterial)continue;u=b(r),u&&d.setMaterialFaces(r.material),v=r.geometry.morphTargets.length>0&&u.morphTargets,w=r instanceof a.SkinnedMesh&&u.skinning,p=r.customDepthMaterial?r.customDepthMaterial:w?v?h:g:v?f:e,o instanceof a.BufferGeometry?d.renderBufferDirect(l,k.__lights,t,p,o,r):d.renderBuffer(l,k.__lights,t,p,o,r)}for(s=k.__webglObjectsImmediate,m=0,n=s.length;n>m;m++)q=s[m],r=q.object,r.visible&&(r._modelViewMatrix.multiplyMatrices(l.matrixWorldInverse,r.matrixWorld),d.renderImmediateObject(l,k.__lights,t,e,r));var x=d.getClearColor(),y=d.getClearAlpha();c.clearColor(x.r,x.g,x.b,y),c.enable(c.BLEND)}},a.ShaderFlares={lensFlareVertexTexture:{vertexShader:["uniform lowp int renderType;","uniform vec3 screenPosition;","uniform vec2 scale;","uniform float rotation;","uniform sampler2D occlusionMap;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","varying float vVisibility;","void main() {","vUV = uv;","vec2 pos = position;","if( renderType == 2 ) {","vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );","vVisibility = visibility.r / 9.0;","vVisibility *= 1.0 - visibility.g / 9.0;","vVisibility *= visibility.b / 9.0;","vVisibility *= 1.0 - visibility.a / 9.0;","pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;","pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;","}","gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );","}"].join("\n"),fragmentShader:["uniform lowp int renderType;","uniform sampler2D map;","uniform float opacity;","uniform vec3 color;","varying vec2 vUV;","varying float vVisibility;","void main() {","if( renderType == 0 ) {","gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );","} else if( renderType == 1 ) {","gl_FragColor = texture2D( map, vUV );","} else {","vec4 texture = texture2D( map, vUV );","texture.a *= opacity * vVisibility;","gl_FragColor = texture;","gl_FragColor.rgb *= color;","}","}"].join("\n")},lensFlare:{vertexShader:["uniform lowp int renderType;","uniform vec3 screenPosition;","uniform vec2 scale;","uniform float rotation;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","void main() {","vUV = uv;","vec2 pos = position;","if( renderType == 2 ) {","pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;","pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;","}","gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );","}"].join("\n"),fragmentShader:["precision mediump float;","uniform lowp int renderType;","uniform sampler2D map;","uniform sampler2D occlusionMap;","uniform float opacity;","uniform vec3 color;","varying vec2 vUV;","void main() {","if( renderType == 0 ) {","gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );","} else if( renderType == 1 ) {","gl_FragColor = texture2D( map, vUV );","} else {","float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;","visibility = ( 1.0 - visibility / 4.0 );","vec4 texture = texture2D( map, vUV );","texture.a *= opacity * visibility;","gl_FragColor = texture;","gl_FragColor.rgb *= color;","}","}"].join("\n")}}}(),BrainBrowser.SurfaceViewer.modules.annotations=function(a){"use strict";function b(b){b=b||{};var c=b.model_name||null;return!c&&a.model.children[0]&&(c=a.model.children[0].userData.model_name),c}var c=BrainBrowser.createTreeStore(),d=.5,e=65280,f=16711680;a.annotations={add:function(e,g,h){h=h||{};var i,j,k=b(h);k&&(j=a.getVertex(e,{model_name:h.model_name}),i={data:g,model_name:k,vertex:e,position:j,marker:a.drawDot(j.x,j.y,j.z,d,f)},i.marker.userData.annotation_info=i,c.set(k,e,i),h.activate!==!1&&a.annotations.activate(e,h))},get:function(d,e){e=e||{};var f,g=b(e);return g?(f=c.get(g,d),e.activate!==!1&&a.annotations.activate(d,e),f):null},remove:function(d,e){e=e||{};var f,g=b(e);return g?(f=c.remove(g,d),a.model.remove(f.marker),f.marker=null,a.updated=!0,f):null},reset:function(){a.annotations.forEach(function(b){a.annotations.remove(b.vertex)})},activate:function(b,c){c=c||{};var d=a.annotations.get(b,{model_name:c.model_name,activate:!1});d&&(a.annotations.forEach(function(a){a.marker.material.color.setHex(a===d?e:f)}),a.updated=!0)},forEach:function(a){c.forEach(2,a)},setMarkerOnColor:function(a){e=a},setMarkerOffColor:function(a){f=a},setMarkerRadius:function(a){d=a}}},BrainBrowser.SurfaceViewer.modules.color=function(a){"use strict";function b(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p;for(i=0,k=b.length;k>i;i++){for(d=b[i],l=d.getObjectByName("__WIREFRAME__"),p=!!l,p&&(m=l.geometry.attributes.color.array),c=d.geometry,e=d.userData.original_data.indices,f=c.attributes.color,g=f.array,h=0,j=e.length;j>h;h+=3)n=4*h,o=2*n,g[n]=a[4*e[h]],g[n+1]=a[4*e[h]+1],g[n+2]=a[4*e[h]+2],g[n+3]=1,g[n+4]=a[4*e[h+1]],g[n+5]=a[4*e[h+1]+1],g[n+6]=a[4*e[h+1]+2],g[n+7]=1,g[n+8]=a[4*e[h+2]],g[n+9]=a[4*e[h+2]+1],g[n+10]=a[4*e[h+2]+2],g[n+11]=1,p&&(m[o]=g[n],m[o+1]=g[n+1],m[o+2]=g[n+2],m[o+3]=g[n+3],m[o+4]=g[n+4],m[o+5]=g[n+5],m[o+6]=g[n+6],m[o+7]=g[n+7],m[o+8]=g[n+4],m[o+9]=g[n+5],m[o+10]=g[n+6],m[o+11]=g[n+7],m[o+12]=g[n+8],m[o+13]=g[n+9],m[o+14]=g[n+10],m[o+15]=g[n+11],m[o+16]=g[n+8],m[o+17]=g[n+9],m[o+18]=g[n+10],m[o+19]=g[n+11],m[o+20]=g[n],m[o+21]=g[n+1],m[o+22]=g[n+2],m[o+23]=g[n+3]);f.needsUpdate=!0,p&&(l.geometry.attributes.color.needsUpdate=!0)}}function c(b,c){var d,e,f,g,h,i,j,k=a.model_data.get(c),l=[],m=[];for(b.forEach(function(b){l.push(a.color_map.mapColors(b.values,{min:b.range_min,max:b.range_max,default_colors:k.colors})),m.push(b.alpha)}),d=new Float32Array(l[0].length),e=0,i=l[0].length/4;i>e;e++)for(f=0,h=l.length;h>f;f++)g=4*e,j=m[f],d[g]+=l[f][g]*j,d[g+1]+=l[f][g+1]*j,d[g+2]+=l[f][g+2]*j,d[g+3]+=j;return d}var d=null;a.updateColors=function(e){function f(c){var d,e=a.model.getObjectByName(k,!0);d=e?[e]:a.model.children.filter(function(a){return!!a.userData.original_data}),b(c,d),i&&i(),a.triggerEvent("updatecolors",{model_data:l,intensity_data:g,colors:c,blend:h}),h&&a.triggerEvent("blendcolors",{model_data:l,intensity_data:g,colors:c})}e=e||{};var g,h,i=e.complete,j=e.model_name,k=e.shape_name||j+"_1",l=a.model_data.get(j);l.intensity_data.length>1?(g=l.intensity_data,h=!0):(g=l.intensity_data[0],h=!1),clearTimeout(d),d=setTimeout(function(){f(h?c(g,e.model_name):a.color_map.mapColors(g.values,{min:g.range_min,max:g.range_max,default_colors:a.model_data.get(e.model_name).colors}))},0)},a.setIntensity=function(){var b,c,d,e,f,g=Array.prototype.slice.call(arguments);b=BrainBrowser.utils.isNumeric(g[0])?a.model_data.getDefaultIntensityData():g.shift(),f=b.model_data,c=g[0],d=g[1],e=g[2]||{},b&&c>=0&&c1?a.blend(d.complete):a.updateColors({model_name:h,complete:d.complete}),a.triggerEvent("loadintensitydata",{model_data:i,intensity_data:b})})}function d(b){a.color_map=b,a.triggerEvent("loadcolormap",{color_map:b}),a.model_data.forEach(function(b){b.intensity_data[0]&&a.updateColors({model_name:b.name})})}function e(a,b,c,d){var e,f=b+"_model";if(!j.worker_urls[f])throw e="error in SurfaceViewer configuration.\nModel worker URL for "+b+" not defined.\nUse 'BrainBrowser.config.set(\"model_types."+b+".worker\", ...)' to set it.",BrainBrowser.events.triggerEvent("error",{message:e}),new Error(e);var g,h=new Worker(j.worker_urls[f]);h.addEventListener("message",function(a){var f=a.data;if(f.error)throw e="error parsing model.\n"+f.error_message+"\nFile type: "+b+"\nOptions: "+JSON.stringify(c),BrainBrowser.events.triggerEvent("error",{message:e}),new Error(e);f.colors=f.colors||[.7,.7,.7,1],g=new Worker(j.worker_urls.deindex),g.addEventListener("message",function(a){d(a.data)}),g.postMessage(f),h.terminate()}),h.postMessage({data:a,options:c})}function f(b,c,d){d=d||{};var e=d.complete,f=g(b,c,d);a.triggerEvent("displaymodel",{model:a.model,model_data:b,new_shapes:f}),e&&e()}function g(b,c,d){var e,f,g,i,j=a.model,k=b.shapes,l="line"===b.type,m=d.render_depth,n=d.pick_ignore,o=[];if(b.name=b.name||c,a.model_data.add(b.name,b),k){for(g=0,i=k.length;i>g;g++)f=b.shapes[g],e=h(f,l),e.name=f.name||c+"_"+(g+1),e.userData.model_name=b.name,e.userData.original_data={vertices:b.vertices,indices:f.indices,normals:b.normals,colors:b.colors},e.userData.pick_ignore=n,m&&(e.renderDepth=m),o.push(e),j.add(e);b.split&&(j.children[0].name="left",j.children[1].name="right")}return o}function h(a,b){var c,d,e=a.unindexed,f=a.centroid,g=e.position,h=e.normal||[],i=e.color||[],j=new k.BufferGeometry;return j.dynamic=!0,j.attributes.position={itemSize:3,array:new Float32Array(g),numItems:g.length},h.length>0?j.attributes.normal={itemSize:3,array:new Float32Array(h)}:j.computeVertexNormals(),i.length>0&&(j.attributes.color={itemSize:4,array:new Float32Array(i)}),b?(c=new k.LineBasicMaterial({vertexColors:k.VertexColors}),d=new k.Line(j,c,k.LinePieces)):(c=new k.MeshPhongMaterial({color:16777215,ambient:16777215,specular:1052688,shininess:150,vertexColors:k.VertexColors}),d=new k.Mesh(j,c),d.has_wireframe=!0),d.centroid=f,d.position.set(f.x,f.y,f.z),d}function i(a){a=a||{};var b=a.format||"mniobj",c=BrainBrowser.config.get("model_types."+b);return c&&c.binary&&(a.result_type=a.result_type||"arraybuffer"),a}var j=BrainBrowser.SurfaceViewer,k=j.THREE,l=BrainBrowser.loader,m={};a.model_data={add:function(a,b){m[a]=b,b.intensity_data=[]},get:function(a){return a=a||Object.keys(m)[0],m[a]||null},getDefaultIntensityData:function(a){var b,c,d,e;if(a)b=this.get(a),c=b?b.intensity_data[0]:null;else for(b=Object.keys(m).map(function(a){return m[a]}),d=0,e=b.length;e>d&&!(c=b[d].intensity_data[0]);d++);return c||null},count:function(){return Object.keys(m).length},clear:function(){m={}},forEach:function(a){Object.keys(m).forEach(function(b){a(m[b],b)})}},a.loadModelFromURL=function(a,c){c=i(c),l.loadFromURL(a,b,c)},a.loadModelFromFile=function(a,c){c=i(c),l.loadFromFile(a,b,c)},a.loadIntensityDataFromURL=function(a,b){b=i(b),l.loadFromURL(a,c,b)},a.loadIntensityDataFromFile=function(a,b){b=i(b),l.loadFromFile(a,c,b)},a.loadColorMapFromURL=function(a,b){l.loadColorMapFromURL(a,d,b)},a.loadColorMapFromFile=function(a,b){l.loadColorMapFromFile(a,d,b)},a.clearScreen=function(){for(var b=a.model.children;b.length>0;)a.model.remove(b[0]);a.model_data.clear(),a.resetView(),a.triggerEvent("clearscreen")}},BrainBrowser.SurfaceViewer.modules.rendering=function(a){"use strict";function b(f){var g,m,n=a.model,o=i.position,p=j/a.zoom;window.requestAnimationFrame(b),d=c||f,c=f,g=c-d,m=15e-5*g,a.autorotate.x&&(n.rotation.x+=m,a.updated=!0),a.autorotate.y&&(n.rotation.y+=m,a.updated=!0),a.autorotate.z&&(n.rotation.z+=m,a.updated=!0),e!==a.zoom&&(e=a.zoom,a.updated=!0,a.triggerEvent("zoom",{zoom:a.zoom})),a.updated&&(p>i.near&&p<.9*i.far&&(o.z=p,k.position.z=p),l.render(h,i),a.triggerEvent("draw",{renderer:l,scene:h,camera:i}),a.updated=!1)}var c,d,e,f=BrainBrowser.SurfaceViewer.THREE,g=new f.WebGLRenderer({preserveDrawingBuffer:!0}),h=new f.Scene,i=new f.PerspectiveCamera(30,a.dom_element.offsetWidth/a.dom_element.offsetHeight,1,3e3),j=500,k=new f.PointLight(16777215),l=g,m={},n=g.domElement;a.model=new f.Object3D,h.add(a.model),a.render=function(){var c=a.dom_element;g.setClearColor(0),c.appendChild(g.domElement),i.position.z=j,k.position.set(0,0,j),h.add(k),a.updateViewport(),b()},a.updateViewport=function(){var b=a.dom_element;l.setSize(b.offsetWidth,b.offsetHeight),i.aspect=b.offsetWidth/b.offsetHeight,i.updateProjectionMatrix(),a.updated=!0},a.canvasDataURL=function(){return g.domElement.toDataURL()},a.addEffect=function(b){var c;BrainBrowser.utils.isFunction(f[b])&&(c=new f[b](g),c.setSize(a.dom_element.offsetWidth,a.dom_element.offsetHeight),m[b]=c)},a.setEffect=function(b){l=m[b]?m[b]:g,l.setSize(a.dom_element.offsetWidth,a.dom_element.offsetHeight),l.render(h,i),a.updated=!0},a.setCameraPosition=function(b,c,d){i.position.set(b,c,d),k.position.set(b,c,d),a.updated=!0},a.resetView=function(){var b,c,d,e,g=a.model,h=new f.Matrix4;for(h.getInverse(g.matrix),g.applyMatrix(h),i.position.set(0,0,j),k.position.set(0,0,j),a.zoom=1,d=0,e=a.model.children.length;e>d;d++)b=g.children[d],b.centroid?b.position.set(b.centroid.x,b.centroid.y,b.centroid.z):b.position.set(0,0,0),b.rotation.set(0,0,0),c=b.getObjectByName("__WIREFRAME__");a.updated=!0},a.setClearColor=function(b){g.setClearColor(b,1),a.updated=!0},a.drawDot=function(b,c,d,e,g){e=e||2,e=e>=0?e:0,g=g>=0?g:16711680;var i=new f.SphereGeometry(e),j=new f.MeshBasicMaterial({color:g}),k=new f.Mesh(i,j);return k.position.set(b,c,d),a.model?a.model.add(k):h.add(k),a.updated=!0,k},a.pick=function(b,c){b=void 0===b?a.mouse.x:b,c=void 0===c?a.mouse.y:c,b=b/a.dom_element.offsetWidth*2-1,c=-c/a.dom_element.offsetHeight*2+1;var d,e,g,h,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y=a.model,z=new f.Projector,A=new f.Raycaster,B=new f.Vector3(b,c,i.near),C=null,D=new f.Matrix4;for(z.unprojectVector(B,i),A.set(i.position,B.sub(i.position).normalize()),d=A.intersectObject(y,!0),s=0;ss;s++)p=o[j[s]],q=new f.Vector3(n[3*p],n[3*p+1],n[3*p+2]),r=h.distanceTo(new f.Vector3(q.x-v,q.y-w,q.z-x)),m>r&&(k=p,l=q,m=r);e={index:k,point:l,object:g}}else e=null;return e},function(){function b(b,c){var d,e,g=new f.Matrix4,h=b.x,l=b.y;if(null!==p)if(d=h-p,e=l-q,"rotate"===o){g.getInverse(m.matrix);var n=new f.Vector3(1,0,0).applyMatrix4(g).normalize();m.rotateOnAxis(n,e/150),g.getInverse(m.matrix),n=new f.Vector3(0,1,0).applyMatrix4(g).normalize(),m.rotateOnAxis(n,d/150)}else c=c||1,c*=i.position.z/j,i.position.x-=d*c*.25,k.position.x-=d*c*.25,i.position.y+=e*c*.25,k.position.y+=e*c*.25;p=h,q=l,a.updated=!0}function c(){var b,c=a.touches[0].x-a.touches[1].x,d=a.touches[0].y-a.touches[1].y,e=Math.sqrt(c*c+d*d);null!==r&&(b=e-r,a.zoom*=1+.01*b),r=e}function d(c){c.preventDefault(),b(a.mouse,1.1)}function e(d){d.preventDefault(),"zoom"===o?c():b(a.touches[0],2)}function g(){document.removeEventListener("mousemove",d,!1),document.removeEventListener("mouseup",g,!1),p=null,q=null}function h(){document.removeEventListener("touchmove",e,!1),document.removeEventListener("touchend",h,!1),p=null,q=null,r=null}function l(b){var c=Math.max(-1,Math.min(1,b.wheelDelta||-b.detail));b.preventDefault(),a.zoom*=1+.05*c}var m=a.model,o="rotate",p=null,q=null,r=null;n.addEventListener("mousedown",function(a){document.addEventListener("mousemove",d,!1),document.addEventListener("mouseup",g,!1),o=1===a.which?"rotate":"translate"},!1),n.addEventListener("touchstart",function(a){document.addEventListener("touchmove",e,!1),document.addEventListener("touchend",h,!1),o=1===a.touches.length?"rotate":2===a.touches.length?"zoom":"translate"},!1),n.addEventListener("mousewheel",l,!1),n.addEventListener("DOMMouseScroll",l,!1),n.addEventListener("contextmenu",function(a){a.preventDefault()},!1)}()},BrainBrowser.SurfaceViewer.modules.views=function(a){"use strict";function b(a,d){f>g?c(a,d):setTimeout(function(){b(a,d)},0)}function c(a,b){var c=new Worker(BrainBrowser.SurfaceViewer.worker_urls.wireframe),d=a.geometry.attributes;c.addEventListener("message",function(d){var f,h,i=d.data.positions,j=d.data.colors,k=new e.BufferGeometry;k.attributes.position={itemSize:3,array:i,numItems:i.length},k.attributes.color={itemSize:4,array:j},k.attributes.color.needsUpdate=!0,f=new e.LineBasicMaterial({vertexColors:e.VertexColors}),h=new e.Line(k,f,e.LinePieces),h.name="__WIREFRAME__",h.visible=!1,a.wireframe_active=!1,a.add(h),g--,b(h),c.terminate()}),c.postMessage({positions:d.position.array,colors:d.color.array}),g++}function d(b,c,d){b.visible=!d,c.visible=d,b.wireframe_active=d,a.updated=!0}var e=BrainBrowser.SurfaceViewer.THREE,f=20,g=0,h={medialView:function(b){var c=a.model;b.split&&(c.getObjectByName("left").position.x-=100,c.getObjectByName("left").rotation.z-=Math.PI/2,c.getObjectByName("right").position.x+=100,c.getObjectByName("right").rotation.z+=Math.PI/2,c.rotation.x-=Math.PI/2)},lateralView:function(b){var c,d,e=a.model;b.split&&(c=e.getObjectByName("left"),d=e.getObjectByName("right"),c.position.x-=100,c.rotation.z-=Math.PI/2,d.position.x+=100,d.rotation.z+=Math.PI/2,e.rotation.x+=Math.PI/2,e.rotation.y+=Math.PI)},inferiorView:function(){a.model.rotation.y+=Math.PI},anteriorView:function(){a.resetView(),a.model.rotation.x-=Math.PI/2,a.model.rotation.z+=Math.PI},posteriorView:function(){a.resetView(),a.model.rotation.x-=Math.PI/2}};a.setTransparency=function(b,c){c=c||{};var d,e,f,g=c.shape_name,h=a.model.getObjectByName(g);d=h?[h]:a.model.children||[],d.forEach(function(a){e=a.material,e.opacity=b,e.transparent=1===b?!1:!0,f=a.getObjectByName("__WIREFRAME__"),f&&(f.material.opacity=e.opacity,f.material.transparent=e.transparent)
+}),a.updated=!0},a.setWireframe=function(c,e){e=e||{};var f,g,h=e.shape_name,i=a.model.getObjectByName(h);f=i?[i]:a.model.children||[],f.forEach(function(a){g=a.getObjectByName("__WIREFRAME__"),g?d(a,g,c):a.has_wireframe&&b(a,function(b){d(a,b,c)})})},a.setView=function(b,c){var d=b+"View",e=a.model_data.get(c);a.resetView(),e&&BrainBrowser.utils.isFunction(h[d])&&h[d](e),a.updated=!0},a.separateHalves=function(b,c){b=b||1,c=c||{},a.model_data.get(c.model_name).split&&(a.model.children[0].position.x-=b,a.model.children[1].position.x+=b),a.updated=!0}};
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/brainbrowser.volume-viewer.min.js b/build/brainbrowser-2.2.0/brainbrowser.volume-viewer.min.js
new file mode 100644
index 00000000..d770b309
--- /dev/null
+++ b/build/brainbrowser-2.2.0/brainbrowser.volume-viewer.min.js
@@ -0,0 +1,33 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";var a="2.2.0";a=a.indexOf("BRAINBROWSER_VERSION")>0?"D.E.V":a,window.BrainBrowser={version:a},window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return window.setTimeout(a,1e3/60)},window.cancelAnimationFrame=window.cancelAnimationFrame||function(a){window.clearTimeout(a)}}(),function(){"use strict";function a(b,c,d,e){return c>d?e(b):void Object.keys(b).forEach(function(f){a(b[f],c+1,d,e)})}BrainBrowser.createTreeStore=function(){var b={};return{set:function(){var a,c,d,e,f=arguments[arguments.length-1],g=Array.prototype.slice.call(arguments,0,arguments.length-1),h=b;for(c=0,d=g.length-1;d>c;c++){if(a=g[c],h[a]&&"object"!=typeof h[a])throw e="Hash key '["+g.slice(0,c+1).join("][")+"]' has already been set to a non-object value.\nCannot set '["+g.join("][")+"]'",BrainBrowser.events.triggerEvent("error",{message:e}),new Error(e);h[a]||(h[a]={}),h=h[a]}a=g[c],h[a]=f},get:function(){var a,c,d,e=Array.prototype.slice.call(arguments),f=b;if(0===e.length)return b;for(c=0,d=e.length-1;d>c;c++){if(a=e[c],void 0===f[a])return null;f=f[a]}return a=e[c],void 0!==f[a]?f[a]:null},remove:function(){var a,c,d,e,f=Array.prototype.slice.call(arguments),g=b;for(c=0,d=f.length-1;d>c;c++){if(a=f[c],void 0===g[a])return null;g=g[a]}return a=f[c],e=g[a],g[a]=void 0,e},reset:function(a){a=a&&"object"==typeof a?a:{},b=a},forEach:function(c,d){c=c>0?c:1,a(b,1,c,d)}}}}(),function(){"use strict";BrainBrowser.createColorMap=function(a,b){function c(a,b,c,d,e,f,g){var h;return(b>a||a>c)&&!e?-1:(h=Math.floor(Math.max(0,Math.min((a-b)*d,g-1))),f&&(h=g-1-h),h*=4)}function d(a,b,c){var d,e,f,g=document.createElement("canvas"),h=new Array(256);for(g.width=256,g.height=c,d=0;256>d;d++)h[d]=d;for(f=r.scale,r.scale=255,a=r.mapColors(h),r.scale=f,e=g.getContext("2d"),d=0;256>d;d++)e.fillStyle="rgb("+Math.floor(a[4*d])+", "+Math.floor(a[4*d+1])+", "+Math.floor(a[4*d+2])+")",e.fillRect(d,0,1,b);return g}b=b||{};var e,f,g,h,i,j,k,l,m=void 0===b.clamp?!0:b.clamp,n=b.flip||!1,o=b.scale||1,p=b.contrast||1,q=b.brightness||0;if(a)for(f=a.trim().split(/\n/),e=new Float32Array(4*f.length),k=0,i=0,g=f.length;g>i;i++)if(l=f[i].trim().split(/\s+/).slice(0,4),h=l.length,!(3>h)){for(j=0;h>j;j++)e[k+j]=parseFloat(l[j]);4>h&&(e[k+3]=1),k+=4}var r={colors:e,clamp:m,flip:n,scale:o,contrast:p,brightness:q,mapColors:function(a,b){b=b||{};var d,e,f,g,h,i,j=void 0===b.min?0:b.min,k=void 0===b.max?255:b.max,l=b.default_colors||[0,0,0,1],m=b.destination||new Float32Array(4*a.length),n=r.colors,o=r.colors.length/4,p=void 0===b.scale?r.scale:b.scale,q=void 0===b.clamp?r.clamp:b.clamp,s=void 0===b.flip?r.flip:b.flip,t=void 0===b.brightness?r.brightness:b.brightness,u=void 0===b.contrast?r.contrast:b.contrast,v=4===l.length?0:1,w=k-j,x=o/w;for(t*=p,u*=p,e=0,h=a.length;h>e;e++)d=a[e],f=4*e,i=c(d,j,k,x,q,s,o),0>i?(g=f*v,m[f]=u*l[g]+t,m[f+1]=u*l[g+1]+t,m[f+2]=u*l[g+2]+t,m[f+3]=p*l[g+3]):(m[f]=u*n[i]+t,m[f+1]=u*n[i+1]+t,m[f+2]=u*n[i+2]+t,m[f+3]=p*n[i+3]);return m},colorFromValue:function(a,b){b=b||{};var d,e=b.hex||!1,f=void 0===b.min?0:b.min,g=void 0===b.max?255:b.max,h=void 0===b.scale?r.scale:b.scale,i=void 0===b.brightness?r.brightness:b.brightness,j=void 0===b.contrast?r.contrast:b.contrast,k=g-f,l=r.colors.length/4,m=l/k,n=c(a,f,g,m,r.clamp,r.flip,l);return d=n>=0?Array.prototype.slice.call(r.colors,n,n+4):[0,0,0,1],d[0]=Math.max(0,Math.min(j*d[0]+i,1)),d[1]=Math.max(0,Math.min(j*d[1]+i,1)),d[2]=Math.max(0,Math.min(j*d[2]+i,1)),e?(d[0]=Math.floor(255*d[0]),d[1]=Math.floor(255*d[1]),d[2]=Math.floor(255*d[2]),d[3]=Math.floor(255*d[3]),d[0]=("0"+d[0].toString(16)).slice(-2),d[1]=("0"+d[1].toString(16)).slice(-2),d[2]=("0"+d[2].toString(16)).slice(-2),d=d.slice(0,3).join("")):(d[0]=d[0]*h,d[1]=d[1]*h,d[2]=d[2]*h,d[3]=d[3]*h),d},createElement:function(a,b){var c,e,f=r.colors,g=b-a;return c=d(f,20,40,n),e=c.getContext("2d"),e.fillStyle="#FFA000",e.fillRect(.5,20,1,10),e.fillText(a.toPrecision(3),.5,40),e.fillRect(c.width/4,20,1,10),e.fillText((a+.25*g).toPrecision(3),.25*c.width,40),e.fillRect(c.width/2,20,1,10),e.fillText((a+.5*g).toPrecision(3),.5*c.width,40),e.fillRect(3*c.width/4,20,1,10),e.fillText((a+.75*g).toPrecision(3),.75*c.width,40),e.fillRect(c.width-.5,20,1,10),e.fillText(b.toPrecision(3),c.width-20,40),c}};return r}}(),function(){"use strict";var a=BrainBrowser.createTreeStore();BrainBrowser.config={set:function(b,c){b=b||"";var d=b.split(".");d.push(c),a.set.apply(a,d)},get:function(b){b=b||"";var c=b.split(".");return a.get.apply(a,c)}}}(),function(){"use strict";function a(a,b){try{a.call(b.target,b)}catch(c){console.error("Error in event handler for: ",b.name),console.error(c.stack||c.message||c)}}var b=["eventmodelcleanup"];BrainBrowser.events={unpropagatedEvent:function(a){b.push(a)},addEventModel:function(c){var d=[],e={};c.addEventListener=function(a,b){d[a]||(d[a]=[]),d[a].push(b)},c.triggerEvent=function(e,f){var g=this,h=c.directPropagationTargets(e);f=f||{},f.name=e,f.target=g,d[e]&&d[e].forEach(function(b){a(b,f)}),d["*"]&&d["*"].forEach(function(b){a(b,f)}),-1===b.indexOf(e)&&(h.forEach(function(a){a.triggerEvent.call(g,e,f)}),0===h.length&&c!==BrainBrowser.events&&BrainBrowser.events.triggerEvent.call(g,e,f))},c.propagateEventTo=function(a,b){if(!BrainBrowser.utils.isFunction(b.allPropagationTargets))throw new Error("Propagation target doesn't seem to have an event model.");if(c===BrainBrowser.events||-1!==b.allPropagationTargets(a).indexOf(c))throw new Error("Propagating event '"+a+"' would cause a cycle.");e[a]=e[a]||[],-1===c.directPropagationTargets().indexOf(b)&&b.addEventListener("eventmodelcleanup",function(){this===b&&c.stopPropagatingTo(b)}),-1===e[a].indexOf(b)&&e[a].push(b)},c.propagateEventFrom=function(a,b){b.propagateEventTo(a,c)},c.stopPropagatingTo=function(a){Object.keys(e).forEach(function(b){e[b]=e[b].filter(function(b){return b!==a})})},c.directPropagationTargets=function(a){var b=[],c=void 0===a?Object.keys(e):[a,"*"];return c.forEach(function(a){var c=e[a]||[];c.forEach(function(a){-1===b.indexOf(a)&&b.push(a)})}),b},c.allPropagationTargets=function(a){var b=c.directPropagationTargets(a),d=Array.prototype.slice.call(b);return b.forEach(function(b){b.allPropagationTargets(a).forEach(function(a){-1===d.indexOf(a)&&d.push(a)})}),d}}},BrainBrowser.events.addEventModel(BrainBrowser.events)}(),function(){"use strict";var a=BrainBrowser.loader={loadFromURL:function(b,c,d){d=d||{};var e,f=new XMLHttpRequest,g=d.result_type,h=b.split("/"),i=h[h.length-1];f.open("GET",b),"arraybuffer"===g&&(f.responseType="arraybuffer"),f.onreadystatechange=function(){if(4===f.readyState){if(e=f.status,!(e>=200&&300>e||304===e)){var g="error loading URL: "+b+"\nHTTP Response: "+f.status+"\nHTTP Status: "+f.statusText+"\nResponse was: \n"+f.response;throw BrainBrowser.events.triggerEvent("error",{message:g}),new Error(g)}a.checkCancel(d)||c(f.response,i,d)}},f.send()},loadFromFile:function(a,b,c){var d=a.files;if(0!==d.length){c=c||{};var e=c.result_type,f=new FileReader,g=a.value.split("\\"),h=g[g.length-1];f.file=d[0],f.onloadend=function(a){b(a.target.result,h,c)},f.onerror=function(){var a="error reading file: "+h;throw BrainBrowser.events.triggerEvent("error",{message:a}),new Error(a)},"arraybuffer"===e?f.readAsArrayBuffer(d[0]):f.readAsText(d[0])}},loadColorMapFromURL:function(b,c,d){a.loadFromURL(b,function(a,b,d){c(BrainBrowser.createColorMap(a,d),b,d)},d)},loadColorMapFromFile:function(b,c,d){a.loadFromFile(b,function(a,b,d){c(BrainBrowser.createColorMap(a,d),b,d)},d)},checkCancel:function(a){a=a||{},BrainBrowser.utils.isFunction(a)&&(a={test:a});var b=a.test,c=a.cleanup,d=!1;return b&&b()&&(d=!0,c&&c()),d}}}(),function(){"use strict";BrainBrowser.utils={canvasEnabled:function(){return!!document.createElement("canvas")},webglEnabled:function(){var a=document.createElement("canvas");try{return!(!a||!window.WebGLRenderingContext||!a.getContext("webgl")&&!a.getContext("experimental-webgl"))}catch(b){return!1}},webWorkersEnabled:function(){return!!window.Worker},webGLErrorMessage:function(){var a,b='BrainBrowser requires WebGL.
';return b+=window.WebGLRenderingContext?"Your browser seems to support it, but it is
disabled or unavailable.
":"Your browser does not seem to support it.
",b+='Test your browser\'s WebGL support here.',a=document.createElement("div"),a.id="webgl-error",a.innerHTML=b,a},isFunction:function(a){return a instanceof Function||"function"==typeof a},isNumeric:function(a){return!isNaN(parseFloat(a))},createDataURL:function(a,b){if(!window.URL||!window.URL.createObjectURL)throw new Error("createDataURL requires URL.createObjectURL which does not seem to be available is this browser.");return window.URL.createObjectURL(new Blob([a],{type:b||"text/plain"}))},min:function(){var a=Array.prototype.slice.call(arguments);a=1===a.length&&BrainBrowser.utils.isNumeric(a[0].length)?a[0]:a;var b,c,d=a[0];for(b=1,c=a.length;c>b;b++)a[b]b;b++)a[b]>d&&(d=a[b]);return d},getOffset:function(a){for(var b=0,c=0;a.offsetParent;)b+=a.offsetTop,c+=a.offsetLeft,a=a.offsetParent;return{top:b,left:c}},captureMouse:function(a){var b={x:0,y:0,left:!1,middle:!1,right:!1};return document.addEventListener("mousemove",function(c){var d,e,f=BrainBrowser.utils.getOffset(a);void 0!==c.pageX?(d=c.pageX,e=c.pageY):(d=c.clientX+window.pageXOffset,e=c.clientY+window.pageYOffset),b.x=d-f.left,b.y=e-f.top},!1),a.addEventListener("mousedown",function(a){a.preventDefault(),0===a.button&&(b.left=!0),1===a.button&&(b.middle=!0),2===a.button&&(b.right=!0)},!1),a.addEventListener("mouseup",function(a){a.preventDefault(),0===a.button&&(b.left=!1),1===a.button&&(b.middle=!1),2===a.button&&(b.right=!1)},!1),a.addEventListener("mouseleave",function(a){a.preventDefault(),b.left=b.middle=b.right=!1},!1),a.addEventListener("contextmenu",function(a){a.preventDefault()},!1),b},captureTouch:function(a){function b(b){var d,e,f,g,h,i=BrainBrowser.utils.getOffset(a);for(c.length=g=b.touches.length,f=0;g>f;f++)h=b.touches[f],void 0!==h.pageX?(d=h.pageX,e=h.pageY):(d=h.clientX+window.pageXOffset,e=h.clientY+window.pageYOffset),c[f]=c[f]||{},c[f].x=d-i.left,c[f].y=e-i.top}var c=[];return a.addEventListener("touchstart",b,!1),a.addEventListener("touchmove",b,!1),a.addEventListener("touchend",b,!1),c}}}(),function(){"use strict";var a=BrainBrowser.VolumeViewer={};a.modules={},a.volume_loaders={},a.start=function(b,c){function d(){document.addEventListener("keydown",function(a){if(f.active_panel){var b,c,d,e=f.active_panel,g=e.volume,h=e.axis,i=a.which,j={17:function(){e.anchor||(e.mouse.left||e.mouse.middle||e.mouse.right)&&(e.anchor={x:e.mouse.x,y:e.mouse.y})},37:function(){b=e.slice.width_space.name,g.position[b]>0&&g.position[b]--},38:function(){b=e.slice.height_space.name,g.position[b]0&&g.position[b]--}};return"function"==typeof j[i]?(a.preventDefault(),j[i](),e.updated=!0,g.display.forEach(function(a){e!==a&&a.updateSlice()}),f.synced&&(d=e.getCursorPosition(),f.volumes.forEach(function(a){var b;a!==g&&(b=a.display.getPanel(h),b.updateVolumePosition(d.x,d.y),a.display.forEach(function(a){a!==b&&a.updateSlice()}))})),!1):32===i&&(a.preventDefault(),g.data.time)?(c=a.shiftKey?Math.max(0,g.current_time-1):Math.min(g.current_time+1,g.data.time.space_length-1),g.current_time=c,f.synced&&f.volumes.forEach(function(a){a!==g&&(a.current_time=Math.max(0,Math.min(c,a.data.time.space_length-1)))}),f.redrawVolumes(),!1):void 0}},!1),document.addEventListener("keyup",function(a){var b=a.which,c={17:function(){f.volumes.forEach(function(a){a.display.forEach(function(a){a.anchor=null})})}};return"function"==typeof c[b]?(a.preventDefault(),c[b](),!1):void 0},!1)}var e;e="string"==typeof b?document.getElementById(b):b;var f={dom_element:e,volumes:[],synced:!1};return Object.keys(a.modules).forEach(function(b){a.modules[b](f)}),BrainBrowser.events.addEventModel(f),console.log("BrainBrowser Volume Viewer v"+BrainBrowser.version),d(),c(f),f}}(),function(){"use strict";BrainBrowser.VolumeViewer.createDisplay=function(){var a={},b={setPanel:function(c,d){a[c]&&a[c].triggerEvent("eventmodelcleanup"),d.propagateEventTo("*",b),a[c]=d},getPanel:function(b){return a[b]},refreshPanels:function(){b.forEach(function(a){a.updateSlice()})},setContrast:function(a){b.forEach(function(b){b.contrast=a})},setBrightness:function(a){b.forEach(function(b){b.brightness=a})},forEach:function(b){Object.keys(a).forEach(function(c,d){b(a[c],c,d)})}};return BrainBrowser.events.addEventModel(b),b.addEventListener("eventmodelcleanup",function(){b.forEach(function(a){a.triggerEvent("eventmodelcleanup")})}),b}}(),function(){"use strict";function a(a,b){a.slice=b,a.slice_image=a.slice.getImage(a.zoom,a.contrast,a.brightness)}function b(a,b){var c,d,e,f,g,h,i=a.context,j=a.getCursorPosition(),k=a.zoom,l=8*k;b=b||"#FF0000",i.save(),i.strokeStyle=b,i.fillStyle=b,e=k,c=j.x,d=j.y,i.lineWidth=2*e,i.beginPath(),i.moveTo(c,d-l),i.lineTo(c,d-e),i.moveTo(c,d+e),i.lineTo(c,d+l),i.moveTo(c-l,d),i.lineTo(c-e,d),i.moveTo(c+e,d),i.lineTo(c+l,d),i.stroke(),a.anchor&&(g=(a.anchor.x-j.x)/a.zoom,h=(a.anchor.y-j.y)/a.zoom,f=Math.sqrt(g*g+h*h),i.font="bold 12px arial",a.canvas.width-j.x<50?(i.textAlign="right",c=j.x-l):(i.textAlign="left",c=j.x+l),j.y<30?(i.textBaseline="top",d=j.y+l):(i.textBaseline="bottom",d=j.y-l),i.fillText(f.toFixed(2),c,d),i.lineWidth=1,i.beginPath(),i.arc(a.anchor.x,a.anchor.y,2*e,0,2*Math.PI),i.fill(),i.moveTo(a.anchor.x,a.anchor.y),i.lineTo(j.x,j.y),i.stroke()),i.restore()}function c(a){var b,c=a.slice_image;c&&(b={x:a.image_center.x-a.slice_image.width/2,y:a.image_center.y-a.slice_image.height/2},a.context.putImageData(c,b.x,b.y))}function d(a){var b=a.slice;return{x:a.image_center.x-Math.abs(b.width_space.step*b.width_space.space_length*a.zoom)/2,y:a.image_center.y-Math.abs(b.height_space.step*b.height_space.space_length*a.zoom)/2}}BrainBrowser.VolumeViewer.createPanel=function(e){e=e||{};var f=0,g={x:0,y:0},h={x:0,y:0},i=null,j={image_center:{x:0,y:0},zoom:1,contrast:1,brightness:0,updated:!0,setSize:function(a,b,c){c=c||{},a=a>0?a:0,b=b>0?b:0;var d,e,f,g=c.scale_image;g&&(d=j.canvas.width,e=j.canvas.width,f=Math.min(a/d,b/e)),j.canvas.width=a,j.canvas.height=b,g&&(j.zoom=j.zoom*f,j.image_center.x=a/2,j.image_center.y=b/2,j.updateVolumePosition(),j.updateSlice()),j.updated=!0},followPointer:function(a){var b=a.x-h.x,c=a.y-h.y,d=j.getCursorPosition();j.image_center.x+=b,j.image_center.y+=c,d.x+=b,d.y+=c,h.x=a.x,h.y=a.y,j.updated=!0},reset:function(){j.zoom=1,j.image_center.x=j.canvas.width/2,j.image_center.y=j.canvas.height/2},getCursorPosition:function(){var a=j.volume,b=j.slice,c=d(j);return{x:a.position[b.width_space.name]*Math.abs(b.width_space.step)*j.zoom+c.x,y:(b.height_space.space_length-a.position[b.height_space.name]-1)*Math.abs(b.height_space.step)*j.zoom+c.y}},updateVolumePosition:function(a,b){var c,e,f,g=d(j),h=j.zoom,i=j.volume,k=j.slice;(void 0===a||void 0===b)&&(c=j.getCursorPosition(),a=c.x,b=c.y),e=Math.round((a-g.x)/h/Math.abs(k.width_space.step)),f=Math.round(k.height_space.space_length-(b-g.y)/h/Math.abs(k.height_space.step)-1),i.position[j.slice.width_space.name]=e,i.position[j.slice.height_space.name]=f,j.updated=!0},updateSlice:function(b){clearTimeout(i),i=setTimeout(function(){var c,d=j.volume;c=d.slice(j.axis),c.min=d.min,c.max=d.max,a(j,c),j.triggerEvent("sliceupdate",{volume:d,slice:c}),j.updated=!0,BrainBrowser.utils.isFunction(b)&&b(c)},0)},draw:function(a,d){var e=j.getCursorPosition();if((g.x!==e.x||g.y!==e.y)&&(g.x=e.x,g.y=e.y,j.updated=!0,j.triggerEvent("cursorupdate",{volume:j.volume,cursor:e})),f!==j.zoom&&(f=j.zoom,j.updated=!0,j.triggerEvent("zoom",{volume:j.volume,zoom:j.zoom})),j.touches[0]?(h.x=j.touches[0].x,h.y=j.touches[0].y):(h.x=j.mouse.x,h.y=j.mouse.y),j.updated){var i=j.canvas,k=j.context,l=4,m=l/2;k.globalAlpha=255,k.clearRect(0,0,i.width,i.height),c(j),j.triggerEvent("draw",{volume:j.volume,cursor:e,canvas:i,context:k}),b(j,a),d&&(k.save(),k.strokeStyle="#EC2121",k.lineWidth=l,k.strokeRect(m,m,i.width-l,i.height-l),k.restore()),j.updated=!1}}};return Object.keys(e).forEach(function(a){BrainBrowser.utils.isFunction(j[a])||(j[a]=e[a])}),BrainBrowser.events.addEventModel(j),j.canvas&&BrainBrowser.utils.isFunction(j.canvas.getContext)&&(j.context=j.canvas.getContext("2d"),j.mouse=BrainBrowser.utils.captureMouse(j.canvas),j.touches=BrainBrowser.utils.captureTouch(j.canvas)),j.volume&&a(j,j.volume.slice(j.axis)),j}}(),function(){"use strict";BrainBrowser.VolumeViewer.utils={nearestNeighbor:function(a,b,c,d,e,f){f=f||{};var g,h,i,j,k,l,m,n,o,p,q=f.block_size||1,r=f.array_type||Uint8ClampedArray;if(b===d&&c===e)return a;for(k=new r(d*e*q),g=b/d,h=c/e,m=0;e>m;m++)for(i=Math.floor(m*h)*b,n=m*d,l=0;d>l;l++)for(j=(i+Math.floor(l*g))*q,o=(n+l)*q,p=0;q>p;p++)k[o+p]=a[j+p];return k},flipArray:function(a,b,c,d){d=d||{};var e,f,g,h,i,j,k,l,m,n=d.flipx||!1,o=d.flipy||!1,p=d.block_size||1,q=new a.constructor(a.length);if(!n&&!o){for(e=0,f=a.length;f>e;e++)q[e]=a[e];return q}for(f=0;c>f;f++)for(j=f*b,i=o?c-f-1:f,l=i*b,e=0;b>e;e++)for(k=(j+e)*p,h=n?b-e-1:e,m=(l+h)*p,g=0;p>g;g++)q[k+g]=a[m+g];return q}}}(),BrainBrowser.VolumeViewer.modules.loading=function(a){"use strict";function b(a,b){var c,d=h.volume_loaders[a.type];if(!d)throw c="Unsuported Volume Type",BrainBrowser.events.triggerEvent("error",{message:c}),new Error(c);d(a,b)}function c(c,d,e){b(d,function(b){var f=0,h=d.views||["xspace","yspace","zspace"];BrainBrowser.events.addEventModel(b),b.addEventListener("eventmodelcleanup",function(){b.display.triggerEvent("eventmodelcleanup")}),a.volumes[c]=b,b.color_map=i,b.display=g(a.dom_element,c,d),b.propagateEventTo("*",a),["xspace","yspace","zspace"].forEach(function(a){b.position[a]=Math.floor(b.header[a].space_length/2)}),b.display.forEach(function(c){c.updateSlice(function(){++f===h.length&&(a.triggerEvent("volumeloaded",{volume:b}),BrainBrowser.utils.isFunction(e)&&e(b))})})})}function d(b,c,d){b.cursor_color=c,i=b,a.volumes.forEach(function(a){a.color_map=a.color_map||i}),BrainBrowser.utils.isFunction(d)&&d(b)}function e(b,c,d,e){c.cursor_color=d,a.setVolumeColorMap(b,c),BrainBrowser.utils.isFunction(e)&&e(a.volumes[b],c)}function f(a,b,c,d){var e=document.getElementById(c).innerHTML.replace(/\{\{VOLID\}\}/gm,b),f=document.createElement("div");f.innerHTML=e;var g,h,i,j=f.childNodes,k=f.getElementsByClassName(d)[0];for(g=0,h=a.childNodes.length;h>g;g++)i=a.childNodes[g],1===i.nodeType&&(k.appendChild(i),g--,h--);return j}function g(b,c,d){var e,g=document.createElement("div"),i=a.volumes[c],l=h.createDisplay(),m=d.template||{},n=d.views||["xspace","yspace","zspace"];return l.propagateEventTo("*",i),g.classList.add("volume-container"),n.forEach(function(a){var b=document.createElement("canvas");b.width=j,b.height=k,b.classList.add("slice-display"),b.style.backgroundColor="#000000",g.appendChild(b),l.setPanel(a,h.createPanel({volume:i,volume_id:c,axis:a,canvas:b,image_center:{x:b.width/2,y:b.height/2}}))}),m.element_id&&m.viewer_insert_class&&(e=f(g,c,m.element_id,m.viewer_insert_class),"function"==typeof m.complete&&m.complete(i,e),Array.prototype.forEach.call(e,function(a){1===a.nodeType&&g.appendChild(a)})),function(){var b=null;n.forEach(function(d){function e(b,e,f){f&&(a.volumes.forEach(function(a){a.display.forEach(function(a){a.anchor=null})}),r.anchor={x:b.x,y:b.y}),e||(r.updateVolumePosition(b.x,b.y),i.display.forEach(function(a){r!==a&&a.updateSlice()}),a.synced&&a.volumes.forEach(function(a,e){var f;e!==c&&(f=a.display.getPanel(d),f.updateVolumePosition(b.x,b.y),a.display.forEach(function(a){a!==f&&a.updateSlice()}))})),r.updated=!0}function f(b,e){e?(r.followPointer(b),a.synced&&a.volumes.forEach(function(a,e){var f;e!==c&&(f=a.display.getPanel(d),f.followPointer(b))})):(r.updateVolumePosition(b.x,b.y),i.display.forEach(function(a){r!==a&&a.updateSlice()}),a.synced&&a.volumes.forEach(function(a,e){var f;e!==c&&(f=a.display.getPanel(d),f.updateVolumePosition(b.x,b.y),a.display.forEach(function(a){a!==f&&a.updateSlice()}))})),r.updated=!0}function g(a){a.target===b&&(a.preventDefault(),f(r.mouse,a.shiftKey))}function h(a){a.target===b&&(a.preventDefault(),f(r.touches[0],r.touches.length===n.length))}function j(){document.removeEventListener("mousemove",g,!1),document.removeEventListener("mouseup",j,!1),a.volumes.forEach(function(a){a.display.forEach(function(a){a.anchor=null})}),b=null}function k(){document.removeEventListener("touchmove",h,!1),document.removeEventListener("touchend",k,!1),a.volumes.forEach(function(a){a.display.forEach(function(a){a.anchor=null})}),b=null}function m(){var a,b=r.touches[0].x-r.touches[1].x,c=r.touches[0].y-r.touches[1].y,d=Math.sqrt(b*b+c*c);null!==t&&(a=d-t,q(.2*a)),t=d}function o(){document.removeEventListener("touchmove",m,!1),document.removeEventListener("touchend",o,!1),t=null}function p(a){q(Math.max(-1,Math.min(1,a.wheelDelta||-a.detail)))}function q(b){event.preventDefault(),r.zoom=Math.max(r.zoom+.05*b,.05),r.updateVolumePosition(),r.updateSlice(),a.synced&&a.volumes.forEach(function(a,b){var e=a.display.getPanel(d);b!==c&&(e.zoom=r.zoom,e.updateVolumePosition(),e.updateSlice())})}var r=l.getPanel(d),s=r.canvas,t=null;s.addEventListener("mousedown",function(c){c.preventDefault(),b=c.target,a.active_panel&&(a.active_panel.updated=!0),a.active_panel=r,document.addEventListener("mousemove",g,!1),document.addEventListener("mouseup",j,!1),e(r.mouse,c.shiftKey,c.ctrlKey)},!1),s.addEventListener("touchstart",function(c){c.preventDefault(),b=c.target,a.active_panel&&(a.active_panel.updated=!0),a.active_panel=r,2===r.touches.length?(document.removeEventListener("touchmove",h,!1),document.removeEventListener("touchend",k,!1),document.addEventListener("touchmove",m,!1),document.addEventListener("touchend",o,!1)):(document.removeEventListener("touchmove",m,!1),document.removeEventListener("touchend",o,!1),document.addEventListener("touchmove",h,!1),document.addEventListener("touchend",k,!1),e(r.touches[0],3===r.touches.length,!0))},!1),s.addEventListener("mousewheel",p,!1),s.addEventListener("DOMMouseScroll",p,!1)})}(),b.appendChild(g),a.triggerEvent("volumeuiloaded",{container:g,volume:i,volume_id:c}),l}var h=BrainBrowser.VolumeViewer,i=null,j=256,k=256;a.loadVolumes=function(b){function d(d){c(d,g[d],function(){++j1?a.createOverlay(f,function(){BrainBrowser.utils.isFunction(i)&&i(),a.triggerEvent("volumesloaded")}):(BrainBrowser.utils.isFunction(i)&&i(),a.triggerEvent("volumesloaded")))})}b=b||{};var e,f=b.overlay&&"object"==typeof b.overlay?b.overlay:{},g=b.volumes,h=b.volumes.length,i=b.complete,j=0;for(e=0;h>e;e++)d(e)},a.loadVolumeColorMapFromURL=function(a,b,c,d){BrainBrowser.loader.loadColorMapFromURL(b,function(b){e(a,b,c,d)},{scale:255})},a.loadDefaultColorMapFromURL=function(a,b,c){BrainBrowser.loader.loadColorMapFromURL(a,function(a){d(a,b,c)},{scale:255})},a.loadVolumeColorMapFromFile=function(a,b,c,d){BrainBrowser.loader.loadColorMapFromFile(b,function(b){e(a,b,c,d)},{scale:255})},a.loadDefaultColorMapFromFile=function(a,b,c){BrainBrowser.loader.loadColorMapFromFile(a,function(a){d(a,b,c)},{scale:255})},a.setVolumeColorMap=function(b,c){a.volumes[b].color_map=c},a.loadVolume=function(b,d){c(a.volumes.length,b,d)},a.clearVolumes=function(){a.volumes.forEach(function(a){a.triggerEvent("eventmodelcleanup")}),a.volumes=[],a.active_panel=null,a.dom_element.innerHTML=""},a.createOverlay=function(b,c){b=b||{},a.loadVolume({volumes:a.volumes,type:"overlay",template:b.template},c)},a.setDefaultPanelSize=function(a,b){j=a,k=b}},BrainBrowser.VolumeViewer.modules.rendering=function(a){"use strict";a.draw=function(){a.volumes.forEach(function(b){b.display.forEach(function(c){c.draw(b.color_map.cursor_color,a.active_panel===c)})})},a.render=function(){a.triggerEvent("rendering"),function b(){window.requestAnimationFrame(b),a.draw()}()},a.redrawVolume=function(b){var c=a.volumes[b];c.display.forEach(function(a){a.updateSlice()})},a.redrawVolumes=function(){a.volumes.forEach(function(b,c){a.redrawVolume(c)})},a.resetDisplays=function(){a.volumes.forEach(function(a){a.display.forEach(function(a){a.reset()})})},a.setPanelSize=function(b,c,d){a.volumes.forEach(function(a){a.display.forEach(function(a){a.setSize(b,c,d)})})}},function(){"use strict";function a(a,b){var c,d;try{c=JSON.parse(a)}catch(e){throw d="server did not respond with valid JSON\nResponse was: \n"+a,BrainBrowser.events.triggerEvent("error",{message:d}),new Error(d)}BrainBrowser.utils.isFunction(b)&&b(c)}function b(a,b,f){var g=c(a,new Uint8Array(b)),h={position:{},current_time:0,data:g,header:g.header,min:0,max:255,slice:function(a,b,c){b=void 0===b?h.position[a]:b,c=void 0===c?h.current_time:c;var f=h.data.slice(a,b,c);return f.color_map=h.color_map,f.min=h.min,f.max=h.max,f.axis=a,f.getImage=function(a,b,c){a=a||1;var g,i=f.color_map;if(!i)throw g="No color map set for this volume. Cannot render slice.",h.triggerEvent("error",g),new Error(g);var j=f.width_space.step,k=f.height_space.step,l=Math.abs(Math.floor(f.width*j*a)),m=Math.abs(Math.floor(f.height*k*a)),n=e.createImageData(f.width,f.height),o=e.createImageData(l,m);return i.mapColors(f.data,{min:f.min,max:f.max,contrast:b,brightness:c,destination:n.data}),o.data.set(d.utils.nearestNeighbor(n.data,n.width,n.height,l,m,{block_size:4})),o},f},getIntensityValue:function(a,b,c,d){if(a=void 0===a?h.position.xspace:a,b=void 0===b?h.position.yspace:b,c=void 0===c?h.position.zspace:c,d=void 0===d?h.current_time:d,0>a||a>h.data.xspace.space_length||0>b||b>h.data.yspace.space_length||0>c||c>h.data.zspace.space_length)return 0;var e=h.data.slice("zspace",c,d);return e.data[(e.height_space.space_length-b-1)*e.width+a]},getVoxelCoords:function(){var a=h.data,b={xspace:a.xspace.step>0?h.position.xspace:a.xspace.space_length-h.position.xspace,yspace:a.yspace.step>0?h.position.yspace:a.yspace.space_length-h.position.yspace,zspace:a.zspace.step>0?h.position.zspace:a.zspace.space_length-h.position.zspace};return{i:b[a.order[0]],j:b[a.order[1]],k:b[a.order[2]]}},setVoxelCoords:function(a,b,c){var d=h.data,e=d.order[0],f=d.order[1],g=d.order[2];h.position[e]=d[e].step>0?a:d[e].space_length-a,h.position[f]=d[f].step>0?b:d[f].space_length-b,h.position[g]=d[g].step>0?c:d[g].space_length-c},getWorldCoords:function(){var a=h.getVoxelCoords();return h.voxelToWorld(a.i,a.j,a.k)},setWorldCoords:function(a,b,c){var d=h.worldToVoxel(a,b,c);h.setVoxelCoords(d.i,d.j,d.k)},voxelToWorld:function(a,b,c){var d,e,f,g={};g[h.data.order[0]]=a,g[h.data.order[1]]=b,g[h.data.order[2]]=c,d=g.xspace,e=g.yspace,f=g.zspace;var i=h.data.xspace.direction_cosines,j=h.data.yspace.direction_cosines,k=h.data.zspace.direction_cosines,l=h.data.xspace.step,m=h.data.yspace.step,n=h.data.zspace.step,o=h.data.voxel_origin;return{x:d*i[0]*l+e*j[0]*m+f*k[0]*n+o.x,y:d*i[1]*l+e*j[1]*m+f*k[1]*n+o.y,z:d*i[2]*l+e*j[2]*m+f*k[2]*n+o.z}},worldToVoxel:function(a,b,c){var d=h.data.xspace.direction_cosines,e=h.data.yspace.direction_cosines,f=h.data.zspace.direction_cosines,g=h.data.xspace.step,i=h.data.yspace.step,j=h.data.zspace.step,k=h.data.voxel_origin,l=(-k.x*d[0]-k.y*d[1]-k.z*d[2])/g,m=(-k.x*e[0]-k.y*e[1]-k.z*e[2])/i,n=(-k.x*f[0]-k.y*f[1]-k.z*f[2])/j,o={x:Math.round(a*d[0]/g+b*d[1]/g+c*d[2]/g+l),y:Math.round(a*e[0]/i+b*e[1]/i+c*e[2]/i+m),z:Math.round(a*f[0]/j+b*f[1]/j+c*f[2]/j+n)},p={};return p[h.data.order[0]]=o.x,p[h.data.order[1]]=o.y,p[h.data.order[2]]=o.z,{i:p.xspace,j:p.yspace,k:p.zspace}}};BrainBrowser.utils.isFunction(f)&&f(h)}function c(a,b){var c,d,e,f,g,h,i={data:b,cached_slices:{}};return i.header=a,i.order=a.order,4===a.order.length&&(i.order=i.order.slice(1),i.time=a.time),i.xspace=a.xspace,i.yspace=a.yspace,i.zspace=a.zspace,i.xspace.name="xspace",i.yspace.name="yspace",i.zspace.name="zspace",i.xspace.space_length=parseFloat(i.xspace.space_length),i.yspace.space_length=parseFloat(i.yspace.space_length),i.zspace.space_length=parseFloat(i.zspace.space_length),c=i.xspace.start=parseFloat(i.xspace.start),d=i.yspace.start=parseFloat(i.yspace.start),e=i.zspace.start=parseFloat(i.zspace.start),i.xspace.step=parseFloat(i.xspace.step),i.yspace.step=parseFloat(i.yspace.step),i.zspace.step=parseFloat(i.zspace.step),i.xspace.direction_cosines=i.xspace.direction_cosines||[1,0,0],i.yspace.direction_cosines=i.yspace.direction_cosines||[0,1,0],i.zspace.direction_cosines=i.zspace.direction_cosines||[0,0,1],f=i.xspace.direction_cosines=i.xspace.direction_cosines.map(parseFloat),g=i.yspace.direction_cosines=i.yspace.direction_cosines.map(parseFloat),h=i.zspace.direction_cosines=i.zspace.direction_cosines.map(parseFloat),i.voxel_origin={x:c*f[0]+d*g[0]+e*h[0],y:c*f[1]+d*g[1]+e*h[1],z:c*f[2]+d*g[2]+e*h[2]},i.xspace.width_space=i.yspace,i.xspace.width=i.yspace.space_length,i.xspace.height_space=i.zspace,i.xspace.height=i.zspace.space_length,i.yspace.width_space=i.xspace,i.yspace.width=i.xspace.space_length,i.yspace.height_space=i.zspace,i.yspace.height=i.zspace.space_length,i.zspace.width_space=i.xspace,i.zspace.width=i.xspace.space_length,i.zspace.height_space=i.yspace,i.zspace.height=i.yspace.space_length,i[i.order[0]].offset=i[i.order[1]].space_length*i[i.order[2]].space_length,i[i.order[1]].offset=i[i.order[2]].space_length,i[i.order[2]].offset=1,i.time&&(i.time.space_length=parseFloat(i.time.space_length),i.time.start=parseFloat(i.time.start),i.time.step=parseFloat(i.time.step),i.time.offset=i.xspace.space_length*i.yspace.space_length*i.zspace.space_length),i.slice=function(a,b,c){if(void 0===i.order)return null;c=c||0;var d=i.cached_slices;if(d[a]=d[a]||[],d[a][c]=d[a][c]||[],void 0!==d[a][c][b])return d[a][c][b];var e,f,g,h,j,k,l,m,n,o=i.time?c*i.time.offset:0,p=i[a],q=p.width_space,r=p.height_space,s=p.width,t=p.height,u=p.offset,v=q.offset,w=r.offset,x=new Uint8Array(s*t),y=q.step>0,z=r.step>0,A=p.step>0,B=0;for(k=A?b:p.space_length-b-1,l=o+k*u,f=t-1;f>=0;f--)for(j=z?f:t-f-1,m=l+j*w,g=0;s>g;g++)h=y?g:s-g-1,n=m+h*v,x[B++]=i.data[n];return e={data:x,width_space:q,height_space:r,width:s,height:t},d[a][c][b]=e,e},i}var d=BrainBrowser.VolumeViewer,e=document.createElement("canvas").getContext("2d");d.volume_loaders.minc=function(c,d){var e;if(c.header_url&&c.raw_data_url)BrainBrowser.loader.loadFromURL(c.header_url,function(e){a(e,function(a){BrainBrowser.loader.loadFromURL(c.raw_data_url,function(c){b(a,c,d)},{result_type:"arraybuffer"})})});else{if(!c.header_file||!c.raw_data_file)throw e="invalid volume description.\nDescription must contain property pair 'header_url' and 'raw_data_url', or\n'header_file' and 'raw_data_file'.",BrainBrowser.events.triggerEvent("error",{message:e}),new Error(e);BrainBrowser.loader.loadFromFile(c.header_file,function(e){a(e,function(a){BrainBrowser.loader.loadFromFile(c.raw_data_file,function(c){b(a,c,d)},{result_type:"arraybuffer"})})})}}}(),function(){"use strict";function a(a,b,c){var d=a.length;if(1===d)return a[0];var e,f,g,h,i,j,k,l,m,n=c.data,o=c.width,p=c.height,q=new Uint32Array(a.length),r=new Float32Array(b);for(e=0;p>e;e+=1)for(m=e*o,f=0;o>f;f+=1)for(j=4*(m+f),k=0,g=0;d>g;g+=1)h=a[g],em&&n>0&&q.data.set(b.utils.flipImage(q.data,q.width,q.height,{flipx:!0,flipy:!1,block_size:4})),r.data.set(b.utils.nearestNeighbor(q.data,q.width,q.height,o,p,{block_size:4})),j=Math.max(j,o),k=Math.max(k,p),i.push(r)}),a(i,g.blend_ratios,c.createImageData(j,k))}}},getIntensityValue:function(a,b,c,d){a=void 0===a?this.position.xspace:a,b=void 0===b?this.position.yspace:b,c=void 0===c?this.position.zspace:c,d=void 0===d?this.current_time:d;var e=this,f=[];return e.volumes.forEach(function(e){(0>a||a>e.data.xspace.space_length||0>b||b>e.data.yspace.space_length||0>c||c>e.data.zspace.space_length)&&f.push(0);var g,h,i=e.data.slice("zspace",c,d),j=i.data;"xspace"===i.width_space.name?(g=a,h=b):(g=b,h=c),f.push(j[(i.height_space.space_length-h-1)*i.width+g])}),f.reduce(function(a,b,c){return a+b*e.blend_ratios[c]},0)}};f.forEach(function(a){g.volumes.push(a),g.blend_ratios.push(1/f.length)}),BrainBrowser.utils.isFunction(e)&&e(g)}}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/deindex.worker.js b/build/brainbrowser-2.2.0/workers/deindex.worker.js
new file mode 100644
index 00000000..2b024312
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/deindex.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a,c,d,e){a=a||[],c=c||[],d=d||[],e=e;var f,g,h,i,j,k,l,m,n,o,p=a.length,q=3*p,r=4*p,s=d.length>0,t={},u={};4===e.length&&(j=!0,f=e[0],g=e[1],h=e[2],i=e[3]);var v=new Float32Array(q),w=s?new Float32Array(q):new Float32Array,x=new Float32Array(r);for(k=0,l=a.length;l>k;k++)b(t,c[3*a[k]],c[3*a[k]+1],c[3*a[k]+2]);for(u.x=t.minX+(t.maxX-t.minX)/2,u.y=t.minY+(t.maxY-t.minY)/2,u.z=t.minZ+(t.maxZ-t.minZ)/2,u.bounding_box=t,k=0;p>k;k+=3)m=3*k,n=4*k,v[m]=c[3*a[k]]-u.x,v[m+1]=c[3*a[k]+1]-u.y,v[m+2]=c[3*a[k]+2]-u.z,v[m+3]=c[3*a[k+1]]-u.x,v[m+4]=c[3*a[k+1]+1]-u.y,v[m+5]=c[3*a[k+1]+2]-u.z,v[m+6]=c[3*a[k+2]]-u.x,v[m+7]=c[3*a[k+2]+1]-u.y,v[m+8]=c[3*a[k+2]+2]-u.z,s&&(w[m]=d[3*a[k]],w[m+1]=d[3*a[k]+1],w[m+2]=d[3*a[k]+2],w[m+3]=d[3*a[k+1]],w[m+4]=d[3*a[k+1]+1],w[m+5]=d[3*a[k+1]+2],w[m+6]=d[3*a[k+2]],w[m+7]=d[3*a[k+2]+1],w[m+8]=d[3*a[k+2]+2]),j?(x[n]=f,x[n+1]=g,x[n+2]=h,x[n+3]=i,x[n+4]=f,x[n+5]=g,x[n+6]=h,x[n+7]=i,x[n+8]=f,x[n+9]=g,x[n+10]=h,x[n+11]=i):(x[n]=e[4*a[k]],x[n+1]=e[4*a[k]+1],x[n+2]=e[4*a[k]+2],x[n+3]=e[4*a[k]+3],x[n+4]=e[4*a[k+1]],x[n+5]=e[4*a[k+1]+1],x[n+6]=e[4*a[k+1]+2],x[n+7]=e[4*a[k+1]+3],x[n+8]=e[4*a[k+2]],x[n+9]=e[4*a[k+2]+1],x[n+10]=e[4*a[k+2]+2],x[n+11]=e[4*a[k+2]+3]);return o={centroid:u,unindexed:{position:v,normal:w,color:x}}}function b(a,b,c,d){(!a.minX||a.minX>b)&&(a.minX=b),(!a.maxX||a.maxXc)&&(a.minY=c),(!a.maxY||a.maxYd)&&(a.minZ=d),(!a.maxZ||a.maxZc;c++)e=h[c],f=a(h[c].indices,i,j,e.color||k),e.centroid=f.centroid,e.unindexed=f.unindexed;self.postMessage(g)})}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/freesurferasc.intensity.worker.js b/build/brainbrowser-2.2.0/workers/freesurferasc.intensity.worker.js
new file mode 100644
index 00000000..e26e8290
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/freesurferasc.intensity.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a){var b,c,d,e,f,g,h;for(a=a.trim(),c=a.split("\n"),f=c.length,b=new Float32Array(f),d=parseFloat(c[0].trim().split(/\s+/)[4]),b[0]=d,g=d,h=d,e=1;f>e;e++)d=parseFloat(c[e].trim().split(/\s+/)[4]),b[e]=d,g=Math.min(g,d),h=Math.max(h,d);return{values:b,min:g,max:h}}self.addEventListener("message",function(b){var c=b.data,d=c.data;self.postMessage(a(d))})}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/freesurferasc.worker.js b/build/brainbrowser-2.2.0/workers/freesurferasc.worker.js
new file mode 100644
index 00000000..2f4ea37b
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/freesurferasc.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a){var b,c,d,e,f,g,h,i,j={};for(a=a.split("\n"),d=a[1].trim().split(/\s+/),e=parseInt(d[0],10),f=parseInt(d[1],10),b=new Float32Array(3*e),c=new Uint32Array(3*f),h=0;e>h;h++)g=a[h+2].trim().split(/\s+/),i=3*h,b[i]=parseFloat(g[0]),b[i+1]=parseFloat(g[1]),b[i+2]=parseFloat(g[2]);for(h=0;f>h;h++)g=a[h+e+2].trim().split(/\s+/),i=3*h,c[i]=parseInt(g[0],10),c[i+1]=parseInt(g[1],10),c[i+2]=parseInt(g[2],10);return j.type="polygon",j.vertices=b,j.shapes=[{indices:c}],j}self.addEventListener("message",function(b){self.postMessage(a(b.data.data))})}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/freesurferbin.intensity.worker.js b/build/brainbrowser-2.2.0/workers/freesurferbin.intensity.worker.js
new file mode 100644
index 00000000..06fc14cb
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/freesurferbin.intensity.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a){var c,d,e,f,g,h,i=new DataView(a),j=0,k=b(i);if(j+=3,16777215!==k)return{error:!0,error_message:"Unrecognized file format."};if(d=i.getUint32(j),j+=8,e=i.getUint32(j),j+=4,1!==e)return{error:!0,error_message:"Only one value per vertex supported. Number of values: "+e};for(c=new Float32Array(d),c[0]=f=g=i.getFloat32(j),j+=4,h=1;d>h;h++)c[h]=i.getFloat32(j),f=Math.min(f,c[h]),g=Math.max(g,c[h]),j+=4;return{values:c,min:f,max:g}}function b(a){var b,c=0;for(b=0;3>b;b++)c+=a.getUint8(b)<<8*(3-b-1);return c}self.addEventListener("message",function(b){self.postMessage(a(b.data.data))})}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/freesurferbin.worker.js b/build/brainbrowser-2.2.0/workers/freesurferbin.worker.js
new file mode 100644
index 00000000..53e07625
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/freesurferbin.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a){var c,d,e,f,g,h,i=new DataView(a),j=0,k=b(i);if(j+=3,16777214!==k)return{error:!0,error_message:"Only triangle meshes supported."};for(;10!==i.getUint8(j)||10!==i.getUint8(j+1);)j++;for(j+=2,d=i.getUint32(j),j+=4,f=3*i.getUint32(j),j+=4,c=new Float32Array(3*d),e=new Uint32Array(f),g=0;d>g;g++)h=3*g,c[h]=i.getFloat32(j),j+=4,c[h+1]=i.getFloat32(j),j+=4,c[h+2]=i.getFloat32(j),j+=4;for(g=0;f>g;g++)e[g]=i.getUint32(j),j+=4;return{vertices:c,shapes:[{indices:e}]}}function b(a){var b,c=0;for(b=0;3>b;b++)c+=a.getUint8(b)<<8*(3-b-1);return c}self.addEventListener("message",function(b){self.postMessage(a(b.data.data))})}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/json.worker.js b/build/brainbrowser-2.2.0/workers/json.worker.js
new file mode 100644
index 00000000..d1219f6e
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/json.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a){var e={name:a.name,type:a.type,shapes:[]};return e.vertices=b(a.vertices),a.colors=a.colors||a.color,a.colors&&(e.colors=b(a.colors),(e.vertices.length===e.colors.length||3===e.colors.length)&&(e.colors=c(e.colors))),a.normals&&(e.normals=b(a.normals)),void 0===a.shapes&&(a.shapes=[]),a.indices&&a.shapes.push({indices:a.indices}),a.shapes.forEach(function(a){var c=b(a.indices);a.one_indexed&&d(c),a.color=a.color||a.colors,Array.isArray(a.color)&&3===a.color.length&&a.color.push(1),e.shapes.push({name:a.name,indices:c,color:a.color})}),e}function b(a,c){if(!Array.isArray(a))return[a];if(c=c||0,c===a.length)return[];var d,e,f=[];for(d=0,e=a.length;e>d;d++)f.push.apply(f,b(a[d]));return f}function c(a){var b,c,d,e;for(b=new Float32Array(4*a.length/3),c=d=0,e=a.length;e>c;)b[d++]=a[c++],b[d++]=a[c++],b[d++]=a[c++],b[d++]=1;return b}function d(a){var b,c;for(b=0,c=a.length;c>b;b++)a[b]=a[b]-1}self.addEventListener("message",function(b){self.postMessage(a(JSON.parse(b.data.data)))})}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/mniobj.intensity.worker.js b/build/brainbrowser-2.2.0/workers/mniobj.intensity.worker.js
new file mode 100644
index 00000000..c4727aef
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/mniobj.intensity.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a){var b,c,d,e,f={};for(f.values=a.trim().split(/\s+/).map(parseFloat),d=f.values[0],e=f.values[0],b=1,c=f.values.length;c>b;b++)d=Math.min(d,f.values[b]),e=Math.max(e,f.values[b]);return f.min=d,f.max=e,f}self.addEventListener("message",function(b){var c=b.data,d=c.data;self.postMessage(a(d))})}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/mniobj.worker.js b/build/brainbrowser-2.2.0/workers/mniobj.worker.js
new file mode 100644
index 00000000..8324b163
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/mniobj.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a,l){j=a.trim().split(/\s+/).reverse(),k=j.length-1;var m,n,o,p,q,r,s,t=[],u=l.split,v={},w=i();if(v.split=!1,v.type="P"===w?"polygon":"L"===w?"line":w,"polygon"===v.type)b(v),v.num_vertices=parseInt(i(),10),c(v),d(v),v.nitems=parseInt(i(),10);else{if("line"!==v.type)return v.error=!0,void(v.error_message='Invalid MNI Object class: must be "polygon" or "line"');b(v),v.num_vertices=parseInt(i(),10),c(v),v.nitems=parseInt(i(),10)}if(e(v),f(v),g(v),"polygon"===v.type)u&&(v.split=!0,h(v));else if("line"===v.type){for(r=v.indices,s=v.end_indices,q=v.nitems,m=0;q>m;m++){for(o=0===m?0:s[m-1],t.push(r[o]),p=s[m],n=o+1;p-1>n;n++)t.push(r[n]),t.push(r[n]);t.push(r[p-1])}v.indices=t}return v}function b(a){"polygon"===a.type?a.surface_properties={ambient:parseFloat(i()),diffuse:parseFloat(i()),specular_reflectance:parseFloat(i()),specular_scattering:parseFloat(i()),transparency:parseFloat(i())}:"line"===a.type&&(a.surfaceProperties={width:i()})}function c(a){var b,c=3*a.num_vertices,d=new Float32Array(c);for(b=0;c>b;b++)d[b]=parseFloat(i());a.vertices=d}function d(a){var b,c=3*a.num_vertices,d=new Float32Array(c);for(b=0;c>b;b++)d[b]=parseFloat(i());a.normals=d}function e(a){var b,c,d,e=parseInt(i(),10);if(0===e)for(b=new Float32Array(4),c=0;4>c;c++)b[c]=parseFloat(i());else if(1===e)for(d=4*a.num_polygons,b=new Float32Array(d),c=0;d>c;c++)b[c]=parseFloat(i());else if(2===e)for(d=4*a.num_vertices,b=new Float32Array(d),c=0;d>c;c++)b[c]=parseFloat(i());else a.error=!0,a.error_message="Invalid color flag: "+e;a.color_flag=e,a.colors=b}function f(a){var b,c=a.nitems,d=new Uint32Array(c);for(b=0;c>b;b++)d[b]=parseInt(i(),10);a.end_indices=d}function g(a){var b,c=k+1,d=new Float32Array(c);for(b=0;c>b;b++)d[b]=parseInt(i(),10);a.indices=d}function h(a){var b=a.indices.length;a.left={indices:Array.prototype.slice.call(a.indices,0,b/2)},a.right={indices:Array.prototype.slice.call(a.indices,b/2)}}function i(){return j[k--]}var j,k;self.addEventListener("message",function(b){var c=b.data,d=a(c.data,c.options)||{error:!0,error_message:"Error parsing data."},e={type:d.type,vertices:d.vertices,normals:d.normals,colors:d.colors,surface_properties:d.surface_properties,split:d.split,error:d.error,error_message:d.error_message};e.shapes=e.split?[{indices:d.left.indices},{indices:d.right.indices}]:[{indices:d.indices}],self.postMessage(e)})}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/wavefrontobj.worker.js b/build/brainbrowser-2.2.0/workers/wavefrontobj.worker.js
new file mode 100644
index 00000000..4f9243ef
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/wavefrontobj.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o=[],p=[],q=[],r={};for(a=a.split("\n"),r.shapes=[],b={faces:[],indices:[],texture_indices:[],normal_indices:[]},r.shapes.push(b),i=0,l=a.length;l>i;i++)if(f=a[i].replace(/^\s+/,"").replace(/\s+$/,"").split(/\s+/),g=f[0],h=f.length,!g.match("#")||""===f)switch(g){case"o":case"g":b={name:f[1],faces:[],indices:[],texture_indices:[],normal_indices:[]},r.shapes.push(b);break;case"v":o.push(parseFloat(f[1])),o.push(parseFloat(f[2])),o.push(parseFloat(f[3]));break;case"vt":for(j=1;h>j;j++)p.push(parseFloat(f[j]));break;case"vn":q.push(parseFloat(f[1])),q.push(parseFloat(f[2])),q.push(parseFloat(f[3]));break;case"f":m=[],c=b.indices,d=b.texture_indices,e=b.normal_indices;var s=f[1].split("/");for(k=2;h-1>k;k++)m.push(parseInt(s[0],10)-1),c.push(parseInt(s[0],10)-1),d.push(parseInt(s[1],10)-1),s[2]&&e.push(parseInt(s[2],10)-1),n=f[k].split("/"),m.push(parseInt(n[0],10)-1),c.push(parseInt(n[0],10)-1),d.push(parseInt(n[1],10)-1),n[2]&&e.push(parseInt(n[2],10)-1),n=f[k+1].split("/"),m.push(parseInt(n[0],10)-1),c.push(parseInt(n[0],10)-1),d.push(parseInt(n[1],10)-1),n[2]&&e.push(parseInt(n[2],10)-1);b.faces.push(m)}return r.type="polygon",r.vertices=o,r.normals=q,r.texture_coords=p,r}self.addEventListener("message",function(b){self.postMessage(a(b.data.data))})}();
\ No newline at end of file
diff --git a/build/brainbrowser-2.2.0/workers/wireframe.worker.js b/build/brainbrowser-2.2.0/workers/wireframe.worker.js
new file mode 100644
index 00000000..18d1191e
--- /dev/null
+++ b/build/brainbrowser-2.2.0/workers/wireframe.worker.js
@@ -0,0 +1,32 @@
+/*
+* BrainBrowser: Web-based Neurological Visualization Tools
+* (https://brainbrowser.cbrain.mcgill.ca)
+*
+* Copyright (C) 2011
+* The Royal Institution for the Advancement of Learning
+* McGill University
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see .
+*/
+
+/*
+* BrainBrowser v2.2.0
+*
+* Author: Tarek Sherif (http://tareksherif.ca/)
+* Author: Nicolas Kassis
+* Author: Paul Mougel
+*
+* three.js (c) 2010-2014 three.js authors, used under the MIT license
+*/
+!function(){"use strict";function a(a,b){var c,d,e,f,g,h=new Float32Array(2*a.length),i=new Float32Array(2*b.length),j=a.length/3;for(c=0;j>c;c+=3)e=3*c,f=4*c,d=2*e,g=2*f,h[d]=a[e],h[d+1]=a[e+1],h[d+2]=a[e+2],h[d+3]=a[e+3],h[d+4]=a[e+4],h[d+5]=a[e+5],h[d+6]=a[e+3],h[d+7]=a[e+4],h[d+8]=a[e+5],h[d+9]=a[e+6],h[d+10]=a[e+7],h[d+11]=a[e+8],h[d+12]=a[e+6],h[d+13]=a[e+7],h[d+14]=a[e+8],h[d+15]=a[e],h[d+16]=a[e+1],h[d+17]=a[e+2],i[g]=b[f],i[g+1]=b[f+1],i[g+2]=b[f+2],i[g+3]=b[f+3],i[g+4]=b[f+4],i[g+5]=b[f+5],i[g+6]=b[f+6],i[g+7]=b[f+7],i[g+8]=b[f+4],i[g+9]=b[f+5],i[g+10]=b[f+6],i[g+11]=b[f+7],i[g+12]=b[f+8],i[g+13]=b[f+9],i[g+14]=b[f+10],i[g+15]=b[f+11],i[g+16]=b[f+8],i[g+17]=b[f+9],i[g+18]=b[f+10],i[g+19]=b[f+11],i[g+20]=b[f],i[g+21]=b[f+1],i[g+22]=b[f+2],i[g+23]=b[f+3];return{positions:h,colors:i}}self.addEventListener("message",function(b){var c=b.data;self.postMessage(a(c.positions,c.colors))})}();
\ No newline at end of file
diff --git a/package.json b/package.json
index 43bf7ebb..8b734d7d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "brainbrowser",
- "version": "2.1.1",
+ "version": "2.2.0",
"license": "GNU Affero GPL 3.0",
"devDependencies": {
"grunt": "~0.4.1",
diff --git a/release/brainbrowser-2.2.0.tar.gz b/release/brainbrowser-2.2.0.tar.gz
new file mode 100644
index 00000000..f9d9ae05
Binary files /dev/null and b/release/brainbrowser-2.2.0.tar.gz differ