lecodes-cli 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/index.js +2580 -872
  2. package/package.json +16 -11
  3. package/runtime/sdk-types.json +1 -1
  4. package/runtime/web/VERSION.json +3 -3
  5. package/runtime/web/assets/creator-2d-CYlV77UR.js +1 -0
  6. package/runtime/web/assets/creator-2d-nG7rGEmq.wasm +0 -0
  7. package/runtime/web/assets/{creator-full-D2dSDdDj.wasm → creator-full-Cla1R8N6.wasm} +0 -0
  8. package/runtime/web/assets/creator-full-DmfoULcB.js +1 -0
  9. package/runtime/web/assets/creator-full.js-D8SMHuCt.symbols +8419 -0
  10. package/runtime/web/assets/creator-ui-CbtoaRlz.js +1 -0
  11. package/runtime/web/assets/creator-ui-DZaoxIpX.wasm +0 -0
  12. package/runtime/web/player.js +17 -17
  13. package/runtime/web-lite/assets/__vite-browser-external-BIHI7g3E.js +1 -0
  14. package/runtime/web-lite/assets/ar-BOdQ-wV4.js +1 -0
  15. package/runtime/web-lite/assets/basis-C64VHDVD.js +1 -0
  16. package/runtime/web-lite/assets/basis_transcoder-VXdx5NbI.wasm +0 -0
  17. package/runtime/web-lite/assets/canvas-WxiusXCB.js +1 -0
  18. package/runtime/web-lite/assets/creatorAnim-BOwKr-C1.js +1 -0
  19. package/runtime/web-lite/assets/creatorParticles-DYlv4g1J.js +1 -0
  20. package/runtime/web-lite/assets/creatorPhysics-k7wL0kV1.js +1 -0
  21. package/runtime/web-lite/assets/draco-BiISTFcR.js +118 -0
  22. package/runtime/web-lite/assets/draco_decoder-DsQ12WqX.wasm +0 -0
  23. package/runtime/web-lite/assets/index-3CbsYWmo.js +2 -0
  24. package/runtime/web-lite/assets/neutral_ibl128-D-lzdkLN.ktx +0 -0
  25. package/runtime/web-lite/assets/pager-Db5BY7FB.js +1 -0
  26. package/runtime/web-lite/assets/plugins-CuEPHbHL.js +1 -0
  27. package/runtime/web-lite/assets/roboto-cyrillic-DVBNKCCH.woff2 +0 -0
  28. package/runtime/web-lite/assets/roboto-cyrillic-ext-1gPz9dK9.woff2 +0 -0
  29. package/runtime/web-lite/assets/roboto-greek-DVLYEgdx.woff2 +0 -0
  30. package/runtime/web-lite/assets/roboto-greek-ext-D98D44EL.woff2 +0 -0
  31. package/runtime/web-lite/assets/roboto-latin-cAJwcdBQ.woff2 +0 -0
  32. package/runtime/web-lite/assets/roboto-latin-ext-t610Sqxq.woff2 +0 -0
  33. package/runtime/web-lite/assets/roboto-rest-C7JkyNHT.woff2 +0 -0
  34. package/runtime/web-lite/assets/roboto-vietnamese-w-p-nKZZ.woff2 +0 -0
  35. package/runtime/web-lite/assets/scene3d-CX7MAqmN.js +866 -0
  36. package/runtime/web-lite/assets/tween-BnWYhJ7P.js +1 -0
  37. package/runtime/web-lite/assets/video-BLj61nDx.js +1 -0
  38. package/runtime/web-lite/assets/vlist-DrV2Q7P5.js +1 -0
  39. package/runtime/web-lite/assets/worker-Caf-yYEI.js +2 -0
  40. package/runtime/web-lite/features.json +134 -0
  41. package/runtime/web-lite/lite.js +90 -13
  42. package/runtime/web-lite/plugins/camera/index-5XOM8eHl.js +1 -0
  43. package/runtime/web-lite/plugins/geolocation/index-BjTKN9_P.js +1 -0
  44. package/runtime/web-lite/plugins/map/_virtual_lecodes-half-CQBO044A.js +1 -0
  45. package/runtime/web-lite/plugins/map/_virtual_lecodes-half-resources-BYwqQkWQ.js +1 -0
  46. package/runtime/web-lite/plugins/map/assets/maplibre-gl-worker-DeQFNGa4.js +8 -0
  47. package/runtime/web-lite/plugins/map/index-BTBHQ264.js +1 -0
  48. package/runtime/web-lite/plugins/map/mapImpl-C6E1SwCS.js +823 -0
  49. package/runtime/web-lite/plugins/qr-scanner/index-CK_cYoJR.js +1 -0
  50. package/runtime/web-lite/plugins.json +8 -0
  51. package/src/commands/compile.ts +7 -1
  52. package/src/commands/desktop.ts +7 -4
  53. package/src/commands/dev.ts +4 -14
  54. package/src/commands/render.ts +6 -2
  55. package/src/commands/test.ts +25 -9
  56. package/src/commands/update/index.ts +5 -4
  57. package/src/compile/projectCompile.ts +47 -1
  58. package/src/dev/androidDev.ts +1 -1
  59. package/src/dev/backendWorker.ts +138 -0
  60. package/src/dev/devServer.ts +119 -115
  61. package/src/dev/localBackend.ts +214 -0
  62. package/src/dev/projectBackend.ts +199 -0
  63. package/src/dev/serve.ts +164 -0
  64. package/src/hosts/archives.ts +41 -7
  65. package/src/hosts/cmgenTool.ts +6 -9
  66. package/src/hosts/desktopRenderer.ts +6 -5
  67. package/src/hosts/liteRunner.ts +52 -9
  68. package/src/hosts/matcTool.ts +5 -22
  69. package/src/hosts/peerInstall.ts +7 -7
  70. package/src/hosts/peers.ts +1 -0
  71. package/src/hosts/releases.ts +6 -0
  72. package/src/index.ts +5 -1
  73. package/src/plugin/generate.ts +10 -6
  74. package/src/web/build.ts +45 -5
  75. package/runtime/web/assets/creator-2d-D9WKYM6h.js +0 -1
  76. package/runtime/web/assets/creator-2d-ukvEmNEp.wasm +0 -0
  77. package/runtime/web/assets/creator-full-BBXzQlhq.js +0 -1
  78. package/runtime/web/assets/creator-full.js-BYswGsqR.symbols +0 -8124
  79. package/runtime/web/assets/creator-ui-DIc92ion.wasm +0 -0
  80. package/runtime/web/assets/creator-ui-_1Z_AX2M.js +0 -1
  81. package/runtime/web-lite/assets/Roboto-Variable-DHm9jpd-.woff2 +0 -0
  82. package/runtime/web-lite/assets/creatorTween-PF8B6T8V.wasm +0 -0
@@ -0,0 +1,866 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-3CbsYWmo.js","../lite.js","./creatorPhysics-k7wL0kV1.js","./creatorAnim-BOwKr-C1.js","./creatorParticles-DYlv4g1J.js"])))=>i.map(i=>d[i]);
2
+ import{r as Xs,_ as Ys,g as Ks,a as Qs,b as Zs,h as Js,p as ei,c as ti,d as ri,e as mr,v as dn,T as ni}from"../lite.js";function hr(t){let e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function Jr(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function si(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function mn(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function pn(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function ii(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function oi(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function Lr(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function ai(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 li(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 gn(t){let e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function ci(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function hi(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function en(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 _s(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function yn(t,e,r){let n=e[0],s=e[1],i=e[2],l=r[0],o=r[1],a=r[2];return t[0]=s*a-i*o,t[1]=i*l-n*a,t[2]=n*o-s*l,t}function ui(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 fi(t,e,r,n,s){const i=Math.exp(-n*s);let l=e[0],o=e[1],a=e[2];return t[0]=r[0]+(l-r[0])*i,t[1]=r[1]+(o-r[1])*i,t[2]=r[2]+(a-r[2])*i,t}function di(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 mi(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 pi(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 gi(t,e,r){let n=e[0],s=e[1],i=e[2],l=r[0],o=r[1],a=r[2],u=r[3],g=o*i-a*s,p=a*n-l*i,h=l*s-o*n,v=o*h-a*p,M=a*g-l*h,m=l*p-o*g,y=u*2;return g*=y,p*=y,h*=y,v*=2,M*=2,m*=2,t[0]=n+g+v,t[1]=s+p+M,t[2]=i+h+m,t}const yi=(function(){const t=[0,0,0],e=[0,0,0];return function(r,n){Jr(t,r),Jr(e,n),en(t,t),en(e,e);let s=_s(t,e);return s>1?0:s<-1?Math.PI:Math.acos(s)}})();function vi(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}class Me 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):(si(this,e,r,n),this)}copy(e){return Jr(this,e),this}add(e,r){return r?mn(this,e,r):mn(this,this,e),this}sub(e,r){return r?pn(this,e,r):pn(this,this,e),this}multiply(e){return e.length?ii(this,this,e):Lr(this,this,e),this}divide(e){return e.length?oi(this,this,e):Lr(this,this,1/e),this}inverse(e=this){return hi(this,e),this}len(){return hr(this)}distance(e){return e?ai(this,e):hr(this)}squaredLen(){return gn(this)}squaredDistance(e){return e?li(this,e):gn(this)}negate(e=this){return ci(this,e),this}cross(e,r){return r?yn(this,e,r):yn(this,this,e),this}scale(e){return Lr(this,this,e),this}normalize(){return en(this,this),this}dot(e){return _s(this,e)}equals(e){return vi(this,e)}applyMatrix3(e){return pi(this,this,e),this}applyMatrix4(e){return di(this,this,e),this}scaleRotateMatrix4(e){return mi(this,this,e),this}applyQuaternion(e){return gi(this,this,e),this}angle(e){return yi(this,e)}lerp(e,r){return ui(this,this,e,r),this}smoothLerp(e,r,n){return fi(this,this,e,r,n),this}clone(){return new Me(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 Me;let xi=1,wi=1,xn=!1;class rt{constructor(e,r={}){e.canvas||console.error("gl not passed as first argument to Geometry"),this.gl=e,this.attributes=r,this.id=xi++,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=wi++,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 o=i.size/l,a=l===1?0:l*l*4,u=l===1?0:l*4;for(let g=0;g<l;g++)this.gl.vertexAttribPointer(r+g,o,i.type,i.normalized,i.stride+a,i.offset+g*u),this.gl.enableVertexAttribArray(r+g),this.gl.renderer.vertexAttribDivisor(r+g,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 o=this.attributes[l];o.needsUpdate&&this.updateAttribute(o)});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(!xn)return console.warn("No position buffer data found to compute bounds"),xn=!0}computeBoundingBox(e){e||(e=this.getPosition());const r=e.data,n=e.size;this.bounds||(this.bounds={min:new Me,max:new Me,center:new Me,scale:new Me,radius:1/0});const s=this.bounds.min,i=this.bounds.max,l=this.bounds.center,o=this.bounds.scale;s.set(1/0),i.set(-1/0);for(let a=0,u=r.length;a<u;a+=n){const g=r[a],p=r[a+1],h=r[a+2];s.x=Math.min(g,s.x),s.y=Math.min(p,s.y),s.z=Math.min(h,s.z),i.x=Math.max(g,i.x),i.y=Math.max(p,i.y),i.z=Math.max(h,i.z)}o.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 Mi=1;const wn={};class Ie{constructor(e,{vertex:r,fragment:n,uniforms:s={},transparent:i=!1,cullFace:l=e.BACK,frontFace:o=e.CCW,depthTest:a=!0,depthWrite:u=!0,depthFunc:g=e.LEQUAL}={}){e.canvas||console.error("gl not passed as first argument to Program"),this.gl=e,this.uniforms=s,this.id=Mi++,r||console.warn("vertex shader not supplied"),n||console.warn("fragment shader not supplied"),this.transparent=i,this.cullFace=l,this.frontFace=o,this.depthTest=a,this.depthWrite=u,this.depthFunc=g,this.blendFunc={},this.blendEquation={},this.stencilFunc={},this.stencilOp={},this.transparent&&!this.blendFunc.src&&(this.gl.renderer.premultipliedAlpha?this.setBlendFunc(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.setBlendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA)),this.vertexShader=e.createShader(e.VERTEX_SHADER),this.fragmentShader=e.createShader(e.FRAGMENT_SHADER),this.program=e.createProgram(),e.attachShader(this.program,this.vertexShader),e.attachShader(this.program,this.fragmentShader),this.setShaders({vertex:r,fragment:n})}setShaders({vertex:e,fragment:r}){if(e&&(this.gl.shaderSource(this.vertexShader,e),this.gl.compileShader(this.vertexShader),this.gl.getShaderInfoLog(this.vertexShader)!==""&&console.warn(`${this.gl.getShaderInfoLog(this.vertexShader)}
3
+ Vertex Shader
4
+ ${Mn(e)}`)),r&&(this.gl.shaderSource(this.fragmentShader,r),this.gl.compileShader(this.fragmentShader),this.gl.getShaderInfoLog(this.fragmentShader)!==""&&console.warn(`${this.gl.getShaderInfoLog(this.fragmentShader)}
5
+ Fragment Shader
6
+ ${Mn(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 o=this.gl.getActiveUniform(this.program,l);this.uniformLocations.set(o,this.gl.getUniformLocation(this.program,o.name));const a=o.name.match(/(\w+)/g);o.uniformName=a[0],o.nameComponents=a.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 o=this.gl.getActiveAttrib(this.program,l),a=this.gl.getAttribLocation(this.program,o.name);a!==-1&&(s[a]=o.name,this.attributeLocations.set(o,a))}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 o of i.nameComponents){if(!l)break;if(o in l)l=l[o];else{if(Array.isArray(l.value))break;l=void 0;break}}if(!l)return An(`Active uniform ${i.name} has not been supplied`);if(l&&l.value===void 0)return An(`${i.name} uniform is missing a value parameter`);if(l.value.texture)return r=r+1,l.value.update(r),Or(this.gl,i.type,s,r);if(l.value.length&&l.value[0].texture){const o=[];return l.value.forEach(a=>{r=r+1,a.update(r),o.push(r)}),Or(this.gl,i.type,s,o)}Or(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 Or(t,e,r,n){n=n.length?Ai(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(Si(s,n))return;s.set?s.set(n):bi(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 Mn(t){let e=t.split(`
7
+ `);for(let r=0;r<e.length;r++)e[r]=r+1+": "+e[r];return e.join(`
8
+ `)}function Ai(t){const e=t.length,r=t[0].length;if(r===void 0)return t;const n=e*r;let s=wn[n];s||(wn[n]=s=new Float32Array(n));for(let i=0;i<e;i++)s.set(t[i],i*r);return s}function Si(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 bi(t,e){for(let r=0,n=t.length;r<n;r++)t[r]=e[r]}let Ir=0;function An(t){Ir>100||(console.warn(t),Ir++,Ir>100&&console.warn("More than 100 program warnings - stopping logs."))}const Dr=new Me;let _i=1;class Ci{constructor({canvas:e=document.createElement("canvas"),width:r=300,height:n=150,dpr:s=1,alpha:i=!1,depth:l=!0,stencil:o=!1,antialias:a=!1,premultipliedAlpha:u=!1,preserveDrawingBuffer:g=!1,powerPreference:p="default",autoClear:h=!0,webgl:v=2}={}){const M={alpha:i,depth:l,stencil:o,antialias:a,premultipliedAlpha:u,preserveDrawingBuffer:g,powerPreference:p};this.dpr=s,this.alpha=i,this.color=!0,this.depth=l,this.stencil=o,this.premultipliedAlpha=u,this.autoClear=h,this.id=_i++,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=[],o=[],a=[];i.forEach(u=>{u.program.transparent?u.program.depthTest?o.push(u):a.push(u):l.push(u),u.zDepth=0,!(u.renderOrder!==0||!u.program.depthTest||!r)&&(u.worldMatrix.getTranslation(Dr),Dr.applyMatrix4(r.projectionViewMatrix),u.zDepth=Dr.z)}),l.sort(this.sortOpaque),o.sort(this.sortTransparent),a.sort(this.sortUI),i=l.concat(o,a)}return i}render({scene:e,camera:r,target:n=null,update:s=!0,sort:i=!0,frustumCull:l=!0,clear:o}){n===null?(this.bindFramebuffer(),this.setViewport(this.width*this.dpr,this.height*this.dpr)):(this.bindFramebuffer(n),this.setViewport(n.width,n.height)),(o||this.autoClear&&o!==!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(u=>{u.draw({camera:r})})}}function Cs(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function Es(t,e,r,n,s){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t}function Ei(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 Fs(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 Ts(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Fi(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function Ti(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 Sn(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=r[0],a=r[1],u=r[2],g=r[3];return t[0]=n*g+l*o+s*u-i*a,t[1]=s*g+l*a+i*o-n*u,t[2]=i*g+l*u+n*a-s*o,t[3]=l*g-n*o-s*a-i*u,t}function Pi(t,e,r){r*=.5;let n=e[0],s=e[1],i=e[2],l=e[3],o=Math.sin(r),a=Math.cos(r);return t[0]=n*a+l*o,t[1]=s*a+i*o,t[2]=i*a-s*o,t[3]=l*a-n*o,t}function Ri(t,e,r){r*=.5;let n=e[0],s=e[1],i=e[2],l=e[3],o=Math.sin(r),a=Math.cos(r);return t[0]=n*a-i*o,t[1]=s*a+l*o,t[2]=i*a+n*o,t[3]=l*a-s*o,t}function Bi(t,e,r){r*=.5;let n=e[0],s=e[1],i=e[2],l=e[3],o=Math.sin(r),a=Math.cos(r);return t[0]=n*a+s*o,t[1]=s*a-n*o,t[2]=i*a+l*o,t[3]=l*a-i*o,t}function Ni(t,e,r,n){let s=e[0],i=e[1],l=e[2],o=e[3],a=r[0],u=r[1],g=r[2],p=r[3],h,v,M,m,y;return v=s*a+i*u+l*g+o*p,v<0&&(v=-v,a=-a,u=-u,g=-g,p=-p),1-v>1e-6?(h=Math.acos(v),M=Math.sin(h),m=Math.sin((1-n)*h)/M,y=Math.sin(n*h)/M):(m=1-n,y=n),t[0]=m*s+y*a,t[1]=m*i+y*u,t[2]=m*l+y*g,t[3]=m*o+y*p,t}function Li(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=r*r+n*n+s*s+i*i,o=l?1/l:0;return t[0]=-r*o,t[1]=-n*o,t[2]=-s*o,t[3]=i*o,t}function Oi(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function Ii(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 Di(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),o=Math.sin(e[2]*.5),a=Math.cos(e[2]*.5);return r==="XYZ"?(t[0]=n*l*a+s*i*o,t[1]=s*i*a-n*l*o,t[2]=s*l*o+n*i*a,t[3]=s*l*a-n*i*o):r==="YXZ"?(t[0]=n*l*a+s*i*o,t[1]=s*i*a-n*l*o,t[2]=s*l*o-n*i*a,t[3]=s*l*a+n*i*o):r==="ZXY"?(t[0]=n*l*a-s*i*o,t[1]=s*i*a+n*l*o,t[2]=s*l*o+n*i*a,t[3]=s*l*a-n*i*o):r==="ZYX"?(t[0]=n*l*a-s*i*o,t[1]=s*i*a+n*l*o,t[2]=s*l*o-n*i*a,t[3]=s*l*a+n*i*o):r==="YZX"?(t[0]=n*l*a+s*i*o,t[1]=s*i*a+n*l*o,t[2]=s*l*o-n*i*a,t[3]=s*l*a-n*i*o):r==="XZY"&&(t[0]=n*l*a-s*i*o,t[1]=s*i*a-n*l*o,t[2]=s*l*o+n*i*a,t[3]=s*l*a+n*i*o),t}const zi=Cs,Ui=Es,Vi=Ts,Gi=Fs;class Gt 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,o){const a=Reflect.set(...arguments);return a&&i.includes(o)&&l.onChange(),a}})}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 Fi(this._target),this.onChange(),this}set(e,r,n,s){return e.length?this.copy(e):(Ui(this._target,e,r,n,s),this.onChange(),this)}rotateX(e){return Pi(this._target,this._target,e),this.onChange(),this}rotateY(e){return Ri(this._target,this._target,e),this.onChange(),this}rotateZ(e){return Bi(this._target,this._target,e),this.onChange(),this}inverse(e=this._target){return Li(this._target,e),this.onChange(),this}conjugate(e=this._target){return Oi(this._target,e),this.onChange(),this}copy(e){return zi(this._target,e),this.onChange(),this}normalize(e=this._target){return Gi(this._target,e),this.onChange(),this}multiply(e,r){return r?Sn(this._target,e,r):Sn(this._target,this._target,e),this.onChange(),this}dot(e){return Vi(this._target,e)}fromMatrix3(e){return Ii(this._target,e),this.onChange(),this}fromEuler(e,r){return Di(this._target,e,e.order),r||this.onChange(),this}fromAxisAngle(e,r){return Ti(this._target,e,r),this.onChange(),this}slerp(e,r){return Ni(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 Hi=1e-6;function ki(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 Wi(t,e,r,n,s,i,l,o,a,u,g,p,h,v,M,m,y){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t[4]=i,t[5]=l,t[6]=o,t[7]=a,t[8]=u,t[9]=g,t[10]=p,t[11]=h,t[12]=v,t[13]=M,t[14]=m,t[15]=y,t}function $i(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 ji(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=e[4],o=e[5],a=e[6],u=e[7],g=e[8],p=e[9],h=e[10],v=e[11],M=e[12],m=e[13],y=e[14],x=e[15],F=r*o-n*l,R=r*a-s*l,C=r*u-i*l,P=n*a-s*o,c=n*u-i*o,f=s*u-i*a,d=g*m-p*M,w=g*y-h*M,S=g*x-v*M,N=p*y-h*m,U=p*x-v*m,L=h*x-v*y,$=F*L-R*U+C*N+P*S-c*w+f*d;return $?($=1/$,t[0]=(o*L-a*U+u*N)*$,t[1]=(s*U-n*L-i*N)*$,t[2]=(m*f-y*c+x*P)*$,t[3]=(h*c-p*f-v*P)*$,t[4]=(a*S-l*L-u*w)*$,t[5]=(r*L-s*S+i*w)*$,t[6]=(y*C-M*f-x*R)*$,t[7]=(g*f-h*C+v*R)*$,t[8]=(l*U-o*S+u*d)*$,t[9]=(n*S-r*U-i*d)*$,t[10]=(M*c-m*C+x*F)*$,t[11]=(p*C-g*c-v*F)*$,t[12]=(o*w-l*N-a*d)*$,t[13]=(r*N-n*w+s*d)*$,t[14]=(m*R-M*P-y*F)*$,t[15]=(g*P-p*R+h*F)*$,t):null}function Ps(t){let e=t[0],r=t[1],n=t[2],s=t[3],i=t[4],l=t[5],o=t[6],a=t[7],u=t[8],g=t[9],p=t[10],h=t[11],v=t[12],M=t[13],m=t[14],y=t[15],x=e*l-r*i,F=e*o-n*i,R=e*a-s*i,C=r*o-n*l,P=r*a-s*l,c=n*a-s*o,f=u*M-g*v,d=u*m-p*v,w=u*y-h*v,S=g*m-p*M,N=g*y-h*M,U=p*y-h*m;return x*U-F*N+R*S+C*w-P*d+c*f}function bn(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=e[4],a=e[5],u=e[6],g=e[7],p=e[8],h=e[9],v=e[10],M=e[11],m=e[12],y=e[13],x=e[14],F=e[15],R=r[0],C=r[1],P=r[2],c=r[3];return t[0]=R*n+C*o+P*p+c*m,t[1]=R*s+C*a+P*h+c*y,t[2]=R*i+C*u+P*v+c*x,t[3]=R*l+C*g+P*M+c*F,R=r[4],C=r[5],P=r[6],c=r[7],t[4]=R*n+C*o+P*p+c*m,t[5]=R*s+C*a+P*h+c*y,t[6]=R*i+C*u+P*v+c*x,t[7]=R*l+C*g+P*M+c*F,R=r[8],C=r[9],P=r[10],c=r[11],t[8]=R*n+C*o+P*p+c*m,t[9]=R*s+C*a+P*h+c*y,t[10]=R*i+C*u+P*v+c*x,t[11]=R*l+C*g+P*M+c*F,R=r[12],C=r[13],P=r[14],c=r[15],t[12]=R*n+C*o+P*p+c*m,t[13]=R*s+C*a+P*h+c*y,t[14]=R*i+C*u+P*v+c*x,t[15]=R*l+C*g+P*M+c*F,t}function qi(t,e,r){let n=r[0],s=r[1],i=r[2],l,o,a,u,g,p,h,v,M,m,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],o=e[1],a=e[2],u=e[3],g=e[4],p=e[5],h=e[6],v=e[7],M=e[8],m=e[9],y=e[10],x=e[11],t[0]=l,t[1]=o,t[2]=a,t[3]=u,t[4]=g,t[5]=p,t[6]=h,t[7]=v,t[8]=M,t[9]=m,t[10]=y,t[11]=x,t[12]=l*n+g*s+M*i+e[12],t[13]=o*n+p*s+m*i+e[13],t[14]=a*n+h*s+y*i+e[14],t[15]=u*n+v*s+x*i+e[15]),t}function Xi(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 Yi(t,e,r,n){let s=n[0],i=n[1],l=n[2],o=Math.hypot(s,i,l),a,u,g,p,h,v,M,m,y,x,F,R,C,P,c,f,d,w,S,N,U,L,$,j;return Math.abs(o)<Hi?null:(o=1/o,s*=o,i*=o,l*=o,a=Math.sin(r),u=Math.cos(r),g=1-u,p=e[0],h=e[1],v=e[2],M=e[3],m=e[4],y=e[5],x=e[6],F=e[7],R=e[8],C=e[9],P=e[10],c=e[11],f=s*s*g+u,d=i*s*g+l*a,w=l*s*g-i*a,S=s*i*g-l*a,N=i*i*g+u,U=l*i*g+s*a,L=s*l*g+i*a,$=i*l*g-s*a,j=l*l*g+u,t[0]=p*f+m*d+R*w,t[1]=h*f+y*d+C*w,t[2]=v*f+x*d+P*w,t[3]=M*f+F*d+c*w,t[4]=p*S+m*N+R*U,t[5]=h*S+y*N+C*U,t[6]=v*S+x*N+P*U,t[7]=M*S+F*N+c*U,t[8]=p*L+m*$+R*j,t[9]=h*L+y*$+C*j,t[10]=v*L+x*$+P*j,t[11]=M*L+F*$+c*j,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function Ki(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Rs(t,e){let r=e[0],n=e[1],s=e[2],i=e[4],l=e[5],o=e[6],a=e[8],u=e[9],g=e[10];return t[0]=Math.hypot(r,n,s),t[1]=Math.hypot(i,l,o),t[2]=Math.hypot(a,u,g),t}function Qi(t){let e=t[0],r=t[1],n=t[2],s=t[4],i=t[5],l=t[6],o=t[8],a=t[9],u=t[10];const g=e*e+r*r+n*n,p=s*s+i*i+l*l,h=o*o+a*a+u*u;return Math.sqrt(Math.max(g,p,h))}const Bs=(function(){const t=[1,1,1];return function(e,r){let n=t;Rs(n,r);let s=1/n[0],i=1/n[1],l=1/n[2],o=r[0]*s,a=r[1]*i,u=r[2]*l,g=r[4]*s,p=r[5]*i,h=r[6]*l,v=r[8]*s,M=r[9]*i,m=r[10]*l,y=o+p+m,x=0;return y>0?(x=Math.sqrt(y+1)*2,e[3]=.25*x,e[0]=(h-M)/x,e[1]=(v-u)/x,e[2]=(a-g)/x):o>p&&o>m?(x=Math.sqrt(1+o-p-m)*2,e[3]=(h-M)/x,e[0]=.25*x,e[1]=(a+g)/x,e[2]=(v+u)/x):p>m?(x=Math.sqrt(1+p-o-m)*2,e[3]=(v-u)/x,e[0]=(a+g)/x,e[1]=.25*x,e[2]=(h+M)/x):(x=Math.sqrt(1+m-o-p)*2,e[3]=(a-g)/x,e[0]=(v+u)/x,e[1]=(h+M)/x,e[2]=.25*x),e}})();function Zi(t,e,r,n){let s=hr([t[0],t[1],t[2]]);const i=hr([t[4],t[5],t[6]]),l=hr([t[8],t[9],t[10]]);Ps(t)<0&&(s=-s),r[0]=t[12],r[1]=t[13],r[2]=t[14];const a=t.slice(),u=1/s,g=1/i,p=1/l;a[0]*=u,a[1]*=u,a[2]*=u,a[4]*=g,a[5]*=g,a[6]*=g,a[8]*=p,a[9]*=p,a[10]*=p,Bs(e,a),n[0]=s,n[1]=i,n[2]=l}function Ji(t,e,r,n){const s=t,i=e[0],l=e[1],o=e[2],a=e[3],u=i+i,g=l+l,p=o+o,h=i*u,v=i*g,M=i*p,m=l*g,y=l*p,x=o*p,F=a*u,R=a*g,C=a*p,P=n[0],c=n[1],f=n[2];return s[0]=(1-(m+x))*P,s[1]=(v+C)*P,s[2]=(M-R)*P,s[3]=0,s[4]=(v-C)*c,s[5]=(1-(h+x))*c,s[6]=(y+F)*c,s[7]=0,s[8]=(M+R)*f,s[9]=(y-F)*f,s[10]=(1-(h+m))*f,s[11]=0,s[12]=r[0],s[13]=r[1],s[14]=r[2],s[15]=1,s}function eo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=r+r,o=n+n,a=s+s,u=r*l,g=n*l,p=n*o,h=s*l,v=s*o,M=s*a,m=i*l,y=i*o,x=i*a;return t[0]=1-p-M,t[1]=g+x,t[2]=h-y,t[3]=0,t[4]=g-x,t[5]=1-u-M,t[6]=v+m,t[7]=0,t[8]=h+y,t[9]=v-m,t[10]=1-u-p,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function to(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 ro(t,e,r,n,s,i,l){let o=1/(e-r),a=1/(n-s),u=1/(i-l);return t[0]=-2*o,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*a,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*u,t[11]=0,t[12]=(e+r)*o,t[13]=(s+n)*a,t[14]=(l+i)*u,t[15]=1,t}function no(t,e,r,n){let s=e[0],i=e[1],l=e[2],o=n[0],a=n[1],u=n[2],g=s-r[0],p=i-r[1],h=l-r[2],v=g*g+p*p+h*h;v===0?h=1:(v=1/Math.sqrt(v),g*=v,p*=v,h*=v);let M=a*h-u*p,m=u*g-o*h,y=o*p-a*g;return v=M*M+m*m+y*y,v===0&&(u?o+=1e-6:a?u+=1e-6:a+=1e-6,M=a*h-u*p,m=u*g-o*h,y=o*p-a*g,v=M*M+m*m+y*y),v=1/Math.sqrt(v),M*=v,m*=v,y*=v,t[0]=M,t[1]=m,t[2]=y,t[3]=0,t[4]=p*y-h*m,t[5]=h*M-g*y,t[6]=g*m-p*M,t[7]=0,t[8]=g,t[9]=p,t[10]=h,t[11]=0,t[12]=s,t[13]=i,t[14]=l,t[15]=1,t}function _n(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 Cn(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 so(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 ft extends Array{constructor(e=1,r=0,n=0,s=0,i=0,l=1,o=0,a=0,u=0,g=0,p=1,h=0,v=0,M=0,m=0,y=1){return super(e,r,n,s,i,l,o,a,u,g,p,h,v,M,m,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,o,a,u,g,p,h,v,M,m,y){return e.length?this.copy(e):(Wi(this,e,r,n,s,i,l,o,a,u,g,p,h,v,M,m,y),this)}translate(e,r=this){return qi(this,r,e),this}rotate(e,r,n=this){return Yi(this,n,e,r),this}scale(e,r=this){return Xi(this,r,typeof e=="number"?[e,e,e]:e),this}add(e,r){return r?_n(this,e,r):_n(this,this,e),this}sub(e,r){return r?Cn(this,e,r):Cn(this,this,e),this}multiply(e,r){return e.length?r?bn(this,e,r):bn(this,this,e):so(this,this,e),this}identity(){return $i(this),this}copy(e){return ki(this,e),this}fromPerspective({fov:e,aspect:r,near:n,far:s}={}){return to(this,e,r,n,s),this}fromOrthogonal({left:e,right:r,bottom:n,top:s,near:i,far:l}){return ro(this,e,r,n,s,i,l),this}fromQuaternion(e){return eo(this,e),this}setPosition(e){return this.x=e[0],this.y=e[1],this.z=e[2],this}inverse(e=this){return ji(this,e),this}compose(e,r,n){return Ji(this,e,r,n),this}decompose(e,r,n){return Zi(this,e,r,n),this}getRotation(e){return Bs(e,this),this}getTranslation(e){return Ki(e,this),this}getScaling(e){return Rs(e,this),this}getMaxScaleOnAxis(){return Qi(this)}lookAt(e,r,n){return no(this,e,r,n),this}determinant(){return Ps(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 io(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 En=new ft;class oo 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,o){const a=Reflect.set(...arguments);return a&&i.includes(o)&&l.onChange(),a}})}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 io(this._target,e,r),this.onChange(),this}fromQuaternion(e,r=this.order,n){return En.fromQuaternion(e),this._target.fromRotationMatrix(En,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 ot{constructor(){this.parent=null,this.children=[],this.visible=!0,this.matrix=new ft,this.worldMatrix=new ft,this.matrixAutoUpdate=!0,this.worldMatrixNeedsUpdate=!1,this.position=new Me,this.quaternion=new Gt,this.scale=new Me(1),this.rotation=new oo,this.up=new Me(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 ao=new ft,lo=new Me,co=new Me;class sn extends ot{constructor(e,{near:r=.1,far:n=100,fov:s=45,aspect:i=1,left:l,right:o,bottom:a,top:u,zoom:g=1}={}){super(),Object.assign(this,{near:r,far:n,fov:s,aspect:i,left:l,right:o,bottom:a,top:u,zoom:g}),this.projectionMatrix=new ft,this.viewMatrix=new ft,this.projectionViewMatrix=new ft,this.worldPosition=new Me,this.type=l||o?"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:o=this.zoom}={}){return Object.assign(this,{near:e,far:r,left:n,right:s,bottom:i,top:l,zoom:o}),n/=o,s/=o,i/=o,l/=o,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(ao.inverse(this.projectionMatrix)),e.applyMatrix4(this.worldMatrix),this}updateFrustum(){this.frustum||(this.frustum=[new Me,new Me,new Me,new Me,new Me,new Me]);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=lo;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=co;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 ho(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 uo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=r+r,o=n+n,a=s+s,u=r*l,g=n*l,p=n*o,h=s*l,v=s*o,M=s*a,m=i*l,y=i*o,x=i*a;return t[0]=1-p-M,t[3]=g-x,t[6]=h+y,t[1]=g+x,t[4]=1-u-M,t[7]=v-m,t[2]=h-y,t[5]=v+m,t[8]=1-u-p,t}function fo(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 mo(t,e,r,n,s,i,l,o,a,u){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t[4]=i,t[5]=l,t[6]=o,t[7]=a,t[8]=u,t}function po(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 go(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=e[4],o=e[5],a=e[6],u=e[7],g=e[8],p=g*l-o*u,h=-g*i+o*a,v=u*i-l*a,M=r*p+n*h+s*v;return M?(M=1/M,t[0]=p*M,t[1]=(-g*n+s*u)*M,t[2]=(o*n-s*l)*M,t[3]=h*M,t[4]=(g*r-s*a)*M,t[5]=(-o*r+s*i)*M,t[6]=v*M,t[7]=(-u*r+n*a)*M,t[8]=(l*r-n*i)*M,t):null}function Fn(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=e[4],a=e[5],u=e[6],g=e[7],p=e[8],h=r[0],v=r[1],M=r[2],m=r[3],y=r[4],x=r[5],F=r[6],R=r[7],C=r[8];return t[0]=h*n+v*l+M*u,t[1]=h*s+v*o+M*g,t[2]=h*i+v*a+M*p,t[3]=m*n+y*l+x*u,t[4]=m*s+y*o+x*g,t[5]=m*i+y*a+x*p,t[6]=F*n+R*l+C*u,t[7]=F*s+R*o+C*g,t[8]=F*i+R*a+C*p,t}function yo(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=e[4],a=e[5],u=e[6],g=e[7],p=e[8],h=r[0],v=r[1];return t[0]=n,t[1]=s,t[2]=i,t[3]=l,t[4]=o,t[5]=a,t[6]=h*n+v*l+u,t[7]=h*s+v*o+g,t[8]=h*i+v*a+p,t}function vo(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=e[4],a=e[5],u=e[6],g=e[7],p=e[8],h=Math.sin(r),v=Math.cos(r);return t[0]=v*n+h*l,t[1]=v*s+h*o,t[2]=v*i+h*a,t[3]=v*l-h*n,t[4]=v*o-h*s,t[5]=v*a-h*i,t[6]=u,t[7]=g,t[8]=p,t}function xo(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 wo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=e[4],o=e[5],a=e[6],u=e[7],g=e[8],p=e[9],h=e[10],v=e[11],M=e[12],m=e[13],y=e[14],x=e[15],F=r*o-n*l,R=r*a-s*l,C=r*u-i*l,P=n*a-s*o,c=n*u-i*o,f=s*u-i*a,d=g*m-p*M,w=g*y-h*M,S=g*x-v*M,N=p*y-h*m,U=p*x-v*m,L=h*x-v*y,$=F*L-R*U+C*N+P*S-c*w+f*d;return $?($=1/$,t[0]=(o*L-a*U+u*N)*$,t[1]=(a*S-l*L-u*w)*$,t[2]=(l*U-o*S+u*d)*$,t[3]=(s*U-n*L-i*N)*$,t[4]=(r*L-s*S+i*w)*$,t[5]=(n*S-r*U-i*d)*$,t[6]=(m*f-y*c+x*P)*$,t[7]=(y*C-M*f-x*R)*$,t[8]=(M*c-m*C+x*F)*$,t):null}class Mo extends Array{constructor(e=1,r=0,n=0,s=0,i=1,l=0,o=0,a=0,u=1){return super(e,r,n,s,i,l,o,a,u),this}set(e,r,n,s,i,l,o,a,u){return e.length?this.copy(e):(mo(this,e,r,n,s,i,l,o,a,u),this)}translate(e,r=this){return yo(this,r,e),this}rotate(e,r=this){return vo(this,r,e),this}scale(e,r=this){return xo(this,r,e),this}multiply(e,r){return r?Fn(this,e,r):Fn(this,this,e),this}identity(){return po(this),this}copy(e){return fo(this,e),this}fromMatrix4(e){return ho(this,e),this}fromQuaternion(e){return uo(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 go(this,e),this}getNormalMatrix(e){return wo(this,e),this}}let Ao=0;class Ke extends ot{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=Ao++,this.geometry=r,this.program=n,this.mode=s,this.frustumCulled=i,this.renderOrder=l,this.modelViewMatrix=new ft,this.normalMatrix=new Mo,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 Tn=new Uint8Array(4);function Pn(t){return(t&t-1)===0}let So=1;class je{constructor(e,{image:r,target:n=e.TEXTURE_2D,type:s=e.UNSIGNED_BYTE,format:i=e.RGBA,internalFormat:l=i,wrapS:o=e.CLAMP_TO_EDGE,wrapT:a=e.CLAMP_TO_EDGE,wrapR:u=e.CLAMP_TO_EDGE,generateMipmaps:g=n===(e.TEXTURE_2D||e.TEXTURE_CUBE_MAP),minFilter:p=g?e.NEAREST_MIPMAP_LINEAR:e.LINEAR,magFilter:h=e.LINEAR,premultiplyAlpha:v=!1,unpackAlignment:M=4,flipY:m=n==(e.TEXTURE_2D||e.TEXTURE_3D),anisotropy:y=0,level:x=0,width:F,height:R=F,length:C=1}={}){this.gl=e,this.id=So++,this.image=r,this.target=n,this.type=s,this.format=i,this.internalFormat=l,this.minFilter=p,this.magFilter=h,this.wrapS=o,this.wrapT=a,this.wrapR=u,this.generateMipmaps=g,this.premultiplyAlpha=v,this.unpackAlignment=M,this.flipY=m,this.anisotropy=Math.min(y,this.gl.renderer.parameters.maxAnisotropy),this.level=x,this.width=F,this.height=R,this.length=C,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&&(!Pn(this.image.width)||!Pn(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,Tn);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,Tn);this.store.image=this.image}}}class Ns{constructor(e,{width:r=e.canvas.width,height:n=e.canvas.height,target:s=e.FRAMEBUFFER,color:i=1,depth:l=!0,stencil:o=!1,depthTexture:a=!1,wrapS:u=e.CLAMP_TO_EDGE,wrapT:g=e.CLAMP_TO_EDGE,wrapR:p=e.CLAMP_TO_EDGE,minFilter:h=e.LINEAR,magFilter:v=h,type:M=e.UNSIGNED_BYTE,format:m=e.RGBA,internalFormat:y=m,unpackAlignment:x,premultiplyAlpha:F}={}){this.gl=e,this.width=r,this.height=n,this.depth=l,this.stencil=o,this.buffer=this.gl.createFramebuffer(),this.target=s,this.gl.renderer.bindFramebuffer(this),this.textures=[];const R=[];for(let C=0;C<i;C++)this.textures.push(new je(e,{width:r,height:n,wrapS:u,wrapT:g,wrapR:p,minFilter:h,magFilter:v,type:M,format:m,internalFormat:y,unpackAlignment:x,premultiplyAlpha:F,flipY:!1,generateMipmaps:!1})),this.textures[C].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+C,this.gl.TEXTURE_2D,this.textures[C].texture,0),R.push(this.gl.COLOR_ATTACHMENT0+C);R.length>1&&this.gl.renderer.drawBuffers(R),this.texture=this.textures[0],a&&(this.gl.renderer.isWebgl2||this.gl.renderer.getExtension("WEBGL_depth_texture"))?(this.depthTexture=new je(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&&!o&&(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)),o&&!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&&o&&(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 bo(t,e){return t[0]=e[0],t[1]=e[1],t}function _o(t,e,r){return t[0]=e,t[1]=r,t}function Rn(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t}function Bn(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t}function Co(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t}function Eo(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t}function zr(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t}function Fo(t,e){var r=e[0]-t[0],n=e[1]-t[1];return Math.sqrt(r*r+n*n)}function To(t,e){var r=e[0]-t[0],n=e[1]-t[1];return r*r+n*n}function Nn(t){var e=t[0],r=t[1];return Math.sqrt(e*e+r*r)}function Po(t){var e=t[0],r=t[1];return e*e+r*r}function Ro(t,e){return t[0]=-e[0],t[1]=-e[1],t}function Bo(t,e){return t[0]=1/e[0],t[1]=1/e[1],t}function No(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 Lo(t,e){return t[0]*e[0]+t[1]*e[1]}function Ln(t,e){return t[0]*e[1]-t[1]*e[0]}function Oo(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 Io(t,e,r,n,s){const i=Math.exp(-n*s);let l=e[0],o=e[1];return t[0]=r[0]+(l-r[0])*i,t[1]=r[1]+(o-r[1])*i,t}function Do(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 zo(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 Uo(t,e){return t[0]===e[0]&&t[1]===e[1]}class ir 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):(_o(this,e,r),this)}copy(e){return bo(this,e),this}add(e,r){return r?Rn(this,e,r):Rn(this,this,e),this}sub(e,r){return r?Bn(this,e,r):Bn(this,this,e),this}multiply(e){return e.length?Co(this,this,e):zr(this,this,e),this}divide(e){return e.length?Eo(this,this,e):zr(this,this,1/e),this}inverse(e=this){return Bo(this,e),this}len(){return Nn(this)}distance(e){return e?Fo(this,e):Nn(this)}squaredLen(){return this.squaredDistance()}squaredDistance(e){return e?To(this,e):Po(this)}negate(e=this){return Ro(this,e),this}cross(e,r){return r?Ln(e,r):Ln(this,e)}scale(e){return zr(this,this,e),this}normalize(){return No(this,this),this}dot(e){return Lo(this,e)}equals(e){return Uo(this,e)}applyMatrix3(e){return Do(this,this,e),this}applyMatrix4(e){return zo(this,this,e),this}lerp(e,r){return Oo(this,this,e,r),this}smoothLerp(e,r,n){return Io(this,this,e,r,n),this}clone(){return new ir(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 Vo 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):(Es(this,e,r,n,s),this)}copy(e){return Cs(this,e),this}normalize(){return Fs(this,this),this}multiply(e){return Ei(this,this,e),this}dot(e){return Ts(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 Pt extends rt{constructor(e,{width:r=1,height:n=1,widthSegments:s=1,heightSegments:i=1,attributes:l={}}={}){const o=s,a=i,u=(o+1)*(a+1),g=o*a*6,p=new Float32Array(u*3),h=new Float32Array(u*3),v=new Float32Array(u*2),M=g>65536?new Uint32Array(g):new Uint16Array(g);Pt.buildPlane(p,h,v,M,r,n,0,o,a),Object.assign(l,{position:{size:3,data:p},normal:{size:3,data:h},uv:{size:2,data:v},index:{data:M}}),super(e,l)}static buildPlane(e,r,n,s,i,l,o,a,u,g=0,p=1,h=2,v=1,M=-1,m=0,y=0){const x=m,F=i/a,R=l/u;for(let C=0;C<=u;C++){let P=C*R-l/2;for(let c=0;c<=a;c++,m++){let f=c*F-i/2;if(e[m*3+g]=f*v,e[m*3+p]=P*M,e[m*3+h]=o/2,r[m*3+g]=0,r[m*3+p]=0,r[m*3+h]=o>=0?1:-1,n[m*2]=c/a,n[m*2+1]=1-C/u,C===u||c===a)continue;let d=x+c+C*(a+1),w=x+c+(C+1)*(a+1),S=x+c+(C+1)*(a+1)+1,N=x+c+C*(a+1)+1;s[y*6]=d,s[y*6+1]=w,s[y*6+2]=N,s[y*6+3]=w,s[y*6+4]=S,s[y*6+5]=N,y++}}}}class On extends rt{constructor(e,{width:r=1,height:n=1,depth:s=1,widthSegments:i=1,heightSegments:l=1,depthSegments:o=1,attributes:a={}}={}){const u=i,g=l,p=o,h=(u+1)*(g+1)*2+(u+1)*(p+1)*2+(g+1)*(p+1)*2,v=(u*g*2+u*p*2+g*p*2)*6,M=new Float32Array(h*3),m=new Float32Array(h*3),y=new Float32Array(h*2),x=h>65536?new Uint32Array(v):new Uint16Array(v);let F=0,R=0;Pt.buildPlane(M,m,y,x,s,n,r,p,g,2,1,0,-1,-1,F,R),F+=(p+1)*(g+1),R+=p*g,Pt.buildPlane(M,m,y,x,s,n,-r,p,g,2,1,0,1,-1,F,R),F+=(p+1)*(g+1),R+=p*g,Pt.buildPlane(M,m,y,x,r,s,n,p,u,0,2,1,1,1,F,R),F+=(u+1)*(p+1),R+=u*p,Pt.buildPlane(M,m,y,x,r,s,-n,p,u,0,2,1,1,-1,F,R),F+=(u+1)*(p+1),R+=u*p,Pt.buildPlane(M,m,y,x,r,n,-s,u,g,0,1,2,-1,-1,F,R),F+=(u+1)*(g+1),R+=u*g,Pt.buildPlane(M,m,y,x,r,n,s,u,g,0,1,2,1,-1,F,R),Object.assign(a,{position:{size:3,data:M},normal:{size:3,data:m},uv:{size:2,data:y},index:{data:x}}),super(e,a)}}class In extends rt{constructor(e,{radiusTop:r=.5,radiusBottom:n=.5,height:s=1,radialSegments:i=8,heightSegments:l=1,openEnded:o=!1,thetaStart:a=0,thetaLength:u=Math.PI*2,attributes:g={}}={}){const p=i,h=l,v=a,M=u,m=o?0:n&&r?2:1,y=(p+1)*(h+1+m)+m,x=p*h*6+m*p*3,F=new Float32Array(y*3),R=new Float32Array(y*3),C=new Float32Array(y*2),P=y>65536?new Uint32Array(x):new Uint16Array(x);let c=0,f=0;const d=[];w(),o||(r&&S(!0),n&&S(!1));function w(){let N,U;const L=new Me,$=(n-r)/s;for(U=0;U<=h;U++){const j=[],oe=U/h,Y=oe*(n-r)+r;for(N=0;N<=p;N++){const O=N/p,k=O*M+v,V=Math.sin(k),X=Math.cos(k);F.set([Y*V,(.5-oe)*s,Y*X],c*3),L.set(V,$,X).normalize(),R.set([L.x,L.y,L.z],c*3),C.set([O,1-oe],c*2),j.push(c++)}d.push(j)}for(N=0;N<p;N++)for(U=0;U<h;U++){const j=d[U][N],oe=d[U+1][N],Y=d[U+1][N+1],O=d[U][N+1];P.set([j,oe,O,oe,Y,O],f*3),f+=2}}function S(N){let U;const L=N===!0?r:n,$=N===!0?1:-1,j=c;for(F.set([0,.5*s*$,0],c*3),R.set([0,$,0],c*3),C.set([.5,.5],c*2),c++,U=0;U<=p;U++){const Y=U/p*M+v,O=Math.cos(Y),k=Math.sin(Y);F.set([L*k,.5*s*$,L*O],c*3),R.set([0,$,0],c*3),C.set([O*.5+.5,k*.5*$+.5],c*2),c++}for(U=0;U<p;U++){const oe=j+U+1;N?P.set([oe,oe+1,j],f*3):P.set([oe+1,oe,j],f*3),f++}}Object.assign(g,{position:{size:3,data:F},normal:{size:3,data:R},uv:{size:2,data:C},index:{data:P}}),super(e,g)}}class Go extends rt{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 Ho extends rt{constructor(e,{radius:r=.5,tube:n=.2,radialSegments:s=8,tubularSegments:i=6,arc:l=Math.PI*2,attributes:o={}}={}){const a=(s+1)*(i+1),u=s*i*6,g=new Float32Array(a*3),p=new Float32Array(a*3),h=new Float32Array(a*2),v=a>65536?new Uint32Array(u):new Uint16Array(u),M=new Me,m=new Me,y=new Me;let x=0;for(let F=0;F<=s;F++)for(let R=0;R<=i;R++,x++){const C=R/i*l,P=F/s*Math.PI*2;m.x=(r+n*Math.cos(P))*Math.cos(C),m.y=(r+n*Math.cos(P))*Math.sin(C),m.z=n*Math.sin(P),g.set([m.x,m.y,m.z],x*3),M.x=r*Math.cos(C),M.y=r*Math.sin(C),y.sub(m,M).normalize(),p.set([y.x,y.y,y.z],x*3),h.set([R/i,F/s],x*2)}x=0;for(let F=1;F<=s;F++)for(let R=1;R<=i;R++,x++){const C=(i+1)*F+R-1,P=(i+1)*(F-1)+R-1,c=(i+1)*(F-1)+R,f=(i+1)*F+R;v.set([C,P,f,P,c,f],x*6)}Object.assign(o,{position:{size:3,data:g},normal:{size:3,data:p},uv:{size:2,data:h},index:{data:v}}),super(e,o)}}const ko=new ir,Wo=new ir,$o=new ir,Ur=new Me,Dn=new Me,zn=new Me,jo=new Me,qo=new Me,Xo=new Me,Un=new Me,Vr=new Me,Vn=new Me,Gn=new Me,Yo=new Me,Hn=new ft;class Ko{constructor(){this.origin=new Me,this.direction=new Me}castMouse(e,r=[0,0]){if(e.type==="orthographic"){const{left:n,right:s,bottom:i,top:l,zoom:o}=e,a=n/o+(s-n)/o*(r[0]*.5+.5),u=i/o+(l-i)/o*(r[1]*.5+.5);this.origin.set(a,u,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=Hn,i=Ur,l=Dn,o=n;return o.length=0,e.forEach(a=>{(!a.geometry.bounds||a.geometry.bounds.radius===1/0)&&a.geometry.computeBoundingSphere();const u=a.geometry.bounds;s.inverse(a.worldMatrix);let g;if(r&&(l.copy(this.direction).scaleRotateMatrix4(s),g=r*l.len()),i.copy(this.origin).applyMatrix4(s),l.copy(this.direction).transformDirection(s),r&&i.distance(u.center)-u.radius>g)return;let p=0;if(a.geometry.raycast==="sphere"){if(i.distance(u.center)>u.radius&&(p=this.intersectSphere(u,i,l),!p))return}else if((i.x<u.min.x||i.x>u.max.x||i.y<u.min.y||i.y>u.max.y||i.z<u.min.z||i.z>u.max.z)&&(p=this.intersectBox(u,i,l),!p))return;r&&p>g||(a.hit||(a.hit={localPoint:new Me,point:new Me}),a.hit.localPoint.copy(l).multiply(p).add(i),a.hit.point.copy(a.hit.localPoint).applyMatrix4(a.worldMatrix),a.hit.distance=a.hit.point.distance(this.origin),o.push(a))}),o.sort((a,u)=>a.hit.distance-u.hit.distance),o}intersectMeshes(e,{cullFace:r=!0,maxDistance:n,includeUV:s=!0,includeNormal:i=!0,output:l=[]}={}){const o=this.intersectBounds(e,{maxDistance:n,output:l});if(!o.length)return o;const a=Hn,u=Ur,g=Dn,p=zn,h=jo,v=qo,M=Xo,m=Un,y=Vr,x=ko,F=Wo,R=$o;for(let C=o.length-1;C>=0;C--){const P=o[C];a.inverse(P.worldMatrix);let c;n&&(g.copy(this.direction).scaleRotateMatrix4(a),c=n*g.len()),u.copy(this.origin).applyMatrix4(a),g.copy(this.direction).transformDirection(a);let f=0,d,w,S;const N=P.geometry,U=N.attributes,L=U.index,$=U.position,j=Math.max(0,N.drawRange.start),oe=Math.min(L?L.count:$.count,N.drawRange.start+N.drawRange.count),Y=$.size;for(let O=j;O<oe;O+=3){const k=L?L.data[O]:O,V=L?L.data[O+1]:O+1,X=L?L.data[O+2]:O+2;p.fromArray($.data,k*Y),h.fromArray($.data,V*Y),v.fromArray($.data,X*Y);const le=this.intersectTriangle(p,h,v,r,u,g,m);le&&(n&&le>c||(!f||le<f)&&(f=le,d=k,w=V,S=X,M.copy(m)))}f||o.splice(C,1),P.hit.localPoint.copy(g).multiply(f).add(u),P.hit.point.copy(P.hit.localPoint).applyMatrix4(P.worldMatrix),P.hit.distance=P.hit.point.distance(this.origin),P.hit.faceNormal||(P.hit.localFaceNormal=new Me,P.hit.faceNormal=new Me,P.hit.uv=new ir,P.hit.localNormal=new Me,P.hit.normal=new Me),P.hit.localFaceNormal.copy(M),P.hit.faceNormal.copy(P.hit.localFaceNormal).transformDirection(P.worldMatrix),(s||i)&&(p.fromArray($.data,d*3),h.fromArray($.data,w*3),v.fromArray($.data,S*3),this.getBarycoord(P.hit.localPoint,p,h,v,y)),s&&U.uv&&(x.fromArray(U.uv.data,d*2),F.fromArray(U.uv.data,w*2),R.fromArray(U.uv.data,S*2),P.hit.uv.set(x.x*y.x+F.x*y.y+R.x*y.z,x.y*y.x+F.y*y.y+R.y*y.z)),i&&U.normal&&(p.fromArray(U.normal.data,d*3),h.fromArray(U.normal.data,w*3),v.fromArray(U.normal.data,S*3),P.hit.localNormal.set(p.x*y.x+h.x*y.y+v.x*y.z,p.y*y.x+h.y*y.y+v.y*y.z,p.z*y.x+h.z*y.y+v.z*y.z),P.hit.normal.copy(P.hit.localNormal).transformDirection(P.worldMatrix))}return o.sort((C,P)=>C.hit.distance-P.hit.distance),o}intersectPlane(e,r=this.origin,n=this.direction){const s=Ur;s.sub(e.origin,r);const i=s.dot(e.normal),l=n.dot(e.normal);if(l==0)return 0;const o=i/l;return o<=0?0:r.add(n.scale(o))}intersectSphere(e,r=this.origin,n=this.direction){const s=zn;s.sub(e.center,r);const i=s.dot(n),l=s.dot(s)-i*i,o=e.radius*e.radius;if(l>o)return 0;const a=Math.sqrt(o-l),u=i-a,g=i+a;return u<0&&g<0?0:u<0?g:u}intersectBox(e,r=this.origin,n=this.direction){let s,i,l,o,a,u;const g=1/n.x,p=1/n.y,h=1/n.z,v=e.min,M=e.max;return s=((g>=0?v.x:M.x)-r.x)*g,i=((g>=0?M.x:v.x)-r.x)*g,l=((p>=0?v.y:M.y)-r.y)*p,o=((p>=0?M.y:v.y)-r.y)*p,s>o||l>i||(l>s&&(s=l),o<i&&(i=o),a=((h>=0?v.z:M.z)-r.z)*h,u=((h>=0?M.z:v.z)-r.z)*h,s>u||a>i)||(a>s&&(s=a),u<i&&(i=u),i<0)?0:s>=0?s:i}intersectTriangle(e,r,n,s=!0,i=this.origin,l=this.direction,o=Un){const a=Vr,u=Vn,g=Gn;a.sub(r,e),u.sub(n,e),o.cross(a,u);let p=l.dot(o);if(!p)return 0;let h;if(p>0){if(s)return 0;h=1}else h=-1,p=-p;g.sub(i,e);let v=h*l.dot(u.cross(g,u));if(v<0)return 0;let M=h*l.dot(a.cross(g));if(M<0||v+M>p)return 0;let m=-h*g.dot(o);return m<0?0:m/p}getBarycoord(e,r,n,s,i=Vr){const l=Vn,o=Gn,a=Yo;l.sub(s,r),o.sub(n,r),a.sub(e,r);const u=l.dot(l),g=l.dot(o),p=l.dot(a),h=o.dot(o),v=o.dot(a),M=u*h-g*g;if(M===0)return i.set(-2,-1,-1);const m=1/M,y=(h*p-g*v)*m,x=(u*v-g*p)*m;return i.set(1-y-x,x,y)}}const Qo=`
9
+ precision highp float;
10
+ precision highp int;
11
+
12
+ attribute vec3 position;
13
+ attribute vec3 normal;
14
+
15
+ uniform mat3 normalMatrix;
16
+ uniform mat4 modelViewMatrix;
17
+ uniform mat4 projectionMatrix;
18
+
19
+ varying vec3 vNormal;
20
+
21
+ void main() {
22
+ vNormal = normalize(normalMatrix * normal);
23
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
24
+ }
25
+ `,Zo=`
26
+ precision highp float;
27
+ precision highp int;
28
+
29
+ varying vec3 vNormal;
30
+
31
+ void main() {
32
+ gl_FragColor.rgb = normalize(vNormal);
33
+ gl_FragColor.a = 1.0;
34
+ }
35
+ `;function Jo(t){return new Ie(t,{vertex:Qo,fragment:Zo,cullFace:!1})}const kn=new Me,ea=new Me,ta=new Me,ra=new Me,Wn=new Gt,na=new Gt,sa=new Gt,ia=new Gt;class oa{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:o,times:a,values:u})=>{if(!this.duration){let F=kn,R=3;l==="quaternion"&&(F=Wn,R=4),F.fromArray(u,0),R===4?i[l].slerp(F,n):i[l].lerp(F,n);return}const g=Math.max(1,a.findIndex(F=>F>s))-1,p=g+1;let h=(s-a[g])/(a[p]-a[g]);o==="STEP"&&(h=0);let v=kn,M=ea,m=ta,y=ra,x=3;l==="quaternion"&&(v=Wn,M=na,m=sa,y=ia,x=4),o==="CUBICSPLINE"?(v.fromArray(u,g*x*3+x*1),M.fromArray(u,g*x*3+x*2),m.fromArray(u,p*x*3+x*0),y.fromArray(u,p*x*3+x*1),v=this.cubicSplineInterpolate(h,v,M,m,y),x===4&&v.normalize()):(v.fromArray(u,g*x),y.fromArray(u,p*x),x===4?v.slerp(y,h):v.lerp(y,h)),x===4?i[l].slerp(v,n):i[l].lerp(v,n)})}cubicSplineInterpolate(e,r,n,s,i){const l=e*e,o=l*e,a=3*l-2*o,u=o-l,g=1-a,p=u-l+e;for(let h=0;h<r.length;h++)r[h]=g*r[h]+p*(1-e)*n[h]+a*i[h]+u*e*s[h];return r}}const $n=new ft,aa=new ft;class vt extends Ke{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 je(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)=>{$n.multiply(e.worldMatrix,e.bindInverse),this.boneMatrices.set($n,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=aa,super.draw({camera:e}),this.worldMatrix=r}}class la extends Ke{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 ot;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 Vo().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 jn={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array,"image/jpeg":Uint8Array,"image/png":Uint8Array,"image/webp":Uint8Array},ca={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},qn={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},ha={translation:"position",rotation:"quaternion",scale:"scale"};class Xn{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,F;(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()"),(F=r.extensionsRequired)!=null&&F.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),o=this.parseTextures(e,r,l),a=this.parseMaterials(e,r,o),u=this.parseSkins(e,r,i),g=await this.parseMeshes(e,r,i,a,u),[p,h]=this.parseNodes(e,r,g,u,l);this.populateSkins(u,p);const v=this.parseAnimations(e,r,p,i),M=this.parseScenes(r,p),m=M[r.scene],y=this.parseLights(e,r,p,M);for(let R=p.length;R>=0;R--)p[R]||p.splice(R,1);return{json:r,buffers:s,bufferViews:i,cameras:h,images:l,textures:o,materials:a,meshes:g,nodes:p,lights:y,animations:v,scenes:M,scene:m}}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)),o=JSON.parse(l);if(s+i===e.byteLength)return o;const a=new Uint32Array(e,s+i,2);if(a[1]!==5130562)throw new Error("Unexpected GLB layout.");const u=s+i+8,g=a[0],p=e.slice(u,u+g);return o.buffers[0].binary=p,o}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:o,extensions:a})=>{for(const u in l){const g=r.accessors[l[u]];g.bufferView===void 0&&a&&a.KHR_draco_mesh_compression&&(g.bufferView=a.KHR_draco_mesh_compression.bufferView,s[g.bufferView].isDraco=!0),s[g.bufferView].isAttribute=!0}if(o!==void 0){const u=r.accessors[o];u.bufferView===void 0&&a&&a.KHR_draco_mesh_compression&&(u.bufferView=a.KHR_draco_mesh_compression.bufferView,s[u.bufferView].isDraco=!0),s[u.bufferView].isAttribute=!0,s[u.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:o})=>{l!==void 0&&(s[l].mimeType=o)}),s.forEach(({buffer:i,byteOffset:l=0,byteLength:o,byteStride:a,target:u=e.ARRAY_BUFFER,name:g,extensions:p,extras:h,componentType:v,mimeType:M,isAttribute:m,isDraco:y},x)=>{if(s[x].data=n[i].slice(l,l+o),!m||y)return;const F=e.createBuffer();e.bindBuffer(u,F),e.renderer.state.boundBuffer=F,e.bufferData(u,s[x].data,e.STATIC_DRAW),s[x].buffer=F}),s}static parseImages(e,r,n,s){return r.images?Promise.all(r.images.map(async({uri:i,bufferView:l,mimeType:o,name:a})=>{if(o==="image/ktx2"){const{data:g}=s[l];return await this.basisManager.parseTexture(g)}const u=new Image;if(u.name=a,i)u.src=this.resolveURI(i,n);else if(l!==void 0){const{data:g}=s[l],p=new Blob([g],{type:o});u.src=URL.createObjectURL(p)}return u.ready=new Promise(g=>{u.onload=()=>g()}),u})):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:o,extras:a}){i===void 0&&o&&(o.EXT_texture_webp&&(i=o.EXT_texture_webp.source),o.KHR_texture_basisu&&(i=o.KHR_texture_basisu.source));const u=n[i];if(u.texture)return u.texture;const g={flipY:!1,wrapS:e.REPEAT,wrapT:e.REPEAT},p=s!==void 0?r.samplers[s]:null;if(p&&["magFilter","minFilter","wrapS","wrapT"].forEach(v=>{p[v]&&(g[v]=p[v])}),u.isBasis){g.image=u,g.internalFormat=u.internalFormat,u.isCompressedTexture&&(g.generateMipmaps=!1,u.length>1&&(this.minFilter=e.NEAREST_MIPMAP_LINEAR));const v=new je(e,g);return v.name=l,u.texture=v,v}const h=new je(e,g);return h.name=l,u.texture=h,u.ready.then(()=>{h.image=u}),h}static parseMaterials(e,r,n){return r.materials?r.materials.map(({name:s,extensions:i,extras:l,pbrMetallicRoughness:o={},normalTexture:a,occlusionTexture:u,emissiveTexture:g,emissiveFactor:p=[0,0,0],alphaMode:h="OPAQUE",alphaCutoff:v=.5,doubleSided:M=!1})=>{const{baseColorFactor:m=[1,1,1,1],baseColorTexture:y,metallicFactor:x=1,roughnessFactor:F=1,metallicRoughnessTexture:R}=o;return y&&(y.texture=n[y.index]),a&&(a.texture=n[a.index]),R&&(R.texture=n[R.index]),u&&(u.texture=n[u.index]),g&&(g.texture=n[g.index]),{name:s,extensions:i,extras:l,baseColorFactor:m,baseColorTexture:y,metallicFactor:x,roughnessFactor:F,metallicRoughnessTexture:R,normalTexture:a,occlusionTexture:u,emissiveTexture:g,emissiveFactor:p,alphaMode:h,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:o,name:a,extensions:u,extras:g={}},p)=>{let h=0,v=[],M=!1;return r.nodes&&r.nodes.forEach(({mesh:y,skin:x,extras:F})=>{y===p&&(h++,x!==void 0&&v.push(x),F&&F.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:F,mode:R})=>{const C=new vt(e,{skeleton:i[y],geometry:x,program:F,mode:R});return C.name=a,C.extras=g,u&&(C.extensions=u),C.frustumCulled=!1,C}))),l.instanceCount=0,l.numInstances=h):l=(await this.parsePrimitives(e,l,r,n,s,h,M)).map(({geometry:y,program:x,mode:F})=>{const R=y.attributes.instanceMatrix?la:Ke,C=new R(e,{geometry:y,program:x,mode:F});return C.name=a,C.extras=g,u&&(C.extensions=u),C.numInstances=h,C}),{primitives:l,weights:o,name:a}})):null}static parsePrimitives(e,r,n,s,i,l,o){return Promise.all(r.map(async({attributes:a,indices:u,material:g,mode:p=4,targets:h,extensions:v,extras:M})=>{const m=new Jo(e);g!==void 0&&(m.gltfMaterial=i[g]);const y=new rt(e);if(M&&(y.extras=M),v&&(y.extensions=v),v&&v.KHR_draco_mesh_compression){const x=v.KHR_draco_mesh_compression.bufferView,F=v.KHR_draco_mesh_compression.attributes,R={},C={},P={},c={};for(const w in a){const S=n.accessors[a[w]],N=qn[w];R[N]=F[w],C[N]=S.componentType,P[N]=jn[S.componentType].name,c[N]=S.normalized===!0}const{data:f}=s[x],d=await this.dracoManager.decodeGeometry(f,{attributeIds:R,attributeTypes:P});for(let w=0;w<d.attributes.length;w++){const S=d.attributes[w],N=S.name,U=S.array,L=S.itemSize,$=C[N],j=c[N],oe=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,oe),e.renderer.state.boundBuffer=oe,e.bufferData(e.ARRAY_BUFFER,U,e.STATIC_DRAW),y.addAttribute(N,{data:U,size:L,type:$,normalized:j,buffer:oe})}if(d.index){const w=d.index.array,S=d.index.itemSize,N=e.createBuffer();e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,N),e.renderer.state.boundBuffer=N,e.bufferData(e.ELEMENT_ARRAY_BUFFER,w,e.STATIC_DRAW),y.addAttribute("index",{data:w,size:S,type:5125,normalized:!1,buffer:N})}}else{for(const x in a)y.addAttribute(qn[x],this.parseAccessor(a[x],n,s));u!==void 0&&y.addAttribute("index",this.parseAccessor(u,n,s))}return l>1&&y.addAttribute("instanceMatrix",{instanced:1,size:16,data:new Float32Array(l*16)}),o&&y.addAttribute("lightmapScaleOffset",{instanced:1,size:4,data:new Float32Array(l*4)}),{geometry:y,program:m,mode:p}}))}static parseAccessor(e,r,n){const{bufferView:s,byteOffset:i=0,componentType:l,normalized:o=!1,count:a,type:u,min:g,max:p,sparse:h}=r.accessors[e],{data:v,buffer:M,byteOffset:m=0,byteStride:y=0,target:x}=n[s],F=ca[u],R=jn[l],C=R.BYTES_PER_ELEMENT,P=y/C,c=!!y&&P!==F;let f;if(c){const d=new R(v,i);f=new R(a*F);for(let w=0;w<a;w++){const S=P*w,N=S+F;f.set(d.slice(S,N),w*F)}}else f=new R(v,i,a*F);return{data:f,size:F,type:l,normalized:o,buffer:M,stride:y,offset:i,count:a,min:g,max:p}}static parseNodes(e,r,n,s,i){if(!r.nodes)return null;const l=[],o=r.nodes.map(({camera:a,children:u,skin:g,matrix:p,mesh:h,rotation:v,scale:M,translation:m,weights:y,name:x,extensions:F,extras:R})=>{const C=a!==void 0,P=C?new sn(e):new ot;if(C){const S=r.cameras[a];if(S.type==="perspective"){const{yfov:N,znear:U,zfar:L}=S.perspective;P.perspective({fov:N*(180/Math.PI),near:U,far:L})}else{const{xmag:N,ymag:U,znear:L,zfar:$}=S.orthographic;P.orthographic({near:L,far:$,left:-N,right:N,top:-U,bottom:U})}l.push(P)}x&&(P.name=x),R&&(P.extras=R),F&&(P.extensions=F),R&&R.lightmapTexture!==void 0&&(R.lightmapTexture.texture=this.createTexture(e,r,i,{source:R.lightmapTexture.index})),p?(P.matrix.copy(p),P.decompose()):(v&&P.quaternion.copy(v),M&&P.scale.copy(M),m&&P.position.copy(m),P.updateMatrix());let c=!1,f=!0,d=!1;if(h!==void 0&&(g!==void 0?(n[h].primitives[n[h].primitives.instanceCount].forEach(S=>{R&&Object.assign(S.extras,R),S.setParent(P)}),n[h].primitives.instanceCount++,n[h].primitives.instanceCount===n[h].primitives.numInstances&&(delete n[h].primitives.numInstances,delete n[h].primitives.instanceCount)):n[h].primitives.forEach(S=>{R&&Object.assign(S.extras,R),S.geometry.isInstanced&&(c=!0,S.instanceCount?f=!1:S.instanceCount=0,S.geometry.attributes.instanceMatrix&&(d=!0,P.matrix.toArray(S.geometry.attributes.instanceMatrix.data,S.instanceCount*16)),S.geometry.attributes.lightmapScaleOffset&&S.geometry.attributes.lightmapScaleOffset.data.set(R.lightmap_scale_offset,S.instanceCount*4),S.instanceCount++,S.instanceCount===S.numInstances&&(delete S.numInstances,delete S.instanceCount,S.geometry.attributes.instanceMatrix&&(S.geometry.attributes.instanceMatrix.needsUpdate=!0),S.geometry.attributes.lightmapScaleOffset&&(S.geometry.attributes.lightmapScaleOffset.needsUpdate=!0))),c?f&&S.setParent(P):S.setParent(P)})),d){if(!f)return null;P.matrix.identity(),P.decompose()}return P});return r.nodes.forEach(({children:a=[]},u)=>{a.forEach(g=>{o[g]&&o[g].setParent(o[u])})}),n.forEach(({primitives:a},u)=>{a.forEach((g,p)=>{g.isInstancedMesh&&g.addFrustumCull()})}),[o,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 ft(...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:o},a)=>{const u=i.map(({sampler:g,target:p})=>{const{input:h,interpolation:v="LINEAR",output:M}=l[g],{node:m,path:y}=p,x=n[m],F=ha[y],R=this.parseAccessor(h,r,s).data,C=this.parseAccessor(M,r,s).data;return x.animations||(x.animations=[]),x.animations.includes(a)||x.animations.push(a),{node:x,transform:F,interpolation:v,times:R,values:C}});return{name:o,animation:new oa(u)}}):null}static parseScenes(e,r){return e.scenes?e.scenes.map(({nodes:n=[],name:s,extensions:i,extras:l})=>{const o=n.reduce((a,u)=>(r[u]&&a.push(r[u]),a),[]);return o.extras=l,o}):null}static parseLights(e,r,n,s){var o,a;const i={directional:[],point:[],spot:[]};s.forEach(u=>u.forEach(g=>g.updateMatrixWorld()));const l=((a=(o=r.extensions)==null?void 0:o.KHR_lights_punctual)==null?void 0:a.lights)||[];return n.forEach(u=>{var v;if(!((v=u==null?void 0:u.extensions)!=null&&v.KHR_lights_punctual))return;const g=u.extensions.KHR_lights_punctual.light,p=l[g],h={name:p.name||"",color:{value:new Me().set(p.color||1)}};switch(p.intensity!==void 0&&h.color.value.multiply(p.intensity),p.type){case"directional":h.direction={value:new Me(0,0,1).transformDirection(u.worldMatrix)};break;case"point":h.position={value:new Me().applyMatrix4(u.worldMatrix)},h.distance={value:p.range},h.decay={value:2};break;case"spot":Object.assign(h,p);break}i[p.type].push(h)}),i}}const ua={fetch:Ys,getBuffer:Qs,getBlob:Ks,putBuffer:ei,putLocalBuffer:ti,hasLocalBuffer:Js,getLocalName:Zs,getPlayer:ri,removePlayers:Xs},He=()=>{const t=new Float32Array(16);return t[0]=t[5]=t[10]=t[15]=1,t},ut=(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],o=r[n*4+3];t[n*4]=e[0]*s+e[4]*i+e[8]*l+e[12]*o,t[n*4+1]=e[1]*s+e[5]*i+e[9]*l+e[13]*o,t[n*4+2]=e[2]*s+e[6]*i+e[10]*l+e[14]*o,t[n*4+3]=e[3]*s+e[7]*i+e[11]*l+e[15]*o}return t},wt=t=>{const e=t[0],r=t[1],n=t[2],s=t[4],i=t[5],l=t[6],o=t[8],a=t[9],u=t[10],g=e*(i*u-l*a)-s*(r*u-n*a)+o*(r*l-n*i),p=g===0?0:1/g,h=new Float32Array(16);h[0]=(i*u-l*a)*p,h[1]=(n*a-r*u)*p,h[2]=(r*l-n*i)*p,h[4]=(l*o-s*u)*p,h[5]=(e*u-n*o)*p,h[6]=(n*s-e*l)*p,h[8]=(s*a-i*o)*p,h[9]=(r*o-e*a)*p,h[10]=(e*i-r*s)*p;const v=t[12],M=t[13],m=t[14];return h[12]=-(h[0]*v+h[4]*M+h[8]*m),h[13]=-(h[1]*v+h[5]*M+h[9]*m),h[14]=-(h[2]*v+h[6]*M+h[10]*m),h[15]=1,h},pr=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])],Ls=(t,e,r,n,s)=>{const[i,l,o]=pr(t),a=Math.hypot(e,r,n,s)||1,u=e/a,g=r/a,p=n/a,h=s/a,v=u*u,M=u*g,m=u*p,y=u*h,x=g*g,F=g*p,R=g*h,C=p*p,P=p*h;t[0]=(1-2*(x+C))*i,t[1]=2*(M+P)*i,t[2]=2*(m-R)*i,t[4]=2*(M-P)*l,t[5]=(1-2*(v+C))*l,t[6]=2*(F+y)*l,t[8]=2*(m+R)*o,t[9]=2*(F-y)*o,t[10]=(1-2*(v+x))*o},Vt=Math.PI/180,fa=(t,e,r,n,s)=>{const[i,l,o]=pr(t),a=e*Vt,u=r*Vt,g=n*Vt,p=Math.cos(a),h=Math.sin(a),v=Math.cos(u),M=Math.sin(u),m=Math.cos(g),y=Math.sin(g);let x=1,F=0,R=0,C=0,P=1,c=0,f=0,d=0,w=1;switch(s){case 0:x=v*m,F=-v*y,R=M,C=h*M*m+p*y,P=-h*M*y+p*m,c=-h*v,f=-p*M*m+h*y,d=p*M*y+h*m,w=p*v;break;case 1:x=v*m+M*h*y,F=-v*y+M*h*m,R=M*p,C=p*y,P=p*m,c=-h,f=-M*m+v*h*y,d=M*y+v*h*m,w=v*p;break;case 2:x=v*m-M*h*y,F=-p*y,R=M*m+v*h*y,C=v*y+M*h*m,P=p*m,c=M*y-v*h*m,f=-M*p,d=h,w=v*p;break;case 3:x=v*m,F=h*M*m-p*y,R=p*M*m+h*y,C=v*y,P=h*M*y+p*m,c=p*M*y-h*m,f=-M,d=h*v,w=p*v;break;case 4:x=v*m,F=-y,R=M*m,C=h*M+p*v*y,P=p*m,c=-v*h+p*M*y,f=-p*M+h*v*y,d=h*m,w=p*v+h*M*y;break;case 5:x=v*m,F=-v*y,R=M,C=p*y+h*M*m,P=p*m-h*M*y,c=-h*v,f=h*y-p*M*m,d=h*m+p*M*y,w=p*v;break}t[0]=x*i,t[1]=C*i,t[2]=f*i,t[4]=F*l,t[5]=P*l,t[6]=d*l,t[8]=R*o,t[9]=c*o,t[10]=w*o},Os=(t,e,r,n)=>{const[s,i,l]=pr(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 o=e/s,a=r/i,u=n/l;t[0]*=o,t[1]*=o,t[2]*=o,t[4]*=a,t[5]*=a,t[6]*=a,t[8]*=u,t[9]*=u,t[10]*=u},Yn=t=>{const[e,r,n]=pr(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 o=t[5]/r,a=t[8]/n,u=t[9]/n,g=t[10]/n,p=Math.asin(-Math.min(1,Math.max(-1,u)));let h,v;return Math.abs(u)<.9999?(h=Math.atan2(a,g),v=Math.atan2(i,o)):(h=Math.atan2(-l,s),v=0),[p/Vt,h/Vt,v/Vt]},Is=(t,e,r)=>{const n=He();return Ls(n,e[0],e[1],e[2],e[3]),Os(n,r[0],r[1],r[2]),n[12]=t[0],n[13]=t[1],n[14]=t[2],n},Ds=(t,e,r,n)=>{const s=1/Math.tan(t*Vt/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},da=(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},Kn=(t,e,r,n)=>{let s=-1/0,i=1/0;for(let l=0;l<3;l++){if(n[l]===0)continue;const o=(t[l]-e[l]-r[l])/n[l],a=(t[l]+e[l]-r[l])/n[l];s=Math.max(s,Math.min(o,a)),i=Math.min(i,Math.max(o,a))}return s<0||i<s?-1:s},ma=(t,e,r,n)=>{const s=r[0]-t[0],i=r[1]-t[1],l=r[2]-t[2],o=n[0]**2+n[1]**2+n[2]**2,a=2*(s*n[0]+i*n[1]+l*n[2]),u=s*s+i*i+l*l-e*e,g=a*a-4*o*u;if(g<0)return-1;const p=Math.sqrt(g),h=(-a-p)/(2*o),v=(-a+p)/(2*o);return h>0&&v>0?Math.min(h,v):h>0?h:v>0?v:-1},xt=(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),pa=(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,o=1,a=0;Math.abs(n)>.999&&(l=0,o=0,a=-1);let u=n*a-s*o,g=s*l-r*a,p=r*o-n*l;const h=Math.hypot(u,g,p)||1;u/=h,g/=h,p/=h;const v=g*s-p*n,M=p*r-u*s,m=u*n-g*r,y=new Float32Array(16);return y[0]=u,y[4]=g,y[8]=p,y[1]=v,y[5]=M,y[9]=m,y[2]=-r,y[6]=-n,y[10]=-s,y[12]=-(u*t[0]+g*t[1]+p*t[2]),y[13]=-(v*t[0]+M*t[1]+m*t[2]),y[14]=r*t[0]+n*t[1]+s*t[2],y[15]=1,y},ga=1/(1.2*Math.pow(2,Math.log2(256/(1/125)))),ya=`#version 300 es
36
+ precision highp float;
37
+ in vec3 position;
38
+ in vec3 normal;
39
+ in vec2 uv;
40
+ uniform mat4 modelMatrix;
41
+ uniform mat4 modelViewMatrix;
42
+ uniform mat4 projectionMatrix;
43
+ uniform mat3 normalMatrix;
44
+ out vec3 vWorldPos;
45
+ out vec3 vNormal;
46
+ out vec2 vUv;
47
+ `,zs=`
48
+ in vec4 skinIndex;
49
+ in vec4 skinWeight;
50
+ uniform sampler2D boneTexture;
51
+ uniform int boneTextureSize;
52
+
53
+ mat4 getBoneMatrix(const in float i) {
54
+ float j = i * 4.0;
55
+ float x = mod(j, float(boneTextureSize));
56
+ float y = floor(j / float(boneTextureSize));
57
+ float dx = 1.0 / float(boneTextureSize);
58
+ float dy = 1.0 / float(boneTextureSize);
59
+ y = dy * (y + 0.5);
60
+ vec4 v1 = texture(boneTexture, vec2(dx * (x + 0.5), y));
61
+ vec4 v2 = texture(boneTexture, vec2(dx * (x + 1.5), y));
62
+ vec4 v3 = texture(boneTexture, vec2(dx * (x + 2.5), y));
63
+ vec4 v4 = texture(boneTexture, vec2(dx * (x + 3.5), y));
64
+ return mat4(v1, v2, v3, v4);
65
+ }
66
+
67
+ mat4 getSkinMatrix() {
68
+ mat4 boneMatX = getBoneMatrix(skinIndex.x);
69
+ mat4 boneMatY = getBoneMatrix(skinIndex.y);
70
+ mat4 boneMatZ = getBoneMatrix(skinIndex.z);
71
+ mat4 boneMatW = getBoneMatrix(skinIndex.w);
72
+ return boneMatX * skinWeight.x + boneMatY * skinWeight.y + boneMatZ * skinWeight.z + boneMatW * skinWeight.w;
73
+ }
74
+ `,va=`
75
+ uniform sampler2D uMorphTex;
76
+ uniform int uMorphCount; // active target count (capped by glb.ts)
77
+ uniform int uMorphVertexCount;
78
+ uniform int uMorphTexWidth;
79
+ uniform float uMorphWeights[8];
80
+
81
+ vec3 morphFetch(int idx) {
82
+ return texelFetch(uMorphTex, ivec2(idx % uMorphTexWidth, idx / uMorphTexWidth), 0).rgb;
83
+ }
84
+ `,Us=t=>`${ya}
85
+ #ifdef INSTANCED
86
+ in mat4 instanceMatrix;
87
+ uniform mat4 viewMatrix;
88
+ #endif
89
+ ${t.includes("HAS_SKIN")?zs:""}
90
+ ${t.includes("HAS_MORPH")?va:""}
91
+ ${t.includes("HAS_COLOR")?`in vec4 color;
92
+ out vec4 vColor;`:""}
93
+ uniform mat4 shadowMatrix;
94
+ out vec4 vShadowCoord;
95
+
96
+ void main() {
97
+ vec4 pos = vec4(position, 1.0);
98
+ vec3 nrm = normal;
99
+ ${t.includes("HAS_MORPH")?`
100
+ for (int t = 0; t < uMorphCount; t++) {
101
+ if (uMorphWeights[t] != 0.0) {
102
+ pos.xyz += uMorphWeights[t] * morphFetch(t * uMorphVertexCount + gl_VertexID);
103
+ ${t.includes("HAS_MORPH_NORMALS")?"nrm += uMorphWeights[t] * morphFetch((uMorphCount + t) * uMorphVertexCount + gl_VertexID);":""}
104
+ }
105
+ }
106
+ `:""}
107
+ ${t.includes("HAS_SKIN")?`
108
+ mat4 skinMatrix = getSkinMatrix();
109
+ pos = skinMatrix * pos;
110
+ nrm = mat3(skinMatrix) * nrm;
111
+ `:""}
112
+ ${t.includes("HAS_COLOR")?"vColor = color;":""}
113
+ #ifdef INSTANCED
114
+ mat4 model = instanceMatrix;
115
+ #else
116
+ mat4 model = modelMatrix;
117
+ #endif
118
+ vec4 worldPos = model * pos;
119
+ vWorldPos = worldPos.xyz;
120
+ vNormal = normalize(mat3(model) * nrm);
121
+ vUv = uv;
122
+ vShadowCoord = shadowMatrix * worldPos;
123
+ #ifdef INSTANCED
124
+ gl_Position = projectionMatrix * viewMatrix * worldPos;
125
+ #else
126
+ gl_Position = projectionMatrix * modelViewMatrix * pos;
127
+ #endif
128
+ }
129
+ `,gr=`
130
+ uniform vec3 sunDirection;
131
+ uniform vec4 sunColorIntensity; // rgb = linear color, a = intensity (lux)
132
+ uniform float iblLuminance;
133
+ uniform vec3 iblSH[9];
134
+ uniform samplerCube envMap;
135
+ uniform float envMapMaxLod;
136
+ uniform sampler2D shadowMap;
137
+ uniform float shadowEnabled;
138
+ uniform float shadowMapSize;
139
+ uniform float exposure;
140
+ in vec4 vShadowCoord;
141
+
142
+ #define PI 3.14159265359
143
+
144
+ float D_GGX(float NoH, float a) {
145
+ float a2 = a * a;
146
+ float f = (NoH * a2 - NoH) * NoH + 1.0;
147
+ return a2 / (PI * f * f);
148
+ }
149
+
150
+ float V_SmithGGXCorrelated(float NoV, float NoL, float a) {
151
+ float a2 = a * a;
152
+ float GGXL = NoV * sqrt((-NoL * a2 + NoL) * NoL + a2);
153
+ float GGXV = NoL * sqrt((-NoV * a2 + NoV) * NoV + a2);
154
+ return 0.5 / (GGXV + GGXL + 1e-5);
155
+ }
156
+
157
+ vec3 F_Schlick(float u, vec3 f0) {
158
+ float f = pow(1.0 - u, 5.0);
159
+ return f0 + (vec3(1.0) - f0) * f;
160
+ }
161
+
162
+ vec3 evalSH(vec3 n) {
163
+ return max(
164
+ iblSH[0]
165
+ + iblSH[1] * n.y
166
+ + iblSH[2] * n.z
167
+ + iblSH[3] * n.x
168
+ + iblSH[4] * (n.y * n.x)
169
+ + iblSH[5] * (n.y * n.z)
170
+ + iblSH[6] * (3.0 * n.z * n.z - 1.0)
171
+ + iblSH[7] * (n.z * n.x)
172
+ + iblSH[8] * (n.x * n.x - n.y * n.y)
173
+ , vec3(0.0));
174
+ }
175
+
176
+ float sampleShadowPCF() {
177
+ if (shadowEnabled < 0.5) return 1.0;
178
+ vec3 coord = vShadowCoord.xyz / vShadowCoord.w;
179
+ coord = coord * 0.5 + 0.5;
180
+ if (coord.x < 0.0 || coord.x > 1.0 || coord.y < 0.0 || coord.y > 1.0 || coord.z > 1.0) return 1.0;
181
+ float bias = 0.0018;
182
+ float texel = 1.0 / shadowMapSize;
183
+ float sum = 0.0;
184
+ for (int x = -1; x <= 1; x++) {
185
+ for (int y = -1; y <= 1; y++) {
186
+ float depth = texture(shadowMap, coord.xy + vec2(float(x), float(y)) * texel).r;
187
+ sum += (coord.z - bias) > depth ? 0.0 : 1.0;
188
+ }
189
+ }
190
+ return sum / 9.0;
191
+ }
192
+
193
+ // diffuseColor: linear albedo (already metallic-adjusted); f0: specular reflectance at normal.
194
+ vec3 shadePBR(vec3 n, vec3 v, vec3 diffuseColor, vec3 f0, float perceptualRoughness, float occlusion) {
195
+ float roughness = clamp(perceptualRoughness, 0.045, 1.0);
196
+ float a = roughness * roughness;
197
+ float NoV = abs(dot(n, v)) + 1e-5;
198
+
199
+ vec3 color = vec3(0.0);
200
+
201
+ // --- sun ---
202
+ if (sunColorIntensity.a > 0.0) {
203
+ vec3 l = normalize(-sunDirection);
204
+ float NoL = clamp(dot(n, l), 0.0, 1.0);
205
+ if (NoL > 0.0) {
206
+ vec3 h = normalize(v + l);
207
+ float NoH = clamp(dot(n, h), 0.0, 1.0);
208
+ float LoH = clamp(dot(l, h), 0.0, 1.0);
209
+ float D = D_GGX(NoH, a);
210
+ float V = V_SmithGGXCorrelated(NoV, NoL, a);
211
+ vec3 F = F_Schlick(LoH, f0);
212
+ vec3 Fr = D * V * F;
213
+ vec3 Fd = diffuseColor * (1.0 / PI);
214
+ float shadow = sampleShadowPCF();
215
+ // "illuminance" model: lux * NoL, pre-exposed
216
+ color += (Fd + Fr) * sunColorIntensity.rgb * (sunColorIntensity.a * exposure * NoL * shadow);
217
+ }
218
+ }
219
+
220
+ // --- IBL ---
221
+ if (iblLuminance > 0.0) {
222
+ // cmgen's SH coefficients are pre-convolved irradiance — no extra 1/PI (matches Filament).
223
+ vec3 irradiance = evalSH(n);
224
+ vec3 Fd = diffuseColor * irradiance;
225
+
226
+ vec3 r = reflect(-v, n);
227
+ float lod = roughness * envMapMaxLod;
228
+ vec3 prefiltered = textureLod(envMap, r, lod).rgb;
229
+ // Simple DFG approximation (Karis): avoids a DFG LUT.
230
+ vec3 specular = prefiltered * (f0 * (1.0 - roughness) + roughness * 0.25 * f0 + 0.05 * (1.0 - roughness));
231
+ color += (Fd + specular) * (iblLuminance * exposure * occlusion);
232
+ }
233
+
234
+ return color;
235
+ }
236
+
237
+ // ACES filmic fit (Narkowicz) + sRGB OETF — stands in for Filament's default ACES color grading.
238
+ vec3 tonemap(vec3 x) {
239
+ 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;
240
+ vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
241
+ return pow(t, vec3(1.0 / 2.2));
242
+ }
243
+ `,xa=`#version 300 es
244
+ precision highp float;
245
+ in vec3 vWorldPos;
246
+ in vec3 vNormal;
247
+ in vec2 vUv;
248
+ uniform vec3 cameraPosition;
249
+ uniform vec3 baseColor; // linear factor over baseColorMap (both default white)
250
+ uniform sampler2D baseColorMap;
251
+ uniform float roughness;
252
+ uniform float metallic;
253
+ ${gr}
254
+ out vec4 fragColor;
255
+
256
+ void main() {
257
+ vec3 albedo = baseColor * texture(baseColorMap, vUv).rgb;
258
+ vec3 n = normalize(vNormal);
259
+ vec3 v = normalize(cameraPosition - vWorldPos);
260
+ if (dot(n, v) < 0.0) n = -n;
261
+ vec3 diffuseColor = albedo * (1.0 - metallic);
262
+ vec3 f0 = mix(vec3(0.04), albedo, metallic);
263
+ vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, 1.0);
264
+ fragColor = vec4(tonemap(color), 1.0);
265
+ }
266
+ `,wa=`#version 300 es
267
+ precision highp float;
268
+ in vec3 vWorldPos;
269
+ in vec3 vNormal;
270
+ in vec2 vUv;
271
+ uniform vec3 cameraPosition;
272
+ uniform sampler2D control;
273
+ uniform sampler2D albedo0;
274
+ uniform sampler2D albedo1;
275
+ uniform sampler2D albedo2;
276
+ uniform sampler2D albedo3;
277
+ uniform sampler2D normals01;
278
+ uniform sampler2D normals23;
279
+ uniform vec4 tiling;
280
+ uniform vec4 roughness;
281
+ uniform vec4 normalScale;
282
+ uniform vec4 triplanar;
283
+ uniform vec2 gridSize;
284
+ uniform float cellSize;
285
+ uniform vec3 tint;
286
+ ${gr}
287
+ out vec4 fragColor;
288
+
289
+ vec4 triplanarSample(sampler2D tex, vec3 p, vec3 bw, float s) {
290
+ return texture(tex, p.zy / s) * bw.x + texture(tex, p.xz / s) * bw.y + texture(tex, p.xy / s) * bw.z;
291
+ }
292
+
293
+ void splatLayer(sampler2D alb, sampler2D pack, float slot, float tl, float nscale, float tri, float w,
294
+ vec2 uv, vec3 wp, vec3 bw, inout vec3 albedo, inout vec3 nrm) {
295
+ if (w <= 0.0) return;
296
+ float s = max(tl, 1e-3);
297
+ if (tri > 0.5) {
298
+ albedo += triplanarSample(alb, wp, bw, s).rgb * w;
299
+ nrm += vec3(0.0, 0.0, 1.0) * w;
300
+ } else {
301
+ vec2 luv = uv / s;
302
+ albedo += texture(alb, luv).rgb * w;
303
+ if (nscale > 0.0) {
304
+ vec4 p = texture(pack, luv);
305
+ vec2 xy = (slot > 0.5 ? p.ba : p.rg) * 2.0 - 1.0;
306
+ xy *= nscale;
307
+ nrm += vec3(xy, sqrt(max(1.0 - dot(xy, xy), 0.0))) * w;
308
+ } else {
309
+ nrm += vec3(0.0, 0.0, 1.0) * w;
310
+ }
311
+ }
312
+ }
313
+
314
+ vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
315
+ vec3 pos_dx = dFdx(vWorldPos);
316
+ vec3 pos_dy = dFdy(vWorldPos);
317
+ vec2 tex_dx = dFdx(vUv);
318
+ vec2 tex_dy = dFdy(vUv);
319
+ float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
320
+ if (abs(det) < 1e-8) return ng;
321
+ vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
322
+ t = normalize(t - ng * dot(ng, t));
323
+ vec3 b = normalize(cross(ng, t)) * sign(det);
324
+ return normalize(mat3(t, b, ng) * nTangent);
325
+ }
326
+
327
+ void main() {
328
+ vec2 cuv = (vUv / max(cellSize, 1e-4) + 0.5) / max(gridSize, vec2(1.0));
329
+ vec4 w = texture(control, cuv);
330
+ float ws = w.r + w.g + w.b + w.a;
331
+ w = ws > 1e-4 ? w / ws : vec4(1.0, 0.0, 0.0, 0.0);
332
+ vec3 ng = normalize(vNormal);
333
+ vec3 bw = abs(ng);
334
+ bw = bw / max(bw.x + bw.y + bw.z, 1e-4);
335
+ vec3 albedo = vec3(0.0);
336
+ vec3 nrm = vec3(0.0);
337
+ splatLayer(albedo0, normals01, 0.0, tiling.x, normalScale.x, triplanar.x, w.r, vUv, vWorldPos, bw, albedo, nrm);
338
+ splatLayer(albedo1, normals01, 1.0, tiling.y, normalScale.y, triplanar.y, w.g, vUv, vWorldPos, bw, albedo, nrm);
339
+ splatLayer(albedo2, normals23, 0.0, tiling.z, normalScale.z, triplanar.z, w.b, vUv, vWorldPos, bw, albedo, nrm);
340
+ splatLayer(albedo3, normals23, 1.0, tiling.w, normalScale.w, triplanar.w, w.a, vUv, vWorldPos, bw, albedo, nrm);
341
+ vec3 n = applyTangentNormal(normalize(nrm), ng);
342
+ vec3 v = normalize(cameraPosition - vWorldPos);
343
+ if (dot(ng, v) < 0.0) n = -n;
344
+ vec3 diffuseColor = albedo * tint;
345
+ vec3 color = shadePBR(n, v, diffuseColor, vec3(0.04), dot(roughness, w), 1.0);
346
+ fragColor = vec4(tonemap(color), 1.0);
347
+ }
348
+ `,Ma=`#version 300 es
349
+ precision highp float;
350
+ in vec3 vWorldPos;
351
+ in vec3 vNormal;
352
+ in vec2 vUv;
353
+ uniform vec4 baseColor; // linear, premultiplied; factor over baseColorMap
354
+ uniform sampler2D baseColorMap;
355
+ out vec4 fragColor;
356
+
357
+ vec3 tonemapUnlit(vec3 x) {
358
+ 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;
359
+ vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
360
+ return pow(t, vec3(1.0 / 2.2));
361
+ }
362
+
363
+ void main() {
364
+ vec4 c = baseColor * texture(baseColorMap, vUv);
365
+ fragColor = vec4(tonemapUnlit(c.rgb), 1.0);
366
+ }
367
+ `,Aa=`#version 300 es
368
+ precision highp float;
369
+ in vec3 vWorldPos;
370
+ in vec3 vNormal;
371
+ in vec2 vUv;
372
+ uniform vec4 baseColor; // linear, straight alpha; factor over baseColorMap
373
+ uniform sampler2D baseColorMap;
374
+ out vec4 fragColor;
375
+
376
+ vec3 tonemapUnlit(vec3 x) {
377
+ 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;
378
+ vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
379
+ return pow(t, vec3(1.0 / 2.2));
380
+ }
381
+
382
+ void main() {
383
+ vec4 c = baseColor * texture(baseColorMap, vUv);
384
+ fragColor = vec4(tonemapUnlit(c.rgb) * c.a, c.a);
385
+ }
386
+ `,Sa=`#version 300 es
387
+ precision highp float;
388
+ in vec2 vUv;
389
+ in vec3 vWorldPos;
390
+ in vec3 vNormal;
391
+ uniform sampler2D baseColorMap;
392
+ out vec4 fragColor;
393
+ void main() {
394
+ fragColor = vec4(texture(baseColorMap, vUv).rgb, 1.0);
395
+ }
396
+ `,ba=`#version 300 es
397
+ precision highp float;
398
+ in vec3 vWorldPos;
399
+ in vec3 vNormal;
400
+ in vec2 vUv;
401
+ uniform vec4 color; // linear, premultiplied
402
+ ${gr}
403
+ out vec4 fragColor;
404
+ void main() {
405
+ float vis = sampleShadowPCF();
406
+ float shadowAmount = 1.0 - vis;
407
+ fragColor = vec4(color.rgb * shadowAmount, color.a * shadowAmount);
408
+ }
409
+ `,Vs=t=>Us(t),Dt=Us(""),_a=t=>`#version 300 es
410
+ precision highp float;
411
+ ${t}
412
+ in vec3 vWorldPos;
413
+ in vec3 vNormal;
414
+ in vec2 vUv;
415
+ #ifdef HAS_COLOR
416
+ in vec4 vColor;
417
+ #endif
418
+ uniform vec3 cameraPosition;
419
+ uniform vec4 uBaseColorFactor;
420
+ uniform float uMetallic;
421
+ uniform float uRoughness;
422
+ uniform vec3 uEmissive;
423
+ uniform float uAlphaCutoff;
424
+ #ifdef HAS_BASECOLOR_MAP
425
+ uniform sampler2D uBaseColorMap;
426
+ #endif
427
+ #ifdef HAS_MR_MAP
428
+ uniform sampler2D uMRMap;
429
+ #endif
430
+ #ifdef HAS_NORMAL_MAP
431
+ uniform sampler2D uNormalMap;
432
+ #endif
433
+ #ifdef HAS_OCCLUSION_MAP
434
+ uniform sampler2D uOcclusionMap;
435
+ #endif
436
+ #ifdef HAS_EMISSIVE_MAP
437
+ uniform sampler2D uEmissiveMap;
438
+ #endif
439
+ ${gr}
440
+ out vec4 fragColor;
441
+
442
+ #ifdef HAS_NORMAL_MAP
443
+ vec3 getNormal() {
444
+ vec3 pos_dx = dFdx(vWorldPos);
445
+ vec3 pos_dy = dFdy(vWorldPos);
446
+ vec2 tex_dx = dFdx(vUv);
447
+ vec2 tex_dy = dFdy(vUv);
448
+ float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
449
+ if (abs(det) < 1e-8) return normalize(vNormal);
450
+ vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
451
+ vec3 ng = normalize(vNormal);
452
+ t = normalize(t - ng * dot(ng, t));
453
+ vec3 b = normalize(cross(ng, t)) * sign(det);
454
+ mat3 tbn = mat3(t, b, ng);
455
+ vec3 n = texture(uNormalMap, vUv).rgb * 2.0 - 1.0;
456
+ return normalize(tbn * n);
457
+ }
458
+ #endif
459
+
460
+ void main() {
461
+ vec4 base = uBaseColorFactor;
462
+ #ifdef HAS_BASECOLOR_MAP
463
+ base *= texture(uBaseColorMap, vUv);
464
+ #endif
465
+ #ifdef HAS_COLOR
466
+ base *= vColor;
467
+ #endif
468
+ #ifdef ALPHA_MASK
469
+ if (base.a < uAlphaCutoff) discard;
470
+ #endif
471
+
472
+ #ifdef UNLIT
473
+ // KHR_materials_unlit: the base colour IS the shaded colour — no lights, no IBL, no exposure
474
+ // (Filament's UNLIT shading model does the same, then tone-maps in post like everything else).
475
+ #ifdef ALPHA_BLEND
476
+ fragColor = vec4(tonemap(base.rgb), base.a);
477
+ #else
478
+ fragColor = vec4(tonemap(base.rgb), 1.0);
479
+ #endif
480
+ return;
481
+ #endif
482
+
483
+ float metallic = uMetallic;
484
+ float roughness = uRoughness;
485
+ #ifdef HAS_MR_MAP
486
+ vec3 mr = texture(uMRMap, vUv).rgb;
487
+ roughness *= mr.g;
488
+ metallic *= mr.b;
489
+ #endif
490
+
491
+ float occlusion = 1.0;
492
+ #ifdef HAS_OCCLUSION_MAP
493
+ occlusion = texture(uOcclusionMap, vUv).r;
494
+ #endif
495
+
496
+ #ifdef HAS_NORMAL_MAP
497
+ vec3 n = getNormal();
498
+ #else
499
+ vec3 n = normalize(vNormal);
500
+ #endif
501
+ vec3 v = normalize(cameraPosition - vWorldPos);
502
+ #ifdef DOUBLE_SIDED
503
+ if (dot(n, v) < 0.0) n = -n;
504
+ #endif
505
+
506
+ vec3 diffuseColor = base.rgb * (1.0 - metallic);
507
+ vec3 f0 = mix(vec3(0.04), base.rgb, metallic);
508
+ vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, occlusion);
509
+
510
+ vec3 emissive = uEmissive;
511
+ #ifdef HAS_EMISSIVE_MAP
512
+ emissive *= texture(uEmissiveMap, vUv).rgb;
513
+ #endif
514
+ color += emissive * iblLuminance * exposure;
515
+
516
+ #ifdef ALPHA_BLEND
517
+ fragColor = vec4(tonemap(color), base.a);
518
+ #else
519
+ fragColor = vec4(tonemap(color), 1.0);
520
+ #endif
521
+ }
522
+ `,Qn=`#version 300 es
523
+ precision highp float;
524
+ in vec3 vWorldPos;
525
+ in vec3 vNormal;
526
+ in vec2 vUv;
527
+ uniform vec3 uWireColor;
528
+ out vec4 fragColor;
529
+ void main() { fragColor = vec4(uWireColor, 1.0); }
530
+ `,ur=(t,e=!1)=>`#version 300 es
531
+ precision highp float;
532
+ in vec3 position;
533
+ ${t?`in vec3 normal;
534
+ in vec2 uv;`:""}
535
+ ${e?"in mat4 instanceMatrix;":"uniform mat4 modelMatrix;"}
536
+ uniform mat4 shadowViewProjection;
537
+ ${t?zs:""}
538
+ void main() {
539
+ vec4 pos = vec4(position, 1.0);
540
+ ${t?"pos = getSkinMatrix() * pos;":""}
541
+ gl_Position = shadowViewProjection * ${e?"instanceMatrix":"modelMatrix"} * pos;
542
+ }
543
+ `,fr=`#version 300 es
544
+ precision highp float;
545
+ out vec4 fragColor;
546
+ void main() { fragColor = vec4(1.0); }
547
+ `,tr=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),Yt=t=>{const e=Math.min(1,Math.max(0,t*(2.51*t+.03)/(t*(2.43*t+.59)+.14)));return Math.pow(e,1/2.2)},Ca=t=>[tr((t>>>16&255)/255),tr((t>>>8&255)/255),tr((t&255)/255)],Ea=t=>[tr((t>>>24&255)/255),tr((t>>>16&255)/255),tr((t>>>8&255)/255),(t&255)/255],Gs=`
548
+ uniform sampler2D baseColorMap;
549
+ uniform vec2 sheetSize; // (cols, rows) of the flipbook sheet, both >= 1 (the SDK primes it)
550
+ uniform float emissive;
551
+ uniform float additive;
552
+ uniform float softness;
553
+ uniform float depthFade; // declared so the SDK's write lands somewhere; ignored (no depth buffer)
554
+
555
+ vec3 tonemapParticle(vec3 x) {
556
+ 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;
557
+ vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
558
+ return pow(t, vec3(1.0 / 2.2));
559
+ }
560
+ // Integer cell math: a float floor(frame / cols) lands one row early at row starts on the GPU.
561
+ vec2 sheetCell(int fi) {
562
+ int sx = int(sheetSize.x + 0.5);
563
+ return vec2(float(fi - (fi / sx) * sx), float(fi / sx));
564
+ }
565
+ `,Fa=`#version 300 es
566
+ precision highp float;
567
+ in vec3 position;
568
+ in vec4 color;
569
+ in vec4 custom;
570
+ uniform mat4 modelMatrix;
571
+ uniform mat4 viewMatrix;
572
+ uniform mat4 projectionMatrix;
573
+ uniform float perspScale; // viewportHeightPx / (2 tan(fov/2)): a true world-space diameter
574
+ out vec4 vColor;
575
+ out vec4 vCustom;
576
+ void main() {
577
+ vec4 viewPos = viewMatrix * modelMatrix * vec4(position, 1.0);
578
+ float z = max(-viewPos.z, 1e-3);
579
+ gl_PointSize = custom.x * perspScale / z;
580
+ vColor = color;
581
+ vCustom = custom;
582
+ gl_Position = projectionMatrix * viewPos;
583
+ }
584
+ `,Ta=`#version 300 es
585
+ precision highp float;
586
+ in vec4 vColor;
587
+ in vec4 vCustom;
588
+ ${Gs}
589
+ out vec4 fragColor;
590
+ void main() {
591
+ vec2 uv = gl_PointCoord.xy;
592
+ float rot = vCustom.y;
593
+ if (rot != 0.0) {
594
+ float co = cos(rot);
595
+ float si = sin(rot);
596
+ vec2 p = uv - vec2(0.5);
597
+ uv = vec2(co * p.x - si * p.y, si * p.x + co * p.y) + vec2(0.5);
598
+ if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) discard;
599
+ }
600
+ int total = int(sheetSize.x + 0.5) * int(sheetSize.y + 0.5);
601
+ int fi = int(floor(vCustom.w) + 0.5);
602
+ fi = fi - (fi / total) * total;
603
+ vec4 tex = texture(baseColorMap, (sheetCell(fi) + uv) / sheetSize);
604
+ float radial = 1.0 - smoothstep(0.0, 0.5, length(gl_PointCoord.xy - vec2(0.5)));
605
+ float shape = mix(1.0, radial, clamp(softness, 0.0, 1.0));
606
+ float alpha = tex.a * vColor.a * vCustom.z * shape;
607
+ vec3 rgb = tex.rgb * vColor.rgb * (1.0 + emissive);
608
+ fragColor = vec4(tonemapParticle(rgb) * alpha, alpha * (1.0 - clamp(additive, 0.0, 1.0)));
609
+ }
610
+ `,Pa=`#version 300 es
611
+ precision highp float;
612
+ in vec3 position;
613
+ in vec4 color;
614
+ in vec4 custom; // size, rotation, opacity, frame
615
+ in vec3 aux; // quad: velocity (stretch axis); ribbon: strip tangent — sim space
616
+ in vec2 corner; // quad: ±0.5 square; ribbon: (u01 - 0.5, ±0.5 side)
617
+ uniform mat4 modelMatrix;
618
+ uniform mat4 viewMatrix;
619
+ uniform mat4 projectionMatrix;
620
+ uniform float mode; // 0 camera billboard, 1 velocity-stretched, 2 ribbon strip
621
+ uniform float stretch; // (mode 1) extra length per unit of speed: length = size + stretch · |v|
622
+ out vec4 vColor;
623
+ out vec4 vCustom;
624
+ out vec4 vQuadUv; // xy: in-cell uv, zw: the softness basis
625
+ void main() {
626
+ vec4 wp = modelMatrix * vec4(position, 1.0);
627
+ vec3 a = mat3(modelMatrix) * aux;
628
+ // the camera's world axes: rows of the view rotation (= columns of its inverse)
629
+ vec3 camX = vec3(viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0]);
630
+ vec3 camY = vec3(viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1]);
631
+ vec3 camZ = vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]); // toward the camera
632
+ vec3 offset;
633
+ vec2 suv = corner;
634
+ if (mode < 0.5) {
635
+ float co = cos(custom.y);
636
+ float si = sin(custom.y);
637
+ vec2 rc = vec2(co * corner.x - si * corner.y, si * corner.x + co * corner.y);
638
+ offset = (camX * rc.x + camY * rc.y) * custom.x;
639
+ } else if (mode < 1.5) {
640
+ float speed = length(a);
641
+ vec3 dir = speed > 1e-4 ? a / speed : camY;
642
+ vec3 y = dir - camZ * dot(dir, camZ);
643
+ float yl = length(y);
644
+ y = yl > 1e-4 ? y / yl : camY;
645
+ vec3 x = normalize(cross(y, camZ));
646
+ offset = x * corner.x * custom.x + y * corner.y * (custom.x + stretch * speed * yl);
647
+ } else {
648
+ vec3 x = cross(a, camZ);
649
+ float xl = length(x);
650
+ x = xl > 1e-4 ? x / xl : camX;
651
+ offset = x * corner.y * custom.x;
652
+ suv = vec2(0.0, corner.y);
653
+ }
654
+ wp.xyz += offset;
655
+ vColor = color;
656
+ vCustom = custom;
657
+ vQuadUv = vec4(corner.x + 0.5, 0.5 - corner.y, suv.x, suv.y);
658
+ gl_Position = projectionMatrix * viewMatrix * wp;
659
+ }
660
+ `,Ra=`#version 300 es
661
+ precision highp float;
662
+ in vec4 vColor;
663
+ in vec4 vCustom;
664
+ in vec4 vQuadUv;
665
+ ${Gs}
666
+ uniform sampler2D emissiveMap;
667
+ uniform vec3 emissiveColor;
668
+ uniform float frameBlend;
669
+ out vec4 fragColor;
670
+ void main() {
671
+ vec2 uv = vQuadUv.xy;
672
+ float total = sheetSize.x * sheetSize.y;
673
+ float fidx = mod(vCustom.w, total);
674
+ float frame = floor(fidx);
675
+ int fi = int(frame + 0.5);
676
+ vec2 tuv = (sheetCell(fi) + uv) / sheetSize;
677
+ vec4 tex = texture(baseColorMap, tuv);
678
+ vec3 em = texture(emissiveMap, tuv).rgb;
679
+ if (frameBlend > 0.5) {
680
+ int ni = min(fi + 1, int(total + 0.5) - 1);
681
+ vec2 tuv2 = (sheetCell(ni) + uv) / sheetSize;
682
+ float f = fidx - frame;
683
+ tex = mix(tex, texture(baseColorMap, tuv2), f);
684
+ em = mix(em, texture(emissiveMap, tuv2).rgb, f);
685
+ }
686
+ float radial = 1.0 - smoothstep(0.0, 0.5, length(vQuadUv.zw));
687
+ float shape = mix(1.0, radial, clamp(softness, 0.0, 1.0));
688
+ float alpha = tex.a * vColor.a * vCustom.z * shape;
689
+ vec3 rgb = tex.rgb * vColor.rgb * (1.0 + emissive) + em * emissiveColor;
690
+ fragColor = vec4(tonemapParticle(rgb) * alpha, alpha * (1.0 - clamp(additive, 0.0, 1.0)));
691
+ }
692
+ `,Ba=2873840728,Na=t=>{const e=new DataView(t);if(e.getUint32(0,!1)!==Ba)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),o=n(36),a=n(40),u=n(52),g=Math.max(1,n(56)),p=n(60),h=new Map,v=new TextDecoder("utf-8");let M=64;const m=64+p;for(;M<m;){const x=n(M);M+=4;const F=new Uint8Array(t,M,x),R=F.indexOf(0),C=v.decode(F.subarray(0,R)),P=v.decode(F.subarray(R+1)).replace(/\0+$/,"");h.set(C,P),M+=x+(3-(x+3)%4)}const y=[];M=m;for(let x=0;x<g;x++){const F=n(M);M+=4;const R=[];for(let C=0;C<u;C++)R.push(new Uint8Array(t,M,F)),M+=F+(3-(F+3)%4);y.push(R)}return{glType:s,glFormat:i,glInternalFormat:l,width:o,height:a,faces:u,mipLevels:g,keyValues:h,mips:y}},La=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},Zn=35898,Oa=35899,Jn=6407,Ia=(t,e)=>{const r=Na(e),n=La(r.keyValues.get("sh")),s=new je(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===Zn;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 o=Math.max(1,r.width>>l);for(let a=0;a<r.faces;a++){const u=r.mips[l][a];if(i)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+a,l,Zn,o,o,0,Jn,Oa,new Uint32Array(u.buffer,u.byteOffset,u.byteLength/4));else{const g=r.glFormat===Jn?3:4;t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+a,l,g===3?t.RGB8:t.RGBA8,o,o,0,g===3?t.RGB:t.RGBA,t.UNSIGNED_BYTE,u)}}}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}},Da=["EXT_meshopt_compression"],za=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))},Ua=t=>{const e=[];return(t.animations??[]).forEach((r,n)=>{var i,l;const s=[];for(const o of r.channels??[]){const a=o.sampler!==void 0?(i=r.samplers)==null?void 0:i[o.sampler]:void 0;((l=o.target)==null?void 0:l.path)==="weights"&&o.target.node!==void 0&&a?e.push({anim:n,node:o.target.node,input:a.input,output:a.output,interpolation:a.interpolation??"LINEAR"}):s.push(o)}r.channels=s}),e},Va={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Ga={5120:127,5121:255,5122:32767,5123:65535},Ha={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},Fr=(t,e,r)=>{var a,u,g;const n=(a=t==null?void 0:t.accessors)==null?void 0:a[r],s=Ha[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=(p,h,v,M,m,y)=>{var f;const x=new Float32Array(M*m),F=(f=t.bufferViews)==null?void 0:f[p],R=F?e[typeof F.buffer=="number"?F.buffer:0]:void 0,C=Va[v];if(!F||!R||!C)return x;const P=C.BYTES_PER_ELEMENT,c=(F.byteOffset??0)+h;if(!y||y===m*P){const d=new C(R,c,M*m);for(let w=0;w<x.length;w++)x[w]=d[w]}else for(let d=0;d<M;d++){const w=new C(R,c+d*y,m);for(let S=0;S<m;S++)x[d*m+S]=w[S]}return x};if(n.bufferView!==void 0&&i.set(l(n.bufferView,n.byteOffset??0,n.componentType,n.count,s,((g=(u=t.bufferViews)==null?void 0:u[n.bufferView])==null?void 0:g.byteStride)??0)),n.sparse){const p=n.sparse,h=l(p.indices.bufferView,p.indices.byteOffset??0,p.indices.componentType,p.count,1,0),v=l(p.values.bufferView,p.values.byteOffset??0,n.componentType,p.count,s,0);for(let M=0;M<p.count;M++)for(let m=0;m<s;m++)i[h[M]*s+m]=v[M*s+m]}const o=n.normalized?Ga[n.componentType]:void 0;if(o)for(let p=0;p<i.length;p++)i[p]=Math.max(i[p]/o,-1);return i};new Gt;new Gt;const ka=(t,e)=>{const r=Math.floor((t?t.length:e)/3),n=1<<24,s=new Set;for(let o=0;o<r;o++){const a=t?t[o*3]:o*3,u=t?t[o*3+1]:o*3+1,g=t?t[o*3+2]:o*3+2;s.add(Math.min(a,u)*n+Math.max(a,u)),s.add(Math.min(u,g)*n+Math.max(u,g)),s.add(Math.min(g,a)*n+Math.max(g,a))}const i=e>65535?new Uint32Array(s.size*2):new Uint16Array(s.size*2);let l=0;for(const o of s)i[l++]=Math.floor(o/n),i[l++]=o%n;return i},Wa=t=>new je(t,{image:new Uint8Array([255,255,255,255]),width:1,height:1,generateMipmaps:!1}),$a=t=>{const e=new je(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},dr=8,ja=(t,e,r,n)=>{var i,l,o,a,u,g;const s=e.nodes??[];for(let p=0;p<s.length;p++){const h=s[p].mesh;if(h===void 0)continue;const v=(i=e.meshes)==null?void 0:i[h],M=v==null?void 0:v.primitives;if(!(M!=null&&M.some(P=>{var c;return(c=P.targets)==null?void 0:c.length})))continue;const m=(l=r.nodes)==null?void 0:l[p],y=(o=r.meshes)==null?void 0:o[h];if(!m||!y)continue;const x=Math.max(...M.map(P=>{var c;return((c=P.targets)==null?void 0:c.length)??0})),F=new Float32Array(x),R=s[p].weights??v.weights;if(R)for(let P=0;P<Math.min(x,R.length);P++)F[P]=R[P];m.weights=F,x>dr&&console.warn(`[viewer-lite] GLB: mesh has ${x} morph targets — only the first ${dr} deform`);const C=Array.isArray((a=y.primitives)==null?void 0:a[0])?y.primitives[0]:y.primitives??[];for(let P=0;P<M.length;P++){const c=M[P].targets,f=C[P];if(!(c!=null&&c.length)||!(f!=null&&f.geometry))continue;const d=((g=(u=f.geometry.attributes)==null?void 0:u.position)==null?void 0:g.count)??0;if(d===0)continue;const w=Math.min(c.length,dr);if(c.slice(0,w).find(Y=>{const O=k=>{var V,X;return k!==void 0&&((X=(V=e.accessors)==null?void 0:V[k])==null?void 0:X.count)!==d};return O(Y.POSITION)||O(Y.NORMAL)})){console.warn(`[viewer-lite] GLB: morph targets skipped on a primitive — target accessor count doesn't match the ${d}-vertex geometry (draco decode changed the vertex set)`);continue}const N=c.slice(0,w).some(Y=>Y.NORMAL!==void 0),U=d*w*(N?2:1),L=Math.max(1,Math.ceil(Math.sqrt(U))),$=Math.max(1,Math.ceil(U/L)),j=new Float32Array(L*$*4);for(let Y=0;Y<w;Y++){const O=c[Y].POSITION!==void 0?Fr(e,n,c[Y].POSITION):null,k=N&&c[Y].NORMAL!==void 0?Fr(e,n,c[Y].NORMAL):null;for(let V=0;V<d;V++){if(O){const X=(Y*d+V)*4;j[X]=O[V*3]??0,j[X+1]=O[V*3+1]??0,j[X+2]=O[V*3+2]??0}if(k){const X=((w+Y)*d+V)*4;j[X]=k[V*3]??0,j[X+1]=k[V*3+1]??0,j[X+2]=k[V*3+2]??0}}}const oe=new je(t,{image:j,width:L,height:$,type:t.FLOAT,format:t.RGBA,internalFormat:t.RGBA32F,generateMipmaps:!1,minFilter:t.NEAREST,magFilter:t.NEAREST,flipY:!1});f._morph={texture:oe,count:w,vertexCount:d,texWidth:L,hasNormals:N,weights:F}}}},es=(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}},qa=(t,e,r,n,s,i,l)=>{var v,M,m,y,x,F,R,C,P,c,f;const o=e??{},a=[];r&&a.push("#define HAS_SKIN"),n&&a.push("#define HAS_COLOR"),(v=o.baseColorTexture)!=null&&v.texture&&a.push("#define HAS_BASECOLOR_MAP"),(M=o.metallicRoughnessTexture)!=null&&M.texture&&a.push("#define HAS_MR_MAP"),(m=o.normalTexture)!=null&&m.texture&&a.push("#define HAS_NORMAL_MAP"),(y=o.occlusionTexture)!=null&&y.texture&&a.push("#define HAS_OCCLUSION_MAP"),(x=o.emissiveTexture)!=null&&x.texture&&a.push("#define HAS_EMISSIVE_MAP"),(F=o.extensions)!=null&&F.KHR_materials_unlit&&a.push("#define UNLIT"),o.doubleSided&&a.push("#define DOUBLE_SIDED"),o.alphaMode==="MASK"&&a.push("#define ALPHA_MASK"),o.alphaMode==="BLEND"&&a.push("#define ALPHA_BLEND");const u=a.join(`
693
+ `);es(t,o.baseColorTexture),es(t,o.emissiveTexture);const g={...s,uBaseColorFactor:{value:o.baseColorFactor??[1,1,1,1]},uMetallic:{value:o.metallicFactor??1},uRoughness:{value:o.roughnessFactor??1},uEmissive:{value:o.emissiveFactor??[0,0,0]},uAlphaCutoff:{value:o.alphaCutoff??.5}};(R=o.baseColorTexture)!=null&&R.texture&&(g.uBaseColorMap={value:o.baseColorTexture.texture}),(C=o.metallicRoughnessTexture)!=null&&C.texture&&(g.uMRMap={value:o.metallicRoughnessTexture.texture}),(P=o.normalTexture)!=null&&P.texture&&(g.uNormalMap={value:o.normalTexture.texture}),(c=o.occlusionTexture)!=null&&c.texture&&(g.uOcclusionMap={value:o.occlusionTexture.texture}),(f=o.emissiveTexture)!=null&&f.texture&&(g.uEmissiveMap={value:o.emissiveTexture.texture}),l&&(g.uMorphTex={value:l.texture},g.uMorphCount={value:l.count},g.uMorphVertexCount={value:l.vertexCount},g.uMorphTexWidth={value:l.texWidth},g.uMorphWeights={value:[l.weights.length>dr?l.weights.subarray(0,dr):l.weights]});const p=(r?"HAS_SKIN ":"")+(n?"HAS_COLOR ":"")+(l?"HAS_MORPH ":"")+(l!=null&&l.hasNormals?"HAS_MORPH_NORMALS":""),h=new Ie(t,{vertex:Vs(p),fragment:_a(u),uniforms:g,transparent:o.alphaMode==="BLEND",cullFace:o.doubleSided?!1:t.BACK});return o.alphaMode==="BLEND"&&h.setBlendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),h},Xa=async(t,e,r,n)=>{var x,F,R,C,P,c,f;const s=Xn.unpackGLB(e),i=(s.extensionsRequired??[]).filter(d=>Da.includes(d));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??[]],o=l.includes("KHR_draco_mesh_compression"),a=l.includes("KHR_texture_basisu")||(s.images??[]).some(d=>d.mimeType==="image/ktx2");if(o||a){const d=await mr(()=>import("./index-3CbsYWmo.js"),__vite__mapDeps([0,1]),import.meta.url);await Promise.all([o?d.ensureDracoDecoder():null,a?d.ensureBasisTranscoder(t):null])}za(s);const u=Ua(s),g=await Xn.parse(t,s,""),p=(s.buffers??[]).map(d=>d.binary);ja(t,s,g,p);const h=new Map,v=new Set,M=[];for(const d of g.nodes)d.traverse(w=>(w.draw&&!v.has(w)&&(v.add(w),M.push(w)),!1));for(const d of M){const w=(x=d.geometry)==null?void 0:x.attributes,S=((F=w==null?void 0:w.position)==null?void 0:F.count)??0;if(w&&S>0){if(!w.normal){const k=new Float32Array(S*3);for(let V=2;V<k.length;V+=3)k[V]=1;d.geometry.addAttribute("normal",{size:3,data:k})}w.uv||d.geometry.addAttribute("uv",{size:2,data:new Float32Array(S*2)})}const N=(R=d.program)==null?void 0:R.gltfMaterial,U=d instanceof vt,L=(P=(C=d.geometry)==null?void 0:C.attributes)==null?void 0:P.color,$=!!L&&L.size===4,j=d._morph,Y=U||$||j?d:N??d;let O=h.get(Y);O||(O=qa(t,N,U,$,r,n,j),h.set(Y,O)),d.program=O,d._receiveShadows=!0,d._castShadows=!0}g.images&&await Promise.all(g.images.map(d=>d==null?void 0:d.ready).filter(Boolean));const m=(g.animations??[]).map((d,w)=>{const S=[];for(const N of d.animation.data)S.includes(N.node)||S.push(N.node);return{name:typeof d.name=="string"&&d.name.length>0?d.name:`animation_${w}`,duration:d.animation.duration,animation:d.animation,nodes:S}});let y=0;for(const d of u){const w=m[d.anim],S=(c=g.nodes)==null?void 0:c[d.node];!w||!(S!=null&&S.weights)||(w.animation.data.push({node:S,transform:"weights",interpolation:d.interpolation,times:Fr(s,p,d.input),values:Fr(s,p,d.output)}),y++)}u.length>y&&console.warn(`[viewer-lite] GLB: ${u.length-y} morph (weights) animation channel(s) ignored — their nodes carry no usable morph targets`);for(const d of m){let w=1/0,S=0;for(const N of d.animation.data)w=Math.min(w,N.times[0]),S=Math.max(S,N.times[N.times.length-1]);d.animation.startTime=w===1/0?0:w,d.animation.duration=d.duration=w===1/0?0:S-w}return{roots:g.scene??((f=g.scenes)==null?void 0:f[0])??[],nodes:g.nodes??[],animations:m}},Ya=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}},Ka={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])}},Qa=`
694
+ struct MaterialInputs {
695
+ vec4 baseColor;
696
+ float roughness;
697
+ float metallic;
698
+ float reflectance;
699
+ float ambientOcclusion;
700
+ vec4 emissive;
701
+ vec3 normal;
702
+ float clearCoat;
703
+ float clearCoatRoughness;
704
+ vec4 postLightingColor;
705
+ };
706
+ void prepareMaterial(inout MaterialInputs m) {}
707
+ vec2 getUV0() { return vUv; }
708
+ vec2 getUV1() { return vUv; }
709
+ vec3 getWorldPosition() { return vWorldPos; }
710
+ vec3 getWorldGeometricNormalVector() { return normalize(vNormal); }
711
+ vec3 getWorldViewVector() { return normalize(cameraPosition - vWorldPos); }
712
+ vec4 getUserTime() { return userTime; }
713
+ `,Gr=`
714
+ MaterialInputs inputs;
715
+ inputs.baseColor = vec4(1.0);
716
+ inputs.roughness = 1.0;
717
+ inputs.metallic = 0.0;
718
+ inputs.reflectance = 0.5;
719
+ inputs.ambientOcclusion = 1.0;
720
+ inputs.emissive = vec4(0.0, 0.0, 0.0, 1.0);
721
+ inputs.normal = vec3(0.0, 0.0, 1.0);
722
+ inputs.clearCoat = 0.0;
723
+ inputs.clearCoatRoughness = 0.0;
724
+ inputs.postLightingColor = vec4(0.0);
725
+ material(inputs);
726
+ `,Za=`
727
+ vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
728
+ vec3 pos_dx = dFdx(vWorldPos);
729
+ vec3 pos_dy = dFdy(vWorldPos);
730
+ vec2 tex_dx = dFdx(vUv);
731
+ vec2 tex_dy = dFdy(vUv);
732
+ float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
733
+ if (abs(det) < 1e-8) return ng;
734
+ vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
735
+ t = normalize(t - ng * dot(ng, t));
736
+ vec3 b = normalize(cross(ng, t)) * sign(det);
737
+ return normalize(mat3(t, b, ng) * nTangent);
738
+ }
739
+ `,Ja=`
740
+ vec3 tonemap(vec3 x) {
741
+ 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;
742
+ vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
743
+ return pow(t, vec3(1.0 / 2.2));
744
+ }
745
+ `,el=t=>{if(t.unsupported)return null;const e=[],r=[],n=new Set;for(const p of t.params){const h=Ka[p.type];if(!h)return null;e.push(`uniform ${h.decl} materialParams_${p.name}${p.size?`[${p.size}]`:""};`);const v=p.size?new Array(p.size*(Array.isArray(h.zero)||h.zero instanceof Float32Array?h.zero.length:1)).fill(0):h.zero;r.push({key:`materialParams_${p.name}`,value:Array.isArray(v)?[...v]:v}),n.add(p.name)}for(const p of t.samplers)e.push(`uniform sampler2D materialParams_${p.name};`),r.push({key:`materialParams_${p.name}`,value:"texture"}),n.add(p.name);const s=t.shadingModel==="lit",i=s||t.shadowMultiplier,l=t.blending==="opaque"||t.blending==="masked",o=t.blending==="masked"?`if (inputs.baseColor.a < ${t.maskThreshold.toFixed(4)}) discard;`:"",a=l?"1.0":"inputs.baseColor.a",u=t.shadowMultiplier?`
746
+ void main() {
747
+ ${Gr}
748
+ float shadowAmount = 1.0 - sampleShadowPCF();
749
+ fragColor = vec4(inputs.baseColor.rgb * shadowAmount, inputs.baseColor.a * shadowAmount);
750
+ }
751
+ `:s?`
752
+ void main() {
753
+ ${Gr}
754
+ ${o}
755
+ vec3 n = normalize(vNormal);
756
+ vec3 v = normalize(cameraPosition - vWorldPos);
757
+ ${t.doubleSided?"if (dot(n, v) < 0.0) n = -n;":""}
758
+ ${t.writesNormal?"n = applyTangentNormal(inputs.normal, n);":""}
759
+ vec3 diffuseColor = inputs.baseColor.rgb * (1.0 - inputs.metallic);
760
+ vec3 f0 = mix(vec3(0.16 * inputs.reflectance * inputs.reflectance), inputs.baseColor.rgb, inputs.metallic);
761
+ vec3 color = shadePBR(n, v, diffuseColor, f0, inputs.roughness, inputs.ambientOcclusion);
762
+ color += inputs.emissive.rgb * (iblLuminance * exposure);
763
+ color += inputs.postLightingColor.rgb;
764
+ fragColor = vec4(tonemap(color), ${a});
765
+ }
766
+ `:`
767
+ void main() {
768
+ ${Gr}
769
+ ${o}
770
+ vec3 color = inputs.baseColor.rgb + inputs.emissive.rgb + inputs.postLightingColor.rgb;
771
+ fragColor = vec4(tonemap(color), ${a});
772
+ }
773
+ `;return{fragment:`#version 300 es
774
+ precision highp float;
775
+ in vec3 vWorldPos;
776
+ in vec3 vNormal;
777
+ in vec2 vUv;
778
+ uniform vec3 cameraPosition;
779
+ uniform vec4 userTime;
780
+ ${e.join(`
781
+ `)}
782
+ ${i?gr:Ja}
783
+ ${Qa}
784
+ ${t.writesNormal?Za:""}
785
+ out vec4 fragColor;
786
+ ${t.fragmentCode}
787
+ ${u}`,uniforms:r,paramNames:n,needsSceneUniforms:i}},et=10,ts=0,rs=1;let tl=null,Tr=null;const rl=()=>tl??(tl=mr(()=>import("./creatorPhysics-k7wL0kV1.js"),__vite__mapDeps([2,1]),import.meta.url).then(t=>t.default()).then(t=>Tr=t)),ns=()=>Tr!==null,tt=(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)}},ss=(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)}},Ar=(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)}},is=t=>t instanceof Uint8Array?t:new Uint8Array(t),lr=(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,o=t[1]/n,a=t[2]/n,u=t[4]/s,g=t[5]/s,p=t[6]/s,h=t[8]/i,v=t[9]/i,M=t[10]/i,m=l+g+M;let y,x,F,R;if(m>0){const C=Math.sqrt(m+1)*2;R=.25*C,y=(p-v)/C,x=(h-a)/C,F=(o-u)/C}else if(l>g&&l>M){const C=Math.sqrt(1+l-g-M)*2;R=(p-v)/C,y=.25*C,x=(u+o)/C,F=(h+a)/C}else if(g>M){const C=Math.sqrt(1+g-l-M)*2;R=(h-a)/C,y=(u+o)/C,x=.25*C,F=(v+p)/C}else{const C=Math.sqrt(1+M-l-g)*2;R=(o-u)/C,y=(h+a)/C,x=(v+p)/C,F=.25*C}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]=F,e[r+6]=R,e[r+7]=n,e[r+8]=s,e[r+9]=i},nl=(t,e)=>{const r=Math.cos(e),n=Math.sin(e),s=t[0],i=t[1],l=t[2],o=t[8],a=t[9],u=t[10],g=t;g[0]=s*r-o*n,g[1]=i*r-a*n,g[2]=l*r-u*n,g[8]=s*n+o*r,g[9]=i*n+a*r,g[10]=l*n+u*r},sl=(t,e=1,r=1,n=1)=>{const s=Tr;if(!s||t.length<12)return null;const i=tt(s,t,g=>s._cphysShapeMesh(g,Math.floor(t.length/3),0,0,1,e,r,n));if(!i)return null;const l=s._malloc(4),o=s._cphysShapeTriangles(i,l),a=s.HEAPU32[l>>2],u=o&&a?Float32Array.from(s.HEAPF32.subarray(o>>2,(o>>2)+a)):null;return o&&s._free(o),s._free(l),s._cphysShapeDestroy(i),u};function il(t){const e=Tr;if(!e)throw new Error("creator-physics: await loadCreatorPhysics() before createPhysicsBridge()");const r=e._malloc(et*4),n=e._malloc(32),s=e._malloc(4);let i=0,l=0;const o=c=>(c>l&&(i&&e._free(i),i=e._malloc(c*4),l=c),i),a=new Map,u=new Map,g=(c,f)=>{if(!t.jointRanges)return;const d=f.entities.length,w=new Float32Array(d*9);if(tt(e,w,Y=>{const O=e._cphysRagdollJointFrames(c,Y);return w.set(e.HEAPF32.subarray(Y>>2,(Y>>2)+d*9)),O})!==d)return;const N=[],U=[],L=[];for(let Y=0;Y<d;Y++){const O=w[Y*9];if(!(O<0)){N.push(f.entities[Y],f.entities[O]);for(let k=1;k<9;k++)U.push(w[Y*9+k]);L.push(Y)}}if(N.length===0)return;const $=t.jointRanges(f.entities[0],N,Float32Array.from(U));if(!$)return;const j=new Float32Array(d*6),oe=180/Math.PI;for(let Y=0;Y<L.length;Y++)for(let O=0;O<3;O++)j[L[Y]*6+O*2]=$[Y*6+O*2]*oe-f.margin,j[L[Y]*6+O*2+1]=$[Y*6+O*2+1]*oe+f.margin;tt(e,j,Y=>e._cphysRagdollSetLimits(c,Y))&&(f.learned=!0)},p=new WeakMap;let h=null;const v=e.addFunction(c=>t.parentOf(c)|0,"ii");e._cphysSetParentLookup(v),e._cphysInit();const M=c=>(lr(t.world(c),e.HEAPF32,r>>2),r),m=(c,f)=>{const d=e.HEAPF32,w=f>>2;c[0]=d[w],c[1]=d[w+1],c[2]=d[w+2]},y=c=>{if(c===0)return;const f=e.HEAPU32,d=e._cphysPulledIds()>>2,w=e.HEAPF32,S=e._cphysPulledPoses()>>2;for(let N=0;N<c;N++){const U=S+N*et;t.setWorldTRS(f[d+N],w[U],w[U+1],w[U+2],w[U+3],w[U+4],w[U+5],w[U+6],w[U+7],w[U+8],w[U+9])}},x=c=>{if(c===0)return;const f=e.HEAPU32,d=e._cphysPulledIds()>>2,w=e.HEAPF32,S=e._cphysPulledPoses()>>2;for(let N=0;N<c;N++){const U=S+N*et;t.setWorldPosition(f[d+N],w[U],w[U+1],w[U+2])}},F=(c,f)=>{var N;const d=(N=t.glbBytes)==null?void 0:N.call(t,c);if(!d)return 0;let w=p.get(d);w||(w=[0,0],p.set(d,w));const S=f?1:0;if(!w[S]){const U=is(d);w[S]=Ar(e,U,L=>e._cphysShapeMeshFromGlb(L,U.length,f?1:0))}return w[S]},R=(c,f,d,w,S,N)=>f?e._cphysBodyCreate(c,f,d|0,w,S?1:0,N?1:0,1,M(c)):0,C=(c,f,d,w)=>{const S=R(c,f,d,w,!1,!1);return f&&e._cphysShapeDestroy(f),S};return{methods:{physicsHasSupport:()=>!0,physicsConfigure(c,f,d,w){e._cphysConfigure(c,f,d,(w|0)>0?w|0:0)},setInterpolation(c){e._cphysSetInterpolation(c?1:0)},physicsBuildBox:(c,f,d)=>e._cphysShapeBox(c,f,d),physicsBuildSphere:c=>e._cphysShapeSphere(c),physicsBuildCylinder:(c,f)=>e._cphysShapeCylinder(c,f),physicsBuildCapsule:(c,f)=>e._cphysShapeCapsule(c,f),physicsBuildMesh(c,f,d,w,S,N){return tt(e,c,U=>ss(e,f,L=>e._cphysShapeMesh(U,Math.floor(c.length/3),L,f.length,d?1:0,w,S,N)))},physicsBuildMeshFromEntity(c,f,d,w,S){const N=F(c,f);return N?e._cphysShapeScaled(N,d,w,S):0},physicsBuildHeightField(c,f,d,w,S,N,U,L){return tt(e,c,$=>S?Ar(e,S,j=>e._cphysShapeHeightField($,f,d,w,j,N,U,L)):e._cphysShapeHeightField($,f,d,w,0,N,U,L))},physicsUpdateHeightField(c,f,d,w,S,N,U,L,$){tt(e,f,j=>$?Ar(e,$,oe=>e._cphysShapeUpdateHeightField(c,j,d,w,S,N,U,L,oe)):e._cphysShapeUpdateHeightField(c,j,d,w,S,N,U,L,0))},glbTriangles(c){var U;const f=(U=t.glbBytes)==null?void 0:U.call(t,c);if(!f)return new Float32Array(0);const d=is(f),w=Ar(e,d,L=>e._cphysGlbTriangles(L,d.length,s));if(!w)return new Float32Array(0);const S=e.HEAPU32[s>>2],N=Float32Array.from(e.HEAPF32.subarray(w>>2,(w>>2)+S));return e._free(w),N},physicsSetShapeOrigin(c,f,d,w){e._cphysShapeSetOrigin(c,f,d,w)},physicsSetBodyShape(c,f,d){e._cphysBodySetShape(c,f,d?1:0)},physicsDestroyShape(c){e._cphysShapeDestroy(c)},physicsCreateBody:(c,f,d,w,S,N)=>R(c,f,d,w,S,N),physicsSetPickable(c,f){e._cphysBodySetPickable(c,f?1:0)},physicsSetFriction(c,f){e._cphysBodySetFriction(c,f)},physicsGetFriction:c=>e._cphysBodyGetFriction(c),physicsRaycast(c,f,d,w,S,N,U,L){const $=e._cphysRaycast(c,f,d,w,S,N,U,n);return $&&L&&L.set(e.HEAPF32.subarray(n>>2,(n>>2)+Math.min(7,L.length))),$},physicsCreateBox:(c,f,d,w,S,N)=>C(c,e._cphysShapeBox(f,d,w),S,N),physicsCreateSphere:(c,f,d,w)=>C(c,e._cphysShapeSphere(f),d,w),physicsCreateCylinder:(c,f,d,w,S)=>C(c,e._cphysShapeCylinder(f,d),w,S),physicsSetLinearVelocity(c,f,d,w){e._cphysBodySetLinearVelocity(c,f,d,w)},physicsGetLinearVelocity(c,f){e._cphysBodyGetLinearVelocity(c,n),m(f,n)},physicsSetAngularVelocity(c,f,d,w){e._cphysBodySetAngularVelocity(c,f,d,w)},physicsGetAngularVelocity(c,f){e._cphysBodyGetAngularVelocity(c,n),m(f,n)},physicsApplyImpulse(c,f,d,w){e._cphysBodyApplyImpulse(c,f,d,w)},physicsApplyImpulseAt(c,f,d,w,S,N,U){e._cphysBodyApplyImpulseAt(c,f,d,w,S,N,U)},physicsSetBodyPosition(c,f,d,w){e._cphysBodySetPosition(c,f,d,w)},physicsSetBodyRotation(c,f,d,w,S){e._cphysBodySetRotation(c,f,d,w,S)},physicsRemoveBody(c){e._cphysBodyRemove(c)},characterCreate(c,f,d){const w=f?e._cphysCharacterCreate(c,f,d,M(c)):0;return w&&a.set(w,c),w},characterDestroy(c){e._cphysCharacterDestroy(c),a.delete(c)},characterMove(c,f,d){e._cphysCharacterMove(c,f,d)},characterMoveFree(c,f,d,w){e._cphysCharacterMoveFree(c,f,d,w)},characterSetVerticalVelocity(c,f){e._cphysCharacterSetVerticalVelocity(c,f)},characterSetVelocity(c,f,d,w){e._cphysCharacterSetVelocity(c,f,d,w)},characterSetGravityScale(c,f){e._cphysCharacterSetGravityScale(c,f)},characterSetMaxSlope(c,f){e._cphysCharacterSetMaxSlope(c,f)},characterSetShape(c,f){if(!e._cphysCharacterSetShape(c,f))return!1;const d=a.get(c);if(d!==void 0){e._cphysCharacterPosition(c,n);const w=e.HEAPF32,S=n>>2;t.setWorldPosition(d,w[S],w[S+1],w[S+2])}return!0},characterGetVelocity(c,f){e._cphysCharacterGetVelocity(c,n),m(f,n)},characterGetGroundState:c=>e._cphysCharacterGetGroundState(c),characterSetPosition(c,f,d,w){e._cphysCharacterSetPosition(c,f,d,w)},vehicleCreate(c,f,d){return f?tt(e,d,w=>e._cphysVehicleCreate(c,f,w,d.length,M(c))):0},vehicleDestroy(c){e._cphysVehicleDestroy(c)},vehicleSetInput(c,f){tt(e,f,d=>e._cphysVehicleSetInput(c,d,f.length))},vehicleSetTuning(c,f){tt(e,f,d=>e._cphysVehicleSetTuning(c,d,f.length))},vehicleGetState(c,f){const d=o(f.length);e._cphysVehicleGetState(c,d,f.length),f.set(e.HEAPF32.subarray(d>>2,(d>>2)+f.length))},vehicleReset(c,f,d,w,S,N,U,L){e._cphysVehicleReset(c,f,d,w,S,N,U,L)},vehicleBodyId:c=>e._cphysVehicleBodyId(c),ragdollCreate(c,f,d){const w=d.length>1?d[1]|0:0;if(w<=0||f.length<w*2)return 0;const S=new Float32Array(et);lr(t.world(c),S,0);const N=new Float32Array(w*(et+3)),U=[];for(let $=0;$<w;$++){const j=$*(et+3);lr(t.world(f[$*2]),N,j),U.push(f[$*2]);const oe=f[$*2+1];if(oe){const Y=t.world(oe);N[j+et]=Y[12],N[j+et+1]=Y[13],N[j+et+2]=Y[14]}}const L=tt(e,S,$=>ss(e,f,j=>tt(e,N,oe=>tt(e,d,Y=>e._cphysRagdollCreate($,j,f.length,oe,Y,d.length)))));return L&&u.set(L,{entities:U,prev:new Float32Array(w*et),cur:new Float32Array(w*et),valid:0,dt:1/60,active:!1,driven:!1,learn:d.length>14&&d[13]!==0,margin:d.length>14?Math.max(0,d[14]):0,learned:!1}),L},ragdollDestroy(c){e._cphysRagdollDestroy(c),u.delete(c)},ragdollActivate(c,f,d,w){const S=u.get(c);if(!S)return!1;!S.active&&S.learn&&!S.learned&&g(c,S);const N=S.entities.length,U=new Float32Array(N*et);for(let j=0;j<N;j++)lr(t.world(S.entities[j]),U,j*et);let L=null;if(!S.active&&S.valid>=2&&S.dt>1e-5){L=new Float32Array(N*6);const j=1/S.dt;for(let oe=0;oe<N;oe++){const Y=oe*et,O=oe*6;L[O]=(S.cur[Y]-S.prev[Y])*j,L[O+1]=(S.cur[Y+1]-S.prev[Y+1])*j,L[O+2]=(S.cur[Y+2]-S.prev[Y+2])*j;const k=S.prev[Y+3],V=S.prev[Y+4],X=S.prev[Y+5],le=S.prev[Y+6],ee=S.cur[Y+3],te=S.cur[Y+4],fe=S.cur[Y+5],ye=S.cur[Y+6];let de=ye*-k+ee*le+te*-X-fe*-V,De=ye*-V-ee*-X+te*le+fe*-k,qe=ye*-X+ee*-V-te*-k+fe*le,_=ye*le-ee*-k-te*-V-fe*-X;_<0&&(de=-de,De=-De,qe=-qe,_=-_);const T=Math.sqrt(Math.max(0,1-_*_));if(T>1e-6){const B=2*Math.acos(Math.min(1,_))/T*j;L[O+3]=de*B,L[O+4]=De*B,L[O+5]=qe*B}}}const $=tt(e,U,j=>L?tt(e,L,oe=>e._cphysRagdollActivate(c,f,d,w,j,oe)):e._cphysRagdollActivate(c,f,d,w,j,0))!==0;return $&&(S.active=!0),$},ragdollDeactivate(c,f){var w;const d=u.get(c);d!=null&&d.active&&(y(e._cphysRagdollPose(c)),f>0&&d.entities.length>0&&((w=t.seedAnimator)==null||w.call(t,d.entities[0],f)),d.active=!1,d.valid=0),e._cphysRagdollDeactivate(c)},ragdollSetDrive(c,f,d){const w=u.get(c);w&&(w.driven=f>0||d),e._cphysRagdollSetDrive(c,f,d?1:0)},ragdollActive:c=>e._cphysRagdollActive(c)!==0,ragdollBodyId:(c,f)=>e._cphysRagdollBodyId(c,f),setOnPhysicsEvent(c){h=c}},frame(c,f){const d=e._cphysFrameBegin(c),w=e._cphysFixedDt();for(let N=0;N<d;N++)f&&(y(e._cphysPullBodies(rs)),x(e._cphysPullCharacters(rs)),f(w)),e._cphysStep();e._cphysFrameEnd(),y(e._cphysPullBodies(ts)),x(e._cphysPullCharacters(ts));const S=e._cphysEventCount();if(S>0&&h){const N=e._cphysEventData()>>2,U=Array.from(e.HEAPU32.subarray(N,N+S*3));for(let L=0;L<S;L++)h(U[L*3],U[L*3+1],U[L*3+2])}},syncRagdolls(c){if(u.size!==0){for(const[f,d]of u){const w=d.prev;d.prev=d.cur,d.cur=w;for(let S=0;S<d.entities.length;S++)lr(t.world(d.entities[S]),d.cur,S*et);c>1e-5&&(d.dt=c),d.valid<2&&d.valid++,d.active&&d.driven&&tt(e,d.cur,S=>e._cphysRagdollSetTarget(f,S))}y(e._cphysPullRagdolls())}},applyRootMotion(c,f,d,w,S){for(let N=c;N;N=t.parentOf(N)){const U=e._cphysCharacterForEntity(N);if(U){if(e._cphysCharacterSetExternalVelocity(U,w>0?f/w:0,w>0?d/w:0),S!==0){const L=t.get(N);L&&(nl(L.m,S),t.localMatrixChanged(N))}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),a.clear(),u.clear()}}}const os={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},Ee=Math.fround,as=Ee(1/3),ol=Ee(1/6),ls=Ee(2/3),al=Ee(3.14159265),ll=Ee(.9),tn=t=>t===32||t>=9&&t<=13,Sr=t=>t>=48&&t<=57,Pr=t=>t>=65&&t<=90?t+32:t,cs=t=>{const e=Pr(t);return e>=97&&e<=122},cl=t=>{const e=Pr(t);return e>=48&&e<=57?e-48:e>=97&&e<=102?e-87:-1},Rt=(t,e,r,n)=>{if(r!==n.length)return!1;for(let s=0;s<r;s++)if(Pr(t.charCodeAt(e+s))!==n.charCodeAt(s))return!1;return!0},hl=(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&&Sr(t.charCodeAt(n));)n++,s++;if(n<r&&t.charCodeAt(n)===46){let l=n+1;for(;l<r&&Sr(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&&Sr(t.charCodeAt(l))){for(;l<r&&Sr(t.charCodeAt(l));)l++;n=l}}return n-e},ul=(t,e,r)=>{const n=[];let s=e;for(;s<r;){for(;s<r&&(tn(t.charCodeAt(s))||t.charCodeAt(s)===44||t.charCodeAt(s)===47);)s++;if(s>=r)break;const i=hl(t,s,r);if(i===0||i>=64)return null;let l=Ee(parseFloat(t.slice(s,s+i)));s+=i;let o=!1;if(s<r&&t.charCodeAt(s)===37)o=!0,s++;else if(s<r&&cs(t.charCodeAt(s))){const a=s;for(;s<r&&cs(t.charCodeAt(s));)s++;const u=s-a;if(!Rt(t,a,u,"deg"))if(Rt(t,a,u,"rad"))l=Ee(l*180),l=Ee(l/al);else if(Rt(t,a,u,"turn"))l=Ee(l*360);else if(Rt(t,a,u,"grad"))l=Ee(l*ll);else return null}if(!Number.isFinite(l)||n.length===4)return null;n.push({v:l,percent:o})}return n.length>=3?n:null},zt=t=>t<0?0:t>1?1:t,Hr=(t,e,r)=>{r<0&&(r=Ee(r+1)),r>1&&(r=Ee(r-1));const n=Ee(e-t);return r<ol?Ee(t+Ee(Ee(n*6)*r)):r<.5?e:r<ls?Ee(t+Ee(Ee(n*Ee(ls-r))*6)):t},kr=(t,e,r,n)=>({r:Ee(t/255),g:Ee(e/255),b:Ee(r/255),a:Ee(n/255)}),fl=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&&tn(r.charCodeAt(n));)n++;for(;s>n&&tn(r.charCodeAt(s-1));)s--;const i=s-n;if(i===0)return null;if(r.charCodeAt(n)===35){const u=i-1;if(u!==3&&u!==4&&u!==6&&u!==8)return null;const g=[];for(let p=0;p<u;p++){const h=cl(r.charCodeAt(n+1+p));if(h<0)return null;g.push(h)}return u<=4?kr(g[0]*17,g[1]*17,g[2]*17,u===4?g[3]*17:255):kr(g[0]*16+g[1],g[2]*16+g[3],g[4]*16+g[5],u===8?g[6]*16+g[7]:255)}const l=r.indexOf("(",n);if(l>=0&&l<s&&r.charCodeAt(s-1)===41){const u=ul(r,l+1,s-1);if(!u)return null;const g=u.length===4?zt(u[3].percent?Ee(u[3].v/100):u[3].v):1,p=l-n;if(Rt(r,n,p,"rgb")||Rt(r,n,p,"rgba")){const h=v=>zt(v.percent?Ee(v.v/100):Ee(v.v/255));return{r:h(u[0]),g:h(u[1]),b:h(u[2]),a:g}}if(Rt(r,n,p,"hsl")||Rt(r,n,p,"hsla")){let h=u[0].v%360;h<0&&(h=Ee(h+360)),h=Ee(h/360);const v=zt(Ee(u[1].v/100)),M=zt(Ee(u[2].v/100));if(v<=0)return{r:M,g:M,b:M,a:g};const m=M<.5?Ee(M*Ee(1+v)):Ee(Ee(M+v)-Ee(M*v)),y=Ee(Ee(2*M)-m);return{r:zt(Hr(y,m,Ee(h+as))),g:zt(Hr(y,m,h)),b:zt(Hr(y,m,Ee(h-as))),a:g}}return null}if(i>20)return null;let o="";for(let u=n;u<s;u++)o+=String.fromCharCode(Pr(r.charCodeAt(u)));if(!Object.prototype.hasOwnProperty.call(os,o))return null;const a=os[o];return kr(a>>>24,a>>>16&255,a>>>8&255,a&255)},Bt=t=>{const e=Ee(t);if(!(e>0))return 0;if(e>=1)return 255;const r=Ee(e*255);return Math.floor(Ee(r+.5))},Wr=Math.fround,dl=t=>{if(typeof t=="number")return!Number.isInteger(t)||t<0||t>16777215?null:[Wr((t>>16&255)/255),Wr((t>>8&255)/255),Wr((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},Hs=t=>{if(typeof t=="string"){const e=fl(t);return e?[e.r,e.g,e.b,e.a]:null}return dl(t)},$r=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),ml=t=>{throw typeof t=="number"?new RangeError(`Color: ${$r(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: ${$r(t)} is not a CSS color`):new TypeError(`Color: ${$r(t)} is not a color — a string, an 0xRRGGBB number or [r, g, b(, a)] in 0..1`)},Er=t=>Hs(t)??ml(t),hs=t=>{const e=Er(t);return[Bt(e[0]),Bt(e[1]),Bt(e[2]),Bt(e[3])]},br=t=>(t<16?"0":"")+t.toString(16),pl=t=>"#"+br(Bt(t[0]))+br(Bt(t[1]))+br(Bt(t[2]))+br(Bt(t[3])),gl={toRgb01(t){const e=Er(t);return[e[0],e[1],e[2]]},toRgba01(t){return Er(t)},toPackedRgb(t){const e=hs(t);return e[0]<<16|e[1]<<8|e[2]},toPackedRgba(t){const e=hs(t);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0},toHexString(t){return pl(Er(t))},tryParse(t){return Hs(t)}},yl=.0025,us=1,fs=.85,vl=.13,xl=.1,wl=5,Ml=8,ds=15*Math.PI/180,Al=[[.93,.16,.12],[.42,.9,.16],[.16,.35,1]],Sl=[.85,.85,.88],ms=t=>[t[0]*.5+.5,t[1]*.5+.5,t[2]*.5+.5],ps=[.941,.396,.243],bl=[.36,.92,.48],_l=.85,$e=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],rr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],nr=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Qe=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],rn=(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]],er=t=>Math.hypot(t[0],t[1],t[2]),sr=t=>{const e=er(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Kt=(t,e,r,n)=>{const s=Qe(e,n);if(Math.abs(s)<1e-6)return null;const i=Qe($e(r,t),n)/s;return i<=0?null:rr(t,nr(e,i))},gs=(t,e,r,n,s)=>{const i=$e(t,r),l=Qe(n,e),o=Qe(n,i),a=Qe(e,i),u=1-l*l,g=Math.abs(u)<1e-8?o:(o-l*a)/u,p=Math.max(0,Math.min(s,g)),h=rr(r,nr(n,p)),v=Math.max(0,Qe($e(h,t),e));return{dist:er($e(h,rr(t,nr(e,v)))),t:p}},Cl=(t,e,r)=>{const n=rn(sr($e(t,r)),e),s=rn(e,n);return Qe(s,s)<1e-4?sr($e(t,r)):sr(s)},El=(t,e)=>{const[r,n,s]=t,i=Math.cos(e),l=Math.sin(e),o=1-i,a=new Float32Array(16);return a[0]=o*r*r+i,a[1]=o*r*n+l*s,a[2]=o*r*s-l*n,a[4]=o*r*n-l*s,a[5]=o*n*n+i,a[6]=o*n*s+l*r,a[8]=o*r*s+l*n,a[9]=o*n*s-l*r,a[10]=o*s*s+i,a[15]=1,a},Fl=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,o=t[4]/r,a=t[5]/r,u=t[6]/r,g=t[8]/n,p=t[9]/n,h=t[10]/n,v=s+a+h;let M,m,y,x;if(v>0){const F=.5/Math.sqrt(v+1);x=.25/F,M=(u-p)*F,m=(g-l)*F,y=(i-o)*F}else if(s>a&&s>h){const F=2*Math.sqrt(1+s-a-h);x=(u-p)/F,M=.25*F,m=(o+i)/F,y=(g+l)/F}else if(a>h){const F=2*Math.sqrt(1+a-s-h);x=(g-l)/F,M=(o+i)/F,m=.25*F,y=(p+u)/F}else{const F=2*Math.sqrt(1+h-s-a);x=(i-o)/F,M=(g+l)/F,m=(p+u)/F,y=.25*F}return{position:[t[12],t[13],t[14]],quaternion:[M,m,y,x],scale:[e,r,n]}},Tl=`#version 300 es
788
+ precision highp float;
789
+ in vec3 position;
790
+ in vec3 normal;
791
+ uniform mat4 modelViewMatrix;
792
+ uniform mat4 projectionMatrix;
793
+ uniform mat3 normalMatrix;
794
+ out vec3 vN;
795
+ void main() {
796
+ vN = normalize(normalMatrix * normal);
797
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
798
+ }
799
+ `,Pl=`#version 300 es
800
+ precision highp float;
801
+ in vec3 vN;
802
+ uniform vec3 uColor;
803
+ out vec4 fragColor;
804
+ void main() { fragColor = vec4(uColor * (0.72 + 0.28 * abs(vN.z)), 1.0); }
805
+ `,Rl=`#version 300 es
806
+ precision highp float;
807
+ in vec3 position;
808
+ uniform mat4 modelMatrix;
809
+ uniform mat4 modelViewMatrix;
810
+ uniform mat4 projectionMatrix;
811
+ out vec3 vWorld;
812
+ void main() {
813
+ vWorld = (modelMatrix * vec4(position, 1.0)).xyz;
814
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
815
+ }
816
+ `,Bl=`#version 300 es
817
+ precision highp float;
818
+ in vec3 vWorld;
819
+ uniform vec3 uColor;
820
+ uniform vec3 uOrigin;
821
+ uniform vec3 uEye;
822
+ uniform float uFull;
823
+ out vec4 fragColor;
824
+ void main() {
825
+ if (uFull < 0.5 && dot(vWorld - uOrigin, uOrigin - uEye) > 0.0) discard;
826
+ fragColor = vec4(uColor, 1.0);
827
+ }
828
+ `,jr=`#version 300 es
829
+ precision highp float;
830
+ in vec3 position;
831
+ uniform mat4 modelViewMatrix;
832
+ uniform mat4 projectionMatrix;
833
+ void main() { gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }
834
+ `,qr=`#version 300 es
835
+ precision highp float;
836
+ uniform vec3 uColor;
837
+ uniform float uAlpha;
838
+ out vec4 fragColor;
839
+ void main() { fragColor = vec4(uColor * uAlpha, uAlpha); }
840
+ `,Nl=`#version 300 es
841
+ in vec2 position;
842
+ in vec2 uv;
843
+ out vec2 vUv;
844
+ void main() { vUv = uv; gl_Position = vec4(position, 0.0, 1.0); }
845
+ `,Ll=`#version 300 es
846
+ precision highp float;
847
+ in vec2 vUv;
848
+ uniform sampler2D tMask;
849
+ uniform vec2 uTexel;
850
+ uniform vec3 uColor;
851
+ out vec4 fragColor;
852
+ void main() {
853
+ float center = texture(tMask, vUv).r;
854
+ float edge = 0.0;
855
+ for (int x = -2; x <= 2; x++) {
856
+ for (int y = -2; y <= 2; y++) {
857
+ edge = max(edge, texture(tMask, vUv + vec2(float(x), float(y)) * uTexel).r);
858
+ }
859
+ }
860
+ float a = clamp(edge - center, 0.0, 1.0);
861
+ if (a < 0.02) discard;
862
+ fragColor = vec4(uColor * a, a);
863
+ }
864
+ `,Ol=t=>{const{gl:e,renderer:r,canvas:n,camera:s,core:i}=t;let l={},o=!1,a=null,u=null,g="global";const p=.1,h=.22,v=[],M=new ot;{const Z=[];for(let K=-10;K<=10;K++)K!==0&&Z.push(K,0,-10,K,0,10,-10,0,K,10,0,K);const H=(K,se)=>{const ne=new Ie(e,{vertex:jr,fragment:qr,uniforms:{uColor:{value:[1,1,1]},uAlpha:{value:se}},transparent:!0});ne.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),v.push(ne);const he=new rt(e,{position:{size:3,data:Float32Array.from(K)}}),ue=new Ke(e,{geometry:he,program:ne,mode:e.LINES});return ue.frustumCulled=!1,ue};M.addChild(H(Z,p)),M.addChild(H([-10,.001,0,10,.001,0,0,.001,-10,0,.001,10],h))}let m=-1;const y=z=>{const H=.2126*(z[0]??0)+.7152*(z[1]??0)+.0722*(z[2]??0)>.5?0:1;if(H!==m){m=H;for(const K of v)K.uniforms.uColor.value=[H,H,H]}},x=new Ie(e,{vertex:Tl,fragment:Pl,uniforms:{uColor:{value:[1,1,1]}}}),F=new Ie(e,{vertex:Rl,fragment:Bl,uniforms:{uColor:{value:[1,1,1]},uOrigin:{value:[0,0,0]},uEye:{value:[0,0,0]},uFull:{value:0}}});let R=null,C=null;const P=new ot;P.matrixAutoUpdate=!1;const c=(z,Z,H=x)=>(z._axis=Z,z.frustumCulled=!1,z.onBeforeRender(()=>{const K=C?C.axis:R,se=Z===3?Sl:Al[Z];H.uniforms.uColor.value=K===Z?ms(se):se}),z),f=(z,Z)=>{const H=new ot;return Z===0?H.rotation.z=-Math.PI/2:Z===2&&(H.rotation.x=Math.PI/2),H.setParent(z),H},d=new ot,w=new ot,S=new ot;for(const z of[d,w,S])z.setParent(P);{const z=new In(e,{radiusTop:.014,radiusBottom:.014,height:.78,radialSegments:6}),Z=new In(e,{radiusTop:.001,radiusBottom:.065,height:.26,radialSegments:12}),H=new On(e,{width:.1,height:.1,depth:.1}),K=new On(e,{width:.14,height:.14,depth:.14}),se=new Ho(e,{radius:fs,tube:.02,radialSegments:8,tubularSegments:64});for(let ne=0;ne<3;ne++){const he=f(d,ne),ue=c(new Ke(e,{geometry:z,program:x}),ne);ue.position.y=.39;const pe=c(new Ke(e,{geometry:Z,program:x}),ne);pe.position.y=.87,he.addChild(ue),he.addChild(pe);const ve=f(S,ne),we=c(new Ke(e,{geometry:z,program:x}),ne);we.position.y=.39;const ge=c(new Ke(e,{geometry:H,program:x}),ne);ge.position.y=.83,ve.addChild(we),ve.addChild(ge);const xe=c(new Ke(e,{geometry:se,program:F}),ne,F);ne===0?xe.rotation.y=Math.PI/2:ne===1&&(xe.rotation.x=Math.PI/2),w.addChild(xe)}S.addChild(c(new Ke(e,{geometry:K,program:x}),3))}const N=()=>{if(a===null||u===null||!i.entities.has(a))return null;const z=i.activeSceneId(),Z=i.scenes.get(z);if(!Z||Z.camera===void 0)return null;const H=i.worldMatrixF(a),K=[H[12],H[13],H[14]],ne=g==="local"||u==="scale"?[0,1,2].map(ve=>sr([H[ve*4],H[ve*4+1],H[ve*4+2]])):[[1,0,0],[0,1,0],[0,0,1]],he=i.worldMatrixF(Z.camera),ue=[he[12],he[13],he[14]],pe=er($e(K,ue))||1;return{origin:K,axes:ne,scale:pe*yl*i.projectionOf(z).fov,camPos:ue,sceneId:z}},U=()=>{const z=N();if(!z)return!1;const Z=P.matrix;for(let K=0;K<3;K++)Z[K]=z.axes[0][K]*z.scale,Z[4+K]=z.axes[1][K]*z.scale,Z[8+K]=z.axes[2][K]*z.scale,Z[12+K]=z.origin[K];Z[3]=0,Z[7]=0,Z[11]=0,Z[15]=1,P.worldMatrixNeedsUpdate=!0,d.visible=u==="translate",w.visible=u==="rotate",S.visible=u==="scale";const H=F.uniforms;H.uOrigin.value=z.origin,H.uEye.value=z.camPos,H.uFull.value=C&&u==="rotate"?1:0;for(const K of[d,w,S])K.traverse(se=>{se._axis!==void 0&&(se.visible=C===null||se._axis===C.axis)});return!0},L=(z,Z)=>{const H=N();if(!H)return null;const{origin:K,dir:se}=t.getViewRay(H.sceneId,z,Z),ne=xl*H.scale;if(u==="rotate"){const pe=sr($e(H.origin,H.camPos));let ve=null,we=1/0;for(let ge=0;ge<3;ge++){const xe=Kt(K,se,H.origin,H.axes[ge]);if(!xe||Qe($e(xe,H.origin),pe)>0)continue;const Pe=Math.abs(er($e(xe,H.origin))-fs*H.scale),Fe=er($e(xe,K));Pe<ne&&Fe<we&&(ve=ge,we=Fe)}return ve}if(u==="scale"){const{dist:pe}=gs(K,se,H.origin,sr(se),0);if(pe<vl*H.scale)return 3}let he=null,ue=ne;for(let pe=0;pe<3;pe++){const{dist:ve}=gs(K,se,H.origin,H.axes[pe],(us+.05)*H.scale);ve<=ue&&(ue=ve,he=pe)}return he},$=z=>{const Z=n.getBoundingClientRect(),H=dn(n);return[(z.clientX-Z.left)/H,(z.clientY-Z.top)/H]},j=(z,Z)=>{const H=N();if(!H||a===null)return!1;const K=a,se=i.ent(K),ne=Float32Array.from(se.m),he=se.parent!==0?i.worldMatrixF(se.parent):He(),ue=wt(Float32Array.from(he)),pe=ut(new Float32Array(16),he,ne),[ve]=$(Z);let we=null;if(z===3)we=Te=>{const[We]=$(Te),Ge=Math.max(.01,1+(We-ve)/150),A=Float32Array.from(ne);for(let b=0;b<3;b++)for(let E=0;E<3;E++)A[b*4+E]*=Ge;i.methods.setMatrix(K,A)};else if(u==="rotate"){const Te=H.axes[z],{origin:We,dir:Ge}=t.getViewRay(H.sceneId,...$(Z)),A=Kt(We,Ge,H.origin,Te);if(!A)return!1;const b=$e(A,H.origin);we=E=>{const D=t.getViewRay(H.sceneId,...$(E)),G=Kt(D.origin,D.dir,H.origin,Te);if(!G)return;const W=$e(G,H.origin);let Q=Math.atan2(Qe(rn(b,W),Te),Qe(b,W));E.ctrlKey&&(Q=Math.round(Q/ds)*ds);const J=El(Te,Q),ae=[0,0,0];xt(ae,J,H.origin[0],H.origin[1],H.origin[2],1),J[12]=H.origin[0]-ae[0],J[13]=H.origin[1]-ae[1],J[14]=H.origin[2]-ae[2];const me=ut(new Float32Array(16),J,pe),Se=se.parent!==0?ut(new Float32Array(16),ue,me):me;i.methods.setMatrix(K,Se)}}else{const Te=H.axes[z],We=Cl(H.origin,Te,H.camPos),{origin:Ge,dir:A}=t.getViewRay(H.sceneId,...$(Z)),b=Kt(Ge,A,H.origin,We);if(!b)return!1;if(u==="translate"){const E=[pe[12],pe[13],pe[14]];we=D=>{const G=t.getViewRay(H.sceneId,...$(D)),W=Kt(G.origin,G.dir,H.origin,We);if(!W)return;const Q=Qe($e(W,b),Te),J=rr(E,nr(Te,Q)),ae=[0,0,0];se.parent!==0?xt(ae,ue,J[0],J[1],J[2],1):(ae[0]=J[0],ae[1]=J[1],ae[2]=J[2]),i.methods.setPosition(K,ae[0],ae[1],ae[2])}}else we=E=>{const D=t.getViewRay(H.sceneId,...$(E)),G=Kt(D.origin,D.dir,H.origin,We);if(!G)return;const W=Math.max(.01,1+Qe($e(G,b),Te)/(us*H.scale)),Q=Float32Array.from(ne);for(let J=0;J<3;J++)Q[z*4+J]*=W;i.methods.setMatrix(K,Q)}}if(!we)return!1;const ge=n.ownerDocument.defaultView??window,xe=Z.pointerId,Pe=Te=>{Te.pointerId===xe&&(C==null||C.onMove(Te))},Fe=Te=>{var Ge;if(!C)return;const We=C;C=null,We.cleanup(),Te?(Ge=l.onTransformEnd)==null||Ge.call(l,K,Fl(i.ent(K).m),u):i.methods.setMatrix(K,We.startLocal)},Be=Te=>{Te.pointerId===xe&&Fe(!0)},Ne=()=>Fe(!1),ie=Te=>{Te.code==="Escape"&&Fe(!1)};return ge.addEventListener("pointermove",Pe),ge.addEventListener("pointerup",Be),ge.addEventListener("pointercancel",Ne),ge.addEventListener("keydown",ie),C={axis:z,startLocal:ne,onMove:we,cleanup:()=>{ge.removeEventListener("pointermove",Pe),ge.removeEventListener("pointerup",Be),ge.removeEventListener("pointercancel",Ne),ge.removeEventListener("keydown",ie)}},!0},oe=new Ko,Y=(z,Z)=>{var we,ge;const H=i.activeSceneId(),K=t.sceneRoots.get(H),se=i.scenes.get(H);if(!K||!se||se.camera===void 0)return 0;const{origin:ne,dir:he}=t.getViewRay(H,z,Z);oe.origin.set(ne[0],ne[1],ne[2]),oe.direction.set(he[0],he[1],he[2]);const ue=[],pe=[];for(const xe of t.collectMeshes(K)){const Pe=(ge=(we=xe.geometry)==null?void 0:we.attributes)==null?void 0:ge.position;if(!(Pe!=null&&Pe.data))continue;const Fe=Pe.stride&&Pe.stride!==Pe.size*Pe.data.BYTES_PER_ELEMENT;xe.mode===e.TRIANGLES&&!Fe?ue.push(xe):pe.push(xe)}K.updateMatrixWorld();let ve=null;try{for(const xe of oe.intersectMeshes(ue,{cullFace:!1,includeUV:!1,includeNormal:!1,output:[]}))(!ve||xe.hit.distance<ve.hit.distance)&&(ve=xe)}catch{}try{for(const xe of oe.intersectBounds(pe,{output:[]}))(!ve||xe.hit.distance<ve.hit.distance)&&(ve=xe)}catch{}return(ve==null?void 0:ve._entId)??0};let O=null;const k=z=>{if(z.button!==0||z.shiftKey||C)return;const[Z,H]=$(z),K=L(Z,H);if(K!==null&&j(K,z)){z.preventDefault(),z.stopPropagation(),O=null;return}O={pointerId:z.pointerId,x:z.clientX,y:z.clientY}},V=z=>{var se;const Z=O;if(O=null,!Z||Z.pointerId!==z.pointerId||Math.abs(z.clientX-Z.x)+Math.abs(z.clientY-Z.y)>wl)return;const[H,K]=$(z);(se=l.onPick)==null||se.call(l,_e(H,K)||Y(H,K))},X=z=>{if(C)return;const[Z,H]=$(z),K=u!==null&&a!==null?L(Z,H):null,se=K===null&&T.length>0&&_e(Z,H)||null;(K!==R||se!==B)&&(R=K,B=se,n.style.cursor=K!==null||se!==null?"pointer":"")};n.addEventListener("pointerdown",k),n.addEventListener("pointerup",V),n.addEventListener("pointermove",X);const le=new Ie(e,{vertex:jr,fragment:qr,uniforms:{uColor:{value:bl},uAlpha:{value:_l}},transparent:!0,depthTest:!1,depthWrite:!1});le.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const ee=z=>new rt(e,{position:{size:3,data:Float32Array.from(z)}}),te=(z,Z,H,K,se=32)=>{for(let ne=0;ne<se;ne++)for(const he of[Math.PI*2*ne/se,Math.PI*2*(ne+1)/se]){const ue=Math.cos(he)*Z,pe=Math.sin(he)*Z;K===1?z.push(ue,H,pe):K===0?z.push(H,ue,pe):z.push(ue,pe,H)}},fe=ee((()=>{const z=[],Z=H=>[H&1?1:-1,H&2?1:-1,H&4?1:-1];for(let H=0;H<8;H++)for(const K of[1,2,4])H&K||z.push(...Z(H),...Z(H|K));return z})()),ye=ee((()=>{const z=[];return te(z,1,0,0),te(z,1,0,1),te(z,1,0,2),z})()),de=new Map,De=(z,Z,H)=>{const K=`${z}:${Z}:${H}`;let se=de.get(K);if(se)return se;const ne=[];te(ne,H,Z,1),te(ne,H,-Z,1);for(const[he,ue]of[[H,0],[-H,0],[0,H],[0,-H]])ne.push(he,-Z,ue,he,Z,ue);if(z==="capsule")for(const ue of[!0,!1])for(const pe of[0,2])for(let ve=0;ve<12;ve++)for(const we of[Math.PI*ve/12,Math.PI*(ve+1)/12]){const ge=Math.cos(we)*H,xe=(ue?Z:-Z)+Math.sin(we)*H*(ue?1:-1);pe===0?ne.push(ge,xe,0):ne.push(0,xe,ge)}return se=ee(ne),de.size>64&&de.clear(),de.set(K,se),se},qe=new ot,_=[],T=[];let B=null;const q=[.81,.83,.87,1],ce=z=>{var Z,H;for(const K of _)K.setParent(null),(H=(Z=K.geometry).remove)==null||H.call(Z);_.length=0,T.length=0,B=null;for(const K of Array.isArray(z)?z:[]){if(!K||!Array.isArray(K.segments)||K.segments.length<6)continue;const[se,ne,he,ue]=gl.tryParse(K.color)??q,pe=[se,ne,he],ve=Math.max(0,Math.min(1,Number(K.alpha??1)*ue)),we=new Ie(e,{vertex:jr,fragment:qr,uniforms:{uColor:{value:pe.slice()},uAlpha:{value:ve}},transparent:!0,depthTest:!1,depthWrite:!1});we.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const ge=Math.floor(K.segments.length/6)*6,xe=Float32Array.from(K.segments.slice(0,ge)),Pe=new rt(e,{position:{size:3,data:xe}}),Fe=new Ke(e,{geometry:Pe,program:we,mode:e.LINES});Fe.frustumCulled=!1,Fe.setParent(qe),_.push(Fe);const Be=Number(K.entityId??0);Be>0&&(Fe.matrixAutoUpdate=!1,T.push({entityId:Be,mesh:Fe,program:we,color:pe,segments:xe}))}},re=()=>{for(const z of T){if(!i.entities.has(z.entityId)){z.mesh.visible=!1;continue}z.mesh.visible=!0,z.mesh.matrix.copy(ze(z.entityId)),z.mesh.worldMatrixNeedsUpdate=!0;const Z=z.entityId===a?ps:z.entityId===B?ms(z.color):z.color,H=z.program.uniforms.uColor.value;H[0]=Z[0],H[1]=Z[1],H[2]=Z[2]}},_e=(z,Z)=>{if(T.length===0)return 0;const H=i.activeSceneId(),K=i.scenes.get(H);if(!K||K.camera===void 0)return 0;const{origin:se,dir:ne}=t.getViewRay(H,z,Z),he=n.getBoundingClientRect(),ue=Math.max(1,he.height/dn(n)),pe=2*Math.tan(i.projectionOf(H).fov*Math.PI/360)*Ml/ue;let ve=0,we=1,ge=1/0;const xe=[0,0,0],Pe=[0,0,0];for(const Fe of T){if(!i.entities.has(Fe.entityId))continue;const Be=ze(Fe.entityId),Ne=Fe.segments;for(let ie=0;ie+5<Ne.length;ie+=6){for(let be=0;be<3;be++)xe[be]=Be[be]*Ne[ie]+Be[4+be]*Ne[ie+1]+Be[8+be]*Ne[ie+2]+Be[12+be],Pe[be]=Be[be]*Ne[ie+3]+Be[4+be]*Ne[ie+4]+Be[8+be]*Ne[ie+5]+Be[12+be];const Te=$e(Pe,xe),We=$e(xe,se),Ge=Qe(ne,ne),A=Qe(ne,Te),b=Qe(Te,Te),E=Qe(ne,We),D=Qe(Te,We),G=Ge*b-A*A;let W=G>1e-12?(A*E-Ge*D)/G:0;W=Math.max(0,Math.min(1,W));const Q=Math.max(0,(E+W*A)/(Ge||1)),J=rr(xe,nr(Te,W)),ae=rr(se,nr(ne,Q));if(Q<=1e-6)continue;const me=Q*pe,Se=er($e(J,ae))/me;Se>1||(Se<we-.001||Math.abs(Se-we)<=.001&&Q<ge)&&(ve=Fe.entityId,we=Se,ge=Q)}}return ve};let Ae=[];const Le=new ot,Ue=[],Xe=[1,1,1],ze=z=>{const Z=Float32Array.from(i.worldMatrix(z));for(let H=0;H<3;H++){const K=Math.hypot(Z[H*4],Z[H*4+1],Z[H*4+2])||1;Xe[H]=K,Z[H*4]/=K,Z[H*4+1]/=K,Z[H*4+2]/=K}return Z},Ye=(z,Z,H,K,se=0,ne=0,he=0)=>{const ue=Float32Array.from(z);ue[12]=z[12]+z[0]*se+z[4]*ne+z[8]*he,ue[13]=z[13]+z[1]*se+z[5]*ne+z[9]*he,ue[14]=z[14]+z[2]*se+z[6]*ne+z[10]*he;for(let pe=0;pe<3;pe++)ue[pe]*=Z,ue[4+pe]*=H,ue[8+pe]*=K;return ue},Ze=(z,Z)=>{const H=i.entities.get(z);if(H){for(const K of t.drawablesOf(z))K.mode===e.TRIANGLES&&Z.push(K);for(const K of H.children)Ze(K,Z)}},at=new Map,pt=z=>{const Z=new Map,H=[],K=(he,ue,pe)=>{const ve=`${he.toFixed(5)},${ue.toFixed(5)},${pe.toFixed(5)}`;let we=Z.get(ve);return we===void 0&&(we=H.length/3,Z.set(ve,we),H.push(he,ue,pe)),we},se=new Set;for(let he=0;he+8<z.length;he+=9){const ue=K(z[he],z[he+1],z[he+2]),pe=K(z[he+3],z[he+4],z[he+5]),ve=K(z[he+6],z[he+7],z[he+8]);for(const[we,ge]of[[ue,pe],[pe,ve],[ve,ue]])se.add(we<ge?we*65536+ge:ge*65536+we)}const ne=[];for(const he of se){const ue=Math.floor(he/65536)*3,pe=he%65536*3;ne.push(H[ue],H[ue+1],H[ue+2],H[pe],H[pe+1],H[pe+2])}return new rt(e,{position:{size:3,data:Float32Array.from(ne)}})},gt=z=>{var ve,we;const Z=[];Ze(z,Z);const H=ze(z),K=Z.map(ge=>{var xe;return((xe=ge.geometry)==null?void 0:xe.id)??"?"}).join(",")+"|"+Xe.map(ge=>ge.toFixed(4)).join(","),se=at.get(z);if(se&&se.key===K)return se.geometry;const ne=wt(H),he=[];for(const ge of Z){const xe=(we=(ve=ge.geometry)==null?void 0:ve.attributes)==null?void 0:we.position,Pe=xe==null?void 0:xe.data;if(!(Pe instanceof Float32Array)||xe.size!==3||xe.stride)continue;const Fe=ut(new Float32Array(16),ne,ge.worldMatrix);for(let Be=0;Be+2<Pe.length;Be+=3){const Ne=Pe[Be],ie=Pe[Be+1],Te=Pe[Be+2];he.push(Fe[0]*Ne+Fe[4]*ie+Fe[8]*Te+Fe[12],Fe[1]*Ne+Fe[5]*ie+Fe[9]*Te+Fe[13],Fe[2]*Ne+Fe[6]*ie+Fe[10]*Te+Fe[14])}}const ue=he.length>=12?sl(he):null,pe=ue?pt(ue):null;return at.set(z,{key:K,geometry:pe}),pe},Nt=()=>{var Z,H,K;for(const se of Ue)se.setParent(null);Ue.length=0;const z=(se,ne)=>{const he=new Ke(e,{geometry:se,program:le,mode:e.LINES});he.frustumCulled=!1,he.matrixAutoUpdate=!1,he.matrix.copy(ne),he.setParent(Le),Ue.push(he)};for(const se of Ae){if(!i.entities.has(se.entityId))continue;const ne=se.shape,he=se.origin,[ue,pe,ve]=he??[0,0,0];if(ne.kind==="box")z(fe,Ye(ze(se.entityId),ne.half[0],ne.half[1],ne.half[2],ue,pe,ve));else if(ne.kind==="sphere")z(ye,Ye(ze(se.entityId),ne.radius,ne.radius,ne.radius,ue,pe,ve));else if(ne.kind==="cylinder"||ne.kind==="capsule")z(De(ne.kind,ne.halfHeight,ne.radius),Ye(ze(se.entityId),1,1,1,ue,pe,ve));else if(ne.kind==="mesh"&&ne.convex&&gt(se.entityId))z(gt(se.entityId),Ye(ze(se.entityId),1,1,1,ue,pe,ve));else if(ne.kind==="mesh"){const we=[];Ze(se.entityId,we);const ge=ze(se.entityId),xe=ge[0]*ue+ge[4]*pe+ge[8]*ve,Pe=ge[1]*ue+ge[5]*pe+ge[9]*ve,Fe=ge[2]*ue+ge[6]*pe+ge[10]*ve;for(const Be of we){if(!((H=(Z=Be.geometry)==null?void 0:Z.attributes)!=null&&H.position))continue;const Ne=Float32Array.from(Be.worldMatrix);Ne[12]+=xe,Ne[13]+=Pe,Ne[14]+=Fe,z(t.wireGeometryFor(Be.geometry),Ne)}}else{const we=t.drawablesOf(se.entityId).find(b=>b.mode===e.TRIANGLES);let ge=.5,xe=.5,Pe=.5,Fe=0,Be=0,Ne=0;const ie=(K=we==null?void 0:we.geometry)==null?void 0:K.bounds;ie&&isFinite(ie.min.x)&&(ge=(ie.max.x-ie.min.x)/2,xe=(ie.max.y-ie.min.y)/2,Pe=(ie.max.z-ie.min.z)/2,Fe=(ie.max.x+ie.min.x)/2,Be=(ie.max.y+ie.min.y)/2,Ne=(ie.max.z+ie.min.z)/2);const Te=ze(se.entityId),[We,Ge,A]=Xe;z(fe,he?Ye(Te,ge*We,xe*Ge,Pe*A,ue,pe,ve):Ye(Te,ge*We,xe*Ge,Pe*A,Fe*We,Be*Ge,Ne*A))}}return Ue.length>0},_t=new Ie(e,{vertex:ur(!1),fragment:fr,uniforms:{modelMatrix:{value:He()},shadowViewProjection:{value:He()}},depthTest:!1,depthWrite:!1,cullFace:!1}),dt=new Ie(e,{vertex:ur(!0),fragment:fr,uniforms:{modelMatrix:{value:He()},shadowViewProjection:{value:He()},boneTexture:{value:null},boneTextureSize:{value:4}},depthTest:!1,depthWrite:!1,cullFace:!1});let ke=null;const Je=new Ie(e,{vertex:Nl,fragment:Ll,uniforms:{tMask:{value:null},uTexel:{value:[0,0]},uColor:{value:ps}},depthTest:!1,depthWrite:!1,transparent:!0});Je.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const Mt=new Ke(e,{geometry:new Go(e),program:Je}),Lt=(z,Z)=>{const H=i.entities.get(z);if(!(!H||!H.visible)){Z.push(...t.drawablesOf(z));for(const K of H.children)Lt(K,Z)}},Ot=()=>{if(a===null||!i.entities.has(a))return;const z=[];if(Lt(a,z),z.length===0)return;(!ke||ke.width!==n.width||ke.height!==n.height)&&(ke=new Ns(e,{width:Math.max(1,n.width),height:Math.max(1,n.height)}));const Z=ut(new Float32Array(16),s.projectionMatrix,s.viewMatrix);_t.uniforms.shadowViewProjection.value=Z,dt.uniforms.shadowViewProjection.value=Z,r.bindFramebuffer(ke),r.setViewport(ke.width,ke.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);const H=He();for(const K of z){const se=K instanceof vt,ne=se?dt:_t;ne.uniforms.modelMatrix.value=se?H:K.worldMatrix;const he=K.program;K.program=ne,K.draw({}),K.program=he}r.bindFramebuffer({buffer:null}),r.setViewport(n.width,n.height),Je.uniforms.tMask.value=ke.texture,Je.uniforms.uTexel.value=[1/ke.width,1/ke.height],Mt.draw({})},Oe=z=>{o&&(y(z),r.render({scene:M,camera:s,clear:!1,frustumCull:!1,sort:!1}))},yr=()=>{Ot(),Ae.length>0&&Nt()&&r.render({scene:Le,camera:s,clear:!1,frustumCull:!1,sort:!1}),_.length>0&&(re(),r.render({scene:qe,camera:s,clear:!1,frustumCull:!1,sort:!1})),U()&&(r.setDepthMask(!0),e.clear(e.DEPTH_BUFFER_BIT),r.render({scene:P,camera:s,clear:!1,frustumCull:!1,sort:!1}))};let or=null;const At=new sn(e,{fov:60,near:.01,far:1e3,aspect:1});return At.matrixAutoUpdate=!1,{api:{setGrid(z){o=z===!0},setSelection(z){C&&z!==a&&(C.cleanup(),C=null),a=z&&z>0?z:null},setGizmoMode(z){u=z==="translate"||z==="rotate"||z==="scale"?z:null,R=null},setGizmoSpace(z){g=z==="local"?"local":"global"},setColliders(z){Ae=Array.isArray(z)?z.slice():[]},setGizmos:ce,setPreview(z){or=z&&z.entityId>0?z:null},pickAt(z,Z){return Y(z,Z)}},setHandlers(z){l=z??{}},renderScenePass:Oe,renderOverlayPass:yr,renderPreviewPass:(z,Z)=>{const H=or;if(!H)return;const K=n.width/(n.getBoundingClientRect().width||n.width),se=Math.round(H.rect[0]*K),ne=Math.round(H.rect[1]*K),he=Math.round(H.rect[2]*K),ue=Math.round(H.rect[3]*K);if(he<2||ue<2)return;const pe=i.worldMatrixF(H.entityId);if(!pe)return;for(let ge=0;ge<16;ge++)At.matrix[ge]=pe[ge];At.worldMatrixNeedsUpdate=!0,At.perspective({fov:H.fov,aspect:he/ue,near:H.near,far:H.far}),At.updateMatrixWorld();const ve=[];for(const ge of H.hide??[])for(const xe of t.drawablesOf(ge))xe.visible&&(xe.visible=!1,ve.push(xe));const we=n.height-ne-ue;r.bindFramebuffer({buffer:null}),r.setViewport(he,ue,se,we),e.enable(e.SCISSOR_TEST),e.scissor(se,we,he,ue),e.clearColor(Z[0]??0,Z[1]??0,Z[2]??0,1),r.enable(e.DEPTH_TEST),r.setDepthMask(!0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),t.renderScene(z,At,ve.length>0),e.disable(e.SCISSOR_TEST);for(const ge of ve)ge.visible=!0;r.setViewport(n.width,n.height)},dispose:()=>{C==null||C.cleanup(),C=null,n.removeEventListener("pointerdown",k),n.removeEventListener("pointerup",V),n.removeEventListener("pointermove",X),n.style.cursor=""}}},Il={value:0},Qt=16,Dl=600,zl=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])),Ul=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]),Vl=(t,e)=>{const r=new Map,n=[],s=[],i=[];let l=-1;const o=new Float32Array(16);let a=!0,u=!0;const g=new Map;let p=0;const h=O=>{const k=g.get(O);if(k!==void 0)return k;let V=null;const X=t.getShaderSource(O.vertexShader),le=t.getShaderSource(O.fragmentShader);if(X&&le&&X.startsWith("#version")){const ee=X.replace(/^([^\n]*\n)/,`$1#define INSTANCED
865
+ `),te=new Ie(t,{vertex:ee,fragment:le,uniforms:O.uniforms,transparent:O.transparent,cullFace:O.cullFace,frontFace:O.frontFace,depthTest:O.depthTest,depthWrite:O.depthWrite,depthFunc:O.depthFunc});let fe=!1;te.attributeLocations.forEach((ye,de)=>{de.name==="instanceMatrix"&&(fe=!0)}),fe&&t.getProgramParameter(te.program,t.LINK_STATUS)?V=te:te.remove()}return g.set(O,V),V},v=(O,k)=>{O.transparent=k.transparent,O.cullFace=k.cullFace,O.frontFace=k.frontFace,O.depthTest=k.depthTest,O.depthWrite=k.depthWrite,O.depthFunc=k.depthFunc,O.blendFunc=k.blendFunc,O.blendEquation=k.blendEquation},M=(O,k)=>{const V={};for(const[le,ee]of Object.entries(O.attributes))V[le]={size:ee.size,data:ee.data,type:ee.type,normalized:ee.normalized,stride:ee.stride,offset:ee.offset,buffer:ee.buffer,count:ee.count};V.instanceMatrix={instanced:1,size:16,data:new Float32Array(k*16),usage:t.DYNAMIC_DRAW};const X=new rt(t,V);return X.drawRange.start=O.drawRange.start,X.drawRange.count=O.drawRange.count,X},m=O=>{for(const V of Object.values(O.VAOs))e.deleteVertexArray(V);O.VAOs={};const k=O.attributes.instanceMatrix;k!=null&&k.buffer&&(t.deleteBuffer(k.buffer),k.buffer=null),e.currentGeometry=null},y=(O,k)=>{const V=O.attributes.instanceMatrix;let X=Math.max(Qt,V.count);for(;X<k;)X*=2;const le=new Float32Array(X*16);return le.set(V.data),m(O),O.instancedCount=0,O.addAttribute("instanceMatrix",{instanced:1,size:16,data:le,usage:t.DYNAMIC_DRAW}),le},x=(O,k,V)=>{const X=O.attributes.instanceMatrix;V>0&&(t.bindBuffer(t.ARRAY_BUFFER,X.buffer),e.state.boundBuffer=X.buffer,t.bufferSubData(t.ARRAY_BUFFER,0,k,0,V*16)),O.setInstancedCount(V)},F=(O,k,V)=>{const X=O.program,le=O._castShadows!==!1,ee=O._receiveShadows!==!1,te=`${O.geometry.id}|${X.id}|${O.mode}|${O.renderOrder}|${le?1:0}${ee?1:0}${V?1:0}`;let fe=r.get(te);if(!fe){const ye=O.geometry;fe={key:te,source:ye,program:X,twin:k,mode:O.mode,renderOrder:O.renderOrder,castShadows:le,receiveShadows:ee,flip:V,all:new Float32Array(Qt*16),allCount:0,allDirty:!0,geoAll:M(ye,Qt),sph:new Float32Array(Qt*4),vis:new Float32Array(Qt*16),visCount:0,visDirty:!0,geoVis:M(ye,Qt),bounds:new Float32Array(6),lastUsed:p},r.set(te,fe)}return fe},R=O=>{var V,X;if(!u||O instanceof vt||O._particles||O.mode===t.POINTS)return null;const k=O.program;return k.transparent||!k.depthTest||!((X=(V=O.geometry)==null?void 0:V.attributes)!=null&&X.position)||O.geometry.isInstanced||k.uniforms.uMorphTex?null:h(k)},C=O=>{const k=O.geometry;return(!k.bounds||k.bounds.radius===1/0)&&k.computeBoundingSphere(),k.bounds&&isFinite(k.bounds.radius)?k.bounds:null},P=(O,k,V,X,le)=>{const ee=O.frustum;for(let te=0;te<6;te++){const fe=ee[te];if(fe[0]*k+fe[1]*V+fe[2]*X+fe.constant<-le)return!1}return!0},c=(O,k,V)=>{const X=k*16;let le=!1;for(let ee=0;ee<16;ee++){const te=V[ee];O[X+ee]!==te&&(O[X+ee]=te,le=!0)}return le},f=O=>{const k=O.source;k.bounds||k.computeBoundingBox();const V=O.bounds;if(V[0]=V[1]=V[2]=1/0,V[3]=V[4]=V[5]=-1/0,!k.bounds||!isFinite(k.bounds.min.x))return;const{min:X,max:le}=k.bounds,ee=[0,0,0];for(let te=0;te<O.allCount;te++){const fe=O.all.subarray(te*16,te*16+16);for(let ye=0;ye<8;ye++){xt(ee,fe,ye&1?le.x:X.x,ye&2?le.y:X.y,ye&4?le.z:X.z,1);for(let de=0;de<3;de++)ee[de]<V[de]&&(V[de]=ee[de]),ee[de]>V[de+3]&&(V[de+3]=ee[de])}}},d=[0,0,0],w=O=>{p++,s.length=0,i.length=0;for(const k of r.values())k.allCount=0;O.traverse(k=>{if(!k.visible)return!0;if(!k.draw)return!1;const V=k.worldMatrix,X=R(k);if(!X)return s.push(k),k._castShadows!==!1&&i.push(k),!1;const le=!!k.program.cullFace&&Ul(V)<0,ee=F(k,X,le);ee.lastUsed=p;const te=ee.allCount;if(te*16>=ee.all.length){ee.all=y(ee.geoAll,te+1);const de=new Float32Array(ee.all.length/4);de.set(ee.sph),ee.sph=de}c(ee.all,te,V)&&(ee.allDirty=!0);const fe=C(k),ye=te*4;return fe&&k.frustumCulled?(xt(d,V,fe.center.x,fe.center.y,fe.center.z,1),ee.sph[ye]=d[0],ee.sph[ye+1]=d[1],ee.sph[ye+2]=d[2],ee.sph[ye+3]=fe.radius*zl(V)):ee.sph[ye+3]=-1,ee.allCount++,!1});for(const[k,V]of r)V.allCount!==V.geoAll.instancedCount&&(V.allDirty=!0),V.allDirty&&(x(V.geoAll,V.all,V.allCount),f(V),V.allDirty=!1),V.allCount===0&&p-V.lastUsed>Dl&&(m(V.geoAll),m(V.geoVis),r.delete(k))},S=(O,k)=>{O.updateFrustum();for(const V of r.values()){V.visCount=0;const X=V.allCount;for(let le=0;le<X;le++){const ee=le*4;if(k&&V.sph[ee+3]>=0&&!P(O,V.sph[ee],V.sph[ee+1],V.sph[ee+2],V.sph[ee+3]))continue;const te=V.visCount;te*16>=V.vis.length&&(V.vis=y(V.geoVis,te+1));const fe=le*16,ye=te*16;for(let de=0;de<16;de++){const De=V.all[fe+de];V.vis[ye+de]!==De&&(V.vis[ye+de]=De,V.visDirty=!0)}V.visCount++}V.visCount!==V.geoVis.instancedCount&&(V.visDirty=!0),V.visDirty&&(x(V.geoVis,V.vis,V.visCount),V.visDirty=!1)}n.length=0;for(const V of s)k&&V.frustumCulled&&!O.frustumIntersectsMesh(V)||n.push(V)},N=(O,k,V,X=-2,le=!1)=>{const ee=le||X!==l;ee&&(w(O),l=X),k.updateMatrixWorld();const te=k.projectionViewMatrix;let fe=V!==a;for(let ye=0;ye<16&&!fe;ye++)o[ye]!==te[ye]&&(fe=!0);if(!(!ee&&!fe)){S(k,V);for(let ye=0;ye<16;ye++)o[ye]=te[ye];a=V}},U=()=>[...r.values()].sort((O,k)=>O.renderOrder-k.renderOrder);return{collect:N,drawMain:(O,k)=>{for(const te of U()){if(te.visCount===0)continue;const fe=te.twin.uniforms;(fe.projectionMatrix??(fe.projectionMatrix={value:null})).value=O.projectionMatrix,(fe.viewMatrix??(fe.viewMatrix={value:null})).value=O.viewMatrix,(fe.cameraPosition??(fe.cameraPosition={value:null})).value=O.worldPosition;const ye=fe.shadowEnabled;ye&&(fe.shadowEnabled=te.receiveShadows?k:Il),v(te.twin,te.program),te.twin.use({flipFaces:te.flip}),te.geoVis.draw({mode:te.mode,program:te.twin}),ye&&(fe.shadowEnabled=ye)}const V=[],X=[],le=[],ee=O.projectionViewMatrix;for(const te of n){if(te.program.transparent?te.program.depthTest?X.push(te):le.push(te):V.push(te),te.zDepth=0,te.renderOrder!==0||!te.program.depthTest)continue;const fe=te.worldMatrix,ye=fe[12],de=fe[13],De=fe[14],qe=ee[3]*ye+ee[7]*de+ee[11]*De+ee[15]||1;te.zDepth=(ee[2]*ye+ee[6]*de+ee[10]*De+ee[14])/qe}V.sort(e.sortOpaque),X.sort(e.sortTransparent),le.sort(e.sortUI);for(const te of V)te.draw({camera:O});for(const te of X)te.draw({camera:O});for(const te of le)te.draw({camera:O})},drawShadow:O=>{for(const k of r.values())!k.castShadows||k.allCount===0||(O.use({flipFaces:k.flip}),k.geoAll.draw({mode:k.mode,program:O}))},casterBounds:(O,k)=>{for(const V of r.values())if(!(!V.castShadows||V.allCount===0||!isFinite(V.bounds[0])))for(let X=0;X<3;X++)V.bounds[X]<O[X]&&(O[X]=V.bounds[X]),V.bounds[X+3]>k[X]&&(k[X]=V.bounds[X+3])},isBatched:O=>R(O)!==null,dispose:()=>{for(const O of r.values())m(O.geoAll),m(O.geoVis);r.clear();for(const O of g.values())O==null||O.remove();g.clear()},setEnabled:O=>{u=O,l=-1},singles:n,casterSingles:i,stats:()=>{let O=0,k=0,V=0;for(const X of r.values())X.allCount>0&&(V++,O+=X.allCount,k+=X.visCount);return{batches:V,instances:O,visible:k,singles:n.length}}}},Gl=1179937895,Hl=1313821514,kl=t=>{var e,r;try{if(t.byteLength<20)return null;const n=new DataView(t);if(n.getUint32(0,!0)!==Gl)return null;const s=n.getUint32(12,!0);if(n.getUint32(16,!0)!==Hl||20+s>t.byteLength)return null;const i=JSON.parse(new TextDecoder("utf-8").decode(new Uint8Array(t,20,s))),l=i.accessors??[],o=i.meshes??[],a=(i.nodes??[]).map(h=>{var m;let v;Array.isArray(h.matrix)&&h.matrix.length===16?v=Float32Array.from(h.matrix):h.translation||h.rotation||h.scale?v=Is(h.translation??[0,0,0],h.rotation??[0,0,0,1],h.scale??[1,1,1]):v=He();const M={children:h.children??[],matrix:v};if(typeof h.name=="string"&&h.name.length>0&&(M.name=h.name),h.mesh!=null&&o[h.mesh]){const y=o[h.mesh].primitives??[];let x,F;for(const R of y){const C=l[(m=R.attributes)==null?void 0:m.POSITION];if(!(!C||!Array.isArray(C.min)||!Array.isArray(C.max)))if(!x||!F)x=[C.min[0],C.min[1],C.min[2]],F=[C.max[0],C.max[1],C.max[2]];else for(let P=0;P<3;P++)x[P]=Math.min(x[P],C.min[P]),F[P]=Math.max(F[P],C.max[P])}M.mesh={primitives:y.length,min:x,max:F}}return M});for(const h of i.skins??[])for(const v of h.joints??[])a[v]&&(a[v].skinJoint=!0);const u=(i.animations??[]).map((h,v)=>{var m,y;let M=0;for(const x of h.samplers??[]){const F=(y=(m=l[x.input])==null?void 0:m.max)==null?void 0:y[0];typeof F=="number"&&F>M&&(M=F)}return{name:typeof h.name=="string"?h.name:`animation_${v}`,duration:M}}),g=i.scene??0,p=((r=(e=i.scenes)==null?void 0:e[g])==null?void 0:r.nodes)??[];return{nodes:a,roots:p,animations:u}}catch{return null}};let Wl=null,on=null;const $l=()=>Wl??(Wl=mr(()=>import("./creatorAnim-BOwKr-C1.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.default()).then(t=>on=t)),ks=()=>on!==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)}},jl=(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)}},it=(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)}},ql=(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)}},Xr=(t,e,r,n,s,i,l,o,a,u,g)=>{const p=s+s,h=i+i,v=l+l,M=s*p,m=s*h,y=s*v,x=i*h,F=i*v,R=l*v,C=o*p,P=o*h,c=o*v,f=t;f[0]=(1-(x+R))*a,f[1]=(m+c)*a,f[2]=(y-P)*a,f[3]=0,f[4]=(m-c)*u,f[5]=(1-(M+R))*u,f[6]=(F+C)*u,f[7]=0,f[8]=(y+P)*g,f[9]=(F-C)*g,f[10]=(1-(M+x))*g,f[11]=0,f[12]=e,f[13]=r,f[14]=n,f[15]=1},_r=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,o=n!==0?1/n:0,a=s!==0?1/s:0,u=e[0]*l,g=e[1]*l,p=e[2]*l,h=e[4]*o,v=e[5]*o,M=e[6]*o,m=e[8]*a,y=e[9]*a,x=e[10]*a,F=u+v+x;let R,C,P,c;if(F>0){const f=.5/Math.sqrt(F+1);c=.25/f,R=(M-y)*f,C=(m-p)*f,P=(g-h)*f}else if(u>v&&u>x){const f=2*Math.sqrt(1+u-v-x);c=(M-y)/f,R=.25*f,C=(h+g)/f,P=(m+p)/f}else if(v>x){const f=2*Math.sqrt(1+v-u-x);c=(m-p)/f,R=(h+g)/f,C=.25*f,P=(y+M)/f}else{const f=2*Math.sqrt(1+x-u-v);c=(g-h)/f,R=(m+p)/f,C=(y+M)/f,P=.25*f}return{t:[e[12],e[13],e[14]],r:[R,C,P,c],s:[r,n,s]}},Xl=(t,e)=>{const r=Math.cos(e),n=Math.sin(e),s=t[0],i=t[1],l=t[2],o=t[8],a=t[9],u=t[10];t[0]=s*r-o*n,t[1]=i*r-a*n,t[2]=l*r-u*n,t[8]=s*n+o*r,t[9]=i*n+a*r,t[10]=l*n+u*r};let ys=!1;const Yr=t=>typeof t._canimAnimatorLateSolve=="function"?!0:(ys||(ys=!0,console.warn("creator-anim: this wasm predates IK chains / sockets — rebuild it (build-wasm.sh + vendor:creator); chains are inert")),!1),Zt=19,mt={TARGET_X:0,POLE_X:3,HAS_POLE:6,ROT_X:8},vs=64,cr=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Yl(t){const e=on;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),o=e._malloc(12),a=e._malloc(12),u=e._malloc(32),g=e._malloc(4),p=e._malloc(4),h=e._malloc(vs*4),v=[],M=[];let m=null;const y=c=>{const f=c instanceof Uint8Array?c:new Uint8Array(c);return ql(e,f,d=>e._canimClipsLoad(d,f.length))},x=c=>{e._free(c.trs),e._free(c.write)},F={loadClips(c,f,d){const w=t.getBuffer(c),S=w?y(w):0;if(!S){d(new Error("loadClips: not a GLB with animations"));return}f(S)},createClipFromTracks(c,f){return it(e,c,d=>ct(e,f,w=>e._canimClipsFromTracks(d,w,f.length)))},getClipSetInfo(c){const f=e._canimClipsCount(c),d=[];for(let w=0;w<f;w++){const S=e._canimClipName(c,w);d.push({name:S?e.UTF8ToString(S):"",duration:e._canimClipDuration(c,w),trackCount:e._canimClipTrackCount(c,w)})}return d},sliceClip(c,f,d,w){return e._canimClipsSlice(c,f,d,w)},deriveClip(c,f,d,w,S){return e._canimClipsDerive(c,f,d?1:0,w,S)},destroyClipSet(c){e._canimClipsDestroy(c)},animatorCreate(c){if(!t.get(c))return 0;const d=[],w=[],S=[],N=[],U=[],L=(k,V)=>{const X=t.get(k);if(!X)return;const le=d.length;d.push(k),w.push(V),S.push(X.name??""),U.push(X.skinJoint?1:0);const{t:ee,r:te,s:fe}=_r(X.m);N.push(ee[0],ee[1],ee[2],te[0],te[1],te[2],te[3],fe[0],fe[1],fe[2]);for(const ye of X.children)L(ye,le)};L(c,-1);const $=d.length,j=e._malloc(Math.max(4,$*4));e.HEAP32.set(w,j>>2);const oe=e._malloc(Math.max(1,$));e.HEAPU8.set(U,oe);let Y=0;try{Y=it(e,S.join(`
866
+ `),k=>ct(e,N,V=>e._canimAnimatorCreate($,j,k,V,oe,c)))}finally{e._free(j),e._free(oe)}if(!Y)return 0;const O=e._canimAnimatorShadowedNames(Y);return O>0&&console.warn(`[Animator] ${O} bone name(s) exist twice under this model (a leftover skeleton copy?) — bound to the skinned ones; run 'lecodes assets doctor' on the GLB`),r.set(Y,{rootId:c,entities:d,trs:e._malloc(Math.max(4,$*40)),write:e._malloc(Math.max(1,$)),n:$,feetOn:!1,iks:[],sockets:[]}),Y},animatorDestroy(c){const f=r.get(c);if(!f){e._canimAnimatorDestroy(c);return}e._canimAnimatorRest(c,f.trs,f.write);const d=e.HEAPF32,w=e.HEAPU8,S=f.trs>>2;for(let N=0;N<f.n;N++){if(!w[f.write+N])continue;const U=t.get(f.entities[N]);if(!U)continue;const L=S+N*10;Xr(U.m,d[L],d[L+1],d[L+2],d[L+3],d[L+4],d[L+5],d[L+6],d[L+7],d[L+8],d[L+9]),t.localMatrixChanged(f.entities[N])}e._canimAnimatorDestroy(c),x(f),r.delete(c)},animatorBind(c,f,d,w){return e._canimAnimatorBind(c,f,d,w)},animatorBindMirror(c,f,d,w){return e._canimAnimatorBindMirror?e._canimAnimatorBindMirror(c,f,d,w):-1},animatorBoundTracks(c,f){return e._canimAnimatorBoundTracks(c,f)},setClipEvents(c,f,d){ct(e,d,w=>e._canimClipsSetEvents(c,f,w,d.length))},animatorSetBlend(c,f,d,w,S,N,U,L){const $=d>1?2:1,j=Math.min(w.length,Math.floor(S.length/$)),oe=L&&L.length>=j*2?L:null;jl(e,w,Y=>ct(e,S,O=>{oe?ct(e,oe,k=>e._canimAnimatorSetBlend(c,f,$,Y,O,k,j,N,U)):e._canimAnimatorSetBlend(c,f,$,Y,O,0,j,N,U)}))},animatorSetBlendValue(c,f,d,w){e._canimAnimatorSetBlendValue(c,f,d,w)},animatorSlotSetTurn(c,f,d,w){e._canimAnimatorSlotSetTurn(c,f,d,w?1:0)},animatorSlotSetWindow(c,f,d,w){e._canimAnimatorSlotSetWindow(c,f,d,w)},animatorPlay(c,f,d,w,S,N,U){e._canimAnimatorPlay(c,f,d?1:0,w,S,N,U?1:0)},animatorStop(c,f,d,w){e._canimAnimatorStop(c,f,d,w)},animatorSeek(c,f,d){e._canimAnimatorSeek(c,f,d)},animatorGetSlotTime(c,f){return e._canimAnimatorSlotTime(c,f)},animatorGetSlotWeight(c,f){return e._canimAnimatorSlotWeight(c,f)},animatorSetLayer(c,f,d,w,S){it(e,S??"",N=>e._canimAnimatorSetLayer(c,f,d,w?1:0,N))},animatorSetLayerAnticipation(c,f,d){e._canimAnimatorSetLayerAnticipation(c,f,d)},animatorSetGlobal(c,f,d){e._canimAnimatorSetGlobal(c,f,d?1:0)},animatorJointRanges(c,f,d){for(const[w,S]of r){if(!S.entities.includes(c))continue;const N=f.length>>1,U=new Int32Array(N*2);for(let Y=0;Y<N*2;Y++)U[Y]=S.entities.indexOf(f[Y]);const L=new Float32Array(N*6),$=e._malloc(Math.max(4,N*8));e.HEAP32.set(U,$>>2);const j=e._malloc(Math.max(4,N*24));let oe=0;try{oe=ct(e,d,Y=>e._canimAnimatorJointRanges(w,$,N,Y,j)),oe>0&&L.set(e.HEAPF32.subarray(j>>2,(j>>2)+N*6))}finally{e._free($),e._free(j)}return oe>0?L:null}return null},animatorSeedPose(c,f){for(const[d,w]of r){if(!w.entities.includes(c))continue;const S=new Float32Array(w.n*10);for(let N=0;N<w.n;N++){const U=t.get(w.entities[N]),{t:L,r:$,s:j}=_r(U?U.m:cr);S.set([L[0],L[1],L[2],$[0],$[1],$[2],$[3],j[0],j[1],j[2]],N*10)}ct(e,S,N=>e._canimAnimatorSeedPose(d,N,f));return}},animatorSetRootMotion(c,f,d){it(e,f??"",w=>e._canimAnimatorSetRootMotion(c,w,(d|0)&255))},animatorGetRootMotion(c,f){e._canimAnimatorRootMotion(c,i);const d=e.HEAPF32,w=i>>2;f[0]=d[w],f[1]=d[w+1],f[2]=d[w+2]},setOnAnimatorEvent(c){n=c},animatorSetFeet(c,f,d){it(e,f,w=>it(e,d,S=>e._canimAnimatorSetFeet(c,w,S)))},animatorSlotCurveAt(c,f,d,w){return e._canimAnimatorSlotCurveAt(c,f,d,w)},animatorSlotCurveInfo(c,f,d){const w=e._canimAnimatorSlotCurveInfo(c,f,s);return w&&d.set(e.HEAPF32.subarray(s>>2,(s>>2)+Math.min(4,d.length))),w!==0},animatorSlotTurn(c,f){return e._canimAnimatorSlotTurn(c,f)},animatorSlotTimeAtTurn(c,f,d){return e._canimAnimatorSlotTimeAtTurn(c,f,d)},animatorLayerPhase(c,f){return e._canimAnimatorLayerPhase(c,f)},animatorSeekPhase(c,f,d){e._canimAnimatorSeekPhase(c,f,d)},animatorSlotContacts(c,f,d){const w=Math.floor(d.length/8);if(w===0)return e._canimAnimatorSlotContacts(c,f,0,0);const S=e._malloc(w*8*4),N=e._canimAnimatorSlotContacts(c,f,S,w);return d.set(e.HEAPF32.subarray(S>>2,(S>>2)+Math.min(N,w)*8)),e._free(S),N},animatorSlotTreads(c,f,d){if(d.length===0)return e._canimAnimatorSlotTreads(c,f,0,0);const w=e._malloc(d.length*4),S=e._canimAnimatorSlotTreads(c,f,w,d.length);return d.set(e.HEAPF32.subarray(w>>2,(w>>2)+Math.min(S+1,d.length))),e._free(w),S},animatorSlotPhysics(c,f,d,w){const S=e._malloc(44),N=e._canimAnimatorSlotPhysics(c,f,d,S);return N&&w.set(e.HEAPF32.subarray(S>>2,(S>>2)+Math.min(11,w.length))),e._free(S),N},animatorSlotFeatures(c,f,d,w){const S=e._malloc(148),N=e._canimAnimatorSlotFeatures(c,f,d,S);return N&&w.set(e.HEAPF32.subarray(S>>2,(S>>2)+Math.min(37,w.length))),e._free(S),N},animatorKneeAxis(c,f,d){const w=e._canimAnimatorKneeAxis(c,f,u);return w&&d.set(e.HEAPF32.subarray(u>>2,(u>>2)+Math.min(8,d.length))),w},animatorSlotKneePole(c,f,d,w,S){const N=e._canimAnimatorSlotKneePole(c,f,d,w,u);return N&&S.set(e.HEAPF32.subarray(u>>2,(u>>2)+Math.min(6,S.length))),N},animatorSetStepWarp(c,f,d,w,S,N){e._canimAnimatorSetStepWarp(c,f?1:0,d,w,S,N)},animatorSlotFit(c,f,d,w,S){if(S.length===0)return e._canimAnimatorSlotFit(c,f,d,w,0,0);const N=e._malloc(S.length*4),U=e._canimAnimatorSlotFit(c,f,d,w,N,S.length);return S.set(e.HEAPF32.subarray(N>>2,(N>>2)+Math.min(U,S.length))),e._free(N),U},animatorSlotExit(c,f,d,w,S,N){return e._canimAnimatorSlotExit(c,f,d,w,S?1:0,N)},animatorSlotAlign(c,f,d,w,S,N){if(N.length<4)return 0;const U=e._malloc(16),L=e._canimAnimatorSlotAlign(c,f,d,w,S,U);return L&&N.set(e.HEAPF32.subarray(U>>2,(U>>2)+4)),e._free(U),L},setOnAnimatorStep(c){m=c},animatorSetFeetParams(c,f){ct(e,f,w=>e._canimAnimatorSetFeetParams(c,w,f.length));const d=r.get(c);d&&(d.feetOn=f.length>0&&f[0]>.5||f.length>1&&f[1]>.5)},animatorFootState(c,f,d){const w=e._canimAnimatorFootState(c,f,u);return w&&d.set(e.HEAPF32.subarray(u>>2,(u>>2)+Math.min(8,d.length))),w!==0},animatorIkCreate(c,f,d){var oe,Y;const w=r.get(c);if(!w||!Yr(e))return 0;const S=w.entities.indexOf(d);if(S<0)return 0;let N=-1,U=-1;if(f===0){const O=((oe=t.get(d))==null?void 0:oe.parent)??0;if(N=w.entities.indexOf(O),N<0||(U=w.entities.indexOf(((Y=t.get(O))==null?void 0:Y.parent)??0),U<0))return 0}const L=e._canimAnimatorIkCreateJoints(c,f,U,N,S);if(!L)return 0;const $=new Float32Array(Zt),j=e._malloc(Zt*4);return e._canimAnimatorIkGet(c,L,j,Zt),$.set(e.HEAPF32.subarray(j>>2,(j>>2)+Zt)),e._free(j),w.iks.push({ik:L,target:0,pole:0,rotation:0,params:$}),L},animatorIkDestroy(c,f){e._canimAnimatorIkDestroy(c,f);const d=r.get(c);d&&(d.iks=d.iks.filter(w=>w.ik!==f))},animatorIkSet(c,f,d){var S;ct(e,d,N=>e._canimAnimatorIkSet(c,f,N,d.length));const w=(S=r.get(c))==null?void 0:S.iks.find(N=>N.ik===f);w&&w.params.set(d.subarray(0,Math.min(d.length,Zt)))},animatorIkNodes(c,f,d,w,S){var U;const N=(U=r.get(c))==null?void 0:U.iks.find(L=>L.ik===f);N&&(N.target=d,N.pole=w,N.rotation=S)},animatorIkAnchor(c,f,d){it(e,d??"",w=>e._canimAnimatorIkAnchor(c,f,w))},animatorIkState(c,f,d){const w=e._canimAnimatorIkState(c,f,s);return w&&d.set(e.HEAPF32.subarray(s>>2,(s>>2)+Math.min(4,d.length))),w!==0},animatorSetSocket(c,f,d,w,S,N){const U=r.get(c);if(!U||!Yr(e))return;U.sockets=U.sockets.filter(j=>!(j.set===f&&j.name===d));const L=(j,oe)=>{it(e,f,Y=>it(e,d,O=>{oe?ct(e,oe,k=>e._canimAnimatorSetSocket(c,Y,O,j,k)):e._canimAnimatorSetSocket(c,Y,O,j,0)}))};if(S===0&&!N){L(-1,null);return}const $=U.entities.indexOf(w);if($<0){console.warn(`[Animator] socket '${d}': the joint is no bone of this animator`);return}L($,N??[0,0,0,0,0,0,1]),S!==0&&U.sockets.push({set:f,name:d,node:S})},setClipAnchors(c,f,d,w,S,N){Yr(e)&&it(e,d,U=>it(e,w??"",L=>it(e,S??"",$=>ct(e,N,j=>e._canimClipsSetAnchors(c,f,U,L,$,j,Math.floor(N.length/4))))))},animatorSetMotion(c,f,d,w){e._canimAnimatorSetMotion(c,f,d,w)},animatorSetDriveInput(c,f,d){e._canimAnimatorSetDriveInput(c,f,d)},animatorSetSlotDrive(c,f,d,w){e._canimAnimatorSetSlotDrive(c,f,d,w)},animatorSetWarpParams(c,f){ct(e,f,d=>e._canimAnimatorSetWarpParams(c,d,f.length))}},R=(c,f,d)=>{var Y,O;const w=t.get(f.rootId),S=w&&w.parent?t.get(w.parent):void 0,N=S?((Y=t.world)==null?void 0:Y.call(t,S.id))??S.m:cr;e.HEAPF32.set(N,l>>2),e._canimAnimatorSetWorld(c,l);const U=e._canimAnimatorEvaluate(c,d,0,f.trs,f.write);if(f.feetOn&&w){const k=(((O=t.world)==null?void 0:O.call(t,f.rootId))??w.m)[13];for(let V=0;V<2;V++){if(!e._canimAnimatorFootProbe(c,V,o,a))continue;const X=e.HEAPF32,le=o>>2;e._canimAnimatorSetGround(c,V,1,X[le],k,X[le+2],0,1,0)}}const L=e.HEAPF32,$=e.HEAPU8,j=f.trs>>2;for(let k=0;k<f.n;k++){if(!$[f.write+k])continue;const V=t.get(f.entities[k]);if(!V)continue;const X=j+k*10;Xr(V.m,L[X],L[X+1],L[X+2],L[X+3],L[X+4],L[X+5],L[X+6],L[X+7],L[X+8],L[X+9]),t.localMatrixChanged(f.entities[k])}if(t.setMorphWeights){const k=e._canimAnimatorMorphCount(c);for(let V=0;V<k;V++){const X=e._canimAnimatorMorph(c,V,g,p),le=e.HEAP32[g>>2],ee=e.HEAPU32[p>>2];!X||le<0||ee===0||t.setMorphWeights(f.entities[le],Float32Array.from(e.HEAPF32.subarray(X>>2,(X>>2)+ee)))}}const oe=e._canimAnimatorRootMotionFrame(c,s);if(oe!==0){const k=e.HEAPF32,V=s>>2,X=k[V],le=k[V+1],ee=k[V+2],te=k[V+3];let fe=!1;if(oe===2&&t.applyRootMotion&&(fe=t.applyRootMotion(f.rootId,X,le,ee,d,te)),!fe&&(X!==0||le!==0||ee!==0||te!==0)){const ye=t.get(f.rootId);if(ye){const de=ye.m;te!==0&&Xl(de,te);const De=de[0]*X+de[4]*le+de[8]*ee,qe=de[1]*X+de[5]*le+de[9]*ee,_=de[2]*X+de[6]*le+de[10]*ee;de[12]+=De,de[13]+=qe,de[14]+=_,t.localMatrixChanged(f.rootId)}}}if(m){const k=e._canimAnimatorStepCount(c);for(let V=0;V<k;V++){const X=e._canimAnimatorStep(c,V,i);if(X<0)continue;const le=e.HEAPF32,ee=i>>2,te=le[ee],fe=le[ee+1],ye=le[ee+2],de=N;M.push({id:c,side:X,x:de[0]*te+de[4]*fe+de[8]*ye+de[12],y:de[1]*te+de[5]*fe+de[9]*ye+de[13],z:de[2]*te+de[6]*fe+de[10]*ye+de[14]})}}if(U>0){const k=e._canimAnimatorEvents(c,h,vs),V=e.HEAPU16,X=h>>1;for(let le=0;le<k;le++)v.push({id:c,slot:V[X+le*2],type:V[X+le*2+1]})}},C=c=>{var f,d;return((f=t.world)==null?void 0:f.call(t,c))??((d=t.get(c))==null?void 0:d.m)},P=(c,f)=>{if(f.iks.length===0)return;const d=t.get(f.rootId);if(!d)return;const w=d.parent?C(d.parent)??cr:cr;for(const L of f.iks){if(!L.target&&!L.pole&&!L.rotation)continue;const $=L.target?C(L.target):void 0;$&&(L.params[mt.TARGET_X]=$[12],L.params[mt.TARGET_X+1]=$[13],L.params[mt.TARGET_X+2]=$[14]);const j=L.pole?C(L.pole):void 0;j&&(L.params[mt.POLE_X]=j[12],L.params[mt.POLE_X+1]=j[13],L.params[mt.POLE_X+2]=j[14],L.params[mt.HAS_POLE]=1);const oe=L.rotation?C(L.rotation):void 0;if(oe){const Y=_r(oe).r;L.params[mt.ROT_X]=Y[0],L.params[mt.ROT_X+1]=Y[1],L.params[mt.ROT_X+2]=Y[2],L.params[mt.ROT_X+3]=Y[3]}ct(e,L.params,Y=>e._canimAnimatorIkSet(c,L.ik,Y,Zt))}for(const L of f.sockets){const $=C(L.node);$&&(e.HEAPF32.set($,l>>2),it(e,L.set,j=>it(e,L.name,oe=>e._canimAnimatorSocketSetWorld(c,j,oe,l))))}const S=e.HEAPF32,N=f.trs>>2;for(let L=0;L<f.n;L++){const $=t.get(f.entities[L]),{t:j,r:oe,s:Y}=_r($?$.m:cr),O=N+L*10;S[O]=j[0],S[O+1]=j[1],S[O+2]=j[2],S[O+3]=oe[0],S[O+4]=oe[1],S[O+5]=oe[2],S[O+6]=oe[3],S[O+7]=Y[0],S[O+8]=Y[1],S[O+9]=Y[2]}if(e.HEAPF32.set(w,l>>2),e._canimAnimatorLateSolve(c,l,f.trs,f.write)===0)return;const U=e.HEAPU8;for(let L=0;L<f.n;L++){if(!U[f.write+L])continue;const $=t.get(f.entities[L]);if(!$)continue;const j=N+L*10;Xr($.m,S[j],S[j+1],S[j+2],S[j+3],S[j+4],S[j+5],S[j+6],S[j+7],S[j+8],S[j+9]),t.localMatrixChanged(f.entities[L])}};return{methods:F,registerGlbClips(c){return y(c)},lateSolve(){for(const[c,f]of r)P(c,f)},evaluate(c){for(const[f,d]of r)R(f,d,c);if(M.length>0){const f=M.splice(0,M.length);if(m)for(const d of f)m(d.id,d.side,d.x,d.y,d.z)}if(v.length>0&&n){const f=v.splice(0,v.length);for(const d of f)n(d.id,d.slot,d.type)}else v.length=0},onEntityDestroyed(c){e._canimAnimatorsDestroyTagged(c);for(const[f,d]of r)d.rootId===c&&(x(d),r.delete(f))}}}const Kl=["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"],Ql=t=>{let e=null;const r=()=>{if(!e){if(!ks())throw new Error("creator-anim is not loaded: await loadCreatorAnim() (viewer-lite/src/gl/core/animBridge) before the first animation call");e=Yl(t)}return e},n={};for(const s of Kl)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)}}},Zl=["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"],Kr=1/60,xs=["static","kinematic","dynamic"],nn=34,Jl=15,ec=32,ws=33,Ms=(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(nn,nn+e*2))}:{}}),tc=t=>{let e=null;const r=()=>{if(!e){if(!ns())throw new Error("creator-physics is not loaded: await loadCreatorPhysics() (viewer-lite/src/gl/core/physicsBridge) before the first physics call");e=il(t)}return e},n={};for(const m of Zl)n[m]=(...y)=>r().methods[m](...y);const s=new Map,i=new Map,l=new Map,o=new Map,a=new Map;let u;const g=(m,y)=>(m&&s.set(m,y),m),p=(m,y)=>{const x=m.get(y);return x===void 0?void 0:t.ent(x).physics},h=(m,y,x,F,R)=>(m&&(i.set(m,y),t.ent(y).physics={motion:xs[x]??x,mass:F,shape:R}),m),v={...n,physicsHasSupport:()=>ns(),physicsConfigure(m,y,x,F){u={gravity:[m,y,x],maxBodies:F},n.physicsConfigure(m,y,x,F)},physicsBuildBox:(m,y,x)=>g(n.physicsBuildBox(m,y,x),{type:"box",size:[m*2,y*2,x*2]}),physicsBuildSphere:m=>g(n.physicsBuildSphere(m),{type:"sphere",radius:m}),physicsBuildCylinder:(m,y)=>g(n.physicsBuildCylinder(m,y),{type:"cylinder",height:m*2,radius:y}),physicsBuildCapsule:(m,y)=>g(n.physicsBuildCapsule(m,y),{type:"capsule",height:m*2,radius:y}),physicsBuildMesh:(m,y,x,F,R,C)=>g(n.physicsBuildMesh(m,y,x,F,R,C),{type:x?"convexHull":"mesh",vertices:m.length/3,triangles:Math.floor(y.length/3),scale:[F,R,C]}),physicsBuildMeshFromEntity:(m,y,x,F,R)=>g(n.physicsBuildMeshFromEntity(m,y,x,F,R),{type:y?"convexHull":"mesh",source:m,scale:[x,F,R]}),physicsBuildHeightField(m,y,x,F,R,C,P,c){let f=0;if(R)for(let d=0;d<R.length;d++)R[d]&&f++;return g(n.physicsBuildHeightField(m,y,x,F,R,C,P,c),{type:"heightfield",size:[y,x],cellSize:F,samples:m.length,holes:f,scale:[C,P,c]})},physicsSetShapeOrigin(m,y,x,F){const R=s.get(m);R&&(y===0&&x===0&&F===0?delete R.origin:R.origin=[y,x,F]),n.physicsSetShapeOrigin(m,y,x,F)},physicsSetBodyShape(m,y,x){const F=p(i,m);F&&(F.shape=s.get(y)),n.physicsSetBodyShape(m,y,x)},physicsDestroyShape(m){s.delete(m),n.physicsDestroyShape(m)},physicsCreateBody(m,y,x,F,R,C){const P=n.physicsCreateBody(m,y,x,F,R,C);return P&&(i.set(P,m),t.ent(m).physics={motion:xs[x]??x,mass:F,...R&&{sensor:R},...C&&{pickOnly:C},shape:s.get(y)}),P},physicsSetFriction(m,y){const x=p(i,m);x&&(x.friction=y),n.physicsSetFriction(m,y)},physicsRemoveBody(m){i.delete(m),n.physicsRemoveBody(m)},physicsCreateBox:(m,y,x,F,R,C)=>h(n.physicsCreateBox(m,y,x,F,R,C),m,R,C,{type:"box",size:[y*2,x*2,F*2]}),physicsCreateSphere:(m,y,x,F)=>h(n.physicsCreateSphere(m,y,x,F),m,x,F,{type:"sphere",radius:y}),physicsCreateCylinder:(m,y,x,F,R)=>h(n.physicsCreateCylinder(m,y,x,F,R),m,F,R,{type:"cylinder",height:y*2,radius:x}),characterCreate(m,y,x){const F=n.characterCreate(m,y,x);return F&&(l.set(F,m),t.ent(m).physics={character:!0,maxSlopeDeg:x,shape:s.get(y)}),F},characterDestroy(m){l.delete(m),n.characterDestroy(m)},characterSetMaxSlope(m,y){const x=p(l,m);x&&(x.maxSlopeDeg=y),n.characterSetMaxSlope(m,y)},characterSetShape(m,y){const x=n.characterSetShape(m,y);if(x){const F=p(l,m);F&&(F.shape=s.get(y))}return x},vehicleCreate(m,y,x){const F=n.vehicleCreate(m,y,x);if(!F)return 0;const R=x[ec]??0,C=x[ws]??0;let P=nn+C*2;const c=[];for(let f=0;f<R;f++){const d=x[P+13]??0,w=x[P+14]??0;c.push({position:[x[P],x[P+1],x[P+2]],radius:x[P+3],width:x[P+4],...x[P+5]?{steerDeg:x[P+5]}:{},...x[P+6]?{driven:x[P+6]}:{},axle:x[P+7],suspension:{travel:x[P+8],stiffness:x[P+9],damping:x[P+10]},tire:{traction:x[P+11],circle:x[P+12],side:d,forward:w}}),P+=Jl+(d+w)*2}return o.set(F,m),t.ent(m).physics={motion:"dynamic",mass:x[1],vehicle:!0,...Ms(x,C),wheels:c,shape:s.get(y)},F},vehicleDestroy(m){o.delete(m),n.vehicleDestroy(m)},vehicleSetTuning(m,y){const x=p(o,m);x&&Object.assign(x,Ms(y,y[ws]??0)),n.vehicleSetTuning(m,y)},vehicleSetInput(m,y){const x=p(o,m);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(m,y)},ragdollCreate(m,y,x){const F=n.ragdollCreate(m,y,x);if(!F)return 0;const R=16,C=x[1]??0,P=x[2]??12,c=[];for(let f=0;f<C;f++){const d=R+f*P;c.push({bone:y[f*2],...y[f*2+1]?{to:y[f*2+1]}:{},parent:x[d],radius:x[d+1],...x[d+2]?{length:x[d+2]}:{},mass:x[d+3],...x[d+6]?{hinge:{axis:[x[d+7],x[d+8],x[d+9]],min:x[d+10],max:x[d+11]}}:{swing:x[d+4],twist:x[d+5]}})}return a.set(F,m),t.ent(m).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:c},F},ragdollDestroy(m){a.delete(m),n.ragdollDestroy(m)},ragdollActivate(m,y,x,F){const R=n.ragdollActivate(m,y,x,F),C=a.get(m),P=C===void 0?void 0:t.ent(C).ragdoll;return R&&P&&(P.active=!0,P.launch=[y,x,F]),R},ragdollDeactivate(m,y){const x=a.get(m),F=x===void 0?void 0:t.ent(x).ragdoll;F&&(F.active=!1,delete F.launch,y>0&&(F.blendOut=y)),n.ragdollDeactivate(m,y)},ragdollSetDrive(m,y,x){const F=a.get(m),R=F===void 0?void 0:t.ent(F).ragdoll;R&&(R.strength=y,R.anchored=x),n.ragdollSetDrive(m,y,x)}};let M=0;return{methods:v,loaded:()=>e!==null,frame(m,y){if(e){e.frame(m,y);return}if(!y){M=0;return}M+=m;let x=0;for(;M>=Kr&&x<4;)y(Kr),M-=Kr,x++;x===4&&(M=0)},syncRagdolls(m){e&&e.syncRagdolls(m)},applyRootMotion:(m,y,x,F,R)=>e?e.applyRootMotion(m,y,x,F,R):!1,config:()=>u}},Et={POINTS:0,QUADS:1,MESH:3};let rc=null,an=null;const nc=()=>rc??(rc=mr(()=>import("./creatorParticles-DYlv4g1J.js"),__vite__mapDeps([4,1]),import.meta.url).then(t=>t.default()).then(t=>an=t)),sc=()=>an!==null,ic=(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 oc(t){const e=an;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(o,a,u){e._cpartCreate(o,u|0)&&s.set(o,a)},spawnParticles(o,a){e._cpartSpawn(o,a)},setParticleSystemConfig(o,a){ic(e,a,u=>e._cpartSetConfig(o,u,a.length))},createNoise:()=>e._cpartNoiseCreate(),setNoiseFrequency(o,a){e._cpartNoiseSetFrequency(o,a)},setNoiseOctaves(o,a){e._cpartNoiseSetOctaves(o,a|0)},setNoiseFractalLunacrity(o,a){e._cpartNoiseSetLacunarity(o,a)},setNoiseFractalGain(o,a){e._cpartNoiseSetGain(o,a)},getNoise2D:(o,a,u)=>e._cpartNoise2D(o,a,u),getNoise3D:(o,a,u,g)=>e._cpartNoise3D(o,a,u,g)},l=o=>{const a=e._cpartVertexCount(o),u=e._cpartVertexStride(o),g=e._cpartVertexData(o);return{mode:e._cpartMode(o),stride:u,vertexCount:a,indexCount:e._cpartIndexCount(o),bytes:a>0&&g?e.HEAPU8.subarray(g,g+a*u):new Uint8Array(0),geometryVersion:e._cpartGeometryVersion(o),capacity:e._cpartCapacity(o),meshVertexCount:e._cpartMeshVertexCount(o),order:e._cpartOrder(o),alive:e._cpartAlive(o)}};return{methods:i,materialOf:o=>s.get(o),systems:()=>s.keys(),update(o,a){const u=t.cameraPosition();let g=0;u&&(e.HEAPF32.set([u[0],u[1],u[2]],n>>2),g=n);for(const p of s.keys())e.HEAPF32.set(t.world(p),r>>2),e._cpartUpdate(p,o,r,g),a(p,l(p))},setVisible(o,a){e._cpartSetVisible(o,a?1:0)},alive:o=>e._cpartAlive(o),indexPattern(o){const a=e._cpartIndexPatternCount(o);if(a===0)return new Uint32Array(0);const u=e._malloc(a*4);e._cpartWriteIndexPattern(o,u);const g=Uint32Array.from(e.HEAPU32.subarray(u>>2,(u>>2)+a));return e._free(u),g},destroy(o){e._cpartDestroy(o),s.delete(o)},dispose(){e._cpartReset(),s.clear(),e._free(r),e._free(n)}}}const Qr={createNoise:()=>0,setNoiseFrequency(){},setNoiseOctaves(){},setNoiseFractalLunacrity(){},setNoiseFractalGain(){},getNoise2D:()=>0,getNoise3D:()=>0},ac=t=>{let e=null;const r=()=>(!e&&sc()&&(e=oc(t)),e);let n=1;const s=(o,a,u)=>{const g=t.ent(o);g.particles||(g.particles={}),u===void 0?delete g.particles[a]:g.particles[a]=u},i={createParticleSystem(o,a,u){var p;t.ent(o).particles={material:a,...u?{maxParticles:u}:{}};const g=r();g&&(g.methods.createParticleSystem(o,a,u),(p=t.created)==null||p.call(t,o,a))},spawnParticles(o,a){var g;const u=t.ent(o).particles;u&&(u.spawned=(u.spawned??0)+a),(g=r())==null||g.methods.spawnParticles(o,a)},setParticleSystemConfig(o,a){var p;const u=(h,v)=>h===v?h:{min:h,max:v},g=h=>[a[h],a[h+1],a[h+2],a[h+3]];for(let h=0;h+2<=a.length;h+=2+a[h+1]){const v=h+2;switch(a[h]){case 1:{const M=a[v];M===0?s(o,"shape",{type:"point",at:[a[v+1],a[v+2],a[v+3]]}):M===1?s(o,"shape",{type:"box",min:[a[v+1],a[v+2],a[v+3]],max:[a[v+4],a[v+5],a[v+6]]}):s(o,"shape",{type:"circle",center:[a[v+1],a[v+2],a[v+3]],radius:a[v+4]});break}case 2:s(o,"lifetime",u(a[v],a[v+1]));break;case 3:s(o,"rate",a[v]);break;case 4:s(o,"velocity",{kind:a[v],value:[a[v+1],a[v+2],a[v+3]]}),s(o,"speed",u(a[v+4],a[v+5]));break;case 5:s(o,"spreadAngle",a[v]?{min:[a[v+1],a[v+2]],max:[a[v+3],a[v+4]]}:void 0);break;case 6:s(o,"acceleration",[a[v],a[v+1],a[v+2]]);break;case 7:s(o,"drag",a[v]);break;case 8:s(o,"noise",a[v]!==0?{strength:a[v],frequency:a[v+1],speed:a[v+2]}:void 0);break;case 9:s(o,"seed",a[v]);break;case 10:{const M=u(a[v+2],a[v+3]);s(o,`param${a[v]}`,a[v+4]>0?{base:M,curve:a[v+4]}:M);break}case 11:{const M=g(v),m=g(v+4),y=M.every((x,F)=>x===m[F])?M:{min:M,max:m};s(o,"color",a[v+8]>0?{base:y,curve:a[v+8]}:y);break}case 12:s(o,"space",a[v]?"world":"local");break;case 15:s(o,"render",["point","quad","ribbon","mesh"][a[v]]??a[v]);break}}(p=r())==null||p.methods.setParticleSystemConfig(o,a)},...Qr},l=Object.fromEntries(Object.keys(Qr).map(o=>[o,(...a)=>{const u=r();return u?u.methods[o](...a):o==="createNoise"?n++:Qr[o](...a)}]));return Object.assign(i,l),{methods:i,loaded:()=>e!==null,update(o){e&&e.update(o,(a,u)=>{var p;const g=t.ent(a).particles;g&&(g.alive=u.alive),(p=t.frame)==null||p.call(t,a,u)})},setVisible(o,a){e==null||e.setVisible(o,a)},indexPattern:o=>(e==null?void 0:e.indexPattern(o))??new Uint32Array(0),onEntityDestroyed(o){var a;e&&e.materialOf(o)!==void 0&&(e.destroy(o),(a=t.destroyed)==null||a.call(t,o))}}},Ws=t=>{const e=Math.max(t.lastIndexOf(":"),t.lastIndexOf("|"));return e<0?t:t.slice(e+1)},lc=(t,e,r,n)=>t?t===r?e?0:1:Ws(t)===n?e?2:3:-1:-1,Ft=(t,e,r=16)=>{for(let n=0;n<r;n++)t[n]=e[n]};function cc(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,o=new Map,a=new Map,u=new Map;let g=1,p=1,h=1,v=-1,M=null,m=null,y=null;const x=tc({ent:_=>c(_),get:_=>l.get(_),world:_=>d(_),setWorldTRS:(_,T,B,q,ce,re,_e,Ae,Le,Ue,Xe)=>N(_,Is([T,B,q],[ce,re,_e,Ae],[Le,Ue,Xe])),setWorldPosition:(_,T,B,q)=>U(_,T,B,q),localMatrixChanged:_=>{var T;return(T=t.localMatrixChanged)==null?void 0:T.call(t,_)},parentOf:_=>{var T;return((T=l.get(_))==null?void 0:T.parent)??0},glbBytes:_=>{var T,B;return(B=(T=l.get(_))==null?void 0:T.model)==null?void 0:B.buffer},seedAnimator:(_,T)=>R.methods.animatorSeedPose(_,T),jointRanges:(_,T,B)=>R.methods.animatorJointRanges(_,T,B)}),F=ac({ent:_=>c(_),world:_=>d(_),cameraPosition:()=>{var B;const _=(B=o.get(v))==null?void 0:B.camera;if(_===void 0)return null;const T=f(_);return[T[12],T[13],T[14]]},created:(_,T)=>{var B;return(B=t.particleSystemCreated)==null?void 0:B.call(t,_,T)},frame:(_,T)=>{var B;return(B=t.particlesFrame)==null?void 0:B.call(t,_,T)},destroyed:_=>{var T;return(T=t.particleSystemDestroyed)==null?void 0:T.call(t,_)}}),R=Ql({get:_=>l.get(_),world:_=>d(_),localMatrixChanged:_=>{var T;return(T=t.localMatrixChanged)==null?void 0:T.call(t,_)},getBuffer:_=>e.getBuffer(_),setMorphWeights:(_,T)=>{var B;return(B=t.morphWeights)==null?void 0:B.call(t,_,T)},applyRootMotion:(_,T,B,q,ce,re)=>{const _e=d(_);return x.applyRootMotion(_,_e[0]*T+_e[4]*B+_e[8]*q,_e[2]*T+_e[6]*B+_e[10]*q,ce,re)}}),C=_=>{const T={id:_,name:"",m:t.allocMatrix(_),parent:0,children:[],visible:!0,materials:[]};return(T.m[0]!==1||T.m[5]!==1||T.m[10]!==1||T.m[15]!==1)&&Ft(T.m,He()),l.set(_,T),T},P=()=>C(g++),c=_=>{let T=l.get(_);return T||(T=C(_),_>=g&&(g=_+1)),T},f=_=>{const T=c(_);return T.parent===0?T.m:ut(new Float32Array(16),f(T.parent),T.m)},d=_=>{const T=f(_);return T instanceof Float32Array?T:Float32Array.from(T)},w=_=>{if(_.parent!==0){const T=l.get(_.parent);T&&(T.children=T.children.filter(B=>B!==_.id)),_.parent=0}},S=(_,T,B)=>{var ce,re;const q=c(_);if(q.parent!==T){if(B){const _e=d(_),Ae=T===0?_e:ut(new Float32Array(16),wt(d(T)),_e);Ft(q.m,Ae)}w(q),T!==0&&(q.parent=T,c(T).children.push(_)),(ce=t.parentChanged)==null||ce.call(t,_,T),(re=t.localMatrixChanged)==null||re.call(t,_)}},N=(_,T)=>{var q;const B=c(_);Ft(B.m,B.parent===0?T:ut(new Float32Array(16),wt(d(B.parent)),T)),(q=t.localMatrixChanged)==null||q.call(t,_)},U=(_,T,B,q)=>{var _e;const ce=c(_),re=ce.m;if(ce.parent===0)re[12]=T,re[13]=B,re[14]=q;else{const Ae=wt(d(ce.parent));re[12]=Ae[0]*T+Ae[4]*B+Ae[8]*q+Ae[12],re[13]=Ae[1]*T+Ae[5]*B+Ae[9]*q+Ae[13],re[14]=Ae[2]*T+Ae[6]*B+Ae[10]*q+Ae[14]}(_e=t.localMatrixChanged)==null||_e.call(t,_)},L=_=>{const T=o.get(_),B=(T==null?void 0:T.overlayOf)!==void 0?o.get(T.overlayOf):T;return(B==null?void 0:B.projection)??i},$=_=>{for(let T=_;T!==0;){for(const B of o.values())if(B.entities.has(T))return B;T=c(T).parent}return null},j=_=>{var ce;const T=(ce=e.getSourceName)==null?void 0:ce.call(e,_);if(!T)return;const B=T.startsWith("lecodesfile://")?decodeURIComponent(T.slice(14)):T;return(B.includes("/")||B.includes("\\"))&&!B.startsWith("http")?B.split(/[\\/]/).pop()??B:B},oe=_=>{let T=a.get(_);return T||(T={shader:"unknown",uniforms:{}},a.set(_,T)),T},Y=(_,T,B)=>{var q;oe(_).uniforms[T]=B,(q=t.uniformChanged)==null||q.call(t,_,T,B)},O=_=>{const T=e.getBuffer(_),B=T?kl(T):null,q=P();if(q.model={source:j(_),systemId:_,animations:(B==null?void 0:B.animations)??[],loaded:B!==null,...T&&{buffer:T}},B&&B.animations.length>0&&T&&ks()&&(q.model.clipSet=R.registerGlbClips(T)),!B)return{rootId:q.id,entIds:[]};const ce=B.nodes.map(()=>P().id);B.nodes.forEach((re,_e)=>{var Le;const Ae=c(ce[_e]);Ae.name=re.name??"",Ft(Ae.m,re.matrix),(Le=t.localMatrixChanged)==null||Le.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 Ue of re.children)S(ce[Ue],Ae.id,!1)});for(const re of B.roots)S(ce[re],q.id,!1);return{rootId:q.id,entIds:ce}},k=(_,T)=>{var ce,re;const B=c(_),q=P();T.set(B.id,q.id),q.name=B.name,Ft(q.m,B.m),q.visible=B.visible,B.skinJoint&&(q.skinJoint=!0),B.light&&(q.light={...B.light}),B.mesh&&(q.mesh={...B.mesh}),q.materials=[...B.materials],B.model&&(q.model={...B.model,animations:B.model.animations}),B.castShadows!==void 0&&(q.castShadows=B.castShadows),B.receiveShadows!==void 0&&(q.receiveShadows=B.receiveShadows),B.particles&&(q.particles=structuredClone(B.particles)),B.physics&&(q.physics=structuredClone(B.physics)),B.collider&&(q.collider=structuredClone(B.collider)),B.anchor&&(q.anchor=B.anchor),(ce=t.localMatrixChanged)==null||ce.call(t,q.id),(re=t.entityCloned)==null||re.call(t,B.id,q.id);for(const _e of B.children)S(k(_e,T),q.id,!1);return q.id},V=_=>{var B;const T=l.get(_);if(T){for(const q of[...T.children])V(q);w(T);for(const q of o.values())q.entities.delete(_);(B=t.entityDestroyed)==null||B.call(t,_),R.onEntityDestroyed(_),F.onEntityDestroyed(_),l.delete(_)}},X=_=>{for(let T=_;T!==0;T=c(T).parent)if(!c(T).visible)return!1;return!0};let le=1;const ee=_=>{const T=_*le;M==null||M(_),x.frame(T,y),R.evaluate(T),x.syncRagdolls(T),m==null||m(_),R.lateSolve(),F.update(T)},te=_=>{const T=Math.min(1e3,Math.floor(_/16));for(let B=0;B<T;B++)ee(.016)},fe=()=>v>=0||o.size>0,ye=()=>v,de={createScene(){var T;const _=o.size;return o.set(_,{id:_,entities:new Set,overlays:[]}),(T=t.sceneCreated)==null||T.call(t,_),_},createOverlayScene(_){var B,q;const T=o.size;return o.set(T,{id:T,entities:new Set,overlays:[],overlayOf:_}),(B=o.get(_))==null||B.overlays.push(T),(q=t.sceneCreated)==null||q.call(t,T),T},createGLView(){},openScene(_){v=_},closeScene(){v=-1},addEntityToScene(_,T){var q;const B=o.get(_);if(B){for(const ce of o.values())ce!==B&&ce.entities.delete(T);B.entities.add(T),(q=t.entitySceneChanged)==null||q.call(t,T,_,!0)}},removeEntityFromScene(_,T){var q;const B=o.get(_);B&&(B.entities.delete(T),(q=t.entitySceneChanged)==null||q.call(t,T,_,!1))},createEntity:()=>P().id,cloneEntity(_){var ce,re;const T=c(_),B=new Map,q=k(_,B);if(T.parent!==0)S(q,T.parent,!1);else{const _e=$(_);_e&&(_e.entities.add(q),(ce=t.entitySceneChanged)==null||ce.call(t,q,_e.id,!0))}return(re=t.subtreeCloned)==null||re.call(t,_,q,B),q},destroyEntity(_){V(_)},setMatrix(_,T){var q;const B=c(_);Ft(B.m,T),(q=t.localMatrixChanged)==null||q.call(t,_)},setWorldMatrix(_,T){var ce,re;const B=c(_);if(B.parent===0){Ft(B.m,T),(ce=t.localMatrixChanged)==null||ce.call(t,_);return}const q=ut(new Float32Array(16),wt(d(B.parent)),Float32Array.from(T.subarray(0,16)));Ft(B.m,q),(re=t.localMatrixChanged)==null||re.call(t,_)},getChildCount:_=>c(_).children.length,getChild:(_,T)=>c(_).children[T]??0,setPosition(_,T,B,q){var re;const ce=c(_).m;ce[12]=T,ce[13]=B,ce[14]=q,(re=t.localMatrixChanged)==null||re.call(t,_)},setQuaternion(_,T,B,q,ce){var re;Ls(c(_).m,T,B,q,ce),(re=t.localMatrixChanged)==null||re.call(t,_)},setEulerAngles(_,T,B,q,ce){var re;fa(c(_).m,T,B,q,ce),(re=t.localMatrixChanged)==null||re.call(t,_)},setScale(_,T,B,q){var ce;Os(c(_).m,T,B,q),(ce=t.localMatrixChanged)==null||ce.call(t,_)},setParent(_,T,B){S(_,T,B)},setParentNull(_,T){S(_,0,T)},getParent:_=>c(_).parent,traverse(_,T){const B=q=>{T(q);for(const ce of c(q).children)B(ce)};for(const q of c(_).children)B(q)},findNode(_,T){const B=Ws(T);let q=0,ce=4;const re=_e=>{const Ae=c(_e),Le=lc(Ae.name,!!Ae.skinJoint,T,B);Le<ce&&Le>=0&&(q=_e,ce=Le);for(const Ue of Ae.children){if(ce===0)return;re(Ue)}};for(const _e of c(_).children){if(ce===0)break;re(_e)}return q},createSunLight(_,T,B,q,ce,re,_e,Ae=100,Le=1){c(_).light={direction:[T,B,q],intensity:ce,color:re,shadowsQuality:_e,shadowDistance:Ae,shadowCascades:Le}},setDefaultIbl(_,T){const B=o.get(_);B&&(B.ibl=T)},setBloomOptions(_,T,B){const q=o.get(_);q&&(q.bloom=T?{strength:B}:void 0)},setSkybox(_,T){const B=o.get(_);B&&(B.skybox=T)},setSceneMultiSampleAntiAliasing(_,T){const B=o.get(_);B&&(B.antialias=T)},setSceneRenderOptions(){},setMaterialGlobalParameter(){},getCameraFov(_,T){const{fov:B}=L(_);if(T!==1)return B;const q=B*Math.PI/180;return 2*Math.atan(Math.tan(q/2)*(r/n))*180/Math.PI},setCameraProjection(_,T,B,q){const ce=o.get(_);ce&&(ce.projection={fov:T,near:B,far:q})},getMatrix(_,T){return T.set(De(_)),!0},getWorldMatrix(_,T){T.set(d(_))},getWorldPosition(_,T){const B=f(_);T[0]=B[12],T[1]=B[13],T[2]=B[14]},getWorldDirection(_,T,B){const q=f(_);B[0]=q[T*4],B[1]=q[T*4+1],B[2]=q[T*4+2]},getWorldMatrixInverse(_,T){T.set(wt(d(_)))},getCameraViewDirection(_,T,B,q){var at;const ce=(at=o.get(_))==null?void 0:at.camera,re=ce?f(ce):He(),_e=r/n,Ae=Math.tan(L(_).fov*Math.PI/360),Le=(T/r*2-1)*Ae*_e,Ue=(1-B/n*2)*Ae,Xe=re[0]*Le+re[4]*Ue-re[8],ze=re[1]*Le+re[5]*Ue-re[9],Ye=re[2]*Le+re[6]*Ue-re[10],Ze=Math.hypot(Xe,ze,Ye)||1;q[0]=Xe/Ze,q[1]=ze/Ze,q[2]=Ye/Ze},setMesh(_,T,B,q,ce,re,_e,Ae,Le){var _t;const Ue=c(_);let Xe=1/0,ze=1/0,Ye=1/0,Ze=-1/0,at=-1/0,pt=-1/0;for(let dt=0;dt+2<B.length;dt+=3){const ke=B[dt],Je=B[dt+1],Mt=B[dt+2];ke<Xe&&(Xe=ke),ke>Ze&&(Ze=ke),Je<ze&&(ze=Je),Je>at&&(at=Je),Mt<Ye&&(Ye=Mt),Mt>pt&&(pt=Mt)}const gt=B.length>=3,Nt={kind:_e,vertexCount:Math.floor(B.length/3),size:gt?[Ze-Xe,at-ze,pt-Ye]:void 0,center:gt?[(Ze+Xe)/2,(at+ze)/2,(pt+Ye)/2]:void 0};Ue.mesh=Nt,Ue.materials[0]=T,(_t=t.meshSet)==null||_t.call(t,_,T,Nt,{vertices:B,normals:q,indices:ce,uv:re,colors:Le})},setCulling(){},setRenderPriority(){},setMaterialDepthTest(){},setMaterialDepthWrite(){},setMaterialCulling(){},setMaterialStencil(){},setSceneStencil(){},setCastShadows(_,T){c(_).castShadows=T},setReceiveShadows(_,T){c(_).receiveShadows=T},setGlbShadows(_,T,B){const q=ce=>{const re=c(ce);re.castShadows=T,re.receiveShadows=B;for(const _e of re.children)q(_e)};q(_)},setCastShadowsGlobal(){},setReceiveShadowsGlobal(){},hasMesh:_=>c(_).mesh!==void 0,createMaterial(_){var q;const T=p++,B={shader:j(_)??"unknown",uniforms:{}};return a.set(T,B),(q=t.materialCreated)==null||q.call(t,T,B,_),T},createMaterialNamed(_){var q;const T=p++,B={shader:_,uniforms:{}};return a.set(T,B),(q=t.materialCreated)==null||q.call(t,T,B),T},setMaterial(_,T,B){c(_).materials[B]=T},getMaterial:(_,T)=>c(_).materials[T]??0,setUniformRgb(_,T,B){Y(_,T,{kind:"rgb",v:B})},setUniformRgba(_,T,B){Y(_,T,{kind:"rgba",v:B})},setUniformFloat(_,T,B){Y(_,T,{kind:"float",v:B})},setUniformBoolean(_,T,B){Y(_,T,{kind:"bool",v:B})},setUniformTexture(_,T,B){Y(_,T,{kind:"texture",v:B})},setUniformArray(_,T,B){Y(_,T,{kind:"array",v:Array.from(B)})},setUniformNull(_,T){Y(_,T,{kind:"null"})},createTexture(_,T,B){const q=e.getBuffer(_);if(!q||q.byteLength===0){B();return}const[ce,re]=hc(q),_e=h++;u.set(_e,{source:j(_),width:ce,height:re}),T(_e,ce,re)},createTextureFromCanvas(_){const T=h++;return u.set(T,{source:`canvas#${_}`,width:0,height:0}),T},updateTextureFromCanvas(){},createTexturePixels(_,T,B){const q=h++;return u.set(q,{source:`pixels ${_}x${T}x${B}`,width:_,height:T}),q},updateTexturePixels(){},createMediaPlayerTexture(_){const T=h++;return u.set(T,{source:`mediaplayer#${_}`,width:0,height:0}),T},attachCameraToAR(_,T,B){const q=o.get(_);q&&(q.camera=T);const ce=L(_);B(Ds(ce.fov,r/n,ce.near,ce.far),ce.fov)},getDisplaySize:()=>Float32Array.of(r,n),setVisible(_,T){var q;c(_).visible=T,(q=t.visibleChanged)==null||q.call(t,_,T);const B=ce=>{const re=c(ce);re.particles&&F.setVisible(ce,X(ce));for(const _e of re.children)B(_e)};B(_)},isVisible:_=>X(_),getName:_=>c(_).name,setName(_,T){c(_).name=T},createGlb(_,T,B){const{rootId:q,entIds:ce}=O(_);if(!t.glbAttach){T(q);return}Promise.resolve(t.glbAttach(_,q,ce)).then(()=>T(q)).catch(re=>B==null?void 0:B(re))},setGlbCulling(){},getGlbClipSet:_=>{var T,B;return((B=(T=l.get(_))==null?void 0:T.model)==null?void 0:B.clipSet)??0},...R.methods,setEarlyUpdate(_){M=_},setLateUpdate(_){m=_},setFixedUpdate(_){y=_},setTimeScale(_){le=Number.isFinite(_)&&_>0?_:0},...x.methods,...F.methods};function De(_){const T=c(_).m;return T instanceof Float32Array?T:Float32Array.from(T)}let qe=null;return{width:r,height:n,fov:s,entities:l,scenes:o,materials:a,textures:u,cameraOverride:()=>qe,setCameraOverride:_=>{qe=_},ent:c,newEnt:P,worldMatrix:f,worldMatrixF:d,sourceName:j,setParentInternal:S,sceneOf:$,projectionOf:L,rebindMatrix:(_,T)=>{c(_).m=T},methods:de,simulate:te,tick:ee,hasActiveScene:fe,activeSceneId:ye,physicsConfig:x.config,particleIndexPattern:F.indexPattern,nextTextureId:()=>h++,nextMaterialId:()=>p++}}const hc=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]},Tt=(t,e)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},$s=(t,e)=>{var u,g;const r=(u=e.mesh)==null?void 0:u.size;if(!r)return[];const n=((g=e.mesh)==null?void 0:g.center)??[0,0,0],s=r[0]/2,i=r[1]/2,l=r[2]/2,o=t.worldMatrixF(e.id),a=[];for(let p=0;p<8;p++){const h=n[0]+(p&1?s:-s),v=n[1]+(p&2?i:-i),M=n[2]+(p&4?l:-l);a.push([o[0]*h+o[4]*v+o[8]*M+o[12],o[1]*h+o[5]*v+o[9]*M+o[13],o[2]*h+o[6]*v+o[10]*M+o[14]])}return a},uc=(t,e)=>{const r=[],n=s=>{const i=t.entities.get(s);if(i){r.push(...$s(t,i));for(const l of i.children)n(l)}};return n(e),r};function fc(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:o,far:a}=t.projectionOf(e.id),u=(n==null?void 0:n.fov)??l,g=n?pa(n.eye,n.target):wt(t.worldMatrixF(r)),p=ut(new Float32Array(16),Ds(u,s/i,o,a),g),h=(C,P,c)=>{const f=p[3]*C+p[7]*P+p[11]*c+p[15],d=p[0]*C+p[4]*P+p[8]*c+p[12],w=p[1]*C+p[5]*P+p[9]*c+p[13],S=f>1e-4;return S?{sx:(d/f*.5+.5)*s,sy:(1-(w/f*.5+.5))*i,cw:f,inFront:S}:{sx:0,sy:0,cw:f,inFront:S}},v=C=>{for(let P=C;P!==0;P=t.ent(P).parent)if(!t.ent(P).visible)return!1;return!0},M=[e,...e.overlays.map(C=>t.scenes.get(C)).filter(C=>!!C)],m=new Set,y=[],x=C=>{if(!(m.has(C)||!t.entities.has(C))){m.add(C),y.push(C);for(const P of t.ent(C).children)x(P)}};for(const C of M)for(const P of C.entities)x(P);const F=[];for(const C of y){const P=t.ent(C);if(!v(C))continue;const c=P.model?"model":P.mesh&&!P.light?"mesh":P.particles?"particles":null;if(!c)continue;let f;if(c==="model")f=uc(t,C);else if(c==="mesh")f=$s(t,P);else{const B=t.worldMatrixF(C);f=[[B[12],B[13],B[14]]]}if(f.length===0)continue;let d=1/0,w=1/0,S=1/0,N=-1/0,U=-1/0,L=-1/0;for(const B of f)B[0]<d&&(d=B[0]),B[0]>N&&(N=B[0]),B[1]<w&&(w=B[1]),B[1]>U&&(U=B[1]),B[2]<S&&(S=B[2]),B[2]>L&&(L=B[2]);const $=h((d+N)/2,(w+U)/2,(S+L)/2);let j=!1,oe=!1,Y=1/0,O=1/0,k=-1/0,V=-1/0;for(const B of f){const q=h(B[0],B[1],B[2]);if(!q.inFront){j=!0;continue}oe=!0,q.sx<Y&&(Y=q.sx),q.sx>k&&(k=q.sx),q.sy<O&&(O=q.sy),q.sy>V&&(V=q.sy)}const X={kind:c,depth:Tt($.cw,3),coverage:0};if(P.name&&(X.name=P.name),!oe){X.behindCamera=!0,F.push({obj:X,id:C});continue}const le=Y,ee=O,te=Math.max(0,k-Y),fe=Math.max(0,V-O);X.rect=[Tt(le,1),Tt(ee,1),Tt(te,1),Tt(fe,1)],$.inFront&&(X.center=[Tt($.sx,1),Tt($.sy,1)]);const ye=Math.max(0,le),de=Math.max(0,ee),De=Math.min(s,le+te),qe=Math.min(i,ee+fe),_=Math.max(0,De-ye)*Math.max(0,qe-de);X.coverage=Tt(_/(s*i),4);const T=le>=0&&ee>=0&&le+te<=s&&ee+fe<=i;_===0?X.offscreen=!0:(j||!T)&&(X.clipped=!0),F.push({obj:X,id:C})}const R=C=>{const P=[];for(let c=C;c!==0;c=t.ent(c).parent)P.unshift(t.ent(c).name||"~");for(;P.length>0&&P[0]==="~";)P.shift();return P.join("/")};for(const{obj:C,id:P}of F)C.name&&(C.path=R(P));return F.sort((C,P)=>P.obj.coverage-C.obj.coverage||C.obj.depth-P.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:F.map(C=>C.obj)}}const Jt=(t,e=4)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},Ut=(t,e=4)=>Array.from(t,r=>Jt(r,e)),Cr=(t,e)=>"#"+(t>>>0).toString(16).padStart(e?8:6,"0");function dc(t,e){const{entities:r,scenes:n,materials:s,textures:i,worldMatrixF:l}=t,o=M=>{var m;switch(M.kind){case"rgb":return Cr(M.v,!1);case"rgba":return Cr(M.v,!0);case"texture":return((m=i.get(M.v))==null?void 0:m.source)??`texture#${M.v}`;case"null":return null;default:return M.v}},a=M=>{const m=s.get(M);if(!m)return;const y={shader:m.shader.replace(/\.filamat$/,"")};for(const[x,F]of Object.entries(m.uniforms))y[x]=o(F);return y},u=M=>{var c;const m=t.ent(M),y=m.m,x=Ut([y[12],y[13],y[14]]),F=Yn(y).map(f=>Jt(f,2)),R=pr(y).map(f=>Jt(f,4)),C=m.light?"light":m.model?"model":m.mesh?"mesh":m.particles?"particles":m.anchor?"anchor":"node",P={};if(m.name&&(P.name=m.name),P.kind=C,x.some(f=>f!==0)&&(P.position=x),F.some(f=>f!==0)&&(P.rotation=F),R.some(f=>f!==1)&&(P.scale=R),m.visible||(P.visible=!1),m.mesh){const f={type:m.mesh.kind===1?"edges":m.mesh.kind===2?"vertices":"triangles"};m.mesh.size&&(f.size=Ut(m.mesh.size)),(c=m.mesh.center)!=null&&c.some(w=>Jt(w)!==0)&&(f.center=Ut(m.mesh.center)),P.mesh=f;const d=a(m.materials[0]);d&&(P.material=d)}return m.model&&(P.model={...m.model.source&&{source:m.model.source},...!m.model.loaded&&{loaded:!1},animations:m.model.animations.map(f=>({name:f.name,duration:Jt(f.duration,2)}))}),m.light&&(P.light={type:"sun",direction:Ut(m.light.direction),intensity:m.light.intensity,color:Cr(m.light.color,!1),shadows:m.light.shadowsQuality}),m.particles&&(P.particles=m.particles),m.physics&&(P.physics=m.physics),m.ragdoll&&(P.ragdoll=m.ragdoll),m.collider&&(P.collider=m.collider),m.castShadows!==void 0&&(P.castShadows=m.castShadows),m.receiveShadows!==void 0&&(P.receiveShadows=m.receiveShadows),m.anchor&&(P.anchor=m.anchor),m.children.length>0&&(P.children=m.children.map(u)),P},g=M=>{const m=R=>{for(let C=t.ent(R).parent;C!==0;C=t.ent(C).parent)if(M.entities.has(C))return!0;return!1},y=[...M.entities].filter(R=>r.has(R)&&!m(R)),x={};M.arMode&&(x.ar={mode:M.arMode}),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 F=t.cameraOverride();if(F)x.camera={position:Ut(F.eye),lookAt:Ut(F.target),fov:F.fov??t.projectionOf(M.id).fov,inspection:!0};else if(M.camera!==void 0&&r.has(M.camera)){const R=l(M.camera),C=Yn(R).map(P=>Jt(P,2));x.camera={position:Ut([R[12],R[13],R[14]]),...C.some(P=>P!==0)&&{rotation:C},fov:t.projectionOf(M.id).fov}}return x.nodes=y.map(u),M.overlays.length>0&&(x.overlays=M.overlays.map(R=>n.get(R)).filter(Boolean).map(R=>g(R))),x},p=n.get(t.activeSceneId())??[...n.values()].find(M=>M.overlayOf===void 0);if(!p)return null;const h=g(p),v=fc(t,p);return v&&(h.frame=v),h}const As=new Set,I=t=>{As.has(t)||(As.add(t),console.warn(`[gl-lite] ${t}: not supported by the lite 3D engine`))},mc={createEngine(){I("createEngine")},createScene(){return I("createScene"),0},createOverlayScene(){return I("createOverlayScene"),0},createGLView(){I("createGLView")},openScene(){I("openScene")},closeScene(){I("closeScene")},launchAR(){I("launchAR")},stopAR(){I("stopAR")},launchVR(){I("launchVR")},stopVR(){I("stopVR")},addEntityToScene(){I("addEntityToScene")},removeEntityFromScene(){I("removeEntityFromScene")},warmRender(){I("warmRender")},createEntity(){return I("createEntity"),{id:0}},cloneEntity(){return I("cloneEntity"),{id:0}},destroyEntity(){I("destroyEntity")},entityIsOwned(){return I("entityIsOwned"),!1},setMatrix(){I("setMatrix")},setWorldMatrix(){I("setWorldMatrix")},getChildCount(){return I("getChildCount"),0},getChild(){return I("getChild"),0},setPosition(){I("setPosition")},setQuaternion(){I("setQuaternion")},setEulerAngles(){I("setEulerAngles")},setScale(){I("setScale")},setParent(){I("setParent")},setParentNull(){I("setParentNull")},getParent(){return I("getParent"),0},traverse(){I("traverse")},createSunLight(){I("createSunLight")},setDefaultIbl(){I("setDefaultIbl")},setBloomOptions(){I("setBloomOptions")},setSkybox(){I("setSkybox")},setSceneMultiSampleAntiAliasing(){I("setSceneMultiSampleAntiAliasing")},setMaterialGlobalParameter(){I("setMaterialGlobalParameter")},getCameraFov(){return I("getCameraFov"),0},getMatrix(){I("getMatrix")},getWorldMatrix(){I("getWorldMatrix")},getWorldPosition(){I("getWorldPosition")},getWorldDirection(){I("getWorldDirection")},getWorldMatrixInverse(){I("getWorldMatrixInverse")},getCameraViewDirection(){I("getCameraViewDirection")},setMesh(){I("setMesh")},createInstancedMesh(){I("createInstancedMesh")},setInstanceTransforms(){I("setInstanceTransforms")},setInstancedMeshMaterial(){I("setInstancedMeshMaterial")},setInstancedMeshShadows(){I("setInstancedMeshShadows")},setCulling(){I("setCulling")},setCastShadows(){I("setCastShadows")},setReceiveShadows(){I("setReceiveShadows")},createTexture(){I("createTexture")},createTextureFromCanvas(){return I("createTextureFromCanvas"),0},updateTextureFromCanvas(){I("updateTextureFromCanvas")},createMaterial(){return I("createMaterial"),{id:0}},builtinMaterial(){return I("builtinMaterial"),null},setMaterial(){I("setMaterial")},getMaterial(){return I("getMaterial"),0},setUniformRgb(){I("setUniformRgb")},setUniformRgba(){I("setUniformRgba")},setUniformFloat(){I("setUniformFloat")},setUniformBoolean(){I("setUniformBoolean")},setUniformTexture(){I("setUniformTexture")},setUniformArray(){I("setUniformArray")},setUniformNull(){I("setUniformNull")},attachCameraToAR(){I("attachCameraToAR")},getDisplaySize(){return I("getDisplaySize"),new Float32Array(0)},setVisible(){I("setVisible")},isVisible(){return I("isVisible"),!1},createGlb(){I("createGlb")},setGlbCulling(){I("setGlbCulling")},setEarlyUpdate(){I("setEarlyUpdate")},setLateUpdate(){I("setLateUpdate")},setOnPhysicsEvent(){I("setOnPhysicsEvent")},loadClips(){I("loadClips")},createClipFromTracks(){return I("createClipFromTracks"),0},getClipSetInfo(){return I("getClipSetInfo"),[]},deriveClip(){return I("deriveClip"),0},setClipEvents(){I("setClipEvents")},getGlbClipSet(){return I("getGlbClipSet"),0},destroyClipSet(){I("destroyClipSet")},animatorCreate(){return I("animatorCreate"),0},animatorDestroy(){I("animatorDestroy")},animatorBind(){return I("animatorBind"),0},animatorBoundTracks(){return I("animatorBoundTracks"),0},animatorSetBlend(){I("animatorSetBlend")},animatorSetBlendValue(){I("animatorSetBlendValue")},animatorPlay(){I("animatorPlay")},animatorStop(){I("animatorStop")},animatorSeek(){I("animatorSeek")},animatorGetSlotTime(){return I("animatorGetSlotTime"),0},animatorGetSlotWeight(){return I("animatorGetSlotWeight"),0},animatorSetLayer(){I("animatorSetLayer")},animatorSetGlobal(){I("animatorSetGlobal")},animatorSetRootMotion(){I("animatorSetRootMotion")},animatorGetRootMotion(){I("animatorGetRootMotion")},setOnAnimatorEvent(){I("setOnAnimatorEvent")},animatorSetFeet(){I("animatorSetFeet")},animatorSlotCurveAt(){return I("animatorSlotCurveAt"),0},animatorSlotCurveInfo(){return I("animatorSlotCurveInfo"),!1},animatorSlotTurn(){return I("animatorSlotTurn"),0},animatorSlotTimeAtTurn(){return I("animatorSlotTimeAtTurn"),0},animatorLayerPhase(){return I("animatorLayerPhase"),0},animatorSeekPhase(){I("animatorSeekPhase")},animatorSlotFit(){return I("animatorSlotFit"),0},animatorSlotExit(){return I("animatorSlotExit"),0},animatorSlotAlign(){return I("animatorSlotAlign"),0},animatorSlotContacts(){return I("animatorSlotContacts"),0},animatorSlotTreads(){return I("animatorSlotTreads"),0},animatorSlotPhysics(){return I("animatorSlotPhysics"),0},animatorSlotFeatures(){return I("animatorSlotFeatures"),0},animatorKneeAxis(){return I("animatorKneeAxis"),0},animatorSlotKneePole(){return I("animatorSlotKneePole"),0},animatorSetStepWarp(){I("animatorSetStepWarp")},setOnAnimatorStep(){I("setOnAnimatorStep")},animatorSetMotion(){I("animatorSetMotion")},animatorSetDriveInput(){I("animatorSetDriveInput")},animatorSetSlotDrive(){I("animatorSetSlotDrive")},animatorSetWarpParams(){I("animatorSetWarpParams")},locoCreate(){return I("locoCreate"),0},locoDestroy(){I("locoDestroy")},locoSetParams(){I("locoSetParams")},locoDefaults(){I("locoDefaults")},locoSetEntry(){I("locoSetEntry")},locoClearSet(){I("locoClearSet")},locoSetInput(){I("locoSetInput")},locoStep(){I("locoStep")},locoUpdate(){I("locoUpdate")},locoRead(){I("locoRead")},locoBuildDatabase(){return I("locoBuildDatabase"),0},setColliderFromMesh(){I("setColliderFromMesh")},setColliderBox(){I("setColliderBox")},setColliderSphere(){I("setColliderSphere")},physicsHasSupport(){return I("physicsHasSupport"),!1},physicsConfigure(){I("physicsConfigure")},setInterpolation(){I("setInterpolation")},physicsBuildBox(){return I("physicsBuildBox"),0},physicsBuildSphere(){return I("physicsBuildSphere"),0},physicsBuildCylinder(){return I("physicsBuildCylinder"),0},physicsBuildCapsule(){return I("physicsBuildCapsule"),0},physicsBuildMesh(){return I("physicsBuildMesh"),0},physicsBuildMeshFromEntity(){return I("physicsBuildMeshFromEntity"),0},physicsDestroyShape(){I("physicsDestroyShape")},physicsCreateBody(){return I("physicsCreateBody"),0},physicsSetPickable(){I("physicsSetPickable")},physicsSetFriction(){I("physicsSetFriction")},physicsGetFriction(){return I("physicsGetFriction"),0},physicsRaycast(){return I("physicsRaycast"),0},characterCreate(){return I("characterCreate"),0},characterDestroy(){I("characterDestroy")},characterMove(){I("characterMove")},characterMoveFree(){I("characterMoveFree")},characterSetVerticalVelocity(){I("characterSetVerticalVelocity")},characterSetVelocity(){I("characterSetVelocity")},characterSetGravityScale(){I("characterSetGravityScale")},characterSetMaxSlope(){I("characterSetMaxSlope")},characterGetVelocity(){I("characterGetVelocity")},characterGetGroundState(){return I("characterGetGroundState"),0},characterSetPosition(){I("characterSetPosition")},vehicleCreate(){return I("vehicleCreate"),0},vehicleDestroy(){I("vehicleDestroy")},vehicleSetInput(){I("vehicleSetInput")},vehicleGetState(){I("vehicleGetState")},vehicleReset(){I("vehicleReset")},vehicleBodyId(){return I("vehicleBodyId"),0},physicsCreateBox(){return I("physicsCreateBox"),0},physicsCreateSphere(){return I("physicsCreateSphere"),0},physicsCreateCylinder(){return I("physicsCreateCylinder"),0},physicsSetLinearVelocity(){I("physicsSetLinearVelocity")},physicsGetLinearVelocity(){I("physicsGetLinearVelocity")},physicsApplyImpulse(){I("physicsApplyImpulse")},physicsSetBodyPosition(){I("physicsSetBodyPosition")},physicsRemoveBody(){I("physicsRemoveBody")},createMediaPlayerTexture(){return I("createMediaPlayerTexture"),0},getName(){return I("getName"),""},setName(){I("setName")},hasMesh(){return I("hasMesh"),!1},createARController(){I("createARController")},createRootAnchor(){return I("createRootAnchor"),0},createAnchor(){return I("createAnchor"),0},createParticleSystem(){I("createParticleSystem")},spawnParticles(){I("spawnParticles")},setParticleSystemConfig(){I("setParticleSystemConfig")},createNoise(){return I("createNoise"),0},setNoiseFrequency(){I("setNoiseFrequency")},setNoiseOctaves(){I("setNoiseOctaves")},setNoiseFractalLunacrity(){I("setNoiseFractalLunacrity")},setNoiseFractalGain(){I("setNoiseFractalGain")},getNoise2D(){return I("getNoise2D"),0},getNoise3D(){return I("getNoise3D"),0},captureImage(){I("captureImage")}},pc=""+new URL("neutral_ibl128-D-lzdkLN.ktx",import.meta.url).href,gc={backend:"webgl-lite"},Zr=60,Ss=.01,bs=1e3,yc={baseColorFactor:"uBaseColorFactor",metallicFactor:"uMetallic",roughnessFactor:"uRoughness",emissiveFactor:"uEmissive",baseColorMap:"uBaseColorMap",baseColorIndex:"uBaseColorIndex"},vc=async(t,e={})=>{var Ge;const{fetch:r,getBlob:n,getBuffer:s,getLocalName:i,hasLocalBuffer:l,putBuffer:o,putLocalBuffer:a,getPlayer:u,removePlayers:g}=e.stores??ua,p=new Ci({canvas:t,dpr:1,alpha:e.transparent===!0||e.alpha===!0,antialias:!0,premultipliedAlpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:((Ge=e.preloads)==null?void 0:Ge.has("capture"))??!1}),h=p.gl;p.autoClear=!1;const v=Wa(h),M=$a(h);for(const A of["lit.filamat","unlit.filamat","unlit-transparent.filamat","video.filamat","shadow.filamat","particles.filamat","particles-quad.filamat","terrain.filamat"])l(A)||a(A,new ArrayBuffer(0));const m={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:He()},exposure:{value:ga}},y={value:[0,0,0,0]};let x=null;fetch(pc).then(A=>A.arrayBuffer()).then(A=>{x=Ia(h,A),m.envMap.value=x.cubemap,m.envMapMaxLod.value=x.maxLod,m.iblSH.value=Array.from(x.sh)}).catch(A=>console.warn("[viewer-lite] IBL load failed:",A));const F=new Map,R=new Map,C=new Map,P=new Map,c=new Map,f=new Map,d={value:1},w=new Map;let S=1,N=!0,U=!0,L=null;const $=[],j=A=>{let b=F.get(A);if(!b){const E=new ot;E.matrixAutoUpdate=!1,E._entId=A,b={transform:E,drawables:[]},F.set(A,b)}return b},oe=(A,b=!1)=>{let E;if(A==="lit")E=new Ie(h,{vertex:Dt,fragment:xa,uniforms:{...m,baseColor:{value:[1,1,1]},baseColorMap:{value:v},roughness:{value:0},metallic:{value:0}}});else if(A==="terrain")E=new Ie(h,{vertex:Dt,fragment:wa,uniforms:{...m,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(A==="video")E=new Ie(h,{vertex:Dt,fragment:Sa,uniforms:{baseColorMap:{value:v},shadowMatrix:m.shadowMatrix}});else if(A==="shadow")E=new Ie(h,{vertex:Dt,fragment:ba,uniforms:{...m,color:{value:[0,0,0,.66]}},transparent:!0}),E.setBlendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA);else if(A==="particles"||A==="particles-quad"){const D=A==="particles-quad";E=new Ie(h,{vertex:D?Pa:Fa,fragment:D?Ra:Ta,uniforms:{baseColorMap:{value:v},sheetSize:{value:[1,1]},emissive:{value:0},additive:{value:0},softness:{value:0},depthFade:{value:0},...D?{mode:{value:0},stretch:{value:0},emissiveMap:{value:v},emissiveColor:{value:[0,0,0]},frameBlend:{value:0}}:{perspScale:d}},transparent:!0,depthWrite:!1,cullFace:!1}),E.setBlendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA)}else E=new Ie(h,{vertex:Dt,fragment:b?Aa:Ma,uniforms:{baseColor:{value:[1,1,1,1]},baseColorMap:{value:v},shadowMatrix:m.shadowMatrix},transparent:b}),b&&E.setBlendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA);return{kind:A,program:E}},Y=A=>{const b=Ya(s(A));if(!b)return null;if(b.unsupported)return console.warn(`[viewer-lite] custom material not supported in lite (${b.unsupported}) — rendering unlit`),null;b.hasVertexBlock&&console.warn("[viewer-lite] custom material has a vertex{} block — the custom vertex stage is ignored in lite");const E=el(b);if(!E)return null;const D=E.needsSceneUniforms?{...m,userTime:y}:{shadowMatrix:m.shadowMatrix,userTime:y};for(const Q of E.uniforms)D[Q.key]={value:Q.value==="texture"?v:Q.value};const G=b.blending==="opaque"||b.blending==="masked",W=new Ie(h,{vertex:Dt,fragment:E.fragment,uniforms:D,transparent:!G,cullFace:b.doubleSided||b.culling==="none"?!1:b.culling==="front"?h.FRONT:h.BACK,depthWrite:b.depthWrite});return h.getProgramParameter(W.program,h.LINK_STATUS)?(G||W.setBlendFunc(h.ONE,b.blending==="add"?h.ONE:h.ONE_MINUS_SRC_ALPHA),{kind:"custom",program:W,customParams:E.paramNames}):(console.warn("[viewer-lite] custom material failed to compile — rendering unlit"),null)},O=(A,b)=>{const E=A.startsWith("lit")?"lit":A.startsWith("unlit")?"unlit":A.startsWith("video")?"video":A.startsWith("shadow")?"shadow":A.startsWith("terrain")?"terrain":A.startsWith("particles-quad")?"particles-quad":A.startsWith("particles")?"particles":"unknown";if(E==="unknown"&&b!==void 0){const D=Y(b);if(D)return D;console.warn(`[viewer-lite] custom shader can't run here (material "${A||b}") — rendering unlit`)}return oe(E,A.startsWith("unlit-transparent"))},k=(A,b)=>{var G;const E=A.kind==="gltf"?yc[b]??b:(G=A.customParams)!=null&&G.has(b)?`materialParams_${b}`:b,D=A.program.uniforms;return D[E]||(D[E]={value:0}),D[E]},V=(A,b,E)=>{const D=P.get(A);if(!D)return;if(b==="useBaseColorMap"&&(D.kind==="lit"||D.kind==="unlit")){if(E.kind==="bool"&&!E.v){const W=k(D,"baseColorMap");W.value instanceof je&&(W.value=v)}return}const G=k(D,b);switch(E.kind){case"rgb":{const[W,Q,J]=Ca(E.v);Array.isArray(G.value)&&G.value.length===4?G.value=[W,Q,J,G.value[3]]:G.value=[W,Q,J];break}case"rgba":{const W=Ea(E.v);G.value=Array.isArray(G.value)&&G.value.length===3?W.slice(0,3):W;break}case"float":G.value=E.v;break;case"bool":G.value=E.v?1:0;break;case"array":G.value=Float32Array.from(E.v);break;case"texture":{const W=c.get(E.v);W&&(G.value=W);break}case"null":G.value instanceof je&&(G.value=v);break}},X=(A,b)=>{b.kind!=="lit"&&b.kind!=="gltf"&&b.kind!=="shadow"&&b.kind!=="custom"||A.onBeforeRender(()=>{const E=A.program.uniforms;if(E.shadowEnabled){const D=m.shadowEnabled.value===1&&A._receiveShadows!==!1;E.shadowEnabled=D?m.shadowEnabled:{value:0}}})},le=(A,b,E,D)=>{const G=P.get(b);if(!G)return;const{vertices:W,normals:Q,indices:J,uv:ae,colors:me}=E,Se=new rt(h,{position:{size:3,data:Float32Array.from(W)},normal:{size:3,data:Q.length?Float32Array.from(Q):new Float32Array(W.length)},uv:{size:2,data:ae.length?Float32Array.from(ae):new Float32Array(W.length/3*2)},...me&&me.length?{color:{size:4,data:Float32Array.from(me,Ve=>Ve/255)}}:{},index:{data:Uint16Array.from(J)}});Se.computeBoundingBox();const be=D===1?h.LINES:D===2?h.POINTS:h.TRIANGLES,Ce=new Ke(h,{geometry:Se,program:G.program,mode:be});Ce.matrixAutoUpdate=!1,Ce._entId=A,Ce._castShadows=N,Ce._receiveShadows=U,X(Ce,G);const Re=j(A);for(const Ve of Re.drawables){Re.transform.removeChild(Ve);const ht=B.get(Ve);ht&&(ht.setParent(null),B.delete(Ve))}Re.drawables=[Ce],Re.transform.addChild(Ce)},ee=async(A,b,E)=>{const D=s(A);let G;try{G=await Xa(h,D,m,v)}catch(W){console.warn(`[viewer-lite] GLB "${i(A)??A}" drawables failed to load:`,W instanceof Error?W.message:W);return}G.nodes.forEach((W,Q)=>{const J=E[Q];if(J===void 0)return;const ae=j(J);ae.transform.setParent(null),ie.rebindMatrix(J,W.matrix),W.matrixAutoUpdate=!1,W._entId=J,ae.transform=W,ae.drawables=[];for(const me of W.children)me.draw&&(me.matrixAutoUpdate=!1,me._entId=J,me._castShadows=N,me._receiveShadows=U,ae.drawables.push(me))});for(const W of G.roots)W.setParent(j(b).transform)},te=[],fe=(A,b)=>{const E=j(A),D=j(b);for(const G of E.drawables){const W=G instanceof vt?new vt(h,{skeleton:G.skeleton,geometry:G.geometry,program:G.program,mode:G.mode}):new Ke(h,{geometry:G.geometry,program:G.program,mode:G.mode});W instanceof vt&&te.push(W),W._entId=b,W._castShadows=G._castShadows,W._receiveShadows=G._receiveShadows,W.frustumCulled=G.frustumCulled,W.matrixAutoUpdate=!1,D.drawables.push(W),D.transform.addChild(W)}},ye=A=>{for(const b of te.splice(0)){const E=b.skeleton.joints.map(D=>{const G=D._entId===void 0?void 0:A.get(D._entId);if(G===void 0)return D;const W=j(G).transform;return W.bindInverse=D.bindInverse,W});b.skeleton={...b.skeleton,joints:E}}};let de="off";const De={value:[.05,.06,.08]},qe=new Ie(h,{vertex:Dt,fragment:Qn,uniforms:{uWireColor:De,shadowMatrix:m.shadowMatrix}}),_=new Ie(h,{vertex:Vs("HAS_SKIN"),fragment:Qn,uniforms:{uWireColor:De,shadowMatrix:m.shadowMatrix,boneTexture:{value:v},boneTextureSize:{value:4}}}),T=new WeakMap,B=new WeakMap,q=A=>{var E;let b=T.get(A);if(!b){const D={};for(const[Q,J]of Object.entries(A.attributes))Q!=="index"&&(D[Q]={size:J.size,data:J.data,type:J.type,normalized:J.normalized,stride:J.stride,offset:J.offset,buffer:J.buffer,count:J.count});const G=A.attributes.position,W=G?G.count??G.data.length/G.size:0;D.index={data:ka((E=A.attributes.index)==null?void 0:E.data,W)},b=new rt(h,D),T.set(A,b)}return b},ce=A=>{var D,G;let b=B.get(A);if(b)return b;if(!A.parent||!((G=(D=A.geometry)==null?void 0:D.attributes)!=null&&G.position))return null;const E=q(A.geometry);return b=A instanceof vt?new vt(h,{skeleton:A.skeleton,geometry:E,program:_,mode:h.LINES}):new Ke(h,{geometry:E,program:qe,mode:h.LINES}),b.frustumCulled=!1,b.matrixAutoUpdate=!1,b.matrix.copy(A.matrix),b._entId=A._entId,b._castShadows=!1,b._receiveShadows=!1,b.setParent(A.parent),B.set(A,b),Oe(),b},re=()=>{for(const A of F.values())for(const b of A.drawables)if(b.mode===h.TRIANGLES)if(de==="off"){b.visible=!0;const E=B.get(b);E&&(E.visible=!1)}else{const E=ce(b);b.visible=de==="overlay",E&&(E.visible=!0)}},_e=()=>{for(const A of $)A.video.videoWidth===0||A.video.currentTime===A.lastTime||(A.texture.image=A.video,A.texture.needsUpdate=!0,A.lastTime=A.video.currentTime)},Ae=new sn(h,{fov:Zr,near:Ss,far:bs,aspect:1});Ae.matrixAutoUpdate=!1;let Le=!1,Ue=e.transparent===!0,Xe=0,ze=0,Ye=Zr,Ze=Ss,at=bs,pt=1,gt=null,Nt=0;const _t=new Ie(h,{vertex:ur(!1),fragment:fr,uniforms:{modelMatrix:{value:He()},shadowViewProjection:{value:He()}},cullFace:h.FRONT}),dt=new Ie(h,{vertex:ur(!0),fragment:fr,uniforms:{modelMatrix:{value:He()},shadowViewProjection:{value:He()},boneTexture:{value:v},boneTextureSize:{value:4}},cullFace:h.FRONT}),ke=new Ie(h,{vertex:ur(!1,!0),fragment:fr,uniforms:{shadowViewProjection:{value:He()}},cullFace:h.FRONT}),Je=new Map;let Mt=!0;const Lt=A=>{let b=Je.get(A);return b||(b=Vl(h,p),b.setEnabled(Mt),Je.set(A,b)),b};let Ot=0;const Oe=()=>{Ot++},yr=new Map,or=A=>{yr.get(A)!==Ot&&(A.updateMatrixWorld(),yr.set(A,Ot))},At=(A,b,E=!1)=>{const D=Lt(A);or(A),D.collect(A,b,!0,Ot,E),D.drawMain(b,m.shadowEnabled),E&&Oe()},ln=A=>{var b;for(const[E,D]of ie.entities)if(D.light&&ie.methods.isVisible(E)&&((b=ie.sceneOf(E))==null?void 0:b.id)===A)return D.light;return null},Rr=A=>{const b=[];return A.traverse(E=>E.visible?(E.draw&&b.push(E),!1):!0),b},cn=(A,b)=>{const E=b.shadowsQuality>=3?4096:b.shadowsQuality>=2?2048:1024;(!gt||Nt!==E)&&(gt=new Ns(h,{width:E,height:E,depthTexture:!0}),Nt=E);const D=Lt(A),G=D.casterSingles,W=[1/0,1/0,1/0],Q=[-1/0,-1/0,-1/0],J=[0,0,0];for(const bt of G){const lt=bt.geometry;if(lt.bounds||lt.computeBoundingBox(),!lt.bounds||!isFinite(lt.bounds.min.x))continue;const Mr=bt.worldMatrix;for(let It=0;It<8;It++){xt(J,Mr,It&1?lt.bounds.max.x:lt.bounds.min.x,It&2?lt.bounds.max.y:lt.bounds.min.y,It&4?lt.bounds.max.z:lt.bounds.min.z,1);for(let yt=0;yt<3;yt++)J[yt]<W[yt]&&(W[yt]=J[yt]),J[yt]>Q[yt]&&(Q[yt]=J[yt])}}if(D.casterBounds(W,Q),!isFinite(W[0])){m.shadowEnabled.value=0;return}const[ae,me,Se]=W,[be,Ce,Re]=Q,Ve=(ae+be)/2,ht=(me+Ce)/2,Ct=(Se+Re)/2,nt=Math.max(.5,Math.hypot(be-ae,Ce-me,Re-Se)/2);let vr=b.direction[0],ar=b.direction[1],xr=b.direction[2];const Br=Math.hypot(vr,ar,xr)||1;vr/=Br,ar/=Br,xr/=Br;const St=[Ve-vr*nt*2,ht-ar*nt*2,Ct-xr*nt*2],Ht=-vr,kt=-ar,Wt=-xr,$t=Math.abs(ar)>.99?[1,0,0]:[0,1,0];let jt=$t[1]*Wt-$t[2]*kt,qt=$t[2]*Ht-$t[0]*Wt,Xt=$t[0]*kt-$t[1]*Ht;const Nr=Math.hypot(jt,qt,Xt)||1;jt/=Nr,qt/=Nr,Xt/=Nr;const hn=kt*Xt-Wt*qt,un=Wt*jt-Ht*Xt,fn=Ht*qt-kt*jt,st=new Float32Array(16);st[0]=jt,st[4]=qt,st[8]=Xt,st[1]=hn,st[5]=un,st[9]=fn,st[2]=Ht,st[6]=kt,st[10]=Wt,st[12]=-(jt*St[0]+qt*St[1]+Xt*St[2]),st[13]=-(hn*St[0]+un*St[1]+fn*St[2]),st[14]=-(Ht*St[0]+kt*St[1]+Wt*St[2]),st[15]=1;const js=da(-nt,nt,-nt,nt,.05,nt*4),wr=ut(new Float32Array(16),js,st);_t.uniforms.shadowViewProjection.value=wr,dt.uniforms.shadowViewProjection.value=wr,ke.uniforms.shadowViewProjection.value=wr,m.shadowMatrix.value=wr,m.shadowMap.value=gt.depthTexture,m.shadowMapSize.value=E,m.shadowEnabled.value=1,p.bindFramebuffer(gt),p.setViewport(E,E),h.clearColor(1,1,1,1),p.enable(h.DEPTH_TEST),p.setDepthMask(!0),h.clear(h.COLOR_BUFFER_BIT|h.DEPTH_BUFFER_BIT);const qs=He();for(const bt of G){const lt=bt instanceof vt,Mr=lt?dt:_t,It=bt.program;Mr.uniforms.modelMatrix.value=lt?qs:bt.worldMatrix,bt.program=Mr,bt.draw({}),bt.program=It}D.drawShadow(ke),p.bindFramebuffer({buffer:null})},z=A=>{let b=Xe===0?0:(A-Xe)/1e3;b>.05&&(b=.05),Xe=A;const E=A/1e3;y.value[0]=E,y.value[1]=E-Math.floor(E),ie.tick(b)},Z=A=>{var J;const b=t.width/Math.max(1,t.height),{fov:E,near:D,far:G}=ie.projectionOf(A);d.value=Math.max(1,t.height)/(2*Math.tan(E*Math.PI/360)),(b!==ze||E!==Ye||D!==Ze||G!==at)&&(ze=b,Ye=E,Ze=D,at=G,Ae.perspective({fov:E,aspect:b,near:D,far:G}));const W=(J=ie.scenes.get(A))==null?void 0:J.camera,Q=W!==void 0?ie.worldMatrix(W):He();for(let ae=0;ae<16;ae++)Ae.matrix[ae]=Q[ae];Ae.worldMatrixNeedsUpdate=!0},H=A=>{const b=ie.activeSceneId(),E=ie.scenes.get(b),D=R.get(b);if(!E||!D)return!1;z(A),_e(),Z(b),de!=="off"?(re(),h.enable(h.POLYGON_OFFSET_FILL),h.polygonOffset(1,1)):h.disable(h.POLYGON_OFFSET_FILL),or(D);const G=Lt(D);G.collect(D,Ae,!0,Ot);const W=ln(b);if(W){const J=(W.color>>>16&255)/255,ae=(W.color>>>8&255)/255,me=(W.color&255)/255;m.sunDirection.value=W.direction,m.sunColorIntensity.value=[J,ae,me,W.intensity],W.shadowsQuality>0?cn(D,W):m.shadowEnabled.value=0}else m.sunColorIntensity.value=[1,1,1,0],m.shadowEnabled.value=0;m.iblLuminance.value=E.ibl??0;const Q=E.skybox!==void 0?[Yt((E.skybox>>>16&255)/255),Yt((E.skybox>>>8&255)/255),Yt((E.skybox&255)/255)]:[Yt(.1),Yt(.25),Yt(.57)];p.bindFramebuffer({buffer:null}),p.setViewport(t.width,t.height),Ue?h.clearColor(0,0,0,0):h.clearColor(Q[0],Q[1],Q[2],1),p.enable(h.DEPTH_TEST),p.setDepthMask(!0),h.clear(h.COLOR_BUFFER_BIT|h.DEPTH_BUFFER_BIT),G.drawMain(Ae,m.shadowEnabled),L==null||L.renderScenePass(Q);for(const J of E.overlays){const ae=R.get(J);ae&&(h.clear(h.DEPTH_BUFFER_BIT),At(ae,Ae))}return L==null||L.renderOverlayPass(),L==null||L.renderPreviewPass(D,Q),!0},K=new Set,se=()=>{if(Le){try{H(performance.now())}catch(A){const b=A instanceof Error?A.message:String(A);K.has(b)||(K.add(b),console.error("[viewer-lite] render frame failed:",A))}requestAnimationFrame(se)}},ne=A=>{var b;return(b=ie.sceneOf(A))==null?void 0:b.id};let he=[0,0,0];const ue=(A,b,E)=>{var nt;const D=(nt=ie.scenes.get(A))==null?void 0:nt.camera,G=D!==void 0?ie.worldMatrix(D):He(),W=Math.max(1,t.width),Q=Math.max(1,t.height),J=W/Q,ae=b*pt,me=E*pt,Se=Math.tan(ie.projectionOf(A).fov*Math.PI/360),be=(ae/W*2-1)*Se*J,Ce=(1-me/Q*2)*Se,Re=G[0]*be+G[4]*Ce-G[8],Ve=G[1]*be+G[5]*Ce-G[9],ht=G[2]*be+G[6]*Ce-G[10],Ct=Math.hypot(Re,Ve,ht)||1;return he=[G[12],G[13],G[14]],{origin:he,dir:[Re/Ct,Ve/Ct,ht/Ct]}},pe=(A,b,E)=>{const D=C.get(A);if(!D)return 0;let G=1/0,W=0;const Q=[0,0,0],J=[0,0,0];for(const[ae,me]of D){if(!ie.entities.has(ae)||!ie.methods.isVisible(ae))continue;const Se=wt(ie.worldMatrixF(ae));xt(Q,Se,b[0],b[1],b[2],1),xt(J,Se,E[0],E[1],E[2],0);const be=me.type==="box"?Kn(me.center,me.extent,Q,J):ma(me.center,me.radius,Q,J);be>0&&be<G&&(G=be,W=ae)}return W},ve=(A,b,E)=>{const D=R.get(A);if(!D)return 0;let G=1/0,W=0;const Q=[0,0,0],J=[0,0,0];D.updateMatrixWorld();for(const ae of Rr(D)){const me=ae.geometry;if(me.bounds||me.computeBoundingBox(),!me.bounds||!isFinite(me.bounds.min.x))continue;const Se=wt(ae.worldMatrix);xt(Q,Se,b[0],b[1],b[2],1),xt(J,Se,E[0],E[1],E[2],0);const be=[(me.bounds.min.x+me.bounds.max.x)/2,(me.bounds.min.y+me.bounds.max.y)/2,(me.bounds.min.z+me.bounds.max.z)/2],Ce=[(me.bounds.max.x-me.bounds.min.x)/2,(me.bounds.max.y-me.bounds.min.y)/2,(me.bounds.max.z-me.bounds.min.z)/2],Re=Kn(be,Ce,Q,J);Re>0&&Re<G&&(G=Re,W=ae._entId??0)}return W},we=(A,b)=>{const E=ie.activeSceneId(),D=ie.scenes.get(E);if(!D||D.camera===void 0)return 0;const{origin:G,dir:W}=ue(E,A,b);for(let Q=D.overlays.length-1;Q>=0;Q--){const J=pe(D.overlays[Q],G,W);if(J!==0)return J}return pe(E,G,W)},ge=A=>{A.mesh&&A.mesh.setParent(null),A.buffer&&h.deleteBuffer(A.buffer),A.mesh=null,A.geometry=null,A.buffer=null},xe=(A,b)=>{const E=P.get(A.materialId);if(b===Et.MESH)return(E??oe("unlit")).program;const D=b!==Et.POINTS;return E&&E.kind===(D?"particles-quad":"particles")?E.program:oe(D?"particles-quad":"particles").program},Pe=(A,b,E)=>{if(ge(b),b.version=E.geometryVersion,b.mode=E.mode,E.capacity===0)return;const D=ie.particleIndexPattern(A);if(D.length===0)return;let G;if(E.mode===Et.MESH){const Q=E.capacity*E.meshVertexCount;G=new rt(h,{position:{size:3,data:new Float32Array(Q*3),usage:h.DYNAMIC_DRAW},normal:{size:3,data:new Float32Array(Q*3),usage:h.DYNAMIC_DRAW},uv:{size:2,data:new Float32Array(Q*2),usage:h.DYNAMIC_DRAW},index:{data:D}})}else{const Q=h.createBuffer();b.buffer=Q;const J=E.stride,ae=E.mode===Et.POINTS?E.capacity:E.mode===Et.QUADS?E.capacity*4:(E.capacity+1)*2,me=(be,Ce)=>({size:be,type:h.FLOAT,buffer:Q,stride:J,offset:Ce,count:ae,data:new Float32Array(0)}),Se={position:me(3,0),color:me(4,12),custom:me(4,28)};E.mode!==Et.POINTS&&(Se.aux=me(3,44),Se.corner=me(2,56)),Se.index={data:Uint16Array.from(D)},G=new rt(h,Se),h.bindBuffer(h.ARRAY_BUFFER,Q),h.bufferData(h.ARRAY_BUFFER,ae*J,h.DYNAMIC_DRAW),p.state.boundBuffer=Q}const W=new Ke(h,{geometry:G,program:xe(b,E.mode),mode:E.mode===Et.POINTS?h.POINTS:h.TRIANGLES});W.frustumCulled=!1,W.matrixAutoUpdate=!1,W._entId=A,W._particles=!0,W.setParent(j(A).transform),b.geometry=G,b.mesh=W},Fe=(A,b)=>{let E=f.get(A);if(E||(E={materialId:0,mesh:null,geometry:null,buffer:null,version:0,mode:-1},f.set(A,E)),(E.version!==b.geometryVersion||E.mode!==b.mode||!E.mesh)&&(Pe(A,E,b),Oe()),!E.mesh||!E.geometry)return;const D=b.indexCount>0;if(E.mesh.visible!==D&&(E.mesh.visible=D,Oe()),!!D){if(E.mesh.renderOrder=b.order,b.mode===Et.MESH){const G=b.vertexCount,W=new Float32Array(b.bytes.buffer,b.bytes.byteOffset,G*10),Q=E.geometry.attributes.position,J=E.geometry.attributes.normal,ae=E.geometry.attributes.uv,me=Q.data,Se=J.data,be=ae.data;for(let Ce=0;Ce<G;Ce++){const Re=Ce*10;me[Ce*3]=W[Re],me[Ce*3+1]=W[Re+1],me[Ce*3+2]=W[Re+2];const Ve=W[Re+3],ht=W[Re+4],Ct=W[Re+5],nt=W[Re+6];Se[Ce*3]=2*(Ve*Ct+ht*nt),Se[Ce*3+1]=2*(ht*Ct-Ve*nt),Se[Ce*3+2]=1-2*(Ve*Ve+ht*ht),be[Ce*2]=W[Re+8],be[Ce*2+1]=W[Re+9]}Q.needsUpdate=J.needsUpdate=ae.needsUpdate=!0}else E.buffer&&(h.bindBuffer(h.ARRAY_BUFFER,E.buffer),h.bufferSubData(h.ARRAY_BUFFER,0,b.bytes),p.state.boundBuffer=E.buffer);E.geometry.drawRange.start=0,E.geometry.drawRange.count=b.indexCount}},Be={allocMatrix:A=>j(A).transform.matrix,localMatrixChanged:A=>{j(A).transform.worldMatrixNeedsUpdate=!0,Oe()},parentChanged:(A,b)=>{Oe();const E=j(A).transform;if(b!==0)E.setParent(j(b).transform);else{const D=ie.sceneOf(A);E.setParent((D&&R.get(D.id))??null)}},sceneCreated:A=>{R.set(A,new ot),C.set(A,new Map)},entitySceneChanged:(A,b,E)=>{Oe();const D=R.get(b);if(!D)return;const G=j(A);if(E){for(const[W,Q]of C){if(W===b)continue;const J=Q.get(A);J&&(C.get(b).set(A,J),Q.delete(A))}ie.ent(A).parent===0&&G.transform.setParent(D)}else ie.ent(A).parent===0&&G.transform.parent===D&&G.transform.setParent(null)},visibleChanged:(A,b)=>{j(A).transform.visible=b,Oe()},materialCreated:(A,b,E)=>{P.set(A,O(b.shader,E))},uniformChanged:(A,b,E)=>V(A,b,E),meshSet:(A,b,E,D)=>{le(A,b,D,E.kind),Oe()},glbAttach:(A,b,E)=>ee(A,b,E).then(Oe),morphWeights:(A,b)=>{const E=j(A).transform.weights;E&&E.set(b.subarray(0,Math.min(E.length,b.length)))},entityDestroyed:A=>{Oe();const b=F.get(A);b&&(b.transform.setParent(null),F.delete(A));for(const E of C.values())E.delete(A)},entityCloned:(A,b)=>{fe(A,b),Oe()},subtreeCloned:(A,b,E)=>ye(E),particleSystemCreated:(A,b)=>{const E=f.get(A);E?(ge(E),E.materialId=b,E.version=0):f.set(A,{materialId:b,mesh:null,geometry:null,buffer:null,version:0,mode:-1})},particlesFrame:(A,b)=>Fe(A,b),particleSystemDestroyed:A=>{const b=f.get(A);b&&(ge(b),f.delete(A)),Oe()}},Ne=e.twins??{};await Promise.all([Ne.anim!==!1&&$l(),Ne.physics!==!1&&rl(),Ne.particles!==!1&&nc()]);const ie=cc(Be,{getBuffer:s,getSourceName:i,width:t.width||1,height:t.height||1,fov:Zr}),Te=(A,b,E)=>{createImageBitmap(A).then(D=>{const G=new je(h,{image:D,internalFormat:h.SRGB8_ALPHA8,format:h.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),W=S++;c.set(W,G),b(W,D.width,D.height)}).catch(E)};return{...mc,...gc,...ie.methods,createEntity:()=>({id:ie.methods.createEntity()}),cloneEntity:A=>({id:ie.methods.cloneEntity(A)}),createMaterial:A=>({id:ie.methods.createMaterial(A)}),builtinMaterial:A=>({id:ie.methods.createMaterialNamed(A)}),createGlb(A,b,E){ie.methods.createGlb(A,D=>b({id:D}),E)},openScene(A){const b=Le;ie.methods.openScene(A),Le=ie.scenes.has(A),t.style.display="block",!b&&Le&&requestAnimationFrame(se)},closeScene(){t.style.display="none",Le=!1,ie.methods.closeScene()},launchAR(){throw new Error("launchAR is not implemented")},stopAR(){throw new Error("stopAR is not implemented")},launchVR(A,b,E){E(new Error("VR is not supported on this device"))},stopVR(){},async warmRender(A,b){b()},attachCameraToAR(A,b,E){const D=ie.scenes.get(A);if(D){D.camera=b;for(const G of D.overlays){const W=ie.scenes.get(G);W&&(W.camera=b)}}},getCameraFov(A,b){const E=ie.projectionOf(A).fov;if(b!==1)return E;const D=E*Math.PI/180,G=t.width/Math.max(1,t.height);return 2*Math.atan(Math.tan(D/2)*G)*180/Math.PI},getCameraViewDirection(A,b,E,D){if(!ie.scenes.has(A)){D[0]=0,D[1]=0,D[2]=-1;return}const{dir:G}=ue(A,b,E);D[0]=G[0],D[1]=G[1],D[2]=G[2]},getDisplaySize:()=>Float32Array.of(p.width||t.width,p.height||t.height),createTexture(A,b,E){const D=(W,Q,J)=>b({id:W},Q,J),G=n(A);G.slice(0,12).arrayBuffer().then(async W=>{const Q=await mr(()=>import("./index-3CbsYWmo.js"),__vite__mapDeps([0,1]),import.meta.url);if(!Q.isKtx2Bytes(new Uint8Array(W)))return!1;const J=await G.arrayBuffer(),ae=await Q.transcodeKtx2(h,J),me=Q.ktx2IsSrgb(J);let Se;ae.isCompressedTexture?Se=new je(h,{image:ae,internalFormat:me&&ae.srgbInternalFormat?ae.srgbInternalFormat:ae.internalFormat,generateMipmaps:!1,minFilter:ae.length>1?h.LINEAR_MIPMAP_LINEAR:h.LINEAR,flipY:!1}):Se=new je(h,{image:ae,internalFormat:me?h.SRGB8_ALPHA8:h.RGBA8,format:h.RGBA,generateMipmaps:!0,flipY:!1,premultiplyAlpha:!1});const be=S++;return c.set(be,Se),D(be,ae.width,ae.height),!0}).then(W=>{W||Te(G,D,E)},E)},createTexturePixels(A,b,E,D,G){if(A<=0||b<=0||D.length<A*b*E)return{id:4294967295};const W=new Uint8Array(A*b*4);for(let ae=0,me=A*b;ae<me;ae++){const Se=ae*E,be=ae*4;W[be]=D[Se],W[be+1]=E>=2?D[Se+1]:D[Se],W[be+2]=E>=3?D[Se+2]:D[Se],W[be+3]=E>=4?D[Se+3]:255}const Q=new je(h,{image:W,width:A,height:b,internalFormat:G?h.SRGB8_ALPHA8:h.RGBA8,format:h.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1,minFilter:h.LINEAR,magFilter:h.LINEAR}),J=S++;return c.set(J,Q),w.set(J,{rgba:W,width:A,height:b,channels:E}),{id:J}},updateTexturePixels(A,b,E,D,G,W){const Q=w.get(A),J=c.get(A);if(!Q||!J)return;const ae=Q.channels;for(let me=0;me<G;me++){const Se=E+me;if(!(Se<0||Se>=Q.height))for(let be=0;be<D;be++){const Ce=b+be;if(Ce<0||Ce>=Q.width)continue;const Re=(me*D+be)*ae,Ve=(Se*Q.width+Ce)*4;Q.rgba[Ve]=W[Re],Q.rgba[Ve+1]=ae>=2?W[Re+1]:W[Re],Q.rgba[Ve+2]=ae>=3?W[Re+2]:W[Re],Q.rgba[Ve+3]=ae>=4?W[Re+3]:255}}J.image=Q.rgba,J.needsUpdate=!0},createTextureFromCanvas(A){var G;const b=(G=e.canvasHost)==null?void 0:G.readSurface(A);if(!b)return 0;const E=new je(h,{image:new Uint8Array(b.data.buffer.slice(0)),width:b.width,height:b.height,internalFormat:h.SRGB8_ALPHA8,format:h.RGBA,generateMipmaps:!1,flipY:!1}),D=S++;return c.set(D,E),D},updateTextureFromCanvas(A,b){var G;const E=(G=e.canvasHost)==null?void 0:G.readSurface(b),D=c.get(A);!E||!D||(D.image=new Uint8Array(E.data.buffer.slice(0)),D.width=E.width,D.height=E.height,D.needsUpdate=!0)},createMediaPlayerTexture(A){const b=u(A),E=new je(h,{generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1});$.push({video:b,texture:E,lastTime:-1});const D=S++;return c.set(D,E),D},setUniformTexture(A,b,E,D,G){ie.methods.setUniformTexture(A,b,E);const W=P.get(A),Q=c.get(E);if(!W||!Q)return;const J=[h.CLAMP_TO_EDGE,h.REPEAT,h.MIRRORED_REPEAT];Q.wrapS=J[D]??h.REPEAT,Q.wrapT=J[G]??h.REPEAT,Q.needsUpdate=!0,k(W,b).value=Q},setMaterial(A,b,E){ie.methods.setMaterial(A,b,E);const D=P.get(b),G=j(A).drawables[E];!D||!G||(G.program=D.program,X(G,D),Oe())},getMaterial(A,b){const E=j(A).drawables[b];if(!E)return 0;const D=ie.nextMaterialId();return P.set(D,{kind:"gltf",program:E.program}),D},setCulling(A,b){for(const E of j(A).drawables)E.frustumCulled=b;Oe()},setGlbCulling(A,b){const E=D=>{for(const G of j(D).drawables)G.frustumCulled=b;for(const G of ie.ent(D).children)E(G)};E(A),Oe()},setRenderPriority(A,b){for(const E of j(A).drawables)E.renderOrder=b;Oe()},setMaterialDepthTest(A,b){const E=P.get(A);E&&(E.program.depthTest=b)},setMaterialDepthWrite(A,b){const E=P.get(A);E&&(E.program.depthWrite=b)},setMaterialCulling(A,b){const E=P.get(A);E&&(E.program.cullFace=b===0?!1:b===1?h.FRONT:h.BACK)},setCastShadows(A,b){ie.methods.setCastShadows(A,b);for(const E of j(A).drawables)E._castShadows=b;Oe()},setReceiveShadows(A,b){ie.methods.setReceiveShadows(A,b);for(const E of j(A).drawables)E._receiveShadows=b;Oe()},setGlbShadows(A,b,E){ie.methods.setGlbShadows(A,b,E);const D=G=>{for(const W of j(G).drawables)W._castShadows=b,W._receiveShadows=E;for(const W of ie.ent(G).children)D(W)};D(A),Oe()},setCastShadowsGlobal(A){N=A},setReceiveShadowsGlobal(A){U=A},setColliderFromMesh(A,b,E){var Q;if(E!==0)return;const D=j(b).drawables[0];if(!D)return;const G=D.geometry;if(G.bounds||G.computeBoundingBox(),!G.bounds)return;const W=ne(A)??ie.activeSceneId();(Q=C.get(W))==null||Q.set(A,{type:"box",center:[(G.bounds.min.x+G.bounds.max.x)/2,(G.bounds.min.y+G.bounds.max.y)/2,(G.bounds.min.z+G.bounds.max.z)/2],extent:[(G.bounds.max.x-G.bounds.min.x)/2,(G.bounds.max.y-G.bounds.min.y)/2,(G.bounds.max.z-G.bounds.min.z)/2]})},setColliderBox(A,b,E,D,G,W,Q){var ae;const J=ne(A)??ie.activeSceneId();(ae=C.get(J))==null||ae.set(A,{type:"box",center:[b,E,D],extent:[G/2,W/2,Q/2]})},setColliderSphere(A,b,E,D,G){var Q;const W=ne(A)??ie.activeSceneId();(Q=C.get(W))==null||Q.set(A,{type:"sphere",center:[b,E,D],radius:G})},createARController(){throw new Error("createARController is not implemented")},createRootAnchor(){throw new Error("createRootAnchor is not implemented")},createAnchor(){throw new Error("createAnchor is not implemented")},createARPlane:()=>0,updateProjectionMatrixAR(){},_setARController(){},_renderNow:()=>H(performance.now()),async captureImage(A,b,E){try{H(performance.now());const D=new OffscreenCanvas(t.width,t.height);D.getContext("2d").drawImage(t,0,0);const W=await D.convertToBlob({type:"image/png"}),Q=await W.arrayBuffer();b(o(Q),"image.png",W.size)}catch{E()}},raycastView:we,_raycastView:we,raycastPick(A,b){const E=ie.activeSceneId(),D=ie.scenes.get(E);if(!D||D.camera===void 0)return 0;const G=we(A,b);if(G!==0)return G;const{origin:W,dir:Q}=ue(E,A,b);return ve(E,W,Q)},computeBoundingBox(A){const b=Float32Array.of(1/0,1/0,1/0,-1/0,-1/0,-1/0),E=[0,0,0],D=(G,W)=>{for(const Q of j(G).drawables){const J=Q.geometry;if(J.bounds||J.computeBoundingBox(),!(!J.bounds||!isFinite(J.bounds.min.x)))for(let ae=0;ae<8;ae++){const me=ae&1?J.bounds.max.x:J.bounds.min.x,Se=ae&2?J.bounds.max.y:J.bounds.min.y,be=ae&4?J.bounds.max.z:J.bounds.min.z;W?xt(E,W,me,Se,be,1):(E[0]=me,E[1]=Se,E[2]=be);for(let Ce=0;Ce<3;Ce++)E[Ce]<b[Ce]&&(b[Ce]=E[Ce]),E[Ce]>b[Ce+3]&&(b[Ce+3]=E[Ce])}}for(const Q of ie.ent(G).children){const J=j(Q).transform.matrix,ae=W?ut(new Float32Array(16),W,J):Float32Array.from(J);D(Q,ae)}};return D(A,null),isFinite(b[0])||b.fill(0),b},stopAllPlayers(){g()},_dumpScene3d:()=>dc(ie),_setWireframeMode(A){de=A==="overlay"||A==="only"?A:"off",De.value=de==="only"?[.62,.66,.72]:[.05,.06,.08],re(),Oe()},_setBatching(A){for(const b of Je.values())b.setEnabled(A);Mt=A,Oe()},_batchStats(){const A=R.get(ie.activeSceneId());return A?Lt(A).stats():{batches:0,instances:0,visible:0,singles:0}},_editorConnect(A){return L??(L=Ol({gl:h,renderer:p,canvas:t,camera:Ae,core:ie,sceneRoots:R,drawablesOf:b=>j(b).drawables,collectMeshes:Rr,wireGeometryFor:q,getViewRay:ue,renderScene:At})),L.setHandlers(A),L.api},async createEngine(){},_fetch:r,_getPlayer:u,_createGLTexture(A){const b=new je(h,{image:A,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),E=S++;return c.set(E,b),b.update(),{gl:h,glTexture:b.texture,textureId:E}},_projectionOf:A=>ie.projectionOf(A),_setTransparent(A){Ue=A},_onResize(A,b,E=1){pt=E,p.dpr=E,p.setSize(A,b),ze=0},_dispose(){var A;L==null||L.dispose(),L=null;for(const b of Je.values())b.dispose();Je.clear(),this.closeScene(),this.stopAllPlayers(),(A=h.getExtension("WEBGL_lose_context"))==null||A.loseContext()}}},xc=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 vc(s,{preloads:e.preloads,twins:e.twins,alpha:e.alpha}),l=()=>{const g=t.clientWidth,p=t.clientHeight;g>0&&p>0&&i._onResize(g,p,n.devicePixelRatio||1)};let o=null,a=-1;return{feature:{name:"scene3d",install(){return t.insertBefore(s,t.firstChild),l(),o=new ResizeObserver(l),o.observe(t),{globals:{_creator:i},destination(g,p){return g.kind!==ni?!1:(p?(a=g.id,i.openScene(g.id)):a===g.id&&(a=-1,i.closeScene()),!0)},hit:(g,p,h)=>g===s&&a>=0?i.raycastPick(p,h):null,destroy(){o==null||o.disconnect(),o=null,a=-1,i._dispose(),s.remove()}}}},engine:i,canvas:s,opened:()=>a,dispose(){i._dispose(),s.remove()}}},Mc=Object.freeze(Object.defineProperty({__proto__:null,createScene3d:xc},Symbol.toStringTag,{value:"Module"}));export{Xn as G,Mc as s};