memoscan
← all memos

Memo 0xf10aba6d…2b18f9 on Ethereum

ttributes(e)}bindAttributes(e){e.attributeLocations.forEach((t,{name:s,type:i})=>{if(!this.attributes[s]){console.warn(`active attribute ${s} not being supplied`);return}const n=this.attributes[s];this.gl.bindBuffer(n.target,n.buffer),this.glState.boundBuffer=n.buffer;let l=1;i===35674&&(l=2),i===35675&&(l=3),i===35676&&(l=4);const o=n.size/l,h=l===1?0:l*l*4,d=l===1?0:l*4;for(let u=0;u<l;u++)this.gl.vertexAttribPointer(t+u,o,n.type,n.normalized,n.stride+h,n.offset+u*d),this.gl.enableVertexAttribArray(t+u),this.gl.renderer.vertexAttribDivisor(t+u,n.divisor)}),this.attributes.index&&this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.attributes.index.buffer)}draw({program:e,mode:t=this.gl.TRIANGLES}){this.gl.renderer.currentGeometry!==`${this.id}_${e.attributeOrder}`&&(this.VAOs[e.attributeOrder]||this.createVAO(e),this.gl.renderer.bindVertexArray(this.VAOs[e.attributeOrder]),this.gl.renderer.currentGeometry=`${this.id}_${e.attributeOrder}`),e.attributeLocations.forEach((i,{name:n})=>{const l=this.attributes[n];l.needsUpdate&&this.updateAttribute(l)});let s=2;this.attributes.index?.type===this.gl.UNSIGNED_INT&&(s=4),this.attributes.index?this.gl.drawElements(t,this.drawRange.count,this.attributes.index.type,this.attributes.index.offset+this.drawRange.start*s):this.gl.drawArrays(t,this.drawRange.start,this.drawRange.count)}getPosition(){const e=this.attributes.position;if(e.data)return e;if(!He)return He=!0}remove(){for(let e in this.VAOs)this.gl.renderer.deleteVertexArray(this.VAOs[e]),delete this.VAOs[e];for(let e in this.attributes)this.gl.deleteBuffer(this.attributes[e].buffer),delete this.attributes[e]}}let ji=1;const We={};class ae{constructor(e,{vertex:t,fragment:s,uniforms:i={},transparent:n=!1,cullFace:l=e.BACK,frontFace:o=e.CCW,depthTest:h=!0,depthWrite:d=!0,depthFunc:u=e.LESS}={}){e.canvas||console.error("gl not passed as first argument to Program"),this.gl=e,this.uniforms=i,this.id=ji++,t||console.warn("vertex shader not supplied"),s||console.warn("fragment shader not supplied"),this.transparent=n,this.cullFace=l,this.frontFace=o,this.depthTest=h,this.depthWrite=d,this.depthFunc=u,this.blendFunc={},this.blendEquation={},this.transparent&&!this.blendFunc.src&&(this.gl.renderer.premultipliedAlpha?this.setBlendFunc(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.setBlendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA));const f=e.createShader(e.VERTEX_SHADER);e.shaderSource(f,t),e.compileShader(f),e.getShaderInfoLog(f)!==""&&console.warn(`${e.getShaderInfoLog(f)} Vertex Shader ${Ye(t)}`);const g=e.createShader(e.FRAGMENT_SHADER);if(e.shaderSource(g,s),e.compileShader(g),e.getShaderInfoLog(g)!==""&&console.warn(`${e.getShaderInfoLog(g)} Fragment Shader ${Ye(s)}`),this.program=e.createProgram(),e.attachShader(this.program,f),e.attachShader(this.program,g),e.linkProgram(this.program),!e.getProgramParameter(this.program,e.LINK_STATUS))return console.warn(e.getProgramInfoLog(this.program));e.deleteShader(f),e.deleteShader(g),this.uniformLocations=new Map;let _=e.getProgramParameter(this.program,e.ACTIVE_UNIFORMS);for(let w=0;w<_;w++){let v=e.getActiveUniform(this.program,w);this.uniformLocations.set(v,e.getUniformLocation(this.program,v.name));const x=v.name.match(/(\w+)/g);v.uniformName=x[0],x.length===3?(v.isStructArray=!0,v.structIndex=Number(x[1]),v.structProperty=x[2]):x.length===2&&isNaN(Number(x[1]))&&(v.isStruct=!0,v.structProperty=x[1])}this.attributeLocations=new Map;const m=[],p=e.getProgramParameter(this.program,e.ACTIVE_ATTRIBUTES);for(let w=0;w<p;w++){const v=e.getActiveAttrib(this.program,w),x=e.getAttribLocation(this.program,v.name);x!==-1&&(m[x]=v.name,this.attributeLocations.set(v,x))}this.attributeOrder=m.join("")}setBlendFunc(e,t,s,i){this.blendFunc.src=e,this.blendFunc.dst=t,this.blendFunc.srcAlpha=s,this.blendFunc.dstAlpha=i,e&&(this.transparent=!0)}setBlendEquation(e,t){this.blendEquation.modeRGB=e,this.blendEquation.modeAlpha=t}applyState(){this.depthTest?this.gl.renderer.enable(this.gl.DEPTH_TEST):this.gl.renderer.disable(this.gl.DEPTH_TEST),this.cullFace?this.gl.renderer.enable(this.gl.CULL_FACE):this.gl.renderer.disable(this.gl.CULL_FACE),this.blendFunc.src?this.gl.renderer.enable(this.gl.BLEND):this.gl.renderer.disable(this.gl.BLEND),this.cullFace&&this.gl.renderer.setCullFace(this.cullFace),this.gl.renderer.setFrontFace(this.frontFace),this.gl.renderer.setDepthMask(this.depthWrite),this.gl.renderer.setDepthFunc(this.depthFunc),this.blendFunc.src&&this.gl.renderer.setBlendFunc(this.blendFunc.src,this.blendFunc.dst,this.blendFunc.srcAlpha,this.blendFunc.dstAlpha),this.gl.renderer.setBlendEquation(this.blendEquation.modeRGB,this.blendEquation.modeAlpha)}use({flipFaces:e=!1}={}){let t=-1;this.gl.renderer.state.currentProgram===this.id||(this.gl.useProgram(this.program),this.gl.renderer.state.currentProgram=this.id),this.uniformLocations.forEach((i,n)=>{let l=n.uniformName,o=this.uniforms[l];if(o.value.texture)return t=t+1,o.value.update(t),Fe(this.gl,n.type,i,t);if(o.value.length&&o.value[0].texture){const h=[];return o.value.forEach(d=>{t=t+1,d.update(t),h.push(t)}),Fe(this.gl,n.type,i,h)}Fe(this.gl,n.type,i,o.value)}),this.applyState(),e&&this.gl.renderer.setFrontFace(this.frontFace===this.gl.CCW?this.gl.CW:this.gl.CCW)}remove(){this.gl.deleteProgram(this.program)}}function Fe(r,e,t,s){s=s.length?qi(s):s;const i=r.renderer.state.uniformLocations.get(t);if(s.length)if(i===void 0||i.length!==s.length)r.renderer.state.uniformLocations.set(t,s.slice(0));else{if(Hi(i,s))return;i.set?i.set(s):Wi(i,s),r.renderer.state.uniformLocations.set(t,i)}else{if(i===s)return;r.renderer.state.uniformLocations.set(t,s)}switch(e){case 5126:return s.length?r.uniform1fv(t,s):r.uniform1f(t,s);case 35664:return r.uniform2fv(t,s);case 35665:return r.uniform3fv(t,s);case 35666:return r.uniform4fv(t,s);case 35670:case 5124:case 35678:case 35680:return s.length?r.uniform1iv(t,s):r.uniform1i(t,s);case 35671:case 35667:return r.uniform2iv(t,s);case 35672:case 35668:return r.uniform3iv(t,s);case 35673:case 35669:return r.uniform4iv(t,s);case 35674:return r.uniformMatrix2fv(t,!1,s);case 35675:return r.uniformMatrix3fv(t,!1,s);case 35676:return r.uniformMatrix4fv(t,!1,s)}}function Ye(r){let e=r.split(` `);for(let t=0;t<e.length;t++)e[t]=t+1+": "+e[t];return e.join(` `)}function qi(r){const e=r.length,t=r[0].length;if(t===void 0)return r;const s=e*t;let i=We[s];i||(We[s]=i=new Float32Array(s));for(let n=0;n<e;n++)i.set(r[n],n*t);return i}function Hi(r,e){if(r.length!==e.length)return!1;for(let t=0,s=r.length;t<s;t++)if(r[t]!==e[t])return!1;return!0}function Wi(r,e){for(let t=0,s=r.length;t<s;t++)r[t]=e[t]}new Z;let Yi=1;class Xi{constructor({canvas:e=document.createElement("canvas"),width:t=300,height:s=150,dpr:i=1,alpha:n=!1,depth:l=!0,stencil:o=!1,antialias:h=!1,premultipliedAlpha:d=!1,preserveDrawingBuffer:u=!1,powerPreference:f="default",autoClear:g=!0,webgl:_=2}={}){const m={alpha:n,depth:l,stencil:o,antialias:h,premultipliedAlpha:d,preserveDrawingBuffer:u,powerPreference:f};this.dpr=i,this.alpha=n,this.color=!0,this.depth=l,this.stencil=o,this.premultipliedAlpha=d,this.autoClear=g,this.id=Yi++,_===2&&(this.gl=e.getContext("webgl2",m)),this.isWebgl2=!!this.gl,this.gl||(this.gl=e.getContext("webgl",m)),this.gl||console.error("unable to create webgl context"),this.gl.renderer=this,this.setSize(t,s),this.state={},this.state.blendFunc={src:this.gl.ONE,dst:this.gl.ZERO},this.state.blendEquation={modeRGB:this.gl.FUNC_ADD},this.state.cullFace=null,this.state.frontFace=this.gl.CCW,this.state.depthMask=!0,this.state.depthFunc=this.gl.LESS,this.state.premultiplyAlpha=!1,this.state.flipY=!1,this.state.unpackAlignment=4,this.state.framebuffer=null,this.state.viewport={x:0,y:0,width:null,height:null},this.state.textureUnits=[],this.state.activeTextureUnit=0,this.state.boundBuffer=null,this.state.uniformLocations=new Map,this.state.currentProgram=null,this.extensions={},this.isWebgl2&&(this.getExtension("EXT_color_buffer_float"),this.getExtension("OES_texture_float_linear")),this.vertexAttribDivisor=this.getExtension("ANGLE_instanced_arrays","vertexAttribDivisor","vertexAttribDivisorANGLE"),this.drawArraysInstanced=this.getExtension("ANGLE_instanced_arrays","drawArraysInstanced","drawArraysInstancedANGLE"),this.drawElementsInstanced=this.getExtension("ANGLE_instanced_arrays","drawElementsInstanced","drawElementsInstancedANGLE"),this.createVertexArray=this.getExtension("OES_vertex_array_object","createVertexArray","createVertexArrayOES"),this.bindVertexArray=this.getExtension("OES_vertex_array_object","bindVertexArray","bindVertexArrayOES"),this.deleteVertexArray=this.getExtension("OES_vertex_array_object","deleteVertexArray","deleteVertexArrayOES"),this.drawBuffers=this.getExtension("WEBGL_draw_buffers","drawBuffers","drawBuffersWEBGL"),this.parameters={},this.parameters.maxTextureUnits=this.gl.getParameter(this.gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS),this.parameters.maxAnisotropy=this.getExtension("EXT_texture_filter_anisotropic")?this.gl.getParameter(this.getExtension("EXT_texture_filter_anisotropic").MAX_TEXTURE_MAX_ANISOTROPY_EXT):0}setSize(e,t){this.width=e,this.height=t,this.gl.canvas.width=e*this.dpr,this.gl.canvas.height=t*this.dpr,this.gl.canvas.style&&Object.assign(this.gl.canvas.style,{width:e+"px",height:t+"px"})}setViewport(e,t,s=0,i=0){this.state.viewport.width===e&&this.state.viewport.height===t||(this.state.viewport.width=e,this.state.viewport.height=t,this.state.viewport.x=s,this.state.viewport.y=i,this.gl.viewport(s,i,e,t))}setScissor(e,t,s=0,i=0){this.gl.scissor(s,i,e,t)}enable(e){this.state[e]!==!0&&(this.gl.enable(e),this.state[e]=!0)}disable(e){this.state[e]!==!1&&(this.gl.disable(e),this.state[e]=!1)}setBlendFunc(e,t,s,i){this.state.blendFunc.src===e&&this.state.blendFunc.dst===t&&this.state.blendFunc.srcAlpha===s&&this.state.blendFunc.dstAlpha===i||(this.state.blendFunc.src=e,this.state.blendFunc.dst=t,this.state.blendFunc.srcAlpha=s,this.state.blendFunc.dstAlpha=i,s!==void 0?this.gl.blendFuncSeparate(e,t,s,i):this.gl.blendFunc(e,t))}setBlendEquation(e,t){e=e||this.gl.FUNC_ADD,!(this.state.blendEquation.modeRGB===e&&this.state.blendEquation.modeAlpha===t)&&(this.state.blendEquation.modeRGB=e,this.state.blendEquation.modeAlpha=t,t!==void 0?this.gl.blendEquationSeparate(e,t):this.gl.blendEquation(e))}setCullFace(e){this.state.cullFace!==e&&(this.state.cullFace=e,this.gl.cullFace(e))}setFrontFace(e){this.state.frontFace!==e&&(this.state.frontFace=e,this.gl.frontFace(e))}setDepthMask(e){this.state.depthMask!==e&&(this.state.depthMask=e,this.gl.depthMask(e))}setDepthFunc(e){this.state.depthFunc!==e&&(this.state.depthFunc=e,this.gl.depthFunc(e))}activeTexture(e){this.state.activeTextureUnit!==e&&(this.state.activeTextureUnit=e,this.gl.activeTexture(this.gl.TEXTURE0+e))}bindFramebuffer({target:e=this.gl.FRAMEBUFFER,buffer:t=null}={}){this.state.framebuffer!==t&&(this.state.framebuffer=t,this.gl.bindFramebuffer(e,t))}getExtension(e,t,s){return t&&this.gl[t]?this.gl[t].bind(this.gl):(this.extensions[e]||(this.extensions[e]=this.gl.getExtension(e)),t?this.extensions[e]?this.extensions[e][s].bind(this.extensions[e]):null:this.extensions[e])}getRenderList({scene:e,camera:t,frustumCull:s,sort:i}){let n=[];return e.traverse(l=>{if(!l.visible)return!0;l.draw&&n.push(l)}),n}render({scene:e,camera:t,target:s=null,update:i=!0,sort:n=!0,frustumCull:l=!0,clear:o}){s===null?(this.bindFramebuffer(),this.setViewport(this.width*this.dpr,this.height*this.dpr)):(this.bindFramebuffer(s),this.setViewport(s.width,s.height)),(o||this.autoClear&&o!==!1)&&(this.depth&&(!s||s.depth)&&(this.enable(this.gl.DEPTH_TEST),this.setDepthMask(!0)),this.gl.clear((this.color?this.gl.COLOR_BUFFER_BIT:0)|(this.depth?this.gl.DEPTH_BUFFER_BIT:0)|(this.stencil?this.gl.STENCIL_BUFFER_BIT:0))),i&&e.updateMatrixWorld(),t&&t.updateMatrixWorld(),this.getRenderList({scene:e,camera:t,frustumCull:l,sort:n}).forEach(d=>{d.draw({camera:t})})}}class Ki extends Array{constructor(e=0,t=0,s=0,i=1){return super(e,t,s,i),this.onChange=()=>{},this}get x(){return this[0]}get y(){return this[1]}get z(){return this[2]}get w(){return this[3]}set x(e){this[0]=e,this.onChange()}set y(e){this[1]=e,this.onChange()}set z(e){this[2]=e,this.onChange()}set w(e){this[3]=e,this.onChange()}}function Ji(r,e,t,s,i){let n=1/Math.tan(e/2),l=1/(s-i);return r[0]=n/t,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=n,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=(i+s)*l,r[11]=-1,r[12]=0,r[13]=0,r[14]=2*i*s*l,r[15]=0,r}class $ extends Array{constructor(e=1,t=0,s=0,i=0,n=0,l=1,o=0,h=0,d=0,u=0,f=1,g=0,_=0,m=0,p=0,w=1){return super(e,t,s,i,n,l,o,h,d,u,f,g,_,m,p,w),this}get x(){return this[12]}get y(){return this[13]}get z(){return this[14]}get w(){return this[15]}set x(e){this[12]=e}set y(e){this[13]=e}set z(e){this[14]=e}set w(e){this[15]=e}multiply(e,t){return this}identity(){}copy(e){return this}fromPerspective({fov:e,aspect:t,near:s,far:i}={}){return Ji(this,e,t,s,i),this}setPosition(e){return this.x=e[0],this.y=e[1],this.z=e[2],this}compose(e,t,s){return this}getRotation(e){return this}getTranslation(e){return this}getScaling(e){return this}}new $;class Zi extends Array{constructor(e=0,t=e,s=e,i="YXZ"){return super(e,t,s),this.order=i,this.onChange=()=>{},this}get x(){return this[0]}get y(){return this[1]}get z(){return this[2]}set x(e){this[0]=e,this.onChange()}set y(e){this[1]=e,this.onChange()}set z(e){this[2]=e,this.onChange()}set(e,t=e,s=e){return e.length?this.copy(e):(this[0]=e,this[1]=t,this[2]=s,this.onChange(),this)}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this.onChange(),this}reorder(e){}fromRotationMatrix(e,t=this.order){}fromQuaternion(e,t=this.order){}fromArray(e,t=0){}toArray(e=[],t=0){}}class Me{constructor(){this.parent=null,this.children=[],this.visible=!0,this.matrix=new $,this.worldMatrix=new $,this.matrixAutoUpdate=!0,this.position=new Z,this.quaternion=new Ki,this.scale=new Z(1),this.rotation=new Zi,this.up=new Z(0,1,0),this.rotation.onChange=()=>this.quaternion.fromEuler(this.rotation),this.quaternion.onChange=()=>this.rotation.fromQuaternion(this.quaternion)}setParent(e,t=!0){this.parent&&e!==this.parent&&this.parent.removeChild(this,!1),this.parent=e,t&&e&&e.addChild(this,!1)}addChild(e,t=!0){~this.children.indexOf(e)||this.children.push(e),t&&e.setParent(this,!1)}removeChild(e,t=!0){~this.children.indexOf(e)&&this.children.splice(this.children.indexOf(e),1),t&&e.setParent(null,!1)}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.worldMatrixNeedsUpdate||e)&&(this.parent===null?this.worldMatrix.copy(this.matrix):this.worldMatrix.multiply(this.parent.worldMatrix,this.matrix),this.worldMatrixNeedsUpdate=!1,e=!0);for(let t=0,s=this.children.length;t<s;t++)this.children[t].updateMatrixWorld(e)}updateMatrix(){this.matrix.compose(this.quaternion,this.position,this.scale),this.worldMatrixNeedsUpdate=!0}traverse(e){if(!e(this))for(let t=0,s=this.children.length;t<s;t++)this.children[t].traverse(e)}lookAt(e,t=!1){this.matrix.getRotation(this.quaternion),this.rotation.fromQuaternion(this.quaternion)}}const Qi=new $;class kt extends Me{constructor(e,{near:t=.1,far:s=100,fov:i=45,aspect:n=1,left:l,right:o,bottom:h,top:d,zoom:u=1}={}){super(),Object.assign(this,{near:t,far:s,fov:i,aspect:n,left:l,right:o,bottom:h,top:d,zoom:u}),this.projectionMatrix=new $,this.viewMatrix=new $,this.projectionViewMatrix=new $,this.worldPosition=new Z,this.type="perspective",this.perspective()}perspective({near:e=this.near,far:t=this.far,fov:s=this.fov,aspect:i=this.aspect}={}){return Object.assign(this,{near:e,far:t,fov:s,aspect:i}),this.projectionMatrix.fromPerspective({fov:s*(Math.PI/180),aspect:i,near:e,far:t}),this.type="perspective",this}updateMatrixWorld(){return super.updateMatrixWorld(),this.worldMatrix.getTranslation(this.worldPosition),this.projectionViewMatrix.multiply(this.projectionMatrix,this.viewMatrix),this}lookAt(e){return super.lookAt(e,!0),this}project(e){return e.applyMatrix4(this.viewMatrix),e.applyMatrix4(this.projectionMatrix),this}unproject(e){return e.applyMatrix4(Qi.inverse(this.projectionMatrix)),e.applyMatrix4(this.worldMatrix),this}}class er extends Array{constructor(e=1,t=0,s=0,i=0,n=1,l=0,o=0,h=0,d=1){return super(e,t,s,i,n,l,o,h,d),this}set(e,t,s,i,n,l,o,h,d){return e.length?this.copy(e):this}translate(e,t=this){return this}rotate(e,t=this){return this}scale(e,t=this){return this}multiply(e,t){return this}identity(){return this}copy(e){return this}fromMatrix4(e){return this}fromQuaternion(e){return this}fromBasis(e,t,s){return this}inverse(e=this){return this}getNormalMatrix(e){return this}}let tr=0;class Le extends Me{constructor(e,{geometry:t,program:s,mode:i=e.TRIANGLES,frustumCulled:n=!0,renderOrder:l=0}={}){super(),e.canvas||console.error("gl not passed as first argument to Mesh"),this.gl=e,this.id=tr++,this.geometry=t,this.program=s,this.mode=i,this.frustumCulled=n,this.renderOrder=l,this.modelViewMatrix=new $,this.normalMatrix=new er}draw({camera:e}={}){e&&(this.program.uniforms.modelMatrix||Object.assign(this.program.uniforms,{modelMatrix:{value:null},viewMatrix:{value:null},modelViewMatrix:{value:null},normalMatrix:{value:null},projectionMatrix:{value:null},cameraPosition:{value:null}}),this.program.uniforms.projectionMatrix.value=e.projectionMatrix,this.program.uniforms.cameraPosition.value=e.worldPosition,this.program.uniforms.viewMatrix.value=e.viewMatrix,this.modelViewMatrix.multiply(e.viewMatrix,this.worldMatrix),this.normalMatrix.getNormalMatrix(this.modelViewMatrix),this.program.uniforms.modelMatrix.value=this.worldMatrix,this.program.uniforms.modelViewMatrix.value=this.modelViewMatrix,this.program.uniforms.normalMatrix.value=this.normalMatrix),this.program.use(),this.geometry.draw({mode:this.mode,program:this.program})}}const sr=new Uint8Array(4);let ir=1;class oe{constructor(e,{image:t,target:s=e.TEXTURE_2D,type:i=e.UNSIGNED_BYTE,format:n=e.RGBA,internalFormat:l=n,wrapS:o=e.CLAMP_TO_EDGE,wrapT:h=e.CLAMP_TO_EDGE,generateMipmaps:d=!0,minFilter:u=d?e.NEAREST_MIPMAP_LINEAR:e.LINEAR,magFilter:f=e.LINEAR,premultiplyAlpha:g=!1,unpackAlignment:_=4,flipY:m=s==e.TEXTURE_2D,anisotropy:p=0,level:w=0,width:v,height:x=v}={}){this.gl=e,this.id=ir++,this.image=t,this.target=s,this.type=i,this.format=n,this.internalFormat=l,this.minFilter=u,this.magFilter=f,this.wrapS=o,this.wrapT=h,this.generateMipmaps=d,this.premultiplyAlpha=g,this.unpackAlignment=_,this.flipY=m,this.anisotropy=Math.min(p,this.gl.renderer.parameters.maxAnisotropy),this.level=w,this.width=v,this.height=x,this.texture=this.gl.createTexture(),this.store={image:null},this.glState=this.gl.renderer.state,this.state={},this.state.minFilter=this.gl.NEAREST_MIPMAP_LINEAR,this.state.magFilter=this.gl.LINEAR,this.state.wrapS=this.gl.REPEAT,this.state.wrapT=this.gl.REPEAT,this.state.anisotropy=0}bind(){this.glState.textureUnits[this.glState.activeTextureUnit]!==this.id&&(this.gl.bindTexture(this.target,this.texture),this.glState.textureUnits[this.glState.activeTextureUnit]=this.id)}update(e=0){const t=!(this.image===this.store.image&&!this.needsUpdate);(t||this.glState.textureUnits[e]!==this.id)&&(this.gl.renderer.activeTexture(e),this.bind()),t&&(this.needsUpdate=!1,this.flipY!==this.glState.flipY&&(this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,this.flipY),this.glState.flipY=this.flipY),this.premultiplyAlpha!==this.glState.premultiplyAlpha&&(this.gl.pixelStorei(this.gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),this.glState.premultiplyAlpha=this.premultiplyAlpha),this.unpackAlignment!==this.glState.unpackAlignment&&(this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT,this.unpackAlignment),this.glState.unpackAlignment=this.unpackAlignment),this.minFilter!==this.state.minFilter&&(this.gl.texParameteri(this.target,this.gl.TEXTURE_MIN_FILTER,this.minFilter),this.state.minFilter=this.minFilter),this.magFilter!==this.state.magFilter&&(this.gl.texParameteri(this.target,this.gl.TEXTURE_MAG_FILTER,this.magFilter),this.state.magFilter=this.magFilter),this.wrapS!==this.state.wrapS&&(this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_S,this.wrapS),this.state.wrapS=this.wrapS),this.wrapT!==this.state.wrapT&&(this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_T,this.wrapT),this.state.wrapT=this.wrapT),this.image?(this.image.width&&(this.width=this.image.width,this.height=this.image.height),ArrayBuffer.isView(this.image)?this.gl.texImage2D(this.target,this.level,this.internalFormat,this.width,this.height,0,this.format,this.type,this.image):this.gl.texImage2D(this.target,this.level,this.internalFormat,this.format,this.type,this.image),this.onUpdate&&this.onUpdate()):this.width?this.gl.texImage2D(this.target,this.level,this.internalFormat,this.width,this.height,0,this.format,this.type,null):this.gl.texImage2D(this.target,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,sr),this.store.image=this.image)}}class Ie{constructor(e,{width:t=e.canvas.width,height:s=e.canvas.height,target:i=e.FRAMEBUFFER,color:n=1,depth:l=!0,stencil:o=!1,depthTexture:h=!1,wrapS:d=e.CLAMP_TO_EDGE,wrapT:u=e.CLAMP_TO_EDGE,minFilter:f=e.LINEAR,magFilter:g=f,type:_=e.UNSIGNED_BYTE,format:m=e.RGBA,internalFormat:p=m,unpackAlignment:w,premultiplyAlpha:v}={}){this.gl=e,this.width=t,this.height=s,this.depth=l,this.buffer=this.gl.createFramebuffer(),this.target=i,this.gl.renderer.bindFramebuffer(this),this.textures=[];const x=[];for(let y=0;y<n;y++)this.textures.push(new oe(e,{width:t,height:s,wrapS:d,wrapT:u,minFilter:f,magFilter:g,type:_,format:m,internalFormat:p,unpackAlignment:w,premultiplyAlpha:v,flipY:!1,generateMipmaps:!1})),this.textures[y].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+y,this.gl.TEXTURE_2D,this.textures[y].texture,0),x.push(this.gl.COLOR_ATTACHMENT0+y);x.length>1&&this.gl.renderer.drawBuffers(x),this.texture=this.textures[0],this.gl.renderer.bindFramebuffer({target:this.target})}setSize(e,t){if(!(this.width===e&&this.height===t)){this.width=e,this.height=t,this.gl.renderer.bindFramebuffer(this);for(let s=0;s<this.textures.length;s++)this.textures[s].width=e,this.textures[s].height=t,this.textures[s].needsUpdate=!0,this.textures[s].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+s,this.gl.TEXTURE_2D,this.textures[s].texture,0);this.gl.renderer.bindFramebuffer({target:this.target})}}}const Xe={black:"#000000",white:"#ffffff"};function Ke(r){r.length===4&&(r=r[0]+r[1]+r[1]+r[2]+r[2]+r[3]+r[3]);const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(r);return[parseInt(e[1],16)/255,parseInt(e[2],16)/255,parseInt(e[3],16)/255]}function