0;var c;c=j?{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")}:{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")},g=d(c),h={vertex:m.getAttribLocation(g,"position"),uv:m.getAttribLocation(g,"uv")},i={renderType:m.getUniformLocation(g,"renderType"),map:m.getUniformLocation(g,"map"),occlusionMap:m.getUniformLocation(g,"occlusionMap"),opacity:m.getUniformLocation(g,"opacity"),color:m.getUniformLocation(g,"color"),scale:m.getUniformLocation(g,"scale"),rotation:m.getUniformLocation(g,"rotation"),screenPosition:m.getUniformLocation(g,"screenPosition")}};this.render=function(d,o,p,q){if(0!==c.length){var r=new a.Vector3,s=q/p,t=.5*p,u=.5*q,v=16/q,w=new a.Vector2(v*s,v),x=new a.Vector3(1,1,0),y=new a.Vector2(1,1);void 0===g&&n(),m.useProgram(g),m.enableVertexAttribArray(h.vertex),m.enableVertexAttribArray(h.uv),m.uniform1i(i.occlusionMap,0),m.uniform1i(i.map,1),m.bindBuffer(m.ARRAY_BUFFER,e),m.vertexAttribPointer(h.vertex,2,m.FLOAT,!1,16,0),m.vertexAttribPointer(h.uv,2,m.FLOAT,!1,16,8),m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,f),m.disable(m.CULL_FACE),m.depthMask(!1);for(var z=0,A=c.length;A>z;z++){v=16/q,w.set(v*s,v);var B=c[z];if(r.set(B.matrixWorld.elements[12],B.matrixWorld.elements[13],B.matrixWorld.elements[14]),r.applyMatrix4(o.matrixWorldInverse),r.applyProjection(o.projectionMatrix),x.copy(r),y.x=x.x*t+t,y.y=x.y*u+u,j||y.x>0&&y.x0&&y.yC;C++){var E=B.lensFlares[C];E.opacity>.001&&E.scale>.001&&(x.x=E.x,x.y=E.y,x.z=E.z,v=E.size*E.scale/q,w.x=v*s,w.y=v,m.uniform3f(i.screenPosition,x.x,x.y,x.z),m.uniform2f(i.scale,w.x,w.y),m.uniform1f(i.rotation,E.rotation),m.uniform1f(i.opacity,E.opacity),m.uniform3f(i.color,E.color.r,E.color.g,E.color.b),b.setBlending(E.blending,E.blendEquation,E.blendSrc,E.blendDst),b.setTexture(E.texture,1),m.drawElements(m.TRIANGLES,6,m.UNSIGNED_SHORT,0))}}}m.enable(m.CULL_FACE),m.enable(m.DEPTH_TEST),m.depthMask(!0),b.resetGLState()}}},a.ShadowMapPlugin=function(b,c,d,e){function f(a,b,c){if(b.visible){var e=d[b.id];if(e&&b.castShadow&&(b.frustumCulled===!1||p.intersectsObject(b)===!0))for(var g=0,h=e.length;h>g;g++){var i=e[g];b._modelViewMatrix.multiplyMatrices(c.matrixWorldInverse,b.matrixWorld),u.push(i)}for(var g=0,h=b.children.length;h>g;g++)f(a,b.children[g],c)}}function g(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 h(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 i(a,b){var c=b.shadowCamera,d=b.pointsFrustum,e=b.pointsWorld;r.set(1/0,1/0,1/0),s.set(-(1/0),-(1/0),-(1/0));for(var f=0;8>f;f++){var g=e[f];g.copy(d[f]),g.unproject(a),g.applyMatrix4(c.matrixWorldInverse),g.xs.x&&(s.x=g.x),g.ys.y&&(s.y=g.y),g.zs.z&&(s.z=g.z)}c.left=r.x,c.right=s.x,c.top=s.y,c.bottom=r.y,c.updateProjectionMatrix()}function j(b){return b.material instanceof a.MeshFaceMaterial?b.material.materials[0]:b.material}var k,l,m,n,o=b.context,p=new a.Frustum,q=new a.Matrix4,r=new a.Vector3,s=new a.Vector3,t=new a.Vector3,u=[],v=a.ShaderLib.depthRGBA,w=a.UniformsUtils.clone(v.uniforms);k=new a.ShaderMaterial({uniforms:w,vertexShader:v.vertexShader,fragmentShader:v.fragmentShader}),l=new a.ShaderMaterial({uniforms:w,vertexShader:v.vertexShader,fragmentShader:v.fragmentShader,morphTargets:!0}),m=new a.ShaderMaterial({uniforms:w,vertexShader:v.vertexShader,fragmentShader:v.fragmentShader,skinning:!0}),n=new a.ShaderMaterial({uniforms:w,vertexShader:v.vertexShader,fragmentShader:v.fragmentShader,morphTargets:!0,skinning:!0}),k._shadowPass=!0,l._shadowPass=!0,m._shadowPass=!0,n._shadowPass=!0,this.render=function(d,r){if(b.shadowMapEnabled!==!1){var s,v,w,x,y,z,A,B,C,D,E,F,G,H=[],I=0,J=null;for(o.clearColor(1,1,1,1),o.disable(o.BLEND),o.enable(o.CULL_FACE),o.frontFace(o.CCW),b.shadowMapCullFace===a.CullFaceFront?o.cullFace(o.FRONT):o.cullFace(o.BACK),b.setDepthTest(!0),s=0,v=c.length;v>s;s++)if(G=c[s],G.castShadow)if(G instanceof a.DirectionalLight&&G.shadowCascade)for(y=0;ys;s++){if(G=H[s],!G.shadowMap){var M=a.LinearFilter;b.shadowMapType===a.PCFSoftShadowMap&&(M=a.NearestFilter);var N={minFilter:M,magFilter:M,format:a.RGBAFormat};G.shadowMap=new a.WebGLRenderTarget(G.shadowMapWidth,G.shadowMapHeight,N),G.shadowMapSize=new a.Vector2(G.shadowMapWidth,G.shadowMapHeight),G.shadowMatrix=new a.Matrix4}if(!G.shadowCamera){if(G instanceof a.SpotLight)G.shadowCamera=new a.PerspectiveCamera(G.shadowCameraFov,G.shadowMapWidth/G.shadowMapHeight,G.shadowCameraNear,G.shadowCameraFar);else{if(!(G instanceof a.DirectionalLight)){console.error("Unsupported light type for shadow");continue}G.shadowCamera=new a.OrthographicCamera(G.shadowCameraLeft,G.shadowCameraRight,G.shadowCameraTop,G.shadowCameraBottom,G.shadowCameraNear,G.shadowCameraFar)}d.add(G.shadowCamera),d.autoUpdate===!0&&d.updateMatrixWorld()}G.shadowCameraVisible&&!G.cameraHelper&&(G.cameraHelper=new a.CameraHelper(G.shadowCamera),d.add(G.cameraHelper)),G.isVirtual&&K.originalCamera==r&&i(r,G),z=G.shadowMap,A=G.shadowMatrix,B=G.shadowCamera,B.position.setFromMatrixPosition(G.matrixWorld),t.setFromMatrixPosition(G.target.matrixWorld),B.lookAt(t),B.updateMatrixWorld(),B.matrixWorldInverse.getInverse(B.matrixWorld),G.cameraHelper&&(G.cameraHelper.visible=G.shadowCameraVisible),G.shadowCameraVisible&&G.cameraHelper.update(),A.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),A.multiply(B.projectionMatrix),A.multiply(B.matrixWorldInverse),q.multiplyMatrices(B.projectionMatrix,B.matrixWorldInverse),p.setFromMatrix(q),b.setRenderTarget(z),b.clear(),u.length=0,f(d,d,B);var O,P,Q;for(w=0,x=u.length;x>w;w++)E=u[w],F=E.object,C=E.buffer,O=j(F),P=void 0!==F.geometry.morphTargets&&F.geometry.morphTargets.length>0&&O.morphTargets,Q=F instanceof a.SkinnedMesh&&O.skinning,D=F.customDepthMaterial?F.customDepthMaterial:Q?P?n:m:P?l:k,b.setMaterialFaces(O),C instanceof a.BufferGeometry?b.renderBufferDirect(B,c,J,D,C,F):b.renderBuffer(B,c,J,D,C,F);for(w=0,x=e.length;x>w;w++)E=e[w],F=E.object,F.visible&&F.castShadow&&(F._modelViewMatrix.multiplyMatrices(B.matrixWorldInverse,F.matrixWorld),b.renderImmediateObject(B,c,J,k,F))}var R=b.getClearColor(),S=b.getClearAlpha();o.clearColor(R.r,R.g,R.b,S),o.enable(o.BLEND),b.shadowMapCullFace===a.CullFaceFront&&o.cullFace(o.BACK),b.resetGLState()}}},a.SpritePlugin=function(b,c){function d(){var a=l.createProgram(),c=l.createShader(l.VERTEX_SHADER),d=l.createShader(l.FRAGMENT_SHADER);return l.shaderSource(c,["precision "+b.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")),l.shaderSource(d,["precision "+b.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")),l.compileShader(c),l.compileShader(d),l.attachShader(a,c),l.attachShader(a,d),l.linkProgram(a),a}function e(a,b){return a.z!==b.z?b.z-a.z:b.id-a.id}var f,g,h,i,j,k,l=b.context,m=function(){var b=new Float32Array([-.5,-.5,0,0,.5,-.5,1,0,.5,.5,1,1,-.5,.5,0,1]),c=new Uint16Array([0,1,2,0,2,3]);f=l.createBuffer(),g=l.createBuffer(),l.bindBuffer(l.ARRAY_BUFFER,f),l.bufferData(l.ARRAY_BUFFER,b,l.STATIC_DRAW),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,g),l.bufferData(l.ELEMENT_ARRAY_BUFFER,c,l.STATIC_DRAW),h=d(),i={position:l.getAttribLocation(h,"position"),uv:l.getAttribLocation(h,"uv")},j={uvOffset:l.getUniformLocation(h,"uvOffset"),uvScale:l.getUniformLocation(h,"uvScale"),rotation:l.getUniformLocation(h,"rotation"),scale:l.getUniformLocation(h,"scale"),color:l.getUniformLocation(h,"color"),map:l.getUniformLocation(h,"map"),opacity:l.getUniformLocation(h,"opacity"),modelViewMatrix:l.getUniformLocation(h,"modelViewMatrix"),projectionMatrix:l.getUniformLocation(h,"projectionMatrix"),fogType:l.getUniformLocation(h,"fogType"),fogDensity:l.getUniformLocation(h,"fogDensity"),fogNear:l.getUniformLocation(h,"fogNear"),fogFar:l.getUniformLocation(h,"fogFar"),fogColor:l.getUniformLocation(h,"fogColor"),alphaTest:l.getUniformLocation(h,"alphaTest")};var e=document.createElement("canvas");e.width=8,e.height=8;var m=e.getContext("2d");m.fillStyle="white",m.fillRect(0,0,8,8),k=new a.Texture(e),k.needsUpdate=!0};this.render=function(d,n){if(0!==c.length){void 0===h&&m(),l.useProgram(h),l.enableVertexAttribArray(i.position),l.enableVertexAttribArray(i.uv),l.disable(l.CULL_FACE),l.enable(l.BLEND),l.bindBuffer(l.ARRAY_BUFFER,f),l.vertexAttribPointer(i.position,2,l.FLOAT,!1,16,0),l.vertexAttribPointer(i.uv,2,l.FLOAT,!1,16,8),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,g),l.uniformMatrix4fv(j.projectionMatrix,!1,n.projectionMatrix.elements),l.activeTexture(l.TEXTURE0),l.uniform1i(j.map,0);var o=0,p=0,q=d.fog;q?(l.uniform3f(j.fogColor,q.color.r,q.color.g,q.color.b),q instanceof a.Fog?(l.uniform1f(j.fogNear,q.near),l.uniform1f(j.fogFar,q.far),l.uniform1i(j.fogType,1),o=1,p=1):q instanceof a.FogExp2&&(l.uniform1f(j.fogDensity,q.density),l.uniform1i(j.fogType,2),o=2,p=2)):(l.uniform1i(j.fogType,0),o=0,p=0);for(var r=0,s=c.length;s>r;r++){var t=c[r];t._modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,t.matrixWorld),null===t.renderDepth?t.z=-t._modelViewMatrix.elements[14]:t.z=t.renderDepth}c.sort(e);for(var u=[],r=0,s=c.length;s>r;r++){var t=c[r],v=t.material;l.uniform1f(j.alphaTest,v.alphaTest),l.uniformMatrix4fv(j.modelViewMatrix,!1,t._modelViewMatrix.elements),u[0]=t.scale.x,u[1]=t.scale.y;var w=0;d.fog&&v.fog&&(w=p),o!==w&&(l.uniform1i(j.fogType,w),o=w),null!==v.map?(l.uniform2f(j.uvOffset,v.map.offset.x,v.map.offset.y),l.uniform2f(j.uvScale,v.map.repeat.x,v.map.repeat.y)):(l.uniform2f(j.uvOffset,0,0),l.uniform2f(j.uvScale,1,1)),l.uniform1f(j.opacity,v.opacity),l.uniform3f(j.color,v.color.r,v.color.g,v.color.b),l.uniform1f(j.rotation,v.rotation),l.uniform2fv(j.scale,u),b.setBlending(v.blending,v.blendEquation,v.blendSrc,v.blendDst),b.setDepthTest(v.depthTest),b.setDepthWrite(v.depthWrite),v.map&&v.map.image&&v.map.image.width?b.setTexture(v.map,0):b.setTexture(k,0),l.drawElements(l.TRIANGLES,6,l.UNSIGNED_SHORT,0)}l.enable(l.CULL_FACE),b.resetGLState()}}},a.GeometryUtils={merge:function(b,c,d){console.warn("THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.");var e;c instanceof a.Mesh&&(c.matrixAutoUpdate&&c.updateMatrix(),e=c.matrix,c=c.geometry),b.merge(c,e,d)},center:function(a){return console.warn("THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead."),a.center()}},a.ImageUtils={crossOrigin:void 0,loadTexture:function(b,c,d,e){var f=new a.ImageLoader;f.crossOrigin=this.crossOrigin;var g=new a.Texture(void 0,c);return f.load(b,function(a){g.image=a,g.needsUpdate=!0,d&&d(g)},void 0,function(a){e&&e(a)}),g.sourceFile=b,g},loadTextureCube:function(b,c,d,e){var f=[],g=new a.ImageLoader;g.crossOrigin=this.crossOrigin;var h=new a.CubeTexture(f,c);h.flipY=!1;for(var i=0,j=function(a){g.load(b[a],function(b){h.images[a]=b,i+=1,6===i&&(h.needsUpdate=!0,d&&d(h))})},k=0,l=b.length;l>k;++k)j(k);return h},loadCompressedTexture:function(){console.error("THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.")},loadCompressedTextureCube:function(){console.error("THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.")},getNormalMap:function(a,b){var c=function(a,b){return[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]},d=function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2]]},e=function(a){var b=Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);return[a[0]/b,a[1]/b,a[2]/b]};b=1|b;var f=a.width,g=a.height,h=document.createElement("canvas");h.width=f,h.height=g;var i=h.getContext("2d");i.drawImage(a,0,0);for(var j=i.getImageData(0,0,f,g).data,k=i.createImageData(f,g),l=k.data,m=0;f>m;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(){try{return this.faces[this.face][this.weight][this.style]}catch(a){throw"The font "+this.face+" with "+this.weight+" weight and "+this.style+" style is missing."}},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(u,v,w,x,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.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.Audio=function(b){a.Object3D.call(this),this.type="Audio",this.context=b.context,this.source=this.context.createBufferSource(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.panner=this.context.createPanner(),this.panner.connect(this.gain)},a.Audio.prototype=Object.create(a.Object3D.prototype),a.Audio.prototype.load=function(a){var b=this,c=new XMLHttpRequest;return c.open("GET",a,!0),c.responseType="arraybuffer",c.onload=function(a){b.context.decodeAudioData(this.response,function(a){b.source.buffer=a,b.source.connect(b.panner),b.source.start(0)})},c.send(),this},a.Audio.prototype.setLoop=function(a){this.source.loop=a},a.Audio.prototype.setRefDistance=function(a){this.panner.refDistance=a},a.Audio.prototype.setRolloffFactor=function(a){this.panner.rolloffFactor=a},a.Audio.prototype.updateMatrixWorld=function(){var b=new a.Vector3;return function(c){a.Object3D.prototype.updateMatrixWorld.call(this,c),b.setFromMatrixPosition(this.matrixWorld),this.panner.setPosition(b.x,b.y,b.z)}}(),a.AudioListener=function(){a.Object3D.call(this),this.type="AudioListener",this.context=new(window.AudioContext||window.webkitAudioContext)},a.AudioListener.prototype=Object.create(a.Object3D.prototype),a.AudioListener.prototype.updateMatrixWorld=function(){var b=new a.Vector3,c=new a.Quaternion,d=new a.Vector3,e=new a.Vector3,f=new a.Vector3,g=new a.Vector3;return function(h){a.Object3D.prototype.updateMatrixWorld.call(this,h);var i=this.context.listener;this.matrixWorld.decompose(b,c,d),e.set(0,0,-1).applyQuaternion(c),f.subVectors(b,g),i.setPosition(b.x,b.y,b.z),i.setOrientation(e.x,e.y,e.z,this.up.x,this.up.y,this.up.z),i.setVelocity(f.x,f.y,f.z),g.copy(b)}}(),a.Curve=function(){},a.Curve.prototype.getPoint=function(a){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,b,c,d,e){var f=6*a*a-6*a,g=3*a*a-4*a+1,h=-6*a*a+6*a,i=3*a*a-2*a;return f+g+h+i},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(){var b=new a.Vector3,c=new a.Quaternion,d=new a.Vector3,e=new a.Vector3,f=new a.Quaternion,g=new a.Vector3;return function(a){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||a)&&(this.parent?(this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorld.decompose(e,f,g),this.matrix.decompose(b,c,d),this.matrixWorld.compose(e,c,g)):this.matrixWorld.copy(this.matrix),this.matrixWorldNeedsUpdate=!1,a=!0);for(var h=0,i=this.children.length;i>h;h++)this.children[h].updateMatrixWorld(a)}}(),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(b,c){var d=Array.prototype.slice.call(arguments);this.actions.push({action:a.PathActions.MOVE_TO,args:d})},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,b){a||(a=40);for(var c=[],d=0;a>d;d++)c.push(this.getPoint(d/a));return c},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)c;c++)e=b[c],g=e.args,f=e.action,f==a.PathActions.MOVE_TO&&0!=i.actions.length&&(h.push(i),i=new a.Path),i[f].apply(i,g);return 0!=i.actions.length&&h.push(i),h}function e(b){for(var c=[],d=0,e=b.length;e>d;d++){var f=b[d],g=new a.Shape;g.actions=f.actions,g.curves=f.curves,c.push(g)}return c}function f(a,b){for(var c=1e-10,d=b.length,e=!1,f=d-1,g=0;d>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 g=d(this.actions);if(0==g.length)return[];if(c===!0)return e(g);var h,i,j,k=[];if(1==g.length)return i=g[0],j=new a.Shape,j.actions=i.actions,j.curves=i.curves,k.push(j),k;var l=!a.Shape.Utils.isClockWise(g[0].getPoints());l=b?!l:l;var m,n=[],o=[],p=[],q=0;o[q]=void 0,p[q]=[];var r,s;for(r=0,s=g.length;s>r;r++)i=g[r],m=i.getPoints(),h=a.Shape.Utils.isClockWise(m),h=b?!h:h,h?(!l&&o[q]&&q++,o[q]={s:new a.Shape,p:m},o[q].s.actions=i.actions,o[q].s.curves=i.curves,l&&q++,p[q]=[]):p[q].push({h:i,p:m[0]});if(!o[0])return e(g);if(o.length>1){for(var t=!1,u=[],v=0,w=o.length;w>v;v++)n[v]=[];for(var v=0,w=o.length;w>v;v++)for(var x=(o[v],p[v]),y=0;y0&&(t||(p=n))}var C,D,E;for(r=0,s=o.length;s>r;r++)for(j=o[r].s,k.push(j),C=p[r],D=0,E=C.length;E>D;D++)j.holes.push(C[D].h);return k},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=0,y=2*t.length;t.length>0;){if(y--,0>y){console.log("Infinite Loop! Holes left:"+t.length+", Probably Hole outside Shape!");break}for(j=x;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(a){var b=this.v2.clone().sub(this.v1);return b.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=new a.Vector2;return c.x=a.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x),c.y=a.Shape.Utils.b2(b,this.v0.y,this.v1.y,this.v2.y),c},a.QuadraticBezierCurve.prototype.getTangent=function(b){var c=new a.Vector2;return c.x=a.Curve.Utils.tangentQuadraticBezier(b,this.v0.x,this.v1.x,this.v2.x),c.y=a.Curve.Utils.tangentQuadraticBezier(b,this.v0.y,this.v1.y,this.v2.y),c.normalize()},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=this.points,d=(c.length-1)*b,e=Math.floor(d),f=d-e,g=c[0==e?e:e-1],h=c[e],i=c[e>c.length-2?c.length-1:e+1],j=c[e>c.length-3?c.length-1:e+2],k=new a.Vector2;return k.x=a.Curve.Utils.interpolate(g.x,h.x,i.x,j.x,f),k.y=a.Curve.Utils.interpolate(g.y,h.y,i.y,j.y,f),k},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=this.aEndAngle-this.aStartAngle;0>c&&(c+=2*Math.PI),c>2*Math.PI&&(c-=2*Math.PI);var d;d=this.aClockwise===!0?this.aEndAngle+(1-b)*(2*Math.PI-c):this.aStartAngle+b*c;var e=new a.Vector2;return e.x=this.aX+this.xRadius*Math.cos(d),e.y=this.aY+this.yRadius*Math.sin(d),e},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=new a.Vector3;return c.x=a.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x),c.y=a.Shape.Utils.b2(b,this.v0.y,this.v1.y,this.v2.y),c.z=a.Shape.Utils.b2(b,this.v0.z,this.v1.z,this.v2.z),c}),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=new a.Vector3;return c.x=a.Shape.Utils.b3(b,this.v0.x,this.v1.x,this.v2.x,this.v3.x),c.y=a.Shape.Utils.b3(b,this.v0.y,this.v1.y,this.v2.y,this.v3.y),c.z=a.Shape.Utils.b3(b,this.v0.z,this.v1.z,this.v2.z,this.v3.z),c}),a.SplineCurve3=a.Curve.create(function(a){this.points=void 0==a?[]:a},function(b){var c=this.points,d=(c.length-1)*b,e=Math.floor(d),f=d-e,g=c[0==e?e:e-1],h=c[e],i=c[e>c.length-2?c.length-1:e+1],j=c[e>c.length-3?c.length-1:e+2],k=new a.Vector3;return k.x=a.Curve.Utils.interpolate(g.x,h.x,i.x,j.x,f),k.y=a.Curve.Utils.interpolate(g.y,h.y,i.y,j.y,f),k.z=a.Curve.Utils.interpolate(g.z,h.z,i.z,j.z,f),k}),a.ClosedSplineCurve3=a.Curve.create(function(a){this.points=void 0==a?[]:a},function(b){var c=this.points,d=(c.length-0)*b,e=Math.floor(d),f=d-e;e+=e>0?0:(Math.floor(Math.abs(e)/c.length)+1)*c.length;var g=c[(e-1)%c.length],h=c[e%c.length],i=c[(e+1)%c.length],j=c[(e+2)%c.length],k=new a.Vector3;return k.x=a.Curve.Utils.interpolate(g.x,h.x,i.x,j.x,f),k.y=a.Curve.Utils.interpolate(g.y,h.y,i.y,j.y,f),k.z=a.Curve.Utils.interpolate(g.z,h.z,i.z,j.z,f),k}),a.AnimationHandler={LINEAR:0,CATMULLROM:1,CATMULLROM_FORWARD:2,add:function(){console.warn("THREE.AnimationHandler.add() has been deprecated.")},get:function(){console.warn("THREE.AnimationHandler.get() has been deprecated.")},remove:function(){console.warn("THREE.AnimationHandler.remove() has been deprecated.")},animations:[],init:function(b){if(b.initialized!==!0){for(var c=0;ca;a++){var c=this.hierarchy[a];c.matrixAutoUpdate=!0,void 0===c.animationCache&&(c.animationCache={animations:{},blending:{positionWeight:0,quaternionWeight:0,scaleWeight:0}}),void 0===c.animationCache.animations[this.data.name]&&(c.animationCache.animations[this.data.name]={},c.animationCache.animations[this.data.name].prevKey={pos:0,rot:0,scl:0},c.animationCache.animations[this.data.name].nextKey={pos:0,rot:0,scl:0},c.animationCache.animations[this.data.name].originalMatrix=c.matrix);for(var d=c.animationCache.animations[this.data.name],e=0;3>e;e++){for(var f=this.keyTypes[e],g=this.data.hierarchy[a].keys[0],h=this.getNextKeyWith(f,a,1);h.timeg.index;)g=h,h=this.getNextKeyWith(f,a,h.index+1);d.prevKey[f]=g,d.nextKey[f]=h}}},a.Animation.prototype.resetBlendWeights=function(){for(var a=0,b=this.hierarchy.length;b>a;a++){var c=this.hierarchy[a];void 0!==c.animationCache&&(c.animationCache.blending.positionWeight=0,c.animationCache.blending.quaternionWeight=0,c.animationCache.blending.scaleWeight=0)}},a.Animation.prototype.update=function(){var b=[],c=new a.Vector3,d=new a.Vector3,e=new a.Quaternion,f=function(a,b){var c,d,e,f,h,i,j,k,l,m=[],n=[];return c=(a.length-1)*b,d=Math.floor(c),e=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]],f=e*e,h=e*f,n[0]=g(i[0],j[0],k[0],l[0],e,f,h),n[1]=g(i[1],j[1],k[1],l[1],e,f,h),n[2]=g(i[2],j[2],k[2],l[2],e,f,h),n},g=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(g){if(this.isPlaying!==!1&&(this.currentTime+=g*this.timeScale,0!==this.weight)){var h=this.data.length;if(this.currentTime>h||this.currentTime<0){if(!this.loop)return void this.stop();this.currentTime%=h,this.currentTime<0&&(this.currentTime+=h),this.reset()}for(var i=0,j=this.hierarchy.length;j>i;i++)for(var k=this.hierarchy[i],l=k.animationCache.animations[this.data.name],m=k.animationCache.blending,n=0;3>n;n++){var o=this.keyTypes[n],p=l.prevKey[o],q=l.nextKey[o];if(this.timeScale>0&&q.time<=this.currentTime||this.timeScale<0&&p.time>=this.currentTime){for(p=this.data.hierarchy[i].keys[0],q=this.getNextKeyWith(o,i,1);q.timep.index;)p=q,q=this.getNextKeyWith(o,i,q.index+1);l.prevKey[o]=p,l.nextKey[o]=q}k.matrixAutoUpdate=!0,k.matrixWorldNeedsUpdate=!0;var r=(this.currentTime-p.time)/(q.time-p.time),s=p[o],t=q[o];if(0>r&&(r=0),r>1&&(r=1),"pos"===o){if(this.interpolationType===a.AnimationHandler.LINEAR){d.x=s[0]+(t[0]-s[0])*r,d.y=s[1]+(t[1]-s[1])*r,d.z=s[2]+(t[2]-s[2])*r;var u=this.weight/(this.weight+m.positionWeight);k.position.lerp(d,u),m.positionWeight+=this.weight}else if(this.interpolationType===a.AnimationHandler.CATMULLROM||this.interpolationType===a.AnimationHandler.CATMULLROM_FORWARD){b[0]=this.getPrevKeyWith("pos",i,p.index-1).pos,b[1]=s,b[2]=t,b[3]=this.getNextKeyWith("pos",i,q.index+1).pos,r=.33*r+.33;var v=f(b,r),u=this.weight/(this.weight+m.positionWeight);m.positionWeight+=this.weight;var w=k.position;if(w.x=w.x+(v[0]-w.x)*u,w.y=w.y+(v[1]-w.y)*u,w.z=w.z+(v[2]-w.z)*u,this.interpolationType===a.AnimationHandler.CATMULLROM_FORWARD){var x=f(b,1.01*r);c.set(x[0],x[1],x[2]),c.sub(w),c.y=0,c.normalize();var y=Math.atan2(c.x,c.z);k.rotation.set(0,y,0)}}}else if("rot"===o)if(a.Quaternion.slerp(s,t,e,r),0===m.quaternionWeight)k.quaternion.copy(e),m.quaternionWeight=this.weight;else{var u=this.weight/(this.weight+m.quaternionWeight);a.Quaternion.slerp(k.quaternion,e,k.quaternion,u),m.quaternionWeight+=this.weight}else if("scl"===o){d.x=s[0]+(t[0]-s[0])*r,d.y=s[1]+(t[1]-s[1])*r,d.z=s[2]+(t[2]-s[2])*r;
+var u=this.weight/(this.weight+m.scaleWeight);k.scale.lerp(d,u),m.scaleWeight+=this.weight}}return!0}}}(),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){this.root=b.node,this.data=a.AnimationHandler.init(b),this.hierarchy=a.AnimationHandler.parse(this.root),this.currentTime=0,this.timeScale=.001,this.isPlaying=!1,this.isPaused=!0,this.loop=!0;for(var c=0,d=this.hierarchy.length;d>c;c++){var e=this.data.hierarchy[c].keys,f=this.data.hierarchy[c].sids,g=this.hierarchy[c];if(e.length&&f){for(var h=0;hc;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.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.play(this)},a.KeyFrameAnimation.prototype.stop=function(){this.isPlaying=!1,this.isPaused=!1,a.AnimationHandler.stop(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.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),this.type="BoxGeometry",this.parameters={width:b,height:c,depth:d,widthSegments:e,heightSegments:f,depthSegments:g},this.widthSegments=e||1,this.heightSegments=f||1,this.depthSegments=g||1;var i=this,j=b/2,k=c/2,l=d/2;h("z","y",-1,-1,d,c,j,0),h("z","y",1,-1,d,c,-j,1),h("x","z",1,1,b,d,k,2),h("x","z",1,-1,b,d,-k,3),h("x","y",1,-1,b,c,l,4),h("x","y",-1,-1,b,c,-l,5),this.mergeVertices()},a.BoxGeometry.prototype=Object.create(a.Geometry.prototype),a.CircleGeometry=function(b,c,d,e){a.Geometry.call(this),this.type="CircleGeometry",this.parameters={radius:b,segments:c,thetaStart:d,thetaLength:e},b=b||50,c=void 0!==c?Math.max(3,c):8,d=void 0!==d?d:0,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++)this.faces.push(new a.Face3(f,f+1,0,[l.clone(),l.clone(),l.clone()])),this.faceVertexUvs[0].push([g[f].clone(),g[f+1].clone(),i.clone()]);this.computeFaceNormals(),this.boundingSphere=new a.Sphere(new a.Vector3,b)},a.CircleGeometry.prototype=Object.create(a.Geometry.prototype),a.CubeGeometry=function(b,c,d,e,f,g){return console.warn("THREE.CubeGeometry has been renamed to THREE.BoxGeometry."),new a.BoxGeometry(b,c,d,e,f,g)},a.CylinderGeometry=function(b,c,d,e,f,g){a.Geometry.call(this),this.type="CylinderGeometry",this.parameters={radiusTop:b,radiusBottom:c,height:d,radialSegments:e,heightSegments:f,openEnded:g},b=void 0!==b?b:20,c=void 0!==c?c:20,d=void 0!==d?d:100,e=e||8,f=f||1,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.computeFaceNormals()},a.CylinderGeometry.prototype=Object.create(a.Geometry.prototype),a.ExtrudeGeometry=function(b,c){return"undefined"==typeof b?void(b=[]):(a.Geometry.call(this),this.type="ExtrudeGeometry",b=b instanceof Array?b:[b],this.addShapeList(b,c),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=1,i=b.x-c.x,j=b.y-c.y,k=d.x-b.x,l=d.y-b.y,m=i*i+j*j,n=i*l-j*k;if(Math.abs(n)>g){var o=Math.sqrt(m),p=Math.sqrt(k*k+l*l),q=c.x-j/o,r=c.y+i/o,s=d.x-l/p,t=d.y+k/p,u=((s-q)*l-(t-r)*k)/(i*l-j*k);e=q+i*u-b.x,f=r+j*u-b.y;var v=e*e+f*f;if(2>=v)return new a.Vector2(e,f);h=Math.sqrt(v/2)}else{var w=!1;i>g?k>g&&(w=!0):-g>i?-g>k&&(w=!0):Math.sign(j)==Math.sign(l)&&(w=!0),w?(e=-j,f=i,h=Math.sqrt(m)):(e=i,f=j,h=Math.sqrt(m/2))}return new a.Vector2(e/h,f/h)}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);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)}else{for(W=0;U>W;W++)S=L[W],j(S[2],S[1],S[0]);for(W=0;U>W;W++)S=L[W],j(S[0]+T*w,S[1]+T*w,S[2]+T*w)}}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(b,c,d){b+=G,c+=G,d+=G,F.faces.push(new a.Face3(b,c,d,null,null,z));var e=B.generateTopUV(F,b,c,d);F.faceVertexUvs[0].push(e)}function k(b,c,d,e,f,g,h,i,j){b+=G,c+=G,d+=G,e+=G,F.faces.push(new a.Face3(b,c,e,null,null,A)),F.faces.push(new a.Face3(c,d,e,null,null,A));var k=B.generateSideWallUV(F,b,c,d,e);F.faceVertexUvs[0].push([k[0],k[1],k[3]]),F.faceVertexUvs[0].push([k[1],k[2],k[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;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 $,_=[],aa=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($),aa=aa.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],aa[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 ba;for(ba=1;w>=ba;ba++)for(W=0;T>W;W++)R=u?d(I[W],aa[W],O):I[W],y?(o.copy(m.normals[ba]).multiplyScalar(R.x),n.copy(m.binormals[ba]).multiplyScalar(R.y),p.copy(l[ba]).add(o).add(n),i(p.x,p.y,p.z)):i(R.x,R.y,q/w*ba);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){var f=b.vertices,g=f[c],h=f[d],i=f[e];return[new a.Vector2(g.x,g.y),new a.Vector2(h.x,h.y),new a.Vector2(i.x,i.y)]},generateSideWallUV:function(b,c,d,e,f){var g=b.vertices,h=g[c],i=g[d],j=g[e],k=g[f];return Math.abs(h.y-i.y)<.01?[new a.Vector2(h.x,1-h.z),new a.Vector2(i.x,1-i.z),new a.Vector2(j.x,1-j.z),new a.Vector2(k.x,1-k.z)]:[new a.Vector2(h.y,1-h.z),new a.Vector2(i.y,1-i.z),new a.Vector2(j.y,1-j.z),new a.Vector2(k.y,1-k.z)]}},a.ShapeGeometry=function(b,c){a.Geometry.call(this),this.type="ShapeGeometry",b instanceof Array==!1&&(b=[b]),this.addShapeList(b,c),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.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.generateTopUV(this,u,v,w))}},a.LatheGeometry=function(b,c,d,e){a.Geometry.call(this),this.type="LatheGeometry",this.parameters={points:b,segments:c,phiStart:d,phiLength:e},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.computeFaceNormals(),this.computeVertexNormals()},a.LatheGeometry.prototype=Object.create(a.Geometry.prototype),a.PlaneGeometry=function(b,c,d,e){console.info("THREE.PlaneGeometry: Consider using THREE.PlaneBufferGeometry for lower memory footprint."),a.Geometry.call(this),this.type="PlaneGeometry",this.parameters={width:b,height:c,widthSegments:d,heightSegments:e},this.fromBufferGeometry(new a.PlaneBufferGeometry(b,c,d,e))},a.PlaneGeometry.prototype=Object.create(a.Geometry.prototype),a.PlaneBufferGeometry=function(b,c,d,e){a.BufferGeometry.call(this),this.type="PlaneBufferGeometry",this.parameters={width:b,height:c,widthSegments:d,heightSegments:e};for(var f=b/2,g=c/2,h=d||1,i=e||1,j=h+1,k=i+1,l=b/h,m=c/i,n=new Float32Array(j*k*3),o=new Float32Array(j*k*3),p=new Float32Array(j*k*2),q=0,r=0,s=0;k>s;s++)for(var t=s*m-g,u=0;j>u;u++){var v=u*l-f;n[q]=v,n[q+1]=-t,o[q+2]=1,p[r]=u/h,p[r+1]=1-s/i,q+=3,r+=2}q=0;for(var w=new(n.length/3>65535?Uint32Array:Uint16Array)(h*i*6),s=0;i>s;s++)for(var u=0;h>u;u++){var x=u+j*s,y=u+j*(s+1),z=u+1+j*(s+1),A=u+1+j*s;w[q]=x,w[q+1]=y,w[q+2]=A,w[q+3]=y,w[q+4]=z,w[q+5]=A,q+=6}this.addAttribute("index",new a.BufferAttribute(w,1)),this.addAttribute("position",new a.BufferAttribute(n,3)),this.addAttribute("normal",new a.BufferAttribute(o,3)),this.addAttribute("uv",new a.BufferAttribute(p,2))},a.PlaneBufferGeometry.prototype=Object.create(a.BufferGeometry.prototype),a.RingGeometry=function(b,c,d,e,f,g){a.Geometry.call(this),this.type="RingGeometry",this.parameters={innerRadius:b,outerRadius:c,thetaSegments:d,phiSegments:e,thetaStart:f,thetaLength:g},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(1,e):8;var h,i,j=[],k=b,l=(c-b)/e;for(h=0;e+1>h;h++){for(i=0;d+1>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+1);for(i=0;d>i;i++){var n=i+p,q=n,r=n+d+1,s=n+d+2;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,r=n+d+2,s=n+1,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.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.type="SphereGeometry",this.parameters={radius:b,widthSegments:c,heightSegments:d,phiStart:e,phiLength:f,thetaStart:g,thetaLength:h},b=b||50,c=Math.max(3,Math.floor(c)||8),d=Math.max(2,Math.floor(d)||6),e=void 0!==e?e:0,f=void 0!==f?f:2*Math.PI,g=void 0!==g?g:0,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;d>j;j++)for(i=0;c>i;i++){var r=k[j][i+1],s=k[j][i],t=k[j+1][i],u=k[j+1][i+1],v=this.vertices[r].clone().normalize(),w=this.vertices[s].clone().normalize(),x=this.vertices[t].clone().normalize(),y=this.vertices[u].clone().normalize(),z=l[j][i+1].clone(),A=l[j][i].clone(),B=l[j+1][i].clone(),C=l[j+1][i+1].clone();Math.abs(this.vertices[r].y)===b?(z.x=(z.x+A.x)/2,this.faces.push(new a.Face3(r,t,u,[v,x,y])),this.faceVertexUvs[0].push([z,B,C])):Math.abs(this.vertices[t].y)===b?(B.x=(B.x+C.x)/2,this.faces.push(new a.Face3(r,s,t,[v,w,x])),this.faceVertexUvs[0].push([z,A,B])):(this.faces.push(new a.Face3(r,s,u,[v,w,y])),this.faceVertexUvs[0].push([z,A,C]),this.faces.push(new a.Face3(s,t,u,[w.clone(),x,y.clone()])),this.faceVertexUvs[0].push([A.clone(),B,C.clone()]))}this.computeFaceNormals(),this.boundingSphere=new a.Sphere(new a.Vector3,b)},a.SphereGeometry.prototype=Object.create(a.Geometry.prototype),a.TextGeometry=function(b,c){c=c||{};var d=a.FontUtils.generateShapes(b,c);c.amount=void 0!==c.height?c.height:50,void 0===c.bevelThickness&&(c.bevelThickness=10),void 0===c.bevelSize&&(c.bevelSize=8),void 0===c.bevelEnabled&&(c.bevelEnabled=!1),a.ExtrudeGeometry.call(this,d,c),this.type="TextGeometry"},a.TextGeometry.prototype=Object.create(a.ExtrudeGeometry.prototype),a.TorusGeometry=function(b,c,d,e,f){a.Geometry.call(this),this.type="TorusGeometry",this.parameters={radius:b,tube:c,radialSegments:d,tubularSegments:e,arc:f},b=b||100,c=c||40,d=d||8,e=e||6,f=f||2*Math.PI;for(var g=new a.Vector3,h=[],i=[],j=0;d>=j;j++)for(var k=0;e>=k;k++){var l=k/e*f,m=j/d*Math.PI*2;g.x=b*Math.cos(l),g.y=b*Math.sin(l);var n=new a.Vector3;n.x=(b+c*Math.cos(m))*Math.cos(l),n.y=(b+c*Math.cos(m))*Math.sin(l),n.z=c*Math.sin(m),this.vertices.push(n),h.push(new a.Vector2(k/e,j/d)),i.push(n.clone().sub(g).normalize())}for(var j=1;d>=j;j++)for(var k=1;e>=k;k++){var o=(e+1)*j+k-1,p=(e+1)*(j-1)+k-1,q=(e+1)*(j-1)+k,r=(e+1)*j+k,s=new a.Face3(o,p,r,[i[o].clone(),i[p].clone(),i[r].clone()]);this.faces.push(s),this.faceVertexUvs[0].push([h[o].clone(),h[p].clone(),h[r].clone()]),s=new a.Face3(p,q,r,[i[p].clone(),i[q].clone(),i[r].clone()]),this.faces.push(s),this.faceVertexUvs[0].push([h[p].clone(),h[q].clone(),h[r].clone()])}this.computeFaceNormals()},a.TorusGeometry.prototype=Object.create(a.Geometry.prototype),a.TorusKnotGeometry=function(b,c,d,e,f,g,h){function i(b,c,d,e,f){var g=Math.cos(b),h=Math.sin(b),i=c/d*b,j=Math.cos(i),k=e*(2+j)*.5*g,l=e*(2+j)*h*.5,m=f*e*Math.sin(i)*.5;return new a.Vector3(k,l,m)}a.Geometry.call(this),this.type="TorusKnotGeometry",this.parameters={radius:b,tube:c,radialSegments:d,tubularSegments:e,p:f,q:g,heightScale:h},b=b||100,c=c||40,d=d||64,e=e||8,f=f||2,g=g||3,h=h||1;for(var j=new Array(d),k=new a.Vector3,l=new a.Vector3,m=new a.Vector3,n=0;d>n;++n){j[n]=new Array(e);var o=n/d*2*f*Math.PI,p=i(o,g,f,b,h),q=i(o+.01,g,f,b,h);k.subVectors(q,p),l.addVectors(q,p),m.crossVectors(k,l),l.crossVectors(m,k),m.normalize(),l.normalize();for(var r=0;e>r;++r){var s=r/e*2*Math.PI,t=-c*Math.cos(s),u=c*Math.sin(s),v=new a.Vector3;v.x=p.x+t*l.x+u*m.x,v.y=p.y+t*l.y+u*m.y,v.z=p.z+t*l.z+u*m.z,j[n][r]=this.vertices.push(v)-1}}for(var n=0;d>n;++n)for(var r=0;e>r;++r){var w=(n+1)%d,x=(r+1)%e,y=j[n][r],z=j[w][r],A=j[w][x],B=j[n][x],C=new a.Vector2(n/d,r/e),D=new a.Vector2((n+1)/d,r/e),E=new a.Vector2((n+1)/d,(r+1)/e),F=new a.Vector2(n/d,(r+1)/e);this.faces.push(new a.Face3(y,z,B)),this.faceVertexUvs[0].push([C,D,F]),this.faces.push(new a.Face3(z,A,B)),this.faceVertexUvs[0].push([D.clone(),E,F.clone()])}this.computeFaceNormals(),this.computeVertexNormals()},a.TorusKnotGeometry.prototype=Object.create(a.Geometry.prototype),a.TubeGeometry=function(b,c,d,e,f){function g(b,c,d){return C.vertices.push(new a.Vector3(b,c,d))-1}a.Geometry.call(this),this.type="TubeGeometry",this.parameters={path:b,segments:c,radius:d,radialSegments:e,closed:f},c=c||64,d=d||1,e=e||8,f=f||!1;var h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B=[],C=this,D=c+1,E=new a.Vector3,F=new a.TubeGeometry.FrenetFrames(b,c,f),G=F.tangents,H=F.normals,I=F.binormals;for(this.tangents=G,this.normals=H,this.binormals=I,p=0;D>p;p++)for(B[p]=[],k=p/(D-1),o=b.getPointAt(k),h=G[p],i=H[p],j=I[p],q=0;e>q;q++)l=q/e*2*Math.PI,m=-d*Math.cos(l),n=d*Math.sin(l),E.copy(o),E.x+=m*i.x+n*j.x,E.y+=m*i.y+n*j.y,E.z+=m*i.z+n*j.z,B[p][q]=g(E.x,E.y,E.z);for(p=0;c>p;p++)for(q=0;e>q;q++)r=f?(p+1)%c:p+1,s=(q+1)%e,t=B[p][q],u=B[r][q],v=B[r][s],w=B[p][s],x=new a.Vector2(p/c,q/e),y=new a.Vector2((p+1)/c,q/e),z=new a.Vector2((p+1)/c,(q+1)/e),A=new a.Vector2(p/c,(q+1)/e),this.faces.push(new a.Face3(t,u,w)),this.faceVertexUvs[0].push([x,y,A]),this.faces.push(new a.Face3(u,v,w)),this.faceVertexUvs[0].push([y.clone(),z,A.clone()]);this.computeFaceNormals(),this.computeVertexNormals()},a.TubeGeometry.prototype=Object.create(a.Geometry.prototype),a.TubeGeometry.FrenetFrames=function(b,c,d){function e(){o[0]=new a.Vector3,p[0]=new a.Vector3,g=Number.MAX_VALUE,h=Math.abs(n[0].x),i=Math.abs(n[0].y),j=Math.abs(n[0].z),g>=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()]);l.faces.push(e),u.copy(b).add(c).add(d).divideScalar(3);var f=i(u);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++)0==o&&j==c?i[j][o]=k:i[j][o]=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),this.type="PolyhedronGeometry",this.parameters={vertices:b,indices:c,radius:d,detail:e},d=d||1,e=e||0;for(var l=this,m=0,n=b.length;n>m;m+=3)f(new a.Vector3(b[m],b[m+1],b[m+2]));for(var o=this.vertices,p=[],m=0,q=0,n=c.length;n>m;m+=3,q++){var r=o[c[m]],s=o[c[m+1]],t=o[c[m+2]];p[q]=new a.Face3(r.index,s.index,t.index,[r.clone(),s.clone(),t.clone()])}for(var u=new a.Vector3,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 v=this.faceVertexUvs[0][m],w=v[0].x,x=v[1].x,y=v[2].x,z=Math.max(w,Math.max(x,y)),A=Math.min(w,Math.min(x,y));z>.9&&.1>A&&(.2>w&&(v[0].x+=1),.2>x&&(v[1].x+=1),.2>y&&(v[2].x+=1))}for(var m=0,n=this.vertices.length;n>m;m++)this.vertices[m].multiplyScalar(d);this.mergeVertices(),this.computeFaceNormals(),this.boundingSphere=new a.Sphere(new a.Vector3,d)},a.PolyhedronGeometry.prototype=Object.create(a.Geometry.prototype),a.DodecahedronGeometry=function(b,c){this.parameters={radius:b,detail:c};var d=(1+Math.sqrt(5))/2,e=1/d,f=[-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-e,-d,0,-e,d,0,e,-d,0,e,d,-e,-d,0,-e,d,0,e,-d,0,e,d,0,-d,0,-e,d,0,-e,-d,0,e,d,0,e],g=[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9];a.PolyhedronGeometry.call(this,f,g,b,c)},a.DodecahedronGeometry.prototype=Object.create(a.Geometry.prototype),a.IcosahedronGeometry=function(b,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),this.type="IcosahedronGeometry",this.parameters={radius:b,detail:c}},a.IcosahedronGeometry.prototype=Object.create(a.Geometry.prototype),a.OctahedronGeometry=function(b,c){this.parameters={radius:b,detail: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),this.type="OctahedronGeometry",this.parameters={radius:b,detail: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),this.type="TetrahedronGeometry",this.parameters={radius:b,detail:c}},a.TetrahedronGeometry.prototype=Object.create(a.Geometry.prototype),a.ParametricGeometry=function(b,c,d){a.Geometry.call(this),this.type="ParametricGeometry",this.parameters={func:b,slices:c,stacks:d};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.computeFaceNormals(),this.computeVertexNormals()},a.ParametricGeometry.prototype=Object.create(a.Geometry.prototype),a.AxisHelper=function(b){b=b||1;var c=new Float32Array([0,0,0,b,0,0,0,0,0,0,b,0,0,0,0,0,0,b]),d=new Float32Array([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1]),e=new a.BufferGeometry;e.addAttribute("position",new a.BufferAttribute(c,3)),e.addAttribute("color",new a.BufferAttribute(d,3));var f=new a.LineBasicMaterial({vertexColors:a.VertexColors});a.Line.call(this,e,f,a.LinePieces)},a.AxisHelper.prototype=Object.create(a.Line.prototype),a.ArrowHelper=function(){var b=new a.Geometry;b.vertices.push(new a.Vector3(0,0,0),new a.Vector3(0,1,0));var c=new a.CylinderGeometry(0,.5,1,5,1);return c.applyMatrix((new a.Matrix4).makeTranslation(0,-.5,0)),function(d,e,f,g,h,i){a.Object3D.call(this),void 0===g&&(g=16776960),void 0===f&&(f=1),void 0===h&&(h=.2*f),void 0===i&&(i=.2*h),this.position.copy(e),this.line=new a.Line(b,new a.LineBasicMaterial({color:g})),this.line.matrixAutoUpdate=!1,this.add(this.line),this.cone=new a.Mesh(c,new a.MeshBasicMaterial({color:g})),this.cone.matrixAutoUpdate=!1,this.add(this.cone),this.setDirection(d),this.setLength(f,h,i)}}(),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.set(a),this.cone.material.color.set(a)},a.BoxHelper=function(b){var c=new a.BufferGeometry;c.addAttribute("position",new a.BufferAttribute(new Float32Array(72),3)),a.Line.call(this,c,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.geometry.attributes.position.array;e[0]=d.x,e[1]=d.y,e[2]=d.z,e[3]=c.x,e[4]=d.y,e[5]=d.z,e[6]=c.x,e[7]=d.y,e[8]=d.z,e[9]=c.x,e[10]=c.y,e[11]=d.z,e[12]=c.x,e[13]=c.y,e[14]=d.z,e[15]=d.x,e[16]=c.y,e[17]=d.z,e[18]=d.x,e[19]=c.y,e[20]=d.z,e[21]=d.x,e[22]=d.y,e[23]=d.z,e[24]=d.x,e[25]=d.y,e[26]=c.z,e[27]=c.x,e[28]=d.y,e[29]=c.z,e[30]=c.x,e[31]=d.y,e[32]=c.z,e[33]=c.x,e[34]=c.y,e[35]=c.z,e[36]=c.x,e[37]=c.y,e[38]=c.z,e[39]=d.x,e[40]=c.y,e[41]=c.z,e[42]=d.x,e[43]=c.y,e[44]=c.z,e[45]=d.x,e[46]=d.y,e[47]=c.z,e[48]=d.x,e[49]=d.y,e[50]=d.z,e[51]=d.x,e[52]=d.y,e[53]=c.z,e[54]=c.x,e[55]=d.y,e[56]=d.z,e[57]=c.x,e[58]=d.y,e[59]=c.z,e[60]=c.x,e[61]=c.y,e[62]=d.z,e[63]=c.x,e[64]=c.y,e[65]=c.z,e[66]=d.x,e[67]=c.y,e[68]=d.z,e[69]=d.x,e[70]=c.y,e[71]=c.z,this.geometry.attributes.position.needsUpdate=!0,this.geometry.computeBoundingSphere(),this.matrix=a.matrixWorld,this.matrixAutoUpdate=!1},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.matrix=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,c,d=new a.Vector3,e=new a.Camera,f=function(a,f,g,h){d.set(f,g,h).unproject(e);var i=c[a];if(void 0!==i)for(var j=0,k=i.length;k>j;j++)b.vertices[i[j]].copy(d)};return function(){b=this.geometry,c=this.pointMap;var a=1,d=1;e.projectionMatrix.copy(this.camera.projectionMatrix),f("c",0,0,-1),f("t",0,0,1),f("n1",-a,-d,-1),f("n2",a,-d,-1),f("n3",-a,d,-1),f("n4",a,d,-1),f("f1",-a,-d,1),f("f2",a,-d,1),f("f3",-a,d,1),f("f4",a,d,1),f("u1",.7*a,1.1*d,-1),f("u2",.7*-a,1.1*d,-1),f("u3",0,2*d,-1),f("cf1",-a,0,1),f("cf2",a,0,1),f("cf3",0,-d,1),f("cf4",0,d,1),f("cn1",-a,0,-1),f("cn2",a,0,-1),f("cn3",0,-d,-1),f("cn4",0,d,-1),b.verticesNeedUpdate=!0}}(),a.DirectionalLightHelper=function(b,c){a.Object3D.call(this),this.light=b,this.light.updateMatrixWorld(),this.matrix=b.matrixWorld,this.matrixAutoUpdate=!1,c=c||1;var d=new a.Geometry;d.vertices.push(new a.Vector3(-c,c,0),new a.Vector3(c,c,0),new a.Vector3(c,-c,0),new a.Vector3(-c,-c,0),new a.Vector3(-c,c,0));var e=new a.LineBasicMaterial({fog:!1});e.color.copy(this.light.color).multiplyScalar(this.light.intensity),this.lightPlane=new a.Line(d,e),this.add(this.lightPlane),d=new a.Geometry,d.vertices.push(new a.Vector3,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}var s=new Float32Array(2*m*3),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}}i.addAttribute("position",new a.BufferAttribute(s,3)),a.Line.call(this,i,new a.LineBasicMaterial({color:d}),a.LinePieces),this.matrix=b.matrixWorld,this.matrixAutoUpdate=!1},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,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 a=this.geometry.vertices,b=this.object,c=b.geometry.vertices,d=b.geometry.faces,e=b.matrixWorld;b.updateMatrixWorld(!0),this.normalMatrix.getNormalMatrix(e);for(var f=0,g=0,h=d.length;h>f;f++,g+=2){var i=d[f];a[g].copy(c[i.a]).add(c[i.b]).add(c[i.c]).divideScalar(3).applyMatrix4(e),a[g+1].copy(i.normal).applyMatrix3(this.normalMatrix).normalize().multiplyScalar(this.size).add(a[g])}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,d,e){a.Object3D.call(this),this.light=b,this.light.updateMatrixWorld(),this.matrix=b.matrixWorld,this.matrixAutoUpdate=!1,this.colors=[new a.Color,new a.Color];var f=new a.SphereGeometry(c,4,2);f.applyMatrix((new a.Matrix4).makeRotationX(-Math.PI/2));for(var g=0,h=8;h>g;g++)f.faces[g].color=this.colors[4>g?0:1];var i=new a.MeshBasicMaterial({vertexColors:a.FaceColors,wireframe:!0});this.lightSphere=new a.Mesh(f,i),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.matrix=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.SkeletonHelper=function(b){this.bones=this.getBoneList(b);for(var c=new a.Geometry,d=0;dj;j++)for(var l=i[j],m=0,n=l.vertexNormals.length;n>m;m++)h.vertices.push(new a.Vector3,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(b){var c=new a.Vector3;return function(a){var b=["a","b","c","d"];this.object.updateMatrixWorld(!0),this.normalMatrix.getNormalMatrix(this.object.matrixWorld);for(var d=this.geometry.vertices,e=this.object.geometry.vertices,f=this.object.geometry.faces,g=this.object.matrixWorld,h=0,i=0,j=f.length;j>i;i++)for(var k=f[i],l=0,m=k.vertexNormals.length;m>l;l++){var n=k[b[l]],o=e[n],p=k.vertexNormals[l];d[h].copy(o).applyMatrix4(g),c.copy(p).applyMatrix3(this.normalMatrix).normalize().multiplyScalar(this.size),c.add(d[h]),h+=1,d[h].copy(c),h+=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(b){var c=new a.Vector3;return function(a){var b=["a","b","c","d"];this.object.updateMatrixWorld(!0);for(var d=this.geometry.vertices,e=this.object.geometry.vertices,f=this.object.geometry.faces,g=this.object.matrixWorld,h=0,i=0,j=f.length;j>i;i++)for(var k=f[i],l=0,m=k.vertexTangents.length;m>l;l++){var n=k[b[l]],o=e[n],p=k.vertexTangents[l];d[h].copy(o).applyMatrix4(g),c.copy(p).transformDirection(g).multiplyScalar(this.size),c.add(d[h]),h+=1,d[h].copy(c),h+=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++)}for(var s=new Float32Array(2*l*3),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}i.addAttribute("position",new a.BufferAttribute(s,3))}else if(b.geometry instanceof a.BufferGeometry)if(void 0!==b.geometry.attributes.index){var j=b.geometry.attributes.position.array,v=b.geometry.attributes.index.array,w=b.geometry.drawcalls,l=0;0===w.length&&(w=[{count:v.length,index:0,start:0}]);for(var 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++)}for(var s=new Float32Array(2*l*3),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]}i.addAttribute("position",new a.BufferAttribute(s,3))}else{for(var j=b.geometry.attributes.position.array,l=j.length/3,D=l/3,s=new Float32Array(2*l*3),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]}i.addAttribute("position",new a.BufferAttribute(s,3))}a.Line.call(this,i,new a.LineBasicMaterial({color:d}),a.LinePieces),this.matrix=b.matrixWorld,this.matrixAutoUpdate=!1},a.WireframeHelper.prototype=Object.create(a.Line.prototype),a.ImmediateRenderObject=function(){a.Object3D.call(this),this.render=function(a){}},a.ImmediateRenderObject.prototype=Object.create(a.Object3D.prototype),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}}}}(),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===d?a.marker.material.color.setHex(e):a.marker.material.color.setHex(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++){if(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,BrainBrowser.WEBGL_UINT_INDEX_ENABLED){for(h=0;hh;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,e=[];a.updateColors=function(f){function g(c){var d,f=a.model.getObjectByName(l,!0);d=f?[f]:a.model.children.filter(function(a){return!!a.userData.original_data}),b(c,d),e.forEach(function(a){a()}),e.length=0,a.triggerEvent("updatecolors",{model_data:m,intensity_data:h,colors:c,blend:i}),i&&a.triggerEvent("blendcolors",{model_data:m,intensity_data:h,colors:c})}f=f||{};var h,i,j=f.complete,k=f.model_name,l=f.shape_name||k+"_1",m=a.model_data.get(k);BrainBrowser.utils.isFunction(j)&&e.push(j),m.intensity_data.length>1?(h=m.intensity_data,i=!0):(h=m.intensity_data[0],i=!1),clearTimeout(d),d=setTimeout(function(){g(i?c(h,f.model_name):a.color_map.mapColors(h.values,{min:h.range_min,max:h.range_max,default_colors:a.model_data.get(f.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,g=b+"_model";if(!n.worker_urls[g])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 h,i=new Worker(n.worker_urls[g]);i.addEventListener("message",function(a){var g,j=a.data;if(j.error)throw e="error parsing model.\n"+j.error_message+"\nFile type: "+b+"\nOptions: "+JSON.stringify(c),BrainBrowser.events.triggerEvent("error",{message:e}),new Error(e);j.colors=j.colors||new Float32Array([.7,.7,.7,1]),BrainBrowser.WEBGL_UINT_INDEX_ENABLED?f(j,d):(h=new Worker(n.worker_urls.deindex),h.addEventListener("message",function(a){d(a.data)}),g=[j.vertices.buffer],j.normals&&g.push(j.normals.buffer),j.colors&&g.push(j.colors.buffer),j.shapes.forEach(function(a){g.push(a.indices.buffer)}),h.postMessage(j,g)),i.terminate()}),i.postMessage({data:a,options:c})}function f(a,b){var c=a.vertices;4===a.colors.length&&(a.colors=g(a.colors,c.length/3)),k(a),b(a)}function g(a,b){var c,d,e,f,g,h,i;for(g=new Float32Array(4*b),c=a[0],d=a[1],e=a[2],f=a[3],h=0,i=g.length;i>h;h+=4)g[h]=c,g[h+1]=d,g[h+2]=e,g[h+3]=f;return g}function h(b,c,d){d=d||{};var e=d.complete,f=i(b,c,d);a.triggerEvent("displaymodel",{model:a.model,model_data:b,new_shapes:f}),e&&e()}function i(b,c,d){var e,f,g,h,i,k,m,n=a.model,p=b.shapes,q="line"===b.type,r=d.render_depth,s=d.pick_ignore,t=d.recenter||b.split,u=[],v={is_line:q};if(BrainBrowser.WEBGL_UINT_INDEX_ENABLED&&(i=new o.BufferAttribute(new Float32Array(b.vertices),3),b.normals&&(k=new o.BufferAttribute(new Float32Array(b.normals),3)),b.colors&&(m=new o.BufferAttribute(new Float32Array(b.colors),4))),b.name=b.name||c,a.model_data.add(b.name,b),p){for(g=0,h=p.length;h>g;g++)f=b.shapes[g],0!==f.indices.length&&(BrainBrowser.WEBGL_UINT_INDEX_ENABLED?(l(m.array,f.color,f.indices),v={position:i,normal:k,color:m,index:new o.BufferAttribute(new Uint32Array(f.indices),1)}):(i=k=m=null,i=new o.BufferAttribute(new Float32Array(f.unindexed.position),3),f.unindexed.normal&&(k=new o.BufferAttribute(new Float32Array(f.unindexed.normal),3)),f.unindexed.color&&(m=new o.BufferAttribute(new Float32Array(f.unindexed.color),4)),v={position:i,normal:k,color:m}),v.is_line=q,v.centroid=f.centroid,v.recenter=t,e=j(v),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=s,r&&(e.renderDepth=r),u.push(e),n.add(e));b.split&&(n.children[0].name="left",n.children[1].name="right")}return u}function j(a){var b,c,d,e,f,g,h,i=a.position,j=i.array,k=a.normal,l=a.color,m=a.index,n=a.centroid,p=a.is_line,q=a.recenter,r=new o.BufferGeometry;if(r.dynamic=!0,q)if(m)for(b=m.array,c=new Float32Array(j),g=0,h=b.length;h>g;g++)d=3*b[g],j[d]=c[d]-n.x,j[d+1]=c[d+1]-n.y,j[d+2]=c[d+2]-n.z;else for(g=0,h=j.length;h>g;g+=3)j[g]-=n.x,j[g+1]-=n.y,j[g+2]-=n.z;return r.addAttribute("position",i),m&&r.addAttribute("index",m),k?r.addAttribute("normal",k):r.computeVertexNormals(),l&&r.addAttribute("color",l),p?(e=new o.LineBasicMaterial({vertexColors:o.VertexColors}),f=new o.Line(r,e,o.LinePieces)):(e=new o.MeshPhongMaterial({color:16777215,ambient:16777215,specular:1052688,shininess:150,vertexColors:o.VertexColors}),f=new o.Mesh(r,e),f.userData.has_wireframe=!0),f.userData.centroid=n,q&&(f.userData.recentered=!0,f.position.set(n.x,n.y,n.z)),f}function k(a){var b,c,d,e,f,g,h=a.vertices;a.shapes.forEach(function(a){var i,j,k,l,m,n,o=a.indices;for(b=d=f=Number.POSITIVE_INFINITY,c=e=g=Number.NEGATIVE_INFINITY,m=0,n=o.length;n>m;m++)i=o[m],j=h[3*i],k=h[3*i+1],l=h[3*i+2],b=Math.min(b,j),d=Math.min(d,k),f=Math.min(f,l),c=Math.max(c,j),e=Math.max(e,k),g=Math.max(g,l);a.bounding_box={min_x:b,min_y:d,min_z:f,max_x:c,max_y:e,max_z:g},a.centroid={x:b+(c-b)/2,y:d+(e-d)/2,z:f+(g-f)/2}})}function l(a,b,c){if(b){var d,e,f,g,h,i,j,k=4===b.length;for(d=b[0],e=b[1],f=b[2],g=b[3],h=0,j=c.length;j>h;h++)k||(i=4*h,d=b[i],e=b[i+1],f=b[i+2],g=b[i+3]),i=4*c[h],a[i]=d,a[i+1]=e,a[i+2]=f,a[i+3]=g}}function m(a,b){b=b||{};var c=b.format||"mniobj",d=BrainBrowser.config.get(a+"."+c);return d&&d.binary&&(b.result_type=b.result_type||"arraybuffer"),b}var n=BrainBrowser.SurfaceViewer,o=n.THREE,p=BrainBrowser.loader,q={};a.model_data={add:function(a,b){q[a]=b,b.intensity_data=[]},get:function(a){return a=a||Object.keys(q)[0],q[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(q).map(function(a){return q[a]}),d=0,e=b.length;e>d&&!(c=b[d].intensity_data[0]);d++);return c||null},count:function(){return Object.keys(q).length},clear:function(){q={}},forEach:function(a){Object.keys(q).forEach(function(b){a(q[b],b)})}},a.loadModelFromURL=function(a,c){c=m("model_types",c),p.loadFromURL(a,b,c)},a.loadModelFromFile=function(a,c){c=m("model_types",c),p.loadFromFile(a,b,c)},a.loadIntensityDataFromURL=function(a,b){b=m("intensity_data_types",b),p.loadFromURL(a,c,b)},a.loadIntensityDataFromFile=function(a,b){b=m("intensity_data_types",b),p.loadFromFile(a,c,b)},a.loadColorMapFromURL=function(a,b){p.loadColorMapFromURL(a,d,b)},a.loadColorMapFromFile=function(a,b){p.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,alpha:!0,autoClear:!1}),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.getCameraPosition=function(){return i.position},a.resetView=function(){var b=a.model,c=new f.Matrix4;c.getInverse(b.matrix),b.applyMatrix(c),i.position.set(0,0,j),k.position.set(0,0,j);var d=b.userData.model_center_offset||new f.Vector3(0,0,0);b.children.forEach(function(a){var b=a.userData.centroid,c=a.userData.recentered;a.userData.original_data&&(b&&c?a.position.set(b.x+d.x,b.y+d.y,b.z+d.z):a.position.set(d.x,d.y,d.z),a.rotation.set(0,0,0),a.material.opacity=1)}),b.rotation.set(0,0,0),a.zoom=1,a.updated=!0},a.setClearColor=function(b,c){void 0===c&&(c=1),g.setClearColor(b,c),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);if(k.position.set(b,c,d),a.model){var l=a.model.userData.model_center_offset,m=a.model.userData.model_centric;void 0!==l&&m===!0&&(k.translateX(l.x),k.translateY(l.y),k.translateZ(l.z)),a.model.add(k)}else h.add(k);return a.updated=!0,k},a.drawGrid=function(b,c,d){d=d||{};var e=d.name,g=d.color_center_line,i=d.color_grid,j=d.x,k=d.y,l=d.z,m=d.euler_rotation;(void 0===b||0>=b)&&(b=100),(void 0===c||0>=c)&&(c=10),g=g>=0?g:4473924,i=i>=0?i:8947848,j=j||0,k=k||0,l=l||0;var n=new f.GridHelper(b,c);return n.name=e,n.setColors(g,i),n.position.set(j,k,l),void 0!==m&&n.setRotationFromEuler(m),a.model?a.model.add(n):h.add(n),a.updated=!0,n},a.drawLine=function(b,c,d){d=d||{};var e=d.color>=0?d.color:4473924,g=new f.Geometry;g.vertices.push(b.clone()),g.vertices.push(c.clone()),g.computeLineDistances();var i=d.dashed===!0?new f.LineDashedMaterial({linewidth:3,color:e,gapSize:3}):new f.LineBasicMaterial({linewidth:3,color:e}),j=new f.Line(g,i,f.LinePieces);return d.draw===!1?j:(a.model?a.model.add(j):h.add(j),a.updated=!0,j)},a.drawAxes=function(b,c){b=b||300,c=c||{};var d=c.name||"axes",e=c.center||new f.Vector3(0,0,0),g=c.x_color>=0?c.x_color:16711680,i=c.y_color>=0?c.y_color:65280,j=c.z_color>=0?c.z_color:255,k=c.complete===!0,l=new f.Object3D;return l.name=d,l.add(a.drawLine(e,new f.Vector3(b,0,0),{color:g,dashed:!1,draw:!1})),k&&l.add(a.drawLine(e,new f.Vector3(-b,0,0),{color:g,dashed:!0,draw:!1})),l.add(a.drawLine(e,new f.Vector3(0,b,0),{color:i,dashed:!1,draw:!1})),k&&l.add(a.drawLine(e,new f.Vector3(0,-b,0),{color:i,dashed:!0,draw:!1})),l.add(a.drawLine(e,new f.Vector3(0,0,b),{color:j,dashed:!1,draw:!1})),k&&l.add(a.drawLine(e,new f.Vector3(0,0,-b),{color:j,dashed:!0,draw:!1})),a.model?a.model.add(l):h.add(l),a.updated=!0,l},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,z=a.model,A=new f.Raycaster,B=new f.Vector3(b,c,i.near),C=null,D=new f.Matrix4;
+for(B.unproject(i),A.set(i.position,B.sub(i.position).normalize()),d=A.intersectObject(z,!0),t=0;tt;t++)q=j[t],BrainBrowser.WEBGL_UINT_INDEX_ENABLED||(q=p[q]),r=new f.Vector3(o[3*q],o[3*q+1],o[3*q+2]),s=h.distanceTo(new f.Vector3(r.x-w,r.y-x,r.z-y)),n>s&&(l=q,m=r,n=s);e={index:l,point:m,object:g}}else e=null;return e},a.modelCentric=function(b){void 0===b&&(b=!1);var c=a.model;if(a.findUserDataCentroid(c),b!==c.userData.model_centric){var d=new f.Vector3;d.copy(c.userData.model_center_offset),b===!1&&d.negate(),c.children.forEach(function(a){(0!==Object.keys(a.userData).length||a.userData.constructor!==Object)&&(a.translateX(d.x),a.translateY(d.y),a.translateZ(d.z))}),c.userData.model_centric=b,a.updated=!0}},a.findUserDataCentroid=function(b){if(void 0===b.userData.model_center_offset){var c,d,e,g,h,i;c=e=h=Number.POSITIVE_INFINITY,d=g=i=Number.NEGATIVE_INFINITY,b.children.forEach(function(j){var k=j.userData.model_name,l=a.model_data.get(k),m=j.name;l.shapes.forEach(function(a){if(a.name===m){var b=a.bounding_box;c=Math.min(c,b.min_x),e=Math.min(e,b.min_y),h=Math.min(h,b.min_z),d=Math.max(d,b.max_x),g=Math.max(g,b.max_y),i=Math.max(i,b.max_z)}});var n=new f.Vector3;n.x=c+(d-c)/2,n.y=e+(g-e)/2,n.z=h+(i-h)/2,b.userData.model_center_offset=new f.Vector3(-n.x,-n.y,-n.z)})}},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){a.userData.creating_wireframe=!0,f>g?c(a,d):setTimeout(function(){b(a,d)},0)}function c(a,b){var c,d=new Worker(BrainBrowser.SurfaceViewer.worker_urls.wireframe),f=a.geometry.attributes;d.addEventListener("message",function(c){var h,i,j,k,l=new e.BufferGeometry;j=c.data.positions?new e.BufferAttribute(c.data.positions,3):f.position,k=c.data.colors?new e.BufferAttribute(c.data.colors,4):f.color,l.addAttribute("position",j),l.addAttribute("color",k),c.data.indices&&l.addAttribute("index",new e.BufferAttribute(c.data.indices,1)),l.attributes.color.needsUpdate=!0,h=new e.LineBasicMaterial({vertexColors:e.VertexColors}),i=new e.Line(l,h,e.LinePieces),i.name="__WIREFRAME__",i.material.visible=!1,a.add(i),a.creating_wireframe=!1,g--,b(i),d.terminate()}),c=BrainBrowser.WEBGL_UINT_INDEX_ENABLED?{indices:f.index.array}:{positions:f.position.array,colors:f.color.array},d.postMessage(c),g++}function d(b,c,d){b.material.visible=!d,c.material.visible=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):(c.rotation.x+=Math.PI/2,c.rotation.y+=Math.PI,c.rotation.z+=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):(e.rotation.x+=Math.PI/2,e.rotation.y+=Math.PI,e.rotation.z-=Math.PI/2)},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,1===b||b>1?e.transparent=!1:e.transparent=!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.userData.has_wireframe&&!a.userData.creating_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.5.0/brainbrowser.volume-viewer.min.js b/build/brainbrowser-2.5.0/brainbrowser.volume-viewer.min.js
index c7d42d0b..9c8e3ef8 100644
--- a/build/brainbrowser-2.5.0/brainbrowser.volume-viewer.min.js
+++ b/build/brainbrowser-2.5.0/brainbrowser.volume-viewer.min.js
@@ -29,6 +29,7 @@
*
* three.js (c) 2010-2014 three.js authors, used under the MIT license
*/
-!function(){"use strict";function a(a){var b=!1,c=!1,d=!1,e=!1,f=document.createElement("canvas"),g=null;b=!!f,c=!!window.Worker;try{f&&window.WebGLRenderingContext&&(g=f.getContext("webgl")||f.getContext("experimental-webgl")),d=!!g}catch(h){d=!1}d&&(e=!!g.getExtension("OES_element_index_uint")),a.CANVAS_ENABLED=b,a.WEB_WORKERS_ENABLED=c,a.WEBGL_ENABLED=d,a.WEBGL_UINT_INDEX_ENABLED=e}var b="2.5.0";b=b.indexOf("BRAINBROWSER_VERSION")>0?"D.E.V":b;var c=window.BrainBrowser={version:b};a(c),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={webglExtensionAvailable:function(a){if(!BrainBrowser.WEBGL_ENABLED)return!1;var b=document.createElement("canvas"),c=b.getContext("webgl")||b.getContext("experimental-webgl");return!!c.getExtension(a)},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=f.active_panel,e=d.volume,g=d.axis,h=a.which,i={17:function(){d.anchor||(d.mouse.left||d.mouse.middle||d.mouse.right)&&(d.anchor={x:d.mouse.x,y:d.mouse.y})},37:function(){b=d.slice.width_space.name,e.position[b]>0&&e.position[b]--},38:function(){b=d.slice.height_space.name,e.position[b]0&&e.position[b]--}};return"function"==typeof i[h]?(a.preventDefault(),i[h](),d.updated=!0,e.display.forEach(function(a){d!==a&&a.updateSlice()}),f.synced&&f.syncPosition(d,e,g),!1):32===h&&(a.preventDefault(),e.header.time)?(c=a.shiftKey?Math.max(0,e.current_time-1):Math.min(e.current_time+1,e.header.time.space_length-1),e.current_time=c,f.synced&&f.volumes.forEach(function(a){a!==e&&(a.current_time=Math.max(0,Math.min(c,a.header.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.volume.getSliceImage(a.slice,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/a.default_zoom);b=b||"#FF0000",i.save(),i.strokeStyle=b,i.fillStyle=b,e=1,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=[],k={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=k.canvas.width,e=k.canvas.width,f=Math.min(a/d,b/e)),k.canvas.width=a,k.canvas.height=b,g&&(k.zoom=k.zoom*f,k.image_center.x=a/2,k.image_center.y=b/2,k.updateVolumePosition(),k.updateSlice()),k.updated=!0},followPointer:function(a){var b=a.x-h.x,c=a.y-h.y;return k.translateImage(b,c),h.x=a.x,h.y=a.y,{dx:b,dy:c}},translateImage:function(a,b){k.image_center.x+=a,k.image_center.y+=b,k.updated=!0},reset:function(){k.zoom=k.default_zoom,k.image_center.x=k.canvas.width/2,k.image_center.y=k.canvas.height/2,k.updated=!0},getCursorPosition:function(){var a=k.volume,b=k.slice,c=d(k);return{x:a.position[b.width_space.name]*Math.abs(b.width_space.step)*k.zoom+c.x,y:(b.height_space.space_length-a.position[b.height_space.name]-1)*Math.abs(b.height_space.step)*k.zoom+c.y}},updateVolumePosition:function(a,b){var c,e,f,g=d(k),h=k.zoom,i=k.volume,j=k.slice;(void 0===a||void 0===b)&&(c=k.getCursorPosition(),a=c.x,b=c.y),e=Math.round((a-g.x)/h/Math.abs(j.width_space.step)),f=Math.round(j.height_space.space_length-(b-g.y)/h/Math.abs(j.height_space.step)-1),i.position[k.slice.width_space.name]=e,i.position[k.slice.height_space.name]=f,k.updated=!0},updateSlice:function(b){clearTimeout(i),BrainBrowser.utils.isFunction(b)&&j.push(b),i=setTimeout(function(){var b,c=k.volume;b=c.slice(k.axis),a(k,b),k.triggerEvent("sliceupdate",{volume:c,slice:b}),k.updated=!0,j.forEach(function(a){a(b)}),j.length=0},0)},draw:function(a,d){var e=k.getCursorPosition();if((g.x!==e.x||g.y!==e.y)&&(g.x=e.x,g.y=e.y,k.updated=!0,k.triggerEvent("cursorupdate",{volume:k.volume,cursor:e})),f!==k.zoom&&(f=k.zoom,k.updated=!0,k.triggerEvent("zoom",{volume:k.volume,zoom:k.zoom})),k.touches[0]?(h.x=k.touches[0].x,h.y=k.touches[0].y):(h.x=k.mouse.x,h.y=k.mouse.y),k.updated){var i=k.canvas,j=k.context,l=4,m=l/2;j.globalAlpha=255,j.clearRect(0,0,i.width,i.height),c(k),k.triggerEvent("draw",{volume:k.volume,cursor:e,canvas:i,context:j}),b(k,a),d&&(j.save(),j.strokeStyle="#EC2121",j.lineWidth=l,j.strokeRect(m,m,i.width-l,i.height-l),j.restore()),k.updated=!1}}};if(Object.keys(e).forEach(function(a){BrainBrowser.utils.isFunction(k[a])||(k[a]=e[a])}),BrainBrowser.events.addEventModel(k),k.canvas&&BrainBrowser.utils.isFunction(k.canvas.getContext)&&(k.context=k.canvas.getContext("2d"),k.mouse=BrainBrowser.utils.captureMouse(k.canvas),k.touches=BrainBrowser.utils.captureTouch(k.canvas)),k.volume){var l=k.volume;a(k,l.slice(k.axis)),k.default_zoom=l.getPreferredZoom(k.canvas.width,k.canvas.height),k.zoom=k.default_zoom}return k}}(),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,c,e){e&&(a.volumes.forEach(function(a){a.display.forEach(function(a){a.anchor=null})}),r.anchor={x:b.x,y:b.y}),c||(r.updateVolumePosition(b.x,b.y),i.display.forEach(function(a){r!==a&&a.updateSlice()}),a.synced&&a.syncPosition(r,i,d)),r.updated=!0}function f(b,e){var f;e?(f=r.followPointer(b),a.synced&&a.volumes.forEach(function(a,b){var e;b!==c&&(e=a.display.getPanel(d),e.translateImage(f.dx,f.dy))})):(r.updateVolumePosition(b.x,b.y),i.display.forEach(function(a){r!==a&&a.updateSlice()}),a.synced&&a.syncPosition(r,i,d)),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(a){var b,c=r.touches[0].x-r.touches[1].x,d=r.touches[0].y-r.touches[1].y,e=Math.sqrt(c*c+d*d);a.preventDefault(),null!==t&&(b=e-t,q(.2*b)),t=e}function o(){document.removeEventListener("touchmove",m,!1),document.removeEventListener("touchend",o,!1),t=null}function p(a){a.preventDefault(),q(Math.max(-1,Math.min(1,a.wheelDelta||-a.detail)))}function q(b){r.zoom*=0>b?1/1.05:1.05,r.zoom=Math.max(r.zoom,.25),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},a.syncPosition=function(b,c,d){var e=c.getWorldCoords();a.volumes.forEach(function(a){if(a!==c){var b=a.display.getPanel(d);b.volume.setWorldCoords(e.x,e.y,e.z),b.updated=!0,a.display.forEach(function(a){a!==b&&a.updateSlice()})}})}},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){return"undefined"!=typeof a}function b(b){return a(b)?b.constructor.name:"undefined"}function c(a){if(a>=m.INT8&&a=m.FLT&&a<=m.DBL}function e(a,b){function d(){var a={};return a.hdr_offset=0,a.data_offset=0,a.data_length=0,a.n_filled=0,a.chunk_size=0,a.sym_btree=0,a.sym_lheap=0,a.name="",a.attributes={},a.children=[],a.array=void 0,a.type=-1,a.inflate=!1,a.dims=[],a}function e(){ca=Y}function f(){var a=Y-ca;if(a%Z!==0){var c=Z-a%Z;Y+=c,b&&console.log("skipping "+c+" bytes at "+a+" for alignmnent")}}function g(a){Y+=a}function h(a){Y=a}function i(){return Y}function j(){var a=aa.getUint8(Y);return Y+=1,a}function k(){var a=aa.getUint16(Y,$);return Y+=2,a}function l(){var a=aa.getUint32(Y,$);return Y+=4,a}function n(){var a=aa.getUint64(Y,$);return Y+=8,a}function o(){var a=aa.getFloat32(Y,$);return Y+=4,a}function p(){var a=aa.getFloat64(Y,$);return Y+=8,a}function q(a){var b=0;if(a=a||ba.offsz,4===a)b=aa.getUint32(Y,$);else{if(8!==a)throw new Error("Unsupported value for offset size "+a);b=aa.getUint64(Y,$)}return Y+=a,b}function r(){var a=aa.getUint64(Y,$);return Y+=ba.lensz,a}function s(a){var b,c,d="";for(b=0;a>b;b+=1){if(c=j(),0===c){Y+=a-b-1;break}d+=String.fromCharCode(c)}return d}function t(b,c,d){var e,f,g,h,i=Y;switch(d&&(Y=d),b){case m.INT8:e=new Int8Array(a,Y,c);break;case m.UINT8:e=new Uint8Array(a,Y,c);break;case m.INT16:if(Y%2!==0)for(g=new ArrayBuffer(c),f=c/2,e=new Int16Array(g),h=0;f>h;h+=1)e[h]=k();else e=new Int16Array(a,Y,c/2),Y+=c;break;case m.UINT16:if(Y%2!==0)for(g=new ArrayBuffer(c),f=c/2,e=new Uint16Array(g),h=0;f>h;h+=1)e[h]=k();else e=new Uint16Array(a,Y,c/2),Y+=c;break;case m.INT32:if(Y%4!==0)for(g=new ArrayBuffer(c),f=c/4,e=new Int32Array(g),h=0;f>h;h+=1)e[h]=l();else e=new Int32Array(a,Y,c/4),Y+=c;break;case m.UINT32:if(Y%4!==0)for(g=new ArrayBuffer(c),f=c/4,e=new Uint32Array(g),h=0;f>h;h+=1)e[h]=l();else e=new Uint32Array(a,Y,c/4),Y+=c;break;case m.FLT:if(Y%4!==0)for(g=new ArrayBuffer(c),f=c/4,e=new Float32Array(g),h=0;f>h;h+=1)e[h]=o();else e=new Float32Array(a,Y,c/4),Y+=c;break;case m.DBL:if(Y%8!==0)for(g=new ArrayBuffer(c),f=c/8,e=new Float64Array(g),h=0;f>h;h+=1)e[h]=p();else e=new Float64Array(a,Y,c/8),Y+=c;break;default:throw new Error("Bad type in getArray "+b)}return d&&(Y=i),e}function u(a){var b,c;switch(a){case 1:b=aa.getUint8(Y);break;case 2:b=aa.getUint16(Y,$);break;case 4:b=aa.getUint32(Y,$);break;case 8:b=aa.getUint64(Y,$);break;default:if(b=0,$)for(c=a-1;c>=0;c--)b=(b<<8)+aa.getUint8(Y+c);else for(c=0;a>c;c++)b=(b<<8)+aa.getUint8(Y+c)}return Y+=a,b}function v(a){var b;for(b=0;b2)throw new Error("Unsupported HDF5 superblock version "+a.sbver);return a.sbver<=1?(a.fsver=j(),a.rgver=j(),g(1),a.shver=j(),a.offsz=j(),a.lensz=j(),g(1),a.gln_k=k(),a.gin_k=k(),a.cflags=l(),1===a.sbver&&(a.isin_k=k(),g(2)),a.base_addr=q(a.offsz),a.gfsi_addr=q(a.offsz),a.eof_addr=q(a.offsz),a.dib_addr=q(a.offsz),a.root_ln_offs=q(a.offsz),a.root_addr=q(a.offsz),a.root_cache_type=l(),g(4),g(16)):(a.offsz=j(),a.lensz=j(),a.cflags=j(),a.base_addr=q(a.offsz),a.ext_addr=q(a.offsz),a.eof_addr=q(a.offsz),a.root_addr=q(a.offsz),a.checksum=l()),b&&console.log("HDF5 SB "+a.sbver+" "+a.offsz+" "+a.lensz+" "+a.cflags),a}function x(){var a={};if(!v("FRHP"))throw new Error("Bad or missing FRHP signature");a.ver=j(),a.idlen=k(),a.iof_el=k(),a.flags=j(),a.objmax=l(),a.objnid=r(),a.objbta=q(),a.nf_blk=r(),a.af_blk=q(),a.heap_total=r(),a.heap_alloc=r(),a.bai_offset=r(),a.heap_nobj=r(),a.heap_chuge=r(),a.heap_nhuge=r(),a.heap_ctiny=r(),a.heap_ntiny=r(),a.table_width=k(),a.start_blksz=r(),a.max_blksz=r(),a.max_heapsz=k(),a.rib_srows=k(),a.root_addr=q(),a.rib_crows=k();var c=Math.log2(a.max_blksz)-Math.log2(a.start_blksz)+2;if(a.K=Math.min(a.rib_crows,c)*a.table_width,a.N=a.rib_crows0)throw new Error("Filters present in fractal heap.");return a}function y(){var a={};if(!v("BTHD"))throw new Error("Bad or missing BTHD signature");return a.ver=j(),a.type=j(),a.nodesz=l(),a.recsz=k(),a.depth=k(),a.splitp=j(),a.mergep=j(),a.root_addr=q(),a.root_nrec=k(),a.total_nrec=r(),a.checksum=l(),b&&console.log("BTHD V"+a.ver+" T"+a.type+" "+a.nodesz+" "+a.recsz+" "+a.depth+" "+a.root_addr+" "+a.root_nrec+" "+a.total_nrec),a}function z(a,c,d,e){var f,g,k,m;if(1===c)for(f=0;d>f;f++){k=q(),m=r();var n=r();b&&console.log(" -> "+k+" "+m+" "+n+" "+da),g=i(),n===da&&(h(k),M(m,e)),h(g)}else{if(8!==c)throw new Error("Unhandled V2 btree type.");var o,p;o=a.max_heapsz/8;var s=Math.min(a.objmax,a.max_blksz);for(p=256>=s?1:65536>=s?2:4,f=0;d>f;f++){var t=j();if(0!==(192&t))throw new Error("Bad Fractal Heap ID version "+t);var v,w=48&t;if(16===w)da=u(7);else{if(0!==w)throw new Error("Can't handle this Heap ID: "+t);k=u(o),m=u(p)}if(v=j(),l(),l(),b&&console.log(" -> "+t+" "+k+" "+m+" "+v),g=i(),16===w){h(a.objbta);var x=y();if(1!==x.type)throw new Error("Can only handle type-1 btrees");h(x.root_addr),A(a,x.root_nrec,e)}else{var z=S(a,k);h(z),M(m,e)}h(g)}}}function A(a,c,d){if(!v("BTLF"))throw new Error("Bad or missing BTLF signature");var e=j(),f=j();b&&console.log("BTLF V"+e+" T"+f+" "+i()),z(a,f,c,d)}function B(a,c,d,e){if(!v("BTIN"))throw new Error("Bad or missing BTIN signature");var f,g=j(),h=j();for(b&&console.log("BTIN V"+g+" T"+h),z(a,h,c,e),f=0;c>=f;f++){var i,k=q(),l=u(1);d>1&&(i=u(1)),b&&console.log(" child->"+k+" "+l+" "+i)}}function C(a){if(am&&(r=d(),r.hdr_offset=o,a&&(t=i(),h(a.lh_dseg_off+n),r.name=s(a.lh_dseg_len),h(t)),b&&console.log(" "+m+" O "+n+" A "+o+" T "+p+" '"+r.name+"'"),c.children.push(r))}function F(){var a={};if(!v("HEAP"))throw new Error("Bad or missing HEAP signature");return a.lh_ver=j(),g(3),a.lh_dseg_len=r(),a.lh_flst_len=r(),a.lh_dseg_off=q(),b&&console.log("LHEAP V"+a.lh_ver+" "+a.lh_dseg_len+" "+a.lh_flst_len+" "+a.lh_dseg_off),a}function G(a,c){var d,e=j(),f=j(),h=j();g(1>=e?5:1);var i,k=1,l=[];for(i=0;f>i;i+=1)l[i]=r(),k*=l[i];d=f*ba.lensz+(1>=e?8:4);var m=[];if(0!==(1&h))for(d+=f*ba.lensz,i=0;f>i;i+=1)m[i]=r();var n=[];if(0!==(2&h))for(d+=f*ba.lensz,i=0;f>i;i+=1)n[i]=r();var o="hdf5MsgDataspace V"+e+" N"+f+" F"+h;return b&&(0!==f&&(o+="["+l.join(", ")+"]"),console.log(o)),a>d&&g(a-d),c&&(c.dims=l),k}function H(a){var c=j(),d=j();0!==(1&d)&&n();var e=q(),f=q();0!==(2&d)&&q(),b&&console.log("hdf5MsgLinkInfo V"+c+" F"+d+" FH "+e+" BT "+f);var g=i();if(e>4,u=15&s,v=[];for(o=0;3>o;o+=1)v[o]=j();var w=l();switch(b&&console.log("hdf5MsgDatatype V"+t+" C"+u+" "+I(u)+" "+v[0]+"."+v[1]+"."+v[2]+" "+w),u){case 0:switch(c=k(),d=k(),w){case 4:p.typ_type=8&v[0]?m.INT32:m.UINT32;break;case 2:p.typ_type=8&v[0]?m.INT16:m.UINT16;break;case 1:p.typ_type=8&v[0]?m.INT8:m.UINT8;break;default:throw new Error("Unknown type size "+w)}p.typ_length=w,q+=4,b&&console.log(" ("+c+" "+d+")");break;case 1:if(r="",b)switch(65&v[0]){case 0:r+="LE ";break;case 1:r+="BE ";break;case 65:r+="VX ";break;default:throw new Error("Reserved fp byte order: "+v[0])}if(c=k(),d=k(),e=j(),f=j(),h=j(),i=j(),n=l(),b&&(r+=c+" "+d+" "+e+" "+f+" "+h+" "+i+" "+n),64===d&&0===c&&52===e&&11===f&&0===h&&52===i&&1023===n&&8===w)p.typ_type=m.DBL;else{if(32!==d||0!==c||23!==e||8!==f||0!==h||23!==i||127!==n||4!==w)throw new Error("Unsupported floating-point type");p.typ_type=m.FLT}b&&console.log(r),p.typ_length=w,q+=12;break;case 3:p.typ_type=m.STR,p.typ_length=w;break;default:throw new Error("Unimplemented HDF5 data class "+u)}return a>q&&g(a-q),p}function K(a){var c,d,e,f,h,m,n,o="",p=j(),s=[],t=1;if(1===p||2===p){if(d=j(),c=j(),g(5),b&&(o+="hdf5MsgLayout V"+p+" N"+d+" C"+c),1===c||2===c){var u=q();b&&(o+=" A"+u),a.data_offset=u}for(f=0;d>f;f+=1)s[f]=l(),t*=s[f];b&&(o+="["+s.join(", ")+"]"),2===c&&(n=l(),a.chunk_size=t*n,b&&(o+=" E"+n)),0===c?(e=l(),b&&(o+="("+e+")"),a.data_offset=i(),a.data_length=e):1===c&&(a.data_length=t)}else{if(3!==p)throw new Error("Illegal layout version "+p);if(c=j(),o="hdf5MsgLayout V"+p+" C"+c,0===c)e=k(),b&&(o+="("+e+")"),a.data_offset=i(),a.data_length=e;else if(1===c)h=q(),m=r(),b&&(o+="("+h+", "+m+")"),a.data_offset=h,a.data_length=m;else if(2===c){for(d=j(),h=q(),a.data_offset=h,a.chunk_size=1,f=0;d-1>f;f+=1)s[f]=l(),t*=s[f];b&&(o+="(N"+d+", A"+h+" ["+s.join(",")+"]"),n=l(),a.chunk_size=t*n,b&&(o+=" E"+n)}}b&&console.log(o)}function L(a){var c=j(),d=j(),e="hdf5MsgPipeline V"+c+" N"+d;1===c&&g(6),b&&console.log(e);var f,h,i,l,m;for(f=0;d>f;f+=1){if(h=k(),1!==h)throw new Error("Unimplemented HDF5 filter "+h);if("object"!=typeof pako)throw new Error("Need pako to inflate data.");a.inflate=!0,i=1===c||h>256?k():0,l=k(),m=k(),0!==(1&m)&&(m+=1),0!==i&&g(i),g(4*m),b&&console.log(" "+f+" ID"+h+" F"+l+" "+m)}}function M(a,c){var d=j(),e=j(),f=k(),g=k(),h=k(),l="hdf5MsgAttribute V"+d+" F"+e+" "+a+": ";if(0!==(3&e))throw new Error("Shared dataspaces and datatypes are not supported.");if(3===d){var n=j();b&&(l+=0===n?"ASCII":"UTF-8")}b&&(l+="("+f+" "+g+" "+h+")"),3>d&&(f=8*Math.floor((f+7)/8),g=8*Math.floor((g+7)/8),h=8*Math.floor((h+7)/8),b&&(l+="/("+f+" "+g+" "+h+")"));var o=s(f);b&&(l+=" Name: "+o,console.log(l));var p=J(g),q=G(h),r=0;r=a>0?3>d?a-(8+f+g+h):a-(9+f+g+h):p.typ_length*q,b&&console.log(" attribute data size "+r+" "+i());var u;u=p.typ_type===m.STR?s(r):t(p.typ_type,r),c.attributes[o]=u}function N(){var a=4,c=8,d=j(),e=j();0!==(1&e)&&(k(),k()),0!==(2&e)&&(a=k(),c=k()),b&&console.log("hdf5MsgGroupInfo V"+d+" F"+e+" ENT "+a+" LNL "+c)}function O(a){var c=j(),e=0;if(1!==c)throw new Error("Bad link message version "+c);var f=j();0!==(8&f)&&(e=j()),0!==(4&f)&&n(),0!==(16&f)&&j();var g=1<<(3&f),h=u(g),i=d();i.name=s(h),0===(8&f)&&(i.hdr_offset=q()),b&&console.log("hdf5MsgLink V"+c+" F"+f+" T"+e+" NM "+i.name+" OF "+i.hdr_offset),a.children.push(i)}function P(a,c,d,e){if(!v("FHDB"))throw new Error("Bad or missing FHDB signature");var f=j();if(0!==f)throw new Error("Bad FHDB version: "+f);q();var g=Math.ceil(a.max_heapsz/8),h=u(g);0!==(2&a.flags)&&l(),b&&console.log("FHDB V:"+f+" R:"+c+" O:"+h+" A:"+d);var i=5+ba.offsz+g;0!==(2&a.flags)&&(i+=4);var k;return k=1>=c?a.start_blksz:Math.pow(2,c-1)*a.start_blksz,e?e(c,d,h,k):!0}function Q(a,c){if(!v("FHIB"))throw new Error("Bad or missing FHIB signature");var d=j();if(0!==d)throw new Error("Bad FHIB version: "+d);q();var e=Math.ceil(a.max_heapsz/8),f=u(e);b&&console.log("FHIB V:"+d+" O:"+f);var g,i,k=[];for(g=0;g=e&&e+f>b?(c=d+(b-e),!1):!0}),c}function T(a){var c=j();if(0!==c)throw new Error("Bad attribute information message version: "+c);var d=j();0!==(1&d)&&k();var e=q(),f=q();0!==(2&d)&&q(),b&&console.log("hdf5MsgAttrInfo V"+c+" F"+d+" HP "+e+" AN "+f);var g,l=i();if(e0?B(g,m.root_nrec,m.depth,a):A(g,m.root_nrec,a)}h(l)}function U(a,c){var d,e={};switch(a.hm_type){case 1:G(a.hm_size,c);break;case 2:H(c);break;case 3:d=J(a.hm_size),c&&(c.type=d.typ_type);break;case 6:O(c);break;case 8:K(c);break;case 10:N();break;case 11:L(c);break;case 12:M(a.hm_size,c);break;case 16:e.cq_off=q(),e.cq_len=r(),_.push(e),b&&console.log("hdf5MsgObjHdrContinue "+e.cq_off+" "+e.cq_len);break;case 17:c.sym_btree=q(),c.sym_lheap=q(),b&&console.log("hdf5MsgSymbolTable "+c.sym_btree+" "+c.sym_lheap);break;case 21:T(c);break;case 0:case 4:case 5:case 7:case 18:case 19:case 20:case 22:case 24:g(a.hm_size);break;default:throw new Error("Unknown message type: "+a.hm_type)}}function V(a){if(!v("OHDR"))throw new Error("Bad or missing OHDR signature");var c=j(),d=j();0!==(32&d)&&(l(),l(),l(),l()),0!==(16&d)&&(k(),k());var e=1<<(3&d),f=u(e),m=0,n=0,o=f;b&&console.log("hdf5V2ObjectHeader V"+c+" F"+d+" HS"+f);for(var p,q,r;;){for(;o-n>=8;)p={},p.hm_type=j(),p.hm_size=k(),p.hm_flags=j(),b&&console.log(" msg"+m+" F"+p.hm_flags+" T "+p.hm_type+" S "+p.hm_size+" ("+n+"/"+o+") "+C(p.hm_type)),0!==(4&d)&&(p.hm_corder=k()),r=i(),U(p,a),h(r+p.hm_size),n+=p.hm_size+4,m+=1;if(o-n>4&&g(o-(n+4)),l(),0===_.length)break;if(q=_.shift(),h(q.cq_off),o=q.cq_len-4,n=0,b&&console.log("continuing with "+q.cq_len+" bytes at "+i()),!v("OCHK"))throw new Error("Bad v2 object continuation")}a.children.forEach(function(a,c){h(a.hdr_offset),b&&console.log(c+" "+a.hdr_offset+" "+a.name),v("OHDR")?(h(a.hdr_offset),V(a)):(h(a.hdr_offset),X(a))})}function W(a){if(0!==a.chunk_size){h(a.data_offset);var d,e=1;for(d=0;d0&&a.data_offset=p){if(0===_.length)break;d=_.shift(),h(d.cq_off),p=d.cq_len,b&&console.log("continuing with "+p+" bytes at "+i()),e()}if(f(),n={},n.hm_type=k(),n.hm_size=k(),n.hm_flags=j(),n.hm_size%8!==0)throw new Error("Size is not 8-byte aligned: "+n.hm_size);g(3),p-=8+n.hm_size,b&&console.log(" msg"+m+" F "+n.hm_flags+" T "+n.hm_type+" S "+n.hm_size+"("+p+") "+C(n.hm_type)),o=i(),U(n,a),h(o+n.hm_size)}if(0!==a.sym_btree&&0!==a.sym_lheap){h(a.sym_btree);var q=D();h(a.sym_lheap);var r,s=F();for(r=0;rd;d+=1)e+=" ";e+=a.name+(a.children.length?"/":""),a.type>0&&(e+=" "+b(a.array),a.dims.length&&(e+="["+a.dims.join(", ")+"]"),e+=a.array?":"+a.array.length:" NULL"),console.log(e),Object.keys(a.attributes).forEach(function(g){var h=a.attributes[g];for(e="",d=0;2*c+1>d;d+=1)e+=" ";e+=a.name+":"+g+" "+b(h)+"["+h.length+"] ","string"==typeof h?e+=JSON.stringify(h):(e+="{"+f(h.slice(0,16),", "),h.length>16&&(e+=", ..."),e+="}"),console.log(e)}),a.children.forEach(function(a){g(a,c+1)})}function h(b,c,d){var e;return b.name===c&&b.type>0?e=b:b.children.find(function(b){return e=h(b,c,d+1),a(e)}),e}function i(b,c,d){var e=b.attributes[c];return e?e:(b.children.find(function(b){return e=i(b,c,d+1),a(e)}),e)}function j(a,b,c,e,f){var g=new ArrayBuffer(a.array.length*Float32Array.BYTES_PER_ELEMENT),h=new Float32Array(g),i=a.dims.length-b.dims.length;if(1>i)throw new Error("Too few slice dimensions: "+a.dims.length+" "+b.dims.length);var j,k=1;for(j=b.dims.length;jv;v+=1)w=p[m],we[1]?h[m]=0:(h[m]=w,l+=w,w>n&&(n=w),o>w&&(o=w)),m+=1;else for(s=e[1]-e[0],t=q[j]-r[j],u=r[j],v=0;k>v;v+=1)w=(p[m]-x)/s*t+u,h[m]=w,l+=w,m+=1,w>n&&(n=w),o>w&&(o=w);return f&&(console.log("Min: "+o),console.log("Max: "+n),console.log("Sum: "+l),console.log("Mean: "+l/m)),g}function k(a,b){var c=a.order;return"Uint8Array"===b.array.constructor.name&&c.length>0&&"vector_dimension"===c[c.length-1]&&3===a.vector_dimension.space_length}function l(a){var b,c=a.array,d=c.length,e=new ArrayBuffer(d/3*4),f=new Uint8Array(e),g=0;for(b=0;d>b;b+=3)f[g+0]=c[b+0],f[g+1]=c[b+1],f[g+2]=c[b+2],f[g+3]=255,g+=4;return e}var m={INT8:1,UINT8:2,INT16:3,UINT16:4,INT32:5,UINT32:6,FLT:7,DBL:8,STR:9};Array.prototype.find||(Array.prototype.find=function(a){if(null===this)throw new TypeError("Array.prototype.find called on null or undefined");if("function"!=typeof a)throw new TypeError("predicate must be a function");for(var b,c=Object(this),d=c.length>>>0,e=arguments[1],f=0;d>f;f++)if(b=c[f],a.call(e,b,f,c))return b;return void 0});var n=[0,1,1,2,2,4,4,4,8,0],o=BrainBrowser.VolumeViewer;o.utils.hdf5Loader=function(b){var c,d=!1;try{c=e(b,d)}catch(f){d&&(console.log(f),console.log("Trying as NetCDF...")),c=o.utils.netcdfReader(b,d)}d&&g(c,0);var n=h(c,"image");if(!a(n))throw new Error("Can't find image dataset.");var p=i(n,"valid_range",0);if(!a(p)){var q,r;switch(n.type){case m.INT8:q=-128,r=127;break;case m.UINT8:q=0,r=255;break;case m.INT16:q=-32768,r=32767;break;case m.UINT16:q=0,r=65535;break;case m.INT32:q=-(1<<31),r=(1<<31)-1;break;case m.UINT32:q=0,r=0}p=Float32Array.of(q,r)}var s=h(c,"image-min");a(s)||(s={array:Float32Array.of(0),dims:[]});var t=h(c,"image-max");a(t)||(t={array:Float32Array.of(1),dims:[]});var u={},v=i(n,"dimorder",0);if("string"!=typeof v)throw new Error("Can't find dimension order.");u.order=v.split(","),u.order.forEach(function(b){var d=h(c,b);if(!a(d))throw new Error("Can't find dimension variable "+b);if(u[b]={},v=i(d,"step",0),a(v)||(v=Float32Array.of(1)),u[b].step=v[0],v=i(d,"start",0),a(v)||(v=Float32Array.of(0)),u[b].start=v[0],v=i(d,"length",0),!a(v))throw new Error("Can't find length for "+b);u[b].space_length=v[0],v=i(d,"direction_cosines",0),a(v)?u[b].direction_cosines=Array.prototype.slice.call(v):"xspace"===b?u[b].direction_cosines=[1,0,0]:"yspace"===b?u[b].direction_cosines=[0,1,0]:"zspace"===b&&(u[b].direction_cosines=[0,0,1])});var w;return k(u,n)?(u.order.pop(),u.datatype="rgb8",w=l(n)):(u.datatype="float32",w=j(n,s,t,p,d)),{header_text:JSON.stringify(u),raw_data:w}}}(),function(){"use strict";function a(a,b){var c,f={order:["xspace","yspace","zspace"],xspace:{},yspace:{},zspace:{}},g=new DataView(a,0,284),h=!0,i=g.getUint32(0,!0);1===i?h=!0:16777216===i?h=!1:c="This does not look like an MGH file.";var j=0,k=[0,0,0,0],l=4,m=1;for(j=0;4>j&&(k[j]=g.getUint32(l,h),!(k[j]<=1));j++)m*=k[j],l+=4;(3>j||j>4)&&(c="Cannot handle "+j+"-dimensional images yet.");var n,o,p=g.getUint32(20,h),q=g.getUint16(28,h),r=[1,1,1],s=[[-1,0,0],[0,0,-1],[0,1,0],[0,0,0]];if(q){for(l=30,n=0;3>n;n++)r[n]=g.getFloat32(l,h),l+=4;for(n=0;4>n;n++)for(o=0;3>o;o++)s[n][o]=g.getFloat32(l,h),l+=4}if(e)for(n=0;3>n;n++){var t="";for(o=0;4>o;o++)t+="xyzc"[o]+"_"+"ras"[n]+" "+s[o][n]+" ";console.log(t)}for(var u=[0,1,2],v=0;3>v;v++){var w=0,x=Math.abs(s[v][0]),y=Math.abs(s[v][1]),z=Math.abs(s[v][2]);f.order[v]="xspace",y>x&&y>z&&(w=1,f.order[v]="yspace"),z>x&&z>y&&(w=2,f.order[v]="zspace"),u[v]=w}4===j&&(e&&console.log("Creating time dimension: "+k[3]),f.time={space_length:k[3],step:1,start:0,name:"time"},f.order.push("time"));var A=!1,B=[[0,0,0,0],[0,0,0,0],[0,0,0,0]];for(n=0;3>n;n++)for(o=0;3>o;o++)B[n][o]=s[o][n]*r[n];for(n=0;3>n;n++){var C=0;for(o=0;3>o;o++)C+=B[n][o]*(k[o]/2);A?B[n][3]=-C:B[n][3]=s[3][n]-C}var D=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]];for(n=0;3>n;n++)for(o=0;4>o;o++){var E=o;3>o&&(E=u[o]),D[n][E]=B[n][o]}if(d.utils.transformToMinc(D,f),void 0!==c)throw BrainBrowser.events.triggerEvent("error",{message:c}),new Error(c);for(f.datatype=p,f.little_endian=h,f.nvoxels=m,n=0;3>n;n++)f[f.order[n]].space_length=k[n];BrainBrowser.utils.isFunction(b)&&b(f)}function b(a,b,e){var f=d.createVolume(a,c(a,b));f.type="mgh",f.intensity_min=a.voxel_min,f.intensity_max=a.voxel_max,f.saveOriginAndTransform(a),BrainBrowser.utils.isFunction(e)&&e(f)}function c(a,b){var c=null,e=1;switch(a.datatype){case 0:e=1;break;case 1:case 3:e=4;break;case 4:e=2;break;default:var f="Unsupported data type: "+a.datatype;throw BrainBrowser.events.triggerEvent("error",{message:f}),new Error(f)}var g=a.nvoxels*e;switch(e>1&&!a.little_endian&&d.utils.swapn(new Uint8Array(b,284,g),e),a.datatype){case 0:c=new Uint8Array(b,284,a.nvoxels);break;case 1:c=new Int32Array(b,284,a.nvoxels);break;case 3:c=new Float32Array(b,284,a.nvoxels);break;case 4:c=new Int16Array(b,284,a.nvoxels)}d.utils.scanDataRange(c,a);var h,i=1;for(h=0;h0,A=s.step>0,B=q.step>0,C=0;if(l=B?b:q.space_length-b-1,l>=0&&l=0;h--)for(k=A?h:u-h-1,n=m+k*x,i=0;t>i;i++)j=z?i:t-i-1,o=n+j*w,y[C++]=g.data[o];return e={axis:a,data:y,width_space:r,height_space:s,width:t,height:u},f[a][c][b]=e,e},saveOriginAndTransform:function(a){var b=a.xspace.start,c=a.yspace.start,d=a.zspace.start,e=a.xspace.direction_cosines,f=a.yspace.direction_cosines,g=a.zspace.direction_cosines,h=a.xspace.step,i=a.yspace.step,j=a.zspace.step;a.voxel_origin={x:b*e[0]+c*f[0]+d*g[0],y:b*e[1]+c*f[1]+d*g[1],z:b*e[2]+c*f[2]+d*g[2]};var k=a.voxel_origin,l=(-k.x*e[0]-k.y*e[1]-k.z*e[2])/h,m=(-k.x*f[0]-k.y*f[1]-k.z*f[2])/i,n=(-k.x*g[0]-k.y*g[1]-k.z*g[2])/j;a.w2v=[[e[0]/h,e[1]/h,e[2]/h,l],[f[0]/i,f[1]/i,f[2]/i,m],[g[0]/j,g[1]/j,g[2]/j,n]]},getSliceImage:function(a,b,c,f){b=b||1;var h,i=g.color_map;if(!i)throw h="No color map set for this volume. Cannot render slice.",g.triggerEvent("error",h),new Error(h);var j=a.width_space.step,k=a.height_space.step,l=Math.abs(Math.floor(a.width*j*b)),m=Math.abs(Math.floor(a.height*k*b)),n=d.createImageData(a.width,a.height),o=d.createImageData(l,m);if("rgb8"===g.header.datatype){var p=new Uint8ClampedArray(a.data.buffer);n.data.set(p,0)}else i.mapColors(a.data,{min:g.intensity_min,max:g.intensity_max,contrast:c,brightness:f,destination:n.data});return o.data.set(e.utils.nearestNeighbor(n.data,n.width,n.height,l,m,{block_size:4})),o},getIntensityValue:function(a,b,c,d){var e=g.header,f=g.getVoxelCoords();if(a=void 0===a?f.i:a,b=void 0===b?f.j:b,c=void 0===c?f.k:c,d=void 0===d?g.current_time:d,0>a||a>=e[e.order[0]].space_length||0>b||b>=e[e.order[1]].space_length||0>c||c>=e[e.order[2]].space_length)return 0;var h=e.time?d*e.time.offset:0,i=a*e[e.order[0]].offset+b*e[e.order[1]].offset+c*e[e.order[2]].offset+h;return g.data[i]},getVoxelCoords:function(){var a=g.header,b={xspace:a.xspace.step>0?g.position.xspace:a.xspace.space_length-g.position.xspace,yspace:a.yspace.step>0?g.position.yspace:a.yspace.space_length-g.position.yspace,zspace:a.zspace.step>0?g.position.zspace:a.zspace.space_length-g.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=g.header,e=d.order[0],f=d.order[1],h=d.order[2];g.position[e]=d[e].step>0?a:d[e].space_length-a,g.position[f]=d[f].step>0?b:d[f].space_length-b,g.position[h]=d[h].step>0?c:d[h].space_length-c},getWorldCoords:function(){var a=g.getVoxelCoords();return g.voxelToWorld(a.i,a.j,a.k)},setWorldCoords:function(a,b,c){var d=g.worldToVoxel(a,b,c);g.setVoxelCoords(d.i,d.j,d.k)},voxelToWorld:function(a,b,c){var d,e,f,h={},i=g.header;h[i.order[0]]=a,h[i.order[1]]=b,h[i.order[2]]=c,d=h.xspace,e=h.yspace,f=h.zspace;var j=i.xspace.direction_cosines,k=i.yspace.direction_cosines,l=i.zspace.direction_cosines,m=i.xspace.step,n=i.yspace.step,o=i.zspace.step,p=i.voxel_origin;return{x:d*j[0]*m+e*k[0]*n+f*l[0]*o+p.x,y:d*j[1]*m+e*k[1]*n+f*l[1]*o+p.y,z:d*j[2]*m+e*k[2]*n+f*l[2]*o+p.z}},worldToVoxel:function(b,c,d){var e=a.w2v,f={vx:b*e[0][0]+c*e[0][1]+d*e[0][2]+e[0][3],vy:b*e[1][0]+c*e[1][1]+d*e[1][2]+e[1][3],vz:b*e[2][0]+c*e[2][1]+d*e[2][2]+e[2][3]},g={};return g[a.order[0]]=Math.round(f.vx),g[a.order[1]]=Math.round(f.vy),g[a.order[2]]=Math.round(f.vz),{i:g.xspace,j:g.yspace,k:g.zspace}},getVoxelMin:function(){return g.header.voxel_min},getVoxelMax:function(){return g.header.voxel_max},getPreferredZoom:function(a,b){var c=g.header,d=c.xspace.space_length*Math.abs(c.xspace.step),e=c.yspace.space_length*Math.abs(c.yspace.step),f=c.zspace.space_length*Math.abs(c.xspace.step),h=a/d,i=a/e,j=b/e,k=b/f;return Math.min(i,h,k,j)}};return g},e.utils.scanDataRange=function(a,b){var c=0,d=+(1/0),e=-(1/0);for(c=0;ce&&(e=f),d>f&&(d=f)}b.voxel_min=d,b.voxel_max=e}}(),function(){"use strict";function a(a){if(a>=c.BYTE&&a0&&(h+=","),h+=c[g].name;h.length>0&&(a.attributes.dimorder=h)}var c={BYTE:1,CHAR:2,SHORT:3,INT:4,FLOAT:5,DOUBLE:6},d=[0,1,1,2,4,4,8],e=BrainBrowser.VolumeViewer;e.utils.netcdfReader=function(d,f){function g(){return{begin:0,vsize:0,name:"",attributes:{},children:[],array:void 0,type:-1,dims:[],nelem:0}}function h(){var a=x.getUint8(v);return v+=1,a}function i(){var a=x.getUint32(v,w);return v+=4,a}function j(a){var b,c,d="";for(b=0;a>b;b+=1){if(c=h(),0===c){v+=a-b-1;break}d+=String.fromCharCode(c)}return d}function k(a){return 4*Math.floor((a+3)/4)}function l(b,f,g,h){var i,j;if(h=h||v,b===c.CHAR)i=new Int8Array(d,h,f);else if(b===c.BYTE)i=new Uint8Array(d,h,f);else if(b===c.DOUBLE){var l=new ArrayBuffer(f),m=0;for(i=new Float64Array(l),j=0;f>j;j+=8)i[m]=x.getFloat64(h+j),m+=1}else{var n=f/a(b);if(e.utils.swapn(new Uint8Array(d,h,f),a(b)),b===c.SHORT)i=new Int16Array(d,h,n);else if(b===c.INT)i=new Int32Array(d,h,n);else{if(b!==c.FLOAT)throw"Bad type in getArray "+b;i=new Float32Array(d,h,n)}}return h===v&&(v+=k(f)),i}function m(){var a=j(3);if("CDF"!==a)return!1;var b=h();return 1!==b?!1:!0}function n(a,b,c){var d,e=i(),f=i();if(e===a)for(d=0;f>d;d++)b(c);else if(0!==e||0!==f)throw new Error("Protocol error.")}function o(){var a=i(),b=j(k(a)),c=i();y.push({name:b,length:c})}function p(){n(10,o)}function q(b){var d=i(),e=j(k(d)),f=i(),g=i(),h=l(f,a(f)*g,[]);if(f===c.CHAR){var m,n="";for(m=0;m