lecodes-cli 2.3.1 → 2.4.1
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 +31 -8
- package/package.json +8 -8
- package/runtime/materials/foliage-cards.mat +251 -0
- package/runtime/sdk-types.json +1 -1
- package/runtime/web/VERSION.json +3 -3
- package/runtime/web/assets/materials-world-n3tLX5vO.bin +0 -0
- package/runtime/web/player.js +3 -3
- package/runtime/web-lite/assets/{index-By07xWGA.js → index-B2zEJlWS.js} +1 -1
- package/runtime/web-lite/assets/scene3d-Bew8g7Ws.js +1081 -0
- package/runtime/web-lite/features.json +2 -2
- package/runtime/web-lite/lite.js +2 -2
- package/src/commands/app/desktop.ts +4 -2
- package/src/commands/app/shared.ts +14 -7
- package/src/commands/desktop.ts +2 -1
- package/src/commands/dev.ts +1 -0
- package/src/hosts/desktopRenderer.ts +9 -2
- package/src/web/build.ts +24 -2
- package/runtime/web/assets/materials-world-CQWt8TAm.bin +0 -0
- package/runtime/web-lite/assets/scene3d-D5R7Vq3f.js +0 -888
|
@@ -0,0 +1,1081 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-B2zEJlWS.js","../lite.js","./creatorPhysics-k7wL0kV1.js","./creatorAnim-BOwKr-C1.js","./creatorParticles-DYlv4g1J.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as vi,_ as yi,g as xi,a as wi,b as Mi,h as bi,p as Ai,c as Si,d as _i,e as Tr,v as Cn,T as Ei}from"../lite.js";function _r(t){let e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function pn(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function Ci(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,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}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}function Fi(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function Ti(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function Yr(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function Pi(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 Ri(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 Pn(t){let e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function Bi(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function Li(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function gn(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 Hs(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Rn(t,e,r){let n=e[0],s=e[1],i=e[2],o=r[0],l=r[1],a=r[2];return t[0]=s*a-i*l,t[1]=i*o-n*a,t[2]=n*l-s*o,t}function Ni(t,e,r,n){let s=e[0],i=e[1],o=e[2];return t[0]=s+n*(r[0]-s),t[1]=i+n*(r[1]-i),t[2]=o+n*(r[2]-o),t}function Oi(t,e,r,n,s){const i=Math.exp(-n*s);let o=e[0],l=e[1],a=e[2];return t[0]=r[0]+(o-r[0])*i,t[1]=r[1]+(l-r[1])*i,t[2]=r[2]+(a-r[2])*i,t}function Ii(t,e,r){let n=e[0],s=e[1],i=e[2],o=r[3]*n+r[7]*s+r[11]*i+r[15];return o=o||1,t[0]=(r[0]*n+r[4]*s+r[8]*i+r[12])/o,t[1]=(r[1]*n+r[5]*s+r[9]*i+r[13])/o,t[2]=(r[2]*n+r[6]*s+r[10]*i+r[14])/o,t}function Di(t,e,r){let n=e[0],s=e[1],i=e[2],o=r[3]*n+r[7]*s+r[11]*i+r[15];return o=o||1,t[0]=(r[0]*n+r[4]*s+r[8]*i)/o,t[1]=(r[1]*n+r[5]*s+r[9]*i)/o,t[2]=(r[2]*n+r[6]*s+r[10]*i)/o,t}function Ui(t,e,r){let n=e[0],s=e[1],i=e[2];return t[0]=n*r[0]+s*r[3]+i*r[6],t[1]=n*r[1]+s*r[4]+i*r[7],t[2]=n*r[2]+s*r[5]+i*r[8],t}function zi(t,e,r){let n=e[0],s=e[1],i=e[2],o=r[0],l=r[1],a=r[2],f=r[3],p=l*i-a*s,g=a*n-o*i,h=o*s-l*n,v=l*h-a*g,M=a*p-o*h,d=o*g-l*p,y=f*2;return p*=y,g*=y,h*=y,v*=2,M*=2,d*=2,t[0]=n+p+v,t[1]=s+g+M,t[2]=i+h+d,t}const Gi=(function(){const t=[0,0,0],e=[0,0,0];return function(r,n){pn(t,r),pn(e,n),gn(t,t),gn(e,e);let s=Hs(t,e);return s>1?0:s<-1?Math.PI:Math.acos(s)}})();function Vi(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}class Ee 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):(Ci(this,e,r,n),this)}copy(e){return pn(this,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){return e.length?Fi(this,this,e):Yr(this,this,e),this}divide(e){return e.length?Ti(this,this,e):Yr(this,this,1/e),this}inverse(e=this){return Li(this,e),this}len(){return _r(this)}distance(e){return e?Pi(this,e):_r(this)}squaredLen(){return Pn(this)}squaredDistance(e){return e?Ri(this,e):Pn(this)}negate(e=this){return Bi(this,e),this}cross(e,r){return r?Rn(this,e,r):Rn(this,this,e),this}scale(e){return Yr(this,this,e),this}normalize(){return gn(this,this),this}dot(e){return Hs(this,e)}equals(e){return Vi(this,e)}applyMatrix3(e){return Ui(this,this,e),this}applyMatrix4(e){return Ii(this,this,e),this}scaleRotateMatrix4(e){return Di(this,this,e),this}applyQuaternion(e){return zi(this,this,e),this}angle(e){return Gi(this,e)}lerp(e,r){return Ni(this,this,e,r),this}smoothLerp(e,r,n){return Oi(this,this,e,r,n),this}clone(){return new Ee(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 Bn=new Ee;let Hi=1,ki=1,Ln=!1;class ht{constructor(e,r={}){e.canvas||console.error("gl not passed as first argument to Geometry"),this.gl=e,this.attributes=r,this.id=Hi++,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=ki++,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 o=1;s===35674&&(o=2),s===35675&&(o=3),s===35676&&(o=4);const l=i.size/o,a=o===1?0:o*o*4,f=o===1?0:o*4;for(let p=0;p<o;p++)this.gl.vertexAttribPointer(r+p,l,i.type,i.normalized,i.stride+a,i.offset+p*f),this.gl.enableVertexAttribArray(r+p),this.gl.renderer.vertexAttribDivisor(r+p,i.divisor)}),this.attributes.index&&this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.attributes.index.buffer)}draw({program:e,mode:r=this.gl.TRIANGLES}){var s;this.gl.renderer.currentGeometry!==`${this.id}_${e.attributeOrder}`&&(this.VAOs[e.attributeOrder]||this.createVAO(e),this.gl.renderer.bindVertexArray(this.VAOs[e.attributeOrder]),this.gl.renderer.currentGeometry=`${this.id}_${e.attributeOrder}`),e.attributeLocations.forEach((i,{name:o})=>{const l=this.attributes[o];l.needsUpdate&&this.updateAttribute(l)});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(!Ln)return console.warn("No position buffer data found to compute bounds"),Ln=!0}computeBoundingBox(e){e||(e=this.getPosition());const r=e.data,n=e.size;this.bounds||(this.bounds={min:new Ee,max:new Ee,center:new Ee,scale:new Ee,radius:1/0});const s=this.bounds.min,i=this.bounds.max,o=this.bounds.center,l=this.bounds.scale;s.set(1/0),i.set(-1/0);for(let a=0,f=r.length;a<f;a+=n){const p=r[a],g=r[a+1],h=r[a+2];s.x=Math.min(p,s.x),s.y=Math.min(g,s.y),s.z=Math.min(h,s.z),i.x=Math.max(p,i.x),i.y=Math.max(g,i.y),i.z=Math.max(h,i.z)}l.sub(i,s),o.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,o=r.length;i<o;i+=n)Bn.fromArray(r,i),s=Math.max(s,this.bounds.center.squaredDistance(Bn));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 Wi=1;const Nn={};class Ue{constructor(e,{vertex:r,fragment:n,uniforms:s={},transparent:i=!1,cullFace:o=e.BACK,frontFace:l=e.CCW,depthTest:a=!0,depthWrite:f=!0,depthFunc:p=e.LEQUAL}={}){e.canvas||console.error("gl not passed as first argument to Program"),this.gl=e,this.uniforms=s,this.id=Wi++,r||console.warn("vertex shader not supplied"),n||console.warn("fragment shader not supplied"),this.transparent=i,this.cullFace=o,this.frontFace=l,this.depthTest=a,this.depthWrite=f,this.depthFunc=p,this.blendFunc={},this.blendEquation={},this.stencilFunc={},this.stencilOp={},this.transparent&&!this.blendFunc.src&&(this.gl.renderer.premultipliedAlpha?this.setBlendFunc(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA):this.setBlendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA)),this.vertexShader=e.createShader(e.VERTEX_SHADER),this.fragmentShader=e.createShader(e.FRAGMENT_SHADER),this.program=e.createProgram(),e.attachShader(this.program,this.vertexShader),e.attachShader(this.program,this.fragmentShader),this.setShaders({vertex:r,fragment:n})}setShaders({vertex:e,fragment:r}){if(e&&(this.gl.shaderSource(this.vertexShader,e),this.gl.compileShader(this.vertexShader),this.gl.getShaderInfoLog(this.vertexShader)!==""&&console.warn(`${this.gl.getShaderInfoLog(this.vertexShader)}
|
|
3
|
+
Vertex Shader
|
|
4
|
+
${On(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
|
+
${On(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 o=0;o<n;o++){let l=this.gl.getActiveUniform(this.program,o);this.uniformLocations.set(l,this.gl.getUniformLocation(this.program,l.name));const a=l.name.match(/(\w+)/g);l.uniformName=a[0],l.nameComponents=a.slice(1)}this.attributeLocations=new Map;const s=[],i=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_ATTRIBUTES);for(let o=0;o<i;o++){const l=this.gl.getActiveAttrib(this.program,o),a=this.gl.getAttribLocation(this.program,l.name);a!==-1&&(s[a]=l.name,this.attributeLocations.set(l,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 o=this.uniforms[i.uniformName];for(const l of i.nameComponents){if(!o)break;if(l in o)o=o[l];else{if(Array.isArray(o.value))break;o=void 0;break}}if(!o)return In(`Active uniform ${i.name} has not been supplied`);if(o&&o.value===void 0)return In(`${i.name} uniform is missing a value parameter`);if(o.value.texture)return r=r+1,o.value.update(r),Kr(this.gl,i.type,s,r);if(o.value.length&&o.value[0].texture){const l=[];return o.value.forEach(a=>{r=r+1,a.update(r),l.push(r)}),Kr(this.gl,i.type,s,l)}Kr(this.gl,i.type,s,o.value)}),this.applyState(),e&&this.gl.renderer.setFrontFace(this.frontFace===this.gl.CCW?this.gl.CW:this.gl.CCW)}remove(){this.gl.deleteProgram(this.program)}}function Kr(t,e,r,n){n=n.length?$i(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(ji(s,n))return;s.set?s.set(n):Xi(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 On(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 $i(t){const e=t.length,r=t[0].length;if(r===void 0)return t;const n=e*r;let s=Nn[n];s||(Nn[n]=s=new Float32Array(n));for(let i=0;i<e;i++)s.set(t[i],i*r);return s}function ji(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 Xi(t,e){for(let r=0,n=t.length;r<n;r++)t[r]=e[r]}let Qr=0;function In(t){Qr>100||(console.warn(t),Qr++,Qr>100&&console.warn("More than 100 program warnings - stopping logs."))}const Zr=new Ee;let qi=1;class Yi{constructor({canvas:e=document.createElement("canvas"),width:r=300,height:n=150,dpr:s=1,alpha:i=!1,depth:o=!0,stencil:l=!1,antialias:a=!1,premultipliedAlpha:f=!1,preserveDrawingBuffer:p=!1,powerPreference:g="default",autoClear:h=!0,webgl:v=2}={}){const M={alpha:i,depth:o,stencil:l,antialias:a,premultipliedAlpha:f,preserveDrawingBuffer:p,powerPreference:g};this.dpr=s,this.alpha=i,this.color=!0,this.depth=o,this.stencil=l,this.premultipliedAlpha=f,this.autoClear=h,this.id=qi++,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(o=>{if(!o.visible)return!0;o.draw&&(n&&o.frustumCulled&&r&&!r.frustumIntersectsMesh(o)||i.push(o))}),s){const o=[],l=[],a=[];i.forEach(f=>{f.program.transparent?f.program.depthTest?l.push(f):a.push(f):o.push(f),f.zDepth=0,!(f.renderOrder!==0||!f.program.depthTest||!r)&&(f.worldMatrix.getTranslation(Zr),Zr.applyMatrix4(r.projectionViewMatrix),f.zDepth=Zr.z)}),o.sort(this.sortOpaque),l.sort(this.sortTransparent),a.sort(this.sortUI),i=o.concat(l,a)}return i}render({scene:e,camera:r,target:n=null,update:s=!0,sort:i=!0,frustumCull:o=!0,clear:l}){n===null?(this.bindFramebuffer(),this.setViewport(this.width*this.dpr,this.height*this.dpr)):(this.bindFramebuffer(n),this.setViewport(n.width,n.height)),(l||this.autoClear&&l!==!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:o,sort:i}).forEach(f=>{f.draw({camera:r})})}}function ks(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function Ws(t,e,r,n,s){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t}function Ki(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 $s(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],o=r*r+n*n+s*s+i*i;return o>0&&(o=1/Math.sqrt(o)),t[0]=r*o,t[1]=n*o,t[2]=s*o,t[3]=i*o,t}function js(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Qi(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function Zi(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 Dn(t,e,r){let n=e[0],s=e[1],i=e[2],o=e[3],l=r[0],a=r[1],f=r[2],p=r[3];return t[0]=n*p+o*l+s*f-i*a,t[1]=s*p+o*a+i*l-n*f,t[2]=i*p+o*f+n*a-s*l,t[3]=o*p-n*l-s*a-i*f,t}function Ji(t,e,r){r*=.5;let n=e[0],s=e[1],i=e[2],o=e[3],l=Math.sin(r),a=Math.cos(r);return t[0]=n*a+o*l,t[1]=s*a+i*l,t[2]=i*a-s*l,t[3]=o*a-n*l,t}function eo(t,e,r){r*=.5;let n=e[0],s=e[1],i=e[2],o=e[3],l=Math.sin(r),a=Math.cos(r);return t[0]=n*a-i*l,t[1]=s*a+o*l,t[2]=i*a+n*l,t[3]=o*a-s*l,t}function to(t,e,r){r*=.5;let n=e[0],s=e[1],i=e[2],o=e[3],l=Math.sin(r),a=Math.cos(r);return t[0]=n*a+s*l,t[1]=s*a-n*l,t[2]=i*a+o*l,t[3]=o*a-i*l,t}function ro(t,e,r,n){let s=e[0],i=e[1],o=e[2],l=e[3],a=r[0],f=r[1],p=r[2],g=r[3],h,v,M,d,y;return v=s*a+i*f+o*p+l*g,v<0&&(v=-v,a=-a,f=-f,p=-p,g=-g),1-v>1e-6?(h=Math.acos(v),M=Math.sin(h),d=Math.sin((1-n)*h)/M,y=Math.sin(n*h)/M):(d=1-n,y=n),t[0]=d*s+y*a,t[1]=d*i+y*f,t[2]=d*o+y*p,t[3]=d*l+y*g,t}function no(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],o=r*r+n*n+s*s+i*i,l=o?1/o:0;return t[0]=-r*l,t[1]=-n*l,t[2]=-s*l,t[3]=i*l,t}function so(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function io(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,o=(s+2)%3;n=Math.sqrt(e[s*3+s]-e[i*3+i]-e[o*3+o]+1),t[s]=.5*n,n=.5/n,t[3]=(e[i*3+o]-e[o*3+i])*n,t[i]=(e[i*3+s]+e[s*3+i])*n,t[o]=(e[o*3+s]+e[s*3+o])*n}return t}function oo(t,e,r="YXZ"){let n=Math.sin(e[0]*.5),s=Math.cos(e[0]*.5),i=Math.sin(e[1]*.5),o=Math.cos(e[1]*.5),l=Math.sin(e[2]*.5),a=Math.cos(e[2]*.5);return r==="XYZ"?(t[0]=n*o*a+s*i*l,t[1]=s*i*a-n*o*l,t[2]=s*o*l+n*i*a,t[3]=s*o*a-n*i*l):r==="YXZ"?(t[0]=n*o*a+s*i*l,t[1]=s*i*a-n*o*l,t[2]=s*o*l-n*i*a,t[3]=s*o*a+n*i*l):r==="ZXY"?(t[0]=n*o*a-s*i*l,t[1]=s*i*a+n*o*l,t[2]=s*o*l+n*i*a,t[3]=s*o*a-n*i*l):r==="ZYX"?(t[0]=n*o*a-s*i*l,t[1]=s*i*a+n*o*l,t[2]=s*o*l-n*i*a,t[3]=s*o*a+n*i*l):r==="YZX"?(t[0]=n*o*a+s*i*l,t[1]=s*i*a+n*o*l,t[2]=s*o*l-n*i*a,t[3]=s*o*a-n*i*l):r==="XZY"&&(t[0]=n*o*a-s*i*l,t[1]=s*i*a-n*o*l,t[2]=s*o*l+n*i*a,t[3]=s*o*a+n*i*l),t}const ao=ks,lo=Ws,co=js,ho=$s;class tr 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(o,l){const a=Reflect.set(...arguments);return a&&i.includes(l)&&o.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 Qi(this._target),this.onChange(),this}set(e,r,n,s){return e.length?this.copy(e):(lo(this._target,e,r,n,s),this.onChange(),this)}rotateX(e){return Ji(this._target,this._target,e),this.onChange(),this}rotateY(e){return eo(this._target,this._target,e),this.onChange(),this}rotateZ(e){return to(this._target,this._target,e),this.onChange(),this}inverse(e=this._target){return no(this._target,e),this.onChange(),this}conjugate(e=this._target){return so(this._target,e),this.onChange(),this}copy(e){return ao(this._target,e),this.onChange(),this}normalize(e=this._target){return ho(this._target,e),this.onChange(),this}multiply(e,r){return r?Dn(this._target,e,r):Dn(this._target,this._target,e),this.onChange(),this}dot(e){return co(this._target,e)}fromMatrix3(e){return io(this._target,e),this.onChange(),this}fromEuler(e,r){return oo(this._target,e,e.order),r||this.onChange(),this}fromAxisAngle(e,r){return Zi(this._target,e,r),this.onChange(),this}slerp(e,r){return ro(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 uo=1e-6;function fo(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[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 mo(t,e,r,n,s,i,o,l,a,f,p,g,h,v,M,d,y){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t[4]=i,t[5]=o,t[6]=l,t[7]=a,t[8]=f,t[9]=p,t[10]=g,t[11]=h,t[12]=v,t[13]=M,t[14]=d,t[15]=y,t}function po(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 go(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],o=e[4],l=e[5],a=e[6],f=e[7],p=e[8],g=e[9],h=e[10],v=e[11],M=e[12],d=e[13],y=e[14],x=e[15],P=r*l-n*o,B=r*a-s*o,T=r*f-i*o,E=n*a-s*l,c=n*f-i*l,u=s*f-i*a,m=p*d-g*M,w=p*y-h*M,_=p*x-v*M,L=g*y-h*d,z=g*x-v*d,N=h*x-v*y,$=P*N-B*z+T*L+E*_-c*w+u*m;return $?($=1/$,t[0]=(l*N-a*z+f*L)*$,t[1]=(s*z-n*N-i*L)*$,t[2]=(d*u-y*c+x*E)*$,t[3]=(h*c-g*u-v*E)*$,t[4]=(a*_-o*N-f*w)*$,t[5]=(r*N-s*_+i*w)*$,t[6]=(y*T-M*u-x*B)*$,t[7]=(p*u-h*T+v*B)*$,t[8]=(o*z-l*_+f*m)*$,t[9]=(n*_-r*z-i*m)*$,t[10]=(M*c-d*T+x*P)*$,t[11]=(g*T-p*c-v*P)*$,t[12]=(l*w-o*L-a*m)*$,t[13]=(r*L-n*w+s*m)*$,t[14]=(d*B-M*E-y*P)*$,t[15]=(p*E-g*B+h*P)*$,t):null}function Xs(t){let e=t[0],r=t[1],n=t[2],s=t[3],i=t[4],o=t[5],l=t[6],a=t[7],f=t[8],p=t[9],g=t[10],h=t[11],v=t[12],M=t[13],d=t[14],y=t[15],x=e*o-r*i,P=e*l-n*i,B=e*a-s*i,T=r*l-n*o,E=r*a-s*o,c=n*a-s*l,u=f*M-p*v,m=f*d-g*v,w=f*y-h*v,_=p*d-g*M,L=p*y-h*M,z=g*y-h*d;return x*z-P*L+B*_+T*w-E*m+c*u}function Un(t,e,r){let n=e[0],s=e[1],i=e[2],o=e[3],l=e[4],a=e[5],f=e[6],p=e[7],g=e[8],h=e[9],v=e[10],M=e[11],d=e[12],y=e[13],x=e[14],P=e[15],B=r[0],T=r[1],E=r[2],c=r[3];return t[0]=B*n+T*l+E*g+c*d,t[1]=B*s+T*a+E*h+c*y,t[2]=B*i+T*f+E*v+c*x,t[3]=B*o+T*p+E*M+c*P,B=r[4],T=r[5],E=r[6],c=r[7],t[4]=B*n+T*l+E*g+c*d,t[5]=B*s+T*a+E*h+c*y,t[6]=B*i+T*f+E*v+c*x,t[7]=B*o+T*p+E*M+c*P,B=r[8],T=r[9],E=r[10],c=r[11],t[8]=B*n+T*l+E*g+c*d,t[9]=B*s+T*a+E*h+c*y,t[10]=B*i+T*f+E*v+c*x,t[11]=B*o+T*p+E*M+c*P,B=r[12],T=r[13],E=r[14],c=r[15],t[12]=B*n+T*l+E*g+c*d,t[13]=B*s+T*a+E*h+c*y,t[14]=B*i+T*f+E*v+c*x,t[15]=B*o+T*p+E*M+c*P,t}function vo(t,e,r){let n=r[0],s=r[1],i=r[2],o,l,a,f,p,g,h,v,M,d,y,x;return e===t?(t[12]=e[0]*n+e[4]*s+e[8]*i+e[12],t[13]=e[1]*n+e[5]*s+e[9]*i+e[13],t[14]=e[2]*n+e[6]*s+e[10]*i+e[14],t[15]=e[3]*n+e[7]*s+e[11]*i+e[15]):(o=e[0],l=e[1],a=e[2],f=e[3],p=e[4],g=e[5],h=e[6],v=e[7],M=e[8],d=e[9],y=e[10],x=e[11],t[0]=o,t[1]=l,t[2]=a,t[3]=f,t[4]=p,t[5]=g,t[6]=h,t[7]=v,t[8]=M,t[9]=d,t[10]=y,t[11]=x,t[12]=o*n+p*s+M*i+e[12],t[13]=l*n+g*s+d*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 yo(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 xo(t,e,r,n){let s=n[0],i=n[1],o=n[2],l=Math.hypot(s,i,o),a,f,p,g,h,v,M,d,y,x,P,B,T,E,c,u,m,w,_,L,z,N,$,k;return Math.abs(l)<uo?null:(l=1/l,s*=l,i*=l,o*=l,a=Math.sin(r),f=Math.cos(r),p=1-f,g=e[0],h=e[1],v=e[2],M=e[3],d=e[4],y=e[5],x=e[6],P=e[7],B=e[8],T=e[9],E=e[10],c=e[11],u=s*s*p+f,m=i*s*p+o*a,w=o*s*p-i*a,_=s*i*p-o*a,L=i*i*p+f,z=o*i*p+s*a,N=s*o*p+i*a,$=i*o*p-s*a,k=o*o*p+f,t[0]=g*u+d*m+B*w,t[1]=h*u+y*m+T*w,t[2]=v*u+x*m+E*w,t[3]=M*u+P*m+c*w,t[4]=g*_+d*L+B*z,t[5]=h*_+y*L+T*z,t[6]=v*_+x*L+E*z,t[7]=M*_+P*L+c*z,t[8]=g*N+d*$+B*k,t[9]=h*N+y*$+T*k,t[10]=v*N+x*$+E*k,t[11]=M*N+P*$+c*k,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function wo(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function qs(t,e){let r=e[0],n=e[1],s=e[2],i=e[4],o=e[5],l=e[6],a=e[8],f=e[9],p=e[10];return t[0]=Math.hypot(r,n,s),t[1]=Math.hypot(i,o,l),t[2]=Math.hypot(a,f,p),t}function Mo(t){let e=t[0],r=t[1],n=t[2],s=t[4],i=t[5],o=t[6],l=t[8],a=t[9],f=t[10];const p=e*e+r*r+n*n,g=s*s+i*i+o*o,h=l*l+a*a+f*f;return Math.sqrt(Math.max(p,g,h))}const Ys=(function(){const t=[1,1,1];return function(e,r){let n=t;qs(n,r);let s=1/n[0],i=1/n[1],o=1/n[2],l=r[0]*s,a=r[1]*i,f=r[2]*o,p=r[4]*s,g=r[5]*i,h=r[6]*o,v=r[8]*s,M=r[9]*i,d=r[10]*o,y=l+g+d,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-p)/x):l>g&&l>d?(x=Math.sqrt(1+l-g-d)*2,e[3]=(h-M)/x,e[0]=.25*x,e[1]=(a+p)/x,e[2]=(v+f)/x):g>d?(x=Math.sqrt(1+g-l-d)*2,e[3]=(v-f)/x,e[0]=(a+p)/x,e[1]=.25*x,e[2]=(h+M)/x):(x=Math.sqrt(1+d-l-g)*2,e[3]=(a-p)/x,e[0]=(v+f)/x,e[1]=(h+M)/x,e[2]=.25*x),e}})();function bo(t,e,r,n){let s=_r([t[0],t[1],t[2]]);const i=_r([t[4],t[5],t[6]]),o=_r([t[8],t[9],t[10]]);Xs(t)<0&&(s=-s),r[0]=t[12],r[1]=t[13],r[2]=t[14];const a=t.slice(),f=1/s,p=1/i,g=1/o;a[0]*=f,a[1]*=f,a[2]*=f,a[4]*=p,a[5]*=p,a[6]*=p,a[8]*=g,a[9]*=g,a[10]*=g,Ys(e,a),n[0]=s,n[1]=i,n[2]=o}function Ao(t,e,r,n){const s=t,i=e[0],o=e[1],l=e[2],a=e[3],f=i+i,p=o+o,g=l+l,h=i*f,v=i*p,M=i*g,d=o*p,y=o*g,x=l*g,P=a*f,B=a*p,T=a*g,E=n[0],c=n[1],u=n[2];return s[0]=(1-(d+x))*E,s[1]=(v+T)*E,s[2]=(M-B)*E,s[3]=0,s[4]=(v-T)*c,s[5]=(1-(h+x))*c,s[6]=(y+P)*c,s[7]=0,s[8]=(M+B)*u,s[9]=(y-P)*u,s[10]=(1-(h+d))*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],o=r+r,l=n+n,a=s+s,f=r*o,p=n*o,g=n*l,h=s*o,v=s*l,M=s*a,d=i*o,y=i*l,x=i*a;return t[0]=1-g-M,t[1]=p+x,t[2]=h-y,t[3]=0,t[4]=p-x,t[5]=1-f-M,t[6]=v+d,t[7]=0,t[8]=h+y,t[9]=v-d,t[10]=1-f-g,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function _o(t,e,r,n,s){let i=1/Math.tan(e/2),o=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)*o,t[11]=-1,t[12]=0,t[13]=0,t[14]=2*s*n*o,t[15]=0,t}function Eo(t,e,r,n,s,i,o){let l=1/(e-r),a=1/(n-s),f=1/(i-o);return t[0]=-2*l,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)*l,t[13]=(s+n)*a,t[14]=(o+i)*f,t[15]=1,t}function Co(t,e,r,n){let s=e[0],i=e[1],o=e[2],l=n[0],a=n[1],f=n[2],p=s-r[0],g=i-r[1],h=o-r[2],v=p*p+g*g+h*h;v===0?h=1:(v=1/Math.sqrt(v),p*=v,g*=v,h*=v);let M=a*h-f*g,d=f*p-l*h,y=l*g-a*p;return v=M*M+d*d+y*y,v===0&&(f?l+=1e-6:a?f+=1e-6:a+=1e-6,M=a*h-f*g,d=f*p-l*h,y=l*g-a*p,v=M*M+d*d+y*y),v=1/Math.sqrt(v),M*=v,d*=v,y*=v,t[0]=M,t[1]=d,t[2]=y,t[3]=0,t[4]=g*y-h*d,t[5]=h*M-p*y,t[6]=p*d-g*M,t[7]=0,t[8]=p,t[9]=g,t[10]=h,t[11]=0,t[12]=s,t[13]=i,t[14]=o,t[15]=1,t}function zn(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 Gn(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 Fo(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 Mt extends Array{constructor(e=1,r=0,n=0,s=0,i=0,o=1,l=0,a=0,f=0,p=0,g=1,h=0,v=0,M=0,d=0,y=1){return super(e,r,n,s,i,o,l,a,f,p,g,h,v,M,d,y),this}get x(){return this[12]}get y(){return this[13]}get z(){return this[14]}get w(){return this[15]}set x(e){this[12]=e}set y(e){this[13]=e}set z(e){this[14]=e}set w(e){this[15]=e}set(e,r,n,s,i,o,l,a,f,p,g,h,v,M,d,y){return e.length?this.copy(e):(mo(this,e,r,n,s,i,o,l,a,f,p,g,h,v,M,d,y),this)}translate(e,r=this){return vo(this,r,e),this}rotate(e,r,n=this){return xo(this,n,e,r),this}scale(e,r=this){return yo(this,r,typeof e=="number"?[e,e,e]:e),this}add(e,r){return r?zn(this,e,r):zn(this,this,e),this}sub(e,r){return r?Gn(this,e,r):Gn(this,this,e),this}multiply(e,r){return e.length?r?Un(this,e,r):Un(this,this,e):Fo(this,this,e),this}identity(){return po(this),this}copy(e){return fo(this,e),this}fromPerspective({fov:e,aspect:r,near:n,far:s}={}){return _o(this,e,r,n,s),this}fromOrthogonal({left:e,right:r,bottom:n,top:s,near:i,far:o}){return Eo(this,e,r,n,s,i,o),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 go(this,e),this}compose(e,r,n){return Ao(this,e,r,n),this}decompose(e,r,n){return bo(this,e,r,n),this}getRotation(e){return Ys(e,this),this}getTranslation(e){return wo(e,this),this}getScaling(e){return qs(e,this),this}getMaxScaleOnAxis(){return Mo(this)}lookAt(e,r,n){return Co(this,e,r,n),this}determinant(){return Xs(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 To(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 Vn=new Mt;class Po 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(o,l){const a=Reflect.set(...arguments);return a&&i.includes(l)&&o.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 To(this._target,e,r),this.onChange(),this}fromQuaternion(e,r=this.order,n){return Vn.fromQuaternion(e),this._target.fromRotationMatrix(Vn,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 mt{constructor(){this.parent=null,this.children=[],this.visible=!0,this.matrix=new Mt,this.worldMatrix=new Mt,this.matrixAutoUpdate=!0,this.worldMatrixNeedsUpdate=!1,this.position=new Ee,this.quaternion=new tr,this.scale=new Ee(1),this.rotation=new Po,this.up=new Ee(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 Ro=new Mt,Bo=new Ee,Lo=new Ee;class Mn extends mt{constructor(e,{near:r=.1,far:n=100,fov:s=45,aspect:i=1,left:o,right:l,bottom:a,top:f,zoom:p=1}={}){super(),Object.assign(this,{near:r,far:n,fov:s,aspect:i,left:o,right:l,bottom:a,top:f,zoom:p}),this.projectionMatrix=new Mt,this.viewMatrix=new Mt,this.projectionViewMatrix=new Mt,this.worldPosition=new Ee,this.type=o||l?"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:o=this.top||1,zoom:l=this.zoom}={}){return Object.assign(this,{near:e,far:r,left:n,right:s,bottom:i,top:o,zoom:l}),n/=l,s/=l,i/=l,o/=l,this.projectionMatrix.fromOrthogonal({left:n,right:s,bottom:i,top:o,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(Ro.inverse(this.projectionMatrix)),e.applyMatrix4(this.worldMatrix),this}updateFrustum(){this.frustum||(this.frustum=[new Ee,new Ee,new Ee,new Ee,new Ee,new Ee]);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=Bo;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=Lo;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 No(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 Oo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],o=r+r,l=n+n,a=s+s,f=r*o,p=n*o,g=n*l,h=s*o,v=s*l,M=s*a,d=i*o,y=i*l,x=i*a;return t[0]=1-g-M,t[3]=p-x,t[6]=h+y,t[1]=p+x,t[4]=1-f-M,t[7]=v-d,t[2]=h-y,t[5]=v+d,t[8]=1-f-g,t}function Io(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 Do(t,e,r,n,s,i,o,l,a,f){return t[0]=e,t[1]=r,t[2]=n,t[3]=s,t[4]=i,t[5]=o,t[6]=l,t[7]=a,t[8]=f,t}function Uo(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1,t}function zo(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],o=e[4],l=e[5],a=e[6],f=e[7],p=e[8],g=p*o-l*f,h=-p*i+l*a,v=f*i-o*a,M=r*g+n*h+s*v;return M?(M=1/M,t[0]=g*M,t[1]=(-p*n+s*f)*M,t[2]=(l*n-s*o)*M,t[3]=h*M,t[4]=(p*r-s*a)*M,t[5]=(-l*r+s*i)*M,t[6]=v*M,t[7]=(-f*r+n*a)*M,t[8]=(o*r-n*i)*M,t):null}function Hn(t,e,r){let n=e[0],s=e[1],i=e[2],o=e[3],l=e[4],a=e[5],f=e[6],p=e[7],g=e[8],h=r[0],v=r[1],M=r[2],d=r[3],y=r[4],x=r[5],P=r[6],B=r[7],T=r[8];return t[0]=h*n+v*o+M*f,t[1]=h*s+v*l+M*p,t[2]=h*i+v*a+M*g,t[3]=d*n+y*o+x*f,t[4]=d*s+y*l+x*p,t[5]=d*i+y*a+x*g,t[6]=P*n+B*o+T*f,t[7]=P*s+B*l+T*p,t[8]=P*i+B*a+T*g,t}function Go(t,e,r){let n=e[0],s=e[1],i=e[2],o=e[3],l=e[4],a=e[5],f=e[6],p=e[7],g=e[8],h=r[0],v=r[1];return t[0]=n,t[1]=s,t[2]=i,t[3]=o,t[4]=l,t[5]=a,t[6]=h*n+v*o+f,t[7]=h*s+v*l+p,t[8]=h*i+v*a+g,t}function Vo(t,e,r){let n=e[0],s=e[1],i=e[2],o=e[3],l=e[4],a=e[5],f=e[6],p=e[7],g=e[8],h=Math.sin(r),v=Math.cos(r);return t[0]=v*n+h*o,t[1]=v*s+h*l,t[2]=v*i+h*a,t[3]=v*o-h*n,t[4]=v*l-h*s,t[5]=v*a-h*i,t[6]=f,t[7]=p,t[8]=g,t}function Ho(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 ko(t,e){let r=e[0],n=e[1],s=e[2],i=e[3],o=e[4],l=e[5],a=e[6],f=e[7],p=e[8],g=e[9],h=e[10],v=e[11],M=e[12],d=e[13],y=e[14],x=e[15],P=r*l-n*o,B=r*a-s*o,T=r*f-i*o,E=n*a-s*l,c=n*f-i*l,u=s*f-i*a,m=p*d-g*M,w=p*y-h*M,_=p*x-v*M,L=g*y-h*d,z=g*x-v*d,N=h*x-v*y,$=P*N-B*z+T*L+E*_-c*w+u*m;return $?($=1/$,t[0]=(l*N-a*z+f*L)*$,t[1]=(a*_-o*N-f*w)*$,t[2]=(o*z-l*_+f*m)*$,t[3]=(s*z-n*N-i*L)*$,t[4]=(r*N-s*_+i*w)*$,t[5]=(n*_-r*z-i*m)*$,t[6]=(d*u-y*c+x*E)*$,t[7]=(y*T-M*u-x*B)*$,t[8]=(M*c-d*T+x*P)*$,t):null}class Wo extends Array{constructor(e=1,r=0,n=0,s=0,i=1,o=0,l=0,a=0,f=1){return super(e,r,n,s,i,o,l,a,f),this}set(e,r,n,s,i,o,l,a,f){return e.length?this.copy(e):(Do(this,e,r,n,s,i,o,l,a,f),this)}translate(e,r=this){return Go(this,r,e),this}rotate(e,r=this){return Vo(this,r,e),this}scale(e,r=this){return Ho(this,r,e),this}multiply(e,r){return r?Hn(this,e,r):Hn(this,this,e),this}identity(){return Uo(this),this}copy(e){return Io(this,e),this}fromMatrix4(e){return No(this,e),this}fromQuaternion(e){return Oo(this,e),this}fromBasis(e,r,n){return this.set(e[0],e[1],e[2],r[0],r[1],r[2],n[0],n[1],n[2]),this}inverse(e=this){return zo(this,e),this}getNormalMatrix(e){return ko(this,e),this}}let $o=0;class et extends mt{constructor(e,{geometry:r,program:n,mode:s=e.TRIANGLES,frustumCulled:i=!0,renderOrder:o=0}={}){super(),e.canvas||console.error("gl not passed as first argument to Mesh"),this.gl=e,this.id=$o++,this.geometry=r,this.program=n,this.mode=s,this.frustumCulled=i,this.renderOrder=o,this.modelViewMatrix=new Mt,this.normalMatrix=new Wo,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 kn=new Uint8Array(4);function Wn(t){return(t&t-1)===0}let jo=1;class qe{constructor(e,{image:r,target:n=e.TEXTURE_2D,type:s=e.UNSIGNED_BYTE,format:i=e.RGBA,internalFormat:o=i,wrapS:l=e.CLAMP_TO_EDGE,wrapT:a=e.CLAMP_TO_EDGE,wrapR:f=e.CLAMP_TO_EDGE,generateMipmaps:p=n===(e.TEXTURE_2D||e.TEXTURE_CUBE_MAP),minFilter:g=p?e.NEAREST_MIPMAP_LINEAR:e.LINEAR,magFilter:h=e.LINEAR,premultiplyAlpha:v=!1,unpackAlignment:M=4,flipY:d=n==(e.TEXTURE_2D||e.TEXTURE_3D),anisotropy:y=0,level:x=0,width:P,height:B=P,length:T=1}={}){this.gl=e,this.id=jo++,this.image=r,this.target=n,this.type=s,this.format=i,this.internalFormat=o,this.minFilter=g,this.magFilter=h,this.wrapS=l,this.wrapT=a,this.wrapR=f,this.generateMipmaps=p,this.premultiplyAlpha=v,this.unpackAlignment=M,this.flipY=d,this.anisotropy=Math.min(y,this.gl.renderer.parameters.maxAnisotropy),this.level=x,this.width=P,this.height=B,this.length=T,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&&(!Wn(this.image.width)||!Wn(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,kn);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,kn);this.store.image=this.image}}}class Ks{constructor(e,{width:r=e.canvas.width,height:n=e.canvas.height,target:s=e.FRAMEBUFFER,color:i=1,depth:o=!0,stencil:l=!1,depthTexture:a=!1,wrapS:f=e.CLAMP_TO_EDGE,wrapT:p=e.CLAMP_TO_EDGE,wrapR:g=e.CLAMP_TO_EDGE,minFilter:h=e.LINEAR,magFilter:v=h,type:M=e.UNSIGNED_BYTE,format:d=e.RGBA,internalFormat:y=d,unpackAlignment:x,premultiplyAlpha:P}={}){this.gl=e,this.width=r,this.height=n,this.depth=o,this.stencil=l,this.buffer=this.gl.createFramebuffer(),this.target=s,this.gl.renderer.bindFramebuffer(this),this.textures=[];const B=[];for(let T=0;T<i;T++)this.textures.push(new qe(e,{width:r,height:n,wrapS:f,wrapT:p,wrapR:g,minFilter:h,magFilter:v,type:M,format:d,internalFormat:y,unpackAlignment:x,premultiplyAlpha:P,flipY:!1,generateMipmaps:!1})),this.textures[T].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+T,this.gl.TEXTURE_2D,this.textures[T].texture,0),B.push(this.gl.COLOR_ATTACHMENT0+T);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 qe(e,{width:r,height:n,minFilter:this.gl.NEAREST,magFilter:this.gl.NEAREST,format:this.stencil?this.gl.DEPTH_STENCIL:this.gl.DEPTH_COMPONENT,internalFormat:e.renderer.isWebgl2?this.stencil?this.gl.DEPTH24_STENCIL8:this.gl.DEPTH_COMPONENT16:this.gl.DEPTH_COMPONENT,type:this.stencil?this.gl.UNSIGNED_INT_24_8:this.gl.UNSIGNED_INT}),this.depthTexture.update(),this.gl.framebufferTexture2D(this.target,this.stencil?this.gl.DEPTH_STENCIL_ATTACHMENT:this.gl.DEPTH_ATTACHMENT,this.gl.TEXTURE_2D,this.depthTexture.texture,0)):(o&&!l&&(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)),l&&!o&&(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)),o&&l&&(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 Xo(t,e){return t[0]=e[0],t[1]=e[1],t}function qo(t,e,r){return t[0]=e,t[1]=r,t}function $n(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t}function jn(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t}function Yo(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t}function Ko(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t}function Jr(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t}function Qo(t,e){var r=e[0]-t[0],n=e[1]-t[1];return Math.sqrt(r*r+n*n)}function Zo(t,e){var r=e[0]-t[0],n=e[1]-t[1];return r*r+n*n}function Xn(t){var e=t[0],r=t[1];return Math.sqrt(e*e+r*r)}function Jo(t){var e=t[0],r=t[1];return e*e+r*r}function ea(t,e){return t[0]=-e[0],t[1]=-e[1],t}function ta(t,e){return t[0]=1/e[0],t[1]=1/e[1],t}function ra(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 na(t,e){return t[0]*e[0]+t[1]*e[1]}function qn(t,e){return t[0]*e[1]-t[1]*e[0]}function sa(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 ia(t,e,r,n,s){const i=Math.exp(-n*s);let o=e[0],l=e[1];return t[0]=r[0]+(o-r[0])*i,t[1]=r[1]+(l-r[1])*i,t}function oa(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 aa(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 la(t,e){return t[0]===e[0]&&t[1]===e[1]}class yr 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):(qo(this,e,r),this)}copy(e){return Xo(this,e),this}add(e,r){return r?$n(this,e,r):$n(this,this,e),this}sub(e,r){return r?jn(this,e,r):jn(this,this,e),this}multiply(e){return e.length?Yo(this,this,e):Jr(this,this,e),this}divide(e){return e.length?Ko(this,this,e):Jr(this,this,1/e),this}inverse(e=this){return ta(this,e),this}len(){return Xn(this)}distance(e){return e?Qo(this,e):Xn(this)}squaredLen(){return this.squaredDistance()}squaredDistance(e){return e?Zo(this,e):Jo(this)}negate(e=this){return ea(this,e),this}cross(e,r){return r?qn(e,r):qn(this,e)}scale(e){return Jr(this,this,e),this}normalize(){return ra(this,this),this}dot(e){return na(this,e)}equals(e){return la(this,e)}applyMatrix3(e){return oa(this,this,e),this}applyMatrix4(e){return aa(this,this,e),this}lerp(e,r){return sa(this,this,e,r),this}smoothLerp(e,r,n){return ia(this,this,e,r,n),this}clone(){return new yr(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 ca 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):(Ws(this,e,r,n,s),this)}copy(e){return ks(this,e),this}normalize(){return $s(this,this),this}multiply(e){return Ki(this,this,e),this}dot(e){return js(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 Ht extends ht{constructor(e,{width:r=1,height:n=1,widthSegments:s=1,heightSegments:i=1,attributes:o={}}={}){const l=s,a=i,f=(l+1)*(a+1),p=l*a*6,g=new Float32Array(f*3),h=new Float32Array(f*3),v=new Float32Array(f*2),M=p>65536?new Uint32Array(p):new Uint16Array(p);Ht.buildPlane(g,h,v,M,r,n,0,l,a),Object.assign(o,{position:{size:3,data:g},normal:{size:3,data:h},uv:{size:2,data:v},index:{data:M}}),super(e,o)}static buildPlane(e,r,n,s,i,o,l,a,f,p=0,g=1,h=2,v=1,M=-1,d=0,y=0){const x=d,P=i/a,B=o/f;for(let T=0;T<=f;T++){let E=T*B-o/2;for(let c=0;c<=a;c++,d++){let u=c*P-i/2;if(e[d*3+p]=u*v,e[d*3+g]=E*M,e[d*3+h]=l/2,r[d*3+p]=0,r[d*3+g]=0,r[d*3+h]=l>=0?1:-1,n[d*2]=c/a,n[d*2+1]=1-T/f,T===f||c===a)continue;let m=x+c+T*(a+1),w=x+c+(T+1)*(a+1),_=x+c+(T+1)*(a+1)+1,L=x+c+T*(a+1)+1;s[y*6]=m,s[y*6+1]=w,s[y*6+2]=L,s[y*6+3]=w,s[y*6+4]=_,s[y*6+5]=L,y++}}}}class Yn extends ht{constructor(e,{width:r=1,height:n=1,depth:s=1,widthSegments:i=1,heightSegments:o=1,depthSegments:l=1,attributes:a={}}={}){const f=i,p=o,g=l,h=(f+1)*(p+1)*2+(f+1)*(g+1)*2+(p+1)*(g+1)*2,v=(f*p*2+f*g*2+p*g*2)*6,M=new Float32Array(h*3),d=new Float32Array(h*3),y=new Float32Array(h*2),x=h>65536?new Uint32Array(v):new Uint16Array(v);let P=0,B=0;Ht.buildPlane(M,d,y,x,s,n,r,g,p,2,1,0,-1,-1,P,B),P+=(g+1)*(p+1),B+=g*p,Ht.buildPlane(M,d,y,x,s,n,-r,g,p,2,1,0,1,-1,P,B),P+=(g+1)*(p+1),B+=g*p,Ht.buildPlane(M,d,y,x,r,s,n,g,f,0,2,1,1,1,P,B),P+=(f+1)*(g+1),B+=f*g,Ht.buildPlane(M,d,y,x,r,s,-n,g,f,0,2,1,1,-1,P,B),P+=(f+1)*(g+1),B+=f*g,Ht.buildPlane(M,d,y,x,r,n,-s,f,p,0,1,2,-1,-1,P,B),P+=(f+1)*(p+1),B+=f*p,Ht.buildPlane(M,d,y,x,r,n,s,f,p,0,1,2,1,-1,P,B),Object.assign(a,{position:{size:3,data:M},normal:{size:3,data:d},uv:{size:2,data:y},index:{data:x}}),super(e,a)}}class Kn extends ht{constructor(e,{radiusTop:r=.5,radiusBottom:n=.5,height:s=1,radialSegments:i=8,heightSegments:o=1,openEnded:l=!1,thetaStart:a=0,thetaLength:f=Math.PI*2,attributes:p={}}={}){const g=i,h=o,v=a,M=f,d=l?0:n&&r?2:1,y=(g+1)*(h+1+d)+d,x=g*h*6+d*g*3,P=new Float32Array(y*3),B=new Float32Array(y*3),T=new Float32Array(y*2),E=y>65536?new Uint32Array(x):new Uint16Array(x);let c=0,u=0;const m=[];w(),l||(r&&_(!0),n&&_(!1));function w(){let L,z;const N=new Ee,$=(n-r)/s;for(z=0;z<=h;z++){const k=[],J=z/h,Y=J*(n-r)+r;for(L=0;L<=g;L++){const D=L/g,X=D*M+v,V=Math.sin(X),q=Math.cos(X);P.set([Y*V,(.5-J)*s,Y*q],c*3),N.set(V,$,q).normalize(),B.set([N.x,N.y,N.z],c*3),T.set([D,1-J],c*2),k.push(c++)}m.push(k)}for(L=0;L<g;L++)for(z=0;z<h;z++){const k=m[z][L],J=m[z+1][L],Y=m[z+1][L+1],D=m[z][L+1];E.set([k,J,D,J,Y,D],u*3),u+=2}}function _(L){let z;const N=L===!0?r:n,$=L===!0?1:-1,k=c;for(P.set([0,.5*s*$,0],c*3),B.set([0,$,0],c*3),T.set([.5,.5],c*2),c++,z=0;z<=g;z++){const Y=z/g*M+v,D=Math.cos(Y),X=Math.sin(Y);P.set([N*X,.5*s*$,N*D],c*3),B.set([0,$,0],c*3),T.set([D*.5+.5,X*.5*$+.5],c*2),c++}for(z=0;z<g;z++){const J=k+z+1;L?E.set([J,J+1,k],u*3):E.set([J+1,J,k],u*3),u++}}Object.assign(p,{position:{size:3,data:P},normal:{size:3,data:B},uv:{size:2,data:T},index:{data:E}}),super(e,p)}}class Qs extends ht{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 ha extends ht{constructor(e,{radius:r=.5,tube:n=.2,radialSegments:s=8,tubularSegments:i=6,arc:o=Math.PI*2,attributes:l={}}={}){const a=(s+1)*(i+1),f=s*i*6,p=new Float32Array(a*3),g=new Float32Array(a*3),h=new Float32Array(a*2),v=a>65536?new Uint32Array(f):new Uint16Array(f),M=new Ee,d=new Ee,y=new Ee;let x=0;for(let P=0;P<=s;P++)for(let B=0;B<=i;B++,x++){const T=B/i*o,E=P/s*Math.PI*2;d.x=(r+n*Math.cos(E))*Math.cos(T),d.y=(r+n*Math.cos(E))*Math.sin(T),d.z=n*Math.sin(E),p.set([d.x,d.y,d.z],x*3),M.x=r*Math.cos(T),M.y=r*Math.sin(T),y.sub(d,M).normalize(),g.set([y.x,y.y,y.z],x*3),h.set([B/i,P/s],x*2)}x=0;for(let P=1;P<=s;P++)for(let B=1;B<=i;B++,x++){const T=(i+1)*P+B-1,E=(i+1)*(P-1)+B-1,c=(i+1)*(P-1)+B,u=(i+1)*P+B;v.set([T,E,u,E,c,u],x*6)}Object.assign(l,{position:{size:3,data:p},normal:{size:3,data:g},uv:{size:2,data:h},index:{data:v}}),super(e,l)}}const ua=new yr,fa=new yr,da=new yr,en=new Ee,Qn=new Ee,Zn=new Ee,ma=new Ee,pa=new Ee,ga=new Ee,Jn=new Ee,tn=new Ee,es=new Ee,ts=new Ee,va=new Ee,rs=new Mt;class ya{constructor(){this.origin=new Ee,this.direction=new Ee}castMouse(e,r=[0,0]){if(e.type==="orthographic"){const{left:n,right:s,bottom:i,top:o,zoom:l}=e,a=n/l+(s-n)/l*(r[0]*.5+.5),f=i/l+(o-i)/l*(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=rs,i=en,o=Qn,l=n;return l.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 p;if(r&&(o.copy(this.direction).scaleRotateMatrix4(s),p=r*o.len()),i.copy(this.origin).applyMatrix4(s),o.copy(this.direction).transformDirection(s),r&&i.distance(f.center)-f.radius>p)return;let g=0;if(a.geometry.raycast==="sphere"){if(i.distance(f.center)>f.radius&&(g=this.intersectSphere(f,i,o),!g))return}else if((i.x<f.min.x||i.x>f.max.x||i.y<f.min.y||i.y>f.max.y||i.z<f.min.z||i.z>f.max.z)&&(g=this.intersectBox(f,i,o),!g))return;r&&g>p||(a.hit||(a.hit={localPoint:new Ee,point:new Ee}),a.hit.localPoint.copy(o).multiply(g).add(i),a.hit.point.copy(a.hit.localPoint).applyMatrix4(a.worldMatrix),a.hit.distance=a.hit.point.distance(this.origin),l.push(a))}),l.sort((a,f)=>a.hit.distance-f.hit.distance),l}intersectMeshes(e,{cullFace:r=!0,maxDistance:n,includeUV:s=!0,includeNormal:i=!0,output:o=[]}={}){const l=this.intersectBounds(e,{maxDistance:n,output:o});if(!l.length)return l;const a=rs,f=en,p=Qn,g=Zn,h=ma,v=pa,M=ga,d=Jn,y=tn,x=ua,P=fa,B=da;for(let T=l.length-1;T>=0;T--){const E=l[T];a.inverse(E.worldMatrix);let c;n&&(p.copy(this.direction).scaleRotateMatrix4(a),c=n*p.len()),f.copy(this.origin).applyMatrix4(a),p.copy(this.direction).transformDirection(a);let u=0,m,w,_;const L=E.geometry,z=L.attributes,N=z.index,$=z.position,k=Math.max(0,L.drawRange.start),J=Math.min(N?N.count:$.count,L.drawRange.start+L.drawRange.count),Y=$.size;for(let D=k;D<J;D+=3){const X=N?N.data[D]:D,V=N?N.data[D+1]:D+1,q=N?N.data[D+2]:D+2;g.fromArray($.data,X*Y),h.fromArray($.data,V*Y),v.fromArray($.data,q*Y);const ae=this.intersectTriangle(g,h,v,r,f,p,d);ae&&(n&&ae>c||(!u||ae<u)&&(u=ae,m=X,w=V,_=q,M.copy(d)))}u||l.splice(T,1),E.hit.localPoint.copy(p).multiply(u).add(f),E.hit.point.copy(E.hit.localPoint).applyMatrix4(E.worldMatrix),E.hit.distance=E.hit.point.distance(this.origin),E.hit.faceNormal||(E.hit.localFaceNormal=new Ee,E.hit.faceNormal=new Ee,E.hit.uv=new yr,E.hit.localNormal=new Ee,E.hit.normal=new Ee),E.hit.localFaceNormal.copy(M),E.hit.faceNormal.copy(E.hit.localFaceNormal).transformDirection(E.worldMatrix),(s||i)&&(g.fromArray($.data,m*3),h.fromArray($.data,w*3),v.fromArray($.data,_*3),this.getBarycoord(E.hit.localPoint,g,h,v,y)),s&&z.uv&&(x.fromArray(z.uv.data,m*2),P.fromArray(z.uv.data,w*2),B.fromArray(z.uv.data,_*2),E.hit.uv.set(x.x*y.x+P.x*y.y+B.x*y.z,x.y*y.x+P.y*y.y+B.y*y.z)),i&&z.normal&&(g.fromArray(z.normal.data,m*3),h.fromArray(z.normal.data,w*3),v.fromArray(z.normal.data,_*3),E.hit.localNormal.set(g.x*y.x+h.x*y.y+v.x*y.z,g.y*y.x+h.y*y.y+v.y*y.z,g.z*y.x+h.z*y.y+v.z*y.z),E.hit.normal.copy(E.hit.localNormal).transformDirection(E.worldMatrix))}return l.sort((T,E)=>T.hit.distance-E.hit.distance),l}intersectPlane(e,r=this.origin,n=this.direction){const s=en;s.sub(e.origin,r);const i=s.dot(e.normal),o=n.dot(e.normal);if(o==0)return 0;const l=i/o;return l<=0?0:r.add(n.scale(l))}intersectSphere(e,r=this.origin,n=this.direction){const s=Zn;s.sub(e.center,r);const i=s.dot(n),o=s.dot(s)-i*i,l=e.radius*e.radius;if(o>l)return 0;const a=Math.sqrt(l-o),f=i-a,p=i+a;return f<0&&p<0?0:f<0?p:f}intersectBox(e,r=this.origin,n=this.direction){let s,i,o,l,a,f;const p=1/n.x,g=1/n.y,h=1/n.z,v=e.min,M=e.max;return s=((p>=0?v.x:M.x)-r.x)*p,i=((p>=0?M.x:v.x)-r.x)*p,o=((g>=0?v.y:M.y)-r.y)*g,l=((g>=0?M.y:v.y)-r.y)*g,s>l||o>i||(o>s&&(s=o),l<i&&(i=l),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,o=this.direction,l=Jn){const a=tn,f=es,p=ts;a.sub(r,e),f.sub(n,e),l.cross(a,f);let g=o.dot(l);if(!g)return 0;let h;if(g>0){if(s)return 0;h=1}else h=-1,g=-g;p.sub(i,e);let v=h*o.dot(f.cross(p,f));if(v<0)return 0;let M=h*o.dot(a.cross(p));if(M<0||v+M>g)return 0;let d=-h*p.dot(l);return d<0?0:d/g}getBarycoord(e,r,n,s,i=tn){const o=es,l=ts,a=va;o.sub(s,r),l.sub(n,r),a.sub(e,r);const f=o.dot(o),p=o.dot(l),g=o.dot(a),h=l.dot(l),v=l.dot(a),M=f*h-p*p;if(M===0)return i.set(-2,-1,-1);const d=1/M,y=(h*g-p*v)*d,x=(f*v-p*g)*d;return i.set(1-y-x,x,y)}}const xa=`
|
|
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
|
+
`,wa=`
|
|
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 Ma(t){return new Ue(t,{vertex:xa,fragment:wa,cullFace:!1})}const ns=new Ee,ba=new Ee,Aa=new Ee,Sa=new Ee,ss=new tr,_a=new tr,Ea=new tr,Ca=new tr;class Fa{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:o,interpolation:l,times:a,values:f})=>{if(!this.duration){let P=ns,B=3;o==="quaternion"&&(P=ss,B=4),P.fromArray(f,0),B===4?i[o].slerp(P,n):i[o].lerp(P,n);return}const p=Math.max(1,a.findIndex(P=>P>s))-1,g=p+1;let h=(s-a[p])/(a[g]-a[p]);l==="STEP"&&(h=0);let v=ns,M=ba,d=Aa,y=Sa,x=3;o==="quaternion"&&(v=ss,M=_a,d=Ea,y=Ca,x=4),l==="CUBICSPLINE"?(v.fromArray(f,p*x*3+x*1),M.fromArray(f,p*x*3+x*2),d.fromArray(f,g*x*3+x*0),y.fromArray(f,g*x*3+x*1),v=this.cubicSplineInterpolate(h,v,M,d,y),x===4&&v.normalize()):(v.fromArray(f,p*x),y.fromArray(f,g*x),x===4?v.slerp(y,h):v.lerp(y,h)),x===4?i[o].slerp(v,n):i[o].lerp(v,n)})}cubicSplineInterpolate(e,r,n,s,i){const o=e*e,l=o*e,a=3*o-2*l,f=l-o,p=1-a,g=f-o+e;for(let h=0;h<r.length;h++)r[h]=p*r[h]+g*(1-e)*n[h]+a*i[h]+f*e*s[h];return r}}const is=new Mt,Ta=new Mt;class Et extends et{constructor(e,{skeleton:r,geometry:n,program:s,mode:i=e.TRIANGLES}={}){super(e,{geometry:n,program:s,mode:i}),this.skeleton=r,this.program=s,this.createBoneTexture()}createBoneTexture(){if(!this.skeleton.joints.length)return;const e=Math.max(4,Math.pow(2,Math.ceil(Math.log(Math.sqrt(this.skeleton.joints.length*4))/Math.LN2)));this.boneMatrices=new Float32Array(e*e*4),this.boneTextureSize=e,this.boneTexture=new qe(this.gl,{image:this.boneMatrices,generateMipmaps:!1,type:this.gl.FLOAT,internalFormat:this.gl.renderer.isWebgl2?this.gl.RGBA32F:this.gl.RGBA,minFilter:this.gl.NEAREST,magFilter:this.gl.NEAREST,flipY:!1,width:e})}updateUniforms(){this.skeleton.joints.forEach((e,r)=>{is.multiply(e.worldMatrix,e.bindInverse),this.boneMatrices.set(is,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=Ta,super.draw({camera:e}),this.worldMatrix=r}}class Pa extends et{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 mt;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 ca().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 os={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array,"image/jpeg":Uint8Array,"image/png":Uint8Array,"image/webp":Uint8Array},Ra={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},as={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv2",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},Ba={translation:"position",rotation:"quaternion",scale:"scale"};class ls{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,P;(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()"),(P=r.extensionsRequired)!=null&&P.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),o=await this.parseImages(e,r,n,i),l=this.parseTextures(e,r,o),a=this.parseMaterials(e,r,l),f=this.parseSkins(e,r,i),p=await this.parseMeshes(e,r,i,a,f),[g,h]=this.parseNodes(e,r,p,f,o);this.populateSkins(f,g);const v=this.parseAnimations(e,r,g,i),M=this.parseScenes(r,g),d=M[r.scene],y=this.parseLights(e,r,g,M);for(let B=g.length;B>=0;B--)g[B]||g.splice(B,1);return{json:r,buffers:s,bufferViews:i,cameras:h,images:o,textures:l,materials:a,meshes:p,nodes:g,lights:y,animations:v,scenes:M,scene:d}}static parseDesc(e){return fetch(e,{mode:"cors"}).then(r=>r.arrayBuffer()).then(r=>{const n=new TextDecoder;return n.decode(new Uint8Array(r,0,4))==="glTF"?this.unpackGLB(r):JSON.parse(n.decode(r))})}static unpackGLB(e){const r=new Uint32Array(e,0,3);if(r[0]!==1179937895)throw new Error("Invalid glTF asset.");if(r[1]!==2)throw new Error(`Unsupported glTF binary version, "${r[1]}".`);const n=new Uint32Array(e,12,2),s=20,i=n[0];if(n[1]!==1313821514)throw new Error("Unexpected GLB layout.");const o=new TextDecoder().decode(e.slice(s,s+i)),l=JSON.parse(o);if(s+i===e.byteLength)return l;const a=new Uint32Array(e,s+i,2);if(a[1]!==5130562)throw new Error("Unexpected GLB layout.");const f=s+i+8,p=a[0],g=e.slice(f,f+p);return l.buffers[0].binary=g,l}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:o,indices:l,extensions:a})=>{for(const f in o){const p=r.accessors[o[f]];p.bufferView===void 0&&a&&a.KHR_draco_mesh_compression&&(p.bufferView=a.KHR_draco_mesh_compression.bufferView,s[p.bufferView].isDraco=!0),s[p.bufferView].isAttribute=!0}if(l!==void 0){const f=r.accessors[l];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:o})=>{i!==void 0&&(s[i].componentType=o)}),r.images&&r.images.forEach(({uri:i,bufferView:o,mimeType:l})=>{o!==void 0&&(s[o].mimeType=l)}),s.forEach(({buffer:i,byteOffset:o=0,byteLength:l,byteStride:a,target:f=e.ARRAY_BUFFER,name:p,extensions:g,extras:h,componentType:v,mimeType:M,isAttribute:d,isDraco:y},x)=>{if(s[x].data=n[i].slice(o,o+l),!d||y)return;const P=e.createBuffer();e.bindBuffer(f,P),e.renderer.state.boundBuffer=P,e.bufferData(f,s[x].data,e.STATIC_DRAW),s[x].buffer=P}),s}static parseImages(e,r,n,s){return r.images?Promise.all(r.images.map(async({uri:i,bufferView:o,mimeType:l,name:a})=>{if(l==="image/ktx2"){const{data:p}=s[o];return await this.basisManager.parseTexture(p)}const f=new Image;if(f.name=a,i)f.src=this.resolveURI(i,n);else if(o!==void 0){const{data:p}=s[o],g=new Blob([p],{type:l});f.src=URL.createObjectURL(g)}return f.ready=new Promise(p=>{f.onload=()=>p()}),f})):null}static parseTextures(e,r,n){return r.textures?r.textures.map(s=>this.createTexture(e,r,n,s)):null}static createTexture(e,r,n,{sampler:s,source:i,name:o,extensions:l,extras:a}){i===void 0&&l&&(l.EXT_texture_webp&&(i=l.EXT_texture_webp.source),l.KHR_texture_basisu&&(i=l.KHR_texture_basisu.source));const f=n[i];if(f.texture)return f.texture;const p={flipY:!1,wrapS:e.REPEAT,wrapT:e.REPEAT},g=s!==void 0?r.samplers[s]:null;if(g&&["magFilter","minFilter","wrapS","wrapT"].forEach(v=>{g[v]&&(p[v]=g[v])}),f.isBasis){p.image=f,p.internalFormat=f.internalFormat,f.isCompressedTexture&&(p.generateMipmaps=!1,f.length>1&&(this.minFilter=e.NEAREST_MIPMAP_LINEAR));const v=new qe(e,p);return v.name=o,f.texture=v,v}const h=new qe(e,p);return h.name=o,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:o,pbrMetallicRoughness:l={},normalTexture:a,occlusionTexture:f,emissiveTexture:p,emissiveFactor:g=[0,0,0],alphaMode:h="OPAQUE",alphaCutoff:v=.5,doubleSided:M=!1})=>{const{baseColorFactor:d=[1,1,1,1],baseColorTexture:y,metallicFactor:x=1,roughnessFactor:P=1,metallicRoughnessTexture:B}=l;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]),p&&(p.texture=n[p.index]),{name:s,extensions:i,extras:o,baseColorFactor:d,baseColorTexture:y,metallicFactor:x,roughnessFactor:P,metallicRoughnessTexture:B,normalTexture:a,occlusionTexture:f,emissiveTexture:p,emissiveFactor:g,alphaMode:h,alphaCutoff:v,doubleSided:M}}):null}static parseSkins(e,r,n){return r.skins?r.skins.map(({inverseBindMatrices:s,skeleton:i,joints:o})=>({inverseBindMatrices:this.parseAccessor(s,r,n),skeleton:i,joints:o})):null}static parseMeshes(e,r,n,s,i){return r.meshes?Promise.all(r.meshes.map(async({primitives:o,weights:l,name:a,extensions:f,extras:p={}},g)=>{let h=0,v=[],M=!1;return r.nodes&&r.nodes.forEach(({mesh:y,skin:x,extras:P})=>{y===g&&(h++,x!==void 0&&v.push(x),P&&P.lightmap_scale_offset&&(M=!0))}),!!v.length?(o=await Promise.all(v.map(async y=>(await this.parsePrimitives(e,o,r,n,s,1,M)).map(({geometry:x,program:P,mode:B})=>{const T=new Et(e,{skeleton:i[y],geometry:x,program:P,mode:B});return T.name=a,T.extras=p,f&&(T.extensions=f),T.frustumCulled=!1,T}))),o.instanceCount=0,o.numInstances=h):o=(await this.parsePrimitives(e,o,r,n,s,h,M)).map(({geometry:y,program:x,mode:P})=>{const B=y.attributes.instanceMatrix?Pa:et,T=new B(e,{geometry:y,program:x,mode:P});return T.name=a,T.extras=p,f&&(T.extensions=f),T.numInstances=h,T}),{primitives:o,weights:l,name:a}})):null}static parsePrimitives(e,r,n,s,i,o,l){return Promise.all(r.map(async({attributes:a,indices:f,material:p,mode:g=4,targets:h,extensions:v,extras:M})=>{const d=new Ma(e);p!==void 0&&(d.gltfMaterial=i[p]);const y=new ht(e);if(M&&(y.extras=M),v&&(y.extensions=v),v&&v.KHR_draco_mesh_compression){const x=v.KHR_draco_mesh_compression.bufferView,P=v.KHR_draco_mesh_compression.attributes,B={},T={},E={},c={};for(const w in a){const _=n.accessors[a[w]],L=as[w];B[L]=P[w],T[L]=_.componentType,E[L]=os[_.componentType].name,c[L]=_.normalized===!0}const{data:u}=s[x],m=await this.dracoManager.decodeGeometry(u,{attributeIds:B,attributeTypes:E});for(let w=0;w<m.attributes.length;w++){const _=m.attributes[w],L=_.name,z=_.array,N=_.itemSize,$=T[L],k=c[L],J=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,J),e.renderer.state.boundBuffer=J,e.bufferData(e.ARRAY_BUFFER,z,e.STATIC_DRAW),y.addAttribute(L,{data:z,size:N,type:$,normalized:k,buffer:J})}if(m.index){const w=m.index.array,_=m.index.itemSize,L=e.createBuffer();e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,L),e.renderer.state.boundBuffer=L,e.bufferData(e.ELEMENT_ARRAY_BUFFER,w,e.STATIC_DRAW),y.addAttribute("index",{data:w,size:_,type:5125,normalized:!1,buffer:L})}}else{for(const x in a)y.addAttribute(as[x],this.parseAccessor(a[x],n,s));f!==void 0&&y.addAttribute("index",this.parseAccessor(f,n,s))}return o>1&&y.addAttribute("instanceMatrix",{instanced:1,size:16,data:new Float32Array(o*16)}),l&&y.addAttribute("lightmapScaleOffset",{instanced:1,size:4,data:new Float32Array(o*4)}),{geometry:y,program:d,mode:g}}))}static parseAccessor(e,r,n){const{bufferView:s,byteOffset:i=0,componentType:o,normalized:l=!1,count:a,type:f,min:p,max:g,sparse:h}=r.accessors[e],{data:v,buffer:M,byteOffset:d=0,byteStride:y=0,target:x}=n[s],P=Ra[f],B=os[o],T=B.BYTES_PER_ELEMENT,E=y/T,c=!!y&&E!==P;let u;if(c){const m=new B(v,i);u=new B(a*P);for(let w=0;w<a;w++){const _=E*w,L=_+P;u.set(m.slice(_,L),w*P)}}else u=new B(v,i,a*P);return{data:u,size:P,type:o,normalized:l,buffer:M,stride:y,offset:i,count:a,min:p,max:g}}static parseNodes(e,r,n,s,i){if(!r.nodes)return null;const o=[],l=r.nodes.map(({camera:a,children:f,skin:p,matrix:g,mesh:h,rotation:v,scale:M,translation:d,weights:y,name:x,extensions:P,extras:B})=>{const T=a!==void 0,E=T?new Mn(e):new mt;if(T){const _=r.cameras[a];if(_.type==="perspective"){const{yfov:L,znear:z,zfar:N}=_.perspective;E.perspective({fov:L*(180/Math.PI),near:z,far:N})}else{const{xmag:L,ymag:z,znear:N,zfar:$}=_.orthographic;E.orthographic({near:N,far:$,left:-L,right:L,top:-z,bottom:z})}o.push(E)}x&&(E.name=x),B&&(E.extras=B),P&&(E.extensions=P),B&&B.lightmapTexture!==void 0&&(B.lightmapTexture.texture=this.createTexture(e,r,i,{source:B.lightmapTexture.index})),g?(E.matrix.copy(g),E.decompose()):(v&&E.quaternion.copy(v),M&&E.scale.copy(M),d&&E.position.copy(d),E.updateMatrix());let c=!1,u=!0,m=!1;if(h!==void 0&&(p!==void 0?(n[h].primitives[n[h].primitives.instanceCount].forEach(_=>{B&&Object.assign(_.extras,B),_.setParent(E)}),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(_=>{B&&Object.assign(_.extras,B),_.geometry.isInstanced&&(c=!0,_.instanceCount?u=!1:_.instanceCount=0,_.geometry.attributes.instanceMatrix&&(m=!0,E.matrix.toArray(_.geometry.attributes.instanceMatrix.data,_.instanceCount*16)),_.geometry.attributes.lightmapScaleOffset&&_.geometry.attributes.lightmapScaleOffset.data.set(B.lightmap_scale_offset,_.instanceCount*4),_.instanceCount++,_.instanceCount===_.numInstances&&(delete _.numInstances,delete _.instanceCount,_.geometry.attributes.instanceMatrix&&(_.geometry.attributes.instanceMatrix.needsUpdate=!0),_.geometry.attributes.lightmapScaleOffset&&(_.geometry.attributes.lightmapScaleOffset.needsUpdate=!0))),c?u&&_.setParent(E):_.setParent(E)})),m){if(!u)return null;E.matrix.identity(),E.decompose()}return E});return r.nodes.forEach(({children:a=[]},f)=>{a.forEach(p=>{l[p]&&l[p].setParent(l[f])})}),n.forEach(({primitives:a},f)=>{a.forEach((p,g)=>{p.isInstancedMesh&&p.addFrustumCull()})}),[l,o]}static populateSkins(e,r){e&&e.forEach(n=>{n.joints=n.joints.map((s,i)=>{const o=r[s];return o.skin=n,o.bindInverse=new Mt(...n.inverseBindMatrices.data.slice(i*16,(i+1)*16)),o}),n.skeleton&&(n.skeleton=r[n.skeleton])})}static parseAnimations(e,r,n,s){return r.animations?r.animations.map(({channels:i,samplers:o,name:l},a)=>{const f=i.map(({sampler:p,target:g})=>{const{input:h,interpolation:v="LINEAR",output:M}=o[p],{node:d,path:y}=g,x=n[d],P=Ba[y],B=this.parseAccessor(h,r,s).data,T=this.parseAccessor(M,r,s).data;return x.animations||(x.animations=[]),x.animations.includes(a)||x.animations.push(a),{node:x,transform:P,interpolation:v,times:B,values:T}});return{name:l,animation:new Fa(f)}}):null}static parseScenes(e,r){return e.scenes?e.scenes.map(({nodes:n=[],name:s,extensions:i,extras:o})=>{const l=n.reduce((a,f)=>(r[f]&&a.push(r[f]),a),[]);return l.extras=o,l}):null}static parseLights(e,r,n,s){var l,a;const i={directional:[],point:[],spot:[]};s.forEach(f=>f.forEach(p=>p.updateMatrixWorld()));const o=((a=(l=r.extensions)==null?void 0:l.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 p=f.extensions.KHR_lights_punctual.light,g=o[p],h={name:g.name||"",color:{value:new Ee().set(g.color||1)}};switch(g.intensity!==void 0&&h.color.value.multiply(g.intensity),g.type){case"directional":h.direction={value:new Ee(0,0,1).transformDirection(f.worldMatrix)};break;case"point":h.position={value:new Ee().applyMatrix4(f.worldMatrix)},h.distance={value:g.range},h.decay={value:2};break;case"spot":Object.assign(h,g);break}i[g.type].push(h)}),i}}const La={fetch:yi,getBuffer:wi,getBlob:xi,putBuffer:Ai,putLocalBuffer:Si,hasLocalBuffer:bi,getLocalName:Mi,getPlayer:_i,removePlayers:vi},$e=()=>{const t=new Float32Array(16);return t[0]=t[5]=t[10]=t[15]=1,t},wt=(t,e,r)=>{for(let n=0;n<4;n++){const s=r[n*4],i=r[n*4+1],o=r[n*4+2],l=r[n*4+3];t[n*4]=e[0]*s+e[4]*i+e[8]*o+e[12]*l,t[n*4+1]=e[1]*s+e[5]*i+e[9]*o+e[13]*l,t[n*4+2]=e[2]*s+e[6]*i+e[10]*o+e[14]*l,t[n*4+3]=e[3]*s+e[7]*i+e[11]*o+e[15]*l}return t},Ft=t=>{const e=t[0],r=t[1],n=t[2],s=t[4],i=t[5],o=t[6],l=t[8],a=t[9],f=t[10],p=e*(i*f-o*a)-s*(r*f-n*a)+l*(r*o-n*i),g=p===0?0:1/p,h=new Float32Array(16);h[0]=(i*f-o*a)*g,h[1]=(n*a-r*f)*g,h[2]=(r*o-n*i)*g,h[4]=(o*l-s*f)*g,h[5]=(e*f-n*l)*g,h[6]=(n*s-e*o)*g,h[8]=(s*a-i*l)*g,h[9]=(r*l-e*a)*g,h[10]=(e*i-r*s)*g;const v=t[12],M=t[13],d=t[14];return h[12]=-(h[0]*v+h[4]*M+h[8]*d),h[13]=-(h[1]*v+h[5]*M+h[9]*d),h[14]=-(h[2]*v+h[6]*M+h[10]*d),h[15]=1,h},Pr=t=>[Math.hypot(t[0],t[1],t[2]),Math.hypot(t[4],t[5],t[6]),Math.hypot(t[8],t[9],t[10])],Zs=(t,e,r,n,s)=>{const[i,o,l]=Pr(t),a=Math.hypot(e,r,n,s)||1,f=e/a,p=r/a,g=n/a,h=s/a,v=f*f,M=f*p,d=f*g,y=f*h,x=p*p,P=p*g,B=p*h,T=g*g,E=g*h;t[0]=(1-2*(x+T))*i,t[1]=2*(M+E)*i,t[2]=2*(d-B)*i,t[4]=2*(M-E)*o,t[5]=(1-2*(v+T))*o,t[6]=2*(P+y)*o,t[8]=2*(d+B)*l,t[9]=2*(P-y)*l,t[10]=(1-2*(v+x))*l},er=Math.PI/180,Na=(t,e,r,n,s)=>{const[i,o,l]=Pr(t),a=e*er,f=r*er,p=n*er,g=Math.cos(a),h=Math.sin(a),v=Math.cos(f),M=Math.sin(f),d=Math.cos(p),y=Math.sin(p);let x=1,P=0,B=0,T=0,E=1,c=0,u=0,m=0,w=1;switch(s){case 0:x=v*d,P=-v*y,B=M,T=h*M*d+g*y,E=-h*M*y+g*d,c=-h*v,u=-g*M*d+h*y,m=g*M*y+h*d,w=g*v;break;case 1:x=v*d+M*h*y,P=-v*y+M*h*d,B=M*g,T=g*y,E=g*d,c=-h,u=-M*d+v*h*y,m=M*y+v*h*d,w=v*g;break;case 2:x=v*d-M*h*y,P=-g*y,B=M*d+v*h*y,T=v*y+M*h*d,E=g*d,c=M*y-v*h*d,u=-M*g,m=h,w=v*g;break;case 3:x=v*d,P=h*M*d-g*y,B=g*M*d+h*y,T=v*y,E=h*M*y+g*d,c=g*M*y-h*d,u=-M,m=h*v,w=g*v;break;case 4:x=v*d,P=-y,B=M*d,T=h*M+g*v*y,E=g*d,c=-v*h+g*M*y,u=-g*M+h*v*y,m=h*d,w=g*v+h*M*y;break;case 5:x=v*d,P=-v*y,B=M,T=g*y+h*M*d,E=g*d-h*M*y,c=-h*v,u=h*y-g*M*d,m=h*d+g*M*y,w=g*v;break}t[0]=x*i,t[1]=T*i,t[2]=u*i,t[4]=P*o,t[5]=E*o,t[6]=m*o,t[8]=B*l,t[9]=c*l,t[10]=w*l},Js=(t,e,r,n)=>{const[s,i,o]=Pr(t);if(s===0||i===0||o===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 l=e/s,a=r/i,f=n/o;t[0]*=l,t[1]*=l,t[2]*=l,t[4]*=a,t[5]*=a,t[6]*=a,t[8]*=f,t[9]*=f,t[10]*=f},cs=t=>{const[e,r,n]=Pr(t);if(e===0||r===0||n===0)return[0,0,0];const s=t[0]/e,i=t[1]/e,o=t[2]/e;t[4]/r;const l=t[5]/r,a=t[8]/n,f=t[9]/n,p=t[10]/n,g=Math.asin(-Math.min(1,Math.max(-1,f)));let h,v;return Math.abs(f)<.9999?(h=Math.atan2(a,p),v=Math.atan2(i,l)):(h=Math.atan2(-o,s),v=0),[g/er,h/er,v/er]},ei=(t,e,r)=>{const n=$e();return Zs(n,e[0],e[1],e[2],e[3]),Js(n,r[0],r[1],r[2]),n[12]=t[0],n[13]=t[1],n[14]=t[2],n},ti=(t,e,r,n)=>{const s=1/Math.tan(t*er/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},Oa=(t,e,r,n,s,i)=>{const o=new Float32Array(16);return o[0]=2/(e-t),o[5]=2/(n-r),o[10]=-2/(i-s),o[12]=-(e+t)/(e-t),o[13]=-(n+r)/(n-r),o[14]=-(i+s)/(i-s),o[15]=1,o},hs=(t,e,r,n)=>{let s=-1/0,i=1/0;for(let o=0;o<3;o++){if(n[o]===0)continue;const l=(t[o]-e[o]-r[o])/n[o],a=(t[o]+e[o]-r[o])/n[o];s=Math.max(s,Math.min(l,a)),i=Math.min(i,Math.max(l,a))}return s<0||i<s?-1:s},Ia=(t,e,r,n)=>{const s=r[0]-t[0],i=r[1]-t[1],o=r[2]-t[2],l=n[0]**2+n[1]**2+n[2]**2,a=2*(s*n[0]+i*n[1]+o*n[2]),f=s*s+i*i+o*o-e*e,p=a*a-4*l*f;if(p<0)return-1;const g=Math.sqrt(p),h=(-a-g)/(2*l),v=(-a+g)/(2*l);return h>0&&v>0?Math.min(h,v):h>0?h:v>0?v:-1},Ct=(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),Da=(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 o=0,l=1,a=0;Math.abs(n)>.999&&(o=0,l=0,a=-1);let f=n*a-s*l,p=s*o-r*a,g=r*l-n*o;const h=Math.hypot(f,p,g)||1;f/=h,p/=h,g/=h;const v=p*s-g*n,M=g*r-f*s,d=f*n-p*r,y=new Float32Array(16);return y[0]=f,y[4]=p,y[8]=g,y[1]=v,y[5]=M,y[9]=d,y[2]=-r,y[6]=-n,y[10]=-s,y[12]=-(f*t[0]+p*t[1]+g*t[2]),y[13]=-(v*t[0]+M*t[1]+d*t[2]),y[14]=r*t[0]+n*t[1]+s*t[2],y[15]=1,y},Ua=1/(1.2*Math.pow(2,Math.log2(256/(1/125)))),ri=`
|
|
36
|
+
vec3 acesFilmicSrgb(vec3 x) {
|
|
37
|
+
const float A = 2.51; const float B = 0.03; const float C = 2.43; const float D = 0.59; const float E = 0.14;
|
|
38
|
+
vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
|
|
39
|
+
return pow(t, vec3(1.0 / 2.2));
|
|
40
|
+
}
|
|
41
|
+
`,xr=`
|
|
42
|
+
uniform float uTonemap;
|
|
43
|
+
${ri}
|
|
44
|
+
vec3 tonemap(vec3 x) {
|
|
45
|
+
if (uTonemap < 0.5) return x;
|
|
46
|
+
return acesFilmicSrgb(x);
|
|
47
|
+
}
|
|
48
|
+
`,ni=`
|
|
49
|
+
vec3 Inverse_Tonemap_Filmic(const vec3 x) {
|
|
50
|
+
return (0.03 - 0.59 * x - sqrt(0.0009 + 1.3702 * x - 1.0127 * x * x)) / (-5.02 + 4.86 * x);
|
|
51
|
+
}
|
|
52
|
+
vec3 inverseTonemapSRGB(vec3 color) {
|
|
53
|
+
color = clamp(color, 0.0, 1.0);
|
|
54
|
+
return Inverse_Tonemap_Filmic(pow(color, vec3(2.2)));
|
|
55
|
+
}
|
|
56
|
+
`,za=`#version 300 es
|
|
57
|
+
precision highp float;
|
|
58
|
+
in vec3 position;
|
|
59
|
+
in vec3 normal;
|
|
60
|
+
in vec2 uv;
|
|
61
|
+
uniform mat4 modelMatrix;
|
|
62
|
+
uniform mat4 modelViewMatrix;
|
|
63
|
+
uniform mat4 projectionMatrix;
|
|
64
|
+
uniform mat3 normalMatrix;
|
|
65
|
+
out vec3 vWorldPos;
|
|
66
|
+
out vec3 vNormal;
|
|
67
|
+
out vec2 vUv;
|
|
68
|
+
`,si=`
|
|
69
|
+
in vec4 skinIndex;
|
|
70
|
+
in vec4 skinWeight;
|
|
71
|
+
uniform sampler2D boneTexture;
|
|
72
|
+
uniform int boneTextureSize;
|
|
73
|
+
|
|
74
|
+
mat4 getBoneMatrix(const in float i) {
|
|
75
|
+
float j = i * 4.0;
|
|
76
|
+
float x = mod(j, float(boneTextureSize));
|
|
77
|
+
float y = floor(j / float(boneTextureSize));
|
|
78
|
+
float dx = 1.0 / float(boneTextureSize);
|
|
79
|
+
float dy = 1.0 / float(boneTextureSize);
|
|
80
|
+
y = dy * (y + 0.5);
|
|
81
|
+
vec4 v1 = texture(boneTexture, vec2(dx * (x + 0.5), y));
|
|
82
|
+
vec4 v2 = texture(boneTexture, vec2(dx * (x + 1.5), y));
|
|
83
|
+
vec4 v3 = texture(boneTexture, vec2(dx * (x + 2.5), y));
|
|
84
|
+
vec4 v4 = texture(boneTexture, vec2(dx * (x + 3.5), y));
|
|
85
|
+
return mat4(v1, v2, v3, v4);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
mat4 getSkinMatrix() {
|
|
89
|
+
mat4 boneMatX = getBoneMatrix(skinIndex.x);
|
|
90
|
+
mat4 boneMatY = getBoneMatrix(skinIndex.y);
|
|
91
|
+
mat4 boneMatZ = getBoneMatrix(skinIndex.z);
|
|
92
|
+
mat4 boneMatW = getBoneMatrix(skinIndex.w);
|
|
93
|
+
return boneMatX * skinWeight.x + boneMatY * skinWeight.y + boneMatZ * skinWeight.z + boneMatW * skinWeight.w;
|
|
94
|
+
}
|
|
95
|
+
`,Ga=`
|
|
96
|
+
uniform sampler2D uMorphTex;
|
|
97
|
+
uniform int uMorphCount; // active target count (capped by glb.ts)
|
|
98
|
+
uniform int uMorphVertexCount;
|
|
99
|
+
uniform int uMorphTexWidth;
|
|
100
|
+
uniform float uMorphWeights[8];
|
|
101
|
+
|
|
102
|
+
vec3 morphFetch(int idx) {
|
|
103
|
+
return texelFetch(uMorphTex, ivec2(idx % uMorphTexWidth, idx / uMorphTexWidth), 0).rgb;
|
|
104
|
+
}
|
|
105
|
+
`,ii=t=>`${za}
|
|
106
|
+
#ifdef INSTANCED
|
|
107
|
+
in mat4 instanceMatrix;
|
|
108
|
+
uniform mat4 viewMatrix;
|
|
109
|
+
#endif
|
|
110
|
+
${t.includes("HAS_SKIN")?si:""}
|
|
111
|
+
${t.includes("HAS_MORPH")?Ga:""}
|
|
112
|
+
${t.includes("HAS_COLOR")?`in vec4 color;
|
|
113
|
+
out vec4 vColor;`:""}
|
|
114
|
+
uniform mat4 shadowMatrix;
|
|
115
|
+
out vec4 vShadowCoord;
|
|
116
|
+
|
|
117
|
+
void main() {
|
|
118
|
+
vec4 pos = vec4(position, 1.0);
|
|
119
|
+
vec3 nrm = normal;
|
|
120
|
+
${t.includes("HAS_MORPH")?`
|
|
121
|
+
for (int t = 0; t < uMorphCount; t++) {
|
|
122
|
+
if (uMorphWeights[t] != 0.0) {
|
|
123
|
+
pos.xyz += uMorphWeights[t] * morphFetch(t * uMorphVertexCount + gl_VertexID);
|
|
124
|
+
${t.includes("HAS_MORPH_NORMALS")?"nrm += uMorphWeights[t] * morphFetch((uMorphCount + t) * uMorphVertexCount + gl_VertexID);":""}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
`:""}
|
|
128
|
+
${t.includes("HAS_SKIN")?`
|
|
129
|
+
mat4 skinMatrix = getSkinMatrix();
|
|
130
|
+
pos = skinMatrix * pos;
|
|
131
|
+
nrm = mat3(skinMatrix) * nrm;
|
|
132
|
+
`:""}
|
|
133
|
+
${t.includes("HAS_COLOR")?"vColor = color;":""}
|
|
134
|
+
#ifdef INSTANCED
|
|
135
|
+
mat4 model = instanceMatrix;
|
|
136
|
+
#else
|
|
137
|
+
mat4 model = modelMatrix;
|
|
138
|
+
#endif
|
|
139
|
+
vec4 worldPos = model * pos;
|
|
140
|
+
vWorldPos = worldPos.xyz;
|
|
141
|
+
vNormal = normalize(mat3(model) * nrm);
|
|
142
|
+
vUv = uv;
|
|
143
|
+
vShadowCoord = shadowMatrix * worldPos;
|
|
144
|
+
#ifdef INSTANCED
|
|
145
|
+
gl_Position = projectionMatrix * viewMatrix * worldPos;
|
|
146
|
+
#else
|
|
147
|
+
gl_Position = projectionMatrix * modelViewMatrix * pos;
|
|
148
|
+
#endif
|
|
149
|
+
}
|
|
150
|
+
`,Jt=8,Rr=`
|
|
151
|
+
#define MAX_PUNCTUAL ${Jt}
|
|
152
|
+
uniform int punctualCount;
|
|
153
|
+
uniform vec4 punctualPos[MAX_PUNCTUAL]; // xyz = world position, w = 1 / range²
|
|
154
|
+
uniform vec4 punctualColor[MAX_PUNCTUAL]; // rgb = linear colour x candela, w = cone scale (0 = a point light)
|
|
155
|
+
uniform vec4 punctualDir[MAX_PUNCTUAL]; // xyz = where the light travels (unit), w = cone offset (1 = a point light)
|
|
156
|
+
uniform vec3 sunDirection;
|
|
157
|
+
uniform vec4 sunColorIntensity; // rgb = linear color, a = intensity (lux)
|
|
158
|
+
uniform float iblLuminance;
|
|
159
|
+
uniform vec3 iblSH[9];
|
|
160
|
+
uniform samplerCube envMap;
|
|
161
|
+
uniform float envMapMaxLod;
|
|
162
|
+
uniform sampler2D shadowMap;
|
|
163
|
+
uniform float shadowEnabled;
|
|
164
|
+
uniform float shadowMapSize;
|
|
165
|
+
uniform float exposure;
|
|
166
|
+
in vec4 vShadowCoord;
|
|
167
|
+
|
|
168
|
+
#define PI 3.14159265359
|
|
169
|
+
|
|
170
|
+
float D_GGX(float NoH, float a) {
|
|
171
|
+
float a2 = a * a;
|
|
172
|
+
float f = (NoH * a2 - NoH) * NoH + 1.0;
|
|
173
|
+
return a2 / (PI * f * f);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
float V_SmithGGXCorrelated(float NoV, float NoL, float a) {
|
|
177
|
+
float a2 = a * a;
|
|
178
|
+
float GGXL = NoV * sqrt((-NoL * a2 + NoL) * NoL + a2);
|
|
179
|
+
float GGXV = NoL * sqrt((-NoV * a2 + NoV) * NoV + a2);
|
|
180
|
+
return 0.5 / (GGXV + GGXL + 1e-5);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
vec3 F_Schlick(float u, vec3 f0) {
|
|
184
|
+
float f = pow(1.0 - u, 5.0);
|
|
185
|
+
return f0 + (vec3(1.0) - f0) * f;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
vec3 evalSH(vec3 n) {
|
|
189
|
+
return max(
|
|
190
|
+
iblSH[0]
|
|
191
|
+
+ iblSH[1] * n.y
|
|
192
|
+
+ iblSH[2] * n.z
|
|
193
|
+
+ iblSH[3] * n.x
|
|
194
|
+
+ iblSH[4] * (n.y * n.x)
|
|
195
|
+
+ iblSH[5] * (n.y * n.z)
|
|
196
|
+
+ iblSH[6] * (3.0 * n.z * n.z - 1.0)
|
|
197
|
+
+ iblSH[7] * (n.z * n.x)
|
|
198
|
+
+ iblSH[8] * (n.x * n.x - n.y * n.y)
|
|
199
|
+
, vec3(0.0));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
float sampleShadowPCF() {
|
|
203
|
+
if (shadowEnabled < 0.5) return 1.0;
|
|
204
|
+
vec3 coord = vShadowCoord.xyz / vShadowCoord.w;
|
|
205
|
+
coord = coord * 0.5 + 0.5;
|
|
206
|
+
if (coord.x < 0.0 || coord.x > 1.0 || coord.y < 0.0 || coord.y > 1.0 || coord.z > 1.0) return 1.0;
|
|
207
|
+
float bias = 0.0018;
|
|
208
|
+
float texel = 1.0 / shadowMapSize;
|
|
209
|
+
float sum = 0.0;
|
|
210
|
+
for (int x = -1; x <= 1; x++) {
|
|
211
|
+
for (int y = -1; y <= 1; y++) {
|
|
212
|
+
float depth = texture(shadowMap, coord.xy + vec2(float(x), float(y)) * texel).r;
|
|
213
|
+
sum += (coord.z - bias) > depth ? 0.0 : 1.0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return sum / 9.0;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Lambert diffuse + the GGX specular lobe for one light direction l (unit, TO the light).
|
|
220
|
+
vec3 surfaceBRDF(vec3 n, vec3 v, vec3 l, float NoV, float NoL, float a, vec3 diffuseColor, vec3 f0) {
|
|
221
|
+
vec3 h = normalize(v + l);
|
|
222
|
+
float NoH = clamp(dot(n, h), 0.0, 1.0);
|
|
223
|
+
float LoH = clamp(dot(l, h), 0.0, 1.0);
|
|
224
|
+
vec3 Fr = D_GGX(NoH, a) * V_SmithGGXCorrelated(NoV, NoL, a) * F_Schlick(LoH, f0);
|
|
225
|
+
return diffuseColor * (1.0 / PI) + Fr;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// diffuseColor: linear albedo (already metallic-adjusted); f0: specular reflectance at normal.
|
|
229
|
+
vec3 shadePBR(vec3 n, vec3 v, vec3 diffuseColor, vec3 f0, float perceptualRoughness, float occlusion) {
|
|
230
|
+
float roughness = clamp(perceptualRoughness, 0.045, 1.0);
|
|
231
|
+
float a = roughness * roughness;
|
|
232
|
+
float NoV = abs(dot(n, v)) + 1e-5;
|
|
233
|
+
|
|
234
|
+
vec3 color = vec3(0.0);
|
|
235
|
+
|
|
236
|
+
// --- sun ---
|
|
237
|
+
if (sunColorIntensity.a > 0.0) {
|
|
238
|
+
vec3 l = normalize(-sunDirection);
|
|
239
|
+
float NoL = clamp(dot(n, l), 0.0, 1.0);
|
|
240
|
+
if (NoL > 0.0) {
|
|
241
|
+
float shadow = sampleShadowPCF();
|
|
242
|
+
// "illuminance" model: lux * NoL, pre-exposed
|
|
243
|
+
color += surfaceBRDF(n, v, l, NoV, NoL, a, diffuseColor, f0) * sunColorIntensity.rgb * (sunColorIntensity.a * exposure * NoL * shadow);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// --- point + spot lights ---
|
|
248
|
+
for (int i = 0; i < MAX_PUNCTUAL; i++) {
|
|
249
|
+
if (i >= punctualCount) break;
|
|
250
|
+
vec3 toLight = punctualPos[i].xyz - vWorldPos;
|
|
251
|
+
float d2 = dot(toLight, toLight);
|
|
252
|
+
float f = d2 * punctualPos[i].w;
|
|
253
|
+
float win = clamp(1.0 - f * f, 0.0, 1.0);
|
|
254
|
+
vec3 l = toLight * inversesqrt(max(d2, 1e-8));
|
|
255
|
+
float cone = clamp(dot(-punctualDir[i].xyz, l) * punctualColor[i].w + punctualDir[i].w, 0.0, 1.0);
|
|
256
|
+
// a punctual light occupies a volume of 1 cm (filament): no division by 0 on its own surface
|
|
257
|
+
float attenuation = win * win * cone * cone / max(d2, 1e-4);
|
|
258
|
+
float NoL = clamp(dot(n, l), 0.0, 1.0);
|
|
259
|
+
if (attenuation <= 0.0 || NoL <= 0.0) continue;
|
|
260
|
+
color += surfaceBRDF(n, v, l, NoV, NoL, a, diffuseColor, f0) * punctualColor[i].rgb * (attenuation * exposure * NoL);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// --- IBL ---
|
|
264
|
+
if (iblLuminance > 0.0) {
|
|
265
|
+
// cmgen's SH coefficients are pre-convolved irradiance — no extra 1/PI (matches Filament).
|
|
266
|
+
vec3 irradiance = evalSH(n);
|
|
267
|
+
vec3 Fd = diffuseColor * irradiance;
|
|
268
|
+
|
|
269
|
+
vec3 r = reflect(-v, n);
|
|
270
|
+
float lod = roughness * envMapMaxLod;
|
|
271
|
+
vec3 prefiltered = textureLod(envMap, r, lod).rgb;
|
|
272
|
+
// Simple DFG approximation (Karis): avoids a DFG LUT.
|
|
273
|
+
vec3 specular = prefiltered * (f0 * (1.0 - roughness) + roughness * 0.25 * f0 + 0.05 * (1.0 - roughness));
|
|
274
|
+
color += (Fd + specular) * (iblLuminance * exposure * occlusion);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return color;
|
|
278
|
+
}
|
|
279
|
+
${xr}`,Va=`#version 300 es
|
|
280
|
+
precision highp float;
|
|
281
|
+
in vec3 vWorldPos;
|
|
282
|
+
in vec3 vNormal;
|
|
283
|
+
in vec2 vUv;
|
|
284
|
+
uniform vec3 cameraPosition;
|
|
285
|
+
uniform vec3 baseColor; // linear factor over baseColorMap (both default white)
|
|
286
|
+
uniform sampler2D baseColorMap;
|
|
287
|
+
uniform float roughness;
|
|
288
|
+
uniform float metallic;
|
|
289
|
+
${Rr}
|
|
290
|
+
out vec4 fragColor;
|
|
291
|
+
|
|
292
|
+
void main() {
|
|
293
|
+
vec3 albedo = baseColor * texture(baseColorMap, vUv).rgb;
|
|
294
|
+
vec3 n = normalize(vNormal);
|
|
295
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
296
|
+
if (dot(n, v) < 0.0) n = -n;
|
|
297
|
+
vec3 diffuseColor = albedo * (1.0 - metallic);
|
|
298
|
+
vec3 f0 = mix(vec3(0.04), albedo, metallic);
|
|
299
|
+
vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, 1.0);
|
|
300
|
+
fragColor = vec4(tonemap(color), 1.0);
|
|
301
|
+
}
|
|
302
|
+
`,Ha=`#version 300 es
|
|
303
|
+
precision highp float;
|
|
304
|
+
in vec3 vWorldPos;
|
|
305
|
+
in vec3 vNormal;
|
|
306
|
+
in vec2 vUv;
|
|
307
|
+
uniform vec3 cameraPosition;
|
|
308
|
+
uniform sampler2D control;
|
|
309
|
+
uniform sampler2D albedo0;
|
|
310
|
+
uniform sampler2D albedo1;
|
|
311
|
+
uniform sampler2D albedo2;
|
|
312
|
+
uniform sampler2D albedo3;
|
|
313
|
+
uniform sampler2D normals01;
|
|
314
|
+
uniform sampler2D normals23;
|
|
315
|
+
uniform vec4 tiling;
|
|
316
|
+
uniform vec4 roughness;
|
|
317
|
+
uniform vec4 normalScale;
|
|
318
|
+
uniform vec4 triplanar;
|
|
319
|
+
uniform vec2 gridSize;
|
|
320
|
+
uniform float cellSize;
|
|
321
|
+
uniform vec3 tint;
|
|
322
|
+
${Rr}
|
|
323
|
+
out vec4 fragColor;
|
|
324
|
+
|
|
325
|
+
vec4 triplanarSample(sampler2D tex, vec3 p, vec3 bw, float s) {
|
|
326
|
+
return texture(tex, p.zy / s) * bw.x + texture(tex, p.xz / s) * bw.y + texture(tex, p.xy / s) * bw.z;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
void splatLayer(sampler2D alb, sampler2D pack, float slot, float tl, float nscale, float tri, float w,
|
|
330
|
+
vec2 uv, vec3 wp, vec3 bw, inout vec3 albedo, inout vec3 nrm) {
|
|
331
|
+
if (w <= 0.0) return;
|
|
332
|
+
float s = max(tl, 1e-3);
|
|
333
|
+
if (tri > 0.5) {
|
|
334
|
+
albedo += triplanarSample(alb, wp, bw, s).rgb * w;
|
|
335
|
+
nrm += vec3(0.0, 0.0, 1.0) * w;
|
|
336
|
+
} else {
|
|
337
|
+
vec2 luv = uv / s;
|
|
338
|
+
albedo += texture(alb, luv).rgb * w;
|
|
339
|
+
if (nscale > 0.0) {
|
|
340
|
+
vec4 p = texture(pack, luv);
|
|
341
|
+
vec2 xy = (slot > 0.5 ? p.ba : p.rg) * 2.0 - 1.0;
|
|
342
|
+
xy *= nscale;
|
|
343
|
+
nrm += vec3(xy, sqrt(max(1.0 - dot(xy, xy), 0.0))) * w;
|
|
344
|
+
} else {
|
|
345
|
+
nrm += vec3(0.0, 0.0, 1.0) * w;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
|
|
351
|
+
vec3 pos_dx = dFdx(vWorldPos);
|
|
352
|
+
vec3 pos_dy = dFdy(vWorldPos);
|
|
353
|
+
vec2 tex_dx = dFdx(vUv);
|
|
354
|
+
vec2 tex_dy = dFdy(vUv);
|
|
355
|
+
float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
|
|
356
|
+
if (abs(det) < 1e-8) return ng;
|
|
357
|
+
vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
|
|
358
|
+
t = normalize(t - ng * dot(ng, t));
|
|
359
|
+
vec3 b = normalize(cross(ng, t)) * sign(det);
|
|
360
|
+
return normalize(mat3(t, b, ng) * nTangent);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
void main() {
|
|
364
|
+
vec2 cuv = (vUv / max(cellSize, 1e-4) + 0.5) / max(gridSize, vec2(1.0));
|
|
365
|
+
vec4 w = texture(control, cuv);
|
|
366
|
+
float ws = w.r + w.g + w.b + w.a;
|
|
367
|
+
w = ws > 1e-4 ? w / ws : vec4(1.0, 0.0, 0.0, 0.0);
|
|
368
|
+
vec3 ng = normalize(vNormal);
|
|
369
|
+
vec3 bw = abs(ng);
|
|
370
|
+
bw = bw / max(bw.x + bw.y + bw.z, 1e-4);
|
|
371
|
+
vec3 albedo = vec3(0.0);
|
|
372
|
+
vec3 nrm = vec3(0.0);
|
|
373
|
+
splatLayer(albedo0, normals01, 0.0, tiling.x, normalScale.x, triplanar.x, w.r, vUv, vWorldPos, bw, albedo, nrm);
|
|
374
|
+
splatLayer(albedo1, normals01, 1.0, tiling.y, normalScale.y, triplanar.y, w.g, vUv, vWorldPos, bw, albedo, nrm);
|
|
375
|
+
splatLayer(albedo2, normals23, 0.0, tiling.z, normalScale.z, triplanar.z, w.b, vUv, vWorldPos, bw, albedo, nrm);
|
|
376
|
+
splatLayer(albedo3, normals23, 1.0, tiling.w, normalScale.w, triplanar.w, w.a, vUv, vWorldPos, bw, albedo, nrm);
|
|
377
|
+
vec3 n = applyTangentNormal(normalize(nrm), ng);
|
|
378
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
379
|
+
if (dot(ng, v) < 0.0) n = -n;
|
|
380
|
+
vec3 diffuseColor = albedo * tint;
|
|
381
|
+
vec3 color = shadePBR(n, v, diffuseColor, vec3(0.04), dot(roughness, w), 1.0);
|
|
382
|
+
fragColor = vec4(tonemap(color), 1.0);
|
|
383
|
+
}
|
|
384
|
+
`,ka=`#version 300 es
|
|
385
|
+
precision highp float;
|
|
386
|
+
in vec3 vWorldPos;
|
|
387
|
+
in vec3 vNormal;
|
|
388
|
+
in vec2 vUv;
|
|
389
|
+
uniform vec4 baseColor; // linear, premultiplied; factor over baseColorMap
|
|
390
|
+
uniform sampler2D baseColorMap;
|
|
391
|
+
out vec4 fragColor;
|
|
392
|
+
${xr}
|
|
393
|
+
void main() {
|
|
394
|
+
vec4 c = baseColor * texture(baseColorMap, vUv);
|
|
395
|
+
fragColor = vec4(tonemap(c.rgb), 1.0);
|
|
396
|
+
}
|
|
397
|
+
`,Wa=`#version 300 es
|
|
398
|
+
precision highp float;
|
|
399
|
+
in vec3 vWorldPos;
|
|
400
|
+
in vec3 vNormal;
|
|
401
|
+
in vec2 vUv;
|
|
402
|
+
uniform vec4 baseColor; // linear, straight alpha; factor over baseColorMap
|
|
403
|
+
uniform sampler2D baseColorMap;
|
|
404
|
+
out vec4 fragColor;
|
|
405
|
+
${xr}
|
|
406
|
+
void main() {
|
|
407
|
+
vec4 c = baseColor * texture(baseColorMap, vUv);
|
|
408
|
+
fragColor = vec4(tonemap(c.rgb) * c.a, c.a);
|
|
409
|
+
}
|
|
410
|
+
`,$a=`#version 300 es
|
|
411
|
+
precision highp float;
|
|
412
|
+
in vec2 vUv;
|
|
413
|
+
in vec3 vWorldPos;
|
|
414
|
+
in vec3 vNormal;
|
|
415
|
+
uniform sampler2D baseColorMap;
|
|
416
|
+
out vec4 fragColor;
|
|
417
|
+
${xr}
|
|
418
|
+
${ni}
|
|
419
|
+
void main() {
|
|
420
|
+
vec3 c = texture(baseColorMap, vUv).rgb;
|
|
421
|
+
fragColor = vec4(uTonemap > 0.5 ? c : inverseTonemapSRGB(c), 1.0);
|
|
422
|
+
}
|
|
423
|
+
`,ja=`#version 300 es
|
|
424
|
+
precision highp float;
|
|
425
|
+
in vec3 vWorldPos;
|
|
426
|
+
in vec3 vNormal;
|
|
427
|
+
in vec2 vUv;
|
|
428
|
+
uniform vec4 color; // linear, premultiplied
|
|
429
|
+
${Rr}
|
|
430
|
+
out vec4 fragColor;
|
|
431
|
+
void main() {
|
|
432
|
+
float vis = sampleShadowPCF();
|
|
433
|
+
float shadowAmount = 1.0 - vis;
|
|
434
|
+
fragColor = vec4(color.rgb * shadowAmount, color.a * shadowAmount);
|
|
435
|
+
}
|
|
436
|
+
`,vn=t=>ii(t),Kt=ii(""),Xa=t=>`#version 300 es
|
|
437
|
+
precision highp float;
|
|
438
|
+
${t}
|
|
439
|
+
in vec3 vWorldPos;
|
|
440
|
+
in vec3 vNormal;
|
|
441
|
+
in vec2 vUv;
|
|
442
|
+
#ifdef HAS_COLOR
|
|
443
|
+
in vec4 vColor;
|
|
444
|
+
#endif
|
|
445
|
+
uniform vec3 cameraPosition;
|
|
446
|
+
uniform vec4 uBaseColorFactor;
|
|
447
|
+
uniform float uMetallic;
|
|
448
|
+
uniform float uRoughness;
|
|
449
|
+
uniform vec3 uEmissive;
|
|
450
|
+
uniform float uAlphaCutoff;
|
|
451
|
+
#ifdef HAS_BASECOLOR_MAP
|
|
452
|
+
uniform sampler2D uBaseColorMap;
|
|
453
|
+
#endif
|
|
454
|
+
#ifdef HAS_MR_MAP
|
|
455
|
+
uniform sampler2D uMRMap;
|
|
456
|
+
#endif
|
|
457
|
+
#ifdef HAS_NORMAL_MAP
|
|
458
|
+
uniform sampler2D uNormalMap;
|
|
459
|
+
#endif
|
|
460
|
+
#ifdef HAS_OCCLUSION_MAP
|
|
461
|
+
uniform sampler2D uOcclusionMap;
|
|
462
|
+
#endif
|
|
463
|
+
#ifdef HAS_EMISSIVE_MAP
|
|
464
|
+
uniform sampler2D uEmissiveMap;
|
|
465
|
+
#endif
|
|
466
|
+
${Rr}
|
|
467
|
+
out vec4 fragColor;
|
|
468
|
+
|
|
469
|
+
#ifdef HAS_NORMAL_MAP
|
|
470
|
+
vec3 getNormal() {
|
|
471
|
+
vec3 pos_dx = dFdx(vWorldPos);
|
|
472
|
+
vec3 pos_dy = dFdy(vWorldPos);
|
|
473
|
+
vec2 tex_dx = dFdx(vUv);
|
|
474
|
+
vec2 tex_dy = dFdy(vUv);
|
|
475
|
+
float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
|
|
476
|
+
if (abs(det) < 1e-8) return normalize(vNormal);
|
|
477
|
+
vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
|
|
478
|
+
vec3 ng = normalize(vNormal);
|
|
479
|
+
t = normalize(t - ng * dot(ng, t));
|
|
480
|
+
vec3 b = normalize(cross(ng, t)) * sign(det);
|
|
481
|
+
mat3 tbn = mat3(t, b, ng);
|
|
482
|
+
vec3 n = texture(uNormalMap, vUv).rgb * 2.0 - 1.0;
|
|
483
|
+
return normalize(tbn * n);
|
|
484
|
+
}
|
|
485
|
+
#endif
|
|
486
|
+
|
|
487
|
+
void main() {
|
|
488
|
+
vec4 base = uBaseColorFactor;
|
|
489
|
+
#ifdef HAS_BASECOLOR_MAP
|
|
490
|
+
base *= texture(uBaseColorMap, vUv);
|
|
491
|
+
#endif
|
|
492
|
+
#ifdef HAS_COLOR
|
|
493
|
+
base *= vColor;
|
|
494
|
+
#endif
|
|
495
|
+
#ifdef ALPHA_MASK
|
|
496
|
+
if (base.a < uAlphaCutoff) discard;
|
|
497
|
+
#endif
|
|
498
|
+
|
|
499
|
+
#ifdef UNLIT
|
|
500
|
+
// KHR_materials_unlit: the base colour IS the shaded colour — no lights, no IBL, no exposure
|
|
501
|
+
// (Filament's UNLIT shading model does the same, then tone-maps in post like everything else).
|
|
502
|
+
#ifdef ALPHA_BLEND
|
|
503
|
+
fragColor = vec4(tonemap(base.rgb), base.a);
|
|
504
|
+
#else
|
|
505
|
+
fragColor = vec4(tonemap(base.rgb), 1.0);
|
|
506
|
+
#endif
|
|
507
|
+
return;
|
|
508
|
+
#endif
|
|
509
|
+
|
|
510
|
+
float metallic = uMetallic;
|
|
511
|
+
float roughness = uRoughness;
|
|
512
|
+
#ifdef HAS_MR_MAP
|
|
513
|
+
vec3 mr = texture(uMRMap, vUv).rgb;
|
|
514
|
+
roughness *= mr.g;
|
|
515
|
+
metallic *= mr.b;
|
|
516
|
+
#endif
|
|
517
|
+
|
|
518
|
+
float occlusion = 1.0;
|
|
519
|
+
#ifdef HAS_OCCLUSION_MAP
|
|
520
|
+
occlusion = texture(uOcclusionMap, vUv).r;
|
|
521
|
+
#endif
|
|
522
|
+
|
|
523
|
+
#ifdef HAS_NORMAL_MAP
|
|
524
|
+
vec3 n = getNormal();
|
|
525
|
+
#else
|
|
526
|
+
vec3 n = normalize(vNormal);
|
|
527
|
+
#endif
|
|
528
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
529
|
+
#ifdef DOUBLE_SIDED
|
|
530
|
+
if (dot(n, v) < 0.0) n = -n;
|
|
531
|
+
#endif
|
|
532
|
+
|
|
533
|
+
vec3 diffuseColor = base.rgb * (1.0 - metallic);
|
|
534
|
+
vec3 f0 = mix(vec3(0.04), base.rgb, metallic);
|
|
535
|
+
vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, occlusion);
|
|
536
|
+
|
|
537
|
+
vec3 emissive = uEmissive;
|
|
538
|
+
#ifdef HAS_EMISSIVE_MAP
|
|
539
|
+
emissive *= texture(uEmissiveMap, vUv).rgb;
|
|
540
|
+
#endif
|
|
541
|
+
color += emissive * iblLuminance * exposure;
|
|
542
|
+
|
|
543
|
+
#ifdef ALPHA_BLEND
|
|
544
|
+
fragColor = vec4(tonemap(color), base.a);
|
|
545
|
+
#else
|
|
546
|
+
fragColor = vec4(tonemap(color), 1.0);
|
|
547
|
+
#endif
|
|
548
|
+
}
|
|
549
|
+
`,us=`#version 300 es
|
|
550
|
+
precision highp float;
|
|
551
|
+
in vec3 vWorldPos;
|
|
552
|
+
in vec3 vNormal;
|
|
553
|
+
in vec2 vUv;
|
|
554
|
+
uniform vec3 uWireColor;
|
|
555
|
+
out vec4 fragColor;
|
|
556
|
+
void main() { fragColor = vec4(uWireColor, 1.0); }
|
|
557
|
+
`,Er=(t,e=!1)=>`#version 300 es
|
|
558
|
+
precision highp float;
|
|
559
|
+
in vec3 position;
|
|
560
|
+
${t?`in vec3 normal;
|
|
561
|
+
in vec2 uv;`:""}
|
|
562
|
+
${e?"in mat4 instanceMatrix;":"uniform mat4 modelMatrix;"}
|
|
563
|
+
uniform mat4 shadowViewProjection;
|
|
564
|
+
${t?si:""}
|
|
565
|
+
void main() {
|
|
566
|
+
vec4 pos = vec4(position, 1.0);
|
|
567
|
+
${t?"pos = getSkinMatrix() * pos;":""}
|
|
568
|
+
gl_Position = shadowViewProjection * ${e?"instanceMatrix":"modelMatrix"} * pos;
|
|
569
|
+
}
|
|
570
|
+
`,Cr=`#version 300 es
|
|
571
|
+
precision highp float;
|
|
572
|
+
out vec4 fragColor;
|
|
573
|
+
void main() { fragColor = vec4(1.0); }
|
|
574
|
+
`,mr=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),qa=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)},Ya=t=>[mr((t>>>16&255)/255),mr((t>>>8&255)/255),mr((t&255)/255)],Ka=t=>[mr((t>>>24&255)/255),mr((t>>>16&255)/255),mr((t>>>8&255)/255),(t&255)/255],oi=`
|
|
575
|
+
uniform sampler2D baseColorMap;
|
|
576
|
+
uniform vec2 sheetSize; // (cols, rows) of the flipbook sheet, both >= 1 (the SDK primes it)
|
|
577
|
+
uniform float emissive;
|
|
578
|
+
uniform float additive;
|
|
579
|
+
uniform float softness;
|
|
580
|
+
uniform float depthFade; // declared so the SDK's write lands somewhere; ignored (no depth buffer)
|
|
581
|
+
${xr}
|
|
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
|
+
`,Qa=`#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
|
+
`,Za=`#version 300 es
|
|
607
|
+
precision highp float;
|
|
608
|
+
in vec4 vColor;
|
|
609
|
+
in vec4 vCustom;
|
|
610
|
+
${oi}
|
|
611
|
+
out vec4 fragColor;
|
|
612
|
+
void main() {
|
|
613
|
+
vec2 uv = gl_PointCoord.xy;
|
|
614
|
+
float rot = vCustom.y;
|
|
615
|
+
if (rot != 0.0) {
|
|
616
|
+
float co = cos(rot);
|
|
617
|
+
float si = sin(rot);
|
|
618
|
+
vec2 p = uv - vec2(0.5);
|
|
619
|
+
uv = vec2(co * p.x - si * p.y, si * p.x + co * p.y) + vec2(0.5);
|
|
620
|
+
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) discard;
|
|
621
|
+
}
|
|
622
|
+
int total = int(sheetSize.x + 0.5) * int(sheetSize.y + 0.5);
|
|
623
|
+
int fi = int(floor(vCustom.w) + 0.5);
|
|
624
|
+
fi = fi - (fi / total) * total;
|
|
625
|
+
vec4 tex = texture(baseColorMap, (sheetCell(fi) + uv) / sheetSize);
|
|
626
|
+
float radial = 1.0 - smoothstep(0.0, 0.5, length(gl_PointCoord.xy - vec2(0.5)));
|
|
627
|
+
float shape = mix(1.0, radial, clamp(softness, 0.0, 1.0));
|
|
628
|
+
float alpha = tex.a * vColor.a * vCustom.z * shape;
|
|
629
|
+
vec3 rgb = tex.rgb * vColor.rgb * (1.0 + emissive);
|
|
630
|
+
fragColor = vec4(tonemap(rgb) * alpha, alpha * (1.0 - clamp(additive, 0.0, 1.0)));
|
|
631
|
+
}
|
|
632
|
+
`,Ja=`#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
|
+
`,el=`#version 300 es
|
|
683
|
+
precision highp float;
|
|
684
|
+
in vec4 vColor;
|
|
685
|
+
in vec4 vCustom;
|
|
686
|
+
in vec4 vQuadUv;
|
|
687
|
+
${oi}
|
|
688
|
+
uniform sampler2D emissiveMap;
|
|
689
|
+
uniform vec3 emissiveColor;
|
|
690
|
+
uniform float frameBlend;
|
|
691
|
+
out vec4 fragColor;
|
|
692
|
+
void main() {
|
|
693
|
+
vec2 uv = vQuadUv.xy;
|
|
694
|
+
float total = sheetSize.x * sheetSize.y;
|
|
695
|
+
float fidx = mod(vCustom.w, total);
|
|
696
|
+
float frame = floor(fidx);
|
|
697
|
+
int fi = int(frame + 0.5);
|
|
698
|
+
vec2 tuv = (sheetCell(fi) + uv) / sheetSize;
|
|
699
|
+
vec4 tex = texture(baseColorMap, tuv);
|
|
700
|
+
vec3 em = texture(emissiveMap, tuv).rgb;
|
|
701
|
+
if (frameBlend > 0.5) {
|
|
702
|
+
int ni = min(fi + 1, int(total + 0.5) - 1);
|
|
703
|
+
vec2 tuv2 = (sheetCell(ni) + uv) / sheetSize;
|
|
704
|
+
float f = fidx - frame;
|
|
705
|
+
tex = mix(tex, texture(baseColorMap, tuv2), f);
|
|
706
|
+
em = mix(em, texture(emissiveMap, tuv2).rgb, f);
|
|
707
|
+
}
|
|
708
|
+
float radial = 1.0 - smoothstep(0.0, 0.5, length(vQuadUv.zw));
|
|
709
|
+
float shape = mix(1.0, radial, clamp(softness, 0.0, 1.0));
|
|
710
|
+
float alpha = tex.a * vColor.a * vCustom.z * shape;
|
|
711
|
+
vec3 rgb = tex.rgb * vColor.rgb * (1.0 + emissive) + em * emissiveColor;
|
|
712
|
+
fragColor = vec4(tonemap(rgb) * alpha, alpha * (1.0 - clamp(additive, 0.0, 1.0)));
|
|
713
|
+
}
|
|
714
|
+
`,tl=2873840728,rl=t=>{const e=new DataView(t);if(e.getUint32(0,!1)!==tl)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),o=n(28),l=n(36),a=n(40),f=n(52),p=Math.max(1,n(56)),g=n(60),h=new Map,v=new TextDecoder("utf-8");let M=64;const d=64+g;for(;M<d;){const x=n(M);M+=4;const P=new Uint8Array(t,M,x),B=P.indexOf(0),T=v.decode(P.subarray(0,B)),E=v.decode(P.subarray(B+1)).replace(/\0+$/,"");h.set(T,E),M+=x+(3-(x+3)%4)}const y=[];M=d;for(let x=0;x<p;x++){const P=n(M);M+=4;const B=[];for(let T=0;T<f;T++)B.push(new Uint8Array(t,M,P)),M+=P+(3-(P+3)%4);y.push(B)}return{glType:s,glFormat:i,glInternalFormat:o,width:l,height:a,faces:f,mipLevels:p,keyValues:h,mips:y}},nl=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},fs=35898,sl=35899,ds=6407,il=(t,e)=>{const r=rl(e),n=nl(r.keyValues.get("sh")),s=new qe(t,{target:t.TEXTURE_CUBE_MAP,generateMipmaps:!1,minFilter:t.LINEAR_MIPMAP_LINEAR,magFilter:t.LINEAR,flipY:!1,width:r.width,height:r.height}),i=r.glInternalFormat===fs;t.bindTexture(t.TEXTURE_CUBE_MAP,s.texture),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!1),t.pixelStorei(t.UNPACK_ALIGNMENT,1);for(let o=0;o<r.mipLevels;o++){const l=Math.max(1,r.width>>o);for(let a=0;a<r.faces;a++){const f=r.mips[o][a];if(i)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+a,o,fs,l,l,0,ds,sl,new Uint32Array(f.buffer,f.byteOffset,f.byteLength/4));else{const p=r.glFormat===ds?3:4;t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+a,o,p===3?t.RGB8:t.RGBA8,l,l,0,p===3?t.RGB:t.RGBA,t.UNSIGNED_BYTE,f)}}}return t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAX_LEVEL,r.mipLevels-1),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR),s.store.image=s.image=r,s.needsUpdate=!1,{sh:n,cubemap:s,maxLod:r.mipLevels-1}},ol=["EXT_meshopt_compression"],al=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))},ll=t=>{const e=[];return(t.animations??[]).forEach((r,n)=>{var i,o;const s=[];for(const l of r.channels??[]){const a=l.sampler!==void 0?(i=r.samplers)==null?void 0:i[l.sampler]:void 0;((o=l.target)==null?void 0:o.path)==="weights"&&l.target.node!==void 0&&a?e.push({anim:n,node:l.target.node,input:a.input,output:a.output,interpolation:a.interpolation??"LINEAR"}):s.push(l)}r.channels=s}),e},cl={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},hl={5120:127,5121:255,5122:32767,5123:65535},ul={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},Gr=(t,e,r)=>{var a,f,p;const n=(a=t==null?void 0:t.accessors)==null?void 0:a[r],s=ul[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 o=(g,h,v,M,d,y)=>{var u;const x=new Float32Array(M*d),P=(u=t.bufferViews)==null?void 0:u[g],B=P?e[typeof P.buffer=="number"?P.buffer:0]:void 0,T=cl[v];if(!P||!B||!T)return x;const E=T.BYTES_PER_ELEMENT,c=(P.byteOffset??0)+h;if(!y||y===d*E){const m=new T(B,c,M*d);for(let w=0;w<x.length;w++)x[w]=m[w]}else for(let m=0;m<M;m++){const w=new T(B,c+m*y,d);for(let _=0;_<d;_++)x[m*d+_]=w[_]}return x};if(n.bufferView!==void 0&&i.set(o(n.bufferView,n.byteOffset??0,n.componentType,n.count,s,((p=(f=t.bufferViews)==null?void 0:f[n.bufferView])==null?void 0:p.byteStride)??0)),n.sparse){const g=n.sparse,h=o(g.indices.bufferView,g.indices.byteOffset??0,g.indices.componentType,g.count,1,0),v=o(g.values.bufferView,g.values.byteOffset??0,n.componentType,g.count,s,0);for(let M=0;M<g.count;M++)for(let d=0;d<s;d++)i[h[M]*s+d]=v[M*s+d]}const l=n.normalized?hl[n.componentType]:void 0;if(l)for(let g=0;g<i.length;g++)i[g]=Math.max(i[g]/l,-1);return i};new tr;new tr;const fl=(t,e)=>{const r=Math.floor((t?t.length:e)/3),n=1<<24,s=new Set;for(let l=0;l<r;l++){const a=t?t[l*3]:l*3,f=t?t[l*3+1]:l*3+1,p=t?t[l*3+2]:l*3+2;s.add(Math.min(a,f)*n+Math.max(a,f)),s.add(Math.min(f,p)*n+Math.max(f,p)),s.add(Math.min(p,a)*n+Math.max(p,a))}const i=e>65535?new Uint32Array(s.size*2):new Uint16Array(s.size*2);let o=0;for(const l of s)i[o++]=Math.floor(l/n),i[o++]=l%n;return i},dl=t=>new qe(t,{image:new Uint8Array([255,255,255,255]),width:1,height:1,generateMipmaps:!1}),ml=t=>{const e=new qe(t,{target:t.TEXTURE_CUBE_MAP,width:1,height:1,generateMipmaps:!1,minFilter:t.LINEAR});t.bindTexture(t.TEXTURE_CUBE_MAP,e.texture);const r=new Uint8Array(4);for(let n=0;n<6;n++)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,r);return e.store.image=e.image=r,e.needsUpdate=!1,e},Fr=8,pl=(t,e,r,n)=>{var i,o,l,a,f,p;const s=e.nodes??[];for(let g=0;g<s.length;g++){const h=s[g].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(E=>{var c;return(c=E.targets)==null?void 0:c.length})))continue;const d=(o=r.nodes)==null?void 0:o[g],y=(l=r.meshes)==null?void 0:l[h];if(!d||!y)continue;const x=Math.max(...M.map(E=>{var c;return((c=E.targets)==null?void 0:c.length)??0})),P=new Float32Array(x),B=s[g].weights??v.weights;if(B)for(let E=0;E<Math.min(x,B.length);E++)P[E]=B[E];d.weights=P,x>Fr&&console.warn(`[viewer-lite] GLB: mesh has ${x} morph targets — only the first ${Fr} deform`);const T=Array.isArray((a=y.primitives)==null?void 0:a[0])?y.primitives[0]:y.primitives??[];for(let E=0;E<M.length;E++){const c=M[E].targets,u=T[E];if(!(c!=null&&c.length)||!(u!=null&&u.geometry))continue;const m=((p=(f=u.geometry.attributes)==null?void 0:f.position)==null?void 0:p.count)??0;if(m===0)continue;const w=Math.min(c.length,Fr);if(c.slice(0,w).find(Y=>{const D=X=>{var V,q;return X!==void 0&&((q=(V=e.accessors)==null?void 0:V[X])==null?void 0:q.count)!==m};return D(Y.POSITION)||D(Y.NORMAL)})){console.warn(`[viewer-lite] GLB: morph targets skipped on a primitive — target accessor count doesn't match the ${m}-vertex geometry (draco decode changed the vertex set)`);continue}const L=c.slice(0,w).some(Y=>Y.NORMAL!==void 0),z=m*w*(L?2:1),N=Math.max(1,Math.ceil(Math.sqrt(z))),$=Math.max(1,Math.ceil(z/N)),k=new Float32Array(N*$*4);for(let Y=0;Y<w;Y++){const D=c[Y].POSITION!==void 0?Gr(e,n,c[Y].POSITION):null,X=L&&c[Y].NORMAL!==void 0?Gr(e,n,c[Y].NORMAL):null;for(let V=0;V<m;V++){if(D){const q=(Y*m+V)*4;k[q]=D[V*3]??0,k[q+1]=D[V*3+1]??0,k[q+2]=D[V*3+2]??0}if(X){const q=((w+Y)*m+V)*4;k[q]=X[V*3]??0,k[q+1]=X[V*3+1]??0,k[q+2]=X[V*3+2]??0}}}const J=new qe(t,{image:k,width:N,height:$,type:t.FLOAT,format:t.RGBA,internalFormat:t.RGBA32F,generateMipmaps:!1,minFilter:t.NEAREST,magFilter:t.NEAREST,flipY:!1});u._morph={texture:J,count:w,vertexCount:m,texWidth:N,hasNormals:L,weights:P}}}},ms=(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}},ai=t=>{var s,i;const e=[];t instanceof Et&&e.push("HAS_SKIN");const r=(i=(s=t.geometry)==null?void 0:s.attributes)==null?void 0:i.color;r&&r.size===4&&e.push("HAS_COLOR");const n=t._morph;return n&&(e.push("HAS_MORPH"),n.hasNormals&&e.push("HAS_MORPH_NORMALS")),e.join(" ")},li=(t,e)=>{const r={uMorphTex:{value:e.texture},uMorphCount:{value:e.count},uMorphVertexCount:{value:e.vertexCount},uMorphTexWidth:{value:e.texWidth},uMorphWeights:{value:[e.weights.length>Fr?e.weights.subarray(0,Fr):e.weights]}};t.onBeforeRender(()=>{Object.assign(t.program.uniforms,r)})},gl=(t,e,r,n,s)=>{var p,g,h,v,M,d,y,x,P,B,T;const i=e??{},o=[];(p=i.baseColorTexture)!=null&&p.texture&&o.push("#define HAS_BASECOLOR_MAP"),(g=i.metallicRoughnessTexture)!=null&&g.texture&&o.push("#define HAS_MR_MAP"),(h=i.normalTexture)!=null&&h.texture&&o.push("#define HAS_NORMAL_MAP"),(v=i.occlusionTexture)!=null&&v.texture&&o.push("#define HAS_OCCLUSION_MAP"),(M=i.emissiveTexture)!=null&&M.texture&&o.push("#define HAS_EMISSIVE_MAP"),(d=i.extensions)!=null&&d.KHR_materials_unlit&&o.push("#define UNLIT"),i.doubleSided&&o.push("#define DOUBLE_SIDED"),i.alphaMode==="MASK"&&o.push("#define ALPHA_MASK"),i.alphaMode==="BLEND"&&o.push("#define ALPHA_BLEND");const l=E=>Xa([...o,...E.includes("HAS_COLOR")?["#define HAS_COLOR"]:[]].join(`
|
|
715
|
+
`));ms(t,i.baseColorTexture),ms(t,i.emissiveTexture);const a={...n,uBaseColorFactor:{value:i.baseColorFactor??[1,1,1,1]},uMetallic:{value:i.metallicFactor??1},uRoughness:{value:i.roughnessFactor??1},uEmissive:{value:i.emissiveFactor??[0,0,0]},uAlphaCutoff:{value:i.alphaCutoff??.5}};(y=i.baseColorTexture)!=null&&y.texture&&(a.uBaseColorMap={value:i.baseColorTexture.texture}),(x=i.metallicRoughnessTexture)!=null&&x.texture&&(a.uMRMap={value:i.metallicRoughnessTexture.texture}),(P=i.normalTexture)!=null&&P.texture&&(a.uNormalMap={value:i.normalTexture.texture}),(B=i.occlusionTexture)!=null&&B.texture&&(a.uOcclusionMap={value:i.occlusionTexture.texture}),(T=i.emissiveTexture)!=null&&T.texture&&(a.uEmissiveMap={value:i.emissiveTexture.texture});const f=new Ue(t,{vertex:vn(r),fragment:l(r),uniforms:a,transparent:i.alphaMode==="BLEND",cullFace:i.doubleSided?!1:t.BACK});return i.alphaMode==="BLEND"&&f.setBlendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),f._source={fragment:l,vertex:r},f},vl=async(t,e,r,n)=>{var x,P,B,T,E;const s=ls.unpackGLB(e),i=(s.extensionsRequired??[]).filter(c=>ol.includes(c));if(i.length>0)throw new Error(`GLB requires ${i.join(", ")} — the lite engine has no decoder for it`);const o=[...s.extensionsUsed??[],...s.extensionsRequired??[]],l=o.includes("KHR_draco_mesh_compression"),a=o.includes("KHR_texture_basisu")||(s.images??[]).some(c=>c.mimeType==="image/ktx2");if(l||a){const c=await Tr(()=>import("./index-B2zEJlWS.js"),__vite__mapDeps([0,1]),import.meta.url);await Promise.all([l?c.ensureDracoDecoder():null,a?c.ensureBasisTranscoder(t):null])}al(s);const f=ll(s),p=await ls.parse(t,s,""),g=(s.buffers??[]).map(c=>c.binary);pl(t,s,p,g);const h=new Map,v=new Set,M=[];for(const c of p.nodes)c.traverse(u=>(u.draw&&!v.has(u)&&(v.add(u),M.push(u)),!1));for(const c of M){const u=(x=c.geometry)==null?void 0:x.attributes,m=((P=u==null?void 0:u.position)==null?void 0:P.count)??0;if(u&&m>0){if(!u.normal){const k=new Float32Array(m*3);for(let J=2;J<k.length;J+=3)k[J]=1;c.geometry.addAttribute("normal",{size:3,data:k})}u.uv||c.geometry.addAttribute("uv",{size:2,data:new Float32Array(m*2)})}const w=(B=c.program)==null?void 0:B.gltfMaterial,_=c._morph;_&&li(c,_);const L=ai(c),z=w??c;let N=h.get(z);N||h.set(z,N=new Map);let $=N.get(L);$||N.set(L,$=gl(t,w,L,r)),c.program=$,c._receiveShadows=!0,c._castShadows=!0}p.images&&await Promise.all(p.images.map(c=>c==null?void 0:c.ready).filter(Boolean));const d=(p.animations??[]).map((c,u)=>{const m=[];for(const w of c.animation.data)m.includes(w.node)||m.push(w.node);return{name:typeof c.name=="string"&&c.name.length>0?c.name:`animation_${u}`,duration:c.animation.duration,animation:c.animation,nodes:m}});let y=0;for(const c of f){const u=d[c.anim],m=(T=p.nodes)==null?void 0:T[c.node];!u||!(m!=null&&m.weights)||(u.animation.data.push({node:m,transform:"weights",interpolation:c.interpolation,times:Gr(s,g,c.input),values:Gr(s,g,c.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 c of d){let u=1/0,m=0;for(const w of c.animation.data)u=Math.min(u,w.times[0]),m=Math.max(m,w.times[w.times.length-1]);c.animation.startTime=u===1/0?0:u,c.animation.duration=c.duration=u===1/0?0:m-u}return{roots:p.scene??((E=p.scenes)==null?void 0:E[0])??[],nodes:p.nodes??[],animations:d}},yl=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}},xl={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])}},wl=`
|
|
716
|
+
struct MaterialInputs {
|
|
717
|
+
vec4 baseColor;
|
|
718
|
+
float roughness;
|
|
719
|
+
float metallic;
|
|
720
|
+
float reflectance;
|
|
721
|
+
float ambientOcclusion;
|
|
722
|
+
vec4 emissive;
|
|
723
|
+
vec3 normal;
|
|
724
|
+
float clearCoat;
|
|
725
|
+
float clearCoatRoughness;
|
|
726
|
+
vec4 postLightingColor;
|
|
727
|
+
};
|
|
728
|
+
void prepareMaterial(inout MaterialInputs m) {}
|
|
729
|
+
vec3 getWorldPosition() { return vWorldPos; }
|
|
730
|
+
vec3 getWorldGeometricNormalVector() { return normalize(vNormal); }
|
|
731
|
+
vec3 getWorldViewVector() { return normalize(cameraPosition - vWorldPos); }
|
|
732
|
+
vec4 getUserTime() { return userTime; }
|
|
733
|
+
${ni}
|
|
734
|
+
vec3 inverseTonemap(vec3 linear) {
|
|
735
|
+
return Inverse_Tonemap_Filmic(clamp(linear, 0.0, 1.0));
|
|
736
|
+
}
|
|
737
|
+
`,rn=`
|
|
738
|
+
MaterialInputs inputs;
|
|
739
|
+
inputs.baseColor = vec4(1.0);
|
|
740
|
+
inputs.roughness = 1.0;
|
|
741
|
+
inputs.metallic = 0.0;
|
|
742
|
+
inputs.reflectance = 0.5;
|
|
743
|
+
inputs.ambientOcclusion = 1.0;
|
|
744
|
+
inputs.emissive = vec4(0.0, 0.0, 0.0, 1.0);
|
|
745
|
+
inputs.normal = vec3(0.0, 0.0, 1.0);
|
|
746
|
+
inputs.clearCoat = 0.0;
|
|
747
|
+
inputs.clearCoatRoughness = 0.0;
|
|
748
|
+
inputs.postLightingColor = vec4(0.0);
|
|
749
|
+
material(inputs);
|
|
750
|
+
`,Ml=`
|
|
751
|
+
vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
|
|
752
|
+
vec3 pos_dx = dFdx(vWorldPos);
|
|
753
|
+
vec3 pos_dy = dFdy(vWorldPos);
|
|
754
|
+
vec2 tex_dx = dFdx(vUv);
|
|
755
|
+
vec2 tex_dy = dFdy(vUv);
|
|
756
|
+
float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
|
|
757
|
+
if (abs(det) < 1e-8) return ng;
|
|
758
|
+
vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
|
|
759
|
+
t = normalize(t - ng * dot(ng, t));
|
|
760
|
+
vec3 b = normalize(cross(ng, t)) * sign(det);
|
|
761
|
+
return normalize(mat3(t, b, ng) * nTangent);
|
|
762
|
+
}
|
|
763
|
+
`,bl=t=>{if(t.unsupported)return null;const e=[],r=[],n=new Set;for(const h of t.params){const v=xl[h.type];if(!v)return null;e.push(`uniform ${v.decl} materialParams_${h.name}${h.size?`[${h.size}]`:""};`);const M=h.size?new Array(h.size*(Array.isArray(v.zero)||v.zero instanceof Float32Array?v.zero.length:1)).fill(0):v.zero;r.push({key:`materialParams_${h.name}`,value:Array.isArray(M)?[...M]:M}),n.add(h.name)}for(const h of t.samplers)e.push(`uniform sampler2D materialParams_${h.name};`),r.push({key:`materialParams_${h.name}`,value:"texture"}),n.add(h.name);const s=t.shadingModel==="lit",i=s||t.shadowMultiplier,o=t.blending==="opaque"||t.blending==="masked",l=t.blending==="masked"?`if (inputs.baseColor.a < ${t.maskThreshold.toFixed(4)}) discard;`:"",a=o?"1.0":"inputs.baseColor.a",f=t.shadowMultiplier?`
|
|
764
|
+
void main() {
|
|
765
|
+
${rn}
|
|
766
|
+
float shadowAmount = 1.0 - sampleShadowPCF();
|
|
767
|
+
fragColor = vec4(inputs.baseColor.rgb * shadowAmount, inputs.baseColor.a * shadowAmount);
|
|
768
|
+
}
|
|
769
|
+
`:s?`
|
|
770
|
+
void main() {
|
|
771
|
+
${rn}
|
|
772
|
+
${l}
|
|
773
|
+
vec3 n = normalize(vNormal);
|
|
774
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
775
|
+
${t.doubleSided?"if (dot(n, v) < 0.0) n = -n;":""}
|
|
776
|
+
${t.writesNormal?"n = applyTangentNormal(inputs.normal, n);":""}
|
|
777
|
+
vec3 diffuseColor = inputs.baseColor.rgb * (1.0 - inputs.metallic);
|
|
778
|
+
vec3 f0 = mix(vec3(0.16 * inputs.reflectance * inputs.reflectance), inputs.baseColor.rgb, inputs.metallic);
|
|
779
|
+
vec3 color = shadePBR(n, v, diffuseColor, f0, inputs.roughness, inputs.ambientOcclusion);
|
|
780
|
+
color += inputs.emissive.rgb * (iblLuminance * exposure);
|
|
781
|
+
color += inputs.postLightingColor.rgb;
|
|
782
|
+
fragColor = vec4(tonemap(color), ${a});
|
|
783
|
+
}
|
|
784
|
+
`:`
|
|
785
|
+
void main() {
|
|
786
|
+
${rn}
|
|
787
|
+
${l}
|
|
788
|
+
vec3 color = inputs.baseColor.rgb + inputs.emissive.rgb + inputs.postLightingColor.rgb;
|
|
789
|
+
fragColor = vec4(tonemap(color), ${a});
|
|
790
|
+
}
|
|
791
|
+
`,p=t.flipUV===!1?"vUv":"vec2(vUv.x, 1.0 - vUv.y)";return{fragment:`#version 300 es
|
|
792
|
+
precision highp float;
|
|
793
|
+
in vec3 vWorldPos;
|
|
794
|
+
in vec3 vNormal;
|
|
795
|
+
in vec2 vUv;
|
|
796
|
+
uniform vec3 cameraPosition;
|
|
797
|
+
uniform vec4 userTime;
|
|
798
|
+
${e.join(`
|
|
799
|
+
`)}
|
|
800
|
+
${i?Rr:xr}
|
|
801
|
+
${wl}
|
|
802
|
+
vec2 getUV0() { return ${p}; }
|
|
803
|
+
vec2 getUV1() { return ${p}; }
|
|
804
|
+
${t.writesNormal?Ml:""}
|
|
805
|
+
out vec4 fragColor;
|
|
806
|
+
${t.fragmentCode}
|
|
807
|
+
${f}`,uniforms:r,paramNames:n,needsSceneUniforms:i}},lt=10,ps=0,gs=1;let Al=null,Vr=null;const Sl=()=>Al??(Al=Tr(()=>import("./creatorPhysics-k7wL0kV1.js"),__vite__mapDeps([2,1]),import.meta.url).then(t=>t.default()).then(t=>Vr=t)),vs=()=>Vr!==null,ct=(t,e,r)=>{const n=t._malloc(Math.max(4,e.length*4));t.HEAPF32.set(e,n>>2);try{return r(n)}finally{t._free(n)}},ys=(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)}},Or=(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)}},xs=t=>t instanceof Uint8Array?t:new Uint8Array(t),Mr=(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,o=t[0]/n,l=t[1]/n,a=t[2]/n,f=t[4]/s,p=t[5]/s,g=t[6]/s,h=t[8]/i,v=t[9]/i,M=t[10]/i,d=o+p+M;let y,x,P,B;if(d>0){const T=Math.sqrt(d+1)*2;B=.25*T,y=(g-v)/T,x=(h-a)/T,P=(l-f)/T}else if(o>p&&o>M){const T=Math.sqrt(1+o-p-M)*2;B=(g-v)/T,y=.25*T,x=(f+l)/T,P=(h+a)/T}else if(p>M){const T=Math.sqrt(1+p-o-M)*2;B=(h-a)/T,y=(f+l)/T,x=.25*T,P=(v+g)/T}else{const T=Math.sqrt(1+M-o-p)*2;B=(l-f)/T,y=(h+a)/T,x=(v+g)/T,P=.25*T}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]=P,e[r+6]=B,e[r+7]=n,e[r+8]=s,e[r+9]=i},_l=(t,e)=>{const r=Math.cos(e),n=Math.sin(e),s=t[0],i=t[1],o=t[2],l=t[8],a=t[9],f=t[10],p=t;p[0]=s*r-l*n,p[1]=i*r-a*n,p[2]=o*r-f*n,p[8]=s*n+l*r,p[9]=i*n+a*r,p[10]=o*n+f*r},El=(t,e=1,r=1,n=1)=>{const s=Vr;if(!s||t.length<12)return null;const i=ct(s,t,p=>s._cphysShapeMesh(p,Math.floor(t.length/3),0,0,1,e,r,n));if(!i)return null;const o=s._malloc(4),l=s._cphysShapeTriangles(i,o),a=s.HEAPU32[o>>2],f=l&&a?Float32Array.from(s.HEAPF32.subarray(l>>2,(l>>2)+a)):null;return l&&s._free(l),s._free(o),s._cphysShapeDestroy(i),f};function Cl(t){const e=Vr;if(!e)throw new Error("creator-physics: await loadCreatorPhysics() before createPhysicsBridge()");const r=e._malloc(lt*4),n=e._malloc(32),s=e._malloc(4);let i=0,o=0;const l=c=>(c>o&&(i&&e._free(i),i=e._malloc(c*4),o=c),i),a=new Map,f=new Map,p=(c,u)=>{if(!t.jointRanges)return;const m=u.entities.length,w=new Float32Array(m*9);if(ct(e,w,Y=>{const D=e._cphysRagdollJointFrames(c,Y);return w.set(e.HEAPF32.subarray(Y>>2,(Y>>2)+m*9)),D})!==m)return;const L=[],z=[],N=[];for(let Y=0;Y<m;Y++){const D=w[Y*9];if(!(D<0)){L.push(u.entities[Y],u.entities[D]);for(let X=1;X<9;X++)z.push(w[Y*9+X]);N.push(Y)}}if(L.length===0)return;const $=t.jointRanges(u.entities[0],L,Float32Array.from(z));if(!$)return;const k=new Float32Array(m*6),J=180/Math.PI;for(let Y=0;Y<N.length;Y++)for(let D=0;D<3;D++)k[N[Y]*6+D*2]=$[Y*6+D*2]*J-u.margin,k[N[Y]*6+D*2+1]=$[Y*6+D*2+1]*J+u.margin;ct(e,k,Y=>e._cphysRagdollSetLimits(c,Y))&&(u.learned=!0)},g=new WeakMap;let h=null;const v=e.addFunction(c=>t.parentOf(c)|0,"ii");e._cphysSetParentLookup(v),e._cphysInit();const M=c=>(Mr(t.world(c),e.HEAPF32,r>>2),r),d=(c,u)=>{const m=e.HEAPF32,w=u>>2;c[0]=m[w],c[1]=m[w+1],c[2]=m[w+2]},y=c=>{if(c===0)return;const u=e.HEAPU32,m=e._cphysPulledIds()>>2,w=e.HEAPF32,_=e._cphysPulledPoses()>>2;for(let L=0;L<c;L++){const z=_+L*lt;t.setWorldTRS(u[m+L],w[z],w[z+1],w[z+2],w[z+3],w[z+4],w[z+5],w[z+6],w[z+7],w[z+8],w[z+9])}},x=c=>{if(c===0)return;const u=e.HEAPU32,m=e._cphysPulledIds()>>2,w=e.HEAPF32,_=e._cphysPulledPoses()>>2;for(let L=0;L<c;L++){const z=_+L*lt;t.setWorldPosition(u[m+L],w[z],w[z+1],w[z+2])}},P=(c,u)=>{var L;const m=(L=t.glbBytes)==null?void 0:L.call(t,c);if(!m)return 0;let w=g.get(m);w||(w=[0,0],g.set(m,w));const _=u?1:0;if(!w[_]){const z=xs(m);w[_]=Or(e,z,N=>e._cphysShapeMeshFromGlb(N,z.length,u?1:0))}return w[_]},B=(c,u,m,w,_,L)=>u?e._cphysBodyCreate(c,u,m|0,w,_?1:0,L?1:0,1,M(c)):0,T=(c,u,m,w)=>{const _=B(c,u,m,w,!1,!1);return u&&e._cphysShapeDestroy(u),_};return{methods:{physicsHasSupport:()=>!0,physicsConfigure(c,u,m,w){e._cphysConfigure(c,u,m,(w|0)>0?w|0:0)},setInterpolation(c){e._cphysSetInterpolation(c?1:0)},physicsBuildBox:(c,u,m)=>e._cphysShapeBox(c,u,m),physicsBuildSphere:c=>e._cphysShapeSphere(c),physicsBuildCylinder:(c,u)=>e._cphysShapeCylinder(c,u),physicsBuildCapsule:(c,u)=>e._cphysShapeCapsule(c,u),physicsBuildMesh(c,u,m,w,_,L){return ct(e,c,z=>ys(e,u,N=>e._cphysShapeMesh(z,Math.floor(c.length/3),N,u.length,m?1:0,w,_,L)))},physicsBuildMeshFromEntity(c,u,m,w,_){const L=P(c,u);return L?e._cphysShapeScaled(L,m,w,_):0},physicsBuildHeightField(c,u,m,w,_,L,z,N){return ct(e,c,$=>_?Or(e,_,k=>e._cphysShapeHeightField($,u,m,w,k,L,z,N)):e._cphysShapeHeightField($,u,m,w,0,L,z,N))},physicsUpdateHeightField(c,u,m,w,_,L,z,N,$){ct(e,u,k=>$?Or(e,$,J=>e._cphysShapeUpdateHeightField(c,k,m,w,_,L,z,N,J)):e._cphysShapeUpdateHeightField(c,k,m,w,_,L,z,N,0))},glbTriangles(c){var z;const u=(z=t.glbBytes)==null?void 0:z.call(t,c);if(!u)return new Float32Array(0);const m=xs(u),w=Or(e,m,N=>e._cphysGlbTriangles(N,m.length,s));if(!w)return new Float32Array(0);const _=e.HEAPU32[s>>2],L=Float32Array.from(e.HEAPF32.subarray(w>>2,(w>>2)+_));return e._free(w),L},physicsSetShapeOrigin(c,u,m,w){e._cphysShapeSetOrigin(c,u,m,w)},physicsSetBodyShape(c,u,m){e._cphysBodySetShape(c,u,m?1:0)},physicsDestroyShape(c){e._cphysShapeDestroy(c)},physicsCreateBody:(c,u,m,w,_,L)=>B(c,u,m,w,_,L),physicsSetPickable(c,u){e._cphysBodySetPickable(c,u?1:0)},physicsSetFriction(c,u){e._cphysBodySetFriction(c,u)},physicsGetFriction:c=>e._cphysBodyGetFriction(c),physicsRaycast(c,u,m,w,_,L,z,N){const $=e._cphysRaycast(c,u,m,w,_,L,z,n);return $&&N&&N.set(e.HEAPF32.subarray(n>>2,(n>>2)+Math.min(7,N.length))),$},physicsCreateBox:(c,u,m,w,_,L)=>T(c,e._cphysShapeBox(u,m,w),_,L),physicsCreateSphere:(c,u,m,w)=>T(c,e._cphysShapeSphere(u),m,w),physicsCreateCylinder:(c,u,m,w,_)=>T(c,e._cphysShapeCylinder(u,m),w,_),physicsSetLinearVelocity(c,u,m,w){e._cphysBodySetLinearVelocity(c,u,m,w)},physicsGetLinearVelocity(c,u){e._cphysBodyGetLinearVelocity(c,n),d(u,n)},physicsSetAngularVelocity(c,u,m,w){e._cphysBodySetAngularVelocity(c,u,m,w)},physicsGetAngularVelocity(c,u){e._cphysBodyGetAngularVelocity(c,n),d(u,n)},physicsApplyImpulse(c,u,m,w){e._cphysBodyApplyImpulse(c,u,m,w)},physicsApplyImpulseAt(c,u,m,w,_,L,z){e._cphysBodyApplyImpulseAt(c,u,m,w,_,L,z)},physicsSetBodyPosition(c,u,m,w){e._cphysBodySetPosition(c,u,m,w)},physicsSetBodyRotation(c,u,m,w,_){e._cphysBodySetRotation(c,u,m,w,_)},physicsRemoveBody(c){e._cphysBodyRemove(c)},characterCreate(c,u,m){const w=u?e._cphysCharacterCreate(c,u,m,M(c)):0;return w&&a.set(w,c),w},characterDestroy(c){e._cphysCharacterDestroy(c),a.delete(c)},characterMove(c,u,m){e._cphysCharacterMove(c,u,m)},characterMoveFree(c,u,m,w){e._cphysCharacterMoveFree(c,u,m,w)},characterSetVerticalVelocity(c,u){e._cphysCharacterSetVerticalVelocity(c,u)},characterSetVelocity(c,u,m,w){e._cphysCharacterSetVelocity(c,u,m,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 m=a.get(c);if(m!==void 0){e._cphysCharacterPosition(c,n);const w=e.HEAPF32,_=n>>2;t.setWorldPosition(m,w[_],w[_+1],w[_+2])}return!0},characterGetVelocity(c,u){e._cphysCharacterGetVelocity(c,n),d(u,n)},characterGetGroundState:c=>e._cphysCharacterGetGroundState(c),characterSetPosition(c,u,m,w){e._cphysCharacterSetPosition(c,u,m,w)},vehicleCreate(c,u,m){return u?ct(e,m,w=>e._cphysVehicleCreate(c,u,w,m.length,M(c))):0},vehicleDestroy(c){e._cphysVehicleDestroy(c)},vehicleSetInput(c,u){ct(e,u,m=>e._cphysVehicleSetInput(c,m,u.length))},vehicleSetTuning(c,u){ct(e,u,m=>e._cphysVehicleSetTuning(c,m,u.length))},vehicleGetState(c,u){const m=l(u.length);e._cphysVehicleGetState(c,m,u.length),u.set(e.HEAPF32.subarray(m>>2,(m>>2)+u.length))},vehicleReset(c,u,m,w,_,L,z,N){e._cphysVehicleReset(c,u,m,w,_,L,z,N)},vehicleBodyId:c=>e._cphysVehicleBodyId(c),ragdollCreate(c,u,m){const w=m.length>1?m[1]|0:0;if(w<=0||u.length<w*2)return 0;const _=new Float32Array(lt);Mr(t.world(c),_,0);const L=new Float32Array(w*(lt+3)),z=[];for(let $=0;$<w;$++){const k=$*(lt+3);Mr(t.world(u[$*2]),L,k),z.push(u[$*2]);const J=u[$*2+1];if(J){const Y=t.world(J);L[k+lt]=Y[12],L[k+lt+1]=Y[13],L[k+lt+2]=Y[14]}}const N=ct(e,_,$=>ys(e,u,k=>ct(e,L,J=>ct(e,m,Y=>e._cphysRagdollCreate($,k,u.length,J,Y,m.length)))));return N&&f.set(N,{entities:z,prev:new Float32Array(w*lt),cur:new Float32Array(w*lt),valid:0,dt:1/60,active:!1,driven:!1,learn:m.length>14&&m[13]!==0,margin:m.length>14?Math.max(0,m[14]):0,learned:!1}),N},ragdollDestroy(c){e._cphysRagdollDestroy(c),f.delete(c)},ragdollActivate(c,u,m,w){const _=f.get(c);if(!_)return!1;!_.active&&_.learn&&!_.learned&&p(c,_);const L=_.entities.length,z=new Float32Array(L*lt);for(let k=0;k<L;k++)Mr(t.world(_.entities[k]),z,k*lt);let N=null;if(!_.active&&_.valid>=2&&_.dt>1e-5){N=new Float32Array(L*6);const k=1/_.dt;for(let J=0;J<L;J++){const Y=J*lt,D=J*6;N[D]=(_.cur[Y]-_.prev[Y])*k,N[D+1]=(_.cur[Y+1]-_.prev[Y+1])*k,N[D+2]=(_.cur[Y+2]-_.prev[Y+2])*k;const X=_.prev[Y+3],V=_.prev[Y+4],q=_.prev[Y+5],ae=_.prev[Y+6],ee=_.cur[Y+3],se=_.cur[Y+4],ue=_.cur[Y+5],xe=_.cur[Y+6];let me=xe*-X+ee*ae+se*-q-ue*-V,je=xe*-V-ee*-q+se*ae+ue*-X,Qe=xe*-q+ee*-V-se*-X+ue*ae,A=xe*ae-ee*-X-se*-V-ue*-q;A<0&&(me=-me,je=-je,Qe=-Qe,A=-A);const C=Math.sqrt(Math.max(0,1-A*A));if(C>1e-6){const R=2*Math.acos(Math.min(1,A))/C*k;N[D+3]=me*R,N[D+4]=je*R,N[D+5]=Qe*R}}}const $=ct(e,z,k=>N?ct(e,N,J=>e._cphysRagdollActivate(c,u,m,w,k,J)):e._cphysRagdollActivate(c,u,m,w,k,0))!==0;return $&&(_.active=!0),$},ragdollDeactivate(c,u){var w;const m=f.get(c);m!=null&&m.active&&(y(e._cphysRagdollPose(c)),u>0&&m.entities.length>0&&((w=t.seedAnimator)==null||w.call(t,m.entities[0],u)),m.active=!1,m.valid=0),e._cphysRagdollDeactivate(c)},ragdollSetDrive(c,u,m){const w=f.get(c);w&&(w.driven=u>0||m),e._cphysRagdollSetDrive(c,u,m?1:0)},ragdollActive:c=>e._cphysRagdollActive(c)!==0,ragdollBodyId:(c,u)=>e._cphysRagdollBodyId(c,u),setOnPhysicsEvent(c){h=c}},frame(c,u){const m=e._cphysFrameBegin(c),w=e._cphysFixedDt();for(let L=0;L<m;L++)u&&(y(e._cphysPullBodies(gs)),x(e._cphysPullCharacters(gs)),u(w)),e._cphysStep();e._cphysFrameEnd(),y(e._cphysPullBodies(ps)),x(e._cphysPullCharacters(ps));const _=e._cphysEventCount();if(_>0&&h){const L=e._cphysEventData()>>2,z=Array.from(e.HEAPU32.subarray(L,L+_*3));for(let N=0;N<_;N++)h(z[N*3],z[N*3+1],z[N*3+2])}},syncRagdolls(c){if(f.size!==0){for(const[u,m]of f){const w=m.prev;m.prev=m.cur,m.cur=w;for(let _=0;_<m.entities.length;_++)Mr(t.world(m.entities[_]),m.cur,_*lt);c>1e-5&&(m.dt=c),m.valid<2&&m.valid++,m.active&&m.driven&&ct(e,m.cur,_=>e._cphysRagdollSetTarget(u,_))}y(e._cphysPullRagdolls())}},applyRootMotion(c,u,m,w,_){for(let L=c;L;L=t.parentOf(L)){const z=e._cphysCharacterForEntity(L);if(z){if(e._cphysCharacterSetExternalVelocity(z,w>0?u/w:0,w>0?m/w:0),_!==0){const N=t.get(L);N&&(_l(N.m,_),t.localMatrixChanged(L))}return!0}}return!1},dispose(){e._cphysShutdown(),e._cphysSetParentLookup(0),e.removeFunction(v),e._free(r),e._free(n),e._free(s),i&&e._free(i),a.clear(),f.clear()}}}const ws={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,Ms=Fe(1/3),Fl=Fe(1/6),bs=Fe(2/3),Tl=Fe(3.14159265),Pl=Fe(.9),yn=t=>t===32||t>=9&&t<=13,Ir=t=>t>=48&&t<=57,Hr=t=>t>=65&&t<=90?t+32:t,As=t=>{const e=Hr(t);return e>=97&&e<=122},Rl=t=>{const e=Hr(t);return e>=48&&e<=57?e-48:e>=97&&e<=102?e-87:-1},kt=(t,e,r,n)=>{if(r!==n.length)return!1;for(let s=0;s<r;s++)if(Hr(t.charCodeAt(e+s))!==n.charCodeAt(s))return!1;return!0},Bl=(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&&Ir(t.charCodeAt(n));)n++,s++;if(n<r&&t.charCodeAt(n)===46){let o=n+1;for(;o<r&&Ir(t.charCodeAt(o));)o++,i++;(s>0||i>0)&&(n=o)}if(s===0&&i===0)return 0;if(n<r&&(t.charCodeAt(n)===101||t.charCodeAt(n)===69)){let o=n+1;if(o<r&&(t.charCodeAt(o)===43||t.charCodeAt(o)===45)&&o++,o<r&&Ir(t.charCodeAt(o))){for(;o<r&&Ir(t.charCodeAt(o));)o++;n=o}}return n-e},Ll=(t,e,r)=>{const n=[];let s=e;for(;s<r;){for(;s<r&&(yn(t.charCodeAt(s))||t.charCodeAt(s)===44||t.charCodeAt(s)===47);)s++;if(s>=r)break;const i=Bl(t,s,r);if(i===0||i>=64)return null;let o=Fe(parseFloat(t.slice(s,s+i)));s+=i;let l=!1;if(s<r&&t.charCodeAt(s)===37)l=!0,s++;else if(s<r&&As(t.charCodeAt(s))){const a=s;for(;s<r&&As(t.charCodeAt(s));)s++;const f=s-a;if(!kt(t,a,f,"deg"))if(kt(t,a,f,"rad"))o=Fe(o*180),o=Fe(o/Tl);else if(kt(t,a,f,"turn"))o=Fe(o*360);else if(kt(t,a,f,"grad"))o=Fe(o*Pl);else return null}if(!Number.isFinite(o)||n.length===4)return null;n.push({v:o,percent:l})}return n.length>=3?n:null},Qt=t=>t<0?0:t>1?1:t,nn=(t,e,r)=>{r<0&&(r=Fe(r+1)),r>1&&(r=Fe(r-1));const n=Fe(e-t);return r<Fl?Fe(t+Fe(Fe(n*6)*r)):r<.5?e:r<bs?Fe(t+Fe(Fe(n*Fe(bs-r))*6)):t},sn=(t,e,r,n)=>({r:Fe(t/255),g:Fe(e/255),b:Fe(r/255),a:Fe(n/255)}),Nl=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&&yn(r.charCodeAt(n));)n++;for(;s>n&&yn(r.charCodeAt(s-1));)s--;const i=s-n;if(i===0)return null;if(r.charCodeAt(n)===35){const f=i-1;if(f!==3&&f!==4&&f!==6&&f!==8)return null;const p=[];for(let g=0;g<f;g++){const h=Rl(r.charCodeAt(n+1+g));if(h<0)return null;p.push(h)}return f<=4?sn(p[0]*17,p[1]*17,p[2]*17,f===4?p[3]*17:255):sn(p[0]*16+p[1],p[2]*16+p[3],p[4]*16+p[5],f===8?p[6]*16+p[7]:255)}const o=r.indexOf("(",n);if(o>=0&&o<s&&r.charCodeAt(s-1)===41){const f=Ll(r,o+1,s-1);if(!f)return null;const p=f.length===4?Qt(f[3].percent?Fe(f[3].v/100):f[3].v):1,g=o-n;if(kt(r,n,g,"rgb")||kt(r,n,g,"rgba")){const h=v=>Qt(v.percent?Fe(v.v/100):Fe(v.v/255));return{r:h(f[0]),g:h(f[1]),b:h(f[2]),a:p}}if(kt(r,n,g,"hsl")||kt(r,n,g,"hsla")){let h=f[0].v%360;h<0&&(h=Fe(h+360)),h=Fe(h/360);const v=Qt(Fe(f[1].v/100)),M=Qt(Fe(f[2].v/100));if(v<=0)return{r:M,g:M,b:M,a:p};const d=M<.5?Fe(M*Fe(1+v)):Fe(Fe(M+v)-Fe(M*v)),y=Fe(Fe(2*M)-d);return{r:Qt(nn(y,d,Fe(h+Ms))),g:Qt(nn(y,d,h)),b:Qt(nn(y,d,Fe(h-Ms))),a:p}}return null}if(i>20)return null;let l="";for(let f=n;f<s;f++)l+=String.fromCharCode(Hr(r.charCodeAt(f)));if(!Object.prototype.hasOwnProperty.call(ws,l))return null;const a=ws[l];return sn(a>>>24,a>>>16&255,a>>>8&255,a&255)},Wt=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))},on=Math.fround,Ol=t=>{if(typeof t=="number")return!Number.isInteger(t)||t<0||t>16777215?null:[on((t>>16&255)/255),on((t>>8&255)/255),on((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},ci=t=>{if(typeof t=="string"){const e=Nl(t);return e?[e.r,e.g,e.b,e.a]:null}return Ol(t)},an=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),Il=t=>{throw typeof t=="number"?new RangeError(`Color: ${an(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: ${an(t)} is not a CSS color`):new TypeError(`Color: ${an(t)} is not a color — a string, an 0xRRGGBB number or [r, g, b(, a)] in 0..1`)},zr=t=>ci(t)??Il(t),Ss=t=>{const e=zr(t);return[Wt(e[0]),Wt(e[1]),Wt(e[2]),Wt(e[3])]},Dr=t=>(t<16?"0":"")+t.toString(16),Dl=t=>"#"+Dr(Wt(t[0]))+Dr(Wt(t[1]))+Dr(Wt(t[2]))+Dr(Wt(t[3])),Ul={toRgb01(t){const e=zr(t);return[e[0],e[1],e[2]]},toRgba01(t){return zr(t)},toPackedRgb(t){const e=Ss(t);return e[0]<<16|e[1]<<8|e[2]},toPackedRgba(t){const e=Ss(t);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0},toHexString(t){return Dl(zr(t))},tryParse(t){return ci(t)}},zl=.0025,_s=1,Es=.85,Gl=.13,Vl=.1,Hl=5,kl=8,Cs=15*Math.PI/180,Wl=[[.93,.16,.12],[.42,.9,.16],[.16,.35,1]],$l=[.85,.85,.88],Fs=t=>[t[0]*.5+.5,t[1]*.5+.5,t[2]*.5+.5],Ts=[.941,.396,.243],jl=[.36,.92,.48],Xl=.85,Ke=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],pr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],gr=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],tt=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],xn=(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]],dr=t=>Math.hypot(t[0],t[1],t[2]),vr=t=>{const e=dr(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},hr=(t,e,r,n)=>{const s=tt(e,n);if(Math.abs(s)<1e-6)return null;const i=tt(Ke(r,t),n)/s;return i<=0?null:pr(t,gr(e,i))},Ps=(t,e,r,n,s)=>{const i=Ke(t,r),o=tt(n,e),l=tt(n,i),a=tt(e,i),f=1-o*o,p=Math.abs(f)<1e-8?l:(l-o*a)/f,g=Math.max(0,Math.min(s,p)),h=pr(r,gr(n,g)),v=Math.max(0,tt(Ke(h,t),e));return{dist:dr(Ke(h,pr(t,gr(e,v)))),t:g}},ql=(t,e,r)=>{const n=xn(vr(Ke(t,r)),e),s=xn(e,n);return tt(s,s)<1e-4?vr(Ke(t,r)):vr(s)},Yl=(t,e)=>{const[r,n,s]=t,i=Math.cos(e),o=Math.sin(e),l=1-i,a=new Float32Array(16);return a[0]=l*r*r+i,a[1]=l*r*n+o*s,a[2]=l*r*s-o*n,a[4]=l*r*n-o*s,a[5]=l*n*n+i,a[6]=l*n*s+o*r,a[8]=l*r*s+o*n,a[9]=l*n*s-o*r,a[10]=l*s*s+i,a[15]=1,a},Kl=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,o=t[2]/e,l=t[4]/r,a=t[5]/r,f=t[6]/r,p=t[8]/n,g=t[9]/n,h=t[10]/n,v=s+a+h;let M,d,y,x;if(v>0){const P=.5/Math.sqrt(v+1);x=.25/P,M=(f-g)*P,d=(p-o)*P,y=(i-l)*P}else if(s>a&&s>h){const P=2*Math.sqrt(1+s-a-h);x=(f-g)/P,M=.25*P,d=(l+i)/P,y=(p+o)/P}else if(a>h){const P=2*Math.sqrt(1+a-s-h);x=(p-o)/P,M=(l+i)/P,d=.25*P,y=(g+f)/P}else{const P=2*Math.sqrt(1+h-s-a);x=(i-l)/P,M=(p+o)/P,d=(g+f)/P,y=.25*P}return{position:[t[12],t[13],t[14]],quaternion:[M,d,y,x],scale:[e,r,n]}},Ql=`#version 300 es
|
|
808
|
+
precision highp float;
|
|
809
|
+
in vec3 position;
|
|
810
|
+
in vec3 normal;
|
|
811
|
+
uniform mat4 modelViewMatrix;
|
|
812
|
+
uniform mat4 projectionMatrix;
|
|
813
|
+
uniform mat3 normalMatrix;
|
|
814
|
+
out vec3 vN;
|
|
815
|
+
void main() {
|
|
816
|
+
vN = normalize(normalMatrix * normal);
|
|
817
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
818
|
+
}
|
|
819
|
+
`,Zl=`#version 300 es
|
|
820
|
+
precision highp float;
|
|
821
|
+
in vec3 vN;
|
|
822
|
+
uniform vec3 uColor;
|
|
823
|
+
out vec4 fragColor;
|
|
824
|
+
void main() { fragColor = vec4(uColor * (0.72 + 0.28 * abs(vN.z)), 1.0); }
|
|
825
|
+
`,Jl=`#version 300 es
|
|
826
|
+
precision highp float;
|
|
827
|
+
in vec3 position;
|
|
828
|
+
uniform mat4 modelMatrix;
|
|
829
|
+
uniform mat4 modelViewMatrix;
|
|
830
|
+
uniform mat4 projectionMatrix;
|
|
831
|
+
out vec3 vWorld;
|
|
832
|
+
void main() {
|
|
833
|
+
vWorld = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
834
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
835
|
+
}
|
|
836
|
+
`,ec=`#version 300 es
|
|
837
|
+
precision highp float;
|
|
838
|
+
in vec3 vWorld;
|
|
839
|
+
uniform vec3 uColor;
|
|
840
|
+
uniform vec3 uOrigin;
|
|
841
|
+
uniform vec3 uEye;
|
|
842
|
+
uniform float uFull;
|
|
843
|
+
out vec4 fragColor;
|
|
844
|
+
void main() {
|
|
845
|
+
if (uFull < 0.5 && dot(vWorld - uOrigin, uOrigin - uEye) > 0.0) discard;
|
|
846
|
+
fragColor = vec4(uColor, 1.0);
|
|
847
|
+
}
|
|
848
|
+
`,ln=`#version 300 es
|
|
849
|
+
precision highp float;
|
|
850
|
+
in vec3 position;
|
|
851
|
+
uniform mat4 modelViewMatrix;
|
|
852
|
+
uniform mat4 projectionMatrix;
|
|
853
|
+
void main() { gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }
|
|
854
|
+
`,cn=`#version 300 es
|
|
855
|
+
precision highp float;
|
|
856
|
+
uniform vec3 uColor;
|
|
857
|
+
uniform float uAlpha;
|
|
858
|
+
out vec4 fragColor;
|
|
859
|
+
void main() { fragColor = vec4(uColor * uAlpha, uAlpha); }
|
|
860
|
+
`,tc=`#version 300 es
|
|
861
|
+
in vec2 position;
|
|
862
|
+
in vec2 uv;
|
|
863
|
+
out vec2 vUv;
|
|
864
|
+
void main() { vUv = uv; gl_Position = vec4(position, 0.0, 1.0); }
|
|
865
|
+
`,rc=`#version 300 es
|
|
866
|
+
precision highp float;
|
|
867
|
+
in vec2 vUv;
|
|
868
|
+
uniform sampler2D tMask;
|
|
869
|
+
uniform vec2 uTexel;
|
|
870
|
+
uniform vec3 uColor;
|
|
871
|
+
out vec4 fragColor;
|
|
872
|
+
void main() {
|
|
873
|
+
float center = texture(tMask, vUv).r;
|
|
874
|
+
float edge = 0.0;
|
|
875
|
+
for (int x = -2; x <= 2; x++) {
|
|
876
|
+
for (int y = -2; y <= 2; y++) {
|
|
877
|
+
edge = max(edge, texture(tMask, vUv + vec2(float(x), float(y)) * uTexel).r);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
float a = clamp(edge - center, 0.0, 1.0);
|
|
881
|
+
if (a < 0.02) discard;
|
|
882
|
+
fragColor = vec4(uColor * a, a);
|
|
883
|
+
}
|
|
884
|
+
`,nc=t=>{const{gl:e,renderer:r,canvas:n,camera:s,core:i}=t;let o={},l=!1,a=null,f=null,p="global";const g=.1,h=.22,v=[],M=new mt;{const Q=[];for(let K=-10;K<=10;K++)K!==0&&Q.push(K,0,-10,K,0,10,-10,0,K,10,0,K);const H=(K,oe)=>{const re=new Ue(e,{vertex:ln,fragment:cn,uniforms:{uColor:{value:[1,1,1]},uAlpha:{value:oe}},transparent:!0});re.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),v.push(re);const le=new ht(e,{position:{size:3,data:Float32Array.from(K)}}),he=new et(e,{geometry:le,program:re,mode:e.LINES});return he.frustumCulled=!1,he};M.addChild(H(Q,g)),M.addChild(H([-10,.001,0,10,.001,0,0,.001,-10,0,.001,10],h))}let d=-1;const y=G=>{const H=.2126*(G[0]??0)+.7152*(G[1]??0)+.0722*(G[2]??0)>.5?0:1;if(H!==d){d=H;for(const K of v)K.uniforms.uColor.value=[H,H,H]}},x=new Ue(e,{vertex:Ql,fragment:Zl,uniforms:{uColor:{value:[1,1,1]}}}),P=new Ue(e,{vertex:Jl,fragment:ec,uniforms:{uColor:{value:[1,1,1]},uOrigin:{value:[0,0,0]},uEye:{value:[0,0,0]},uFull:{value:0}}});let B=null,T=null;const E=new mt;E.matrixAutoUpdate=!1;const c=(G,Q,H=x)=>(G._axis=Q,G.frustumCulled=!1,G.onBeforeRender(()=>{const K=T?T.axis:B,oe=Q===3?$l:Wl[Q];H.uniforms.uColor.value=K===Q?Fs(oe):oe}),G),u=(G,Q)=>{const H=new mt;return Q===0?H.rotation.z=-Math.PI/2:Q===2&&(H.rotation.x=Math.PI/2),H.setParent(G),H},m=new mt,w=new mt,_=new mt;for(const G of[m,w,_])G.setParent(E);{const G=new Kn(e,{radiusTop:.014,radiusBottom:.014,height:.78,radialSegments:6}),Q=new Kn(e,{radiusTop:.001,radiusBottom:.065,height:.26,radialSegments:12}),H=new Yn(e,{width:.1,height:.1,depth:.1}),K=new Yn(e,{width:.14,height:.14,depth:.14}),oe=new ha(e,{radius:Es,tube:.02,radialSegments:8,tubularSegments:64});for(let re=0;re<3;re++){const le=u(m,re),he=c(new et(e,{geometry:G,program:x}),re);he.position.y=.39;const pe=c(new et(e,{geometry:Q,program:x}),re);pe.position.y=.87,le.addChild(he),le.addChild(pe);const we=u(_,re),_e=c(new et(e,{geometry:G,program:x}),re);_e.position.y=.39;const ge=c(new et(e,{geometry:H,program:x}),re);ge.position.y=.83,we.addChild(_e),we.addChild(ge);const Me=c(new et(e,{geometry:oe,program:P}),re,P);re===0?Me.rotation.y=Math.PI/2:re===1&&(Me.rotation.x=Math.PI/2),w.addChild(Me)}_.addChild(c(new et(e,{geometry:K,program:x}),3))}const L=()=>{if(a===null||f===null||!i.entities.has(a))return null;const G=i.activeSceneId(),Q=i.scenes.get(G);if(!Q||Q.camera===void 0)return null;const H=i.worldMatrixF(a),K=[H[12],H[13],H[14]],re=p==="local"||f==="scale"?[0,1,2].map(we=>vr([H[we*4],H[we*4+1],H[we*4+2]])):[[1,0,0],[0,1,0],[0,0,1]],le=i.worldMatrixF(Q.camera),he=[le[12],le[13],le[14]],pe=dr(Ke(K,he))||1;return{origin:K,axes:re,scale:pe*zl*i.projectionOf(G).fov,camPos:he,sceneId:G}},z=()=>{const G=L();if(!G)return!1;const Q=E.matrix;for(let K=0;K<3;K++)Q[K]=G.axes[0][K]*G.scale,Q[4+K]=G.axes[1][K]*G.scale,Q[8+K]=G.axes[2][K]*G.scale,Q[12+K]=G.origin[K];Q[3]=0,Q[7]=0,Q[11]=0,Q[15]=1,E.worldMatrixNeedsUpdate=!0,m.visible=f==="translate",w.visible=f==="rotate",_.visible=f==="scale";const H=P.uniforms;H.uOrigin.value=G.origin,H.uEye.value=G.camPos,H.uFull.value=T&&f==="rotate"?1:0;for(const K of[m,w,_])K.traverse(oe=>{oe._axis!==void 0&&(oe.visible=T===null||oe._axis===T.axis)});return!0},N=(G,Q)=>{const H=L();if(!H)return null;const{origin:K,dir:oe}=t.getViewRay(H.sceneId,G,Q),re=Vl*H.scale;if(f==="rotate"){const pe=vr(Ke(H.origin,H.camPos));let we=null,_e=1/0;for(let ge=0;ge<3;ge++){const Me=hr(K,oe,H.origin,H.axes[ge]);if(!Me||tt(Ke(Me,H.origin),pe)>0)continue;const Be=Math.abs(dr(Ke(Me,H.origin))-Es*H.scale),Te=dr(Ke(Me,K));Be<re&&Te<_e&&(we=ge,_e=Te)}return we}if(f==="scale"){const{dist:pe}=Ps(K,oe,H.origin,vr(oe),0);if(pe<Gl*H.scale)return 3}let le=null,he=re;for(let pe=0;pe<3;pe++){const{dist:we}=Ps(K,oe,H.origin,H.axes[pe],(_s+.05)*H.scale);we<=he&&(he=we,le=pe)}return le},$=G=>{const Q=n.getBoundingClientRect(),H=Cn(n);return[(G.clientX-Q.left)/H,(G.clientY-Q.top)/H]},k=(G,Q)=>{const H=L();if(!H||a===null)return!1;const K=a,oe=i.ent(K),re=Float32Array.from(oe.m),le=oe.parent!==0?i.worldMatrixF(oe.parent):$e(),he=Ft(Float32Array.from(le)),pe=wt(new Float32Array(16),le,re),[we]=$(Q);let _e=null;if(G===3)_e=Pe=>{const[Xe]=$(Pe),He=Math.max(.01,1+(Xe-we)/150),ke=Float32Array.from(re);for(let nt=0;nt<3;nt++)for(let it=0;it<3;it++)ke[nt*4+it]*=He;i.methods.setMatrix(K,ke)};else if(f==="rotate"){const Pe=H.axes[G],{origin:Xe,dir:He}=t.getViewRay(H.sceneId,...$(Q)),ke=hr(Xe,He,H.origin,Pe);if(!ke)return!1;const nt=Ke(ke,H.origin);_e=it=>{const bt=t.getViewRay(H.sceneId,...$(it)),gt=hr(bt.origin,bt.dir,H.origin,Pe);if(!gt)return;const st=Ke(gt,H.origin);let ce=Math.atan2(tt(xn(nt,st),Pe),tt(nt,st));it.ctrlKey&&(ce=Math.round(ce/Cs)*Cs);const We=Yl(Pe,ce),ot=[0,0,0];Ct(ot,We,H.origin[0],H.origin[1],H.origin[2],1),We[12]=H.origin[0]-ot[0],We[13]=H.origin[1]-ot[1],We[14]=H.origin[2]-ot[2];const Xt=wt(new Float32Array(16),We,pe),b=oe.parent!==0?wt(new Float32Array(16),he,Xt):Xt;i.methods.setMatrix(K,b)}}else{const Pe=H.axes[G],Xe=ql(H.origin,Pe,H.camPos),{origin:He,dir:ke}=t.getViewRay(H.sceneId,...$(Q)),nt=hr(He,ke,H.origin,Xe);if(!nt)return!1;if(f==="translate"){const it=[pe[12],pe[13],pe[14]];_e=bt=>{const gt=t.getViewRay(H.sceneId,...$(bt)),st=hr(gt.origin,gt.dir,H.origin,Xe);if(!st)return;const ce=tt(Ke(st,nt),Pe),We=pr(it,gr(Pe,ce)),ot=[0,0,0];oe.parent!==0?Ct(ot,he,We[0],We[1],We[2],1):(ot[0]=We[0],ot[1]=We[1],ot[2]=We[2]),i.methods.setPosition(K,ot[0],ot[1],ot[2])}}else _e=it=>{const bt=t.getViewRay(H.sceneId,...$(it)),gt=hr(bt.origin,bt.dir,H.origin,Xe);if(!gt)return;const st=Math.max(.01,1+tt(Ke(gt,nt),Pe)/(_s*H.scale)),ce=Float32Array.from(re);for(let We=0;We<3;We++)ce[G*4+We]*=st;i.methods.setMatrix(K,ce)}}if(!_e)return!1;const ge=n.ownerDocument.defaultView??window,Me=Q.pointerId,Be=Pe=>{Pe.pointerId===Me&&(T==null||T.onMove(Pe))},Te=Pe=>{var He;if(!T)return;const Xe=T;T=null,Xe.cleanup(),Pe?(He=o.onTransformEnd)==null||He.call(o,K,Kl(i.ent(K).m),f):i.methods.setMatrix(K,Xe.startLocal)},Le=Pe=>{Pe.pointerId===Me&&Te(!0)},De=()=>Te(!1),Re=Pe=>{Pe.code==="Escape"&&Te(!1)};return ge.addEventListener("pointermove",Be),ge.addEventListener("pointerup",Le),ge.addEventListener("pointercancel",De),ge.addEventListener("keydown",Re),T={axis:G,startLocal:re,onMove:_e,cleanup:()=>{ge.removeEventListener("pointermove",Be),ge.removeEventListener("pointerup",Le),ge.removeEventListener("pointercancel",De),ge.removeEventListener("keydown",Re)}},!0},J=new ya,Y=(G,Q)=>{var _e,ge;const H=i.activeSceneId(),K=t.sceneRoots.get(H),oe=i.scenes.get(H);if(!K||!oe||oe.camera===void 0)return 0;const{origin:re,dir:le}=t.getViewRay(H,G,Q);J.origin.set(re[0],re[1],re[2]),J.direction.set(le[0],le[1],le[2]);const he=[],pe=[];for(const Me of t.collectMeshes(K)){const Be=(ge=(_e=Me.geometry)==null?void 0:_e.attributes)==null?void 0:ge.position;if(!(Be!=null&&Be.data))continue;const Te=Be.stride&&Be.stride!==Be.size*Be.data.BYTES_PER_ELEMENT;Me.mode===e.TRIANGLES&&!Te?he.push(Me):pe.push(Me)}K.updateMatrixWorld();let we=null;try{for(const Me of J.intersectMeshes(he,{cullFace:!1,includeUV:!1,includeNormal:!1,output:[]}))(!we||Me.hit.distance<we.hit.distance)&&(we=Me)}catch{}try{for(const Me of J.intersectBounds(pe,{output:[]}))(!we||Me.hit.distance<we.hit.distance)&&(we=Me)}catch{}return(we==null?void 0:we._entId)??0};let D=null;const X=G=>{if(G.button!==0||G.shiftKey||T)return;const[Q,H]=$(G),K=N(Q,H);if(K!==null&&k(K,G)){G.preventDefault(),G.stopPropagation(),D=null;return}D={pointerId:G.pointerId,x:G.clientX,y:G.clientY}},V=G=>{var oe;const Q=D;if(D=null,!Q||Q.pointerId!==G.pointerId||Math.abs(G.clientX-Q.x)+Math.abs(G.clientY-Q.y)>Hl)return;const[H,K]=$(G);(oe=o.onPick)==null||oe.call(o,Se(H,K)||Y(H,K))},q=G=>{if(T)return;const[Q,H]=$(G),K=f!==null&&a!==null?N(Q,H):null,oe=K===null&&C.length>0&&Se(Q,H)||null;(K!==B||oe!==R)&&(B=K,R=oe,n.style.cursor=K!==null||oe!==null?"pointer":"")};n.addEventListener("pointerdown",X),n.addEventListener("pointerup",V),n.addEventListener("pointermove",q);const ae=new Ue(e,{vertex:ln,fragment:cn,uniforms:{uColor:{value:jl},uAlpha:{value:Xl}},transparent:!0,depthTest:!1,depthWrite:!1});ae.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const ee=G=>new ht(e,{position:{size:3,data:Float32Array.from(G)}}),se=(G,Q,H,K,oe=32)=>{for(let re=0;re<oe;re++)for(const le of[Math.PI*2*re/oe,Math.PI*2*(re+1)/oe]){const he=Math.cos(le)*Q,pe=Math.sin(le)*Q;K===1?G.push(he,H,pe):K===0?G.push(H,he,pe):G.push(he,pe,H)}},ue=ee((()=>{const G=[],Q=H=>[H&1?1:-1,H&2?1:-1,H&4?1:-1];for(let H=0;H<8;H++)for(const K of[1,2,4])H&K||G.push(...Q(H),...Q(H|K));return G})()),xe=ee((()=>{const G=[];return se(G,1,0,0),se(G,1,0,1),se(G,1,0,2),G})()),me=new Map,je=(G,Q,H)=>{const K=`${G}:${Q}:${H}`;let oe=me.get(K);if(oe)return oe;const re=[];se(re,H,Q,1),se(re,H,-Q,1);for(const[le,he]of[[H,0],[-H,0],[0,H],[0,-H]])re.push(le,-Q,he,le,Q,he);if(G==="capsule")for(const he of[!0,!1])for(const pe of[0,2])for(let we=0;we<12;we++)for(const _e of[Math.PI*we/12,Math.PI*(we+1)/12]){const ge=Math.cos(_e)*H,Me=(he?Q:-Q)+Math.sin(_e)*H*(he?1:-1);pe===0?re.push(ge,Me,0):re.push(0,Me,ge)}return oe=ee(re),me.size>64&&me.clear(),me.set(K,oe),oe},Qe=new mt,A=[],C=[];let R=null;const W=[.81,.83,.87,1],ie=G=>{var Q,H;for(const K of A)K.setParent(null),(H=(Q=K.geometry).remove)==null||H.call(Q);A.length=0,C.length=0,R=null;for(const K of Array.isArray(G)?G:[]){if(!K||!Array.isArray(K.segments)||K.segments.length<6)continue;const[oe,re,le,he]=Ul.tryParse(K.color)??W,pe=[oe,re,le],we=Math.max(0,Math.min(1,Number(K.alpha??1)*he)),_e=new Ue(e,{vertex:ln,fragment:cn,uniforms:{uColor:{value:pe.slice()},uAlpha:{value:we}},transparent:!0,depthTest:!1,depthWrite:!1});_e.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const ge=Math.floor(K.segments.length/6)*6,Me=Float32Array.from(K.segments.slice(0,ge)),Be=new ht(e,{position:{size:3,data:Me}}),Te=new et(e,{geometry:Be,program:_e,mode:e.LINES});Te.frustumCulled=!1,Te.setParent(Qe),A.push(Te);const Le=Number(K.entityId??0);Le>0&&(Te.matrixAutoUpdate=!1,C.push({entityId:Le,mesh:Te,program:_e,color:pe,segments:Me}))}},ne=()=>{for(const G of C){if(!i.entities.has(G.entityId)){G.mesh.visible=!1;continue}G.mesh.visible=!0,G.mesh.matrix.copy(Ge(G.entityId)),G.mesh.worldMatrixNeedsUpdate=!0;const Q=G.entityId===a?Ts:G.entityId===R?Fs(G.color):G.color,H=G.program.uniforms.uColor.value;H[0]=Q[0],H[1]=Q[1],H[2]=Q[2]}},Se=(G,Q)=>{if(C.length===0)return 0;const H=i.activeSceneId(),K=i.scenes.get(H);if(!K||K.camera===void 0)return 0;const{origin:oe,dir:re}=t.getViewRay(H,G,Q),le=n.getBoundingClientRect(),he=Math.max(1,le.height/Cn(n)),pe=2*Math.tan(i.projectionOf(H).fov*Math.PI/360)*kl/he;let we=0,_e=1,ge=1/0;const Me=[0,0,0],Be=[0,0,0];for(const Te of C){if(!i.entities.has(Te.entityId))continue;const Le=Ge(Te.entityId),De=Te.segments;for(let Re=0;Re+5<De.length;Re+=6){for(let S=0;S<3;S++)Me[S]=Le[S]*De[Re]+Le[4+S]*De[Re+1]+Le[8+S]*De[Re+2]+Le[12+S],Be[S]=Le[S]*De[Re+3]+Le[4+S]*De[Re+4]+Le[8+S]*De[Re+5]+Le[12+S];const Pe=Ke(Be,Me),Xe=Ke(Me,oe),He=tt(re,re),ke=tt(re,Pe),nt=tt(Pe,Pe),it=tt(re,Xe),bt=tt(Pe,Xe),gt=He*nt-ke*ke;let st=gt>1e-12?(ke*it-He*bt)/gt:0;st=Math.max(0,Math.min(1,st));const ce=Math.max(0,(it+st*ke)/(He||1)),We=pr(Me,gr(Pe,st)),ot=pr(oe,gr(re,ce));if(ce<=1e-6)continue;const Xt=ce*pe,b=dr(Ke(We,ot))/Xt;b>1||(b<_e-.001||Math.abs(b-_e)<=.001&&ce<ge)&&(we=Te.entityId,_e=b,ge=ce)}}return we};let Ce=[];const Oe=new mt,Ve=[],Ie=[1,1,1],Ge=G=>{const Q=Float32Array.from(i.worldMatrix(G));for(let H=0;H<3;H++){const K=Math.hypot(Q[H*4],Q[H*4+1],Q[H*4+2])||1;Ie[H]=K,Q[H*4]/=K,Q[H*4+1]/=K,Q[H*4+2]/=K}return Q},Ze=(G,Q,H,K,oe=0,re=0,le=0)=>{const he=Float32Array.from(G);he[12]=G[12]+G[0]*oe+G[4]*re+G[8]*le,he[13]=G[13]+G[1]*oe+G[5]*re+G[9]*le,he[14]=G[14]+G[2]*oe+G[6]*re+G[10]*le;for(let pe=0;pe<3;pe++)he[pe]*=Q,he[4+pe]*=H,he[8+pe]*=K;return he},rt=(G,Q)=>{const H=i.entities.get(G);if(H){for(const K of t.drawablesOf(G))K.mode===e.TRIANGLES&&Q.push(K);for(const K of H.children)rt(K,Q)}},ut=new Map,Tt=G=>{const Q=new Map,H=[],K=(le,he,pe)=>{const we=`${le.toFixed(5)},${he.toFixed(5)},${pe.toFixed(5)}`;let _e=Q.get(we);return _e===void 0&&(_e=H.length/3,Q.set(we,_e),H.push(le,he,pe)),_e},oe=new Set;for(let le=0;le+8<G.length;le+=9){const he=K(G[le],G[le+1],G[le+2]),pe=K(G[le+3],G[le+4],G[le+5]),we=K(G[le+6],G[le+7],G[le+8]);for(const[_e,ge]of[[he,pe],[pe,we],[we,he]])oe.add(_e<ge?_e*65536+ge:ge*65536+_e)}const re=[];for(const le of oe){const he=Math.floor(le/65536)*3,pe=le%65536*3;re.push(H[he],H[he+1],H[he+2],H[pe],H[pe+1],H[pe+2])}return new ht(e,{position:{size:3,data:Float32Array.from(re)}})},Nt=G=>{var we,_e;const Q=[];rt(G,Q);const H=Ge(G),K=Q.map(ge=>{var Me;return((Me=ge.geometry)==null?void 0:Me.id)??"?"}).join(",")+"|"+Ie.map(ge=>ge.toFixed(4)).join(","),oe=ut.get(G);if(oe&&oe.key===K)return oe.geometry;const re=Ft(H),le=[];for(const ge of Q){const Me=(_e=(we=ge.geometry)==null?void 0:we.attributes)==null?void 0:_e.position,Be=Me==null?void 0:Me.data;if(!(Be instanceof Float32Array)||Me.size!==3||Me.stride)continue;const Te=wt(new Float32Array(16),re,ge.worldMatrix);for(let Le=0;Le+2<Be.length;Le+=3){const De=Be[Le],Re=Be[Le+1],Pe=Be[Le+2];le.push(Te[0]*De+Te[4]*Re+Te[8]*Pe+Te[12],Te[1]*De+Te[5]*Re+Te[9]*Pe+Te[13],Te[2]*De+Te[6]*Re+Te[10]*Pe+Te[14])}}const he=le.length>=12?El(le):null,pe=he?Tt(he):null;return ut.set(G,{key:K,geometry:pe}),pe},$t=()=>{var Q,H,K;for(const oe of Ve)oe.setParent(null);Ve.length=0;const G=(oe,re)=>{const le=new et(e,{geometry:oe,program:ae,mode:e.LINES});le.frustumCulled=!1,le.matrixAutoUpdate=!1,le.matrix.copy(re),le.setParent(Oe),Ve.push(le)};for(const oe of Ce){if(!i.entities.has(oe.entityId))continue;const re=oe.shape,le=oe.origin,[he,pe,we]=le??[0,0,0];if(re.kind==="box")G(ue,Ze(Ge(oe.entityId),re.half[0],re.half[1],re.half[2],he,pe,we));else if(re.kind==="sphere")G(xe,Ze(Ge(oe.entityId),re.radius,re.radius,re.radius,he,pe,we));else if(re.kind==="cylinder"||re.kind==="capsule")G(je(re.kind,re.halfHeight,re.radius),Ze(Ge(oe.entityId),1,1,1,he,pe,we));else if(re.kind==="mesh"&&re.convex&&Nt(oe.entityId))G(Nt(oe.entityId),Ze(Ge(oe.entityId),1,1,1,he,pe,we));else if(re.kind==="mesh"){const _e=[];rt(oe.entityId,_e);const ge=Ge(oe.entityId),Me=ge[0]*he+ge[4]*pe+ge[8]*we,Be=ge[1]*he+ge[5]*pe+ge[9]*we,Te=ge[2]*he+ge[6]*pe+ge[10]*we;for(const Le of _e){if(!((H=(Q=Le.geometry)==null?void 0:Q.attributes)!=null&&H.position))continue;const De=Float32Array.from(Le.worldMatrix);De[12]+=Me,De[13]+=Be,De[14]+=Te,G(t.wireGeometryFor(Le.geometry),De)}}else{const _e=t.drawablesOf(oe.entityId).find(nt=>nt.mode===e.TRIANGLES);let ge=.5,Me=.5,Be=.5,Te=0,Le=0,De=0;const Re=(K=_e==null?void 0:_e.geometry)==null?void 0:K.bounds;Re&&isFinite(Re.min.x)&&(ge=(Re.max.x-Re.min.x)/2,Me=(Re.max.y-Re.min.y)/2,Be=(Re.max.z-Re.min.z)/2,Te=(Re.max.x+Re.min.x)/2,Le=(Re.max.y+Re.min.y)/2,De=(Re.max.z+Re.min.z)/2);const Pe=Ge(oe.entityId),[Xe,He,ke]=Ie;G(ue,le?Ze(Pe,ge*Xe,Me*He,Be*ke,he,pe,we):Ze(Pe,ge*Xe,Me*He,Be*ke,Te*Xe,Le*He,De*ke))}}return Ve.length>0},Pt=new Ue(e,{vertex:Er(!1),fragment:Cr,uniforms:{modelMatrix:{value:$e()},shadowViewProjection:{value:$e()}},depthTest:!1,depthWrite:!1,cullFace:!1}),pt=new Ue(e,{vertex:Er(!0),fragment:Cr,uniforms:{modelMatrix:{value:$e()},shadowViewProjection:{value:$e()},boneTexture:{value:null},boneTextureSize:{value:4}},depthTest:!1,depthWrite:!1,cullFace:!1});let Ye=null;const xt=new Ue(e,{vertex:tc,fragment:rc,uniforms:{tMask:{value:null},uTexel:{value:[0,0]},uColor:{value:Ts}},depthTest:!1,depthWrite:!1,transparent:!0});xt.setBlendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA);const Rt=new et(e,{geometry:new Qs(e),program:xt}),wr=(G,Q)=>{const H=i.entities.get(G);if(!(!H||!H.visible)){Q.push(...t.drawablesOf(G));for(const K of H.children)wr(K,Q)}},jt=()=>{if(a===null||!i.entities.has(a))return;const G=[];if(wr(a,G),G.length===0)return;(!Ye||Ye.width!==n.width||Ye.height!==n.height)&&(Ye=new Ks(e,{width:Math.max(1,n.width),height:Math.max(1,n.height)}));const Q=wt(new Float32Array(16),s.projectionMatrix,s.viewMatrix);Pt.uniforms.shadowViewProjection.value=Q,pt.uniforms.shadowViewProjection.value=Q,r.bindFramebuffer(Ye),r.setViewport(Ye.width,Ye.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);const H=$e();for(const K of G){const oe=K instanceof Et,re=oe?pt:Pt;re.uniforms.modelMatrix.value=oe?H:K.worldMatrix;const le=K.program;K.program=re,K.draw({}),K.program=le}r.bindFramebuffer({buffer:null}),r.setViewport(n.width,n.height),xt.uniforms.tMask.value=Ye.texture,xt.uniforms.uTexel.value=[1/Ye.width,1/Ye.height],Rt.draw({})},Br=G=>{l&&(y(G),r.render({scene:M,camera:s,clear:!1,frustumCull:!1,sort:!1}))},rr=()=>{jt(),Ce.length>0&&$t()&&r.render({scene:Oe,camera:s,clear:!1,frustumCull:!1,sort:!1}),A.length>0&&(ne(),r.render({scene:Qe,camera:s,clear:!1,frustumCull:!1,sort:!1})),z()&&(r.setDepthMask(!0),e.clear(e.DEPTH_BUFFER_BIT),r.render({scene:E,camera:s,clear:!1,frustumCull:!1,sort:!1}))};let Ot=null;const Ne=new Mn(e,{fov:60,near:.01,far:1e3,aspect:1});return Ne.matrixAutoUpdate=!1,{api:{setGrid(G){l=G===!0},setSelection(G){T&&G!==a&&(T.cleanup(),T=null),a=G&&G>0?G:null},setGizmoMode(G){f=G==="translate"||G==="rotate"||G==="scale"?G:null,B=null},setGizmoSpace(G){p=G==="local"?"local":"global"},setColliders(G){Ce=Array.isArray(G)?G.slice():[]},setGizmos:ie,setPreview(G){Ot=G&&G.entityId>0?G:null},pickAt(G,Q){return Y(G,Q)}},setHandlers(G){o=G??{}},renderScenePass:Br,renderOverlayPass:rr,renderPreviewPass:(G,Q)=>{const H=Ot;if(!H)return;const K=n.width/(n.getBoundingClientRect().width||n.width),oe=Math.round(H.rect[0]*K),re=Math.round(H.rect[1]*K),le=Math.round(H.rect[2]*K),he=Math.round(H.rect[3]*K);if(le<2||he<2)return;const pe=i.worldMatrixF(H.entityId);if(!pe)return;for(let ge=0;ge<16;ge++)Ne.matrix[ge]=pe[ge];Ne.worldMatrixNeedsUpdate=!0,Ne.perspective({fov:H.fov,aspect:le/he,near:H.near,far:H.far}),Ne.updateMatrixWorld();const we=[];for(const ge of H.hide??[])for(const Me of t.drawablesOf(ge))Me.visible&&(Me.visible=!1,we.push(Me));const _e=n.height-re-he;r.bindFramebuffer({buffer:null}),r.setViewport(le,he,oe,_e),e.enable(e.SCISSOR_TEST),e.scissor(oe,_e,le,he),e.clearColor(Q[0]??0,Q[1]??0,Q[2]??0,1),r.enable(e.DEPTH_TEST),r.setDepthMask(!0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),t.renderScene(G,Ne,we.length>0),e.disable(e.SCISSOR_TEST);for(const ge of we)ge.visible=!0;r.setViewport(n.width,n.height)},dispose:()=>{T==null||T.cleanup(),T=null,n.removeEventListener("pointerdown",X),n.removeEventListener("pointerup",V),n.removeEventListener("pointermove",q),n.style.cursor=""}}},sc={value:0},ur=16,ic=600,oc=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])),ac=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]),lc=(t,e)=>{const r=new Map,n=[],s=[],i=[];let o=-1;const l=new Float32Array(16);let a=!0,f=!0;const p=new Map;let g=0;const h=D=>{const X=p.get(D);if(X!==void 0)return X;let V=null;const q=t.getShaderSource(D.vertexShader),ae=t.getShaderSource(D.fragmentShader);if(q&&ae&&q.startsWith("#version")){const ee=q.replace(/^([^\n]*\n)/,`$1#define INSTANCED
|
|
885
|
+
`),se=new Ue(t,{vertex:ee,fragment:ae,uniforms:D.uniforms,transparent:D.transparent,cullFace:D.cullFace,frontFace:D.frontFace,depthTest:D.depthTest,depthWrite:D.depthWrite,depthFunc:D.depthFunc});let ue=!1;se.attributeLocations.forEach((xe,me)=>{me.name==="instanceMatrix"&&(ue=!0)}),ue&&t.getProgramParameter(se.program,t.LINK_STATUS)?V=se:se.remove()}return p.set(D,V),V},v=(D,X)=>{D.transparent=X.transparent,D.cullFace=X.cullFace,D.frontFace=X.frontFace,D.depthTest=X.depthTest,D.depthWrite=X.depthWrite,D.depthFunc=X.depthFunc,D.blendFunc=X.blendFunc,D.blendEquation=X.blendEquation},M=(D,X)=>{const V={};for(const[ae,ee]of Object.entries(D.attributes))V[ae]={size:ee.size,data:ee.data,type:ee.type,normalized:ee.normalized,stride:ee.stride,offset:ee.offset,buffer:ee.buffer,count:ee.count};V.instanceMatrix={instanced:1,size:16,data:new Float32Array(X*16),usage:t.DYNAMIC_DRAW};const q=new ht(t,V);return q.drawRange.start=D.drawRange.start,q.drawRange.count=D.drawRange.count,q},d=D=>{for(const V of Object.values(D.VAOs))e.deleteVertexArray(V);D.VAOs={};const X=D.attributes.instanceMatrix;X!=null&&X.buffer&&(t.deleteBuffer(X.buffer),X.buffer=null),e.currentGeometry=null},y=(D,X)=>{const V=D.attributes.instanceMatrix;let q=Math.max(ur,V.count);for(;q<X;)q*=2;const ae=new Float32Array(q*16);return ae.set(V.data),d(D),D.instancedCount=0,D.addAttribute("instanceMatrix",{instanced:1,size:16,data:ae,usage:t.DYNAMIC_DRAW}),ae},x=(D,X,V)=>{const q=D.attributes.instanceMatrix;V>0&&(t.bindBuffer(t.ARRAY_BUFFER,q.buffer),e.state.boundBuffer=q.buffer,t.bufferSubData(t.ARRAY_BUFFER,0,X,0,V*16)),D.setInstancedCount(V)},P=(D,X,V)=>{const q=D.program,ae=D._castShadows!==!1,ee=D._receiveShadows!==!1,se=`${D.geometry.id}|${q.id}|${D.mode}|${D.renderOrder}|${ae?1:0}${ee?1:0}${V?1:0}`;let ue=r.get(se);if(!ue){const xe=D.geometry;ue={key:se,source:xe,program:q,twin:X,mode:D.mode,renderOrder:D.renderOrder,castShadows:ae,receiveShadows:ee,flip:V,all:new Float32Array(ur*16),allCount:0,allDirty:!0,geoAll:M(xe,ur),sph:new Float32Array(ur*4),vis:new Float32Array(ur*16),visCount:0,visDirty:!0,geoVis:M(xe,ur),bounds:new Float32Array(6),lastUsed:g},r.set(se,ue)}return ue},B=D=>{var V,q;if(!f||D instanceof Et||D._particles||D.mode===t.POINTS)return null;const X=D.program;return X.transparent||!X.depthTest||!((q=(V=D.geometry)==null?void 0:V.attributes)!=null&&q.position)||D.geometry.isInstanced||X.uniforms.uMorphTex?null:h(X)},T=D=>{const X=D.geometry;return(!X.bounds||X.bounds.radius===1/0)&&X.computeBoundingSphere(),X.bounds&&isFinite(X.bounds.radius)?X.bounds:null},E=(D,X,V,q,ae)=>{const ee=D.frustum;for(let se=0;se<6;se++){const ue=ee[se];if(ue[0]*X+ue[1]*V+ue[2]*q+ue.constant<-ae)return!1}return!0},c=(D,X,V)=>{const q=X*16;let ae=!1;for(let ee=0;ee<16;ee++){const se=V[ee];D[q+ee]!==se&&(D[q+ee]=se,ae=!0)}return ae},u=D=>{const X=D.source;X.bounds||X.computeBoundingBox();const V=D.bounds;if(V[0]=V[1]=V[2]=1/0,V[3]=V[4]=V[5]=-1/0,!X.bounds||!isFinite(X.bounds.min.x))return;const{min:q,max:ae}=X.bounds,ee=[0,0,0];for(let se=0;se<D.allCount;se++){const ue=D.all.subarray(se*16,se*16+16);for(let xe=0;xe<8;xe++){Ct(ee,ue,xe&1?ae.x:q.x,xe&2?ae.y:q.y,xe&4?ae.z:q.z,1);for(let me=0;me<3;me++)ee[me]<V[me]&&(V[me]=ee[me]),ee[me]>V[me+3]&&(V[me+3]=ee[me])}}},m=[0,0,0],w=D=>{g++,s.length=0,i.length=0;for(const X of r.values())X.allCount=0;D.traverse(X=>{if(!X.visible)return!0;if(!X.draw)return!1;const V=X.worldMatrix,q=B(X);if(!q)return s.push(X),X._castShadows!==!1&&i.push(X),!1;const ae=!!X.program.cullFace&&ac(V)<0,ee=P(X,q,ae);ee.lastUsed=g;const se=ee.allCount;if(se*16>=ee.all.length){ee.all=y(ee.geoAll,se+1);const me=new Float32Array(ee.all.length/4);me.set(ee.sph),ee.sph=me}c(ee.all,se,V)&&(ee.allDirty=!0);const ue=T(X),xe=se*4;return ue&&X.frustumCulled?(Ct(m,V,ue.center.x,ue.center.y,ue.center.z,1),ee.sph[xe]=m[0],ee.sph[xe+1]=m[1],ee.sph[xe+2]=m[2],ee.sph[xe+3]=ue.radius*oc(V)):ee.sph[xe+3]=-1,ee.allCount++,!1});for(const[X,V]of r)V.allCount!==V.geoAll.instancedCount&&(V.allDirty=!0),V.allDirty&&(x(V.geoAll,V.all,V.allCount),u(V),V.allDirty=!1),V.allCount===0&&g-V.lastUsed>ic&&(d(V.geoAll),d(V.geoVis),r.delete(X))},_=(D,X)=>{D.updateFrustum();for(const V of r.values()){V.visCount=0;const q=V.allCount;for(let ae=0;ae<q;ae++){const ee=ae*4;if(X&&V.sph[ee+3]>=0&&!E(D,V.sph[ee],V.sph[ee+1],V.sph[ee+2],V.sph[ee+3]))continue;const se=V.visCount;se*16>=V.vis.length&&(V.vis=y(V.geoVis,se+1));const ue=ae*16,xe=se*16;for(let me=0;me<16;me++){const je=V.all[ue+me];V.vis[xe+me]!==je&&(V.vis[xe+me]=je,V.visDirty=!0)}V.visCount++}V.visCount!==V.geoVis.instancedCount&&(V.visDirty=!0),V.visDirty&&(x(V.geoVis,V.vis,V.visCount),V.visDirty=!1)}n.length=0;for(const V of s)X&&V.frustumCulled&&!D.frustumIntersectsMesh(V)||n.push(V)},L=(D,X,V,q=-2,ae=!1)=>{const ee=ae||q!==o;ee&&(w(D),o=q),X.updateMatrixWorld();const se=X.projectionViewMatrix;let ue=V!==a;for(let xe=0;xe<16&&!ue;xe++)l[xe]!==se[xe]&&(ue=!0);if(!(!ee&&!ue)){_(X,V);for(let xe=0;xe<16;xe++)l[xe]=se[xe];a=V}},z=()=>[...r.values()].sort((D,X)=>D.renderOrder-X.renderOrder);return{collect:L,drawMain:(D,X)=>{for(const se of z()){if(se.visCount===0)continue;const ue=se.twin.uniforms;(ue.projectionMatrix??(ue.projectionMatrix={value:null})).value=D.projectionMatrix,(ue.viewMatrix??(ue.viewMatrix={value:null})).value=D.viewMatrix,(ue.cameraPosition??(ue.cameraPosition={value:null})).value=D.worldPosition;const xe=ue.shadowEnabled;xe&&(ue.shadowEnabled=se.receiveShadows?X:sc),v(se.twin,se.program),se.twin.use({flipFaces:se.flip}),se.geoVis.draw({mode:se.mode,program:se.twin}),xe&&(ue.shadowEnabled=xe)}const V=[],q=[],ae=[],ee=D.projectionViewMatrix;for(const se of n){if(se.program.transparent?se.program.depthTest?q.push(se):ae.push(se):V.push(se),se.zDepth=0,se.renderOrder!==0||!se.program.depthTest)continue;const ue=se.worldMatrix,xe=ue[12],me=ue[13],je=ue[14],Qe=ee[3]*xe+ee[7]*me+ee[11]*je+ee[15]||1;se.zDepth=(ee[2]*xe+ee[6]*me+ee[10]*je+ee[14])/Qe}V.sort(e.sortOpaque),q.sort(e.sortTransparent),ae.sort(e.sortUI);for(const se of V)se.draw({camera:D});for(const se of q)se.draw({camera:D});for(const se of ae)se.draw({camera:D})},drawShadow:D=>{for(const X of r.values())!X.castShadows||X.allCount===0||(D.use({flipFaces:X.flip}),X.geoAll.draw({mode:X.mode,program:D}))},casterBounds:(D,X)=>{for(const V of r.values())if(!(!V.castShadows||V.allCount===0||!isFinite(V.bounds[0])))for(let q=0;q<3;q++)V.bounds[q]<D[q]&&(D[q]=V.bounds[q]),V.bounds[q+3]>X[q]&&(X[q]=V.bounds[q+3])},isBatched:D=>B(D)!==null,dispose:()=>{for(const D of r.values())d(D.geoAll),d(D.geoVis);r.clear();for(const D of p.values())D==null||D.remove();p.clear()},setEnabled:D=>{f=D,o=-1},singles:n,casterSingles:i,stats:()=>{let D=0,X=0,V=0;for(const q of r.values())q.allCount>0&&(V++,D+=q.allCount,X+=q.visCount);return{batches:V,instances:D,visible:X,singles:n.length}}}},cc=t=>t.getExtension("EXT_color_buffer_float")!==null,hc=(t,e)=>{const r=t.getInternalformatParameter(t.RENDERBUFFER,t.RGBA16F,t.SAMPLES);let n=0;for(const s of r??[])s<=e&&s>n&&(n=s);return n},hi=(t,e,r)=>{const n=new qe(t,{width:e,height:r,internalFormat:t.RGBA16F,format:t.RGBA,type:t.HALF_FLOAT,generateMipmaps:!1,minFilter:t.LINEAR,magFilter:t.LINEAR,wrapS:t.CLAMP_TO_EDGE,wrapT:t.CLAMP_TO_EDGE,flipY:!1});return n.update(),n},ui=(t,e,r)=>{const n=t.createFramebuffer();return e.bindFramebuffer({buffer:n}),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r.texture,0),n},uc=(t,e,r,n,s)=>{const i=hi(t,r,n),o=ui(t,e,i),l=[],a=(h,v)=>{const M=t.createRenderbuffer();l.push(M),t.bindRenderbuffer(t.RENDERBUFFER,M),s>0?t.renderbufferStorageMultisample(t.RENDERBUFFER,s,v,r,n):t.renderbufferStorage(t.RENDERBUFFER,v,r,n),t.framebufferRenderbuffer(t.FRAMEBUFFER,h,t.RENDERBUFFER,M)};let f=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE,p=o;s>0&&(p=t.createFramebuffer(),e.bindFramebuffer({buffer:p}),a(t.COLOR_ATTACHMENT0,t.RGBA16F)),a(t.DEPTH_ATTACHMENT,t.DEPTH_COMPONENT24),f&&(f=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE),t.bindRenderbuffer(t.RENDERBUFFER,null),e.bindFramebuffer({buffer:null});const g=()=>{p!==o&&t.deleteFramebuffer(p),t.deleteFramebuffer(o);for(const h of l)t.deleteRenderbuffer(h);t.deleteTexture(i.texture)};return f?{width:r,height:n,samples:s,texture:i,bindDraw:()=>e.bindFramebuffer({buffer:p}),resolve:()=>{p!==o&&(t.bindFramebuffer(t.READ_FRAMEBUFFER,p),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,o),t.blitFramebuffer(0,0,r,n,0,0,r,n,t.COLOR_BUFFER_BIT,t.NEAREST),t.bindFramebuffer(t.FRAMEBUFFER,null),e.state.framebuffer=null)},dispose:g}:(g(),null)},Rs=384,fc=12,dc=(t,e,r,n)=>{const s=Rs,i=Rs*t/Math.max(1,e),o=Math.max(1,Math.trunc(Math.max(i,s))),l=Math.floor(Math.log2(o))+1,a=Math.max(1,Math.min(Math.floor(r)||1,l,fc)),f=[];if(n<2){let p=t,g=e;for(;2*i<p||2*s<g;)p=Math.max(1,Math.floor(p/2)),g=Math.max(1,Math.floor(g/2)),f.push({width:p,height:g})}return{width:Math.max(1,Math.floor(i)),height:Math.max(1,Math.floor(s)),levels:a,preDownscales:f}},mc=(t,e,r)=>({width:Math.max(1,t>>r),height:Math.max(1,e>>r)}),pc=`#version 300 es
|
|
886
|
+
in vec2 position;
|
|
887
|
+
in vec2 uv;
|
|
888
|
+
out vec2 vUv;
|
|
889
|
+
void main() {
|
|
890
|
+
vUv = uv;
|
|
891
|
+
gl_Position = vec4(position, 0.0, 1.0);
|
|
892
|
+
}
|
|
893
|
+
`,kr=`#version 300 es
|
|
894
|
+
precision highp float;
|
|
895
|
+
precision highp sampler2D;
|
|
896
|
+
in vec2 vUv;
|
|
897
|
+
uniform sampler2D source;
|
|
898
|
+
out vec4 fragColor;
|
|
899
|
+
`,gc=`${kr}
|
|
900
|
+
uniform float uThreshold;
|
|
901
|
+
uniform float uFireflies;
|
|
902
|
+
uniform float uInvHighlight;
|
|
903
|
+
|
|
904
|
+
float max3(const vec3 v) { return max(v.x, max(v.y, v.z)); }
|
|
905
|
+
|
|
906
|
+
void threshold(inout vec3 c) {
|
|
907
|
+
// threshold everything below 1.0
|
|
908
|
+
c = max(vec3(0.0), c - 1.0);
|
|
909
|
+
// crush everything above 1
|
|
910
|
+
float f = max3(c);
|
|
911
|
+
c *= 1.0 / (1.0 + f * uInvHighlight);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
void main() {
|
|
915
|
+
vec2 size = vec2(textureSize(source, 0));
|
|
916
|
+
vec2 texelSize = vec2(1.0) / size;
|
|
917
|
+
|
|
918
|
+
// Castaño, 2013, "Shadow Mapping Summary Part 1"
|
|
919
|
+
// 3x3 gaussian filter with 4 linear samples
|
|
920
|
+
vec2 offset = vec2(0.5);
|
|
921
|
+
vec2 uv = (vUv * size) + offset;
|
|
922
|
+
vec2 base = (floor(uv) - offset) * texelSize;
|
|
923
|
+
vec2 st = fract(uv);
|
|
924
|
+
vec2 uw = vec2(3.0 - 2.0 * st.x, 1.0 + 2.0 * st.x);
|
|
925
|
+
vec2 vw = vec2(3.0 - 2.0 * st.y, 1.0 + 2.0 * st.y);
|
|
926
|
+
vec2 u = vec2((2.0 - st.x) / uw.x - 1.0, st.x / uw.y + 1.0) * texelSize.x;
|
|
927
|
+
vec2 v = vec2((2.0 - st.y) / vw.x - 1.0, st.y / vw.y + 1.0) * texelSize.y;
|
|
928
|
+
vec3 c0 = textureLod(source, base + vec2(u.x, v.x), 0.0).rgb;
|
|
929
|
+
vec3 c1 = textureLod(source, base + vec2(u.y, v.x), 0.0).rgb;
|
|
930
|
+
vec3 c2 = textureLod(source, base + vec2(u.x, v.y), 0.0).rgb;
|
|
931
|
+
vec3 c3 = textureLod(source, base + vec2(u.y, v.y), 0.0).rgb;
|
|
932
|
+
|
|
933
|
+
float w0 = uw.x * vw.x * (1.0 / 16.0);
|
|
934
|
+
float w1 = uw.y * vw.x * (1.0 / 16.0);
|
|
935
|
+
float w2 = uw.x * vw.y * (1.0 / 16.0);
|
|
936
|
+
float w3 = uw.y * vw.y * (1.0 / 16.0);
|
|
937
|
+
|
|
938
|
+
if (uFireflies > 0.0) {
|
|
939
|
+
w0 /= (1.0 + max3(c0));
|
|
940
|
+
w1 /= (1.0 + max3(c1));
|
|
941
|
+
w2 /= (1.0 + max3(c2));
|
|
942
|
+
w3 /= (1.0 + max3(c3));
|
|
943
|
+
float w = 1.0 / (w0 + w1 + w2 + w3);
|
|
944
|
+
w0 *= w;
|
|
945
|
+
w1 *= w;
|
|
946
|
+
w2 *= w;
|
|
947
|
+
w3 *= w;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
vec3 c = c0 * w0 + c1 * w1 + c2 * w2 + c3 * w3;
|
|
951
|
+
|
|
952
|
+
if (uThreshold > 0.0) {
|
|
953
|
+
threshold(c);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
fragColor = vec4(c, 1.0);
|
|
957
|
+
}
|
|
958
|
+
`,vc=`${kr}
|
|
959
|
+
vec3 box4x4(vec3 s0, vec3 s1, vec3 s2, vec3 s3) {
|
|
960
|
+
return (s0 + s1 + s2 + s3) * 0.25;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
void main() {
|
|
964
|
+
vec2 uv = vUv;
|
|
965
|
+
|
|
966
|
+
// see SIGGRAPH 2014: Advances in Real-Time Rendering
|
|
967
|
+
// "Next Generation Post-Processing in Call of Duty Advanced Warfare"
|
|
968
|
+
// Jorge Jimenez
|
|
969
|
+
vec3 c = textureLod(source, uv, 0.0).rgb;
|
|
970
|
+
|
|
971
|
+
// The offsets below are in "source" texture space
|
|
972
|
+
vec3 lt = textureLodOffset(source, uv, 0.0, ivec2(-1, -1)).rgb;
|
|
973
|
+
vec3 rt = textureLodOffset(source, uv, 0.0, ivec2( 1, -1)).rgb;
|
|
974
|
+
vec3 rb = textureLodOffset(source, uv, 0.0, ivec2( 1, 1)).rgb;
|
|
975
|
+
vec3 lb = textureLodOffset(source, uv, 0.0, ivec2(-1, 1)).rgb;
|
|
976
|
+
|
|
977
|
+
vec3 lt2 = textureLodOffset(source, uv, 0.0, ivec2(-2, -2)).rgb;
|
|
978
|
+
vec3 rt2 = textureLodOffset(source, uv, 0.0, ivec2( 2, -2)).rgb;
|
|
979
|
+
vec3 rb2 = textureLodOffset(source, uv, 0.0, ivec2( 2, 2)).rgb;
|
|
980
|
+
vec3 lb2 = textureLodOffset(source, uv, 0.0, ivec2(-2, 2)).rgb;
|
|
981
|
+
|
|
982
|
+
vec3 l = textureLodOffset(source, uv, 0.0, ivec2(-2, 0)).rgb;
|
|
983
|
+
vec3 t = textureLodOffset(source, uv, 0.0, ivec2( 0, -2)).rgb;
|
|
984
|
+
vec3 r = textureLodOffset(source, uv, 0.0, ivec2( 2, 0)).rgb;
|
|
985
|
+
vec3 b = textureLodOffset(source, uv, 0.0, ivec2( 0, 2)).rgb;
|
|
986
|
+
|
|
987
|
+
// five h4x4 boxes
|
|
988
|
+
vec3 c0, c1;
|
|
989
|
+
|
|
990
|
+
// common case
|
|
991
|
+
c0 = box4x4(lt, rt, rb, lb);
|
|
992
|
+
c1 = box4x4(c, l, t, lt2);
|
|
993
|
+
c1 += box4x4(c, r, t, rt2);
|
|
994
|
+
c1 += box4x4(c, r, b, rb2);
|
|
995
|
+
c1 += box4x4(c, l, b, lb2);
|
|
996
|
+
|
|
997
|
+
// weighted average of the five boxes
|
|
998
|
+
fragColor = vec4(c0 * 0.5 + c1 * 0.125, 1.0);
|
|
999
|
+
}
|
|
1000
|
+
`,yc=`${kr}
|
|
1001
|
+
void main() {
|
|
1002
|
+
vec2 uv = vUv;
|
|
1003
|
+
vec2 size = vec2(1.0) / vec2(textureSize(source, 0));
|
|
1004
|
+
|
|
1005
|
+
float o = 1.5 + 0.261629;
|
|
1006
|
+
float wa = 7.46602 / 32.0;
|
|
1007
|
+
float wb = 1.0 - wa * 2.0;
|
|
1008
|
+
float wab = wa * wb;
|
|
1009
|
+
float waa = wa * wa;
|
|
1010
|
+
float wbb = wb * wb;
|
|
1011
|
+
|
|
1012
|
+
size *= o;
|
|
1013
|
+
|
|
1014
|
+
vec3 c = textureLod(source, uv + vec2(0.0) , 0.0).rgb;
|
|
1015
|
+
vec3 l = textureLod(source, uv + vec2(-size.x, 0.0), 0.0).rgb;
|
|
1016
|
+
vec3 r = textureLod(source, uv + vec2( size.x, 0.0), 0.0).rgb;
|
|
1017
|
+
vec3 b = textureLod(source, uv + vec2( 0.0,-size.y), 0.0).rgb;
|
|
1018
|
+
vec3 t = textureLod(source, uv + vec2( 0.0, size.y), 0.0).rgb;
|
|
1019
|
+
vec3 lb = textureLod(source, uv + vec2(-size.x,-size.y), 0.0).rgb;
|
|
1020
|
+
vec3 rb = textureLod(source, uv + vec2( size.x,-size.y), 0.0).rgb;
|
|
1021
|
+
vec3 lt = textureLod(source, uv + vec2(-size.x, size.y), 0.0).rgb;
|
|
1022
|
+
vec3 rt = textureLod(source, uv + vec2( size.x, size.y), 0.0).rgb;
|
|
1023
|
+
|
|
1024
|
+
fragColor = vec4(
|
|
1025
|
+
(c * wbb +
|
|
1026
|
+
(l * wab +
|
|
1027
|
+
(r * wab +
|
|
1028
|
+
(b * wab +
|
|
1029
|
+
(t * wab +
|
|
1030
|
+
(lb * waa +
|
|
1031
|
+
(rb * waa +
|
|
1032
|
+
(lt * waa +
|
|
1033
|
+
(rt * waa))))))))), 1.0);
|
|
1034
|
+
}
|
|
1035
|
+
`,Bs=t=>`${kr}
|
|
1036
|
+
uniform vec4 resolution;
|
|
1037
|
+
void main() {
|
|
1038
|
+
vec2 uv = vUv;
|
|
1039
|
+
${t?`
|
|
1040
|
+
// see SIGGRAPH 2014: Advances in Real-Time Rendering
|
|
1041
|
+
// "Next Generation Post-Processing in Call of Duty Advanced Warfare"
|
|
1042
|
+
// Jorge Jimenez
|
|
1043
|
+
const float radius = 1.0;
|
|
1044
|
+
vec4 d = vec4(resolution.zw, -resolution.zw) * radius;
|
|
1045
|
+
vec3 c0, c1;
|
|
1046
|
+
c0 = textureLod(source, uv + d.zw, 0.0).rgb;
|
|
1047
|
+
c0 += textureLod(source, uv + d.xw, 0.0).rgb;
|
|
1048
|
+
c0 += textureLod(source, uv + d.xy, 0.0).rgb;
|
|
1049
|
+
c0 += textureLod(source, uv + d.zy, 0.0).rgb;
|
|
1050
|
+
c0 += 4.0 * textureLod(source, uv, 0.0).rgb;
|
|
1051
|
+
c1 = textureLod(source, uv + vec2(d.z, 0.0), 0.0).rgb;
|
|
1052
|
+
c1 += textureLod(source, uv + vec2(0.0, d.w), 0.0).rgb;
|
|
1053
|
+
c1 += textureLod(source, uv + vec2(d.x, 0.0), 0.0).rgb;
|
|
1054
|
+
c1 += textureLod(source, uv + vec2( 0.0, d.y), 0.0).rgb;
|
|
1055
|
+
fragColor = vec4((c0 + 2.0 * c1) * (1.0 / 16.0), 1.0);
|
|
1056
|
+
`:`
|
|
1057
|
+
vec4 d = vec4(resolution.zw, -resolution.zw) * 0.5;
|
|
1058
|
+
vec3 c;
|
|
1059
|
+
c = textureLod(source, uv + d.zw, 0.0).rgb;
|
|
1060
|
+
c += textureLod(source, uv + d.xw, 0.0).rgb;
|
|
1061
|
+
c += textureLod(source, uv + d.xy, 0.0).rgb;
|
|
1062
|
+
c += textureLod(source, uv + d.zy, 0.0).rgb;
|
|
1063
|
+
fragColor = vec4(c * 0.25, 1.0);
|
|
1064
|
+
`}
|
|
1065
|
+
}
|
|
1066
|
+
`,xc=`#version 300 es
|
|
1067
|
+
precision highp float;
|
|
1068
|
+
precision highp sampler2D;
|
|
1069
|
+
in vec2 vUv;
|
|
1070
|
+
uniform sampler2D uColor;
|
|
1071
|
+
uniform sampler2D uBloom;
|
|
1072
|
+
uniform float uBloomStrength;
|
|
1073
|
+
out vec4 fragColor;
|
|
1074
|
+
${ri}
|
|
1075
|
+
void main() {
|
|
1076
|
+
vec4 color = texelFetch(uColor, ivec2(gl_FragCoord.xy), 0);
|
|
1077
|
+
vec3 hdr = color.rgb + textureLod(uBloom, vUv, 0.0).rgb * uBloomStrength;
|
|
1078
|
+
fragColor = vec4(acesFilmicSrgb(hdr), color.a);
|
|
1079
|
+
}
|
|
1080
|
+
`,wc=(t,e)=>{const r=new Qs(t),n=(E,c,u=!1)=>{const m=new Ue(t,{vertex:pc,fragment:E,uniforms:c,transparent:u,depthTest:!1,depthWrite:!1,cullFace:!1});return u&&m.setBlendFunc(t.ONE,t.ONE),m},s=n(gc,{source:{value:null},uThreshold:{value:0},uFireflies:{value:0},uInvHighlight:{value:0}}),i=n(vc,{source:{value:null}}),o=n(yc,{source:{value:null}}),l=[0,0,0,0],a=n(Bs(!1),{source:{value:null},resolution:{value:l}},!0),f=n(Bs(!0),{source:{value:null},resolution:{value:l}},!0),p=n(xc,{uColor:{value:null},uBloom:{value:null},uBloomStrength:{value:0}});let g=[],h=[],v="";const M=({width:E,height:c})=>{const u=hi(t,E,c);return{width:E,height:c,texture:u,fbo:ui(t,e,u)}},d=()=>{for(const E of[...g,...h])t.deleteFramebuffer(E.fbo),t.deleteTexture(E.texture.texture);g=[],h=[],v=""},y=E=>{const c=`${E.width}x${E.height}/${E.levels}/${E.preDownscales.map(u=>`${u.width}x${u.height}`).join(",")}`;if(c!==v){d(),g=E.preDownscales.map(M);for(let u=0;u<E.levels;u++)h.push(M(mc(E.width,E.height,u)));v=c,e.bindFramebuffer({buffer:null})}},x=(E,c)=>{e.bindFramebuffer({buffer:c.fbo}),e.setViewport(c.width,c.height),E.use(),r.draw({program:E})};return{run:(E,c,u,m)=>{const w=dc(c,u,m.levels,m.quality);y(w);let _=m.threshold;const L=Number.isFinite(m.highlight)&&m.highlight>0?1/m.highlight:0;let z=E;const N=k=>{const J=s.uniforms;J.source.value=z,J.uThreshold.value=J.uFireflies.value=_?1:0,J.uInvHighlight.value=L,x(s,k),_=!1,z=k.texture};for(const k of g)N(k);N(h[0]);for(let k=1;k<w.levels;k++){const J=h[k-1],Y=J.width&1||J.height&1?i:o;Y.uniforms.source.value=J.texture,x(Y,h[k])}const $=m.quality>=2?f:a;for(let k=w.levels-1;k>=1;k--){const J=h[k-1];$.uniforms.source.value=h[k].texture,l[0]=J.width,l[1]=J.height,l[2]=1/J.width,l[3]=1/J.height,x($,J)}return{texture:h[0].texture,levels:w.levels}},compose:(E,c,u,m,w)=>{e.bindFramebuffer({buffer:null}),e.setViewport(m,w);const _=p.uniforms;_.uColor.value=E,_.uBloom.value=c,_.uBloomStrength.value=u,p.use(),r.draw({program:p})},dispose:()=>{d();for(const E of[s,i,o,a,f,p])E.remove();r.remove()}}},Mc=1179937895,bc=1313821514,Ac=t=>{var e,r;try{if(t.byteLength<20)return null;const n=new DataView(t);if(n.getUint32(0,!0)!==Mc)return null;const s=n.getUint32(12,!0);if(n.getUint32(16,!0)!==bc||20+s>t.byteLength)return null;const i=JSON.parse(new TextDecoder("utf-8").decode(new Uint8Array(t,20,s))),o=i.accessors??[],l=i.meshes??[],a=(i.nodes??[]).map(h=>{var d;let v;Array.isArray(h.matrix)&&h.matrix.length===16?v=Float32Array.from(h.matrix):h.translation||h.rotation||h.scale?v=ei(h.translation??[0,0,0],h.rotation??[0,0,0,1],h.scale??[1,1,1]):v=$e();const M={children:h.children??[],matrix:v};if(typeof h.name=="string"&&h.name.length>0&&(M.name=h.name),h.mesh!=null&&l[h.mesh]){const y=l[h.mesh].primitives??[];let x,P;for(const B of y){const T=o[(d=B.attributes)==null?void 0:d.POSITION];if(!(!T||!Array.isArray(T.min)||!Array.isArray(T.max)))if(!x||!P)x=[T.min[0],T.min[1],T.min[2]],P=[T.max[0],T.max[1],T.max[2]];else for(let E=0;E<3;E++)x[E]=Math.min(x[E],T.min[E]),P[E]=Math.max(P[E],T.max[E])}M.mesh={primitives:y.length,min:x,max:P}}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 d,y;let M=0;for(const x of h.samplers??[]){const P=(y=(d=o[x.input])==null?void 0:d.max)==null?void 0:y[0];typeof P=="number"&&P>M&&(M=P)}return{name:typeof h.name=="string"?h.name:`animation_${v}`,duration:M}}),p=i.scene??0,g=((r=(e=i.scenes)==null?void 0:e[p])==null?void 0:r.nodes)??[];return{nodes:a,roots:g,animations:f}}catch{return null}};let Sc=null,bn=null;const _c=()=>Sc??(Sc=Tr(()=>import("./creatorAnim-BOwKr-C1.js"),__vite__mapDeps([3,1]),import.meta.url).then(t=>t.default()).then(t=>bn=t)),fi=()=>bn!==null,yt=(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)}},Ec=(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)}},dt=(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)}},Cc=(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)}},hn=(t,e,r,n,s,i,o,l,a,f,p)=>{const g=s+s,h=i+i,v=o+o,M=s*g,d=s*h,y=s*v,x=i*h,P=i*v,B=o*v,T=l*g,E=l*h,c=l*v,u=t;u[0]=(1-(x+B))*a,u[1]=(d+c)*a,u[2]=(y-E)*a,u[3]=0,u[4]=(d-c)*f,u[5]=(1-(M+B))*f,u[6]=(P+T)*f,u[7]=0,u[8]=(y+E)*p,u[9]=(P-T)*p,u[10]=(1-(M+x))*p,u[11]=0,u[12]=e,u[13]=r,u[14]=n,u[15]=1},Ur=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 o=r!==0?1/r:0,l=n!==0?1/n:0,a=s!==0?1/s:0,f=e[0]*o,p=e[1]*o,g=e[2]*o,h=e[4]*l,v=e[5]*l,M=e[6]*l,d=e[8]*a,y=e[9]*a,x=e[10]*a,P=f+v+x;let B,T,E,c;if(P>0){const u=.5/Math.sqrt(P+1);c=.25/u,B=(M-y)*u,T=(d-g)*u,E=(p-h)*u}else if(f>v&&f>x){const u=2*Math.sqrt(1+f-v-x);c=(M-y)/u,B=.25*u,T=(h+p)/u,E=(d+g)/u}else if(v>x){const u=2*Math.sqrt(1+v-f-x);c=(d-g)/u,B=(h+p)/u,T=.25*u,E=(y+M)/u}else{const u=2*Math.sqrt(1+x-f-v);c=(p-h)/u,B=(d+g)/u,T=(y+M)/u,E=.25*u}return{t:[e[12],e[13],e[14]],r:[B,T,E,c],s:[r,n,s]}},Fc=(t,e)=>{const r=Math.cos(e),n=Math.sin(e),s=t[0],i=t[1],o=t[2],l=t[8],a=t[9],f=t[10];t[0]=s*r-l*n,t[1]=i*r-a*n,t[2]=o*r-f*n,t[8]=s*n+l*r,t[9]=i*n+a*r,t[10]=o*n+f*r};let Ls=!1;const un=t=>typeof t._canimAnimatorLateSolve=="function"?!0:(Ls||(Ls=!0,console.warn("creator-anim: this wasm predates IK chains / sockets — rebuild it (build-wasm.sh + vendor:creator); chains are inert")),!1),fr=19,St={TARGET_X:0,POLE_X:3,HAS_POLE:6,ROT_X:8},Ns=64,br=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Tc(t){const e=bn;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),o=e._malloc(64),l=e._malloc(12),a=e._malloc(12),f=e._malloc(32),p=e._malloc(4),g=e._malloc(4),h=e._malloc(Ns*4),v=[],M=[];let d=null;const y=c=>{const u=c instanceof Uint8Array?c:new Uint8Array(c);return Cc(e,u,m=>e._canimClipsLoad(m,u.length))},x=c=>{e._free(c.trs),e._free(c.write)},P={loadClips(c,u,m){const w=t.getBuffer(c),_=w?y(w):0;if(!_){m(new Error("loadClips: not a GLB with animations"));return}u(_)},createClipFromTracks(c,u){return dt(e,c,m=>yt(e,u,w=>e._canimClipsFromTracks(m,w,u.length)))},getClipSetInfo(c){const u=e._canimClipsCount(c),m=[];for(let w=0;w<u;w++){const _=e._canimClipName(c,w);m.push({name:_?e.UTF8ToString(_):"",duration:e._canimClipDuration(c,w),trackCount:e._canimClipTrackCount(c,w)})}return m},sliceClip(c,u,m,w){return e._canimClipsSlice(c,u,m,w)},deriveClip(c,u,m,w,_){return e._canimClipsDerive(c,u,m?1:0,w,_)},destroyClipSet(c){e._canimClipsDestroy(c)},animatorCreate(c){if(!t.get(c))return 0;const m=[],w=[],_=[],L=[],z=[],N=(X,V)=>{const q=t.get(X);if(!q)return;const ae=m.length;m.push(X),w.push(V),_.push(q.name??""),z.push(q.skinJoint?1:0);const{t:ee,r:se,s:ue}=Ur(q.m);L.push(ee[0],ee[1],ee[2],se[0],se[1],se[2],se[3],ue[0],ue[1],ue[2]);for(const xe of q.children)N(xe,ae)};N(c,-1);const $=m.length,k=e._malloc(Math.max(4,$*4));e.HEAP32.set(w,k>>2);const J=e._malloc(Math.max(1,$));e.HEAPU8.set(z,J);let Y=0;try{Y=dt(e,_.join(`
|
|
1081
|
+
`),X=>yt(e,L,V=>e._canimAnimatorCreate($,k,X,V,J,c)))}finally{e._free(k),e._free(J)}if(!Y)return 0;const D=e._canimAnimatorShadowedNames(Y);return D>0&&console.warn(`[Animator] ${D} 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:m,trs:e._malloc(Math.max(4,$*40)),write:e._malloc(Math.max(1,$)),n:$,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 m=e.HEAPF32,w=e.HEAPU8,_=u.trs>>2;for(let L=0;L<u.n;L++){if(!w[u.write+L])continue;const z=t.get(u.entities[L]);if(!z)continue;const N=_+L*10;hn(z.m,m[N],m[N+1],m[N+2],m[N+3],m[N+4],m[N+5],m[N+6],m[N+7],m[N+8],m[N+9]),t.localMatrixChanged(u.entities[L])}e._canimAnimatorDestroy(c),x(u),r.delete(c)},animatorBind(c,u,m,w){return e._canimAnimatorBind(c,u,m,w)},animatorBindMirror(c,u,m,w){return e._canimAnimatorBindMirror?e._canimAnimatorBindMirror(c,u,m,w):-1},animatorBoundTracks(c,u){return e._canimAnimatorBoundTracks(c,u)},setClipEvents(c,u,m){yt(e,m,w=>e._canimClipsSetEvents(c,u,w,m.length))},animatorSetBlend(c,u,m,w,_,L,z,N){const $=m>1?2:1,k=Math.min(w.length,Math.floor(_.length/$)),J=N&&N.length>=k*2?N:null;Ec(e,w,Y=>yt(e,_,D=>{J?yt(e,J,X=>e._canimAnimatorSetBlend(c,u,$,Y,D,X,k,L,z)):e._canimAnimatorSetBlend(c,u,$,Y,D,0,k,L,z)}))},animatorSetBlendValue(c,u,m,w){e._canimAnimatorSetBlendValue(c,u,m,w)},animatorSlotSetTurn(c,u,m,w){e._canimAnimatorSlotSetTurn(c,u,m,w?1:0)},animatorSlotSetWindow(c,u,m,w){e._canimAnimatorSlotSetWindow(c,u,m,w)},animatorPlay(c,u,m,w,_,L,z){e._canimAnimatorPlay(c,u,m?1:0,w,_,L,z?1:0)},animatorStop(c,u,m,w){e._canimAnimatorStop(c,u,m,w)},animatorSeek(c,u,m){e._canimAnimatorSeek(c,u,m)},animatorGetSlotTime(c,u){return e._canimAnimatorSlotTime(c,u)},animatorGetSlotWeight(c,u){return e._canimAnimatorSlotWeight(c,u)},animatorSetLayer(c,u,m,w,_){dt(e,_??"",L=>e._canimAnimatorSetLayer(c,u,m,w?1:0,L))},animatorSetLayerAnticipation(c,u,m){e._canimAnimatorSetLayerAnticipation(c,u,m)},animatorSetGlobal(c,u,m){e._canimAnimatorSetGlobal(c,u,m?1:0)},animatorJointRanges(c,u,m){for(const[w,_]of r){if(!_.entities.includes(c))continue;const L=u.length>>1,z=new Int32Array(L*2);for(let Y=0;Y<L*2;Y++)z[Y]=_.entities.indexOf(u[Y]);const N=new Float32Array(L*6),$=e._malloc(Math.max(4,L*8));e.HEAP32.set(z,$>>2);const k=e._malloc(Math.max(4,L*24));let J=0;try{J=yt(e,m,Y=>e._canimAnimatorJointRanges(w,$,L,Y,k)),J>0&&N.set(e.HEAPF32.subarray(k>>2,(k>>2)+L*6))}finally{e._free($),e._free(k)}return J>0?N:null}return null},animatorSeedPose(c,u){for(const[m,w]of r){if(!w.entities.includes(c))continue;const _=new Float32Array(w.n*10);for(let L=0;L<w.n;L++){const z=t.get(w.entities[L]),{t:N,r:$,s:k}=Ur(z?z.m:br);_.set([N[0],N[1],N[2],$[0],$[1],$[2],$[3],k[0],k[1],k[2]],L*10)}yt(e,_,L=>e._canimAnimatorSeedPose(m,L,u));return}},animatorSetRootMotion(c,u,m){dt(e,u??"",w=>e._canimAnimatorSetRootMotion(c,w,(m|0)&255))},animatorGetRootMotion(c,u){e._canimAnimatorRootMotion(c,i);const m=e.HEAPF32,w=i>>2;u[0]=m[w],u[1]=m[w+1],u[2]=m[w+2]},setOnAnimatorEvent(c){n=c},animatorSetFeet(c,u,m){dt(e,u,w=>dt(e,m,_=>e._canimAnimatorSetFeet(c,w,_)))},animatorSlotCurveAt(c,u,m,w){return e._canimAnimatorSlotCurveAt(c,u,m,w)},animatorSlotCurveInfo(c,u,m){const w=e._canimAnimatorSlotCurveInfo(c,u,s);return w&&m.set(e.HEAPF32.subarray(s>>2,(s>>2)+Math.min(4,m.length))),w!==0},animatorSlotTurn(c,u){return e._canimAnimatorSlotTurn(c,u)},animatorSlotTimeAtTurn(c,u,m){return e._canimAnimatorSlotTimeAtTurn(c,u,m)},animatorLayerPhase(c,u){return e._canimAnimatorLayerPhase(c,u)},animatorSeekPhase(c,u,m){e._canimAnimatorSeekPhase(c,u,m)},animatorSlotContacts(c,u,m){const w=Math.floor(m.length/8);if(w===0)return e._canimAnimatorSlotContacts(c,u,0,0);const _=e._malloc(w*8*4),L=e._canimAnimatorSlotContacts(c,u,_,w);return m.set(e.HEAPF32.subarray(_>>2,(_>>2)+Math.min(L,w)*8)),e._free(_),L},animatorSlotTreads(c,u,m){if(m.length===0)return e._canimAnimatorSlotTreads(c,u,0,0);const w=e._malloc(m.length*4),_=e._canimAnimatorSlotTreads(c,u,w,m.length);return m.set(e.HEAPF32.subarray(w>>2,(w>>2)+Math.min(_+1,m.length))),e._free(w),_},animatorSlotPhysics(c,u,m,w){const _=e._malloc(44),L=e._canimAnimatorSlotPhysics(c,u,m,_);return L&&w.set(e.HEAPF32.subarray(_>>2,(_>>2)+Math.min(11,w.length))),e._free(_),L},animatorSlotFeatures(c,u,m,w){const _=e._malloc(148),L=e._canimAnimatorSlotFeatures(c,u,m,_);return L&&w.set(e.HEAPF32.subarray(_>>2,(_>>2)+Math.min(37,w.length))),e._free(_),L},animatorKneeAxis(c,u,m){const w=e._canimAnimatorKneeAxis(c,u,f);return w&&m.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(8,m.length))),w},animatorSlotKneePole(c,u,m,w,_){const L=e._canimAnimatorSlotKneePole(c,u,m,w,f);return L&&_.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(6,_.length))),L},animatorSetStepWarp(c,u,m,w,_,L){e._canimAnimatorSetStepWarp(c,u?1:0,m,w,_,L)},animatorSlotFit(c,u,m,w,_){if(_.length===0)return e._canimAnimatorSlotFit(c,u,m,w,0,0);const L=e._malloc(_.length*4),z=e._canimAnimatorSlotFit(c,u,m,w,L,_.length);return _.set(e.HEAPF32.subarray(L>>2,(L>>2)+Math.min(z,_.length))),e._free(L),z},animatorSlotExit(c,u,m,w,_,L){return e._canimAnimatorSlotExit(c,u,m,w,_?1:0,L)},animatorSlotAlign(c,u,m,w,_,L){if(L.length<4)return 0;const z=e._malloc(16),N=e._canimAnimatorSlotAlign(c,u,m,w,_,z);return N&&L.set(e.HEAPF32.subarray(z>>2,(z>>2)+4)),e._free(z),N},setOnAnimatorStep(c){d=c},animatorSetFeetParams(c,u){yt(e,u,w=>e._canimAnimatorSetFeetParams(c,w,u.length));const m=r.get(c);m&&(m.feetOn=u.length>0&&u[0]>.5||u.length>1&&u[1]>.5)},animatorFootState(c,u,m){const w=e._canimAnimatorFootState(c,u,f);return w&&m.set(e.HEAPF32.subarray(f>>2,(f>>2)+Math.min(8,m.length))),w!==0},animatorIkCreate(c,u,m){var J,Y;const w=r.get(c);if(!w||!un(e))return 0;const _=w.entities.indexOf(m);if(_<0)return 0;let L=-1,z=-1;if(u===0){const D=((J=t.get(m))==null?void 0:J.parent)??0;if(L=w.entities.indexOf(D),L<0||(z=w.entities.indexOf(((Y=t.get(D))==null?void 0:Y.parent)??0),z<0))return 0}const N=e._canimAnimatorIkCreateJoints(c,u,z,L,_);if(!N)return 0;const $=new Float32Array(fr),k=e._malloc(fr*4);return e._canimAnimatorIkGet(c,N,k,fr),$.set(e.HEAPF32.subarray(k>>2,(k>>2)+fr)),e._free(k),w.iks.push({ik:N,target:0,pole:0,rotation:0,params:$}),N},animatorIkDestroy(c,u){e._canimAnimatorIkDestroy(c,u);const m=r.get(c);m&&(m.iks=m.iks.filter(w=>w.ik!==u))},animatorIkSet(c,u,m){var _;yt(e,m,L=>e._canimAnimatorIkSet(c,u,L,m.length));const w=(_=r.get(c))==null?void 0:_.iks.find(L=>L.ik===u);w&&w.params.set(m.subarray(0,Math.min(m.length,fr)))},animatorIkNodes(c,u,m,w,_){var z;const L=(z=r.get(c))==null?void 0:z.iks.find(N=>N.ik===u);L&&(L.target=m,L.pole=w,L.rotation=_)},animatorIkAnchor(c,u,m){dt(e,m??"",w=>e._canimAnimatorIkAnchor(c,u,w))},animatorIkState(c,u,m){const w=e._canimAnimatorIkState(c,u,s);return w&&m.set(e.HEAPF32.subarray(s>>2,(s>>2)+Math.min(4,m.length))),w!==0},animatorSetSocket(c,u,m,w,_,L){const z=r.get(c);if(!z||!un(e))return;z.sockets=z.sockets.filter(k=>!(k.set===u&&k.name===m));const N=(k,J)=>{dt(e,u,Y=>dt(e,m,D=>{J?yt(e,J,X=>e._canimAnimatorSetSocket(c,Y,D,k,X)):e._canimAnimatorSetSocket(c,Y,D,k,0)}))};if(_===0&&!L){N(-1,null);return}const $=z.entities.indexOf(w);if($<0){console.warn(`[Animator] socket '${m}': the joint is no bone of this animator`);return}N($,L??[0,0,0,0,0,0,1]),_!==0&&z.sockets.push({set:u,name:m,node:_})},setClipAnchors(c,u,m,w,_,L){un(e)&&dt(e,m,z=>dt(e,w??"",N=>dt(e,_??"",$=>yt(e,L,k=>e._canimClipsSetAnchors(c,u,z,N,$,k,Math.floor(L.length/4))))))},animatorSetMotion(c,u,m,w){e._canimAnimatorSetMotion(c,u,m,w)},animatorSetDriveInput(c,u,m){e._canimAnimatorSetDriveInput(c,u,m)},animatorSetSlotDrive(c,u,m,w){e._canimAnimatorSetSlotDrive(c,u,m,w)},animatorSetWarpParams(c,u){yt(e,u,m=>e._canimAnimatorSetWarpParams(c,m,u.length))}},B=(c,u,m)=>{var Y,D;const w=t.get(u.rootId),_=w&&w.parent?t.get(w.parent):void 0,L=_?((Y=t.world)==null?void 0:Y.call(t,_.id))??_.m:br;e.HEAPF32.set(L,o>>2),e._canimAnimatorSetWorld(c,o);const z=e._canimAnimatorEvaluate(c,m,0,u.trs,u.write);if(u.feetOn&&w){const X=(((D=t.world)==null?void 0:D.call(t,u.rootId))??w.m)[13];for(let V=0;V<2;V++){if(!e._canimAnimatorFootProbe(c,V,l,a))continue;const q=e.HEAPF32,ae=l>>2;e._canimAnimatorSetGround(c,V,1,q[ae],X,q[ae+2],0,1,0)}}const N=e.HEAPF32,$=e.HEAPU8,k=u.trs>>2;for(let X=0;X<u.n;X++){if(!$[u.write+X])continue;const V=t.get(u.entities[X]);if(!V)continue;const q=k+X*10;hn(V.m,N[q],N[q+1],N[q+2],N[q+3],N[q+4],N[q+5],N[q+6],N[q+7],N[q+8],N[q+9]),t.localMatrixChanged(u.entities[X])}if(t.setMorphWeights){const X=e._canimAnimatorMorphCount(c);for(let V=0;V<X;V++){const q=e._canimAnimatorMorph(c,V,p,g),ae=e.HEAP32[p>>2],ee=e.HEAPU32[g>>2];!q||ae<0||ee===0||t.setMorphWeights(u.entities[ae],Float32Array.from(e.HEAPF32.subarray(q>>2,(q>>2)+ee)))}}const J=e._canimAnimatorRootMotionFrame(c,s);if(J!==0){const X=e.HEAPF32,V=s>>2,q=X[V],ae=X[V+1],ee=X[V+2],se=X[V+3];let ue=!1;if(J===2&&t.applyRootMotion&&(ue=t.applyRootMotion(u.rootId,q,ae,ee,m,se)),!ue&&(q!==0||ae!==0||ee!==0||se!==0)){const xe=t.get(u.rootId);if(xe){const me=xe.m;se!==0&&Fc(me,se);const je=me[0]*q+me[4]*ae+me[8]*ee,Qe=me[1]*q+me[5]*ae+me[9]*ee,A=me[2]*q+me[6]*ae+me[10]*ee;me[12]+=je,me[13]+=Qe,me[14]+=A,t.localMatrixChanged(u.rootId)}}}if(d){const X=e._canimAnimatorStepCount(c);for(let V=0;V<X;V++){const q=e._canimAnimatorStep(c,V,i);if(q<0)continue;const ae=e.HEAPF32,ee=i>>2,se=ae[ee],ue=ae[ee+1],xe=ae[ee+2],me=L;M.push({id:c,side:q,x:me[0]*se+me[4]*ue+me[8]*xe+me[12],y:me[1]*se+me[5]*ue+me[9]*xe+me[13],z:me[2]*se+me[6]*ue+me[10]*xe+me[14]})}}if(z>0){const X=e._canimAnimatorEvents(c,h,Ns),V=e.HEAPU16,q=h>>1;for(let ae=0;ae<X;ae++)v.push({id:c,slot:V[q+ae*2],type:V[q+ae*2+1]})}},T=c=>{var u,m;return((u=t.world)==null?void 0:u.call(t,c))??((m=t.get(c))==null?void 0:m.m)},E=(c,u)=>{if(u.iks.length===0)return;const m=t.get(u.rootId);if(!m)return;const w=m.parent?T(m.parent)??br:br;for(const N of u.iks){if(!N.target&&!N.pole&&!N.rotation)continue;const $=N.target?T(N.target):void 0;$&&(N.params[St.TARGET_X]=$[12],N.params[St.TARGET_X+1]=$[13],N.params[St.TARGET_X+2]=$[14]);const k=N.pole?T(N.pole):void 0;k&&(N.params[St.POLE_X]=k[12],N.params[St.POLE_X+1]=k[13],N.params[St.POLE_X+2]=k[14],N.params[St.HAS_POLE]=1);const J=N.rotation?T(N.rotation):void 0;if(J){const Y=Ur(J).r;N.params[St.ROT_X]=Y[0],N.params[St.ROT_X+1]=Y[1],N.params[St.ROT_X+2]=Y[2],N.params[St.ROT_X+3]=Y[3]}yt(e,N.params,Y=>e._canimAnimatorIkSet(c,N.ik,Y,fr))}for(const N of u.sockets){const $=T(N.node);$&&(e.HEAPF32.set($,o>>2),dt(e,N.set,k=>dt(e,N.name,J=>e._canimAnimatorSocketSetWorld(c,k,J,o))))}const _=e.HEAPF32,L=u.trs>>2;for(let N=0;N<u.n;N++){const $=t.get(u.entities[N]),{t:k,r:J,s:Y}=Ur($?$.m:br),D=L+N*10;_[D]=k[0],_[D+1]=k[1],_[D+2]=k[2],_[D+3]=J[0],_[D+4]=J[1],_[D+5]=J[2],_[D+6]=J[3],_[D+7]=Y[0],_[D+8]=Y[1],_[D+9]=Y[2]}if(e.HEAPF32.set(w,o>>2),e._canimAnimatorLateSolve(c,o,u.trs,u.write)===0)return;const z=e.HEAPU8;for(let N=0;N<u.n;N++){if(!z[u.write+N])continue;const $=t.get(u.entities[N]);if(!$)continue;const k=L+N*10;hn($.m,_[k],_[k+1],_[k+2],_[k+3],_[k+4],_[k+5],_[k+6],_[k+7],_[k+8],_[k+9]),t.localMatrixChanged(u.entities[N])}};return{methods:P,registerGlbClips(c){return y(c)},lateSolve(){for(const[c,u]of r)E(c,u)},evaluate(c){for(const[u,m]of r)B(u,m,c);if(M.length>0){const u=M.splice(0,M.length);if(d)for(const m of u)d(m.id,m.side,m.x,m.y,m.z)}if(v.length>0&&n){const u=v.splice(0,v.length);for(const m of u)n(m.id,m.slot,m.type)}else v.length=0},onEntityDestroyed(c){e._canimAnimatorsDestroyTagged(c);for(const[u,m]of r)m.rootId===c&&(x(m),r.delete(u))}}}const Pc=["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"],Rc=t=>{let e=null;const r=()=>{if(!e){if(!fi())throw new Error("creator-anim is not loaded: await loadCreatorAnim() (viewer-lite/src/gl/core/animBridge) before the first animation call");e=Tc(t)}return e},n={};for(const s of Pc)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)}}},Bc=["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"],fn=1/60,Os=["static","kinematic","dynamic"],wn=34,Lc=15,Nc=32,Is=33,Ds=(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(wn,wn+e*2))}:{}}),Oc=t=>{let e=null;const r=()=>{if(!e){if(!vs())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 d of Bc)n[d]=(...y)=>r().methods[d](...y);const s=new Map,i=new Map,o=new Map,l=new Map,a=new Map;let f;const p=(d,y)=>(d&&s.set(d,y),d),g=(d,y)=>{const x=d.get(y);return x===void 0?void 0:t.ent(x).physics},h=(d,y,x,P,B)=>(d&&(i.set(d,y),t.ent(y).physics={motion:Os[x]??x,mass:P,shape:B}),d),v={...n,physicsHasSupport:()=>vs(),physicsConfigure(d,y,x,P){f={gravity:[d,y,x],maxBodies:P},n.physicsConfigure(d,y,x,P)},physicsBuildBox:(d,y,x)=>p(n.physicsBuildBox(d,y,x),{type:"box",size:[d*2,y*2,x*2]}),physicsBuildSphere:d=>p(n.physicsBuildSphere(d),{type:"sphere",radius:d}),physicsBuildCylinder:(d,y)=>p(n.physicsBuildCylinder(d,y),{type:"cylinder",height:d*2,radius:y}),physicsBuildCapsule:(d,y)=>p(n.physicsBuildCapsule(d,y),{type:"capsule",height:d*2,radius:y}),physicsBuildMesh:(d,y,x,P,B,T)=>p(n.physicsBuildMesh(d,y,x,P,B,T),{type:x?"convexHull":"mesh",vertices:d.length/3,triangles:Math.floor(y.length/3),scale:[P,B,T]}),physicsBuildMeshFromEntity:(d,y,x,P,B)=>p(n.physicsBuildMeshFromEntity(d,y,x,P,B),{type:y?"convexHull":"mesh",source:d,scale:[x,P,B]}),physicsBuildHeightField(d,y,x,P,B,T,E,c){let u=0;if(B)for(let m=0;m<B.length;m++)B[m]&&u++;return p(n.physicsBuildHeightField(d,y,x,P,B,T,E,c),{type:"heightfield",size:[y,x],cellSize:P,samples:d.length,holes:u,scale:[T,E,c]})},physicsSetShapeOrigin(d,y,x,P){const B=s.get(d);B&&(y===0&&x===0&&P===0?delete B.origin:B.origin=[y,x,P]),n.physicsSetShapeOrigin(d,y,x,P)},physicsSetBodyShape(d,y,x){const P=g(i,d);P&&(P.shape=s.get(y)),n.physicsSetBodyShape(d,y,x)},physicsDestroyShape(d){s.delete(d),n.physicsDestroyShape(d)},physicsCreateBody(d,y,x,P,B,T){const E=n.physicsCreateBody(d,y,x,P,B,T);return E&&(i.set(E,d),t.ent(d).physics={motion:Os[x]??x,mass:P,...B&&{sensor:B},...T&&{pickOnly:T},shape:s.get(y)}),E},physicsSetFriction(d,y){const x=g(i,d);x&&(x.friction=y),n.physicsSetFriction(d,y)},physicsRemoveBody(d){i.delete(d),n.physicsRemoveBody(d)},physicsCreateBox:(d,y,x,P,B,T)=>h(n.physicsCreateBox(d,y,x,P,B,T),d,B,T,{type:"box",size:[y*2,x*2,P*2]}),physicsCreateSphere:(d,y,x,P)=>h(n.physicsCreateSphere(d,y,x,P),d,x,P,{type:"sphere",radius:y}),physicsCreateCylinder:(d,y,x,P,B)=>h(n.physicsCreateCylinder(d,y,x,P,B),d,P,B,{type:"cylinder",height:y*2,radius:x}),characterCreate(d,y,x){const P=n.characterCreate(d,y,x);return P&&(o.set(P,d),t.ent(d).physics={character:!0,maxSlopeDeg:x,shape:s.get(y)}),P},characterDestroy(d){o.delete(d),n.characterDestroy(d)},characterSetMaxSlope(d,y){const x=g(o,d);x&&(x.maxSlopeDeg=y),n.characterSetMaxSlope(d,y)},characterSetShape(d,y){const x=n.characterSetShape(d,y);if(x){const P=g(o,d);P&&(P.shape=s.get(y))}return x},vehicleCreate(d,y,x){const P=n.vehicleCreate(d,y,x);if(!P)return 0;const B=x[Nc]??0,T=x[Is]??0;let E=wn+T*2;const c=[];for(let u=0;u<B;u++){const m=x[E+13]??0,w=x[E+14]??0;c.push({position:[x[E],x[E+1],x[E+2]],radius:x[E+3],width:x[E+4],...x[E+5]?{steerDeg:x[E+5]}:{},...x[E+6]?{driven:x[E+6]}:{},axle:x[E+7],suspension:{travel:x[E+8],stiffness:x[E+9],damping:x[E+10]},tire:{traction:x[E+11],circle:x[E+12],side:m,forward:w}}),E+=Lc+(m+w)*2}return l.set(P,d),t.ent(d).physics={motion:"dynamic",mass:x[1],vehicle:!0,...Ds(x,T),wheels:c,shape:s.get(y)},P},vehicleDestroy(d){l.delete(d),n.vehicleDestroy(d)},vehicleSetTuning(d,y){const x=g(l,d);x&&Object.assign(x,Ds(y,y[Is]??0)),n.vehicleSetTuning(d,y)},vehicleSetInput(d,y){const x=g(l,d);x&&(x.input={throttle:y[0],steer:y[1],steerForce:y[2],ratio:y[3],clutch:y[4],brakes:Array.from(y.subarray(5))}),n.vehicleSetInput(d,y)},ragdollCreate(d,y,x){const P=n.ragdollCreate(d,y,x);if(!P)return 0;const B=16,T=x[1]??0,E=x[2]??12,c=[];for(let u=0;u<T;u++){const m=B+u*E;c.push({bone:y[u*2],...y[u*2+1]?{to:y[u*2+1]}:{},parent:x[m],radius:x[m+1],...x[m+2]?{length:x[m+2]}:{},mass:x[m+3],...x[m+6]?{hinge:{axis:[x[m+7],x[m+8],x[m+9]],min:x[m+10],max:x[m+11]}}:{swing:x[m+4],twist:x[m+5]}})}return a.set(P,d),t.ent(d).ragdoll={friction:x[3],collide:x[6]?"static":"all",freeze:!!x[7],freezeAfter:x[8]??0,drive:{frequency:x[9],damping:x[10],torque:x[11]},jointFriction:x[12],limits:x[13]?"clips":"table",limitsMargin:x[14],parts:c},P},ragdollDestroy(d){a.delete(d),n.ragdollDestroy(d)},ragdollActivate(d,y,x,P){const B=n.ragdollActivate(d,y,x,P),T=a.get(d),E=T===void 0?void 0:t.ent(T).ragdoll;return B&&E&&(E.active=!0,E.launch=[y,x,P]),B},ragdollDeactivate(d,y){const x=a.get(d),P=x===void 0?void 0:t.ent(x).ragdoll;P&&(P.active=!1,delete P.launch,y>0&&(P.blendOut=y)),n.ragdollDeactivate(d,y)},ragdollSetDrive(d,y,x){const P=a.get(d),B=P===void 0?void 0:t.ent(P).ragdoll;B&&(B.strength=y,B.anchored=x),n.ragdollSetDrive(d,y,x)}};let M=0;return{methods:v,loaded:()=>e!==null,frame(d,y){if(e){e.frame(d,y);return}if(!y){M=0;return}M+=d;let x=0;for(;M>=fn&&x<4;)y(fn),M-=fn,x++;x===4&&(M=0)},syncRagdolls(d){e&&e.syncRagdolls(d)},applyRootMotion:(d,y,x,P,B)=>e?e.applyRootMotion(d,y,x,P,B):!1,config:()=>f}},Ut={POINTS:0,QUADS:1,MESH:3};let Ic=null,An=null;const Dc=()=>Ic??(Ic=Tr(()=>import("./creatorParticles-DYlv4g1J.js"),__vite__mapDeps([4,1]),import.meta.url).then(t=>t.default()).then(t=>An=t)),Uc=()=>An!==null,zc=(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 Gc(t){const e=An;if(!e)throw new Error("creator-particles: await loadCreatorParticles() before createParticleBridge()");const r=e._malloc(64),n=e._malloc(12),s=new Map,i={createParticleSystem(l,a,f){e._cpartCreate(l,f|0)&&s.set(l,a)},spawnParticles(l,a){e._cpartSpawn(l,a)},setParticleSystemConfig(l,a){zc(e,a,f=>e._cpartSetConfig(l,f,a.length))},createNoise:()=>e._cpartNoiseCreate(),setNoiseFrequency(l,a){e._cpartNoiseSetFrequency(l,a)},setNoiseOctaves(l,a){e._cpartNoiseSetOctaves(l,a|0)},setNoiseFractalLunacrity(l,a){e._cpartNoiseSetLacunarity(l,a)},setNoiseFractalGain(l,a){e._cpartNoiseSetGain(l,a)},getNoise2D:(l,a,f)=>e._cpartNoise2D(l,a,f),getNoise3D:(l,a,f,p)=>e._cpartNoise3D(l,a,f,p)},o=l=>{const a=e._cpartVertexCount(l),f=e._cpartVertexStride(l),p=e._cpartVertexData(l);return{mode:e._cpartMode(l),stride:f,vertexCount:a,indexCount:e._cpartIndexCount(l),bytes:a>0&&p?e.HEAPU8.subarray(p,p+a*f):new Uint8Array(0),geometryVersion:e._cpartGeometryVersion(l),capacity:e._cpartCapacity(l),meshVertexCount:e._cpartMeshVertexCount(l),order:e._cpartOrder(l),alive:e._cpartAlive(l)}};return{methods:i,materialOf:l=>s.get(l),systems:()=>s.keys(),update(l,a){const f=t.cameraPosition();let p=0;f&&(e.HEAPF32.set([f[0],f[1],f[2]],n>>2),p=n);for(const g of s.keys())e.HEAPF32.set(t.world(g),r>>2),e._cpartUpdate(g,l,r,p),a(g,o(g))},setVisible(l,a){e._cpartSetVisible(l,a?1:0)},alive:l=>e._cpartAlive(l),indexPattern(l){const a=e._cpartIndexPatternCount(l);if(a===0)return new Uint32Array(0);const f=e._malloc(a*4);e._cpartWriteIndexPattern(l,f);const p=Uint32Array.from(e.HEAPU32.subarray(f>>2,(f>>2)+a));return e._free(f),p},destroy(l){e._cpartDestroy(l),s.delete(l)},dispose(){e._cpartReset(),s.clear(),e._free(r),e._free(n)}}}const dn={createNoise:()=>0,setNoiseFrequency(){},setNoiseOctaves(){},setNoiseFractalLunacrity(){},setNoiseFractalGain(){},getNoise2D:()=>0,getNoise3D:()=>0},Vc=t=>{let e=null;const r=()=>(!e&&Uc()&&(e=Gc(t)),e);let n=1;const s=(l,a,f)=>{const p=t.ent(l);p.particles||(p.particles={}),f===void 0?delete p.particles[a]:p.particles[a]=f},i={createParticleSystem(l,a,f){var g;t.ent(l).particles={material:a,...f?{maxParticles:f}:{}};const p=r();p&&(p.methods.createParticleSystem(l,a,f),(g=t.created)==null||g.call(t,l,a))},spawnParticles(l,a){var p;const f=t.ent(l).particles;f&&(f.spawned=(f.spawned??0)+a),(p=r())==null||p.methods.spawnParticles(l,a)},setParticleSystemConfig(l,a){var g;const f=(h,v)=>h===v?h:{min:h,max:v},p=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(l,"shape",{type:"point",at:[a[v+1],a[v+2],a[v+3]]}):M===1?s(l,"shape",{type:"box",min:[a[v+1],a[v+2],a[v+3]],max:[a[v+4],a[v+5],a[v+6]]}):s(l,"shape",{type:"circle",center:[a[v+1],a[v+2],a[v+3]],radius:a[v+4]});break}case 2:s(l,"lifetime",f(a[v],a[v+1]));break;case 3:s(l,"rate",a[v]);break;case 4:s(l,"velocity",{kind:a[v],value:[a[v+1],a[v+2],a[v+3]]}),s(l,"speed",f(a[v+4],a[v+5]));break;case 5:s(l,"spreadAngle",a[v]?{min:[a[v+1],a[v+2]],max:[a[v+3],a[v+4]]}:void 0);break;case 6:s(l,"acceleration",[a[v],a[v+1],a[v+2]]);break;case 7:s(l,"drag",a[v]);break;case 8:s(l,"noise",a[v]!==0?{strength:a[v],frequency:a[v+1],speed:a[v+2]}:void 0);break;case 9:s(l,"seed",a[v]);break;case 10:{const M=f(a[v+2],a[v+3]);s(l,`param${a[v]}`,a[v+4]>0?{base:M,curve:a[v+4]}:M);break}case 11:{const M=p(v),d=p(v+4),y=M.every((x,P)=>x===d[P])?M:{min:M,max:d};s(l,"color",a[v+8]>0?{base:y,curve:a[v+8]}:y);break}case 12:s(l,"space",a[v]?"world":"local");break;case 15:s(l,"render",["point","quad","ribbon","mesh"][a[v]]??a[v]);break}}(g=r())==null||g.methods.setParticleSystemConfig(l,a)},...dn},o=Object.fromEntries(Object.keys(dn).map(l=>[l,(...a)=>{const f=r();return f?f.methods[l](...a):l==="createNoise"?n++:dn[l](...a)}]));return Object.assign(i,o),{methods:i,loaded:()=>e!==null,update(l){e&&e.update(l,(a,f)=>{var g;const p=t.ent(a).particles;p&&(p.alive=f.alive),(g=t.frame)==null||g.call(t,a,f)})},setVisible(l,a){e==null||e.setVisible(l,a)},indexPattern:l=>(e==null?void 0:e.indexPattern(l))??new Uint32Array(0),onEntityDestroyed(l){var a;e&&e.materialOf(l)!==void 0&&(e.destroy(l),(a=t.destroyed)==null||a.call(t,l))}}},di=t=>{const e=Math.max(t.lastIndexOf(":"),t.lastIndexOf("|"));return e<0?t:t.slice(e+1)},Hc=(t,e,r,n)=>t?t===r?e?0:1:di(t)===n?e?2:3:-1:-1,zt=(t,e,r=16)=>{for(let n=0;n<r;n++)t[n]=e[n]},Us=(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 kc(t,e){const r=e.width??390,n=e.height??844,s=e.fov??60,i={fov:s,near:.01,far:1e3},o=new Map,l=new Map,a=new Map,f=new Map;let p=1,g=1,h=1,v=-1,M=null,d=null,y=null;const x=Oc({ent:A=>c(A),get:A=>o.get(A),world:A=>m(A),setWorldTRS:(A,C,R,W,ie,ne,Se,Ce,Oe,Ve,Ie)=>L(A,ei([C,R,W],[ie,ne,Se,Ce],[Oe,Ve,Ie])),setWorldPosition:(A,C,R,W)=>z(A,C,R,W),localMatrixChanged:A=>{var C;return(C=t.localMatrixChanged)==null?void 0:C.call(t,A)},parentOf:A=>{var C;return((C=o.get(A))==null?void 0:C.parent)??0},glbBytes:A=>{var C,R;return(R=(C=o.get(A))==null?void 0:C.model)==null?void 0:R.buffer},seedAnimator:(A,C)=>B.methods.animatorSeedPose(A,C),jointRanges:(A,C,R)=>B.methods.animatorJointRanges(A,C,R)}),P=Vc({ent:A=>c(A),world:A=>m(A),cameraPosition:()=>{var R;const A=(R=l.get(v))==null?void 0:R.camera;if(A===void 0)return null;const C=u(A);return[C[12],C[13],C[14]]},created:(A,C)=>{var R;return(R=t.particleSystemCreated)==null?void 0:R.call(t,A,C)},frame:(A,C)=>{var R;return(R=t.particlesFrame)==null?void 0:R.call(t,A,C)},destroyed:A=>{var C;return(C=t.particleSystemDestroyed)==null?void 0:C.call(t,A)}}),B=Rc({get:A=>o.get(A),world:A=>m(A),localMatrixChanged:A=>{var C;return(C=t.localMatrixChanged)==null?void 0:C.call(t,A)},getBuffer:A=>e.getBuffer(A),setMorphWeights:(A,C)=>{var R;return(R=t.morphWeights)==null?void 0:R.call(t,A,C)},applyRootMotion:(A,C,R,W,ie,ne)=>{const Se=m(A);return x.applyRootMotion(A,Se[0]*C+Se[4]*R+Se[8]*W,Se[2]*C+Se[6]*R+Se[10]*W,ie,ne)}}),T=A=>{const C={id:A,name:"",m:t.allocMatrix(A),parent:0,children:[],visible:!0,materials:[]};return(C.m[0]!==1||C.m[5]!==1||C.m[10]!==1||C.m[15]!==1)&&zt(C.m,$e()),o.set(A,C),C},E=()=>T(p++),c=A=>{let C=o.get(A);return C||(C=T(A),A>=p&&(p=A+1)),C},u=A=>{const C=c(A);return C.parent===0?C.m:wt(new Float32Array(16),u(C.parent),C.m)},m=A=>{const C=u(A);return C instanceof Float32Array?C:Float32Array.from(C)},w=A=>{if(A.parent!==0){const C=o.get(A.parent);C&&(C.children=C.children.filter(R=>R!==A.id)),A.parent=0}},_=(A,C,R)=>{var ie,ne;const W=c(A);if(W.parent!==C){if(R){const Se=m(A),Ce=C===0?Se:wt(new Float32Array(16),Ft(m(C)),Se);zt(W.m,Ce)}w(W),C!==0&&(W.parent=C,c(C).children.push(A)),(ie=t.parentChanged)==null||ie.call(t,A,C),(ne=t.localMatrixChanged)==null||ne.call(t,A)}},L=(A,C)=>{var W;const R=c(A);zt(R.m,R.parent===0?C:wt(new Float32Array(16),Ft(m(R.parent)),C)),(W=t.localMatrixChanged)==null||W.call(t,A)},z=(A,C,R,W)=>{var Se;const ie=c(A),ne=ie.m;if(ie.parent===0)ne[12]=C,ne[13]=R,ne[14]=W;else{const Ce=Ft(m(ie.parent));ne[12]=Ce[0]*C+Ce[4]*R+Ce[8]*W+Ce[12],ne[13]=Ce[1]*C+Ce[5]*R+Ce[9]*W+Ce[13],ne[14]=Ce[2]*C+Ce[6]*R+Ce[10]*W+Ce[14]}(Se=t.localMatrixChanged)==null||Se.call(t,A)},N=A=>{const C=l.get(A),R=(C==null?void 0:C.overlayOf)!==void 0?l.get(C.overlayOf):C;return(R==null?void 0:R.customProjection)??(R==null?void 0:R.projection)??i},$=A=>{for(let C=A;C!==0;){for(const R of l.values())if(R.entities.has(C))return R;C=c(C).parent}return null},k=A=>{var ie;const C=(ie=e.getSourceName)==null?void 0:ie.call(e,A);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},J=A=>{let C=a.get(A);return C||(C={shader:"unknown",uniforms:{}},a.set(A,C)),C},Y=(A,C,R)=>{var W;J(A).uniforms[C]=R,(W=t.uniformChanged)==null||W.call(t,A,C,R)},D=A=>{const C=e.getBuffer(A),R=C?Ac(C):null,W=E();if(W.model={source:k(A),systemId:A,animations:(R==null?void 0:R.animations)??[],loaded:R!==null,...C&&{buffer:C}},R&&R.animations.length>0&&C&&fi()&&(W.model.clipSet=B.registerGlbClips(C)),!R)return{rootId:W.id,entIds:[]};const ie=R.nodes.map(()=>E().id);R.nodes.forEach((ne,Se)=>{var Oe;const Ce=c(ie[Se]);Ce.name=ne.name??"",zt(Ce.m,ne.matrix),(Oe=t.localMatrixChanged)==null||Oe.call(t,Ce.id),ne.skinJoint&&(Ce.skinJoint=!0),ne.mesh&&(Ce.mesh={kind:0,vertexCount:0,primitives:ne.mesh.primitives},ne.mesh.min&&ne.mesh.max&&(Ce.mesh.size=[ne.mesh.max[0]-ne.mesh.min[0],ne.mesh.max[1]-ne.mesh.min[1],ne.mesh.max[2]-ne.mesh.min[2]],Ce.mesh.center=[(ne.mesh.max[0]+ne.mesh.min[0])/2,(ne.mesh.max[1]+ne.mesh.min[1])/2,(ne.mesh.max[2]+ne.mesh.min[2])/2]));for(const Ve of ne.children)_(ie[Ve],Ce.id,!1)});for(const ne of R.roots)_(ie[ne],W.id,!1);return{rootId:W.id,entIds:ie}},X=(A,C)=>{var ie,ne;const R=c(A),W=E();C.set(R.id,W.id),W.name=R.name,zt(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)),(ie=t.localMatrixChanged)==null||ie.call(t,W.id),(ne=t.entityCloned)==null||ne.call(t,R.id,W.id);for(const Se of R.children)_(X(Se,C),W.id,!1);return W.id},V=A=>{var R;const C=o.get(A);if(C){for(const W of[...C.children])V(W);w(C);for(const W of l.values())W.entities.delete(A);(R=t.entityDestroyed)==null||R.call(t,A),B.onEntityDestroyed(A),P.onEntityDestroyed(A),o.delete(A)}},q=A=>{for(let C=A;C!==0;C=c(C).parent)if(!c(C).visible)return!1;return!0};let ae=1;const ee=A=>{const C=A*ae;M==null||M(A),x.frame(C,y),B.evaluate(C),x.syncRagdolls(C),d==null||d(A),B.lateSolve(),P.update(C)},se=A=>{const C=Math.min(1e3,Math.floor(A/16));for(let R=0;R<C;R++)ee(.016)},ue=()=>v>=0||l.size>0,xe=()=>v,me={createScene(){var C;const A=l.size;return l.set(A,{id:A,entities:new Set,overlays:[]}),(C=t.sceneCreated)==null||C.call(t,A),A},createOverlayScene(A){var R,W;const C=l.size;return l.set(C,{id:C,entities:new Set,overlays:[],overlayOf:A}),(R=l.get(A))==null||R.overlays.push(C),(W=t.sceneCreated)==null||W.call(t,C),C},createGLView(){},openScene(A){v=A},closeScene(){v=-1},addEntityToScene(A,C){var W;const R=l.get(A);if(R){for(const ie of l.values())ie!==R&&ie.entities.delete(C);R.entities.add(C),(W=t.entitySceneChanged)==null||W.call(t,C,A,!0)}},removeEntityFromScene(A,C){var W;const R=l.get(A);R&&(R.entities.delete(C),(W=t.entitySceneChanged)==null||W.call(t,C,A,!1))},createEntity:()=>E().id,cloneEntity(A){var ie,ne;const C=c(A),R=new Map,W=X(A,R);if(C.parent!==0)_(W,C.parent,!1);else{const Se=$(A);Se&&(Se.entities.add(W),(ie=t.entitySceneChanged)==null||ie.call(t,W,Se.id,!0))}return(ne=t.subtreeCloned)==null||ne.call(t,A,W,R),W},destroyEntity(A){V(A)},setMatrix(A,C){var W;const R=c(A);zt(R.m,C),(W=t.localMatrixChanged)==null||W.call(t,A)},setWorldMatrix(A,C){var ie,ne;const R=c(A);if(R.parent===0){zt(R.m,C),(ie=t.localMatrixChanged)==null||ie.call(t,A);return}const W=wt(new Float32Array(16),Ft(m(R.parent)),Float32Array.from(C.subarray(0,16)));zt(R.m,W),(ne=t.localMatrixChanged)==null||ne.call(t,A)},getChildCount:A=>c(A).children.length,getChild:(A,C)=>c(A).children[C]??0,setPosition(A,C,R,W){var ne;const ie=c(A).m;ie[12]=C,ie[13]=R,ie[14]=W,(ne=t.localMatrixChanged)==null||ne.call(t,A)},setQuaternion(A,C,R,W,ie){var ne;Zs(c(A).m,C,R,W,ie),(ne=t.localMatrixChanged)==null||ne.call(t,A)},setEulerAngles(A,C,R,W,ie){var ne;Na(c(A).m,C,R,W,ie),(ne=t.localMatrixChanged)==null||ne.call(t,A)},setScale(A,C,R,W){var ie;Js(c(A).m,C,R,W),(ie=t.localMatrixChanged)==null||ie.call(t,A)},setParent(A,C,R){_(A,C,R)},setParentNull(A,C){_(A,0,C)},getParent:A=>c(A).parent,traverse(A,C){const R=W=>{C(W);for(const ie of c(W).children)R(ie)};for(const W of c(A).children)R(W)},findNode(A,C){const R=di(C);let W=0,ie=4;const ne=Se=>{const Ce=c(Se),Oe=Hc(Ce.name,!!Ce.skinJoint,C,R);Oe<ie&&Oe>=0&&(W=Se,ie=Oe);for(const Ve of Ce.children){if(ie===0)return;ne(Ve)}};for(const Se of c(A).children){if(ie===0)break;ne(Se)}return W},createSunLight(A,C,R,W,ie,ne,Se,Ce=100,Oe=1){c(A).light={direction:[C,R,W],intensity:ie,color:ne,shadowsQuality:Se,shadowDistance:Ce,shadowCascades:Oe}},createPointLight(A,C,R,W,ie){c(A).punctual={type:"point",intensity:C,color:R,range:W>0?W:1,inner:0,outer:0,castShadows:ie}},createSpotLight(A,C,R,W,ie,ne,Se){const[Ce,Oe]=Us(ie,ne);c(A).punctual={type:"spot",intensity:C,color:R,range:W>0?W:1,inner:Ce,outer:Oe,castShadows:Se}},setLightCone(A,C,R){var ie;const W=(ie=o.get(A))==null?void 0:ie.punctual;(W==null?void 0:W.type)==="spot"&&([W.inner,W.outer]=Us(C,R))},setLightIntensity(A,C){const R=o.get(A);R!=null&&R.light&&(R.light.intensity=C),R!=null&&R.punctual&&(R.punctual.intensity=C)},setLightColor(A,C){const R=o.get(A);R!=null&&R.light&&(R.light.color=C),R!=null&&R.punctual&&(R.punctual.color=C)},setDefaultIbl(A,C){const R=l.get(A);R&&(R.ibl=C)},setBloomOptions(A,C,R,W,ie,ne,Se,Ce,Oe,Ve){const Ie=l.get(A);Ie&&(Ie.bloom=C?{strength:R,threshold:W,highlight:ie,levels:ne,quality:Se}:void 0)},setSkybox(A,C){const R=l.get(A);R&&(R.skybox=C)},setSceneMultiSampleAntiAliasing(A,C){const R=l.get(A);R&&(R.antialias=C)},setSceneRenderOptions(){},setMaterialGlobalParameter(){},getCameraFov(A,C){const{fov:R}=N(A);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(A,C,R,W){const ie=l.get(A);ie&&(ie.projection={fov:C,near:R,far:W})},setCameraMatrix(A,C){var W;const R=(W=l.get(A))==null?void 0:W.camera;R&&me.setWorldMatrix(R,C)},setCameraProjectionMatrix(A,C,R,W){const ie=l.get(A);ie&&C[5]>0&&(ie.customProjection={fov:2*Math.atan(1/C[5])*180/Math.PI,near:R,far:W})},clearCameraProjectionMatrix(A){const C=l.get(A);C&&delete C.customProjection},getMatrix(A,C){return C.set(je(A)),!0},getWorldMatrix(A,C){C.set(m(A))},getWorldPosition(A,C){const R=u(A);C[0]=R[12],C[1]=R[13],C[2]=R[14]},getWorldDirection(A,C,R){const W=u(A);R[0]=W[C*4],R[1]=W[C*4+1],R[2]=W[C*4+2]},getWorldMatrixInverse(A,C){C.set(Ft(m(A)))},getCameraViewDirection(A,C,R,W){var ut;const ie=(ut=l.get(A))==null?void 0:ut.camera,ne=ie?u(ie):$e(),Se=r/n,Ce=Math.tan(N(A).fov*Math.PI/360),Oe=(C/r*2-1)*Ce*Se,Ve=(1-R/n*2)*Ce,Ie=ne[0]*Oe+ne[4]*Ve-ne[8],Ge=ne[1]*Oe+ne[5]*Ve-ne[9],Ze=ne[2]*Oe+ne[6]*Ve-ne[10],rt=Math.hypot(Ie,Ge,Ze)||1;W[0]=Ie/rt,W[1]=Ge/rt,W[2]=Ze/rt},setMesh(A,C,R,W,ie,ne,Se,Ce,Oe){var Pt;const Ve=c(A);let Ie=1/0,Ge=1/0,Ze=1/0,rt=-1/0,ut=-1/0,Tt=-1/0;for(let pt=0;pt+2<R.length;pt+=3){const Ye=R[pt],xt=R[pt+1],Rt=R[pt+2];Ye<Ie&&(Ie=Ye),Ye>rt&&(rt=Ye),xt<Ge&&(Ge=xt),xt>ut&&(ut=xt),Rt<Ze&&(Ze=Rt),Rt>Tt&&(Tt=Rt)}const Nt=R.length>=3,$t={kind:Se,vertexCount:Math.floor(R.length/3),size:Nt?[rt-Ie,ut-Ge,Tt-Ze]:void 0,center:Nt?[(rt+Ie)/2,(ut+Ge)/2,(Tt+Ze)/2]:void 0};Ve.mesh=$t,Ve.materials[0]=C,(Pt=t.meshSet)==null||Pt.call(t,A,C,$t,{vertices:R,normals:W,indices:ie,uv:ne,colors:Oe})},setCulling(){},setRenderPriority(){},setMaterialDepthTest(){},setMaterialDepthWrite(){},setMaterialCulling(){},setMaterialStencil(){},setSceneStencil(){},setCastShadows(A,C){c(A).castShadows=C},setReceiveShadows(A,C){c(A).receiveShadows=C},setGlbShadows(A,C,R){const W=ie=>{const ne=c(ie);ne.castShadows=C,ne.receiveShadows=R;for(const Se of ne.children)W(Se)};W(A)},setCastShadowsGlobal(){},setReceiveShadowsGlobal(){},hasMesh:A=>c(A).mesh!==void 0,createMaterial(A){var W;const C=g++,R={shader:k(A)??"unknown",uniforms:{}};return a.set(C,R),(W=t.materialCreated)==null||W.call(t,C,R,A),C},createMaterialNamed(A){var W;const C=g++,R={shader:A,uniforms:{}};return a.set(C,R),(W=t.materialCreated)==null||W.call(t,C,R),C},setMaterial(A,C,R){c(A).materials[R]=C},getMaterial:(A,C)=>c(A).materials[C]??0,setUniformRgb(A,C,R){Y(A,C,{kind:"rgb",v:R})},setUniformRgba(A,C,R){Y(A,C,{kind:"rgba",v:R})},setUniformFloat(A,C,R){Y(A,C,{kind:"float",v:R})},setUniformBoolean(A,C,R){Y(A,C,{kind:"bool",v:R})},setUniformTexture(A,C,R){Y(A,C,{kind:"texture",v:R})},setUniformArray(A,C,R){Y(A,C,{kind:"array",v:Array.from(R)})},setUniformNull(A,C){Y(A,C,{kind:"null"})},createTexture(A,C,R){const W=e.getBuffer(A);if(!W||W.byteLength===0){R();return}const[ie,ne]=Wc(W),Se=h++;f.set(Se,{source:k(A),width:ie,height:ne}),C(Se,ie,ne)},createTextureFromCanvas(A){const C=h++;return f.set(C,{source:`canvas#${A}`,width:0,height:0}),C},updateTextureFromCanvas(){},createTexturePixels(A,C,R){const W=h++;return f.set(W,{source:`pixels ${A}x${C}x${R}`,width:A,height:C}),W},updateTexturePixels(){},createMediaPlayerTexture(A){const C=h++;return f.set(C,{source:`mediaplayer#${A}`,width:0,height:0}),C},attachCameraToAR(A,C,R){const W=l.get(A);W&&(W.camera=C);const ie=N(A);R(ti(ie.fov,r/n,ie.near,ie.far),ie.fov)},getDisplaySize:()=>Float32Array.of(r,n),setVisible(A,C){var W;c(A).visible=C,(W=t.visibleChanged)==null||W.call(t,A,C);const R=ie=>{const ne=c(ie);ne.particles&&P.setVisible(ie,q(ie));for(const Se of ne.children)R(Se)};R(A)},isVisible:A=>q(A),getName:A=>c(A).name,setName(A,C){c(A).name=C},createGlb(A,C,R){const{rootId:W,entIds:ie}=D(A);if(!t.glbAttach){C(W);return}Promise.resolve(t.glbAttach(A,W,ie)).then(()=>C(W)).catch(ne=>R==null?void 0:R(ne))},setGlbCulling(){},getGlbClipSet:A=>{var C,R;return((R=(C=o.get(A))==null?void 0:C.model)==null?void 0:R.clipSet)??0},...B.methods,setEarlyUpdate(A){M=A},setLateUpdate(A){d=A},setFixedUpdate(A){y=A},setTimeScale(A){ae=Number.isFinite(A)&&A>0?A:0},...x.methods,...P.methods};function je(A){const C=c(A).m;return C instanceof Float32Array?C:Float32Array.from(C)}let Qe=null;return{width:r,height:n,fov:s,entities:o,scenes:l,materials:a,textures:f,cameraOverride:()=>Qe,setCameraOverride:A=>{Qe=A},ent:c,newEnt:E,worldMatrix:u,worldMatrixF:m,sourceName:k,setParentInternal:_,sceneOf:$,projectionOf:N,rebindMatrix:(A,C)=>{c(A).m=C},methods:me,simulate:se,tick:ee,hasActiveScene:ue,activeSceneId:xe,physicsConfig:x.config,particleIndexPattern:P.indexPattern,nextTextureId:()=>h++,nextMaterialId:()=>g++}}const Wc=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]},Gt=(t,e)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},mi=(t,e)=>{var f,p;const r=(f=e.mesh)==null?void 0:f.size;if(!r)return[];const n=((p=e.mesh)==null?void 0:p.center)??[0,0,0],s=r[0]/2,i=r[1]/2,o=r[2]/2,l=t.worldMatrixF(e.id),a=[];for(let g=0;g<8;g++){const h=n[0]+(g&1?s:-s),v=n[1]+(g&2?i:-i),M=n[2]+(g&4?o:-o);a.push([l[0]*h+l[4]*v+l[8]*M+l[12],l[1]*h+l[5]*v+l[9]*M+l[13],l[2]*h+l[6]*v+l[10]*M+l[14]])}return a},$c=(t,e)=>{const r=[],n=s=>{const i=t.entities.get(s);if(i){r.push(...mi(t,i));for(const o of i.children)n(o)}};return n(e),r};function jc(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:o,near:l,far:a}=t.projectionOf(e.id),f=(n==null?void 0:n.fov)??o,p=n?Da(n.eye,n.target):Ft(t.worldMatrixF(r)),g=wt(new Float32Array(16),ti(f,s/i,l,a),p),h=(T,E,c)=>{const u=g[3]*T+g[7]*E+g[11]*c+g[15],m=g[0]*T+g[4]*E+g[8]*c+g[12],w=g[1]*T+g[5]*E+g[9]*c+g[13],_=u>1e-4;return _?{sx:(m/u*.5+.5)*s,sy:(1-(w/u*.5+.5))*i,cw:u,inFront:_}:{sx:0,sy:0,cw:u,inFront:_}},v=T=>{for(let E=T;E!==0;E=t.ent(E).parent)if(!t.ent(E).visible)return!1;return!0},M=[e,...e.overlays.map(T=>t.scenes.get(T)).filter(T=>!!T)],d=new Set,y=[],x=T=>{if(!(d.has(T)||!t.entities.has(T))){d.add(T),y.push(T);for(const E of t.ent(T).children)x(E)}};for(const T of M)for(const E of T.entities)x(E);const P=[];for(const T of y){const E=t.ent(T);if(!v(T))continue;const c=E.model?"model":E.mesh&&!E.light?"mesh":E.particles?"particles":null;if(!c)continue;let u;if(c==="model")u=$c(t,T);else if(c==="mesh")u=mi(t,E);else{const R=t.worldMatrixF(T);u=[[R[12],R[13],R[14]]]}if(u.length===0)continue;let m=1/0,w=1/0,_=1/0,L=-1/0,z=-1/0,N=-1/0;for(const R of u)R[0]<m&&(m=R[0]),R[0]>L&&(L=R[0]),R[1]<w&&(w=R[1]),R[1]>z&&(z=R[1]),R[2]<_&&(_=R[2]),R[2]>N&&(N=R[2]);const $=h((m+L)/2,(w+z)/2,(_+N)/2);let k=!1,J=!1,Y=1/0,D=1/0,X=-1/0,V=-1/0;for(const R of u){const W=h(R[0],R[1],R[2]);if(!W.inFront){k=!0;continue}J=!0,W.sx<Y&&(Y=W.sx),W.sx>X&&(X=W.sx),W.sy<D&&(D=W.sy),W.sy>V&&(V=W.sy)}const q={kind:c,depth:Gt($.cw,3),coverage:0};if(E.name&&(q.name=E.name),!J){q.behindCamera=!0,P.push({obj:q,id:T});continue}const ae=Y,ee=D,se=Math.max(0,X-Y),ue=Math.max(0,V-D);q.rect=[Gt(ae,1),Gt(ee,1),Gt(se,1),Gt(ue,1)],$.inFront&&(q.center=[Gt($.sx,1),Gt($.sy,1)]);const xe=Math.max(0,ae),me=Math.max(0,ee),je=Math.min(s,ae+se),Qe=Math.min(i,ee+ue),A=Math.max(0,je-xe)*Math.max(0,Qe-me);q.coverage=Gt(A/(s*i),4);const C=ae>=0&&ee>=0&&ae+se<=s&&ee+ue<=i;A===0?q.offscreen=!0:(k||!C)&&(q.clipped=!0),P.push({obj:q,id:T})}const B=T=>{const E=[];for(let c=T;c!==0;c=t.ent(c).parent)E.unshift(t.ent(c).name||"~");for(;E.length>0&&E[0]==="~";)E.shift();return E.join("/")};for(const{obj:T,id:E}of P)T.name&&(T.path=B(E));return P.sort((T,E)=>E.obj.coverage-T.obj.coverage||T.obj.depth-E.obj.depth),{viewport:{width:s,height:i},note:(n?"INSPECTION camera (not the app's) — ":"")+"screen px, top-left origin; depth is a camera-distance hint, not true occlusion; rects are rest-pose (headless doesn't sample animation)",objects:P.map(T=>T.obj)}}const Vt=(t,e=4)=>{const r=10**e,n=Math.round(t*r)/r;return n===0?0:n},Zt=(t,e=4)=>Array.from(t,r=>Vt(r,e)),Ar=(t,e)=>"#"+(t>>>0).toString(16).padStart(e?8:6,"0");function Xc(t,e){const{entities:r,scenes:n,materials:s,textures:i,worldMatrixF:o}=t,l=M=>{var d;switch(M.kind){case"rgb":return Ar(M.v,!1);case"rgba":return Ar(M.v,!0);case"texture":return((d=i.get(M.v))==null?void 0:d.source)??`texture#${M.v}`;case"null":return null;default:return M.v}},a=M=>{const d=s.get(M);if(!d)return;const y={shader:d.shader.replace(/\.filamat$/,"")};for(const[x,P]of Object.entries(d.uniforms))y[x]=l(P);return y},f=M=>{var c;const d=t.ent(M),y=d.m,x=Zt([y[12],y[13],y[14]]),P=cs(y).map(u=>Vt(u,2)),B=Pr(y).map(u=>Vt(u,4)),T=d.light||d.punctual?"light":d.model?"model":d.mesh?"mesh":d.particles?"particles":"node",E={};if(d.name&&(E.name=d.name),E.kind=T,x.some(u=>u!==0)&&(E.position=x),P.some(u=>u!==0)&&(E.rotation=P),B.some(u=>u!==1)&&(E.scale=B),d.visible||(E.visible=!1),d.mesh){const u={type:d.mesh.kind===1?"edges":d.mesh.kind===2?"vertices":"triangles"};d.mesh.size&&(u.size=Zt(d.mesh.size)),(c=d.mesh.center)!=null&&c.some(w=>Vt(w)!==0)&&(u.center=Zt(d.mesh.center)),E.mesh=u;const m=a(d.materials[0]);m&&(E.material=m)}if(d.model&&(E.model={...d.model.source&&{source:d.model.source},...!d.model.loaded&&{loaded:!1},animations:d.model.animations.map(u=>({name:u.name,duration:Vt(u.duration,2)}))}),d.light&&(E.light={type:"sun",direction:Zt(d.light.direction),intensity:d.light.intensity,color:Ar(d.light.color,!1),shadows:d.light.shadowsQuality}),d.punctual){const u=d.punctual;E.light={type:u.type,intensity:u.intensity,color:Ar(u.color,!1),range:u.range,...u.type==="spot"&&{angle:Vt(u.outer*360/Math.PI,2),innerAngle:Vt(u.inner*360/Math.PI,2)},...u.castShadows&&{castShadows:!0}}}return d.particles&&(E.particles=d.particles),d.physics&&(E.physics=d.physics),d.ragdoll&&(E.ragdoll=d.ragdoll),d.collider&&(E.collider=d.collider),d.castShadows!==void 0&&(E.castShadows=d.castShadows),d.receiveShadows!==void 0&&(E.receiveShadows=d.receiveShadows),d.children.length>0&&(E.children=d.children.map(f)),E},p=M=>{const d=B=>{for(let T=t.ent(B).parent;T!==0;T=t.ent(T).parent)if(M.entities.has(T))return!0;return!1},y=[...M.entities].filter(B=>r.has(B)&&!d(B)),x={};M.skybox!==void 0&&(x.skybox=Ar(M.skybox,!1)),M.ibl!==void 0&&(x.environment={intensity:M.ibl}),M.bloom&&(x.bloom={...M.bloom});const P=t.cameraOverride();if(P)x.camera={position:Zt(P.eye),lookAt:Zt(P.target),fov:P.fov??t.projectionOf(M.id).fov,inspection:!0};else if(M.camera!==void 0&&r.has(M.camera)){const B=o(M.camera),T=cs(B).map(E=>Vt(E,2));x.camera={position:Zt([B[12],B[13],B[14]]),...T.some(E=>E!==0)&&{rotation:T},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=>p(B))),x},g=n.get(t.activeSceneId())??[...n.values()].find(M=>M.overlayOf===void 0);if(!g)return null;const h=p(g),v=jc(t,g);return v&&(h.frame=v),h}const Sr='AR is the "ar" plugin since 2.3: add it to "plugins" of app.json',zs=new Set,I=t=>{zs.has(t)||(zs.add(t),console.warn(`[gl-lite] ${t}: not supported by the lite 3D engine`))},qc={createEngine(){I("createEngine")},createScene(){return I("createScene"),0},createOverlayScene(){return I("createOverlayScene"),0},createGLView(){I("createGLView")},openScene(){I("openScene")},closeScene(){I("closeScene")},launchAR(){I("launchAR")},stopAR(){I("stopAR")},launchVR(){I("launchVR")},stopVR(){I("stopVR")},addEntityToScene(){I("addEntityToScene")},removeEntityFromScene(){I("removeEntityFromScene")},warmRender(){I("warmRender")},createEntity(){return I("createEntity"),{id:0}},cloneEntity(){return I("cloneEntity"),{id:0}},destroyEntity(){I("destroyEntity")},entityIsOwned(){return I("entityIsOwned"),!1},setMatrix(){I("setMatrix")},setWorldMatrix(){I("setWorldMatrix")},getChildCount(){return I("getChildCount"),0},getChild(){return I("getChild"),0},setPosition(){I("setPosition")},setQuaternion(){I("setQuaternion")},setEulerAngles(){I("setEulerAngles")},setScale(){I("setScale")},setParent(){I("setParent")},setParentNull(){I("setParentNull")},getParent(){return I("getParent"),0},traverse(){I("traverse")},createSunLight(){I("createSunLight")},setDefaultIbl(){I("setDefaultIbl")},setBloomOptions(){I("setBloomOptions")},setSkybox(){I("setSkybox")},setSceneMultiSampleAntiAliasing(){I("setSceneMultiSampleAntiAliasing")},setMaterialGlobalParameter(){I("setMaterialGlobalParameter")},getCameraFov(){return I("getCameraFov"),0},getMatrix(){I("getMatrix")},getWorldMatrix(){I("getWorldMatrix")},getWorldPosition(){I("getWorldPosition")},getWorldDirection(){I("getWorldDirection")},getWorldMatrixInverse(){I("getWorldMatrixInverse")},getCameraViewDirection(){I("getCameraViewDirection")},setMesh(){I("setMesh")},createInstancedMesh(){I("createInstancedMesh")},setInstanceTransforms(){I("setInstanceTransforms")},setInstancedMeshMaterial(){I("setInstancedMeshMaterial")},setInstancedMeshShadows(){I("setInstancedMeshShadows")},setCulling(){I("setCulling")},setCastShadows(){I("setCastShadows")},setReceiveShadows(){I("setReceiveShadows")},createTexture(){I("createTexture")},createTextureFromCanvas(){return I("createTextureFromCanvas"),0},updateTextureFromCanvas(){I("updateTextureFromCanvas")},createMaterial(){return I("createMaterial"),{id:0}},builtinMaterial(){return I("builtinMaterial"),null},setMaterial(){I("setMaterial")},getMaterial(){return I("getMaterial"),0},setUniformRgb(){I("setUniformRgb")},setUniformRgba(){I("setUniformRgba")},setUniformFloat(){I("setUniformFloat")},setUniformBoolean(){I("setUniformBoolean")},setUniformTexture(){I("setUniformTexture")},setUniformArray(){I("setUniformArray")},setUniformNull(){I("setUniformNull")},attachCameraToAR(){I("attachCameraToAR")},getDisplaySize(){return I("getDisplaySize"),new Float32Array(0)},setVisible(){I("setVisible")},isVisible(){return I("isVisible"),!1},createGlb(){I("createGlb")},setGlbCulling(){I("setGlbCulling")},setEarlyUpdate(){I("setEarlyUpdate")},setLateUpdate(){I("setLateUpdate")},setOnPhysicsEvent(){I("setOnPhysicsEvent")},loadClips(){I("loadClips")},createClipFromTracks(){return I("createClipFromTracks"),0},getClipSetInfo(){return I("getClipSetInfo"),[]},deriveClip(){return I("deriveClip"),0},setClipEvents(){I("setClipEvents")},getGlbClipSet(){return I("getGlbClipSet"),0},destroyClipSet(){I("destroyClipSet")},animatorCreate(){return I("animatorCreate"),0},animatorDestroy(){I("animatorDestroy")},animatorBind(){return I("animatorBind"),0},animatorBoundTracks(){return I("animatorBoundTracks"),0},animatorSetBlend(){I("animatorSetBlend")},animatorSetBlendValue(){I("animatorSetBlendValue")},animatorPlay(){I("animatorPlay")},animatorStop(){I("animatorStop")},animatorSeek(){I("animatorSeek")},animatorGetSlotTime(){return I("animatorGetSlotTime"),0},animatorGetSlotWeight(){return I("animatorGetSlotWeight"),0},animatorSetLayer(){I("animatorSetLayer")},animatorSetGlobal(){I("animatorSetGlobal")},animatorSetRootMotion(){I("animatorSetRootMotion")},animatorGetRootMotion(){I("animatorGetRootMotion")},setOnAnimatorEvent(){I("setOnAnimatorEvent")},animatorSetFeet(){I("animatorSetFeet")},animatorSlotCurveAt(){return I("animatorSlotCurveAt"),0},animatorSlotCurveInfo(){return I("animatorSlotCurveInfo"),!1},animatorSlotTurn(){return I("animatorSlotTurn"),0},animatorSlotTimeAtTurn(){return I("animatorSlotTimeAtTurn"),0},animatorLayerPhase(){return I("animatorLayerPhase"),0},animatorSeekPhase(){I("animatorSeekPhase")},animatorSlotFit(){return I("animatorSlotFit"),0},animatorSlotExit(){return I("animatorSlotExit"),0},animatorSlotAlign(){return I("animatorSlotAlign"),0},animatorSlotContacts(){return I("animatorSlotContacts"),0},animatorSlotTreads(){return I("animatorSlotTreads"),0},animatorSlotPhysics(){return I("animatorSlotPhysics"),0},animatorSlotFeatures(){return I("animatorSlotFeatures"),0},animatorKneeAxis(){return I("animatorKneeAxis"),0},animatorSlotKneePole(){return I("animatorSlotKneePole"),0},animatorSetStepWarp(){I("animatorSetStepWarp")},setOnAnimatorStep(){I("setOnAnimatorStep")},animatorSetMotion(){I("animatorSetMotion")},animatorSetDriveInput(){I("animatorSetDriveInput")},animatorSetSlotDrive(){I("animatorSetSlotDrive")},animatorSetWarpParams(){I("animatorSetWarpParams")},locoCreate(){return I("locoCreate"),0},locoDestroy(){I("locoDestroy")},locoSetParams(){I("locoSetParams")},locoDefaults(){I("locoDefaults")},locoSetEntry(){I("locoSetEntry")},locoClearSet(){I("locoClearSet")},locoSetInput(){I("locoSetInput")},locoStep(){I("locoStep")},locoUpdate(){I("locoUpdate")},locoRead(){I("locoRead")},locoBuildDatabase(){return I("locoBuildDatabase"),0},setColliderFromMesh(){I("setColliderFromMesh")},setColliderBox(){I("setColliderBox")},setColliderSphere(){I("setColliderSphere")},physicsHasSupport(){return I("physicsHasSupport"),!1},physicsConfigure(){I("physicsConfigure")},setInterpolation(){I("setInterpolation")},physicsBuildBox(){return I("physicsBuildBox"),0},physicsBuildSphere(){return I("physicsBuildSphere"),0},physicsBuildCylinder(){return I("physicsBuildCylinder"),0},physicsBuildCapsule(){return I("physicsBuildCapsule"),0},physicsBuildMesh(){return I("physicsBuildMesh"),0},physicsBuildMeshFromEntity(){return I("physicsBuildMeshFromEntity"),0},physicsDestroyShape(){I("physicsDestroyShape")},physicsCreateBody(){return I("physicsCreateBody"),0},physicsSetPickable(){I("physicsSetPickable")},physicsSetFriction(){I("physicsSetFriction")},physicsGetFriction(){return I("physicsGetFriction"),0},physicsRaycast(){return I("physicsRaycast"),0},characterCreate(){return I("characterCreate"),0},characterDestroy(){I("characterDestroy")},characterMove(){I("characterMove")},characterMoveFree(){I("characterMoveFree")},characterSetVerticalVelocity(){I("characterSetVerticalVelocity")},characterSetVelocity(){I("characterSetVelocity")},characterSetGravityScale(){I("characterSetGravityScale")},characterSetMaxSlope(){I("characterSetMaxSlope")},characterGetVelocity(){I("characterGetVelocity")},characterGetGroundState(){return I("characterGetGroundState"),0},characterSetPosition(){I("characterSetPosition")},vehicleCreate(){return I("vehicleCreate"),0},vehicleDestroy(){I("vehicleDestroy")},vehicleSetInput(){I("vehicleSetInput")},vehicleGetState(){I("vehicleGetState")},vehicleReset(){I("vehicleReset")},vehicleBodyId(){return I("vehicleBodyId"),0},physicsCreateBox(){return I("physicsCreateBox"),0},physicsCreateSphere(){return I("physicsCreateSphere"),0},physicsCreateCylinder(){return I("physicsCreateCylinder"),0},physicsSetLinearVelocity(){I("physicsSetLinearVelocity")},physicsGetLinearVelocity(){I("physicsGetLinearVelocity")},physicsApplyImpulse(){I("physicsApplyImpulse")},physicsSetBodyPosition(){I("physicsSetBodyPosition")},physicsRemoveBody(){I("physicsRemoveBody")},createMediaPlayerTexture(){return I("createMediaPlayerTexture"),0},getName(){return I("getName"),""},setName(){I("setName")},hasMesh(){return I("hasMesh"),!1},createARController(){I("createARController")},createRootAnchor(){return I("createRootAnchor"),0},createAnchor(){return I("createAnchor"),0},createParticleSystem(){I("createParticleSystem")},spawnParticles(){I("spawnParticles")},setParticleSystemConfig(){I("setParticleSystemConfig")},createNoise(){return I("createNoise"),0},setNoiseFrequency(){I("setNoiseFrequency")},setNoiseOctaves(){I("setNoiseOctaves")},setNoiseFractalLunacrity(){I("setNoiseFractalLunacrity")},setNoiseFractalGain(){I("setNoiseFractalGain")},getNoise2D(){return I("getNoise2D"),0},getNoise3D(){return I("getNoise3D"),0},captureImage(){I("captureImage")}},Yc=""+new URL("neutral_ibl128-D-lzdkLN.ktx",import.meta.url).href,Kc={backend:"webgl-lite"},mn=60,Gs=.01,Vs=1e3,Qc={baseColorFactor:"uBaseColorFactor",metallicFactor:"uMetallic",roughnessFactor:"uRoughness",emissiveFactor:"uEmissive",baseColorMap:"uBaseColorMap",baseColorIndex:"uBaseColorIndex"},Zc=async(t,e={})=>{var Xt;const{fetch:r,getBlob:n,getBuffer:s,getLocalName:i,hasLocalBuffer:o,putBuffer:l,putLocalBuffer:a,getPlayer:f,removePlayers:p}=e.stores??La,g=new Yi({canvas:t,dpr:1,alpha:e.transparent===!0||e.alpha===!0,antialias:!0,premultipliedAlpha:!0,powerPreference:"high-performance",preserveDrawingBuffer:((Xt=e.preloads)==null?void 0:Xt.has("capture"))??!1}),h=g.gl;g.autoClear=!1;const v=dl(h),M=ml(h);for(const b of["lit.filamat","unlit.filamat","unlit-transparent.filamat","video.filamat","shadow.filamat","particles.filamat","particles-quad.filamat","terrain.filamat"])o(b)||a(b,new ArrayBuffer(0));const d={sunDirection:{value:[0,-1,0]},sunColorIntensity:{value:[1,1,1,0]},iblLuminance:{value:0},iblSH:{value:new Array(27).fill(0)},envMap:{value:M},envMapMaxLod:{value:0},shadowMap:{value:v},shadowEnabled:{value:0},shadowMapSize:{value:1024},shadowMatrix:{value:$e()},exposure:{value:Ua},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)},uTonemap:{value:1}},y={value:[0,0,0,0]};let x=null;fetch(Yc).then(b=>b.arrayBuffer()).then(b=>{x=il(h,b),d.envMap.value=x.cubemap,d.envMapMaxLod.value=x.maxLod,d.iblSH.value=Array.from(x.sh)}).catch(b=>console.warn("[viewer-lite] IBL load failed:",b));const P=new Map,B=new Map,T=new Map,E=new Map,c=new Map,u=new Map,m={value:1},w=new Map;let _=1,L=!0,z=!0,N=null;const $=[],k=b=>{let S=P.get(b);if(!S){const F=new mt;F.matrixAutoUpdate=!1,F._entId=b,S={transform:F,drawables:[]},P.set(b,S)}return S},J=(b,S=!1)=>{let F,O=null;if(b==="lit")O=Va,F=new Ue(h,{vertex:Kt,fragment:O,uniforms:{...d,baseColor:{value:[1,1,1]},baseColorMap:{value:v},roughness:{value:0},metallic:{value:0}}});else if(b==="terrain")O=Ha,F=new Ue(h,{vertex:Kt,fragment:O,uniforms:{...d,control:{value:v},albedo0:{value:v},albedo1:{value:v},albedo2:{value:v},albedo3:{value:v},normals01:{value:v},normals23:{value:v},tiling:{value:[8,8,8,8]},roughness:{value:[1,1,1,1]},normalScale:{value:[0,0,0,0]},triplanar:{value:[0,0,0,0]},gridSize:{value:[2,2]},cellSize:{value:1},tint:{value:[1,1,1]}}});else if(b==="video")O=$a,F=new Ue(h,{vertex:Kt,fragment:O,uniforms:{baseColorMap:{value:v},shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap}});else if(b==="shadow")O=ja,F=new Ue(h,{vertex:Kt,fragment:O,uniforms:{...d,color:{value:[0,0,0,.66]}},transparent:!0}),F.setBlendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA);else if(b==="particles"||b==="particles-quad"){const U=b==="particles-quad";F=new Ue(h,{vertex:U?Ja:Qa,fragment:U?el:Za,uniforms:{baseColorMap:{value:v},sheetSize:{value:[1,1]},emissive:{value:0},additive:{value:0},softness:{value:0},depthFade:{value:0},uTonemap:d.uTonemap,...U?{mode:{value:0},stretch:{value:0},emissiveMap:{value:v},emissiveColor:{value:[0,0,0]},frameBlend:{value:0}}:{perspScale:m}},transparent:!0,depthWrite:!1,cullFace:!1}),F.setBlendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA)}else O=S?Wa:ka,F=new Ue(h,{vertex:Kt,fragment:O,uniforms:{baseColor:{value:[1,1,1,1]},baseColorMap:{value:v},shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap},transparent:S}),S&&F.setBlendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA);return O===null?{kind:b,program:F}:{kind:b,program:F,source:Y(O)}},Y=b=>({fragment:()=>b,vertex:""}),D=b=>{const S=yl(s(b));if(!S)return null;if(S.unsupported)return console.warn(`[viewer-lite] custom material not supported in lite (${S.unsupported}) — rendering unlit`),null;S.hasVertexBlock&&console.warn("[viewer-lite] custom material has a vertex{} block — the custom vertex stage is ignored in lite");const F=bl(S);if(!F)return null;const O=F.needsSceneUniforms?{...d,userTime:y}:{shadowMatrix:d.shadowMatrix,uTonemap:d.uTonemap,userTime:y};for(const Z of F.uniforms)O[Z.key]={value:Z.value==="texture"?v:Z.value};const U=S.blending==="opaque"||S.blending==="masked",j=new Ue(h,{vertex:Kt,fragment:F.fragment,uniforms:O,transparent:!U,cullFace:S.doubleSided||S.culling==="none"?!1:S.culling==="front"?h.FRONT:h.BACK,depthWrite:S.depthWrite});return h.getProgramParameter(j.program,h.LINK_STATUS)?(U||j.setBlendFunc(h.ONE,S.blending==="add"?h.ONE:h.ONE_MINUS_SRC_ALPHA),{kind:"custom",program:j,source:Y(F.fragment),customParams:F.paramNames}):(console.warn("[viewer-lite] custom material failed to compile — rendering unlit"),null)},X=(b,S)=>{const F=b.startsWith("lit")?"lit":b.startsWith("unlit")?"unlit":b.startsWith("video")?"video":b.startsWith("shadow")?"shadow":b.startsWith("terrain")?"terrain":b.startsWith("particles-quad")?"particles-quad":b.startsWith("particles")?"particles":"unknown";if(F==="unknown"&&S!==void 0){const O=D(S);if(O)return O;console.warn(`[viewer-lite] custom shader can't run here (material "${b||S}") — rendering unlit`)}return J(F,b.startsWith("unlit-transparent"))},V=(b,S)=>{if(!b.source)return b.program;const F=ai(S);if(F===b.source.vertex)return b.program;b.variants??(b.variants=new Map);let O=b.variants.get(F);if(O===void 0){const U=b.program,j=new Ue(h,{vertex:vn(F),fragment:b.source.fragment(F),uniforms:U.uniforms,transparent:U.transparent,cullFace:U.cullFace,frontFace:U.frontFace,depthTest:U.depthTest,depthWrite:U.depthWrite,depthFunc:U.depthFunc});j.blendFunc={...U.blendFunc},j.blendEquation={...U.blendEquation},h.getProgramParameter(j.program,h.LINK_STATUS)?O=j:(j.remove(),O=null,console.warn(`[viewer-lite] a "${b.kind}" material has no variant for [${F}] — the mesh is drawn with its base program`)),b.variants.set(F,O)}return O??b.program},q=b=>{const S=[b.program];if(b.variants)for(const F of b.variants.values())F&&S.push(F);return S},ae=(b,S)=>{var U;const F=b.kind==="gltf"?Qc[S]??S:(U=b.customParams)!=null&&U.has(S)?`materialParams_${S}`:S,O=b.program.uniforms;return O[F]||(O[F]={value:0}),O[F]},ee=(b,S,F)=>{const O=E.get(b);if(!O)return;if(S==="useBaseColorMap"&&(O.kind==="lit"||O.kind==="unlit")){if(F.kind==="bool"&&!F.v){const j=ae(O,"baseColorMap");j.value instanceof qe&&(j.value=v)}return}const U=ae(O,S);switch(F.kind){case"rgb":{const[j,Z,te]=Ya(F.v);Array.isArray(U.value)&&U.value.length===4?U.value=[j,Z,te,U.value[3]]:U.value=[j,Z,te];break}case"rgba":{const j=Ka(F.v);U.value=Array.isArray(U.value)&&U.value.length===3?j.slice(0,3):j;break}case"float":U.value=F.v;break;case"bool":U.value=F.v?1:0;break;case"array":U.value=Float32Array.from(F.v);break;case"texture":{const j=c.get(F.v);j&&(U.value=j);break}case"null":U.value instanceof qe&&(U.value=v);break}},se=(b,S)=>{S.kind!=="lit"&&S.kind!=="gltf"&&S.kind!=="shadow"&&S.kind!=="custom"||b.onBeforeRender(()=>{const F=b.program.uniforms;if(F.shadowEnabled){const O=d.shadowEnabled.value===1&&b._receiveShadows!==!1;F.shadowEnabled=O?d.shadowEnabled:{value:0}}})},ue=(b,S,F,O)=>{const U=E.get(S);if(!U)return;const{vertices:j,normals:Z,indices:te,uv:de,colors:fe}=F,ye=new ht(h,{position:{size:3,data:Float32Array.from(j)},normal:{size:3,data:Z.length?Float32Array.from(Z):new Float32Array(j.length)},uv:{size:2,data:de.length?Float32Array.from(de):new Float32Array(j.length/3*2)},...fe&&fe.length?{color:{size:4,data:Float32Array.from(fe,ze=>ze/255)}}:{},index:{data:Uint16Array.from(te)}});ye.computeBoundingBox();const be=O===1?h.LINES:O===2?h.POINTS:h.TRIANGLES,ve=new et(h,{geometry:ye,program:U.program,mode:be});ve.program=V(U,ve),ve.matrixAutoUpdate=!1,ve._entId=b,ve._castShadows=L,ve._receiveShadows=z,se(ve,U);const Ae=k(b);for(const ze of Ae.drawables){Ae.transform.removeChild(ze);const at=ne.get(ze);at&&(at.setParent(null),ne.delete(ze))}Ae.drawables=[ve],Ae.transform.addChild(ve)},xe=async(b,S,F)=>{const O=s(b);let U;try{U=await vl(h,O,d,v)}catch(j){console.warn(`[viewer-lite] GLB "${i(b)??b}" drawables failed to load:`,j instanceof Error?j.message:j);return}U.nodes.forEach((j,Z)=>{const te=F[Z];if(te===void 0)return;const de=k(te);de.transform.setParent(null),ce.rebindMatrix(te,j.matrix),j.matrixAutoUpdate=!1,j._entId=te,de.transform=j,de.drawables=[];for(const fe of j.children)fe.draw&&(fe.matrixAutoUpdate=!1,fe._entId=te,fe._castShadows=L,fe._receiveShadows=z,de.drawables.push(fe))});for(const j of U.roots)j.setParent(k(S).transform)},me=[],je=(b,S)=>{const F=k(b),O=k(S);for(const U of F.drawables){const j=U instanceof Et?new Et(h,{skeleton:U.skeleton,geometry:U.geometry,program:U.program,mode:U.mode}):new et(h,{geometry:U.geometry,program:U.program,mode:U.mode});j instanceof Et&&me.push(j);const Z=U._morph;Z&&(j._morph=Z,li(j,Z)),j._entId=S,j._castShadows=U._castShadows,j._receiveShadows=U._receiveShadows,j.frustumCulled=U.frustumCulled,j.matrixAutoUpdate=!1,O.drawables.push(j),O.transform.addChild(j)}},Qe=b=>{for(const S of me.splice(0)){const F=S.skeleton.joints.map(O=>{const U=O._entId===void 0?void 0:b.get(O._entId);if(U===void 0)return O;const j=k(U).transform;return j.bindInverse=O.bindInverse,j});S.skeleton={...S.skeleton,joints:F}}};let A="off";const C={value:[.05,.06,.08]},R=new Ue(h,{vertex:Kt,fragment:us,uniforms:{uWireColor:C,shadowMatrix:d.shadowMatrix}}),W=new Ue(h,{vertex:vn("HAS_SKIN"),fragment:us,uniforms:{uWireColor:C,shadowMatrix:d.shadowMatrix,boneTexture:{value:v},boneTextureSize:{value:4}}}),ie=new WeakMap,ne=new WeakMap,Se=b=>{var F;let S=ie.get(b);if(!S){const O={};for(const[Z,te]of Object.entries(b.attributes))Z!=="index"&&(O[Z]={size:te.size,data:te.data,type:te.type,normalized:te.normalized,stride:te.stride,offset:te.offset,buffer:te.buffer,count:te.count});const U=b.attributes.position,j=U?U.count??U.data.length/U.size:0;O.index={data:fl((F=b.attributes.index)==null?void 0:F.data,j)},S=new ht(h,O),ie.set(b,S)}return S},Ce=b=>{var O,U;let S=ne.get(b);if(S)return S;if(!b.parent||!((U=(O=b.geometry)==null?void 0:O.attributes)!=null&&U.position))return null;const F=Se(b.geometry);return S=b instanceof Et?new Et(h,{skeleton:b.skeleton,geometry:F,program:W,mode:h.LINES}):new et(h,{geometry:F,program:R,mode:h.LINES}),S.frustumCulled=!1,S.matrixAutoUpdate=!1,S.matrix.copy(b.matrix),S._entId=b._entId,S._castShadows=!1,S._receiveShadows=!1,S.setParent(b.parent),ne.set(b,S),Ne(),S},Oe=()=>{for(const b of P.values())for(const S of b.drawables)if(S.mode===h.TRIANGLES)if(A==="off"){S.visible=!0;const F=ne.get(S);F&&(F.visible=!1)}else{const F=Ce(S);S.visible=A==="overlay",F&&(F.visible=!0)}},Ve=()=>{for(const b of $)b.video.videoWidth===0||b.video.currentTime===b.lastTime||(b.texture.image=b.video,b.texture.needsUpdate=!0,b.lastTime=b.video.currentTime)},Ie=new Mn(h,{fov:mn,near:Gs,far:Vs,aspect:1});Ie.matrixAutoUpdate=!1;let Ge=!1,Ze=e.transparent===!0,rt=0,ut=0,Tt=mn,Nt=Gs,$t=Vs,Pt=1,pt=null,Ye=0;const xt=new Ue(h,{vertex:Er(!1),fragment:Cr,uniforms:{modelMatrix:{value:$e()},shadowViewProjection:{value:$e()}},cullFace:h.FRONT}),Rt=new Ue(h,{vertex:Er(!0),fragment:Cr,uniforms:{modelMatrix:{value:$e()},shadowViewProjection:{value:$e()},boneTexture:{value:v},boneTextureSize:{value:4}},cullFace:h.FRONT}),wr=new Ue(h,{vertex:Er(!1,!0),fragment:Cr,uniforms:{shadowViewProjection:{value:$e()}},cullFace:h.FRONT}),jt=new Map;let Br=!0;const rr=b=>{let S=jt.get(b);return S||(S=lc(h,g),S.setEnabled(Br),jt.set(b,S)),S};let Ot=0;const Ne=()=>{Ot++},Wr=new Map,$r=b=>{Wr.get(b)!==Ot&&(b.updateMatrixWorld(),Wr.set(b,Ot))},jr=(b,S,F=!1)=>{const O=rr(b);$r(b),O.collect(b,S,!0,Ot,F),O.drawMain(S,d.shadowEnabled),F&&Ne()},G=b=>{var S;for(const[F,O]of ce.entities)if(O.light&&ce.methods.isVisible(F)&&((S=ce.sceneOf(F))==null?void 0:S.id)===b)return O.light;return null};let Q=!1;const H=b=>{var de,fe;const S=(de=ce.scenes.get(b))==null?void 0:de.camera,F=S!==void 0?ce.worldMatrix(S):$e(),O=[];for(const[ye,be]of ce.entities){const ve=be.punctual;if(!ve||!(ve.intensity>0)||!ce.methods.isVisible(ye)||((fe=ce.sceneOf(ye))==null?void 0:fe.id)!==b)continue;const Ae=ce.worldMatrix(ye);O.push({id:ye,p:ve,w:Ae,near:Math.hypot(Ae[12]-F[12],Ae[13]-F[13],Ae[14]-F[14])-ve.range})}O.length>Jt&&(O.sort((ye,be)=>ye.near-be.near),Q||(Q=!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),j=d.punctualPos.value,Z=d.punctualColor.value,te=d.punctualDir.value;for(let ye=0;ye<U;ye++){const{p:be,w:ve}=O[ye],Ae=ye*4;j[Ae]=ve[12],j[Ae+1]=ve[13],j[Ae+2]=ve[14],j[Ae+3]=1/(be.range*be.range);const ze=be.intensity/(be.type==="spot"?Math.PI:4*Math.PI);Z[Ae]=(be.color>>>16&255)/255*ze,Z[Ae+1]=(be.color>>>8&255)/255*ze,Z[Ae+2]=(be.color&255)/255*ze;const at=-ve[8],At=-ve[9],Je=-ve[10],It=Math.hypot(at,At,Je)||1;if(te[Ae]=at/It,te[Ae+1]=At/It,te[Ae+2]=Je/It,be.type==="spot"){const Dt=Math.cos(be.outer),qt=1/Math.max(1/1024,Math.cos(be.inner)-Dt);Z[Ae+3]=qt,te[Ae+3]=-Dt*qt}else Z[Ae+3]=0,te[Ae+3]=1}d.punctualCount.value=U},K=b=>{const S=[];return b.traverse(F=>F.visible?(F.draw&&S.push(F),!1):!0),S},oe=(b,S)=>{const F=S.shadowsQuality>=3?4096:S.shadowsQuality>=2?2048:1024;(!pt||Ye!==F)&&(pt=new Ks(h,{width:F,height:F,depthTexture:!0}),Ye=F);const O=rr(b),U=O.casterSingles,j=[1/0,1/0,1/0],Z=[-1/0,-1/0,-1/0],te=[0,0,0];for(const Lt of U){const vt=Lt.geometry;if(vt.bounds||vt.computeBoundingBox(),!vt.bounds||!isFinite(vt.bounds.min.x))continue;const Nr=Lt.worldMatrix;for(let Yt=0;Yt<8;Yt++){Ct(te,Nr,Yt&1?vt.bounds.max.x:vt.bounds.min.x,Yt&2?vt.bounds.max.y:vt.bounds.min.y,Yt&4?vt.bounds.max.z:vt.bounds.min.z,1);for(let _t=0;_t<3;_t++)te[_t]<j[_t]&&(j[_t]=te[_t]),te[_t]>Z[_t]&&(Z[_t]=te[_t])}}if(O.casterBounds(j,Z),!isFinite(j[0])){d.shadowEnabled.value=0;return}const[de,fe,ye]=j,[be,ve,Ae]=Z,ze=(de+be)/2,at=(fe+ve)/2,At=(ye+Ae)/2,Je=Math.max(.5,Math.hypot(be-de,ve-fe,Ae-ye)/2);let It=S.direction[0],Dt=S.direction[1],qt=S.direction[2];const Xr=Math.hypot(It,Dt,qt)||1;It/=Xr,Dt/=Xr,qt/=Xr;const Bt=[ze-It*Je*2,at-Dt*Je*2,At-qt*Je*2],nr=-It,sr=-Dt,ir=-qt,or=Math.abs(Dt)>.99?[1,0,0]:[0,1,0];let ar=or[1]*ir-or[2]*sr,lr=or[2]*nr-or[0]*ir,cr=or[0]*sr-or[1]*nr;const qr=Math.hypot(ar,lr,cr)||1;ar/=qr,lr/=qr,cr/=qr;const Sn=sr*cr-ir*lr,_n=ir*ar-nr*cr,En=nr*lr-sr*ar,ft=new Float32Array(16);ft[0]=ar,ft[4]=lr,ft[8]=cr,ft[1]=Sn,ft[5]=_n,ft[9]=En,ft[2]=nr,ft[6]=sr,ft[10]=ir,ft[12]=-(ar*Bt[0]+lr*Bt[1]+cr*Bt[2]),ft[13]=-(Sn*Bt[0]+_n*Bt[1]+En*Bt[2]),ft[14]=-(nr*Bt[0]+sr*Bt[1]+ir*Bt[2]),ft[15]=1;const pi=Oa(-Je,Je,-Je,Je,.05,Je*4),Lr=wt(new Float32Array(16),pi,ft);xt.uniforms.shadowViewProjection.value=Lr,Rt.uniforms.shadowViewProjection.value=Lr,wr.uniforms.shadowViewProjection.value=Lr,d.shadowMatrix.value=Lr,d.shadowMap.value=pt.depthTexture,d.shadowMapSize.value=F,d.shadowEnabled.value=1,g.bindFramebuffer(pt),g.setViewport(F,F),h.clearColor(1,1,1,1),g.enable(h.DEPTH_TEST),g.setDepthMask(!0),h.clear(h.COLOR_BUFFER_BIT|h.DEPTH_BUFFER_BIT);const gi=$e();for(const Lt of U){const vt=Lt instanceof Et,Nr=vt?Rt:xt,Yt=Lt.program;Nr.uniforms.modelMatrix.value=vt?gi:Lt.worldMatrix,Lt.program=Nr,Lt.draw({}),Lt.program=Yt}O.drawShadow(wr),g.bindFramebuffer({buffer:null})};let re=null,le=null,he=null,pe=null;const we=b=>{he===null&&(he=cc(h),he||console.warn("[viewer-lite] bloom needs EXT_color_buffer_float — drawn without"));const S=t.width,F=t.height;if(!he||S===0||F===0)return null;pe??(pe=hc(h,4));const O=b.antialias===!1?0:pe;return(!re||re.width!==S||re.height!==F||re.samples!==O)&&(re==null||re.dispose(),re=uc(h,g,S,F,O),re||(he=!1,console.warn("[viewer-lite] bloom target is incomplete on this driver — drawn without"))),re},_e=b=>{let S=rt===0?0:(b-rt)/1e3;S>.05&&(S=.05),rt=b;const F=b/1e3;y.value[0]=F,y.value[1]=F-Math.floor(F),ce.tick(S)},ge=b=>{var te;const S=t.width/Math.max(1,t.height),{fov:F,near:O,far:U}=ce.projectionOf(b);m.value=Math.max(1,t.height)/(2*Math.tan(F*Math.PI/360)),(S!==ut||F!==Tt||O!==Nt||U!==$t)&&(ut=S,Tt=F,Nt=O,$t=U,Ie.perspective({fov:F,aspect:S,near:O,far:U}));const j=(te=ce.scenes.get(b))==null?void 0:te.camera,Z=j!==void 0?ce.worldMatrix(j):$e();for(let de=0;de<16;de++)Ie.matrix[de]=Z[de];Ie.worldMatrixNeedsUpdate=!0},Me=b=>{const S=ce.activeSceneId(),F=ce.scenes.get(S),O=B.get(S);if(!F||!O)return!1;_e(b),Ve(),ge(S),A!=="off"?(Oe(),h.enable(h.POLYGON_OFFSET_FILL),h.polygonOffset(1,1)):h.disable(h.POLYGON_OFFSET_FILL),$r(O);const U=rr(O);U.collect(O,Ie,!0,Ot);const j=G(S);if(j){const ye=(j.color>>>16&255)/255,be=(j.color>>>8&255)/255,ve=(j.color&255)/255;d.sunDirection.value=j.direction,d.sunColorIntensity.value=[ye,be,ve,j.intensity],j.shadowsQuality>0?oe(O,j):d.shadowEnabled.value=0}else d.sunColorIntensity.value=[1,1,1,0],d.shadowEnabled.value=0;H(S),d.iblLuminance.value=F.ibl??0;const Z=N?void 0:F.bloom,te=Z?we(F):null;d.uTonemap.value=te?0:1;const de=F.skybox!==void 0?[(F.skybox>>>16&255)/255,(F.skybox>>>8&255)/255,(F.skybox&255)/255]:[.1,.25,.57],fe=te?de:de.map(qa);te?te.bindDraw():g.bindFramebuffer({buffer:null}),g.setViewport(t.width,t.height),Ze?h.clearColor(0,0,0,0):h.clearColor(fe[0],fe[1],fe[2],1),g.enable(h.DEPTH_TEST),g.setDepthMask(!0),h.clear(h.COLOR_BUFFER_BIT|h.DEPTH_BUFFER_BIT),U.drawMain(Ie,d.shadowEnabled),N==null||N.renderScenePass(fe);for(const ye of F.overlays){const be=B.get(ye);be&&(h.clear(h.DEPTH_BUFFER_BIT),jr(be,Ie))}if(N==null||N.renderOverlayPass(),N==null||N.renderPreviewPass(O,fe),te&&Z){te.resolve(),le??(le=wc(h,g));const ye=le.run(te.texture,te.width,te.height,Z);le.compose(te.texture,ye.texture,Z.strength/ye.levels,t.width,t.height)}return!0},Be=new Set,Te=()=>{if(Ge){try{Me(performance.now())}catch(b){const S=b instanceof Error?b.message:String(b);Be.has(S)||(Be.add(S),console.error("[viewer-lite] render frame failed:",b))}requestAnimationFrame(Te)}},Le=b=>{var S;return(S=ce.sceneOf(b))==null?void 0:S.id};let De=[0,0,0];const Re=(b,S,F)=>{var Je;const O=(Je=ce.scenes.get(b))==null?void 0:Je.camera,U=O!==void 0?ce.worldMatrix(O):$e(),j=Math.max(1,t.width),Z=Math.max(1,t.height),te=j/Z,de=S*Pt,fe=F*Pt,ye=Math.tan(ce.projectionOf(b).fov*Math.PI/360),be=(de/j*2-1)*ye*te,ve=(1-fe/Z*2)*ye,Ae=U[0]*be+U[4]*ve-U[8],ze=U[1]*be+U[5]*ve-U[9],at=U[2]*be+U[6]*ve-U[10],At=Math.hypot(Ae,ze,at)||1;return De=[U[12],U[13],U[14]],{origin:De,dir:[Ae/At,ze/At,at/At]}},Pe=(b,S,F)=>{const O=T.get(b);if(!O)return 0;let U=1/0,j=0;const Z=[0,0,0],te=[0,0,0];for(const[de,fe]of O){if(!ce.entities.has(de)||!ce.methods.isVisible(de))continue;const ye=Ft(ce.worldMatrixF(de));Ct(Z,ye,S[0],S[1],S[2],1),Ct(te,ye,F[0],F[1],F[2],0);const be=fe.type==="box"?hs(fe.center,fe.extent,Z,te):Ia(fe.center,fe.radius,Z,te);be>0&&be<U&&(U=be,j=de)}return j},Xe=(b,S,F)=>{const O=B.get(b);if(!O)return 0;let U=1/0,j=0;const Z=[0,0,0],te=[0,0,0];O.updateMatrixWorld();for(const de of K(O)){const fe=de.geometry;if(fe.bounds||fe.computeBoundingBox(),!fe.bounds||!isFinite(fe.bounds.min.x))continue;const ye=Ft(de.worldMatrix);Ct(Z,ye,S[0],S[1],S[2],1),Ct(te,ye,F[0],F[1],F[2],0);const be=[(fe.bounds.min.x+fe.bounds.max.x)/2,(fe.bounds.min.y+fe.bounds.max.y)/2,(fe.bounds.min.z+fe.bounds.max.z)/2],ve=[(fe.bounds.max.x-fe.bounds.min.x)/2,(fe.bounds.max.y-fe.bounds.min.y)/2,(fe.bounds.max.z-fe.bounds.min.z)/2],Ae=hs(be,ve,Z,te);Ae>0&&Ae<U&&(U=Ae,j=de._entId??0)}return j},He=(b,S)=>{const F=ce.activeSceneId(),O=ce.scenes.get(F);if(!O||O.camera===void 0)return 0;const{origin:U,dir:j}=Re(F,b,S);for(let Z=O.overlays.length-1;Z>=0;Z--){const te=Pe(O.overlays[Z],U,j);if(te!==0)return te}return Pe(F,U,j)},ke=b=>{b.mesh&&b.mesh.setParent(null),b.buffer&&h.deleteBuffer(b.buffer),b.mesh=null,b.geometry=null,b.buffer=null},nt=(b,S)=>{const F=E.get(b.materialId);if(S===Ut.MESH)return(F??J("unlit")).program;const O=S!==Ut.POINTS;return F&&F.kind===(O?"particles-quad":"particles")?F.program:J(O?"particles-quad":"particles").program},it=(b,S,F)=>{if(ke(S),S.version=F.geometryVersion,S.mode=F.mode,F.capacity===0)return;const O=ce.particleIndexPattern(b);if(O.length===0)return;let U;if(F.mode===Ut.MESH){const Z=F.capacity*F.meshVertexCount;U=new ht(h,{position:{size:3,data:new Float32Array(Z*3),usage:h.DYNAMIC_DRAW},normal:{size:3,data:new Float32Array(Z*3),usage:h.DYNAMIC_DRAW},uv:{size:2,data:new Float32Array(Z*2),usage:h.DYNAMIC_DRAW},index:{data:O}})}else{const Z=h.createBuffer();S.buffer=Z;const te=F.stride,de=F.mode===Ut.POINTS?F.capacity:F.mode===Ut.QUADS?F.capacity*4:(F.capacity+1)*2,fe=(be,ve)=>({size:be,type:h.FLOAT,buffer:Z,stride:te,offset:ve,count:de,data:new Float32Array(0)}),ye={position:fe(3,0),color:fe(4,12),custom:fe(4,28)};F.mode!==Ut.POINTS&&(ye.aux=fe(3,44),ye.corner=fe(2,56)),ye.index={data:Uint16Array.from(O)},U=new ht(h,ye),h.bindBuffer(h.ARRAY_BUFFER,Z),h.bufferData(h.ARRAY_BUFFER,de*te,h.DYNAMIC_DRAW),g.state.boundBuffer=Z}const j=new et(h,{geometry:U,program:nt(S,F.mode),mode:F.mode===Ut.POINTS?h.POINTS:h.TRIANGLES});j.frustumCulled=!1,j.matrixAutoUpdate=!1,j._entId=b,j._particles=!0,j.setParent(k(b).transform),S.geometry=U,S.mesh=j},bt=(b,S)=>{let F=u.get(b);if(F||(F={materialId:0,mesh:null,geometry:null,buffer:null,version:0,mode:-1},u.set(b,F)),(F.version!==S.geometryVersion||F.mode!==S.mode||!F.mesh)&&(it(b,F,S),Ne()),!F.mesh||!F.geometry)return;const O=S.indexCount>0;if(F.mesh.visible!==O&&(F.mesh.visible=O,Ne()),!!O){if(F.mesh.renderOrder=S.order,S.mode===Ut.MESH){const U=S.vertexCount,j=new Float32Array(S.bytes.buffer,S.bytes.byteOffset,U*10),Z=F.geometry.attributes.position,te=F.geometry.attributes.normal,de=F.geometry.attributes.uv,fe=Z.data,ye=te.data,be=de.data;for(let ve=0;ve<U;ve++){const Ae=ve*10;fe[ve*3]=j[Ae],fe[ve*3+1]=j[Ae+1],fe[ve*3+2]=j[Ae+2];const ze=j[Ae+3],at=j[Ae+4],At=j[Ae+5],Je=j[Ae+6];ye[ve*3]=2*(ze*At+at*Je),ye[ve*3+1]=2*(at*At-ze*Je),ye[ve*3+2]=1-2*(ze*ze+at*at),be[ve*2]=j[Ae+8],be[ve*2+1]=j[Ae+9]}Z.needsUpdate=te.needsUpdate=de.needsUpdate=!0}else F.buffer&&(h.bindBuffer(h.ARRAY_BUFFER,F.buffer),h.bufferSubData(h.ARRAY_BUFFER,0,S.bytes),g.state.boundBuffer=F.buffer);F.geometry.drawRange.start=0,F.geometry.drawRange.count=S.indexCount}},gt={allocMatrix:b=>k(b).transform.matrix,localMatrixChanged:b=>{k(b).transform.worldMatrixNeedsUpdate=!0,Ne()},parentChanged:(b,S)=>{Ne();const F=k(b).transform;if(S!==0)F.setParent(k(S).transform);else{const O=ce.sceneOf(b);F.setParent((O&&B.get(O.id))??null)}},sceneCreated:b=>{B.set(b,new mt),T.set(b,new Map)},entitySceneChanged:(b,S,F)=>{Ne();const O=B.get(S);if(!O)return;const U=k(b);if(F){for(const[j,Z]of T){if(j===S)continue;const te=Z.get(b);te&&(T.get(S).set(b,te),Z.delete(b))}ce.ent(b).parent===0&&U.transform.setParent(O)}else ce.ent(b).parent===0&&U.transform.parent===O&&U.transform.setParent(null)},visibleChanged:(b,S)=>{k(b).transform.visible=S,Ne()},materialCreated:(b,S,F)=>{E.set(b,X(S.shader,F))},uniformChanged:(b,S,F)=>ee(b,S,F),meshSet:(b,S,F,O)=>{ue(b,S,O,F.kind),Ne()},glbAttach:(b,S,F)=>xe(b,S,F).then(Ne),morphWeights:(b,S)=>{const F=k(b).transform.weights;F&&F.set(S.subarray(0,Math.min(F.length,S.length)))},entityDestroyed:b=>{Ne();const S=P.get(b);S&&(S.transform.setParent(null),P.delete(b));for(const F of T.values())F.delete(b)},entityCloned:(b,S)=>{je(b,S),Ne()},subtreeCloned:(b,S,F)=>Qe(F),particleSystemCreated:(b,S)=>{const F=u.get(b);F?(ke(F),F.materialId=S,F.version=0):u.set(b,{materialId:S,mesh:null,geometry:null,buffer:null,version:0,mode:-1})},particlesFrame:(b,S)=>bt(b,S),particleSystemDestroyed:b=>{const S=u.get(b);S&&(ke(S),u.delete(b)),Ne()}},st=e.twins??{};await Promise.all([st.anim!==!1&&_c(),st.physics!==!1&&Sl(),st.particles!==!1&&Dc()]);const ce=kc(gt,{getBuffer:s,getSourceName:i,width:t.width||1,height:t.height||1,fov:mn}),We=(b,S,F)=>{createImageBitmap(b).then(O=>{const U=new qe(h,{image:O,internalFormat:h.SRGB8_ALPHA8,format:h.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),j=_++;c.set(j,U),S(j,O.width,O.height)}).catch(F)};return{...qc,...Kc,...ce.methods,createEntity:()=>({id:ce.methods.createEntity()}),cloneEntity:b=>({id:ce.methods.cloneEntity(b)}),createMaterial:b=>({id:ce.methods.createMaterial(b)}),builtinMaterial:b=>({id:ce.methods.createMaterialNamed(b)}),createGlb(b,S,F){ce.methods.createGlb(b,O=>S({id:O}),F)},openScene(b){const S=Ge;ce.methods.openScene(b),Ge=ce.scenes.has(b),t.style.display="block",!S&&Ge&&requestAnimationFrame(Te)},closeScene(){t.style.display="none",Ge=!1,ce.methods.closeScene()},launchAR(){throw new Error(Sr)},stopAR(){throw new Error(Sr)},launchVR(b,S,F){F(new Error("VR is not supported on this device"))},stopVR(){},async warmRender(b,S){S()},attachCameraToAR(b,S,F){const O=ce.scenes.get(b);if(O){O.camera=S;for(const U of O.overlays){const j=ce.scenes.get(U);j&&(j.camera=S)}}},getCameraFov(b,S){const F=ce.projectionOf(b).fov;if(S!==1)return F;const O=F*Math.PI/180,U=t.width/Math.max(1,t.height);return 2*Math.atan(Math.tan(O/2)*U)*180/Math.PI},getCameraViewDirection(b,S,F,O){if(!ce.scenes.has(b)){O[0]=0,O[1]=0,O[2]=-1;return}const{dir:U}=Re(b,S,F);O[0]=U[0],O[1]=U[1],O[2]=U[2]},getDisplaySize:()=>Float32Array.of(g.width||t.width,g.height||t.height),createTexture(b,S,F){const O=(j,Z,te)=>S({id:j},Z,te),U=n(b);U.slice(0,12).arrayBuffer().then(async j=>{const Z=await Tr(()=>import("./index-B2zEJlWS.js"),__vite__mapDeps([0,1]),import.meta.url);if(!Z.isKtx2Bytes(new Uint8Array(j)))return!1;const te=await U.arrayBuffer(),de=await Z.transcodeKtx2(h,te),fe=Z.ktx2IsSrgb(te);let ye;de.isCompressedTexture?ye=new qe(h,{image:de,internalFormat:fe&&de.srgbInternalFormat?de.srgbInternalFormat:de.internalFormat,generateMipmaps:!1,minFilter:de.length>1?h.LINEAR_MIPMAP_LINEAR:h.LINEAR,flipY:!1}):ye=new qe(h,{image:de,internalFormat:fe?h.SRGB8_ALPHA8:h.RGBA8,format:h.RGBA,generateMipmaps:!0,flipY:!1,premultiplyAlpha:!1});const be=_++;return c.set(be,ye),O(be,de.width,de.height),!0}).then(j=>{j||We(U,O,F)},F)},createTexturePixels(b,S,F,O,U){if(b<=0||S<=0||O.length<b*S*F)return{id:4294967295};const j=new Uint8Array(b*S*4);for(let de=0,fe=b*S;de<fe;de++){const ye=de*F,be=de*4;j[be]=O[ye],j[be+1]=F>=2?O[ye+1]:O[ye],j[be+2]=F>=3?O[ye+2]:O[ye],j[be+3]=F>=4?O[ye+3]:255}const Z=new qe(h,{image:j,width:b,height:S,internalFormat:U?h.SRGB8_ALPHA8:h.RGBA8,format:h.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1,minFilter:h.LINEAR,magFilter:h.LINEAR}),te=_++;return c.set(te,Z),w.set(te,{rgba:j,width:b,height:S,channels:F}),{id:te}},updateTexturePixels(b,S,F,O,U,j){const Z=w.get(b),te=c.get(b);if(!Z||!te)return;const de=Z.channels;for(let fe=0;fe<U;fe++){const ye=F+fe;if(!(ye<0||ye>=Z.height))for(let be=0;be<O;be++){const ve=S+be;if(ve<0||ve>=Z.width)continue;const Ae=(fe*O+be)*de,ze=(ye*Z.width+ve)*4;Z.rgba[ze]=j[Ae],Z.rgba[ze+1]=de>=2?j[Ae+1]:j[Ae],Z.rgba[ze+2]=de>=3?j[Ae+2]:j[Ae],Z.rgba[ze+3]=de>=4?j[Ae+3]:255}}te.image=Z.rgba,te.needsUpdate=!0},createTextureFromCanvas(b){var U;const S=(U=e.canvasHost)==null?void 0:U.readSurface(b);if(!S)return 0;const F=new qe(h,{image:new Uint8Array(S.data.buffer.slice(0)),width:S.width,height:S.height,internalFormat:h.SRGB8_ALPHA8,format:h.RGBA,generateMipmaps:!1,flipY:!1}),O=_++;return c.set(O,F),O},updateTextureFromCanvas(b,S){var U;const F=(U=e.canvasHost)==null?void 0:U.readSurface(S),O=c.get(b);!F||!O||(O.image=new Uint8Array(F.data.buffer.slice(0)),O.width=F.width,O.height=F.height,O.needsUpdate=!0)},createMediaPlayerTexture(b){const S=f(b),F=new qe(h,{generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1});$.push({video:S,texture:F,lastTime:-1});const O=_++;return c.set(O,F),O},setUniformTexture(b,S,F,O,U){ce.methods.setUniformTexture(b,S,F);const j=E.get(b),Z=c.get(F);if(!j||!Z)return;const te=[h.CLAMP_TO_EDGE,h.REPEAT,h.MIRRORED_REPEAT];Z.wrapS=te[O]??h.REPEAT,Z.wrapT=te[U]??h.REPEAT,Z.needsUpdate=!0,ae(j,S).value=Z},setMaterial(b,S,F){ce.methods.setMaterial(b,S,F);const O=E.get(S),U=k(b).drawables[F];!O||!U||(U.program=V(O,U),se(U,O),Ne())},getMaterial(b,S){const F=k(b).drawables[S];if(!F)return 0;const O=ce.nextMaterialId();return E.set(O,{kind:"gltf",program:F.program,source:F.program._source}),O},setCulling(b,S){for(const F of k(b).drawables)F.frustumCulled=S;Ne()},setGlbCulling(b,S){const F=O=>{for(const U of k(O).drawables)U.frustumCulled=S;for(const U of ce.ent(O).children)F(U)};F(b),Ne()},setRenderPriority(b,S){for(const F of k(b).drawables)F.renderOrder=S;Ne()},setMaterialDepthTest(b,S){const F=E.get(b);if(F)for(const O of q(F))O.depthTest=S},setMaterialDepthWrite(b,S){const F=E.get(b);if(F)for(const O of q(F))O.depthWrite=S},setMaterialCulling(b,S){const F=E.get(b);if(F)for(const O of q(F))O.cullFace=S===0?!1:S===1?h.FRONT:h.BACK},setCastShadows(b,S){ce.methods.setCastShadows(b,S);for(const F of k(b).drawables)F._castShadows=S;Ne()},setReceiveShadows(b,S){ce.methods.setReceiveShadows(b,S);for(const F of k(b).drawables)F._receiveShadows=S;Ne()},setGlbShadows(b,S,F){ce.methods.setGlbShadows(b,S,F);const O=U=>{for(const j of k(U).drawables)j._castShadows=S,j._receiveShadows=F;for(const j of ce.ent(U).children)O(j)};O(b),Ne()},setCastShadowsGlobal(b){L=b},setReceiveShadowsGlobal(b){z=b},setColliderFromMesh(b,S,F){var Z;if(F!==0)return;const O=k(S).drawables[0];if(!O)return;const U=O.geometry;if(U.bounds||U.computeBoundingBox(),!U.bounds)return;const j=Le(b)??ce.activeSceneId();(Z=T.get(j))==null||Z.set(b,{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(b,S,F,O,U,j,Z){var de;const te=Le(b)??ce.activeSceneId();(de=T.get(te))==null||de.set(b,{type:"box",center:[S,F,O],extent:[U/2,j/2,Z/2]})},setColliderSphere(b,S,F,O,U){var Z;const j=Le(b)??ce.activeSceneId();(Z=T.get(j))==null||Z.set(b,{type:"sphere",center:[S,F,O],radius:U})},createARController(){throw new Error(Sr)},createRootAnchor(){throw new Error(Sr)},createAnchor(){throw new Error(Sr)},_renderNow:()=>Me(performance.now()),async captureImage(b,S,F){try{Me(performance.now());const O=new OffscreenCanvas(t.width,t.height);O.getContext("2d").drawImage(t,0,0);const j=await O.convertToBlob({type:"image/png"}),Z=await j.arrayBuffer();S(l(Z),"image.png",j.size)}catch{F()}},raycastView:He,_raycastView:He,raycastPick(b,S){const F=ce.activeSceneId(),O=ce.scenes.get(F);if(!O||O.camera===void 0)return 0;const U=He(b,S);if(U!==0)return U;const{origin:j,dir:Z}=Re(F,b,S);return Xe(F,j,Z)},computeBoundingBox(b){const S=Float32Array.of(1/0,1/0,1/0,-1/0,-1/0,-1/0),F=[0,0,0],O=(U,j)=>{for(const Z of k(U).drawables){const te=Z.geometry;if(te.bounds||te.computeBoundingBox(),!(!te.bounds||!isFinite(te.bounds.min.x)))for(let de=0;de<8;de++){const fe=de&1?te.bounds.max.x:te.bounds.min.x,ye=de&2?te.bounds.max.y:te.bounds.min.y,be=de&4?te.bounds.max.z:te.bounds.min.z;j?Ct(F,j,fe,ye,be,1):(F[0]=fe,F[1]=ye,F[2]=be);for(let ve=0;ve<3;ve++)F[ve]<S[ve]&&(S[ve]=F[ve]),F[ve]>S[ve+3]&&(S[ve+3]=F[ve])}}for(const Z of ce.ent(U).children){const te=k(Z).transform.matrix,de=j?wt(new Float32Array(16),j,te):Float32Array.from(te);O(Z,de)}};return O(b,null),isFinite(S[0])||S.fill(0),S},stopAllPlayers(){p()},_dumpScene3d:()=>Xc(ce),_setWireframeMode(b){A=b==="overlay"||b==="only"?b:"off",C.value=A==="only"?[.62,.66,.72]:[.05,.06,.08],Oe(),Ne()},_setBatching(b){for(const S of jt.values())S.setEnabled(b);Br=b,Ne()},_batchStats(){const b=B.get(ce.activeSceneId());return b?rr(b).stats():{batches:0,instances:0,visible:0,singles:0}},_editorConnect(b){return N??(N=nc({gl:h,renderer:g,canvas:t,camera:Ie,core:ce,sceneRoots:B,drawablesOf:S=>k(S).drawables,collectMeshes:K,wireGeometryFor:Se,getViewRay:Re,renderScene:jr})),N.setHandlers(b),N.api},async createEngine(){},_fetch:r,_getPlayer:f,_createGLTexture(b){const S=new qe(h,{image:b,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),F=_++;return c.set(F,S),S.update(),{gl:h,glTexture:S.texture,textureId:F}},_projectionOf:b=>ce.projectionOf(b),_setTransparent(b){Ze=b},_onResize(b,S,F=1){Pt=F,g.dpr=F,g.setSize(b,S),ut=0},_dispose(){var b;N==null||N.dispose(),N=null,re==null||re.dispose(),re=null,le==null||le.dispose(),le=null;for(const S of jt.values())S.dispose();jt.clear(),this.closeScene(),this.stopAllPlayers(),(b=h.getExtension("WEBGL_lose_context"))==null||b.loseContext()}}},Jc=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 Zc(s,{preloads:e.preloads,twins:e.twins,alpha:e.alpha}),o=()=>{const p=t.clientWidth,g=t.clientHeight;p>0&&g>0&&i._onResize(p,g,n.devicePixelRatio||1)};let l=null,a=-1;return{feature:{name:"scene3d",install(){return t.insertBefore(s,t.firstChild),o(),l=new ResizeObserver(o),l.observe(t),{globals:{_creator:i},destination(p,g){return p.kind!==Ei?!1:(g?(a=p.id,i.openScene(p.id)):a===p.id&&(a=-1,i.closeScene()),!0)},hit:(p,g,h)=>p===s&&a>=0?i.raycastPick(g,h):null,destroy(){l==null||l.disconnect(),l=null,a=-1,i._dispose(),s.remove()}}}},engine:i,canvas:s,opened:()=>a,dispose(){i._dispose(),s.remove()}}},th=Object.freeze(Object.defineProperty({__proto__:null,createScene3d:Jc},Symbol.toStringTag,{value:"Module"}));export{ls as G,th as s};
|