lecodes-cli 2.4.8 → 2.4.10

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,11 +1,11 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-Bd7pdF7u.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 ut{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)}
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-e-m97P8Y.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 Bi,a as Li,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 ut{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
3
  Vertex Shader
4
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
5
  Fragment Shader
6
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
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 ir 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],R=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,F=p*x-v*M,B=g*y-u*d,W=g*x-v*d,O=u*x-v*y,I=R*O-P*W+L*B+_*F-o*w+h*m;return I?(I=1/I,t[0]=(a*O-c*W+f*B)*I,t[1]=(s*W-n*O-i*B)*I,t[2]=(d*h-y*o+x*_)*I,t[3]=(u*o-g*h-v*_)*I,t[4]=(c*F-l*O-f*w)*I,t[5]=(r*O-s*F+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*F+f*m)*I,t[9]=(n*F-r*W-i*m)*I,t[10]=(M*o-d*L+x*R)*I,t[11]=(g*L-p*o-v*R)*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*R)*I,t[15]=(p*_-g*P+u*R)*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,R=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,F=p*d-g*M,B=p*y-u*M,W=g*y-u*d;return x*W-R*B+P*F+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],R=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*R,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*R,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*R,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*R,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,R,P,L,_,o,h,m,w,F,B,W,O,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],R=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,F=s*i*p-l*c,B=i*i*p+f,W=l*i*p+s*c,O=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+R*m+o*w,t[4]=g*F+d*B+P*W,t[5]=u*F+y*B+L*W,t[6]=v*F+x*B+_*W,t[7]=M*F+R*B+o*W,t[8]=g*O+d*I+P*D,t[9]=u*O+y*I+L*D,t[10]=v*O+x*I+_*D,t[11]=M*O+R*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,R=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+R)*o,s[7]=0,s[8]=(M+P)*h,s[9]=(y-R)*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 At 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 At;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 vt{constructor(){this.parent=null,this.children=[],this.visible=!0,this.matrix=new At,this.worldMatrix=new At,this.matrixAutoUpdate=!0,this.worldMatrixNeedsUpdate=!1,this.position=new Ce,this.quaternion=new ir,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 At,$o=new Ce,Xo=new Ce;class Tn extends vt{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 At,this.viewMatrix=new At,this.projectionViewMatrix=new At,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],R=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]=R*n+P*l+L*f,t[7]=R*s+P*a+L*p,t[8]=R*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],R=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,F=p*x-v*M,B=g*y-u*d,W=g*x-v*d,O=u*x-v*y,I=R*O-P*W+L*B+_*F-o*w+h*m;return I?(I=1/I,t[0]=(a*O-c*W+f*B)*I,t[1]=(c*F-l*O-f*w)*I,t[2]=(l*W-a*F+f*m)*I,t[3]=(s*W-n*O-i*B)*I,t[4]=(r*O-s*F+i*w)*I,t[5]=(n*F-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*R)*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 vt{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 At,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 Ke{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:R,height:P=R,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=R,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:R}={}){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 Ke(e,{width:r,height:n,wrapS:f,wrapT:p,wrapR:g,minFilter:u,magFilter:v,type:M,format:d,internalFormat:y,unpackAlignment:x,premultiplyAlpha:R,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 Ke(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 br 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 br(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 jt extends ut{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);jt.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,R=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*R-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),F=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]=F,s[y*6+5]=B,y++}}}}class ss extends ut{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 R=0,P=0;jt.buildPlane(M,d,y,x,s,n,r,g,p,2,1,0,-1,-1,R,P),R+=(g+1)*(p+1),P+=g*p,jt.buildPlane(M,d,y,x,s,n,-r,g,p,2,1,0,1,-1,R,P),R+=(g+1)*(p+1),P+=g*p,jt.buildPlane(M,d,y,x,r,s,n,g,f,0,2,1,1,1,R,P),R+=(f+1)*(g+1),P+=f*g,jt.buildPlane(M,d,y,x,r,s,-n,g,f,0,2,1,1,-1,R,P),R+=(f+1)*(g+1),P+=f*g,jt.buildPlane(M,d,y,x,r,n,-s,f,p,0,1,2,-1,-1,R,P),R+=(f+1)*(p+1),P+=f*p,jt.buildPlane(M,d,y,x,r,n,s,f,p,0,1,2,1,-1,R,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 ut{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,R=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&&F(!0),n&&F(!1));function w(){let B,W;const O=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 N=B/g,k=N*M+v,z=Math.sin(k),Y=Math.cos(k);R.set([q*z,(.5-K)*s,q*Y],o*3),O.set(z,I,Y).normalize(),P.set([O.x,O.y,O.z],o*3),L.set([N,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],N=m[W][B+1];_.set([D,K,N,K,q,N],h*3),h+=2}}function F(B){let W;const O=B===!0?r:n,I=B===!0?1:-1,D=o;for(R.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,N=Math.cos(q),k=Math.sin(q);R.set([O*k,.5*s*I,O*N],o*3),P.set([0,I,0],o*3),L.set([N*.5+.5,k*.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:R},normal:{size:3,data:P},uv:{size:2,data:L},index:{data:_}}),super(e,p)}}class oi extends ut{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 ut{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 R=0;R<=s;R++)for(let P=0;P<=i;P++,x++){const L=P/i*l,_=R/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,R/s],x*2)}x=0;for(let R=1;R<=s;R++)for(let P=1;P<=i;P++,x++){const L=(i+1)*R+P-1,_=(i+1)*(R-1)+P-1,o=(i+1)*(R-1)+P,h=(i+1)*R+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 br,_a=new br,Ea=new br,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 At;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,R=_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,F;const B=_.geometry,W=B.attributes,O=W.index,I=W.position,D=Math.max(0,B.drawRange.start),K=Math.min(O?O.count:I.count,B.drawRange.start+B.drawRange.count),q=I.size;for(let N=D;N<K;N+=3){const k=O?O.data[N]:N,z=O?O.data[N+1]:N+1,Y=O?O.data[N+2]:N+2;g.fromArray(I.data,k*q),u.fromArray(I.data,z*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=k,w=z,F=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 br,_.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,F*3),this.getBarycoord(_.hit.localPoint,g,u,v,y)),s&&W.uv&&(x.fromArray(W.uv.data,m*2),R.fromArray(W.uv.data,w*2),P.fromArray(W.uv.data,F*2),_.hit.uv.set(x.x*y.x+R.x*y.y+P.x*y.z,x.y*y.x+R.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,F*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=`
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 ir 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],R=r*a-n*l,P=r*c-s*l,B=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,F=p*x-v*M,L=g*y-u*d,W=g*x-v*d,O=u*x-v*y,I=R*O-P*W+B*L+_*F-o*w+h*m;return I?(I=1/I,t[0]=(a*O-c*W+f*L)*I,t[1]=(s*W-n*O-i*L)*I,t[2]=(d*h-y*o+x*_)*I,t[3]=(u*o-g*h-v*_)*I,t[4]=(c*F-l*O-f*w)*I,t[5]=(r*O-s*F+i*w)*I,t[6]=(y*B-M*h-x*P)*I,t[7]=(p*h-u*B+v*P)*I,t[8]=(l*W-a*F+f*m)*I,t[9]=(n*F-r*W-i*m)*I,t[10]=(M*o-d*B+x*R)*I,t[11]=(g*B-p*o-v*R)*I,t[12]=(a*w-l*L-c*m)*I,t[13]=(r*L-n*w+s*m)*I,t[14]=(d*P-M*_-y*R)*I,t[15]=(p*_-g*P+u*R)*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,R=e*a-n*i,P=e*c-s*i,B=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,F=p*d-g*M,L=p*y-u*M,W=g*y-u*d;return x*W-R*L+P*F+B*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],R=e[15],P=r[0],B=r[1],_=r[2],o=r[3];return t[0]=P*n+B*a+_*g+o*d,t[1]=P*s+B*c+_*u+o*y,t[2]=P*i+B*f+_*v+o*x,t[3]=P*l+B*p+_*M+o*R,P=r[4],B=r[5],_=r[6],o=r[7],t[4]=P*n+B*a+_*g+o*d,t[5]=P*s+B*c+_*u+o*y,t[6]=P*i+B*f+_*v+o*x,t[7]=P*l+B*p+_*M+o*R,P=r[8],B=r[9],_=r[10],o=r[11],t[8]=P*n+B*a+_*g+o*d,t[9]=P*s+B*c+_*u+o*y,t[10]=P*i+B*f+_*v+o*x,t[11]=P*l+B*p+_*M+o*R,P=r[12],B=r[13],_=r[14],o=r[15],t[12]=P*n+B*a+_*g+o*d,t[13]=P*s+B*c+_*u+o*y,t[14]=P*i+B*f+_*v+o*x,t[15]=P*l+B*p+_*M+o*R,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 Bo(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,R,P,B,_,o,h,m,w,F,L,W,O,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],R=e[7],P=e[8],B=e[9],_=e[10],o=e[11],h=s*s*p+f,m=i*s*p+l*c,w=l*s*p-i*c,F=s*i*p-l*c,L=i*i*p+f,W=l*i*p+s*c,O=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+B*w,t[2]=v*h+x*m+_*w,t[3]=M*h+R*m+o*w,t[4]=g*F+d*L+P*W,t[5]=u*F+y*L+B*W,t[6]=v*F+x*L+_*W,t[7]=M*F+R*L+o*W,t[8]=g*O+d*I+P*D,t[9]=u*O+y*I+B*D,t[10]=v*O+x*I+_*D,t[11]=M*O+R*I+o*D,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Lo(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,R=c*f,P=c*p,B=c*g,_=n[0],o=n[1],h=n[2];return s[0]=(1-(d+x))*_,s[1]=(v+B)*_,s[2]=(M-P)*_,s[3]=0,s[4]=(v-B)*o,s[5]=(1-(u+x))*o,s[6]=(y+R)*o,s[7]=0,s[8]=(M+P)*h,s[9]=(y-R)*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 At 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 Bo(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 Lo(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 At;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 vt{constructor(){this.parent=null,this.children=[],this.visible=!0,this.matrix=new At,this.worldMatrix=new At,this.matrixAutoUpdate=!0,this.worldMatrixNeedsUpdate=!1,this.position=new Ce,this.quaternion=new ir,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 At,$o=new Ce,Xo=new Ce;class Tn extends vt{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 At,this.viewMatrix=new At,this.projectionViewMatrix=new At,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],R=r[6],P=r[7],B=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]=R*n+P*l+B*f,t[7]=R*s+P*a+B*p,t[8]=R*i+P*c+B*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],R=r*a-n*l,P=r*c-s*l,B=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,F=p*x-v*M,L=g*y-u*d,W=g*x-v*d,O=u*x-v*y,I=R*O-P*W+B*L+_*F-o*w+h*m;return I?(I=1/I,t[0]=(a*O-c*W+f*L)*I,t[1]=(c*F-l*O-f*w)*I,t[2]=(l*W-a*F+f*m)*I,t[3]=(s*W-n*O-i*L)*I,t[4]=(r*O-s*F+i*w)*I,t[5]=(n*F-r*W-i*m)*I,t[6]=(d*h-y*o+x*_)*I,t[7]=(y*B-M*h-x*P)*I,t[8]=(M*o-d*B+x*R)*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 vt{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 At,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 Ke{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:R,height:P=R,length:B=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=R,this.height=P,this.length=B,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:R}={}){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 B=0;B<i;B++)this.textures.push(new Ke(e,{width:r,height:n,wrapS:f,wrapT:p,wrapR:g,minFilter:u,magFilter:v,type:M,format:d,internalFormat:y,unpackAlignment:x,premultiplyAlpha:R,flipY:!1,generateMipmaps:!1})),this.textures[B].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+B,this.gl.TEXTURE_2D,this.textures[B].texture,0),P.push(this.gl.COLOR_ATTACHMENT0+B);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 Ke(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 br 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 br(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 jt extends ut{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);jt.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,R=i/c,P=l/f;for(let B=0;B<=f;B++){let _=B*P-l/2;for(let o=0;o<=c;o++,d++){let h=o*R-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-B/f,B===f||o===c)continue;let m=x+o+B*(c+1),w=x+o+(B+1)*(c+1),F=x+o+(B+1)*(c+1)+1,L=x+o+B*(c+1)+1;s[y*6]=m,s[y*6+1]=w,s[y*6+2]=L,s[y*6+3]=w,s[y*6+4]=F,s[y*6+5]=L,y++}}}}class ss extends ut{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 R=0,P=0;jt.buildPlane(M,d,y,x,s,n,r,g,p,2,1,0,-1,-1,R,P),R+=(g+1)*(p+1),P+=g*p,jt.buildPlane(M,d,y,x,s,n,-r,g,p,2,1,0,1,-1,R,P),R+=(g+1)*(p+1),P+=g*p,jt.buildPlane(M,d,y,x,r,s,n,g,f,0,2,1,1,1,R,P),R+=(f+1)*(g+1),P+=f*g,jt.buildPlane(M,d,y,x,r,s,-n,g,f,0,2,1,1,-1,R,P),R+=(f+1)*(g+1),P+=f*g,jt.buildPlane(M,d,y,x,r,n,-s,f,p,0,1,2,-1,-1,R,P),R+=(f+1)*(p+1),P+=f*p,jt.buildPlane(M,d,y,x,r,n,s,f,p,0,1,2,1,-1,R,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 ut{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,R=new Float32Array(y*3),P=new Float32Array(y*3),B=new Float32Array(y*2),_=y>65536?new Uint32Array(x):new Uint16Array(x);let o=0,h=0;const m=[];w(),a||(r&&F(!0),n&&F(!1));function w(){let L,W;const O=new Ce,I=(n-r)/s;for(W=0;W<=u;W++){const D=[],K=W/u,q=K*(n-r)+r;for(L=0;L<=g;L++){const N=L/g,k=N*M+v,z=Math.sin(k),Y=Math.cos(k);R.set([q*z,(.5-K)*s,q*Y],o*3),O.set(z,I,Y).normalize(),P.set([O.x,O.y,O.z],o*3),B.set([N,1-K],o*2),D.push(o++)}m.push(D)}for(L=0;L<g;L++)for(W=0;W<u;W++){const D=m[W][L],K=m[W+1][L],q=m[W+1][L+1],N=m[W][L+1];_.set([D,K,N,K,q,N],h*3),h+=2}}function F(L){let W;const O=L===!0?r:n,I=L===!0?1:-1,D=o;for(R.set([0,.5*s*I,0],o*3),P.set([0,I,0],o*3),B.set([.5,.5],o*2),o++,W=0;W<=g;W++){const q=W/g*M+v,N=Math.cos(q),k=Math.sin(q);R.set([O*k,.5*s*I,O*N],o*3),P.set([0,I,0],o*3),B.set([N*.5+.5,k*.5*I+.5],o*2),o++}for(W=0;W<g;W++){const K=D+W+1;L?_.set([K,K+1,D],h*3):_.set([K+1,K,D],h*3),h++}}Object.assign(p,{position:{size:3,data:R},normal:{size:3,data:P},uv:{size:2,data:B},index:{data:_}}),super(e,p)}}class oi extends ut{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 ut{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 R=0;R<=s;R++)for(let P=0;P<=i;P++,x++){const B=P/i*l,_=R/s*Math.PI*2;d.x=(r+n*Math.cos(_))*Math.cos(B),d.y=(r+n*Math.cos(_))*Math.sin(B),d.z=n*Math.sin(_),p.set([d.x,d.y,d.z],x*3),M.x=r*Math.cos(B),M.y=r*Math.sin(B),y.sub(d,M).normalize(),g.set([y.x,y.y,y.z],x*3),u.set([P/i,R/s],x*2)}x=0;for(let R=1;R<=s;R++)for(let P=1;P<=i;P++,x++){const B=(i+1)*R+P-1,_=(i+1)*(R-1)+P-1,o=(i+1)*(R-1)+P,h=(i+1)*R+P;v.set([B,_,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 br,_a=new br,Ea=new br,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 At;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,R=_a,P=Ea;for(let B=a.length-1;B>=0;B--){const _=a[B];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,F;const L=_.geometry,W=L.attributes,O=W.index,I=W.position,D=Math.max(0,L.drawRange.start),K=Math.min(O?O.count:I.count,L.drawRange.start+L.drawRange.count),q=I.size;for(let N=D;N<K;N+=3){const k=O?O.data[N]:N,z=O?O.data[N+1]:N+1,Y=O?O.data[N+2]:N+2;g.fromArray(I.data,k*q),u.fromArray(I.data,z*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=k,w=z,F=Y,M.copy(d)))}h||a.splice(B,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 br,_.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,F*3),this.getBarycoord(_.hit.localPoint,g,u,v,y)),s&&W.uv&&(x.fromArray(W.uv.data,m*2),R.fromArray(W.uv.data,w*2),P.fromArray(W.uv.data,F*2),_.hit.uv.set(x.x*y.x+R.x*y.y+P.x*y.z,x.y*y.x+R.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,F*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((B,_)=>B.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 Ba=`
9
9
  precision highp float;
10
10
  precision highp int;
11
11
 
@@ -22,7 +22,7 @@ ${Wn(r)}`)),this.gl.linkProgram(this.program),!this.gl.getProgramParameter(this.
22
22
  vNormal = normalize(normalMatrix * normal);
23
23
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
24
24
  }
25
- `,Ba=`
25
+ `,La=`
26
26
  precision highp float;
27
27
  precision highp int;
28
28
 
@@ -32,7 +32,7 @@ ${Wn(r)}`)),this.gl.linkProgram(this.program),!this.gl.getProgramParameter(this.
32
32
  gl_FragColor.rgb = normalize(vNormal);
33
33
  gl_FragColor.a = 1.0;
34
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 ir,Da=new ir,za=new ir,Ga=new ir;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 R=fs,P=3;l==="quaternion"&&(R=ds,P=4),R.fromArray(f,0),P===4?i[l].slerp(R,n):i[l].lerp(R,n);return}const p=Math.max(1,c.findIndex(R=>R>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 At,Ha=new At;class Pt 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 Ke(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 vt;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,R;(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()"),(R=r.extensionsRequired)!=null&&R.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 R=e.createBuffer();e.bindBuffer(f,R),e.renderer.state.boundBuffer=R,e.bufferData(f,s[x].data,e.STATIC_DRAW),s[x].buffer=R}),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 Ke(e,p);return v.name=l,f.texture=v,v}const u=new Ke(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:R=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:R,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:R})=>{y===g&&(u++,x!==void 0&&v.push(x),R&&R.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:R,mode:P})=>{const L=new Pt(e,{skeleton:i[y],geometry:x,program:R,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:R})=>{const P=y.attributes.instanceMatrix?ka:nt,L=new P(e,{geometry:y,program:x,mode:R});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 ut(e);if(M&&(y.extras=M),v&&(y.extensions=v),v&&v.KHR_draco_mesh_compression){const x=v.KHR_draco_mesh_compression.bufferView,R=v.KHR_draco_mesh_compression.attributes,P={},L={},_={},o={};for(const w in c){const F=n.accessors[c[w]],B=gs[w];P[B]=R[w],L[B]=F.componentType,_[B]=ps[F.componentType].name,o[B]=F.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 F=m.attributes[w],B=F.name,W=F.array,O=F.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:O,type:I,normalized:D,buffer:K})}if(m.index){const w=m.index.array,F=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:F,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],R=Wa[f],P=ps[l],L=P.BYTES_PER_ELEMENT,_=y/L,o=!!y&&_!==R;let h;if(o){const m=new P(v,i);h=new P(c*R);for(let w=0;w<c;w++){const F=_*w,B=F+R;h.set(m.slice(F,B),w*R)}}else h=new P(v,i,c*R);return{data:h,size:R,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:R,extras:P})=>{const L=c!==void 0,_=L?new Tn(e):new vt;if(L){const F=r.cameras[c];if(F.type==="perspective"){const{yfov:B,znear:W,zfar:O}=F.perspective;_.perspective({fov:B*(180/Math.PI),near:W,far:O})}else{const{xmag:B,ymag:W,znear:O,zfar:I}=F.orthographic;_.orthographic({near:O,far:I,left:-B,right:B,top:-W,bottom:W})}l.push(_)}x&&(_.name=x),P&&(_.extras=P),R&&(_.extensions=R),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(F=>{P&&Object.assign(F.extras,P),F.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(F=>{P&&Object.assign(F.extras,P),F.geometry.isInstanced&&(o=!0,F.instanceCount?h=!1:F.instanceCount=0,F.geometry.attributes.instanceMatrix&&(m=!0,_.matrix.toArray(F.geometry.attributes.instanceMatrix.data,F.instanceCount*16)),F.geometry.attributes.lightmapScaleOffset&&F.geometry.attributes.lightmapScaleOffset.data.set(P.lightmap_scale_offset,F.instanceCount*4),F.instanceCount++,F.instanceCount===F.numInstances&&(delete F.numInstances,delete F.instanceCount,F.geometry.attributes.instanceMatrix&&(F.geometry.attributes.instanceMatrix.needsUpdate=!0),F.geometry.attributes.lightmapScaleOffset&&(F.geometry.attributes.lightmapScaleOffset.needsUpdate=!0))),o?h&&F.setParent(_):F.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 At(...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],R=$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:R,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},qe=()=>{const t=new Float32Array(16);return t[0]=t[5]=t[10]=t[15]=1,t},bt=(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},Bt=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,R=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*(R+y)*l,t[8]=2*(d+P)*a,t[9]=2*(R-y)*a,t[10]=(1-2*(v+x))*a},Kt=Math.PI/180,ja=(t,e,r,n,s)=>{const[i,l,a]=Or(t),c=e*Kt,f=r*Kt,p=n*Kt,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,R=0,P=0,L=0,_=1,o=0,h=0,m=0,w=1;switch(s){case 0:x=v*d,R=-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,R=-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,R=-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,R=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,R=-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,R=-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]=R*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/Kt,u/Kt,v/Kt]},ci=(t,e,r)=>{const n=qe();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*Kt/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*Kt/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},Lt=(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=`
35
+ `;function Na(t){return new ze(t,{vertex:Ba,fragment:La,cullFace:!1})}const fs=new Ce,Oa=new Ce,Ia=new Ce,Ua=new Ce,ds=new ir,Da=new ir,za=new ir,Ga=new ir;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 R=fs,P=3;l==="quaternion"&&(R=ds,P=4),R.fromArray(f,0),P===4?i[l].slerp(R,n):i[l].lerp(R,n);return}const p=Math.max(1,c.findIndex(R=>R>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 At,Ha=new At;class Pt 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 Ke(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 vt;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,R;(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()"),(R=r.extensionsRequired)!=null&&R.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 R=e.createBuffer();e.bindBuffer(f,R),e.renderer.state.boundBuffer=R,e.bufferData(f,s[x].data,e.STATIC_DRAW),s[x].buffer=R}),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 Ke(e,p);return v.name=l,f.texture=v,v}const u=new Ke(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:R=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:R,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:R})=>{y===g&&(u++,x!==void 0&&v.push(x),R&&R.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:R,mode:P})=>{const B=new Pt(e,{skeleton:i[y],geometry:x,program:R,mode:P});return B.name=c,B.extras=p,f&&(B.extensions=f),B.frustumCulled=!1,B}))),l.instanceCount=0,l.numInstances=u):l=(await this.parsePrimitives(e,l,r,n,s,u,M)).map(({geometry:y,program:x,mode:R})=>{const P=y.attributes.instanceMatrix?ka:nt,B=new P(e,{geometry:y,program:x,mode:R});return B.name=c,B.extras=p,f&&(B.extensions=f),B.numInstances=u,B}),{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 ut(e);if(M&&(y.extras=M),v&&(y.extensions=v),v&&v.KHR_draco_mesh_compression){const x=v.KHR_draco_mesh_compression.bufferView,R=v.KHR_draco_mesh_compression.attributes,P={},B={},_={},o={};for(const w in c){const F=n.accessors[c[w]],L=gs[w];P[L]=R[w],B[L]=F.componentType,_[L]=ps[F.componentType].name,o[L]=F.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 F=m.attributes[w],L=F.name,W=F.array,O=F.itemSize,I=B[L],D=o[L],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(L,{data:W,size:O,type:I,normalized:D,buffer:K})}if(m.index){const w=m.index.array,F=m.index.itemSize,L=e.createBuffer();e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,L),e.renderer.state.boundBuffer=L,e.bufferData(e.ELEMENT_ARRAY_BUFFER,w,e.STATIC_DRAW),y.addAttribute("index",{data:w,size:F,type:5125,normalized:!1,buffer:L})}}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],R=Wa[f],P=ps[l],B=P.BYTES_PER_ELEMENT,_=y/B,o=!!y&&_!==R;let h;if(o){const m=new P(v,i);h=new P(c*R);for(let w=0;w<c;w++){const F=_*w,L=F+R;h.set(m.slice(F,L),w*R)}}else h=new P(v,i,c*R);return{data:h,size:R,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:R,extras:P})=>{const B=c!==void 0,_=B?new Tn(e):new vt;if(B){const F=r.cameras[c];if(F.type==="perspective"){const{yfov:L,znear:W,zfar:O}=F.perspective;_.perspective({fov:L*(180/Math.PI),near:W,far:O})}else{const{xmag:L,ymag:W,znear:O,zfar:I}=F.orthographic;_.orthographic({near:O,far:I,left:-L,right:L,top:-W,bottom:W})}l.push(_)}x&&(_.name=x),P&&(_.extras=P),R&&(_.extensions=R),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(F=>{P&&Object.assign(F.extras,P),F.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(F=>{P&&Object.assign(F.extras,P),F.geometry.isInstanced&&(o=!0,F.instanceCount?h=!1:F.instanceCount=0,F.geometry.attributes.instanceMatrix&&(m=!0,_.matrix.toArray(F.geometry.attributes.instanceMatrix.data,F.instanceCount*16)),F.geometry.attributes.lightmapScaleOffset&&F.geometry.attributes.lightmapScaleOffset.data.set(P.lightmap_scale_offset,F.instanceCount*4),F.instanceCount++,F.instanceCount===F.numInstances&&(delete F.numInstances,delete F.instanceCount,F.geometry.attributes.instanceMatrix&&(F.geometry.attributes.instanceMatrix.needsUpdate=!0),F.geometry.attributes.lightmapScaleOffset&&(F.geometry.attributes.lightmapScaleOffset.needsUpdate=!0))),o?h&&F.setParent(_):F.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 At(...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],R=$a[y],P=this.parseAccessor(u,r,s).data,B=this.parseAccessor(M,r,s).data;return x.animations||(x.animations=[]),x.animations.includes(c)||x.animations.push(c),{node:x,transform:R,interpolation:v,times:P,values:B}});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:Li,getBlob:Bi,putBuffer:Ii,putLocalBuffer:Ui,hasLocalBuffer:Oi,getLocalName:Ni,getPlayer:Di,removePlayers:Ri},qe=()=>{const t=new Float32Array(16);return t[0]=t[5]=t[10]=t[15]=1,t},bt=(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,R=p*g,P=p*u,B=g*g,_=g*u;t[0]=(1-2*(x+B))*i,t[1]=2*(M+_)*i,t[2]=2*(d-P)*i,t[4]=2*(M-_)*l,t[5]=(1-2*(v+B))*l,t[6]=2*(R+y)*l,t[8]=2*(d+P)*a,t[9]=2*(R-y)*a,t[10]=(1-2*(v+x))*a},Kt=Math.PI/180,ja=(t,e,r,n,s)=>{const[i,l,a]=Or(t),c=e*Kt,f=r*Kt,p=n*Kt,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,R=0,P=0,B=0,_=1,o=0,h=0,m=0,w=1;switch(s){case 0:x=v*d,R=-v*y,P=M,B=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,R=-v*y+M*u*d,P=M*g,B=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,R=-g*y,P=M*d+v*u*y,B=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,R=u*M*d-g*y,P=g*M*d+u*y,B=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,R=-y,P=M*d,B=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,R=-v*y,P=M,B=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]=B*i,t[2]=h*i,t[4]=R*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/Kt,u/Kt,v/Kt]},ci=(t,e,r)=>{const n=qe();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*Kt/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*Kt/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},Bt=(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
36
  vec3 acesFilmicSrgb(vec3 x) {
37
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
38
  vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
@@ -286,6 +286,12 @@ uniform vec3 baseColor; // linear factor over baseColorMap (both default w
286
286
  uniform sampler2D baseColorMap;
287
287
  uniform float roughness;
288
288
  uniform float metallic;
289
+ // the glow (Material.lit's emissive, linear; black = none) and its luminance: lit.mat's rule exactly —
290
+ // over 0 = cd / m2 of emission 1.0 through the camera's exposure (scene-referred), 0 = added as it is
291
+ // (screen-referred). Not the glTF path's emissive x iblLuminance x exposure: Material.lit looks the same on
292
+ // both hosts. (lit.mat's emissiveBake is the bake's: the lite has no bake and no such uniform.)
293
+ uniform vec3 emissive;
294
+ uniform float emissiveNits;
289
295
  ${Ir}
290
296
  out vec4 fragColor;
291
297
 
@@ -297,6 +303,7 @@ void main() {
297
303
  vec3 diffuseColor = albedo * (1.0 - metallic);
298
304
  vec3 f0 = mix(vec3(0.04), albedo, metallic);
299
305
  vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, 1.0);
306
+ color += emissive * (emissiveNits > 0.0 ? emissiveNits * exposure : 1.0);
300
307
  fragColor = vec4(tonemap(color), 1.0);
301
308
  }
302
309
  `,tl=`#version 300 es
@@ -711,8 +718,8 @@ void main() {
711
718
  vec3 rgb = tex.rgb * vColor.rgb * (1.0 + emissive) + em * emissiveColor;
712
719
  fragColor = vec4(tonemap(rgb) * alpha, alpha * (1.0 - clamp(additive, 0.0, 1.0)));
713
720
  }
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 R=new Uint8Array(t,M,x),P=R.indexOf(0),L=v.decode(R.subarray(0,P)),_=v.decode(R.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 R=n(M);M+=4;const P=[];for(let L=0;L<f;L++)P.push(new Uint8Array(t,M,R)),M+=R+(3-(R+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 Ke(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),R=(h=t.bufferViews)==null?void 0:h[g],P=R?e[typeof R.buffer=="number"?R.buffer:0]:void 0,L=bl[v];if(!R||!P||!L)return x;const _=L.BYTES_PER_ELEMENT,o=(R.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 F=0;F<d;F++)x[m*d+F]=w[F]}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 ir;new ir;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 Ke(t,{image:new Uint8Array([255,255,255,255]),width:1,height:1,generateMipmaps:!1}),Cl=t=>{const e=new Ke(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})),R=new Float32Array(x),P=s[g].weights??v.weights;if(P)for(let _=0;_<Math.min(x,P.length);_++)R[_]=P[_];d.weights=R,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 N=k=>{var z,Y;return k!==void 0&&((Y=(z=e.accessors)==null?void 0:z[k])==null?void 0:Y.count)!==m};return N(q.POSITION)||N(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),O=Math.max(1,Math.ceil(Math.sqrt(W))),I=Math.max(1,Math.ceil(W/O)),D=new Float32Array(O*I*4);for(let q=0;q<w;q++){const N=o[q].POSITION!==void 0?Xr(e,n,o[q].POSITION):null,k=B&&o[q].NORMAL!==void 0?Xr(e,n,o[q].NORMAL):null;for(let z=0;z<m;z++){if(N){const Y=(q*m+z)*4;D[Y]=N[z*3]??0,D[Y+1]=N[z*3+1]??0,D[Y+2]=N[z*3+2]??0}if(k){const Y=((w+q)*m+z)*4;D[Y]=k[z*3]??0,D[Y+1]=k[z*3+1]??0,D[Y+2]=k[z*3+2]??0}}}const K=new Ke(t,{image:D,width:O,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:O,hasNormals:B,weights:R}}}},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 Pt&&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,R,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}),(R=i.normalTexture)!=null&&R.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,R,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-Bd7pdF7u.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=((R=h==null?void 0:h.position)==null?void 0:R.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,F=o._morph;F&&vi(o,F);const B=gi(o),W=w??o;let O=u.get(W);O||u.set(W,O=new Map);let I=O.get(B);I||O.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=`
721
+ `,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 R=new Uint8Array(t,M,x),P=R.indexOf(0),B=v.decode(R.subarray(0,P)),_=v.decode(R.subarray(P+1)).replace(/\0+$/,"");u.set(B,_),M+=x+(3-(x+3)%4)}const y=[];M=d;for(let x=0;x<p;x++){const R=n(M);M+=4;const P=[];for(let B=0;B<f;B++)P.push(new Uint8Array(t,M,R)),M+=R+(3-(R+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 Ke(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),R=(h=t.bufferViews)==null?void 0:h[g],P=R?e[typeof R.buffer=="number"?R.buffer:0]:void 0,B=bl[v];if(!R||!P||!B)return x;const _=B.BYTES_PER_ELEMENT,o=(R.byteOffset??0)+u;if(!y||y===d*_){const m=new B(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 B(P,o+m*y,d);for(let F=0;F<d;F++)x[m*d+F]=w[F]}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 ir;new ir;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 Ke(t,{image:new Uint8Array([255,255,255,255]),width:1,height:1,generateMipmaps:!1}),Cl=t=>{const e=new Ke(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},Br=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})),R=new Float32Array(x),P=s[g].weights??v.weights;if(P)for(let _=0;_<Math.min(x,P.length);_++)R[_]=P[_];d.weights=R,x>Br&&console.warn(`[viewer-lite] GLB: mesh has ${x} morph targets — only the first ${Br} deform`);const B=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=B[_];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,Br);if(o.slice(0,w).find(q=>{const N=k=>{var z,Y;return k!==void 0&&((Y=(z=e.accessors)==null?void 0:z[k])==null?void 0:Y.count)!==m};return N(q.POSITION)||N(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 L=o.slice(0,w).some(q=>q.NORMAL!==void 0),W=m*w*(L?2:1),O=Math.max(1,Math.ceil(Math.sqrt(W))),I=Math.max(1,Math.ceil(W/O)),D=new Float32Array(O*I*4);for(let q=0;q<w;q++){const N=o[q].POSITION!==void 0?Xr(e,n,o[q].POSITION):null,k=L&&o[q].NORMAL!==void 0?Xr(e,n,o[q].NORMAL):null;for(let z=0;z<m;z++){if(N){const Y=(q*m+z)*4;D[Y]=N[z*3]??0,D[Y+1]=N[z*3+1]??0,D[Y+2]=N[z*3+2]??0}if(k){const Y=((w+q)*m+z)*4;D[Y]=k[z*3]??0,D[Y+1]=k[z*3+1]??0,D[Y+2]=k[z*3+2]??0}}}const K=new Ke(t,{image:D,width:O,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:O,hasNormals:L,weights:R}}}},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 Pt&&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>Br?e.weights.subarray(0,Br):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,R,P,B;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(`
722
+ `));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}),(R=i.normalTexture)!=null&&R.texture&&(c.uNormalMap={value:i.normalTexture.texture}),(P=i.occlusionTexture)!=null&&P.texture&&(c.uOcclusionMap={value:i.occlusionTexture.texture}),(B=i.emissiveTexture)!=null&&B.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,R,P,B,_;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-e-m97P8Y.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=((R=h==null?void 0:h.position)==null?void 0:R.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,F=o._morph;F&&vi(o,F);const L=gi(o),W=w??o;let O=u.get(W);O||u.set(W,O=new Map);let I=O.get(L);I||O.set(L,I=Tl(t,w,L,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=(B=p.nodes)==null?void 0:B[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}},Bl={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])}},Ll=`
716
723
  struct MaterialInputs {
717
724
  vec4 baseColor;
718
725
  float roughness;
@@ -760,7 +767,7 @@ vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
760
767
  vec3 b = normalize(cross(ng, t)) * sign(det);
761
768
  return normalize(mat3(t, b, ng) * nTangent);
762
769
  }
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?`
770
+ `,Ol=t=>{if(t.unsupported)return null;const e=[],r=[],n=new Set;for(const u of t.params){const v=Bl[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
771
  void main() {
765
772
  ${ln}
766
773
  float shadowAmount = 1.0 - sampleShadowPCF();
@@ -798,13 +805,13 @@ uniform vec4 userTime;
798
805
  ${e.join(`
799
806
  `)}
800
807
  ${i?Ir:Ar}
801
- ${Bl}
808
+ ${Ll}
802
809
  vec2 getUV0() { return ${p}; }
803
810
  vec2 getUV1() { return ${p}; }
804
811
  ${t.writesNormal?Nl:""}
805
812
  out vec4 fragColor;
806
813
  ${t.fragmentCode}
807
- ${f}`,uniforms:r,paramNames:n,needsSceneUniforms:i}},lt=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,ct=(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,R,P;if(d>0){const L=Math.sqrt(d+1)*2;P=.25*L,y=(g-v)/L,x=(u-c)/L,R=(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,R=(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,R=(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,R=.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]=R,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=ct(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(lt*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(ct(e,w,q=>{const N=e._cphysRagdollJointFrames(o,q);return w.set(e.HEAPF32.subarray(q>>2,(q>>2)+m*9)),N})!==m)return;const B=[],W=[],O=[];for(let q=0;q<m;q++){const N=w[q*9];if(!(N<0)){B.push(h.entities[q],h.entities[N]);for(let k=1;k<9;k++)W.push(w[q*9+k]);O.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<O.length;q++)for(let N=0;N<3;N++)D[O[q]*6+N*2]=I[q*6+N*2]*K-h.margin,D[O[q]*6+N*2+1]=I[q*6+N*2+1]*K+h.margin;ct(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,F=e._cphysPulledPoses()>>2;for(let B=0;B<o;B++){const W=F+B*lt;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,F=e._cphysPulledPoses()>>2;for(let B=0;B<o;B++){const W=F+B*lt;t.setWorldPosition(h[m+B],w[W],w[W+1],w[W+2])}},R=(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 F=h?1:0;if(!w[F]){const W=Fs(m);w[F]=Vr(e,W,O=>e._cphysShapeMeshFromGlb(O,W.length,h?1:0))}return w[F]},P=(o,h,m,w,F,B)=>h?e._cphysBodyCreate(o,h,m|0,w,F?1:0,B?1:0,1,M(o)):0,L=(o,h,m,w)=>{const F=P(o,h,m,w,!1,!1);return h&&e._cphysShapeDestroy(h),F};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,F,B){return ct(e,o,W=>Cs(e,h,O=>e._cphysShapeMesh(W,Math.floor(o.length/3),O,h.length,m?1:0,w,F,B)))},physicsBuildMeshFromEntity(o,h,m,w,F){const B=R(o,h);return B?e._cphysShapeScaled(B,m,w,F):0},physicsBuildHeightField(o,h,m,w,F,B,W,O){return ct(e,o,I=>F?Vr(e,F,D=>e._cphysShapeHeightField(I,h,m,w,D,B,W,O)):e._cphysShapeHeightField(I,h,m,w,0,B,W,O))},physicsUpdateHeightField(o,h,m,w,F,B,W,O,I){ct(e,h,D=>I?Vr(e,I,K=>e._cphysShapeUpdateHeightField(o,D,m,w,F,B,W,O,K)):e._cphysShapeUpdateHeightField(o,D,m,w,F,B,W,O,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,O=>e._cphysGlbTriangles(O,m.length,s));if(!w)return new Float32Array(0);const F=e.HEAPU32[s>>2],B=Float32Array.from(e.HEAPF32.subarray(w>>2,(w>>2)+F));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,F,B)=>P(o,h,m,w,F,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,F,B,W,O){const I=e._cphysRaycast(o,h,m,w,F,B,W,n);return I&&O&&O.set(e.HEAPF32.subarray(n>>2,(n>>2)+Math.min(7,O.length))),I},physicsCreateBox:(o,h,m,w,F,B)=>L(o,e._cphysShapeBox(h,m,w),F,B),physicsCreateSphere:(o,h,m,w)=>L(o,e._cphysShapeSphere(h),m,w),physicsCreateCylinder:(o,h,m,w,F)=>L(o,e._cphysShapeCylinder(h,m),w,F),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,F,B,W){e._cphysBodyApplyImpulseAt(o,h,m,w,F,B,W)},physicsSetBodyPosition(o,h,m,w){e._cphysBodySetPosition(o,h,m,w)},physicsSetBodyRotation(o,h,m,w,F){e._cphysBodySetRotation(o,h,m,w,F)},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,F=n>>2;t.setWorldPosition(m,w[F],w[F+1],w[F+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?ct(e,m,w=>e._cphysVehicleCreate(o,h,w,m.length,M(o))):0},vehicleDestroy(o){e._cphysVehicleDestroy(o)},vehicleSetInput(o,h){ct(e,h,m=>e._cphysVehicleSetInput(o,m,h.length))},vehicleSetTuning(o,h){ct(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,F,B,W,O){e._cphysVehicleReset(o,h,m,w,F,B,W,O)},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 F=new Float32Array(lt);_r(t.world(o),F,0);const B=new Float32Array(w*(lt+3)),W=[];for(let I=0;I<w;I++){const D=I*(lt+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+lt]=q[12],B[D+lt+1]=q[13],B[D+lt+2]=q[14]}}const O=ct(e,F,I=>Cs(e,h,D=>ct(e,B,K=>ct(e,m,q=>e._cphysRagdollCreate(I,D,h.length,K,q,m.length)))));return O&&f.set(O,{entities:W,prev:new Float32Array(w*lt),cur:new Float32Array(w*lt),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}),O},ragdollDestroy(o){e._cphysRagdollDestroy(o),f.delete(o)},ragdollActivate(o,h,m,w){const F=f.get(o);if(!F)return!1;!F.active&&F.learn&&!F.learned&&p(o,F);const B=F.entities.length,W=new Float32Array(B*lt);for(let D=0;D<B;D++)_r(t.world(F.entities[D]),W,D*lt);let O=null;if(!F.active&&F.valid>=2&&F.dt>1e-5){O=new Float32Array(B*6);const D=1/F.dt;for(let K=0;K<B;K++){const q=K*lt,N=K*6;O[N]=(F.cur[q]-F.prev[q])*D,O[N+1]=(F.cur[q+1]-F.prev[q+1])*D,O[N+2]=(F.cur[q+2]-F.prev[q+2])*D;const k=F.prev[q+3],z=F.prev[q+4],Y=F.prev[q+5],se=F.prev[q+6],ee=F.cur[q+3],ne=F.cur[q+4],fe=F.cur[q+5],we=F.cur[q+6];let pe=we*-k+ee*se+ne*-Y-fe*-z,Ge=we*-z-ee*-Y+ne*se+fe*-k,Qe=we*-Y+ee*-z-ne*-k+fe*se,Ue=we*se-ee*-k-ne*-z-fe*-Y;Ue<0&&(pe=-pe,Ge=-Ge,Qe=-Qe,Ue=-Ue);const S=Math.sqrt(Math.max(0,1-Ue*Ue));if(S>1e-6){const A=2*Math.acos(Math.min(1,Ue))/S*D;O[N+3]=pe*A,O[N+4]=Ge*A,O[N+5]=Qe*A}}}const I=ct(e,W,D=>O?ct(e,O,K=>e._cphysRagdollActivate(o,h,m,w,D,K)):e._cphysRagdollActivate(o,h,m,w,D,0))!==0;return I&&(F.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 F=e._cphysEventCount();if(F>0&&u){const B=e._cphysEventData()>>2,W=Array.from(e.HEAPU32.subarray(B,B+F*3));for(let O=0;O<F;O++)u(W[O*3],W[O*3+1],W[O*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 F=0;F<m.entities.length;F++)_r(t.world(m.entities[F]),m.cur,F*lt);o>1e-5&&(m.dt=o),m.valid<2&&m.valid++,m.active&&m.driven&&ct(e,m.cur,F=>e._cphysRagdollSetTarget(h,F))}y(e._cphysPullRagdolls())}},applyRootMotion(o,h,m,w,F){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),F!==0){const O=t.get(B);O&&(Dl(O.m,F),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},Re=Math.fround,Rs=Re(1/3),Vl=Re(1/6),Ps=Re(2/3),Hl=Re(3.14159265),kl=Re(.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},qt=(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=Re(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(!qt(t,c,f,"deg"))if(qt(t,c,f,"rad"))l=Re(l*180),l=Re(l/Hl);else if(qt(t,c,f,"turn"))l=Re(l*360);else if(qt(t,c,f,"grad"))l=Re(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},rr=t=>t<0?0:t>1?1:t,cn=(t,e,r)=>{r<0&&(r=Re(r+1)),r>1&&(r=Re(r-1));const n=Re(e-t);return r<Vl?Re(t+Re(Re(n*6)*r)):r<.5?e:r<Ps?Re(t+Re(Re(n*Re(Ps-r))*6)):t},un=(t,e,r,n)=>({r:Re(t/255),g:Re(e/255),b:Re(r/255),a:Re(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?rr(f[3].percent?Re(f[3].v/100):f[3].v):1,g=l-n;if(qt(r,n,g,"rgb")||qt(r,n,g,"rgba")){const u=v=>rr(v.percent?Re(v.v/100):Re(v.v/255));return{r:u(f[0]),g:u(f[1]),b:u(f[2]),a:p}}if(qt(r,n,g,"hsl")||qt(r,n,g,"hsla")){let u=f[0].v%360;u<0&&(u=Re(u+360)),u=Re(u/360);const v=rr(Re(f[1].v/100)),M=rr(Re(f[2].v/100));if(v<=0)return{r:M,g:M,b:M,a:p};const d=M<.5?Re(M*Re(1+v)):Re(Re(M+v)-Re(M*v)),y=Re(Re(2*M)-d);return{r:rr(cn(y,d,Re(u+Rs))),g:rr(cn(y,d,u)),b:rr(cn(y,d,Re(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)},Yt=t=>{const e=Re(t);if(!(e>0))return 0;if(e>=1)return 255;const r=Re(e*255);return Math.floor(Re(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[Yt(e[0]),Yt(e[1]),Yt(e[2]),Yt(e[3])]},kr=t=>(t<16?"0":"")+t.toString(16),Kl=t=>"#"+kr(Yt(t[0]))+kr(Yt(t[1]))+kr(Yt(t[2]))+kr(Yt(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]],xr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],wr=(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]],vr=t=>Math.hypot(t[0],t[1],t[2]),Mr=t=>{const e=vr(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},mr=(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:xr(t,wr(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=xr(r,wr(n,g)),v=Math.max(0,st(et(u,t),e));return{dist:vr(et(u,xr(t,wr(e,v)))),t:g}},ac=(t,e,r)=>{const n=Cn(Mr(et(t,r)),e),s=Cn(e,n);return st(s,s)<1e-4?Mr(et(t,r)):Mr(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 R=.5/Math.sqrt(v+1);x=.25/R,M=(f-g)*R,d=(p-l)*R,y=(i-a)*R}else if(s>c&&s>u){const R=2*Math.sqrt(1+s-c-u);x=(f-g)/R,M=.25*R,d=(a+i)/R,y=(p+l)/R}else if(c>u){const R=2*Math.sqrt(1+c-s-u);x=(p-l)/R,M=(a+i)/R,d=.25*R,y=(g+f)/R}else{const R=2*Math.sqrt(1+u-s-c);x=(i-a)/R,M=(p+l)/R,d=(g+f)/R,y=.25*R}return{position:[t[12],t[13],t[14]],quaternion:[M,d,y,x],scale:[e,r,n]}},uc=`#version 300 es
814
+ ${f}`,uniforms:r,paramNames:n,needsSceneUniforms:i}},lt=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,ct=(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,R,P;if(d>0){const B=Math.sqrt(d+1)*2;P=.25*B,y=(g-v)/B,x=(u-c)/B,R=(a-f)/B}else if(l>p&&l>M){const B=Math.sqrt(1+l-p-M)*2;P=(g-v)/B,y=.25*B,x=(f+a)/B,R=(u+c)/B}else if(p>M){const B=Math.sqrt(1+p-l-M)*2;P=(u-c)/B,y=(f+a)/B,x=.25*B,R=(v+g)/B}else{const B=Math.sqrt(1+M-l-p)*2;P=(a-f)/B,y=(u+c)/B,x=(v+g)/B,R=.25*B}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]=R,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=ct(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(lt*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(ct(e,w,q=>{const N=e._cphysRagdollJointFrames(o,q);return w.set(e.HEAPF32.subarray(q>>2,(q>>2)+m*9)),N})!==m)return;const L=[],W=[],O=[];for(let q=0;q<m;q++){const N=w[q*9];if(!(N<0)){L.push(h.entities[q],h.entities[N]);for(let k=1;k<9;k++)W.push(w[q*9+k]);O.push(q)}}if(L.length===0)return;const I=t.jointRanges(h.entities[0],L,Float32Array.from(W));if(!I)return;const D=new Float32Array(m*6),K=180/Math.PI;for(let q=0;q<O.length;q++)for(let N=0;N<3;N++)D[O[q]*6+N*2]=I[q*6+N*2]*K-h.margin,D[O[q]*6+N*2+1]=I[q*6+N*2+1]*K+h.margin;ct(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,F=e._cphysPulledPoses()>>2;for(let L=0;L<o;L++){const W=F+L*lt;t.setWorldTRS(h[m+L],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,F=e._cphysPulledPoses()>>2;for(let L=0;L<o;L++){const W=F+L*lt;t.setWorldPosition(h[m+L],w[W],w[W+1],w[W+2])}},R=(o,h)=>{var L;const m=(L=t.glbBytes)==null?void 0:L.call(t,o);if(!m)return 0;let w=g.get(m);w||(w=[0,0],g.set(m,w));const F=h?1:0;if(!w[F]){const W=Fs(m);w[F]=Vr(e,W,O=>e._cphysShapeMeshFromGlb(O,W.length,h?1:0))}return w[F]},P=(o,h,m,w,F,L)=>h?e._cphysBodyCreate(o,h,m|0,w,F?1:0,L?1:0,1,M(o)):0,B=(o,h,m,w)=>{const F=P(o,h,m,w,!1,!1);return h&&e._cphysShapeDestroy(h),F};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,F,L){return ct(e,o,W=>Cs(e,h,O=>e._cphysShapeMesh(W,Math.floor(o.length/3),O,h.length,m?1:0,w,F,L)))},physicsBuildMeshFromEntity(o,h,m,w,F){const L=R(o,h);return L?e._cphysShapeScaled(L,m,w,F):0},physicsBuildHeightField(o,h,m,w,F,L,W,O){return ct(e,o,I=>F?Vr(e,F,D=>e._cphysShapeHeightField(I,h,m,w,D,L,W,O)):e._cphysShapeHeightField(I,h,m,w,0,L,W,O))},physicsUpdateHeightField(o,h,m,w,F,L,W,O,I){ct(e,h,D=>I?Vr(e,I,K=>e._cphysShapeUpdateHeightField(o,D,m,w,F,L,W,O,K)):e._cphysShapeUpdateHeightField(o,D,m,w,F,L,W,O,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,O=>e._cphysGlbTriangles(O,m.length,s));if(!w)return new Float32Array(0);const F=e.HEAPU32[s>>2],L=Float32Array.from(e.HEAPF32.subarray(w>>2,(w>>2)+F));return e._free(w),L},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,F,L)=>P(o,h,m,w,F,L),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,F,L,W,O){const I=e._cphysRaycast(o,h,m,w,F,L,W,n);return I&&O&&O.set(e.HEAPF32.subarray(n>>2,(n>>2)+Math.min(7,O.length))),I},physicsCreateBox:(o,h,m,w,F,L)=>B(o,e._cphysShapeBox(h,m,w),F,L),physicsCreateSphere:(o,h,m,w)=>B(o,e._cphysShapeSphere(h),m,w),physicsCreateCylinder:(o,h,m,w,F)=>B(o,e._cphysShapeCylinder(h,m),w,F),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,F,L,W){e._cphysBodyApplyImpulseAt(o,h,m,w,F,L,W)},physicsSetBodyPosition(o,h,m,w){e._cphysBodySetPosition(o,h,m,w)},physicsSetBodyRotation(o,h,m,w,F){e._cphysBodySetRotation(o,h,m,w,F)},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,F=n>>2;t.setWorldPosition(m,w[F],w[F+1],w[F+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?ct(e,m,w=>e._cphysVehicleCreate(o,h,w,m.length,M(o))):0},vehicleDestroy(o){e._cphysVehicleDestroy(o)},vehicleSetInput(o,h){ct(e,h,m=>e._cphysVehicleSetInput(o,m,h.length))},vehicleSetTuning(o,h){ct(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,F,L,W,O){e._cphysVehicleReset(o,h,m,w,F,L,W,O)},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 F=new Float32Array(lt);_r(t.world(o),F,0);const L=new Float32Array(w*(lt+3)),W=[];for(let I=0;I<w;I++){const D=I*(lt+3);_r(t.world(h[I*2]),L,D),W.push(h[I*2]);const K=h[I*2+1];if(K){const q=t.world(K);L[D+lt]=q[12],L[D+lt+1]=q[13],L[D+lt+2]=q[14]}}const O=ct(e,F,I=>Cs(e,h,D=>ct(e,L,K=>ct(e,m,q=>e._cphysRagdollCreate(I,D,h.length,K,q,m.length)))));return O&&f.set(O,{entities:W,prev:new Float32Array(w*lt),cur:new Float32Array(w*lt),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}),O},ragdollDestroy(o){e._cphysRagdollDestroy(o),f.delete(o)},ragdollActivate(o,h,m,w){const F=f.get(o);if(!F)return!1;!F.active&&F.learn&&!F.learned&&p(o,F);const L=F.entities.length,W=new Float32Array(L*lt);for(let D=0;D<L;D++)_r(t.world(F.entities[D]),W,D*lt);let O=null;if(!F.active&&F.valid>=2&&F.dt>1e-5){O=new Float32Array(L*6);const D=1/F.dt;for(let K=0;K<L;K++){const q=K*lt,N=K*6;O[N]=(F.cur[q]-F.prev[q])*D,O[N+1]=(F.cur[q+1]-F.prev[q+1])*D,O[N+2]=(F.cur[q+2]-F.prev[q+2])*D;const k=F.prev[q+3],z=F.prev[q+4],Y=F.prev[q+5],se=F.prev[q+6],ee=F.cur[q+3],ne=F.cur[q+4],fe=F.cur[q+5],we=F.cur[q+6];let pe=we*-k+ee*se+ne*-Y-fe*-z,Ge=we*-z-ee*-Y+ne*se+fe*-k,Qe=we*-Y+ee*-z-ne*-k+fe*se,Ue=we*se-ee*-k-ne*-z-fe*-Y;Ue<0&&(pe=-pe,Ge=-Ge,Qe=-Qe,Ue=-Ue);const S=Math.sqrt(Math.max(0,1-Ue*Ue));if(S>1e-6){const A=2*Math.acos(Math.min(1,Ue))/S*D;O[N+3]=pe*A,O[N+4]=Ge*A,O[N+5]=Qe*A}}}const I=ct(e,W,D=>O?ct(e,O,K=>e._cphysRagdollActivate(o,h,m,w,D,K)):e._cphysRagdollActivate(o,h,m,w,D,0))!==0;return I&&(F.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 L=0;L<m;L++)h&&(y(e._cphysPullBodies(_s)),x(e._cphysPullCharacters(_s)),h(w)),e._cphysStep();e._cphysFrameEnd(),y(e._cphysPullBodies(Ss)),x(e._cphysPullCharacters(Ss));const F=e._cphysEventCount();if(F>0&&u){const L=e._cphysEventData()>>2,W=Array.from(e.HEAPU32.subarray(L,L+F*3));for(let O=0;O<F;O++)u(W[O*3],W[O*3+1],W[O*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 F=0;F<m.entities.length;F++)_r(t.world(m.entities[F]),m.cur,F*lt);o>1e-5&&(m.dt=o),m.valid<2&&m.valid++,m.active&&m.driven&&ct(e,m.cur,F=>e._cphysRagdollSetTarget(h,F))}y(e._cphysPullRagdolls())}},applyRootMotion(o,h,m,w,F){for(let L=o;L;L=t.parentOf(L)){const W=e._cphysCharacterForEntity(L);if(W){if(e._cphysCharacterSetExternalVelocity(W,w>0?h/w:0,w>0?m/w:0),F!==0){const O=t.get(L);O&&(Dl(O.m,F),t.localMatrixChanged(L))}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},Re=Math.fround,Rs=Re(1/3),Vl=Re(1/6),Ps=Re(2/3),Hl=Re(3.14159265),kl=Re(.9),En=t=>t===32||t>=9&&t<=13,Hr=t=>t>=48&&t<=57,qr=t=>t>=65&&t<=90?t+32:t,Bs=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},qt=(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=Re(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&&Bs(t.charCodeAt(s))){const c=s;for(;s<r&&Bs(t.charCodeAt(s));)s++;const f=s-c;if(!qt(t,c,f,"deg"))if(qt(t,c,f,"rad"))l=Re(l*180),l=Re(l/Hl);else if(qt(t,c,f,"turn"))l=Re(l*360);else if(qt(t,c,f,"grad"))l=Re(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},rr=t=>t<0?0:t>1?1:t,cn=(t,e,r)=>{r<0&&(r=Re(r+1)),r>1&&(r=Re(r-1));const n=Re(e-t);return r<Vl?Re(t+Re(Re(n*6)*r)):r<.5?e:r<Ps?Re(t+Re(Re(n*Re(Ps-r))*6)):t},un=(t,e,r,n)=>({r:Re(t/255),g:Re(e/255),b:Re(r/255),a:Re(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?rr(f[3].percent?Re(f[3].v/100):f[3].v):1,g=l-n;if(qt(r,n,g,"rgb")||qt(r,n,g,"rgba")){const u=v=>rr(v.percent?Re(v.v/100):Re(v.v/255));return{r:u(f[0]),g:u(f[1]),b:u(f[2]),a:p}}if(qt(r,n,g,"hsl")||qt(r,n,g,"hsla")){let u=f[0].v%360;u<0&&(u=Re(u+360)),u=Re(u/360);const v=rr(Re(f[1].v/100)),M=rr(Re(f[2].v/100));if(v<=0)return{r:M,g:M,b:M,a:p};const d=M<.5?Re(M*Re(1+v)):Re(Re(M+v)-Re(M*v)),y=Re(Re(2*M)-d);return{r:rr(cn(y,d,Re(u+Rs))),g:rr(cn(y,d,u)),b:rr(cn(y,d,Re(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)},Yt=t=>{const e=Re(t);if(!(e>0))return 0;if(e>=1)return 255;const r=Re(e*255);return Math.floor(Re(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),Ls=t=>{const e=$r(t);return[Yt(e[0]),Yt(e[1]),Yt(e[2]),Yt(e[3])]},kr=t=>(t<16?"0":"")+t.toString(16),Kl=t=>"#"+kr(Yt(t[0]))+kr(Yt(t[1]))+kr(Yt(t[2]))+kr(Yt(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=Ls(t);return e[0]<<16|e[1]<<8|e[2]},toPackedRgba(t){const e=Ls(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]],xr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],wr=(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]],vr=t=>Math.hypot(t[0],t[1],t[2]),Mr=t=>{const e=vr(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},mr=(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:xr(t,wr(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=xr(r,wr(n,g)),v=Math.max(0,st(et(u,t),e));return{dist:vr(et(u,xr(t,wr(e,v)))),t:g}},ac=(t,e,r)=>{const n=Cn(Mr(et(t,r)),e),s=Cn(e,n);return st(s,s)<1e-4?Mr(et(t,r)):Mr(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 R=.5/Math.sqrt(v+1);x=.25/R,M=(f-g)*R,d=(p-l)*R,y=(i-a)*R}else if(s>c&&s>u){const R=2*Math.sqrt(1+s-c-u);x=(f-g)/R,M=.25*R,d=(a+i)/R,y=(p+l)/R}else if(c>u){const R=2*Math.sqrt(1+c-s-u);x=(p-l)/R,M=(a+i)/R,d=.25*R,y=(g+f)/R}else{const R=2*Math.sqrt(1+u-s-c);x=(i-a)/R,M=(p+l)/R,d=(g+f)/R,y=.25*R}return{position:[t[12],t[13],t[14]],quaternion:[M,d,y,x],scale:[e,r,n]}},uc=`#version 300 es
808
815
  precision highp float;
809
816
  in vec3 position;
810
817
  in vec3 normal;
@@ -881,8 +888,8 @@ void main() {
881
888
  if (a < 0.02) discard;
882
889
  fragColor = vec4(uColor * a, a);
883
890
  }
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 vt;{const te=[];for(let Q=-10;Q<=10;Q++)Q!==0&&te.push(Q,0,-10,Q,0,10,-10,0,Q,10,0,Q);const X=(Q,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 he=new ut(e,{position:{size:3,data:Float32Array.from(Q)}}),le=new nt(e,{geometry:he,program:oe,mode:e.LINES});return le.frustumCulled=!1,le};M.addChild(X(te,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 Q of v)Q.uniforms.uColor.value=[X,X,X]}},x=new ze(e,{vertex:uc,fragment:hc,uniforms:{uColor:{value:[1,1,1]}}}),R=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 vt;_.matrixAutoUpdate=!1;const o=($,te,X=x)=>($._axis=te,$.frustumCulled=!1,$.onBeforeRender(()=>{const Q=L?L.axis:P,ae=te===3?sc:nc[te];X.uniforms.uColor.value=Q===te?Us(ae):ae}),$),h=($,te)=>{const X=new vt;return te===0?X.rotation.z=-Math.PI/2:te===2&&(X.rotation.x=Math.PI/2),X.setParent($),X},m=new vt,w=new vt,F=new vt;for(const $ of[m,w,F])$.setParent(_);{const $=new is(e,{radiusTop:.014,radiusBottom:.014,height:.78,radialSegments:6}),te=new is(e,{radiusTop:.001,radiusBottom:.065,height:.26,radialSegments:12}),X=new ss(e,{width:.1,height:.1,depth:.1}),Q=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 he=h(m,oe),le=o(new nt(e,{geometry:$,program:x}),oe);le.position.y=.39;const me=o(new nt(e,{geometry:te,program:x}),oe);me.position.y=.87,he.addChild(le),he.addChild(me);const Me=h(F,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,Me.addChild(Ee),Me.addChild(xe);const Se=o(new nt(e,{geometry:ae,program:R}),oe,R);oe===0?Se.rotation.y=Math.PI/2:oe===1&&(Se.rotation.x=Math.PI/2),w.addChild(Se)}F.addChild(o(new nt(e,{geometry:Q,program:x}),3))}const B=()=>{if(c===null||f===null||!i.entities.has(c))return null;const $=i.activeSceneId(),te=i.scenes.get($);if(!te||te.camera===void 0)return null;const X=i.worldMatrixF(c),Q=[X[12],X[13],X[14]],oe=p==="local"||f==="scale"?[0,1,2].map(Me=>Mr([X[Me*4],X[Me*4+1],X[Me*4+2]])):[[1,0,0],[0,1,0],[0,0,1]],he=i.worldMatrixF(te.camera),le=[he[12],he[13],he[14]],me=vr(et(Q,le))||1;return{origin:Q,axes:oe,scale:me*Zl*i.projectionOf($).fov,camPos:le,sceneId:$}},W=()=>{const $=B();if(!$)return!1;const te=_.matrix;for(let Q=0;Q<3;Q++)te[Q]=$.axes[0][Q]*$.scale,te[4+Q]=$.axes[1][Q]*$.scale,te[8+Q]=$.axes[2][Q]*$.scale,te[12+Q]=$.origin[Q];te[3]=0,te[7]=0,te[11]=0,te[15]=1,_.worldMatrixNeedsUpdate=!0,m.visible=f==="translate",w.visible=f==="rotate",F.visible=f==="scale";const X=R.uniforms;X.uOrigin.value=$.origin,X.uEye.value=$.camPos,X.uFull.value=L&&f==="rotate"?1:0;for(const Q of[m,w,F])Q.traverse(ae=>{ae._axis!==void 0&&(ae.visible=L===null||ae._axis===L.axis)});return!0},O=($,te)=>{const X=B();if(!X)return null;const{origin:Q,dir:ae}=t.getViewRay(X.sceneId,$,te),oe=ec*X.scale;if(f==="rotate"){const me=Mr(et(X.origin,X.camPos));let Me=null,Ee=1/0;for(let xe=0;xe<3;xe++){const Se=mr(Q,ae,X.origin,X.axes[xe]);if(!Se||st(et(Se,X.origin),me)>0)continue;const Ie=Math.abs(vr(et(Se,X.origin))-Os*X.scale),Le=vr(et(Se,Q));Ie<oe&&Le<Ee&&(Me=xe,Ee=Le)}return Me}if(f==="scale"){const{dist:me}=zs(Q,ae,X.origin,Mr(ae),0);if(me<Jl*X.scale)return 3}let he=null,le=oe;for(let me=0;me<3;me++){const{dist:Me}=zs(Q,ae,X.origin,X.axes[me],(Ns+.05)*X.scale);Me<=le&&(le=Me,he=me)}return he},I=$=>{const te=n.getBoundingClientRect(),X=In(n);return[($.clientX-te.left)/X,($.clientY-te.top)/X]},D=($,te)=>{const X=B();if(!X||c===null)return!1;const Q=c,ae=i.ent(Q),oe=Float32Array.from(ae.m),he=ae.parent!==0?i.worldMatrixF(ae.parent):qe(),le=Bt(Float32Array.from(he)),me=bt(new Float32Array(16),he,oe),[Me]=I(te);let Ee=null;if($===3)Ee=Be=>{const[$e]=I(Be),Ze=Math.max(.01,1+($e-Me)/150),Ye=Float32Array.from(oe);for(let it=0;it<3;it++)for(let Xe=0;Xe<3;Xe++)Ye[it*4+Xe]*=Ze;i.methods.setMatrix(Q,Ye)};else if(f==="rotate"){const Be=X.axes[$],{origin:$e,dir:Ze}=t.getViewRay(X.sceneId,...I(te)),Ye=mr($e,Ze,X.origin,Be);if(!Ye)return!1;const it=et(Ye,X.origin);Ee=Xe=>{const yt=t.getViewRay(X.sceneId,...I(Xe)),ft=mr(yt.origin,yt.dir,X.origin,Be);if(!ft)return;const tt=et(ft,X.origin);let rt=Math.atan2(st(Cn(it,tt),Be),st(it,tt));Xe.ctrlKey&&(rt=Math.round(rt/Is)*Is);const je=lc(Be,rt),Je=[0,0,0];Lt(Je,je,X.origin[0],X.origin[1],X.origin[2],1),je[12]=X.origin[0]-Je[0],je[13]=X.origin[1]-Je[1],je[14]=X.origin[2]-Je[2];const zt=bt(new Float32Array(16),je,me),Gt=ae.parent!==0?bt(new Float32Array(16),le,zt):zt;i.methods.setMatrix(Q,Gt)}}else{const Be=X.axes[$],$e=ac(X.origin,Be,X.camPos),{origin:Ze,dir:Ye}=t.getViewRay(X.sceneId,...I(te)),it=mr(Ze,Ye,X.origin,$e);if(!it)return!1;if(f==="translate"){const Xe=[me[12],me[13],me[14]];Ee=yt=>{const ft=t.getViewRay(X.sceneId,...I(yt)),tt=mr(ft.origin,ft.dir,X.origin,$e);if(!tt)return;const rt=st(et(tt,it),Be),je=xr(Xe,wr(Be,rt)),Je=[0,0,0];ae.parent!==0?Lt(Je,le,je[0],je[1],je[2],1):(Je[0]=je[0],Je[1]=je[1],Je[2]=je[2]),i.methods.setPosition(Q,Je[0],Je[1],Je[2])}}else Ee=Xe=>{const yt=t.getViewRay(X.sceneId,...I(Xe)),ft=mr(yt.origin,yt.dir,X.origin,$e);if(!ft)return;const tt=Math.max(.01,1+st(et(ft,it),Be)/(Ns*X.scale)),rt=Float32Array.from(oe);for(let je=0;je<3;je++)rt[$*4+je]*=tt;i.methods.setMatrix(Q,rt)}}if(!Ee)return!1;const xe=n.ownerDocument.defaultView??window,Se=te.pointerId,Ie=Be=>{Be.pointerId===Se&&(L==null||L.onMove(Be))},Le=Be=>{var Ze;if(!L)return;const $e=L;L=null,$e.cleanup(),Be?(Ze=l.onTransformEnd)==null||Ze.call(l,Q,cc(i.ent(Q).m),f):i.methods.setMatrix(Q,$e.startLocal)},Oe=Be=>{Be.pointerId===Se&&Le(!0)},De=()=>Le(!1),Ne=Be=>{Be.code==="Escape"&&Le(!1)};return xe.addEventListener("pointermove",Ie),xe.addEventListener("pointerup",Oe),xe.addEventListener("pointercancel",De),xe.addEventListener("keydown",Ne),L={axis:$,startLocal:oe,onMove:Ee,cleanup:()=>{xe.removeEventListener("pointermove",Ie),xe.removeEventListener("pointerup",Oe),xe.removeEventListener("pointercancel",De),xe.removeEventListener("keydown",Ne)}},!0},K=new Pa,q=($,te)=>{var Ee,xe;const X=i.activeSceneId(),Q=t.sceneRoots.get(X),ae=i.scenes.get(X);if(!Q||!ae||ae.camera===void 0)return 0;const{origin:oe,dir:he}=t.getViewRay(X,$,te);K.origin.set(oe[0],oe[1],oe[2]),K.direction.set(he[0],he[1],he[2]);const le=[],me=[];for(const Se of t.collectMeshes(Q)){const Ie=(xe=(Ee=Se.geometry)==null?void 0:Ee.attributes)==null?void 0:xe.position;if(!(Ie!=null&&Ie.data))continue;const Le=Ie.stride&&Ie.stride!==Ie.size*Ie.data.BYTES_PER_ELEMENT;Se.mode===e.TRIANGLES&&!Le?le.push(Se):me.push(Se)}Q.updateMatrixWorld();let Me=null;try{for(const Se of K.intersectMeshes(le,{cullFace:!1,includeUV:!1,includeNormal:!1,output:[]}))(!Me||Se.hit.distance<Me.hit.distance)&&(Me=Se)}catch{}try{for(const Se of K.intersectBounds(me,{output:[]}))(!Me||Se.hit.distance<Me.hit.distance)&&(Me=Se)}catch{}return(Me==null?void 0:Me._entId)??0};let N=null;const k=$=>{if($.button!==0||$.shiftKey||L)return;const[te,X]=I($),Q=O(te,X);if(Q!==null&&D(Q,$)){$.preventDefault(),$.stopPropagation(),N=null;return}N={pointerId:$.pointerId,x:$.clientX,y:$.clientY}},z=$=>{var ae;const te=N;if(N=null,!te||te.pointerId!==$.pointerId||Math.abs($.clientX-te.x)+Math.abs($.clientY-te.y)>tc)return;const[X,Q]=I($);(ae=l.onPick)==null||ae.call(l,re(X,Q)||q(X,Q))},Y=$=>{if(L)return;const[te,X]=I($),Q=f!==null&&c!==null?O(te,X):null,ae=Q===null&&S.length>0&&re(te,X)||null;(Q!==P||ae!==A)&&(P=Q,A=ae,n.style.cursor=Q!==null||ae!==null?"pointer":"")};n.addEventListener("pointerdown",k),n.addEventListener("pointerup",z),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 ee=$=>new ut(e,{position:{size:3,data:Float32Array.from($)}}),ne=($,te,X,Q,ae=32)=>{for(let oe=0;oe<ae;oe++)for(const he of[Math.PI*2*oe/ae,Math.PI*2*(oe+1)/ae]){const le=Math.cos(he)*te,me=Math.sin(he)*te;Q===1?$.push(le,X,me):Q===0?$.push(X,le,me):$.push(le,me,X)}},fe=ee((()=>{const $=[],te=X=>[X&1?1:-1,X&2?1:-1,X&4?1:-1];for(let X=0;X<8;X++)for(const Q of[1,2,4])X&Q||$.push(...te(X),...te(X|Q));return $})()),we=ee((()=>{const $=[];return ne($,1,0,0),ne($,1,0,1),ne($,1,0,2),$})()),pe=new Map,Ge=($,te,X)=>{const Q=`${$}:${te}:${X}`;let ae=pe.get(Q);if(ae)return ae;const oe=[];ne(oe,X,te,1),ne(oe,X,-te,1);for(const[he,le]of[[X,0],[-X,0],[0,X],[0,-X]])oe.push(he,-te,le,he,te,le);if($==="capsule")for(const le of[!0,!1])for(const me of[0,2])for(let Me=0;Me<12;Me++)for(const Ee of[Math.PI*Me/12,Math.PI*(Me+1)/12]){const xe=Math.cos(Ee)*X,Se=(le?te:-te)+Math.sin(Ee)*X*(le?1:-1);me===0?oe.push(xe,Se,0):oe.push(0,Se,xe)}return ae=ee(oe),pe.size>64&&pe.clear(),pe.set(Q,ae),ae},Qe=new vt,Ue=[],S=[];let A=null;const C=[.81,.83,.87,1],G=$=>{var te,X;for(const Q of Ue)Q.setParent(null),(X=(te=Q.geometry).remove)==null||X.call(te);Ue.length=0,S.length=0,A=null;for(const Q of Array.isArray($)?$:[]){if(!Q||!Array.isArray(Q.segments)||Q.segments.length<6)continue;const[ae,oe,he,le]=Ql.tryParse(Q.color)??C,me=[ae,oe,he],Me=Math.max(0,Math.min(1,Number(Q.alpha??1)*le)),Ee=new ze(e,{vertex:dn,fragment:mn,uniforms:{uColor:{value:me.slice()},uAlpha:{value:Me}},transparent:!0,depthTest:!1,depthWrite:!1});Ee.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const xe=Math.floor(Q.segments.length/6)*6,Se=Float32Array.from(Q.segments.slice(0,xe)),Ie=new ut(e,{position:{size:3,data:Se}}),Le=new nt(e,{geometry:Ie,program:Ee,mode:e.LINES});Le.frustumCulled=!1,Le.setParent(Qe),Ue.push(Le);const Oe=Number(Q.entityId??0);Oe>0&&(Le.matrixAutoUpdate=!1,S.push({entityId:Oe,mesh:Le,program:Ee,color:me,segments:Se}))}},Z=()=>{for(const $ of S){if(!i.entities.has($.entityId)){$.mesh.visible=!1;continue}$.mesh.visible=!0,$.mesh.matrix.copy(Pe($.entityId)),$.mesh.worldMatrixNeedsUpdate=!0;const te=$.entityId===c?Ds:$.entityId===A?Us($.color):$.color,X=$.program.uniforms.uColor.value;X[0]=te[0],X[1]=te[1],X[2]=te[2]}},re=($,te)=>{if(S.length===0)return 0;const X=i.activeSceneId(),Q=i.scenes.get(X);if(!Q||Q.camera===void 0)return 0;const{origin:ae,dir:oe}=t.getViewRay(X,$,te),he=n.getBoundingClientRect(),le=Math.max(1,he.height/In(n)),me=2*Math.tan(i.projectionOf(X).fov*Math.PI/360)*rc/le;let Me=0,Ee=1,xe=1/0;const Se=[0,0,0],Ie=[0,0,0];for(const Le of S){if(!i.entities.has(Le.entityId))continue;const Oe=Pe(Le.entityId),De=Le.segments;for(let Ne=0;Ne+5<De.length;Ne+=6){for(let dt=0;dt<3;dt++)Se[dt]=Oe[dt]*De[Ne]+Oe[4+dt]*De[Ne+1]+Oe[8+dt]*De[Ne+2]+Oe[12+dt],Ie[dt]=Oe[dt]*De[Ne+3]+Oe[4+dt]*De[Ne+4]+Oe[8+dt]*De[Ne+5]+Oe[12+dt];const Be=et(Ie,Se),$e=et(Se,ae),Ze=st(oe,oe),Ye=st(oe,Be),it=st(Be,Be),Xe=st(oe,$e),yt=st(Be,$e),ft=Ze*it-Ye*Ye;let tt=ft>1e-12?(Ye*Xe-Ze*yt)/ft:0;tt=Math.max(0,Math.min(1,tt));const rt=Math.max(0,(Xe+tt*Ye)/(Ze||1)),je=xr(Se,wr(Be,tt)),Je=xr(ae,wr(oe,rt));if(rt<=1e-6)continue;const zt=rt*me,Gt=vr(et(je,Je))/zt;Gt>1||(Gt<Ee-.001||Math.abs(Gt-Ee)<=.001&&rt<xe)&&(Me=Le.entityId,Ee=Gt,xe=rt)}}return Me};let ce=[];const Ae=new vt,Te=[],Fe=[1,1,1],Pe=$=>{const te=Float32Array.from(i.worldMatrix($));for(let X=0;X<3;X++){const Q=Math.hypot(te[X*4],te[X*4+1],te[X*4+2])||1;Fe[X]=Q,te[X*4]/=Q,te[X*4+1]/=Q,te[X*4+2]/=Q}return te},ke=($,te,X,Q,ae=0,oe=0,he=0)=>{const le=Float32Array.from($);le[12]=$[12]+$[0]*ae+$[4]*oe+$[8]*he,le[13]=$[13]+$[1]*ae+$[5]*oe+$[9]*he,le[14]=$[14]+$[2]*ae+$[6]*oe+$[10]*he;for(let me=0;me<3;me++)le[me]*=te,le[4+me]*=X,le[8+me]*=Q;return le},at=($,te)=>{const X=i.entities.get($);if(X){for(const Q of t.drawablesOf($))Q.mode===e.TRIANGLES&&te.push(Q);for(const Q of X.children)at(Q,te)}},Mt=new Map,Nt=$=>{const te=new Map,X=[],Q=(he,le,me)=>{const Me=`${he.toFixed(5)},${le.toFixed(5)},${me.toFixed(5)}`;let Ee=te.get(Me);return Ee===void 0&&(Ee=X.length/3,te.set(Me,Ee),X.push(he,le,me)),Ee},ae=new Set;for(let he=0;he+8<$.length;he+=9){const le=Q($[he],$[he+1],$[he+2]),me=Q($[he+3],$[he+4],$[he+5]),Me=Q($[he+6],$[he+7],$[he+8]);for(const[Ee,xe]of[[le,me],[me,Me],[Me,le]])ae.add(Ee<xe?Ee*65536+xe:xe*65536+Ee)}const oe=[];for(const he of ae){const le=Math.floor(he/65536)*3,me=he%65536*3;oe.push(X[le],X[le+1],X[le+2],X[me],X[me+1],X[me+2])}return new ut(e,{position:{size:3,data:Float32Array.from(oe)}})},Et=$=>{var Me,Ee;const te=[];at($,te);const X=Pe($),Q=te.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===Q)return ae.geometry;const oe=Bt(X),he=[];for(const xe of te){const Se=(Ee=(Me=xe.geometry)==null?void 0:Me.attributes)==null?void 0:Ee.position,Ie=Se==null?void 0:Se.data;if(!(Ie instanceof Float32Array)||Se.size!==3||Se.stride)continue;const Le=bt(new Float32Array(16),oe,xe.worldMatrix);for(let Oe=0;Oe+2<Ie.length;Oe+=3){const De=Ie[Oe],Ne=Ie[Oe+1],Be=Ie[Oe+2];he.push(Le[0]*De+Le[4]*Ne+Le[8]*Be+Le[12],Le[1]*De+Le[5]*Ne+Le[9]*Be+Le[13],Le[2]*De+Le[6]*Ne+Le[10]*Be+Le[14])}}const le=he.length>=12?zl(he):null,me=le?Nt(le):null;return Mt.set($,{key:Q,geometry:me}),me},Qt=()=>{var te,X,Q;for(const ae of Te)ae.setParent(null);Te.length=0;const $=(ae,oe)=>{const he=new nt(e,{geometry:ae,program:se,mode:e.LINES});he.frustumCulled=!1,he.matrixAutoUpdate=!1,he.matrix.copy(oe),he.setParent(Ae),Te.push(he)};for(const ae of ce){if(!i.entities.has(ae.entityId))continue;const oe=ae.shape,he=ae.origin,[le,me,Me]=he??[0,0,0];if(oe.kind==="box")$(fe,ke(Pe(ae.entityId),oe.half[0],oe.half[1],oe.half[2],le,me,Me));else if(oe.kind==="sphere")$(we,ke(Pe(ae.entityId),oe.radius,oe.radius,oe.radius,le,me,Me));else if(oe.kind==="cylinder"||oe.kind==="capsule")$(Ge(oe.kind,oe.halfHeight,oe.radius),ke(Pe(ae.entityId),1,1,1,le,me,Me));else if(oe.kind==="mesh"&&oe.convex&&Et(ae.entityId))$(Et(ae.entityId),ke(Pe(ae.entityId),1,1,1,le,me,Me));else if(oe.kind==="mesh"){const Ee=[];at(ae.entityId,Ee);const xe=Pe(ae.entityId),Se=xe[0]*le+xe[4]*me+xe[8]*Me,Ie=xe[1]*le+xe[5]*me+xe[9]*Me,Le=xe[2]*le+xe[6]*me+xe[10]*Me;for(const Oe of Ee){if(!((X=(te=Oe.geometry)==null?void 0:te.attributes)!=null&&X.position))continue;const De=Float32Array.from(Oe.worldMatrix);De[12]+=Se,De[13]+=Ie,De[14]+=Le,$(t.wireGeometryFor(Oe.geometry),De)}}else{const Ee=t.drawablesOf(ae.entityId).find(it=>it.mode===e.TRIANGLES);let xe=.5,Se=.5,Ie=.5,Le=0,Oe=0,De=0;const Ne=(Q=Ee==null?void 0:Ee.geometry)==null?void 0:Q.bounds;Ne&&isFinite(Ne.min.x)&&(xe=(Ne.max.x-Ne.min.x)/2,Se=(Ne.max.y-Ne.min.y)/2,Ie=(Ne.max.z-Ne.min.z)/2,Le=(Ne.max.x+Ne.min.x)/2,Oe=(Ne.max.y+Ne.min.y)/2,De=(Ne.max.z+Ne.min.z)/2);const Be=Pe(ae.entityId),[$e,Ze,Ye]=Fe;$(fe,he?ke(Be,xe*$e,Se*Ze,Ie*Ye,le,me,Me):ke(Be,xe*$e,Se*Ze,Ie*Ye,Le*$e,Oe*Ze,De*Ye))}}return Te.length>0},Ct=new ze(e,{vertex:Rr(!1),fragment:Pr,uniforms:{modelMatrix:{value:qe()},shadowViewProjection:{value:qe()}},depthTest:!1,depthWrite:!1,cullFace:!1}),Ot=new ze(e,{vertex:Rr(!0),fragment:Pr,uniforms:{modelMatrix:{value:qe()},shadowViewProjection:{value:qe()},boneTexture:{value:null},boneTextureSize:{value:4}},depthTest:!1,depthWrite:!1,cullFace:!1});let We=null;const ht=new ze(e,{vertex:mc,fragment:pc,uniforms:{tMask:{value:null},uTexel:{value:[0,0]},uColor:{value:Ds}},depthTest:!1,depthWrite:!1,transparent:!0});ht.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const It=new nt(e,{geometry:new oi(e),program:ht}),Ft=($,te)=>{const X=i.entities.get($);if(!(!X||!X.visible)){te.push(...t.drawablesOf($));for(const Q of X.children)Ft(Q,te)}},Ur=()=>{if(c===null||!i.entities.has(c))return;const $=[];if(Ft(c,$),$.length===0)return;(!We||We.width!==n.width||We.height!==n.height)&&(We=new ii(e,{width:Math.max(1,n.width),height:Math.max(1,n.height)}));const te=bt(new Float32Array(16),s.projectionMatrix,s.viewMatrix);Ct.uniforms.shadowViewProjection.value=te,Ot.uniforms.shadowViewProjection.value=te,r.bindFramebuffer(We),r.setViewport(We.width,We.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);const X=qe();for(const Q of $){const ae=Q instanceof Pt,oe=ae?Ot:Ct;oe.uniforms.modelMatrix.value=ae?X:Q.worldMatrix;const he=Q.program;Q.program=oe,Q.draw({}),Q.program=he}r.bindFramebuffer({buffer:null}),r.setViewport(n.width,n.height),ht.uniforms.tMask.value=We.texture,ht.uniforms.uTexel.value=[1/We.width,1/We.height],It.draw({})},Dr=$=>{a&&(y($),r.render({scene:M,camera:s,clear:!1,frustumCull:!1,sort:!1}))},Zt=()=>{Ur(),ce.length>0&&Qt()&&r.render({scene:Ae,camera:s,clear:!1,frustumCull:!1,sort:!1}),Ue.length>0&&(Z(),r.render({scene:Qe,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 St=new Tn(e,{fov:60,near:.01,far:1e3,aspect:1});return St.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($){ce=Array.isArray($)?$.slice():[]},setGizmos:G,setPreview($){Sr=$&&$.entityId>0?$:null},pickAt($,te){return q($,te)}},setHandlers($){l=$??{}},renderScenePass:Dr,renderOverlayPass:Zt,renderPreviewPass:($,te)=>{const X=Sr;if(!X)return;const Q=n.width/(n.getBoundingClientRect().width||n.width),ae=Math.round(X.rect[0]*Q),oe=Math.round(X.rect[1]*Q),he=Math.round(X.rect[2]*Q),le=Math.round(X.rect[3]*Q);if(he<2||le<2)return;const me=i.worldMatrixF(X.entityId);if(!me)return;for(let xe=0;xe<16;xe++)St.matrix[xe]=me[xe];St.worldMatrixNeedsUpdate=!0,St.perspective({fov:X.fov,aspect:he/le,near:X.near,far:X.far}),St.updateMatrixWorld();const Me=[];for(const xe of X.hide??[])for(const Se of t.drawablesOf(xe))Se.visible&&(Se.visible=!1,Me.push(Se));const Ee=n.height-oe-le;r.bindFramebuffer({buffer:null}),r.setViewport(he,le,ae,Ee),e.enable(e.SCISSOR_TEST),e.scissor(ae,Ee,he,le),e.clearColor(te[0]??0,te[1]??0,te[2]??0,1),r.enable(e.DEPTH_TEST),r.setDepthMask(!0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),t.renderScene($,St,Me.length>0),e.disable(e.SCISSOR_TEST);for(const xe of Me)xe.visible=!0;r.setViewport(n.width,n.height)},dispose:()=>{L==null||L.cleanup(),L=null,n.removeEventListener("pointerdown",k),n.removeEventListener("pointerup",z),n.removeEventListener("pointermove",Y),n.style.cursor=""}}},vc={value:0},pr=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=N=>{const k=p.get(N);if(k!==void 0)return k;let z=null;const Y=t.getShaderSource(N.vertexShader),se=t.getShaderSource(N.fragmentShader);if(Y&&se&&Y.startsWith("#version")){const ee=Y.replace(/^([^\n]*\n)/,`$1#define INSTANCED
885
- `),ne=new ze(t,{vertex:ee,fragment:se,uniforms:N.uniforms,transparent:N.transparent,cullFace:N.cullFace,frontFace:N.frontFace,depthTest:N.depthTest,depthWrite:N.depthWrite,depthFunc:N.depthFunc});let fe=!1;ne.attributeLocations.forEach((we,pe)=>{pe.name==="instanceMatrix"&&(fe=!0)}),fe&&t.getProgramParameter(ne.program,t.LINK_STATUS)?z=ne:ne.remove()}return p.set(N,z),z},v=(N,k)=>{N.transparent=k.transparent,N.cullFace=k.cullFace,N.frontFace=k.frontFace,N.depthTest=k.depthTest,N.depthWrite=k.depthWrite,N.depthFunc=k.depthFunc,N.blendFunc=k.blendFunc,N.blendEquation=k.blendEquation},M=(N,k)=>{const z={};for(const[se,ee]of Object.entries(N.attributes))z[se]={size:ee.size,data:ee.data,type:ee.type,normalized:ee.normalized,stride:ee.stride,offset:ee.offset,buffer:ee.buffer,count:ee.count};z.instanceMatrix={instanced:1,size:16,data:new Float32Array(k*16),usage:t.DYNAMIC_DRAW};const Y=new ut(t,z);return Y.drawRange.start=N.drawRange.start,Y.drawRange.count=N.drawRange.count,Y},d=N=>{for(const z of Object.values(N.VAOs))e.deleteVertexArray(z);N.VAOs={};const k=N.attributes.instanceMatrix;k!=null&&k.buffer&&(t.deleteBuffer(k.buffer),k.buffer=null),e.currentGeometry=null},y=(N,k)=>{const z=N.attributes.instanceMatrix;let Y=Math.max(pr,z.count);for(;Y<k;)Y*=2;const se=new Float32Array(Y*16);return se.set(z.data),d(N),N.instancedCount=0,N.addAttribute("instanceMatrix",{instanced:1,size:16,data:se,usage:t.DYNAMIC_DRAW}),se},x=(N,k,z)=>{const Y=N.attributes.instanceMatrix;z>0&&(t.bindBuffer(t.ARRAY_BUFFER,Y.buffer),e.state.boundBuffer=Y.buffer,t.bufferSubData(t.ARRAY_BUFFER,0,k,0,z*16)),N.setInstancedCount(z)},R=(N,k,z)=>{const Y=N.program,se=N._castShadows!==!1,ee=N._receiveShadows!==!1,ne=`${N.geometry.id}|${Y.id}|${N.mode}|${N.renderOrder}|${se?1:0}${ee?1:0}${z?1:0}`;let fe=r.get(ne);if(!fe){const we=N.geometry;fe={key:ne,source:we,program:Y,twin:k,mode:N.mode,renderOrder:N.renderOrder,castShadows:se,receiveShadows:ee,flip:z,all:new Float32Array(pr*16),allCount:0,allDirty:!0,geoAll:M(we,pr),sph:new Float32Array(pr*4),vis:new Float32Array(pr*16),visCount:0,visDirty:!0,geoVis:M(we,pr),bounds:new Float32Array(6),lastUsed:g},r.set(ne,fe)}return fe},P=N=>{var z,Y;if(!f||N instanceof Pt||N._particles||N.mode===t.POINTS)return null;const k=N.program;return k.transparent||!k.depthTest||!((Y=(z=N.geometry)==null?void 0:z.attributes)!=null&&Y.position)||N.geometry.isInstanced||k.uniforms.uMorphTex?null:u(k)},L=N=>{const k=N.geometry;return(!k.bounds||k.bounds.radius===1/0)&&k.computeBoundingSphere(),k.bounds&&isFinite(k.bounds.radius)?k.bounds:null},_=(N,k,z,Y,se)=>{const ee=N.frustum;for(let ne=0;ne<6;ne++){const fe=ee[ne];if(fe[0]*k+fe[1]*z+fe[2]*Y+fe.constant<-se)return!1}return!0},o=(N,k,z)=>{const Y=k*16;let se=!1;for(let ee=0;ee<16;ee++){const ne=z[ee];N[Y+ee]!==ne&&(N[Y+ee]=ne,se=!0)}return se},h=N=>{const k=N.source;k.bounds||k.computeBoundingBox();const z=N.bounds;if(z[0]=z[1]=z[2]=1/0,z[3]=z[4]=z[5]=-1/0,!k.bounds||!isFinite(k.bounds.min.x))return;const{min:Y,max:se}=k.bounds,ee=[0,0,0];for(let ne=0;ne<N.allCount;ne++){const fe=N.all.subarray(ne*16,ne*16+16);for(let we=0;we<8;we++){Lt(ee,fe,we&1?se.x:Y.x,we&2?se.y:Y.y,we&4?se.z:Y.z,1);for(let pe=0;pe<3;pe++)ee[pe]<z[pe]&&(z[pe]=ee[pe]),ee[pe]>z[pe+3]&&(z[pe+3]=ee[pe])}}},m=[0,0,0],w=N=>{g++,s.length=0,i.length=0;for(const k of r.values())k.allCount=0;N.traverse(k=>{if(!k.visible)return!0;if(!k.draw)return!1;const z=k.worldMatrix,Y=P(k);if(!Y)return s.push(k),k._castShadows!==!1&&i.push(k),!1;const se=!!k.program.cullFace&&wc(z)<0,ee=R(k,Y,se);ee.lastUsed=g;const ne=ee.allCount;if(ne*16>=ee.all.length){ee.all=y(ee.geoAll,ne+1);const pe=new Float32Array(ee.all.length/4);pe.set(ee.sph),ee.sph=pe}o(ee.all,ne,z)&&(ee.allDirty=!0);const fe=L(k),we=ne*4;return fe&&k.frustumCulled?(Lt(m,z,fe.center.x,fe.center.y,fe.center.z,1),ee.sph[we]=m[0],ee.sph[we+1]=m[1],ee.sph[we+2]=m[2],ee.sph[we+3]=fe.radius*xc(z)):ee.sph[we+3]=-1,ee.allCount++,!1});for(const[k,z]of r)z.allCount!==z.geoAll.instancedCount&&(z.allDirty=!0),z.allDirty&&(x(z.geoAll,z.all,z.allCount),h(z),z.allDirty=!1),z.allCount===0&&g-z.lastUsed>yc&&(d(z.geoAll),d(z.geoVis),r.delete(k))},F=(N,k)=>{N.updateFrustum();for(const z of r.values()){z.visCount=0;const Y=z.allCount;for(let se=0;se<Y;se++){const ee=se*4;if(k&&z.sph[ee+3]>=0&&!_(N,z.sph[ee],z.sph[ee+1],z.sph[ee+2],z.sph[ee+3]))continue;const ne=z.visCount;ne*16>=z.vis.length&&(z.vis=y(z.geoVis,ne+1));const fe=se*16,we=ne*16;for(let pe=0;pe<16;pe++){const Ge=z.all[fe+pe];z.vis[we+pe]!==Ge&&(z.vis[we+pe]=Ge,z.visDirty=!0)}z.visCount++}z.visCount!==z.geoVis.instancedCount&&(z.visDirty=!0),z.visDirty&&(x(z.geoVis,z.vis,z.visCount),z.visDirty=!1)}n.length=0;for(const z of s)k&&z.frustumCulled&&!N.frustumIntersectsMesh(z)||n.push(z)},B=(N,k,z,Y=-2,se=!1)=>{const ee=se||Y!==l;ee&&(w(N),l=Y),k.updateMatrixWorld();const ne=k.projectionViewMatrix;let fe=z!==c;for(let we=0;we<16&&!fe;we++)a[we]!==ne[we]&&(fe=!0);if(!(!ee&&!fe)){F(k,z);for(let we=0;we<16;we++)a[we]=ne[we];c=z}},W=()=>[...r.values()].sort((N,k)=>N.renderOrder-k.renderOrder);return{collect:B,drawMain:(N,k)=>{for(const ne of W()){if(ne.visCount===0)continue;const fe=ne.twin.uniforms;(fe.projectionMatrix??(fe.projectionMatrix={value:null})).value=N.projectionMatrix,(fe.viewMatrix??(fe.viewMatrix={value:null})).value=N.viewMatrix,(fe.cameraPosition??(fe.cameraPosition={value:null})).value=N.worldPosition;const we=fe.shadowEnabled;we&&(fe.shadowEnabled=ne.receiveShadows?k:vc),v(ne.twin,ne.program),ne.twin.use({flipFaces:ne.flip}),ne.geoVis.draw({mode:ne.mode,program:ne.twin}),we&&(fe.shadowEnabled=we)}const z=[],Y=[],se=[],ee=N.projectionViewMatrix;for(const ne of n){if(ne.program.transparent?ne.program.depthTest?Y.push(ne):se.push(ne):z.push(ne),ne.zDepth=0,ne.renderOrder!==0||!ne.program.depthTest)continue;const fe=ne.worldMatrix,we=fe[12],pe=fe[13],Ge=fe[14],Qe=ee[3]*we+ee[7]*pe+ee[11]*Ge+ee[15]||1;ne.zDepth=(ee[2]*we+ee[6]*pe+ee[10]*Ge+ee[14])/Qe}z.sort(e.sortOpaque),Y.sort(e.sortTransparent),se.sort(e.sortUI);for(const ne of z)ne.draw({camera:N});for(const ne of Y)ne.draw({camera:N});for(const ne of se)ne.draw({camera:N})},drawShadow:N=>{for(const k of r.values())!k.castShadows||k.allCount===0||(N.use({flipFaces:k.flip}),k.geoAll.draw({mode:k.mode,program:N}))},casterBounds:(N,k)=>{for(const z of r.values())if(!(!z.castShadows||z.allCount===0||!isFinite(z.bounds[0])))for(let Y=0;Y<3;Y++)z.bounds[Y]<N[Y]&&(N[Y]=z.bounds[Y]),z.bounds[Y+3]>k[Y]&&(k[Y]=z.bounds[Y+3])},isBatched:N=>P(N)!==null,dispose:()=>{for(const N of r.values())d(N.geoAll),d(N.geoVis);r.clear();for(const N of p.values())N==null||N.remove();p.clear()},setEnabled:N=>{f=N,l=-1},singles:n,casterSingles:i,stats:()=>{let N=0,k=0,z=0;for(const Y of r.values())Y.allCount>0&&(z++,N+=Y.allCount,k+=Y.visCount);return{batches:z,instances:N,visible:k,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 Ke(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
891
+ `,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 vt;{const te=[];for(let Q=-10;Q<=10;Q++)Q!==0&&te.push(Q,0,-10,Q,0,10,-10,0,Q,10,0,Q);const X=(Q,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 he=new ut(e,{position:{size:3,data:Float32Array.from(Q)}}),le=new nt(e,{geometry:he,program:oe,mode:e.LINES});return le.frustumCulled=!1,le};M.addChild(X(te,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 Q of v)Q.uniforms.uColor.value=[X,X,X]}},x=new ze(e,{vertex:uc,fragment:hc,uniforms:{uColor:{value:[1,1,1]}}}),R=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,B=null;const _=new vt;_.matrixAutoUpdate=!1;const o=($,te,X=x)=>($._axis=te,$.frustumCulled=!1,$.onBeforeRender(()=>{const Q=B?B.axis:P,ae=te===3?sc:nc[te];X.uniforms.uColor.value=Q===te?Us(ae):ae}),$),h=($,te)=>{const X=new vt;return te===0?X.rotation.z=-Math.PI/2:te===2&&(X.rotation.x=Math.PI/2),X.setParent($),X},m=new vt,w=new vt,F=new vt;for(const $ of[m,w,F])$.setParent(_);{const $=new is(e,{radiusTop:.014,radiusBottom:.014,height:.78,radialSegments:6}),te=new is(e,{radiusTop:.001,radiusBottom:.065,height:.26,radialSegments:12}),X=new ss(e,{width:.1,height:.1,depth:.1}),Q=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 he=h(m,oe),le=o(new nt(e,{geometry:$,program:x}),oe);le.position.y=.39;const me=o(new nt(e,{geometry:te,program:x}),oe);me.position.y=.87,he.addChild(le),he.addChild(me);const Me=h(F,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,Me.addChild(Ee),Me.addChild(xe);const Se=o(new nt(e,{geometry:ae,program:R}),oe,R);oe===0?Se.rotation.y=Math.PI/2:oe===1&&(Se.rotation.x=Math.PI/2),w.addChild(Se)}F.addChild(o(new nt(e,{geometry:Q,program:x}),3))}const L=()=>{if(c===null||f===null||!i.entities.has(c))return null;const $=i.activeSceneId(),te=i.scenes.get($);if(!te||te.camera===void 0)return null;const X=i.worldMatrixF(c),Q=[X[12],X[13],X[14]],oe=p==="local"||f==="scale"?[0,1,2].map(Me=>Mr([X[Me*4],X[Me*4+1],X[Me*4+2]])):[[1,0,0],[0,1,0],[0,0,1]],he=i.worldMatrixF(te.camera),le=[he[12],he[13],he[14]],me=vr(et(Q,le))||1;return{origin:Q,axes:oe,scale:me*Zl*i.projectionOf($).fov,camPos:le,sceneId:$}},W=()=>{const $=L();if(!$)return!1;const te=_.matrix;for(let Q=0;Q<3;Q++)te[Q]=$.axes[0][Q]*$.scale,te[4+Q]=$.axes[1][Q]*$.scale,te[8+Q]=$.axes[2][Q]*$.scale,te[12+Q]=$.origin[Q];te[3]=0,te[7]=0,te[11]=0,te[15]=1,_.worldMatrixNeedsUpdate=!0,m.visible=f==="translate",w.visible=f==="rotate",F.visible=f==="scale";const X=R.uniforms;X.uOrigin.value=$.origin,X.uEye.value=$.camPos,X.uFull.value=B&&f==="rotate"?1:0;for(const Q of[m,w,F])Q.traverse(ae=>{ae._axis!==void 0&&(ae.visible=B===null||ae._axis===B.axis)});return!0},O=($,te)=>{const X=L();if(!X)return null;const{origin:Q,dir:ae}=t.getViewRay(X.sceneId,$,te),oe=ec*X.scale;if(f==="rotate"){const me=Mr(et(X.origin,X.camPos));let Me=null,Ee=1/0;for(let xe=0;xe<3;xe++){const Se=mr(Q,ae,X.origin,X.axes[xe]);if(!Se||st(et(Se,X.origin),me)>0)continue;const Ie=Math.abs(vr(et(Se,X.origin))-Os*X.scale),Be=vr(et(Se,Q));Ie<oe&&Be<Ee&&(Me=xe,Ee=Be)}return Me}if(f==="scale"){const{dist:me}=zs(Q,ae,X.origin,Mr(ae),0);if(me<Jl*X.scale)return 3}let he=null,le=oe;for(let me=0;me<3;me++){const{dist:Me}=zs(Q,ae,X.origin,X.axes[me],(Ns+.05)*X.scale);Me<=le&&(le=Me,he=me)}return he},I=$=>{const te=n.getBoundingClientRect(),X=In(n);return[($.clientX-te.left)/X,($.clientY-te.top)/X]},D=($,te)=>{const X=L();if(!X||c===null)return!1;const Q=c,ae=i.ent(Q),oe=Float32Array.from(ae.m),he=ae.parent!==0?i.worldMatrixF(ae.parent):qe(),le=Lt(Float32Array.from(he)),me=bt(new Float32Array(16),he,oe),[Me]=I(te);let Ee=null;if($===3)Ee=Le=>{const[$e]=I(Le),Ze=Math.max(.01,1+($e-Me)/150),Ye=Float32Array.from(oe);for(let it=0;it<3;it++)for(let Xe=0;Xe<3;Xe++)Ye[it*4+Xe]*=Ze;i.methods.setMatrix(Q,Ye)};else if(f==="rotate"){const Le=X.axes[$],{origin:$e,dir:Ze}=t.getViewRay(X.sceneId,...I(te)),Ye=mr($e,Ze,X.origin,Le);if(!Ye)return!1;const it=et(Ye,X.origin);Ee=Xe=>{const yt=t.getViewRay(X.sceneId,...I(Xe)),ft=mr(yt.origin,yt.dir,X.origin,Le);if(!ft)return;const tt=et(ft,X.origin);let rt=Math.atan2(st(Cn(it,tt),Le),st(it,tt));Xe.ctrlKey&&(rt=Math.round(rt/Is)*Is);const je=lc(Le,rt),Je=[0,0,0];Bt(Je,je,X.origin[0],X.origin[1],X.origin[2],1),je[12]=X.origin[0]-Je[0],je[13]=X.origin[1]-Je[1],je[14]=X.origin[2]-Je[2];const zt=bt(new Float32Array(16),je,me),Gt=ae.parent!==0?bt(new Float32Array(16),le,zt):zt;i.methods.setMatrix(Q,Gt)}}else{const Le=X.axes[$],$e=ac(X.origin,Le,X.camPos),{origin:Ze,dir:Ye}=t.getViewRay(X.sceneId,...I(te)),it=mr(Ze,Ye,X.origin,$e);if(!it)return!1;if(f==="translate"){const Xe=[me[12],me[13],me[14]];Ee=yt=>{const ft=t.getViewRay(X.sceneId,...I(yt)),tt=mr(ft.origin,ft.dir,X.origin,$e);if(!tt)return;const rt=st(et(tt,it),Le),je=xr(Xe,wr(Le,rt)),Je=[0,0,0];ae.parent!==0?Bt(Je,le,je[0],je[1],je[2],1):(Je[0]=je[0],Je[1]=je[1],Je[2]=je[2]),i.methods.setPosition(Q,Je[0],Je[1],Je[2])}}else Ee=Xe=>{const yt=t.getViewRay(X.sceneId,...I(Xe)),ft=mr(yt.origin,yt.dir,X.origin,$e);if(!ft)return;const tt=Math.max(.01,1+st(et(ft,it),Le)/(Ns*X.scale)),rt=Float32Array.from(oe);for(let je=0;je<3;je++)rt[$*4+je]*=tt;i.methods.setMatrix(Q,rt)}}if(!Ee)return!1;const xe=n.ownerDocument.defaultView??window,Se=te.pointerId,Ie=Le=>{Le.pointerId===Se&&(B==null||B.onMove(Le))},Be=Le=>{var Ze;if(!B)return;const $e=B;B=null,$e.cleanup(),Le?(Ze=l.onTransformEnd)==null||Ze.call(l,Q,cc(i.ent(Q).m),f):i.methods.setMatrix(Q,$e.startLocal)},Oe=Le=>{Le.pointerId===Se&&Be(!0)},De=()=>Be(!1),Ne=Le=>{Le.code==="Escape"&&Be(!1)};return xe.addEventListener("pointermove",Ie),xe.addEventListener("pointerup",Oe),xe.addEventListener("pointercancel",De),xe.addEventListener("keydown",Ne),B={axis:$,startLocal:oe,onMove:Ee,cleanup:()=>{xe.removeEventListener("pointermove",Ie),xe.removeEventListener("pointerup",Oe),xe.removeEventListener("pointercancel",De),xe.removeEventListener("keydown",Ne)}},!0},K=new Pa,q=($,te)=>{var Ee,xe;const X=i.activeSceneId(),Q=t.sceneRoots.get(X),ae=i.scenes.get(X);if(!Q||!ae||ae.camera===void 0)return 0;const{origin:oe,dir:he}=t.getViewRay(X,$,te);K.origin.set(oe[0],oe[1],oe[2]),K.direction.set(he[0],he[1],he[2]);const le=[],me=[];for(const Se of t.collectMeshes(Q)){const Ie=(xe=(Ee=Se.geometry)==null?void 0:Ee.attributes)==null?void 0:xe.position;if(!(Ie!=null&&Ie.data))continue;const Be=Ie.stride&&Ie.stride!==Ie.size*Ie.data.BYTES_PER_ELEMENT;Se.mode===e.TRIANGLES&&!Be?le.push(Se):me.push(Se)}Q.updateMatrixWorld();let Me=null;try{for(const Se of K.intersectMeshes(le,{cullFace:!1,includeUV:!1,includeNormal:!1,output:[]}))(!Me||Se.hit.distance<Me.hit.distance)&&(Me=Se)}catch{}try{for(const Se of K.intersectBounds(me,{output:[]}))(!Me||Se.hit.distance<Me.hit.distance)&&(Me=Se)}catch{}return(Me==null?void 0:Me._entId)??0};let N=null;const k=$=>{if($.button!==0||$.shiftKey||B)return;const[te,X]=I($),Q=O(te,X);if(Q!==null&&D(Q,$)){$.preventDefault(),$.stopPropagation(),N=null;return}N={pointerId:$.pointerId,x:$.clientX,y:$.clientY}},z=$=>{var ae;const te=N;if(N=null,!te||te.pointerId!==$.pointerId||Math.abs($.clientX-te.x)+Math.abs($.clientY-te.y)>tc)return;const[X,Q]=I($);(ae=l.onPick)==null||ae.call(l,re(X,Q)||q(X,Q))},Y=$=>{if(B)return;const[te,X]=I($),Q=f!==null&&c!==null?O(te,X):null,ae=Q===null&&S.length>0&&re(te,X)||null;(Q!==P||ae!==A)&&(P=Q,A=ae,n.style.cursor=Q!==null||ae!==null?"pointer":"")};n.addEventListener("pointerdown",k),n.addEventListener("pointerup",z),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 ee=$=>new ut(e,{position:{size:3,data:Float32Array.from($)}}),ne=($,te,X,Q,ae=32)=>{for(let oe=0;oe<ae;oe++)for(const he of[Math.PI*2*oe/ae,Math.PI*2*(oe+1)/ae]){const le=Math.cos(he)*te,me=Math.sin(he)*te;Q===1?$.push(le,X,me):Q===0?$.push(X,le,me):$.push(le,me,X)}},fe=ee((()=>{const $=[],te=X=>[X&1?1:-1,X&2?1:-1,X&4?1:-1];for(let X=0;X<8;X++)for(const Q of[1,2,4])X&Q||$.push(...te(X),...te(X|Q));return $})()),we=ee((()=>{const $=[];return ne($,1,0,0),ne($,1,0,1),ne($,1,0,2),$})()),pe=new Map,Ge=($,te,X)=>{const Q=`${$}:${te}:${X}`;let ae=pe.get(Q);if(ae)return ae;const oe=[];ne(oe,X,te,1),ne(oe,X,-te,1);for(const[he,le]of[[X,0],[-X,0],[0,X],[0,-X]])oe.push(he,-te,le,he,te,le);if($==="capsule")for(const le of[!0,!1])for(const me of[0,2])for(let Me=0;Me<12;Me++)for(const Ee of[Math.PI*Me/12,Math.PI*(Me+1)/12]){const xe=Math.cos(Ee)*X,Se=(le?te:-te)+Math.sin(Ee)*X*(le?1:-1);me===0?oe.push(xe,Se,0):oe.push(0,Se,xe)}return ae=ee(oe),pe.size>64&&pe.clear(),pe.set(Q,ae),ae},Qe=new vt,Ue=[],S=[];let A=null;const C=[.81,.83,.87,1],G=$=>{var te,X;for(const Q of Ue)Q.setParent(null),(X=(te=Q.geometry).remove)==null||X.call(te);Ue.length=0,S.length=0,A=null;for(const Q of Array.isArray($)?$:[]){if(!Q||!Array.isArray(Q.segments)||Q.segments.length<6)continue;const[ae,oe,he,le]=Ql.tryParse(Q.color)??C,me=[ae,oe,he],Me=Math.max(0,Math.min(1,Number(Q.alpha??1)*le)),Ee=new ze(e,{vertex:dn,fragment:mn,uniforms:{uColor:{value:me.slice()},uAlpha:{value:Me}},transparent:!0,depthTest:!1,depthWrite:!1});Ee.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const xe=Math.floor(Q.segments.length/6)*6,Se=Float32Array.from(Q.segments.slice(0,xe)),Ie=new ut(e,{position:{size:3,data:Se}}),Be=new nt(e,{geometry:Ie,program:Ee,mode:e.LINES});Be.frustumCulled=!1,Be.setParent(Qe),Ue.push(Be);const Oe=Number(Q.entityId??0);Oe>0&&(Be.matrixAutoUpdate=!1,S.push({entityId:Oe,mesh:Be,program:Ee,color:me,segments:Se}))}},Z=()=>{for(const $ of S){if(!i.entities.has($.entityId)){$.mesh.visible=!1;continue}$.mesh.visible=!0,$.mesh.matrix.copy(Pe($.entityId)),$.mesh.worldMatrixNeedsUpdate=!0;const te=$.entityId===c?Ds:$.entityId===A?Us($.color):$.color,X=$.program.uniforms.uColor.value;X[0]=te[0],X[1]=te[1],X[2]=te[2]}},re=($,te)=>{if(S.length===0)return 0;const X=i.activeSceneId(),Q=i.scenes.get(X);if(!Q||Q.camera===void 0)return 0;const{origin:ae,dir:oe}=t.getViewRay(X,$,te),he=n.getBoundingClientRect(),le=Math.max(1,he.height/In(n)),me=2*Math.tan(i.projectionOf(X).fov*Math.PI/360)*rc/le;let Me=0,Ee=1,xe=1/0;const Se=[0,0,0],Ie=[0,0,0];for(const Be of S){if(!i.entities.has(Be.entityId))continue;const Oe=Pe(Be.entityId),De=Be.segments;for(let Ne=0;Ne+5<De.length;Ne+=6){for(let dt=0;dt<3;dt++)Se[dt]=Oe[dt]*De[Ne]+Oe[4+dt]*De[Ne+1]+Oe[8+dt]*De[Ne+2]+Oe[12+dt],Ie[dt]=Oe[dt]*De[Ne+3]+Oe[4+dt]*De[Ne+4]+Oe[8+dt]*De[Ne+5]+Oe[12+dt];const Le=et(Ie,Se),$e=et(Se,ae),Ze=st(oe,oe),Ye=st(oe,Le),it=st(Le,Le),Xe=st(oe,$e),yt=st(Le,$e),ft=Ze*it-Ye*Ye;let tt=ft>1e-12?(Ye*Xe-Ze*yt)/ft:0;tt=Math.max(0,Math.min(1,tt));const rt=Math.max(0,(Xe+tt*Ye)/(Ze||1)),je=xr(Se,wr(Le,tt)),Je=xr(ae,wr(oe,rt));if(rt<=1e-6)continue;const zt=rt*me,Gt=vr(et(je,Je))/zt;Gt>1||(Gt<Ee-.001||Math.abs(Gt-Ee)<=.001&&rt<xe)&&(Me=Be.entityId,Ee=Gt,xe=rt)}}return Me};let ce=[];const Ae=new vt,Te=[],Fe=[1,1,1],Pe=$=>{const te=Float32Array.from(i.worldMatrix($));for(let X=0;X<3;X++){const Q=Math.hypot(te[X*4],te[X*4+1],te[X*4+2])||1;Fe[X]=Q,te[X*4]/=Q,te[X*4+1]/=Q,te[X*4+2]/=Q}return te},ke=($,te,X,Q,ae=0,oe=0,he=0)=>{const le=Float32Array.from($);le[12]=$[12]+$[0]*ae+$[4]*oe+$[8]*he,le[13]=$[13]+$[1]*ae+$[5]*oe+$[9]*he,le[14]=$[14]+$[2]*ae+$[6]*oe+$[10]*he;for(let me=0;me<3;me++)le[me]*=te,le[4+me]*=X,le[8+me]*=Q;return le},at=($,te)=>{const X=i.entities.get($);if(X){for(const Q of t.drawablesOf($))Q.mode===e.TRIANGLES&&te.push(Q);for(const Q of X.children)at(Q,te)}},Mt=new Map,Nt=$=>{const te=new Map,X=[],Q=(he,le,me)=>{const Me=`${he.toFixed(5)},${le.toFixed(5)},${me.toFixed(5)}`;let Ee=te.get(Me);return Ee===void 0&&(Ee=X.length/3,te.set(Me,Ee),X.push(he,le,me)),Ee},ae=new Set;for(let he=0;he+8<$.length;he+=9){const le=Q($[he],$[he+1],$[he+2]),me=Q($[he+3],$[he+4],$[he+5]),Me=Q($[he+6],$[he+7],$[he+8]);for(const[Ee,xe]of[[le,me],[me,Me],[Me,le]])ae.add(Ee<xe?Ee*65536+xe:xe*65536+Ee)}const oe=[];for(const he of ae){const le=Math.floor(he/65536)*3,me=he%65536*3;oe.push(X[le],X[le+1],X[le+2],X[me],X[me+1],X[me+2])}return new ut(e,{position:{size:3,data:Float32Array.from(oe)}})},Et=$=>{var Me,Ee;const te=[];at($,te);const X=Pe($),Q=te.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===Q)return ae.geometry;const oe=Lt(X),he=[];for(const xe of te){const Se=(Ee=(Me=xe.geometry)==null?void 0:Me.attributes)==null?void 0:Ee.position,Ie=Se==null?void 0:Se.data;if(!(Ie instanceof Float32Array)||Se.size!==3||Se.stride)continue;const Be=bt(new Float32Array(16),oe,xe.worldMatrix);for(let Oe=0;Oe+2<Ie.length;Oe+=3){const De=Ie[Oe],Ne=Ie[Oe+1],Le=Ie[Oe+2];he.push(Be[0]*De+Be[4]*Ne+Be[8]*Le+Be[12],Be[1]*De+Be[5]*Ne+Be[9]*Le+Be[13],Be[2]*De+Be[6]*Ne+Be[10]*Le+Be[14])}}const le=he.length>=12?zl(he):null,me=le?Nt(le):null;return Mt.set($,{key:Q,geometry:me}),me},Qt=()=>{var te,X,Q;for(const ae of Te)ae.setParent(null);Te.length=0;const $=(ae,oe)=>{const he=new nt(e,{geometry:ae,program:se,mode:e.LINES});he.frustumCulled=!1,he.matrixAutoUpdate=!1,he.matrix.copy(oe),he.setParent(Ae),Te.push(he)};for(const ae of ce){if(!i.entities.has(ae.entityId))continue;const oe=ae.shape,he=ae.origin,[le,me,Me]=he??[0,0,0];if(oe.kind==="box")$(fe,ke(Pe(ae.entityId),oe.half[0],oe.half[1],oe.half[2],le,me,Me));else if(oe.kind==="sphere")$(we,ke(Pe(ae.entityId),oe.radius,oe.radius,oe.radius,le,me,Me));else if(oe.kind==="cylinder"||oe.kind==="capsule")$(Ge(oe.kind,oe.halfHeight,oe.radius),ke(Pe(ae.entityId),1,1,1,le,me,Me));else if(oe.kind==="mesh"&&oe.convex&&Et(ae.entityId))$(Et(ae.entityId),ke(Pe(ae.entityId),1,1,1,le,me,Me));else if(oe.kind==="mesh"){const Ee=[];at(ae.entityId,Ee);const xe=Pe(ae.entityId),Se=xe[0]*le+xe[4]*me+xe[8]*Me,Ie=xe[1]*le+xe[5]*me+xe[9]*Me,Be=xe[2]*le+xe[6]*me+xe[10]*Me;for(const Oe of Ee){if(!((X=(te=Oe.geometry)==null?void 0:te.attributes)!=null&&X.position))continue;const De=Float32Array.from(Oe.worldMatrix);De[12]+=Se,De[13]+=Ie,De[14]+=Be,$(t.wireGeometryFor(Oe.geometry),De)}}else{const Ee=t.drawablesOf(ae.entityId).find(it=>it.mode===e.TRIANGLES);let xe=.5,Se=.5,Ie=.5,Be=0,Oe=0,De=0;const Ne=(Q=Ee==null?void 0:Ee.geometry)==null?void 0:Q.bounds;Ne&&isFinite(Ne.min.x)&&(xe=(Ne.max.x-Ne.min.x)/2,Se=(Ne.max.y-Ne.min.y)/2,Ie=(Ne.max.z-Ne.min.z)/2,Be=(Ne.max.x+Ne.min.x)/2,Oe=(Ne.max.y+Ne.min.y)/2,De=(Ne.max.z+Ne.min.z)/2);const Le=Pe(ae.entityId),[$e,Ze,Ye]=Fe;$(fe,he?ke(Le,xe*$e,Se*Ze,Ie*Ye,le,me,Me):ke(Le,xe*$e,Se*Ze,Ie*Ye,Be*$e,Oe*Ze,De*Ye))}}return Te.length>0},Ct=new ze(e,{vertex:Rr(!1),fragment:Pr,uniforms:{modelMatrix:{value:qe()},shadowViewProjection:{value:qe()}},depthTest:!1,depthWrite:!1,cullFace:!1}),Ot=new ze(e,{vertex:Rr(!0),fragment:Pr,uniforms:{modelMatrix:{value:qe()},shadowViewProjection:{value:qe()},boneTexture:{value:null},boneTextureSize:{value:4}},depthTest:!1,depthWrite:!1,cullFace:!1});let We=null;const ht=new ze(e,{vertex:mc,fragment:pc,uniforms:{tMask:{value:null},uTexel:{value:[0,0]},uColor:{value:Ds}},depthTest:!1,depthWrite:!1,transparent:!0});ht.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const It=new nt(e,{geometry:new oi(e),program:ht}),Ft=($,te)=>{const X=i.entities.get($);if(!(!X||!X.visible)){te.push(...t.drawablesOf($));for(const Q of X.children)Ft(Q,te)}},Ur=()=>{if(c===null||!i.entities.has(c))return;const $=[];if(Ft(c,$),$.length===0)return;(!We||We.width!==n.width||We.height!==n.height)&&(We=new ii(e,{width:Math.max(1,n.width),height:Math.max(1,n.height)}));const te=bt(new Float32Array(16),s.projectionMatrix,s.viewMatrix);Ct.uniforms.shadowViewProjection.value=te,Ot.uniforms.shadowViewProjection.value=te,r.bindFramebuffer(We),r.setViewport(We.width,We.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);const X=qe();for(const Q of $){const ae=Q instanceof Pt,oe=ae?Ot:Ct;oe.uniforms.modelMatrix.value=ae?X:Q.worldMatrix;const he=Q.program;Q.program=oe,Q.draw({}),Q.program=he}r.bindFramebuffer({buffer:null}),r.setViewport(n.width,n.height),ht.uniforms.tMask.value=We.texture,ht.uniforms.uTexel.value=[1/We.width,1/We.height],It.draw({})},Dr=$=>{a&&(y($),r.render({scene:M,camera:s,clear:!1,frustumCull:!1,sort:!1}))},Zt=()=>{Ur(),ce.length>0&&Qt()&&r.render({scene:Ae,camera:s,clear:!1,frustumCull:!1,sort:!1}),Ue.length>0&&(Z(),r.render({scene:Qe,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 St=new Tn(e,{fov:60,near:.01,far:1e3,aspect:1});return St.matrixAutoUpdate=!1,{api:{setGrid($){a=$===!0},setSelection($){B&&$!==c&&(B.cleanup(),B=null),c=$&&$>0?$:null},setGizmoMode($){f=$==="translate"||$==="rotate"||$==="scale"?$:null,P=null},setGizmoSpace($){p=$==="local"?"local":"global"},setColliders($){ce=Array.isArray($)?$.slice():[]},setGizmos:G,setPreview($){Sr=$&&$.entityId>0?$:null},pickAt($,te){return q($,te)}},setHandlers($){l=$??{}},renderScenePass:Dr,renderOverlayPass:Zt,renderPreviewPass:($,te)=>{const X=Sr;if(!X)return;const Q=n.width/(n.getBoundingClientRect().width||n.width),ae=Math.round(X.rect[0]*Q),oe=Math.round(X.rect[1]*Q),he=Math.round(X.rect[2]*Q),le=Math.round(X.rect[3]*Q);if(he<2||le<2)return;const me=i.worldMatrixF(X.entityId);if(!me)return;for(let xe=0;xe<16;xe++)St.matrix[xe]=me[xe];St.worldMatrixNeedsUpdate=!0,St.perspective({fov:X.fov,aspect:he/le,near:X.near,far:X.far}),St.updateMatrixWorld();const Me=[];for(const xe of X.hide??[])for(const Se of t.drawablesOf(xe))Se.visible&&(Se.visible=!1,Me.push(Se));const Ee=n.height-oe-le;r.bindFramebuffer({buffer:null}),r.setViewport(he,le,ae,Ee),e.enable(e.SCISSOR_TEST),e.scissor(ae,Ee,he,le),e.clearColor(te[0]??0,te[1]??0,te[2]??0,1),r.enable(e.DEPTH_TEST),r.setDepthMask(!0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),t.renderScene($,St,Me.length>0),e.disable(e.SCISSOR_TEST);for(const xe of Me)xe.visible=!0;r.setViewport(n.width,n.height)},dispose:()=>{B==null||B.cleanup(),B=null,n.removeEventListener("pointerdown",k),n.removeEventListener("pointerup",z),n.removeEventListener("pointermove",Y),n.style.cursor=""}}},vc={value:0},pr=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=N=>{const k=p.get(N);if(k!==void 0)return k;let z=null;const Y=t.getShaderSource(N.vertexShader),se=t.getShaderSource(N.fragmentShader);if(Y&&se&&Y.startsWith("#version")){const ee=Y.replace(/^([^\n]*\n)/,`$1#define INSTANCED
892
+ `),ne=new ze(t,{vertex:ee,fragment:se,uniforms:N.uniforms,transparent:N.transparent,cullFace:N.cullFace,frontFace:N.frontFace,depthTest:N.depthTest,depthWrite:N.depthWrite,depthFunc:N.depthFunc});let fe=!1;ne.attributeLocations.forEach((we,pe)=>{pe.name==="instanceMatrix"&&(fe=!0)}),fe&&t.getProgramParameter(ne.program,t.LINK_STATUS)?z=ne:ne.remove()}return p.set(N,z),z},v=(N,k)=>{N.transparent=k.transparent,N.cullFace=k.cullFace,N.frontFace=k.frontFace,N.depthTest=k.depthTest,N.depthWrite=k.depthWrite,N.depthFunc=k.depthFunc,N.blendFunc=k.blendFunc,N.blendEquation=k.blendEquation},M=(N,k)=>{const z={};for(const[se,ee]of Object.entries(N.attributes))z[se]={size:ee.size,data:ee.data,type:ee.type,normalized:ee.normalized,stride:ee.stride,offset:ee.offset,buffer:ee.buffer,count:ee.count};z.instanceMatrix={instanced:1,size:16,data:new Float32Array(k*16),usage:t.DYNAMIC_DRAW};const Y=new ut(t,z);return Y.drawRange.start=N.drawRange.start,Y.drawRange.count=N.drawRange.count,Y},d=N=>{for(const z of Object.values(N.VAOs))e.deleteVertexArray(z);N.VAOs={};const k=N.attributes.instanceMatrix;k!=null&&k.buffer&&(t.deleteBuffer(k.buffer),k.buffer=null),e.currentGeometry=null},y=(N,k)=>{const z=N.attributes.instanceMatrix;let Y=Math.max(pr,z.count);for(;Y<k;)Y*=2;const se=new Float32Array(Y*16);return se.set(z.data),d(N),N.instancedCount=0,N.addAttribute("instanceMatrix",{instanced:1,size:16,data:se,usage:t.DYNAMIC_DRAW}),se},x=(N,k,z)=>{const Y=N.attributes.instanceMatrix;z>0&&(t.bindBuffer(t.ARRAY_BUFFER,Y.buffer),e.state.boundBuffer=Y.buffer,t.bufferSubData(t.ARRAY_BUFFER,0,k,0,z*16)),N.setInstancedCount(z)},R=(N,k,z)=>{const Y=N.program,se=N._castShadows!==!1,ee=N._receiveShadows!==!1,ne=`${N.geometry.id}|${Y.id}|${N.mode}|${N.renderOrder}|${se?1:0}${ee?1:0}${z?1:0}`;let fe=r.get(ne);if(!fe){const we=N.geometry;fe={key:ne,source:we,program:Y,twin:k,mode:N.mode,renderOrder:N.renderOrder,castShadows:se,receiveShadows:ee,flip:z,all:new Float32Array(pr*16),allCount:0,allDirty:!0,geoAll:M(we,pr),sph:new Float32Array(pr*4),vis:new Float32Array(pr*16),visCount:0,visDirty:!0,geoVis:M(we,pr),bounds:new Float32Array(6),lastUsed:g},r.set(ne,fe)}return fe},P=N=>{var z,Y;if(!f||N instanceof Pt||N._particles||N.mode===t.POINTS)return null;const k=N.program;return k.transparent||!k.depthTest||!((Y=(z=N.geometry)==null?void 0:z.attributes)!=null&&Y.position)||N.geometry.isInstanced||k.uniforms.uMorphTex?null:u(k)},B=N=>{const k=N.geometry;return(!k.bounds||k.bounds.radius===1/0)&&k.computeBoundingSphere(),k.bounds&&isFinite(k.bounds.radius)?k.bounds:null},_=(N,k,z,Y,se)=>{const ee=N.frustum;for(let ne=0;ne<6;ne++){const fe=ee[ne];if(fe[0]*k+fe[1]*z+fe[2]*Y+fe.constant<-se)return!1}return!0},o=(N,k,z)=>{const Y=k*16;let se=!1;for(let ee=0;ee<16;ee++){const ne=z[ee];N[Y+ee]!==ne&&(N[Y+ee]=ne,se=!0)}return se},h=N=>{const k=N.source;k.bounds||k.computeBoundingBox();const z=N.bounds;if(z[0]=z[1]=z[2]=1/0,z[3]=z[4]=z[5]=-1/0,!k.bounds||!isFinite(k.bounds.min.x))return;const{min:Y,max:se}=k.bounds,ee=[0,0,0];for(let ne=0;ne<N.allCount;ne++){const fe=N.all.subarray(ne*16,ne*16+16);for(let we=0;we<8;we++){Bt(ee,fe,we&1?se.x:Y.x,we&2?se.y:Y.y,we&4?se.z:Y.z,1);for(let pe=0;pe<3;pe++)ee[pe]<z[pe]&&(z[pe]=ee[pe]),ee[pe]>z[pe+3]&&(z[pe+3]=ee[pe])}}},m=[0,0,0],w=N=>{g++,s.length=0,i.length=0;for(const k of r.values())k.allCount=0;N.traverse(k=>{if(!k.visible)return!0;if(!k.draw)return!1;const z=k.worldMatrix,Y=P(k);if(!Y)return s.push(k),k._castShadows!==!1&&i.push(k),!1;const se=!!k.program.cullFace&&wc(z)<0,ee=R(k,Y,se);ee.lastUsed=g;const ne=ee.allCount;if(ne*16>=ee.all.length){ee.all=y(ee.geoAll,ne+1);const pe=new Float32Array(ee.all.length/4);pe.set(ee.sph),ee.sph=pe}o(ee.all,ne,z)&&(ee.allDirty=!0);const fe=B(k),we=ne*4;return fe&&k.frustumCulled?(Bt(m,z,fe.center.x,fe.center.y,fe.center.z,1),ee.sph[we]=m[0],ee.sph[we+1]=m[1],ee.sph[we+2]=m[2],ee.sph[we+3]=fe.radius*xc(z)):ee.sph[we+3]=-1,ee.allCount++,!1});for(const[k,z]of r)z.allCount!==z.geoAll.instancedCount&&(z.allDirty=!0),z.allDirty&&(x(z.geoAll,z.all,z.allCount),h(z),z.allDirty=!1),z.allCount===0&&g-z.lastUsed>yc&&(d(z.geoAll),d(z.geoVis),r.delete(k))},F=(N,k)=>{N.updateFrustum();for(const z of r.values()){z.visCount=0;const Y=z.allCount;for(let se=0;se<Y;se++){const ee=se*4;if(k&&z.sph[ee+3]>=0&&!_(N,z.sph[ee],z.sph[ee+1],z.sph[ee+2],z.sph[ee+3]))continue;const ne=z.visCount;ne*16>=z.vis.length&&(z.vis=y(z.geoVis,ne+1));const fe=se*16,we=ne*16;for(let pe=0;pe<16;pe++){const Ge=z.all[fe+pe];z.vis[we+pe]!==Ge&&(z.vis[we+pe]=Ge,z.visDirty=!0)}z.visCount++}z.visCount!==z.geoVis.instancedCount&&(z.visDirty=!0),z.visDirty&&(x(z.geoVis,z.vis,z.visCount),z.visDirty=!1)}n.length=0;for(const z of s)k&&z.frustumCulled&&!N.frustumIntersectsMesh(z)||n.push(z)},L=(N,k,z,Y=-2,se=!1)=>{const ee=se||Y!==l;ee&&(w(N),l=Y),k.updateMatrixWorld();const ne=k.projectionViewMatrix;let fe=z!==c;for(let we=0;we<16&&!fe;we++)a[we]!==ne[we]&&(fe=!0);if(!(!ee&&!fe)){F(k,z);for(let we=0;we<16;we++)a[we]=ne[we];c=z}},W=()=>[...r.values()].sort((N,k)=>N.renderOrder-k.renderOrder);return{collect:L,drawMain:(N,k)=>{for(const ne of W()){if(ne.visCount===0)continue;const fe=ne.twin.uniforms;(fe.projectionMatrix??(fe.projectionMatrix={value:null})).value=N.projectionMatrix,(fe.viewMatrix??(fe.viewMatrix={value:null})).value=N.viewMatrix,(fe.cameraPosition??(fe.cameraPosition={value:null})).value=N.worldPosition;const we=fe.shadowEnabled;we&&(fe.shadowEnabled=ne.receiveShadows?k:vc),v(ne.twin,ne.program),ne.twin.use({flipFaces:ne.flip}),ne.geoVis.draw({mode:ne.mode,program:ne.twin}),we&&(fe.shadowEnabled=we)}const z=[],Y=[],se=[],ee=N.projectionViewMatrix;for(const ne of n){if(ne.program.transparent?ne.program.depthTest?Y.push(ne):se.push(ne):z.push(ne),ne.zDepth=0,ne.renderOrder!==0||!ne.program.depthTest)continue;const fe=ne.worldMatrix,we=fe[12],pe=fe[13],Ge=fe[14],Qe=ee[3]*we+ee[7]*pe+ee[11]*Ge+ee[15]||1;ne.zDepth=(ee[2]*we+ee[6]*pe+ee[10]*Ge+ee[14])/Qe}z.sort(e.sortOpaque),Y.sort(e.sortTransparent),se.sort(e.sortUI);for(const ne of z)ne.draw({camera:N});for(const ne of Y)ne.draw({camera:N});for(const ne of se)ne.draw({camera:N})},drawShadow:N=>{for(const k of r.values())!k.castShadows||k.allCount===0||(N.use({flipFaces:k.flip}),k.geoAll.draw({mode:k.mode,program:N}))},casterBounds:(N,k)=>{for(const z of r.values())if(!(!z.castShadows||z.allCount===0||!isFinite(z.bounds[0])))for(let Y=0;Y<3;Y++)z.bounds[Y]<N[Y]&&(N[Y]=z.bounds[Y]),z.bounds[Y+3]>k[Y]&&(k[Y]=z.bounds[Y+3])},isBatched:N=>P(N)!==null,dispose:()=>{for(const N of r.values())d(N.geoAll),d(N.geoVis);r.clear();for(const N of p.values())N==null||N.remove();p.clear()},setEnabled:N=>{f=N,l=-1},singles:n,casterSingles:i,stats:()=>{let N=0,k=0,z=0;for(const Y of r.values())Y.allCount>0&&(z++,N+=Y.allCount,k+=Y.visCount);return{batches:z,instances:N,visible:k,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},Lr=(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 Ke(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
893
  out vec2 vUv;
887
894
  void main() {
888
895
  // one triangle over the target: (0,0) (2,0) (0,2) in uv
@@ -906,7 +913,7 @@ void main() {
906
913
  + texture(uCamera, uv + vec2(-uStep.x, uStep.y)).rgb + texture(uCamera, uv + vec2(uStep.x, uStep.y)).rgb;
907
914
  float y = dot(c * 0.25, vec3(0.299, 0.587, 0.114));
908
915
  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 ee=e.createShader(Y);return e.shaderSource(ee,se),e.compileShader(ee),ee},q=K(e.VERTEX_SHADER,_c),N=K(e.FRAGMENT_SHADER,I),k=e.createProgram();if(e.attachShader(k,q),e.attachShader(k,N),e.linkProgram(k),e.deleteShader(q),e.deleteShader(N),!e.getProgramParameter(k,e.LINK_STATUS)){const Y=e.getProgramInfoLog(k);throw e.deleteProgram(k),new Error(`the camera's blit did not link: ${Y}`)}const z=e.createSampler();return e.samplerParameteri(z,e.TEXTURE_MIN_FILTER,D),e.samplerParameteri(z,e.TEXTURE_MAG_FILTER,D),e.samplerParameteri(z,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.samplerParameteri(z,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),{program:k,sampler:z,location:e.getUniformLocation(k,"uCamera"),step:e.getUniformLocation(k,"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)},R=()=>{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 N=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:N,scratch:N?null:new Uint8Array(I*D*4)},a},_=(I,D,K,q)=>{const N=Math.max(1,Math.round(K*q/D)),k=y(),z=L(q,N);e.useProgram(k.program);const Y=D/q>=1.5;return e.uniform2f(k.step,Y?.25/q:0,Y?.25/N:0),x(k,I),z},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 N=I.scratch;e.readPixels(0,0,D,K,e.RGBA,e.UNSIGNED_BYTE,N);for(let k=0,z=D*K;k<z;k++)q[k]=N[k*4]}return q},h=I=>{const D=c.find(N=>!N.busy&&N.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,N=h(q?D*K:D*K*4);if(g||e.getError(),e.bindBuffer(e.PIXEL_PACK_BUFFER,N.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 z=e.getError();if(z!==e.NO_ERROR)throw new Error(`readPixels into a pack buffer gave GL error 0x${z.toString(16)}`);g=!0}const k=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);if(!k)throw new Error("no fence was made");return e.flush(),N.busy=!0,{pack:N,sync:k}},F=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 N=0,k=D*K;N<k;N++)q[N]=f[N*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(),N=e.createTexture();e.bindTexture(e.TEXTURE_2D,N),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8,D,K);const k=e.createFramebuffer();Br(e,r,{buffer:k,x:0,y:0,width:D,height:K}),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,N,0),x(q,I);const z=new Uint8Array(D*K*4);e.readPixels(0,0,D,K,e.RGBA,e.UNSIGNED_BYTE,z),R(),e.deleteFramebuffer(k),e.deleteTexture(N);const Y=D*4,se=new Uint8Array(z.length);for(let ee=0;ee<K;ee++)se.set(z.subarray((K-1-ee)*Y,(K-ee)*Y),ee*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 S=new XRWebGLLayer(I,e,{alpha:!0,antialias:!1});I.updateRenderState({baseLayer:S,depthNear:t.near,depthFar:t.far})}finally{s=!1}let N=0,k=null,z=[],Y=[],se=0;const ee=(S,A,C,G)=>{const Z=new Float32Array(G.projectionMatrix),re=new Float32Array(G.transform.matrix);try{const ce=_(S,A.width,A.height,C);if(p)try{const{pack:Ae,sync:Te}=w(ce),Fe={pack:Ae,sync:Te,width:ce.width,height:ce.height,red:ce.red,projection:Z,viewMatrix:re,frames:0,takers:[]};return Y.push(Fe),Fe}catch(Ae){e.bindBuffer(e.PIXEL_PACK_BUFFER,null),B(`the camera's picture cannot be read without a stall (${Ae instanceof Error?Ae.message:Ae})`)}return{data:o(ce),width:ce.width,height:ce.height,projection:Z,viewMatrix:re}}finally{R()}},ne=(S,A)=>{S.pack.busy=!1,S.takers.forEach((C,G)=>C(A&&G>0?Vs(A):A))},fe=()=>{if(Y.length===0)return;const S=Y;Y=[];for(const A of S){let C=!1;try{C=e.getSyncParameter(A.sync,e.SYNC_STATUS)===e.SIGNALED}catch{}if(!C&&++A.frames<Gs){Y.push(A);continue}C||B(`a camera read's fence did not signal in ${Gs} frames`),e.deleteSync(A.sync);let G=null;try{G={data:F(A),width:A.width,height:A.height,projection:A.projection,viewMatrix:A.viewMatrix}}catch(Z){t.failed("the XR camera image",Z),B(`a camera read could not be taken back (${Z instanceof Error?Z.message:Z})`)}ne(A,G)}},we=S=>{var Ae;if(z.length===0)return;const A=z;z=[];let C=null;const G=S?S.camera:void 0;if(S&&!G&&v("camera-access",'the XR session has no camera access (the "camera-access" feature was not granted): no camera picture'),S&&G)try{k??(k=new XRWebGLBinding(I,e)),C=((Ae=k.getCameraImage)==null?void 0:Ae.call(k,G))??null,C||v("camera-image","the XR session gave no camera image")}catch(Te){t.failed("the XR camera image",Te)}let Z;const re=new Map,ce=new Set;for(const Te of A){if(!C||!S||!G){Te.resolve(null);continue}try{if(Te.gray){const Fe=Math.max(1,Math.min(G.width,Math.floor(Te.maxWidth)));let Pe=re.get(Fe);if(Pe||(Pe=ee(C,G,Fe,S),re.set(Fe,Pe)),"takers"in Pe)Pe.takers.push(Te.resolve);else{const ke=!ce.has(Pe);ce.add(Pe),Te.resolve(ke?Pe:Vs(Pe))}}else{Z??(Z=W(C,G.width,G.height));const Fe=!ce.has(Z);ce.add(Z),Te.resolve(Fe?Z:{...Z,rgba:Z.rgba.slice()})}}catch(Fe){t.failed("the XR camera image",Fe),Te.resolve(null)}}},pe=(S,A)=>{var Te;if(n!==Ue)return;N=I.requestAnimationFrame(pe),fe(),t.begin();let C=null;try{C=A.getViewerPose(D)??null}catch(Fe){t.failed("the XR viewer pose",Fe)}const G=(C==null?void 0:C.views[0])??null;C&&C.views.length>1&&C.views.length!==se&&(se=C.views.length,v("views",`an XR session of ${se} views: the lite engine draws the first (a phone's)`));const Z=I.renderState,re=G!==null&&t.view(q,G.transform.matrix,G.projectionMatrix,Z.depthNear??t.near,Z.depthFar??t.far);try{K(S,A,C)}catch(Fe){t.failed("the XR frame body",Fe)}we(G);const ce=re&&G?(Te=Z.baseLayer)==null?void 0:Te.getViewport(G):void 0,Ae=Z.baseLayer;t.draw(ce&&Ae?{buffer:Ae.framebuffer,x:ce.x,y:ce.y,width:ce.width,height:ce.height}:null)},Ge=()=>{if(n!==Ue)return;n=null,I.removeEventListener("end",Ge);try{I.cancelAnimationFrame(N)}catch{}k=null;const S=z;z=[];for(const C of S)C.resolve(null);const A=Y;Y=[];for(const C of A){try{e.deleteSync(C.sync)}catch{}ne(C,null)}P(),m(),t.presenting(!1)};function Qe(S){return n!==Ue?Promise.resolve(null):new Promise(A=>{z.push(S!=null&&S.gray?{gray:!0,maxWidth:S.maxWidth??1/0,resolve:A}:{gray:!1,resolve:A})})}const Ue={session:I,end:Ge,captureCamera:Qe};return n=Ue,I.addEventListener("end",Ge),t.presenting(!0),N=I.requestAnimationFrame(pe),Ue},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
916
+ }`,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 ee=e.createShader(Y);return e.shaderSource(ee,se),e.compileShader(ee),ee},q=K(e.VERTEX_SHADER,_c),N=K(e.FRAGMENT_SHADER,I),k=e.createProgram();if(e.attachShader(k,q),e.attachShader(k,N),e.linkProgram(k),e.deleteShader(q),e.deleteShader(N),!e.getProgramParameter(k,e.LINK_STATUS)){const Y=e.getProgramInfoLog(k);throw e.deleteProgram(k),new Error(`the camera's blit did not link: ${Y}`)}const z=e.createSampler();return e.samplerParameteri(z,e.TEXTURE_MIN_FILTER,D),e.samplerParameteri(z,e.TEXTURE_MAG_FILTER,D),e.samplerParameteri(z,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.samplerParameteri(z,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),{program:k,sampler:z,location:e.getUniformLocation(k,"uCamera"),step:e.getUniformLocation(k,"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)},R=()=>{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)},B=(I,D)=>{if(a&&a.width===I&&a.height===D)return Lr(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();Lr(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 N=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:N,scratch:N?null:new Uint8Array(I*D*4)},a},_=(I,D,K,q)=>{const N=Math.max(1,Math.round(K*q/D)),k=y(),z=B(q,N);e.useProgram(k.program);const Y=D/q>=1.5;return e.uniform2f(k.step,Y?.25/q:0,Y?.25/N:0),x(k,I),z},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 N=I.scratch;e.readPixels(0,0,D,K,e.RGBA,e.UNSIGNED_BYTE,N);for(let k=0,z=D*K;k<z;k++)q[k]=N[k*4]}return q},h=I=>{const D=c.find(N=>!N.busy&&N.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,N=h(q?D*K:D*K*4);if(g||e.getError(),e.bindBuffer(e.PIXEL_PACK_BUFFER,N.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 z=e.getError();if(z!==e.NO_ERROR)throw new Error(`readPixels into a pack buffer gave GL error 0x${z.toString(16)}`);g=!0}const k=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);if(!k)throw new Error("no fence was made");return e.flush(),N.busy=!0,{pack:N,sync:k}},F=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 N=0,k=D*K;N<k;N++)q[N]=f[N*4]}}finally{e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}return q},L=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(),N=e.createTexture();e.bindTexture(e.TEXTURE_2D,N),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8,D,K);const k=e.createFramebuffer();Lr(e,r,{buffer:k,x:0,y:0,width:D,height:K}),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,N,0),x(q,I);const z=new Uint8Array(D*K*4);e.readPixels(0,0,D,K,e.RGBA,e.UNSIGNED_BYTE,z),R(),e.deleteFramebuffer(k),e.deleteTexture(N);const Y=D*4,se=new Uint8Array(z.length);for(let ee=0;ee<K;ee++)se.set(z.subarray((K-1-ee)*Y,(K-ee)*Y),ee*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 S=new XRWebGLLayer(I,e,{alpha:!0,antialias:!1});I.updateRenderState({baseLayer:S,depthNear:t.near,depthFar:t.far})}finally{s=!1}let N=0,k=null,z=[],Y=[],se=0;const ee=(S,A,C,G)=>{const Z=new Float32Array(G.projectionMatrix),re=new Float32Array(G.transform.matrix);try{const ce=_(S,A.width,A.height,C);if(p)try{const{pack:Ae,sync:Te}=w(ce),Fe={pack:Ae,sync:Te,width:ce.width,height:ce.height,red:ce.red,projection:Z,viewMatrix:re,frames:0,takers:[]};return Y.push(Fe),Fe}catch(Ae){e.bindBuffer(e.PIXEL_PACK_BUFFER,null),L(`the camera's picture cannot be read without a stall (${Ae instanceof Error?Ae.message:Ae})`)}return{data:o(ce),width:ce.width,height:ce.height,projection:Z,viewMatrix:re}}finally{R()}},ne=(S,A)=>{S.pack.busy=!1,S.takers.forEach((C,G)=>C(A&&G>0?Vs(A):A))},fe=()=>{if(Y.length===0)return;const S=Y;Y=[];for(const A of S){let C=!1;try{C=e.getSyncParameter(A.sync,e.SYNC_STATUS)===e.SIGNALED}catch{}if(!C&&++A.frames<Gs){Y.push(A);continue}C||L(`a camera read's fence did not signal in ${Gs} frames`),e.deleteSync(A.sync);let G=null;try{G={data:F(A),width:A.width,height:A.height,projection:A.projection,viewMatrix:A.viewMatrix}}catch(Z){t.failed("the XR camera image",Z),L(`a camera read could not be taken back (${Z instanceof Error?Z.message:Z})`)}ne(A,G)}},we=S=>{var Ae;if(z.length===0)return;const A=z;z=[];let C=null;const G=S?S.camera:void 0;if(S&&!G&&v("camera-access",'the XR session has no camera access (the "camera-access" feature was not granted): no camera picture'),S&&G)try{k??(k=new XRWebGLBinding(I,e)),C=((Ae=k.getCameraImage)==null?void 0:Ae.call(k,G))??null,C||v("camera-image","the XR session gave no camera image")}catch(Te){t.failed("the XR camera image",Te)}let Z;const re=new Map,ce=new Set;for(const Te of A){if(!C||!S||!G){Te.resolve(null);continue}try{if(Te.gray){const Fe=Math.max(1,Math.min(G.width,Math.floor(Te.maxWidth)));let Pe=re.get(Fe);if(Pe||(Pe=ee(C,G,Fe,S),re.set(Fe,Pe)),"takers"in Pe)Pe.takers.push(Te.resolve);else{const ke=!ce.has(Pe);ce.add(Pe),Te.resolve(ke?Pe:Vs(Pe))}}else{Z??(Z=W(C,G.width,G.height));const Fe=!ce.has(Z);ce.add(Z),Te.resolve(Fe?Z:{...Z,rgba:Z.rgba.slice()})}}catch(Fe){t.failed("the XR camera image",Fe),Te.resolve(null)}}},pe=(S,A)=>{var Te;if(n!==Ue)return;N=I.requestAnimationFrame(pe),fe(),t.begin();let C=null;try{C=A.getViewerPose(D)??null}catch(Fe){t.failed("the XR viewer pose",Fe)}const G=(C==null?void 0:C.views[0])??null;C&&C.views.length>1&&C.views.length!==se&&(se=C.views.length,v("views",`an XR session of ${se} views: the lite engine draws the first (a phone's)`));const Z=I.renderState,re=G!==null&&t.view(q,G.transform.matrix,G.projectionMatrix,Z.depthNear??t.near,Z.depthFar??t.far);try{K(S,A,C)}catch(Fe){t.failed("the XR frame body",Fe)}we(G);const ce=re&&G?(Te=Z.baseLayer)==null?void 0:Te.getViewport(G):void 0,Ae=Z.baseLayer;t.draw(ce&&Ae?{buffer:Ae.framebuffer,x:ce.x,y:ce.y,width:ce.width,height:ce.height}:null)},Ge=()=>{if(n!==Ue)return;n=null,I.removeEventListener("end",Ge);try{I.cancelAnimationFrame(N)}catch{}k=null;const S=z;z=[];for(const C of S)C.resolve(null);const A=Y;Y=[];for(const C of A){try{e.deleteSync(C.sync)}catch{}ne(C,null)}P(),m(),t.presenting(!1)};function Qe(S){return n!==Ue?Promise.resolve(null):new Promise(A=>{z.push(S!=null&&S.gray?{gray:!0,maxWidth:S.maxWidth??1/0,resolve:A}:{gray:!1,resolve:A})})}const Ue={session:I,end:Ge,captureCamera:Qe};return n=Ue,I.addEventListener("end",Ge),t.presenting(!0),N=I.requestAnimationFrame(pe),Ue},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)}),Bc=`#version 300 es
910
917
  in vec2 position;
911
918
  in vec2 uv;
912
919
  out vec2 vUv;
@@ -920,7 +927,7 @@ precision highp sampler2D;
920
927
  in vec2 vUv;
921
928
  uniform sampler2D source;
922
929
  out vec4 fragColor;
923
- `,Bc=`${Yr}
930
+ `,Lc=`${Yr}
924
931
  uniform float uThreshold;
925
932
  uniform float uFireflies;
926
933
  uniform float uInvHighlight;
@@ -1101,5 +1108,5 @@ void main() {
1101
1108
  vec3 hdr = color.rgb + textureLod(uBloom, vUv, 0.0).rgb * uBloomStrength;
1102
1109
  fragColor = vec4(acesFilmicSrgb(hdr), color.a);
1103
1110
  }
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 F=m.threshold;const B=Number.isFinite(m.highlight)&&m.highlight>0?1/m.highlight:0;let W=_;const O=D=>{const K=s.uniforms;K.source.value=W,K.uThreshold.value=K.uFireflies.value=F?1:0,K.uInvHighlight.value=B,x(s,D),F=!1,W=D.texture};for(const D of g)O(D);O(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=qe();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,R;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||!R)x=[L.min[0],L.min[1],L.min[2]],R=[L.max[0],L.max[1],L.max[2]];else for(let _=0;_<3;_++)x[_]=Math.min(x[_],L.min[_]),R[_]=Math.max(R[_],L.max[_])}M.mesh={primitives:y.length,min:x,max:R}}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 R=(y=(d=l[x.input])==null?void 0:d.max)==null?void 0:y[0];typeof R=="number"&&R>M&&(M=R)}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,wt=(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)}},gt=(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,R=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]=(R+L)*f,h[7]=0,h[8]=(y+_)*p,h[9]=(R-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,R=f+v+x;let P,L,_,o;if(R>0){const h=.5/Math.sqrt(R+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),gr=19,_t={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)},R={loadClips(o,h,m){const w=t.getBuffer(o),F=w?y(w):0;if(!F){m(new Error("loadClips: not a GLB with animations"));return}h(F)},createClipFromTracks(o,h){return gt(e,o,m=>wt(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 F=e._canimClipName(o,w);m.push({name:F?e.UTF8ToString(F):"",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,F){return e._canimClipsDerive(o,h,m?1:0,w,F)},destroyClipSet(o){e._canimClipsDestroy(o)},animatorCreate(o){if(!t.get(o))return 0;const m=[],w=[],F=[],B=[],W=[],O=(k,z)=>{const Y=t.get(k);if(!Y)return;const se=m.length;m.push(k),w.push(z),F.push(Y.name??""),W.push(Y.skinJoint?1:0);const{t:ee,r:ne,s:fe}=Wr(Y.m);B.push(ee[0],ee[1],ee[2],ne[0],ne[1],ne[2],ne[3],fe[0],fe[1],fe[2]);for(const we of Y.children)O(we,se)};O(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=gt(e,F.join(`
1105
- `),k=>wt(e,B,z=>e._canimAnimatorCreate(I,D,k,z,K,o)))}finally{e._free(D),e._free(K)}if(!q)return 0;const N=e._canimAnimatorShadowedNames(q);return N>0&&console.warn(`[Animator] ${N} 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,F=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 O=F+B*10;pn(W.m,m[O],m[O+1],m[O+2],m[O+3],m[O+4],m[O+5],m[O+6],m[O+7],m[O+8],m[O+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){wt(e,m,w=>e._canimClipsSetEvents(o,h,w,m.length))},animatorSetBlend(o,h,m,w,F,B,W,O){const I=m>1?2:1,D=Math.min(w.length,Math.floor(F.length/I)),K=O&&O.length>=D*2?O:null;kc(e,w,q=>wt(e,F,N=>{K?wt(e,K,k=>e._canimAnimatorSetBlend(o,h,I,q,N,k,D,B,W)):e._canimAnimatorSetBlend(o,h,I,q,N,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,F,B,W){e._canimAnimatorPlay(o,h,m?1:0,w,F,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,F){gt(e,F??"",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,F]of r){if(!F.entities.includes(o))continue;const B=h.length>>1,W=new Int32Array(B*2);for(let q=0;q<B*2;q++)W[q]=F.entities.indexOf(h[q]);const O=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=wt(e,m,q=>e._canimAnimatorJointRanges(w,I,B,q,D)),K>0&&O.set(e.HEAPF32.subarray(D>>2,(D>>2)+B*6))}finally{e._free(I),e._free(D)}return K>0?O:null}return null},animatorSeedPose(o,h){for(const[m,w]of r){if(!w.entities.includes(o))continue;const F=new Float32Array(w.n*10);for(let B=0;B<w.n;B++){const W=t.get(w.entities[B]),{t:O,r:I,s:D}=Wr(W?W.m:Er);F.set([O[0],O[1],O[2],I[0],I[1],I[2],I[3],D[0],D[1],D[2]],B*10)}wt(e,F,B=>e._canimAnimatorSeedPose(m,B,h));return}},animatorSetRootMotion(o,h,m){gt(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){gt(e,h,w=>gt(e,m,F=>e._canimAnimatorSetFeet(o,w,F)))},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 F=e._malloc(w*8*4),B=e._canimAnimatorSlotContacts(o,h,F,w);return m.set(e.HEAPF32.subarray(F>>2,(F>>2)+Math.min(B,w)*8)),e._free(F),B},animatorSlotTreads(o,h,m){if(m.length===0)return e._canimAnimatorSlotTreads(o,h,0,0);const w=e._malloc(m.length*4),F=e._canimAnimatorSlotTreads(o,h,w,m.length);return m.set(e.HEAPF32.subarray(w>>2,(w>>2)+Math.min(F+1,m.length))),e._free(w),F},animatorSlotPhysics(o,h,m,w){const F=e._malloc(44),B=e._canimAnimatorSlotPhysics(o,h,m,F);return B&&w.set(e.HEAPF32.subarray(F>>2,(F>>2)+Math.min(11,w.length))),e._free(F),B},animatorSlotFeatures(o,h,m,w){const F=e._malloc(148),B=e._canimAnimatorSlotFeatures(o,h,m,F);return B&&w.set(e.HEAPF32.subarray(F>>2,(F>>2)+Math.min(37,w.length))),e._free(F),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,F){const B=e._canimAnimatorSlotKneePole(o,h,m,w,f);return B&&F.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(6,F.length))),B},animatorSetStepWarp(o,h,m,w,F,B){e._canimAnimatorSetStepWarp(o,h?1:0,m,w,F,B)},animatorSlotFit(o,h,m,w,F){if(F.length===0)return e._canimAnimatorSlotFit(o,h,m,w,0,0);const B=e._malloc(F.length*4),W=e._canimAnimatorSlotFit(o,h,m,w,B,F.length);return F.set(e.HEAPF32.subarray(B>>2,(B>>2)+Math.min(W,F.length))),e._free(B),W},animatorSlotExit(o,h,m,w,F,B){return e._canimAnimatorSlotExit(o,h,m,w,F?1:0,B)},animatorSlotAlign(o,h,m,w,F,B){if(B.length<4)return 0;const W=e._malloc(16),O=e._canimAnimatorSlotAlign(o,h,m,w,F,W);return O&&B.set(e.HEAPF32.subarray(W>>2,(W>>2)+4)),e._free(W),O},setOnAnimatorStep(o){d=o},animatorSetFeetParams(o,h){wt(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 F=w.entities.indexOf(m);if(F<0)return 0;let B=-1,W=-1;if(h===0){const N=((K=t.get(m))==null?void 0:K.parent)??0;if(B=w.entities.indexOf(N),B<0||(W=w.entities.indexOf(((q=t.get(N))==null?void 0:q.parent)??0),W<0))return 0}const O=e._canimAnimatorIkCreateJoints(o,h,W,B,F);if(!O)return 0;const I=new Float32Array(gr),D=e._malloc(gr*4);return e._canimAnimatorIkGet(o,O,D,gr),I.set(e.HEAPF32.subarray(D>>2,(D>>2)+gr)),e._free(D),w.iks.push({ik:O,target:0,pole:0,rotation:0,params:I}),O},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 F;wt(e,m,B=>e._canimAnimatorIkSet(o,h,B,m.length));const w=(F=r.get(o))==null?void 0:F.iks.find(B=>B.ik===h);w&&w.params.set(m.subarray(0,Math.min(m.length,gr)))},animatorIkNodes(o,h,m,w,F){var W;const B=(W=r.get(o))==null?void 0:W.iks.find(O=>O.ik===h);B&&(B.target=m,B.pole=w,B.rotation=F)},animatorIkAnchor(o,h,m){gt(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,F,B){const W=r.get(o);if(!W||!gn(e))return;W.sockets=W.sockets.filter(D=>!(D.set===h&&D.name===m));const O=(D,K)=>{gt(e,h,q=>gt(e,m,N=>{K?wt(e,K,k=>e._canimAnimatorSetSocket(o,q,N,D,k)):e._canimAnimatorSetSocket(o,q,N,D,0)}))};if(F===0&&!B){O(-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}O(I,B??[0,0,0,0,0,0,1]),F!==0&&W.sockets.push({set:h,name:m,node:F})},setClipAnchors(o,h,m,w,F,B){gn(e)&&gt(e,m,W=>gt(e,w??"",O=>gt(e,F??"",I=>wt(e,B,D=>e._canimClipsSetAnchors(o,h,W,O,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){wt(e,h,m=>e._canimAnimatorSetWarpParams(o,m,h.length))}},P=(o,h,m)=>{var q,N;const w=t.get(h.rootId),F=w&&w.parent?t.get(w.parent):void 0,B=F?((q=t.world)==null?void 0:q.call(t,F.id))??F.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 k=(((N=t.world)==null?void 0:N.call(t,h.rootId))??w.m)[13];for(let z=0;z<2;z++){if(!e._canimAnimatorFootProbe(o,z,a,c))continue;const Y=e.HEAPF32,se=a>>2;e._canimAnimatorSetGround(o,z,1,Y[se],k,Y[se+2],0,1,0)}}const O=e.HEAPF32,I=e.HEAPU8,D=h.trs>>2;for(let k=0;k<h.n;k++){if(!I[h.write+k])continue;const z=t.get(h.entities[k]);if(!z)continue;const Y=D+k*10;pn(z.m,O[Y],O[Y+1],O[Y+2],O[Y+3],O[Y+4],O[Y+5],O[Y+6],O[Y+7],O[Y+8],O[Y+9]),t.localMatrixChanged(h.entities[k])}if(t.setMorphWeights){const k=e._canimAnimatorMorphCount(o);for(let z=0;z<k;z++){const Y=e._canimAnimatorMorph(o,z,p,g),se=e.HEAP32[p>>2],ee=e.HEAPU32[g>>2];!Y||se<0||ee===0||t.setMorphWeights(h.entities[se],Float32Array.from(e.HEAPF32.subarray(Y>>2,(Y>>2)+ee)))}}const K=e._canimAnimatorRootMotionFrame(o,s);if(K!==0){const k=e.HEAPF32,z=s>>2,Y=k[z],se=k[z+1],ee=k[z+2],ne=k[z+3];let fe=!1;if(K===2&&t.applyRootMotion&&(fe=t.applyRootMotion(h.rootId,Y,se,ee,m,ne)),!fe&&(Y!==0||se!==0||ee!==0||ne!==0)){const we=t.get(h.rootId);if(we){const pe=we.m;ne!==0&&$c(pe,ne);const Ge=pe[0]*Y+pe[4]*se+pe[8]*ee,Qe=pe[1]*Y+pe[5]*se+pe[9]*ee,Ue=pe[2]*Y+pe[6]*se+pe[10]*ee;pe[12]+=Ge,pe[13]+=Qe,pe[14]+=Ue,t.localMatrixChanged(h.rootId)}}}if(d){const k=e._canimAnimatorStepCount(o);for(let z=0;z<k;z++){const Y=e._canimAnimatorStep(o,z,i);if(Y<0)continue;const se=e.HEAPF32,ee=i>>2,ne=se[ee],fe=se[ee+1],we=se[ee+2],pe=B;M.push({id:o,side:Y,x:pe[0]*ne+pe[4]*fe+pe[8]*we+pe[12],y:pe[1]*ne+pe[5]*fe+pe[9]*we+pe[13],z:pe[2]*ne+pe[6]*fe+pe[10]*we+pe[14]})}}if(W>0){const k=e._canimAnimatorEvents(o,u,$s),z=e.HEAPU16,Y=u>>1;for(let se=0;se<k;se++)v.push({id:o,slot:z[Y+se*2],type:z[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 O of h.iks){if(!O.target&&!O.pole&&!O.rotation)continue;const I=O.target?L(O.target):void 0;I&&(O.params[_t.TARGET_X]=I[12],O.params[_t.TARGET_X+1]=I[13],O.params[_t.TARGET_X+2]=I[14]);const D=O.pole?L(O.pole):void 0;D&&(O.params[_t.POLE_X]=D[12],O.params[_t.POLE_X+1]=D[13],O.params[_t.POLE_X+2]=D[14],O.params[_t.HAS_POLE]=1);const K=O.rotation?L(O.rotation):void 0;if(K){const q=Wr(K).r;O.params[_t.ROT_X]=q[0],O.params[_t.ROT_X+1]=q[1],O.params[_t.ROT_X+2]=q[2],O.params[_t.ROT_X+3]=q[3]}wt(e,O.params,q=>e._canimAnimatorIkSet(o,O.ik,q,gr))}for(const O of h.sockets){const I=L(O.node);I&&(e.HEAPF32.set(I,l>>2),gt(e,O.set,D=>gt(e,O.name,K=>e._canimAnimatorSocketSetWorld(o,D,K,l))))}const F=e.HEAPF32,B=h.trs>>2;for(let O=0;O<h.n;O++){const I=t.get(h.entities[O]),{t:D,r:K,s:q}=Wr(I?I.m:Er),N=B+O*10;F[N]=D[0],F[N+1]=D[1],F[N+2]=D[2],F[N+3]=K[0],F[N+4]=K[1],F[N+5]=K[2],F[N+6]=K[3],F[N+7]=q[0],F[N+8]=q[1],F[N+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 O=0;O<h.n;O++){if(!W[h.write+O])continue;const I=t.get(h.entities[O]);if(!I)continue;const D=B+O*10;pn(I.m,F[D],F[D+1],F[D+2],F[D+3],F[D+4],F[D+5],F[D+6],F[D+7],F[D+8],F[D+9]),t.localMatrixChanged(h.entities[O])}};return{methods:R,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,R,P)=>(d&&(i.set(d,y),t.ent(y).physics={motion:Xs[x]??x,mass:R,shape:P}),d),v={...n,physicsHasSupport:()=>Es(),physicsConfigure(d,y,x,R){f={gravity:[d,y,x],maxBodies:R},n.physicsConfigure(d,y,x,R)},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,R,P,L)=>p(n.physicsBuildMesh(d,y,x,R,P,L),{type:x?"convexHull":"mesh",vertices:d.length/3,triangles:Math.floor(y.length/3),scale:[R,P,L]}),physicsBuildMeshFromEntity:(d,y,x,R,P)=>p(n.physicsBuildMeshFromEntity(d,y,x,R,P),{type:y?"convexHull":"mesh",source:d,scale:[x,R,P]}),physicsBuildHeightField(d,y,x,R,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,R,P,L,_,o),{type:"heightfield",size:[y,x],cellSize:R,samples:d.length,holes:h,scale:[L,_,o]})},physicsSetShapeOrigin(d,y,x,R){const P=s.get(d);P&&(y===0&&x===0&&R===0?delete P.origin:P.origin=[y,x,R]),n.physicsSetShapeOrigin(d,y,x,R)},physicsSetBodyShape(d,y,x){const R=g(i,d);R&&(R.shape=s.get(y)),n.physicsSetBodyShape(d,y,x)},physicsDestroyShape(d){s.delete(d),n.physicsDestroyShape(d)},physicsCreateBody(d,y,x,R,P,L){const _=n.physicsCreateBody(d,y,x,R,P,L);return _&&(i.set(_,d),t.ent(d).physics={motion:Xs[x]??x,mass:R,...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,R,P,L)=>u(n.physicsCreateBox(d,y,x,R,P,L),d,P,L,{type:"box",size:[y*2,x*2,R*2]}),physicsCreateSphere:(d,y,x,R)=>u(n.physicsCreateSphere(d,y,x,R),d,x,R,{type:"sphere",radius:y}),physicsCreateCylinder:(d,y,x,R,P)=>u(n.physicsCreateCylinder(d,y,x,R,P),d,R,P,{type:"cylinder",height:y*2,radius:x}),characterCreate(d,y,x){const R=n.characterCreate(d,y,x);return R&&(l.set(R,d),t.ent(d).physics={character:!0,maxSlopeDeg:x,shape:s.get(y)}),R},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 R=g(l,d);R&&(R.shape=s.get(y))}return x},vehicleCreate(d,y,x){const R=n.vehicleCreate(d,y,x);if(!R)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(R,d),t.ent(d).physics={motion:"dynamic",mass:x[1],vehicle:!0,...qs(x,L),wheels:o,shape:s.get(y)},R},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 R=n.ragdollCreate(d,y,x);if(!R)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(R,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},R},ragdollDestroy(d){c.delete(d),n.ragdollDestroy(d)},ragdollActivate(d,y,x,R){const P=n.ragdollActivate(d,y,x,R),L=c.get(d),_=L===void 0?void 0:t.ent(L).ragdoll;return P&&_&&(_.active=!0,_.launch=[y,x,R]),P},ragdollDeactivate(d,y){const x=c.get(d),R=x===void 0?void 0:t.ent(x).ragdoll;R&&(R.active=!1,delete R.launch,y>0&&(R.blendOut=y)),n.ragdollDeactivate(d,y)},ragdollSetDrive(d,y,x){const R=c.get(d),P=R===void 0?void 0:t.ent(R).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,R,P)=>e?e.applyRootMotion(d,y,x,R,P):!1,config:()=>f}},kt={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,R)=>x===d[R])?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,Wt=(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,C,G,Z,re,ce,Ae,Te,Fe,Pe)=>W(S,ci([A,C,G],[Z,re,ce,Ae],[Te,Fe,Pe])),setWorldPosition:(S,A,C,G)=>O(S,A,C,G),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,C;return(C=(A=l.get(S))==null?void 0:A.model)==null?void 0:C.buffer},seedAnimator:(S,A)=>P.methods.animatorSeedPose(S,A),jointRanges:(S,A,C)=>P.methods.animatorJointRanges(S,A,C)}),R=su({ent:S=>o(S),world:S=>m(S),cameraPosition:()=>{var C;const S=(C=a.get(v))==null?void 0:C.camera;if(S===void 0)return null;const A=h(S);return[A[12],A[13],A[14]]},created:(S,A)=>{var C;return(C=t.particleSystemCreated)==null?void 0:C.call(t,S,A)},frame:(S,A)=>{var C;return(C=t.particlesFrame)==null?void 0:C.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 C;return(C=t.morphWeights)==null?void 0:C.call(t,S,A)},applyRootMotion:(S,A,C,G,Z,re)=>{const ce=m(S);return x.applyRootMotion(S,ce[0]*A+ce[4]*C+ce[8]*G,ce[2]*A+ce[6]*C+ce[10]*G,Z,re)}}),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)&&Wt(A.m,qe()),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:bt(new Float32Array(16),h(A.parent),A.m)},m=S=>{const A=h(S);return A instanceof Float32Array?A:Float32Array.from(A)},w=S=>{var Fe;const A=h(S),[C,G,Z]=((Fe=o(S).light)==null?void 0:Fe.direction)??[0,0,-1],re=A[0]*C+A[4]*G+A[8]*Z,ce=A[1]*C+A[5]*G+A[9]*Z,Ae=A[2]*C+A[6]*G+A[10]*Z,Te=Math.hypot(re,ce,Ae)||1;return[re/Te,ce/Te,Ae/Te]},F=S=>{if(S.parent!==0){const A=l.get(S.parent);A&&(A.children=A.children.filter(C=>C!==S.id)),S.parent=0}},B=(S,A,C)=>{var Z,re;const G=o(S);if(G.parent!==A){if(C){const ce=m(S),Ae=A===0?ce:bt(new Float32Array(16),Bt(m(A)),ce);Wt(G.m,Ae)}F(G),A!==0&&(G.parent=A,o(A).children.push(S)),(Z=t.parentChanged)==null||Z.call(t,S,A),(re=t.localMatrixChanged)==null||re.call(t,S)}},W=(S,A)=>{var G;const C=o(S);Wt(C.m,C.parent===0?A:bt(new Float32Array(16),Bt(m(C.parent)),A)),(G=t.localMatrixChanged)==null||G.call(t,S)},O=(S,A,C,G)=>{var ce;const Z=o(S),re=Z.m;if(Z.parent===0)re[12]=A,re[13]=C,re[14]=G;else{const Ae=Bt(m(Z.parent));re[12]=Ae[0]*A+Ae[4]*C+Ae[8]*G+Ae[12],re[13]=Ae[1]*A+Ae[5]*C+Ae[9]*G+Ae[13],re[14]=Ae[2]*A+Ae[6]*C+Ae[10]*G+Ae[14]}(ce=t.localMatrixChanged)==null||ce.call(t,S)},I=S=>{const A=a.get(S),C=(A==null?void 0:A.overlayOf)!==void 0?a.get(A.overlayOf):A;return(C==null?void 0:C.customProjection)??(C==null?void 0:C.projection)??i},D=S=>{for(let A=S;A!==0;){for(const C of a.values())if(C.entities.has(A))return C;A=o(A).parent}return null},K=S=>{var Z;const A=(Z=e.getSourceName)==null?void 0:Z.call(e,S);if(!A)return;const C=A.startsWith("lecodesfile://")?decodeURIComponent(A.slice(14)):A;return(C.includes("/")||C.includes("\\"))&&!C.startsWith("http")?C.split(/[\\/]/).pop()??C:C},q=S=>{let A=c.get(S);return A||(A={shader:"unknown",uniforms:{}},c.set(S,A)),A},N=(S,A,C)=>{var G;q(S).uniforms[A]=C,(G=t.uniformChanged)==null||G.call(t,S,A,C)},k=S=>{const A=e.getBuffer(S),C=A?Gc(A):null,G=_();if(G.model={source:K(S),systemId:S,animations:(C==null?void 0:C.animations)??[],loaded:C!==null,...A&&{buffer:A}},C&&C.animations.length>0&&A&&bi()&&(G.model.clipSet=P.registerGlbClips(A)),!C)return{rootId:G.id,entIds:[]};const Z=C.nodes.map(()=>_().id);C.nodes.forEach((re,ce)=>{var Te;const Ae=o(Z[ce]);Ae.name=re.name??"",Wt(Ae.m,re.matrix),(Te=t.localMatrixChanged)==null||Te.call(t,Ae.id),re.skinJoint&&(Ae.skinJoint=!0),re.mesh&&(Ae.mesh={kind:0,vertexCount:0,primitives:re.mesh.primitives},re.mesh.min&&re.mesh.max&&(Ae.mesh.size=[re.mesh.max[0]-re.mesh.min[0],re.mesh.max[1]-re.mesh.min[1],re.mesh.max[2]-re.mesh.min[2]],Ae.mesh.center=[(re.mesh.max[0]+re.mesh.min[0])/2,(re.mesh.max[1]+re.mesh.min[1])/2,(re.mesh.max[2]+re.mesh.min[2])/2]));for(const Fe of re.children)B(Z[Fe],Ae.id,!1)});for(const re of C.roots)B(Z[re],G.id,!1);return{rootId:G.id,entIds:Z}},z=(S,A)=>{var Z,re;const C=o(S),G=_();A.set(C.id,G.id),G.name=C.name,Wt(G.m,C.m),G.visible=C.visible,C.skinJoint&&(G.skinJoint=!0),C.light&&(G.light={...C.light}),C.punctual&&(G.punctual={...C.punctual}),C.mesh&&(G.mesh={...C.mesh}),G.materials=[...C.materials],C.model&&(G.model={...C.model,animations:C.model.animations}),C.castShadows!==void 0&&(G.castShadows=C.castShadows),C.receiveShadows!==void 0&&(G.receiveShadows=C.receiveShadows),C.particles&&(G.particles=structuredClone(C.particles)),C.physics&&(G.physics=structuredClone(C.physics)),C.collider&&(G.collider=structuredClone(C.collider)),(Z=t.localMatrixChanged)==null||Z.call(t,G.id),(re=t.entityCloned)==null||re.call(t,C.id,G.id);for(const ce of C.children)B(z(ce,A),G.id,!1);return G.id},Y=S=>{var C;const A=l.get(S);if(A){for(const G of[...A.children])Y(G);F(A);for(const G of a.values())G.entities.delete(S);(C=t.entityDestroyed)==null||C.call(t,S),P.onEntityDestroyed(S),R.onEntityDestroyed(S),l.delete(S)}},se=S=>{for(let A=S;A!==0;A=o(A).parent)if(!o(A).visible)return!1;return!0};let ee=1;const ne=S=>{const A=S*ee;M==null||M(S),x.frame(A,y),P.evaluate(A),x.syncRagdolls(A),d==null||d(S),P.lateSolve(),R.update(A)},fe=S=>{const A=Math.min(1e3,Math.floor(S/16));for(let C=0;C<A;C++)ne(.016)},we=()=>v>=0||a.size>0,pe=()=>v,Ge={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 C,G;const A=a.size;return a.set(A,{id:A,entities:new Set,overlays:[],overlayOf:S}),(C=a.get(S))==null||C.overlays.push(A),(G=t.sceneCreated)==null||G.call(t,A),A},createGLView(){},openScene(S){v=S},closeScene(){v=-1},addEntityToScene(S,A){var G;const C=a.get(S);if(C){for(const Z of a.values())Z!==C&&Z.entities.delete(A);C.entities.add(A),(G=t.entitySceneChanged)==null||G.call(t,A,S,!0)}},removeEntityFromScene(S,A){var G;const C=a.get(S);C&&(C.entities.delete(A),(G=t.entitySceneChanged)==null||G.call(t,A,S,!1))},createEntity:()=>_().id,cloneEntity(S){var Z,re;const A=o(S),C=new Map,G=z(S,C);if(A.parent!==0)B(G,A.parent,!1);else{const ce=D(S);ce&&(ce.entities.add(G),(Z=t.entitySceneChanged)==null||Z.call(t,G,ce.id,!0))}return(re=t.subtreeCloned)==null||re.call(t,S,G,C),G},destroyEntity(S){Y(S)},setMatrix(S,A){var G;const C=o(S);Wt(C.m,A),(G=t.localMatrixChanged)==null||G.call(t,S)},setWorldMatrix(S,A){var Z,re;const C=o(S);if(C.parent===0){Wt(C.m,A),(Z=t.localMatrixChanged)==null||Z.call(t,S);return}const G=bt(new Float32Array(16),Bt(m(C.parent)),Float32Array.from(A.subarray(0,16)));Wt(C.m,G),(re=t.localMatrixChanged)==null||re.call(t,S)},getChildCount:S=>o(S).children.length,getChild:(S,A)=>o(S).children[A]??0,setPosition(S,A,C,G){var re;const Z=o(S).m;Z[12]=A,Z[13]=C,Z[14]=G,(re=t.localMatrixChanged)==null||re.call(t,S)},setQuaternion(S,A,C,G,Z){var re;ai(o(S).m,A,C,G,Z),(re=t.localMatrixChanged)==null||re.call(t,S)},setEulerAngles(S,A,C,G,Z){var re;ja(o(S).m,A,C,G,Z),(re=t.localMatrixChanged)==null||re.call(t,S)},setScale(S,A,C,G){var Z;li(o(S).m,A,C,G),(Z=t.localMatrixChanged)==null||Z.call(t,S)},setParent(S,A,C){B(S,A,C)},setParentNull(S,A){B(S,0,A)},getParent:S=>o(S).parent,traverse(S,A){const C=G=>{A(G);for(const Z of o(G).children)C(Z)};for(const G of o(S).children)C(G)},findNode(S,A){const C=Ai(A);let G=0,Z=4;const re=ce=>{const Ae=o(ce),Te=iu(Ae.name,!!Ae.skinJoint,A,C);Te<Z&&Te>=0&&(G=ce,Z=Te);for(const Fe of Ae.children){if(Z===0)return;re(Fe)}};for(const ce of o(S).children){if(Z===0)break;re(ce)}return G},createSunLight(S,A,C,G,Z,re,ce,Ae=100,Te=1){o(S).light={direction:[A,C,G],intensity:Z,color:re,shadowsQuality:ce,shadowDistance:Ae,shadowCascades:Te}},createPointLight(S,A,C,G,Z){o(S).punctual={type:"point",intensity:A,color:C,range:G>0?G:1,inner:0,outer:0,castShadows:Z}},createSpotLight(S,A,C,G,Z,re,ce){const[Ae,Te]=Ys(Z,re);o(S).punctual={type:"spot",intensity:A,color:C,range:G>0?G:1,inner:Ae,outer:Te,castShadows:ce}},setLightCone(S,A,C){var Z;const G=(Z=l.get(S))==null?void 0:Z.punctual;(G==null?void 0:G.type)==="spot"&&([G.inner,G.outer]=Ys(A,C))},setLightIntensity(S,A){const C=l.get(S);C!=null&&C.light&&(C.light.intensity=A),C!=null&&C.punctual&&(C.punctual.intensity=A)},setLightColor(S,A){const C=l.get(S);C!=null&&C.light&&(C.light.color=A),C!=null&&C.punctual&&(C.punctual.color=A)},setDefaultIbl(S,A){const C=a.get(S);C&&(C.ibl=A)},setBloomOptions(S,A,C,G,Z,re,ce,Ae,Te,Fe){const Pe=a.get(S);Pe&&(Pe.bloom=A?{strength:C,threshold:G,highlight:Z,levels:re,quality:ce}:void 0)},setSkybox(S,A){const C=a.get(S);C&&(C.skybox=A)},setSceneMultiSampleAntiAliasing(S,A){const C=a.get(S);C&&(C.antialias=A)},setSceneRenderOptions(){},setMaterialGlobalParameter(){},getCameraFov(S,A){const{fov:C}=I(S);if(A!==1)return C;const G=C*Math.PI/180;return 2*Math.atan(Math.tan(G/2)*(r/n))*180/Math.PI},setCameraProjection(S,A,C,G){const Z=a.get(S);Z&&(Z.projection={fov:A,near:C,far:G})},setCameraMatrix(S,A){var G;const C=(G=a.get(S))==null?void 0:G.camera;C&&Ge.setWorldMatrix(C,A)},setCameraProjectionMatrix(S,A,C,G){const Z=a.get(S);if(!Z||A.length<16)return;const re=Float32Array.from(A.subarray(0,16)),ce=re[5]>0?2*Math.atan(1/re[5])*180/Math.PI:(Z.projection??i).fov;Z.customProjection={fov:ce,near:C,far:G,matrix:re}},clearCameraProjectionMatrix(S){const A=a.get(S);A&&delete A.customProjection},getMatrix(S,A){return A.set(Qe(S)),!0},getWorldMatrix(S,A){A.set(m(S))},getWorldPosition(S,A){const C=h(S);A[0]=C[12],A[1]=C[13],A[2]=C[14]},getWorldDirection(S,A,C){const G=h(S);C[0]=G[A*4],C[1]=G[A*4+1],C[2]=G[A*4+2]},getWorldMatrixInverse(S,A){A.set(Bt(m(S)))},getCameraViewDirection(S,A,C,G){var at;const Z=(at=a.get(S))==null?void 0:at.camera,re=Z?h(Z):qe(),[ce,Ae]=ui(I(S),r/n,A/r*2-1,1-C/n*2),Te=re[0]*ce+re[4]*Ae-re[8],Fe=re[1]*ce+re[5]*Ae-re[9],Pe=re[2]*ce+re[6]*Ae-re[10],ke=Math.hypot(Te,Fe,Pe)||1;G[0]=Te/ke,G[1]=Fe/ke,G[2]=Pe/ke},setMesh(S,A,C,G,Z,re,ce,Ae,Te){var Ot;const Fe=o(S);let Pe=1/0,ke=1/0,at=1/0,Mt=-1/0,Nt=-1/0,Et=-1/0;for(let We=0;We+2<C.length;We+=3){const ht=C[We],It=C[We+1],Ft=C[We+2];ht<Pe&&(Pe=ht),ht>Mt&&(Mt=ht),It<ke&&(ke=It),It>Nt&&(Nt=It),Ft<at&&(at=Ft),Ft>Et&&(Et=Ft)}const Qt=C.length>=3,Ct={kind:ce,vertexCount:Math.floor(C.length/3),size:Qt?[Mt-Pe,Nt-ke,Et-at]:void 0,center:Qt?[(Mt+Pe)/2,(Nt+ke)/2,(Et+at)/2]:void 0};Fe.mesh=Ct,Fe.materials[0]=A,(Ot=t.meshSet)==null||Ot.call(t,S,A,Ct,{vertices:C,normals:G,indices:Z,uv:re,colors:Te})},setCulling(){},setRenderPriority(){},setMaterialDepthTest(){},setMaterialDepthWrite(){},setMaterialCulling(){},setMaterialStencil(){},setSceneStencil(){},setCastShadows(S,A){o(S).castShadows=A},setReceiveShadows(S,A){o(S).receiveShadows=A},setGlbShadows(S,A,C){const G=Z=>{const re=o(Z);re.castShadows=A,re.receiveShadows=C;for(const ce of re.children)G(ce)};G(S)},setCastShadowsGlobal(){},setReceiveShadowsGlobal(){},hasMesh:S=>o(S).mesh!==void 0,createMaterial(S){var G;const A=g++,C={shader:K(S)??"unknown",uniforms:{}};return c.set(A,C),(G=t.materialCreated)==null||G.call(t,A,C,S),A},createMaterialNamed(S){var G;const A=g++,C={shader:S,uniforms:{}};return c.set(A,C),(G=t.materialCreated)==null||G.call(t,A,C),A},setMaterial(S,A,C){o(S).materials[C]=A},getMaterial:(S,A)=>o(S).materials[A]??0,setUniformRgb(S,A,C){N(S,A,{kind:"rgb",v:C})},setUniformRgba(S,A,C){N(S,A,{kind:"rgba",v:C})},setUniformFloat(S,A,C){N(S,A,{kind:"float",v:C})},setUniformBoolean(S,A,C){N(S,A,{kind:"bool",v:C})},setUniformTexture(S,A,C){N(S,A,{kind:"texture",v:C})},setUniformArray(S,A,C){N(S,A,{kind:"array",v:Array.from(C)})},setUniformNull(S,A){N(S,A,{kind:"null"})},createTexture(S,A,C){const G=e.getBuffer(S);if(!G||G.byteLength===0){C();return}const[Z,re]=au(G),ce=u++;f.set(ce,{source:K(S),width:Z,height:re}),A(ce,Z,re)},createTextureFromCanvas(S){const A=u++;return f.set(A,{source:`canvas#${S}`,width:0,height:0}),A},updateTextureFromCanvas(){},createTexturePixels(S,A,C){const G=u++;return f.set(G,{source:`pixels ${S}x${A}x${C}`,width:S,height:A}),G},updateTexturePixels(){},createMediaPlayerTexture(S){const A=u++;return f.set(A,{source:`mediaplayer#${S}`,width:0,height:0}),A},attachCameraToAR(S,A,C){const G=a.get(S);G&&(G.camera=A);const Z=I(S);C(Z.matrix?Float32Array.from(Z.matrix):Sn(Z.fov,r/n,Z.near,Z.far),Z.fov)},getDisplaySize:()=>Float32Array.of(r,n),setVisible(S,A){var G;o(S).visible=A,(G=t.visibleChanged)==null||G.call(t,S,A);const C=Z=>{const re=o(Z);re.particles&&R.setVisible(Z,se(Z));for(const ce of re.children)C(ce)};C(S)},isVisible:S=>se(S),getName:S=>o(S).name,setName(S,A){o(S).name=A},createGlb(S,A,C){const{rootId:G,entIds:Z}=k(S);if(!t.glbAttach){A(G);return}Promise.resolve(t.glbAttach(S,G,Z)).then(()=>A(G)).catch(re=>C==null?void 0:C(re))},setGlbCulling(){},getGlbClipSet:S=>{var A,C;return((C=(A=l.get(S))==null?void 0:A.model)==null?void 0:C.clipSet)??0},...P.methods,setEarlyUpdate(S){M=S},setLateUpdate(S){d=S},setFixedUpdate(S){y=S},setTimeScale(S){ee=Number.isFinite(S)&&S>0?S:0},...x.methods,...R.methods};function Qe(S){const A=o(S).m;return A instanceof Float32Array?A:Float32Array.from(A)}let Ue=null;return{width:r,height:n,fov:s,entities:l,scenes:a,materials:c,textures:f,cameraOverride:()=>Ue,setCameraOverride:S=>{Ue=S},ent:o,newEnt:_,worldMatrix:h,worldMatrixF:m,sunDirection:w,sourceName:K,setParentInternal:B,sceneOf:D,projectionOf:I,rebindMatrix:(S,A)=>{o(S).m=A},methods:Ge,simulate:fe,tick:ne,hasActiveScene:we,activeSceneId:pe,physicsConfig:x.config,particleIndexPattern:R.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]},$t=(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):Bt(t.worldMatrixF(r)),u=bt(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],F=u[1]*_+u[5]*o+u[9]*h+u[13],B=m>1e-4;return B?{sx:(w/m*.5+.5)*s,sy:(1-(F/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=[],R=_=>{if(!(y.has(_)||!t.entities.has(_))){y.add(_),x.push(_);for(const o of t.ent(_).children)R(o)}};for(const _ of d)for(const o of _.entities)R(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 C=t.worldMatrixF(_);m=[[C[12],C[13],C[14]]]}if(m.length===0)continue;let w=1/0,F=1/0,B=1/0,W=-1/0,O=-1/0,I=-1/0;for(const C of m)C[0]<w&&(w=C[0]),C[0]>W&&(W=C[0]),C[1]<F&&(F=C[1]),C[1]>O&&(O=C[1]),C[2]<B&&(B=C[2]),C[2]>I&&(I=C[2]);const D=v((w+W)/2,(F+O)/2,(B+I)/2);let K=!1,q=!1,N=1/0,k=1/0,z=-1/0,Y=-1/0;for(const C of m){const G=v(C[0],C[1],C[2]);if(!G.inFront){K=!0;continue}q=!0,G.sx<N&&(N=G.sx),G.sx>z&&(z=G.sx),G.sy<k&&(k=G.sy),G.sy>Y&&(Y=G.sy)}const se={kind:h,depth:$t(D.cw,3),coverage:0};if(o.name&&(se.name=o.name),!q){se.behindCamera=!0,P.push({obj:se,id:_});continue}const ee=N,ne=k,fe=Math.max(0,z-N),we=Math.max(0,Y-k);se.rect=[$t(ee,1),$t(ne,1),$t(fe,1),$t(we,1)],D.inFront&&(se.center=[$t(D.sx,1),$t(D.sy,1)]);const pe=Math.max(0,ee),Ge=Math.max(0,ne),Qe=Math.min(s,ee+fe),Ue=Math.min(i,ne+we),S=Math.max(0,Qe-pe)*Math.max(0,Ue-Ge);se.coverage=$t(S/(s*i),4);const A=ee>=0&&ne>=0&&ee+fe<=s&&ne+we<=i;S===0?se.offscreen=!0:(K||!A)&&(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 Xt=(t,e=4)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},nr=(t,e=4)=>Array.from(t,r=>Xt(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,R]of Object.entries(d.uniforms))y[x]=a(R);return y},f=M=>{var o;const d=t.ent(M),y=d.m,x=nr([y[12],y[13],y[14]]),R=ys(y).map(h=>Xt(h,2)),P=Or(y).map(h=>Xt(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),R.some(h=>h!==0)&&(_.rotation=R),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=nr(d.mesh.size)),(o=d.mesh.center)!=null&&o.some(w=>Xt(w)!==0)&&(h.center=nr(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:Xt(h.duration,2)}))}),d.light&&(_.light={type:"sun",direction:nr(t.sunDirection(M)),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:Xt(h.outer*360/Math.PI,2),innerAngle:Xt(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 R=t.cameraOverride();if(R)x.camera={position:nr(R.eye),lookAt:nr(R.target),fov:R.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(_=>Xt(_,2));x.camera={position:nr([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:qe()},exposure:{value:Qa},punctualCount:{value:0},punctualPos:{value:new Array(sr*4).fill(0)},punctualColor:{value:new Array(sr*4).fill(0)},punctualDir:{value:new Array(sr*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 R=new Map,P=new Map,L=new Map,_=new Map,o=new Map,h=new Map,m={value:1},w=new Map;let F=1,B=!0,W=!0,O=null;const I=[],D=b=>{let E=R.get(b);if(!E){const T=new vt;T.matrixAutoUpdate=!1,T._entId=b,E={transform:T,drawables:[]},R.set(b,E)}return E},K=(b,E=!1)=>{let T,U=null;if(b==="lit")U=el,T=new ze(u,{vertex:tr,fragment:U,uniforms:{...d,baseColor:{value:[1,1,1]},baseColorMap:{value:v},roughness:{value:0},metallic:{value:0}}});else if(b==="terrain")U=tl,T=new ze(u,{vertex:tr,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,T=new ze(u,{vertex:tr,fragment:U,uniforms:{baseColorMap:{value:v},shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap}});else if(b==="shadow")U=il,T=new ze(u,{vertex:tr,fragment:U,uniforms:{...d,color:{value:[0,0,0,.66]}},transparent:!0}),T.setBlendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA);else if(b==="particles"||b==="particles-quad"){const H=b==="particles-quad";T=new ze(u,{vertex:H?fl:ul,fragment:H?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,...H?{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}),T.setBlendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA)}else U=E?nl:rl,T=new ze(u,{vertex:tr,fragment:U,uniforms:{baseColor:{value:[1,1,1,1]},baseColorMap:{value:v},shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap},transparent:E}),E&&T.setBlendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA);return U===null?{kind:b,program:T}:{kind:b,program:T,source:q(U)}},q=b=>({fragment:()=>b,vertex:""}),N=b=>{const E=Pl(s(b));if(!E)return null;if(E.unsupported)return console.warn(`[viewer-lite] custom material not supported in lite (${E.unsupported}) — rendering unlit`),null;E.hasVertexBlock&&console.warn("[viewer-lite] custom material has a vertex{} block — the custom vertex stage is ignored in lite");const T=Ol(E);if(!T)return null;const U=T.needsSceneUniforms?{...d,userTime:y}:{shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap,userTime:y};for(const J of T.uniforms)U[J.key]={value:J.value==="texture"?v:J.value};const H=E.blending==="opaque"||E.blending==="masked",j=new ze(u,{vertex:tr,fragment:T.fragment,uniforms:U,transparent:!H,cullFace:E.doubleSided||E.culling==="none"?!1:E.culling==="front"?u.FRONT:u.BACK,depthWrite:E.depthWrite});return u.getProgramParameter(j.program,u.LINK_STATUS)?(H||j.setBlendFunc(u.ONE,E.blending==="add"?u.ONE:u.ONE_MINUS_SRC_ALPHA),{kind:"custom",program:j,source:q(T.fragment),customParams:T.paramNames}):(console.warn("[viewer-lite] custom material failed to compile — rendering unlit"),null)},k=(b,E)=>{const T=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(T==="unknown"&&E!==void 0){const U=N(E);if(U)return U;console.warn(`[viewer-lite] custom shader can't run here (material "${b||E}") — rendering unlit`)}return K(T,b.startsWith("unlit-transparent"))},z=(b,E)=>{if(!b.source)return b.program;const T=gi(E);if(T===b.source.vertex)return b.program;b.variants??(b.variants=new Map);let U=b.variants.get(T);if(U===void 0){const H=b.program,j=new ze(u,{vertex:_n(T),fragment:b.source.fragment(T),uniforms:H.uniforms,transparent:H.transparent,cullFace:H.cullFace,frontFace:H.frontFace,depthTest:H.depthTest,depthWrite:H.depthWrite,depthFunc:H.depthFunc});j.blendFunc={...H.blendFunc},j.blendEquation={...H.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 [${T}] — the mesh is drawn with its base program`)),b.variants.set(T,U)}return U??b.program},Y=b=>{const E=[b.program];if(b.variants)for(const T of b.variants.values())T&&E.push(T);return E},se=(b,E)=>{var H;const T=b.kind==="gltf"?mu[E]??E:(H=b.customParams)!=null&&H.has(E)?`materialParams_${E}`:E,U=b.program.uniforms;return U[T]||(U[T]={value:0}),U[T]},ee=(b,E,T)=>{const U=_.get(b);if(!U)return;if(E==="useBaseColorMap"&&(U.kind==="lit"||U.kind==="unlit")){if(T.kind==="bool"&&!T.v){const j=se(U,"baseColorMap");j.value instanceof Ke&&(j.value=v)}return}const H=se(U,E);switch(T.kind){case"rgb":{const[j,J,ie]=ll(T.v);Array.isArray(H.value)&&H.value.length===4?H.value=[j,J,ie,H.value[3]]:H.value=[j,J,ie];break}case"rgba":{const j=cl(T.v);H.value=Array.isArray(H.value)&&H.value.length===3?j.slice(0,3):j;break}case"float":H.value=T.v;break;case"bool":H.value=T.v?1:0;break;case"array":H.value=Float32Array.from(T.v);break;case"texture":{const j=o.get(T.v);j&&(H.value=j);break}case"null":H.value instanceof Ke&&(H.value=v);break}},ne=(b,E)=>{E.kind!=="lit"&&E.kind!=="gltf"&&E.kind!=="shadow"&&E.kind!=="custom"||b.onBeforeRender(()=>{const T=b.program.uniforms;if(T.shadowEnabled){const U=d.shadowEnabled.value===1&&b._receiveShadows!==!1;T.shadowEnabled=U?d.shadowEnabled:{value:0}}})},fe=(b,E,T,U)=>{const H=_.get(E);if(!H)return;const{vertices:j,normals:J,indices:ie,uv:de,colors:ue}=T,be=new ut(u,{position:{size:3,data:Float32Array.from(j)},normal:{size:3,data:J.length?Float32Array.from(J):new Float32Array(j.length)},uv:{size:2,data:de.length?Float32Array.from(de):new Float32Array(j.length/3*2)},...ue&&ue.length?{color:{size:4,data:Float32Array.from(ue,Ve=>Ve/255)}}:{},index:{data:Uint16Array.from(ie)}});be.computeBoundingBox();const ge=U===1?u.LINES:U===2?u.POINTS:u.TRIANGLES,ve=new nt(u,{geometry:be,program:H.program,mode:ge});ve.program=z(H,ve),ve.matrixAutoUpdate=!1,ve._entId=b,ve._castShadows=B,ve._receiveShadows=W,ne(ve,H);const _e=D(b);for(const Ve of _e.drawables){_e.transform.removeChild(Ve);const ot=Z.get(Ve);ot&&(ot.setParent(null),Z.delete(Ve))}_e.drawables=[ve],_e.transform.addChild(ve)},we=async(b,E,T)=>{const U=s(b);let H;try{H=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}H.nodes.forEach((j,J)=>{const ie=T[J];if(ie===void 0)return;const de=D(ie);de.transform.setParent(null),ye.rebindMatrix(ie,j.matrix),j.matrixAutoUpdate=!1,j._entId=ie,de.transform=j,de.drawables=[];for(const ue of j.children)ue.draw&&(ue.matrixAutoUpdate=!1,ue._entId=ie,ue._castShadows=B,ue._receiveShadows=W,de.drawables.push(ue))});for(const j of H.roots)j.setParent(D(E).transform)},pe=[],Ge=(b,E)=>{const T=D(b),U=D(E);for(const H of T.drawables){const j=H instanceof Pt?new Pt(u,{skeleton:H.skeleton,geometry:H.geometry,program:H.program,mode:H.mode}):new nt(u,{geometry:H.geometry,program:H.program,mode:H.mode});j instanceof Pt&&pe.push(j);const J=H._morph;J&&(j._morph=J,vi(j,J)),j._entId=E,j._castShadows=H._castShadows,j._receiveShadows=H._receiveShadows,j.frustumCulled=H.frustumCulled,j.matrixAutoUpdate=!1,U.drawables.push(j),U.transform.addChild(j)}},Qe=b=>{for(const E of pe.splice(0)){const T=E.skeleton.joints.map(U=>{const H=U._entId===void 0?void 0:b.get(U._entId);if(H===void 0)return U;const j=D(H).transform;return j.bindInverse=U.bindInverse,j});E.skeleton={...E.skeleton,joints:T}}};let Ue="off";const S={value:[.05,.06,.08]},A=new ze(u,{vertex:tr,fragment:ws,uniforms:{uWireColor:S,shadowMatrix:d.shadowMatrix}}),C=new ze(u,{vertex:_n("HAS_SKIN"),fragment:ws,uniforms:{uWireColor:S,shadowMatrix:d.shadowMatrix,boneTexture:{value:v},boneTextureSize:{value:4}}}),G=new WeakMap,Z=new WeakMap,re=b=>{var T;let E=G.get(b);if(!E){const U={};for(const[J,ie]of Object.entries(b.attributes))J!=="index"&&(U[J]={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 H=b.attributes.position,j=H?H.count??H.data.length/H.size:0;U.index={data:_l((T=b.attributes.index)==null?void 0:T.data,j)},E=new ut(u,U),G.set(b,E)}return E},ce=b=>{var U,H;let E=Z.get(b);if(E)return E;if(!b.parent||!((H=(U=b.geometry)==null?void 0:U.attributes)!=null&&H.position))return null;const T=re(b.geometry);return E=b instanceof Pt?new Pt(u,{skeleton:b.skeleton,geometry:T,program:C,mode:u.LINES}):new nt(u,{geometry:T,program:A,mode:u.LINES}),E.frustumCulled=!1,E.matrixAutoUpdate=!1,E.matrix.copy(b.matrix),E._entId=b._entId,E._castShadows=!1,E._receiveShadows=!1,E.setParent(b.parent),Z.set(b,E),He(),E},Ae=()=>{for(const b of R.values())for(const E of b.drawables)if(E.mode===u.TRIANGLES)if(Ue==="off"){E.visible=!0;const T=Z.get(E);T&&(T.visible=!1)}else{const T=ce(E);E.visible=Ue==="overlay",T&&(T.visible=!0)}},Te=()=>{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,ke=e.transparent===!0,at=0,Mt=0,Nt=xn,Et=wn,Qt=Mn,Ct=null,Ot=!1,We=1,ht=null,It=0;const Ft=new ze(u,{vertex:Rr(!1),fragment:Pr,uniforms:{modelMatrix:{value:qe()},shadowViewProjection:{value:qe()}},cullFace:u.FRONT}),Ur=new ze(u,{vertex:Rr(!0),fragment:Pr,uniforms:{modelMatrix:{value:qe()},shadowViewProjection:{value:qe()},boneTexture:{value:v},boneTextureSize:{value:4}},cullFace:u.FRONT}),Dr=new ze(u,{vertex:Rr(!1,!0),fragment:Pr,uniforms:{shadowViewProjection:{value:qe()}},cullFace:u.FRONT}),Zt=new Map;let Sr=!0;const St=b=>{let E=Zt.get(b);return E||(E=Mc(u,g),E.setEnabled(Sr),Zt.set(b,E)),E};let or=0;const He=()=>{or++},Kr=new Map,$=b=>{Kr.get(b)!==or&&(b.updateMatrixWorld(),Kr.set(b,or))},te=(b,E,T=!1)=>{const U=St(b);$(b),U.collect(b,E,!0,or,T),U.drawMain(E,d.shadowEnabled),T&&He()},X=b=>{var E;for(const[T,U]of ye.entities)if(U.light&&ye.methods.isVisible(T)&&((E=ye.sceneOf(T))==null?void 0:E.id)===b)return{...U.light,direction:ye.sunDirection(T)};return null};let Q=!1;const ae=b=>{var de,ue;const E=(de=ye.scenes.get(b))==null?void 0:de.camera,T=E!==void 0?ye.worldMatrix(E):qe(),U=[];for(const[be,ge]of ye.entities){const ve=ge.punctual;if(!ve||!(ve.intensity>0)||!ye.methods.isVisible(be)||((ue=ye.sceneOf(be))==null?void 0:ue.id)!==b)continue;const _e=ye.worldMatrix(be);U.push({id:be,p:ve,w:_e,near:Math.hypot(_e[12]-T[12],_e[13]-T[13],_e[14]-T[14])-ve.range})}U.length>sr&&(U.sort((be,ge)=>be.near-ge.near),Q||(Q=!0,console.warn(`[viewer-lite] ${U.length} point / spot lights in the scene: the lite engine draws the ${sr} nearest the camera`)));const H=Math.min(U.length,sr),j=d.punctualPos.value,J=d.punctualColor.value,ie=d.punctualDir.value;for(let be=0;be<H;be++){const{p:ge,w:ve}=U[be],_e=be*4;j[_e]=ve[12],j[_e+1]=ve[13],j[_e+2]=ve[14],j[_e+3]=1/(ge.range*ge.range);const Ve=ge.intensity/(ge.type==="spot"?Math.PI:4*Math.PI);J[_e]=(ge.color>>>16&255)/255*Ve,J[_e+1]=(ge.color>>>8&255)/255*Ve,J[_e+2]=(ge.color&255)/255*Ve;const ot=-ve[8],Tt=-ve[9],mt=-ve[10],Vt=Math.hypot(ot,Tt,mt)||1;if(ie[_e]=ot/Vt,ie[_e+1]=Tt/Vt,ie[_e+2]=mt/Vt,ge.type==="spot"){const Ht=Math.cos(ge.outer),Jt=1/Math.max(1/1024,Math.cos(ge.inner)-Ht);J[_e+3]=Jt,ie[_e+3]=-Ht*Jt}else J[_e+3]=0,ie[_e+3]=1}d.punctualCount.value=H},oe=b=>{const E=[];return b.traverse(T=>T.visible?(T.draw&&E.push(T),!1):!0),E},he=(b,E)=>{const T=E.shadowsQuality>=3?4096:E.shadowsQuality>=2?2048:1024;(!ht||It!==T)&&(ht=new ii(u,{width:T,height:T,depthTexture:!0}),It=T);const U=St(b),H=U.casterSingles,j=[1/0,1/0,1/0],J=[-1/0,-1/0,-1/0],ie=[0,0,0];for(const Dt of H){const xt=Dt.geometry;if(xt.bounds||xt.computeBoundingBox(),!xt.bounds||!isFinite(xt.bounds.min.x))continue;const Gr=Dt.worldMatrix;for(let er=0;er<8;er++){Lt(ie,Gr,er&1?xt.bounds.max.x:xt.bounds.min.x,er&2?xt.bounds.max.y:xt.bounds.min.y,er&4?xt.bounds.max.z:xt.bounds.min.z,1);for(let Rt=0;Rt<3;Rt++)ie[Rt]<j[Rt]&&(j[Rt]=ie[Rt]),ie[Rt]>J[Rt]&&(J[Rt]=ie[Rt])}}if(U.casterBounds(j,J),!isFinite(j[0])){d.shadowEnabled.value=0;return}const[de,ue,be]=j,[ge,ve,_e]=J,Ve=(de+ge)/2,ot=(ue+ve)/2,Tt=(be+_e)/2,mt=Math.max(.5,Math.hypot(ge-de,ve-ue,_e-be)/2);let Vt=E.direction[0],Ht=E.direction[1],Jt=E.direction[2];const Zr=Math.hypot(Vt,Ht,Jt)||1;Vt/=Zr,Ht/=Zr,Jt/=Zr;const Ut=[Ve-Vt*mt*2,ot-Ht*mt*2,Tt-Jt*mt*2],ar=-Vt,lr=-Ht,cr=-Jt,ur=Math.abs(Ht)>.99?[1,0,0]:[0,1,0];let hr=ur[1]*cr-ur[2]*lr,fr=ur[2]*ar-ur[0]*cr,dr=ur[0]*lr-ur[1]*ar;const Jr=Math.hypot(hr,fr,dr)||1;hr/=Jr,fr/=Jr,dr/=Jr;const Bn=lr*dr-cr*fr,Nn=cr*hr-ar*dr,On=ar*fr-lr*hr,pt=new Float32Array(16);pt[0]=hr,pt[4]=fr,pt[8]=dr,pt[1]=Bn,pt[5]=Nn,pt[9]=On,pt[2]=ar,pt[6]=lr,pt[10]=cr,pt[12]=-(hr*Ut[0]+fr*Ut[1]+dr*Ut[2]),pt[13]=-(Bn*Ut[0]+Nn*Ut[1]+On*Ut[2]),pt[14]=-(ar*Ut[0]+lr*Ut[1]+cr*Ut[2]),pt[15]=1;const Fi=qa(-mt,mt,-mt,mt,.05,mt*4),zr=bt(new Float32Array(16),Fi,pt);Ft.uniforms.shadowViewProjection.value=zr,Ur.uniforms.shadowViewProjection.value=zr,Dr.uniforms.shadowViewProjection.value=zr,d.shadowMatrix.value=zr,d.shadowMap.value=ht.depthTexture,d.shadowMapSize.value=T,d.shadowEnabled.value=1,g.bindFramebuffer(ht),g.setViewport(T,T),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=qe();for(const Dt of H){const xt=Dt instanceof Pt,Gr=xt?Ur:Ft,er=Dt.program;Gr.uniforms.modelMatrix.value=xt?Ti:Dt.worldMatrix,Dt.program=Gr,Dt.draw({}),Dt.program=er}U.drawShadow(Dr),g.bindFramebuffer({buffer:null})};let le=null,me=null,Me=null,Ee=null;const xe=(b,E,T)=>{if(Me===null&&(Me=bc(u),Me||console.warn("[viewer-lite] bloom needs EXT_color_buffer_float — drawn without")),!Me||E===0||T===0)return null;Ee??(Ee=Ac(u,4));const U=b.antialias===!1?0:Ee;return(!le||le.width!==E||le.height!==T||le.samples!==U)&&(le==null||le.dispose(),le=Sc(u,g,E,T,U),le||(Me=!1,console.warn("[viewer-lite] bloom target is incomplete on this driver — drawn without"))),le},Se=b=>{let E=at===0?0:(b-at)/1e3;E>.05&&(E=.05),at=b;const T=b/1e3;y.value[0]=T,y.value[1]=T-Math.floor(T),ye.tick(E)},Ie=(b,E,T)=>{var be;const U=E/Math.max(1,T),{fov:H,near:j,far:J,matrix:ie}=ye.projectionOf(b);if(m.value=Math.max(1,T)/(2*Math.tan(H*Math.PI/360)),ie){for(let ge=0;ge<16;ge++)Fe.projectionMatrix[ge]=ie[ge];Fe.near=j,Fe.far=J,Mt=0}else(U!==Mt||H!==Nt||j!==Et||J!==Qt)&&(Mt=U,Nt=H,Et=j,Qt=J,Fe.perspective({fov:H,aspect:U,near:j,far:J}));const de=(be=ye.scenes.get(b))==null?void 0:be.camera,ue=de!==void 0?ye.worldMatrix(de):qe();for(let ge=0;ge<16;ge++)Fe.matrix[ge]=ue[ge];Fe.worldMatrixNeedsUpdate=!0},Le=()=>({buffer:null,x:0,y:0,width:t.width,height:t.height}),Oe=(b,E=Le())=>{const T=ye.activeSceneId(),U=ye.scenes.get(T),H=P.get(T);if(!U||!H)return!1;Se(b),Te(),Ie(T,E.width,E.height),Ue!=="off"?(Ae(),u.enable(u.POLYGON_OFFSET_FILL),u.polygonOffset(1,1)):u.disable(u.POLYGON_OFFSET_FILL),$(H);const j=St(H);j.collect(H,Fe,!0,or);const J=X(T);if(J){const ge=(J.color>>>16&255)/255,ve=(J.color>>>8&255)/255,_e=(J.color&255)/255;d.sunDirection.value=J.direction,d.sunColorIntensity.value=[ge,ve,_e,J.intensity],J.shadowsQuality>0?he(H,J):d.shadowEnabled.value=0}else d.sunColorIntensity.value=[1,1,1,0],d.shadowEnabled.value=0;ae(T),d.iblLuminance.value=U.ibl??0;const ie=O?void 0:U.bloom,de=ie?xe(U,E.width,E.height):null;d.uTonemap.value=de?0:1;const ue=U.skybox!==void 0?[(U.skybox>>>16&255)/255,(U.skybox>>>8&255)/255,(U.skybox&255)/255]:[.1,.25,.57],be=de?ue:ue.map(al);de?(de.bindDraw(),xi(u,g,de.width,de.height)):Br(u,g,E),ke||Xe.active()?u.clearColor(0,0,0,0):u.clearColor(be[0],be[1],be[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),O==null||O.renderScenePass(be);for(const ge of U.overlays){const ve=P.get(ge);ve&&(u.clear(u.DEPTH_BUFFER_BIT),te(ve,Fe))}if(O==null||O.renderOverlayPass(),O==null||O.renderPreviewPass(H,be),de&&ie){de.resolve(),me??(me=Uc(u,g));const ge=me.run(de.texture,de.width,de.height,ie);me.compose(de.texture,ge.texture,ie.strength/ge.levels,E)}return E.buffer===null&&Xe.active()&&queueMicrotask(it),!0},De=new Set,Ne=(b,E)=>{const T=E instanceof Error?E.message:String(E);De.has(T)||(De.add(T),console.error(`[viewer-lite] ${b} failed:`,E))},Be=()=>{Ot||(Ot=!0,requestAnimationFrame(Ze))},$e=()=>{if(Ct)try{Ct()}catch(b){Ne("the host's frame hook",b)}},Ze=()=>{if(Ot=!1,!(!Pe||Xe.active())){$e();try{Oe(performance.now())}catch(b){Ne("render frame",b)}Be()}},Ye=()=>{g.bindFramebuffer({buffer:null}),u.clearColor(0,0,0,0),g.setDepthMask(!0),u.clear(u.COLOR_BUFFER_BIT|u.DEPTH_BUFFER_BIT)},it=()=>{Xe.active()&&Ye()},Xe=Fc({gl:u,renderer:g,near:wn,far:Mn,presenting(b){b?Ye():Pe&&Be()},begin(){Pe&&$e()},view(b,E,T,U,H){if(!Pe)return!1;const j=ye.activeSceneId();return b!==void 0&&j!==b?!1:(ye.methods.setCameraMatrix(j,E),ye.methods.setCameraProjectionMatrix(j,T,U,H),!0)},draw(b){if(Pe)try{b?Oe(performance.now(),b):Se(performance.now())}catch(E){Ne("render frame (XR)",E)}},failed:Ne}),yt=b=>{var E;return(E=ye.sceneOf(b))==null?void 0:E.id};let ft=[0,0,0];const tt=(b,E,T)=>{var Tt;const U=(Tt=ye.scenes.get(b))==null?void 0:Tt.camera,H=U!==void 0?ye.worldMatrix(U):qe(),j=Math.max(1,t.width),J=Math.max(1,t.height),ie=j/J,de=E*We,ue=T*We,[be,ge]=ui(ye.projectionOf(b),ie,de/j*2-1,1-ue/J*2),ve=H[0]*be+H[4]*ge-H[8],_e=H[1]*be+H[5]*ge-H[9],Ve=H[2]*be+H[6]*ge-H[10],ot=Math.hypot(ve,_e,Ve)||1;return ft=[H[12],H[13],H[14]],{origin:ft,dir:[ve/ot,_e/ot,Ve/ot]}},rt=(b,E,T)=>{const U=L.get(b);if(!U)return 0;let H=1/0,j=0;const J=[0,0,0],ie=[0,0,0];for(const[de,ue]of U){if(!ye.entities.has(de)||!ye.methods.isVisible(de))continue;const be=Bt(ye.worldMatrixF(de));Lt(J,be,E[0],E[1],E[2],1),Lt(ie,be,T[0],T[1],T[2],0);const ge=ue.type==="box"?xs(ue.center,ue.extent,J,ie):Ya(ue.center,ue.radius,J,ie);ge>0&&ge<H&&(H=ge,j=de)}return j},je=(b,E,T)=>{const U=P.get(b);if(!U)return 0;let H=1/0,j=0;const J=[0,0,0],ie=[0,0,0];U.updateMatrixWorld();for(const de of oe(U)){const ue=de.geometry;if(ue.bounds||ue.computeBoundingBox(),!ue.bounds||!isFinite(ue.bounds.min.x))continue;const be=Bt(de.worldMatrix);Lt(J,be,E[0],E[1],E[2],1),Lt(ie,be,T[0],T[1],T[2],0);const ge=[(ue.bounds.min.x+ue.bounds.max.x)/2,(ue.bounds.min.y+ue.bounds.max.y)/2,(ue.bounds.min.z+ue.bounds.max.z)/2],ve=[(ue.bounds.max.x-ue.bounds.min.x)/2,(ue.bounds.max.y-ue.bounds.min.y)/2,(ue.bounds.max.z-ue.bounds.min.z)/2],_e=xs(ge,ve,J,ie);_e>0&&_e<H&&(H=_e,j=de._entId??0)}return j},Je=(b,E)=>{const T=ye.activeSceneId(),U=ye.scenes.get(T);if(!U||U.camera===void 0)return 0;const{origin:H,dir:j}=tt(T,b,E);for(let J=U.overlays.length-1;J>=0;J--){const ie=rt(U.overlays[J],H,j);if(ie!==0)return ie}return rt(T,H,j)},zt=b=>{b.mesh&&b.mesh.setParent(null),b.buffer&&u.deleteBuffer(b.buffer),b.mesh=null,b.geometry=null,b.buffer=null},Gt=(b,E)=>{const T=_.get(b.materialId);if(E===kt.MESH)return(T??K("unlit")).program;const U=E!==kt.POINTS;return T&&T.kind===(U?"particles-quad":"particles")?T.program:K(U?"particles-quad":"particles").program},dt=(b,E,T)=>{if(zt(E),E.version=T.geometryVersion,E.mode=T.mode,T.capacity===0)return;const U=ye.particleIndexPattern(b);if(U.length===0)return;let H;if(T.mode===kt.MESH){const J=T.capacity*T.meshVertexCount;H=new ut(u,{position:{size:3,data:new Float32Array(J*3),usage:u.DYNAMIC_DRAW},normal:{size:3,data:new Float32Array(J*3),usage:u.DYNAMIC_DRAW},uv:{size:2,data:new Float32Array(J*2),usage:u.DYNAMIC_DRAW},index:{data:U}})}else{const J=u.createBuffer();E.buffer=J;const ie=T.stride,de=T.mode===kt.POINTS?T.capacity:T.mode===kt.QUADS?T.capacity*4:(T.capacity+1)*2,ue=(ge,ve)=>({size:ge,type:u.FLOAT,buffer:J,stride:ie,offset:ve,count:de,data:new Float32Array(0)}),be={position:ue(3,0),color:ue(4,12),custom:ue(4,28)};T.mode!==kt.POINTS&&(be.aux=ue(3,44),be.corner=ue(2,56)),be.index={data:Uint16Array.from(U)},H=new ut(u,be),u.bindBuffer(u.ARRAY_BUFFER,J),u.bufferData(u.ARRAY_BUFFER,de*ie,u.DYNAMIC_DRAW),g.state.boundBuffer=J}const j=new nt(u,{geometry:H,program:Gt(E,T.mode),mode:T.mode===kt.POINTS?u.POINTS:u.TRIANGLES});j.frustumCulled=!1,j.matrixAutoUpdate=!1,j._entId=b,j._particles=!0,j.setParent(D(b).transform),E.geometry=H,E.mesh=j},_i=(b,E)=>{let T=h.get(b);if(T||(T={materialId:0,mesh:null,geometry:null,buffer:null,version:0,mode:-1},h.set(b,T)),(T.version!==E.geometryVersion||T.mode!==E.mode||!T.mesh)&&(dt(b,T,E),He()),!T.mesh||!T.geometry)return;const U=E.indexCount>0;if(T.mesh.visible!==U&&(T.mesh.visible=U,He()),!!U){if(T.mesh.renderOrder=E.order,E.mode===kt.MESH){const H=E.vertexCount,j=new Float32Array(E.bytes.buffer,E.bytes.byteOffset,H*10),J=T.geometry.attributes.position,ie=T.geometry.attributes.normal,de=T.geometry.attributes.uv,ue=J.data,be=ie.data,ge=de.data;for(let ve=0;ve<H;ve++){const _e=ve*10;ue[ve*3]=j[_e],ue[ve*3+1]=j[_e+1],ue[ve*3+2]=j[_e+2];const Ve=j[_e+3],ot=j[_e+4],Tt=j[_e+5],mt=j[_e+6];be[ve*3]=2*(Ve*Tt+ot*mt),be[ve*3+1]=2*(ot*Tt-Ve*mt),be[ve*3+2]=1-2*(Ve*Ve+ot*ot),ge[ve*2]=j[_e+8],ge[ve*2+1]=j[_e+9]}J.needsUpdate=ie.needsUpdate=de.needsUpdate=!0}else T.buffer&&(u.bindBuffer(u.ARRAY_BUFFER,T.buffer),u.bufferSubData(u.ARRAY_BUFFER,0,E.bytes),g.state.boundBuffer=T.buffer);T.geometry.drawRange.start=0,T.geometry.drawRange.count=E.indexCount}},Ei={allocMatrix:b=>D(b).transform.matrix,localMatrixChanged:b=>{D(b).transform.worldMatrixNeedsUpdate=!0,He()},parentChanged:(b,E)=>{He();const T=D(b).transform;if(E!==0)T.setParent(D(E).transform);else{const U=ye.sceneOf(b);T.setParent((U&&P.get(U.id))??null)}},sceneCreated:b=>{P.set(b,new vt),L.set(b,new Map)},entitySceneChanged:(b,E,T)=>{He();const U=P.get(E);if(!U)return;const H=D(b);if(T){for(const[j,J]of L){if(j===E)continue;const ie=J.get(b);ie&&(L.get(E).set(b,ie),J.delete(b))}ye.ent(b).parent===0&&H.transform.setParent(U)}else ye.ent(b).parent===0&&H.transform.parent===U&&H.transform.setParent(null)},visibleChanged:(b,E)=>{D(b).transform.visible=E,He()},materialCreated:(b,E,T)=>{_.set(b,k(E.shader,T))},uniformChanged:(b,E,T)=>ee(b,E,T),meshSet:(b,E,T,U)=>{fe(b,E,U,T.kind),He()},glbAttach:(b,E,T)=>we(b,E,T).then(He),morphWeights:(b,E)=>{const T=D(b).transform.weights;T&&T.set(E.subarray(0,Math.min(T.length,E.length)))},entityDestroyed:b=>{He();const E=R.get(b);E&&(E.transform.setParent(null),R.delete(b));for(const T of L.values())T.delete(b)},entityCloned:(b,E)=>{Ge(b,E),He()},subtreeCloned:(b,E,T)=>Qe(T),particleSystemCreated:(b,E)=>{const T=h.get(b);T?(zt(T),T.materialId=E,T.version=0):h.set(b,{materialId:E,mesh:null,geometry:null,buffer:null,version:0,mode:-1})},particlesFrame:(b,E)=>_i(b,E),particleSystemDestroyed:b=>{const E=h.get(b);E&&(zt(E),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,E,T,U=!1)=>{createImageBitmap(b).then(H=>{const j=new Ke(u,{image:H,internalFormat:U?u.RGBA8:u.SRGB8_ALPHA8,format:u.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),J=F++;o.set(J,j),E(J,H.width,H.height)}).catch(T)};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,E,T){ye.methods.createGlb(b,U=>E({id:U}),T)},openScene(b){const E=Pe;ye.methods.openScene(b),Pe=ye.scenes.has(b),t.style.display="block",!E&&Pe&&Be()},closeScene(){t.style.display="none",Pe=!1,ye.methods.closeScene()},launchAR(){throw new Error(Fr)},stopAR(){throw new Error(Fr)},launchVR(b,E,T){T(new Error("VR is not supported on this device"))},stopVR(){},async warmRender(b,E){E()},attachCameraToAR(b,E,T){const U=ye.scenes.get(b);if(U){U.camera=E;for(const H of U.overlays){const j=ye.scenes.get(H);j&&(j.camera=E)}}},getCameraFov(b,E){const T=ye.projectionOf(b).fov;if(E!==1)return T;const U=T*Math.PI/180,H=t.width/Math.max(1,t.height);return 2*Math.atan(Math.tan(U/2)*H)*180/Math.PI},getCameraViewDirection(b,E,T,U){if(!ye.scenes.has(b)){U[0]=0,U[1]=0,U[2]=-1;return}const{dir:H}=tt(b,E,T);U[0]=H[0],U[1]=H[1],U[2]=H[2]},getDisplaySize:()=>Float32Array.of(g.width||t.width,g.height||t.height),createTexture(b,E,T,U=0){const H=(J,ie,de)=>E({id:J},ie,de),j=n(b);j.slice(0,12).arrayBuffer().then(async J=>{const ie=await Nr(()=>import("./index-Bd7pdF7u.js"),__vite__mapDeps([0,1]),import.meta.url);if(!ie.isKtx2Bytes(new Uint8Array(J)))return!1;const de=await j.arrayBuffer(),ue=await ie.transcodeKtx2(u,de),be=ie.ktx2IsSrgb(de);let ge;ue.isCompressedTexture?ge=new Ke(u,{image:ue,internalFormat:be&&ue.srgbInternalFormat?ue.srgbInternalFormat:ue.internalFormat,generateMipmaps:!1,minFilter:ue.length>1?u.LINEAR_MIPMAP_LINEAR:u.LINEAR,flipY:!1}):ge=new Ke(u,{image:ue,internalFormat:be?u.SRGB8_ALPHA8:u.RGBA8,format:u.RGBA,generateMipmaps:!0,flipY:!1,premultiplyAlpha:!1});const ve=F++;return o.set(ve,ge),H(ve,ue.width,ue.height),!0}).then(J=>{J||Ci(j,H,T,(U&1)!==0)},T)},createTexturePixels(b,E,T,U,H){if(b<=0||E<=0||U.length<b*E*T)return{id:4294967295};const j=new Uint8Array(b*E*4);for(let de=0,ue=b*E;de<ue;de++){const be=de*T,ge=de*4;j[ge]=U[be],j[ge+1]=T>=2?U[be+1]:U[be],j[ge+2]=T>=3?U[be+2]:U[be],j[ge+3]=T>=4?U[be+3]:255}const J=new Ke(u,{image:j,width:b,height:E,internalFormat:H?u.SRGB8_ALPHA8:u.RGBA8,format:u.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1,minFilter:u.LINEAR,magFilter:u.LINEAR}),ie=F++;return o.set(ie,J),w.set(ie,{rgba:j,width:b,height:E,channels:T}),{id:ie}},updateTexturePixels(b,E,T,U,H,j){const J=w.get(b),ie=o.get(b);if(!J||!ie)return;const de=J.channels;for(let ue=0;ue<H;ue++){const be=T+ue;if(!(be<0||be>=J.height))for(let ge=0;ge<U;ge++){const ve=E+ge;if(ve<0||ve>=J.width)continue;const _e=(ue*U+ge)*de,Ve=(be*J.width+ve)*4;J.rgba[Ve]=j[_e],J.rgba[Ve+1]=de>=2?j[_e+1]:j[_e],J.rgba[Ve+2]=de>=3?j[_e+2]:j[_e],J.rgba[Ve+3]=de>=4?j[_e+3]:255}}ie.image=J.rgba,ie.needsUpdate=!0},createTextureFromCanvas(b){var H;const E=(H=e.canvasHost)==null?void 0:H.readSurface(b);if(!E)return 0;const T=new Ke(u,{image:new Uint8Array(E.data.buffer.slice(0)),width:E.width,height:E.height,internalFormat:u.SRGB8_ALPHA8,format:u.RGBA,generateMipmaps:!1,flipY:!1}),U=F++;return o.set(U,T),U},updateTextureFromCanvas(b,E){var H;const T=(H=e.canvasHost)==null?void 0:H.readSurface(E),U=o.get(b);!T||!U||(U.image=new Uint8Array(T.data.buffer.slice(0)),U.width=T.width,U.height=T.height,U.needsUpdate=!0)},createMediaPlayerTexture(b){const E=f(b),T=new Ke(u,{generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1});I.push({video:E,texture:T,lastTime:-1});const U=F++;return o.set(U,T),U},setUniformTexture(b,E,T,U,H){ye.methods.setUniformTexture(b,E,T);const j=_.get(b),J=o.get(T);if(!j||!J)return;const ie=[u.CLAMP_TO_EDGE,u.REPEAT,u.MIRRORED_REPEAT];J.wrapS=ie[U]??u.REPEAT,J.wrapT=ie[H]??u.REPEAT,J.needsUpdate=!0,se(j,E).value=J},setMaterial(b,E,T){ye.methods.setMaterial(b,E,T);const U=_.get(E),H=D(b).drawables[T];!U||!H||(H.program=z(U,H),ne(H,U),He())},getMaterial(b,E){const T=D(b).drawables[E];if(!T)return 0;const U=ye.nextMaterialId();return _.set(U,{kind:"gltf",program:T.program,source:T.program._source}),U},setCulling(b,E){for(const T of D(b).drawables)T.frustumCulled=E;He()},setGlbCulling(b,E){const T=U=>{for(const H of D(U).drawables)H.frustumCulled=E;for(const H of ye.ent(U).children)T(H)};T(b),He()},setRenderPriority(b,E){for(const T of D(b).drawables)T.renderOrder=E;He()},setMaterialDepthTest(b,E){const T=_.get(b);if(T)for(const U of Y(T))U.depthTest=E},setMaterialDepthWrite(b,E){const T=_.get(b);if(T)for(const U of Y(T))U.depthWrite=E},setMaterialCulling(b,E){const T=_.get(b);if(T)for(const U of Y(T))U.cullFace=E===0?!1:E===1?u.FRONT:u.BACK},setCastShadows(b,E){ye.methods.setCastShadows(b,E);for(const T of D(b).drawables)T._castShadows=E;He()},setReceiveShadows(b,E){ye.methods.setReceiveShadows(b,E);for(const T of D(b).drawables)T._receiveShadows=E;He()},setGlbShadows(b,E,T){ye.methods.setGlbShadows(b,E,T);const U=H=>{for(const j of D(H).drawables)j._castShadows=E,j._receiveShadows=T;for(const j of ye.ent(H).children)U(j)};U(b),He()},setCastShadowsGlobal(b){B=b},setReceiveShadowsGlobal(b){W=b},setColliderFromMesh(b,E,T){var J;if(T!==0)return;const U=D(E).drawables[0];if(!U)return;const H=U.geometry;if(H.bounds||H.computeBoundingBox(),!H.bounds)return;const j=yt(b)??ye.activeSceneId();(J=L.get(j))==null||J.set(b,{type:"box",center:[(H.bounds.min.x+H.bounds.max.x)/2,(H.bounds.min.y+H.bounds.max.y)/2,(H.bounds.min.z+H.bounds.max.z)/2],extent:[(H.bounds.max.x-H.bounds.min.x)/2,(H.bounds.max.y-H.bounds.min.y)/2,(H.bounds.max.z-H.bounds.min.z)/2]})},setColliderBox(b,E,T,U,H,j,J){var de;const ie=yt(b)??ye.activeSceneId();(de=L.get(ie))==null||de.set(b,{type:"box",center:[E,T,U],extent:[H/2,j/2,J/2]})},setColliderSphere(b,E,T,U,H){var J;const j=yt(b)??ye.activeSceneId();(J=L.get(j))==null||J.set(b,{type:"sphere",center:[E,T,U],radius:H})},createARController(){throw new Error(Fr)},createRootAnchor(){throw new Error(Fr)},createAnchor(){throw new Error(Fr)},_renderNow:()=>Oe(performance.now()),async captureImage(b,E,T){try{Oe(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"}),J=await j.arrayBuffer();E(a(J),"image.png",j.size)}catch{T()}},raycastView:Je,_raycastView:Je,raycastPick(b,E){const T=ye.activeSceneId(),U=ye.scenes.get(T);if(!U||U.camera===void 0)return 0;const H=Je(b,E);if(H!==0)return H;const{origin:j,dir:J}=tt(T,b,E);return je(T,j,J)},computeBoundingBox(b){const E=Float32Array.of(1/0,1/0,1/0,-1/0,-1/0,-1/0),T=[0,0,0],U=(H,j)=>{for(const J of D(H).drawables){const ie=J.geometry;if(ie.bounds||ie.computeBoundingBox(),!(!ie.bounds||!isFinite(ie.bounds.min.x)))for(let de=0;de<8;de++){const ue=de&1?ie.bounds.max.x:ie.bounds.min.x,be=de&2?ie.bounds.max.y:ie.bounds.min.y,ge=de&4?ie.bounds.max.z:ie.bounds.min.z;j?Lt(T,j,ue,be,ge,1):(T[0]=ue,T[1]=be,T[2]=ge);for(let ve=0;ve<3;ve++)T[ve]<E[ve]&&(E[ve]=T[ve]),T[ve]>E[ve+3]&&(E[ve+3]=T[ve])}}for(const J of ye.ent(H).children){const ie=D(J).transform.matrix,de=j?bt(new Float32Array(16),j,ie):Float32Array.from(ie);U(J,de)}};return U(b,null),isFinite(E[0])||E.fill(0),E},stopAllPlayers(){p()},_dumpScene3d:()=>uu(ye),_setWireframeMode(b){Ue=b==="overlay"||b==="only"?b:"off",S.value=Ue==="only"?[.62,.66,.72]:[.05,.06,.08],Ae(),He()},_setBatching(b){for(const E of Zt.values())E.setEnabled(b);Sr=b,He()},_batchStats(){const b=P.get(ye.activeSceneId());return b?St(b).stats():{batches:0,instances:0,visible:0,singles:0}},_editorConnect(b){return O??(O=gc({gl:u,renderer:g,canvas:t,camera:Fe,core:ye,sceneRoots:P,drawablesOf:E=>D(E).drawables,collectMeshes:oe,wireGeometryFor:re,getViewRay:tt,renderScene:te})),O.setHandlers(b),O.api},async createEngine(){},_fetch:r,_getPlayer:f,_createGLTexture(b){const E=new Ke(u,{image:b,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),T=F++;return o.set(T,E),E.update(),{gl:u,glTexture:E.texture,textureId:T}},_projectionOf:b=>ye.projectionOf(b),_setTransparent(b){ke=b},_beforeFrame(b){Ct=b},_presentXR(b,E,T,U){return U!==void 0&&!ye.scenes.has(U)?Promise.reject(new Error(`[viewer-lite] _presentXR: there is no scene ${U}`)):Xe.present(b,E,T,U)},_onResize(b,E,T=1){We=T,g.dpr=T,g.setSize(b,E),Mt=0},_dispose(){var b;Ct=null,Xe.end(),O==null||O.dispose(),O=null,le==null||le.dispose(),le=null,me==null||me.dispose(),me=null;for(const E of Zt.values())E.dispose();Zt.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};
1111
+ `,Uc=(t,e)=>{const r=new oi(t),n=(_,o,h=!1)=>{const m=new ze(t,{vertex:Bc,fragment:_,uniforms:o,transparent:h,depthTest:!1,depthWrite:!1,cullFace:!1});return h&&m.setBlendFunc(t.ONE,t.ONE),m},s=n(Lc,{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 F=m.threshold;const L=Number.isFinite(m.highlight)&&m.highlight>0?1/m.highlight:0;let W=_;const O=D=>{const K=s.uniforms;K.source.value=W,K.uThreshold.value=K.uFireflies.value=F?1:0,K.uInvHighlight.value=L,x(s,D),F=!1,W=D.texture};for(const D of g)O(D);O(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)=>{Lr(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=qe();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,R;for(const P of y){const B=l[(d=P.attributes)==null?void 0:d.POSITION];if(!(!B||!Array.isArray(B.min)||!Array.isArray(B.max)))if(!x||!R)x=[B.min[0],B.min[1],B.min[2]],R=[B.max[0],B.max[1],B.max[2]];else for(let _=0;_<3;_++)x[_]=Math.min(x[_],B.min[_]),R[_]=Math.max(R[_],B.max[_])}M.mesh={primitives:y.length,min:x,max:R}}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 R=(y=(d=l[x.input])==null?void 0:d.max)==null?void 0:y[0];typeof R=="number"&&R>M&&(M=R)}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,wt=(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)}},gt=(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,R=i*v,P=l*v,B=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]=(R+B)*f,h[7]=0,h[8]=(y+_)*p,h[9]=(R-B)*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,R=f+v+x;let P,B,_,o;if(R>0){const h=.5/Math.sqrt(R+1);o=.25/h,P=(M-y)*h,B=(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,B=(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,B=.25*h,_=(y+M)/h}else{const h=2*Math.sqrt(1+x-f-v);o=(p-u)/h,P=(d+g)/h,B=(y+M)/h,_=.25*h}return{t:[e[12],e[13],e[14]],r:[P,B,_,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),gr=19,_t={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)},R={loadClips(o,h,m){const w=t.getBuffer(o),F=w?y(w):0;if(!F){m(new Error("loadClips: not a GLB with animations"));return}h(F)},createClipFromTracks(o,h){return gt(e,o,m=>wt(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 F=e._canimClipName(o,w);m.push({name:F?e.UTF8ToString(F):"",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,F){return e._canimClipsDerive(o,h,m?1:0,w,F)},destroyClipSet(o){e._canimClipsDestroy(o)},animatorCreate(o){if(!t.get(o))return 0;const m=[],w=[],F=[],L=[],W=[],O=(k,z)=>{const Y=t.get(k);if(!Y)return;const se=m.length;m.push(k),w.push(z),F.push(Y.name??""),W.push(Y.skinJoint?1:0);const{t:ee,r:ne,s:fe}=Wr(Y.m);L.push(ee[0],ee[1],ee[2],ne[0],ne[1],ne[2],ne[3],fe[0],fe[1],fe[2]);for(const we of Y.children)O(we,se)};O(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=gt(e,F.join(`
1112
+ `),k=>wt(e,L,z=>e._canimAnimatorCreate(I,D,k,z,K,o)))}finally{e._free(D),e._free(K)}if(!q)return 0;const N=e._canimAnimatorShadowedNames(q);return N>0&&console.warn(`[Animator] ${N} 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,F=h.trs>>2;for(let L=0;L<h.n;L++){if(!w[h.write+L])continue;const W=t.get(h.entities[L]);if(!W)continue;const O=F+L*10;pn(W.m,m[O],m[O+1],m[O+2],m[O+3],m[O+4],m[O+5],m[O+6],m[O+7],m[O+8],m[O+9]),t.localMatrixChanged(h.entities[L])}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){wt(e,m,w=>e._canimClipsSetEvents(o,h,w,m.length))},animatorSetBlend(o,h,m,w,F,L,W,O){const I=m>1?2:1,D=Math.min(w.length,Math.floor(F.length/I)),K=O&&O.length>=D*2?O:null;kc(e,w,q=>wt(e,F,N=>{K?wt(e,K,k=>e._canimAnimatorSetBlend(o,h,I,q,N,k,D,L,W)):e._canimAnimatorSetBlend(o,h,I,q,N,0,D,L,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,F,L,W){e._canimAnimatorPlay(o,h,m?1:0,w,F,L,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,F){gt(e,F??"",L=>e._canimAnimatorSetLayer(o,h,m,w?1:0,L))},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,F]of r){if(!F.entities.includes(o))continue;const L=h.length>>1,W=new Int32Array(L*2);for(let q=0;q<L*2;q++)W[q]=F.entities.indexOf(h[q]);const O=new Float32Array(L*6),I=e._malloc(Math.max(4,L*8));e.HEAP32.set(W,I>>2);const D=e._malloc(Math.max(4,L*24));let K=0;try{K=wt(e,m,q=>e._canimAnimatorJointRanges(w,I,L,q,D)),K>0&&O.set(e.HEAPF32.subarray(D>>2,(D>>2)+L*6))}finally{e._free(I),e._free(D)}return K>0?O:null}return null},animatorSeedPose(o,h){for(const[m,w]of r){if(!w.entities.includes(o))continue;const F=new Float32Array(w.n*10);for(let L=0;L<w.n;L++){const W=t.get(w.entities[L]),{t:O,r:I,s:D}=Wr(W?W.m:Er);F.set([O[0],O[1],O[2],I[0],I[1],I[2],I[3],D[0],D[1],D[2]],L*10)}wt(e,F,L=>e._canimAnimatorSeedPose(m,L,h));return}},animatorSetRootMotion(o,h,m){gt(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){gt(e,h,w=>gt(e,m,F=>e._canimAnimatorSetFeet(o,w,F)))},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 F=e._malloc(w*8*4),L=e._canimAnimatorSlotContacts(o,h,F,w);return m.set(e.HEAPF32.subarray(F>>2,(F>>2)+Math.min(L,w)*8)),e._free(F),L},animatorSlotTreads(o,h,m){if(m.length===0)return e._canimAnimatorSlotTreads(o,h,0,0);const w=e._malloc(m.length*4),F=e._canimAnimatorSlotTreads(o,h,w,m.length);return m.set(e.HEAPF32.subarray(w>>2,(w>>2)+Math.min(F+1,m.length))),e._free(w),F},animatorSlotPhysics(o,h,m,w){const F=e._malloc(44),L=e._canimAnimatorSlotPhysics(o,h,m,F);return L&&w.set(e.HEAPF32.subarray(F>>2,(F>>2)+Math.min(11,w.length))),e._free(F),L},animatorSlotFeatures(o,h,m,w){const F=e._malloc(148),L=e._canimAnimatorSlotFeatures(o,h,m,F);return L&&w.set(e.HEAPF32.subarray(F>>2,(F>>2)+Math.min(37,w.length))),e._free(F),L},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,F){const L=e._canimAnimatorSlotKneePole(o,h,m,w,f);return L&&F.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(6,F.length))),L},animatorSetStepWarp(o,h,m,w,F,L){e._canimAnimatorSetStepWarp(o,h?1:0,m,w,F,L)},animatorSlotFit(o,h,m,w,F){if(F.length===0)return e._canimAnimatorSlotFit(o,h,m,w,0,0);const L=e._malloc(F.length*4),W=e._canimAnimatorSlotFit(o,h,m,w,L,F.length);return F.set(e.HEAPF32.subarray(L>>2,(L>>2)+Math.min(W,F.length))),e._free(L),W},animatorSlotExit(o,h,m,w,F,L){return e._canimAnimatorSlotExit(o,h,m,w,F?1:0,L)},animatorSlotAlign(o,h,m,w,F,L){if(L.length<4)return 0;const W=e._malloc(16),O=e._canimAnimatorSlotAlign(o,h,m,w,F,W);return O&&L.set(e.HEAPF32.subarray(W>>2,(W>>2)+4)),e._free(W),O},setOnAnimatorStep(o){d=o},animatorSetFeetParams(o,h){wt(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 F=w.entities.indexOf(m);if(F<0)return 0;let L=-1,W=-1;if(h===0){const N=((K=t.get(m))==null?void 0:K.parent)??0;if(L=w.entities.indexOf(N),L<0||(W=w.entities.indexOf(((q=t.get(N))==null?void 0:q.parent)??0),W<0))return 0}const O=e._canimAnimatorIkCreateJoints(o,h,W,L,F);if(!O)return 0;const I=new Float32Array(gr),D=e._malloc(gr*4);return e._canimAnimatorIkGet(o,O,D,gr),I.set(e.HEAPF32.subarray(D>>2,(D>>2)+gr)),e._free(D),w.iks.push({ik:O,target:0,pole:0,rotation:0,params:I}),O},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 F;wt(e,m,L=>e._canimAnimatorIkSet(o,h,L,m.length));const w=(F=r.get(o))==null?void 0:F.iks.find(L=>L.ik===h);w&&w.params.set(m.subarray(0,Math.min(m.length,gr)))},animatorIkNodes(o,h,m,w,F){var W;const L=(W=r.get(o))==null?void 0:W.iks.find(O=>O.ik===h);L&&(L.target=m,L.pole=w,L.rotation=F)},animatorIkAnchor(o,h,m){gt(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,F,L){const W=r.get(o);if(!W||!gn(e))return;W.sockets=W.sockets.filter(D=>!(D.set===h&&D.name===m));const O=(D,K)=>{gt(e,h,q=>gt(e,m,N=>{K?wt(e,K,k=>e._canimAnimatorSetSocket(o,q,N,D,k)):e._canimAnimatorSetSocket(o,q,N,D,0)}))};if(F===0&&!L){O(-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}O(I,L??[0,0,0,0,0,0,1]),F!==0&&W.sockets.push({set:h,name:m,node:F})},setClipAnchors(o,h,m,w,F,L){gn(e)&&gt(e,m,W=>gt(e,w??"",O=>gt(e,F??"",I=>wt(e,L,D=>e._canimClipsSetAnchors(o,h,W,O,I,D,Math.floor(L.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){wt(e,h,m=>e._canimAnimatorSetWarpParams(o,m,h.length))}},P=(o,h,m)=>{var q,N;const w=t.get(h.rootId),F=w&&w.parent?t.get(w.parent):void 0,L=F?((q=t.world)==null?void 0:q.call(t,F.id))??F.m:Er;e.HEAPF32.set(L,l>>2),e._canimAnimatorSetWorld(o,l);const W=e._canimAnimatorEvaluate(o,m,0,h.trs,h.write);if(h.feetOn&&w){const k=(((N=t.world)==null?void 0:N.call(t,h.rootId))??w.m)[13];for(let z=0;z<2;z++){if(!e._canimAnimatorFootProbe(o,z,a,c))continue;const Y=e.HEAPF32,se=a>>2;e._canimAnimatorSetGround(o,z,1,Y[se],k,Y[se+2],0,1,0)}}const O=e.HEAPF32,I=e.HEAPU8,D=h.trs>>2;for(let k=0;k<h.n;k++){if(!I[h.write+k])continue;const z=t.get(h.entities[k]);if(!z)continue;const Y=D+k*10;pn(z.m,O[Y],O[Y+1],O[Y+2],O[Y+3],O[Y+4],O[Y+5],O[Y+6],O[Y+7],O[Y+8],O[Y+9]),t.localMatrixChanged(h.entities[k])}if(t.setMorphWeights){const k=e._canimAnimatorMorphCount(o);for(let z=0;z<k;z++){const Y=e._canimAnimatorMorph(o,z,p,g),se=e.HEAP32[p>>2],ee=e.HEAPU32[g>>2];!Y||se<0||ee===0||t.setMorphWeights(h.entities[se],Float32Array.from(e.HEAPF32.subarray(Y>>2,(Y>>2)+ee)))}}const K=e._canimAnimatorRootMotionFrame(o,s);if(K!==0){const k=e.HEAPF32,z=s>>2,Y=k[z],se=k[z+1],ee=k[z+2],ne=k[z+3];let fe=!1;if(K===2&&t.applyRootMotion&&(fe=t.applyRootMotion(h.rootId,Y,se,ee,m,ne)),!fe&&(Y!==0||se!==0||ee!==0||ne!==0)){const we=t.get(h.rootId);if(we){const pe=we.m;ne!==0&&$c(pe,ne);const Ge=pe[0]*Y+pe[4]*se+pe[8]*ee,Qe=pe[1]*Y+pe[5]*se+pe[9]*ee,Ue=pe[2]*Y+pe[6]*se+pe[10]*ee;pe[12]+=Ge,pe[13]+=Qe,pe[14]+=Ue,t.localMatrixChanged(h.rootId)}}}if(d){const k=e._canimAnimatorStepCount(o);for(let z=0;z<k;z++){const Y=e._canimAnimatorStep(o,z,i);if(Y<0)continue;const se=e.HEAPF32,ee=i>>2,ne=se[ee],fe=se[ee+1],we=se[ee+2],pe=L;M.push({id:o,side:Y,x:pe[0]*ne+pe[4]*fe+pe[8]*we+pe[12],y:pe[1]*ne+pe[5]*fe+pe[9]*we+pe[13],z:pe[2]*ne+pe[6]*fe+pe[10]*we+pe[14]})}}if(W>0){const k=e._canimAnimatorEvents(o,u,$s),z=e.HEAPU16,Y=u>>1;for(let se=0;se<k;se++)v.push({id:o,slot:z[Y+se*2],type:z[Y+se*2+1]})}},B=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?B(m.parent)??Er:Er;for(const O of h.iks){if(!O.target&&!O.pole&&!O.rotation)continue;const I=O.target?B(O.target):void 0;I&&(O.params[_t.TARGET_X]=I[12],O.params[_t.TARGET_X+1]=I[13],O.params[_t.TARGET_X+2]=I[14]);const D=O.pole?B(O.pole):void 0;D&&(O.params[_t.POLE_X]=D[12],O.params[_t.POLE_X+1]=D[13],O.params[_t.POLE_X+2]=D[14],O.params[_t.HAS_POLE]=1);const K=O.rotation?B(O.rotation):void 0;if(K){const q=Wr(K).r;O.params[_t.ROT_X]=q[0],O.params[_t.ROT_X+1]=q[1],O.params[_t.ROT_X+2]=q[2],O.params[_t.ROT_X+3]=q[3]}wt(e,O.params,q=>e._canimAnimatorIkSet(o,O.ik,q,gr))}for(const O of h.sockets){const I=B(O.node);I&&(e.HEAPF32.set(I,l>>2),gt(e,O.set,D=>gt(e,O.name,K=>e._canimAnimatorSocketSetWorld(o,D,K,l))))}const F=e.HEAPF32,L=h.trs>>2;for(let O=0;O<h.n;O++){const I=t.get(h.entities[O]),{t:D,r:K,s:q}=Wr(I?I.m:Er),N=L+O*10;F[N]=D[0],F[N+1]=D[1],F[N+2]=D[2],F[N+3]=K[0],F[N+4]=K[1],F[N+5]=K[2],F[N+6]=K[3],F[N+7]=q[0],F[N+8]=q[1],F[N+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 O=0;O<h.n;O++){if(!W[h.write+O])continue;const I=t.get(h.entities[O]);if(!I)continue;const D=L+O*10;pn(I.m,F[D],F[D+1],F[D+2],F[D+3],F[D+4],F[D+5],F[D+6],F[D+7],F[D+8],F[D+9]),t.localMatrixChanged(h.entities[O])}};return{methods:R,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,R,P)=>(d&&(i.set(d,y),t.ent(y).physics={motion:Xs[x]??x,mass:R,shape:P}),d),v={...n,physicsHasSupport:()=>Es(),physicsConfigure(d,y,x,R){f={gravity:[d,y,x],maxBodies:R},n.physicsConfigure(d,y,x,R)},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,R,P,B)=>p(n.physicsBuildMesh(d,y,x,R,P,B),{type:x?"convexHull":"mesh",vertices:d.length/3,triangles:Math.floor(y.length/3),scale:[R,P,B]}),physicsBuildMeshFromEntity:(d,y,x,R,P)=>p(n.physicsBuildMeshFromEntity(d,y,x,R,P),{type:y?"convexHull":"mesh",source:d,scale:[x,R,P]}),physicsBuildHeightField(d,y,x,R,P,B,_,o){let h=0;if(P)for(let m=0;m<P.length;m++)P[m]&&h++;return p(n.physicsBuildHeightField(d,y,x,R,P,B,_,o),{type:"heightfield",size:[y,x],cellSize:R,samples:d.length,holes:h,scale:[B,_,o]})},physicsSetShapeOrigin(d,y,x,R){const P=s.get(d);P&&(y===0&&x===0&&R===0?delete P.origin:P.origin=[y,x,R]),n.physicsSetShapeOrigin(d,y,x,R)},physicsSetBodyShape(d,y,x){const R=g(i,d);R&&(R.shape=s.get(y)),n.physicsSetBodyShape(d,y,x)},physicsDestroyShape(d){s.delete(d),n.physicsDestroyShape(d)},physicsCreateBody(d,y,x,R,P,B){const _=n.physicsCreateBody(d,y,x,R,P,B);return _&&(i.set(_,d),t.ent(d).physics={motion:Xs[x]??x,mass:R,...P&&{sensor:P},...B&&{pickOnly:B},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,R,P,B)=>u(n.physicsCreateBox(d,y,x,R,P,B),d,P,B,{type:"box",size:[y*2,x*2,R*2]}),physicsCreateSphere:(d,y,x,R)=>u(n.physicsCreateSphere(d,y,x,R),d,x,R,{type:"sphere",radius:y}),physicsCreateCylinder:(d,y,x,R,P)=>u(n.physicsCreateCylinder(d,y,x,R,P),d,R,P,{type:"cylinder",height:y*2,radius:x}),characterCreate(d,y,x){const R=n.characterCreate(d,y,x);return R&&(l.set(R,d),t.ent(d).physics={character:!0,maxSlopeDeg:x,shape:s.get(y)}),R},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 R=g(l,d);R&&(R.shape=s.get(y))}return x},vehicleCreate(d,y,x){const R=n.vehicleCreate(d,y,x);if(!R)return 0;const P=x[Qc]??0,B=x[js]??0;let _=Fn+B*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(R,d),t.ent(d).physics={motion:"dynamic",mass:x[1],vehicle:!0,...qs(x,B),wheels:o,shape:s.get(y)},R},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 R=n.ragdollCreate(d,y,x);if(!R)return 0;const P=16,B=x[1]??0,_=x[2]??12,o=[];for(let h=0;h<B;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(R,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},R},ragdollDestroy(d){c.delete(d),n.ragdollDestroy(d)},ragdollActivate(d,y,x,R){const P=n.ragdollActivate(d,y,x,R),B=c.get(d),_=B===void 0?void 0:t.ent(B).ragdoll;return P&&_&&(_.active=!0,_.launch=[y,x,R]),P},ragdollDeactivate(d,y){const x=c.get(d),R=x===void 0?void 0:t.ent(x).ragdoll;R&&(R.active=!1,delete R.launch,y>0&&(R.blendOut=y)),n.ragdollDeactivate(d,y)},ragdollSetDrive(d,y,x){const R=c.get(d),P=R===void 0?void 0:t.ent(R).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,R,P)=>e?e.applyRootMotion(d,y,x,R,P):!1,config:()=>f}},kt={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,R)=>x===d[R])?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,Wt=(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,C,G,Z,re,ce,Ae,Te,Fe,Pe)=>W(S,ci([A,C,G],[Z,re,ce,Ae],[Te,Fe,Pe])),setWorldPosition:(S,A,C,G)=>O(S,A,C,G),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,C;return(C=(A=l.get(S))==null?void 0:A.model)==null?void 0:C.buffer},seedAnimator:(S,A)=>P.methods.animatorSeedPose(S,A),jointRanges:(S,A,C)=>P.methods.animatorJointRanges(S,A,C)}),R=su({ent:S=>o(S),world:S=>m(S),cameraPosition:()=>{var C;const S=(C=a.get(v))==null?void 0:C.camera;if(S===void 0)return null;const A=h(S);return[A[12],A[13],A[14]]},created:(S,A)=>{var C;return(C=t.particleSystemCreated)==null?void 0:C.call(t,S,A)},frame:(S,A)=>{var C;return(C=t.particlesFrame)==null?void 0:C.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 C;return(C=t.morphWeights)==null?void 0:C.call(t,S,A)},applyRootMotion:(S,A,C,G,Z,re)=>{const ce=m(S);return x.applyRootMotion(S,ce[0]*A+ce[4]*C+ce[8]*G,ce[2]*A+ce[6]*C+ce[10]*G,Z,re)}}),B=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)&&Wt(A.m,qe()),l.set(S,A),A},_=()=>B(p++),o=S=>{let A=l.get(S);return A||(A=B(S),S>=p&&(p=S+1)),A},h=S=>{const A=o(S);return A.parent===0?A.m:bt(new Float32Array(16),h(A.parent),A.m)},m=S=>{const A=h(S);return A instanceof Float32Array?A:Float32Array.from(A)},w=S=>{var Fe;const A=h(S),[C,G,Z]=((Fe=o(S).light)==null?void 0:Fe.direction)??[0,0,-1],re=A[0]*C+A[4]*G+A[8]*Z,ce=A[1]*C+A[5]*G+A[9]*Z,Ae=A[2]*C+A[6]*G+A[10]*Z,Te=Math.hypot(re,ce,Ae)||1;return[re/Te,ce/Te,Ae/Te]},F=S=>{if(S.parent!==0){const A=l.get(S.parent);A&&(A.children=A.children.filter(C=>C!==S.id)),S.parent=0}},L=(S,A,C)=>{var Z,re;const G=o(S);if(G.parent!==A){if(C){const ce=m(S),Ae=A===0?ce:bt(new Float32Array(16),Lt(m(A)),ce);Wt(G.m,Ae)}F(G),A!==0&&(G.parent=A,o(A).children.push(S)),(Z=t.parentChanged)==null||Z.call(t,S,A),(re=t.localMatrixChanged)==null||re.call(t,S)}},W=(S,A)=>{var G;const C=o(S);Wt(C.m,C.parent===0?A:bt(new Float32Array(16),Lt(m(C.parent)),A)),(G=t.localMatrixChanged)==null||G.call(t,S)},O=(S,A,C,G)=>{var ce;const Z=o(S),re=Z.m;if(Z.parent===0)re[12]=A,re[13]=C,re[14]=G;else{const Ae=Lt(m(Z.parent));re[12]=Ae[0]*A+Ae[4]*C+Ae[8]*G+Ae[12],re[13]=Ae[1]*A+Ae[5]*C+Ae[9]*G+Ae[13],re[14]=Ae[2]*A+Ae[6]*C+Ae[10]*G+Ae[14]}(ce=t.localMatrixChanged)==null||ce.call(t,S)},I=S=>{const A=a.get(S),C=(A==null?void 0:A.overlayOf)!==void 0?a.get(A.overlayOf):A;return(C==null?void 0:C.customProjection)??(C==null?void 0:C.projection)??i},D=S=>{for(let A=S;A!==0;){for(const C of a.values())if(C.entities.has(A))return C;A=o(A).parent}return null},K=S=>{var Z;const A=(Z=e.getSourceName)==null?void 0:Z.call(e,S);if(!A)return;const C=A.startsWith("lecodesfile://")?decodeURIComponent(A.slice(14)):A;return(C.includes("/")||C.includes("\\"))&&!C.startsWith("http")?C.split(/[\\/]/).pop()??C:C},q=S=>{let A=c.get(S);return A||(A={shader:"unknown",uniforms:{}},c.set(S,A)),A},N=(S,A,C)=>{var G;q(S).uniforms[A]=C,(G=t.uniformChanged)==null||G.call(t,S,A,C)},k=S=>{const A=e.getBuffer(S),C=A?Gc(A):null,G=_();if(G.model={source:K(S),systemId:S,animations:(C==null?void 0:C.animations)??[],loaded:C!==null,...A&&{buffer:A}},C&&C.animations.length>0&&A&&bi()&&(G.model.clipSet=P.registerGlbClips(A)),!C)return{rootId:G.id,entIds:[]};const Z=C.nodes.map(()=>_().id);C.nodes.forEach((re,ce)=>{var Te;const Ae=o(Z[ce]);Ae.name=re.name??"",Wt(Ae.m,re.matrix),(Te=t.localMatrixChanged)==null||Te.call(t,Ae.id),re.skinJoint&&(Ae.skinJoint=!0),re.mesh&&(Ae.mesh={kind:0,vertexCount:0,primitives:re.mesh.primitives},re.mesh.min&&re.mesh.max&&(Ae.mesh.size=[re.mesh.max[0]-re.mesh.min[0],re.mesh.max[1]-re.mesh.min[1],re.mesh.max[2]-re.mesh.min[2]],Ae.mesh.center=[(re.mesh.max[0]+re.mesh.min[0])/2,(re.mesh.max[1]+re.mesh.min[1])/2,(re.mesh.max[2]+re.mesh.min[2])/2]));for(const Fe of re.children)L(Z[Fe],Ae.id,!1)});for(const re of C.roots)L(Z[re],G.id,!1);return{rootId:G.id,entIds:Z}},z=(S,A)=>{var Z,re;const C=o(S),G=_();A.set(C.id,G.id),G.name=C.name,Wt(G.m,C.m),G.visible=C.visible,C.skinJoint&&(G.skinJoint=!0),C.light&&(G.light={...C.light}),C.punctual&&(G.punctual={...C.punctual}),C.mesh&&(G.mesh={...C.mesh}),G.materials=[...C.materials],C.model&&(G.model={...C.model,animations:C.model.animations}),C.castShadows!==void 0&&(G.castShadows=C.castShadows),C.receiveShadows!==void 0&&(G.receiveShadows=C.receiveShadows),C.particles&&(G.particles=structuredClone(C.particles)),C.physics&&(G.physics=structuredClone(C.physics)),C.collider&&(G.collider=structuredClone(C.collider)),(Z=t.localMatrixChanged)==null||Z.call(t,G.id),(re=t.entityCloned)==null||re.call(t,C.id,G.id);for(const ce of C.children)L(z(ce,A),G.id,!1);return G.id},Y=S=>{var C;const A=l.get(S);if(A){for(const G of[...A.children])Y(G);F(A);for(const G of a.values())G.entities.delete(S);(C=t.entityDestroyed)==null||C.call(t,S),P.onEntityDestroyed(S),R.onEntityDestroyed(S),l.delete(S)}},se=S=>{for(let A=S;A!==0;A=o(A).parent)if(!o(A).visible)return!1;return!0};let ee=1;const ne=S=>{const A=S*ee;M==null||M(S),x.frame(A,y),P.evaluate(A),x.syncRagdolls(A),d==null||d(S),P.lateSolve(),R.update(A)},fe=S=>{const A=Math.min(1e3,Math.floor(S/16));for(let C=0;C<A;C++)ne(.016)},we=()=>v>=0||a.size>0,pe=()=>v,Ge={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 C,G;const A=a.size;return a.set(A,{id:A,entities:new Set,overlays:[],overlayOf:S}),(C=a.get(S))==null||C.overlays.push(A),(G=t.sceneCreated)==null||G.call(t,A),A},createGLView(){},openScene(S){v=S},closeScene(){v=-1},addEntityToScene(S,A){var G;const C=a.get(S);if(C){for(const Z of a.values())Z!==C&&Z.entities.delete(A);C.entities.add(A),(G=t.entitySceneChanged)==null||G.call(t,A,S,!0)}},removeEntityFromScene(S,A){var G;const C=a.get(S);C&&(C.entities.delete(A),(G=t.entitySceneChanged)==null||G.call(t,A,S,!1))},createEntity:()=>_().id,cloneEntity(S){var Z,re;const A=o(S),C=new Map,G=z(S,C);if(A.parent!==0)L(G,A.parent,!1);else{const ce=D(S);ce&&(ce.entities.add(G),(Z=t.entitySceneChanged)==null||Z.call(t,G,ce.id,!0))}return(re=t.subtreeCloned)==null||re.call(t,S,G,C),G},destroyEntity(S){Y(S)},setMatrix(S,A){var G;const C=o(S);Wt(C.m,A),(G=t.localMatrixChanged)==null||G.call(t,S)},setWorldMatrix(S,A){var Z,re;const C=o(S);if(C.parent===0){Wt(C.m,A),(Z=t.localMatrixChanged)==null||Z.call(t,S);return}const G=bt(new Float32Array(16),Lt(m(C.parent)),Float32Array.from(A.subarray(0,16)));Wt(C.m,G),(re=t.localMatrixChanged)==null||re.call(t,S)},getChildCount:S=>o(S).children.length,getChild:(S,A)=>o(S).children[A]??0,setPosition(S,A,C,G){var re;const Z=o(S).m;Z[12]=A,Z[13]=C,Z[14]=G,(re=t.localMatrixChanged)==null||re.call(t,S)},setQuaternion(S,A,C,G,Z){var re;ai(o(S).m,A,C,G,Z),(re=t.localMatrixChanged)==null||re.call(t,S)},setEulerAngles(S,A,C,G,Z){var re;ja(o(S).m,A,C,G,Z),(re=t.localMatrixChanged)==null||re.call(t,S)},setScale(S,A,C,G){var Z;li(o(S).m,A,C,G),(Z=t.localMatrixChanged)==null||Z.call(t,S)},setParent(S,A,C){L(S,A,C)},setParentNull(S,A){L(S,0,A)},getParent:S=>o(S).parent,traverse(S,A){const C=G=>{A(G);for(const Z of o(G).children)C(Z)};for(const G of o(S).children)C(G)},findNode(S,A){const C=Ai(A);let G=0,Z=4;const re=ce=>{const Ae=o(ce),Te=iu(Ae.name,!!Ae.skinJoint,A,C);Te<Z&&Te>=0&&(G=ce,Z=Te);for(const Fe of Ae.children){if(Z===0)return;re(Fe)}};for(const ce of o(S).children){if(Z===0)break;re(ce)}return G},createSunLight(S,A,C,G,Z,re,ce,Ae=100,Te=1){o(S).light={direction:[A,C,G],intensity:Z,color:re,shadowsQuality:ce,shadowDistance:Ae,shadowCascades:Te}},createPointLight(S,A,C,G,Z){o(S).punctual={type:"point",intensity:A,color:C,range:G>0?G:1,inner:0,outer:0,castShadows:Z}},createSpotLight(S,A,C,G,Z,re,ce){const[Ae,Te]=Ys(Z,re);o(S).punctual={type:"spot",intensity:A,color:C,range:G>0?G:1,inner:Ae,outer:Te,castShadows:ce}},setLightCone(S,A,C){var Z;const G=(Z=l.get(S))==null?void 0:Z.punctual;(G==null?void 0:G.type)==="spot"&&([G.inner,G.outer]=Ys(A,C))},setLightIntensity(S,A){const C=l.get(S);C!=null&&C.light&&(C.light.intensity=A),C!=null&&C.punctual&&(C.punctual.intensity=A)},setLightColor(S,A){const C=l.get(S);C!=null&&C.light&&(C.light.color=A),C!=null&&C.punctual&&(C.punctual.color=A)},setDefaultIbl(S,A){const C=a.get(S);C&&(C.ibl=A)},setBloomOptions(S,A,C,G,Z,re,ce,Ae,Te,Fe){const Pe=a.get(S);Pe&&(Pe.bloom=A?{strength:C,threshold:G,highlight:Z,levels:re,quality:ce}:void 0)},setSkybox(S,A){const C=a.get(S);C&&(C.skybox=A)},setSceneMultiSampleAntiAliasing(S,A){const C=a.get(S);C&&(C.antialias=A)},setSceneRenderOptions(){},setMaterialGlobalParameter(){},getCameraFov(S,A){const{fov:C}=I(S);if(A!==1)return C;const G=C*Math.PI/180;return 2*Math.atan(Math.tan(G/2)*(r/n))*180/Math.PI},setCameraProjection(S,A,C,G){const Z=a.get(S);Z&&(Z.projection={fov:A,near:C,far:G})},setCameraMatrix(S,A){var G;const C=(G=a.get(S))==null?void 0:G.camera;C&&Ge.setWorldMatrix(C,A)},setCameraProjectionMatrix(S,A,C,G){const Z=a.get(S);if(!Z||A.length<16)return;const re=Float32Array.from(A.subarray(0,16)),ce=re[5]>0?2*Math.atan(1/re[5])*180/Math.PI:(Z.projection??i).fov;Z.customProjection={fov:ce,near:C,far:G,matrix:re}},clearCameraProjectionMatrix(S){const A=a.get(S);A&&delete A.customProjection},getMatrix(S,A){return A.set(Qe(S)),!0},getWorldMatrix(S,A){A.set(m(S))},getWorldPosition(S,A){const C=h(S);A[0]=C[12],A[1]=C[13],A[2]=C[14]},getWorldDirection(S,A,C){const G=h(S);C[0]=G[A*4],C[1]=G[A*4+1],C[2]=G[A*4+2]},getWorldMatrixInverse(S,A){A.set(Lt(m(S)))},getCameraViewDirection(S,A,C,G){var at;const Z=(at=a.get(S))==null?void 0:at.camera,re=Z?h(Z):qe(),[ce,Ae]=ui(I(S),r/n,A/r*2-1,1-C/n*2),Te=re[0]*ce+re[4]*Ae-re[8],Fe=re[1]*ce+re[5]*Ae-re[9],Pe=re[2]*ce+re[6]*Ae-re[10],ke=Math.hypot(Te,Fe,Pe)||1;G[0]=Te/ke,G[1]=Fe/ke,G[2]=Pe/ke},setMesh(S,A,C,G,Z,re,ce,Ae,Te){var Ot;const Fe=o(S);let Pe=1/0,ke=1/0,at=1/0,Mt=-1/0,Nt=-1/0,Et=-1/0;for(let We=0;We+2<C.length;We+=3){const ht=C[We],It=C[We+1],Ft=C[We+2];ht<Pe&&(Pe=ht),ht>Mt&&(Mt=ht),It<ke&&(ke=It),It>Nt&&(Nt=It),Ft<at&&(at=Ft),Ft>Et&&(Et=Ft)}const Qt=C.length>=3,Ct={kind:ce,vertexCount:Math.floor(C.length/3),size:Qt?[Mt-Pe,Nt-ke,Et-at]:void 0,center:Qt?[(Mt+Pe)/2,(Nt+ke)/2,(Et+at)/2]:void 0};Fe.mesh=Ct,Fe.materials[0]=A,(Ot=t.meshSet)==null||Ot.call(t,S,A,Ct,{vertices:C,normals:G,indices:Z,uv:re,colors:Te})},setCulling(){},setRenderPriority(){},setMaterialDepthTest(){},setMaterialDepthWrite(){},setMaterialCulling(){},setMaterialStencil(){},setSceneStencil(){},setCastShadows(S,A){o(S).castShadows=A},setReceiveShadows(S,A){o(S).receiveShadows=A},setGlbShadows(S,A,C){const G=Z=>{const re=o(Z);re.castShadows=A,re.receiveShadows=C;for(const ce of re.children)G(ce)};G(S)},setCastShadowsGlobal(){},setReceiveShadowsGlobal(){},hasMesh:S=>o(S).mesh!==void 0,createMaterial(S){var G;const A=g++,C={shader:K(S)??"unknown",uniforms:{}};return c.set(A,C),(G=t.materialCreated)==null||G.call(t,A,C,S),A},createMaterialNamed(S){var G;const A=g++,C={shader:S,uniforms:{}};return c.set(A,C),(G=t.materialCreated)==null||G.call(t,A,C),A},setMaterial(S,A,C){o(S).materials[C]=A},getMaterial:(S,A)=>o(S).materials[A]??0,setUniformRgb(S,A,C){N(S,A,{kind:"rgb",v:C})},setUniformRgba(S,A,C){N(S,A,{kind:"rgba",v:C})},setUniformFloat(S,A,C){N(S,A,{kind:"float",v:C})},setUniformBoolean(S,A,C){N(S,A,{kind:"bool",v:C})},setUniformTexture(S,A,C){N(S,A,{kind:"texture",v:C})},setUniformArray(S,A,C){N(S,A,{kind:"array",v:Array.from(C)})},setUniformNull(S,A){N(S,A,{kind:"null"})},createTexture(S,A,C){const G=e.getBuffer(S);if(!G||G.byteLength===0){C();return}const[Z,re]=au(G),ce=u++;f.set(ce,{source:K(S),width:Z,height:re}),A(ce,Z,re)},createTextureFromCanvas(S){const A=u++;return f.set(A,{source:`canvas#${S}`,width:0,height:0}),A},updateTextureFromCanvas(){},createTexturePixels(S,A,C){const G=u++;return f.set(G,{source:`pixels ${S}x${A}x${C}`,width:S,height:A}),G},updateTexturePixels(){},createMediaPlayerTexture(S){const A=u++;return f.set(A,{source:`mediaplayer#${S}`,width:0,height:0}),A},attachCameraToAR(S,A,C){const G=a.get(S);G&&(G.camera=A);const Z=I(S);C(Z.matrix?Float32Array.from(Z.matrix):Sn(Z.fov,r/n,Z.near,Z.far),Z.fov)},getDisplaySize:()=>Float32Array.of(r,n),setVisible(S,A){var G;o(S).visible=A,(G=t.visibleChanged)==null||G.call(t,S,A);const C=Z=>{const re=o(Z);re.particles&&R.setVisible(Z,se(Z));for(const ce of re.children)C(ce)};C(S)},isVisible:S=>se(S),getName:S=>o(S).name,setName(S,A){o(S).name=A},createGlb(S,A,C){const{rootId:G,entIds:Z}=k(S);if(!t.glbAttach){A(G);return}Promise.resolve(t.glbAttach(S,G,Z)).then(()=>A(G)).catch(re=>C==null?void 0:C(re))},setGlbCulling(){},getGlbClipSet:S=>{var A,C;return((C=(A=l.get(S))==null?void 0:A.model)==null?void 0:C.clipSet)??0},...P.methods,setEarlyUpdate(S){M=S},setLateUpdate(S){d=S},setFixedUpdate(S){y=S},setTimeScale(S){ee=Number.isFinite(S)&&S>0?S:0},...x.methods,...R.methods};function Qe(S){const A=o(S).m;return A instanceof Float32Array?A:Float32Array.from(A)}let Ue=null;return{width:r,height:n,fov:s,entities:l,scenes:a,materials:c,textures:f,cameraOverride:()=>Ue,setCameraOverride:S=>{Ue=S},ent:o,newEnt:_,worldMatrix:h,worldMatrixF:m,sunDirection:w,sourceName:K,setParentInternal:L,sceneOf:D,projectionOf:I,rebindMatrix:(S,A)=>{o(S).m=A},methods:Ge,simulate:fe,tick:ne,hasActiveScene:we,activeSceneId:pe,physicsConfig:x.config,particleIndexPattern:R.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]},$t=(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=bt(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],F=u[1]*_+u[5]*o+u[9]*h+u[13],L=m>1e-4;return L?{sx:(w/m*.5+.5)*s,sy:(1-(F/m*.5+.5))*i,cw:m,inFront:L}:{sx:0,sy:0,cw:m,inFront:L}},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=[],R=_=>{if(!(y.has(_)||!t.entities.has(_))){y.add(_),x.push(_);for(const o of t.ent(_).children)R(o)}};for(const _ of d)for(const o of _.entities)R(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 C=t.worldMatrixF(_);m=[[C[12],C[13],C[14]]]}if(m.length===0)continue;let w=1/0,F=1/0,L=1/0,W=-1/0,O=-1/0,I=-1/0;for(const C of m)C[0]<w&&(w=C[0]),C[0]>W&&(W=C[0]),C[1]<F&&(F=C[1]),C[1]>O&&(O=C[1]),C[2]<L&&(L=C[2]),C[2]>I&&(I=C[2]);const D=v((w+W)/2,(F+O)/2,(L+I)/2);let K=!1,q=!1,N=1/0,k=1/0,z=-1/0,Y=-1/0;for(const C of m){const G=v(C[0],C[1],C[2]);if(!G.inFront){K=!0;continue}q=!0,G.sx<N&&(N=G.sx),G.sx>z&&(z=G.sx),G.sy<k&&(k=G.sy),G.sy>Y&&(Y=G.sy)}const se={kind:h,depth:$t(D.cw,3),coverage:0};if(o.name&&(se.name=o.name),!q){se.behindCamera=!0,P.push({obj:se,id:_});continue}const ee=N,ne=k,fe=Math.max(0,z-N),we=Math.max(0,Y-k);se.rect=[$t(ee,1),$t(ne,1),$t(fe,1),$t(we,1)],D.inFront&&(se.center=[$t(D.sx,1),$t(D.sy,1)]);const pe=Math.max(0,ee),Ge=Math.max(0,ne),Qe=Math.min(s,ee+fe),Ue=Math.min(i,ne+we),S=Math.max(0,Qe-pe)*Math.max(0,Ue-Ge);se.coverage=$t(S/(s*i),4);const A=ee>=0&&ne>=0&&ee+fe<=s&&ne+we<=i;S===0?se.offscreen=!0:(K||!A)&&(se.clipped=!0),P.push({obj:se,id:_})}const B=_=>{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=B(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 Xt=(t,e=4)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},nr=(t,e=4)=>Array.from(t,r=>Xt(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,R]of Object.entries(d.uniforms))y[x]=a(R);return y},f=M=>{var o;const d=t.ent(M),y=d.m,x=nr([y[12],y[13],y[14]]),R=ys(y).map(h=>Xt(h,2)),P=Or(y).map(h=>Xt(h,4)),B=d.light||d.punctual?"light":d.model?"model":d.mesh?"mesh":d.particles?"particles":"node",_={};if(d.name&&(_.name=d.name),_.kind=B,x.some(h=>h!==0)&&(_.position=x),R.some(h=>h!==0)&&(_.rotation=R),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=nr(d.mesh.size)),(o=d.mesh.center)!=null&&o.some(w=>Xt(w)!==0)&&(h.center=nr(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:Xt(h.duration,2)}))}),d.light&&(_.light={type:"sun",direction:nr(t.sunDirection(M)),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:Xt(h.outer*360/Math.PI,2),innerAngle:Xt(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 B=t.ent(P).parent;B!==0;B=t.ent(B).parent)if(M.entities.has(B))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 R=t.cameraOverride();if(R)x.camera={position:nr(R.eye),lookAt:nr(R.target),fov:R.fov??t.projectionOf(M.id).fov,inspection:!0};else if(M.camera!==void 0&&r.has(M.camera)){const P=l(M.camera),B=ys(P).map(_=>Xt(_,2));x.camera={position:nr([P[12],P[13],P[14]]),...B.some(_=>_!==0)&&{rotation:B},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 Bn;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:((Bn=e.preloads)==null?void 0:Bn.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:qe()},exposure:{value:Qa},punctualCount:{value:0},punctualPos:{value:new Array(sr*4).fill(0)},punctualColor:{value:new Array(sr*4).fill(0)},punctualDir:{value:new Array(sr*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 R=new Map,P=new Map,B=new Map,_=new Map,o=new Map,h=new Map,m={value:1},w=new Map;let F=1,L=!0,W=!0,O=null;const I=[],D=b=>{let E=R.get(b);if(!E){const T=new vt;T.matrixAutoUpdate=!1,T._entId=b,E={transform:T,drawables:[]},R.set(b,E)}return E},K=(b,E=!1)=>{let T,U=null;if(b==="lit")U=el,T=new ze(u,{vertex:tr,fragment:U,uniforms:{...d,baseColor:{value:[1,1,1]},baseColorMap:{value:v},roughness:{value:0},metallic:{value:0},emissive:{value:[0,0,0]},emissiveNits:{value:0},emissiveBake:{value:1}}});else if(b==="terrain")U=tl,T=new ze(u,{vertex:tr,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,T=new ze(u,{vertex:tr,fragment:U,uniforms:{baseColorMap:{value:v},shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap}});else if(b==="shadow")U=il,T=new ze(u,{vertex:tr,fragment:U,uniforms:{...d,color:{value:[0,0,0,.66]}},transparent:!0}),T.setBlendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA);else if(b==="particles"||b==="particles-quad"){const H=b==="particles-quad";T=new ze(u,{vertex:H?fl:ul,fragment:H?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,...H?{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}),T.setBlendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA)}else U=E?nl:rl,T=new ze(u,{vertex:tr,fragment:U,uniforms:{baseColor:{value:[1,1,1,1]},baseColorMap:{value:v},shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap},transparent:E}),E&&T.setBlendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA);return U===null?{kind:b,program:T}:{kind:b,program:T,source:q(U)}},q=b=>({fragment:()=>b,vertex:""}),N=b=>{const E=Pl(s(b));if(!E)return null;if(E.unsupported)return console.warn(`[viewer-lite] custom material not supported in lite (${E.unsupported}) — rendering unlit`),null;E.hasVertexBlock&&console.warn("[viewer-lite] custom material has a vertex{} block — the custom vertex stage is ignored in lite");const T=Ol(E);if(!T)return null;const U=T.needsSceneUniforms?{...d,userTime:y}:{shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap,userTime:y};for(const J of T.uniforms)U[J.key]={value:J.value==="texture"?v:J.value};const H=E.blending==="opaque"||E.blending==="masked",j=new ze(u,{vertex:tr,fragment:T.fragment,uniforms:U,transparent:!H,cullFace:E.doubleSided||E.culling==="none"?!1:E.culling==="front"?u.FRONT:u.BACK,depthWrite:E.depthWrite});return u.getProgramParameter(j.program,u.LINK_STATUS)?(H||j.setBlendFunc(u.ONE,E.blending==="add"?u.ONE:u.ONE_MINUS_SRC_ALPHA),{kind:"custom",program:j,source:q(T.fragment),customParams:T.paramNames}):(console.warn("[viewer-lite] custom material failed to compile — rendering unlit"),null)},k=(b,E)=>{const T=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(T==="unknown"&&E!==void 0){const U=N(E);if(U)return U;console.warn(`[viewer-lite] custom shader can't run here (material "${b||E}") — rendering unlit`)}return K(T,b.startsWith("unlit-transparent"))},z=(b,E)=>{if(!b.source)return b.program;const T=gi(E);if(T===b.source.vertex)return b.program;b.variants??(b.variants=new Map);let U=b.variants.get(T);if(U===void 0){const H=b.program,j=new ze(u,{vertex:_n(T),fragment:b.source.fragment(T),uniforms:H.uniforms,transparent:H.transparent,cullFace:H.cullFace,frontFace:H.frontFace,depthTest:H.depthTest,depthWrite:H.depthWrite,depthFunc:H.depthFunc});j.blendFunc={...H.blendFunc},j.blendEquation={...H.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 [${T}] — the mesh is drawn with its base program`)),b.variants.set(T,U)}return U??b.program},Y=b=>{const E=[b.program];if(b.variants)for(const T of b.variants.values())T&&E.push(T);return E},se=(b,E)=>{var H;const T=b.kind==="gltf"?mu[E]??E:(H=b.customParams)!=null&&H.has(E)?`materialParams_${E}`:E,U=b.program.uniforms;return U[T]||(U[T]={value:0}),U[T]},ee=(b,E,T)=>{const U=_.get(b);if(!U)return;if(E==="useBaseColorMap"&&(U.kind==="lit"||U.kind==="unlit")){if(T.kind==="bool"&&!T.v){const j=se(U,"baseColorMap");j.value instanceof Ke&&(j.value=v)}return}const H=se(U,E);switch(T.kind){case"rgb":{const[j,J,ie]=ll(T.v);Array.isArray(H.value)&&H.value.length===4?H.value=[j,J,ie,H.value[3]]:H.value=[j,J,ie];break}case"rgba":{const j=cl(T.v);H.value=Array.isArray(H.value)&&H.value.length===3?j.slice(0,3):j;break}case"float":H.value=T.v;break;case"bool":H.value=T.v?1:0;break;case"array":H.value=Float32Array.from(T.v);break;case"texture":{const j=o.get(T.v);j&&(H.value=j);break}case"null":H.value instanceof Ke&&(H.value=v);break}},ne=(b,E)=>{E.kind!=="lit"&&E.kind!=="gltf"&&E.kind!=="shadow"&&E.kind!=="custom"||b.onBeforeRender(()=>{const T=b.program.uniforms;if(T.shadowEnabled){const U=d.shadowEnabled.value===1&&b._receiveShadows!==!1;T.shadowEnabled=U?d.shadowEnabled:{value:0}}})},fe=(b,E,T,U)=>{const H=_.get(E);if(!H)return;const{vertices:j,normals:J,indices:ie,uv:de,colors:ue}=T,be=new ut(u,{position:{size:3,data:Float32Array.from(j)},normal:{size:3,data:J.length?Float32Array.from(J):new Float32Array(j.length)},uv:{size:2,data:de.length?Float32Array.from(de):new Float32Array(j.length/3*2)},...ue&&ue.length?{color:{size:4,data:Float32Array.from(ue,Ve=>Ve/255)}}:{},index:{data:Uint16Array.from(ie)}});be.computeBoundingBox();const ge=U===1?u.LINES:U===2?u.POINTS:u.TRIANGLES,ve=new nt(u,{geometry:be,program:H.program,mode:ge});ve.program=z(H,ve),ve.matrixAutoUpdate=!1,ve._entId=b,ve._castShadows=L,ve._receiveShadows=W,ne(ve,H);const _e=D(b);for(const Ve of _e.drawables){_e.transform.removeChild(Ve);const ot=Z.get(Ve);ot&&(ot.setParent(null),Z.delete(Ve))}_e.drawables=[ve],_e.transform.addChild(ve)},we=async(b,E,T)=>{const U=s(b);let H;try{H=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}H.nodes.forEach((j,J)=>{const ie=T[J];if(ie===void 0)return;const de=D(ie);de.transform.setParent(null),ye.rebindMatrix(ie,j.matrix),j.matrixAutoUpdate=!1,j._entId=ie,de.transform=j,de.drawables=[];for(const ue of j.children)ue.draw&&(ue.matrixAutoUpdate=!1,ue._entId=ie,ue._castShadows=L,ue._receiveShadows=W,de.drawables.push(ue))});for(const j of H.roots)j.setParent(D(E).transform)},pe=[],Ge=(b,E)=>{const T=D(b),U=D(E);for(const H of T.drawables){const j=H instanceof Pt?new Pt(u,{skeleton:H.skeleton,geometry:H.geometry,program:H.program,mode:H.mode}):new nt(u,{geometry:H.geometry,program:H.program,mode:H.mode});j instanceof Pt&&pe.push(j);const J=H._morph;J&&(j._morph=J,vi(j,J)),j._entId=E,j._castShadows=H._castShadows,j._receiveShadows=H._receiveShadows,j.frustumCulled=H.frustumCulled,j.matrixAutoUpdate=!1,U.drawables.push(j),U.transform.addChild(j)}},Qe=b=>{for(const E of pe.splice(0)){const T=E.skeleton.joints.map(U=>{const H=U._entId===void 0?void 0:b.get(U._entId);if(H===void 0)return U;const j=D(H).transform;return j.bindInverse=U.bindInverse,j});E.skeleton={...E.skeleton,joints:T}}};let Ue="off";const S={value:[.05,.06,.08]},A=new ze(u,{vertex:tr,fragment:ws,uniforms:{uWireColor:S,shadowMatrix:d.shadowMatrix}}),C=new ze(u,{vertex:_n("HAS_SKIN"),fragment:ws,uniforms:{uWireColor:S,shadowMatrix:d.shadowMatrix,boneTexture:{value:v},boneTextureSize:{value:4}}}),G=new WeakMap,Z=new WeakMap,re=b=>{var T;let E=G.get(b);if(!E){const U={};for(const[J,ie]of Object.entries(b.attributes))J!=="index"&&(U[J]={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 H=b.attributes.position,j=H?H.count??H.data.length/H.size:0;U.index={data:_l((T=b.attributes.index)==null?void 0:T.data,j)},E=new ut(u,U),G.set(b,E)}return E},ce=b=>{var U,H;let E=Z.get(b);if(E)return E;if(!b.parent||!((H=(U=b.geometry)==null?void 0:U.attributes)!=null&&H.position))return null;const T=re(b.geometry);return E=b instanceof Pt?new Pt(u,{skeleton:b.skeleton,geometry:T,program:C,mode:u.LINES}):new nt(u,{geometry:T,program:A,mode:u.LINES}),E.frustumCulled=!1,E.matrixAutoUpdate=!1,E.matrix.copy(b.matrix),E._entId=b._entId,E._castShadows=!1,E._receiveShadows=!1,E.setParent(b.parent),Z.set(b,E),He(),E},Ae=()=>{for(const b of R.values())for(const E of b.drawables)if(E.mode===u.TRIANGLES)if(Ue==="off"){E.visible=!0;const T=Z.get(E);T&&(T.visible=!1)}else{const T=ce(E);E.visible=Ue==="overlay",T&&(T.visible=!0)}},Te=()=>{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,ke=e.transparent===!0,at=0,Mt=0,Nt=xn,Et=wn,Qt=Mn,Ct=null,Ot=!1,We=1,ht=null,It=0;const Ft=new ze(u,{vertex:Rr(!1),fragment:Pr,uniforms:{modelMatrix:{value:qe()},shadowViewProjection:{value:qe()}},cullFace:u.FRONT}),Ur=new ze(u,{vertex:Rr(!0),fragment:Pr,uniforms:{modelMatrix:{value:qe()},shadowViewProjection:{value:qe()},boneTexture:{value:v},boneTextureSize:{value:4}},cullFace:u.FRONT}),Dr=new ze(u,{vertex:Rr(!1,!0),fragment:Pr,uniforms:{shadowViewProjection:{value:qe()}},cullFace:u.FRONT}),Zt=new Map;let Sr=!0;const St=b=>{let E=Zt.get(b);return E||(E=Mc(u,g),E.setEnabled(Sr),Zt.set(b,E)),E};let or=0;const He=()=>{or++},Kr=new Map,$=b=>{Kr.get(b)!==or&&(b.updateMatrixWorld(),Kr.set(b,or))},te=(b,E,T=!1)=>{const U=St(b);$(b),U.collect(b,E,!0,or,T),U.drawMain(E,d.shadowEnabled),T&&He()},X=b=>{var E;for(const[T,U]of ye.entities)if(U.light&&ye.methods.isVisible(T)&&((E=ye.sceneOf(T))==null?void 0:E.id)===b)return{...U.light,direction:ye.sunDirection(T)};return null};let Q=!1;const ae=b=>{var de,ue;const E=(de=ye.scenes.get(b))==null?void 0:de.camera,T=E!==void 0?ye.worldMatrix(E):qe(),U=[];for(const[be,ge]of ye.entities){const ve=ge.punctual;if(!ve||!(ve.intensity>0)||!ye.methods.isVisible(be)||((ue=ye.sceneOf(be))==null?void 0:ue.id)!==b)continue;const _e=ye.worldMatrix(be);U.push({id:be,p:ve,w:_e,near:Math.hypot(_e[12]-T[12],_e[13]-T[13],_e[14]-T[14])-ve.range})}U.length>sr&&(U.sort((be,ge)=>be.near-ge.near),Q||(Q=!0,console.warn(`[viewer-lite] ${U.length} point / spot lights in the scene: the lite engine draws the ${sr} nearest the camera`)));const H=Math.min(U.length,sr),j=d.punctualPos.value,J=d.punctualColor.value,ie=d.punctualDir.value;for(let be=0;be<H;be++){const{p:ge,w:ve}=U[be],_e=be*4;j[_e]=ve[12],j[_e+1]=ve[13],j[_e+2]=ve[14],j[_e+3]=1/(ge.range*ge.range);const Ve=ge.intensity/(ge.type==="spot"?Math.PI:4*Math.PI);J[_e]=(ge.color>>>16&255)/255*Ve,J[_e+1]=(ge.color>>>8&255)/255*Ve,J[_e+2]=(ge.color&255)/255*Ve;const ot=-ve[8],Tt=-ve[9],mt=-ve[10],Vt=Math.hypot(ot,Tt,mt)||1;if(ie[_e]=ot/Vt,ie[_e+1]=Tt/Vt,ie[_e+2]=mt/Vt,ge.type==="spot"){const Ht=Math.cos(ge.outer),Jt=1/Math.max(1/1024,Math.cos(ge.inner)-Ht);J[_e+3]=Jt,ie[_e+3]=-Ht*Jt}else J[_e+3]=0,ie[_e+3]=1}d.punctualCount.value=H},oe=b=>{const E=[];return b.traverse(T=>T.visible?(T.draw&&E.push(T),!1):!0),E},he=(b,E)=>{const T=E.shadowsQuality>=3?4096:E.shadowsQuality>=2?2048:1024;(!ht||It!==T)&&(ht=new ii(u,{width:T,height:T,depthTexture:!0}),It=T);const U=St(b),H=U.casterSingles,j=[1/0,1/0,1/0],J=[-1/0,-1/0,-1/0],ie=[0,0,0];for(const Dt of H){const xt=Dt.geometry;if(xt.bounds||xt.computeBoundingBox(),!xt.bounds||!isFinite(xt.bounds.min.x))continue;const Gr=Dt.worldMatrix;for(let er=0;er<8;er++){Bt(ie,Gr,er&1?xt.bounds.max.x:xt.bounds.min.x,er&2?xt.bounds.max.y:xt.bounds.min.y,er&4?xt.bounds.max.z:xt.bounds.min.z,1);for(let Rt=0;Rt<3;Rt++)ie[Rt]<j[Rt]&&(j[Rt]=ie[Rt]),ie[Rt]>J[Rt]&&(J[Rt]=ie[Rt])}}if(U.casterBounds(j,J),!isFinite(j[0])){d.shadowEnabled.value=0;return}const[de,ue,be]=j,[ge,ve,_e]=J,Ve=(de+ge)/2,ot=(ue+ve)/2,Tt=(be+_e)/2,mt=Math.max(.5,Math.hypot(ge-de,ve-ue,_e-be)/2);let Vt=E.direction[0],Ht=E.direction[1],Jt=E.direction[2];const Zr=Math.hypot(Vt,Ht,Jt)||1;Vt/=Zr,Ht/=Zr,Jt/=Zr;const Ut=[Ve-Vt*mt*2,ot-Ht*mt*2,Tt-Jt*mt*2],ar=-Vt,lr=-Ht,cr=-Jt,ur=Math.abs(Ht)>.99?[1,0,0]:[0,1,0];let hr=ur[1]*cr-ur[2]*lr,fr=ur[2]*ar-ur[0]*cr,dr=ur[0]*lr-ur[1]*ar;const Jr=Math.hypot(hr,fr,dr)||1;hr/=Jr,fr/=Jr,dr/=Jr;const Ln=lr*dr-cr*fr,Nn=cr*hr-ar*dr,On=ar*fr-lr*hr,pt=new Float32Array(16);pt[0]=hr,pt[4]=fr,pt[8]=dr,pt[1]=Ln,pt[5]=Nn,pt[9]=On,pt[2]=ar,pt[6]=lr,pt[10]=cr,pt[12]=-(hr*Ut[0]+fr*Ut[1]+dr*Ut[2]),pt[13]=-(Ln*Ut[0]+Nn*Ut[1]+On*Ut[2]),pt[14]=-(ar*Ut[0]+lr*Ut[1]+cr*Ut[2]),pt[15]=1;const Fi=qa(-mt,mt,-mt,mt,.05,mt*4),zr=bt(new Float32Array(16),Fi,pt);Ft.uniforms.shadowViewProjection.value=zr,Ur.uniforms.shadowViewProjection.value=zr,Dr.uniforms.shadowViewProjection.value=zr,d.shadowMatrix.value=zr,d.shadowMap.value=ht.depthTexture,d.shadowMapSize.value=T,d.shadowEnabled.value=1,g.bindFramebuffer(ht),g.setViewport(T,T),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=qe();for(const Dt of H){const xt=Dt instanceof Pt,Gr=xt?Ur:Ft,er=Dt.program;Gr.uniforms.modelMatrix.value=xt?Ti:Dt.worldMatrix,Dt.program=Gr,Dt.draw({}),Dt.program=er}U.drawShadow(Dr),g.bindFramebuffer({buffer:null})};let le=null,me=null,Me=null,Ee=null;const xe=(b,E,T)=>{if(Me===null&&(Me=bc(u),Me||console.warn("[viewer-lite] bloom needs EXT_color_buffer_float — drawn without")),!Me||E===0||T===0)return null;Ee??(Ee=Ac(u,4));const U=b.antialias===!1?0:Ee;return(!le||le.width!==E||le.height!==T||le.samples!==U)&&(le==null||le.dispose(),le=Sc(u,g,E,T,U),le||(Me=!1,console.warn("[viewer-lite] bloom target is incomplete on this driver — drawn without"))),le},Se=b=>{let E=at===0?0:(b-at)/1e3;E>.05&&(E=.05),at=b;const T=b/1e3;y.value[0]=T,y.value[1]=T-Math.floor(T),ye.tick(E)},Ie=(b,E,T)=>{var be;const U=E/Math.max(1,T),{fov:H,near:j,far:J,matrix:ie}=ye.projectionOf(b);if(m.value=Math.max(1,T)/(2*Math.tan(H*Math.PI/360)),ie){for(let ge=0;ge<16;ge++)Fe.projectionMatrix[ge]=ie[ge];Fe.near=j,Fe.far=J,Mt=0}else(U!==Mt||H!==Nt||j!==Et||J!==Qt)&&(Mt=U,Nt=H,Et=j,Qt=J,Fe.perspective({fov:H,aspect:U,near:j,far:J}));const de=(be=ye.scenes.get(b))==null?void 0:be.camera,ue=de!==void 0?ye.worldMatrix(de):qe();for(let ge=0;ge<16;ge++)Fe.matrix[ge]=ue[ge];Fe.worldMatrixNeedsUpdate=!0},Be=()=>({buffer:null,x:0,y:0,width:t.width,height:t.height}),Oe=(b,E=Be())=>{const T=ye.activeSceneId(),U=ye.scenes.get(T),H=P.get(T);if(!U||!H)return!1;Se(b),Te(),Ie(T,E.width,E.height),Ue!=="off"?(Ae(),u.enable(u.POLYGON_OFFSET_FILL),u.polygonOffset(1,1)):u.disable(u.POLYGON_OFFSET_FILL),$(H);const j=St(H);j.collect(H,Fe,!0,or);const J=X(T);if(J){const ge=(J.color>>>16&255)/255,ve=(J.color>>>8&255)/255,_e=(J.color&255)/255;d.sunDirection.value=J.direction,d.sunColorIntensity.value=[ge,ve,_e,J.intensity],J.shadowsQuality>0?he(H,J):d.shadowEnabled.value=0}else d.sunColorIntensity.value=[1,1,1,0],d.shadowEnabled.value=0;ae(T),d.iblLuminance.value=U.ibl??0;const ie=O?void 0:U.bloom,de=ie?xe(U,E.width,E.height):null;d.uTonemap.value=de?0:1;const ue=U.skybox!==void 0?[(U.skybox>>>16&255)/255,(U.skybox>>>8&255)/255,(U.skybox&255)/255]:[.1,.25,.57],be=de?ue:ue.map(al);de?(de.bindDraw(),xi(u,g,de.width,de.height)):Lr(u,g,E),ke||Xe.active()?u.clearColor(0,0,0,0):u.clearColor(be[0],be[1],be[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),O==null||O.renderScenePass(be);for(const ge of U.overlays){const ve=P.get(ge);ve&&(u.clear(u.DEPTH_BUFFER_BIT),te(ve,Fe))}if(O==null||O.renderOverlayPass(),O==null||O.renderPreviewPass(H,be),de&&ie){de.resolve(),me??(me=Uc(u,g));const ge=me.run(de.texture,de.width,de.height,ie);me.compose(de.texture,ge.texture,ie.strength/ge.levels,E)}return E.buffer===null&&Xe.active()&&queueMicrotask(it),!0},De=new Set,Ne=(b,E)=>{const T=E instanceof Error?E.message:String(E);De.has(T)||(De.add(T),console.error(`[viewer-lite] ${b} failed:`,E))},Le=()=>{Ot||(Ot=!0,requestAnimationFrame(Ze))},$e=()=>{if(Ct)try{Ct()}catch(b){Ne("the host's frame hook",b)}},Ze=()=>{if(Ot=!1,!(!Pe||Xe.active())){$e();try{Oe(performance.now())}catch(b){Ne("render frame",b)}Le()}},Ye=()=>{g.bindFramebuffer({buffer:null}),u.clearColor(0,0,0,0),g.setDepthMask(!0),u.clear(u.COLOR_BUFFER_BIT|u.DEPTH_BUFFER_BIT)},it=()=>{Xe.active()&&Ye()},Xe=Fc({gl:u,renderer:g,near:wn,far:Mn,presenting(b){b?Ye():Pe&&Le()},begin(){Pe&&$e()},view(b,E,T,U,H){if(!Pe)return!1;const j=ye.activeSceneId();return b!==void 0&&j!==b?!1:(ye.methods.setCameraMatrix(j,E),ye.methods.setCameraProjectionMatrix(j,T,U,H),!0)},draw(b){if(Pe)try{b?Oe(performance.now(),b):Se(performance.now())}catch(E){Ne("render frame (XR)",E)}},failed:Ne}),yt=b=>{var E;return(E=ye.sceneOf(b))==null?void 0:E.id};let ft=[0,0,0];const tt=(b,E,T)=>{var Tt;const U=(Tt=ye.scenes.get(b))==null?void 0:Tt.camera,H=U!==void 0?ye.worldMatrix(U):qe(),j=Math.max(1,t.width),J=Math.max(1,t.height),ie=j/J,de=E*We,ue=T*We,[be,ge]=ui(ye.projectionOf(b),ie,de/j*2-1,1-ue/J*2),ve=H[0]*be+H[4]*ge-H[8],_e=H[1]*be+H[5]*ge-H[9],Ve=H[2]*be+H[6]*ge-H[10],ot=Math.hypot(ve,_e,Ve)||1;return ft=[H[12],H[13],H[14]],{origin:ft,dir:[ve/ot,_e/ot,Ve/ot]}},rt=(b,E,T)=>{const U=B.get(b);if(!U)return 0;let H=1/0,j=0;const J=[0,0,0],ie=[0,0,0];for(const[de,ue]of U){if(!ye.entities.has(de)||!ye.methods.isVisible(de))continue;const be=Lt(ye.worldMatrixF(de));Bt(J,be,E[0],E[1],E[2],1),Bt(ie,be,T[0],T[1],T[2],0);const ge=ue.type==="box"?xs(ue.center,ue.extent,J,ie):Ya(ue.center,ue.radius,J,ie);ge>0&&ge<H&&(H=ge,j=de)}return j},je=(b,E,T)=>{const U=P.get(b);if(!U)return 0;let H=1/0,j=0;const J=[0,0,0],ie=[0,0,0];U.updateMatrixWorld();for(const de of oe(U)){const ue=de.geometry;if(ue.bounds||ue.computeBoundingBox(),!ue.bounds||!isFinite(ue.bounds.min.x))continue;const be=Lt(de.worldMatrix);Bt(J,be,E[0],E[1],E[2],1),Bt(ie,be,T[0],T[1],T[2],0);const ge=[(ue.bounds.min.x+ue.bounds.max.x)/2,(ue.bounds.min.y+ue.bounds.max.y)/2,(ue.bounds.min.z+ue.bounds.max.z)/2],ve=[(ue.bounds.max.x-ue.bounds.min.x)/2,(ue.bounds.max.y-ue.bounds.min.y)/2,(ue.bounds.max.z-ue.bounds.min.z)/2],_e=xs(ge,ve,J,ie);_e>0&&_e<H&&(H=_e,j=de._entId??0)}return j},Je=(b,E)=>{const T=ye.activeSceneId(),U=ye.scenes.get(T);if(!U||U.camera===void 0)return 0;const{origin:H,dir:j}=tt(T,b,E);for(let J=U.overlays.length-1;J>=0;J--){const ie=rt(U.overlays[J],H,j);if(ie!==0)return ie}return rt(T,H,j)},zt=b=>{b.mesh&&b.mesh.setParent(null),b.buffer&&u.deleteBuffer(b.buffer),b.mesh=null,b.geometry=null,b.buffer=null},Gt=(b,E)=>{const T=_.get(b.materialId);if(E===kt.MESH)return(T??K("unlit")).program;const U=E!==kt.POINTS;return T&&T.kind===(U?"particles-quad":"particles")?T.program:K(U?"particles-quad":"particles").program},dt=(b,E,T)=>{if(zt(E),E.version=T.geometryVersion,E.mode=T.mode,T.capacity===0)return;const U=ye.particleIndexPattern(b);if(U.length===0)return;let H;if(T.mode===kt.MESH){const J=T.capacity*T.meshVertexCount;H=new ut(u,{position:{size:3,data:new Float32Array(J*3),usage:u.DYNAMIC_DRAW},normal:{size:3,data:new Float32Array(J*3),usage:u.DYNAMIC_DRAW},uv:{size:2,data:new Float32Array(J*2),usage:u.DYNAMIC_DRAW},index:{data:U}})}else{const J=u.createBuffer();E.buffer=J;const ie=T.stride,de=T.mode===kt.POINTS?T.capacity:T.mode===kt.QUADS?T.capacity*4:(T.capacity+1)*2,ue=(ge,ve)=>({size:ge,type:u.FLOAT,buffer:J,stride:ie,offset:ve,count:de,data:new Float32Array(0)}),be={position:ue(3,0),color:ue(4,12),custom:ue(4,28)};T.mode!==kt.POINTS&&(be.aux=ue(3,44),be.corner=ue(2,56)),be.index={data:Uint16Array.from(U)},H=new ut(u,be),u.bindBuffer(u.ARRAY_BUFFER,J),u.bufferData(u.ARRAY_BUFFER,de*ie,u.DYNAMIC_DRAW),g.state.boundBuffer=J}const j=new nt(u,{geometry:H,program:Gt(E,T.mode),mode:T.mode===kt.POINTS?u.POINTS:u.TRIANGLES});j.frustumCulled=!1,j.matrixAutoUpdate=!1,j._entId=b,j._particles=!0,j.setParent(D(b).transform),E.geometry=H,E.mesh=j},_i=(b,E)=>{let T=h.get(b);if(T||(T={materialId:0,mesh:null,geometry:null,buffer:null,version:0,mode:-1},h.set(b,T)),(T.version!==E.geometryVersion||T.mode!==E.mode||!T.mesh)&&(dt(b,T,E),He()),!T.mesh||!T.geometry)return;const U=E.indexCount>0;if(T.mesh.visible!==U&&(T.mesh.visible=U,He()),!!U){if(T.mesh.renderOrder=E.order,E.mode===kt.MESH){const H=E.vertexCount,j=new Float32Array(E.bytes.buffer,E.bytes.byteOffset,H*10),J=T.geometry.attributes.position,ie=T.geometry.attributes.normal,de=T.geometry.attributes.uv,ue=J.data,be=ie.data,ge=de.data;for(let ve=0;ve<H;ve++){const _e=ve*10;ue[ve*3]=j[_e],ue[ve*3+1]=j[_e+1],ue[ve*3+2]=j[_e+2];const Ve=j[_e+3],ot=j[_e+4],Tt=j[_e+5],mt=j[_e+6];be[ve*3]=2*(Ve*Tt+ot*mt),be[ve*3+1]=2*(ot*Tt-Ve*mt),be[ve*3+2]=1-2*(Ve*Ve+ot*ot),ge[ve*2]=j[_e+8],ge[ve*2+1]=j[_e+9]}J.needsUpdate=ie.needsUpdate=de.needsUpdate=!0}else T.buffer&&(u.bindBuffer(u.ARRAY_BUFFER,T.buffer),u.bufferSubData(u.ARRAY_BUFFER,0,E.bytes),g.state.boundBuffer=T.buffer);T.geometry.drawRange.start=0,T.geometry.drawRange.count=E.indexCount}},Ei={allocMatrix:b=>D(b).transform.matrix,localMatrixChanged:b=>{D(b).transform.worldMatrixNeedsUpdate=!0,He()},parentChanged:(b,E)=>{He();const T=D(b).transform;if(E!==0)T.setParent(D(E).transform);else{const U=ye.sceneOf(b);T.setParent((U&&P.get(U.id))??null)}},sceneCreated:b=>{P.set(b,new vt),B.set(b,new Map)},entitySceneChanged:(b,E,T)=>{He();const U=P.get(E);if(!U)return;const H=D(b);if(T){for(const[j,J]of B){if(j===E)continue;const ie=J.get(b);ie&&(B.get(E).set(b,ie),J.delete(b))}ye.ent(b).parent===0&&H.transform.setParent(U)}else ye.ent(b).parent===0&&H.transform.parent===U&&H.transform.setParent(null)},visibleChanged:(b,E)=>{D(b).transform.visible=E,He()},materialCreated:(b,E,T)=>{_.set(b,k(E.shader,T))},uniformChanged:(b,E,T)=>ee(b,E,T),meshSet:(b,E,T,U)=>{fe(b,E,U,T.kind),He()},glbAttach:(b,E,T)=>we(b,E,T).then(He),morphWeights:(b,E)=>{const T=D(b).transform.weights;T&&T.set(E.subarray(0,Math.min(T.length,E.length)))},entityDestroyed:b=>{He();const E=R.get(b);E&&(E.transform.setParent(null),R.delete(b));for(const T of B.values())T.delete(b)},entityCloned:(b,E)=>{Ge(b,E),He()},subtreeCloned:(b,E,T)=>Qe(T),particleSystemCreated:(b,E)=>{const T=h.get(b);T?(zt(T),T.materialId=E,T.version=0):h.set(b,{materialId:E,mesh:null,geometry:null,buffer:null,version:0,mode:-1})},particlesFrame:(b,E)=>_i(b,E),particleSystemDestroyed:b=>{const E=h.get(b);E&&(zt(E),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,E,T,U=!1)=>{createImageBitmap(b).then(H=>{const j=new Ke(u,{image:H,internalFormat:U?u.RGBA8:u.SRGB8_ALPHA8,format:u.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),J=F++;o.set(J,j),E(J,H.width,H.height)}).catch(T)};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,E,T){ye.methods.createGlb(b,U=>E({id:U}),T)},openScene(b){const E=Pe;ye.methods.openScene(b),Pe=ye.scenes.has(b),t.style.display="block",!E&&Pe&&Le()},closeScene(){t.style.display="none",Pe=!1,ye.methods.closeScene()},launchAR(){throw new Error(Fr)},stopAR(){throw new Error(Fr)},launchVR(b,E,T){T(new Error("VR is not supported on this device"))},stopVR(){},async warmRender(b,E){E()},attachCameraToAR(b,E,T){const U=ye.scenes.get(b);if(U){U.camera=E;for(const H of U.overlays){const j=ye.scenes.get(H);j&&(j.camera=E)}}},getCameraFov(b,E){const T=ye.projectionOf(b).fov;if(E!==1)return T;const U=T*Math.PI/180,H=t.width/Math.max(1,t.height);return 2*Math.atan(Math.tan(U/2)*H)*180/Math.PI},getCameraViewDirection(b,E,T,U){if(!ye.scenes.has(b)){U[0]=0,U[1]=0,U[2]=-1;return}const{dir:H}=tt(b,E,T);U[0]=H[0],U[1]=H[1],U[2]=H[2]},getDisplaySize:()=>Float32Array.of(g.width||t.width,g.height||t.height),createTexture(b,E,T,U=0){const H=(J,ie,de)=>E({id:J},ie,de),j=n(b);j.slice(0,12).arrayBuffer().then(async J=>{const ie=await Nr(()=>import("./index-e-m97P8Y.js"),__vite__mapDeps([0,1]),import.meta.url);if(!ie.isKtx2Bytes(new Uint8Array(J)))return!1;const de=await j.arrayBuffer(),ue=await ie.transcodeKtx2(u,de),be=ie.ktx2IsSrgb(de);let ge;ue.isCompressedTexture?ge=new Ke(u,{image:ue,internalFormat:be&&ue.srgbInternalFormat?ue.srgbInternalFormat:ue.internalFormat,generateMipmaps:!1,minFilter:ue.length>1?u.LINEAR_MIPMAP_LINEAR:u.LINEAR,flipY:!1}):ge=new Ke(u,{image:ue,internalFormat:be?u.SRGB8_ALPHA8:u.RGBA8,format:u.RGBA,generateMipmaps:!0,flipY:!1,premultiplyAlpha:!1});const ve=F++;return o.set(ve,ge),H(ve,ue.width,ue.height),!0}).then(J=>{J||Ci(j,H,T,(U&1)!==0)},T)},createTexturePixels(b,E,T,U,H){if(b<=0||E<=0||U.length<b*E*T)return{id:4294967295};const j=new Uint8Array(b*E*4);for(let de=0,ue=b*E;de<ue;de++){const be=de*T,ge=de*4;j[ge]=U[be],j[ge+1]=T>=2?U[be+1]:U[be],j[ge+2]=T>=3?U[be+2]:U[be],j[ge+3]=T>=4?U[be+3]:255}const J=new Ke(u,{image:j,width:b,height:E,internalFormat:H?u.SRGB8_ALPHA8:u.RGBA8,format:u.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1,minFilter:u.LINEAR,magFilter:u.LINEAR}),ie=F++;return o.set(ie,J),w.set(ie,{rgba:j,width:b,height:E,channels:T}),{id:ie}},updateTexturePixels(b,E,T,U,H,j){const J=w.get(b),ie=o.get(b);if(!J||!ie)return;const de=J.channels;for(let ue=0;ue<H;ue++){const be=T+ue;if(!(be<0||be>=J.height))for(let ge=0;ge<U;ge++){const ve=E+ge;if(ve<0||ve>=J.width)continue;const _e=(ue*U+ge)*de,Ve=(be*J.width+ve)*4;J.rgba[Ve]=j[_e],J.rgba[Ve+1]=de>=2?j[_e+1]:j[_e],J.rgba[Ve+2]=de>=3?j[_e+2]:j[_e],J.rgba[Ve+3]=de>=4?j[_e+3]:255}}ie.image=J.rgba,ie.needsUpdate=!0},createTextureFromCanvas(b){var H;const E=(H=e.canvasHost)==null?void 0:H.readSurface(b);if(!E)return 0;const T=new Ke(u,{image:new Uint8Array(E.data.buffer.slice(0)),width:E.width,height:E.height,internalFormat:u.SRGB8_ALPHA8,format:u.RGBA,generateMipmaps:!1,flipY:!1}),U=F++;return o.set(U,T),U},updateTextureFromCanvas(b,E){var H;const T=(H=e.canvasHost)==null?void 0:H.readSurface(E),U=o.get(b);!T||!U||(U.image=new Uint8Array(T.data.buffer.slice(0)),U.width=T.width,U.height=T.height,U.needsUpdate=!0)},createMediaPlayerTexture(b){const E=f(b),T=new Ke(u,{generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1});I.push({video:E,texture:T,lastTime:-1});const U=F++;return o.set(U,T),U},setUniformTexture(b,E,T,U,H){ye.methods.setUniformTexture(b,E,T);const j=_.get(b),J=o.get(T);if(!j||!J)return;const ie=[u.CLAMP_TO_EDGE,u.REPEAT,u.MIRRORED_REPEAT];J.wrapS=ie[U]??u.REPEAT,J.wrapT=ie[H]??u.REPEAT,J.needsUpdate=!0,se(j,E).value=J},setMaterial(b,E,T){ye.methods.setMaterial(b,E,T);const U=_.get(E),H=D(b).drawables[T];!U||!H||(H.program=z(U,H),ne(H,U),He())},getMaterial(b,E){const T=D(b).drawables[E];if(!T)return 0;const U=ye.nextMaterialId();return _.set(U,{kind:"gltf",program:T.program,source:T.program._source}),U},setCulling(b,E){for(const T of D(b).drawables)T.frustumCulled=E;He()},setGlbCulling(b,E){const T=U=>{for(const H of D(U).drawables)H.frustumCulled=E;for(const H of ye.ent(U).children)T(H)};T(b),He()},setRenderPriority(b,E){for(const T of D(b).drawables)T.renderOrder=E;He()},setMaterialDepthTest(b,E){const T=_.get(b);if(T)for(const U of Y(T))U.depthTest=E},setMaterialDepthWrite(b,E){const T=_.get(b);if(T)for(const U of Y(T))U.depthWrite=E},setMaterialCulling(b,E){const T=_.get(b);if(T)for(const U of Y(T))U.cullFace=E===0?!1:E===1?u.FRONT:u.BACK},setCastShadows(b,E){ye.methods.setCastShadows(b,E);for(const T of D(b).drawables)T._castShadows=E;He()},setReceiveShadows(b,E){ye.methods.setReceiveShadows(b,E);for(const T of D(b).drawables)T._receiveShadows=E;He()},setGlbShadows(b,E,T){ye.methods.setGlbShadows(b,E,T);const U=H=>{for(const j of D(H).drawables)j._castShadows=E,j._receiveShadows=T;for(const j of ye.ent(H).children)U(j)};U(b),He()},setCastShadowsGlobal(b){L=b},setReceiveShadowsGlobal(b){W=b},setColliderFromMesh(b,E,T){var J;if(T!==0)return;const U=D(E).drawables[0];if(!U)return;const H=U.geometry;if(H.bounds||H.computeBoundingBox(),!H.bounds)return;const j=yt(b)??ye.activeSceneId();(J=B.get(j))==null||J.set(b,{type:"box",center:[(H.bounds.min.x+H.bounds.max.x)/2,(H.bounds.min.y+H.bounds.max.y)/2,(H.bounds.min.z+H.bounds.max.z)/2],extent:[(H.bounds.max.x-H.bounds.min.x)/2,(H.bounds.max.y-H.bounds.min.y)/2,(H.bounds.max.z-H.bounds.min.z)/2]})},setColliderBox(b,E,T,U,H,j,J){var de;const ie=yt(b)??ye.activeSceneId();(de=B.get(ie))==null||de.set(b,{type:"box",center:[E,T,U],extent:[H/2,j/2,J/2]})},setColliderSphere(b,E,T,U,H){var J;const j=yt(b)??ye.activeSceneId();(J=B.get(j))==null||J.set(b,{type:"sphere",center:[E,T,U],radius:H})},createARController(){throw new Error(Fr)},createRootAnchor(){throw new Error(Fr)},createAnchor(){throw new Error(Fr)},_renderNow:()=>Oe(performance.now()),async captureImage(b,E,T){try{Oe(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"}),J=await j.arrayBuffer();E(a(J),"image.png",j.size)}catch{T()}},raycastView:Je,_raycastView:Je,raycastPick(b,E){const T=ye.activeSceneId(),U=ye.scenes.get(T);if(!U||U.camera===void 0)return 0;const H=Je(b,E);if(H!==0)return H;const{origin:j,dir:J}=tt(T,b,E);return je(T,j,J)},computeBoundingBox(b){const E=Float32Array.of(1/0,1/0,1/0,-1/0,-1/0,-1/0),T=[0,0,0],U=(H,j)=>{for(const J of D(H).drawables){const ie=J.geometry;if(ie.bounds||ie.computeBoundingBox(),!(!ie.bounds||!isFinite(ie.bounds.min.x)))for(let de=0;de<8;de++){const ue=de&1?ie.bounds.max.x:ie.bounds.min.x,be=de&2?ie.bounds.max.y:ie.bounds.min.y,ge=de&4?ie.bounds.max.z:ie.bounds.min.z;j?Bt(T,j,ue,be,ge,1):(T[0]=ue,T[1]=be,T[2]=ge);for(let ve=0;ve<3;ve++)T[ve]<E[ve]&&(E[ve]=T[ve]),T[ve]>E[ve+3]&&(E[ve+3]=T[ve])}}for(const J of ye.ent(H).children){const ie=D(J).transform.matrix,de=j?bt(new Float32Array(16),j,ie):Float32Array.from(ie);U(J,de)}};return U(b,null),isFinite(E[0])||E.fill(0),E},stopAllPlayers(){p()},_dumpScene3d:()=>uu(ye),_setWireframeMode(b){Ue=b==="overlay"||b==="only"?b:"off",S.value=Ue==="only"?[.62,.66,.72]:[.05,.06,.08],Ae(),He()},_setBatching(b){for(const E of Zt.values())E.setEnabled(b);Sr=b,He()},_batchStats(){const b=P.get(ye.activeSceneId());return b?St(b).stats():{batches:0,instances:0,visible:0,singles:0}},_editorConnect(b){return O??(O=gc({gl:u,renderer:g,canvas:t,camera:Fe,core:ye,sceneRoots:P,drawablesOf:E=>D(E).drawables,collectMeshes:oe,wireGeometryFor:re,getViewRay:tt,renderScene:te})),O.setHandlers(b),O.api},async createEngine(){},_fetch:r,_getPlayer:f,_createGLTexture(b){const E=new Ke(u,{image:b,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),T=F++;return o.set(T,E),E.update(),{gl:u,glTexture:E.texture,textureId:T}},_projectionOf:b=>ye.projectionOf(b),_setTransparent(b){ke=b},_beforeFrame(b){Ct=b},_presentXR(b,E,T,U){return U!==void 0&&!ye.scenes.has(U)?Promise.reject(new Error(`[viewer-lite] _presentXR: there is no scene ${U}`)):Xe.present(b,E,T,U)},_onResize(b,E,T=1){We=T,g.dpr=T,g.setSize(b,E),Mt=0},_dispose(){var b;Ct=null,Xe.end(),O==null||O.dispose(),O=null,le==null||le.dispose(),le=null,me==null||me.dispose(),me=null;for(const E of Zt.values())E.dispose();Zt.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};