lecodes-cli 2.4.3 → 2.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1105 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-oPsDD47E.js","../lite.js","./creatorPhysics-k7wL0kV1.js","./creatorAnim-BOwKr-C1.js","./creatorParticles-DYlv4g1J.js"])))=>i.map(i=>d[i]);
2
- import{r as Ri,_ as Pi,g as Li,a as Bi,b as Ni,h as Oi,p as Ii,c as Ui,d as Di,e as Nr,v as In,T as zi}from"../lite.js";function Tr(t){let e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function bn(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function Gi(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function Un(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function Dn(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function Vi(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function Hi(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function en(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function ki(t,e){let r=e[0]-t[0],n=e[1]-t[1],s=e[2]-t[2];return Math.sqrt(r*r+n*n+s*s)}function Wi(t,e){let r=e[0]-t[0],n=e[1]-t[1],s=e[2]-t[2];return r*r+n*n+s*s}function zn(t){let e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function $i(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function Xi(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function An(t,e){let r=e[0],n=e[1],s=e[2],i=r*r+n*n+s*s;return i>0&&(i=1/Math.sqrt(i)),t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i,t}function Qs(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Gn(t,e,r){let n=e[0],s=e[1],i=e[2],l=r[0],a=r[1],c=r[2];return t[0]=s*c-i*a,t[1]=i*l-n*c,t[2]=n*a-s*l,t}function ji(t,e,r,n){let s=e[0],i=e[1],l=e[2];return t[0]=s+n*(r[0]-s),t[1]=i+n*(r[1]-i),t[2]=l+n*(r[2]-l),t}function qi(t,e,r,n,s){const i=Math.exp(-n*s);let l=e[0],a=e[1],c=e[2];return t[0]=r[0]+(l-r[0])*i,t[1]=r[1]+(a-r[1])*i,t[2]=r[2]+(c-r[2])*i,t}function Yi(t,e,r){let n=e[0],s=e[1],i=e[2],l=r[3]*n+r[7]*s+r[11]*i+r[15];return l=l||1,t[0]=(r[0]*n+r[4]*s+r[8]*i+r[12])/l,t[1]=(r[1]*n+r[5]*s+r[9]*i+r[13])/l,t[2]=(r[2]*n+r[6]*s+r[10]*i+r[14])/l,t}function Ki(t,e,r){let n=e[0],s=e[1],i=e[2],l=r[3]*n+r[7]*s+r[11]*i+r[15];return l=l||1,t[0]=(r[0]*n+r[4]*s+r[8]*i)/l,t[1]=(r[1]*n+r[5]*s+r[9]*i)/l,t[2]=(r[2]*n+r[6]*s+r[10]*i)/l,t}function Qi(t,e,r){let n=e[0],s=e[1],i=e[2];return t[0]=n*r[0]+s*r[3]+i*r[6],t[1]=n*r[1]+s*r[4]+i*r[7],t[2]=n*r[2]+s*r[5]+i*r[8],t}function Zi(t,e,r){let n=e[0],s=e[1],i=e[2],l=r[0],a=r[1],c=r[2],f=r[3],p=a*i-c*s,g=c*n-l*i,u=l*s-a*n,v=a*u-c*g,M=c*p-l*u,d=l*g-a*p,y=f*2;return p*=y,g*=y,u*=y,v*=2,M*=2,d*=2,t[0]=n+p+v,t[1]=s+g+M,t[2]=i+u+d,t}const Ji=(function(){const t=[0,0,0],e=[0,0,0];return function(r,n){bn(t,r),bn(e,n),An(t,t),An(e,e);let s=Qs(t,e);return s>1?0:s<-1?Math.PI:Math.acos(s)}})();function eo(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}class Ce extends Array{constructor(e=0,r=e,n=e){return super(e,r,n),this}get x(){return this[0]}get y(){return this[1]}get z(){return this[2]}set x(e){this[0]=e}set y(e){this[1]=e}set z(e){this[2]=e}set(e,r=e,n=e){return e.length?this.copy(e):(Gi(this,e,r,n),this)}copy(e){return bn(this,e),this}add(e,r){return r?Un(this,e,r):Un(this,this,e),this}sub(e,r){return r?Dn(this,e,r):Dn(this,this,e),this}multiply(e){return e.length?Vi(this,this,e):en(this,this,e),this}divide(e){return e.length?Hi(this,this,e):en(this,this,1/e),this}inverse(e=this){return Xi(this,e),this}len(){return Tr(this)}distance(e){return e?ki(this,e):Tr(this)}squaredLen(){return zn(this)}squaredDistance(e){return e?Wi(this,e):zn(this)}negate(e=this){return $i(this,e),this}cross(e,r){return r?Gn(this,e,r):Gn(this,this,e),this}scale(e){return en(this,this,e),this}normalize(){return An(this,this),this}dot(e){return Qs(this,e)}equals(e){return eo(this,e)}applyMatrix3(e){return Qi(this,this,e),this}applyMatrix4(e){return Yi(this,this,e),this}scaleRotateMatrix4(e){return Ki(this,this,e),this}applyQuaternion(e){return Zi(this,this,e),this}angle(e){return Ji(this,e)}lerp(e,r){return ji(this,this,e,r),this}smoothLerp(e,r,n){return qi(this,this,e,r,n),this}clone(){return new Ce(this[0],this[1],this[2])}fromArray(e,r=0){return this[0]=e[r],this[1]=e[r+1],this[2]=e[r+2],this}toArray(e=[],r=0){return e[r]=this[0],e[r+1]=this[1],e[r+2]=this[2],e}transformDirection(e){const r=this[0],n=this[1],s=this[2];return this[0]=e[0]*r+e[4]*n+e[8]*s,this[1]=e[1]*r+e[5]*n+e[9]*s,this[2]=e[2]*r+e[6]*n+e[10]*s,this.normalize()}}const Vn=new Ce;let to=1,ro=1,Hn=!1;class ct{constructor(e,r={}){e.canvas||console.error("gl not passed as first argument to Geometry"),this.gl=e,this.attributes=r,this.id=to++,this.VAOs={},this.drawRange={start:0,count:0},this.instancedCount=0,this.gl.renderer.bindVertexArray(null),this.gl.renderer.currentGeometry=null,this.glState=this.gl.renderer.state;for(let n in r)this.addAttribute(n,r[n])}addAttribute(e,r){if(this.attributes[e]=r,r.id=ro++,r.size=r.size||1,r.type=r.type||(r.data.constructor===Float32Array?this.gl.FLOAT:r.data.constructor===Uint16Array?this.gl.UNSIGNED_SHORT:this.gl.UNSIGNED_INT),r.target=e==="index"?this.gl.ELEMENT_ARRAY_BUFFER:this.gl.ARRAY_BUFFER,r.normalized=r.normalized||!1,r.stride=r.stride||0,r.offset=r.offset||0,r.count=r.count||(r.stride?r.data.byteLength/r.stride:r.data.length/r.size),r.divisor=r.instanced||0,r.needsUpdate=!1,r.usage=r.usage||this.gl.STATIC_DRAW,r.buffer||this.updateAttribute(r),r.divisor){if(this.isInstanced=!0,this.instancedCount&&this.instancedCount!==r.count*r.divisor)return console.warn("geometry has multiple instanced buffers of different length"),this.instancedCount=Math.min(this.instancedCount,r.count*r.divisor);this.instancedCount=r.count*r.divisor}else e==="index"?this.drawRange.count=r.count:this.attributes.index||(this.drawRange.count=Math.max(this.drawRange.count,r.count))}updateAttribute(e){const r=!e.buffer;r&&(e.buffer=this.gl.createBuffer()),this.glState.boundBuffer!==e.buffer&&(this.gl.bindBuffer(e.target,e.buffer),this.glState.boundBuffer=e.buffer),r?this.gl.bufferData(e.target,e.data,e.usage):this.gl.bufferSubData(e.target,0,e.data),e.needsUpdate=!1}setIndex(e){this.addAttribute("index",e)}setDrawRange(e,r){this.drawRange.start=e,this.drawRange.count=r}setInstancedCount(e){this.instancedCount=e}createVAO(e){this.VAOs[e.attributeOrder]=this.gl.renderer.createVertexArray(),this.gl.renderer.bindVertexArray(this.VAOs[e.attributeOrder]),this.bindAttributes(e)}bindAttributes(e){e.attributeLocations.forEach((r,{name:n,type:s})=>{if(!this.attributes[n]){console.warn(`active attribute ${n} not being supplied`);return}const i=this.attributes[n];this.gl.bindBuffer(i.target,i.buffer),this.glState.boundBuffer=i.buffer;let l=1;s===35674&&(l=2),s===35675&&(l=3),s===35676&&(l=4);const a=i.size/l,c=l===1?0:l*l*4,f=l===1?0:l*4;for(let p=0;p<l;p++)this.gl.vertexAttribPointer(r+p,a,i.type,i.normalized,i.stride+c,i.offset+p*f),this.gl.enableVertexAttribArray(r+p),this.gl.renderer.vertexAttribDivisor(r+p,i.divisor)}),this.attributes.index&&this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.attributes.index.buffer)}draw({program:e,mode:r=this.gl.TRIANGLES}){var s;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:l})=>{const a=this.attributes[l];a.needsUpdate&&this.updateAttribute(a)});let n=2;((s=this.attributes.index)==null?void 0:s.type)===this.gl.UNSIGNED_INT&&(n=4),this.isInstanced?this.attributes.index?this.gl.renderer.drawElementsInstanced(r,this.drawRange.count,this.attributes.index.type,this.attributes.index.offset+this.drawRange.start*n,this.instancedCount):this.gl.renderer.drawArraysInstanced(r,this.drawRange.start,this.drawRange.count,this.instancedCount):this.attributes.index?this.gl.drawElements(r,this.drawRange.count,this.attributes.index.type,this.attributes.index.offset+this.drawRange.start*n):this.gl.drawArrays(r,this.drawRange.start,this.drawRange.count)}getPosition(){const e=this.attributes.position;if(e.data)return e;if(!Hn)return console.warn("No position buffer data found to compute bounds"),Hn=!0}computeBoundingBox(e){e||(e=this.getPosition());const r=e.data,n=e.size;this.bounds||(this.bounds={min:new Ce,max:new Ce,center:new Ce,scale:new Ce,radius:1/0});const s=this.bounds.min,i=this.bounds.max,l=this.bounds.center,a=this.bounds.scale;s.set(1/0),i.set(-1/0);for(let c=0,f=r.length;c<f;c+=n){const p=r[c],g=r[c+1],u=r[c+2];s.x=Math.min(p,s.x),s.y=Math.min(g,s.y),s.z=Math.min(u,s.z),i.x=Math.max(p,i.x),i.y=Math.max(g,i.y),i.z=Math.max(u,i.z)}a.sub(i,s),l.add(s,i).divide(2)}computeBoundingSphere(e){e||(e=this.getPosition());const r=e.data,n=e.size;this.bounds||this.computeBoundingBox(e);let s=0;for(let i=0,l=r.length;i<l;i+=n)Vn.fromArray(r,i),s=Math.max(s,this.bounds.center.squaredDistance(Vn));this.bounds.radius=Math.sqrt(s)}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 no=1;const kn={};class ze{constructor(e,{vertex:r,fragment:n,uniforms:s={},transparent:i=!1,cullFace:l=e.BACK,frontFace:a=e.CCW,depthTest:c=!0,depthWrite:f=!0,depthFunc:p=e.LEQUAL}={}){e.canvas||console.error("gl not passed as first argument to Program"),this.gl=e,this.uniforms=s,this.id=no++,r||console.warn("vertex shader not supplied"),n||console.warn("fragment shader not supplied"),this.transparent=i,this.cullFace=l,this.frontFace=a,this.depthTest=c,this.depthWrite=f,this.depthFunc=p,this.blendFunc={},this.blendEquation={},this.stencilFunc={},this.stencilOp={},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)),this.vertexShader=e.createShader(e.VERTEX_SHADER),this.fragmentShader=e.createShader(e.FRAGMENT_SHADER),this.program=e.createProgram(),e.attachShader(this.program,this.vertexShader),e.attachShader(this.program,this.fragmentShader),this.setShaders({vertex:r,fragment:n})}setShaders({vertex:e,fragment:r}){if(e&&(this.gl.shaderSource(this.vertexShader,e),this.gl.compileShader(this.vertexShader),this.gl.getShaderInfoLog(this.vertexShader)!==""&&console.warn(`${this.gl.getShaderInfoLog(this.vertexShader)}
3
- Vertex Shader
4
- ${Wn(e)}`)),r&&(this.gl.shaderSource(this.fragmentShader,r),this.gl.compileShader(this.fragmentShader),this.gl.getShaderInfoLog(this.fragmentShader)!==""&&console.warn(`${this.gl.getShaderInfoLog(this.fragmentShader)}
5
- Fragment Shader
6
- ${Wn(r)}`)),this.gl.linkProgram(this.program),!this.gl.getProgramParameter(this.program,this.gl.LINK_STATUS))return console.warn(this.gl.getProgramInfoLog(this.program));this.uniformLocations=new Map;let n=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_UNIFORMS);for(let l=0;l<n;l++){let a=this.gl.getActiveUniform(this.program,l);this.uniformLocations.set(a,this.gl.getUniformLocation(this.program,a.name));const c=a.name.match(/(\w+)/g);a.uniformName=c[0],a.nameComponents=c.slice(1)}this.attributeLocations=new Map;const s=[],i=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_ATTRIBUTES);for(let l=0;l<i;l++){const a=this.gl.getActiveAttrib(this.program,l),c=this.gl.getAttribLocation(this.program,a.name);c!==-1&&(s[c]=a.name,this.attributeLocations.set(a,c))}this.attributeOrder=s.join("")}setBlendFunc(e,r,n,s){this.blendFunc.src=e,this.blendFunc.dst=r,this.blendFunc.srcAlpha=n,this.blendFunc.dstAlpha=s,e&&(this.transparent=!0)}setBlendEquation(e,r){this.blendEquation.modeRGB=e,this.blendEquation.modeAlpha=r}setStencilFunc(e,r,n){this.stencilRef=r,this.stencilFunc.func=e,this.stencilFunc.ref=r,this.stencilFunc.mask=n}setStencilOp(e,r,n){this.stencilOp.stencilFail=e,this.stencilOp.depthFail=r,this.stencilOp.depthPass=n}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),this.stencilFunc.func||this.stencilOp.stencilFail?this.gl.renderer.enable(this.gl.STENCIL_TEST):this.gl.renderer.disable(this.gl.STENCIL_TEST),this.gl.renderer.setStencilFunc(this.stencilFunc.func,this.stencilFunc.ref,this.stencilFunc.mask),this.gl.renderer.setStencilOp(this.stencilOp.stencilFail,this.stencilOp.depthFail,this.stencilOp.depthPass)}use({flipFaces:e=!1}={}){let r=-1;this.gl.renderer.state.currentProgram===this.id||(this.gl.useProgram(this.program),this.gl.renderer.state.currentProgram=this.id),this.uniformLocations.forEach((s,i)=>{let l=this.uniforms[i.uniformName];for(const a of i.nameComponents){if(!l)break;if(a in l)l=l[a];else{if(Array.isArray(l.value))break;l=void 0;break}}if(!l)return $n(`Active uniform ${i.name} has not been supplied`);if(l&&l.value===void 0)return $n(`${i.name} uniform is missing a value parameter`);if(l.value.texture)return r=r+1,l.value.update(r),tn(this.gl,i.type,s,r);if(l.value.length&&l.value[0].texture){const a=[];return l.value.forEach(c=>{r=r+1,c.update(r),a.push(r)}),tn(this.gl,i.type,s,a)}tn(this.gl,i.type,s,l.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 tn(t,e,r,n){n=n.length?so(n):n;const s=t.renderer.state.uniformLocations.get(r);if(n.length)if(s===void 0||s.length!==n.length)t.renderer.state.uniformLocations.set(r,n.slice(0));else{if(io(s,n))return;s.set?s.set(n):oo(s,n),t.renderer.state.uniformLocations.set(r,s)}else{if(s===n)return;t.renderer.state.uniformLocations.set(r,n)}switch(e){case 5126:return n.length?t.uniform1fv(r,n):t.uniform1f(r,n);case 35664:return t.uniform2fv(r,n);case 35665:return t.uniform3fv(r,n);case 35666:return t.uniform4fv(r,n);case 35670:case 5124:case 35678:case 36306:case 35680:case 36289:return n.length?t.uniform1iv(r,n):t.uniform1i(r,n);case 35671:case 35667:return t.uniform2iv(r,n);case 35672:case 35668:return t.uniform3iv(r,n);case 35673:case 35669:return t.uniform4iv(r,n);case 35674:return t.uniformMatrix2fv(r,!1,n);case 35675:return t.uniformMatrix3fv(r,!1,n);case 35676:return t.uniformMatrix4fv(r,!1,n)}}function Wn(t){let e=t.split(`
7
- `);for(let r=0;r<e.length;r++)e[r]=r+1+": "+e[r];return e.join(`
8
- `)}function so(t){const e=t.length,r=t[0].length;if(r===void 0)return t;const n=e*r;let s=kn[n];s||(kn[n]=s=new Float32Array(n));for(let i=0;i<e;i++)s.set(t[i],i*r);return s}function io(t,e){if(t.length!==e.length)return!1;for(let r=0,n=t.length;r<n;r++)if(t[r]!==e[r])return!1;return!0}function oo(t,e){for(let r=0,n=t.length;r<n;r++)t[r]=e[r]}let rn=0;function $n(t){rn>100||(console.warn(t),rn++,rn>100&&console.warn("More than 100 program warnings - stopping logs."))}const nn=new Ce;let ao=1;class lo{constructor({canvas:e=document.createElement("canvas"),width:r=300,height:n=150,dpr:s=1,alpha:i=!1,depth:l=!0,stencil:a=!1,antialias:c=!1,premultipliedAlpha:f=!1,preserveDrawingBuffer:p=!1,powerPreference:g="default",autoClear:u=!0,webgl:v=2}={}){const M={alpha:i,depth:l,stencil:a,antialias:c,premultipliedAlpha:f,preserveDrawingBuffer:p,powerPreference:g};this.dpr=s,this.alpha=i,this.color=!0,this.depth=l,this.stencil=a,this.premultipliedAlpha=f,this.autoClear=u,this.id=ao++,v===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(r,n),this.state={},this.state.blendFunc={src:this.gl.ONE,dst:this.gl.ZERO},this.state.blendEquation={modeRGB:this.gl.FUNC_ADD},this.state.cullFace=!1,this.state.frontFace=this.gl.CCW,this.state.depthMask=!0,this.state.depthFunc=this.gl.LEQUAL,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.getExtension("OES_texture_float"),this.getExtension("OES_texture_float_linear"),this.getExtension("OES_texture_half_float"),this.getExtension("OES_texture_half_float_linear"),this.getExtension("OES_element_index_uint"),this.getExtension("OES_standard_derivatives"),this.getExtension("EXT_sRGB"),this.getExtension("WEBGL_depth_texture"),this.getExtension("WEBGL_draw_buffers")),this.getExtension("WEBGL_compressed_texture_astc"),this.getExtension("EXT_texture_compression_bptc"),this.getExtension("WEBGL_compressed_texture_s3tc"),this.getExtension("WEBGL_compressed_texture_etc1"),this.getExtension("WEBGL_compressed_texture_pvrtc"),this.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),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,r){this.width=e,this.height=r,this.gl.canvas.width=e*this.dpr,this.gl.canvas.height=r*this.dpr,this.gl.canvas.style&&Object.assign(this.gl.canvas.style,{width:e+"px",height:r+"px"})}setViewport(e,r,n=0,s=0){this.state.viewport.width===e&&this.state.viewport.height===r||(this.state.viewport.width=e,this.state.viewport.height=r,this.state.viewport.x=n,this.state.viewport.y=s,this.gl.viewport(n,s,e,r))}setScissor(e,r,n=0,s=0){this.gl.scissor(n,s,e,r)}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,r,n,s){this.state.blendFunc.src===e&&this.state.blendFunc.dst===r&&this.state.blendFunc.srcAlpha===n&&this.state.blendFunc.dstAlpha===s||(this.state.blendFunc.src=e,this.state.blendFunc.dst=r,this.state.blendFunc.srcAlpha=n,this.state.blendFunc.dstAlpha=s,n!==void 0?this.gl.blendFuncSeparate(e,r,n,s):this.gl.blendFunc(e,r))}setBlendEquation(e,r){e=e||this.gl.FUNC_ADD,!(this.state.blendEquation.modeRGB===e&&this.state.blendEquation.modeAlpha===r)&&(this.state.blendEquation.modeRGB=e,this.state.blendEquation.modeAlpha=r,r!==void 0?this.gl.blendEquationSeparate(e,r):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))}setStencilMask(e){this.state.stencilMask!==e&&(this.state.stencilMask=e,this.gl.stencilMask(e))}setStencilFunc(e,r,n){this.state.stencilFunc===e&&this.state.stencilRef===r&&this.state.stencilFuncMask===n||(this.state.stencilFunc=e||this.gl.ALWAYS,this.state.stencilRef=r||0,this.state.stencilFuncMask=n||0,this.gl.stencilFunc(e||this.gl.ALWAYS,r||0,n||0))}setStencilOp(e,r,n){this.state.stencilFail===e&&this.state.stencilDepthFail===r&&this.state.stencilDepthPass===n||(this.state.stencilFail=e,this.state.stencilDepthFail=r,this.state.stencilDepthPass=n,this.gl.stencilOp(e,r,n))}activeTexture(e){this.state.activeTextureUnit!==e&&(this.state.activeTextureUnit=e,this.gl.activeTexture(this.gl.TEXTURE0+e))}bindFramebuffer({target:e=this.gl.FRAMEBUFFER,buffer:r=null}={}){this.state.framebuffer!==r&&(this.state.framebuffer=r,this.gl.bindFramebuffer(e,r))}getExtension(e,r,n){return r&&this.gl[r]?this.gl[r].bind(this.gl):(this.extensions[e]||(this.extensions[e]=this.gl.getExtension(e)),r?this.extensions[e]?this.extensions[e][n].bind(this.extensions[e]):null:this.extensions[e])}sortOpaque(e,r){return e.renderOrder!==r.renderOrder?e.renderOrder-r.renderOrder:e.program.id!==r.program.id?e.program.id-r.program.id:e.zDepth!==r.zDepth?e.zDepth-r.zDepth:r.id-e.id}sortTransparent(e,r){return e.renderOrder!==r.renderOrder?e.renderOrder-r.renderOrder:e.zDepth!==r.zDepth?r.zDepth-e.zDepth:r.id-e.id}sortUI(e,r){return e.renderOrder!==r.renderOrder?e.renderOrder-r.renderOrder:e.program.id!==r.program.id?e.program.id-r.program.id:r.id-e.id}getRenderList({scene:e,camera:r,frustumCull:n,sort:s}){let i=[];if(r&&n&&r.updateFrustum(),e.traverse(l=>{if(!l.visible)return!0;l.draw&&(n&&l.frustumCulled&&r&&!r.frustumIntersectsMesh(l)||i.push(l))}),s){const l=[],a=[],c=[];i.forEach(f=>{f.program.transparent?f.program.depthTest?a.push(f):c.push(f):l.push(f),f.zDepth=0,!(f.renderOrder!==0||!f.program.depthTest||!r)&&(f.worldMatrix.getTranslation(nn),nn.applyMatrix4(r.projectionViewMatrix),f.zDepth=nn.z)}),l.sort(this.sortOpaque),a.sort(this.sortTransparent),c.sort(this.sortUI),i=l.concat(a,c)}return i}render({scene:e,camera:r,target:n=null,update:s=!0,sort:i=!0,frustumCull:l=!0,clear:a}){n===null?(this.bindFramebuffer(),this.setViewport(this.width*this.dpr,this.height*this.dpr)):(this.bindFramebuffer(n),this.setViewport(n.width,n.height)),(a||this.autoClear&&a!==!1)&&(this.depth&&(!n||n.depth)&&(this.enable(this.gl.DEPTH_TEST),this.setDepthMask(!0)),(this.stencil||!n||n.stencil)&&(this.enable(this.gl.STENCIL_TEST),this.setStencilMask(255)),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))),s&&e.updateMatrixWorld(),r&&r.updateMatrixWorld(),this.getRenderList({scene:e,camera:r,frustumCull:l,sort:i}).forEach(f=>{f.draw({camera:r})})}}function Zs(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function Js(t,e,r,n,s){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t}function co(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t}function ei(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=r*r+n*n+s*s+i*i;return l>0&&(l=1/Math.sqrt(l)),t[0]=r*l,t[1]=n*l,t[2]=s*l,t[3]=i*l,t}function ti(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function uo(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function ho(t,e,r){r=r*.5;let n=Math.sin(r);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(r),t}function Xn(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],a=r[0],c=r[1],f=r[2],p=r[3];return t[0]=n*p+l*a+s*f-i*c,t[1]=s*p+l*c+i*a-n*f,t[2]=i*p+l*f+n*c-s*a,t[3]=l*p-n*a-s*c-i*f,t}function fo(t,e,r){r*=.5;let n=e[0],s=e[1],i=e[2],l=e[3],a=Math.sin(r),c=Math.cos(r);return t[0]=n*c+l*a,t[1]=s*c+i*a,t[2]=i*c-s*a,t[3]=l*c-n*a,t}function mo(t,e,r){r*=.5;let n=e[0],s=e[1],i=e[2],l=e[3],a=Math.sin(r),c=Math.cos(r);return t[0]=n*c-i*a,t[1]=s*c+l*a,t[2]=i*c+n*a,t[3]=l*c-s*a,t}function po(t,e,r){r*=.5;let n=e[0],s=e[1],i=e[2],l=e[3],a=Math.sin(r),c=Math.cos(r);return t[0]=n*c+s*a,t[1]=s*c-n*a,t[2]=i*c+l*a,t[3]=l*c-i*a,t}function go(t,e,r,n){let s=e[0],i=e[1],l=e[2],a=e[3],c=r[0],f=r[1],p=r[2],g=r[3],u,v,M,d,y;return v=s*c+i*f+l*p+a*g,v<0&&(v=-v,c=-c,f=-f,p=-p,g=-g),1-v>1e-6?(u=Math.acos(v),M=Math.sin(u),d=Math.sin((1-n)*u)/M,y=Math.sin(n*u)/M):(d=1-n,y=n),t[0]=d*s+y*c,t[1]=d*i+y*f,t[2]=d*l+y*p,t[3]=d*a+y*g,t}function vo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=r*r+n*n+s*s+i*i,a=l?1/l:0;return t[0]=-r*a,t[1]=-n*a,t[2]=-s*a,t[3]=i*a,t}function yo(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function xo(t,e){let r=e[0]+e[4]+e[8],n;if(r>0)n=Math.sqrt(r+1),t[3]=.5*n,n=.5/n,t[0]=(e[5]-e[7])*n,t[1]=(e[6]-e[2])*n,t[2]=(e[1]-e[3])*n;else{let s=0;e[4]>e[0]&&(s=1),e[8]>e[s*3+s]&&(s=2);let i=(s+1)%3,l=(s+2)%3;n=Math.sqrt(e[s*3+s]-e[i*3+i]-e[l*3+l]+1),t[s]=.5*n,n=.5/n,t[3]=(e[i*3+l]-e[l*3+i])*n,t[i]=(e[i*3+s]+e[s*3+i])*n,t[l]=(e[l*3+s]+e[s*3+l])*n}return t}function wo(t,e,r="YXZ"){let n=Math.sin(e[0]*.5),s=Math.cos(e[0]*.5),i=Math.sin(e[1]*.5),l=Math.cos(e[1]*.5),a=Math.sin(e[2]*.5),c=Math.cos(e[2]*.5);return r==="XYZ"?(t[0]=n*l*c+s*i*a,t[1]=s*i*c-n*l*a,t[2]=s*l*a+n*i*c,t[3]=s*l*c-n*i*a):r==="YXZ"?(t[0]=n*l*c+s*i*a,t[1]=s*i*c-n*l*a,t[2]=s*l*a-n*i*c,t[3]=s*l*c+n*i*a):r==="ZXY"?(t[0]=n*l*c-s*i*a,t[1]=s*i*c+n*l*a,t[2]=s*l*a+n*i*c,t[3]=s*l*c-n*i*a):r==="ZYX"?(t[0]=n*l*c-s*i*a,t[1]=s*i*c+n*l*a,t[2]=s*l*a-n*i*c,t[3]=s*l*c+n*i*a):r==="YZX"?(t[0]=n*l*c+s*i*a,t[1]=s*i*c+n*l*a,t[2]=s*l*a-n*i*c,t[3]=s*l*c-n*i*a):r==="XZY"&&(t[0]=n*l*c-s*i*a,t[1]=s*i*c-n*l*a,t[2]=s*l*a+n*i*c,t[3]=s*l*c+n*i*a),t}const Mo=Zs,bo=Js,Ao=ti,So=ei;class sr extends Array{constructor(e=0,r=0,n=0,s=1){super(e,r,n,s),this.onChange=()=>{},this._target=this;const i=["0","1","2","3"];return new Proxy(this,{set(l,a){const c=Reflect.set(...arguments);return c&&i.includes(a)&&l.onChange(),c}})}get x(){return this[0]}get y(){return this[1]}get z(){return this[2]}get w(){return this[3]}set x(e){this._target[0]=e,this.onChange()}set y(e){this._target[1]=e,this.onChange()}set z(e){this._target[2]=e,this.onChange()}set w(e){this._target[3]=e,this.onChange()}identity(){return uo(this._target),this.onChange(),this}set(e,r,n,s){return e.length?this.copy(e):(bo(this._target,e,r,n,s),this.onChange(),this)}rotateX(e){return fo(this._target,this._target,e),this.onChange(),this}rotateY(e){return mo(this._target,this._target,e),this.onChange(),this}rotateZ(e){return po(this._target,this._target,e),this.onChange(),this}inverse(e=this._target){return vo(this._target,e),this.onChange(),this}conjugate(e=this._target){return yo(this._target,e),this.onChange(),this}copy(e){return Mo(this._target,e),this.onChange(),this}normalize(e=this._target){return So(this._target,e),this.onChange(),this}multiply(e,r){return r?Xn(this._target,e,r):Xn(this._target,this._target,e),this.onChange(),this}dot(e){return Ao(this._target,e)}fromMatrix3(e){return xo(this._target,e),this.onChange(),this}fromEuler(e,r){return wo(this._target,e,e.order),r||this.onChange(),this}fromAxisAngle(e,r){return ho(this._target,e,r),this.onChange(),this}slerp(e,r){return go(this._target,this._target,e,r),this.onChange(),this}fromArray(e,r=0){return this._target[0]=e[r],this._target[1]=e[r+1],this._target[2]=e[r+2],this._target[3]=e[r+3],this.onChange(),this}toArray(e=[],r=0){return e[r]=this[0],e[r+1]=this[1],e[r+2]=this[2],e[r+3]=this[3],e}}const _o=1e-6;function Eo(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Co(t,e,r,n,s,i,l,a,c,f,p,g,u,v,M,d,y){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t[4]=i,t[5]=l,t[6]=a,t[7]=c,t[8]=f,t[9]=p,t[10]=g,t[11]=u,t[12]=v,t[13]=M,t[14]=d,t[15]=y,t}function Fo(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function To(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=e[4],a=e[5],c=e[6],f=e[7],p=e[8],g=e[9],u=e[10],v=e[11],M=e[12],d=e[13],y=e[14],x=e[15],T=r*a-n*l,P=r*c-s*l,L=r*f-i*l,_=n*c-s*a,o=n*f-i*a,h=s*f-i*c,m=p*d-g*M,w=p*y-u*M,E=p*x-v*M,B=g*y-u*d,W=g*x-v*d,N=u*x-v*y,I=T*N-P*W+L*B+_*E-o*w+h*m;return I?(I=1/I,t[0]=(a*N-c*W+f*B)*I,t[1]=(s*W-n*N-i*B)*I,t[2]=(d*h-y*o+x*_)*I,t[3]=(u*o-g*h-v*_)*I,t[4]=(c*E-l*N-f*w)*I,t[5]=(r*N-s*E+i*w)*I,t[6]=(y*L-M*h-x*P)*I,t[7]=(p*h-u*L+v*P)*I,t[8]=(l*W-a*E+f*m)*I,t[9]=(n*E-r*W-i*m)*I,t[10]=(M*o-d*L+x*T)*I,t[11]=(g*L-p*o-v*T)*I,t[12]=(a*w-l*B-c*m)*I,t[13]=(r*B-n*w+s*m)*I,t[14]=(d*P-M*_-y*T)*I,t[15]=(p*_-g*P+u*T)*I,t):null}function ri(t){let e=t[0],r=t[1],n=t[2],s=t[3],i=t[4],l=t[5],a=t[6],c=t[7],f=t[8],p=t[9],g=t[10],u=t[11],v=t[12],M=t[13],d=t[14],y=t[15],x=e*l-r*i,T=e*a-n*i,P=e*c-s*i,L=r*a-n*l,_=r*c-s*l,o=n*c-s*a,h=f*M-p*v,m=f*d-g*v,w=f*y-u*v,E=p*d-g*M,B=p*y-u*M,W=g*y-u*d;return x*W-T*B+P*E+L*w-_*m+o*h}function jn(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],a=e[4],c=e[5],f=e[6],p=e[7],g=e[8],u=e[9],v=e[10],M=e[11],d=e[12],y=e[13],x=e[14],T=e[15],P=r[0],L=r[1],_=r[2],o=r[3];return t[0]=P*n+L*a+_*g+o*d,t[1]=P*s+L*c+_*u+o*y,t[2]=P*i+L*f+_*v+o*x,t[3]=P*l+L*p+_*M+o*T,P=r[4],L=r[5],_=r[6],o=r[7],t[4]=P*n+L*a+_*g+o*d,t[5]=P*s+L*c+_*u+o*y,t[6]=P*i+L*f+_*v+o*x,t[7]=P*l+L*p+_*M+o*T,P=r[8],L=r[9],_=r[10],o=r[11],t[8]=P*n+L*a+_*g+o*d,t[9]=P*s+L*c+_*u+o*y,t[10]=P*i+L*f+_*v+o*x,t[11]=P*l+L*p+_*M+o*T,P=r[12],L=r[13],_=r[14],o=r[15],t[12]=P*n+L*a+_*g+o*d,t[13]=P*s+L*c+_*u+o*y,t[14]=P*i+L*f+_*v+o*x,t[15]=P*l+L*p+_*M+o*T,t}function Ro(t,e,r){let n=r[0],s=r[1],i=r[2],l,a,c,f,p,g,u,v,M,d,y,x;return e===t?(t[12]=e[0]*n+e[4]*s+e[8]*i+e[12],t[13]=e[1]*n+e[5]*s+e[9]*i+e[13],t[14]=e[2]*n+e[6]*s+e[10]*i+e[14],t[15]=e[3]*n+e[7]*s+e[11]*i+e[15]):(l=e[0],a=e[1],c=e[2],f=e[3],p=e[4],g=e[5],u=e[6],v=e[7],M=e[8],d=e[9],y=e[10],x=e[11],t[0]=l,t[1]=a,t[2]=c,t[3]=f,t[4]=p,t[5]=g,t[6]=u,t[7]=v,t[8]=M,t[9]=d,t[10]=y,t[11]=x,t[12]=l*n+p*s+M*i+e[12],t[13]=a*n+g*s+d*i+e[13],t[14]=c*n+u*s+y*i+e[14],t[15]=f*n+v*s+x*i+e[15]),t}function Po(t,e,r){let n=r[0],s=r[1],i=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*s,t[5]=e[5]*s,t[6]=e[6]*s,t[7]=e[7]*s,t[8]=e[8]*i,t[9]=e[9]*i,t[10]=e[10]*i,t[11]=e[11]*i,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function Lo(t,e,r,n){let s=n[0],i=n[1],l=n[2],a=Math.hypot(s,i,l),c,f,p,g,u,v,M,d,y,x,T,P,L,_,o,h,m,w,E,B,W,N,I,D;return Math.abs(a)<_o?null:(a=1/a,s*=a,i*=a,l*=a,c=Math.sin(r),f=Math.cos(r),p=1-f,g=e[0],u=e[1],v=e[2],M=e[3],d=e[4],y=e[5],x=e[6],T=e[7],P=e[8],L=e[9],_=e[10],o=e[11],h=s*s*p+f,m=i*s*p+l*c,w=l*s*p-i*c,E=s*i*p-l*c,B=i*i*p+f,W=l*i*p+s*c,N=s*l*p+i*c,I=i*l*p-s*c,D=l*l*p+f,t[0]=g*h+d*m+P*w,t[1]=u*h+y*m+L*w,t[2]=v*h+x*m+_*w,t[3]=M*h+T*m+o*w,t[4]=g*E+d*B+P*W,t[5]=u*E+y*B+L*W,t[6]=v*E+x*B+_*W,t[7]=M*E+T*B+o*W,t[8]=g*N+d*I+P*D,t[9]=u*N+y*I+L*D,t[10]=v*N+x*I+_*D,t[11]=M*N+T*I+o*D,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Bo(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function ni(t,e){let r=e[0],n=e[1],s=e[2],i=e[4],l=e[5],a=e[6],c=e[8],f=e[9],p=e[10];return t[0]=Math.hypot(r,n,s),t[1]=Math.hypot(i,l,a),t[2]=Math.hypot(c,f,p),t}function No(t){let e=t[0],r=t[1],n=t[2],s=t[4],i=t[5],l=t[6],a=t[8],c=t[9],f=t[10];const p=e*e+r*r+n*n,g=s*s+i*i+l*l,u=a*a+c*c+f*f;return Math.sqrt(Math.max(p,g,u))}const si=(function(){const t=[1,1,1];return function(e,r){let n=t;ni(n,r);let s=1/n[0],i=1/n[1],l=1/n[2],a=r[0]*s,c=r[1]*i,f=r[2]*l,p=r[4]*s,g=r[5]*i,u=r[6]*l,v=r[8]*s,M=r[9]*i,d=r[10]*l,y=a+g+d,x=0;return y>0?(x=Math.sqrt(y+1)*2,e[3]=.25*x,e[0]=(u-M)/x,e[1]=(v-f)/x,e[2]=(c-p)/x):a>g&&a>d?(x=Math.sqrt(1+a-g-d)*2,e[3]=(u-M)/x,e[0]=.25*x,e[1]=(c+p)/x,e[2]=(v+f)/x):g>d?(x=Math.sqrt(1+g-a-d)*2,e[3]=(v-f)/x,e[0]=(c+p)/x,e[1]=.25*x,e[2]=(u+M)/x):(x=Math.sqrt(1+d-a-g)*2,e[3]=(c-p)/x,e[0]=(v+f)/x,e[1]=(u+M)/x,e[2]=.25*x),e}})();function Oo(t,e,r,n){let s=Tr([t[0],t[1],t[2]]);const i=Tr([t[4],t[5],t[6]]),l=Tr([t[8],t[9],t[10]]);ri(t)<0&&(s=-s),r[0]=t[12],r[1]=t[13],r[2]=t[14];const c=t.slice(),f=1/s,p=1/i,g=1/l;c[0]*=f,c[1]*=f,c[2]*=f,c[4]*=p,c[5]*=p,c[6]*=p,c[8]*=g,c[9]*=g,c[10]*=g,si(e,c),n[0]=s,n[1]=i,n[2]=l}function Io(t,e,r,n){const s=t,i=e[0],l=e[1],a=e[2],c=e[3],f=i+i,p=l+l,g=a+a,u=i*f,v=i*p,M=i*g,d=l*p,y=l*g,x=a*g,T=c*f,P=c*p,L=c*g,_=n[0],o=n[1],h=n[2];return s[0]=(1-(d+x))*_,s[1]=(v+L)*_,s[2]=(M-P)*_,s[3]=0,s[4]=(v-L)*o,s[5]=(1-(u+x))*o,s[6]=(y+T)*o,s[7]=0,s[8]=(M+P)*h,s[9]=(y-T)*h,s[10]=(1-(u+d))*h,s[11]=0,s[12]=r[0],s[13]=r[1],s[14]=r[2],s[15]=1,s}function Uo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=r+r,a=n+n,c=s+s,f=r*l,p=n*l,g=n*a,u=s*l,v=s*a,M=s*c,d=i*l,y=i*a,x=i*c;return t[0]=1-g-M,t[1]=p+x,t[2]=u-y,t[3]=0,t[4]=p-x,t[5]=1-f-M,t[6]=v+d,t[7]=0,t[8]=u+y,t[9]=v-d,t[10]=1-f-g,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Do(t,e,r,n,s){let i=1/Math.tan(e/2),l=1/(n-s);return t[0]=i/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=i,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=(s+n)*l,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*s*n*l,t[15]=0,t}function zo(t,e,r,n,s,i,l){let a=1/(e-r),c=1/(n-s),f=1/(i-l);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*c,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*f,t[11]=0,t[12]=(e+r)*a,t[13]=(s+n)*c,t[14]=(l+i)*f,t[15]=1,t}function Go(t,e,r,n){let s=e[0],i=e[1],l=e[2],a=n[0],c=n[1],f=n[2],p=s-r[0],g=i-r[1],u=l-r[2],v=p*p+g*g+u*u;v===0?u=1:(v=1/Math.sqrt(v),p*=v,g*=v,u*=v);let M=c*u-f*g,d=f*p-a*u,y=a*g-c*p;return v=M*M+d*d+y*y,v===0&&(f?a+=1e-6:c?f+=1e-6:c+=1e-6,M=c*u-f*g,d=f*p-a*u,y=a*g-c*p,v=M*M+d*d+y*y),v=1/Math.sqrt(v),M*=v,d*=v,y*=v,t[0]=M,t[1]=d,t[2]=y,t[3]=0,t[4]=g*y-u*d,t[5]=u*M-p*y,t[6]=p*d-g*M,t[7]=0,t[8]=p,t[9]=g,t[10]=u,t[11]=0,t[12]=s,t[13]=i,t[14]=l,t[15]=1,t}function qn(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t[9]=e[9]+r[9],t[10]=e[10]+r[10],t[11]=e[11]+r[11],t[12]=e[12]+r[12],t[13]=e[13]+r[13],t[14]=e[14]+r[14],t[15]=e[15]+r[15],t}function Yn(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t[9]=e[9]-r[9],t[10]=e[10]-r[10],t[11]=e[11]-r[11],t[12]=e[12]-r[12],t[13]=e[13]-r[13],t[14]=e[14]-r[14],t[15]=e[15]-r[15],t}function Vo(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}class St extends Array{constructor(e=1,r=0,n=0,s=0,i=0,l=1,a=0,c=0,f=0,p=0,g=1,u=0,v=0,M=0,d=0,y=1){return super(e,r,n,s,i,l,a,c,f,p,g,u,v,M,d,y),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}set(e,r,n,s,i,l,a,c,f,p,g,u,v,M,d,y){return e.length?this.copy(e):(Co(this,e,r,n,s,i,l,a,c,f,p,g,u,v,M,d,y),this)}translate(e,r=this){return Ro(this,r,e),this}rotate(e,r,n=this){return Lo(this,n,e,r),this}scale(e,r=this){return Po(this,r,typeof e=="number"?[e,e,e]:e),this}add(e,r){return r?qn(this,e,r):qn(this,this,e),this}sub(e,r){return r?Yn(this,e,r):Yn(this,this,e),this}multiply(e,r){return e.length?r?jn(this,e,r):jn(this,this,e):Vo(this,this,e),this}identity(){return Fo(this),this}copy(e){return Eo(this,e),this}fromPerspective({fov:e,aspect:r,near:n,far:s}={}){return Do(this,e,r,n,s),this}fromOrthogonal({left:e,right:r,bottom:n,top:s,near:i,far:l}){return zo(this,e,r,n,s,i,l),this}fromQuaternion(e){return Uo(this,e),this}setPosition(e){return this.x=e[0],this.y=e[1],this.z=e[2],this}inverse(e=this){return To(this,e),this}compose(e,r,n){return Io(this,e,r,n),this}decompose(e,r,n){return Oo(this,e,r,n),this}getRotation(e){return si(e,this),this}getTranslation(e){return Bo(e,this),this}getScaling(e){return ni(e,this),this}getMaxScaleOnAxis(){return No(this)}lookAt(e,r,n){return Go(this,e,r,n),this}determinant(){return ri(this)}fromArray(e,r=0){return this[0]=e[r],this[1]=e[r+1],this[2]=e[r+2],this[3]=e[r+3],this[4]=e[r+4],this[5]=e[r+5],this[6]=e[r+6],this[7]=e[r+7],this[8]=e[r+8],this[9]=e[r+9],this[10]=e[r+10],this[11]=e[r+11],this[12]=e[r+12],this[13]=e[r+13],this[14]=e[r+14],this[15]=e[r+15],this}toArray(e=[],r=0){return e[r]=this[0],e[r+1]=this[1],e[r+2]=this[2],e[r+3]=this[3],e[r+4]=this[4],e[r+5]=this[5],e[r+6]=this[6],e[r+7]=this[7],e[r+8]=this[8],e[r+9]=this[9],e[r+10]=this[10],e[r+11]=this[11],e[r+12]=this[12],e[r+13]=this[13],e[r+14]=this[14],e[r+15]=this[15],e}}function Ho(t,e,r="YXZ"){return r==="XYZ"?(t[1]=Math.asin(Math.min(Math.max(e[8],-1),1)),Math.abs(e[8])<.99999?(t[0]=Math.atan2(-e[9],e[10]),t[2]=Math.atan2(-e[4],e[0])):(t[0]=Math.atan2(e[6],e[5]),t[2]=0)):r==="YXZ"?(t[0]=Math.asin(-Math.min(Math.max(e[9],-1),1)),Math.abs(e[9])<.99999?(t[1]=Math.atan2(e[8],e[10]),t[2]=Math.atan2(e[1],e[5])):(t[1]=Math.atan2(-e[2],e[0]),t[2]=0)):r==="ZXY"?(t[0]=Math.asin(Math.min(Math.max(e[6],-1),1)),Math.abs(e[6])<.99999?(t[1]=Math.atan2(-e[2],e[10]),t[2]=Math.atan2(-e[4],e[5])):(t[1]=0,t[2]=Math.atan2(e[1],e[0]))):r==="ZYX"?(t[1]=Math.asin(-Math.min(Math.max(e[2],-1),1)),Math.abs(e[2])<.99999?(t[0]=Math.atan2(e[6],e[10]),t[2]=Math.atan2(e[1],e[0])):(t[0]=0,t[2]=Math.atan2(-e[4],e[5]))):r==="YZX"?(t[2]=Math.asin(Math.min(Math.max(e[1],-1),1)),Math.abs(e[1])<.99999?(t[0]=Math.atan2(-e[9],e[5]),t[1]=Math.atan2(-e[2],e[0])):(t[0]=0,t[1]=Math.atan2(e[8],e[10]))):r==="XZY"&&(t[2]=Math.asin(-Math.min(Math.max(e[4],-1),1)),Math.abs(e[4])<.99999?(t[0]=Math.atan2(e[6],e[5]),t[1]=Math.atan2(e[8],e[0])):(t[0]=Math.atan2(-e[9],e[10]),t[1]=0)),t}const Kn=new St;class ko extends Array{constructor(e=0,r=e,n=e,s="YXZ"){super(e,r,n),this.order=s,this.onChange=()=>{},this._target=this;const i=["0","1","2"];return new Proxy(this,{set(l,a){const c=Reflect.set(...arguments);return c&&i.includes(a)&&l.onChange(),c}})}get x(){return this[0]}get y(){return this[1]}get z(){return this[2]}set x(e){this._target[0]=e,this.onChange()}set y(e){this._target[1]=e,this.onChange()}set z(e){this._target[2]=e,this.onChange()}set(e,r=e,n=e){return e.length?this.copy(e):(this._target[0]=e,this._target[1]=r,this._target[2]=n,this.onChange(),this)}copy(e){return this._target[0]=e[0],this._target[1]=e[1],this._target[2]=e[2],this.onChange(),this}reorder(e){return this._target.order=e,this.onChange(),this}fromRotationMatrix(e,r=this.order){return Ho(this._target,e,r),this.onChange(),this}fromQuaternion(e,r=this.order,n){return Kn.fromQuaternion(e),this._target.fromRotationMatrix(Kn,r),n||this.onChange(),this}fromArray(e,r=0){return this._target[0]=e[r],this._target[1]=e[r+1],this._target[2]=e[r+2],this}toArray(e=[],r=0){return e[r]=this[0],e[r+1]=this[1],e[r+2]=this[2],e}}class gt{constructor(){this.parent=null,this.children=[],this.visible=!0,this.matrix=new St,this.worldMatrix=new St,this.matrixAutoUpdate=!0,this.worldMatrixNeedsUpdate=!1,this.position=new Ce,this.quaternion=new sr,this.scale=new Ce(1),this.rotation=new ko,this.up=new Ce(0,1,0),this.rotation._target.onChange=()=>this.quaternion.fromEuler(this.rotation,!0),this.quaternion._target.onChange=()=>this.rotation.fromQuaternion(this.quaternion,void 0,!0)}setParent(e,r=!0){this.parent&&e!==this.parent&&this.parent.removeChild(this,!1),this.parent=e,r&&e&&e.addChild(this,!1)}addChild(e,r=!0){~this.children.indexOf(e)||this.children.push(e),r&&e.setParent(this,!1)}removeChild(e,r=!0){~this.children.indexOf(e)&&this.children.splice(this.children.indexOf(e),1),r&&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 r=0,n=this.children.length;r<n;r++)this.children[r].updateMatrixWorld(e)}updateMatrix(){this.matrix.compose(this.quaternion,this.position,this.scale),this.worldMatrixNeedsUpdate=!0}traverse(e){if(!e(this))for(let r=0,n=this.children.length;r<n;r++)this.children[r].traverse(e)}decompose(){this.matrix.decompose(this.quaternion._target,this.position,this.scale),this.rotation.fromQuaternion(this.quaternion)}lookAt(e,r=!1){r?this.matrix.lookAt(this.position,e,this.up):this.matrix.lookAt(e,this.position,this.up),this.matrix.getRotation(this.quaternion._target),this.rotation.fromQuaternion(this.quaternion)}}const Wo=new St,$o=new Ce,Xo=new Ce;class Tn extends gt{constructor(e,{near:r=.1,far:n=100,fov:s=45,aspect:i=1,left:l,right:a,bottom:c,top:f,zoom:p=1}={}){super(),Object.assign(this,{near:r,far:n,fov:s,aspect:i,left:l,right:a,bottom:c,top:f,zoom:p}),this.projectionMatrix=new St,this.viewMatrix=new St,this.projectionViewMatrix=new St,this.worldPosition=new Ce,this.type=l||a?"orthographic":"perspective",this.type==="orthographic"?this.orthographic():this.perspective()}perspective({near:e=this.near,far:r=this.far,fov:n=this.fov,aspect:s=this.aspect}={}){return Object.assign(this,{near:e,far:r,fov:n,aspect:s}),this.projectionMatrix.fromPerspective({fov:n*(Math.PI/180),aspect:s,near:e,far:r}),this.type="perspective",this}orthographic({near:e=this.near,far:r=this.far,left:n=this.left||-1,right:s=this.right||1,bottom:i=this.bottom||-1,top:l=this.top||1,zoom:a=this.zoom}={}){return Object.assign(this,{near:e,far:r,left:n,right:s,bottom:i,top:l,zoom:a}),n/=a,s/=a,i/=a,l/=a,this.projectionMatrix.fromOrthogonal({left:n,right:s,bottom:i,top:l,near:e,far:r}),this.type="orthographic",this}updateMatrixWorld(){return super.updateMatrixWorld(),this.viewMatrix.inverse(this.worldMatrix),this.worldMatrix.getTranslation(this.worldPosition),this.projectionViewMatrix.multiply(this.projectionMatrix,this.viewMatrix),this}updateProjectionMatrix(){return this.type==="perspective"?this.perspective():this.orthographic()}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(Wo.inverse(this.projectionMatrix)),e.applyMatrix4(this.worldMatrix),this}updateFrustum(){this.frustum||(this.frustum=[new Ce,new Ce,new Ce,new Ce,new Ce,new Ce]);const e=this.projectionViewMatrix;this.frustum[0].set(e[3]-e[0],e[7]-e[4],e[11]-e[8]).constant=e[15]-e[12],this.frustum[1].set(e[3]+e[0],e[7]+e[4],e[11]+e[8]).constant=e[15]+e[12],this.frustum[2].set(e[3]+e[1],e[7]+e[5],e[11]+e[9]).constant=e[15]+e[13],this.frustum[3].set(e[3]-e[1],e[7]-e[5],e[11]-e[9]).constant=e[15]-e[13],this.frustum[4].set(e[3]-e[2],e[7]-e[6],e[11]-e[10]).constant=e[15]-e[14],this.frustum[5].set(e[3]+e[2],e[7]+e[6],e[11]+e[10]).constant=e[15]+e[14];for(let r=0;r<6;r++){const n=1/this.frustum[r].distance();this.frustum[r].multiply(n),this.frustum[r].constant*=n}}frustumIntersectsMesh(e,r=e.worldMatrix){if(!e.geometry.attributes.position||((!e.geometry.bounds||e.geometry.bounds.radius===1/0)&&e.geometry.computeBoundingSphere(),!e.geometry.bounds))return!0;const n=$o;n.copy(e.geometry.bounds.center),n.applyMatrix4(r);const s=e.geometry.bounds.radius*r.getMaxScaleOnAxis();return this.frustumIntersectsSphere(n,s)}frustumIntersectsSphere(e,r){const n=Xo;for(let s=0;s<6;s++){const i=this.frustum[s];if(n.copy(i).dot(e)+i.constant<-r)return!1}return!0}}function jo(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function qo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=r+r,a=n+n,c=s+s,f=r*l,p=n*l,g=n*a,u=s*l,v=s*a,M=s*c,d=i*l,y=i*a,x=i*c;return t[0]=1-g-M,t[3]=p-x,t[6]=u+y,t[1]=p+x,t[4]=1-f-M,t[7]=v-d,t[2]=u-y,t[5]=v+d,t[8]=1-f-g,t}function Yo(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function Ko(t,e,r,n,s,i,l,a,c,f){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t[4]=i,t[5]=l,t[6]=a,t[7]=c,t[8]=f,t}function Qo(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function Zo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=e[4],a=e[5],c=e[6],f=e[7],p=e[8],g=p*l-a*f,u=-p*i+a*c,v=f*i-l*c,M=r*g+n*u+s*v;return M?(M=1/M,t[0]=g*M,t[1]=(-p*n+s*f)*M,t[2]=(a*n-s*l)*M,t[3]=u*M,t[4]=(p*r-s*c)*M,t[5]=(-a*r+s*i)*M,t[6]=v*M,t[7]=(-f*r+n*c)*M,t[8]=(l*r-n*i)*M,t):null}function Qn(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],a=e[4],c=e[5],f=e[6],p=e[7],g=e[8],u=r[0],v=r[1],M=r[2],d=r[3],y=r[4],x=r[5],T=r[6],P=r[7],L=r[8];return t[0]=u*n+v*l+M*f,t[1]=u*s+v*a+M*p,t[2]=u*i+v*c+M*g,t[3]=d*n+y*l+x*f,t[4]=d*s+y*a+x*p,t[5]=d*i+y*c+x*g,t[6]=T*n+P*l+L*f,t[7]=T*s+P*a+L*p,t[8]=T*i+P*c+L*g,t}function Jo(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],a=e[4],c=e[5],f=e[6],p=e[7],g=e[8],u=r[0],v=r[1];return t[0]=n,t[1]=s,t[2]=i,t[3]=l,t[4]=a,t[5]=c,t[6]=u*n+v*l+f,t[7]=u*s+v*a+p,t[8]=u*i+v*c+g,t}function ea(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],a=e[4],c=e[5],f=e[6],p=e[7],g=e[8],u=Math.sin(r),v=Math.cos(r);return t[0]=v*n+u*l,t[1]=v*s+u*a,t[2]=v*i+u*c,t[3]=v*l-u*n,t[4]=v*a-u*s,t[5]=v*c-u*i,t[6]=f,t[7]=p,t[8]=g,t}function ta(t,e,r){let n=r[0],s=r[1];return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=s*e[3],t[4]=s*e[4],t[5]=s*e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function ra(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=e[4],a=e[5],c=e[6],f=e[7],p=e[8],g=e[9],u=e[10],v=e[11],M=e[12],d=e[13],y=e[14],x=e[15],T=r*a-n*l,P=r*c-s*l,L=r*f-i*l,_=n*c-s*a,o=n*f-i*a,h=s*f-i*c,m=p*d-g*M,w=p*y-u*M,E=p*x-v*M,B=g*y-u*d,W=g*x-v*d,N=u*x-v*y,I=T*N-P*W+L*B+_*E-o*w+h*m;return I?(I=1/I,t[0]=(a*N-c*W+f*B)*I,t[1]=(c*E-l*N-f*w)*I,t[2]=(l*W-a*E+f*m)*I,t[3]=(s*W-n*N-i*B)*I,t[4]=(r*N-s*E+i*w)*I,t[5]=(n*E-r*W-i*m)*I,t[6]=(d*h-y*o+x*_)*I,t[7]=(y*L-M*h-x*P)*I,t[8]=(M*o-d*L+x*T)*I,t):null}class na extends Array{constructor(e=1,r=0,n=0,s=0,i=1,l=0,a=0,c=0,f=1){return super(e,r,n,s,i,l,a,c,f),this}set(e,r,n,s,i,l,a,c,f){return e.length?this.copy(e):(Ko(this,e,r,n,s,i,l,a,c,f),this)}translate(e,r=this){return Jo(this,r,e),this}rotate(e,r=this){return ea(this,r,e),this}scale(e,r=this){return ta(this,r,e),this}multiply(e,r){return r?Qn(this,e,r):Qn(this,this,e),this}identity(){return Qo(this),this}copy(e){return Yo(this,e),this}fromMatrix4(e){return jo(this,e),this}fromQuaternion(e){return qo(this,e),this}fromBasis(e,r,n){return this.set(e[0],e[1],e[2],r[0],r[1],r[2],n[0],n[1],n[2]),this}inverse(e=this){return Zo(this,e),this}getNormalMatrix(e){return ra(this,e),this}}let sa=0;class nt extends gt{constructor(e,{geometry:r,program:n,mode:s=e.TRIANGLES,frustumCulled:i=!0,renderOrder:l=0}={}){super(),e.canvas||console.error("gl not passed as first argument to Mesh"),this.gl=e,this.id=sa++,this.geometry=r,this.program=n,this.mode=s,this.frustumCulled=i,this.renderOrder=l,this.modelViewMatrix=new St,this.normalMatrix=new na,this.beforeRenderCallbacks=[],this.afterRenderCallbacks=[]}onBeforeRender(e){return this.beforeRenderCallbacks.push(e),this}onAfterRender(e){return this.afterRenderCallbacks.push(e),this}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.beforeRenderCallbacks.forEach(n=>n&&n({mesh:this,camera:e}));let r=this.program.cullFace&&this.worldMatrix.determinant()<0;this.program.use({flipFaces:r}),this.geometry.draw({mode:this.mode,program:this.program}),this.afterRenderCallbacks.forEach(n=>n&&n({mesh:this,camera:e}))}}const Zn=new Uint8Array(4);function Jn(t){return(t&t-1)===0}let ia=1;class Qe{constructor(e,{image:r,target:n=e.TEXTURE_2D,type:s=e.UNSIGNED_BYTE,format:i=e.RGBA,internalFormat:l=i,wrapS:a=e.CLAMP_TO_EDGE,wrapT:c=e.CLAMP_TO_EDGE,wrapR:f=e.CLAMP_TO_EDGE,generateMipmaps:p=n===(e.TEXTURE_2D||e.TEXTURE_CUBE_MAP),minFilter:g=p?e.NEAREST_MIPMAP_LINEAR:e.LINEAR,magFilter:u=e.LINEAR,premultiplyAlpha:v=!1,unpackAlignment:M=4,flipY:d=n==(e.TEXTURE_2D||e.TEXTURE_3D),anisotropy:y=0,level:x=0,width:T,height:P=T,length:L=1}={}){this.gl=e,this.id=ia++,this.image=r,this.target=n,this.type=s,this.format=i,this.internalFormat=l,this.minFilter=g,this.magFilter=u,this.wrapS=a,this.wrapT=c,this.wrapR=f,this.generateMipmaps=p,this.premultiplyAlpha=v,this.unpackAlignment=M,this.flipY=d,this.anisotropy=Math.min(y,this.gl.renderer.parameters.maxAnisotropy),this.level=x,this.width=T,this.height=P,this.length=L,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 r=!(this.image===this.store.image&&!this.needsUpdate);if((r||this.glState.textureUnits[e]!==this.id)&&(this.gl.renderer.activeTexture(e),this.bind()),!!r){if(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.wrapR!==this.state.wrapR&&(this.gl.texParameteri(this.target,this.gl.TEXTURE_WRAP_R,this.wrapR),this.state.wrapR=this.wrapR),this.anisotropy&&this.anisotropy!==this.state.anisotropy&&(this.gl.texParameterf(this.target,this.gl.renderer.getExtension("EXT_texture_filter_anisotropic").TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropy),this.state.anisotropy=this.anisotropy),this.image){if(this.image.width&&(this.width=this.image.width,this.height=this.image.height),this.target===this.gl.TEXTURE_CUBE_MAP)for(let n=0;n<6;n++)this.gl.texImage2D(this.gl.TEXTURE_CUBE_MAP_POSITIVE_X+n,this.level,this.internalFormat,this.format,this.type,this.image[n]);else if(ArrayBuffer.isView(this.image))this.target===this.gl.TEXTURE_2D?this.gl.texImage2D(this.target,this.level,this.internalFormat,this.width,this.height,0,this.format,this.type,this.image):(this.target===this.gl.TEXTURE_2D_ARRAY||this.target===this.gl.TEXTURE_3D)&&this.gl.texImage3D(this.target,this.level,this.internalFormat,this.width,this.height,this.length,0,this.format,this.type,this.image);else if(this.image.isCompressedTexture)for(let n=0;n<this.image.length;n++)this.gl.compressedTexImage2D(this.target,n,this.internalFormat,this.image[n].width,this.image[n].height,0,this.image[n].data);else this.target===this.gl.TEXTURE_2D?this.gl.texImage2D(this.target,this.level,this.internalFormat,this.format,this.type,this.image):this.gl.texImage3D(this.target,this.level,this.internalFormat,this.width,this.height,this.length,0,this.format,this.type,this.image);this.generateMipmaps&&(!this.gl.renderer.isWebgl2&&(!Jn(this.image.width)||!Jn(this.image.height))?(this.generateMipmaps=!1,this.wrapS=this.wrapT=this.gl.CLAMP_TO_EDGE,this.minFilter=this.gl.LINEAR):this.gl.generateMipmap(this.target)),this.onUpdate&&this.onUpdate()}else if(this.target===this.gl.TEXTURE_CUBE_MAP)for(let n=0;n<6;n++)this.gl.texImage2D(this.gl.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,Zn);else this.width?this.target===this.gl.TEXTURE_2D?this.gl.texImage2D(this.target,this.level,this.internalFormat,this.width,this.height,0,this.format,this.type,null):this.gl.texImage3D(this.target,this.level,this.internalFormat,this.width,this.height,this.length,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,Zn);this.store.image=this.image}}}class ii{constructor(e,{width:r=e.canvas.width,height:n=e.canvas.height,target:s=e.FRAMEBUFFER,color:i=1,depth:l=!0,stencil:a=!1,depthTexture:c=!1,wrapS:f=e.CLAMP_TO_EDGE,wrapT:p=e.CLAMP_TO_EDGE,wrapR:g=e.CLAMP_TO_EDGE,minFilter:u=e.LINEAR,magFilter:v=u,type:M=e.UNSIGNED_BYTE,format:d=e.RGBA,internalFormat:y=d,unpackAlignment:x,premultiplyAlpha:T}={}){this.gl=e,this.width=r,this.height=n,this.depth=l,this.stencil=a,this.buffer=this.gl.createFramebuffer(),this.target=s,this.gl.renderer.bindFramebuffer(this),this.textures=[];const P=[];for(let L=0;L<i;L++)this.textures.push(new Qe(e,{width:r,height:n,wrapS:f,wrapT:p,wrapR:g,minFilter:u,magFilter:v,type:M,format:d,internalFormat:y,unpackAlignment:x,premultiplyAlpha:T,flipY:!1,generateMipmaps:!1})),this.textures[L].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+L,this.gl.TEXTURE_2D,this.textures[L].texture,0),P.push(this.gl.COLOR_ATTACHMENT0+L);P.length>1&&this.gl.renderer.drawBuffers(P),this.texture=this.textures[0],c&&(this.gl.renderer.isWebgl2||this.gl.renderer.getExtension("WEBGL_depth_texture"))?(this.depthTexture=new Qe(e,{width:r,height:n,minFilter:this.gl.NEAREST,magFilter:this.gl.NEAREST,format:this.stencil?this.gl.DEPTH_STENCIL:this.gl.DEPTH_COMPONENT,internalFormat:e.renderer.isWebgl2?this.stencil?this.gl.DEPTH24_STENCIL8:this.gl.DEPTH_COMPONENT16:this.gl.DEPTH_COMPONENT,type:this.stencil?this.gl.UNSIGNED_INT_24_8:this.gl.UNSIGNED_INT}),this.depthTexture.update(),this.gl.framebufferTexture2D(this.target,this.stencil?this.gl.DEPTH_STENCIL_ATTACHMENT:this.gl.DEPTH_ATTACHMENT,this.gl.TEXTURE_2D,this.depthTexture.texture,0)):(l&&!a&&(this.depthBuffer=this.gl.createRenderbuffer(),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,r,n),this.gl.framebufferRenderbuffer(this.target,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.depthBuffer)),a&&!l&&(this.stencilBuffer=this.gl.createRenderbuffer(),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.stencilBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.STENCIL_INDEX8,r,n),this.gl.framebufferRenderbuffer(this.target,this.gl.STENCIL_ATTACHMENT,this.gl.RENDERBUFFER,this.stencilBuffer)),l&&a&&(this.depthStencilBuffer=this.gl.createRenderbuffer(),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.depthStencilBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_STENCIL,r,n),this.gl.framebufferRenderbuffer(this.target,this.gl.DEPTH_STENCIL_ATTACHMENT,this.gl.RENDERBUFFER,this.depthStencilBuffer))),this.gl.renderer.bindFramebuffer({target:this.target})}setSize(e,r){if(!(this.width===e&&this.height===r)){this.width=e,this.height=r,this.gl.renderer.bindFramebuffer(this);for(let n=0;n<this.textures.length;n++)this.textures[n].width=e,this.textures[n].height=r,this.textures[n].needsUpdate=!0,this.textures[n].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+n,this.gl.TEXTURE_2D,this.textures[n].texture,0);this.depthTexture?(this.depthTexture.width=e,this.depthTexture.height=r,this.depthTexture.needsUpdate=!0,this.depthTexture.update(),this.gl.framebufferTexture2D(this.target,this.gl.DEPTH_ATTACHMENT,this.gl.TEXTURE_2D,this.depthTexture.texture,0)):(this.depthBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,e,r)),this.stencilBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.stencilBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.STENCIL_INDEX8,e,r)),this.depthStencilBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.depthStencilBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_STENCIL,e,r))),this.gl.renderer.bindFramebuffer({target:this.target})}}}function oa(t,e){return t[0]=e[0],t[1]=e[1],t}function aa(t,e,r){return t[0]=e,t[1]=r,t}function es(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t}function ts(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t}function la(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t}function ca(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t}function sn(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t}function ua(t,e){var r=e[0]-t[0],n=e[1]-t[1];return Math.sqrt(r*r+n*n)}function ha(t,e){var r=e[0]-t[0],n=e[1]-t[1];return r*r+n*n}function rs(t){var e=t[0],r=t[1];return Math.sqrt(e*e+r*r)}function fa(t){var e=t[0],r=t[1];return e*e+r*r}function da(t,e){return t[0]=-e[0],t[1]=-e[1],t}function ma(t,e){return t[0]=1/e[0],t[1]=1/e[1],t}function pa(t,e){var r=e[0],n=e[1],s=r*r+n*n;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t}function ga(t,e){return t[0]*e[0]+t[1]*e[1]}function ns(t,e){return t[0]*e[1]-t[1]*e[0]}function va(t,e,r,n){var s=e[0],i=e[1];return t[0]=s+n*(r[0]-s),t[1]=i+n*(r[1]-i),t}function ya(t,e,r,n,s){const i=Math.exp(-n*s);let l=e[0],a=e[1];return t[0]=r[0]+(l-r[0])*i,t[1]=r[1]+(a-r[1])*i,t}function xa(t,e,r){var n=e[0],s=e[1];return t[0]=r[0]*n+r[3]*s+r[6],t[1]=r[1]*n+r[4]*s+r[7],t}function wa(t,e,r){let n=e[0],s=e[1];return t[0]=r[0]*n+r[4]*s+r[12],t[1]=r[1]*n+r[5]*s+r[13],t}function Ma(t,e){return t[0]===e[0]&&t[1]===e[1]}class Mr extends Array{constructor(e=0,r=e){return super(e,r),this}get x(){return this[0]}get y(){return this[1]}set x(e){this[0]=e}set y(e){this[1]=e}set(e,r=e){return e.length?this.copy(e):(aa(this,e,r),this)}copy(e){return oa(this,e),this}add(e,r){return r?es(this,e,r):es(this,this,e),this}sub(e,r){return r?ts(this,e,r):ts(this,this,e),this}multiply(e){return e.length?la(this,this,e):sn(this,this,e),this}divide(e){return e.length?ca(this,this,e):sn(this,this,1/e),this}inverse(e=this){return ma(this,e),this}len(){return rs(this)}distance(e){return e?ua(this,e):rs(this)}squaredLen(){return this.squaredDistance()}squaredDistance(e){return e?ha(this,e):fa(this)}negate(e=this){return da(this,e),this}cross(e,r){return r?ns(e,r):ns(this,e)}scale(e){return sn(this,this,e),this}normalize(){return pa(this,this),this}dot(e){return ga(this,e)}equals(e){return Ma(this,e)}applyMatrix3(e){return xa(this,this,e),this}applyMatrix4(e){return wa(this,this,e),this}lerp(e,r){return va(this,this,e,r),this}smoothLerp(e,r,n){return ya(this,this,e,r,n),this}clone(){return new Mr(this[0],this[1])}fromArray(e,r=0){return this[0]=e[r],this[1]=e[r+1],this}toArray(e=[],r=0){return e[r]=this[0],e[r+1]=this[1],e}}class ba extends Array{constructor(e=0,r=e,n=e,s=e){return super(e,r,n,s),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}set y(e){this[1]=e}set z(e){this[2]=e}set w(e){this[3]=e}set(e,r=e,n=e,s=e){return e.length?this.copy(e):(Js(this,e,r,n,s),this)}copy(e){return Zs(this,e),this}normalize(){return ei(this,this),this}multiply(e){return co(this,this,e),this}dot(e){return ti(this,e)}fromArray(e,r=0){return this[0]=e[r],this[1]=e[r+1],this[2]=e[r+2],this[3]=e[r+3],this}toArray(e=[],r=0){return e[r]=this[0],e[r+1]=this[1],e[r+2]=this[2],e[r+3]=this[3],e}}class Xt extends ct{constructor(e,{width:r=1,height:n=1,widthSegments:s=1,heightSegments:i=1,attributes:l={}}={}){const a=s,c=i,f=(a+1)*(c+1),p=a*c*6,g=new Float32Array(f*3),u=new Float32Array(f*3),v=new Float32Array(f*2),M=p>65536?new Uint32Array(p):new Uint16Array(p);Xt.buildPlane(g,u,v,M,r,n,0,a,c),Object.assign(l,{position:{size:3,data:g},normal:{size:3,data:u},uv:{size:2,data:v},index:{data:M}}),super(e,l)}static buildPlane(e,r,n,s,i,l,a,c,f,p=0,g=1,u=2,v=1,M=-1,d=0,y=0){const x=d,T=i/c,P=l/f;for(let L=0;L<=f;L++){let _=L*P-l/2;for(let o=0;o<=c;o++,d++){let h=o*T-i/2;if(e[d*3+p]=h*v,e[d*3+g]=_*M,e[d*3+u]=a/2,r[d*3+p]=0,r[d*3+g]=0,r[d*3+u]=a>=0?1:-1,n[d*2]=o/c,n[d*2+1]=1-L/f,L===f||o===c)continue;let m=x+o+L*(c+1),w=x+o+(L+1)*(c+1),E=x+o+(L+1)*(c+1)+1,B=x+o+L*(c+1)+1;s[y*6]=m,s[y*6+1]=w,s[y*6+2]=B,s[y*6+3]=w,s[y*6+4]=E,s[y*6+5]=B,y++}}}}class ss extends ct{constructor(e,{width:r=1,height:n=1,depth:s=1,widthSegments:i=1,heightSegments:l=1,depthSegments:a=1,attributes:c={}}={}){const f=i,p=l,g=a,u=(f+1)*(p+1)*2+(f+1)*(g+1)*2+(p+1)*(g+1)*2,v=(f*p*2+f*g*2+p*g*2)*6,M=new Float32Array(u*3),d=new Float32Array(u*3),y=new Float32Array(u*2),x=u>65536?new Uint32Array(v):new Uint16Array(v);let T=0,P=0;Xt.buildPlane(M,d,y,x,s,n,r,g,p,2,1,0,-1,-1,T,P),T+=(g+1)*(p+1),P+=g*p,Xt.buildPlane(M,d,y,x,s,n,-r,g,p,2,1,0,1,-1,T,P),T+=(g+1)*(p+1),P+=g*p,Xt.buildPlane(M,d,y,x,r,s,n,g,f,0,2,1,1,1,T,P),T+=(f+1)*(g+1),P+=f*g,Xt.buildPlane(M,d,y,x,r,s,-n,g,f,0,2,1,1,-1,T,P),T+=(f+1)*(g+1),P+=f*g,Xt.buildPlane(M,d,y,x,r,n,-s,f,p,0,1,2,-1,-1,T,P),T+=(f+1)*(p+1),P+=f*p,Xt.buildPlane(M,d,y,x,r,n,s,f,p,0,1,2,1,-1,T,P),Object.assign(c,{position:{size:3,data:M},normal:{size:3,data:d},uv:{size:2,data:y},index:{data:x}}),super(e,c)}}class is extends ct{constructor(e,{radiusTop:r=.5,radiusBottom:n=.5,height:s=1,radialSegments:i=8,heightSegments:l=1,openEnded:a=!1,thetaStart:c=0,thetaLength:f=Math.PI*2,attributes:p={}}={}){const g=i,u=l,v=c,M=f,d=a?0:n&&r?2:1,y=(g+1)*(u+1+d)+d,x=g*u*6+d*g*3,T=new Float32Array(y*3),P=new Float32Array(y*3),L=new Float32Array(y*2),_=y>65536?new Uint32Array(x):new Uint16Array(x);let o=0,h=0;const m=[];w(),a||(r&&E(!0),n&&E(!1));function w(){let B,W;const N=new Ce,I=(n-r)/s;for(W=0;W<=u;W++){const D=[],K=W/u,q=K*(n-r)+r;for(B=0;B<=g;B++){const O=B/g,H=O*M+v,G=Math.sin(H),Y=Math.cos(H);T.set([q*G,(.5-K)*s,q*Y],o*3),N.set(G,I,Y).normalize(),P.set([N.x,N.y,N.z],o*3),L.set([O,1-K],o*2),D.push(o++)}m.push(D)}for(B=0;B<g;B++)for(W=0;W<u;W++){const D=m[W][B],K=m[W+1][B],q=m[W+1][B+1],O=m[W][B+1];_.set([D,K,O,K,q,O],h*3),h+=2}}function E(B){let W;const N=B===!0?r:n,I=B===!0?1:-1,D=o;for(T.set([0,.5*s*I,0],o*3),P.set([0,I,0],o*3),L.set([.5,.5],o*2),o++,W=0;W<=g;W++){const q=W/g*M+v,O=Math.cos(q),H=Math.sin(q);T.set([N*H,.5*s*I,N*O],o*3),P.set([0,I,0],o*3),L.set([O*.5+.5,H*.5*I+.5],o*2),o++}for(W=0;W<g;W++){const K=D+W+1;B?_.set([K,K+1,D],h*3):_.set([K+1,K,D],h*3),h++}}Object.assign(p,{position:{size:3,data:T},normal:{size:3,data:P},uv:{size:2,data:L},index:{data:_}}),super(e,p)}}class oi extends ct{constructor(e,{attributes:r={}}={}){Object.assign(r,{position:{size:2,data:new Float32Array([-1,-1,3,-1,-1,3])},uv:{size:2,data:new Float32Array([0,0,2,0,0,2])}}),super(e,r)}}class Aa extends ct{constructor(e,{radius:r=.5,tube:n=.2,radialSegments:s=8,tubularSegments:i=6,arc:l=Math.PI*2,attributes:a={}}={}){const c=(s+1)*(i+1),f=s*i*6,p=new Float32Array(c*3),g=new Float32Array(c*3),u=new Float32Array(c*2),v=c>65536?new Uint32Array(f):new Uint16Array(f),M=new Ce,d=new Ce,y=new Ce;let x=0;for(let T=0;T<=s;T++)for(let P=0;P<=i;P++,x++){const L=P/i*l,_=T/s*Math.PI*2;d.x=(r+n*Math.cos(_))*Math.cos(L),d.y=(r+n*Math.cos(_))*Math.sin(L),d.z=n*Math.sin(_),p.set([d.x,d.y,d.z],x*3),M.x=r*Math.cos(L),M.y=r*Math.sin(L),y.sub(d,M).normalize(),g.set([y.x,y.y,y.z],x*3),u.set([P/i,T/s],x*2)}x=0;for(let T=1;T<=s;T++)for(let P=1;P<=i;P++,x++){const L=(i+1)*T+P-1,_=(i+1)*(T-1)+P-1,o=(i+1)*(T-1)+P,h=(i+1)*T+P;v.set([L,_,h,_,o,h],x*6)}Object.assign(a,{position:{size:3,data:p},normal:{size:3,data:g},uv:{size:2,data:u},index:{data:v}}),super(e,a)}}const Sa=new Mr,_a=new Mr,Ea=new Mr,on=new Ce,os=new Ce,as=new Ce,Ca=new Ce,Fa=new Ce,Ta=new Ce,ls=new Ce,an=new Ce,cs=new Ce,us=new Ce,Ra=new Ce,hs=new St;class Pa{constructor(){this.origin=new Ce,this.direction=new Ce}castMouse(e,r=[0,0]){if(e.type==="orthographic"){const{left:n,right:s,bottom:i,top:l,zoom:a}=e,c=n/a+(s-n)/a*(r[0]*.5+.5),f=i/a+(l-i)/a*(r[1]*.5+.5);this.origin.set(c,f,0),this.origin.applyMatrix4(e.worldMatrix),this.direction.x=-e.worldMatrix[8],this.direction.y=-e.worldMatrix[9],this.direction.z=-e.worldMatrix[10]}else e.worldMatrix.getTranslation(this.origin),this.direction.set(r[0],r[1],.5),e.unproject(this.direction),this.direction.sub(this.origin).normalize()}intersectBounds(e,{maxDistance:r,output:n=[]}={}){Array.isArray(e)||(e=[e]);const s=hs,i=on,l=os,a=n;return a.length=0,e.forEach(c=>{(!c.geometry.bounds||c.geometry.bounds.radius===1/0)&&c.geometry.computeBoundingSphere();const f=c.geometry.bounds;s.inverse(c.worldMatrix);let p;if(r&&(l.copy(this.direction).scaleRotateMatrix4(s),p=r*l.len()),i.copy(this.origin).applyMatrix4(s),l.copy(this.direction).transformDirection(s),r&&i.distance(f.center)-f.radius>p)return;let g=0;if(c.geometry.raycast==="sphere"){if(i.distance(f.center)>f.radius&&(g=this.intersectSphere(f,i,l),!g))return}else if((i.x<f.min.x||i.x>f.max.x||i.y<f.min.y||i.y>f.max.y||i.z<f.min.z||i.z>f.max.z)&&(g=this.intersectBox(f,i,l),!g))return;r&&g>p||(c.hit||(c.hit={localPoint:new Ce,point:new Ce}),c.hit.localPoint.copy(l).multiply(g).add(i),c.hit.point.copy(c.hit.localPoint).applyMatrix4(c.worldMatrix),c.hit.distance=c.hit.point.distance(this.origin),a.push(c))}),a.sort((c,f)=>c.hit.distance-f.hit.distance),a}intersectMeshes(e,{cullFace:r=!0,maxDistance:n,includeUV:s=!0,includeNormal:i=!0,output:l=[]}={}){const a=this.intersectBounds(e,{maxDistance:n,output:l});if(!a.length)return a;const c=hs,f=on,p=os,g=as,u=Ca,v=Fa,M=Ta,d=ls,y=an,x=Sa,T=_a,P=Ea;for(let L=a.length-1;L>=0;L--){const _=a[L];c.inverse(_.worldMatrix);let o;n&&(p.copy(this.direction).scaleRotateMatrix4(c),o=n*p.len()),f.copy(this.origin).applyMatrix4(c),p.copy(this.direction).transformDirection(c);let h=0,m,w,E;const B=_.geometry,W=B.attributes,N=W.index,I=W.position,D=Math.max(0,B.drawRange.start),K=Math.min(N?N.count:I.count,B.drawRange.start+B.drawRange.count),q=I.size;for(let O=D;O<K;O+=3){const H=N?N.data[O]:O,G=N?N.data[O+1]:O+1,Y=N?N.data[O+2]:O+2;g.fromArray(I.data,H*q),u.fromArray(I.data,G*q),v.fromArray(I.data,Y*q);const se=this.intersectTriangle(g,u,v,r,f,p,d);se&&(n&&se>o||(!h||se<h)&&(h=se,m=H,w=G,E=Y,M.copy(d)))}h||a.splice(L,1),_.hit.localPoint.copy(p).multiply(h).add(f),_.hit.point.copy(_.hit.localPoint).applyMatrix4(_.worldMatrix),_.hit.distance=_.hit.point.distance(this.origin),_.hit.faceNormal||(_.hit.localFaceNormal=new Ce,_.hit.faceNormal=new Ce,_.hit.uv=new Mr,_.hit.localNormal=new Ce,_.hit.normal=new Ce),_.hit.localFaceNormal.copy(M),_.hit.faceNormal.copy(_.hit.localFaceNormal).transformDirection(_.worldMatrix),(s||i)&&(g.fromArray(I.data,m*3),u.fromArray(I.data,w*3),v.fromArray(I.data,E*3),this.getBarycoord(_.hit.localPoint,g,u,v,y)),s&&W.uv&&(x.fromArray(W.uv.data,m*2),T.fromArray(W.uv.data,w*2),P.fromArray(W.uv.data,E*2),_.hit.uv.set(x.x*y.x+T.x*y.y+P.x*y.z,x.y*y.x+T.y*y.y+P.y*y.z)),i&&W.normal&&(g.fromArray(W.normal.data,m*3),u.fromArray(W.normal.data,w*3),v.fromArray(W.normal.data,E*3),_.hit.localNormal.set(g.x*y.x+u.x*y.y+v.x*y.z,g.y*y.x+u.y*y.y+v.y*y.z,g.z*y.x+u.z*y.y+v.z*y.z),_.hit.normal.copy(_.hit.localNormal).transformDirection(_.worldMatrix))}return a.sort((L,_)=>L.hit.distance-_.hit.distance),a}intersectPlane(e,r=this.origin,n=this.direction){const s=on;s.sub(e.origin,r);const i=s.dot(e.normal),l=n.dot(e.normal);if(l==0)return 0;const a=i/l;return a<=0?0:r.add(n.scale(a))}intersectSphere(e,r=this.origin,n=this.direction){const s=as;s.sub(e.center,r);const i=s.dot(n),l=s.dot(s)-i*i,a=e.radius*e.radius;if(l>a)return 0;const c=Math.sqrt(a-l),f=i-c,p=i+c;return f<0&&p<0?0:f<0?p:f}intersectBox(e,r=this.origin,n=this.direction){let s,i,l,a,c,f;const p=1/n.x,g=1/n.y,u=1/n.z,v=e.min,M=e.max;return s=((p>=0?v.x:M.x)-r.x)*p,i=((p>=0?M.x:v.x)-r.x)*p,l=((g>=0?v.y:M.y)-r.y)*g,a=((g>=0?M.y:v.y)-r.y)*g,s>a||l>i||(l>s&&(s=l),a<i&&(i=a),c=((u>=0?v.z:M.z)-r.z)*u,f=((u>=0?M.z:v.z)-r.z)*u,s>f||c>i)||(c>s&&(s=c),f<i&&(i=f),i<0)?0:s>=0?s:i}intersectTriangle(e,r,n,s=!0,i=this.origin,l=this.direction,a=ls){const c=an,f=cs,p=us;c.sub(r,e),f.sub(n,e),a.cross(c,f);let g=l.dot(a);if(!g)return 0;let u;if(g>0){if(s)return 0;u=1}else u=-1,g=-g;p.sub(i,e);let v=u*l.dot(f.cross(p,f));if(v<0)return 0;let M=u*l.dot(c.cross(p));if(M<0||v+M>g)return 0;let d=-u*p.dot(a);return d<0?0:d/g}getBarycoord(e,r,n,s,i=an){const l=cs,a=us,c=Ra;l.sub(s,r),a.sub(n,r),c.sub(e,r);const f=l.dot(l),p=l.dot(a),g=l.dot(c),u=a.dot(a),v=a.dot(c),M=f*u-p*p;if(M===0)return i.set(-2,-1,-1);const d=1/M,y=(u*g-p*v)*d,x=(f*v-p*g)*d;return i.set(1-y-x,x,y)}}const La=`
9
- precision highp float;
10
- precision highp int;
11
-
12
- attribute vec3 position;
13
- attribute vec3 normal;
14
-
15
- uniform mat3 normalMatrix;
16
- uniform mat4 modelViewMatrix;
17
- uniform mat4 projectionMatrix;
18
-
19
- varying vec3 vNormal;
20
-
21
- void main() {
22
- vNormal = normalize(normalMatrix * normal);
23
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
24
- }
25
- `,Ba=`
26
- precision highp float;
27
- precision highp int;
28
-
29
- varying vec3 vNormal;
30
-
31
- void main() {
32
- gl_FragColor.rgb = normalize(vNormal);
33
- gl_FragColor.a = 1.0;
34
- }
35
- `;function Na(t){return new ze(t,{vertex:La,fragment:Ba,cullFace:!1})}const fs=new Ce,Oa=new Ce,Ia=new Ce,Ua=new Ce,ds=new sr,Da=new sr,za=new sr,Ga=new sr;class Va{constructor(e,r=1){this.data=e,this.elapsed=0,this.weight=r,this.loop=!0,this.startTime=e.reduce((n,{times:s})=>Math.min(n,s[0]),1/0),this.endTime=e.reduce((n,{times:s})=>Math.max(n,s[s.length-1]),0),this.duration=this.endTime-this.startTime}update(e=1,r){const n=r?1:this.weight/e,s=this.duration?(this.loop?this.elapsed%this.duration:Math.min(this.elapsed,this.duration-.001))+this.startTime:0;this.data.forEach(({node:i,transform:l,interpolation:a,times:c,values:f})=>{if(!this.duration){let T=fs,P=3;l==="quaternion"&&(T=ds,P=4),T.fromArray(f,0),P===4?i[l].slerp(T,n):i[l].lerp(T,n);return}const p=Math.max(1,c.findIndex(T=>T>s))-1,g=p+1;let u=(s-c[p])/(c[g]-c[p]);a==="STEP"&&(u=0);let v=fs,M=Oa,d=Ia,y=Ua,x=3;l==="quaternion"&&(v=ds,M=Da,d=za,y=Ga,x=4),a==="CUBICSPLINE"?(v.fromArray(f,p*x*3+x*1),M.fromArray(f,p*x*3+x*2),d.fromArray(f,g*x*3+x*0),y.fromArray(f,g*x*3+x*1),v=this.cubicSplineInterpolate(u,v,M,d,y),x===4&&v.normalize()):(v.fromArray(f,p*x),y.fromArray(f,g*x),x===4?v.slerp(y,u):v.lerp(y,u)),x===4?i[l].slerp(v,n):i[l].lerp(v,n)})}cubicSplineInterpolate(e,r,n,s,i){const l=e*e,a=l*e,c=3*l-2*a,f=a-l,p=1-c,g=f-l+e;for(let u=0;u<r.length;u++)r[u]=p*r[u]+g*(1-e)*n[u]+c*i[u]+f*e*s[u];return r}}const ms=new St,Ha=new St;class Rt extends nt{constructor(e,{skeleton:r,geometry:n,program:s,mode:i=e.TRIANGLES}={}){super(e,{geometry:n,program:s,mode:i}),this.skeleton=r,this.program=s,this.createBoneTexture()}createBoneTexture(){if(!this.skeleton.joints.length)return;const e=Math.max(4,Math.pow(2,Math.ceil(Math.log(Math.sqrt(this.skeleton.joints.length*4))/Math.LN2)));this.boneMatrices=new Float32Array(e*e*4),this.boneTextureSize=e,this.boneTexture=new Qe(this.gl,{image:this.boneMatrices,generateMipmaps:!1,type:this.gl.FLOAT,internalFormat:this.gl.renderer.isWebgl2?this.gl.RGBA32F:this.gl.RGBA,minFilter:this.gl.NEAREST,magFilter:this.gl.NEAREST,flipY:!1,width:e})}updateUniforms(){this.skeleton.joints.forEach((e,r)=>{ms.multiply(e.worldMatrix,e.bindInverse),this.boneMatrices.set(ms,r*16)}),this.boneTexture.needsUpdate=!0,this.program.uniforms.boneTexture.value=this.boneTexture,this.program.uniforms.boneTextureSize.value=this.boneTextureSize}draw({camera:e}={}){this.program.uniforms.boneTexture||Object.assign(this.program.uniforms,{boneTexture:{value:this.boneTexture},boneTextureSize:{value:this.boneTextureSize}}),this.updateUniforms();const r=this.worldMatrix;this.worldMatrix=Ha,super.draw({camera:e}),this.worldMatrix=r}}class ka extends nt{constructor(...e){super(...e),this.frustumCulled=!1,this.isInstancedMesh=!0}addFrustumCull(){this.instanceTransforms=null,this.instanceLightmapScaleOffset=null,this.totalInstanceCount=0,this.frustumCullFunction=null,this.instanceRenderList=null,this.geometry.attributes.instanceMatrix||console.error(`mesh ${this.name?`"${this.name}" `:""}missing instanceMatrix attribute; unable to frustum cull`);const e=this.geometry.attributes.instanceMatrix.data;this.instanceTransforms=[];for(let r=0,n=0;r<e.length;r+=16,n++){const s=new gt;s.index=n,s.matrix.fromArray(e,r),s.decompose(),this.instanceTransforms.push(s),s.setParent(this.parent)}if(this.totalInstanceCount=this.instanceTransforms.length,this.geometry.attributes.lightmapScaleOffset){const r=this.geometry.attributes.lightmapScaleOffset.data;for(let n=0,s=0;n<r.length;n+=4,s++)this.instanceTransforms[s].lightmapData=new ba().fromArray(r,n)}this.frustumCullFunction=({camera:r})=>{this.instanceRenderList=[],this.instanceTransforms.forEach(n=>{r.frustumIntersectsMesh(this,n.worldMatrix)&&this.instanceRenderList.push(n)}),this.instanceRenderList.forEach((n,s)=>{n.matrix.toArray(this.geometry.attributes.instanceMatrix.data,s*16),n.lightmapData&&(n.lightmapData.toArray(this.geometry.attributes.lightmapScaleOffset.data,s*4),this.geometry.attributes.lightmapScaleOffset.needsUpdate=!0)}),this.geometry.instancedCount=this.instanceRenderList.length,this.geometry.attributes.instanceMatrix.needsUpdate=!0},this.onBeforeRender(this.frustumCullFunction)}removeFrustumCull(){this.offBeforeRender(this.frustumCullFunction),this.geometry.instancedCount=this.totalInstanceCount,this.instanceTransforms.forEach((e,r)=>{e.matrix.toArray(this.geometry.attributes.instanceMatrix.data,r*16),e.lightmapData&&(e.lightmapData.toArray(this.geometry.attributes.lightmapScaleOffset.data,r*4),this.geometry.attributes.lightmapScaleOffset.needsUpdate=!0)}),this.geometry.attributes.instanceMatrix.needsUpdate=!0}}const ps={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array,"image/jpeg":Uint8Array,"image/png":Uint8Array,"image/webp":Uint8Array},Wa={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},gs={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},$a={translation:"position",rotation:"quaternion",scale:"scale"};class vs{static setDracoManager(e){this.dracoManager=e}static setBasisManager(e){this.basisManager=e}static async load(e,r){const n=r.split("/").slice(0,-1).join("/")+"/",s=await this.parseDesc(r);return this.parse(e,s,n)}static async parse(e,r,n){var x,T;(r.asset===void 0||r.asset.version[0]<2)&&console.warn("Only GLTF >=2.0 supported. Attempting to parse."),(x=r.extensionsRequired)!=null&&x.includes("KHR_draco_mesh_compression")&&!this.dracoManager&&console.warn("KHR_draco_mesh_compression extension required but no manager supplied. Use .setDracoManager()"),(T=r.extensionsRequired)!=null&&T.includes("KHR_texture_basisu")&&!this.basisManager&&console.warn("KHR_texture_basisu extension required but no manager supplied. Use .setBasisManager()");const s=await this.loadBuffers(r,n);e.renderer.bindVertexArray(null);const i=this.parseBufferViews(e,r,s),l=await this.parseImages(e,r,n,i),a=this.parseTextures(e,r,l),c=this.parseMaterials(e,r,a),f=this.parseSkins(e,r,i),p=await this.parseMeshes(e,r,i,c,f),[g,u]=this.parseNodes(e,r,p,f,l);this.populateSkins(f,g);const v=this.parseAnimations(e,r,g,i),M=this.parseScenes(r,g),d=M[r.scene],y=this.parseLights(e,r,g,M);for(let P=g.length;P>=0;P--)g[P]||g.splice(P,1);return{json:r,buffers:s,bufferViews:i,cameras:u,images:l,textures:a,materials:c,meshes:p,nodes:g,lights:y,animations:v,scenes:M,scene:d}}static parseDesc(e){return fetch(e,{mode:"cors"}).then(r=>r.arrayBuffer()).then(r=>{const n=new TextDecoder;return n.decode(new Uint8Array(r,0,4))==="glTF"?this.unpackGLB(r):JSON.parse(n.decode(r))})}static unpackGLB(e){const r=new Uint32Array(e,0,3);if(r[0]!==1179937895)throw new Error("Invalid glTF asset.");if(r[1]!==2)throw new Error(`Unsupported glTF binary version, "${r[1]}".`);const n=new Uint32Array(e,12,2),s=20,i=n[0];if(n[1]!==1313821514)throw new Error("Unexpected GLB layout.");const l=new TextDecoder().decode(e.slice(s,s+i)),a=JSON.parse(l);if(s+i===e.byteLength)return a;const c=new Uint32Array(e,s+i,2);if(c[1]!==5130562)throw new Error("Unexpected GLB layout.");const f=s+i+8,p=c[0],g=e.slice(f,f+p);return a.buffers[0].binary=g,a}static resolveURI(e,r){return typeof e!="string"||e===""?"":(/^https?:\/\//i.test(r)&&/^\//.test(e)&&(r=r.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(e)||/^data:.*,.*$/i.test(e)||/^blob:.*$/i.test(e)?e:r+e)}static loadBuffers(e,r){return e.buffers?Promise.all(e.buffers.map(n=>{if(n.binary)return n.binary;const s=this.resolveURI(n.uri,r);return fetch(s,{mode:"cors"}).then(i=>i.arrayBuffer())})):null}static parseBufferViews(e,r,n){if(!r.bufferViews)return null;const s=r.bufferViews;return r.meshes&&r.meshes.forEach(({primitives:i})=>{i.forEach(({attributes:l,indices:a,extensions:c})=>{for(const f in l){const p=r.accessors[l[f]];p.bufferView===void 0&&c&&c.KHR_draco_mesh_compression&&(p.bufferView=c.KHR_draco_mesh_compression.bufferView,s[p.bufferView].isDraco=!0),s[p.bufferView].isAttribute=!0}if(a!==void 0){const f=r.accessors[a];f.bufferView===void 0&&c&&c.KHR_draco_mesh_compression&&(f.bufferView=c.KHR_draco_mesh_compression.bufferView,s[f.bufferView].isDraco=!0),s[f.bufferView].isAttribute=!0,s[f.bufferView].target=e.ELEMENT_ARRAY_BUFFER}})}),r.accessors.forEach(({bufferView:i,componentType:l})=>{i!==void 0&&(s[i].componentType=l)}),r.images&&r.images.forEach(({uri:i,bufferView:l,mimeType:a})=>{l!==void 0&&(s[l].mimeType=a)}),s.forEach(({buffer:i,byteOffset:l=0,byteLength:a,byteStride:c,target:f=e.ARRAY_BUFFER,name:p,extensions:g,extras:u,componentType:v,mimeType:M,isAttribute:d,isDraco:y},x)=>{if(s[x].data=n[i].slice(l,l+a),!d||y)return;const T=e.createBuffer();e.bindBuffer(f,T),e.renderer.state.boundBuffer=T,e.bufferData(f,s[x].data,e.STATIC_DRAW),s[x].buffer=T}),s}static parseImages(e,r,n,s){return r.images?Promise.all(r.images.map(async({uri:i,bufferView:l,mimeType:a,name:c})=>{if(a==="image/ktx2"){const{data:p}=s[l];return await this.basisManager.parseTexture(p)}const f=new Image;if(f.name=c,i)f.src=this.resolveURI(i,n);else if(l!==void 0){const{data:p}=s[l],g=new Blob([p],{type:a});f.src=URL.createObjectURL(g)}return f.ready=new Promise(p=>{f.onload=()=>p()}),f})):null}static parseTextures(e,r,n){return r.textures?r.textures.map(s=>this.createTexture(e,r,n,s)):null}static createTexture(e,r,n,{sampler:s,source:i,name:l,extensions:a,extras:c}){i===void 0&&a&&(a.EXT_texture_webp&&(i=a.EXT_texture_webp.source),a.KHR_texture_basisu&&(i=a.KHR_texture_basisu.source));const f=n[i];if(f.texture)return f.texture;const p={flipY:!1,wrapS:e.REPEAT,wrapT:e.REPEAT},g=s!==void 0?r.samplers[s]:null;if(g&&["magFilter","minFilter","wrapS","wrapT"].forEach(v=>{g[v]&&(p[v]=g[v])}),f.isBasis){p.image=f,p.internalFormat=f.internalFormat,f.isCompressedTexture&&(p.generateMipmaps=!1,f.length>1&&(this.minFilter=e.NEAREST_MIPMAP_LINEAR));const v=new Qe(e,p);return v.name=l,f.texture=v,v}const u=new Qe(e,p);return u.name=l,f.texture=u,f.ready.then(()=>{u.image=f}),u}static parseMaterials(e,r,n){return r.materials?r.materials.map(({name:s,extensions:i,extras:l,pbrMetallicRoughness:a={},normalTexture:c,occlusionTexture:f,emissiveTexture:p,emissiveFactor:g=[0,0,0],alphaMode:u="OPAQUE",alphaCutoff:v=.5,doubleSided:M=!1})=>{const{baseColorFactor:d=[1,1,1,1],baseColorTexture:y,metallicFactor:x=1,roughnessFactor:T=1,metallicRoughnessTexture:P}=a;return y&&(y.texture=n[y.index]),c&&(c.texture=n[c.index]),P&&(P.texture=n[P.index]),f&&(f.texture=n[f.index]),p&&(p.texture=n[p.index]),{name:s,extensions:i,extras:l,baseColorFactor:d,baseColorTexture:y,metallicFactor:x,roughnessFactor:T,metallicRoughnessTexture:P,normalTexture:c,occlusionTexture:f,emissiveTexture:p,emissiveFactor:g,alphaMode:u,alphaCutoff:v,doubleSided:M}}):null}static parseSkins(e,r,n){return r.skins?r.skins.map(({inverseBindMatrices:s,skeleton:i,joints:l})=>({inverseBindMatrices:this.parseAccessor(s,r,n),skeleton:i,joints:l})):null}static parseMeshes(e,r,n,s,i){return r.meshes?Promise.all(r.meshes.map(async({primitives:l,weights:a,name:c,extensions:f,extras:p={}},g)=>{let u=0,v=[],M=!1;return r.nodes&&r.nodes.forEach(({mesh:y,skin:x,extras:T})=>{y===g&&(u++,x!==void 0&&v.push(x),T&&T.lightmap_scale_offset&&(M=!0))}),!!v.length?(l=await Promise.all(v.map(async y=>(await this.parsePrimitives(e,l,r,n,s,1,M)).map(({geometry:x,program:T,mode:P})=>{const L=new Rt(e,{skeleton:i[y],geometry:x,program:T,mode:P});return L.name=c,L.extras=p,f&&(L.extensions=f),L.frustumCulled=!1,L}))),l.instanceCount=0,l.numInstances=u):l=(await this.parsePrimitives(e,l,r,n,s,u,M)).map(({geometry:y,program:x,mode:T})=>{const P=y.attributes.instanceMatrix?ka:nt,L=new P(e,{geometry:y,program:x,mode:T});return L.name=c,L.extras=p,f&&(L.extensions=f),L.numInstances=u,L}),{primitives:l,weights:a,name:c}})):null}static parsePrimitives(e,r,n,s,i,l,a){return Promise.all(r.map(async({attributes:c,indices:f,material:p,mode:g=4,targets:u,extensions:v,extras:M})=>{const d=new Na(e);p!==void 0&&(d.gltfMaterial=i[p]);const y=new ct(e);if(M&&(y.extras=M),v&&(y.extensions=v),v&&v.KHR_draco_mesh_compression){const x=v.KHR_draco_mesh_compression.bufferView,T=v.KHR_draco_mesh_compression.attributes,P={},L={},_={},o={};for(const w in c){const E=n.accessors[c[w]],B=gs[w];P[B]=T[w],L[B]=E.componentType,_[B]=ps[E.componentType].name,o[B]=E.normalized===!0}const{data:h}=s[x],m=await this.dracoManager.decodeGeometry(h,{attributeIds:P,attributeTypes:_});for(let w=0;w<m.attributes.length;w++){const E=m.attributes[w],B=E.name,W=E.array,N=E.itemSize,I=L[B],D=o[B],K=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,K),e.renderer.state.boundBuffer=K,e.bufferData(e.ARRAY_BUFFER,W,e.STATIC_DRAW),y.addAttribute(B,{data:W,size:N,type:I,normalized:D,buffer:K})}if(m.index){const w=m.index.array,E=m.index.itemSize,B=e.createBuffer();e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,B),e.renderer.state.boundBuffer=B,e.bufferData(e.ELEMENT_ARRAY_BUFFER,w,e.STATIC_DRAW),y.addAttribute("index",{data:w,size:E,type:5125,normalized:!1,buffer:B})}}else{for(const x in c)y.addAttribute(gs[x],this.parseAccessor(c[x],n,s));f!==void 0&&y.addAttribute("index",this.parseAccessor(f,n,s))}return l>1&&y.addAttribute("instanceMatrix",{instanced:1,size:16,data:new Float32Array(l*16)}),a&&y.addAttribute("lightmapScaleOffset",{instanced:1,size:4,data:new Float32Array(l*4)}),{geometry:y,program:d,mode:g}}))}static parseAccessor(e,r,n){const{bufferView:s,byteOffset:i=0,componentType:l,normalized:a=!1,count:c,type:f,min:p,max:g,sparse:u}=r.accessors[e],{data:v,buffer:M,byteOffset:d=0,byteStride:y=0,target:x}=n[s],T=Wa[f],P=ps[l],L=P.BYTES_PER_ELEMENT,_=y/L,o=!!y&&_!==T;let h;if(o){const m=new P(v,i);h=new P(c*T);for(let w=0;w<c;w++){const E=_*w,B=E+T;h.set(m.slice(E,B),w*T)}}else h=new P(v,i,c*T);return{data:h,size:T,type:l,normalized:a,buffer:M,stride:y,offset:i,count:c,min:p,max:g}}static parseNodes(e,r,n,s,i){if(!r.nodes)return null;const l=[],a=r.nodes.map(({camera:c,children:f,skin:p,matrix:g,mesh:u,rotation:v,scale:M,translation:d,weights:y,name:x,extensions:T,extras:P})=>{const L=c!==void 0,_=L?new Tn(e):new gt;if(L){const E=r.cameras[c];if(E.type==="perspective"){const{yfov:B,znear:W,zfar:N}=E.perspective;_.perspective({fov:B*(180/Math.PI),near:W,far:N})}else{const{xmag:B,ymag:W,znear:N,zfar:I}=E.orthographic;_.orthographic({near:N,far:I,left:-B,right:B,top:-W,bottom:W})}l.push(_)}x&&(_.name=x),P&&(_.extras=P),T&&(_.extensions=T),P&&P.lightmapTexture!==void 0&&(P.lightmapTexture.texture=this.createTexture(e,r,i,{source:P.lightmapTexture.index})),g?(_.matrix.copy(g),_.decompose()):(v&&_.quaternion.copy(v),M&&_.scale.copy(M),d&&_.position.copy(d),_.updateMatrix());let o=!1,h=!0,m=!1;if(u!==void 0&&(p!==void 0?(n[u].primitives[n[u].primitives.instanceCount].forEach(E=>{P&&Object.assign(E.extras,P),E.setParent(_)}),n[u].primitives.instanceCount++,n[u].primitives.instanceCount===n[u].primitives.numInstances&&(delete n[u].primitives.numInstances,delete n[u].primitives.instanceCount)):n[u].primitives.forEach(E=>{P&&Object.assign(E.extras,P),E.geometry.isInstanced&&(o=!0,E.instanceCount?h=!1:E.instanceCount=0,E.geometry.attributes.instanceMatrix&&(m=!0,_.matrix.toArray(E.geometry.attributes.instanceMatrix.data,E.instanceCount*16)),E.geometry.attributes.lightmapScaleOffset&&E.geometry.attributes.lightmapScaleOffset.data.set(P.lightmap_scale_offset,E.instanceCount*4),E.instanceCount++,E.instanceCount===E.numInstances&&(delete E.numInstances,delete E.instanceCount,E.geometry.attributes.instanceMatrix&&(E.geometry.attributes.instanceMatrix.needsUpdate=!0),E.geometry.attributes.lightmapScaleOffset&&(E.geometry.attributes.lightmapScaleOffset.needsUpdate=!0))),o?h&&E.setParent(_):E.setParent(_)})),m){if(!h)return null;_.matrix.identity(),_.decompose()}return _});return r.nodes.forEach(({children:c=[]},f)=>{c.forEach(p=>{a[p]&&a[p].setParent(a[f])})}),n.forEach(({primitives:c},f)=>{c.forEach((p,g)=>{p.isInstancedMesh&&p.addFrustumCull()})}),[a,l]}static populateSkins(e,r){e&&e.forEach(n=>{n.joints=n.joints.map((s,i)=>{const l=r[s];return l.skin=n,l.bindInverse=new St(...n.inverseBindMatrices.data.slice(i*16,(i+1)*16)),l}),n.skeleton&&(n.skeleton=r[n.skeleton])})}static parseAnimations(e,r,n,s){return r.animations?r.animations.map(({channels:i,samplers:l,name:a},c)=>{const f=i.map(({sampler:p,target:g})=>{const{input:u,interpolation:v="LINEAR",output:M}=l[p],{node:d,path:y}=g,x=n[d],T=$a[y],P=this.parseAccessor(u,r,s).data,L=this.parseAccessor(M,r,s).data;return x.animations||(x.animations=[]),x.animations.includes(c)||x.animations.push(c),{node:x,transform:T,interpolation:v,times:P,values:L}});return{name:a,animation:new Va(f)}}):null}static parseScenes(e,r){return e.scenes?e.scenes.map(({nodes:n=[],name:s,extensions:i,extras:l})=>{const a=n.reduce((c,f)=>(r[f]&&c.push(r[f]),c),[]);return a.extras=l,a}):null}static parseLights(e,r,n,s){var a,c;const i={directional:[],point:[],spot:[]};s.forEach(f=>f.forEach(p=>p.updateMatrixWorld()));const l=((c=(a=r.extensions)==null?void 0:a.KHR_lights_punctual)==null?void 0:c.lights)||[];return n.forEach(f=>{var v;if(!((v=f==null?void 0:f.extensions)!=null&&v.KHR_lights_punctual))return;const p=f.extensions.KHR_lights_punctual.light,g=l[p],u={name:g.name||"",color:{value:new Ce().set(g.color||1)}};switch(g.intensity!==void 0&&u.color.value.multiply(g.intensity),g.type){case"directional":u.direction={value:new Ce(0,0,1).transformDirection(f.worldMatrix)};break;case"point":u.position={value:new Ce().applyMatrix4(f.worldMatrix)},u.distance={value:g.range},u.decay={value:2};break;case"spot":Object.assign(u,g);break}i[g.type].push(u)}),i}}const Xa={fetch:Pi,getBuffer:Bi,getBlob:Li,putBuffer:Ii,putLocalBuffer:Ui,hasLocalBuffer:Oi,getLocalName:Ni,getPlayer:Di,removePlayers:Ri},Xe=()=>{const t=new Float32Array(16);return t[0]=t[5]=t[10]=t[15]=1,t},At=(t,e,r)=>{for(let n=0;n<4;n++){const s=r[n*4],i=r[n*4+1],l=r[n*4+2],a=r[n*4+3];t[n*4]=e[0]*s+e[4]*i+e[8]*l+e[12]*a,t[n*4+1]=e[1]*s+e[5]*i+e[9]*l+e[13]*a,t[n*4+2]=e[2]*s+e[6]*i+e[10]*l+e[14]*a,t[n*4+3]=e[3]*s+e[7]*i+e[11]*l+e[15]*a}return t},Lt=t=>{const e=t[0],r=t[1],n=t[2],s=t[4],i=t[5],l=t[6],a=t[8],c=t[9],f=t[10],p=e*(i*f-l*c)-s*(r*f-n*c)+a*(r*l-n*i),g=p===0?0:1/p,u=new Float32Array(16);u[0]=(i*f-l*c)*g,u[1]=(n*c-r*f)*g,u[2]=(r*l-n*i)*g,u[4]=(l*a-s*f)*g,u[5]=(e*f-n*a)*g,u[6]=(n*s-e*l)*g,u[8]=(s*c-i*a)*g,u[9]=(r*a-e*c)*g,u[10]=(e*i-r*s)*g;const v=t[12],M=t[13],d=t[14];return u[12]=-(u[0]*v+u[4]*M+u[8]*d),u[13]=-(u[1]*v+u[5]*M+u[9]*d),u[14]=-(u[2]*v+u[6]*M+u[10]*d),u[15]=1,u},Or=t=>[Math.hypot(t[0],t[1],t[2]),Math.hypot(t[4],t[5],t[6]),Math.hypot(t[8],t[9],t[10])],ai=(t,e,r,n,s)=>{const[i,l,a]=Or(t),c=Math.hypot(e,r,n,s)||1,f=e/c,p=r/c,g=n/c,u=s/c,v=f*f,M=f*p,d=f*g,y=f*u,x=p*p,T=p*g,P=p*u,L=g*g,_=g*u;t[0]=(1-2*(x+L))*i,t[1]=2*(M+_)*i,t[2]=2*(d-P)*i,t[4]=2*(M-_)*l,t[5]=(1-2*(v+L))*l,t[6]=2*(T+y)*l,t[8]=2*(d+P)*a,t[9]=2*(T-y)*a,t[10]=(1-2*(v+x))*a},Yt=Math.PI/180,ja=(t,e,r,n,s)=>{const[i,l,a]=Or(t),c=e*Yt,f=r*Yt,p=n*Yt,g=Math.cos(c),u=Math.sin(c),v=Math.cos(f),M=Math.sin(f),d=Math.cos(p),y=Math.sin(p);let x=1,T=0,P=0,L=0,_=1,o=0,h=0,m=0,w=1;switch(s){case 0:x=v*d,T=-v*y,P=M,L=u*M*d+g*y,_=-u*M*y+g*d,o=-u*v,h=-g*M*d+u*y,m=g*M*y+u*d,w=g*v;break;case 1:x=v*d+M*u*y,T=-v*y+M*u*d,P=M*g,L=g*y,_=g*d,o=-u,h=-M*d+v*u*y,m=M*y+v*u*d,w=v*g;break;case 2:x=v*d-M*u*y,T=-g*y,P=M*d+v*u*y,L=v*y+M*u*d,_=g*d,o=M*y-v*u*d,h=-M*g,m=u,w=v*g;break;case 3:x=v*d,T=u*M*d-g*y,P=g*M*d+u*y,L=v*y,_=u*M*y+g*d,o=g*M*y-u*d,h=-M,m=u*v,w=g*v;break;case 4:x=v*d,T=-y,P=M*d,L=u*M+g*v*y,_=g*d,o=-v*u+g*M*y,h=-g*M+u*v*y,m=u*d,w=g*v+u*M*y;break;case 5:x=v*d,T=-v*y,P=M,L=g*y+u*M*d,_=g*d-u*M*y,o=-u*v,h=u*y-g*M*d,m=u*d+g*M*y,w=g*v;break}t[0]=x*i,t[1]=L*i,t[2]=h*i,t[4]=T*l,t[5]=_*l,t[6]=m*l,t[8]=P*a,t[9]=o*a,t[10]=w*a},li=(t,e,r,n)=>{const[s,i,l]=Or(t);if(s===0||i===0||l===0){t[0]=e,t[1]=0,t[2]=0,t[4]=0,t[5]=r,t[6]=0,t[8]=0,t[9]=0,t[10]=n;return}const a=e/s,c=r/i,f=n/l;t[0]*=a,t[1]*=a,t[2]*=a,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=f,t[9]*=f,t[10]*=f},ys=t=>{const[e,r,n]=Or(t);if(e===0||r===0||n===0)return[0,0,0];const s=t[0]/e,i=t[1]/e,l=t[2]/e;t[4]/r;const a=t[5]/r,c=t[8]/n,f=t[9]/n,p=t[10]/n,g=Math.asin(-Math.min(1,Math.max(-1,f)));let u,v;return Math.abs(f)<.9999?(u=Math.atan2(c,p),v=Math.atan2(i,a)):(u=Math.atan2(-l,s),v=0),[g/Yt,u/Yt,v/Yt]},ci=(t,e,r)=>{const n=Xe();return ai(n,e[0],e[1],e[2],e[3]),li(n,r[0],r[1],r[2]),n[12]=t[0],n[13]=t[1],n[14]=t[2],n},Sn=(t,e,r,n)=>{const s=1/Math.tan(t*Yt/2),i=new Float32Array(16);return i[0]=s/e,i[5]=s,i[10]=(n+r)/(r-n),i[11]=-1,i[14]=2*n*r/(r-n),i},ui=(t,e,r,n)=>{const s=t.matrix;if(s)return[(r+s[8])/s[0],(n+s[9])/s[5]];const i=Math.tan(t.fov*Yt/2);return[r*i*e,n*i]},qa=(t,e,r,n,s,i)=>{const l=new Float32Array(16);return l[0]=2/(e-t),l[5]=2/(n-r),l[10]=-2/(i-s),l[12]=-(e+t)/(e-t),l[13]=-(n+r)/(n-r),l[14]=-(i+s)/(i-s),l[15]=1,l},xs=(t,e,r,n)=>{let s=-1/0,i=1/0;for(let l=0;l<3;l++){if(n[l]===0)continue;const a=(t[l]-e[l]-r[l])/n[l],c=(t[l]+e[l]-r[l])/n[l];s=Math.max(s,Math.min(a,c)),i=Math.min(i,Math.max(a,c))}return s<0||i<s?-1:s},Ya=(t,e,r,n)=>{const s=r[0]-t[0],i=r[1]-t[1],l=r[2]-t[2],a=n[0]**2+n[1]**2+n[2]**2,c=2*(s*n[0]+i*n[1]+l*n[2]),f=s*s+i*i+l*l-e*e,p=c*c-4*a*f;if(p<0)return-1;const g=Math.sqrt(p),u=(-c-g)/(2*a),v=(-c+g)/(2*a);return u>0&&v>0?Math.min(u,v):u>0?u:v>0?v:-1},Pt=(t,e,r,n,s,i)=>(t[0]=e[0]*r+e[4]*n+e[8]*s+e[12]*i,t[1]=e[1]*r+e[5]*n+e[9]*s+e[13]*i,t[2]=e[2]*r+e[6]*n+e[10]*s+e[14]*i,t),Ka=(t,e)=>{let r=e[0]-t[0],n=e[1]-t[1],s=e[2]-t[2],i=Math.hypot(r,n,s);i<1e-9&&(r=0,n=0,s=-1,i=1),r/=i,n/=i,s/=i;let l=0,a=1,c=0;Math.abs(n)>.999&&(l=0,a=0,c=-1);let f=n*c-s*a,p=s*l-r*c,g=r*a-n*l;const u=Math.hypot(f,p,g)||1;f/=u,p/=u,g/=u;const v=p*s-g*n,M=g*r-f*s,d=f*n-p*r,y=new Float32Array(16);return y[0]=f,y[4]=p,y[8]=g,y[1]=v,y[5]=M,y[9]=d,y[2]=-r,y[6]=-n,y[10]=-s,y[12]=-(f*t[0]+p*t[1]+g*t[2]),y[13]=-(v*t[0]+M*t[1]+d*t[2]),y[14]=r*t[0]+n*t[1]+s*t[2],y[15]=1,y},Qa=1/(1.2*Math.pow(2,Math.log2(256/(1/125)))),hi=`
36
- vec3 acesFilmicSrgb(vec3 x) {
37
- const float A = 2.51; const float B = 0.03; const float C = 2.43; const float D = 0.59; const float E = 0.14;
38
- vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
39
- return pow(t, vec3(1.0 / 2.2));
40
- }
41
- `,br=`
42
- uniform float uTonemap;
43
- ${hi}
44
- vec3 tonemap(vec3 x) {
45
- if (uTonemap < 0.5) return x;
46
- return acesFilmicSrgb(x);
47
- }
48
- `,fi=`
49
- vec3 Inverse_Tonemap_Filmic(const vec3 x) {
50
- return (0.03 - 0.59 * x - sqrt(0.0009 + 1.3702 * x - 1.0127 * x * x)) / (-5.02 + 4.86 * x);
51
- }
52
- vec3 inverseTonemapSRGB(vec3 color) {
53
- color = clamp(color, 0.0, 1.0);
54
- return Inverse_Tonemap_Filmic(pow(color, vec3(2.2)));
55
- }
56
- `,Za=`#version 300 es
57
- precision highp float;
58
- in vec3 position;
59
- in vec3 normal;
60
- in vec2 uv;
61
- uniform mat4 modelMatrix;
62
- uniform mat4 modelViewMatrix;
63
- uniform mat4 projectionMatrix;
64
- uniform mat3 normalMatrix;
65
- out vec3 vWorldPos;
66
- out vec3 vNormal;
67
- out vec2 vUv;
68
- `,di=`
69
- in vec4 skinIndex;
70
- in vec4 skinWeight;
71
- uniform sampler2D boneTexture;
72
- uniform int boneTextureSize;
73
-
74
- mat4 getBoneMatrix(const in float i) {
75
- float j = i * 4.0;
76
- float x = mod(j, float(boneTextureSize));
77
- float y = floor(j / float(boneTextureSize));
78
- float dx = 1.0 / float(boneTextureSize);
79
- float dy = 1.0 / float(boneTextureSize);
80
- y = dy * (y + 0.5);
81
- vec4 v1 = texture(boneTexture, vec2(dx * (x + 0.5), y));
82
- vec4 v2 = texture(boneTexture, vec2(dx * (x + 1.5), y));
83
- vec4 v3 = texture(boneTexture, vec2(dx * (x + 2.5), y));
84
- vec4 v4 = texture(boneTexture, vec2(dx * (x + 3.5), y));
85
- return mat4(v1, v2, v3, v4);
86
- }
87
-
88
- mat4 getSkinMatrix() {
89
- mat4 boneMatX = getBoneMatrix(skinIndex.x);
90
- mat4 boneMatY = getBoneMatrix(skinIndex.y);
91
- mat4 boneMatZ = getBoneMatrix(skinIndex.z);
92
- mat4 boneMatW = getBoneMatrix(skinIndex.w);
93
- return boneMatX * skinWeight.x + boneMatY * skinWeight.y + boneMatZ * skinWeight.z + boneMatW * skinWeight.w;
94
- }
95
- `,Ja=`
96
- uniform sampler2D uMorphTex;
97
- uniform int uMorphCount; // active target count (capped by glb.ts)
98
- uniform int uMorphVertexCount;
99
- uniform int uMorphTexWidth;
100
- uniform float uMorphWeights[8];
101
-
102
- vec3 morphFetch(int idx) {
103
- return texelFetch(uMorphTex, ivec2(idx % uMorphTexWidth, idx / uMorphTexWidth), 0).rgb;
104
- }
105
- `,mi=t=>`${Za}
106
- #ifdef INSTANCED
107
- in mat4 instanceMatrix;
108
- uniform mat4 viewMatrix;
109
- #endif
110
- ${t.includes("HAS_SKIN")?di:""}
111
- ${t.includes("HAS_MORPH")?Ja:""}
112
- ${t.includes("HAS_COLOR")?`in vec4 color;
113
- out vec4 vColor;`:""}
114
- uniform mat4 shadowMatrix;
115
- out vec4 vShadowCoord;
116
-
117
- void main() {
118
- vec4 pos = vec4(position, 1.0);
119
- vec3 nrm = normal;
120
- ${t.includes("HAS_MORPH")?`
121
- for (int t = 0; t < uMorphCount; t++) {
122
- if (uMorphWeights[t] != 0.0) {
123
- pos.xyz += uMorphWeights[t] * morphFetch(t * uMorphVertexCount + gl_VertexID);
124
- ${t.includes("HAS_MORPH_NORMALS")?"nrm += uMorphWeights[t] * morphFetch((uMorphCount + t) * uMorphVertexCount + gl_VertexID);":""}
125
- }
126
- }
127
- `:""}
128
- ${t.includes("HAS_SKIN")?`
129
- mat4 skinMatrix = getSkinMatrix();
130
- pos = skinMatrix * pos;
131
- nrm = mat3(skinMatrix) * nrm;
132
- `:""}
133
- ${t.includes("HAS_COLOR")?"vColor = color;":""}
134
- #ifdef INSTANCED
135
- mat4 model = instanceMatrix;
136
- #else
137
- mat4 model = modelMatrix;
138
- #endif
139
- vec4 worldPos = model * pos;
140
- vWorldPos = worldPos.xyz;
141
- vNormal = normalize(mat3(model) * nrm);
142
- vUv = uv;
143
- vShadowCoord = shadowMatrix * worldPos;
144
- #ifdef INSTANCED
145
- gl_Position = projectionMatrix * viewMatrix * worldPos;
146
- #else
147
- gl_Position = projectionMatrix * modelViewMatrix * pos;
148
- #endif
149
- }
150
- `,nr=8,Ir=`
151
- #define MAX_PUNCTUAL ${nr}
152
- uniform int punctualCount;
153
- uniform vec4 punctualPos[MAX_PUNCTUAL]; // xyz = world position, w = 1 / range²
154
- uniform vec4 punctualColor[MAX_PUNCTUAL]; // rgb = linear colour x candela, w = cone scale (0 = a point light)
155
- uniform vec4 punctualDir[MAX_PUNCTUAL]; // xyz = where the light travels (unit), w = cone offset (1 = a point light)
156
- uniform vec3 sunDirection;
157
- uniform vec4 sunColorIntensity; // rgb = linear color, a = intensity (lux)
158
- uniform float iblLuminance;
159
- uniform vec3 iblSH[9];
160
- uniform samplerCube envMap;
161
- uniform float envMapMaxLod;
162
- uniform sampler2D shadowMap;
163
- uniform float shadowEnabled;
164
- uniform float shadowMapSize;
165
- uniform float exposure;
166
- in vec4 vShadowCoord;
167
-
168
- #define PI 3.14159265359
169
-
170
- float D_GGX(float NoH, float a) {
171
- float a2 = a * a;
172
- float f = (NoH * a2 - NoH) * NoH + 1.0;
173
- return a2 / (PI * f * f);
174
- }
175
-
176
- float V_SmithGGXCorrelated(float NoV, float NoL, float a) {
177
- float a2 = a * a;
178
- float GGXL = NoV * sqrt((-NoL * a2 + NoL) * NoL + a2);
179
- float GGXV = NoL * sqrt((-NoV * a2 + NoV) * NoV + a2);
180
- return 0.5 / (GGXV + GGXL + 1e-5);
181
- }
182
-
183
- vec3 F_Schlick(float u, vec3 f0) {
184
- float f = pow(1.0 - u, 5.0);
185
- return f0 + (vec3(1.0) - f0) * f;
186
- }
187
-
188
- vec3 evalSH(vec3 n) {
189
- return max(
190
- iblSH[0]
191
- + iblSH[1] * n.y
192
- + iblSH[2] * n.z
193
- + iblSH[3] * n.x
194
- + iblSH[4] * (n.y * n.x)
195
- + iblSH[5] * (n.y * n.z)
196
- + iblSH[6] * (3.0 * n.z * n.z - 1.0)
197
- + iblSH[7] * (n.z * n.x)
198
- + iblSH[8] * (n.x * n.x - n.y * n.y)
199
- , vec3(0.0));
200
- }
201
-
202
- float sampleShadowPCF() {
203
- if (shadowEnabled < 0.5) return 1.0;
204
- vec3 coord = vShadowCoord.xyz / vShadowCoord.w;
205
- coord = coord * 0.5 + 0.5;
206
- if (coord.x < 0.0 || coord.x > 1.0 || coord.y < 0.0 || coord.y > 1.0 || coord.z > 1.0) return 1.0;
207
- float bias = 0.0018;
208
- float texel = 1.0 / shadowMapSize;
209
- float sum = 0.0;
210
- for (int x = -1; x <= 1; x++) {
211
- for (int y = -1; y <= 1; y++) {
212
- float depth = texture(shadowMap, coord.xy + vec2(float(x), float(y)) * texel).r;
213
- sum += (coord.z - bias) > depth ? 0.0 : 1.0;
214
- }
215
- }
216
- return sum / 9.0;
217
- }
218
-
219
- // Lambert diffuse + the GGX specular lobe for one light direction l (unit, TO the light).
220
- vec3 surfaceBRDF(vec3 n, vec3 v, vec3 l, float NoV, float NoL, float a, vec3 diffuseColor, vec3 f0) {
221
- vec3 h = normalize(v + l);
222
- float NoH = clamp(dot(n, h), 0.0, 1.0);
223
- float LoH = clamp(dot(l, h), 0.0, 1.0);
224
- vec3 Fr = D_GGX(NoH, a) * V_SmithGGXCorrelated(NoV, NoL, a) * F_Schlick(LoH, f0);
225
- return diffuseColor * (1.0 / PI) + Fr;
226
- }
227
-
228
- // diffuseColor: linear albedo (already metallic-adjusted); f0: specular reflectance at normal.
229
- vec3 shadePBR(vec3 n, vec3 v, vec3 diffuseColor, vec3 f0, float perceptualRoughness, float occlusion) {
230
- float roughness = clamp(perceptualRoughness, 0.045, 1.0);
231
- float a = roughness * roughness;
232
- float NoV = abs(dot(n, v)) + 1e-5;
233
-
234
- vec3 color = vec3(0.0);
235
-
236
- // --- sun ---
237
- if (sunColorIntensity.a > 0.0) {
238
- vec3 l = normalize(-sunDirection);
239
- float NoL = clamp(dot(n, l), 0.0, 1.0);
240
- if (NoL > 0.0) {
241
- float shadow = sampleShadowPCF();
242
- // "illuminance" model: lux * NoL, pre-exposed
243
- color += surfaceBRDF(n, v, l, NoV, NoL, a, diffuseColor, f0) * sunColorIntensity.rgb * (sunColorIntensity.a * exposure * NoL * shadow);
244
- }
245
- }
246
-
247
- // --- point + spot lights ---
248
- for (int i = 0; i < MAX_PUNCTUAL; i++) {
249
- if (i >= punctualCount) break;
250
- vec3 toLight = punctualPos[i].xyz - vWorldPos;
251
- float d2 = dot(toLight, toLight);
252
- float f = d2 * punctualPos[i].w;
253
- float win = clamp(1.0 - f * f, 0.0, 1.0);
254
- vec3 l = toLight * inversesqrt(max(d2, 1e-8));
255
- float cone = clamp(dot(-punctualDir[i].xyz, l) * punctualColor[i].w + punctualDir[i].w, 0.0, 1.0);
256
- // a punctual light occupies a volume of 1 cm (filament): no division by 0 on its own surface
257
- float attenuation = win * win * cone * cone / max(d2, 1e-4);
258
- float NoL = clamp(dot(n, l), 0.0, 1.0);
259
- if (attenuation <= 0.0 || NoL <= 0.0) continue;
260
- color += surfaceBRDF(n, v, l, NoV, NoL, a, diffuseColor, f0) * punctualColor[i].rgb * (attenuation * exposure * NoL);
261
- }
262
-
263
- // --- IBL ---
264
- if (iblLuminance > 0.0) {
265
- // cmgen's SH coefficients are pre-convolved irradiance — no extra 1/PI (matches Filament).
266
- vec3 irradiance = evalSH(n);
267
- vec3 Fd = diffuseColor * irradiance;
268
-
269
- vec3 r = reflect(-v, n);
270
- float lod = roughness * envMapMaxLod;
271
- vec3 prefiltered = textureLod(envMap, r, lod).rgb;
272
- // Simple DFG approximation (Karis): avoids a DFG LUT.
273
- vec3 specular = prefiltered * (f0 * (1.0 - roughness) + roughness * 0.25 * f0 + 0.05 * (1.0 - roughness));
274
- color += (Fd + specular) * (iblLuminance * exposure * occlusion);
275
- }
276
-
277
- return color;
278
- }
279
- ${br}`,el=`#version 300 es
280
- precision highp float;
281
- in vec3 vWorldPos;
282
- in vec3 vNormal;
283
- in vec2 vUv;
284
- uniform vec3 cameraPosition;
285
- uniform vec3 baseColor; // linear factor over baseColorMap (both default white)
286
- uniform sampler2D baseColorMap;
287
- uniform float roughness;
288
- uniform float metallic;
289
- ${Ir}
290
- out vec4 fragColor;
291
-
292
- void main() {
293
- vec3 albedo = baseColor * texture(baseColorMap, vUv).rgb;
294
- vec3 n = normalize(vNormal);
295
- vec3 v = normalize(cameraPosition - vWorldPos);
296
- if (dot(n, v) < 0.0) n = -n;
297
- vec3 diffuseColor = albedo * (1.0 - metallic);
298
- vec3 f0 = mix(vec3(0.04), albedo, metallic);
299
- vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, 1.0);
300
- fragColor = vec4(tonemap(color), 1.0);
301
- }
302
- `,tl=`#version 300 es
303
- precision highp float;
304
- in vec3 vWorldPos;
305
- in vec3 vNormal;
306
- in vec2 vUv;
307
- uniform vec3 cameraPosition;
308
- uniform sampler2D control;
309
- uniform sampler2D albedo0;
310
- uniform sampler2D albedo1;
311
- uniform sampler2D albedo2;
312
- uniform sampler2D albedo3;
313
- uniform sampler2D normals01;
314
- uniform sampler2D normals23;
315
- uniform vec4 tiling;
316
- uniform vec4 roughness;
317
- uniform vec4 normalScale;
318
- uniform vec4 triplanar;
319
- uniform vec2 gridSize;
320
- uniform float cellSize;
321
- uniform vec3 tint;
322
- ${Ir}
323
- out vec4 fragColor;
324
-
325
- vec4 triplanarSample(sampler2D tex, vec3 p, vec3 bw, float s) {
326
- return texture(tex, p.zy / s) * bw.x + texture(tex, p.xz / s) * bw.y + texture(tex, p.xy / s) * bw.z;
327
- }
328
-
329
- void splatLayer(sampler2D alb, sampler2D pack, float slot, float tl, float nscale, float tri, float w,
330
- vec2 uv, vec3 wp, vec3 bw, inout vec3 albedo, inout vec3 nrm) {
331
- if (w <= 0.0) return;
332
- float s = max(tl, 1e-3);
333
- if (tri > 0.5) {
334
- albedo += triplanarSample(alb, wp, bw, s).rgb * w;
335
- nrm += vec3(0.0, 0.0, 1.0) * w;
336
- } else {
337
- vec2 luv = uv / s;
338
- albedo += texture(alb, luv).rgb * w;
339
- if (nscale > 0.0) {
340
- vec4 p = texture(pack, luv);
341
- vec2 xy = (slot > 0.5 ? p.ba : p.rg) * 2.0 - 1.0;
342
- xy *= nscale;
343
- nrm += vec3(xy, sqrt(max(1.0 - dot(xy, xy), 0.0))) * w;
344
- } else {
345
- nrm += vec3(0.0, 0.0, 1.0) * w;
346
- }
347
- }
348
- }
349
-
350
- vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
351
- vec3 pos_dx = dFdx(vWorldPos);
352
- vec3 pos_dy = dFdy(vWorldPos);
353
- vec2 tex_dx = dFdx(vUv);
354
- vec2 tex_dy = dFdy(vUv);
355
- float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
356
- if (abs(det) < 1e-8) return ng;
357
- vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
358
- t = normalize(t - ng * dot(ng, t));
359
- vec3 b = normalize(cross(ng, t)) * sign(det);
360
- return normalize(mat3(t, b, ng) * nTangent);
361
- }
362
-
363
- void main() {
364
- vec2 cuv = (vUv / max(cellSize, 1e-4) + 0.5) / max(gridSize, vec2(1.0));
365
- vec4 w = texture(control, cuv);
366
- float ws = w.r + w.g + w.b + w.a;
367
- w = ws > 1e-4 ? w / ws : vec4(1.0, 0.0, 0.0, 0.0);
368
- vec3 ng = normalize(vNormal);
369
- vec3 bw = abs(ng);
370
- bw = bw / max(bw.x + bw.y + bw.z, 1e-4);
371
- vec3 albedo = vec3(0.0);
372
- vec3 nrm = vec3(0.0);
373
- splatLayer(albedo0, normals01, 0.0, tiling.x, normalScale.x, triplanar.x, w.r, vUv, vWorldPos, bw, albedo, nrm);
374
- splatLayer(albedo1, normals01, 1.0, tiling.y, normalScale.y, triplanar.y, w.g, vUv, vWorldPos, bw, albedo, nrm);
375
- splatLayer(albedo2, normals23, 0.0, tiling.z, normalScale.z, triplanar.z, w.b, vUv, vWorldPos, bw, albedo, nrm);
376
- splatLayer(albedo3, normals23, 1.0, tiling.w, normalScale.w, triplanar.w, w.a, vUv, vWorldPos, bw, albedo, nrm);
377
- vec3 n = applyTangentNormal(normalize(nrm), ng);
378
- vec3 v = normalize(cameraPosition - vWorldPos);
379
- if (dot(ng, v) < 0.0) n = -n;
380
- vec3 diffuseColor = albedo * tint;
381
- vec3 color = shadePBR(n, v, diffuseColor, vec3(0.04), dot(roughness, w), 1.0);
382
- fragColor = vec4(tonemap(color), 1.0);
383
- }
384
- `,rl=`#version 300 es
385
- precision highp float;
386
- in vec3 vWorldPos;
387
- in vec3 vNormal;
388
- in vec2 vUv;
389
- uniform vec4 baseColor; // linear, premultiplied; factor over baseColorMap
390
- uniform sampler2D baseColorMap;
391
- out vec4 fragColor;
392
- ${br}
393
- void main() {
394
- vec4 c = baseColor * texture(baseColorMap, vUv);
395
- fragColor = vec4(tonemap(c.rgb), 1.0);
396
- }
397
- `,nl=`#version 300 es
398
- precision highp float;
399
- in vec3 vWorldPos;
400
- in vec3 vNormal;
401
- in vec2 vUv;
402
- uniform vec4 baseColor; // linear, straight alpha; factor over baseColorMap
403
- uniform sampler2D baseColorMap;
404
- out vec4 fragColor;
405
- ${br}
406
- void main() {
407
- vec4 c = baseColor * texture(baseColorMap, vUv);
408
- fragColor = vec4(tonemap(c.rgb) * c.a, c.a);
409
- }
410
- `,sl=`#version 300 es
411
- precision highp float;
412
- in vec2 vUv;
413
- in vec3 vWorldPos;
414
- in vec3 vNormal;
415
- uniform sampler2D baseColorMap;
416
- out vec4 fragColor;
417
- ${br}
418
- ${fi}
419
- void main() {
420
- vec3 c = texture(baseColorMap, vUv).rgb;
421
- fragColor = vec4(uTonemap > 0.5 ? c : inverseTonemapSRGB(c), 1.0);
422
- }
423
- `,il=`#version 300 es
424
- precision highp float;
425
- in vec3 vWorldPos;
426
- in vec3 vNormal;
427
- in vec2 vUv;
428
- uniform vec4 color; // linear, premultiplied
429
- ${Ir}
430
- out vec4 fragColor;
431
- void main() {
432
- float vis = sampleShadowPCF();
433
- float shadowAmount = 1.0 - vis;
434
- fragColor = vec4(color.rgb * shadowAmount, color.a * shadowAmount);
435
- }
436
- `,_n=t=>mi(t),er=mi(""),ol=t=>`#version 300 es
437
- precision highp float;
438
- ${t}
439
- in vec3 vWorldPos;
440
- in vec3 vNormal;
441
- in vec2 vUv;
442
- #ifdef HAS_COLOR
443
- in vec4 vColor;
444
- #endif
445
- uniform vec3 cameraPosition;
446
- uniform vec4 uBaseColorFactor;
447
- uniform float uMetallic;
448
- uniform float uRoughness;
449
- uniform vec3 uEmissive;
450
- uniform float uAlphaCutoff;
451
- #ifdef HAS_BASECOLOR_MAP
452
- uniform sampler2D uBaseColorMap;
453
- #endif
454
- #ifdef HAS_MR_MAP
455
- uniform sampler2D uMRMap;
456
- #endif
457
- #ifdef HAS_NORMAL_MAP
458
- uniform sampler2D uNormalMap;
459
- #endif
460
- #ifdef HAS_OCCLUSION_MAP
461
- uniform sampler2D uOcclusionMap;
462
- #endif
463
- #ifdef HAS_EMISSIVE_MAP
464
- uniform sampler2D uEmissiveMap;
465
- #endif
466
- ${Ir}
467
- out vec4 fragColor;
468
-
469
- #ifdef HAS_NORMAL_MAP
470
- vec3 getNormal() {
471
- vec3 pos_dx = dFdx(vWorldPos);
472
- vec3 pos_dy = dFdy(vWorldPos);
473
- vec2 tex_dx = dFdx(vUv);
474
- vec2 tex_dy = dFdy(vUv);
475
- float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
476
- if (abs(det) < 1e-8) return normalize(vNormal);
477
- vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
478
- vec3 ng = normalize(vNormal);
479
- t = normalize(t - ng * dot(ng, t));
480
- vec3 b = normalize(cross(ng, t)) * sign(det);
481
- mat3 tbn = mat3(t, b, ng);
482
- vec3 n = texture(uNormalMap, vUv).rgb * 2.0 - 1.0;
483
- return normalize(tbn * n);
484
- }
485
- #endif
486
-
487
- void main() {
488
- vec4 base = uBaseColorFactor;
489
- #ifdef HAS_BASECOLOR_MAP
490
- base *= texture(uBaseColorMap, vUv);
491
- #endif
492
- #ifdef HAS_COLOR
493
- base *= vColor;
494
- #endif
495
- #ifdef ALPHA_MASK
496
- if (base.a < uAlphaCutoff) discard;
497
- #endif
498
-
499
- #ifdef UNLIT
500
- // KHR_materials_unlit: the base colour IS the shaded colour — no lights, no IBL, no exposure
501
- // (Filament's UNLIT shading model does the same, then tone-maps in post like everything else).
502
- #ifdef ALPHA_BLEND
503
- fragColor = vec4(tonemap(base.rgb), base.a);
504
- #else
505
- fragColor = vec4(tonemap(base.rgb), 1.0);
506
- #endif
507
- return;
508
- #endif
509
-
510
- float metallic = uMetallic;
511
- float roughness = uRoughness;
512
- #ifdef HAS_MR_MAP
513
- vec3 mr = texture(uMRMap, vUv).rgb;
514
- roughness *= mr.g;
515
- metallic *= mr.b;
516
- #endif
517
-
518
- float occlusion = 1.0;
519
- #ifdef HAS_OCCLUSION_MAP
520
- occlusion = texture(uOcclusionMap, vUv).r;
521
- #endif
522
-
523
- #ifdef HAS_NORMAL_MAP
524
- vec3 n = getNormal();
525
- #else
526
- vec3 n = normalize(vNormal);
527
- #endif
528
- vec3 v = normalize(cameraPosition - vWorldPos);
529
- #ifdef DOUBLE_SIDED
530
- if (dot(n, v) < 0.0) n = -n;
531
- #endif
532
-
533
- vec3 diffuseColor = base.rgb * (1.0 - metallic);
534
- vec3 f0 = mix(vec3(0.04), base.rgb, metallic);
535
- vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, occlusion);
536
-
537
- vec3 emissive = uEmissive;
538
- #ifdef HAS_EMISSIVE_MAP
539
- emissive *= texture(uEmissiveMap, vUv).rgb;
540
- #endif
541
- color += emissive * iblLuminance * exposure;
542
-
543
- #ifdef ALPHA_BLEND
544
- fragColor = vec4(tonemap(color), base.a);
545
- #else
546
- fragColor = vec4(tonemap(color), 1.0);
547
- #endif
548
- }
549
- `,ws=`#version 300 es
550
- precision highp float;
551
- in vec3 vWorldPos;
552
- in vec3 vNormal;
553
- in vec2 vUv;
554
- uniform vec3 uWireColor;
555
- out vec4 fragColor;
556
- void main() { fragColor = vec4(uWireColor, 1.0); }
557
- `,Rr=(t,e=!1)=>`#version 300 es
558
- precision highp float;
559
- in vec3 position;
560
- ${t?`in vec3 normal;
561
- in vec2 uv;`:""}
562
- ${e?"in mat4 instanceMatrix;":"uniform mat4 modelMatrix;"}
563
- uniform mat4 shadowViewProjection;
564
- ${t?di:""}
565
- void main() {
566
- vec4 pos = vec4(position, 1.0);
567
- ${t?"pos = getSkinMatrix() * pos;":""}
568
- gl_Position = shadowViewProjection * ${e?"instanceMatrix":"modelMatrix"} * pos;
569
- }
570
- `,Pr=`#version 300 es
571
- precision highp float;
572
- out vec4 fragColor;
573
- void main() { fragColor = vec4(1.0); }
574
- `,vr=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),al=t=>{const e=Math.min(1,Math.max(0,t*(2.51*t+.03)/(t*(2.43*t+.59)+.14)));return Math.pow(e,1/2.2)},ll=t=>[vr((t>>>16&255)/255),vr((t>>>8&255)/255),vr((t&255)/255)],cl=t=>[vr((t>>>24&255)/255),vr((t>>>16&255)/255),vr((t>>>8&255)/255),(t&255)/255],pi=`
575
- uniform sampler2D baseColorMap;
576
- uniform vec2 sheetSize; // (cols, rows) of the flipbook sheet, both >= 1 (the SDK primes it)
577
- uniform float emissive;
578
- uniform float additive;
579
- uniform float softness;
580
- uniform float depthFade; // declared so the SDK's write lands somewhere; ignored (no depth buffer)
581
- ${br}
582
- // Integer cell math: a float floor(frame / cols) lands one row early at row starts on the GPU.
583
- vec2 sheetCell(int fi) {
584
- int sx = int(sheetSize.x + 0.5);
585
- return vec2(float(fi - (fi / sx) * sx), float(fi / sx));
586
- }
587
- `,ul=`#version 300 es
588
- precision highp float;
589
- in vec3 position;
590
- in vec4 color;
591
- in vec4 custom;
592
- uniform mat4 modelMatrix;
593
- uniform mat4 viewMatrix;
594
- uniform mat4 projectionMatrix;
595
- uniform float perspScale; // viewportHeightPx / (2 tan(fov/2)): a true world-space diameter
596
- out vec4 vColor;
597
- out vec4 vCustom;
598
- void main() {
599
- vec4 viewPos = viewMatrix * modelMatrix * vec4(position, 1.0);
600
- float z = max(-viewPos.z, 1e-3);
601
- gl_PointSize = custom.x * perspScale / z;
602
- vColor = color;
603
- vCustom = custom;
604
- gl_Position = projectionMatrix * viewPos;
605
- }
606
- `,hl=`#version 300 es
607
- precision highp float;
608
- in vec4 vColor;
609
- in vec4 vCustom;
610
- ${pi}
611
- out vec4 fragColor;
612
- void main() {
613
- vec2 uv = gl_PointCoord.xy;
614
- float rot = vCustom.y;
615
- if (rot != 0.0) {
616
- float co = cos(rot);
617
- float si = sin(rot);
618
- vec2 p = uv - vec2(0.5);
619
- uv = vec2(co * p.x - si * p.y, si * p.x + co * p.y) + vec2(0.5);
620
- if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) discard;
621
- }
622
- int total = int(sheetSize.x + 0.5) * int(sheetSize.y + 0.5);
623
- int fi = int(floor(vCustom.w) + 0.5);
624
- fi = fi - (fi / total) * total;
625
- vec4 tex = texture(baseColorMap, (sheetCell(fi) + uv) / sheetSize);
626
- float radial = 1.0 - smoothstep(0.0, 0.5, length(gl_PointCoord.xy - vec2(0.5)));
627
- float shape = mix(1.0, radial, clamp(softness, 0.0, 1.0));
628
- float alpha = tex.a * vColor.a * vCustom.z * shape;
629
- vec3 rgb = tex.rgb * vColor.rgb * (1.0 + emissive);
630
- fragColor = vec4(tonemap(rgb) * alpha, alpha * (1.0 - clamp(additive, 0.0, 1.0)));
631
- }
632
- `,fl=`#version 300 es
633
- precision highp float;
634
- in vec3 position;
635
- in vec4 color;
636
- in vec4 custom; // size, rotation, opacity, frame
637
- in vec3 aux; // quad: velocity (stretch axis); ribbon: strip tangent — sim space
638
- in vec2 corner; // quad: ±0.5 square; ribbon: (u01 - 0.5, ±0.5 side)
639
- uniform mat4 modelMatrix;
640
- uniform mat4 viewMatrix;
641
- uniform mat4 projectionMatrix;
642
- uniform float mode; // 0 camera billboard, 1 velocity-stretched, 2 ribbon strip
643
- uniform float stretch; // (mode 1) extra length per unit of speed: length = size + stretch · |v|
644
- out vec4 vColor;
645
- out vec4 vCustom;
646
- out vec4 vQuadUv; // xy: in-cell uv, zw: the softness basis
647
- void main() {
648
- vec4 wp = modelMatrix * vec4(position, 1.0);
649
- vec3 a = mat3(modelMatrix) * aux;
650
- // the camera's world axes: rows of the view rotation (= columns of its inverse)
651
- vec3 camX = vec3(viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0]);
652
- vec3 camY = vec3(viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1]);
653
- vec3 camZ = vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]); // toward the camera
654
- vec3 offset;
655
- vec2 suv = corner;
656
- if (mode < 0.5) {
657
- float co = cos(custom.y);
658
- float si = sin(custom.y);
659
- vec2 rc = vec2(co * corner.x - si * corner.y, si * corner.x + co * corner.y);
660
- offset = (camX * rc.x + camY * rc.y) * custom.x;
661
- } else if (mode < 1.5) {
662
- float speed = length(a);
663
- vec3 dir = speed > 1e-4 ? a / speed : camY;
664
- vec3 y = dir - camZ * dot(dir, camZ);
665
- float yl = length(y);
666
- y = yl > 1e-4 ? y / yl : camY;
667
- vec3 x = normalize(cross(y, camZ));
668
- offset = x * corner.x * custom.x + y * corner.y * (custom.x + stretch * speed * yl);
669
- } else {
670
- vec3 x = cross(a, camZ);
671
- float xl = length(x);
672
- x = xl > 1e-4 ? x / xl : camX;
673
- offset = x * corner.y * custom.x;
674
- suv = vec2(0.0, corner.y);
675
- }
676
- wp.xyz += offset;
677
- vColor = color;
678
- vCustom = custom;
679
- vQuadUv = vec4(corner.x + 0.5, 0.5 - corner.y, suv.x, suv.y);
680
- gl_Position = projectionMatrix * viewMatrix * wp;
681
- }
682
- `,dl=`#version 300 es
683
- precision highp float;
684
- in vec4 vColor;
685
- in vec4 vCustom;
686
- in vec4 vQuadUv;
687
- ${pi}
688
- uniform sampler2D emissiveMap;
689
- uniform vec3 emissiveColor;
690
- uniform float frameBlend;
691
- out vec4 fragColor;
692
- void main() {
693
- vec2 uv = vQuadUv.xy;
694
- float total = sheetSize.x * sheetSize.y;
695
- float fidx = mod(vCustom.w, total);
696
- float frame = floor(fidx);
697
- int fi = int(frame + 0.5);
698
- vec2 tuv = (sheetCell(fi) + uv) / sheetSize;
699
- vec4 tex = texture(baseColorMap, tuv);
700
- vec3 em = texture(emissiveMap, tuv).rgb;
701
- if (frameBlend > 0.5) {
702
- int ni = min(fi + 1, int(total + 0.5) - 1);
703
- vec2 tuv2 = (sheetCell(ni) + uv) / sheetSize;
704
- float f = fidx - frame;
705
- tex = mix(tex, texture(baseColorMap, tuv2), f);
706
- em = mix(em, texture(emissiveMap, tuv2).rgb, f);
707
- }
708
- float radial = 1.0 - smoothstep(0.0, 0.5, length(vQuadUv.zw));
709
- float shape = mix(1.0, radial, clamp(softness, 0.0, 1.0));
710
- float alpha = tex.a * vColor.a * vCustom.z * shape;
711
- vec3 rgb = tex.rgb * vColor.rgb * (1.0 + emissive) + em * emissiveColor;
712
- fragColor = vec4(tonemap(rgb) * alpha, alpha * (1.0 - clamp(additive, 0.0, 1.0)));
713
- }
714
- `,ml=2873840728,pl=t=>{const e=new DataView(t);if(e.getUint32(0,!1)!==ml)throw new Error("Not a KTX1 file");const r=e.getUint32(12,!0)===67305985,n=x=>e.getUint32(x,r),s=n(16),i=n(24),l=n(28),a=n(36),c=n(40),f=n(52),p=Math.max(1,n(56)),g=n(60),u=new Map,v=new TextDecoder("utf-8");let M=64;const d=64+g;for(;M<d;){const x=n(M);M+=4;const T=new Uint8Array(t,M,x),P=T.indexOf(0),L=v.decode(T.subarray(0,P)),_=v.decode(T.subarray(P+1)).replace(/\0+$/,"");u.set(L,_),M+=x+(3-(x+3)%4)}const y=[];M=d;for(let x=0;x<p;x++){const T=n(M);M+=4;const P=[];for(let L=0;L<f;L++)P.push(new Uint8Array(t,M,T)),M+=T+(3-(T+3)%4);y.push(P)}return{glType:s,glFormat:i,glInternalFormat:l,width:a,height:c,faces:f,mipLevels:p,keyValues:u,mips:y}},gl=t=>{const e=new Float32Array(27);if(!t)return e;const r=t.trim().split(/[\s\n]+/).map(Number);for(let n=0;n<Math.min(27,r.length);n++)e[n]=r[n];return e},Ms=35898,vl=35899,bs=6407,yl=(t,e)=>{const r=pl(e),n=gl(r.keyValues.get("sh")),s=new Qe(t,{target:t.TEXTURE_CUBE_MAP,generateMipmaps:!1,minFilter:t.LINEAR_MIPMAP_LINEAR,magFilter:t.LINEAR,flipY:!1,width:r.width,height:r.height}),i=r.glInternalFormat===Ms;t.bindTexture(t.TEXTURE_CUBE_MAP,s.texture),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!1),t.pixelStorei(t.UNPACK_ALIGNMENT,1);for(let l=0;l<r.mipLevels;l++){const a=Math.max(1,r.width>>l);for(let c=0;c<r.faces;c++){const f=r.mips[l][c];if(i)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+c,l,Ms,a,a,0,bs,vl,new Uint32Array(f.buffer,f.byteOffset,f.byteLength/4));else{const p=r.glFormat===bs?3:4;t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+c,l,p===3?t.RGB8:t.RGBA8,a,a,0,p===3?t.RGB:t.RGBA,t.UNSIGNED_BYTE,f)}}}return t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAX_LEVEL,r.mipLevels-1),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR),s.store.image=s.image=r,s.needsUpdate=!1,{sh:n,cubemap:s,maxLod:r.mipLevels-1}},xl=["EXT_meshopt_compression"],wl=t=>{const e=t.meshes;if(!e)return;const r=new Set;for(const n of t.nodes??[])n.mesh===void 0||!e[n.mesh]||(r.has(n.mesh)?(e.push({...e[n.mesh]}),n.mesh=e.length-1):r.add(n.mesh))},Ml=t=>{const e=[];return(t.animations??[]).forEach((r,n)=>{var i,l;const s=[];for(const a of r.channels??[]){const c=a.sampler!==void 0?(i=r.samplers)==null?void 0:i[a.sampler]:void 0;((l=a.target)==null?void 0:l.path)==="weights"&&a.target.node!==void 0&&c?e.push({anim:n,node:a.target.node,input:c.input,output:c.output,interpolation:c.interpolation??"LINEAR"}):s.push(a)}r.channels=s}),e},bl={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Al={5120:127,5121:255,5122:32767,5123:65535},Sl={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},Xr=(t,e,r)=>{var c,f,p;const n=(c=t==null?void 0:t.accessors)==null?void 0:c[r],s=Sl[n==null?void 0:n.type]??1,i=new Float32Array(((n==null?void 0:n.count)??0)*s);if(!n||i.length===0)return i;const l=(g,u,v,M,d,y)=>{var h;const x=new Float32Array(M*d),T=(h=t.bufferViews)==null?void 0:h[g],P=T?e[typeof T.buffer=="number"?T.buffer:0]:void 0,L=bl[v];if(!T||!P||!L)return x;const _=L.BYTES_PER_ELEMENT,o=(T.byteOffset??0)+u;if(!y||y===d*_){const m=new L(P,o,M*d);for(let w=0;w<x.length;w++)x[w]=m[w]}else for(let m=0;m<M;m++){const w=new L(P,o+m*y,d);for(let E=0;E<d;E++)x[m*d+E]=w[E]}return x};if(n.bufferView!==void 0&&i.set(l(n.bufferView,n.byteOffset??0,n.componentType,n.count,s,((p=(f=t.bufferViews)==null?void 0:f[n.bufferView])==null?void 0:p.byteStride)??0)),n.sparse){const g=n.sparse,u=l(g.indices.bufferView,g.indices.byteOffset??0,g.indices.componentType,g.count,1,0),v=l(g.values.bufferView,g.values.byteOffset??0,n.componentType,g.count,s,0);for(let M=0;M<g.count;M++)for(let d=0;d<s;d++)i[u[M]*s+d]=v[M*s+d]}const a=n.normalized?Al[n.componentType]:void 0;if(a)for(let g=0;g<i.length;g++)i[g]=Math.max(i[g]/a,-1);return i};new sr;new sr;const _l=(t,e)=>{const r=Math.floor((t?t.length:e)/3),n=1<<24,s=new Set;for(let a=0;a<r;a++){const c=t?t[a*3]:a*3,f=t?t[a*3+1]:a*3+1,p=t?t[a*3+2]:a*3+2;s.add(Math.min(c,f)*n+Math.max(c,f)),s.add(Math.min(f,p)*n+Math.max(f,p)),s.add(Math.min(p,c)*n+Math.max(p,c))}const i=e>65535?new Uint32Array(s.size*2):new Uint16Array(s.size*2);let l=0;for(const a of s)i[l++]=Math.floor(a/n),i[l++]=a%n;return i},El=t=>new Qe(t,{image:new Uint8Array([255,255,255,255]),width:1,height:1,generateMipmaps:!1}),Cl=t=>{const e=new Qe(t,{target:t.TEXTURE_CUBE_MAP,width:1,height:1,generateMipmaps:!1,minFilter:t.LINEAR});t.bindTexture(t.TEXTURE_CUBE_MAP,e.texture);const r=new Uint8Array(4);for(let n=0;n<6;n++)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,r);return e.store.image=e.image=r,e.needsUpdate=!1,e},Lr=8,Fl=(t,e,r,n)=>{var i,l,a,c,f,p;const s=e.nodes??[];for(let g=0;g<s.length;g++){const u=s[g].mesh;if(u===void 0)continue;const v=(i=e.meshes)==null?void 0:i[u],M=v==null?void 0:v.primitives;if(!(M!=null&&M.some(_=>{var o;return(o=_.targets)==null?void 0:o.length})))continue;const d=(l=r.nodes)==null?void 0:l[g],y=(a=r.meshes)==null?void 0:a[u];if(!d||!y)continue;const x=Math.max(...M.map(_=>{var o;return((o=_.targets)==null?void 0:o.length)??0})),T=new Float32Array(x),P=s[g].weights??v.weights;if(P)for(let _=0;_<Math.min(x,P.length);_++)T[_]=P[_];d.weights=T,x>Lr&&console.warn(`[viewer-lite] GLB: mesh has ${x} morph targets — only the first ${Lr} deform`);const L=Array.isArray((c=y.primitives)==null?void 0:c[0])?y.primitives[0]:y.primitives??[];for(let _=0;_<M.length;_++){const o=M[_].targets,h=L[_];if(!(o!=null&&o.length)||!(h!=null&&h.geometry))continue;const m=((p=(f=h.geometry.attributes)==null?void 0:f.position)==null?void 0:p.count)??0;if(m===0)continue;const w=Math.min(o.length,Lr);if(o.slice(0,w).find(q=>{const O=H=>{var G,Y;return H!==void 0&&((Y=(G=e.accessors)==null?void 0:G[H])==null?void 0:Y.count)!==m};return O(q.POSITION)||O(q.NORMAL)})){console.warn(`[viewer-lite] GLB: morph targets skipped on a primitive — target accessor count doesn't match the ${m}-vertex geometry (draco decode changed the vertex set)`);continue}const B=o.slice(0,w).some(q=>q.NORMAL!==void 0),W=m*w*(B?2:1),N=Math.max(1,Math.ceil(Math.sqrt(W))),I=Math.max(1,Math.ceil(W/N)),D=new Float32Array(N*I*4);for(let q=0;q<w;q++){const O=o[q].POSITION!==void 0?Xr(e,n,o[q].POSITION):null,H=B&&o[q].NORMAL!==void 0?Xr(e,n,o[q].NORMAL):null;for(let G=0;G<m;G++){if(O){const Y=(q*m+G)*4;D[Y]=O[G*3]??0,D[Y+1]=O[G*3+1]??0,D[Y+2]=O[G*3+2]??0}if(H){const Y=((w+q)*m+G)*4;D[Y]=H[G*3]??0,D[Y+1]=H[G*3+1]??0,D[Y+2]=H[G*3+2]??0}}}const K=new Qe(t,{image:D,width:N,height:I,type:t.FLOAT,format:t.RGBA,internalFormat:t.RGBA32F,generateMipmaps:!1,minFilter:t.NEAREST,magFilter:t.NEAREST,flipY:!1});h._morph={texture:K,count:w,vertexCount:m,texWidth:N,hasNormals:B,weights:T}}}},As=(t,e)=>{var n;const r=e==null?void 0:e.texture;if(!(!r||r._srgbTagged)){if(r._srgbTagged=!0,(n=r.image)!=null&&n.isCompressedTexture){r.image.srgbInternalFormat&&(r.internalFormat=r.image.srgbInternalFormat);return}r.internalFormat=t.SRGB8_ALPHA8,r.format=t.RGBA}},gi=t=>{var s,i;const e=[];t instanceof Rt&&e.push("HAS_SKIN");const r=(i=(s=t.geometry)==null?void 0:s.attributes)==null?void 0:i.color;r&&r.size===4&&e.push("HAS_COLOR");const n=t._morph;return n&&(e.push("HAS_MORPH"),n.hasNormals&&e.push("HAS_MORPH_NORMALS")),e.join(" ")},vi=(t,e)=>{const r={uMorphTex:{value:e.texture},uMorphCount:{value:e.count},uMorphVertexCount:{value:e.vertexCount},uMorphTexWidth:{value:e.texWidth},uMorphWeights:{value:[e.weights.length>Lr?e.weights.subarray(0,Lr):e.weights]}};t.onBeforeRender(()=>{Object.assign(t.program.uniforms,r)})},Tl=(t,e,r,n,s)=>{var p,g,u,v,M,d,y,x,T,P,L;const i=e??{},l=[];(p=i.baseColorTexture)!=null&&p.texture&&l.push("#define HAS_BASECOLOR_MAP"),(g=i.metallicRoughnessTexture)!=null&&g.texture&&l.push("#define HAS_MR_MAP"),(u=i.normalTexture)!=null&&u.texture&&l.push("#define HAS_NORMAL_MAP"),(v=i.occlusionTexture)!=null&&v.texture&&l.push("#define HAS_OCCLUSION_MAP"),(M=i.emissiveTexture)!=null&&M.texture&&l.push("#define HAS_EMISSIVE_MAP"),(d=i.extensions)!=null&&d.KHR_materials_unlit&&l.push("#define UNLIT"),i.doubleSided&&l.push("#define DOUBLE_SIDED"),i.alphaMode==="MASK"&&l.push("#define ALPHA_MASK"),i.alphaMode==="BLEND"&&l.push("#define ALPHA_BLEND");const a=_=>ol([...l,..._.includes("HAS_COLOR")?["#define HAS_COLOR"]:[]].join(`
715
- `));As(t,i.baseColorTexture),As(t,i.emissiveTexture);const c={...n,uBaseColorFactor:{value:i.baseColorFactor??[1,1,1,1]},uMetallic:{value:i.metallicFactor??1},uRoughness:{value:i.roughnessFactor??1},uEmissive:{value:i.emissiveFactor??[0,0,0]},uAlphaCutoff:{value:i.alphaCutoff??.5}};(y=i.baseColorTexture)!=null&&y.texture&&(c.uBaseColorMap={value:i.baseColorTexture.texture}),(x=i.metallicRoughnessTexture)!=null&&x.texture&&(c.uMRMap={value:i.metallicRoughnessTexture.texture}),(T=i.normalTexture)!=null&&T.texture&&(c.uNormalMap={value:i.normalTexture.texture}),(P=i.occlusionTexture)!=null&&P.texture&&(c.uOcclusionMap={value:i.occlusionTexture.texture}),(L=i.emissiveTexture)!=null&&L.texture&&(c.uEmissiveMap={value:i.emissiveTexture.texture});const f=new ze(t,{vertex:_n(r),fragment:a(r),uniforms:c,transparent:i.alphaMode==="BLEND",cullFace:i.doubleSided?!1:t.BACK});return i.alphaMode==="BLEND"&&f.setBlendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),f._source={fragment:a,vertex:r},f},Rl=async(t,e,r,n)=>{var x,T,P,L,_;const s=vs.unpackGLB(e),i=(s.extensionsRequired??[]).filter(o=>xl.includes(o));if(i.length>0)throw new Error(`GLB requires ${i.join(", ")} — the lite engine has no decoder for it`);const l=[...s.extensionsUsed??[],...s.extensionsRequired??[]],a=l.includes("KHR_draco_mesh_compression"),c=l.includes("KHR_texture_basisu")||(s.images??[]).some(o=>o.mimeType==="image/ktx2");if(a||c){const o=await Nr(()=>import("./index-oPsDD47E.js"),__vite__mapDeps([0,1]),import.meta.url);await Promise.all([a?o.ensureDracoDecoder():null,c?o.ensureBasisTranscoder(t):null])}wl(s);const f=Ml(s),p=await vs.parse(t,s,""),g=(s.buffers??[]).map(o=>o.binary);Fl(t,s,p,g);const u=new Map,v=new Set,M=[];for(const o of p.nodes)o.traverse(h=>(h.draw&&!v.has(h)&&(v.add(h),M.push(h)),!1));for(const o of M){const h=(x=o.geometry)==null?void 0:x.attributes,m=((T=h==null?void 0:h.position)==null?void 0:T.count)??0;if(h&&m>0){if(!h.normal){const D=new Float32Array(m*3);for(let K=2;K<D.length;K+=3)D[K]=1;o.geometry.addAttribute("normal",{size:3,data:D})}h.uv||o.geometry.addAttribute("uv",{size:2,data:new Float32Array(m*2)})}const w=(P=o.program)==null?void 0:P.gltfMaterial,E=o._morph;E&&vi(o,E);const B=gi(o),W=w??o;let N=u.get(W);N||u.set(W,N=new Map);let I=N.get(B);I||N.set(B,I=Tl(t,w,B,r)),o.program=I,o._receiveShadows=!0,o._castShadows=!0}p.images&&await Promise.all(p.images.map(o=>o==null?void 0:o.ready).filter(Boolean));const d=(p.animations??[]).map((o,h)=>{const m=[];for(const w of o.animation.data)m.includes(w.node)||m.push(w.node);return{name:typeof o.name=="string"&&o.name.length>0?o.name:`animation_${h}`,duration:o.animation.duration,animation:o.animation,nodes:m}});let y=0;for(const o of f){const h=d[o.anim],m=(L=p.nodes)==null?void 0:L[o.node];!h||!(m!=null&&m.weights)||(h.animation.data.push({node:m,transform:"weights",interpolation:o.interpolation,times:Xr(s,g,o.input),values:Xr(s,g,o.output)}),y++)}f.length>y&&console.warn(`[viewer-lite] GLB: ${f.length-y} morph (weights) animation channel(s) ignored — their nodes carry no usable morph targets`);for(const o of d){let h=1/0,m=0;for(const w of o.animation.data)h=Math.min(h,w.times[0]),m=Math.max(m,w.times[w.times.length-1]);o.animation.startTime=h===1/0?0:h,o.animation.duration=o.duration=h===1/0?0:m-h}return{roots:p.scene??((_=p.scenes)==null?void 0:_[0])??[],nodes:p.nodes??[],animations:d}},Pl=t=>{if(!t||t.byteLength<24||t.byteLength>1e6||new Uint8Array(t,0,1)[0]!==123)return null;try{const e=JSON.parse(new TextDecoder().decode(t));return(e==null?void 0:e.lecodesLiteMaterial)===1?e:null}catch{return null}},Ll={float:{decl:"float",zero:0},float2:{decl:"vec2",zero:[0,0]},float3:{decl:"vec3",zero:[0,0,0]},float4:{decl:"vec4",zero:[0,0,0,0]},int:{decl:"int",zero:0},int2:{decl:"ivec2",zero:[0,0]},int3:{decl:"ivec3",zero:[0,0,0]},int4:{decl:"ivec4",zero:[0,0,0,0]},bool:{decl:"bool",zero:0},bool2:{decl:"bvec2",zero:[0,0]},bool3:{decl:"bvec3",zero:[0,0,0]},bool4:{decl:"bvec4",zero:[0,0,0,0]},float3x3:{decl:"mat3",zero:new Float32Array([1,0,0,0,1,0,0,0,1])},float4x4:{decl:"mat4",zero:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}},Bl=`
716
- struct MaterialInputs {
717
- vec4 baseColor;
718
- float roughness;
719
- float metallic;
720
- float reflectance;
721
- float ambientOcclusion;
722
- vec4 emissive;
723
- vec3 normal;
724
- float clearCoat;
725
- float clearCoatRoughness;
726
- vec4 postLightingColor;
727
- };
728
- void prepareMaterial(inout MaterialInputs m) {}
729
- vec3 getWorldPosition() { return vWorldPos; }
730
- vec3 getWorldGeometricNormalVector() { return normalize(vNormal); }
731
- vec3 getWorldViewVector() { return normalize(cameraPosition - vWorldPos); }
732
- vec4 getUserTime() { return userTime; }
733
- ${fi}
734
- vec3 inverseTonemap(vec3 linear) {
735
- return Inverse_Tonemap_Filmic(clamp(linear, 0.0, 1.0));
736
- }
737
- `,ln=`
738
- MaterialInputs inputs;
739
- inputs.baseColor = vec4(1.0);
740
- inputs.roughness = 1.0;
741
- inputs.metallic = 0.0;
742
- inputs.reflectance = 0.5;
743
- inputs.ambientOcclusion = 1.0;
744
- inputs.emissive = vec4(0.0, 0.0, 0.0, 1.0);
745
- inputs.normal = vec3(0.0, 0.0, 1.0);
746
- inputs.clearCoat = 0.0;
747
- inputs.clearCoatRoughness = 0.0;
748
- inputs.postLightingColor = vec4(0.0);
749
- material(inputs);
750
- `,Nl=`
751
- vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
752
- vec3 pos_dx = dFdx(vWorldPos);
753
- vec3 pos_dy = dFdy(vWorldPos);
754
- vec2 tex_dx = dFdx(vUv);
755
- vec2 tex_dy = dFdy(vUv);
756
- float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
757
- if (abs(det) < 1e-8) return ng;
758
- vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
759
- t = normalize(t - ng * dot(ng, t));
760
- vec3 b = normalize(cross(ng, t)) * sign(det);
761
- return normalize(mat3(t, b, ng) * nTangent);
762
- }
763
- `,Ol=t=>{if(t.unsupported)return null;const e=[],r=[],n=new Set;for(const u of t.params){const v=Ll[u.type];if(!v)return null;e.push(`uniform ${v.decl} materialParams_${u.name}${u.size?`[${u.size}]`:""};`);const M=u.size?new Array(u.size*(Array.isArray(v.zero)||v.zero instanceof Float32Array?v.zero.length:1)).fill(0):v.zero;r.push({key:`materialParams_${u.name}`,value:Array.isArray(M)?[...M]:M}),n.add(u.name)}for(const u of t.samplers)e.push(`uniform sampler2D materialParams_${u.name};`),r.push({key:`materialParams_${u.name}`,value:"texture"}),n.add(u.name);const s=t.shadingModel==="lit",i=s||t.shadowMultiplier,l=t.blending==="opaque"||t.blending==="masked",a=t.blending==="masked"?`if (inputs.baseColor.a < ${t.maskThreshold.toFixed(4)}) discard;`:"",c=l?"1.0":"inputs.baseColor.a",f=t.shadowMultiplier?`
764
- void main() {
765
- ${ln}
766
- float shadowAmount = 1.0 - sampleShadowPCF();
767
- fragColor = vec4(inputs.baseColor.rgb * shadowAmount, inputs.baseColor.a * shadowAmount);
768
- }
769
- `:s?`
770
- void main() {
771
- ${ln}
772
- ${a}
773
- vec3 n = normalize(vNormal);
774
- vec3 v = normalize(cameraPosition - vWorldPos);
775
- ${t.doubleSided?"if (dot(n, v) < 0.0) n = -n;":""}
776
- ${t.writesNormal?"n = applyTangentNormal(inputs.normal, n);":""}
777
- vec3 diffuseColor = inputs.baseColor.rgb * (1.0 - inputs.metallic);
778
- vec3 f0 = mix(vec3(0.16 * inputs.reflectance * inputs.reflectance), inputs.baseColor.rgb, inputs.metallic);
779
- vec3 color = shadePBR(n, v, diffuseColor, f0, inputs.roughness, inputs.ambientOcclusion);
780
- color += inputs.emissive.rgb * (iblLuminance * exposure);
781
- color += inputs.postLightingColor.rgb;
782
- fragColor = vec4(tonemap(color), ${c});
783
- }
784
- `:`
785
- void main() {
786
- ${ln}
787
- ${a}
788
- vec3 color = inputs.baseColor.rgb + inputs.emissive.rgb + inputs.postLightingColor.rgb;
789
- fragColor = vec4(tonemap(color), ${c});
790
- }
791
- `,p=t.flipUV===!1?"vUv":"vec2(vUv.x, 1.0 - vUv.y)";return{fragment:`#version 300 es
792
- precision highp float;
793
- in vec3 vWorldPos;
794
- in vec3 vNormal;
795
- in vec2 vUv;
796
- uniform vec3 cameraPosition;
797
- uniform vec4 userTime;
798
- ${e.join(`
799
- `)}
800
- ${i?Ir:br}
801
- ${Bl}
802
- vec2 getUV0() { return ${p}; }
803
- vec2 getUV1() { return ${p}; }
804
- ${t.writesNormal?Nl:""}
805
- out vec4 fragColor;
806
- ${t.fragmentCode}
807
- ${f}`,uniforms:r,paramNames:n,needsSceneUniforms:i}},at=10,Ss=0,_s=1;let Il=null,jr=null;const Ul=()=>Il??(Il=Nr(()=>import("./creatorPhysics-k7wL0kV1.js"),__vite__mapDeps([2,1]),import.meta.url).then(t=>t.default()).then(t=>jr=t)),Es=()=>jr!==null,lt=(t,e,r)=>{const n=t._malloc(Math.max(4,e.length*4));t.HEAPF32.set(e,n>>2);try{return r(n)}finally{t._free(n)}},Cs=(t,e,r)=>{const n=t._malloc(Math.max(4,e.length*4));t.HEAPU32.set(e,n>>2);try{return r(n)}finally{t._free(n)}},Vr=(t,e,r)=>{const n=t._malloc(Math.max(1,e.length));t.HEAPU8.set(e,n);try{return r(n)}finally{t._free(n)}},Fs=t=>t instanceof Uint8Array?t:new Uint8Array(t),_r=(t,e,r)=>{const n=Math.hypot(t[0],t[1],t[2])||1,s=Math.hypot(t[4],t[5],t[6])||1,i=Math.hypot(t[8],t[9],t[10])||1,l=t[0]/n,a=t[1]/n,c=t[2]/n,f=t[4]/s,p=t[5]/s,g=t[6]/s,u=t[8]/i,v=t[9]/i,M=t[10]/i,d=l+p+M;let y,x,T,P;if(d>0){const L=Math.sqrt(d+1)*2;P=.25*L,y=(g-v)/L,x=(u-c)/L,T=(a-f)/L}else if(l>p&&l>M){const L=Math.sqrt(1+l-p-M)*2;P=(g-v)/L,y=.25*L,x=(f+a)/L,T=(u+c)/L}else if(p>M){const L=Math.sqrt(1+p-l-M)*2;P=(u-c)/L,y=(f+a)/L,x=.25*L,T=(v+g)/L}else{const L=Math.sqrt(1+M-l-p)*2;P=(a-f)/L,y=(u+c)/L,x=(v+g)/L,T=.25*L}e[r]=t[12],e[r+1]=t[13],e[r+2]=t[14],e[r+3]=y,e[r+4]=x,e[r+5]=T,e[r+6]=P,e[r+7]=n,e[r+8]=s,e[r+9]=i},Dl=(t,e)=>{const r=Math.cos(e),n=Math.sin(e),s=t[0],i=t[1],l=t[2],a=t[8],c=t[9],f=t[10],p=t;p[0]=s*r-a*n,p[1]=i*r-c*n,p[2]=l*r-f*n,p[8]=s*n+a*r,p[9]=i*n+c*r,p[10]=l*n+f*r},zl=(t,e=1,r=1,n=1)=>{const s=jr;if(!s||t.length<12)return null;const i=lt(s,t,p=>s._cphysShapeMesh(p,Math.floor(t.length/3),0,0,1,e,r,n));if(!i)return null;const l=s._malloc(4),a=s._cphysShapeTriangles(i,l),c=s.HEAPU32[l>>2],f=a&&c?Float32Array.from(s.HEAPF32.subarray(a>>2,(a>>2)+c)):null;return a&&s._free(a),s._free(l),s._cphysShapeDestroy(i),f};function Gl(t){const e=jr;if(!e)throw new Error("creator-physics: await loadCreatorPhysics() before createPhysicsBridge()");const r=e._malloc(at*4),n=e._malloc(32),s=e._malloc(4);let i=0,l=0;const a=o=>(o>l&&(i&&e._free(i),i=e._malloc(o*4),l=o),i),c=new Map,f=new Map,p=(o,h)=>{if(!t.jointRanges)return;const m=h.entities.length,w=new Float32Array(m*9);if(lt(e,w,q=>{const O=e._cphysRagdollJointFrames(o,q);return w.set(e.HEAPF32.subarray(q>>2,(q>>2)+m*9)),O})!==m)return;const B=[],W=[],N=[];for(let q=0;q<m;q++){const O=w[q*9];if(!(O<0)){B.push(h.entities[q],h.entities[O]);for(let H=1;H<9;H++)W.push(w[q*9+H]);N.push(q)}}if(B.length===0)return;const I=t.jointRanges(h.entities[0],B,Float32Array.from(W));if(!I)return;const D=new Float32Array(m*6),K=180/Math.PI;for(let q=0;q<N.length;q++)for(let O=0;O<3;O++)D[N[q]*6+O*2]=I[q*6+O*2]*K-h.margin,D[N[q]*6+O*2+1]=I[q*6+O*2+1]*K+h.margin;lt(e,D,q=>e._cphysRagdollSetLimits(o,q))&&(h.learned=!0)},g=new WeakMap;let u=null;const v=e.addFunction(o=>t.parentOf(o)|0,"ii");e._cphysSetParentLookup(v),e._cphysInit();const M=o=>(_r(t.world(o),e.HEAPF32,r>>2),r),d=(o,h)=>{const m=e.HEAPF32,w=h>>2;o[0]=m[w],o[1]=m[w+1],o[2]=m[w+2]},y=o=>{if(o===0)return;const h=e.HEAPU32,m=e._cphysPulledIds()>>2,w=e.HEAPF32,E=e._cphysPulledPoses()>>2;for(let B=0;B<o;B++){const W=E+B*at;t.setWorldTRS(h[m+B],w[W],w[W+1],w[W+2],w[W+3],w[W+4],w[W+5],w[W+6],w[W+7],w[W+8],w[W+9])}},x=o=>{if(o===0)return;const h=e.HEAPU32,m=e._cphysPulledIds()>>2,w=e.HEAPF32,E=e._cphysPulledPoses()>>2;for(let B=0;B<o;B++){const W=E+B*at;t.setWorldPosition(h[m+B],w[W],w[W+1],w[W+2])}},T=(o,h)=>{var B;const m=(B=t.glbBytes)==null?void 0:B.call(t,o);if(!m)return 0;let w=g.get(m);w||(w=[0,0],g.set(m,w));const E=h?1:0;if(!w[E]){const W=Fs(m);w[E]=Vr(e,W,N=>e._cphysShapeMeshFromGlb(N,W.length,h?1:0))}return w[E]},P=(o,h,m,w,E,B)=>h?e._cphysBodyCreate(o,h,m|0,w,E?1:0,B?1:0,1,M(o)):0,L=(o,h,m,w)=>{const E=P(o,h,m,w,!1,!1);return h&&e._cphysShapeDestroy(h),E};return{methods:{physicsHasSupport:()=>!0,physicsConfigure(o,h,m,w){e._cphysConfigure(o,h,m,(w|0)>0?w|0:0)},setInterpolation(o){e._cphysSetInterpolation(o?1:0)},physicsBuildBox:(o,h,m)=>e._cphysShapeBox(o,h,m),physicsBuildSphere:o=>e._cphysShapeSphere(o),physicsBuildCylinder:(o,h)=>e._cphysShapeCylinder(o,h),physicsBuildCapsule:(o,h)=>e._cphysShapeCapsule(o,h),physicsBuildMesh(o,h,m,w,E,B){return lt(e,o,W=>Cs(e,h,N=>e._cphysShapeMesh(W,Math.floor(o.length/3),N,h.length,m?1:0,w,E,B)))},physicsBuildMeshFromEntity(o,h,m,w,E){const B=T(o,h);return B?e._cphysShapeScaled(B,m,w,E):0},physicsBuildHeightField(o,h,m,w,E,B,W,N){return lt(e,o,I=>E?Vr(e,E,D=>e._cphysShapeHeightField(I,h,m,w,D,B,W,N)):e._cphysShapeHeightField(I,h,m,w,0,B,W,N))},physicsUpdateHeightField(o,h,m,w,E,B,W,N,I){lt(e,h,D=>I?Vr(e,I,K=>e._cphysShapeUpdateHeightField(o,D,m,w,E,B,W,N,K)):e._cphysShapeUpdateHeightField(o,D,m,w,E,B,W,N,0))},glbTriangles(o){var W;const h=(W=t.glbBytes)==null?void 0:W.call(t,o);if(!h)return new Float32Array(0);const m=Fs(h),w=Vr(e,m,N=>e._cphysGlbTriangles(N,m.length,s));if(!w)return new Float32Array(0);const E=e.HEAPU32[s>>2],B=Float32Array.from(e.HEAPF32.subarray(w>>2,(w>>2)+E));return e._free(w),B},physicsSetShapeOrigin(o,h,m,w){e._cphysShapeSetOrigin(o,h,m,w)},physicsSetBodyShape(o,h,m){e._cphysBodySetShape(o,h,m?1:0)},physicsDestroyShape(o){e._cphysShapeDestroy(o)},physicsCreateBody:(o,h,m,w,E,B)=>P(o,h,m,w,E,B),physicsSetPickable(o,h){e._cphysBodySetPickable(o,h?1:0)},physicsSetFriction(o,h){e._cphysBodySetFriction(o,h)},physicsGetFriction:o=>e._cphysBodyGetFriction(o),physicsRaycast(o,h,m,w,E,B,W,N){const I=e._cphysRaycast(o,h,m,w,E,B,W,n);return I&&N&&N.set(e.HEAPF32.subarray(n>>2,(n>>2)+Math.min(7,N.length))),I},physicsCreateBox:(o,h,m,w,E,B)=>L(o,e._cphysShapeBox(h,m,w),E,B),physicsCreateSphere:(o,h,m,w)=>L(o,e._cphysShapeSphere(h),m,w),physicsCreateCylinder:(o,h,m,w,E)=>L(o,e._cphysShapeCylinder(h,m),w,E),physicsSetLinearVelocity(o,h,m,w){e._cphysBodySetLinearVelocity(o,h,m,w)},physicsGetLinearVelocity(o,h){e._cphysBodyGetLinearVelocity(o,n),d(h,n)},physicsSetAngularVelocity(o,h,m,w){e._cphysBodySetAngularVelocity(o,h,m,w)},physicsGetAngularVelocity(o,h){e._cphysBodyGetAngularVelocity(o,n),d(h,n)},physicsApplyImpulse(o,h,m,w){e._cphysBodyApplyImpulse(o,h,m,w)},physicsApplyImpulseAt(o,h,m,w,E,B,W){e._cphysBodyApplyImpulseAt(o,h,m,w,E,B,W)},physicsSetBodyPosition(o,h,m,w){e._cphysBodySetPosition(o,h,m,w)},physicsSetBodyRotation(o,h,m,w,E){e._cphysBodySetRotation(o,h,m,w,E)},physicsRemoveBody(o){e._cphysBodyRemove(o)},characterCreate(o,h,m){const w=h?e._cphysCharacterCreate(o,h,m,M(o)):0;return w&&c.set(w,o),w},characterDestroy(o){e._cphysCharacterDestroy(o),c.delete(o)},characterMove(o,h,m){e._cphysCharacterMove(o,h,m)},characterMoveFree(o,h,m,w){e._cphysCharacterMoveFree(o,h,m,w)},characterSetVerticalVelocity(o,h){e._cphysCharacterSetVerticalVelocity(o,h)},characterSetVelocity(o,h,m,w){e._cphysCharacterSetVelocity(o,h,m,w)},characterSetGravityScale(o,h){e._cphysCharacterSetGravityScale(o,h)},characterSetMaxSlope(o,h){e._cphysCharacterSetMaxSlope(o,h)},characterSetShape(o,h){if(!e._cphysCharacterSetShape(o,h))return!1;const m=c.get(o);if(m!==void 0){e._cphysCharacterPosition(o,n);const w=e.HEAPF32,E=n>>2;t.setWorldPosition(m,w[E],w[E+1],w[E+2])}return!0},characterGetVelocity(o,h){e._cphysCharacterGetVelocity(o,n),d(h,n)},characterGetGroundState:o=>e._cphysCharacterGetGroundState(o),characterSetPosition(o,h,m,w){e._cphysCharacterSetPosition(o,h,m,w)},vehicleCreate(o,h,m){return h?lt(e,m,w=>e._cphysVehicleCreate(o,h,w,m.length,M(o))):0},vehicleDestroy(o){e._cphysVehicleDestroy(o)},vehicleSetInput(o,h){lt(e,h,m=>e._cphysVehicleSetInput(o,m,h.length))},vehicleSetTuning(o,h){lt(e,h,m=>e._cphysVehicleSetTuning(o,m,h.length))},vehicleGetState(o,h){const m=a(h.length);e._cphysVehicleGetState(o,m,h.length),h.set(e.HEAPF32.subarray(m>>2,(m>>2)+h.length))},vehicleReset(o,h,m,w,E,B,W,N){e._cphysVehicleReset(o,h,m,w,E,B,W,N)},vehicleBodyId:o=>e._cphysVehicleBodyId(o),ragdollCreate(o,h,m){const w=m.length>1?m[1]|0:0;if(w<=0||h.length<w*2)return 0;const E=new Float32Array(at);_r(t.world(o),E,0);const B=new Float32Array(w*(at+3)),W=[];for(let I=0;I<w;I++){const D=I*(at+3);_r(t.world(h[I*2]),B,D),W.push(h[I*2]);const K=h[I*2+1];if(K){const q=t.world(K);B[D+at]=q[12],B[D+at+1]=q[13],B[D+at+2]=q[14]}}const N=lt(e,E,I=>Cs(e,h,D=>lt(e,B,K=>lt(e,m,q=>e._cphysRagdollCreate(I,D,h.length,K,q,m.length)))));return N&&f.set(N,{entities:W,prev:new Float32Array(w*at),cur:new Float32Array(w*at),valid:0,dt:1/60,active:!1,driven:!1,learn:m.length>14&&m[13]!==0,margin:m.length>14?Math.max(0,m[14]):0,learned:!1}),N},ragdollDestroy(o){e._cphysRagdollDestroy(o),f.delete(o)},ragdollActivate(o,h,m,w){const E=f.get(o);if(!E)return!1;!E.active&&E.learn&&!E.learned&&p(o,E);const B=E.entities.length,W=new Float32Array(B*at);for(let D=0;D<B;D++)_r(t.world(E.entities[D]),W,D*at);let N=null;if(!E.active&&E.valid>=2&&E.dt>1e-5){N=new Float32Array(B*6);const D=1/E.dt;for(let K=0;K<B;K++){const q=K*at,O=K*6;N[O]=(E.cur[q]-E.prev[q])*D,N[O+1]=(E.cur[q+1]-E.prev[q+1])*D,N[O+2]=(E.cur[q+2]-E.prev[q+2])*D;const H=E.prev[q+3],G=E.prev[q+4],Y=E.prev[q+5],se=E.prev[q+6],te=E.cur[q+3],ne=E.cur[q+4],he=E.cur[q+5],we=E.cur[q+6];let de=we*-H+te*se+ne*-Y-he*-G,Ve=we*-G-te*-Y+ne*se+he*-H,je=we*-Y+te*-G-ne*-H+he*se,S=we*se-te*-H-ne*-G-he*-Y;S<0&&(de=-de,Ve=-Ve,je=-je,S=-S);const A=Math.sqrt(Math.max(0,1-S*S));if(A>1e-6){const R=2*Math.acos(Math.min(1,S))/A*D;N[O+3]=de*R,N[O+4]=Ve*R,N[O+5]=je*R}}}const I=lt(e,W,D=>N?lt(e,N,K=>e._cphysRagdollActivate(o,h,m,w,D,K)):e._cphysRagdollActivate(o,h,m,w,D,0))!==0;return I&&(E.active=!0),I},ragdollDeactivate(o,h){var w;const m=f.get(o);m!=null&&m.active&&(y(e._cphysRagdollPose(o)),h>0&&m.entities.length>0&&((w=t.seedAnimator)==null||w.call(t,m.entities[0],h)),m.active=!1,m.valid=0),e._cphysRagdollDeactivate(o)},ragdollSetDrive(o,h,m){const w=f.get(o);w&&(w.driven=h>0||m),e._cphysRagdollSetDrive(o,h,m?1:0)},ragdollActive:o=>e._cphysRagdollActive(o)!==0,ragdollBodyId:(o,h)=>e._cphysRagdollBodyId(o,h),setOnPhysicsEvent(o){u=o}},frame(o,h){const m=e._cphysFrameBegin(o),w=e._cphysFixedDt();for(let B=0;B<m;B++)h&&(y(e._cphysPullBodies(_s)),x(e._cphysPullCharacters(_s)),h(w)),e._cphysStep();e._cphysFrameEnd(),y(e._cphysPullBodies(Ss)),x(e._cphysPullCharacters(Ss));const E=e._cphysEventCount();if(E>0&&u){const B=e._cphysEventData()>>2,W=Array.from(e.HEAPU32.subarray(B,B+E*3));for(let N=0;N<E;N++)u(W[N*3],W[N*3+1],W[N*3+2])}},syncRagdolls(o){if(f.size!==0){for(const[h,m]of f){const w=m.prev;m.prev=m.cur,m.cur=w;for(let E=0;E<m.entities.length;E++)_r(t.world(m.entities[E]),m.cur,E*at);o>1e-5&&(m.dt=o),m.valid<2&&m.valid++,m.active&&m.driven&&lt(e,m.cur,E=>e._cphysRagdollSetTarget(h,E))}y(e._cphysPullRagdolls())}},applyRootMotion(o,h,m,w,E){for(let B=o;B;B=t.parentOf(B)){const W=e._cphysCharacterForEntity(B);if(W){if(e._cphysCharacterSetExternalVelocity(W,w>0?h/w:0,w>0?m/w:0),E!==0){const N=t.get(B);N&&(Dl(N.m,E),t.localMatrixChanged(B))}return!0}}return!1},dispose(){e._cphysShutdown(),e._cphysSetParentLookup(0),e.removeFunction(v),e._free(r),e._free(n),e._free(s),i&&e._free(i),c.clear(),f.clear()}}}const Ts={aliceblue:4042850303,antiquewhite:4209760255,aqua:16777215,aquamarine:2147472639,azure:4043309055,beige:4126530815,bisque:4293182719,black:255,blanchedalmond:4293643775,blue:65535,blueviolet:2318131967,brown:2771004159,burlywood:3736635391,cadetblue:1604231423,chartreuse:2147418367,chocolate:3530104575,coral:4286533887,cornflowerblue:1687547391,cornsilk:4294499583,crimson:3692313855,cyan:16777215,darkblue:35839,darkcyan:9145343,darkgoldenrod:3095792639,darkgray:2846468607,darkgreen:6553855,darkgrey:2846468607,darkkhaki:3182914559,darkmagenta:2332068863,darkolivegreen:1433087999,darkorange:4287365375,darkorchid:2570243327,darkred:2332033279,darksalmon:3918953215,darkseagreen:2411499519,darkslateblue:1211993087,darkslategray:793726975,darkslategrey:793726975,darkturquoise:13554175,darkviolet:2483082239,deeppink:4279538687,deepskyblue:12582911,dimgray:1768516095,dimgrey:1768516095,dodgerblue:512819199,firebrick:2988581631,floralwhite:4294635775,forestgreen:579543807,fuchsia:4278255615,gainsboro:3705462015,ghostwhite:4177068031,gold:4292280575,goldenrod:3668254975,gray:2155905279,green:8388863,greenyellow:2919182335,grey:2155905279,honeydew:4043305215,hotpink:4285117695,indianred:3445382399,indigo:1258324735,ivory:4294963455,khaki:4041641215,lavender:3873897215,lavenderblush:4293981695,lawngreen:2096890111,lemonchiffon:4294626815,lightblue:2916673279,lightcoral:4034953471,lightcyan:3774873599,lightgoldenrodyellow:4210742015,lightgray:3553874943,lightgreen:2431553791,lightgrey:3553874943,lightpink:4290167295,lightsalmon:4288707327,lightseagreen:548580095,lightskyblue:2278488831,lightslategray:2005441023,lightslategrey:2005441023,lightsteelblue:2965692159,lightyellow:4294959359,lime:16711935,limegreen:852308735,linen:4210091775,magenta:4278255615,maroon:2147483903,mediumaquamarine:1724754687,mediumblue:52735,mediumorchid:3126187007,mediumpurple:2473647103,mediumseagreen:1018393087,mediumslateblue:2070474495,mediumspringgreen:16423679,mediumturquoise:1221709055,mediumvioletred:3340076543,midnightblue:421097727,mintcream:4127193855,mistyrose:4293190143,moccasin:4293178879,navajowhite:4292783615,navy:33023,oldlace:4260751103,olive:2155872511,olivedrab:1804477439,orange:4289003775,orangered:4282712319,orchid:3664828159,palegoldenrod:4008225535,palegreen:2566625535,paleturquoise:2951671551,palevioletred:3681588223,papayawhip:4293907967,peachpuff:4292524543,peru:3448061951,pink:4290825215,plum:3718307327,powderblue:2967529215,purple:2147516671,rebeccapurple:1714657791,red:4278190335,rosybrown:3163525119,royalblue:1097458175,saddlebrown:2336560127,salmon:4202722047,sandybrown:4104413439,seagreen:780883967,seashell:4294307583,sienna:2689740287,silver:3233857791,skyblue:2278484991,slateblue:1784335871,slategray:1887473919,slategrey:1887473919,snow:4294638335,springgreen:16744447,steelblue:1182971135,tan:3535047935,teal:8421631,thistle:3636451583,tomato:4284696575,turquoise:1088475391,violet:4001558271,wheat:4125012991,white:4294967295,whitesmoke:4126537215,yellow:4294902015,yellowgreen:2597139199,transparent:0,clear:0},Te=Math.fround,Rs=Te(1/3),Vl=Te(1/6),Ps=Te(2/3),Hl=Te(3.14159265),kl=Te(.9),En=t=>t===32||t>=9&&t<=13,Hr=t=>t>=48&&t<=57,qr=t=>t>=65&&t<=90?t+32:t,Ls=t=>{const e=qr(t);return e>=97&&e<=122},Wl=t=>{const e=qr(t);return e>=48&&e<=57?e-48:e>=97&&e<=102?e-87:-1},jt=(t,e,r,n)=>{if(r!==n.length)return!1;for(let s=0;s<r;s++)if(qr(t.charCodeAt(e+s))!==n.charCodeAt(s))return!1;return!0},$l=(t,e,r)=>{let n=e;n<r&&(t.charCodeAt(n)===43||t.charCodeAt(n)===45)&&n++;let s=0,i=0;for(;n<r&&Hr(t.charCodeAt(n));)n++,s++;if(n<r&&t.charCodeAt(n)===46){let l=n+1;for(;l<r&&Hr(t.charCodeAt(l));)l++,i++;(s>0||i>0)&&(n=l)}if(s===0&&i===0)return 0;if(n<r&&(t.charCodeAt(n)===101||t.charCodeAt(n)===69)){let l=n+1;if(l<r&&(t.charCodeAt(l)===43||t.charCodeAt(l)===45)&&l++,l<r&&Hr(t.charCodeAt(l))){for(;l<r&&Hr(t.charCodeAt(l));)l++;n=l}}return n-e},Xl=(t,e,r)=>{const n=[];let s=e;for(;s<r;){for(;s<r&&(En(t.charCodeAt(s))||t.charCodeAt(s)===44||t.charCodeAt(s)===47);)s++;if(s>=r)break;const i=$l(t,s,r);if(i===0||i>=64)return null;let l=Te(parseFloat(t.slice(s,s+i)));s+=i;let a=!1;if(s<r&&t.charCodeAt(s)===37)a=!0,s++;else if(s<r&&Ls(t.charCodeAt(s))){const c=s;for(;s<r&&Ls(t.charCodeAt(s));)s++;const f=s-c;if(!jt(t,c,f,"deg"))if(jt(t,c,f,"rad"))l=Te(l*180),l=Te(l/Hl);else if(jt(t,c,f,"turn"))l=Te(l*360);else if(jt(t,c,f,"grad"))l=Te(l*kl);else return null}if(!Number.isFinite(l)||n.length===4)return null;n.push({v:l,percent:a})}return n.length>=3?n:null},tr=t=>t<0?0:t>1?1:t,cn=(t,e,r)=>{r<0&&(r=Te(r+1)),r>1&&(r=Te(r-1));const n=Te(e-t);return r<Vl?Te(t+Te(Te(n*6)*r)):r<.5?e:r<Ps?Te(t+Te(Te(n*Te(Ps-r))*6)):t},un=(t,e,r,n)=>({r:Te(t/255),g:Te(e/255),b:Te(r/255),a:Te(n/255)}),jl=t=>{if(typeof t!="string")return null;const e=t.indexOf("\0"),r=e<0?t:t.slice(0,e);let n=0,s=r.length;for(;n<s&&En(r.charCodeAt(n));)n++;for(;s>n&&En(r.charCodeAt(s-1));)s--;const i=s-n;if(i===0)return null;if(r.charCodeAt(n)===35){const f=i-1;if(f!==3&&f!==4&&f!==6&&f!==8)return null;const p=[];for(let g=0;g<f;g++){const u=Wl(r.charCodeAt(n+1+g));if(u<0)return null;p.push(u)}return f<=4?un(p[0]*17,p[1]*17,p[2]*17,f===4?p[3]*17:255):un(p[0]*16+p[1],p[2]*16+p[3],p[4]*16+p[5],f===8?p[6]*16+p[7]:255)}const l=r.indexOf("(",n);if(l>=0&&l<s&&r.charCodeAt(s-1)===41){const f=Xl(r,l+1,s-1);if(!f)return null;const p=f.length===4?tr(f[3].percent?Te(f[3].v/100):f[3].v):1,g=l-n;if(jt(r,n,g,"rgb")||jt(r,n,g,"rgba")){const u=v=>tr(v.percent?Te(v.v/100):Te(v.v/255));return{r:u(f[0]),g:u(f[1]),b:u(f[2]),a:p}}if(jt(r,n,g,"hsl")||jt(r,n,g,"hsla")){let u=f[0].v%360;u<0&&(u=Te(u+360)),u=Te(u/360);const v=tr(Te(f[1].v/100)),M=tr(Te(f[2].v/100));if(v<=0)return{r:M,g:M,b:M,a:p};const d=M<.5?Te(M*Te(1+v)):Te(Te(M+v)-Te(M*v)),y=Te(Te(2*M)-d);return{r:tr(cn(y,d,Te(u+Rs))),g:tr(cn(y,d,u)),b:tr(cn(y,d,Te(u-Rs))),a:p}}return null}if(i>20)return null;let a="";for(let f=n;f<s;f++)a+=String.fromCharCode(qr(r.charCodeAt(f)));if(!Object.prototype.hasOwnProperty.call(Ts,a))return null;const c=Ts[a];return un(c>>>24,c>>>16&255,c>>>8&255,c&255)},qt=t=>{const e=Te(t);if(!(e>0))return 0;if(e>=1)return 255;const r=Te(e*255);return Math.floor(Te(r+.5))},hn=Math.fround,ql=t=>{if(typeof t=="number")return!Number.isInteger(t)||t<0||t>16777215?null:[hn((t>>16&255)/255),hn((t>>8&255)/255),hn((t&255)/255),1];if(typeof t=="object"&&t!==null&&typeof t.length=="number"){const e=t;if(e.length!==3&&e.length!==4)return null;for(let n=0;n<e.length;n++)if(typeof e[n]!="number"||!Number.isFinite(e[n]))return null;const r=e;return[r[0],r[1],r[2],e.length===4?r[3]:1]}return null},yi=t=>{if(typeof t=="string"){const e=jl(t);return e?[e.r,e.g,e.b,e.a]:null}return ql(t)},fn=t=>typeof t=="string"?JSON.stringify(t):typeof t=="number"&&Number.isInteger(t)&&t>=0?`0x${t.toString(16)} (${t})`:Array.isArray(t)?`[${t.join(", ")}]`:String(t),Yl=t=>{throw typeof t=="number"?new RangeError(`Color: ${fn(t)} is not a color — a number is an opaque 0xRRGGBB (an integer 0..0xFFFFFF); write alpha as "#rrggbbaa" or [r, g, b, a]`):typeof t=="string"?new TypeError(`Color: ${fn(t)} is not a CSS color`):new TypeError(`Color: ${fn(t)} is not a color — a string, an 0xRRGGBB number or [r, g, b(, a)] in 0..1`)},$r=t=>yi(t)??Yl(t),Bs=t=>{const e=$r(t);return[qt(e[0]),qt(e[1]),qt(e[2]),qt(e[3])]},kr=t=>(t<16?"0":"")+t.toString(16),Kl=t=>"#"+kr(qt(t[0]))+kr(qt(t[1]))+kr(qt(t[2]))+kr(qt(t[3])),Ql={toRgb01(t){const e=$r(t);return[e[0],e[1],e[2]]},toRgba01(t){return $r(t)},toPackedRgb(t){const e=Bs(t);return e[0]<<16|e[1]<<8|e[2]},toPackedRgba(t){const e=Bs(t);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0},toHexString(t){return Kl($r(t))},tryParse(t){return yi(t)}},Zl=.0025,Ns=1,Os=.85,Jl=.13,ec=.1,tc=5,rc=8,Is=15*Math.PI/180,nc=[[.93,.16,.12],[.42,.9,.16],[.16,.35,1]],sc=[.85,.85,.88],Us=t=>[t[0]*.5+.5,t[1]*.5+.5,t[2]*.5+.5],Ds=[.941,.396,.243],ic=[.36,.92,.48],oc=.85,et=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],yr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],xr=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],st=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Cn=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],gr=t=>Math.hypot(t[0],t[1],t[2]),wr=t=>{const e=gr(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},dr=(t,e,r,n)=>{const s=st(e,n);if(Math.abs(s)<1e-6)return null;const i=st(et(r,t),n)/s;return i<=0?null:yr(t,xr(e,i))},zs=(t,e,r,n,s)=>{const i=et(t,r),l=st(n,e),a=st(n,i),c=st(e,i),f=1-l*l,p=Math.abs(f)<1e-8?a:(a-l*c)/f,g=Math.max(0,Math.min(s,p)),u=yr(r,xr(n,g)),v=Math.max(0,st(et(u,t),e));return{dist:gr(et(u,yr(t,xr(e,v)))),t:g}},ac=(t,e,r)=>{const n=Cn(wr(et(t,r)),e),s=Cn(e,n);return st(s,s)<1e-4?wr(et(t,r)):wr(s)},lc=(t,e)=>{const[r,n,s]=t,i=Math.cos(e),l=Math.sin(e),a=1-i,c=new Float32Array(16);return c[0]=a*r*r+i,c[1]=a*r*n+l*s,c[2]=a*r*s-l*n,c[4]=a*r*n-l*s,c[5]=a*n*n+i,c[6]=a*n*s+l*r,c[8]=a*r*s+l*n,c[9]=a*n*s-l*r,c[10]=a*s*s+i,c[15]=1,c},cc=t=>{const e=Math.hypot(t[0],t[1],t[2])||1,r=Math.hypot(t[4],t[5],t[6])||1,n=Math.hypot(t[8],t[9],t[10])||1,s=t[0]/e,i=t[1]/e,l=t[2]/e,a=t[4]/r,c=t[5]/r,f=t[6]/r,p=t[8]/n,g=t[9]/n,u=t[10]/n,v=s+c+u;let M,d,y,x;if(v>0){const T=.5/Math.sqrt(v+1);x=.25/T,M=(f-g)*T,d=(p-l)*T,y=(i-a)*T}else if(s>c&&s>u){const T=2*Math.sqrt(1+s-c-u);x=(f-g)/T,M=.25*T,d=(a+i)/T,y=(p+l)/T}else if(c>u){const T=2*Math.sqrt(1+c-s-u);x=(p-l)/T,M=(a+i)/T,d=.25*T,y=(g+f)/T}else{const T=2*Math.sqrt(1+u-s-c);x=(i-a)/T,M=(p+l)/T,d=(g+f)/T,y=.25*T}return{position:[t[12],t[13],t[14]],quaternion:[M,d,y,x],scale:[e,r,n]}},uc=`#version 300 es
808
- precision highp float;
809
- in vec3 position;
810
- in vec3 normal;
811
- uniform mat4 modelViewMatrix;
812
- uniform mat4 projectionMatrix;
813
- uniform mat3 normalMatrix;
814
- out vec3 vN;
815
- void main() {
816
- vN = normalize(normalMatrix * normal);
817
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
818
- }
819
- `,hc=`#version 300 es
820
- precision highp float;
821
- in vec3 vN;
822
- uniform vec3 uColor;
823
- out vec4 fragColor;
824
- void main() { fragColor = vec4(uColor * (0.72 + 0.28 * abs(vN.z)), 1.0); }
825
- `,fc=`#version 300 es
826
- precision highp float;
827
- in vec3 position;
828
- uniform mat4 modelMatrix;
829
- uniform mat4 modelViewMatrix;
830
- uniform mat4 projectionMatrix;
831
- out vec3 vWorld;
832
- void main() {
833
- vWorld = (modelMatrix * vec4(position, 1.0)).xyz;
834
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
835
- }
836
- `,dc=`#version 300 es
837
- precision highp float;
838
- in vec3 vWorld;
839
- uniform vec3 uColor;
840
- uniform vec3 uOrigin;
841
- uniform vec3 uEye;
842
- uniform float uFull;
843
- out vec4 fragColor;
844
- void main() {
845
- if (uFull < 0.5 && dot(vWorld - uOrigin, uOrigin - uEye) > 0.0) discard;
846
- fragColor = vec4(uColor, 1.0);
847
- }
848
- `,dn=`#version 300 es
849
- precision highp float;
850
- in vec3 position;
851
- uniform mat4 modelViewMatrix;
852
- uniform mat4 projectionMatrix;
853
- void main() { gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }
854
- `,mn=`#version 300 es
855
- precision highp float;
856
- uniform vec3 uColor;
857
- uniform float uAlpha;
858
- out vec4 fragColor;
859
- void main() { fragColor = vec4(uColor * uAlpha, uAlpha); }
860
- `,mc=`#version 300 es
861
- in vec2 position;
862
- in vec2 uv;
863
- out vec2 vUv;
864
- void main() { vUv = uv; gl_Position = vec4(position, 0.0, 1.0); }
865
- `,pc=`#version 300 es
866
- precision highp float;
867
- in vec2 vUv;
868
- uniform sampler2D tMask;
869
- uniform vec2 uTexel;
870
- uniform vec3 uColor;
871
- out vec4 fragColor;
872
- void main() {
873
- float center = texture(tMask, vUv).r;
874
- float edge = 0.0;
875
- for (int x = -2; x <= 2; x++) {
876
- for (int y = -2; y <= 2; y++) {
877
- edge = max(edge, texture(tMask, vUv + vec2(float(x), float(y)) * uTexel).r);
878
- }
879
- }
880
- float a = clamp(edge - center, 0.0, 1.0);
881
- if (a < 0.02) discard;
882
- fragColor = vec4(uColor * a, a);
883
- }
884
- `,gc=t=>{const{gl:e,renderer:r,canvas:n,camera:s,core:i}=t;let l={},a=!1,c=null,f=null,p="global";const g=.1,u=.22,v=[],M=new gt;{const re=[];for(let Z=-10;Z<=10;Z++)Z!==0&&re.push(Z,0,-10,Z,0,10,-10,0,Z,10,0,Z);const X=(Z,ae)=>{const oe=new ze(e,{vertex:dn,fragment:mn,uniforms:{uColor:{value:[1,1,1]},uAlpha:{value:ae}},transparent:!0});oe.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),v.push(oe);const ue=new ct(e,{position:{size:3,data:Float32Array.from(Z)}}),le=new nt(e,{geometry:ue,program:oe,mode:e.LINES});return le.frustumCulled=!1,le};M.addChild(X(re,g)),M.addChild(X([-10,.001,0,10,.001,0,0,.001,-10,0,.001,10],u))}let d=-1;const y=$=>{const X=.2126*($[0]??0)+.7152*($[1]??0)+.0722*($[2]??0)>.5?0:1;if(X!==d){d=X;for(const Z of v)Z.uniforms.uColor.value=[X,X,X]}},x=new ze(e,{vertex:uc,fragment:hc,uniforms:{uColor:{value:[1,1,1]}}}),T=new ze(e,{vertex:fc,fragment:dc,uniforms:{uColor:{value:[1,1,1]},uOrigin:{value:[0,0,0]},uEye:{value:[0,0,0]},uFull:{value:0}}});let P=null,L=null;const _=new gt;_.matrixAutoUpdate=!1;const o=($,re,X=x)=>($._axis=re,$.frustumCulled=!1,$.onBeforeRender(()=>{const Z=L?L.axis:P,ae=re===3?sc:nc[re];X.uniforms.uColor.value=Z===re?Us(ae):ae}),$),h=($,re)=>{const X=new gt;return re===0?X.rotation.z=-Math.PI/2:re===2&&(X.rotation.x=Math.PI/2),X.setParent($),X},m=new gt,w=new gt,E=new gt;for(const $ of[m,w,E])$.setParent(_);{const $=new is(e,{radiusTop:.014,radiusBottom:.014,height:.78,radialSegments:6}),re=new is(e,{radiusTop:.001,radiusBottom:.065,height:.26,radialSegments:12}),X=new ss(e,{width:.1,height:.1,depth:.1}),Z=new ss(e,{width:.14,height:.14,depth:.14}),ae=new Aa(e,{radius:Os,tube:.02,radialSegments:8,tubularSegments:64});for(let oe=0;oe<3;oe++){const ue=h(m,oe),le=o(new nt(e,{geometry:$,program:x}),oe);le.position.y=.39;const me=o(new nt(e,{geometry:re,program:x}),oe);me.position.y=.87,ue.addChild(le),ue.addChild(me);const be=h(E,oe),Ee=o(new nt(e,{geometry:$,program:x}),oe);Ee.position.y=.39;const xe=o(new nt(e,{geometry:X,program:x}),oe);xe.position.y=.83,be.addChild(Ee),be.addChild(xe);const Se=o(new nt(e,{geometry:ae,program:T}),oe,T);oe===0?Se.rotation.y=Math.PI/2:oe===1&&(Se.rotation.x=Math.PI/2),w.addChild(Se)}E.addChild(o(new nt(e,{geometry:Z,program:x}),3))}const B=()=>{if(c===null||f===null||!i.entities.has(c))return null;const $=i.activeSceneId(),re=i.scenes.get($);if(!re||re.camera===void 0)return null;const X=i.worldMatrixF(c),Z=[X[12],X[13],X[14]],oe=p==="local"||f==="scale"?[0,1,2].map(be=>wr([X[be*4],X[be*4+1],X[be*4+2]])):[[1,0,0],[0,1,0],[0,0,1]],ue=i.worldMatrixF(re.camera),le=[ue[12],ue[13],ue[14]],me=gr(et(Z,le))||1;return{origin:Z,axes:oe,scale:me*Zl*i.projectionOf($).fov,camPos:le,sceneId:$}},W=()=>{const $=B();if(!$)return!1;const re=_.matrix;for(let Z=0;Z<3;Z++)re[Z]=$.axes[0][Z]*$.scale,re[4+Z]=$.axes[1][Z]*$.scale,re[8+Z]=$.axes[2][Z]*$.scale,re[12+Z]=$.origin[Z];re[3]=0,re[7]=0,re[11]=0,re[15]=1,_.worldMatrixNeedsUpdate=!0,m.visible=f==="translate",w.visible=f==="rotate",E.visible=f==="scale";const X=T.uniforms;X.uOrigin.value=$.origin,X.uEye.value=$.camPos,X.uFull.value=L&&f==="rotate"?1:0;for(const Z of[m,w,E])Z.traverse(ae=>{ae._axis!==void 0&&(ae.visible=L===null||ae._axis===L.axis)});return!0},N=($,re)=>{const X=B();if(!X)return null;const{origin:Z,dir:ae}=t.getViewRay(X.sceneId,$,re),oe=ec*X.scale;if(f==="rotate"){const me=wr(et(X.origin,X.camPos));let be=null,Ee=1/0;for(let xe=0;xe<3;xe++){const Se=dr(Z,ae,X.origin,X.axes[xe]);if(!Se||st(et(Se,X.origin),me)>0)continue;const Ue=Math.abs(gr(et(Se,X.origin))-Os*X.scale),Re=gr(et(Se,Z));Ue<oe&&Re<Ee&&(be=xe,Ee=Re)}return be}if(f==="scale"){const{dist:me}=zs(Z,ae,X.origin,wr(ae),0);if(me<Jl*X.scale)return 3}let ue=null,le=oe;for(let me=0;me<3;me++){const{dist:be}=zs(Z,ae,X.origin,X.axes[me],(Ns+.05)*X.scale);be<=le&&(le=be,ue=me)}return ue},I=$=>{const re=n.getBoundingClientRect(),X=In(n);return[($.clientX-re.left)/X,($.clientY-re.top)/X]},D=($,re)=>{const X=B();if(!X||c===null)return!1;const Z=c,ae=i.ent(Z),oe=Float32Array.from(ae.m),ue=ae.parent!==0?i.worldMatrixF(ae.parent):Xe(),le=Lt(Float32Array.from(ue)),me=At(new Float32Array(16),ue,oe),[be]=I(re);let Ee=null;if($===3)Ee=Le=>{const[ke]=I(Le),Ze=Math.max(.01,1+(ke-be)/150),Ke=Float32Array.from(oe);for(let it=0;it<3;it++)for(let We=0;We<3;We++)Ke[it*4+We]*=Ze;i.methods.setMatrix(Z,Ke)};else if(f==="rotate"){const Le=X.axes[$],{origin:ke,dir:Ze}=t.getViewRay(X.sceneId,...I(re)),Ke=dr(ke,Ze,X.origin,Le);if(!Ke)return!1;const it=et(Ke,X.origin);Ee=We=>{const vt=t.getViewRay(X.sceneId,...I(We)),ht=dr(vt.origin,vt.dir,X.origin,Le);if(!ht)return;const tt=et(ht,X.origin);let rt=Math.atan2(st(Cn(it,tt),Le),st(it,tt));We.ctrlKey&&(rt=Math.round(rt/Is)*Is);const $e=lc(Le,rt),Je=[0,0,0];Pt(Je,$e,X.origin[0],X.origin[1],X.origin[2],1),$e[12]=X.origin[0]-Je[0],$e[13]=X.origin[1]-Je[1],$e[14]=X.origin[2]-Je[2];const Dt=At(new Float32Array(16),$e,me),zt=ae.parent!==0?At(new Float32Array(16),le,Dt):Dt;i.methods.setMatrix(Z,zt)}}else{const Le=X.axes[$],ke=ac(X.origin,Le,X.camPos),{origin:Ze,dir:Ke}=t.getViewRay(X.sceneId,...I(re)),it=dr(Ze,Ke,X.origin,ke);if(!it)return!1;if(f==="translate"){const We=[me[12],me[13],me[14]];Ee=vt=>{const ht=t.getViewRay(X.sceneId,...I(vt)),tt=dr(ht.origin,ht.dir,X.origin,ke);if(!tt)return;const rt=st(et(tt,it),Le),$e=yr(We,xr(Le,rt)),Je=[0,0,0];ae.parent!==0?Pt(Je,le,$e[0],$e[1],$e[2],1):(Je[0]=$e[0],Je[1]=$e[1],Je[2]=$e[2]),i.methods.setPosition(Z,Je[0],Je[1],Je[2])}}else Ee=We=>{const vt=t.getViewRay(X.sceneId,...I(We)),ht=dr(vt.origin,vt.dir,X.origin,ke);if(!ht)return;const tt=Math.max(.01,1+st(et(ht,it),Le)/(Ns*X.scale)),rt=Float32Array.from(oe);for(let $e=0;$e<3;$e++)rt[$*4+$e]*=tt;i.methods.setMatrix(Z,rt)}}if(!Ee)return!1;const xe=n.ownerDocument.defaultView??window,Se=re.pointerId,Ue=Le=>{Le.pointerId===Se&&(L==null||L.onMove(Le))},Re=Le=>{var Ze;if(!L)return;const ke=L;L=null,ke.cleanup(),Le?(Ze=l.onTransformEnd)==null||Ze.call(l,Z,cc(i.ent(Z).m),f):i.methods.setMatrix(Z,ke.startLocal)},Ie=Le=>{Le.pointerId===Se&&Re(!0)},De=()=>Re(!1),Ne=Le=>{Le.code==="Escape"&&Re(!1)};return xe.addEventListener("pointermove",Ue),xe.addEventListener("pointerup",Ie),xe.addEventListener("pointercancel",De),xe.addEventListener("keydown",Ne),L={axis:$,startLocal:oe,onMove:Ee,cleanup:()=>{xe.removeEventListener("pointermove",Ue),xe.removeEventListener("pointerup",Ie),xe.removeEventListener("pointercancel",De),xe.removeEventListener("keydown",Ne)}},!0},K=new Pa,q=($,re)=>{var Ee,xe;const X=i.activeSceneId(),Z=t.sceneRoots.get(X),ae=i.scenes.get(X);if(!Z||!ae||ae.camera===void 0)return 0;const{origin:oe,dir:ue}=t.getViewRay(X,$,re);K.origin.set(oe[0],oe[1],oe[2]),K.direction.set(ue[0],ue[1],ue[2]);const le=[],me=[];for(const Se of t.collectMeshes(Z)){const Ue=(xe=(Ee=Se.geometry)==null?void 0:Ee.attributes)==null?void 0:xe.position;if(!(Ue!=null&&Ue.data))continue;const Re=Ue.stride&&Ue.stride!==Ue.size*Ue.data.BYTES_PER_ELEMENT;Se.mode===e.TRIANGLES&&!Re?le.push(Se):me.push(Se)}Z.updateMatrixWorld();let be=null;try{for(const Se of K.intersectMeshes(le,{cullFace:!1,includeUV:!1,includeNormal:!1,output:[]}))(!be||Se.hit.distance<be.hit.distance)&&(be=Se)}catch{}try{for(const Se of K.intersectBounds(me,{output:[]}))(!be||Se.hit.distance<be.hit.distance)&&(be=Se)}catch{}return(be==null?void 0:be._entId)??0};let O=null;const H=$=>{if($.button!==0||$.shiftKey||L)return;const[re,X]=I($),Z=N(re,X);if(Z!==null&&D(Z,$)){$.preventDefault(),$.stopPropagation(),O=null;return}O={pointerId:$.pointerId,x:$.clientX,y:$.clientY}},G=$=>{var ae;const re=O;if(O=null,!re||re.pointerId!==$.pointerId||Math.abs($.clientX-re.x)+Math.abs($.clientY-re.y)>tc)return;const[X,Z]=I($);(ae=l.onPick)==null||ae.call(l,Me(X,Z)||q(X,Z))},Y=$=>{if(L)return;const[re,X]=I($),Z=f!==null&&c!==null?N(re,X):null,ae=Z===null&&A.length>0&&Me(re,X)||null;(Z!==P||ae!==R)&&(P=Z,R=ae,n.style.cursor=Z!==null||ae!==null?"pointer":"")};n.addEventListener("pointerdown",H),n.addEventListener("pointerup",G),n.addEventListener("pointermove",Y);const se=new ze(e,{vertex:dn,fragment:mn,uniforms:{uColor:{value:ic},uAlpha:{value:oc}},transparent:!0,depthTest:!1,depthWrite:!1});se.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const te=$=>new ct(e,{position:{size:3,data:Float32Array.from($)}}),ne=($,re,X,Z,ae=32)=>{for(let oe=0;oe<ae;oe++)for(const ue of[Math.PI*2*oe/ae,Math.PI*2*(oe+1)/ae]){const le=Math.cos(ue)*re,me=Math.sin(ue)*re;Z===1?$.push(le,X,me):Z===0?$.push(X,le,me):$.push(le,me,X)}},he=te((()=>{const $=[],re=X=>[X&1?1:-1,X&2?1:-1,X&4?1:-1];for(let X=0;X<8;X++)for(const Z of[1,2,4])X&Z||$.push(...re(X),...re(X|Z));return $})()),we=te((()=>{const $=[];return ne($,1,0,0),ne($,1,0,1),ne($,1,0,2),$})()),de=new Map,Ve=($,re,X)=>{const Z=`${$}:${re}:${X}`;let ae=de.get(Z);if(ae)return ae;const oe=[];ne(oe,X,re,1),ne(oe,X,-re,1);for(const[ue,le]of[[X,0],[-X,0],[0,X],[0,-X]])oe.push(ue,-re,le,ue,re,le);if($==="capsule")for(const le of[!0,!1])for(const me of[0,2])for(let be=0;be<12;be++)for(const Ee of[Math.PI*be/12,Math.PI*(be+1)/12]){const xe=Math.cos(Ee)*X,Se=(le?re:-re)+Math.sin(Ee)*X*(le?1:-1);me===0?oe.push(xe,Se,0):oe.push(0,Se,xe)}return ae=te(oe),de.size>64&&de.clear(),de.set(Z,ae),ae},je=new gt,S=[],A=[];let R=null;const z=[.81,.83,.87,1],Q=$=>{var re,X;for(const Z of S)Z.setParent(null),(X=(re=Z.geometry).remove)==null||X.call(re);S.length=0,A.length=0,R=null;for(const Z of Array.isArray($)?$:[]){if(!Z||!Array.isArray(Z.segments)||Z.segments.length<6)continue;const[ae,oe,ue,le]=Ql.tryParse(Z.color)??z,me=[ae,oe,ue],be=Math.max(0,Math.min(1,Number(Z.alpha??1)*le)),Ee=new ze(e,{vertex:dn,fragment:mn,uniforms:{uColor:{value:me.slice()},uAlpha:{value:be}},transparent:!0,depthTest:!1,depthWrite:!1});Ee.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const xe=Math.floor(Z.segments.length/6)*6,Se=Float32Array.from(Z.segments.slice(0,xe)),Ue=new ct(e,{position:{size:3,data:Se}}),Re=new nt(e,{geometry:Ue,program:Ee,mode:e.LINES});Re.frustumCulled=!1,Re.setParent(je),S.push(Re);const Ie=Number(Z.entityId??0);Ie>0&&(Re.matrixAutoUpdate=!1,A.push({entityId:Ie,mesh:Re,program:Ee,color:me,segments:Se}))}},J=()=>{for(const $ of A){if(!i.entities.has($.entityId)){$.mesh.visible=!1;continue}$.mesh.visible=!0,$.mesh.matrix.copy(Pe($.entityId)),$.mesh.worldMatrixNeedsUpdate=!0;const re=$.entityId===c?Ds:$.entityId===R?Us($.color):$.color,X=$.program.uniforms.uColor.value;X[0]=re[0],X[1]=re[1],X[2]=re[2]}},Me=($,re)=>{if(A.length===0)return 0;const X=i.activeSceneId(),Z=i.scenes.get(X);if(!Z||Z.camera===void 0)return 0;const{origin:ae,dir:oe}=t.getViewRay(X,$,re),ue=n.getBoundingClientRect(),le=Math.max(1,ue.height/In(n)),me=2*Math.tan(i.projectionOf(X).fov*Math.PI/360)*rc/le;let be=0,Ee=1,xe=1/0;const Se=[0,0,0],Ue=[0,0,0];for(const Re of A){if(!i.entities.has(Re.entityId))continue;const Ie=Pe(Re.entityId),De=Re.segments;for(let Ne=0;Ne+5<De.length;Ne+=6){for(let ft=0;ft<3;ft++)Se[ft]=Ie[ft]*De[Ne]+Ie[4+ft]*De[Ne+1]+Ie[8+ft]*De[Ne+2]+Ie[12+ft],Ue[ft]=Ie[ft]*De[Ne+3]+Ie[4+ft]*De[Ne+4]+Ie[8+ft]*De[Ne+5]+Ie[12+ft];const Le=et(Ue,Se),ke=et(Se,ae),Ze=st(oe,oe),Ke=st(oe,Le),it=st(Le,Le),We=st(oe,ke),vt=st(Le,ke),ht=Ze*it-Ke*Ke;let tt=ht>1e-12?(Ke*We-Ze*vt)/ht:0;tt=Math.max(0,Math.min(1,tt));const rt=Math.max(0,(We+tt*Ke)/(Ze||1)),$e=yr(Se,xr(Le,tt)),Je=yr(ae,xr(oe,rt));if(rt<=1e-6)continue;const Dt=rt*me,zt=gr(et($e,Je))/Dt;zt>1||(zt<Ee-.001||Math.abs(zt-Ee)<=.001&&rt<xe)&&(be=Re.entityId,Ee=zt,xe=rt)}}return be};let ve=[];const Be=new gt,Oe=[],Fe=[1,1,1],Pe=$=>{const re=Float32Array.from(i.worldMatrix($));for(let X=0;X<3;X++){const Z=Math.hypot(re[X*4],re[X*4+1],re[X*4+2])||1;Fe[X]=Z,re[X*4]/=Z,re[X*4+1]/=Z,re[X*4+2]/=Z}return re},qe=($,re,X,Z,ae=0,oe=0,ue=0)=>{const le=Float32Array.from($);le[12]=$[12]+$[0]*ae+$[4]*oe+$[8]*ue,le[13]=$[13]+$[1]*ae+$[5]*oe+$[9]*ue,le[14]=$[14]+$[2]*ae+$[6]*oe+$[10]*ue;for(let me=0;me<3;me++)le[me]*=re,le[4+me]*=X,le[8+me]*=Z;return le},wt=($,re)=>{const X=i.entities.get($);if(X){for(const Z of t.drawablesOf($))Z.mode===e.TRIANGLES&&re.push(Z);for(const Z of X.children)wt(Z,re)}},Mt=new Map,Bt=$=>{const re=new Map,X=[],Z=(ue,le,me)=>{const be=`${ue.toFixed(5)},${le.toFixed(5)},${me.toFixed(5)}`;let Ee=re.get(be);return Ee===void 0&&(Ee=X.length/3,re.set(be,Ee),X.push(ue,le,me)),Ee},ae=new Set;for(let ue=0;ue+8<$.length;ue+=9){const le=Z($[ue],$[ue+1],$[ue+2]),me=Z($[ue+3],$[ue+4],$[ue+5]),be=Z($[ue+6],$[ue+7],$[ue+8]);for(const[Ee,xe]of[[le,me],[me,be],[be,le]])ae.add(Ee<xe?Ee*65536+xe:xe*65536+Ee)}const oe=[];for(const ue of ae){const le=Math.floor(ue/65536)*3,me=ue%65536*3;oe.push(X[le],X[le+1],X[le+2],X[me],X[me+1],X[me+2])}return new ct(e,{position:{size:3,data:Float32Array.from(oe)}})},Ut=$=>{var be,Ee;const re=[];wt($,re);const X=Pe($),Z=re.map(xe=>{var Se;return((Se=xe.geometry)==null?void 0:Se.id)??"?"}).join(",")+"|"+Fe.map(xe=>xe.toFixed(4)).join(","),ae=Mt.get($);if(ae&&ae.key===Z)return ae.geometry;const oe=Lt(X),ue=[];for(const xe of re){const Se=(Ee=(be=xe.geometry)==null?void 0:be.attributes)==null?void 0:Ee.position,Ue=Se==null?void 0:Se.data;if(!(Ue instanceof Float32Array)||Se.size!==3||Se.stride)continue;const Re=At(new Float32Array(16),oe,xe.worldMatrix);for(let Ie=0;Ie+2<Ue.length;Ie+=3){const De=Ue[Ie],Ne=Ue[Ie+1],Le=Ue[Ie+2];ue.push(Re[0]*De+Re[4]*Ne+Re[8]*Le+Re[12],Re[1]*De+Re[5]*Ne+Re[9]*Le+Re[13],Re[2]*De+Re[6]*Ne+Re[10]*Le+Re[14])}}const le=ue.length>=12?zl(ue):null,me=le?Bt(le):null;return Mt.set($,{key:Z,geometry:me}),me},Kt=()=>{var re,X,Z;for(const ae of Oe)ae.setParent(null);Oe.length=0;const $=(ae,oe)=>{const ue=new nt(e,{geometry:ae,program:se,mode:e.LINES});ue.frustumCulled=!1,ue.matrixAutoUpdate=!1,ue.matrix.copy(oe),ue.setParent(Be),Oe.push(ue)};for(const ae of ve){if(!i.entities.has(ae.entityId))continue;const oe=ae.shape,ue=ae.origin,[le,me,be]=ue??[0,0,0];if(oe.kind==="box")$(he,qe(Pe(ae.entityId),oe.half[0],oe.half[1],oe.half[2],le,me,be));else if(oe.kind==="sphere")$(we,qe(Pe(ae.entityId),oe.radius,oe.radius,oe.radius,le,me,be));else if(oe.kind==="cylinder"||oe.kind==="capsule")$(Ve(oe.kind,oe.halfHeight,oe.radius),qe(Pe(ae.entityId),1,1,1,le,me,be));else if(oe.kind==="mesh"&&oe.convex&&Ut(ae.entityId))$(Ut(ae.entityId),qe(Pe(ae.entityId),1,1,1,le,me,be));else if(oe.kind==="mesh"){const Ee=[];wt(ae.entityId,Ee);const xe=Pe(ae.entityId),Se=xe[0]*le+xe[4]*me+xe[8]*be,Ue=xe[1]*le+xe[5]*me+xe[9]*be,Re=xe[2]*le+xe[6]*me+xe[10]*be;for(const Ie of Ee){if(!((X=(re=Ie.geometry)==null?void 0:re.attributes)!=null&&X.position))continue;const De=Float32Array.from(Ie.worldMatrix);De[12]+=Se,De[13]+=Ue,De[14]+=Re,$(t.wireGeometryFor(Ie.geometry),De)}}else{const Ee=t.drawablesOf(ae.entityId).find(it=>it.mode===e.TRIANGLES);let xe=.5,Se=.5,Ue=.5,Re=0,Ie=0,De=0;const Ne=(Z=Ee==null?void 0:Ee.geometry)==null?void 0:Z.bounds;Ne&&isFinite(Ne.min.x)&&(xe=(Ne.max.x-Ne.min.x)/2,Se=(Ne.max.y-Ne.min.y)/2,Ue=(Ne.max.z-Ne.min.z)/2,Re=(Ne.max.x+Ne.min.x)/2,Ie=(Ne.max.y+Ne.min.y)/2,De=(Ne.max.z+Ne.min.z)/2);const Le=Pe(ae.entityId),[ke,Ze,Ke]=Fe;$(he,ue?qe(Le,xe*ke,Se*Ze,Ue*Ke,le,me,be):qe(Le,xe*ke,Se*Ze,Ue*Ke,Re*ke,Ie*Ze,De*Ke))}}return Oe.length>0},Ct=new ze(e,{vertex:Rr(!1),fragment:Pr,uniforms:{modelMatrix:{value:Xe()},shadowViewProjection:{value:Xe()}},depthTest:!1,depthWrite:!1,cullFace:!1}),bt=new ze(e,{vertex:Rr(!0),fragment:Pr,uniforms:{modelMatrix:{value:Xe()},shadowViewProjection:{value:Xe()},boneTexture:{value:null},boneTextureSize:{value:4}},depthTest:!1,depthWrite:!1,cullFace:!1});let Ye=null;const ut=new ze(e,{vertex:mc,fragment:pc,uniforms:{tMask:{value:null},uTexel:{value:[0,0]},uColor:{value:Ds}},depthTest:!1,depthWrite:!1,transparent:!0});ut.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const Nt=new nt(e,{geometry:new oi(e),program:ut}),Ar=($,re)=>{const X=i.entities.get($);if(!(!X||!X.visible)){re.push(...t.drawablesOf($));for(const Z of X.children)Ar(Z,re)}},Ur=()=>{if(c===null||!i.entities.has(c))return;const $=[];if(Ar(c,$),$.length===0)return;(!Ye||Ye.width!==n.width||Ye.height!==n.height)&&(Ye=new ii(e,{width:Math.max(1,n.width),height:Math.max(1,n.height)}));const re=At(new Float32Array(16),s.projectionMatrix,s.viewMatrix);Ct.uniforms.shadowViewProjection.value=re,bt.uniforms.shadowViewProjection.value=re,r.bindFramebuffer(Ye),r.setViewport(Ye.width,Ye.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);const X=Xe();for(const Z of $){const ae=Z instanceof Rt,oe=ae?bt:Ct;oe.uniforms.modelMatrix.value=ae?X:Z.worldMatrix;const ue=Z.program;Z.program=oe,Z.draw({}),Z.program=ue}r.bindFramebuffer({buffer:null}),r.setViewport(n.width,n.height),ut.uniforms.tMask.value=Ye.texture,ut.uniforms.uTexel.value=[1/Ye.width,1/Ye.height],Nt.draw({})},Dr=$=>{a&&(y($),r.render({scene:M,camera:s,clear:!1,frustumCull:!1,sort:!1}))},Qt=()=>{Ur(),ve.length>0&&Kt()&&r.render({scene:Be,camera:s,clear:!1,frustumCull:!1,sort:!1}),S.length>0&&(J(),r.render({scene:je,camera:s,clear:!1,frustumCull:!1,sort:!1})),W()&&(r.setDepthMask(!0),e.clear(e.DEPTH_BUFFER_BIT),r.render({scene:_,camera:s,clear:!1,frustumCull:!1,sort:!1}))};let Sr=null;const _t=new Tn(e,{fov:60,near:.01,far:1e3,aspect:1});return _t.matrixAutoUpdate=!1,{api:{setGrid($){a=$===!0},setSelection($){L&&$!==c&&(L.cleanup(),L=null),c=$&&$>0?$:null},setGizmoMode($){f=$==="translate"||$==="rotate"||$==="scale"?$:null,P=null},setGizmoSpace($){p=$==="local"?"local":"global"},setColliders($){ve=Array.isArray($)?$.slice():[]},setGizmos:Q,setPreview($){Sr=$&&$.entityId>0?$:null},pickAt($,re){return q($,re)}},setHandlers($){l=$??{}},renderScenePass:Dr,renderOverlayPass:Qt,renderPreviewPass:($,re)=>{const X=Sr;if(!X)return;const Z=n.width/(n.getBoundingClientRect().width||n.width),ae=Math.round(X.rect[0]*Z),oe=Math.round(X.rect[1]*Z),ue=Math.round(X.rect[2]*Z),le=Math.round(X.rect[3]*Z);if(ue<2||le<2)return;const me=i.worldMatrixF(X.entityId);if(!me)return;for(let xe=0;xe<16;xe++)_t.matrix[xe]=me[xe];_t.worldMatrixNeedsUpdate=!0,_t.perspective({fov:X.fov,aspect:ue/le,near:X.near,far:X.far}),_t.updateMatrixWorld();const be=[];for(const xe of X.hide??[])for(const Se of t.drawablesOf(xe))Se.visible&&(Se.visible=!1,be.push(Se));const Ee=n.height-oe-le;r.bindFramebuffer({buffer:null}),r.setViewport(ue,le,ae,Ee),e.enable(e.SCISSOR_TEST),e.scissor(ae,Ee,ue,le),e.clearColor(re[0]??0,re[1]??0,re[2]??0,1),r.enable(e.DEPTH_TEST),r.setDepthMask(!0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),t.renderScene($,_t,be.length>0),e.disable(e.SCISSOR_TEST);for(const xe of be)xe.visible=!0;r.setViewport(n.width,n.height)},dispose:()=>{L==null||L.cleanup(),L=null,n.removeEventListener("pointerdown",H),n.removeEventListener("pointerup",G),n.removeEventListener("pointermove",Y),n.style.cursor=""}}},vc={value:0},mr=16,yc=600,xc=t=>Math.sqrt(Math.max(t[0]*t[0]+t[1]*t[1]+t[2]*t[2],t[4]*t[4]+t[5]*t[5]+t[6]*t[6],t[8]*t[8]+t[9]*t[9]+t[10]*t[10])),wc=t=>t[0]*(t[5]*t[10]-t[6]*t[9])-t[1]*(t[4]*t[10]-t[6]*t[8])+t[2]*(t[4]*t[9]-t[5]*t[8]),Mc=(t,e)=>{const r=new Map,n=[],s=[],i=[];let l=-1;const a=new Float32Array(16);let c=!0,f=!0;const p=new Map;let g=0;const u=O=>{const H=p.get(O);if(H!==void 0)return H;let G=null;const Y=t.getShaderSource(O.vertexShader),se=t.getShaderSource(O.fragmentShader);if(Y&&se&&Y.startsWith("#version")){const te=Y.replace(/^([^\n]*\n)/,`$1#define INSTANCED
885
- `),ne=new ze(t,{vertex:te,fragment:se,uniforms:O.uniforms,transparent:O.transparent,cullFace:O.cullFace,frontFace:O.frontFace,depthTest:O.depthTest,depthWrite:O.depthWrite,depthFunc:O.depthFunc});let he=!1;ne.attributeLocations.forEach((we,de)=>{de.name==="instanceMatrix"&&(he=!0)}),he&&t.getProgramParameter(ne.program,t.LINK_STATUS)?G=ne:ne.remove()}return p.set(O,G),G},v=(O,H)=>{O.transparent=H.transparent,O.cullFace=H.cullFace,O.frontFace=H.frontFace,O.depthTest=H.depthTest,O.depthWrite=H.depthWrite,O.depthFunc=H.depthFunc,O.blendFunc=H.blendFunc,O.blendEquation=H.blendEquation},M=(O,H)=>{const G={};for(const[se,te]of Object.entries(O.attributes))G[se]={size:te.size,data:te.data,type:te.type,normalized:te.normalized,stride:te.stride,offset:te.offset,buffer:te.buffer,count:te.count};G.instanceMatrix={instanced:1,size:16,data:new Float32Array(H*16),usage:t.DYNAMIC_DRAW};const Y=new ct(t,G);return Y.drawRange.start=O.drawRange.start,Y.drawRange.count=O.drawRange.count,Y},d=O=>{for(const G of Object.values(O.VAOs))e.deleteVertexArray(G);O.VAOs={};const H=O.attributes.instanceMatrix;H!=null&&H.buffer&&(t.deleteBuffer(H.buffer),H.buffer=null),e.currentGeometry=null},y=(O,H)=>{const G=O.attributes.instanceMatrix;let Y=Math.max(mr,G.count);for(;Y<H;)Y*=2;const se=new Float32Array(Y*16);return se.set(G.data),d(O),O.instancedCount=0,O.addAttribute("instanceMatrix",{instanced:1,size:16,data:se,usage:t.DYNAMIC_DRAW}),se},x=(O,H,G)=>{const Y=O.attributes.instanceMatrix;G>0&&(t.bindBuffer(t.ARRAY_BUFFER,Y.buffer),e.state.boundBuffer=Y.buffer,t.bufferSubData(t.ARRAY_BUFFER,0,H,0,G*16)),O.setInstancedCount(G)},T=(O,H,G)=>{const Y=O.program,se=O._castShadows!==!1,te=O._receiveShadows!==!1,ne=`${O.geometry.id}|${Y.id}|${O.mode}|${O.renderOrder}|${se?1:0}${te?1:0}${G?1:0}`;let he=r.get(ne);if(!he){const we=O.geometry;he={key:ne,source:we,program:Y,twin:H,mode:O.mode,renderOrder:O.renderOrder,castShadows:se,receiveShadows:te,flip:G,all:new Float32Array(mr*16),allCount:0,allDirty:!0,geoAll:M(we,mr),sph:new Float32Array(mr*4),vis:new Float32Array(mr*16),visCount:0,visDirty:!0,geoVis:M(we,mr),bounds:new Float32Array(6),lastUsed:g},r.set(ne,he)}return he},P=O=>{var G,Y;if(!f||O instanceof Rt||O._particles||O.mode===t.POINTS)return null;const H=O.program;return H.transparent||!H.depthTest||!((Y=(G=O.geometry)==null?void 0:G.attributes)!=null&&Y.position)||O.geometry.isInstanced||H.uniforms.uMorphTex?null:u(H)},L=O=>{const H=O.geometry;return(!H.bounds||H.bounds.radius===1/0)&&H.computeBoundingSphere(),H.bounds&&isFinite(H.bounds.radius)?H.bounds:null},_=(O,H,G,Y,se)=>{const te=O.frustum;for(let ne=0;ne<6;ne++){const he=te[ne];if(he[0]*H+he[1]*G+he[2]*Y+he.constant<-se)return!1}return!0},o=(O,H,G)=>{const Y=H*16;let se=!1;for(let te=0;te<16;te++){const ne=G[te];O[Y+te]!==ne&&(O[Y+te]=ne,se=!0)}return se},h=O=>{const H=O.source;H.bounds||H.computeBoundingBox();const G=O.bounds;if(G[0]=G[1]=G[2]=1/0,G[3]=G[4]=G[5]=-1/0,!H.bounds||!isFinite(H.bounds.min.x))return;const{min:Y,max:se}=H.bounds,te=[0,0,0];for(let ne=0;ne<O.allCount;ne++){const he=O.all.subarray(ne*16,ne*16+16);for(let we=0;we<8;we++){Pt(te,he,we&1?se.x:Y.x,we&2?se.y:Y.y,we&4?se.z:Y.z,1);for(let de=0;de<3;de++)te[de]<G[de]&&(G[de]=te[de]),te[de]>G[de+3]&&(G[de+3]=te[de])}}},m=[0,0,0],w=O=>{g++,s.length=0,i.length=0;for(const H of r.values())H.allCount=0;O.traverse(H=>{if(!H.visible)return!0;if(!H.draw)return!1;const G=H.worldMatrix,Y=P(H);if(!Y)return s.push(H),H._castShadows!==!1&&i.push(H),!1;const se=!!H.program.cullFace&&wc(G)<0,te=T(H,Y,se);te.lastUsed=g;const ne=te.allCount;if(ne*16>=te.all.length){te.all=y(te.geoAll,ne+1);const de=new Float32Array(te.all.length/4);de.set(te.sph),te.sph=de}o(te.all,ne,G)&&(te.allDirty=!0);const he=L(H),we=ne*4;return he&&H.frustumCulled?(Pt(m,G,he.center.x,he.center.y,he.center.z,1),te.sph[we]=m[0],te.sph[we+1]=m[1],te.sph[we+2]=m[2],te.sph[we+3]=he.radius*xc(G)):te.sph[we+3]=-1,te.allCount++,!1});for(const[H,G]of r)G.allCount!==G.geoAll.instancedCount&&(G.allDirty=!0),G.allDirty&&(x(G.geoAll,G.all,G.allCount),h(G),G.allDirty=!1),G.allCount===0&&g-G.lastUsed>yc&&(d(G.geoAll),d(G.geoVis),r.delete(H))},E=(O,H)=>{O.updateFrustum();for(const G of r.values()){G.visCount=0;const Y=G.allCount;for(let se=0;se<Y;se++){const te=se*4;if(H&&G.sph[te+3]>=0&&!_(O,G.sph[te],G.sph[te+1],G.sph[te+2],G.sph[te+3]))continue;const ne=G.visCount;ne*16>=G.vis.length&&(G.vis=y(G.geoVis,ne+1));const he=se*16,we=ne*16;for(let de=0;de<16;de++){const Ve=G.all[he+de];G.vis[we+de]!==Ve&&(G.vis[we+de]=Ve,G.visDirty=!0)}G.visCount++}G.visCount!==G.geoVis.instancedCount&&(G.visDirty=!0),G.visDirty&&(x(G.geoVis,G.vis,G.visCount),G.visDirty=!1)}n.length=0;for(const G of s)H&&G.frustumCulled&&!O.frustumIntersectsMesh(G)||n.push(G)},B=(O,H,G,Y=-2,se=!1)=>{const te=se||Y!==l;te&&(w(O),l=Y),H.updateMatrixWorld();const ne=H.projectionViewMatrix;let he=G!==c;for(let we=0;we<16&&!he;we++)a[we]!==ne[we]&&(he=!0);if(!(!te&&!he)){E(H,G);for(let we=0;we<16;we++)a[we]=ne[we];c=G}},W=()=>[...r.values()].sort((O,H)=>O.renderOrder-H.renderOrder);return{collect:B,drawMain:(O,H)=>{for(const ne of W()){if(ne.visCount===0)continue;const he=ne.twin.uniforms;(he.projectionMatrix??(he.projectionMatrix={value:null})).value=O.projectionMatrix,(he.viewMatrix??(he.viewMatrix={value:null})).value=O.viewMatrix,(he.cameraPosition??(he.cameraPosition={value:null})).value=O.worldPosition;const we=he.shadowEnabled;we&&(he.shadowEnabled=ne.receiveShadows?H:vc),v(ne.twin,ne.program),ne.twin.use({flipFaces:ne.flip}),ne.geoVis.draw({mode:ne.mode,program:ne.twin}),we&&(he.shadowEnabled=we)}const G=[],Y=[],se=[],te=O.projectionViewMatrix;for(const ne of n){if(ne.program.transparent?ne.program.depthTest?Y.push(ne):se.push(ne):G.push(ne),ne.zDepth=0,ne.renderOrder!==0||!ne.program.depthTest)continue;const he=ne.worldMatrix,we=he[12],de=he[13],Ve=he[14],je=te[3]*we+te[7]*de+te[11]*Ve+te[15]||1;ne.zDepth=(te[2]*we+te[6]*de+te[10]*Ve+te[14])/je}G.sort(e.sortOpaque),Y.sort(e.sortTransparent),se.sort(e.sortUI);for(const ne of G)ne.draw({camera:O});for(const ne of Y)ne.draw({camera:O});for(const ne of se)ne.draw({camera:O})},drawShadow:O=>{for(const H of r.values())!H.castShadows||H.allCount===0||(O.use({flipFaces:H.flip}),H.geoAll.draw({mode:H.mode,program:O}))},casterBounds:(O,H)=>{for(const G of r.values())if(!(!G.castShadows||G.allCount===0||!isFinite(G.bounds[0])))for(let Y=0;Y<3;Y++)G.bounds[Y]<O[Y]&&(O[Y]=G.bounds[Y]),G.bounds[Y+3]>H[Y]&&(H[Y]=G.bounds[Y+3])},isBatched:O=>P(O)!==null,dispose:()=>{for(const O of r.values())d(O.geoAll),d(O.geoVis);r.clear();for(const O of p.values())O==null||O.remove();p.clear()},setEnabled:O=>{f=O,l=-1},singles:n,casterSingles:i,stats:()=>{let O=0,H=0,G=0;for(const Y of r.values())Y.allCount>0&&(G++,O+=Y.allCount,H+=Y.visCount);return{batches:G,instances:O,visible:H,singles:n.length}}}},xi=(t,e,r,n,s=0,i=0)=>{t.viewport(s,i,r,n);const l=e.state.viewport,a=s===0&&i===0;l.x=s,l.y=i,l.width=a?r:null,l.height=a?n:null},Br=(t,e,r)=>{e.bindFramebuffer({buffer:r.buffer}),xi(t,e,r.width,r.height,r.x,r.y)},bc=t=>t.getExtension("EXT_color_buffer_float")!==null,Ac=(t,e)=>{const r=t.getInternalformatParameter(t.RENDERBUFFER,t.RGBA16F,t.SAMPLES);let n=0;for(const s of r??[])s<=e&&s>n&&(n=s);return n},wi=(t,e,r)=>{const n=new Qe(t,{width:e,height:r,internalFormat:t.RGBA16F,format:t.RGBA,type:t.HALF_FLOAT,generateMipmaps:!1,minFilter:t.LINEAR,magFilter:t.LINEAR,wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,flipY:!1});return n.update(),n},Mi=(t,e,r)=>{const n=t.createFramebuffer();return e.bindFramebuffer({buffer:n}),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r.texture,0),n},Sc=(t,e,r,n,s)=>{const i=wi(t,r,n),l=Mi(t,e,i),a=[],c=(u,v)=>{const M=t.createRenderbuffer();a.push(M),t.bindRenderbuffer(t.RENDERBUFFER,M),s>0?t.renderbufferStorageMultisample(t.RENDERBUFFER,s,v,r,n):t.renderbufferStorage(t.RENDERBUFFER,v,r,n),t.framebufferRenderbuffer(t.FRAMEBUFFER,u,t.RENDERBUFFER,M)};let f=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE,p=l;s>0&&(p=t.createFramebuffer(),e.bindFramebuffer({buffer:p}),c(t.COLOR_ATTACHMENT0,t.RGBA16F)),c(t.DEPTH_ATTACHMENT,t.DEPTH_COMPONENT24),f&&(f=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE),t.bindRenderbuffer(t.RENDERBUFFER,null),e.bindFramebuffer({buffer:null});const g=()=>{p!==l&&t.deleteFramebuffer(p),t.deleteFramebuffer(l);for(const u of a)t.deleteRenderbuffer(u);t.deleteTexture(i.texture)};return f?{width:r,height:n,samples:s,texture:i,bindDraw:()=>e.bindFramebuffer({buffer:p}),resolve:()=>{p!==l&&(t.bindFramebuffer(t.READ_FRAMEBUFFER,p),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,l),t.blitFramebuffer(0,0,r,n,0,0,r,n,t.COLOR_BUFFER_BIT,t.NEAREST),t.bindFramebuffer(t.FRAMEBUFFER,null),e.state.framebuffer=null)},dispose:g}:(g(),null)},_c=`#version 300 es
886
- out vec2 vUv;
887
- void main() {
888
- // one triangle over the target: (0,0) (2,0) (0,2) in uv
889
- vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
890
- vUv = p;
891
- gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
892
- }`,Ec=`#version 300 es
893
- precision mediump float;
894
- uniform sampler2D uCamera;
895
- in vec2 vUv;
896
- out vec4 color;
897
- void main() { color = vec4(texture(uCamera, vUv).rgb, 1.0); }`,Cc=`#version 300 es
898
- precision highp float;
899
- uniform sampler2D uCamera;
900
- uniform vec2 uStep;
901
- in vec2 vUv;
902
- out vec4 color;
903
- void main() {
904
- vec2 uv = vec2(vUv.x, 1.0 - vUv.y);
905
- vec3 c = texture(uCamera, uv + vec2(-uStep.x, -uStep.y)).rgb + texture(uCamera, uv + vec2(uStep.x, -uStep.y)).rgb
906
- + texture(uCamera, uv + vec2(-uStep.x, uStep.y)).rgb + texture(uCamera, uv + vec2(uStep.x, uStep.y)).rgb;
907
- float y = dot(c * 0.25, vec3(0.299, 0.587, 0.114));
908
- color = vec4(y, y, y, 1.0);
909
- }`,Gs=30,Vs=t=>({...t,data:t.data.slice(),projection:t.projection.slice(),viewMatrix:t.viewMatrix.slice()}),Fc=t=>{const{gl:e,renderer:r}=t;let n=null,s=!1,i=null,l=null,a=null,c=[],f=null,p=!0,g=!1;const u=new Set,v=(I,D)=>{u.has(I)||(u.add(I),console.warn(`[viewer-lite] ${D}`))},M=(I,D)=>{const K=(Y,se)=>{const te=e.createShader(Y);return e.shaderSource(te,se),e.compileShader(te),te},q=K(e.VERTEX_SHADER,_c),O=K(e.FRAGMENT_SHADER,I),H=e.createProgram();if(e.attachShader(H,q),e.attachShader(H,O),e.linkProgram(H),e.deleteShader(q),e.deleteShader(O),!e.getProgramParameter(H,e.LINK_STATUS)){const Y=e.getProgramInfoLog(H);throw e.deleteProgram(H),new Error(`the camera's blit did not link: ${Y}`)}const G=e.createSampler();return e.samplerParameteri(G,e.TEXTURE_MIN_FILTER,D),e.samplerParameteri(G,e.TEXTURE_MAG_FILTER,D),e.samplerParameteri(G,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.samplerParameteri(G,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),{program:H,sampler:G,location:e.getUniformLocation(H,"uCamera"),step:e.getUniformLocation(H,"uStep")}},d=()=>i??(i=M(Ec,e.NEAREST)),y=()=>l??(l=M(Cc,e.LINEAR)),x=(I,D)=>{r.disable(e.DEPTH_TEST),r.disable(e.BLEND),r.disable(e.CULL_FACE),e.useProgram(I.program),r.activeTexture(0),e.bindTexture(e.TEXTURE_2D,D),e.bindSampler(0,I.sampler),e.uniform1i(I.location,0),e.bindVertexArray(null),e.drawArrays(e.TRIANGLES,0,3)},T=()=>{e.bindSampler(0,null),e.bindTexture(e.TEXTURE_2D,null),r.state.textureUnits[0]=-1,r.state.currentProgram=null,r.currentGeometry=null,r.bindFramebuffer({buffer:null})},P=()=>{a&&(e.deleteFramebuffer(a.fbo),e.deleteTexture(a.texture),a=null)},L=(I,D)=>{if(a&&a.width===I&&a.height===D)return Br(e,r,{buffer:a.fbo,x:0,y:0,width:I,height:D}),a;P();const K=e.createTexture();r.activeTexture(0),e.bindTexture(e.TEXTURE_2D,K),e.texStorage2D(e.TEXTURE_2D,1,e.R8,I,D),e.bindTexture(e.TEXTURE_2D,null),r.state.textureUnits[0]=-1;const q=e.createFramebuffer();Br(e,r,{buffer:q,x:0,y:0,width:I,height:D}),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,K,0);const O=e.getParameter(e.IMPLEMENTATION_COLOR_READ_FORMAT)===e.RED&&e.getParameter(e.IMPLEMENTATION_COLOR_READ_TYPE)===e.UNSIGNED_BYTE;return a={texture:K,fbo:q,width:I,height:D,red:O,scratch:O?null:new Uint8Array(I*D*4)},a},_=(I,D,K,q)=>{const O=Math.max(1,Math.round(K*q/D)),H=y(),G=L(q,O);e.useProgram(H.program);const Y=D/q>=1.5;return e.uniform2f(H.step,Y?.25/q:0,Y?.25/O:0),x(H,I),G},o=I=>{const{width:D,height:K}=I,q=new Uint8Array(D*K);if(I.red)e.pixelStorei(e.PACK_ALIGNMENT,1),e.readPixels(0,0,D,K,e.RED,e.UNSIGNED_BYTE,q),e.pixelStorei(e.PACK_ALIGNMENT,4);else{const O=I.scratch;e.readPixels(0,0,D,K,e.RGBA,e.UNSIGNED_BYTE,O);for(let H=0,G=D*K;H<G;H++)q[H]=O[H*4]}return q},h=I=>{const D=c.find(O=>!O.busy&&O.bytes===I);if(D)return D;const K=e.createBuffer();if(!K)throw new Error("no pack buffer was made");e.bindBuffer(e.PIXEL_PACK_BUFFER,K),e.bufferData(e.PIXEL_PACK_BUFFER,I,e.STREAM_READ),e.bindBuffer(e.PIXEL_PACK_BUFFER,null);const q={buffer:K,bytes:I,busy:!1};return c.push(q),q},m=()=>{for(const I of c)e.deleteBuffer(I.buffer);c=[],f=null},w=I=>{const{width:D,height:K,red:q}=I,O=h(q?D*K:D*K*4);if(g||e.getError(),e.bindBuffer(e.PIXEL_PACK_BUFFER,O.buffer),q&&e.pixelStorei(e.PACK_ALIGNMENT,1),e.readPixels(0,0,D,K,q?e.RED:e.RGBA,e.UNSIGNED_BYTE,0),q&&e.pixelStorei(e.PACK_ALIGNMENT,4),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),!g){const G=e.getError();if(G!==e.NO_ERROR)throw new Error(`readPixels into a pack buffer gave GL error 0x${G.toString(16)}`);g=!0}const H=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);if(!H)throw new Error("no fence was made");return e.flush(),O.busy=!0,{pack:O,sync:H}},E=I=>{const{width:D,height:K}=I,q=new Uint8Array(D*K);e.bindBuffer(e.PIXEL_PACK_BUFFER,I.pack.buffer);try{if(I.red)e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,q);else{(!f||f.length!==I.pack.bytes)&&(f=new Uint8Array(I.pack.bytes)),e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,f);for(let O=0,H=D*K;O<H;O++)q[O]=f[O*4]}}finally{e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}return q},B=I=>{p&&(p=!1,console.warn(`[viewer-lite] ${I}: the camera's gray picture is read at once from now on (the frame waits for it)`))},W=(I,D,K)=>{const q=d(),O=e.createTexture();e.bindTexture(e.TEXTURE_2D,O),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8,D,K);const H=e.createFramebuffer();Br(e,r,{buffer:H,x:0,y:0,width:D,height:K}),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,O,0),x(q,I);const G=new Uint8Array(D*K*4);e.readPixels(0,0,D,K,e.RGBA,e.UNSIGNED_BYTE,G),T(),e.deleteFramebuffer(H),e.deleteTexture(O);const Y=D*4,se=new Uint8Array(G.length);for(let te=0;te<K;te++)se.set(G.subarray((K-1-te)*Y,(K-te)*Y),te*Y);return{rgba:se,width:D,height:K}};return{present:async(I,D,K,q)=>{if(n||s)throw new Error("[viewer-lite] an XR session is presented already: end that presentation first");s=!0;try{await e.makeXRCompatible();const A=new XRWebGLLayer(I,e,{alpha:!0,antialias:!1});I.updateRenderState({baseLayer:A,depthNear:t.near,depthFar:t.far})}finally{s=!1}let O=0,H=null,G=[],Y=[],se=0;const te=(A,R,z,Q)=>{const J=new Float32Array(Q.projectionMatrix),Me=new Float32Array(Q.transform.matrix);try{const ve=_(A,R.width,R.height,z);if(p)try{const{pack:Be,sync:Oe}=w(ve),Fe={pack:Be,sync:Oe,width:ve.width,height:ve.height,red:ve.red,projection:J,viewMatrix:Me,frames:0,takers:[]};return Y.push(Fe),Fe}catch(Be){e.bindBuffer(e.PIXEL_PACK_BUFFER,null),B(`the camera's picture cannot be read without a stall (${Be instanceof Error?Be.message:Be})`)}return{data:o(ve),width:ve.width,height:ve.height,projection:J,viewMatrix:Me}}finally{T()}},ne=(A,R)=>{A.pack.busy=!1,A.takers.forEach((z,Q)=>z(R&&Q>0?Vs(R):R))},he=()=>{if(Y.length===0)return;const A=Y;Y=[];for(const R of A){let z=!1;try{z=e.getSyncParameter(R.sync,e.SYNC_STATUS)===e.SIGNALED}catch{}if(!z&&++R.frames<Gs){Y.push(R);continue}z||B(`a camera read's fence did not signal in ${Gs} frames`),e.deleteSync(R.sync);let Q=null;try{Q={data:E(R),width:R.width,height:R.height,projection:R.projection,viewMatrix:R.viewMatrix}}catch(J){t.failed("the XR camera image",J),B(`a camera read could not be taken back (${J instanceof Error?J.message:J})`)}ne(R,Q)}},we=A=>{var Be;if(G.length===0)return;const R=G;G=[];let z=null;const Q=A?A.camera:void 0;if(A&&!Q&&v("camera-access",'the XR session has no camera access (the "camera-access" feature was not granted): no camera picture'),A&&Q)try{H??(H=new XRWebGLBinding(I,e)),z=((Be=H.getCameraImage)==null?void 0:Be.call(H,Q))??null,z||v("camera-image","the XR session gave no camera image")}catch(Oe){t.failed("the XR camera image",Oe)}let J;const Me=new Map,ve=new Set;for(const Oe of R){if(!z||!A||!Q){Oe.resolve(null);continue}try{if(Oe.gray){const Fe=Math.max(1,Math.min(Q.width,Math.floor(Oe.maxWidth)));let Pe=Me.get(Fe);if(Pe||(Pe=te(z,Q,Fe,A),Me.set(Fe,Pe)),"takers"in Pe)Pe.takers.push(Oe.resolve);else{const qe=!ve.has(Pe);ve.add(Pe),Oe.resolve(qe?Pe:Vs(Pe))}}else{J??(J=W(z,Q.width,Q.height));const Fe=!ve.has(J);ve.add(J),Oe.resolve(Fe?J:{...J,rgba:J.rgba.slice()})}}catch(Fe){t.failed("the XR camera image",Fe),Oe.resolve(null)}}},de=(A,R)=>{var Oe;if(n!==S)return;O=I.requestAnimationFrame(de),he(),t.begin();let z=null;try{z=R.getViewerPose(D)??null}catch(Fe){t.failed("the XR viewer pose",Fe)}const Q=(z==null?void 0:z.views[0])??null;z&&z.views.length>1&&z.views.length!==se&&(se=z.views.length,v("views",`an XR session of ${se} views: the lite engine draws the first (a phone's)`));const J=I.renderState,Me=Q!==null&&t.view(q,Q.transform.matrix,Q.projectionMatrix,J.depthNear??t.near,J.depthFar??t.far);try{K(A,R,z)}catch(Fe){t.failed("the XR frame body",Fe)}we(Q);const ve=Me&&Q?(Oe=J.baseLayer)==null?void 0:Oe.getViewport(Q):void 0,Be=J.baseLayer;t.draw(ve&&Be?{buffer:Be.framebuffer,x:ve.x,y:ve.y,width:ve.width,height:ve.height}:null)},Ve=()=>{if(n!==S)return;n=null,I.removeEventListener("end",Ve);try{I.cancelAnimationFrame(O)}catch{}H=null;const A=G;G=[];for(const z of A)z.resolve(null);const R=Y;Y=[];for(const z of R){try{e.deleteSync(z.sync)}catch{}ne(z,null)}P(),m(),t.presenting(!1)};function je(A){return n!==S?Promise.resolve(null):new Promise(R=>{G.push(A!=null&&A.gray?{gray:!0,maxWidth:A.maxWidth??1/0,resolve:R}:{gray:!1,resolve:R})})}const S={session:I,end:Ve,captureCamera:je};return n=S,I.addEventListener("end",Ve),t.presenting(!0),O=I.requestAnimationFrame(de),S},active:()=>n!==null,end:()=>{n==null||n.end()}}},Hs=384,Tc=12,Rc=(t,e,r,n)=>{const s=Hs,i=Hs*t/Math.max(1,e),l=Math.max(1,Math.trunc(Math.max(i,s))),a=Math.floor(Math.log2(l))+1,c=Math.max(1,Math.min(Math.floor(r)||1,a,Tc)),f=[];if(n<2){let p=t,g=e;for(;2*i<p||2*s<g;)p=Math.max(1,Math.floor(p/2)),g=Math.max(1,Math.floor(g/2)),f.push({width:p,height:g})}return{width:Math.max(1,Math.floor(i)),height:Math.max(1,Math.floor(s)),levels:c,preDownscales:f}},Pc=(t,e,r)=>({width:Math.max(1,t>>r),height:Math.max(1,e>>r)}),Lc=`#version 300 es
910
- in vec2 position;
911
- in vec2 uv;
912
- out vec2 vUv;
913
- void main() {
914
- vUv = uv;
915
- gl_Position = vec4(position, 0.0, 1.0);
916
- }
917
- `,Yr=`#version 300 es
918
- precision highp float;
919
- precision highp sampler2D;
920
- in vec2 vUv;
921
- uniform sampler2D source;
922
- out vec4 fragColor;
923
- `,Bc=`${Yr}
924
- uniform float uThreshold;
925
- uniform float uFireflies;
926
- uniform float uInvHighlight;
927
-
928
- float max3(const vec3 v) { return max(v.x, max(v.y, v.z)); }
929
-
930
- void threshold(inout vec3 c) {
931
- // threshold everything below 1.0
932
- c = max(vec3(0.0), c - 1.0);
933
- // crush everything above 1
934
- float f = max3(c);
935
- c *= 1.0 / (1.0 + f * uInvHighlight);
936
- }
937
-
938
- void main() {
939
- vec2 size = vec2(textureSize(source, 0));
940
- vec2 texelSize = vec2(1.0) / size;
941
-
942
- // Castaño, 2013, "Shadow Mapping Summary Part 1"
943
- // 3x3 gaussian filter with 4 linear samples
944
- vec2 offset = vec2(0.5);
945
- vec2 uv = (vUv * size) + offset;
946
- vec2 base = (floor(uv) - offset) * texelSize;
947
- vec2 st = fract(uv);
948
- vec2 uw = vec2(3.0 - 2.0 * st.x, 1.0 + 2.0 * st.x);
949
- vec2 vw = vec2(3.0 - 2.0 * st.y, 1.0 + 2.0 * st.y);
950
- vec2 u = vec2((2.0 - st.x) / uw.x - 1.0, st.x / uw.y + 1.0) * texelSize.x;
951
- vec2 v = vec2((2.0 - st.y) / vw.x - 1.0, st.y / vw.y + 1.0) * texelSize.y;
952
- vec3 c0 = textureLod(source, base + vec2(u.x, v.x), 0.0).rgb;
953
- vec3 c1 = textureLod(source, base + vec2(u.y, v.x), 0.0).rgb;
954
- vec3 c2 = textureLod(source, base + vec2(u.x, v.y), 0.0).rgb;
955
- vec3 c3 = textureLod(source, base + vec2(u.y, v.y), 0.0).rgb;
956
-
957
- float w0 = uw.x * vw.x * (1.0 / 16.0);
958
- float w1 = uw.y * vw.x * (1.0 / 16.0);
959
- float w2 = uw.x * vw.y * (1.0 / 16.0);
960
- float w3 = uw.y * vw.y * (1.0 / 16.0);
961
-
962
- if (uFireflies > 0.0) {
963
- w0 /= (1.0 + max3(c0));
964
- w1 /= (1.0 + max3(c1));
965
- w2 /= (1.0 + max3(c2));
966
- w3 /= (1.0 + max3(c3));
967
- float w = 1.0 / (w0 + w1 + w2 + w3);
968
- w0 *= w;
969
- w1 *= w;
970
- w2 *= w;
971
- w3 *= w;
972
- }
973
-
974
- vec3 c = c0 * w0 + c1 * w1 + c2 * w2 + c3 * w3;
975
-
976
- if (uThreshold > 0.0) {
977
- threshold(c);
978
- }
979
-
980
- fragColor = vec4(c, 1.0);
981
- }
982
- `,Nc=`${Yr}
983
- vec3 box4x4(vec3 s0, vec3 s1, vec3 s2, vec3 s3) {
984
- return (s0 + s1 + s2 + s3) * 0.25;
985
- }
986
-
987
- void main() {
988
- vec2 uv = vUv;
989
-
990
- // see SIGGRAPH 2014: Advances in Real-Time Rendering
991
- // "Next Generation Post-Processing in Call of Duty Advanced Warfare"
992
- // Jorge Jimenez
993
- vec3 c = textureLod(source, uv, 0.0).rgb;
994
-
995
- // The offsets below are in "source" texture space
996
- vec3 lt = textureLodOffset(source, uv, 0.0, ivec2(-1, -1)).rgb;
997
- vec3 rt = textureLodOffset(source, uv, 0.0, ivec2( 1, -1)).rgb;
998
- vec3 rb = textureLodOffset(source, uv, 0.0, ivec2( 1, 1)).rgb;
999
- vec3 lb = textureLodOffset(source, uv, 0.0, ivec2(-1, 1)).rgb;
1000
-
1001
- vec3 lt2 = textureLodOffset(source, uv, 0.0, ivec2(-2, -2)).rgb;
1002
- vec3 rt2 = textureLodOffset(source, uv, 0.0, ivec2( 2, -2)).rgb;
1003
- vec3 rb2 = textureLodOffset(source, uv, 0.0, ivec2( 2, 2)).rgb;
1004
- vec3 lb2 = textureLodOffset(source, uv, 0.0, ivec2(-2, 2)).rgb;
1005
-
1006
- vec3 l = textureLodOffset(source, uv, 0.0, ivec2(-2, 0)).rgb;
1007
- vec3 t = textureLodOffset(source, uv, 0.0, ivec2( 0, -2)).rgb;
1008
- vec3 r = textureLodOffset(source, uv, 0.0, ivec2( 2, 0)).rgb;
1009
- vec3 b = textureLodOffset(source, uv, 0.0, ivec2( 0, 2)).rgb;
1010
-
1011
- // five h4x4 boxes
1012
- vec3 c0, c1;
1013
-
1014
- // common case
1015
- c0 = box4x4(lt, rt, rb, lb);
1016
- c1 = box4x4(c, l, t, lt2);
1017
- c1 += box4x4(c, r, t, rt2);
1018
- c1 += box4x4(c, r, b, rb2);
1019
- c1 += box4x4(c, l, b, lb2);
1020
-
1021
- // weighted average of the five boxes
1022
- fragColor = vec4(c0 * 0.5 + c1 * 0.125, 1.0);
1023
- }
1024
- `,Oc=`${Yr}
1025
- void main() {
1026
- vec2 uv = vUv;
1027
- vec2 size = vec2(1.0) / vec2(textureSize(source, 0));
1028
-
1029
- float o = 1.5 + 0.261629;
1030
- float wa = 7.46602 / 32.0;
1031
- float wb = 1.0 - wa * 2.0;
1032
- float wab = wa * wb;
1033
- float waa = wa * wa;
1034
- float wbb = wb * wb;
1035
-
1036
- size *= o;
1037
-
1038
- vec3 c = textureLod(source, uv + vec2(0.0) , 0.0).rgb;
1039
- vec3 l = textureLod(source, uv + vec2(-size.x, 0.0), 0.0).rgb;
1040
- vec3 r = textureLod(source, uv + vec2( size.x, 0.0), 0.0).rgb;
1041
- vec3 b = textureLod(source, uv + vec2( 0.0,-size.y), 0.0).rgb;
1042
- vec3 t = textureLod(source, uv + vec2( 0.0, size.y), 0.0).rgb;
1043
- vec3 lb = textureLod(source, uv + vec2(-size.x,-size.y), 0.0).rgb;
1044
- vec3 rb = textureLod(source, uv + vec2( size.x,-size.y), 0.0).rgb;
1045
- vec3 lt = textureLod(source, uv + vec2(-size.x, size.y), 0.0).rgb;
1046
- vec3 rt = textureLod(source, uv + vec2( size.x, size.y), 0.0).rgb;
1047
-
1048
- fragColor = vec4(
1049
- (c * wbb +
1050
- (l * wab +
1051
- (r * wab +
1052
- (b * wab +
1053
- (t * wab +
1054
- (lb * waa +
1055
- (rb * waa +
1056
- (lt * waa +
1057
- (rt * waa))))))))), 1.0);
1058
- }
1059
- `,ks=t=>`${Yr}
1060
- uniform vec4 resolution;
1061
- void main() {
1062
- vec2 uv = vUv;
1063
- ${t?`
1064
- // see SIGGRAPH 2014: Advances in Real-Time Rendering
1065
- // "Next Generation Post-Processing in Call of Duty Advanced Warfare"
1066
- // Jorge Jimenez
1067
- const float radius = 1.0;
1068
- vec4 d = vec4(resolution.zw, -resolution.zw) * radius;
1069
- vec3 c0, c1;
1070
- c0 = textureLod(source, uv + d.zw, 0.0).rgb;
1071
- c0 += textureLod(source, uv + d.xw, 0.0).rgb;
1072
- c0 += textureLod(source, uv + d.xy, 0.0).rgb;
1073
- c0 += textureLod(source, uv + d.zy, 0.0).rgb;
1074
- c0 += 4.0 * textureLod(source, uv, 0.0).rgb;
1075
- c1 = textureLod(source, uv + vec2(d.z, 0.0), 0.0).rgb;
1076
- c1 += textureLod(source, uv + vec2(0.0, d.w), 0.0).rgb;
1077
- c1 += textureLod(source, uv + vec2(d.x, 0.0), 0.0).rgb;
1078
- c1 += textureLod(source, uv + vec2( 0.0, d.y), 0.0).rgb;
1079
- fragColor = vec4((c0 + 2.0 * c1) * (1.0 / 16.0), 1.0);
1080
- `:`
1081
- vec4 d = vec4(resolution.zw, -resolution.zw) * 0.5;
1082
- vec3 c;
1083
- c = textureLod(source, uv + d.zw, 0.0).rgb;
1084
- c += textureLod(source, uv + d.xw, 0.0).rgb;
1085
- c += textureLod(source, uv + d.xy, 0.0).rgb;
1086
- c += textureLod(source, uv + d.zy, 0.0).rgb;
1087
- fragColor = vec4(c * 0.25, 1.0);
1088
- `}
1089
- }
1090
- `,Ic=`#version 300 es
1091
- precision highp float;
1092
- precision highp sampler2D;
1093
- in vec2 vUv;
1094
- uniform sampler2D uColor;
1095
- uniform sampler2D uBloom;
1096
- uniform float uBloomStrength;
1097
- out vec4 fragColor;
1098
- ${hi}
1099
- void main() {
1100
- vec4 color = texelFetch(uColor, ivec2(gl_FragCoord.xy), 0);
1101
- vec3 hdr = color.rgb + textureLod(uBloom, vUv, 0.0).rgb * uBloomStrength;
1102
- fragColor = vec4(acesFilmicSrgb(hdr), color.a);
1103
- }
1104
- `,Uc=(t,e)=>{const r=new oi(t),n=(_,o,h=!1)=>{const m=new ze(t,{vertex:Lc,fragment:_,uniforms:o,transparent:h,depthTest:!1,depthWrite:!1,cullFace:!1});return h&&m.setBlendFunc(t.ONE,t.ONE),m},s=n(Bc,{source:{value:null},uThreshold:{value:0},uFireflies:{value:0},uInvHighlight:{value:0}}),i=n(Nc,{source:{value:null}}),l=n(Oc,{source:{value:null}}),a=[0,0,0,0],c=n(ks(!1),{source:{value:null},resolution:{value:a}},!0),f=n(ks(!0),{source:{value:null},resolution:{value:a}},!0),p=n(Ic,{uColor:{value:null},uBloom:{value:null},uBloomStrength:{value:0}});let g=[],u=[],v="";const M=({width:_,height:o})=>{const h=wi(t,_,o);return{width:_,height:o,texture:h,fbo:Mi(t,e,h)}},d=()=>{for(const _ of[...g,...u])t.deleteFramebuffer(_.fbo),t.deleteTexture(_.texture.texture);g=[],u=[],v=""},y=_=>{const o=`${_.width}x${_.height}/${_.levels}/${_.preDownscales.map(h=>`${h.width}x${h.height}`).join(",")}`;if(o!==v){d(),g=_.preDownscales.map(M);for(let h=0;h<_.levels;h++)u.push(M(Pc(_.width,_.height,h)));v=o,e.bindFramebuffer({buffer:null})}},x=(_,o)=>{e.bindFramebuffer({buffer:o.fbo}),e.setViewport(o.width,o.height),_.use(),r.draw({program:_})};return{run:(_,o,h,m)=>{const w=Rc(o,h,m.levels,m.quality);y(w);let E=m.threshold;const B=Number.isFinite(m.highlight)&&m.highlight>0?1/m.highlight:0;let W=_;const N=D=>{const K=s.uniforms;K.source.value=W,K.uThreshold.value=K.uFireflies.value=E?1:0,K.uInvHighlight.value=B,x(s,D),E=!1,W=D.texture};for(const D of g)N(D);N(u[0]);for(let D=1;D<w.levels;D++){const K=u[D-1],q=K.width&1||K.height&1?i:l;q.uniforms.source.value=K.texture,x(q,u[D])}const I=m.quality>=2?f:c;for(let D=w.levels-1;D>=1;D--){const K=u[D-1];I.uniforms.source.value=u[D].texture,a[0]=K.width,a[1]=K.height,a[2]=1/K.width,a[3]=1/K.height,x(I,K)}return{texture:u[0].texture,levels:w.levels}},compose:(_,o,h,m)=>{Br(t,e,m);const w=p.uniforms;w.uColor.value=_,w.uBloom.value=o,w.uBloomStrength.value=h,p.use(),r.draw({program:p})},dispose:()=>{d();for(const _ of[s,i,l,c,f,p])_.remove();r.remove()}}},Dc=1179937895,zc=1313821514,Gc=t=>{var e,r;try{if(t.byteLength<20)return null;const n=new DataView(t);if(n.getUint32(0,!0)!==Dc)return null;const s=n.getUint32(12,!0);if(n.getUint32(16,!0)!==zc||20+s>t.byteLength)return null;const i=JSON.parse(new TextDecoder("utf-8").decode(new Uint8Array(t,20,s))),l=i.accessors??[],a=i.meshes??[],c=(i.nodes??[]).map(u=>{var d;let v;Array.isArray(u.matrix)&&u.matrix.length===16?v=Float32Array.from(u.matrix):u.translation||u.rotation||u.scale?v=ci(u.translation??[0,0,0],u.rotation??[0,0,0,1],u.scale??[1,1,1]):v=Xe();const M={children:u.children??[],matrix:v};if(typeof u.name=="string"&&u.name.length>0&&(M.name=u.name),u.mesh!=null&&a[u.mesh]){const y=a[u.mesh].primitives??[];let x,T;for(const P of y){const L=l[(d=P.attributes)==null?void 0:d.POSITION];if(!(!L||!Array.isArray(L.min)||!Array.isArray(L.max)))if(!x||!T)x=[L.min[0],L.min[1],L.min[2]],T=[L.max[0],L.max[1],L.max[2]];else for(let _=0;_<3;_++)x[_]=Math.min(x[_],L.min[_]),T[_]=Math.max(T[_],L.max[_])}M.mesh={primitives:y.length,min:x,max:T}}return M});for(const u of i.skins??[])for(const v of u.joints??[])c[v]&&(c[v].skinJoint=!0);const f=(i.animations??[]).map((u,v)=>{var d,y;let M=0;for(const x of u.samplers??[]){const T=(y=(d=l[x.input])==null?void 0:d.max)==null?void 0:y[0];typeof T=="number"&&T>M&&(M=T)}return{name:typeof u.name=="string"?u.name:`animation_${v}`,duration:M}}),p=i.scene??0,g=((r=(e=i.scenes)==null?void 0:e[p])==null?void 0:r.nodes)??[];return{nodes:c,roots:g,animations:f}}catch{return null}};let Vc=null,Rn=null;const Hc=()=>Vc??(Vc=Nr(()=>import("./creatorAnim-BOwKr-C1.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.default()).then(t=>Rn=t)),bi=()=>Rn!==null,xt=(t,e,r)=>{const n=t._malloc(Math.max(4,e.length*4));t.HEAPF32.set(e,n>>2);try{return r(n)}finally{t._free(n)}},kc=(t,e,r)=>{const n=t._malloc(Math.max(4,e.length*2));t.HEAPU16.set(e,n>>1);try{return r(n)}finally{t._free(n)}},pt=(t,e,r)=>{const n=t.lengthBytesUTF8(e)+1,s=t._malloc(n);t.stringToUTF8(e,s,n);try{return r(s)}finally{t._free(s)}},Wc=(t,e,r)=>{const n=t._malloc(Math.max(1,e.length));t.HEAPU8.set(e,n);try{return r(n)}finally{t._free(n)}},pn=(t,e,r,n,s,i,l,a,c,f,p)=>{const g=s+s,u=i+i,v=l+l,M=s*g,d=s*u,y=s*v,x=i*u,T=i*v,P=l*v,L=a*g,_=a*u,o=a*v,h=t;h[0]=(1-(x+P))*c,h[1]=(d+o)*c,h[2]=(y-_)*c,h[3]=0,h[4]=(d-o)*f,h[5]=(1-(M+P))*f,h[6]=(T+L)*f,h[7]=0,h[8]=(y+_)*p,h[9]=(T-L)*p,h[10]=(1-(M+x))*p,h[11]=0,h[12]=e,h[13]=r,h[14]=n,h[15]=1},Wr=t=>{const e=t;let r=Math.hypot(e[0],e[1],e[2]),n=Math.hypot(e[4],e[5],e[6]),s=Math.hypot(e[8],e[9],e[10]);e[0]*(e[5]*e[10]-e[6]*e[9])-e[4]*(e[1]*e[10]-e[2]*e[9])+e[8]*(e[1]*e[6]-e[2]*e[5])<0&&(r=-r);const l=r!==0?1/r:0,a=n!==0?1/n:0,c=s!==0?1/s:0,f=e[0]*l,p=e[1]*l,g=e[2]*l,u=e[4]*a,v=e[5]*a,M=e[6]*a,d=e[8]*c,y=e[9]*c,x=e[10]*c,T=f+v+x;let P,L,_,o;if(T>0){const h=.5/Math.sqrt(T+1);o=.25/h,P=(M-y)*h,L=(d-g)*h,_=(p-u)*h}else if(f>v&&f>x){const h=2*Math.sqrt(1+f-v-x);o=(M-y)/h,P=.25*h,L=(u+p)/h,_=(d+g)/h}else if(v>x){const h=2*Math.sqrt(1+v-f-x);o=(d-g)/h,P=(u+p)/h,L=.25*h,_=(y+M)/h}else{const h=2*Math.sqrt(1+x-f-v);o=(p-u)/h,P=(d+g)/h,L=(y+M)/h,_=.25*h}return{t:[e[12],e[13],e[14]],r:[P,L,_,o],s:[r,n,s]}},$c=(t,e)=>{const r=Math.cos(e),n=Math.sin(e),s=t[0],i=t[1],l=t[2],a=t[8],c=t[9],f=t[10];t[0]=s*r-a*n,t[1]=i*r-c*n,t[2]=l*r-f*n,t[8]=s*n+a*r,t[9]=i*n+c*r,t[10]=l*n+f*r};let Ws=!1;const gn=t=>typeof t._canimAnimatorLateSolve=="function"?!0:(Ws||(Ws=!0,console.warn("creator-anim: this wasm predates IK chains / sockets — rebuild it (build-wasm.sh + vendor:creator); chains are inert")),!1),pr=19,Et={TARGET_X:0,POLE_X:3,HAS_POLE:6,ROT_X:8},$s=64,Er=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Xc(t){const e=Rn;if(!e)throw new Error("creator-anim: await loadCreatorAnim() before createAnimBridge()");const r=new Map;let n=null;const s=e._malloc(16),i=e._malloc(12),l=e._malloc(64),a=e._malloc(12),c=e._malloc(12),f=e._malloc(32),p=e._malloc(4),g=e._malloc(4),u=e._malloc($s*4),v=[],M=[];let d=null;const y=o=>{const h=o instanceof Uint8Array?o:new Uint8Array(o);return Wc(e,h,m=>e._canimClipsLoad(m,h.length))},x=o=>{e._free(o.trs),e._free(o.write)},T={loadClips(o,h,m){const w=t.getBuffer(o),E=w?y(w):0;if(!E){m(new Error("loadClips: not a GLB with animations"));return}h(E)},createClipFromTracks(o,h){return pt(e,o,m=>xt(e,h,w=>e._canimClipsFromTracks(m,w,h.length)))},getClipSetInfo(o){const h=e._canimClipsCount(o),m=[];for(let w=0;w<h;w++){const E=e._canimClipName(o,w);m.push({name:E?e.UTF8ToString(E):"",duration:e._canimClipDuration(o,w),trackCount:e._canimClipTrackCount(o,w)})}return m},sliceClip(o,h,m,w){return e._canimClipsSlice(o,h,m,w)},deriveClip(o,h,m,w,E){return e._canimClipsDerive(o,h,m?1:0,w,E)},destroyClipSet(o){e._canimClipsDestroy(o)},animatorCreate(o){if(!t.get(o))return 0;const m=[],w=[],E=[],B=[],W=[],N=(H,G)=>{const Y=t.get(H);if(!Y)return;const se=m.length;m.push(H),w.push(G),E.push(Y.name??""),W.push(Y.skinJoint?1:0);const{t:te,r:ne,s:he}=Wr(Y.m);B.push(te[0],te[1],te[2],ne[0],ne[1],ne[2],ne[3],he[0],he[1],he[2]);for(const we of Y.children)N(we,se)};N(o,-1);const I=m.length,D=e._malloc(Math.max(4,I*4));e.HEAP32.set(w,D>>2);const K=e._malloc(Math.max(1,I));e.HEAPU8.set(W,K);let q=0;try{q=pt(e,E.join(`
1105
- `),H=>xt(e,B,G=>e._canimAnimatorCreate(I,D,H,G,K,o)))}finally{e._free(D),e._free(K)}if(!q)return 0;const O=e._canimAnimatorShadowedNames(q);return O>0&&console.warn(`[Animator] ${O} bone name(s) exist twice under this model (a leftover skeleton copy?) — bound to the skinned ones; run 'lecodes assets doctor' on the GLB`),r.set(q,{rootId:o,entities:m,trs:e._malloc(Math.max(4,I*40)),write:e._malloc(Math.max(1,I)),n:I,feetOn:!1,iks:[],sockets:[]}),q},animatorDestroy(o){const h=r.get(o);if(!h){e._canimAnimatorDestroy(o);return}e._canimAnimatorRest(o,h.trs,h.write);const m=e.HEAPF32,w=e.HEAPU8,E=h.trs>>2;for(let B=0;B<h.n;B++){if(!w[h.write+B])continue;const W=t.get(h.entities[B]);if(!W)continue;const N=E+B*10;pn(W.m,m[N],m[N+1],m[N+2],m[N+3],m[N+4],m[N+5],m[N+6],m[N+7],m[N+8],m[N+9]),t.localMatrixChanged(h.entities[B])}e._canimAnimatorDestroy(o),x(h),r.delete(o)},animatorBind(o,h,m,w){return e._canimAnimatorBind(o,h,m,w)},animatorBindMirror(o,h,m,w){return e._canimAnimatorBindMirror?e._canimAnimatorBindMirror(o,h,m,w):-1},animatorBoundTracks(o,h){return e._canimAnimatorBoundTracks(o,h)},setClipEvents(o,h,m){xt(e,m,w=>e._canimClipsSetEvents(o,h,w,m.length))},animatorSetBlend(o,h,m,w,E,B,W,N){const I=m>1?2:1,D=Math.min(w.length,Math.floor(E.length/I)),K=N&&N.length>=D*2?N:null;kc(e,w,q=>xt(e,E,O=>{K?xt(e,K,H=>e._canimAnimatorSetBlend(o,h,I,q,O,H,D,B,W)):e._canimAnimatorSetBlend(o,h,I,q,O,0,D,B,W)}))},animatorSetBlendValue(o,h,m,w){e._canimAnimatorSetBlendValue(o,h,m,w)},animatorSlotSetTurn(o,h,m,w){e._canimAnimatorSlotSetTurn(o,h,m,w?1:0)},animatorSlotSetWindow(o,h,m,w){e._canimAnimatorSlotSetWindow(o,h,m,w)},animatorPlay(o,h,m,w,E,B,W){e._canimAnimatorPlay(o,h,m?1:0,w,E,B,W?1:0)},animatorStop(o,h,m,w){e._canimAnimatorStop(o,h,m,w)},animatorSeek(o,h,m){e._canimAnimatorSeek(o,h,m)},animatorGetSlotTime(o,h){return e._canimAnimatorSlotTime(o,h)},animatorGetSlotWeight(o,h){return e._canimAnimatorSlotWeight(o,h)},animatorSetLayer(o,h,m,w,E){pt(e,E??"",B=>e._canimAnimatorSetLayer(o,h,m,w?1:0,B))},animatorSetLayerAnticipation(o,h,m){e._canimAnimatorSetLayerAnticipation(o,h,m)},animatorSetGlobal(o,h,m){e._canimAnimatorSetGlobal(o,h,m?1:0)},animatorJointRanges(o,h,m){for(const[w,E]of r){if(!E.entities.includes(o))continue;const B=h.length>>1,W=new Int32Array(B*2);for(let q=0;q<B*2;q++)W[q]=E.entities.indexOf(h[q]);const N=new Float32Array(B*6),I=e._malloc(Math.max(4,B*8));e.HEAP32.set(W,I>>2);const D=e._malloc(Math.max(4,B*24));let K=0;try{K=xt(e,m,q=>e._canimAnimatorJointRanges(w,I,B,q,D)),K>0&&N.set(e.HEAPF32.subarray(D>>2,(D>>2)+B*6))}finally{e._free(I),e._free(D)}return K>0?N:null}return null},animatorSeedPose(o,h){for(const[m,w]of r){if(!w.entities.includes(o))continue;const E=new Float32Array(w.n*10);for(let B=0;B<w.n;B++){const W=t.get(w.entities[B]),{t:N,r:I,s:D}=Wr(W?W.m:Er);E.set([N[0],N[1],N[2],I[0],I[1],I[2],I[3],D[0],D[1],D[2]],B*10)}xt(e,E,B=>e._canimAnimatorSeedPose(m,B,h));return}},animatorSetRootMotion(o,h,m){pt(e,h??"",w=>e._canimAnimatorSetRootMotion(o,w,(m|0)&255))},animatorGetRootMotion(o,h){e._canimAnimatorRootMotion(o,i);const m=e.HEAPF32,w=i>>2;h[0]=m[w],h[1]=m[w+1],h[2]=m[w+2]},setOnAnimatorEvent(o){n=o},animatorSetFeet(o,h,m){pt(e,h,w=>pt(e,m,E=>e._canimAnimatorSetFeet(o,w,E)))},animatorSlotCurveAt(o,h,m,w){return e._canimAnimatorSlotCurveAt(o,h,m,w)},animatorSlotCurveInfo(o,h,m){const w=e._canimAnimatorSlotCurveInfo(o,h,s);return w&&m.set(e.HEAPF32.subarray(s>>2,(s>>2)+Math.min(4,m.length))),w!==0},animatorSlotTurn(o,h){return e._canimAnimatorSlotTurn(o,h)},animatorSlotTimeAtTurn(o,h,m){return e._canimAnimatorSlotTimeAtTurn(o,h,m)},animatorLayerPhase(o,h){return e._canimAnimatorLayerPhase(o,h)},animatorSeekPhase(o,h,m){e._canimAnimatorSeekPhase(o,h,m)},animatorSlotContacts(o,h,m){const w=Math.floor(m.length/8);if(w===0)return e._canimAnimatorSlotContacts(o,h,0,0);const E=e._malloc(w*8*4),B=e._canimAnimatorSlotContacts(o,h,E,w);return m.set(e.HEAPF32.subarray(E>>2,(E>>2)+Math.min(B,w)*8)),e._free(E),B},animatorSlotTreads(o,h,m){if(m.length===0)return e._canimAnimatorSlotTreads(o,h,0,0);const w=e._malloc(m.length*4),E=e._canimAnimatorSlotTreads(o,h,w,m.length);return m.set(e.HEAPF32.subarray(w>>2,(w>>2)+Math.min(E+1,m.length))),e._free(w),E},animatorSlotPhysics(o,h,m,w){const E=e._malloc(44),B=e._canimAnimatorSlotPhysics(o,h,m,E);return B&&w.set(e.HEAPF32.subarray(E>>2,(E>>2)+Math.min(11,w.length))),e._free(E),B},animatorSlotFeatures(o,h,m,w){const E=e._malloc(148),B=e._canimAnimatorSlotFeatures(o,h,m,E);return B&&w.set(e.HEAPF32.subarray(E>>2,(E>>2)+Math.min(37,w.length))),e._free(E),B},animatorKneeAxis(o,h,m){const w=e._canimAnimatorKneeAxis(o,h,f);return w&&m.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(8,m.length))),w},animatorSlotKneePole(o,h,m,w,E){const B=e._canimAnimatorSlotKneePole(o,h,m,w,f);return B&&E.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(6,E.length))),B},animatorSetStepWarp(o,h,m,w,E,B){e._canimAnimatorSetStepWarp(o,h?1:0,m,w,E,B)},animatorSlotFit(o,h,m,w,E){if(E.length===0)return e._canimAnimatorSlotFit(o,h,m,w,0,0);const B=e._malloc(E.length*4),W=e._canimAnimatorSlotFit(o,h,m,w,B,E.length);return E.set(e.HEAPF32.subarray(B>>2,(B>>2)+Math.min(W,E.length))),e._free(B),W},animatorSlotExit(o,h,m,w,E,B){return e._canimAnimatorSlotExit(o,h,m,w,E?1:0,B)},animatorSlotAlign(o,h,m,w,E,B){if(B.length<4)return 0;const W=e._malloc(16),N=e._canimAnimatorSlotAlign(o,h,m,w,E,W);return N&&B.set(e.HEAPF32.subarray(W>>2,(W>>2)+4)),e._free(W),N},setOnAnimatorStep(o){d=o},animatorSetFeetParams(o,h){xt(e,h,w=>e._canimAnimatorSetFeetParams(o,w,h.length));const m=r.get(o);m&&(m.feetOn=h.length>0&&h[0]>.5||h.length>1&&h[1]>.5)},animatorFootState(o,h,m){const w=e._canimAnimatorFootState(o,h,f);return w&&m.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(8,m.length))),w!==0},animatorIkCreate(o,h,m){var K,q;const w=r.get(o);if(!w||!gn(e))return 0;const E=w.entities.indexOf(m);if(E<0)return 0;let B=-1,W=-1;if(h===0){const O=((K=t.get(m))==null?void 0:K.parent)??0;if(B=w.entities.indexOf(O),B<0||(W=w.entities.indexOf(((q=t.get(O))==null?void 0:q.parent)??0),W<0))return 0}const N=e._canimAnimatorIkCreateJoints(o,h,W,B,E);if(!N)return 0;const I=new Float32Array(pr),D=e._malloc(pr*4);return e._canimAnimatorIkGet(o,N,D,pr),I.set(e.HEAPF32.subarray(D>>2,(D>>2)+pr)),e._free(D),w.iks.push({ik:N,target:0,pole:0,rotation:0,params:I}),N},animatorIkDestroy(o,h){e._canimAnimatorIkDestroy(o,h);const m=r.get(o);m&&(m.iks=m.iks.filter(w=>w.ik!==h))},animatorIkSet(o,h,m){var E;xt(e,m,B=>e._canimAnimatorIkSet(o,h,B,m.length));const w=(E=r.get(o))==null?void 0:E.iks.find(B=>B.ik===h);w&&w.params.set(m.subarray(0,Math.min(m.length,pr)))},animatorIkNodes(o,h,m,w,E){var W;const B=(W=r.get(o))==null?void 0:W.iks.find(N=>N.ik===h);B&&(B.target=m,B.pole=w,B.rotation=E)},animatorIkAnchor(o,h,m){pt(e,m??"",w=>e._canimAnimatorIkAnchor(o,h,w))},animatorIkState(o,h,m){const w=e._canimAnimatorIkState(o,h,s);return w&&m.set(e.HEAPF32.subarray(s>>2,(s>>2)+Math.min(4,m.length))),w!==0},animatorSetSocket(o,h,m,w,E,B){const W=r.get(o);if(!W||!gn(e))return;W.sockets=W.sockets.filter(D=>!(D.set===h&&D.name===m));const N=(D,K)=>{pt(e,h,q=>pt(e,m,O=>{K?xt(e,K,H=>e._canimAnimatorSetSocket(o,q,O,D,H)):e._canimAnimatorSetSocket(o,q,O,D,0)}))};if(E===0&&!B){N(-1,null);return}const I=W.entities.indexOf(w);if(I<0){console.warn(`[Animator] socket '${m}': the joint is no bone of this animator`);return}N(I,B??[0,0,0,0,0,0,1]),E!==0&&W.sockets.push({set:h,name:m,node:E})},setClipAnchors(o,h,m,w,E,B){gn(e)&&pt(e,m,W=>pt(e,w??"",N=>pt(e,E??"",I=>xt(e,B,D=>e._canimClipsSetAnchors(o,h,W,N,I,D,Math.floor(B.length/4))))))},animatorSetMotion(o,h,m,w){e._canimAnimatorSetMotion(o,h,m,w)},animatorSetDriveInput(o,h,m){e._canimAnimatorSetDriveInput(o,h,m)},animatorSetSlotDrive(o,h,m,w){e._canimAnimatorSetSlotDrive(o,h,m,w)},animatorSetWarpParams(o,h){xt(e,h,m=>e._canimAnimatorSetWarpParams(o,m,h.length))}},P=(o,h,m)=>{var q,O;const w=t.get(h.rootId),E=w&&w.parent?t.get(w.parent):void 0,B=E?((q=t.world)==null?void 0:q.call(t,E.id))??E.m:Er;e.HEAPF32.set(B,l>>2),e._canimAnimatorSetWorld(o,l);const W=e._canimAnimatorEvaluate(o,m,0,h.trs,h.write);if(h.feetOn&&w){const H=(((O=t.world)==null?void 0:O.call(t,h.rootId))??w.m)[13];for(let G=0;G<2;G++){if(!e._canimAnimatorFootProbe(o,G,a,c))continue;const Y=e.HEAPF32,se=a>>2;e._canimAnimatorSetGround(o,G,1,Y[se],H,Y[se+2],0,1,0)}}const N=e.HEAPF32,I=e.HEAPU8,D=h.trs>>2;for(let H=0;H<h.n;H++){if(!I[h.write+H])continue;const G=t.get(h.entities[H]);if(!G)continue;const Y=D+H*10;pn(G.m,N[Y],N[Y+1],N[Y+2],N[Y+3],N[Y+4],N[Y+5],N[Y+6],N[Y+7],N[Y+8],N[Y+9]),t.localMatrixChanged(h.entities[H])}if(t.setMorphWeights){const H=e._canimAnimatorMorphCount(o);for(let G=0;G<H;G++){const Y=e._canimAnimatorMorph(o,G,p,g),se=e.HEAP32[p>>2],te=e.HEAPU32[g>>2];!Y||se<0||te===0||t.setMorphWeights(h.entities[se],Float32Array.from(e.HEAPF32.subarray(Y>>2,(Y>>2)+te)))}}const K=e._canimAnimatorRootMotionFrame(o,s);if(K!==0){const H=e.HEAPF32,G=s>>2,Y=H[G],se=H[G+1],te=H[G+2],ne=H[G+3];let he=!1;if(K===2&&t.applyRootMotion&&(he=t.applyRootMotion(h.rootId,Y,se,te,m,ne)),!he&&(Y!==0||se!==0||te!==0||ne!==0)){const we=t.get(h.rootId);if(we){const de=we.m;ne!==0&&$c(de,ne);const Ve=de[0]*Y+de[4]*se+de[8]*te,je=de[1]*Y+de[5]*se+de[9]*te,S=de[2]*Y+de[6]*se+de[10]*te;de[12]+=Ve,de[13]+=je,de[14]+=S,t.localMatrixChanged(h.rootId)}}}if(d){const H=e._canimAnimatorStepCount(o);for(let G=0;G<H;G++){const Y=e._canimAnimatorStep(o,G,i);if(Y<0)continue;const se=e.HEAPF32,te=i>>2,ne=se[te],he=se[te+1],we=se[te+2],de=B;M.push({id:o,side:Y,x:de[0]*ne+de[4]*he+de[8]*we+de[12],y:de[1]*ne+de[5]*he+de[9]*we+de[13],z:de[2]*ne+de[6]*he+de[10]*we+de[14]})}}if(W>0){const H=e._canimAnimatorEvents(o,u,$s),G=e.HEAPU16,Y=u>>1;for(let se=0;se<H;se++)v.push({id:o,slot:G[Y+se*2],type:G[Y+se*2+1]})}},L=o=>{var h,m;return((h=t.world)==null?void 0:h.call(t,o))??((m=t.get(o))==null?void 0:m.m)},_=(o,h)=>{if(h.iks.length===0)return;const m=t.get(h.rootId);if(!m)return;const w=m.parent?L(m.parent)??Er:Er;for(const N of h.iks){if(!N.target&&!N.pole&&!N.rotation)continue;const I=N.target?L(N.target):void 0;I&&(N.params[Et.TARGET_X]=I[12],N.params[Et.TARGET_X+1]=I[13],N.params[Et.TARGET_X+2]=I[14]);const D=N.pole?L(N.pole):void 0;D&&(N.params[Et.POLE_X]=D[12],N.params[Et.POLE_X+1]=D[13],N.params[Et.POLE_X+2]=D[14],N.params[Et.HAS_POLE]=1);const K=N.rotation?L(N.rotation):void 0;if(K){const q=Wr(K).r;N.params[Et.ROT_X]=q[0],N.params[Et.ROT_X+1]=q[1],N.params[Et.ROT_X+2]=q[2],N.params[Et.ROT_X+3]=q[3]}xt(e,N.params,q=>e._canimAnimatorIkSet(o,N.ik,q,pr))}for(const N of h.sockets){const I=L(N.node);I&&(e.HEAPF32.set(I,l>>2),pt(e,N.set,D=>pt(e,N.name,K=>e._canimAnimatorSocketSetWorld(o,D,K,l))))}const E=e.HEAPF32,B=h.trs>>2;for(let N=0;N<h.n;N++){const I=t.get(h.entities[N]),{t:D,r:K,s:q}=Wr(I?I.m:Er),O=B+N*10;E[O]=D[0],E[O+1]=D[1],E[O+2]=D[2],E[O+3]=K[0],E[O+4]=K[1],E[O+5]=K[2],E[O+6]=K[3],E[O+7]=q[0],E[O+8]=q[1],E[O+9]=q[2]}if(e.HEAPF32.set(w,l>>2),e._canimAnimatorLateSolve(o,l,h.trs,h.write)===0)return;const W=e.HEAPU8;for(let N=0;N<h.n;N++){if(!W[h.write+N])continue;const I=t.get(h.entities[N]);if(!I)continue;const D=B+N*10;pn(I.m,E[D],E[D+1],E[D+2],E[D+3],E[D+4],E[D+5],E[D+6],E[D+7],E[D+8],E[D+9]),t.localMatrixChanged(h.entities[N])}};return{methods:T,registerGlbClips(o){return y(o)},lateSolve(){for(const[o,h]of r)_(o,h)},evaluate(o){for(const[h,m]of r)P(h,m,o);if(M.length>0){const h=M.splice(0,M.length);if(d)for(const m of h)d(m.id,m.side,m.x,m.y,m.z)}if(v.length>0&&n){const h=v.splice(0,v.length);for(const m of h)n(m.id,m.slot,m.type)}else v.length=0},onEntityDestroyed(o){e._canimAnimatorsDestroyTagged(o);for(const[h,m]of r)m.rootId===o&&(x(m),r.delete(h))}}}const jc=["loadClips","createClipFromTracks","getClipSetInfo","sliceClip","deriveClip","destroyClipSet","animatorCreate","animatorDestroy","animatorBind","animatorBoundTracks","setClipEvents","animatorSetBlend","animatorSetBlendValue","animatorPlay","animatorStop","animatorSeek","animatorGetSlotTime","animatorGetSlotWeight","animatorSetLayer","animatorSetGlobal","animatorSeedPose","animatorJointRanges","animatorSetRootMotion","animatorGetRootMotion","setOnAnimatorEvent","animatorSetFeet","animatorSlotCurveAt","animatorSlotCurveInfo","animatorSlotTurn","animatorLayerPhase","animatorSeekPhase","animatorSlotContacts","animatorSlotTreads","animatorSlotPhysics","animatorSlotFeatures","animatorKneeAxis","animatorSlotKneePole","animatorSetStepWarp","setOnAnimatorStep","animatorSlotFit","animatorSlotExit","animatorSlotAlign","animatorSlotTimeAtTurn","animatorSetFeetParams","animatorFootState","animatorIkCreate","animatorIkDestroy","animatorIkSet","animatorIkNodes","animatorIkAnchor","animatorIkState","animatorSetSocket","setClipAnchors","animatorSetMotion","animatorSetDriveInput","animatorSetSlotDrive","animatorSetWarpParams"],qc=t=>{let e=null;const r=()=>{if(!e){if(!bi())throw new Error("creator-anim is not loaded: await loadCreatorAnim() (viewer-lite/src/gl/core/animBridge) before the first animation call");e=Xc(t)}return e},n={};for(const s of jc)n[s]=(...i)=>r().methods[s](...i);return{methods:n,registerGlbClips:s=>r().registerGlbClips(s),evaluate:s=>{e&&e.evaluate(s)},lateSolve:()=>{e&&e.lateSolve()},onEntityDestroyed:s=>{e&&e.onEntityDestroyed(s)}}},Yc=["physicsConfigure","setInterpolation","physicsBuildBox","physicsBuildSphere","physicsBuildCylinder","physicsBuildCapsule","physicsBuildMesh","physicsBuildMeshFromEntity","physicsBuildHeightField","physicsUpdateHeightField","glbTriangles","physicsSetShapeOrigin","physicsSetBodyShape","physicsDestroyShape","physicsCreateBody","physicsSetPickable","physicsSetFriction","physicsGetFriction","physicsRaycast","physicsCreateBox","physicsCreateSphere","physicsCreateCylinder","physicsSetLinearVelocity","physicsGetLinearVelocity","physicsSetAngularVelocity","physicsGetAngularVelocity","physicsApplyImpulse","physicsApplyImpulseAt","physicsSetBodyPosition","physicsSetBodyRotation","physicsRemoveBody","characterCreate","characterDestroy","characterMove","characterMoveFree","characterSetVerticalVelocity","characterSetVelocity","characterSetGravityScale","characterSetMaxSlope","characterSetShape","characterGetVelocity","characterGetGroundState","characterSetPosition","vehicleCreate","vehicleDestroy","vehicleSetInput","vehicleSetTuning","vehicleGetState","vehicleReset","vehicleBodyId","ragdollCreate","ragdollDestroy","ragdollActivate","ragdollDeactivate","ragdollActive","ragdollBodyId","ragdollSetDrive","setOnPhysicsEvent"],vn=1/60,Xs=["static","kinematic","dynamic"],Fn=34,Kc=15,Qc=32,js=33,qs=(t,e)=>({engine:{torque:t[4],maxRpm:t[5],idleRpm:t[6],inertia:t[7],braking:t[8]},clutchStrength:t[9],clutchCapacity:t[31],differential:t[10]<=0?"open":t[10],antiRoll:t[11],maxTilt:t[12],aero:{downforce:t[13],drag:t[14]},steering:t[15]?{feedback:{inertia:t[16],damping:t[17],parkingFriction:t[18],powerSteering:t[24],friction:t[29]},caster:t[19],trail:t[20]}:{caster:t[19],trail:t[20]},...e>0?{torqueCurve:Array.from(t.subarray(Fn,Fn+e*2))}:{}}),Zc=t=>{let e=null;const r=()=>{if(!e){if(!Es())throw new Error("creator-physics is not loaded: await loadCreatorPhysics() (viewer-lite/src/gl/core/physicsBridge) before the first physics call");e=Gl(t)}return e},n={};for(const d of Yc)n[d]=(...y)=>r().methods[d](...y);const s=new Map,i=new Map,l=new Map,a=new Map,c=new Map;let f;const p=(d,y)=>(d&&s.set(d,y),d),g=(d,y)=>{const x=d.get(y);return x===void 0?void 0:t.ent(x).physics},u=(d,y,x,T,P)=>(d&&(i.set(d,y),t.ent(y).physics={motion:Xs[x]??x,mass:T,shape:P}),d),v={...n,physicsHasSupport:()=>Es(),physicsConfigure(d,y,x,T){f={gravity:[d,y,x],maxBodies:T},n.physicsConfigure(d,y,x,T)},physicsBuildBox:(d,y,x)=>p(n.physicsBuildBox(d,y,x),{type:"box",size:[d*2,y*2,x*2]}),physicsBuildSphere:d=>p(n.physicsBuildSphere(d),{type:"sphere",radius:d}),physicsBuildCylinder:(d,y)=>p(n.physicsBuildCylinder(d,y),{type:"cylinder",height:d*2,radius:y}),physicsBuildCapsule:(d,y)=>p(n.physicsBuildCapsule(d,y),{type:"capsule",height:d*2,radius:y}),physicsBuildMesh:(d,y,x,T,P,L)=>p(n.physicsBuildMesh(d,y,x,T,P,L),{type:x?"convexHull":"mesh",vertices:d.length/3,triangles:Math.floor(y.length/3),scale:[T,P,L]}),physicsBuildMeshFromEntity:(d,y,x,T,P)=>p(n.physicsBuildMeshFromEntity(d,y,x,T,P),{type:y?"convexHull":"mesh",source:d,scale:[x,T,P]}),physicsBuildHeightField(d,y,x,T,P,L,_,o){let h=0;if(P)for(let m=0;m<P.length;m++)P[m]&&h++;return p(n.physicsBuildHeightField(d,y,x,T,P,L,_,o),{type:"heightfield",size:[y,x],cellSize:T,samples:d.length,holes:h,scale:[L,_,o]})},physicsSetShapeOrigin(d,y,x,T){const P=s.get(d);P&&(y===0&&x===0&&T===0?delete P.origin:P.origin=[y,x,T]),n.physicsSetShapeOrigin(d,y,x,T)},physicsSetBodyShape(d,y,x){const T=g(i,d);T&&(T.shape=s.get(y)),n.physicsSetBodyShape(d,y,x)},physicsDestroyShape(d){s.delete(d),n.physicsDestroyShape(d)},physicsCreateBody(d,y,x,T,P,L){const _=n.physicsCreateBody(d,y,x,T,P,L);return _&&(i.set(_,d),t.ent(d).physics={motion:Xs[x]??x,mass:T,...P&&{sensor:P},...L&&{pickOnly:L},shape:s.get(y)}),_},physicsSetFriction(d,y){const x=g(i,d);x&&(x.friction=y),n.physicsSetFriction(d,y)},physicsRemoveBody(d){i.delete(d),n.physicsRemoveBody(d)},physicsCreateBox:(d,y,x,T,P,L)=>u(n.physicsCreateBox(d,y,x,T,P,L),d,P,L,{type:"box",size:[y*2,x*2,T*2]}),physicsCreateSphere:(d,y,x,T)=>u(n.physicsCreateSphere(d,y,x,T),d,x,T,{type:"sphere",radius:y}),physicsCreateCylinder:(d,y,x,T,P)=>u(n.physicsCreateCylinder(d,y,x,T,P),d,T,P,{type:"cylinder",height:y*2,radius:x}),characterCreate(d,y,x){const T=n.characterCreate(d,y,x);return T&&(l.set(T,d),t.ent(d).physics={character:!0,maxSlopeDeg:x,shape:s.get(y)}),T},characterDestroy(d){l.delete(d),n.characterDestroy(d)},characterSetMaxSlope(d,y){const x=g(l,d);x&&(x.maxSlopeDeg=y),n.characterSetMaxSlope(d,y)},characterSetShape(d,y){const x=n.characterSetShape(d,y);if(x){const T=g(l,d);T&&(T.shape=s.get(y))}return x},vehicleCreate(d,y,x){const T=n.vehicleCreate(d,y,x);if(!T)return 0;const P=x[Qc]??0,L=x[js]??0;let _=Fn+L*2;const o=[];for(let h=0;h<P;h++){const m=x[_+13]??0,w=x[_+14]??0;o.push({position:[x[_],x[_+1],x[_+2]],radius:x[_+3],width:x[_+4],...x[_+5]?{steerDeg:x[_+5]}:{},...x[_+6]?{driven:x[_+6]}:{},axle:x[_+7],suspension:{travel:x[_+8],stiffness:x[_+9],damping:x[_+10]},tire:{traction:x[_+11],circle:x[_+12],side:m,forward:w}}),_+=Kc+(m+w)*2}return a.set(T,d),t.ent(d).physics={motion:"dynamic",mass:x[1],vehicle:!0,...qs(x,L),wheels:o,shape:s.get(y)},T},vehicleDestroy(d){a.delete(d),n.vehicleDestroy(d)},vehicleSetTuning(d,y){const x=g(a,d);x&&Object.assign(x,qs(y,y[js]??0)),n.vehicleSetTuning(d,y)},vehicleSetInput(d,y){const x=g(a,d);x&&(x.input={throttle:y[0],steer:y[1],steerForce:y[2],ratio:y[3],clutch:y[4],brakes:Array.from(y.subarray(5))}),n.vehicleSetInput(d,y)},ragdollCreate(d,y,x){const T=n.ragdollCreate(d,y,x);if(!T)return 0;const P=16,L=x[1]??0,_=x[2]??12,o=[];for(let h=0;h<L;h++){const m=P+h*_;o.push({bone:y[h*2],...y[h*2+1]?{to:y[h*2+1]}:{},parent:x[m],radius:x[m+1],...x[m+2]?{length:x[m+2]}:{},mass:x[m+3],...x[m+6]?{hinge:{axis:[x[m+7],x[m+8],x[m+9]],min:x[m+10],max:x[m+11]}}:{swing:x[m+4],twist:x[m+5]}})}return c.set(T,d),t.ent(d).ragdoll={friction:x[3],collide:x[6]?"static":"all",freeze:!!x[7],freezeAfter:x[8]??0,drive:{frequency:x[9],damping:x[10],torque:x[11]},jointFriction:x[12],limits:x[13]?"clips":"table",limitsMargin:x[14],parts:o},T},ragdollDestroy(d){c.delete(d),n.ragdollDestroy(d)},ragdollActivate(d,y,x,T){const P=n.ragdollActivate(d,y,x,T),L=c.get(d),_=L===void 0?void 0:t.ent(L).ragdoll;return P&&_&&(_.active=!0,_.launch=[y,x,T]),P},ragdollDeactivate(d,y){const x=c.get(d),T=x===void 0?void 0:t.ent(x).ragdoll;T&&(T.active=!1,delete T.launch,y>0&&(T.blendOut=y)),n.ragdollDeactivate(d,y)},ragdollSetDrive(d,y,x){const T=c.get(d),P=T===void 0?void 0:t.ent(T).ragdoll;P&&(P.strength=y,P.anchored=x),n.ragdollSetDrive(d,y,x)}};let M=0;return{methods:v,loaded:()=>e!==null,frame(d,y){if(e){e.frame(d,y);return}if(!y){M=0;return}M+=d;let x=0;for(;M>=vn&&x<4;)y(vn),M-=vn,x++;x===4&&(M=0)},syncRagdolls(d){e&&e.syncRagdolls(d)},applyRootMotion:(d,y,x,T,P)=>e?e.applyRootMotion(d,y,x,T,P):!1,config:()=>f}},Ht={POINTS:0,QUADS:1,MESH:3};let Jc=null,Pn=null;const eu=()=>Jc??(Jc=Nr(()=>import("./creatorParticles-DYlv4g1J.js"),__vite__mapDeps([4,1]),import.meta.url).then(t=>t.default()).then(t=>Pn=t)),tu=()=>Pn!==null,ru=(t,e,r)=>{const n=t._malloc(Math.max(4,e.length*4));t.HEAPF32.set(e,n>>2);try{return r(n)}finally{t._free(n)}};function nu(t){const e=Pn;if(!e)throw new Error("creator-particles: await loadCreatorParticles() before createParticleBridge()");const r=e._malloc(64),n=e._malloc(12),s=new Map,i={createParticleSystem(a,c,f){e._cpartCreate(a,f|0)&&s.set(a,c)},spawnParticles(a,c){e._cpartSpawn(a,c)},setParticleSystemConfig(a,c){ru(e,c,f=>e._cpartSetConfig(a,f,c.length))},createNoise:()=>e._cpartNoiseCreate(),setNoiseFrequency(a,c){e._cpartNoiseSetFrequency(a,c)},setNoiseOctaves(a,c){e._cpartNoiseSetOctaves(a,c|0)},setNoiseFractalLunacrity(a,c){e._cpartNoiseSetLacunarity(a,c)},setNoiseFractalGain(a,c){e._cpartNoiseSetGain(a,c)},getNoise2D:(a,c,f)=>e._cpartNoise2D(a,c,f),getNoise3D:(a,c,f,p)=>e._cpartNoise3D(a,c,f,p)},l=a=>{const c=e._cpartVertexCount(a),f=e._cpartVertexStride(a),p=e._cpartVertexData(a);return{mode:e._cpartMode(a),stride:f,vertexCount:c,indexCount:e._cpartIndexCount(a),bytes:c>0&&p?e.HEAPU8.subarray(p,p+c*f):new Uint8Array(0),geometryVersion:e._cpartGeometryVersion(a),capacity:e._cpartCapacity(a),meshVertexCount:e._cpartMeshVertexCount(a),order:e._cpartOrder(a),alive:e._cpartAlive(a)}};return{methods:i,materialOf:a=>s.get(a),systems:()=>s.keys(),update(a,c){const f=t.cameraPosition();let p=0;f&&(e.HEAPF32.set([f[0],f[1],f[2]],n>>2),p=n);for(const g of s.keys())e.HEAPF32.set(t.world(g),r>>2),e._cpartUpdate(g,a,r,p),c(g,l(g))},setVisible(a,c){e._cpartSetVisible(a,c?1:0)},alive:a=>e._cpartAlive(a),indexPattern(a){const c=e._cpartIndexPatternCount(a);if(c===0)return new Uint32Array(0);const f=e._malloc(c*4);e._cpartWriteIndexPattern(a,f);const p=Uint32Array.from(e.HEAPU32.subarray(f>>2,(f>>2)+c));return e._free(f),p},destroy(a){e._cpartDestroy(a),s.delete(a)},dispose(){e._cpartReset(),s.clear(),e._free(r),e._free(n)}}}const yn={createNoise:()=>0,setNoiseFrequency(){},setNoiseOctaves(){},setNoiseFractalLunacrity(){},setNoiseFractalGain(){},getNoise2D:()=>0,getNoise3D:()=>0},su=t=>{let e=null;const r=()=>(!e&&tu()&&(e=nu(t)),e);let n=1;const s=(a,c,f)=>{const p=t.ent(a);p.particles||(p.particles={}),f===void 0?delete p.particles[c]:p.particles[c]=f},i={createParticleSystem(a,c,f){var g;t.ent(a).particles={material:c,...f?{maxParticles:f}:{}};const p=r();p&&(p.methods.createParticleSystem(a,c,f),(g=t.created)==null||g.call(t,a,c))},spawnParticles(a,c){var p;const f=t.ent(a).particles;f&&(f.spawned=(f.spawned??0)+c),(p=r())==null||p.methods.spawnParticles(a,c)},setParticleSystemConfig(a,c){var g;const f=(u,v)=>u===v?u:{min:u,max:v},p=u=>[c[u],c[u+1],c[u+2],c[u+3]];for(let u=0;u+2<=c.length;u+=2+c[u+1]){const v=u+2;switch(c[u]){case 1:{const M=c[v];M===0?s(a,"shape",{type:"point",at:[c[v+1],c[v+2],c[v+3]]}):M===1?s(a,"shape",{type:"box",min:[c[v+1],c[v+2],c[v+3]],max:[c[v+4],c[v+5],c[v+6]]}):s(a,"shape",{type:"circle",center:[c[v+1],c[v+2],c[v+3]],radius:c[v+4]});break}case 2:s(a,"lifetime",f(c[v],c[v+1]));break;case 3:s(a,"rate",c[v]);break;case 4:s(a,"velocity",{kind:c[v],value:[c[v+1],c[v+2],c[v+3]]}),s(a,"speed",f(c[v+4],c[v+5]));break;case 5:s(a,"spreadAngle",c[v]?{min:[c[v+1],c[v+2]],max:[c[v+3],c[v+4]]}:void 0);break;case 6:s(a,"acceleration",[c[v],c[v+1],c[v+2]]);break;case 7:s(a,"drag",c[v]);break;case 8:s(a,"noise",c[v]!==0?{strength:c[v],frequency:c[v+1],speed:c[v+2]}:void 0);break;case 9:s(a,"seed",c[v]);break;case 10:{const M=f(c[v+2],c[v+3]);s(a,`param${c[v]}`,c[v+4]>0?{base:M,curve:c[v+4]}:M);break}case 11:{const M=p(v),d=p(v+4),y=M.every((x,T)=>x===d[T])?M:{min:M,max:d};s(a,"color",c[v+8]>0?{base:y,curve:c[v+8]}:y);break}case 12:s(a,"space",c[v]?"world":"local");break;case 15:s(a,"render",["point","quad","ribbon","mesh"][c[v]]??c[v]);break}}(g=r())==null||g.methods.setParticleSystemConfig(a,c)},...yn},l=Object.fromEntries(Object.keys(yn).map(a=>[a,(...c)=>{const f=r();return f?f.methods[a](...c):a==="createNoise"?n++:yn[a](...c)}]));return Object.assign(i,l),{methods:i,loaded:()=>e!==null,update(a){e&&e.update(a,(c,f)=>{var g;const p=t.ent(c).particles;p&&(p.alive=f.alive),(g=t.frame)==null||g.call(t,c,f)})},setVisible(a,c){e==null||e.setVisible(a,c)},indexPattern:a=>(e==null?void 0:e.indexPattern(a))??new Uint32Array(0),onEntityDestroyed(a){var c;e&&e.materialOf(a)!==void 0&&(e.destroy(a),(c=t.destroyed)==null||c.call(t,a))}}},Ai=t=>{const e=Math.max(t.lastIndexOf(":"),t.lastIndexOf("|"));return e<0?t:t.slice(e+1)},iu=(t,e,r,n)=>t?t===r?e?0:1:Ai(t)===n?e?2:3:-1:-1,kt=(t,e,r=16)=>{for(let n=0;n<r;n++)t[n]=e[n]},Ys=(t,e)=>{const r=.5*Math.PI/180,n=Math.PI/2,s=Math.min(Math.max(Math.abs(e),r),n);return[Math.min(Math.max(Math.abs(t),r),s),s]};function ou(t,e){const r=e.width??390,n=e.height??844,s=e.fov??60,i={fov:s,near:.01,far:1e3},l=new Map,a=new Map,c=new Map,f=new Map;let p=1,g=1,u=1,v=-1,M=null,d=null,y=null;const x=Zc({ent:S=>o(S),get:S=>l.get(S),world:S=>m(S),setWorldTRS:(S,A,R,z,Q,J,Me,ve,Be,Oe,Fe)=>B(S,ci([A,R,z],[Q,J,Me,ve],[Be,Oe,Fe])),setWorldPosition:(S,A,R,z)=>W(S,A,R,z),localMatrixChanged:S=>{var A;return(A=t.localMatrixChanged)==null?void 0:A.call(t,S)},parentOf:S=>{var A;return((A=l.get(S))==null?void 0:A.parent)??0},glbBytes:S=>{var A,R;return(R=(A=l.get(S))==null?void 0:A.model)==null?void 0:R.buffer},seedAnimator:(S,A)=>P.methods.animatorSeedPose(S,A),jointRanges:(S,A,R)=>P.methods.animatorJointRanges(S,A,R)}),T=su({ent:S=>o(S),world:S=>m(S),cameraPosition:()=>{var R;const S=(R=a.get(v))==null?void 0:R.camera;if(S===void 0)return null;const A=h(S);return[A[12],A[13],A[14]]},created:(S,A)=>{var R;return(R=t.particleSystemCreated)==null?void 0:R.call(t,S,A)},frame:(S,A)=>{var R;return(R=t.particlesFrame)==null?void 0:R.call(t,S,A)},destroyed:S=>{var A;return(A=t.particleSystemDestroyed)==null?void 0:A.call(t,S)}}),P=qc({get:S=>l.get(S),world:S=>m(S),localMatrixChanged:S=>{var A;return(A=t.localMatrixChanged)==null?void 0:A.call(t,S)},getBuffer:S=>e.getBuffer(S),setMorphWeights:(S,A)=>{var R;return(R=t.morphWeights)==null?void 0:R.call(t,S,A)},applyRootMotion:(S,A,R,z,Q,J)=>{const Me=m(S);return x.applyRootMotion(S,Me[0]*A+Me[4]*R+Me[8]*z,Me[2]*A+Me[6]*R+Me[10]*z,Q,J)}}),L=S=>{const A={id:S,name:"",m:t.allocMatrix(S),parent:0,children:[],visible:!0,materials:[]};return(A.m[0]!==1||A.m[5]!==1||A.m[10]!==1||A.m[15]!==1)&&kt(A.m,Xe()),l.set(S,A),A},_=()=>L(p++),o=S=>{let A=l.get(S);return A||(A=L(S),S>=p&&(p=S+1)),A},h=S=>{const A=o(S);return A.parent===0?A.m:At(new Float32Array(16),h(A.parent),A.m)},m=S=>{const A=h(S);return A instanceof Float32Array?A:Float32Array.from(A)},w=S=>{if(S.parent!==0){const A=l.get(S.parent);A&&(A.children=A.children.filter(R=>R!==S.id)),S.parent=0}},E=(S,A,R)=>{var Q,J;const z=o(S);if(z.parent!==A){if(R){const Me=m(S),ve=A===0?Me:At(new Float32Array(16),Lt(m(A)),Me);kt(z.m,ve)}w(z),A!==0&&(z.parent=A,o(A).children.push(S)),(Q=t.parentChanged)==null||Q.call(t,S,A),(J=t.localMatrixChanged)==null||J.call(t,S)}},B=(S,A)=>{var z;const R=o(S);kt(R.m,R.parent===0?A:At(new Float32Array(16),Lt(m(R.parent)),A)),(z=t.localMatrixChanged)==null||z.call(t,S)},W=(S,A,R,z)=>{var Me;const Q=o(S),J=Q.m;if(Q.parent===0)J[12]=A,J[13]=R,J[14]=z;else{const ve=Lt(m(Q.parent));J[12]=ve[0]*A+ve[4]*R+ve[8]*z+ve[12],J[13]=ve[1]*A+ve[5]*R+ve[9]*z+ve[13],J[14]=ve[2]*A+ve[6]*R+ve[10]*z+ve[14]}(Me=t.localMatrixChanged)==null||Me.call(t,S)},N=S=>{const A=a.get(S),R=(A==null?void 0:A.overlayOf)!==void 0?a.get(A.overlayOf):A;return(R==null?void 0:R.customProjection)??(R==null?void 0:R.projection)??i},I=S=>{for(let A=S;A!==0;){for(const R of a.values())if(R.entities.has(A))return R;A=o(A).parent}return null},D=S=>{var Q;const A=(Q=e.getSourceName)==null?void 0:Q.call(e,S);if(!A)return;const R=A.startsWith("lecodesfile://")?decodeURIComponent(A.slice(14)):A;return(R.includes("/")||R.includes("\\"))&&!R.startsWith("http")?R.split(/[\\/]/).pop()??R:R},K=S=>{let A=c.get(S);return A||(A={shader:"unknown",uniforms:{}},c.set(S,A)),A},q=(S,A,R)=>{var z;K(S).uniforms[A]=R,(z=t.uniformChanged)==null||z.call(t,S,A,R)},O=S=>{const A=e.getBuffer(S),R=A?Gc(A):null,z=_();if(z.model={source:D(S),systemId:S,animations:(R==null?void 0:R.animations)??[],loaded:R!==null,...A&&{buffer:A}},R&&R.animations.length>0&&A&&bi()&&(z.model.clipSet=P.registerGlbClips(A)),!R)return{rootId:z.id,entIds:[]};const Q=R.nodes.map(()=>_().id);R.nodes.forEach((J,Me)=>{var Be;const ve=o(Q[Me]);ve.name=J.name??"",kt(ve.m,J.matrix),(Be=t.localMatrixChanged)==null||Be.call(t,ve.id),J.skinJoint&&(ve.skinJoint=!0),J.mesh&&(ve.mesh={kind:0,vertexCount:0,primitives:J.mesh.primitives},J.mesh.min&&J.mesh.max&&(ve.mesh.size=[J.mesh.max[0]-J.mesh.min[0],J.mesh.max[1]-J.mesh.min[1],J.mesh.max[2]-J.mesh.min[2]],ve.mesh.center=[(J.mesh.max[0]+J.mesh.min[0])/2,(J.mesh.max[1]+J.mesh.min[1])/2,(J.mesh.max[2]+J.mesh.min[2])/2]));for(const Oe of J.children)E(Q[Oe],ve.id,!1)});for(const J of R.roots)E(Q[J],z.id,!1);return{rootId:z.id,entIds:Q}},H=(S,A)=>{var Q,J;const R=o(S),z=_();A.set(R.id,z.id),z.name=R.name,kt(z.m,R.m),z.visible=R.visible,R.skinJoint&&(z.skinJoint=!0),R.light&&(z.light={...R.light}),R.punctual&&(z.punctual={...R.punctual}),R.mesh&&(z.mesh={...R.mesh}),z.materials=[...R.materials],R.model&&(z.model={...R.model,animations:R.model.animations}),R.castShadows!==void 0&&(z.castShadows=R.castShadows),R.receiveShadows!==void 0&&(z.receiveShadows=R.receiveShadows),R.particles&&(z.particles=structuredClone(R.particles)),R.physics&&(z.physics=structuredClone(R.physics)),R.collider&&(z.collider=structuredClone(R.collider)),(Q=t.localMatrixChanged)==null||Q.call(t,z.id),(J=t.entityCloned)==null||J.call(t,R.id,z.id);for(const Me of R.children)E(H(Me,A),z.id,!1);return z.id},G=S=>{var R;const A=l.get(S);if(A){for(const z of[...A.children])G(z);w(A);for(const z of a.values())z.entities.delete(S);(R=t.entityDestroyed)==null||R.call(t,S),P.onEntityDestroyed(S),T.onEntityDestroyed(S),l.delete(S)}},Y=S=>{for(let A=S;A!==0;A=o(A).parent)if(!o(A).visible)return!1;return!0};let se=1;const te=S=>{const A=S*se;M==null||M(S),x.frame(A,y),P.evaluate(A),x.syncRagdolls(A),d==null||d(S),P.lateSolve(),T.update(A)},ne=S=>{const A=Math.min(1e3,Math.floor(S/16));for(let R=0;R<A;R++)te(.016)},he=()=>v>=0||a.size>0,we=()=>v,de={createScene(){var A;const S=a.size;return a.set(S,{id:S,entities:new Set,overlays:[]}),(A=t.sceneCreated)==null||A.call(t,S),S},createOverlayScene(S){var R,z;const A=a.size;return a.set(A,{id:A,entities:new Set,overlays:[],overlayOf:S}),(R=a.get(S))==null||R.overlays.push(A),(z=t.sceneCreated)==null||z.call(t,A),A},createGLView(){},openScene(S){v=S},closeScene(){v=-1},addEntityToScene(S,A){var z;const R=a.get(S);if(R){for(const Q of a.values())Q!==R&&Q.entities.delete(A);R.entities.add(A),(z=t.entitySceneChanged)==null||z.call(t,A,S,!0)}},removeEntityFromScene(S,A){var z;const R=a.get(S);R&&(R.entities.delete(A),(z=t.entitySceneChanged)==null||z.call(t,A,S,!1))},createEntity:()=>_().id,cloneEntity(S){var Q,J;const A=o(S),R=new Map,z=H(S,R);if(A.parent!==0)E(z,A.parent,!1);else{const Me=I(S);Me&&(Me.entities.add(z),(Q=t.entitySceneChanged)==null||Q.call(t,z,Me.id,!0))}return(J=t.subtreeCloned)==null||J.call(t,S,z,R),z},destroyEntity(S){G(S)},setMatrix(S,A){var z;const R=o(S);kt(R.m,A),(z=t.localMatrixChanged)==null||z.call(t,S)},setWorldMatrix(S,A){var Q,J;const R=o(S);if(R.parent===0){kt(R.m,A),(Q=t.localMatrixChanged)==null||Q.call(t,S);return}const z=At(new Float32Array(16),Lt(m(R.parent)),Float32Array.from(A.subarray(0,16)));kt(R.m,z),(J=t.localMatrixChanged)==null||J.call(t,S)},getChildCount:S=>o(S).children.length,getChild:(S,A)=>o(S).children[A]??0,setPosition(S,A,R,z){var J;const Q=o(S).m;Q[12]=A,Q[13]=R,Q[14]=z,(J=t.localMatrixChanged)==null||J.call(t,S)},setQuaternion(S,A,R,z,Q){var J;ai(o(S).m,A,R,z,Q),(J=t.localMatrixChanged)==null||J.call(t,S)},setEulerAngles(S,A,R,z,Q){var J;ja(o(S).m,A,R,z,Q),(J=t.localMatrixChanged)==null||J.call(t,S)},setScale(S,A,R,z){var Q;li(o(S).m,A,R,z),(Q=t.localMatrixChanged)==null||Q.call(t,S)},setParent(S,A,R){E(S,A,R)},setParentNull(S,A){E(S,0,A)},getParent:S=>o(S).parent,traverse(S,A){const R=z=>{A(z);for(const Q of o(z).children)R(Q)};for(const z of o(S).children)R(z)},findNode(S,A){const R=Ai(A);let z=0,Q=4;const J=Me=>{const ve=o(Me),Be=iu(ve.name,!!ve.skinJoint,A,R);Be<Q&&Be>=0&&(z=Me,Q=Be);for(const Oe of ve.children){if(Q===0)return;J(Oe)}};for(const Me of o(S).children){if(Q===0)break;J(Me)}return z},createSunLight(S,A,R,z,Q,J,Me,ve=100,Be=1){o(S).light={direction:[A,R,z],intensity:Q,color:J,shadowsQuality:Me,shadowDistance:ve,shadowCascades:Be}},createPointLight(S,A,R,z,Q){o(S).punctual={type:"point",intensity:A,color:R,range:z>0?z:1,inner:0,outer:0,castShadows:Q}},createSpotLight(S,A,R,z,Q,J,Me){const[ve,Be]=Ys(Q,J);o(S).punctual={type:"spot",intensity:A,color:R,range:z>0?z:1,inner:ve,outer:Be,castShadows:Me}},setLightCone(S,A,R){var Q;const z=(Q=l.get(S))==null?void 0:Q.punctual;(z==null?void 0:z.type)==="spot"&&([z.inner,z.outer]=Ys(A,R))},setLightIntensity(S,A){const R=l.get(S);R!=null&&R.light&&(R.light.intensity=A),R!=null&&R.punctual&&(R.punctual.intensity=A)},setLightColor(S,A){const R=l.get(S);R!=null&&R.light&&(R.light.color=A),R!=null&&R.punctual&&(R.punctual.color=A)},setDefaultIbl(S,A){const R=a.get(S);R&&(R.ibl=A)},setBloomOptions(S,A,R,z,Q,J,Me,ve,Be,Oe){const Fe=a.get(S);Fe&&(Fe.bloom=A?{strength:R,threshold:z,highlight:Q,levels:J,quality:Me}:void 0)},setSkybox(S,A){const R=a.get(S);R&&(R.skybox=A)},setSceneMultiSampleAntiAliasing(S,A){const R=a.get(S);R&&(R.antialias=A)},setSceneRenderOptions(){},setMaterialGlobalParameter(){},getCameraFov(S,A){const{fov:R}=N(S);if(A!==1)return R;const z=R*Math.PI/180;return 2*Math.atan(Math.tan(z/2)*(r/n))*180/Math.PI},setCameraProjection(S,A,R,z){const Q=a.get(S);Q&&(Q.projection={fov:A,near:R,far:z})},setCameraMatrix(S,A){var z;const R=(z=a.get(S))==null?void 0:z.camera;R&&de.setWorldMatrix(R,A)},setCameraProjectionMatrix(S,A,R,z){const Q=a.get(S);if(!Q||A.length<16)return;const J=Float32Array.from(A.subarray(0,16)),Me=J[5]>0?2*Math.atan(1/J[5])*180/Math.PI:(Q.projection??i).fov;Q.customProjection={fov:Me,near:R,far:z,matrix:J}},clearCameraProjectionMatrix(S){const A=a.get(S);A&&delete A.customProjection},getMatrix(S,A){return A.set(Ve(S)),!0},getWorldMatrix(S,A){A.set(m(S))},getWorldPosition(S,A){const R=h(S);A[0]=R[12],A[1]=R[13],A[2]=R[14]},getWorldDirection(S,A,R){const z=h(S);R[0]=z[A*4],R[1]=z[A*4+1],R[2]=z[A*4+2]},getWorldMatrixInverse(S,A){A.set(Lt(m(S)))},getCameraViewDirection(S,A,R,z){var qe;const Q=(qe=a.get(S))==null?void 0:qe.camera,J=Q?h(Q):Xe(),[Me,ve]=ui(N(S),r/n,A/r*2-1,1-R/n*2),Be=J[0]*Me+J[4]*ve-J[8],Oe=J[1]*Me+J[5]*ve-J[9],Fe=J[2]*Me+J[6]*ve-J[10],Pe=Math.hypot(Be,Oe,Fe)||1;z[0]=Be/Pe,z[1]=Oe/Pe,z[2]=Fe/Pe},setMesh(S,A,R,z,Q,J,Me,ve,Be){var Ct;const Oe=o(S);let Fe=1/0,Pe=1/0,qe=1/0,wt=-1/0,Mt=-1/0,Bt=-1/0;for(let bt=0;bt+2<R.length;bt+=3){const Ye=R[bt],ut=R[bt+1],Nt=R[bt+2];Ye<Fe&&(Fe=Ye),Ye>wt&&(wt=Ye),ut<Pe&&(Pe=ut),ut>Mt&&(Mt=ut),Nt<qe&&(qe=Nt),Nt>Bt&&(Bt=Nt)}const Ut=R.length>=3,Kt={kind:Me,vertexCount:Math.floor(R.length/3),size:Ut?[wt-Fe,Mt-Pe,Bt-qe]:void 0,center:Ut?[(wt+Fe)/2,(Mt+Pe)/2,(Bt+qe)/2]:void 0};Oe.mesh=Kt,Oe.materials[0]=A,(Ct=t.meshSet)==null||Ct.call(t,S,A,Kt,{vertices:R,normals:z,indices:Q,uv:J,colors:Be})},setCulling(){},setRenderPriority(){},setMaterialDepthTest(){},setMaterialDepthWrite(){},setMaterialCulling(){},setMaterialStencil(){},setSceneStencil(){},setCastShadows(S,A){o(S).castShadows=A},setReceiveShadows(S,A){o(S).receiveShadows=A},setGlbShadows(S,A,R){const z=Q=>{const J=o(Q);J.castShadows=A,J.receiveShadows=R;for(const Me of J.children)z(Me)};z(S)},setCastShadowsGlobal(){},setReceiveShadowsGlobal(){},hasMesh:S=>o(S).mesh!==void 0,createMaterial(S){var z;const A=g++,R={shader:D(S)??"unknown",uniforms:{}};return c.set(A,R),(z=t.materialCreated)==null||z.call(t,A,R,S),A},createMaterialNamed(S){var z;const A=g++,R={shader:S,uniforms:{}};return c.set(A,R),(z=t.materialCreated)==null||z.call(t,A,R),A},setMaterial(S,A,R){o(S).materials[R]=A},getMaterial:(S,A)=>o(S).materials[A]??0,setUniformRgb(S,A,R){q(S,A,{kind:"rgb",v:R})},setUniformRgba(S,A,R){q(S,A,{kind:"rgba",v:R})},setUniformFloat(S,A,R){q(S,A,{kind:"float",v:R})},setUniformBoolean(S,A,R){q(S,A,{kind:"bool",v:R})},setUniformTexture(S,A,R){q(S,A,{kind:"texture",v:R})},setUniformArray(S,A,R){q(S,A,{kind:"array",v:Array.from(R)})},setUniformNull(S,A){q(S,A,{kind:"null"})},createTexture(S,A,R){const z=e.getBuffer(S);if(!z||z.byteLength===0){R();return}const[Q,J]=au(z),Me=u++;f.set(Me,{source:D(S),width:Q,height:J}),A(Me,Q,J)},createTextureFromCanvas(S){const A=u++;return f.set(A,{source:`canvas#${S}`,width:0,height:0}),A},updateTextureFromCanvas(){},createTexturePixels(S,A,R){const z=u++;return f.set(z,{source:`pixels ${S}x${A}x${R}`,width:S,height:A}),z},updateTexturePixels(){},createMediaPlayerTexture(S){const A=u++;return f.set(A,{source:`mediaplayer#${S}`,width:0,height:0}),A},attachCameraToAR(S,A,R){const z=a.get(S);z&&(z.camera=A);const Q=N(S);R(Q.matrix?Float32Array.from(Q.matrix):Sn(Q.fov,r/n,Q.near,Q.far),Q.fov)},getDisplaySize:()=>Float32Array.of(r,n),setVisible(S,A){var z;o(S).visible=A,(z=t.visibleChanged)==null||z.call(t,S,A);const R=Q=>{const J=o(Q);J.particles&&T.setVisible(Q,Y(Q));for(const Me of J.children)R(Me)};R(S)},isVisible:S=>Y(S),getName:S=>o(S).name,setName(S,A){o(S).name=A},createGlb(S,A,R){const{rootId:z,entIds:Q}=O(S);if(!t.glbAttach){A(z);return}Promise.resolve(t.glbAttach(S,z,Q)).then(()=>A(z)).catch(J=>R==null?void 0:R(J))},setGlbCulling(){},getGlbClipSet:S=>{var A,R;return((R=(A=l.get(S))==null?void 0:A.model)==null?void 0:R.clipSet)??0},...P.methods,setEarlyUpdate(S){M=S},setLateUpdate(S){d=S},setFixedUpdate(S){y=S},setTimeScale(S){se=Number.isFinite(S)&&S>0?S:0},...x.methods,...T.methods};function Ve(S){const A=o(S).m;return A instanceof Float32Array?A:Float32Array.from(A)}let je=null;return{width:r,height:n,fov:s,entities:l,scenes:a,materials:c,textures:f,cameraOverride:()=>je,setCameraOverride:S=>{je=S},ent:o,newEnt:_,worldMatrix:h,worldMatrixF:m,sourceName:D,setParentInternal:E,sceneOf:I,projectionOf:N,rebindMatrix:(S,A)=>{o(S).m=A},methods:de,simulate:ne,tick:te,hasActiveScene:he,activeSceneId:we,physicsConfig:x.config,particleIndexPattern:T.indexPattern,nextTextureId:()=>u++,nextMaterialId:()=>g++}}const au=t=>{const e=new Uint8Array(t);if(e.length>24&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71){const r=new DataView(t);return[r.getUint32(16),r.getUint32(20)]}if(e.length>=28&&e[0]===171&&e[1]===75&&e[2]===84&&e[3]===88&&e[4]===32&&e[5]===50&&e[6]===48&&e[7]===187){const r=new DataView(t);return[r.getUint32(20,!0),r.getUint32(24,!0)]}if(e.length>4&&e[0]===255&&e[1]===216){const r=new DataView(t);let n=2;for(;n+9<e.length&&e[n]===255;){const s=e[n+1];if(s>=192&&s<=207&&s!==196&&s!==200&&s!==204)return[r.getUint16(n+7),r.getUint16(n+5)];n+=2+r.getUint16(n+2)}}return[0,0]},Wt=(t,e)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},Si=(t,e)=>{var f,p;const r=(f=e.mesh)==null?void 0:f.size;if(!r)return[];const n=((p=e.mesh)==null?void 0:p.center)??[0,0,0],s=r[0]/2,i=r[1]/2,l=r[2]/2,a=t.worldMatrixF(e.id),c=[];for(let g=0;g<8;g++){const u=n[0]+(g&1?s:-s),v=n[1]+(g&2?i:-i),M=n[2]+(g&4?l:-l);c.push([a[0]*u+a[4]*v+a[8]*M+a[12],a[1]*u+a[5]*v+a[9]*M+a[13],a[2]*u+a[6]*v+a[10]*M+a[14]])}return c},lu=(t,e)=>{const r=[],n=s=>{const i=t.entities.get(s);if(i){r.push(...Si(t,i));for(const l of i.children)n(l)}};return n(e),r};function cu(t,e){const r=e.camera,n=t.cameraOverride();if(!n&&(r===void 0||!t.entities.has(r)))return;const s=t.width,i=t.height,{fov:l,near:a,far:c,matrix:f}=t.projectionOf(e.id),p=(n==null?void 0:n.fov)!==void 0?Sn(n.fov,s/i,a,c):f??Sn(l,s/i,a,c),g=n?Ka(n.eye,n.target):Lt(t.worldMatrixF(r)),u=At(new Float32Array(16),p,g),v=(_,o,h)=>{const m=u[3]*_+u[7]*o+u[11]*h+u[15],w=u[0]*_+u[4]*o+u[8]*h+u[12],E=u[1]*_+u[5]*o+u[9]*h+u[13],B=m>1e-4;return B?{sx:(w/m*.5+.5)*s,sy:(1-(E/m*.5+.5))*i,cw:m,inFront:B}:{sx:0,sy:0,cw:m,inFront:B}},M=_=>{for(let o=_;o!==0;o=t.ent(o).parent)if(!t.ent(o).visible)return!1;return!0},d=[e,...e.overlays.map(_=>t.scenes.get(_)).filter(_=>!!_)],y=new Set,x=[],T=_=>{if(!(y.has(_)||!t.entities.has(_))){y.add(_),x.push(_);for(const o of t.ent(_).children)T(o)}};for(const _ of d)for(const o of _.entities)T(o);const P=[];for(const _ of x){const o=t.ent(_);if(!M(_))continue;const h=o.model?"model":o.mesh&&!o.light?"mesh":o.particles?"particles":null;if(!h)continue;let m;if(h==="model")m=lu(t,_);else if(h==="mesh")m=Si(t,o);else{const z=t.worldMatrixF(_);m=[[z[12],z[13],z[14]]]}if(m.length===0)continue;let w=1/0,E=1/0,B=1/0,W=-1/0,N=-1/0,I=-1/0;for(const z of m)z[0]<w&&(w=z[0]),z[0]>W&&(W=z[0]),z[1]<E&&(E=z[1]),z[1]>N&&(N=z[1]),z[2]<B&&(B=z[2]),z[2]>I&&(I=z[2]);const D=v((w+W)/2,(E+N)/2,(B+I)/2);let K=!1,q=!1,O=1/0,H=1/0,G=-1/0,Y=-1/0;for(const z of m){const Q=v(z[0],z[1],z[2]);if(!Q.inFront){K=!0;continue}q=!0,Q.sx<O&&(O=Q.sx),Q.sx>G&&(G=Q.sx),Q.sy<H&&(H=Q.sy),Q.sy>Y&&(Y=Q.sy)}const se={kind:h,depth:Wt(D.cw,3),coverage:0};if(o.name&&(se.name=o.name),!q){se.behindCamera=!0,P.push({obj:se,id:_});continue}const te=O,ne=H,he=Math.max(0,G-O),we=Math.max(0,Y-H);se.rect=[Wt(te,1),Wt(ne,1),Wt(he,1),Wt(we,1)],D.inFront&&(se.center=[Wt(D.sx,1),Wt(D.sy,1)]);const de=Math.max(0,te),Ve=Math.max(0,ne),je=Math.min(s,te+he),S=Math.min(i,ne+we),A=Math.max(0,je-de)*Math.max(0,S-Ve);se.coverage=Wt(A/(s*i),4);const R=te>=0&&ne>=0&&te+he<=s&&ne+we<=i;A===0?se.offscreen=!0:(K||!R)&&(se.clipped=!0),P.push({obj:se,id:_})}const L=_=>{const o=[];for(let h=_;h!==0;h=t.ent(h).parent)o.unshift(t.ent(h).name||"~");for(;o.length>0&&o[0]==="~";)o.shift();return o.join("/")};for(const{obj:_,id:o}of P)_.name&&(_.path=L(o));return P.sort((_,o)=>o.obj.coverage-_.obj.coverage||_.obj.depth-o.obj.depth),{viewport:{width:s,height:i},note:(n?"INSPECTION camera (not the app's) — ":"")+"screen px, top-left origin; depth is a camera-distance hint, not true occlusion; rects are rest-pose (headless doesn't sample animation)",objects:P.map(_=>_.obj)}}const $t=(t,e=4)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},rr=(t,e=4)=>Array.from(t,r=>$t(r,e)),Cr=(t,e)=>"#"+(t>>>0).toString(16).padStart(e?8:6,"0");function uu(t,e){const{entities:r,scenes:n,materials:s,textures:i,worldMatrixF:l}=t,a=M=>{var d;switch(M.kind){case"rgb":return Cr(M.v,!1);case"rgba":return Cr(M.v,!0);case"texture":return((d=i.get(M.v))==null?void 0:d.source)??`texture#${M.v}`;case"null":return null;default:return M.v}},c=M=>{const d=s.get(M);if(!d)return;const y={shader:d.shader.replace(/\.filamat$/,"")};for(const[x,T]of Object.entries(d.uniforms))y[x]=a(T);return y},f=M=>{var o;const d=t.ent(M),y=d.m,x=rr([y[12],y[13],y[14]]),T=ys(y).map(h=>$t(h,2)),P=Or(y).map(h=>$t(h,4)),L=d.light||d.punctual?"light":d.model?"model":d.mesh?"mesh":d.particles?"particles":"node",_={};if(d.name&&(_.name=d.name),_.kind=L,x.some(h=>h!==0)&&(_.position=x),T.some(h=>h!==0)&&(_.rotation=T),P.some(h=>h!==1)&&(_.scale=P),d.visible||(_.visible=!1),d.mesh){const h={type:d.mesh.kind===1?"edges":d.mesh.kind===2?"vertices":"triangles"};d.mesh.size&&(h.size=rr(d.mesh.size)),(o=d.mesh.center)!=null&&o.some(w=>$t(w)!==0)&&(h.center=rr(d.mesh.center)),_.mesh=h;const m=c(d.materials[0]);m&&(_.material=m)}if(d.model&&(_.model={...d.model.source&&{source:d.model.source},...!d.model.loaded&&{loaded:!1},animations:d.model.animations.map(h=>({name:h.name,duration:$t(h.duration,2)}))}),d.light&&(_.light={type:"sun",direction:rr(d.light.direction),intensity:d.light.intensity,color:Cr(d.light.color,!1),shadows:d.light.shadowsQuality}),d.punctual){const h=d.punctual;_.light={type:h.type,intensity:h.intensity,color:Cr(h.color,!1),range:h.range,...h.type==="spot"&&{angle:$t(h.outer*360/Math.PI,2),innerAngle:$t(h.inner*360/Math.PI,2)},...h.castShadows&&{castShadows:!0}}}return d.particles&&(_.particles=d.particles),d.physics&&(_.physics=d.physics),d.ragdoll&&(_.ragdoll=d.ragdoll),d.collider&&(_.collider=d.collider),d.castShadows!==void 0&&(_.castShadows=d.castShadows),d.receiveShadows!==void 0&&(_.receiveShadows=d.receiveShadows),d.children.length>0&&(_.children=d.children.map(f)),_},p=M=>{const d=P=>{for(let L=t.ent(P).parent;L!==0;L=t.ent(L).parent)if(M.entities.has(L))return!0;return!1},y=[...M.entities].filter(P=>r.has(P)&&!d(P)),x={};M.skybox!==void 0&&(x.skybox=Cr(M.skybox,!1)),M.ibl!==void 0&&(x.environment={intensity:M.ibl}),M.bloom&&(x.bloom={...M.bloom});const T=t.cameraOverride();if(T)x.camera={position:rr(T.eye),lookAt:rr(T.target),fov:T.fov??t.projectionOf(M.id).fov,inspection:!0};else if(M.camera!==void 0&&r.has(M.camera)){const P=l(M.camera),L=ys(P).map(_=>$t(_,2));x.camera={position:rr([P[12],P[13],P[14]]),...L.some(_=>_!==0)&&{rotation:L},fov:t.projectionOf(M.id).fov}}return x.nodes=y.map(f),M.overlays.length>0&&(x.overlays=M.overlays.map(P=>n.get(P)).filter(Boolean).map(P=>p(P))),x},g=n.get(t.activeSceneId())??[...n.values()].find(M=>M.overlayOf===void 0);if(!g)return null;const u=p(g),v=cu(t,g);return v&&(u.frame=v),u}const Fr='AR is the "ar" plugin since 2.3: add it to "plugins" of app.json',Ks=new Set,V=t=>{Ks.has(t)||(Ks.add(t),console.warn(`[gl-lite] ${t}: not supported by the lite 3D engine`))},hu={createEngine(){V("createEngine")},createScene(){return V("createScene"),0},createOverlayScene(){return V("createOverlayScene"),0},createGLView(){V("createGLView")},openScene(){V("openScene")},closeScene(){V("closeScene")},launchAR(){V("launchAR")},stopAR(){V("stopAR")},launchVR(){V("launchVR")},stopVR(){V("stopVR")},addEntityToScene(){V("addEntityToScene")},removeEntityFromScene(){V("removeEntityFromScene")},warmRender(){V("warmRender")},createEntity(){return V("createEntity"),{id:0}},cloneEntity(){return V("cloneEntity"),{id:0}},destroyEntity(){V("destroyEntity")},entityIsOwned(){return V("entityIsOwned"),!1},setMatrix(){V("setMatrix")},setWorldMatrix(){V("setWorldMatrix")},getChildCount(){return V("getChildCount"),0},getChild(){return V("getChild"),0},setPosition(){V("setPosition")},setQuaternion(){V("setQuaternion")},setEulerAngles(){V("setEulerAngles")},setScale(){V("setScale")},setParent(){V("setParent")},setParentNull(){V("setParentNull")},getParent(){return V("getParent"),0},traverse(){V("traverse")},createSunLight(){V("createSunLight")},setDefaultIbl(){V("setDefaultIbl")},setBloomOptions(){V("setBloomOptions")},setSkybox(){V("setSkybox")},setSceneMultiSampleAntiAliasing(){V("setSceneMultiSampleAntiAliasing")},setMaterialGlobalParameter(){V("setMaterialGlobalParameter")},getCameraFov(){return V("getCameraFov"),0},getMatrix(){V("getMatrix")},getWorldMatrix(){V("getWorldMatrix")},getWorldPosition(){V("getWorldPosition")},getWorldDirection(){V("getWorldDirection")},getWorldMatrixInverse(){V("getWorldMatrixInverse")},getCameraViewDirection(){V("getCameraViewDirection")},setMesh(){V("setMesh")},createInstancedMesh(){V("createInstancedMesh")},setInstanceTransforms(){V("setInstanceTransforms")},setInstancedMeshMaterial(){V("setInstancedMeshMaterial")},setInstancedMeshShadows(){V("setInstancedMeshShadows")},setCulling(){V("setCulling")},setCastShadows(){V("setCastShadows")},setReceiveShadows(){V("setReceiveShadows")},createTexture(){V("createTexture")},createTextureFromCanvas(){return V("createTextureFromCanvas"),0},updateTextureFromCanvas(){V("updateTextureFromCanvas")},createMaterial(){return V("createMaterial"),{id:0}},builtinMaterial(){return V("builtinMaterial"),null},setMaterial(){V("setMaterial")},getMaterial(){return V("getMaterial"),0},setUniformRgb(){V("setUniformRgb")},setUniformRgba(){V("setUniformRgba")},setUniformFloat(){V("setUniformFloat")},setUniformBoolean(){V("setUniformBoolean")},setUniformTexture(){V("setUniformTexture")},setUniformArray(){V("setUniformArray")},setUniformNull(){V("setUniformNull")},attachCameraToAR(){V("attachCameraToAR")},getDisplaySize(){return V("getDisplaySize"),new Float32Array(0)},setVisible(){V("setVisible")},isVisible(){return V("isVisible"),!1},createGlb(){V("createGlb")},setGlbCulling(){V("setGlbCulling")},setEarlyUpdate(){V("setEarlyUpdate")},setLateUpdate(){V("setLateUpdate")},setOnPhysicsEvent(){V("setOnPhysicsEvent")},loadClips(){V("loadClips")},createClipFromTracks(){return V("createClipFromTracks"),0},getClipSetInfo(){return V("getClipSetInfo"),[]},deriveClip(){return V("deriveClip"),0},setClipEvents(){V("setClipEvents")},getGlbClipSet(){return V("getGlbClipSet"),0},destroyClipSet(){V("destroyClipSet")},animatorCreate(){return V("animatorCreate"),0},animatorDestroy(){V("animatorDestroy")},animatorBind(){return V("animatorBind"),0},animatorBoundTracks(){return V("animatorBoundTracks"),0},animatorSetBlend(){V("animatorSetBlend")},animatorSetBlendValue(){V("animatorSetBlendValue")},animatorPlay(){V("animatorPlay")},animatorStop(){V("animatorStop")},animatorSeek(){V("animatorSeek")},animatorGetSlotTime(){return V("animatorGetSlotTime"),0},animatorGetSlotWeight(){return V("animatorGetSlotWeight"),0},animatorSetLayer(){V("animatorSetLayer")},animatorSetGlobal(){V("animatorSetGlobal")},animatorSetRootMotion(){V("animatorSetRootMotion")},animatorGetRootMotion(){V("animatorGetRootMotion")},setOnAnimatorEvent(){V("setOnAnimatorEvent")},animatorSetFeet(){V("animatorSetFeet")},animatorSlotCurveAt(){return V("animatorSlotCurveAt"),0},animatorSlotCurveInfo(){return V("animatorSlotCurveInfo"),!1},animatorSlotTurn(){return V("animatorSlotTurn"),0},animatorSlotTimeAtTurn(){return V("animatorSlotTimeAtTurn"),0},animatorLayerPhase(){return V("animatorLayerPhase"),0},animatorSeekPhase(){V("animatorSeekPhase")},animatorSlotFit(){return V("animatorSlotFit"),0},animatorSlotExit(){return V("animatorSlotExit"),0},animatorSlotAlign(){return V("animatorSlotAlign"),0},animatorSlotContacts(){return V("animatorSlotContacts"),0},animatorSlotTreads(){return V("animatorSlotTreads"),0},animatorSlotPhysics(){return V("animatorSlotPhysics"),0},animatorSlotFeatures(){return V("animatorSlotFeatures"),0},animatorKneeAxis(){return V("animatorKneeAxis"),0},animatorSlotKneePole(){return V("animatorSlotKneePole"),0},animatorSetStepWarp(){V("animatorSetStepWarp")},setOnAnimatorStep(){V("setOnAnimatorStep")},animatorSetMotion(){V("animatorSetMotion")},animatorSetDriveInput(){V("animatorSetDriveInput")},animatorSetSlotDrive(){V("animatorSetSlotDrive")},animatorSetWarpParams(){V("animatorSetWarpParams")},locoCreate(){return V("locoCreate"),0},locoDestroy(){V("locoDestroy")},locoSetParams(){V("locoSetParams")},locoDefaults(){V("locoDefaults")},locoSetEntry(){V("locoSetEntry")},locoClearSet(){V("locoClearSet")},locoSetInput(){V("locoSetInput")},locoStep(){V("locoStep")},locoUpdate(){V("locoUpdate")},locoRead(){V("locoRead")},locoBuildDatabase(){return V("locoBuildDatabase"),0},setColliderFromMesh(){V("setColliderFromMesh")},setColliderBox(){V("setColliderBox")},setColliderSphere(){V("setColliderSphere")},physicsHasSupport(){return V("physicsHasSupport"),!1},physicsConfigure(){V("physicsConfigure")},setInterpolation(){V("setInterpolation")},physicsBuildBox(){return V("physicsBuildBox"),0},physicsBuildSphere(){return V("physicsBuildSphere"),0},physicsBuildCylinder(){return V("physicsBuildCylinder"),0},physicsBuildCapsule(){return V("physicsBuildCapsule"),0},physicsBuildMesh(){return V("physicsBuildMesh"),0},physicsBuildMeshFromEntity(){return V("physicsBuildMeshFromEntity"),0},physicsDestroyShape(){V("physicsDestroyShape")},physicsCreateBody(){return V("physicsCreateBody"),0},physicsSetPickable(){V("physicsSetPickable")},physicsSetFriction(){V("physicsSetFriction")},physicsGetFriction(){return V("physicsGetFriction"),0},physicsRaycast(){return V("physicsRaycast"),0},characterCreate(){return V("characterCreate"),0},characterDestroy(){V("characterDestroy")},characterMove(){V("characterMove")},characterMoveFree(){V("characterMoveFree")},characterSetVerticalVelocity(){V("characterSetVerticalVelocity")},characterSetVelocity(){V("characterSetVelocity")},characterSetGravityScale(){V("characterSetGravityScale")},characterSetMaxSlope(){V("characterSetMaxSlope")},characterGetVelocity(){V("characterGetVelocity")},characterGetGroundState(){return V("characterGetGroundState"),0},characterSetPosition(){V("characterSetPosition")},vehicleCreate(){return V("vehicleCreate"),0},vehicleDestroy(){V("vehicleDestroy")},vehicleSetInput(){V("vehicleSetInput")},vehicleGetState(){V("vehicleGetState")},vehicleReset(){V("vehicleReset")},vehicleBodyId(){return V("vehicleBodyId"),0},physicsCreateBox(){return V("physicsCreateBox"),0},physicsCreateSphere(){return V("physicsCreateSphere"),0},physicsCreateCylinder(){return V("physicsCreateCylinder"),0},physicsSetLinearVelocity(){V("physicsSetLinearVelocity")},physicsGetLinearVelocity(){V("physicsGetLinearVelocity")},physicsApplyImpulse(){V("physicsApplyImpulse")},physicsSetBodyPosition(){V("physicsSetBodyPosition")},physicsRemoveBody(){V("physicsRemoveBody")},createMediaPlayerTexture(){return V("createMediaPlayerTexture"),0},getName(){return V("getName"),""},setName(){V("setName")},hasMesh(){return V("hasMesh"),!1},createARController(){V("createARController")},createRootAnchor(){return V("createRootAnchor"),0},createAnchor(){return V("createAnchor"),0},createParticleSystem(){V("createParticleSystem")},spawnParticles(){V("spawnParticles")},setParticleSystemConfig(){V("setParticleSystemConfig")},createNoise(){return V("createNoise"),0},setNoiseFrequency(){V("setNoiseFrequency")},setNoiseOctaves(){V("setNoiseOctaves")},setNoiseFractalLunacrity(){V("setNoiseFractalLunacrity")},setNoiseFractalGain(){V("setNoiseFractalGain")},getNoise2D(){return V("getNoise2D"),0},getNoise3D(){return V("getNoise3D"),0},captureImage(){V("captureImage")}},fu=""+new URL("neutral_ibl128-D-lzdkLN.ktx",import.meta.url).href,du={backend:"webgl-lite"},xn=60,wn=.01,Mn=1e3,mu={baseColorFactor:"uBaseColorFactor",metallicFactor:"uMetallic",roughnessFactor:"uRoughness",emissiveFactor:"uEmissive",baseColorMap:"uBaseColorMap",baseColorIndex:"uBaseColorIndex"},pu=async(t,e={})=>{var Ln;const{fetch:r,getBlob:n,getBuffer:s,getLocalName:i,hasLocalBuffer:l,putBuffer:a,putLocalBuffer:c,getPlayer:f,removePlayers:p}=e.stores??Xa,g=new lo({canvas:t,dpr:1,alpha:e.transparent===!0||e.alpha===!0,antialias:!0,premultipliedAlpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:((Ln=e.preloads)==null?void 0:Ln.has("capture"))??!1}),u=g.gl;g.autoClear=!1;const v=El(u),M=Cl(u);for(const b of["lit.filamat","unlit.filamat","unlit-transparent.filamat","video.filamat","shadow.filamat","particles.filamat","particles-quad.filamat","terrain.filamat"])l(b)||c(b,new ArrayBuffer(0));const d={sunDirection:{value:[0,-1,0]},sunColorIntensity:{value:[1,1,1,0]},iblLuminance:{value:0},iblSH:{value:new Array(27).fill(0)},envMap:{value:M},envMapMaxLod:{value:0},shadowMap:{value:v},shadowEnabled:{value:0},shadowMapSize:{value:1024},shadowMatrix:{value:Xe()},exposure:{value:Qa},punctualCount:{value:0},punctualPos:{value:new Array(nr*4).fill(0)},punctualColor:{value:new Array(nr*4).fill(0)},punctualDir:{value:new Array(nr*4).fill(0)},uTonemap:{value:1}},y={value:[0,0,0,0]};let x=null;fetch(fu).then(b=>b.arrayBuffer()).then(b=>{x=yl(u,b),d.envMap.value=x.cubemap,d.envMapMaxLod.value=x.maxLod,d.iblSH.value=Array.from(x.sh)}).catch(b=>console.warn("[viewer-lite] IBL load failed:",b));const T=new Map,P=new Map,L=new Map,_=new Map,o=new Map,h=new Map,m={value:1},w=new Map;let E=1,B=!0,W=!0,N=null;const I=[],D=b=>{let C=T.get(b);if(!C){const F=new gt;F.matrixAutoUpdate=!1,F._entId=b,C={transform:F,drawables:[]},T.set(b,C)}return C},K=(b,C=!1)=>{let F,U=null;if(b==="lit")U=el,F=new ze(u,{vertex:er,fragment:U,uniforms:{...d,baseColor:{value:[1,1,1]},baseColorMap:{value:v},roughness:{value:0},metallic:{value:0}}});else if(b==="terrain")U=tl,F=new ze(u,{vertex:er,fragment:U,uniforms:{...d,control:{value:v},albedo0:{value:v},albedo1:{value:v},albedo2:{value:v},albedo3:{value:v},normals01:{value:v},normals23:{value:v},tiling:{value:[8,8,8,8]},roughness:{value:[1,1,1,1]},normalScale:{value:[0,0,0,0]},triplanar:{value:[0,0,0,0]},gridSize:{value:[2,2]},cellSize:{value:1},tint:{value:[1,1,1]}}});else if(b==="video")U=sl,F=new ze(u,{vertex:er,fragment:U,uniforms:{baseColorMap:{value:v},shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap}});else if(b==="shadow")U=il,F=new ze(u,{vertex:er,fragment:U,uniforms:{...d,color:{value:[0,0,0,.66]}},transparent:!0}),F.setBlendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA);else if(b==="particles"||b==="particles-quad"){const k=b==="particles-quad";F=new ze(u,{vertex:k?fl:ul,fragment:k?dl:hl,uniforms:{baseColorMap:{value:v},sheetSize:{value:[1,1]},emissive:{value:0},additive:{value:0},softness:{value:0},depthFade:{value:0},uTonemap:d.uTonemap,...k?{mode:{value:0},stretch:{value:0},emissiveMap:{value:v},emissiveColor:{value:[0,0,0]},frameBlend:{value:0}}:{perspScale:m}},transparent:!0,depthWrite:!1,cullFace:!1}),F.setBlendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA)}else U=C?nl:rl,F=new ze(u,{vertex:er,fragment:U,uniforms:{baseColor:{value:[1,1,1,1]},baseColorMap:{value:v},shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap},transparent:C}),C&&F.setBlendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA);return U===null?{kind:b,program:F}:{kind:b,program:F,source:q(U)}},q=b=>({fragment:()=>b,vertex:""}),O=b=>{const C=Pl(s(b));if(!C)return null;if(C.unsupported)return console.warn(`[viewer-lite] custom material not supported in lite (${C.unsupported}) — rendering unlit`),null;C.hasVertexBlock&&console.warn("[viewer-lite] custom material has a vertex{} block — the custom vertex stage is ignored in lite");const F=Ol(C);if(!F)return null;const U=F.needsSceneUniforms?{...d,userTime:y}:{shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap,userTime:y};for(const ee of F.uniforms)U[ee.key]={value:ee.value==="texture"?v:ee.value};const k=C.blending==="opaque"||C.blending==="masked",j=new ze(u,{vertex:er,fragment:F.fragment,uniforms:U,transparent:!k,cullFace:C.doubleSided||C.culling==="none"?!1:C.culling==="front"?u.FRONT:u.BACK,depthWrite:C.depthWrite});return u.getProgramParameter(j.program,u.LINK_STATUS)?(k||j.setBlendFunc(u.ONE,C.blending==="add"?u.ONE:u.ONE_MINUS_SRC_ALPHA),{kind:"custom",program:j,source:q(F.fragment),customParams:F.paramNames}):(console.warn("[viewer-lite] custom material failed to compile — rendering unlit"),null)},H=(b,C)=>{const F=b.startsWith("lit")?"lit":b.startsWith("unlit")?"unlit":b.startsWith("video")?"video":b.startsWith("shadow")?"shadow":b.startsWith("terrain")?"terrain":b.startsWith("particles-quad")?"particles-quad":b.startsWith("particles")?"particles":"unknown";if(F==="unknown"&&C!==void 0){const U=O(C);if(U)return U;console.warn(`[viewer-lite] custom shader can't run here (material "${b||C}") — rendering unlit`)}return K(F,b.startsWith("unlit-transparent"))},G=(b,C)=>{if(!b.source)return b.program;const F=gi(C);if(F===b.source.vertex)return b.program;b.variants??(b.variants=new Map);let U=b.variants.get(F);if(U===void 0){const k=b.program,j=new ze(u,{vertex:_n(F),fragment:b.source.fragment(F),uniforms:k.uniforms,transparent:k.transparent,cullFace:k.cullFace,frontFace:k.frontFace,depthTest:k.depthTest,depthWrite:k.depthWrite,depthFunc:k.depthFunc});j.blendFunc={...k.blendFunc},j.blendEquation={...k.blendEquation},u.getProgramParameter(j.program,u.LINK_STATUS)?U=j:(j.remove(),U=null,console.warn(`[viewer-lite] a "${b.kind}" material has no variant for [${F}] — the mesh is drawn with its base program`)),b.variants.set(F,U)}return U??b.program},Y=b=>{const C=[b.program];if(b.variants)for(const F of b.variants.values())F&&C.push(F);return C},se=(b,C)=>{var k;const F=b.kind==="gltf"?mu[C]??C:(k=b.customParams)!=null&&k.has(C)?`materialParams_${C}`:C,U=b.program.uniforms;return U[F]||(U[F]={value:0}),U[F]},te=(b,C,F)=>{const U=_.get(b);if(!U)return;if(C==="useBaseColorMap"&&(U.kind==="lit"||U.kind==="unlit")){if(F.kind==="bool"&&!F.v){const j=se(U,"baseColorMap");j.value instanceof Qe&&(j.value=v)}return}const k=se(U,C);switch(F.kind){case"rgb":{const[j,ee,ie]=ll(F.v);Array.isArray(k.value)&&k.value.length===4?k.value=[j,ee,ie,k.value[3]]:k.value=[j,ee,ie];break}case"rgba":{const j=cl(F.v);k.value=Array.isArray(k.value)&&k.value.length===3?j.slice(0,3):j;break}case"float":k.value=F.v;break;case"bool":k.value=F.v?1:0;break;case"array":k.value=Float32Array.from(F.v);break;case"texture":{const j=o.get(F.v);j&&(k.value=j);break}case"null":k.value instanceof Qe&&(k.value=v);break}},ne=(b,C)=>{C.kind!=="lit"&&C.kind!=="gltf"&&C.kind!=="shadow"&&C.kind!=="custom"||b.onBeforeRender(()=>{const F=b.program.uniforms;if(F.shadowEnabled){const U=d.shadowEnabled.value===1&&b._receiveShadows!==!1;F.shadowEnabled=U?d.shadowEnabled:{value:0}}})},he=(b,C,F,U)=>{const k=_.get(C);if(!k)return;const{vertices:j,normals:ee,indices:ie,uv:fe,colors:ce}=F,Ae=new ct(u,{position:{size:3,data:Float32Array.from(j)},normal:{size:3,data:ee.length?Float32Array.from(ee):new Float32Array(j.length)},uv:{size:2,data:fe.length?Float32Array.from(fe):new Float32Array(j.length/3*2)},...ce&&ce.length?{color:{size:4,data:Float32Array.from(ce,Ge=>Ge/255)}}:{},index:{data:Uint16Array.from(ie)}});Ae.computeBoundingBox();const pe=U===1?u.LINES:U===2?u.POINTS:u.TRIANGLES,ge=new nt(u,{geometry:Ae,program:k.program,mode:pe});ge.program=G(k,ge),ge.matrixAutoUpdate=!1,ge._entId=b,ge._castShadows=B,ge._receiveShadows=W,ne(ge,k);const _e=D(b);for(const Ge of _e.drawables){_e.transform.removeChild(Ge);const ot=J.get(Ge);ot&&(ot.setParent(null),J.delete(Ge))}_e.drawables=[ge],_e.transform.addChild(ge)},we=async(b,C,F)=>{const U=s(b);let k;try{k=await Rl(u,U,d,v)}catch(j){console.warn(`[viewer-lite] GLB "${i(b)??b}" drawables failed to load:`,j instanceof Error?j.message:j);return}k.nodes.forEach((j,ee)=>{const ie=F[ee];if(ie===void 0)return;const fe=D(ie);fe.transform.setParent(null),ye.rebindMatrix(ie,j.matrix),j.matrixAutoUpdate=!1,j._entId=ie,fe.transform=j,fe.drawables=[];for(const ce of j.children)ce.draw&&(ce.matrixAutoUpdate=!1,ce._entId=ie,ce._castShadows=B,ce._receiveShadows=W,fe.drawables.push(ce))});for(const j of k.roots)j.setParent(D(C).transform)},de=[],Ve=(b,C)=>{const F=D(b),U=D(C);for(const k of F.drawables){const j=k instanceof Rt?new Rt(u,{skeleton:k.skeleton,geometry:k.geometry,program:k.program,mode:k.mode}):new nt(u,{geometry:k.geometry,program:k.program,mode:k.mode});j instanceof Rt&&de.push(j);const ee=k._morph;ee&&(j._morph=ee,vi(j,ee)),j._entId=C,j._castShadows=k._castShadows,j._receiveShadows=k._receiveShadows,j.frustumCulled=k.frustumCulled,j.matrixAutoUpdate=!1,U.drawables.push(j),U.transform.addChild(j)}},je=b=>{for(const C of de.splice(0)){const F=C.skeleton.joints.map(U=>{const k=U._entId===void 0?void 0:b.get(U._entId);if(k===void 0)return U;const j=D(k).transform;return j.bindInverse=U.bindInverse,j});C.skeleton={...C.skeleton,joints:F}}};let S="off";const A={value:[.05,.06,.08]},R=new ze(u,{vertex:er,fragment:ws,uniforms:{uWireColor:A,shadowMatrix:d.shadowMatrix}}),z=new ze(u,{vertex:_n("HAS_SKIN"),fragment:ws,uniforms:{uWireColor:A,shadowMatrix:d.shadowMatrix,boneTexture:{value:v},boneTextureSize:{value:4}}}),Q=new WeakMap,J=new WeakMap,Me=b=>{var F;let C=Q.get(b);if(!C){const U={};for(const[ee,ie]of Object.entries(b.attributes))ee!=="index"&&(U[ee]={size:ie.size,data:ie.data,type:ie.type,normalized:ie.normalized,stride:ie.stride,offset:ie.offset,buffer:ie.buffer,count:ie.count});const k=b.attributes.position,j=k?k.count??k.data.length/k.size:0;U.index={data:_l((F=b.attributes.index)==null?void 0:F.data,j)},C=new ct(u,U),Q.set(b,C)}return C},ve=b=>{var U,k;let C=J.get(b);if(C)return C;if(!b.parent||!((k=(U=b.geometry)==null?void 0:U.attributes)!=null&&k.position))return null;const F=Me(b.geometry);return C=b instanceof Rt?new Rt(u,{skeleton:b.skeleton,geometry:F,program:z,mode:u.LINES}):new nt(u,{geometry:F,program:R,mode:u.LINES}),C.frustumCulled=!1,C.matrixAutoUpdate=!1,C.matrix.copy(b.matrix),C._entId=b._entId,C._castShadows=!1,C._receiveShadows=!1,C.setParent(b.parent),J.set(b,C),He(),C},Be=()=>{for(const b of T.values())for(const C of b.drawables)if(C.mode===u.TRIANGLES)if(S==="off"){C.visible=!0;const F=J.get(C);F&&(F.visible=!1)}else{const F=ve(C);C.visible=S==="overlay",F&&(F.visible=!0)}},Oe=()=>{for(const b of I)b.video.videoWidth===0||b.video.currentTime===b.lastTime||(b.texture.image=b.video,b.texture.needsUpdate=!0,b.lastTime=b.video.currentTime)},Fe=new Tn(u,{fov:xn,near:wn,far:Mn,aspect:1});Fe.matrixAutoUpdate=!1;let Pe=!1,qe=e.transparent===!0,wt=0,Mt=0,Bt=xn,Ut=wn,Kt=Mn,Ct=null,bt=!1,Ye=1,ut=null,Nt=0;const Ar=new ze(u,{vertex:Rr(!1),fragment:Pr,uniforms:{modelMatrix:{value:Xe()},shadowViewProjection:{value:Xe()}},cullFace:u.FRONT}),Ur=new ze(u,{vertex:Rr(!0),fragment:Pr,uniforms:{modelMatrix:{value:Xe()},shadowViewProjection:{value:Xe()},boneTexture:{value:v},boneTextureSize:{value:4}},cullFace:u.FRONT}),Dr=new ze(u,{vertex:Rr(!1,!0),fragment:Pr,uniforms:{shadowViewProjection:{value:Xe()}},cullFace:u.FRONT}),Qt=new Map;let Sr=!0;const _t=b=>{let C=Qt.get(b);return C||(C=Mc(u,g),C.setEnabled(Sr),Qt.set(b,C)),C};let ir=0;const He=()=>{ir++},Kr=new Map,$=b=>{Kr.get(b)!==ir&&(b.updateMatrixWorld(),Kr.set(b,ir))},re=(b,C,F=!1)=>{const U=_t(b);$(b),U.collect(b,C,!0,ir,F),U.drawMain(C,d.shadowEnabled),F&&He()},X=b=>{var C;for(const[F,U]of ye.entities)if(U.light&&ye.methods.isVisible(F)&&((C=ye.sceneOf(F))==null?void 0:C.id)===b)return U.light;return null};let Z=!1;const ae=b=>{var fe,ce;const C=(fe=ye.scenes.get(b))==null?void 0:fe.camera,F=C!==void 0?ye.worldMatrix(C):Xe(),U=[];for(const[Ae,pe]of ye.entities){const ge=pe.punctual;if(!ge||!(ge.intensity>0)||!ye.methods.isVisible(Ae)||((ce=ye.sceneOf(Ae))==null?void 0:ce.id)!==b)continue;const _e=ye.worldMatrix(Ae);U.push({id:Ae,p:ge,w:_e,near:Math.hypot(_e[12]-F[12],_e[13]-F[13],_e[14]-F[14])-ge.range})}U.length>nr&&(U.sort((Ae,pe)=>Ae.near-pe.near),Z||(Z=!0,console.warn(`[viewer-lite] ${U.length} point / spot lights in the scene: the lite engine draws the ${nr} nearest the camera`)));const k=Math.min(U.length,nr),j=d.punctualPos.value,ee=d.punctualColor.value,ie=d.punctualDir.value;for(let Ae=0;Ae<k;Ae++){const{p:pe,w:ge}=U[Ae],_e=Ae*4;j[_e]=ge[12],j[_e+1]=ge[13],j[_e+2]=ge[14],j[_e+3]=1/(pe.range*pe.range);const Ge=pe.intensity/(pe.type==="spot"?Math.PI:4*Math.PI);ee[_e]=(pe.color>>>16&255)/255*Ge,ee[_e+1]=(pe.color>>>8&255)/255*Ge,ee[_e+2]=(pe.color&255)/255*Ge;const ot=-ge[8],Ft=-ge[9],dt=-ge[10],Gt=Math.hypot(ot,Ft,dt)||1;if(ie[_e]=ot/Gt,ie[_e+1]=Ft/Gt,ie[_e+2]=dt/Gt,pe.type==="spot"){const Vt=Math.cos(pe.outer),Zt=1/Math.max(1/1024,Math.cos(pe.inner)-Vt);ee[_e+3]=Zt,ie[_e+3]=-Vt*Zt}else ee[_e+3]=0,ie[_e+3]=1}d.punctualCount.value=k},oe=b=>{const C=[];return b.traverse(F=>F.visible?(F.draw&&C.push(F),!1):!0),C},ue=(b,C)=>{const F=C.shadowsQuality>=3?4096:C.shadowsQuality>=2?2048:1024;(!ut||Nt!==F)&&(ut=new ii(u,{width:F,height:F,depthTexture:!0}),Nt=F);const U=_t(b),k=U.casterSingles,j=[1/0,1/0,1/0],ee=[-1/0,-1/0,-1/0],ie=[0,0,0];for(const It of k){const yt=It.geometry;if(yt.bounds||yt.computeBoundingBox(),!yt.bounds||!isFinite(yt.bounds.min.x))continue;const Gr=It.worldMatrix;for(let Jt=0;Jt<8;Jt++){Pt(ie,Gr,Jt&1?yt.bounds.max.x:yt.bounds.min.x,Jt&2?yt.bounds.max.y:yt.bounds.min.y,Jt&4?yt.bounds.max.z:yt.bounds.min.z,1);for(let Tt=0;Tt<3;Tt++)ie[Tt]<j[Tt]&&(j[Tt]=ie[Tt]),ie[Tt]>ee[Tt]&&(ee[Tt]=ie[Tt])}}if(U.casterBounds(j,ee),!isFinite(j[0])){d.shadowEnabled.value=0;return}const[fe,ce,Ae]=j,[pe,ge,_e]=ee,Ge=(fe+pe)/2,ot=(ce+ge)/2,Ft=(Ae+_e)/2,dt=Math.max(.5,Math.hypot(pe-fe,ge-ce,_e-Ae)/2);let Gt=C.direction[0],Vt=C.direction[1],Zt=C.direction[2];const Zr=Math.hypot(Gt,Vt,Zt)||1;Gt/=Zr,Vt/=Zr,Zt/=Zr;const Ot=[Ge-Gt*dt*2,ot-Vt*dt*2,Ft-Zt*dt*2],or=-Gt,ar=-Vt,lr=-Zt,cr=Math.abs(Vt)>.99?[1,0,0]:[0,1,0];let ur=cr[1]*lr-cr[2]*ar,hr=cr[2]*or-cr[0]*lr,fr=cr[0]*ar-cr[1]*or;const Jr=Math.hypot(ur,hr,fr)||1;ur/=Jr,hr/=Jr,fr/=Jr;const Bn=ar*fr-lr*hr,Nn=lr*ur-or*fr,On=or*hr-ar*ur,mt=new Float32Array(16);mt[0]=ur,mt[4]=hr,mt[8]=fr,mt[1]=Bn,mt[5]=Nn,mt[9]=On,mt[2]=or,mt[6]=ar,mt[10]=lr,mt[12]=-(ur*Ot[0]+hr*Ot[1]+fr*Ot[2]),mt[13]=-(Bn*Ot[0]+Nn*Ot[1]+On*Ot[2]),mt[14]=-(or*Ot[0]+ar*Ot[1]+lr*Ot[2]),mt[15]=1;const Fi=qa(-dt,dt,-dt,dt,.05,dt*4),zr=At(new Float32Array(16),Fi,mt);Ar.uniforms.shadowViewProjection.value=zr,Ur.uniforms.shadowViewProjection.value=zr,Dr.uniforms.shadowViewProjection.value=zr,d.shadowMatrix.value=zr,d.shadowMap.value=ut.depthTexture,d.shadowMapSize.value=F,d.shadowEnabled.value=1,g.bindFramebuffer(ut),g.setViewport(F,F),u.clearColor(1,1,1,1),g.enable(u.DEPTH_TEST),g.setDepthMask(!0),u.clear(u.COLOR_BUFFER_BIT|u.DEPTH_BUFFER_BIT);const Ti=Xe();for(const It of k){const yt=It instanceof Rt,Gr=yt?Ur:Ar,Jt=It.program;Gr.uniforms.modelMatrix.value=yt?Ti:It.worldMatrix,It.program=Gr,It.draw({}),It.program=Jt}U.drawShadow(Dr),g.bindFramebuffer({buffer:null})};let le=null,me=null,be=null,Ee=null;const xe=(b,C,F)=>{if(be===null&&(be=bc(u),be||console.warn("[viewer-lite] bloom needs EXT_color_buffer_float — drawn without")),!be||C===0||F===0)return null;Ee??(Ee=Ac(u,4));const U=b.antialias===!1?0:Ee;return(!le||le.width!==C||le.height!==F||le.samples!==U)&&(le==null||le.dispose(),le=Sc(u,g,C,F,U),le||(be=!1,console.warn("[viewer-lite] bloom target is incomplete on this driver — drawn without"))),le},Se=b=>{let C=wt===0?0:(b-wt)/1e3;C>.05&&(C=.05),wt=b;const F=b/1e3;y.value[0]=F,y.value[1]=F-Math.floor(F),ye.tick(C)},Ue=(b,C,F)=>{var Ae;const U=C/Math.max(1,F),{fov:k,near:j,far:ee,matrix:ie}=ye.projectionOf(b);if(m.value=Math.max(1,F)/(2*Math.tan(k*Math.PI/360)),ie){for(let pe=0;pe<16;pe++)Fe.projectionMatrix[pe]=ie[pe];Fe.near=j,Fe.far=ee,Mt=0}else(U!==Mt||k!==Bt||j!==Ut||ee!==Kt)&&(Mt=U,Bt=k,Ut=j,Kt=ee,Fe.perspective({fov:k,aspect:U,near:j,far:ee}));const fe=(Ae=ye.scenes.get(b))==null?void 0:Ae.camera,ce=fe!==void 0?ye.worldMatrix(fe):Xe();for(let pe=0;pe<16;pe++)Fe.matrix[pe]=ce[pe];Fe.worldMatrixNeedsUpdate=!0},Re=()=>({buffer:null,x:0,y:0,width:t.width,height:t.height}),Ie=(b,C=Re())=>{const F=ye.activeSceneId(),U=ye.scenes.get(F),k=P.get(F);if(!U||!k)return!1;Se(b),Oe(),Ue(F,C.width,C.height),S!=="off"?(Be(),u.enable(u.POLYGON_OFFSET_FILL),u.polygonOffset(1,1)):u.disable(u.POLYGON_OFFSET_FILL),$(k);const j=_t(k);j.collect(k,Fe,!0,ir);const ee=X(F);if(ee){const pe=(ee.color>>>16&255)/255,ge=(ee.color>>>8&255)/255,_e=(ee.color&255)/255;d.sunDirection.value=ee.direction,d.sunColorIntensity.value=[pe,ge,_e,ee.intensity],ee.shadowsQuality>0?ue(k,ee):d.shadowEnabled.value=0}else d.sunColorIntensity.value=[1,1,1,0],d.shadowEnabled.value=0;ae(F),d.iblLuminance.value=U.ibl??0;const ie=N?void 0:U.bloom,fe=ie?xe(U,C.width,C.height):null;d.uTonemap.value=fe?0:1;const ce=U.skybox!==void 0?[(U.skybox>>>16&255)/255,(U.skybox>>>8&255)/255,(U.skybox&255)/255]:[.1,.25,.57],Ae=fe?ce:ce.map(al);fe?(fe.bindDraw(),xi(u,g,fe.width,fe.height)):Br(u,g,C),qe||We.active()?u.clearColor(0,0,0,0):u.clearColor(Ae[0],Ae[1],Ae[2],1),g.enable(u.DEPTH_TEST),g.setDepthMask(!0),u.clear(u.COLOR_BUFFER_BIT|u.DEPTH_BUFFER_BIT),j.drawMain(Fe,d.shadowEnabled),N==null||N.renderScenePass(Ae);for(const pe of U.overlays){const ge=P.get(pe);ge&&(u.clear(u.DEPTH_BUFFER_BIT),re(ge,Fe))}if(N==null||N.renderOverlayPass(),N==null||N.renderPreviewPass(k,Ae),fe&&ie){fe.resolve(),me??(me=Uc(u,g));const pe=me.run(fe.texture,fe.width,fe.height,ie);me.compose(fe.texture,pe.texture,ie.strength/pe.levels,C)}return C.buffer===null&&We.active()&&queueMicrotask(it),!0},De=new Set,Ne=(b,C)=>{const F=C instanceof Error?C.message:String(C);De.has(F)||(De.add(F),console.error(`[viewer-lite] ${b} failed:`,C))},Le=()=>{bt||(bt=!0,requestAnimationFrame(Ze))},ke=()=>{if(Ct)try{Ct()}catch(b){Ne("the host's frame hook",b)}},Ze=()=>{if(bt=!1,!(!Pe||We.active())){ke();try{Ie(performance.now())}catch(b){Ne("render frame",b)}Le()}},Ke=()=>{g.bindFramebuffer({buffer:null}),u.clearColor(0,0,0,0),g.setDepthMask(!0),u.clear(u.COLOR_BUFFER_BIT|u.DEPTH_BUFFER_BIT)},it=()=>{We.active()&&Ke()},We=Fc({gl:u,renderer:g,near:wn,far:Mn,presenting(b){b?Ke():Pe&&Le()},begin(){Pe&&ke()},view(b,C,F,U,k){if(!Pe)return!1;const j=ye.activeSceneId();return b!==void 0&&j!==b?!1:(ye.methods.setCameraMatrix(j,C),ye.methods.setCameraProjectionMatrix(j,F,U,k),!0)},draw(b){if(Pe)try{b?Ie(performance.now(),b):Se(performance.now())}catch(C){Ne("render frame (XR)",C)}},failed:Ne}),vt=b=>{var C;return(C=ye.sceneOf(b))==null?void 0:C.id};let ht=[0,0,0];const tt=(b,C,F)=>{var Ft;const U=(Ft=ye.scenes.get(b))==null?void 0:Ft.camera,k=U!==void 0?ye.worldMatrix(U):Xe(),j=Math.max(1,t.width),ee=Math.max(1,t.height),ie=j/ee,fe=C*Ye,ce=F*Ye,[Ae,pe]=ui(ye.projectionOf(b),ie,fe/j*2-1,1-ce/ee*2),ge=k[0]*Ae+k[4]*pe-k[8],_e=k[1]*Ae+k[5]*pe-k[9],Ge=k[2]*Ae+k[6]*pe-k[10],ot=Math.hypot(ge,_e,Ge)||1;return ht=[k[12],k[13],k[14]],{origin:ht,dir:[ge/ot,_e/ot,Ge/ot]}},rt=(b,C,F)=>{const U=L.get(b);if(!U)return 0;let k=1/0,j=0;const ee=[0,0,0],ie=[0,0,0];for(const[fe,ce]of U){if(!ye.entities.has(fe)||!ye.methods.isVisible(fe))continue;const Ae=Lt(ye.worldMatrixF(fe));Pt(ee,Ae,C[0],C[1],C[2],1),Pt(ie,Ae,F[0],F[1],F[2],0);const pe=ce.type==="box"?xs(ce.center,ce.extent,ee,ie):Ya(ce.center,ce.radius,ee,ie);pe>0&&pe<k&&(k=pe,j=fe)}return j},$e=(b,C,F)=>{const U=P.get(b);if(!U)return 0;let k=1/0,j=0;const ee=[0,0,0],ie=[0,0,0];U.updateMatrixWorld();for(const fe of oe(U)){const ce=fe.geometry;if(ce.bounds||ce.computeBoundingBox(),!ce.bounds||!isFinite(ce.bounds.min.x))continue;const Ae=Lt(fe.worldMatrix);Pt(ee,Ae,C[0],C[1],C[2],1),Pt(ie,Ae,F[0],F[1],F[2],0);const pe=[(ce.bounds.min.x+ce.bounds.max.x)/2,(ce.bounds.min.y+ce.bounds.max.y)/2,(ce.bounds.min.z+ce.bounds.max.z)/2],ge=[(ce.bounds.max.x-ce.bounds.min.x)/2,(ce.bounds.max.y-ce.bounds.min.y)/2,(ce.bounds.max.z-ce.bounds.min.z)/2],_e=xs(pe,ge,ee,ie);_e>0&&_e<k&&(k=_e,j=fe._entId??0)}return j},Je=(b,C)=>{const F=ye.activeSceneId(),U=ye.scenes.get(F);if(!U||U.camera===void 0)return 0;const{origin:k,dir:j}=tt(F,b,C);for(let ee=U.overlays.length-1;ee>=0;ee--){const ie=rt(U.overlays[ee],k,j);if(ie!==0)return ie}return rt(F,k,j)},Dt=b=>{b.mesh&&b.mesh.setParent(null),b.buffer&&u.deleteBuffer(b.buffer),b.mesh=null,b.geometry=null,b.buffer=null},zt=(b,C)=>{const F=_.get(b.materialId);if(C===Ht.MESH)return(F??K("unlit")).program;const U=C!==Ht.POINTS;return F&&F.kind===(U?"particles-quad":"particles")?F.program:K(U?"particles-quad":"particles").program},ft=(b,C,F)=>{if(Dt(C),C.version=F.geometryVersion,C.mode=F.mode,F.capacity===0)return;const U=ye.particleIndexPattern(b);if(U.length===0)return;let k;if(F.mode===Ht.MESH){const ee=F.capacity*F.meshVertexCount;k=new ct(u,{position:{size:3,data:new Float32Array(ee*3),usage:u.DYNAMIC_DRAW},normal:{size:3,data:new Float32Array(ee*3),usage:u.DYNAMIC_DRAW},uv:{size:2,data:new Float32Array(ee*2),usage:u.DYNAMIC_DRAW},index:{data:U}})}else{const ee=u.createBuffer();C.buffer=ee;const ie=F.stride,fe=F.mode===Ht.POINTS?F.capacity:F.mode===Ht.QUADS?F.capacity*4:(F.capacity+1)*2,ce=(pe,ge)=>({size:pe,type:u.FLOAT,buffer:ee,stride:ie,offset:ge,count:fe,data:new Float32Array(0)}),Ae={position:ce(3,0),color:ce(4,12),custom:ce(4,28)};F.mode!==Ht.POINTS&&(Ae.aux=ce(3,44),Ae.corner=ce(2,56)),Ae.index={data:Uint16Array.from(U)},k=new ct(u,Ae),u.bindBuffer(u.ARRAY_BUFFER,ee),u.bufferData(u.ARRAY_BUFFER,fe*ie,u.DYNAMIC_DRAW),g.state.boundBuffer=ee}const j=new nt(u,{geometry:k,program:zt(C,F.mode),mode:F.mode===Ht.POINTS?u.POINTS:u.TRIANGLES});j.frustumCulled=!1,j.matrixAutoUpdate=!1,j._entId=b,j._particles=!0,j.setParent(D(b).transform),C.geometry=k,C.mesh=j},_i=(b,C)=>{let F=h.get(b);if(F||(F={materialId:0,mesh:null,geometry:null,buffer:null,version:0,mode:-1},h.set(b,F)),(F.version!==C.geometryVersion||F.mode!==C.mode||!F.mesh)&&(ft(b,F,C),He()),!F.mesh||!F.geometry)return;const U=C.indexCount>0;if(F.mesh.visible!==U&&(F.mesh.visible=U,He()),!!U){if(F.mesh.renderOrder=C.order,C.mode===Ht.MESH){const k=C.vertexCount,j=new Float32Array(C.bytes.buffer,C.bytes.byteOffset,k*10),ee=F.geometry.attributes.position,ie=F.geometry.attributes.normal,fe=F.geometry.attributes.uv,ce=ee.data,Ae=ie.data,pe=fe.data;for(let ge=0;ge<k;ge++){const _e=ge*10;ce[ge*3]=j[_e],ce[ge*3+1]=j[_e+1],ce[ge*3+2]=j[_e+2];const Ge=j[_e+3],ot=j[_e+4],Ft=j[_e+5],dt=j[_e+6];Ae[ge*3]=2*(Ge*Ft+ot*dt),Ae[ge*3+1]=2*(ot*Ft-Ge*dt),Ae[ge*3+2]=1-2*(Ge*Ge+ot*ot),pe[ge*2]=j[_e+8],pe[ge*2+1]=j[_e+9]}ee.needsUpdate=ie.needsUpdate=fe.needsUpdate=!0}else F.buffer&&(u.bindBuffer(u.ARRAY_BUFFER,F.buffer),u.bufferSubData(u.ARRAY_BUFFER,0,C.bytes),g.state.boundBuffer=F.buffer);F.geometry.drawRange.start=0,F.geometry.drawRange.count=C.indexCount}},Ei={allocMatrix:b=>D(b).transform.matrix,localMatrixChanged:b=>{D(b).transform.worldMatrixNeedsUpdate=!0,He()},parentChanged:(b,C)=>{He();const F=D(b).transform;if(C!==0)F.setParent(D(C).transform);else{const U=ye.sceneOf(b);F.setParent((U&&P.get(U.id))??null)}},sceneCreated:b=>{P.set(b,new gt),L.set(b,new Map)},entitySceneChanged:(b,C,F)=>{He();const U=P.get(C);if(!U)return;const k=D(b);if(F){for(const[j,ee]of L){if(j===C)continue;const ie=ee.get(b);ie&&(L.get(C).set(b,ie),ee.delete(b))}ye.ent(b).parent===0&&k.transform.setParent(U)}else ye.ent(b).parent===0&&k.transform.parent===U&&k.transform.setParent(null)},visibleChanged:(b,C)=>{D(b).transform.visible=C,He()},materialCreated:(b,C,F)=>{_.set(b,H(C.shader,F))},uniformChanged:(b,C,F)=>te(b,C,F),meshSet:(b,C,F,U)=>{he(b,C,U,F.kind),He()},glbAttach:(b,C,F)=>we(b,C,F).then(He),morphWeights:(b,C)=>{const F=D(b).transform.weights;F&&F.set(C.subarray(0,Math.min(F.length,C.length)))},entityDestroyed:b=>{He();const C=T.get(b);C&&(C.transform.setParent(null),T.delete(b));for(const F of L.values())F.delete(b)},entityCloned:(b,C)=>{Ve(b,C),He()},subtreeCloned:(b,C,F)=>je(F),particleSystemCreated:(b,C)=>{const F=h.get(b);F?(Dt(F),F.materialId=C,F.version=0):h.set(b,{materialId:C,mesh:null,geometry:null,buffer:null,version:0,mode:-1})},particlesFrame:(b,C)=>_i(b,C),particleSystemDestroyed:b=>{const C=h.get(b);C&&(Dt(C),h.delete(b)),He()}},Qr=e.twins??{};await Promise.all([Qr.anim!==!1&&Hc(),Qr.physics!==!1&&Ul(),Qr.particles!==!1&&eu()]);const ye=ou(Ei,{getBuffer:s,getSourceName:i,width:t.width||1,height:t.height||1,fov:xn}),Ci=(b,C,F,U=!1)=>{createImageBitmap(b).then(k=>{const j=new Qe(u,{image:k,internalFormat:U?u.RGBA8:u.SRGB8_ALPHA8,format:u.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),ee=E++;o.set(ee,j),C(ee,k.width,k.height)}).catch(F)};return{...hu,...du,...ye.methods,createEntity:()=>({id:ye.methods.createEntity()}),cloneEntity:b=>({id:ye.methods.cloneEntity(b)}),createMaterial:b=>({id:ye.methods.createMaterial(b)}),builtinMaterial:b=>({id:ye.methods.createMaterialNamed(b)}),createGlb(b,C,F){ye.methods.createGlb(b,U=>C({id:U}),F)},openScene(b){const C=Pe;ye.methods.openScene(b),Pe=ye.scenes.has(b),t.style.display="block",!C&&Pe&&Le()},closeScene(){t.style.display="none",Pe=!1,ye.methods.closeScene()},launchAR(){throw new Error(Fr)},stopAR(){throw new Error(Fr)},launchVR(b,C,F){F(new Error("VR is not supported on this device"))},stopVR(){},async warmRender(b,C){C()},attachCameraToAR(b,C,F){const U=ye.scenes.get(b);if(U){U.camera=C;for(const k of U.overlays){const j=ye.scenes.get(k);j&&(j.camera=C)}}},getCameraFov(b,C){const F=ye.projectionOf(b).fov;if(C!==1)return F;const U=F*Math.PI/180,k=t.width/Math.max(1,t.height);return 2*Math.atan(Math.tan(U/2)*k)*180/Math.PI},getCameraViewDirection(b,C,F,U){if(!ye.scenes.has(b)){U[0]=0,U[1]=0,U[2]=-1;return}const{dir:k}=tt(b,C,F);U[0]=k[0],U[1]=k[1],U[2]=k[2]},getDisplaySize:()=>Float32Array.of(g.width||t.width,g.height||t.height),createTexture(b,C,F,U=0){const k=(ee,ie,fe)=>C({id:ee},ie,fe),j=n(b);j.slice(0,12).arrayBuffer().then(async ee=>{const ie=await Nr(()=>import("./index-oPsDD47E.js"),__vite__mapDeps([0,1]),import.meta.url);if(!ie.isKtx2Bytes(new Uint8Array(ee)))return!1;const fe=await j.arrayBuffer(),ce=await ie.transcodeKtx2(u,fe),Ae=ie.ktx2IsSrgb(fe);let pe;ce.isCompressedTexture?pe=new Qe(u,{image:ce,internalFormat:Ae&&ce.srgbInternalFormat?ce.srgbInternalFormat:ce.internalFormat,generateMipmaps:!1,minFilter:ce.length>1?u.LINEAR_MIPMAP_LINEAR:u.LINEAR,flipY:!1}):pe=new Qe(u,{image:ce,internalFormat:Ae?u.SRGB8_ALPHA8:u.RGBA8,format:u.RGBA,generateMipmaps:!0,flipY:!1,premultiplyAlpha:!1});const ge=E++;return o.set(ge,pe),k(ge,ce.width,ce.height),!0}).then(ee=>{ee||Ci(j,k,F,(U&1)!==0)},F)},createTexturePixels(b,C,F,U,k){if(b<=0||C<=0||U.length<b*C*F)return{id:4294967295};const j=new Uint8Array(b*C*4);for(let fe=0,ce=b*C;fe<ce;fe++){const Ae=fe*F,pe=fe*4;j[pe]=U[Ae],j[pe+1]=F>=2?U[Ae+1]:U[Ae],j[pe+2]=F>=3?U[Ae+2]:U[Ae],j[pe+3]=F>=4?U[Ae+3]:255}const ee=new Qe(u,{image:j,width:b,height:C,internalFormat:k?u.SRGB8_ALPHA8:u.RGBA8,format:u.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1,minFilter:u.LINEAR,magFilter:u.LINEAR}),ie=E++;return o.set(ie,ee),w.set(ie,{rgba:j,width:b,height:C,channels:F}),{id:ie}},updateTexturePixels(b,C,F,U,k,j){const ee=w.get(b),ie=o.get(b);if(!ee||!ie)return;const fe=ee.channels;for(let ce=0;ce<k;ce++){const Ae=F+ce;if(!(Ae<0||Ae>=ee.height))for(let pe=0;pe<U;pe++){const ge=C+pe;if(ge<0||ge>=ee.width)continue;const _e=(ce*U+pe)*fe,Ge=(Ae*ee.width+ge)*4;ee.rgba[Ge]=j[_e],ee.rgba[Ge+1]=fe>=2?j[_e+1]:j[_e],ee.rgba[Ge+2]=fe>=3?j[_e+2]:j[_e],ee.rgba[Ge+3]=fe>=4?j[_e+3]:255}}ie.image=ee.rgba,ie.needsUpdate=!0},createTextureFromCanvas(b){var k;const C=(k=e.canvasHost)==null?void 0:k.readSurface(b);if(!C)return 0;const F=new Qe(u,{image:new Uint8Array(C.data.buffer.slice(0)),width:C.width,height:C.height,internalFormat:u.SRGB8_ALPHA8,format:u.RGBA,generateMipmaps:!1,flipY:!1}),U=E++;return o.set(U,F),U},updateTextureFromCanvas(b,C){var k;const F=(k=e.canvasHost)==null?void 0:k.readSurface(C),U=o.get(b);!F||!U||(U.image=new Uint8Array(F.data.buffer.slice(0)),U.width=F.width,U.height=F.height,U.needsUpdate=!0)},createMediaPlayerTexture(b){const C=f(b),F=new Qe(u,{generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1});I.push({video:C,texture:F,lastTime:-1});const U=E++;return o.set(U,F),U},setUniformTexture(b,C,F,U,k){ye.methods.setUniformTexture(b,C,F);const j=_.get(b),ee=o.get(F);if(!j||!ee)return;const ie=[u.CLAMP_TO_EDGE,u.REPEAT,u.MIRRORED_REPEAT];ee.wrapS=ie[U]??u.REPEAT,ee.wrapT=ie[k]??u.REPEAT,ee.needsUpdate=!0,se(j,C).value=ee},setMaterial(b,C,F){ye.methods.setMaterial(b,C,F);const U=_.get(C),k=D(b).drawables[F];!U||!k||(k.program=G(U,k),ne(k,U),He())},getMaterial(b,C){const F=D(b).drawables[C];if(!F)return 0;const U=ye.nextMaterialId();return _.set(U,{kind:"gltf",program:F.program,source:F.program._source}),U},setCulling(b,C){for(const F of D(b).drawables)F.frustumCulled=C;He()},setGlbCulling(b,C){const F=U=>{for(const k of D(U).drawables)k.frustumCulled=C;for(const k of ye.ent(U).children)F(k)};F(b),He()},setRenderPriority(b,C){for(const F of D(b).drawables)F.renderOrder=C;He()},setMaterialDepthTest(b,C){const F=_.get(b);if(F)for(const U of Y(F))U.depthTest=C},setMaterialDepthWrite(b,C){const F=_.get(b);if(F)for(const U of Y(F))U.depthWrite=C},setMaterialCulling(b,C){const F=_.get(b);if(F)for(const U of Y(F))U.cullFace=C===0?!1:C===1?u.FRONT:u.BACK},setCastShadows(b,C){ye.methods.setCastShadows(b,C);for(const F of D(b).drawables)F._castShadows=C;He()},setReceiveShadows(b,C){ye.methods.setReceiveShadows(b,C);for(const F of D(b).drawables)F._receiveShadows=C;He()},setGlbShadows(b,C,F){ye.methods.setGlbShadows(b,C,F);const U=k=>{for(const j of D(k).drawables)j._castShadows=C,j._receiveShadows=F;for(const j of ye.ent(k).children)U(j)};U(b),He()},setCastShadowsGlobal(b){B=b},setReceiveShadowsGlobal(b){W=b},setColliderFromMesh(b,C,F){var ee;if(F!==0)return;const U=D(C).drawables[0];if(!U)return;const k=U.geometry;if(k.bounds||k.computeBoundingBox(),!k.bounds)return;const j=vt(b)??ye.activeSceneId();(ee=L.get(j))==null||ee.set(b,{type:"box",center:[(k.bounds.min.x+k.bounds.max.x)/2,(k.bounds.min.y+k.bounds.max.y)/2,(k.bounds.min.z+k.bounds.max.z)/2],extent:[(k.bounds.max.x-k.bounds.min.x)/2,(k.bounds.max.y-k.bounds.min.y)/2,(k.bounds.max.z-k.bounds.min.z)/2]})},setColliderBox(b,C,F,U,k,j,ee){var fe;const ie=vt(b)??ye.activeSceneId();(fe=L.get(ie))==null||fe.set(b,{type:"box",center:[C,F,U],extent:[k/2,j/2,ee/2]})},setColliderSphere(b,C,F,U,k){var ee;const j=vt(b)??ye.activeSceneId();(ee=L.get(j))==null||ee.set(b,{type:"sphere",center:[C,F,U],radius:k})},createARController(){throw new Error(Fr)},createRootAnchor(){throw new Error(Fr)},createAnchor(){throw new Error(Fr)},_renderNow:()=>Ie(performance.now()),async captureImage(b,C,F){try{Ie(performance.now());const U=new OffscreenCanvas(t.width,t.height);U.getContext("2d").drawImage(t,0,0);const j=await U.convertToBlob({type:"image/png"}),ee=await j.arrayBuffer();C(a(ee),"image.png",j.size)}catch{F()}},raycastView:Je,_raycastView:Je,raycastPick(b,C){const F=ye.activeSceneId(),U=ye.scenes.get(F);if(!U||U.camera===void 0)return 0;const k=Je(b,C);if(k!==0)return k;const{origin:j,dir:ee}=tt(F,b,C);return $e(F,j,ee)},computeBoundingBox(b){const C=Float32Array.of(1/0,1/0,1/0,-1/0,-1/0,-1/0),F=[0,0,0],U=(k,j)=>{for(const ee of D(k).drawables){const ie=ee.geometry;if(ie.bounds||ie.computeBoundingBox(),!(!ie.bounds||!isFinite(ie.bounds.min.x)))for(let fe=0;fe<8;fe++){const ce=fe&1?ie.bounds.max.x:ie.bounds.min.x,Ae=fe&2?ie.bounds.max.y:ie.bounds.min.y,pe=fe&4?ie.bounds.max.z:ie.bounds.min.z;j?Pt(F,j,ce,Ae,pe,1):(F[0]=ce,F[1]=Ae,F[2]=pe);for(let ge=0;ge<3;ge++)F[ge]<C[ge]&&(C[ge]=F[ge]),F[ge]>C[ge+3]&&(C[ge+3]=F[ge])}}for(const ee of ye.ent(k).children){const ie=D(ee).transform.matrix,fe=j?At(new Float32Array(16),j,ie):Float32Array.from(ie);U(ee,fe)}};return U(b,null),isFinite(C[0])||C.fill(0),C},stopAllPlayers(){p()},_dumpScene3d:()=>uu(ye),_setWireframeMode(b){S=b==="overlay"||b==="only"?b:"off",A.value=S==="only"?[.62,.66,.72]:[.05,.06,.08],Be(),He()},_setBatching(b){for(const C of Qt.values())C.setEnabled(b);Sr=b,He()},_batchStats(){const b=P.get(ye.activeSceneId());return b?_t(b).stats():{batches:0,instances:0,visible:0,singles:0}},_editorConnect(b){return N??(N=gc({gl:u,renderer:g,canvas:t,camera:Fe,core:ye,sceneRoots:P,drawablesOf:C=>D(C).drawables,collectMeshes:oe,wireGeometryFor:Me,getViewRay:tt,renderScene:re})),N.setHandlers(b),N.api},async createEngine(){},_fetch:r,_getPlayer:f,_createGLTexture(b){const C=new Qe(u,{image:b,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),F=E++;return o.set(F,C),C.update(),{gl:u,glTexture:C.texture,textureId:F}},_projectionOf:b=>ye.projectionOf(b),_setTransparent(b){qe=b},_beforeFrame(b){Ct=b},_presentXR(b,C,F,U){return U!==void 0&&!ye.scenes.has(U)?Promise.reject(new Error(`[viewer-lite] _presentXR: there is no scene ${U}`)):We.present(b,C,F,U)},_onResize(b,C,F=1){Ye=F,g.dpr=F,g.setSize(b,C),Mt=0},_dispose(){var b;Ct=null,We.end(),N==null||N.dispose(),N=null,le==null||le.dispose(),le=null,me==null||me.dispose(),me=null;for(const C of Qt.values())C.dispose();Qt.clear(),this.closeScene(),this.stopAllPlayers(),(b=u.getExtension("WEBGL_lose_context"))==null||b.loseContext()}}},gu=async(t,e={})=>{const r=t.ownerDocument,n=r.defaultView??window,s=r.createElement("canvas");s.className="lc-scene",s.style.cssText="position: absolute; left: 0; top: 0; display: none; pointer-events: auto; touch-action: none";const i=await pu(s,{preloads:e.preloads,twins:e.twins,alpha:e.alpha}),l=()=>{const p=t.clientWidth,g=t.clientHeight;p>0&&g>0&&i._onResize(p,g,n.devicePixelRatio||1)};let a=null,c=-1;return{feature:{name:"scene3d",install(){return t.insertBefore(s,t.firstChild),l(),a=new ResizeObserver(l),a.observe(t),{globals:{_creator:i},destination(p,g){return p.kind!==zi?!1:(g?(c=p.id,i.openScene(p.id)):c===p.id&&(c=-1,i.closeScene()),!0)},hit:(p,g,u)=>p===s&&c>=0?i.raycastPick(g,u):null,destroy(){a==null||a.disconnect(),a=null,c=-1,i._dispose(),s.remove()}}}},engine:i,canvas:s,opened:()=>c,dispose(){i._dispose(),s.remove()}}},xu=Object.freeze(Object.defineProperty({__proto__:null,createScene3d:gu},Symbol.toStringTag,{value:"Module"}));export{vs as G,xu as s};