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
|
+
"use strict";var xe=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var $e=(i,e)=>{for(var t in e)xe(i,t,{get:e[t],enumerable:!0})},qe=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of je(e))!Ke.call(i,n)&&n!==t&&xe(i,n,{get:()=>e[n],enumerable:!(r=Ye(e,n))||r.enumerable});return i};var Ze=i=>qe(xe({},"__esModule",{value:!0}),i);var nt={};$e(nt,{MicroViewer:()=>se,SANDBOX_HOST_SCENE_LIMITS:()=>tt,ThreeView:()=>se,decodeUtf8:()=>Ie,default:()=>it,getDecoder:()=>ae,getRegisteredPlugins:()=>De,isGLBData:()=>Be,mat3NormalFromMat4:()=>te,mat4Create:()=>G,mat4FromRotationTranslationScale:()=>ge,mat4Invert:()=>ye,mat4LookAt:()=>le,mat4Multiply:()=>O,mat4Perspective:()=>he,parseGLB:()=>Le,rayIntersectsTriangle:()=>Te,readFloat32Array:()=>Je,registerDecoder:()=>Ne,registerPlugin:()=>Re,resolveNodeWorldMatrices:()=>Me,sanitizeTextureUri:()=>Ge,toGLBData:()=>Pe,unprojectPoint:()=>be});module.exports=Ze(nt);function G(){let i=new Float32Array(16);return i[0]=1,i[5]=1,i[10]=1,i[15]=1,i}function he(i,e,t,r,n){let s=1/Math.tan(e/2);i.fill(0),i[0]=s/t,i[5]=s,i[11]=-1;let o=1/(r-n);return i[10]=(n+r)*o,i[14]=2*n*r*o,i}function le(i,e,t,r){let[n,s,o]=e,[h,c,u]=r,[a,l,f]=t,b=n-a,p=s-l,T=o-f,M=Math.hypot(b,p,T);M<=1e-5?(b=0,p=0,T=1):(b/=M,p/=M,T/=M);let D=c*T-u*p,E=u*b-h*T,w=h*p-c*b;M=Math.hypot(D,E,w),M<=1e-5?(D=0,E=0,w=0):(D/=M,E/=M,w/=M);let v=p*w-T*E,d=T*D-b*w,m=b*E-p*D;return M=Math.hypot(v,d,m),M<=1e-5?(v=0,d=0,m=0):(v/=M,d/=M,m/=M),i[0]=D,i[1]=v,i[2]=b,i[3]=0,i[4]=E,i[5]=d,i[6]=p,i[7]=0,i[8]=w,i[9]=m,i[10]=T,i[11]=0,i[12]=-(D*n+E*s+w*o),i[13]=-(v*n+d*s+m*o),i[14]=-(b*n+p*s+T*o),i[15]=1,i}function O(i,e,t){let r=e[0],n=e[1],s=e[2],o=e[3],h=e[4],c=e[5],u=e[6],a=e[7],l=e[8],f=e[9],b=e[10],p=e[11],T=e[12],M=e[13],D=e[14],E=e[15],w=t[0],v=t[1],d=t[2],m=t[3];return i[0]=w*r+v*h+d*l+m*T,i[1]=w*n+v*c+d*f+m*M,i[2]=w*s+v*u+d*b+m*D,i[3]=w*o+v*a+d*p+m*E,w=t[4],v=t[5],d=t[6],m=t[7],i[4]=w*r+v*h+d*l+m*T,i[5]=w*n+v*c+d*f+m*M,i[6]=w*s+v*u+d*b+m*D,i[7]=w*o+v*a+d*p+m*E,w=t[8],v=t[9],d=t[10],m=t[11],i[8]=w*r+v*h+d*l+m*T,i[9]=w*n+v*c+d*f+m*M,i[10]=w*s+v*u+d*b+m*D,i[11]=w*o+v*a+d*p+m*E,w=t[12],v=t[13],d=t[14],m=t[15],i[12]=w*r+v*h+d*l+m*T,i[13]=w*n+v*c+d*f+m*M,i[14]=w*s+v*u+d*b+m*D,i[15]=w*o+v*a+d*p+m*E,i}function ge(i,e,t,r){let n=e[0],s=e[1],o=e[2],h=e[3],c=n+n,u=s+s,a=o+o,l=n*c,f=n*u,b=n*a,p=s*u,T=s*a,M=o*a,D=h*c,E=h*u,w=h*a,v=r[0],d=r[1],m=r[2];return i[0]=(1-(p+M))*v,i[1]=(f+w)*v,i[2]=(b-E)*v,i[3]=0,i[4]=(f-w)*d,i[5]=(1-(l+M))*d,i[6]=(T+D)*d,i[7]=0,i[8]=(b+E)*m,i[9]=(T-D)*m,i[10]=(1-(l+p))*m,i[11]=0,i[12]=t[0],i[13]=t[1],i[14]=t[2],i[15]=1,i}function te(i,e){let t=e[0],r=e[1],n=e[2],s=e[4],o=e[5],h=e[6],c=e[8],u=e[9],a=e[10],l=a*o-h*u,f=-a*s+h*c,b=u*s-o*c,p=t*l+r*f+n*b;return p&&(p=1/p,i[0]=l*p,i[1]=(-a*r+n*u)*p,i[2]=(h*r-n*o)*p,i[3]=f*p,i[4]=(a*t-n*c)*p,i[5]=(-h*t+n*s)*p,i[6]=b*p,i[7]=(-u*t+r*c)*p,i[8]=(o*t-r*s)*p),i}function ye(i,e){let t=e[0],r=e[1],n=e[2],s=e[3],o=e[4],h=e[5],c=e[6],u=e[7],a=e[8],l=e[9],f=e[10],b=e[11],p=e[12],T=e[13],M=e[14],D=e[15],E=t*h-r*o,w=t*c-n*o,v=t*u-s*o,d=r*c-n*h,m=r*u-s*h,C=n*u-s*c,P=a*T-l*p,g=a*M-f*p,A=a*D-b*p,L=l*M-f*T,F=l*D-b*T,y=f*D-b*M,R=E*y-w*F+v*L+d*A-m*g+C*P;return R?(R=1/R,i[0]=(h*y-c*F+u*L)*R,i[1]=(n*F-r*y-s*L)*R,i[2]=(T*C-M*m+D*d)*R,i[3]=(f*m-l*C-b*d)*R,i[4]=(c*A-o*y-u*g)*R,i[5]=(t*y-n*A+s*g)*R,i[6]=(M*v-p*C-D*w)*R,i[7]=(a*C-f*v+b*w)*R,i[8]=(o*F-h*A+u*P)*R,i[9]=(r*A-t*F-s*P)*R,i[10]=(p*m-T*v+D*E)*R,i[11]=(l*v-a*m-b*E)*R,i[12]=(h*g-o*L-c*P)*R,i[13]=(t*L-r*g+n*P)*R,i[14]=(T*w-p*d-M*E)*R,i[15]=(a*d-l*w+f*E)*R,i):null}function be(i,e,t,r,n){let s=n[0]*e+n[4]*t+n[8]*r+n[12],o=n[1]*e+n[5]*t+n[9]*r+n[13],h=n[2]*e+n[6]*t+n[10]*r+n[14],c=n[3]*e+n[7]*t+n[11]*r+n[15],u=c!==0?1/c:1;i[0]=s*u,i[1]=o*u,i[2]=h*u}function Te(i,e,t,r,n,s,o,h,c,u,a,l,f,b,p,T,M=0){let D=u-o,E=a-h,w=l-c,v=f-o,d=b-h,m=p-c,C=n*m-s*d,P=s*v-r*m,g=r*d-n*v,A=D*C+E*P+w*g;if(A>-1e-7&&A<1e-7)return!1;let L=1/A,F=i-o,y=e-h,R=t-c,B=L*(F*C+y*P+R*g);if(B<-M||B>1+M)return!1;let x=y*w-R*E,X=R*D-F*w,k=F*E-y*D,ie=L*(r*x+n*X+s*k);if(ie<-M||B+ie>1+M)return!1;let U=L*(v*x+d*X+m*k);if(U>1e-4&&U<T.distance){T.distance=U,T.point=[i+r*U,e+n*U,t+s*U];let H=E*m-w*d,N=w*v-D*m,I=D*d-E*v,_=Math.hypot(H,N,I)||1;return T.normal=[H/_,N/_,I/_],!0}return!1}function Me(i,e){let t=Array.isArray(i?.nodes)?i.nodes.length:0,r=[];for(let a=0;a<t;a++)r.push(G());if(t===0)return r;let n=new Set;for(let a of i.nodes)if(Array.isArray(a.children))for(let l of a.children)n.add(l);let s=new Set,o=128,h=(a,l,f=0)=>{if(f>o||a<0||a>=t||s.has(a))return;s.add(a);let b=i.nodes[a];if(!b)return;let p=G();if(e&&e[a])p.set(e[a]);else if(b.matrix&&b.matrix.length===16)p.set(b.matrix);else{let M=b.translation||[0,0,0],D=b.rotation||[0,0,0,1],E=b.scale||[1,1,1];ge(p,D,M,E)}let T=r[a];if(l?O(T,l,p):T.set(p),Array.isArray(b.children))for(let M of b.children)typeof M=="number"&&h(M,T,f+1)},c=[],u=i.scenes&&i.scenes[i.scene!==void 0?i.scene:0];if(u&&Array.isArray(u.nodes))c.push(...u.nodes);else for(let a=0;a<t;a++)n.has(a)||c.push(a);for(let a of c)h(a,null);for(let a=0;a<t;a++)!n.has(a)&&!c.includes(a)&&h(a,null);return r}var ve="__THREE_LIVE_REGISTRY__";function me(){let i=typeof globalThis<"u"?globalThis:{};if(!i[ve]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(i,ve,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{i[ve]=e}}return i[ve]}var V=me().plugins;function Re(i){let e=me().plugins;e.some(t=>t.name===i.name)||e.push(i)}function De(){return me().plugins}function Ie(i){return new TextDecoder().decode(i)}var Se=me().decoders;function Ne(i,e){Se.set(i.toLowerCase(),e)}function ae(i){return Se.get(i.toLowerCase())}function Le(i){let e=ArrayBuffer.isView(i)?i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength):i,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=t.getUint32(0,!0);if(r!==1179937895){let f=t.getUint8(0);throw f===123||f===32||f===10||f===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 n=t.getUint32(4,!0);if(n!==2)throw new Error(`Unsupported GLB version: ${n}`);let s=t.getUint32(8,!0),o=12,h=null,c=null;for(;o+8<=s&&o+8<=e.byteLength;){let f=t.getUint32(o,!0),b=t.getUint32(o+4,!0),p=o+8;if(p+f>e.byteLength)throw new Error(`Truncated GLB chunk: required ${p+f} bytes, buffer has ${e.byteLength}`);if(b===1313821514){let T=new Uint8Array(e,p,f),M=Ie(T);h=JSON.parse(M,(D,E)=>D==="__proto__"||D==="constructor"||D==="prototype"?void 0:E)}else b===5130562&&(c=e.slice(p,p+f));o=p+f}if(!h)throw new Error("Missing JSON chunk in GLB");let u=h.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!ae("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(u.includes("EXT_meshopt_compression")&&!ae("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(u.includes("KHR_texture_basisu")&&!ae("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=c||new ArrayBuffer(0),l={gltf:h,bin:a,animations:[]};for(let f of V)f.onParseGLB?.(l);return l}function Je(i,e,t){return e%4===0?new Float32Array(i,e,t):new Float32Array(i.slice(e,e+t*4))}function Be(i){return typeof i=="object"&&i!==null&&"gltf"in i&&typeof i.gltf=="object"&&i.gltf!==null&&"bin"in i&&(i.bin instanceof ArrayBuffer||ArrayBuffer.isView(i.bin))}function Pe(i){if(Be(i))return i;if(i instanceof ArrayBuffer||ArrayBuffer.isView(i))return Le(i);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Ue=`#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
|
+
}`,_e=`#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);}`,et=`#version 300 es
|
|
219
|
+
precision highp float;
|
|
220
|
+
uniform vec4 uColorId;
|
|
221
|
+
out vec4 fragColor;
|
|
222
|
+
void main(){fragColor=uColorId;}`;function Fe(i,e,t){let r=i.createShader(e);if(i.shaderSource(r,t),i.compileShader(r),!i.getShaderParameter(r,35713)){let n=i.getShaderInfoLog(r);throw i.deleteShader(r),new Error(`Shader compile error: ${n}`)}return r}function Ee(i,e,t){let r=Fe(i,35633,e),n=Fe(i,35632,t),s=i.createProgram();if(i.attachShader(s,r),i.attachShader(s,n),i.linkProgram(s),!i.getProgramParameter(s,35714)){let o=i.getProgramInfoLog(s);throw i.deleteProgram(s),new Error(`Program link error: ${o}`)}return s}function Ae(i,e,t){let r={};for(let n of t)r[n]=i.getUniformLocation(e,n);return r}var ke=["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 Ge(i){if(typeof i!="string")return null;let e=i.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let t=e.toLowerCase();return t.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:t.startsWith("https://")||t.startsWith("blob:")?e:t.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function we(i,e,t,r,n,s,o){if(r===void 0||!e.accessors?.[r])return null;let h=e.accessors[r],c=e.bufferViews[h.bufferView],u=(c.byteOffset||0)+(h.byteOffset||0),a=c.byteStride&&c.byteStride>s*4?c.byteStride>>2:s,l;if(a===s)l=new Float32Array(t,u,h.count*s);else{l=new Float32Array(h.count*s);let b=new Float32Array(t,c.byteOffset||0,Math.floor(c.byteLength/4)),p=(h.byteOffset||0)>>2;for(let T=0;T<h.count;T++){let M=p+T*a;for(let D=0;D<s;D++)l[T*s+D]=b[M+D]}}let f=i.createBuffer();return o.push(f),i.bindBuffer(34962,f),i.bufferData(34962,l,35044),i.enableVertexAttribArray(n),i.vertexAttribPointer(n,s,5126,!1,0,0),l}var tt=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Ve=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ce(i,e,t=Ve,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n,bin:s}=e,o=[],h=Me(n),c=[];if(Array.isArray(n.nodes))for(let P=0;P<n.nodes.length;P++){let g=n.nodes[P];g.mesh!==void 0&&n.meshes&&n.meshes[g.mesh]&&c.push({node:g,nodeIdx:P,meshIdx:g.mesh})}let u=c.length>0?c:(n.meshes||[]).map((P,g)=>({node:P,nodeIdx:-1,meshIdx:g})),a=[];if(Array.isArray(e.lights)&&e.lights.length>0)a.push(...e.lights);else if(n.extensions?.KHR_lights_punctual?.lights){let P=n.extensions.KHR_lights_punctual.lights;for(let g of P){let A=g.type==="directional"?"directional":g.type==="point"?"point":"ambient";a.push({type:A,color:g.color||[1,1,1],intensity:g.intensity!==void 0?g.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]})),u.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${u.length}`);let l=[];if(n.textures&&n.images){if(n.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${n.textures.length}`);for(let P=0;P<n.textures.length;P++){let g=n.textures[P],A=n.images[g.source];if(A){let L=i.createTexture();if(i.bindTexture(3553,L),i.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),i.texParameteri(3553,10242,10497),i.texParameteri(3553,10243,10497),i.texParameteri(3553,10241,9729),i.texParameteri(3553,10240,9729),A.bufferView!==void 0){let F=n.bufferViews[A.bufferView],y=s.slice(F.byteOffset||0,(F.byteOffset||0)+F.byteLength),R=new Blob([y],{type:A.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(R).then(B=>{i.bindTexture(3553,L),i.texImage2D(3553,0,6408,6408,5121,B),i.generateMipmap(3553),r?.()}).catch(()=>{})}else if(A.uri){let F=Ge(A.uri);if(F){let y=new Image;y.crossOrigin="anonymous",y.referrerPolicy="no-referrer",y.onload=()=>{i.bindTexture(3553,L),i.texImage2D(3553,0,6408,6408,5121,y),i.generateMipmap(3553),r?.()},y.src=F}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",A.uri)}l.push(L)}else l.push(null)}}let f=[1/0,1/0,1/0],b=[-1/0,-1/0,-1/0],p=0,T=0;for(let P=0;P<u.length;P++){let g=u[P],A=n.meshes[g.meshIdx],L=g.nodeIdx>=0?h[g.nodeIdx]:G(),F=new Float32Array(9);te(F,L);let y={name:g.node.name||A.name||`Mesh_${g.meshIdx}`,nodeIndex:g.nodeIdx,transform:L,normalMatrix:F,primitives:[],extras:g.node.extras||A.extras};for(let R of A.primitives||[]){if(R.extensions?.KHR_draco_mesh_compression){let S=ae("draco");S&&S.decodePrimitive(n,R,s)}let B=[],x=i.createVertexArray();i.bindVertexArray(x);let X=n.accessors[R.attributes.POSITION],k=Number(X?.count??0);if(!Number.isFinite(k)||k<0||p+k>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(p+=k,X?.min&&X?.max)for(let S=0;S<3;S++){let j=L[12+S],re=L[12+S];for(let Z=0;Z<3;Z++){let fe=L[Z*4+S]*X.min[Z],pe=L[Z*4+S]*X.max[Z];j+=fe<pe?fe:pe,re+=fe>pe?fe:pe}j<f[S]&&(f[S]=j),re>b[S]&&(b[S]=re)}let ie=we(i,n,s,R.attributes.POSITION,0,3,B);we(i,n,s,R.attributes.NORMAL,1,3,B),we(i,n,s,R.attributes.TEXCOORD_0,2,2,B);let U=0,H=5123,N=null;if(R.indices!==void 0){let S=n.accessors[R.indices],re=(n.bufferViews[S.bufferView].byteOffset||0)+(S.byteOffset||0);if(U=Number(S.count??0),!Number.isFinite(U)||U<0||T+U>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);T+=U,H=S.componentType===5125?5125||5125:5123||5123;let Z=i.createBuffer();B.push(Z),i.bindBuffer(34963,Z),S.componentType===5125?(N=new Uint32Array(s,re,S.count),i.bufferData(34963,N,35044)):(N=new Uint16Array(s,re,S.count),i.bufferData(34963,N,35044))}else U=X.count;let I={};for(let S of V)if(S.onBuildPrimitiveVAO){let j=S.onBuildPrimitiveVAO(i,x,R,n,s);j&&(I[S.name]=j)}i.bindVertexArray(null);let _=n.materials&&R.material!==void 0?n.materials[R.material]:null,W=Ue,K=_e,q=!1;for(let S of V)if(S.onResolveShader){let j=S.onResolveShader(R,_,W,K);j&&(W=j.vs,K=j.fs,q=!0)}let $=q?Ee(i,W,K):null,de=$?Ae(i,$,ke):null,z=_?.pbrMetallicRoughness,Y=z?.baseColorFactor||[.8,.8,.8,1],oe=z?.metallicFactor??.1,ue=z?.roughnessFactor??.5,ne=_?.extensions?.KHR_materials_clearcoat,J=ne?ne.clearcoatFactor??1:0,Q=Math.max(.04,ne?.clearcoatRoughnessFactor??.04),ee=z?.baseColorTexture!==void 0&&l[z.baseColorTexture.index]?l[z.baseColorTexture.index]:null,ce=z?.metallicRoughnessTexture!==void 0&&l[z.metallicRoughnessTexture.index]?l[z.metallicRoughnessTexture.index]:null,Xe=_?.normalTexture!==void 0&&l[_.normalTexture.index]?l[_.normalTexture.index]:null,He=_?.normalTexture?.scale??1,We=_?.occlusionTexture!==void 0&&l[_.occlusionTexture.index]?l[_.occlusionTexture.index]:null,Oe=_?.occlusionTexture?.strength??1,ze=!!(_?.extensions?.KHR_materials_transmission||I.materials?.isTransmissive);y.primitives.push({vao:x,indexCount:U,indexType:H,baseColor:Y,metallic:oe,roughness:ue,clearcoat:J,clearcoatRoughness:Q,positions:ie,indices:N,texture:ee,metallicRoughnessTexture:ce,normalTexture:Xe,occlusionTexture:We,normalScale:He,occlusionStrength:Oe,buffers:B,materialIndex:R.material,pluginData:I,customProgram:$,customUniforms:de,isTransmissive:ze})}o.push(y)}isFinite(f[0])||(f=[-1,-1,-1]),isFinite(b[0])||(b=[1,1,1]);let M=[(f[0]+b[0])/2,(f[1]+b[1])/2,(f[2]+b[2])/2],D=b[0]-f[0],E=b[1]-f[1],w=b[2]-f[2],v=Math.max(Math.hypot(D,E,w)/2,.5),d=[f[0],f[1],f[2]],m=[b[0],b[1],b[2]],C=e.animations;if(!C){for(let P of V)if(P.onParseGLB?.(e),e.animations){C=e.animations;break}}return C||(C=[]),{meshes:o,bounds:{center:M,radius:v,min:d,max:m},lights:a,animations:C,worldMatrices:h}}var se=class{constructor(e,t,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=G();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=G();this.viewMatrix=G();this.modelMatrix=G();this.mvpMatrix=G();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:G(),rawValueToMeters:.001,format:0};this.container=e;let n,s;if(t&&typeof t.getContext=="function"?(n=t,s=r):(s=t,n=s?.canvas),!n){let c=e.querySelector("canvas");c||(c=document.createElement("canvas"),c.style.width="100%",c.style.height="100%",c.style.display="block",c.style.touchAction="none",e.prepend(c)),n=c}this.canvas=n,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let o=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!o:o&&(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 h=n.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!h)throw new Error("WebGL2 not supported");this.gl=h,this.renderProg=Ee(h,Ue,_e),this.pickProg=Ee(h,Qe,et),this.uRender=Ae(h,this.renderProg,ke),this.uPick=Ae(h,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(e,t){Ne(e,t)}static getDecoder(e){return ae(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,n=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=n,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,n,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,n,s)}loadGLBData(e,t){let{meshes:r,bounds:n,lights:s,animations:o,worldMatrices:h}=Ce(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=n,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=o||[],this.worldMatrices=h||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let u of e.gltf.nodes)this.initialNodeTransforms.push({t:u.translation?[u.translation[0],u.translation[1],u.translation[2]]:[0,0,0],r:u.rotation?[u.rotation[0],u.rotation[1],u.rotation[2],u.rotation[3]]:[0,0,0,1],s:u.scale?[u.scale[0],u.scale[1],u.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let u of V)u.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:n.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let c=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;c!==void 0&&(this.envIntensity=Math.max(0,Number(c))),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(e){this.loadGLBData(Le(e))}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(e){this.loadGLBData(Pe(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Pe(e),{meshes:n}=Ce(this.gl,r,Ve,()=>this.render());if(t)for(let s of n)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],te(s.normalMatrix,s.transform);this.backdropMeshes=n,this.update(0),this.render()}setClearColor(e,t,r,n=1){this.clearColor=[e,t,r,n]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],n;e instanceof Map?n=e.get(r.name)??e.get(t):Array.isArray(e)?n=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?n=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(n=e[t])),n&&n.length===16&&(r.transform.set(n),te(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],n=[],s=[],o=[],h=[];for(let c of this.lights){let u=c.color||[1,1,1],a=c.intensity!==void 0?c.intensity:1;if(c.type==="ambient")r=[u[0]*a,u[1]*a,u[2]*a];else if(c.type==="directional"&&n.length<6){let l=c.direction||[.5,1,.8];n.push(l[0],l[1],l[2]),s.push(u[0]*a,u[1]*a,u[2]*a)}else if(c.type==="point"&&o.length<6){let l=c.position||[0,0,0];o.push(l[0],l[1],l[2]),h.push(u[0]*a,u[1]*a,u[2]*a)}}n.length===0&&(n.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,n.length/3),n.length>0&&(t.uniform3fv(e.uDirLightDir,n),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,o.length/3),o.length>0&&(t.uniform3fv(e.uPointLightPos,o),t.uniform3fv(e.uPointLightColor,h)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of V)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of V)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let n=this.meshes.flatMap(a=>a.primitives.filter(l=>l.materialIndex===r||e.length===1&&l.materialIndex===void 0)),s=n[0],o=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],h=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,c=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,u={baseColorFactor:o,metallicFactor:h,roughnessFactor:c,setBaseColorFactor:a=>{let l=[a[0],a[1],a[2],a[3]??1];u.baseColorFactor=l,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=l);for(let f of n)f.baseColor=l;this.render()},setMetallicFactor:a=>{u.metallicFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=a);for(let l of n)l.metallic=a;this.render()},setRoughnessFactor:a=>{u.roughnessFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=a);for(let l of n)l.roughness=a;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:u}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of V)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.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(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=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(t,Math.min(r,e))}setCamera(e,t,r,n){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),n!==void 0&&n>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/n))}setInitialCamera(e,t,r,n){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*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(n!==void 0&&n>0){let s=this.clampDistance(this.bounds.radius*2.5/n);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(e,t){let r=G();O(r,this.projMatrix,this.viewMatrix);let[n,s,o]=e,h=t?t[0]:0,c=t?t[1]:0,u=t?t[2]:0,a=this.modelRootMatrix;a&&(n=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],s=a[1]*e[0]+a[5]*e[1]+a[9]*e[2]+a[13],o=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]+a[14],t&&(h=a[0]*t[0]+a[4]*t[1]+a[8]*t[2],c=a[1]*t[0]+a[5]*t[1]+a[9]*t[2],u=a[2]*t[0]+a[6]*t[1]+a[10]*t[2]));let l=r[0]*n+r[4]*s+r[8]*o+r[12],f=r[1]*n+r[5]*s+r[9]*o+r[13],b=r[2]*n+r[6]*s+r[10]*o+r[14],p=r[3]*n+r[7]*s+r[11]*o+r[15];if(p<=1e-4)return{x:0,y:0,z:1,visible:!1};let T=l/p,M=f/p,D=b/p,E=this.canvas.getBoundingClientRect(),w=E.width||this.canvas.clientWidth||this.canvas.width||300,v=E.height||this.canvas.clientHeight||this.canvas.height||150,d=(T*.5+.5)*w,m=(-M*.5+.5)*v,C=T>=-1.1&&T<=1.1&&M>=-1.1&&M<=1.1&&D>=-1&&D<=1;if(C&&t){let P=this.customTarget||this.bounds.center,g=P[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),A=P[1]+this.currDistance*Math.sin(this.currPhi),L=P[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),F=[n-g,s-A,o-L];h*F[0]+c*F[1]+u*F[2]>.05&&(C=!1)}return{x:d,y:m,z:D,visible:C}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},n=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(n,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let o=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],h=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],c=this.customTarget?[...this.customTarget]:[...this.bounds.center],u=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;c[0]+=(-n*o[0]+s*h[0])*u,c[1]+=(-n*o[1]+s*h[1])*u,c[2]+=(-n*o[2]+s*h[2])*u,this.customTarget=c}else this.targetTheta=this.clampTheta(this.targetTheta-n*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),n=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(n,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.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),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.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(e,t){let r=this.canvas,n=r.getBoundingClientRect(),s=r.width||300,o=r.height||300,h=n.width>0?Math.floor((e-n.left)*(s/n.width)):Math.floor(e),c=n.height>0?Math.floor((t-n.top)*(o/n.height)):Math.floor(t);return this.performMeshPick(h,c,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let n=this.gl,s=Math.max(1,this.canvas.width||300),o=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let h=G();O(h,this.projMatrix,this.viewMatrix);let c=[],u=Math.max(0,Math.min(s-1,e)),a=Math.max(0,Math.min(o-1,o-1-t));if(this.pickFbo&&n&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==o)&&this.resizePickingFbo(s,o),n.bindFramebuffer(36160,this.pickFbo),n.viewport(0,0,s,o),n.enable(2929),n.clearColor(0,0,0,0),n.clear(16384|256),n.useProgram(this.pickProg);for(let C=0;C<this.meshes.length;C++){let P=this.meshes[C];if(P.visible===!1||P.isPluginMesh)continue;let g=C+1,A=(g&255)/255,L=(g>>8&255)/255,F=(g>>16&255)/255;n.uniform4f(this.uPick.uColorId,A,L,F,1),O(this.modelMatrix,this.modelRootMatrix,P.transform),O(this.mvpMatrix,h,this.modelMatrix),n.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let y of P.primitives)n.bindVertexArray(y.vao),n.drawElements(4,y.indexCount,y.indexType,0)}let d=new Uint8Array(4);n.readPixels(u,a,1,1,6408,5121,d),n.bindFramebuffer(36160,null);let m=d[0]+(d[1]<<8)+(d[2]<<16);m>0&&m<=this.meshes.length&&(c=[this.meshes[m-1]])}c.length===0&&(c=this.meshes.filter(d=>d.visible!==!1));let l=null,f=1/0,b=[0,0,0],p=[0,1,0],T=this.customTarget||this.bounds.center,M=T[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),D=T[1]+this.currDistance*Math.sin(this.currPhi),E=T[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let d of c){O(this.modelMatrix,this.modelRootMatrix,d.transform),O(this.mvpMatrix,h,this.modelMatrix);let m=G();if(!ye(m,this.mvpMatrix))continue;let C=(u+.5)/s*2-1,P=(a+.5)/o*2-1,g=[0,0,0],A=[0,0,0];be(g,C,P,-1,m),be(A,C,P,1,m);let L=A[0]-g[0],F=A[1]-g[1],y=A[2]-g[2],R=Math.hypot(L,F,y)||1,B=L/R,x=F/R,X=y/R,k={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((U=>{for(let H of d.primitives){if(!H.positions)continue;let N=H.positions,I=H.indices,_=Math.floor(I?I.length/3:N.length/9);for(let W=0;W<_;W++){let K=I?I[W*3]:W*3,q=I?I[W*3+1]:W*3+1,$=I?I[W*3+2]:W*3+2;Te(g[0],g[1],g[2],B,x,X,N[K*3],N[K*3+1],N[K*3+2],N[q*3],N[q*3+1],N[q*3+2],N[$*3],N[$*3+1],N[$*3+2],k,U)}}})(1e-4),isFinite(k.distance)){let U=k.point[0],H=k.point[1],N=k.point[2],I=this.modelMatrix,_=I[0]*U+I[4]*H+I[8]*N+I[12],W=I[1]*U+I[5]*H+I[9]*N+I[13],K=I[2]*U+I[6]*H+I[10]*N+I[14],q=_-M,$=W-D,de=K-E,z=Math.hypot(q,$,de);if(z<f){te(this.normalMatrix,this.modelMatrix);let Y=this.normalMatrix,oe=k.normal[0],ue=k.normal[1],ne=k.normal[2],J=Y[0]*oe+Y[3]*ue+Y[6]*ne,Q=Y[1]*oe+Y[4]*ue+Y[7]*ne,ee=Y[2]*oe+Y[5]*ue+Y[8]*ne,ce=Math.hypot(J,Q,ee)||1;J/=ce,Q/=ce,ee/=ce,J*q+Q*$+ee*de>0&&(J=-J,Q=-Q,ee=-ee),l=d,f=Math.round(z*1e3)/1e3,b=[Math.round(_*1e3)/1e3,Math.round(W*1e3)/1e3,Math.round(K*1e3)/1e3],p=[Math.round(J*1e3)/1e3,Math.round(Q*1e3)/1e3,Math.round(ee*1e3)/1e3]}}}if(!l)return null;let v={meshIndex:this.meshes.indexOf(l),meshName:l.name,nodeIndex:l.nodeIndex,distance:f,hitPoint:b,normal:p,screenX:e,screenY:t};if(r){for(let d of V)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(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),n=e>=r,s=n?e-r:e,o=n?Math.max(1,t-r):r,h=(s+.5)/o*2-1;return Math.floor((h*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);he(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center,n=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=r[1]+this.currDistance*Math.sin(this.currPhi),o=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);le(this.viewMatrix,[n,s,o],r,[0,1,0]),O(this.mvpMatrix,this.projMatrix,this.viewMatrix),te(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),n=Math.max(1,Math.floor(t.height*e));this.canvas.width!==r||this.canvas.height!==n?(this.canvas.width=r,this.canvas.height=n,this.resizePickingFbo(r,n),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let r of V)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(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of V)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(n){this.reportRenderError(n)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],n=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=r-(e*r+t*n),s[13]=0,s[14]=n-(-t*r+e*n),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let o of V)o.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let o of V)o.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),n=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(n-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=n,this.lastReportedZoom=s;let o={theta:r,phi:n,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(o),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:o}))}}renderXRView(e,t,r,n,s=!0,o=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let h=e?.transform?.inverse?.matrix||this.viewMatrix,c=e?.projectionMatrix||this.projMatrix,u=e?.transform?.position,a=u?[u.x,u.y,u.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:h,projMatrix:c,eyePos:a,viewport:n,eye:e?.eye||"none",clear:o>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&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)),C=Math.max(1,v-m),P=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),g=this.customTarget||this.bounds.center,A=g[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),L=g[1]+this.currDistance*Math.sin(this.currPhi),F=g[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),y=Math.cos(this.currTheta),R=-Math.sin(this.currTheta),B=.032,x=G(),X=G(),k=[A-y*B,L,F-R*B],ie=[g[0]-y*B*.25,g[1],g[2]-R*B*.25];he(x,this.fov,m/d,.1,P),le(X,k,ie,[0,1,0]);let U=G(),H=G(),N=[A+y*B,L,F+R*B],I=[g[0]+y*B*.25,g[1],g[2]+R*B*.25];he(U,this.fov,C/d,.1,P),le(H,N,I,[0,1,0]),this.render({viewMatrix:X,projMatrix:x,eyePos:k,viewport:[0,0,m,d],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:H,projMatrix:U,eyePos:N,viewport:[m,0,C,d],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,d);return}let t=this.gl,r=0,n=0,s=this.canvas.width,o=this.canvas.height;e?.viewport?(r=e.viewport[0],n=e.viewport[1],s=e.viewport[2],o=e.viewport[3],t.viewport(r,n,s,o)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let h=G(),c=e?.viewMatrix??this.viewMatrix;O(h,e?.projMatrix??this.projMatrix,c);let u=[-c[2],-c[6],-c[10]],a=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,l=this.customTarget||this.bounds.center,f=e?e.eyePos[0]:l[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),b=e?e.eyePos[1]:l[1]+this.currDistance*Math.sin(this.currPhi),p=e?e.eyePos[2]:l[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let v of V)v.onBeforeDrawScene?.(this,t,h,[f,b,p],a);let T=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&T===0)return;let M=e?.eye||"none",D=!1,E=T>0?[...this.backdropMeshes,...this.meshes]:this.meshes,w=v=>{for(let d=0;d<E.length;d++){let m=E[d];if(m.visible===!1)continue;let C=this.selectedMeshName!==""&&m.name===this.selectedMeshName;d<T||m.worldSpace===!0||m.name==="__xr_reticle__"?this.modelMatrix.set(m.transform):O(this.modelMatrix,this.modelRootMatrix,m.transform),O(this.mvpMatrix,h,this.modelMatrix),te(m.normalMatrix,this.modelMatrix);let P=m.extras?.xr?.stereo||m.userData?.xr?.stereo,g=0,A=0,L=1,F=1;P==="sbs"?(L=.5,g=M==="right"?.5:0):P==="ou"&&(F=.5,A=M==="right"?.5:0);for(let y of m.primitives){let R=!!y.isTransmissive;if(!v&&R){D=!0;continue}if(v&&!R)continue;let B=y.customProgram||this.renderProg,x=y.customUniforms||this.uRender;t.useProgram(B),t.uniform1i(x.uToneMapping,a),t.uniform1f(x.uEnvIntensity,this.envIntensity),t.uniform3f(x.uCameraPos,f,b,p),x.uCameraFwd&&t.uniform3f(x.uCameraFwd,u[0],u[1],u[2]),t.uniform1f(x.uEmissive,C?1:0),t.uniformMatrix4fv(x.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(x.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(x.uNormalMatrix,!1,m.normalMatrix),x.uUvTransform&&t.uniform4f(x.uUvTransform,g,A,L,F),x.uViewportSize&&t.uniform2f(x.uViewportSize,Math.max(1,s),Math.max(1,o)),x.uViewport&&t.uniform4f(x.uViewport,r,n,Math.max(1,s),Math.max(1,o)),this.xrDepthState.enabled&&this.xrDepthState.texture?(t.activeTexture(33989),t.bindTexture(3553,this.xrDepthState.texture),x.uXrDepthTex&&t.uniform1i(x.uXrDepthTex,5),x.uXrDepthEnabled&&t.uniform1i(x.uXrDepthEnabled,1),x.uXrDepthFormat&&t.uniform1i(x.uXrDepthFormat,this.xrDepthState.format||0),x.uXrRawValueToMeters&&t.uniform1f(x.uXrRawValueToMeters,this.xrDepthState.rawValueToMeters),x.uXrDepthUVTransform&&t.uniformMatrix4fv(x.uXrDepthUVTransform,!1,this.xrDepthState.uvTransform)):x.uXrDepthEnabled&&t.uniform1i(x.uXrDepthEnabled,0),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(x.uEnvironmentMap,4),t.uniform1i(x.uHasEnvironmentMap,1)):t.uniform1i(x.uHasEnvironmentMap,0),this.bindLights(x);for(let X of V)X.onBeforeDrawPrimitive?.(t,B,y,m,this.worldMatrices||[],this.gltf);t.uniform4fv(x.uBaseColor,y.baseColor),t.uniform1f(x.uMetallic,y.metallic),t.uniform1f(x.uRoughness,y.roughness),x.uClearcoat&&t.uniform2f(x.uClearcoat,y.clearcoat??0,y.clearcoatRoughness??.04),y.texture?(t.activeTexture(33984),t.bindTexture(3553,y.texture),t.uniform1i(x.uBaseColorTexture,0),t.uniform1i(x.uHasTexture,1)):t.uniform1i(x.uHasTexture,0),y.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,y.metallicRoughnessTexture),t.uniform1i(x.uMetallicRoughnessTexture,1),t.uniform1i(x.uHasMetallicRoughnessTexture,1)):t.uniform1i(x.uHasMetallicRoughnessTexture,0),y.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,y.normalTexture),t.uniform1i(x.uNormalTexture,2),t.uniform1i(x.uHasNormalTexture,1),t.uniform1f(x.uNormalScale,y.normalScale)):t.uniform1i(x.uHasNormalTexture,0),y.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,y.occlusionTexture),t.uniform1i(x.uOcclusionTexture,3),t.uniform1i(x.uHasOcclusionTexture,1),t.uniform1f(x.uOcclusionStrength,y.occlusionStrength)):t.uniform1i(x.uHasOcclusionTexture,0),t.bindVertexArray(y.vao),t.drawElements(4,y.indexCount,y.indexType,0)}}};if(w(!1),D){for(let v of V)v.onBeforeTransmissivePass?.(t,this);w(!0)}for(let v of V)v.onAfterRender?.(t,this,h)}disposeMeshListGpuResources(e){let t=this.gl;for(let r of e)for(let n of r.primitives){if(n.vao&&t.deleteVertexArray(n.vao),n.buffers)for(let s of n.buffers)t.deleteBuffer(s);n.texture&&t.deleteTexture(n.texture),n.metallicRoughnessTexture&&t.deleteTexture(n.metallicRoughnessTexture),n.normalTexture&&t.deleteTexture(n.normalTexture),n.occlusionTexture&&t.deleteTexture(n.occlusionTexture),n.customProgram&&t.deleteProgram(n.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of V)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};se.registerPlugin=Re,se.getRegisteredPlugins=De;var it=se;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview Ambient and module declarations for three-live and xr-live.
|
|
17
|
+
* Enables zero-config, type-safe usage of <three-live> and <xr-live> in React 19,
|
|
18
|
+
* Next.js, Vue, Svelte, and modern TSX/JSX environments.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type {
|
|
22
|
+
CameraState,
|
|
23
|
+
ThreeLiveElement,
|
|
24
|
+
} from './three-live/src/three-live-element';
|
|
25
|
+
import type {
|
|
26
|
+
CameraDetail,
|
|
27
|
+
GLBData,
|
|
28
|
+
HitDetail,
|
|
29
|
+
ThreeView,
|
|
30
|
+
} from './three-live/src/three-view';
|
|
31
|
+
import type {ARLaunchResult, ARMode} from './three-live/src/three-xr';
|
|
32
|
+
import type {TranscriptEvent} from './xr-live/src/plugins/gemini-live';
|
|
33
|
+
import type {Detection3D} from './xr-live/src/plugins/world-understanding';
|
|
34
|
+
import type {
|
|
35
|
+
XRAnchorElement,
|
|
36
|
+
XRDepthMode,
|
|
37
|
+
XRHandsMode,
|
|
38
|
+
XRLiveElement,
|
|
39
|
+
XRMode,
|
|
40
|
+
XRProfile,
|
|
41
|
+
XRSimulatorRoom,
|
|
42
|
+
} from './xr-live/src/xr-live-element';
|
|
43
|
+
|
|
44
|
+
export * from './three-live/src/core';
|
|
45
|
+
export {
|
|
46
|
+
getInteractivityVM,
|
|
47
|
+
interactivityPlugin,
|
|
48
|
+
InteractivityVM,
|
|
49
|
+
parseSafeGltfPointer,
|
|
50
|
+
sendInteractivityEvent,
|
|
51
|
+
type InteractivityDeclaration,
|
|
52
|
+
type InteractivityEventDef,
|
|
53
|
+
type InteractivityFlowTarget,
|
|
54
|
+
type InteractivityGraph,
|
|
55
|
+
type InteractivityNode,
|
|
56
|
+
type InteractivityValue,
|
|
57
|
+
type InteractivityValueSocket,
|
|
58
|
+
type InteractivityVariableDef,
|
|
59
|
+
} from './three-live/src/plugins/interactivity';
|
|
60
|
+
export {
|
|
61
|
+
ThreeLiveElement,
|
|
62
|
+
type ARLaunchOptions,
|
|
63
|
+
type ARLaunchResult,
|
|
64
|
+
type ARMode,
|
|
65
|
+
type ARProvider,
|
|
66
|
+
type CameraState,
|
|
67
|
+
} from './three-live/src/three-live-element';
|
|
68
|
+
export {
|
|
69
|
+
XRAnchorElement,
|
|
70
|
+
XRLiveElement,
|
|
71
|
+
type XRDepthMode,
|
|
72
|
+
type XRHandsMode,
|
|
73
|
+
type XRMode,
|
|
74
|
+
type XRProfile,
|
|
75
|
+
type XRSimulatorRoom,
|
|
76
|
+
} from './xr-live/src/xr-live-element';
|
|
77
|
+
/** Optional spatial plugins (`xr-live/plugins`, `xr-live-plugins.min.js`). */
|
|
78
|
+
export * from './xr-live/src/plugins/index';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Declarative JSX / HTML attributes supported by the <three-live> custom element.
|
|
82
|
+
*/
|
|
83
|
+
export interface ThreeLiveAttributes {
|
|
84
|
+
/** URL to glTF 2.0 binary (.glb) model. */
|
|
85
|
+
'src'?: string;
|
|
86
|
+
/** URL to Apple Universal Scene Description (.usdz) model for iOS Quick Look. */
|
|
87
|
+
'ios-src'?: string;
|
|
88
|
+
/** URL or inline script for procedural Three.js scene generation. */
|
|
89
|
+
'script-src'?: string;
|
|
90
|
+
/** Responsive image preview shown before 3D model finishes hydration. */
|
|
91
|
+
'poster'?: string;
|
|
92
|
+
/** Uniform or per-axis scale multiplier ("x y z"). */
|
|
93
|
+
'scale'?: string;
|
|
94
|
+
/** Initial camera orbit angles and distance: "theta phi [radius]" (e.g. "0deg 75deg 3m") or JSON string. */
|
|
95
|
+
'camera-orbit'?: string | CameraState;
|
|
96
|
+
/** Orbit center coordinate "x y z". */
|
|
97
|
+
'camera-target'?: string;
|
|
98
|
+
/** Lower bounds for camera orbit ("theta phi radius"). */
|
|
99
|
+
'min-camera-orbit'?: string;
|
|
100
|
+
/** Upper bounds for camera orbit ("theta phi radius"). */
|
|
101
|
+
'max-camera-orbit'?: string;
|
|
102
|
+
/** Vertical field of view angle (e.g. "45deg"). */
|
|
103
|
+
'field-of-view'?: string;
|
|
104
|
+
/** Sub-mesh name to highlight with interactive selection color. */
|
|
105
|
+
'selected-mesh'?: string;
|
|
106
|
+
/** Exposure / lighting multiplier for studio IBL lighting (default: 1.0). */
|
|
107
|
+
'exposure'?: number | string;
|
|
108
|
+
/** Equirectangular HDR/LDR environment map URL. */
|
|
109
|
+
'environment-image'?: string;
|
|
110
|
+
/** Visible background equirectangular skybox image URL. */
|
|
111
|
+
'skybox-image'?: string;
|
|
112
|
+
/** Ground contact shadow opacity (0.0 to 1.0). */
|
|
113
|
+
'shadow-intensity'?: number | string;
|
|
114
|
+
/** Radial Gaussian blur falloff of contact shadow (0.0 to 1.0). */
|
|
115
|
+
'shadow-softness'?: number | string;
|
|
116
|
+
/** Tone mapping mode ("neutral", "reinhard", "none"). */
|
|
117
|
+
'tone-mapping'?: string;
|
|
118
|
+
/** Enable or disable interactive camera orbit/pan/zoom controls (default: true). */
|
|
119
|
+
'camera-controls'?: boolean | string;
|
|
120
|
+
/** Automatically start keyframe animation playback. */
|
|
121
|
+
'autoplay'?: boolean | string;
|
|
122
|
+
/** Name of specific glTF animation clip to play. */
|
|
123
|
+
'animation-name'?: string;
|
|
124
|
+
/** Automatically rotate scene around the Y-axis when user is idle. */
|
|
125
|
+
'auto-rotate'?: boolean | string;
|
|
126
|
+
/** Delay in milliseconds before auto-rotation resumes after user interaction (default: 3000). */
|
|
127
|
+
'auto-rotate-delay'?: number | string;
|
|
128
|
+
/** Rate of turntable auto-rotation (e.g. "30deg", "0.5rad", "100%", default: "30deg"). */
|
|
129
|
+
'rotation-per-second'?: string;
|
|
130
|
+
/** Enable one-tap Augmented Reality button overlay. */
|
|
131
|
+
'ar'?: boolean | string;
|
|
132
|
+
/** Ordered list of AR launch targets ('webxr', 'quick-look', 'scene-viewer'). */
|
|
133
|
+
'ar-modes'?: string;
|
|
134
|
+
/** Controls whether the model can be scaled in AR ("auto" or "fixed"). */
|
|
135
|
+
'ar-scale'?: 'auto' | 'fixed';
|
|
136
|
+
/** Controls whether the model is placed on horizontal surfaces ("floor") or vertical surfaces ("wall"). */
|
|
137
|
+
'ar-placement'?: 'floor' | 'wall';
|
|
138
|
+
/**
|
|
139
|
+
* Mandatory isolation level for procedural scripts. Defaults to `'worker'`,
|
|
140
|
+
* which runs the script in a dedicated Web Worker with network, storage and
|
|
141
|
+
* thread-spawning capabilities revoked across the prototype chain. `'iframe'`
|
|
142
|
+
* runs the Worker inside an opaque-origin `<iframe sandbox="allow-scripts">`
|
|
143
|
+
* (`three-live-sandbox.html`) with a strict `connect-src 'none'` Content
|
|
144
|
+
* Security Policy.
|
|
145
|
+
*/
|
|
146
|
+
sandbox?: 'worker' | 'iframe';
|
|
147
|
+
/**
|
|
148
|
+
* Opt-in attribute allowing client-modified Three.js script strings
|
|
149
|
+
* (`executeScript(code)` and inline `<script type="text/three-live">`).
|
|
150
|
+
* Server-generated scripts (`script-src`) are enabled by default.
|
|
151
|
+
*/
|
|
152
|
+
'allow-client-scripts'?: boolean | string;
|
|
153
|
+
|
|
154
|
+
// React 19 / JSX Event Listeners
|
|
155
|
+
onload?: (e: CustomEvent<{model: GLBData}>) => void;
|
|
156
|
+
onerror?: (e: CustomEvent<{error: any}>) => void;
|
|
157
|
+
onmeshclick?: (e: CustomEvent<HitDetail>) => void;
|
|
158
|
+
'oncamera-change'?: (e: CustomEvent<CameraDetail>) => void;
|
|
159
|
+
'onar-status'?: (
|
|
160
|
+
e: CustomEvent<{
|
|
161
|
+
status: 'session-started' | 'not-presenting' | 'failed';
|
|
162
|
+
error?: any;
|
|
163
|
+
}>,
|
|
164
|
+
) => void;
|
|
165
|
+
|
|
166
|
+
// Standard HTML / JSX attributes
|
|
167
|
+
id?: string;
|
|
168
|
+
className?: string;
|
|
169
|
+
class?: string;
|
|
170
|
+
style?: any;
|
|
171
|
+
ref?: any;
|
|
172
|
+
key?: any;
|
|
173
|
+
slot?: string;
|
|
174
|
+
tabIndex?: number;
|
|
175
|
+
role?: string;
|
|
176
|
+
'aria-label'?: string;
|
|
177
|
+
children?: any;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Declarative JSX / HTML attributes supported by the <xr-live> spatial computing element.
|
|
182
|
+
*/
|
|
183
|
+
export interface XRLiveAttributes extends ThreeLiveAttributes {
|
|
184
|
+
/** WebXR session target mode ("ar", "vr", "inline", or "auto"). */
|
|
185
|
+
'xr-mode'?: XRMode;
|
|
186
|
+
/** Real-world hardware depth occlusion or physics mode ("occlusion", "occlusion-physics", "mesh", "none"). */
|
|
187
|
+
'xr-depth'?: XRDepthMode;
|
|
188
|
+
/** 25-joint hand tracking and gesture recognition mode ("gestures", "joints", "pinch", "none"). */
|
|
189
|
+
'xr-hands'?: XRHandsMode;
|
|
190
|
+
/** Desktop room simulator environment ("living-room", "office", "tabletop", "none"). */
|
|
191
|
+
'xr-simulator'?: XRSimulatorRoom;
|
|
192
|
+
/** Spatial UI profile ("quest3", "android-xr", "visionos", "auto"). */
|
|
193
|
+
'xr-profile'?: XRProfile;
|
|
194
|
+
/** Spatial plugin: enables plane/mesh detection; include "reticle" for a gaze reticle. */
|
|
195
|
+
'world-understanding'?: boolean | string;
|
|
196
|
+
/** Spatial plugin: pinch in empty space to paint 3D tubes (optional `#rrggbb` color). */
|
|
197
|
+
'spatial-paint'?: boolean | string;
|
|
198
|
+
'onxr-object-detected'?: (e: CustomEvent<Detection3D>) => void;
|
|
199
|
+
'onxr-transcription'?: (e: CustomEvent<TranscriptEvent>) => void;
|
|
200
|
+
'onxr-hold-to-ask'?: (
|
|
201
|
+
e: CustomEvent<{mesh: string; transcript: string; prompt: string}>,
|
|
202
|
+
) => void;
|
|
203
|
+
'onxr-handles-change'?: (
|
|
204
|
+
e: CustomEvent<{mesh: string; scale: number; yawDeg: number}>,
|
|
205
|
+
) => void;
|
|
206
|
+
'onxr-paint-stroke'?: (
|
|
207
|
+
e: CustomEvent<{index: number; points: number; lengthMeters: number}>,
|
|
208
|
+
) => void;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare global {
|
|
212
|
+
namespace JSX {
|
|
213
|
+
interface IntrinsicElements {
|
|
214
|
+
'three-live': ThreeLiveAttributes;
|
|
215
|
+
'xr-live': XRLiveAttributes;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
interface HTMLElementTagNameMap {
|
|
220
|
+
'three-live': ThreeLiveElement;
|
|
221
|
+
'xr-live': XRLiveElement;
|
|
222
|
+
'xr-anchor': XRAnchorElement;
|
|
223
|
+
}
|
|
224
|
+
}
|