three-live 0.0.1-alpha.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +58 -0
- package/dist/index.d.ts +224 -0
- package/dist/three-author-engine.js +297 -0
- package/dist/three-author.cjs +297 -0
- package/dist/three-author.d.ts +224 -0
- package/dist/three-author.js +297 -0
- package/dist/three-convert.cjs +291 -0
- package/dist/three-convert.d.ts +224 -0
- package/dist/three-convert.js +291 -0
- package/dist/three-live-animation.cjs +36 -0
- package/dist/three-live-animation.d.ts +224 -0
- package/dist/three-live-animation.js +36 -0
- package/dist/three-live-animation.min.js +36 -0
- package/dist/three-live-element.cjs +222 -0
- package/dist/three-live-element.d.ts +224 -0
- package/dist/three-live-element.js +222 -0
- package/dist/three-live-extras.cjs +42 -0
- package/dist/three-live-extras.d.ts +224 -0
- package/dist/three-live-extras.js +42 -0
- package/dist/three-live-extras.min.js +42 -0
- package/dist/three-live-full.cjs +341 -0
- package/dist/three-live-full.js +341 -0
- package/dist/three-live-full.min.js +341 -0
- package/dist/three-live-sandbox.html +157 -0
- package/dist/three-live-viewer.cjs +222 -0
- package/dist/three-live-viewer.d.ts +224 -0
- package/dist/three-live-viewer.js +222 -0
- package/dist/three-live-viewer.min.js +222 -0
- package/dist/three-live.cjs +299 -0
- package/dist/three-live.js +299 -0
- package/dist/three-live.min.js +299 -0
- package/dist/three-view.cjs +222 -0
- package/dist/three-view.d.ts +224 -0
- package/dist/three-view.js +222 -0
- package/dist/three-xr.cjs +291 -0
- package/dist/three-xr.d.ts +224 -0
- package/dist/three-xr.js +291 -0
- package/package.json +78 -6
- package/index.js +0 -1
|
@@ -0,0 +1,222 @@
|
|
|
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
|
+
var fe="__THREE_LIVE_REGISTRY__";function H(){let n=typeof globalThis<"u"?globalThis:{};if(!n[fe]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(n,fe,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{n[fe]=t}}return n[fe]}var G=H().plugins;function Re(n){let t=H().plugins;t.some(e=>e.name===n.name)||t.push(n)}function Ee(){return H().plugins}function V(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function be(n,t,e,r,i){let s=1/Math.tan(t/2);n.fill(0),n[0]=s/e,n[5]=s,n[11]=-1;let u=1/(r-i);return n[10]=(i+r)*u,n[14]=2*i*r*u,n}function ve(n,t,e,r){let[i,s,u]=t,[l,o,c]=r,[a,h,p]=e,b=i-a,f=s-h,T=u-p,M=Math.hypot(b,f,T);M<=1e-5?(b=0,f=0,T=1):(b/=M,f/=M,T/=M);let R=o*T-c*f,P=c*b-l*T,E=l*f-o*b;M=Math.hypot(R,P,E),M<=1e-5?(R=0,P=0,E=0):(R/=M,P/=M,E/=M);let v=f*E-T*P,d=T*R-b*E,m=b*P-f*R;return M=Math.hypot(v,d,m),M<=1e-5?(v=0,d=0,m=0):(v/=M,d/=M,m/=M),n[0]=R,n[1]=v,n[2]=b,n[3]=0,n[4]=P,n[5]=d,n[6]=f,n[7]=0,n[8]=E,n[9]=m,n[10]=T,n[11]=0,n[12]=-(R*i+P*s+E*u),n[13]=-(v*i+d*s+m*u),n[14]=-(b*i+f*s+T*u),n[15]=1,n}function $(n,t,e){let r=t[0],i=t[1],s=t[2],u=t[3],l=t[4],o=t[5],c=t[6],a=t[7],h=t[8],p=t[9],b=t[10],f=t[11],T=t[12],M=t[13],R=t[14],P=t[15],E=e[0],v=e[1],d=e[2],m=e[3];return n[0]=E*r+v*l+d*h+m*T,n[1]=E*i+v*o+d*p+m*M,n[2]=E*s+v*c+d*b+m*R,n[3]=E*u+v*a+d*f+m*P,E=e[4],v=e[5],d=e[6],m=e[7],n[4]=E*r+v*l+d*h+m*T,n[5]=E*i+v*o+d*p+m*M,n[6]=E*s+v*c+d*b+m*R,n[7]=E*u+v*a+d*f+m*P,E=e[8],v=e[9],d=e[10],m=e[11],n[8]=E*r+v*l+d*h+m*T,n[9]=E*i+v*o+d*p+m*M,n[10]=E*s+v*c+d*b+m*R,n[11]=E*u+v*a+d*f+m*P,E=e[12],v=e[13],d=e[14],m=e[15],n[12]=E*r+v*l+d*h+m*T,n[13]=E*i+v*o+d*p+m*M,n[14]=E*s+v*c+d*b+m*R,n[15]=E*u+v*a+d*f+m*P,n}function Ae(n,t,e,r){let i=t[0],s=t[1],u=t[2],l=t[3],o=i+i,c=s+s,a=u+u,h=i*o,p=i*c,b=i*a,f=s*c,T=s*a,M=u*a,R=l*o,P=l*c,E=l*a,v=r[0],d=r[1],m=r[2];return n[0]=(1-(f+M))*v,n[1]=(p+E)*v,n[2]=(b-P)*v,n[3]=0,n[4]=(p-E)*d,n[5]=(1-(h+M))*d,n[6]=(T+R)*d,n[7]=0,n[8]=(b+P)*m,n[9]=(T-R)*m,n[10]=(1-(h+f))*m,n[11]=0,n[12]=e[0],n[13]=e[1],n[14]=e[2],n[15]=1,n}function ae(n,t){let e=t[0],r=t[1],i=t[2],s=t[4],u=t[5],l=t[6],o=t[8],c=t[9],a=t[10],h=a*u-l*c,p=-a*s+l*o,b=c*s-u*o,f=e*h+r*p+i*b;return f&&(f=1/f,n[0]=h*f,n[1]=(-a*r+i*c)*f,n[2]=(l*r-i*u)*f,n[3]=p*f,n[4]=(a*e-i*o)*f,n[5]=(-l*e+i*s)*f,n[6]=b*f,n[7]=(-c*e+r*o)*f,n[8]=(u*e-r*s)*f),n}function Pe(n,t){let e=t[0],r=t[1],i=t[2],s=t[3],u=t[4],l=t[5],o=t[6],c=t[7],a=t[8],h=t[9],p=t[10],b=t[11],f=t[12],T=t[13],M=t[14],R=t[15],P=e*l-r*u,E=e*o-i*u,v=e*c-s*u,d=r*o-i*l,m=r*c-s*l,L=i*c-s*o,A=a*T-h*f,x=a*M-p*f,D=a*R-b*f,S=h*M-p*T,C=h*R-b*T,y=p*R-b*M,w=P*y-E*C+v*S+d*D-m*x+L*A;return w?(w=1/w,n[0]=(l*y-o*C+c*S)*w,n[1]=(i*C-r*y-s*S)*w,n[2]=(T*L-M*m+R*d)*w,n[3]=(p*m-h*L-b*d)*w,n[4]=(o*D-u*y-c*x)*w,n[5]=(e*y-i*D+s*x)*w,n[6]=(M*v-f*L-R*E)*w,n[7]=(a*L-p*v+b*E)*w,n[8]=(u*C-l*D+c*A)*w,n[9]=(r*D-e*C-s*A)*w,n[10]=(f*m-T*v+R*P)*w,n[11]=(h*v-a*m-b*P)*w,n[12]=(l*x-u*S-o*A)*w,n[13]=(e*S-r*x+i*A)*w,n[14]=(T*E-f*d-M*P)*w,n[15]=(a*d-h*E+p*P)*w,n):null}function xe(n,t,e,r,i){let s=i[0]*t+i[4]*e+i[8]*r+i[12],u=i[1]*t+i[5]*e+i[9]*r+i[13],l=i[2]*t+i[6]*e+i[10]*r+i[14],o=i[3]*t+i[7]*e+i[11]*r+i[15],c=o!==0?1/o:1;n[0]=s*c,n[1]=u*c,n[2]=l*c}function De(n,t,e,r,i,s,u,l,o,c,a,h,p,b,f,T,M=0){let R=c-u,P=a-l,E=h-o,v=p-u,d=b-l,m=f-o,L=i*m-s*d,A=s*v-r*m,x=r*d-i*v,D=R*L+P*A+E*x;if(D>-1e-7&&D<1e-7)return!1;let S=1/D,C=n-u,y=t-l,w=e-o,k=S*(C*L+y*A+w*x);if(k<-M||k>1+M)return!1;let g=y*E-w*P,X=w*R-C*E,O=C*P-y*R,ne=S*(r*g+i*X+s*O);if(ne<-M||k+ne>1+M)return!1;let N=S*(v*g+d*X+m*O);if(N>1e-4&&N<T.distance){T.distance=N,T.point=[n+r*N,t+i*N,e+s*N];let W=P*m-E*d,B=E*v-R*m,F=R*d-P*v,U=Math.hypot(W,B,F)||1;return T.normal=[W/U,B/U,F/U],!0}return!1}function Se(n,t){let e=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let a=0;a<e;a++)r.push(V());if(e===0)return r;let i=new Set;for(let a of n.nodes)if(Array.isArray(a.children))for(let h of a.children)i.add(h);let s=new Set,u=128,l=(a,h,p=0)=>{if(p>u||a<0||a>=e||s.has(a))return;s.add(a);let b=n.nodes[a];if(!b)return;let f=V();if(t&&t[a])f.set(t[a]);else if(b.matrix&&b.matrix.length===16)f.set(b.matrix);else{let M=b.translation||[0,0,0],R=b.rotation||[0,0,0,1],P=b.scale||[1,1,1];Ae(f,R,M,P)}let T=r[a];if(h?$(T,h,f):T.set(f),Array.isArray(b.children))for(let M of b.children)typeof M=="number"&&l(M,T,p+1)},o=[],c=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(c&&Array.isArray(c.nodes))o.push(...c.nodes);else for(let a=0;a<e;a++)i.has(a)||o.push(a);for(let a of o)l(a,null);for(let a=0;a<e;a++)!i.has(a)&&!o.includes(a)&&l(a,null);return r}function je(n){return new TextDecoder().decode(n)}var Fe=H().decoders;function Ye(n,t){Fe.set(n.toLowerCase(),t)}function he(n){return Fe.get(n.toLowerCase())}function Ie(n){let t=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,e=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=e.getUint32(0,!0);if(r!==1179937895){let p=e.getUint8(0);throw p===123||p===32||p===10||p===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=e.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let s=e.getUint32(8,!0),u=12,l=null,o=null;for(;u+8<=s&&u+8<=t.byteLength;){let p=e.getUint32(u,!0),b=e.getUint32(u+4,!0),f=u+8;if(f+p>t.byteLength)throw new Error(`Truncated GLB chunk: required ${f+p} bytes, buffer has ${t.byteLength}`);if(b===1313821514){let T=new Uint8Array(t,f,p),M=je(T);l=JSON.parse(M,(R,P)=>R==="__proto__"||R==="constructor"||R==="prototype"?void 0:P)}else b===5130562&&(o=t.slice(f,f+p));u=f+p}if(!l)throw new Error("Missing JSON chunk in GLB");let c=l.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!he("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(c.includes("EXT_meshopt_compression")&&!he("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(c.includes("KHR_texture_basisu")&&!he("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=o||new ArrayBuffer(0),h={gltf:l,bin:a,animations:[]};for(let p of G)p.onParseGLB?.(h);return h}function $e(n){return typeof n=="object"&&n!==null&&"gltf"in n&&typeof n.gltf=="object"&&n.gltf!==null&&"bin"in n&&(n.bin instanceof ArrayBuffer||ArrayBuffer.isView(n.bin))}function ge(n){if($e(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return Ie(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Be=`#version 300 es
|
|
18
|
+
layout(location=0) in vec3 aPosition;
|
|
19
|
+
layout(location=1) in vec3 aNormal;
|
|
20
|
+
layout(location=2) in vec2 aUV;
|
|
21
|
+
uniform mat4 uMVP,uModel;
|
|
22
|
+
uniform mat3 uNormalMatrix;
|
|
23
|
+
uniform vec4 uUvTransform;
|
|
24
|
+
out vec3 vNormal,vWorldPos;
|
|
25
|
+
out vec2 vUV;
|
|
26
|
+
void main(){
|
|
27
|
+
vec3 rawN=uNormalMatrix*aNormal;
|
|
28
|
+
vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
|
|
29
|
+
vec4 world=uModel*vec4(aPosition,1.0);
|
|
30
|
+
vWorldPos=world.xyz;
|
|
31
|
+
vec2 scaleUV=uUvTransform.zw;
|
|
32
|
+
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
33
|
+
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
34
|
+
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
35
|
+
}`,ke=`#version 300 es
|
|
36
|
+
precision highp float;
|
|
37
|
+
in vec3 vNormal,vWorldPos;
|
|
38
|
+
in vec2 vUV;
|
|
39
|
+
uniform vec4 uBaseColor;
|
|
40
|
+
uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity;
|
|
41
|
+
uniform vec2 uClearcoat;
|
|
42
|
+
uniform vec3 uCameraPos,uAmbientColor;
|
|
43
|
+
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uXrDepthTex;
|
|
44
|
+
uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uXrDepthEnabled,uXrDepthFormat;
|
|
45
|
+
uniform float uNormalScale,uOcclusionStrength,uXrRawValueToMeters;
|
|
46
|
+
uniform mat4 uXrDepthUVTransform;
|
|
47
|
+
uniform vec2 uViewportSize;
|
|
48
|
+
uniform vec4 uViewport;
|
|
49
|
+
uniform vec3 uCameraFwd;
|
|
50
|
+
uniform int uToneMapping,uNumDirLights,uNumPointLights;
|
|
51
|
+
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
|
|
52
|
+
out vec4 fragColor;
|
|
53
|
+
|
|
54
|
+
vec2 envBRDF(float r,float n){
|
|
55
|
+
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04);
|
|
56
|
+
vec4 rv=r*c0+c1;
|
|
57
|
+
float a=min(rv.x*rv.x,exp2(-9.28*n))*rv.x+rv.y;
|
|
58
|
+
return vec2(-1.04,1.04)*a+rv.zw;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
vec3 F_SchlickRoughness(vec3 F0,float r,float n){
|
|
62
|
+
return F0+(max(vec3(1.0-r),F0)-F0)*pow(clamp(1.0-n,0.0,1.0),5.0);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
vec3 getStudioRadiance(vec3 R,float r){
|
|
66
|
+
vec3 kd=normalize(vec3(0.0,1.0,0.35));
|
|
67
|
+
float ki=pow(max(dot(R,kd),0.0),mix(96.0,1.5,r))*mix(2.4,0.5,r);
|
|
68
|
+
vec3 fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
69
|
+
float fi=pow(max(dot(R,fd),0.0),mix(36.0,1.2,r))*mix(1.3,0.35,r);
|
|
70
|
+
float ri=pow(clamp(1.0-abs(R.y),0.0,1.0),3.5)*mix(0.55,0.22,r);
|
|
71
|
+
vec3 ag=mix(vec3(0.06,0.06,0.08),vec3(0.48,0.50,0.55),R.y*0.5+0.5);
|
|
72
|
+
return ag+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
vec3 perturbNormal(vec3 N,vec3 V,vec2 uv,sampler2D normalMap,float scale){
|
|
76
|
+
vec3 mapNormal=texture(normalMap,uv).xyz*2.0-1.0;
|
|
77
|
+
mapNormal.xy*=scale;
|
|
78
|
+
vec3 dp1=dFdx(vWorldPos);
|
|
79
|
+
vec3 dp2=dFdy(vWorldPos);
|
|
80
|
+
vec2 duv1=dFdx(uv);
|
|
81
|
+
vec2 duv2=dFdy(uv);
|
|
82
|
+
vec3 dp2perp=cross(dp2,N);
|
|
83
|
+
vec3 dp1perp=cross(N,dp1);
|
|
84
|
+
vec3 T=dp2perp*duv1.x+dp1perp*duv2.x;
|
|
85
|
+
vec3 B=dp2perp*duv1.y+dp1perp*duv2.y;
|
|
86
|
+
float invmax=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
87
|
+
return normalize(mat3(T*invmax,B*invmax,N)*normalize(mapNormal));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
vec2 equirectangularUV(vec3 dir){
|
|
91
|
+
vec3 d=normalize(dir);
|
|
92
|
+
float u=atan(d.z,d.x)*0.15915494309+0.5;
|
|
93
|
+
float v=asin(clamp(d.y,-1.0,1.0))*0.31830988618+0.5;
|
|
94
|
+
return vec2(u,1.0-v);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
vec3 neutralToneMapping(vec3 color){
|
|
98
|
+
const float startCompression=0.76;
|
|
99
|
+
const float desaturation=0.15;
|
|
100
|
+
float x=min(color.r,min(color.g,color.b));
|
|
101
|
+
float offset=x<0.08?x-6.25*x*x:0.04;
|
|
102
|
+
color-=offset;
|
|
103
|
+
float peak=max(color.r,max(color.g,color.b));
|
|
104
|
+
if(peak<startCompression)return color;
|
|
105
|
+
const float d=1.0-startCompression;
|
|
106
|
+
float newPeak=1.0-d*d/(peak+d-startCompression);
|
|
107
|
+
color*=newPeak/peak;
|
|
108
|
+
float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
|
|
109
|
+
return mix(color,newPeak*vec3(1.0),g);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
vec3 applyToneMapping(vec3 color,int mode){
|
|
113
|
+
if(mode==0)return neutralToneMapping(color);
|
|
114
|
+
if(mode==1)return color/(color+vec3(1.0));
|
|
115
|
+
return color;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
void main(){
|
|
119
|
+
vec4 base=uBaseColor;
|
|
120
|
+
if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
|
|
121
|
+
if(length(vNormal)<1e-4&&uHasTexture==1){
|
|
122
|
+
vec3 unlit=base.rgb+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
123
|
+
fragColor=vec4(unlit,base.a);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
vec3 N=length(vNormal)<1e-4?normalize(cross(dFdx(vWorldPos),dFdy(vWorldPos))):normalize(vNormal);
|
|
127
|
+
if(!gl_FrontFacing)N=-N;
|
|
128
|
+
vec3 V=normalize(uCameraPos-vWorldPos);
|
|
129
|
+
if(uHasNormalTexture==1){
|
|
130
|
+
N=perturbNormal(N,V,vUV,uNormalTexture,uNormalScale);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
float metallic=uMetallic;
|
|
134
|
+
float roughness=uRoughness;
|
|
135
|
+
if(uHasMetallicRoughnessTexture==1){
|
|
136
|
+
vec4 mr=texture(uMetallicRoughnessTexture,vUV);
|
|
137
|
+
roughness*=mr.g;
|
|
138
|
+
metallic*=mr.b;
|
|
139
|
+
}
|
|
140
|
+
roughness=clamp(roughness,0.04,1.0);
|
|
141
|
+
metallic=clamp(metallic,0.0,1.0);
|
|
142
|
+
|
|
143
|
+
float occ=1.0;
|
|
144
|
+
if(uHasOcclusionTexture==1){
|
|
145
|
+
occ=mix(1.0,texture(uOcclusionTexture,vUV).r,uOcclusionStrength);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
float gloss=1.0-roughness;
|
|
149
|
+
float specExp=mix(16.0,256.0,gloss*gloss);
|
|
150
|
+
float specWeight=mix(0.22*gloss,1.0,metallic);
|
|
151
|
+
vec3 directLight=vec3(0.0);
|
|
152
|
+
for(int i=0;i<2;i++){
|
|
153
|
+
if(i>=uNumDirLights)break;
|
|
154
|
+
vec3 L=normalize(uDirLightDir[i]);
|
|
155
|
+
float NdotL=max(dot(N,L),0.0);
|
|
156
|
+
vec3 H=normalize(L+V);
|
|
157
|
+
float NoH=max(dot(N,H),0.0);
|
|
158
|
+
float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
|
|
159
|
+
directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uDirLightColor[i];
|
|
160
|
+
}
|
|
161
|
+
for(int i=0;i<2;i++){
|
|
162
|
+
if(i>=uNumPointLights)break;
|
|
163
|
+
vec3 toLight=uPointLightPos[i]-vWorldPos;
|
|
164
|
+
float dist=length(toLight);
|
|
165
|
+
vec3 L=toLight/max(dist,0.0001);
|
|
166
|
+
float atten=1.0/(1.0+0.09*dist+0.032*dist*dist);
|
|
167
|
+
float NdotL=max(dot(N,L),0.0);
|
|
168
|
+
vec3 H=normalize(L+V);
|
|
169
|
+
float NoH=max(dot(N,H),0.0);
|
|
170
|
+
float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
|
|
171
|
+
directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uPointLightColor[i]*atten;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
vec3 R=reflect(-V,N);
|
|
175
|
+
float NoV=clamp(dot(N,V),0.001,1.0);
|
|
176
|
+
vec3 F0=mix(vec3(0.04),base.rgb,metallic);
|
|
177
|
+
vec3 F=F_SchlickRoughness(F0,roughness,NoV);
|
|
178
|
+
vec2 brdf=envBRDF(roughness,NoV);
|
|
179
|
+
|
|
180
|
+
vec3 specularIBL;
|
|
181
|
+
vec3 envDiffuse;
|
|
182
|
+
if(uHasEnvironmentMap==1){
|
|
183
|
+
specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
|
|
184
|
+
envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
|
|
185
|
+
}else{
|
|
186
|
+
specularIBL=getStudioRadiance(R,roughness)*(F*brdf.x+brdf.y);
|
|
187
|
+
envDiffuse=mix(vec3(0.10,0.10,0.12),vec3(0.52,0.54,0.58),N.y*0.5+0.5);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
vec3 kD=(vec3(1.0)-F)*(1.0-metallic);
|
|
191
|
+
vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
192
|
+
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
193
|
+
if(uClearcoat.x>0.0){
|
|
194
|
+
vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
|
|
195
|
+
color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
196
|
+
}
|
|
197
|
+
color=applyToneMapping(color,uToneMapping);
|
|
198
|
+
float outAlpha=base.a;
|
|
199
|
+
if(uXrDepthEnabled==1){
|
|
200
|
+
vec2 normViewUV=vec2((gl_FragCoord.x-uViewport.x)/max(uViewport.z,1.0),1.0-(gl_FragCoord.y-uViewport.y)/max(uViewport.w,1.0));
|
|
201
|
+
vec2 depthUV=(uXrDepthUVTransform*vec4(normViewUV,0.0,1.0)).xy;
|
|
202
|
+
if(depthUV.x>=0.0&&depthUV.x<=1.0&&depthUV.y>=0.0&&depthUV.y<=1.0){
|
|
203
|
+
vec4 depthSample=texture(uXrDepthTex,depthUV);
|
|
204
|
+
float rawDepth=uXrDepthFormat==1?depthSample.r:(depthSample.r*255.0+depthSample.a*65280.0);
|
|
205
|
+
float realDepth=rawDepth*uXrRawValueToMeters;
|
|
206
|
+
float virtDepth=dot(uCameraFwd,uCameraFwd)>0.5?dot(vWorldPos-uCameraPos,uCameraFwd):length(uCameraPos-vWorldPos);
|
|
207
|
+
if(rawDepth>0.0&&(uXrDepthFormat==1||rawDepth<65500.0)&&realDepth>0.15&&realDepth<20.0&&virtDepth>realDepth+0.02){
|
|
208
|
+
float occAlpha=1.0-smoothstep(0.0,0.035,virtDepth-realDepth-0.02);
|
|
209
|
+
outAlpha*=occAlpha;
|
|
210
|
+
if(outAlpha<0.01)discard;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
fragColor=vec4(color,outAlpha);
|
|
215
|
+
}`,qe=`#version 300 es
|
|
216
|
+
layout(location=0) in vec3 aPosition;
|
|
217
|
+
uniform mat4 uMVP;
|
|
218
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Ke=`#version 300 es
|
|
219
|
+
precision highp float;
|
|
220
|
+
uniform vec4 uColorId;
|
|
221
|
+
out vec4 fragColor;
|
|
222
|
+
void main(){fragColor=uColorId;}`;function Ce(n,t,e){let r=n.createShader(t);if(n.shaderSource(r,e),n.compileShader(r),!n.getShaderParameter(r,35713)){let i=n.getShaderInfoLog(r);throw n.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function Te(n,t,e){let r=Ce(n,35633,t),i=Ce(n,35632,e),s=n.createProgram();if(n.attachShader(s,r),n.attachShader(s,i),n.linkProgram(s),!n.getProgramParameter(s,35714)){let u=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${u}`)}return s}function Me(n,t,e){let r={};for(let i of e)r[i]=n.getUniformLocation(t,i);return r}var Ne=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uXrDepthTex","uXrDepthEnabled","uXrDepthFormat","uXrRawValueToMeters","uXrDepthUVTransform","uViewportSize","uViewport","uCameraFwd"];function Ze(n){if(typeof n!="string")return null;let t=n.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let e=t.toLowerCase();return e.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:e.startsWith("https://")||e.startsWith("blob:")?t:e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function ye(n,t,e,r,i,s,u){if(r===void 0||!t.accessors?.[r])return null;let l=t.accessors[r],o=t.bufferViews[l.bufferView],c=(o.byteOffset||0)+(l.byteOffset||0),a=o.byteStride&&o.byteStride>s*4?o.byteStride>>2:s,h;if(a===s)h=new Float32Array(e,c,l.count*s);else{h=new Float32Array(l.count*s);let b=new Float32Array(e,o.byteOffset||0,Math.floor(o.byteLength/4)),f=(l.byteOffset||0)>>2;for(let T=0;T<l.count;T++){let M=f+T*a;for(let R=0;R<s;R++)h[T*s+R]=b[M+R]}}let p=n.createBuffer();return u.push(p),n.bindBuffer(34962,p),n.bufferData(34962,h,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),h}var Ue=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Oe=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Le(n,t,e=Oe,r){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:s}=t,u=[],l=Se(i),o=[];if(Array.isArray(i.nodes))for(let A=0;A<i.nodes.length;A++){let x=i.nodes[A];x.mesh!==void 0&&i.meshes&&i.meshes[x.mesh]&&o.push({node:x,nodeIdx:A,meshIdx:x.mesh})}let c=o.length>0?o:(i.meshes||[]).map((A,x)=>({node:A,nodeIdx:-1,meshIdx:x})),a=[];if(Array.isArray(t.lights)&&t.lights.length>0)a.push(...t.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let A=i.extensions.KHR_lights_punctual.lights;for(let x of A){let D=x.type==="directional"?"directional":x.type==="point"?"point":"ambient";a.push({type:D,color:x.color||[1,1,1],intensity:x.intensity!==void 0?x.intensity:1})}}if(a.length===0&&(a.push({type:"ambient",color:[1,1,1],intensity:.35}),a.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),c.length>e.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${e.maxMeshes}). Found: ${c.length}`);let h=[];if(i.textures&&i.images){if(i.textures.length>e.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${e.maxTextures}). Found: ${i.textures.length}`);for(let A=0;A<i.textures.length;A++){let x=i.textures[A],D=i.images[x.source];if(D){let S=n.createTexture();if(n.bindTexture(3553,S),n.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),n.texParameteri(3553,10242,10497),n.texParameteri(3553,10243,10497),n.texParameteri(3553,10241,9729),n.texParameteri(3553,10240,9729),D.bufferView!==void 0){let C=i.bufferViews[D.bufferView],y=s.slice(C.byteOffset||0,(C.byteOffset||0)+C.byteLength),w=new Blob([y],{type:D.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(w).then(k=>{n.bindTexture(3553,S),n.texImage2D(3553,0,6408,6408,5121,k),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(D.uri){let C=Ze(D.uri);if(C){let y=new Image;y.crossOrigin="anonymous",y.referrerPolicy="no-referrer",y.onload=()=>{n.bindTexture(3553,S),n.texImage2D(3553,0,6408,6408,5121,y),n.generateMipmap(3553),r?.()},y.src=C}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",D.uri)}h.push(S)}else h.push(null)}}let p=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0],f=0,T=0;for(let A=0;A<c.length;A++){let x=c[A],D=i.meshes[x.meshIdx],S=x.nodeIdx>=0?l[x.nodeIdx]:V(),C=new Float32Array(9);ae(C,S);let y={name:x.node.name||D.name||`Mesh_${x.meshIdx}`,nodeIndex:x.nodeIdx,transform:S,normalMatrix:C,primitives:[],extras:x.node.extras||D.extras};for(let w of D.primitives||[]){if(w.extensions?.KHR_draco_mesh_compression){let I=he("draco");I&&I.decodePrimitive(i,w,s)}let k=[],g=n.createVertexArray();n.bindVertexArray(g);let X=i.accessors[w.attributes.POSITION],O=Number(X?.count??0);if(!Number.isFinite(O)||O<0||f+O>e.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${e.maxVertices}).`);if(f+=O,X?.min&&X?.max)for(let I=0;I<3;I++){let K=S[12+I],oe=S[12+I];for(let ee=0;ee<3;ee++){let de=S[ee*4+I]*X.min[ee],pe=S[ee*4+I]*X.max[ee];K+=de<pe?de:pe,oe+=de>pe?de:pe}K<p[I]&&(p[I]=K),oe>b[I]&&(b[I]=oe)}let ne=ye(n,i,s,w.attributes.POSITION,0,3,k);ye(n,i,s,w.attributes.NORMAL,1,3,k),ye(n,i,s,w.attributes.TEXCOORD_0,2,2,k);let N=0,W=5123,B=null;if(w.indices!==void 0){let I=i.accessors[w.indices],oe=(i.bufferViews[I.bufferView].byteOffset||0)+(I.byteOffset||0);if(N=Number(I.count??0),!Number.isFinite(N)||N<0||T+N>e.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${e.maxIndices}).`);T+=N,W=I.componentType===5125?5125||5125:5123||5123;let ee=n.createBuffer();k.push(ee),n.bindBuffer(34963,ee),I.componentType===5125?(B=new Uint32Array(s,oe,I.count),n.bufferData(34963,B,35044)):(B=new Uint16Array(s,oe,I.count),n.bufferData(34963,B,35044))}else N=X.count;let F={};for(let I of G)if(I.onBuildPrimitiveVAO){let K=I.onBuildPrimitiveVAO(n,g,w,i,s);K&&(F[I.name]=K)}n.bindVertexArray(null);let U=i.materials&&w.material!==void 0?i.materials[w.material]:null,z=Be,Z=ke,Q=!1;for(let I of G)if(I.onResolveShader){let K=I.onResolveShader(w,U,z,Z);K&&(z=K.vs,Z=K.fs,Q=!0)}let J=Q?Te(n,z,Z):null,me=J?Me(n,J,Ne):null,Y=U?.pbrMetallicRoughness,q=Y?.baseColorFactor||[.8,.8,.8,1],ue=Y?.metallicFactor??.1,ce=Y?.roughnessFactor??.5,se=U?.extensions?.KHR_materials_clearcoat,te=se?se.clearcoatFactor??1:0,ie=Math.max(.04,se?.clearcoatRoughnessFactor??.04),re=Y?.baseColorTexture!==void 0&&h[Y.baseColorTexture.index]?h[Y.baseColorTexture.index]:null,le=Y?.metallicRoughnessTexture!==void 0&&h[Y.metallicRoughnessTexture.index]?h[Y.metallicRoughnessTexture.index]:null,Ve=U?.normalTexture!==void 0&&h[U.normalTexture.index]?h[U.normalTexture.index]:null,He=U?.normalTexture?.scale??1,Xe=U?.occlusionTexture!==void 0&&h[U.occlusionTexture.index]?h[U.occlusionTexture.index]:null,We=U?.occlusionTexture?.strength??1,ze=!!(U?.extensions?.KHR_materials_transmission||F.materials?.isTransmissive);y.primitives.push({vao:g,indexCount:N,indexType:W,baseColor:q,metallic:ue,roughness:ce,clearcoat:te,clearcoatRoughness:ie,positions:ne,indices:B,texture:re,metallicRoughnessTexture:le,normalTexture:Ve,occlusionTexture:Xe,normalScale:He,occlusionStrength:We,buffers:k,materialIndex:w.material,pluginData:F,customProgram:J,customUniforms:me,isTransmissive:ze})}u.push(y)}isFinite(p[0])||(p=[-1,-1,-1]),isFinite(b[0])||(b=[1,1,1]);let M=[(p[0]+b[0])/2,(p[1]+b[1])/2,(p[2]+b[2])/2],R=b[0]-p[0],P=b[1]-p[1],E=b[2]-p[2],v=Math.max(Math.hypot(R,P,E)/2,.5),d=[p[0],p[1],p[2]],m=[b[0],b[1],b[2]],L=t.animations;if(!L){for(let A of G)if(A.onParseGLB?.(t),t.animations){L=t.animations;break}}return L||(L=[]),{meshes:u,bounds:{center:M,radius:v,min:d,max:m},lights:a,animations:L,worldMatrices:l}}var j=class{constructor(t,e,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=V();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=V();this.viewMatrix=V();this.modelMatrix=V();this.mvpMatrix=V();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:V(),rawValueToMeters:.001,format:0};this.container=t;let i,s;if(e&&typeof e.getContext=="function"?(i=e,s=r):(s=e,i=s?.canvas),!i){let o=t.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",t.prepend(o)),i=o}this.canvas=i,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let u=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!u:u&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.renderProg=Te(l,Be,ke),this.pickProg=Te(l,qe,Ke),this.uRender=Me(l,this.renderProg,Ne),this.uPick=Me(l,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(t,e){Ye(t,e)}static getDecoder(t){return he(t)}setupPickingFbo(){let t=this.gl;if(typeof t.createFramebuffer!="function")return;this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer();let e=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=e,this.pickFboHeight=r,t.bindTexture(3553,this.pickTexture),t.texImage2D(3553,0,6408,e,r,0,6408,5121,null),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728),t.bindRenderbuffer(36161,this.pickDepth),t.renderbufferStorage(36161,33189,e,r),t.bindFramebuffer(36160,this.pickFbo),t.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),t.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),t.bindFramebuffer(36160,null)}resizePickingFbo(t,e){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,t),s=Math.max(1,e);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(t,e){let{meshes:r,bounds:i,lights:s,animations:u,worldMatrices:l}=Le(this.gl,t,e,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=u||[],this.worldMatrices=l||[],this.gltf=t.gltf,this.initialNodeTransforms=[],Array.isArray(t.gltf?.nodes))for(let c of t.gltf.nodes)this.initialNodeTransforms.push({t:c.translation?[c.translation[0],c.translation[1],c.translation[2]]:[0,0,0],r:c.rotation?[c.rotation[0],c.rotation[1],c.rotation[2],c.rotation[3]]:[0,0,0,1],s:c.scale?[c.scale[0],c.scale[1],c.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let c of G)c.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let o=t.exposure??t.environmentIntensity??t.gltf?.extras?.exposure??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.exposure??t.gltf?.asset?.extras?.environmentIntensity;o!==void 0&&(this.envIntensity=Math.max(0,Number(o))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(t){this.loadGLBData(Ie(t))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(ge(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let r=ge(t),{meshes:i}=Le(this.gl,r,Oe,()=>this.render());if(e)for(let s of i)s.transform[12]+=e[0],s.transform[13]+=e[1],s.transform[14]+=e[2],ae(s.normalMatrix,s.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(t,e,r,i=1){this.clearColor=[t,e,r,i]}updateMeshTransforms(t){for(let e=0;e<this.meshes.length;e++){let r=this.meshes[e],i;t instanceof Map?i=t.get(r.name)??t.get(e):Array.isArray(t)?i=t[e]:t&&typeof t=="object"&&(Object.prototype.hasOwnProperty.call(t,r.name)?i=t[r.name]:Object.prototype.hasOwnProperty.call(t,e)&&(i=t[e])),i&&i.length===16&&(r.transform.set(i),ae(r.normalMatrix,r.transform))}}bindLights(t=this.uRender){let e=this.gl,r=[.28,.28,.28],i=[],s=[],u=[],l=[];for(let o of this.lights){let c=o.color||[1,1,1],a=o.intensity!==void 0?o.intensity:1;if(o.type==="ambient")r=[c[0]*a,c[1]*a,c[2]*a];else if(o.type==="directional"&&i.length<6){let h=o.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),s.push(c[0]*a,c[1]*a,c[2]*a)}else if(o.type==="point"&&u.length<6){let h=o.position||[0,0,0];u.push(h[0],h[1],h[2]),l.push(c[0]*a,c[1]*a,c[2]*a)}}i.length===0&&(i.push(.5,1,.8),s.push(1,1,1)),e.uniform3fv(t.uAmbientColor,r),e.uniform1i(t.uNumDirLights,i.length/3),i.length>0&&(e.uniform3fv(t.uDirLightDir,i),e.uniform3fv(t.uDirLightColor,s)),e.uniform1i(t.uNumPointLights,u.length/3),u.length>0&&(e.uniform3fv(t.uPointLightPos,u),e.uniform3fv(t.uPointLightColor,l)),e.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.envIntensity=Math.max(0,Number(t))}getExposure(){return this.envIntensity}setShadow(t,e){this.shadowIntensity=Math.max(0,Math.min(1,Number(t)||0)),e!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(e)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(t){this.toneMapping=t}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){for(let e of G)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t);return}}async setSkyboxImage(t){for(let e of G)if(e.setSkyboxImage){await e.setSkyboxImage(this,t);return}}setInteractive(t){this.interactive=t}isInteractive(){return this.interactive}getCameraOrbit(){let t=this.currTheta,e=this.currPhi,r=this.currDistance;return{theta:t,phi:e,radius:r,toString(){return`${t.toFixed(4)}rad ${e.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let t=this.customTarget||this.bounds.center;return{x:t[0],y:t[1],z:t[2],toString(){return`${t[0].toFixed(4)}m ${t[1].toFixed(4)}m ${t[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let t=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return t.map((e,r)=>{let i=this.meshes.flatMap(a=>a.primitives.filter(h=>h.materialIndex===r||t.length===1&&h.materialIndex===void 0)),s=i[0],u=s?[...s.baseColor]:e.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=s?s.metallic:e.pbrMetallicRoughness?.metallicFactor??.1,o=s?s.roughness:e.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:u,metallicFactor:l,roughnessFactor:o,setBaseColorFactor:a=>{let h=[a[0],a[1],a[2],a[3]??1];c.baseColorFactor=h,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.baseColorFactor=h);for(let p of i)p.baseColor=h;this.render()},setMetallicFactor:a=>{c.metallicFactor=a,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.metallicFactor=a);for(let h of i)h.metallic=a;this.render()},setRoughnessFactor:a=>{c.roughnessFactor=a,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.roughnessFactor=a);for(let h of i)h.roughness=a;this.render()}};return{name:e.name||`Material_${r}`,pbrMetallicRoughness:c}})}playAnimation(t){if(this.animations.length!==0){if(t){let e=this.animations.find(r=>r.name===t);e&&(this.currentClip=e)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(t=>t.name)}setAutoplay(t){this.autoplay=t,t?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(t){this.animationName=t,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(t)}evaluateAnimation(t){for(let e of G)if(e.evaluateAnimation){e.evaluateAnimation(this,t);return}}setTarget(t,e,r){this.customTarget=[t,e,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(t){let e=Math.max(10,Math.min(90,t));this.fov=e*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(t){if(this.distanceMode=t,!this.customDistance){let e=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=e,this.targetDistance=e,this.currDistance=e,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(t){t.minTheta!==void 0&&(this.minTheta=t.minTheta*Math.PI/180),t.maxTheta!==void 0&&(this.maxTheta=t.maxTheta*Math.PI/180),t.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,t.minPhi*Math.PI/180)),t.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,t.maxPhi*Math.PI/180)),t.minDistance!==void 0&&(this.minDistanceLimit=t.minDistance),t.maxDistance!==void 0&&(this.maxDistanceLimit=t.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(t){return Math.max(this.minTheta,Math.min(this.maxTheta,t))}clampPhi(t){return Math.max(this.minPhi,Math.min(this.maxPhi,t))}clampDistance(t){let e=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(e,Math.min(r,t))}setCamera(t,e,r,i){t!==void 0&&(this.targetTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.targetPhi=this.clampPhi(e*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(t,e,r,i){if(t!==void 0&&(this.initialTheta=this.clampTheta(t*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),e!==void 0&&(this.initialPhi=this.clampPhi(e*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(t,e){let r=V();$(r,this.projMatrix,this.viewMatrix);let[i,s,u]=t,l=e?e[0]:0,o=e?e[1]:0,c=e?e[2]:0,a=this.modelRootMatrix;a&&(i=a[0]*t[0]+a[4]*t[1]+a[8]*t[2]+a[12],s=a[1]*t[0]+a[5]*t[1]+a[9]*t[2]+a[13],u=a[2]*t[0]+a[6]*t[1]+a[10]*t[2]+a[14],e&&(l=a[0]*e[0]+a[4]*e[1]+a[8]*e[2],o=a[1]*e[0]+a[5]*e[1]+a[9]*e[2],c=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]));let h=r[0]*i+r[4]*s+r[8]*u+r[12],p=r[1]*i+r[5]*s+r[9]*u+r[13],b=r[2]*i+r[6]*s+r[10]*u+r[14],f=r[3]*i+r[7]*s+r[11]*u+r[15];if(f<=1e-4)return{x:0,y:0,z:1,visible:!1};let T=h/f,M=p/f,R=b/f,P=this.canvas.getBoundingClientRect(),E=P.width||this.canvas.clientWidth||this.canvas.width||300,v=P.height||this.canvas.clientHeight||this.canvas.height||150,d=(T*.5+.5)*E,m=(-M*.5+.5)*v,L=T>=-1.1&&T<=1.1&&M>=-1.1&&M<=1.1&&R>=-1&&R<=1;if(L&&e){let A=this.customTarget||this.bounds.center,x=A[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),D=A[1]+this.currDistance*Math.sin(this.currPhi),S=A[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),C=[i-x,s-D,u-S];l*C[0]+o*C[1]+c*C[2]>.05&&(L=!1)}return{x:d,y:m,z:R,visible:L}}setSelectedMesh(t){this.selectedMeshName=t||""}setupEvents(){let t=this.canvas;this.boundContextMenu=e=>{e.preventDefault()},t.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=e=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=e.clientX,this.lastPointerY=e.clientY,this.totalDragDist=0,this.activePointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.isPanning=e.button===2||e.shiftKey||this.activePointers.size===2,t.setPointerCapture(e.pointerId))},t.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=e=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(e.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=e.clientX-r.x,s=e.clientY-r.y;if(this.activePointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.lastPointerX=e.clientX,this.lastPointerY=e.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||e.button===2||e.shiftKey||this.activePointers.size===2){let u=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],l=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],o=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;o[0]+=(-i*u[0]+s*l[0])*c,o[1]+=(-i*u[1]+s*l[1])*c,o[2]+=(-i*u[2]+s*l[2])*c,this.customTarget=o}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},t.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=e=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(e.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{t.releasePointerCapture(e.pointerId)}catch{}if(this.totalDragDist<5&&e.button===0){let r=t.getBoundingClientRect(),i=Math.floor((e.clientX-r.left)*(t.width/Math.max(r.width,1))),s=Math.floor((e.clientY-r.top)*(t.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},t.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=e=>{if(!this.interactive)return;e.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(e.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},t.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=e=>{let r=e.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),t.tabIndex!==void 0&&t.tabIndex<0&&(t.tabIndex=0),t.getAttribute?.("role")||t.setAttribute?.("role","region"),t.getAttribute?.("aria-label")||t.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=e=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(e.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),e.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),e.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),e.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),e.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),e.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),e.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),e.preventDefault();break}},t.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let t=this.canvas;this.boundContextMenu&&(t.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(t.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(t.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(t.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(t.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(t.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(t,e){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,u=r.height||300,l=i.width>0?Math.floor((t-i.left)*(s/i.width)):Math.floor(t),o=i.height>0?Math.floor((e-i.top)*(u/i.height)):Math.floor(e);return this.performMeshPick(l,o,!1)}performMeshPick(t,e,r=!0){if(this.meshes.length===0)return null;let i=this.gl,s=Math.max(1,this.canvas.width||300),u=Math.max(1,this.canvas.height||300);t=this.mapStereoPickX(t,s);let l=V();$(l,this.projMatrix,this.viewMatrix);let o=[],c=Math.max(0,Math.min(s-1,t)),a=Math.max(0,Math.min(u-1,u-1-e));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==u)&&this.resizePickingFbo(s,u),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,u),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let L=0;L<this.meshes.length;L++){let A=this.meshes[L];if(A.visible===!1||A.isPluginMesh)continue;let x=L+1,D=(x&255)/255,S=(x>>8&255)/255,C=(x>>16&255)/255;i.uniform4f(this.uPick.uColorId,D,S,C,1),$(this.modelMatrix,this.modelRootMatrix,A.transform),$(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let y of A.primitives)i.bindVertexArray(y.vao),i.drawElements(4,y.indexCount,y.indexType,0)}let d=new Uint8Array(4);i.readPixels(c,a,1,1,6408,5121,d),i.bindFramebuffer(36160,null);let m=d[0]+(d[1]<<8)+(d[2]<<16);m>0&&m<=this.meshes.length&&(o=[this.meshes[m-1]])}o.length===0&&(o=this.meshes.filter(d=>d.visible!==!1));let h=null,p=1/0,b=[0,0,0],f=[0,1,0],T=this.customTarget||this.bounds.center,M=T[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),R=T[1]+this.currDistance*Math.sin(this.currPhi),P=T[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let d of o){$(this.modelMatrix,this.modelRootMatrix,d.transform),$(this.mvpMatrix,l,this.modelMatrix);let m=V();if(!Pe(m,this.mvpMatrix))continue;let L=(c+.5)/s*2-1,A=(a+.5)/u*2-1,x=[0,0,0],D=[0,0,0];xe(x,L,A,-1,m),xe(D,L,A,1,m);let S=D[0]-x[0],C=D[1]-x[1],y=D[2]-x[2],w=Math.hypot(S,C,y)||1,k=S/w,g=C/w,X=y/w,O={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((N=>{for(let W of d.primitives){if(!W.positions)continue;let B=W.positions,F=W.indices,U=Math.floor(F?F.length/3:B.length/9);for(let z=0;z<U;z++){let Z=F?F[z*3]:z*3,Q=F?F[z*3+1]:z*3+1,J=F?F[z*3+2]:z*3+2;De(x[0],x[1],x[2],k,g,X,B[Z*3],B[Z*3+1],B[Z*3+2],B[Q*3],B[Q*3+1],B[Q*3+2],B[J*3],B[J*3+1],B[J*3+2],O,N)}}})(1e-4),isFinite(O.distance)){let N=O.point[0],W=O.point[1],B=O.point[2],F=this.modelMatrix,U=F[0]*N+F[4]*W+F[8]*B+F[12],z=F[1]*N+F[5]*W+F[9]*B+F[13],Z=F[2]*N+F[6]*W+F[10]*B+F[14],Q=U-M,J=z-R,me=Z-P,Y=Math.hypot(Q,J,me);if(Y<p){ae(this.normalMatrix,this.modelMatrix);let q=this.normalMatrix,ue=O.normal[0],ce=O.normal[1],se=O.normal[2],te=q[0]*ue+q[3]*ce+q[6]*se,ie=q[1]*ue+q[4]*ce+q[7]*se,re=q[2]*ue+q[5]*ce+q[8]*se,le=Math.hypot(te,ie,re)||1;te/=le,ie/=le,re/=le,te*Q+ie*J+re*me>0&&(te=-te,ie=-ie,re=-re),h=d,p=Math.round(Y*1e3)/1e3,b=[Math.round(U*1e3)/1e3,Math.round(z*1e3)/1e3,Math.round(Z*1e3)/1e3],f=[Math.round(te*1e3)/1e3,Math.round(ie*1e3)/1e3,Math.round(re*1e3)/1e3]}}}if(!h)return null;let v={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:p,hitPoint:b,normal:f,screenX:t,screenY:e};if(r){for(let d of G)d.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}mapStereoPickX(t,e){if(!this.stereoSBS||this.xrSessionActive||e<2)return t;let r=Math.max(1,Math.floor(e*.5)),i=t>=r,s=i?t-r:t,u=i?Math.max(1,e-r):r,l=(s+.5)/u*2-1;return Math.floor((l*.5+1)*.5*e)}setStereoSBS(t){this.stereoSBS=!!t,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let t=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),e=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);be(this.projMatrix,this.fov,t,.1,e);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=r[1]+this.currDistance*Math.sin(this.currPhi),u=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);ve(this.viewMatrix,[i,s,u],r,[0,1,0]),$(this.mvpMatrix,this.projMatrix,this.viewMatrix),ae(this.normalMatrix,this.modelMatrix)}resize(){let t=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),e=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(e.width*t)),i=Math.max(1,Math.floor(e.height*t));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(t){let e=this.xrSessionActive;if(this.xrSessionActive=t,e&&!t){this.xrDepthState.enabled=!1;for(let r of G)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let e of G)e.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let t=e=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((e-this.lastTime)/1e3,0),.1);if(this.lastTime=e,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(t))};this.animFrameId=requestAnimationFrame(t)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(t){this.autoRotate=t}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(t){this.autoRotateSpeed=t}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(t){this.autoRotateDelay=Math.max(0,Number(t)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(t=0){this.turntableRotation=Number(t)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let t=Math.cos(this.turntableRotation),e=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],s=this.modelRootMatrix;s[0]=t,s[1]=0,s[2]=-e,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=e,s[9]=0,s[10]=t,s[11]=0,s[12]=r-(t*r+e*i),s[13]=0,s[14]=i-(-e*r+t*i),s[15]=1}setVisible(t){this.isVisible=t}update(t){for(let u of G)u.onUpdate?.(this,t);let e=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&e-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let u of G)u.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=s;let u={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(u),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:u}))}}renderXRView(t,e,r,i,s=!0,u=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let l=t?.transform?.inverse?.matrix||this.viewMatrix,o=t?.projectionMatrix||this.projMatrix,c=t?.transform?.position,a=c?[c.x,c.y,c.z]:[0,1.6,0];e?this.modelRootMatrix.set(e):r&&e&&this.modelRootMatrix.set(e),this.render({viewMatrix:l,projMatrix:o,eyePos:a,viewport:i,eye:t?.eye||"none",clear:u>0?!1:t?.eye!=="right",isAR:s})}render(t){if(!t&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),d=Math.max(1,this.canvas.height||1),m=Math.max(1,Math.floor(v*.5)),L=Math.max(1,v-m),A=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),x=this.customTarget||this.bounds.center,D=x[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),S=x[1]+this.currDistance*Math.sin(this.currPhi),C=x[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),y=Math.cos(this.currTheta),w=-Math.sin(this.currTheta),k=.032,g=V(),X=V(),O=[D-y*k,S,C-w*k],ne=[x[0]-y*k*.25,x[1],x[2]-w*k*.25];be(g,this.fov,m/d,.1,A),ve(X,O,ne,[0,1,0]);let N=V(),W=V(),B=[D+y*k,S,C+w*k],F=[x[0]+y*k*.25,x[1],x[2]+w*k*.25];be(N,this.fov,L/d,.1,A),ve(W,B,F,[0,1,0]),this.render({viewMatrix:X,projMatrix:g,eyePos:O,viewport:[0,0,m,d],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:W,projMatrix:N,eyePos:B,viewport:[m,0,L,d],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,d);return}let e=this.gl,r=0,i=0,s=this.canvas.width,u=this.canvas.height;t?.viewport?(r=t.viewport[0],i=t.viewport[1],s=t.viewport[2],u=t.viewport[3],e.viewport(r,i,s,u)):e.viewport(0,0,this.canvas.width,this.canvas.height),e.enable(2929),(!t||t.clear!==!1)&&(t?.isAR?e.clearColor(0,0,0,0):e.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),e.clear(16384|256));let l=V(),o=t?.viewMatrix??this.viewMatrix;$(l,t?.projMatrix??this.projMatrix,o);let c=[-o[2],-o[6],-o[10]],a=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,h=this.customTarget||this.bounds.center,p=t?t.eyePos[0]:h[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),b=t?t.eyePos[1]:h[1]+this.currDistance*Math.sin(this.currPhi),f=t?t.eyePos[2]:h[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let v of G)v.onBeforeDrawScene?.(this,e,l,[p,b,f],a);let T=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&T===0)return;let M=t?.eye||"none",R=!1,P=T>0?[...this.backdropMeshes,...this.meshes]:this.meshes,E=v=>{for(let d=0;d<P.length;d++){let m=P[d];if(m.visible===!1)continue;let L=this.selectedMeshName!==""&&m.name===this.selectedMeshName;d<T||m.worldSpace===!0||m.name==="__xr_reticle__"?this.modelMatrix.set(m.transform):$(this.modelMatrix,this.modelRootMatrix,m.transform),$(this.mvpMatrix,l,this.modelMatrix),ae(m.normalMatrix,this.modelMatrix);let A=m.extras?.xr?.stereo||m.userData?.xr?.stereo,x=0,D=0,S=1,C=1;A==="sbs"?(S=.5,x=M==="right"?.5:0):A==="ou"&&(C=.5,D=M==="right"?.5:0);for(let y of m.primitives){let w=!!y.isTransmissive;if(!v&&w){R=!0;continue}if(v&&!w)continue;let k=y.customProgram||this.renderProg,g=y.customUniforms||this.uRender;e.useProgram(k),e.uniform1i(g.uToneMapping,a),e.uniform1f(g.uEnvIntensity,this.envIntensity),e.uniform3f(g.uCameraPos,p,b,f),g.uCameraFwd&&e.uniform3f(g.uCameraFwd,c[0],c[1],c[2]),e.uniform1f(g.uEmissive,L?1:0),e.uniformMatrix4fv(g.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(g.uModel,!1,this.modelMatrix),e.uniformMatrix3fv(g.uNormalMatrix,!1,m.normalMatrix),g.uUvTransform&&e.uniform4f(g.uUvTransform,x,D,S,C),g.uViewportSize&&e.uniform2f(g.uViewportSize,Math.max(1,s),Math.max(1,u)),g.uViewport&&e.uniform4f(g.uViewport,r,i,Math.max(1,s),Math.max(1,u)),this.xrDepthState.enabled&&this.xrDepthState.texture?(e.activeTexture(33989),e.bindTexture(3553,this.xrDepthState.texture),g.uXrDepthTex&&e.uniform1i(g.uXrDepthTex,5),g.uXrDepthEnabled&&e.uniform1i(g.uXrDepthEnabled,1),g.uXrDepthFormat&&e.uniform1i(g.uXrDepthFormat,this.xrDepthState.format||0),g.uXrRawValueToMeters&&e.uniform1f(g.uXrRawValueToMeters,this.xrDepthState.rawValueToMeters),g.uXrDepthUVTransform&&e.uniformMatrix4fv(g.uXrDepthUVTransform,!1,this.xrDepthState.uvTransform)):g.uXrDepthEnabled&&e.uniform1i(g.uXrDepthEnabled,0),this.environmentTexture?(e.activeTexture(33988),e.bindTexture(3553,this.environmentTexture),e.uniform1i(g.uEnvironmentMap,4),e.uniform1i(g.uHasEnvironmentMap,1)):e.uniform1i(g.uHasEnvironmentMap,0),this.bindLights(g);for(let X of G)X.onBeforeDrawPrimitive?.(e,k,y,m,this.worldMatrices||[],this.gltf);e.uniform4fv(g.uBaseColor,y.baseColor),e.uniform1f(g.uMetallic,y.metallic),e.uniform1f(g.uRoughness,y.roughness),g.uClearcoat&&e.uniform2f(g.uClearcoat,y.clearcoat??0,y.clearcoatRoughness??.04),y.texture?(e.activeTexture(33984),e.bindTexture(3553,y.texture),e.uniform1i(g.uBaseColorTexture,0),e.uniform1i(g.uHasTexture,1)):e.uniform1i(g.uHasTexture,0),y.metallicRoughnessTexture?(e.activeTexture(33985),e.bindTexture(3553,y.metallicRoughnessTexture),e.uniform1i(g.uMetallicRoughnessTexture,1),e.uniform1i(g.uHasMetallicRoughnessTexture,1)):e.uniform1i(g.uHasMetallicRoughnessTexture,0),y.normalTexture?(e.activeTexture(33986),e.bindTexture(3553,y.normalTexture),e.uniform1i(g.uNormalTexture,2),e.uniform1i(g.uHasNormalTexture,1),e.uniform1f(g.uNormalScale,y.normalScale)):e.uniform1i(g.uHasNormalTexture,0),y.occlusionTexture?(e.activeTexture(33987),e.bindTexture(3553,y.occlusionTexture),e.uniform1i(g.uOcclusionTexture,3),e.uniform1i(g.uHasOcclusionTexture,1),e.uniform1f(g.uOcclusionStrength,y.occlusionStrength)):e.uniform1i(g.uHasOcclusionTexture,0),e.bindVertexArray(y.vao),e.drawElements(4,y.indexCount,y.indexType,0)}}};if(E(!1),R){for(let v of G)v.onBeforeTransmissivePass?.(e,this);E(!0)}for(let v of G)v.onAfterRender?.(e,this,l)}disposeMeshListGpuResources(t){let e=this.gl;for(let r of t)for(let i of r.primitives){if(i.vao&&e.deleteVertexArray(i.vao),i.buffers)for(let s of i.buffers)e.deleteBuffer(s);i.texture&&e.deleteTexture(i.texture),i.metallicRoughnessTexture&&e.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&e.deleteTexture(i.normalTexture),i.occlusionTexture&&e.deleteTexture(i.occlusionTexture),i.customProgram&&e.deleteProgram(i.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let t=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let e of G)e.onDestroy?.(t,this);this.environmentTexture&&(t.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&t.deleteProgram(this.renderProg),this.pickProg&&t.deleteProgram(this.pickProg),this.pickFbo&&t.deleteFramebuffer(this.pickFbo),this.pickTexture&&t.deleteTexture(this.pickTexture),this.pickDepth&&t.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};j.registerPlugin=Re,j.getRegisteredPlugins=Ee;var Ge='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',_e="Security Error: client-side scripts require allow-client-scripts opt-in.";var Je=typeof HTMLElement<"u"?HTMLElement:class{};typeof CustomEvent>"u"&&typeof Event<"u"&&(globalThis.CustomEvent=class extends Event{constructor(n,t){super(n,t),this.detail=t?.detail??null}});var _=class _ extends Je{constructor(){super(...arguments);this.viewer=null;this.canvas=null;this.posterEl=null;this.arButton=null;this.currentModel=null;this.activeXRSession=null;this.toastTimer=null;this.currentModelLimits=void 0;this.isModelLoaded=!1;this.scriptHandle=null;this.resizeObserver=null;this.mutationObserver=null}static get arProvider(){return H().arProvider}static set arProvider(e){H().arProvider=e}static get scriptRunner(){return H().scriptRunner}static set scriptRunner(e){H().scriptRunner=e}static get sandboxEngineSrc(){return H().sandboxEngineSrc??null}static set sandboxEngineSrc(e){H().sandboxEngineSrc=e}static get sandboxIframeSrc(){return H().sandboxIframeSrc??null}static set sandboxIframeSrc(e){H().sandboxIframeSrc=e}static get allowClientScripts(){return!!H().allowClientScripts}static set allowClientScripts(e){H().allowClientScripts=e}static registerScriptRunner(e){_.scriptRunner=e}static registerDecoder(e,r){j.registerDecoder(e,r)}static getDecoder(e){return j.getDecoder(e)}static registerAR(e){typeof e=="function"?_.arProvider={activateAR:e}:_.arProvider=e,typeof document<"u"&&document.querySelectorAll("three-live").forEach(i=>{i instanceof _&&i.updateARButtonVisibility()})}static isARSupported(){return!!_.arProvider}getLoadedModel(){return this.currentModel}connectedCallback(){if(typeof document>"u")return;(!this.style.display||this.style.display==="inline")&&(this.style.display="block"),getComputedStyle(this).position==="static"&&(this.style.position="relative"),this.style.overflow="hidden",this.setupDOM(),this.initViewer(),this.setupResizeObserver();let e=this.getAttribute("src"),r=this.getAttribute("script-src");if(e)this.loadModelFromSrc(e).catch(()=>{});else if(r)this.loadScriptFromSrc(r).catch(()=>{});else{let i=this.querySelector('script[type="text/three"], script[type="text/three-live"]');i&&i.textContent&&this.executeScript(i.textContent).catch(()=>{})}for(let i of j.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let e of j.getRegisteredPlugins())e.onElementDisconnected?.(this);this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.activeXRSession&&(this.activeXRSession.stop?.().catch?.(()=>{}),this.activeXRSession=null),this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),this.viewer&&(this.viewer.destroy(),this.viewer=null),this.isModelLoaded=!1}attributeChangedCallback(e,r,i){if(r!==i){switch(e){case"src":i&&this.loadModelFromSrc(i).catch(()=>{});break;case"camera-target":this.applyCameraTarget(i);break;case"min-camera-orbit":case"max-camera-orbit":this.applyOrbitLimits();break;case"field-of-view":this.applyFieldOfView(i);break;case"script-src":i&&this.loadScriptFromSrc(i).catch(()=>{});break;case"sandbox":case"allow-client-scripts":case"ios-src":break;case"poster":this.updatePoster(i);break;case"camera-orbit":this.applyCameraOrbit(i);break;case"selected-mesh":this.viewer&&i!==null&&this.viewer.setSelectedMesh(i);break;case"exposure":if(this.viewer&&i!==null){let s=parseFloat(i);isNaN(s)||this.viewer.setExposure(s)}break;case"shadow-intensity":case"shadow-softness":this.viewer&&this.viewer.setShadow(this.shadowIntensity,this.shadowSoftness);break;case"tone-mapping":this.viewer&&i&&this.viewer.setToneMapping(i);break;case"environment-image":this.viewer&&this.viewer.setEnvironmentImage(i).catch(()=>{});break;case"skybox-image":this.viewer&&this.viewer.setSkyboxImage?.(i)?.catch?.(()=>{});break;case"camera-controls":{let s=this.cameraControls;this.viewer&&this.viewer.setInteractive?.(s),this.canvas&&(this.canvas.style.touchAction=s?"none":"auto");break}case"autoplay":this.viewer&&this.viewer.setAutoplay(i!==null&&i!=="false");break;case"animation-name":this.viewer&&i!==null&&this.viewer.setAnimationName(i);break;case"auto-rotate":this.viewer&&this.viewer.setAutoRotate(i!==null&&i!=="false");break;case"auto-rotate-delay":this.viewer&&this.viewer.setAutoRotateDelay(this.autoRotateDelay);break;case"rotation-per-second":this.viewer&&this.viewer.setAutoRotateSpeed(this.parseRotationPerSecond(i));break;case"ar":this.updateARButtonVisibility();break}for(let s of j.getRegisteredPlugins())s.onAttributeChanged?.(this,e,r,i)}}getAttr(e){return this.getAttribute(e)}setAttr(e,r){r!==null?this.setAttribute(e,r):this.removeAttribute(e)}getBoolAttr(e){return this.hasAttribute(e)&&this.getAttribute(e)!=="false"}setBoolAttr(e,r){r?this.setAttribute(e,""):this.removeAttribute(e)}getFloatAttr(e,r){let i=this.getAttribute(e);return i!==null?parseFloat(i):r}get src(){return this.getAttr("src")}set src(e){this.setAttr("src",e)}get cameraControls(){return this.getBoolAttr("camera-controls")}set cameraControls(e){this.setBoolAttr("camera-controls",e)}get cameraOrbit(){return this.getAttr("camera-orbit")}set cameraOrbit(e){this.setAttr("camera-orbit",e)}get cameraTarget(){return this.getAttr("camera-target")}set cameraTarget(e){this.setAttr("camera-target",e)}get minCameraOrbit(){return this.getAttr("min-camera-orbit")}set minCameraOrbit(e){this.setAttr("min-camera-orbit",e)}get maxCameraOrbit(){return this.getAttr("max-camera-orbit")}set maxCameraOrbit(e){this.setAttr("max-camera-orbit",e)}get fieldOfView(){return this.getAttr("field-of-view")}set fieldOfView(e){this.setAttr("field-of-view",e)}get iosSrc(){return this.getAttr("ios-src")}set iosSrc(e){this.setAttr("ios-src",e)}get scriptSrc(){return this.getAttr("script-src")}set scriptSrc(e){this.setAttr("script-src",e)}get sandbox(){return this.getAttribute("sandbox")||(H().sandboxIframeSrc?"iframe":"worker")}set sandbox(e){this.setAttribute("sandbox",e)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||_.allowClientScripts}set allowClientScripts(e){this.setBoolAttr("allow-client-scripts",e)}get poster(){return this.getAttr("poster")}set poster(e){this.setAttr("poster",e)}get selectedMesh(){return this.getAttr("selected-mesh")}set selectedMesh(e){this.setAttr("selected-mesh",e)}get exposure(){return this.getFloatAttr("exposure",1)}set exposure(e){this.setAttribute("exposure",String(e))}get autoRotate(){return this.getBoolAttr("auto-rotate")}set autoRotate(e){this.setBoolAttr("auto-rotate",e)}get autoRotateDelay(){return this.getFloatAttr("auto-rotate-delay",3e3)}set autoRotateDelay(e){this.setAttribute("auto-rotate-delay",String(e))}get rotationPerSecond(){return this.getAttr("rotation-per-second")||"30deg"}set rotationPerSecond(e){this.setAttr("rotation-per-second",e)}get turntableRotation(){return this.viewer?this.viewer.turntableRotation:0}get ar(){return this.hasAttribute("ar")}set ar(e){this.setBoolAttr("ar",e)}get arScale(){return this.getAttribute("ar-scale")||"auto"}set arScale(e){this.setAttribute("ar-scale",e)}get arPlacement(){return this.getAttribute("ar-placement")||"floor"}set arPlacement(e){this.setAttribute("ar-placement",e)}get canActivateAR(){return _.isARSupported()}get shadowIntensity(){return this.getFloatAttr("shadow-intensity",0)}set shadowIntensity(e){this.setAttribute("shadow-intensity",String(e))}get shadowSoftness(){return this.getFloatAttr("shadow-softness",.5)}set shadowSoftness(e){this.setAttribute("shadow-softness",String(e))}get toneMapping(){return this.getAttribute("tone-mapping")||"neutral"}set toneMapping(e){this.setAttribute("tone-mapping",e)}get environmentImage(){return this.getAttr("environment-image")}set environmentImage(e){this.setAttr("environment-image",e)}get skyboxImage(){return this.getAttr("skybox-image")}set skyboxImage(e){this.setAttr("skybox-image",e)}get autoplay(){return this.getBoolAttr("autoplay")}set autoplay(e){this.setBoolAttr("autoplay",e)}get animationName(){return this.getAttr("animation-name")}set animationName(e){this.setAttr("animation-name",e)}get availableAnimations(){return this.viewer?this.viewer.getAvailableAnimations():[]}get model(){let e=this.viewer?this.viewer.getModelMaterials():[];return{materials:e,getMaterialByName(r){return e.find(i=>i.name===r)??null}}}play(){this.viewer&&this.viewer.playAnimation(this.animationName||void 0)}pause(){this.viewer&&this.viewer.pauseAnimation()}resetCamera(){this.viewer?.resetCamera()}resetTurntableRotation(e=0){this.viewer?.resetTurntableRotation(e)}setCamera(e,r,i,s){this.viewer&&this.viewer.setCamera(e,r,i,s)}getCameraOrbit(){return this.viewer?this.viewer.getCameraOrbit():{theta:0,phi:0,radius:3,toString(){return"0rad 0rad 3m"}}}getCameraTarget(){return this.viewer?this.viewer.getCameraTarget():{x:0,y:0,z:0,toString(){return"0m 0m 0m"}}}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(e,r){return this.viewer&&this.viewer.render?.(),this.canvas?this.canvas.toDataURL(e,r):""}toBlob(e){return this.viewer&&this.viewer.render?.(),new Promise((r,i)=>{if(!this.canvas||typeof this.canvas.toBlob!="function"){i(new Error("Canvas toBlob is not supported in this environment."));return}this.canvas.toBlob(s=>{s?r(s):i(new Error("Failed to capture canvas blob."))},e?.mimeType,e?.qualityArgument)})}positionAndNormalFromPoint(e,r){if(!this.viewer)return null;let i=this.viewer.raycastFromScreenPoint(e,r);if(!i)return null;let[s,u,l]=i.hitPoint||i.point,[o,c,a]=i.normal;return{position:{x:s,y:u,z:l,toString(){return`${s}m ${u}m ${l}m`}},normal:{x:o,y:c,z:a,toString(){return`${o}m ${c}m ${a}m`}}}}async loadModel(e){return this.loadModelWithLimits(e)}async loadModelWithLimits(e,r){if(!this.viewer){this.currentModel=e,this.currentModelLimits=r;return}try{let i;if(typeof e=="string"){this.isModelLoaded=!1,this.viewer?.clearScene?.();let l=await fetch(e);if(!l.ok)throw new Error(`Failed to load 3D model from "${e}": HTTP ${l.status}`);i=await l.arrayBuffer()}else i=e;let s=ge(i);this.viewer.loadGLBData(s,r),this.currentModel=s,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.updateHotspots();let u=this.getAttribute("selected-mesh");u&&this.viewer.setSelectedMesh(u),this.dispatchEvent(new CustomEvent("load",{bubbles:!0,composed:!0,detail:{model:s}}))}catch(i){throw this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),i}}showToast(e,r=4500){if(typeof document>"u")return;let i=this.querySelector(".three-live-toast");i||(i=document.createElement("div"),i.className="three-live-toast",i.style.cssText="position:absolute;bottom:70px;left:50%;transform:translateX(-50%) translateY(10px);z-index:10;padding:10px 16px;background-color:rgba(15,23,42,0.94);color:#f8fafc;border:1px solid rgba(56,189,248,0.45);border-radius:14px;font:500 13px/1.35 system-ui,-apple-system,sans-serif;box-shadow:0 10px 25px rgba(0,0,0,0.45);backdrop-filter:blur(12px);pointer-events:none;opacity:0;transition:opacity .25s ease,transform .25s ease;max-width:88%;text-align:center;white-space:normal;word-break:break-word",this.appendChild(i)),i.textContent=e,this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),typeof requestAnimationFrame<"u"?requestAnimationFrame(()=>{i&&(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)")}):(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)"),this.toastTimer=setTimeout(()=>{i&&(i.style.opacity="0",i.style.transform="translateX(-50%) translateY(10px)"),this.toastTimer=null},r)}async activateAR(){if(this.activeXRSession&&typeof this.activeXRSession.isSessionActive=="function"&&this.activeXRSession.isSessionActive()&&(await this.activeXRSession.stop().catch(()=>{}),this.activeXRSession=null),!this.currentModel){let i=new Error("No 3D model is loaded in <three-live>.");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}if(!_.arProvider){let i=new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR().");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}let e=this.getAttribute("ios-src"),r=(this.getAttribute("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"session-started"}}));let i=await _.arProvider.activateAR({model:e||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,element:this,preferredModes:r.length>0?r:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"not-presenting"}}))},onError:s=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:s}})),this.showToast(`AR error: ${s.message}`,6e3)}}});if(i.success)i.session&&(this.activeXRSession=i.session),i.mode==="quick-look"?this.showToast("Opening Apple AR Quick Look..."):i.mode==="scene-viewer"?this.showToast("Opening Google Scene Viewer..."):i.mode==="webxr"&&this.showToast("WebXR AR session started.");else{let s=typeof navigator<"u"&&navigator.userAgent||"",u=/Macintosh/i.test(s)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1),l=/Android|iPhone|iPad|iPod/i.test(s);if(u&&!l&&typeof document<"u"&&this.currentModel&&_.arProvider.createUSDZBlob)try{let o=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:_.arProvider.createUSDZBlob(this.currentModel),c=URL.createObjectURL(o),a=document.createElement("a");a.href=c,a.download="three_live_model.usdz",document.body.appendChild(a),a.click(),document.body.removeChild(a),setTimeout(()=>URL.revokeObjectURL(c),3e3),this.showToast("Downloaded USDZ preview for macOS Quick Look.",5e3)}catch{this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3)}else this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3);i.error&&this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i.error}}))}return i}catch(i){throw this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(`AR error: ${i.message||String(i)}`,6e3),i}}setupDOM(){let e=this.querySelector("canvas");e||(e=document.createElement("canvas"),e.style.width="100%",e.style.height="100%",e.style.display="block",e.style.touchAction=this.cameraControls?"none":"auto",e.style.outline="none",this.appendChild(e)),this.canvas=e;let r=this.getAttribute("poster");r&&this.updatePoster(r),this.createARButton(),typeof MutationObserver<"u"&&!this.mutationObserver&&(this.mutationObserver=new MutationObserver(()=>{this.updateARButtonVisibility()}),this.mutationObserver.observe(this,{childList:!0}))}initViewer(){if(!this.canvas)return;let e=this.autoRotate,r=this.exposure,i=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),s=this.parseOrbitLimit(this.getAttribute("max-camera-orbit")),u=this.parseCameraTarget(this.getAttribute("camera-target")),l=this.parseFieldOfView(this.getAttribute("field-of-view"));this.viewer=new j(this,this.canvas,{autoRotate:e,autoRotateDelay:this.autoRotateDelay,autoRotateSpeed:this.parseRotationPerSecond(this.getAttribute("rotation-per-second")),exposure:r,shadowIntensity:this.shadowIntensity,shadowSoftness:this.shadowSoftness,toneMapping:this.toneMapping,environmentImage:this.environmentImage,autoplay:this.autoplay,animationName:this.animationName||void 0,fieldOfView:l,cameraTarget:u,minCameraOrbit:i,maxCameraOrbit:s,onMeshClick:c=>{this.dispatchEvent(new CustomEvent("meshclick",{bubbles:!0,composed:!0,detail:c}))},onCameraChange:c=>{this.updateHotspots();for(let a of j.getRegisteredPlugins())a.onCameraChange?.(this.viewer,this);this.dispatchEvent(new CustomEvent("camera-change",{bubbles:!0,composed:!0,detail:c}))}}),this.viewer.setInteractive(this.cameraControls),this.skyboxImage&&this.viewer.setSkyboxImage(this.skyboxImage).catch(()=>{});let o=this.getAttribute("camera-orbit");o&&this.applyCameraOrbit(o),this.currentModel&&this.loadModelWithLimits(this.currentModel,this.currentModelLimits)}setupResizeObserver(){typeof ResizeObserver>"u"||(this.resizeObserver=new ResizeObserver(()=>{this.viewer&&(this.viewer.resize(),this.viewer.render(),this.updateHotspots())}),this.resizeObserver.observe(this))}updatePoster(e){if(!(typeof document>"u")){if(!e){this.posterEl&&(this.posterEl.remove(),this.posterEl=null);return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.setAttribute("alt","3D Scene Preview"),this.posterEl.style.position="absolute",this.posterEl.style.inset="0",this.posterEl.style.width="100%",this.posterEl.style.height="100%",this.posterEl.style.objectFit="cover",this.posterEl.style.transition="opacity 0.35s ease-out",this.posterEl.style.pointerEvents="none",this.posterEl.style.zIndex="1",this.appendChild(this.posterEl)),this.posterEl.src=e,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.posterEl&&(this.posterEl.style.opacity="0",setTimeout(()=>{this.isModelLoaded&&this.posterEl&&(this.posterEl.remove(),this.posterEl=null)},400))}createARButton(){if(!(typeof document>"u")){if(!this.arButton){let e=document.createElement("button");e.setAttribute("type","button"),e.setAttribute("aria-label","View in Augmented Reality"),e.className="three-live-ar-button",e.setAttribute("part","default-ar-button");let r="http://www.w3.org/2000/svg";if(typeof document.createElementNS=="function"){let s=document.createElementNS(r,"svg");s.setAttribute("width","20"),s.setAttribute("height","20"),s.setAttribute("viewBox","0 0 24 24"),s.setAttribute("fill","none"),s.setAttribute("stroke","currentColor"),s.setAttribute("stroke-width","2"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),s.style.marginRight="6px";let u=document.createElementNS(r,"path");u.setAttribute("d","M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z");let l=document.createElementNS(r,"polyline");l.setAttribute("points","3.27 6.96 12 12.01 20.73 6.96");let o=document.createElementNS(r,"line");o.setAttribute("x1","12"),o.setAttribute("y1","22.08"),o.setAttribute("x2","12"),o.setAttribute("y2","12"),s.appendChild(u),s.appendChild(l),s.appendChild(o),e.appendChild(s)}let i=document.createElement("span");i.textContent="View in AR",e.appendChild(i),e.style.cssText="position:absolute;right:16px;bottom:16px;z-index:2;align-items:center;justify-content:center;padding:8px 16px;background-color:rgba(15,23,42,0.85);color:#fff;border:1px solid rgba(255,255,255,0.15);border-radius:9999px;font:600 13px system-ui,-apple-system,sans-serif;cursor:pointer;backdrop-filter:blur(8px);box-shadow:0 4px 12px rgba(0,0,0,0.25);transition:transform .15s ease,background-color .15s ease;display:none",e.addEventListener("mouseenter",()=>{e.style.backgroundColor="rgba(30, 41, 59, 0.95)",e.style.transform="scale(1.04)"}),e.addEventListener("mouseleave",()=>{e.style.backgroundColor="rgba(15, 23, 42, 0.85)",e.style.transform="scale(1)"}),e.addEventListener("click",s=>{s.stopPropagation(),this.activateAR()}),this.arButton=e,this.appendChild(e)}this.updateARButtonVisibility()}}updateARButtonVisibility(){let e=this.hasAttribute("ar")&&!!_.arProvider,r=typeof this.querySelector=="function"?this.querySelector('[slot="ar-button"]'):null;r?(this.arButton&&(this.arButton.style.display="none"),r.__tlARBound||(r.__tlARBound=!0,r.addEventListener("click",i=>{i.stopPropagation(),this.activateAR()})),r.dataset.tlOrigDisplay===void 0&&(r.dataset.tlOrigDisplay=r.style.display==="none"?"":r.style.display),r.style.display=e?r.dataset.tlOrigDisplay||"":"none"):this.arButton&&(this.arButton.style.display=e?"flex":"none")}applyCameraOrbit(e){if(!(!e||!this.viewer))try{let r=JSON.parse(e);this.viewer.setInitialCamera(r.theta,r.phi,r.distance,r.zoom)}catch{let r=e.trim().split(/\s+/);if(r.length>=2){let i=o=>o.endsWith("rad")?parseFloat(o)*180/Math.PI:parseFloat(o.replace(/deg$/,"")),s=r[0]==="auto"?void 0:i(r[0]),u=r[1]==="auto"?void 0:i(r[1]),l;r.length>=3&&r[2]!=="auto"&&(l=parseFloat(r[2].replace(/m$/,""))),(s!==void 0&&!isNaN(s)||u!==void 0&&!isNaN(u))&&this.viewer.setInitialCamera(s!==void 0&&!isNaN(s)?s:void 0,u!==void 0&&!isNaN(u)?u:void 0,l!==void 0&&!isNaN(l)?l:void 0)}}}parseOrbitLimit(e){if(!e)return{};let r=e.trim().split(/\s+/),i={};if(r.length>0&&r[0]!=="auto"){let s=r[0].endsWith("rad")?parseFloat(r[0])*180/Math.PI:parseFloat(r[0].replace(/deg$/,""));isNaN(s)||(i.theta=s)}if(r.length>1&&r[1]!=="auto"){let s=r[1].endsWith("rad")?parseFloat(r[1])*180/Math.PI:parseFloat(r[1].replace(/deg$/,""));isNaN(s)||(i.phi=s)}if(r.length>2&&r[2]!=="auto"){let s=parseFloat(r[2].replace(/m$/,""));isNaN(s)||(i.distance=s)}return i}applyOrbitLimits(){if(!this.viewer)return;let e=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),r=this.parseOrbitLimit(this.getAttribute("max-camera-orbit"));this.viewer.setOrbitLimits({minTheta:e.theta,maxTheta:r.theta,minPhi:e.phi,maxPhi:r.phi,minDistance:e.distance,maxDistance:r.distance})}parseCameraTarget(e){if(!e)return;let r=e.trim().split(/\s+/).map(i=>parseFloat(i.replace(/m$/,"")));return r.length>=3&&!r.some(isNaN)?[r[0],r[1],r[2]]:void 0}parseFieldOfView(e){if(!e)return;let r=e.endsWith("rad")?parseFloat(e)*180/Math.PI:parseFloat(e.replace(/deg$/,""));return isNaN(r)?void 0:r}parseRotationPerSecond(e){if(!e)return Math.PI/6;let r=e.trim(),i=parseFloat(r);return isNaN(i)?Math.PI/6:r.endsWith("rad")?i:r.endsWith("%")?i/100*Math.PI*2:i*Math.PI/180}applyCameraTarget(e){let r=this.parseCameraTarget(e);this.viewer&&r&&this.viewer.setTarget(r[0],r[1],r[2])}applyFieldOfView(e){let r=this.parseFieldOfView(e);this.viewer&&r!==void 0&&this.viewer.setFieldOfView(r)}updateHotspot(e){let r=this.querySelector(`[slot="${e.name}"]`);r&&(e.position!==void 0&&r.setAttribute("data-position",e.position),e.normal!==void 0&&r.setAttribute("data-normal",e.normal)),this.updateHotspots()}updateHotspots(){for(let e of j.getRegisteredPlugins())if(e.updateHotspotsForElement){e.updateHotspotsForElement(this,this.viewer);return}}async loadModelFromSrc(e){await this.loadModel(e)}runWithScriptRunner(e){let r=_.scriptRunner;if(!r){let i=new Error('Procedural script execution requires "three-live/full" or ThreeLiveElement.registerScriptRunner().');return this.showToast(i.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),Promise.reject(i)}return this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.isModelLoaded=!1,this.viewer?.clearScene?.(),new Promise((i,s)=>{let u=!1;e(r,{onModelReady:o=>{this.loadModelWithLimits(o,Ue).then(()=>{u||(u=!0,i(o))},c=>{let a=c instanceof Error?c.message:String(c);this.showToast(a),u||(u=!0,s(c))})},onUpdateTransforms:o=>this.viewer?.updateMeshTransforms(o),onError:o=>{this.showToast(o.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:o}})),u||(u=!0,s(o))},onToast:o=>this.showToast(o)}).then(o=>{o&&(this.scriptHandle=o)},o=>{o instanceof Error&&o.message&&this.showToast(o.message),u||(u=!0,s(o))})})}loadScriptFromSrc(e){return this.runWithScriptRunner((r,i)=>{if(typeof r.executeUrl!="function"){let s=new Error("Registered ScriptRunner does not support executeUrl() for server-generated scripts.");return i.onError?.(s),Promise.reject(s)}return r.executeUrl(e,this.sandbox,i)})}executeScript(e){if(!_.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(Ge);return this.showToast(_e),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:r}})),Promise.reject(r)}return this.runWithScriptRunner((r,i)=>r.execute(e,this.sandbox,i,{allowClientScripts:!0}))}};_.observedAttributes=["src","ios-src","script-src","sandbox","allow-client-scripts","poster","camera-controls","camera-orbit","camera-target","min-camera-orbit","max-camera-orbit","field-of-view","selected-mesh","ar","ar-modes","ar-scale","ar-placement","exposure","shadow-intensity","shadow-softness","tone-mapping","environment-image","skybox-image","autoplay","animation-name","auto-rotate","auto-rotate-delay","rotation-per-second"],_.registerPlugin=j.registerPlugin,_.getRegisteredPlugins=j.getRegisteredPlugins;var we=_;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",we);export{we as ThreeLiveElement};
|
|
@@ -0,0 +1,42 @@
|
|
|
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 ve=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var ft=(e,t)=>{for(var n in t)ve(e,n,{get:t[n],enumerable:!0})},mt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of lt(t))!ut.call(e,o)&&o!==n&&ve(e,o,{get:()=>t[o],enumerable:!(r=ct(t,o))||r.enumerable});return e};var dt=e=>mt(ve({},"__esModule",{value:!0}),e);var Pt={};ft(Pt,{InteractivityVM:()=>re,contactShadowPlugin:()=>ke,environmentMapPlugin:()=>Se,getEnvironmentSH:()=>je,getInteractivityVM:()=>be,hotspotPlugin:()=>Ee,interactivityPlugin:()=>Le,materialsPlugin:()=>Ve,parseSafeGltfPointer:()=>ne,registerMaterialShader:()=>rt,sendInteractivityEvent:()=>Pe,setEnvironmentSH:()=>le,webxrPlugin:()=>De});module.exports=dt(Pt);var ce="__THREE_LIVE_REGISTRY__";function Ae(){let e=typeof globalThis<"u"?globalThis:{};if(!e[ce]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,ce,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[ce]=t}}return e[ce]}var Ct=Ae().plugins;function Q(e){let t=Ae().plugins;t.some(n=>n.name===e.name)||t.push(e)}function Be(){return Ae().plugins}function Oe(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function pt(e,t,n){let r=t[0],o=t[1],s=t[2],x=t[3],p=t[4],f=t[5],d=t[6],m=t[7],M=t[8],S=t[9],F=t[10],v=t[11],y=t[12],R=t[13],V=t[14],N=t[15],E=n[0],w=n[1],I=n[2],P=n[3];return e[0]=E*r+w*p+I*M+P*y,e[1]=E*o+w*f+I*S+P*R,e[2]=E*s+w*d+I*F+P*V,e[3]=E*x+w*m+I*v+P*N,E=n[4],w=n[5],I=n[6],P=n[7],e[4]=E*r+w*p+I*M+P*y,e[5]=E*o+w*f+I*S+P*R,e[6]=E*s+w*d+I*F+P*V,e[7]=E*x+w*m+I*v+P*N,E=n[8],w=n[9],I=n[10],P=n[11],e[8]=E*r+w*p+I*M+P*y,e[9]=E*o+w*f+I*S+P*R,e[10]=E*s+w*d+I*F+P*V,e[11]=E*x+w*m+I*v+P*N,E=n[12],w=n[13],I=n[14],P=n[15],e[12]=E*r+w*p+I*M+P*y,e[13]=E*o+w*f+I*S+P*R,e[14]=E*s+w*d+I*F+P*V,e[15]=E*x+w*m+I*v+P*N,e}function bt(e,t,n,r){let o=t[0],s=t[1],x=t[2],p=t[3],f=o+o,d=s+s,m=x+x,M=o*f,S=o*d,F=o*m,v=s*d,y=s*m,R=x*m,V=p*f,N=p*d,E=p*m,w=r[0],I=r[1],P=r[2];return e[0]=(1-(v+R))*w,e[1]=(S+E)*w,e[2]=(F-N)*w,e[3]=0,e[4]=(S-E)*I,e[5]=(1-(M+R))*I,e[6]=(y+V)*I,e[7]=0,e[8]=(F+N)*P,e[9]=(y-V)*P,e[10]=(1-(M+v))*P,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Me(e,t){let n=t[0],r=t[1],o=t[2],s=t[4],x=t[5],p=t[6],f=t[8],d=t[9],m=t[10],M=m*x-p*d,S=-m*s+p*f,F=d*s-x*f,v=n*M+r*S+o*F;return v&&(v=1/v,e[0]=M*v,e[1]=(-m*r+o*d)*v,e[2]=(p*r-o*x)*v,e[3]=S*v,e[4]=(m*n-o*f)*v,e[5]=(-p*n+o*s)*v,e[6]=F*v,e[7]=(-d*n+r*f)*v,e[8]=(x*n-r*s)*v),e}function We(e,t){let n=t[0],r=t[1],o=t[2],s=t[3],x=t[4],p=t[5],f=t[6],d=t[7],m=t[8],M=t[9],S=t[10],F=t[11],v=t[12],y=t[13],R=t[14],V=t[15],N=n*p-r*x,E=n*f-o*x,w=n*d-s*x,I=r*f-o*p,P=r*d-s*p,O=o*d-s*f,H=m*y-M*v,B=m*R-S*v,k=m*V-F*v,Y=M*R-S*y,q=M*V-F*y,Z=S*V-F*R,z=N*Z-E*q+w*Y+I*k-P*B+O*H;return z?(z=1/z,e[0]=(p*Z-f*q+d*Y)*z,e[1]=(o*q-r*Z-s*Y)*z,e[2]=(y*O-R*P+V*I)*z,e[3]=(S*P-M*O-F*I)*z,e[4]=(f*k-x*Z-d*B)*z,e[5]=(n*Z-o*k+s*B)*z,e[6]=(R*w-v*O-V*E)*z,e[7]=(m*O-S*w+F*E)*z,e[8]=(x*q-p*k+d*H)*z,e[9]=(r*k-n*q-s*H)*z,e[10]=(v*P-y*w+V*N)*z,e[11]=(M*w-m*P-F*N)*z,e[12]=(p*B-x*Y-f*H)*z,e[13]=(n*Y-r*B+o*H)*z,e[14]=(y*E-v*I-R*N)*z,e[15]=(m*I-M*E+S*N)*z,e):null}function Te(e,t){let n=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let m=0;m<n;m++)r.push(Oe());if(n===0)return r;let o=new Set;for(let m of e.nodes)if(Array.isArray(m.children))for(let M of m.children)o.add(M);let s=new Set,x=128,p=(m,M,S=0)=>{if(S>x||m<0||m>=n||s.has(m))return;s.add(m);let F=e.nodes[m];if(!F)return;let v=Oe();if(t&&t[m])v.set(t[m]);else if(F.matrix&&F.matrix.length===16)v.set(F.matrix);else{let R=F.translation||[0,0,0],V=F.rotation||[0,0,0,1],N=F.scale||[1,1,1];bt(v,V,R,N)}let y=r[m];if(M?pt(y,M,v):y.set(v),Array.isArray(F.children))for(let R of F.children)typeof R=="number"&&p(R,y,S+1)},f=[],d=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(d&&Array.isArray(d.nodes))f.push(...d.nodes);else for(let m=0;m<n;m++)o.has(m)||f.push(m);for(let m of f)p(m,null);for(let m=0;m<n;m++)!o.has(m)&&!f.includes(m)&&p(m,null);return r}var Re=new WeakMap;function le(e,t){let n=t instanceof Float32Array?t:new Float32Array(t);Re.set(e,n)}function je(e){return Re.get(e)}async function yt(e,t){if(!t)return null;let n;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let s=await(await fetch(t)).blob();n=await createImageBitmap(s)}else if(typeof Image<"u")n=await new Promise((o,s)=>{let x=new Image;x.crossOrigin="anonymous",x.onload=()=>o(x),x.onerror=s,x.src=t});else return null;else n=t;let r=e.createTexture();return e.bindTexture(3553,r),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),r}var Ge=new WeakMap,Xe=new Float32Array(16);async function $e(e,t,n){let r=n?await yt(e.gl,n):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=r}var Se={name:"environment-map",setEnvironmentImage(e,t){return $e(e,"environmentTexture",t)},setSkyboxImage(e,t){return $e(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,n,r,o){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let s=Ge.get(t);if(!s){let M=(v,y)=>{let R=t.createShader(v);return t.shaderSource(R,y),t.compileShader(R),R},S=t.createProgram();t.attachShader(S,M(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(S,M(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(S);let F=typeof t.createVertexArray=="function"?t.createVertexArray():null;s={program:S,vao:F},Ge.set(t,s)}let x=We(Xe,n)||Xe;t.depthMask(!1),t.useProgram(s.program),s.vao&&t.bindVertexArray(s.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let p=t.getUniformLocation(s.program,"uSkyboxMap");p&&t.uniform1i(p,0);let f=t.getUniformLocation(s.program,"uInvVP");f&&t.uniformMatrix4fv(f,!1,x);let d=t.getUniformLocation(s.program,"uCameraPos");d&&t.uniform3f(d,r[0],r[1],r[2]);let m=t.getUniformLocation(s.program,"uExposure");m&&t.uniform1f(m,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,n,r){if(r.includes("evalSHIrradiance"))return null;let o=r.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 o=o.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:o}},onBeforeDrawPrimitive(e,t,n,r,o,s){let x=Re.get(e),p=e.getUniformLocation(t,"uHasSH");if(x&&x.length>=27){p&&e.uniform1i(p,1);let f=e.getUniformLocation(t,"uSH");f&&e.uniform3fv(f,x)}else p&&e.uniform1i(p,0)},onAttributeChanged(e,t,n,r){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,r):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,r)}};var we=new WeakMap;function Ie(e,t){let n=t||e.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let r=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let o=0;o<r.length;o++){let s=r[o],x=s.getAttribute("data-position");if(!x)continue;let p=x.trim().split(/\s+/).map(M=>parseFloat(M.replace(/m$/,"")));if(p.length<3||p.some(isNaN))continue;let f=s.getAttribute("data-normal"),d;if(f){let M=f.trim().split(/\s+/).map(S=>parseFloat(S));M.length>=3&&!M.some(isNaN)&&(d=[M[0],M[1],M[2]])}let m=n.projectPointToScreen([p[0],p[1],p[2]],d);s.style.position="absolute",s.style.left="0",s.style.top="0",s.style.transform=`translate(-50%, -50%) translate3d(${m.x}px, ${m.y}px, 0)`,s.style.zIndex="3",m.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 Ee={name:"hotspots",updateHotspotsForElement:Ie,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{Ie(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),we.set(e,t)},onCameraChange(e,t){t&&Ie(t,e)},onElementDisconnected(e){let t=we.get(e);t&&(t.disconnect(),we.delete(e))}};function ue(e,t,n,r){let o=typeof e=="number"&&Number.isFinite(e)?e:r;return Math.max(t,Math.min(n,o))}function ht(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function gt(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function qe(e){let t=gt(e);if(!t)return null;let n=t.target;return{target:ht(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:ue(t.radius,.01,50,.5),speed:ue(t.speed,-20,20,.5),height:ue(t.height,-10,10,0),phase:ue(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}function Ke(e,t,n,r){let o=t[0],s=t[1],x=t[2],p=t[3],f=n[0],d=n[1],m=n[2],M=n[3],S=o*f+s*d+x*m+p*M;if(S<0&&(f=-f,d=-d,m=-m,M=-M,S=-S),Math.abs(S)>=1)return e[0]=o,e[1]=s,e[2]=x,e[3]=p,e;let F=Math.acos(S),v=Math.sqrt(1-S*S);if(Math.abs(v)<.001)return e[0]=.5*(o+f),e[1]=.5*(s+d),e[2]=.5*(x+m),e[3]=.5*(p+M),e;let y=Math.sin((1-r)*F)/v,R=Math.sin(r*F)/v;return e[0]=o*y+f*R,e[1]=s*y+d*R,e[2]=x*y+m*R,e[3]=p*y+M*R,e}var Ye=1024,_e=256,fe=2048,xt=128,vt=64,At=16,Mt=1e4,Tt=8,K=new Set(["__proto__","constructor","prototype"]),Ze={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))},Qe={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},me={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},de=(e,t)=>e!==null&&typeof e=="object"&&!K.has(t)&&Object.prototype.hasOwnProperty.call(e,t),G=e=>Array.isArray(e)?[...e]:e,nt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&de(e,"value")?e.value:e,U=(e,t)=>de(e.configuration,t)?nt(e.configuration[t]):void 0,A=(e,t=0)=>{let n=Number(e);return Number.isFinite(n)?n:t},J=e=>Math.max(0,Math.min(1,e)),X=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function ne(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let n of e.slice(1).split("/")){let r=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!r||K.has(r)||K.has(n))return null;t.push(r)}return{segments:t}}var te=(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},Je=e=>{let t=A(e[0]),n=A(e[1]),r=A(e[2]),o=A(e[3],1),s=Math.hypot(t,n,r,o);return s>1e-8?[t/s,n/s,r/s,o/s]:[0,0,0,1]},et=(e,t,n,r)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*n;if(Array.isArray(e)&&Array.isArray(t)){if(r&&e.length===4&&t.length===4){let o=[0,0,0,1];return Ke(o,Je(e),Je(t),n),o}return e.slice(0,t.length).map((o,s)=>o+(t[s]-o)*n)}return n>=.5?t:e},Fe=(e,t,n)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((r,o)=>n(A(r),A(t[o]))):Array.isArray(e)?e.map(r=>n(A(r),A(t))):Array.isArray(t)?t.map(r=>n(A(e),A(r))):n(A(e),A(t)),Rt=(e,t)=>Array.isArray(e)?e.map(n=>t(A(n))):t(A(e)),tt=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,r)=>Math.abs(n-t[r])<=1e-6):e===t,re=class{constructor(t,n,r){let o=Array.isArray(r.nodes)?r.nodes:[];if(o.length>Ye)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${Ye})`);let s=Array.isArray(r.variables)?r.variables:[];if(s.length>_e)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${_e})`);let x=Array.isArray(r.declarations)?r.declarations:[],p=Array.isArray(r.events)?r.events:[],f=new Map,d=new Map,m=new Map,M=new Map,S=new Map,F=new Map,v=[],y=[],R=new Map,V=1,N=0,E=0,w=0,I=0,P=!1,O=!1,H=!1;s.forEach((l,u)=>{if(!l||typeof l!="object")return;let h=G(nt(l.value));f.set(u,h);let g=l.id??l.name;typeof g=="string"&&g&&!K.has(g)&&f.set(g,h)}),(n?.nodes||[]).forEach((l,u)=>{for(let h of l?.children||[])typeof h=="number"&&R.set(h,u)});let B=l=>l.op||typeof l.declaration=="number"&&x[l.declaration]?.op||"",k=(l,u,h)=>{if(K.has(u))return;let g=d.get(l);g||d.set(l,g=Object.create(null)),g[u]=h},Y=(l,u)=>{if(typeof l!="number"&&typeof l!="string"||typeof l=="string"&&K.has(l)||!f.has(l)&&f.size>=_e*2)return;let h=G(u);if(f.set(l,h),typeof l=="number"){let g=s[l]?.id??s[l]?.name;typeof g=="string"&&!K.has(g)&&f.set(g,h)}},q=l=>typeof l=="number"?p[l]?.id??String(l):typeof l=="string"?/^\d+$/.test(l)&&p[Number(l)]?.id?p[Number(l)].id:l:"",Z=(l,u)=>{for(let h=l,g=0;h!==void 0&&h>=0&&g<128;h=R.get(h),g++)if(h===u)return!0;return!1},z=l=>{for(let u=v.length-1;u>=0;u--)v[u].key===l&&v.splice(u,1)},Ue=l=>{z(l.key),v.length>=xt&&v.shift(),v.push(l)},he=l=>{let u=ne(l)?.segments;if(u){if(u[0]==="nodes"&&Array.isArray(n?.nodes)){let h=n.nodes[te(u[1],n.nodes.length)];if(!h)return;let g=u[2];if(g in me){let c=me[g],a=h[g]||c;return c.map((i,b)=>A(a[b],i))}if(g==="weights"){let c=Array.isArray(h.weights)?h.weights:[0],a=u.length===4?te(u[3],64):-2;return a===-2?c.map(i=>A(i)):a>=0?A(c[a]):void 0}if(g==="visible"||g==="extensions"&&u[3]==="KHR_node_visibility"&&u[4]==="visible")return h.extensions?.KHR_node_visibility?.visible??h.visible??!0}else if(u[0]==="materials"&&Array.isArray(n?.materials)){let h=n.materials[te(u[1],n.materials.length)];if(!h)return;let g=h.pbrMetallicRoughness||{};if(u[2]==="pbrMetallicRoughness"){if(u[3]==="baseColorFactor"){let c=g.baseColorFactor||[1,1,1,1];return[A(c[0],1),A(c[1],1),A(c[2],1),A(c[3],1)]}if(u[3]==="metallicFactor"||u[3]==="roughnessFactor")return A(g[u[3]],1)}if(u[2]==="emissiveFactor"){let c=h.emissiveFactor||[0,0,0];return[A(c[0]),A(c[1]),A(c[2])]}if(u[2]==="alphaCutoff")return A(h.alphaCutoff,.5)}}},ae=(l,u)=>{let h=ne(l)?.segments;if(!h)return!1;if(h[0]==="nodes"&&Array.isArray(n?.nodes)){let g=te(h[1],n.nodes.length),c=n.nodes[g];if(!c)return!1;let a=h[2];if(a in me&&Array.isArray(u)){let i=me[a];if(u.length<i.length)return!1;let b=i.map((C,D)=>A(u[D],C));if(a==="rotation"){let C=Math.hypot(...b);b=C>1e-8?b.map(D=>D/C):[0,0,0,1]}c[a]=b,delete c.matrix;let L=t?.initialNodeTransforms?.[g];return L&&(L[a[0]]=[...b]),P=!0,!0}if(a==="weights"){Array.isArray(c.weights)||(c.weights=[]);let i=(b,L)=>{for(let C of t?.meshes||[])if(C.nodeIndex===g)for(let D of C.primitives||[])D.pluginData?.morph?.weights&&(D.pluginData.morph.weights[b]=L)};if(h.length===4){let b=te(h[3],64);if(b<0)return!1;i(b,c.weights[b]=A(u))}else if(Array.isArray(u))c.weights=u.slice(0,64).map(b=>A(b)),c.weights.forEach((b,L)=>i(L,b));else return!1;return H=!0,!0}if(a==="visible"||a==="extensions"&&h[3]==="KHR_node_visibility"&&h[4]==="visible"){let i=X(u);return c.visible=i,(!c.extensions||typeof c.extensions!="object")&&(c.extensions={}),c.extensions.KHR_node_visibility={visible:i},O=!0,!0}}else if(h[0]==="materials"&&Array.isArray(n?.materials)){let g=te(h[1],n.materials.length),c=n.materials[g];if(!c)return!1;let a=c.pbrMetallicRoughness||(c.pbrMetallicRoughness={}),i=b=>{for(let L of t?.meshes||[])for(let C of L.primitives||[])(C.materialIndex??0)===g&&b(C)};if(h[2]==="pbrMetallicRoughness"){if(h[3]==="baseColorFactor"&&Array.isArray(u)&&u.length>=3){let b=[J(A(u[0],1)),J(A(u[1],1)),J(A(u[2],1)),u[3]!==void 0?J(A(u[3],1)):a.baseColorFactor?.[3]??1];return a.baseColorFactor=b,i(L=>L.baseColor=[...b]),H=!0}if(h[3]==="metallicFactor"||h[3]==="roughnessFactor"){let b=h[3]==="metallicFactor",L=J(A(u,b?0:.5));return a[h[3]]=L,i(C=>C[b?"metallic":"roughness"]=L),H=!0}}if(h[2]==="emissiveFactor"&&Array.isArray(u)&&u.length>=3)return c.emissiveFactor=[0,1,2].map(b=>Math.max(0,A(u[b]))),H=!0;if(h[2]==="alphaCutoff")return c.alphaCutoff=J(A(u,.5)),H=!0}return!1},ge=(l,u,h=new Set)=>{let g=U(u,"pointer");if(typeof g!="string"||!g.startsWith("/"))return null;let c=g.replace(/\{([a-zA-Z0-9_]+)\}/g,(a,i)=>{let b=Math.trunc(Number(ie(l,i,void 0,h)??U(u,i)));return Number.isSafeInteger(b)&&b>=0?String(b):"-1"});return ne(c)?c:null},ie=(l,u,h,g)=>{let c=o[l]?.values;if(!de(c,u))return h;let a=c[u];if(a==null)return h;if(typeof a!="object"||Array.isArray(a))return G(a);let i=a;return typeof i.node=="number"?it(i.node,i.socket||"value",g):de(i,"value")?G(i.value):h},it=(l,u,h)=>{if(l<0||l>=o.length||h.has(l)||h.size>128||++w>Mt)return;let g=o[l],c=B(g);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(c))return G(d.get(l)?.[u]);h.add(l);try{let a=(i,b=0)=>ie(l,i,b,h);if(c==="variable/get"){let i=U(g,"variable")??U(g,"id");return typeof i=="number"||typeof i=="string"?G(f.get(i)):void 0}if(c==="pointer/get"){let i=ge(l,g,h);return i?he(i):void 0}if(c.startsWith("math/")){let i=c.slice(5);if(i in Ze)return Rt(a("a"),Ze[i]);if(i in Qe){let b=/^(mul|div|rem|mod|pow)$/.test(i)?1:0;return Fe(a("a",i==="mul"?1:0),a("b",b),Qe[i])}if(i==="pi")return Math.PI;if(i==="e")return Math.E;if(i==="random")return Math.random();if(i==="clamp")return Fe(Fe(a("a"),a("b",a("min",0)),Math.max),a("c",a("max",1)),Math.min);if(i==="mix"||i==="quatSlerp")return et(a("a",0),a("b",1),A(a("c",a("t",.5)),.5),i==="quatSlerp");if(i==="dot"){let b=a("a"),L=a("b");return Array.isArray(b)&&Array.isArray(L)?b.reduce((C,D,T)=>C+(D||0)*(L[T]||0),0):A(b)*A(L)}if(i==="cross"){let b=a("a",[0,0,0]),L=a("b",[0,0,0]);return Array.isArray(b)&&Array.isArray(L)?[(b[1]||0)*(L[2]||0)-(b[2]||0)*(L[1]||0),(b[2]||0)*(L[0]||0)-(b[0]||0)*(L[2]||0),(b[0]||0)*(L[1]||0)-(b[1]||0)*(L[0]||0)]:[0,0,0]}if(i==="length"){let b=a("a");return Array.isArray(b)?Math.hypot(...b):Math.abs(A(b))}if(i==="distance"){let b=a("a"),L=a("b");return Array.isArray(b)&&Array.isArray(L)?Math.hypot(...b.map((C,D)=>(C||0)-(L[D]||0))):Math.abs(A(b)-A(L))}if(i==="normalize"){let b=a("a");if(!Array.isArray(b))return A(b)>=0?1:-1;let L=Math.hypot(...b);return L>1e-8?b.map(C=>C/L):b.map(()=>0)}if(i.startsWith("combine"))return["a","b","c","d"].slice(0,Number(i[7])||2).map(b=>A(a(b)));if(i.startsWith("extract")){let b=a("a");return Array.isArray(b)?b[u==="0"||u==="x"?0:u==="1"||u==="y"?1:u==="2"||u==="z"?2:3]??0:0}if(i==="eq")return tt(a("a"),a("b"));if(i==="ne")return!tt(a("a"),a("b"));if(i==="lt")return A(a("a"))<A(a("b"));if(i==="le")return A(a("a"))<=A(a("b"));if(i==="gt")return A(a("a"))>A(a("b"));if(i==="ge")return A(a("a"))>=A(a("b"));if(i==="isNaN")return Number.isNaN(Number(a("a")));if(i==="isInf"){let b=Number(a("a"));return!Number.isFinite(b)&&!Number.isNaN(b)}return i==="and"?X(a("a",!1))&&X(a("b",!1)):i==="or"?X(a("a",!1))||X(a("b",!1)):i==="xor"?X(a("a",!1))!==X(a("b",!1)):i==="not"?!X(a("a",!1)):i==="select"?G(X(a("condition",!1))?a("a"):a("b")):void 0}return c==="type/boolToInt"||c==="type/boolToFloat"?X(a("a",!1))?1:0:c==="type/intToBool"||c==="type/floatToBool"?A(a("a",0))!==0:c==="type/intToFloat"?A(a("a",0)):c==="type/floatToInt"?Math.trunc(A(a("a",0))):void 0}finally{h.delete(l)}},se=()=>{if(P){P=!1,H=!0;let l=Te(n);if(t){t.worldMatrices=l;for(let u of t.meshes||[])u.nodeIndex>=0&&u.nodeIndex<l.length&&(u.transform.set(l[u.nodeIndex]),Me(u.normalMatrix,u.transform))}}if(O){O=!1,H=!0;let l=n?.nodes;if(Array.isArray(t?.meshes)&&Array.isArray(l))for(let u of t.meshes){let h=!0;for(let g=u.nodeIndex,c=0;g!==void 0&&g>=0&&c<128;g=R.get(g),c++){let a=l[g];if(a?.visible===!1||a?.extensions?.KHR_node_visibility?.visible===!1){h=!1;break}}u.visible=h}}H&&(H=!1,t?.render?.())},ee=(l,u={steps:0})=>{if(!l||typeof l.node!="number")return;u.steps===0&&(w=0);let h=[l],g=c=>{h.length+u.steps<fe&&h.push(c)};for(;h.length>0&&u.steps<fe;){u.steps++;let c=h.shift();if(!c||c.node<0||c.node>=o.length)continue;let a=c.node,i=o[a];if(!i)continue;let b=c.socket||"in",L=B(i),C=(T,_=void 0)=>ie(a,T,_,new Set),D=(T="out")=>{let _=i.flows?.[T];_&&g(_)};switch(L){case"flow/branch":D(X(C("condition",!1))?"true":"false");break;case"flow/sequence":for(let T of Object.keys(i.flows||{}).sort((_,W)=>Number(_)-Number(W)||_.localeCompare(W)))D(T);break;case"flow/switch":{let T=i.flows?.[String(C("selection",C("value",0)))]??i.flows?.default;T&&g(T);break}case"flow/for":{let T=Math.trunc(A(C("startIndex",0))),_=Math.trunc(A(C("endIndex",0))),W=Math.max(1,Math.trunc(A(C("step",1),1))),$=i.flows?.body;if($&&_>T&&I<Tt){let st=Math.min(Math.ceil((_-T)/W),fe);I++;try{for(let xe=0;xe<st&&u.steps<fe;xe++)k(a,"index",T+xe*W),ee($,u)}finally{I--}}let ze=i.flows?.completed??i.flows?.out;ze&&g(ze);break}case"flow/doN":{let T=b==="reset"?0:(m.get(a)||0)+1;if(m.set(a,T),k(a,"currentCount",T),k(a,"count",T),b!=="reset"){let _=Math.trunc(A(C("n",U(i,"stopIterations")??U(i,"n")??1),1));T<=_&&D()}break}case"flow/multiGate":{if(b==="reset"){F.set(a,0);break}let T=Object.keys(i.flows||{}).sort();if(!T.length)break;let _=U(i,"isRandom")?Math.floor(Math.random()*T.length):F.get(a)||0;_<T.length&&(D(T[_]),F.set(a,U(i,"isLoop")!==!1?(_+1)%T.length:_+1));break}case"flow/waitAll":{if(b==="reset"){M.delete(a);break}let T=M.get(a);T||M.set(a,T=new Set),T.add(b),T.size>=Math.max(1,Math.trunc(Number(U(i,"inputFlows")??2)||2))&&(T.clear(),D("out"),D("completed"));break}case"flow/throttle":{if(b==="reset"){S.delete(a);break}let T=Math.max(0,A(C("duration",0))),_=S.get(a);_===void 0||N-_>=T?(S.set(a,N),k(a,"lastRemainingTime",0),D()):k(a,"lastRemainingTime",Math.max(0,T-(N-_)));break}case"flow/delay":case"flow/setDelay":{if(b==="cancel"){for(let $=y.length-1;$>=0;$--)y[$].nodeIdx===a&&y.splice($,1);k(a,"lastDelayIndex",-1);break}let T=Math.max(0,A(C("duration",U(i,"duration")??0))),_=i.flows?.done??i.flows?.out;if(T<=0){k(a,"lastDelayIndex",-1),_&&g(_);break}y.length>=vt&&y.shift();let W=V++;k(a,"lastDelayIndex",W),y.push({id:W,nodeIdx:a,rem:T,done:_}),L==="flow/setDelay"&&i.flows?.out&&i.flows?.done&&D("out");break}case"flow/cancelDelay":{let T=Math.trunc(A(C("delayIndex",-1),-1));if(T<0)y.length=0;else for(let _=y.length-1;_>=0;_--)y[_].id===T&&y.splice(_,1);D();break}case"variable/set":Y(U(i,"variable")??U(i,"id"),C("value")),D();break;case"variable/interpolate":{let T=U(i,"variable")??U(i,"id"),_=C("value",C("target")),W=Math.max(0,A(C("duration",U(i,"duration")??.3),.3));T!==void 0&&_!==void 0&&Ue({key:`var:${String(T)}`,varKey:T,from:G(C("from")??f.get(T)??0),to:G(_),dur:W,elapsed:0,quat:!1,linear:U(i,"easing")==="linear",done:i.flows?.done}),D();break}case"pointer/set":{let T=ge(a,i),_=C("value");T&&_!==void 0&&(z(`ptr:${T}`),ae(T,_)),D();break}case"pointer/interpolate":{let T=ge(a,i),_=C("value",C("target")),W=Math.max(0,A(C("duration",U(i,"duration")??.3),.3));if(T&&_!==void 0){let $=C("from")??he(T);$!==void 0&&(W<=0?(ae(T,_),D("done")):Ue({key:`ptr:${T}`,ptr:T,from:G($),to:G(_),dur:W,elapsed:0,quat:T.endsWith("/rotation"),linear:U(i,"easing")==="linear",done:i.flows?.done}))}D();break}case"animation/start":{let T=C("animation")??U(i,"animation")??U(i,"clipName"),_=typeof T=="number"?t?.animations?.[T]?.name??n?.animations?.[T]?.name:typeof T=="string"?T:void 0;t?.playAnimation?.(_),H=!0,D();break}case"animation/stop":case"animation/resetAt":t?.pauseAnimation?.(),L==="animation/resetAt"&&t?.evaluateAnimation?.(A(C("time",0))),H=!0,D();break;case"event/send":case"customEvent/send":{let T=q(U(i,"event")??U(i,"id")),_={};for(let W of Object.keys(i.values||{}))K.has(W)||(_[W]=C(W));T&&(typeof CustomEvent<"u"&&typeof t?.container?.dispatchEvent=="function"&&t.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:T,values:_}})),He(T,_,u)),D();break}default:D();break}}};this.readScenePointer=he,this.writeScenePointer=ae,this.fireOnStart=()=>{o.forEach(l=>{B(l)==="event/onStart"&&ee(l.flows?.out)}),se()},this.fireOnSelect=l=>{if(!l)return;let u=typeof l.meshIndex=="number"?l.meshIndex:-1,h=typeof l.nodeIndex=="number"?l.nodeIndex:t?.meshes?.[u]?.nodeIndex??-1;o.forEach((g,c)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(B(g)))return;let a=U(g,"nodeIndex")??U(g,"node")??ie(c,"nodeIndex",void 0,new Set),i=U(g,"meshName");if(typeof i=="string"&&i?l.meshName===i:a==null||Number(a)<0||Number.isNaN(Number(a))||Z(h,Math.trunc(Number(a)))){if(k(c,"nodeIndex",h),k(c,"meshIndex",u),Array.isArray(l.hitPoint)){let L=[A(l.hitPoint[0]),A(l.hitPoint[1]),A(l.hitPoint[2])];k(c,"hitPoint",L),k(c,"point",L),k(c,"intersectionPoint",L)}if(Array.isArray(l.normal)){let L=[A(l.normal[0]),A(l.normal[1],1),A(l.normal[2])];k(c,"normal",L),k(c,"hitNormal",L)}typeof l.distance=="number"&&k(c,"distance",l.distance),ee(g.flows?.out)}}),se()},this.receiveCustomEvent=(l,u={})=>He(l,u,{steps:0});function He(l,u,h){if(!(E>=At)){E++;try{let g=q(l);o.forEach((c,a)=>{if(!/^(customE|e)vent\/receive$/.test(B(c)))return;let i=U(c,"event")??U(c,"id");if(!(q(i)!==g&&String(i)!==String(l))){for(let[b,L]of Object.entries(u))K.has(b)||k(a,b,G(L));ee(c.flows?.out,h)}}),se()}finally{E--}}}this.tick=l=>{if(!Number.isFinite(l)||l<0)return;let u=Math.min(l,.25);N+=u,o.forEach((g,c)=>{B(g)==="event/onTick"&&(k(c,"timeDelta",u),k(c,"dt",u),k(c,"timeElapsed",N),ee(g.flows?.out))});let h=[];for(let g=v.length-1;g>=0;g--){let c=v[g];c.elapsed+=u;let a=c.dur>1e-6?J(c.elapsed/c.dur):1,i=c.linear?a:a*a*(3-2*a),b=et(c.from,c.to,i,c.quat);c.ptr?ae(c.ptr,b):c.varKey!==void 0&&Y(c.varKey,b),a>=1&&(v.splice(g,1),c.done&&h.push(c.done))}for(let g=y.length-1;g>=0;g--){let c=y[g];c.rem-=u,c.rem<=0&&(y.splice(g,1),c.done&&h.push(c.done))}for(let g of h)ee(g);se()},this.dispose=()=>{v.length=0,y.length=0,f.clear(),d.clear(),m.clear(),M.clear(),S.clear(),F.clear()}}},j=new WeakMap,pe=new WeakMap;function St(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||Be().some(p=>p.name==="xr-live-head-follow"))return;let n=e.gltf,r=n?.nodes;if(!Array.isArray(r)||r.length===0)return;let o=Math.min(t,.1),s=(pe.get(e)||0)+o,x=!1;for(let p=0;p<r.length;p++){let f=r[p],d=qe(f?.extras?.xr?.orbit);if(!d)continue;let m=0,M=0,S=0;if(Array.isArray(d.target))m=d.target[0],M=d.target[1],S=d.target[2];else if(typeof d.target=="string"&&d.target!=="head"){let V=r.find(N=>N?.name===d.target);Array.isArray(V?.translation)&&(m=A(V.translation[0]),M=A(V.translation[1]),S=A(V.translation[2]))}let F=d.phase+d.speed*s,v=m+Math.cos(F)*d.radius,y=M+d.height,R=S+Math.sin(F)*d.radius;if(f.translation=[v,y,R],d.faceCenter){let V=Math.atan2(m-v,S-R);f.rotation=[0,Math.sin(V*.5),0,Math.cos(V*.5)]}x=!0}if(x){pe.set(e,s);let p=Te(n);e.worldMatrices=p;for(let f of e.meshes||[])f.nodeIndex>=0&&f.nodeIndex<p.length&&(f.transform.set(p[f.nodeIndex]),Me(f.normalMatrix,f.transform))}}function be(e){if(!(!e||typeof e!="object"))return j.get(e)||j.get(e.viewer)||j.get(e._view)}function Pe(e,t,n){let r=be(e);return r?(r.receiveCustomEvent(t,n),!0):!1}var Le={name:"khr-interactivity",sendInteractivityEvent:Pe,getInteractivityVM:be,onLoadModel(e,t){if(!e||typeof e!="object")return;j.get(e)?.dispose(),j.delete(e),pe.delete(e);let n=t?.extensions?.KHR_interactivity,r=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!r||!Array.isArray(r.nodes))return;let o=new re(e,t,r);j.set(e,o),o.fireOnStart()},onMeshSelect(e,t){j.get(e)?.fireOnSelect(t)},onUpdate(e,t){j.get(e)?.tick(t),St(e,t)},onDestroy(e,t){j.get(t)?.dispose(),j.delete(t),pe.delete(t)}};var oe=new Map,Ce=new WeakMap;function rt(e,t){oe.set(e,t)}var Ve={name:"materials",onBuildPrimitiveVAO(e,t,n,r,o){return(((r?.materials&&n.material!==void 0?r.materials[n.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let n=Ce.get(e);n||(n=e.createTexture(),Ce.set(e,n));let r=Math.max(1,t.canvas.width),o=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,n),e.copyTexImage2D(3553,0,6408,0,0,r,o,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,r){if(!t)return null;if(t.name&&oe.has(t.name)){let v=oe.get(t.name);return{vs:v.vs||n,fs:v.fs||r}}let o=t.extensions||{},s=o.KHR_materials_clearcoat,x=o.KHR_materials_sheen,p=!!o.KHR_materials_transmission,f=!!o.KHR_materials_ior,d=o.KHR_materials_iridescence;if(!s&&!x&&!o.KHR_materials_unlit&&!p&&!o.KHR_materials_volume&&!f&&!o.KHR_materials_dispersion&&!d)return null;if(o.KHR_materials_unlit)return{vs:n,fs:r.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let m=r;if(p){let v=m.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
|
|
33
|
+
`;m=m.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
|
|
34
|
+
${v}out vec4 fragColor;`)}let M=(v,y,R=0,V=1e6,N=3)=>{let E=Number(v);return(Number.isFinite(E)?Math.min(V,Math.max(R,E)):y).toFixed(N)},S=Number(o.KHR_materials_ior?.ior??1.5),F=Number.isFinite(S)?Math.min(10,Math.max(1,S)):1.5;if(f){let v=Math.pow((F-1)/(F+1),2);m=m.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${M(v,.04,0,1,4)}),base.rgb,metallic);`)}if(d){let v=M(d.iridescenceFactor,1,0,1),y=M(d.iridescenceIor,1.3,1,10);m=m.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${y}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${v}*pow(1.-NoV,2.));`)}if(p){let v=M(o.KHR_materials_transmission?.transmissionFactor,1,0,1),y=o.KHR_materials_volume||{},R=M(y.thicknessFactor,.5,0,1e4),V=M(y.attenuationDistance,1,.001,1e6),N=Array.isArray(y.attenuationColor)?y.attenuationColor:[1,1,1],E=M(o.KHR_materials_dispersion?.dispersion,0,0,10);m=m.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=${M(F,1.5,1,10)},dV=${E},tV=${R},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(${M(N[0],1,0,1)},${M(N[1],1,0,1)},${M(N[2],1,0,1)});
|
|
39
|
+
vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${V},.001));
|
|
40
|
+
diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${v});`)}if(s&&!r.includes("uClearcoat")){let v=M(s.clearcoatFactor,1,0,1),y=M(s.clearcoatRoughnessFactor,0,0,1);m=m.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${y},NoV)*${v};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${y})*ccF;fragColor=vec4(color,base.a);`)}if(x){let v=Array.isArray(x.sheenColorFactor)?x.sheenColorFactor:[1,1,1],y=`color+=vec3(${M(v[0],1,0,1)},${M(v[1],1,0,1)},${M(v[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;m.includes("color=applyToneMapping(color,uToneMapping);")?m=m.replace("color=applyToneMapping(color,uToneMapping);",`${y}color=applyToneMapping(color,uToneMapping);`):m=m.replace("fragColor=vec4(color,base.a);",`${y}fragColor=vec4(color,base.a);`)}return{vs:n,fs:m}},onBeforeDrawPrimitive(e,t,n,r,o,s){let x=n.materialIndex;if(x!==void 0&&s?.materials){let p=s.materials[x];p?.name&&oe.has(p.name)&&oe.get(p.name).onBindUniforms?.(e,t,n)}if(n.isTransmissive){let p=Ce.get(e);if(p){e.activeTexture(33990),e.bindTexture(3553,p);let f=e.getUniformLocation(t,"uTransmissionTex");f&&e.uniform1i(f,6);let d=e.getUniformLocation(t,"uViewportSize");d&&e.uniform2f(d,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}};var It=`#version 300 es
|
|
41
|
+
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.);}`,Et=`#version 300 es
|
|
42
|
+
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);}`,ye=new WeakMap,ot=new Float32Array(20);function Ne(e,t){let[n,r,o,s,x,p]=t;return[e[0]*n+e[4]*r+e[8]*o+e[12],e[1]*n+e[5]*r+e[9]*o+e[13],e[2]*n+e[6]*r+e[10]*o+e[14],Math.abs(e[0])*s+Math.abs(e[4])*x+Math.abs(e[8])*p,Math.abs(e[1])*s+Math.abs(e[5])*x+Math.abs(e[9])*p,Math.abs(e[2])*s+Math.abs(e[6])*x+Math.abs(e[10])*p]}function _t(e){if(e._lb!==void 0)return e._lb;let t=1e9,n=1e9,r=1e9,o=-1e9,s=-1e9,x=-1e9;for(let p of e.primitives||[]){let f=p.positions;if(f)for(let d=0;d<f.length;d+=3)f[d]<t&&(t=f[d]),f[d+1]<n&&(n=f[d+1]),f[d+2]<r&&(r=f[d+2]),f[d]>o&&(o=f[d]),f[d+1]>s&&(s=f[d+1]),f[d+2]>x&&(x=f[d+2])}return e._lb=t<=o?[(t+o)*.5,(n+s)*.5,(r+x)*.5,(o-t)*.5,(s-n)*.5,(x-r)*.5]:null}function Ft(e){let t=ye.get(e);if(t)return t;let n=(p,f)=>{let d=e.createShader(p);return e.shaderSource(d,f),e.compileShader(d),d},r=e.createProgram();e.attachShader(r,n(35633,It)),e.attachShader(r,n(35632,Et)),e.linkProgram(r);let o=e.createVertexArray(),s=e.createBuffer(),x=e.createBuffer();return e.bindVertexArray(o),e.bindBuffer(34962,s),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,x),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:r,vao:o,vbo:s,ibo:x,uMVP:e.getUniformLocation(r,"uMVP"),uIntensity:e.getUniformLocation(r,"uShadowIntensity"),uSoftness:e.getUniformLocation(r,"uShadowSoftness")},ye.set(e,t),t}var ke={name:"contact-shadow",onAfterRender(e,t,n){let r=t.shadowIntensity;if(r<=0||!t.bounds)return;let o=Ft(e),s=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,x=[],p=[];for(let y of t.meshes||[]){if(!y||y.visible===!1||y.isPluginMesh||y.name==="__xr_reticle__"||y.name?.startsWith("__xr_slot_"))continue;let R=_t(y);if(!R)continue;y.transform&&(R=Ne(y.transform,R)),t.modelRootMatrix&&(R=Ne(t.modelRootMatrix,R));let[V,N,E,w,I,P]=R,O=[V,E,w,P,N-I,N+I];/floor|table|pedestal|ground|base|plane/i.test(y.name||"")||I<.14&&Math.min(w,P)>.45?p.push(O):x.push(O)}let f=[],d=t.bounds.center||[0,0,0],m=Math.max(.05,Number(t.bounds.radius)||.5),M=t.bounds.min,S=M?[d[0],d[1],d[2],m,Math.max(.01,d[1]-M[1]),m]:[d[0],d[1],d[2],m,m,m];t.modelRootMatrix&&(S=Ne(t.modelRootMatrix,S));let v=t.xrSessionActive&&p.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:S[1]-S[4]+.002;for(let[y,R,V,N,E]of x){let w=-1/0;for(let[P,O,H,B,,k]of p)E>=k-.08&&Math.abs(y-P)<=H&&Math.abs(R-O)<=B&&k+.002>w&&(w=k+.002);s&&(w=Math.max(w,y>=.04&&y<=.36&&R>=-.34&&R<=-.04&&E>=.01?.036:Math.hypot(y,R)<=.66&&E>=-.06?.003:-.477)),isFinite(w)||(w=v);let I=f.find(P=>Math.hypot(y-P[0],R-P[1])<.06&&Math.abs(w-P[5])<.05);I?(I[2]=Math.max(I[2],V*.78),I[3]=Math.max(I[3],N*.78),I[4]=Math.min(I[4],E)):f.push([y,R,V,N,E,w])}if(f.length===0){let y=Math.max(.1,S[3]*1.5)/1.45;f.push([S[0],S[2],y,y,v,v])}e.useProgram(o.prog),e.uniformMatrix4fv(o.uMVP,!1,n),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(o.vao),e.bindBuffer(34962,o.vbo);for(let[y,R,V,N,E,w]of f){let I=Math.max(0,E-w),P=r/(1+I*2);if(P<.02)continue;let O=1+Math.min(.75,I*.85),H=Math.max(.045,V*1.45*O),B=Math.max(.045,N*1.45*O);ot.set([y-H,w,R-B,0,0,y+H,w,R-B,1,0,y+H,w,R+B,1,1,y-H,w,R+B,0,1]),e.bufferSubData(34962,0,ot),e.uniform1f(o.uIntensity,P),e.uniform1f(o.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,I*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=ye.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),ye.delete(e))}};var at=new WeakMap,De={name:"webxr-suite",onConfigureXRSessionInit(e,t){let n=new Set(t.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation");let r=e?.querySelector?.('[slot="ar-overlay"]')||null;r&&(n.add("dom-overlay"),t.domOverlay={root:r},r.addEventListener?.("beforexrselect",o=>{o.preventDefault()})),t.optionalFeatures=Array.from(n)},onXRFrame(e,t,n,r){if(!e||!t||!n||!r)return;let o=at.get(t);if(o||(o={lightProbe:null},at.set(t,o),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(s=>{o&&s&&(o.lightProbe=s)}).catch(()=>{})),o.lightProbe&&typeof n.getLightEstimate=="function"){let s=n.getLightEstimate(o.lightProbe);if(s){let x=s.primaryLightDirection,p=s.primaryLightIntensity;if(x&&p&&Array.isArray(e.lights)){let f=e.lights.find(m=>m.type==="directional");f||(f={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(f)),f.direction=[x.x,x.y,x.z];let d=Math.max(p.x,p.y,p.z,.001);f.color=[p.x/d,p.y/d,p.z/d],f.intensity=d}s.sphericalHarmonicsCoefficients&&e.gl&&le(e.gl,s.sphericalHarmonicsCoefficients)}}}};Q(ke);Q(Ee);Q(Se);Q(Ve);Q(De);Q(Le);
|