diff --git a/dist/kaleidoscope.es.js b/dist/kaleidoscope.es.js index f7783c9..ed57eca 100644 --- a/dist/kaleidoscope.es.js +++ b/dist/kaleidoscope.es.js @@ -1492,9 +1492,6 @@ var Renderer = function () { this.renderer.setSize(this.width, this.height); this.renderer.setPixelRatio(Math.floor(window.devicePixelRatio)); this.el = this.renderer.domElement; - - this.target = this.container ? this.container : document.querySelector(this.containerId); - this.target.appendChild(this.el); } createClass(Renderer, [{ @@ -1530,6 +1527,8 @@ var Renderer = function () { var MouseControls = function () { function MouseControls(camera, renderer) { + var _this = this; + classCallCheck(this, MouseControls); this.camera = camera; @@ -1545,35 +1544,43 @@ var MouseControls = function () { this.euler = new THREE.Euler(); this.isUserInteracting = false; this.addDraggableStyle(); + this.onMouseMove = this.onMouseMove.bind(this); + this.onMouseDown = this.onMouseDown.bind(this); + this.onMouseUp = this.onMouseUp.bind(this); + this.onTouchStart = function (e) { + return _this.onMouseDown({ clientX: e.touches[0].pageX, clientY: e.touches[0].pageY }); + }; + this.onTouchMove = function (e) { + return _this.onMouseMove({ clientX: e.touches[0].pageX, clientY: e.touches[0].pageY }); + }; + this.onTouchEnd = function (e) { + return _this.onMouseUp({ clientX: e.touches[0].pageX, clientY: e.touches[0].pageY }); + }; + this.onDeviceMotion = this.onDeviceMotion.bind(this); this.bindEvents(); } createClass(MouseControls, [{ key: 'bindEvents', value: function bindEvents() { - var _this = this; - - this.el.addEventListener('mousemove', function (e) { - return _this.onMouseMove(e); - }); - this.el.addEventListener('mousedown', function (e) { - return _this.onMouseDown(e); - }); - this.el.addEventListener('mouseup', function (e) { - return _this.onMouseUp(e); - }); - this.el.addEventListener('touchstart', function (e) { - return _this.onMouseDown({ clientX: e.touches[0].pageX, clientY: e.touches[0].pageY }); - }); - this.el.addEventListener('touchmove', function (e) { - return _this.onMouseMove({ clientX: e.touches[0].pageX, clientY: e.touches[0].pageY }); - }); - this.el.addEventListener('touchend', function (e) { - return _this.onMouseUp(); - }); - window.addEventListener('devicemotion', function (e) { - return _this.onDeviceMotion(e); - }); + this.el.addEventListener('mousemove', this.onMouseMove); + this.el.addEventListener('mousedown', this.onMouseDown); + this.el.addEventListener('mouseup', this.onMouseUp); + this.el.addEventListener('touchstart', this.onTouchStart); + this.el.addEventListener('touchmove', this.onTouchMove); + this.el.addEventListener('touchend', this.onTouchEnd); + window.addEventListener('devicemotion', this.onDeviceMotion); + } + }, { + key: 'destroy', + value: function destroy() { + this.el.removeEventListener('mousemove', this.onMouseMove); + this.el.removeEventListener('mousedown', this.onMouseDown); + this.el.removeEventListener('mouseup', this.onMouseUp); + this.el.removeEventListener('touchstart', this.onTouchStart); + this.el.removeEventListener('touchmove', this.onTouchMove); + this.el.removeEventListener('touchend', this.onTouchEnd); + window.removeEventListener('devicemotion', this.onDeviceMotion); } }, { key: 'getCurrentSizeStyle', @@ -1650,7 +1657,7 @@ var ThreeSixtyViewer = function () { var container = this.container; var containerId = this.containerId; - this.renderer = new Renderer({ height: height, width: width, container: container, containerId: containerId }); + this.renderer = new Renderer({ height: height, width: width }); this.camera = new THREE.PerspectiveCamera(80, window.innerWidth / window.innerHeight, 0.1, 100); this.controls = new MouseControls(this.camera, this.renderer); this.scene = this.createScene(); @@ -1659,6 +1666,7 @@ var ThreeSixtyViewer = function () { this.texture = this.createTexture(); this.renderer.setTexture(this.texture); this.scene.getObjectByName('photo').children = [this.renderer.mesh]; + this.target = this.container ? this.container : document.querySelector(this.containerId); } createClass(ThreeSixtyViewer, [{ @@ -1674,8 +1682,11 @@ var ThreeSixtyViewer = function () { }, { key: 'destroy', value: function destroy() { - //TODO: unbind events - this.video.style.display = ''; + this.element.style.display = ''; + cancelAnimationFrame(this.animationFrameId); + this.target.removeChild(this.renderer.el); + this.controls.destroy(); + this.element.pause && this.element.pause(); } }, { key: 'setSize', @@ -1696,7 +1707,7 @@ var ThreeSixtyViewer = function () { video.muted = this.muted || false; video.setAttribute('crossorigin', 'anonymous'); video.setAttribute('webkit-playsinline', ''); - video.autoplay = this.autoplay || true; + video.autoplay = this.autoplay !== undefined ? this.autoplay : true; video.addEventListener('error', function (err) { return _this.onError(err); }); @@ -1731,12 +1742,16 @@ var ThreeSixtyViewer = function () { value: function render() { var _this2 = this; + this.target.appendChild(this.renderer.el); + this.element.style.display = 'none'; + var loop = function loop() { _this2.controls.update(); _this2.renderer.render(_this2.scene, _this2.camera); - requestAnimationFrame(loop); + return requestAnimationFrame(loop); }; - loop(); + + this.animationFrameId = loop(); } }]); return ThreeSixtyViewer; diff --git a/dist/kaleidoscope.min.js b/dist/kaleidoscope.min.js index efabb21..a14dde9 100644 --- a/dist/kaleidoscope.min.js +++ b/dist/kaleidoscope.min.js @@ -5,5 +5,5 @@ a.__originalFaceNormal?a.__originalFaceNormal.copy(a.normal):a.__originalFaceNor Object.defineProperty(this,"id",{value:i.TextureIdCount++}),this.uuid=i.Math.generateUUID(),this.name="",this.sourceFile="",this.image=void 0!==t?t:i.Texture.DEFAULT_IMAGE,this.mipmaps=[],this.mapping=void 0!==e?e:i.Texture.DEFAULT_MAPPING,this.wrapS=void 0!==r?r:i.ClampToEdgeWrapping,this.wrapT=void 0!==n?n:i.ClampToEdgeWrapping,this.magFilter=void 0!==a?a:i.LinearFilter,this.minFilter=void 0!==o?o:i.LinearMipMapLinearFilter,this.anisotropy=void 0!==u?u:1,this.format=void 0!==s?s:i.RGBAFormat,this.type=void 0!==h?h:i.UnsignedByteType,this.offset=new i.Vector2(0,0),this.repeat=new i.Vector2(1,1),this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.encoding=i.LinearEncoding,this.version=0,this.onUpdate=null},i.Texture.DEFAULT_IMAGE=void 0,i.Texture.DEFAULT_MAPPING=i.UVMapping,i.Texture.prototype={constructor:i.Texture,set needsUpdate(t){t===!0&&this.version++},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.image=t.image,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.encoding=t.encoding,this},toJSON:function(t){function e(t){var e;return void 0!==t.toDataURL?e=t:(e=document.createElement("canvas"),e.width=t.width,e.height=t.height,e.getContext("2d").drawImage(t,0,0,t.width,t.height)),e.width>2048||e.height>2048?e.toDataURL("image/jpeg",.6):e.toDataURL("image/png")}if(void 0!==t.textures[this.uuid])return t.textures[this.uuid];var r={metadata:{version:4.4,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,mapping:this.mapping,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],wrap:[this.wrapS,this.wrapT],minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy};if(void 0!==this.image){var n=this.image;void 0===n.uuid&&(n.uuid=i.Math.generateUUID()),void 0===t.images[n.uuid]&&(t.images[n.uuid]={uuid:n.uuid,url:e(n)}),r.image=n.uuid}return t.textures[this.uuid]=r,r},dispose:function(){this.dispatchEvent({type:"dispose"})},transformUv:function(t){if(this.mapping===i.UVMapping){if(t.multiply(this.repeat),t.add(this.offset),t.x<0||t.x>1)switch(this.wrapS){case i.RepeatWrapping:t.x=t.x-Math.floor(t.x);break;case i.ClampToEdgeWrapping:t.x=t.x<0?0:1;break;case i.MirroredRepeatWrapping: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 i.RepeatWrapping:t.y=t.y-Math.floor(t.y);break;case i.ClampToEdgeWrapping:t.y=t.y<0?0:1;break;case i.MirroredRepeatWrapping: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)}}},i.EventDispatcher.prototype.apply(i.Texture.prototype),i.TextureIdCount=0,i.DataTexture=function(t,e,r,n,a,o,s,h,u,l,c){i.Texture.call(this,null,o,s,h,u,l,n,a,c),this.image={data:t,width:e,height:r},this.magFilter=void 0!==u?u:i.NearestFilter,this.minFilter=void 0!==l?l:i.NearestFilter,this.flipY=!1,this.generateMipmaps=!1},i.DataTexture.prototype=Object.create(i.Texture.prototype),i.DataTexture.prototype.constructor=i.DataTexture,i.CompressedTexture=function(t,e,r,n,a,o,s,h,u,l,c){i.Texture.call(this,null,o,s,h,u,l,n,a,c),this.image={width:e,height:r},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1},i.CompressedTexture.prototype=Object.create(i.Texture.prototype),i.CompressedTexture.prototype.constructor=i.CompressedTexture,i.CubeTexture=function(t,e,r,n,a,o,s,h,u){t=void 0!==t?t:[],e=void 0!==e?e:i.CubeReflectionMapping,i.Texture.call(this,t,e,r,n,a,o,s,h,u),this.flipY=!1},i.CubeTexture.prototype=Object.create(i.Texture.prototype),i.CubeTexture.prototype.constructor=i.CubeTexture,Object.defineProperty(i.CubeTexture.prototype,"images",{get:function(){return this.image},set:function(t){this.image=t}}),i.VideoTexture=function(t,e,r,n,a,o,s,h,u){function l(){requestAnimationFrame(l),t.readyState>=t.HAVE_CURRENT_DATA&&(c.needsUpdate=!0)}i.Texture.call(this,t,e,r,n,a,o,s,h,u),this.generateMipmaps=!1;var c=this;l()},i.VideoTexture.prototype=Object.create(i.Texture.prototype),i.VideoTexture.prototype.constructor=i.VideoTexture,i.Sprite=function(){var t=new Uint16Array([0,1,2,0,2,3]),e=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),r=new Float32Array([0,0,1,0,1,1,0,1]),n=new i.BufferGeometry;return n.setIndex(new i.BufferAttribute(t,1)),n.addAttribute("position",new i.BufferAttribute(e,3)),n.addAttribute("uv",new i.BufferAttribute(r,2)),function(t){i.Object3D.call(this),this.type="Sprite",this.geometry=n,this.material=void 0!==t?t:new i.SpriteMaterial}}(),i.Sprite.prototype=Object.create(i.Object3D.prototype),i.Sprite.prototype.constructor=i.Sprite,i.Sprite.prototype.raycast=function(){var t=new i.Vector3;return function(e,i){t.setFromMatrixPosition(this.matrixWorld);var r=e.ray.distanceSqToPoint(t),n=this.scale.x*this.scale.y;r>n||i.push({distance:Math.sqrt(r),point:this.position,face:null,object:this})}}(),i.Sprite.prototype.clone=function(){return new this.constructor(this.material).copy(this)},i.Particle=i.Sprite,i.LensFlare=function(t,e,r,n,a){i.Object3D.call(this),this.lensFlares=[],this.positionScreen=new i.Vector3,this.customUpdateCallback=void 0,void 0!==t&&this.add(t,e,r,n,a)},i.LensFlare.prototype=Object.create(i.Object3D.prototype),i.LensFlare.prototype.constructor=i.LensFlare,i.LensFlare.prototype.add=function(t,e,r,n,a,o){void 0===e&&(e=-1),void 0===r&&(r=0),void 0===o&&(o=1),void 0===a&&(a=new i.Color(16777215)),void 0===n&&(n=i.NormalBlending),r=Math.min(r,Math.max(0,r)),this.lensFlares.push({texture:t,size:e,distance:r,x:0,y:0,z:0,scale:1,rotation:0,opacity:o,color:a,blending:n})},i.LensFlare.prototype.updateLensFlares=function(){var t,e,i=this.lensFlares.length,r=2*-this.positionScreen.x,n=2*-this.positionScreen.y;for(t=0;ts)){f.applyMatrix4(this.matrixWorld);var w=n.ray.origin.distanceTo(f);wn.far||a.push({distance:w,point:p.clone().applyMatrix4(this.matrixWorld),index:x,face:null,faceIndex:null,object:this})}}else for(var x=0,M=g.length/3-1;xs)){f.applyMatrix4(this.matrixWorld);var w=n.ray.origin.distanceTo(f);wn.far||a.push({distance:w,point:p.clone().applyMatrix4(this.matrixWorld),index:x,face:null,faceIndex:null,object:this})}}}else if(h instanceof i.Geometry)for(var E=h.vertices,T=E.length,x=0;xs)){f.applyMatrix4(this.matrixWorld);var w=n.ray.origin.distanceTo(f);wn.far||a.push({distance:w,point:p.clone().applyMatrix4(this.matrixWorld),index:x,face:null,faceIndex:null,object:this})}}}}}(),i.Line.prototype.clone=function(){return new this.constructor(this.geometry,this.material).copy(this)},i.LineStrip=0,i.LinePieces=1,i.LineSegments=function(t,e){i.Line.call(this,t,e),this.type="LineSegments"},i.LineSegments.prototype=Object.create(i.Line.prototype),i.LineSegments.prototype.constructor=i.LineSegments,i.Mesh=function(t,e){i.Object3D.call(this),this.type="Mesh",this.geometry=void 0!==t?t:new i.Geometry,this.material=void 0!==e?e:new i.MeshBasicMaterial({color:16777215*Math.random()}),this.drawMode=i.TrianglesDrawMode,this.updateMorphTargets()},i.Mesh.prototype=Object.create(i.Object3D.prototype),i.Mesh.prototype.constructor=i.Mesh,i.Mesh.prototype.setDrawMode=function(t){this.drawMode=t},i.Mesh.prototype.updateMorphTargets=function(){if(void 0!==this.geometry.morphTargets&&this.geometry.morphTargets.length>0){this.morphTargetBase=-1,this.morphTargetInfluences=[],this.morphTargetDictionary={};for(var t=0,e=this.geometry.morphTargets.length;te.far?null:{distance:l,point:y.clone(),object:t}}function r(r,n,a,o,l,c,p,v){s.fromArray(o,3*c),h.fromArray(o,3*p),u.fromArray(o,3*v);var y=e(r,n,a,s,h,u,g);return y&&(l&&(f.fromArray(l,2*c),d.fromArray(l,2*p),m.fromArray(l,2*v),y.uv=t(g,s,h,u,f,d,m)),y.face=new i.Face3(c,p,v,i.Triangle.normal(s,h,u)),y.faceIndex=c),y}var n=new i.Matrix4,a=new i.Ray,o=new i.Sphere,s=new i.Vector3,h=new i.Vector3,u=new i.Vector3,l=new i.Vector3,c=new i.Vector3,p=new i.Vector3,f=new i.Vector2,d=new i.Vector2,m=new i.Vector2,v=new i.Vector3,g=new i.Vector3,y=new i.Vector3;return function(v,y){var x=this.geometry,M=this.material,b=this.matrixWorld;if(void 0!==M&&(null===x.boundingSphere&&x.computeBoundingSphere(),o.copy(x.boundingSphere),o.applyMatrix4(b),v.ray.intersectsSphere(o)!==!1&&(n.getInverse(b),a.copy(v.ray).applyMatrix4(n),null===x.boundingBox||a.intersectsBox(x.boundingBox)!==!1))){var _,S;if(x instanceof i.BufferGeometry){var w,E,T,A=x.index,L=x.attributes,C=L.position.array;if(void 0!==L.uv&&(_=L.uv.array),null!==A)for(var R=A.array,U=0,F=R.length;U0&&(_=z);for(var G=0,k=V.length;Gn.far)return;a.push({distance:h,distanceToRay:Math.sqrt(r),point:o.clone(),index:i,face:null,object:s})}}var s=this,h=this.geometry,u=this.matrixWorld,l=n.params.Points.threshold;if(null===h.boundingSphere&&h.computeBoundingSphere(),r.copy(h.boundingSphere),r.applyMatrix4(u),n.ray.intersectsSphere(r)!==!1){t.getInverse(u),e.copy(n.ray).applyMatrix4(t);var c=l/((this.scale.x+this.scale.y+this.scale.z)/3),p=c*c,f=new i.Vector3;if(h instanceof i.BufferGeometry){var d=h.index,m=h.attributes,v=m.position.array;if(null!==d)for(var g=d.array,y=0,x=g.length;y=0){var c=o[u];if(void 0!==c){var p=c.itemSize,f=Yt.getAttributeBuffer(c);if(c instanceof i.InterleavedBufferAttribute){var d=c.data,m=d.stride,v=c.offset;d instanceof i.InstancedInterleavedBuffer?(Ht.enableAttributeAndDivisor(l,d.meshPerAttribute,a),void 0===r.maxInstancedCount&&(r.maxInstancedCount=d.meshPerAttribute*d.count)):Ht.enableAttribute(l),kt.bindBuffer(kt.ARRAY_BUFFER,f),kt.vertexAttribPointer(l,p,kt.FLOAT,!1,m*d.array.BYTES_PER_ELEMENT,(n*m+v)*d.array.BYTES_PER_ELEMENT)}else c instanceof i.InstancedBufferAttribute?(Ht.enableAttributeAndDivisor(l,c.meshPerAttribute,a),void 0===r.maxInstancedCount&&(r.maxInstancedCount=c.meshPerAttribute*c.count)):Ht.enableAttribute(l),kt.bindBuffer(kt.ARRAY_BUFFER,f),kt.vertexAttribPointer(l,p,kt.FLOAT,!1,0,n*p*4)}else if(void 0!==h){var g=h[u];if(void 0!==g)switch(g.length){case 2:kt.vertexAttrib2fv(l,g);break;case 3:kt.vertexAttrib3fv(l,g);break;case 4:kt.vertexAttrib4fv(l,g);break;default:kt.vertexAttrib1fv(l,g)}}}}Ht.disableUnusedAttributes()}}function m(t,e){return Math.abs(e[0])-Math.abs(t[0])}function v(t,e){return t.object.renderOrder!==e.object.renderOrder?t.object.renderOrder-e.object.renderOrder:t.material.id!==e.material.id?t.material.id-e.material.id:t.z!==e.z?t.z-e.z:t.id-e.id}function g(t,e){return t.object.renderOrder!==e.object.renderOrder?t.object.renderOrder-e.object.renderOrder:t.z!==e.z?e.z-t.z:t.id-e.id}function y(t,e,i,r,n){var a,o;i.transparent?(a=pt,o=++ft):(a=lt,o=++ct);var s=a[o];void 0!==s?(s.id=t.id,s.object=t,s.geometry=e,s.material=i,s.z=It.z,s.group=n):(s={id:t.id,object:t,geometry:e,material:i,z:It.z,group:n},a.push(s))}function x(t,e){if(t.visible!==!1){if(t.layers.test(e.layers))if(t instanceof i.Light)ut.push(t);else if(t instanceof i.Sprite)t.frustumCulled!==!1&&Bt.intersectsObject(t)!==!0||mt.push(t);else if(t instanceof i.LensFlare)vt.push(t);else if(t instanceof i.ImmediateRenderObject)gt.sortObjects===!0&&(It.setFromMatrixPosition(t.matrixWorld),It.applyProjection(Ot)),y(t,null,t.material,It.z,null);else if((t instanceof i.Mesh||t instanceof i.Line||t instanceof i.Points)&&(t instanceof i.SkinnedMesh&&t.skeleton.update(),t.frustumCulled===!1||Bt.intersectsObject(t)===!0)){var r=t.material;if(r.visible===!0){gt.sortObjects===!0&&(It.setFromMatrixPosition(t.matrixWorld),It.applyProjection(Ot));var n=Yt.update(t);if(r instanceof i.MultiMaterial)for(var a=n.groups,o=r.materials,s=0,h=a.length;s=0&&t.numSupportedMorphTargets++}if(t.morphNormals){t.numSupportedMorphNormals=0;for(var p=0;p=0&&t.numSupportedMorphNormals++}n.uniformsList=[];var d=n.__webglShader.uniforms,m=n.program.getUniforms();for(var v in d){var g=m[v];g&&n.uniformsList.push([n.__webglShader.uniforms[v],g])}(t instanceof i.MeshPhongMaterial||t instanceof i.MeshLambertMaterial||t instanceof i.MeshStandardMaterial||t.lights)&&(n.lightsHash=Vt.hash,d.ambientLightColor.value=Vt.ambient,d.directionalLights.value=Vt.directional,d.spotLights.value=Vt.spot,d.pointLights.value=Vt.point,d.hemisphereLights.value=Vt.hemi,d.directionalShadowMap.value=Vt.directionalShadowMap,d.directionalShadowMatrix.value=Vt.directionalShadowMatrix,d.spotShadowMap.value=Vt.spotShadowMap,d.spotShadowMatrix.value=Vt.spotShadowMatrix,d.pointShadowMap.value=Vt.pointShadowMap,d.pointShadowMatrix.value=Vt.pointShadowMatrix),n.hasDynamicUniforms=!1;for(var y=0,x=n.uniformsList.length;y=Xt.maxTextures,At+=1,t}function O(t,e,r,n){var a,o;if("1i"===e)kt.uniform1i(r,n);else if("1f"===e)kt.uniform1f(r,n);else if("2f"===e)kt.uniform2f(r,n[0],n[1]);else if("3f"===e)kt.uniform3f(r,n[0],n[1],n[2]);else if("4f"===e)kt.uniform4f(r,n[0],n[1],n[2],n[3]);else if("1iv"===e)kt.uniform1iv(r,n);else if("3iv"===e)kt.uniform3iv(r,n);else if("1fv"===e)kt.uniform1fv(r,n);else if("2fv"===e)kt.uniform2fv(r,n);else if("3fv"===e)kt.uniform3fv(r,n);else if("4fv"===e)kt.uniform4fv(r,n);else if("Matrix2fv"===e)kt.uniformMatrix2fv(r,!1,n);else if("Matrix3fv"===e)kt.uniformMatrix3fv(r,!1,n);else if("Matrix4fv"===e)kt.uniformMatrix4fv(r,!1,n);else if("i"===e)kt.uniform1i(r,n);else if("f"===e)kt.uniform1f(r,n);else if("v2"===e)kt.uniform2f(r,n.x,n.y);else if("v3"===e)kt.uniform3f(r,n.x,n.y,n.z);else if("v4"===e)kt.uniform4f(r,n.x,n.y,n.z,n.w);else if("c"===e)kt.uniform3f(r,n.r,n.g,n.b);else if("s"===e){var s=t.properties;for(var h in s){var u=s[h],l=r[h],c=n[h];O(u,u.type,l,c)}}else if("sa"===e)for(var s=t.properties,p=0,f=n.length;p1||qt.get(e).__currentAnisotropy)&&(kt.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e.anisotropy,gt.getMaxAnisotropy())),qt.get(e).__currentAnisotropy=e.anisotropy)}}function G(t,e,r){void 0===t.__webglInit&&(t.__webglInit=!0,e.addEventListener("dispose",s),t.__webglTexture=kt.createTexture(),zt.textures++),Ht.activeTexture(kt.TEXTURE0+r),Ht.bindTexture(kt.TEXTURE_2D,t.__webglTexture),kt.pixelStorei(kt.UNPACK_FLIP_Y_WEBGL,e.flipY),kt.pixelStorei(kt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),kt.pixelStorei(kt.UNPACK_ALIGNMENT,e.unpackAlignment);var n=k(e.image,Xt.maxTextureSize);W(e)&&j(n)===!1&&(n=X(n));var a=j(n),o=tt(e.format),h=tt(e.type);z(kt.TEXTURE_2D,e,a);var u,l=e.mipmaps;if(e instanceof i.DataTexture)if(l.length>0&&a){for(var c=0,p=l.length;c-1&&Ht.compressedTexImage2D(kt.TEXTURE_2D,c,o,u.width,u.height,0,u.data):Ht.texImage2D(kt.TEXTURE_2D,c,o,u.width,u.height,0,o,h,u.data);else if(l.length>0&&a){for(var c=0,p=l.length;ce||t.height>e){var i=e/Math.max(t.width,t.height),r=document.createElement("canvas");r.width=Math.floor(t.width*i),r.height=Math.floor(t.height*i);var n=r.getContext("2d");return n.drawImage(t,0,0,t.width,t.height,0,0,r.width,r.height),r}return t}function j(t){return i.Math.isPowerOfTwo(t.width)&&i.Math.isPowerOfTwo(t.height)}function W(t){return t.wrapS!==i.ClampToEdgeWrapping||t.wrapT!==i.ClampToEdgeWrapping||t.minFilter!==i.NearestFilter&&t.minFilter!==i.LinearFilter}function X(t){if(t instanceof HTMLImageElement||t instanceof HTMLCanvasElement){var e=document.createElement("canvas");e.width=i.Math.nearestPowerOfTwo(t.width),e.height=i.Math.nearestPowerOfTwo(t.height);var r=e.getContext("2d");return r.drawImage(t,0,0,e.width,e.height),e}return t}function H(t,e){var r=qt.get(t);if(6===t.image.length)if(t.version>0&&r.__version!==t.version){r.__image__webglTextureCube||(t.addEventListener("dispose",s),r.__image__webglTextureCube=kt.createTexture(),zt.textures++),Ht.activeTexture(kt.TEXTURE0+e),Ht.bindTexture(kt.TEXTURE_CUBE_MAP,r.__image__webglTextureCube),kt.pixelStorei(kt.UNPACK_FLIP_Y_WEBGL,t.flipY);for(var n=t instanceof i.CompressedTexture,a=t.image[0]instanceof i.DataTexture,o=[],h=0;h<6;h++)!gt.autoScaleCubemaps||n||a?o[h]=a?t.image[h].image:t.image[h]:o[h]=k(t.image[h],Xt.maxCubemapSize);var u=o[0],l=j(u),c=tt(t.format),p=tt(t.type);z(kt.TEXTURE_CUBE_MAP,t,l);for(var h=0;h<6;h++)if(n)for(var f,d=o[h].mipmaps,m=0,v=d.length;m-1&&Ht.compressedTexImage2D(kt.TEXTURE_CUBE_MAP_POSITIVE_X+h,m,c,f.width,f.height,0,f.data):Ht.texImage2D(kt.TEXTURE_CUBE_MAP_POSITIVE_X+h,m,c,f.width,f.height,0,c,p,f.data);else a?Ht.texImage2D(kt.TEXTURE_CUBE_MAP_POSITIVE_X+h,0,c,o[h].width,o[h].height,0,c,p,o[h].data):Ht.texImage2D(kt.TEXTURE_CUBE_MAP_POSITIVE_X+h,0,c,c,p,o[h]);t.generateMipmaps&&l&&kt.generateMipmap(kt.TEXTURE_CUBE_MAP),r.__version=t.version,t.onUpdate&&t.onUpdate(t)}else Ht.activeTexture(kt.TEXTURE0+e),Ht.bindTexture(kt.TEXTURE_CUBE_MAP,r.__image__webglTextureCube)}function q(t,e){Ht.activeTexture(kt.TEXTURE0+e),Ht.bindTexture(kt.TEXTURE_CUBE_MAP,qt.get(t).__webglTexture)}function Y(t,e,i,r){var n=tt(e.texture.format),a=tt(e.texture.type);Ht.texImage2D(r,0,n,e.width,e.height,0,n,a,null),kt.bindFramebuffer(kt.FRAMEBUFFER,t),kt.framebufferTexture2D(kt.FRAMEBUFFER,i,r,qt.get(e.texture).__webglTexture,0),kt.bindFramebuffer(kt.FRAMEBUFFER,null)}function Z(t,e){kt.bindRenderbuffer(kt.RENDERBUFFER,t),e.depthBuffer&&!e.stencilBuffer?(kt.renderbufferStorage(kt.RENDERBUFFER,kt.DEPTH_COMPONENT16,e.width,e.height),kt.framebufferRenderbuffer(kt.FRAMEBUFFER,kt.DEPTH_ATTACHMENT,kt.RENDERBUFFER,t)):e.depthBuffer&&e.stencilBuffer?(kt.renderbufferStorage(kt.RENDERBUFFER,kt.DEPTH_STENCIL,e.width,e.height),kt.framebufferRenderbuffer(kt.FRAMEBUFFER,kt.DEPTH_STENCIL_ATTACHMENT,kt.RENDERBUFFER,t)):kt.renderbufferStorage(kt.RENDERBUFFER,kt.RGBA4,e.width,e.height),kt.bindRenderbuffer(kt.RENDERBUFFER,null)}function Q(t){var e=qt.get(t),r=t instanceof i.WebGLRenderTargetCube;if(r){e.__webglDepthbuffer=[];for(var n=0;n<6;n++)kt.bindFramebuffer(kt.FRAMEBUFFER,e.__webglFramebuffer[n]),e.__webglDepthbuffer[n]=kt.createRenderbuffer(),Z(e.__webglDepthbuffer[n],t)}else kt.bindFramebuffer(kt.FRAMEBUFFER,e.__webglFramebuffer),e.__webglDepthbuffer=kt.createRenderbuffer(),Z(e.__webglDepthbuffer,t);kt.bindFramebuffer(kt.FRAMEBUFFER,null)}function J(t){var e=qt.get(t),r=qt.get(t.texture);t.addEventListener("dispose",h),r.__webglTexture=kt.createTexture(),zt.textures++;var n=t instanceof i.WebGLRenderTargetCube,a=i.Math.isPowerOfTwo(t.width)&&i.Math.isPowerOfTwo(t.height);if(n){e.__webglFramebuffer=[];for(var o=0;o<6;o++)e.__webglFramebuffer[o]=kt.createFramebuffer()}else e.__webglFramebuffer=kt.createFramebuffer();if(n){Ht.bindTexture(kt.TEXTURE_CUBE_MAP,r.__webglTexture),z(kt.TEXTURE_CUBE_MAP,t.texture,a);for(var o=0;o<6;o++)Y(e.__webglFramebuffer[o],t,kt.COLOR_ATTACHMENT0,kt.TEXTURE_CUBE_MAP_POSITIVE_X+o);t.texture.generateMipmaps&&a&&kt.generateMipmap(kt.TEXTURE_CUBE_MAP),Ht.bindTexture(kt.TEXTURE_CUBE_MAP,null)}else Ht.bindTexture(kt.TEXTURE_2D,r.__webglTexture),z(kt.TEXTURE_2D,t.texture,a),Y(e.__webglFramebuffer,t,kt.COLOR_ATTACHMENT0,kt.TEXTURE_2D),t.texture.generateMipmaps&&a&&kt.generateMipmap(kt.TEXTURE_2D),Ht.bindTexture(kt.TEXTURE_2D,null);t.depthBuffer&&Q(t)}function K(t){var e=t instanceof i.WebGLRenderTargetCube?kt.TEXTURE_CUBE_MAP:kt.TEXTURE_2D,r=qt.get(t.texture).__webglTexture;Ht.bindTexture(e,r),kt.generateMipmap(e),Ht.bindTexture(e,null)}function $(t){return t===i.NearestFilter||t===i.NearestMipMapNearestFilter||t===i.NearestMipMapLinearFilter?kt.NEAREST:kt.LINEAR}function tt(t){var e;if(t===i.RepeatWrapping)return kt.REPEAT;if(t===i.ClampToEdgeWrapping)return kt.CLAMP_TO_EDGE;if(t===i.MirroredRepeatWrapping)return kt.MIRRORED_REPEAT;if(t===i.NearestFilter)return kt.NEAREST;if(t===i.NearestMipMapNearestFilter)return kt.NEAREST_MIPMAP_NEAREST;if(t===i.NearestMipMapLinearFilter)return kt.NEAREST_MIPMAP_LINEAR;if(t===i.LinearFilter)return kt.LINEAR;if(t===i.LinearMipMapNearestFilter)return kt.LINEAR_MIPMAP_NEAREST;if(t===i.LinearMipMapLinearFilter)return kt.LINEAR_MIPMAP_LINEAR;if(t===i.UnsignedByteType)return kt.UNSIGNED_BYTE;if(t===i.UnsignedShort4444Type)return kt.UNSIGNED_SHORT_4_4_4_4;if(t===i.UnsignedShort5551Type)return kt.UNSIGNED_SHORT_5_5_5_1;if(t===i.UnsignedShort565Type)return kt.UNSIGNED_SHORT_5_6_5;if(t===i.ByteType)return kt.BYTE;if(t===i.ShortType)return kt.SHORT;if(t===i.UnsignedShortType)return kt.UNSIGNED_SHORT;if(t===i.IntType)return kt.INT;if(t===i.UnsignedIntType)return kt.UNSIGNED_INT;if(t===i.FloatType)return kt.FLOAT;if(e=Wt.get("OES_texture_half_float"),null!==e&&t===i.HalfFloatType)return e.HALF_FLOAT_OES;if(t===i.AlphaFormat)return kt.ALPHA;if(t===i.RGBFormat)return kt.RGB;if(t===i.RGBAFormat)return kt.RGBA;if(t===i.LuminanceFormat)return kt.LUMINANCE;if(t===i.LuminanceAlphaFormat)return kt.LUMINANCE_ALPHA;if(t===i.AddEquation)return kt.FUNC_ADD;if(t===i.SubtractEquation)return kt.FUNC_SUBTRACT;if(t===i.ReverseSubtractEquation)return kt.FUNC_REVERSE_SUBTRACT;if(t===i.ZeroFactor)return kt.ZERO;if(t===i.OneFactor)return kt.ONE;if(t===i.SrcColorFactor)return kt.SRC_COLOR;if(t===i.OneMinusSrcColorFactor)return kt.ONE_MINUS_SRC_COLOR;if(t===i.SrcAlphaFactor)return kt.SRC_ALPHA;if(t===i.OneMinusSrcAlphaFactor)return kt.ONE_MINUS_SRC_ALPHA;if(t===i.DstAlphaFactor)return kt.DST_ALPHA;if(t===i.OneMinusDstAlphaFactor)return kt.ONE_MINUS_DST_ALPHA;if(t===i.DstColorFactor)return kt.DST_COLOR;if(t===i.OneMinusDstColorFactor)return kt.ONE_MINUS_DST_COLOR;if(t===i.SrcAlphaSaturateFactor)return kt.SRC_ALPHA_SATURATE;if(e=Wt.get("WEBGL_compressed_texture_s3tc"),null!==e){if(t===i.RGB_S3TC_DXT1_Format)return e.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===i.RGBA_S3TC_DXT1_Format)return e.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===i.RGBA_S3TC_DXT3_Format)return e.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(t===i.RGBA_S3TC_DXT5_Format)return e.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(e=Wt.get("WEBGL_compressed_texture_pvrtc"),null!==e){if(t===i.RGB_PVRTC_4BPPV1_Format)return e.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(t===i.RGB_PVRTC_2BPPV1_Format)return e.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(t===i.RGBA_PVRTC_4BPPV1_Format)return e.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(t===i.RGBA_PVRTC_2BPPV1_Format)return e.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(e=Wt.get("WEBGL_compressed_texture_etc1"),null!==e&&t===i.RGB_ETC1_Format)return e.COMPRESSED_RGB_ETC1_WEBGL;if(e=Wt.get("EXT_blend_minmax"),null!==e){if(t===i.MinEquation)return e.MIN_EXT;if(t===i.MaxEquation)return e.MAX_EXT}return 0}t=t||{};var et=void 0!==t.canvas?t.canvas:document.createElement("canvas"),it=void 0!==t.context?t.context:null,rt=void 0!==t.alpha&&t.alpha,nt=void 0===t.depth||t.depth,at=void 0===t.stencil||t.stencil,ot=void 0!==t.antialias&&t.antialias,st=void 0===t.premultipliedAlpha||t.premultipliedAlpha,ht=void 0!==t.preserveDrawingBuffer&&t.preserveDrawingBuffer,ut=[],lt=[],ct=-1,pt=[],ft=-1,dt=new Float32Array(8),mt=[],vt=[];this.domElement=et,this.context=null,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.gammaFactor=2,this.gammaInput=!1,this.gammaOutput=!1,this.physicallyCorrectLights=!1,this.toneMapping=i.LinearToneMapping,this.toneMappingExposure=1,this.toneMappingWhitePoint=1,this.maxMorphTargets=8,this.maxMorphNormals=4,this.autoScaleCubemaps=!0;var gt=this,yt=null,xt=null,Mt=null,bt=-1,_t="",St=null,wt=new i.Vector4,Et=null,Tt=new i.Vector4,At=0,Lt=new i.Color(0),Ct=0,Rt=et.width,Ut=et.height,Ft=1,Pt=new i.Vector4(0,0,Rt,Ut),Nt=!1,Dt=new i.Vector4(0,0,Rt,Ut),Bt=new i.Frustum,Ot=new i.Matrix4,It=new i.Vector3,Vt={hash:"",ambient:[0,0,0],directional:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotShadowMap:[],spotShadowMatrix:[],point:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],shadows:[],shadowsPointLight:0},zt={geometries:0,textures:0},Gt={calls:0,vertices:0,faces:0,points:0};this.info={render:Gt,memory:zt,programs:null};var kt;try{var jt={alpha:rt,depth:nt,stencil:at,antialias:ot,premultipliedAlpha:st,preserveDrawingBuffer:ht};if(kt=it||et.getContext("webgl",jt)||et.getContext("experimental-webgl",jt),null===kt)throw null!==et.getContext("webgl")?"Error creating WebGL context with your selected attributes.":"Error creating WebGL context.";void 0===kt.getShaderPrecisionFormat&&(kt.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}}),et.addEventListener("webglcontextlost",o,!1)}catch(t){}var Wt=new i.WebGLExtensions(kt);Wt.get("OES_texture_float"),Wt.get("OES_texture_float_linear"),Wt.get("OES_texture_half_float"),Wt.get("OES_texture_half_float_linear"),Wt.get("OES_standard_derivatives"),Wt.get("ANGLE_instanced_arrays"),Wt.get("OES_element_index_uint")&&(i.BufferGeometry.MaxIndex=4294967296);var Xt=new i.WebGLCapabilities(kt,Wt,t),Ht=new i.WebGLState(kt,Wt,tt),qt=new i.WebGLProperties,Yt=new i.WebGLObjects(kt,qt,this.info),Zt=new i.WebGLPrograms(this,Xt),Qt=new i.WebGLLights;this.info.programs=Zt.programs;var Jt=new i.WebGLBufferRenderer(kt,Wt,Gt),Kt=new i.WebGLIndexedBufferRenderer(kt,Wt,Gt);n(),this.context=kt,this.capabilities=Xt,this.extensions=Wt,this.properties=qt,this.state=Ht;var $t=new i.WebGLShadowMap(this,Vt,Yt);this.shadowMap=$t;var te=new i.SpritePlugin(this,mt),ee=new i.LensFlarePlugin(this,vt);this.getContext=function(){return kt},this.getContextAttributes=function(){return kt.getContextAttributes()},this.forceContextLoss=function(){Wt.get("WEBGL_lose_context").loseContext()},this.getMaxAnisotropy=function(){var t;return function(){if(void 0!==t)return t;var e=Wt.get("EXT_texture_filter_anisotropic");return t=null!==e?kt.getParameter(e.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0}}(),this.getPrecision=function(){return Xt.precision},this.getPixelRatio=function(){return Ft},this.setPixelRatio=function(t){void 0!==t&&(Ft=t,this.setSize(Dt.z,Dt.w,!1))},this.getSize=function(){return{width:Rt,height:Ut}},this.setSize=function(t,e,i){Rt=t,Ut=e,et.width=t*Ft,et.height=e*Ft,i!==!1&&(et.style.width=t+"px",et.style.height=e+"px"),this.setViewport(0,0,t,e)},this.setViewport=function(t,e,i,r){Ht.viewport(Dt.set(t,e,i,r))},this.setScissor=function(t,e,i,r){Ht.scissor(Pt.set(t,e,i,r))},this.setScissorTest=function(t){Ht.setScissorTest(Nt=t)},this.getClearColor=function(){return Lt},this.setClearColor=function(t,e){Lt.set(t),Ct=void 0!==e?e:1,r(Lt.r,Lt.g,Lt.b,Ct)},this.getClearAlpha=function(){return Ct},this.setClearAlpha=function(t){Ct=t,r(Lt.r,Lt.g,Lt.b,Ct)},this.clear=function(t,e,i){var r=0;(void 0===t||t)&&(r|=kt.COLOR_BUFFER_BIT),(void 0===e||e)&&(r|=kt.DEPTH_BUFFER_BIT),(void 0===i||i)&&(r|=kt.STENCIL_BUFFER_BIT),kt.clear(r)},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,i,r){this.setRenderTarget(t),this.clear(e,i,r)},this.resetGLState=a,this.dispose=function(){et.removeEventListener("webglcontextlost",o,!1)},this.renderBufferImmediate=function(t,e,r){Ht.initAttributes();var n=qt.get(t);t.hasPositions&&!n.position&&(n.position=kt.createBuffer()),t.hasNormals&&!n.normal&&(n.normal=kt.createBuffer()),t.hasUvs&&!n.uv&&(n.uv=kt.createBuffer()),t.hasColors&&!n.color&&(n.color=kt.createBuffer());var a=e.getAttributes();if(t.hasPositions&&(kt.bindBuffer(kt.ARRAY_BUFFER,n.position),kt.bufferData(kt.ARRAY_BUFFER,t.positionArray,kt.DYNAMIC_DRAW),Ht.enableAttribute(a.position),kt.vertexAttribPointer(a.position,3,kt.FLOAT,!1,0,0)),t.hasNormals){if(kt.bindBuffer(kt.ARRAY_BUFFER,n.normal),"MeshPhongMaterial"!==r.type&&"MeshStandardMaterial"!==r.type&&r.shading===i.FlatShading)for(var o=0,s=3*t.count;o8&&(p.length=8);for(var y=n.morphAttributes,f=0,v=p.length;f0&&S.renderInstances(n,U,P):S.render(U,P)},this.render=function(t,e,r,n){if(e instanceof i.Camera!=!1){var a=t.fog;if(_t="",bt=-1,St=null,t.autoUpdate===!0&&t.updateMatrixWorld(),null===e.parent&&e.updateMatrixWorld(),e.matrixWorldInverse.getInverse(e.matrixWorld),Ot.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),Bt.setFromMatrix(Ot),ut.length=0,ct=-1,ft=-1,mt.length=0,vt.length=0,x(t,e),lt.length=ct+1,pt.length=ft+1,gt.sortObjects===!0&&(lt.sort(v),pt.sort(g)),V(ut,e),$t.render(t,e),Gt.calls=0,Gt.vertices=0,Gt.faces=0,Gt.points=0,void 0===r&&(r=null),this.setRenderTarget(r),(this.autoClear||n)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil),t.overrideMaterial){var o=t.overrideMaterial;M(lt,e,a,o),M(pt,e,a,o)}else Ht.setBlending(i.NoBlending),M(lt,e,a),M(pt,e,a);if(te.render(t,e),ee.render(t,e,Tt),r){var s=r.texture;s.generateMipmaps&&j(r)&&s.minFilter!==i.NearestFilter&&s.minFilter!==i.LinearFilter&&K(r)}Ht.setDepthTest(!0),Ht.setDepthWrite(!0),Ht.setColorWrite(!0)}},this.setFaceCulling=function(t,e){t===i.CullFaceNone?Ht.disable(kt.CULL_FACE):(e===i.FrontFaceDirectionCW?kt.frontFace(kt.CW):kt.frontFace(kt.CCW),t===i.CullFaceBack?kt.cullFace(kt.BACK):t===i.CullFaceFront?kt.cullFace(kt.FRONT):kt.cullFace(kt.FRONT_AND_BACK),Ht.enable(kt.CULL_FACE))},this.setTexture=function(t,e){var i=qt.get(t);if(t.version>0&&i.__version!==t.version){var r=t.image;if(void 0===r)return;if(r.complete===!1)return;return void G(i,t,e)}Ht.activeTexture(kt.TEXTURE0+e),Ht.bindTexture(kt.TEXTURE_2D,i.__webglTexture)},this.getCurrentRenderTarget=function(){return xt},this.setRenderTarget=function(t){xt=t,t&&void 0===qt.get(t).__webglFramebuffer&&J(t);var e,r=t instanceof i.WebGLRenderTargetCube;if(t){var n=qt.get(t);e=r?n.__webglFramebuffer[t.activeCubeFace]:n.__webglFramebuffer,wt.copy(t.scissor),Et=t.scissorTest,Tt.copy(t.viewport)}else e=null,wt.copy(Pt).multiplyScalar(Ft),Et=Nt,Tt.copy(Dt).multiplyScalar(Ft);if(Mt!==e&&(kt.bindFramebuffer(kt.FRAMEBUFFER,e),Mt=e),Ht.scissor(wt),Ht.setScissorTest(Et),Ht.viewport(Tt),r){var a=qt.get(t.texture);kt.framebufferTexture2D(kt.FRAMEBUFFER,kt.COLOR_ATTACHMENT0,kt.TEXTURE_CUBE_MAP_POSITIVE_X+t.activeCubeFace,a.__webglTexture,t.activeMipMapLevel)}},this.readRenderTargetPixels=function(t,e,r,n,a,o){if(t instanceof i.WebGLRenderTarget!=!1){var s=qt.get(t).__webglFramebuffer;if(s){var h=!1;s!==Mt&&(kt.bindFramebuffer(kt.FRAMEBUFFER,s),h=!0);try{var u=t.texture;if(u.format!==i.RGBAFormat&&tt(u.format)!==kt.getParameter(kt.IMPLEMENTATION_COLOR_READ_FORMAT))return;if(!(u.type===i.UnsignedByteType||tt(u.type)===kt.getParameter(kt.IMPLEMENTATION_COLOR_READ_TYPE)||u.type===i.FloatType&&Wt.get("WEBGL_color_buffer_float")||u.type===i.HalfFloatType&&Wt.get("EXT_color_buffer_half_float")))return;kt.checkFramebufferStatus(kt.FRAMEBUFFER)===kt.FRAMEBUFFER_COMPLETE&&kt.readPixels(e,r,n,a,tt(u.format),tt(u.type),o)}finally{h&&kt.bindFramebuffer(kt.FRAMEBUFFER,Mt)}}}}},i.WebGLExtensions=function(t){var e={};this.get=function(i){if(void 0!==e[i])return e[i];var r;switch(i){case"EXT_texture_filter_anisotropic":r=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":r=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":r=t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;case"WEBGL_compressed_texture_etc1":r=t.getExtension("WEBGL_compressed_texture_etc1");break;default:r=t.getExtension(i)}return e[i]=r,r}},i.WebGLCapabilities=function(t,e,i){function r(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"}this.getMaxPrecision=r,this.precision=void 0!==i.precision?i.precision:"highp",this.logarithmicDepthBuffer=void 0!==i.logarithmicDepthBuffer&&i.logarithmicDepthBuffer,this.maxTextures=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),this.maxVertexTextures=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS),this.maxTextureSize=t.getParameter(t.MAX_TEXTURE_SIZE),this.maxCubemapSize=t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),this.maxAttributes=t.getParameter(t.MAX_VERTEX_ATTRIBS),this.maxVertexUniforms=t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),this.maxVaryings=t.getParameter(t.MAX_VARYING_VECTORS),this.maxFragmentUniforms=t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),this.vertexTextures=this.maxVertexTextures>0,this.floatFragmentTextures=!!e.get("OES_texture_float"),this.floatVertexTextures=this.vertexTextures&&this.floatFragmentTextures;var n=r(this.precision);n!==this.precision&&(this.precision=n),this.logarithmicDepthBuffer&&(this.logarithmicDepthBuffer=!!e.get("EXT_frag_depth"))},i.WebGLProperties=function(){var t={};this.get=function(e){var i=e.uuid,r=t[i];return void 0===r&&(r={},t[i]=r),r},this.delete=function(e){delete t[e.uuid]},this.clear=function(){t={}}},i.WebGLLights=function(){var t={};this.get=function(e){if(void 0!==t[e.id])return t[e.id];var r;switch(e.type){case"DirectionalLight":r={direction:new i.Vector3,color:new i.Color,shadow:!1,shadowBias:0,shadowRadius:1,shadowMapSize:new i.Vector2};break;case"SpotLight":r={position:new i.Vector3,direction:new i.Vector3,color:new i.Color,distance:0,coneCos:0,penumbraCos:0,decay:0,shadow:!1,shadowBias:0,shadowRadius:1,shadowMapSize:new i.Vector2};break;case"PointLight":r={position:new i.Vector3,color:new i.Color,distance:0,decay:0,shadow:!1,shadowBias:0,shadowRadius:1,shadowMapSize:new i.Vector2};break;case"HemisphereLight":r={direction:new i.Vector3,skyColor:new i.Color,groundColor:new i.Color}}return t[e.id]=r,r}},i.WebGLState=function(t,e,r){var n=this,a=new i.Vector4,o=new Uint8Array(16),s=new Uint8Array(16),h=new Uint8Array(16),u={},l=null,c=null,p=null,f=null,d=null,m=null,v=null,g=null,y=!1,x=null,M=null,b=null,_=null,S=null,w=null,E=null,T=null,A=null,L=null,C=null,R=null,U=null,F=null,P=null,N=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),D=void 0,B={},O=new i.Vector4,I=null,V=null,z=new i.Vector4,G=new i.Vector4,k=t.createTexture();t.bindTexture(t.TEXTURE_2D,k),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texImage2D(t.TEXTURE_2D,0,t.RGB,1,1,0,t.RGB,t.UNSIGNED_BYTE,new Uint8Array(3)),this.init=function(){this.clearColor(0,0,0,1),this.clearDepth(1),this.clearStencil(0),this.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.frontFace(t.CCW),t.cullFace(t.BACK),this.enable(t.CULL_FACE),this.enable(t.BLEND),t.blendEquation(t.FUNC_ADD),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA)},this.initAttributes=function(){for(var t=0,e=o.length;t0&&e.morphTargets,l=t instanceof i.SkinnedMesh&&e.skinning,c=0;u&&(c|=d),l&&(c|=m),o=s[c]}return o.visible=e.visible,o.wireframe=e.wireframe,o.wireframeLinewidth=e.wireframeLinewidth,r&&void 0!==o.uniforms.lightPos&&o.uniforms.lightPos.value.copy(n),o}function a(t,e,r){if(t.visible!==!1){if(t.layers.test(e.layers)&&(t instanceof i.Mesh||t instanceof i.Line||t instanceof i.Points)&&t.castShadow&&(t.frustumCulled===!1||h.intersectsObject(t)===!0)){var n=t.material;n.visible===!0&&(t.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,t.matrixWorld),f.push(t))}for(var o=t.children,s=0,u=o.length;s 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")),p.compileShader(i),p.compileShader(r),p.attachShader(e,i),p.attachShader(e,r),p.linkProgram(e),e}function a(t,e){return t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:e.id-t.id}var o,s,h,u,l,c,p=t.context,f=t.state,d=new i.Vector3,m=new i.Quaternion,v=new i.Vector3;this.render=function(n,g){if(0!==e.length){void 0===h&&r(),p.useProgram(h),f.initAttributes(),f.enableAttribute(u.position),f.enableAttribute(u.uv),f.disableUnusedAttributes(),f.disable(p.CULL_FACE),f.enable(p.BLEND),p.bindBuffer(p.ARRAY_BUFFER,o),p.vertexAttribPointer(u.position,2,p.FLOAT,!1,16,0),p.vertexAttribPointer(u.uv,2,p.FLOAT,!1,16,8),p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,s),p.uniformMatrix4fv(l.projectionMatrix,!1,g.projectionMatrix.elements),f.activeTexture(p.TEXTURE0),p.uniform1i(l.map,0);var y=0,x=0,M=n.fog;M?(p.uniform3f(l.fogColor,M.color.r,M.color.g,M.color.b),M instanceof i.Fog?(p.uniform1f(l.fogNear,M.near),p.uniform1f(l.fogFar,M.far),p.uniform1i(l.fogType,1),y=1,x=1):M instanceof i.FogExp2&&(p.uniform1f(l.fogDensity,M.density),p.uniform1i(l.fogType,2),y=2,x=2)):(p.uniform1i(l.fogType,0),y=0,x=0);for(var b=0,_=e.length;b<_;b++){var S=e[b];S.modelViewMatrix.multiplyMatrices(g.matrixWorldInverse,S.matrixWorld),S.z=-S.modelViewMatrix.elements[14]}e.sort(a);for(var w=[],b=0,_=e.length;b<_;b++){var S=e[b],E=S.material;p.uniform1f(l.alphaTest,E.alphaTest),p.uniformMatrix4fv(l.modelViewMatrix,!1,S.modelViewMatrix.elements),S.matrixWorld.decompose(d,m,v),w[0]=v.x,w[1]=v.y;var T=0;n.fog&&E.fog&&(T=x),y!==T&&(p.uniform1i(l.fogType,T),y=T),null!==E.map?(p.uniform2f(l.uvOffset,E.map.offset.x,E.map.offset.y),p.uniform2f(l.uvScale,E.map.repeat.x,E.map.repeat.y)):(p.uniform2f(l.uvOffset,0,0),p.uniform2f(l.uvScale,1,1)),p.uniform1f(l.opacity,E.opacity),p.uniform3f(l.color,E.color.r,E.color.g,E.color.b),p.uniform1f(l.rotation,E.rotation),p.uniform2fv(l.scale,w),f.setBlending(E.blending,E.blendEquation,E.blendSrc,E.blendDst),f.setDepthTest(E.depthTest),f.setDepthWrite(E.depthWrite),E.map&&E.map.image&&E.map.image.width?t.setTexture(E.map,0):t.setTexture(c,0),p.drawElements(p.TRIANGLES,6,p.UNSIGNED_SHORT,0)}f.enable(p.CULL_FACE),t.resetGLState()}}},i.LensFlarePlugin=function(t,e){function r(){var t=new Float32Array([-1,-1,0,0,1,-1,1,0,1,1,1,1,-1,1,0,1]),e=new Uint16Array([0,1,2,0,2,3]);a=f.createBuffer(),o=f.createBuffer(),f.bindBuffer(f.ARRAY_BUFFER,a),f.bufferData(f.ARRAY_BUFFER,t,f.STATIC_DRAW),f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,o),f.bufferData(f.ELEMENT_ARRAY_BUFFER,e,f.STATIC_DRAW),c=f.createTexture(),p=f.createTexture(),d.bindTexture(f.TEXTURE_2D,c),f.texImage2D(f.TEXTURE_2D,0,f.RGB,16,16,0,f.RGB,f.UNSIGNED_BYTE,null),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.NEAREST),d.bindTexture(f.TEXTURE_2D,p),f.texImage2D(f.TEXTURE_2D,0,f.RGBA,16,16,0,f.RGBA,f.UNSIGNED_BYTE,null),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.NEAREST),l=f.getParameter(f.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0;var i;i=l?{vertexShader:["uniform lowp int renderType;","uniform vec3 screenPosition;","uniform vec2 scale;","uniform float rotation;","uniform sampler2D occlusionMap;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","varying float vVisibility;","void main() {","vUV = uv;","vec2 pos = position;","if ( renderType == 2 ) {","vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );","vVisibility = visibility.r / 9.0;","vVisibility *= 1.0 - visibility.g / 9.0;","vVisibility *= visibility.b / 9.0;","vVisibility *= 1.0 - visibility.a / 9.0;","pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;","pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;","}","gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );","}"].join("\n"),fragmentShader:["uniform lowp int renderType;","uniform sampler2D map;","uniform float opacity;","uniform vec3 color;","varying vec2 vUV;","varying float vVisibility;","void main() {","if ( renderType == 0 ) {","gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );","} else if ( renderType == 1 ) {","gl_FragColor = texture2D( map, vUV );","} else {","vec4 texture = texture2D( map, vUV );","texture.a *= opacity * vVisibility;","gl_FragColor = texture;","gl_FragColor.rgb *= color;","}","}"].join("\n")}:{vertexShader:["uniform lowp int renderType;","uniform vec3 screenPosition;","uniform vec2 scale;","uniform float rotation;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","void main() {","vUV = uv;","vec2 pos = position;","if ( renderType == 2 ) {","pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;","pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;","}","gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );","}"].join("\n"),fragmentShader:["precision mediump float;","uniform lowp int renderType;","uniform sampler2D map;","uniform sampler2D occlusionMap;","uniform float opacity;","uniform vec3 color;","varying vec2 vUV;","void main() {","if ( renderType == 0 ) {","gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );","} else if ( renderType == 1 ) {","gl_FragColor = texture2D( map, vUV );","} else {","float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;","visibility = ( 1.0 - visibility / 4.0 );","vec4 texture = texture2D( map, vUV );","texture.a *= opacity * visibility;","gl_FragColor = texture;","gl_FragColor.rgb *= color;","}","}"].join("\n")},s=n(i),h={vertex:f.getAttribLocation(s,"position"),uv:f.getAttribLocation(s,"uv")},u={renderType:f.getUniformLocation(s,"renderType"),map:f.getUniformLocation(s,"map"),occlusionMap:f.getUniformLocation(s,"occlusionMap"),opacity:f.getUniformLocation(s,"opacity"),color:f.getUniformLocation(s,"color"),scale:f.getUniformLocation(s,"scale"),rotation:f.getUniformLocation(s,"rotation"),screenPosition:f.getUniformLocation(s,"screenPosition")}}function n(e){var i=f.createProgram(),r=f.createShader(f.FRAGMENT_SHADER),n=f.createShader(f.VERTEX_SHADER),a="precision "+t.getPrecision()+" float;\n";return f.shaderSource(r,a+e.fragmentShader),f.shaderSource(n,a+e.vertexShader),f.compileShader(r),f.compileShader(n),f.attachShader(i,r),f.attachShader(i,n),f.linkProgram(i),i}var a,o,s,h,u,l,c,p,f=t.context,d=t.state;this.render=function(n,m,v){if(0!==e.length){var g=new i.Vector3,y=v.w/v.z,x=.5*v.z,M=.5*v.w,b=16/v.w,_=new i.Vector2(b*y,b),S=new i.Vector3(1,1,0),w=new i.Vector2(1,1);void 0===s&&r(),f.useProgram(s),d.initAttributes(),d.enableAttribute(h.vertex),d.enableAttribute(h.uv),d.disableUnusedAttributes(),f.uniform1i(u.occlusionMap,0),f.uniform1i(u.map,1),f.bindBuffer(f.ARRAY_BUFFER,a),f.vertexAttribPointer(h.vertex,2,f.FLOAT,!1,16,0),f.vertexAttribPointer(h.uv,2,f.FLOAT,!1,16,8),f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,o),d.disable(f.CULL_FACE),d.setDepthWrite(!1);for(var E=0,T=e.length;E0&&w.x0&&w.y.001&&R.scale>.001&&(S.x=R.x,S.y=R.y,S.z=R.z,b=R.size*R.scale/v.w,_.x=b*y,_.y=b,f.uniform3f(u.screenPosition,S.x,S.y,S.z),f.uniform2f(u.scale,_.x,_.y),f.uniform1f(u.rotation,R.rotation),f.uniform1f(u.opacity,R.opacity),f.uniform3f(u.color,R.color.r,R.color.g,R.color.b),d.setBlending(R.blending,R.blendEquation,R.blendSrc,R.blendDst),t.setTexture(R.texture,1),f.drawElements(f.TRIANGLES,6,f.UNSIGNED_SHORT,0))}}}d.enable(f.CULL_FACE),d.enable(f.DEPTH_TEST),d.setDepthWrite(!0),t.resetGLState()}}},i.WebGLObjects=function(t,e,r){function n(e){var r=c.get(e);e.geometry instanceof i.Geometry&&r.updateFromObject(e);var n=r.index,o=r.attributes;null!==n&&a(n,t.ELEMENT_ARRAY_BUFFER);for(var s in o)a(o[s],t.ARRAY_BUFFER);var h=r.morphAttributes;for(var s in h)for(var u=h[s],l=0,p=u.length;l65535?Uint32Array:Uint16Array,x=new i.BufferAttribute(new y(o),1);return a(x,t.ELEMENT_ARRAY_BUFFER),n.wireframe=x,x}function l(t,e,i){if(e>i){var r=e;e=i,i=r}var n=t[e];return void 0===n?(t[e]=[i],!0):n.indexOf(i)===-1&&(n.push(i),!0)}var c=new i.WebGLGeometries(t,e,r);this.getAttributeBuffer=h,this.getWireframeAttribute=u,this.update=n},i.WebGLProgram=function(){function t(t){switch(t){case i.LinearEncoding:return["Linear","( value )"];case i.sRGBEncoding:return["sRGB","( value )"];case i.RGBEEncoding:return["RGBE","( value )"];case i.RGBM7Encoding:return["RGBM","( value, 7.0 )"];case i.RGBM16Encoding:return["RGBM","( value, 16.0 )"];case i.RGBDEncoding:return["RGBD","( value, 256.0 )"];case i.GammaEncoding:return["Gamma","( value, float( GAMMA_FACTOR ) )"];default:throw new Error("unsupported encoding: "+t)}}function e(e,i){var r=t(i);return"vec4 "+e+"( vec4 value ) { return "+r[0]+"ToLinear"+r[1]+"; }"}function r(e,i){var r=t(i);return"vec4 "+e+"( vec4 value ) { return LinearTo"+r[0]+r[1]+"; }"}function n(t,e){var r;switch(e){case i.LinearToneMapping:r="Linear";break;case i.ReinhardToneMapping:r="Reinhard";break;case i.Uncharted2ToneMapping:r="Uncharted2";break;case i.CineonToneMapping:r="OptimizedCineon";break;default:throw new Error("unsupported toneMapping: "+e)}return"vec3 "+t+"( vec3 color ) { return "+r+"ToneMapping( color ); }"}function a(t,e,i){t=t||{};var r=[t.derivatives||e.envMapCubeUV||e.bumpMap||e.normalMap||e.flatShading?"#extension GL_OES_standard_derivatives : enable":"",(t.fragDepth||e.logarithmicDepthBuffer)&&i.get("EXT_frag_depth")?"#extension GL_EXT_frag_depth : enable":"",t.drawBuffers&&i.get("WEBGL_draw_buffers")?"#extension GL_EXT_draw_buffers : require":"",(t.shaderTextureLOD||e.envMap)&&i.get("EXT_shader_texture_lod")?"#extension GL_EXT_shader_texture_lod : enable":""];return r.filter(u).join("\n")}function o(t){var e=[];for(var i in t){var r=t[i];r!==!1&&e.push("#define "+i+" "+r)}return e.join("\n")}function s(t,e,i){for(var r={},n=t.getProgramParameter(e,t.ACTIVE_UNIFORMS),a=0;a");return c(r)}var r=/#include +<([\w\d.]+)>/g;return t.replace(r,e)}function p(t){function e(t,e,i,r){for(var n="",a=parseInt(e);a0?t.gammaFactor:1,C=a(y,v,t.extensions),R=o(x),U=g.createProgram();m instanceof i.RawShaderMaterial?(T="",A=""):(T=["precision "+v.precision+" float;","precision "+v.precision+" int;","#define SHADER_NAME "+m.__webglShader.name,R,v.supportsVertexTextures?"#define VERTEX_TEXTURES":"","#define GAMMA_FACTOR "+L,"#define MAX_BONES "+v.maxBones,v.map?"#define USE_MAP":"",v.envMap?"#define USE_ENVMAP":"",v.envMap?"#define "+w:"",v.lightMap?"#define USE_LIGHTMAP":"",v.aoMap?"#define USE_AOMAP":"",v.emissiveMap?"#define USE_EMISSIVEMAP":"",v.bumpMap?"#define USE_BUMPMAP":"",v.normalMap?"#define USE_NORMALMAP":"",v.displacementMap&&v.supportsVertexTextures?"#define USE_DISPLACEMENTMAP":"",v.specularMap?"#define USE_SPECULARMAP":"",v.roughnessMap?"#define USE_ROUGHNESSMAP":"",v.metalnessMap?"#define USE_METALNESSMAP":"",v.alphaMap?"#define USE_ALPHAMAP":"",v.vertexColors?"#define USE_COLOR":"",v.flatShading?"#define FLAT_SHADED":"",v.skinning?"#define USE_SKINNING":"",v.useVertexTexture?"#define BONE_TEXTURE":"",v.morphTargets?"#define USE_MORPHTARGETS":"",v.morphNormals&&v.flatShading===!1?"#define USE_MORPHNORMALS":"",v.doubleSided?"#define DOUBLE_SIDED":"",v.flipSided?"#define FLIP_SIDED":"",v.shadowMapEnabled?"#define USE_SHADOWMAP":"",v.shadowMapEnabled?"#define "+_:"",v.pointLightShadows>0?"#define POINT_LIGHT_SHADOWS":"",v.sizeAttenuation?"#define USE_SIZEATTENUATION":"",v.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",v.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(u).join("\n"),A=[C,"precision "+v.precision+" float;","precision "+v.precision+" int;","#define SHADER_NAME "+m.__webglShader.name,R,v.alphaTest?"#define ALPHATEST "+v.alphaTest:"","#define GAMMA_FACTOR "+L,v.useFog&&v.fog?"#define USE_FOG":"",v.useFog&&v.fogExp?"#define FOG_EXP2":"",v.map?"#define USE_MAP":"",v.envMap?"#define USE_ENVMAP":"",v.envMap?"#define "+S:"",v.envMap?"#define "+w:"",v.envMap?"#define "+E:"",v.lightMap?"#define USE_LIGHTMAP":"",v.aoMap?"#define USE_AOMAP":"",v.emissiveMap?"#define USE_EMISSIVEMAP":"",v.bumpMap?"#define USE_BUMPMAP":"",v.normalMap?"#define USE_NORMALMAP":"",v.specularMap?"#define USE_SPECULARMAP":"",v.roughnessMap?"#define USE_ROUGHNESSMAP":"",v.metalnessMap?"#define USE_METALNESSMAP":"",v.alphaMap?"#define USE_ALPHAMAP":"",v.vertexColors?"#define USE_COLOR":"",v.flatShading?"#define FLAT_SHADED":"",v.doubleSided?"#define DOUBLE_SIDED":"",v.flipSided?"#define FLIP_SIDED":"",v.shadowMapEnabled?"#define USE_SHADOWMAP":"",v.shadowMapEnabled?"#define "+_:"",v.pointLightShadows>0?"#define POINT_LIGHT_SHADOWS":"",v.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",v.physicallyCorrectLights?"#define PHYSICALLY_CORRECT_LIGHTS":"",v.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",v.logarithmicDepthBuffer&&t.extensions.get("EXT_frag_depth")?"#define USE_LOGDEPTHBUF_EXT":"",v.envMap&&t.extensions.get("EXT_shader_texture_lod")?"#define TEXTURE_LOD_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;",v.toneMapping!==i.NoToneMapping?"#define TONE_MAPPING":"",v.toneMapping!==i.NoToneMapping?i.ShaderChunk.tonemapping_pars_fragment:"",v.toneMapping!==i.NoToneMapping?n("toneMapping",v.toneMapping):"",v.outputEncoding||v.mapEncoding||v.envMapEncoding||v.emissiveMapEncoding?i.ShaderChunk.encodings_pars_fragment:"",v.mapEncoding?e("mapTexelToLinear",v.mapEncoding):"",v.envMapEncoding?e("envMapTexelToLinear",v.envMapEncoding):"",v.emissiveMapEncoding?e("emissiveMapTexelToLinear",v.emissiveMapEncoding):"",v.outputEncoding?r("linearToOutputTexel",v.outputEncoding):"","\n"].filter(u).join("\n")),M=c(M,v),M=l(M,v),b=c(b,v),b=l(b,v),m instanceof i.ShaderMaterial==!1&&(M=p(M),b=p(b));var F=T+M,P=A+b,N=i.WebGLShader(g,g.VERTEX_SHADER,F),D=i.WebGLShader(g,g.FRAGMENT_SHADER,P);g.attachShader(U,N),g.attachShader(U,D),void 0!==m.index0AttributeName?g.bindAttribLocation(U,0,m.index0AttributeName):v.morphTargets===!0&&g.bindAttribLocation(U,0,"position"),g.linkProgram(U);var B=g.getProgramInfoLog(U),O=g.getShaderInfoLog(N),I=g.getShaderInfoLog(D),V=!0,z=!0;g.getProgramParameter(U,g.LINK_STATUS)===!1?V=!1:""!==B||""!==O&&""!==I||(z=!1),z&&(this.diagnostics={runnable:V,material:m,programLog:B,vertexShader:{log:O,prefix:T},fragmentShader:{log:I,prefix:A}}),g.deleteShader(N),g.deleteShader(D);var G;this.getUniforms=function(){return void 0===G&&(G=s(g,U)),G};var k;return this.getAttributes=function(){return void 0===k&&(k=h(g,U)),k},this.destroy=function(){g.deleteProgram(U),this.program=void 0},Object.defineProperties(this,{uniforms:{get:function(){return this.getUniforms()}},attributes:{get:function(){return this.getAttributes()}}}),this.id=f++,this.code=d,this.usedTimes=1,this.program=U,this.vertexShader=N,this.fragmentShader=D,this}}(),i.WebGLRenderTarget=function(t,e,r){this.uuid=i.Math.generateUUID(),this.width=t,this.height=e,this.scissor=new i.Vector4(0,0,t,e),this.scissorTest=!1,this.viewport=new i.Vector4(0,0,t,e),r=r||{},void 0===r.minFilter&&(r.minFilter=i.LinearFilter),this.texture=new i.Texture((void 0),(void 0),r.wrapS,r.wrapT,r.magFilter,r.minFilter,r.format,r.type,r.anisotropy),this.depthBuffer=void 0===r.depthBuffer||r.depthBuffer,this.stencilBuffer=void 0===r.stencilBuffer||r.stencilBuffer},i.WebGLRenderTarget.prototype={constructor:i.WebGLRenderTarget,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},dispose:function(){this.dispatchEvent({type:"dispose"})}},i.EventDispatcher.prototype.apply(i.WebGLRenderTarget.prototype),i.WebGLRenderTargetCube=function(t,e,r){i.WebGLRenderTarget.call(this,t,e,r),this.activeCubeFace=0,this.activeMipMapLevel=0},i.WebGLRenderTargetCube.prototype=Object.create(i.WebGLRenderTarget.prototype),i.WebGLRenderTargetCube.prototype.constructor=i.WebGLRenderTargetCube,i.WebGLPrograms=function(t,e){function r(t){if(e.floatVertexTextures&&t&&t.skeleton&&t.skeleton.useVertexTexture)return 1024;var r=e.maxVertexUniforms,n=Math.floor((r-20)/4),a=n;return void 0!==t&&t instanceof i.SkinnedMesh&&(a=Math.min(t.skeleton.bones.length,a),a0,shadowMapType:t.shadowMap.type,toneMapping:t.toneMapping,physicallyCorrectLights:t.physicallyCorrectLights,premultipliedAlpha:a.premultipliedAlpha,alphaTest:a.alphaTest,doubleSided:a.side===i.DoubleSide,flipSided:a.side===i.BackSide};return f},this.getProgramCode=function(t,e){var i=[];if(e.shaderID?i.push(e.shaderID):(i.push(t.fragmentShader),i.push(t.vertexShader)),void 0!==t.defines)for(var r in t.defines)i.push(r),i.push(t.defines[r]);for(var n=0;n 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")),p.compileShader(i),p.compileShader(r),p.attachShader(e,i),p.attachShader(e,r),p.linkProgram(e),e}function a(t,e){return t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:e.id-t.id}var o,s,h,u,l,c,p=t.context,f=t.state,d=new i.Vector3,m=new i.Quaternion,v=new i.Vector3;this.render=function(n,g){if(0!==e.length){void 0===h&&r(),p.useProgram(h),f.initAttributes(),f.enableAttribute(u.position),f.enableAttribute(u.uv),f.disableUnusedAttributes(),f.disable(p.CULL_FACE),f.enable(p.BLEND),p.bindBuffer(p.ARRAY_BUFFER,o),p.vertexAttribPointer(u.position,2,p.FLOAT,!1,16,0),p.vertexAttribPointer(u.uv,2,p.FLOAT,!1,16,8),p.bindBuffer(p.ELEMENT_ARRAY_BUFFER,s),p.uniformMatrix4fv(l.projectionMatrix,!1,g.projectionMatrix.elements),f.activeTexture(p.TEXTURE0),p.uniform1i(l.map,0);var y=0,x=0,M=n.fog;M?(p.uniform3f(l.fogColor,M.color.r,M.color.g,M.color.b),M instanceof i.Fog?(p.uniform1f(l.fogNear,M.near),p.uniform1f(l.fogFar,M.far),p.uniform1i(l.fogType,1),y=1,x=1):M instanceof i.FogExp2&&(p.uniform1f(l.fogDensity,M.density),p.uniform1i(l.fogType,2),y=2,x=2)):(p.uniform1i(l.fogType,0),y=0,x=0);for(var b=0,_=e.length;b<_;b++){var S=e[b];S.modelViewMatrix.multiplyMatrices(g.matrixWorldInverse,S.matrixWorld),S.z=-S.modelViewMatrix.elements[14]}e.sort(a);for(var w=[],b=0,_=e.length;b<_;b++){var S=e[b],E=S.material;p.uniform1f(l.alphaTest,E.alphaTest),p.uniformMatrix4fv(l.modelViewMatrix,!1,S.modelViewMatrix.elements),S.matrixWorld.decompose(d,m,v),w[0]=v.x,w[1]=v.y;var T=0;n.fog&&E.fog&&(T=x),y!==T&&(p.uniform1i(l.fogType,T),y=T),null!==E.map?(p.uniform2f(l.uvOffset,E.map.offset.x,E.map.offset.y),p.uniform2f(l.uvScale,E.map.repeat.x,E.map.repeat.y)):(p.uniform2f(l.uvOffset,0,0),p.uniform2f(l.uvScale,1,1)),p.uniform1f(l.opacity,E.opacity),p.uniform3f(l.color,E.color.r,E.color.g,E.color.b),p.uniform1f(l.rotation,E.rotation),p.uniform2fv(l.scale,w),f.setBlending(E.blending,E.blendEquation,E.blendSrc,E.blendDst),f.setDepthTest(E.depthTest),f.setDepthWrite(E.depthWrite),E.map&&E.map.image&&E.map.image.width?t.setTexture(E.map,0):t.setTexture(c,0),p.drawElements(p.TRIANGLES,6,p.UNSIGNED_SHORT,0)}f.enable(p.CULL_FACE),t.resetGLState()}}},i.LensFlarePlugin=function(t,e){function r(){var t=new Float32Array([-1,-1,0,0,1,-1,1,0,1,1,1,1,-1,1,0,1]),e=new Uint16Array([0,1,2,0,2,3]);a=f.createBuffer(),o=f.createBuffer(),f.bindBuffer(f.ARRAY_BUFFER,a),f.bufferData(f.ARRAY_BUFFER,t,f.STATIC_DRAW),f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,o),f.bufferData(f.ELEMENT_ARRAY_BUFFER,e,f.STATIC_DRAW),c=f.createTexture(),p=f.createTexture(),d.bindTexture(f.TEXTURE_2D,c),f.texImage2D(f.TEXTURE_2D,0,f.RGB,16,16,0,f.RGB,f.UNSIGNED_BYTE,null),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.NEAREST),d.bindTexture(f.TEXTURE_2D,p),f.texImage2D(f.TEXTURE_2D,0,f.RGBA,16,16,0,f.RGBA,f.UNSIGNED_BYTE,null),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.NEAREST),l=f.getParameter(f.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0;var i;i=l?{vertexShader:["uniform lowp int renderType;","uniform vec3 screenPosition;","uniform vec2 scale;","uniform float rotation;","uniform sampler2D occlusionMap;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","varying float vVisibility;","void main() {","vUV = uv;","vec2 pos = position;","if ( renderType == 2 ) {","vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );","vVisibility = visibility.r / 9.0;","vVisibility *= 1.0 - visibility.g / 9.0;","vVisibility *= visibility.b / 9.0;","vVisibility *= 1.0 - visibility.a / 9.0;","pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;","pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;","}","gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );","}"].join("\n"),fragmentShader:["uniform lowp int renderType;","uniform sampler2D map;","uniform float opacity;","uniform vec3 color;","varying vec2 vUV;","varying float vVisibility;","void main() {","if ( renderType == 0 ) {","gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );","} else if ( renderType == 1 ) {","gl_FragColor = texture2D( map, vUV );","} else {","vec4 texture = texture2D( map, vUV );","texture.a *= opacity * vVisibility;","gl_FragColor = texture;","gl_FragColor.rgb *= color;","}","}"].join("\n")}:{vertexShader:["uniform lowp int renderType;","uniform vec3 screenPosition;","uniform vec2 scale;","uniform float rotation;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","void main() {","vUV = uv;","vec2 pos = position;","if ( renderType == 2 ) {","pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;","pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;","}","gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );","}"].join("\n"),fragmentShader:["precision mediump float;","uniform lowp int renderType;","uniform sampler2D map;","uniform sampler2D occlusionMap;","uniform float opacity;","uniform vec3 color;","varying vec2 vUV;","void main() {","if ( renderType == 0 ) {","gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );","} else if ( renderType == 1 ) {","gl_FragColor = texture2D( map, vUV );","} else {","float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;","visibility = ( 1.0 - visibility / 4.0 );","vec4 texture = texture2D( map, vUV );","texture.a *= opacity * visibility;","gl_FragColor = texture;","gl_FragColor.rgb *= color;","}","}"].join("\n")},s=n(i),h={vertex:f.getAttribLocation(s,"position"),uv:f.getAttribLocation(s,"uv")},u={renderType:f.getUniformLocation(s,"renderType"),map:f.getUniformLocation(s,"map"),occlusionMap:f.getUniformLocation(s,"occlusionMap"),opacity:f.getUniformLocation(s,"opacity"),color:f.getUniformLocation(s,"color"),scale:f.getUniformLocation(s,"scale"),rotation:f.getUniformLocation(s,"rotation"),screenPosition:f.getUniformLocation(s,"screenPosition")}}function n(e){var i=f.createProgram(),r=f.createShader(f.FRAGMENT_SHADER),n=f.createShader(f.VERTEX_SHADER),a="precision "+t.getPrecision()+" float;\n";return f.shaderSource(r,a+e.fragmentShader),f.shaderSource(n,a+e.vertexShader),f.compileShader(r),f.compileShader(n),f.attachShader(i,r),f.attachShader(i,n),f.linkProgram(i),i}var a,o,s,h,u,l,c,p,f=t.context,d=t.state;this.render=function(n,m,v){if(0!==e.length){var g=new i.Vector3,y=v.w/v.z,x=.5*v.z,M=.5*v.w,b=16/v.w,_=new i.Vector2(b*y,b),S=new i.Vector3(1,1,0),w=new i.Vector2(1,1);void 0===s&&r(),f.useProgram(s),d.initAttributes(),d.enableAttribute(h.vertex),d.enableAttribute(h.uv),d.disableUnusedAttributes(),f.uniform1i(u.occlusionMap,0),f.uniform1i(u.map,1),f.bindBuffer(f.ARRAY_BUFFER,a),f.vertexAttribPointer(h.vertex,2,f.FLOAT,!1,16,0),f.vertexAttribPointer(h.uv,2,f.FLOAT,!1,16,8),f.bindBuffer(f.ELEMENT_ARRAY_BUFFER,o),d.disable(f.CULL_FACE),d.setDepthWrite(!1);for(var E=0,T=e.length;E0&&w.x0&&w.y.001&&R.scale>.001&&(S.x=R.x,S.y=R.y,S.z=R.z,b=R.size*R.scale/v.w,_.x=b*y,_.y=b,f.uniform3f(u.screenPosition,S.x,S.y,S.z),f.uniform2f(u.scale,_.x,_.y),f.uniform1f(u.rotation,R.rotation),f.uniform1f(u.opacity,R.opacity),f.uniform3f(u.color,R.color.r,R.color.g,R.color.b),d.setBlending(R.blending,R.blendEquation,R.blendSrc,R.blendDst),t.setTexture(R.texture,1),f.drawElements(f.TRIANGLES,6,f.UNSIGNED_SHORT,0))}}}d.enable(f.CULL_FACE),d.enable(f.DEPTH_TEST),d.setDepthWrite(!0),t.resetGLState()}}},i.WebGLObjects=function(t,e,r){function n(e){var r=c.get(e);e.geometry instanceof i.Geometry&&r.updateFromObject(e);var n=r.index,o=r.attributes;null!==n&&a(n,t.ELEMENT_ARRAY_BUFFER);for(var s in o)a(o[s],t.ARRAY_BUFFER);var h=r.morphAttributes;for(var s in h)for(var u=h[s],l=0,p=u.length;l65535?Uint32Array:Uint16Array,x=new i.BufferAttribute(new y(o),1);return a(x,t.ELEMENT_ARRAY_BUFFER),n.wireframe=x,x}function l(t,e,i){if(e>i){var r=e;e=i,i=r}var n=t[e];return void 0===n?(t[e]=[i],!0):n.indexOf(i)===-1&&(n.push(i),!0)}var c=new i.WebGLGeometries(t,e,r);this.getAttributeBuffer=h,this.getWireframeAttribute=u,this.update=n},i.WebGLProgram=function(){function t(t){switch(t){case i.LinearEncoding:return["Linear","( value )"];case i.sRGBEncoding:return["sRGB","( value )"];case i.RGBEEncoding:return["RGBE","( value )"];case i.RGBM7Encoding:return["RGBM","( value, 7.0 )"];case i.RGBM16Encoding:return["RGBM","( value, 16.0 )"];case i.RGBDEncoding:return["RGBD","( value, 256.0 )"];case i.GammaEncoding:return["Gamma","( value, float( GAMMA_FACTOR ) )"];default:throw new Error("unsupported encoding: "+t)}}function e(e,i){var r=t(i);return"vec4 "+e+"( vec4 value ) { return "+r[0]+"ToLinear"+r[1]+"; }"}function r(e,i){var r=t(i);return"vec4 "+e+"( vec4 value ) { return LinearTo"+r[0]+r[1]+"; }"}function n(t,e){var r;switch(e){case i.LinearToneMapping:r="Linear";break;case i.ReinhardToneMapping:r="Reinhard";break;case i.Uncharted2ToneMapping:r="Uncharted2";break;case i.CineonToneMapping:r="OptimizedCineon";break;default:throw new Error("unsupported toneMapping: "+e)}return"vec3 "+t+"( vec3 color ) { return "+r+"ToneMapping( color ); }"}function a(t,e,i){t=t||{};var r=[t.derivatives||e.envMapCubeUV||e.bumpMap||e.normalMap||e.flatShading?"#extension GL_OES_standard_derivatives : enable":"",(t.fragDepth||e.logarithmicDepthBuffer)&&i.get("EXT_frag_depth")?"#extension GL_EXT_frag_depth : enable":"",t.drawBuffers&&i.get("WEBGL_draw_buffers")?"#extension GL_EXT_draw_buffers : require":"",(t.shaderTextureLOD||e.envMap)&&i.get("EXT_shader_texture_lod")?"#extension GL_EXT_shader_texture_lod : enable":""];return r.filter(u).join("\n")}function o(t){var e=[];for(var i in t){var r=t[i];r!==!1&&e.push("#define "+i+" "+r)}return e.join("\n")}function s(t,e,i){for(var r={},n=t.getProgramParameter(e,t.ACTIVE_UNIFORMS),a=0;a");return c(r)}var r=/#include +<([\w\d.]+)>/g;return t.replace(r,e)}function p(t){function e(t,e,i,r){for(var n="",a=parseInt(e);a0?t.gammaFactor:1,C=a(y,v,t.extensions),R=o(x),U=g.createProgram();m instanceof i.RawShaderMaterial?(T="",A=""):(T=["precision "+v.precision+" float;","precision "+v.precision+" int;","#define SHADER_NAME "+m.__webglShader.name,R,v.supportsVertexTextures?"#define VERTEX_TEXTURES":"","#define GAMMA_FACTOR "+L,"#define MAX_BONES "+v.maxBones,v.map?"#define USE_MAP":"",v.envMap?"#define USE_ENVMAP":"",v.envMap?"#define "+w:"",v.lightMap?"#define USE_LIGHTMAP":"",v.aoMap?"#define USE_AOMAP":"",v.emissiveMap?"#define USE_EMISSIVEMAP":"",v.bumpMap?"#define USE_BUMPMAP":"",v.normalMap?"#define USE_NORMALMAP":"",v.displacementMap&&v.supportsVertexTextures?"#define USE_DISPLACEMENTMAP":"",v.specularMap?"#define USE_SPECULARMAP":"",v.roughnessMap?"#define USE_ROUGHNESSMAP":"",v.metalnessMap?"#define USE_METALNESSMAP":"",v.alphaMap?"#define USE_ALPHAMAP":"",v.vertexColors?"#define USE_COLOR":"",v.flatShading?"#define FLAT_SHADED":"",v.skinning?"#define USE_SKINNING":"",v.useVertexTexture?"#define BONE_TEXTURE":"",v.morphTargets?"#define USE_MORPHTARGETS":"",v.morphNormals&&v.flatShading===!1?"#define USE_MORPHNORMALS":"",v.doubleSided?"#define DOUBLE_SIDED":"",v.flipSided?"#define FLIP_SIDED":"",v.shadowMapEnabled?"#define USE_SHADOWMAP":"",v.shadowMapEnabled?"#define "+_:"",v.pointLightShadows>0?"#define POINT_LIGHT_SHADOWS":"",v.sizeAttenuation?"#define USE_SIZEATTENUATION":"",v.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",v.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(u).join("\n"),A=[C,"precision "+v.precision+" float;","precision "+v.precision+" int;","#define SHADER_NAME "+m.__webglShader.name,R,v.alphaTest?"#define ALPHATEST "+v.alphaTest:"","#define GAMMA_FACTOR "+L,v.useFog&&v.fog?"#define USE_FOG":"",v.useFog&&v.fogExp?"#define FOG_EXP2":"",v.map?"#define USE_MAP":"",v.envMap?"#define USE_ENVMAP":"",v.envMap?"#define "+S:"",v.envMap?"#define "+w:"",v.envMap?"#define "+E:"",v.lightMap?"#define USE_LIGHTMAP":"",v.aoMap?"#define USE_AOMAP":"",v.emissiveMap?"#define USE_EMISSIVEMAP":"",v.bumpMap?"#define USE_BUMPMAP":"",v.normalMap?"#define USE_NORMALMAP":"",v.specularMap?"#define USE_SPECULARMAP":"",v.roughnessMap?"#define USE_ROUGHNESSMAP":"",v.metalnessMap?"#define USE_METALNESSMAP":"",v.alphaMap?"#define USE_ALPHAMAP":"",v.vertexColors?"#define USE_COLOR":"",v.flatShading?"#define FLAT_SHADED":"",v.doubleSided?"#define DOUBLE_SIDED":"",v.flipSided?"#define FLIP_SIDED":"",v.shadowMapEnabled?"#define USE_SHADOWMAP":"",v.shadowMapEnabled?"#define "+_:"",v.pointLightShadows>0?"#define POINT_LIGHT_SHADOWS":"",v.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",v.physicallyCorrectLights?"#define PHYSICALLY_CORRECT_LIGHTS":"",v.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",v.logarithmicDepthBuffer&&t.extensions.get("EXT_frag_depth")?"#define USE_LOGDEPTHBUF_EXT":"",v.envMap&&t.extensions.get("EXT_shader_texture_lod")?"#define TEXTURE_LOD_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;",v.toneMapping!==i.NoToneMapping?"#define TONE_MAPPING":"",v.toneMapping!==i.NoToneMapping?i.ShaderChunk.tonemapping_pars_fragment:"",v.toneMapping!==i.NoToneMapping?n("toneMapping",v.toneMapping):"",v.outputEncoding||v.mapEncoding||v.envMapEncoding||v.emissiveMapEncoding?i.ShaderChunk.encodings_pars_fragment:"",v.mapEncoding?e("mapTexelToLinear",v.mapEncoding):"",v.envMapEncoding?e("envMapTexelToLinear",v.envMapEncoding):"",v.emissiveMapEncoding?e("emissiveMapTexelToLinear",v.emissiveMapEncoding):"",v.outputEncoding?r("linearToOutputTexel",v.outputEncoding):"","\n"].filter(u).join("\n")),M=c(M,v),M=l(M,v),b=c(b,v),b=l(b,v),m instanceof i.ShaderMaterial==!1&&(M=p(M),b=p(b));var F=T+M,P=A+b,N=i.WebGLShader(g,g.VERTEX_SHADER,F),D=i.WebGLShader(g,g.FRAGMENT_SHADER,P);g.attachShader(U,N),g.attachShader(U,D),void 0!==m.index0AttributeName?g.bindAttribLocation(U,0,m.index0AttributeName):v.morphTargets===!0&&g.bindAttribLocation(U,0,"position"),g.linkProgram(U);var B=g.getProgramInfoLog(U),O=g.getShaderInfoLog(N),I=g.getShaderInfoLog(D),V=!0,z=!0;g.getProgramParameter(U,g.LINK_STATUS)===!1?V=!1:""!==B||""!==O&&""!==I||(z=!1),z&&(this.diagnostics={runnable:V,material:m,programLog:B,vertexShader:{log:O,prefix:T},fragmentShader:{log:I,prefix:A}}),g.deleteShader(N),g.deleteShader(D);var G;this.getUniforms=function(){return void 0===G&&(G=s(g,U)),G};var k;return this.getAttributes=function(){return void 0===k&&(k=h(g,U)),k},this.destroy=function(){g.deleteProgram(U),this.program=void 0},Object.defineProperties(this,{uniforms:{get:function(){return this.getUniforms()}},attributes:{get:function(){return this.getAttributes()}}}),this.id=f++,this.code=d,this.usedTimes=1,this.program=U,this.vertexShader=N,this.fragmentShader=D,this}}(),i.WebGLRenderTarget=function(t,e,r){this.uuid=i.Math.generateUUID(),this.width=t,this.height=e,this.scissor=new i.Vector4(0,0,t,e),this.scissorTest=!1,this.viewport=new i.Vector4(0,0,t,e),r=r||{},void 0===r.minFilter&&(r.minFilter=i.LinearFilter),this.texture=new i.Texture((void 0),(void 0),r.wrapS,r.wrapT,r.magFilter,r.minFilter,r.format,r.type,r.anisotropy),this.depthBuffer=void 0===r.depthBuffer||r.depthBuffer,this.stencilBuffer=void 0===r.stencilBuffer||r.stencilBuffer},i.WebGLRenderTarget.prototype={constructor:i.WebGLRenderTarget,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},dispose:function(){this.dispatchEvent({type:"dispose"})}},i.EventDispatcher.prototype.apply(i.WebGLRenderTarget.prototype),i.WebGLRenderTargetCube=function(t,e,r){i.WebGLRenderTarget.call(this,t,e,r),this.activeCubeFace=0,this.activeMipMapLevel=0},i.WebGLRenderTargetCube.prototype=Object.create(i.WebGLRenderTarget.prototype),i.WebGLRenderTargetCube.prototype.constructor=i.WebGLRenderTargetCube,i.WebGLPrograms=function(t,e){function r(t){if(e.floatVertexTextures&&t&&t.skeleton&&t.skeleton.useVertexTexture)return 1024;var r=e.maxVertexUniforms,n=Math.floor((r-20)/4),a=n;return void 0!==t&&t instanceof i.SkinnedMesh&&(a=Math.min(t.skeleton.bones.length,a),a0,shadowMapType:t.shadowMap.type,toneMapping:t.toneMapping,physicallyCorrectLights:t.physicallyCorrectLights,premultipliedAlpha:a.premultipliedAlpha,alphaTest:a.alphaTest,doubleSided:a.side===i.DoubleSide,flipSided:a.side===i.BackSide};return f},this.getProgramCode=function(t,e){var i=[];if(e.shaderID?i.push(e.shaderID):(i.push(t.fragmentShader),i.push(t.vertexShader)),void 0!==t.defines)for(var r in t.defines)i.push(r),i.push(t.defines[r]);for(var n=0;n