lecodes-3d-editor 0.1.0
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/README.md +31 -0
- package/dist/app/assets/createViewer-DGHC9eXK.js +5 -0
- package/dist/app/assets/createViewer2d-CI6PFuCm.js +1 -0
- package/dist/app/assets/createViewerLite-CoShwplA.js +487 -0
- package/dist/app/assets/creator-gl-GaTBGmVI.wasm +0 -0
- package/dist/app/assets/creator-ui-DNJBpZ2P.wasm +0 -0
- package/dist/app/assets/creator2d-zNxn9uSj.wasm +0 -0
- package/dist/app/assets/fetch-CbiE4Jmm.js +1 -0
- package/dist/app/assets/fetch-yAxxs-ZQ.js +1 -0
- package/dist/app/assets/gizmo-D5xdNVjw.filamat +0 -0
- package/dist/app/assets/index-BuGYQX6Z.css +1 -0
- package/dist/app/assets/index-DZc_N5Kk.js +2 -0
- package/dist/app/assets/lit-WtoZF0Yx.filamat +0 -0
- package/dist/app/assets/matcap_porcelain_white-DRnbNWwg.jpg +0 -0
- package/dist/app/assets/mediaplayer-40oza6jV.js +1 -0
- package/dist/app/assets/neutral_ibl128-D-lzdkLN.ktx +0 -0
- package/dist/app/assets/shadow-CnJ-PXnb.filamat +0 -0
- package/dist/app/assets/src-DKPpeImT.js +451 -0
- package/dist/app/assets/uberarchive-De8g3sSw.bin +0 -0
- package/dist/app/assets/unlit-pnl94z8g.filamat +0 -0
- package/dist/app/assets/video-CdjDrvX4.filamat +0 -0
- package/dist/app/index.html +26 -0
- package/dist/server.js +503 -0
- package/package.json +34 -0
- package/src/index.ts +19 -0
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import{c as e,d as t,l as n,n as r,s as i,u as a}from"./fetch-yAxxs-ZQ.js";import{a as o,s}from"./mediaplayer-40oza6jV.js";function c(e){let t=e[0],n=e[1],r=e[2];return Math.sqrt(t*t+n*n+r*r)}function l(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function u(e,t,n,r){return e[0]=t,e[1]=n,e[2]=r,e}function d(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e}function f(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e}function p(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e}function m(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e[2]=t[2]/n[2],e}function h(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e}function g(e,t){let n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2];return Math.sqrt(n*n+r*r+i*i)}function _(e,t){let n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2];return n*n+r*r+i*i}function v(e){let t=e[0],n=e[1],r=e[2];return t*t+n*n+r*r}function y(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e}function b(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e}function x(e,t){let n=t[0],r=t[1],i=t[2],a=n*n+r*r+i*i;return a>0&&(a=1/Math.sqrt(a)),e[0]=t[0]*a,e[1]=t[1]*a,e[2]=t[2]*a,e}function S(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function C(e,t,n){let r=t[0],i=t[1],a=t[2],o=n[0],s=n[1],c=n[2];return e[0]=i*c-a*s,e[1]=a*o-r*c,e[2]=r*s-i*o,e}function w(e,t,n,r){let i=t[0],a=t[1],o=t[2];return e[0]=i+r*(n[0]-i),e[1]=a+r*(n[1]-a),e[2]=o+r*(n[2]-o),e}function T(e,t,n,r,i){let a=Math.exp(-r*i),o=t[0],s=t[1],c=t[2];return e[0]=n[0]+(o-n[0])*a,e[1]=n[1]+(s-n[1])*a,e[2]=n[2]+(c-n[2])*a,e}function E(e,t,n){let r=t[0],i=t[1],a=t[2],o=n[3]*r+n[7]*i+n[11]*a+n[15];return o||=1,e[0]=(n[0]*r+n[4]*i+n[8]*a+n[12])/o,e[1]=(n[1]*r+n[5]*i+n[9]*a+n[13])/o,e[2]=(n[2]*r+n[6]*i+n[10]*a+n[14])/o,e}function D(e,t,n){let r=t[0],i=t[1],a=t[2],o=n[3]*r+n[7]*i+n[11]*a+n[15];return o||=1,e[0]=(n[0]*r+n[4]*i+n[8]*a)/o,e[1]=(n[1]*r+n[5]*i+n[9]*a)/o,e[2]=(n[2]*r+n[6]*i+n[10]*a)/o,e}function O(e,t,n){let r=t[0],i=t[1],a=t[2];return e[0]=r*n[0]+i*n[3]+a*n[6],e[1]=r*n[1]+i*n[4]+a*n[7],e[2]=r*n[2]+i*n[5]+a*n[8],e}function k(e,t,n){let r=t[0],i=t[1],a=t[2],o=n[0],s=n[1],c=n[2],l=n[3],u=s*a-c*i,d=c*r-o*a,f=o*i-s*r,p=s*f-c*d,m=c*u-o*f,h=o*d-s*u,g=l*2;return u*=g,d*=g,f*=g,p*=2,m*=2,h*=2,e[0]=r+u+p,e[1]=i+d+m,e[2]=a+f+h,e}var A=(function(){let e=[0,0,0],t=[0,0,0];return function(n,r){l(e,n),l(t,r),x(e,e),x(t,t);let i=S(e,t);return i>1?0:i<-1?Math.PI:Math.acos(i)}})();function j(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}var M=class e extends Array{constructor(e=0,t=e,n=e){return super(e,t,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,t=e,n=e){return e.length?this.copy(e):(u(this,e,t,n),this)}copy(e){return l(this,e),this}add(e,t){return t?d(this,e,t):d(this,this,e),this}sub(e,t){return t?f(this,e,t):f(this,this,e),this}multiply(e){return e.length?p(this,this,e):h(this,this,e),this}divide(e){return e.length?m(this,this,e):h(this,this,1/e),this}inverse(e=this){return b(this,e),this}len(){return c(this)}distance(e){return e?g(this,e):c(this)}squaredLen(){return v(this)}squaredDistance(e){return e?_(this,e):v(this)}negate(e=this){return y(this,e),this}cross(e,t){return t?C(this,e,t):C(this,this,e),this}scale(e){return h(this,this,e),this}normalize(){return x(this,this),this}dot(e){return S(this,e)}equals(e){return j(this,e)}applyMatrix3(e){return O(this,this,e),this}applyMatrix4(e){return E(this,this,e),this}scaleRotateMatrix4(e){return D(this,this,e),this}applyQuaternion(e){return k(this,this,e),this}angle(e){return A(this,e)}lerp(e,t){return w(this,this,e,t),this}smoothLerp(e,t,n){return T(this,this,e,t,n),this}clone(){return new e(this[0],this[1],this[2])}fromArray(e,t=0){return this[0]=e[t],this[1]=e[t+1],this[2]=e[t+2],this}toArray(e=[],t=0){return e[t]=this[0],e[t+1]=this[1],e[t+2]=this[2],e}transformDirection(e){let t=this[0],n=this[1],r=this[2];return this[0]=e[0]*t+e[4]*n+e[8]*r,this[1]=e[1]*t+e[5]*n+e[9]*r,this[2]=e[2]*t+e[6]*n+e[10]*r,this.normalize()}},N=new M,P=1,ee=1,F=!1,te=class{constructor(e,t={}){e.canvas||console.error(`gl not passed as first argument to Geometry`),this.gl=e,this.attributes=t,this.id=P++,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 e in t)this.addAttribute(e,t[e])}addAttribute(e,t){if(this.attributes[e]=t,t.id=ee++,t.size=t.size||1,t.type=t.type||(t.data.constructor===Float32Array?this.gl.FLOAT:t.data.constructor===Uint16Array?this.gl.UNSIGNED_SHORT:this.gl.UNSIGNED_INT),t.target=e===`index`?this.gl.ELEMENT_ARRAY_BUFFER:this.gl.ARRAY_BUFFER,t.normalized=t.normalized||!1,t.stride=t.stride||0,t.offset=t.offset||0,t.count=t.count||(t.stride?t.data.byteLength/t.stride:t.data.length/t.size),t.divisor=t.instanced||0,t.needsUpdate=!1,t.usage=t.usage||this.gl.STATIC_DRAW,t.buffer||this.updateAttribute(t),t.divisor){if(this.isInstanced=!0,this.instancedCount&&this.instancedCount!==t.count*t.divisor)return console.warn(`geometry has multiple instanced buffers of different length`),this.instancedCount=Math.min(this.instancedCount,t.count*t.divisor);this.instancedCount=t.count*t.divisor}else e===`index`?this.drawRange.count=t.count:this.attributes.index||(this.drawRange.count=Math.max(this.drawRange.count,t.count))}updateAttribute(e){let t=!e.buffer;t&&(e.buffer=this.gl.createBuffer()),this.glState.boundBuffer!==e.buffer&&(this.gl.bindBuffer(e.target,e.buffer),this.glState.boundBuffer=e.buffer),t?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,t){this.drawRange.start=e,this.drawRange.count=t}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((e,{name:t,type:n})=>{if(!this.attributes[t]){console.warn(`active attribute ${t} not being supplied`);return}let r=this.attributes[t];this.gl.bindBuffer(r.target,r.buffer),this.glState.boundBuffer=r.buffer;let i=1;n===35674&&(i=2),n===35675&&(i=3),n===35676&&(i=4);let a=r.size/i,o=i===1?0:i*i*4,s=i===1?0:i*4;for(let t=0;t<i;t++)this.gl.vertexAttribPointer(e+t,a,r.type,r.normalized,r.stride+o,r.offset+t*s),this.gl.enableVertexAttribArray(e+t),this.gl.renderer.vertexAttribDivisor(e+t,r.divisor)}),this.attributes.index&&this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.attributes.index.buffer)}draw({program:e,mode:t=this.gl.TRIANGLES}){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((e,{name:t})=>{let n=this.attributes[t];n.needsUpdate&&this.updateAttribute(n)});let n=2;this.attributes.index?.type===this.gl.UNSIGNED_INT&&(n=4),this.isInstanced?this.attributes.index?this.gl.renderer.drawElementsInstanced(t,this.drawRange.count,this.attributes.index.type,this.attributes.index.offset+this.drawRange.start*n,this.instancedCount):this.gl.renderer.drawArraysInstanced(t,this.drawRange.start,this.drawRange.count,this.instancedCount):this.attributes.index?this.gl.drawElements(t,this.drawRange.count,this.attributes.index.type,this.attributes.index.offset+this.drawRange.start*n):this.gl.drawArrays(t,this.drawRange.start,this.drawRange.count)}getPosition(){let e=this.attributes.position;if(e.data)return e;if(!F)return console.warn(`No position buffer data found to compute bounds`),F=!0}computeBoundingBox(e){e||=this.getPosition();let t=e.data,n=e.size;this.bounds||={min:new M,max:new M,center:new M,scale:new M,radius:1/0};let r=this.bounds.min,i=this.bounds.max,a=this.bounds.center,o=this.bounds.scale;r.set(1/0),i.set(-1/0);for(let e=0,a=t.length;e<a;e+=n){let n=t[e],a=t[e+1],o=t[e+2];r.x=Math.min(n,r.x),r.y=Math.min(a,r.y),r.z=Math.min(o,r.z),i.x=Math.max(n,i.x),i.y=Math.max(a,i.y),i.z=Math.max(o,i.z)}o.sub(i,r),a.add(r,i).divide(2)}computeBoundingSphere(e){e||=this.getPosition();let t=e.data,n=e.size;this.bounds||this.computeBoundingBox(e);let r=0;for(let e=0,i=t.length;e<i;e+=n)N.fromArray(t,e),r=Math.max(r,this.bounds.center.squaredDistance(N));this.bounds.radius=Math.sqrt(r)}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]}},ne=1,re={},I=class{constructor(e,{vertex:t,fragment:n,uniforms:r={},transparent:i=!1,cullFace:a=e.BACK,frontFace:o=e.CCW,depthTest:s=!0,depthWrite:c=!0,depthFunc:l=e.LEQUAL}={}){e.canvas||console.error(`gl not passed as first argument to Program`),this.gl=e,this.uniforms=r,this.id=ne++,t||console.warn(`vertex shader not supplied`),n||console.warn(`fragment shader not supplied`),this.transparent=i,this.cullFace=a,this.frontFace=o,this.depthTest=s,this.depthWrite=c,this.depthFunc=l,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:t,fragment:n})}setShaders({vertex:e,fragment:t}){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)}\nVertex Shader\n${R(e)}`)),t&&(this.gl.shaderSource(this.fragmentShader,t),this.gl.compileShader(this.fragmentShader),this.gl.getShaderInfoLog(this.fragmentShader)!==``&&console.warn(`${this.gl.getShaderInfoLog(this.fragmentShader)}\nFragment Shader\n${R(t)}`)),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 e=0;e<n;e++){let t=this.gl.getActiveUniform(this.program,e);this.uniformLocations.set(t,this.gl.getUniformLocation(this.program,t.name));let n=t.name.match(/(\w+)/g);t.uniformName=n[0],t.nameComponents=n.slice(1)}this.attributeLocations=new Map;let r=[],i=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_ATTRIBUTES);for(let e=0;e<i;e++){let t=this.gl.getActiveAttrib(this.program,e),n=this.gl.getAttribLocation(this.program,t.name);n!==-1&&(r[n]=t.name,this.attributeLocations.set(t,n))}this.attributeOrder=r.join(``)}setBlendFunc(e,t,n,r){this.blendFunc.src=e,this.blendFunc.dst=t,this.blendFunc.srcAlpha=n,this.blendFunc.dstAlpha=r,e&&(this.transparent=!0)}setBlendEquation(e,t){this.blendEquation.modeRGB=e,this.blendEquation.modeAlpha=t}setStencilFunc(e,t,n){this.stencilRef=t,this.stencilFunc.func=e,this.stencilFunc.ref=t,this.stencilFunc.mask=n}setStencilOp(e,t,n){this.stencilOp.stencilFail=e,this.stencilOp.depthFail=t,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 t=-1;this.gl.renderer.state.currentProgram!==this.id&&(this.gl.useProgram(this.program),this.gl.renderer.state.currentProgram=this.id),this.uniformLocations.forEach((e,n)=>{let r=this.uniforms[n.uniformName];for(let e of n.nameComponents){if(!r)break;if(e in r)r=r[e];else if(Array.isArray(r.value))break;else{r=void 0;break}}if(!r)return ce(`Active uniform ${n.name} has not been supplied`);if(r&&r.value===void 0)return ce(`${n.name} uniform is missing a value parameter`);if(r.value.texture)return t+=1,r.value.update(t),L(this.gl,n.type,e,t);if(r.value.length&&r.value[0].texture){let i=[];return r.value.forEach(e=>{t+=1,e.update(t),i.push(t)}),L(this.gl,n.type,e,i)}L(this.gl,n.type,e,r.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 L(e,t,n,r){r=r.length?ie(r):r;let i=e.renderer.state.uniformLocations.get(n);if(r.length)if(i===void 0||i.length!==r.length)e.renderer.state.uniformLocations.set(n,r.slice(0));else{if(ae(i,r))return;i.set?i.set(r):oe(i,r),e.renderer.state.uniformLocations.set(n,i)}else{if(i===r)return;e.renderer.state.uniformLocations.set(n,r)}switch(t){case 5126:return r.length?e.uniform1fv(n,r):e.uniform1f(n,r);case 35664:return e.uniform2fv(n,r);case 35665:return e.uniform3fv(n,r);case 35666:return e.uniform4fv(n,r);case 35670:case 5124:case 35678:case 36306:case 35680:case 36289:return r.length?e.uniform1iv(n,r):e.uniform1i(n,r);case 35671:case 35667:return e.uniform2iv(n,r);case 35672:case 35668:return e.uniform3iv(n,r);case 35673:case 35669:return e.uniform4iv(n,r);case 35674:return e.uniformMatrix2fv(n,!1,r);case 35675:return e.uniformMatrix3fv(n,!1,r);case 35676:return e.uniformMatrix4fv(n,!1,r)}}function R(e){let t=e.split(`
|
|
2
|
+
`);for(let e=0;e<t.length;e++)t[e]=e+1+`: `+t[e];return t.join(`
|
|
3
|
+
`)}function ie(e){let t=e.length,n=e[0].length;if(n===void 0)return e;let r=t*n,i=re[r];i||(re[r]=i=new Float32Array(r));for(let r=0;r<t;r++)i.set(e[r],r*n);return i}function ae(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function oe(e,t){for(let n=0,r=e.length;n<r;n++)e[n]=t[n]}var se=0;function ce(e){se>100||(console.warn(e),se++,se>100&&console.warn(`More than 100 program warnings - stopping logs.`))}var le=new M,ue=1,de=class{constructor({canvas:e=document.createElement(`canvas`),width:t=300,height:n=150,dpr:r=1,alpha:i=!1,depth:a=!0,stencil:o=!1,antialias:s=!1,premultipliedAlpha:c=!1,preserveDrawingBuffer:l=!1,powerPreference:u=`default`,autoClear:d=!0,webgl:f=2}={}){let p={alpha:i,depth:a,stencil:o,antialias:s,premultipliedAlpha:c,preserveDrawingBuffer:l,powerPreference:u};this.dpr=r,this.alpha=i,this.color=!0,this.depth=a,this.stencil=o,this.premultipliedAlpha=c,this.autoClear=d,this.id=ue++,f===2&&(this.gl=e.getContext(`webgl2`,p)),this.isWebgl2=!!this.gl,this.gl||=e.getContext(`webgl`,p),this.gl||console.error(`unable to create webgl context`),this.gl.renderer=this,this.setSize(t,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,t){this.width=e,this.height=t,this.gl.canvas.width=e*this.dpr,this.gl.canvas.height=t*this.dpr,this.gl.canvas.style&&Object.assign(this.gl.canvas.style,{width:e+`px`,height:t+`px`})}setViewport(e,t,n=0,r=0){this.state.viewport.width===e&&this.state.viewport.height===t||(this.state.viewport.width=e,this.state.viewport.height=t,this.state.viewport.x=n,this.state.viewport.y=r,this.gl.viewport(n,r,e,t))}setScissor(e,t,n=0,r=0){this.gl.scissor(n,r,e,t)}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,t,n,r){this.state.blendFunc.src===e&&this.state.blendFunc.dst===t&&this.state.blendFunc.srcAlpha===n&&this.state.blendFunc.dstAlpha===r||(this.state.blendFunc.src=e,this.state.blendFunc.dst=t,this.state.blendFunc.srcAlpha=n,this.state.blendFunc.dstAlpha=r,n===void 0?this.gl.blendFunc(e,t):this.gl.blendFuncSeparate(e,t,n,r))}setBlendEquation(e,t){e||=this.gl.FUNC_ADD,!(this.state.blendEquation.modeRGB===e&&this.state.blendEquation.modeAlpha===t)&&(this.state.blendEquation.modeRGB=e,this.state.blendEquation.modeAlpha=t,t===void 0?this.gl.blendEquation(e):this.gl.blendEquationSeparate(e,t))}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,t,n){this.state.stencilFunc===e&&this.state.stencilRef===t&&this.state.stencilFuncMask===n||(this.state.stencilFunc=e||this.gl.ALWAYS,this.state.stencilRef=t||0,this.state.stencilFuncMask=n||0,this.gl.stencilFunc(e||this.gl.ALWAYS,t||0,n||0))}setStencilOp(e,t,n){this.state.stencilFail===e&&this.state.stencilDepthFail===t&&this.state.stencilDepthPass===n||(this.state.stencilFail=e,this.state.stencilDepthFail=t,this.state.stencilDepthPass=n,this.gl.stencilOp(e,t,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:t=null}={}){this.state.framebuffer!==t&&(this.state.framebuffer=t,this.gl.bindFramebuffer(e,t))}getExtension(e,t,n){return t&&this.gl[t]?this.gl[t].bind(this.gl):(this.extensions[e]||(this.extensions[e]=this.gl.getExtension(e)),t?this.extensions[e]?this.extensions[e][n].bind(this.extensions[e]):null:this.extensions[e])}sortOpaque(e,t){return e.renderOrder===t.renderOrder?e.program.id===t.program.id?e.zDepth===t.zDepth?t.id-e.id:e.zDepth-t.zDepth:e.program.id-t.program.id:e.renderOrder-t.renderOrder}sortTransparent(e,t){return e.renderOrder===t.renderOrder?e.zDepth===t.zDepth?t.id-e.id:t.zDepth-e.zDepth:e.renderOrder-t.renderOrder}sortUI(e,t){return e.renderOrder===t.renderOrder?e.program.id===t.program.id?t.id-e.id:e.program.id-t.program.id:e.renderOrder-t.renderOrder}getRenderList({scene:e,camera:t,frustumCull:n,sort:r}){let i=[];if(t&&n&&t.updateFrustum(),e.traverse(e=>{if(!e.visible)return!0;e.draw&&(n&&e.frustumCulled&&t&&!t.frustumIntersectsMesh(e)||i.push(e))}),r){let e=[],n=[],r=[];i.forEach(i=>{i.program.transparent?i.program.depthTest?n.push(i):r.push(i):e.push(i),i.zDepth=0,!(i.renderOrder!==0||!i.program.depthTest||!t)&&(i.worldMatrix.getTranslation(le),le.applyMatrix4(t.projectionViewMatrix),i.zDepth=le.z)}),e.sort(this.sortOpaque),n.sort(this.sortTransparent),r.sort(this.sortUI),i=e.concat(n,r)}return i}render({scene:e,camera:t,target:n=null,update:r=!0,sort:i=!0,frustumCull:a=!0,clear:o}){n===null?(this.bindFramebuffer(),this.setViewport(this.width*this.dpr,this.height*this.dpr)):(this.bindFramebuffer(n),this.setViewport(n.width,n.height)),(o||this.autoClear&&o!==!1)&&(this.depth&&(!n||n.depth)&&(this.enable(this.gl.DEPTH_TEST),this.setDepthMask(!0)),(this.stencil||!n||n.stencil)&&(this.enable(this.gl.STENCIL_TEST),this.setStencilMask(255)),this.gl.clear((this.color?this.gl.COLOR_BUFFER_BIT:0)|(this.depth?this.gl.DEPTH_BUFFER_BIT:0)|(this.stencil?this.gl.STENCIL_BUFFER_BIT:0))),r&&e.updateMatrixWorld(),t&&t.updateMatrixWorld(),this.getRenderList({scene:e,camera:t,frustumCull:a,sort:i}).forEach(e=>{e.draw({camera:t})})}};function fe(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function pe(e,t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,e[3]=i,e}function me(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e}function he(e,t){let n=t[0],r=t[1],i=t[2],a=t[3],o=n*n+r*r+i*i+a*a;return o>0&&(o=1/Math.sqrt(o)),e[0]=n*o,e[1]=r*o,e[2]=i*o,e[3]=a*o,e}function ge(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function _e(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}function ve(e,t,n){n*=.5;let r=Math.sin(n);return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=Math.cos(n),e}function ye(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=n[0],c=n[1],l=n[2],u=n[3];return e[0]=r*u+o*s+i*l-a*c,e[1]=i*u+o*c+a*s-r*l,e[2]=a*u+o*l+r*c-i*s,e[3]=o*u-r*s-i*c-a*l,e}function be(e,t,n){n*=.5;let r=t[0],i=t[1],a=t[2],o=t[3],s=Math.sin(n),c=Math.cos(n);return e[0]=r*c+o*s,e[1]=i*c+a*s,e[2]=a*c-i*s,e[3]=o*c-r*s,e}function xe(e,t,n){n*=.5;let r=t[0],i=t[1],a=t[2],o=t[3],s=Math.sin(n),c=Math.cos(n);return e[0]=r*c-a*s,e[1]=i*c+o*s,e[2]=a*c+r*s,e[3]=o*c-i*s,e}function Se(e,t,n){n*=.5;let r=t[0],i=t[1],a=t[2],o=t[3],s=Math.sin(n),c=Math.cos(n);return e[0]=r*c+i*s,e[1]=i*c-r*s,e[2]=a*c+o*s,e[3]=o*c-a*s,e}function Ce(e,t,n,r){let i=t[0],a=t[1],o=t[2],s=t[3],c=n[0],l=n[1],u=n[2],d=n[3],f,p,m,h,g;return p=i*c+a*l+o*u+s*d,p<0&&(p=-p,c=-c,l=-l,u=-u,d=-d),1-p>1e-6?(f=Math.acos(p),m=Math.sin(f),h=Math.sin((1-r)*f)/m,g=Math.sin(r*f)/m):(h=1-r,g=r),e[0]=h*i+g*c,e[1]=h*a+g*l,e[2]=h*o+g*u,e[3]=h*s+g*d,e}function we(e,t){let n=t[0],r=t[1],i=t[2],a=t[3],o=n*n+r*r+i*i+a*a,s=o?1/o:0;return e[0]=-n*s,e[1]=-r*s,e[2]=-i*s,e[3]=a*s,e}function z(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e}function Te(e,t){let n=t[0]+t[4]+t[8],r;if(n>0)r=Math.sqrt(n+1),e[3]=.5*r,r=.5/r,e[0]=(t[5]-t[7])*r,e[1]=(t[6]-t[2])*r,e[2]=(t[1]-t[3])*r;else{let n=0;t[4]>t[0]&&(n=1),t[8]>t[n*3+n]&&(n=2);let i=(n+1)%3,a=(n+2)%3;r=Math.sqrt(t[n*3+n]-t[i*3+i]-t[a*3+a]+1),e[n]=.5*r,r=.5/r,e[3]=(t[i*3+a]-t[a*3+i])*r,e[i]=(t[i*3+n]+t[n*3+i])*r,e[a]=(t[a*3+n]+t[n*3+a])*r}return e}function Ee(e,t,n=`YXZ`){let r=Math.sin(t[0]*.5),i=Math.cos(t[0]*.5),a=Math.sin(t[1]*.5),o=Math.cos(t[1]*.5),s=Math.sin(t[2]*.5),c=Math.cos(t[2]*.5);return n===`XYZ`?(e[0]=r*o*c+i*a*s,e[1]=i*a*c-r*o*s,e[2]=i*o*s+r*a*c,e[3]=i*o*c-r*a*s):n===`YXZ`?(e[0]=r*o*c+i*a*s,e[1]=i*a*c-r*o*s,e[2]=i*o*s-r*a*c,e[3]=i*o*c+r*a*s):n===`ZXY`?(e[0]=r*o*c-i*a*s,e[1]=i*a*c+r*o*s,e[2]=i*o*s+r*a*c,e[3]=i*o*c-r*a*s):n===`ZYX`?(e[0]=r*o*c-i*a*s,e[1]=i*a*c+r*o*s,e[2]=i*o*s-r*a*c,e[3]=i*o*c+r*a*s):n===`YZX`?(e[0]=r*o*c+i*a*s,e[1]=i*a*c+r*o*s,e[2]=i*o*s-r*a*c,e[3]=i*o*c-r*a*s):n===`XZY`&&(e[0]=r*o*c-i*a*s,e[1]=i*a*c-r*o*s,e[2]=i*o*s+r*a*c,e[3]=i*o*c+r*a*s),e}var De=fe,Oe=pe,ke=ge,Ae=he,je=class extends Array{constructor(e=0,t=0,n=0,r=1){super(e,t,n,r),this.onChange=()=>{},this._target=this;let i=[`0`,`1`,`2`,`3`];return new Proxy(this,{set(e,t){let n=Reflect.set(...arguments);return n&&i.includes(t)&&e.onChange(),n}})}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 _e(this._target),this.onChange(),this}set(e,t,n,r){return e.length?this.copy(e):(Oe(this._target,e,t,n,r),this.onChange(),this)}rotateX(e){return be(this._target,this._target,e),this.onChange(),this}rotateY(e){return xe(this._target,this._target,e),this.onChange(),this}rotateZ(e){return Se(this._target,this._target,e),this.onChange(),this}inverse(e=this._target){return we(this._target,e),this.onChange(),this}conjugate(e=this._target){return z(this._target,e),this.onChange(),this}copy(e){return De(this._target,e),this.onChange(),this}normalize(e=this._target){return Ae(this._target,e),this.onChange(),this}multiply(e,t){return t?ye(this._target,e,t):ye(this._target,this._target,e),this.onChange(),this}dot(e){return ke(this._target,e)}fromMatrix3(e){return Te(this._target,e),this.onChange(),this}fromEuler(e,t){return Ee(this._target,e,e.order),t||this.onChange(),this}fromAxisAngle(e,t){return ve(this._target,e,t),this.onChange(),this}slerp(e,t){return Ce(this._target,this._target,e,t),this.onChange(),this}fromArray(e,t=0){return this._target[0]=e[t],this._target[1]=e[t+1],this._target[2]=e[t+2],this._target[3]=e[t+3],this.onChange(),this}toArray(e=[],t=0){return e[t]=this[0],e[t+1]=this[1],e[t+2]=this[2],e[t+3]=this[3],e}},Me=1e-6;function Ne(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function Pe(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g){return e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a,e[5]=o,e[6]=s,e[7]=c,e[8]=l,e[9]=u,e[10]=d,e[11]=f,e[12]=p,e[13]=m,e[14]=h,e[15]=g,e}function Fe(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Ie(e,t){let n=t[0],r=t[1],i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10],p=t[11],m=t[12],h=t[13],g=t[14],_=t[15],v=n*s-r*o,y=n*c-i*o,b=n*l-a*o,x=r*c-i*s,S=r*l-a*s,C=i*l-a*c,w=u*h-d*m,T=u*g-f*m,E=u*_-p*m,D=d*g-f*h,O=d*_-p*h,k=f*_-p*g,A=v*k-y*O+b*D+x*E-S*T+C*w;return A?(A=1/A,e[0]=(s*k-c*O+l*D)*A,e[1]=(i*O-r*k-a*D)*A,e[2]=(h*C-g*S+_*x)*A,e[3]=(f*S-d*C-p*x)*A,e[4]=(c*E-o*k-l*T)*A,e[5]=(n*k-i*E+a*T)*A,e[6]=(g*b-m*C-_*y)*A,e[7]=(u*C-f*b+p*y)*A,e[8]=(o*O-s*E+l*w)*A,e[9]=(r*E-n*O-a*w)*A,e[10]=(m*S-h*b+_*v)*A,e[11]=(d*b-u*S-p*v)*A,e[12]=(s*T-o*D-c*w)*A,e[13]=(n*D-r*T+i*w)*A,e[14]=(h*y-m*x-g*v)*A,e[15]=(u*x-d*y+f*v)*A,e):null}function Le(e){let t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=e[9],d=e[10],f=e[11],p=e[12],m=e[13],h=e[14],g=e[15],_=t*o-n*a,v=t*s-r*a,y=t*c-i*a,b=n*s-r*o,x=n*c-i*o,S=r*c-i*s,C=l*m-u*p,w=l*h-d*p,T=l*g-f*p,E=u*h-d*m,D=u*g-f*m;return _*(d*g-f*h)-v*D+y*E+b*T-x*w+S*C}function Re(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=t[6],u=t[7],d=t[8],f=t[9],p=t[10],m=t[11],h=t[12],g=t[13],_=t[14],v=t[15],y=n[0],b=n[1],x=n[2],S=n[3];return e[0]=y*r+b*s+x*d+S*h,e[1]=y*i+b*c+x*f+S*g,e[2]=y*a+b*l+x*p+S*_,e[3]=y*o+b*u+x*m+S*v,y=n[4],b=n[5],x=n[6],S=n[7],e[4]=y*r+b*s+x*d+S*h,e[5]=y*i+b*c+x*f+S*g,e[6]=y*a+b*l+x*p+S*_,e[7]=y*o+b*u+x*m+S*v,y=n[8],b=n[9],x=n[10],S=n[11],e[8]=y*r+b*s+x*d+S*h,e[9]=y*i+b*c+x*f+S*g,e[10]=y*a+b*l+x*p+S*_,e[11]=y*o+b*u+x*m+S*v,y=n[12],b=n[13],x=n[14],S=n[15],e[12]=y*r+b*s+x*d+S*h,e[13]=y*i+b*c+x*f+S*g,e[14]=y*a+b*l+x*p+S*_,e[15]=y*o+b*u+x*m+S*v,e}function ze(e,t,n){let r=n[0],i=n[1],a=n[2],o,s,c,l,u,d,f,p,m,h,g,_;return t===e?(e[12]=t[0]*r+t[4]*i+t[8]*a+t[12],e[13]=t[1]*r+t[5]*i+t[9]*a+t[13],e[14]=t[2]*r+t[6]*i+t[10]*a+t[14],e[15]=t[3]*r+t[7]*i+t[11]*a+t[15]):(o=t[0],s=t[1],c=t[2],l=t[3],u=t[4],d=t[5],f=t[6],p=t[7],m=t[8],h=t[9],g=t[10],_=t[11],e[0]=o,e[1]=s,e[2]=c,e[3]=l,e[4]=u,e[5]=d,e[6]=f,e[7]=p,e[8]=m,e[9]=h,e[10]=g,e[11]=_,e[12]=o*r+u*i+m*a+t[12],e[13]=s*r+d*i+h*a+t[13],e[14]=c*r+f*i+g*a+t[14],e[15]=l*r+p*i+_*a+t[15]),e}function Be(e,t,n){let r=n[0],i=n[1],a=n[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*i,e[5]=t[5]*i,e[6]=t[6]*i,e[7]=t[7]*i,e[8]=t[8]*a,e[9]=t[9]*a,e[10]=t[10]*a,e[11]=t[11]*a,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function Ve(e,t,n,r){let i=r[0],a=r[1],o=r[2],s=Math.hypot(i,a,o),c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j;return Math.abs(s)<Me?null:(s=1/s,i*=s,a*=s,o*=s,c=Math.sin(n),l=Math.cos(n),u=1-l,d=t[0],f=t[1],p=t[2],m=t[3],h=t[4],g=t[5],_=t[6],v=t[7],y=t[8],b=t[9],x=t[10],S=t[11],C=i*i*u+l,w=a*i*u+o*c,T=o*i*u-a*c,E=i*a*u-o*c,D=a*a*u+l,O=o*a*u+i*c,k=i*o*u+a*c,A=a*o*u-i*c,j=o*o*u+l,e[0]=d*C+h*w+y*T,e[1]=f*C+g*w+b*T,e[2]=p*C+_*w+x*T,e[3]=m*C+v*w+S*T,e[4]=d*E+h*D+y*O,e[5]=f*E+g*D+b*O,e[6]=p*E+_*D+x*O,e[7]=m*E+v*D+S*O,e[8]=d*k+h*A+y*j,e[9]=f*k+g*A+b*j,e[10]=p*k+_*A+x*j,e[11]=m*k+v*A+S*j,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function He(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function Ue(e,t){let n=t[0],r=t[1],i=t[2],a=t[4],o=t[5],s=t[6],c=t[8],l=t[9],u=t[10];return e[0]=Math.hypot(n,r,i),e[1]=Math.hypot(a,o,s),e[2]=Math.hypot(c,l,u),e}function We(e){let t=e[0],n=e[1],r=e[2],i=e[4],a=e[5],o=e[6],s=e[8],c=e[9],l=e[10],u=t*t+n*n+r*r,d=i*i+a*a+o*o,f=s*s+c*c+l*l;return Math.sqrt(Math.max(u,d,f))}var Ge=(function(){let e=[1,1,1];return function(t,n){let r=e;Ue(r,n);let i=1/r[0],a=1/r[1],o=1/r[2],s=n[0]*i,c=n[1]*a,l=n[2]*o,u=n[4]*i,d=n[5]*a,f=n[6]*o,p=n[8]*i,m=n[9]*a,h=n[10]*o,g=s+d+h,_=0;return g>0?(_=Math.sqrt(g+1)*2,t[3]=.25*_,t[0]=(f-m)/_,t[1]=(p-l)/_,t[2]=(c-u)/_):s>d&&s>h?(_=Math.sqrt(1+s-d-h)*2,t[3]=(f-m)/_,t[0]=.25*_,t[1]=(c+u)/_,t[2]=(p+l)/_):d>h?(_=Math.sqrt(1+d-s-h)*2,t[3]=(p-l)/_,t[0]=(c+u)/_,t[1]=.25*_,t[2]=(f+m)/_):(_=Math.sqrt(1+h-s-d)*2,t[3]=(c-u)/_,t[0]=(p+l)/_,t[1]=(f+m)/_,t[2]=.25*_),t}})();function Ke(e,t,n,r){let i=c([e[0],e[1],e[2]]),a=c([e[4],e[5],e[6]]),o=c([e[8],e[9],e[10]]);Le(e)<0&&(i=-i),n[0]=e[12],n[1]=e[13],n[2]=e[14];let s=e.slice(),l=1/i,u=1/a,d=1/o;s[0]*=l,s[1]*=l,s[2]*=l,s[4]*=u,s[5]*=u,s[6]*=u,s[8]*=d,s[9]*=d,s[10]*=d,Ge(t,s),r[0]=i,r[1]=a,r[2]=o}function qe(e,t,n,r){let i=e,a=t[0],o=t[1],s=t[2],c=t[3],l=a+a,u=o+o,d=s+s,f=a*l,p=a*u,m=a*d,h=o*u,g=o*d,_=s*d,v=c*l,y=c*u,b=c*d,x=r[0],S=r[1],C=r[2];return i[0]=(1-(h+_))*x,i[1]=(p+b)*x,i[2]=(m-y)*x,i[3]=0,i[4]=(p-b)*S,i[5]=(1-(f+_))*S,i[6]=(g+v)*S,i[7]=0,i[8]=(m+y)*C,i[9]=(g-v)*C,i[10]=(1-(f+h))*C,i[11]=0,i[12]=n[0],i[13]=n[1],i[14]=n[2],i[15]=1,i}function Je(e,t){let n=t[0],r=t[1],i=t[2],a=t[3],o=n+n,s=r+r,c=i+i,l=n*o,u=r*o,d=r*s,f=i*o,p=i*s,m=i*c,h=a*o,g=a*s,_=a*c;return e[0]=1-d-m,e[1]=u+_,e[2]=f-g,e[3]=0,e[4]=u-_,e[5]=1-l-m,e[6]=p+h,e[7]=0,e[8]=f+g,e[9]=p-h,e[10]=1-l-d,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Ye(e,t,n,r,i){let a=1/Math.tan(t/2),o=1/(r-i);return e[0]=a/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=a,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=(i+r)*o,e[11]=-1,e[12]=0,e[13]=0,e[14]=2*i*r*o,e[15]=0,e}function Xe(e,t,n,r,i,a,o){let s=1/(t-n),c=1/(r-i),l=1/(a-o);return e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*l,e[11]=0,e[12]=(t+n)*s,e[13]=(i+r)*c,e[14]=(o+a)*l,e[15]=1,e}function Ze(e,t,n,r){let i=t[0],a=t[1],o=t[2],s=r[0],c=r[1],l=r[2],u=i-n[0],d=a-n[1],f=o-n[2],p=u*u+d*d+f*f;p===0?f=1:(p=1/Math.sqrt(p),u*=p,d*=p,f*=p);let m=c*f-l*d,h=l*u-s*f,g=s*d-c*u;return p=m*m+h*h+g*g,p===0&&(l?s+=1e-6:c?l+=1e-6:c+=1e-6,m=c*f-l*d,h=l*u-s*f,g=s*d-c*u,p=m*m+h*h+g*g),p=1/Math.sqrt(p),m*=p,h*=p,g*=p,e[0]=m,e[1]=h,e[2]=g,e[3]=0,e[4]=d*g-f*h,e[5]=f*m-u*g,e[6]=u*h-d*m,e[7]=0,e[8]=u,e[9]=d,e[10]=f,e[11]=0,e[12]=i,e[13]=a,e[14]=o,e[15]=1,e}function Qe(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e[4]=t[4]+n[4],e[5]=t[5]+n[5],e[6]=t[6]+n[6],e[7]=t[7]+n[7],e[8]=t[8]+n[8],e[9]=t[9]+n[9],e[10]=t[10]+n[10],e[11]=t[11]+n[11],e[12]=t[12]+n[12],e[13]=t[13]+n[13],e[14]=t[14]+n[14],e[15]=t[15]+n[15],e}function $e(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e[4]=t[4]-n[4],e[5]=t[5]-n[5],e[6]=t[6]-n[6],e[7]=t[7]-n[7],e[8]=t[8]-n[8],e[9]=t[9]-n[9],e[10]=t[10]-n[10],e[11]=t[11]-n[11],e[12]=t[12]-n[12],e[13]=t[13]-n[13],e[14]=t[14]-n[14],e[15]=t[15]-n[15],e}function et(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7]*n,e[8]=t[8]*n,e[9]=t[9]*n,e[10]=t[10]*n,e[11]=t[11]*n,e[12]=t[12]*n,e[13]=t[13]*n,e[14]=t[14]*n,e[15]=t[15]*n,e}var B=class extends Array{constructor(e=1,t=0,n=0,r=0,i=0,a=1,o=0,s=0,c=0,l=0,u=1,d=0,f=0,p=0,m=0,h=1){return super(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h),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,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){return e.length?this.copy(e):(Pe(this,e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h),this)}translate(e,t=this){return ze(this,t,e),this}rotate(e,t,n=this){return Ve(this,n,e,t),this}scale(e,t=this){return Be(this,t,typeof e==`number`?[e,e,e]:e),this}add(e,t){return t?Qe(this,e,t):Qe(this,this,e),this}sub(e,t){return t?$e(this,e,t):$e(this,this,e),this}multiply(e,t){return e.length?t?Re(this,e,t):Re(this,this,e):et(this,this,e),this}identity(){return Fe(this),this}copy(e){return Ne(this,e),this}fromPerspective({fov:e,aspect:t,near:n,far:r}={}){return Ye(this,e,t,n,r),this}fromOrthogonal({left:e,right:t,bottom:n,top:r,near:i,far:a}){return Xe(this,e,t,n,r,i,a),this}fromQuaternion(e){return Je(this,e),this}setPosition(e){return this.x=e[0],this.y=e[1],this.z=e[2],this}inverse(e=this){return Ie(this,e),this}compose(e,t,n){return qe(this,e,t,n),this}decompose(e,t,n){return Ke(this,e,t,n),this}getRotation(e){return Ge(e,this),this}getTranslation(e){return He(e,this),this}getScaling(e){return Ue(e,this),this}getMaxScaleOnAxis(){return We(this)}lookAt(e,t,n){return Ze(this,e,t,n),this}determinant(){return Le(this)}fromArray(e,t=0){return this[0]=e[t],this[1]=e[t+1],this[2]=e[t+2],this[3]=e[t+3],this[4]=e[t+4],this[5]=e[t+5],this[6]=e[t+6],this[7]=e[t+7],this[8]=e[t+8],this[9]=e[t+9],this[10]=e[t+10],this[11]=e[t+11],this[12]=e[t+12],this[13]=e[t+13],this[14]=e[t+14],this[15]=e[t+15],this}toArray(e=[],t=0){return e[t]=this[0],e[t+1]=this[1],e[t+2]=this[2],e[t+3]=this[3],e[t+4]=this[4],e[t+5]=this[5],e[t+6]=this[6],e[t+7]=this[7],e[t+8]=this[8],e[t+9]=this[9],e[t+10]=this[10],e[t+11]=this[11],e[t+12]=this[12],e[t+13]=this[13],e[t+14]=this[14],e[t+15]=this[15],e}};function tt(e,t,n=`YXZ`){return n===`XYZ`?(e[1]=Math.asin(Math.min(Math.max(t[8],-1),1)),Math.abs(t[8])<.99999?(e[0]=Math.atan2(-t[9],t[10]),e[2]=Math.atan2(-t[4],t[0])):(e[0]=Math.atan2(t[6],t[5]),e[2]=0)):n===`YXZ`?(e[0]=Math.asin(-Math.min(Math.max(t[9],-1),1)),Math.abs(t[9])<.99999?(e[1]=Math.atan2(t[8],t[10]),e[2]=Math.atan2(t[1],t[5])):(e[1]=Math.atan2(-t[2],t[0]),e[2]=0)):n===`ZXY`?(e[0]=Math.asin(Math.min(Math.max(t[6],-1),1)),Math.abs(t[6])<.99999?(e[1]=Math.atan2(-t[2],t[10]),e[2]=Math.atan2(-t[4],t[5])):(e[1]=0,e[2]=Math.atan2(t[1],t[0]))):n===`ZYX`?(e[1]=Math.asin(-Math.min(Math.max(t[2],-1),1)),Math.abs(t[2])<.99999?(e[0]=Math.atan2(t[6],t[10]),e[2]=Math.atan2(t[1],t[0])):(e[0]=0,e[2]=Math.atan2(-t[4],t[5]))):n===`YZX`?(e[2]=Math.asin(Math.min(Math.max(t[1],-1),1)),Math.abs(t[1])<.99999?(e[0]=Math.atan2(-t[9],t[5]),e[1]=Math.atan2(-t[2],t[0])):(e[0]=0,e[1]=Math.atan2(t[8],t[10]))):n===`XZY`&&(e[2]=Math.asin(-Math.min(Math.max(t[4],-1),1)),Math.abs(t[4])<.99999?(e[0]=Math.atan2(t[6],t[5]),e[1]=Math.atan2(t[8],t[0])):(e[0]=Math.atan2(-t[9],t[10]),e[1]=0)),e}var nt=new B,rt=class extends Array{constructor(e=0,t=e,n=e,r=`YXZ`){super(e,t,n),this.order=r,this.onChange=()=>{},this._target=this;let i=[`0`,`1`,`2`];return new Proxy(this,{set(e,t){let n=Reflect.set(...arguments);return n&&i.includes(t)&&e.onChange(),n}})}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,t=e,n=e){return e.length?this.copy(e):(this._target[0]=e,this._target[1]=t,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,t=this.order){return tt(this._target,e,t),this.onChange(),this}fromQuaternion(e,t=this.order,n){return nt.fromQuaternion(e),this._target.fromRotationMatrix(nt,t),n||this.onChange(),this}fromArray(e,t=0){return this._target[0]=e[t],this._target[1]=e[t+1],this._target[2]=e[t+2],this}toArray(e=[],t=0){return e[t]=this[0],e[t+1]=this[1],e[t+2]=this[2],e}},V=class{constructor(){this.parent=null,this.children=[],this.visible=!0,this.matrix=new B,this.worldMatrix=new B,this.matrixAutoUpdate=!0,this.worldMatrixNeedsUpdate=!1,this.position=new M,this.quaternion=new je,this.scale=new M(1),this.rotation=new rt,this.up=new M(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,t=!0){this.parent&&e!==this.parent&&this.parent.removeChild(this,!1),this.parent=e,t&&e&&e.addChild(this,!1)}addChild(e,t=!0){~this.children.indexOf(e)||this.children.push(e),t&&e.setParent(this,!1)}removeChild(e,t=!0){~this.children.indexOf(e)&&this.children.splice(this.children.indexOf(e),1),t&&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 t=0,n=this.children.length;t<n;t++)this.children[t].updateMatrixWorld(e)}updateMatrix(){this.matrix.compose(this.quaternion,this.position,this.scale),this.worldMatrixNeedsUpdate=!0}traverse(e){if(!e(this))for(let t=0,n=this.children.length;t<n;t++)this.children[t].traverse(e)}decompose(){this.matrix.decompose(this.quaternion._target,this.position,this.scale),this.rotation.fromQuaternion(this.quaternion)}lookAt(e,t=!1){t?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)}},it=new B,at=new M,ot=new M,st=class extends V{constructor(e,{near:t=.1,far:n=100,fov:r=45,aspect:i=1,left:a,right:o,bottom:s,top:c,zoom:l=1}={}){super(),Object.assign(this,{near:t,far:n,fov:r,aspect:i,left:a,right:o,bottom:s,top:c,zoom:l}),this.projectionMatrix=new B,this.viewMatrix=new B,this.projectionViewMatrix=new B,this.worldPosition=new M,this.type=a||o?`orthographic`:`perspective`,this.type===`orthographic`?this.orthographic():this.perspective()}perspective({near:e=this.near,far:t=this.far,fov:n=this.fov,aspect:r=this.aspect}={}){return Object.assign(this,{near:e,far:t,fov:n,aspect:r}),this.projectionMatrix.fromPerspective({fov:Math.PI/180*n,aspect:r,near:e,far:t}),this.type=`perspective`,this}orthographic({near:e=this.near,far:t=this.far,left:n=this.left||-1,right:r=this.right||1,bottom:i=this.bottom||-1,top:a=this.top||1,zoom:o=this.zoom}={}){return Object.assign(this,{near:e,far:t,left:n,right:r,bottom:i,top:a,zoom:o}),n/=o,r/=o,i/=o,a/=o,this.projectionMatrix.fromOrthogonal({left:n,right:r,bottom:i,top:a,near:e,far:t}),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(it.inverse(this.projectionMatrix)),e.applyMatrix4(this.worldMatrix),this}updateFrustum(){this.frustum||=[new M,new M,new M,new M,new M,new M];let 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 e=0;e<6;e++){let t=1/this.frustum[e].distance();this.frustum[e].multiply(t),this.frustum[e].constant*=t}}frustumIntersectsMesh(e,t=e.worldMatrix){if(!e.geometry.attributes.position||((!e.geometry.bounds||e.geometry.bounds.radius===1/0)&&e.geometry.computeBoundingSphere(),!e.geometry.bounds))return!0;let n=at;n.copy(e.geometry.bounds.center),n.applyMatrix4(t);let r=e.geometry.bounds.radius*t.getMaxScaleOnAxis();return this.frustumIntersectsSphere(n,r)}frustumIntersectsSphere(e,t){let n=ot;for(let r=0;r<6;r++){let i=this.frustum[r];if(n.copy(i).dot(e)+i.constant<-t)return!1}return!0}};function ct(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}function lt(e,t){let n=t[0],r=t[1],i=t[2],a=t[3],o=n+n,s=r+r,c=i+i,l=n*o,u=r*o,d=r*s,f=i*o,p=i*s,m=i*c,h=a*o,g=a*s,_=a*c;return e[0]=1-d-m,e[3]=u-_,e[6]=f+g,e[1]=u+_,e[4]=1-l-m,e[7]=p-h,e[2]=f-g,e[5]=p+h,e[8]=1-l-d,e}function ut(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function dt(e,t,n,r,i,a,o,s,c,l){return e[0]=t,e[1]=n,e[2]=r,e[3]=i,e[4]=a,e[5]=o,e[6]=s,e[7]=c,e[8]=l,e}function ft(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e}function pt(e,t){let n=t[0],r=t[1],i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=u*o-s*l,f=-u*a+s*c,p=l*a-o*c,m=n*d+r*f+i*p;return m?(m=1/m,e[0]=d*m,e[1]=(-u*r+i*l)*m,e[2]=(s*r-i*o)*m,e[3]=f*m,e[4]=(u*n-i*c)*m,e[5]=(-s*n+i*a)*m,e[6]=p*m,e[7]=(-l*n+r*c)*m,e[8]=(o*n-r*a)*m,e):null}function mt(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=t[6],u=t[7],d=t[8],f=n[0],p=n[1],m=n[2],h=n[3],g=n[4],_=n[5],v=n[6],y=n[7],b=n[8];return e[0]=f*r+p*o+m*l,e[1]=f*i+p*s+m*u,e[2]=f*a+p*c+m*d,e[3]=h*r+g*o+_*l,e[4]=h*i+g*s+_*u,e[5]=h*a+g*c+_*d,e[6]=v*r+y*o+b*l,e[7]=v*i+y*s+b*u,e[8]=v*a+y*c+b*d,e}function ht(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=t[6],u=t[7],d=t[8],f=n[0],p=n[1];return e[0]=r,e[1]=i,e[2]=a,e[3]=o,e[4]=s,e[5]=c,e[6]=f*r+p*o+l,e[7]=f*i+p*s+u,e[8]=f*a+p*c+d,e}function gt(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=t[6],u=t[7],d=t[8],f=Math.sin(n),p=Math.cos(n);return e[0]=p*r+f*o,e[1]=p*i+f*s,e[2]=p*a+f*c,e[3]=p*o-f*r,e[4]=p*s-f*i,e[5]=p*c-f*a,e[6]=l,e[7]=u,e[8]=d,e}function _t(e,t,n){let r=n[0],i=n[1];return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=i*t[3],e[4]=i*t[4],e[5]=i*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function vt(e,t){let n=t[0],r=t[1],i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10],p=t[11],m=t[12],h=t[13],g=t[14],_=t[15],v=n*s-r*o,y=n*c-i*o,b=n*l-a*o,x=r*c-i*s,S=r*l-a*s,C=i*l-a*c,w=u*h-d*m,T=u*g-f*m,E=u*_-p*m,D=d*g-f*h,O=d*_-p*h,k=f*_-p*g,A=v*k-y*O+b*D+x*E-S*T+C*w;return A?(A=1/A,e[0]=(s*k-c*O+l*D)*A,e[1]=(c*E-o*k-l*T)*A,e[2]=(o*O-s*E+l*w)*A,e[3]=(i*O-r*k-a*D)*A,e[4]=(n*k-i*E+a*T)*A,e[5]=(r*E-n*O-a*w)*A,e[6]=(h*C-g*S+_*x)*A,e[7]=(g*b-m*C-_*y)*A,e[8]=(m*S-h*b+_*v)*A,e):null}var yt=class extends Array{constructor(e=1,t=0,n=0,r=0,i=1,a=0,o=0,s=0,c=1){return super(e,t,n,r,i,a,o,s,c),this}set(e,t,n,r,i,a,o,s,c){return e.length?this.copy(e):(dt(this,e,t,n,r,i,a,o,s,c),this)}translate(e,t=this){return ht(this,t,e),this}rotate(e,t=this){return gt(this,t,e),this}scale(e,t=this){return _t(this,t,e),this}multiply(e,t){return t?mt(this,e,t):mt(this,this,e),this}identity(){return ft(this),this}copy(e){return ut(this,e),this}fromMatrix4(e){return ct(this,e),this}fromQuaternion(e){return lt(this,e),this}fromBasis(e,t,n){return this.set(e[0],e[1],e[2],t[0],t[1],t[2],n[0],n[1],n[2]),this}inverse(e=this){return pt(this,e),this}getNormalMatrix(e){return vt(this,e),this}},bt=0,xt=class extends V{constructor(e,{geometry:t,program:n,mode:r=e.TRIANGLES,frustumCulled:i=!0,renderOrder:a=0}={}){super(),e.canvas||console.error(`gl not passed as first argument to Mesh`),this.gl=e,this.id=bt++,this.geometry=t,this.program=n,this.mode=r,this.frustumCulled=i,this.renderOrder=a,this.modelViewMatrix=new B,this.normalMatrix=new yt,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(t=>t&&t({mesh:this,camera:e}));let t=this.program.cullFace&&this.worldMatrix.determinant()<0;this.program.use({flipFaces:t}),this.geometry.draw({mode:this.mode,program:this.program}),this.afterRenderCallbacks.forEach(t=>t&&t({mesh:this,camera:e}))}},St=new Uint8Array(4);function Ct(e){return(e&e-1)==0}var wt=1,H=class{constructor(e,{image:t,target:n=e.TEXTURE_2D,type:r=e.UNSIGNED_BYTE,format:i=e.RGBA,internalFormat:a=i,wrapS:o=e.CLAMP_TO_EDGE,wrapT:s=e.CLAMP_TO_EDGE,wrapR:c=e.CLAMP_TO_EDGE,generateMipmaps:l=n===(e.TEXTURE_2D||e.TEXTURE_CUBE_MAP),minFilter:u=l?e.NEAREST_MIPMAP_LINEAR:e.LINEAR,magFilter:d=e.LINEAR,premultiplyAlpha:f=!1,unpackAlignment:p=4,flipY:m=n==(e.TEXTURE_2D||e.TEXTURE_3D),anisotropy:h=0,level:g=0,width:_,height:v=_,length:y=1}={}){this.gl=e,this.id=wt++,this.image=t,this.target=n,this.type=r,this.format=i,this.internalFormat=a,this.minFilter=u,this.magFilter=d,this.wrapS=o,this.wrapT=s,this.wrapR=c,this.generateMipmaps=l,this.premultiplyAlpha=f,this.unpackAlignment=p,this.flipY=m,this.anisotropy=Math.min(h,this.gl.renderer.parameters.maxAnisotropy),this.level=g,this.width=_,this.height=v,this.length=y,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){let t=!(this.image===this.store.image&&!this.needsUpdate);if((t||this.glState.textureUnits[e]!==this.id)&&(this.gl.renderer.activeTexture(e),this.bind()),t){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 e=0;e<6;e++)this.gl.texImage2D(this.gl.TEXTURE_CUBE_MAP_POSITIVE_X+e,this.level,this.internalFormat,this.format,this.type,this.image[e]);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 e=0;e<this.image.length;e++)this.gl.compressedTexImage2D(this.target,e,this.internalFormat,this.image[e].width,this.image[e].height,0,this.image[e].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&&(!Ct(this.image.width)||!Ct(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 e=0;e<6;e++)this.gl.texImage2D(this.gl.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,St);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,St);this.store.image=this.image}}},Tt=class{constructor(e,{width:t=e.canvas.width,height:n=e.canvas.height,target:r=e.FRAMEBUFFER,color:i=1,depth:a=!0,stencil:o=!1,depthTexture:s=!1,wrapS:c=e.CLAMP_TO_EDGE,wrapT:l=e.CLAMP_TO_EDGE,wrapR:u=e.CLAMP_TO_EDGE,minFilter:d=e.LINEAR,magFilter:f=d,type:p=e.UNSIGNED_BYTE,format:m=e.RGBA,internalFormat:h=m,unpackAlignment:g,premultiplyAlpha:_}={}){this.gl=e,this.width=t,this.height=n,this.depth=a,this.stencil=o,this.buffer=this.gl.createFramebuffer(),this.target=r,this.gl.renderer.bindFramebuffer(this),this.textures=[];let v=[];for(let r=0;r<i;r++)this.textures.push(new H(e,{width:t,height:n,wrapS:c,wrapT:l,wrapR:u,minFilter:d,magFilter:f,type:p,format:m,internalFormat:h,unpackAlignment:g,premultiplyAlpha:_,flipY:!1,generateMipmaps:!1})),this.textures[r].update(),this.gl.framebufferTexture2D(this.target,this.gl.COLOR_ATTACHMENT0+r,this.gl.TEXTURE_2D,this.textures[r].texture,0),v.push(this.gl.COLOR_ATTACHMENT0+r);v.length>1&&this.gl.renderer.drawBuffers(v),this.texture=this.textures[0],s&&(this.gl.renderer.isWebgl2||this.gl.renderer.getExtension(`WEBGL_depth_texture`))?(this.depthTexture=new H(e,{width:t,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)):(a&&!o&&(this.depthBuffer=this.gl.createRenderbuffer(),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.depthBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_COMPONENT16,t,n),this.gl.framebufferRenderbuffer(this.target,this.gl.DEPTH_ATTACHMENT,this.gl.RENDERBUFFER,this.depthBuffer)),o&&!a&&(this.stencilBuffer=this.gl.createRenderbuffer(),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.stencilBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.STENCIL_INDEX8,t,n),this.gl.framebufferRenderbuffer(this.target,this.gl.STENCIL_ATTACHMENT,this.gl.RENDERBUFFER,this.stencilBuffer)),a&&o&&(this.depthStencilBuffer=this.gl.createRenderbuffer(),this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.depthStencilBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_STENCIL,t,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,t){if(!(this.width===e&&this.height===t)){this.width=e,this.height=t,this.gl.renderer.bindFramebuffer(this);for(let n=0;n<this.textures.length;n++)this.textures[n].width=e,this.textures[n].height=t,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=t,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,t)),this.stencilBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.stencilBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.STENCIL_INDEX8,e,t)),this.depthStencilBuffer&&(this.gl.bindRenderbuffer(this.gl.RENDERBUFFER,this.depthStencilBuffer),this.gl.renderbufferStorage(this.gl.RENDERBUFFER,this.gl.DEPTH_STENCIL,e,t))),this.gl.renderer.bindFramebuffer({target:this.target})}}},Et=class extends Array{constructor(e=0,t=e,n=e,r=e){return super(e,t,n,r),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,t=e,n=e,r=e){return e.length?this.copy(e):(pe(this,e,t,n,r),this)}copy(e){return fe(this,e),this}normalize(){return he(this,this),this}multiply(e){return me(this,this,e),this}dot(e){return ge(this,e)}fromArray(e,t=0){return this[0]=e[t],this[1]=e[t+1],this[2]=e[t+2],this[3]=e[t+3],this}toArray(e=[],t=0){return e[t]=this[0],e[t+1]=this[1],e[t+2]=this[2],e[t+3]=this[3],e}},Dt=`
|
|
4
|
+
precision highp float;
|
|
5
|
+
precision highp int;
|
|
6
|
+
|
|
7
|
+
attribute vec3 position;
|
|
8
|
+
attribute vec3 normal;
|
|
9
|
+
|
|
10
|
+
uniform mat3 normalMatrix;
|
|
11
|
+
uniform mat4 modelViewMatrix;
|
|
12
|
+
uniform mat4 projectionMatrix;
|
|
13
|
+
|
|
14
|
+
varying vec3 vNormal;
|
|
15
|
+
|
|
16
|
+
void main() {
|
|
17
|
+
vNormal = normalize(normalMatrix * normal);
|
|
18
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
19
|
+
}
|
|
20
|
+
`,Ot=`
|
|
21
|
+
precision highp float;
|
|
22
|
+
precision highp int;
|
|
23
|
+
|
|
24
|
+
varying vec3 vNormal;
|
|
25
|
+
|
|
26
|
+
void main() {
|
|
27
|
+
gl_FragColor.rgb = normalize(vNormal);
|
|
28
|
+
gl_FragColor.a = 1.0;
|
|
29
|
+
}
|
|
30
|
+
`;function kt(e){return new I(e,{vertex:Dt,fragment:Ot,cullFace:!1})}var At=new M,jt=new M,Mt=new M,Nt=new M,Pt=new je,Ft=new je,It=new je,Lt=new je,Rt=class{constructor(e,t=1){this.data=e,this.elapsed=0,this.weight=t,this.loop=!0,this.startTime=e.reduce((e,{times:t})=>Math.min(e,t[0]),1/0),this.endTime=e.reduce((e,{times:t})=>Math.max(e,t[t.length-1]),0),this.duration=this.endTime-this.startTime}update(e=1,t){let n=t?1:this.weight/e,r=this.duration?(this.loop?this.elapsed%this.duration:Math.min(this.elapsed,this.duration-.001))+this.startTime:0;this.data.forEach(({node:e,transform:t,interpolation:i,times:a,values:o})=>{if(!this.duration){let r=At,i=3;t===`quaternion`&&(r=Pt,i=4),r.fromArray(o,0),i===4?e[t].slerp(r,n):e[t].lerp(r,n);return}let s=Math.max(1,a.findIndex(e=>e>r))-1,c=s+1,l=(r-a[s])/(a[c]-a[s]);i===`STEP`&&(l=0);let u=At,d=jt,f=Mt,p=Nt,m=3;t===`quaternion`&&(u=Pt,d=Ft,f=It,p=Lt,m=4),i===`CUBICSPLINE`?(u.fromArray(o,s*m*3+m*1),d.fromArray(o,s*m*3+m*2),f.fromArray(o,c*m*3+m*0),p.fromArray(o,c*m*3+m*1),u=this.cubicSplineInterpolate(l,u,d,f,p),m===4&&u.normalize()):(u.fromArray(o,s*m),p.fromArray(o,c*m),m===4?u.slerp(p,l):u.lerp(p,l)),m===4?e[t].slerp(u,n):e[t].lerp(u,n)})}cubicSplineInterpolate(e,t,n,r,i){let a=e*e,o=a*e,s=3*a-2*o,c=o-a,l=1-s,u=c-a+e;for(let a=0;a<t.length;a++)t[a]=l*t[a]+u*(1-e)*n[a]+s*i[a]+c*e*r[a];return t}},zt=new B,Bt=new B,Vt=class extends xt{constructor(e,{skeleton:t,geometry:n,program:r,mode:i=e.TRIANGLES}={}){super(e,{geometry:n,program:r,mode:i}),this.skeleton=t,this.program=r,this.createBoneTexture()}createBoneTexture(){if(!this.skeleton.joints.length)return;let e=Math.max(4,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 H(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,t)=>{zt.multiply(e.worldMatrix,e.bindInverse),this.boneMatrices.set(zt,t*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();let t=this.worldMatrix;this.worldMatrix=Bt,super.draw({camera:e}),this.worldMatrix=t}},Ht=class extends xt{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`);let e=this.geometry.attributes.instanceMatrix.data;this.instanceTransforms=[];for(let t=0,n=0;t<e.length;t+=16,n++){let r=new V;r.index=n,r.matrix.fromArray(e,t),r.decompose(),this.instanceTransforms.push(r),r.setParent(this.parent)}if(this.totalInstanceCount=this.instanceTransforms.length,this.geometry.attributes.lightmapScaleOffset){let e=this.geometry.attributes.lightmapScaleOffset.data;for(let t=0,n=0;t<e.length;t+=4,n++)this.instanceTransforms[n].lightmapData=new Et().fromArray(e,t)}this.frustumCullFunction=({camera:e})=>{this.instanceRenderList=[],this.instanceTransforms.forEach(t=>{e.frustumIntersectsMesh(this,t.worldMatrix)&&this.instanceRenderList.push(t)}),this.instanceRenderList.forEach((e,t)=>{e.matrix.toArray(this.geometry.attributes.instanceMatrix.data,t*16),e.lightmapData&&(e.lightmapData.toArray(this.geometry.attributes.lightmapScaleOffset.data,t*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,t)=>{e.matrix.toArray(this.geometry.attributes.instanceMatrix.data,t*16),e.lightmapData&&(e.lightmapData.toArray(this.geometry.attributes.lightmapScaleOffset.data,t*4),this.geometry.attributes.lightmapScaleOffset.needsUpdate=!0)}),this.geometry.attributes.instanceMatrix.needsUpdate=!0}},Ut={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array,"image/jpeg":Uint8Array,"image/png":Uint8Array,"image/webp":Uint8Array},Wt={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Gt={POSITION:`position`,NORMAL:`normal`,TANGENT:`tangent`,TEXCOORD_0:`uv`,TEXCOORD_1:`uv2`,COLOR_0:`color`,WEIGHTS_0:`skinWeight`,JOINTS_0:`skinIndex`},Kt={translation:`position`,rotation:`quaternion`,scale:`scale`},qt=class{static setDracoManager(e){this.dracoManager=e}static setBasisManager(e){this.basisManager=e}static async load(e,t){let n=t.split(`/`).slice(0,-1).join(`/`)+`/`,r=await this.parseDesc(t);return this.parse(e,r,n)}static async parse(e,t,n){(t.asset===void 0||t.asset.version[0]<2)&&console.warn(`Only GLTF >=2.0 supported. Attempting to parse.`),t.extensionsRequired?.includes(`KHR_draco_mesh_compression`)&&!this.dracoManager&&console.warn(`KHR_draco_mesh_compression extension required but no manager supplied. Use .setDracoManager()`),t.extensionsRequired?.includes(`KHR_texture_basisu`)&&!this.basisManager&&console.warn(`KHR_texture_basisu extension required but no manager supplied. Use .setBasisManager()`);let r=await this.loadBuffers(t,n);e.renderer.bindVertexArray(null);let i=this.parseBufferViews(e,t,r),a=await this.parseImages(e,t,n,i),o=this.parseTextures(e,t,a),s=this.parseMaterials(e,t,o),c=this.parseSkins(e,t,i),l=await this.parseMeshes(e,t,i,s,c),[u,d]=this.parseNodes(e,t,l,c,a);this.populateSkins(c,u);let f=this.parseAnimations(e,t,u,i),p=this.parseScenes(t,u),m=p[t.scene],h=this.parseLights(e,t,u,p);for(let e=u.length;e>=0;e--)u[e]||u.splice(e,1);return{json:t,buffers:r,bufferViews:i,cameras:d,images:a,textures:o,materials:s,meshes:l,nodes:u,lights:h,animations:f,scenes:p,scene:m}}static parseDesc(e){return fetch(e,{mode:`cors`}).then(e=>e.arrayBuffer()).then(e=>{let t=new TextDecoder;return t.decode(new Uint8Array(e,0,4))===`glTF`?this.unpackGLB(e):JSON.parse(t.decode(e))})}static unpackGLB(e){let t=new Uint32Array(e,0,3);if(t[0]!==1179937895)throw Error(`Invalid glTF asset.`);if(t[1]!==2)throw Error(`Unsupported glTF binary version, "${t[1]}".`);let n=new Uint32Array(e,12,2),r=n[0];if(n[1]!==1313821514)throw Error(`Unexpected GLB layout.`);let i=new TextDecoder().decode(e.slice(20,20+r)),a=JSON.parse(i);if(20+r===e.byteLength)return a;let o=new Uint32Array(e,20+r,2);if(o[1]!==5130562)throw Error(`Unexpected GLB layout.`);let s=20+r+8,c=o[0],l=e.slice(s,s+c);return a.buffers[0].binary=l,a}static resolveURI(e,t){return typeof e!=`string`||e===``?``:(/^https?:\/\//i.test(t)&&/^\//.test(e)&&(t=t.replace(/(^https?:\/\/[^\/]+).*/i,`$1`)),/^(https?:)?\/\//i.test(e)||/^data:.*,.*$/i.test(e)||/^blob:.*$/i.test(e)?e:t+e)}static loadBuffers(e,t){return e.buffers?Promise.all(e.buffers.map(e=>{if(e.binary)return e.binary;let n=this.resolveURI(e.uri,t);return fetch(n,{mode:`cors`}).then(e=>e.arrayBuffer())})):null}static parseBufferViews(e,t,n){if(!t.bufferViews)return null;let r=t.bufferViews;return t.meshes&&t.meshes.forEach(({primitives:n})=>{n.forEach(({attributes:n,indices:i,extensions:a})=>{for(let e in n){let i=t.accessors[n[e]];i.bufferView===void 0&&a&&a.KHR_draco_mesh_compression&&(i.bufferView=a.KHR_draco_mesh_compression.bufferView,r[i.bufferView].isDraco=!0),r[i.bufferView].isAttribute=!0}if(i!==void 0){let n=t.accessors[i];n.bufferView===void 0&&a&&a.KHR_draco_mesh_compression&&(n.bufferView=a.KHR_draco_mesh_compression.bufferView,r[n.bufferView].isDraco=!0),r[n.bufferView].isAttribute=!0,r[n.bufferView].target=e.ELEMENT_ARRAY_BUFFER}})}),t.accessors.forEach(({bufferView:e,componentType:t})=>{e!==void 0&&(r[e].componentType=t)}),t.images&&t.images.forEach(({uri:e,bufferView:t,mimeType:n})=>{t!==void 0&&(r[t].mimeType=n)}),r.forEach(({buffer:t,byteOffset:i=0,byteLength:a,byteStride:o,target:s=e.ARRAY_BUFFER,name:c,extensions:l,extras:u,componentType:d,mimeType:f,isAttribute:p,isDraco:m},h)=>{if(r[h].data=n[t].slice(i,i+a),!p||m)return;let g=e.createBuffer();e.bindBuffer(s,g),e.renderer.state.boundBuffer=g,e.bufferData(s,r[h].data,e.STATIC_DRAW),r[h].buffer=g}),r}static parseImages(e,t,n,r){return t.images?Promise.all(t.images.map(async({uri:e,bufferView:t,mimeType:i,name:a})=>{if(i===`image/ktx2`){let{data:e}=r[t];return await this.basisManager.parseTexture(e)}let o=new Image;if(o.name=a,e)o.src=this.resolveURI(e,n);else if(t!==void 0){let{data:e}=r[t],n=new Blob([e],{type:i});o.src=URL.createObjectURL(n)}return o.ready=new Promise(e=>{o.onload=()=>e()}),o})):null}static parseTextures(e,t,n){return t.textures?t.textures.map(r=>this.createTexture(e,t,n,r)):null}static createTexture(e,t,n,{sampler:r,source:i,name:a,extensions:o,extras:s}){i===void 0&&o&&(o.EXT_texture_webp&&(i=o.EXT_texture_webp.source),o.KHR_texture_basisu&&(i=o.KHR_texture_basisu.source));let c=n[i];if(c.texture)return c.texture;let l={flipY:!1,wrapS:e.REPEAT,wrapT:e.REPEAT},u=r===void 0?null:t.samplers[r];if(u&&[`magFilter`,`minFilter`,`wrapS`,`wrapT`].forEach(e=>{u[e]&&(l[e]=u[e])}),c.isBasis){l.image=c,l.internalFormat=c.internalFormat,c.isCompressedTexture&&(l.generateMipmaps=!1,c.length>1&&(this.minFilter=e.NEAREST_MIPMAP_LINEAR));let t=new H(e,l);return t.name=a,c.texture=t,t}let d=new H(e,l);return d.name=a,c.texture=d,c.ready.then(()=>{d.image=c}),d}static parseMaterials(e,t,n){return t.materials?t.materials.map(({name:e,extensions:t,extras:r,pbrMetallicRoughness:i={},normalTexture:a,occlusionTexture:o,emissiveTexture:s,emissiveFactor:c=[0,0,0],alphaMode:l=`OPAQUE`,alphaCutoff:u=.5,doubleSided:d=!1})=>{let{baseColorFactor:f=[1,1,1,1],baseColorTexture:p,metallicFactor:m=1,roughnessFactor:h=1,metallicRoughnessTexture:g}=i;return p&&(p.texture=n[p.index]),a&&(a.texture=n[a.index]),g&&(g.texture=n[g.index]),o&&(o.texture=n[o.index]),s&&(s.texture=n[s.index]),{name:e,extensions:t,extras:r,baseColorFactor:f,baseColorTexture:p,metallicFactor:m,roughnessFactor:h,metallicRoughnessTexture:g,normalTexture:a,occlusionTexture:o,emissiveTexture:s,emissiveFactor:c,alphaMode:l,alphaCutoff:u,doubleSided:d}}):null}static parseSkins(e,t,n){return t.skins?t.skins.map(({inverseBindMatrices:e,skeleton:r,joints:i})=>({inverseBindMatrices:this.parseAccessor(e,t,n),skeleton:r,joints:i})):null}static parseMeshes(e,t,n,r,i){return t.meshes?Promise.all(t.meshes.map(async({primitives:a,weights:o,name:s,extensions:c,extras:l={}},u)=>{let d=0,f=[],p=!1;return t.nodes&&t.nodes.forEach(({mesh:e,skin:t,extras:n})=>{e===u&&(d++,t!==void 0&&f.push(t),n&&n.lightmap_scale_offset&&(p=!0))}),f.length?(a=await Promise.all(f.map(async o=>(await this.parsePrimitives(e,a,t,n,r,1,p)).map(({geometry:t,program:n,mode:r})=>{let a=new Vt(e,{skeleton:i[o],geometry:t,program:n,mode:r});return a.name=s,a.extras=l,c&&(a.extensions=c),a.frustumCulled=!1,a}))),a.instanceCount=0,a.numInstances=d):a=(await this.parsePrimitives(e,a,t,n,r,d,p)).map(({geometry:t,program:n,mode:r})=>{let i=new(t.attributes.instanceMatrix?Ht:xt)(e,{geometry:t,program:n,mode:r});return i.name=s,i.extras=l,c&&(i.extensions=c),i.numInstances=d,i}),{primitives:a,weights:o,name:s}})):null}static parsePrimitives(e,t,n,r,i,a,o){return Promise.all(t.map(async({attributes:t,indices:s,material:c,mode:l=4,targets:u,extensions:d,extras:f})=>{let p=new kt(e);c!==void 0&&(p.gltfMaterial=i[c]);let m=new te(e);if(f&&(m.extras=f),d&&(m.extensions=d),d&&d.KHR_draco_mesh_compression){let i=d.KHR_draco_mesh_compression.bufferView,a=d.KHR_draco_mesh_compression.attributes,o={},s={},c={},l={};for(let e in t){let r=n.accessors[t[e]],i=Gt[e];o[i]=a[e],s[i]=r.componentType,c[i]=Ut[r.componentType].name,l[i]=r.normalized===!0}let{data:u}=r[i],f=await this.dracoManager.decodeGeometry(u,{attributeIds:o,attributeTypes:c});for(let t=0;t<f.attributes.length;t++){let n=f.attributes[t],r=n.name,i=n.array,a=n.itemSize,o=s[r],c=l[r],u=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,u),e.renderer.state.boundBuffer=u,e.bufferData(e.ARRAY_BUFFER,i,e.STATIC_DRAW),m.addAttribute(r,{data:i,size:a,type:o,normalized:c,buffer:u})}if(f.index){let t=f.index.array,n=f.index.itemSize,r=e.createBuffer();e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.renderer.state.boundBuffer=r,e.bufferData(e.ELEMENT_ARRAY_BUFFER,t,e.STATIC_DRAW),m.addAttribute(`index`,{data:t,size:n,type:5125,normalized:!1,buffer:r})}}else{for(let e in t)m.addAttribute(Gt[e],this.parseAccessor(t[e],n,r));s!==void 0&&m.addAttribute(`index`,this.parseAccessor(s,n,r))}return a>1&&m.addAttribute(`instanceMatrix`,{instanced:1,size:16,data:new Float32Array(a*16)}),o&&m.addAttribute(`lightmapScaleOffset`,{instanced:1,size:4,data:new Float32Array(a*4)}),{geometry:m,program:p,mode:l}}))}static parseAccessor(e,t,n){let{bufferView:r,byteOffset:i=0,componentType:a,normalized:o=!1,count:s,type:c,min:l,max:u,sparse:d}=t.accessors[e],{data:f,buffer:p,byteOffset:m=0,byteStride:h=0,target:g}=n[r],_=Wt[c],v=Ut[a],y=h/v.BYTES_PER_ELEMENT,b=!!h&&y!==_,x;if(b){let e=new v(f,i);x=new v(s*_);for(let t=0;t<s;t++){let n=y*t,r=n+_;x.set(e.slice(n,r),t*_)}}else x=new v(f,i,s*_);return{data:x,size:_,type:a,normalized:o,buffer:p,stride:h,offset:i,count:s,min:l,max:u}}static parseNodes(e,t,n,r,i){if(!t.nodes)return null;let a=[],o=t.nodes.map(({camera:r,children:o,skin:s,matrix:c,mesh:l,rotation:u,scale:d,translation:f,weights:p,name:m,extensions:h,extras:g})=>{let _=r!==void 0,v=_?new st(e):new V;if(_){let e=t.cameras[r];if(e.type===`perspective`){let{yfov:t,znear:n,zfar:r}=e.perspective;v.perspective({fov:180/Math.PI*t,near:n,far:r})}else{let{xmag:t,ymag:n,znear:r,zfar:i}=e.orthographic;v.orthographic({near:r,far:i,left:-t,right:t,top:-n,bottom:n})}a.push(v)}m&&(v.name=m),g&&(v.extras=g),h&&(v.extensions=h),g&&g.lightmapTexture!==void 0&&(g.lightmapTexture.texture=this.createTexture(e,t,i,{source:g.lightmapTexture.index})),c?(v.matrix.copy(c),v.decompose()):(u&&v.quaternion.copy(u),d&&v.scale.copy(d),f&&v.position.copy(f),v.updateMatrix());let y=!1,b=!0,x=!1;if(l!==void 0&&(s===void 0?n[l].primitives.forEach(e=>{g&&Object.assign(e.extras,g),e.geometry.isInstanced&&(y=!0,e.instanceCount?b=!1:e.instanceCount=0,e.geometry.attributes.instanceMatrix&&(x=!0,v.matrix.toArray(e.geometry.attributes.instanceMatrix.data,e.instanceCount*16)),e.geometry.attributes.lightmapScaleOffset&&e.geometry.attributes.lightmapScaleOffset.data.set(g.lightmap_scale_offset,e.instanceCount*4),e.instanceCount++,e.instanceCount===e.numInstances&&(delete e.numInstances,delete e.instanceCount,e.geometry.attributes.instanceMatrix&&(e.geometry.attributes.instanceMatrix.needsUpdate=!0),e.geometry.attributes.lightmapScaleOffset&&(e.geometry.attributes.lightmapScaleOffset.needsUpdate=!0))),y?b&&e.setParent(v):e.setParent(v)}):(n[l].primitives[n[l].primitives.instanceCount].forEach(e=>{g&&Object.assign(e.extras,g),e.setParent(v)}),n[l].primitives.instanceCount++,n[l].primitives.instanceCount===n[l].primitives.numInstances&&(delete n[l].primitives.numInstances,delete n[l].primitives.instanceCount))),x){if(!b)return null;v.matrix.identity(),v.decompose()}return v});return t.nodes.forEach(({children:e=[]},t)=>{e.forEach(e=>{o[e]&&o[e].setParent(o[t])})}),n.forEach(({primitives:e},t)=>{e.forEach((e,t)=>{e.isInstancedMesh&&e.addFrustumCull()})}),[o,a]}static populateSkins(e,t){e&&e.forEach(e=>{e.joints=e.joints.map((n,r)=>{let i=t[n];return i.skin=e,i.bindInverse=new B(...e.inverseBindMatrices.data.slice(r*16,(r+1)*16)),i}),e.skeleton&&=t[e.skeleton]})}static parseAnimations(e,t,n,r){return t.animations?t.animations.map(({channels:e,samplers:i,name:a},o)=>({name:a,animation:new Rt(e.map(({sampler:e,target:a})=>{let{input:s,interpolation:c=`LINEAR`,output:l}=i[e],{node:u,path:d}=a,f=n[u],p=Kt[d],m=this.parseAccessor(s,t,r).data,h=this.parseAccessor(l,t,r).data;return f.animations||=[],f.animations.includes(o)||f.animations.push(o),{node:f,transform:p,interpolation:c,times:m,values:h}}))})):null}static parseScenes(e,t){return e.scenes?e.scenes.map(({nodes:e=[],name:n,extensions:r,extras:i})=>{let a=e.reduce((e,n)=>(t[n]&&e.push(t[n]),e),[]);return a.extras=i,a}):null}static parseLights(e,t,n,r){let i={directional:[],point:[],spot:[]};r.forEach(e=>e.forEach(e=>e.updateMatrixWorld()));let a=t.extensions?.KHR_lights_punctual?.lights||[];return n.forEach(e=>{if(!e?.extensions?.KHR_lights_punctual)return;let t=a[e.extensions.KHR_lights_punctual.light],n={name:t.name||``,color:{value:new M().set(t.color||1)}};switch(t.intensity!==void 0&&n.color.value.multiply(t.intensity),t.type){case`directional`:n.direction={value:new M(0,0,1).transformDirection(e.worldMatrix)};break;case`point`:n.position={value:new M().applyMatrix4(e.worldMatrix)},n.distance={value:t.range},n.decay={value:2};break;case`spot`:Object.assign(n,t);break}i[t.type].push(n)}),i}},U=()=>{let e=new Float32Array(16);return e[0]=e[5]=e[10]=e[15]=1,e},W=(e,t,n)=>{for(let r=0;r<4;r++){let i=n[r*4],a=n[r*4+1],o=n[r*4+2],s=n[r*4+3];e[r*4]=t[0]*i+t[4]*a+t[8]*o+t[12]*s,e[r*4+1]=t[1]*i+t[5]*a+t[9]*o+t[13]*s,e[r*4+2]=t[2]*i+t[6]*a+t[10]*o+t[14]*s,e[r*4+3]=t[3]*i+t[7]*a+t[11]*o+t[15]*s}return e},G=e=>{let t=e[0],n=e[1],r=e[2],i=e[4],a=e[5],o=e[6],s=e[8],c=e[9],l=e[10],u=t*(a*l-o*c)-i*(n*l-r*c)+s*(n*o-r*a),d=u===0?0:1/u,f=new Float32Array(16);f[0]=(a*l-o*c)*d,f[1]=(r*c-n*l)*d,f[2]=(n*o-r*a)*d,f[4]=(o*s-i*l)*d,f[5]=(t*l-r*s)*d,f[6]=(r*i-t*o)*d,f[8]=(i*c-a*s)*d,f[9]=(n*s-t*c)*d,f[10]=(t*a-n*i)*d;let p=e[12],m=e[13],h=e[14];return f[12]=-(f[0]*p+f[4]*m+f[8]*h),f[13]=-(f[1]*p+f[5]*m+f[9]*h),f[14]=-(f[2]*p+f[6]*m+f[10]*h),f[15]=1,f},Jt=e=>[Math.hypot(e[0],e[1],e[2]),Math.hypot(e[4],e[5],e[6]),Math.hypot(e[8],e[9],e[10])],Yt=(e,t,n,r,i)=>{let[a,o,s]=Jt(e),c=Math.hypot(t,n,r,i)||1,l=t/c,u=n/c,d=r/c,f=i/c,p=l*l,m=l*u,h=l*d,g=l*f,_=u*u,v=u*d,y=u*f,b=d*d,x=d*f;e[0]=(1-2*(_+b))*a,e[1]=2*(m+x)*a,e[2]=2*(h-y)*a,e[4]=2*(m-x)*o,e[5]=(1-2*(p+b))*o,e[6]=2*(v+g)*o,e[8]=2*(h+y)*s,e[9]=2*(v-g)*s,e[10]=(1-2*(p+_))*s},K=Math.PI/180,Xt=(e,t,n,r,i)=>{let[a,o,s]=Jt(e),c=t*K,l=n*K,u=r*K,d=Math.cos(c),f=Math.sin(c),p=Math.cos(l),m=Math.sin(l),h=Math.cos(u),g=Math.sin(u),_=1,v=0,y=0,b=0,x=1,S=0,C=0,w=0,T=1;switch(i){case 0:_=p*h,v=-p*g,y=m,b=f*m*h+d*g,x=-f*m*g+d*h,S=-f*p,C=-d*m*h+f*g,w=d*m*g+f*h,T=d*p;break;case 1:_=p*h+m*f*g,v=-p*g+m*f*h,y=m*d,b=d*g,x=d*h,S=-f,C=-m*h+p*f*g,w=m*g+p*f*h,T=p*d;break;case 2:_=p*h-m*f*g,v=-d*g,y=m*h+p*f*g,b=p*g+m*f*h,x=d*h,S=m*g-p*f*h,C=-m*d,w=f,T=p*d;break;case 3:_=p*h,v=f*m*h-d*g,y=d*m*h+f*g,b=p*g,x=f*m*g+d*h,S=d*m*g-f*h,C=-m,w=f*p,T=d*p;break;case 4:_=p*h,v=-g,y=m*h,b=f*m+d*p*g,x=d*h,S=-p*f+d*m*g,C=-d*m+f*p*g,w=f*h,T=d*p+f*m*g;break;case 5:_=p*h,v=-p*g,y=m,b=d*g+f*m*h,x=d*h-f*m*g,S=-f*p,C=f*g-d*m*h,w=f*h+d*m*g,T=d*p;break}e[0]=_*a,e[1]=b*a,e[2]=C*a,e[4]=v*o,e[5]=x*o,e[6]=w*o,e[8]=y*s,e[9]=S*s,e[10]=T*s},Zt=(e,t,n,r)=>{let[i,a,o]=Jt(e);if(i===0||a===0||o===0){e[0]=t,e[1]=0,e[2]=0,e[4]=0,e[5]=n,e[6]=0,e[8]=0,e[9]=0,e[10]=r;return}let s=t/i,c=n/a,l=r/o;e[0]*=s,e[1]*=s,e[2]*=s,e[4]*=c,e[5]*=c,e[6]*=c,e[8]*=l,e[9]*=l,e[10]*=l},Qt=e=>{let[t,n,r]=Jt(e);if(t===0||n===0||r===0)return[0,0,0];let i=e[0]/t,a=e[1]/t,o=e[2]/t;e[4]/n;let s=e[5]/n,c=e[8]/r,l=e[9]/r,u=e[10]/r,d=Math.asin(-Math.min(1,Math.max(-1,l))),f,p;return Math.abs(l)<.9999?(f=Math.atan2(c,u),p=Math.atan2(a,s)):(f=Math.atan2(-o,i),p=0),[d/K,f/K,p/K]},$t=(e,t,n)=>{let r=U();return Yt(r,t[0],t[1],t[2],t[3]),Zt(r,n[0],n[1],n[2]),r[12]=e[0],r[13]=e[1],r[14]=e[2],r},en=(e,t,n,r)=>{let i=1/Math.tan(e*K/2),a=new Float32Array(16);return a[0]=i/t,a[5]=i,a[10]=(r+n)/(n-r),a[11]=-1,a[14]=2*r*n/(n-r),a},tn=(e,t,n,r,i,a)=>{let o=new Float32Array(16);return o[0]=2/(t-e),o[5]=2/(r-n),o[10]=-2/(a-i),o[12]=-(t+e)/(t-e),o[13]=-(r+n)/(r-n),o[14]=-(a+i)/(a-i),o[15]=1,o},nn=(e,t,n,r)=>{let i=-1/0,a=1/0;for(let o=0;o<3;o++){if(r[o]===0)continue;let s=(e[o]-t[o]-n[o])/r[o],c=(e[o]+t[o]-n[o])/r[o];i=Math.max(i,Math.min(s,c)),a=Math.min(a,Math.max(s,c))}return i<0||a<i?-1:i},rn=(e,t,n,r)=>{let i=n[0]-e[0],a=n[1]-e[1],o=n[2]-e[2],s=r[0]**2+r[1]**2+r[2]**2,c=2*(i*r[0]+a*r[1]+o*r[2]),l=i*i+a*a+o*o-t*t,u=c*c-4*s*l;if(u<0)return-1;let d=Math.sqrt(u),f=(-c-d)/(2*s),p=(-c+d)/(2*s);return f>0&&p>0?Math.min(f,p):f>0?f:p>0?p:-1},an=(e,t,n,r,i,a)=>(e[0]=t[0]*n+t[4]*r+t[8]*i+t[12]*a,e[1]=t[1]*n+t[5]*r+t[9]*i+t[13]*a,e[2]=t[2]*n+t[6]*r+t[10]*i+t[14]*a,e),on=1/(1.2*2**Math.log2(256/(1/125))),sn=`#version 300 es
|
|
31
|
+
precision highp float;
|
|
32
|
+
in vec3 position;
|
|
33
|
+
in vec3 normal;
|
|
34
|
+
in vec2 uv;
|
|
35
|
+
uniform mat4 modelMatrix;
|
|
36
|
+
uniform mat4 modelViewMatrix;
|
|
37
|
+
uniform mat4 projectionMatrix;
|
|
38
|
+
uniform mat3 normalMatrix;
|
|
39
|
+
out vec3 vWorldPos;
|
|
40
|
+
out vec3 vNormal;
|
|
41
|
+
out vec2 vUv;
|
|
42
|
+
`,cn=`
|
|
43
|
+
in vec4 skinIndex;
|
|
44
|
+
in vec4 skinWeight;
|
|
45
|
+
uniform sampler2D boneTexture;
|
|
46
|
+
uniform int boneTextureSize;
|
|
47
|
+
|
|
48
|
+
mat4 getBoneMatrix(const in float i) {
|
|
49
|
+
float j = i * 4.0;
|
|
50
|
+
float x = mod(j, float(boneTextureSize));
|
|
51
|
+
float y = floor(j / float(boneTextureSize));
|
|
52
|
+
float dx = 1.0 / float(boneTextureSize);
|
|
53
|
+
float dy = 1.0 / float(boneTextureSize);
|
|
54
|
+
y = dy * (y + 0.5);
|
|
55
|
+
vec4 v1 = texture(boneTexture, vec2(dx * (x + 0.5), y));
|
|
56
|
+
vec4 v2 = texture(boneTexture, vec2(dx * (x + 1.5), y));
|
|
57
|
+
vec4 v3 = texture(boneTexture, vec2(dx * (x + 2.5), y));
|
|
58
|
+
vec4 v4 = texture(boneTexture, vec2(dx * (x + 3.5), y));
|
|
59
|
+
return mat4(v1, v2, v3, v4);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
mat4 getSkinMatrix() {
|
|
63
|
+
mat4 boneMatX = getBoneMatrix(skinIndex.x);
|
|
64
|
+
mat4 boneMatY = getBoneMatrix(skinIndex.y);
|
|
65
|
+
mat4 boneMatZ = getBoneMatrix(skinIndex.z);
|
|
66
|
+
mat4 boneMatW = getBoneMatrix(skinIndex.w);
|
|
67
|
+
return boneMatX * skinWeight.x + boneMatY * skinWeight.y + boneMatZ * skinWeight.z + boneMatW * skinWeight.w;
|
|
68
|
+
}
|
|
69
|
+
`,ln=e=>`${sn}
|
|
70
|
+
${e.includes(`HAS_SKIN`)?cn:``}
|
|
71
|
+
${e.includes(`HAS_COLOR`)?`in vec4 color;
|
|
72
|
+
out vec4 vColor;`:``}
|
|
73
|
+
uniform mat4 shadowMatrix;
|
|
74
|
+
out vec4 vShadowCoord;
|
|
75
|
+
|
|
76
|
+
void main() {
|
|
77
|
+
vec4 pos = vec4(position, 1.0);
|
|
78
|
+
vec3 nrm = normal;
|
|
79
|
+
${e.includes(`HAS_SKIN`)?`
|
|
80
|
+
mat4 skinMatrix = getSkinMatrix();
|
|
81
|
+
pos = skinMatrix * pos;
|
|
82
|
+
nrm = mat3(skinMatrix) * nrm;
|
|
83
|
+
`:``}
|
|
84
|
+
${e.includes(`HAS_COLOR`)?`vColor = color;`:``}
|
|
85
|
+
vec4 worldPos = modelMatrix * pos;
|
|
86
|
+
vWorldPos = worldPos.xyz;
|
|
87
|
+
vNormal = normalize(mat3(modelMatrix) * nrm);
|
|
88
|
+
vUv = uv;
|
|
89
|
+
vShadowCoord = shadowMatrix * worldPos;
|
|
90
|
+
gl_Position = projectionMatrix * modelViewMatrix * pos;
|
|
91
|
+
}
|
|
92
|
+
`,un=`
|
|
93
|
+
uniform vec3 sunDirection;
|
|
94
|
+
uniform vec4 sunColorIntensity; // rgb = linear color, a = intensity (lux)
|
|
95
|
+
uniform float iblLuminance;
|
|
96
|
+
uniform vec3 iblSH[9];
|
|
97
|
+
uniform samplerCube envMap;
|
|
98
|
+
uniform float envMapMaxLod;
|
|
99
|
+
uniform sampler2D shadowMap;
|
|
100
|
+
uniform float shadowEnabled;
|
|
101
|
+
uniform float shadowMapSize;
|
|
102
|
+
uniform float exposure;
|
|
103
|
+
in vec4 vShadowCoord;
|
|
104
|
+
|
|
105
|
+
#define PI 3.14159265359
|
|
106
|
+
|
|
107
|
+
float D_GGX(float NoH, float a) {
|
|
108
|
+
float a2 = a * a;
|
|
109
|
+
float f = (NoH * a2 - NoH) * NoH + 1.0;
|
|
110
|
+
return a2 / (PI * f * f);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
float V_SmithGGXCorrelated(float NoV, float NoL, float a) {
|
|
114
|
+
float a2 = a * a;
|
|
115
|
+
float GGXL = NoV * sqrt((-NoL * a2 + NoL) * NoL + a2);
|
|
116
|
+
float GGXV = NoL * sqrt((-NoV * a2 + NoV) * NoV + a2);
|
|
117
|
+
return 0.5 / (GGXV + GGXL + 1e-5);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
vec3 F_Schlick(float u, vec3 f0) {
|
|
121
|
+
float f = pow(1.0 - u, 5.0);
|
|
122
|
+
return f0 + (vec3(1.0) - f0) * f;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
vec3 evalSH(vec3 n) {
|
|
126
|
+
return max(
|
|
127
|
+
iblSH[0]
|
|
128
|
+
+ iblSH[1] * n.y
|
|
129
|
+
+ iblSH[2] * n.z
|
|
130
|
+
+ iblSH[3] * n.x
|
|
131
|
+
+ iblSH[4] * (n.y * n.x)
|
|
132
|
+
+ iblSH[5] * (n.y * n.z)
|
|
133
|
+
+ iblSH[6] * (3.0 * n.z * n.z - 1.0)
|
|
134
|
+
+ iblSH[7] * (n.z * n.x)
|
|
135
|
+
+ iblSH[8] * (n.x * n.x - n.y * n.y)
|
|
136
|
+
, vec3(0.0));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
float sampleShadowPCF() {
|
|
140
|
+
if (shadowEnabled < 0.5) return 1.0;
|
|
141
|
+
vec3 coord = vShadowCoord.xyz / vShadowCoord.w;
|
|
142
|
+
coord = coord * 0.5 + 0.5;
|
|
143
|
+
if (coord.x < 0.0 || coord.x > 1.0 || coord.y < 0.0 || coord.y > 1.0 || coord.z > 1.0) return 1.0;
|
|
144
|
+
float bias = 0.0018;
|
|
145
|
+
float texel = 1.0 / shadowMapSize;
|
|
146
|
+
float sum = 0.0;
|
|
147
|
+
for (int x = -1; x <= 1; x++) {
|
|
148
|
+
for (int y = -1; y <= 1; y++) {
|
|
149
|
+
float depth = texture(shadowMap, coord.xy + vec2(float(x), float(y)) * texel).r;
|
|
150
|
+
sum += (coord.z - bias) > depth ? 0.0 : 1.0;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return sum / 9.0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// diffuseColor: linear albedo (already metallic-adjusted); f0: specular reflectance at normal.
|
|
157
|
+
vec3 shadePBR(vec3 n, vec3 v, vec3 diffuseColor, vec3 f0, float perceptualRoughness, float occlusion) {
|
|
158
|
+
float roughness = clamp(perceptualRoughness, 0.045, 1.0);
|
|
159
|
+
float a = roughness * roughness;
|
|
160
|
+
float NoV = abs(dot(n, v)) + 1e-5;
|
|
161
|
+
|
|
162
|
+
vec3 color = vec3(0.0);
|
|
163
|
+
|
|
164
|
+
// --- sun ---
|
|
165
|
+
if (sunColorIntensity.a > 0.0) {
|
|
166
|
+
vec3 l = normalize(-sunDirection);
|
|
167
|
+
float NoL = clamp(dot(n, l), 0.0, 1.0);
|
|
168
|
+
if (NoL > 0.0) {
|
|
169
|
+
vec3 h = normalize(v + l);
|
|
170
|
+
float NoH = clamp(dot(n, h), 0.0, 1.0);
|
|
171
|
+
float LoH = clamp(dot(l, h), 0.0, 1.0);
|
|
172
|
+
float D = D_GGX(NoH, a);
|
|
173
|
+
float V = V_SmithGGXCorrelated(NoV, NoL, a);
|
|
174
|
+
vec3 F = F_Schlick(LoH, f0);
|
|
175
|
+
vec3 Fr = D * V * F;
|
|
176
|
+
vec3 Fd = diffuseColor * (1.0 / PI);
|
|
177
|
+
float shadow = sampleShadowPCF();
|
|
178
|
+
// "illuminance" model: lux * NoL, pre-exposed
|
|
179
|
+
color += (Fd + Fr) * sunColorIntensity.rgb * (sunColorIntensity.a * exposure * NoL * shadow);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// --- IBL ---
|
|
184
|
+
if (iblLuminance > 0.0) {
|
|
185
|
+
// cmgen's SH coefficients are pre-convolved irradiance — no extra 1/PI (matches Filament).
|
|
186
|
+
vec3 irradiance = evalSH(n);
|
|
187
|
+
vec3 Fd = diffuseColor * irradiance;
|
|
188
|
+
|
|
189
|
+
vec3 r = reflect(-v, n);
|
|
190
|
+
float lod = roughness * envMapMaxLod;
|
|
191
|
+
vec3 prefiltered = textureLod(envMap, r, lod).rgb;
|
|
192
|
+
// Simple DFG approximation (Karis): avoids a DFG LUT.
|
|
193
|
+
vec3 specular = prefiltered * (f0 * (1.0 - roughness) + roughness * 0.25 * f0 + 0.05 * (1.0 - roughness));
|
|
194
|
+
color += (Fd + specular) * (iblLuminance * exposure * occlusion);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return color;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ACES filmic fit (Narkowicz) + sRGB OETF — stands in for Filament's default ACES color grading.
|
|
201
|
+
vec3 tonemap(vec3 x) {
|
|
202
|
+
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;
|
|
203
|
+
vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
|
|
204
|
+
return pow(t, vec3(1.0 / 2.2));
|
|
205
|
+
}
|
|
206
|
+
`,dn=`#version 300 es
|
|
207
|
+
precision highp float;
|
|
208
|
+
in vec3 vWorldPos;
|
|
209
|
+
in vec3 vNormal;
|
|
210
|
+
in vec2 vUv;
|
|
211
|
+
uniform vec3 cameraPosition;
|
|
212
|
+
uniform vec3 baseColor; // linear
|
|
213
|
+
uniform sampler2D baseColorMap;
|
|
214
|
+
uniform float useBaseColorMap;
|
|
215
|
+
uniform float roughness;
|
|
216
|
+
uniform float metallic;
|
|
217
|
+
${un}
|
|
218
|
+
out vec4 fragColor;
|
|
219
|
+
|
|
220
|
+
void main() {
|
|
221
|
+
vec3 albedo = useBaseColorMap > 0.5 ? texture(baseColorMap, vUv).rgb : baseColor;
|
|
222
|
+
vec3 n = normalize(vNormal);
|
|
223
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
224
|
+
if (dot(n, v) < 0.0) n = -n;
|
|
225
|
+
vec3 diffuseColor = albedo * (1.0 - metallic);
|
|
226
|
+
vec3 f0 = mix(vec3(0.04), albedo, metallic);
|
|
227
|
+
vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, 1.0);
|
|
228
|
+
fragColor = vec4(tonemap(color), 1.0);
|
|
229
|
+
}
|
|
230
|
+
`,fn=`#version 300 es
|
|
231
|
+
precision highp float;
|
|
232
|
+
in vec3 vWorldPos;
|
|
233
|
+
in vec3 vNormal;
|
|
234
|
+
in vec2 vUv;
|
|
235
|
+
uniform vec4 baseColor; // linear, premultiplied
|
|
236
|
+
uniform sampler2D baseColorMap;
|
|
237
|
+
uniform float useBaseColorMap;
|
|
238
|
+
out vec4 fragColor;
|
|
239
|
+
|
|
240
|
+
vec3 tonemapUnlit(vec3 x) {
|
|
241
|
+
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;
|
|
242
|
+
vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
|
|
243
|
+
return pow(t, vec3(1.0 / 2.2));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
void main() {
|
|
247
|
+
vec4 c = useBaseColorMap > 0.5 ? texture(baseColorMap, vUv) : baseColor;
|
|
248
|
+
fragColor = vec4(tonemapUnlit(c.rgb), c.a);
|
|
249
|
+
}
|
|
250
|
+
`,pn=`#version 300 es
|
|
251
|
+
precision highp float;
|
|
252
|
+
in vec2 vUv;
|
|
253
|
+
in vec3 vWorldPos;
|
|
254
|
+
in vec3 vNormal;
|
|
255
|
+
uniform sampler2D baseColorMap;
|
|
256
|
+
out vec4 fragColor;
|
|
257
|
+
void main() {
|
|
258
|
+
fragColor = vec4(texture(baseColorMap, vUv).rgb, 1.0);
|
|
259
|
+
}
|
|
260
|
+
`,mn=`#version 300 es
|
|
261
|
+
precision highp float;
|
|
262
|
+
in vec3 vWorldPos;
|
|
263
|
+
in vec3 vNormal;
|
|
264
|
+
in vec2 vUv;
|
|
265
|
+
uniform vec4 color; // linear, premultiplied
|
|
266
|
+
${un}
|
|
267
|
+
out vec4 fragColor;
|
|
268
|
+
void main() {
|
|
269
|
+
float vis = sampleShadowPCF();
|
|
270
|
+
float shadowAmount = 1.0 - vis;
|
|
271
|
+
fragColor = vec4(color.rgb * shadowAmount, color.a * shadowAmount);
|
|
272
|
+
}
|
|
273
|
+
`,hn=e=>ln(e),gn=ln(``),_n=e=>`#version 300 es
|
|
274
|
+
precision highp float;
|
|
275
|
+
${e}
|
|
276
|
+
in vec3 vWorldPos;
|
|
277
|
+
in vec3 vNormal;
|
|
278
|
+
in vec2 vUv;
|
|
279
|
+
#ifdef HAS_COLOR
|
|
280
|
+
in vec4 vColor;
|
|
281
|
+
#endif
|
|
282
|
+
uniform vec3 cameraPosition;
|
|
283
|
+
uniform vec4 uBaseColorFactor;
|
|
284
|
+
uniform float uMetallic;
|
|
285
|
+
uniform float uRoughness;
|
|
286
|
+
uniform vec3 uEmissive;
|
|
287
|
+
uniform float uAlphaCutoff;
|
|
288
|
+
#ifdef HAS_BASECOLOR_MAP
|
|
289
|
+
uniform sampler2D uBaseColorMap;
|
|
290
|
+
#endif
|
|
291
|
+
#ifdef HAS_MR_MAP
|
|
292
|
+
uniform sampler2D uMRMap;
|
|
293
|
+
#endif
|
|
294
|
+
#ifdef HAS_NORMAL_MAP
|
|
295
|
+
uniform sampler2D uNormalMap;
|
|
296
|
+
#endif
|
|
297
|
+
#ifdef HAS_OCCLUSION_MAP
|
|
298
|
+
uniform sampler2D uOcclusionMap;
|
|
299
|
+
#endif
|
|
300
|
+
#ifdef HAS_EMISSIVE_MAP
|
|
301
|
+
uniform sampler2D uEmissiveMap;
|
|
302
|
+
#endif
|
|
303
|
+
${un}
|
|
304
|
+
out vec4 fragColor;
|
|
305
|
+
|
|
306
|
+
#ifdef HAS_NORMAL_MAP
|
|
307
|
+
vec3 getNormal() {
|
|
308
|
+
vec3 pos_dx = dFdx(vWorldPos);
|
|
309
|
+
vec3 pos_dy = dFdy(vWorldPos);
|
|
310
|
+
vec2 tex_dx = dFdx(vUv);
|
|
311
|
+
vec2 tex_dy = dFdy(vUv);
|
|
312
|
+
float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
|
|
313
|
+
if (abs(det) < 1e-8) return normalize(vNormal);
|
|
314
|
+
vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
|
|
315
|
+
vec3 ng = normalize(vNormal);
|
|
316
|
+
t = normalize(t - ng * dot(ng, t));
|
|
317
|
+
vec3 b = normalize(cross(ng, t)) * sign(det);
|
|
318
|
+
mat3 tbn = mat3(t, b, ng);
|
|
319
|
+
vec3 n = texture(uNormalMap, vUv).rgb * 2.0 - 1.0;
|
|
320
|
+
return normalize(tbn * n);
|
|
321
|
+
}
|
|
322
|
+
#endif
|
|
323
|
+
|
|
324
|
+
void main() {
|
|
325
|
+
vec4 base = uBaseColorFactor;
|
|
326
|
+
#ifdef HAS_BASECOLOR_MAP
|
|
327
|
+
base *= texture(uBaseColorMap, vUv);
|
|
328
|
+
#endif
|
|
329
|
+
#ifdef HAS_COLOR
|
|
330
|
+
base *= vColor;
|
|
331
|
+
#endif
|
|
332
|
+
#ifdef ALPHA_MASK
|
|
333
|
+
if (base.a < uAlphaCutoff) discard;
|
|
334
|
+
#endif
|
|
335
|
+
|
|
336
|
+
float metallic = uMetallic;
|
|
337
|
+
float roughness = uRoughness;
|
|
338
|
+
#ifdef HAS_MR_MAP
|
|
339
|
+
vec3 mr = texture(uMRMap, vUv).rgb;
|
|
340
|
+
roughness *= mr.g;
|
|
341
|
+
metallic *= mr.b;
|
|
342
|
+
#endif
|
|
343
|
+
|
|
344
|
+
float occlusion = 1.0;
|
|
345
|
+
#ifdef HAS_OCCLUSION_MAP
|
|
346
|
+
occlusion = texture(uOcclusionMap, vUv).r;
|
|
347
|
+
#endif
|
|
348
|
+
|
|
349
|
+
#ifdef HAS_NORMAL_MAP
|
|
350
|
+
vec3 n = getNormal();
|
|
351
|
+
#else
|
|
352
|
+
vec3 n = normalize(vNormal);
|
|
353
|
+
#endif
|
|
354
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
355
|
+
#ifdef DOUBLE_SIDED
|
|
356
|
+
if (dot(n, v) < 0.0) n = -n;
|
|
357
|
+
#endif
|
|
358
|
+
|
|
359
|
+
vec3 diffuseColor = base.rgb * (1.0 - metallic);
|
|
360
|
+
vec3 f0 = mix(vec3(0.04), base.rgb, metallic);
|
|
361
|
+
vec3 color = shadePBR(n, v, diffuseColor, f0, roughness, occlusion);
|
|
362
|
+
|
|
363
|
+
vec3 emissive = uEmissive;
|
|
364
|
+
#ifdef HAS_EMISSIVE_MAP
|
|
365
|
+
emissive *= texture(uEmissiveMap, vUv).rgb;
|
|
366
|
+
#endif
|
|
367
|
+
color += emissive * iblLuminance * exposure;
|
|
368
|
+
|
|
369
|
+
#ifdef ALPHA_BLEND
|
|
370
|
+
fragColor = vec4(tonemap(color), base.a);
|
|
371
|
+
#else
|
|
372
|
+
fragColor = vec4(tonemap(color), 1.0);
|
|
373
|
+
#endif
|
|
374
|
+
}
|
|
375
|
+
`,vn=e=>`#version 300 es
|
|
376
|
+
precision highp float;
|
|
377
|
+
in vec3 position;
|
|
378
|
+
${e?`in vec3 normal;
|
|
379
|
+
in vec2 uv;`:``}
|
|
380
|
+
uniform mat4 modelMatrix;
|
|
381
|
+
uniform mat4 shadowViewProjection;
|
|
382
|
+
${e?cn:``}
|
|
383
|
+
void main() {
|
|
384
|
+
vec4 pos = vec4(position, 1.0);
|
|
385
|
+
${e?`pos = getSkinMatrix() * pos;`:``}
|
|
386
|
+
gl_Position = shadowViewProjection * modelMatrix * pos;
|
|
387
|
+
}
|
|
388
|
+
`,yn=`#version 300 es
|
|
389
|
+
precision highp float;
|
|
390
|
+
out vec4 fragColor;
|
|
391
|
+
void main() { fragColor = vec4(1.0); }
|
|
392
|
+
`,bn=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,xn=e=>Math.min(1,Math.max(0,e*(2.51*e+.03)/(e*(2.43*e+.59)+.14)))**(1/2.2),Sn=e=>[bn((e>>>16&255)/255),bn((e>>>8&255)/255),bn((e&255)/255)],Cn=e=>[bn((e>>>24&255)/255),bn((e>>>16&255)/255),bn((e>>>8&255)/255),(e&255)/255],wn=2873840728,Tn=e=>{let t=new DataView(e);if(t.getUint32(0,!1)!==wn)throw Error(`Not a KTX1 file`);let n=t.getUint32(12,!0)===67305985,r=e=>t.getUint32(e,n),i=r(16),a=r(24),o=r(28),s=r(36),c=r(40),l=r(52),u=Math.max(1,r(56)),d=r(60),f=new Map,p=new TextDecoder(`utf-8`),m=64,h=64+d;for(;m<h;){let t=r(m);m+=4;let n=new Uint8Array(e,m,t),i=n.indexOf(0),a=p.decode(n.subarray(0,i)),o=p.decode(n.subarray(i+1)).replace(/\0+$/,``);f.set(a,o),m+=t+(3-(t+3)%4)}let g=[];m=h;for(let t=0;t<u;t++){let t=r(m);m+=4;let n=[];for(let r=0;r<l;r++)n.push(new Uint8Array(e,m,t)),m+=t+(3-(t+3)%4);g.push(n)}return{glType:i,glFormat:a,glInternalFormat:o,width:s,height:c,faces:l,mipLevels:u,keyValues:f,mips:g}},En=e=>{let t=new Float32Array(27);if(!e)return t;let n=e.trim().split(/[\s\n]+/).map(Number);for(let e=0;e<Math.min(27,n.length);e++)t[e]=n[e];return t},Dn=35898,On=35899,kn=6407,An=(e,t)=>{let n=Tn(t),r=En(n.keyValues.get(`sh`)),i=new H(e,{target:e.TEXTURE_CUBE_MAP,generateMipmaps:!1,minFilter:e.LINEAR_MIPMAP_LINEAR,magFilter:e.LINEAR,flipY:!1,width:n.width,height:n.height}),a=n.glInternalFormat===Dn;e.bindTexture(e.TEXTURE_CUBE_MAP,i.texture),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.pixelStorei(e.UNPACK_ALIGNMENT,1);for(let t=0;t<n.mipLevels;t++){let r=Math.max(1,n.width>>t);for(let i=0;i<n.faces;i++){let o=n.mips[t][i];if(a)e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+i,t,Dn,r,r,0,kn,On,new Uint32Array(o.buffer,o.byteOffset,o.byteLength/4));else{let a=n.glFormat===kn?3:4;e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+i,t,a===3?e.RGB8:e.RGBA8,r,r,0,a===3?e.RGB:e.RGBA,e.UNSIGNED_BYTE,o)}}}return e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MAX_LEVEL,n.mipLevels-1),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MAG_FILTER,e.LINEAR),i.store.image=i.image=n,i.needsUpdate=!1,{sh:r,cubemap:i,maxLod:n.mipLevels-1}},jn=e=>new H(e,{image:new Uint8Array([255,255,255,255]),width:1,height:1,generateMipmaps:!1}),Mn=e=>{let t=new H(e,{target:e.TEXTURE_CUBE_MAP,width:1,height:1,generateMipmaps:!1,minFilter:e.LINEAR});e.bindTexture(e.TEXTURE_CUBE_MAP,t.texture);let n=new Uint8Array(4);for(let t=0;t<6;t++)e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,n);return t.store.image=t.image=n,t.needsUpdate=!1,t},Nn=(e,t)=>{let n=t?.texture;!n||n._srgbTagged||(n._srgbTagged=!0,n.internalFormat=e.SRGB8_ALPHA8,n.format=e.RGBA)},Pn=(e,t,n,r,i,a)=>{let o=t??{},s=[];n&&s.push(`#define HAS_SKIN`),r&&s.push(`#define HAS_COLOR`),o.baseColorTexture?.texture&&s.push(`#define HAS_BASECOLOR_MAP`),o.metallicRoughnessTexture?.texture&&s.push(`#define HAS_MR_MAP`),o.normalTexture?.texture&&s.push(`#define HAS_NORMAL_MAP`),o.occlusionTexture?.texture&&s.push(`#define HAS_OCCLUSION_MAP`),o.emissiveTexture?.texture&&s.push(`#define HAS_EMISSIVE_MAP`),o.doubleSided&&s.push(`#define DOUBLE_SIDED`),o.alphaMode===`MASK`&&s.push(`#define ALPHA_MASK`),o.alphaMode===`BLEND`&&s.push(`#define ALPHA_BLEND`);let c=s.join(`
|
|
393
|
+
`);Nn(e,o.baseColorTexture),Nn(e,o.emissiveTexture);let l={...i,uBaseColorFactor:{value:o.baseColorFactor??[1,1,1,1]},uMetallic:{value:o.metallicFactor??1},uRoughness:{value:o.roughnessFactor??1},uEmissive:{value:o.emissiveFactor??[0,0,0]},uAlphaCutoff:{value:o.alphaCutoff??.5}};o.baseColorTexture?.texture&&(l.uBaseColorMap={value:o.baseColorTexture.texture}),o.metallicRoughnessTexture?.texture&&(l.uMRMap={value:o.metallicRoughnessTexture.texture}),o.normalTexture?.texture&&(l.uNormalMap={value:o.normalTexture.texture}),o.occlusionTexture?.texture&&(l.uOcclusionMap={value:o.occlusionTexture.texture}),o.emissiveTexture?.texture&&(l.uEmissiveMap={value:o.emissiveTexture.texture});let u=new I(e,{vertex:hn((n?`HAS_SKIN `:``)+(r?`HAS_COLOR`:``)),fragment:_n(c),uniforms:l,transparent:o.alphaMode===`BLEND`,cullFace:o.doubleSided?!1:e.BACK});return o.alphaMode===`BLEND`&&u.setBlendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),u},Fn=async(e,t,n,r)=>{let i=qt.unpackGLB(t),a=await qt.parse(e,i,``),o=new Map,s=new Set,c=[];for(let e of a.nodes)e.traverse(e=>(e.draw&&!s.has(e)&&(s.add(e),c.push(e)),!1));for(let t of c){let i=t.program?.gltfMaterial,a=t instanceof Vt,s=t.geometry?.attributes?.color,c=!!s&&s.size===4,l=a||c?t:i??t,u=o.get(l);u||(u=Pn(e,i,a,c,n,r),o.set(l,u)),t.program=u,t._receiveShadows=!0,t._castShadows=!0}a.images&&await Promise.all(a.images.map(e=>e?.ready).filter(Boolean));let l=(a.animations??[]).map((e,t)=>{let n=[];for(let t of e.animation.data)n.includes(t.node)||n.push(t.node);return{name:typeof e.name==`string`&&e.name.length>0?e.name:`animation_${t}`,duration:e.animation.duration,animation:e.animation,nodes:n}});return{roots:a.scene??[],nodes:a.nodes??[],animations:l}},In=e=>{if(!e||e.byteLength<24||e.byteLength>1e6||new Uint8Array(e,0,1)[0]!==123)return null;try{let t=JSON.parse(new TextDecoder().decode(e));return t?.lecodesLiteMaterial===1?t:null}catch{return null}},Ln={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])}},Rn=`
|
|
394
|
+
struct MaterialInputs {
|
|
395
|
+
vec4 baseColor;
|
|
396
|
+
float roughness;
|
|
397
|
+
float metallic;
|
|
398
|
+
float reflectance;
|
|
399
|
+
float ambientOcclusion;
|
|
400
|
+
vec4 emissive;
|
|
401
|
+
vec3 normal;
|
|
402
|
+
float clearCoat;
|
|
403
|
+
float clearCoatRoughness;
|
|
404
|
+
vec4 postLightingColor;
|
|
405
|
+
};
|
|
406
|
+
void prepareMaterial(inout MaterialInputs m) {}
|
|
407
|
+
vec2 getUV0() { return vUv; }
|
|
408
|
+
vec2 getUV1() { return vUv; }
|
|
409
|
+
vec3 getWorldPosition() { return vWorldPos; }
|
|
410
|
+
vec3 getWorldGeometricNormalVector() { return normalize(vNormal); }
|
|
411
|
+
vec3 getWorldViewVector() { return normalize(cameraPosition - vWorldPos); }
|
|
412
|
+
vec4 getUserTime() { return userTime; }
|
|
413
|
+
`,zn=`
|
|
414
|
+
MaterialInputs inputs;
|
|
415
|
+
inputs.baseColor = vec4(1.0);
|
|
416
|
+
inputs.roughness = 1.0;
|
|
417
|
+
inputs.metallic = 0.0;
|
|
418
|
+
inputs.reflectance = 0.5;
|
|
419
|
+
inputs.ambientOcclusion = 1.0;
|
|
420
|
+
inputs.emissive = vec4(0.0, 0.0, 0.0, 1.0);
|
|
421
|
+
inputs.normal = vec3(0.0, 0.0, 1.0);
|
|
422
|
+
inputs.clearCoat = 0.0;
|
|
423
|
+
inputs.clearCoatRoughness = 0.0;
|
|
424
|
+
inputs.postLightingColor = vec4(0.0);
|
|
425
|
+
material(inputs);
|
|
426
|
+
`,Bn=`
|
|
427
|
+
vec3 applyTangentNormal(vec3 nTangent, vec3 ng) {
|
|
428
|
+
vec3 pos_dx = dFdx(vWorldPos);
|
|
429
|
+
vec3 pos_dy = dFdy(vWorldPos);
|
|
430
|
+
vec2 tex_dx = dFdx(vUv);
|
|
431
|
+
vec2 tex_dy = dFdy(vUv);
|
|
432
|
+
float det = tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y;
|
|
433
|
+
if (abs(det) < 1e-8) return ng;
|
|
434
|
+
vec3 t = normalize(pos_dx * tex_dy.y - pos_dy * tex_dx.y);
|
|
435
|
+
t = normalize(t - ng * dot(ng, t));
|
|
436
|
+
vec3 b = normalize(cross(ng, t)) * sign(det);
|
|
437
|
+
return normalize(mat3(t, b, ng) * nTangent);
|
|
438
|
+
}
|
|
439
|
+
`,Vn=`
|
|
440
|
+
vec3 tonemap(vec3 x) {
|
|
441
|
+
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;
|
|
442
|
+
vec3 t = clamp((x * (A * x + B)) / (x * (C * x + D) + E), 0.0, 1.0);
|
|
443
|
+
return pow(t, vec3(1.0 / 2.2));
|
|
444
|
+
}
|
|
445
|
+
`,Hn=e=>{if(e.unsupported)return null;let t=[],n=[],r=new Set;for(let i of e.params){let e=Ln[i.type];if(!e)return null;t.push(`uniform ${e.decl} materialParams_${i.name}${i.size?`[${i.size}]`:``};`);let a=i.size?Array(i.size*(Array.isArray(e.zero)||e.zero instanceof Float32Array?e.zero.length:1)).fill(0):e.zero;n.push({key:`materialParams_${i.name}`,value:Array.isArray(a)?[...a]:a}),r.add(i.name)}for(let i of e.samplers)t.push(`uniform sampler2D materialParams_${i.name};`),n.push({key:`materialParams_${i.name}`,value:`texture`}),r.add(i.name);let i=e.shadingModel===`lit`,a=i||e.shadowMultiplier,o=e.blending===`opaque`||e.blending===`masked`,s=e.blending===`masked`?`if (inputs.baseColor.a < ${e.maskThreshold.toFixed(4)}) discard;`:``,c=o?`1.0`:`inputs.baseColor.a`,l=e.shadowMultiplier?`
|
|
446
|
+
void main() {
|
|
447
|
+
${zn}
|
|
448
|
+
float shadowAmount = 1.0 - sampleShadowPCF();
|
|
449
|
+
fragColor = vec4(inputs.baseColor.rgb * shadowAmount, inputs.baseColor.a * shadowAmount);
|
|
450
|
+
}
|
|
451
|
+
`:i?`
|
|
452
|
+
void main() {
|
|
453
|
+
${zn}
|
|
454
|
+
${s}
|
|
455
|
+
vec3 n = normalize(vNormal);
|
|
456
|
+
vec3 v = normalize(cameraPosition - vWorldPos);
|
|
457
|
+
${e.doubleSided?`if (dot(n, v) < 0.0) n = -n;`:``}
|
|
458
|
+
${e.writesNormal?`n = applyTangentNormal(inputs.normal, n);`:``}
|
|
459
|
+
vec3 diffuseColor = inputs.baseColor.rgb * (1.0 - inputs.metallic);
|
|
460
|
+
vec3 f0 = mix(vec3(0.16 * inputs.reflectance * inputs.reflectance), inputs.baseColor.rgb, inputs.metallic);
|
|
461
|
+
vec3 color = shadePBR(n, v, diffuseColor, f0, inputs.roughness, inputs.ambientOcclusion);
|
|
462
|
+
color += inputs.emissive.rgb * (iblLuminance * exposure);
|
|
463
|
+
color += inputs.postLightingColor.rgb;
|
|
464
|
+
fragColor = vec4(tonemap(color), ${c});
|
|
465
|
+
}
|
|
466
|
+
`:`
|
|
467
|
+
void main() {
|
|
468
|
+
${zn}
|
|
469
|
+
${s}
|
|
470
|
+
vec3 color = inputs.baseColor.rgb + inputs.emissive.rgb + inputs.postLightingColor.rgb;
|
|
471
|
+
fragColor = vec4(tonemap(color), ${c});
|
|
472
|
+
}
|
|
473
|
+
`;return{fragment:`#version 300 es
|
|
474
|
+
precision highp float;
|
|
475
|
+
in vec3 vWorldPos;
|
|
476
|
+
in vec3 vNormal;
|
|
477
|
+
in vec2 vUv;
|
|
478
|
+
uniform vec3 cameraPosition;
|
|
479
|
+
uniform vec4 userTime;
|
|
480
|
+
${t.join(`
|
|
481
|
+
`)}
|
|
482
|
+
${a?un:Vn}
|
|
483
|
+
${Rn}
|
|
484
|
+
${e.writesNormal?Bn:``}
|
|
485
|
+
out vec4 fragColor;
|
|
486
|
+
${e.fragmentCode}
|
|
487
|
+
${l}`,uniforms:n,paramNames:r,needsSceneUniforms:a}},q=new Uint8Array(512);{let e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;let t=1337;for(let n=255;n>0;n--){t^=t<<13,t^=t>>>17,t^=t<<5;let r=Math.abs(t)%(n+1),i=e[n];e[n]=e[r],e[r]=i}for(let t=0;t<512;t++)q[t]=e[t&255]}var Un=e=>e*e*e*(e*(e*6-15)+10),J=(e,t,n)=>e+n*(t-e),Wn=(e,t,n)=>{switch(e&7){case 0:return t+n;case 1:return-t+n;case 2:return t-n;case 3:return-t-n;case 4:return t;case 5:return-t;case 6:return n;default:return-n}},Y=(e,t,n,r)=>{let i=e&15,a=i<8?t:n,o=i<4?n:i===12||i===14?t:r;return(i&1?-a:a)+(i&2?-o:o)},Gn=(e,t)=>{let n=Math.floor(e)&255,r=Math.floor(t)&255;e-=Math.floor(e),t-=Math.floor(t);let i=Un(e),a=Un(t),o=q[n]+r,s=q[n+1]+r;return J(J(Wn(q[o],e,t),Wn(q[s],e-1,t),i),J(Wn(q[o+1],e,t-1),Wn(q[s+1],e-1,t-1),i),a)*1.42},Kn=(e,t,n)=>{let r=Math.floor(e)&255,i=Math.floor(t)&255,a=Math.floor(n)&255;e-=Math.floor(e),t-=Math.floor(t),n-=Math.floor(n);let o=Un(e),s=Un(t),c=Un(n),l=q[r]+i,u=q[l]+a,d=q[l+1]+a,f=q[r+1]+i,p=q[f]+a,m=q[f+1]+a;return J(J(J(Y(q[u],e,t,n),Y(q[p],e-1,t,n),o),J(Y(q[d],e,t-1,n),Y(q[m],e-1,t-1,n),o),s),J(J(Y(q[u+1],e,t,n-1),Y(q[p+1],e-1,t,n-1),o),J(Y(q[d+1],e,t-1,n-1),Y(q[m+1],e-1,t-1,n-1),o),s),c)*1.14},qn=()=>{let e=new Map,t=1,n=t=>{let n=e.get(t);return n||(n={frequency:.01,octaves:1,lacunarity:2,gain:.5},e.set(t,n)),n},r=(e,t)=>{let n=0,r=1,i=0,a=e.frequency;for(let o=0;o<e.octaves;o++)n+=t(a)*r,i+=r,r*=e.gain,a*=e.lacunarity;return n/i};return{createNoise:()=>{let e=t++;return n(e),e},setNoiseFrequency:(e,t)=>{n(e).frequency=t},setNoiseOctaves:(e,t)=>{n(e).octaves=Math.max(1,t|0)},setNoiseFractalLunacrity:(e,t)=>{n(e).lacunarity=t},setNoiseFractalGain:(e,t)=>{n(e).gain=t},getNoise2D:(e,t,i)=>r(n(e),e=>Gn(t*e,i*e)),getNoise3D:(e,t,i,a)=>r(n(e),e=>Kn(t*e,i*e,a*e))}},Jn=1179937895,Yn=1313821514,Xn=e=>{try{if(e.byteLength<20)return null;let t=new DataView(e);if(t.getUint32(0,!0)!==Jn)return null;let n=t.getUint32(12,!0);if(t.getUint32(16,!0)!==Yn||20+n>e.byteLength)return null;let r=JSON.parse(new TextDecoder(`utf-8`).decode(new Uint8Array(e,20,n))),i=r.accessors??[],a=r.meshes??[],o=(r.nodes??[]).map(e=>{let t;t=Array.isArray(e.matrix)&&e.matrix.length===16?Float32Array.from(e.matrix):e.translation||e.rotation||e.scale?$t(e.translation??[0,0,0],e.rotation??[0,0,0,1],e.scale??[1,1,1]):U();let n={children:e.children??[],matrix:t};if(typeof e.name==`string`&&e.name.length>0&&(n.name=e.name),e.mesh!=null&&a[e.mesh]){let t=a[e.mesh].primitives??[],r,o;for(let e of t){let t=i[e.attributes?.POSITION];if(!(!t||!Array.isArray(t.min)||!Array.isArray(t.max)))if(!r||!o)r=[t.min[0],t.min[1],t.min[2]],o=[t.max[0],t.max[1],t.max[2]];else for(let e=0;e<3;e++)r[e]=Math.min(r[e],t.min[e]),o[e]=Math.max(o[e],t.max[e])}n.mesh={primitives:t.length,min:r,max:o}}return n}),s=(r.animations??[]).map((e,t)=>{let n=0;for(let t of e.samplers??[]){let e=i[t.input]?.max?.[0];typeof e==`number`&&e>n&&(n=e)}return{name:typeof e.name==`string`?e.name:`animation_${t}`,duration:n}}),c=r.scene??0;return{nodes:o,roots:r.scenes?.[c]?.nodes??[],animations:s}}catch{return null}},X=(e,t,n=16)=>{for(let r=0;r<n;r++)e[r]=t[r]};function Zn(e,t){let n=t.width??390,r=t.height??844,i=t.fov??60,a=new Map,o=new Map,s=new Map,c=new Map,l=1,u=1,d=1,f=-1,p=null,m=null,h=null,g=t=>{let n={id:t,name:``,m:e.allocMatrix(t),parent:0,children:[],visible:!0,materials:[]};return(n.m[0]!==1||n.m[5]!==1||n.m[10]!==1||n.m[15]!==1)&&X(n.m,U()),a.set(t,n),n},_=()=>g(l++),v=e=>{let t=a.get(e);return t||(t=g(e),e>=l&&(l=e+1)),t},y=e=>{let t=v(e);return t.parent===0?t.m:W(new Float32Array(16),y(t.parent),t.m)},b=e=>{let t=y(e);return t instanceof Float32Array?t:Float32Array.from(t)},x=e=>{if(e.parent!==0){let t=a.get(e.parent);t&&(t.children=t.children.filter(t=>t!==e.id)),e.parent=0}},S=(t,n,r)=>{let i=v(t);if(i.parent!==n){if(r){let e=b(t),r=n===0?e:W(new Float32Array(16),G(b(n)),e);X(i.m,r)}x(i),n!==0&&(i.parent=n,v(n).children.push(t)),e.parentChanged?.(t,n),e.localMatrixChanged?.(t)}},C=e=>{for(let t=e;t!==0;){for(let e of o.values())if(e.entities.has(t))return e;t=v(t).parent}return null},w=e=>{let n=t.getSourceName?.(e);if(!n)return;let r=n.startsWith(`lecodesfile://`)?decodeURIComponent(n.slice(14)):n;return(r.includes(`/`)||r.includes(`\\`))&&!r.startsWith(`http`)?r.split(/[\\/]/).pop()??r:r},T=e=>{let t=s.get(e);return t||(t={shader:`unknown`,uniforms:{}},s.set(e,t)),t},E=(t,n,r)=>{T(t).uniforms[n]=r,e.uniformChanged?.(t,n,r)},D=n=>{let r=t.getBuffer(n),i=r?Xn(r):null,a=_();if(a.model={source:w(n),animations:i?.animations??[],loaded:i!==null},!i)return{rootId:a.id,entIds:[]};let o=i.nodes.map(()=>_().id);i.nodes.forEach((t,n)=>{let r=v(o[n]);r.name=t.name??``,X(r.m,t.matrix),e.localMatrixChanged?.(r.id),t.mesh&&(r.mesh={kind:0,vertexCount:0,primitives:t.mesh.primitives},t.mesh.min&&t.mesh.max&&(r.mesh.size=[t.mesh.max[0]-t.mesh.min[0],t.mesh.max[1]-t.mesh.min[1],t.mesh.max[2]-t.mesh.min[2]],r.mesh.center=[(t.mesh.max[0]+t.mesh.min[0])/2,(t.mesh.max[1]+t.mesh.min[1])/2,(t.mesh.max[2]+t.mesh.min[2])/2]));for(let e of t.children)S(o[e],r.id,!1)});for(let e of i.roots)S(o[e],a.id,!1);return{rootId:a.id,entIds:o}},O=t=>{let n=v(t),r=_();r.name=n.name,X(r.m,n.m),r.visible=n.visible,n.light&&(r.light={...n.light}),n.mesh&&(r.mesh={...n.mesh}),r.materials=[...n.materials],n.model&&(r.model={...n.model,animations:n.model.animations,playing:n.model.playing?{...n.model.playing}:void 0}),n.castShadows!==void 0&&(r.castShadows=n.castShadows),n.receiveShadows!==void 0&&(r.receiveShadows=n.receiveShadows),n.particles&&(r.particles=structuredClone(n.particles)),n.physics&&(r.physics=structuredClone(n.physics)),n.collider&&(r.collider=structuredClone(n.collider)),n.anchor&&(r.anchor=n.anchor),e.localMatrixChanged?.(r.id),e.entityCloned?.(n.id,r.id);for(let e of n.children)S(O(e),r.id,!1);return r.id},k=t=>{let n=a.get(t);if(n){for(let e of[...n.children])k(e);x(n);for(let e of o.values())e.entities.delete(t);e.entityDestroyed?.(t),a.delete(t)}},A=t=>{for(let n of a.values()){let r=n.model?.playing;if(!r||r.paused)continue;let i=n.model.animations[r.clip];if(!i){n.model.playing=void 0;continue}r.time+=t*r.speed;let a=i.duration;if(r.time>=a&&a>0)if(p?.(n.id,r.clip))r.time=r.time>a*2?0:r.time-a;else{n.model.playing=void 0;continue}e.animationApply?.(n.id,r.clip,r.time)}},j=e=>{m?.(e),A(e),h?.(e)},M=e=>{let t=Math.min(1e3,Math.floor(e/16));for(let e=0;e<t;e++)j(.016)},N=()=>f>=0||o.size>0,P=()=>f,ee={createScene(){let t=o.size;return o.set(t,{id:t,entities:new Set,overlays:[]}),e.sceneCreated?.(t),t},createOverlayScene(t){let n=o.size;return o.set(n,{id:n,entities:new Set,overlays:[],overlayOf:t}),o.get(t)?.overlays.push(n),e.sceneCreated?.(n),n},createGLView(){},openScene(e){f=e},closeScene(){f=-1},addEntityToScene(t,n){let r=o.get(t);if(r){for(let e of o.values())e!==r&&e.entities.delete(n);r.entities.add(n),e.entitySceneChanged?.(n,t,!0)}},removeEntityFromScene(t,n){let r=o.get(t);r&&(r.entities.delete(n),e.entitySceneChanged?.(n,t,!1))},createEntity:()=>_().id,cloneEntity(t){let n=v(t),r=O(t);if(n.parent!==0)S(r,n.parent,!1);else{let n=C(t);n&&(n.entities.add(r),e.entitySceneChanged?.(r,n.id,!0))}return r},destroyEntity(e){k(e)},setMatrix(t,n){X(v(t).m,n),e.localMatrixChanged?.(t)},setWorldMatrix(t,n){let r=v(t);if(r.parent===0){X(r.m,n),e.localMatrixChanged?.(t);return}let i=W(new Float32Array(16),G(b(r.parent)),Float32Array.from(n.subarray(0,16)));X(r.m,i),e.localMatrixChanged?.(t)},getChildren:e=>[...v(e).children],getChildCount:e=>v(e).children.length,getChild:(e,t)=>v(e).children[t]??0,setPosition(t,n,r,i){let a=v(t).m;a[12]=n,a[13]=r,a[14]=i,e.localMatrixChanged?.(t)},setQuaternion(t,n,r,i,a){Yt(v(t).m,n,r,i,a),e.localMatrixChanged?.(t)},setEulerAngles(t,n,r,i,a){Xt(v(t).m,n,r,i,a),e.localMatrixChanged?.(t)},setScale(t,n,r,i){Zt(v(t).m,n,r,i),e.localMatrixChanged?.(t)},addChildren(e,t){for(let n of t)S(n,e,!1)},setParent(e,t,n){S(e,t,n)},setParentNull(e,t){S(e,0,t)},getParent:e=>v(e).parent,traverse(e,t){let n=e=>{t(e);for(let t of v(e).children)n(t)};for(let t of v(e).children)n(t)},createSunLight(e,t,n,r,i,a,o){v(e).light={direction:[t,n,r],intensity:i,color:a,shadowsQuality:o}},setDefaultIbl(e,t){let n=o.get(e);n&&(n.ibl=t)},setBloomOptions(e,t,n){let r=o.get(e);r&&(r.bloom=t?{strength:n}:void 0)},setSkybox(e,t){let n=o.get(e);n&&(n.skybox=t)},setSceneMultiSampleAntiAliasing(e,t){let n=o.get(e);n&&(n.antialias=t)},setMaterialGlobalParameter(){},getCameraFov(e,t){if(t!==1)return i;let a=i*Math.PI/180;return 2*Math.atan(Math.tan(a/2)*(n/r))*180/Math.PI},getMatrix(e,t){return t.set(F(e)),!0},getWorldMatrix(e,t){t.set(b(e))},getWorldPosition(e,t){let n=y(e);t[0]=n[12],t[1]=n[13],t[2]=n[14]},getWorldDirection(e,t,n){let r=y(e);n[0]=r[t*4],n[1]=r[t*4+1],n[2]=r[t*4+2]},getWorldMatrixInverse(e,t){t.set(G(b(e)))},getCameraViewDirection(e,t,a,s){let c=o.get(e)?.camera,l=c?y(c):U(),u=n/r,d=Math.tan(i*Math.PI/360),f=(t/n*2-1)*d*u,p=(1-a/r*2)*d,m=l[0]*f+l[4]*p-l[8],h=l[1]*f+l[5]*p-l[9],g=l[2]*f+l[6]*p-l[10],_=Math.hypot(m,h,g)||1;s[0]=m/_,s[1]=h/_,s[2]=g/_},setMesh(t,n,r,i,a,o,s){let c=v(t),l=1/0,u=1/0,d=1/0,f=-1/0,p=-1/0,m=-1/0;for(let e=0;e+2<r.length;e+=3){let t=r[e],n=r[e+1],i=r[e+2];t<l&&(l=t),t>f&&(f=t),n<u&&(u=n),n>p&&(p=n),i<d&&(d=i),i>m&&(m=i)}let h=r.length>=3,g={kind:s,vertexCount:Math.floor(r.length/3),size:h?[f-l,p-u,m-d]:void 0,center:h?[(f+l)/2,(p+u)/2,(m+d)/2]:void 0};c.mesh=g,c.materials[0]=n,e.meshSet?.(t,n,g,{vertices:r,normals:i,indices:a,uv:o})},setCulling(){},setCastShadows(e,t){v(e).castShadows=t},setReceiveShadows(e,t){v(e).receiveShadows=t},setCastShadowsGlobal(){},setReceiveShadowsGlobal(){},hasMesh:e=>v(e).mesh!==void 0,createMaterial(t){let n=u++,r={shader:w(t)??`unknown`,uniforms:{}};return s.set(n,r),e.materialCreated?.(n,r,t),n},createMaterialS(t){let n=u++,r={shader:t,uniforms:{}};return s.set(n,r),e.materialCreated?.(n,r),n},setMaterial(e,t,n){v(e).materials[n]=t},getMaterial:(e,t)=>v(e).materials[t]??0,setUniformRgb(e,t,n){E(e,t,{kind:`rgb`,v:n})},setUniformRgba(e,t,n){E(e,t,{kind:`rgba`,v:n})},setUniformFloat(e,t,n){E(e,t,{kind:`float`,v:n})},setUniformBoolean(e,t,n){E(e,t,{kind:`bool`,v:n})},setUniformTexture(e,t,n){E(e,t,{kind:`texture`,v:n})},setUniformArray(e,t,n){E(e,t,{kind:`array`,v:Array.from(n)})},setUniformNull(e,t){E(e,t,{kind:`null`})},createTexture(e,n,r){let i=t.getBuffer(e);if(!i||i.byteLength===0){r();return}let[a,o]=Qn(i),s=d++;c.set(s,{source:w(e),width:a,height:o}),n(s,a,o)},createTextureFromCanvas(e){let t=d++;return c.set(t,{source:`canvas#${e}`,width:0,height:0}),t},updateTextureFromCanvas(){},createMediaPlayerTexture(e){let t=d++;return c.set(t,{source:`mediaplayer#${e}`,width:0,height:0}),t},attachCameraToAR(e,t,a){let s=o.get(e);s&&(s.camera=t),a(en(i,n/r,.05,1e3),i)},getDisplaySize:()=>Float32Array.of(n,r),setVisible(t,n){v(t).visible=n,e.visibleChanged?.(t,n)},isVisible:e=>{for(let t=e;t!==0;t=v(t).parent)if(!v(t).visible)return!1;return!0},getName:e=>v(e).name,setName(e,t){v(e).name=t},createGlb(t,n,r){let{rootId:i,entIds:a}=D(t);if(!e.glbAttach){n(i);return}Promise.resolve(e.glbAttach(t,i,a)).then(()=>n(i)).catch(e=>r?.(e))},setGlbCulling(){},getGlbAnimations:e=>v(e).model?.animations??[],setOnAnimationComplete(e){p=e},setEarlyUpdate(e){m=e},setLateUpdate(e){h=e},setOnPhysicsEvent(){},setAnimation(t,n,r,i){let a=v(t).model;if(!a)return;let o=a.animations[r];if(!o)return;let s=a.playing;if(s)s.speed=i,s.paused=!n,(s.clip!==r||s.time>=o.duration)&&(s.clip=r,s.time=0,e.animationApply?.(t,r,0));else{if(!n)return;a.playing={clip:r,time:0,speed:i,paused:!1},e.animationApply?.(t,r,0)}},getAnimationTime:e=>v(e).model?.playing?.time??0,setAnimationTime(t,n,r){let i=v(t).model;i?.animations[n]&&(i.playing&&(i.playing.time=r),e.animationApply?.(t,n,r))}};function F(e){let t=v(e).m;return t instanceof Float32Array?t:Float32Array.from(t)}return{width:n,height:r,fov:i,entities:a,scenes:o,materials:s,textures:c,ent:v,newEnt:_,worldMatrix:y,worldMatrixF:b,sourceName:w,setParentInternal:S,sceneOf:C,rebindMatrix:(e,t)=>{v(e).m=t},methods:ee,simulate:M,tick:j,hasActiveScene:N,activeSceneId:P,nextTextureId:()=>d++,nextMaterialId:()=>u++}}var Qn=e=>{let t=new Uint8Array(e);if(t.length>24&&t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71){let t=new DataView(e);return[t.getUint32(16),t.getUint32(20)]}if(t.length>4&&t[0]===255&&t[1]===216){let n=new DataView(e),r=2;for(;r+9<t.length&&t[r]===255;){let e=t[r+1];if(e>=192&&e<=207&&e!==196&&e!==200&&e!==204)return[n.getUint16(r+7),n.getUint16(r+5)];r+=2+n.getUint16(r+2)}}return[0,0]},$n=.05,er=1e3,Z=(e,t)=>{let n=10**t,r=Math.round(e*n)/n;return r===0?0:r},tr=(e,t)=>{let n=t.mesh?.size;if(!n)return[];let r=t.mesh?.center??[0,0,0],i=n[0]/2,a=n[1]/2,o=n[2]/2,s=e.worldMatrixF(t.id),c=[];for(let e=0;e<8;e++){let t=r[0]+(e&1?i:-i),n=r[1]+(e&2?a:-a),l=r[2]+(e&4?o:-o);c.push([s[0]*t+s[4]*n+s[8]*l+s[12],s[1]*t+s[5]*n+s[9]*l+s[13],s[2]*t+s[6]*n+s[10]*l+s[14]])}return c},nr=(e,t)=>{let n=[],r=t=>{let i=e.entities.get(t);if(i){n.push(...tr(e,i));for(let e of i.children)r(e)}};return r(t),n};function rr(e,t){let n=t.camera;if(n===void 0||!e.entities.has(n))return;let r=e.width,i=e.height,a=W(new Float32Array(16),en(e.fov,r/i,$n,er),G(e.worldMatrixF(n))),o=(e,t,n)=>{let o=a[3]*e+a[7]*t+a[11]*n+a[15],s=a[0]*e+a[4]*t+a[8]*n+a[12],c=a[1]*e+a[5]*t+a[9]*n+a[13],l=o>1e-4;return l?{sx:(s/o*.5+.5)*r,sy:(1-(c/o*.5+.5))*i,cw:o,inFront:l}:{sx:0,sy:0,cw:o,inFront:l}},s=t=>{for(let n=t;n!==0;n=e.ent(n).parent)if(!e.ent(n).visible)return!1;return!0},c=[t,...t.overlays.map(t=>e.scenes.get(t)).filter(e=>!!e)],l=new Set,u=[],d=t=>{if(!(l.has(t)||!e.entities.has(t))){l.add(t),u.push(t);for(let n of e.ent(t).children)d(n)}};for(let e of c)for(let t of e.entities)d(t);let f=[];for(let t of u){let n=e.ent(t);if(!s(t))continue;let a=n.model?`model`:n.mesh&&!n.light?`mesh`:n.particles?`particles`:null;if(!a)continue;let c;if(a===`model`)c=nr(e,t);else if(a===`mesh`)c=tr(e,n);else{let n=e.worldMatrixF(t);c=[[n[12],n[13],n[14]]]}if(c.length===0)continue;let l=1/0,u=1/0,d=1/0,p=-1/0,m=-1/0,h=-1/0;for(let e of c)e[0]<l&&(l=e[0]),e[0]>p&&(p=e[0]),e[1]<u&&(u=e[1]),e[1]>m&&(m=e[1]),e[2]<d&&(d=e[2]),e[2]>h&&(h=e[2]);let g=o((l+p)/2,(u+m)/2,(d+h)/2),_=!1,v=!1,y=1/0,b=1/0,x=-1/0,S=-1/0;for(let e of c){let t=o(e[0],e[1],e[2]);if(!t.inFront){_=!0;continue}v=!0,t.sx<y&&(y=t.sx),t.sx>x&&(x=t.sx),t.sy<b&&(b=t.sy),t.sy>S&&(S=t.sy)}let C={kind:a,depth:Z(g.cw,3),coverage:0};if(n.name&&(C.name=n.name),!v){C.behindCamera=!0,f.push({obj:C,id:t});continue}let w=y,T=b,E=Math.max(0,x-y),D=Math.max(0,S-b);C.rect=[Z(w,1),Z(T,1),Z(E,1),Z(D,1)],g.inFront&&(C.center=[Z(g.sx,1),Z(g.sy,1)]);let O=Math.max(0,w),k=Math.max(0,T),A=Math.min(r,w+E),j=Math.min(i,T+D),M=Math.max(0,A-O)*Math.max(0,j-k);C.coverage=Z(M/(r*i),4);let N=w>=0&&T>=0&&w+E<=r&&T+D<=i;M===0?C.offscreen=!0:(_||!N)&&(C.clipped=!0),f.push({obj:C,id:t})}let p=new Map;for(let{obj:e}of f)e.name&&p.set(e.name,(p.get(e.name)??0)+1);let m=t=>{let n=[];for(let r=t;r!==0;r=e.ent(r).parent){let t=e.ent(r).name;t&&n.unshift(t)}return n.join(`/`)};for(let{obj:e,id:t}of f)e.name&&(p.get(e.name)??0)>1&&(e.path=m(t));return f.sort((e,t)=>t.obj.coverage-e.obj.coverage||e.obj.depth-t.obj.depth),{viewport:{width:r,height:i},note:`screen px, top-left origin; depth is a camera-distance hint, not true occlusion; rects are rest-pose (headless doesn't sample animation)`,objects:f.map(e=>e.obj)}}var Q=(e,t=4)=>{let n=10**t,r=Math.round(e*n)/n;return r===0?0:r},ir=(e,t=4)=>Array.from(e,e=>Q(e,t)),ar=(e,t)=>`#`+(e>>>0).toString(16).padStart(t?8:6,`0`);function or(e,t){let{entities:n,scenes:r,materials:i,textures:a,worldMatrixF:o}=e,s=e=>{switch(e.kind){case`rgb`:return ar(e.v,!1);case`rgba`:return ar(e.v,!0);case`texture`:return a.get(e.v)?.source??`texture#${e.v}`;case`null`:return null;default:return e.v}},c=e=>{let t=i.get(e);if(!t)return;let n={shader:t.shader.replace(/\.filamat$/,``)};for(let[e,r]of Object.entries(t.uniforms))n[e]=s(r);return n},l=t=>{let n=e.ent(t),r=n.m,i=ir([r[12],r[13],r[14]]),a=Qt(r).map(e=>Q(e,2)),o=Jt(r).map(e=>Q(e,4)),s=n.light?`light`:n.model?`model`:n.mesh?`mesh`:n.particles?`particles`:n.anchor?`anchor`:`node`,u={};if(n.name&&(u.name=n.name),u.kind=s,i.some(e=>e!==0)&&(u.position=i),a.some(e=>e!==0)&&(u.rotation=a),o.some(e=>e!==1)&&(u.scale=o),n.visible||(u.visible=!1),n.mesh){let e={type:n.mesh.kind===1?`edges`:n.mesh.kind===2?`vertices`:`triangles`};n.mesh.size&&(e.size=ir(n.mesh.size)),n.mesh.center?.some(e=>Q(e)!==0)&&(e.center=ir(n.mesh.center)),u.mesh=e;let t=c(n.materials[0]);t&&(u.material=t)}if(n.model){let e=n.model.playing;u.model={...n.model.source&&{source:n.model.source},...!n.model.loaded&&{loaded:!1},animations:n.model.animations.map(e=>({name:e.name,duration:Q(e.duration,2)})),...e&&{playing:{clip:e.clip,time:Q(e.time,4),speed:e.speed}}}}return n.light&&(u.light={type:`sun`,direction:ir(n.light.direction),intensity:n.light.intensity,color:ar(n.light.color,!1),shadows:n.light.shadowsQuality}),n.particles&&(u.particles=n.particles),n.physics&&(u.physics=n.physics),n.collider&&(u.collider=n.collider),n.castShadows!==void 0&&(u.castShadows=n.castShadows),n.receiveShadows!==void 0&&(u.receiveShadows=n.receiveShadows),n.anchor&&(u.anchor=n.anchor),n.children.length>0&&(u.children=n.children.map(l)),u},u=i=>{let a=t=>{for(let n=e.ent(t).parent;n!==0;n=e.ent(n).parent)if(i.entities.has(n))return!0;return!1},s=[...i.entities].filter(e=>n.has(e)&&!a(e)),c={};if(i.arMode&&(c.ar={mode:i.arMode}),i.skybox!==void 0&&(c.skybox=ar(i.skybox,!1)),i.ibl!==void 0&&(c.environment={intensity:i.ibl}),i.bloom&&(c.bloom=i.bloom),i.camera!==void 0&&n.has(i.camera)){let t=o(i.camera),n=Qt(t).map(e=>Q(e,2));c.camera={position:ir([t[12],t[13],t[14]]),...n.some(e=>e!==0)&&{rotation:n},fov:e.fov}}return t&&(c.physics=t),c.nodes=s.map(l),i.overlays.length>0&&(c.overlays=i.overlays.map(e=>r.get(e)).filter(Boolean).map(e=>u(e))),c},d=r.get(e.activeSceneId())??[...r.values()].find(e=>e.overlayOf===void 0);if(!d)return null;let f=u(d),p=rr(e,d);return p&&(f.frame=p),f}var sr=`/assets/neutral_ibl128-D-lzdkLN.ktx`,cr={backend:`opengl`,subBackend:`webgl-lite`},$=60,lr=.01,ur=100,dr={baseColorFactor:`uBaseColorFactor`,metallicFactor:`uMetallic`,roughnessFactor:`uRoughness`,emissiveFactor:`uEmissive`,baseColorMap:`uBaseColorMap`,baseColorIndex:`uBaseColorIndex`},fr=async(c,l={})=>{let u=new de({canvas:c,dpr:1,alpha:!1,antialias:!0,premultipliedAlpha:!0,powerPreference:`high-performance`,preserveDrawingBuffer:l.preloads?.has(`capture`)??!1}),d=u.gl;u.autoClear=!1;let f=jn(d),p=Mn(d);for(let e of l.preloads??[])e.endsWith(`.filamat`)&&t(e,new ArrayBuffer(0));let m={sunDirection:{value:[0,-1,0]},sunColorIntensity:{value:[1,1,1,0]},iblLuminance:{value:0},iblSH:{value:Array(27).fill(0)},envMap:{value:p},envMapMaxLod:{value:0},shadowMap:{value:f},shadowEnabled:{value:0},shadowMapSize:{value:1024},shadowMatrix:{value:U()},exposure:{value:on}},h={value:[0,0,0,0]},g=null;fetch(sr).then(e=>e.arrayBuffer()).then(e=>{g=An(d,e),m.envMap.value=g.cubemap,m.envMapMaxLod.value=g.maxLod,m.iblSH.value=Array.from(g.sh)}).catch(e=>console.warn(`[viewer-lite] IBL load failed:`,e));let _=new Map,v=new Map,y=new Map,b=new Map,x=new Map,S=1,C=!0,w=!0,T=qn(),E=[],D=e=>{let t=_.get(e);if(!t){let n=new V;n.matrixAutoUpdate=!1,n._entId=e,t={transform:n,drawables:[]},_.set(e,t)}return t},O=e=>{let t;return e===`lit`?t=new I(d,{vertex:gn,fragment:dn,uniforms:{...m,baseColor:{value:[0,0,0]},baseColorMap:{value:f},useBaseColorMap:{value:0},roughness:{value:0},metallic:{value:0}}}):e===`video`?t=new I(d,{vertex:gn,fragment:pn,uniforms:{baseColorMap:{value:f},shadowMatrix:m.shadowMatrix}}):e===`shadow`?(t=new I(d,{vertex:gn,fragment:mn,uniforms:{...m,color:{value:[0,0,0,.66]}},transparent:!0}),t.setBlendFunc(d.ONE,d.ONE_MINUS_SRC_ALPHA)):(t=new I(d,{vertex:gn,fragment:fn,uniforms:{baseColor:{value:[0,0,0,1]},baseColorMap:{value:f},useBaseColorMap:{value:0},shadowMatrix:m.shadowMatrix},transparent:!0}),t.setBlendFunc(d.ONE,d.ONE_MINUS_SRC_ALPHA)),{kind:e,program:t}},k=t=>{let n=In(e(t));if(!n)return null;if(n.unsupported)return console.warn(`[viewer-lite] custom material not supported in lite (${n.unsupported}) — rendering unlit`),null;n.hasVertexBlock&&console.warn(`[viewer-lite] custom material has a vertex{} block — the custom vertex stage is ignored in lite`);let r=Hn(n);if(!r)return null;let i=r.needsSceneUniforms?{...m,userTime:h}:{shadowMatrix:m.shadowMatrix,userTime:h};for(let e of r.uniforms)i[e.key]={value:e.value===`texture`?f:e.value};let a=n.blending===`opaque`||n.blending===`masked`,o=new I(d,{vertex:gn,fragment:r.fragment,uniforms:i,transparent:!a,cullFace:n.doubleSided||n.culling===`none`?!1:n.culling===`front`?d.FRONT:d.BACK,depthWrite:n.depthWrite});return d.getProgramParameter(o.program,d.LINK_STATUS)?(a||o.setBlendFunc(d.ONE,n.blending===`add`?d.ONE:d.ONE_MINUS_SRC_ALPHA),{kind:`custom`,program:o,customParams:r.paramNames}):(console.warn(`[viewer-lite] custom material failed to compile — rendering unlit`),null)},A=(e,t)=>{let n=e.startsWith(`lit`)?`lit`:e.startsWith(`unlit`)?`unlit`:e.startsWith(`video`)?`video`:e.startsWith(`shadow`)?`shadow`:`unknown`;if(n===`unknown`&&t!==void 0){let n=k(t);if(n)return n;console.warn(`[viewer-lite] custom shader can't run here (material "${e||t}") — rendering unlit`)}return O(n)},j=(e,t)=>{let n=e.kind===`gltf`?dr[t]??t:e.customParams?.has(t)?`materialParams_${t}`:t,r=e.program.uniforms;return r[n]||(r[n]={value:0}),r[n]},M=(e,t,n)=>{let r=b.get(e);if(!r)return;let i=j(r,t);switch(n.kind){case`rgb`:{let[e,t,r]=Sn(n.v);Array.isArray(i.value)&&i.value.length===4?i.value=[e,t,r,i.value[3]]:i.value=[e,t,r];break}case`rgba`:i.value=Cn(n.v);break;case`float`:i.value=n.v;break;case`bool`:i.value=+!!n.v;break;case`array`:i.value=Float32Array.from(n.v);break;case`texture`:{let e=x.get(n.v);e&&(i.value=e);break}case`null`:i.value instanceof H&&(i.value=f);break}},N=(e,t)=>{t.kind!==`lit`&&t.kind!==`gltf`&&t.kind!==`shadow`&&t.kind!==`custom`||e.onBeforeRender(()=>{let t=e.program.uniforms;t.shadowEnabled&&=m.shadowEnabled.value===1&&e._receiveShadows!==!1?m.shadowEnabled:{value:0}})},P=(e,t,n,r)=>{let i=b.get(t);if(!i)return;let{vertices:a,normals:o,indices:s,uv:c}=n,l=new te(d,{position:{size:3,data:Float32Array.from(a)},normal:{size:3,data:o.length?Float32Array.from(o):new Float32Array(a.length)},uv:{size:2,data:c.length?Float32Array.from(c):new Float32Array(a.length/3*2)},index:{data:Uint16Array.from(s)}});l.computeBoundingBox();let u=r===1?d.LINES:r===2?d.POINTS:d.TRIANGLES,f=new xt(d,{geometry:l,program:i.program,mode:u});f.matrixAutoUpdate=!1,f._entId=e,f._castShadows=C,f._receiveShadows=w,N(f,i);let p=D(e);for(let e of p.drawables)p.transform.removeChild(e);p.drawables=[f],p.transform.addChild(f)},ee=async(t,n,r)=>{let i=await Fn(d,e(t),m,f);D(n).glbClips=i.animations,i.nodes.forEach((e,t)=>{let n=r[t];if(n===void 0)return;let i=D(n);i.transform.setParent(null),z.rebindMatrix(n,e.matrix),e.matrixAutoUpdate=!1,e._entId=n,i.transform=e,i.drawables=[];for(let t of e.children)t.draw&&(t.matrixAutoUpdate=!1,t._entId=n,t._castShadows=C,t._receiveShadows=w,i.drawables.push(t))});for(let e of i.roots)e.setParent(D(n).transform)},F=(e,t)=>{let n=D(e),r=D(t);r.glbClips=n.glbClips;for(let e of n.drawables){let n=e instanceof Vt?new Vt(d,{skeleton:e.skeleton,geometry:e.geometry,program:e.program,mode:e.mode}):new xt(d,{geometry:e.geometry,program:e.program,mode:e.mode});n._entId=t,n._castShadows=e._castShadows,n._receiveShadows=e._receiveShadows,n.frustumCulled=e.frustumCulled,n.matrixAutoUpdate=!1,r.drawables.push(n),r.transform.addChild(n)}},ne=(e,t)=>{e.animation.elapsed=t,e.animation.update(1,!0);for(let t of e.nodes)t.updateMatrix()},re=()=>{for(let e of E)e.video.videoWidth===0||e.video.currentTime===e.lastTime||(e.texture.image=e.video,e.texture.needsUpdate=!0,e.lastTime=e.video.currentTime)},L=new st(d,{fov:$,near:lr,far:ur,aspect:1});L.matrixAutoUpdate=!1;let R=!1,ie=0,ae=0,oe=null,se=0,ce=new I(d,{vertex:vn(!1),fragment:yn,uniforms:{modelMatrix:{value:U()},shadowViewProjection:{value:U()}},cullFace:d.FRONT}),le=new I(d,{vertex:vn(!0),fragment:yn,uniforms:{modelMatrix:{value:U()},shadowViewProjection:{value:U()},boneTexture:{value:f},boneTextureSize:{value:4}},cullFace:d.FRONT}),ue=e=>{for(let[t,n]of z.entities)if(n.light&&z.methods.isVisible(t)&&z.sceneOf(t)?.id===e)return n.light;return null},fe=e=>{let t=[];return e.traverse(e=>e.visible?(e.draw&&t.push(e),!1):!0),t},pe=(e,t)=>{let n=t.shadowsQuality>=3?4096:t.shadowsQuality>=2?2048:1024;(!oe||se!==n)&&(oe=new Tt(d,{width:n,height:n,depthTexture:!0}),se=n);let r=fe(e).filter(e=>e._castShadows!==!1);if(r.length===0){m.shadowEnabled.value=0;return}let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0,f=[0,0,0];for(let e of r){let t=e.geometry;if(t.bounds||t.computeBoundingBox(),!t.bounds||!isFinite(t.bounds.min.x))continue;let n=e.worldMatrix;for(let e=0;e<8;e++)an(f,n,e&1?t.bounds.max.x:t.bounds.min.x,e&2?t.bounds.max.y:t.bounds.min.y,e&4?t.bounds.max.z:t.bounds.min.z,1),f[0]<i&&(i=f[0]),f[0]>s&&(s=f[0]),f[1]<a&&(a=f[1]),f[1]>c&&(c=f[1]),f[2]<o&&(o=f[2]),f[2]>l&&(l=f[2])}if(!isFinite(i)){m.shadowEnabled.value=0;return}let p=(i+s)/2,h=(a+c)/2,g=(o+l)/2,_=Math.max(.5,Math.hypot(s-i,c-a,l-o)/2),v=t.direction[0],y=t.direction[1],b=t.direction[2],x=Math.hypot(v,y,b)||1;v/=x,y/=x,b/=x;let S=[p-v*_*2,h-y*_*2,g-b*_*2],C=-v,w=-y,T=-b,E=Math.abs(y)>.99?[1,0,0]:[0,1,0],D=E[1]*T-E[2]*w,O=E[2]*C-E[0]*T,k=E[0]*w-E[1]*C,A=Math.hypot(D,O,k)||1;D/=A,O/=A,k/=A;let j=w*k-T*O,M=T*D-C*k,N=C*O-w*D,P=new Float32Array(16);P[0]=D,P[4]=O,P[8]=k,P[1]=j,P[5]=M,P[9]=N,P[2]=C,P[6]=w,P[10]=T,P[12]=-(D*S[0]+O*S[1]+k*S[2]),P[13]=-(j*S[0]+M*S[1]+N*S[2]),P[14]=-(C*S[0]+w*S[1]+T*S[2]),P[15]=1;let ee=tn(-_,_,-_,_,.05,_*4),F=W(new Float32Array(16),ee,P);ce.uniforms.shadowViewProjection.value=F,le.uniforms.shadowViewProjection.value=F,m.shadowMatrix.value=F,m.shadowMap.value=oe.depthTexture,m.shadowMapSize.value=n,m.shadowEnabled.value=1,u.bindFramebuffer(oe),u.setViewport(n,n),d.clearColor(1,1,1,1),u.enable(d.DEPTH_TEST),u.setDepthMask(!0),d.clear(d.COLOR_BUFFER_BIT|d.DEPTH_BUFFER_BIT);let te=U();for(let e of r){let t=e instanceof Vt,n=t?le:ce,r=e.program;n.uniforms.modelMatrix.value=t?te:e.worldMatrix,e.program=n,e.draw({}),e.program=r}u.bindFramebuffer({buffer:null})},me=e=>{let t=ie===0?0:(e-ie)/1e3;t>.05&&(t=.05),ie=e;let n=e/1e3;h.value[0]=n,h.value[1]=n-Math.floor(n),z.tick(t)},he=e=>{let t=c.width/Math.max(1,c.height);t!==ae&&(ae=t,L.perspective({fov:$,aspect:t,near:lr,far:ur}));let n=z.scenes.get(e)?.camera,r=n===void 0?U():z.worldMatrix(n);for(let e=0;e<16;e++)L.matrix[e]=r[e];L.worldMatrixNeedsUpdate=!0},ge=e=>{let t=z.activeSceneId(),n=z.scenes.get(t),r=v.get(t);if(!n||!r)return;me(e),re(),he(t),r.updateMatrixWorld();let i=ue(t);if(i){let e=(i.color>>>16&255)/255,t=(i.color>>>8&255)/255,n=(i.color&255)/255;m.sunDirection.value=i.direction,m.sunColorIntensity.value=[e,t,n,i.intensity],i.shadowsQuality>0?pe(r,i):m.shadowEnabled.value=0}else m.sunColorIntensity.value=[1,1,1,0],m.shadowEnabled.value=0;m.iblLuminance.value=n.ibl??0;let a=n.skybox===void 0?[xn(.1),xn(.25),xn(.57)]:[xn((n.skybox>>>16&255)/255),xn((n.skybox>>>8&255)/255),xn((n.skybox&255)/255)];u.bindFramebuffer({buffer:null}),u.setViewport(c.width,c.height),d.clearColor(a[0],a[1],a[2],1),u.enable(d.DEPTH_TEST),u.setDepthMask(!0),d.clear(d.COLOR_BUFFER_BIT|d.DEPTH_BUFFER_BIT),u.render({scene:r,camera:L,clear:!1,sort:!0,frustumCull:!0});for(let e of n.overlays){let t=v.get(e);t&&(d.clear(d.DEPTH_BUFFER_BIT),u.render({scene:t,camera:L,clear:!1,sort:!0,frustumCull:!0}))}},_e=new Set,ve=()=>{if(R){try{ge(performance.now())}catch(e){let t=e instanceof Error?e.message:String(e);_e.has(t)||(_e.add(t),console.error(`[viewer-lite] render frame failed:`,e))}requestAnimationFrame(ve)}},ye=e=>z.sceneOf(e)?.id,be=[0,0,0],xe=(e,t,n)=>{let r=z.scenes.get(e)?.camera,i=r===void 0?U():z.worldMatrix(r),a=Math.max(1,c.width),o=Math.max(1,c.height),s=a/o,l=Math.tan($*Math.PI/360),u=(t/a*2-1)*l*s,d=(1-n/o*2)*l,f=i[0]*u+i[4]*d-i[8],p=i[1]*u+i[5]*d-i[9],m=i[2]*u+i[6]*d-i[10],h=Math.hypot(f,p,m)||1;return be=[i[12],i[13],i[14]],{origin:be,dir:[f/h,p/h,m/h]}},Se=(e,t,n)=>{let r=y.get(e);if(!r)return 0;let i=1/0,a=0,o=[0,0,0],s=[0,0,0];for(let[e,c]of r){if(!z.entities.has(e)||!z.methods.isVisible(e))continue;let r=G(z.worldMatrixF(e));an(o,r,t[0],t[1],t[2],1),an(s,r,n[0],n[1],n[2],0);let l=c.type===`box`?nn(c.center,c.extent,o,s):rn(c.center,c.radius,o,s);l>0&&l<i&&(i=l,a=e)}return a},Ce=(e,t,n)=>{let r=v.get(e);if(!r)return 0;let i=1/0,a=0,o=[0,0,0],s=[0,0,0];r.updateMatrixWorld();for(let e of fe(r)){let r=e.geometry;if(r.bounds||r.computeBoundingBox(),!r.bounds||!isFinite(r.bounds.min.x))continue;let c=G(e.worldMatrix);an(o,c,t[0],t[1],t[2],1),an(s,c,n[0],n[1],n[2],0);let l=nn([(r.bounds.min.x+r.bounds.max.x)/2,(r.bounds.min.y+r.bounds.max.y)/2,(r.bounds.min.z+r.bounds.max.z)/2],[(r.bounds.max.x-r.bounds.min.x)/2,(r.bounds.max.y-r.bounds.min.y)/2,(r.bounds.max.z-r.bounds.min.z)/2],o,s);l>0&&l<i&&(i=l,a=e._entId??0)}return a},we=(e,t)=>{let n=z.activeSceneId(),r=z.scenes.get(n);if(!r||r.camera===void 0)return 0;let{origin:i,dir:a}=xe(n,e,t);for(let e=r.overlays.length-1;e>=0;e--){let t=Se(r.overlays[e],i,a);if(t!==0)return t}return Se(n,i,a)},z=Zn({allocMatrix:e=>D(e).transform.matrix,localMatrixChanged:e=>{D(e).transform.worldMatrixNeedsUpdate=!0},parentChanged:(e,t)=>{let n=D(e).transform;if(t!==0)n.setParent(D(t).transform);else{let t=z.sceneOf(e);n.setParent((t&&v.get(t.id))??null)}},sceneCreated:e=>{v.set(e,new V),y.set(e,new Map)},entitySceneChanged:(e,t,n)=>{let r=v.get(t);if(!r)return;let i=D(e);if(n){for(let[n,r]of y){if(n===t)continue;let i=r.get(e);i&&(y.get(t).set(e,i),r.delete(e))}z.ent(e).parent===0&&i.transform.setParent(r)}else z.ent(e).parent===0&&i.transform.parent===r&&i.transform.setParent(null)},visibleChanged:(e,t)=>{D(e).transform.visible=t},materialCreated:(e,t,n)=>{b.set(e,A(t.shader,n))},uniformChanged:(e,t,n)=>M(e,t,n),meshSet:(e,t,n,r)=>P(e,t,r,n.kind),glbAttach:(e,t,n)=>ee(e,t,n),animationApply:(e,t,n)=>{let r=D(e).glbClips?.[t];r&&ne(r,n)},entityDestroyed:e=>{let t=_.get(e);t&&(t.transform.setParent(null),_.delete(e));for(let t of y.values())t.delete(e)},entityCloned:(e,t)=>F(e,t)},{getBuffer:e,getSourceName:n,width:c.width||1,height:c.height||1,fov:$}),Te={...cr,...z.methods,openScene(e){let t=R;z.methods.openScene(e),R=z.scenes.has(e),c.style.display=`block`,!t&&R&&requestAnimationFrame(ve)},closeScene(){c.style.display=`none`,R=!1,z.methods.closeScene()},requestCamera(e){e()},launchAR(){throw Error(`launchAR is not implemented`)},stopAR(){throw Error(`stopAR is not implemented`)},launchVR(e,t,n){n(Error(`VR is not supported on this device`))},stopVR(){},async warmRender(e,t){t()},getSceneMaterial(e){throw Error(`getSceneMaterial is not implemented`)},attachCameraToAR(e,t,n){let r=z.scenes.get(e);if(r){r.camera=t;for(let e of r.overlays){let n=z.scenes.get(e);n&&(n.camera=t)}}},getCameraFov(e,t){if(t!==1)return $;let n=$*Math.PI/180,r=c.width/Math.max(1,c.height);return 2*Math.atan(Math.tan(n/2)*r)*180/Math.PI},getCameraViewDirection(e,t,n,r){if(!z.scenes.has(e)){r[0]=0,r[1]=0,r[2]=-1;return}let{dir:i}=xe(e,t,n);r[0]=i[0],r[1]=i[1],r[2]=i[2]},getDisplaySize:()=>Float32Array.of(c.width,c.height),createTexture(e,t,n){let r=i(e);createImageBitmap(r).then(e=>{let n=new H(d,{image:e,internalFormat:d.SRGB8_ALPHA8,format:d.RGBA,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),r=S++;x.set(r,n),t(r,e.width,e.height)}).catch(n)},createTextureFromCanvas(e){let t=l.canvasHost?.readSurface(e);if(!t)return 0;let n=new H(d,{image:new Uint8Array(t.data.buffer.slice(0)),width:t.width,height:t.height,internalFormat:d.SRGB8_ALPHA8,format:d.RGBA,generateMipmaps:!1,flipY:!1}),r=S++;return x.set(r,n),r},updateTextureFromCanvas(e,t){let n=l.canvasHost?.readSurface(t),r=x.get(e);!n||!r||(r.image=new Uint8Array(n.data.buffer.slice(0)),r.width=n.width,r.height=n.height,r.needsUpdate=!0)},createMediaPlayerTexture(e){let t=o(e),n=new H(d,{generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1});E.push({video:t,texture:n,lastTime:-1});let r=S++;return x.set(r,n),r},setUniformColor(e,t,n){z.methods.setUniformRgb(e,t,n)},setUniformTexture(e,t,n,r,i){z.methods.setUniformTexture(e,t,n);let a=b.get(e),o=x.get(n);if(!a||!o)return;let s=[d.CLAMP_TO_EDGE,d.REPEAT,d.MIRRORED_REPEAT];o.wrapS=s[r]??d.REPEAT,o.wrapT=s[i]??d.REPEAT,o.needsUpdate=!0,j(a,t).value=o},setMaterial(e,t,n){z.methods.setMaterial(e,t,n);let r=b.get(t),i=D(e).drawables[n];!r||!i||(i.program=r.program,N(i,r))},getMaterial(e,t){let n=D(e).drawables[t];if(!n)return 0;let r=z.nextMaterialId();return b.set(r,{kind:`gltf`,program:n.program}),r},setCulling(e,t){for(let n of D(e).drawables)n.frustumCulled=t},setGlbCulling(e,t){let n=e=>{for(let n of D(e).drawables)n.frustumCulled=t;for(let t of z.ent(e).children)n(t)};n(e)},setCastShadows(e,t){z.methods.setCastShadows(e,t);for(let n of D(e).drawables)n._castShadows=t},setReceiveShadows(e,t){z.methods.setReceiveShadows(e,t);for(let n of D(e).drawables)n._receiveShadows=t},setCastShadowsGlobal(e){C=e},setReceiveShadowsGlobal(e){w=e},setColliderFromMesh(e,t,n){if(n!==0)return;let r=D(t).drawables[0];if(!r)return;let i=r.geometry;if(i.bounds||i.computeBoundingBox(),!i.bounds)return;let a=ye(e)??z.activeSceneId();y.get(a)?.set(e,{type:`box`,center:[(i.bounds.min.x+i.bounds.max.x)/2,(i.bounds.min.y+i.bounds.max.y)/2,(i.bounds.min.z+i.bounds.max.z)/2],extent:[(i.bounds.max.x-i.bounds.min.x)/2,(i.bounds.max.y-i.bounds.min.y)/2,(i.bounds.max.z-i.bounds.min.z)/2]})},setColliderBox(e,t,n,r,i,a,o){let s=ye(e)??z.activeSceneId();y.get(s)?.set(e,{type:`box`,center:[t,n,r],extent:[i/2,a/2,o/2]})},setColliderSphere(e,t,n,r,i){let a=ye(e)??z.activeSceneId();y.get(a)?.set(e,{type:`sphere`,center:[t,n,r],radius:i})},physicsHasSupport:()=>!1,physicsConfigure(){},setInterpolation(){},physicsBuildBox:()=>0,physicsBuildSphere:()=>0,physicsBuildCylinder:()=>0,physicsBuildCapsule:()=>0,physicsDestroyShape(){},physicsCreateBody:()=>0,physicsSetPickable(){},physicsRaycast:()=>0,characterCreate:()=>0,characterDestroy(){},characterSetVelocity(){},characterGetVelocity(e,t){t[0]=0,t[1]=0,t[2]=0},characterGetGroundState:()=>0,characterSetPosition(){},physicsCreateBox:()=>0,physicsCreateSphere:()=>0,physicsCreateCylinder:()=>0,physicsSetLinearVelocity(){},physicsGetLinearVelocity(e,t){t[0]=0,t[1]=0,t[2]=0},physicsApplyImpulse(){},physicsSetBodyPosition(){},physicsRemoveBody(){},createARController(){throw Error(`createARController is not implemented`)},createRootAnchor(){throw Error(`createRootAnchor is not implemented`)},createAnchor(){throw Error(`createAnchor is not implemented`)},createARPlane:()=>0,updateProjectionMatrixAR(){},_setARController(){},createParticleSystem(){De()},spawnParticles(){},setParticleSystemShapePoint(){},setParticleSystemShapeBox(){},setParticleSystemShapeCircle(){},setParticleSystemVelocityValue(){},setParticleSystemVelocitySpeedValue(){},setParticleSystemVelocitySpeedRange(){},setParticleSystemVelocityRndAngle(){},setParticleSystemNoise(){},disableParticleSystemNoise(){},setParticleSystemRateValue(){},setParticleSystemGravityValue(){},setParticleSystemDragValue(){},setParticleSystemParamValue(){},setParticleSystemParamRange(){},setParticleSystemParamCurveA(){},setParticleSystemParamCurveB(){},setParticleSystemLifetimeValue(){},setParticleSystemLifetimeRange(){},setParticleSystemColorValue(){},setParticleSystemColorRange(){},setParticleSystemColorCurveA(){},setParticleSystemColorCurveB(){},...T,async captureImage(e,t,n){try{ge(performance.now());let e=new OffscreenCanvas(c.width,c.height);e.getContext(`2d`).drawImage(c,0,0);let n=await e.convertToBlob({type:`image/png`});t(a(await n.arrayBuffer()),`image.png`,n.size)}catch{n()}},raycastView:we,_raycastView:we,raycastPick(e,t){let n=z.activeSceneId(),r=z.scenes.get(n);if(!r||r.camera===void 0)return 0;let i=we(e,t);if(i!==0)return i;let{origin:a,dir:o}=xe(n,e,t);return Ce(n,a,o)},computeBoundingBox(e){let t=Float32Array.of(1/0,1/0,1/0,-1/0,-1/0,-1/0),n=[0,0,0],r=(e,i)=>{for(let r of D(e).drawables){let e=r.geometry;if(e.bounds||e.computeBoundingBox(),!(!e.bounds||!isFinite(e.bounds.min.x)))for(let r=0;r<8;r++){let a=r&1?e.bounds.max.x:e.bounds.min.x,o=r&2?e.bounds.max.y:e.bounds.min.y,s=r&4?e.bounds.max.z:e.bounds.min.z;i?an(n,i,a,o,s,1):(n[0]=a,n[1]=o,n[2]=s);for(let e=0;e<3;e++)n[e]<t[e]&&(t[e]=n[e]),n[e]>t[e+3]&&(t[e+3]=n[e])}}for(let t of z.ent(e).children){let e=D(t).transform.matrix;r(t,i?W(new Float32Array(16),i,e):Float32Array.from(e))}};return r(e,null),isFinite(t[0])||t.fill(0),t},stopAllPlayers(){s()},_dumpScene3d:()=>or(z),async createEngine(){},_fetch:r,_getPlayer:o,_createGLTexture(e){let t=new H(d,{image:e,generateMipmaps:!1,flipY:!1,premultiplyAlpha:!1}),n=S++;return x.set(n,t),t.update(),{gl:d,glTexture:t.texture,textureId:n}},_onResize(e,t){u.setSize(e,t),ae=0},_dispose(){this.closeScene(),this.stopAllPlayers(),d.getExtension(`WEBGL_lose_context`)?.loseContext()}},Ee=!1,De=()=>{Ee||(Ee=!0,console.warn(`[viewer-lite] particle systems are not implemented in the lite engine yet`))};return Te};export{fr as createViewerLite};
|