!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.CV=t.CV||{})}(this,function(t){"use strict";function e(){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],arguments.length>0&&console.error("THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.")}function r(t,e,r,n){this._x=t||0,this._y=e||0,this._z=r||0,this._w=void 0!==n?n:1}function n(t,e,r){this.x=t||0,this.y=e||0,this.z=r||0}function i(t){if(void 0!==t){var e;for(e in t)Bs.set(e,t[e])}}function a(t,e){return Bs.has(t)?Bs.get(t):e}function o(t,e){return t.split(".").shift()+"."+e}function s(){}function c(t,e,r){return void 0===e&&void 0===r?this.set(t):this.setRGB(t,e,r)}function l(){}function h(t,e){this.x=t||0,this.y=e||0}function u(t,e,r,n,i,a,o,s,c,l){Object.defineProperty(this,"id",{value:Wl++}),this.uuid=Ko.generateUUID(),this.name="",this.image=void 0!==t?t:u.DEFAULT_IMAGE,this.mipmaps=[],this.mapping=void 0!==e?e:u.DEFAULT_MAPPING,this.wrapS=void 0!==r?r:Zc,this.wrapT=void 0!==n?n:Zc,this.magFilter=void 0!==i?i:tl,this.minFilter=void 0!==a?a:rl,this.anisotropy=void 0!==c?c:1,this.format=void 0!==o?o:vl,this.type=void 0!==s?s:nl,this.offset=new h(0,0),this.repeat=new h(1,1),this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.encoding=void 0!==l?l:Ul,this.version=0,this.onUpdate=null}function d(t,e,r,n,i,a,o,s,c,l,h,d){u.call(this,null,a,o,s,c,l,n,i,h,d),this.image={data:t,width:e,height:r},this.magFilter=void 0!==c?c:Qc,this.minFilter=void 0!==l?l:Qc,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}function p(t){for(var e=t.length,r=new Uint8Array(3*e),n=0;n0)return t;var i=e*r,a=Jl[i];if(void 0===a&&(a=new Float32Array(i),Jl[i]=a),0!==e){n.toArray(a,0);for(var o=1,s=0;o!==e;++o)s+=r,t[o].toArray(a,s)}return a}function M(t,e){var r=Ql[e];void 0===r&&(r=new Int32Array(e),Ql[e]=r);for(var n=0;n!==e;++n)r[n]=t.allocTextureUnit();return r}function E(t,e){t.uniform1f(this.addr,e)}function S(t,e){t.uniform1i(this.addr,e)}function T(t,e){void 0===e.x?t.uniform2fv(this.addr,e):t.uniform2f(this.addr,e.x,e.y)}function A(t,e){void 0!==e.x?t.uniform3f(this.addr,e.x,e.y,e.z):void 0!==e.r?t.uniform3f(this.addr,e.r,e.g,e.b):t.uniform3fv(this.addr,e)}function L(t,e){void 0===e.x?t.uniform4fv(this.addr,e):t.uniform4f(this.addr,e.x,e.y,e.z,e.w)}function C(t,e){t.uniformMatrix2fv(this.addr,!1,e.elements||e)}function R(t,e){void 0===e.elements?t.uniformMatrix3fv(this.addr,!1,e):($l.set(e.elements),t.uniformMatrix3fv(this.addr,!1,$l))}function P(t,e){void 0===e.elements?t.uniformMatrix4fv(this.addr,!1,e):(Kl.set(e.elements),t.uniformMatrix4fv(this.addr,!1,Kl))}function I(t,e,r){var n=r.allocTextureUnit();t.uniform1i(this.addr,n),r.setTexture2D(e||ql,n)}function O(t,e,r){var n=r.allocTextureUnit();t.uniform1i(this.addr,n),r.setTextureCube(e||Zl,n)}function N(t,e){t.uniform2iv(this.addr,e)}function D(t,e){t.uniform3iv(this.addr,e)}function U(t,e){t.uniform4iv(this.addr,e)}function z(t){switch(t){case 5126:return E;case 35664:return T;case 35665:return A;case 35666:return L;case 35674:return C;case 35675:return R;case 35676:return P;case 35678:case 36198:return I;case 35680:return O;case 5124:case 35670:return S;case 35667:case 35671:return N;case 35668:case 35672:return D;case 35669:case 35673:return U}}function B(t,e){t.uniform1fv(this.addr,e)}function F(t,e){t.uniform1iv(this.addr,e)}function k(t,e){t.uniform2fv(this.addr,_(e,this.size,2))}function G(t,e){t.uniform3fv(this.addr,_(e,this.size,3))}function V(t,e){t.uniform4fv(this.addr,_(e,this.size,4))}function H(t,e){t.uniformMatrix2fv(this.addr,!1,_(e,this.size,4))}function j(t,e){t.uniformMatrix3fv(this.addr,!1,_(e,this.size,9))}function W(t,e){t.uniformMatrix4fv(this.addr,!1,_(e,this.size,16))}function X(t,e,r){var n=e.length,i=M(r,n);t.uniform1iv(this.addr,i);for(var a=0;a!==n;++a)r.setTexture2D(e[a]||ql,i[a])}function Y(t,e,r){var n=e.length,i=M(r,n);t.uniform1iv(this.addr,i);for(var a=0;a!==n;++a)r.setTextureCube(e[a]||Zl,i[a])}function q(t){switch(t){case 5126:return B;case 35664:return k;case 35665:return G;case 35666:return V;case 35674:return H;case 35675:return j;case 35676:return W;case 35678:return X;case 35680:return Y;case 5124:case 35670:return F;case 35667:case 35671:return N;case 35668:case 35672:return D;case 35669:case 35673:return U}}function Z(t,e,r){this.id=t,this.addr=r,this.setValue=z(e.type)}function J(t,e,r){this.id=t,this.addr=r,this.size=e.size,this.setValue=q(e.type)}function Q(t){this.id=t,w.call(this)}function K(t,e){t.seq.push(e),t.map[e.id]=e}function $(t,e,r){var n=t.name,i=n.length;for(th.lastIndex=0;;){var a=th.exec(n),o=th.lastIndex,s=a[1],c="]"===a[2],l=a[3];if(c&&(s|=0),void 0===l||"["===l&&o+2===i){K(r,void 0===l?new Z(s,t,e):new J(s,t,e));break}var h=r.map[s];void 0===h&&K(r,h=new Q(s)),r=h}}function tt(t,e,r){w.call(this),this.renderer=r;for(var n=t.getProgramParameter(e,t.ACTIVE_UNIFORMS),i=0;i.001&&P.scale>.001&&(M.x=P.x,M.y=P.y,M.z=P.z,w=P.size*P.scale/g.w,_.x=w*y,_.y=w,f.uniform3f(u.screenPosition,M.x,M.y,M.z),f.uniform2f(u.scale,_.x,_.y),f.uniform1f(u.rotation,P.rotation),f.uniform1f(u.opacity,P.opacity),f.uniform3f(u.color,P.color.r,P.color.g,P.color.b),m.setBlending(P.blending,P.blendEquation,P.blendSrc,P.blendDst),t.setTexture2D(P.texture,1),f.drawElements(f.TRIANGLES,6,f.UNSIGNED_SHORT,0))}}}m.enable(f.CULL_FACE),m.enable(f.DEPTH_TEST),m.buffers.depth.setMask(!0),t.resetGLState()}}}function nt(t,e){function i(){var t=new Float32Array([-.5,-.5,0,0,.5,-.5,1,0,.5,.5,1,1,-.5,.5,0,1]),e=new Uint16Array([0,1,2,0,2,3]);s=f.createBuffer(),c=f.createBuffer(),f.bindBuffer(f.ARRAY_BUFFER,s),f.bufferData(f.ARRAY_BUFFER,t,f.STATIC_DRAW),f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,c),f.bufferData(f.ELEMENT_ARRAY_BUFFER,e,f.STATIC_DRAW),l=a(),h={position:f.getAttribLocation(l,"position"),uv:f.getAttribLocation(l,"uv")},d={uvOffset:f.getUniformLocation(l,"uvOffset"),uvScale:f.getUniformLocation(l,"uvScale"),rotation:f.getUniformLocation(l,"rotation"),scale:f.getUniformLocation(l,"scale"),color:f.getUniformLocation(l,"color"),map:f.getUniformLocation(l,"map"),opacity:f.getUniformLocation(l,"opacity"),modelViewMatrix:f.getUniformLocation(l,"modelViewMatrix"),projectionMatrix:f.getUniformLocation(l,"projectionMatrix"),fogType:f.getUniformLocation(l,"fogType"),fogDensity:f.getUniformLocation(l,"fogDensity"),fogNear:f.getUniformLocation(l,"fogNear"),fogFar:f.getUniformLocation(l,"fogFar"),fogColor:f.getUniformLocation(l,"fogColor"),alphaTest:f.getUniformLocation(l,"alphaTest")};var r=document.createElementNS("http://www.w3.org/1999/xhtml","canvas");r.width=8,r.height=8;var n=r.getContext("2d");n.fillStyle="white",n.fillRect(0,0,8,8),(p=new u(r)).needsUpdate=!0}function a(){var e=f.createProgram(),r=f.createShader(f.VERTEX_SHADER),n=f.createShader(f.FRAGMENT_SHADER);return f.shaderSource(r,["precision "+t.getPrecision()+" float;","#define SHADER_NAME SpriteMaterial","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")),f.shaderSource(n,["precision "+t.getPrecision()+" float;","#define SHADER_NAME SpriteMaterial","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;","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")),f.compileShader(r),f.compileShader(n),f.attachShader(e,r),f.attachShader(e,n),f.linkProgram(e),e}function o(t,e){return t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:e.id-t.id}var s,c,l,h,d,p,f=t.context,m=t.state,g=new n,v=new r,y=new n;this.render=function(r,n){if(0!==e.length){void 0===l&&i(),f.useProgram(l),m.initAttributes(),m.enableAttribute(h.position),m.enableAttribute(h.uv),m.disableUnusedAttributes(),m.disable(f.CULL_FACE),m.enable(f.BLEND),f.bindBuffer(f.ARRAY_BUFFER,s),f.vertexAttribPointer(h.position,2,f.FLOAT,!1,16,0),f.vertexAttribPointer(h.uv,2,f.FLOAT,!1,16,8),f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,c),f.uniformMatrix4fv(d.projectionMatrix,!1,n.projectionMatrix.elements),m.activeTexture(f.TEXTURE0),f.uniform1i(d.map,0);var a=0,u=0,x=r.fog;x?(f.uniform3f(d.fogColor,x.color.r,x.color.g,x.color.b),x.isFog?(f.uniform1f(d.fogNear,x.near),f.uniform1f(d.fogFar,x.far),f.uniform1i(d.fogType,1),a=1,u=1):x.isFogExp2&&(f.uniform1f(d.fogDensity,x.density),f.uniform1i(d.fogType,2),a=2,u=2)):(f.uniform1i(d.fogType,0),a=0,u=0);for(var b=0,w=e.length;b0&&console.error("THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.")}function ht(t,e){this.normal=void 0!==t?t:new n(1,0,0),this.constant=void 0!==e?e:0}function ut(t,e,r,n,i,a){this.planes=[void 0!==t?t:new ht,void 0!==e?e:new ht,void 0!==r?r:new ht,void 0!==n?n:new ht,void 0!==i?i:new ht,void 0!==a?a:new ht]}function dt(t,r,i,a){function o(e,r,n,i){var a=e.geometry,o=null,s=M,c=e.customDepthMaterial;if(n&&(s=E,c=e.customDistanceMaterial),c)o=c;else{var l=!1;r.morphTargets&&(a&&a.isBufferGeometry?l=a.morphAttributes&&a.morphAttributes.position&&a.morphAttributes.position.length>0:a&&a.isGeometry&&(l=a.morphTargets&&a.morphTargets.length>0)),e.isSkinnedMesh&&!1===r.skinning&&console.warn("THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:",e);var h=e.isSkinnedMesh&&r.skinning,u=0;l&&(u|=b),h&&(u|=w),o=s[u]}if(t.localClippingEnabled&&!0===r.clipShadows&&0!==r.clippingPlanes.length){var d=o.uuid,p=r.uuid,f=S[d];void 0===f&&(f={},S[d]=f);var m=f[p];void 0===m&&(m=o.clone(),f[p]=m),o=m}o.visible=r.visible,o.wireframe=r.wireframe;var g=r.side;return z.renderSingleSided&&g==Qs&&(g=Zs),z.renderReverseSided&&(g===Zs?g=Js:g===Js&&(g=Zs)),o.side=g,o.clipShadows=r.clipShadows,o.clippingPlanes=r.clippingPlanes,o.wireframeLinewidth=r.wireframeLinewidth,o.linewidth=r.linewidth,n&&void 0!==o.uniforms.lightPos&&o.uniforms.lightPos.value.copy(i),o}function s(e,r,n,a){if(!1!==e.visible){if(e.layers.test(r.layers)&&(e.isMesh||e.isLine||e.isPoints)&&e.castShadow&&(!e.frustumCulled||u.intersectsObject(e))){e.modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,e.matrixWorld);var c=i.update(e),l=e.material;if(Array.isArray(l))for(var h=c.groups,d=0,p=h.length;de&&(e=t[r]);return e}function Ct(){Object.defineProperty(this,"id",{value:wt()}),this.uuid=Ko.generateUUID(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0}}function Rt(t,e,r,n,i,a){_t.call(this),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:r,widthSegments:n,heightSegments:i,depthSegments:a},this.fromBufferGeometry(new Pt(t,e,r,n,i,a)),this.mergeVertices()}function Pt(t,e,r,i,a,o){function s(t,e,r,i,a,o,s,m,g,v,y){var x,b,w=o/g,_=s/v,M=o/2,E=s/2,S=m/2,T=g+1,A=v+1,L=0,C=0,R=new n;for(b=0;b0?1:-1,u.push(R.x,R.y,R.z),d.push(x/g),d.push(1-b/v),L+=1}}for(b=0;b65535?St:Et)(i,1),e.update(n,t.ELEMENT_ARRAY_BUFFER),c[r.id]=n,n}var s={},c={};return{get:i,update:a,getWireframeAttribute:o}}function Yt(){var t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];var r;switch(e.type){case"DirectionalLight":r={direction:new n,color:new c,shadow:!1,shadowBias:0,shadowRadius:1,shadowMapSize:new h};break;case"SpotLight":r={position:new n,direction:new n,color:new c,distance:0,coneCos:0,penumbraCos:0,decay:0,shadow:!1,shadowBias:0,shadowRadius:1,shadowMapSize:new h};break;case"PointLight":r={position:new n,color:new c,distance:0,decay:0,shadow:!1,shadowBias:0,shadowRadius:1,shadowMapSize:new h};break;case"HemisphereLight":r={direction:new n,skyColor:new c,groundColor:new c};break;case"RectAreaLight":r={color:new c,position:new n,halfWidth:new n,halfHeight:new n}}return t[e.id]=r,r}}}function qt(t,e,r){function n(t){var n=r.frame,i=t.geometry,o=e.get(t,i);return a[o.id]!==n&&(i.isGeometry&&o.updateFromObject(t),e.update(o),a[o.id]=n),o}function i(){a={}}var a={};return{update:n,clear:i}}function Zt(t){for(var e=t.split("\n"),r=0;r");return oe(r)}return t.replace(/^[ \t]*#include +<([\w\d.]+)>/gm,e)}function se(t){function e(t,e,r,n){for(var i="",a=parseInt(e);a0?t.gammaFactor:1,v=ee(o,i,t.extensions),y=re(s),x=a.createProgram();r.isRawShaderMaterial?(f=[y,"\n"].filter(ie).join("\n"),m=[v,y,"\n"].filter(ie).join("\n")):(f=["precision "+i.precision+" float;","precision "+i.precision+" int;","#define SHADER_NAME "+n.name,y,i.supportsVertexTextures?"#define VERTEX_TEXTURES":"","#define GAMMA_FACTOR "+g,"#define MAX_BONES "+i.maxBones,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+d:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.displacementMap&&i.supportsVertexTextures?"#define USE_DISPLACEMENTMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.vertexColors?"#define USE_COLOR":"",i.flatShading?"#define FLAT_SHADED":"",i.skinning?"#define USE_SKINNING":"",i.useVertexTexture?"#define BONE_TEXTURE":"",i.morphTargets?"#define USE_MORPHTARGETS":"",i.morphNormals&&!1===i.flatShading?"#define USE_MORPHNORMALS":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"","#define NUM_CLIPPING_PLANES "+i.numClippingPlanes,i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+h:"",i.sizeAttenuation?"#define USE_SIZEATTENUATION":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&t.extensions.get("EXT_frag_depth")?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_COLOR","\tattribute vec3 color;","#endif","#ifdef USE_MORPHTARGETS","\tattribute vec3 morphTarget0;","\tattribute vec3 morphTarget1;","\tattribute vec3 morphTarget2;","\tattribute vec3 morphTarget3;","\t#ifdef USE_MORPHNORMALS","\t\tattribute vec3 morphNormal0;","\t\tattribute vec3 morphNormal1;","\t\tattribute vec3 morphNormal2;","\t\tattribute vec3 morphNormal3;","\t#else","\t\tattribute vec3 morphTarget4;","\t\tattribute vec3 morphTarget5;","\t\tattribute vec3 morphTarget6;","\t\tattribute vec3 morphTarget7;","\t#endif","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(ie).join("\n"),m=[v,"precision "+i.precision+" float;","precision "+i.precision+" int;","#define SHADER_NAME "+n.name,y,i.alphaTest?"#define ALPHATEST "+i.alphaTest:"","#define GAMMA_FACTOR "+g,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+u:"",i.envMap?"#define "+d:"",i.envMap?"#define "+p:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.vertexColors?"#define USE_COLOR":"",i.gradientMap?"#define USE_GRADIENTMAP":"",i.flatShading?"#define FLAT_SHADED":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"","#define NUM_CLIPPING_PLANES "+i.numClippingPlanes,"#define UNION_CLIPPING_PLANES "+(i.numClippingPlanes-i.numClipIntersection),i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+h:"",i.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",i.physicallyCorrectLights?"#define PHYSICALLY_CORRECT_LIGHTS":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&t.extensions.get("EXT_frag_depth")?"#define USE_LOGDEPTHBUF_EXT":"",i.envMap&&t.extensions.get("EXT_shader_texture_lod")?"#define TEXTURE_LOD_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;",i.toneMapping!==Uc?"#define TONE_MAPPING":"",i.toneMapping!==Uc?nh.tonemapping_pars_fragment:"",i.toneMapping!==Uc?te("toneMapping",i.toneMapping):"",i.dithering?"#define DITHERING":"",i.outputEncoding||i.mapEncoding||i.envMapEncoding||i.emissiveMapEncoding?nh.encodings_pars_fragment:"",i.mapEncoding?Kt("mapTexelToLinear",i.mapEncoding):"",i.envMapEncoding?Kt("envMapTexelToLinear",i.envMapEncoding):"",i.emissiveMapEncoding?Kt("emissiveMapTexelToLinear",i.emissiveMapEncoding):"",i.outputEncoding?$t("linearToOutputTexel",i.outputEncoding):"",i.depthPacking?"#define DEPTH_PACKING "+r.depthPacking:"","\n"].filter(ie).join("\n")),c=ae(c=oe(c),i),l=ae(l=oe(l),i),r.isShaderMaterial||(c=se(c),l=se(l));var b=f+c,w=m+l,_=Jt(a,a.VERTEX_SHADER,b),M=Jt(a,a.FRAGMENT_SHADER,w);a.attachShader(x,_),a.attachShader(x,M),void 0!==r.index0AttributeName?a.bindAttribLocation(x,0,r.index0AttributeName):!0===i.morphTargets&&a.bindAttribLocation(x,0,"position"),a.linkProgram(x);var E=a.getProgramInfoLog(x),S=a.getShaderInfoLog(_),T=a.getShaderInfoLog(M),A=!0,L=!0;!1===a.getProgramParameter(x,a.LINK_STATUS)?(A=!1,console.error("THREE.WebGLProgram: shader error: ",a.getError(),"gl.VALIDATE_STATUS",a.getProgramParameter(x,a.VALIDATE_STATUS),"gl.getProgramInfoLog",E,S,T)):""!==E?console.warn("THREE.WebGLProgram: gl.getProgramInfoLog()",E):""!==S&&""!==T||(L=!1),L&&(this.diagnostics={runnable:A,material:r,programLog:E,vertexShader:{log:S,prefix:f},fragmentShader:{log:T,prefix:m}}),a.deleteShader(_),a.deleteShader(M);var C;this.getUniforms=function(){return void 0===C&&(C=new tt(a,x,t)),C};var R;return this.getAttributes=function(){return void 0===R&&(R=ne(a,x)),R},this.destroy=function(){a.deleteProgram(x),this.program=void 0},Object.defineProperties(this,{uniforms:{get:function(){return console.warn("THREE.WebGLProgram: .uniforms is now .getUniforms()."),this.getUniforms()}},attributes:{get:function(){return console.warn("THREE.WebGLProgram: .attributes is now .getAttributes()."),this.getAttributes()}}}),this.id=ch++,this.code=e,this.usedTimes=1,this.program=x,this.vertexShader=_,this.fragmentShader=M,this}function le(t,e){function r(t){var r=t.skeleton.bones;if(e.floatVertexTextures)return 1024;var n=e.maxVertexUniforms,i=Math.floor((n-20)/4),a=Math.min(i,r.length);return a0,maxBones:d,useVertexTexture:e.floatVertexTextures,morphTargets:i.morphTargets,morphNormals:i.morphNormals,maxMorphTargets:t.maxMorphTargets,maxMorphNormals:t.maxMorphNormals,numDirLights:o.directional.length,numPointLights:o.point.length,numSpotLights:o.spot.length,numRectAreaLights:o.rectArea.length,numHemiLights:o.hemi.length,numClippingPlanes:c,numClipIntersection:l,dithering:i.dithering,shadowMapEnabled:t.shadowMap.enabled&&h.receiveShadow&&o.shadows.length>0,shadowMapType:t.shadowMap.type,toneMapping:t.toneMapping,physicallyCorrectLights:t.physicallyCorrectLights,premultipliedAlpha:i.premultipliedAlpha,alphaTest:i.alphaTest,doubleSided:i.side===Qs,flipSided:i.side===Js,depthPacking:void 0!==i.depthPacking&&i.depthPacking}},this.getProgramCode=function(e,r){var n=[];if(r.shaderID?n.push(r.shaderID):(n.push(e.fragmentShader),n.push(e.vertexShader)),void 0!==e.defines)for(var i in e.defines)n.push(i),n.push(e.defines[i]);for(var a=0;ae||t.height>e){var r=e/Math.max(t.width,t.height),n=document.createElementNS("http://www.w3.org/1999/xhtml","canvas");return n.width=Math.floor(t.width*r),n.height=Math.floor(t.height*r),n.getContext("2d").drawImage(t,0,0,t.width,t.height,0,0,n.width,n.height),console.warn("THREE.WebGLRenderer: image is too big ("+t.width+"x"+t.height+"). Resized to "+n.width+"x"+n.height,t),n}return t}function c(t){return Ko.isPowerOfTwo(t.width)&&Ko.isPowerOfTwo(t.height)}function l(t){if(t instanceof HTMLImageElement||t instanceof HTMLCanvasElement){var e=document.createElementNS("http://www.w3.org/1999/xhtml","canvas");return e.width=Ko.nearestPowerOfTwo(t.width),e.height=Ko.nearestPowerOfTwo(t.height),e.getContext("2d").drawImage(t,0,0,e.width,e.height),console.warn("THREE.WebGLRenderer: image is not power of two ("+t.width+"x"+t.height+"). Resized to "+e.width+"x"+e.height,t),e}return t}function h(t){return t.wrapS!==Zc||t.wrapT!==Zc||t.minFilter!==Qc&&t.minFilter!==tl}function u(t,e){return t.generateMipmaps&&e&&t.minFilter!==Qc&&t.minFilter!==tl}function d(e){return e===Qc||e===Kc||e===$c?t.NEAREST:t.LINEAR}function p(t){var e=t.target;e.removeEventListener("dispose",p),m(e),o.textures--}function f(t){var e=t.target;e.removeEventListener("dispose",f),g(e),o.textures--}function m(e){var r=n.get(e);if(e.image&&r.__image__webglTextureCube)t.deleteTexture(r.__image__webglTextureCube);else{if(void 0===r.__webglInit)return;t.deleteTexture(r.__webglTexture)}n.remove(e)}function g(e){var r=n.get(e),i=n.get(e.texture);if(e){if(void 0!==i.__webglTexture&&t.deleteTexture(i.__webglTexture),e.depthTexture&&e.depthTexture.dispose(),e.isWebGLRenderTargetCube)for(var a=0;a<6;a++)t.deleteFramebuffer(r.__webglFramebuffer[a]),r.__webglDepthbuffer&&t.deleteRenderbuffer(r.__webglDepthbuffer[a]);else t.deleteFramebuffer(r.__webglFramebuffer),r.__webglDepthbuffer&&t.deleteRenderbuffer(r.__webglDepthbuffer);n.remove(e.texture),n.remove(e)}}function v(e,i){var a=n.get(e);if(e.version>0&&a.__version!==e.version){var o=e.image;if(void 0===o)console.warn("THREE.WebGLRenderer: Texture marked for update but image is undefined",e);else{if(!1!==o.complete)return void w(a,e,i);console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete",e)}}r.activeTexture(t.TEXTURE0+i),r.bindTexture(t.TEXTURE_2D,a.__webglTexture)}function y(e,l){var h=n.get(e);if(6===e.image.length)if(e.version>0&&h.__version!==e.version){h.__image__webglTextureCube||(e.addEventListener("dispose",p),h.__image__webglTextureCube=t.createTexture(),o.textures++),r.activeTexture(t.TEXTURE0+l),r.bindTexture(t.TEXTURE_CUBE_MAP,h.__image__webglTextureCube),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,e.flipY);for(var d=e&&e.isCompressedTexture,f=e.image[0]&&e.image[0].isDataTexture,m=[],g=0;g<6;g++)m[g]=d||f?f?e.image[g].image:e.image[g]:s(e.image[g],i.maxCubemapSize);var v=c(m[0]),y=a(e.format),x=a(e.type);b(t.TEXTURE_CUBE_MAP,e,v);for(g=0;g<6;g++)if(d)for(var w,_=m[g].mipmaps,M=0,E=_.length;M-1?r.compressedTexImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+g,M,y,w.width,w.height,0,w.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):r.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+g,M,y,w.width,w.height,0,y,x,w.data);else f?r.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,y,m[g].width,m[g].height,0,y,x,m[g].data):r.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+g,0,y,y,x,m[g]);u(e,v)&&t.generateMipmap(t.TEXTURE_CUBE_MAP),h.__version=e.version,e.onUpdate&&e.onUpdate(e)}else r.activeTexture(t.TEXTURE0+l),r.bindTexture(t.TEXTURE_CUBE_MAP,h.__image__webglTextureCube)}function x(e,i){r.activeTexture(t.TEXTURE0+i),r.bindTexture(t.TEXTURE_CUBE_MAP,n.get(e).__webglTexture)}function b(r,o,s){var c;if(s?(t.texParameteri(r,t.TEXTURE_WRAP_S,a(o.wrapS)),t.texParameteri(r,t.TEXTURE_WRAP_T,a(o.wrapT)),t.texParameteri(r,t.TEXTURE_MAG_FILTER,a(o.magFilter)),t.texParameteri(r,t.TEXTURE_MIN_FILTER,a(o.minFilter))):(t.texParameteri(r,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(r,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),o.wrapS===Zc&&o.wrapT===Zc||console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.",o),t.texParameteri(r,t.TEXTURE_MAG_FILTER,d(o.magFilter)),t.texParameteri(r,t.TEXTURE_MIN_FILTER,d(o.minFilter)),o.minFilter!==Qc&&o.minFilter!==tl&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.",o)),c=e.get("EXT_texture_filter_anisotropic")){if(o.type===ll&&null===e.get("OES_texture_float_linear"))return;if(o.type===hl&&null===e.get("OES_texture_half_float_linear"))return;(o.anisotropy>1||n.get(o).__currentAnisotropy)&&(t.texParameterf(r,c.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(o.anisotropy,i.getMaxAnisotropy())),n.get(o).__currentAnisotropy=o.anisotropy)}}function w(e,n,d){void 0===e.__webglInit&&(e.__webglInit=!0,n.addEventListener("dispose",p),e.__webglTexture=t.createTexture(),o.textures++),r.activeTexture(t.TEXTURE0+d),r.bindTexture(t.TEXTURE_2D,e.__webglTexture),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,n.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,n.unpackAlignment);var f=s(n.image,i.maxTextureSize);h(n)&&!1===c(f)&&(f=l(f));var m=c(f),g=a(n.format),v=a(n.type);b(t.TEXTURE_2D,n,m);var y,x=n.mipmaps;if(n.isDepthTexture){var w=t.DEPTH_COMPONENT;if(n.type===ll){if(!L)throw new Error("Float Depth Texture only supported in WebGL2.0");w=t.DEPTH_COMPONENT32F}else L&&(w=t.DEPTH_COMPONENT16);n.format===bl&&w===t.DEPTH_COMPONENT&&n.type!==ol&&n.type!==cl&&(console.warn("THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture."),n.type=ol,v=a(n.type)),n.format===wl&&(w=t.DEPTH_STENCIL,n.type!==fl&&(console.warn("THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture."),n.type=fl,v=a(n.type))),r.texImage2D(t.TEXTURE_2D,0,w,f.width,f.height,0,g,v,null)}else if(n.isDataTexture)if(x.length>0&&m){for(var _=0,M=x.length;_-1?r.compressedTexImage2D(t.TEXTURE_2D,_,g,y.width,y.height,0,y.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):r.texImage2D(t.TEXTURE_2D,_,g,y.width,y.height,0,g,v,y.data);else if(x.length>0&&m){for(var _=0,M=x.length;_=1,nt=null,it={},at=new y,ot=new y,st={};return st[t.TEXTURE_2D]=o(t.TEXTURE_2D,t.TEXTURE_2D,1),st[t.TEXTURE_CUBE_MAP]=o(t.TEXTURE_CUBE_MAP,t.TEXTURE_CUBE_MAP_POSITIVE_X,6),{buffers:{color:P,depth:I,stencil:O},init:s,initAttributes:c,enableAttribute:l,enableAttributeAndDivisor:h,disableUnusedAttributes:u,enable:d,disable:p,getCompressedTextureFormats:f,setBlending:m,setMaterial:g,setFlipSided:v,setCullFace:x,setLineWidth:b,setPolygonOffset:w,getScissorTest:_,setScissorTest:M,activeTexture:E,bindTexture:S,compressedTexImage2D:T,texImage2D:A,scissor:L,viewport:C,reset:R}}function pe(t,e,r){function n(){if(void 0!==a)return a;var r=e.get("EXT_texture_filter_anisotropic");return a=null!==r?t.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0}function i(e){if("highp"===e){if(t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.HIGH_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0)return"highp";e="mediump"}return"mediump"===e&&t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}var a,o=void 0!==r.precision?r.precision:"highp",s=i(o);s!==o&&(console.warn("THREE.WebGLRenderer:",o,"not supported, using",s,"instead."),o=s);var c=!0===r.logarithmicDepthBuffer&&!!e.get("EXT_frag_depth"),l=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),h=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS),u=t.getParameter(t.MAX_TEXTURE_SIZE),d=t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),p=t.getParameter(t.MAX_VERTEX_ATTRIBS),f=t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),m=t.getParameter(t.MAX_VARYING_VECTORS),g=t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),v=h>0,y=!!e.get("OES_texture_float");return{getMaxAnisotropy:n,getMaxPrecision:i,precision:o,logarithmicDepthBuffer:c,maxTextures:l,maxVertexTextures:h,maxTextureSize:u,maxCubemapSize:d,maxAttributes:p,maxVertexUniforms:f,maxVaryings:m,maxFragmentUniforms:g,vertexTextures:v,floatFragmentTextures:y,floatVertexTextures:v&&y}}function fe(t){xt.call(this),this.cameras=t||[]}function me(t){function r(){if(i.isPresenting){var e=i.getEyeParameters("left"),r=e.renderWidth,a=e.renderHeight;p=t.getPixelRatio(),d=t.getSize(),t.setDrawingBufferSize(2*r,a,1)}else n.enabled&&t.setDrawingBufferSize(d.width,d.height,p)}var n=this,i=null,a=null;"VRFrameData"in window&&(a=new window.VRFrameData);var o=new e,s=new e,c=new e,l=new xt;l.bounds=new y(0,0,.5,1),l.layers.enable(1);var h=new xt;h.bounds=new y(.5,0,.5,1),h.layers.enable(2);var u=new fe([l,h]);u.layers.enable(1),u.layers.enable(2);var d,p;window.addEventListener("vrdisplaypresentchange",r,!1),this.enabled=!1,this.standing=!1,this.getDevice=function(){return i},this.setDevice=function(t){void 0!==t&&(i=t)},this.getCamera=function(t){if(null===i)return t;i.depthNear=t.near,i.depthFar=t.far,i.getFrameData(a);var e=a.pose;null!==e.position?t.position.fromArray(e.position):t.position.set(0,0,0),null!==e.orientation&&t.quaternion.fromArray(e.orientation),t.updateMatrixWorld();var r=i.stageParameters;if(this.standing&&r&&(s.fromArray(r.sittingToStandingTransform),c.getInverse(s),t.matrixWorld.multiply(s),t.matrixWorldInverse.multiply(c)),!1===i.isPresenting)return t;u.matrixWorld.copy(t.matrixWorld),u.matrixWorldInverse.copy(t.matrixWorldInverse),l.matrixWorldInverse.fromArray(a.leftViewMatrix),h.matrixWorldInverse.fromArray(a.rightViewMatrix),this.standing&&r&&(l.matrixWorldInverse.multiply(c),h.matrixWorldInverse.multiply(c));var n=t.parent;null!==n&&(o.getInverse(n.matrixWorld),l.matrixWorldInverse.multiply(o),h.matrixWorldInverse.multiply(o)),l.matrixWorld.getInverse(l.matrixWorldInverse),h.matrixWorld.getInverse(h.matrixWorldInverse),l.projectionMatrix.fromArray(a.leftProjectionMatrix),h.projectionMatrix.fromArray(a.rightProjectionMatrix),u.projectionMatrix.copy(l.projectionMatrix);var d=i.getLayers();if(d.length){var p=d[0];null!==p.leftBounds&&4===p.leftBounds.length&&l.bounds.fromArray(p.leftBounds),null!==p.rightBounds&&4===p.rightBounds.length&&h.bounds.fromArray(p.rightBounds)}return u},this.getStandingMatrix=function(){return s},this.submitFrame=function(){i&&i.isPresenting&&i.submitFrame()}}function ge(t){var e={};return{get:function(r){if(void 0!==e[r])return e[r];var n;switch(r){case"WEBGL_depth_texture":n=t.getExtension("WEBGL_depth_texture")||t.getExtension("MOZ_WEBGL_depth_texture")||t.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=t.getExtension("EXT_texture_filter_anisotropic")||t.getExtension("MOZ_EXT_texture_filter_anisotropic")||t.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=t.getExtension("WEBGL_compressed_texture_s3tc")||t.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;case"WEBGL_compressed_texture_etc1":n=t.getExtension("WEBGL_compressed_texture_etc1");break;default:n=t.getExtension(r)}return null===n&&console.warn("THREE.WebGLRenderer: "+r+" extension not supported."),e[r]=n,n}}}function ve(){function t(){l.value!==n&&(l.value=n,l.needsUpdate=i>0),r.numPlanes=i,r.numIntersection=0}function e(t,e,n,i){var a=null!==t?t.length:0,o=null;if(0!==a){if(o=l.value,!0!==i||null===o){var h=n+4*a,u=e.matrixWorldInverse;c.getNormalMatrix(u),(null===o||o.length=0){var l=i[s];if(void 0!==l){var h=l.normalized,u=l.itemSize,d=Bt.get(l),p=d.buffer,f=d.type,m=d.bytesPerElement;if(l.isInterleavedBufferAttribute){var g=l.data,v=g.stride,y=l.offset;g&&g.isInstancedInterleavedBuffer?(Dt.enableAttributeAndDivisor(c,g.meshPerAttribute),void 0===r.maxInstancedCount&&(r.maxInstancedCount=g.meshPerAttribute*g.count)):Dt.enableAttribute(c),Pt.bindBuffer(Pt.ARRAY_BUFFER,p),Pt.vertexAttribPointer(c,u,f,h,v*m,(n*v+y)*m)}else l.isInstancedBufferAttribute?(Dt.enableAttributeAndDivisor(c,l.meshPerAttribute),void 0===r.maxInstancedCount&&(r.maxInstancedCount=l.meshPerAttribute*l.count)):Dt.enableAttribute(c),Pt.bindBuffer(Pt.ARRAY_BUFFER,p),Pt.vertexAttribPointer(c,u,f,h,0,n*u*m)}else if(void 0!==o){var x=o[s];if(void 0!==x)switch(x.length){case 2:Pt.vertexAttrib2fv(c,x);break;case 3:Pt.vertexAttrib3fv(c,x);break;case 4:Pt.vertexAttrib4fv(c,x);break;default:Pt.vertexAttrib1fv(c,x)}}}}Dt.disableUnusedAttributes()}function f(t,e,r){if(t.visible){if(t.layers.test(e.layers))if(t.isLight)j.push(t);else if(t.isSprite)t.frustumCulled&&!xt.intersectsSprite(t)||Y.push(t);else if(t.isLensFlare)q.push(t);else if(t.isImmediateRenderObject)r&&Et.setFromMatrixPosition(t.matrixWorld).applyMatrix4(Mt),W.push(t,null,t.material,Et.z,null);else if((t.isMesh||t.isLine||t.isPoints)&&(t.isSkinnedMesh&&t.skeleton.update(),!t.frustumCulled||xt.intersectsObject(t))){r&&Et.setFromMatrixPosition(t.matrixWorld).applyMatrix4(Mt);var n=Gt.update(t),i=t.material;if(Array.isArray(i))for(var a=n.groups,o=0,s=a.length;o=0&&t.numSupportedMorphTargets++}if(t.morphNormals){t.numSupportedMorphNormals=0;for(var d=0;d=0&&t.numSupportedMorphNormals++}var p=n.shader.uniforms;(t.isShaderMaterial||t.isRawShaderMaterial)&&!0!==t.clipping||(n.numClippingPlanes=bt.numPlanes,n.numIntersection=bt.numIntersection,p.clippingPlanes=bt.uniform),n.fog=e,n.lightsHash=At.hash,t.lights&&(p.ambientLightColor.value=At.ambient,p.directionalLights.value=At.directional,p.spotLights.value=At.spot,p.rectAreaLights.value=At.rectArea,p.pointLights.value=At.point,p.hemisphereLights.value=At.hemi,p.directionalShadowMap.value=At.directionalShadowMap,p.directionalShadowMatrix.value=At.directionalShadowMatrix,p.spotShadowMap.value=At.spotShadowMap,p.spotShadowMatrix.value=At.spotShadowMatrix,p.pointShadowMap.value=At.pointShadowMap,p.pointShadowMatrix.value=At.pointShadowMatrix);var f=n.program.getUniforms(),m=tt.seqWithValue(f.seq,p);n.uniformsList=m}function x(t,e,r,n){lt=0;var i=Ut.get(r);if(wt&&(_t||t!==it)){var a=t===it&&r.id===$;bt.setState(r.clippingPlanes,r.clipIntersection,r.clipShadows,t,i,a)}!1===r.needsUpdate&&(void 0===i.program?r.needsUpdate=!0:r.fog&&i.fog!==e?r.needsUpdate=!0:r.lights&&i.lightsHash!==At.hash?r.needsUpdate=!0:void 0===i.numClippingPlanes||i.numClippingPlanes===bt.numPlanes&&i.numIntersection===bt.numIntersection||(r.needsUpdate=!0)),r.needsUpdate&&(v(r,e,n),r.needsUpdate=!1);var o=!1,s=!1,c=!1,l=i.program,h=l.getUniforms(),u=i.shader.uniforms;if(l.id!==J&&(Pt.useProgram(l.program),J=l.id,o=!0,s=!0,c=!0),r.id!==$&&($=r.id,s=!0),o||t!==it){if(h.setValue(Pt,"projectionMatrix",t.projectionMatrix),Nt.logarithmicDepthBuffer&&h.setValue(Pt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),it!==(at||t)&&(it=at||t,s=!0,c=!0),r.isShaderMaterial||r.isMeshPhongMaterial||r.isMeshStandardMaterial||r.envMap){var p=h.map.cameraPosition;void 0!==p&&p.setValue(Pt,Et.setFromMatrixPosition(t.matrixWorld))}(r.isMeshPhongMaterial||r.isMeshLambertMaterial||r.isMeshBasicMaterial||r.isMeshStandardMaterial||r.isShaderMaterial||r.skinning)&&h.setValue(Pt,"viewMatrix",t.matrixWorldInverse)}if(r.skinning){h.setOptional(Pt,n,"bindMatrix"),h.setOptional(Pt,n,"bindMatrixInverse");var f=n.skeleton;if(f){var m=f.bones;if(Nt.floatVertexTextures){if(void 0===f.boneTexture){var g=Math.sqrt(4*m.length);g=Ko.nextPowerOfTwo(Math.ceil(g)),g=Math.max(g,4);var y=new Float32Array(g*g*4);y.set(f.boneMatrices);var x=new d(y,g,g,vl,ll);f.boneMatrices=y,f.boneTexture=x,f.boneTextureSize=g}h.setValue(Pt,"boneTexture",f.boneTexture),h.setValue(Pt,"boneTextureSize",f.boneTextureSize)}else h.setOptional(Pt,f,"boneMatrices")}}return s&&(h.setValue(Pt,"toneMappingExposure",Z.toneMappingExposure),h.setValue(Pt,"toneMappingWhitePoint",Z.toneMappingWhitePoint),r.lights&&P(u,c),e&&r.fog&&E(u,e),(r.isMeshBasicMaterial||r.isMeshLambertMaterial||r.isMeshPhongMaterial||r.isMeshStandardMaterial||r.isMeshNormalMaterial||r.isMeshDepthMaterial)&&b(u,r),r.isLineBasicMaterial?w(u,r):r.isLineDashedMaterial?(w(u,r),_(u,r)):r.isPointsMaterial?M(u,r):r.isMeshLambertMaterial?S(u,r):r.isMeshToonMaterial?A(u,r):r.isMeshPhongMaterial?T(u,r):r.isMeshPhysicalMaterial?C(u,r):r.isMeshStandardMaterial?L(u,r):r.isMeshDepthMaterial?r.displacementMap&&(u.displacementMap.value=r.displacementMap,u.displacementScale.value=r.displacementScale,u.displacementBias.value=r.displacementBias):r.isMeshNormalMaterial&&R(u,r),void 0!==u.ltcMat&&(u.ltcMat.value=eh.LTC_MAT_TEXTURE),void 0!==u.ltcMag&&(u.ltcMag.value=eh.LTC_MAG_TEXTURE),tt.upload(Pt,i.uniformsList,u,Z)),h.setValue(Pt,"modelViewMatrix",n.modelViewMatrix),h.setValue(Pt,"normalMatrix",n.normalMatrix),h.setValue(Pt,"modelMatrix",n.matrixWorld),l}function b(t,e){t.opacity.value=e.opacity,t.diffuse.value=e.color,e.emissive&&t.emissive.value.copy(e.emissive).multiplyScalar(e.emissiveIntensity),t.map.value=e.map,t.specularMap.value=e.specularMap,t.alphaMap.value=e.alphaMap,e.lightMap&&(t.lightMap.value=e.lightMap,t.lightMapIntensity.value=e.lightMapIntensity),e.aoMap&&(t.aoMap.value=e.aoMap,t.aoMapIntensity.value=e.aoMapIntensity);var r;if(e.map?r=e.map:e.specularMap?r=e.specularMap:e.displacementMap?r=e.displacementMap:e.normalMap?r=e.normalMap:e.bumpMap?r=e.bumpMap:e.roughnessMap?r=e.roughnessMap:e.metalnessMap?r=e.metalnessMap:e.alphaMap?r=e.alphaMap:e.emissiveMap&&(r=e.emissiveMap),void 0!==r){r.isWebGLRenderTarget&&(r=r.texture);var n=r.offset,i=r.repeat;t.offsetRepeat.value.set(n.x,n.y,i.x,i.y)}t.envMap.value=e.envMap,t.flipEnvMap.value=e.envMap&&e.envMap.isCubeTexture?-1:1,t.reflectivity.value=e.reflectivity,t.refractionRatio.value=e.refractionRatio}function w(t,e){t.diffuse.value=e.color,t.opacity.value=e.opacity}function _(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}function M(t,e){if(t.diffuse.value=e.color,t.opacity.value=e.opacity,t.size.value=e.size*mt,t.scale.value=.5*ft,t.map.value=e.map,null!==e.map){var r=e.map.offset,n=e.map.repeat;t.offsetRepeat.value.set(r.x,r.y,n.x,n.y)}}function E(t,e){t.fogColor.value=e.color,e.isFog?(t.fogNear.value=e.near,t.fogFar.value=e.far):e.isFogExp2&&(t.fogDensity.value=e.density)}function S(t,e){e.emissiveMap&&(t.emissiveMap.value=e.emissiveMap)}function T(t,e){t.specular.value=e.specular,t.shininess.value=Math.max(e.shininess,1e-4),e.emissiveMap&&(t.emissiveMap.value=e.emissiveMap),e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale)),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}function A(t,e){T(t,e),e.gradientMap&&(t.gradientMap.value=e.gradientMap)}function L(t,e){t.roughness.value=e.roughness,t.metalness.value=e.metalness,e.roughnessMap&&(t.roughnessMap.value=e.roughnessMap),e.metalnessMap&&(t.metalnessMap.value=e.metalnessMap),e.emissiveMap&&(t.emissiveMap.value=e.emissiveMap),e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale)),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias),e.envMap&&(t.envMapIntensity.value=e.envMapIntensity)}function C(t,e){t.clearCoat.value=e.clearCoat,t.clearCoatRoughness.value=e.clearCoatRoughness,L(t,e)}function R(t,e){e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale)),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}function P(t,e){t.ambientLightColor.needsUpdate=e,t.directionalLights.needsUpdate=e,t.pointLights.needsUpdate=e,t.spotLights.needsUpdate=e,t.rectAreaLights.needsUpdate=e,t.hemisphereLights.needsUpdate=e}function I(t){for(var e=0,r=0,n=t.length;r=Nt.maxTextures&&console.warn("THREE.WebGLRenderer: Trying to use "+t+" texture units while this GPU supports only "+Nt.maxTextures),lt+=1,t}function D(t){var e;if(t===qc)return Pt.REPEAT;if(t===Zc)return Pt.CLAMP_TO_EDGE;if(t===Jc)return Pt.MIRRORED_REPEAT;if(t===Qc)return Pt.NEAREST;if(t===Kc)return Pt.NEAREST_MIPMAP_NEAREST;if(t===$c)return Pt.NEAREST_MIPMAP_LINEAR;if(t===tl)return Pt.LINEAR;if(t===el)return Pt.LINEAR_MIPMAP_NEAREST;if(t===rl)return Pt.LINEAR_MIPMAP_LINEAR;if(t===nl)return Pt.UNSIGNED_BYTE;if(t===ul)return Pt.UNSIGNED_SHORT_4_4_4_4;if(t===dl)return Pt.UNSIGNED_SHORT_5_5_5_1;if(t===pl)return Pt.UNSIGNED_SHORT_5_6_5;if(t===il)return Pt.BYTE;if(t===al)return Pt.SHORT;if(t===ol)return Pt.UNSIGNED_SHORT;if(t===sl)return Pt.INT;if(t===cl)return Pt.UNSIGNED_INT;if(t===ll)return Pt.FLOAT;if(t===hl&&null!==(e=Ot.get("OES_texture_half_float")))return e.HALF_FLOAT_OES;if(t===ml)return Pt.ALPHA;if(t===gl)return Pt.RGB;if(t===vl)return Pt.RGBA;if(t===yl)return Pt.LUMINANCE;if(t===xl)return Pt.LUMINANCE_ALPHA;if(t===bl)return Pt.DEPTH_COMPONENT;if(t===wl)return Pt.DEPTH_STENCIL;if(t===lc)return Pt.FUNC_ADD;if(t===hc)return Pt.FUNC_SUBTRACT;if(t===uc)return Pt.FUNC_REVERSE_SUBTRACT;if(t===fc)return Pt.ZERO;if(t===mc)return Pt.ONE;if(t===gc)return Pt.SRC_COLOR;if(t===vc)return Pt.ONE_MINUS_SRC_COLOR;if(t===yc)return Pt.SRC_ALPHA;if(t===xc)return Pt.ONE_MINUS_SRC_ALPHA;if(t===bc)return Pt.DST_ALPHA;if(t===wc)return Pt.ONE_MINUS_DST_ALPHA;if(t===_c)return Pt.DST_COLOR;if(t===Mc)return Pt.ONE_MINUS_DST_COLOR;if(t===Ec)return Pt.SRC_ALPHA_SATURATE;if((t===_l||t===Ml||t===El||t===Sl)&&null!==(e=Ot.get("WEBGL_compressed_texture_s3tc"))){if(t===_l)return e.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===Ml)return e.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===El)return e.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(t===Sl)return e.COMPRESSED_RGBA_S3TC_DXT5_EXT}if((t===Tl||t===Al||t===Ll||t===Cl)&&null!==(e=Ot.get("WEBGL_compressed_texture_pvrtc"))){if(t===Tl)return e.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(t===Al)return e.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(t===Ll)return e.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(t===Cl)return e.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(t===Rl&&null!==(e=Ot.get("WEBGL_compressed_texture_etc1")))return e.COMPRESSED_RGB_ETC1_WEBGL;if((t===dc||t===pc)&&null!==(e=Ot.get("EXT_blend_minmax"))){if(t===dc)return e.MIN_EXT;if(t===pc)return e.MAX_EXT}return t===fl&&null!==(e=Ot.get("WEBGL_depth_texture"))?e.UNSIGNED_INT_24_8_WEBGL:0}console.log("THREE.WebGLRenderer",Gs);var U=void 0!==(t=t||{}).canvas?t.canvas:document.createElementNS("http://www.w3.org/1999/xhtml","canvas"),z=void 0!==t.context?t.context:null,B=void 0!==t.alpha&&t.alpha,F=void 0===t.depth||t.depth,k=void 0===t.stencil||t.stencil,G=void 0!==t.antialias&&t.antialias,V=void 0===t.premultipliedAlpha||t.premultipliedAlpha,H=void 0!==t.preserveDrawingBuffer&&t.preserveDrawingBuffer,j=[],W=null,X=new Float32Array(8),Y=[],q=[];this.domElement=U,this.context=null,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.gammaFactor=2,this.gammaInput=!1,this.gammaOutput=!1,this.physicallyCorrectLights=!1,this.toneMapping=zc,this.toneMappingExposure=1,this.toneMappingWhitePoint=1,this.maxMorphTargets=8,this.maxMorphNormals=4;var Z=this,J=null,Q=null,K=null,$=-1,et="",it=null,at=null,ot=new y,st=null,ct=new y,lt=0,ht=U.width,ft=U.height,mt=1,gt=new y(0,0,ht,ft),vt=!1,yt=new y(0,0,ht,ft),xt=new ut,bt=new ve,wt=!1,_t=!1,Mt=new e,Et=new n,St=new e,Tt=new e,At={hash:"",ambient:[0,0,0],directional:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotShadowMap:[],spotShadowMatrix:[],rectArea:[],point:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],shadows:[]},Lt={geometries:0,textures:0},Rt={frame:0,calls:0,vertices:0,faces:0,points:0};this.info={render:Rt,memory:Lt,programs:null};var Pt;try{var It={alpha:B,depth:F,stencil:k,antialias:G,premultipliedAlpha:V,preserveDrawingBuffer:H};if(null===(Pt=z||U.getContext("webgl",It)||U.getContext("experimental-webgl",It)))throw null!==U.getContext("webgl")?"Error creating WebGL context with your selected attributes.":"Error creating WebGL context.";void 0===Pt.getShaderPrecisionFormat&&(Pt.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}}),U.addEventListener("webglcontextlost",o,!1)}catch(t){console.error("THREE.WebGLRenderer: "+t)}var Ot=new ge(Pt);Ot.get("WEBGL_depth_texture"),Ot.get("OES_texture_float"),Ot.get("OES_texture_float_linear"),Ot.get("OES_texture_half_float"),Ot.get("OES_texture_half_float_linear"),Ot.get("OES_standard_derivatives"),Ot.get("ANGLE_instanced_arrays"),Ot.get("OES_element_index_uint")&&(Ct.MaxIndex=4294967296);var Nt=new pe(Pt,Ot,t),Dt=new de(Pt,Ot,D),Ut=new ue,zt=new he(Pt,Ot,Dt,Ut,Nt,D,Lt),Bt=new pt(Pt),kt=new Xt(Pt,Bt,Lt),Gt=new qt(Pt,kt,Rt),Vt=new le(this,Nt),Zt=new Yt,Jt=new Ht,Qt=new Ft(this,Dt,Gt,V),Kt=new me(this);this.info.programs=Vt.programs;var $t=new Wt(Pt,Ot,Rt),te=new jt(Pt,Ot,Rt);i(),this.context=Pt,this.capabilities=Nt,this.extensions=Ot,this.properties=Ut,this.renderLists=Jt,this.state=Dt,this.vr=Kt;var ee=new dt(this,At,Gt,Nt);this.shadowMap=ee;var re=new nt(this,Y),ne=new rt(this,q);this.getContext=function(){return Pt},this.getContextAttributes=function(){return Pt.getContextAttributes()},this.forceContextLoss=function(){var t=Ot.get("WEBGL_lose_context");t&&t.loseContext()},this.getMaxAnisotropy=function(){return Nt.getMaxAnisotropy()},this.getPrecision=function(){return Nt.precision},this.getPixelRatio=function(){return mt},this.setPixelRatio=function(t){void 0!==t&&(mt=t,this.setSize(ht,ft,!1))},this.getSize=function(){return{width:ht,height:ft}},this.setSize=function(t,e,r){var n=Kt.getDevice();if(n&&n.isPresenting)return void console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting.");ht=t,ft=e,U.width=t*mt,U.height=e*mt,!1!==r&&(U.style.width=t+"px",U.style.height=e+"px"),this.setViewport(0,0,t,e)},this.getDrawingBufferSize=function(){return{width:ht*mt,height:ft*mt}},this.setDrawingBufferSize=function(t,e,r){ht=t,ft=e,mt=r,U.width=t*r,U.height=e*r,this.setViewport(0,0,t,e)},this.setViewport=function(t,e,r,n){yt.set(t,ft-e-n,r,n),Dt.viewport(ct.copy(yt).multiplyScalar(mt))},this.setScissor=function(t,e,r,n){gt.set(t,ft-e-n,r,n),Dt.scissor(ot.copy(gt).multiplyScalar(mt))},this.setScissorTest=function(t){Dt.setScissorTest(vt=t)},this.getClearColor=Qt.getClearColor,this.setClearColor=Qt.setClearColor,this.getClearAlpha=Qt.getClearAlpha,this.setClearAlpha=Qt.setClearAlpha,this.clear=function(t,e,r){var n=0;(void 0===t||t)&&(n|=Pt.COLOR_BUFFER_BIT),(void 0===e||e)&&(n|=Pt.DEPTH_BUFFER_BIT),(void 0===r||r)&&(n|=Pt.STENCIL_BUFFER_BIT),Pt.clear(n)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.clearTarget=function(t,e,r,n){this.setRenderTarget(t),this.clear(e,r,n)},this.resetGLState=a,this.dispose=function(){U.removeEventListener("webglcontextlost",o,!1),Jt.dispose()},this.renderBufferImmediate=function(t,e,r){Dt.initAttributes();var n=Ut.get(t);t.hasPositions&&!n.position&&(n.position=Pt.createBuffer()),t.hasNormals&&!n.normal&&(n.normal=Pt.createBuffer()),t.hasUvs&&!n.uv&&(n.uv=Pt.createBuffer()),t.hasColors&&!n.color&&(n.color=Pt.createBuffer());var i=e.getAttributes();if(t.hasPositions&&(Pt.bindBuffer(Pt.ARRAY_BUFFER,n.position),Pt.bufferData(Pt.ARRAY_BUFFER,t.positionArray,Pt.DYNAMIC_DRAW),Dt.enableAttribute(i.position),Pt.vertexAttribPointer(i.position,3,Pt.FLOAT,!1,0,0)),t.hasNormals){if(Pt.bindBuffer(Pt.ARRAY_BUFFER,n.normal),!r.isMeshPhongMaterial&&!r.isMeshStandardMaterial&&!r.isMeshNormalMaterial&&r.shading===Ks)for(var a=0,o=3*t.count;a8&&(d.length=8);for(var g=n.morphAttributes,f=0,m=d.length;f0&&E.renderInstances(n,R,I):E.render(R,I)}},this.compile=function(t,e){j=[],t.traverse(function(t){t.isLight&&j.push(t)}),O(j,e),t.traverse(function(e){if(e.material)if(Array.isArray(e.material))for(var r=0;r=0&&e<=t.width-n&&r>=0&&r<=t.height-i&&Pt.readPixels(e,r,n,i,D(l),D(h),a):console.error("THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.")}finally{s&&Pt.bindFramebuffer(Pt.FRAMEBUFFER,K)}}}}function xe(t,e){this.name="",this.color=new c(t),this.density=void 0!==e?e:25e-5}function be(t,e,r){this.name="",this.color=new c(t),this.near=void 0!==e?e:1,this.far=void 0!==r?r:1e3}function we(){gt.call(this),this.type="Scene",this.background=null,this.fog=null,this.overrideMaterial=null,this.autoUpdate=!0}function _e(t,e,r,i,a){gt.call(this),this.lensFlares=[],this.positionScreen=new n,this.customUpdateCallback=void 0,void 0!==t&&this.add(t,e,r,i,a)}function Me(t){it.call(this),this.type="SpriteMaterial",this.color=new c(16777215),this.map=null,this.rotation=0,this.fog=!1,this.lights=!1,this.setValues(t)}function Ee(t){gt.call(this),this.type="Sprite",this.material=void 0!==t?t:new Me}function Se(){gt.call(this),this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]}})}function Te(t,r){if(t=t||[],this.bones=t.slice(0),this.boneMatrices=new Float32Array(16*this.bones.length),void 0===r)this.calculateInverses();else if(this.bones.length===r.length)this.boneInverses=r.slice(0);else{console.warn("THREE.Skeleton boneInverses is the wrong length."),this.boneInverses=[];for(var n=0,i=this.bones.length;n=0?(d=t(v-1e-5,g,d),p.subVectors(u,d)):(d=t(v+1e-5,g,d),p.subVectors(d,u)),g-1e-5>=0?(d=t(v,g-1e-5,d),f.subVectors(u,d)):(d=t(v,g+1e-5,d),f.subVectors(d,u)),h.crossVectors(p,f).normalize(),c.push(h.x,h.y,h.z),l.push(v,g)}}for(i=0;i.9&&a<.1&&(e<.2&&(m[t+0]+=1),r<.2&&(m[t+2]+=1),n<.2&&(m[t+4]+=1))}}function s(t){f.push(t.x,t.y,t.z)}function c(e,r){var n=3*e;r.x=t[n+0],r.y=t[n+1],r.z=t[n+2]}function l(){for(var t=new n,e=new n,r=new n,i=new n,a=new h,o=new h,s=new h,c=0,l=0;c0)&&m.push(_,M,S),(l!==r-1||h0&&l(!0),e>0&&l(!1)),this.setIndex(d),this.addAttribute("position",new Tt(p,3)),this.addAttribute("normal",new Tt(f,3)),this.addAttribute("uv",new Tt(m,2))}function yr(t,e,r,n,i,a,o){gr.call(this,0,t,e,r,n,i,a,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:r,heightSegments:n,openEnded:i,thetaStart:a,thetaLength:o}}function xr(t,e,r,n,i,a,o){vr.call(this,0,t,e,r,n,i,a,o),this.type="ConeBufferGeometry",this.parameters={radius:t,height:e,radialSegments:r,heightSegments:n,openEnded:i,thetaStart:a,thetaLength:o}}function br(t,e,r,n){_t.call(this),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:r,thetaLength:n},this.fromBufferGeometry(new wr(t,e,r,n)),this.mergeVertices()}function wr(t,e,r,i){Ct.call(this),this.type="CircleBufferGeometry",this.parameters={radius:t,segments:e,thetaStart:r,thetaLength:i},t=t||50,e=void 0!==e?Math.max(3,e):8,r=void 0!==r?r:0,i=void 0!==i?i:2*Math.PI;var a,o,s=[],c=[],l=[],u=[],d=new n,p=new h;for(c.push(0,0,0),l.push(0,0,1),u.push(.5,.5),o=0,a=3;o<=e;o++,a+=3){var f=r+o/e*i;d.x=t*Math.cos(f),d.y=t*Math.sin(f),c.push(d.x,d.y,d.z),l.push(0,0,1),p.x=(c[a]/t+1)/2,p.y=(c[a+1]/t+1)/2,u.push(p.x,p.y)}for(a=1;a<=e;a++)s.push(a,a+1,0);this.setIndex(s),this.addAttribute("position",new Tt(c,3)),this.addAttribute("normal",new Tt(l,3)),this.addAttribute("uv",new Tt(u,2))}function _r(t){at.call(this,{uniforms:rh.merge([eh.lights,{opacity:{value:1}}]),vertexShader:nh.shadow_vert,fragmentShader:nh.shadow_frag}),this.lights=!0,this.transparent=!0,Object.defineProperties(this,{opacity:{enumerable:!0,get:function(){return this.uniforms.opacity.value},set:function(t){this.uniforms.opacity.value=t}}}),this.setValues(t)}function Mr(t){at.call(this,t),this.type="RawShaderMaterial"}function Er(t){it.call(this),this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new c(16777215),this.roughness=.5,this.metalness=.5,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new c(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalScale=new h(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)}function Sr(t){Er.call(this),this.defines={PHYSICAL:""},this.type="MeshPhysicalMaterial",this.reflectivity=.5,this.clearCoat=0,this.clearCoatRoughness=0,this.setValues(t)}function Tr(t){it.call(this),this.type="MeshPhongMaterial",this.color=new c(16777215),this.specular=new c(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new c(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalScale=new h(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=Oc,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)}function Ar(t){Tr.call(this),this.defines={TOON:""},this.type="MeshToonMaterial",this.gradientMap=null,this.setValues(t)}function Lr(t){it.call(this),this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalScale=new h(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)}function Cr(t){it.call(this),this.type="MeshLambertMaterial",this.color=new c(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new c(0),this.emissiveIntensity=1,this.emissiveMap=null,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=Oc,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)}function Rr(t){it.call(this),this.type="LineDashedMaterial",this.color=new c(16777215),this.linewidth=1,this.scale=1,this.dashSize=3,this.gapSize=1,this.lights=!1,this.setValues(t)}function Pr(t,e,r){var n=this,i=!1,a=0,o=0;this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=r,this.itemStart=function(t){o++,!1===i&&void 0!==n.onStart&&n.onStart(t,a,o),i=!0},this.itemEnd=function(t){a++,void 0!==n.onProgress&&n.onProgress(t,a,o),a===o&&(i=!1,void 0!==n.onLoad&&n.onLoad())},this.itemError=function(t){void 0!==n.onError&&n.onError(t)}}function Ir(t){this.manager=void 0!==t?t:ph}function Or(t){this.manager=void 0!==t?t:ph,this._parser=null}function Nr(t){this.manager=void 0!==t?t:ph,this._parser=null}function Dr(t){this.manager=void 0!==t?t:ph}function Ur(t){this.manager=void 0!==t?t:ph}function zr(t){this.manager=void 0!==t?t:ph}function Br(t,e){gt.call(this),this.type="Light",this.color=new c(t),this.intensity=void 0!==e?e:1,this.receiveShadow=void 0}function Fr(t,e,r){Br.call(this,t,r),this.type="HemisphereLight",this.castShadow=void 0,this.position.copy(gt.DefaultUp),this.updateMatrix(),this.groundColor=new c(e)}function kr(t){this.camera=t,this.bias=0,this.radius=1,this.mapSize=new h(512,512),this.map=null,this.matrix=new e}function Gr(){kr.call(this,new xt(50,1,.5,500))}function Vr(t,e,r,n,i,a){Br.call(this,t,e),this.type="SpotLight",this.position.copy(gt.DefaultUp),this.updateMatrix(),this.target=new gt,Object.defineProperty(this,"power",{get:function(){return this.intensity*Math.PI},set:function(t){this.intensity=t/Math.PI}}),this.distance=void 0!==r?r:0,this.angle=void 0!==n?n:Math.PI/3,this.penumbra=void 0!==i?i:0,this.decay=void 0!==a?a:1,this.shadow=new Gr}function Hr(t,e,r,n){Br.call(this,t,e),this.type="PointLight",Object.defineProperty(this,"power",{get:function(){return 4*this.intensity*Math.PI},set:function(t){this.intensity=t/(4*Math.PI)}}),this.distance=void 0!==r?r:0,this.decay=void 0!==n?n:1,this.shadow=new kr(new xt(90,1,.5,500))}function jr(){kr.call(this,new yt(-5,5,5,-5,.5,500))}function Wr(t,e){Br.call(this,t,e),this.type="DirectionalLight",this.position.copy(gt.DefaultUp),this.updateMatrix(),this.target=new gt,this.shadow=new jr}function Xr(t,e){Br.call(this,t,e),this.type="AmbientLight",this.castShadow=void 0}function Yr(t,e,r,n){Br.call(this,t,e),this.type="RectAreaLight",this.position.set(0,1,0),this.updateMatrix(),this.width=void 0!==r?r:10,this.height=void 0!==n?n:10}function qr(t,e,r,n){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=void 0!==n?n:new e.constructor(r),this.sampleValues=e,this.valueSize=r}function Zr(t,e,r,n){qr.call(this,t,e,r,n),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0}function Jr(t,e,r,n){qr.call(this,t,e,r,n)}function Qr(t,e,r,n){qr.call(this,t,e,r,n)}function Kr(t,e,r,n){if(void 0===t)throw new Error("track name is undefined");if(void 0===e||0===e.length)throw new Error("no keyframes in track named "+t);this.name=t,this.times=fh.convertArray(e,this.TimeBufferType),this.values=fh.convertArray(r,this.ValueBufferType),this.setInterpolation(n||this.DefaultInterpolation),this.validate(),this.optimize()}function $r(t,e,r,n){Kr.call(this,t,e,r,n)}function tn(t,e,r,n){qr.call(this,t,e,r,n)}function en(t,e,r,n){Kr.call(this,t,e,r,n)}function rn(t,e,r,n){Kr.call(this,t,e,r,n)}function nn(t,e,r,n){Kr.call(this,t,e,r,n)}function an(t,e,r){Kr.call(this,t,e,r)}function on(t,e,r,n){Kr.call(this,t,e,r,n)}function sn(t,e,r,n){Kr.apply(this,arguments)}function cn(t,e,r){this.name=t,this.tracks=r,this.duration=void 0!==e?e:-1,this.uuid=Ko.generateUUID(),this.duration<0&&this.resetDuration(),this.optimize()}function ln(t){this.manager=void 0!==t?t:ph,this.textures={}}function hn(t){this.manager=void 0!==t?t:ph}function un(){this.onLoadStart=function(){},this.onLoadProgress=function(){},this.onLoadComplete=function(){}}function dn(t){"boolean"==typeof t&&(console.warn("THREE.JSONLoader: showStatus parameter has been removed from constructor."),t=void 0),this.manager=void 0!==t?t:ph,this.withCredentials=!1}function pn(t){this.manager=void 0!==t?t:ph,this.texturePath=""}function fn(t,e,r,n,i){var a=.5*(n-e),o=.5*(i-r),s=t*t;return(2*r-2*n+a+o)*(t*s)+(-3*r+3*n-2*a-o)*s+a*t+r}function mn(t,e){var r=1-t;return r*r*e}function gn(t,e){return 2*(1-t)*t*e}function vn(t,e){return t*t*e}function yn(t,e,r,n){return mn(t,e)+gn(t,r)+vn(t,n)}function xn(t,e){var r=1-t;return r*r*r*e}function bn(t,e){var r=1-t;return 3*r*r*t*e}function wn(t,e){return 3*(1-t)*t*t*e}function _n(t,e){return t*t*t*e}function Mn(t,e,r,n,i){return xn(t,e)+bn(t,r)+wn(t,n)+_n(t,i)}function En(){this.arcLengthDivisions=200}function Sn(t,e){En.call(this),this.v1=t,this.v2=e}function Tn(){En.call(this),this.curves=[],this.autoClose=!1}function An(t,e,r,n,i,a,o,s){En.call(this),this.aX=t,this.aY=e,this.xRadius=r,this.yRadius=n,this.aStartAngle=i,this.aEndAngle=a,this.aClockwise=o,this.aRotation=s||0}function Ln(t){En.call(this),this.points=void 0===t?[]:t}function Cn(t,e,r,n){En.call(this),this.v0=t,this.v1=e,this.v2=r,this.v3=n}function Rn(t,e,r){En.call(this),this.v0=t,this.v1=e,this.v2=r}function Pn(t){Tn.call(this),this.currentPoint=new h,t&&this.fromPoints(t)}function In(){Pn.apply(this,arguments),this.holes=[]}function On(){this.subPaths=[],this.currentPath=null}function Nn(t){this.data=t}function Dn(t){this.manager=void 0!==t?t:ph}function Un(t){this.manager=void 0!==t?t:ph}function zn(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new xt,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new xt,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1}function Bn(){gt.call(this),this.type="AudioListener",this.context=_h.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null}function Fn(t){gt.call(this),this.type="Audio",this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.loop=!1,this.startTime=0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.sourceType="empty",this.filters=[]}function kn(t){Fn.call(this,t),this.panner=this.context.createPanner(),this.panner.connect(this.gain)}function Gn(t,e){this.analyser=t.context.createAnalyser(),this.analyser.fftSize=void 0!==e?e:2048,this.data=new Uint8Array(this.analyser.frequencyBinCount),t.getOutput().connect(this.analyser)}function Vn(t,e,r){this.binding=t,this.valueSize=r;var n,i=Float64Array;switch(e){case"quaternion":n=this._slerp;break;case"string":case"bool":i=Array,n=this._select;break;default:n=this._lerp}this.buffer=new i(4*r),this._mixBufferRegion=n,this.cumulativeWeight=0,this.useCount=0,this.referenceCount=0}function Hn(t,e,r){var n=r||jn.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,n)}function jn(t,e,r){this.path=e,this.parsedPath=r||jn.parseTrackName(e),this.node=jn.findNode(t,this.parsedPath.nodeName)||t,this.rootNode=t}function Wn(t){this.uuid=Ko.generateUUID(),this._objects=Array.prototype.slice.call(arguments),this.nCachedObjects_=0;var e={};this._indicesByUUID=e;for(var r=0,n=arguments.length;r!==n;++r)e[arguments[r].uuid]=r;this._paths=[],this._parsedPaths=[],this._bindings=[],this._bindingsIndicesByPath={};var i=this;this.stats={objects:{get total(){return i._objects.length},get inUse(){return this.total-i.nCachedObjects_}},get bindingsPerObject(){return i._bindings.length}}}function Xn(t,e,r){this._mixer=t,this._clip=e,this._localRoot=r||null;for(var n=e.tracks,i=n.length,a=new Array(i),o={endingStart:Il,endingEnd:Il},s=0;s!==i;++s){var c=n[s].createInterpolant(null);a[s]=c,c.settings=o}this._interpolantSettings=o,this._interpolants=a,this._propertyBindings=new Array(i),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=Pl,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}function Yn(t){this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}function qn(t){"string"==typeof t&&(console.warn("THREE.Uniform: Type parameter is no longer needed."),t=arguments[1]),this.value=t}function Zn(){Ct.call(this),this.type="InstancedBufferGeometry",this.maxInstancedCount=void 0}function Jn(t,e,r,n){this.uuid=Ko.generateUUID(),this.data=t,this.itemSize=e,this.offset=r,this.normalized=!0===n}function Qn(t,e){this.uuid=Ko.generateUUID(),this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.dynamic=!1,this.updateRange={offset:0,count:-1},this.onUploadCallback=function(){},this.version=0}function Kn(t,e,r){Qn.call(this,t,e),this.meshPerAttribute=r||1}function $n(t,e,r){Mt.call(this,t,e),this.meshPerAttribute=r||1}function ti(t,e,r,n){this.ray=new Dt(t,e),this.near=r||0,this.far=n||1/0,this.params={Mesh:{},Line:{},LOD:{},Points:{threshold:1},Sprite:{}},Object.defineProperties(this.params,{PointCloud:{get:function(){return console.warn("THREE.Raycaster: params.PointCloud has been renamed to params.Points."),this.Points}}})}function ei(t,e){return t.distance-e.distance}function ri(t,e,r,n){if(!1!==t.visible&&(t.raycast(e,r),!0===n))for(var i=t.children,a=0,o=i.length;a256)return void console.error("too many glyphs for atlas");var o;n.textAlign="left",n.font="20px "+t,n.fillStyle="#ffffff";for(var s,c,l=0;lf&&(f=l);var L=T*x+A*b+M,C=T*w+A*_+E;for(this.boundingBox=new st(new n(M,E,p),new n(L,C,f)),i=0;i20;)(n=i.split(".")).shift(),i=n.join("."),a=!0;a&&(i="..."+i),this.addLine(i),this.addLine("x: "+e.x+" m").addLine("y: "+e.y+" m").addLine("z: "+e.z+" m"),null!==r&&this.addLine("depth from surface: "+Math.round(r)+" m")}function Oa(){this.array=null}function Na(t,e,r,n,i){return this.x=t,this.y=e,this.zoom=r,this.tileSet=n,this.clip=i,this.canZoom=!0,this.evicted=!1,this.replaced=!1,this.evictionCount=1,this.resurrectionPending=!1,this.childrenLoading=0,this.childErrors=0,this.boundingBox=null,this.worldBoundingBox=null,Bt.call(this,new Ct,Dh.getSurfaceMaterial()),this.onBeforeRender=mu.onBeforeRender,this.onAfterRender=mu.onAfterRender,this}function Da(t,e,r){function n(t){s.tileSets=JSON.parse(t),e()}function i(){e()}Ta.call(this),this.name="WebTerrain",this.type="CV.WebTerrain";var o=t.limits;this.limits=new et(new h(o.min.x,o.min.y),new h(o.max.x,o.max.y)),this.offsets=t.offsets,this.onLoaded=r,this.childrenLoading=0,this.childErrors=0,this.terrainLoaded=!1,this.material=null,this.initialZoom=null,this.currentZoom=null,this.currentLimits=null,this.dying=!1,this.overlaysLoading=0,this.debug=!0,this.workerPool=new Ca("webTileWorker.js"),void 0!==Qh&&(this.progressDial=Qh.getProgressDial());var s=this;(new Ir).setResponseType("text").load(a("terrainDirectory","")+"/tileSets.json",n,function(){},i)}function Ua(t,e){this.provider=t,this.container=e;var r=t.getAttribution();r&&(r.classList.add("overlay-branding"),this.attribution=r),this.materialCache={}}function za(t,e){function i(){return 2*Math.PI/60/60*U.autoRotateSpeed}function a(){return Math.pow(.95,U.zoomSpeed)}function o(t){j.theta-=t}function s(t){j.phi-=t}function c(t){U.object instanceof xt?W/=t:U.object instanceof yt?(U.object.zoom=Math.max(U.minZoom,Math.min(U.maxZoom,U.object.zoom*t)),U.object.updateProjectionMatrix(),Y=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),U.enableZoom=!1)}function l(t){U.object instanceof xt?W*=t:U.object instanceof yt?(U.object.zoom=Math.max(U.minZoom,Math.min(U.maxZoom,U.object.zoom/t)),U.object.updateProjectionMatrix(),Y=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),U.enableZoom=!1)}function u(t){q.set(t.clientX,t.clientY)}function d(t){tt.set(t.clientX,t.clientY)}function p(t){Q.set(t.clientX,t.clientY)}function f(t){Z.set(t.clientX,t.clientY),J.subVectors(Z,q);var e=U.domElement===document?U.domElement.body:U.domElement;o(2*Math.PI*J.x/e.clientWidth*U.rotateSpeed),s(2*Math.PI*J.y/e.clientHeight*U.rotateSpeed),q.copy(Z),U.update()}function m(t){et.set(t.clientX,t.clientY),rt.subVectors(et,tt),rt.y>0?c(a()):rt.y<0&&l(a()),tt.copy(et),U.update()}function g(t){K.set(t.clientX,t.clientY),$.subVectors(K,Q),at($.x,$.y),Q.copy(K),U.update()}function v(t){}function y(t){t.deltaY<0?l(a()):t.deltaY>0&&c(a()),U.update()}function x(t){switch(t.keyCode){case U.keys.UP:at(0,U.keyPanSpeed),U.update();break;case U.keys.BOTTOM:at(0,-U.keyPanSpeed),U.update();break;case U.keys.LEFT:at(U.keyPanSpeed,0),U.update();break;case U.keys.RIGHT:at(-U.keyPanSpeed,0),U.update()}}function b(t){q.set(t.touches[0].pageX,t.touches[0].pageY)}function w(t){var e=t.touches[0].pageX-t.touches[1].pageX,r=t.touches[0].pageY-t.touches[1].pageY,n=Math.sqrt(e*e+r*r);tt.set(0,n)}function _(t){Q.set(t.touches[0].pageX,t.touches[0].pageY)}function M(t){Z.set(t.touches[0].pageX,t.touches[0].pageY),J.subVectors(Z,q);var e=U.domElement===document?U.domElement.body:U.domElement;o(2*Math.PI*J.x/e.clientWidth*U.rotateSpeed),s(2*Math.PI*J.y/e.clientHeight*U.rotateSpeed),q.copy(Z),U.update()}function E(t){var e=t.touches[0].pageX-t.touches[1].pageX,r=t.touches[0].pageY-t.touches[1].pageY,n=Math.sqrt(e*e+r*r);et.set(0,n),rt.subVectors(et,tt),rt.y>0?l(a()):rt.y<0&&c(a()),tt.copy(et),U.update()}function S(t){K.set(t.touches[0].pageX,t.touches[0].pageY),$.subVectors(K,Q),at($.x,$.y),Q.copy(K),U.update()}function T(t){}function A(t){if(!1!==U.enabled){if(t.preventDefault(),t.button===U.mouseButtons.ORBIT){if(!1===U.enableRotate)return;u(t),G=k.ROTATE}else if(t.button===U.mouseButtons.ZOOM){if(!1===U.enableZoom)return;d(t),G=k.DOLLY}else if(t.button===U.mouseButtons.PAN){if(!1===U.enablePan)return;p(t),G=k.PAN}G!==k.NONE&&(document.addEventListener("mousemove",L,!1),document.addEventListener("mouseup",C,!1),U.dispatchEvent(B))}}function L(t){if(!1!==U.enabled)if(t.preventDefault(),G===k.ROTATE){if(!1===U.enableRotate)return;f(t)}else if(G===k.DOLLY){if(!1===U.enableZoom)return;m(t)}else if(G===k.PAN){if(!1===U.enablePan)return;g(t)}}function C(t){!1!==U.enabled&&(v(t),document.removeEventListener("mousemove",L,!1),document.removeEventListener("mouseup",C,!1),U.dispatchEvent(F),G=k.NONE)}function R(t){!1===U.enabled||!1===U.enableZoom||G!==k.NONE&&G!==k.ROTATE||(t.preventDefault(),t.stopPropagation(),y(t),U.dispatchEvent(B),U.dispatchEvent(F))}function P(t){!1!==U.enabled&&!1!==U.enableKeys&&!1!==U.enablePan&&x(t)}function I(t){if(!1!==U.enabled){switch(t.touches.length){case 1:if(!1===U.enableRotate)return;b(t),G=k.TOUCH_ROTATE;break;case 2:if(!1===U.enableZoom)return;w(t),G=k.TOUCH_DOLLY;break;case 3:if(!1===U.enablePan)return;_(t),G=k.TOUCH_PAN;break;default:G=k.NONE}G!==k.NONE&&U.dispatchEvent(B)}}function O(t){if(!1!==U.enabled)switch(t.preventDefault(),t.stopPropagation(),t.touches.length){case 1:if(!1===U.enableRotate)return;if(G!==k.TOUCH_ROTATE)return;M(t);break;case 2:if(!1===U.enableZoom)return;if(G!==k.TOUCH_DOLLY)return;E(t);break;case 3:if(!1===U.enablePan)return;if(G!==k.TOUCH_PAN)return;S(t);break;default:G=k.NONE}}function N(t){!1!==U.enabled&&(T(t),U.dispatchEvent(F),G=k.NONE)}function D(t){t.preventDefault()}this.object=t,this.domElement=void 0!==e?e:document,this.enabled=!0,this.target=new n,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.25,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.enableKeys=!0,this.keys={LEFT:37,UP:38,RIGHT:39,BOTTOM:40},this.mouseButtons={ORBIT:Vs.LEFT,ZOOM:Vs.MIDDLE,PAN:Vs.RIGHT},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this.getPolarAngle=function(){return H.phi},this.getAzimuthalAngle=function(){return H.theta},this.reset=function(){U.target.copy(U.target0),U.object.position.copy(U.position0),U.object.zoom=U.zoom0,U.object.updateProjectionMatrix(),U.dispatchEvent(z),U.update(),G=k.NONE},this.update=function(){var e=new n,a=(new r).setFromUnitVectors(t.up,new n(0,1,0)),s=a.clone().inverse(),c=new n,l=new r;return function(){var t=U.object.position;return e.copy(t).sub(U.target),e.applyQuaternion(a),H.setFromVector3(e),U.autoRotate&&G===k.NONE&&o(i()),H.theta+=j.theta,H.phi+=j.phi,H.theta=Math.max(U.minAzimuthAngle,Math.min(U.maxAzimuthAngle,H.theta)),H.phi=Math.max(U.minPolarAngle,Math.min(U.maxPolarAngle,H.phi)),H.makeSafe(),H.radius*=W,H.radius=Math.max(U.minDistance,Math.min(U.maxDistance,H.radius)),U.target.add(X),e.setFromSpherical(H),e.applyQuaternion(s),t.copy(U.target).add(e),U.object.lookAt(U.target),!0===U.enableDamping?(j.theta*=1-U.dampingFactor,j.phi*=1-U.dampingFactor):j.set(0,0,0),W=1,X.set(0,0,0),!!(Y||c.distanceToSquared(U.object.position)>V||8*(1-l.dot(U.object.quaternion))>V)&&(U.dispatchEvent(z),c.copy(U.object.position),l.copy(U.object.quaternion),Y=!1,!0)}}(),this.dispose=function(){U.domElement.removeEventListener("contextmenu",D,!1),U.domElement.removeEventListener("mousedown",A,!1),U.domElement.removeEventListener("wheel",R,!1),U.domElement.removeEventListener("touchstart",I,!1),U.domElement.removeEventListener("touchend",N,!1),U.domElement.removeEventListener("touchmove",O,!1),document.removeEventListener("mousemove",L,!1),document.removeEventListener("mouseup",C,!1),window.removeEventListener("keydown",P,!1)};var U=this,z={type:"change"},B={type:"start"},F={type:"end"},k={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5},G=k.NONE,V=1e-6,H=new ii,j=new ii,W=1,X=new n,Y=!1,q=new h,Z=new h,J=new h,Q=new h,K=new h,$=new h,tt=new h,et=new h,rt=new h,nt=function(){var t=new n;return function(e,r){t.setFromMatrixColumn(r,0),t.multiplyScalar(-e),X.add(t)}}(),it=function(){var t=new n;return function(e,r){t.setFromMatrixColumn(r,1),t.multiplyScalar(e),X.add(t)}}(),at=function(){var t=new n;return function(e,r){var n=U.domElement===document?U.domElement.body:U.domElement;if(U.object instanceof xt){var i=U.object.position;t.copy(i).sub(U.target);var a=t.length();a*=Math.tan(U.object.fov/2*Math.PI/180),nt(2*e*a/n.clientHeight,U.object.matrix),it(2*r*a/n.clientHeight,U.object.matrix)}else U.object instanceof yt?(nt(e*(U.object.right-U.object.left)/U.object.zoom/n.clientWidth,U.object.matrix),it(r*(U.object.top-U.object.bottom)/U.object.zoom/n.clientHeight,U.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),U.enablePan=!1)}}();U.domElement.addEventListener("contextmenu",D,!1),U.domElement.addEventListener("mousedown",A,!1),U.domElement.addEventListener("wheel",R,!1),U.domElement.addEventListener("touchstart",I,!1),U.domElement.addEventListener("touchend",N,!1),U.domElement.addEventListener("touchmove",O,!1),window.addEventListener("keydown",P,!1),this.update()}function Ba(t,e){function r(t,e){Object.defineProperty(ed,e,{writeable:!0,get:function(){return qa(t)},set:function(r){Ya(t,r),this.dispatchEvent({type:"change",name:e})}})}function n(t,e){r(t,e),e="has"+e.substr(0,1).toUpperCase()+e.substr(1),Object.defineProperty(ed,e,{get:function(){return Pu.hasFeature(t)}})}function a(t,e,r){t(isNaN(r)?r:Number(r)),ed.dispatchEvent({type:"change",name:e})}function o(t){switch(Wu=t?us:hs){case hs:Xu=Pu.pointTargets;break;case us:Xu=Pu.legTargets;break;default:console.warn("invalid mouse mode")}}console.log("CaveView v"+$o),(Eu=document.getElementById(t))||alert("No container DOM object ["+t+"] available"),i(e);var s=Eu.clientWidth,c=Eu.clientHeight;(Su=new ye({antialias:!0})).setSize(s,c),Su.setPixelRatio(window.devicePixelRatio),Su.setClearColor(0),Su.autoClear=!1,(Tu=new yt(-s/2,s/2,c/2,-c/2,1,4e3)).rotateOnAxis(zs,Math.PI/2),Xa(Tu),Xa(Au=new xt(75,s/c,1,16e3)),Lu=Au,Hu.add(Au),Hu.add(Tu),(Ru=new Wr(16777215)).position.copy(ku),Hu.add(Ru),Hu.add(new Fr(16777215,65535,.3)),Cu=new ti,Su.clear(),Eu.appendChild(Su.domElement),Bu=new za(Lu,Su.domElement),Fu=new na(Bu,rd,mo),Bu.addEventListener("change",function(){Fu.prepare(null,null),Fu.start(80)}),Bu.enableDamping=!0,window.addEventListener("resize",io),Object.defineProperties(ed,{container:{value:Eu},terrain:{writeable:!0,get:function(){return qa(Cs)},set:function(t){co(t)}},terrainShading:{writeable:!0,get:function(){return Uu},set:function(t){a(Ja,"terrainShading",t)}},hasTerrain:{get:function(){return!!Yu}},terrainDatumShift:{writeable:!0,get:function(){return!!Yu.activeDatumShift},set:function(t){Ha(t)}},terrainOverlays:{get:function(){return Yu.isTiled?Object.keys(Ju):Yu.hasOverlay?[!0]:[]}},terrainOverlay:{writeable:!0,get:function(){return Qu},set:function(t){a($a,"terrainOverlay",t)}},terrainOpacity:{writeable:!0,get:function(){return Yu.getOpacity()},set:function(t){Va(t)}},shadingMode:{writeable:!0,get:function(){return Du},set:function(t){a(Qa,"shadingMode",t)}},surfaceShading:{writeable:!0,get:function(){return Zu},set:function(t){a(Ka,"surfaceShading",t)}},cameraType:{writeable:!0,get:function(){return zu},set:function(t){a(Wa,"cameraType",t)}},view:{writeable:!0,get:function(){return is},set:function(t){a(Za,"view",t)}},cursorHeight:{writeable:!0,get:function(){return Nu},set:function(t){Ga(t)}},initCursorHeight:{writeable:!0,get:function(){return Nu},set:function(t){Nu=t}},maxHeight:{get:function(){return Iu.max.z}},minHeight:{get:function(){return Iu.min.z}},maxLegLength:{get:function(){return qu.maxLegLength}},minLegLength:{get:function(){return qu.minLegLength}},section:{writeable:!0,get:function(){return Ku},set:function(t){a(no,"section",t)}},highlight:{writeable:!0,set:function(t){a(ro,"highlight",t)}},routeEdit:{writeable:!0,get:function(){return Wu===us},set:function(t){o(t),this.dispatchEvent({type:"change",name:"routeEdit"})}},setPOI:{writeable:!0,get:function(){return!0},set:function(t){a(vo,"setPOI",t)}},developerInfo:{writeable:!0,get:function(){return!0},set:function(t){}},HUD:{writeable:!0,get:function(){return Qh.getVisibility()},set:function(t){Qh.setVisibility(t)}},cut:{writeable:!0,get:function(){return!0},set:function(){eo()}},zScale:{writeable:!0,get:function(){return Ou},set:function(t){Fa(t)}},autoRotate:{writeable:!0,get:function(){return Bu.autoRotate},set:function(t){ka(!!t)}},autoRotateSpeed:{writeable:!0,get:function(){return Bu.autoRotateSpeed/11},set:function(t){Bu.autoRotateSpeed=11*t}}}),r(Ts,"box"),n(Ls,"entrances"),n(Rs,"stations"),n(Ps,"traces"),n(Os,"scraps"),n(Is,"walls"),n(Es,"splays"),n(Ss,"surfaceLegs"),n(Ns,"stationLabels"),Dh.initCache(ed),Qh.init(t,Su)}function Fa(t){var r=Math.pow(2,4*(Ou-.5)),n=Math.pow(2,4*(t-.5));Pu.applyMatrix((new e).makeScale(1,1,n/r)),Ou=t,rd()}function ka(t){Bu.autoRotate=t,t?(Fu.prepare(null,null),Fu.start(2952e3)):Fu.stop()}function Ga(t){Nu=t,ed.dispatchEvent({type:"cursorChange",name:"cursorHeight"}),rd()}function Va(t){Yu.setOpacity(t),ed.dispatchEvent({type:"change",name:"terrainOpacity"}),rd()}function Ha(t){Yu.applyDatumShift(t),ed.dispatchEvent({type:"change",name:"terrainDatumShift"}),rd()}function ja(){if(null!==Yu&&Yu.isLoaded()){var t=Eu.clientWidth,e=Eu.clientHeight,r=Iu.getSize(),n=t/r.x,i=e/r.y;n0}function Za(t,e){var r=new n,i=e||240;switch(t){case as:r.set(0,0,ns);break;case os:r.set(0,ns,0);break;case ss:r.set(0,-ns,0);break;case cs:r.set(ns,0,0);break;case ls:r.set(-ns,0,0);break;default:return void console.warn("invalid view mode specified: ",t)}r.add($u),Fu.cancel(),Fu.prepare(r,$u),Fu.start(i)}function Ja(t){Yu.setShadingMode(t,rd)&&(Uu=t),rd()}function Qa(t){(null!==Yu||t!==bs&&t!==_s)&&(Pu.setShadingMode(t)&&(Du=t),rd())}function Ka(t){Pu.setLegShading(Ss,t)&&(Zu=t),rd()}function $a(t){Uu===ys&&(Qu=t,Yu.setOverlay(Ju[t],rd))}function to(t,e){Ju[t]=new Ua(e,Eu),1===Object.keys(Ju).length&&(Qu=t)}function eo(){if(0!==Ku){Pu.remove(Yu),Pu.cutSection(Ku);var t=Pu;ao(),so(t)}}function ro(t){Pu.highlightSelection(t),rd()}function no(t){var e=Pu.selectSection(t);if(Qa(Du),Ku=t,0!==t){if(void 0===e.p){if(void 0===e.boundingBox)return;var r=e.boundingBox.clone();Fu.prepare(null,r.applyMatrix4(Pu.matrixWorld))}else Fu.prepare(null,Pu.getWorldPosition(e.p));rd()}}function io(){var t=Eu.clientWidth,e=Eu.clientHeight;Su.setSize(t,e),void 0!==Tu&&(Tu.left=-t/2,Tu.right=t/2,Tu.top=e/2,Tu.bottom=-e/2,Tu.updateProjectionMatrix(),Au.aspect=t/e,Au.updateProjectionMatrix(),rd())}function ao(){Vu=!1,Su.clear(),Qh.setVisibility(!1),Pu&&(Pu.remove(Yu),Hu.remove(Pu)),Bu.enabled=!1,Pu=null,Yu=null,Ku=0,Wu=hs,Xu=[],Du=ds,Zu=gs,Uu=xs,ho(),Dh.flushCache(),Eu.removeEventListener("mousedown",fo),Xa(Au),Xa(Tu),ed.cameraType=rs,Za(as,1),rd()}function oo(t){if(!t)return void alert("failed loading cave information");so(new Ra(t))}function so(t){function e(){Yu.hasCoverage()?(Ja(Uu),Yu.tileArea(Pu.limits),Yu.setDefaultOverlay(Ju[Qu]),Pu.add(Yu)):Yu=null,ed.dispatchEvent({type:"newCave",name:"newCave"})}function r(){rd(),lo(),null===Yu.depthTexture&&ja()}function n(){Qa(Du),rd()}var i=!1;qu=(Pu=t).getFeature(Ms).stats,yo(Pu),Yu=Pu.terrain,Hu.up=zs,Hu.add(Pu),Vu=!0,no(0),Xu=Pu.pointTargets,Ka(Zu),null===Yu?(Yu=new Da(Pu,e,r,rd),i=!0):(Pu.add(Yu),Ja(Uu),ja()),Hu.matrixAutoUpdate=!1,Eu.addEventListener("mousedown",fo,!1),Qh.setVisibility(!0),i||ed.dispatchEvent({type:"newCave",name:"newCave"}),Bu.object=Lu,Bu.enabled=!0,Pu.getRoutes().addEventListener("changed",n),Za(as,1),rd()}function co(t){Yu.isLoaded()&&(t?lo():ho(),Yu.setVisibility(t),Ya(Cs,t),ed.dispatchEvent({type:"change",name:"terrain"}))}function lo(){uo(),Bu.addEventListener("end",uo)}function ho(){Bu&&(Bu.removeEventListener("end",uo),po())}function uo(){td=performance.now()}function po(){td=0}function fo(t){function e(){Qa(Du),rd()}var r,i;ju.x=t.clientX/Eu.clientWidth*2-1,ju.y=-t.clientY/Eu.clientHeight*2+1,Cu.setFromCamera(ju,Lu);for(var a=Cu.intersectObjects(Xu,!1),o=0,s=a.length;oGu&&(po(),Yu.zoomCheck(Lu)&&setTimeout(go,5*Gu))}function vo(){Fu.start(200)}function yo(t){var e=Eu.clientWidth,r=Eu.clientHeight,i=Pu.scaleFactor;Iu=Pu.limits,Ou=.5;var a=Iu.getSize();Nu=0;var o=Math.min(e/a.x,r/a.y),s=o*i,c=new n(o,o,s);t.scale.copy(c),t.position.copy(Pu.modelLimits.getCenter().multiply(c).negate()),Qh.setScale(s),t.setScale(s)}function xo(){return qu}function bo(){return Bu}function wo(){return Pu.getMetadataURL()}function _o(){return Pu.getRoutes()}function Mo(){return Pu.surveyTree}function Eo(t,e){function r(t){t.target.parentElement.classList.remove("onscreen")}var n=document.createElement("div"),i=document.createElement("div"),a=Eo.frame;if(i.classList.add("page"),n.id=t,n.classList.add("tab"),n.style.top=40*Eo.position+++"px",n.addEventListener("click",this.tabHandleClick),void 0!==e&&n.addEventListener("click",e),null===a){(a=document.createElement("div")).id="frame",a.style.display="block",Eo.frame=a;var o=document.createElement("div");o.id="close",o.addEventListener("click",r),a.appendChild(o)}a.appendChild(n),a.appendChild(i),Eo.pages.push({tab:n,page:i}),this.page=i,this.slide=void 0}function So(t){var e=(t.clientWidth-300)/2,r=document.createElement("div");r.id="status-text",r.style.width="300px",r.style.left=e+"px";var n=document.createElement("progress");n.id="progress-bar",n.style.width="300px",n.style.left=e+"px",n.setAttribute("max","100"),this.container=t,this.progressBar=n,this.statusText=r}function To(t){this.fileName=t,this.groups=[],this.surface=[],this.xGroups=[],this.surveyTree=new ia,this.sourceCRS=null,this.targetCRS="EPSG:3857",this.projection=null}function Ao(t){this.fileName=t,this.scraps=[],this.faults=[],this.lineSegments=[],this.xGroups=[],this.surveyTree=new ia("",0),this.terrain={},this.hasTerrain=!1}function Lo(t){this.fileName=t,this.groups=[],this.surface=[],this.xGroups=[],this.surveyTree=new ia,this.sourceCRS=null,this.targetCRS="EPSG:3857",this.projection=null}function Co(t){this.filename=t,this.box=new st}function Ro(t,e){t||alert("No callback specified"),this.callback=t,this.progress=e,this.dataResponse=null,this.metadataResponse=null,this.taskCount=0}function Po(t,e){if(!(sd=document.getElementById(t)))return void alert("No container DOM object ["+t+"] available");ld=new So(sd),ed.init(t,e),id=new Ro(Zo,qo),document.addEventListener("keydown",Qo),sd.addEventListener("drop",Vo),sd.addEventListener("dragover",Go),Object.defineProperty(pd,"file",{get:function(){return cd},set:function(t){Xo(t),cd=t}}),ed.addEventListener("change",Eo.handleChange),ed.addEventListener("change",Oo),ed.addEventListener("newCave",Jo)}function Io(t,e){for(var r,n=e?"block":"none",i=0,a=t.length;i2?(n.style.color="yellow",n.textContent="◼ "):0===t.hitCount?(n.style.color="red",n.textContent="◻ "):(n.style.color="red",n.textContent="◼ ");if(e.appendChild(n),e.appendChild(r),t.children.length>0){var a=document.createElement("div");a.classList.add("descend-tree"),a.id="ssv"+t.id,a.textContent="►",e.appendChild(a)}o.appendChild(e)}}function a(t,e){return u(t.name,e.name)}for(var o,l,h,d=hu.getSurveyColourMap(ad,ed.section);l=c.firstChild;)c.removeChild(l);null===t.parent?c.textContent=""===t.name?"[model]":t.name:((h=document.createElement("span")).textContent=" ◄",s.addListener(h,"click",i),c.appendChild(h),c.appendChild(document.createTextNode(" "+t.name))),o=document.createElement("ul");var p=t.children;return p.sorted||(p.sort(a),p.sorted=!0),t.forEachChild(e),od=t,s.addListener(o,"mouseover",n),s.addListener(o,"mouseleave",r),o}function r(t){t.stopPropagation(),ed.highlight=0}function n(t){t.stopPropagation();var e=t.target;if("LI"===e.nodeName){var r=Number(e.id.split("v")[1]);return r!==h&&(ed.highlight=ed.section!==r?r:0,h=r),!1}}function i(t){t.stopPropagation(),null!==od.parent&&s.replaceSlide(e(od.parent),--l,o)}function a(){ed.section=od.id}function o(t){var r=t.target,n=Number(r.id.split("v")[1]);switch(t.stopPropagation(),r.nodeName){case"LI":ed.section=ed.section!==n?n:0,ed.setPOI=!0;break;case"DIV":n&&s.replaceSlide(e(od.findById(n)),++l,o)}}var s,c=document.createElement("div"),l=0,h=0,u=new Intl.Collator("en-GB",{numeric:!0}).compare;if(od=ad,fd){(s=new Eo("icon_explore")).addHeader("Selection"),c.id="ui-path",s.addListener(c,"click",a),s.appendChild(c),s.addSlide(e(od),l,o);sd.clientHeight;s.addListener(ed,"change",t)}}function Do(){function t(){hd.addRoute(i()),n=a.addSelect("Current Route",hd.getRouteNames(),hd,"setRoute",n)}function e(){hd.saveCurrent()}function r(){ed.shadingMode=ws,!hd.setRoute&&s.length>0&&(hd.setRoute=s[0])}var n,i,a=new Eo("icon_route",r),s=hd.getRouteNames();a.addHeader("Routes"),a.addCheckbox("Edit Routes",ed,"routeEdit"),n=a.addSelect("Current Route",s,hd,"setRoute"),gd.push(a.addButton("Save",e)),gd.push(a.addTextBox("New Route","---",function(t){i=t})),gd.push(a.addButton("Add",t)),gd.push(a.addDownloadButton("Download",ed.getMetadata,o(cd,"json"))),Io(gd,!1),a.addListener(hd,"changed",Eo.handleChange)}function Uo(){function t(t,r){var n=document.createElement("dt"),i=document.createElement("dd");n.textContent=t,i.textContent=r,e.appendChild(n),e.appendChild(i)}var e,r=new Eo("icon_help");r.addHeader("Help - key commands"),r.addHeader("Shading"),e=document.createElement("dl"),t("1","height"),t("2","leg angle"),t("3","leg length"),t("4","height cursor "),t("5","single colour"),t("6","survey section"),t("7","route"),t("8","depth from surface"),t("9","depth cursor"),t("[","move depth cursor up"),t("]","move depth cursor down"),dd.length>0&&t("n","next cave"),r.appendChild(e),r.addHeader("View"),e=document.createElement("dl"),t("O","orthogonal view"),t("P","perspective view"),t("R","reset to plan view"),t(".","center view on last feature selected"),r.appendChild(e),r.addHeader("Visibility"),e=document.createElement("dl"),t("C","scraps on/off [lox only]"),t("J","station labels on/off"),t("L","labels on/off"),t("Q","splay legs on/off"),t("S","surface legs on/off"),t("T","terrain on/off"),t("W","LRUD walls on/off"),t("Z","stations on/off"),t("","-"),t("<","Decrease terrain opacity"),t(">","Increase terrain opacity"),r.appendChild(e),r.addHeader("Selection"),e=document.createElement("dl"),t("V","Remove all except selected section"),r.appendChild(e)}function zo(){var t=new Eo("icon_info");t.addHeader("Information"),t.addText("CaveView v"+$o+" - a work in progress 3d cave viewer for Survex (.3d) and Therion (.lox) models."),t.addText("Requires a browser supporting WebGL (IE 11+ and most other recent browsers), no plugins required. Created using the THREE.js 3D library and chroma,js colour handling library.")}function Bo(){var t=Object.assign({},yd);ed.hasTerrain&&(t.depth=bs,t["depth cursor"]=_s);var e=new Eo("icon_settings");e.addHeader("Survey"),dd.length>0&&e.addSelect("File",dd,pd,"file"),e.addHeader("View"),e.addSelect("Camera Type",_d,ed,"cameraType"),e.addSelect("View",wd,ed,"view"),e.addRange("Vertical scaling",ed,"zScale"),e.addCheckbox("Auto Rotate",ed,"autoRotate"),e.addRange("Rotation Speed",ed,"autoRotateSpeed"),e.addHeader("Shading"),e.addSelect("Underground Legs",t,ed,"shadingMode"),e.addHeader("Visibility"),ed.hasEntrances&&e.addCheckbox("Entrances",ed,"entrances"),ed.hasStations&&e.addCheckbox("Stations",ed,"stations"),ed.hasStationLabels&&e.addCheckbox("Station Labels",ed,"stationLabels"),ed.hasSplays&&e.addCheckbox("Splay Legs",ed,"splays"),ed.hasWalls&&e.addCheckbox("Walls (LRUD)",ed,"walls"),ed.hasScraps&&e.addCheckbox("Scraps",ed,"scraps"),ed.hasTraces&&e.addCheckbox("Dye Traces",ed,"traces"),e.addCheckbox("Indicators",ed,"HUD"),e.addCheckbox("Bounding Box",ed,"box")}function Fo(){vd=null,md=[];var t=new Eo("icon_terrain");if(t.addHeader("Surface Features"),ed.hasSurfaceLegs&&(t.addCheckbox("Surface Legs",ed,"surfaceLegs"),t.addSelect("Leg Shading",xd,ed,"surfaceShading")),ed.hasTerrain){t.addHeader("Terrain"),t.addCheckbox("Terrain",ed,"terrain");var e=ed.terrainOverlays,r=Object.assign({},bd);e.length>0&&(r["map overlay"]=ys),md.push(t.addSelect("Shading",r,ed,"terrainShading")),e.length>1&&(vd=t.addSelect("Overlay",e,ed,"terrainOverlay"),md.push(vd)),md.push(t.addRange("Terrain opacity",ed,"terrainOpacity")),md.push(t.addCheckbox("Vertical datum shift",ed,"terrainDatumShift")),Io(md,!1)}}function ko(){Eo.reset(),Bo(),Fo(),No(),Do(),zo(),Uo(),sd.appendChild(Eo.frame)}function Go(t){t.preventDefault(),t.dataTransfer.dropEffect="copy"}function Vo(t){var e=t.dataTransfer;t.preventDefault(),1===e.files.length&&Yo(e.files[0])}function Ho(){fd&&(fd=!1,Eo.clear(),ad=null)}function jo(t){dd=t,Wo()}function Wo(){if(0===dd.length)return!1;++ud>=dd.length&&(ud=0),pd.file=dd[ud]}function Xo(t){cd=t,Ho(),ed.clearView(),ld.Start("Loading file "+cd+" ..."),id.loadURL(cd)}function Yo(t){Ho(),ed.clearView(),ld.Start("Loading file "+t.name+" ..."),id.loadFile(t)}function qo(t){ld.Update(t)}function Zo(t){function e(){ld.End(),ld.Start("Rendering..."),setTimeout(r,100)}function r(){ed.loadCave(nd),ld.End()}nd=t,setTimeout(e,100)}function Jo(){ed.shadingMode=ds,ad=ed.getSurveyTree(),hd=ed.getRoutes(),fd=!0,nd=null,ko()}function Qo(t){if(fd)switch(t.keyCode){case 49:ed.shadingMode=ds;break;case 50:ed.shadingMode=fs;break;case 51:ed.shadingMode=ps;break;case 52:ed.shadingMode=ms;break;case 53:ed.shadingMode=gs;break;case 54:ed.shadingMode=vs;break;case 55:ed.shadingMode=ws;break;case 56:ed.shadingMode=bs;break;case 57:ed.shadingMode=_s;break;case 67:ed.hasScraps&&(ed.scraps=!ed.scraps);break;case 68:ed.hasTraces&&(ed.traces=!ed.traces);break;case 73:ed.developerInfo=!0;break;case 74:ed.hasStationLabels&&(ed.stationLabels=!ed.stationLabels);break;case 76:ed.hasEntrances&&(ed.entrances=!ed.entrances);break;case 78:Wo();break;case 79:ed.cameraType=es;break;case 80:ed.cameraType=rs;break;case 81:ed.hasSplays&&(ed.splays=!ed.splays);break;case 82:ed.view=as;break;case 83:ed.hasSurfaceLegs&&(ed.surfaceLegs=!ed.surfaceLegs);break;case 84:ed.hasTerrain&&(ed.terrain=!ed.terrain);break;case 86:Ho(),ed.cut=!0;break;case 87:ed.hasWalls&&(ed.walls=!ed.walls);break;case 88:ed.setPOI=!0;break;case 90:ed.stations=!ed.stations;break;case 107:case 219:ed.cursorHeight++;break;case 109:case 221:ed.cursorHeight--;break;case 188:ed.hasTerrain&&(ed.terrainOpacity=Math.max(ed.terrainOpacity-.05,0));break;case 190:ed.hasTerrain&&(ed.terrainOpacity=Math.min(ed.terrainOpacity+.05,1))}}void 0===Number.EPSILON&&(Number.EPSILON=Math.pow(2,-52)),void 0===Number.isInteger&&(Number.isInteger=function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t}),void 0===Math.sign&&(Math.sign=function(t){return t<0?-1:t>0?1:+t}),void 0===Function.prototype.name&&Object.defineProperty(Function.prototype,"name",{get:function(){return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1]}}),void 0===Object.assign&&function(){Object.assign=function(t){if(void 0===t||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),r=1;r>=4,r[i]=e[19===i?3&t|8:t]);return r.join("")}}(),clamp:function(t,e,r){return Math.max(e,Math.min(r,t))},euclideanModulo:function(t,e){return(t%e+e)%e},mapLinear:function(t,e,r,n,i){return n+(t-e)*(i-n)/(r-e)},lerp:function(t,e,r){return(1-r)*t+r*e},smoothstep:function(t,e,r){return t<=e?0:t>=r?1:(t=(t-e)/(r-e))*t*(3-2*t)},smootherstep:function(t,e,r){return t<=e?0:t>=r?1:(t=(t-e)/(r-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},degToRad:function(t){return t*Ko.DEG2RAD},radToDeg:function(t){return t*Ko.RAD2DEG},isPowerOfTwo:function(t){return 0==(t&t-1)&&0!==t},nearestPowerOfTwo:function(t){return Math.pow(2,Math.round(Math.log(t)/Math.LN2))},nextPowerOfTwo:function(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,++t}};Object.assign(e.prototype,{isMatrix4:!0,set:function(t,e,r,n,i,a,o,s,c,l,h,u,d,p,f,m){var g=this.elements;return g[0]=t,g[4]=e,g[8]=r,g[12]=n,g[1]=i,g[5]=a,g[9]=o,g[13]=s,g[2]=c,g[6]=l,g[10]=h,g[14]=u,g[3]=d,g[7]=p,g[11]=f,g[15]=m,this},identity:function(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this},clone:function(){return(new e).fromArray(this.elements)},copy:function(t){var e=this.elements,r=t.elements;return e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],e[4]=r[4],e[5]=r[5],e[6]=r[6],e[7]=r[7],e[8]=r[8],e[9]=r[9],e[10]=r[10],e[11]=r[11],e[12]=r[12],e[13]=r[13],e[14]=r[14],e[15]=r[15],this},copyPosition:function(t){var e=this.elements,r=t.elements;return e[12]=r[12],e[13]=r[13],e[14]=r[14],this},extractBasis:function(t,e,r){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),r.setFromMatrixColumn(this,2),this},makeBasis:function(t,e,r){return this.set(t.x,e.x,r.x,0,t.y,e.y,r.y,0,t.z,e.z,r.z,0,0,0,0,1),this},extractRotation:function(){var t=new n;return function(e){var r=this.elements,n=e.elements,i=1/t.setFromMatrixColumn(e,0).length(),a=1/t.setFromMatrixColumn(e,1).length(),o=1/t.setFromMatrixColumn(e,2).length();return r[0]=n[0]*i,r[1]=n[1]*i,r[2]=n[2]*i,r[4]=n[4]*a,r[5]=n[5]*a,r[6]=n[6]*a,r[8]=n[8]*o,r[9]=n[9]*o,r[10]=n[10]*o,this}}(),makeRotationFromEuler:function(t){t&&t.isEuler||console.error("THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.");var e=this.elements,r=t.x,n=t.y,i=t.z,a=Math.cos(r),o=Math.sin(r),s=Math.cos(n),c=Math.sin(n),l=Math.cos(i),h=Math.sin(i);if("XYZ"===t.order){var u=a*l,d=a*h,p=o*l,f=o*h;e[0]=s*l,e[4]=-s*h,e[8]=c,e[1]=d+p*c,e[5]=u-f*c,e[9]=-o*s,e[2]=f-u*c,e[6]=p+d*c,e[10]=a*s}else if("YXZ"===t.order){var m=s*l,g=s*h,v=c*l,y=c*h;e[0]=m+y*o,e[4]=v*o-g,e[8]=a*c,e[1]=a*h,e[5]=a*l,e[9]=-o,e[2]=g*o-v,e[6]=y+m*o,e[10]=a*s}else if("ZXY"===t.order){var m=s*l,g=s*h,v=c*l,y=c*h;e[0]=m-y*o,e[4]=-a*h,e[8]=v+g*o,e[1]=g+v*o,e[5]=a*l,e[9]=y-m*o,e[2]=-a*c,e[6]=o,e[10]=a*s}else if("ZYX"===t.order){var u=a*l,d=a*h,p=o*l,f=o*h;e[0]=s*l,e[4]=p*c-d,e[8]=u*c+f,e[1]=s*h,e[5]=f*c+u,e[9]=d*c-p,e[2]=-c,e[6]=o*s,e[10]=a*s}else if("YZX"===t.order){var x=a*s,b=a*c,w=o*s,_=o*c;e[0]=s*l,e[4]=_-x*h,e[8]=w*h+b,e[1]=h,e[5]=a*l,e[9]=-o*l,e[2]=-c*l,e[6]=b*h+w,e[10]=x-_*h}else if("XZY"===t.order){var x=a*s,b=a*c,w=o*s,_=o*c;e[0]=s*l,e[4]=-h,e[8]=c*l,e[1]=x*h+_,e[5]=a*l,e[9]=b*h-w,e[2]=w*h-b,e[6]=o*l,e[10]=_*h+x}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this},makeRotationFromQuaternion:function(t){var e=this.elements,r=t._x,n=t._y,i=t._z,a=t._w,o=r+r,s=n+n,c=i+i,l=r*o,h=r*s,u=r*c,d=n*s,p=n*c,f=i*c,m=a*o,g=a*s,v=a*c;return e[0]=1-(d+f),e[4]=h-v,e[8]=u+g,e[1]=h+v,e[5]=1-(l+f),e[9]=p-m,e[2]=u-g,e[6]=p+m,e[10]=1-(l+d),e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this},lookAt:function(){var t=new n,e=new n,r=new n;return function(n,i,a){var o=this.elements;return r.subVectors(n,i),0===r.lengthSq()&&(r.z=1),r.normalize(),t.crossVectors(a,r),0===t.lengthSq()&&(1===Math.abs(a.z)?r.x+=1e-4:r.z+=1e-4,r.normalize(),t.crossVectors(a,r)),t.normalize(),e.crossVectors(r,t),o[0]=t.x,o[4]=e.x,o[8]=r.x,o[1]=t.y,o[5]=e.y,o[9]=r.y,o[2]=t.z,o[6]=e.z,o[10]=r.z,this}}(),multiply:function(t,e){return void 0!==e?(console.warn("THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead."),this.multiplyMatrices(t,e)):this.multiplyMatrices(this,t)},premultiply:function(t){return this.multiplyMatrices(t,this)},multiplyMatrices:function(t,e){var r=t.elements,n=e.elements,i=this.elements,a=r[0],o=r[4],s=r[8],c=r[12],l=r[1],h=r[5],u=r[9],d=r[13],p=r[2],f=r[6],m=r[10],g=r[14],v=r[3],y=r[7],x=r[11],b=r[15],w=n[0],_=n[4],M=n[8],E=n[12],S=n[1],T=n[5],A=n[9],L=n[13],C=n[2],R=n[6],P=n[10],I=n[14],O=n[3],N=n[7],D=n[11],U=n[15];return i[0]=a*w+o*S+s*C+c*O,i[4]=a*_+o*T+s*R+c*N,i[8]=a*M+o*A+s*P+c*D,i[12]=a*E+o*L+s*I+c*U,i[1]=l*w+h*S+u*C+d*O,i[5]=l*_+h*T+u*R+d*N,i[9]=l*M+h*A+u*P+d*D,i[13]=l*E+h*L+u*I+d*U,i[2]=p*w+f*S+m*C+g*O,i[6]=p*_+f*T+m*R+g*N,i[10]=p*M+f*A+m*P+g*D,i[14]=p*E+f*L+m*I+g*U,i[3]=v*w+y*S+x*C+b*O,i[7]=v*_+y*T+x*R+b*N,i[11]=v*M+y*A+x*P+b*D,i[15]=v*E+y*L+x*I+b*U,this},multiplyScalar:function(t){var e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this},applyToBufferAttribute:function(){var t=new n;return function(e){for(var r=0,n=e.count;r=0?1:-1,y=1-g*g;if(y>Number.EPSILON){var x=Math.sqrt(y),b=Math.atan2(x,g*v);m=Math.sin(m*b)/x,o=Math.sin(o*b)/x}var w=o*v;if(s=s*m+u*w,c=c*m+d*w,l=l*m+p*w,h=h*m+f*w,m===1-o){var _=1/Math.sqrt(s*s+c*c+l*l+h*h);s*=_,c*=_,l*=_,h*=_}}t[e]=s,t[e+1]=c,t[e+2]=l,t[e+3]=h}}),Object.defineProperties(r.prototype,{x:{get:function(){return this._x},set:function(t){this._x=t,this.onChangeCallback()}},y:{get:function(){return this._y},set:function(t){this._y=t,this.onChangeCallback()}},z:{get:function(){return this._z},set:function(t){this._z=t,this.onChangeCallback()}},w:{get:function(){return this._w},set:function(t){this._w=t,this.onChangeCallback()}}}),Object.assign(r.prototype,{set:function(t,e,r,n){return this._x=t,this._y=e,this._z=r,this._w=n,this.onChangeCallback(),this},clone:function(){return new this.constructor(this._x,this._y,this._z,this._w)},copy:function(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this.onChangeCallback(),this},setFromEuler:function(t,e){if(!t||!t.isEuler)throw new Error("THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.");var r=t._x,n=t._y,i=t._z,a=t.order,o=Math.cos,s=Math.sin,c=o(r/2),l=o(n/2),h=o(i/2),u=s(r/2),d=s(n/2),p=s(i/2);return"XYZ"===a?(this._x=u*l*h+c*d*p,this._y=c*d*h-u*l*p,this._z=c*l*p+u*d*h,this._w=c*l*h-u*d*p):"YXZ"===a?(this._x=u*l*h+c*d*p,this._y=c*d*h-u*l*p,this._z=c*l*p-u*d*h,this._w=c*l*h+u*d*p):"ZXY"===a?(this._x=u*l*h-c*d*p,this._y=c*d*h+u*l*p,this._z=c*l*p+u*d*h,this._w=c*l*h-u*d*p):"ZYX"===a?(this._x=u*l*h-c*d*p,this._y=c*d*h+u*l*p,this._z=c*l*p-u*d*h,this._w=c*l*h+u*d*p):"YZX"===a?(this._x=u*l*h+c*d*p,this._y=c*d*h+u*l*p,this._z=c*l*p-u*d*h,this._w=c*l*h-u*d*p):"XZY"===a&&(this._x=u*l*h-c*d*p,this._y=c*d*h-u*l*p,this._z=c*l*p+u*d*h,this._w=c*l*h+u*d*p),!1!==e&&this.onChangeCallback(),this},setFromAxisAngle:function(t,e){var r=e/2,n=Math.sin(r);return this._x=t.x*n,this._y=t.y*n,this._z=t.z*n,this._w=Math.cos(r),this.onChangeCallback(),this},setFromRotationMatrix:function(t){var e,r=t.elements,n=r[0],i=r[4],a=r[8],o=r[1],s=r[5],c=r[9],l=r[2],h=r[6],u=r[10],d=n+s+u;return d>0?(e=.5/Math.sqrt(d+1),this._w=.25/e,this._x=(h-c)*e,this._y=(a-l)*e,this._z=(o-i)*e):n>s&&n>u?(e=2*Math.sqrt(1+n-s-u),this._w=(h-c)/e,this._x=.25*e,this._y=(i+o)/e,this._z=(a+l)/e):s>u?(e=2*Math.sqrt(1+s-n-u),this._w=(a-l)/e,this._x=(i+o)/e,this._y=.25*e,this._z=(c+h)/e):(e=2*Math.sqrt(1+u-n-s),this._w=(o-i)/e,this._x=(a+l)/e,this._y=(c+h)/e,this._z=.25*e),this.onChangeCallback(),this},setFromUnitVectors:function(){var t,e=new n;return function(r,i){return void 0===e&&(e=new n),t=r.dot(i)+1,t<1e-6?(t=0,Math.abs(r.x)>Math.abs(r.z)?e.set(-r.y,r.x,0):e.set(0,-r.z,r.y)):e.crossVectors(r,i),this._x=e.x,this._y=e.y,this._z=e.z,this._w=t,this.normalize()}}(),inverse:function(){return this.conjugate().normalize()},conjugate:function(){return this._x*=-1,this._y*=-1,this._z*=-1,this.onChangeCallback(),this},dot:function(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w},lengthSq:function(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w},length:function(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)},normalize:function(){var t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this.onChangeCallback(),this},multiply:function(t,e){return void 0!==e?(console.warn("THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead."),this.multiplyQuaternions(t,e)):this.multiplyQuaternions(this,t)},premultiply:function(t){return this.multiplyQuaternions(t,this)},multiplyQuaternions:function(t,e){var r=t._x,n=t._y,i=t._z,a=t._w,o=e._x,s=e._y,c=e._z,l=e._w;return this._x=r*l+a*o+n*c-i*s,this._y=n*l+a*s+i*o-r*c,this._z=i*l+a*c+r*s-n*o,this._w=a*l-r*o-n*s-i*c,this.onChangeCallback(),this},slerp:function(t,e){if(0===e)return this;if(1===e)return this.copy(t);var r=this._x,n=this._y,i=this._z,a=this._w,o=a*t._w+r*t._x+n*t._y+i*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=a,this._x=r,this._y=n,this._z=i,this;var s=Math.sqrt(1-o*o);if(Math.abs(s)<.001)return this._w=.5*(a+this._w),this._x=.5*(r+this._x),this._y=.5*(n+this._y),this._z=.5*(i+this._z),this;var c=Math.atan2(s,o),l=Math.sin((1-e)*c)/s,h=Math.sin(e*c)/s;return this._w=a*l+this._w*h,this._x=r*l+this._x*h,this._y=n*l+this._y*h,this._z=i*l+this._z*h,this.onChangeCallback(),this},equals:function(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w},fromArray:function(t,e){return void 0===e&&(e=0),this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this.onChangeCallback(),this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t},onChange:function(t){return this.onChangeCallback=t,this},onChangeCallback:function(){}}),Object.assign(n.prototype,{isVector3:!0,set:function(t,e,r){return this.x=t,this.y=e,this.z=r,this},setScalar:function(t){return this.x=t,this.y=t,this.z=t,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setZ:function(t){return this.z=t,this},setComponent:function(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this},getComponent:function(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}},clone:function(){return new this.constructor(this.x,this.y,this.z)},copy:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},add:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(t,e)):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this)},addScalar:function(t){return this.x+=t,this.y+=t,this.z+=t,this},addVectors:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this},addScaledVector:function(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this},sub:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(t,e)):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this)},subScalar:function(t){return this.x-=t,this.y-=t,this.z-=t,this},subVectors:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this},multiply:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead."),this.multiplyVectors(t,e)):(this.x*=t.x,this.y*=t.y,this.z*=t.z,this)},multiplyScalar:function(t){return this.x*=t,this.y*=t,this.z*=t,this},multiplyVectors:function(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this},applyEuler:function(){var t=new r;return function(e){return e&&e.isEuler||console.error("THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order."),this.applyQuaternion(t.setFromEuler(e))}}(),applyAxisAngle:function(){var t=new r;return function(e,r){return this.applyQuaternion(t.setFromAxisAngle(e,r))}}(),applyMatrix3:function(t){var e=this.x,r=this.y,n=this.z,i=t.elements;return this.x=i[0]*e+i[3]*r+i[6]*n,this.y=i[1]*e+i[4]*r+i[7]*n,this.z=i[2]*e+i[5]*r+i[8]*n,this},applyMatrix4:function(t){var e=this.x,r=this.y,n=this.z,i=t.elements,a=1/(i[3]*e+i[7]*r+i[11]*n+i[15]);return this.x=(i[0]*e+i[4]*r+i[8]*n+i[12])*a,this.y=(i[1]*e+i[5]*r+i[9]*n+i[13])*a,this.z=(i[2]*e+i[6]*r+i[10]*n+i[14])*a,this},applyQuaternion:function(t){var e=this.x,r=this.y,n=this.z,i=t.x,a=t.y,o=t.z,s=t.w,c=s*e+a*n-o*r,l=s*r+o*e-i*n,h=s*n+i*r-a*e,u=-i*e-a*r-o*n;return this.x=c*s+u*-i+l*-o-h*-a,this.y=l*s+u*-a+h*-i-c*-o,this.z=h*s+u*-o+c*-a-l*-i,this},project:function(){var t=new e;return function(e){return t.multiplyMatrices(e.projectionMatrix,t.getInverse(e.matrixWorld)),this.applyMatrix4(t)}}(),unproject:function(){var t=new e;return function(e){return t.multiplyMatrices(e.matrixWorld,t.getInverse(e.projectionMatrix)),this.applyMatrix4(t)}}(),transformDirection:function(t){var e=this.x,r=this.y,n=this.z,i=t.elements;return this.x=i[0]*e+i[4]*r+i[8]*n,this.y=i[1]*e+i[5]*r+i[9]*n,this.z=i[2]*e+i[6]*r+i[10]*n,this.normalize()},divide:function(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this},divideScalar:function(t){return this.multiplyScalar(1/t)},min:function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this},max:function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this},clamp:function(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this},clampScalar:function(){var t=new n,e=new n;return function(r,n){return t.set(r,r,r),e.set(n,n,n),this.clamp(t,e)}}(),clampLength:function(t,e){var r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(t,Math.min(e,r)))},floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this},negate:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},dot:function(t){return this.x*t.x+this.y*t.y+this.z*t.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length()||1)},setLength:function(t){return this.normalize().multiplyScalar(t)},lerp:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this},lerpVectors:function(t,e,r){return this.subVectors(e,t).multiplyScalar(r).add(t)},cross:function(t,e){if(void 0!==e)return console.warn("THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead."),this.crossVectors(t,e);var r=this.x,n=this.y,i=this.z;return this.x=n*t.z-i*t.y,this.y=i*t.x-r*t.z,this.z=r*t.y-n*t.x,this},crossVectors:function(t,e){var r=t.x,n=t.y,i=t.z,a=e.x,o=e.y,s=e.z;return this.x=n*s-i*o,this.y=i*a-r*s,this.z=r*o-n*a,this},projectOnVector:function(t){var e=t.dot(this)/t.lengthSq();return this.copy(t).multiplyScalar(e)},projectOnPlane:function(){var t=new n;return function(e){return t.copy(this).projectOnVector(e),this.sub(t)}}(),reflect:function(){var t=new n;return function(e){return this.sub(t.copy(e).multiplyScalar(2*this.dot(e)))}}(),angleTo:function(t){var e=this.dot(t)/Math.sqrt(this.lengthSq()*t.lengthSq());return Math.acos(Ko.clamp(e,-1,1))},distanceTo:function(t){return Math.sqrt(this.distanceToSquared(t))},distanceToSquared:function(t){var e=this.x-t.x,r=this.y-t.y,n=this.z-t.z;return e*e+r*r+n*n},distanceToManhattan:function(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)},setFromSpherical:function(t){var e=Math.sin(t.phi)*t.radius;return this.x=e*Math.sin(t.theta),this.y=Math.cos(t.phi)*t.radius,this.z=e*Math.cos(t.theta),this},setFromCylindrical:function(t){return this.x=t.radius*Math.sin(t.theta),this.y=t.y,this.z=t.radius*Math.cos(t.theta),this},setFromMatrixPosition:function(t){var e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this},setFromMatrixScale:function(t){var e=this.setFromMatrixColumn(t,0).length(),r=this.setFromMatrixColumn(t,1).length(),n=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=r,this.z=n,this},setFromMatrixColumn:function(t,e){return this.fromArray(t.elements,4*e)},equals:function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z},fromArray:function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this.z=t[e+2],this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t},fromBufferAttribute:function(t,e,r){return void 0!==r&&console.warn("THREE.Vector3: offset has been removed from .fromBufferAttribute()."),this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}});var $o="1.2.2",ts=1,es=1,rs=2,ns=600,is=0,as=1,os=2,ss=3,cs=4,ls=5,hs=0,us=1,ds=1,ps=2,fs=3,ms=4,gs=5,vs=6,ys=7,xs=8,bs=9,ws=10,_s=11,Ms=1,Es=2,Ss=3,Ts=4,As=5,Ls=6,Cs=7,Rs=8,Ps=9,Is=10,Os=11,Ns=12,Ds=0,Us=1,zs=new n(0,0,1),Bs=new Map;String.prototype.padStart||(String.prototype.padStart=function(t,e){return t>>=0,e=String(e||" "),this.length>t?String(this):((t-=this.length)>e.length&&(e+=e.repeat(t/e.length)),e.slice(0,t)+String(this))}),String.prototype.repeat||(String.prototype.repeat=function(t){if(null==this)throw new TypeError("can't convert "+this+" to object");var e=""+this;if((t=+t)!=t&&(t=0),t<0)throw new RangeError("repeat count must be non-negative");if(t==1/0)throw new RangeError("repeat count must be less than infinity");if(t=Math.floor(t),0==e.length||0==t)return"";if(e.length*t>=1<<28)throw new RangeError("repeat count must not overflow maximum string size");for(var r="";1==(1&t)&&(r+=e),0!=(t>>>=1);)e+=e;return r}),s.stdWidth=40,s.stdMargin=5,s.prototype.removeDomObjects=function(){for(var t,e=0,r=this.domObjects.length;e>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,this},setRGB:function(t,e,r){return this.r=t,this.g=e,this.b=r,this},setHSL:function(){function t(t,e,r){return r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+6*(e-t)*r:r<.5?e:r<2/3?t+6*(e-t)*(2/3-r):t}return function(e,r,n){if(e=Ko.euclideanModulo(e,1),r=Ko.clamp(r,0,1),n=Ko.clamp(n,0,1),0===r)this.r=this.g=this.b=n;else{var i=n<=.5?n*(1+r):n+r-n*r,a=2*n-i;this.r=t(a,i,e+1/3),this.g=t(a,i,e),this.b=t(a,i,e-1/3)}return this}}(),setStyle:function(t){function e(e){void 0!==e&&parseFloat(e)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}var r;if(r=/^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(t)){var n,i=r[1],a=r[2];switch(i){case"rgb":case"rgba":if(n=/^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(a))return this.r=Math.min(255,parseInt(n[1],10))/255,this.g=Math.min(255,parseInt(n[2],10))/255,this.b=Math.min(255,parseInt(n[3],10))/255,e(n[5]),this;if(n=/^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(a))return this.r=Math.min(100,parseInt(n[1],10))/100,this.g=Math.min(100,parseInt(n[2],10))/100,this.b=Math.min(100,parseInt(n[3],10))/100,e(n[5]),this;break;case"hsl":case"hsla":if(n=/^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(a)){var o=parseFloat(n[1])/360,s=parseInt(n[2],10)/100,c=parseInt(n[3],10)/100;return e(n[5]),this.setHSL(o,s,c)}}}else if(r=/^\#([A-Fa-f0-9]+)$/.exec(t)){var l=(h=r[1]).length;if(3===l)return this.r=parseInt(h.charAt(0)+h.charAt(0),16)/255,this.g=parseInt(h.charAt(1)+h.charAt(1),16)/255,this.b=parseInt(h.charAt(2)+h.charAt(2),16)/255,this;if(6===l)return this.r=parseInt(h.charAt(0)+h.charAt(1),16)/255,this.g=parseInt(h.charAt(2)+h.charAt(3),16)/255,this.b=parseInt(h.charAt(4)+h.charAt(5),16)/255,this}if(t&&t.length>0){var h=Fs[t];void 0!==h?this.setHex(h):console.warn("THREE.Color: Unknown color "+t)}return this},clone:function(){return new this.constructor(this.r,this.g,this.b)},copy:function(t){return this.r=t.r,this.g=t.g,this.b=t.b,this},copyGammaToLinear:function(t,e){return void 0===e&&(e=2),this.r=Math.pow(t.r,e),this.g=Math.pow(t.g,e),this.b=Math.pow(t.b,e),this},copyLinearToGamma:function(t,e){void 0===e&&(e=2);var r=e>0?1/e:1;return this.r=Math.pow(t.r,r),this.g=Math.pow(t.g,r),this.b=Math.pow(t.b,r),this},convertGammaToLinear:function(){var t=this.r,e=this.g,r=this.b;return this.r=t*t,this.g=e*e,this.b=r*r,this},convertLinearToGamma:function(){return this.r=Math.sqrt(this.r),this.g=Math.sqrt(this.g),this.b=Math.sqrt(this.b),this},getHex:function(){return 255*this.r<<16^255*this.g<<8^255*this.b<<0},getHexString:function(){return("000000"+this.getHex().toString(16)).slice(-6)},getHSL:function(t){var e,r,n=t||{h:0,s:0,l:0},i=this.r,a=this.g,o=this.b,s=Math.max(i,a,o),c=Math.min(i,a,o),l=(c+s)/2;if(c===s)e=0,r=0;else{var h=s-c;switch(r=l<=.5?h/(s+c):h/(2-s-c),s){case i:e=(a-o)/h+(a2048||e.height>2048?e.toDataURL("image/jpeg",.6):e.toDataURL("image/png")}(r)}),e.image=r.uuid}return t.textures[this.uuid]=e,e},dispose:function(){this.dispatchEvent({type:"dispose"})},transformUv:function(t){if(300===this.mapping){if(t.multiply(this.repeat),t.add(this.offset),t.x<0||t.x>1)switch(this.wrapS){case qc:t.x=t.x-Math.floor(t.x);break;case Zc:t.x=t.x<0?0:1;break;case Jc:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case qc:t.y=t.y-Math.floor(t.y);break;case Zc:t.y=t.y<0?0:1;break;case Jc:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}this.flipY&&(t.y=1-t.y)}}}),d.prototype=Object.create(u.prototype),d.prototype.constructor=d,d.prototype.isDataTexture=!0;var Xl={colors:[],texture:[]},Yl={getTexture:g,getColors:v,red:new c(16711680),yellow:new c(16776960),green:new c(65280),white:new c(16777215),grey:new c(4473924),lightGrey:new c(8947848),hudBlue:new c(1077133),hudRed:new c(8397056)};Object.assign(y.prototype,{isVector4:!0,set:function(t,e,r,n){return this.x=t,this.y=e,this.z=r,this.w=n,this},setScalar:function(t){return this.x=t,this.y=t,this.z=t,this.w=t,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setZ:function(t){return this.z=t,this},setW:function(t){return this.w=t,this},setComponent:function(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this},getComponent:function(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}},clone:function(){return new this.constructor(this.x,this.y,this.z,this.w)},copy:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this},add:function(t,e){return void 0!==e?(console.warn("THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(t,e)):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this)},addScalar:function(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this},addVectors:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this},addScaledVector:function(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this},sub:function(t,e){return void 0!==e?(console.warn("THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(t,e)):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this)},subScalar:function(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this},subVectors:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this},multiplyScalar:function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},applyMatrix4:function(t){var e=this.x,r=this.y,n=this.z,i=this.w,a=t.elements;return this.x=a[0]*e+a[4]*r+a[8]*n+a[12]*i,this.y=a[1]*e+a[5]*r+a[9]*n+a[13]*i,this.z=a[2]*e+a[6]*r+a[10]*n+a[14]*i,this.w=a[3]*e+a[7]*r+a[11]*n+a[15]*i,this},divideScalar:function(t){return this.multiplyScalar(1/t)},setAxisAngleFromQuaternion:function(t){this.w=2*Math.acos(t.w);var e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this},setAxisAngleFromRotationMatrix:function(t){var e,r,n,i,a=t.elements,o=a[0],s=a[4],c=a[8],l=a[1],h=a[5],u=a[9],d=a[2],p=a[6],f=a[10];if(Math.abs(s-l)<.01&&Math.abs(c-d)<.01&&Math.abs(u-p)<.01){if(Math.abs(s+l)<.1&&Math.abs(c+d)<.1&&Math.abs(u+p)<.1&&Math.abs(o+h+f-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;var m=(o+1)/2,g=(h+1)/2,v=(f+1)/2,y=(s+l)/4,x=(c+d)/4,b=(u+p)/4;return m>g&&m>v?m<.01?(r=0,n=.707106781,i=.707106781):(n=y/(r=Math.sqrt(m)),i=x/r):g>v?g<.01?(r=.707106781,n=0,i=.707106781):(r=y/(n=Math.sqrt(g)),i=b/n):v<.01?(r=.707106781,n=.707106781,i=0):(r=x/(i=Math.sqrt(v)),n=b/i),this.set(r,n,i,e),this}var w=Math.sqrt((p-u)*(p-u)+(c-d)*(c-d)+(l-s)*(l-s));return Math.abs(w)<.001&&(w=1),this.x=(p-u)/w,this.y=(c-d)/w,this.z=(l-s)/w,this.w=Math.acos((o+h+f-1)/2),this},min:function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this},max:function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this},clamp:function(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this},clampScalar:function(){var t,e;return function(r,n){return void 0===t&&(t=new y,e=new y),t.set(r,r,r,r),e.set(n,n,n,n),this.clamp(t,e)}}(),clampLength:function(t,e){var r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(t,Math.min(e,r)))},floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this.w=this.w<0?Math.ceil(this.w):Math.floor(this.w),this},negate:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this},dot:function(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)},normalize:function(){return this.divideScalar(this.length()||1)},setLength:function(t){return this.normalize().multiplyScalar(t)},lerp:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this},lerpVectors:function(t,e,r){return this.subVectors(e,t).multiplyScalar(r).add(t)},equals:function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w},fromArray:function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t},fromBufferAttribute:function(t,e,r){return void 0!==r&&console.warn("THREE.Vector4: offset has been removed from .fromBufferAttribute()."),this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}}),Object.assign(x.prototype,l.prototype,{isWebGLRenderTarget:!0,setSize:function(t,e){this.width===t&&this.height===e||(this.width=t,this.height=e,this.dispose()),this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.width=t.width,this.height=t.height,this.viewport.copy(t.viewport),this.texture=t.texture.clone(),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.depthTexture=t.depthTexture,this},dispose:function(){this.dispatchEvent({type:"dispose"})}}),b.prototype=Object.create(u.prototype),b.prototype.constructor=b,b.prototype.isCubeTexture=!0,Object.defineProperty(b.prototype,"images",{get:function(){return this.image},set:function(t){this.image=t}});var ql=new u,Zl=new b,Jl=[],Ql=[],Kl=new Float32Array(16),$l=new Float32Array(9);Q.prototype.setValue=function(t,e){for(var r=this.seq,n=0,i=r.length;n!==i;++n){var a=r[n];a.setValue(t,e[a.id])}};var th=/([\w\d_]+)(\])?(\[|\.)?/g;tt.prototype.setValue=function(t,e,r){var n=this.map[e];void 0!==n&&n.setValue(t,r,this.renderer)},tt.prototype.setOptional=function(t,e,r){var n=e[r];void 0!==n&&this.setValue(t,r,n)},tt.upload=function(t,e,r,n){for(var i=0,a=e.length;i!==a;++i){var o=e[i],s=r[o.id];!1!==s.needsUpdate&&o.setValue(t,s.value,n)}},tt.seqWithValue=function(t,e){for(var r=[],n=0,i=t.length;n!==i;++n){var a=t[n];a.id in e&&r.push(a)}return r};var eh={common:{diffuse:{value:new c(15658734)},opacity:{value:1},map:{value:null},offsetRepeat:{value:new y(0,0,1,1)},specularMap:{value:null},alphaMap:{value:null},envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1}},emissivemap:{emissiveMap:{value:null}},bumpmap:{bumpMap:{value:null},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalScale:{value:new h(1,1)}},displacementmap:{displacementMap:{value:null},displacementScale:{value:1},displacementBias:{value:0}},roughnessmap:{roughnessMap:{value:null}},metalnessmap:{metalnessMap:{value:null}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new c(16777215)}},lights:{ambientLightColor:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{},shadow:{},shadowBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{},shadow:{},shadowBias:{},shadowRadius:{},shadowMapSize:{}}},spotShadowMap:{value:[]},spotShadowMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{},shadow:{},shadowBias:{},shadowRadius:{},shadowMapSize:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}}},points:{diffuse:{value:new c(15658734)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},offsetRepeat:{value:new y(0,0,1,1)}}},rh={merge:function(t){for(var e={},r=0;r 0.0 ) {\r\n\r\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\r\n\r\n\t\t// based upon Frostbite 3 Moving to Physically-based Rendering\r\n\t\t// page 32, equation 26: E[window1]\r\n\t\t// http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr_v2.pdf\r\n\t\t// this is intended to be used on spot and point lights who are represented as luminous intensity\r\n\t\t// but who must be converted to luminous irradiance for surface lighting calculation\r\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\r\n\t\tfloat maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\r\n\t\treturn distanceFalloff * maxDistanceCutoffFactor;\r\n\r\n#else\r\n\r\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\r\n\r\n#endif\r\n\r\n\t}\r\n\r\n\treturn 1.0;\r\n\r\n}\r\n\r\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\r\n\r\n\treturn RECIPROCAL_PI * diffuseColor;\r\n\r\n} // validated\r\n\r\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\r\n\r\n\t// Original approximation by Christophe Schlick \'94\r\n\t// float fresnel = pow( 1.0 - dotLH, 5.0 );\r\n\r\n\t// Optimized variant (presented by Epic at SIGGRAPH \'13)\r\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\r\n\r\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\r\n\r\n} // validated\r\n\r\n// Microfacet Models for Refraction through Rough Surfaces - equation (34)\r\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\r\n// alpha is "roughness squared" in Disney’s reparameterization\r\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\r\n\r\n\t// geometry term = G(l)⋅G(v) / 4(n⋅l)(n⋅v)\r\n\r\n\tfloat a2 = pow2( alpha );\r\n\r\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\r\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\r\n\r\n\treturn 1.0 / ( gl * gv );\r\n\r\n} // validated\r\n\r\n// Moving Frostbite to Physically Based Rendering 2.0 - page 12, listing 2\r\n// http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr_v2.pdf\r\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\r\n\r\n\tfloat a2 = pow2( alpha );\r\n\r\n\t// dotNL and dotNV are explicitly swapped. This is not a mistake.\r\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\r\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\r\n\r\n\treturn 0.5 / max( gv + gl, EPSILON );\r\n}\r\n\r\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\r\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\r\n// alpha is "roughness squared" in Disney’s reparameterization\r\nfloat D_GGX( const in float alpha, const in float dotNH ) {\r\n\r\n\tfloat a2 = pow2( alpha );\r\n\r\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\r\n\r\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\r\n\r\n}\r\n\r\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\r\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\r\n\r\n\tfloat alpha = pow2( roughness ); // UE4\'s roughness\r\n\r\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\r\n\r\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\r\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\r\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\r\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\r\n\r\n\tvec3 F = F_Schlick( specularColor, dotLH );\r\n\r\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\r\n\r\n\tfloat D = D_GGX( alpha, dotNH );\r\n\r\n\treturn F * ( G * D );\r\n\r\n} // validated\r\n\r\n// Rect Area Light\r\n\r\n// Area light computation code adapted from:\r\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\r\n// By: Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt\r\n// https://drive.google.com/file/d/0BzvWIdpUpRx_d09ndGVjNVJzZjA/view\r\n// https://eheitzresearch.wordpress.com/415-2/\r\n// http://blog.selfshadow.com/sandbox/ltc.html\r\n\r\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\r\n\r\n\tconst float LUT_SIZE = 64.0;\r\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\r\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\r\n\r\n\tfloat theta = acos( dot( N, V ) );\r\n\r\n\t// Parameterization of texture:\r\n\t// sqrt(roughness) -> [0,1]\r\n\t// theta -> [0, PI/2]\r\n\tvec2 uv = vec2(\r\n\t\tsqrt( saturate( roughness ) ),\r\n\t\tsaturate( theta / ( 0.5 * PI ) ) );\r\n\r\n\t// Ensure we don\'t have nonlinearities at the look-up table\'s edges\r\n\t// see: http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html\r\n\t// "Shader Analysis" section\r\n\tuv = uv * LUT_SCALE + LUT_BIAS;\r\n\r\n\treturn uv;\r\n\r\n}\r\n\r\n// Real-Time Area Lighting: a Journey from Research to Production\r\n// By: Stephen Hill & Eric Heitz\r\n// http://advances.realtimerendering.com/s2016/s2016_ltc_rnd.pdf\r\n// An approximation for the form factor of a clipped rectangle.\r\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\r\n\r\n\tfloat l = length( f );\r\n\r\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\r\n\r\n}\r\n\r\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\r\n// also Real-Time Area Lighting: a Journey from Research to Production\r\n// http://advances.realtimerendering.com/s2016/s2016_ltc_rnd.pdf\r\n// Normalization by 2*PI is incorporated in this function itself.\r\n// theta/sin(theta) is approximated by rational polynomial\r\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\r\n\r\n\tfloat x = dot( v1, v2 );\r\n\r\n\tfloat y = abs( x );\r\n\tfloat a = 0.86267 + (0.49788 + 0.01436 * y ) * y;\r\n\tfloat b = 3.45068 + (4.18814 + y) * y;\r\n\tfloat v = a / b;\r\n\r\n\tfloat theta_sintheta = (x > 0.0) ? v : 0.5 * inversesqrt( 1.0 - x * x ) - v;\r\n\r\n\treturn cross( v1, v2 ) * theta_sintheta;\r\n\r\n}\r\n\r\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\r\n\r\n\t// bail if point is on back side of plane of light\r\n\t// assumes ccw winding order of light vertices\r\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\r\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\r\n\tvec3 lightNormal = cross( v1, v2 );\r\n\r\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\r\n\r\n\t// construct orthonormal basis around N\r\n\tvec3 T1, T2;\r\n\tT1 = normalize( V - N * dot( V, N ) );\r\n\tT2 = - cross( N, T1 ); // negated from paper; possibly due to a different assumed handedness of world coordinate system\r\n\r\n\t// compute transform\r\n\tmat3 mat = mInv * transpose( mat3( T1, T2, N ) );\r\n\r\n\t// transform rect\r\n\tvec3 coords[ 4 ];\r\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\r\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\r\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\r\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\r\n\r\n\t// project rect onto sphere\r\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\r\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\r\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\r\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\r\n\r\n\t// calculate vector form factor\r\n\tvec3 vectorFormFactor = vec3( 0.0 );\r\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\r\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\r\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\r\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\r\n\r\n\t// adjust for horizon clipping\r\n\tvec3 result = vec3( LTC_ClippedSphereFormFactor( vectorFormFactor ) );\r\n\r\n\treturn result;\r\n\r\n}\r\n\r\n// End Rect Area Light\r\n\r\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\r\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\r\n\r\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\r\n\r\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\r\n\r\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\r\n\r\n\tvec4 r = roughness * c0 + c1;\r\n\r\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\r\n\r\n\tvec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\r\n\r\n\treturn specularColor * AB.x + AB.y;\r\n\r\n} // validated\r\n\r\n\r\nfloat G_BlinnPhong_Implicit( ) {\r\n\r\n\t// geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\r\n\treturn 0.25;\r\n\r\n}\r\n\r\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\r\n\r\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\r\n\r\n}\r\n\r\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\r\n\r\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\r\n\r\n\t//float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\r\n\t//float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\r\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\r\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\r\n\r\n\tvec3 F = F_Schlick( specularColor, dotLH );\r\n\r\n\tfloat G = G_BlinnPhong_Implicit( );\r\n\r\n\tfloat D = D_BlinnPhong( shininess, dotNH );\r\n\r\n\treturn F * ( G * D );\r\n\r\n} // validated\r\n\r\n// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html\r\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\r\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\r\n}\r\n\r\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\r\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\r\n}\r\n',bumpmap_pars_fragment:"#ifdef USE_BUMPMAP\r\n\r\n\tuniform sampler2D bumpMap;\r\n\tuniform float bumpScale;\r\n\r\n\t// Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen\r\n\t// http://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html\r\n\r\n\t// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\r\n\r\n\tvec2 dHdxy_fwd() {\r\n\r\n\t\tvec2 dSTdx = dFdx( vUv );\r\n\t\tvec2 dSTdy = dFdy( vUv );\r\n\r\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\r\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\r\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\r\n\r\n\t\treturn vec2( dBx, dBy );\r\n\r\n\t}\r\n\r\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\r\n\r\n\t\t// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988\r\n\r\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\r\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\r\n\t\tvec3 vN = surf_norm;\t\t// normalized\r\n\r\n\t\tvec3 R1 = cross( vSigmaY, vN );\r\n\t\tvec3 R2 = cross( vN, vSigmaX );\r\n\r\n\t\tfloat fDet = dot( vSigmaX, R1 );\r\n\r\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\r\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\r\n\r\n\t}\r\n\r\n#endif\r\n",clipping_planes_fragment:"#if NUM_CLIPPING_PLANES > 0\r\n\r\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; ++ i ) {\r\n\r\n\t\tvec4 plane = clippingPlanes[ i ];\r\n\t\tif ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\r\n\r\n\t}\r\n\t\t\r\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\r\n\r\n\t\tbool clipped = true;\r\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; ++ i ) {\r\n\t\t\tvec4 plane = clippingPlanes[ i ];\r\n\t\t\tclipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;\r\n\t\t}\r\n\r\n\t\tif ( clipped ) discard;\r\n\t\r\n\t#endif\r\n\r\n#endif\r\n",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\r\n\r\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG )\r\n\t\tvarying vec3 vViewPosition;\r\n\t#endif\r\n\r\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\r\n\r\n#endif\r\n",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\r\n\tvarying vec3 vViewPosition;\r\n#endif\r\n",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\r\n\tvViewPosition = - mvPosition.xyz;\r\n#endif\r\n\r\n",color_fragment:"#ifdef USE_COLOR\r\n\r\n\tdiffuseColor.rgb *= vColor;\r\n\r\n#endif",color_pars_fragment:"#ifdef USE_COLOR\r\n\r\n\tvarying vec3 vColor;\r\n\r\n#endif\r\n",color_pars_vertex:"#ifdef USE_COLOR\r\n\r\n\tvarying vec3 vColor;\r\n\r\n#endif",color_vertex:"#ifdef USE_COLOR\r\n\r\n\tvColor.xyz = color.xyz;\r\n\r\n#endif",common:"#define PI 3.14159265359\r\n#define PI2 6.28318530718\r\n#define PI_HALF 1.5707963267949\r\n#define RECIPROCAL_PI 0.31830988618\r\n#define RECIPROCAL_PI2 0.15915494\r\n#define LOG2 1.442695\r\n#define EPSILON 1e-6\r\n\r\n#define saturate(a) clamp( a, 0.0, 1.0 )\r\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\r\n\r\nfloat pow2( const in float x ) { return x*x; }\r\nfloat pow3( const in float x ) { return x*x*x; }\r\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\r\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\r\n// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.\r\n// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/\r\nhighp float rand( const in vec2 uv ) {\r\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\r\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\r\n\treturn fract(sin(sn) * c);\r\n}\r\n\r\nstruct IncidentLight {\r\n\tvec3 color;\r\n\tvec3 direction;\r\n\tbool visible;\r\n};\r\n\r\nstruct ReflectedLight {\r\n\tvec3 directDiffuse;\r\n\tvec3 directSpecular;\r\n\tvec3 indirectDiffuse;\r\n\tvec3 indirectSpecular;\r\n};\r\n\r\nstruct GeometricContext {\r\n\tvec3 position;\r\n\tvec3 normal;\r\n\tvec3 viewDir;\r\n};\r\n\r\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\r\n\r\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\r\n\r\n}\r\n\r\n// http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations\r\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\r\n\r\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\r\n\r\n}\r\n\r\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\r\n\r\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\r\n\r\n\treturn - distance * planeNormal + point;\r\n\r\n}\r\n\r\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\r\n\r\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\r\n\r\n}\r\n\r\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\r\n\r\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\r\n\r\n}\r\n\r\nmat3 transpose( const in mat3 v ) {\r\n\r\n\tmat3 tmp;\r\n\ttmp[0] = vec3(v[0].x, v[1].x, v[2].x);\r\n\ttmp[1] = vec3(v[0].y, v[1].y, v[2].y);\r\n\ttmp[2] = vec3(v[0].z, v[1].z, v[2].z);\r\n\r\n\treturn tmp;\r\n\r\n}\r\n",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\r\n\r\n#define cubeUV_textureSize (1024.0)\r\n\r\nint getFaceFromDirection(vec3 direction) {\r\n\tvec3 absDirection = abs(direction);\r\n\tint face = -1;\r\n\tif( absDirection.x > absDirection.z ) {\r\n\t\tif(absDirection.x > absDirection.y )\r\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\r\n\t\telse\r\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\r\n\t}\r\n\telse {\r\n\t\tif(absDirection.z > absDirection.y )\r\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\r\n\t\telse\r\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\r\n\t}\r\n\treturn face;\r\n}\r\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\r\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\r\n\r\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\r\n\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\r\n\tfloat dxRoughness = dFdx(roughness);\r\n\tfloat dyRoughness = dFdy(roughness);\r\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\r\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\r\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\r\n\t// Clamp the value to the max mip level counts. hard coded to 6 mips\r\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\r\n\tfloat mipLevel = 0.5 * log2(d);\r\n\treturn vec2(floor(mipLevel), fract(mipLevel));\r\n}\r\n\r\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\r\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\r\n\r\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\r\n\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\r\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\r\n\r\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\r\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\r\n\t// float powScale = exp2(roughnessLevel + mipLevel);\r\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\r\n\t// float scale = 1.0 / exp2(roughnessLevel + 2.0 + mipLevel);\r\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\r\n\t// float mipOffset = 0.75*(1.0 - 1.0/exp2(mipLevel))/exp2(roughnessLevel);\r\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\r\n\r\n\tbool bRes = mipLevel == 0.0;\r\n\tscale = bRes && (scale < a) ? a : scale;\r\n\r\n\tvec3 r;\r\n\tvec2 offset;\r\n\tint face = getFaceFromDirection(direction);\r\n\r\n\tfloat rcpPowScale = 1.0 / powScale;\r\n\r\n\tif( face == 0) {\r\n\t\tr = vec3(direction.x, -direction.z, direction.y);\r\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\r\n\t}\r\n\telse if( face == 1) {\r\n\t\tr = vec3(direction.y, direction.x, direction.z);\r\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\r\n\t}\r\n\telse if( face == 2) {\r\n\t\tr = vec3(direction.z, direction.x, direction.y);\r\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\r\n\t}\r\n\telse if( face == 3) {\r\n\t\tr = vec3(direction.x, direction.z, direction.y);\r\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\r\n\t}\r\n\telse if( face == 4) {\r\n\t\tr = vec3(direction.y, direction.x, -direction.z);\r\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\r\n\t}\r\n\telse {\r\n\t\tr = vec3(direction.z, -direction.x, direction.y);\r\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\r\n\t}\r\n\tr = normalize(r);\r\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\r\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\r\n\tvec2 base = offset + vec2( texelOffset );\r\n\treturn base + s * ( scale - 2.0 * texelOffset );\r\n}\r\n\r\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\r\n\r\nvec4 textureCubeUV(vec3 reflectedDirection, float roughness ) {\r\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\r\n\tfloat r1 = floor(roughnessVal);\r\n\tfloat r2 = r1 + 1.0;\r\n\tfloat t = fract(roughnessVal);\r\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\r\n\tfloat s = mipInfo.y;\r\n\tfloat level0 = mipInfo.x;\r\n\tfloat level1 = level0 + 1.0;\r\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\r\n\r\n\t// round to nearest mipmap if we are not interpolating.\r\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\r\n\r\n\t// Tri linear interpolation.\r\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\r\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\r\n\r\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\r\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\r\n\r\n\tvec4 result = mix(color10, color20, t);\r\n\r\n\treturn vec4(result.rgb, 1.0);\r\n}\r\n\r\n#endif\r\n",defaultnormal_vertex:"vec3 transformedNormal = normalMatrix * objectNormal;\r\n\r\n#ifdef FLIP_SIDED\r\n\r\n\ttransformedNormal = - transformedNormal;\r\n\r\n#endif\r\n",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\r\n\r\n\tuniform sampler2D displacementMap;\r\n\tuniform float displacementScale;\r\n\tuniform float displacementBias;\r\n\r\n#endif\r\n",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\r\n\r\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\r\n\r\n#endif\r\n",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\r\n\r\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\r\n\r\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\r\n\r\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\r\n\r\n#endif\r\n",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\r\n\r\n\tuniform sampler2D emissiveMap;\r\n\r\n#endif\r\n",encodings_fragment:" gl_FragColor = linearToOutputTexel( gl_FragColor );\r\n",encodings_pars_fragment:"// For a discussion of what this is, please read this: http://lousodrome.net/blog/light/2013/05/26/gamma-correct-and-hdr-rendering-in-a-32-bits-buffer/\r\n\r\nvec4 LinearToLinear( in vec4 value ) {\r\n\treturn value;\r\n}\r\n\r\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\r\n\treturn vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );\r\n}\r\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\r\n\treturn vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\r\n}\r\n\r\nvec4 sRGBToLinear( in vec4 value ) {\r\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );\r\n}\r\nvec4 LinearTosRGB( in vec4 value ) {\r\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );\r\n}\r\n\r\nvec4 RGBEToLinear( in vec4 value ) {\r\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\r\n}\r\nvec4 LinearToRGBE( in vec4 value ) {\r\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\r\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\r\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\r\n// return vec4( value.brg, ( 3.0 + 128.0 ) / 256.0 );\r\n}\r\n\r\n// reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html\r\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\r\n\treturn vec4( value.xyz * value.w * maxRange, 1.0 );\r\n}\r\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\r\n\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\r\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\r\n\tM = ceil( M * 255.0 ) / 255.0;\r\n\treturn vec4( value.rgb / ( M * maxRange ), M );\r\n}\r\n\r\n// reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html\r\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\r\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\r\n}\r\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\r\n\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\r\n\tfloat D = max( maxRange / maxRGB, 1.0 );\r\n\tD = min( floor( D ) / 255.0, 1.0 );\r\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\r\n}\r\n\r\n// LogLuv reference: http://graphicrants.blogspot.ca/2009/04/rgbm-color-encoding.html\r\n\r\n// M matrix, for encoding\r\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\r\nvec4 LinearToLogLuv( in vec4 value ) {\r\n\tvec3 Xp_Y_XYZp = value.rgb * cLogLuvM;\r\n\tXp_Y_XYZp = max(Xp_Y_XYZp, vec3(1e-6, 1e-6, 1e-6));\r\n\tvec4 vResult;\r\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\r\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\r\n\tvResult.w = fract(Le);\r\n\tvResult.z = (Le - (floor(vResult.w*255.0))/255.0)/255.0;\r\n\treturn vResult;\r\n}\r\n\r\n// Inverse M matrix, for decoding\r\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\r\nvec4 LogLuvToLinear( in vec4 value ) {\r\n\tfloat Le = value.z * 255.0 + value.w;\r\n\tvec3 Xp_Y_XYZp;\r\n\tXp_Y_XYZp.y = exp2((Le - 127.0) / 2.0);\r\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\r\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\r\n\tvec3 vRGB = Xp_Y_XYZp.rgb * cLogLuvInverseM;\r\n\treturn vec4( max(vRGB, 0.0), 1.0 );\r\n}\r\n",envmap_fragment:"#ifdef USE_ENVMAP\r\n\r\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\r\n\r\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\r\n\r\n\t\t// Transforming Normal Vectors with the Inverse Transformation\r\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\r\n\r\n\t\t#ifdef ENVMAP_MODE_REFLECTION\r\n\r\n\t\t\tvec3 reflectVec = reflect( cameraToVertex, worldNormal );\r\n\r\n\t\t#else\r\n\r\n\t\t\tvec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\r\n\r\n\t\t#endif\r\n\r\n\t#else\r\n\r\n\t\tvec3 reflectVec = vReflect;\r\n\r\n\t#endif\r\n\r\n\t#ifdef ENVMAP_TYPE_CUBE\r\n\r\n\t\tvec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\r\n\r\n\t#elif defined( ENVMAP_TYPE_EQUIREC )\r\n\r\n\t\tvec2 sampleUV;\r\n\t\tsampleUV.y = asin( flipNormal * reflectVec.y ) * RECIPROCAL_PI + 0.5;\r\n\t\tsampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\r\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\r\n\r\n\t#elif defined( ENVMAP_TYPE_SPHERE )\r\n\r\n\t\tvec3 reflectView = flipNormal * normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );\r\n\t\tvec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\r\n\r\n\t#else\r\n\r\n\t\tvec4 envColor = vec4( 0.0 );\r\n\r\n\t#endif\r\n\r\n\tenvColor = envMapTexelToLinear( envColor );\r\n\r\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\r\n\r\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\r\n\r\n\t#elif defined( ENVMAP_BLENDING_MIX )\r\n\r\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\r\n\r\n\t#elif defined( ENVMAP_BLENDING_ADD )\r\n\r\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\r\n\r\n\t#endif\r\n\r\n#endif\r\n",envmap_pars_fragment:"#if defined( USE_ENVMAP ) || defined( PHYSICAL )\r\n\tuniform float reflectivity;\r\n\tuniform float envMapIntensity;\r\n#endif\r\n\r\n#ifdef USE_ENVMAP\r\n\r\n\t#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\r\n\t\tvarying vec3 vWorldPosition;\r\n\t#endif\r\n\r\n\t#ifdef ENVMAP_TYPE_CUBE\r\n\t\tuniform samplerCube envMap;\r\n\t#else\r\n\t\tuniform sampler2D envMap;\r\n\t#endif\r\n\tuniform float flipEnvMap;\r\n\r\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\r\n\t\tuniform float refractionRatio;\r\n\t#else\r\n\t\tvarying vec3 vReflect;\r\n\t#endif\r\n\r\n#endif\r\n",envmap_pars_vertex:"#ifdef USE_ENVMAP\r\n\r\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\r\n\t\tvarying vec3 vWorldPosition;\r\n\r\n\t#else\r\n\r\n\t\tvarying vec3 vReflect;\r\n\t\tuniform float refractionRatio;\r\n\r\n\t#endif\r\n\r\n#endif\r\n",envmap_vertex:"#ifdef USE_ENVMAP\r\n\r\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\r\n\r\n\t\tvWorldPosition = worldPosition.xyz;\r\n\r\n\t#else\r\n\r\n\t\tvec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\r\n\r\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\r\n\r\n\t\t#ifdef ENVMAP_MODE_REFLECTION\r\n\r\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\r\n\r\n\t\t#else\r\n\r\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\r\n\r\n\t\t#endif\r\n\r\n\t#endif\r\n\r\n#endif\r\n",fog_vertex:"\r\n#ifdef USE_FOG\r\nfogDepth = -mvPosition.z;\r\n#endif",fog_pars_vertex:"#ifdef USE_FOG\r\n\r\n varying float fogDepth;\r\n\r\n#endif\r\n",fog_fragment:"#ifdef USE_FOG\r\n\r\n\t#ifdef FOG_EXP2\r\n\r\n\t\tfloat fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 ) );\r\n\r\n\t#else\r\n\r\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\r\n\r\n\t#endif\r\n\r\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\r\n\r\n#endif\r\n",fog_pars_fragment:"#ifdef USE_FOG\r\n\r\n\tuniform vec3 fogColor;\r\n\tvarying float fogDepth;\r\n\r\n\t#ifdef FOG_EXP2\r\n\r\n\t\tuniform float fogDensity;\r\n\r\n\t#else\r\n\r\n\t\tuniform float fogNear;\r\n\t\tuniform float fogFar;\r\n\r\n\t#endif\r\n\r\n#endif\r\n",gradientmap_pars_fragment:"#ifdef TOON\r\n\r\n\tuniform sampler2D gradientMap;\r\n\r\n\tvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\r\n\r\n\t\t// dotNL will be from -1.0 to 1.0\r\n\t\tfloat dotNL = dot( normal, lightDirection );\r\n\t\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\r\n\r\n\t\t#ifdef USE_GRADIENTMAP\r\n\r\n\t\t\treturn texture2D( gradientMap, coord ).rgb;\r\n\r\n\t\t#else\r\n\r\n\t\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\r\n\r\n\t\t#endif\r\n\r\n\r\n\t}\r\n\r\n#endif\r\n",lightmap_fragment:"#ifdef USE_LIGHTMAP\r\n\r\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity; // factor of PI should not be present; included here to prevent breakage\r\n\r\n#endif\r\n",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\r\n\r\n\tuniform sampler2D lightMap;\r\n\tuniform float lightMapIntensity;\r\n\r\n#endif",lights_lambert_vertex:"vec3 diffuse = vec3( 1.0 );\r\n\r\nGeometricContext geometry;\r\ngeometry.position = mvPosition.xyz;\r\ngeometry.normal = normalize( transformedNormal );\r\ngeometry.viewDir = normalize( -mvPosition.xyz );\r\n\r\nGeometricContext backGeometry;\r\nbackGeometry.position = geometry.position;\r\nbackGeometry.normal = -geometry.normal;\r\nbackGeometry.viewDir = geometry.viewDir;\r\n\r\nvLightFront = vec3( 0.0 );\r\n\r\n#ifdef DOUBLE_SIDED\r\n\tvLightBack = vec3( 0.0 );\r\n#endif\r\n\r\nIncidentLight directLight;\r\nfloat dotNL;\r\nvec3 directLightColor_Diffuse;\r\n\r\n#if NUM_POINT_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\r\n\r\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\r\n\r\n\t\tdotNL = dot( geometry.normal, directLight.direction );\r\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\r\n\r\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#ifdef DOUBLE_SIDED\r\n\r\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#endif\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if NUM_SPOT_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\r\n\r\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\r\n\r\n\t\tdotNL = dot( geometry.normal, directLight.direction );\r\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\r\n\r\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#ifdef DOUBLE_SIDED\r\n\r\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#endif\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n\r\n#if NUM_DIR_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\r\n\r\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\r\n\r\n\t\tdotNL = dot( geometry.normal, directLight.direction );\r\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\r\n\r\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#ifdef DOUBLE_SIDED\r\n\r\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#endif\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if NUM_HEMI_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\r\n\r\n\t\tvLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\r\n\r\n\t\t#ifdef DOUBLE_SIDED\r\n\r\n\t\t\tvLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\r\n\r\n\t\t#endif\r\n\r\n\t}\r\n\r\n#endif\r\n",lights_pars:"uniform vec3 ambientLightColor;\r\n\r\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\r\n\r\n\tvec3 irradiance = ambientLightColor;\r\n\r\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\tirradiance *= PI;\r\n\r\n\t#endif\r\n\r\n\treturn irradiance;\r\n\r\n}\r\n\r\n#if NUM_DIR_LIGHTS > 0\r\n\r\n\tstruct DirectionalLight {\r\n\t\tvec3 direction;\r\n\t\tvec3 color;\r\n\r\n\t\tint shadow;\r\n\t\tfloat shadowBias;\r\n\t\tfloat shadowRadius;\r\n\t\tvec2 shadowMapSize;\r\n\t};\r\n\r\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\r\n\r\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\r\n\r\n\t\tdirectLight.color = directionalLight.color;\r\n\t\tdirectLight.direction = directionalLight.direction;\r\n\t\tdirectLight.visible = true;\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n#if NUM_POINT_LIGHTS > 0\r\n\r\n\tstruct PointLight {\r\n\t\tvec3 position;\r\n\t\tvec3 color;\r\n\t\tfloat distance;\r\n\t\tfloat decay;\r\n\r\n\t\tint shadow;\r\n\t\tfloat shadowBias;\r\n\t\tfloat shadowRadius;\r\n\t\tvec2 shadowMapSize;\r\n\t};\r\n\r\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\r\n\r\n\t// directLight is an out parameter as having it as a return value caused compiler errors on some devices\r\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\r\n\r\n\t\tvec3 lVector = pointLight.position - geometry.position;\r\n\t\tdirectLight.direction = normalize( lVector );\r\n\r\n\t\tfloat lightDistance = length( lVector );\r\n\r\n\t\tdirectLight.color = pointLight.color;\r\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\r\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n#if NUM_SPOT_LIGHTS > 0\r\n\r\n\tstruct SpotLight {\r\n\t\tvec3 position;\r\n\t\tvec3 direction;\r\n\t\tvec3 color;\r\n\t\tfloat distance;\r\n\t\tfloat decay;\r\n\t\tfloat coneCos;\r\n\t\tfloat penumbraCos;\r\n\r\n\t\tint shadow;\r\n\t\tfloat shadowBias;\r\n\t\tfloat shadowRadius;\r\n\t\tvec2 shadowMapSize;\r\n\t};\r\n\r\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\r\n\r\n\t// directLight is an out parameter as having it as a return value caused compiler errors on some devices\r\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\r\n\r\n\t\tvec3 lVector = spotLight.position - geometry.position;\r\n\t\tdirectLight.direction = normalize( lVector );\r\n\r\n\t\tfloat lightDistance = length( lVector );\r\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\r\n\r\n\t\tif ( angleCos > spotLight.coneCos ) {\r\n\r\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\r\n\r\n\t\t\tdirectLight.color = spotLight.color;\r\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\r\n\t\t\tdirectLight.visible = true;\r\n\r\n\t\t} else {\r\n\r\n\t\t\tdirectLight.color = vec3( 0.0 );\r\n\t\t\tdirectLight.visible = false;\r\n\r\n\t\t}\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n#if NUM_RECT_AREA_LIGHTS > 0\r\n\r\n\tstruct RectAreaLight {\r\n\t\tvec3 color;\r\n\t\tvec3 position;\r\n\t\tvec3 halfWidth;\r\n\t\tvec3 halfHeight;\r\n\t};\r\n\r\n\t// Pre-computed values of LinearTransformedCosine approximation of BRDF\r\n\t// BRDF approximation Texture is 64x64\r\n\tuniform sampler2D ltcMat; // RGBA Float\r\n\tuniform sampler2D ltcMag; // Alpha Float (only has w component)\r\n\r\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\r\n\r\n#endif\r\n\r\n\r\n#if NUM_HEMI_LIGHTS > 0\r\n\r\n\tstruct HemisphereLight {\r\n\t\tvec3 direction;\r\n\t\tvec3 skyColor;\r\n\t\tvec3 groundColor;\r\n\t};\r\n\r\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\r\n\r\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\r\n\r\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\r\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\r\n\r\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\r\n\r\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\t\tirradiance *= PI;\r\n\r\n\t\t#endif\r\n\r\n\t\treturn irradiance;\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n#if defined( USE_ENVMAP ) && defined( PHYSICAL )\r\n\r\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\r\n\r\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\r\n\r\n\t\t#ifdef ENVMAP_TYPE_CUBE\r\n\r\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\r\n\r\n\t\t\t// TODO: replace with properly filtered cubemaps and access the irradiance LOD level, be it the last LOD level\r\n\t\t\t// of a specular cubemap, or just the default level of a specially created irradiance cubemap.\r\n\r\n\t\t\t#ifdef TEXTURE_LOD_EXT\r\n\r\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\r\n\r\n\t\t\t#else\r\n\r\n\t\t\t\t// force the bias high to get the last LOD level as it is the most blurred.\r\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\r\n\r\n\t\t\t#endif\r\n\r\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\r\n\r\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\r\n\r\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\r\n\t\t\tvec4 envMapColor = textureCubeUV( queryVec, 1.0 );\r\n\r\n\t\t#else\r\n\r\n\t\t\tvec4 envMapColor = vec4( 0.0 );\r\n\r\n\t\t#endif\r\n\r\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\r\n\r\n\t}\r\n\r\n\t// taken from here: http://casual-effects.blogspot.ca/2011/08/plausible-environment-lighting-in-two.html\r\n\tfloat getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\r\n\r\n\t\t//float envMapWidth = pow( 2.0, maxMIPLevelScalar );\r\n\t\t//float desiredMIPLevel = log2( envMapWidth * sqrt( 3.0 ) ) - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\r\n\r\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\r\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\r\n\r\n\t\t// clamp to allowable LOD ranges.\r\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\r\n\r\n\t}\r\n\r\n\tvec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\r\n\r\n\t\t#ifdef ENVMAP_MODE_REFLECTION\r\n\r\n\t\t\tvec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\r\n\r\n\t\t#else\r\n\r\n\t\t\tvec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\r\n\r\n\t\t#endif\r\n\r\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\r\n\r\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\r\n\r\n\t\t#ifdef ENVMAP_TYPE_CUBE\r\n\r\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\r\n\r\n\t\t\t#ifdef TEXTURE_LOD_EXT\r\n\r\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\r\n\r\n\t\t\t#else\r\n\r\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\r\n\r\n\t\t\t#endif\r\n\r\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\r\n\r\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\r\n\r\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\r\n\t\t\tvec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\r\n\r\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\r\n\r\n\t\t\tvec2 sampleUV;\r\n\t\t\tsampleUV.y = saturate( reflectVec.y * 0.5 + 0.5 );\r\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\r\n\r\n\t\t\t#ifdef TEXTURE_LOD_EXT\r\n\r\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\r\n\r\n\t\t\t#else\r\n\r\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\r\n\r\n\t\t\t#endif\r\n\r\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\r\n\r\n\t\t#elif defined( ENVMAP_TYPE_SPHERE )\r\n\r\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\r\n\r\n\t\t\t#ifdef TEXTURE_LOD_EXT\r\n\r\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\r\n\r\n\t\t\t#else\r\n\r\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\r\n\r\n\t\t\t#endif\r\n\r\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\r\n\r\n\t\t#endif\r\n\r\n\t\treturn envMapColor.rgb * envMapIntensity;\r\n\r\n\t}\r\n\r\n#endif\r\n",lights_phong_fragment:"BlinnPhongMaterial material;\r\nmaterial.diffuseColor = diffuseColor.rgb;\r\nmaterial.specularColor = specular;\r\nmaterial.specularShininess = shininess;\r\nmaterial.specularStrength = specularStrength;\r\n",lights_phong_pars_fragment:"varying vec3 vViewPosition;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n\r\nstruct BlinnPhongMaterial {\r\n\r\n\tvec3\tdiffuseColor;\r\n\tvec3\tspecularColor;\r\n\tfloat\tspecularShininess;\r\n\tfloat\tspecularStrength;\r\n\r\n};\r\n\r\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\t#ifdef TOON\r\n\r\n\t\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\r\n\r\n\t#else\r\n\r\n\t\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\r\n\t\tvec3 irradiance = dotNL * directLight.color;\r\n\r\n\t#endif\r\n\r\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\tirradiance *= PI; // punctual light\r\n\r\n\t#endif\r\n\r\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\r\n\r\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\r\n\r\n}\r\n\r\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\r\n\r\n}\r\n\r\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\r\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\r\n\r\n#define Material_LightProbeLOD( material )\t(0)\r\n",lights_physical_fragment:"PhysicalMaterial material;\r\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\r\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\r\n#ifdef STANDARD\r\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\r\n#else\r\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\r\n\tmaterial.clearCoat = saturate( clearCoat ); // Burley clearcoat model\r\n\tmaterial.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );\r\n#endif\r\n",lights_physical_pars_fragment:"struct PhysicalMaterial {\r\n\r\n\tvec3\tdiffuseColor;\r\n\tfloat\tspecularRoughness;\r\n\tvec3\tspecularColor;\r\n\r\n\t#ifndef STANDARD\r\n\t\tfloat clearCoat;\r\n\t\tfloat clearCoatRoughness;\r\n\t#endif\r\n\r\n};\r\n\r\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\r\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\r\n\r\n// Clear coat directional hemishperical reflectance (this approximation should be improved)\r\nfloat clearCoatDHRApprox( const in float roughness, const in float dotNL ) {\r\n\r\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\r\n\r\n}\r\n\r\n#if NUM_RECT_AREA_LIGHTS > 0\r\n\r\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\t\tvec3 normal = geometry.normal;\r\n\t\tvec3 viewDir = geometry.viewDir;\r\n\t\tvec3 position = geometry.position;\r\n\t\tvec3 lightPos = rectAreaLight.position;\r\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\r\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\r\n\t\tvec3 lightColor = rectAreaLight.color;\r\n\t\tfloat roughness = material.specularRoughness;\r\n\r\n\t\tvec3 rectCoords[ 4 ];\r\n\t\trectCoords[ 0 ] = lightPos - halfWidth - halfHeight; // counterclockwise\r\n\t\trectCoords[ 1 ] = lightPos + halfWidth - halfHeight;\r\n\t\trectCoords[ 2 ] = lightPos + halfWidth + halfHeight;\r\n\t\trectCoords[ 3 ] = lightPos - halfWidth + halfHeight;\r\n\r\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\r\n\r\n\t\tfloat norm = texture2D( ltcMag, uv ).a;\r\n\r\n\t\tvec4 t = texture2D( ltcMat, uv );\r\n\r\n\t\tmat3 mInv = mat3(\r\n\t\t\tvec3( 1, 0, t.y ),\r\n\t\t\tvec3( 0, t.z, 0 ),\r\n\t\t\tvec3( t.w, 0, t.x )\r\n\t\t);\r\n\r\n\t\treflectedLight.directSpecular += lightColor * material.specularColor * norm * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords ); // no fresnel\r\n\r\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1 ), rectCoords );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\r\n\r\n\tvec3 irradiance = dotNL * directLight.color;\r\n\r\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\tirradiance *= PI; // punctual light\r\n\r\n\t#endif\r\n\r\n\t#ifndef STANDARD\r\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\r\n\t#else\r\n\t\tfloat clearCoatDHR = 0.0;\r\n\t#endif\r\n\r\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\r\n\r\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\r\n\r\n\t#ifndef STANDARD\r\n\r\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\r\n\r\n\t#endif\r\n\r\n}\r\n\r\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\r\n\r\n}\r\n\r\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\t#ifndef STANDARD\r\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\r\n\t\tfloat dotNL = dotNV;\r\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\r\n\t#else\r\n\t\tfloat clearCoatDHR = 0.0;\r\n\t#endif\r\n\r\n\treflectedLight.indirectSpecular += ( 1.0 - clearCoatDHR ) * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\r\n\r\n\t#ifndef STANDARD\r\n\r\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\r\n\r\n\t#endif\r\n\r\n}\r\n\r\n#define RE_Direct\t\t\t\tRE_Direct_Physical\r\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\r\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\r\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\r\n\r\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\r\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\r\n\r\n// ref: http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr_v2.pdf\r\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\r\n\r\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\r\n\r\n}\r\n",lights_template:"\r\n\r\nGeometricContext geometry;\r\n\r\ngeometry.position = - vViewPosition;\r\ngeometry.normal = normal;\r\ngeometry.viewDir = normalize( vViewPosition );\r\n\r\nIncidentLight directLight;\r\n\r\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\r\n\r\n\tPointLight pointLight;\r\n\r\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\r\n\r\n\t\tpointLight = pointLights[ i ];\r\n\r\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\r\n\r\n\t\t#ifdef USE_SHADOWMAP\r\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\r\n\t\t#endif\r\n\r\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\r\n\r\n\tSpotLight spotLight;\r\n\r\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\r\n\r\n\t\tspotLight = spotLights[ i ];\r\n\r\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\r\n\r\n\t\t#ifdef USE_SHADOWMAP\r\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\r\n\t\t#endif\r\n\r\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\r\n\r\n\tDirectionalLight directionalLight;\r\n\r\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\r\n\r\n\t\tdirectionalLight = directionalLights[ i ];\r\n\r\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\r\n\r\n\t\t#ifdef USE_SHADOWMAP\r\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\r\n\t\t#endif\r\n\r\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\r\n\r\n\tRectAreaLight rectAreaLight;\r\n\r\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\r\n\r\n\t\trectAreaLight = rectAreaLights[ i ];\r\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if defined( RE_IndirectDiffuse )\r\n\r\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\r\n\r\n\t#ifdef USE_LIGHTMAP\r\n\r\n\t\tvec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\r\n\r\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\t\tlightMapIrradiance *= PI; // factor of PI should not be present; included here to prevent breakage\r\n\r\n\t\t#endif\r\n\r\n\t\tirradiance += lightMapIrradiance;\r\n\r\n\t#endif\r\n\r\n\t#if ( NUM_HEMI_LIGHTS > 0 )\r\n\r\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\r\n\r\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\r\n\r\n\t\t}\r\n\r\n\t#endif\r\n\r\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\r\n\r\n\t\t// TODO, replace 8 with the real maxMIPLevel\r\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, 8 );\r\n\r\n\t#endif\r\n\r\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\r\n\r\n#endif\r\n\r\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\r\n\r\n\t// TODO, replace 8 with the real maxMIPLevel\r\n\tvec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\r\n\r\n\t#ifndef STANDARD\r\n\t\tvec3 clearCoatRadiance = getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), 8 );\r\n\t#else\r\n\t\tvec3 clearCoatRadiance = vec3( 0.0 );\r\n\t#endif\r\n\r\n\tRE_IndirectSpecular( radiance, clearCoatRadiance, geometry, material, reflectedLight );\r\n\r\n#endif\r\n",logdepthbuf_fragment:"#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\r\n\r\n\tgl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\r\n\r\n#endif",logdepthbuf_pars_fragment:"#ifdef USE_LOGDEPTHBUF\r\n\r\n\tuniform float logDepthBufFC;\r\n\r\n\t#ifdef USE_LOGDEPTHBUF_EXT\r\n\r\n\t\tvarying float vFragDepth;\r\n\r\n\t#endif\r\n\r\n#endif\r\n",logdepthbuf_pars_vertex:"#ifdef USE_LOGDEPTHBUF\r\n\r\n\t#ifdef USE_LOGDEPTHBUF_EXT\r\n\r\n\t\tvarying float vFragDepth;\r\n\r\n\t#endif\r\n\r\n\tuniform float logDepthBufFC;\r\n\r\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGDEPTHBUF\r\n\r\n\tgl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;\r\n\r\n\t#ifdef USE_LOGDEPTHBUF_EXT\r\n\r\n\t\tvFragDepth = 1.0 + gl_Position.w;\r\n\r\n\t#else\r\n\r\n\t\tgl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\r\n\r\n\t#endif\r\n\r\n#endif\r\n",map_fragment:"#ifdef USE_MAP\r\n\r\n\tvec4 texelColor = texture2D( map, vUv );\r\n\r\n\ttexelColor = mapTexelToLinear( texelColor );\r\n\tdiffuseColor *= texelColor;\r\n\r\n#endif\r\n",map_pars_fragment:"#ifdef USE_MAP\r\n\r\n\tuniform sampler2D map;\r\n\r\n#endif\r\n",map_particle_fragment:"#ifdef USE_MAP\r\n\r\n\tvec4 mapTexel = texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\r\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\r\n\r\n#endif\r\n",map_particle_pars_fragment:"#ifdef USE_MAP\r\n\r\n\tuniform vec4 offsetRepeat;\r\n\tuniform sampler2D map;\r\n\r\n#endif\r\n",metalnessmap_fragment:"float metalnessFactor = metalness;\r\n\r\n#ifdef USE_METALNESSMAP\r\n\r\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\r\n\r\n\t// reads channel B, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\r\n\tmetalnessFactor *= texelMetalness.b;\r\n\r\n#endif\r\n",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\r\n\r\n\tuniform sampler2D metalnessMap;\r\n\r\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\r\n\r\n\tobjectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\r\n\tobjectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\r\n\tobjectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\r\n\tobjectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\r\n\r\n#endif\r\n",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\r\n\r\n\t#ifndef USE_MORPHNORMALS\r\n\r\n\tuniform float morphTargetInfluences[ 8 ];\r\n\r\n\t#else\r\n\r\n\tuniform float morphTargetInfluences[ 4 ];\r\n\r\n\t#endif\r\n\r\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\r\n\r\n\ttransformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\r\n\ttransformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\r\n\ttransformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\r\n\ttransformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\r\n\r\n\t#ifndef USE_MORPHNORMALS\r\n\r\n\ttransformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\r\n\ttransformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\r\n\ttransformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\r\n\ttransformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\r\n\r\n\t#endif\r\n\r\n#endif\r\n",normal_flip:"#ifdef DOUBLE_SIDED\r\n\tfloat flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\r\n#else\r\n\tfloat flipNormal = 1.0;\r\n#endif\r\n",normal_fragment:"#ifdef FLAT_SHADED\r\n\r\n\t// Workaround for Adreno/Nexus5 not able able to do dFdx( vViewPosition ) ...\r\n\r\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\r\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\r\n\tvec3 normal = normalize( cross( fdx, fdy ) );\r\n\r\n#else\r\n\r\n\tvec3 normal = normalize( vNormal ) * flipNormal;\r\n\r\n#endif\r\n\r\n#ifdef USE_NORMALMAP\r\n\r\n\tnormal = perturbNormal2Arb( -vViewPosition, normal );\r\n\r\n#elif defined( USE_BUMPMAP )\r\n\r\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\r\n\r\n#endif\r\n",normalmap_pars_fragment:"#ifdef USE_NORMALMAP\r\n\r\n\tuniform sampler2D normalMap;\r\n\tuniform vec2 normalScale;\r\n\r\n\t// Per-Pixel Tangent Space Normal Mapping\r\n\t// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html\r\n\r\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\r\n\r\n\t\t// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988\r\n\r\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\r\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\r\n\t\tvec2 st0 = dFdx( vUv.st );\r\n\t\tvec2 st1 = dFdy( vUv.st );\r\n\r\n\t\tvec3 S = normalize( q0 * st1.t - q1 * st0.t );\r\n\t\tvec3 T = normalize( -q0 * st1.s + q1 * st0.s );\r\n\t\tvec3 N = normalize( surf_norm );\r\n\r\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\r\n\t\tmapN.xy = normalScale * mapN.xy;\r\n\t\tmat3 tsn = mat3( S, T, N );\r\n\t\treturn normalize( tsn * mapN );\r\n\r\n\t}\r\n\r\n#endif\r\n",packing:"vec3 packNormalToRGB( const in vec3 normal ) {\r\n\treturn normalize( normal ) * 0.5 + 0.5;\r\n}\r\n\r\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\r\n\treturn 1.0 - 2.0 * rgb.xyz;\r\n}\r\n\r\nconst float PackUpscale = 256. / 255.; // fraction -> 0..1 (including 1)\r\nconst float UnpackDownscale = 255. / 256.; // 0..1 -> fraction (excluding 1)\r\n\r\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\r\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\r\n\r\nconst float ShiftRight8 = 1. / 256.;\r\n\r\nvec4 packDepthToRGBA( const in float v ) {\r\n\tvec4 r = vec4( fract( v * PackFactors ), v );\r\n\tr.yzw -= r.xyz * ShiftRight8; // tidy overflow\r\n\treturn r * PackUpscale;\r\n}\r\n\r\nfloat unpackRGBAToDepth( const in vec4 v ) {\r\n\treturn dot( v, UnpackFactors );\r\n}\r\n\r\n// NOTE: viewZ/eyeZ is < 0 when in front of the camera per OpenGL conventions\r\n\r\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\r\n\treturn ( viewZ + near ) / ( near - far );\r\n}\r\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\r\n\treturn linearClipZ * ( near - far ) - near;\r\n}\r\n\r\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\r\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\r\n}\r\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\r\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\r\n}\r\n",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\r\n\r\n\t// Get get normal blending with premultipled, use with CustomBlending, OneFactor, OneMinusSrcAlphaFactor, AddEquation.\r\n\tgl_FragColor.rgb *= gl_FragColor.a;\r\n\r\n#endif\r\n",project_vertex:"vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\r\n\r\ngl_Position = projectionMatrix * mvPosition;\r\n",dithering_fragment:"#if defined( DITHERING )\r\n\r\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\r\n\r\n#endif\r\n",dithering_pars_fragment:"#if defined( DITHERING )\r\n\r\n\t// based on https://www.shadertoy.com/view/MslGR8\r\n\tvec3 dithering( vec3 color ) {\r\n\t\t//Calculate grid position\r\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\r\n\r\n\t\t//Shift the individual colors differently, thus making it even harder to see the dithering pattern\r\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\r\n\r\n\t\t//modify shift acording to grid position.\r\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\r\n\r\n\t\t//shift the color by dither_shift\r\n\t\treturn color + dither_shift_RGB;\r\n\t}\r\n\r\n#endif\r\n",roughnessmap_fragment:"float roughnessFactor = roughness;\r\n\r\n#ifdef USE_ROUGHNESSMAP\r\n\r\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\r\n\r\n\t// reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\r\n\troughnessFactor *= texelRoughness.g;\r\n\r\n#endif\r\n",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\r\n\r\n\tuniform sampler2D roughnessMap;\r\n\r\n#endif",shadowmap_pars_fragment:"#ifdef USE_SHADOWMAP\r\n\r\n\t#if NUM_DIR_LIGHTS > 0\r\n\r\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\r\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\t#if NUM_SPOT_LIGHTS > 0\r\n\r\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\r\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\t#if NUM_POINT_LIGHTS > 0\r\n\r\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\r\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\r\n\r\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\r\n\r\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\r\n\r\n\t}\r\n\r\n\tfloat texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\r\n\r\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\r\n\r\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\r\n\t\tvec2 centroidUV = floor( uv * size + 0.5 ) / size;\r\n\r\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\r\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\r\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\r\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\r\n\r\n\t\tvec2 f = fract( uv * size + 0.5 );\r\n\r\n\t\tfloat a = mix( lb, lt, f.y );\r\n\t\tfloat b = mix( rb, rt, f.y );\r\n\t\tfloat c = mix( a, b, f.x );\r\n\r\n\t\treturn c;\r\n\r\n\t}\r\n\r\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\r\n\r\n\t\tfloat shadow = 1.0;\r\n\r\n\t\tshadowCoord.xyz /= shadowCoord.w;\r\n\t\tshadowCoord.z += shadowBias;\r\n\r\n\t\t// if ( something && something ) breaks ATI OpenGL shader compiler\r\n\t\t// if ( all( something, something ) ) using this instead\r\n\r\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\r\n\t\tbool inFrustum = all( inFrustumVec );\r\n\r\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\r\n\r\n\t\tbool frustumTest = all( frustumTestVec );\r\n\r\n\t\tif ( frustumTest ) {\r\n\r\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\r\n\r\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\r\n\r\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\r\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\r\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\r\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\r\n\r\n\t\t\tshadow = (\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\r\n\t\t\t) * ( 1.0 / 9.0 );\r\n\r\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\r\n\r\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\r\n\r\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\r\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\r\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\r\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\r\n\r\n\t\t\tshadow = (\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\r\n\t\t\t) * ( 1.0 / 9.0 );\r\n\r\n\t\t#else // no percentage-closer filtering:\r\n\r\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\r\n\r\n\t\t#endif\r\n\r\n\t\t}\r\n\r\n\t\treturn shadow;\r\n\r\n\t}\r\n\r\n\t// cubeToUV() maps a 3D direction vector suitable for cube texture mapping to a 2D\r\n\t// vector suitable for 2D texture mapping. This code uses the following layout for the\r\n\t// 2D texture:\r\n\t//\r\n\t// xzXZ\r\n\t// y Y\r\n\t//\r\n\t// Y - Positive y direction\r\n\t// y - Negative y direction\r\n\t// X - Positive x direction\r\n\t// x - Negative x direction\r\n\t// Z - Positive z direction\r\n\t// z - Negative z direction\r\n\t//\r\n\t// Source and test bed:\r\n\t// https://gist.github.com/tschw/da10c43c467ce8afd0c4\r\n\r\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\r\n\r\n\t\t// Number of texels to avoid at the edge of each square\r\n\r\n\t\tvec3 absV = abs( v );\r\n\r\n\t\t// Intersect unit cube\r\n\r\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\r\n\t\tabsV *= scaleToCube;\r\n\r\n\t\t// Apply scale to avoid seams\r\n\r\n\t\t// two texels less per square (one texel will do for NEAREST)\r\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\r\n\r\n\t\t// Unwrap\r\n\r\n\t\t// space: -1 ... 1 range for each square\r\n\t\t//\r\n\t\t// #X##\t\tdim := ( 4 , 2 )\r\n\t\t// # #\t\tcenter := ( 1 , 1 )\r\n\r\n\t\tvec2 planar = v.xy;\r\n\r\n\t\tfloat almostATexel = 1.5 * texelSizeY;\r\n\t\tfloat almostOne = 1.0 - almostATexel;\r\n\r\n\t\tif ( absV.z >= almostOne ) {\r\n\r\n\t\t\tif ( v.z > 0.0 )\r\n\t\t\t\tplanar.x = 4.0 - v.x;\r\n\r\n\t\t} else if ( absV.x >= almostOne ) {\r\n\r\n\t\t\tfloat signX = sign( v.x );\r\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\r\n\r\n\t\t} else if ( absV.y >= almostOne ) {\r\n\r\n\t\t\tfloat signY = sign( v.y );\r\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\r\n\t\t\tplanar.y = v.z * signY - 2.0;\r\n\r\n\t\t}\r\n\r\n\t\t// Transform to UV space\r\n\r\n\t\t// scale := 0.5 / dim\r\n\t\t// translate := ( center + 0.5 ) / dim\r\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\r\n\r\n\t}\r\n\r\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\r\n\r\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\r\n\r\n\t\t// for point lights, the uniform @vShadowCoord is re-purposed to hold\r\n\t\t// the distance from the light to the world-space position of the fragment.\r\n\t\tvec3 lightToPosition = shadowCoord.xyz;\r\n\r\n\t\t// bd3D = base direction 3D\r\n\t\tvec3 bd3D = normalize( lightToPosition );\r\n\t\t// dp = distance from light to fragment position\r\n\t\tfloat dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;\r\n\r\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\r\n\r\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\r\n\r\n\t\t\treturn (\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\r\n\t\t\t) * ( 1.0 / 9.0 );\r\n\r\n\t\t#else // no percentage-closer filtering\r\n\r\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\r\n\r\n\t\t#endif\r\n\r\n\t}\r\n\r\n#endif\r\n",shadowmap_pars_vertex:"#ifdef USE_SHADOWMAP\r\n\r\n\t#if NUM_DIR_LIGHTS > 0\r\n\r\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\r\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\t#if NUM_SPOT_LIGHTS > 0\r\n\r\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\r\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\t#if NUM_POINT_LIGHTS > 0\r\n\r\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\r\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\r\n\r\n#endif\r\n",shadowmap_vertex:"#ifdef USE_SHADOWMAP\r\n\r\n\t#if NUM_DIR_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\r\n\r\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\t#if NUM_SPOT_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\r\n\r\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\t#if NUM_POINT_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\r\n\r\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\r\n\r\n#endif\r\n",shadowmask_pars_fragment:"float getShadowMask() {\r\n\r\n\tfloat shadow = 1.0;\r\n\r\n\t#ifdef USE_SHADOWMAP\r\n\r\n\t#if NUM_DIR_LIGHTS > 0\r\n\r\n\tDirectionalLight directionalLight;\r\n\r\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\r\n\r\n\t\tdirectionalLight = directionalLights[ i ];\r\n\t\tshadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\t#if NUM_SPOT_LIGHTS > 0\r\n\r\n\tSpotLight spotLight;\r\n\r\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\r\n\r\n\t\tspotLight = spotLights[ i ];\r\n\t\tshadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\t#if NUM_POINT_LIGHTS > 0\r\n\r\n\tPointLight pointLight;\r\n\r\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\r\n\r\n\t\tpointLight = pointLights[ i ];\r\n\t\tshadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\r\n\r\n\t#endif\r\n\r\n\treturn shadow;\r\n\r\n}\r\n",skinbase_vertex:"#ifdef USE_SKINNING\r\n\r\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\r\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\r\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\r\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\r\n\r\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\r\n\r\n\tuniform mat4 bindMatrix;\r\n\tuniform mat4 bindMatrixInverse;\r\n\r\n\t#ifdef BONE_TEXTURE\r\n\r\n\t\tuniform sampler2D boneTexture;\r\n\t\tuniform int boneTextureSize;\r\n\r\n\t\tmat4 getBoneMatrix( const in float i ) {\r\n\r\n\t\t\tfloat j = i * 4.0;\r\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\r\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\r\n\r\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\r\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\r\n\r\n\t\t\ty = dy * ( y + 0.5 );\r\n\r\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\r\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\r\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\r\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\r\n\r\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\r\n\r\n\t\t\treturn bone;\r\n\r\n\t\t}\r\n\r\n\t#else\r\n\r\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\r\n\r\n\t\tmat4 getBoneMatrix( const in float i ) {\r\n\r\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\r\n\t\t\treturn bone;\r\n\r\n\t\t}\r\n\r\n\t#endif\r\n\r\n#endif\r\n",skinning_vertex:"#ifdef USE_SKINNING\r\n\r\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\r\n\r\n\tvec4 skinned = vec4( 0.0 );\r\n\tskinned += boneMatX * skinVertex * skinWeight.x;\r\n\tskinned += boneMatY * skinVertex * skinWeight.y;\r\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\r\n\tskinned += boneMatW * skinVertex * skinWeight.w;\r\n\r\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\r\n\r\n#endif\r\n",skinnormal_vertex:"#ifdef USE_SKINNING\r\n\r\n\tmat4 skinMatrix = mat4( 0.0 );\r\n\tskinMatrix += skinWeight.x * boneMatX;\r\n\tskinMatrix += skinWeight.y * boneMatY;\r\n\tskinMatrix += skinWeight.z * boneMatZ;\r\n\tskinMatrix += skinWeight.w * boneMatW;\r\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\r\n\r\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\r\n\r\n#endif\r\n",specularmap_fragment:"float specularStrength;\r\n\r\n#ifdef USE_SPECULARMAP\r\n\r\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\r\n\tspecularStrength = texelSpecular.r;\r\n\r\n#else\r\n\r\n\tspecularStrength = 1.0;\r\n\r\n#endif",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\r\n\r\n\tuniform sampler2D specularMap;\r\n\r\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\r\n\r\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\r\n\r\n#endif\r\n",tonemapping_pars_fragment:"#define saturate(a) clamp( a, 0.0, 1.0 )\r\n\r\nuniform float toneMappingExposure;\r\nuniform float toneMappingWhitePoint;\r\n\r\n// exposure only\r\nvec3 LinearToneMapping( vec3 color ) {\r\n\r\n\treturn toneMappingExposure * color;\r\n\r\n}\r\n\r\n// source: https://www.cs.utah.edu/~reinhard/cdrom/\r\nvec3 ReinhardToneMapping( vec3 color ) {\r\n\r\n\tcolor *= toneMappingExposure;\r\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\r\n\r\n}\r\n\r\n// source: http://filmicgames.com/archives/75\r\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\r\nvec3 Uncharted2ToneMapping( vec3 color ) {\r\n\r\n\t// John Hable's filmic operator from Uncharted 2 video game\r\n\tcolor *= toneMappingExposure;\r\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\r\n\r\n}\r\n\r\n// source: http://filmicgames.com/archives/75\r\nvec3 OptimizedCineonToneMapping( vec3 color ) {\r\n\r\n\t// optimized filmic operator by Jim Hejl and Richard Burgess-Dawson\r\n\tcolor *= toneMappingExposure;\r\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\r\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\r\n\r\n}\r\n",uv_pars_fragment:"#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\r\n\r\n\tvarying vec2 vUv;\r\n\r\n#endif",uv_pars_vertex:"#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\r\n\r\n\tvarying vec2 vUv;\r\n\tuniform vec4 offsetRepeat;\r\n\r\n#endif\r\n",uv_vertex:"#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\r\n\r\n\tvUv = uv * offsetRepeat.zw + offsetRepeat.xy;\r\n\r\n#endif",uv2_pars_fragment:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tvarying vec2 vUv2;\r\n\r\n#endif",uv2_pars_vertex:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tattribute vec2 uv2;\r\n\tvarying vec2 vUv2;\r\n\r\n#endif",uv2_vertex:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tvUv2 = uv2;\r\n\r\n#endif",worldpos_vertex:"#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\r\n\r\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\r\n\r\n#endif\r\n",cube_frag:"uniform samplerCube tCube;\r\nuniform float tFlip;\r\nuniform float opacity;\r\n\r\nvarying vec3 vWorldPosition;\r\n\r\n#include \r\n\r\nvoid main() {\r\n\r\n\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\r\n\tgl_FragColor.a *= opacity;\r\n\r\n}\r\n",cube_vert:"varying vec3 vWorldPosition;\r\n\r\n#include \r\n\r\nvoid main() {\r\n\r\n\tvWorldPosition = transformDirection( position, modelMatrix );\r\n\r\n\t#include \r\n\t#include \r\n\r\n}\r\n",depth_frag:"#if DEPTH_PACKING == 3200\r\n\r\n\tuniform float opacity;\r\n\r\n#endif\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\tvec4 diffuseColor = vec4( 1.0 );\r\n\r\n\t#if DEPTH_PACKING == 3200\r\n\r\n\t\tdiffuseColor.a = opacity;\r\n\r\n\t#endif\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#include \r\n\r\n\t#if DEPTH_PACKING == 3200\r\n\r\n\t\tgl_FragColor = vec4( vec3( gl_FragCoord.z ), opacity );\r\n\r\n\t#elif DEPTH_PACKING == 3201\r\n\r\n\t\tgl_FragColor = packDepthToRGBA( gl_FragCoord.z );\r\n\r\n\t#endif\r\n\r\n}\r\n",depth_vert:"#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\t#include \r\n\r\n\t#ifdef USE_DISPLACEMENTMAP\r\n\r\n\t\t#include \r\n\t\t#include \r\n\t\t#include \r\n\r\n\t#endif\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",distanceRGBA_frag:"uniform vec3 lightPos;\r\nvarying vec4 vWorldPosition;\r\n\r\n#include \r\n#include \r\n#include \r\n\r\nvoid main () {\r\n\r\n\t#include \r\n\r\n\tgl_FragColor = packDepthToRGBA( length( vWorldPosition.xyz - lightPos.xyz ) / 1000.0 );\r\n\r\n}\r\n",distanceRGBA_vert:"varying vec4 vWorldPosition;\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\tvWorldPosition = worldPosition;\r\n\r\n}\r\n",equirect_frag:"uniform sampler2D tEquirect;\r\nuniform float tFlip;\r\n\r\nvarying vec3 vWorldPosition;\r\n\r\n#include \r\n\r\nvoid main() {\r\n\r\n\t// \tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\r\n\tvec3 direction = normalize( vWorldPosition );\r\n\tvec2 sampleUV;\r\n\tsampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\r\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\r\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\r\n\r\n}\r\n",equirect_vert:"varying vec3 vWorldPosition;\r\n\r\n#include \r\n\r\nvoid main() {\r\n\r\n\tvWorldPosition = transformDirection( position, modelMatrix );\r\n\r\n\t#include \r\n\t#include \r\n\r\n}\r\n",linedashed_frag:"uniform vec3 diffuse;\r\nuniform float opacity;\r\n\r\nuniform float dashSize;\r\nuniform float totalSize;\r\n\r\nvarying float vLineDistance;\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\r\n\r\n\t\tdiscard;\r\n\r\n\t}\r\n\r\n\tvec3 outgoingLight = vec3( 0.0 );\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\r\n\t#include \r\n\t#include \r\n\r\n\toutgoingLight = diffuseColor.rgb; // simple shader\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",linedashed_vert:"uniform float scale;\r\nattribute float lineDistance;\r\n\r\nvarying float vLineDistance;\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\tvLineDistance = scale * lineDistance;\r\n\r\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\r\n\tgl_Position = projectionMatrix * mvPosition;\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",meshbasic_frag:"uniform vec3 diffuse;\r\nuniform float opacity;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\r\n\r\n\t// accumulation (baked indirect lighting only)\r\n\t#ifdef USE_LIGHTMAP\r\n\r\n\t\treflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\r\n\r\n\t#else\r\n\r\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\r\n\r\n\t#endif\r\n\r\n\t// modulation\r\n\t#include \r\n\r\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\r\n\r\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\r\n\r\n\t#include \r\n\t#include \r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",meshbasic_vert:"#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#ifdef USE_ENVMAP\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#endif\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",meshlambert_frag:"uniform vec3 diffuse;\r\nuniform vec3 emissive;\r\nuniform float opacity;\r\n\r\nvarying vec3 vLightFront;\r\n\r\n#ifdef DOUBLE_SIDED\r\n\r\n\tvarying vec3 vLightBack;\r\n\r\n#endif\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\r\n\tvec3 totalEmissiveRadiance = emissive;\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t// accumulation\r\n\treflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\r\n\r\n\t#include \r\n\r\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\r\n\r\n\t#ifdef DOUBLE_SIDED\r\n\r\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\r\n\r\n\t#else\r\n\r\n\t\treflectedLight.directDiffuse = vLightFront;\r\n\r\n\t#endif\r\n\r\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\r\n\r\n\t// modulation\r\n\t#include \r\n\r\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\r\n\r\n\t#include \r\n\t#include \r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",meshlambert_vert:"#define LAMBERT\r\n\r\nvarying vec3 vLightFront;\r\n\r\n#ifdef DOUBLE_SIDED\r\n\r\n\tvarying vec3 vLightBack;\r\n\r\n#endif\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",meshphong_frag:"#define PHONG\r\n\r\nuniform vec3 diffuse;\r\nuniform vec3 emissive;\r\nuniform vec3 specular;\r\nuniform float shininess;\r\nuniform float opacity;\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\r\n\tvec3 totalEmissiveRadiance = emissive;\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t// accumulation\r\n\t#include \r\n\t#include \r\n\r\n\t// modulation\r\n\t#include \r\n\r\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\r\n\r\n\t#include \r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",meshphong_vert:"#define PHONG\r\n\r\nvarying vec3 vViewPosition;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n#ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED\r\n\r\n\tvNormal = normalize( transformedNormal );\r\n\r\n#endif\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\tvViewPosition = - mvPosition.xyz;\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",meshphysical_frag:"#define PHYSICAL\r\n\r\nuniform vec3 diffuse;\r\nuniform vec3 emissive;\r\nuniform float roughness;\r\nuniform float metalness;\r\nuniform float opacity;\r\n\r\n#ifndef STANDARD\r\n\tuniform float clearCoat;\r\n\tuniform float clearCoatRoughness;\r\n#endif\r\n\r\nvarying vec3 vViewPosition;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\r\n\tvec3 totalEmissiveRadiance = emissive;\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t// accumulation\r\n\t#include \r\n\t#include \r\n\r\n\t// modulation\r\n\t#include \r\n\r\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",meshphysical_vert:"#define PHYSICAL\r\n\r\nvarying vec3 vViewPosition;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n#ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED\r\n\r\n\tvNormal = normalize( transformedNormal );\r\n\r\n#endif\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\tvViewPosition = - mvPosition.xyz;\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",normal_frag:"#define NORMAL\r\n\r\nuniform float opacity;\r\n\r\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\r\n\r\n\tvarying vec3 vViewPosition;\r\n\r\n#endif\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\r\n\r\n}\r\n",normal_vert:"#define NORMAL\r\n\r\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\r\n\r\n\tvarying vec3 vViewPosition;\r\n\r\n#endif\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n#ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED\r\n\r\n\tvNormal = normalize( transformedNormal );\r\n\r\n#endif\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\r\n\r\n\tvViewPosition = - mvPosition.xyz;\r\n\r\n#endif\r\n\r\n}\r\n",points_frag:"uniform vec3 diffuse;\r\nuniform float opacity;\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\tvec3 outgoingLight = vec3( 0.0 );\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\toutgoingLight = diffuseColor.rgb;\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",points_vert:"uniform float size;\r\nuniform float scale;\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#ifdef USE_SIZEATTENUATION\r\n\t\tgl_PointSize = size * ( scale / - mvPosition.z );\r\n\t#else\r\n\t\tgl_PointSize = size;\r\n\t#endif\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",shadow_frag:"uniform float opacity;\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\tgl_FragColor = vec4( 0.0, 0.0, 0.0, opacity * ( 1.0 - getShadowMask() ) );\r\n\r\n}\r\n",shadow_vert:"#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n"},ih={basic:{uniforms:rh.merge([eh.common,eh.aomap,eh.lightmap,eh.fog]),vertexShader:nh.meshbasic_vert,fragmentShader:nh.meshbasic_frag},lambert:{uniforms:rh.merge([eh.common,eh.aomap,eh.lightmap,eh.emissivemap,eh.fog,eh.lights,{emissive:{value:new c(0)}}]),vertexShader:nh.meshlambert_vert,fragmentShader:nh.meshlambert_frag},phong:{uniforms:rh.merge([eh.common,eh.aomap,eh.lightmap,eh.emissivemap,eh.bumpmap,eh.normalmap,eh.displacementmap,eh.gradientmap,eh.fog,eh.lights,{emissive:{value:new c(0)},specular:{value:new c(1118481)},shininess:{value:30}}]),vertexShader:nh.meshphong_vert,fragmentShader:nh.meshphong_frag},standard:{uniforms:rh.merge([eh.common,eh.aomap,eh.lightmap,eh.emissivemap,eh.bumpmap,eh.normalmap,eh.displacementmap,eh.roughnessmap,eh.metalnessmap,eh.fog,eh.lights,{emissive:{value:new c(0)},roughness:{value:.5},metalness:{value:.5},envMapIntensity:{value:1}}]),vertexShader:nh.meshphysical_vert,fragmentShader:nh.meshphysical_frag},points:{uniforms:rh.merge([eh.points,eh.fog]),vertexShader:nh.points_vert,fragmentShader:nh.points_frag},dashed:{uniforms:rh.merge([eh.common,eh.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:nh.linedashed_vert,fragmentShader:nh.linedashed_frag},depth:{uniforms:rh.merge([eh.common,eh.displacementmap]),vertexShader:nh.depth_vert,fragmentShader:nh.depth_frag},normal:{uniforms:rh.merge([eh.common,eh.bumpmap,eh.normalmap,eh.displacementmap,{opacity:{value:1}}]),vertexShader:nh.normal_vert,fragmentShader:nh.normal_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:nh.cube_vert,fragmentShader:nh.cube_frag},equirect:{uniforms:{tEquirect:{value:null},tFlip:{value:-1}},vertexShader:nh.equirect_vert,fragmentShader:nh.equirect_frag},distanceRGBA:{uniforms:{lightPos:{value:new n}},vertexShader:nh.distanceRGBA_vert,fragmentShader:nh.distanceRGBA_frag}};ih.physical={uniforms:rh.merge([ih.standard.uniforms,{clearCoat:{value:0},clearCoatRoughness:{value:0}}]),vertexShader:nh.meshphysical_vert,fragmentShader:nh.meshphysical_frag},Object.assign(et.prototype,{set:function(t,e){return this.min.copy(t),this.max.copy(e),this},setFromPoints:function(t){this.makeEmpty();for(var e=0,r=t.length;ethis.max.x||t.ythis.max.y)},containsBox:function(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y},getParameter:function(t,e){return(e||new h).set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))},intersectsBox:function(t){return!(t.max.xthis.max.x||t.max.ythis.max.y)},clampPoint:function(t,e){return(e||new h).copy(t).clamp(this.min,this.max)},distanceToPoint:function(){var t=new h;return function(e){return t.copy(e).clamp(this.min,this.max).sub(e).length()}}(),intersect:function(t){return this.min.max(t.min),this.max.min(t.max),this},union:function(t){return this.min.min(t.min),this.max.max(t.max),this},translate:function(t){return this.min.add(t),this.max.add(t),this},equals:function(t){return t.min.equals(this.min)&&t.max.equals(this.max)}});var ah=0;Object.assign(it.prototype,l.prototype,{isMaterial:!0,onBeforeCompile:function(){},setValues:function(t){if(void 0!==t)for(var e in t){var r=t[e];if(void 0!==r){var n=this[e];void 0!==n?n&&n.isColor?n.set(r):n&&n.isVector3&&r&&r.isVector3?n.copy(r):this[e]="overdraw"===e?Number(r):r:console.warn("THREE."+this.type+": '"+e+"' is not a property of this material.")}else console.warn("THREE.Material: '"+e+"' parameter is undefined.")}},toJSON:function(t){function e(t){var e=[];for(var r in t){var n=t[r];delete n.metadata,e.push(n)}return e}var r=void 0===t;r&&(t={textures:{},images:{}});var n={metadata:{version:4.5,type:"Material",generator:"Material.toJSON"}};if(n.uuid=this.uuid,n.type=this.type,""!==this.name&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),void 0!==this.roughness&&(n.roughness=this.roughness),void 0!==this.metalness&&(n.metalness=this.metalness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),void 0!==this.shininess&&(n.shininess=this.shininess),void 0!==this.clearCoat&&(n.clearCoat=this.clearCoat),void 0!==this.clearCoatRoughness&&(n.clearCoatRoughness=this.clearCoatRoughness),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,n.reflectivity=this.reflectivity),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.size&&(n.size=this.size),void 0!==this.sizeAttenuation&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==ic&&(n.blending=this.blending),this.shading!==$s&&(n.shading=this.shading),this.side!==Zs&&(n.side=this.side),this.vertexColors!==tc&&(n.vertexColors=this.vertexColors),this.opacity<1&&(n.opacity=this.opacity),!0===this.transparent&&(n.transparent=this.transparent),n.depthFunc=this.depthFunc,n.depthTest=this.depthTest,n.depthWrite=this.depthWrite,this.alphaTest>0&&(n.alphaTest=this.alphaTest),!0===this.premultipliedAlpha&&(n.premultipliedAlpha=this.premultipliedAlpha),!0===this.wireframe&&(n.wireframe=this.wireframe),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(n.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(n.wireframeLinejoin=this.wireframeLinejoin),n.skinning=this.skinning,n.morphTargets=this.morphTargets,n.dithering=this.dithering,r){var i=e(t.textures),a=e(t.images);i.length>0&&(n.textures=i),a.length>0&&(n.images=a)}return n},clone:function(){return(new this.constructor).copy(this)},copy:function(t){this.name=t.name,this.fog=t.fog,this.lights=t.lights,this.blending=t.blending,this.side=t.side,this.shading=t.shading,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.premultipliedAlpha=t.premultipliedAlpha,this.overdraw=t.overdraw,this.visible=t.visible,this.clipShadows=t.clipShadows,this.clipIntersection=t.clipIntersection;var e=t.clippingPlanes,r=null;if(null!==e){var n=e.length;r=new Array(n);for(var i=0;i!==n;++i)r[i]=e[i].clone()}return this.clippingPlanes=r,this},dispose:function(){this.dispatchEvent({type:"dispose"})}}),at.prototype=Object.create(it.prototype),at.prototype.constructor=at,at.prototype.isShaderMaterial=!0,at.prototype.copy=function(t){return it.prototype.copy.call(this,t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=rh.clone(t.uniforms),this.defines=t.defines,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.lights=t.lights,this.clipping=t.clipping,this.skinning=t.skinning,this.morphTargets=t.morphTargets,this.morphNormals=t.morphNormals,this.extensions=t.extensions,this},at.prototype.toJSON=function(t){var e=it.prototype.toJSON.call(this,t);return e.uniforms=this.uniforms,e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e},ot.prototype=Object.create(it.prototype),ot.prototype.constructor=ot,ot.prototype.isMeshDepthMaterial=!0,ot.prototype.copy=function(t){return it.prototype.copy.call(this,t),this.depthPacking=t.depthPacking,this.skinning=t.skinning,this.morphTargets=t.morphTargets,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this},Object.assign(st.prototype,{isBox3:!0,set:function(t,e){return this.min.copy(t),this.max.copy(e),this},setFromArray:function(t){for(var e=1/0,r=1/0,n=1/0,i=-1/0,a=-1/0,o=-1/0,s=0,c=t.length;si&&(i=l),h>a&&(a=h),u>o&&(o=u)}return this.min.set(e,r,n),this.max.set(i,a,o),this},setFromBufferAttribute:function(t){for(var e=1/0,r=1/0,n=1/0,i=-1/0,a=-1/0,o=-1/0,s=0,c=t.count;si&&(i=l),h>a&&(a=h),u>o&&(o=u)}return this.min.set(e,r,n),this.max.set(i,a,o),this},setFromPoints:function(t){this.makeEmpty();for(var e=0,r=t.length;ethis.max.x||t.ythis.max.y||t.zthis.max.z)},containsBox:function(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z},getParameter:function(t,e){return(e||new n).set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))},intersectsBox:function(t){return!(t.max.xthis.max.x||t.max.ythis.max.y||t.max.zthis.max.z)},intersectsSphere:function(){var t=new n;return function(e){return this.clampPoint(e.center,t),t.distanceToSquared(e.center)<=e.radius*e.radius}}(),intersectsPlane:function(t){var e,r;return t.normal.x>0?(e=t.normal.x*this.min.x,r=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,r=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,r+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,r+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,r+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,r+=t.normal.z*this.min.z),e<=t.constant&&r>=t.constant},clampPoint:function(t,e){return(e||new n).copy(t).clamp(this.min,this.max)},distanceToPoint:function(){var t=new n;return function(e){return t.copy(e).clamp(this.min,this.max).sub(e).length()}}(),getBoundingSphere:function(){var t=new n;return function(e){var r=e||new ct;return this.getCenter(r.center),r.radius=.5*this.getSize(t).length(),r}}(),intersect:function(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this},union:function(t){return this.min.min(t.min),this.max.max(t.max),this},applyMatrix4:function(){var t=[new n,new n,new n,new n,new n,new n,new n,new n];return function(e){return this.isEmpty()?this:(t[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),t[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),t[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),t[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),t[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),t[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),t[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),t[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(t),this)}}(),translate:function(t){return this.min.add(t),this.max.add(t),this},equals:function(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}),Object.assign(ct.prototype,{set:function(t,e){return this.center.copy(t),this.radius=e,this},setFromPoints:function(){var t=new st;return function(e,r){var n=this.center;void 0!==r?n.copy(r):t.setFromPoints(e).getCenter(n);for(var i=0,a=0,o=e.length;athis.radius*this.radius&&(i.sub(this.center).normalize(),i.multiplyScalar(this.radius).add(this.center)),i},getBoundingBox:function(t){var e=t||new st;return e.set(this.center,this.center),e.expandByScalar(this.radius),e},applyMatrix4:function(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this},translate:function(t){return this.center.add(t),this},equals:function(t){return t.center.equals(this.center)&&t.radius===this.radius}}),Object.assign(lt.prototype,{isMatrix3:!0,set:function(t,e,r,n,i,a,o,s,c){var l=this.elements;return l[0]=t,l[1]=n,l[2]=o,l[3]=e,l[4]=i,l[5]=s,l[6]=r,l[7]=a,l[8]=c,this},identity:function(){return this.set(1,0,0,0,1,0,0,0,1),this},clone:function(){return(new this.constructor).fromArray(this.elements)},copy:function(t){var e=this.elements,r=t.elements;return e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],e[4]=r[4],e[5]=r[5],e[6]=r[6],e[7]=r[7],e[8]=r[8],this},setFromMatrix4:function(t){var e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this},applyToBufferAttribute:function(){var t=new n;return function(e){for(var r=0,n=e.count;r1))return i.copy(a).multiplyScalar(s).add(e.start)}else if(0===this.distanceToPoint(e.start))return i.copy(e.start)}}(),intersectsLine:function(t){var e=this.distanceToPoint(t.start),r=this.distanceToPoint(t.end);return e<0&&r>0||r<0&&e>0},intersectsBox:function(t){return t.intersectsPlane(this)},intersectsSphere:function(t){return t.intersectsPlane(this)},coplanarPoint:function(t){return(t||new n).copy(this.normal).multiplyScalar(-this.constant)},applyMatrix4:function(){var t=new n,e=new lt;return function(r,n){var i=this.coplanarPoint(t).applyMatrix4(r),a=n||e.getNormalMatrix(r),o=this.normal.applyMatrix3(a).normalize();return this.constant=-i.dot(o),this}}(),translate:function(t){return this.constant=this.constant-t.dot(this.normal),this},equals:function(t){return t.normal.equals(this.normal)&&t.constant===this.constant}}),Object.assign(ut.prototype,{set:function(t,e,r,n,i,a){var o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(r),o[3].copy(n),o[4].copy(i),o[5].copy(a),this},clone:function(){return(new this.constructor).copy(this)},copy:function(t){for(var e=this.planes,r=0;r<6;r++)e[r].copy(t.planes[r]);return this},setFromMatrix:function(t){var e=this.planes,r=t.elements,n=r[0],i=r[1],a=r[2],o=r[3],s=r[4],c=r[5],l=r[6],h=r[7],u=r[8],d=r[9],p=r[10],f=r[11],m=r[12],g=r[13],v=r[14],y=r[15];return e[0].setComponents(o-n,h-s,f-u,y-m).normalize(),e[1].setComponents(o+n,h+s,f+u,y+m).normalize(),e[2].setComponents(o+i,h+c,f+d,y+g).normalize(),e[3].setComponents(o-i,h-c,f-d,y-g).normalize(),e[4].setComponents(o-a,h-l,f-p,y-v).normalize(),e[5].setComponents(o+a,h+l,f+p,y+v).normalize(),this},intersectsObject:function(){var t=new ct;return function(e){var r=e.geometry;return null===r.boundingSphere&&r.computeBoundingSphere(),t.copy(r.boundingSphere).applyMatrix4(e.matrixWorld),this.intersectsSphere(t)}}(),intersectsSprite:function(){var t=new ct;return function(e){return t.center.set(0,0,0),t.radius=.7071067811865476,t.applyMatrix4(e.matrixWorld),this.intersectsSphere(t)}}(),intersectsSphere:function(t){for(var e=this.planes,r=t.center,n=-t.radius,i=0;i<6;i++)if(e[i].distanceToPoint(r)0?r.min.x:r.max.x,e.x=a.normal.x>0?r.max.x:r.min.x,t.y=a.normal.y>0?r.min.y:r.max.y,e.y=a.normal.y>0?r.max.y:r.min.y,t.z=a.normal.z>0?r.min.z:r.max.z,e.z=a.normal.z>0?r.max.z:r.min.z;var o=a.distanceToPoint(t),s=a.distanceToPoint(e);if(o<0&&s<0)return!1}return!0}}(),containsPoint:function(t){for(var e=this.planes,r=0;r<6;r++)if(e[r].distanceToPoint(t)<0)return!1;return!0}}),ft.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"],ft.DefaultOrder="XYZ",Object.defineProperties(ft.prototype,{x:{get:function(){return this._x},set:function(t){this._x=t,this.onChangeCallback()}},y:{get:function(){return this._y},set:function(t){this._y=t,this.onChangeCallback()}},z:{get:function(){return this._z},set:function(t){this._z=t,this.onChangeCallback()}},order:{get:function(){return this._order},set:function(t){this._order=t,this.onChangeCallback()}}}),Object.assign(ft.prototype,{isEuler:!0,set:function(t,e,r,n){return this._x=t,this._y=e,this._z=r,this._order=n||this._order,this.onChangeCallback(),this},clone:function(){return new this.constructor(this._x,this._y,this._z,this._order)},copy:function(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this.onChangeCallback(),this},setFromRotationMatrix:function(t,e,r){var n=Ko.clamp,i=t.elements,a=i[0],o=i[4],s=i[8],c=i[1],l=i[5],h=i[9],u=i[2],d=i[6],p=i[10];return e=e||this._order,"XYZ"===e?(this._y=Math.asin(n(s,-1,1)),Math.abs(s)<.99999?(this._x=Math.atan2(-h,p),this._z=Math.atan2(-o,a)):(this._x=Math.atan2(d,l),this._z=0)):"YXZ"===e?(this._x=Math.asin(-n(h,-1,1)),Math.abs(h)<.99999?(this._y=Math.atan2(s,p),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-u,a),this._z=0)):"ZXY"===e?(this._x=Math.asin(n(d,-1,1)),Math.abs(d)<.99999?(this._y=Math.atan2(-u,p),this._z=Math.atan2(-o,l)):(this._y=0,this._z=Math.atan2(c,a))):"ZYX"===e?(this._y=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(this._x=Math.atan2(d,p),this._z=Math.atan2(c,a)):(this._x=0,this._z=Math.atan2(-o,l))):"YZX"===e?(this._z=Math.asin(n(c,-1,1)),Math.abs(c)<.99999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,a)):(this._x=0,this._y=Math.atan2(s,p))):"XZY"===e?(this._z=Math.asin(-n(o,-1,1)),Math.abs(o)<.99999?(this._x=Math.atan2(d,l),this._y=Math.atan2(s,a)):(this._x=Math.atan2(-h,p),this._y=0)):console.warn("THREE.Euler: .setFromRotationMatrix() given unsupported order: "+e),this._order=e,!1!==r&&this.onChangeCallback(),this},setFromQuaternion:function(){var t=new e;return function(e,r,n){return t.makeRotationFromQuaternion(e),this.setFromRotationMatrix(t,r,n)}}(),setFromVector3:function(t,e){return this.set(t.x,t.y,t.z,e||this._order)},reorder:function(){var t=new r;return function(e){return t.setFromEuler(this),this.setFromQuaternion(t,e)}}(),equals:function(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order},fromArray:function(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this.onChangeCallback(),this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t},toVector3:function(t){return t?t.set(this._x,this._y,this._z):new n(this._x,this._y,this._z)},onChange:function(t){return this.onChangeCallback=t,this},onChangeCallback:function(){}}),Object.assign(mt.prototype,{set:function(t){this.mask=1<1){for(var e=0;e1){for(var e=0;e0){a.children=[];for(s=0;s0&&(i.geometries=l),h.length>0&&(i.materials=h),u.length>0&&(i.textures=u),d.length>0&&(i.images=d)}return i.object=a,i},clone:function(t){return(new this.constructor).copy(this,t)},copy:function(t,e){if(void 0===e&&(e=!0),this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(var r=0;r0)for(g=0;g0&&(this.normalsNeedUpdate=!0)},computeFlatVertexNormals:function(){var t,e,r;for(this.computeFaceNormals(),t=0,e=this.faces.length;t0&&(this.normalsNeedUpdate=!0)},computeMorphNormals:function(){var t,e,r,i,a;for(r=0,i=this.faces.length;r0&&(t+=e[r].distanceTo(e[r-1])),this.lineDistances[r]=t},computeBoundingBox:function(){null===this.boundingBox&&(this.boundingBox=new st),this.boundingBox.setFromPoints(this.vertices)},computeBoundingSphere:function(){null===this.boundingSphere&&(this.boundingSphere=new ct),this.boundingSphere.setFromPoints(this.vertices)},merge:function(t,e,r){if(!t||!t.isGeometry)return void console.error("THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.",t);var n,i=this.vertices.length,a=this.vertices,o=t.vertices,s=this.faces,c=t.faces,l=this.faceVertexUvs[0],h=t.faceVertexUvs[0],u=this.colors,d=t.colors;void 0===r&&(r=0),void 0!==e&&(n=(new lt).getNormalMatrix(e));for(var p=0,f=o.length;p=0;r--){var f=d[r];for(this.faces.splice(f,1),o=0,s=this.faceVertexUvs.length;o0,b=v.vertexNormals.length>0,w=1!==v.color.r||1!==v.color.g||1!==v.color.b,_=v.vertexColors.length>0,M=0;if(M=t(M,0,0),M=t(M,1,!0),M=t(M,2,!1),M=t(M,3,y),M=t(M,4,x),M=t(M,5,b),M=t(M,6,w),M=t(M,7,_),h.push(M),h.push(v.a,v.b,v.c),h.push(v.materialIndex),y){var E=this.faceVertexUvs[0][c];h.push(n(E[0]),n(E[1]),n(E[2]))}if(x&&h.push(e(v.normal)),b){var S=v.vertexNormals;h.push(e(S[0]),e(S[1]),e(S[2]))}if(w&&h.push(r(v.color)),_){var T=v.vertexColors;h.push(r(T[0]),r(T[1]),r(T[2]))}}return i.data={},i.data.vertices=s,i.data.normals=u,p.length>0&&(i.data.colors=p),m.length>0&&(i.data.uvs=[m]),i.data.faces=h,i},clone:function(){return(new _t).copy(this)},copy:function(t){var e,r,n,i,a,o;this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.name=t.name;var s=t.vertices;for(e=0,r=s.length;e0,o=i[1]&&i[1].length>0,s=t.morphTargets,c=s.length;if(c>0){e=[];for(v=0;v0){l=[];for(v=0;v65535?St:Et)(t,1):this.index=t},addAttribute:function(t,e){return e&&e.isBufferAttribute||e&&e.isInterleavedBufferAttribute?"index"===t?(console.warn("THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute."),void this.setIndex(e)):(this.attributes[t]=e,this):(console.warn("THREE.BufferGeometry: .addAttribute() now expects ( name, attribute )."),void this.addAttribute(t,new Mt(arguments[1],arguments[2])))},getAttribute:function(t){return this.attributes[t]},removeAttribute:function(t){return delete this.attributes[t],this},addGroup:function(t,e,r){this.groups.push({start:t,count:e,materialIndex:void 0!==r?r:0})},clearGroups:function(){this.groups=[]},setDrawRange:function(t,e){this.drawRange.start=t,this.drawRange.count=e},applyMatrix:function(t){var e=this.attributes.position;void 0!==e&&(t.applyToBufferAttribute(e),e.needsUpdate=!0);var r=this.attributes.normal;return void 0!==r&&((new lt).getNormalMatrix(t).applyToBufferAttribute(r),r.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this},rotateX:function(){var t=new e;return function(e){return t.makeRotationX(e),this.applyMatrix(t),this}}(),rotateY:function(){var t=new e;return function(e){return t.makeRotationY(e),this.applyMatrix(t),this}}(),rotateZ:function(){var t=new e;return function(e){return t.makeRotationZ(e),this.applyMatrix(t),this}}(),translate:function(){var t=new e;return function(e,r,n){return t.makeTranslation(e,r,n),this.applyMatrix(t),this}}(),scale:function(){var t=new e;return function(e,r,n){return t.makeScale(e,r,n),this.applyMatrix(t),this}}(),lookAt:function(){var t=new gt;return function(e){t.lookAt(e),t.updateMatrix(),this.applyMatrix(t.matrix)}}(),center:function(){this.computeBoundingBox();var t=this.boundingBox.getCenter().negate();return this.translate(t.x,t.y,t.z),t},setFromObject:function(t){var e=t.geometry;if(t.isPoints||t.isLine){var r=new Tt(3*e.vertices.length,3),n=new Tt(3*e.colors.length,3);if(this.addAttribute("position",r.copyVector3sArray(e.vertices)),this.addAttribute("color",n.copyColorsArray(e.colors)),e.lineDistances&&e.lineDistances.length===e.vertices.length){var i=new Tt(e.lineDistances.length,1);this.addAttribute("lineDistance",i.copyArray(e.lineDistances))}null!==e.boundingSphere&&(this.boundingSphere=e.boundingSphere.clone()),null!==e.boundingBox&&(this.boundingBox=e.boundingBox.clone())}else t.isMesh&&e&&e.isGeometry&&this.fromGeometry(e);return this},updateFromObject:function(t){var e=t.geometry;if(t.isMesh){var r=e.__directGeometry;if(!0===e.elementsNeedUpdate&&(r=void 0,e.elementsNeedUpdate=!1),void 0===r)return this.fromGeometry(e);r.verticesNeedUpdate=e.verticesNeedUpdate,r.normalsNeedUpdate=e.normalsNeedUpdate,r.colorsNeedUpdate=e.colorsNeedUpdate,r.uvsNeedUpdate=e.uvsNeedUpdate,r.groupsNeedUpdate=e.groupsNeedUpdate,e.verticesNeedUpdate=!1,e.normalsNeedUpdate=!1,e.colorsNeedUpdate=!1,e.uvsNeedUpdate=!1,e.groupsNeedUpdate=!1,e=r}var n;return!0===e.verticesNeedUpdate&&(void 0!==(n=this.attributes.position)&&(n.copyVector3sArray(e.vertices),n.needsUpdate=!0),e.verticesNeedUpdate=!1),!0===e.normalsNeedUpdate&&(void 0!==(n=this.attributes.normal)&&(n.copyVector3sArray(e.normals),n.needsUpdate=!0),e.normalsNeedUpdate=!1),!0===e.colorsNeedUpdate&&(void 0!==(n=this.attributes.color)&&(n.copyColorsArray(e.colors),n.needsUpdate=!0),e.colorsNeedUpdate=!1),e.uvsNeedUpdate&&(void 0!==(n=this.attributes.uv)&&(n.copyVector2sArray(e.uvs),n.needsUpdate=!0),e.uvsNeedUpdate=!1),e.lineDistancesNeedUpdate&&(void 0!==(n=this.attributes.lineDistance)&&(n.copyArray(e.lineDistances),n.needsUpdate=!0),e.lineDistancesNeedUpdate=!1),e.groupsNeedUpdate&&(e.computeGroups(t.geometry),this.groups=e.groups,e.groupsNeedUpdate=!1),this},fromGeometry:function(t){return t.__directGeometry=(new At).fromGeometry(t),this.fromDirectGeometry(t.__directGeometry)},fromDirectGeometry:function(t){var e=new Float32Array(3*t.vertices.length);if(this.addAttribute("position",new Mt(e,3).copyVector3sArray(t.vertices)),t.normals.length>0){var r=new Float32Array(3*t.normals.length);this.addAttribute("normal",new Mt(r,3).copyVector3sArray(t.normals))}if(t.colors.length>0){var n=new Float32Array(3*t.colors.length);this.addAttribute("color",new Mt(n,3).copyColorsArray(t.colors))}if(t.uvs.length>0){var i=new Float32Array(2*t.uvs.length);this.addAttribute("uv",new Mt(i,2).copyVector2sArray(t.uvs))}if(t.uvs2.length>0){var a=new Float32Array(2*t.uvs2.length);this.addAttribute("uv2",new Mt(a,2).copyVector2sArray(t.uvs2))}if(t.indices.length>0){var o=new(Lt(t.indices)>65535?Uint32Array:Uint16Array)(3*t.indices.length);this.setIndex(new Mt(o,1).copyIndicesArray(t.indices))}this.groups=t.groups;for(var s in t.morphTargets){for(var c=[],l=t.morphTargets[s],h=0,u=l.length;h0){var f=new Tt(4*t.skinIndices.length,4);this.addAttribute("skinIndex",f.copyVector4sArray(t.skinIndices))}if(t.skinWeights.length>0){var m=new Tt(4*t.skinWeights.length,4);this.addAttribute("skinWeight",m.copyVector4sArray(t.skinWeights))}return null!==t.boundingSphere&&(this.boundingSphere=t.boundingSphere.clone()),null!==t.boundingBox&&(this.boundingBox=t.boundingBox.clone()),this},computeBoundingBox:function(){null===this.boundingBox&&(this.boundingBox=new st);var t=this.attributes.position;void 0!==t?this.boundingBox.setFromBufferAttribute(t):this.boundingBox.makeEmpty(),(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)},computeBoundingSphere:function(){var t=new st,e=new n;return function(){null===this.boundingSphere&&(this.boundingSphere=new ct);var r=this.attributes.position;if(r){var n=this.boundingSphere.center;t.setFromBufferAttribute(r),t.getCenter(n);for(var i=0,a=0,o=r.count;a0&&(t.data.groups=JSON.parse(JSON.stringify(s)));var c=this.boundingSphere;return null!==c&&(t.data.boundingSphere={center:c.center.toArray(),radius:c.radius}),t},clone:function(){return(new Ct).copy(this)},copy:function(t){var e,r,n;this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.name=t.name;var i=t.index;null!==i&&this.setIndex(i.clone());var a=t.attributes;for(e in a){var o=a[e];this.addAttribute(e,o.clone())}var s=t.morphAttributes;for(e in s){var c=[],l=s[e];for(r=0,n=l.length;r0)if(s=d*f-p,c=d*p-f,h=u*g,s>=0)if(c>=-h)if(c<=h){var v=1/g;l=(s*=v)*(s+d*(c*=v)+2*p)+c*(d*s+c+2*f)+m}else c=u,l=-(s=Math.max(0,-(d*c+p)))*s+c*(c+2*f)+m;else c=-u,l=-(s=Math.max(0,-(d*c+p)))*s+c*(c+2*f)+m;else c<=-h?l=-(s=Math.max(0,-(-d*u+p)))*s+(c=s>0?-u:Math.min(Math.max(-u,-f),u))*(c+2*f)+m:c<=h?(s=0,l=(c=Math.min(Math.max(-u,-f),u))*(c+2*f)+m):l=-(s=Math.max(0,-(d*u+p)))*s+(c=s>0?u:Math.min(Math.max(-u,-f),u))*(c+2*f)+m;else c=d>0?-u:u,l=-(s=Math.max(0,-(d*c+p)))*s+c*(c+2*f)+m;return a&&a.copy(this.direction).multiplyScalar(s).add(this.origin),o&&o.copy(e).multiplyScalar(c).add(t),l}}(),intersectSphere:function(){var t=new n;return function(e,r){t.subVectors(e.center,this.origin);var n=t.dot(this.direction),i=t.dot(t)-n*n,a=e.radius*e.radius;if(i>a)return null;var o=Math.sqrt(a-i),s=n-o,c=n+o;return s<0&&c<0?null:s<0?this.at(c,r):this.at(s,r)}}(),intersectsSphere:function(t){return this.distanceToPoint(t.center)<=t.radius},distanceToPlane:function(t){var e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;var r=-(this.origin.dot(t.normal)+t.constant)/e;return r>=0?r:null},intersectPlane:function(t,e){var r=this.distanceToPlane(t);return null===r?null:this.at(r,e)},intersectsPlane:function(t){var e=t.distanceToPoint(this.origin);return 0===e||t.normal.dot(this.direction)*e<0},intersectBox:function(t,e){var r,n,i,a,o,s,c=1/this.direction.x,l=1/this.direction.y,h=1/this.direction.z,u=this.origin;return c>=0?(r=(t.min.x-u.x)*c,n=(t.max.x-u.x)*c):(r=(t.max.x-u.x)*c,n=(t.min.x-u.x)*c),l>=0?(i=(t.min.y-u.y)*l,a=(t.max.y-u.y)*l):(i=(t.max.y-u.y)*l,a=(t.min.y-u.y)*l),r>a||i>n?null:((i>r||r!==r)&&(r=i),(a=0?(o=(t.min.z-u.z)*h,s=(t.max.z-u.z)*h):(o=(t.max.z-u.z)*h,s=(t.min.z-u.z)*h),r>s||o>n?null:((o>r||r!==r)&&(r=o),(s=0?r:n,e)))},intersectsBox:function(){var t=new n;return function(e){return null!==this.intersectBox(e,t)}}(),intersectTriangle:function(){var t=new n,e=new n,r=new n,i=new n;return function(n,a,o,s,c){e.subVectors(a,n),r.subVectors(o,n),i.crossVectors(e,r);var l,h=this.direction.dot(i);if(h>0){if(s)return null;l=1}else{if(!(h<0))return null;l=-1,h=-h}t.subVectors(this.origin,n);var u=l*this.direction.dot(r.crossVectors(t,r));if(u<0)return null;var d=l*this.direction.dot(e.cross(t));if(d<0)return null;if(u+d>h)return null;var p=-l*t.dot(i);return p<0?null:this.at(p/h,c)}}(),applyMatrix4:function(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this},equals:function(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}}),Object.assign(Ut.prototype,{set:function(t,e){return this.start.copy(t),this.end.copy(e),this},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.start.copy(t.start),this.end.copy(t.end),this},getCenter:function(t){return(t||new n).addVectors(this.start,this.end).multiplyScalar(.5)},delta:function(t){return(t||new n).subVectors(this.end,this.start)},distanceSq:function(){return this.start.distanceToSquared(this.end)},distance:function(){return this.start.distanceTo(this.end)},at:function(t,e){var r=e||new n;return this.delta(r).multiplyScalar(t).add(this.start)},closestPointToPointParameter:function(){var t=new n,e=new n;return function(r,n){t.subVectors(r,this.start),e.subVectors(this.end,this.start);var i=e.dot(e),a=e.dot(t)/i;return n&&(a=Ko.clamp(a,0,1)),a}}(),closestPointToPoint:function(t,e,r){var i=this.closestPointToPointParameter(t,e),a=r||new n;return this.delta(a).multiplyScalar(i).add(this.start)},applyMatrix4:function(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this},equals:function(t){return t.start.equals(this.start)&&t.end.equals(this.end)}}),Object.assign(zt,{normal:function(){var t=new n;return function(e,r,i,a){var o=a||new n;o.subVectors(i,r),t.subVectors(e,r),o.cross(t);var s=o.lengthSq();return s>0?o.multiplyScalar(1/Math.sqrt(s)):o.set(0,0,0)}}(),barycoordFromPoint:function(){var t=new n,e=new n,r=new n;return function(i,a,o,s,c){t.subVectors(s,a),e.subVectors(o,a),r.subVectors(i,a);var l=t.dot(t),h=t.dot(e),u=t.dot(r),d=e.dot(e),p=e.dot(r),f=l*d-h*h,m=c||new n;if(0===f)return m.set(-2,-1,-1);var g=1/f,v=(d*u-h*p)*g,y=(l*p-h*u)*g;return m.set(1-v-y,y,v)}}(),containsPoint:function(){var t=new n;return function(e,r,n,i){var a=zt.barycoordFromPoint(e,r,n,i,t);return a.x>=0&&a.y>=0&&a.x+a.y<=1}}()}),Object.assign(zt.prototype,{set:function(t,e,r){return this.a.copy(t),this.b.copy(e),this.c.copy(r),this},setFromPointsAndIndices:function(t,e,r,n){return this.a.copy(t[e]),this.b.copy(t[r]),this.c.copy(t[n]),this},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this},area:function(){var t=new n,e=new n;return function(){return t.subVectors(this.c,this.b),e.subVectors(this.a,this.b),.5*t.cross(e).length()}}(),midpoint:function(t){return(t||new n).addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)},normal:function(t){return zt.normal(this.a,this.b,this.c,t)},plane:function(t){return(t||new ht).setFromCoplanarPoints(this.a,this.b,this.c)},barycoordFromPoint:function(t,e){return zt.barycoordFromPoint(t,this.a,this.b,this.c,e)},containsPoint:function(t){return zt.containsPoint(t,this.a,this.b,this.c)},closestPointToPoint:function(){var t=new ht,e=[new Ut,new Ut,new Ut],r=new n,i=new n;return function(a,o){var s=o||new n,c=1/0;if(t.setFromCoplanarPoints(this.a,this.b,this.c),t.projectPoint(a,r),!0===this.containsPoint(r))s.copy(r);else{e[0].set(this.a,this.b),e[1].set(this.b,this.c),e[2].set(this.c,this.a);for(var l=0;l0){var o=i[a[0]];if(void 0!==o)for(this.morphTargetInfluences=[],this.morphTargetDictionary={},t=0,e=o.length;t0)for(this.morphTargetInfluences=[],this.morphTargetDictionary={},t=0,e=s.length;te.far?null:{distance:c,point:b.clone(),object:t}}function i(e,n,i,a,o,s,h,d){c.fromBufferAttribute(a,s),l.fromBufferAttribute(a,h),u.fromBufferAttribute(a,d);var p=r(e,n,i,c,l,u,x);return p&&(o&&(m.fromBufferAttribute(o,s),g.fromBufferAttribute(o,h),v.fromBufferAttribute(o,d),p.uv=t(x,c,l,u,m,g,v)),p.face=new bt(s,h,d,zt.normal(c,l,u)),p.faceIndex=s),p}var a=new e,o=new Dt,s=new ct,c=new n,l=new n,u=new n,d=new n,p=new n,f=new n,m=new h,g=new h,v=new h,y=new n,x=new n,b=new n;return function(e,n){var h=this.geometry,y=this.material,b=this.matrixWorld;if(void 0!==y&&(null===h.boundingSphere&&h.computeBoundingSphere(),s.copy(h.boundingSphere),s.applyMatrix4(b),!1!==e.ray.intersectsSphere(s)&&(a.getInverse(b),o.copy(e.ray).applyMatrix4(a),null===h.boundingBox||!1!==o.intersectsBox(h.boundingBox)))){var w;if(h.isBufferGeometry){var _,M,E,S,T,A=h.index,L=h.attributes.position,C=h.attributes.uv;if(null!==A)for(S=0,T=A.count;S0&&(O=z);for(var B=0,F=U.length;Ba)){var o=n.ray.origin.distanceTo(t);on.far||i.push({distance:o,point:t.clone(),face:null,object:this})}}}(),clone:function(){return new this.constructor(this.material).copy(this)}}),Se.prototype=Object.assign(Object.create(gt.prototype),{constructor:Se,copy:function(t){gt.prototype.copy.call(this,t,!1);for(var e=t.levels,r=0,n=e.length;r1){t.setFromMatrixPosition(r.matrixWorld),e.setFromMatrixPosition(this.matrixWorld);var i=t.distanceTo(e);n[0].object.visible=!0;for(var a=1,o=n.length;a=n[a].distance;a++)n[a-1].object.visible=!1,n[a].object.visible=!0;for(;as||(p.applyMatrix4(this.matrixWorld),(S=e.ray.origin.distanceTo(p))e.far||a.push({distance:S,point:d.clone().applyMatrix4(this.matrixWorld),index:y,face:null,faceIndex:null,object:this}))}else for(var y=0,x=g.length/3-1;ys||(p.applyMatrix4(this.matrixWorld),(S=e.ray.origin.distanceTo(p))e.far||a.push({distance:S,point:d.clone().applyMatrix4(this.matrixWorld),index:y,face:null,faceIndex:null,object:this}))}else if(c.isGeometry)for(var _=c.vertices,M=_.length,y=0;ys)){p.applyMatrix4(this.matrixWorld);var S=e.ray.origin.distanceTo(p);Se.far||a.push({distance:S,point:d.clone().applyMatrix4(this.matrixWorld),index:y,face:null,faceIndex:null,object:this})}}}}}(),clone:function(){return new this.constructor(this.geometry,this.material).copy(this)}}),Pe.prototype=Object.assign(Object.create(Re.prototype),{constructor:Pe,isLineSegments:!0}),Ie.prototype=Object.assign(Object.create(Re.prototype),{constructor:Ie,isLineLoop:!0}),Oe.prototype=Object.create(it.prototype),Oe.prototype.constructor=Oe,Oe.prototype.isPointsMaterial=!0,Oe.prototype.copy=function(t){return it.prototype.copy.call(this,t),this.color.copy(t.color),this.map=t.map,this.size=t.size,this.sizeAttenuation=t.sizeAttenuation,this},Ne.prototype=Object.assign(Object.create(gt.prototype),{constructor:Ne,isPoints:!0,raycast:function(){var t=new e,r=new Dt,i=new ct;return function(e,a){function o(t,n){var i=r.distanceSqToPoint(t);if(ie.far)return;a.push({distance:c,distanceToRay:Math.sqrt(i),point:o.clone(),index:n,face:null,object:s})}}var s=this,c=this.geometry,l=this.matrixWorld,h=e.params.Points.threshold;if(null===c.boundingSphere&&c.computeBoundingSphere(),i.copy(c.boundingSphere),i.applyMatrix4(l),i.radius+=h,!1!==e.ray.intersectsSphere(i)){t.getInverse(l),r.copy(e.ray).applyMatrix4(t);var u=h/((this.scale.x+this.scale.y+this.scale.z)/3),d=u*u,p=new n;if(c.isBufferGeometry){var f=c.index,m=c.attributes.position.array;if(null!==f)for(var g=f.array,v=0,y=g.length;v=-Number.EPSILON&&L>=-Number.EPSILON&&A>=-Number.EPSILON))return!1;return!0}return function(e,r){var n=e.length;if(n<3)return null;var i,a,o,s=[],c=[],l=[];if(lh.area(e)>0)for(a=0;a2;){if(u--<=0)return console.warn("THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()"),r?l:s;if(i=a,h<=i&&(i=0),a=i+1,h<=a&&(a=0),o=a+1,h<=o&&(o=0),t(e,i,a,o,h,c)){var d,p,f,m,g;for(d=c[i],p=c[a],f=c[o],s.push([e[d],e[p],e[f]]),l.push([c[i],c[a],c[o]]),m=a,g=a+1;g2&&t[e-1].equals(t[0])&&t.pop()}function n(t,e,r){return t.x!==e.x?t.xNumber.EPSILON){var f;if(d>0){if(p<0||p>d)return[];if((f=l*h-c*u)<0||f>d)return[]}else{if(p>0||p0||fS?[]:b===S?a?[]:[y]:w<=S?[y,x]:[y,M]}function a(t,e,r,n){var i=e.x-t.x,a=e.y-t.y,o=r.x-t.x,s=r.y-t.y,c=n.x-t.x,l=n.y-t.y,h=i*s-a*o,u=i*l-a*c;if(Math.abs(h)>Number.EPSILON){var d=c*s-l*o;return h>0?u>=0&&d>=0:u>=0||d>=0}return u>0}r(t),e.forEach(r);for(var o,s,c,l,h,u,d={},p=t.concat(),f=0,m=e.length;f0;){if(--w<0){console.log("Infinite Loop! Holes left:"+g.length+", Probably Hole outside Shape!");break}for(o=b;on&&(o=0);var s=a(m[t],m[i],m[o],r[e]);if(!s)return!1;var c=r.length-1,l=e-1;l<0&&(l=c);var h=e+1;return h>c&&(h=0),!!(s=a(r[e],r[l],r[h],m[t]))}(o,_)&&!function(t,e){var r,n;for(r=0;r0)return!0;return!1}(s,c)&&!function(t,r){var n,a,o,s;for(n=0;n0)return!0;return!1}(s,c)){n=_,g.splice(y,1),u=m.slice(0,o+1),d=m.slice(o),p=r.slice(n),f=r.slice(0,n+1),m=u.concat(p).concat(f).concat(d),b=o;break}if(n>=0)break;v[h]=!0}if(n>=0)break}}return m}(t,e),v=lh.triangulate(g,!1);for(o=0,s=v.length;oNumber.EPSILON){var p=Math.sqrt(u),f=Math.sqrt(c*c+l*l),m=e.x-s/p,g=e.y+o/p,v=((r.x-l/f-m)*l-(r.y+c/f-g)*c)/(o*l-s*c),y=(n=m+o*v-t.x)*n+(i=g+s*v-t.y)*i;if(y<=2)return new h(n,i);a=Math.sqrt(y/2)}else{var x=!1;o>Number.EPSILON?c>Number.EPSILON&&(x=!0):o<-Number.EPSILON?c<-Number.EPSILON&&(x=!0):Math.sign(s)===Math.sign(l)&&(x=!0),x?(n=-s,i=o,a=Math.sqrt(u)):(n=o,i=s,a=Math.sqrt(u/2))}return new h(n/a,i/a)}function a(t,e){var r,n;for(J=t.length;--J>=0;){r=J,(n=J-1)<0&&(n=t.length-1);var i=0,a=L+2*S;for(i=0;i=0;G--){for(H=G/S,j=M*Math.cos(H*Math.PI/2),V=E*Math.sin(H*Math.PI/2),J=0,Q=k.length;J0||0===t.search(/^data\:image\/jpeg/);a.format=r?gl:vl,a.needsUpdate=!0,void 0!==e&&e(a)},r,n),a},setCrossOrigin:function(t){return this.crossOrigin=t,this},setPath:function(t){return this.path=t,this}}),Br.prototype=Object.assign(Object.create(gt.prototype),{constructor:Br,isLight:!0,copy:function(t){return gt.prototype.copy.call(this,t),this.color.copy(t.color),this.intensity=t.intensity,this},toJSON:function(t){var e=gt.prototype.toJSON.call(this,t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,void 0!==this.groundColor&&(e.object.groundColor=this.groundColor.getHex()),void 0!==this.distance&&(e.object.distance=this.distance),void 0!==this.angle&&(e.object.angle=this.angle),void 0!==this.decay&&(e.object.decay=this.decay),void 0!==this.penumbra&&(e.object.penumbra=this.penumbra),void 0!==this.shadow&&(e.object.shadow=this.shadow.toJSON()),e}}),Fr.prototype=Object.assign(Object.create(Br.prototype),{constructor:Fr,isHemisphereLight:!0,copy:function(t){return Br.prototype.copy.call(this,t),this.groundColor.copy(t.groundColor),this}}),Object.assign(kr.prototype,{copy:function(t){return this.camera=t.camera.clone(),this.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this},clone:function(){return(new this.constructor).copy(this)},toJSON:function(){var t={};return 0!==this.bias&&(t.bias=this.bias),1!==this.radius&&(t.radius=this.radius),512===this.mapSize.x&&512===this.mapSize.y||(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}),Gr.prototype=Object.assign(Object.create(kr.prototype),{constructor:Gr,isSpotLightShadow:!0,update:function(t){var e=this.camera,r=2*Ko.RAD2DEG*t.angle,n=this.mapSize.width/this.mapSize.height,i=t.distance||e.far;r===e.fov&&n===e.aspect&&i===e.far||(e.fov=r,e.aspect=n,e.far=i,e.updateProjectionMatrix())}}),Vr.prototype=Object.assign(Object.create(Br.prototype),{constructor:Vr,isSpotLight:!0,copy:function(t){return Br.prototype.copy.call(this,t),this.distance=t.distance,this.angle=t.angle,this.penumbra=t.penumbra,this.decay=t.decay,this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}),Hr.prototype=Object.assign(Object.create(Br.prototype),{constructor:Hr,isPointLight:!0,copy:function(t){return Br.prototype.copy.call(this,t),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}}),jr.prototype=Object.assign(Object.create(kr.prototype),{constructor:jr}),Wr.prototype=Object.assign(Object.create(Br.prototype),{constructor:Wr,isDirectionalLight:!0,copy:function(t){return Br.prototype.copy.call(this,t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}),Xr.prototype=Object.assign(Object.create(Br.prototype),{constructor:Xr,isAmbientLight:!0}),Yr.prototype=Object.assign(Object.create(Br.prototype),{constructor:Yr,isRectAreaLight:!0,copy:function(t){return Br.prototype.copy.call(this,t),this.width=t.width,this.height=t.height,this},toJSON:function(t){var e=Br.prototype.toJSON.call(this,t);return e.object.width=this.width,e.object.height=this.height,e}});var fh={arraySlice:function(t,e,r){return fh.isTypedArray(t)?new t.constructor(t.subarray(e,void 0!==r?r:t.length)):t.slice(e,r)},convertArray:function(t,e,r){return!t||!r&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)},isTypedArray:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)},getKeyframeOrder:function(t){function e(e,r){return t[e]-t[r]}for(var r=t.length,n=new Array(r),i=0;i!==r;++i)n[i]=i;return n.sort(e),n},sortedArray:function(t,e,r){for(var n=t.length,i=new t.constructor(n),a=0,o=0;o!==n;++a)for(var s=r[a]*e,c=0;c!==e;++c)i[o++]=t[s+c];return i},flattenJSON:function(t,e,r,n){for(var i=1,a=t[0];void 0!==a&&void 0===a[n];)a=t[i++];if(void 0!==a){var o=a[n];if(void 0!==o)if(Array.isArray(o))do{void 0!==(o=a[n])&&(e.push(a.time),r.push.apply(r,o)),a=t[i++]}while(void 0!==a);else if(void 0!==o.toArray)do{void 0!==(o=a[n])&&(e.push(a.time),o.toArray(r,r.length)),a=t[i++]}while(void 0!==a);else do{void 0!==(o=a[n])&&(e.push(a.time),r.push(o)),a=t[i++]}while(void 0!==a)}}};Object.assign(qr.prototype,{evaluate:function(t){var e=this.parameterPositions,r=this._cachedIndex,n=e[r],i=e[r-1];t:{e:{var a;r:{n:if(!(t=i)break t;var o=e[1];t=i)break e}a=r,r=0}}for(;r>>1;te;)--a;if(++a,0!==i||a!==n){i>=a&&(a=Math.max(a,1),i=a-1);var o=this.getValueSize();this.times=fh.arraySlice(r,i,a),this.values=fh.arraySlice(this.values,i*o,a*o)}return this},validate:function(){var t=!0,e=this.getValueSize();e-Math.floor(e)!=0&&(console.error("THREE.KeyframeTrackPrototype: Invalid value size in track.",this),t=!1);var r=this.times,n=this.values,i=r.length;0===i&&(console.error("THREE.KeyframeTrackPrototype: Track is empty.",this),t=!1);for(var a=null,o=0;o!==i;o++){var s=r[o];if("number"==typeof s&&isNaN(s)){console.error("THREE.KeyframeTrackPrototype: Time is not a valid number.",this,o,s),t=!1;break}if(null!==a&&a>s){console.error("THREE.KeyframeTrackPrototype: Out of order keys.",this,o,s,a),t=!1;break}a=s}if(void 0!==n&&fh.isTypedArray(n))for(var o=0,c=n.length;o!==c;++o){var l=n[o];if(isNaN(l)){console.error("THREE.KeyframeTrackPrototype: Value is not a valid number.",this,o,l),t=!1;break}}return t},optimize:function(){for(var t=this.times,e=this.values,r=this.getValueSize(),n=2302===this.getInterpolation(),i=1,a=t.length-1,o=1;o0){t[i]=t[a];for(var f=a*r,m=i*r,d=0;d!==r;++d)e[m+d]=e[f+d];++i}return i!==t.length&&(this.times=fh.arraySlice(t,0,i),this.values=fh.arraySlice(e,0,i*r)),this}},$r.prototype=Object.assign(Object.create(mh),{constructor:$r,ValueTypeName:"vector"}),tn.prototype=Object.assign(Object.create(qr.prototype),{constructor:tn,interpolate_:function(t,e,n,i){for(var a=this.resultBuffer,o=this.sampleValues,s=this.valueSize,c=t*s,l=(n-e)/(i-e),h=c+s;c!==h;c+=4)r.slerpFlat(a,0,o,c-s,o,c,l);return a}}),en.prototype=Object.assign(Object.create(mh),{constructor:en,ValueTypeName:"quaternion",DefaultInterpolation:2301,InterpolantFactoryMethodLinear:function(t){return new tn(this.times,this.values,this.getValueSize(),t)},InterpolantFactoryMethodSmooth:void 0}),rn.prototype=Object.assign(Object.create(mh),{constructor:rn,ValueTypeName:"number"}),nn.prototype=Object.assign(Object.create(mh),{constructor:nn,ValueTypeName:"string",ValueBufferType:Array,DefaultInterpolation:2300,InterpolantFactoryMethodLinear:void 0,InterpolantFactoryMethodSmooth:void 0}),an.prototype=Object.assign(Object.create(mh),{constructor:an,ValueTypeName:"bool",ValueBufferType:Array,DefaultInterpolation:2300,InterpolantFactoryMethodLinear:void 0,InterpolantFactoryMethodSmooth:void 0}),on.prototype=Object.assign(Object.create(mh),{constructor:on,ValueTypeName:"color"}),sn.prototype=mh,mh.constructor=sn,Object.assign(sn,{parse:function(t){if(void 0===t.type)throw new Error("track type undefined, can not parse");var e=sn._getTrackTypeForValueTypeName(t.type);if(void 0===t.times){var r=[],n=[];fh.flattenJSON(t.keys,r,n,"value"),t.times=r,t.values=n}return void 0!==e.parse?e.parse(t):new e(t.name,t.times,t.values,t.interpolation)},toJSON:function(t){var e,r=t.constructor;if(void 0!==r.toJSON)e=r.toJSON(t);else{e={name:t.name,times:fh.convertArray(t.times,Array),values:fh.convertArray(t.values,Array)};var n=t.getInterpolation();n!==t.DefaultInterpolation&&(e.interpolation=n)}return e.type=t.ValueTypeName,e},_getTrackTypeForValueTypeName:function(t){switch(t.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return rn;case"vector":case"vector2":case"vector3":case"vector4":return $r;case"color":return on;case"quaternion":return en;case"bool":case"boolean":return an;case"string":return nn}throw new Error("Unsupported typeName: "+t)}}),Object.assign(cn,{parse:function(t){for(var e=[],r=t.tracks,n=1/(t.fps||1),i=0,a=r.length;i!==a;++i)e.push(sn.parse(r[i]).scale(n));return new cn(t.name,t.duration,e)},toJSON:function(t){for(var e=[],r=t.tracks,n={name:t.name,duration:t.duration,tracks:e},i=0,a=r.length;i!==a;++i)e.push(sn.toJSON(r[i]));return n},CreateFromMorphTargetSequence:function(t,e,r,n){for(var i=e.length,a=[],o=0;o1){var c=n[h=s[1]];c||(n[h]=c=[]),c.push(o)}}var l=[];for(var h in n)l.push(cn.CreateFromMorphTargetSequence(h,n[h],e,r));return l},parseAnimation:function(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;for(var r=function(t,e,r,n,i){if(0!==r.length){var a=[],o=[];fh.flattenJSON(r,a,o,n),0!==a.length&&i.push(new t(e,a,o))}},n=[],i=t.name||"default",a=t.length||-1,o=t.fps||30,s=t.hierarchy||[],c=0;c1?t.skinWeights[n+1]:0,s=r>2?t.skinWeights[n+2]:0,c=r>3?t.skinWeights[n+3]:0;e.skinWeights.push(new y(a,o,s,c))}if(t.skinIndices)for(var n=0,i=t.skinIndices.length;n1?t.skinIndices[n+1]:0,u=r>2?t.skinIndices[n+2]:0,d=r>3?t.skinIndices[n+3]:0;e.skinIndices.push(new y(l,h,u,d))}e.bones=t.bones,e.bones&&e.bones.length>0&&(e.skinWeights.length!==e.skinIndices.length||e.skinIndices.length!==e.vertices.length)&&console.warn("When skinning, number of vertices ("+e.vertices.length+"), skinIndices ("+e.skinIndices.length+"), and skinWeights ("+e.skinWeights.length+") should match.")}function r(t,e){var r=t.scale;if(void 0!==t.morphTargets)for(var i=0,a=t.morphTargets.length;i0){console.warn('THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.');for(var u=e.faces,d=t.morphColors[0].colors,i=0,a=u.length;i0&&(e.animations=r)}return function(n,a){void 0!==n.data&&(n=n.data),void 0!==n.scale?n.scale=1/n.scale:n.scale=1;var o=new _t;return t(n,o),e(n,o),r(n,o),i(n,o),o.computeFaceNormals(),o.computeBoundingSphere(),void 0===n.materials||0===n.materials.length?{geometry:o}:{geometry:o,materials:un.prototype.initMaterials(n.materials,a,this.crossOrigin)}}}()}),Object.assign(pn.prototype,{load:function(t,e,r,n){""===this.texturePath&&(this.texturePath=t.substring(0,t.lastIndexOf("/")+1));var i=this;new Ir(i.manager).load(t,function(r){var a=null;try{a=JSON.parse(r)}catch(e){return void 0!==n&&n(e),void console.error("THREE:ObjectLoader: Can't parse "+t+".",e.message)}var o=a.metadata;if(void 0===o||void 0===o.type||"geometry"===o.type.toLowerCase())return void console.error("THREE.ObjectLoader: Can't load "+t+". Use THREE.JSONLoader instead.");i.parse(a,e)},r,n)},setTexturePath:function(t){this.texturePath=t},setCrossOrigin:function(t){this.crossOrigin=t},parse:function(t,e){var r=this.parseGeometries(t.geometries),n=this.parseImages(t.images,function(){void 0!==e&&e(o)}),i=this.parseTextures(t.textures,n),a=this.parseMaterials(t.materials,i),o=this.parseObject(t.object,r,a);return t.animations&&(o.animations=this.parseAnimations(t.animations)),void 0!==t.images&&0!==t.images.length||void 0!==e&&e(o),o},parseGeometries:function(t){var e={};if(void 0!==t)for(var r=new dn,n=new hn,i=0,a=t.length;i0){var i=new Dr(new Pr(e));i.setCrossOrigin(this.crossOrigin);for(var a=0,o=t.length;a0?new Le(s,l):new Bt(s,l);break;case"LOD":o=new Se;break;case"Line":o=new Re(i(e.geometry),a(e.material),e.mode);break;case"LineLoop":o=new Ie(i(e.geometry),a(e.material));break;case"LineSegments":o=new Pe(i(e.geometry),a(e.material));break;case"PointCloud":case"Points":o=new Ne(i(e.geometry),a(e.material));break;case"Sprite":o=new Ee(a(e.material));break;case"Group":o=new De;break;default:o=new gt}if(o.uuid=e.uuid,void 0!==e.name&&(o.name=e.name),void 0!==e.matrix?(t.fromArray(e.matrix),t.decompose(o.position,o.quaternion,o.scale)):(void 0!==e.position&&o.position.fromArray(e.position),void 0!==e.rotation&&o.rotation.fromArray(e.rotation),void 0!==e.quaternion&&o.quaternion.fromArray(e.quaternion),void 0!==e.scale&&o.scale.fromArray(e.scale)),void 0!==e.castShadow&&(o.castShadow=e.castShadow),void 0!==e.receiveShadow&&(o.receiveShadow=e.receiveShadow),e.shadow&&(void 0!==e.shadow.bias&&(o.shadow.bias=e.shadow.bias),void 0!==e.shadow.radius&&(o.shadow.radius=e.shadow.radius),void 0!==e.shadow.mapSize&&o.shadow.mapSize.fromArray(e.shadow.mapSize),void 0!==e.shadow.camera&&(o.shadow.camera=this.parseObject(e.shadow.camera))),void 0!==e.visible&&(o.visible=e.visible),void 0!==e.userData&&(o.userData=e.userData),void 0!==e.children)for(var h in e.children)o.add(this.parseObject(e.children[h],r,n));if("LOD"===e.type)for(var u=e.levels,d=0;d0)){c=i;break}c=i-1}if(i=c,n[i]===r)return i/(a-1);var l=n[i];return(i+(r-l)/(n[i+1]-l))/(a-1)},getTangent:function(t){var e=t-1e-4,r=t+1e-4;e<0&&(e=0),r>1&&(r=1);var n=this.getPoint(e);return this.getPoint(r).clone().sub(n).normalize()},getTangentAt:function(t){var e=this.getUtoTmapping(t);return this.getTangent(e)},computeFrenetFrames:function(t,r){var i,a,o,s=new n,c=[],l=[],h=[],u=new n,d=new e;for(i=0;i<=t;i++)a=i/t,c[i]=this.getTangentAt(a),c[i].normalize();l[0]=new n,h[0]=new n;var p=Number.MAX_VALUE,f=Math.abs(c[0].x),m=Math.abs(c[0].y),g=Math.abs(c[0].z);for(f<=p&&(p=f,s.set(1,0,0)),m<=p&&(p=m,s.set(0,1,0)),g<=p&&s.set(0,0,1),u.crossVectors(c[0],s).normalize(),l[0].crossVectors(c[0],u),h[0].crossVectors(c[0],l[0]),i=1;i<=t;i++)l[i]=l[i-1].clone(),h[i]=h[i-1].clone(),u.crossVectors(c[i-1],c[i]),u.length()>Number.EPSILON&&(u.normalize(),o=Math.acos(Ko.clamp(c[i-1].dot(c[i]),-1,1)),l[i].applyMatrix4(d.makeRotationAxis(u,o))),h[i].crossVectors(c[i],l[i]);if(!0===r)for(o=Math.acos(Ko.clamp(l[0].dot(l[t]),-1,1)),o/=t,c[0].dot(u.crossVectors(l[0],l[t]))>0&&(o=-o),i=1;i<=t;i++)l[i].applyMatrix4(d.makeRotationAxis(c[i],o*i)),h[i].crossVectors(c[i],l[i]);return{tangents:c,normals:l,binormals:h}}}),Sn.prototype=Object.create(En.prototype),Sn.prototype.constructor=Sn,Sn.prototype.isLineCurve=!0,Sn.prototype.getPoint=function(t){if(1===t)return this.v2.clone();var e=this.v2.clone().sub(this.v1);return e.multiplyScalar(t).add(this.v1),e},Sn.prototype.getPointAt=function(t){return this.getPoint(t)},Sn.prototype.getTangent=function(t){return this.v2.clone().sub(this.v1).normalize()},Tn.prototype=Object.assign(Object.create(En.prototype),{constructor:Tn,add:function(t){this.curves.push(t)},closePath:function(){var t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);t.equals(e)||this.curves.push(new Sn(e,t))},getPoint:function(t){for(var e=t*this.getLength(),r=this.getCurveLengths(),n=0;n=e){var i=r[n]-e,a=this.curves[n],o=a.getLength(),s=0===o?0:1-i/o;return a.getPointAt(s)}n++}return null},getLength:function(){var t=this.getCurveLengths();return t[t.length-1]},updateArcLengths:function(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()},getCurveLengths:function(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;for(var t=[],e=0,r=0,n=this.curves.length;r1&&!r[r.length-1].equals(r[0])&&r.push(r[0]),r},createPointsGeometry:function(t){var e=this.getPoints(t);return this.createGeometry(e)},createSpacedPointsGeometry:function(t){var e=this.getSpacedPoints(t);return this.createGeometry(e)},createGeometry:function(t){for(var e=new _t,r=0,i=t.length;re;)r-=e;re.length-2?e.length-1:n+1],c=e[n>e.length-3?e.length-1:n+2];return new h(fn(i,a.x,o.x,s.x,c.x),fn(i,a.y,o.y,s.y,c.y))},Cn.prototype=Object.create(En.prototype),Cn.prototype.constructor=Cn,Cn.prototype.getPoint=function(t){var e=this.v0,r=this.v1,n=this.v2,i=this.v3;return new h(Mn(t,e.x,r.x,n.x,i.x),Mn(t,e.y,r.y,n.y,i.y))},Rn.prototype=Object.create(En.prototype),Rn.prototype.constructor=Rn,Rn.prototype.getPoint=function(t){var e=this.v0,r=this.v1,n=this.v2;return new h(yn(t,e.x,r.x,n.x),yn(t,e.y,r.y,n.y))};var bh=Object.assign(Object.create(Tn.prototype),{fromPoints:function(t){this.moveTo(t[0].x,t[0].y);for(var e=1,r=t.length;e0){var l=c.getPoint(0);l.equals(this.currentPoint)||this.lineTo(l.x,l.y)}this.curves.push(c);var h=c.getPoint(1);this.currentPoint.copy(h)}});Pn.prototype=bh,bh.constructor=Pn,In.prototype=Object.assign(Object.create(bh),{constructor:In,getPointsHoles:function(t){for(var e=[],r=0,n=this.holes.length;r1){for(var v=!1,y=[],x=0,b=d.length;xNumber.EPSILON){if(l<0&&(o=e[a],c=-c,s=e[i],l=-l),t.ys.y)continue;if(t.y===o.y){if(t.x===o.x)return!0}else{var h=l*(t.x-o.x)-c*(t.y-o.y);if(0===h)return!0;if(h<0)continue;n=!n}}else{if(t.y!==o.y)continue;if(s.x<=t.x&&t.x<=o.x||o.x<=t.x&&t.x<=s.x)return!0}}return n})(M.p,d[S].p)&&(x!==S&&y.push({froms:x,tos:S,hole:_}),E?(E=!1,u[S].push(M)):v=!0);E&&u[x].push(M)}y.length>0&&(v||(p=u))}for(var T,m=0,A=d.length;m0){this.source.connect(this.filters[0]);for(var t=1,e=this.filters.length;t0){this.source.disconnect(this.filters[0]);for(var t=1,e=this.filters.length;t=.5)for(var a=0;a!==i;++a)t[e+a]=t[r+a]},_slerp:function(t,e,n,i){r.slerpFlat(t,e,t,e,t,n,i)},_lerp:function(t,e,r,n,i){for(var a=1-n,o=0;o!==i;++o){var s=e+o;t[s]=t[s]*a+t[r+o]*n}}}),Object.assign(Hn.prototype,{getValue:function(t,e){this.bind();var r=this._targetGroup.nCachedObjects_,n=this._bindings[r];void 0!==n&&n.getValue(t,e)},setValue:function(t,e){for(var r=this._bindings,n=this._targetGroup.nCachedObjects_,i=r.length;n!==i;++n)r[n].setValue(t,e)},bind:function(){for(var t=this._bindings,e=this._targetGroup.nCachedObjects_,r=t.length;e!==r;++e)t[e].bind()},unbind:function(){for(var t=this._bindings,e=this._targetGroup.nCachedObjects_,r=t.length;e!==r;++e)t[e].unbind()}}),Object.assign(jn,{Composite:Hn,create:function(t,e,r){return t&&t.isAnimationObjectGroup?new jn.Composite(t,e,r):new jn(t,e,r)},sanitizeNodeName:function(t){return t.replace(/\s/g,"_").replace(/[^\w-]/g,"")},parseTrackName:function(){var t=new RegExp("^"+/((?:[\w-]+[\/:])*)/.source+/([\w-\.]+)?/.source+/(?:\.([\w-]+)(?:\[(.+)\])?)?/.source+/\.([\w-]+)(?:\[(.+)\])?/.source+"$"),e=["material","materials","bones"];return function(r){var n=t.exec(r);if(!n)throw new Error("PropertyBinding: Cannot parse trackName: "+r);var i={nodeName:n[2],objectName:n[3],objectIndex:n[4],propertyName:n[5],propertyIndex:n[6]},a=i.nodeName&&i.nodeName.lastIndexOf(".");if(void 0!==a&&-1!==a){var o=i.nodeName.substring(a+1);-1!==e.indexOf(o)&&(i.nodeName=i.nodeName.substring(0,a),i.objectName=o)}if(null===i.propertyName||0===i.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+r);return i}}(),findNode:function(t,e){if(!e||""===e||"root"===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){var r=function(t){for(var r=0;r=r){var u=r++,d=e[u];n[d.uuid]=h,e[h]=d,n[l]=u,e[u]=c;for(var p=0,f=a;p!==f;++p){var m=i[p],g=m[u],v=m[h];m[h]=g,m[u]=v}}}this.nCachedObjects_=r},uncache:function(t){for(var e=this._objects,r=e.length,n=this.nCachedObjects_,i=this._indicesByUUID,a=this._bindings,o=a.length,s=0,c=arguments.length;s!==c;++s){var l=arguments[s].uuid,h=i[l];if(void 0!==h)if(delete i[l],h0)for(var c=this._interpolants,l=this._propertyBindings,h=0,u=c.length;h!==u;++h)c[h].evaluate(o),l[h].accumulate(n,s)},_updateWeight:function(t){var e=0;if(this.enabled){e=this.weight;var r=this._weightInterpolant;if(null!==r){var n=r.evaluate(t)[0];e*=n,t>r.parameterPositions[1]&&(this.stopFading(),0===n&&(this.enabled=!1))}}return this._effectiveWeight=e,e},_updateTimeScale:function(t){var e=0;if(!this.paused){e=this.timeScale;var r=this._timeScaleInterpolant;null!==r&&(e*=r.evaluate(t)[0],t>r.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e))}return this._effectiveTimeScale=e,e},_updateTime:function(t){var e=this.time+t;if(0===t)return e;var r=this._clip.duration,n=this.loop,i=this._loopCount;if(2200===n){-1===i&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(e>=r)e=r;else{if(!(e<0))break t;e=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{var a=2202===n;if(-1===i&&(t>=0?(i=0,this._setEndings(!0,0===this.repetitions,a)):this._setEndings(0===this.repetitions,!0,a)),e>=r||e<0){var o=Math.floor(e/r);e-=r*o,i+=Math.abs(o);var s=this.repetitions-i;if(s<0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,e=t>0?r:0,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(0===s){var c=t<0;this._setEndings(c,!c,a)}else this._setEndings(!1,!1,a);this._loopCount=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:o})}}if(a&&1==(1&i))return this.time=e,r-e}return this.time=e,e},_setEndings:function(t,e,r){var n=this._interpolantSettings;r?(n.endingStart=2401,n.endingEnd=2401):(n.endingStart=t?this.zeroSlopeAtStart?2401:Il:2402,n.endingEnd=e?this.zeroSlopeAtEnd?2401:Il:2402)},_scheduleFading:function(t,e,r){var n=this._mixer,i=n.time,a=this._weightInterpolant;null===a&&(a=n._lendControlInterpolant(),this._weightInterpolant=a);var o=a.parameterPositions,s=a.sampleValues;return o[0]=i,s[0]=e,o[1]=i+t,s[1]=r,this}}),Object.assign(Yn.prototype,l.prototype,{_bindAction:function(t,e){var r=t._localRoot||this._root,n=t._clip.tracks,i=n.length,a=t._propertyBindings,o=t._interpolants,s=r.uuid,c=this._bindingsByRootAndName,l=c[s];void 0===l&&(l={},c[s]=l);for(var h=0;h!==i;++h){var u=n[h],d=u.name,p=l[d];if(void 0!==p)a[h]=p;else{if(void 0!==(p=a[h])){null===p._cacheIndex&&(++p.referenceCount,this._addInactiveBinding(p,s,d));continue}var f=e&&e._propertyBindings[h].binding.parsedPath;++(p=new Vn(jn.create(r,d,f),u.ValueTypeName,u.getValueSize())).referenceCount,this._addInactiveBinding(p,s,d),a[h]=p}o[h].resultBuffer=p.buffer}},_activateAction:function(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){var e=(t._localRoot||this._root).uuid,r=t._clip.uuid,n=this._actionsByClip[r];this._bindAction(t,n&&n.knownActions[0]),this._addInactiveAction(t,r,e)}for(var i=t._propertyBindings,a=0,o=i.length;a!==o;++a){var s=i[a];0==s.useCount++&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}},_deactivateAction:function(t){if(this._isActiveAction(t)){for(var e=t._propertyBindings,r=0,n=e.length;r!==n;++r){var i=e[r];0==--i.useCount&&(i.restoreOriginalState(),this._takeBackBinding(i))}this._takeBackAction(t)}},_initMemoryManager:function(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;var t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}},_isActiveAction:function(t){var e=t._cacheIndex;return null!==e&&e0?0:(Math.floor(Math.abs(a)/e.length)+1)*e.length:0===o&&a===r-1&&(a=r-2,o=1);var s,c,l,h;if(this.closed||a>0?s=e[(a-1)%r]:(Mh.subVectors(e[0],e[1]).add(e[0]),s=Mh),c=e[a%r],l=e[(a+1)%r],this.closed||a+2=0&&(i=2*Math.PI-i),i!==this.lastRotation){var a=360-Math.round(Ko.radToDeg(i));this.txt.textContent=a.toString().padStart(3,"0")+"°",this.rotateOnAxis(r,i-this.lastRotation),this.lastRotation=i}}}}();var Ah={cursorVertexShader:"\r\n#ifdef SURFACE\r\n\r\nuniform vec3 uLight;\r\nvarying vec3 vNormal;\r\nvarying vec3 lNormal;\r\n\r\n#else\r\n\t\r\nvarying vec3 vColor;\r\n\r\n#endif\r\n\r\nvarying float height;\r\n\r\nvoid main() {\r\n\r\n#ifdef SURFACE\r\n\r\n\tvNormal = normalMatrix * normal;\r\n\tlNormal = uLight;\r\n\r\n#else\r\n\r\n\tvColor = color;\r\n\r\n#endif\r\n\r\n\theight = position.z;\r\n\r\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\r\n\r\n}\r\n",cursorFragmentShader:"\r\nuniform float cursor;\r\nuniform float cursorWidth;\r\n\r\nuniform vec3 baseColor;\r\nuniform vec3 cursorColor;\r\n\r\nvarying float height;\r\n\r\n#ifdef SURFACE\r\n\r\nvarying vec3 vNormal;\r\nvarying vec3 lNormal;\r\n\r\n#else\r\n\r\nvarying vec3 vColor;\r\n\r\n#endif\r\n\r\nvoid main() {\r\n\r\n#ifdef SURFACE\r\n\r\n\tfloat nDot = dot( normalize( vNormal ), normalize( lNormal ) );\r\n\tfloat light;\r\n\tlight = 0.5 * ( nDot + 1.0 );\r\n\r\n#else\r\n\r\n\tfloat light = 1.0;\r\n\r\n#endif\r\n\r\n\tfloat delta = abs( height - cursor );\r\n\tfloat ss = smoothstep( 0.0, cursorWidth, cursorWidth - delta );\r\n\r\n\r\n#ifdef SURFACE\r\n\r\n\tif ( delta < cursorWidth * 0.05 ) {\r\n\r\n\t\tgl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 ) * light;\r\n\r\n\t} else {\r\n\r\n\t\tgl_FragColor = vec4( mix( baseColor, cursorColor, ss ) * light, 1.0 );\r\n\r\n\t}\r\n\r\n#else\r\n\r\n\tif ( delta < cursorWidth * 0.05 ) {\r\n\r\n\t\tgl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 ) * light * vec4( vColor, 1.0 );\r\n\r\n\t} else {\r\n\r\n\t\tgl_FragColor = vec4( mix( baseColor, cursorColor, ss ) * light, 1.0 ) * vec4( vColor, 1.0 );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n}\r\n",depthMapVertexShader:"\r\nuniform float minZ;\r\nuniform float scaleZ;\r\n\r\nvarying float vHeight;\r\n\r\nvoid main() {\r\n\r\n\tvHeight = ( position.z - minZ ) * scaleZ;\r\n\r\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\r\n\r\n}\r\n",depthMapFragmentShader:"\r\nconst float PackUpscale = 256. / 255.; // fraction -> 0..1 (including 1)\r\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\r\n\r\nconst float ShiftRight8 = 1. / 256.;\r\n\r\nvec4 packFloatToRGBA( const in float v ) {\r\n\r\n\tvec4 r = vec4( fract( v * PackFactors ), v );\r\n\r\n\tr.yzw -= r.xyz * ShiftRight8; // tidy overflow\r\n\r\n\treturn r * PackUpscale;\r\n\r\n}\r\n\r\nvarying float vHeight;\r\n\r\nvoid main() {\r\n\r\n\tgl_FragColor = packFloatToRGBA( vHeight );\r\n\r\n}\r\n",depthVertexShader:"const float UnpackDownscale = 255. / 256.; // 0..1 -> fraction (excluding 1)\r\n\r\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\r\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\r\n\r\nfloat unpackRGBAToFloat( const in vec4 v ) {\r\n\treturn dot( v, UnpackFactors );\r\n}\r\n\r\nuniform float minX;\r\nuniform float minY;\r\nuniform float minZ;\r\n\r\nuniform float scaleX;\r\nuniform float scaleY;\r\nuniform float rangeZ;\r\n\r\nuniform float depthScale;\r\n\r\nuniform sampler2D depthMap;\r\nuniform float datumShift;\r\n\r\n#ifdef SURFACE\r\n\r\nuniform vec3 uLight;\r\n\r\nvarying vec3 vNormal;\r\nvarying vec3 lNormal;\r\n\r\n#else\r\n\r\nvarying vec3 vColor;\r\n\r\n#endif\r\n\r\nvarying float vDepth;\r\n\r\nvoid main() {\r\n\r\n#ifdef SURFACE\r\n\r\n\tvNormal = normalMatrix * normal;\r\n\tlNormal = uLight;\r\n\r\n#else\r\n\r\n\tvColor = color;\r\n\r\n#endif\r\n\r\n\t// get terrain height in model space\r\n\r\n\tvec2 terrainCoords = vec2( ( position.x - minX ) * scaleX, ( position.y - minY ) * scaleY );\r\n\tfloat terrainHeight = unpackRGBAToFloat( texture2D( depthMap, terrainCoords ) );\r\n\r\n\tterrainHeight = terrainHeight * rangeZ + minZ + datumShift;\r\n\r\n\t// depth below terrain for this vertex, scaled in 0.0 - 1.0 range\r\n\r\n\tvDepth = ( terrainHeight - position.z ) * depthScale;\r\n\r\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\r\n\r\n}\r\n",depthFragmentShader:"\r\nuniform sampler2D cmap;\r\nvarying float vDepth;\r\n\r\n#ifdef SURFACE\r\n\r\nvarying vec3 vNormal;\r\nvarying vec3 lNormal;\r\n\r\n#else\r\n\r\nvarying vec3 vColor;\r\n\r\n#endif\r\n\r\nvoid main() {\r\n\r\n#ifdef SURFACE\r\n\r\n\tfloat nDot = dot( normalize( vNormal ), normalize( lNormal ) );\r\n\tfloat light;\r\n\tlight = 0.5 * ( nDot + 1.0 );\r\n\r\n\tgl_FragColor = texture2D( cmap, vec2( vDepth, 1.0 ) ) * light;\r\n\r\n#else\r\n\r\n\tgl_FragColor = texture2D( cmap, vec2( vDepth, 1.0 ) ) * vec4( vColor, 1.0 );\r\n\r\n#endif\r\n\r\n}\r\n",depthCursorVertexShader:"\r\nconst float UnpackDownscale = 255. / 256.; // 0..1 -> fraction (excluding 1)\r\n\r\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\r\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\r\n\r\nfloat unpackRGBAToFloat( const in vec4 v ) {\r\n\treturn dot( v, UnpackFactors );\r\n}\r\n\r\nuniform float minX;\r\nuniform float minY;\r\nuniform float minZ;\r\n\r\nuniform float scaleX;\r\nuniform float scaleY;\r\nuniform float rangeZ;\r\n\r\nuniform sampler2D depthMap;\r\nuniform float datumShift;\r\n\r\n#ifdef SURFACE\r\n\r\nuniform vec3 uLight;\r\n\r\nvarying vec3 vNormal;\r\nvarying vec3 lNormal;\r\n\r\n#else\r\n\t\r\nvarying vec3 vColor;\r\n\r\n#endif\r\n\r\nvarying float vDepth;\r\n\r\nvoid main() {\r\n\r\n#ifdef SURFACE\r\n\r\n\tvNormal = normalMatrix * normal;\r\n\tlNormal = uLight;\r\n\r\n#else\r\n\r\n\tvColor = color;\r\n\r\n#endif\r\n\r\n\tvec2 terrainCoords = vec2( ( position.x - minX ) * scaleX, ( position.y - minY ) * scaleY );\r\n\tfloat terrainHeight = unpackRGBAToFloat( texture2D( depthMap, terrainCoords ) );\r\n\r\n\tvDepth = terrainHeight * rangeZ + datumShift + minZ - position.z;\r\n\r\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n",depthCursorFragmentShader:"\r\nuniform float cursor;\r\nuniform float cursorWidth;\r\n\r\nuniform vec3 baseColor;\r\nuniform vec3 cursorColor;\r\n\r\nvarying float vDepth;\r\n\r\n#ifdef SURFACE\r\n\r\nvarying vec3 vNormal;\r\nvarying vec3 lNormal;\r\n\r\n#else\r\n\r\nvarying vec3 vColor;\r\n\r\n#endif\r\n\r\nvoid main() {\r\n\r\n\tfloat light;\r\n#ifdef SURFACE\r\n\r\n\tfloat nDot = dot( normalize( vNormal ), normalize( lNormal ) );\r\n\tlight = 0.5 * ( nDot + 1.0 );\r\n\r\n#else\r\n\r\n\tlight = 1.0;\r\n\r\n#endif\r\n\r\n\tfloat delta = abs( vDepth - cursor );\r\n\tfloat ss = smoothstep( 0.0, cursorWidth, cursorWidth - delta );\r\n\r\n#ifdef SURFACE\r\n\r\n\tif ( delta < cursorWidth * 0.05 ) {\r\n\r\n\t\tgl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 ) * light;\r\n\r\n\t} else {\r\n\r\n\t\tgl_FragColor = vec4( mix( baseColor, cursorColor, ss ) * light, 1.0 );\r\n\r\n\t}\r\n\r\n#else\r\n\r\n\tif ( delta < cursorWidth * 0.05 ) {\r\n\r\n\t\tgl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 ) * light * vec4( vColor, 1.0 );\r\n\r\n\t} else {\r\n\r\n\t\tgl_FragColor = vec4( mix( baseColor, cursorColor, ss ) * light, 1.0 ) * vec4( vColor, 1.0 );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n}",extendedPointsVertexShader:"uniform float size;\r\nuniform float scale;\r\nuniform float pScale;\r\n\r\nattribute float pSize;\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\t#ifdef USE_SIZEATTENUATION\r\n\t\tgl_PointSize = pScale * pSize * ( scale / - mvPosition.z );\r\n\t#else\r\n\t\tgl_PointSize = pScale * pSize;\r\n\t#endif\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",extendedPointsFragmentShader:"uniform vec3 diffuse;\r\nuniform float opacity;\r\n\r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n#include \r\n\r\nvoid main() {\r\n\r\n\t#include \r\n\r\n\tvec3 outgoingLight = vec3( 0.0 );\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n\toutgoingLight = diffuseColor.rgb;\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include \r\n\t#include \r\n\t#include \r\n\t#include \r\n\r\n}\r\n",glyphVertexShader:"\r\n\r\n// glyph shader, each instance represents one glyph.\r\n\r\nuniform float cellScale;\r\nuniform mat2 rotate;\r\nuniform float scale;\r\n\r\nattribute vec2 instanceUvs;\r\nattribute float instanceOffsets;\r\nattribute float instanceWidths;\r\n\r\nvarying vec2 vUv;\r\nvarying vec3 vColor;\r\n\r\nvoid main() {\r\n\r\n\tvColor = color;\r\n\r\n\t// select glyph from atlas ( with proportional spacing ).\r\n\r\n\tvUv = instanceUvs + vec2( position.x * cellScale * instanceWidths, position.y * cellScale );\r\n\r\n\t// scale by glyph width ( vertices form unit square with (0,0) origin )\r\n\r\n\tvec2 newPosition = vec2( position.x * instanceWidths, position.y );\r\n\r\n\t// move to correct offset in string\r\n\r\n\tnewPosition.x += instanceOffsets;\r\n\r\n\t// rotate as required\r\n\r\n\tnewPosition = rotate * newPosition;\r\n\r\n\t// position of GlyphString object on screeno\r\n\r\n\tvec4 offset = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\r\n\r\n\t// scale glyphs\r\n\r\n\tnewPosition.xy *= 0.0625;\r\n\r\n\t// correct for aspect ratio\r\n\r\n\tnewPosition.x *= scale;\r\n\r\n\t// move to clip space\r\n\r\n\tnewPosition.xy *= offset.w;\r\n\r\n\tgl_Position = vec4( newPosition, 0.0, 0.0 ) + offset;\r\n\r\n}\r\n",glyphFragmentShader:"\r\nuniform sampler2D atlas;\r\n\r\nvarying vec2 vUv;\r\nvarying vec3 vColor;\r\n\r\nvoid main() {\r\n\r\n\tgl_FragColor = texture2D( atlas, vUv ) * vec4( vColor, 1.0 );\r\n\r\n}",heightVertexShader:"\r\nuniform sampler2D cmap;\r\n\r\nuniform float minZ;\r\nuniform float scaleZ;\r\n\r\n#ifdef SURFACE\r\n\r\nuniform vec3 uLight;\r\n\r\nvarying vec3 vNormal;\r\nvarying vec3 lNormal;\r\n\r\n#else\r\n\r\nvarying vec3 vColor;\r\n\r\n#endif\r\n\r\nvarying float zMap;\r\n\r\nvoid main() {\r\n\r\n#ifdef SURFACE\r\n\r\n\tvNormal = normalMatrix * normal;\r\n\tlNormal = uLight;\r\n\r\n#else\r\n\r\n\tvColor = color;\r\n\r\n#endif\r\n\r\n\tzMap = ( position.z - minZ ) * scaleZ;\r\n\r\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\r\n\r\n}\r\n",heightFragmentShader:"\r\nuniform sampler2D cmap;\r\n\r\nvarying float zMap;\r\n\r\n#ifdef SURFACE\r\n\r\nvarying vec3 vNormal;\r\nvarying vec3 lNormal;\r\n\r\n#else\r\n\r\nvarying vec3 vColor;\r\n\r\n#endif\r\n\r\nvoid main() {\r\n\r\n#ifdef SURFACE\r\n\r\n\tfloat nDot = dot( normalize( vNormal ), normalize( lNormal ) );\r\n\tfloat light;\r\n\tlight = 0.5 * ( nDot + 1.0 );\r\n\r\n\tgl_FragColor = texture2D( cmap, vec2( 1.0 - zMap, 1.0 ) ) * vec4( light, light, light, 1.0 );\r\n\r\n#else\r\n\r\n\tgl_FragColor = texture2D( cmap, vec2( 1.0 - zMap, 1.0 ) ) * vec4( vColor, 1.0 );\r\n\r\n#endif\r\n\r\n}\r\n",waterVertexShader:"\r\nattribute vec3 sinks;\r\n\r\nvarying vec3 vPosition;\r\nvarying vec3 vSink;\r\n\r\nvoid main() {\r\n\r\n\tvPosition = position;\r\n\tvSink = sinks;\r\n\r\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\r\n\r\n}\r\n",waterFragmentShader:"\r\nuniform float offset;\r\n\r\nvarying vec3 vPosition;\r\nvarying vec3 vSink;\r\n\r\nvoid main() {\r\n\r\n\tgl_FragColor = vec4( 0.1, 0.1, sin( offset + distance( vPosition, vSink ) ) * 0.4 + 0.6, 0.0 );\r\n\r\n}\r\n"};xi.prototype=Object.create(at.prototype),xi.prototype.constructor=xi,xi.prototype.setCursor=function(t){var e=Math.max(Math.min(t,this.halfRange),-this.halfRange);return this.uniforms.cursor.value=e,e},xi.prototype.getCursor=function(){return this.uniforms.cursor.value},bi.prototype=Object.create(at.prototype),bi.prototype.constructor=bi,bi.prototype.setDatumShift=function(t){this.uniforms.datumShift.value=t},wi.prototype=Object.create(at.prototype),wi.prototype.constructor=wi,wi.prototype.setCursor=function(t){var e=Math.max(Math.min(t,this.max),0);return this.uniforms.cursor.value=e,e},wi.prototype.getCursor=function(){return this.uniforms.cursor.value},wi.prototype.setDatumShift=function(t){this.uniforms.datumShift.value=t},_i.prototype=Object.create(at.prototype),_i.prototype.constructor=_i,Mi.prototype=Object.create(at.prototype),Mi.prototype.constructor=Mi,Ei.prototype.constructor=Ei,Ei.prototype.getTexture=function(){return this.texture},Ei.prototype.getCellScale=function(){return this.cellScale},Ei.prototype.getGlyph=function(t){var e=this.map[t];return void 0===e&&(console.warn("unavailable glyph ["+t+"]",t.codePointAt()),e=this.map["☐"]),e};var Lh={},Ch={};Ch.getAtlas=function(t){var e=Lh[t];return void 0===e&&(e=new Ei(t),Lh[t]=e),e},Si.prototype=Object.create(at.prototype),Si.prototype.constructor=Si,Si.prototype.getAtlas=function(){return this.atlas};var Rh,Ph=new Map,Ih=[],Oh=[],Nh={},Dh={getHeightMaterial:Ci,getDepthMapMaterial:Ri,getDepthMaterial:Pi,getDepthCursorMaterial:Oi,getCursorMaterial:Ii,getSurfaceMaterial:Ni,getLineMaterial:Di,getGlyphMaterial:Ui,setTerrain:zi,initCache:Bi,flushCache:Fi};ki.prototype=Object.create(Bt.prototype),Object.assign(ki.prototype,s.prototype),ki.prototype.constructor=ki,ki.prototype.setRange=function(t,e,r){return this.maxDiv.textContent=Math.round(e)+"m",this.minDiv.textContent=Math.round(t)+"m",this.setCaption(r),this},ki.prototype.setCaption=function(t){return this.caption.textContent=t,this},ki.prototype.setMaterial=function(t){return this.material=t,this},Gi.prototype=Object.create(Bt.prototype),Object.assign(Gi.prototype,s.prototype),Gi.prototype.constructor=Gi,Gi.prototype.setRange=function(t,e,r){return this.maxDiv.textContent=Math.round(e)+"m",this.minDiv.textContent=Math.round(t)+"m",this.caption.textContent=r,this},Gi.prototype.setCursor=function(t){return this.cursor.position.setY(this.barHeight*t),this},Vi.prototype=Object.create(Bt.prototype),Object.assign(Vi.prototype,s.prototype),Vi.prototype.constructor=Vi,Vi.prototype.set=function(t){this.progress=t;for(var e=2*Math.floor(Math.min(100,Math.round(t))/2),r=this.geometry.faces,n=0;n=3?i*Math.pow(10,s-3)+"km":i*Math.pow(10,s)+"m",t*=Math.pow(10,s),this.currentLength!==i){if(!r[i]){var l=function(t){var e,r,i=t*a.hScale,o=new It(i,4,t),s=new It(i,4,10*t),c=new _t;c.vertices.push(new n(-i/2,0,1)),c.vertices.push(new n(i/2,0,1));var l=new Bt(o,new Nt({color:16777215,vertexColors:ec,side:Zs})),h=new Bt(s,new Nt({color:16777215,vertexColors:ec,side:Zs})),u=new Pe(c,new Ce({color:16711680}));for(e=0,r=o.faces.length;e0&&(r[this.currentLength].mesh.visible=!1),r[i].mesh.visible=this.visible,this.currentLength=i}r[i].mesh.scale.x=t;var h=this.legend;return h.style.display=this.visible?"block":"none",h.style.left=t*r[i].topRight-h.clientWidth+"px",h.textContent=e,this};var Uh,zh,Bh,Fh,kh,Gh,Vh,Hh,jh,Wh=0,Xh=null,Yh=null,qh=null,Zh=null,Jh=!0,Qh={init:ji,renderHUD:Qi,update:Ji,setVisibility:Wi,getVisibility:Xi,getProgressDial:Yi,setScale:qi};na.prototype.constructor=na,na.prototype.prepare=function(t,e){if(0===this.frameCount){if(this.skipNext=!1,e&&e.isBox3){var r,n=e.getSize(),i=this.controls.object;if(e=e.getCenter(),i.isPerspectiveCamera){var a=Math.tan(.5*Ko.DEG2RAD*i.getEffectiveFOV()),o=1.5*a*n.y/2+n.z,s=a*i.aspect*n.x/2+n.z;r=Math.max(o,s),this.targetZoom=1,0===r&&(r=100)}else{var c=(i.right-i.left)/n.x,l=(i.top-i.bottom)/n.y;this.targetZoom=Math.min(c,l),r=600}(t=e.clone()).z=t.z+r}this.cameraTarget=t,this.targetPOI=e,this.moveRequired=null!==this.cameraTarget||null!==this.targetPOI;var h=this.controls.target,u=this.controls.object.position;if(null!==t)if(t.equals(u))this.moveRequired=!1,null===e&&(this.skipNext=!0);else{null===e&&(e=h);var d=u.distanceTo(t),p=this.getControlPoint(h,u,t,d),f=this.getControlPoint(e,t,u,d);this.curve=new fi(u,p,f,t)}}},na.prototype.getControlPoint=function(t,e,r,i){for(var a=new n,o=new n,s=new n,c=0;0===c;)a.copy(e).sub(t),o.copy(r).sub(t),s.crossVectors(a,o),0===(c=s.length())&&t.addScalar(-1);var l=(new n).crossVectors(s,a).setLength(Math.min(i,a.length())/3),h=(new n).copy(l).add(a),u=(new n).copy(l).negate().add(a);return o.distanceTo(h)0},ia.prototype.constructor=ia,ia.prototype.traverse=function(t){var e=this.children;t(this);for(var r=0;r0;){r=!1;for(var n=0,i=e.children.length;n0;)n=new ia(t.shift(),null,this.root,r),r.children.push(n),r=n;return void 0!==e&&Object.assign(r,e),r},ia.prototype.getPath=function(t){var e=this,r=[];void 0===t&&(t=this.root);do{r.push(e.name),e=e.parent}while(e!==t);return r.reverse().join(".")},ia.prototype.getSubtreeIds=function(t,e){function r(t){e.add(t.id)}this.findById(t).traverse(r)},ia.prototype.getIdByPath=function(t){var e=this.getByPathArray(t);return 0===t.length?e.id:void 0},aa.prototype.type="Box3Helper",aa.prototype=Object.create(Pe.prototype),aa.prototype.constructor=aa,aa.prototype.update=function(t){if(this.box3=t,!t.isEmpty()){var e=t.min,r=t.max,n=this.geometry.attributes.position,i=n.array;i[0]=r.x,i[1]=r.y,i[2]=r.z,i[3]=e.x,i[4]=r.y,i[5]=r.z,i[6]=e.x,i[7]=e.y,i[8]=r.z,i[9]=r.x,i[10]=e.y,i[11]=r.z,i[12]=r.x,i[13]=r.y,i[14]=e.z,i[15]=e.x,i[16]=r.y,i[17]=e.z,i[18]=e.x,i[19]=e.y,i[20]=e.z,i[21]=r.x,i[22]=e.y,i[23]=e.z,n.needsUpdate=!0,this.geometry.computeBoundingSphere()}},aa.prototype.removed=function(){this.geometry&&this.geometry.dispose()},oa.indexAttribute=null,oa.positionAttribute=null,oa.prototype=Object.assign(Object.create(Zn.prototype),{constructor:oa}),sa.prototype=Object.assign(Object.create(Bt.prototype),{constructor:sa,isGlyphString:!0,getWidth:function(){return this.geometry.width}}),ca.prototype=Object.create(Ne.prototype),ca.prototype.constructor=ca;var Kh=new n,$h=new n,tu=new n,eu=new n,ru=new zt(Kh,$h,tu),nu=new zt(Kh,tu,eu),iu=[];ua.prototype.addNode=function(t,e){var r=0,n=t.position;if(this.markers.push(t),this.centroid.add(t.position),this.count++,0!=e--){var i=(this.xMin+this.xMax)/2,a=(this.yMin+this.yMax)/2;n.x>i&&(r+=1),n.y>a&&(r+=2);var o=this.nodes[r];if(void 0===o){switch(r){case 0:o=new ua(this.xMin,i,this.yMin,a);break;case 1:o=new ua(i,this.xMax,this.yMin,a);break;case 2:o=new ua(this.xMin,i,a,this.yMax);break;case 3:o=new ua(i,this.xMax,a,this.yMax)}this.nodes[r]=o}o.addNode(t,e)}},ua.prototype.check=function(t){for(var e,r=0;r<4;r++)if(void 0!==(e=this.nodes[r])){if(e.count<2){this.nodes[r]=void 0;continue}e.projectedArea(t)<.8?e.clusterMarkers(t):(e.showMarkers(),e.check(t))}},ua.prototype.showMarkers=function(){for(var t=this.markers,e=0,r=t.length;e2?(this.colors[e.stationVertexIndex]=this.junctionColor,this.pointSizes[e.stationVertexIndex]=4):e.hitCount>0&&(this.pointSizes[e.stationVertexIndex]=2))},fa.prototype.finalise=function(){var t=this.geometry,e=new Tt(3*this.vertices.length,3),r=new Tt(3*this.colors.length,3);t.addAttribute("pSize",new Tt(this.pointSizes,1)),t.addAttribute("position",e.copyVector3sArray(this.vertices)),t.addAttribute("color",r.copyColorsArray(this.colors)),this.pointSizes=null,this.vertices=null,this.colors=null},fa.prototype.setScale=function(t){this.material.uniforms.pScale.value=t,this.material.needsUpdate=!0};var au=new n;ma.prototype=Object.create(De.prototype),ma.prototype.constructor=ma,ma.prototype.addStation=function(t){var e;e=0===t.hitCount?this.splayLabelMaterial:t.hitCount<3?this.defaultLabelMaterial:this.junctionLabelMaterial;var r=new sa(t.name,e);r.layers.set(Ns),r.position.copy(t.p),r.hitCount=t.hitCount,r.visible=!1,this.add(r)},ma.prototype.update=function(t,e,r){var n=au.copy(t.position);t.isOrthographicCamera&&(n.sub(e),n.setLength(ns/t.zoom),n.add(e)),n.applyMatrix4(r);for(var i,a,o=t.layers.mask&1<2||o+20)return cu;cu=[];var n=0===(lu=e)?t.id:lu,i=t.findById(n),a=this.getSurveyColour(n);r(i);for(var o=i.children;1===o.length;)r(i=o[0]),o=i.children;for(var s=0,c=o.length;s0){var a=Math.sqrt(n/i-Math.pow(r/i,2));t.datumShift=r/i,console.log("Adjustmenting terrain height by ",t.datumShift,a)}null===this.terrain&&(this.terrain=t)},Ra.prototype.loadCave=function(t){var e=this;!function(t){function r(t){Object.assign(t,ia.prototype)}void 0===t.forEachChild&&(r(t),t.forEachChild(r,!0)),null===e.surveyTree?e.surveyTree=t:e.surveyTree.children.push(t)}(t.surveyTree),function(t){function r(t,r){var n=i[t];if(0!==n.vertices.length){var a=e.getFeature(t,xa);a.addLegs(n.vertices,n.colors,n.runs),e.addFeature(a,t,r+":g")}}var i=[];i[Ms]={vertices:[],colors:[],runs:[]},i[Ss]={vertices:[],colors:[],runs:[]},i[Es]={vertices:[],colors:[],runs:[]};var a,o,s,c,l=t.length;if(0===l)return null;for(var h,u,d=new n,p=0;pt.clientWidth||r+c.clientHeight>t.clientHeight?s():(c.style.left=e+"px",c.style.top=r+"px")}function s(){t.removeChild(c),t.removeEventListener("mousemove",o),t.removeEventListener("mouseup",s)}var c=this.div,l=new n;c.style.left=e+"px",c.style.top=r+"px",t.appendChild(c),t.addEventListener("mouseup",s),t.addEventListener("mousemove",o)},Pa.prototype.addLine=function(t){var e=document.createElement("div");return e.textContent=t,this.div.appendChild(e),this},Ia.prototype=Object.create(Pa.prototype),Ia.prototype.constructor=Ia;var vu=new n,yu=new n,xu=new n,bu=new n,wu=new zt(vu,yu,xu),_u=new zt(vu,xu,bu);Na.liveTiles=0,Na.prototype=Object.create(Bt.prototype),Na.prototype.constructor=Na,Na.prototype.type="Tile",Na.prototype.isTile=!0,Na.prototype.createFromBufferAttributes=function(t,e,r,i){var a,o,s=this.geometry;for(a in e)o=e[a],s.addAttribute(a,new Tt(o.array,o.itemSize));s.setIndex(new Et(t,1)),s.boundingBox=new st(new n(r.min.x,r.min.y,r.min.z),new n(r.max.x,r.max.y,r.max.z)),e=s.attributes;for(var c in e)e[c].onUpload(Oa);return this.geometry.index.onUpload(Oa),this.layers.set(Cs),this.material=i,this},Na.prototype.getWorldBoundingBox=function(){var t;return null===this.worldBoundingBox&&(this.updateMatrixWorld(),(t=this.getBoundingBox().clone()).applyMatrix4(this.matrixWorld),this.worldBoundingBox=t),this.worldBoundingBox},Na.prototype.getBoundingBox=function(){var t;if(null===this.boundingBox){(t=this.geometry.boundingBox.clone()).min.x+=5,t.min.y+=5,t.max.x-=5,t.max.y-=5,this.boundingBox=t}return this.boundingBox},Na.prototype.empty=function(){this.isMesh=!1,this.boundingBox||(console.warn("FIXUP :",this.x,this.y),this.getWorldBoundingBox()),this.geometry&&(this.geometry.dispose(),this.geometry=new Ct),--Na.liveTiles},Na.prototype.evict=function(){this.evictionCount++,this.evicted=!0,this.replaced=!1,this.empty()},Na.prototype.setReplaced=function(){this.evicted=!1,this.replaced=!0,this.empty()},Na.prototype.setPending=function(t){t&&null===this.parent&&t.add(this),this.parent.childrenLoading++,this.isMesh=!1,this.evicted=!1},Na.prototype.setFailed=function(){var t=this.parent;t.childErrors++,t.childrenLoading--,t.canZoom=!1,t.remove(this)},Na.prototype.setLoaded=function(t,e,r){function n(t){t.isMesh=!0,Na.liveTiles++,0==--a&&r()}var i=this.parent,a=0;if(0==--i.childrenLoading){if(0===i.childErrors){i.isTile&&i.setReplaced();for(var o=i.children,s=0,c=o.length;s=t.minX&&e.max_x<=t.maxX&&e.min_y>=t.minY&&e.max_y<=t.maxY)return t.directory=i+t.subdirectory,this.tileSet=t,!0;return!1},Da.prototype.getCoverage=function(t,e){var r={zoom:e},n=Mu,i=-Mu,a=Math.pow(2,e-1)/Mu;return r.min_x=Math.floor((t.min.x-i)*a),r.max_x=Math.floor((t.max.x-i)*a),r.max_y=Math.floor((n-t.min.y)*a),r.min_y=Math.floor((n-t.max.y)*a),r.count=(r.max_x-r.min_x+1)*(r.max_y-r.min_y+1),r},Da.prototype.pickCoverage=function(t){var e,r=this.tileSet,n=r.maxZoom+1;do{--n,e=this.getCoverage(t,n)}while(e.count>4&&n>r.minZoom);return e},Da.prototype.loadTile=function(t,e,r,n,i){function a(t){var e=t.data;return c.workerPool.putWorker(b),--c.tilesLoading,c.dying?void c.progressDial.end():"ok"!==e.status||0!==y.parent.childErrors?(y.setFailed(),void(c.progressDial&&c.progressDial.end())):(c.progressDial&&c.progressDial.add(c.progressInc),y.createFromBufferAttributes(e.index,e.attributes,e.boundingBox,c.material),c.progressDial&&c.progressDial.add(c.progressInc),y.setLoaded(c.activeOverlay,c.opacity,c.onLoaded)&&c.progressDial&&c.progressDial.end(),void(c.terrainLoaded=!0))}var o=this.tileSet,s=r>o.dtmMaxZoom?Math.pow(2,o.dtmMaxZoom-r):1;if(1===s||null!==this.activeOverlay||null===this.currentZoom){console.log("load: [ ",r+"/"+t+"/"+e,"]");var c=this,l=this.limits,h=Mu/Math.pow(2,r-1),u={top:0,bottom:0,left:0,right:0},d=h*t-Mu,p=d+h,f=Mu-h*e,m=f-h,g=o.divisions*s,v=h/g;++this.tilesLoading,f>l.max.y&&(u.top=Math.floor((f-l.max.y)/v)),ml.max.x&&(u.right=Math.floor((p-l.max.x)/v));var y=n||new Na(t,e,r,c.tileSet,u),x=i||this;y.setPending(x);var b=this.workerPool.getWorker();b.onmessage=a,b.postMessage({tileSet:o,divisions:g,resolution:v,x:t,y:e,z:r,clip:u,offsets:this.offsets})}},Da.prototype.resurrectTile=function(t){if(t.isMesh)return void console.warn("resurrecting the undead!");this.loadTile(t.x,t.y,t.zoom,t)},Da.prototype.tileArea=function(t,e){var r=this.pickCoverage(t),n=r.zoom;if(e&&e.zoom==n)return void console.error("ERROR - looping on tile replacement");this.currentLimits=t,null===this.initialZoom&&(this.initialZoom=n);for(var i=r.min_x;i0&&void 0!==this.progressDial&&(this.progressDial.start("Loading "+this.tilesLoading+" terrain tiles"),this.progressInc=100/(2*this.tilesLoading)),this.currentZoom=n},Da.prototype.setDefaultOverlay=function(t){this.defaultOverlay=t},Da.prototype.setOverlay=function(t,e){function r(e){e.isTile&&(e.setOverlay(t,i.opacity,n),i.overlaysLoading++)}function n(){0==--i.overlaysLoading&&e()}if(!(this.tilesLoading>0)){var i=this,a=this.activeOverlay;if(null!==a){if(a===t)return;a.flushCache(),a.hideAttribution()}this.activeOverlay=t,this.defaultOverlay=t,t.showAttribution(),this.traverse(r)}},Da.prototype.removed=function(){function t(t){t!==e&&t.removed(t)}if(this.dying=!0,!(this.tilesLoading>0)){var e=this;this.traverse(t),this.commonRemoved()}},Da.prototype.setMaterial=function(t){function e(e){e.isTile&&e.setMaterial(t)}this.tilesLoading>0||(this.traverse(e),this.activeOverlay=null,t.opacity=this.opacity,t.needsUpdate=!0,this.material=t)},Da.prototype.setOpacity=function(t){function e(e){e.isTile&&e.setOpacity(t)}this.shadingMode===ys?this.traverse(e):this.material&&(this.material.opacity=t,this.material.needsUpdate=!0),this.opacity=t},Da.prototype.zoomCheck=function(t){function r(e){e!==c&&e.isTile&&(l.intersectsBox(e.getWorldBoundingBox())?0===e.children.length?e.isMesh?e.canZoom&&h.push({tile:e,area:e.projectedArea(t)}):d.push(e):(e.isMesh||!e.evicted||this.parent.resurrectionPending||(e.resurrectionPending=!0,d.push(e)),e.parent.ResurrectionPending&&this.isMesh&&console.warn(" should not get here")):e.isMesh&&u.push(e))}var n,i,a,o=this.tileSet.maxZoom,s=this.initialZoom,c=this,l=new ut,h=[],u=[],d=[],p=!1;if(this.tilesLoading>0)return!0;t.updateMatrix(),t.updateMatrixWorld(),t.matrixWorldInverse.getInverse(t.matrixWorld),l.setFromMatrix((new e).multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse)),this.traverse(r);var f=d.length,m=h.length;if(function(){function t(t,e){return t.evictionCount/t.zoom-e.evictionCount/e.zoom}var e,r=u.length;if(0!==r)for(u.sort(t),e=0;en.evictionCount*Math.pow(2,s-n.zoom)&&n.evict()}}(),0!==f){for(this.progressDial&&this.progressDial.start("Resurrecting tiles"),a=0;a.3&&(i=h[a].tile).zoomthis.slideDepth?(o.addEventListener("transitionend",n),o.classList.add("slide-out"),o.clientHeight):e1&&b.push(E),(E=[]).push({coords:t}),!0)}function d(){var t=I();return E.push({coords:t,type:Ms,survey:A}),R=t,!0}function p(){return console.log("LINE_V2"),!1}function f(){var r=new DataView(t,e),n=_.projection.forward({x:r.getInt32(0,!0)/100,y:r.getInt32(4,!0)/100}),i={x:n.x,y:n.y,z:r.getInt32(8,!0)/100};return O.x=Math.min(i.x,O.x),O.y=Math.min(i.y,O.y),O.z=Math.min(i.z,O.z),N.x=Math.max(i.x,N.x),N.y=Math.max(i.y,N.y),N.z=Math.max(i.z,N.z),e+=12,i}function m(){var r=new DataView(t,e),n={x:r.getInt32(0,!0)/100,y:r.getInt32(4,!0)/100,z:r.getInt32(8,!0)/100};return O.x=Math.min(n.x,O.x),O.y=Math.min(n.y,O.y),O.z=Math.min(n.z,O.z),N.x=Math.max(n.x,N.x),N.y=Math.max(n.y,N.y),N.z=Math.max(n.z,N.z),e+=12,n}var g,v,y,x,b=this.groups,w=this.surveyTree,_=this,M=[],E=[],S="",T=new Map,A=0,L=new Uint8Array(t,0),C=L.length,R={x:0,y:0,z:0},P=new DataView(t,0),I=null===this.projection?m:f,O={x:1/0,y:1/0,z:1/0},N={x:-1/0,y:-1/0,z:-1/0};for(g=0;g<256;g++)M[g]=n;for(M[0]=a,M[-1]=a,M[1]=o,M[2]=s,M[3]=s,M[4]=u,M[5]=d,M[6]=c,M[7]=l,g=64;g<128;g++)M[g]=h;for(g=128;g<256;g++)M[g]=p;if(1===r)for(;e>4,i=15&n):(255!==(n=H[e++])?a=n:(a=new DataView(t,e).getUint32(0,!0),e+=4),255!==(n=H[e++])?i=n:(i=new DataView(t,e).getUint32(0,!0),e+=4)),0!==i||0!==a){if(a&&(z=z.slice(0,-a)),i){for(var o=[],s=0;s1&&P.push(U),U=[],F.add(W.x+":"+W.y+":"+W.z);var t=Y();return U.push({coords:t}),W=t,!0}function _(){return e+=20,!0}function M(t){var r=127&t;if(R(0),!(14&r)||32&r)return e+=12,!0;var n=Y(),i=z.split("."),a=i.slice(0,-1).join(".");if(i.length>1&&!V.has(a)){for(var o=0,s=i[o];V.has(s);)s=s+"."+i[++o];var c=i.slice(o).join(".");(i=i.slice(0,o)).push(c)}return B.set(z,n),O.addPath(i,{p:n,type:4&r?Us:Ds}),!0}function E(r){var n=1&r;R(n);var i=new DataView(t,e);return e+=8,T(n,{l:i.getInt16(0,!0)/100,r:i.getInt16(2,!0)/100,u:i.getInt16(4,!0)/100,d:i.getInt16(6,!0)/100})}function S(r){var n=1&r;R(n);var i=new DataView(t,e);return e+=16,T(n,{l:i.getInt32(0,!0)/100,r:i.getInt32(0,!0)/100,u:i.getInt32(0,!0)/100,d:i.getInt32(0,!0)/100})}function T(t,e){var r=B.get(z);if(r){var n=z.split(".");n.pop();var i=O.getIdByPath(n);k.push({start:W,end:r,lrud:e,survey:i}),W=r;var a=!1;return t?a=!0:F.has([r.x,r.y,r.z].toString())&&(a=!0),a&&(k.length>0&&I.push(k),W={x:0,y:0,z:0},k=[]),!0}}function A(){var r=new DataView(t,e),n=N.projection.forward({x:r.getInt32(0,!0)/100,y:r.getInt32(4,!0)/100}),i={x:n.x,y:n.y,z:r.getInt32(8,!0)/100};return q.x=Math.min(i.x,q.x),q.y=Math.min(i.y,q.y),q.z=Math.min(i.z,q.z),Z.x=Math.max(i.x,Z.x),Z.y=Math.max(i.y,Z.y),Z.z=Math.max(i.z,Z.z),e+=12,i}function L(){var r=new DataView(t,e),n={x:r.getInt32(0,!0)/100,y:r.getInt32(4,!0)/100,z:r.getInt32(8,!0)/100};return q.x=Math.min(n.x,q.x),q.y=Math.min(n.y,q.y),q.z=Math.min(n.z,q.z),Z.x=Math.max(n.x,Z.x),Z.y=Math.max(n.y,Z.y),Z.z=Math.max(n.z,Z.z),e+=12,n}var C,R,P=this.groups,I=this.xGroups,O=this.surveyTree,N=this,D=[],U=[],z="",B=new Map,F=new Set,k=[],G=0,V=new Set,H=new Uint8Array(t,0),j=H.length,W={x:0,y:0,z:0},X=!1,Y=null===this.projection?L:A,q={x:1/0,y:1/0,z:1/0},Z={x:-1/0,y:-1/0,z:-1/0};for(C=0;C<256;C++)D[C]=n;if(8===r){for(D[0]=m,D[1]=m,D[2]=m,D[3]=m,D[4]=m,D[15]=w,D[16]=x,D[17]=g,D[18]=v,D[19]=y,D[31]=_,D[48]=E,D[49]=E,D[50]=S,D[51]=S,C=64;C<128;C++)D[C]=b;for(C=128;C<256;C++)D[C]=M;R=o,e++}else{for(C=1;C<15;C++)D[C]=c;for(D[15]=w,C=16;C<32;C++)D[C]=l;for(D[0]=s,D[32]=u,D[33]=f,D[35]=d,D[36]=x,D[34]=_,D[48]=E,D[49]=E,D[50]=S,D[51]=S,C=64;C<128;C++)D[C]=M;for(C=128;C<192;C++)D[C]=b;R=a}for(6===r&&(D[32]=h,D[33]=p);e1&&I.push(k),P.push(U);var J={x:(q.x+Z.x)/2,y:(q.y+Z.y)/2,z:(q.z+Z.z)/2};O.traverse(i),this.offsets=J,this.limits={min:q,max:Z}},To.prototype.getLineSegments=function(){for(var t=[],e=this.groups,r=this.offsets,n=0,i=e.length;n":is,Plan:as,"N Elevation":os,"S Elevation":ss,"E Elevation":cs,"W Elevation":ls},_d={Orthographic:es,Perspective:rs},Md={init:Po,loadCave:Xo,loadCaveList:jo};t.setEnvironment=i,t.Viewer=ed,t.UI=Md,t.CaveLoader=Ro,t.VERSION=$o,t.MATERIAL_LINE=ts,t.MATERIAL_SURFACE=2,t.CAMERA_ORTHOGRAPHIC=es,t.CAMERA_PERSPECTIVE=rs,t.CAMERA_OFFSET=ns,t.VIEW_NONE=is,t.VIEW_PLAN=as,t.VIEW_ELEVATION_N=os,t.VIEW_ELEVATION_S=ss,t.VIEW_ELEVATION_E=cs,t.VIEW_ELEVATION_W=ls,t.MOUSE_MODE_NORMAL=hs,t.MOUSE_MODE_ROUTE_EDIT=us,t.SHADING_HEIGHT=ds,t.SHADING_LENGTH=ps,t.SHADING_INCLINATION=fs,t.SHADING_CURSOR=ms,t.SHADING_SINGLE=gs,t.SHADING_SURVEY=vs,t.SHADING_OVERLAY=ys,t.SHADING_SHADED=xs,t.SHADING_DEPTH=bs,t.SHADING_PATH=ws,t.SHADING_DEPTH_CURSOR=_s,t.LEG_CAVE=Ms,t.LEG_SPLAY=Es,t.LEG_SURFACE=Ss,t.FEATURE_BOX=Ts,t.FEATURE_SELECTED_BOX=As,t.FEATURE_ENTRANCES=Ls,t.FEATURE_TERRAIN=Cs,t.FEATURE_STATIONS=Rs,t.FEATURE_TRACES=Ps,t.FACE_WALLS=Is,t.FACE_SCRAPS=Os,t.LABEL_STATION=Ns,t.NORMAL=0,t.SURFACE=1,t.SPLAY=2,t.DIVING=3,t.STATION_NORMAL=Ds,t.STATION_ENTRANCE=Us,t.upAxis=zs,Object.defineProperty(t,"__esModule",{value:!0})});