three-live 1.2.0 → 1.2.2
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 +6 -1
- package/dist/index.d.ts +182 -6
- package/dist/three-author-engine.js +66 -41
- package/dist/three-author.cjs +63 -39
- package/dist/three-author.d.ts +182 -6
- package/dist/three-author.js +63 -39
- package/dist/three-convert.cjs +61 -37
- package/dist/three-convert.d.ts +182 -6
- package/dist/three-convert.js +61 -37
- package/dist/three-live-animation.cjs +7 -7
- package/dist/three-live-animation.d.ts +182 -6
- package/dist/three-live-animation.js +7 -7
- package/dist/three-live-animation.min.js +7 -7
- package/dist/three-live-cad.cjs +18 -0
- package/dist/{three-live-extras.d.ts → three-live-cad.d.ts} +182 -6
- package/dist/three-live-cad.js +18 -0
- package/dist/three-live-cad.min.js +18 -0
- package/dist/three-live-element.cjs +29 -5
- package/dist/three-live-element.d.ts +182 -6
- package/dist/three-live-element.js +29 -5
- package/dist/three-live-full.cjs +159 -56
- package/dist/three-live-full.js +159 -56
- package/dist/three-live-full.min.js +159 -56
- package/dist/three-live-studio.cjs +120 -0
- package/dist/three-live-studio.d.ts +509 -0
- package/dist/three-live-studio.js +120 -0
- package/dist/three-live-studio.min.js +120 -0
- package/dist/three-live-viewer.cjs +29 -5
- package/dist/three-live-viewer.d.ts +182 -6
- package/dist/three-live-viewer.js +29 -5
- package/dist/three-live-viewer.min.js +29 -5
- package/dist/three-live.cjs +66 -42
- package/dist/three-live.js +66 -42
- package/dist/three-live.min.js +66 -42
- package/dist/three-view.cjs +29 -5
- package/dist/three-view.d.ts +182 -6
- package/dist/three-view.js +29 -5
- package/dist/three-xr.cjs +65 -41
- package/dist/three-xr.d.ts +182 -6
- package/dist/three-xr.js +65 -41
- package/package.json +10 -5
- package/dist/three-live-extras.cjs +0 -42
- package/dist/three-live-extras.js +0 -42
- package/dist/three-live-extras.min.js +0 -42
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
"use strict";var Pe=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Ct=Object.getOwnPropertyNames;var Ot=Object.prototype.hasOwnProperty;var Dt=(e,t)=>{for(var n in t)Pe(e,n,{get:t[n],enumerable:!0})},Bt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ct(t))!Ot.call(e,r)&&r!==n&&Pe(e,r,{get:()=>t[r],enumerable:!(o=Ft(t,r))||o.enumerable});return e};var zt=e=>Bt(Pe({},"__esModule",{value:!0}),e);var yn={};Dt(yn,{InteractivityVM:()=>ue,applyMeshoptFilter:()=>Me,computeOutlineClipOffset:()=>It,contactShadowPlugin:()=>Je,decodeMeshoptBuffer:()=>je,decodeMeshoptGLB:()=>ce,encodeMeshoptBuffer:()=>wt,environmentMapPlugin:()=>Ve,evaluateKawaseBloom:()=>_t,extractMaterialVariants:()=>et,extractPrimitiveVariantMappings:()=>Pt,getEnvironmentSH:()=>ft,getInteractivityVM:()=>Ae,hotspotPlugin:()=>Ce,interactivityPlugin:()=>He,materialsPlugin:()=>We,meshoptDecoder:()=>Ee,meshoptPlugin:()=>Ke,parseHexRgb:()=>Ye,parseSafeGltfPointer:()=>se,postprocessingPlugin:()=>Qe,registerMaterialShader:()=>vt,selectMaterialVariant:()=>Nt,sendInteractivityEvent:()=>Ge,setEnvironmentSH:()=>be,variantsPlugin:()=>tt,webxrPlugin:()=>nt});module.exports=zt(yn);var pe="__THREE_LIVE_REGISTRY__";function ne(){let e=typeof globalThis<"u"?globalThis:{};if(!e[pe]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,pe,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[pe]=t}}return e[pe]}var gn=ne().plugins;function q(e){let t=ne().plugins;t.some(n=>n.name===e.name)||t.push(e),e.onRegister?.()}function at(){return ne().plugins}function re(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function oe(e,t,n){let o=t[0],r=t[1],i=t[2],l=t[3],a=t[4],u=t[5],f=t[6],c=t[7],s=t[8],p=t[9],v=t[10],h=t[11],b=t[12],T=t[13],k=t[14],S=t[15],A=n[0],L=n[1],P=n[2],_=n[3];return e[0]=A*o+L*a+P*s+_*b,e[1]=A*r+L*u+P*p+_*T,e[2]=A*i+L*f+P*v+_*k,e[3]=A*l+L*c+P*h+_*S,A=n[4],L=n[5],P=n[6],_=n[7],e[4]=A*o+L*a+P*s+_*b,e[5]=A*r+L*u+P*p+_*T,e[6]=A*i+L*f+P*v+_*k,e[7]=A*l+L*c+P*h+_*S,A=n[8],L=n[9],P=n[10],_=n[11],e[8]=A*o+L*a+P*s+_*b,e[9]=A*r+L*u+P*p+_*T,e[10]=A*i+L*f+P*v+_*k,e[11]=A*l+L*c+P*h+_*S,A=n[12],L=n[13],P=n[14],_=n[15],e[12]=A*o+L*a+P*s+_*b,e[13]=A*r+L*u+P*p+_*T,e[14]=A*i+L*f+P*v+_*k,e[15]=A*l+L*c+P*h+_*S,e}function Gt(e,t,n,o){let r=t[0],i=t[1],l=t[2],a=t[3],u=r+r,f=i+i,c=l+l,s=r*u,p=r*f,v=r*c,h=i*f,b=i*c,T=l*c,k=a*u,S=a*f,A=a*c,L=o[0],P=o[1],_=o[2];return e[0]=(1-(h+T))*L,e[1]=(p+A)*L,e[2]=(v-S)*L,e[3]=0,e[4]=(p-A)*P,e[5]=(1-(s+T))*P,e[6]=(b+k)*P,e[7]=0,e[8]=(v+S)*_,e[9]=(b-k)*_,e[10]=(1-(s+h))*_,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function ie(e,t){let n=t[0],o=t[1],r=t[2],i=t[4],l=t[5],a=t[6],u=t[8],f=t[9],c=t[10],s=c*l-a*f,p=-c*i+a*u,v=f*i-l*u,h=n*s+o*p+r*v;return h&&(h=1/h,e[0]=s*h,e[1]=p*h,e[2]=v*h,e[3]=(-c*o+r*f)*h,e[4]=(c*n-r*u)*h,e[5]=(-f*n+o*u)*h,e[6]=(a*o-r*l)*h,e[7]=(-a*n+r*i)*h,e[8]=(l*n-o*i)*h),e}function st(e,t){let n=t[0],o=t[1],r=t[2],i=t[3],l=t[4],a=t[5],u=t[6],f=t[7],c=t[8],s=t[9],p=t[10],v=t[11],h=t[12],b=t[13],T=t[14],k=t[15],S=n*a-o*l,A=n*u-r*l,L=n*f-i*l,P=o*u-r*a,_=o*f-i*a,N=r*f-i*u,D=c*b-s*h,V=c*T-p*h,O=c*k-v*h,j=s*T-p*b,X=s*k-v*b,J=p*k-v*T,G=S*J-A*X+L*j+P*O-_*V+N*D;return G?(G=1/G,e[0]=(a*J-u*X+f*j)*G,e[1]=(r*X-o*J-i*j)*G,e[2]=(b*N-T*_+k*P)*G,e[3]=(p*_-s*N-v*P)*G,e[4]=(u*O-l*J-f*V)*G,e[5]=(n*J-r*O+i*V)*G,e[6]=(T*L-h*N-k*A)*G,e[7]=(c*N-p*L+v*A)*G,e[8]=(l*X-a*O+f*D)*G,e[9]=(o*O-n*X-i*D)*G,e[10]=(h*_-b*L+k*S)*G,e[11]=(s*L-c*_-v*S)*G,e[12]=(a*V-l*j-u*D)*G,e[13]=(n*j-o*V+r*D)*G,e[14]=(b*A-h*P-T*S)*G,e[15]=(c*P-s*A+p*S)*G,e):null}function Ne(e,t){let n=Array.isArray(e?.nodes)?e.nodes.length:0,o=[];for(let c=0;c<n;c++)o.push(re());if(n===0)return o;let r=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let s of c.children)r.add(s);let i=new Set,l=128,a=(c,s,p=0)=>{if(p>l||c<0||c>=n||i.has(c))return;i.add(c);let v=e.nodes[c];if(!v)return;let h=re();if(t&&t[c])h.set(t[c]);else if(v.matrix&&v.matrix.length===16)h.set(v.matrix);else{let T=v.translation||[0,0,0],k=v.rotation||[0,0,0,1],S=v.scale||[1,1,1];Gt(h,k,T,S)}let b=o[c];if(s?oe(b,s,h):b.set(h),Array.isArray(v.children))for(let T of v.children)typeof T=="number"&&a(T,b,p+1)},u=[],f=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(f&&Array.isArray(f.nodes))u.push(...f.nodes);else for(let c=0;c<n;c++)r.has(c)||u.push(c);for(let c of u)a(c,null);for(let c=0;c<n;c++)!r.has(c)&&!u.includes(c)&&a(c,null);return o}var ke=new WeakMap;function be(e,t){let n=t instanceof Float32Array?t:new Float32Array(t);ke.set(e,n)}function ft(e){return ke.get(e)}async function Ht(e,t){if(!t)return null;let n;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let i=await(await fetch(t)).blob();n=await createImageBitmap(i)}else if(typeof Image<"u")n=await new Promise((r,i)=>{let l=new Image;l.crossOrigin="anonymous",l.onload=()=>r(l),l.onerror=i,l.src=t});else return null;else n=t;let o=e.createTexture();return e.bindTexture(3553,o),e.texImage2D(3553,0,6408,6408,5121,n),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),o}var ut=new WeakMap,lt=new Float32Array(16);async function ct(e,t,n){let o=n?await Ht(e.gl,n):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=o}var Ve={name:"environment-map",setEnvironmentImage(e,t){return ct(e,"environmentTexture",t)},setSkyboxImage(e,t){return ct(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,n,o,r){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let i=ut.get(t);if(!i){let s=(h,b)=>{let T=t.createShader(h);return t.shaderSource(T,b),t.compileShader(T),T},p=t.createProgram();t.attachShader(p,s(35633,`#version 300 es
|
|
18
|
+
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(p,s(35632,`#version 300 es
|
|
19
|
+
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(p);let v=typeof t.createVertexArray=="function"?t.createVertexArray():null;i={program:p,vao:v},ut.set(t,i)}let l=st(lt,n)||lt;t.depthMask(!1),t.useProgram(i.program),i.vao&&t.bindVertexArray(i.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let a=t.getUniformLocation(i.program,"uSkyboxMap");a&&t.uniform1i(a,0);let u=t.getUniformLocation(i.program,"uInvVP");u&&t.uniformMatrix4fv(u,!1,l);let f=t.getUniformLocation(i.program,"uCameraPos");f&&t.uniform3f(f,o[0],o[1],o[2]);let c=t.getUniformLocation(i.program,"uExposure");c&&t.uniform1f(c,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,n,o){if(o.includes("evalSHIrradiance"))return null;let r=o.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
|
|
20
|
+
uniform int uHasSH;
|
|
21
|
+
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);}
|
|
22
|
+
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));}
|
|
23
|
+
void main(){`);return r=r.replace(`if(uHasEnvironmentMap==1){
|
|
24
|
+
specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
|
|
25
|
+
envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
|
|
26
|
+
}`,`if(uHasEnvironmentMap==1){
|
|
27
|
+
specularIBL=textureLod(uEnvironmentMap,equirectangularUV(R),clamp(roughness*6.0,0.0,6.0)).rgb*integrateBRDFApprox(F,roughness,NoV);
|
|
28
|
+
envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangularUV(N),5.0).rgb;
|
|
29
|
+
}else if(uHasSH==1){
|
|
30
|
+
specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
|
|
31
|
+
envDiffuse=evalSHIrradiance(N);
|
|
32
|
+
}`),{vs:n,fs:r}},onBeforeDrawPrimitive(e,t,n,o,r,i){let l=ke.get(e),a=e.getUniformLocation(t,"uHasSH");if(l&&l.length>=27){a&&e.uniform1i(a,1);let u=e.getUniformLocation(t,"uSH");u&&e.uniform3fv(u,l)}else a&&e.uniform1i(a,0)},onAttributeChanged(e,t,n,o){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,o):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,o)}};var Ue=new WeakMap;function Fe(e,t){let n=t||e.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let o=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let r=0;r<o.length;r++){let i=o[r],l=i.getAttribute("data-position");if(!l)continue;let a=l.trim().split(/\s+/).map(s=>parseFloat(s.replace(/m$/,"")));if(a.length<3||a.some(isNaN))continue;let u=i.getAttribute("data-normal"),f;if(u){let s=u.trim().split(/\s+/).map(p=>parseFloat(p));s.length>=3&&!s.some(isNaN)&&(f=[s[0],s[1],s[2]])}let c=n.projectPointToScreen([a[0],a[1],a[2]],f);i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.transform=`translate(-50%, -50%) translate3d(${c.x}px, ${c.y}px, 0)`,i.style.zIndex="3",c.visible?(i.style.opacity="1",i.style.pointerEvents="auto",i.removeAttribute("data-occluded")):(i.style.opacity="0",i.style.pointerEvents="none",i.setAttribute("data-occluded",""))}}var Ce={name:"hotspots",updateHotspotsForElement:Fe,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{Fe(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Ue.set(e,t)},onCameraChange(e,t){t&&Fe(t,e)},onElementDisconnected(e){let t=Ue.get(e);t&&(t.disconnect(),Ue.delete(e))}};function Q(e,t,n,o){let r=typeof e=="number"&&Number.isFinite(e)?e:o;return Math.max(t,Math.min(n,r))}function Xt(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function Oe(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function Wt(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function mt(e){let t=Oe(e);if(!t)return null;let n=t.target;return{target:Xt(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:Q(t.radius,.01,50,.5),speed:Q(t.speed,-20,20,.5),height:Q(t.height,-10,10,0),phase:Q(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}function he(e,t){let n=Wt(e,16)?.trim();if(!n)return t;let o=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return o?`#${o[1].toLowerCase()}`:t}function De(e){if(e===!1||e===null||e===void 0)return null;if(typeof e=="number")return!Number.isFinite(e)||e<=0?null:{enabled:!0,strength:Q(e,0,5,.35),threshold:.8,radius:.5};if(e===!0)return{enabled:!0,strength:.35,threshold:.8,radius:.5};let t=Oe(e);if(!t||t.enabled===!1)return null;let n=Q(t.strength??t.intensity,0,5,.35);return n<=0?null:{enabled:!0,strength:n,threshold:Q(t.threshold,0,4,.8),radius:Q(t.radius,0,2,.5)}}function ye(e){if(!e)return null;if(typeof e=="string")return{enabled:!0,color:he(e,"#38bdf8"),thickness:3,pulse:!1};if(e===!0)return{enabled:!0,color:"#38bdf8",thickness:3,pulse:!1};let t=Oe(e);return!t||t.enabled===!1?null:{enabled:!0,color:he(t.color,"#38bdf8"),thickness:Q(t.thickness??t.width,.5,20,3),pulse:t.pulse===!0}}function dt(e,t,n,o){let r=t[0],i=t[1],l=t[2],a=t[3],u=n[0],f=n[1],c=n[2],s=n[3],p=r*u+i*f+l*c+a*s;if(p<0&&(u=-u,f=-f,c=-c,s=-s,p=-p),Math.abs(p)>=1)return e[0]=r,e[1]=i,e[2]=l,e[3]=a,e;let v=Math.acos(p),h=Math.sqrt(1-p*p);if(Math.abs(h)<.001)return e[0]=.5*(r+u),e[1]=.5*(i+f),e[2]=.5*(l+c),e[3]=.5*(a+s),e;let b=Math.sin((1-o)*v)/h,T=Math.sin(o*v)/h;return e[0]=r*b+u*T,e[1]=i*b+f*T,e[2]=l*b+c*T,e[3]=a*b+s*T,e}var pt=1024,Be=256,xe=2048,$t=128,jt=64,Kt=16,qt=1e4,Yt=8,Z=new Set(["__proto__","constructor","prototype"]),bt={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))},ht={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},ge={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Te=(e,t)=>e!==null&&typeof e=="object"&&!Z.has(t)&&Object.prototype.hasOwnProperty.call(e,t),W=e=>Array.isArray(e)?[...e]:e,Tt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Te(e,"value")?e.value:e,z=(e,t)=>Te(e.configuration,t)?Tt(e.configuration[t]):void 0,R=(e,t=0)=>{let n=Number(e);return Number.isFinite(n)?n:t},ee=e=>Math.max(0,Math.min(1,e)),$=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function se(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let n of e.slice(1).split("/")){let o=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!o||Z.has(o)||Z.has(n))return null;t.push(o)}return{segments:t}}var ae=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let n=Number(e);return Number.isSafeInteger(n)&&n>=0&&n<t?n:-1},yt=e=>{let t=R(e[0]),n=R(e[1]),o=R(e[2]),r=R(e[3],1),i=Math.hypot(t,n,o,r);return i>1e-8?[t/i,n/i,o/i,r/i]:[0,0,0,1]},xt=(e,t,n,o)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*n;if(Array.isArray(e)&&Array.isArray(t)){if(o&&e.length===4&&t.length===4){let r=[0,0,0,1];return dt(r,yt(e),yt(t),n),r}return e.slice(0,t.length).map((r,i)=>r+(t[i]-r)*n)}return n>=.5?t:e},ze=(e,t,n)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((o,r)=>n(R(o),R(t[r]))):Array.isArray(e)?e.map(o=>n(R(o),R(t))):Array.isArray(t)?t.map(o=>n(R(e),R(o))):n(R(e),R(t)),Qt=(e,t)=>Array.isArray(e)?e.map(n=>t(R(n))):t(R(e)),gt=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,o)=>Math.abs(n-t[o])<=1e-6):e===t,ue=class{constructor(t,n,o){let r=Array.isArray(o.nodes)?o.nodes:[];if(r.length>pt)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${pt})`);let i=Array.isArray(o.variables)?o.variables:[];if(i.length>Be)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Be})`);let l=Array.isArray(o.declarations)?o.declarations:[],a=Array.isArray(o.events)?o.events:[],u=new Map,f=new Map,c=new Map,s=new Map,p=new Map,v=new Map,h=[],b=[],T=new Map,k=1,S=0,A=0,L=0,P=0,_=!1,N=!1,D=!1;i.forEach((x,g)=>{if(!x||typeof x!="object")return;let E=W(Tt(x.value));u.set(g,E);let w=x.id??x.name;typeof w=="string"&&w&&!Z.has(w)&&u.set(w,E)}),(n?.nodes||[]).forEach((x,g)=>{for(let E of x?.children||[])typeof E=="number"&&T.set(E,g)});let V=x=>x.op||typeof x.declaration=="number"&&l[x.declaration]?.op||"",O=(x,g,E)=>{if(Z.has(g))return;let w=f.get(x);w||f.set(x,w=Object.create(null)),w[g]=E},j=(x,g)=>{if(typeof x!="number"&&typeof x!="string"||typeof x=="string"&&Z.has(x)||!u.has(x)&&u.size>=Be*2)return;let E=W(g);if(u.set(x,E),typeof x=="number"){let w=i[x]?.id??i[x]?.name;typeof w=="string"&&!Z.has(w)&&u.set(w,E)}},X=x=>typeof x=="number"?a[x]?.id??String(x):typeof x=="string"?/^\d+$/.test(x)&&a[Number(x)]?.id?a[Number(x)].id:x:"",J=(x,g)=>{for(let E=x,w=0;E!==void 0&&E>=0&&w<128;E=T.get(E),w++)if(E===g)return!0;return!1},G=x=>{for(let g=h.length-1;g>=0;g--)h[g].key===x&&h.splice(g,1)},rt=x=>{G(x.key),h.length>=$t&&h.shift(),h.push(x)},_e=x=>{let g=se(x)?.segments;if(g){if(g[0]==="nodes"&&Array.isArray(n?.nodes)){let E=n.nodes[ae(g[1],n.nodes.length)];if(!E)return;let w=g[2];if(w in ge){let y=ge[w],m=E[w]||y;return y.map((d,M)=>R(m[M],d))}if(w==="weights"){let y=Array.isArray(E.weights)?E.weights:[0],m=g.length===4?ae(g[3],64):-2;return m===-2?y.map(d=>R(d)):m>=0?R(y[m]):void 0}if(w==="visible"||w==="extensions"&&g[3]==="KHR_node_visibility"&&g[4]==="visible")return E.extensions?.KHR_node_visibility?.visible??E.visible??!0}else if(g[0]==="materials"&&Array.isArray(n?.materials)){let E=n.materials[ae(g[1],n.materials.length)];if(!E)return;let w=E.pbrMetallicRoughness||{};if(g[2]==="pbrMetallicRoughness"){if(g[3]==="baseColorFactor"){let y=w.baseColorFactor||[1,1,1,1];return[R(y[0],1),R(y[1],1),R(y[2],1),R(y[3],1)]}if(g[3]==="metallicFactor"||g[3]==="roughnessFactor")return R(w[g[3]],1)}if(g[2]==="emissiveFactor"){let y=E.emissiveFactor||[0,0,0];return[R(y[0]),R(y[1]),R(y[2])]}if(g[2]==="alphaCutoff")return R(E.alphaCutoff,.5)}}},fe=(x,g)=>{let E=se(x)?.segments;if(!E)return!1;if(E[0]==="nodes"&&Array.isArray(n?.nodes)){let w=ae(E[1],n.nodes.length),y=n.nodes[w];if(!y)return!1;let m=E[2];if(m in ge&&Array.isArray(g)){let d=ge[m];if(g.length<d.length)return!1;let M=d.map((C,B)=>R(g[B],C));if(m==="rotation"){let C=Math.hypot(...M);M=C>1e-8?M.map(B=>B/C):[0,0,0,1]}y[m]=M,delete y.matrix;let F=t?.initialNodeTransforms?.[w];return F&&(F[m[0]]=[...M]),_=!0,!0}if(m==="weights"){Array.isArray(y.weights)||(y.weights=[]);let d=(M,F)=>{for(let C of t?.meshes||[])if(C.nodeIndex===w)for(let B of C.primitives||[])B.pluginData?.morph?.weights&&(B.pluginData.morph.weights[M]=F)};if(E.length===4){let M=ae(E[3],64);if(M<0)return!1;d(M,y.weights[M]=R(g))}else if(Array.isArray(g))y.weights=g.slice(0,64).map(M=>R(M)),y.weights.forEach((M,F)=>d(F,M));else return!1;return D=!0,!0}if(m==="visible"||m==="extensions"&&E[3]==="KHR_node_visibility"&&E[4]==="visible"){let d=$(g);return y.visible=d,(!y.extensions||typeof y.extensions!="object")&&(y.extensions={}),y.extensions.KHR_node_visibility={visible:d},N=!0,!0}}else if(E[0]==="materials"&&Array.isArray(n?.materials)){let w=ae(E[1],n.materials.length),y=n.materials[w];if(!y)return!1;let m=y.pbrMetallicRoughness||(y.pbrMetallicRoughness={}),d=M=>{for(let F of t?.meshes||[])for(let C of F.primitives||[])(C.materialIndex??0)===w&&M(C)};if(E[2]==="pbrMetallicRoughness"){if(E[3]==="baseColorFactor"&&Array.isArray(g)&&g.length>=3){let M=[ee(R(g[0],1)),ee(R(g[1],1)),ee(R(g[2],1)),g[3]!==void 0?ee(R(g[3],1)):m.baseColorFactor?.[3]??1];return m.baseColorFactor=M,d(F=>F.baseColor=[...M]),D=!0}if(E[3]==="metallicFactor"||E[3]==="roughnessFactor"){let M=E[3]==="metallicFactor",F=ee(R(g,M?0:.5));return m[E[3]]=F,d(C=>C[M?"metallic":"roughness"]=F),D=!0}}if(E[2]==="emissiveFactor"&&Array.isArray(g)&&g.length>=3)return y.emissiveFactor=[0,1,2].map(M=>Math.max(0,R(g[M]))),D=!0;if(E[2]==="alphaCutoff")return y.alphaCutoff=ee(R(g,.5)),D=!0}return!1},Ie=(x,g,E=new Set)=>{let w=z(g,"pointer");if(typeof w!="string"||!w.startsWith("/"))return null;let y=w.replace(/\{([a-zA-Z0-9_]+)\}/g,(m,d)=>{let M=Math.trunc(Number(me(x,d,void 0,E)??z(g,d)));return Number.isSafeInteger(M)&&M>=0?String(M):"-1"});return se(y)?y:null},me=(x,g,E,w)=>{let y=r[x]?.values;if(!Te(y,g))return E;let m=y[g];if(m==null)return E;if(typeof m!="object"||Array.isArray(m))return W(m);let d=m;return typeof d.node=="number"?Vt(d.node,d.socket||"value",w):Te(d,"value")?W(d.value):E},Vt=(x,g,E)=>{if(x<0||x>=r.length||E.has(x)||E.size>128||++L>qt)return;let w=r[x],y=V(w);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(y))return W(f.get(x)?.[g]);E.add(x);try{let m=(d,M=0)=>me(x,d,M,E);if(y==="variable/get"){let d=z(w,"variable")??z(w,"id");return typeof d=="number"||typeof d=="string"?W(u.get(d)):void 0}if(y==="pointer/get"){let d=Ie(x,w,E);return d?_e(d):void 0}if(y.startsWith("math/")){let d=y.slice(5);if(d in bt)return Qt(m("a"),bt[d]);if(d in ht){let M=/^(mul|div|rem|mod|pow)$/.test(d)?1:0;return ze(m("a",d==="mul"?1:0),m("b",M),ht[d])}if(d==="pi")return Math.PI;if(d==="e")return Math.E;if(d==="random")return Math.random();if(d==="clamp")return ze(ze(m("a"),m("b",m("min",0)),Math.max),m("c",m("max",1)),Math.min);if(d==="mix"||d==="quatSlerp")return xt(m("a",0),m("b",1),R(m("c",m("t",.5)),.5),d==="quatSlerp");if(d==="dot"){let M=m("a"),F=m("b");return Array.isArray(M)&&Array.isArray(F)?M.reduce((C,B,I)=>C+(B||0)*(F[I]||0),0):R(M)*R(F)}if(d==="cross"){let M=m("a",[0,0,0]),F=m("b",[0,0,0]);return Array.isArray(M)&&Array.isArray(F)?[(M[1]||0)*(F[2]||0)-(M[2]||0)*(F[1]||0),(M[2]||0)*(F[0]||0)-(M[0]||0)*(F[2]||0),(M[0]||0)*(F[1]||0)-(M[1]||0)*(F[0]||0)]:[0,0,0]}if(d==="length"){let M=m("a");return Array.isArray(M)?Math.hypot(...M):Math.abs(R(M))}if(d==="distance"){let M=m("a"),F=m("b");return Array.isArray(M)&&Array.isArray(F)?Math.hypot(...M.map((C,B)=>(C||0)-(F[B]||0))):Math.abs(R(M)-R(F))}if(d==="normalize"){let M=m("a");if(!Array.isArray(M))return R(M)>=0?1:-1;let F=Math.hypot(...M);return F>1e-8?M.map(C=>C/F):M.map(()=>0)}if(d.startsWith("combine"))return["a","b","c","d"].slice(0,Number(d[7])||2).map(M=>R(m(M)));if(d.startsWith("extract")){let M=m("a");return Array.isArray(M)?M[g==="0"||g==="x"?0:g==="1"||g==="y"?1:g==="2"||g==="z"?2:3]??0:0}if(d==="eq")return gt(m("a"),m("b"));if(d==="ne")return!gt(m("a"),m("b"));if(d==="lt")return R(m("a"))<R(m("b"));if(d==="le")return R(m("a"))<=R(m("b"));if(d==="gt")return R(m("a"))>R(m("b"));if(d==="ge")return R(m("a"))>=R(m("b"));if(d==="isNaN")return Number.isNaN(Number(m("a")));if(d==="isInf"){let M=Number(m("a"));return!Number.isFinite(M)&&!Number.isNaN(M)}return d==="and"?$(m("a",!1))&&$(m("b",!1)):d==="or"?$(m("a",!1))||$(m("b",!1)):d==="xor"?$(m("a",!1))!==$(m("b",!1)):d==="not"?!$(m("a",!1)):d==="select"?W($(m("condition",!1))?m("a"):m("b")):void 0}return y==="type/boolToInt"||y==="type/boolToFloat"?$(m("a",!1))?1:0:y==="type/intToBool"||y==="type/floatToBool"?R(m("a",0))!==0:y==="type/intToFloat"?R(m("a",0)):y==="type/floatToInt"?Math.trunc(R(m("a",0))):void 0}finally{E.delete(x)}},de=()=>{if(_){_=!1,D=!0;let x=Ne(n);if(t){t.worldMatrices=x;for(let g of t.meshes||[])g.nodeIndex>=0&&g.nodeIndex<x.length&&(g.transform.set(x[g.nodeIndex]),ie(g.normalMatrix,g.transform))}}if(N){N=!1,D=!0;let x=n?.nodes;if(Array.isArray(t?.meshes)&&Array.isArray(x))for(let g of t.meshes){let E=!0;for(let w=g.nodeIndex,y=0;w!==void 0&&w>=0&&y<128;w=T.get(w),y++){let m=x[w];if(m?.visible===!1||m?.extensions?.KHR_node_visibility?.visible===!1){E=!1;break}}g.visible=E}}D&&(D=!1,t?.render?.())},te=(x,g={steps:0})=>{if(!x||typeof x.node!="number")return;g.steps===0&&(L=0);let E=[x],w=y=>{E.length+g.steps<xe&&E.push(y)};for(;E.length>0&&g.steps<xe;){g.steps++;let y=E.shift();if(!y||y.node<0||y.node>=r.length)continue;let m=y.node,d=r[m];if(!d)continue;let M=y.socket||"in",F=V(d),C=(I,U=void 0)=>me(m,I,U,new Set),B=(I="out")=>{let U=d.flows?.[I];U&&w(U)};switch(F){case"flow/branch":B($(C("condition",!1))?"true":"false");break;case"flow/sequence":for(let I of Object.keys(d.flows||{}).sort((U,H)=>Number(U)-Number(H)||U.localeCompare(H)))B(I);break;case"flow/switch":{let I=d.flows?.[String(C("selection",C("value",0)))]??d.flows?.default;I&&w(I);break}case"flow/for":{let I=Math.trunc(R(C("startIndex",0))),U=Math.trunc(R(C("endIndex",0))),H=Math.max(1,Math.trunc(R(C("step",1),1))),K=d.flows?.body;if(K&&U>I&&P<Yt){let Ut=Math.min(Math.ceil((U-I)/H),xe);P++;try{for(let Le=0;Le<Ut&&g.steps<xe;Le++)O(m,"index",I+Le*H),te(K,g)}finally{P--}}let it=d.flows?.completed??d.flows?.out;it&&w(it);break}case"flow/doN":{let I=M==="reset"?0:(c.get(m)||0)+1;if(c.set(m,I),O(m,"currentCount",I),O(m,"count",I),M!=="reset"){let U=Math.trunc(R(C("n",z(d,"stopIterations")??z(d,"n")??1),1));I<=U&&B()}break}case"flow/multiGate":{if(M==="reset"){v.set(m,0);break}let I=Object.keys(d.flows||{}).sort();if(!I.length)break;let U=z(d,"isRandom")?Math.floor(Math.random()*I.length):v.get(m)||0;U<I.length&&(B(I[U]),v.set(m,z(d,"isLoop")!==!1?(U+1)%I.length:U+1));break}case"flow/waitAll":{if(M==="reset"){s.delete(m);break}let I=s.get(m);I||s.set(m,I=new Set),I.add(M),I.size>=Math.max(1,Math.trunc(Number(z(d,"inputFlows")??2)||2))&&(I.clear(),B("out"),B("completed"));break}case"flow/throttle":{if(M==="reset"){p.delete(m);break}let I=Math.max(0,R(C("duration",0))),U=p.get(m);U===void 0||S-U>=I?(p.set(m,S),O(m,"lastRemainingTime",0),B()):O(m,"lastRemainingTime",Math.max(0,I-(S-U)));break}case"flow/delay":case"flow/setDelay":{if(M==="cancel"){for(let K=b.length-1;K>=0;K--)b[K].nodeIdx===m&&b.splice(K,1);O(m,"lastDelayIndex",-1);break}let I=Math.max(0,R(C("duration",z(d,"duration")??0))),U=d.flows?.done??d.flows?.out;if(I<=0){O(m,"lastDelayIndex",-1),U&&w(U);break}b.length>=jt&&b.shift();let H=k++;O(m,"lastDelayIndex",H),b.push({id:H,nodeIdx:m,rem:I,done:U}),F==="flow/setDelay"&&d.flows?.out&&d.flows?.done&&B("out");break}case"flow/cancelDelay":{let I=Math.trunc(R(C("delayIndex",-1),-1));if(I<0)b.length=0;else for(let U=b.length-1;U>=0;U--)b[U].id===I&&b.splice(U,1);B();break}case"variable/set":j(z(d,"variable")??z(d,"id"),C("value")),B();break;case"variable/interpolate":{let I=z(d,"variable")??z(d,"id"),U=C("value",C("target")),H=Math.max(0,R(C("duration",z(d,"duration")??.3),.3));I!==void 0&&U!==void 0&&rt({key:`var:${String(I)}`,varKey:I,from:W(C("from")??u.get(I)??0),to:W(U),dur:H,elapsed:0,quat:!1,linear:z(d,"easing")==="linear",done:d.flows?.done}),B();break}case"pointer/set":{let I=Ie(m,d),U=C("value");I&&U!==void 0&&(G(`ptr:${I}`),fe(I,U)),B();break}case"pointer/interpolate":{let I=Ie(m,d),U=C("value",C("target")),H=Math.max(0,R(C("duration",z(d,"duration")??.3),.3));if(I&&U!==void 0){let K=C("from")??_e(I);K!==void 0&&(H<=0?(fe(I,U),B("done")):rt({key:`ptr:${I}`,ptr:I,from:W(K),to:W(U),dur:H,elapsed:0,quat:I.endsWith("/rotation"),linear:z(d,"easing")==="linear",done:d.flows?.done}))}B();break}case"animation/start":{let I=C("animation")??z(d,"animation")??z(d,"clipName"),U=typeof I=="number"?t?.animations?.[I]?.name??n?.animations?.[I]?.name:typeof I=="string"?I:void 0;t?.playAnimation?.(U),D=!0,B();break}case"animation/stop":case"animation/resetAt":t?.pauseAnimation?.(),F==="animation/resetAt"&&t?.evaluateAnimation?.(R(C("time",0))),D=!0,B();break;case"event/send":case"customEvent/send":{let I=X(z(d,"event")??z(d,"id")),U={};for(let H of Object.keys(d.values||{}))Z.has(H)||(U[H]=C(H));I&&(typeof CustomEvent<"u"&&typeof t?.container?.dispatchEvent=="function"&&t.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:I,values:U}})),ot(I,U,g)),B();break}default:B();break}}};this.readScenePointer=_e,this.writeScenePointer=fe,this.fireOnStart=()=>{r.forEach(x=>{V(x)==="event/onStart"&&te(x.flows?.out)}),de()},this.fireOnSelect=x=>{if(!x)return;let g=typeof x.meshIndex=="number"?x.meshIndex:-1,E=typeof x.nodeIndex=="number"?x.nodeIndex:t?.meshes?.[g]?.nodeIndex??-1;r.forEach((w,y)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(V(w)))return;let m=z(w,"nodeIndex")??z(w,"node")??me(y,"nodeIndex",void 0,new Set),d=z(w,"meshName");if(typeof d=="string"&&d?x.meshName===d:m==null||Number(m)<0||Number.isNaN(Number(m))||J(E,Math.trunc(Number(m)))){if(O(y,"nodeIndex",E),O(y,"meshIndex",g),Array.isArray(x.hitPoint)){let F=[R(x.hitPoint[0]),R(x.hitPoint[1]),R(x.hitPoint[2])];O(y,"hitPoint",F),O(y,"point",F),O(y,"intersectionPoint",F)}if(Array.isArray(x.normal)){let F=[R(x.normal[0]),R(x.normal[1],1),R(x.normal[2])];O(y,"normal",F),O(y,"hitNormal",F)}typeof x.distance=="number"&&O(y,"distance",x.distance),te(w.flows?.out)}}),de()},this.receiveCustomEvent=(x,g={})=>ot(x,g,{steps:0});function ot(x,g,E){if(!(A>=Kt)){A++;try{let w=X(x);r.forEach((y,m)=>{if(!/^(customE|e)vent\/receive$/.test(V(y)))return;let d=z(y,"event")??z(y,"id");if(!(X(d)!==w&&String(d)!==String(x))){for(let[M,F]of Object.entries(g))Z.has(M)||O(m,M,W(F));te(y.flows?.out,E)}}),de()}finally{A--}}}this.tick=x=>{if(!Number.isFinite(x)||x<0)return;let g=Math.min(x,.25);S+=g,r.forEach((w,y)=>{V(w)==="event/onTick"&&(O(y,"timeDelta",g),O(y,"dt",g),O(y,"timeElapsed",S),te(w.flows?.out))});let E=[];for(let w=h.length-1;w>=0;w--){let y=h[w];y.elapsed+=g;let m=y.dur>1e-6?ee(y.elapsed/y.dur):1,d=y.linear?m:m*m*(3-2*m),M=xt(y.from,y.to,d,y.quat);y.ptr?fe(y.ptr,M):y.varKey!==void 0&&j(y.varKey,M),m>=1&&(h.splice(w,1),y.done&&E.push(y.done))}for(let w=b.length-1;w>=0;w--){let y=b[w];y.rem-=g,y.rem<=0&&(b.splice(w,1),y.done&&E.push(y.done))}for(let w of E)te(w);de()},this.dispose=()=>{h.length=0,b.length=0,u.clear(),f.clear(),c.clear(),s.clear(),p.clear(),v.clear()}}},Y=new WeakMap,ve=new WeakMap;function Zt(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||at().some(u=>u.name==="xr-live-head-follow")||(typeof e.getAutoRotate=="function"?e.getAutoRotate():e.autoRotate)===!1)return;let o=e.gltf,r=o?.nodes;if(!Array.isArray(r)||r.length===0)return;let i=Math.min(t,.1),l=(ve.get(e)||0)+i,a=!1;for(let u=0;u<r.length;u++){let f=r[u],c=mt(f?.extras?.xr?.orbit);if(!c)continue;let s=0,p=0,v=0;if(Array.isArray(c.target))s=c.target[0],p=c.target[1],v=c.target[2];else if(typeof c.target=="string"&&c.target!=="head"){let S=r.find(A=>A?.name===c.target);Array.isArray(S?.translation)&&(s=R(S.translation[0]),p=R(S.translation[1]),v=R(S.translation[2]))}let h=c.phase+c.speed*l,b=s+Math.cos(h)*c.radius,T=p+c.height,k=v+Math.sin(h)*c.radius;if(f.translation=[b,T,k],c.faceCenter){let S=Math.atan2(s-b,v-k);f.rotation=[0,Math.sin(S*.5),0,Math.cos(S*.5)]}a=!0}if(a){ve.set(e,l);let u=Ne(o);e.worldMatrices=u;for(let f of e.meshes||[])f.nodeIndex>=0&&f.nodeIndex<u.length&&(f.transform.set(u[f.nodeIndex]),ie(f.normalMatrix,f.transform))}}function Ae(e){if(!(!e||typeof e!="object"))return Y.get(e)||Y.get(e.viewer)||Y.get(e._view)}function Ge(e,t,n){let o=Ae(e);return o?(o.receiveCustomEvent(t,n),!0):!1}var He={name:"khr-interactivity",sendInteractivityEvent:Ge,getInteractivityVM:Ae,onLoadModel(e,t){if(!e||typeof e!="object")return;Y.get(e)?.dispose(),Y.delete(e),ve.delete(e);let n=t?.extensions?.KHR_interactivity,o=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!o||!Array.isArray(o.nodes))return;let r=new ue(e,t,o);Y.set(e,r),r.fireOnStart()},onMeshSelect(e,t){Y.get(e)?.fireOnSelect(t)},onUpdate(e,t){Y.get(e)?.tick(t),Zt(e,t)},onDestroy(e,t){Y.get(t)?.dispose(),Y.delete(t),ve.delete(t)}};var le=new Map,Xe=new WeakMap;function vt(e,t){le.set(e,t)}var We={name:"materials",onBuildPrimitiveVAO(e,t,n,o,r){return(((o?.materials&&n.material!==void 0?o.materials[n.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let n=Xe.get(e);n||(n=e.createTexture(),Xe.set(e,n));let o=Math.max(1,t.canvas.width),r=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,n),e.copyTexImage2D(3553,0,6408,0,0,o,r,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,n,o){if(!t)return null;if(t.name&&le.has(t.name)){let h=le.get(t.name);return{vs:h.vs||n,fs:h.fs||o}}let r=t.extensions||{},i=r.KHR_materials_clearcoat,l=r.KHR_materials_sheen,a=!!r.KHR_materials_transmission,u=!!r.KHR_materials_ior,f=r.KHR_materials_iridescence;if(!i&&!l&&!r.KHR_materials_unlit&&!a&&!r.KHR_materials_volume&&!u&&!r.KHR_materials_dispersion&&!f)return null;if(r.KHR_materials_unlit)return{vs:n,fs:o.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let c=o;if(a){let h=c.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
|
|
33
|
+
`;c=c.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
|
|
34
|
+
${h}out vec4 fragColor;`)}let s=(h,b,T=0,k=1e6,S=3)=>{let A=Number(h);return(Number.isFinite(A)?Math.min(k,Math.max(T,A)):b).toFixed(S)},p=Number(r.KHR_materials_ior?.ior??1.5),v=Number.isFinite(p)?Math.min(10,Math.max(1,p)):1.5;if(u){let h=Math.pow((v-1)/(v+1),2);c=c.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${s(h,.04,0,1,4)}),base.rgb,metallic);`)}if(f){let h=s(f.iridescenceFactor,1,0,1),b=s(f.iridescenceIor,1.3,1,10);c=c.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${b}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${h}*pow(1.-NoV,2.));`)}if(a){let h=s(r.KHR_materials_transmission?.transmissionFactor,1,0,1),b=r.KHR_materials_volume||{},T=s(b.thicknessFactor,.5,0,1e4),k=s(b.attenuationDistance,1,.001,1e6),S=Array.isArray(b.attenuationColor)?b.attenuationColor:[1,1,1],A=s(r.KHR_materials_dispersion?.dispersion,0,0,10);c=c.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
35
|
+
vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${s(v,1.5,1,10)},dV=${A},tV=${T},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
|
|
36
|
+
vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
|
|
37
|
+
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);
|
|
38
|
+
vec3 aCol=vec3(${s(S[0],1,0,1)},${s(S[1],1,0,1)},${s(S[2],1,0,1)});
|
|
39
|
+
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${k},.001));
|
|
40
|
+
diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${h});`)}if(i&&!o.includes("uClearcoat")){let h=s(i.clearcoatFactor,1,0,1),b=s(i.clearcoatRoughnessFactor,0,0,1);c=c.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${b},NoV)*${h};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${b})*ccF;fragColor=vec4(color,base.a);`)}if(l){let h=Array.isArray(l.sheenColorFactor)?l.sheenColorFactor:[1,1,1],b=`color+=vec3(${s(h[0],1,0,1)},${s(h[1],1,0,1)},${s(h[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;c.includes("color=applyToneMapping(color,uToneMapping);")?c=c.replace("color=applyToneMapping(color,uToneMapping);",`${b}color=applyToneMapping(color,uToneMapping);`):c=c.replace("fragColor=vec4(color,base.a);",`${b}fragColor=vec4(color,base.a);`)}return{vs:n,fs:c}},onBeforeDrawPrimitive(e,t,n,o,r,i){let l=n.materialIndex;if(l!==void 0&&i?.materials){let a=i.materials[l];a?.name&&le.has(a.name)&&le.get(a.name).onBindUniforms?.(e,t,n)}if(n.isTransmissive){let a=Xe.get(e);if(a){e.activeTexture(33990),e.bindTexture(3553,a);let u=e.getUniformLocation(t,"uTransmissionTex");u&&e.uniform1i(u,6);let f=e.getUniformLocation(t,"uViewportSize");f&&e.uniform2f(f,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}};var At=64*1024*1024,Mt=128*1024*1024,Jt=16777216;function en(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function $e(e){return(e>>>1^-(e&1))&255}function tn(e){return(e<<1^e>>31)>>>0}function nn(e){return e>>>1^-(e&1)}function Me(e,t,n,o="NONE"){if(!o||o==="NONE"||t<=0)return;let r=new DataView(e.buffer,e.byteOffset,e.byteLength);if(o==="OCTAHEDRAL"){if(n!==4&&n!==8)throw new Error(`EXT_meshopt_compression: OCTAHEDRAL filter requires byteStride 4 or 8 (got ${n})`);let i=n===4?127:32767;for(let l=0;l<t;l++){let a=l*n,u=n===4?r.getInt8(a):r.getInt16(a,!0),f=n===4?r.getInt8(a+1):r.getInt16(a+2,!0),c=n===4?r.getInt8(a+2):r.getInt16(a+4,!0),s=c===0?1:c,p=u/s,v=f/s,h=1-Math.abs(p)-Math.abs(v),b=Math.max(-h,0);p+=p>=0?-b:b,v+=v>=0?-b:b;let T=Math.hypot(p,v,h)||1,k=Math.max(-i,Math.min(i,Math.round(p/T*i))),S=Math.max(-i,Math.min(i,Math.round(v/T*i))),A=Math.max(-i,Math.min(i,Math.round(h/T*i)));n===4?(r.setInt8(a,k),r.setInt8(a+1,S),r.setInt8(a+2,A)):(r.setInt16(a,k,!0),r.setInt16(a+2,S,!0),r.setInt16(a+4,A,!0))}return}if(o==="QUATERNION"){if(n!==8)throw new Error(`EXT_meshopt_compression: QUATERNION filter requires byteStride 8 (got ${n})`);for(let i=0;i<t;i++){let l=i*8,a=r.getInt16(l,!0),u=r.getInt16(l+2,!0),f=r.getInt16(l+4,!0),c=r.getInt16(l+6,!0),s=c&3,p=c|3,v=Math.SQRT1_2/(p===0?1:p),h=a*v,b=u*v,T=f*v,k=Math.sqrt(Math.max(0,1-h*h-b*b-T*T)),S=Math.hypot(h,b,T,k)||1,A=[0,0,0,0];A[s+1&3]=Math.max(-32767,Math.min(32767,Math.round(h/S*32767))),A[s+2&3]=Math.max(-32767,Math.min(32767,Math.round(b/S*32767))),A[s+3&3]=Math.max(-32767,Math.min(32767,Math.round(T/S*32767))),A[s]=Math.max(-32767,Math.min(32767,Math.round(k/S*32767))),r.setInt16(l,A[0],!0),r.setInt16(l+2,A[1],!0),r.setInt16(l+4,A[2],!0),r.setInt16(l+6,A[3],!0)}return}if(o==="EXPONENTIAL"){if(n<4||n%4!==0)throw new Error(`EXT_meshopt_compression: EXPONENTIAL filter requires byteStride multiple of 4 (got ${n})`);let i=t*n>>>2;for(let l=0;l<i;l++){let a=l*4,u=r.getInt32(a,!0),f=u>>24,c=u<<8>>8,s=Math.pow(2,f)*c;r.setFloat32(a,s,!0)}}}function Et(e){let t=Math.floor(8192/e)&-16;return t<32?32:t>256?256:t}function je(e,t,n,o,r="NONE"){if(!Number.isInteger(t)||t<0||t>Jt||!Number.isInteger(n)||n<=0||n>256)throw new Error(`EXT_meshopt_compression: invalid count (${t}) or byteStride (${n})`);let i=t*n;if(i>At)throw new Error(`EXT_meshopt_compression: decompressed size (${i}) exceeds MAX_MESHOPT_BUFFER_BYTES (${At})`);if(t===0)return new Uint8Array(0);let l=new Uint8Array(i),a=e.length>0?e[0]:0;if(o==="ATTRIBUTES"){if(n%4!==0)throw new Error(`EXT_meshopt_compression: ATTRIBUTES byteStride must be a multiple of 4 (got ${n})`);if(a!==160){if(e.byteLength===i)return l.set(e),Me(l,t,n,r),l;throw new Error(`EXT_meshopt_compression: unsupported ATTRIBUTES header 0x${a.toString(16)}`)}if(e.byteLength<1+n)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES stream");let u=e.byteLength-n,f=new Uint8Array(n);f.set(e.subarray(u,u+n));let c=Et(n),s=1,p=0;for(;p<t;){let v=Math.min(t-p,c),h=v+15>>>4,b=h+3>>>2;for(let T=0;T<n;T++){if(s+b>u)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES control header");let k=s;s+=b;let S=f[T];for(let A=0;A<h;A++){let L=e[k+(A>>>2)]>>>(A&3)*2&3,P=A*16,_=Math.min(16,v-P);if(L===0)for(let N=0;N<_;N++)l[(p+P+N)*n+T]=S;else if(L===1){if(s+4>u)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES 2-bit group");for(let N=0;N<16;N++){let V=e[s+(N>>>2)]>>>(N&3)*2&3;S=S+$e(V)&255,N<_&&(l[(p+P+N)*n+T]=S)}s+=4}else if(L===2){if(s+8>u)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES 4-bit group");for(let N=0;N<16;N++){let V=e[s+(N>>>1)]>>>(N&1)*4&15;S=S+$e(V)&255,N<_&&(l[(p+P+N)*n+T]=S)}s+=8}else{if(s+16>u)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES 8-bit group");for(let N=0;N<16;N++){let D=e[s+N];S=S+$e(D)&255,N<_&&(l[(p+P+N)*n+T]=S)}s+=16}}f[T]=S}p+=v}return Me(l,t,n,r),l}if(o==="TRIANGLES"||o==="INDICES"){if(n!==2&&n!==4)throw new Error(`EXT_meshopt_compression: ${o} byteStride must be 2 or 4 (got ${n})`);if(o==="TRIANGLES"&&t%3!==0)throw new Error(`EXT_meshopt_compression: TRIANGLES count must be divisible by 3 (got ${t})`);let u=o==="TRIANGLES"?176:192;if((a&240)!==u){if(e.byteLength===i)return l.set(e),l;throw new Error(`EXT_meshopt_compression: unsupported ${o} header 0x${a.toString(16)}`)}let f=new DataView(l.buffer,l.byteOffset,l.byteLength),c=1,s=0;for(let p=0;p<t;p++){let v=0,h=0;for(;;){if(c>=e.byteLength)throw new Error(`EXT_meshopt_compression: truncated ${o} stream`);let b=e[c++];if(v|=(b&127)<<h,!(b&128))break;if(h+=7,h>28)throw new Error(`EXT_meshopt_compression: varint overflow in ${o}`)}s=s+nn(v)>>>0,n===2?f.setUint16(p*2,s&65535,!0):f.setUint32(p*4,s,!0)}return l}throw new Error(`EXT_meshopt_compression: unknown mode "${String(o)}"`)}function wt(e,t,n,o){let r=t*n;if(e.byteLength<r)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${r})`);if(t===0)return new Uint8Array([o==="ATTRIBUTES"?160:176]);if(o==="ATTRIBUTES"){let u=Et(n),f=[160],c=new Uint8Array(n),s=0;for(;s<t;){let p=Math.min(t-s,u),v=p+15>>>4,h=v+3>>>2;for(let b=0;b<n;b++){let T=new Uint8Array(h),k=[],S=c[b];for(let A=0;A<v;A++){let L=A*16,P=Math.min(16,p-L),_=new Uint8Array(16),N=0;for(let V=0;V<16;V++)if(V<P){let O=e[(s+L+V)*n+b],j=O-S<<24>>24,X=en(j);_[V]=X,X>N&&(N=X),S=O}else _[V]=0;let D=0;if(N===0)D=0;else if(N<=3){D=1;for(let V=0;V<16;V+=4)k.push(_[V]&3|(_[V+1]&3)<<2|(_[V+2]&3)<<4|(_[V+3]&3)<<6)}else if(N<=15){D=2;for(let V=0;V<16;V+=2)k.push(_[V]&15|(_[V+1]&15)<<4)}else{D=3;for(let V=0;V<16;V++)k.push(_[V])}T[A>>>2]|=D<<(A&3)*2}for(let A=0;A<T.length;A++)f.push(T[A]);for(let A=0;A<k.length;A++)f.push(k[A]);c[b]=S}s+=p}for(let p=0;p<n;p++)f.push(0);return new Uint8Array(f)}let i=new DataView(e.buffer,e.byteOffset,e.byteLength),l=[o==="TRIANGLES"?176:192],a=0;for(let u=0;u<t;u++){let f=n===2?i.getUint16(u*2,!0):i.getUint32(u*4,!0),c=f-a|0;a=f;let s=tn(c);for(;s>=128;)l.push(s&127|128),s>>>=7;l.push(s&127)}return new Uint8Array(l)}function ce(e,t){let n=t&&typeof t=="object"?t:e,o=t&&typeof t=="object"?e:n?.gltf;if(!o||!Array.isArray(o.bufferViews))return;let r=new Uint8Array(n.bin),i=[],l=0;for(let s=0;s<o.bufferViews.length;s++){let v=o.bufferViews[s]?.extensions?.EXT_meshopt_compression;if(!v||typeof v!="object")continue;let h=Number(v.count),b=Number(v.byteStride),T=Number(v.byteOffset??0),k=Number(v.byteLength??0),S=v.mode||"ATTRIBUTES",A=v.filter||"NONE";if(!Number.isInteger(T)||T<0||!Number.isInteger(k)||k<0||T+k>r.byteLength)throw new Error(`EXT_meshopt_compression: bufferView ${s} compressed range [${T}, ${T+k}] out of bounds (${r.byteLength})`);let L=h*b;if(l+=L,l>Mt)throw new Error(`EXT_meshopt_compression: total decompressed size (${l}) exceeds MAX_MESHOPT_TOTAL_BYTES (${Mt})`);let P=r.subarray(T,T+k),_=je(P,h,b,S,A);i.push({index:s,bytes:_,ext:v})}if(i.length===0)return;let a=r.byteLength+3&-4,u=0;for(let s of i)u+=s.bytes.byteLength+3&-4;let f=new Uint8Array(a+u);f.set(r,0);let c=a;for(let s of i){f.set(s.bytes,c);let p=o.bufferViews[s.index];p.byteOffset=c,p.byteLength=s.bytes.byteLength,p._decoded=s.bytes,s.ext.mode==="ATTRIBUTES"&&p.byteStride===void 0&&(p.byteStride=Number(s.ext.byteStride)),p.extensions&&delete p.extensions.EXT_meshopt_compression,c+=s.bytes.byteLength+3&-4}n.bin=f.buffer}var Ee={decodeBufferViews(e,t){ce(t)},decodePrimitive(e,t,n){let o=t?.extensions;o?.EXT_meshopt_compression&&delete o.EXT_meshopt_compression,ce({gltf:e,bin:n})}};ne().decoders.set("meshopt",Ee);var Ke={name:"meshopt",onParseGLB(e){ne().decoders.set("meshopt",Ee),ce(e)}};var rn=`#version 300 es
|
|
41
|
+
layout(location=0) in vec3 aPosition;
|
|
42
|
+
layout(location=1) in vec3 aNormal;
|
|
43
|
+
uniform mat4 uMVP,uVP;
|
|
44
|
+
uniform mat3 uNormalMatrix;
|
|
45
|
+
uniform vec2 uViewportSize;
|
|
46
|
+
uniform float uOutlineThickness;
|
|
47
|
+
void main(){
|
|
48
|
+
vec4 clipPos=uMVP*vec4(aPosition,1.0);
|
|
49
|
+
vec3 nPart=length(aNormal)>1e-5?normalize(aNormal):vec3(0.0);
|
|
50
|
+
vec3 pPart=length(aPosition)>1e-5?normalize(aPosition)*0.65:vec3(0.0);
|
|
51
|
+
vec3 rawN=nPart+pPart;
|
|
52
|
+
vec3 worldN=uNormalMatrix*(length(rawN)>1e-5?normalize(rawN):vec3(0.0,1.0,0.0));
|
|
53
|
+
float nLen=length(worldN);
|
|
54
|
+
vec3 n=nLen>1e-5?(worldN/nLen):vec3(0.0,1.0,0.0);
|
|
55
|
+
vec4 clipN=uVP*vec4(n,0.0);
|
|
56
|
+
vec2 dir=length(clipN.xy)>1e-5?normalize(clipN.xy):vec2(0.0);
|
|
57
|
+
vec2 pxOffset=dir*(uOutlineThickness*2.0/max(uViewportSize,vec2(1.0)))*clipPos.w;
|
|
58
|
+
clipPos.xy+=pxOffset;
|
|
59
|
+
clipPos.z+=1e-4*clipPos.w;
|
|
60
|
+
gl_Position=clipPos;
|
|
61
|
+
}`,on=`#version 300 es
|
|
62
|
+
precision highp float;
|
|
63
|
+
uniform vec4 uOutlineColor;
|
|
64
|
+
out vec4 fragColor;
|
|
65
|
+
void main(){
|
|
66
|
+
fragColor=uOutlineColor;
|
|
67
|
+
}`,Rt=`#version 300 es
|
|
68
|
+
out vec2 vUV;
|
|
69
|
+
void main(){
|
|
70
|
+
vec2 pos=vec2((gl_VertexID<<1)&2,gl_VertexID&2);
|
|
71
|
+
vUV=pos;
|
|
72
|
+
gl_Position=vec4(pos*2.0-1.0,0.0,1.0);
|
|
73
|
+
}`,an=`#version 300 es
|
|
74
|
+
precision highp float;
|
|
75
|
+
in vec2 vUV;
|
|
76
|
+
uniform sampler2D uSourceTex;
|
|
77
|
+
uniform vec2 uTexelSize;
|
|
78
|
+
uniform float uThreshold;
|
|
79
|
+
out vec4 fragColor;
|
|
80
|
+
vec3 prefilter(vec3 c){
|
|
81
|
+
float br=max(c.r,max(c.g,c.b));
|
|
82
|
+
float knee=max(uThreshold*0.5,1e-4);
|
|
83
|
+
float soft=clamp(br-uThreshold+knee,0.0,2.0*knee);
|
|
84
|
+
soft=(soft*soft)/(4.0*knee+1e-4);
|
|
85
|
+
float contrib=max(soft,br-uThreshold)/max(br,1e-4);
|
|
86
|
+
return c*clamp(contrib,0.0,1.0);
|
|
87
|
+
}
|
|
88
|
+
void main(){
|
|
89
|
+
vec2 h=uTexelSize*0.5;
|
|
90
|
+
vec3 c=prefilter(texture(uSourceTex,vUV).rgb)*0.5;
|
|
91
|
+
c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,-h.y)).rgb)*0.125;
|
|
92
|
+
c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,-h.y)).rgb)*0.125;
|
|
93
|
+
c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,h.y)).rgb)*0.125;
|
|
94
|
+
c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,h.y)).rgb)*0.125;
|
|
95
|
+
fragColor=vec4(c,1.0);
|
|
96
|
+
}`,sn=`#version 300 es
|
|
97
|
+
precision highp float;
|
|
98
|
+
in vec2 vUV;
|
|
99
|
+
uniform sampler2D uBloomTex;
|
|
100
|
+
uniform vec2 uTexelSize;
|
|
101
|
+
uniform float uRadius;
|
|
102
|
+
uniform float uStrength;
|
|
103
|
+
out vec4 fragColor;
|
|
104
|
+
void main(){
|
|
105
|
+
vec2 d=uTexelSize*max(0.25,uRadius*2.5);
|
|
106
|
+
vec3 sum=vec3(0.0);
|
|
107
|
+
sum+=texture(uBloomTex,vUV+vec2(-d.x*2.0,0.0)).rgb;
|
|
108
|
+
sum+=texture(uBloomTex,vUV+vec2(-d.x,d.y)).rgb*2.0;
|
|
109
|
+
sum+=texture(uBloomTex,vUV+vec2(0.0,d.y*2.0)).rgb;
|
|
110
|
+
sum+=texture(uBloomTex,vUV+vec2(d.x,d.y)).rgb*2.0;
|
|
111
|
+
sum+=texture(uBloomTex,vUV+vec2(d.x*2.0,0.0)).rgb;
|
|
112
|
+
sum+=texture(uBloomTex,vUV+vec2(d.x,-d.y)).rgb*2.0;
|
|
113
|
+
sum+=texture(uBloomTex,vUV+vec2(0.0,-d.y*2.0)).rgb;
|
|
114
|
+
sum+=texture(uBloomTex,vUV+vec2(-d.x,-d.y)).rgb*2.0;
|
|
115
|
+
vec3 bloom=(sum/12.0)*uStrength;
|
|
116
|
+
float a=clamp(min(bloom.r,min(bloom.g,bloom.b)),0.0,1.0);
|
|
117
|
+
fragColor=vec4(bloom,a);
|
|
118
|
+
}`,we=3,Re=new WeakMap;function Ye(e,t=[.22,.74,.97]){let n=he(e,"");if(!n.startsWith("#"))return[t[0],t[1],t[2]];let o=n.slice(1);if(o.length===3){let r=+("0x"+o[0]+o[0])/255,i=+("0x"+o[1]+o[1])/255,l=+("0x"+o[2]+o[2])/255;return[r,i,l]}if(o.length===6){let r=+("0x"+o.slice(0,2))/255,i=+("0x"+o.slice(2,4))/255,l=+("0x"+o.slice(4,6))/255;return[r,i,l]}return[t[0],t[1],t[2]]}function _t(e,t,n=.8,o=.5){let r=Number.isFinite(t)?Math.max(0,t):0;if(r<=0)return[0,0,0];let i=Math.max(0,Number(e[0])||0),l=Math.max(0,Number(e[1])||0),a=Math.max(0,Number(e[2])||0),u=Math.max(i,l,a);if(u<=1e-6)return[0,0,0];let f=Number.isFinite(n)?Math.max(0,n):.8,c=Math.max(f*Math.max(0,o),1e-4),s=Math.max(0,Math.min(2*c,u-f+c)),p=s*s/(4*c+1e-4),h=Math.min(1,Math.max(0,Math.max(p,u-f)/Math.max(u,1e-4)))*r;return[i*h,l*h,a*h]}function It(e,t,n,o){let r=Number(e[0])||0,i=Number(e[1])||0,l=Math.hypot(r,i);if(l<=1e-5||t<=0||n<=0)return[0,0];let a=Math.max(1,Number(o[0])||1),u=Math.max(1,Number(o[1])||1),f=Math.max(0,n)*2*t;return[r/l*(f/a),i/l*(f/u)]}function qe(e,t,n){let o=(i,l)=>{let a=e.createShader(i);return e.shaderSource(a,l),e.compileShader(a),a},r=e.createProgram();return e.attachShader(r,o(35633,t)),e.attachShader(r,o(35632,n)),e.linkProgram(r),r}function St(e){let t=Re.get(e);if(t)return t;let n=qe(e,rn,on),o=qe(e,Rt,an),r=qe(e,Rt,sn),i=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:n,uOutlineMVP:e.getUniformLocation(n,"uMVP"),uOutlineVP:e.getUniformLocation(n,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(n,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(n,"uViewportSize"),uOutlineThickness:e.getUniformLocation(n,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(n,"uOutlineColor"),downProg:o,uDownSourceTex:e.getUniformLocation(o,"uSourceTex"),uDownTexelSize:e.getUniformLocation(o,"uTexelSize"),uDownThreshold:e.getUniformLocation(o,"uThreshold"),upProg:r,uUpBloomTex:e.getUniformLocation(r,"uBloomTex"),uUpTexelSize:e.getUniformLocation(r,"uTexelSize"),uUpRadius:e.getUniformLocation(r,"uRadius"),uUpStrength:e.getUniformLocation(r,"uStrength"),fsVao:i,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Re.set(e,t),t}function un(e,t,n,o){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let r=Math.max(2,n|0),i=Math.max(2,o|0);if(t.sceneTex&&t.bloomFbo.length===we&&t.texWidth===r&&t.texHeight===i)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,r,i,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 l=r,a=i;for(let u=0;u<we;u++)l=Math.max(1,l>>1),a=Math.max(1,a>>1),t.mipWidth[u]=l,t.mipHeight[u]=a,t.bloomTex[u]||(t.bloomTex[u]=e.createTexture()),e.bindTexture(3553,t.bloomTex[u]),e.texImage2D(3553,0,6408,l,a,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[u]||(t.bloomFbo[u]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[u]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[u],0);return e.bindFramebuffer(36160,null),t.texWidth=r,t.texHeight=i,!0}function ln(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let o=t.getAttribute("bloom");if(o!==null){let r=o.trim().toLowerCase();if(r==="false"||r==="0"||r==="none")return null;let i=r===""||r==="true"?.35:Number(r);if(!Number.isFinite(i)||i<=0)return null;let l=t.getAttribute("bloom-threshold"),a=t.getAttribute("bloom-radius"),u=De({strength:i,threshold:l!==null?Number(l):.62,radius:a!==null?Number(a):.75});if(u)return u}}let n=null;for(let o of e.meshes||[]){if(o.visible===!1)continue;let r=o?.extras?.xr?.bloom??o?.userData?.xr?.bloom,i=De(r);i&&(!n||i.strength>n.strength)&&(n=i)}return n}function cn(e,t){if(e==null)return null;let n=e.trim(),o=n.toLowerCase();if(o==="false"||o==="0"||o==="none")return null;let r=t,i=3.5,l=!1;if(n&&o!=="true"){let a=n.split(/\s+/);for(let u of a)if(u.startsWith("#"))r=u;else if(u.toLowerCase()==="pulse")l=!0;else{let f=Number(u);Number.isFinite(f)&&f>0&&(i=f<.25?Math.max(1.5,f*140):f)}}return ye({color:r,thickness:i,pulse:l})}function fn(e,t){let n=e.container,o=typeof n?.getAttribute=="function"?n.getAttribute("outline"):null;if(o!=null){let c=o.trim().toLowerCase();if(c==="false"||c==="0"||c==="none")return null}let r=t?.extras?.xr?.outline??t?.userData?.xr?.outline,i=ye(r);if(i)return i;let l=typeof n?.getAttribute=="function"&&n.getAttribute("outline-color")||"#38bdf8",a=cn(o,l),u=n!=null&&typeof n.hasAttribute=="function"&&n.hasAttribute("outline-selected")&&n.getAttribute("outline-selected")!=="false",f=e.getSelectedMesh?.()||"";if(f)return t.name!==f?null:a||(u?ye({color:l,thickness:3,pulse:!1}):null);if(a){let c=t.name||"";return/floor|pedestal|ground|table|grid|pad/i.test(c)?null:a}return null}var Qe={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,n){if(!t.meshes||t.meshes.length===0)return;let o=Math.max(1,t.canvas?.width||300),r=Math.max(1,t.canvas?.height||150),i=[];for(let s of t.meshes){if(s.visible===!1)continue;let p=fn(t,s);p&&i.push({mesh:s,trait:p})}if(i.length>0){let s=St(e),p=re(),v=re(),h=new Float32Array(9),b=(typeof performance<"u"?performance.now():Date.now())*.001;e.useProgram(s.outlineProg),s.uOutlineViewportSize&&e.uniform2f(s.uOutlineViewportSize,o,r),s.uOutlineVP&&e.uniformMatrix4fv(s.uOutlineVP,!1,n),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(e.LEQUAL),e.depthMask(!1);for(let{mesh:T,trait:k}of i){let[S,A,L]=Ye(k.color),P=k.pulse?.8+.25*Math.sin(b*4):1;s.uOutlineColor&&e.uniform4f(s.uOutlineColor,S,A,L,1),s.uOutlineThickness&&e.uniform1f(s.uOutlineThickness,k.thickness*P),T.worldSpace===!0?p.set(T.transform):oe(p,t.modelRootMatrix,T.transform);let _=T.instanceMatrices;for(let N of T.primitives)if(e.bindVertexArray(N.vao),_&&_.length>=16){let D=_.length>>4,V=re();for(let O=0;O<D;O++)oe(V,p,_.subarray(O*16,O*16+16)),oe(v,n,V),ie(h,V),e.uniformMatrix4fv(s.uOutlineMVP,!1,v),e.uniformMatrix3fv(s.uOutlineNormalMatrix,!1,h),N.indices?e.drawElements(4,N.indexCount,N.indexType,0):e.drawArrays(4,0,N.indexCount)}else oe(v,n,p),ie(h,p),e.uniformMatrix4fv(s.uOutlineMVP,!1,v),e.uniformMatrix3fv(s.uOutlineNormalMatrix,!1,h),N.indices?e.drawElements(4,N.indexCount,N.indexType,0):e.drawArrays(4,0,N.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 l=ln(t);if(!l||l.strength<=0)return;let a=St(e);if(!un(e,a,o,r)||!a.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,a.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,o,r),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(a.downProg),e.uniform1i(a.uDownSourceTex,0),e.bindVertexArray(a.fsVao);let u=a.sceneTex,f=o,c=r;for(let s=0;s<we;s++){let p=a.mipWidth[s],v=a.mipHeight[s];e.bindFramebuffer(36160,a.bloomFbo[s]),e.viewport(0,0,p,v),e.bindTexture(3553,u),e.uniform2f(a.uDownTexelSize,1/f,1/c),e.uniform1f(a.uDownThreshold,s===0?l.threshold:0),e.drawArrays(4,0,3),u=a.bloomTex[s],f=p,c=v}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(a.upProg),e.uniform1i(a.uUpBloomTex,0),e.uniform1f(a.uUpRadius,l.radius);for(let s=we-1;s>=1;s--){let p=s-1;e.bindFramebuffer(36160,a.bloomFbo[p]),e.viewport(0,0,a.mipWidth[p],a.mipHeight[p]),e.bindTexture(3553,a.bloomTex[s]),e.uniform2f(a.uUpTexelSize,1/a.mipWidth[s],1/a.mipHeight[s]),e.uniform1f(a.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,o,r),e.bindTexture(3553,a.bloomTex[0]),e.uniform2f(a.uUpTexelSize,1/a.mipWidth[0],1/a.mipHeight[0]),e.uniform1f(a.uUpStrength,l.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=Re.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 n of t.bloomTex)n&&e.deleteTexture(n);for(let n of t.bloomFbo)n&&e.deleteFramebuffer(n);Re.delete(e)}}};var dn=`#version 300 es
|
|
119
|
+
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.);}`,pn=`#version 300 es
|
|
120
|
+
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);}`,Se=new WeakMap,Lt=new Float32Array(20);function Ze(e,t){let[n,o,r,i,l,a]=t;return[e[0]*n+e[4]*o+e[8]*r+e[12],e[1]*n+e[5]*o+e[9]*r+e[13],e[2]*n+e[6]*o+e[10]*r+e[14],Math.abs(e[0])*i+Math.abs(e[4])*l+Math.abs(e[8])*a,Math.abs(e[1])*i+Math.abs(e[5])*l+Math.abs(e[9])*a,Math.abs(e[2])*i+Math.abs(e[6])*l+Math.abs(e[10])*a]}function bn(e){if(e._lb!==void 0)return e._lb;let t=1e9,n=1e9,o=1e9,r=-1e9,i=-1e9,l=-1e9;for(let a of e.primitives||[]){let u=a.positions;if(u)for(let f=0;f<u.length;f+=3)u[f]<t&&(t=u[f]),u[f+1]<n&&(n=u[f+1]),u[f+2]<o&&(o=u[f+2]),u[f]>r&&(r=u[f]),u[f+1]>i&&(i=u[f+1]),u[f+2]>l&&(l=u[f+2])}return e._lb=t<=r?[(t+r)*.5,(n+i)*.5,(o+l)*.5,(r-t)*.5,(i-n)*.5,(l-o)*.5]:null}function hn(e){let t=Se.get(e);if(t)return t;let n=(a,u)=>{let f=e.createShader(a);return e.shaderSource(f,u),e.compileShader(f),f},o=e.createProgram();e.attachShader(o,n(35633,dn)),e.attachShader(o,n(35632,pn)),e.linkProgram(o);let r=e.createVertexArray(),i=e.createBuffer(),l=e.createBuffer();return e.bindVertexArray(r),e.bindBuffer(34962,i),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,l),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:o,vao:r,vbo:i,ibo:l,uMVP:e.getUniformLocation(o,"uMVP"),uIntensity:e.getUniformLocation(o,"uShadowIntensity"),uSoftness:e.getUniformLocation(o,"uShadowSoftness")},Se.set(e,t),t}var Je={name:"contact-shadow",onAfterRender(e,t,n){let o=t.shadowIntensity;if(o<=0||!t.bounds)return;let r=hn(e),i=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,l=[],a=[];for(let b of t.meshes||[]){if(!b||b.visible===!1||b.isPluginMesh||b.name==="__xr_reticle__"||b.name?.startsWith("__xr_slot_"))continue;let T=bn(b);if(!T)continue;b.transform&&(T=Ze(b.transform,T)),t.modelRootMatrix&&(T=Ze(t.modelRootMatrix,T));let[k,S,A,L,P,_]=T,N=[k,A,L,_,S-P,S+P];/floor|table|pedestal|ground|base|plane/i.test(b.name||"")||P<.14&&Math.min(L,_)>.45?a.push(N):l.push(N)}let u=[],f=t.bounds.center||[0,0,0],c=Math.max(.05,Number(t.bounds.radius)||.5),s=t.bounds.min,p=s?[f[0],f[1],f[2],c,Math.max(.01,f[1]-s[1]),c]:[f[0],f[1],f[2],c,c,c];t.modelRootMatrix&&(p=Ze(t.modelRootMatrix,p));let h=t.xrSessionActive&&a.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:p[1]-p[4]+.002;for(let[b,T,k,S,A]of l){let L=-1/0;for(let[_,N,D,V,,O]of a)A>=O-.08&&Math.abs(b-_)<=D&&Math.abs(T-N)<=V&&O+.002>L&&(L=O+.002);i&&(L=Math.max(L,b>=.04&&b<=.36&&T>=-.34&&T<=-.04&&A>=.01?.036:Math.hypot(b,T)<=.66&&A>=-.06?.003:-.477)),isFinite(L)||(L=h);let P=u.find(_=>Math.hypot(b-_[0],T-_[1])<.06&&Math.abs(L-_[5])<.05);P?(P[2]=Math.max(P[2],k*.78),P[3]=Math.max(P[3],S*.78),P[4]=Math.min(P[4],A)):u.push([b,T,k,S,A,L])}if(u.length===0){let b=Math.max(.1,p[3]*1.5)/1.45;u.push([p[0],p[2],b,b,h,h])}e.useProgram(r.prog),e.uniformMatrix4fv(r.uMVP,!1,n),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(r.vao),e.bindBuffer(34962,r.vbo);for(let[b,T,k,S,A,L]of u){let P=Math.max(0,A-L),_=o/(1+P*2);if(_<.02)continue;let N=1+Math.min(.75,P*.85),D=Math.max(.045,k*1.45*N),V=Math.max(.045,S*1.45*N);Lt.set([b-D,L,T-V,0,0,b+D,L,T-V,1,0,b+D,L,T+V,1,1,b-D,L,T+V,0,1]),e.bufferSubData(34962,0,Lt),e.uniform1f(r.uIntensity,_),e.uniform1f(r.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,P*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=Se.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),Se.delete(e))}};function et(e){let n=e?.extensions?.KHR_materials_variants?.variants;if(!Array.isArray(n))return[];let o=[];for(let r=0;r<n.length&&o.length<256;r++){let i=n[r]?.name;o.push(typeof i=="string"&&i.length>0?i:`Variant_${r}`)}return o}function Pt(e){let n=e?.extensions?.KHR_materials_variants?.mappings;if(!Array.isArray(n))return[];let o=[];for(let r of n){if(!r||typeof r!="object")continue;let i=r,l=Number(i.material);if(!Number.isInteger(l)||l<0)continue;let a=[];if(Array.isArray(i.variants))for(let u of i.variants){let f=Number(u);Number.isInteger(f)&&f>=0&&a.push(f)}a.length>0&&o.push({material:l,variants:a})}return o}function Nt(e,t,n,o=0){let r=e;if(r&&typeof r.selectVariant=="function"&&!Array.isArray(t))return r.selectVariant(typeof t=="string"?t:null);let i=e,l=Array.isArray(t)?t:[],a=n??null;if(!a)return o;let f=et(i).indexOf(a);if(f<0)return o;for(let c of l)if(c.variants.includes(f))return c.material;return o}var tt={name:"variants",onLoadModel(e,t){let n=e.getVariantName?.();n&&e.selectVariant(n)}};var kt=new WeakMap,nt={name:"webxr-suite",onConfigureXRSessionInit(e,t){let n=new Set(t.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation");let o=e?.querySelector?.('[slot="ar-overlay"]')||null;o&&(n.add("dom-overlay"),t.domOverlay={root:o},o.addEventListener?.("beforexrselect",r=>{r.preventDefault()})),t.optionalFeatures=Array.from(n)},onXRFrame(e,t,n,o){if(!e||!t||!n||!o)return;let r=kt.get(t);if(r||(r={lightProbe:null},kt.set(t,r),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(i=>{r&&i&&(r.lightProbe=i)}).catch(()=>{})),r.lightProbe&&typeof n.getLightEstimate=="function"){let i=n.getLightEstimate(r.lightProbe);if(i){let l=i.primaryLightDirection,a=i.primaryLightIntensity;if(l&&a&&Array.isArray(e.lights)){let u=e.lights.find(c=>c.type==="directional");u||(u={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(u)),u.direction=[l.x,l.y,l.z];let f=Math.max(a.x,a.y,a.z,.001);u.color=[a.x/f,a.y/f,a.z/f],u.intensity=f}i.sphericalHarmonicsCoefficients&&e.gl&&be(e.gl,i.sphericalHarmonicsCoefficients)}}}};q(Je);q(Ce);q(Ve);q(We);q(nt);q(He);q(Ke);q(tt);q(Qe);
|