three-live 1.3.2 → 1.4.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 +4 -1
- package/dist/index.d.ts +190 -0
- package/dist/three-author-engine.js +171 -163
- package/dist/three-author.cjs +145 -163
- package/dist/three-author.d.ts +190 -0
- package/dist/three-author.js +145 -163
- package/dist/three-convert.cjs +142 -160
- package/dist/three-convert.d.ts +190 -0
- package/dist/three-convert.js +142 -160
- package/dist/three-live-ai.cjs +41 -0
- package/dist/three-live-ai.d.ts +759 -0
- package/dist/three-live-ai.js +41 -0
- package/dist/three-live-ai.min.js +41 -0
- package/dist/three-live-animation.cjs +6 -6
- package/dist/three-live-animation.d.ts +190 -0
- package/dist/three-live-animation.js +5 -5
- package/dist/three-live-animation.min.js +5 -5
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +190 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +50 -85
- package/dist/three-live-element.d.ts +190 -0
- package/dist/three-live-element.js +50 -85
- package/dist/three-live-full.cjs +907 -189
- package/dist/three-live-full.js +907 -189
- package/dist/three-live-full.min.js +907 -189
- package/dist/three-live-procedural.cjs +16 -0
- package/dist/three-live-procedural.d.ts +759 -0
- package/dist/three-live-procedural.js +16 -0
- package/dist/three-live-procedural.min.js +16 -0
- package/dist/three-live-sandbox.html +11 -1
- package/dist/three-live-studio.cjs +72 -17
- package/dist/three-live-studio.d.ts +190 -0
- package/dist/three-live-studio.js +72 -17
- package/dist/three-live-studio.min.js +73 -18
- package/dist/three-live-tsl.cjs +103 -0
- package/dist/three-live-tsl.d.ts +759 -0
- package/dist/three-live-tsl.js +103 -0
- package/dist/three-live-tsl.min.js +103 -0
- package/dist/three-live-viewer.cjs +50 -85
- package/dist/three-live-viewer.d.ts +190 -0
- package/dist/three-live-viewer.js +50 -85
- package/dist/three-live-viewer.min.js +50 -85
- package/dist/three-live-webgpu.cjs +585 -0
- package/dist/three-live-webgpu.d.ts +759 -0
- package/dist/three-live-webgpu.js +585 -0
- package/dist/three-live-webgpu.min.js +585 -0
- package/dist/three-live.cjs +147 -165
- package/dist/three-live.js +147 -165
- package/dist/three-live.min.js +147 -165
- package/dist/three-view.cjs +49 -84
- package/dist/three-view.d.ts +190 -0
- package/dist/three-view.js +50 -85
- package/dist/three-xr.cjs +141 -159
- package/dist/three-xr.d.ts +190 -0
- package/dist/three-xr.js +140 -158
- package/package.json +21 -1
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/var ThreeLiveStudio=(()=>{var
|
|
17
|
-
out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),t.attachShader(l
|
|
18
|
-
precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),t.linkProgram(
|
|
16
|
+
*/var ThreeLiveStudio=(()=>{var tt=Object.defineProperty,Cr=Object.getOwnPropertyDescriptor,Rr=Object.getOwnPropertyNames,Dr=Object.prototype.hasOwnProperty,Fr=(e,t)=>{for(var r in t)tt(e,r,{get:t[r],enumerable:!0})},Ur=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Rr(t))!Dr.call(e,a)&&a!==r&&tt(e,a,{get:()=>t[a],enumerable:!(i=Cr(t,a))||i.enumerable});return e},kr=e=>Ur(tt({},"__esModule",{value:!0}),e),wt={};Fr(wt,{InteractivityVM:()=>Ot,LOD:()=>li,LodController:()=>$t,MAX_SHADOW_LIGHTS:()=>gt,SHADOW_MAP_TEXTURE_UNIT:()=>hr,applyMeshoptFilter:()=>Xt,computeOutlineClipOffset:()=>Li,computeWorldSceneBounds:()=>br,contactShadowPlugin:()=>Pr,decimateGeometry:()=>oi,decodeMeshoptBuffer:()=>ir,decodeMeshoptGLB:()=>mt,doesMeshCastShadow:()=>et,doesMeshReceiveShadow:()=>yr,encodeMeshoptBuffer:()=>wi,environmentMapPlugin:()=>Lt,evaluateKawaseBloom:()=>Pi,extractMaterialVariants:()=>Lr,extractPrimitiveVariantMappings:()=>Xi,fitDirectionalShadowMatrix:()=>vr,fitSpotShadowMatrix:()=>vt,getEnvironmentSH:()=>Gr,getInteractivityVM:()=>ft,getLodController:()=>si,getShadowMapStats:()=>Oi,hotspotPlugin:()=>Tt,installLodExtension:()=>qe,interactivityPlugin:()=>zt,lodPlugin:()=>Ht,materialsPlugin:()=>jt,meshoptDecoder:()=>dt,meshoptPlugin:()=>nr,normalizeShadowMapsMode:()=>gr,parseHexRgb:()=>sr,parseLod:()=>ht,parseSafeGltfPointer:()=>We,postprocessingPlugin:()=>cr,registerMaterialShader:()=>ui,resolveActiveShadowLights:()=>xr,selectLodLevelIndex:()=>ct,selectMaterialVariant:()=>Zi,sendInteractivityEvent:()=>Bt,setEnvironmentSH:()=>It,shadowMapsPlugin:()=>Ir,variantsPlugin:()=>Tr,webxrPlugin:()=>Er});var ze="__THREE_LIVE_REGISTRY__";function de(){let e=typeof globalThis<"u"?globalThis:{};if(!e[ze]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,ze,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[ze]=t}}return e[ze]}var Yi=de().plugins;function Or(e){let t=de();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function se(e){let t=de().plugins;t.some(r=>r.name===e.name)||t.push(e),e.onRegister?.()}function Br(){return de().plugins}function ue(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function zr(e,t,r,i,a){let n=1/Math.tan(t/2);e.fill(0),e[0]=n/r,e[5]=n,e[11]=-1;let f=1/(i-a);return e[10]=(a+i)*f,e[14]=2*a*i*f,e}function $r(e,t,r,i,a,n,f){let c=1/(t-r),s=1/(i-a),d=1/(n-f);return e.fill(0),e[0]=-2*c,e[5]=-2*s,e[10]=2*d,e[12]=(t+r)*c,e[13]=(a+i)*s,e[14]=(f+n)*d,e[15]=1,e}function St(e,t,r,i){let[a,n,f]=t,[c,s,d]=i,[o,l,u]=r,m=a-o,h=n-l,p=f-u,b=Math.hypot(m,h,p);b<=1e-5?(m=0,h=0,p=1):(m/=b,h/=b,p/=b);let y=s*p-d*h,M=d*m-c*p,g=c*h-s*m;b=Math.hypot(y,M,g),b<=1e-5?(y=0,M=0,g=0):(y/=b,M/=b,g/=b);let v=h*g-p*M,x=p*y-m*g,P=m*M-h*y;return b=Math.hypot(v,x,P),b<=1e-5?(v=0,x=0,P=0):(v/=b,x/=b,P/=b),e[0]=y,e[1]=v,e[2]=m,e[3]=0,e[4]=M,e[5]=x,e[6]=h,e[7]=0,e[8]=g,e[9]=P,e[10]=p,e[11]=0,e[12]=-(y*a+M*n+g*f),e[13]=-(v*a+x*n+P*f),e[14]=-(m*a+h*n+p*f),e[15]=1,e}function ne(e,t,r){let i=t[0],a=t[1],n=t[2],f=t[3],c=t[4],s=t[5],d=t[6],o=t[7],l=t[8],u=t[9],m=t[10],h=t[11],p=t[12],b=t[13],y=t[14],M=t[15],g=r[0],v=r[1],x=r[2],P=r[3];return e[0]=g*i+v*c+x*l+P*p,e[1]=g*a+v*s+x*u+P*b,e[2]=g*n+v*d+x*m+P*y,e[3]=g*f+v*o+x*h+P*M,g=r[4],v=r[5],x=r[6],P=r[7],e[4]=g*i+v*c+x*l+P*p,e[5]=g*a+v*s+x*u+P*b,e[6]=g*n+v*d+x*m+P*y,e[7]=g*f+v*o+x*h+P*M,g=r[8],v=r[9],x=r[10],P=r[11],e[8]=g*i+v*c+x*l+P*p,e[9]=g*a+v*s+x*u+P*b,e[10]=g*n+v*d+x*m+P*y,e[11]=g*f+v*o+x*h+P*M,g=r[12],v=r[13],x=r[14],P=r[15],e[12]=g*i+v*c+x*l+P*p,e[13]=g*a+v*s+x*u+P*b,e[14]=g*n+v*d+x*m+P*y,e[15]=g*f+v*o+x*h+P*M,e}function Hr(e,t,r,i){let a=t[0],n=t[1],f=t[2],c=t[3],s=a+a,d=n+n,o=f+f,l=a*s,u=a*d,m=a*o,h=n*d,p=n*o,b=f*o,y=c*s,M=c*d,g=c*o,v=i[0],x=i[1],P=i[2];return e[0]=(1-(h+b))*v,e[1]=(u+g)*v,e[2]=(m-M)*v,e[3]=0,e[4]=(u-g)*x,e[5]=(1-(l+b))*x,e[6]=(p+y)*x,e[7]=0,e[8]=(m+M)*P,e[9]=(p-y)*P,e[10]=(1-(l+h))*P,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function $e(e,t,r=0){let i=t[0],a=t[1],n=t[2],f=t[4],c=t[5],s=t[6],d=t[8],o=t[9],l=t[10],u=l*c-s*o,m=-l*f+s*d,h=o*f-c*d,p=i*u+a*m+n*h;return!p||r>0&&(!Number.isFinite(p)||Math.abs(p)<=r)||(p=1/p,e[0]=u*p,e[1]=m*p,e[2]=h*p,e[3]=(-l*a+n*o)*p,e[4]=(l*i-n*d)*p,e[5]=(-o*i+a*d)*p,e[6]=(s*a-n*c)*p,e[7]=(-s*i+n*f)*p,e[8]=(c*i-a*f)*p),e}function jr(e,t){let r=t[0],i=t[1],a=t[2],n=t[3],f=t[4],c=t[5],s=t[6],d=t[7],o=t[8],l=t[9],u=t[10],m=t[11],h=t[12],p=t[13],b=t[14],y=t[15],M=r*c-i*f,g=r*s-a*f,v=r*d-n*f,x=i*s-a*c,P=i*d-n*c,C=a*d-n*s,F=o*p-l*h,I=o*b-u*h,B=o*y-m*h,U=l*b-u*p,V=l*y-m*p,k=u*y-m*b,O=M*k-g*V+v*U+x*B-P*I+C*F;return O?(O=1/O,e[0]=(c*k-s*V+d*U)*O,e[1]=(a*V-i*k-n*U)*O,e[2]=(p*C-b*P+y*x)*O,e[3]=(u*P-l*C-m*x)*O,e[4]=(s*B-f*k-d*I)*O,e[5]=(r*k-a*B+n*I)*O,e[6]=(b*v-h*C-y*g)*O,e[7]=(o*C-u*v+m*g)*O,e[8]=(f*V-c*B+d*F)*O,e[9]=(i*B-r*V-n*F)*O,e[10]=(h*P-p*v+y*M)*O,e[11]=(l*v-o*P-m*M)*O,e[12]=(c*I-f*U-s*F)*O,e[13]=(r*U-i*I+a*F)*O,e[14]=(p*g-h*x-b*M)*O,e[15]=(o*x-l*g+u*M)*O,e):null}function At(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let o=0;o<r;o++)i.push(ue());if(r===0)return i;let a=new Set;for(let o of e.nodes)if(Array.isArray(o.children))for(let l of o.children)a.add(l);let n=new Set,f=128,c=(o,l,u=0)=>{if(u>f||o<0||o>=r||n.has(o))return;n.add(o);let m=e.nodes[o];if(!m)return;let h=ue();if(t&&t[o])h.set(t[o]);else if(m.matrix&&m.matrix.length===16)h.set(m.matrix);else{let b=m.translation||[0,0,0],y=m.rotation||[0,0,0,1],M=m.scale||[1,1,1];Hr(h,y,b,M)}let p=i[o];if(l?ne(p,l,h):p.set(h),Array.isArray(m.children))for(let b of m.children)typeof b=="number"&&c(b,p,u+1)},s=[],d=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(d&&Array.isArray(d.nodes))s.push(...d.nodes);else for(let o=0;o<r;o++)a.has(o)||s.push(o);for(let o of s)c(o,null);for(let o=0;o<r;o++)!a.has(o)&&!s.includes(o)&&c(o,null);return i}var rt=new WeakMap;function It(e,t){let r=t instanceof Float32Array?t:new Float32Array(t);rt.set(e,r)}function Gr(e){return rt.get(e)}async function Wr(e,t){if(!t)return null;let r;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let a=await(await fetch(t)).blob();r=await createImageBitmap(a)}else if(typeof Image<"u")r=await new Promise((a,n)=>{let f=new Image;f.crossOrigin="anonymous",f.onload=()=>a(f),f.onerror=n,f.src=t});else return null;else r=t;let i=e.createTexture();return e.bindTexture(3553,i),e.texImage2D(3553,0,6408,6408,5121,r),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),i&&(i.__gpuImageSource=r),i}var it=new WeakMap,Nt=new Float32Array(16);async function Pt(e,t,r){let i=r?await Wr(e.gl,r):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=i}var Lt={name:"environment-map",onContextRestored(e){it.delete(e)},setEnvironmentImage(e,t){return Pt(e,"environmentTexture",t)},setSkyboxImage(e,t){return Pt(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,r,i,a){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let n=it.get(t);if(!n){let l=(h,p)=>{let b=t.createShader(h);return t.shaderSource(b,p),t.compileShader(b),b},u=t.createProgram();t.attachShader(u,l(35633,`#version 300 es
|
|
17
|
+
out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),t.attachShader(u,l(35632,`#version 300 es
|
|
18
|
+
precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),t.linkProgram(u);let m=typeof t.createVertexArray=="function"?t.createVertexArray():null;n={program:u,vao:m},it.set(t,n)}let f=jr(Nt,r)||Nt;t.depthMask(!1),t.useProgram(n.program),n.vao&&t.bindVertexArray(n.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let c=t.getUniformLocation(n.program,"uSkyboxMap");c&&t.uniform1i(c,0);let s=t.getUniformLocation(n.program,"uInvVP");s&&t.uniformMatrix4fv(s,!1,f);let d=t.getUniformLocation(n.program,"uCameraPos");d&&t.uniform3f(d,i[0],i[1],i[2]);let o=t.getUniformLocation(n.program,"uExposure");o&&t.uniform1f(o,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,r,i){if(i.includes("evalSHIrradiance"))return null;let a=i.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
|
|
19
19
|
uniform int uHasSH;
|
|
20
20
|
out vec4 fragColor;`).replace("void main(){",`vec3 integrateBRDFApprox(vec3 f0,float r,float NoV){vec4 c0=vec4(-1.,-.0275,-.572,.022),c1=vec4(1.,.0425,1.04,-.04),rv=r*c0+c1;float a=min(rv.x*rv.x,exp2(-9.28*NoV))*rv.x+rv.y;vec2 ab=vec2(-1.04,1.04)*a+rv.zw;return f0*ab.x+vec3(ab.y);}
|
|
21
21
|
vec3 evalSHIrradiance(vec3 n){return max(vec3(0.),uSH[0]+uSH[1]*n.y+uSH[2]*n.z+uSH[3]*n.x+uSH[4]*(n.x*n.y)+uSH[5]*(n.y*n.z)+uSH[6]*(3.*n.z*n.z-1.)+uSH[7]*(n.x*n.z)+uSH[8]*(n.x*n.x-n.y*n.y));}
|
|
22
|
-
void main(){`);return
|
|
22
|
+
void main(){`);return a=a.replace(`if(uHasEnvironmentMap==1){
|
|
23
23
|
specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
|
|
24
24
|
envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
|
|
25
25
|
}`,`if(uHasEnvironmentMap==1){
|
|
@@ -28,15 +28,15 @@ envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangu
|
|
|
28
28
|
}else if(uHasSH==1){
|
|
29
29
|
specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
|
|
30
30
|
envDiffuse=evalSHIrradiance(N);
|
|
31
|
-
}`),{vs:r,fs:n}},onBeforeDrawPrimitive(e,t,r,i,n,s){let m=je.get(e),c=e.getUniformLocation(t,"uHasSH");if(m&&m.length>=27){c&&e.uniform1i(c,1);let o=e.getUniformLocation(t,"uSH");o&&e.uniform3fv(o,m)}else c&&e.uniform1i(c,0)},onAttributeChanged(e,t,r,i){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,i):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,i)}},Ke=new WeakMap;function qe(e,t){let r=t||e.viewer;if(!r||typeof r.projectPointToScreen!="function")return;let i=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let n=0;n<i.length;n++){let s=i[n],m=s.getAttribute("data-position");if(!m)continue;let c=m.trim().split(/\s+/).map(u=>parseFloat(u.replace(/m$/,"")));if(c.length<3||c.some(isNaN))continue;let o=s.getAttribute("data-normal"),d;if(o){let u=o.trim().split(/\s+/).map(l=>parseFloat(l));u.length>=3&&!u.some(isNaN)&&(d=[u[0],u[1],u[2]])}let a=r.projectPointToScreen([c[0],c[1],c[2]],d);s.style.position="absolute",s.style.left="0",s.style.top="0",s.style.transform=`translate(-50%, -50%) translate3d(${a.x}px, ${a.y}px, 0)`,s.style.zIndex="3",a.visible?(s.style.opacity="1",s.style.pointerEvents="auto",s.removeAttribute("data-occluded")):(s.style.opacity="0",s.style.pointerEvents="none",s.setAttribute("data-occluded",""))}}var ct={name:"hotspots",updateHotspotsForElement:qe,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{qe(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Ke.set(e,t)},onCameraChange(e,t){t&&qe(t,e)},onElementDisconnected(e){let t=Ke.get(e);t&&(t.disconnect(),Ke.delete(e))}};function me(e,t,r,i){let n=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.max(t,Math.min(r,n))}function mr(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function We(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function dr(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function pr(e){let t=We(e);if(!t)return null;let r=t.target;return{target:mr(r)?[r[0],r[1],r[2]]:typeof r=="string"&&r.length>0&&r.length<=256?r:[0,0,0],radius:me(t.radius,.01,50,.5),speed:me(t.speed,-20,20,.5),height:me(t.height,-10,10,0),phase:me(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}var gr=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],br=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],ui=new Set(gr),fi=new Set(br);function ht(e,t){let r=dr(e,16)?.trim();if(!r)return t;let i=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(r);return i?`#${i[1].toLowerCase()}`:t}function mt(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:We(e);if(!t||t.enabled===!1)return null;let r=me(t.strength??t.intensity,0,5,.35);return r>0?{enabled:!0,strength:r,threshold:me(t.threshold,0,4,.8),radius:me(t.radius,0,2,.5)}:null}function Xe(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:We(e);if(!t||t.enabled===!1)return null;let r=t.thickness??t.width;return{enabled:!0,color:ht(t.color,"#38bdf8"),thickness:me(typeof r=="number"&&r>0&&r<.25?Math.max(1.5,r*140):r,.5,20,3),pulse:t.pulse===!0}}function yr(e,t,r,i){let n=t[0],s=t[1],m=t[2],c=t[3],o=r[0],d=r[1],a=r[2],u=r[3],l=n*o+s*d+m*a+c*u;if(l<0&&(o=-o,d=-d,a=-a,u=-u,l=-l),Math.abs(l)>=1)return e[0]=n,e[1]=s,e[2]=m,e[3]=c,e;let h=Math.acos(l),f=Math.sqrt(1-l*l);if(Math.abs(f)<.001)return e[0]=.5*(n+o),e[1]=.5*(s+d),e[2]=.5*(m+a),e[3]=.5*(c+u),e;let g=Math.sin((1-i)*h)/f,A=Math.sin(i*h)/f;return e[0]=n*g+o*A,e[1]=s*g+d*A,e[2]=m*g+a*A,e[3]=c*g+u*A,e}var dt=1024,Qe=256,Re=2048,vr=128,xr=64,Mr=16,wr=1e4,Ar=8,he=new Set(["__proto__","constructor","prototype"]),pt={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},gt={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},Ce={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},De=(e,t)=>e!==null&&typeof e=="object"&&!he.has(t)&&Object.prototype.hasOwnProperty.call(e,t),te=e=>Array.isArray(e)?[...e]:e,bt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&De(e,"value")?e.value:e,W=(e,t)=>De(e.configuration,t)?bt(e.configuration[t]):void 0,V=(e,t=0)=>{let r=Number(e);return Number.isFinite(r)?r:t},ve=e=>Math.max(0,Math.min(1,e)),oe=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function Fe(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let r of e.slice(1).split("/")){let i=r.replace(/~1/g,"/").replace(/~0/g,"~");if(!i||he.has(i)||he.has(r))return null;t.push(i)}return{segments:t}}var xe=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let r=Number(e);return Number.isSafeInteger(r)&&r>=0&&r<t?r:-1},yt=e=>{let t=V(e[0]),r=V(e[1]),i=V(e[2]),n=V(e[3],1),s=Math.hypot(t,r,i,n);return s>1e-8?[t/s,r/s,i/s,n/s]:[0,0,0,1]},vt=(e,t,r,i)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*r;if(Array.isArray(e)&&Array.isArray(t)){if(i&&e.length===4&&t.length===4){let n=[0,0,0,1];return yr(n,yt(e),yt(t),r),n}return e.slice(0,t.length).map((n,s)=>n+(t[s]-n)*r)}return r>=.5?t:e},Ze=(e,t,r)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((i,n)=>r(V(i),V(t[n]))):Array.isArray(e)?e.map(i=>r(V(i),V(t))):Array.isArray(t)?t.map(i=>r(V(e),V(i))):r(V(e),V(t)),Sr=(e,t)=>Array.isArray(e)?e.map(r=>t(V(r))):t(V(e)),xt=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((r,i)=>Math.abs(r-t[i])<=1e-6):e===t,Mt=class{constructor(e,t,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>dt)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${dt})`);let n=Array.isArray(r.variables)?r.variables:[];if(n.length>Qe)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Qe})`);let s=Array.isArray(r.declarations)?r.declarations:[],m=Array.isArray(r.events)?r.events:[],c=new Map,o=new Map,d=new Map,a=new Map,u=new Map,l=new Map,h=[],f=[],g=new Map,A=1,v=0,T=0,p=0,b=0,y=!1,L=!1,C=!1;n.forEach((N,x)=>{if(!N||typeof N!="object")return;let E=te(bt(N.value));c.set(x,E);let P=N.id??N.name;typeof P=="string"&&P&&!he.has(P)&&c.set(P,E)}),(t?.nodes||[]).forEach((N,x)=>{for(let E of N?.children||[])typeof E=="number"&&g.set(E,x)});let F=N=>N.op||typeof N.declaration=="number"&&s[N.declaration]?.op||"",_=(N,x,E)=>{if(he.has(x))return;let P=o.get(N);P||o.set(N,P=Object.create(null)),P[x]=E},O=(N,x)=>{if(typeof N!="number"&&typeof N!="string"||typeof N=="string"&&he.has(N)||!c.has(N)&&c.size>=Qe*2)return;let E=te(x);if(c.set(N,E),typeof N=="number"){let P=n[N]?.id??n[N]?.name;typeof P=="string"&&!he.has(P)&&c.set(P,E)}},D=N=>typeof N=="number"?m[N]?.id??String(N):typeof N=="string"?/^\d+$/.test(N)&&m[Number(N)]?.id?m[Number(N)].id:N:"",$=(N,x)=>{for(let E=N,P=0;E!==void 0&&E>=0&&P<128;E=g.get(E),P++)if(E===x)return!0;return!1},z=N=>{for(let x=h.length-1;x>=0;x--)h[x].key===N&&h.splice(x,1)},k=N=>{z(N.key),h.length>=vr&&h.shift(),h.push(N)},re=N=>{let x=Fe(N)?.segments;if(x){if(x[0]==="nodes"&&Array.isArray(t?.nodes)){let E=t.nodes[xe(x[1],t.nodes.length)];if(!E)return;let P=x[2];if(P in Ce){let S=Ce[P],M=E[P]||S;return S.map((w,I)=>V(M[I],w))}if(P==="weights"){let S=Array.isArray(E.weights)?E.weights:[0],M=x.length===4?xe(x[3],64):-2;return M===-2?S.map(w=>V(w)):M>=0?V(S[M]):void 0}if(P==="visible"||P==="extensions"&&x[3]==="KHR_node_visibility"&&x[4]==="visible")return E.extensions?.KHR_node_visibility?.visible??E.visible??!0}else if(x[0]==="materials"&&Array.isArray(t?.materials)){let E=t.materials[xe(x[1],t.materials.length)];if(!E)return;let P=E.pbrMetallicRoughness||{};if(x[2]==="pbrMetallicRoughness"){if(x[3]==="baseColorFactor"){let S=P.baseColorFactor||[1,1,1,1];return[V(S[0],1),V(S[1],1),V(S[2],1),V(S[3],1)]}if(x[3]==="metallicFactor"||x[3]==="roughnessFactor")return V(P[x[3]],1)}if(x[2]==="emissiveFactor"){let S=E.emissiveFactor||[0,0,0];return[V(S[0]),V(S[1]),V(S[2])]}if(x[2]==="alphaCutoff")return V(E.alphaCutoff,.5)}}},Z=(N,x)=>{let E=Fe(N)?.segments;if(!E)return!1;if(E[0]==="nodes"&&Array.isArray(t?.nodes)){let P=xe(E[1],t.nodes.length),S=t.nodes[P];if(!S)return!1;let M=E[2];if(M in Ce&&Array.isArray(x)){let w=Ce[M];if(x.length<w.length)return!1;let I=w.map((H,K)=>V(x[K],H));if(M==="rotation"){let H=Math.hypot(...I);I=H>1e-8?I.map(K=>K/H):[0,0,0,1]}S[M]=I,delete S.matrix;let B=e?.initialNodeTransforms?.[P];return B&&(B[M[0]]=[...I]),y=!0,!0}if(M==="weights"){Array.isArray(S.weights)||(S.weights=[]);let w=(I,B)=>{for(let H of e?.meshes||[])if(H.nodeIndex===P)for(let K of H.primitives||[])K.pluginData?.morph?.weights&&(K.pluginData.morph.weights[I]=B)};if(E.length===4){let I=xe(E[3],64);if(I<0)return!1;w(I,S.weights[I]=V(x))}else if(Array.isArray(x))S.weights=x.slice(0,64).map(I=>V(I)),S.weights.forEach((I,B)=>w(B,I));else return!1;return C=!0,!0}if(M==="visible"||M==="extensions"&&E[3]==="KHR_node_visibility"&&E[4]==="visible"){let w=oe(x);return S.visible=w,(!S.extensions||typeof S.extensions!="object")&&(S.extensions={}),S.extensions.KHR_node_visibility={visible:w},L=!0,!0}}else if(E[0]==="materials"&&Array.isArray(t?.materials)){let P=xe(E[1],t.materials.length),S=t.materials[P];if(!S)return!1;let M=S.pbrMetallicRoughness||(S.pbrMetallicRoughness={}),w=I=>{for(let B of e?.meshes||[])for(let H of B.primitives||[])(H.materialIndex??0)===P&&I(H)};if(E[2]==="pbrMetallicRoughness"){if(E[3]==="baseColorFactor"&&Array.isArray(x)&&x.length>=3){let I=[ve(V(x[0],1)),ve(V(x[1],1)),ve(V(x[2],1)),x[3]!==void 0?ve(V(x[3],1)):M.baseColorFactor?.[3]??1];return M.baseColorFactor=I,w(B=>B.baseColor=[...I]),C=!0}if(E[3]==="metallicFactor"||E[3]==="roughnessFactor"){let I=E[3]==="metallicFactor",B=ve(V(x,I?0:.5));return M[E[3]]=B,w(H=>H[I?"metallic":"roughness"]=B),C=!0}}if(E[2]==="emissiveFactor"&&Array.isArray(x)&&x.length>=3)return S.emissiveFactor=[0,1,2].map(I=>Math.max(0,V(x[I]))),C=!0;if(E[2]==="alphaCutoff")return S.alphaCutoff=ve(V(x,.5)),C=!0}return!1},X=(N,x,E=new Set)=>{let P=W(x,"pointer");if(typeof P!="string"||!P.startsWith("/"))return null;let S=P.replace(/\{([a-zA-Z0-9_]+)\}/g,(M,w)=>{let I=Math.trunc(Number(ie(N,w,void 0,E)??W(x,w)));return Number.isSafeInteger(I)&&I>=0?String(I):"-1"});return Fe(S)?S:null},ie=(N,x,E,P)=>{let S=i[N]?.values;if(!De(S,x))return E;let M=S[x];if(M==null)return E;if(typeof M!="object"||Array.isArray(M))return te(M);let w=M;return typeof w.node=="number"?He(w.node,w.socket||"value",P):De(w,"value")?te(w.value):E},He=(N,x,E)=>{if(N<0||N>=i.length||E.has(N)||E.size>128||++p>wr)return;let P=i[N],S=F(P);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(S))return te(o.get(N)?.[x]);E.add(N);try{let M=(w,I=0)=>ie(N,w,I,E);if(S==="variable/get"){let w=W(P,"variable")??W(P,"id");return typeof w=="number"||typeof w=="string"?te(c.get(w)):void 0}if(S==="pointer/get"){let w=X(N,P,E);return w?re(w):void 0}if(S.startsWith("math/")){let w=S.slice(5);if(w in pt)return Sr(M("a"),pt[w]);if(w in gt){let I=/^(mul|div|rem|mod|pow)$/.test(w)?1:0;return Ze(M("a",w==="mul"?1:0),M("b",I),gt[w])}if(w==="pi")return Math.PI;if(w==="e")return Math.E;if(w==="random")return Math.random();if(w==="clamp")return Ze(Ze(M("a"),M("b",M("min",0)),Math.max),M("c",M("max",1)),Math.min);if(w==="mix"||w==="quatSlerp")return vt(M("a",0),M("b",1),V(M("c",M("t",.5)),.5),w==="quatSlerp");if(w==="dot"){let I=M("a"),B=M("b");return Array.isArray(I)&&Array.isArray(B)?I.reduce((H,K,R)=>H+(K||0)*(B[R]||0),0):V(I)*V(B)}if(w==="cross"){let I=M("a",[0,0,0]),B=M("b",[0,0,0]);return Array.isArray(I)&&Array.isArray(B)?[(I[1]||0)*(B[2]||0)-(I[2]||0)*(B[1]||0),(I[2]||0)*(B[0]||0)-(I[0]||0)*(B[2]||0),(I[0]||0)*(B[1]||0)-(I[1]||0)*(B[0]||0)]:[0,0,0]}if(w==="length"){let I=M("a");return Array.isArray(I)?Math.hypot(...I):Math.abs(V(I))}if(w==="distance"){let I=M("a"),B=M("b");return Array.isArray(I)&&Array.isArray(B)?Math.hypot(...I.map((H,K)=>(H||0)-(B[K]||0))):Math.abs(V(I)-V(B))}if(w==="normalize"){let I=M("a");if(!Array.isArray(I))return V(I)>=0?1:-1;let B=Math.hypot(...I);return B>1e-8?I.map(H=>H/B):I.map(()=>0)}if(w.startsWith("combine"))return["a","b","c","d"].slice(0,Number(w[7])||2).map(I=>V(M(I)));if(w.startsWith("extract")){let I=M("a");return Array.isArray(I)?I[x==="0"||x==="x"?0:x==="1"||x==="y"?1:x==="2"||x==="z"?2:3]??0:0}if(w==="eq")return xt(M("a"),M("b"));if(w==="ne")return!xt(M("a"),M("b"));if(w==="lt")return V(M("a"))<V(M("b"));if(w==="le")return V(M("a"))<=V(M("b"));if(w==="gt")return V(M("a"))>V(M("b"));if(w==="ge")return V(M("a"))>=V(M("b"));if(w==="isNaN")return Number.isNaN(Number(M("a")));if(w==="isInf"){let I=Number(M("a"));return!Number.isFinite(I)&&!Number.isNaN(I)}return w==="and"?oe(M("a",!1))&&oe(M("b",!1)):w==="or"?oe(M("a",!1))||oe(M("b",!1)):w==="xor"?oe(M("a",!1))!==oe(M("b",!1)):w==="not"?!oe(M("a",!1)):w==="select"?te(oe(M("condition",!1))?M("a"):M("b")):void 0}return S==="type/boolToInt"||S==="type/boolToFloat"?oe(M("a",!1))?1:0:S==="type/intToBool"||S==="type/floatToBool"?V(M("a",0))!==0:S==="type/intToFloat"?V(M("a",0)):S==="type/floatToInt"?Math.trunc(V(M("a",0))):void 0}finally{E.delete(N)}},we=()=>{if(y){y=!1,C=!0;let N=ot(t);if(e){e.worldMatrices=N;for(let x of e.meshes||[])x.nodeIndex>=0&&x.nodeIndex<N.length&&(x.transform.set(N[x.nodeIndex]),Ve(x.normalMatrix,x.transform))}}if(L){L=!1,C=!0;let N=t?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(N))for(let x of e.meshes){let E=!0;for(let P=x.nodeIndex,S=0;P!==void 0&&P>=0&&S<128;P=g.get(P),S++){let M=N[P];if(M?.visible===!1||M?.extensions?.KHR_node_visibility?.visible===!1){E=!1;break}}x.visible=E}}C&&(C=!1,e?.render?.())},ne=(N,x={steps:0})=>{if(!N||typeof N.node!="number")return;x.steps===0&&(p=0);let E=[N],P=S=>{E.length+x.steps<Re&&E.push(S)};for(;E.length>0&&x.steps<Re;){x.steps++;let S=E.shift();if(!S||S.node<0||S.node>=i.length)continue;let M=S.node,w=i[M];if(!w)continue;let I=S.socket||"in",B=F(w),H=(R,U=void 0)=>ie(M,R,U,new Set),K=(R="out")=>{let U=w.flows?.[R];U&&P(U)};switch(B){case"flow/branch":K(oe(H("condition",!1))?"true":"false");break;case"flow/sequence":for(let R of Object.keys(w.flows||{}).sort((U,Q)=>Number(U)-Number(Q)||U.localeCompare(Q)))K(R);break;case"flow/switch":{let R=w.flows?.[String(H("selection",H("value",0)))]??w.flows?.default;R&&P(R);break}case"flow/for":{let R=Math.trunc(V(H("startIndex",0))),U=Math.trunc(V(H("endIndex",0))),Q=Math.max(1,Math.trunc(V(H("step",1),1))),Y=w.flows?.body;if(Y&&U>R&&b<Ar){let G=Math.min(Math.ceil((U-R)/Q),Re);b++;try{for(let ee=0;ee<G&&x.steps<Re;ee++)_(M,"index",R+ee*Q),ne(Y,x)}finally{b--}}let de=w.flows?.completed??w.flows?.out;de&&P(de);break}case"flow/doN":{let R=I==="reset"?0:(d.get(M)||0)+1;if(d.set(M,R),_(M,"currentCount",R),_(M,"count",R),I!=="reset"){let U=Math.trunc(V(H("n",W(w,"stopIterations")??W(w,"n")??1),1));R<=U&&K()}break}case"flow/multiGate":{if(I==="reset"){l.set(M,0);break}let R=Object.keys(w.flows||{}).sort();if(!R.length)break;let U=W(w,"isRandom")?Math.floor(Math.random()*R.length):l.get(M)||0;U<R.length&&(K(R[U]),l.set(M,W(w,"isLoop")!==!1?(U+1)%R.length:U+1));break}case"flow/waitAll":{if(I==="reset"){a.delete(M);break}let R=a.get(M);R||a.set(M,R=new Set),R.add(I),R.size>=Math.max(1,Math.trunc(Number(W(w,"inputFlows")??2)||2))&&(R.clear(),K("out"),K("completed"));break}case"flow/throttle":{if(I==="reset"){u.delete(M);break}let R=Math.max(0,V(H("duration",0))),U=u.get(M);U===void 0||v-U>=R?(u.set(M,v),_(M,"lastRemainingTime",0),K()):_(M,"lastRemainingTime",Math.max(0,R-(v-U)));break}case"flow/delay":case"flow/setDelay":{if(I==="cancel"){for(let Y=f.length-1;Y>=0;Y--)f[Y].nodeIdx===M&&f.splice(Y,1);_(M,"lastDelayIndex",-1);break}let R=Math.max(0,V(H("duration",W(w,"duration")??0))),U=w.flows?.done??w.flows?.out;if(R<=0){_(M,"lastDelayIndex",-1),U&&P(U);break}f.length>=xr&&f.shift();let Q=A++;_(M,"lastDelayIndex",Q),f.push({id:Q,nodeIdx:M,rem:R,done:U}),B==="flow/setDelay"&&w.flows?.out&&w.flows?.done&&K("out");break}case"flow/cancelDelay":{let R=Math.trunc(V(H("delayIndex",-1),-1));if(R<0)f.length=0;else for(let U=f.length-1;U>=0;U--)f[U].id===R&&f.splice(U,1);K();break}case"variable/set":O(W(w,"variable")??W(w,"id"),H("value")),K();break;case"variable/interpolate":{let R=W(w,"variable")??W(w,"id"),U=H("value",H("target")),Q=Math.max(0,V(H("duration",W(w,"duration")??.3),.3));R!==void 0&&U!==void 0&&k({key:`var:${String(R)}`,varKey:R,from:te(H("from")??c.get(R)??0),to:te(U),dur:Q,elapsed:0,quat:!1,linear:W(w,"easing")==="linear",done:w.flows?.done}),K();break}case"pointer/set":{let R=X(M,w),U=H("value");R&&U!==void 0&&(z(`ptr:${R}`),Z(R,U)),K();break}case"pointer/interpolate":{let R=X(M,w),U=H("value",H("target")),Q=Math.max(0,V(H("duration",W(w,"duration")??.3),.3));if(R&&U!==void 0){let Y=H("from")??re(R);Y!==void 0&&(Q<=0?(Z(R,U),K("done")):k({key:`ptr:${R}`,ptr:R,from:te(Y),to:te(U),dur:Q,elapsed:0,quat:R.endsWith("/rotation"),linear:W(w,"easing")==="linear",done:w.flows?.done}))}K();break}case"animation/start":{let R=H("animation")??W(w,"animation")??W(w,"clipName"),U=typeof R=="number"?e?.animations?.[R]?.name??t?.animations?.[R]?.name:typeof R=="string"?R:void 0;e?.playAnimation?.(U),C=!0,K();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),B==="animation/resetAt"&&e?.evaluateAnimation?.(V(H("time",0))),C=!0,K();break;case"event/send":case"customEvent/send":{let R=D(W(w,"event")??W(w,"id")),U={};for(let Q of Object.keys(w.values||{}))he.has(Q)||(U[Q]=H(Q));R&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:R,values:U}})),ce(R,U,x)),K();break}default:K();break}}};this.readScenePointer=re,this.writeScenePointer=Z,this.fireOnStart=()=>{i.forEach(N=>{F(N)==="event/onStart"&&ne(N.flows?.out)}),we()},this.fireOnSelect=N=>{if(!N)return;let x=typeof N.meshIndex=="number"?N.meshIndex:-1,E=typeof N.nodeIndex=="number"?N.nodeIndex:e?.meshes?.[x]?.nodeIndex??-1;i.forEach((P,S)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(F(P)))return;let M=W(P,"nodeIndex")??W(P,"node")??ie(S,"nodeIndex",void 0,new Set),w=W(P,"meshName");if(typeof w=="string"&&w?N.meshName===w:M==null||Number(M)<0||Number.isNaN(Number(M))||$(E,Math.trunc(Number(M)))){if(_(S,"nodeIndex",E),_(S,"meshIndex",x),Array.isArray(N.hitPoint)){let I=[V(N.hitPoint[0]),V(N.hitPoint[1]),V(N.hitPoint[2])];_(S,"hitPoint",I),_(S,"point",I),_(S,"intersectionPoint",I)}if(Array.isArray(N.normal)){let I=[V(N.normal[0]),V(N.normal[1],1),V(N.normal[2])];_(S,"normal",I),_(S,"hitNormal",I)}typeof N.distance=="number"&&_(S,"distance",N.distance),ne(P.flows?.out)}}),we()},this.receiveCustomEvent=(N,x={})=>ce(N,x,{steps:0});function ce(N,x,E){if(!(T>=Mr)){T++;try{let P=D(N);i.forEach((S,M)=>{if(!/^(customE|e)vent\/receive$/.test(F(S)))return;let w=W(S,"event")??W(S,"id");if(!(D(w)!==P&&String(w)!==String(N))){for(let[I,B]of Object.entries(x))he.has(I)||_(M,I,te(B));ne(S.flows?.out,E)}}),we()}finally{T--}}}this.tick=N=>{if(!Number.isFinite(N)||N<0)return;let x=Math.min(N,.25);v+=x,i.forEach((P,S)=>{F(P)==="event/onTick"&&(_(S,"timeDelta",x),_(S,"dt",x),_(S,"timeElapsed",v),ne(P.flows?.out))});let E=[];for(let P=h.length-1;P>=0;P--){let S=h[P];S.elapsed+=x;let M=S.dur>1e-6?ve(S.elapsed/S.dur):1,w=S.linear?M:M*M*(3-2*M),I=vt(S.from,S.to,w,S.quat);S.ptr?Z(S.ptr,I):S.varKey!==void 0&&O(S.varKey,I),M>=1&&(h.splice(P,1),S.done&&E.push(S.done))}for(let P=f.length-1;P>=0;P--){let S=f[P];S.rem-=x,S.rem<=0&&(f.splice(P,1),S.done&&E.push(S.done))}for(let P of E)ne(P);we()},this.dispose=()=>{h.length=0,f.length=0,c.clear(),o.clear(),d.clear(),a.clear(),u.clear(),l.clear()}}},ue=new WeakMap,Oe=new WeakMap;function Tr(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||sr().some(c=>c.name==="xr-live-head-follow")||(typeof e.getAutoRotate=="function"?e.getAutoRotate():e.autoRotate)===!1)return;let r=e.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return;let n=Math.min(t,.1),s=(Oe.get(e)||0)+n,m=!1;for(let c=0;c<i.length;c++){let o=i[c],d=pr(o?.extras?.xr?.orbit);if(!d)continue;let a=0,u=0,l=0;if(Array.isArray(d.target))a=d.target[0],u=d.target[1],l=d.target[2];else if(typeof d.target=="string"&&d.target!=="head"){let v=i.find(T=>T?.name===d.target);Array.isArray(v?.translation)&&(a=V(v.translation[0]),u=V(v.translation[1]),l=V(v.translation[2]))}let h=d.phase+d.speed*s,f=a+Math.cos(h)*d.radius,g=u+d.height,A=l+Math.sin(h)*d.radius;if(o.translation=[f,g,A],d.faceCenter){let v=Math.atan2(a-f,l-A);o.rotation=[0,Math.sin(v*.5),0,Math.cos(v*.5)]}m=!0}if(m){Oe.set(e,s);let c=ot(r);e.worldMatrices=c;for(let o of e.meshes||[])o.nodeIndex>=0&&o.nodeIndex<c.length&&(o.transform.set(c[o.nodeIndex]),Ve(o.normalMatrix,o.transform))}}function Ye(e){if(!(!e||typeof e!="object"))return ue.get(e)||ue.get(e.viewer)||ue.get(e._view)}function wt(e,t,r){let i=Ye(e);return i?(i.receiveCustomEvent(t,r),!0):!1}var At={name:"khr-interactivity",sendInteractivityEvent:wt,getInteractivityVM:Ye,onLoadModel(e,t){if(!e||typeof e!="object")return;ue.get(e)?.dispose(),ue.delete(e),Oe.delete(e);let r=t?.extensions?.KHR_interactivity,i=Array.isArray(r?.graphs)?r.graphs[r.graph??0]:r;if(!i||!Array.isArray(i.nodes))return;let n=new Mt(e,t,i);ue.set(e,n),n.fireOnStart()},onMeshSelect(e,t){ue.get(e)?.fireOnSelect(t)},onUpdate(e,t){ue.get(e)?.tick(t),Tr(e,t)},onDestroy(e,t){ue.get(t)?.dispose(),ue.delete(t),Oe.delete(t)}};function Ue(e,t){let r=(a,u,l,h)=>{let f=typeof a=="number"?a:Number(a);return Number.isFinite(f)?Math.max(u,Math.min(l,f)):h};function i(a,u,l=0,h=.05,f){if(!a||!a.length)return-1;let g=a[0]>0?[0,...a]:a,A=Number.isFinite(u)?Math.max(0,u):0,v=Number.isFinite(h)?Math.max(0,Math.min(.5,h)):.05;if(typeof f=="number"&&Number.isFinite(f)&&f>0){let b=l===-1?f*(1-v):f*(1+v);if(A>b)return-1}let T=0;for(let b=g.length-1;b>=1;b--)if(A>=g[b]){T=b;break}if(l<0||l>=g.length||l===T)return T;if(T>l){let b=l;for(let y=l+1;y<=T&&A>=g[y]*(1+v);y++)b=y;return b}let p=l;for(let b=l;b>T&&A<g[b]*(1-v);b--)p=b-1;return p}function n(a){if(!a)return null;let u=a===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(a)?{distances:a}:typeof a=="object"?a:null;if(!u||u.enabled===!1)return null;let l=r(u.hysteresis,0,.5,.05),h=[],f;if(Array.isArray(u.levels)&&u.levels.length>0){let T=u.levels.slice(0,8);for(let b=0;b<T.length;b++){let y=T[b];if(!y||typeof y!="object"||Array.isArray(y))continue;let L=y,C=r(L.distance,0,1e4,b===0?0:b*4),F=typeof L.hysteresis=="number"?r(L.hysteresis,0,.5,l):void 0,_=typeof L.ratio=="number"?r(L.ratio,.05,1,.5):void 0,O=typeof L.childIndex=="number"&&Number.isFinite(L.childIndex)?Math.max(0,Math.round(L.childIndex)):void 0,D=typeof L.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(L.node.trim())?L.node.trim().slice(0,64):void 0;h.push({distance:C,...F!==void 0?{hysteresis:F}:{},..._!==void 0?{ratio:_}:{},...O!==void 0?{childIndex:O}:{},...D?{node:D}:{}})}h.sort((b,y)=>b.distance-y.distance),h.length>0&&h[0].distance>0&&h.unshift({distance:0,childIndex:0});let p=0;h=h.slice(0,8).map((b,y)=>{let L=y===0?0:Math.max(p,b.distance);return p=L,{...b,distance:L,childIndex:b.childIndex??y}})}if(Array.isArray(u.ratios)&&u.ratios.length>0){let T=[];for(let p of u.ratios.slice(0,7))typeof p=="number"&&T.push(r(p,.05,1,.5));T.length>0&&(f=T)}if(h.length===0){let T=Array.isArray(u.distances)?u.distances:[],p=[];for(let y of T.slice(0,8))typeof y=="number"&&p.push(r(y,0,1e4,4));if(p.length===0&&f&&f.length>0)for(let y=0;y<f.length;y++)p.push((y+1)*4);if(p.length===0&&u.cullDistance===void 0)return null;p.length===0||p[0]>0?p.unshift(0):f&&f.length===p.length&&f[0]===1&&(f=f.slice(1));let b=0;for(let y=0;y<Math.min(8,p.length);y++){let L=y===0?0:Math.max(b,p[y]);b=L;let C=y>0&&f?f[y-1]:void 0;h.push({distance:L,childIndex:y,...C!==void 0?{ratio:C}:{}})}}else if(!f){let T=[];for(let p=1;p<h.length;p++)typeof h[p].ratio=="number"&&T.push(h[p].ratio);T.length>0&&(f=T)}let g=h.map(T=>T.distance),A=g[g.length-1]??0,v=u.cullDistance!==void 0&&u.cullDistance!==null&&u.cullDistance!==!1?r(u.cullDistance,Math.max(1,A),1e4,100):void 0;return{levels:h,distances:g,...f?{ratios:f}:{},hysteresis:l,...v!==void 0?{cullDistance:v}:{}}}function s(a,u){let l=a?.attributes?.position;if(!l||!l.array||l.count<3)return a;let h=r(u,.05,1,.5),f=l.array,g=l.count,A=a.attributes?.normal?.array,v=a.attributes?.uv?.array,T=a.index?.array,p=Math.floor((T?T.length:g)/3);if(p<1)return a;let b=Math.max(1,Math.min(p,Math.round(p*h))),y=1/0,L=1/0,C=1/0,F=-1/0,_=-1/0,O=-1/0;for(let x=0;x<g;x++){let E=f[x*3],P=f[x*3+1],S=f[x*3+2];E<y&&(y=E),P<L&&(L=P),S<C&&(C=S),E>F&&(F=E),P>_&&(_=P),S>O&&(O=S)}let D=Math.max(1e-5,F-y),$=Math.max(1e-5,_-L),z=Math.max(1e-5,O-C),k=Math.max(D,$,z),re=x=>{let E=Math.max(1,Math.round(D/k*x)),P=Math.max(1,Math.round($/k*x)),S=Math.max(1,Math.round(z/k*x)),M=new Map,w=new Int32Array(g),I=[],B=[],H=[],K=[];for(let G=0;G<g;G++){let ee=f[G*3],pe=f[G*3+1],ge=f[G*3+2],le=Math.min(E-1,Math.max(0,Math.floor((ee-y)/D*E))),ae=Math.min(P-1,Math.max(0,Math.floor((pe-L)/$*P))),be=Math.min(S-1,Math.max(0,Math.floor((ge-C)/z*S))),Pe=le+ae*E+be*E*P,J=M.get(Pe);J===void 0?(J=K.length,M.set(Pe,J),I.push(ee,pe,ge),A&&B.push(A[G*3],A[G*3+1],A[G*3+2]),v&&H.push(v[G*2],v[G*2+1]),K.push(1)):(I[J*3]+=ee,I[J*3+1]+=pe,I[J*3+2]+=ge,A&&(B[J*3]+=A[G*3],B[J*3+1]+=A[G*3+1],B[J*3+2]+=A[G*3+2]),K[J]++),w[G]=J}let R=[],U=new Set;for(let G=0;G<p;G++){let ee=T?T[G*3]:G*3,pe=T?T[G*3+1]:G*3+1,ge=T?T[G*3+2]:G*3+2,le=w[ee],ae=w[pe],be=w[ge];if(le===ae||ae===be||be===le)continue;let Pe=Math.min(le,ae,be),J=Math.max(le,ae,be),li=le+ae+be-Pe-J,er=`${Pe}_${li}_${J}`;U.has(er)||(U.add(er),R.push(le,ae,be))}let Q=K.length,Y=new Float32Array(Q*3),de=A?new Float32Array(Q*3):null;for(let G=0;G<Q;G++){let ee=1/K[G];if(Y[G*3]=I[G*3]*ee,Y[G*3+1]=I[G*3+1]*ee,Y[G*3+2]=I[G*3+2]*ee,de){let pe=B[G*3],ge=B[G*3+1],le=B[G*3+2],ae=Math.hypot(pe,ge,le)||1;de[G*3]=pe/ae,de[G*3+1]=ge/ae,de[G*3+2]=le/ae}}return{pos:Y,norm:de,uv:v?new Float32Array(H):null,tris:R,triCount:R.length/3,vertCount:Q}},Z=Math.max(2,Math.round(Math.sqrt(b/4))),X=re(Z);if(X.triCount>b*1.25&&Z>2){let x=Math.max(2,Math.round(Z*Math.sqrt(b/X.triCount)));if(x!==Z){let E=re(x);E.triCount>=Math.min(4,b)&&(X=E)}}else if(X.triCount<Math.min(4,b)){let x=re(Math.max(Z*2,8));x.triCount>X.triCount&&(X=x)}let ie=X.tris;if(h<1&&X.triCount>b){let x=[],E=X.triCount/b;for(let P=0;P<b;P++){let S=Math.min(X.triCount-1,Math.floor(P*E));x.push(X.tris[S*3],X.tris[S*3+1],X.tris[S*3+2])}ie=x}if(ie.length<3){ie=[];for(let x=0;x<b*3;x++)ie.push(T?T[x]:x);X={pos:f.slice(),norm:A?A.slice():null,uv:v?v.slice():null,tris:ie,triCount:b,vertCount:g}}let He=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),we=He?.BufferGeometry??a.constructor,ne=He?.BufferAttribute??l.constructor,ce=new we;ce.setAttribute("position",new ne(X.pos,3)),X.norm&&ce.setAttribute("normal",new ne(X.norm,3)),X.uv&&ce.setAttribute("uv",new ne(X.uv,2));let N=X.vertCount>65535?new Uint32Array(ie):new Uint16Array(ie);return typeof ce.setIndex=="function"?ce.setIndex(new ne(N,1)):ce.index=new ne(N,1),ce}let m=e?.Object3D??t?.threeNamespace?.Object3D??class{constructor(){this.name="",this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0},this.quaternion={x:0,y:0,z:0,w:1},this.scale={x:1,y:1,z:1},this.visible=!0,this.parent=null,this.children=[],this.userData={}}add(...a){for(let u of a)u&&(u.parent=this,this.children.push(u));return this}};class c extends m{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(u,l=0,h=.05){if(!u)return this;let f=Math.max(0,Number.isFinite(Number(l))?Number(l):0),g=r(h,0,.5,.05),A=this.levels.length;for(let p=0;p<this.levels.length;p++)if(f<this.levels[p].distance){A=p;break}this.levels.splice(A,0,{object:u,distance:f,hysteresis:g}),this.add(u);let v=this.levels.map(p=>p.object),T=this.children.filter(p=>!v.includes(p));this.children=[...v,...T];for(let p=0;p<this.levels.length;p++)this.levels[p].object.visible=p===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(u){if(!this.levels.length)return null;let l=i(this.levels.map(h=>h.distance),u,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return l>=0&&l<this.levels.length?this.levels[l].object:null}update(u){if(this.levels.length===0||!u)return;let l=u.position??{x:0,y:0,z:0},h=this.position??{x:0,y:0,z:0},f=Math.hypot((Number(l.x)||0)-(Number(h.x)||0),(Number(l.y)||0)-(Number(h.y)||0),(Number(l.z)||0)-(Number(h.z)||0)),g=i(this.levels.map(A=>A.distance),f,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=g;for(let A=0;A<this.levels.length;A++)this.levels[A].object.visible=A===g}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let u=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((l,h)=>({distance:l.distance,hysteresis:l.hysteresis,childIndex:h,...l.object?.name?{node:l.object.name}:{}})),distances:this.levels.map(l=>l.distance),hysteresis:this.levels[0]?.hysteresis??.05,...u!==void 0?{cullDistance:u}:{}}}}function o(a){if(!a||a._lodMaterialized||!a.userData?.xr?.lod||a.isLOD||Array.isArray(a.children)&&a.children.length>0)return;let u=a.geometry?.attributes?.position;if(!u||!u.array||u.count<3)return;let l=n(a.userData.xr.lod);if(!l||l.levels.length<2)return;a._lodMaterialized=!0;let h=a.geometry;a._lodOriginalGeometry=h;let f=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),g=f?.Mesh??a.constructor,A=f?.BufferGeometry??h.constructor,v=typeof a.name=="string"&&a.name.trim()?a.name.trim():"Mesh",T=new g(h,a.material);T.name=`${v}_LOD0`,T.visible=!0,T.castShadow=!!a.castShadow,T.receiveShadow=!!a.receiveShadow,a.add(T);for(let p=1;p<l.levels.length;p++){let b=l.levels[p].ratio??l.ratios?.[p-1]??Math.max(.05,Math.pow(.5,p)),y=s(h,b),L=new g(y,a.material);L.name=`${v}_LOD${p}`,L.visible=!1,L.castShadow=!!a.castShadow,L.receiveShadow=!!a.receiveShadow,a.add(L)}a.geometry=new A,a.userData.xr.lod={...l,levels:l.levels.map((p,b)=>({...p,childIndex:b,node:`${v}_LOD${b}`}))}}let d={LOD:c,decimateGeometry:s,selectLodLevelIndex:i,parseLod:n,materializeLodGeometry:o};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,{LOD:c,decimateGeometry:s}),t._lodMaterialize=o,t.materializeDeclarativeGeometry=a=>{t._cadMaterialize?.(a),t._lodMaterialize?.(a)}),d}var Te=Ue(),Nr=Te.decimateGeometry,Je=Te.selectLodLevelIndex,et=Te.parseLod,ci=Te.materializeLodGeometry,Ir=Te.LOD,Ne=new WeakMap;function Lr(e){return e&&typeof e=="object"?Ne.get(e):void 0}var St=class{constructor(e,t){this.groups=[],this.viewer=e,this.gltf=t,this.rebuild()}rebuild(){this.groups.length=0;let e=this.gltf?.nodes;if(!Array.isArray(e)||e.length===0)return;let t=new Map;for(let i of this.viewer?.meshes??[])if(typeof i?.nodeIndex=="number"&&i.nodeIndex>=0){let n=t.get(i.nodeIndex);n||(n=[],t.set(i.nodeIndex,n)),n.push(i)}let r=i=>{let n=[],s=new Set,m=[i];for(;m.length>0;){let c=m.pop();if(s.has(c)||c<0||c>=e.length)continue;s.add(c);let o=t.get(c);o&&n.push(...o);let d=e[c]?.children;if(Array.isArray(d))for(let a=d.length-1;a>=0;a--)typeof d[a]=="number"&&m.push(d[a])}return n};for(let i=0;i<e.length;i++){let n=e[i];if(!n||typeof n!="object")continue;let s=n.extras?.xr?.lod??n.extensions?.ANDROID_xr_scenecore?.lod??n.extensions?.MOZ_hubs_components?.lod,m=Array.isArray(n.extensions?.MSFT_lod?.ids)?n.extensions.MSFT_lod.ids.filter(h=>typeof h=="number"&&Number.isInteger(h)&&h>=0&&h<e.length):[],c=et(s);if(!c&&m.length>0&&(c=et({distances:m.map((h,f)=>f*4)})),!c)continue;let o=m.length>0?m:Array.isArray(n.children)?n.children.filter(h=>typeof h=="number"&&Number.isInteger(h)&&h>=0&&h<e.length):[],d=[],a=[];if(o.length>0){let h=Math.min(o.length,c.levels.length);for(let f=0;f<h;f++){let g=o[f];d.push(g),a.push(r(g))}}else{let h=t.get(i)??[];if(h.length===0)continue;d.push(i),a.push(h)}let u=c.distances.slice(0,a.length);u.length===0&&u.push(0);let l={nodeIndex:i,name:typeof n.name=="string"?n.name:`LOD_${i}`,distances:u,hysteresis:c.hysteresis,...c.cullDistance!==void 0?{cullDistance:c.cullDistance}:{},childNodeIndices:d,levelMeshes:a,activeLevelIndex:0,lastDistance:0};this.applyGroupVisibility(l,0),this.groups.push(l)}}getGroups(){return this.groups}getActiveLevel(e){let t=this.findGroup(e);return t?t.activeLevelIndex:null}forceLodLevel(e,t){let r=this.findGroup(e);if(!r)return;if(t==null){r.forcedLevelIndex=null;let n=Je(r.distances,r.lastDistance,r.activeLevelIndex,r.hysteresis,r.cullDistance);r.activeLevelIndex=n,this.applyGroupVisibility(r,n);return}let i=t<0?-1:Math.min(Math.max(0,Math.trunc(t)),r.levelMeshes.length-1);r.forcedLevelIndex=i,r.activeLevelIndex=i,this.applyGroupVisibility(r,i)}findGroup(e){return typeof e=="number"?this.groups.find(t=>t.nodeIndex===e)??this.groups[e]:this.groups.find(t=>t.name===e)}update(e){if(this.groups.length===0)return;let t=this.viewer?.worldMatrices,r=this.viewer?.modelRootMatrix;for(let i of this.groups){let n=Array.isArray(t)&&i.nodeIndex<t.length?t[i.nodeIndex]:null,s=n&&n[12]||0,m=n&&n[13]||0,c=n&&n[14]||0,o=r?r[0]*s+r[4]*m+r[8]*c+r[12]:s,d=r?r[1]*s+r[5]*m+r[9]*c+r[13]:m,a=r?r[2]*s+r[6]*m+r[10]*c+r[14]:c,u=Math.hypot((e[0]||0)-o,(e[1]||0)-d,(e[2]||0)-a);if(i.lastDistance=u,i.forcedLevelIndex!==void 0&&i.forcedLevelIndex!==null){i.activeLevelIndex!==i.forcedLevelIndex&&(i.activeLevelIndex=i.forcedLevelIndex,this.applyGroupVisibility(i,i.forcedLevelIndex));continue}let l=Je(i.distances,u,i.activeLevelIndex,i.hysteresis,i.cullDistance);l!==i.activeLevelIndex&&(i.activeLevelIndex=l,this.applyGroupVisibility(i,l))}}applyGroupVisibility(e,t){let r=this.gltf?.nodes;for(let i=0;i<e.levelMeshes.length;i++){let n=i===t;for(let c of e.levelMeshes[i])c.visible=n;let s=e.childNodeIndices[i],m=Array.isArray(r)?r[s]:null;m&&typeof m=="object"&&(m.visible=n,m.extensions=m.extensions||{},m.extensions.KHR_node_visibility={visible:n})}}},Tt={name:"lod",onRegister(){lr(Ue);let e=ye(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);Ue(t,e)},onLoadModel(e,t){!e||typeof e!="object"||Ne.set(e,new St(e,t))},onUpdate(e){let t=Ne.get(e);if(!t||typeof e?.getCameraOrbit!="function")return;let r=e.getCameraOrbit(),i=typeof e.getCameraTarget=="function"?e.getCameraTarget():{x:0,y:0,z:0},n=r?.radius??3,s=r?.phi??0,m=r?.theta??0,c=Math.cos(s),o=(i.x||0)+n*c*Math.sin(m),d=(i.y||0)+n*Math.sin(s),a=(i.z||0)+n*c*Math.cos(m);t.update([o,d,a])},onBeforeDrawScene(e,t,r,i){let n=Ne.get(e);n&&n.update(i)},onDestroy(e,t){t&&typeof t=="object"&&Ne.delete(t)}},Ie=new Map,ke=new WeakMap;function Er(e,t){Ie.set(e,t)}var Nt={name:"materials",onContextRestored(e){ke.delete(e)},onBuildPrimitiveVAO(e,t,r,i,n){return(((i?.materials&&r.material!==void 0?i.materials[r.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let r=ke.get(e);r||(r=e.createTexture(),ke.set(e,r));let i=Math.max(1,t.canvas.width),n=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,r),e.copyTexImage2D(3553,0,6408,0,0,i,n,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,r,i){if(!t)return null;if(t.name&&Ie.has(t.name)){let f=Ie.get(t.name);return{vs:f.vs||r,fs:f.fs||i}}let n=t.extensions||{},s=n.KHR_materials_clearcoat,m=n.KHR_materials_sheen,c=!!n.KHR_materials_transmission,o=!!n.KHR_materials_ior,d=n.KHR_materials_iridescence;if(!s&&!m&&!n.KHR_materials_unlit&&!c&&!n.KHR_materials_volume&&!o&&!n.KHR_materials_dispersion&&!d)return null;if(n.KHR_materials_unlit)return{vs:r,fs:i.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let a=i;if(c){let f=a.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
|
|
32
|
-
`;
|
|
33
|
-
${
|
|
34
|
-
vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${
|
|
31
|
+
}`),{vs:r,fs:a}},onBeforeDrawPrimitive(e,t,r,i,a,n){let f=rt.get(e),c=e.getUniformLocation(t,"uHasSH");if(f&&f.length>=27){c&&e.uniform1i(c,1);let s=e.getUniformLocation(t,"uSH");s&&e.uniform3fv(s,f)}else c&&e.uniform1i(c,0)},onAttributeChanged(e,t,r,i){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,i):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,i)}},at=new WeakMap;function nt(e,t){let r=t||e.viewer;if(!r||typeof r.projectPointToScreen!="function")return;let i=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let a=0;a<i.length;a++){let n=i[a],f=n.getAttribute("data-position");if(!f)continue;let c=f.trim().split(/\s+/).map(l=>parseFloat(l.replace(/m$/,"")));if(c.length<3||c.some(isNaN))continue;let s=n.getAttribute("data-normal"),d;if(s){let l=s.trim().split(/\s+/).map(u=>parseFloat(u));l.length>=3&&!l.some(isNaN)&&(d=[l[0],l[1],l[2]])}let o=r.projectPointToScreen([c[0],c[1],c[2]],d);n.style.position="absolute",n.style.left="0",n.style.top="0",n.style.transform=`translate(-50%, -50%) translate3d(${o.x}px, ${o.y}px, 0)`,n.style.zIndex="3",o.visible?(n.style.opacity="1",n.style.pointerEvents="auto",n.removeAttribute("data-occluded")):(n.style.opacity="0",n.style.pointerEvents="none",n.setAttribute("data-occluded",""))}}var Tt={name:"hotspots",updateHotspotsForElement:nt,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{nt(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),at.set(e,t)},onCameraChange(e,t){t&&nt(t,e)},onElementDisconnected(e){let t=at.get(e);t&&(t.disconnect(),at.delete(e))}};function xe(e,t,r,i){let a=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.max(t,Math.min(r,a))}function Kr(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function ot(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function qr(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function Xr(e){let t=ot(e);if(!t)return null;let r=t.target;return{target:Kr(r)?[r[0],r[1],r[2]]:typeof r=="string"&&r.length>0&&r.length<=256?r:[0,0,0],radius:xe(t.radius,.01,50,.5),speed:xe(t.speed,-20,20,.5),height:xe(t.height,-10,10,0),phase:xe(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}var Zr=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],Qr=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Ji=new Set(Zr),ea=new Set(Qr);function _t(e,t){let r=qr(e,16)?.trim();if(!r)return t;let i=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(r);return i?`#${i[1].toLowerCase()}`:t}function Et(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:ot(e);if(!t||t.enabled===!1)return null;let r=xe(t.strength??t.intensity,0,5,.35);return r>0?{enabled:!0,strength:r,threshold:xe(t.threshold,0,4,.8),radius:xe(t.radius,0,2,.5)}:null}function lt(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:ot(e);if(!t||t.enabled===!1)return null;let r=t.thickness??t.width;return{enabled:!0,color:_t(t.color,"#38bdf8"),thickness:xe(typeof r=="number"&&r>0&&r<.25?Math.max(1.5,r*140):r,.5,20,3),pulse:t.pulse===!0}}function Yr(e,t,r,i){let a=t[0],n=t[1],f=t[2],c=t[3],s=r[0],d=r[1],o=r[2],l=r[3],u=a*s+n*d+f*o+c*l;if(u<0&&(s=-s,d=-d,o=-o,l=-l,u=-u),Math.abs(u)>=1)return e[0]=a,e[1]=n,e[2]=f,e[3]=c,e;let m=Math.acos(u),h=Math.sqrt(1-u*u);if(Math.abs(h)<.001)return e[0]=.5*(a+s),e[1]=.5*(n+d),e[2]=.5*(f+o),e[3]=.5*(c+l),e;let p=Math.sin((1-i)*m)/h,b=Math.sin(i*m)/h;return e[0]=a*p+s*b,e[1]=n*p+d*b,e[2]=f*p+o*b,e[3]=c*p+l*b,e}var Vt=1024,st=256,He=2048,Jr=128,ei=64,ti=16,ri=1e4,ii=8,pe=new Set(["__proto__","constructor","prototype"]),Ct={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},Rt={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},je={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Ge=(e,t)=>e!==null&&typeof e=="object"&&!pe.has(t)&&Object.prototype.hasOwnProperty.call(e,t),oe=e=>Array.isArray(e)?[...e]:e,Dt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Ge(e,"value")?e.value:e,X=(e,t)=>Ge(e.configuration,t)?Dt(e.configuration[t]):void 0,R=(e,t=0)=>{let r=Number(e);return Number.isFinite(r)?r:t},Ne=e=>Math.max(0,Math.min(1,e)),fe=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function We(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let r of e.slice(1).split("/")){let i=r.replace(/~1/g,"/").replace(/~0/g,"~");if(!i||pe.has(i)||pe.has(r))return null;t.push(i)}return{segments:t}}var Pe=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let r=Number(e);return Number.isSafeInteger(r)&&r>=0&&r<t?r:-1},Ft=e=>{let t=R(e[0]),r=R(e[1]),i=R(e[2]),a=R(e[3],1),n=Math.hypot(t,r,i,a);return n>1e-8?[t/n,r/n,i/n,a/n]:[0,0,0,1]},Ut=(e,t,r,i)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*r;if(Array.isArray(e)&&Array.isArray(t)){if(i&&e.length===4&&t.length===4){let a=[0,0,0,1];return Yr(a,Ft(e),Ft(t),r),a}return e.slice(0,t.length).map((a,n)=>a+(t[n]-a)*r)}return r>=.5?t:e},ut=(e,t,r)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((i,a)=>r(R(i),R(t[a]))):Array.isArray(e)?e.map(i=>r(R(i),R(t))):Array.isArray(t)?t.map(i=>r(R(e),R(i))):r(R(e),R(t)),ai=(e,t)=>Array.isArray(e)?e.map(r=>t(R(r))):t(R(e)),kt=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((r,i)=>Math.abs(r-t[i])<=1e-6):e===t,Ot=class{constructor(e,t,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>Vt)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${Vt})`);let a=Array.isArray(r.variables)?r.variables:[];if(a.length>st)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${st})`);let n=Array.isArray(r.declarations)?r.declarations:[],f=Array.isArray(r.events)?r.events:[],c=new Map,s=new Map,d=new Map,o=new Map,l=new Map,u=new Map,m=[],h=[],p=new Map,b=1,y=0,M=0,g=0,v=0,x=!1,P=!1,C=!1;a.forEach((L,w)=>{if(!L||typeof L!="object")return;let _=oe(Dt(L.value));c.set(w,_);let E=L.id??L.name;typeof E=="string"&&E&&!pe.has(E)&&c.set(E,_)}),(t?.nodes||[]).forEach((L,w)=>{for(let _ of L?.children||[])typeof _=="number"&&p.set(_,w)});let F=L=>L.op||typeof L.declaration=="number"&&n[L.declaration]?.op||"",I=(L,w,_)=>{if(pe.has(w))return;let E=s.get(L);E||s.set(L,E=Object.create(null)),E[w]=_},B=(L,w)=>{if(typeof L!="number"&&typeof L!="string"||typeof L=="string"&&pe.has(L)||!c.has(L)&&c.size>=st*2)return;let _=oe(w);if(c.set(L,_),typeof L=="number"){let E=a[L]?.id??a[L]?.name;typeof E=="string"&&!pe.has(E)&&c.set(E,_)}},U=L=>typeof L=="number"?f[L]?.id??String(L):typeof L=="string"?/^\d+$/.test(L)&&f[Number(L)]?.id?f[Number(L)].id:L:"",V=(L,w)=>{for(let _=L,E=0;_!==void 0&&_>=0&&E<128;_=p.get(_),E++)if(_===w)return!0;return!1},k=L=>{for(let w=m.length-1;w>=0;w--)m[w].key===L&&m.splice(w,1)},O=L=>{k(L.key),m.length>=Jr&&m.shift(),m.push(L)},ee=L=>{let w=We(L)?.segments;if(w){if(w[0]==="nodes"&&Array.isArray(t?.nodes)){let _=t.nodes[Pe(w[1],t.nodes.length)];if(!_)return;let E=w[2];if(E in je){let N=je[E],S=_[E]||N;return N.map((A,T)=>R(S[T],A))}if(E==="weights"){let N=Array.isArray(_.weights)?_.weights:[0],S=w.length===4?Pe(w[3],64):-2;return S===-2?N.map(A=>R(A)):S>=0?R(N[S]):void 0}if(E==="visible"||E==="extensions"&&w[3]==="KHR_node_visibility"&&w[4]==="visible")return _.extensions?.KHR_node_visibility?.visible??_.visible??!0}else if(w[0]==="materials"&&Array.isArray(t?.materials)){let _=t.materials[Pe(w[1],t.materials.length)];if(!_)return;let E=_.pbrMetallicRoughness||{};if(w[2]==="pbrMetallicRoughness"){if(w[3]==="baseColorFactor"){let N=E.baseColorFactor||[1,1,1,1];return[R(N[0],1),R(N[1],1),R(N[2],1),R(N[3],1)]}if(w[3]==="metallicFactor"||w[3]==="roughnessFactor")return R(E[w[3]],1)}if(w[2]==="emissiveFactor"){let N=_.emissiveFactor||[0,0,0];return[R(N[0]),R(N[1]),R(N[2])]}if(w[2]==="alphaCutoff")return R(_.alphaCutoff,.5)}}},J=(L,w)=>{let _=We(L)?.segments;if(!_)return!1;if(_[0]==="nodes"&&Array.isArray(t?.nodes)){let E=Pe(_[1],t.nodes.length),N=t.nodes[E];if(!N)return!1;let S=_[2];if(S in je&&Array.isArray(w)){let A=je[S];if(w.length<A.length)return!1;let T=A.map((H,W)=>R(w[W],H));if(S==="rotation"){let H=Math.hypot(...T);T=H>1e-8?T.map(W=>W/H):[0,0,0,1]}N[S]=T,delete N.matrix;let $=e?.initialNodeTransforms?.[E];return $&&($[S[0]]=[...T]),x=!0,!0}if(S==="weights"){Array.isArray(N.weights)||(N.weights=[]);let A=(T,$)=>{for(let H of e?.meshes||[])if(H.nodeIndex===E)for(let W of H.primitives||[])W.pluginData?.morph?.weights&&(W.pluginData.morph.weights[T]=$)};if(_.length===4){let T=Pe(_[3],64);if(T<0)return!1;A(T,N.weights[T]=R(w))}else if(Array.isArray(w))N.weights=w.slice(0,64).map(T=>R(T)),N.weights.forEach((T,$)=>A($,T));else return!1;return C=!0,!0}if(S==="visible"||S==="extensions"&&_[3]==="KHR_node_visibility"&&_[4]==="visible"){let A=fe(w);return N.visible=A,(!N.extensions||typeof N.extensions!="object")&&(N.extensions={}),N.extensions.KHR_node_visibility={visible:A},P=!0,!0}}else if(_[0]==="materials"&&Array.isArray(t?.materials)){let E=Pe(_[1],t.materials.length),N=t.materials[E];if(!N)return!1;let S=N.pbrMetallicRoughness||(N.pbrMetallicRoughness={}),A=T=>{for(let $ of e?.meshes||[])for(let H of $.primitives||[])(H.materialIndex??0)===E&&T(H)};if(_[2]==="pbrMetallicRoughness"){if(_[3]==="baseColorFactor"&&Array.isArray(w)&&w.length>=3){let T=[Ne(R(w[0],1)),Ne(R(w[1],1)),Ne(R(w[2],1)),w[3]!==void 0?Ne(R(w[3],1)):S.baseColorFactor?.[3]??1];return S.baseColorFactor=T,A($=>$.baseColor=[...T]),C=!0}if(_[3]==="metallicFactor"||_[3]==="roughnessFactor"){let T=_[3]==="metallicFactor",$=Ne(R(w,T?0:.5));return S[_[3]]=$,A(H=>H[T?"metallic":"roughness"]=$),C=!0}}if(_[2]==="emissiveFactor"&&Array.isArray(w)&&w.length>=3)return N.emissiveFactor=[0,1,2].map(T=>Math.max(0,R(w[T]))),C=!0;if(_[2]==="alphaCutoff")return N.alphaCutoff=Ne(R(w,.5)),C=!0}return!1},q=(L,w,_=new Set)=>{let E=X(w,"pointer");if(typeof E!="string"||!E.startsWith("/"))return null;let N=E.replace(/\{([a-zA-Z0-9_]+)\}/g,(S,A)=>{let T=Math.trunc(Number(re(L,A,void 0,_)??X(w,A)));return Number.isSafeInteger(T)&&T>=0?String(T):"-1"});return We(N)?N:null},re=(L,w,_,E)=>{let N=i[L]?.values;if(!Ge(N,w))return _;let S=N[w];if(S==null)return _;if(typeof S!="object"||Array.isArray(S))return oe(S);let A=S;return typeof A.node=="number"?Ve(A.node,A.socket||"value",E):Ge(A,"value")?oe(A.value):_},Ve=(L,w,_)=>{if(L<0||L>=i.length||_.has(L)||_.size>128||++g>ri)return;let E=i[L],N=F(E);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(N))return oe(s.get(L)?.[w]);_.add(L);try{let S=(A,T=0)=>re(L,A,T,_);if(N==="variable/get"){let A=X(E,"variable")??X(E,"id");return typeof A=="number"||typeof A=="string"?oe(c.get(A)):void 0}if(N==="pointer/get"){let A=q(L,E,_);return A?ee(A):void 0}if(N.startsWith("math/")){let A=N.slice(5);if(A in Ct)return ai(S("a"),Ct[A]);if(A in Rt){let T=/^(mul|div|rem|mod|pow)$/.test(A)?1:0;return ut(S("a",A==="mul"?1:0),S("b",T),Rt[A])}if(A==="pi")return Math.PI;if(A==="e")return Math.E;if(A==="random")return Math.random();if(A==="clamp")return ut(ut(S("a"),S("b",S("min",0)),Math.max),S("c",S("max",1)),Math.min);if(A==="mix"||A==="quatSlerp")return Ut(S("a",0),S("b",1),R(S("c",S("t",.5)),.5),A==="quatSlerp");if(A==="dot"){let T=S("a"),$=S("b");return Array.isArray(T)&&Array.isArray($)?T.reduce((H,W,D)=>H+(W||0)*($[D]||0),0):R(T)*R($)}if(A==="cross"){let T=S("a",[0,0,0]),$=S("b",[0,0,0]);return Array.isArray(T)&&Array.isArray($)?[(T[1]||0)*($[2]||0)-(T[2]||0)*($[1]||0),(T[2]||0)*($[0]||0)-(T[0]||0)*($[2]||0),(T[0]||0)*($[1]||0)-(T[1]||0)*($[0]||0)]:[0,0,0]}if(A==="length"){let T=S("a");return Array.isArray(T)?Math.hypot(...T):Math.abs(R(T))}if(A==="distance"){let T=S("a"),$=S("b");return Array.isArray(T)&&Array.isArray($)?Math.hypot(...T.map((H,W)=>(H||0)-($[W]||0))):Math.abs(R(T)-R($))}if(A==="normalize"){let T=S("a");if(!Array.isArray(T))return R(T)>=0?1:-1;let $=Math.hypot(...T);return $>1e-8?T.map(H=>H/$):T.map(()=>0)}if(A.startsWith("combine"))return["a","b","c","d"].slice(0,Number(A[7])||2).map(T=>R(S(T)));if(A.startsWith("extract")){let T=S("a");return Array.isArray(T)?T[w==="0"||w==="x"?0:w==="1"||w==="y"?1:w==="2"||w==="z"?2:3]??0:0}if(A==="eq")return kt(S("a"),S("b"));if(A==="ne")return!kt(S("a"),S("b"));if(A==="lt")return R(S("a"))<R(S("b"));if(A==="le")return R(S("a"))<=R(S("b"));if(A==="gt")return R(S("a"))>R(S("b"));if(A==="ge")return R(S("a"))>=R(S("b"));if(A==="isNaN")return Number.isNaN(Number(S("a")));if(A==="isInf"){let T=Number(S("a"));return!Number.isFinite(T)&&!Number.isNaN(T)}return A==="and"?fe(S("a",!1))&&fe(S("b",!1)):A==="or"?fe(S("a",!1))||fe(S("b",!1)):A==="xor"?fe(S("a",!1))!==fe(S("b",!1)):A==="not"?!fe(S("a",!1)):A==="select"?oe(fe(S("condition",!1))?S("a"):S("b")):void 0}return N==="type/boolToInt"||N==="type/boolToFloat"?fe(S("a",!1))?1:0:N==="type/intToBool"||N==="type/floatToBool"?R(S("a",0))!==0:N==="type/intToFloat"?R(S("a",0)):N==="type/floatToInt"?Math.trunc(R(S("a",0))):void 0}finally{_.delete(L)}},Me=()=>{if(x){x=!1,C=!0;let L=At(t);if(e){e.worldMatrices=L;for(let w of e.meshes||[])w.nodeIndex>=0&&w.nodeIndex<L.length&&(w.transform.set(L[w.nodeIndex]),$e(w.normalMatrix,w.transform))}}if(P){P=!1,C=!0;let L=t?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(L))for(let w of e.meshes){let _=!0;for(let E=w.nodeIndex,N=0;E!==void 0&&E>=0&&N<128;E=p.get(E),N++){let S=L[E];if(S?.visible===!1||S?.extensions?.KHR_node_visibility?.visible===!1){_=!1;break}}w.visible=_}}C&&(C=!1,e?.render?.())},Z=(L,w={steps:0})=>{if(!L||typeof L.node!="number")return;w.steps===0&&(g=0);let _=[L],E=N=>{_.length+w.steps<He&&_.push(N)};for(;_.length>0&&w.steps<He;){w.steps++;let N=_.shift();if(!N||N.node<0||N.node>=i.length)continue;let S=N.node,A=i[S];if(!A)continue;let T=N.socket||"in",$=F(A),H=(D,z=void 0)=>re(S,D,z,new Set),W=(D="out")=>{let z=A.flows?.[D];z&&E(z)};switch($){case"flow/branch":W(fe(H("condition",!1))?"true":"false");break;case"flow/sequence":for(let D of Object.keys(A.flows||{}).sort((z,Y)=>Number(z)-Number(Y)||z.localeCompare(Y)))W(D);break;case"flow/switch":{let D=A.flows?.[String(H("selection",H("value",0)))]??A.flows?.default;D&&E(D);break}case"flow/for":{let D=Math.trunc(R(H("startIndex",0))),z=Math.trunc(R(H("endIndex",0))),Y=Math.max(1,Math.trunc(R(H("step",1),1))),te=A.flows?.body;if(te&&z>D&&v<ii){let G=Math.min(Math.ceil((z-D)/Y),He);v++;try{for(let ae=0;ae<G&&w.steps<He;ae++)I(S,"index",D+ae*Y),Z(te,w)}finally{v--}}let we=A.flows?.completed??A.flows?.out;we&&E(we);break}case"flow/doN":{let D=T==="reset"?0:(d.get(S)||0)+1;if(d.set(S,D),I(S,"currentCount",D),I(S,"count",D),T!=="reset"){let z=Math.trunc(R(H("n",X(A,"stopIterations")??X(A,"n")??1),1));D<=z&&W()}break}case"flow/multiGate":{if(T==="reset"){u.set(S,0);break}let D=Object.keys(A.flows||{}).sort();if(!D.length)break;let z=X(A,"isRandom")?Math.floor(Math.random()*D.length):u.get(S)||0;z<D.length&&(W(D[z]),u.set(S,X(A,"isLoop")!==!1?(z+1)%D.length:z+1));break}case"flow/waitAll":{if(T==="reset"){o.delete(S);break}let D=o.get(S);D||o.set(S,D=new Set),D.add(T),D.size>=Math.max(1,Math.trunc(Number(X(A,"inputFlows")??2)||2))&&(D.clear(),W("out"),W("completed"));break}case"flow/throttle":{if(T==="reset"){l.delete(S);break}let D=Math.max(0,R(H("duration",0))),z=l.get(S);z===void 0||y-z>=D?(l.set(S,y),I(S,"lastRemainingTime",0),W()):I(S,"lastRemainingTime",Math.max(0,D-(y-z)));break}case"flow/delay":case"flow/setDelay":{if(T==="cancel"){for(let te=h.length-1;te>=0;te--)h[te].nodeIdx===S&&h.splice(te,1);I(S,"lastDelayIndex",-1);break}let D=Math.max(0,R(H("duration",X(A,"duration")??0))),z=A.flows?.done??A.flows?.out;if(D<=0){I(S,"lastDelayIndex",-1),z&&E(z);break}h.length>=ei&&h.shift();let Y=b++;I(S,"lastDelayIndex",Y),h.push({id:Y,nodeIdx:S,rem:D,done:z}),$==="flow/setDelay"&&A.flows?.out&&A.flows?.done&&W("out");break}case"flow/cancelDelay":{let D=Math.trunc(R(H("delayIndex",-1),-1));if(D<0)h.length=0;else for(let z=h.length-1;z>=0;z--)h[z].id===D&&h.splice(z,1);W();break}case"variable/set":B(X(A,"variable")??X(A,"id"),H("value")),W();break;case"variable/interpolate":{let D=X(A,"variable")??X(A,"id"),z=H("value",H("target")),Y=Math.max(0,R(H("duration",X(A,"duration")??.3),.3));D!==void 0&&z!==void 0&&O({key:`var:${String(D)}`,varKey:D,from:oe(H("from")??c.get(D)??0),to:oe(z),dur:Y,elapsed:0,quat:!1,linear:X(A,"easing")==="linear",done:A.flows?.done}),W();break}case"pointer/set":{let D=q(S,A),z=H("value");D&&z!==void 0&&(k(`ptr:${D}`),J(D,z)),W();break}case"pointer/interpolate":{let D=q(S,A),z=H("value",H("target")),Y=Math.max(0,R(H("duration",X(A,"duration")??.3),.3));if(D&&z!==void 0){let te=H("from")??ee(D);te!==void 0&&(Y<=0?(J(D,z),W("done")):O({key:`ptr:${D}`,ptr:D,from:oe(te),to:oe(z),dur:Y,elapsed:0,quat:D.endsWith("/rotation"),linear:X(A,"easing")==="linear",done:A.flows?.done}))}W();break}case"animation/start":{let D=H("animation")??X(A,"animation")??X(A,"clipName"),z=typeof D=="number"?e?.animations?.[D]?.name??t?.animations?.[D]?.name:typeof D=="string"?D:void 0;e?.playAnimation?.(z),C=!0,W();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),$==="animation/resetAt"&&e?.evaluateAnimation?.(R(H("time",0))),C=!0,W();break;case"event/send":case"customEvent/send":{let D=U(X(A,"event")??X(A,"id")),z={};for(let Y of Object.keys(A.values||{}))pe.has(Y)||(z[Y]=H(Y));D&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:D,values:z}})),Q(D,z,w)),W();break}default:W();break}}};this.readScenePointer=ee,this.writeScenePointer=J,this.fireOnStart=()=>{i.forEach(L=>{F(L)==="event/onStart"&&Z(L.flows?.out)}),Me()},this.fireOnSelect=L=>{if(!L)return;let w=typeof L.meshIndex=="number"?L.meshIndex:-1,_=typeof L.nodeIndex=="number"?L.nodeIndex:e?.meshes?.[w]?.nodeIndex??-1;i.forEach((E,N)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(F(E)))return;let S=X(E,"nodeIndex")??X(E,"node")??re(N,"nodeIndex",void 0,new Set),A=X(E,"meshName");if(typeof A=="string"&&A?L.meshName===A:S==null||Number(S)<0||Number.isNaN(Number(S))||V(_,Math.trunc(Number(S)))){if(I(N,"nodeIndex",_),I(N,"meshIndex",w),Array.isArray(L.hitPoint)){let T=[R(L.hitPoint[0]),R(L.hitPoint[1]),R(L.hitPoint[2])];I(N,"hitPoint",T),I(N,"point",T),I(N,"intersectionPoint",T)}if(Array.isArray(L.normal)){let T=[R(L.normal[0]),R(L.normal[1],1),R(L.normal[2])];I(N,"normal",T),I(N,"hitNormal",T)}typeof L.distance=="number"&&I(N,"distance",L.distance),Z(E.flows?.out)}}),Me()},this.receiveCustomEvent=(L,w={})=>Q(L,w,{steps:0});function Q(L,w,_){if(!(M>=ti)){M++;try{let E=U(L);i.forEach((N,S)=>{if(!/^(customE|e)vent\/receive$/.test(F(N)))return;let A=X(N,"event")??X(N,"id");if(!(U(A)!==E&&String(A)!==String(L))){for(let[T,$]of Object.entries(w))pe.has(T)||I(S,T,oe($));Z(N.flows?.out,_)}}),Me()}finally{M--}}}this.tick=L=>{if(!Number.isFinite(L)||L<0)return;let w=Math.min(L,.25);y+=w,i.forEach((E,N)=>{F(E)==="event/onTick"&&(I(N,"timeDelta",w),I(N,"dt",w),I(N,"timeElapsed",y),Z(E.flows?.out))});let _=[];for(let E=m.length-1;E>=0;E--){let N=m[E];N.elapsed+=w;let S=N.dur>1e-6?Ne(N.elapsed/N.dur):1,A=N.linear?S:S*S*(3-2*S),T=Ut(N.from,N.to,A,N.quat);N.ptr?J(N.ptr,T):N.varKey!==void 0&&B(N.varKey,T),S>=1&&(m.splice(E,1),N.done&&_.push(N.done))}for(let E=h.length-1;E>=0;E--){let N=h[E];N.rem-=w,N.rem<=0&&(h.splice(E,1),N.done&&_.push(N.done))}for(let E of _)Z(E);Me()},this.dispose=()=>{m.length=0,h.length=0,c.clear(),s.clear(),d.clear(),o.clear(),l.clear(),u.clear()}}},he=new WeakMap,Ke=new WeakMap;function ni(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||Br().some(c=>c.name==="xr-live-head-follow")||(typeof e.getAutoRotate=="function"?e.getAutoRotate():e.autoRotate)===!1)return;let r=e.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return;let a=Math.min(t,.1),n=(Ke.get(e)||0)+a,f=!1;for(let c=0;c<i.length;c++){let s=i[c],d=Xr(s?.extras?.xr?.orbit);if(!d)continue;let o=0,l=0,u=0;if(Array.isArray(d.target))o=d.target[0],l=d.target[1],u=d.target[2];else if(typeof d.target=="string"&&d.target!=="head"){let y=i.find(M=>M?.name===d.target);Array.isArray(y?.translation)&&(o=R(y.translation[0]),l=R(y.translation[1]),u=R(y.translation[2]))}let m=d.phase+d.speed*n,h=o+Math.cos(m)*d.radius,p=l+d.height,b=u+Math.sin(m)*d.radius;if(s.translation=[h,p,b],d.faceCenter){let y=Math.atan2(o-h,u-b);s.rotation=[0,Math.sin(y*.5),0,Math.cos(y*.5)]}f=!0}if(f){Ke.set(e,n);let c=At(r);e.worldMatrices=c;for(let s of e.meshes||[])s.nodeIndex>=0&&s.nodeIndex<c.length&&(s.transform.set(c[s.nodeIndex]),$e(s.normalMatrix,s.transform))}}function ft(e){if(!(!e||typeof e!="object"))return he.get(e)||he.get(e.viewer)||he.get(e._view)}function Bt(e,t,r){let i=ft(e);return i?(i.receiveCustomEvent(t,r),!0):!1}var zt={name:"khr-interactivity",sendInteractivityEvent:Bt,getInteractivityVM:ft,onLoadModel(e,t){if(!e||typeof e!="object")return;he.get(e)?.dispose(),he.delete(e),Ke.delete(e);let r=t?.extensions?.KHR_interactivity,i=Array.isArray(r?.graphs)?r.graphs[r.graph??0]:r;if(!i||!Array.isArray(i.nodes))return;let a=new Ot(e,t,i);he.set(e,a),a.fireOnStart()},onMeshSelect(e,t){he.get(e)?.fireOnSelect(t)},onUpdate(e,t){he.get(e)?.tick(t),ni(e,t)},onDestroy(e,t){he.get(t)?.dispose(),he.delete(t),Ke.delete(t)}};function qe(e,t){let r=(o,l,u,m)=>{let h=typeof o=="number"?o:Number(o);return Number.isFinite(h)?Math.max(l,Math.min(u,h)):m};function i(o,l,u=0,m=.05,h){if(!o||!o.length)return-1;let p=o[0]>0?[0,...o]:o,b=Number.isFinite(l)?Math.max(0,l):0,y=Number.isFinite(m)?Math.max(0,Math.min(.5,m)):.05;if(typeof h=="number"&&Number.isFinite(h)&&h>0){let v=u===-1?h*(1-y):h*(1+y);if(b>v)return-1}let M=0;for(let v=p.length-1;v>=1;v--)if(b>=p[v]){M=v;break}if(u<0||u>=p.length||u===M)return M;if(M>u){let v=u;for(let x=u+1;x<=M&&b>=p[x]*(1+y);x++)v=x;return v}let g=u;for(let v=u;v>M&&b<p[v]*(1-y);v--)g=v-1;return g}function a(o){if(!o)return null;let l=o===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(o)?{distances:o}:typeof o=="object"?o:null;if(!l||l.enabled===!1)return null;let u=r(l.hysteresis,0,.5,.05),m=[],h;if(Array.isArray(l.levels)&&l.levels.length>0){let M=l.levels.slice(0,8);for(let v=0;v<M.length;v++){let x=M[v];if(!x||typeof x!="object"||Array.isArray(x))continue;let P=x,C=r(P.distance,0,1e4,v===0?0:v*4),F=typeof P.hysteresis=="number"?r(P.hysteresis,0,.5,u):void 0,I=typeof P.ratio=="number"?r(P.ratio,.05,1,.5):void 0,B=typeof P.childIndex=="number"&&Number.isFinite(P.childIndex)?Math.max(0,Math.round(P.childIndex)):void 0,U=typeof P.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(P.node.trim())?P.node.trim().slice(0,64):void 0;m.push({distance:C,...F!==void 0?{hysteresis:F}:{},...I!==void 0?{ratio:I}:{},...B!==void 0?{childIndex:B}:{},...U?{node:U}:{}})}m.sort((v,x)=>v.distance-x.distance),m.length>0&&m[0].distance>0&&m.unshift({distance:0,childIndex:0});let g=0;m=m.slice(0,8).map((v,x)=>{let P=x===0?0:Math.max(g,v.distance);return g=P,{...v,distance:P,childIndex:v.childIndex??x}})}if(Array.isArray(l.ratios)&&l.ratios.length>0){let M=[];for(let g of l.ratios.slice(0,7))typeof g=="number"&&M.push(r(g,.05,1,.5));M.length>0&&(h=M)}if(m.length===0){let M=Array.isArray(l.distances)?l.distances:[],g=[];for(let x of M.slice(0,8))typeof x=="number"&&g.push(r(x,0,1e4,4));if(g.length===0&&h&&h.length>0)for(let x=0;x<h.length;x++)g.push((x+1)*4);if(g.length===0&&l.cullDistance===void 0)return null;g.length===0||g[0]>0?g.unshift(0):h&&h.length===g.length&&h[0]===1&&(h=h.slice(1));let v=0;for(let x=0;x<Math.min(8,g.length);x++){let P=x===0?0:Math.max(v,g[x]);v=P;let C=x>0&&h?h[x-1]:void 0;m.push({distance:P,childIndex:x,...C!==void 0?{ratio:C}:{}})}}else if(!h){let M=[];for(let g=1;g<m.length;g++)typeof m[g].ratio=="number"&&M.push(m[g].ratio);M.length>0&&(h=M)}let p=m.map(M=>M.distance),b=p[p.length-1]??0,y=l.cullDistance!==void 0&&l.cullDistance!==null&&l.cullDistance!==!1?r(l.cullDistance,Math.max(1,b),1e4,100):void 0;return{levels:m,distances:p,...h?{ratios:h}:{},hysteresis:u,...y!==void 0?{cullDistance:y}:{}}}function n(o,l){let u=o?.attributes?.position;if(!u||!u.array||u.count<3)return o;let m=r(l,.05,1,.5),h=u.array,p=u.count,b=o.attributes?.normal?.array,y=o.attributes?.uv?.array,M=o.index?.array,g=Math.floor((M?M.length:p)/3);if(g<1)return o;let v=Math.max(1,Math.min(g,Math.round(g*m))),x=1/0,P=1/0,C=1/0,F=-1/0,I=-1/0,B=-1/0;for(let w=0;w<p;w++){let _=h[w*3],E=h[w*3+1],N=h[w*3+2];_<x&&(x=_),E<P&&(P=E),N<C&&(C=N),_>F&&(F=_),E>I&&(I=E),N>B&&(B=N)}let U=Math.max(1e-5,F-x),V=Math.max(1e-5,I-P),k=Math.max(1e-5,B-C),O=Math.max(U,V,k),ee=w=>{let _=Math.max(1,Math.round(U/O*w)),E=Math.max(1,Math.round(V/O*w)),N=Math.max(1,Math.round(k/O*w)),S=new Map,A=new Int32Array(p),T=[],$=[],H=[],W=[];for(let G=0;G<p;G++){let ae=h[G*3],Se=h[G*3+1],Ae=h[G*3+2],ce=Math.min(_-1,Math.max(0,Math.floor((ae-x)/U*_))),le=Math.min(E-1,Math.max(0,Math.floor((Se-P)/V*E))),Ie=Math.min(N-1,Math.max(0,Math.floor((Ae-C)/k*N))),Be=ce+le*_+Ie*_*E,ie=S.get(Be);ie===void 0?(ie=W.length,S.set(Be,ie),T.push(ae,Se,Ae),b&&$.push(b[G*3],b[G*3+1],b[G*3+2]),y&&H.push(y[G*2],y[G*2+1]),W.push(1)):(T[ie*3]+=ae,T[ie*3+1]+=Se,T[ie*3+2]+=Ae,b&&($[ie*3]+=b[G*3],$[ie*3+1]+=b[G*3+1],$[ie*3+2]+=b[G*3+2]),W[ie]++),A[G]=ie}let D=[],z=new Set;for(let G=0;G<g;G++){let ae=M?M[G*3]:G*3,Se=M?M[G*3+1]:G*3+1,Ae=M?M[G*3+2]:G*3+2,ce=A[ae],le=A[Se],Ie=A[Ae];if(ce===le||le===Ie||Ie===ce)continue;let Be=Math.min(ce,le,Ie),ie=Math.max(ce,le,Ie),Qi=ce+le+Ie-Be-ie,Vr=`${Be}_${Qi}_${ie}`;z.has(Vr)||(z.add(Vr),D.push(ce,le,Ie))}let Y=W.length,te=new Float32Array(Y*3),we=b?new Float32Array(Y*3):null;for(let G=0;G<Y;G++){let ae=1/W[G];if(te[G*3]=T[G*3]*ae,te[G*3+1]=T[G*3+1]*ae,te[G*3+2]=T[G*3+2]*ae,we){let Se=$[G*3],Ae=$[G*3+1],ce=$[G*3+2],le=Math.hypot(Se,Ae,ce)||1;we[G*3]=Se/le,we[G*3+1]=Ae/le,we[G*3+2]=ce/le}}return{pos:te,norm:we,uv:y?new Float32Array(H):null,tris:D,triCount:D.length/3,vertCount:Y}},J=Math.max(2,Math.round(Math.sqrt(v/4))),q=ee(J);if(q.triCount>v*1.25&&J>2){let w=Math.max(2,Math.round(J*Math.sqrt(v/q.triCount)));if(w!==J){let _=ee(w);_.triCount>=Math.min(4,v)&&(q=_)}}else if(q.triCount<Math.min(4,v)){let w=ee(Math.max(J*2,8));w.triCount>q.triCount&&(q=w)}let re=q.tris;if(m<1&&q.triCount>v){let w=[],_=q.triCount/v;for(let E=0;E<v;E++){let N=Math.min(q.triCount-1,Math.floor(E*_));w.push(q.tris[N*3],q.tris[N*3+1],q.tris[N*3+2])}re=w}if(re.length<3){re=[];for(let w=0;w<v*3;w++)re.push(M?M[w]:w);q={pos:h.slice(),norm:b?b.slice():null,uv:y?y.slice():null,tris:re,triCount:v,vertCount:p}}let Ve=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),Me=Ve?.BufferGeometry??o.constructor,Z=Ve?.BufferAttribute??u.constructor,Q=new Me;Q.setAttribute("position",new Z(q.pos,3)),q.norm&&Q.setAttribute("normal",new Z(q.norm,3)),q.uv&&Q.setAttribute("uv",new Z(q.uv,2));let L=q.vertCount>65535?new Uint32Array(re):new Uint16Array(re);return typeof Q.setIndex=="function"?Q.setIndex(new Z(L,1)):Q.index=new Z(L,1),Q}let f=e?.Object3D??t?.threeNamespace?.Object3D??class{constructor(){this.name="",this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0},this.quaternion={x:0,y:0,z:0,w:1},this.scale={x:1,y:1,z:1},this.visible=!0,this.parent=null,this.children=[],this.userData={}}add(...o){for(let l of o)l&&(l.parent=this,this.children.push(l));return this}};class c extends f{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(l,u=0,m=.05){if(!l)return this;let h=Math.max(0,Number.isFinite(Number(u))?Number(u):0),p=r(m,0,.5,.05),b=this.levels.length;for(let g=0;g<this.levels.length;g++)if(h<this.levels[g].distance){b=g;break}this.levels.splice(b,0,{object:l,distance:h,hysteresis:p}),this.add(l);let y=this.levels.map(g=>g.object),M=this.children.filter(g=>!y.includes(g));this.children=[...y,...M];for(let g=0;g<this.levels.length;g++)this.levels[g].object.visible=g===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(l){if(!this.levels.length)return null;let u=i(this.levels.map(m=>m.distance),l,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return u>=0&&u<this.levels.length?this.levels[u].object:null}update(l){if(this.levels.length===0||!l)return;let u=l.position??{x:0,y:0,z:0},m=this.position??{x:0,y:0,z:0},h=Math.hypot((Number(u.x)||0)-(Number(m.x)||0),(Number(u.y)||0)-(Number(m.y)||0),(Number(u.z)||0)-(Number(m.z)||0)),p=i(this.levels.map(b=>b.distance),h,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=p;for(let b=0;b<this.levels.length;b++)this.levels[b].object.visible=b===p}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let l=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((u,m)=>({distance:u.distance,hysteresis:u.hysteresis,childIndex:m,...u.object?.name?{node:u.object.name}:{}})),distances:this.levels.map(u=>u.distance),hysteresis:this.levels[0]?.hysteresis??.05,...l!==void 0?{cullDistance:l}:{}}}}function s(o){if(!o||o._lodMaterialized||!o.userData?.xr?.lod||o.isLOD||Array.isArray(o.children)&&o.children.length>0)return;let l=o.geometry?.attributes?.position;if(!l||!l.array||l.count<3)return;let u=a(o.userData.xr.lod);if(!u||u.levels.length<2)return;o._lodMaterialized=!0;let m=o.geometry;o._lodOriginalGeometry=m;let h=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),p=h?.Mesh??o.constructor,b=h?.BufferGeometry??m.constructor,y=typeof o.name=="string"&&o.name.trim()?o.name.trim():"Mesh",M=new p(m,o.material);M.name=`${y}_LOD0`,M.visible=!0,M.castShadow=!!o.castShadow,M.receiveShadow=!!o.receiveShadow,o.add(M);for(let g=1;g<u.levels.length;g++){let v=u.levels[g].ratio??u.ratios?.[g-1]??Math.max(.05,Math.pow(.5,g)),x=n(m,v),P=new p(x,o.material);P.name=`${y}_LOD${g}`,P.visible=!1,P.castShadow=!!o.castShadow,P.receiveShadow=!!o.receiveShadow,o.add(P)}o.geometry=new b,o.userData.xr.lod={...u,levels:u.levels.map((g,v)=>({...g,childIndex:v,node:`${y}_LOD${v}`}))}}let d={LOD:c,decimateGeometry:n,selectLodLevelIndex:i,parseLod:a,materializeLodGeometry:s};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,{LOD:c,decimateGeometry:n}),t._lodMaterialize=s,t.materializeDeclarativeGeometry=o=>{t._cadMaterialize?.(o),t._lodMaterialize?.(o),t._procMaterialize?.(o)}),d}var Ce=qe(),oi=Ce.decimateGeometry,ct=Ce.selectLodLevelIndex,ht=Ce.parseLod,ta=Ce.materializeLodGeometry,li=Ce.LOD,Re=new WeakMap;function si(e){return e&&typeof e=="object"?Re.get(e):void 0}var $t=class{constructor(e,t){this.groups=[],this.viewer=e,this.gltf=t,this.rebuild()}rebuild(){this.groups.length=0;let e=this.gltf?.nodes;if(!Array.isArray(e)||e.length===0)return;let t=new Map;for(let i of this.viewer?.meshes??[])if(typeof i?.nodeIndex=="number"&&i.nodeIndex>=0){let a=t.get(i.nodeIndex);a||(a=[],t.set(i.nodeIndex,a)),a.push(i)}let r=i=>{let a=[],n=new Set,f=[i];for(;f.length>0;){let c=f.pop();if(n.has(c)||c<0||c>=e.length)continue;n.add(c);let s=t.get(c);s&&a.push(...s);let d=e[c]?.children;if(Array.isArray(d))for(let o=d.length-1;o>=0;o--)typeof d[o]=="number"&&f.push(d[o])}return a};for(let i=0;i<e.length;i++){let a=e[i];if(!a||typeof a!="object")continue;let n=a.extras?.xr?.lod??a.extensions?.ANDROID_xr_scenecore?.lod??a.extensions?.MOZ_hubs_components?.lod,f=Array.isArray(a.extensions?.MSFT_lod?.ids)?a.extensions.MSFT_lod.ids.filter(m=>typeof m=="number"&&Number.isInteger(m)&&m>=0&&m<e.length):[],c=ht(n);if(!c&&f.length>0&&(c=ht({distances:f.map((m,h)=>h*4)})),!c)continue;let s=f.length>0?f:Array.isArray(a.children)?a.children.filter(m=>typeof m=="number"&&Number.isInteger(m)&&m>=0&&m<e.length):[],d=[],o=[];if(s.length>0){let m=Math.min(s.length,c.levels.length);for(let h=0;h<m;h++){let p=s[h];d.push(p),o.push(r(p))}}else{let m=t.get(i)??[];if(m.length===0)continue;d.push(i),o.push(m)}let l=c.distances.slice(0,o.length);l.length===0&&l.push(0);let u={nodeIndex:i,name:typeof a.name=="string"?a.name:`LOD_${i}`,distances:l,hysteresis:c.hysteresis,...c.cullDistance!==void 0?{cullDistance:c.cullDistance}:{},childNodeIndices:d,levelMeshes:o,activeLevelIndex:0,lastDistance:0};this.applyGroupVisibility(u,0),this.groups.push(u)}}getGroups(){return this.groups}getActiveLevel(e){let t=this.findGroup(e);return t?t.activeLevelIndex:null}forceLodLevel(e,t){let r=this.findGroup(e);if(!r)return;if(t==null){r.forcedLevelIndex=null;let a=ct(r.distances,r.lastDistance,r.activeLevelIndex,r.hysteresis,r.cullDistance);r.activeLevelIndex=a,this.applyGroupVisibility(r,a);return}let i=t<0?-1:Math.min(Math.max(0,Math.trunc(t)),r.levelMeshes.length-1);r.forcedLevelIndex=i,r.activeLevelIndex=i,this.applyGroupVisibility(r,i)}findGroup(e){return typeof e=="number"?this.groups.find(t=>t.nodeIndex===e)??this.groups[e]:this.groups.find(t=>t.name===e)}update(e){if(this.groups.length===0)return;let t=this.viewer?.worldMatrices,r=this.viewer?.modelRootMatrix;for(let i of this.groups){let a=Array.isArray(t)&&i.nodeIndex<t.length?t[i.nodeIndex]:null,n=a&&a[12]||0,f=a&&a[13]||0,c=a&&a[14]||0,s=r?r[0]*n+r[4]*f+r[8]*c+r[12]:n,d=r?r[1]*n+r[5]*f+r[9]*c+r[13]:f,o=r?r[2]*n+r[6]*f+r[10]*c+r[14]:c,l=Math.hypot((e[0]||0)-s,(e[1]||0)-d,(e[2]||0)-o);if(i.lastDistance=l,i.forcedLevelIndex!==void 0&&i.forcedLevelIndex!==null){i.activeLevelIndex!==i.forcedLevelIndex&&(i.activeLevelIndex=i.forcedLevelIndex,this.applyGroupVisibility(i,i.forcedLevelIndex));continue}let u=ct(i.distances,l,i.activeLevelIndex,i.hysteresis,i.cullDistance);u!==i.activeLevelIndex&&(i.activeLevelIndex=u,this.applyGroupVisibility(i,u))}}applyGroupVisibility(e,t){let r=this.gltf?.nodes;for(let i=0;i<e.levelMeshes.length;i++){let a=i===t;for(let c of e.levelMeshes[i])c.visible=a;let n=e.childNodeIndices[i],f=Array.isArray(r)?r[n]:null;f&&typeof f=="object"&&(f.visible=a,f.extensions=f.extensions||{},f.extensions.KHR_node_visibility={visible:a})}}},Ht={name:"lod",onRegister(){Or(qe);let e=de(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);qe(t,e)},onLoadModel(e,t){!e||typeof e!="object"||Re.set(e,new $t(e,t))},onUpdate(e){let t=Re.get(e);if(!t||typeof e?.getCameraOrbit!="function")return;let r=e.getCameraOrbit(),i=typeof e.getCameraTarget=="function"?e.getCameraTarget():{x:0,y:0,z:0},a=r?.radius??3,n=r?.phi??0,f=r?.theta??0,c=Math.cos(n),s=(i.x||0)+a*c*Math.sin(f),d=(i.y||0)+a*Math.sin(n),o=(i.z||0)+a*c*Math.cos(f);t.update([s,d,o])},onBeforeDrawScene(e,t,r,i){let a=Re.get(e);a&&a.update(i)},onDestroy(e,t){t&&typeof t=="object"&&Re.delete(t)}},De=new Map,Xe=new WeakMap;function ui(e,t){De.set(e,t)}var jt={name:"materials",onContextRestored(e){Xe.delete(e)},onBuildPrimitiveVAO(e,t,r,i,a){return(((i?.materials&&r.material!==void 0?i.materials[r.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let r=Xe.get(e);r||(r=e.createTexture(),Xe.set(e,r));let i=Math.max(1,t.canvas.width),a=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,r),e.copyTexImage2D(3553,0,6408,0,0,i,a,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,r,i){if(!t)return null;if(t.name&&De.has(t.name)){let h=De.get(t.name);return{vs:h.vs||r,fs:h.fs||i}}let a=t.extensions||{},n=a.KHR_materials_clearcoat,f=a.KHR_materials_sheen,c=!!a.KHR_materials_transmission,s=!!a.KHR_materials_ior,d=a.KHR_materials_iridescence;if(!n&&!f&&!a.KHR_materials_unlit&&!c&&!a.KHR_materials_volume&&!s&&!a.KHR_materials_dispersion&&!d)return null;if(a.KHR_materials_unlit)return{vs:r,fs:i.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let o=i;if(c){let h=o.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
|
|
32
|
+
`;o=o.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
|
|
33
|
+
${h}out vec4 fragColor;`)}let l=(h,p,b=0,y=1e6,M=3)=>{let g=Number(h);return(Number.isFinite(g)?Math.min(y,Math.max(b,g)):p).toFixed(M)},u=Number(a.KHR_materials_ior?.ior??1.5),m=Number.isFinite(u)?Math.min(10,Math.max(1,u)):1.5;if(s){let h=Math.pow((m-1)/(m+1),2);o=o.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${l(h,.04,0,1,4)}),base.rgb,metallic);`)}if(d){let h=l(d.iridescenceFactor,1,0,1),p=l(d.iridescenceIor,1.3,1,10);o=o.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${p}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${h}*pow(1.-NoV,2.));`)}if(c){let h=l(a.KHR_materials_transmission?.transmissionFactor,1,0,1),p=a.KHR_materials_volume||{},b=l(p.thicknessFactor,.5,0,1e4),y=l(p.attenuationDistance,1,.001,1e6),M=Array.isArray(p.attenuationColor)?p.attenuationColor:[1,1,1],g=l(a.KHR_materials_dispersion?.dispersion,0,0,10);o=o.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
34
|
+
vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${l(m,1.5,1,10)},dV=${g},tV=${b},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
|
|
35
35
|
vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
|
|
36
36
|
vec3 tr=vec3(textureLod(uTransmissionTex,clamp(sUV+refractedR.xy*sc,.001,.999),lod).r,textureLod(uTransmissionTex,clamp(sUV+rG.xy*sc,.001,.999),lod).g,textureLod(uTransmissionTex,clamp(sUV+refractedB.xy*sc,.001,.999),lod).b);
|
|
37
|
-
vec3 aCol=vec3(${
|
|
38
|
-
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${
|
|
39
|
-
diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${f});`)}if(s&&!i.includes("uClearcoat")){let f=u(s.clearcoatFactor,1,0,1),g=u(s.clearcoatRoughnessFactor,0,0,1);a=a.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${g},NoV)*${f};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${g})*ccF;fragColor=vec4(color,base.a);`)}if(m){let f=Array.isArray(m.sheenColorFactor)?m.sheenColorFactor:[1,1,1],g=`color+=vec3(${u(f[0],1,0,1)},${u(f[1],1,0,1)},${u(f[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;a.includes("color=applyToneMapping(color,uToneMapping);")?a=a.replace("color=applyToneMapping(color,uToneMapping);",`${g}color=applyToneMapping(color,uToneMapping);`):a=a.replace("fragColor=vec4(color,base.a);",`${g}fragColor=vec4(color,base.a);`)}return{vs:r,fs:a}},onBeforeDrawPrimitive(e,t,r,i,n,s){let m=r.materialIndex;if(m!==void 0&&s?.materials){let c=s.materials[m];c?.name&&Ie.has(c.name)&&Ie.get(c.name).onBindUniforms?.(e,t,r)}if(r.isTransmissive){let c=ke.get(e);if(c){e.activeTexture(33990),e.bindTexture(3553,c);let o=e.getUniformLocation(t,"uTransmissionTex");o&&e.uniform1i(o,6);let d=e.getUniformLocation(t,"uViewportSize");d&&e.uniform2f(d,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}},It=64*1024*1024,Lt=128*1024*1024,Pr=16777216;function _r(e){return(e>>>1^-(e&1))&255}function Vr(e){return(e>>>1^-(e&1))&65535}function Rr(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function Et(e){return(e<<1^e>>31)>>>0}function Pt(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw q(`unknown filter "${String(e)}"`)}var j=Math.fround;function Me(e){return Math.trunc(j(e+(e>=0?.5:-.5)))}function _t(e,t,r,i="NONE"){if(Pt(i),!i||i==="NONE"||t<=0)return;let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(i==="OCTAHEDRAL"){if(r!==4&&r!==8)throw q(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${r})`);let u=r===8,l=u?32767:127,h=A=>u?n.getInt16(A,!0):n.getInt8(A),f=(A,v)=>u?n.setInt16(A,v,!0):n.setInt8(A,v<<24>>24),g=u?2:1;for(let A=0;A<t;A++){let v=A*r,T=h(v),p=h(v+g),b=j(h(v+2*g)-Math.abs(T)-Math.abs(p)),y=b>=0?0:b;T=j(T+(T>=0?y:-y)),p=j(p+(p>=0?y:-y));let L=j(Math.sqrt(j(j(j(T*T)+j(p*p))+j(b*b))));if(L===0){f(v,0),f(v+g,0),f(v+2*g,l);continue}let C=j(l/L);f(v,Me(j(T*C))),f(v+g,Me(j(p*C))),f(v+2*g,Me(j(b*C)))}return}if(i==="QUATERNION"){if(r!==8)throw q(`QUATERNION filter requires byteStride 8 (got ${r})`);let u=j(32767/j(Math.SQRT2));for(let l=0;l<t;l++){let h=l*8,f=n.getInt16(h+6,!0),g=f|3,A=n.getInt16(h,!0),v=n.getInt16(h+2,!0),T=n.getInt16(h+4,!0),p=j(g*g),b=j(j(j(j(p*2)-j(A*A))-j(v*v))-j(T*T)),y=j(Math.sqrt(b>=0?b:0)),L=j(u/g),C=f&3,F=[0,0,0,0];F[C+1&3]=Me(j(A*L)),F[C+2&3]=Me(j(v*L)),F[C+3&3]=Me(j(T*L)),F[C]=Math.trunc(j(j(y*L)+.5));for(let _=0;_<4;_++)n.setInt16(h+_*2,F[_]<<16>>16,!0)}return}if(i==="EXPONENTIAL"){if(r<4||r%4!==0)throw q(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${r})`);let u=t*r>>>2;for(let l=0;l<u;l++){let h=l*4,f=n.getUint32(h,!0),g=f<<8>>8,A=f>>24;n.setUint32(h,A+127<<23>>>0,!0);let v=n.getFloat32(h,!0);n.setFloat32(h,j(v*g),!0)}return}if(r!==4&&r!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${r})`);let s=r===8,m=s?65535:255,c=u=>s?n.getUint16(u,!0):n.getUint8(u),o=u=>s?n.getInt16(u,!0):n.getInt8(u),d=(u,l)=>s?n.setUint16(u,l&65535,!0):n.setUint8(u,l&255),a=s?2:1;for(let u=0;u<t;u++){let l=u*r,h=c(l+3*a);h|=h>>1,h|=h>>2,h|=h>>4,h|=h>>8;let f=c(l),g=o(l+a),A=o(l+2*a),v=f+g-A,T=f+A,p=f-g-A,b=c(l+3*a);b=b<<1&h|b&1;let y=h===0?0:j(m/h);d(l,Math.trunc(j(j(v*y)+.5))),d(l+a,Math.trunc(j(j(T*y)+.5))),d(l+2*a,Math.trunc(j(j(p*y)+.5))),d(l+3*a,Math.trunc(j(j(b*y)+.5)))}}var Vt=160,fe=16,Cr=24,Rt=32,Dr=24,Fr=[0,2,4,8],Or=[0,1,2,4,8];function Ct(e){let t=Math.floor(8192/e)&~(fe-1);return t<256?t:256}function q(e){return new Error(`EXT_meshopt_compression: ${e}`)}function Ur(e,t,r,i,n){if(n===0)return r.fill(0,i,i+fe),t;if(n===8)return r.set(e.subarray(t,t+fe),i),t+fe;let s=(1<<n)-1,m=8/n,c=t+fe*n/8;for(let o=0;o<fe;o++){let d=e[t+Math.floor(o/m)],a=o%m,u=n===1?d>>a&1:d>>8-n-a*n&s;r[i+o]=u===s?e[c++]:u}return c}function Dt(e,t,r,i,n,s,m,c){let o=s/fe,d=o+3>>2;if(r-t<d)throw q("truncated ATTRIBUTES stream");let a=t;t+=d;for(let u=0;u<o;u++){if(r-t<Cr)throw q("truncated ATTRIBUTES stream");let l=e[a+(u>>2)]>>(u&3)*2&3;t=Ur(e,t,i,n+u*fe,m[c+l])}return t}function kr(e,t,r,i){if(r%4!==0||r>256)throw q(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let n=e.byteLength;if(n<1)throw q("truncated ATTRIBUTES stream");let s=e[0];if((s&240)!==Vt)throw q(`unsupported ATTRIBUTES header 0x${s.toString(16)}`);let m=s&15;if(m>1)throw q(`unsupported ATTRIBUTES codec version ${m}`);let c=r+(m===0?0:r/4),o=m===0?Rt:Dr,d=c<o?o:c;if(n-1<d)throw q("truncated ATTRIBUTES stream");let a=n-c,u=e.slice(a,a+r),l=a+r,h=Ct(r),f=new Uint8Array(256*4),g=1;for(let A=0;A<t;){let v=Math.min(h,t-A),T=v+fe-1&~(fe-1),p=m===0?0:r/4;if(n-g<p)throw q("truncated ATTRIBUTES stream");let b=g;g+=p;for(let y=0;y<r;y+=4){let L=m===0?0:e[b+y/4];for(let _=0;_<4;_++){let O=L>>_*2&3;if(O===3){if(n-g<v)throw q("truncated ATTRIBUTES stream");f.set(e.subarray(g,g+v),_*v),g+=v}else O===2?f.fill(0,_*v,_*v+v):g=m===0?Dt(e,g,n,f,_*v,T,Fr,0):Dt(e,g,n,f,_*v,T,Or,O)}let C=m===0?0:e[l+y/4],F=C&3;if(F===0)for(let _=0;_<4;_++){let O=u[y+_];for(let D=0;D<v;D++)O=_r(f[_*v+D])+O&255,i[(A+D)*r+y+_]=O}else if(F===1)for(let _=0;_<4;_+=2){let O=u[y+_]|u[y+_+1]<<8,D=_*v;for(let $=0;$<v;$++){let z=f[D+$]|f[D+v+$]<<8;O=Vr(z)+O&65535;let k=(A+$)*r+y+_;i[k]=O&255,i[k+1]=O>>8}}else if(F===2){let _=32-(C>>4)&31,O=(u[y]|u[y+1]<<8|u[y+2]<<16|u[y+3]<<24)>>>0;for(let D=0;D<v;D++){let $=(f[D]|f[v+D]<<8|f[2*v+D]<<16|f[3*v+D]<<24)>>>0;$=(($<<_|$>>>(32-_&31))^O)>>>0,O=$;let z=(A+D)*r+y;i[z]=$&255,i[z+1]=$>>>8&255,i[z+2]=$>>>16&255,i[z+3]=$>>>24}}else throw q(`invalid ATTRIBUTES channel ${C}`)}u.set(i.subarray((A+v-1)*r,(A+v)*r)),A+=v}if(n-g!==d)throw q("ATTRIBUTES trailing data")}var Ft=224,Ot=208;function Ut(e,t){let r=e[t.pos++]??0;if(r<128)return r;let i=r&127,n=7;for(let s=0;s<4;s++){let m=e[t.pos++]??0;if(i=(i|(m&127)<<n)>>>0,n+=7,m<128)break}return i>>>0}function $e(e,t,r){let i=Ut(e,t),n=i>>>1^-(i&1);return r+n>>>0}function $r(e,t,r){if(t%3!==0)throw q(`TRIANGLES count must be divisible by 3 (got ${t})`);let i=t/3;if(e.byteLength<1+i+16)throw q("truncated TRIANGLES stream");let n=e[0];if((n&240)!==Ft)throw q(`unsupported TRIANGLES header 0x${n.toString(16)}`);let s=n&15;if(s>1)throw q(`unsupported TRIANGLES codec version ${s}`);let m=new Uint32Array(16).fill(4294967295),c=new Uint32Array(16).fill(4294967295),o=new Uint32Array(16).fill(4294967295),d=0,a=0,u=(L,C)=>{m[d]=L,c[d]=C,d=d+1&15},l=(L,C=1)=>{o[a]=L,a=a+C&15},h=0,f=0,g=s>=1?13:15,A=1+i,v=e.byteLength-16,T=v,p={pos:A},b=0,y=(L,C,F)=>{r(b++,L),r(b++,C),r(b++,F)};for(let L=1;L<A;L++){let C=e[L];if(C<240){let F=C>>4,_=d-1-F&15,O=m[_],D=c[_],$=0,z=C&15;if(z<g){let k=o[a-1-z&15];$=z===0?h:k;let re=z===0?1:0;h=h+re>>>0,l($,re)}else{if(p.pos>v)throw q("truncated TRIANGLES stream");$=z!==15?f+(z*2-27)>>>0:$e(e,p,f),f=$,l($)}u($,D),u(O,$),y(O,D,$)}else if(C<254){let F=e[T+(C&15)],_=F>>4,O=F&15,D=h;h=h+1>>>0;let $=o[a-_&15],z=_===0?h:$,k=_===0?1:0;h=h+k>>>0;let re=o[a-O&15],Z=O===0?h:re,X=O===0?1:0;h=h+X>>>0,y(D,z,Z),l(D),l(z,k),l(Z,X),u(z,D),u(Z,z),u(D,Z)}else{if(p.pos>v)throw q("truncated TRIANGLES stream");let F=e[p.pos++],_=C===254?0:15,O=F>>4,D=F&15;F===0&&(h=0);let $=0;_===0&&($=h,h=h+1>>>0);let z;O===0?(z=h,h=h+1>>>0):z=o[a-O&15];let k;D===0?(k=h,h=h+1>>>0):k=o[a-D&15],_===15&&(f=$=$e(e,p,f)),O===15&&(f=z=$e(e,p,f)),D===15&&(f=k=$e(e,p,f)),y($,z,k),l($),l(z,O===0||O===15?1:0),l(k,D===0||D===15?1:0),u(z,$),u(k,z),u($,k)}}if(p.pos!==v)throw q("TRIANGLES trailing data")}function Br(e,t,r){if(e.byteLength<1+t+4)throw q("truncated INDICES stream");let i=e[0];if((i&240)!==Ot)throw q(`unsupported INDICES header 0x${i.toString(16)}`);let n=i&15;if(n>1)throw q(`unsupported INDICES codec version ${n}`);let s=e.byteLength-4,m=[0,0],c={pos:1};for(let o=0;o<t;o++){if(c.pos>=s)throw q("truncated INDICES stream");let d=Ut(e,c),a=d&1;d>>>=1;let u=d>>>1^-(d&1),l=m[a]+u>>>0;m[a]=l,r(o,l)}if(c.pos!==s)throw q("INDICES trailing data")}function kt(e,t,r,i,n="NONE"){if(Pt(n),!Number.isInteger(t)||t<0||t>Pr||!Number.isInteger(r)||r<=0||r>256)throw q(`invalid count (${t}) or byteStride (${r})`);let s=t*r;if(s>It)throw q(`decompressed size (${s}) exceeds MAX_MESHOPT_BUFFER_BYTES (${It})`);if(t===0)return new Uint8Array(0);let m=new Uint8Array(s);if(i==="ATTRIBUTES")return kr(e,t,r,m),_t(m,t,r,n),m;if(i==="TRIANGLES"||i==="INDICES"){if(r!==2&&r!==4)throw q(`${i} byteStride must be 2 or 4 (got ${r})`);if(n&&n!=="NONE")throw q(`filter ${n} is only valid for ATTRIBUTES`);let c=new DataView(m.buffer),o=r===2?(d,a)=>c.setUint16(d*2,a&65535,!0):(d,a)=>c.setUint32(d*4,a>>>0,!0);return i==="TRIANGLES"?$r(e,t,o):Br(e,t,o),m}throw q(`unknown mode "${String(i)}"`)}function $t(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function Hr(e,t,r,i){let n=t*r;if(e.byteLength<n)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${n})`);if(i==="ATTRIBUTES"){if(r%4!==0||r>256)throw new Error(`encodeMeshoptBuffer: ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let c=[Vt],o=Ct(r),d=new Uint8Array(r);t>0&&d.set(e.subarray(0,r));let a=d.slice(),u=new Uint8Array(256);for(let l=0;l<t;){let h=Math.min(o,t-l),f=h+15&-16;for(let g=0;g<r;g++){u.fill(0);let A=d[g];for(let p=0;p<h;p++){let b=e[(l+p)*r+g];u[p]=Rr(b-A&255),A=b}d[g]=A;let v=f/16,T=c.length;for(let p=0;p<v+3>>2;p++)c.push(0);for(let p=0;p<v;p++){let b=u.subarray(p*16,p*16+16);if(!b.every(y=>y===0)){c[T+(p>>2)]|=3<<(p&3)*2;for(let y of b)c.push(y)}}}l+=h}for(let l=r;l<Rt;l++)c.push(0);for(let l=0;l<r;l++)c.push(a[l]);return new Uint8Array(c)}if(r!==2&&r!==4)throw new Error(`encodeMeshoptBuffer: ${i} byteStride must be 2 or 4 (got ${r})`);let s=new DataView(e.buffer,e.byteOffset,e.byteLength),m=c=>r===2?s.getUint16(c*2,!0):s.getUint32(c*4,!0);if(i==="INDICES"){let c=[Ot|1],o=0;for(let d=0;d<t;d++){let a=m(d),u=a-o|0;o=a,$t(c,Et(u)<<1>>>0)}return c.push(0,0,0,0),new Uint8Array(c)}if(i==="TRIANGLES"){if(t%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${t})`);let c=t/3,o=[Ft|1];for(let a=0;a<c;a++)o.push(255);let d=0;for(let a=0;a<c;a++){o.push(255);for(let u=0;u<3;u++){let l=m(a*3+u);$t(o,Et(l-d|0)),d=l}}for(let a=0;a<16;a++)o.push(0);return new Uint8Array(o)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(i)}"`)}function tt(e,t){let r=t&&typeof t=="object"?t:e,i=t&&typeof t=="object"?e:r?.gltf;if(!i||!Array.isArray(i.bufferViews))return;let n=new Uint8Array(r.bin),s=[],m=0;for(let u=0;u<i.bufferViews.length;u++){let l=i.bufferViews[u],h=l?.extensions?.KHR_meshopt_compression,f=h??l?.extensions?.EXT_meshopt_compression;if(!f||typeof f!="object")continue;let g=h?"KHR_meshopt_compression":"EXT_meshopt_compression",A=Number(f.count),v=Number(f.byteStride),T=Number(f.byteOffset??0),p=Number(f.byteLength??0),b=f.mode||"ATTRIBUTES",y=f.filter||"NONE";if(y==="COLOR"&&!h)throw q(`bufferView ${u} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(f.buffer??0)!==0)throw new Error(`${g}: bufferView ${u} references buffer ${String(f.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(T)||T<0||!Number.isInteger(p)||p<0||T+p>n.byteLength)throw new Error(`${g}: bufferView ${u} compressed range [${T}, ${T+p}] out of bounds (${n.byteLength})`);let L=A*v;if(m+=L,m>Lt)throw q(`total decompressed size (${m}) exceeds MAX_MESHOPT_TOTAL_BYTES (${Lt})`);let C=n.subarray(T,T+p),F=kt(C,A,v,b,y);s.push({index:u,bytes:F,ext:f})}if(s.length===0)return;let c=n.byteLength+3&-4,o=0;for(let u of s)o+=u.bytes.byteLength+3&-4;let d=new Uint8Array(c+o);d.set(n,0);let a=c;for(let u of s){d.set(u.bytes,a);let l=i.bufferViews[u.index];l.buffer=0,l.byteOffset=a,l.byteLength=u.bytes.byteLength,l._decoded=u.bytes,u.ext.mode==="ATTRIBUTES"&&l.byteStride===void 0&&(l.byteStride=Number(u.ext.byteStride)),l.extensions&&(delete l.extensions.EXT_meshopt_compression,delete l.extensions.KHR_meshopt_compression),a+=u.bytes.byteLength+3&-4}r.bin=d.buffer}var rt={decodeBufferViews(e,t){tt(t)},decodePrimitive(e,t,r){let i=t?.extensions;i?.EXT_meshopt_compression&&delete i.EXT_meshopt_compression,i?.KHR_meshopt_compression&&delete i.KHR_meshopt_compression}};ye().decoders.set("meshopt",rt);var Bt={name:"meshopt",onParseGLB(e){ye().decoders.set("meshopt",rt),tt(e)}};function it(e,t,r,i=!0){let n=[],s=null;try{for(let[m,c]of[[35633,t],[35632,r]]){let o=e.createShader(m);if(!o){if(i)throw new Error("Shader allocation failed");return null}if(n.push(o),e.shaderSource(o,c),e.compileShader(o),e.getShaderParameter&&!e.getShaderParameter(o,35713)){if(i)throw new Error(`Shader compile error: ${e.getShaderInfoLog(o)}`);return null}}if(s=e.createProgram(),!s){if(i)throw new Error("Program allocation failed");return null}for(let m of n)e.attachShader(s,m);if(e.linkProgram(s),e.getProgramParameter&&!e.getProgramParameter(s,35714)){let m=i?e.getProgramInfoLog(s):null;if(e.deleteProgram?.(s),s=null,i)throw new Error(`Program link error: ${m}`);return null}return s}finally{for(let m of n)s&&e.detachShader?.(s,m),e.deleteShader?.(m)}}function Ht(e,t){let r=e?.trim(),i=r?Number(r):NaN;return Number.isFinite(i)?i:t}var zr=`#version 300 es
|
|
37
|
+
vec3 aCol=vec3(${l(M[0],1,0,1)},${l(M[1],1,0,1)},${l(M[2],1,0,1)});
|
|
38
|
+
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${y},.001));
|
|
39
|
+
diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${h});`)}if(n&&!i.includes("uClearcoat")){let h=l(n.clearcoatFactor,1,0,1),p=l(n.clearcoatRoughnessFactor,0,0,1);o=o.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${p},NoV)*${h};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${p})*ccF;fragColor=vec4(color,base.a);`)}if(f){let h=Array.isArray(f.sheenColorFactor)?f.sheenColorFactor:[1,1,1],p=`color+=vec3(${l(h[0],1,0,1)},${l(h[1],1,0,1)},${l(h[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;o.includes("color=applyToneMapping(color,uToneMapping);")?o=o.replace("color=applyToneMapping(color,uToneMapping);",`${p}color=applyToneMapping(color,uToneMapping);`):o=o.replace("fragColor=vec4(color,base.a);",`${p}fragColor=vec4(color,base.a);`)}return{vs:r,fs:o}},onBeforeDrawPrimitive(e,t,r,i,a,n){let f=r.materialIndex;if(f!==void 0&&n?.materials){let c=n.materials[f];c?.name&&De.has(c.name)&&De.get(c.name).onBindUniforms?.(e,t,r)}if(r.isTransmissive){let c=Xe.get(e);if(c){e.activeTexture(33990),e.bindTexture(3553,c);let s=e.getUniformLocation(t,"uTransmissionTex");s&&e.uniform1i(s,6);let d=e.getUniformLocation(t,"uViewportSize");d&&e.uniform2f(d,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}},Gt=64*1024*1024,Wt=128*1024*1024,fi=16777216;function ci(e){return(e>>>1^-(e&1))&255}function hi(e){return(e>>>1^-(e&1))&65535}function mi(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function Kt(e){return(e<<1^e>>31)>>>0}function qt(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw K(`unknown filter "${String(e)}"`)}var j=Math.fround;function Le(e){return Math.trunc(j(e+(e>=0?.5:-.5)))}function Xt(e,t,r,i="NONE"){if(qt(i),!i||i==="NONE"||t<=0)return;let a=new DataView(e.buffer,e.byteOffset,e.byteLength);if(i==="OCTAHEDRAL"){if(r!==4&&r!==8)throw K(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${r})`);let l=r===8,u=l?32767:127,m=b=>l?a.getInt16(b,!0):a.getInt8(b),h=(b,y)=>l?a.setInt16(b,y,!0):a.setInt8(b,y<<24>>24),p=l?2:1;for(let b=0;b<t;b++){let y=b*r,M=m(y),g=m(y+p),v=j(m(y+2*p)-Math.abs(M)-Math.abs(g)),x=v>=0?0:v;M=j(M+(M>=0?x:-x)),g=j(g+(g>=0?x:-x));let P=j(Math.sqrt(j(j(j(M*M)+j(g*g))+j(v*v))));if(P===0){h(y,0),h(y+p,0),h(y+2*p,u);continue}let C=j(u/P);h(y,Le(j(M*C))),h(y+p,Le(j(g*C))),h(y+2*p,Le(j(v*C)))}return}if(i==="QUATERNION"){if(r!==8)throw K(`QUATERNION filter requires byteStride 8 (got ${r})`);let l=j(32767/j(Math.SQRT2));for(let u=0;u<t;u++){let m=u*8,h=a.getInt16(m+6,!0),p=h|3,b=a.getInt16(m,!0),y=a.getInt16(m+2,!0),M=a.getInt16(m+4,!0),g=j(p*p),v=j(j(j(j(g*2)-j(b*b))-j(y*y))-j(M*M)),x=j(Math.sqrt(v>=0?v:0)),P=j(l/p),C=h&3,F=[0,0,0,0];F[C+1&3]=Le(j(b*P)),F[C+2&3]=Le(j(y*P)),F[C+3&3]=Le(j(M*P)),F[C]=Math.trunc(j(j(x*P)+.5));for(let I=0;I<4;I++)a.setInt16(m+I*2,F[I]<<16>>16,!0)}return}if(i==="EXPONENTIAL"){if(r<4||r%4!==0)throw K(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${r})`);let l=t*r>>>2;for(let u=0;u<l;u++){let m=u*4,h=a.getUint32(m,!0),p=h<<8>>8,b=h>>24;a.setUint32(m,b+127<<23>>>0,!0);let y=a.getFloat32(m,!0);a.setFloat32(m,j(y*p),!0)}return}if(r!==4&&r!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${r})`);let n=r===8,f=n?65535:255,c=l=>n?a.getUint16(l,!0):a.getUint8(l),s=l=>n?a.getInt16(l,!0):a.getInt8(l),d=(l,u)=>n?a.setUint16(l,u&65535,!0):a.setUint8(l,u&255),o=n?2:1;for(let l=0;l<t;l++){let u=l*r,m=c(u+3*o);m|=m>>1,m|=m>>2,m|=m>>4,m|=m>>8;let h=c(u),p=s(u+o),b=s(u+2*o),y=h+p-b,M=h+b,g=h-p-b,v=c(u+3*o);v=v<<1&m|v&1;let x=m===0?0:j(f/m);d(u,Math.trunc(j(j(y*x)+.5))),d(u+o,Math.trunc(j(j(M*x)+.5))),d(u+2*o,Math.trunc(j(j(g*x)+.5))),d(u+3*o,Math.trunc(j(j(v*x)+.5)))}}var Zt=160,me=16,di=24,Qt=32,pi=24,gi=[0,2,4,8],bi=[0,1,2,4,8];function Yt(e){let t=Math.floor(8192/e)&~(me-1);return t<256?t:256}function K(e){return new Error(`EXT_meshopt_compression: ${e}`)}function vi(e,t,r,i,a){if(a===0)return r.fill(0,i,i+me),t;if(a===8)return r.set(e.subarray(t,t+me),i),t+me;let n=(1<<a)-1,f=8/a,c=t+me*a/8;for(let s=0;s<me;s++){let d=e[t+Math.floor(s/f)],o=s%f,l=a===1?d>>o&1:d>>8-a-o*a&n;r[i+s]=l===n?e[c++]:l}return c}function Jt(e,t,r,i,a,n,f,c){let s=n/me,d=s+3>>2;if(r-t<d)throw K("truncated ATTRIBUTES stream");let o=t;t+=d;for(let l=0;l<s;l++){if(r-t<di)throw K("truncated ATTRIBUTES stream");let u=e[o+(l>>2)]>>(l&3)*2&3;t=vi(e,t,i,a+l*me,f[c+u])}return t}function yi(e,t,r,i){if(r%4!==0||r>256)throw K(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let a=e.byteLength;if(a<1)throw K("truncated ATTRIBUTES stream");let n=e[0];if((n&240)!==Zt)throw K(`unsupported ATTRIBUTES header 0x${n.toString(16)}`);let f=n&15;if(f>1)throw K(`unsupported ATTRIBUTES codec version ${f}`);let c=r+(f===0?0:r/4),s=f===0?Qt:pi,d=c<s?s:c;if(a-1<d)throw K("truncated ATTRIBUTES stream");let o=a-c,l=e.slice(o,o+r),u=o+r,m=Yt(r),h=new Uint8Array(256*4),p=1;for(let b=0;b<t;){let y=Math.min(m,t-b),M=y+me-1&~(me-1),g=f===0?0:r/4;if(a-p<g)throw K("truncated ATTRIBUTES stream");let v=p;p+=g;for(let x=0;x<r;x+=4){let P=f===0?0:e[v+x/4];for(let I=0;I<4;I++){let B=P>>I*2&3;if(B===3){if(a-p<y)throw K("truncated ATTRIBUTES stream");h.set(e.subarray(p,p+y),I*y),p+=y}else B===2?h.fill(0,I*y,I*y+y):p=f===0?Jt(e,p,a,h,I*y,M,gi,0):Jt(e,p,a,h,I*y,M,bi,B)}let C=f===0?0:e[u+x/4],F=C&3;if(F===0)for(let I=0;I<4;I++){let B=l[x+I];for(let U=0;U<y;U++)B=ci(h[I*y+U])+B&255,i[(b+U)*r+x+I]=B}else if(F===1)for(let I=0;I<4;I+=2){let B=l[x+I]|l[x+I+1]<<8,U=I*y;for(let V=0;V<y;V++){let k=h[U+V]|h[U+y+V]<<8;B=hi(k)+B&65535;let O=(b+V)*r+x+I;i[O]=B&255,i[O+1]=B>>8}}else if(F===2){let I=32-(C>>4)&31,B=(l[x]|l[x+1]<<8|l[x+2]<<16|l[x+3]<<24)>>>0;for(let U=0;U<y;U++){let V=(h[U]|h[y+U]<<8|h[2*y+U]<<16|h[3*y+U]<<24)>>>0;V=((V<<I|V>>>(32-I&31))^B)>>>0,B=V;let k=(b+U)*r+x;i[k]=V&255,i[k+1]=V>>>8&255,i[k+2]=V>>>16&255,i[k+3]=V>>>24}}else throw K(`invalid ATTRIBUTES channel ${C}`)}l.set(i.subarray((b+y-1)*r,(b+y)*r)),b+=y}if(a-p!==d)throw K("ATTRIBUTES trailing data")}var er=224,tr=208;function rr(e,t){let r=e[t.pos++]??0;if(r<128)return r;let i=r&127,a=7;for(let n=0;n<4;n++){let f=e[t.pos++]??0;if(i=(i|(f&127)<<a)>>>0,a+=7,f<128)break}return i>>>0}function Ze(e,t,r){let i=rr(e,t),a=i>>>1^-(i&1);return r+a>>>0}function xi(e,t,r){if(t%3!==0)throw K(`TRIANGLES count must be divisible by 3 (got ${t})`);let i=t/3;if(e.byteLength<1+i+16)throw K("truncated TRIANGLES stream");let a=e[0];if((a&240)!==er)throw K(`unsupported TRIANGLES header 0x${a.toString(16)}`);let n=a&15;if(n>1)throw K(`unsupported TRIANGLES codec version ${n}`);let f=new Uint32Array(16).fill(4294967295),c=new Uint32Array(16).fill(4294967295),s=new Uint32Array(16).fill(4294967295),d=0,o=0,l=(P,C)=>{f[d]=P,c[d]=C,d=d+1&15},u=(P,C=1)=>{s[o]=P,o=o+C&15},m=0,h=0,p=n>=1?13:15,b=1+i,y=e.byteLength-16,M=y,g={pos:b},v=0,x=(P,C,F)=>{r(v++,P),r(v++,C),r(v++,F)};for(let P=1;P<b;P++){let C=e[P];if(C<240){let F=C>>4,I=d-1-F&15,B=f[I],U=c[I],V=0,k=C&15;if(k<p){let O=s[o-1-k&15];V=k===0?m:O;let ee=k===0?1:0;m=m+ee>>>0,u(V,ee)}else{if(g.pos>y)throw K("truncated TRIANGLES stream");V=k!==15?h+(k*2-27)>>>0:Ze(e,g,h),h=V,u(V)}l(V,U),l(B,V),x(B,U,V)}else if(C<254){let F=e[M+(C&15)],I=F>>4,B=F&15,U=m;m=m+1>>>0;let V=s[o-I&15],k=I===0?m:V,O=I===0?1:0;m=m+O>>>0;let ee=s[o-B&15],J=B===0?m:ee,q=B===0?1:0;m=m+q>>>0,x(U,k,J),u(U),u(k,O),u(J,q),l(k,U),l(J,k),l(U,J)}else{if(g.pos>y)throw K("truncated TRIANGLES stream");let F=e[g.pos++],I=C===254?0:15,B=F>>4,U=F&15;F===0&&(m=0);let V=0;I===0&&(V=m,m=m+1>>>0);let k;B===0?(k=m,m=m+1>>>0):k=s[o-B&15];let O;U===0?(O=m,m=m+1>>>0):O=s[o-U&15],I===15&&(h=V=Ze(e,g,h)),B===15&&(h=k=Ze(e,g,h)),U===15&&(h=O=Ze(e,g,h)),x(V,k,O),u(V),u(k,B===0||B===15?1:0),u(O,U===0||U===15?1:0),l(k,V),l(O,k),l(V,O)}}if(g.pos!==y)throw K("TRIANGLES trailing data")}function Mi(e,t,r){if(e.byteLength<1+t+4)throw K("truncated INDICES stream");let i=e[0];if((i&240)!==tr)throw K(`unsupported INDICES header 0x${i.toString(16)}`);let a=i&15;if(a>1)throw K(`unsupported INDICES codec version ${a}`);let n=e.byteLength-4,f=[0,0],c={pos:1};for(let s=0;s<t;s++){if(c.pos>=n)throw K("truncated INDICES stream");let d=rr(e,c),o=d&1;d>>>=1;let l=d>>>1^-(d&1),u=f[o]+l>>>0;f[o]=u,r(s,u)}if(c.pos!==n)throw K("INDICES trailing data")}function ir(e,t,r,i,a="NONE"){if(qt(a),!Number.isInteger(t)||t<0||t>fi||!Number.isInteger(r)||r<=0||r>256)throw K(`invalid count (${t}) or byteStride (${r})`);let n=t*r;if(n>Gt)throw K(`decompressed size (${n}) exceeds MAX_MESHOPT_BUFFER_BYTES (${Gt})`);if(t===0)return new Uint8Array(0);let f=new Uint8Array(n);if(i==="ATTRIBUTES")return yi(e,t,r,f),Xt(f,t,r,a),f;if(i==="TRIANGLES"||i==="INDICES"){if(r!==2&&r!==4)throw K(`${i} byteStride must be 2 or 4 (got ${r})`);if(a&&a!=="NONE")throw K(`filter ${a} is only valid for ATTRIBUTES`);let c=new DataView(f.buffer),s=r===2?(d,o)=>c.setUint16(d*2,o&65535,!0):(d,o)=>c.setUint32(d*4,o>>>0,!0);return i==="TRIANGLES"?xi(e,t,s):Mi(e,t,s),f}throw K(`unknown mode "${String(i)}"`)}function ar(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function wi(e,t,r,i){let a=t*r;if(e.byteLength<a)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${a})`);if(i==="ATTRIBUTES"){if(r%4!==0||r>256)throw new Error(`encodeMeshoptBuffer: ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let c=[Zt],s=Yt(r),d=new Uint8Array(r);t>0&&d.set(e.subarray(0,r));let o=d.slice(),l=new Uint8Array(256);for(let u=0;u<t;){let m=Math.min(s,t-u),h=m+15&-16;for(let p=0;p<r;p++){l.fill(0);let b=d[p];for(let g=0;g<m;g++){let v=e[(u+g)*r+p];l[g]=mi(v-b&255),b=v}d[p]=b;let y=h/16,M=c.length;for(let g=0;g<y+3>>2;g++)c.push(0);for(let g=0;g<y;g++){let v=l.subarray(g*16,g*16+16);if(!v.every(x=>x===0)){c[M+(g>>2)]|=3<<(g&3)*2;for(let x of v)c.push(x)}}}u+=m}for(let u=r;u<Qt;u++)c.push(0);for(let u=0;u<r;u++)c.push(o[u]);return new Uint8Array(c)}if(r!==2&&r!==4)throw new Error(`encodeMeshoptBuffer: ${i} byteStride must be 2 or 4 (got ${r})`);let n=new DataView(e.buffer,e.byteOffset,e.byteLength),f=c=>r===2?n.getUint16(c*2,!0):n.getUint32(c*4,!0);if(i==="INDICES"){let c=[tr|1],s=0;for(let d=0;d<t;d++){let o=f(d),l=o-s|0;s=o,ar(c,Kt(l)<<1>>>0)}return c.push(0,0,0,0),new Uint8Array(c)}if(i==="TRIANGLES"){if(t%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${t})`);let c=t/3,s=[er|1];for(let o=0;o<c;o++)s.push(255);let d=0;for(let o=0;o<c;o++){s.push(255);for(let l=0;l<3;l++){let u=f(o*3+l);ar(s,Kt(u-d|0)),d=u}}for(let o=0;o<16;o++)s.push(0);return new Uint8Array(s)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(i)}"`)}function mt(e,t){let r=t&&typeof t=="object"?t:e,i=t&&typeof t=="object"?e:r?.gltf;if(!i||!Array.isArray(i.bufferViews))return;let a=new Uint8Array(r.bin),n=[],f=0;for(let l=0;l<i.bufferViews.length;l++){let u=i.bufferViews[l],m=u?.extensions?.KHR_meshopt_compression,h=m??u?.extensions?.EXT_meshopt_compression;if(!h||typeof h!="object")continue;let p=m?"KHR_meshopt_compression":"EXT_meshopt_compression",b=Number(h.count),y=Number(h.byteStride),M=Number(h.byteOffset??0),g=Number(h.byteLength??0),v=h.mode||"ATTRIBUTES",x=h.filter||"NONE";if(x==="COLOR"&&!m)throw K(`bufferView ${l} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(h.buffer??0)!==0)throw new Error(`${p}: bufferView ${l} references buffer ${String(h.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(M)||M<0||!Number.isInteger(g)||g<0||M+g>a.byteLength)throw new Error(`${p}: bufferView ${l} compressed range [${M}, ${M+g}] out of bounds (${a.byteLength})`);let P=b*y;if(f+=P,f>Wt)throw K(`total decompressed size (${f}) exceeds MAX_MESHOPT_TOTAL_BYTES (${Wt})`);let C=a.subarray(M,M+g),F=ir(C,b,y,v,x);n.push({index:l,bytes:F,ext:h})}if(n.length===0)return;let c=a.byteLength+3&-4,s=0;for(let l of n)s+=l.bytes.byteLength+3&-4;let d=new Uint8Array(c+s);d.set(a,0);let o=c;for(let l of n){d.set(l.bytes,o);let u=i.bufferViews[l.index];u.buffer=0,u.byteOffset=o,u.byteLength=l.bytes.byteLength,u._decoded=l.bytes,l.ext.mode==="ATTRIBUTES"&&u.byteStride===void 0&&(u.byteStride=Number(l.ext.byteStride)),u.extensions&&(delete u.extensions.EXT_meshopt_compression,delete u.extensions.KHR_meshopt_compression),o+=l.bytes.byteLength+3&-4}r.bin=d.buffer}var dt={decodeBufferViews(e,t){mt(t)},decodePrimitive(e,t,r){let i=t?.extensions;i?.EXT_meshopt_compression&&delete i.EXT_meshopt_compression,i?.KHR_meshopt_compression&&delete i.KHR_meshopt_compression}};de().decoders.set("meshopt",dt);var nr={name:"meshopt",onParseGLB(e){de().decoders.set("meshopt",dt),mt(e)}};function pt(e,t,r,i=!0){let a=[],n=null;try{for(let[f,c]of[[35633,t],[35632,r]]){let s=e.createShader(f);if(!s){if(i)throw new Error("Shader allocation failed");return null}if(a.push(s),e.shaderSource(s,c),e.compileShader(s),e.getShaderParameter&&!e.getShaderParameter(s,35713)){if(i)throw new Error(`Shader compile error: ${e.getShaderInfoLog(s)}`);return null}}if(n=e.createProgram(),!n){if(i)throw new Error("Program allocation failed");return null}for(let f of a)e.attachShader(n,f);if(e.linkProgram(n),e.getProgramParameter&&!e.getProgramParameter(n,35714)){let f=i?e.getProgramInfoLog(n):null;if(e.deleteProgram?.(n),n=null,i)throw new Error(`Program link error: ${f}`);return null}return n}finally{for(let f of a)n&&e.detachShader?.(n,f),e.deleteShader?.(f)}}function or(e,t){let r=e?.trim(),i=r?Number(r):NaN;return Number.isFinite(i)?i:t}var Si=`#version 300 es
|
|
40
40
|
layout(location=0) in vec3 aPosition;
|
|
41
41
|
layout(location=1) in vec3 aNormal;
|
|
42
42
|
uniform mat4 uMVP,uVP;
|
|
@@ -57,19 +57,19 @@ vec2 pxOffset=dir*(uOutlineThickness*2.0/max(uViewportSize,vec2(1.0)))*clipPos.w
|
|
|
57
57
|
clipPos.xy+=pxOffset;
|
|
58
58
|
clipPos.z+=1e-4*clipPos.w;
|
|
59
59
|
gl_Position=clipPos;
|
|
60
|
-
}`,
|
|
60
|
+
}`,Ai=`#version 300 es
|
|
61
61
|
precision highp float;
|
|
62
62
|
uniform vec4 uOutlineColor;
|
|
63
63
|
out vec4 fragColor;
|
|
64
64
|
void main(){
|
|
65
65
|
fragColor=uOutlineColor;
|
|
66
|
-
}`,
|
|
66
|
+
}`,lr=`#version 300 es
|
|
67
67
|
out vec2 vUV;
|
|
68
68
|
void main(){
|
|
69
69
|
vec2 pos=vec2((gl_VertexID<<1)&2,gl_VertexID&2);
|
|
70
70
|
vUV=pos;
|
|
71
71
|
gl_Position=vec4(pos*2.0-1.0,0.0,1.0);
|
|
72
|
-
}`,
|
|
72
|
+
}`,Ii=`#version 300 es
|
|
73
73
|
precision highp float;
|
|
74
74
|
in vec2 vUV;
|
|
75
75
|
uniform sampler2D uSourceTex;
|
|
@@ -92,7 +92,7 @@ c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,-h.y)).rgb)*0.125;
|
|
|
92
92
|
c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,h.y)).rgb)*0.125;
|
|
93
93
|
c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,h.y)).rgb)*0.125;
|
|
94
94
|
fragColor=vec4(c,1.0);
|
|
95
|
-
}`,
|
|
95
|
+
}`,Ni=`#version 300 es
|
|
96
96
|
precision highp float;
|
|
97
97
|
in vec2 vUV;
|
|
98
98
|
uniform sampler2D uBloomTex;
|
|
@@ -114,6 +114,61 @@ sum+=texture(uBloomTex,vUV+vec2(-d.x,-d.y)).rgb*2.0;
|
|
|
114
114
|
vec3 bloom=(sum/12.0)*uStrength;
|
|
115
115
|
float a=clamp(min(bloom.r,min(bloom.g,bloom.b)),0.0,1.0);
|
|
116
116
|
fragColor=vec4(bloom,a);
|
|
117
|
-
}`,Be=3,Le=new WeakMap;function jt(e,t=[.22,.74,.97]){let r=ht(e,"");if(!r.startsWith("#"))return[t[0],t[1],t[2]];let i=r.slice(1);if(i.length===3){let n=+("0x"+i[0]+i[0])/255,s=+("0x"+i[1]+i[1])/255,m=+("0x"+i[2]+i[2])/255;return[n,s,m]}if(i.length===6){let n=+("0x"+i.slice(0,2))/255,s=+("0x"+i.slice(2,4))/255,m=+("0x"+i.slice(4,6))/255;return[n,s,m]}return[t[0],t[1],t[2]]}function qr(e,t,r=.8,i=.5){let n=Number.isFinite(t)?Math.max(0,t):0;if(n<=0)return[0,0,0];let s=Math.max(0,Number(e[0])||0),m=Math.max(0,Number(e[1])||0),c=Math.max(0,Number(e[2])||0),o=Math.max(s,m,c);if(o<=1e-6)return[0,0,0];let d=Number.isFinite(r)?Math.max(0,r):.8,a=Math.max(d*Math.max(0,i),1e-4),u=Math.max(0,Math.min(2*a,o-d+a)),l=u*u/(4*a+1e-4),h=Math.min(1,Math.max(0,Math.max(l,o-d)/Math.max(o,1e-4)))*n;return[s*h,m*h,c*h]}function Wr(e,t,r,i){let n=Number(e[0])||0,s=Number(e[1])||0,m=Math.hypot(n,s);if(m<=1e-5||t<=0||r<=0)return[0,0];let c=Math.max(1,Number(i[0])||1),o=Math.max(1,Number(i[1])||1),d=Math.max(0,r)*2*t;return[n/m*(d/c),s/m*(d/o)]}var Gt=new WeakSet;function Kt(e){let t=Le.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Le.delete(e)}if(Gt.has(e)||e.isContextLost?.())return null;let r=it(e,zr,jr,!1),i=it(e,zt,Gr,!1),n=it(e,zt,Kr,!1);if(!r||!i||!n){for(let m of[r,i,n])m&&e.deleteProgram(m);return Gt.add(e),null}let s=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:r,uOutlineMVP:e.getUniformLocation(r,"uMVP"),uOutlineVP:e.getUniformLocation(r,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(r,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(r,"uViewportSize"),uOutlineThickness:e.getUniformLocation(r,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(r,"uOutlineColor"),downProg:i,uDownSourceTex:e.getUniformLocation(i,"uSourceTex"),uDownTexelSize:e.getUniformLocation(i,"uTexelSize"),uDownThreshold:e.getUniformLocation(i,"uThreshold"),upProg:n,uUpBloomTex:e.getUniformLocation(n,"uBloomTex"),uUpTexelSize:e.getUniformLocation(n,"uTexelSize"),uUpRadius:e.getUniformLocation(n,"uRadius"),uUpStrength:e.getUniformLocation(n,"uStrength"),fsVao:s,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Le.set(e,t),t}function Xr(e,t,r,i){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let n=Math.max(2,r|0),s=Math.max(2,i|0);if(t.sceneTex&&t.bloomFbo.length===Be&&t.texWidth===n&&t.texHeight===s)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,n,s,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071);let m=n,c=s;for(let o=0;o<Be;o++)m=Math.max(1,m>>1),c=Math.max(1,c>>1),t.mipWidth[o]=m,t.mipHeight[o]=c,t.bloomTex[o]||(t.bloomTex[o]=e.createTexture()),e.bindTexture(3553,t.bloomTex[o]),e.texImage2D(3553,0,6408,m,c,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),t.bloomFbo[o]||(t.bloomFbo[o]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[o]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[o],0);return e.bindFramebuffer(36160,null),t.texWidth=n,t.texHeight=s,!0}function Qr(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let i=t.getAttribute("bloom");if(i!==null){let n=i.trim().toLowerCase();if(n==="false"||n==="0"||n==="none")return null;let s=n===""||n==="true"?.35:Number(n);if(!Number.isFinite(s)||s<=0)return null;let m=mt({strength:s,threshold:Ht(t.getAttribute("bloom-threshold"),.62),radius:Ht(t.getAttribute("bloom-radius"),.75)});if(m)return m}}let r=null;for(let i of e.meshes||[]){if(i.visible===!1)continue;let n=i?.extras?.xr?.bloom??i?.userData?.xr?.bloom,s=mt(n);s&&(!r||s.strength>r.strength)&&(r=s)}return r}function Zr(e,t){if(e==null)return null;let r=e.trim(),i=r.toLowerCase();if(i==="false"||i==="0"||i==="none")return null;let n=t,s=3.5,m=!1;if(r&&i!=="true"){let c=r.split(/\s+/);for(let o of c)if(o.startsWith("#"))n=o;else if(o.toLowerCase()==="pulse")m=!0;else{let d=Number(o);Number.isFinite(d)&&d>0&&(s=d)}}return Xe({color:n,thickness:s,pulse:m})}var Yr=new Set(["floor","pedestal","ground","table","grid","pad"]);function Jr(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>Yr.has(t))}function ei(e,t){let r=e.container,i=typeof r?.getAttribute=="function"?r.getAttribute("outline"):null;if(i!=null){let a=i.trim().toLowerCase();if(a==="false"||a==="0"||a==="none")return null}let n=t?.extras?.xr?.outline??t?.userData?.xr?.outline,s=Xe(n);if(s)return s;let m=typeof r?.getAttribute=="function"&&r.getAttribute("outline-color")||"#38bdf8",c=Zr(i,m),o=r!=null&&typeof r.hasAttribute=="function"&&r.hasAttribute("outline-selected")&&r.getAttribute("outline-selected")!=="false",d=e.getSelectedMesh?.()||"";if(d)return t.name!==d?null:c||(o?Xe({color:m,thickness:3,pulse:!1}):null);if(c){let a=t.name||"";return Jr(a)?null:c}return null}var qt={name:"postprocessing",onAttributeChanged(e,t){(t==="bloom"||t==="bloom-threshold"||t==="bloom-radius"||t==="outline"||t==="outline-selected"||t==="outline-color"||t==="selected-mesh")&&e.viewer?.render?.()},onAfterRender(e,t,r){if(!t.meshes||t.meshes.length===0)return;let i=Math.max(1,t.canvas?.width||300),n=Math.max(1,t.canvas?.height||150),s=[];for(let l of t.meshes){if(l.visible===!1)continue;let h=ei(t,l);h&&s.push({mesh:l,trait:h})}let m=s.length>0?Kt(e):null;if(m){let l=m,h=Ae(),f=Ae(),g=new Float32Array(9),A=(typeof performance<"u"?performance.now():Date.now())*.001,v=typeof e.getParameter=="function"?e.getParameter(e.VIEWPORT):null,T=Math.max(1,v?.[2]||i),p=Math.max(1,v?.[3]||n);e.useProgram(l.outlineProg),l.uOutlineViewportSize&&e.uniform2f(l.uOutlineViewportSize,T,p),l.uOutlineVP&&e.uniformMatrix4fv(l.uOutlineVP,!1,r),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(e.LEQUAL),e.depthMask(!1);for(let{mesh:b,trait:y}of s){let[L,C,F]=jt(y.color),_=y.pulse?.8+.25*Math.sin(A*4):1;l.uOutlineColor&&e.uniform4f(l.uOutlineColor,L,C,F,1),l.uOutlineThickness&&e.uniform1f(l.uOutlineThickness,y.thickness*_),b.worldSpace===!0?h.set(b.transform):Se(h,t.modelRootMatrix,b.transform);let O=b.instanceMatrices;for(let D of b.primitives)if(!(D.pluginData?.skinning?.hasSkin||D.pluginData?.morph?.hasMorph))if(e.bindVertexArray(D.vao),O&&O.length>=16){let $=O.length>>4,z=Ae();for(let k=0;k<$;k++)Se(z,h,O.subarray(k*16,k*16+16)),Se(f,r,z),Ve(g,z),e.uniformMatrix4fv(l.uOutlineMVP,!1,f),e.uniformMatrix3fv(l.uOutlineNormalMatrix,!1,g),D.indices?e.drawElements(4,D.indexCount,D.indexType,0):e.drawArrays(4,0,D.indexCount)}else Se(f,r,h),Ve(g,h),e.uniformMatrix4fv(l.uOutlineMVP,!1,f),e.uniformMatrix3fv(l.uOutlineNormalMatrix,!1,g),D.indices?e.drawElements(4,D.indexCount,D.indexType,0):e.drawArrays(4,0,D.indexCount)}e.bindVertexArray(null),e.cullFace(e.BACK),e.disable(e.CULL_FACE),e.depthFunc(e.LESS),e.depthMask(!0)}if(t.xrSessionActive||t.stereoSBS)return;let c=Qr(t);if(!c||c.strength<=0)return;let o=Kt(e);if(!o||!Xr(e,o,i,n)||!o.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,o.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,i,n),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(o.downProg),e.uniform1i(o.uDownSourceTex,0),e.bindVertexArray(o.fsVao);let d=o.sceneTex,a=i,u=n;for(let l=0;l<Be;l++){let h=o.mipWidth[l],f=o.mipHeight[l];e.bindFramebuffer(36160,o.bloomFbo[l]),e.viewport(0,0,h,f),e.bindTexture(3553,d),e.uniform2f(o.uDownTexelSize,1/a,1/u),e.uniform1f(o.uDownThreshold,l===0?c.threshold:0),e.drawArrays(4,0,3),d=o.bloomTex[l],a=h,u=f}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(o.upProg),e.uniform1i(o.uUpBloomTex,0),e.uniform1f(o.uUpRadius,c.radius);for(let l=Be-1;l>=1;l--){let h=l-1;e.bindFramebuffer(36160,o.bloomFbo[h]),e.viewport(0,0,o.mipWidth[h],o.mipHeight[h]),e.bindTexture(3553,o.bloomTex[l]),e.uniform2f(o.uUpTexelSize,1/o.mipWidth[l],1/o.mipHeight[l]),e.uniform1f(o.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,i,n),e.bindTexture(3553,o.bloomTex[0]),e.uniform2f(o.uUpTexelSize,1/o.mipWidth[0],1/o.mipHeight[0]),e.uniform1f(o.uUpStrength,c.strength),e.drawArrays(4,0,3),e.bindVertexArray(null),e.blendFunc(770,771),e.disable(3042),e.depthMask(!0),e.enable(2929)},onDestroy(e){let t=Le.get(e);if(t){e.deleteProgram(t.outlineProg),e.deleteProgram(t.downProg),e.deleteProgram(t.upProg),t.fsVao&&e.deleteVertexArray(t.fsVao),t.sceneTex&&e.deleteTexture(t.sceneTex);for(let r of t.bloomTex)r&&e.deleteTexture(r);for(let r of t.bloomFbo)r&&e.deleteFramebuffer(r);Le.delete(e)}}},ti=`#version 300 es
|
|
118
|
-
layout(location=0) in vec3
|
|
119
|
-
|
|
117
|
+
}`,Qe=3,Fe=new WeakMap;function sr(e,t=[.22,.74,.97]){let r=_t(e,"");if(!r.startsWith("#"))return[t[0],t[1],t[2]];let i=r.slice(1);if(i.length===3){let a=+("0x"+i[0]+i[0])/255,n=+("0x"+i[1]+i[1])/255,f=+("0x"+i[2]+i[2])/255;return[a,n,f]}if(i.length===6){let a=+("0x"+i.slice(0,2))/255,n=+("0x"+i.slice(2,4))/255,f=+("0x"+i.slice(4,6))/255;return[a,n,f]}return[t[0],t[1],t[2]]}function Pi(e,t,r=.8,i=.5){let a=Number.isFinite(t)?Math.max(0,t):0;if(a<=0)return[0,0,0];let n=Math.max(0,Number(e[0])||0),f=Math.max(0,Number(e[1])||0),c=Math.max(0,Number(e[2])||0),s=Math.max(n,f,c);if(s<=1e-6)return[0,0,0];let d=Number.isFinite(r)?Math.max(0,r):.8,o=Math.max(d*Math.max(0,i),1e-4),l=Math.max(0,Math.min(2*o,s-d+o)),u=l*l/(4*o+1e-4),m=Math.min(1,Math.max(0,Math.max(u,s-d)/Math.max(s,1e-4)))*a;return[n*m,f*m,c*m]}function Li(e,t,r,i){let a=Number(e[0])||0,n=Number(e[1])||0,f=Math.hypot(a,n);if(f<=1e-5||t<=0||r<=0)return[0,0];let c=Math.max(1,Number(i[0])||1),s=Math.max(1,Number(i[1])||1),d=Math.max(0,r)*2*t;return[a/f*(d/c),n/f*(d/s)]}var ur=new WeakSet;function fr(e){let t=Fe.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Fe.delete(e)}if(ur.has(e)||e.isContextLost?.())return null;let r=pt(e,Si,Ai,!1),i=pt(e,lr,Ii,!1),a=pt(e,lr,Ni,!1);if(!r||!i||!a){for(let f of[r,i,a])f&&e.deleteProgram(f);return ur.add(e),null}let n=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:r,uOutlineMVP:e.getUniformLocation(r,"uMVP"),uOutlineVP:e.getUniformLocation(r,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(r,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(r,"uViewportSize"),uOutlineThickness:e.getUniformLocation(r,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(r,"uOutlineColor"),downProg:i,uDownSourceTex:e.getUniformLocation(i,"uSourceTex"),uDownTexelSize:e.getUniformLocation(i,"uTexelSize"),uDownThreshold:e.getUniformLocation(i,"uThreshold"),upProg:a,uUpBloomTex:e.getUniformLocation(a,"uBloomTex"),uUpTexelSize:e.getUniformLocation(a,"uTexelSize"),uUpRadius:e.getUniformLocation(a,"uRadius"),uUpStrength:e.getUniformLocation(a,"uStrength"),fsVao:n,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Fe.set(e,t),t}function Ti(e,t,r,i){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let a=Math.max(2,r|0),n=Math.max(2,i|0);if(t.sceneTex&&t.bloomFbo.length===Qe&&t.texWidth===a&&t.texHeight===n)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,a,n,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071);let f=a,c=n;for(let s=0;s<Qe;s++)f=Math.max(1,f>>1),c=Math.max(1,c>>1),t.mipWidth[s]=f,t.mipHeight[s]=c,t.bloomTex[s]||(t.bloomTex[s]=e.createTexture()),e.bindTexture(3553,t.bloomTex[s]),e.texImage2D(3553,0,6408,f,c,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),t.bloomFbo[s]||(t.bloomFbo[s]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[s]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[s],0);return e.bindFramebuffer(36160,null),t.texWidth=a,t.texHeight=n,!0}function _i(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let i=t.getAttribute("bloom");if(i!==null){let a=i.trim().toLowerCase();if(a==="false"||a==="0"||a==="none")return null;let n=a===""||a==="true"?.35:Number(a);if(!Number.isFinite(n)||n<=0)return null;let f=Et({strength:n,threshold:or(t.getAttribute("bloom-threshold"),.62),radius:or(t.getAttribute("bloom-radius"),.75)});if(f)return f}}let r=null;for(let i of e.meshes||[]){if(i.visible===!1)continue;let a=i?.extras?.xr?.bloom??i?.userData?.xr?.bloom,n=Et(a);n&&(!r||n.strength>r.strength)&&(r=n)}return r}function Ei(e,t){if(e==null)return null;let r=e.trim(),i=r.toLowerCase();if(i==="false"||i==="0"||i==="none")return null;let a=t,n=3.5,f=!1;if(r&&i!=="true"){let c=r.split(/\s+/);for(let s of c)if(s.startsWith("#"))a=s;else if(s.toLowerCase()==="pulse")f=!0;else{let d=Number(s);Number.isFinite(d)&&d>0&&(n=d)}}return lt({color:a,thickness:n,pulse:f})}var Vi=new Set(["floor","pedestal","ground","table","grid","pad"]);function Ci(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>Vi.has(t))}function Ri(e,t){let r=e.container,i=typeof r?.getAttribute=="function"?r.getAttribute("outline"):null;if(i!=null){let o=i.trim().toLowerCase();if(o==="false"||o==="0"||o==="none")return null}let a=t?.extras?.xr?.outline??t?.userData?.xr?.outline,n=lt(a);if(n)return n;let f=typeof r?.getAttribute=="function"&&r.getAttribute("outline-color")||"#38bdf8",c=Ei(i,f),s=r!=null&&typeof r.hasAttribute=="function"&&r.hasAttribute("outline-selected")&&r.getAttribute("outline-selected")!=="false",d=e.getSelectedMesh?.()||"";if(d)return t.name!==d?null:c||(s?lt({color:f,thickness:3,pulse:!1}):null);if(c){let o=t.name||"";return Ci(o)?null:c}return null}var cr={name:"postprocessing",onAttributeChanged(e,t){(t==="bloom"||t==="bloom-threshold"||t==="bloom-radius"||t==="outline"||t==="outline-selected"||t==="outline-color"||t==="selected-mesh")&&e.viewer?.render?.()},onAfterRender(e,t,r){if(!t.meshes||t.meshes.length===0)return;let i=Math.max(1,t.canvas?.width||300),a=Math.max(1,t.canvas?.height||150),n=[];for(let u of t.meshes){if(u.visible===!1)continue;let m=Ri(t,u);m&&n.push({mesh:u,trait:m})}let f=n.length>0?fr(e):null;if(f){let u=f,m=ue(),h=ue(),p=new Float32Array(9),b=(typeof performance<"u"?performance.now():Date.now())*.001,y=typeof e.getParameter=="function"?e.getParameter(2978):null,M=Math.max(1,y?.[2]||i),g=Math.max(1,y?.[3]||a);e.useProgram(u.outlineProg),u.uOutlineViewportSize&&e.uniform2f(u.uOutlineViewportSize,M,g),u.uOutlineVP&&e.uniformMatrix4fv(u.uOutlineVP,!1,r),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(515),e.depthMask(!1);for(let{mesh:v,trait:x}of n){let[P,C,F]=sr(x.color),I=x.pulse?.8+.25*Math.sin(b*4):1;u.uOutlineColor&&e.uniform4f(u.uOutlineColor,P,C,F,1),u.uOutlineThickness&&e.uniform1f(u.uOutlineThickness,x.thickness*I),v.worldSpace===!0?m.set(v.transform):ne(m,t.modelRootMatrix,v.transform);let B=v.instanceMatrices;for(let U of v.primitives)if(!(U.pluginData?.skinning?.hasSkin||U.pluginData?.morph?.hasMorph))if(e.bindVertexArray(U.vao),B&&B.length>=16){let V=B.length>>4,k=ue();for(let O=0;O<V;O++)ne(k,m,B.subarray(O*16,O*16+16)),ne(h,r,k),$e(p,k),e.uniformMatrix4fv(u.uOutlineMVP,!1,h),e.uniformMatrix3fv(u.uOutlineNormalMatrix,!1,p),U.indices?e.drawElements(4,U.indexCount,U.indexType,0):e.drawArrays(4,0,U.indexCount)}else ne(h,r,m),$e(p,m),e.uniformMatrix4fv(u.uOutlineMVP,!1,h),e.uniformMatrix3fv(u.uOutlineNormalMatrix,!1,p),U.indices?e.drawElements(4,U.indexCount,U.indexType,0):e.drawArrays(4,0,U.indexCount)}e.bindVertexArray(null),e.cullFace(e.BACK),e.disable(e.CULL_FACE),e.depthFunc(e.LESS),e.depthMask(!0)}if(t.xrSessionActive||t.stereoSBS)return;let c=_i(t);if(!c||c.strength<=0)return;let s=fr(e);if(!s||!Ti(e,s,i,a)||!s.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,s.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,i,a),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(s.downProg),e.uniform1i(s.uDownSourceTex,0),e.bindVertexArray(s.fsVao);let d=s.sceneTex,o=i,l=a;for(let u=0;u<Qe;u++){let m=s.mipWidth[u],h=s.mipHeight[u];e.bindFramebuffer(36160,s.bloomFbo[u]),e.viewport(0,0,m,h),e.bindTexture(3553,d),e.uniform2f(s.uDownTexelSize,1/o,1/l),e.uniform1f(s.uDownThreshold,u===0?c.threshold:0),e.drawArrays(4,0,3),d=s.bloomTex[u],o=m,l=h}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(s.upProg),e.uniform1i(s.uUpBloomTex,0),e.uniform1f(s.uUpRadius,c.radius);for(let u=Qe-1;u>=1;u--){let m=u-1;e.bindFramebuffer(36160,s.bloomFbo[m]),e.viewport(0,0,s.mipWidth[m],s.mipHeight[m]),e.bindTexture(3553,s.bloomTex[u]),e.uniform2f(s.uUpTexelSize,1/s.mipWidth[u],1/s.mipHeight[u]),e.uniform1f(s.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,i,a),e.bindTexture(3553,s.bloomTex[0]),e.uniform2f(s.uUpTexelSize,1/s.mipWidth[0],1/s.mipHeight[0]),e.uniform1f(s.uUpStrength,c.strength),e.drawArrays(4,0,3),e.bindVertexArray(null),e.blendFunc(770,771),e.disable(3042),e.depthMask(!0),e.enable(2929)},onDestroy(e){let t=Fe.get(e);if(t){e.deleteProgram(t.outlineProg),e.deleteProgram(t.downProg),e.deleteProgram(t.upProg),t.fsVao&&e.deleteVertexArray(t.fsVao),t.sceneTex&&e.deleteTexture(t.sceneTex);for(let r of t.bloomTex)r&&e.deleteTexture(r);for(let r of t.bloomFbo)r&&e.deleteFramebuffer(r);Fe.delete(e)}}},gt=4,hr=9,Di=32*1024*1024,Ye=ue(),mr=new Int32Array([-1,-1]);function bt(e,t,r,i){let a=Number(e);return Number.isFinite(a)?Math.max(t,Math.min(r,a)):i}var dr=new WeakMap,ge=new WeakMap,Ue=new WeakMap,Te=ue(),Je=ue(),be=ue(),_e=ue(),pr=new Float32Array(1),Fi=new Uint32Array(pr.buffer);function gr(e){if(typeof e!="string")return"auto";let t=e.trim().toLowerCase();return t==="pcf"||t==="off"?t:"auto"}function Ui(e){let t=dr.get(e);if(t)return t;let r=1/0,i=1/0,a=1/0,n=-1/0,f=-1/0,c=-1/0;for(let d=0;d+2<e.length;d+=3){let o=e[d],l=e[d+1],u=e[d+2];o<r&&(r=o),o>n&&(n=o),l<i&&(i=l),l>f&&(f=l),u<a&&(a=u),u>c&&(c=u)}let s=Number.isFinite(r)?[r,i,a,n,f,c]:[-.5,-.5,-.5,.5,.5,.5];return dr.set(e,s),s}function Ee(e,t,r,i){let a=(e[0]+e[3])*.5,n=(e[1]+e[4])*.5,f=(e[2]+e[5])*.5,c=Math.max(0,(e[3]-e[0])*.5),s=Math.max(0,(e[4]-e[1])*.5),d=Math.max(0,(e[5]-e[2])*.5),o=t[0]*a+t[4]*n+t[8]*f+t[12],l=t[1]*a+t[5]*n+t[9]*f+t[13],u=t[2]*a+t[6]*n+t[10]*f+t[14],m=Math.abs(t[0])*c+Math.abs(t[4])*s+Math.abs(t[8])*d,h=Math.abs(t[1])*c+Math.abs(t[5])*s+Math.abs(t[9])*d,p=Math.abs(t[2])*c+Math.abs(t[6])*s+Math.abs(t[10])*d;o-m<r[0]&&(r[0]=o-m),l-h<r[1]&&(r[1]=l-h),u-p<r[2]&&(r[2]=u-p),o+m>i[0]&&(i[0]=o+m),l+h>i[1]&&(i[1]=l+h),u+p>i[2]&&(i[2]=u+p)}function br(e){let t=e||{},r=t.modelRootMatrix??Ye,i=[1/0,1/0,1/0],a=[-1/0,-1/0,-1/0];for(let l of t.meshes??[]){if(!yt(l))continue;l.worldSpace===!0?be.set(l.transform):ne(be,r,l.transform);let u=l.instanceMatrices;for(let m of l.primitives??[]){if(!m.positions||m.positions.length<3)continue;let h=Ui(m.positions);if(u&&u.length>=16){let p=u.length>>4,b=p>64?Math.ceil(p/64):1;for(let y=0;y<p;y+=b)ne(_e,be,u.subarray(y*16,y*16+16)),Ee(h,_e,i,a);if(b>1){let y=p-1;ne(_e,be,u.subarray(y*16,y*16+16)),Ee(h,_e,i,a)}}else Ee(h,be,i,a)}}if(!Number.isFinite(i[0])){let l=t.bounds;l&&Array.isArray(l.min)&&Array.isArray(l.max)&&Ee([l.min[0],l.min[1],l.min[2],l.max[0],l.max[1],l.max[2]],r,i,a)}Number.isFinite(i[0])||(i[0]=i[1]=i[2]=-1,a[0]=a[1]=a[2]=1);let n=(i[0]+a[0])*.5,f=(i[1]+a[1])*.5,c=(i[2]+a[2])*.5,s=Math.max(.03,(a[0]-i[0])*.5),d=Math.max(.03,(a[1]-i[1])*.5),o=Math.max(.03,(a[2]-i[2])*.5);return{center:[n,f,c],radius:Math.max(.05,Math.hypot(s,d,o)),min:[n-s,f-d,c-o],max:[n+s,f+d,c+o]}}function vr(e,t,r){let i=Number(t[0])||0,a=Number(t[1])||0,n=Number(t[2])||0,f=Math.hypot(i,a,n);f>1e-6?(i/=f,a/=f,n/=f):(i=.37139067,a=.74278135,n=.59422508);let c=Math.max(.05,r.radius),[s,d,o]=r.center,l=c*2.2,u=[s+i*l,d+a*l,o+n*l],m=Math.abs(a)>.99?[0,0,1]:[0,1,0];St(Te,u,r.center,m);let h=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0];Ee([...r.min,...r.max],Te,h,p);let b=Math.max(.02,c*.05),y=Math.max(.01,-p[2]-b),M=Math.max(y+.1,-h[2]+b);return $r(Je,h[0]-b,Math.max(h[0]+.05,p[0])+b,h[1]-b,Math.max(h[1]+.05,p[1])+b,y,M),ne(e,Je,Te)}function vt(e,t,r,i,a,n){let f=Number(t[0])||0,c=Number(t[1])||0,s=Number(t[2])||0,d=Number(r[0])||0,o=Number(r[1])||0,l=Number(r[2])||0,u=Math.hypot(d,o,l);u<=1e-6&&(d=n.center[0]-f,o=n.center[1]-c,l=n.center[2]-s,u=Math.hypot(d,o,l)),u>1e-6?(d/=u,o/=u,l/=u):(d=0,o=-1,l=0);let m=Math.abs(o)>.99?[0,0,1]:[0,1,0];St(Te,[f,c,s],[f+d,c+o,s+l],m);let h=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0];Ee([...n.min,...n.max],Te,h,p);let b=-p[2],y=-h[2],M=Math.max(.05,n.radius),g=Math.hypot(n.center[0]-f,n.center[1]-c,n.center[2]-s),v=Math.max(.5,y+M*.25,g+M),x=a&&a>0?Math.max(.25,Math.min(a,v)):v,P=Math.max(.02,x/1500),C=Math.min(x*.4,Math.max(P,Number.isFinite(b)?b-M*.05:P)),F=Math.max(.08,Math.min(2.35,i*2*1.04));return zr(Je,F,1,C,Math.max(C+.1,x)),ne(e,Je,Te)}function ki(e){let t=e||{};for(let g of t.meshes??[])if(g.name==="__xr_section_gizmo__"&&g.visible!==!1&&g.worldMatrix&&g.worldMatrix.length>=16){let v=g.worldMatrix,x=Math.hypot(v[8],v[9],v[10])||1,P=v[8]/x,C=v[9]/x,F=v[10]/x;return{enabled:!0,normal:[P,C,F],constant:P*v[12]+C*v[13]+F*v[14]}}let r=(t.container?.getAttribute?.("section-plane")??"").trim().toLowerCase();if(!r||r==="none"||r==="false")return null;let i=[1,0,0],a=0;if(r==="interactive")a=t.bounds?.center[0]??0;else{let g=/^([+-]?[xyz])\s*:\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)$/.exec(r);if(!g)return null;let v=g[1].startsWith("-")?-1:1,x=g[1].replace(/^[+-]/,""),P=Math.max(-1e3,Math.min(1e3,Number(g[2])||0));i=x==="x"?[v,0,0]:x==="y"?[0,v,0]:[0,0,v],a=P*v}let n=t.modelRootMatrix??Ye,f=n[0]*i[0]+n[4]*i[1]+n[8]*i[2],c=n[1]*i[0]+n[5]*i[1]+n[9]*i[2],s=n[2]*i[0]+n[6]*i[1]+n[10]*i[2],d=Math.hypot(f,c,s)||1,o=f/d,l=c/d,u=s/d,m=i[0]*a,h=i[1]*a,p=i[2]*a,b=n[0]*m+n[4]*h+n[8]*p+n[12],y=n[1]*m+n[5]*h+n[9]*p+n[13],M=n[2]*m+n[6]*h+n[10]*p+n[14];return{enabled:!0,normal:[o,l,u],constant:o*b+l*y+u*M}}function yt(e){if(e.visible===!1||e.isPluginMesh||e.name==="__contact_shadow__"||e.name==="__xr_reticle__"||e.name==="__xr_section_gizmo__")return!1;let t=e.extras?.xr??e.userData?.xr;return!(t?.splatUrl||t?.splat)}function et(e,t){if(!yt(e))return!1;let r=e.castShadow??e.extras?.shadow?.cast;return r===!1?!1:t?!0:r===!0}function yr(e,t){if(!e||typeof e!="object")return!1;let r=e;if(!yt(r))return!1;let i=r.receiveShadow??r.extras?.shadow?.receive;return i!==void 0?!!i:t}function xt(e){return!(e.isTransmissive||e.alphaMode==="BLEND"||(e.baseColor?.[3]??1)<.98)}function ve(e,t){return Math.imul((e^t>>>0)>>>0,16777619)>>>0}function ye(e,t){return pr[0]=t||0,ve(e,Fi[0])}function ke(e,t,r=64){let i=t.length;if(e=ve(e,i),i<=r)for(let a=0;a<i;a++)e=ye(e,t[a]);else{let a=Math.max(1,Math.floor(i/r));for(let n=0;n<i;n+=a)e=ye(e,t[n]);e=ye(e,t[i-1])}return e}function xr(e){let t=e||{},r=t.shadowMaps??t.container?.getAttribute?.("shadow-maps")??"auto",i=gr(r),a=[-1,-1],n=[-1,-1],f=(V=!1)=>({mode:i,mapSize:0,slices:[],dirSlots:a,ptSlots:n,promoteAllCasters:V,promoteAllReceivers:V,digest:0,sectionPlane:null});if(i==="off")return f();let c=[],s=null,d=null,o=!1,l=0,u=0;for(let V of t.lights??[])V.type==="hemisphere"?o=!0:V.type==="directional"&&l<2?(s||(s=V),V.shadow?.cast&&c.length<gt&&c.push({kind:"directional",subIdx:l,light:V}),l++):(V.type==="spot"||V.type==="point")&&u<2&&(d||(d={kind:V.type,light:V}),V.shadow?.cast&&c.length<gt&&c.push({kind:V.type,subIdx:u,light:V}),u++);if(i==="pcf"&&c.length===0&&(s?c.push({kind:"directional",subIdx:0,light:s}):o?d&&c.push({kind:d.kind,subIdx:0,light:d.light}):c.push({kind:"directional",subIdx:0,light:{type:"directional",direction:[.5,1,.8]}})),c.length===0)return f();let m=t.meshes??[],h=!1;for(let V of m)if(V.castShadow!==void 0||V.receiveShadow!==void 0||V.extras?.shadow!==void 0){h=!0;break}let p=i==="pcf"||!h,b=p,y=!1;for(let V of m)if(et(V,p)){for(let k of V.primitives??[])if(xt(k)&&k.indexCount>0){y=!0;break}if(y)break}if(!y)return f(p);let M=1024;for(let V of c){let k=V.light.shadow?.mapSize;typeof k=="number"&&Number.isFinite(k)&&(M=Math.max(M,Math.round(k)))}let g=Math.max(256,Math.min(2048,M)),v=c.length;for(;g>256&&g*g*v*4>Di;)g=Math.max(256,g>>1);let x=br(t),P=x.radius*2.2/g,C=[];for(let V=0;V<c.length;V++){let k=c[V],O=k.light,ee=O.shadow,J=ue(),q;if(k.kind==="directional"){a[k.subIdx]=V;let Z=O.direction??[.5,1,.8],Q=Math.hypot(Z[0]??.5,Z[1]??1,Z[2]??.8)||1;q=[-(Z[0]??.5)/Q,-(Z[1]??1)/Q,-(Z[2]??.8)/Q],vr(J,Z,x)}else{n[k.subIdx]=V;let Z=O.position??[0,2,0];if(k.kind==="spot"){let Q=O.direction??[0,-1,0],L=Math.hypot(Q[0]??0,Q[1]??-1,Q[2]??0)||1;q=[(Q[0]??0)/L,(Q[1]??-1)/L,(Q[2]??0)/L];let w=Math.max(.02,Math.min(Math.PI/2,O.outerConeAngle??Math.PI/3));vt(J,Z,q,w,O.range,x)}else{let Q=x.center[0]-(Z[0]??0),L=x.center[1]-(Z[1]??0),w=x.center[2]-(Z[2]??0),_=Math.hypot(Q,L,w);q=_>1e-6?[Q/_,L/_,w/_]:[0,-1,0],vt(J,Z,q,Math.PI/3,O.range,x)}}let re=bt(ee?.bias,-.05,.05,-5e-4),Ve=bt(ee?.normalBias,0,.5,.015),Me=bt(ee?.radius,0,16,1.5);C.push({slot:V,viewProj:J,rayDir:q,depthBias:re,normalBiasWorld:Ve/.015*1.75*P,uvRadius:Me*1.35/g})}let F=ki(t),I=2166136261;I=ve(I,i==="pcf"?2:1),I=ve(I,g),I=ve(I,C.length);for(let V of C)I=ke(I,V.viewProj,16),I=ye(I,V.depthBias),I=ye(I,V.normalBiasWorld);F?.enabled?(I=ve(I,1),I=ye(I,F.normal[0]),I=ye(I,F.normal[1]),I=ye(I,F.normal[2]),I=ye(I,F.constant)):I=ve(I,0);let B=t.modelRootMatrix??Ye;I=ke(I,B,16);let U=0;for(let V of m){if(!et(V,p)){U++;continue}I=ve(I,U++),I=ke(I,V.transform,16),V.instanceMatrices&&(I=ke(I,V.instanceMatrices,64));for(let k of V.primitives??[])xt(k)&&(I=ve(I,k.indexCount),k.translations&&(I=ke(I,k.translations,48)))}return I===0&&(I=1),{mode:i,mapSize:g,slices:C,dirSlots:a,ptSlots:n,promoteAllCasters:p,promoteAllReceivers:b,digest:I,sectionPlane:F}}function Oi(e){let t=ge.get(e);return t?{renderedPasses:t.renderedPasses,cacheHits:t.cacheHits,activeLights:t.activeLights,mapSize:t.allocSize}:{renderedPasses:0,cacheHits:0,activeLights:0,mapSize:0}}var Bi=`#version 300 es
|
|
118
|
+
layout(location=0) in vec3 aPos;
|
|
119
|
+
layout(location=1) in vec3 aNormal;
|
|
120
|
+
layout(location=3) in vec3 aOff;
|
|
121
|
+
layout(location=8) in vec4 aInst0;
|
|
122
|
+
layout(location=9) in vec4 aInst1;
|
|
123
|
+
layout(location=10) in vec4 aInst2;
|
|
124
|
+
layout(location=11) in vec4 aInst3;
|
|
125
|
+
uniform mat4 uLightVP,uModel;
|
|
126
|
+
uniform vec4 uBiasRay;
|
|
127
|
+
uniform int uInstanced;
|
|
128
|
+
out vec3 vWorldPos;
|
|
129
|
+
void main(){
|
|
130
|
+
mat4 m=uInstanced==1?uModel*mat4(aInst0,aInst1,aInst2,aInst3):uModel;
|
|
131
|
+
vec4 wp=m*vec4(aPos+aOff,1.0);
|
|
132
|
+
vec3 wn=mat3(m)*aNormal;
|
|
133
|
+
float nl=length(wn);
|
|
134
|
+
if(nl>1e-5&&uBiasRay.w>0.0){
|
|
135
|
+
wn/=nl;
|
|
136
|
+
wp.xyz+=wn*(uBiasRay.w*max(1.0-abs(dot(wn,uBiasRay.xyz)),0.15));
|
|
137
|
+
}
|
|
138
|
+
vWorldPos=wp.xyz;
|
|
139
|
+
gl_Position=uLightVP*wp;
|
|
140
|
+
}`,zi=`#version 300 es
|
|
141
|
+
precision highp float;
|
|
142
|
+
in vec3 vWorldPos;
|
|
143
|
+
uniform vec4 uSecPlane;
|
|
144
|
+
uniform int uSecOn;
|
|
145
|
+
void main(){
|
|
146
|
+
if(uSecOn==1&&dot(vWorldPos,uSecPlane.xyz)>uSecPlane.w)discard;
|
|
147
|
+
}`,$i=`
|
|
148
|
+
uniform highp sampler2DArrayShadow uShadowMap;
|
|
149
|
+
uniform mat4 uShadowVP[4];
|
|
150
|
+
uniform vec4 uShadowParams[4];
|
|
151
|
+
uniform int uDirShdSlot[2],uPtShdSlot[2],uReceiveShadow;
|
|
152
|
+
const vec2 _VD[8]=vec2[8](
|
|
153
|
+
vec2(0.1768,0.0),vec2(-0.2265,0.2078),vec2(0.0355,-0.4150),vec2(0.3204,0.3888),
|
|
154
|
+
vec2(-0.5562,-0.1455),vec2(0.4916,-0.3806),vec2(-0.1419,0.6596),vec2(-0.5177,-0.5150));
|
|
155
|
+
float shdEval(int s,vec3 wp,vec3 N,vec3 L){
|
|
156
|
+
if(s<0||uReceiveShadow==0)return 1.0;
|
|
157
|
+
float nl=dot(N,L);
|
|
158
|
+
if(nl<=0.0)return 0.0;
|
|
159
|
+
mat4 vp=s==0?uShadowVP[0]:s==1?uShadowVP[1]:s==2?uShadowVP[2]:uShadowVP[3];
|
|
160
|
+
vec4 p=s==0?uShadowParams[0]:s==1?uShadowParams[1]:s==2?uShadowParams[2]:uShadowParams[3];
|
|
161
|
+
vec4 sc=vp*vec4(wp+N*(p.y*(1.0-nl)),1.0);
|
|
162
|
+
if(sc.w<=1e-6)return 1.0;
|
|
163
|
+
vec3 u=sc.xyz/sc.w*0.5+0.5;
|
|
164
|
+
if(u.x<=0.002||u.x>=0.998||u.y<=0.002||u.y>=0.998||u.z>1.0||u.z<0.0)return 1.0;
|
|
165
|
+
float rz=clamp(u.z+p.x,0.0,1.0);
|
|
166
|
+
if(p.z<=1e-6)return texture(uShadowMap,vec4(u.xy,float(s),rz));
|
|
167
|
+
float a=fract(52.9829189*fract(dot(gl_FragCoord.xy,vec2(0.06711056,0.00583715))))*6.2831853;
|
|
168
|
+
float ca=cos(a),sa=sin(a),sum=0.0;
|
|
169
|
+
mat2 rot=mat2(ca,sa,-sa,ca);
|
|
170
|
+
for(int k=0;k<8;k++)sum+=texture(uShadowMap,vec4(u.xy+rot*_VD[k]*p.z,float(s),rz));
|
|
171
|
+
return sum*0.125;
|
|
172
|
+
}`,Hi=["uShadowMap","uShadowVP","uShadowParams","uDirShdSlot","uPtShdSlot","uReceiveShadow"];function ji(e){let t=ge.get(e);return t||(t={texArray:null,fbo:null,allocSize:0,allocLayers:0,lastDigest:0,renderedPasses:0,cacheHits:0,activeLights:0,vpFlat:new Float32Array(64),paramsFlat:new Float32Array(16),dirSlots:new Int32Array([-1,-1]),ptSlots:new Int32Array([-1,-1]),promoteAllReceivers:!1},ge.set(e,t)),t}function Mr(e,t,r){let i=e.createTexture?.();if(!i)return null;let a=35866;if(e.bindTexture(a,i),typeof e.texStorage3D=="function")e.texStorage3D(a,1,33190,t,t,r);else if(typeof e.texImage3D=="function")e.texImage3D(a,0,33190,t,t,r,0,6402,5125,null);else return e.deleteTexture?.(i),null;return e.texParameteri(a,10241,9729),e.texParameteri(a,10240,9729),e.texParameteri(a,10242,33071),e.texParameteri(a,10243,33071),e.texParameteri(a,34892,34894),e.texParameteri(a,34893,515),i}function wr(e){let t=Ue.get(e);if(t&&(t.prog===null||e.isProgram?.(t.prog)!==!1))return t;let r=null,i=e.createShader?.(35633),a=e.createShader?.(35632);if(i&&a){e.shaderSource(i,Bi),e.compileShader(i),e.shaderSource(a,zi),e.compileShader(a);let n=e.createProgram();n&&(e.attachShader(n,i),e.attachShader(n,a),e.linkProgram(n),e.detachShader?.(n,i),e.detachShader?.(n,a),e.getProgramParameter(n,35714)!==!1?r=n:e.deleteProgram(n)),e.deleteShader(i),e.deleteShader(a)}return t={prog:r,uLightVP:r?e.getUniformLocation(r,"uLightVP"):null,uModel:r?e.getUniformLocation(r,"uModel"):null,uBiasRay:r?e.getUniformLocation(r,"uBiasRay"):null,uInstanced:r?e.getUniformLocation(r,"uInstanced"):null,uSecPlane:r?e.getUniformLocation(r,"uSecPlane"):null,uSecOn:r?e.getUniformLocation(r,"uSecOn"):null,dummyArrayTex:Mr(e,1,1)},Ue.set(e,t),t}var Sr={uniformsGLSL:$i,dirGLSL:"*shdEval(uDirShdSlot[i],vWorldPos,N,normalize(uDirLightDir[i]))",ptGLSL:"*shdEval(uPtShdSlot[i],vWorldPos,N,L)",uniformNames:Hi,bind(e,t,r,i){let a=t.uShadowMap;if(a===void 0)return;let n=r&&typeof r=="object"?ge.get(r):void 0,f=wr(e),c=!!(n&&n.activeLights>0&&n.texArray),s=c?n.texArray:f.dummyArrayTex;s&&(e.activeTexture(33993),e.bindTexture(35866,s)),a&&e.uniform1i(a,hr);let d=t.uDirShdSlot,o=t.uPtShdSlot,l=t.uReceiveShadow;if(!c){d&&e.uniform1iv?.(d,mr),o&&e.uniform1iv?.(o,mr),l&&e.uniform1i?.(l,0);return}d&&e.uniform1iv?.(d,n.dirSlots),o&&e.uniform1iv?.(o,n.ptSlots);let u=t.uShadowVP;u&&e.uniformMatrix4fv?.(u,!1,n.vpFlat);let m=t.uShadowParams;m&&e.uniform4fv?.(m,n.paramsFlat),l&&e.uniform1i?.(l,yr(i,n.promoteAllReceivers)?1:0)}};function Ar(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}var Ir={name:"shadow-maps",onRegister(){de().shadowMapShader=Sr},onLoadModel(e){if(e&&typeof e=="object"){let t=ge.get(e);t&&(t.lastDigest=0)}},onClearScene(e){if(e&&typeof e=="object"){let t=ge.get(e);t&&(t.lastDigest=0,t.activeLights=0)}},onContextRestored(e,t){if(Ue.delete(e),t&&typeof t=="object"){let r=ge.get(t);r&&(r.texArray=null,r.fbo=null,r.allocSize=0,r.allocLayers=0,r.lastDigest=0,r.activeLights=0)}},onDestroy(e,t){if(t&&typeof t=="object"){let r=ge.get(t);r&&(r.texArray&&e.deleteTexture?.(r.texArray),r.fbo&&e.deleteFramebuffer?.(r.fbo),ge.delete(t))}else if(e){let r=Ue.get(e);r&&(r.prog&&e.deleteProgram?.(r.prog),r.dummyArrayTex&&e.deleteTexture?.(r.dummyArrayTex),Ue.delete(e))}},onBeforeDrawScene(e,t){if(!e||typeof e!="object")return;let r=e,i=de();if(i.shadowMapShader||(i.shadowMapShader=Sr),r.uRender&&!("uShadowMap"in r.uRender)&&r.recompileRenderProgram?.(),i.gpuSceneAccelerator?.willRenderScene?.(e))return;let a=ji(e),n=xr(r);if(a.promoteAllReceivers=n.promoteAllReceivers,a.dirSlots[0]=n.dirSlots[0],a.dirSlots[1]=n.dirSlots[1],a.ptSlots[0]=n.ptSlots[0],a.ptSlots[1]=n.ptSlots[1],n.slices.length===0||typeof t.framebufferTextureLayer!="function"){a.activeLights=0;return}let f=wr(t);if(!f.prog){a.activeLights=0;return}let c=n.slices.length;if(!a.texArray||!a.fbo||a.allocSize!==n.mapSize||a.allocLayers<c){a.texArray&&t.deleteTexture?.(a.texArray);let m=Math.max(a.allocLayers,c);if(a.texArray=Mr(t,n.mapSize,m),a.fbo||(a.fbo=t.createFramebuffer?.()??null),!a.texArray||!a.fbo){a.activeLights=0;return}a.allocSize=n.mapSize,a.allocLayers=m,a.lastDigest=0}a.activeLights=c,a.vpFlat.fill(0),a.paramsFlat.fill(0);for(let m of n.slices){a.vpFlat.set(m.viewProj,m.slot*16);let h=m.slot*4;a.paramsFlat[h]=m.depthBias,a.paramsFlat[h+1]=m.normalBiasWorld*.5,a.paramsFlat[h+2]=m.uvRadius}if(a.lastDigest===n.digest){a.cacheHits++;return}a.lastDigest=n.digest;let s=t.getParameter?.(36006)??null,d=t.getParameter?.(2978),o=d&&d.length>=4?[d[0],d[1],d[2],d[3]]:[0,0,Math.max(1,r.canvas?.width||1),Math.max(1,r.canvas?.height||1)],l=r.modelRootMatrix??Ye,u=r.meshes??[];t.bindFramebuffer(36160,a.fbo),t.drawBuffers?.([0]),t.readBuffer?.(0),t.viewport(0,0,n.mapSize,n.mapSize),t.colorMask?.(!1,!1,!1,!1),t.depthMask?.(!0),t.enable(2929),t.enable(32823),t.polygonOffset?.(1.5,4),t.useProgram(f.prog),f.uSecOn&&(n.sectionPlane?.enabled?(t.uniform1i(f.uSecOn,1),f.uSecPlane&&t.uniform4f(f.uSecPlane,n.sectionPlane.normal[0],n.sectionPlane.normal[1],n.sectionPlane.normal[2],n.sectionPlane.constant)):t.uniform1i(f.uSecOn,0));for(let m of n.slices){t.framebufferTextureLayer(36160,36096,a.texArray,0,m.slot),t.clear(256),f.uLightVP&&t.uniformMatrix4fv(f.uLightVP,!1,m.viewProj),f.uBiasRay&&t.uniform4f(f.uBiasRay,m.rayDir[0],m.rayDir[1],m.rayDir[2],m.normalBiasWorld);for(let h of u){if(!et(h,n.promoteAllCasters))continue;h.worldSpace===!0?be.set(h.transform):ne(be,l,h.transform);let p=h.instanceMatrices;for(let b of h.primitives??[])if(!(!b.vao||b.indexCount<=0||!xt(b)))if(t.bindVertexArray(b.vao),t.vertexAttrib3f?.(3,0,0,0),f.uInstanced&&t.uniform1i(f.uInstanced,0),f.uModel&&t.uniformMatrix4fv(f.uModel,!1,be),b.instanceCount!==void 0)t.drawElementsInstanced(4,b.indexCount,b.indexType,0,b.instanceCount);else if(p&&p.length>=16&&b.instanced&&f.uInstanced){let y=p.length>>4;t.uniform1i(f.uInstanced,1),b.indices?t.drawElementsInstanced(4,b.indexCount,b.indexType,0,y):t.drawArraysInstanced(4,0,b.indexCount,y),t.uniform1i(f.uInstanced,0)}else if(p&&p.length>=16){let y=p.length>>4;for(let M=0;M<y;M++)ne(_e,be,p.subarray(M*16,M*16+16)),f.uModel&&t.uniformMatrix4fv(f.uModel,!1,_e),Ar(t,b)}else Ar(t,b)}a.renderedPasses++}t.bindVertexArray(null),t.disable(32823),t.colorMask?.(!0,!0,!0,!0),t.bindFramebuffer(36160,s),t.viewport(o[0],o[1],o[2],o[3])}},Gi=`#version 300 es
|
|
173
|
+
layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,Wi=`#version 300 es
|
|
174
|
+
precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,Oe=new WeakMap,Nr=new Float32Array(20);function Mt(e,t){let[r,i,a,n,f,c]=t;return[e[0]*r+e[4]*i+e[8]*a+e[12],e[1]*r+e[5]*i+e[9]*a+e[13],e[2]*r+e[6]*i+e[10]*a+e[14],Math.abs(e[0])*n+Math.abs(e[4])*f+Math.abs(e[8])*c,Math.abs(e[1])*n+Math.abs(e[5])*f+Math.abs(e[9])*c,Math.abs(e[2])*n+Math.abs(e[6])*f+Math.abs(e[10])*c]}function Ki(e){if(e._lb!==void 0)return e._lb;let t=1e9,r=1e9,i=1e9,a=-1e9,n=-1e9,f=-1e9;for(let c of e.primitives||[]){let s=c.positions;if(s)for(let d=0;d<s.length;d+=3)s[d]<t&&(t=s[d]),s[d+1]<r&&(r=s[d+1]),s[d+2]<i&&(i=s[d+2]),s[d]>a&&(a=s[d]),s[d+1]>n&&(n=s[d+1]),s[d+2]>f&&(f=s[d+2])}return e._lb=t<=a?[(t+a)*.5,(r+n)*.5,(i+f)*.5,(a-t)*.5,(n-r)*.5,(f-i)*.5]:null}function qi(e){let t=Oe.get(e);if(t)return t;let r=(c,s)=>{let d=e.createShader(c);return e.shaderSource(d,s),e.compileShader(d),d},i=e.createProgram();e.attachShader(i,r(35633,Gi)),e.attachShader(i,r(35632,Wi)),e.linkProgram(i);let a=e.createVertexArray(),n=e.createBuffer(),f=e.createBuffer();return e.bindVertexArray(a),e.bindBuffer(34962,n),e.bufferData(34962,80,35048),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,5126,!1,20,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,5126,!1,20,12),e.bindBuffer(34963,f),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:i,vao:a,vbo:n,ibo:f,uMVP:e.getUniformLocation(i,"uMVP"),uIntensity:e.getUniformLocation(i,"uShadowIntensity"),uSoftness:e.getUniformLocation(i,"uShadowSoftness")},Oe.set(e,t),t}var Pr={name:"contact-shadow",onContextRestored(e){Oe.delete(e)},onAfterRender(e,t,r){let i=t.shadowIntensity;if(i<=0||!t.bounds)return;let a=qi(e),n=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,f=[],c=[];for(let h of t.meshes||[]){if(!h||h.visible===!1||h.isPluginMesh||h.name==="__xr_reticle__"||h.name?.startsWith("__xr_slot_"))continue;let p=Ki(h);if(!p)continue;h.transform&&(p=Mt(h.transform,p)),t.modelRootMatrix&&(p=Mt(t.modelRootMatrix,p));let[b,y,M,g,v,x]=p,P=[b,M,g,x,y-v,y+v];/floor|table|pedestal|ground|base|plane/i.test(h.name||"")||v<.14&&Math.min(g,x)>.45?c.push(P):f.push(P)}let s=[],d=t.bounds.center||[0,0,0],o=Math.max(.05,Number(t.bounds.radius)||.5),l=t.bounds.min,u=l?[d[0],d[1],d[2],o,Math.max(.01,d[1]-l[1]),o]:[d[0],d[1],d[2],o,o,o];t.modelRootMatrix&&(u=Mt(t.modelRootMatrix,u));let m=t.xrSessionActive&&c.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:u[1]-u[4]+.002;for(let[h,p,b,y,M]of f){let g=-1/0;for(let[x,P,C,F,,I]of c)M>=I-.08&&Math.abs(h-x)<=C&&Math.abs(p-P)<=F&&I+.002>g&&(g=I+.002);n&&(g=Math.max(g,h>=.04&&h<=.36&&p>=-.34&&p<=-.04&&M>=.01?.036:Math.hypot(h,p)<=.66&&M>=-.06?.003:-.477)),isFinite(g)||(g=m);let v=s.find(x=>Math.hypot(h-x[0],p-x[1])<.06&&Math.abs(g-x[5])<.05);v?(v[2]=Math.max(v[2],b*.78),v[3]=Math.max(v[3],y*.78),v[4]=Math.min(v[4],M)):s.push([h,p,b,y,M,g])}if(s.length===0){let h=Math.max(.1,u[3]*1.5)/1.45;s.push([u[0],u[2],h,h,m,m])}e.useProgram(a.prog),e.uniformMatrix4fv(a.uMVP,!1,r),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(a.vao),e.bindBuffer(34962,a.vbo);for(let[h,p,b,y,M,g]of s){let v=Math.max(0,M-g),x=i/(1+v*2);if(x<.02)continue;let P=1+Math.min(.75,v*.85),C=Math.max(.045,b*1.45*P),F=Math.max(.045,y*1.45*P);Nr.set([h-C,g,p-F,0,0,h+C,g,p-F,1,0,h+C,g,p+F,1,1,h-C,g,p+F,0,1]),e.bufferSubData(34962,0,Nr),e.uniform1f(a.uIntensity,x),e.uniform1f(a.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,v*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=Oe.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),Oe.delete(e))}};function Lr(e){let t=e?.extensions?.KHR_materials_variants?.variants;if(!Array.isArray(t))return[];let r=[];for(let i=0;i<t.length&&r.length<256;i++){let a=t[i]?.name;r.push(typeof a=="string"&&a.length>0?a:`Variant_${i}`)}return r}function Xi(e){let t=e?.extensions?.KHR_materials_variants?.mappings;if(!Array.isArray(t))return[];let r=[];for(let i of t){if(!i||typeof i!="object")continue;let a=i,n=Number(a.material);if(!Number.isInteger(n)||n<0)continue;let f=[];if(Array.isArray(a.variants))for(let c of a.variants){let s=Number(c);Number.isInteger(s)&&s>=0&&f.push(s)}f.length>0&&r.push({material:n,variants:f})}return r}function Zi(e,t,r,i=0){let a=e;if(a&&typeof a.selectVariant=="function"&&!Array.isArray(t))return a.selectVariant(typeof t=="string"?t:null);let n=e,f=Array.isArray(t)?t:[],c=r??null;if(!c)return i;let s=Lr(n).indexOf(c);if(s<0)return i;for(let d of f)if(d.variants.includes(s))return d.material;return i}var Tr={name:"variants",onLoadModel(e,t){let r=e.getVariantName?.();r&&e.selectVariant(r)}},_r=new WeakMap,Er={name:"webxr-suite",onConfigureXRSessionInit(e,t){let r=new Set(t.optionalFeatures||[]);r.add("hit-test"),r.add("light-estimation");let i=e?.querySelector?.('[slot="ar-overlay"]')||null;i&&(r.add("dom-overlay"),t.domOverlay={root:i},i.addEventListener?.("beforexrselect",a=>{a.preventDefault()})),t.optionalFeatures=Array.from(r)},onXRFrame(e,t,r,i){if(!e||!t||!r||!i)return;let a=_r.get(t);if(a||(a={lightProbe:null},_r.set(t,a),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(n=>{a&&n&&(a.lightProbe=n)}).catch(()=>{})),a.lightProbe&&typeof r.getLightEstimate=="function"){let n=r.getLightEstimate(a.lightProbe);if(n){let f=n.primaryLightDirection,c=n.primaryLightIntensity;if(f&&c&&Array.isArray(e.lights)){let s=e.lights.find(o=>o.type==="directional");s||(s={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(s)),s.direction=[f.x,f.y,f.z];let d=Math.max(c.x,c.y,c.z,.001);s.color=[c.x/d,c.y/d,c.z/d],s.intensity=d}n.sphericalHarmonicsCoefficients&&e.gl&&It(e.gl,n.sphericalHarmonicsCoefficients)}}}};return se(Pr),se(Ir),se(Tt),se(Lt),se(jt),se(Er),se(zt),se(nr),se(Tr),se(cr),se(Ht),kr(wt)})();
|