lecodes-cli 2.0.8 → 2.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +151 -95
- package/package.json +8 -8
- package/runtime/sdk-types.json +1 -1
- package/runtime/web/VERSION.json +3 -3
- package/runtime/web/assets/creator-2d-BSJoqaE1.wasm +0 -0
- package/runtime/web/assets/{creator-2d-CYlV77UR.js → creator-2d-DG2jJnoQ.js} +1 -1
- package/runtime/web/assets/creator-ui-Bu2prHDl.wasm +0 -0
- package/runtime/web/assets/creator-ui-HDloYDcM.js +1 -0
- package/runtime/web/player.js +15 -15
- package/runtime/web-lite/assets/{index-3CbsYWmo.js → index-BttBnvIf.js} +1 -1
- package/runtime/web-lite/assets/pager-DpGa2uaE.js +1 -0
- package/runtime/web-lite/assets/scene3d-D8LdhX0V.js +888 -0
- package/runtime/web-lite/features.json +3 -3
- package/runtime/web-lite/lite.js +21 -10
- package/src/dev/webRunner.ts +1 -1
- package/runtime/web/assets/creator-2d-nG7rGEmq.wasm +0 -0
- package/runtime/web/assets/creator-ui-CbtoaRlz.js +0 -1
- package/runtime/web/assets/creator-ui-DZaoxIpX.wasm +0 -0
- package/runtime/web-lite/assets/pager-Db5BY7FB.js +0 -1
- package/runtime/web-lite/assets/scene3d-CX7MAqmN.js +0 -866
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-BttBnvIf.js","../lite.js","./creatorPhysics-k7wL0kV1.js","./creatorAnim-BOwKr-C1.js","./creatorParticles-DYlv4g1J.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as Zs,_ as Js,g as ei,a as ti,b as ri,h as ni,p as si,c as ii,d as oi,e as wr,v as gn,T as ai}from"../lite.js";function gr(t){let e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function rn(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function li(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function yn(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function vn(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function ci(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function hi(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function Dr(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function ui(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 fi(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 xn(t){let e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function di(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function pi(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function nn(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 Ts(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function wn(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 mi(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 gi(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 yi(t,e,r){let n=e[0],s=e[1],i=e[2],l=r[3]*n+r[7]*s+r[11]*i+r[15];return l=l||1,t[0]=(r[0]*n+r[4]*s+r[8]*i+r[12])/l,t[1]=(r[1]*n+r[5]*s+r[9]*i+r[13])/l,t[2]=(r[2]*n+r[6]*s+r[10]*i+r[14])/l,t}function vi(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 xi(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 wi(t,e,r){let n=e[0],s=e[1],i=e[2],l=r[0],o=r[1],a=r[2],f=r[3],g=o*i-a*s,m=a*n-l*i,h=l*s-o*n,v=o*h-a*m,M=a*g-l*h,p=l*m-o*g,y=f*2;return g*=y,m*=y,h*=y,v*=2,M*=2,p*=2,t[0]=n+g+v,t[1]=s+m+M,t[2]=i+h+p,t}const Mi=(function(){const t=[0,0,0],e=[0,0,0];return function(r,n){rn(t,r),rn(e,n),nn(t,t),nn(e,e);let s=Ts(t,e);return s>1?0:s<-1?Math.PI:Math.acos(s)}})();function Ai(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}class Ce extends Array{constructor(e=0,r=e,n=e){return super(e,r,n),this}get x(){return this[0]}get y(){return this[1]}get z(){return this[2]}set x(e){this[0]=e}set y(e){this[1]=e}set z(e){this[2]=e}set(e,r=e,n=e){return e.length?this.copy(e):(li(this,e,r,n),this)}copy(e){return rn(this,e),this}add(e,r){return r?yn(this,e,r):yn(this,this,e),this}sub(e,r){return r?vn(this,e,r):vn(this,this,e),this}multiply(e){return e.length?ci(this,this,e):Dr(this,this,e),this}divide(e){return e.length?hi(this,this,e):Dr(this,this,1/e),this}inverse(e=this){return pi(this,e),this}len(){return gr(this)}distance(e){return e?ui(this,e):gr(this)}squaredLen(){return xn(this)}squaredDistance(e){return e?fi(this,e):xn(this)}negate(e=this){return di(this,e),this}cross(e,r){return r?wn(this,e,r):wn(this,this,e),this}scale(e){return Dr(this,this,e),this}normalize(){return nn(this,this),this}dot(e){return Ts(this,e)}equals(e){return Ai(this,e)}applyMatrix3(e){return xi(this,this,e),this}applyMatrix4(e){return yi(this,this,e),this}scaleRotateMatrix4(e){return vi(this,this,e),this}applyQuaternion(e){return wi(this,this,e),this}angle(e){return Mi(this,e)}lerp(e,r){return mi(this,this,e,r),this}smoothLerp(e,r,n){return gi(this,this,e,r,n),this}clone(){return new Ce(this[0],this[1],this[2])}fromArray(e,r=0){return this[0]=e[r],this[1]=e[r+1],this[2]=e[r+2],this}toArray(e=[],r=0){return e[r]=this[0],e[r+1]=this[1],e[r+2]=this[2],e}transformDirection(e){const r=this[0],n=this[1],s=this[2];return this[0]=e[0]*r+e[4]*n+e[8]*s,this[1]=e[1]*r+e[5]*n+e[9]*s,this[2]=e[2]*r+e[6]*n+e[10]*s,this.normalize()}}const Mn=new Ce;let Si=1,bi=1,An=!1;class ot{constructor(e,r={}){e.canvas||console.error("gl not passed as first argument to Geometry"),this.gl=e,this.attributes=r,this.id=Si++,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=bi++,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,f=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*f),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(!An)return console.warn("No position buffer data found to compute bounds"),An=!0}computeBoundingBox(e){e||(e=this.getPosition());const r=e.data,n=e.size;this.bounds||(this.bounds={min:new Ce,max:new Ce,center:new Ce,scale:new Ce,radius:1/0});const s=this.bounds.min,i=this.bounds.max,l=this.bounds.center,o=this.bounds.scale;s.set(1/0),i.set(-1/0);for(let a=0,f=r.length;a<f;a+=n){const g=r[a],m=r[a+1],h=r[a+2];s.x=Math.min(g,s.x),s.y=Math.min(m,s.y),s.z=Math.min(h,s.z),i.x=Math.max(g,i.x),i.y=Math.max(m,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)Mn.fromArray(r,i),s=Math.max(s,this.bounds.center.squaredDistance(Mn));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 _i=1;const Sn={};class Ue{constructor(e,{vertex:r,fragment:n,uniforms:s={},transparent:i=!1,cullFace:l=e.BACK,frontFace:o=e.CCW,depthTest:a=!0,depthWrite:f=!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=_i++,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=f,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
|
+
${bn(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
|
+
${bn(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 _n(`Active uniform ${i.name} has not been supplied`);if(l&&l.value===void 0)return _n(`${i.name} uniform is missing a value parameter`);if(l.value.texture)return r=r+1,l.value.update(r),Ur(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)}),Ur(this.gl,i.type,s,o)}Ur(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 Ur(t,e,r,n){n=n.length?Ci(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(Ei(s,n))return;s.set?s.set(n):Fi(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 bn(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 Ci(t){const e=t.length,r=t[0].length;if(r===void 0)return t;const n=e*r;let s=Sn[n];s||(Sn[n]=s=new Float32Array(n));for(let i=0;i<e;i++)s.set(t[i],i*r);return s}function Ei(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 Fi(t,e){for(let r=0,n=t.length;r<n;r++)t[r]=e[r]}let zr=0;function _n(t){zr>100||(console.warn(t),zr++,zr>100&&console.warn("More than 100 program warnings - stopping logs."))}const Vr=new Ce;let Ti=1;class Pi{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:f=!1,preserveDrawingBuffer:g=!1,powerPreference:m="default",autoClear:h=!0,webgl:v=2}={}){const M={alpha:i,depth:l,stencil:o,antialias:a,premultipliedAlpha:f,preserveDrawingBuffer:g,powerPreference:m};this.dpr=s,this.alpha=i,this.color=!0,this.depth=l,this.stencil=o,this.premultipliedAlpha=f,this.autoClear=h,this.id=Ti++,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(f=>{f.program.transparent?f.program.depthTest?o.push(f):a.push(f):l.push(f),f.zDepth=0,!(f.renderOrder!==0||!f.program.depthTest||!r)&&(f.worldMatrix.getTranslation(Vr),Vr.applyMatrix4(r.projectionViewMatrix),f.zDepth=Vr.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(f=>{f.draw({camera:r})})}}function Ps(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function Rs(t,e,r,n,s){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t}function Ri(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 Bs(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 Ns(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Bi(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function Ni(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 Cn(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=r[0],a=r[1],f=r[2],g=r[3];return t[0]=n*g+l*o+s*f-i*a,t[1]=s*g+l*a+i*o-n*f,t[2]=i*g+l*f+n*a-s*o,t[3]=l*g-n*o-s*a-i*f,t}function Li(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 Ii(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 Oi(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 Di(t,e,r,n){let s=e[0],i=e[1],l=e[2],o=e[3],a=r[0],f=r[1],g=r[2],m=r[3],h,v,M,p,y;return v=s*a+i*f+l*g+o*m,v<0&&(v=-v,a=-a,f=-f,g=-g,m=-m),1-v>1e-6?(h=Math.acos(v),M=Math.sin(h),p=Math.sin((1-n)*h)/M,y=Math.sin(n*h)/M):(p=1-n,y=n),t[0]=p*s+y*a,t[1]=p*i+y*f,t[2]=p*l+y*g,t[3]=p*o+y*m,t}function Ui(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 zi(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function Vi(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 Gi(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 Hi=Ps,ki=Rs,Wi=Ns,$i=Bs;class qt 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 Bi(this._target),this.onChange(),this}set(e,r,n,s){return e.length?this.copy(e):(ki(this._target,e,r,n,s),this.onChange(),this)}rotateX(e){return Li(this._target,this._target,e),this.onChange(),this}rotateY(e){return Ii(this._target,this._target,e),this.onChange(),this}rotateZ(e){return Oi(this._target,this._target,e),this.onChange(),this}inverse(e=this._target){return Ui(this._target,e),this.onChange(),this}conjugate(e=this._target){return zi(this._target,e),this.onChange(),this}copy(e){return Hi(this._target,e),this.onChange(),this}normalize(e=this._target){return $i(this._target,e),this.onChange(),this}multiply(e,r){return r?Cn(this._target,e,r):Cn(this._target,this._target,e),this.onChange(),this}dot(e){return Wi(this._target,e)}fromMatrix3(e){return Vi(this._target,e),this.onChange(),this}fromEuler(e,r){return Gi(this._target,e,e.order),r||this.onChange(),this}fromAxisAngle(e,r){return Ni(this._target,e,r),this.onChange(),this}slerp(e,r){return Di(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 ji=1e-6;function Xi(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 qi(t,e,r,n,s,i,l,o,a,f,g,m,h,v,M,p,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]=f,t[9]=g,t[10]=m,t[11]=h,t[12]=v,t[13]=M,t[14]=p,t[15]=y,t}function Yi(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 Ki(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=e[4],o=e[5],a=e[6],f=e[7],g=e[8],m=e[9],h=e[10],v=e[11],M=e[12],p=e[13],y=e[14],x=e[15],T=r*o-n*l,B=r*a-s*l,F=r*f-i*l,P=n*a-s*o,c=n*f-i*o,u=s*f-i*a,d=g*p-m*M,w=g*y-h*M,S=g*x-v*M,N=m*y-h*p,V=m*x-v*p,L=h*x-v*y,j=T*L-B*V+F*N+P*S-c*w+u*d;return j?(j=1/j,t[0]=(o*L-a*V+f*N)*j,t[1]=(s*V-n*L-i*N)*j,t[2]=(p*u-y*c+x*P)*j,t[3]=(h*c-m*u-v*P)*j,t[4]=(a*S-l*L-f*w)*j,t[5]=(r*L-s*S+i*w)*j,t[6]=(y*F-M*u-x*B)*j,t[7]=(g*u-h*F+v*B)*j,t[8]=(l*V-o*S+f*d)*j,t[9]=(n*S-r*V-i*d)*j,t[10]=(M*c-p*F+x*T)*j,t[11]=(m*F-g*c-v*T)*j,t[12]=(o*w-l*N-a*d)*j,t[13]=(r*N-n*w+s*d)*j,t[14]=(p*B-M*P-y*T)*j,t[15]=(g*P-m*B+h*T)*j,t):null}function Ls(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],f=t[8],g=t[9],m=t[10],h=t[11],v=t[12],M=t[13],p=t[14],y=t[15],x=e*l-r*i,T=e*o-n*i,B=e*a-s*i,F=r*o-n*l,P=r*a-s*l,c=n*a-s*o,u=f*M-g*v,d=f*p-m*v,w=f*y-h*v,S=g*p-m*M,N=g*y-h*M,V=m*y-h*p;return x*V-T*N+B*S+F*w-P*d+c*u}function En(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=e[4],a=e[5],f=e[6],g=e[7],m=e[8],h=e[9],v=e[10],M=e[11],p=e[12],y=e[13],x=e[14],T=e[15],B=r[0],F=r[1],P=r[2],c=r[3];return t[0]=B*n+F*o+P*m+c*p,t[1]=B*s+F*a+P*h+c*y,t[2]=B*i+F*f+P*v+c*x,t[3]=B*l+F*g+P*M+c*T,B=r[4],F=r[5],P=r[6],c=r[7],t[4]=B*n+F*o+P*m+c*p,t[5]=B*s+F*a+P*h+c*y,t[6]=B*i+F*f+P*v+c*x,t[7]=B*l+F*g+P*M+c*T,B=r[8],F=r[9],P=r[10],c=r[11],t[8]=B*n+F*o+P*m+c*p,t[9]=B*s+F*a+P*h+c*y,t[10]=B*i+F*f+P*v+c*x,t[11]=B*l+F*g+P*M+c*T,B=r[12],F=r[13],P=r[14],c=r[15],t[12]=B*n+F*o+P*m+c*p,t[13]=B*s+F*a+P*h+c*y,t[14]=B*i+F*f+P*v+c*x,t[15]=B*l+F*g+P*M+c*T,t}function Qi(t,e,r){let n=r[0],s=r[1],i=r[2],l,o,a,f,g,m,h,v,M,p,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],f=e[3],g=e[4],m=e[5],h=e[6],v=e[7],M=e[8],p=e[9],y=e[10],x=e[11],t[0]=l,t[1]=o,t[2]=a,t[3]=f,t[4]=g,t[5]=m,t[6]=h,t[7]=v,t[8]=M,t[9]=p,t[10]=y,t[11]=x,t[12]=l*n+g*s+M*i+e[12],t[13]=o*n+m*s+p*i+e[13],t[14]=a*n+h*s+y*i+e[14],t[15]=f*n+v*s+x*i+e[15]),t}function Zi(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 Ji(t,e,r,n){let s=n[0],i=n[1],l=n[2],o=Math.hypot(s,i,l),a,f,g,m,h,v,M,p,y,x,T,B,F,P,c,u,d,w,S,N,V,L,j,X;return Math.abs(o)<ji?null:(o=1/o,s*=o,i*=o,l*=o,a=Math.sin(r),f=Math.cos(r),g=1-f,m=e[0],h=e[1],v=e[2],M=e[3],p=e[4],y=e[5],x=e[6],T=e[7],B=e[8],F=e[9],P=e[10],c=e[11],u=s*s*g+f,d=i*s*g+l*a,w=l*s*g-i*a,S=s*i*g-l*a,N=i*i*g+f,V=l*i*g+s*a,L=s*l*g+i*a,j=i*l*g-s*a,X=l*l*g+f,t[0]=m*u+p*d+B*w,t[1]=h*u+y*d+F*w,t[2]=v*u+x*d+P*w,t[3]=M*u+T*d+c*w,t[4]=m*S+p*N+B*V,t[5]=h*S+y*N+F*V,t[6]=v*S+x*N+P*V,t[7]=M*S+T*N+c*V,t[8]=m*L+p*j+B*X,t[9]=h*L+y*j+F*X,t[10]=v*L+x*j+P*X,t[11]=M*L+T*j+c*X,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function eo(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function Is(t,e){let r=e[0],n=e[1],s=e[2],i=e[4],l=e[5],o=e[6],a=e[8],f=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,f,g),t}function to(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],f=t[10];const g=e*e+r*r+n*n,m=s*s+i*i+l*l,h=o*o+a*a+f*f;return Math.sqrt(Math.max(g,m,h))}const Os=(function(){const t=[1,1,1];return function(e,r){let n=t;Is(n,r);let s=1/n[0],i=1/n[1],l=1/n[2],o=r[0]*s,a=r[1]*i,f=r[2]*l,g=r[4]*s,m=r[5]*i,h=r[6]*l,v=r[8]*s,M=r[9]*i,p=r[10]*l,y=o+m+p,x=0;return y>0?(x=Math.sqrt(y+1)*2,e[3]=.25*x,e[0]=(h-M)/x,e[1]=(v-f)/x,e[2]=(a-g)/x):o>m&&o>p?(x=Math.sqrt(1+o-m-p)*2,e[3]=(h-M)/x,e[0]=.25*x,e[1]=(a+g)/x,e[2]=(v+f)/x):m>p?(x=Math.sqrt(1+m-o-p)*2,e[3]=(v-f)/x,e[0]=(a+g)/x,e[1]=.25*x,e[2]=(h+M)/x):(x=Math.sqrt(1+p-o-m)*2,e[3]=(a-g)/x,e[0]=(v+f)/x,e[1]=(h+M)/x,e[2]=.25*x),e}})();function ro(t,e,r,n){let s=gr([t[0],t[1],t[2]]);const i=gr([t[4],t[5],t[6]]),l=gr([t[8],t[9],t[10]]);Ls(t)<0&&(s=-s),r[0]=t[12],r[1]=t[13],r[2]=t[14];const a=t.slice(),f=1/s,g=1/i,m=1/l;a[0]*=f,a[1]*=f,a[2]*=f,a[4]*=g,a[5]*=g,a[6]*=g,a[8]*=m,a[9]*=m,a[10]*=m,Os(e,a),n[0]=s,n[1]=i,n[2]=l}function no(t,e,r,n){const s=t,i=e[0],l=e[1],o=e[2],a=e[3],f=i+i,g=l+l,m=o+o,h=i*f,v=i*g,M=i*m,p=l*g,y=l*m,x=o*m,T=a*f,B=a*g,F=a*m,P=n[0],c=n[1],u=n[2];return s[0]=(1-(p+x))*P,s[1]=(v+F)*P,s[2]=(M-B)*P,s[3]=0,s[4]=(v-F)*c,s[5]=(1-(h+x))*c,s[6]=(y+T)*c,s[7]=0,s[8]=(M+B)*u,s[9]=(y-T)*u,s[10]=(1-(h+p))*u,s[11]=0,s[12]=r[0],s[13]=r[1],s[14]=r[2],s[15]=1,s}function so(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=r+r,o=n+n,a=s+s,f=r*l,g=n*l,m=n*o,h=s*l,v=s*o,M=s*a,p=i*l,y=i*o,x=i*a;return t[0]=1-m-M,t[1]=g+x,t[2]=h-y,t[3]=0,t[4]=g-x,t[5]=1-f-M,t[6]=v+p,t[7]=0,t[8]=h+y,t[9]=v-p,t[10]=1-f-m,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function io(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 oo(t,e,r,n,s,i,l){let o=1/(e-r),a=1/(n-s),f=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*f,t[11]=0,t[12]=(e+r)*o,t[13]=(s+n)*a,t[14]=(l+i)*f,t[15]=1,t}function ao(t,e,r,n){let s=e[0],i=e[1],l=e[2],o=n[0],a=n[1],f=n[2],g=s-r[0],m=i-r[1],h=l-r[2],v=g*g+m*m+h*h;v===0?h=1:(v=1/Math.sqrt(v),g*=v,m*=v,h*=v);let M=a*h-f*m,p=f*g-o*h,y=o*m-a*g;return v=M*M+p*p+y*y,v===0&&(f?o+=1e-6:a?f+=1e-6:a+=1e-6,M=a*h-f*m,p=f*g-o*h,y=o*m-a*g,v=M*M+p*p+y*y),v=1/Math.sqrt(v),M*=v,p*=v,y*=v,t[0]=M,t[1]=p,t[2]=y,t[3]=0,t[4]=m*y-h*p,t[5]=h*M-g*y,t[6]=g*p-m*M,t[7]=0,t[8]=g,t[9]=m,t[10]=h,t[11]=0,t[12]=s,t[13]=i,t[14]=l,t[15]=1,t}function Fn(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 Tn(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 lo(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 pt extends Array{constructor(e=1,r=0,n=0,s=0,i=0,l=1,o=0,a=0,f=0,g=0,m=1,h=0,v=0,M=0,p=0,y=1){return super(e,r,n,s,i,l,o,a,f,g,m,h,v,M,p,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,f,g,m,h,v,M,p,y){return e.length?this.copy(e):(qi(this,e,r,n,s,i,l,o,a,f,g,m,h,v,M,p,y),this)}translate(e,r=this){return Qi(this,r,e),this}rotate(e,r,n=this){return Ji(this,n,e,r),this}scale(e,r=this){return Zi(this,r,typeof e=="number"?[e,e,e]:e),this}add(e,r){return r?Fn(this,e,r):Fn(this,this,e),this}sub(e,r){return r?Tn(this,e,r):Tn(this,this,e),this}multiply(e,r){return e.length?r?En(this,e,r):En(this,this,e):lo(this,this,e),this}identity(){return Yi(this),this}copy(e){return Xi(this,e),this}fromPerspective({fov:e,aspect:r,near:n,far:s}={}){return io(this,e,r,n,s),this}fromOrthogonal({left:e,right:r,bottom:n,top:s,near:i,far:l}){return oo(this,e,r,n,s,i,l),this}fromQuaternion(e){return so(this,e),this}setPosition(e){return this.x=e[0],this.y=e[1],this.z=e[2],this}inverse(e=this){return Ki(this,e),this}compose(e,r,n){return no(this,e,r,n),this}decompose(e,r,n){return ro(this,e,r,n),this}getRotation(e){return Os(e,this),this}getTranslation(e){return eo(e,this),this}getScaling(e){return Is(e,this),this}getMaxScaleOnAxis(){return to(this)}lookAt(e,r,n){return ao(this,e,r,n),this}determinant(){return Ls(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 co(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 Pn=new pt;class ho 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 co(this._target,e,r),this.onChange(),this}fromQuaternion(e,r=this.order,n){return Pn.fromQuaternion(e),this._target.fromRotationMatrix(Pn,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 ct{constructor(){this.parent=null,this.children=[],this.visible=!0,this.matrix=new pt,this.worldMatrix=new pt,this.matrixAutoUpdate=!0,this.worldMatrixNeedsUpdate=!1,this.position=new Ce,this.quaternion=new qt,this.scale=new Ce(1),this.rotation=new ho,this.up=new Ce(0,1,0),this.rotation._target.onChange=()=>this.quaternion.fromEuler(this.rotation,!0),this.quaternion._target.onChange=()=>this.rotation.fromQuaternion(this.quaternion,void 0,!0)}setParent(e,r=!0){this.parent&&e!==this.parent&&this.parent.removeChild(this,!1),this.parent=e,r&&e&&e.addChild(this,!1)}addChild(e,r=!0){~this.children.indexOf(e)||this.children.push(e),r&&e.setParent(this,!1)}removeChild(e,r=!0){~this.children.indexOf(e)&&this.children.splice(this.children.indexOf(e),1),r&&e.setParent(null,!1)}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.worldMatrixNeedsUpdate||e)&&(this.parent===null?this.worldMatrix.copy(this.matrix):this.worldMatrix.multiply(this.parent.worldMatrix,this.matrix),this.worldMatrixNeedsUpdate=!1,e=!0);for(let r=0,n=this.children.length;r<n;r++)this.children[r].updateMatrixWorld(e)}updateMatrix(){this.matrix.compose(this.quaternion,this.position,this.scale),this.worldMatrixNeedsUpdate=!0}traverse(e){if(!e(this))for(let r=0,n=this.children.length;r<n;r++)this.children[r].traverse(e)}decompose(){this.matrix.decompose(this.quaternion._target,this.position,this.scale),this.rotation.fromQuaternion(this.quaternion)}lookAt(e,r=!1){r?this.matrix.lookAt(this.position,e,this.up):this.matrix.lookAt(e,this.position,this.up),this.matrix.getRotation(this.quaternion._target),this.rotation.fromQuaternion(this.quaternion)}}const uo=new pt,fo=new Ce,po=new Ce;class ln extends ct{constructor(e,{near:r=.1,far:n=100,fov:s=45,aspect:i=1,left:l,right:o,bottom:a,top:f,zoom:g=1}={}){super(),Object.assign(this,{near:r,far:n,fov:s,aspect:i,left:l,right:o,bottom:a,top:f,zoom:g}),this.projectionMatrix=new pt,this.viewMatrix=new pt,this.projectionViewMatrix=new pt,this.worldPosition=new Ce,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(uo.inverse(this.projectionMatrix)),e.applyMatrix4(this.worldMatrix),this}updateFrustum(){this.frustum||(this.frustum=[new Ce,new Ce,new Ce,new Ce,new Ce,new Ce]);const e=this.projectionViewMatrix;this.frustum[0].set(e[3]-e[0],e[7]-e[4],e[11]-e[8]).constant=e[15]-e[12],this.frustum[1].set(e[3]+e[0],e[7]+e[4],e[11]+e[8]).constant=e[15]+e[12],this.frustum[2].set(e[3]+e[1],e[7]+e[5],e[11]+e[9]).constant=e[15]+e[13],this.frustum[3].set(e[3]-e[1],e[7]-e[5],e[11]-e[9]).constant=e[15]-e[13],this.frustum[4].set(e[3]-e[2],e[7]-e[6],e[11]-e[10]).constant=e[15]-e[14],this.frustum[5].set(e[3]+e[2],e[7]+e[6],e[11]+e[10]).constant=e[15]+e[14];for(let r=0;r<6;r++){const n=1/this.frustum[r].distance();this.frustum[r].multiply(n),this.frustum[r].constant*=n}}frustumIntersectsMesh(e,r=e.worldMatrix){if(!e.geometry.attributes.position||((!e.geometry.bounds||e.geometry.bounds.radius===1/0)&&e.geometry.computeBoundingSphere(),!e.geometry.bounds))return!0;const n=fo;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=po;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 mo(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 go(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=r+r,o=n+n,a=s+s,f=r*l,g=n*l,m=n*o,h=s*l,v=s*o,M=s*a,p=i*l,y=i*o,x=i*a;return t[0]=1-m-M,t[3]=g-x,t[6]=h+y,t[1]=g+x,t[4]=1-f-M,t[7]=v-p,t[2]=h-y,t[5]=v+p,t[8]=1-f-m,t}function yo(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function vo(t,e,r,n,s,i,l,o,a,f){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]=f,t}function xo(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 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],f=e[7],g=e[8],m=g*l-o*f,h=-g*i+o*a,v=f*i-l*a,M=r*m+n*h+s*v;return M?(M=1/M,t[0]=m*M,t[1]=(-g*n+s*f)*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]=(-f*r+n*a)*M,t[8]=(l*r-n*i)*M,t):null}function Rn(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=e[4],a=e[5],f=e[6],g=e[7],m=e[8],h=r[0],v=r[1],M=r[2],p=r[3],y=r[4],x=r[5],T=r[6],B=r[7],F=r[8];return t[0]=h*n+v*l+M*f,t[1]=h*s+v*o+M*g,t[2]=h*i+v*a+M*m,t[3]=p*n+y*l+x*f,t[4]=p*s+y*o+x*g,t[5]=p*i+y*a+x*m,t[6]=T*n+B*l+F*f,t[7]=T*s+B*o+F*g,t[8]=T*i+B*a+F*m,t}function Mo(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=e[4],a=e[5],f=e[6],g=e[7],m=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+f,t[7]=h*s+v*o+g,t[8]=h*i+v*a+m,t}function Ao(t,e,r){let n=e[0],s=e[1],i=e[2],l=e[3],o=e[4],a=e[5],f=e[6],g=e[7],m=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]=f,t[7]=g,t[8]=m,t}function So(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 bo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],l=e[4],o=e[5],a=e[6],f=e[7],g=e[8],m=e[9],h=e[10],v=e[11],M=e[12],p=e[13],y=e[14],x=e[15],T=r*o-n*l,B=r*a-s*l,F=r*f-i*l,P=n*a-s*o,c=n*f-i*o,u=s*f-i*a,d=g*p-m*M,w=g*y-h*M,S=g*x-v*M,N=m*y-h*p,V=m*x-v*p,L=h*x-v*y,j=T*L-B*V+F*N+P*S-c*w+u*d;return j?(j=1/j,t[0]=(o*L-a*V+f*N)*j,t[1]=(a*S-l*L-f*w)*j,t[2]=(l*V-o*S+f*d)*j,t[3]=(s*V-n*L-i*N)*j,t[4]=(r*L-s*S+i*w)*j,t[5]=(n*S-r*V-i*d)*j,t[6]=(p*u-y*c+x*P)*j,t[7]=(y*F-M*u-x*B)*j,t[8]=(M*c-p*F+x*T)*j,t):null}class _o extends Array{constructor(e=1,r=0,n=0,s=0,i=1,l=0,o=0,a=0,f=1){return super(e,r,n,s,i,l,o,a,f),this}set(e,r,n,s,i,l,o,a,f){return e.length?this.copy(e):(vo(this,e,r,n,s,i,l,o,a,f),this)}translate(e,r=this){return Mo(this,r,e),this}rotate(e,r=this){return Ao(this,r,e),this}scale(e,r=this){return So(this,r,e),this}multiply(e,r){return r?Rn(this,e,r):Rn(this,this,e),this}identity(){return xo(this),this}copy(e){return yo(this,e),this}fromMatrix4(e){return mo(this,e),this}fromQuaternion(e){return go(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 wo(this,e),this}getNormalMatrix(e){return bo(this,e),this}}let Co=0;class Je extends ct{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=Co++,this.geometry=r,this.program=n,this.mode=s,this.frustumCulled=i,this.renderOrder=l,this.modelViewMatrix=new pt,this.normalMatrix=new _o,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 Bn=new Uint8Array(4);function Nn(t){return(t&t-1)===0}let Eo=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:f=e.CLAMP_TO_EDGE,generateMipmaps:g=n===(e.TEXTURE_2D||e.TEXTURE_CUBE_MAP),minFilter:m=g?e.NEAREST_MIPMAP_LINEAR:e.LINEAR,magFilter:h=e.LINEAR,premultiplyAlpha:v=!1,unpackAlignment:M=4,flipY:p=n==(e.TEXTURE_2D||e.TEXTURE_3D),anisotropy:y=0,level:x=0,width:T,height:B=T,length:F=1}={}){this.gl=e,this.id=Eo++,this.image=r,this.target=n,this.type=s,this.format=i,this.internalFormat=l,this.minFilter=m,this.magFilter=h,this.wrapS=o,this.wrapT=a,this.wrapR=f,this.generateMipmaps=g,this.premultiplyAlpha=v,this.unpackAlignment=M,this.flipY=p,this.anisotropy=Math.min(y,this.gl.renderer.parameters.maxAnisotropy),this.level=x,this.width=T,this.height=B,this.length=F,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&&(!Nn(this.image.width)||!Nn(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,Bn);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,Bn);this.store.image=this.image}}}class Ds{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:f=e.CLAMP_TO_EDGE,wrapT:g=e.CLAMP_TO_EDGE,wrapR:m=e.CLAMP_TO_EDGE,minFilter:h=e.LINEAR,magFilter:v=h,type:M=e.UNSIGNED_BYTE,format:p=e.RGBA,internalFormat:y=p,unpackAlignment:x,premultiplyAlpha:T}={}){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 B=[];for(let F=0;F<i;F++)this.textures.push(new je(e,{width:r,height:n,wrapS:f,wrapT:g,wrapR:m,minFilter:h,magFilter:v,type:M,format:p,internalFormat:y,unpackAlignment:x,premultiplyAlpha:T,flipY:!1,generateMipmaps:!1})),this.textures[F].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+F,this.gl.TEXTURE_2D,this.textures[F].texture,0),B.push(this.gl.COLOR_ATTACHMENT0+F);B.length>1&&this.gl.renderer.drawBuffers(B),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 Fo(t,e){return t[0]=e[0],t[1]=e[1],t}function To(t,e,r){return t[0]=e,t[1]=r,t}function Ln(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t}function In(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t}function Po(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t}function Ro(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t}function Gr(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t}function Bo(t,e){var r=e[0]-t[0],n=e[1]-t[1];return Math.sqrt(r*r+n*n)}function No(t,e){var r=e[0]-t[0],n=e[1]-t[1];return r*r+n*n}function On(t){var e=t[0],r=t[1];return Math.sqrt(e*e+r*r)}function Lo(t){var e=t[0],r=t[1];return e*e+r*r}function Io(t,e){return t[0]=-e[0],t[1]=-e[1],t}function Oo(t,e){return t[0]=1/e[0],t[1]=1/e[1],t}function Do(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 Uo(t,e){return t[0]*e[0]+t[1]*e[1]}function Dn(t,e){return t[0]*e[1]-t[1]*e[0]}function zo(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 Vo(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 Go(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 Ho(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 ko(t,e){return t[0]===e[0]&&t[1]===e[1]}class ur 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):(To(this,e,r),this)}copy(e){return Fo(this,e),this}add(e,r){return r?Ln(this,e,r):Ln(this,this,e),this}sub(e,r){return r?In(this,e,r):In(this,this,e),this}multiply(e){return e.length?Po(this,this,e):Gr(this,this,e),this}divide(e){return e.length?Ro(this,this,e):Gr(this,this,1/e),this}inverse(e=this){return Oo(this,e),this}len(){return On(this)}distance(e){return e?Bo(this,e):On(this)}squaredLen(){return this.squaredDistance()}squaredDistance(e){return e?No(this,e):Lo(this)}negate(e=this){return Io(this,e),this}cross(e,r){return r?Dn(e,r):Dn(this,e)}scale(e){return Gr(this,this,e),this}normalize(){return Do(this,this),this}dot(e){return Uo(this,e)}equals(e){return ko(this,e)}applyMatrix3(e){return Go(this,this,e),this}applyMatrix4(e){return Ho(this,this,e),this}lerp(e,r){return zo(this,this,e,r),this}smoothLerp(e,r,n){return Vo(this,this,e,r,n),this}clone(){return new ur(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 Wo 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):(Rs(this,e,r,n,s),this)}copy(e){return Ps(this,e),this}normalize(){return Bs(this,this),this}multiply(e){return Ri(this,this,e),this}dot(e){return Ns(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 It extends ot{constructor(e,{width:r=1,height:n=1,widthSegments:s=1,heightSegments:i=1,attributes:l={}}={}){const o=s,a=i,f=(o+1)*(a+1),g=o*a*6,m=new Float32Array(f*3),h=new Float32Array(f*3),v=new Float32Array(f*2),M=g>65536?new Uint32Array(g):new Uint16Array(g);It.buildPlane(m,h,v,M,r,n,0,o,a),Object.assign(l,{position:{size:3,data:m},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,f,g=0,m=1,h=2,v=1,M=-1,p=0,y=0){const x=p,T=i/a,B=l/f;for(let F=0;F<=f;F++){let P=F*B-l/2;for(let c=0;c<=a;c++,p++){let u=c*T-i/2;if(e[p*3+g]=u*v,e[p*3+m]=P*M,e[p*3+h]=o/2,r[p*3+g]=0,r[p*3+m]=0,r[p*3+h]=o>=0?1:-1,n[p*2]=c/a,n[p*2+1]=1-F/f,F===f||c===a)continue;let d=x+c+F*(a+1),w=x+c+(F+1)*(a+1),S=x+c+(F+1)*(a+1)+1,N=x+c+F*(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 Un extends ot{constructor(e,{width:r=1,height:n=1,depth:s=1,widthSegments:i=1,heightSegments:l=1,depthSegments:o=1,attributes:a={}}={}){const f=i,g=l,m=o,h=(f+1)*(g+1)*2+(f+1)*(m+1)*2+(g+1)*(m+1)*2,v=(f*g*2+f*m*2+g*m*2)*6,M=new Float32Array(h*3),p=new Float32Array(h*3),y=new Float32Array(h*2),x=h>65536?new Uint32Array(v):new Uint16Array(v);let T=0,B=0;It.buildPlane(M,p,y,x,s,n,r,m,g,2,1,0,-1,-1,T,B),T+=(m+1)*(g+1),B+=m*g,It.buildPlane(M,p,y,x,s,n,-r,m,g,2,1,0,1,-1,T,B),T+=(m+1)*(g+1),B+=m*g,It.buildPlane(M,p,y,x,r,s,n,m,f,0,2,1,1,1,T,B),T+=(f+1)*(m+1),B+=f*m,It.buildPlane(M,p,y,x,r,s,-n,m,f,0,2,1,1,-1,T,B),T+=(f+1)*(m+1),B+=f*m,It.buildPlane(M,p,y,x,r,n,-s,f,g,0,1,2,-1,-1,T,B),T+=(f+1)*(g+1),B+=f*g,It.buildPlane(M,p,y,x,r,n,s,f,g,0,1,2,1,-1,T,B),Object.assign(a,{position:{size:3,data:M},normal:{size:3,data:p},uv:{size:2,data:y},index:{data:x}}),super(e,a)}}class zn extends ot{constructor(e,{radiusTop:r=.5,radiusBottom:n=.5,height:s=1,radialSegments:i=8,heightSegments:l=1,openEnded:o=!1,thetaStart:a=0,thetaLength:f=Math.PI*2,attributes:g={}}={}){const m=i,h=l,v=a,M=f,p=o?0:n&&r?2:1,y=(m+1)*(h+1+p)+p,x=m*h*6+p*m*3,T=new Float32Array(y*3),B=new Float32Array(y*3),F=new Float32Array(y*2),P=y>65536?new Uint32Array(x):new Uint16Array(x);let c=0,u=0;const d=[];w(),o||(r&&S(!0),n&&S(!1));function w(){let N,V;const L=new Ce,j=(n-r)/s;for(V=0;V<=h;V++){const X=[],oe=V/h,Y=oe*(n-r)+r;for(N=0;N<=m;N++){const I=N/m,$=I*M+v,G=Math.sin($),q=Math.cos($);T.set([Y*G,(.5-oe)*s,Y*q],c*3),L.set(G,j,q).normalize(),B.set([L.x,L.y,L.z],c*3),F.set([I,1-oe],c*2),X.push(c++)}d.push(X)}for(N=0;N<m;N++)for(V=0;V<h;V++){const X=d[V][N],oe=d[V+1][N],Y=d[V+1][N+1],I=d[V][N+1];P.set([X,oe,I,oe,Y,I],u*3),u+=2}}function S(N){let V;const L=N===!0?r:n,j=N===!0?1:-1,X=c;for(T.set([0,.5*s*j,0],c*3),B.set([0,j,0],c*3),F.set([.5,.5],c*2),c++,V=0;V<=m;V++){const Y=V/m*M+v,I=Math.cos(Y),$=Math.sin(Y);T.set([L*$,.5*s*j,L*I],c*3),B.set([0,j,0],c*3),F.set([I*.5+.5,$*.5*j+.5],c*2),c++}for(V=0;V<m;V++){const oe=X+V+1;N?P.set([oe,oe+1,X],u*3):P.set([oe+1,oe,X],u*3),u++}}Object.assign(g,{position:{size:3,data:T},normal:{size:3,data:B},uv:{size:2,data:F},index:{data:P}}),super(e,g)}}class $o extends ot{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 jo extends ot{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),f=s*i*6,g=new Float32Array(a*3),m=new Float32Array(a*3),h=new Float32Array(a*2),v=a>65536?new Uint32Array(f):new Uint16Array(f),M=new Ce,p=new Ce,y=new Ce;let x=0;for(let T=0;T<=s;T++)for(let B=0;B<=i;B++,x++){const F=B/i*l,P=T/s*Math.PI*2;p.x=(r+n*Math.cos(P))*Math.cos(F),p.y=(r+n*Math.cos(P))*Math.sin(F),p.z=n*Math.sin(P),g.set([p.x,p.y,p.z],x*3),M.x=r*Math.cos(F),M.y=r*Math.sin(F),y.sub(p,M).normalize(),m.set([y.x,y.y,y.z],x*3),h.set([B/i,T/s],x*2)}x=0;for(let T=1;T<=s;T++)for(let B=1;B<=i;B++,x++){const F=(i+1)*T+B-1,P=(i+1)*(T-1)+B-1,c=(i+1)*(T-1)+B,u=(i+1)*T+B;v.set([F,P,u,P,c,u],x*6)}Object.assign(o,{position:{size:3,data:g},normal:{size:3,data:m},uv:{size:2,data:h},index:{data:v}}),super(e,o)}}const Xo=new ur,qo=new ur,Yo=new ur,Hr=new Ce,Vn=new Ce,Gn=new Ce,Ko=new Ce,Qo=new Ce,Zo=new Ce,Hn=new Ce,kr=new Ce,kn=new Ce,Wn=new Ce,Jo=new Ce,$n=new pt;class ea{constructor(){this.origin=new Ce,this.direction=new Ce}castMouse(e,r=[0,0]){if(e.type==="orthographic"){const{left:n,right:s,bottom:i,top:l,zoom:o}=e,a=n/o+(s-n)/o*(r[0]*.5+.5),f=i/o+(l-i)/o*(r[1]*.5+.5);this.origin.set(a,f,0),this.origin.applyMatrix4(e.worldMatrix),this.direction.x=-e.worldMatrix[8],this.direction.y=-e.worldMatrix[9],this.direction.z=-e.worldMatrix[10]}else e.worldMatrix.getTranslation(this.origin),this.direction.set(r[0],r[1],.5),e.unproject(this.direction),this.direction.sub(this.origin).normalize()}intersectBounds(e,{maxDistance:r,output:n=[]}={}){Array.isArray(e)||(e=[e]);const s=$n,i=Hr,l=Vn,o=n;return o.length=0,e.forEach(a=>{(!a.geometry.bounds||a.geometry.bounds.radius===1/0)&&a.geometry.computeBoundingSphere();const f=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(f.center)-f.radius>g)return;let m=0;if(a.geometry.raycast==="sphere"){if(i.distance(f.center)>f.radius&&(m=this.intersectSphere(f,i,l),!m))return}else if((i.x<f.min.x||i.x>f.max.x||i.y<f.min.y||i.y>f.max.y||i.z<f.min.z||i.z>f.max.z)&&(m=this.intersectBox(f,i,l),!m))return;r&&m>g||(a.hit||(a.hit={localPoint:new Ce,point:new Ce}),a.hit.localPoint.copy(l).multiply(m).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,f)=>a.hit.distance-f.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=$n,f=Hr,g=Vn,m=Gn,h=Ko,v=Qo,M=Zo,p=Hn,y=kr,x=Xo,T=qo,B=Yo;for(let F=o.length-1;F>=0;F--){const P=o[F];a.inverse(P.worldMatrix);let c;n&&(g.copy(this.direction).scaleRotateMatrix4(a),c=n*g.len()),f.copy(this.origin).applyMatrix4(a),g.copy(this.direction).transformDirection(a);let u=0,d,w,S;const N=P.geometry,V=N.attributes,L=V.index,j=V.position,X=Math.max(0,N.drawRange.start),oe=Math.min(L?L.count:j.count,N.drawRange.start+N.drawRange.count),Y=j.size;for(let I=X;I<oe;I+=3){const $=L?L.data[I]:I,G=L?L.data[I+1]:I+1,q=L?L.data[I+2]:I+2;m.fromArray(j.data,$*Y),h.fromArray(j.data,G*Y),v.fromArray(j.data,q*Y);const ae=this.intersectTriangle(m,h,v,r,f,g,p);ae&&(n&&ae>c||(!u||ae<u)&&(u=ae,d=$,w=G,S=q,M.copy(p)))}u||o.splice(F,1),P.hit.localPoint.copy(g).multiply(u).add(f),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 Ce,P.hit.faceNormal=new Ce,P.hit.uv=new ur,P.hit.localNormal=new Ce,P.hit.normal=new Ce),P.hit.localFaceNormal.copy(M),P.hit.faceNormal.copy(P.hit.localFaceNormal).transformDirection(P.worldMatrix),(s||i)&&(m.fromArray(j.data,d*3),h.fromArray(j.data,w*3),v.fromArray(j.data,S*3),this.getBarycoord(P.hit.localPoint,m,h,v,y)),s&&V.uv&&(x.fromArray(V.uv.data,d*2),T.fromArray(V.uv.data,w*2),B.fromArray(V.uv.data,S*2),P.hit.uv.set(x.x*y.x+T.x*y.y+B.x*y.z,x.y*y.x+T.y*y.y+B.y*y.z)),i&&V.normal&&(m.fromArray(V.normal.data,d*3),h.fromArray(V.normal.data,w*3),v.fromArray(V.normal.data,S*3),P.hit.localNormal.set(m.x*y.x+h.x*y.y+v.x*y.z,m.y*y.x+h.y*y.y+v.y*y.z,m.z*y.x+h.z*y.y+v.z*y.z),P.hit.normal.copy(P.hit.localNormal).transformDirection(P.worldMatrix))}return o.sort((F,P)=>F.hit.distance-P.hit.distance),o}intersectPlane(e,r=this.origin,n=this.direction){const s=Hr;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=Gn;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),f=i-a,g=i+a;return f<0&&g<0?0:f<0?g:f}intersectBox(e,r=this.origin,n=this.direction){let s,i,l,o,a,f;const g=1/n.x,m=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=((m>=0?v.y:M.y)-r.y)*m,o=((m>=0?M.y:v.y)-r.y)*m,s>o||l>i||(l>s&&(s=l),o<i&&(i=o),a=((h>=0?v.z:M.z)-r.z)*h,f=((h>=0?M.z:v.z)-r.z)*h,s>f||a>i)||(a>s&&(s=a),f<i&&(i=f),i<0)?0:s>=0?s:i}intersectTriangle(e,r,n,s=!0,i=this.origin,l=this.direction,o=Hn){const a=kr,f=kn,g=Wn;a.sub(r,e),f.sub(n,e),o.cross(a,f);let m=l.dot(o);if(!m)return 0;let h;if(m>0){if(s)return 0;h=1}else h=-1,m=-m;g.sub(i,e);let v=h*l.dot(f.cross(g,f));if(v<0)return 0;let M=h*l.dot(a.cross(g));if(M<0||v+M>m)return 0;let p=-h*g.dot(o);return p<0?0:p/m}getBarycoord(e,r,n,s,i=kr){const l=kn,o=Wn,a=Jo;l.sub(s,r),o.sub(n,r),a.sub(e,r);const f=l.dot(l),g=l.dot(o),m=l.dot(a),h=o.dot(o),v=o.dot(a),M=f*h-g*g;if(M===0)return i.set(-2,-1,-1);const p=1/M,y=(h*m-g*v)*p,x=(f*v-g*m)*p;return i.set(1-y-x,x,y)}}const ta=`
|
|
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
|
+
`,ra=`
|
|
26
|
+
precision highp float;
|
|
27
|
+
precision highp int;
|
|
28
|
+
|
|
29
|
+
varying vec3 vNormal;
|
|
30
|
+
|
|
31
|
+
void main() {
|
|
32
|
+
gl_FragColor.rgb = normalize(vNormal);
|
|
33
|
+
gl_FragColor.a = 1.0;
|
|
34
|
+
}
|
|
35
|
+
`;function na(t){return new Ue(t,{vertex:ta,fragment:ra,cullFace:!1})}const jn=new Ce,sa=new Ce,ia=new Ce,oa=new Ce,Xn=new qt,aa=new qt,la=new qt,ca=new qt;class ha{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:f})=>{if(!this.duration){let T=jn,B=3;l==="quaternion"&&(T=Xn,B=4),T.fromArray(f,0),B===4?i[l].slerp(T,n):i[l].lerp(T,n);return}const g=Math.max(1,a.findIndex(T=>T>s))-1,m=g+1;let h=(s-a[g])/(a[m]-a[g]);o==="STEP"&&(h=0);let v=jn,M=sa,p=ia,y=oa,x=3;l==="quaternion"&&(v=Xn,M=aa,p=la,y=ca,x=4),o==="CUBICSPLINE"?(v.fromArray(f,g*x*3+x*1),M.fromArray(f,g*x*3+x*2),p.fromArray(f,m*x*3+x*0),y.fromArray(f,m*x*3+x*1),v=this.cubicSplineInterpolate(h,v,M,p,y),x===4&&v.normalize()):(v.fromArray(f,g*x),y.fromArray(f,m*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,f=o-l,g=1-a,m=f-l+e;for(let h=0;h<r.length;h++)r[h]=g*r[h]+m*(1-e)*n[h]+a*i[h]+f*e*s[h];return r}}const qn=new pt,ua=new pt;class Mt extends Je{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)=>{qn.multiply(e.worldMatrix,e.bindInverse),this.boneMatrices.set(qn,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=ua,super.draw({camera:e}),this.worldMatrix=r}}class fa extends Je{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 ct;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 Wo().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 Yn={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array,"image/jpeg":Uint8Array,"image/png":Uint8Array,"image/webp":Uint8Array},da={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Kn={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},pa={translation:"position",rotation:"quaternion",scale:"scale"};class Qn{static setDracoManager(e){this.dracoManager=e}static setBasisManager(e){this.basisManager=e}static async load(e,r){const n=r.split("/").slice(0,-1).join("/")+"/",s=await this.parseDesc(r);return this.parse(e,s,n)}static async parse(e,r,n){var x,T;(r.asset===void 0||r.asset.version[0]<2)&&console.warn("Only GLTF >=2.0 supported. Attempting to parse."),(x=r.extensionsRequired)!=null&&x.includes("KHR_draco_mesh_compression")&&!this.dracoManager&&console.warn("KHR_draco_mesh_compression extension required but no manager supplied. Use .setDracoManager()"),(T=r.extensionsRequired)!=null&&T.includes("KHR_texture_basisu")&&!this.basisManager&&console.warn("KHR_texture_basisu extension required but no manager supplied. Use .setBasisManager()");const s=await this.loadBuffers(r,n);e.renderer.bindVertexArray(null);const i=this.parseBufferViews(e,r,s),l=await this.parseImages(e,r,n,i),o=this.parseTextures(e,r,l),a=this.parseMaterials(e,r,o),f=this.parseSkins(e,r,i),g=await this.parseMeshes(e,r,i,a,f),[m,h]=this.parseNodes(e,r,g,f,l);this.populateSkins(f,m);const v=this.parseAnimations(e,r,m,i),M=this.parseScenes(r,m),p=M[r.scene],y=this.parseLights(e,r,m,M);for(let B=m.length;B>=0;B--)m[B]||m.splice(B,1);return{json:r,buffers:s,bufferViews:i,cameras:h,images:l,textures:o,materials:a,meshes:g,nodes:m,lights:y,animations:v,scenes:M,scene:p}}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 f=s+i+8,g=a[0],m=e.slice(f,f+g);return o.buffers[0].binary=m,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 f in l){const g=r.accessors[l[f]];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 f=r.accessors[o];f.bufferView===void 0&&a&&a.KHR_draco_mesh_compression&&(f.bufferView=a.KHR_draco_mesh_compression.bufferView,s[f.bufferView].isDraco=!0),s[f.bufferView].isAttribute=!0,s[f.bufferView].target=e.ELEMENT_ARRAY_BUFFER}})}),r.accessors.forEach(({bufferView:i,componentType:l})=>{i!==void 0&&(s[i].componentType=l)}),r.images&&r.images.forEach(({uri:i,bufferView:l,mimeType:o})=>{l!==void 0&&(s[l].mimeType=o)}),s.forEach(({buffer:i,byteOffset:l=0,byteLength:o,byteStride:a,target:f=e.ARRAY_BUFFER,name:g,extensions:m,extras:h,componentType:v,mimeType:M,isAttribute:p,isDraco:y},x)=>{if(s[x].data=n[i].slice(l,l+o),!p||y)return;const T=e.createBuffer();e.bindBuffer(f,T),e.renderer.state.boundBuffer=T,e.bufferData(f,s[x].data,e.STATIC_DRAW),s[x].buffer=T}),s}static parseImages(e,r,n,s){return r.images?Promise.all(r.images.map(async({uri:i,bufferView:l,mimeType:o,name:a})=>{if(o==="image/ktx2"){const{data:g}=s[l];return await this.basisManager.parseTexture(g)}const f=new Image;if(f.name=a,i)f.src=this.resolveURI(i,n);else if(l!==void 0){const{data:g}=s[l],m=new Blob([g],{type:o});f.src=URL.createObjectURL(m)}return f.ready=new Promise(g=>{f.onload=()=>g()}),f})):null}static parseTextures(e,r,n){return r.textures?r.textures.map(s=>this.createTexture(e,r,n,s)):null}static createTexture(e,r,n,{sampler:s,source:i,name:l,extensions: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 f=n[i];if(f.texture)return f.texture;const g={flipY:!1,wrapS:e.REPEAT,wrapT:e.REPEAT},m=s!==void 0?r.samplers[s]:null;if(m&&["magFilter","minFilter","wrapS","wrapT"].forEach(v=>{m[v]&&(g[v]=m[v])}),f.isBasis){g.image=f,g.internalFormat=f.internalFormat,f.isCompressedTexture&&(g.generateMipmaps=!1,f.length>1&&(this.minFilter=e.NEAREST_MIPMAP_LINEAR));const v=new je(e,g);return v.name=l,f.texture=v,v}const h=new je(e,g);return h.name=l,f.texture=h,f.ready.then(()=>{h.image=f}),h}static parseMaterials(e,r,n){return r.materials?r.materials.map(({name:s,extensions:i,extras:l,pbrMetallicRoughness:o={},normalTexture:a,occlusionTexture:f,emissiveTexture:g,emissiveFactor:m=[0,0,0],alphaMode:h="OPAQUE",alphaCutoff:v=.5,doubleSided:M=!1})=>{const{baseColorFactor:p=[1,1,1,1],baseColorTexture:y,metallicFactor:x=1,roughnessFactor:T=1,metallicRoughnessTexture:B}=o;return y&&(y.texture=n[y.index]),a&&(a.texture=n[a.index]),B&&(B.texture=n[B.index]),f&&(f.texture=n[f.index]),g&&(g.texture=n[g.index]),{name:s,extensions:i,extras:l,baseColorFactor:p,baseColorTexture:y,metallicFactor:x,roughnessFactor:T,metallicRoughnessTexture:B,normalTexture:a,occlusionTexture:f,emissiveTexture:g,emissiveFactor:m,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:f,extras:g={}},m)=>{let h=0,v=[],M=!1;return r.nodes&&r.nodes.forEach(({mesh:y,skin:x,extras:T})=>{y===m&&(h++,x!==void 0&&v.push(x),T&&T.lightmap_scale_offset&&(M=!0))}),!!v.length?(l=await Promise.all(v.map(async y=>(await this.parsePrimitives(e,l,r,n,s,1,M)).map(({geometry:x,program:T,mode:B})=>{const F=new Mt(e,{skeleton:i[y],geometry:x,program:T,mode:B});return F.name=a,F.extras=g,f&&(F.extensions=f),F.frustumCulled=!1,F}))),l.instanceCount=0,l.numInstances=h):l=(await this.parsePrimitives(e,l,r,n,s,h,M)).map(({geometry:y,program:x,mode:T})=>{const B=y.attributes.instanceMatrix?fa:Je,F=new B(e,{geometry:y,program:x,mode:T});return F.name=a,F.extras=g,f&&(F.extensions=f),F.numInstances=h,F}),{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:f,material:g,mode:m=4,targets:h,extensions:v,extras:M})=>{const p=new na(e);g!==void 0&&(p.gltfMaterial=i[g]);const y=new ot(e);if(M&&(y.extras=M),v&&(y.extensions=v),v&&v.KHR_draco_mesh_compression){const x=v.KHR_draco_mesh_compression.bufferView,T=v.KHR_draco_mesh_compression.attributes,B={},F={},P={},c={};for(const w in a){const S=n.accessors[a[w]],N=Kn[w];B[N]=T[w],F[N]=S.componentType,P[N]=Yn[S.componentType].name,c[N]=S.normalized===!0}const{data:u}=s[x],d=await this.dracoManager.decodeGeometry(u,{attributeIds:B,attributeTypes:P});for(let w=0;w<d.attributes.length;w++){const S=d.attributes[w],N=S.name,V=S.array,L=S.itemSize,j=F[N],X=c[N],oe=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,oe),e.renderer.state.boundBuffer=oe,e.bufferData(e.ARRAY_BUFFER,V,e.STATIC_DRAW),y.addAttribute(N,{data:V,size:L,type:j,normalized:X,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(Kn[x],this.parseAccessor(a[x],n,s));f!==void 0&&y.addAttribute("index",this.parseAccessor(f,n,s))}return l>1&&y.addAttribute("instanceMatrix",{instanced:1,size:16,data:new Float32Array(l*16)}),o&&y.addAttribute("lightmapScaleOffset",{instanced:1,size:4,data:new Float32Array(l*4)}),{geometry:y,program:p,mode:m}}))}static parseAccessor(e,r,n){const{bufferView:s,byteOffset:i=0,componentType:l,normalized:o=!1,count:a,type:f,min:g,max:m,sparse:h}=r.accessors[e],{data:v,buffer:M,byteOffset:p=0,byteStride:y=0,target:x}=n[s],T=da[f],B=Yn[l],F=B.BYTES_PER_ELEMENT,P=y/F,c=!!y&&P!==T;let u;if(c){const d=new B(v,i);u=new B(a*T);for(let w=0;w<a;w++){const S=P*w,N=S+T;u.set(d.slice(S,N),w*T)}}else u=new B(v,i,a*T);return{data:u,size:T,type:l,normalized:o,buffer:M,stride:y,offset:i,count:a,min:g,max:m}}static parseNodes(e,r,n,s,i){if(!r.nodes)return null;const l=[],o=r.nodes.map(({camera:a,children:f,skin:g,matrix:m,mesh:h,rotation:v,scale:M,translation:p,weights:y,name:x,extensions:T,extras:B})=>{const F=a!==void 0,P=F?new ln(e):new ct;if(F){const S=r.cameras[a];if(S.type==="perspective"){const{yfov:N,znear:V,zfar:L}=S.perspective;P.perspective({fov:N*(180/Math.PI),near:V,far:L})}else{const{xmag:N,ymag:V,znear:L,zfar:j}=S.orthographic;P.orthographic({near:L,far:j,left:-N,right:N,top:-V,bottom:V})}l.push(P)}x&&(P.name=x),B&&(P.extras=B),T&&(P.extensions=T),B&&B.lightmapTexture!==void 0&&(B.lightmapTexture.texture=this.createTexture(e,r,i,{source:B.lightmapTexture.index})),m?(P.matrix.copy(m),P.decompose()):(v&&P.quaternion.copy(v),M&&P.scale.copy(M),p&&P.position.copy(p),P.updateMatrix());let c=!1,u=!0,d=!1;if(h!==void 0&&(g!==void 0?(n[h].primitives[n[h].primitives.instanceCount].forEach(S=>{B&&Object.assign(S.extras,B),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=>{B&&Object.assign(S.extras,B),S.geometry.isInstanced&&(c=!0,S.instanceCount?u=!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(B.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?u&&S.setParent(P):S.setParent(P)})),d){if(!u)return null;P.matrix.identity(),P.decompose()}return P});return r.nodes.forEach(({children:a=[]},f)=>{a.forEach(g=>{o[g]&&o[g].setParent(o[f])})}),n.forEach(({primitives:a},f)=>{a.forEach((g,m)=>{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 pt(...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 f=i.map(({sampler:g,target:m})=>{const{input:h,interpolation:v="LINEAR",output:M}=l[g],{node:p,path:y}=m,x=n[p],T=pa[y],B=this.parseAccessor(h,r,s).data,F=this.parseAccessor(M,r,s).data;return x.animations||(x.animations=[]),x.animations.includes(a)||x.animations.push(a),{node:x,transform:T,interpolation:v,times:B,values:F}});return{name:o,animation:new ha(f)}}):null}static parseScenes(e,r){return e.scenes?e.scenes.map(({nodes:n=[],name:s,extensions:i,extras:l})=>{const o=n.reduce((a,f)=>(r[f]&&a.push(r[f]),a),[]);return o.extras=l,o}):null}static parseLights(e,r,n,s){var o,a;const i={directional:[],point:[],spot:[]};s.forEach(f=>f.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(f=>{var v;if(!((v=f==null?void 0:f.extensions)!=null&&v.KHR_lights_punctual))return;const g=f.extensions.KHR_lights_punctual.light,m=l[g],h={name:m.name||"",color:{value:new Ce().set(m.color||1)}};switch(m.intensity!==void 0&&h.color.value.multiply(m.intensity),m.type){case"directional":h.direction={value:new Ce(0,0,1).transformDirection(f.worldMatrix)};break;case"point":h.position={value:new Ce().applyMatrix4(f.worldMatrix)},h.distance={value:m.range},h.decay={value:2};break;case"spot":Object.assign(h,m);break}i[m.type].push(h)}),i}}const ma={fetch:Js,getBuffer:ti,getBlob:ei,putBuffer:si,putLocalBuffer:ii,hasLocalBuffer:ni,getLocalName:ri,getPlayer:oi,removePlayers:Zs},He=()=>{const t=new Float32Array(16);return t[0]=t[5]=t[10]=t[15]=1,t},dt=(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},St=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],f=t[10],g=e*(i*f-l*a)-s*(r*f-n*a)+o*(r*l-n*i),m=g===0?0:1/g,h=new Float32Array(16);h[0]=(i*f-l*a)*m,h[1]=(n*a-r*f)*m,h[2]=(r*l-n*i)*m,h[4]=(l*o-s*f)*m,h[5]=(e*f-n*o)*m,h[6]=(n*s-e*l)*m,h[8]=(s*a-i*o)*m,h[9]=(r*o-e*a)*m,h[10]=(e*i-r*s)*m;const v=t[12],M=t[13],p=t[14];return h[12]=-(h[0]*v+h[4]*M+h[8]*p),h[13]=-(h[1]*v+h[5]*M+h[9]*p),h[14]=-(h[2]*v+h[6]*M+h[10]*p),h[15]=1,h},Mr=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])],Us=(t,e,r,n,s)=>{const[i,l,o]=Mr(t),a=Math.hypot(e,r,n,s)||1,f=e/a,g=r/a,m=n/a,h=s/a,v=f*f,M=f*g,p=f*m,y=f*h,x=g*g,T=g*m,B=g*h,F=m*m,P=m*h;t[0]=(1-2*(x+F))*i,t[1]=2*(M+P)*i,t[2]=2*(p-B)*i,t[4]=2*(M-P)*l,t[5]=(1-2*(v+F))*l,t[6]=2*(T+y)*l,t[8]=2*(p+B)*o,t[9]=2*(T-y)*o,t[10]=(1-2*(v+x))*o},Xt=Math.PI/180,ga=(t,e,r,n,s)=>{const[i,l,o]=Mr(t),a=e*Xt,f=r*Xt,g=n*Xt,m=Math.cos(a),h=Math.sin(a),v=Math.cos(f),M=Math.sin(f),p=Math.cos(g),y=Math.sin(g);let x=1,T=0,B=0,F=0,P=1,c=0,u=0,d=0,w=1;switch(s){case 0:x=v*p,T=-v*y,B=M,F=h*M*p+m*y,P=-h*M*y+m*p,c=-h*v,u=-m*M*p+h*y,d=m*M*y+h*p,w=m*v;break;case 1:x=v*p+M*h*y,T=-v*y+M*h*p,B=M*m,F=m*y,P=m*p,c=-h,u=-M*p+v*h*y,d=M*y+v*h*p,w=v*m;break;case 2:x=v*p-M*h*y,T=-m*y,B=M*p+v*h*y,F=v*y+M*h*p,P=m*p,c=M*y-v*h*p,u=-M*m,d=h,w=v*m;break;case 3:x=v*p,T=h*M*p-m*y,B=m*M*p+h*y,F=v*y,P=h*M*y+m*p,c=m*M*y-h*p,u=-M,d=h*v,w=m*v;break;case 4:x=v*p,T=-y,B=M*p,F=h*M+m*v*y,P=m*p,c=-v*h+m*M*y,u=-m*M+h*v*y,d=h*p,w=m*v+h*M*y;break;case 5:x=v*p,T=-v*y,B=M,F=m*y+h*M*p,P=m*p-h*M*y,c=-h*v,u=h*y-m*M*p,d=h*p+m*M*y,w=m*v;break}t[0]=x*i,t[1]=F*i,t[2]=u*i,t[4]=T*l,t[5]=P*l,t[6]=d*l,t[8]=B*o,t[9]=c*o,t[10]=w*o},zs=(t,e,r,n)=>{const[s,i,l]=Mr(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,f=n/l;t[0]*=o,t[1]*=o,t[2]*=o,t[4]*=a,t[5]*=a,t[6]*=a,t[8]*=f,t[9]*=f,t[10]*=f},Zn=t=>{const[e,r,n]=Mr(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,f=t[9]/n,g=t[10]/n,m=Math.asin(-Math.min(1,Math.max(-1,f)));let h,v;return Math.abs(f)<.9999?(h=Math.atan2(a,g),v=Math.atan2(i,o)):(h=Math.atan2(-l,s),v=0),[m/Xt,h/Xt,v/Xt]},Vs=(t,e,r)=>{const n=He();return Us(n,e[0],e[1],e[2],e[3]),zs(n,r[0],r[1],r[2]),n[12]=t[0],n[13]=t[1],n[14]=t[2],n},Gs=(t,e,r,n)=>{const s=1/Math.tan(t*Xt/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},ya=(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},Jn=(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},va=(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]),f=s*s+i*i+l*l-e*e,g=a*a-4*o*f;if(g<0)return-1;const m=Math.sqrt(g),h=(-a-m)/(2*o),v=(-a+m)/(2*o);return h>0&&v>0?Math.min(h,v):h>0?h:v>0?v:-1},At=(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),xa=(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 f=n*a-s*o,g=s*l-r*a,m=r*o-n*l;const h=Math.hypot(f,g,m)||1;f/=h,g/=h,m/=h;const v=g*s-m*n,M=m*r-f*s,p=f*n-g*r,y=new Float32Array(16);return y[0]=f,y[4]=g,y[8]=m,y[1]=v,y[5]=M,y[9]=p,y[2]=-r,y[6]=-n,y[10]=-s,y[12]=-(f*t[0]+g*t[1]+m*t[2]),y[13]=-(v*t[0]+M*t[1]+p*t[2]),y[14]=r*t[0]+n*t[1]+s*t[2],y[15]=1,y},wa=1/(1.2*Math.pow(2,Math.log2(256/(1/125)))),Ma=`#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
|
+
`,Hs=`
|
|
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
|
+
`,Aa=`
|
|
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
|
+
`,ks=t=>`${Ma}
|
|
85
|
+
#ifdef INSTANCED
|
|
86
|
+
in mat4 instanceMatrix;
|
|
87
|
+
uniform mat4 viewMatrix;
|
|
88
|
+
#endif
|
|
89
|
+
${t.includes("HAS_SKIN")?Hs:""}
|
|
90
|
+
${t.includes("HAS_MORPH")?Aa:""}
|
|
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
|
+
`,jt=8,Ar=`
|
|
130
|
+
#define MAX_PUNCTUAL ${jt}
|
|
131
|
+
uniform int punctualCount;
|
|
132
|
+
uniform vec4 punctualPos[MAX_PUNCTUAL]; // xyz = world position, w = 1 / range²
|
|
133
|
+
uniform vec4 punctualColor[MAX_PUNCTUAL]; // rgb = linear colour x candela, w = cone scale (0 = a point light)
|
|
134
|
+
uniform vec4 punctualDir[MAX_PUNCTUAL]; // xyz = where the light travels (unit), w = cone offset (1 = a point light)
|
|
135
|
+
uniform vec3 sunDirection;
|
|
136
|
+
uniform vec4 sunColorIntensity; // rgb = linear color, a = intensity (lux)
|
|
137
|
+
uniform float iblLuminance;
|
|
138
|
+
uniform vec3 iblSH[9];
|
|
139
|
+
uniform samplerCube envMap;
|
|
140
|
+
uniform float envMapMaxLod;
|
|
141
|
+
uniform sampler2D shadowMap;
|
|
142
|
+
uniform float shadowEnabled;
|
|
143
|
+
uniform float shadowMapSize;
|
|
144
|
+
uniform float exposure;
|
|
145
|
+
in vec4 vShadowCoord;
|
|
146
|
+
|
|
147
|
+
#define PI 3.14159265359
|
|
148
|
+
|
|
149
|
+
float D_GGX(float NoH, float a) {
|
|
150
|
+
float a2 = a * a;
|
|
151
|
+
float f = (NoH * a2 - NoH) * NoH + 1.0;
|
|
152
|
+
return a2 / (PI * f * f);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
float V_SmithGGXCorrelated(float NoV, float NoL, float a) {
|
|
156
|
+
float a2 = a * a;
|
|
157
|
+
float GGXL = NoV * sqrt((-NoL * a2 + NoL) * NoL + a2);
|
|
158
|
+
float GGXV = NoL * sqrt((-NoV * a2 + NoV) * NoV + a2);
|
|
159
|
+
return 0.5 / (GGXV + GGXL + 1e-5);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
vec3 F_Schlick(float u, vec3 f0) {
|
|
163
|
+
float f = pow(1.0 - u, 5.0);
|
|
164
|
+
return f0 + (vec3(1.0) - f0) * f;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
vec3 evalSH(vec3 n) {
|
|
168
|
+
return max(
|
|
169
|
+
iblSH[0]
|
|
170
|
+
+ iblSH[1] * n.y
|
|
171
|
+
+ iblSH[2] * n.z
|
|
172
|
+
+ iblSH[3] * n.x
|
|
173
|
+
+ iblSH[4] * (n.y * n.x)
|
|
174
|
+
+ iblSH[5] * (n.y * n.z)
|
|
175
|
+
+ iblSH[6] * (3.0 * n.z * n.z - 1.0)
|
|
176
|
+
+ iblSH[7] * (n.z * n.x)
|
|
177
|
+
+ iblSH[8] * (n.x * n.x - n.y * n.y)
|
|
178
|
+
, vec3(0.0));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
float sampleShadowPCF() {
|
|
182
|
+
if (shadowEnabled < 0.5) return 1.0;
|
|
183
|
+
vec3 coord = vShadowCoord.xyz / vShadowCoord.w;
|
|
184
|
+
coord = coord * 0.5 + 0.5;
|
|
185
|
+
if (coord.x < 0.0 || coord.x > 1.0 || coord.y < 0.0 || coord.y > 1.0 || coord.z > 1.0) return 1.0;
|
|
186
|
+
float bias = 0.0018;
|
|
187
|
+
float texel = 1.0 / shadowMapSize;
|
|
188
|
+
float sum = 0.0;
|
|
189
|
+
for (int x = -1; x <= 1; x++) {
|
|
190
|
+
for (int y = -1; y <= 1; y++) {
|
|
191
|
+
float depth = texture(shadowMap, coord.xy + vec2(float(x), float(y)) * texel).r;
|
|
192
|
+
sum += (coord.z - bias) > depth ? 0.0 : 1.0;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return sum / 9.0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Lambert diffuse + the GGX specular lobe for one light direction l (unit, TO the light).
|
|
199
|
+
vec3 surfaceBRDF(vec3 n, vec3 v, vec3 l, float NoV, float NoL, float a, vec3 diffuseColor, vec3 f0) {
|
|
200
|
+
vec3 h = normalize(v + l);
|
|
201
|
+
float NoH = clamp(dot(n, h), 0.0, 1.0);
|
|
202
|
+
float LoH = clamp(dot(l, h), 0.0, 1.0);
|
|
203
|
+
vec3 Fr = D_GGX(NoH, a) * V_SmithGGXCorrelated(NoV, NoL, a) * F_Schlick(LoH, f0);
|
|
204
|
+
return diffuseColor * (1.0 / PI) + Fr;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// diffuseColor: linear albedo (already metallic-adjusted); f0: specular reflectance at normal.
|
|
208
|
+
vec3 shadePBR(vec3 n, vec3 v, vec3 diffuseColor, vec3 f0, float perceptualRoughness, float occlusion) {
|
|
209
|
+
float roughness = clamp(perceptualRoughness, 0.045, 1.0);
|
|
210
|
+
float a = roughness * roughness;
|
|
211
|
+
float NoV = abs(dot(n, v)) + 1e-5;
|
|
212
|
+
|
|
213
|
+
vec3 color = vec3(0.0);
|
|
214
|
+
|
|
215
|
+
// --- sun ---
|
|
216
|
+
if (sunColorIntensity.a > 0.0) {
|
|
217
|
+
vec3 l = normalize(-sunDirection);
|
|
218
|
+
float NoL = clamp(dot(n, l), 0.0, 1.0);
|
|
219
|
+
if (NoL > 0.0) {
|
|
220
|
+
float shadow = sampleShadowPCF();
|
|
221
|
+
// "illuminance" model: lux * NoL, pre-exposed
|
|
222
|
+
color += surfaceBRDF(n, v, l, NoV, NoL, a, diffuseColor, f0) * sunColorIntensity.rgb * (sunColorIntensity.a * exposure * NoL * shadow);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// --- point + spot lights ---
|
|
227
|
+
for (int i = 0; i < MAX_PUNCTUAL; i++) {
|
|
228
|
+
if (i >= punctualCount) break;
|
|
229
|
+
vec3 toLight = punctualPos[i].xyz - vWorldPos;
|
|
230
|
+
float d2 = dot(toLight, toLight);
|
|
231
|
+
float f = d2 * punctualPos[i].w;
|
|
232
|
+
float win = clamp(1.0 - f * f, 0.0, 1.0);
|
|
233
|
+
vec3 l = toLight * inversesqrt(max(d2, 1e-8));
|
|
234
|
+
float cone = clamp(dot(-punctualDir[i].xyz, l) * punctualColor[i].w + punctualDir[i].w, 0.0, 1.0);
|
|
235
|
+
// a punctual light occupies a volume of 1 cm (filament): no division by 0 on its own surface
|
|
236
|
+
float attenuation = win * win * cone * cone / max(d2, 1e-4);
|
|
237
|
+
float NoL = clamp(dot(n, l), 0.0, 1.0);
|
|
238
|
+
if (attenuation <= 0.0 || NoL <= 0.0) continue;
|
|
239
|
+
color += surfaceBRDF(n, v, l, NoV, NoL, a, diffuseColor, f0) * punctualColor[i].rgb * (attenuation * exposure * NoL);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// --- IBL ---
|
|
243
|
+
if (iblLuminance > 0.0) {
|
|
244
|
+
// cmgen's SH coefficients are pre-convolved irradiance — no extra 1/PI (matches Filament).
|
|
245
|
+
vec3 irradiance = evalSH(n);
|
|
246
|
+
vec3 Fd = diffuseColor * irradiance;
|
|
247
|
+
|
|
248
|
+
vec3 r = reflect(-v, n);
|
|
249
|
+
float lod = roughness * envMapMaxLod;
|
|
250
|
+
vec3 prefiltered = textureLod(envMap, r, lod).rgb;
|
|
251
|
+
// Simple DFG approximation (Karis): avoids a DFG LUT.
|
|
252
|
+
vec3 specular = prefiltered * (f0 * (1.0 - roughness) + roughness * 0.25 * f0 + 0.05 * (1.0 - roughness));
|
|
253
|
+
color += (Fd + specular) * (iblLuminance * exposure * occlusion);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return color;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// ACES filmic fit (Narkowicz) + sRGB OETF — stands in for Filament's default ACES color grading.
|
|
260
|
+
vec3 tonemap(vec3 x) {
|
|
261
|
+
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;
|
|
262
|
+
vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
|
|
263
|
+
return pow(t, vec3(1.0 / 2.2));
|
|
264
|
+
}
|
|
265
|
+
`,Sa=`#version 300 es
|
|
266
|
+
precision highp float;
|
|
267
|
+
in vec3 vWorldPos;
|
|
268
|
+
in vec3 vNormal;
|
|
269
|
+
in vec2 vUv;
|
|
270
|
+
uniform vec3 cameraPosition;
|
|
271
|
+
uniform vec3 baseColor; // linear factor over baseColorMap (both default white)
|
|
272
|
+
uniform sampler2D baseColorMap;
|
|
273
|
+
uniform float roughness;
|
|
274
|
+
uniform float metallic;
|
|
275
|
+
${Ar}
|
|
276
|
+
out vec4 fragColor;
|
|
277
|
+
|
|
278
|
+
void main() {
|
|
279
|
+
vec3 albedo = baseColor * texture(baseColorMap, vUv).rgb;
|
|
280
|
+
vec3 n = normalize(vNormal);
|
|
281
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
282
|
+
if (dot(n, v) < 0.0) n = -n;
|
|
283
|
+
vec3 diffuseColor = albedo * (1.0 - metallic);
|
|
284
|
+
vec3 f0 = mix(vec3(0.04), albedo, metallic);
|
|
285
|
+
vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, 1.0);
|
|
286
|
+
fragColor = vec4(tonemap(color), 1.0);
|
|
287
|
+
}
|
|
288
|
+
`,ba=`#version 300 es
|
|
289
|
+
precision highp float;
|
|
290
|
+
in vec3 vWorldPos;
|
|
291
|
+
in vec3 vNormal;
|
|
292
|
+
in vec2 vUv;
|
|
293
|
+
uniform vec3 cameraPosition;
|
|
294
|
+
uniform sampler2D control;
|
|
295
|
+
uniform sampler2D albedo0;
|
|
296
|
+
uniform sampler2D albedo1;
|
|
297
|
+
uniform sampler2D albedo2;
|
|
298
|
+
uniform sampler2D albedo3;
|
|
299
|
+
uniform sampler2D normals01;
|
|
300
|
+
uniform sampler2D normals23;
|
|
301
|
+
uniform vec4 tiling;
|
|
302
|
+
uniform vec4 roughness;
|
|
303
|
+
uniform vec4 normalScale;
|
|
304
|
+
uniform vec4 triplanar;
|
|
305
|
+
uniform vec2 gridSize;
|
|
306
|
+
uniform float cellSize;
|
|
307
|
+
uniform vec3 tint;
|
|
308
|
+
${Ar}
|
|
309
|
+
out vec4 fragColor;
|
|
310
|
+
|
|
311
|
+
vec4 triplanarSample(sampler2D tex, vec3 p, vec3 bw, float s) {
|
|
312
|
+
return texture(tex, p.zy / s) * bw.x + texture(tex, p.xz / s) * bw.y + texture(tex, p.xy / s) * bw.z;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
void splatLayer(sampler2D alb, sampler2D pack, float slot, float tl, float nscale, float tri, float w,
|
|
316
|
+
vec2 uv, vec3 wp, vec3 bw, inout vec3 albedo, inout vec3 nrm) {
|
|
317
|
+
if (w <= 0.0) return;
|
|
318
|
+
float s = max(tl, 1e-3);
|
|
319
|
+
if (tri > 0.5) {
|
|
320
|
+
albedo += triplanarSample(alb, wp, bw, s).rgb * w;
|
|
321
|
+
nrm += vec3(0.0, 0.0, 1.0) * w;
|
|
322
|
+
} else {
|
|
323
|
+
vec2 luv = uv / s;
|
|
324
|
+
albedo += texture(alb, luv).rgb * w;
|
|
325
|
+
if (nscale > 0.0) {
|
|
326
|
+
vec4 p = texture(pack, luv);
|
|
327
|
+
vec2 xy = (slot > 0.5 ? p.ba : p.rg) * 2.0 - 1.0;
|
|
328
|
+
xy *= nscale;
|
|
329
|
+
nrm += vec3(xy, sqrt(max(1.0 - dot(xy, xy), 0.0))) * w;
|
|
330
|
+
} else {
|
|
331
|
+
nrm += vec3(0.0, 0.0, 1.0) * w;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
|
|
337
|
+
vec3 pos_dx = dFdx(vWorldPos);
|
|
338
|
+
vec3 pos_dy = dFdy(vWorldPos);
|
|
339
|
+
vec2 tex_dx = dFdx(vUv);
|
|
340
|
+
vec2 tex_dy = dFdy(vUv);
|
|
341
|
+
float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
|
|
342
|
+
if (abs(det) < 1e-8) return ng;
|
|
343
|
+
vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
|
|
344
|
+
t = normalize(t - ng * dot(ng, t));
|
|
345
|
+
vec3 b = normalize(cross(ng, t)) * sign(det);
|
|
346
|
+
return normalize(mat3(t, b, ng) * nTangent);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
void main() {
|
|
350
|
+
vec2 cuv = (vUv / max(cellSize, 1e-4) + 0.5) / max(gridSize, vec2(1.0));
|
|
351
|
+
vec4 w = texture(control, cuv);
|
|
352
|
+
float ws = w.r + w.g + w.b + w.a;
|
|
353
|
+
w = ws > 1e-4 ? w / ws : vec4(1.0, 0.0, 0.0, 0.0);
|
|
354
|
+
vec3 ng = normalize(vNormal);
|
|
355
|
+
vec3 bw = abs(ng);
|
|
356
|
+
bw = bw / max(bw.x + bw.y + bw.z, 1e-4);
|
|
357
|
+
vec3 albedo = vec3(0.0);
|
|
358
|
+
vec3 nrm = vec3(0.0);
|
|
359
|
+
splatLayer(albedo0, normals01, 0.0, tiling.x, normalScale.x, triplanar.x, w.r, vUv, vWorldPos, bw, albedo, nrm);
|
|
360
|
+
splatLayer(albedo1, normals01, 1.0, tiling.y, normalScale.y, triplanar.y, w.g, vUv, vWorldPos, bw, albedo, nrm);
|
|
361
|
+
splatLayer(albedo2, normals23, 0.0, tiling.z, normalScale.z, triplanar.z, w.b, vUv, vWorldPos, bw, albedo, nrm);
|
|
362
|
+
splatLayer(albedo3, normals23, 1.0, tiling.w, normalScale.w, triplanar.w, w.a, vUv, vWorldPos, bw, albedo, nrm);
|
|
363
|
+
vec3 n = applyTangentNormal(normalize(nrm), ng);
|
|
364
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
365
|
+
if (dot(ng, v) < 0.0) n = -n;
|
|
366
|
+
vec3 diffuseColor = albedo * tint;
|
|
367
|
+
vec3 color = shadePBR(n, v, diffuseColor, vec3(0.04), dot(roughness, w), 1.0);
|
|
368
|
+
fragColor = vec4(tonemap(color), 1.0);
|
|
369
|
+
}
|
|
370
|
+
`,_a=`#version 300 es
|
|
371
|
+
precision highp float;
|
|
372
|
+
in vec3 vWorldPos;
|
|
373
|
+
in vec3 vNormal;
|
|
374
|
+
in vec2 vUv;
|
|
375
|
+
uniform vec4 baseColor; // linear, premultiplied; factor over baseColorMap
|
|
376
|
+
uniform sampler2D baseColorMap;
|
|
377
|
+
out vec4 fragColor;
|
|
378
|
+
|
|
379
|
+
vec3 tonemapUnlit(vec3 x) {
|
|
380
|
+
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;
|
|
381
|
+
vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
|
|
382
|
+
return pow(t, vec3(1.0 / 2.2));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
void main() {
|
|
386
|
+
vec4 c = baseColor * texture(baseColorMap, vUv);
|
|
387
|
+
fragColor = vec4(tonemapUnlit(c.rgb), 1.0);
|
|
388
|
+
}
|
|
389
|
+
`,Ca=`#version 300 es
|
|
390
|
+
precision highp float;
|
|
391
|
+
in vec3 vWorldPos;
|
|
392
|
+
in vec3 vNormal;
|
|
393
|
+
in vec2 vUv;
|
|
394
|
+
uniform vec4 baseColor; // linear, straight alpha; factor over baseColorMap
|
|
395
|
+
uniform sampler2D baseColorMap;
|
|
396
|
+
out vec4 fragColor;
|
|
397
|
+
|
|
398
|
+
vec3 tonemapUnlit(vec3 x) {
|
|
399
|
+
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;
|
|
400
|
+
vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
|
|
401
|
+
return pow(t, vec3(1.0 / 2.2));
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
void main() {
|
|
405
|
+
vec4 c = baseColor * texture(baseColorMap, vUv);
|
|
406
|
+
fragColor = vec4(tonemapUnlit(c.rgb) * c.a, c.a);
|
|
407
|
+
}
|
|
408
|
+
`,Ea=`#version 300 es
|
|
409
|
+
precision highp float;
|
|
410
|
+
in vec2 vUv;
|
|
411
|
+
in vec3 vWorldPos;
|
|
412
|
+
in vec3 vNormal;
|
|
413
|
+
uniform sampler2D baseColorMap;
|
|
414
|
+
out vec4 fragColor;
|
|
415
|
+
void main() {
|
|
416
|
+
fragColor = vec4(texture(baseColorMap, vUv).rgb, 1.0);
|
|
417
|
+
}
|
|
418
|
+
`,Fa=`#version 300 es
|
|
419
|
+
precision highp float;
|
|
420
|
+
in vec3 vWorldPos;
|
|
421
|
+
in vec3 vNormal;
|
|
422
|
+
in vec2 vUv;
|
|
423
|
+
uniform vec4 color; // linear, premultiplied
|
|
424
|
+
${Ar}
|
|
425
|
+
out vec4 fragColor;
|
|
426
|
+
void main() {
|
|
427
|
+
float vis = sampleShadowPCF();
|
|
428
|
+
float shadowAmount = 1.0 - vis;
|
|
429
|
+
fragColor = vec4(color.rgb * shadowAmount, color.a * shadowAmount);
|
|
430
|
+
}
|
|
431
|
+
`,Ws=t=>ks(t),kt=ks(""),Ta=t=>`#version 300 es
|
|
432
|
+
precision highp float;
|
|
433
|
+
${t}
|
|
434
|
+
in vec3 vWorldPos;
|
|
435
|
+
in vec3 vNormal;
|
|
436
|
+
in vec2 vUv;
|
|
437
|
+
#ifdef HAS_COLOR
|
|
438
|
+
in vec4 vColor;
|
|
439
|
+
#endif
|
|
440
|
+
uniform vec3 cameraPosition;
|
|
441
|
+
uniform vec4 uBaseColorFactor;
|
|
442
|
+
uniform float uMetallic;
|
|
443
|
+
uniform float uRoughness;
|
|
444
|
+
uniform vec3 uEmissive;
|
|
445
|
+
uniform float uAlphaCutoff;
|
|
446
|
+
#ifdef HAS_BASECOLOR_MAP
|
|
447
|
+
uniform sampler2D uBaseColorMap;
|
|
448
|
+
#endif
|
|
449
|
+
#ifdef HAS_MR_MAP
|
|
450
|
+
uniform sampler2D uMRMap;
|
|
451
|
+
#endif
|
|
452
|
+
#ifdef HAS_NORMAL_MAP
|
|
453
|
+
uniform sampler2D uNormalMap;
|
|
454
|
+
#endif
|
|
455
|
+
#ifdef HAS_OCCLUSION_MAP
|
|
456
|
+
uniform sampler2D uOcclusionMap;
|
|
457
|
+
#endif
|
|
458
|
+
#ifdef HAS_EMISSIVE_MAP
|
|
459
|
+
uniform sampler2D uEmissiveMap;
|
|
460
|
+
#endif
|
|
461
|
+
${Ar}
|
|
462
|
+
out vec4 fragColor;
|
|
463
|
+
|
|
464
|
+
#ifdef HAS_NORMAL_MAP
|
|
465
|
+
vec3 getNormal() {
|
|
466
|
+
vec3 pos_dx = dFdx(vWorldPos);
|
|
467
|
+
vec3 pos_dy = dFdy(vWorldPos);
|
|
468
|
+
vec2 tex_dx = dFdx(vUv);
|
|
469
|
+
vec2 tex_dy = dFdy(vUv);
|
|
470
|
+
float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
|
|
471
|
+
if (abs(det) < 1e-8) return normalize(vNormal);
|
|
472
|
+
vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
|
|
473
|
+
vec3 ng = normalize(vNormal);
|
|
474
|
+
t = normalize(t - ng * dot(ng, t));
|
|
475
|
+
vec3 b = normalize(cross(ng, t)) * sign(det);
|
|
476
|
+
mat3 tbn = mat3(t, b, ng);
|
|
477
|
+
vec3 n = texture(uNormalMap, vUv).rgb * 2.0 - 1.0;
|
|
478
|
+
return normalize(tbn * n);
|
|
479
|
+
}
|
|
480
|
+
#endif
|
|
481
|
+
|
|
482
|
+
void main() {
|
|
483
|
+
vec4 base = uBaseColorFactor;
|
|
484
|
+
#ifdef HAS_BASECOLOR_MAP
|
|
485
|
+
base *= texture(uBaseColorMap, vUv);
|
|
486
|
+
#endif
|
|
487
|
+
#ifdef HAS_COLOR
|
|
488
|
+
base *= vColor;
|
|
489
|
+
#endif
|
|
490
|
+
#ifdef ALPHA_MASK
|
|
491
|
+
if (base.a < uAlphaCutoff) discard;
|
|
492
|
+
#endif
|
|
493
|
+
|
|
494
|
+
#ifdef UNLIT
|
|
495
|
+
// KHR_materials_unlit: the base colour IS the shaded colour — no lights, no IBL, no exposure
|
|
496
|
+
// (Filament's UNLIT shading model does the same, then tone-maps in post like everything else).
|
|
497
|
+
#ifdef ALPHA_BLEND
|
|
498
|
+
fragColor = vec4(tonemap(base.rgb), base.a);
|
|
499
|
+
#else
|
|
500
|
+
fragColor = vec4(tonemap(base.rgb), 1.0);
|
|
501
|
+
#endif
|
|
502
|
+
return;
|
|
503
|
+
#endif
|
|
504
|
+
|
|
505
|
+
float metallic = uMetallic;
|
|
506
|
+
float roughness = uRoughness;
|
|
507
|
+
#ifdef HAS_MR_MAP
|
|
508
|
+
vec3 mr = texture(uMRMap, vUv).rgb;
|
|
509
|
+
roughness *= mr.g;
|
|
510
|
+
metallic *= mr.b;
|
|
511
|
+
#endif
|
|
512
|
+
|
|
513
|
+
float occlusion = 1.0;
|
|
514
|
+
#ifdef HAS_OCCLUSION_MAP
|
|
515
|
+
occlusion = texture(uOcclusionMap, vUv).r;
|
|
516
|
+
#endif
|
|
517
|
+
|
|
518
|
+
#ifdef HAS_NORMAL_MAP
|
|
519
|
+
vec3 n = getNormal();
|
|
520
|
+
#else
|
|
521
|
+
vec3 n = normalize(vNormal);
|
|
522
|
+
#endif
|
|
523
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
524
|
+
#ifdef DOUBLE_SIDED
|
|
525
|
+
if (dot(n, v) < 0.0) n = -n;
|
|
526
|
+
#endif
|
|
527
|
+
|
|
528
|
+
vec3 diffuseColor = base.rgb * (1.0 - metallic);
|
|
529
|
+
vec3 f0 = mix(vec3(0.04), base.rgb, metallic);
|
|
530
|
+
vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, occlusion);
|
|
531
|
+
|
|
532
|
+
vec3 emissive = uEmissive;
|
|
533
|
+
#ifdef HAS_EMISSIVE_MAP
|
|
534
|
+
emissive *= texture(uEmissiveMap, vUv).rgb;
|
|
535
|
+
#endif
|
|
536
|
+
color += emissive * iblLuminance * exposure;
|
|
537
|
+
|
|
538
|
+
#ifdef ALPHA_BLEND
|
|
539
|
+
fragColor = vec4(tonemap(color), base.a);
|
|
540
|
+
#else
|
|
541
|
+
fragColor = vec4(tonemap(color), 1.0);
|
|
542
|
+
#endif
|
|
543
|
+
}
|
|
544
|
+
`,es=`#version 300 es
|
|
545
|
+
precision highp float;
|
|
546
|
+
in vec3 vWorldPos;
|
|
547
|
+
in vec3 vNormal;
|
|
548
|
+
in vec2 vUv;
|
|
549
|
+
uniform vec3 uWireColor;
|
|
550
|
+
out vec4 fragColor;
|
|
551
|
+
void main() { fragColor = vec4(uWireColor, 1.0); }
|
|
552
|
+
`,yr=(t,e=!1)=>`#version 300 es
|
|
553
|
+
precision highp float;
|
|
554
|
+
in vec3 position;
|
|
555
|
+
${t?`in vec3 normal;
|
|
556
|
+
in vec2 uv;`:""}
|
|
557
|
+
${e?"in mat4 instanceMatrix;":"uniform mat4 modelMatrix;"}
|
|
558
|
+
uniform mat4 shadowViewProjection;
|
|
559
|
+
${t?Hs:""}
|
|
560
|
+
void main() {
|
|
561
|
+
vec4 pos = vec4(position, 1.0);
|
|
562
|
+
${t?"pos = getSkinMatrix() * pos;":""}
|
|
563
|
+
gl_Position = shadowViewProjection * ${e?"instanceMatrix":"modelMatrix"} * pos;
|
|
564
|
+
}
|
|
565
|
+
`,vr=`#version 300 es
|
|
566
|
+
precision highp float;
|
|
567
|
+
out vec4 fragColor;
|
|
568
|
+
void main() { fragColor = vec4(1.0); }
|
|
569
|
+
`,ar=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),rr=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)},Pa=t=>[ar((t>>>16&255)/255),ar((t>>>8&255)/255),ar((t&255)/255)],Ra=t=>[ar((t>>>24&255)/255),ar((t>>>16&255)/255),ar((t>>>8&255)/255),(t&255)/255],$s=`
|
|
570
|
+
uniform sampler2D baseColorMap;
|
|
571
|
+
uniform vec2 sheetSize; // (cols, rows) of the flipbook sheet, both >= 1 (the SDK primes it)
|
|
572
|
+
uniform float emissive;
|
|
573
|
+
uniform float additive;
|
|
574
|
+
uniform float softness;
|
|
575
|
+
uniform float depthFade; // declared so the SDK's write lands somewhere; ignored (no depth buffer)
|
|
576
|
+
|
|
577
|
+
vec3 tonemapParticle(vec3 x) {
|
|
578
|
+
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;
|
|
579
|
+
vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
|
|
580
|
+
return pow(t, vec3(1.0 / 2.2));
|
|
581
|
+
}
|
|
582
|
+
// Integer cell math: a float floor(frame / cols) lands one row early at row starts on the GPU.
|
|
583
|
+
vec2 sheetCell(int fi) {
|
|
584
|
+
int sx = int(sheetSize.x + 0.5);
|
|
585
|
+
return vec2(float(fi - (fi / sx) * sx), float(fi / sx));
|
|
586
|
+
}
|
|
587
|
+
`,Ba=`#version 300 es
|
|
588
|
+
precision highp float;
|
|
589
|
+
in vec3 position;
|
|
590
|
+
in vec4 color;
|
|
591
|
+
in vec4 custom;
|
|
592
|
+
uniform mat4 modelMatrix;
|
|
593
|
+
uniform mat4 viewMatrix;
|
|
594
|
+
uniform mat4 projectionMatrix;
|
|
595
|
+
uniform float perspScale; // viewportHeightPx / (2 tan(fov/2)): a true world-space diameter
|
|
596
|
+
out vec4 vColor;
|
|
597
|
+
out vec4 vCustom;
|
|
598
|
+
void main() {
|
|
599
|
+
vec4 viewPos = viewMatrix * modelMatrix * vec4(position, 1.0);
|
|
600
|
+
float z = max(-viewPos.z, 1e-3);
|
|
601
|
+
gl_PointSize = custom.x * perspScale / z;
|
|
602
|
+
vColor = color;
|
|
603
|
+
vCustom = custom;
|
|
604
|
+
gl_Position = projectionMatrix * viewPos;
|
|
605
|
+
}
|
|
606
|
+
`,Na=`#version 300 es
|
|
607
|
+
precision highp float;
|
|
608
|
+
in vec4 vColor;
|
|
609
|
+
in vec4 vCustom;
|
|
610
|
+
${$s}
|
|
611
|
+
out vec4 fragColor;
|
|
612
|
+
void main() {
|
|
613
|
+
vec2 uv = gl_PointCoord.xy;
|
|
614
|
+
float rot = vCustom.y;
|
|
615
|
+
if (rot != 0.0) {
|
|
616
|
+
float co = cos(rot);
|
|
617
|
+
float si = sin(rot);
|
|
618
|
+
vec2 p = uv - vec2(0.5);
|
|
619
|
+
uv = vec2(co * p.x - si * p.y, si * p.x + co * p.y) + vec2(0.5);
|
|
620
|
+
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) discard;
|
|
621
|
+
}
|
|
622
|
+
int total = int(sheetSize.x + 0.5) * int(sheetSize.y + 0.5);
|
|
623
|
+
int fi = int(floor(vCustom.w) + 0.5);
|
|
624
|
+
fi = fi - (fi / total) * total;
|
|
625
|
+
vec4 tex = texture(baseColorMap, (sheetCell(fi) + uv) / sheetSize);
|
|
626
|
+
float radial = 1.0 - smoothstep(0.0, 0.5, length(gl_PointCoord.xy - vec2(0.5)));
|
|
627
|
+
float shape = mix(1.0, radial, clamp(softness, 0.0, 1.0));
|
|
628
|
+
float alpha = tex.a * vColor.a * vCustom.z * shape;
|
|
629
|
+
vec3 rgb = tex.rgb * vColor.rgb * (1.0 + emissive);
|
|
630
|
+
fragColor = vec4(tonemapParticle(rgb) * alpha, alpha * (1.0 - clamp(additive, 0.0, 1.0)));
|
|
631
|
+
}
|
|
632
|
+
`,La=`#version 300 es
|
|
633
|
+
precision highp float;
|
|
634
|
+
in vec3 position;
|
|
635
|
+
in vec4 color;
|
|
636
|
+
in vec4 custom; // size, rotation, opacity, frame
|
|
637
|
+
in vec3 aux; // quad: velocity (stretch axis); ribbon: strip tangent — sim space
|
|
638
|
+
in vec2 corner; // quad: ±0.5 square; ribbon: (u01 - 0.5, ±0.5 side)
|
|
639
|
+
uniform mat4 modelMatrix;
|
|
640
|
+
uniform mat4 viewMatrix;
|
|
641
|
+
uniform mat4 projectionMatrix;
|
|
642
|
+
uniform float mode; // 0 camera billboard, 1 velocity-stretched, 2 ribbon strip
|
|
643
|
+
uniform float stretch; // (mode 1) extra length per unit of speed: length = size + stretch · |v|
|
|
644
|
+
out vec4 vColor;
|
|
645
|
+
out vec4 vCustom;
|
|
646
|
+
out vec4 vQuadUv; // xy: in-cell uv, zw: the softness basis
|
|
647
|
+
void main() {
|
|
648
|
+
vec4 wp = modelMatrix * vec4(position, 1.0);
|
|
649
|
+
vec3 a = mat3(modelMatrix) * aux;
|
|
650
|
+
// the camera's world axes: rows of the view rotation (= columns of its inverse)
|
|
651
|
+
vec3 camX = vec3(viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0]);
|
|
652
|
+
vec3 camY = vec3(viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1]);
|
|
653
|
+
vec3 camZ = vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]); // toward the camera
|
|
654
|
+
vec3 offset;
|
|
655
|
+
vec2 suv = corner;
|
|
656
|
+
if (mode < 0.5) {
|
|
657
|
+
float co = cos(custom.y);
|
|
658
|
+
float si = sin(custom.y);
|
|
659
|
+
vec2 rc = vec2(co * corner.x - si * corner.y, si * corner.x + co * corner.y);
|
|
660
|
+
offset = (camX * rc.x + camY * rc.y) * custom.x;
|
|
661
|
+
} else if (mode < 1.5) {
|
|
662
|
+
float speed = length(a);
|
|
663
|
+
vec3 dir = speed > 1e-4 ? a / speed : camY;
|
|
664
|
+
vec3 y = dir - camZ * dot(dir, camZ);
|
|
665
|
+
float yl = length(y);
|
|
666
|
+
y = yl > 1e-4 ? y / yl : camY;
|
|
667
|
+
vec3 x = normalize(cross(y, camZ));
|
|
668
|
+
offset = x * corner.x * custom.x + y * corner.y * (custom.x + stretch * speed * yl);
|
|
669
|
+
} else {
|
|
670
|
+
vec3 x = cross(a, camZ);
|
|
671
|
+
float xl = length(x);
|
|
672
|
+
x = xl > 1e-4 ? x / xl : camX;
|
|
673
|
+
offset = x * corner.y * custom.x;
|
|
674
|
+
suv = vec2(0.0, corner.y);
|
|
675
|
+
}
|
|
676
|
+
wp.xyz += offset;
|
|
677
|
+
vColor = color;
|
|
678
|
+
vCustom = custom;
|
|
679
|
+
vQuadUv = vec4(corner.x + 0.5, 0.5 - corner.y, suv.x, suv.y);
|
|
680
|
+
gl_Position = projectionMatrix * viewMatrix * wp;
|
|
681
|
+
}
|
|
682
|
+
`,Ia=`#version 300 es
|
|
683
|
+
precision highp float;
|
|
684
|
+
in vec4 vColor;
|
|
685
|
+
in vec4 vCustom;
|
|
686
|
+
in vec4 vQuadUv;
|
|
687
|
+
${$s}
|
|
688
|
+
uniform sampler2D emissiveMap;
|
|
689
|
+
uniform vec3 emissiveColor;
|
|
690
|
+
uniform float frameBlend;
|
|
691
|
+
out vec4 fragColor;
|
|
692
|
+
void main() {
|
|
693
|
+
vec2 uv = vQuadUv.xy;
|
|
694
|
+
float total = sheetSize.x * sheetSize.y;
|
|
695
|
+
float fidx = mod(vCustom.w, total);
|
|
696
|
+
float frame = floor(fidx);
|
|
697
|
+
int fi = int(frame + 0.5);
|
|
698
|
+
vec2 tuv = (sheetCell(fi) + uv) / sheetSize;
|
|
699
|
+
vec4 tex = texture(baseColorMap, tuv);
|
|
700
|
+
vec3 em = texture(emissiveMap, tuv).rgb;
|
|
701
|
+
if (frameBlend > 0.5) {
|
|
702
|
+
int ni = min(fi + 1, int(total + 0.5) - 1);
|
|
703
|
+
vec2 tuv2 = (sheetCell(ni) + uv) / sheetSize;
|
|
704
|
+
float f = fidx - frame;
|
|
705
|
+
tex = mix(tex, texture(baseColorMap, tuv2), f);
|
|
706
|
+
em = mix(em, texture(emissiveMap, tuv2).rgb, f);
|
|
707
|
+
}
|
|
708
|
+
float radial = 1.0 - smoothstep(0.0, 0.5, length(vQuadUv.zw));
|
|
709
|
+
float shape = mix(1.0, radial, clamp(softness, 0.0, 1.0));
|
|
710
|
+
float alpha = tex.a * vColor.a * vCustom.z * shape;
|
|
711
|
+
vec3 rgb = tex.rgb * vColor.rgb * (1.0 + emissive) + em * emissiveColor;
|
|
712
|
+
fragColor = vec4(tonemapParticle(rgb) * alpha, alpha * (1.0 - clamp(additive, 0.0, 1.0)));
|
|
713
|
+
}
|
|
714
|
+
`,Oa=2873840728,Da=t=>{const e=new DataView(t);if(e.getUint32(0,!1)!==Oa)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),f=n(52),g=Math.max(1,n(56)),m=n(60),h=new Map,v=new TextDecoder("utf-8");let M=64;const p=64+m;for(;M<p;){const x=n(M);M+=4;const T=new Uint8Array(t,M,x),B=T.indexOf(0),F=v.decode(T.subarray(0,B)),P=v.decode(T.subarray(B+1)).replace(/\0+$/,"");h.set(F,P),M+=x+(3-(x+3)%4)}const y=[];M=p;for(let x=0;x<g;x++){const T=n(M);M+=4;const B=[];for(let F=0;F<f;F++)B.push(new Uint8Array(t,M,T)),M+=T+(3-(T+3)%4);y.push(B)}return{glType:s,glFormat:i,glInternalFormat:l,width:o,height:a,faces:f,mipLevels:g,keyValues:h,mips:y}},Ua=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},ts=35898,za=35899,rs=6407,Va=(t,e)=>{const r=Da(e),n=Ua(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===ts;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 f=r.mips[l][a];if(i)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+a,l,ts,o,o,0,rs,za,new Uint32Array(f.buffer,f.byteOffset,f.byteLength/4));else{const g=r.glFormat===rs?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,f)}}}return t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAX_LEVEL,r.mipLevels-1),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR),s.store.image=s.image=r,s.needsUpdate=!1,{sh:n,cubemap:s,maxLod:r.mipLevels-1}},Ga=["EXT_meshopt_compression"],Ha=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))},ka=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},Wa={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},$a={5120:127,5121:255,5122:32767,5123:65535},ja={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},Rr=(t,e,r)=>{var a,f,g;const n=(a=t==null?void 0:t.accessors)==null?void 0:a[r],s=ja[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=(m,h,v,M,p,y)=>{var u;const x=new Float32Array(M*p),T=(u=t.bufferViews)==null?void 0:u[m],B=T?e[typeof T.buffer=="number"?T.buffer:0]:void 0,F=Wa[v];if(!T||!B||!F)return x;const P=F.BYTES_PER_ELEMENT,c=(T.byteOffset??0)+h;if(!y||y===p*P){const d=new F(B,c,M*p);for(let w=0;w<x.length;w++)x[w]=d[w]}else for(let d=0;d<M;d++){const w=new F(B,c+d*y,p);for(let S=0;S<p;S++)x[d*p+S]=w[S]}return x};if(n.bufferView!==void 0&&i.set(l(n.bufferView,n.byteOffset??0,n.componentType,n.count,s,((g=(f=t.bufferViews)==null?void 0:f[n.bufferView])==null?void 0:g.byteStride)??0)),n.sparse){const m=n.sparse,h=l(m.indices.bufferView,m.indices.byteOffset??0,m.indices.componentType,m.count,1,0),v=l(m.values.bufferView,m.values.byteOffset??0,n.componentType,m.count,s,0);for(let M=0;M<m.count;M++)for(let p=0;p<s;p++)i[h[M]*s+p]=v[M*s+p]}const o=n.normalized?$a[n.componentType]:void 0;if(o)for(let m=0;m<i.length;m++)i[m]=Math.max(i[m]/o,-1);return i};new qt;new qt;const Xa=(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,f=t?t[o*3+1]:o*3+1,g=t?t[o*3+2]:o*3+2;s.add(Math.min(a,f)*n+Math.max(a,f)),s.add(Math.min(f,g)*n+Math.max(f,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},qa=t=>new je(t,{image:new Uint8Array([255,255,255,255]),width:1,height:1,generateMipmaps:!1}),Ya=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},xr=8,Ka=(t,e,r,n)=>{var i,l,o,a,f,g;const s=e.nodes??[];for(let m=0;m<s.length;m++){const h=s[m].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 p=(l=r.nodes)==null?void 0:l[m],y=(o=r.meshes)==null?void 0:o[h];if(!p||!y)continue;const x=Math.max(...M.map(P=>{var c;return((c=P.targets)==null?void 0:c.length)??0})),T=new Float32Array(x),B=s[m].weights??v.weights;if(B)for(let P=0;P<Math.min(x,B.length);P++)T[P]=B[P];p.weights=T,x>xr&&console.warn(`[viewer-lite] GLB: mesh has ${x} morph targets — only the first ${xr} deform`);const F=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,u=F[P];if(!(c!=null&&c.length)||!(u!=null&&u.geometry))continue;const d=((g=(f=u.geometry.attributes)==null?void 0:f.position)==null?void 0:g.count)??0;if(d===0)continue;const w=Math.min(c.length,xr);if(c.slice(0,w).find(Y=>{const I=$=>{var G,q;return $!==void 0&&((q=(G=e.accessors)==null?void 0:G[$])==null?void 0:q.count)!==d};return I(Y.POSITION)||I(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),V=d*w*(N?2:1),L=Math.max(1,Math.ceil(Math.sqrt(V))),j=Math.max(1,Math.ceil(V/L)),X=new Float32Array(L*j*4);for(let Y=0;Y<w;Y++){const I=c[Y].POSITION!==void 0?Rr(e,n,c[Y].POSITION):null,$=N&&c[Y].NORMAL!==void 0?Rr(e,n,c[Y].NORMAL):null;for(let G=0;G<d;G++){if(I){const q=(Y*d+G)*4;X[q]=I[G*3]??0,X[q+1]=I[G*3+1]??0,X[q+2]=I[G*3+2]??0}if($){const q=((w+Y)*d+G)*4;X[q]=$[G*3]??0,X[q+1]=$[G*3+1]??0,X[q+2]=$[G*3+2]??0}}}const oe=new je(t,{image:X,width:L,height:j,type:t.FLOAT,format:t.RGBA,internalFormat:t.RGBA32F,generateMipmaps:!1,minFilter:t.NEAREST,magFilter:t.NEAREST,flipY:!1});u._morph={texture:oe,count:w,vertexCount:d,texWidth:L,hasNormals:N,weights:T}}}},ns=(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,p,y,x,T,B,F,P,c,u;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"),(p=o.normalTexture)!=null&&p.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"),(T=o.extensions)!=null&&T.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 f=a.join(`
|
|
715
|
+
`);ns(t,o.baseColorTexture),ns(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}};(B=o.baseColorTexture)!=null&&B.texture&&(g.uBaseColorMap={value:o.baseColorTexture.texture}),(F=o.metallicRoughnessTexture)!=null&&F.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}),(u=o.emissiveTexture)!=null&&u.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>xr?l.weights.subarray(0,xr):l.weights]});const m=(r?"HAS_SKIN ":"")+(n?"HAS_COLOR ":"")+(l?"HAS_MORPH ":"")+(l!=null&&l.hasNormals?"HAS_MORPH_NORMALS":""),h=new Ue(t,{vertex:Ws(m),fragment:Ta(f),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},Za=async(t,e,r,n)=>{var x,T,B,F,P,c,u;const s=Qn.unpackGLB(e),i=(s.extensionsRequired??[]).filter(d=>Ga.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 wr(()=>import("./index-BttBnvIf.js"),__vite__mapDeps([0,1]),import.meta.url);await Promise.all([o?d.ensureDracoDecoder():null,a?d.ensureBasisTranscoder(t):null])}Ha(s);const f=ka(s),g=await Qn.parse(t,s,""),m=(s.buffers??[]).map(d=>d.binary);Ka(t,s,g,m);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=((T=w==null?void 0:w.position)==null?void 0:T.count)??0;if(w&&S>0){if(!w.normal){const $=new Float32Array(S*3);for(let G=2;G<$.length;G+=3)$[G]=1;d.geometry.addAttribute("normal",{size:3,data:$})}w.uv||d.geometry.addAttribute("uv",{size:2,data:new Float32Array(S*2)})}const N=(B=d.program)==null?void 0:B.gltfMaterial,V=d instanceof Mt,L=(P=(F=d.geometry)==null?void 0:F.attributes)==null?void 0:P.color,j=!!L&&L.size===4,X=d._morph,Y=V||j||X?d:N??d;let I=h.get(Y);I||(I=Qa(t,N,V,j,r,n,X),h.set(Y,I)),d.program=I,d._receiveShadows=!0,d._castShadows=!0}g.images&&await Promise.all(g.images.map(d=>d==null?void 0:d.ready).filter(Boolean));const p=(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 f){const w=p[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:Rr(s,m,d.input),values:Rr(s,m,d.output)}),y++)}f.length>y&&console.warn(`[viewer-lite] GLB: ${f.length-y} morph (weights) animation channel(s) ignored — their nodes carry no usable morph targets`);for(const d of p){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??((u=g.scenes)==null?void 0:u[0])??[],nodes:g.nodes??[],animations:p}},Ja=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}},el={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])}},tl=`
|
|
716
|
+
struct MaterialInputs {
|
|
717
|
+
vec4 baseColor;
|
|
718
|
+
float roughness;
|
|
719
|
+
float metallic;
|
|
720
|
+
float reflectance;
|
|
721
|
+
float ambientOcclusion;
|
|
722
|
+
vec4 emissive;
|
|
723
|
+
vec3 normal;
|
|
724
|
+
float clearCoat;
|
|
725
|
+
float clearCoatRoughness;
|
|
726
|
+
vec4 postLightingColor;
|
|
727
|
+
};
|
|
728
|
+
void prepareMaterial(inout MaterialInputs m) {}
|
|
729
|
+
vec2 getUV0() { return vUv; }
|
|
730
|
+
vec2 getUV1() { return vUv; }
|
|
731
|
+
vec3 getWorldPosition() { return vWorldPos; }
|
|
732
|
+
vec3 getWorldGeometricNormalVector() { return normalize(vNormal); }
|
|
733
|
+
vec3 getWorldViewVector() { return normalize(cameraPosition - vWorldPos); }
|
|
734
|
+
vec4 getUserTime() { return userTime; }
|
|
735
|
+
`,Wr=`
|
|
736
|
+
MaterialInputs inputs;
|
|
737
|
+
inputs.baseColor = vec4(1.0);
|
|
738
|
+
inputs.roughness = 1.0;
|
|
739
|
+
inputs.metallic = 0.0;
|
|
740
|
+
inputs.reflectance = 0.5;
|
|
741
|
+
inputs.ambientOcclusion = 1.0;
|
|
742
|
+
inputs.emissive = vec4(0.0, 0.0, 0.0, 1.0);
|
|
743
|
+
inputs.normal = vec3(0.0, 0.0, 1.0);
|
|
744
|
+
inputs.clearCoat = 0.0;
|
|
745
|
+
inputs.clearCoatRoughness = 0.0;
|
|
746
|
+
inputs.postLightingColor = vec4(0.0);
|
|
747
|
+
material(inputs);
|
|
748
|
+
`,rl=`
|
|
749
|
+
vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
|
|
750
|
+
vec3 pos_dx = dFdx(vWorldPos);
|
|
751
|
+
vec3 pos_dy = dFdy(vWorldPos);
|
|
752
|
+
vec2 tex_dx = dFdx(vUv);
|
|
753
|
+
vec2 tex_dy = dFdy(vUv);
|
|
754
|
+
float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
|
|
755
|
+
if (abs(det) < 1e-8) return ng;
|
|
756
|
+
vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
|
|
757
|
+
t = normalize(t - ng * dot(ng, t));
|
|
758
|
+
vec3 b = normalize(cross(ng, t)) * sign(det);
|
|
759
|
+
return normalize(mat3(t, b, ng) * nTangent);
|
|
760
|
+
}
|
|
761
|
+
`,nl=`
|
|
762
|
+
vec3 tonemap(vec3 x) {
|
|
763
|
+
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;
|
|
764
|
+
vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
|
|
765
|
+
return pow(t, vec3(1.0 / 2.2));
|
|
766
|
+
}
|
|
767
|
+
`,sl=t=>{if(t.unsupported)return null;const e=[],r=[],n=new Set;for(const m of t.params){const h=el[m.type];if(!h)return null;e.push(`uniform ${h.decl} materialParams_${m.name}${m.size?`[${m.size}]`:""};`);const v=m.size?new Array(m.size*(Array.isArray(h.zero)||h.zero instanceof Float32Array?h.zero.length:1)).fill(0):h.zero;r.push({key:`materialParams_${m.name}`,value:Array.isArray(v)?[...v]:v}),n.add(m.name)}for(const m of t.samplers)e.push(`uniform sampler2D materialParams_${m.name};`),r.push({key:`materialParams_${m.name}`,value:"texture"}),n.add(m.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",f=t.shadowMultiplier?`
|
|
768
|
+
void main() {
|
|
769
|
+
${Wr}
|
|
770
|
+
float shadowAmount = 1.0 - sampleShadowPCF();
|
|
771
|
+
fragColor = vec4(inputs.baseColor.rgb * shadowAmount, inputs.baseColor.a * shadowAmount);
|
|
772
|
+
}
|
|
773
|
+
`:s?`
|
|
774
|
+
void main() {
|
|
775
|
+
${Wr}
|
|
776
|
+
${o}
|
|
777
|
+
vec3 n = normalize(vNormal);
|
|
778
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
779
|
+
${t.doubleSided?"if (dot(n, v) < 0.0) n = -n;":""}
|
|
780
|
+
${t.writesNormal?"n = applyTangentNormal(inputs.normal, n);":""}
|
|
781
|
+
vec3 diffuseColor = inputs.baseColor.rgb * (1.0 - inputs.metallic);
|
|
782
|
+
vec3 f0 = mix(vec3(0.16 * inputs.reflectance * inputs.reflectance), inputs.baseColor.rgb, inputs.metallic);
|
|
783
|
+
vec3 color = shadePBR(n, v, diffuseColor, f0, inputs.roughness, inputs.ambientOcclusion);
|
|
784
|
+
color += inputs.emissive.rgb * (iblLuminance * exposure);
|
|
785
|
+
color += inputs.postLightingColor.rgb;
|
|
786
|
+
fragColor = vec4(tonemap(color), ${a});
|
|
787
|
+
}
|
|
788
|
+
`:`
|
|
789
|
+
void main() {
|
|
790
|
+
${Wr}
|
|
791
|
+
${o}
|
|
792
|
+
vec3 color = inputs.baseColor.rgb + inputs.emissive.rgb + inputs.postLightingColor.rgb;
|
|
793
|
+
fragColor = vec4(tonemap(color), ${a});
|
|
794
|
+
}
|
|
795
|
+
`;return{fragment:`#version 300 es
|
|
796
|
+
precision highp float;
|
|
797
|
+
in vec3 vWorldPos;
|
|
798
|
+
in vec3 vNormal;
|
|
799
|
+
in vec2 vUv;
|
|
800
|
+
uniform vec3 cameraPosition;
|
|
801
|
+
uniform vec4 userTime;
|
|
802
|
+
${e.join(`
|
|
803
|
+
`)}
|
|
804
|
+
${i?Ar:nl}
|
|
805
|
+
${tl}
|
|
806
|
+
${t.writesNormal?rl:""}
|
|
807
|
+
out vec4 fragColor;
|
|
808
|
+
${t.fragmentCode}
|
|
809
|
+
${f}`,uniforms:r,paramNames:n,needsSceneUniforms:i}},st=10,ss=0,is=1;let il=null,Br=null;const ol=()=>il??(il=wr(()=>import("./creatorPhysics-k7wL0kV1.js"),__vite__mapDeps([2,1]),import.meta.url).then(t=>t.default()).then(t=>Br=t)),os=()=>Br!==null,it=(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)}},as=(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)}},Cr=(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)}},ls=t=>t instanceof Uint8Array?t:new Uint8Array(t),dr=(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,f=t[4]/s,g=t[5]/s,m=t[6]/s,h=t[8]/i,v=t[9]/i,M=t[10]/i,p=l+g+M;let y,x,T,B;if(p>0){const F=Math.sqrt(p+1)*2;B=.25*F,y=(m-v)/F,x=(h-a)/F,T=(o-f)/F}else if(l>g&&l>M){const F=Math.sqrt(1+l-g-M)*2;B=(m-v)/F,y=.25*F,x=(f+o)/F,T=(h+a)/F}else if(g>M){const F=Math.sqrt(1+g-l-M)*2;B=(h-a)/F,y=(f+o)/F,x=.25*F,T=(v+m)/F}else{const F=Math.sqrt(1+M-l-g)*2;B=(o-f)/F,y=(h+a)/F,x=(v+m)/F,T=.25*F}e[r]=t[12],e[r+1]=t[13],e[r+2]=t[14],e[r+3]=y,e[r+4]=x,e[r+5]=T,e[r+6]=B,e[r+7]=n,e[r+8]=s,e[r+9]=i},al=(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],f=t[10],g=t;g[0]=s*r-o*n,g[1]=i*r-a*n,g[2]=l*r-f*n,g[8]=s*n+o*r,g[9]=i*n+a*r,g[10]=l*n+f*r},ll=(t,e=1,r=1,n=1)=>{const s=Br;if(!s||t.length<12)return null;const i=it(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],f=o&&a?Float32Array.from(s.HEAPF32.subarray(o>>2,(o>>2)+a)):null;return o&&s._free(o),s._free(l),s._cphysShapeDestroy(i),f};function cl(t){const e=Br;if(!e)throw new Error("creator-physics: await loadCreatorPhysics() before createPhysicsBridge()");const r=e._malloc(st*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,f=new Map,g=(c,u)=>{if(!t.jointRanges)return;const d=u.entities.length,w=new Float32Array(d*9);if(it(e,w,Y=>{const I=e._cphysRagdollJointFrames(c,Y);return w.set(e.HEAPF32.subarray(Y>>2,(Y>>2)+d*9)),I})!==d)return;const N=[],V=[],L=[];for(let Y=0;Y<d;Y++){const I=w[Y*9];if(!(I<0)){N.push(u.entities[Y],u.entities[I]);for(let $=1;$<9;$++)V.push(w[Y*9+$]);L.push(Y)}}if(N.length===0)return;const j=t.jointRanges(u.entities[0],N,Float32Array.from(V));if(!j)return;const X=new Float32Array(d*6),oe=180/Math.PI;for(let Y=0;Y<L.length;Y++)for(let I=0;I<3;I++)X[L[Y]*6+I*2]=j[Y*6+I*2]*oe-u.margin,X[L[Y]*6+I*2+1]=j[Y*6+I*2+1]*oe+u.margin;it(e,X,Y=>e._cphysRagdollSetLimits(c,Y))&&(u.learned=!0)},m=new WeakMap;let h=null;const v=e.addFunction(c=>t.parentOf(c)|0,"ii");e._cphysSetParentLookup(v),e._cphysInit();const M=c=>(dr(t.world(c),e.HEAPF32,r>>2),r),p=(c,u)=>{const d=e.HEAPF32,w=u>>2;c[0]=d[w],c[1]=d[w+1],c[2]=d[w+2]},y=c=>{if(c===0)return;const u=e.HEAPU32,d=e._cphysPulledIds()>>2,w=e.HEAPF32,S=e._cphysPulledPoses()>>2;for(let N=0;N<c;N++){const V=S+N*st;t.setWorldTRS(u[d+N],w[V],w[V+1],w[V+2],w[V+3],w[V+4],w[V+5],w[V+6],w[V+7],w[V+8],w[V+9])}},x=c=>{if(c===0)return;const u=e.HEAPU32,d=e._cphysPulledIds()>>2,w=e.HEAPF32,S=e._cphysPulledPoses()>>2;for(let N=0;N<c;N++){const V=S+N*st;t.setWorldPosition(u[d+N],w[V],w[V+1],w[V+2])}},T=(c,u)=>{var N;const d=(N=t.glbBytes)==null?void 0:N.call(t,c);if(!d)return 0;let w=m.get(d);w||(w=[0,0],m.set(d,w));const S=u?1:0;if(!w[S]){const V=ls(d);w[S]=Cr(e,V,L=>e._cphysShapeMeshFromGlb(L,V.length,u?1:0))}return w[S]},B=(c,u,d,w,S,N)=>u?e._cphysBodyCreate(c,u,d|0,w,S?1:0,N?1:0,1,M(c)):0,F=(c,u,d,w)=>{const S=B(c,u,d,w,!1,!1);return u&&e._cphysShapeDestroy(u),S};return{methods:{physicsHasSupport:()=>!0,physicsConfigure(c,u,d,w){e._cphysConfigure(c,u,d,(w|0)>0?w|0:0)},setInterpolation(c){e._cphysSetInterpolation(c?1:0)},physicsBuildBox:(c,u,d)=>e._cphysShapeBox(c,u,d),physicsBuildSphere:c=>e._cphysShapeSphere(c),physicsBuildCylinder:(c,u)=>e._cphysShapeCylinder(c,u),physicsBuildCapsule:(c,u)=>e._cphysShapeCapsule(c,u),physicsBuildMesh(c,u,d,w,S,N){return it(e,c,V=>as(e,u,L=>e._cphysShapeMesh(V,Math.floor(c.length/3),L,u.length,d?1:0,w,S,N)))},physicsBuildMeshFromEntity(c,u,d,w,S){const N=T(c,u);return N?e._cphysShapeScaled(N,d,w,S):0},physicsBuildHeightField(c,u,d,w,S,N,V,L){return it(e,c,j=>S?Cr(e,S,X=>e._cphysShapeHeightField(j,u,d,w,X,N,V,L)):e._cphysShapeHeightField(j,u,d,w,0,N,V,L))},physicsUpdateHeightField(c,u,d,w,S,N,V,L,j){it(e,u,X=>j?Cr(e,j,oe=>e._cphysShapeUpdateHeightField(c,X,d,w,S,N,V,L,oe)):e._cphysShapeUpdateHeightField(c,X,d,w,S,N,V,L,0))},glbTriangles(c){var V;const u=(V=t.glbBytes)==null?void 0:V.call(t,c);if(!u)return new Float32Array(0);const d=ls(u),w=Cr(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,u,d,w){e._cphysShapeSetOrigin(c,u,d,w)},physicsSetBodyShape(c,u,d){e._cphysBodySetShape(c,u,d?1:0)},physicsDestroyShape(c){e._cphysShapeDestroy(c)},physicsCreateBody:(c,u,d,w,S,N)=>B(c,u,d,w,S,N),physicsSetPickable(c,u){e._cphysBodySetPickable(c,u?1:0)},physicsSetFriction(c,u){e._cphysBodySetFriction(c,u)},physicsGetFriction:c=>e._cphysBodyGetFriction(c),physicsRaycast(c,u,d,w,S,N,V,L){const j=e._cphysRaycast(c,u,d,w,S,N,V,n);return j&&L&&L.set(e.HEAPF32.subarray(n>>2,(n>>2)+Math.min(7,L.length))),j},physicsCreateBox:(c,u,d,w,S,N)=>F(c,e._cphysShapeBox(u,d,w),S,N),physicsCreateSphere:(c,u,d,w)=>F(c,e._cphysShapeSphere(u),d,w),physicsCreateCylinder:(c,u,d,w,S)=>F(c,e._cphysShapeCylinder(u,d),w,S),physicsSetLinearVelocity(c,u,d,w){e._cphysBodySetLinearVelocity(c,u,d,w)},physicsGetLinearVelocity(c,u){e._cphysBodyGetLinearVelocity(c,n),p(u,n)},physicsSetAngularVelocity(c,u,d,w){e._cphysBodySetAngularVelocity(c,u,d,w)},physicsGetAngularVelocity(c,u){e._cphysBodyGetAngularVelocity(c,n),p(u,n)},physicsApplyImpulse(c,u,d,w){e._cphysBodyApplyImpulse(c,u,d,w)},physicsApplyImpulseAt(c,u,d,w,S,N,V){e._cphysBodyApplyImpulseAt(c,u,d,w,S,N,V)},physicsSetBodyPosition(c,u,d,w){e._cphysBodySetPosition(c,u,d,w)},physicsSetBodyRotation(c,u,d,w,S){e._cphysBodySetRotation(c,u,d,w,S)},physicsRemoveBody(c){e._cphysBodyRemove(c)},characterCreate(c,u,d){const w=u?e._cphysCharacterCreate(c,u,d,M(c)):0;return w&&a.set(w,c),w},characterDestroy(c){e._cphysCharacterDestroy(c),a.delete(c)},characterMove(c,u,d){e._cphysCharacterMove(c,u,d)},characterMoveFree(c,u,d,w){e._cphysCharacterMoveFree(c,u,d,w)},characterSetVerticalVelocity(c,u){e._cphysCharacterSetVerticalVelocity(c,u)},characterSetVelocity(c,u,d,w){e._cphysCharacterSetVelocity(c,u,d,w)},characterSetGravityScale(c,u){e._cphysCharacterSetGravityScale(c,u)},characterSetMaxSlope(c,u){e._cphysCharacterSetMaxSlope(c,u)},characterSetShape(c,u){if(!e._cphysCharacterSetShape(c,u))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,u){e._cphysCharacterGetVelocity(c,n),p(u,n)},characterGetGroundState:c=>e._cphysCharacterGetGroundState(c),characterSetPosition(c,u,d,w){e._cphysCharacterSetPosition(c,u,d,w)},vehicleCreate(c,u,d){return u?it(e,d,w=>e._cphysVehicleCreate(c,u,w,d.length,M(c))):0},vehicleDestroy(c){e._cphysVehicleDestroy(c)},vehicleSetInput(c,u){it(e,u,d=>e._cphysVehicleSetInput(c,d,u.length))},vehicleSetTuning(c,u){it(e,u,d=>e._cphysVehicleSetTuning(c,d,u.length))},vehicleGetState(c,u){const d=o(u.length);e._cphysVehicleGetState(c,d,u.length),u.set(e.HEAPF32.subarray(d>>2,(d>>2)+u.length))},vehicleReset(c,u,d,w,S,N,V,L){e._cphysVehicleReset(c,u,d,w,S,N,V,L)},vehicleBodyId:c=>e._cphysVehicleBodyId(c),ragdollCreate(c,u,d){const w=d.length>1?d[1]|0:0;if(w<=0||u.length<w*2)return 0;const S=new Float32Array(st);dr(t.world(c),S,0);const N=new Float32Array(w*(st+3)),V=[];for(let j=0;j<w;j++){const X=j*(st+3);dr(t.world(u[j*2]),N,X),V.push(u[j*2]);const oe=u[j*2+1];if(oe){const Y=t.world(oe);N[X+st]=Y[12],N[X+st+1]=Y[13],N[X+st+2]=Y[14]}}const L=it(e,S,j=>as(e,u,X=>it(e,N,oe=>it(e,d,Y=>e._cphysRagdollCreate(j,X,u.length,oe,Y,d.length)))));return L&&f.set(L,{entities:V,prev:new Float32Array(w*st),cur:new Float32Array(w*st),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),f.delete(c)},ragdollActivate(c,u,d,w){const S=f.get(c);if(!S)return!1;!S.active&&S.learn&&!S.learned&&g(c,S);const N=S.entities.length,V=new Float32Array(N*st);for(let X=0;X<N;X++)dr(t.world(S.entities[X]),V,X*st);let L=null;if(!S.active&&S.valid>=2&&S.dt>1e-5){L=new Float32Array(N*6);const X=1/S.dt;for(let oe=0;oe<N;oe++){const Y=oe*st,I=oe*6;L[I]=(S.cur[Y]-S.prev[Y])*X,L[I+1]=(S.cur[Y+1]-S.prev[Y+1])*X,L[I+2]=(S.cur[Y+2]-S.prev[Y+2])*X;const $=S.prev[Y+3],G=S.prev[Y+4],q=S.prev[Y+5],ae=S.prev[Y+6],J=S.cur[Y+3],te=S.cur[Y+4],de=S.cur[Y+5],ve=S.cur[Y+6];let pe=ve*-$+J*ae+te*-q-de*-G,ze=ve*-G-J*-q+te*ae+de*-$,Xe=ve*-q+J*-G-te*-$+de*ae,b=ve*ae-J*-$-te*-G-de*-q;b<0&&(pe=-pe,ze=-ze,Xe=-Xe,b=-b);const C=Math.sqrt(Math.max(0,1-b*b));if(C>1e-6){const R=2*Math.acos(Math.min(1,b))/C*X;L[I+3]=pe*R,L[I+4]=ze*R,L[I+5]=Xe*R}}}const j=it(e,V,X=>L?it(e,L,oe=>e._cphysRagdollActivate(c,u,d,w,X,oe)):e._cphysRagdollActivate(c,u,d,w,X,0))!==0;return j&&(S.active=!0),j},ragdollDeactivate(c,u){var w;const d=f.get(c);d!=null&&d.active&&(y(e._cphysRagdollPose(c)),u>0&&d.entities.length>0&&((w=t.seedAnimator)==null||w.call(t,d.entities[0],u)),d.active=!1,d.valid=0),e._cphysRagdollDeactivate(c)},ragdollSetDrive(c,u,d){const w=f.get(c);w&&(w.driven=u>0||d),e._cphysRagdollSetDrive(c,u,d?1:0)},ragdollActive:c=>e._cphysRagdollActive(c)!==0,ragdollBodyId:(c,u)=>e._cphysRagdollBodyId(c,u),setOnPhysicsEvent(c){h=c}},frame(c,u){const d=e._cphysFrameBegin(c),w=e._cphysFixedDt();for(let N=0;N<d;N++)u&&(y(e._cphysPullBodies(is)),x(e._cphysPullCharacters(is)),u(w)),e._cphysStep();e._cphysFrameEnd(),y(e._cphysPullBodies(ss)),x(e._cphysPullCharacters(ss));const S=e._cphysEventCount();if(S>0&&h){const N=e._cphysEventData()>>2,V=Array.from(e.HEAPU32.subarray(N,N+S*3));for(let L=0;L<S;L++)h(V[L*3],V[L*3+1],V[L*3+2])}},syncRagdolls(c){if(f.size!==0){for(const[u,d]of f){const w=d.prev;d.prev=d.cur,d.cur=w;for(let S=0;S<d.entities.length;S++)dr(t.world(d.entities[S]),d.cur,S*st);c>1e-5&&(d.dt=c),d.valid<2&&d.valid++,d.active&&d.driven&&it(e,d.cur,S=>e._cphysRagdollSetTarget(u,S))}y(e._cphysPullRagdolls())}},applyRootMotion(c,u,d,w,S){for(let N=c;N;N=t.parentOf(N)){const V=e._cphysCharacterForEntity(N);if(V){if(e._cphysCharacterSetExternalVelocity(V,w>0?u/w:0,w>0?d/w:0),S!==0){const L=t.get(N);L&&(al(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(),f.clear()}}}const cs={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},Fe=Math.fround,hs=Fe(1/3),hl=Fe(1/6),us=Fe(2/3),ul=Fe(3.14159265),fl=Fe(.9),sn=t=>t===32||t>=9&&t<=13,Er=t=>t>=48&&t<=57,Nr=t=>t>=65&&t<=90?t+32:t,fs=t=>{const e=Nr(t);return e>=97&&e<=122},dl=t=>{const e=Nr(t);return e>=48&&e<=57?e-48:e>=97&&e<=102?e-87:-1},Ot=(t,e,r,n)=>{if(r!==n.length)return!1;for(let s=0;s<r;s++)if(Nr(t.charCodeAt(e+s))!==n.charCodeAt(s))return!1;return!0},pl=(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&&Er(t.charCodeAt(n));)n++,s++;if(n<r&&t.charCodeAt(n)===46){let l=n+1;for(;l<r&&Er(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&&Er(t.charCodeAt(l))){for(;l<r&&Er(t.charCodeAt(l));)l++;n=l}}return n-e},ml=(t,e,r)=>{const n=[];let s=e;for(;s<r;){for(;s<r&&(sn(t.charCodeAt(s))||t.charCodeAt(s)===44||t.charCodeAt(s)===47);)s++;if(s>=r)break;const i=pl(t,s,r);if(i===0||i>=64)return null;let l=Fe(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&&fs(t.charCodeAt(s))){const a=s;for(;s<r&&fs(t.charCodeAt(s));)s++;const f=s-a;if(!Ot(t,a,f,"deg"))if(Ot(t,a,f,"rad"))l=Fe(l*180),l=Fe(l/ul);else if(Ot(t,a,f,"turn"))l=Fe(l*360);else if(Ot(t,a,f,"grad"))l=Fe(l*fl);else return null}if(!Number.isFinite(l)||n.length===4)return null;n.push({v:l,percent:o})}return n.length>=3?n:null},Wt=t=>t<0?0:t>1?1:t,$r=(t,e,r)=>{r<0&&(r=Fe(r+1)),r>1&&(r=Fe(r-1));const n=Fe(e-t);return r<hl?Fe(t+Fe(Fe(n*6)*r)):r<.5?e:r<us?Fe(t+Fe(Fe(n*Fe(us-r))*6)):t},jr=(t,e,r,n)=>({r:Fe(t/255),g:Fe(e/255),b:Fe(r/255),a:Fe(n/255)}),gl=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&&sn(r.charCodeAt(n));)n++;for(;s>n&&sn(r.charCodeAt(s-1));)s--;const i=s-n;if(i===0)return null;if(r.charCodeAt(n)===35){const f=i-1;if(f!==3&&f!==4&&f!==6&&f!==8)return null;const g=[];for(let m=0;m<f;m++){const h=dl(r.charCodeAt(n+1+m));if(h<0)return null;g.push(h)}return f<=4?jr(g[0]*17,g[1]*17,g[2]*17,f===4?g[3]*17:255):jr(g[0]*16+g[1],g[2]*16+g[3],g[4]*16+g[5],f===8?g[6]*16+g[7]:255)}const l=r.indexOf("(",n);if(l>=0&&l<s&&r.charCodeAt(s-1)===41){const f=ml(r,l+1,s-1);if(!f)return null;const g=f.length===4?Wt(f[3].percent?Fe(f[3].v/100):f[3].v):1,m=l-n;if(Ot(r,n,m,"rgb")||Ot(r,n,m,"rgba")){const h=v=>Wt(v.percent?Fe(v.v/100):Fe(v.v/255));return{r:h(f[0]),g:h(f[1]),b:h(f[2]),a:g}}if(Ot(r,n,m,"hsl")||Ot(r,n,m,"hsla")){let h=f[0].v%360;h<0&&(h=Fe(h+360)),h=Fe(h/360);const v=Wt(Fe(f[1].v/100)),M=Wt(Fe(f[2].v/100));if(v<=0)return{r:M,g:M,b:M,a:g};const p=M<.5?Fe(M*Fe(1+v)):Fe(Fe(M+v)-Fe(M*v)),y=Fe(Fe(2*M)-p);return{r:Wt($r(y,p,Fe(h+hs))),g:Wt($r(y,p,h)),b:Wt($r(y,p,Fe(h-hs))),a:g}}return null}if(i>20)return null;let o="";for(let f=n;f<s;f++)o+=String.fromCharCode(Nr(r.charCodeAt(f)));if(!Object.prototype.hasOwnProperty.call(cs,o))return null;const a=cs[o];return jr(a>>>24,a>>>16&255,a>>>8&255,a&255)},Dt=t=>{const e=Fe(t);if(!(e>0))return 0;if(e>=1)return 255;const r=Fe(e*255);return Math.floor(Fe(r+.5))},Xr=Math.fround,yl=t=>{if(typeof t=="number")return!Number.isInteger(t)||t<0||t>16777215?null:[Xr((t>>16&255)/255),Xr((t>>8&255)/255),Xr((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},js=t=>{if(typeof t=="string"){const e=gl(t);return e?[e.r,e.g,e.b,e.a]:null}return yl(t)},qr=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),vl=t=>{throw typeof t=="number"?new RangeError(`Color: ${qr(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: ${qr(t)} is not a CSS color`):new TypeError(`Color: ${qr(t)} is not a color — a string, an 0xRRGGBB number or [r, g, b(, a)] in 0..1`)},Pr=t=>js(t)??vl(t),ds=t=>{const e=Pr(t);return[Dt(e[0]),Dt(e[1]),Dt(e[2]),Dt(e[3])]},Fr=t=>(t<16?"0":"")+t.toString(16),xl=t=>"#"+Fr(Dt(t[0]))+Fr(Dt(t[1]))+Fr(Dt(t[2]))+Fr(Dt(t[3])),wl={toRgb01(t){const e=Pr(t);return[e[0],e[1],e[2]]},toRgba01(t){return Pr(t)},toPackedRgb(t){const e=ds(t);return e[0]<<16|e[1]<<8|e[2]},toPackedRgba(t){const e=ds(t);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0},toHexString(t){return xl(Pr(t))},tryParse(t){return js(t)}},Ml=.0025,ps=1,ms=.85,Al=.13,Sl=.1,bl=5,_l=8,gs=15*Math.PI/180,Cl=[[.93,.16,.12],[.42,.9,.16],[.16,.35,1]],El=[.85,.85,.88],ys=t=>[t[0]*.5+.5,t[1]*.5+.5,t[2]*.5+.5],vs=[.941,.396,.243],Fl=[.36,.92,.48],Tl=.85,$e=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],lr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],cr=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],et=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],on=(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]],or=t=>Math.hypot(t[0],t[1],t[2]),hr=t=>{const e=or(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},nr=(t,e,r,n)=>{const s=et(e,n);if(Math.abs(s)<1e-6)return null;const i=et($e(r,t),n)/s;return i<=0?null:lr(t,cr(e,i))},xs=(t,e,r,n,s)=>{const i=$e(t,r),l=et(n,e),o=et(n,i),a=et(e,i),f=1-l*l,g=Math.abs(f)<1e-8?o:(o-l*a)/f,m=Math.max(0,Math.min(s,g)),h=lr(r,cr(n,m)),v=Math.max(0,et($e(h,t),e));return{dist:or($e(h,lr(t,cr(e,v)))),t:m}},Pl=(t,e,r)=>{const n=on(hr($e(t,r)),e),s=on(e,n);return et(s,s)<1e-4?hr($e(t,r)):hr(s)},Rl=(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},Bl=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,f=t[6]/r,g=t[8]/n,m=t[9]/n,h=t[10]/n,v=s+a+h;let M,p,y,x;if(v>0){const T=.5/Math.sqrt(v+1);x=.25/T,M=(f-m)*T,p=(g-l)*T,y=(i-o)*T}else if(s>a&&s>h){const T=2*Math.sqrt(1+s-a-h);x=(f-m)/T,M=.25*T,p=(o+i)/T,y=(g+l)/T}else if(a>h){const T=2*Math.sqrt(1+a-s-h);x=(g-l)/T,M=(o+i)/T,p=.25*T,y=(m+f)/T}else{const T=2*Math.sqrt(1+h-s-a);x=(i-o)/T,M=(g+l)/T,p=(m+f)/T,y=.25*T}return{position:[t[12],t[13],t[14]],quaternion:[M,p,y,x],scale:[e,r,n]}},Nl=`#version 300 es
|
|
810
|
+
precision highp float;
|
|
811
|
+
in vec3 position;
|
|
812
|
+
in vec3 normal;
|
|
813
|
+
uniform mat4 modelViewMatrix;
|
|
814
|
+
uniform mat4 projectionMatrix;
|
|
815
|
+
uniform mat3 normalMatrix;
|
|
816
|
+
out vec3 vN;
|
|
817
|
+
void main() {
|
|
818
|
+
vN = normalize(normalMatrix * normal);
|
|
819
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
820
|
+
}
|
|
821
|
+
`,Ll=`#version 300 es
|
|
822
|
+
precision highp float;
|
|
823
|
+
in vec3 vN;
|
|
824
|
+
uniform vec3 uColor;
|
|
825
|
+
out vec4 fragColor;
|
|
826
|
+
void main() { fragColor = vec4(uColor * (0.72 + 0.28 * abs(vN.z)), 1.0); }
|
|
827
|
+
`,Il=`#version 300 es
|
|
828
|
+
precision highp float;
|
|
829
|
+
in vec3 position;
|
|
830
|
+
uniform mat4 modelMatrix;
|
|
831
|
+
uniform mat4 modelViewMatrix;
|
|
832
|
+
uniform mat4 projectionMatrix;
|
|
833
|
+
out vec3 vWorld;
|
|
834
|
+
void main() {
|
|
835
|
+
vWorld = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
836
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
837
|
+
}
|
|
838
|
+
`,Ol=`#version 300 es
|
|
839
|
+
precision highp float;
|
|
840
|
+
in vec3 vWorld;
|
|
841
|
+
uniform vec3 uColor;
|
|
842
|
+
uniform vec3 uOrigin;
|
|
843
|
+
uniform vec3 uEye;
|
|
844
|
+
uniform float uFull;
|
|
845
|
+
out vec4 fragColor;
|
|
846
|
+
void main() {
|
|
847
|
+
if (uFull < 0.5 && dot(vWorld - uOrigin, uOrigin - uEye) > 0.0) discard;
|
|
848
|
+
fragColor = vec4(uColor, 1.0);
|
|
849
|
+
}
|
|
850
|
+
`,Yr=`#version 300 es
|
|
851
|
+
precision highp float;
|
|
852
|
+
in vec3 position;
|
|
853
|
+
uniform mat4 modelViewMatrix;
|
|
854
|
+
uniform mat4 projectionMatrix;
|
|
855
|
+
void main() { gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }
|
|
856
|
+
`,Kr=`#version 300 es
|
|
857
|
+
precision highp float;
|
|
858
|
+
uniform vec3 uColor;
|
|
859
|
+
uniform float uAlpha;
|
|
860
|
+
out vec4 fragColor;
|
|
861
|
+
void main() { fragColor = vec4(uColor * uAlpha, uAlpha); }
|
|
862
|
+
`,Dl=`#version 300 es
|
|
863
|
+
in vec2 position;
|
|
864
|
+
in vec2 uv;
|
|
865
|
+
out vec2 vUv;
|
|
866
|
+
void main() { vUv = uv; gl_Position = vec4(position, 0.0, 1.0); }
|
|
867
|
+
`,Ul=`#version 300 es
|
|
868
|
+
precision highp float;
|
|
869
|
+
in vec2 vUv;
|
|
870
|
+
uniform sampler2D tMask;
|
|
871
|
+
uniform vec2 uTexel;
|
|
872
|
+
uniform vec3 uColor;
|
|
873
|
+
out vec4 fragColor;
|
|
874
|
+
void main() {
|
|
875
|
+
float center = texture(tMask, vUv).r;
|
|
876
|
+
float edge = 0.0;
|
|
877
|
+
for (int x = -2; x <= 2; x++) {
|
|
878
|
+
for (int y = -2; y <= 2; y++) {
|
|
879
|
+
edge = max(edge, texture(tMask, vUv + vec2(float(x), float(y)) * uTexel).r);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
float a = clamp(edge - center, 0.0, 1.0);
|
|
883
|
+
if (a < 0.02) discard;
|
|
884
|
+
fragColor = vec4(uColor * a, a);
|
|
885
|
+
}
|
|
886
|
+
`,zl=t=>{const{gl:e,renderer:r,canvas:n,camera:s,core:i}=t;let l={},o=!1,a=null,f=null,g="global";const m=.1,h=.22,v=[],M=new ct;{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 k=(K,ne)=>{const ie=new Ue(e,{vertex:Yr,fragment:Kr,uniforms:{uColor:{value:[1,1,1]},uAlpha:{value:ne}},transparent:!0});ie.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),v.push(ie);const ue=new ot(e,{position:{size:3,data:Float32Array.from(K)}}),fe=new Je(e,{geometry:ue,program:ie,mode:e.LINES});return fe.frustumCulled=!1,fe};M.addChild(k(Z,m)),M.addChild(k([-10,.001,0,10,.001,0,0,.001,-10,0,.001,10],h))}let p=-1;const y=z=>{const k=.2126*(z[0]??0)+.7152*(z[1]??0)+.0722*(z[2]??0)>.5?0:1;if(k!==p){p=k;for(const K of v)K.uniforms.uColor.value=[k,k,k]}},x=new Ue(e,{vertex:Nl,fragment:Ll,uniforms:{uColor:{value:[1,1,1]}}}),T=new Ue(e,{vertex:Il,fragment:Ol,uniforms:{uColor:{value:[1,1,1]},uOrigin:{value:[0,0,0]},uEye:{value:[0,0,0]},uFull:{value:0}}});let B=null,F=null;const P=new ct;P.matrixAutoUpdate=!1;const c=(z,Z,k=x)=>(z._axis=Z,z.frustumCulled=!1,z.onBeforeRender(()=>{const K=F?F.axis:B,ne=Z===3?El:Cl[Z];k.uniforms.uColor.value=K===Z?ys(ne):ne}),z),u=(z,Z)=>{const k=new ct;return Z===0?k.rotation.z=-Math.PI/2:Z===2&&(k.rotation.x=Math.PI/2),k.setParent(z),k},d=new ct,w=new ct,S=new ct;for(const z of[d,w,S])z.setParent(P);{const z=new zn(e,{radiusTop:.014,radiusBottom:.014,height:.78,radialSegments:6}),Z=new zn(e,{radiusTop:.001,radiusBottom:.065,height:.26,radialSegments:12}),k=new Un(e,{width:.1,height:.1,depth:.1}),K=new Un(e,{width:.14,height:.14,depth:.14}),ne=new jo(e,{radius:ms,tube:.02,radialSegments:8,tubularSegments:64});for(let ie=0;ie<3;ie++){const ue=u(d,ie),fe=c(new Je(e,{geometry:z,program:x}),ie);fe.position.y=.39;const me=c(new Je(e,{geometry:Z,program:x}),ie);me.position.y=.87,ue.addChild(fe),ue.addChild(me);const ye=u(S,ie),Ae=c(new Je(e,{geometry:z,program:x}),ie);Ae.position.y=.39;const ge=c(new Je(e,{geometry:k,program:x}),ie);ge.position.y=.83,ye.addChild(Ae),ye.addChild(ge);const we=c(new Je(e,{geometry:ne,program:T}),ie,T);ie===0?we.rotation.y=Math.PI/2:ie===1&&(we.rotation.x=Math.PI/2),w.addChild(we)}S.addChild(c(new Je(e,{geometry:K,program:x}),3))}const N=()=>{if(a===null||f===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 k=i.worldMatrixF(a),K=[k[12],k[13],k[14]],ie=g==="local"||f==="scale"?[0,1,2].map(ye=>hr([k[ye*4],k[ye*4+1],k[ye*4+2]])):[[1,0,0],[0,1,0],[0,0,1]],ue=i.worldMatrixF(Z.camera),fe=[ue[12],ue[13],ue[14]],me=or($e(K,fe))||1;return{origin:K,axes:ie,scale:me*Ml*i.projectionOf(z).fov,camPos:fe,sceneId:z}},V=()=>{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=f==="translate",w.visible=f==="rotate",S.visible=f==="scale";const k=T.uniforms;k.uOrigin.value=z.origin,k.uEye.value=z.camPos,k.uFull.value=F&&f==="rotate"?1:0;for(const K of[d,w,S])K.traverse(ne=>{ne._axis!==void 0&&(ne.visible=F===null||ne._axis===F.axis)});return!0},L=(z,Z)=>{const k=N();if(!k)return null;const{origin:K,dir:ne}=t.getViewRay(k.sceneId,z,Z),ie=Sl*k.scale;if(f==="rotate"){const me=hr($e(k.origin,k.camPos));let ye=null,Ae=1/0;for(let ge=0;ge<3;ge++){const we=nr(K,ne,k.origin,k.axes[ge]);if(!we||et($e(we,k.origin),me)>0)continue;const Re=Math.abs(or($e(we,k.origin))-ms*k.scale),Te=or($e(we,K));Re<ie&&Te<Ae&&(ye=ge,Ae=Te)}return ye}if(f==="scale"){const{dist:me}=xs(K,ne,k.origin,hr(ne),0);if(me<Al*k.scale)return 3}let ue=null,fe=ie;for(let me=0;me<3;me++){const{dist:ye}=xs(K,ne,k.origin,k.axes[me],(ps+.05)*k.scale);ye<=fe&&(fe=ye,ue=me)}return ue},j=z=>{const Z=n.getBoundingClientRect(),k=gn(n);return[(z.clientX-Z.left)/k,(z.clientY-Z.top)/k]},X=(z,Z)=>{const k=N();if(!k||a===null)return!1;const K=a,ne=i.ent(K),ie=Float32Array.from(ne.m),ue=ne.parent!==0?i.worldMatrixF(ne.parent):He(),fe=St(Float32Array.from(ue)),me=dt(new Float32Array(16),ue,ie),[ye]=j(Z);let Ae=null;if(z===3)Ae=Pe=>{const[ce]=j(Pe),We=Math.max(.01,1+(ce-ye)/150),Ke=Float32Array.from(ie);for(let Qe=0;Qe<3;Qe++)for(let A=0;A<3;A++)Ke[Qe*4+A]*=We;i.methods.setMatrix(K,Ke)};else if(f==="rotate"){const Pe=k.axes[z],{origin:ce,dir:We}=t.getViewRay(k.sceneId,...j(Z)),Ke=nr(ce,We,k.origin,Pe);if(!Ke)return!1;const Qe=$e(Ke,k.origin);Ae=A=>{const _=t.getViewRay(k.sceneId,...j(A)),E=nr(_.origin,_.dir,k.origin,Pe);if(!E)return;const O=$e(E,k.origin);let U=Math.atan2(et(on(Qe,O),Pe),et(Qe,O));A.ctrlKey&&(U=Math.round(U/gs)*gs);const H=Rl(Pe,U),Q=[0,0,0];At(Q,H,k.origin[0],k.origin[1],k.origin[2],1),H[12]=k.origin[0]-Q[0],H[13]=k.origin[1]-Q[1],H[14]=k.origin[2]-Q[2];const ee=dt(new Float32Array(16),H,me),he=ne.parent!==0?dt(new Float32Array(16),fe,ee):ee;i.methods.setMatrix(K,he)}}else{const Pe=k.axes[z],ce=Pl(k.origin,Pe,k.camPos),{origin:We,dir:Ke}=t.getViewRay(k.sceneId,...j(Z)),Qe=nr(We,Ke,k.origin,ce);if(!Qe)return!1;if(f==="translate"){const A=[me[12],me[13],me[14]];Ae=_=>{const E=t.getViewRay(k.sceneId,...j(_)),O=nr(E.origin,E.dir,k.origin,ce);if(!O)return;const U=et($e(O,Qe),Pe),H=lr(A,cr(Pe,U)),Q=[0,0,0];ne.parent!==0?At(Q,fe,H[0],H[1],H[2],1):(Q[0]=H[0],Q[1]=H[1],Q[2]=H[2]),i.methods.setPosition(K,Q[0],Q[1],Q[2])}}else Ae=A=>{const _=t.getViewRay(k.sceneId,...j(A)),E=nr(_.origin,_.dir,k.origin,ce);if(!E)return;const O=Math.max(.01,1+et($e(E,Qe),Pe)/(ps*k.scale)),U=Float32Array.from(ie);for(let H=0;H<3;H++)U[z*4+H]*=O;i.methods.setMatrix(K,U)}}if(!Ae)return!1;const ge=n.ownerDocument.defaultView??window,we=Z.pointerId,Re=Pe=>{Pe.pointerId===we&&(F==null||F.onMove(Pe))},Te=Pe=>{var We;if(!F)return;const ce=F;F=null,ce.cleanup(),Pe?(We=l.onTransformEnd)==null||We.call(l,K,Bl(i.ent(K).m),f):i.methods.setMatrix(K,ce.startLocal)},Ne=Pe=>{Pe.pointerId===we&&Te(!0)},Oe=()=>Te(!1),Be=Pe=>{Pe.code==="Escape"&&Te(!1)};return ge.addEventListener("pointermove",Re),ge.addEventListener("pointerup",Ne),ge.addEventListener("pointercancel",Oe),ge.addEventListener("keydown",Be),F={axis:z,startLocal:ie,onMove:Ae,cleanup:()=>{ge.removeEventListener("pointermove",Re),ge.removeEventListener("pointerup",Ne),ge.removeEventListener("pointercancel",Oe),ge.removeEventListener("keydown",Be)}},!0},oe=new ea,Y=(z,Z)=>{var Ae,ge;const k=i.activeSceneId(),K=t.sceneRoots.get(k),ne=i.scenes.get(k);if(!K||!ne||ne.camera===void 0)return 0;const{origin:ie,dir:ue}=t.getViewRay(k,z,Z);oe.origin.set(ie[0],ie[1],ie[2]),oe.direction.set(ue[0],ue[1],ue[2]);const fe=[],me=[];for(const we of t.collectMeshes(K)){const Re=(ge=(Ae=we.geometry)==null?void 0:Ae.attributes)==null?void 0:ge.position;if(!(Re!=null&&Re.data))continue;const Te=Re.stride&&Re.stride!==Re.size*Re.data.BYTES_PER_ELEMENT;we.mode===e.TRIANGLES&&!Te?fe.push(we):me.push(we)}K.updateMatrixWorld();let ye=null;try{for(const we of oe.intersectMeshes(fe,{cullFace:!1,includeUV:!1,includeNormal:!1,output:[]}))(!ye||we.hit.distance<ye.hit.distance)&&(ye=we)}catch{}try{for(const we of oe.intersectBounds(me,{output:[]}))(!ye||we.hit.distance<ye.hit.distance)&&(ye=we)}catch{}return(ye==null?void 0:ye._entId)??0};let I=null;const $=z=>{if(z.button!==0||z.shiftKey||F)return;const[Z,k]=j(z),K=L(Z,k);if(K!==null&&X(K,z)){z.preventDefault(),z.stopPropagation(),I=null;return}I={pointerId:z.pointerId,x:z.clientX,y:z.clientY}},G=z=>{var ne;const Z=I;if(I=null,!Z||Z.pointerId!==z.pointerId||Math.abs(z.clientX-Z.x)+Math.abs(z.clientY-Z.y)>bl)return;const[k,K]=j(z);(ne=l.onPick)==null||ne.call(l,Ee(k,K)||Y(k,K))},q=z=>{if(F)return;const[Z,k]=j(z),K=f!==null&&a!==null?L(Z,k):null,ne=K===null&&C.length>0&&Ee(Z,k)||null;(K!==B||ne!==R)&&(B=K,R=ne,n.style.cursor=K!==null||ne!==null?"pointer":"")};n.addEventListener("pointerdown",$),n.addEventListener("pointerup",G),n.addEventListener("pointermove",q);const ae=new Ue(e,{vertex:Yr,fragment:Kr,uniforms:{uColor:{value:Fl},uAlpha:{value:Tl}},transparent:!0,depthTest:!1,depthWrite:!1});ae.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const J=z=>new ot(e,{position:{size:3,data:Float32Array.from(z)}}),te=(z,Z,k,K,ne=32)=>{for(let ie=0;ie<ne;ie++)for(const ue of[Math.PI*2*ie/ne,Math.PI*2*(ie+1)/ne]){const fe=Math.cos(ue)*Z,me=Math.sin(ue)*Z;K===1?z.push(fe,k,me):K===0?z.push(k,fe,me):z.push(fe,me,k)}},de=J((()=>{const z=[],Z=k=>[k&1?1:-1,k&2?1:-1,k&4?1:-1];for(let k=0;k<8;k++)for(const K of[1,2,4])k&K||z.push(...Z(k),...Z(k|K));return z})()),ve=J((()=>{const z=[];return te(z,1,0,0),te(z,1,0,1),te(z,1,0,2),z})()),pe=new Map,ze=(z,Z,k)=>{const K=`${z}:${Z}:${k}`;let ne=pe.get(K);if(ne)return ne;const ie=[];te(ie,k,Z,1),te(ie,k,-Z,1);for(const[ue,fe]of[[k,0],[-k,0],[0,k],[0,-k]])ie.push(ue,-Z,fe,ue,Z,fe);if(z==="capsule")for(const fe of[!0,!1])for(const me of[0,2])for(let ye=0;ye<12;ye++)for(const Ae of[Math.PI*ye/12,Math.PI*(ye+1)/12]){const ge=Math.cos(Ae)*k,we=(fe?Z:-Z)+Math.sin(Ae)*k*(fe?1:-1);me===0?ie.push(ge,we,0):ie.push(0,we,ge)}return ne=J(ie),pe.size>64&&pe.clear(),pe.set(K,ne),ne},Xe=new ct,b=[],C=[];let R=null;const W=[.81,.83,.87,1],se=z=>{var Z,k;for(const K of b)K.setParent(null),(k=(Z=K.geometry).remove)==null||k.call(Z);b.length=0,C.length=0,R=null;for(const K of Array.isArray(z)?z:[]){if(!K||!Array.isArray(K.segments)||K.segments.length<6)continue;const[ne,ie,ue,fe]=wl.tryParse(K.color)??W,me=[ne,ie,ue],ye=Math.max(0,Math.min(1,Number(K.alpha??1)*fe)),Ae=new Ue(e,{vertex:Yr,fragment:Kr,uniforms:{uColor:{value:me.slice()},uAlpha:{value:ye}},transparent:!0,depthTest:!1,depthWrite:!1});Ae.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const ge=Math.floor(K.segments.length/6)*6,we=Float32Array.from(K.segments.slice(0,ge)),Re=new ot(e,{position:{size:3,data:we}}),Te=new Je(e,{geometry:Re,program:Ae,mode:e.LINES});Te.frustumCulled=!1,Te.setParent(Xe),b.push(Te);const Ne=Number(K.entityId??0);Ne>0&&(Te.matrixAutoUpdate=!1,C.push({entityId:Ne,mesh:Te,program:Ae,color:me,segments:we}))}},re=()=>{for(const z of C){if(!i.entities.has(z.entityId)){z.mesh.visible=!1;continue}z.mesh.visible=!0,z.mesh.matrix.copy(Ve(z.entityId)),z.mesh.worldMatrixNeedsUpdate=!0;const Z=z.entityId===a?vs:z.entityId===R?ys(z.color):z.color,k=z.program.uniforms.uColor.value;k[0]=Z[0],k[1]=Z[1],k[2]=Z[2]}},Ee=(z,Z)=>{if(C.length===0)return 0;const k=i.activeSceneId(),K=i.scenes.get(k);if(!K||K.camera===void 0)return 0;const{origin:ne,dir:ie}=t.getViewRay(k,z,Z),ue=n.getBoundingClientRect(),fe=Math.max(1,ue.height/gn(n)),me=2*Math.tan(i.projectionOf(k).fov*Math.PI/360)*_l/fe;let ye=0,Ae=1,ge=1/0;const we=[0,0,0],Re=[0,0,0];for(const Te of C){if(!i.entities.has(Te.entityId))continue;const Ne=Ve(Te.entityId),Oe=Te.segments;for(let Be=0;Be+5<Oe.length;Be+=6){for(let le=0;le<3;le++)we[le]=Ne[le]*Oe[Be]+Ne[4+le]*Oe[Be+1]+Ne[8+le]*Oe[Be+2]+Ne[12+le],Re[le]=Ne[le]*Oe[Be+3]+Ne[4+le]*Oe[Be+4]+Ne[8+le]*Oe[Be+5]+Ne[12+le];const Pe=$e(Re,we),ce=$e(we,ne),We=et(ie,ie),Ke=et(ie,Pe),Qe=et(Pe,Pe),A=et(ie,ce),_=et(Pe,ce),E=We*Qe-Ke*Ke;let O=E>1e-12?(Ke*A-We*_)/E:0;O=Math.max(0,Math.min(1,O));const U=Math.max(0,(A+O*Ke)/(We||1)),H=lr(we,cr(Pe,O)),Q=lr(ne,cr(ie,U));if(U<=1e-6)continue;const ee=U*me,he=or($e(H,Q))/ee;he>1||(he<Ae-.001||Math.abs(he-Ae)<=.001&&U<ge)&&(ye=Te.entityId,Ae=he,ge=U)}}return ye};let be=[];const Le=new ct,Ge=[],qe=[1,1,1],Ve=z=>{const Z=Float32Array.from(i.worldMatrix(z));for(let k=0;k<3;k++){const K=Math.hypot(Z[k*4],Z[k*4+1],Z[k*4+2])||1;qe[k]=K,Z[k*4]/=K,Z[k*4+1]/=K,Z[k*4+2]/=K}return Z},Ye=(z,Z,k,K,ne=0,ie=0,ue=0)=>{const fe=Float32Array.from(z);fe[12]=z[12]+z[0]*ne+z[4]*ie+z[8]*ue,fe[13]=z[13]+z[1]*ne+z[5]*ie+z[9]*ue,fe[14]=z[14]+z[2]*ne+z[6]*ie+z[10]*ue;for(let me=0;me<3;me++)fe[me]*=Z,fe[4+me]*=k,fe[8+me]*=K;return fe},tt=(z,Z)=>{const k=i.entities.get(z);if(k){for(const K of t.drawablesOf(z))K.mode===e.TRIANGLES&&Z.push(K);for(const K of k.children)tt(K,Z)}},ht=new Map,vt=z=>{const Z=new Map,k=[],K=(ue,fe,me)=>{const ye=`${ue.toFixed(5)},${fe.toFixed(5)},${me.toFixed(5)}`;let Ae=Z.get(ye);return Ae===void 0&&(Ae=k.length/3,Z.set(ye,Ae),k.push(ue,fe,me)),Ae},ne=new Set;for(let ue=0;ue+8<z.length;ue+=9){const fe=K(z[ue],z[ue+1],z[ue+2]),me=K(z[ue+3],z[ue+4],z[ue+5]),ye=K(z[ue+6],z[ue+7],z[ue+8]);for(const[Ae,ge]of[[fe,me],[me,ye],[ye,fe]])ne.add(Ae<ge?Ae*65536+ge:ge*65536+Ae)}const ie=[];for(const ue of ne){const fe=Math.floor(ue/65536)*3,me=ue%65536*3;ie.push(k[fe],k[fe+1],k[fe+2],k[me],k[me+1],k[me+2])}return new ot(e,{position:{size:3,data:Float32Array.from(ie)}})},xt=z=>{var ye,Ae;const Z=[];tt(z,Z);const k=Ve(z),K=Z.map(ge=>{var we;return((we=ge.geometry)==null?void 0:we.id)??"?"}).join(",")+"|"+qe.map(ge=>ge.toFixed(4)).join(","),ne=ht.get(z);if(ne&&ne.key===K)return ne.geometry;const ie=St(k),ue=[];for(const ge of Z){const we=(Ae=(ye=ge.geometry)==null?void 0:ye.attributes)==null?void 0:Ae.position,Re=we==null?void 0:we.data;if(!(Re instanceof Float32Array)||we.size!==3||we.stride)continue;const Te=dt(new Float32Array(16),ie,ge.worldMatrix);for(let Ne=0;Ne+2<Re.length;Ne+=3){const Oe=Re[Ne],Be=Re[Ne+1],Pe=Re[Ne+2];ue.push(Te[0]*Oe+Te[4]*Be+Te[8]*Pe+Te[12],Te[1]*Oe+Te[5]*Be+Te[9]*Pe+Te[13],Te[2]*Oe+Te[6]*Be+Te[10]*Pe+Te[14])}}const fe=ue.length>=12?ll(ue):null,me=fe?vt(fe):null;return ht.set(z,{key:K,geometry:me}),me},Ut=()=>{var Z,k,K;for(const ne of Ge)ne.setParent(null);Ge.length=0;const z=(ne,ie)=>{const ue=new Je(e,{geometry:ne,program:ae,mode:e.LINES});ue.frustumCulled=!1,ue.matrixAutoUpdate=!1,ue.matrix.copy(ie),ue.setParent(Le),Ge.push(ue)};for(const ne of be){if(!i.entities.has(ne.entityId))continue;const ie=ne.shape,ue=ne.origin,[fe,me,ye]=ue??[0,0,0];if(ie.kind==="box")z(de,Ye(Ve(ne.entityId),ie.half[0],ie.half[1],ie.half[2],fe,me,ye));else if(ie.kind==="sphere")z(ve,Ye(Ve(ne.entityId),ie.radius,ie.radius,ie.radius,fe,me,ye));else if(ie.kind==="cylinder"||ie.kind==="capsule")z(ze(ie.kind,ie.halfHeight,ie.radius),Ye(Ve(ne.entityId),1,1,1,fe,me,ye));else if(ie.kind==="mesh"&&ie.convex&&xt(ne.entityId))z(xt(ne.entityId),Ye(Ve(ne.entityId),1,1,1,fe,me,ye));else if(ie.kind==="mesh"){const Ae=[];tt(ne.entityId,Ae);const ge=Ve(ne.entityId),we=ge[0]*fe+ge[4]*me+ge[8]*ye,Re=ge[1]*fe+ge[5]*me+ge[9]*ye,Te=ge[2]*fe+ge[6]*me+ge[10]*ye;for(const Ne of Ae){if(!((k=(Z=Ne.geometry)==null?void 0:Z.attributes)!=null&&k.position))continue;const Oe=Float32Array.from(Ne.worldMatrix);Oe[12]+=we,Oe[13]+=Re,Oe[14]+=Te,z(t.wireGeometryFor(Ne.geometry),Oe)}}else{const Ae=t.drawablesOf(ne.entityId).find(Qe=>Qe.mode===e.TRIANGLES);let ge=.5,we=.5,Re=.5,Te=0,Ne=0,Oe=0;const Be=(K=Ae==null?void 0:Ae.geometry)==null?void 0:K.bounds;Be&&isFinite(Be.min.x)&&(ge=(Be.max.x-Be.min.x)/2,we=(Be.max.y-Be.min.y)/2,Re=(Be.max.z-Be.min.z)/2,Te=(Be.max.x+Be.min.x)/2,Ne=(Be.max.y+Be.min.y)/2,Oe=(Be.max.z+Be.min.z)/2);const Pe=Ve(ne.entityId),[ce,We,Ke]=qe;z(de,ue?Ye(Pe,ge*ce,we*We,Re*Ke,fe,me,ye):Ye(Pe,ge*ce,we*We,Re*Ke,Te*ce,Ne*We,Oe*Ke))}}return Ge.length>0},Ft=new Ue(e,{vertex:yr(!1),fragment:vr,uniforms:{modelMatrix:{value:He()},shadowViewProjection:{value:He()}},depthTest:!1,depthWrite:!1,cullFace:!1}),mt=new Ue(e,{vertex:yr(!0),fragment:vr,uniforms:{modelMatrix:{value:He()},shadowViewProjection:{value:He()},boneTexture:{value:null},boneTextureSize:{value:4}},depthTest:!1,depthWrite:!1,cullFace:!1});let ke=null;const rt=new Ue(e,{vertex:Dl,fragment:Ul,uniforms:{tMask:{value:null},uTexel:{value:[0,0]},uColor:{value:vs}},depthTest:!1,depthWrite:!1,transparent:!0});rt.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const bt=new Je(e,{geometry:new $o(e),program:rt}),zt=(z,Z)=>{const k=i.entities.get(z);if(!(!k||!k.visible)){Z.push(...t.drawablesOf(z));for(const K of k.children)zt(K,Z)}},Vt=()=>{if(a===null||!i.entities.has(a))return;const z=[];if(zt(a,z),z.length===0)return;(!ke||ke.width!==n.width||ke.height!==n.height)&&(ke=new Ds(e,{width:Math.max(1,n.width),height:Math.max(1,n.height)}));const Z=dt(new Float32Array(16),s.projectionMatrix,s.viewMatrix);Ft.uniforms.shadowViewProjection.value=Z,mt.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 k=He();for(const K of z){const ne=K instanceof Mt,ie=ne?mt:Ft;ie.uniforms.modelMatrix.value=ne?k:K.worldMatrix;const ue=K.program;K.program=ie,K.draw({}),K.program=ue}r.bindFramebuffer({buffer:null}),r.setViewport(n.width,n.height),rt.uniforms.tMask.value=ke.texture,rt.uniforms.uTexel.value=[1/ke.width,1/ke.height],bt.draw({})},Ie=z=>{o&&(y(z),r.render({scene:M,camera:s,clear:!1,frustumCull:!1,sort:!1}))},Sr=()=>{Vt(),be.length>0&&Ut()&&r.render({scene:Le,camera:s,clear:!1,frustumCull:!1,sort:!1}),b.length>0&&(re(),r.render({scene:Xe,camera:s,clear:!1,frustumCull:!1,sort:!1})),V()&&(r.setDepthMask(!0),e.clear(e.DEPTH_BUFFER_BIT),r.render({scene:P,camera:s,clear:!1,frustumCull:!1,sort:!1}))};let fr=null;const _t=new ln(e,{fov:60,near:.01,far:1e3,aspect:1});return _t.matrixAutoUpdate=!1,{api:{setGrid(z){o=z===!0},setSelection(z){F&&z!==a&&(F.cleanup(),F=null),a=z&&z>0?z:null},setGizmoMode(z){f=z==="translate"||z==="rotate"||z==="scale"?z:null,B=null},setGizmoSpace(z){g=z==="local"?"local":"global"},setColliders(z){be=Array.isArray(z)?z.slice():[]},setGizmos:se,setPreview(z){fr=z&&z.entityId>0?z:null},pickAt(z,Z){return Y(z,Z)}},setHandlers(z){l=z??{}},renderScenePass:Ie,renderOverlayPass:Sr,renderPreviewPass:(z,Z)=>{const k=fr;if(!k)return;const K=n.width/(n.getBoundingClientRect().width||n.width),ne=Math.round(k.rect[0]*K),ie=Math.round(k.rect[1]*K),ue=Math.round(k.rect[2]*K),fe=Math.round(k.rect[3]*K);if(ue<2||fe<2)return;const me=i.worldMatrixF(k.entityId);if(!me)return;for(let ge=0;ge<16;ge++)_t.matrix[ge]=me[ge];_t.worldMatrixNeedsUpdate=!0,_t.perspective({fov:k.fov,aspect:ue/fe,near:k.near,far:k.far}),_t.updateMatrixWorld();const ye=[];for(const ge of k.hide??[])for(const we of t.drawablesOf(ge))we.visible&&(we.visible=!1,ye.push(we));const Ae=n.height-ie-fe;r.bindFramebuffer({buffer:null}),r.setViewport(ue,fe,ne,Ae),e.enable(e.SCISSOR_TEST),e.scissor(ne,Ae,ue,fe),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,_t,ye.length>0),e.disable(e.SCISSOR_TEST);for(const ge of ye)ge.visible=!0;r.setViewport(n.width,n.height)},dispose:()=>{F==null||F.cleanup(),F=null,n.removeEventListener("pointerdown",$),n.removeEventListener("pointerup",G),n.removeEventListener("pointermove",q),n.style.cursor=""}}},Vl={value:0},sr=16,Gl=600,Hl=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])),kl=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]),Wl=(t,e)=>{const r=new Map,n=[],s=[],i=[];let l=-1;const o=new Float32Array(16);let a=!0,f=!0;const g=new Map;let m=0;const h=I=>{const $=g.get(I);if($!==void 0)return $;let G=null;const q=t.getShaderSource(I.vertexShader),ae=t.getShaderSource(I.fragmentShader);if(q&&ae&&q.startsWith("#version")){const J=q.replace(/^([^\n]*\n)/,`$1#define INSTANCED
|
|
887
|
+
`),te=new Ue(t,{vertex:J,fragment:ae,uniforms:I.uniforms,transparent:I.transparent,cullFace:I.cullFace,frontFace:I.frontFace,depthTest:I.depthTest,depthWrite:I.depthWrite,depthFunc:I.depthFunc});let de=!1;te.attributeLocations.forEach((ve,pe)=>{pe.name==="instanceMatrix"&&(de=!0)}),de&&t.getProgramParameter(te.program,t.LINK_STATUS)?G=te:te.remove()}return g.set(I,G),G},v=(I,$)=>{I.transparent=$.transparent,I.cullFace=$.cullFace,I.frontFace=$.frontFace,I.depthTest=$.depthTest,I.depthWrite=$.depthWrite,I.depthFunc=$.depthFunc,I.blendFunc=$.blendFunc,I.blendEquation=$.blendEquation},M=(I,$)=>{const G={};for(const[ae,J]of Object.entries(I.attributes))G[ae]={size:J.size,data:J.data,type:J.type,normalized:J.normalized,stride:J.stride,offset:J.offset,buffer:J.buffer,count:J.count};G.instanceMatrix={instanced:1,size:16,data:new Float32Array($*16),usage:t.DYNAMIC_DRAW};const q=new ot(t,G);return q.drawRange.start=I.drawRange.start,q.drawRange.count=I.drawRange.count,q},p=I=>{for(const G of Object.values(I.VAOs))e.deleteVertexArray(G);I.VAOs={};const $=I.attributes.instanceMatrix;$!=null&&$.buffer&&(t.deleteBuffer($.buffer),$.buffer=null),e.currentGeometry=null},y=(I,$)=>{const G=I.attributes.instanceMatrix;let q=Math.max(sr,G.count);for(;q<$;)q*=2;const ae=new Float32Array(q*16);return ae.set(G.data),p(I),I.instancedCount=0,I.addAttribute("instanceMatrix",{instanced:1,size:16,data:ae,usage:t.DYNAMIC_DRAW}),ae},x=(I,$,G)=>{const q=I.attributes.instanceMatrix;G>0&&(t.bindBuffer(t.ARRAY_BUFFER,q.buffer),e.state.boundBuffer=q.buffer,t.bufferSubData(t.ARRAY_BUFFER,0,$,0,G*16)),I.setInstancedCount(G)},T=(I,$,G)=>{const q=I.program,ae=I._castShadows!==!1,J=I._receiveShadows!==!1,te=`${I.geometry.id}|${q.id}|${I.mode}|${I.renderOrder}|${ae?1:0}${J?1:0}${G?1:0}`;let de=r.get(te);if(!de){const ve=I.geometry;de={key:te,source:ve,program:q,twin:$,mode:I.mode,renderOrder:I.renderOrder,castShadows:ae,receiveShadows:J,flip:G,all:new Float32Array(sr*16),allCount:0,allDirty:!0,geoAll:M(ve,sr),sph:new Float32Array(sr*4),vis:new Float32Array(sr*16),visCount:0,visDirty:!0,geoVis:M(ve,sr),bounds:new Float32Array(6),lastUsed:m},r.set(te,de)}return de},B=I=>{var G,q;if(!f||I instanceof Mt||I._particles||I.mode===t.POINTS)return null;const $=I.program;return $.transparent||!$.depthTest||!((q=(G=I.geometry)==null?void 0:G.attributes)!=null&&q.position)||I.geometry.isInstanced||$.uniforms.uMorphTex?null:h($)},F=I=>{const $=I.geometry;return(!$.bounds||$.bounds.radius===1/0)&&$.computeBoundingSphere(),$.bounds&&isFinite($.bounds.radius)?$.bounds:null},P=(I,$,G,q,ae)=>{const J=I.frustum;for(let te=0;te<6;te++){const de=J[te];if(de[0]*$+de[1]*G+de[2]*q+de.constant<-ae)return!1}return!0},c=(I,$,G)=>{const q=$*16;let ae=!1;for(let J=0;J<16;J++){const te=G[J];I[q+J]!==te&&(I[q+J]=te,ae=!0)}return ae},u=I=>{const $=I.source;$.bounds||$.computeBoundingBox();const G=I.bounds;if(G[0]=G[1]=G[2]=1/0,G[3]=G[4]=G[5]=-1/0,!$.bounds||!isFinite($.bounds.min.x))return;const{min:q,max:ae}=$.bounds,J=[0,0,0];for(let te=0;te<I.allCount;te++){const de=I.all.subarray(te*16,te*16+16);for(let ve=0;ve<8;ve++){At(J,de,ve&1?ae.x:q.x,ve&2?ae.y:q.y,ve&4?ae.z:q.z,1);for(let pe=0;pe<3;pe++)J[pe]<G[pe]&&(G[pe]=J[pe]),J[pe]>G[pe+3]&&(G[pe+3]=J[pe])}}},d=[0,0,0],w=I=>{m++,s.length=0,i.length=0;for(const $ of r.values())$.allCount=0;I.traverse($=>{if(!$.visible)return!0;if(!$.draw)return!1;const G=$.worldMatrix,q=B($);if(!q)return s.push($),$._castShadows!==!1&&i.push($),!1;const ae=!!$.program.cullFace&&kl(G)<0,J=T($,q,ae);J.lastUsed=m;const te=J.allCount;if(te*16>=J.all.length){J.all=y(J.geoAll,te+1);const pe=new Float32Array(J.all.length/4);pe.set(J.sph),J.sph=pe}c(J.all,te,G)&&(J.allDirty=!0);const de=F($),ve=te*4;return de&&$.frustumCulled?(At(d,G,de.center.x,de.center.y,de.center.z,1),J.sph[ve]=d[0],J.sph[ve+1]=d[1],J.sph[ve+2]=d[2],J.sph[ve+3]=de.radius*Hl(G)):J.sph[ve+3]=-1,J.allCount++,!1});for(const[$,G]of r)G.allCount!==G.geoAll.instancedCount&&(G.allDirty=!0),G.allDirty&&(x(G.geoAll,G.all,G.allCount),u(G),G.allDirty=!1),G.allCount===0&&m-G.lastUsed>Gl&&(p(G.geoAll),p(G.geoVis),r.delete($))},S=(I,$)=>{I.updateFrustum();for(const G of r.values()){G.visCount=0;const q=G.allCount;for(let ae=0;ae<q;ae++){const J=ae*4;if($&&G.sph[J+3]>=0&&!P(I,G.sph[J],G.sph[J+1],G.sph[J+2],G.sph[J+3]))continue;const te=G.visCount;te*16>=G.vis.length&&(G.vis=y(G.geoVis,te+1));const de=ae*16,ve=te*16;for(let pe=0;pe<16;pe++){const ze=G.all[de+pe];G.vis[ve+pe]!==ze&&(G.vis[ve+pe]=ze,G.visDirty=!0)}G.visCount++}G.visCount!==G.geoVis.instancedCount&&(G.visDirty=!0),G.visDirty&&(x(G.geoVis,G.vis,G.visCount),G.visDirty=!1)}n.length=0;for(const G of s)$&&G.frustumCulled&&!I.frustumIntersectsMesh(G)||n.push(G)},N=(I,$,G,q=-2,ae=!1)=>{const J=ae||q!==l;J&&(w(I),l=q),$.updateMatrixWorld();const te=$.projectionViewMatrix;let de=G!==a;for(let ve=0;ve<16&&!de;ve++)o[ve]!==te[ve]&&(de=!0);if(!(!J&&!de)){S($,G);for(let ve=0;ve<16;ve++)o[ve]=te[ve];a=G}},V=()=>[...r.values()].sort((I,$)=>I.renderOrder-$.renderOrder);return{collect:N,drawMain:(I,$)=>{for(const te of V()){if(te.visCount===0)continue;const de=te.twin.uniforms;(de.projectionMatrix??(de.projectionMatrix={value:null})).value=I.projectionMatrix,(de.viewMatrix??(de.viewMatrix={value:null})).value=I.viewMatrix,(de.cameraPosition??(de.cameraPosition={value:null})).value=I.worldPosition;const ve=de.shadowEnabled;ve&&(de.shadowEnabled=te.receiveShadows?$:Vl),v(te.twin,te.program),te.twin.use({flipFaces:te.flip}),te.geoVis.draw({mode:te.mode,program:te.twin}),ve&&(de.shadowEnabled=ve)}const G=[],q=[],ae=[],J=I.projectionViewMatrix;for(const te of n){if(te.program.transparent?te.program.depthTest?q.push(te):ae.push(te):G.push(te),te.zDepth=0,te.renderOrder!==0||!te.program.depthTest)continue;const de=te.worldMatrix,ve=de[12],pe=de[13],ze=de[14],Xe=J[3]*ve+J[7]*pe+J[11]*ze+J[15]||1;te.zDepth=(J[2]*ve+J[6]*pe+J[10]*ze+J[14])/Xe}G.sort(e.sortOpaque),q.sort(e.sortTransparent),ae.sort(e.sortUI);for(const te of G)te.draw({camera:I});for(const te of q)te.draw({camera:I});for(const te of ae)te.draw({camera:I})},drawShadow:I=>{for(const $ of r.values())!$.castShadows||$.allCount===0||(I.use({flipFaces:$.flip}),$.geoAll.draw({mode:$.mode,program:I}))},casterBounds:(I,$)=>{for(const G of r.values())if(!(!G.castShadows||G.allCount===0||!isFinite(G.bounds[0])))for(let q=0;q<3;q++)G.bounds[q]<I[q]&&(I[q]=G.bounds[q]),G.bounds[q+3]>$[q]&&($[q]=G.bounds[q+3])},isBatched:I=>B(I)!==null,dispose:()=>{for(const I of r.values())p(I.geoAll),p(I.geoVis);r.clear();for(const I of g.values())I==null||I.remove();g.clear()},setEnabled:I=>{f=I,l=-1},singles:n,casterSingles:i,stats:()=>{let I=0,$=0,G=0;for(const q of r.values())q.allCount>0&&(G++,I+=q.allCount,$+=q.visCount);return{batches:G,instances:I,visible:$,singles:n.length}}}},$l=1179937895,jl=1313821514,Xl=t=>{var e,r;try{if(t.byteLength<20)return null;const n=new DataView(t);if(n.getUint32(0,!0)!==$l)return null;const s=n.getUint32(12,!0);if(n.getUint32(16,!0)!==jl||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 p;let v;Array.isArray(h.matrix)&&h.matrix.length===16?v=Float32Array.from(h.matrix):h.translation||h.rotation||h.scale?v=Vs(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,T;for(const B of y){const F=l[(p=B.attributes)==null?void 0:p.POSITION];if(!(!F||!Array.isArray(F.min)||!Array.isArray(F.max)))if(!x||!T)x=[F.min[0],F.min[1],F.min[2]],T=[F.max[0],F.max[1],F.max[2]];else for(let P=0;P<3;P++)x[P]=Math.min(x[P],F.min[P]),T[P]=Math.max(T[P],F.max[P])}M.mesh={primitives:y.length,min:x,max:T}}return M});for(const h of i.skins??[])for(const v of h.joints??[])a[v]&&(a[v].skinJoint=!0);const f=(i.animations??[]).map((h,v)=>{var p,y;let M=0;for(const x of h.samplers??[]){const T=(y=(p=l[x.input])==null?void 0:p.max)==null?void 0:y[0];typeof T=="number"&&T>M&&(M=T)}return{name:typeof h.name=="string"?h.name:`animation_${v}`,duration:M}}),g=i.scene??0,m=((r=(e=i.scenes)==null?void 0:e[g])==null?void 0:r.nodes)??[];return{nodes:a,roots:m,animations:f}}catch{return null}};let ql=null,cn=null;const Yl=()=>ql??(ql=wr(()=>import("./creatorAnim-BOwKr-C1.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.default()).then(t=>cn=t)),Xs=()=>cn!==null,ft=(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)}},Kl=(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)}},lt=(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)}},Qr=(t,e,r,n,s,i,l,o,a,f,g)=>{const m=s+s,h=i+i,v=l+l,M=s*m,p=s*h,y=s*v,x=i*h,T=i*v,B=l*v,F=o*m,P=o*h,c=o*v,u=t;u[0]=(1-(x+B))*a,u[1]=(p+c)*a,u[2]=(y-P)*a,u[3]=0,u[4]=(p-c)*f,u[5]=(1-(M+B))*f,u[6]=(T+F)*f,u[7]=0,u[8]=(y+P)*g,u[9]=(T-F)*g,u[10]=(1-(M+x))*g,u[11]=0,u[12]=e,u[13]=r,u[14]=n,u[15]=1},Tr=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,f=e[0]*l,g=e[1]*l,m=e[2]*l,h=e[4]*o,v=e[5]*o,M=e[6]*o,p=e[8]*a,y=e[9]*a,x=e[10]*a,T=f+v+x;let B,F,P,c;if(T>0){const u=.5/Math.sqrt(T+1);c=.25/u,B=(M-y)*u,F=(p-m)*u,P=(g-h)*u}else if(f>v&&f>x){const u=2*Math.sqrt(1+f-v-x);c=(M-y)/u,B=.25*u,F=(h+g)/u,P=(p+m)/u}else if(v>x){const u=2*Math.sqrt(1+v-f-x);c=(p-m)/u,B=(h+g)/u,F=.25*u,P=(y+M)/u}else{const u=2*Math.sqrt(1+x-f-v);c=(g-h)/u,B=(p+m)/u,F=(y+M)/u,P=.25*u}return{t:[e[12],e[13],e[14]],r:[B,F,P,c],s:[r,n,s]}},Zl=(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],f=t[10];t[0]=s*r-o*n,t[1]=i*r-a*n,t[2]=l*r-f*n,t[8]=s*n+o*r,t[9]=i*n+a*r,t[10]=l*n+f*r};let ws=!1;const Zr=t=>typeof t._canimAnimatorLateSolve=="function"?!0:(ws||(ws=!0,console.warn("creator-anim: this wasm predates IK chains / sockets — rebuild it (build-wasm.sh + vendor:creator); chains are inert")),!1),ir=19,yt={TARGET_X:0,POLE_X:3,HAS_POLE:6,ROT_X:8},Ms=64,pr=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Jl(t){const e=cn;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),f=e._malloc(32),g=e._malloc(4),m=e._malloc(4),h=e._malloc(Ms*4),v=[],M=[];let p=null;const y=c=>{const u=c instanceof Uint8Array?c:new Uint8Array(c);return Ql(e,u,d=>e._canimClipsLoad(d,u.length))},x=c=>{e._free(c.trs),e._free(c.write)},T={loadClips(c,u,d){const w=t.getBuffer(c),S=w?y(w):0;if(!S){d(new Error("loadClips: not a GLB with animations"));return}u(S)},createClipFromTracks(c,u){return lt(e,c,d=>ft(e,u,w=>e._canimClipsFromTracks(d,w,u.length)))},getClipSetInfo(c){const u=e._canimClipsCount(c),d=[];for(let w=0;w<u;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,u,d,w){return e._canimClipsSlice(c,u,d,w)},deriveClip(c,u,d,w,S){return e._canimClipsDerive(c,u,d?1:0,w,S)},destroyClipSet(c){e._canimClipsDestroy(c)},animatorCreate(c){if(!t.get(c))return 0;const d=[],w=[],S=[],N=[],V=[],L=($,G)=>{const q=t.get($);if(!q)return;const ae=d.length;d.push($),w.push(G),S.push(q.name??""),V.push(q.skinJoint?1:0);const{t:J,r:te,s:de}=Tr(q.m);N.push(J[0],J[1],J[2],te[0],te[1],te[2],te[3],de[0],de[1],de[2]);for(const ve of q.children)L(ve,ae)};L(c,-1);const j=d.length,X=e._malloc(Math.max(4,j*4));e.HEAP32.set(w,X>>2);const oe=e._malloc(Math.max(1,j));e.HEAPU8.set(V,oe);let Y=0;try{Y=lt(e,S.join(`
|
|
888
|
+
`),$=>ft(e,N,G=>e._canimAnimatorCreate(j,X,$,G,oe,c)))}finally{e._free(X),e._free(oe)}if(!Y)return 0;const I=e._canimAnimatorShadowedNames(Y);return I>0&&console.warn(`[Animator] ${I} 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,j*40)),write:e._malloc(Math.max(1,j)),n:j,feetOn:!1,iks:[],sockets:[]}),Y},animatorDestroy(c){const u=r.get(c);if(!u){e._canimAnimatorDestroy(c);return}e._canimAnimatorRest(c,u.trs,u.write);const d=e.HEAPF32,w=e.HEAPU8,S=u.trs>>2;for(let N=0;N<u.n;N++){if(!w[u.write+N])continue;const V=t.get(u.entities[N]);if(!V)continue;const L=S+N*10;Qr(V.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(u.entities[N])}e._canimAnimatorDestroy(c),x(u),r.delete(c)},animatorBind(c,u,d,w){return e._canimAnimatorBind(c,u,d,w)},animatorBindMirror(c,u,d,w){return e._canimAnimatorBindMirror?e._canimAnimatorBindMirror(c,u,d,w):-1},animatorBoundTracks(c,u){return e._canimAnimatorBoundTracks(c,u)},setClipEvents(c,u,d){ft(e,d,w=>e._canimClipsSetEvents(c,u,w,d.length))},animatorSetBlend(c,u,d,w,S,N,V,L){const j=d>1?2:1,X=Math.min(w.length,Math.floor(S.length/j)),oe=L&&L.length>=X*2?L:null;Kl(e,w,Y=>ft(e,S,I=>{oe?ft(e,oe,$=>e._canimAnimatorSetBlend(c,u,j,Y,I,$,X,N,V)):e._canimAnimatorSetBlend(c,u,j,Y,I,0,X,N,V)}))},animatorSetBlendValue(c,u,d,w){e._canimAnimatorSetBlendValue(c,u,d,w)},animatorSlotSetTurn(c,u,d,w){e._canimAnimatorSlotSetTurn(c,u,d,w?1:0)},animatorSlotSetWindow(c,u,d,w){e._canimAnimatorSlotSetWindow(c,u,d,w)},animatorPlay(c,u,d,w,S,N,V){e._canimAnimatorPlay(c,u,d?1:0,w,S,N,V?1:0)},animatorStop(c,u,d,w){e._canimAnimatorStop(c,u,d,w)},animatorSeek(c,u,d){e._canimAnimatorSeek(c,u,d)},animatorGetSlotTime(c,u){return e._canimAnimatorSlotTime(c,u)},animatorGetSlotWeight(c,u){return e._canimAnimatorSlotWeight(c,u)},animatorSetLayer(c,u,d,w,S){lt(e,S??"",N=>e._canimAnimatorSetLayer(c,u,d,w?1:0,N))},animatorSetLayerAnticipation(c,u,d){e._canimAnimatorSetLayerAnticipation(c,u,d)},animatorSetGlobal(c,u,d){e._canimAnimatorSetGlobal(c,u,d?1:0)},animatorJointRanges(c,u,d){for(const[w,S]of r){if(!S.entities.includes(c))continue;const N=u.length>>1,V=new Int32Array(N*2);for(let Y=0;Y<N*2;Y++)V[Y]=S.entities.indexOf(u[Y]);const L=new Float32Array(N*6),j=e._malloc(Math.max(4,N*8));e.HEAP32.set(V,j>>2);const X=e._malloc(Math.max(4,N*24));let oe=0;try{oe=ft(e,d,Y=>e._canimAnimatorJointRanges(w,j,N,Y,X)),oe>0&&L.set(e.HEAPF32.subarray(X>>2,(X>>2)+N*6))}finally{e._free(j),e._free(X)}return oe>0?L:null}return null},animatorSeedPose(c,u){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 V=t.get(w.entities[N]),{t:L,r:j,s:X}=Tr(V?V.m:pr);S.set([L[0],L[1],L[2],j[0],j[1],j[2],j[3],X[0],X[1],X[2]],N*10)}ft(e,S,N=>e._canimAnimatorSeedPose(d,N,u));return}},animatorSetRootMotion(c,u,d){lt(e,u??"",w=>e._canimAnimatorSetRootMotion(c,w,(d|0)&255))},animatorGetRootMotion(c,u){e._canimAnimatorRootMotion(c,i);const d=e.HEAPF32,w=i>>2;u[0]=d[w],u[1]=d[w+1],u[2]=d[w+2]},setOnAnimatorEvent(c){n=c},animatorSetFeet(c,u,d){lt(e,u,w=>lt(e,d,S=>e._canimAnimatorSetFeet(c,w,S)))},animatorSlotCurveAt(c,u,d,w){return e._canimAnimatorSlotCurveAt(c,u,d,w)},animatorSlotCurveInfo(c,u,d){const w=e._canimAnimatorSlotCurveInfo(c,u,s);return w&&d.set(e.HEAPF32.subarray(s>>2,(s>>2)+Math.min(4,d.length))),w!==0},animatorSlotTurn(c,u){return e._canimAnimatorSlotTurn(c,u)},animatorSlotTimeAtTurn(c,u,d){return e._canimAnimatorSlotTimeAtTurn(c,u,d)},animatorLayerPhase(c,u){return e._canimAnimatorLayerPhase(c,u)},animatorSeekPhase(c,u,d){e._canimAnimatorSeekPhase(c,u,d)},animatorSlotContacts(c,u,d){const w=Math.floor(d.length/8);if(w===0)return e._canimAnimatorSlotContacts(c,u,0,0);const S=e._malloc(w*8*4),N=e._canimAnimatorSlotContacts(c,u,S,w);return d.set(e.HEAPF32.subarray(S>>2,(S>>2)+Math.min(N,w)*8)),e._free(S),N},animatorSlotTreads(c,u,d){if(d.length===0)return e._canimAnimatorSlotTreads(c,u,0,0);const w=e._malloc(d.length*4),S=e._canimAnimatorSlotTreads(c,u,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,u,d,w){const S=e._malloc(44),N=e._canimAnimatorSlotPhysics(c,u,d,S);return N&&w.set(e.HEAPF32.subarray(S>>2,(S>>2)+Math.min(11,w.length))),e._free(S),N},animatorSlotFeatures(c,u,d,w){const S=e._malloc(148),N=e._canimAnimatorSlotFeatures(c,u,d,S);return N&&w.set(e.HEAPF32.subarray(S>>2,(S>>2)+Math.min(37,w.length))),e._free(S),N},animatorKneeAxis(c,u,d){const w=e._canimAnimatorKneeAxis(c,u,f);return w&&d.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(8,d.length))),w},animatorSlotKneePole(c,u,d,w,S){const N=e._canimAnimatorSlotKneePole(c,u,d,w,f);return N&&S.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(6,S.length))),N},animatorSetStepWarp(c,u,d,w,S,N){e._canimAnimatorSetStepWarp(c,u?1:0,d,w,S,N)},animatorSlotFit(c,u,d,w,S){if(S.length===0)return e._canimAnimatorSlotFit(c,u,d,w,0,0);const N=e._malloc(S.length*4),V=e._canimAnimatorSlotFit(c,u,d,w,N,S.length);return S.set(e.HEAPF32.subarray(N>>2,(N>>2)+Math.min(V,S.length))),e._free(N),V},animatorSlotExit(c,u,d,w,S,N){return e._canimAnimatorSlotExit(c,u,d,w,S?1:0,N)},animatorSlotAlign(c,u,d,w,S,N){if(N.length<4)return 0;const V=e._malloc(16),L=e._canimAnimatorSlotAlign(c,u,d,w,S,V);return L&&N.set(e.HEAPF32.subarray(V>>2,(V>>2)+4)),e._free(V),L},setOnAnimatorStep(c){p=c},animatorSetFeetParams(c,u){ft(e,u,w=>e._canimAnimatorSetFeetParams(c,w,u.length));const d=r.get(c);d&&(d.feetOn=u.length>0&&u[0]>.5||u.length>1&&u[1]>.5)},animatorFootState(c,u,d){const w=e._canimAnimatorFootState(c,u,f);return w&&d.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(8,d.length))),w!==0},animatorIkCreate(c,u,d){var oe,Y;const w=r.get(c);if(!w||!Zr(e))return 0;const S=w.entities.indexOf(d);if(S<0)return 0;let N=-1,V=-1;if(u===0){const I=((oe=t.get(d))==null?void 0:oe.parent)??0;if(N=w.entities.indexOf(I),N<0||(V=w.entities.indexOf(((Y=t.get(I))==null?void 0:Y.parent)??0),V<0))return 0}const L=e._canimAnimatorIkCreateJoints(c,u,V,N,S);if(!L)return 0;const j=new Float32Array(ir),X=e._malloc(ir*4);return e._canimAnimatorIkGet(c,L,X,ir),j.set(e.HEAPF32.subarray(X>>2,(X>>2)+ir)),e._free(X),w.iks.push({ik:L,target:0,pole:0,rotation:0,params:j}),L},animatorIkDestroy(c,u){e._canimAnimatorIkDestroy(c,u);const d=r.get(c);d&&(d.iks=d.iks.filter(w=>w.ik!==u))},animatorIkSet(c,u,d){var S;ft(e,d,N=>e._canimAnimatorIkSet(c,u,N,d.length));const w=(S=r.get(c))==null?void 0:S.iks.find(N=>N.ik===u);w&&w.params.set(d.subarray(0,Math.min(d.length,ir)))},animatorIkNodes(c,u,d,w,S){var V;const N=(V=r.get(c))==null?void 0:V.iks.find(L=>L.ik===u);N&&(N.target=d,N.pole=w,N.rotation=S)},animatorIkAnchor(c,u,d){lt(e,d??"",w=>e._canimAnimatorIkAnchor(c,u,w))},animatorIkState(c,u,d){const w=e._canimAnimatorIkState(c,u,s);return w&&d.set(e.HEAPF32.subarray(s>>2,(s>>2)+Math.min(4,d.length))),w!==0},animatorSetSocket(c,u,d,w,S,N){const V=r.get(c);if(!V||!Zr(e))return;V.sockets=V.sockets.filter(X=>!(X.set===u&&X.name===d));const L=(X,oe)=>{lt(e,u,Y=>lt(e,d,I=>{oe?ft(e,oe,$=>e._canimAnimatorSetSocket(c,Y,I,X,$)):e._canimAnimatorSetSocket(c,Y,I,X,0)}))};if(S===0&&!N){L(-1,null);return}const j=V.entities.indexOf(w);if(j<0){console.warn(`[Animator] socket '${d}': the joint is no bone of this animator`);return}L(j,N??[0,0,0,0,0,0,1]),S!==0&&V.sockets.push({set:u,name:d,node:S})},setClipAnchors(c,u,d,w,S,N){Zr(e)&<(e,d,V=>lt(e,w??"",L=>lt(e,S??"",j=>ft(e,N,X=>e._canimClipsSetAnchors(c,u,V,L,j,X,Math.floor(N.length/4))))))},animatorSetMotion(c,u,d,w){e._canimAnimatorSetMotion(c,u,d,w)},animatorSetDriveInput(c,u,d){e._canimAnimatorSetDriveInput(c,u,d)},animatorSetSlotDrive(c,u,d,w){e._canimAnimatorSetSlotDrive(c,u,d,w)},animatorSetWarpParams(c,u){ft(e,u,d=>e._canimAnimatorSetWarpParams(c,d,u.length))}},B=(c,u,d)=>{var Y,I;const w=t.get(u.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:pr;e.HEAPF32.set(N,l>>2),e._canimAnimatorSetWorld(c,l);const V=e._canimAnimatorEvaluate(c,d,0,u.trs,u.write);if(u.feetOn&&w){const $=(((I=t.world)==null?void 0:I.call(t,u.rootId))??w.m)[13];for(let G=0;G<2;G++){if(!e._canimAnimatorFootProbe(c,G,o,a))continue;const q=e.HEAPF32,ae=o>>2;e._canimAnimatorSetGround(c,G,1,q[ae],$,q[ae+2],0,1,0)}}const L=e.HEAPF32,j=e.HEAPU8,X=u.trs>>2;for(let $=0;$<u.n;$++){if(!j[u.write+$])continue;const G=t.get(u.entities[$]);if(!G)continue;const q=X+$*10;Qr(G.m,L[q],L[q+1],L[q+2],L[q+3],L[q+4],L[q+5],L[q+6],L[q+7],L[q+8],L[q+9]),t.localMatrixChanged(u.entities[$])}if(t.setMorphWeights){const $=e._canimAnimatorMorphCount(c);for(let G=0;G<$;G++){const q=e._canimAnimatorMorph(c,G,g,m),ae=e.HEAP32[g>>2],J=e.HEAPU32[m>>2];!q||ae<0||J===0||t.setMorphWeights(u.entities[ae],Float32Array.from(e.HEAPF32.subarray(q>>2,(q>>2)+J)))}}const oe=e._canimAnimatorRootMotionFrame(c,s);if(oe!==0){const $=e.HEAPF32,G=s>>2,q=$[G],ae=$[G+1],J=$[G+2],te=$[G+3];let de=!1;if(oe===2&&t.applyRootMotion&&(de=t.applyRootMotion(u.rootId,q,ae,J,d,te)),!de&&(q!==0||ae!==0||J!==0||te!==0)){const ve=t.get(u.rootId);if(ve){const pe=ve.m;te!==0&&Zl(pe,te);const ze=pe[0]*q+pe[4]*ae+pe[8]*J,Xe=pe[1]*q+pe[5]*ae+pe[9]*J,b=pe[2]*q+pe[6]*ae+pe[10]*J;pe[12]+=ze,pe[13]+=Xe,pe[14]+=b,t.localMatrixChanged(u.rootId)}}}if(p){const $=e._canimAnimatorStepCount(c);for(let G=0;G<$;G++){const q=e._canimAnimatorStep(c,G,i);if(q<0)continue;const ae=e.HEAPF32,J=i>>2,te=ae[J],de=ae[J+1],ve=ae[J+2],pe=N;M.push({id:c,side:q,x:pe[0]*te+pe[4]*de+pe[8]*ve+pe[12],y:pe[1]*te+pe[5]*de+pe[9]*ve+pe[13],z:pe[2]*te+pe[6]*de+pe[10]*ve+pe[14]})}}if(V>0){const $=e._canimAnimatorEvents(c,h,Ms),G=e.HEAPU16,q=h>>1;for(let ae=0;ae<$;ae++)v.push({id:c,slot:G[q+ae*2],type:G[q+ae*2+1]})}},F=c=>{var u,d;return((u=t.world)==null?void 0:u.call(t,c))??((d=t.get(c))==null?void 0:d.m)},P=(c,u)=>{if(u.iks.length===0)return;const d=t.get(u.rootId);if(!d)return;const w=d.parent?F(d.parent)??pr:pr;for(const L of u.iks){if(!L.target&&!L.pole&&!L.rotation)continue;const j=L.target?F(L.target):void 0;j&&(L.params[yt.TARGET_X]=j[12],L.params[yt.TARGET_X+1]=j[13],L.params[yt.TARGET_X+2]=j[14]);const X=L.pole?F(L.pole):void 0;X&&(L.params[yt.POLE_X]=X[12],L.params[yt.POLE_X+1]=X[13],L.params[yt.POLE_X+2]=X[14],L.params[yt.HAS_POLE]=1);const oe=L.rotation?F(L.rotation):void 0;if(oe){const Y=Tr(oe).r;L.params[yt.ROT_X]=Y[0],L.params[yt.ROT_X+1]=Y[1],L.params[yt.ROT_X+2]=Y[2],L.params[yt.ROT_X+3]=Y[3]}ft(e,L.params,Y=>e._canimAnimatorIkSet(c,L.ik,Y,ir))}for(const L of u.sockets){const j=F(L.node);j&&(e.HEAPF32.set(j,l>>2),lt(e,L.set,X=>lt(e,L.name,oe=>e._canimAnimatorSocketSetWorld(c,X,oe,l))))}const S=e.HEAPF32,N=u.trs>>2;for(let L=0;L<u.n;L++){const j=t.get(u.entities[L]),{t:X,r:oe,s:Y}=Tr(j?j.m:pr),I=N+L*10;S[I]=X[0],S[I+1]=X[1],S[I+2]=X[2],S[I+3]=oe[0],S[I+4]=oe[1],S[I+5]=oe[2],S[I+6]=oe[3],S[I+7]=Y[0],S[I+8]=Y[1],S[I+9]=Y[2]}if(e.HEAPF32.set(w,l>>2),e._canimAnimatorLateSolve(c,l,u.trs,u.write)===0)return;const V=e.HEAPU8;for(let L=0;L<u.n;L++){if(!V[u.write+L])continue;const j=t.get(u.entities[L]);if(!j)continue;const X=N+L*10;Qr(j.m,S[X],S[X+1],S[X+2],S[X+3],S[X+4],S[X+5],S[X+6],S[X+7],S[X+8],S[X+9]),t.localMatrixChanged(u.entities[L])}};return{methods:T,registerGlbClips(c){return y(c)},lateSolve(){for(const[c,u]of r)P(c,u)},evaluate(c){for(const[u,d]of r)B(u,d,c);if(M.length>0){const u=M.splice(0,M.length);if(p)for(const d of u)p(d.id,d.side,d.x,d.y,d.z)}if(v.length>0&&n){const u=v.splice(0,v.length);for(const d of u)n(d.id,d.slot,d.type)}else v.length=0},onEntityDestroyed(c){e._canimAnimatorsDestroyTagged(c);for(const[u,d]of r)d.rootId===c&&(x(d),r.delete(u))}}}const ec=["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"],tc=t=>{let e=null;const r=()=>{if(!e){if(!Xs())throw new Error("creator-anim is not loaded: await loadCreatorAnim() (viewer-lite/src/gl/core/animBridge) before the first animation call");e=Jl(t)}return e},n={};for(const s of ec)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)}}},rc=["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"],Jr=1/60,As=["static","kinematic","dynamic"],an=34,nc=15,sc=32,Ss=33,bs=(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(an,an+e*2))}:{}}),ic=t=>{let e=null;const r=()=>{if(!e){if(!os())throw new Error("creator-physics is not loaded: await loadCreatorPhysics() (viewer-lite/src/gl/core/physicsBridge) before the first physics call");e=cl(t)}return e},n={};for(const p of rc)n[p]=(...y)=>r().methods[p](...y);const s=new Map,i=new Map,l=new Map,o=new Map,a=new Map;let f;const g=(p,y)=>(p&&s.set(p,y),p),m=(p,y)=>{const x=p.get(y);return x===void 0?void 0:t.ent(x).physics},h=(p,y,x,T,B)=>(p&&(i.set(p,y),t.ent(y).physics={motion:As[x]??x,mass:T,shape:B}),p),v={...n,physicsHasSupport:()=>os(),physicsConfigure(p,y,x,T){f={gravity:[p,y,x],maxBodies:T},n.physicsConfigure(p,y,x,T)},physicsBuildBox:(p,y,x)=>g(n.physicsBuildBox(p,y,x),{type:"box",size:[p*2,y*2,x*2]}),physicsBuildSphere:p=>g(n.physicsBuildSphere(p),{type:"sphere",radius:p}),physicsBuildCylinder:(p,y)=>g(n.physicsBuildCylinder(p,y),{type:"cylinder",height:p*2,radius:y}),physicsBuildCapsule:(p,y)=>g(n.physicsBuildCapsule(p,y),{type:"capsule",height:p*2,radius:y}),physicsBuildMesh:(p,y,x,T,B,F)=>g(n.physicsBuildMesh(p,y,x,T,B,F),{type:x?"convexHull":"mesh",vertices:p.length/3,triangles:Math.floor(y.length/3),scale:[T,B,F]}),physicsBuildMeshFromEntity:(p,y,x,T,B)=>g(n.physicsBuildMeshFromEntity(p,y,x,T,B),{type:y?"convexHull":"mesh",source:p,scale:[x,T,B]}),physicsBuildHeightField(p,y,x,T,B,F,P,c){let u=0;if(B)for(let d=0;d<B.length;d++)B[d]&&u++;return g(n.physicsBuildHeightField(p,y,x,T,B,F,P,c),{type:"heightfield",size:[y,x],cellSize:T,samples:p.length,holes:u,scale:[F,P,c]})},physicsSetShapeOrigin(p,y,x,T){const B=s.get(p);B&&(y===0&&x===0&&T===0?delete B.origin:B.origin=[y,x,T]),n.physicsSetShapeOrigin(p,y,x,T)},physicsSetBodyShape(p,y,x){const T=m(i,p);T&&(T.shape=s.get(y)),n.physicsSetBodyShape(p,y,x)},physicsDestroyShape(p){s.delete(p),n.physicsDestroyShape(p)},physicsCreateBody(p,y,x,T,B,F){const P=n.physicsCreateBody(p,y,x,T,B,F);return P&&(i.set(P,p),t.ent(p).physics={motion:As[x]??x,mass:T,...B&&{sensor:B},...F&&{pickOnly:F},shape:s.get(y)}),P},physicsSetFriction(p,y){const x=m(i,p);x&&(x.friction=y),n.physicsSetFriction(p,y)},physicsRemoveBody(p){i.delete(p),n.physicsRemoveBody(p)},physicsCreateBox:(p,y,x,T,B,F)=>h(n.physicsCreateBox(p,y,x,T,B,F),p,B,F,{type:"box",size:[y*2,x*2,T*2]}),physicsCreateSphere:(p,y,x,T)=>h(n.physicsCreateSphere(p,y,x,T),p,x,T,{type:"sphere",radius:y}),physicsCreateCylinder:(p,y,x,T,B)=>h(n.physicsCreateCylinder(p,y,x,T,B),p,T,B,{type:"cylinder",height:y*2,radius:x}),characterCreate(p,y,x){const T=n.characterCreate(p,y,x);return T&&(l.set(T,p),t.ent(p).physics={character:!0,maxSlopeDeg:x,shape:s.get(y)}),T},characterDestroy(p){l.delete(p),n.characterDestroy(p)},characterSetMaxSlope(p,y){const x=m(l,p);x&&(x.maxSlopeDeg=y),n.characterSetMaxSlope(p,y)},characterSetShape(p,y){const x=n.characterSetShape(p,y);if(x){const T=m(l,p);T&&(T.shape=s.get(y))}return x},vehicleCreate(p,y,x){const T=n.vehicleCreate(p,y,x);if(!T)return 0;const B=x[sc]??0,F=x[Ss]??0;let P=an+F*2;const c=[];for(let u=0;u<B;u++){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+=nc+(d+w)*2}return o.set(T,p),t.ent(p).physics={motion:"dynamic",mass:x[1],vehicle:!0,...bs(x,F),wheels:c,shape:s.get(y)},T},vehicleDestroy(p){o.delete(p),n.vehicleDestroy(p)},vehicleSetTuning(p,y){const x=m(o,p);x&&Object.assign(x,bs(y,y[Ss]??0)),n.vehicleSetTuning(p,y)},vehicleSetInput(p,y){const x=m(o,p);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(p,y)},ragdollCreate(p,y,x){const T=n.ragdollCreate(p,y,x);if(!T)return 0;const B=16,F=x[1]??0,P=x[2]??12,c=[];for(let u=0;u<F;u++){const d=B+u*P;c.push({bone:y[u*2],...y[u*2+1]?{to:y[u*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(T,p),t.ent(p).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},T},ragdollDestroy(p){a.delete(p),n.ragdollDestroy(p)},ragdollActivate(p,y,x,T){const B=n.ragdollActivate(p,y,x,T),F=a.get(p),P=F===void 0?void 0:t.ent(F).ragdoll;return B&&P&&(P.active=!0,P.launch=[y,x,T]),B},ragdollDeactivate(p,y){const x=a.get(p),T=x===void 0?void 0:t.ent(x).ragdoll;T&&(T.active=!1,delete T.launch,y>0&&(T.blendOut=y)),n.ragdollDeactivate(p,y)},ragdollSetDrive(p,y,x){const T=a.get(p),B=T===void 0?void 0:t.ent(T).ragdoll;B&&(B.strength=y,B.anchored=x),n.ragdollSetDrive(p,y,x)}};let M=0;return{methods:v,loaded:()=>e!==null,frame(p,y){if(e){e.frame(p,y);return}if(!y){M=0;return}M+=p;let x=0;for(;M>=Jr&&x<4;)y(Jr),M-=Jr,x++;x===4&&(M=0)},syncRagdolls(p){e&&e.syncRagdolls(p)},applyRootMotion:(p,y,x,T,B)=>e?e.applyRootMotion(p,y,x,T,B):!1,config:()=>f}},Rt={POINTS:0,QUADS:1,MESH:3};let oc=null,hn=null;const ac=()=>oc??(oc=wr(()=>import("./creatorParticles-DYlv4g1J.js"),__vite__mapDeps([4,1]),import.meta.url).then(t=>t.default()).then(t=>hn=t)),lc=()=>hn!==null,cc=(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 hc(t){const e=hn;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,f){e._cpartCreate(o,f|0)&&s.set(o,a)},spawnParticles(o,a){e._cpartSpawn(o,a)},setParticleSystemConfig(o,a){cc(e,a,f=>e._cpartSetConfig(o,f,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,f)=>e._cpartNoise2D(o,a,f),getNoise3D:(o,a,f,g)=>e._cpartNoise3D(o,a,f,g)},l=o=>{const a=e._cpartVertexCount(o),f=e._cpartVertexStride(o),g=e._cpartVertexData(o);return{mode:e._cpartMode(o),stride:f,vertexCount:a,indexCount:e._cpartIndexCount(o),bytes:a>0&&g?e.HEAPU8.subarray(g,g+a*f):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 f=t.cameraPosition();let g=0;f&&(e.HEAPF32.set([f[0],f[1],f[2]],n>>2),g=n);for(const m of s.keys())e.HEAPF32.set(t.world(m),r>>2),e._cpartUpdate(m,o,r,g),a(m,l(m))},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 f=e._malloc(a*4);e._cpartWriteIndexPattern(o,f);const g=Uint32Array.from(e.HEAPU32.subarray(f>>2,(f>>2)+a));return e._free(f),g},destroy(o){e._cpartDestroy(o),s.delete(o)},dispose(){e._cpartReset(),s.clear(),e._free(r),e._free(n)}}}const en={createNoise:()=>0,setNoiseFrequency(){},setNoiseOctaves(){},setNoiseFractalLunacrity(){},setNoiseFractalGain(){},getNoise2D:()=>0,getNoise3D:()=>0},uc=t=>{let e=null;const r=()=>(!e&&lc()&&(e=hc(t)),e);let n=1;const s=(o,a,f)=>{const g=t.ent(o);g.particles||(g.particles={}),f===void 0?delete g.particles[a]:g.particles[a]=f},i={createParticleSystem(o,a,f){var m;t.ent(o).particles={material:a,...f?{maxParticles:f}:{}};const g=r();g&&(g.methods.createParticleSystem(o,a,f),(m=t.created)==null||m.call(t,o,a))},spawnParticles(o,a){var g;const f=t.ent(o).particles;f&&(f.spawned=(f.spawned??0)+a),(g=r())==null||g.methods.spawnParticles(o,a)},setParticleSystemConfig(o,a){var m;const f=(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",f(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",f(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=f(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),p=g(v+4),y=M.every((x,T)=>x===p[T])?M:{min:M,max:p};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}}(m=r())==null||m.methods.setParticleSystemConfig(o,a)},...en},l=Object.fromEntries(Object.keys(en).map(o=>[o,(...a)=>{const f=r();return f?f.methods[o](...a):o==="createNoise"?n++:en[o](...a)}]));return Object.assign(i,l),{methods:i,loaded:()=>e!==null,update(o){e&&e.update(o,(a,f)=>{var m;const g=t.ent(a).particles;g&&(g.alive=f.alive),(m=t.frame)==null||m.call(t,a,f)})},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))}}},qs=t=>{const e=Math.max(t.lastIndexOf(":"),t.lastIndexOf("|"));return e<0?t:t.slice(e+1)},fc=(t,e,r,n)=>t?t===r?e?0:1:qs(t)===n?e?2:3:-1:-1,Bt=(t,e,r=16)=>{for(let n=0;n<r;n++)t[n]=e[n]},_s=(t,e)=>{const r=.5*Math.PI/180,n=Math.PI/2,s=Math.min(Math.max(Math.abs(e),r),n);return[Math.min(Math.max(Math.abs(t),r),s),s]};function dc(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,f=new Map;let g=1,m=1,h=1,v=-1,M=null,p=null,y=null;const x=ic({ent:b=>c(b),get:b=>l.get(b),world:b=>d(b),setWorldTRS:(b,C,R,W,se,re,Ee,be,Le,Ge,qe)=>N(b,Vs([C,R,W],[se,re,Ee,be],[Le,Ge,qe])),setWorldPosition:(b,C,R,W)=>V(b,C,R,W),localMatrixChanged:b=>{var C;return(C=t.localMatrixChanged)==null?void 0:C.call(t,b)},parentOf:b=>{var C;return((C=l.get(b))==null?void 0:C.parent)??0},glbBytes:b=>{var C,R;return(R=(C=l.get(b))==null?void 0:C.model)==null?void 0:R.buffer},seedAnimator:(b,C)=>B.methods.animatorSeedPose(b,C),jointRanges:(b,C,R)=>B.methods.animatorJointRanges(b,C,R)}),T=uc({ent:b=>c(b),world:b=>d(b),cameraPosition:()=>{var R;const b=(R=o.get(v))==null?void 0:R.camera;if(b===void 0)return null;const C=u(b);return[C[12],C[13],C[14]]},created:(b,C)=>{var R;return(R=t.particleSystemCreated)==null?void 0:R.call(t,b,C)},frame:(b,C)=>{var R;return(R=t.particlesFrame)==null?void 0:R.call(t,b,C)},destroyed:b=>{var C;return(C=t.particleSystemDestroyed)==null?void 0:C.call(t,b)}}),B=tc({get:b=>l.get(b),world:b=>d(b),localMatrixChanged:b=>{var C;return(C=t.localMatrixChanged)==null?void 0:C.call(t,b)},getBuffer:b=>e.getBuffer(b),setMorphWeights:(b,C)=>{var R;return(R=t.morphWeights)==null?void 0:R.call(t,b,C)},applyRootMotion:(b,C,R,W,se,re)=>{const Ee=d(b);return x.applyRootMotion(b,Ee[0]*C+Ee[4]*R+Ee[8]*W,Ee[2]*C+Ee[6]*R+Ee[10]*W,se,re)}}),F=b=>{const C={id:b,name:"",m:t.allocMatrix(b),parent:0,children:[],visible:!0,materials:[]};return(C.m[0]!==1||C.m[5]!==1||C.m[10]!==1||C.m[15]!==1)&&Bt(C.m,He()),l.set(b,C),C},P=()=>F(g++),c=b=>{let C=l.get(b);return C||(C=F(b),b>=g&&(g=b+1)),C},u=b=>{const C=c(b);return C.parent===0?C.m:dt(new Float32Array(16),u(C.parent),C.m)},d=b=>{const C=u(b);return C instanceof Float32Array?C:Float32Array.from(C)},w=b=>{if(b.parent!==0){const C=l.get(b.parent);C&&(C.children=C.children.filter(R=>R!==b.id)),b.parent=0}},S=(b,C,R)=>{var se,re;const W=c(b);if(W.parent!==C){if(R){const Ee=d(b),be=C===0?Ee:dt(new Float32Array(16),St(d(C)),Ee);Bt(W.m,be)}w(W),C!==0&&(W.parent=C,c(C).children.push(b)),(se=t.parentChanged)==null||se.call(t,b,C),(re=t.localMatrixChanged)==null||re.call(t,b)}},N=(b,C)=>{var W;const R=c(b);Bt(R.m,R.parent===0?C:dt(new Float32Array(16),St(d(R.parent)),C)),(W=t.localMatrixChanged)==null||W.call(t,b)},V=(b,C,R,W)=>{var Ee;const se=c(b),re=se.m;if(se.parent===0)re[12]=C,re[13]=R,re[14]=W;else{const be=St(d(se.parent));re[12]=be[0]*C+be[4]*R+be[8]*W+be[12],re[13]=be[1]*C+be[5]*R+be[9]*W+be[13],re[14]=be[2]*C+be[6]*R+be[10]*W+be[14]}(Ee=t.localMatrixChanged)==null||Ee.call(t,b)},L=b=>{const C=o.get(b),R=(C==null?void 0:C.overlayOf)!==void 0?o.get(C.overlayOf):C;return(R==null?void 0:R.projection)??i},j=b=>{for(let C=b;C!==0;){for(const R of o.values())if(R.entities.has(C))return R;C=c(C).parent}return null},X=b=>{var se;const C=(se=e.getSourceName)==null?void 0:se.call(e,b);if(!C)return;const R=C.startsWith("lecodesfile://")?decodeURIComponent(C.slice(14)):C;return(R.includes("/")||R.includes("\\"))&&!R.startsWith("http")?R.split(/[\\/]/).pop()??R:R},oe=b=>{let C=a.get(b);return C||(C={shader:"unknown",uniforms:{}},a.set(b,C)),C},Y=(b,C,R)=>{var W;oe(b).uniforms[C]=R,(W=t.uniformChanged)==null||W.call(t,b,C,R)},I=b=>{const C=e.getBuffer(b),R=C?Xl(C):null,W=P();if(W.model={source:X(b),systemId:b,animations:(R==null?void 0:R.animations)??[],loaded:R!==null,...C&&{buffer:C}},R&&R.animations.length>0&&C&&Xs()&&(W.model.clipSet=B.registerGlbClips(C)),!R)return{rootId:W.id,entIds:[]};const se=R.nodes.map(()=>P().id);R.nodes.forEach((re,Ee)=>{var Le;const be=c(se[Ee]);be.name=re.name??"",Bt(be.m,re.matrix),(Le=t.localMatrixChanged)==null||Le.call(t,be.id),re.skinJoint&&(be.skinJoint=!0),re.mesh&&(be.mesh={kind:0,vertexCount:0,primitives:re.mesh.primitives},re.mesh.min&&re.mesh.max&&(be.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]],be.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 Ge of re.children)S(se[Ge],be.id,!1)});for(const re of R.roots)S(se[re],W.id,!1);return{rootId:W.id,entIds:se}},$=(b,C)=>{var se,re;const R=c(b),W=P();C.set(R.id,W.id),W.name=R.name,Bt(W.m,R.m),W.visible=R.visible,R.skinJoint&&(W.skinJoint=!0),R.light&&(W.light={...R.light}),R.punctual&&(W.punctual={...R.punctual}),R.mesh&&(W.mesh={...R.mesh}),W.materials=[...R.materials],R.model&&(W.model={...R.model,animations:R.model.animations}),R.castShadows!==void 0&&(W.castShadows=R.castShadows),R.receiveShadows!==void 0&&(W.receiveShadows=R.receiveShadows),R.particles&&(W.particles=structuredClone(R.particles)),R.physics&&(W.physics=structuredClone(R.physics)),R.collider&&(W.collider=structuredClone(R.collider)),R.anchor&&(W.anchor=R.anchor),(se=t.localMatrixChanged)==null||se.call(t,W.id),(re=t.entityCloned)==null||re.call(t,R.id,W.id);for(const Ee of R.children)S($(Ee,C),W.id,!1);return W.id},G=b=>{var R;const C=l.get(b);if(C){for(const W of[...C.children])G(W);w(C);for(const W of o.values())W.entities.delete(b);(R=t.entityDestroyed)==null||R.call(t,b),B.onEntityDestroyed(b),T.onEntityDestroyed(b),l.delete(b)}},q=b=>{for(let C=b;C!==0;C=c(C).parent)if(!c(C).visible)return!1;return!0};let ae=1;const J=b=>{const C=b*ae;M==null||M(b),x.frame(C,y),B.evaluate(C),x.syncRagdolls(C),p==null||p(b),B.lateSolve(),T.update(C)},te=b=>{const C=Math.min(1e3,Math.floor(b/16));for(let R=0;R<C;R++)J(.016)},de=()=>v>=0||o.size>0,ve=()=>v,pe={createScene(){var C;const b=o.size;return o.set(b,{id:b,entities:new Set,overlays:[]}),(C=t.sceneCreated)==null||C.call(t,b),b},createOverlayScene(b){var R,W;const C=o.size;return o.set(C,{id:C,entities:new Set,overlays:[],overlayOf:b}),(R=o.get(b))==null||R.overlays.push(C),(W=t.sceneCreated)==null||W.call(t,C),C},createGLView(){},openScene(b){v=b},closeScene(){v=-1},addEntityToScene(b,C){var W;const R=o.get(b);if(R){for(const se of o.values())se!==R&&se.entities.delete(C);R.entities.add(C),(W=t.entitySceneChanged)==null||W.call(t,C,b,!0)}},removeEntityFromScene(b,C){var W;const R=o.get(b);R&&(R.entities.delete(C),(W=t.entitySceneChanged)==null||W.call(t,C,b,!1))},createEntity:()=>P().id,cloneEntity(b){var se,re;const C=c(b),R=new Map,W=$(b,R);if(C.parent!==0)S(W,C.parent,!1);else{const Ee=j(b);Ee&&(Ee.entities.add(W),(se=t.entitySceneChanged)==null||se.call(t,W,Ee.id,!0))}return(re=t.subtreeCloned)==null||re.call(t,b,W,R),W},destroyEntity(b){G(b)},setMatrix(b,C){var W;const R=c(b);Bt(R.m,C),(W=t.localMatrixChanged)==null||W.call(t,b)},setWorldMatrix(b,C){var se,re;const R=c(b);if(R.parent===0){Bt(R.m,C),(se=t.localMatrixChanged)==null||se.call(t,b);return}const W=dt(new Float32Array(16),St(d(R.parent)),Float32Array.from(C.subarray(0,16)));Bt(R.m,W),(re=t.localMatrixChanged)==null||re.call(t,b)},getChildCount:b=>c(b).children.length,getChild:(b,C)=>c(b).children[C]??0,setPosition(b,C,R,W){var re;const se=c(b).m;se[12]=C,se[13]=R,se[14]=W,(re=t.localMatrixChanged)==null||re.call(t,b)},setQuaternion(b,C,R,W,se){var re;Us(c(b).m,C,R,W,se),(re=t.localMatrixChanged)==null||re.call(t,b)},setEulerAngles(b,C,R,W,se){var re;ga(c(b).m,C,R,W,se),(re=t.localMatrixChanged)==null||re.call(t,b)},setScale(b,C,R,W){var se;zs(c(b).m,C,R,W),(se=t.localMatrixChanged)==null||se.call(t,b)},setParent(b,C,R){S(b,C,R)},setParentNull(b,C){S(b,0,C)},getParent:b=>c(b).parent,traverse(b,C){const R=W=>{C(W);for(const se of c(W).children)R(se)};for(const W of c(b).children)R(W)},findNode(b,C){const R=qs(C);let W=0,se=4;const re=Ee=>{const be=c(Ee),Le=fc(be.name,!!be.skinJoint,C,R);Le<se&&Le>=0&&(W=Ee,se=Le);for(const Ge of be.children){if(se===0)return;re(Ge)}};for(const Ee of c(b).children){if(se===0)break;re(Ee)}return W},createSunLight(b,C,R,W,se,re,Ee,be=100,Le=1){c(b).light={direction:[C,R,W],intensity:se,color:re,shadowsQuality:Ee,shadowDistance:be,shadowCascades:Le}},createPointLight(b,C,R,W,se){c(b).punctual={type:"point",intensity:C,color:R,range:W>0?W:1,inner:0,outer:0,castShadows:se}},createSpotLight(b,C,R,W,se,re,Ee){const[be,Le]=_s(se,re);c(b).punctual={type:"spot",intensity:C,color:R,range:W>0?W:1,inner:be,outer:Le,castShadows:Ee}},setLightCone(b,C,R){var se;const W=(se=l.get(b))==null?void 0:se.punctual;(W==null?void 0:W.type)==="spot"&&([W.inner,W.outer]=_s(C,R))},setLightIntensity(b,C){const R=l.get(b);R!=null&&R.light&&(R.light.intensity=C),R!=null&&R.punctual&&(R.punctual.intensity=C)},setLightColor(b,C){const R=l.get(b);R!=null&&R.light&&(R.light.color=C),R!=null&&R.punctual&&(R.punctual.color=C)},setDefaultIbl(b,C){const R=o.get(b);R&&(R.ibl=C)},setBloomOptions(b,C,R){const W=o.get(b);W&&(W.bloom=C?{strength:R}:void 0)},setSkybox(b,C){const R=o.get(b);R&&(R.skybox=C)},setSceneMultiSampleAntiAliasing(b,C){const R=o.get(b);R&&(R.antialias=C)},setSceneRenderOptions(){},setMaterialGlobalParameter(){},getCameraFov(b,C){const{fov:R}=L(b);if(C!==1)return R;const W=R*Math.PI/180;return 2*Math.atan(Math.tan(W/2)*(r/n))*180/Math.PI},setCameraProjection(b,C,R,W){const se=o.get(b);se&&(se.projection={fov:C,near:R,far:W})},getMatrix(b,C){return C.set(ze(b)),!0},getWorldMatrix(b,C){C.set(d(b))},getWorldPosition(b,C){const R=u(b);C[0]=R[12],C[1]=R[13],C[2]=R[14]},getWorldDirection(b,C,R){const W=u(b);R[0]=W[C*4],R[1]=W[C*4+1],R[2]=W[C*4+2]},getWorldMatrixInverse(b,C){C.set(St(d(b)))},getCameraViewDirection(b,C,R,W){var ht;const se=(ht=o.get(b))==null?void 0:ht.camera,re=se?u(se):He(),Ee=r/n,be=Math.tan(L(b).fov*Math.PI/360),Le=(C/r*2-1)*be*Ee,Ge=(1-R/n*2)*be,qe=re[0]*Le+re[4]*Ge-re[8],Ve=re[1]*Le+re[5]*Ge-re[9],Ye=re[2]*Le+re[6]*Ge-re[10],tt=Math.hypot(qe,Ve,Ye)||1;W[0]=qe/tt,W[1]=Ve/tt,W[2]=Ye/tt},setMesh(b,C,R,W,se,re,Ee,be,Le){var Ft;const Ge=c(b);let qe=1/0,Ve=1/0,Ye=1/0,tt=-1/0,ht=-1/0,vt=-1/0;for(let mt=0;mt+2<R.length;mt+=3){const ke=R[mt],rt=R[mt+1],bt=R[mt+2];ke<qe&&(qe=ke),ke>tt&&(tt=ke),rt<Ve&&(Ve=rt),rt>ht&&(ht=rt),bt<Ye&&(Ye=bt),bt>vt&&(vt=bt)}const xt=R.length>=3,Ut={kind:Ee,vertexCount:Math.floor(R.length/3),size:xt?[tt-qe,ht-Ve,vt-Ye]:void 0,center:xt?[(tt+qe)/2,(ht+Ve)/2,(vt+Ye)/2]:void 0};Ge.mesh=Ut,Ge.materials[0]=C,(Ft=t.meshSet)==null||Ft.call(t,b,C,Ut,{vertices:R,normals:W,indices:se,uv:re,colors:Le})},setCulling(){},setRenderPriority(){},setMaterialDepthTest(){},setMaterialDepthWrite(){},setMaterialCulling(){},setMaterialStencil(){},setSceneStencil(){},setCastShadows(b,C){c(b).castShadows=C},setReceiveShadows(b,C){c(b).receiveShadows=C},setGlbShadows(b,C,R){const W=se=>{const re=c(se);re.castShadows=C,re.receiveShadows=R;for(const Ee of re.children)W(Ee)};W(b)},setCastShadowsGlobal(){},setReceiveShadowsGlobal(){},hasMesh:b=>c(b).mesh!==void 0,createMaterial(b){var W;const C=m++,R={shader:X(b)??"unknown",uniforms:{}};return a.set(C,R),(W=t.materialCreated)==null||W.call(t,C,R,b),C},createMaterialNamed(b){var W;const C=m++,R={shader:b,uniforms:{}};return a.set(C,R),(W=t.materialCreated)==null||W.call(t,C,R),C},setMaterial(b,C,R){c(b).materials[R]=C},getMaterial:(b,C)=>c(b).materials[C]??0,setUniformRgb(b,C,R){Y(b,C,{kind:"rgb",v:R})},setUniformRgba(b,C,R){Y(b,C,{kind:"rgba",v:R})},setUniformFloat(b,C,R){Y(b,C,{kind:"float",v:R})},setUniformBoolean(b,C,R){Y(b,C,{kind:"bool",v:R})},setUniformTexture(b,C,R){Y(b,C,{kind:"texture",v:R})},setUniformArray(b,C,R){Y(b,C,{kind:"array",v:Array.from(R)})},setUniformNull(b,C){Y(b,C,{kind:"null"})},createTexture(b,C,R){const W=e.getBuffer(b);if(!W||W.byteLength===0){R();return}const[se,re]=pc(W),Ee=h++;f.set(Ee,{source:X(b),width:se,height:re}),C(Ee,se,re)},createTextureFromCanvas(b){const C=h++;return f.set(C,{source:`canvas#${b}`,width:0,height:0}),C},updateTextureFromCanvas(){},createTexturePixels(b,C,R){const W=h++;return f.set(W,{source:`pixels ${b}x${C}x${R}`,width:b,height:C}),W},updateTexturePixels(){},createMediaPlayerTexture(b){const C=h++;return f.set(C,{source:`mediaplayer#${b}`,width:0,height:0}),C},attachCameraToAR(b,C,R){const W=o.get(b);W&&(W.camera=C);const se=L(b);R(Gs(se.fov,r/n,se.near,se.far),se.fov)},getDisplaySize:()=>Float32Array.of(r,n),setVisible(b,C){var W;c(b).visible=C,(W=t.visibleChanged)==null||W.call(t,b,C);const R=se=>{const re=c(se);re.particles&&T.setVisible(se,q(se));for(const Ee of re.children)R(Ee)};R(b)},isVisible:b=>q(b),getName:b=>c(b).name,setName(b,C){c(b).name=C},createGlb(b,C,R){const{rootId:W,entIds:se}=I(b);if(!t.glbAttach){C(W);return}Promise.resolve(t.glbAttach(b,W,se)).then(()=>C(W)).catch(re=>R==null?void 0:R(re))},setGlbCulling(){},getGlbClipSet:b=>{var C,R;return((R=(C=l.get(b))==null?void 0:C.model)==null?void 0:R.clipSet)??0},...B.methods,setEarlyUpdate(b){M=b},setLateUpdate(b){p=b},setFixedUpdate(b){y=b},setTimeScale(b){ae=Number.isFinite(b)&&b>0?b:0},...x.methods,...T.methods};function ze(b){const C=c(b).m;return C instanceof Float32Array?C:Float32Array.from(C)}let Xe=null;return{width:r,height:n,fov:s,entities:l,scenes:o,materials:a,textures:f,cameraOverride:()=>Xe,setCameraOverride:b=>{Xe=b},ent:c,newEnt:P,worldMatrix:u,worldMatrixF:d,sourceName:X,setParentInternal:S,sceneOf:j,projectionOf:L,rebindMatrix:(b,C)=>{c(b).m=C},methods:pe,simulate:te,tick:J,hasActiveScene:de,activeSceneId:ve,physicsConfig:x.config,particleIndexPattern:T.indexPattern,nextTextureId:()=>h++,nextMaterialId:()=>m++}}const pc=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]},Nt=(t,e)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},Ys=(t,e)=>{var f,g;const r=(f=e.mesh)==null?void 0:f.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 m=0;m<8;m++){const h=n[0]+(m&1?s:-s),v=n[1]+(m&2?i:-i),M=n[2]+(m&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},mc=(t,e)=>{const r=[],n=s=>{const i=t.entities.get(s);if(i){r.push(...Ys(t,i));for(const l of i.children)n(l)}};return n(e),r};function gc(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),f=(n==null?void 0:n.fov)??l,g=n?xa(n.eye,n.target):St(t.worldMatrixF(r)),m=dt(new Float32Array(16),Gs(f,s/i,o,a),g),h=(F,P,c)=>{const u=m[3]*F+m[7]*P+m[11]*c+m[15],d=m[0]*F+m[4]*P+m[8]*c+m[12],w=m[1]*F+m[5]*P+m[9]*c+m[13],S=u>1e-4;return S?{sx:(d/u*.5+.5)*s,sy:(1-(w/u*.5+.5))*i,cw:u,inFront:S}:{sx:0,sy:0,cw:u,inFront:S}},v=F=>{for(let P=F;P!==0;P=t.ent(P).parent)if(!t.ent(P).visible)return!1;return!0},M=[e,...e.overlays.map(F=>t.scenes.get(F)).filter(F=>!!F)],p=new Set,y=[],x=F=>{if(!(p.has(F)||!t.entities.has(F))){p.add(F),y.push(F);for(const P of t.ent(F).children)x(P)}};for(const F of M)for(const P of F.entities)x(P);const T=[];for(const F of y){const P=t.ent(F);if(!v(F))continue;const c=P.model?"model":P.mesh&&!P.light?"mesh":P.particles?"particles":null;if(!c)continue;let u;if(c==="model")u=mc(t,F);else if(c==="mesh")u=Ys(t,P);else{const R=t.worldMatrixF(F);u=[[R[12],R[13],R[14]]]}if(u.length===0)continue;let d=1/0,w=1/0,S=1/0,N=-1/0,V=-1/0,L=-1/0;for(const R of u)R[0]<d&&(d=R[0]),R[0]>N&&(N=R[0]),R[1]<w&&(w=R[1]),R[1]>V&&(V=R[1]),R[2]<S&&(S=R[2]),R[2]>L&&(L=R[2]);const j=h((d+N)/2,(w+V)/2,(S+L)/2);let X=!1,oe=!1,Y=1/0,I=1/0,$=-1/0,G=-1/0;for(const R of u){const W=h(R[0],R[1],R[2]);if(!W.inFront){X=!0;continue}oe=!0,W.sx<Y&&(Y=W.sx),W.sx>$&&($=W.sx),W.sy<I&&(I=W.sy),W.sy>G&&(G=W.sy)}const q={kind:c,depth:Nt(j.cw,3),coverage:0};if(P.name&&(q.name=P.name),!oe){q.behindCamera=!0,T.push({obj:q,id:F});continue}const ae=Y,J=I,te=Math.max(0,$-Y),de=Math.max(0,G-I);q.rect=[Nt(ae,1),Nt(J,1),Nt(te,1),Nt(de,1)],j.inFront&&(q.center=[Nt(j.sx,1),Nt(j.sy,1)]);const ve=Math.max(0,ae),pe=Math.max(0,J),ze=Math.min(s,ae+te),Xe=Math.min(i,J+de),b=Math.max(0,ze-ve)*Math.max(0,Xe-pe);q.coverage=Nt(b/(s*i),4);const C=ae>=0&&J>=0&&ae+te<=s&&J+de<=i;b===0?q.offscreen=!0:(X||!C)&&(q.clipped=!0),T.push({obj:q,id:F})}const B=F=>{const P=[];for(let c=F;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:F,id:P}of T)F.name&&(F.path=B(P));return T.sort((F,P)=>P.obj.coverage-F.obj.coverage||F.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:T.map(F=>F.obj)}}const Lt=(t,e=4)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},$t=(t,e=4)=>Array.from(t,r=>Lt(r,e)),mr=(t,e)=>"#"+(t>>>0).toString(16).padStart(e?8:6,"0");function yc(t,e){const{entities:r,scenes:n,materials:s,textures:i,worldMatrixF:l}=t,o=M=>{var p;switch(M.kind){case"rgb":return mr(M.v,!1);case"rgba":return mr(M.v,!0);case"texture":return((p=i.get(M.v))==null?void 0:p.source)??`texture#${M.v}`;case"null":return null;default:return M.v}},a=M=>{const p=s.get(M);if(!p)return;const y={shader:p.shader.replace(/\.filamat$/,"")};for(const[x,T]of Object.entries(p.uniforms))y[x]=o(T);return y},f=M=>{var c;const p=t.ent(M),y=p.m,x=$t([y[12],y[13],y[14]]),T=Zn(y).map(u=>Lt(u,2)),B=Mr(y).map(u=>Lt(u,4)),F=p.light||p.punctual?"light":p.model?"model":p.mesh?"mesh":p.particles?"particles":p.anchor?"anchor":"node",P={};if(p.name&&(P.name=p.name),P.kind=F,x.some(u=>u!==0)&&(P.position=x),T.some(u=>u!==0)&&(P.rotation=T),B.some(u=>u!==1)&&(P.scale=B),p.visible||(P.visible=!1),p.mesh){const u={type:p.mesh.kind===1?"edges":p.mesh.kind===2?"vertices":"triangles"};p.mesh.size&&(u.size=$t(p.mesh.size)),(c=p.mesh.center)!=null&&c.some(w=>Lt(w)!==0)&&(u.center=$t(p.mesh.center)),P.mesh=u;const d=a(p.materials[0]);d&&(P.material=d)}if(p.model&&(P.model={...p.model.source&&{source:p.model.source},...!p.model.loaded&&{loaded:!1},animations:p.model.animations.map(u=>({name:u.name,duration:Lt(u.duration,2)}))}),p.light&&(P.light={type:"sun",direction:$t(p.light.direction),intensity:p.light.intensity,color:mr(p.light.color,!1),shadows:p.light.shadowsQuality}),p.punctual){const u=p.punctual;P.light={type:u.type,intensity:u.intensity,color:mr(u.color,!1),range:u.range,...u.type==="spot"&&{angle:Lt(u.outer*360/Math.PI,2),innerAngle:Lt(u.inner*360/Math.PI,2)},...u.castShadows&&{castShadows:!0}}}return p.particles&&(P.particles=p.particles),p.physics&&(P.physics=p.physics),p.ragdoll&&(P.ragdoll=p.ragdoll),p.collider&&(P.collider=p.collider),p.castShadows!==void 0&&(P.castShadows=p.castShadows),p.receiveShadows!==void 0&&(P.receiveShadows=p.receiveShadows),p.anchor&&(P.anchor=p.anchor),p.children.length>0&&(P.children=p.children.map(f)),P},g=M=>{const p=B=>{for(let F=t.ent(B).parent;F!==0;F=t.ent(F).parent)if(M.entities.has(F))return!0;return!1},y=[...M.entities].filter(B=>r.has(B)&&!p(B)),x={};M.arMode&&(x.ar={mode:M.arMode}),M.skybox!==void 0&&(x.skybox=mr(M.skybox,!1)),M.ibl!==void 0&&(x.environment={intensity:M.ibl}),M.bloom&&(x.bloom=M.bloom);const T=t.cameraOverride();if(T)x.camera={position:$t(T.eye),lookAt:$t(T.target),fov:T.fov??t.projectionOf(M.id).fov,inspection:!0};else if(M.camera!==void 0&&r.has(M.camera)){const B=l(M.camera),F=Zn(B).map(P=>Lt(P,2));x.camera={position:$t([B[12],B[13],B[14]]),...F.some(P=>P!==0)&&{rotation:F},fov:t.projectionOf(M.id).fov}}return x.nodes=y.map(f),M.overlays.length>0&&(x.overlays=M.overlays.map(B=>n.get(B)).filter(Boolean).map(B=>g(B))),x},m=n.get(t.activeSceneId())??[...n.values()].find(M=>M.overlayOf===void 0);if(!m)return null;const h=g(m),v=gc(t,m);return v&&(h.frame=v),h}const Cs=new Set,D=t=>{Cs.has(t)||(Cs.add(t),console.warn(`[gl-lite] ${t}: not supported by the lite 3D engine`))},vc={createEngine(){D("createEngine")},createScene(){return D("createScene"),0},createOverlayScene(){return D("createOverlayScene"),0},createGLView(){D("createGLView")},openScene(){D("openScene")},closeScene(){D("closeScene")},launchAR(){D("launchAR")},stopAR(){D("stopAR")},launchVR(){D("launchVR")},stopVR(){D("stopVR")},addEntityToScene(){D("addEntityToScene")},removeEntityFromScene(){D("removeEntityFromScene")},warmRender(){D("warmRender")},createEntity(){return D("createEntity"),{id:0}},cloneEntity(){return D("cloneEntity"),{id:0}},destroyEntity(){D("destroyEntity")},entityIsOwned(){return D("entityIsOwned"),!1},setMatrix(){D("setMatrix")},setWorldMatrix(){D("setWorldMatrix")},getChildCount(){return D("getChildCount"),0},getChild(){return D("getChild"),0},setPosition(){D("setPosition")},setQuaternion(){D("setQuaternion")},setEulerAngles(){D("setEulerAngles")},setScale(){D("setScale")},setParent(){D("setParent")},setParentNull(){D("setParentNull")},getParent(){return D("getParent"),0},traverse(){D("traverse")},createSunLight(){D("createSunLight")},setDefaultIbl(){D("setDefaultIbl")},setBloomOptions(){D("setBloomOptions")},setSkybox(){D("setSkybox")},setSceneMultiSampleAntiAliasing(){D("setSceneMultiSampleAntiAliasing")},setMaterialGlobalParameter(){D("setMaterialGlobalParameter")},getCameraFov(){return D("getCameraFov"),0},getMatrix(){D("getMatrix")},getWorldMatrix(){D("getWorldMatrix")},getWorldPosition(){D("getWorldPosition")},getWorldDirection(){D("getWorldDirection")},getWorldMatrixInverse(){D("getWorldMatrixInverse")},getCameraViewDirection(){D("getCameraViewDirection")},setMesh(){D("setMesh")},createInstancedMesh(){D("createInstancedMesh")},setInstanceTransforms(){D("setInstanceTransforms")},setInstancedMeshMaterial(){D("setInstancedMeshMaterial")},setInstancedMeshShadows(){D("setInstancedMeshShadows")},setCulling(){D("setCulling")},setCastShadows(){D("setCastShadows")},setReceiveShadows(){D("setReceiveShadows")},createTexture(){D("createTexture")},createTextureFromCanvas(){return D("createTextureFromCanvas"),0},updateTextureFromCanvas(){D("updateTextureFromCanvas")},createMaterial(){return D("createMaterial"),{id:0}},builtinMaterial(){return D("builtinMaterial"),null},setMaterial(){D("setMaterial")},getMaterial(){return D("getMaterial"),0},setUniformRgb(){D("setUniformRgb")},setUniformRgba(){D("setUniformRgba")},setUniformFloat(){D("setUniformFloat")},setUniformBoolean(){D("setUniformBoolean")},setUniformTexture(){D("setUniformTexture")},setUniformArray(){D("setUniformArray")},setUniformNull(){D("setUniformNull")},attachCameraToAR(){D("attachCameraToAR")},getDisplaySize(){return D("getDisplaySize"),new Float32Array(0)},setVisible(){D("setVisible")},isVisible(){return D("isVisible"),!1},createGlb(){D("createGlb")},setGlbCulling(){D("setGlbCulling")},setEarlyUpdate(){D("setEarlyUpdate")},setLateUpdate(){D("setLateUpdate")},setOnPhysicsEvent(){D("setOnPhysicsEvent")},loadClips(){D("loadClips")},createClipFromTracks(){return D("createClipFromTracks"),0},getClipSetInfo(){return D("getClipSetInfo"),[]},deriveClip(){return D("deriveClip"),0},setClipEvents(){D("setClipEvents")},getGlbClipSet(){return D("getGlbClipSet"),0},destroyClipSet(){D("destroyClipSet")},animatorCreate(){return D("animatorCreate"),0},animatorDestroy(){D("animatorDestroy")},animatorBind(){return D("animatorBind"),0},animatorBoundTracks(){return D("animatorBoundTracks"),0},animatorSetBlend(){D("animatorSetBlend")},animatorSetBlendValue(){D("animatorSetBlendValue")},animatorPlay(){D("animatorPlay")},animatorStop(){D("animatorStop")},animatorSeek(){D("animatorSeek")},animatorGetSlotTime(){return D("animatorGetSlotTime"),0},animatorGetSlotWeight(){return D("animatorGetSlotWeight"),0},animatorSetLayer(){D("animatorSetLayer")},animatorSetGlobal(){D("animatorSetGlobal")},animatorSetRootMotion(){D("animatorSetRootMotion")},animatorGetRootMotion(){D("animatorGetRootMotion")},setOnAnimatorEvent(){D("setOnAnimatorEvent")},animatorSetFeet(){D("animatorSetFeet")},animatorSlotCurveAt(){return D("animatorSlotCurveAt"),0},animatorSlotCurveInfo(){return D("animatorSlotCurveInfo"),!1},animatorSlotTurn(){return D("animatorSlotTurn"),0},animatorSlotTimeAtTurn(){return D("animatorSlotTimeAtTurn"),0},animatorLayerPhase(){return D("animatorLayerPhase"),0},animatorSeekPhase(){D("animatorSeekPhase")},animatorSlotFit(){return D("animatorSlotFit"),0},animatorSlotExit(){return D("animatorSlotExit"),0},animatorSlotAlign(){return D("animatorSlotAlign"),0},animatorSlotContacts(){return D("animatorSlotContacts"),0},animatorSlotTreads(){return D("animatorSlotTreads"),0},animatorSlotPhysics(){return D("animatorSlotPhysics"),0},animatorSlotFeatures(){return D("animatorSlotFeatures"),0},animatorKneeAxis(){return D("animatorKneeAxis"),0},animatorSlotKneePole(){return D("animatorSlotKneePole"),0},animatorSetStepWarp(){D("animatorSetStepWarp")},setOnAnimatorStep(){D("setOnAnimatorStep")},animatorSetMotion(){D("animatorSetMotion")},animatorSetDriveInput(){D("animatorSetDriveInput")},animatorSetSlotDrive(){D("animatorSetSlotDrive")},animatorSetWarpParams(){D("animatorSetWarpParams")},locoCreate(){return D("locoCreate"),0},locoDestroy(){D("locoDestroy")},locoSetParams(){D("locoSetParams")},locoDefaults(){D("locoDefaults")},locoSetEntry(){D("locoSetEntry")},locoClearSet(){D("locoClearSet")},locoSetInput(){D("locoSetInput")},locoStep(){D("locoStep")},locoUpdate(){D("locoUpdate")},locoRead(){D("locoRead")},locoBuildDatabase(){return D("locoBuildDatabase"),0},setColliderFromMesh(){D("setColliderFromMesh")},setColliderBox(){D("setColliderBox")},setColliderSphere(){D("setColliderSphere")},physicsHasSupport(){return D("physicsHasSupport"),!1},physicsConfigure(){D("physicsConfigure")},setInterpolation(){D("setInterpolation")},physicsBuildBox(){return D("physicsBuildBox"),0},physicsBuildSphere(){return D("physicsBuildSphere"),0},physicsBuildCylinder(){return D("physicsBuildCylinder"),0},physicsBuildCapsule(){return D("physicsBuildCapsule"),0},physicsBuildMesh(){return D("physicsBuildMesh"),0},physicsBuildMeshFromEntity(){return D("physicsBuildMeshFromEntity"),0},physicsDestroyShape(){D("physicsDestroyShape")},physicsCreateBody(){return D("physicsCreateBody"),0},physicsSetPickable(){D("physicsSetPickable")},physicsSetFriction(){D("physicsSetFriction")},physicsGetFriction(){return D("physicsGetFriction"),0},physicsRaycast(){return D("physicsRaycast"),0},characterCreate(){return D("characterCreate"),0},characterDestroy(){D("characterDestroy")},characterMove(){D("characterMove")},characterMoveFree(){D("characterMoveFree")},characterSetVerticalVelocity(){D("characterSetVerticalVelocity")},characterSetVelocity(){D("characterSetVelocity")},characterSetGravityScale(){D("characterSetGravityScale")},characterSetMaxSlope(){D("characterSetMaxSlope")},characterGetVelocity(){D("characterGetVelocity")},characterGetGroundState(){return D("characterGetGroundState"),0},characterSetPosition(){D("characterSetPosition")},vehicleCreate(){return D("vehicleCreate"),0},vehicleDestroy(){D("vehicleDestroy")},vehicleSetInput(){D("vehicleSetInput")},vehicleGetState(){D("vehicleGetState")},vehicleReset(){D("vehicleReset")},vehicleBodyId(){return D("vehicleBodyId"),0},physicsCreateBox(){return D("physicsCreateBox"),0},physicsCreateSphere(){return D("physicsCreateSphere"),0},physicsCreateCylinder(){return D("physicsCreateCylinder"),0},physicsSetLinearVelocity(){D("physicsSetLinearVelocity")},physicsGetLinearVelocity(){D("physicsGetLinearVelocity")},physicsApplyImpulse(){D("physicsApplyImpulse")},physicsSetBodyPosition(){D("physicsSetBodyPosition")},physicsRemoveBody(){D("physicsRemoveBody")},createMediaPlayerTexture(){return D("createMediaPlayerTexture"),0},getName(){return D("getName"),""},setName(){D("setName")},hasMesh(){return D("hasMesh"),!1},createARController(){D("createARController")},createRootAnchor(){return D("createRootAnchor"),0},createAnchor(){return D("createAnchor"),0},createParticleSystem(){D("createParticleSystem")},spawnParticles(){D("spawnParticles")},setParticleSystemConfig(){D("setParticleSystemConfig")},createNoise(){return D("createNoise"),0},setNoiseFrequency(){D("setNoiseFrequency")},setNoiseOctaves(){D("setNoiseOctaves")},setNoiseFractalLunacrity(){D("setNoiseFractalLunacrity")},setNoiseFractalGain(){D("setNoiseFractalGain")},getNoise2D(){return D("getNoise2D"),0},getNoise3D(){return D("getNoise3D"),0},captureImage(){D("captureImage")}},xc=""+new URL("neutral_ibl128-D-lzdkLN.ktx",import.meta.url).href,wc={backend:"webgl-lite"},tn=60,Es=.01,Fs=1e3,Mc={baseColorFactor:"uBaseColorFactor",metallicFactor:"uMetallic",roughnessFactor:"uRoughness",emissiveFactor:"uEmissive",baseColorMap:"uBaseColorMap",baseColorIndex:"uBaseColorIndex"},Ac=async(t,e={})=>{var Qe;const{fetch:r,getBlob:n,getBuffer:s,getLocalName:i,hasLocalBuffer:l,putBuffer:o,putLocalBuffer:a,getPlayer:f,removePlayers:g}=e.stores??ma,m=new Pi({canvas:t,dpr:1,alpha:e.transparent===!0||e.alpha===!0,antialias:!0,premultipliedAlpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:((Qe=e.preloads)==null?void 0:Qe.has("capture"))??!1}),h=m.gl;m.autoClear=!1;const v=qa(h),M=Ya(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 p={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:wa},punctualCount:{value:0},punctualPos:{value:new Array(jt*4).fill(0)},punctualColor:{value:new Array(jt*4).fill(0)},punctualDir:{value:new Array(jt*4).fill(0)}},y={value:[0,0,0,0]};let x=null;fetch(xc).then(A=>A.arrayBuffer()).then(A=>{x=Va(h,A),p.envMap.value=x.cubemap,p.envMapMaxLod.value=x.maxLod,p.iblSH.value=Array.from(x.sh)}).catch(A=>console.warn("[viewer-lite] IBL load failed:",A));const T=new Map,B=new Map,F=new Map,P=new Map,c=new Map,u=new Map,d={value:1},w=new Map;let S=1,N=!0,V=!0,L=null;const j=[],X=A=>{let _=T.get(A);if(!_){const E=new ct;E.matrixAutoUpdate=!1,E._entId=A,_={transform:E,drawables:[]},T.set(A,_)}return _},oe=(A,_=!1)=>{let E;if(A==="lit")E=new Ue(h,{vertex:kt,fragment:Sa,uniforms:{...p,baseColor:{value:[1,1,1]},baseColorMap:{value:v},roughness:{value:0},metallic:{value:0}}});else if(A==="terrain")E=new Ue(h,{vertex:kt,fragment:ba,uniforms:{...p,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 Ue(h,{vertex:kt,fragment:Ea,uniforms:{baseColorMap:{value:v},shadowMatrix:p.shadowMatrix}});else if(A==="shadow")E=new Ue(h,{vertex:kt,fragment:Fa,uniforms:{...p,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 O=A==="particles-quad";E=new Ue(h,{vertex:O?La:Ba,fragment:O?Ia:Na,uniforms:{baseColorMap:{value:v},sheetSize:{value:[1,1]},emissive:{value:0},additive:{value:0},softness:{value:0},depthFade:{value:0},...O?{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 Ue(h,{vertex:kt,fragment:_?Ca:_a,uniforms:{baseColor:{value:[1,1,1,1]},baseColorMap:{value:v},shadowMatrix:p.shadowMatrix},transparent:_}),_&&E.setBlendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA);return{kind:A,program:E}},Y=A=>{const _=Ja(s(A));if(!_)return null;if(_.unsupported)return console.warn(`[viewer-lite] custom material not supported in lite (${_.unsupported}) — rendering unlit`),null;_.hasVertexBlock&&console.warn("[viewer-lite] custom material has a vertex{} block — the custom vertex stage is ignored in lite");const E=sl(_);if(!E)return null;const O=E.needsSceneUniforms?{...p,userTime:y}:{shadowMatrix:p.shadowMatrix,userTime:y};for(const Q of E.uniforms)O[Q.key]={value:Q.value==="texture"?v:Q.value};const U=_.blending==="opaque"||_.blending==="masked",H=new Ue(h,{vertex:kt,fragment:E.fragment,uniforms:O,transparent:!U,cullFace:_.doubleSided||_.culling==="none"?!1:_.culling==="front"?h.FRONT:h.BACK,depthWrite:_.depthWrite});return h.getProgramParameter(H.program,h.LINK_STATUS)?(U||H.setBlendFunc(h.ONE,_.blending==="add"?h.ONE:h.ONE_MINUS_SRC_ALPHA),{kind:"custom",program:H,customParams:E.paramNames}):(console.warn("[viewer-lite] custom material failed to compile — rendering unlit"),null)},I=(A,_)=>{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"&&_!==void 0){const O=Y(_);if(O)return O;console.warn(`[viewer-lite] custom shader can't run here (material "${A||_}") — rendering unlit`)}return oe(E,A.startsWith("unlit-transparent"))},$=(A,_)=>{var U;const E=A.kind==="gltf"?Mc[_]??_:(U=A.customParams)!=null&&U.has(_)?`materialParams_${_}`:_,O=A.program.uniforms;return O[E]||(O[E]={value:0}),O[E]},G=(A,_,E)=>{const O=P.get(A);if(!O)return;if(_==="useBaseColorMap"&&(O.kind==="lit"||O.kind==="unlit")){if(E.kind==="bool"&&!E.v){const H=$(O,"baseColorMap");H.value instanceof je&&(H.value=v)}return}const U=$(O,_);switch(E.kind){case"rgb":{const[H,Q,ee]=Pa(E.v);Array.isArray(U.value)&&U.value.length===4?U.value=[H,Q,ee,U.value[3]]:U.value=[H,Q,ee];break}case"rgba":{const H=Ra(E.v);U.value=Array.isArray(U.value)&&U.value.length===3?H.slice(0,3):H;break}case"float":U.value=E.v;break;case"bool":U.value=E.v?1:0;break;case"array":U.value=Float32Array.from(E.v);break;case"texture":{const H=c.get(E.v);H&&(U.value=H);break}case"null":U.value instanceof je&&(U.value=v);break}},q=(A,_)=>{_.kind!=="lit"&&_.kind!=="gltf"&&_.kind!=="shadow"&&_.kind!=="custom"||A.onBeforeRender(()=>{const E=A.program.uniforms;if(E.shadowEnabled){const O=p.shadowEnabled.value===1&&A._receiveShadows!==!1;E.shadowEnabled=O?p.shadowEnabled:{value:0}}})},ae=(A,_,E,O)=>{const U=P.get(_);if(!U)return;const{vertices:H,normals:Q,indices:ee,uv:he,colors:le}=E,Me=new ot(h,{position:{size:3,data:Float32Array.from(H)},normal:{size:3,data:Q.length?Float32Array.from(Q):new Float32Array(H.length)},uv:{size:2,data:he.length?Float32Array.from(he):new Float32Array(H.length/3*2)},...le&&le.length?{color:{size:4,data:Float32Array.from(le,De=>De/255)}}:{},index:{data:Uint16Array.from(ee)}});Me.computeBoundingBox();const _e=O===1?h.LINES:O===2?h.POINTS:h.TRIANGLES,xe=new Je(h,{geometry:Me,program:U.program,mode:_e});xe.matrixAutoUpdate=!1,xe._entId=A,xe._castShadows=N,xe._receiveShadows=V,q(xe,U);const Se=X(A);for(const De of Se.drawables){Se.transform.removeChild(De);const nt=R.get(De);nt&&(nt.setParent(null),R.delete(De))}Se.drawables=[xe],Se.transform.addChild(xe)},J=async(A,_,E)=>{const O=s(A);let U;try{U=await Za(h,O,p,v)}catch(H){console.warn(`[viewer-lite] GLB "${i(A)??A}" drawables failed to load:`,H instanceof Error?H.message:H);return}U.nodes.forEach((H,Q)=>{const ee=E[Q];if(ee===void 0)return;const he=X(ee);he.transform.setParent(null),ce.rebindMatrix(ee,H.matrix),H.matrixAutoUpdate=!1,H._entId=ee,he.transform=H,he.drawables=[];for(const le of H.children)le.draw&&(le.matrixAutoUpdate=!1,le._entId=ee,le._castShadows=N,le._receiveShadows=V,he.drawables.push(le))});for(const H of U.roots)H.setParent(X(_).transform)},te=[],de=(A,_)=>{const E=X(A),O=X(_);for(const U of E.drawables){const H=U instanceof Mt?new Mt(h,{skeleton:U.skeleton,geometry:U.geometry,program:U.program,mode:U.mode}):new Je(h,{geometry:U.geometry,program:U.program,mode:U.mode});H instanceof Mt&&te.push(H),H._entId=_,H._castShadows=U._castShadows,H._receiveShadows=U._receiveShadows,H.frustumCulled=U.frustumCulled,H.matrixAutoUpdate=!1,O.drawables.push(H),O.transform.addChild(H)}},ve=A=>{for(const _ of te.splice(0)){const E=_.skeleton.joints.map(O=>{const U=O._entId===void 0?void 0:A.get(O._entId);if(U===void 0)return O;const H=X(U).transform;return H.bindInverse=O.bindInverse,H});_.skeleton={..._.skeleton,joints:E}}};let pe="off";const ze={value:[.05,.06,.08]},Xe=new Ue(h,{vertex:kt,fragment:es,uniforms:{uWireColor:ze,shadowMatrix:p.shadowMatrix}}),b=new Ue(h,{vertex:Ws("HAS_SKIN"),fragment:es,uniforms:{uWireColor:ze,shadowMatrix:p.shadowMatrix,boneTexture:{value:v},boneTextureSize:{value:4}}}),C=new WeakMap,R=new WeakMap,W=A=>{var E;let _=C.get(A);if(!_){const O={};for(const[Q,ee]of Object.entries(A.attributes))Q!=="index"&&(O[Q]={size:ee.size,data:ee.data,type:ee.type,normalized:ee.normalized,stride:ee.stride,offset:ee.offset,buffer:ee.buffer,count:ee.count});const U=A.attributes.position,H=U?U.count??U.data.length/U.size:0;O.index={data:Xa((E=A.attributes.index)==null?void 0:E.data,H)},_=new ot(h,O),C.set(A,_)}return _},se=A=>{var O,U;let _=R.get(A);if(_)return _;if(!A.parent||!((U=(O=A.geometry)==null?void 0:O.attributes)!=null&&U.position))return null;const E=W(A.geometry);return _=A instanceof Mt?new Mt(h,{skeleton:A.skeleton,geometry:E,program:b,mode:h.LINES}):new Je(h,{geometry:E,program:Xe,mode:h.LINES}),_.frustumCulled=!1,_.matrixAutoUpdate=!1,_.matrix.copy(A.matrix),_._entId=A._entId,_._castShadows=!1,_._receiveShadows=!1,_.setParent(A.parent),R.set(A,_),Ie(),_},re=()=>{for(const A of T.values())for(const _ of A.drawables)if(_.mode===h.TRIANGLES)if(pe==="off"){_.visible=!0;const E=R.get(_);E&&(E.visible=!1)}else{const E=se(_);_.visible=pe==="overlay",E&&(E.visible=!0)}},Ee=()=>{for(const A of j)A.video.videoWidth===0||A.video.currentTime===A.lastTime||(A.texture.image=A.video,A.texture.needsUpdate=!0,A.lastTime=A.video.currentTime)},be=new ln(h,{fov:tn,near:Es,far:Fs,aspect:1});be.matrixAutoUpdate=!1;let Le=!1,Ge=e.transparent===!0,qe=0,Ve=0,Ye=tn,tt=Es,ht=Fs,vt=1,xt=null,Ut=0;const Ft=new Ue(h,{vertex:yr(!1),fragment:vr,uniforms:{modelMatrix:{value:He()},shadowViewProjection:{value:He()}},cullFace:h.FRONT}),mt=new Ue(h,{vertex:yr(!0),fragment:vr,uniforms:{modelMatrix:{value:He()},shadowViewProjection:{value:He()},boneTexture:{value:v},boneTextureSize:{value:4}},cullFace:h.FRONT}),ke=new Ue(h,{vertex:yr(!1,!0),fragment:vr,uniforms:{shadowViewProjection:{value:He()}},cullFace:h.FRONT}),rt=new Map;let bt=!0;const zt=A=>{let _=rt.get(A);return _||(_=Wl(h,m),_.setEnabled(bt),rt.set(A,_)),_};let Vt=0;const Ie=()=>{Vt++},Sr=new Map,fr=A=>{Sr.get(A)!==Vt&&(A.updateMatrixWorld(),Sr.set(A,Vt))},_t=(A,_,E=!1)=>{const O=zt(A);fr(A),O.collect(A,_,!0,Vt,E),O.drawMain(_,p.shadowEnabled),E&&Ie()},un=A=>{var _;for(const[E,O]of ce.entities)if(O.light&&ce.methods.isVisible(E)&&((_=ce.sceneOf(E))==null?void 0:_.id)===A)return O.light;return null};let Lr=!1;const fn=A=>{var he,le;const _=(he=ce.scenes.get(A))==null?void 0:he.camera,E=_!==void 0?ce.worldMatrix(_):He(),O=[];for(const[Me,_e]of ce.entities){const xe=_e.punctual;if(!xe||!(xe.intensity>0)||!ce.methods.isVisible(Me)||((le=ce.sceneOf(Me))==null?void 0:le.id)!==A)continue;const Se=ce.worldMatrix(Me);O.push({id:Me,p:xe,w:Se,near:Math.hypot(Se[12]-E[12],Se[13]-E[13],Se[14]-E[14])-xe.range})}O.length>jt&&(O.sort((Me,_e)=>Me.near-_e.near),Lr||(Lr=!0,console.warn(`[viewer-lite] ${O.length} point / spot lights in the scene: the lite engine draws the ${jt} nearest the camera`)));const U=Math.min(O.length,jt),H=p.punctualPos.value,Q=p.punctualColor.value,ee=p.punctualDir.value;for(let Me=0;Me<U;Me++){const{p:_e,w:xe}=O[Me],Se=Me*4;H[Se]=xe[12],H[Se+1]=xe[13],H[Se+2]=xe[14],H[Se+3]=1/(_e.range*_e.range);const De=_e.intensity/(_e.type==="spot"?Math.PI:4*Math.PI);Q[Se]=(_e.color>>>16&255)/255*De,Q[Se+1]=(_e.color>>>8&255)/255*De,Q[Se+2]=(_e.color&255)/255*De;const nt=-xe[8],gt=-xe[9],Ze=-xe[10],Tt=Math.hypot(nt,gt,Ze)||1;if(ee[Se]=nt/Tt,ee[Se+1]=gt/Tt,ee[Se+2]=Ze/Tt,_e.type==="spot"){const Pt=Math.cos(_e.outer),Gt=1/Math.max(1/1024,Math.cos(_e.inner)-Pt);Q[Se+3]=Gt,ee[Se+3]=-Pt*Gt}else Q[Se+3]=0,ee[Se+3]=1}p.punctualCount.value=U},z=A=>{const _=[];return A.traverse(E=>E.visible?(E.draw&&_.push(E),!1):!0),_},Z=(A,_)=>{const E=_.shadowsQuality>=3?4096:_.shadowsQuality>=2?2048:1024;(!xt||Ut!==E)&&(xt=new Ds(h,{width:E,height:E,depthTexture:!0}),Ut=E);const O=zt(A),U=O.casterSingles,H=[1/0,1/0,1/0],Q=[-1/0,-1/0,-1/0],ee=[0,0,0];for(const Et of U){const ut=Et.geometry;if(ut.bounds||ut.computeBoundingBox(),!ut.bounds||!isFinite(ut.bounds.min.x))continue;const _r=Et.worldMatrix;for(let Ht=0;Ht<8;Ht++){At(ee,_r,Ht&1?ut.bounds.max.x:ut.bounds.min.x,Ht&2?ut.bounds.max.y:ut.bounds.min.y,Ht&4?ut.bounds.max.z:ut.bounds.min.z,1);for(let wt=0;wt<3;wt++)ee[wt]<H[wt]&&(H[wt]=ee[wt]),ee[wt]>Q[wt]&&(Q[wt]=ee[wt])}}if(O.casterBounds(H,Q),!isFinite(H[0])){p.shadowEnabled.value=0;return}const[he,le,Me]=H,[_e,xe,Se]=Q,De=(he+_e)/2,nt=(le+xe)/2,gt=(Me+Se)/2,Ze=Math.max(.5,Math.hypot(_e-he,xe-le,Se-Me)/2);let Tt=_.direction[0],Pt=_.direction[1],Gt=_.direction[2];const Ir=Math.hypot(Tt,Pt,Gt)||1;Tt/=Ir,Pt/=Ir,Gt/=Ir;const Ct=[De-Tt*Ze*2,nt-Pt*Ze*2,gt-Gt*Ze*2],Yt=-Tt,Kt=-Pt,Qt=-Gt,Zt=Math.abs(Pt)>.99?[1,0,0]:[0,1,0];let Jt=Zt[1]*Qt-Zt[2]*Kt,er=Zt[2]*Yt-Zt[0]*Qt,tr=Zt[0]*Kt-Zt[1]*Yt;const Or=Math.hypot(Jt,er,tr)||1;Jt/=Or,er/=Or,tr/=Or;const dn=Kt*tr-Qt*er,pn=Qt*Jt-Yt*tr,mn=Yt*er-Kt*Jt,at=new Float32Array(16);at[0]=Jt,at[4]=er,at[8]=tr,at[1]=dn,at[5]=pn,at[9]=mn,at[2]=Yt,at[6]=Kt,at[10]=Qt,at[12]=-(Jt*Ct[0]+er*Ct[1]+tr*Ct[2]),at[13]=-(dn*Ct[0]+pn*Ct[1]+mn*Ct[2]),at[14]=-(Yt*Ct[0]+Kt*Ct[1]+Qt*Ct[2]),at[15]=1;const Ks=ya(-Ze,Ze,-Ze,Ze,.05,Ze*4),br=dt(new Float32Array(16),Ks,at);Ft.uniforms.shadowViewProjection.value=br,mt.uniforms.shadowViewProjection.value=br,ke.uniforms.shadowViewProjection.value=br,p.shadowMatrix.value=br,p.shadowMap.value=xt.depthTexture,p.shadowMapSize.value=E,p.shadowEnabled.value=1,m.bindFramebuffer(xt),m.setViewport(E,E),h.clearColor(1,1,1,1),m.enable(h.DEPTH_TEST),m.setDepthMask(!0),h.clear(h.COLOR_BUFFER_BIT|h.DEPTH_BUFFER_BIT);const Qs=He();for(const Et of U){const ut=Et instanceof Mt,_r=ut?mt:Ft,Ht=Et.program;_r.uniforms.modelMatrix.value=ut?Qs:Et.worldMatrix,Et.program=_r,Et.draw({}),Et.program=Ht}O.drawShadow(ke),m.bindFramebuffer({buffer:null})},k=A=>{let _=qe===0?0:(A-qe)/1e3;_>.05&&(_=.05),qe=A;const E=A/1e3;y.value[0]=E,y.value[1]=E-Math.floor(E),ce.tick(_)},K=A=>{var ee;const _=t.width/Math.max(1,t.height),{fov:E,near:O,far:U}=ce.projectionOf(A);d.value=Math.max(1,t.height)/(2*Math.tan(E*Math.PI/360)),(_!==Ve||E!==Ye||O!==tt||U!==ht)&&(Ve=_,Ye=E,tt=O,ht=U,be.perspective({fov:E,aspect:_,near:O,far:U}));const H=(ee=ce.scenes.get(A))==null?void 0:ee.camera,Q=H!==void 0?ce.worldMatrix(H):He();for(let he=0;he<16;he++)be.matrix[he]=Q[he];be.worldMatrixNeedsUpdate=!0},ne=A=>{const _=ce.activeSceneId(),E=ce.scenes.get(_),O=B.get(_);if(!E||!O)return!1;k(A),Ee(),K(_),pe!=="off"?(re(),h.enable(h.POLYGON_OFFSET_FILL),h.polygonOffset(1,1)):h.disable(h.POLYGON_OFFSET_FILL),fr(O);const U=zt(O);U.collect(O,be,!0,Vt);const H=un(_);if(H){const ee=(H.color>>>16&255)/255,he=(H.color>>>8&255)/255,le=(H.color&255)/255;p.sunDirection.value=H.direction,p.sunColorIntensity.value=[ee,he,le,H.intensity],H.shadowsQuality>0?Z(O,H):p.shadowEnabled.value=0}else p.sunColorIntensity.value=[1,1,1,0],p.shadowEnabled.value=0;fn(_),p.iblLuminance.value=E.ibl??0;const Q=E.skybox!==void 0?[rr((E.skybox>>>16&255)/255),rr((E.skybox>>>8&255)/255),rr((E.skybox&255)/255)]:[rr(.1),rr(.25),rr(.57)];m.bindFramebuffer({buffer:null}),m.setViewport(t.width,t.height),Ge?h.clearColor(0,0,0,0):h.clearColor(Q[0],Q[1],Q[2],1),m.enable(h.DEPTH_TEST),m.setDepthMask(!0),h.clear(h.COLOR_BUFFER_BIT|h.DEPTH_BUFFER_BIT),U.drawMain(be,p.shadowEnabled),L==null||L.renderScenePass(Q);for(const ee of E.overlays){const he=B.get(ee);he&&(h.clear(h.DEPTH_BUFFER_BIT),_t(he,be))}return L==null||L.renderOverlayPass(),L==null||L.renderPreviewPass(O,Q),!0},ie=new Set,ue=()=>{if(Le){try{ne(performance.now())}catch(A){const _=A instanceof Error?A.message:String(A);ie.has(_)||(ie.add(_),console.error("[viewer-lite] render frame failed:",A))}requestAnimationFrame(ue)}},fe=A=>{var _;return(_=ce.sceneOf(A))==null?void 0:_.id};let me=[0,0,0];const ye=(A,_,E)=>{var Ze;const O=(Ze=ce.scenes.get(A))==null?void 0:Ze.camera,U=O!==void 0?ce.worldMatrix(O):He(),H=Math.max(1,t.width),Q=Math.max(1,t.height),ee=H/Q,he=_*vt,le=E*vt,Me=Math.tan(ce.projectionOf(A).fov*Math.PI/360),_e=(he/H*2-1)*Me*ee,xe=(1-le/Q*2)*Me,Se=U[0]*_e+U[4]*xe-U[8],De=U[1]*_e+U[5]*xe-U[9],nt=U[2]*_e+U[6]*xe-U[10],gt=Math.hypot(Se,De,nt)||1;return me=[U[12],U[13],U[14]],{origin:me,dir:[Se/gt,De/gt,nt/gt]}},Ae=(A,_,E)=>{const O=F.get(A);if(!O)return 0;let U=1/0,H=0;const Q=[0,0,0],ee=[0,0,0];for(const[he,le]of O){if(!ce.entities.has(he)||!ce.methods.isVisible(he))continue;const Me=St(ce.worldMatrixF(he));At(Q,Me,_[0],_[1],_[2],1),At(ee,Me,E[0],E[1],E[2],0);const _e=le.type==="box"?Jn(le.center,le.extent,Q,ee):va(le.center,le.radius,Q,ee);_e>0&&_e<U&&(U=_e,H=he)}return H},ge=(A,_,E)=>{const O=B.get(A);if(!O)return 0;let U=1/0,H=0;const Q=[0,0,0],ee=[0,0,0];O.updateMatrixWorld();for(const he of z(O)){const le=he.geometry;if(le.bounds||le.computeBoundingBox(),!le.bounds||!isFinite(le.bounds.min.x))continue;const Me=St(he.worldMatrix);At(Q,Me,_[0],_[1],_[2],1),At(ee,Me,E[0],E[1],E[2],0);const _e=[(le.bounds.min.x+le.bounds.max.x)/2,(le.bounds.min.y+le.bounds.max.y)/2,(le.bounds.min.z+le.bounds.max.z)/2],xe=[(le.bounds.max.x-le.bounds.min.x)/2,(le.bounds.max.y-le.bounds.min.y)/2,(le.bounds.max.z-le.bounds.min.z)/2],Se=Jn(_e,xe,Q,ee);Se>0&&Se<U&&(U=Se,H=he._entId??0)}return H},we=(A,_)=>{const E=ce.activeSceneId(),O=ce.scenes.get(E);if(!O||O.camera===void 0)return 0;const{origin:U,dir:H}=ye(E,A,_);for(let Q=O.overlays.length-1;Q>=0;Q--){const ee=Ae(O.overlays[Q],U,H);if(ee!==0)return ee}return Ae(E,U,H)},Re=A=>{A.mesh&&A.mesh.setParent(null),A.buffer&&h.deleteBuffer(A.buffer),A.mesh=null,A.geometry=null,A.buffer=null},Te=(A,_)=>{const E=P.get(A.materialId);if(_===Rt.MESH)return(E??oe("unlit")).program;const O=_!==Rt.POINTS;return E&&E.kind===(O?"particles-quad":"particles")?E.program:oe(O?"particles-quad":"particles").program},Ne=(A,_,E)=>{if(Re(_),_.version=E.geometryVersion,_.mode=E.mode,E.capacity===0)return;const O=ce.particleIndexPattern(A);if(O.length===0)return;let U;if(E.mode===Rt.MESH){const Q=E.capacity*E.meshVertexCount;U=new ot(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:O}})}else{const Q=h.createBuffer();_.buffer=Q;const ee=E.stride,he=E.mode===Rt.POINTS?E.capacity:E.mode===Rt.QUADS?E.capacity*4:(E.capacity+1)*2,le=(_e,xe)=>({size:_e,type:h.FLOAT,buffer:Q,stride:ee,offset:xe,count:he,data:new Float32Array(0)}),Me={position:le(3,0),color:le(4,12),custom:le(4,28)};E.mode!==Rt.POINTS&&(Me.aux=le(3,44),Me.corner=le(2,56)),Me.index={data:Uint16Array.from(O)},U=new ot(h,Me),h.bindBuffer(h.ARRAY_BUFFER,Q),h.bufferData(h.ARRAY_BUFFER,he*ee,h.DYNAMIC_DRAW),m.state.boundBuffer=Q}const H=new Je(h,{geometry:U,program:Te(_,E.mode),mode:E.mode===Rt.POINTS?h.POINTS:h.TRIANGLES});H.frustumCulled=!1,H.matrixAutoUpdate=!1,H._entId=A,H._particles=!0,H.setParent(X(A).transform),_.geometry=U,_.mesh=H},Oe=(A,_)=>{let E=u.get(A);if(E||(E={materialId:0,mesh:null,geometry:null,buffer:null,version:0,mode:-1},u.set(A,E)),(E.version!==_.geometryVersion||E.mode!==_.mode||!E.mesh)&&(Ne(A,E,_),Ie()),!E.mesh||!E.geometry)return;const O=_.indexCount>0;if(E.mesh.visible!==O&&(E.mesh.visible=O,Ie()),!!O){if(E.mesh.renderOrder=_.order,_.mode===Rt.MESH){const U=_.vertexCount,H=new Float32Array(_.bytes.buffer,_.bytes.byteOffset,U*10),Q=E.geometry.attributes.position,ee=E.geometry.attributes.normal,he=E.geometry.attributes.uv,le=Q.data,Me=ee.data,_e=he.data;for(let xe=0;xe<U;xe++){const Se=xe*10;le[xe*3]=H[Se],le[xe*3+1]=H[Se+1],le[xe*3+2]=H[Se+2];const De=H[Se+3],nt=H[Se+4],gt=H[Se+5],Ze=H[Se+6];Me[xe*3]=2*(De*gt+nt*Ze),Me[xe*3+1]=2*(nt*gt-De*Ze),Me[xe*3+2]=1-2*(De*De+nt*nt),_e[xe*2]=H[Se+8],_e[xe*2+1]=H[Se+9]}Q.needsUpdate=ee.needsUpdate=he.needsUpdate=!0}else E.buffer&&(h.bindBuffer(h.ARRAY_BUFFER,E.buffer),h.bufferSubData(h.ARRAY_BUFFER,0,_.bytes),m.state.boundBuffer=E.buffer);E.geometry.drawRange.start=0,E.geometry.drawRange.count=_.indexCount}},Be={allocMatrix:A=>X(A).transform.matrix,localMatrixChanged:A=>{X(A).transform.worldMatrixNeedsUpdate=!0,Ie()},parentChanged:(A,_)=>{Ie();const E=X(A).transform;if(_!==0)E.setParent(X(_).transform);else{const O=ce.sceneOf(A);E.setParent((O&&B.get(O.id))??null)}},sceneCreated:A=>{B.set(A,new ct),F.set(A,new Map)},entitySceneChanged:(A,_,E)=>{Ie();const O=B.get(_);if(!O)return;const U=X(A);if(E){for(const[H,Q]of F){if(H===_)continue;const ee=Q.get(A);ee&&(F.get(_).set(A,ee),Q.delete(A))}ce.ent(A).parent===0&&U.transform.setParent(O)}else ce.ent(A).parent===0&&U.transform.parent===O&&U.transform.setParent(null)},visibleChanged:(A,_)=>{X(A).transform.visible=_,Ie()},materialCreated:(A,_,E)=>{P.set(A,I(_.shader,E))},uniformChanged:(A,_,E)=>G(A,_,E),meshSet:(A,_,E,O)=>{ae(A,_,O,E.kind),Ie()},glbAttach:(A,_,E)=>J(A,_,E).then(Ie),morphWeights:(A,_)=>{const E=X(A).transform.weights;E&&E.set(_.subarray(0,Math.min(E.length,_.length)))},entityDestroyed:A=>{Ie();const _=T.get(A);_&&(_.transform.setParent(null),T.delete(A));for(const E of F.values())E.delete(A)},entityCloned:(A,_)=>{de(A,_),Ie()},subtreeCloned:(A,_,E)=>ve(E),particleSystemCreated:(A,_)=>{const E=u.get(A);E?(Re(E),E.materialId=_,E.version=0):u.set(A,{materialId:_,mesh:null,geometry:null,buffer:null,version:0,mode:-1})},particlesFrame:(A,_)=>Oe(A,_),particleSystemDestroyed:A=>{const _=u.get(A);_&&(Re(_),u.delete(A)),Ie()}},Pe=e.twins??{};await Promise.all([Pe.anim!==!1&&Yl(),Pe.physics!==!1&&ol(),Pe.particles!==!1&&ac()]);const ce=dc(Be,{getBuffer:s,getSourceName:i,width:t.width||1,height:t.height||1,fov:tn}),We=(A,_,E)=>{createImageBitmap(A).then(O=>{const U=new je(h,{image:O,internalFormat:h.SRGB8_ALPHA8,format:h.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),H=S++;c.set(H,U),_(H,O.width,O.height)}).catch(E)};return{...vc,...wc,...ce.methods,createEntity:()=>({id:ce.methods.createEntity()}),cloneEntity:A=>({id:ce.methods.cloneEntity(A)}),createMaterial:A=>({id:ce.methods.createMaterial(A)}),builtinMaterial:A=>({id:ce.methods.createMaterialNamed(A)}),createGlb(A,_,E){ce.methods.createGlb(A,O=>_({id:O}),E)},openScene(A){const _=Le;ce.methods.openScene(A),Le=ce.scenes.has(A),t.style.display="block",!_&&Le&&requestAnimationFrame(ue)},closeScene(){t.style.display="none",Le=!1,ce.methods.closeScene()},launchAR(){throw new Error("launchAR is not implemented")},stopAR(){throw new Error("stopAR is not implemented")},launchVR(A,_,E){E(new Error("VR is not supported on this device"))},stopVR(){},async warmRender(A,_){_()},attachCameraToAR(A,_,E){const O=ce.scenes.get(A);if(O){O.camera=_;for(const U of O.overlays){const H=ce.scenes.get(U);H&&(H.camera=_)}}},getCameraFov(A,_){const E=ce.projectionOf(A).fov;if(_!==1)return E;const O=E*Math.PI/180,U=t.width/Math.max(1,t.height);return 2*Math.atan(Math.tan(O/2)*U)*180/Math.PI},getCameraViewDirection(A,_,E,O){if(!ce.scenes.has(A)){O[0]=0,O[1]=0,O[2]=-1;return}const{dir:U}=ye(A,_,E);O[0]=U[0],O[1]=U[1],O[2]=U[2]},getDisplaySize:()=>Float32Array.of(m.width||t.width,m.height||t.height),createTexture(A,_,E){const O=(H,Q,ee)=>_({id:H},Q,ee),U=n(A);U.slice(0,12).arrayBuffer().then(async H=>{const Q=await wr(()=>import("./index-BttBnvIf.js"),__vite__mapDeps([0,1]),import.meta.url);if(!Q.isKtx2Bytes(new Uint8Array(H)))return!1;const ee=await U.arrayBuffer(),he=await Q.transcodeKtx2(h,ee),le=Q.ktx2IsSrgb(ee);let Me;he.isCompressedTexture?Me=new je(h,{image:he,internalFormat:le&&he.srgbInternalFormat?he.srgbInternalFormat:he.internalFormat,generateMipmaps:!1,minFilter:he.length>1?h.LINEAR_MIPMAP_LINEAR:h.LINEAR,flipY:!1}):Me=new je(h,{image:he,internalFormat:le?h.SRGB8_ALPHA8:h.RGBA8,format:h.RGBA,generateMipmaps:!0,flipY:!1,premultiplyAlpha:!1});const _e=S++;return c.set(_e,Me),O(_e,he.width,he.height),!0}).then(H=>{H||We(U,O,E)},E)},createTexturePixels(A,_,E,O,U){if(A<=0||_<=0||O.length<A*_*E)return{id:4294967295};const H=new Uint8Array(A*_*4);for(let he=0,le=A*_;he<le;he++){const Me=he*E,_e=he*4;H[_e]=O[Me],H[_e+1]=E>=2?O[Me+1]:O[Me],H[_e+2]=E>=3?O[Me+2]:O[Me],H[_e+3]=E>=4?O[Me+3]:255}const Q=new je(h,{image:H,width:A,height:_,internalFormat:U?h.SRGB8_ALPHA8:h.RGBA8,format:h.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1,minFilter:h.LINEAR,magFilter:h.LINEAR}),ee=S++;return c.set(ee,Q),w.set(ee,{rgba:H,width:A,height:_,channels:E}),{id:ee}},updateTexturePixels(A,_,E,O,U,H){const Q=w.get(A),ee=c.get(A);if(!Q||!ee)return;const he=Q.channels;for(let le=0;le<U;le++){const Me=E+le;if(!(Me<0||Me>=Q.height))for(let _e=0;_e<O;_e++){const xe=_+_e;if(xe<0||xe>=Q.width)continue;const Se=(le*O+_e)*he,De=(Me*Q.width+xe)*4;Q.rgba[De]=H[Se],Q.rgba[De+1]=he>=2?H[Se+1]:H[Se],Q.rgba[De+2]=he>=3?H[Se+2]:H[Se],Q.rgba[De+3]=he>=4?H[Se+3]:255}}ee.image=Q.rgba,ee.needsUpdate=!0},createTextureFromCanvas(A){var U;const _=(U=e.canvasHost)==null?void 0:U.readSurface(A);if(!_)return 0;const E=new je(h,{image:new Uint8Array(_.data.buffer.slice(0)),width:_.width,height:_.height,internalFormat:h.SRGB8_ALPHA8,format:h.RGBA,generateMipmaps:!1,flipY:!1}),O=S++;return c.set(O,E),O},updateTextureFromCanvas(A,_){var U;const E=(U=e.canvasHost)==null?void 0:U.readSurface(_),O=c.get(A);!E||!O||(O.image=new Uint8Array(E.data.buffer.slice(0)),O.width=E.width,O.height=E.height,O.needsUpdate=!0)},createMediaPlayerTexture(A){const _=f(A),E=new je(h,{generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1});j.push({video:_,texture:E,lastTime:-1});const O=S++;return c.set(O,E),O},setUniformTexture(A,_,E,O,U){ce.methods.setUniformTexture(A,_,E);const H=P.get(A),Q=c.get(E);if(!H||!Q)return;const ee=[h.CLAMP_TO_EDGE,h.REPEAT,h.MIRRORED_REPEAT];Q.wrapS=ee[O]??h.REPEAT,Q.wrapT=ee[U]??h.REPEAT,Q.needsUpdate=!0,$(H,_).value=Q},setMaterial(A,_,E){ce.methods.setMaterial(A,_,E);const O=P.get(_),U=X(A).drawables[E];!O||!U||(U.program=O.program,q(U,O),Ie())},getMaterial(A,_){const E=X(A).drawables[_];if(!E)return 0;const O=ce.nextMaterialId();return P.set(O,{kind:"gltf",program:E.program}),O},setCulling(A,_){for(const E of X(A).drawables)E.frustumCulled=_;Ie()},setGlbCulling(A,_){const E=O=>{for(const U of X(O).drawables)U.frustumCulled=_;for(const U of ce.ent(O).children)E(U)};E(A),Ie()},setRenderPriority(A,_){for(const E of X(A).drawables)E.renderOrder=_;Ie()},setMaterialDepthTest(A,_){const E=P.get(A);E&&(E.program.depthTest=_)},setMaterialDepthWrite(A,_){const E=P.get(A);E&&(E.program.depthWrite=_)},setMaterialCulling(A,_){const E=P.get(A);E&&(E.program.cullFace=_===0?!1:_===1?h.FRONT:h.BACK)},setCastShadows(A,_){ce.methods.setCastShadows(A,_);for(const E of X(A).drawables)E._castShadows=_;Ie()},setReceiveShadows(A,_){ce.methods.setReceiveShadows(A,_);for(const E of X(A).drawables)E._receiveShadows=_;Ie()},setGlbShadows(A,_,E){ce.methods.setGlbShadows(A,_,E);const O=U=>{for(const H of X(U).drawables)H._castShadows=_,H._receiveShadows=E;for(const H of ce.ent(U).children)O(H)};O(A),Ie()},setCastShadowsGlobal(A){N=A},setReceiveShadowsGlobal(A){V=A},setColliderFromMesh(A,_,E){var Q;if(E!==0)return;const O=X(_).drawables[0];if(!O)return;const U=O.geometry;if(U.bounds||U.computeBoundingBox(),!U.bounds)return;const H=fe(A)??ce.activeSceneId();(Q=F.get(H))==null||Q.set(A,{type:"box",center:[(U.bounds.min.x+U.bounds.max.x)/2,(U.bounds.min.y+U.bounds.max.y)/2,(U.bounds.min.z+U.bounds.max.z)/2],extent:[(U.bounds.max.x-U.bounds.min.x)/2,(U.bounds.max.y-U.bounds.min.y)/2,(U.bounds.max.z-U.bounds.min.z)/2]})},setColliderBox(A,_,E,O,U,H,Q){var he;const ee=fe(A)??ce.activeSceneId();(he=F.get(ee))==null||he.set(A,{type:"box",center:[_,E,O],extent:[U/2,H/2,Q/2]})},setColliderSphere(A,_,E,O,U){var Q;const H=fe(A)??ce.activeSceneId();(Q=F.get(H))==null||Q.set(A,{type:"sphere",center:[_,E,O],radius:U})},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:()=>ne(performance.now()),async captureImage(A,_,E){try{ne(performance.now());const O=new OffscreenCanvas(t.width,t.height);O.getContext("2d").drawImage(t,0,0);const H=await O.convertToBlob({type:"image/png"}),Q=await H.arrayBuffer();_(o(Q),"image.png",H.size)}catch{E()}},raycastView:we,_raycastView:we,raycastPick(A,_){const E=ce.activeSceneId(),O=ce.scenes.get(E);if(!O||O.camera===void 0)return 0;const U=we(A,_);if(U!==0)return U;const{origin:H,dir:Q}=ye(E,A,_);return ge(E,H,Q)},computeBoundingBox(A){const _=Float32Array.of(1/0,1/0,1/0,-1/0,-1/0,-1/0),E=[0,0,0],O=(U,H)=>{for(const Q of X(U).drawables){const ee=Q.geometry;if(ee.bounds||ee.computeBoundingBox(),!(!ee.bounds||!isFinite(ee.bounds.min.x)))for(let he=0;he<8;he++){const le=he&1?ee.bounds.max.x:ee.bounds.min.x,Me=he&2?ee.bounds.max.y:ee.bounds.min.y,_e=he&4?ee.bounds.max.z:ee.bounds.min.z;H?At(E,H,le,Me,_e,1):(E[0]=le,E[1]=Me,E[2]=_e);for(let xe=0;xe<3;xe++)E[xe]<_[xe]&&(_[xe]=E[xe]),E[xe]>_[xe+3]&&(_[xe+3]=E[xe])}}for(const Q of ce.ent(U).children){const ee=X(Q).transform.matrix,he=H?dt(new Float32Array(16),H,ee):Float32Array.from(ee);O(Q,he)}};return O(A,null),isFinite(_[0])||_.fill(0),_},stopAllPlayers(){g()},_dumpScene3d:()=>yc(ce),_setWireframeMode(A){pe=A==="overlay"||A==="only"?A:"off",ze.value=pe==="only"?[.62,.66,.72]:[.05,.06,.08],re(),Ie()},_setBatching(A){for(const _ of rt.values())_.setEnabled(A);bt=A,Ie()},_batchStats(){const A=B.get(ce.activeSceneId());return A?zt(A).stats():{batches:0,instances:0,visible:0,singles:0}},_editorConnect(A){return L??(L=zl({gl:h,renderer:m,canvas:t,camera:be,core:ce,sceneRoots:B,drawablesOf:_=>X(_).drawables,collectMeshes:z,wireGeometryFor:W,getViewRay:ye,renderScene:_t})),L.setHandlers(A),L.api},async createEngine(){},_fetch:r,_getPlayer:f,_createGLTexture(A){const _=new je(h,{image:A,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),E=S++;return c.set(E,_),_.update(),{gl:h,glTexture:_.texture,textureId:E}},_projectionOf:A=>ce.projectionOf(A),_setTransparent(A){Ge=A},_onResize(A,_,E=1){vt=E,m.dpr=E,m.setSize(A,_),Ve=0},_dispose(){var A;L==null||L.dispose(),L=null;for(const _ of rt.values())_.dispose();rt.clear(),this.closeScene(),this.stopAllPlayers(),(A=h.getExtension("WEBGL_lose_context"))==null||A.loseContext()}}},Sc=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 Ac(s,{preloads:e.preloads,twins:e.twins,alpha:e.alpha}),l=()=>{const g=t.clientWidth,m=t.clientHeight;g>0&&m>0&&i._onResize(g,m,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,m){return g.kind!==ai?!1:(m?(a=g.id,i.openScene(g.id)):a===g.id&&(a=-1,i.closeScene()),!0)},hit:(g,m,h)=>g===s&&a>=0?i.raycastPick(m,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()}}},_c=Object.freeze(Object.defineProperty({__proto__:null,createScene3d:Sc},Symbol.toStringTag,{value:"Module"}));export{Qn as G,_c as s};
|