three-live 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/index.d.ts +182 -6
- package/dist/three-author-engine.js +66 -41
- package/dist/three-author.cjs +63 -39
- package/dist/three-author.d.ts +182 -6
- package/dist/three-author.js +63 -39
- package/dist/three-convert.cjs +61 -37
- package/dist/three-convert.d.ts +182 -6
- package/dist/three-convert.js +61 -37
- package/dist/three-live-animation.cjs +7 -7
- package/dist/three-live-animation.d.ts +182 -6
- package/dist/three-live-animation.js +7 -7
- package/dist/three-live-animation.min.js +7 -7
- package/dist/three-live-cad.cjs +18 -0
- package/dist/{three-live-extras.d.ts → three-live-cad.d.ts} +182 -6
- package/dist/three-live-cad.js +18 -0
- package/dist/three-live-cad.min.js +18 -0
- package/dist/three-live-element.cjs +29 -5
- package/dist/three-live-element.d.ts +182 -6
- package/dist/three-live-element.js +29 -5
- package/dist/three-live-full.cjs +159 -56
- package/dist/three-live-full.js +159 -56
- package/dist/three-live-full.min.js +159 -56
- package/dist/three-live-studio.cjs +120 -0
- package/dist/three-live-studio.d.ts +509 -0
- package/dist/three-live-studio.js +120 -0
- package/dist/three-live-studio.min.js +120 -0
- package/dist/three-live-viewer.cjs +29 -5
- package/dist/three-live-viewer.d.ts +182 -6
- package/dist/three-live-viewer.js +29 -5
- package/dist/three-live-viewer.min.js +29 -5
- package/dist/three-live.cjs +66 -42
- package/dist/three-live.js +66 -42
- package/dist/three-live.min.js +66 -42
- package/dist/three-view.cjs +29 -5
- package/dist/three-view.d.ts +182 -6
- package/dist/three-view.js +29 -5
- package/dist/three-xr.cjs +65 -41
- package/dist/three-xr.d.ts +182 -6
- package/dist/three-xr.js +65 -41
- package/package.json +10 -5
- package/dist/three-live-extras.cjs +0 -42
- package/dist/three-live-extras.js +0 -42
- package/dist/three-live-extras.min.js +0 -42
package/dist/three-convert.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
function Pe(n,e,t){let i=[],r=new Map,s=[],l=[],y=[],u=new Map,a=f=>{let v=r.get(f);return v===void 0&&(v=i.length,i.push({op:f}),r.set(f,v)),v},o=f=>{let v=u.get(f);return v===void 0&&(v=y.length,y.push({id:f}),u.set(f,v)),v},m=(f,v={})=>s.push({declaration:a(f),...v})-1,T=(f,v,p)=>l.push({id:f,type:v,value:p})-1,M=f=>({node:f,socket:"value"}),h=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(h&&typeof h=="object"){let f=Array.isArray(h.graphs)?h.graphs[h.graph??0]:h;if(f&&Array.isArray(f.nodes)){let v=Array.isArray(f.declarations)?f.declarations:[];for(let p of v)p?.op&&a(p.op);Array.isArray(f.variables)&&l.push(...f.variables);for(let p of f.events||[])p?.id&&o(p.id);for(let p of f.nodes){if(!p||typeof p!="object")continue;let w=p.op||(typeof p.declaration=="number"?v[p.declaration]?.op:"");s.push(w?{...p,declaration:a(w)}:{...p})}}}let E=(f,v,p="translation")=>p==="baseColorFactor"||p==="metallicFactor"||p==="roughnessFactor"?`/materials/${Math.max(0,v)}/pbrMetallicRoughness/${p}`:p==="emissiveFactor"||p==="alphaCutoff"?`/materials/${Math.max(0,v)}/${p}`:p==="visible"?`/nodes/${f}/extensions/KHR_node_visibility/visible`:`/nodes/${f}/${p}`,D=new Map;n.forEach((f,v)=>{typeof f?.name=="string"&&!D.has(f.name)&&D.set(f.name,v)});let F=(f,v)=>typeof f.target=="string"&&D.has(f.target)?D.get(f.target):typeof f.targetNode=="number"?f.targetNode:v,C=f=>{let v=n[f];return(typeof v?.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0};for(let f=0;f<n.length;f++){let v=n[f],p=v?.extras?.interactivity;if(!p||typeof p!="object")continue;let w=(typeof v.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0,c=b=>{let A=Array.isArray(b)?b:[b],P=[];for(let g=0;g<A.length;g++){let d=A[g];if(!d||typeof d!="object")continue;let U=d.action||"interpolate",S=typeof d.duration=="number"?d.duration:.35;if(U==="toggleTransform"){let V=d.property==="rotation"||d.property==="scale"?d.property:"translation",G=V==="rotation"?v.rotation||[0,0,0,1]:V==="scale"?v.scale||[1,1,1]:v.translation||[0,0,0],L=`/nodes/${f}/${V}`,_=T(`__toggle_${f}_${g}`,"bool",!1),R=m("variable/get",{configuration:{variable:_}}),k=m("math/not",{values:{a:M(R)}}),N=m("variable/set",{configuration:{variable:_},values:{value:M(k)}}),O=m("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:Array.isArray(d.to)?d.to:G},duration:{value:S}}}),B=m("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:Array.isArray(d.from)?d.from:G},duration:{value:S}}});s[N].flows={out:{node:m("flow/branch",{values:{condition:M(R)},flows:{true:{node:O},false:{node:B}}})}},P.push(N)}else if(U==="interpolate"){let V=d.to??d.value;if(V===void 0)continue;let G={value:{value:V},duration:{value:S}};d.from!==void 0&&(G.from={value:d.from}),P.push(m("pointer/interpolate",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:E(F(d,f),C(F(d,f)),d.property)},values:G}))}else if(U==="setProperty"){if(d.value===void 0)continue;P.push(m("pointer/set",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:E(F(d,f),C(F(d,f)),d.property)},values:{value:{value:d.value}}}))}else if(U==="toggleVisibility"){let V=F(d,f),G=T(`__vis_${V}_${g}`,"bool",!0),L=m("variable/get",{configuration:{variable:G}}),_=m("math/not",{values:{a:M(L)}}),R=m("variable/set",{configuration:{variable:G},values:{value:M(_)}});s[R].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:M(L)}})}},P.push(R)}else if(U==="cycleMaterialColor"&&Array.isArray(d.colors)&&d.colors.length>0){let V=typeof d.duration=="number"?d.duration:.25,G=`/materials/${Math.max(0,w)}/pbrMetallicRoughness/baseColorFactor`,L=T(`__color_idx_${f}_${g}`,"int",0),_=m("variable/get",{configuration:{variable:L}}),R=m("math/add",{values:{a:M(_),b:{value:1}}}),k=m("math/rem",{values:{a:M(R),b:{value:d.colors.length}}}),N=m("variable/set",{configuration:{variable:L},values:{value:M(k)}}),O={};for(let B=0;B<d.colors.length;B++){let H=d.colors[B],W=Array.isArray(H)&&H.length>=3?[H[0],H[1],H[2],H[3]??1]:[1,1,1,1];O[String(B)]={node:V>0?m("pointer/interpolate",{configuration:{pointer:G},values:{value:{value:W},duration:{value:V}}}):m("pointer/set",{configuration:{pointer:G},values:{value:{value:W}}})}}s[N].flows={out:{node:m("flow/switch",{values:{selection:M(_)},flows:O})}},P.push(N)}else if(U==="playAnimation")P.push(m("animation/start",{configuration:{animation:d.animation??d.clip??0}}));else if(U==="stopAnimation")P.push(m("animation/stop"));else if(U==="sendEvent"){let V={};for(let[G,L]of Object.entries(d.values||{}))V[G]={value:L};P.push(m("event/send",{configuration:{event:o(String(d.event??d.id??"custom"))},values:V}))}}if(!P.length)return null;if(P.length===1)return P[0];let I={};return P.forEach((g,d)=>{I[String(d)]={node:g}}),m("flow/sequence",{flows:I})},x=(b,A,P)=>{let I=c(A);I!==null&&m(b,{...P?{configuration:P}:{},flows:{out:{node:I}}})};if(p.onSelect&&x("pointer/onSelect",p.onSelect,{nodeIndex:f}),p.onHoverIn&&x("pointer/onHoverIn",p.onHoverIn,{nodeIndex:f}),p.onHoverOut&&x("pointer/onHoverOut",p.onHoverOut,{nodeIndex:f}),p.onStart&&x("event/onStart",p.onStart),p.onReceive&&typeof p.onReceive=="object")for(let[b,A]of Object.entries(p.onReceive))x("event/receive",A,{event:o(b)})}return s.length?{graphs:[{declarations:i,nodes:s,variables:l,events:y}],graph:0}:null}var pe="__THREE_LIVE_REGISTRY__";function ee(){let n=typeof globalThis<"u"?globalThis:{};if(!n[pe]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,pe,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[pe]=e}}return n[pe]}var Y=ee().plugins;function Se(n){let e=ee().plugins;e.some(t=>t.name===n.name)||e.push(n)}function Fe(){return ee().plugins}function q(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function be(n,e,t,i,r){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let l=1/(i-r);return n[10]=(r+i)*l,n[14]=2*r*i*l,n}function ge(n,e,t,i){let[r,s,l]=e,[y,u,a]=i,[o,m,T]=t,M=r-o,h=s-m,E=l-T,D=Math.hypot(M,h,E);D<=1e-5?(M=0,h=0,E=1):(M/=D,h/=D,E/=D);let F=u*E-a*h,C=a*M-y*E,f=y*h-u*M;D=Math.hypot(F,C,f),D<=1e-5?(F=0,C=0,f=0):(F/=D,C/=D,f/=D);let v=h*f-E*C,p=E*F-M*f,w=M*C-h*F;return D=Math.hypot(v,p,w),D<=1e-5?(v=0,p=0,w=0):(v/=D,p/=D,w/=D),n[0]=F,n[1]=v,n[2]=M,n[3]=0,n[4]=C,n[5]=p,n[6]=h,n[7]=0,n[8]=f,n[9]=w,n[10]=E,n[11]=0,n[12]=-(F*r+C*s+f*l),n[13]=-(v*r+p*s+w*l),n[14]=-(M*r+h*s+E*l),n[15]=1,n}function J(n,e,t){let i=e[0],r=e[1],s=e[2],l=e[3],y=e[4],u=e[5],a=e[6],o=e[7],m=e[8],T=e[9],M=e[10],h=e[11],E=e[12],D=e[13],F=e[14],C=e[15],f=t[0],v=t[1],p=t[2],w=t[3];return n[0]=f*i+v*y+p*m+w*E,n[1]=f*r+v*u+p*T+w*D,n[2]=f*s+v*a+p*M+w*F,n[3]=f*l+v*o+p*h+w*C,f=t[4],v=t[5],p=t[6],w=t[7],n[4]=f*i+v*y+p*m+w*E,n[5]=f*r+v*u+p*T+w*D,n[6]=f*s+v*a+p*M+w*F,n[7]=f*l+v*o+p*h+w*C,f=t[8],v=t[9],p=t[10],w=t[11],n[8]=f*i+v*y+p*m+w*E,n[9]=f*r+v*u+p*T+w*D,n[10]=f*s+v*a+p*M+w*F,n[11]=f*l+v*o+p*h+w*C,f=t[12],v=t[13],p=t[14],w=t[15],n[12]=f*i+v*y+p*m+w*E,n[13]=f*r+v*u+p*T+w*D,n[14]=f*s+v*a+p*M+w*F,n[15]=f*l+v*o+p*h+w*C,n}function Le(n,e,t,i){let r=e[0],s=e[1],l=e[2],y=e[3],u=r+r,a=s+s,o=l+l,m=r*u,T=r*a,M=r*o,h=s*a,E=s*o,D=l*o,F=y*u,C=y*a,f=y*o,v=i[0],p=i[1],w=i[2];return n[0]=(1-(h+D))*v,n[1]=(T+f)*v,n[2]=(M-C)*v,n[3]=0,n[4]=(T-f)*p,n[5]=(1-(m+D))*p,n[6]=(E+F)*p,n[7]=0,n[8]=(M+C)*w,n[9]=(E-F)*w,n[10]=(1-(m+h))*w,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function te(n,e){let t=e[0],i=e[1],r=e[2],s=e[4],l=e[5],y=e[6],u=e[8],a=e[9],o=e[10],m=o*l-y*a,T=-o*s+y*u,M=a*s-l*u,h=t*m+i*T+r*M;return h&&(h=1/h,n[0]=m*h,n[1]=(-o*i+r*a)*h,n[2]=(y*i-r*l)*h,n[3]=T*h,n[4]=(o*t-r*u)*h,n[5]=(-y*t+r*s)*h,n[6]=M*h,n[7]=(-a*t+i*u)*h,n[8]=(l*t-i*s)*h),n}function Ce(n,e){let t=e[0],i=e[1],r=e[2],s=e[3],l=e[4],y=e[5],u=e[6],a=e[7],o=e[8],m=e[9],T=e[10],M=e[11],h=e[12],E=e[13],D=e[14],F=e[15],C=t*y-i*l,f=t*u-r*l,v=t*a-s*l,p=i*u-r*y,w=i*a-s*y,c=r*a-s*u,x=o*E-m*h,b=o*D-T*h,A=o*F-M*h,P=m*D-T*E,I=m*F-M*E,g=T*F-M*D,d=C*g-f*I+v*P+p*A-w*b+c*x;return d?(d=1/d,n[0]=(y*g-u*I+a*P)*d,n[1]=(r*I-i*g-s*P)*d,n[2]=(E*c-D*w+F*p)*d,n[3]=(T*w-m*c-M*p)*d,n[4]=(u*A-l*g-a*b)*d,n[5]=(t*g-r*A+s*b)*d,n[6]=(D*v-h*c-F*f)*d,n[7]=(o*c-T*v+M*f)*d,n[8]=(l*I-y*A+a*x)*d,n[9]=(i*A-t*I-s*x)*d,n[10]=(h*w-E*v+F*C)*d,n[11]=(m*v-o*w-M*C)*d,n[12]=(y*b-l*P-u*x)*d,n[13]=(t*P-i*b+r*x)*d,n[14]=(E*f-h*p-D*C)*d,n[15]=(o*p-m*f+T*C)*d,n):null}function Me(n,e,t,i,r){let s=r[0]*e+r[4]*t+r[8]*i+r[12],l=r[1]*e+r[5]*t+r[9]*i+r[13],y=r[2]*e+r[6]*t+r[10]*i+r[14],u=r[3]*e+r[7]*t+r[11]*i+r[15],a=u!==0?1/u:1;n[0]=s*a,n[1]=l*a,n[2]=y*a}function Ie(n,e,t,i,r,s,l,y,u,a,o,m,T,M,h,E,D=0){let F=a-l,C=o-y,f=m-u,v=T-l,p=M-y,w=h-u,c=r*w-s*p,x=s*v-i*w,b=i*p-r*v,A=F*c+C*x+f*b;if(A>-1e-7&&A<1e-7)return!1;let P=1/A,I=n-l,g=e-y,d=t-u,U=P*(I*c+g*x+d*b);if(U<-D||U>1+D)return!1;let S=g*f-d*C,V=d*F-I*f,G=I*C-g*F,L=P*(i*S+r*V+s*G);if(L<-D||U+L>1+D)return!1;let _=P*(v*S+p*V+w*G);if(_>1e-4&&_<E.distance){E.distance=_,E.point=[n+i*_,e+r*_,t+s*_];let R=C*w-f*p,k=f*v-F*w,N=F*p-C*v,O=Math.hypot(R,k,N)||1;return E.normal=[R/O,k/O,N/O],!0}return!1}function ye(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,i=[];for(let o=0;o<t;o++)i.push(q());if(t===0)return i;let r=new Set;for(let o of n.nodes)if(Array.isArray(o.children))for(let m of o.children)r.add(m);let s=new Set,l=128,y=(o,m,T=0)=>{if(T>l||o<0||o>=t||s.has(o))return;s.add(o);let M=n.nodes[o];if(!M)return;let h=q();if(e&&e[o])h.set(e[o]);else if(M.matrix&&M.matrix.length===16)h.set(M.matrix);else{let D=M.translation||[0,0,0],F=M.rotation||[0,0,0,1],C=M.scale||[1,1,1];Le(h,F,D,C)}let E=i[o];if(m?J(E,m,h):E.set(h),Array.isArray(M.children))for(let D of M.children)typeof D=="number"&&y(D,E,T+1)},u=[],a=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(a&&Array.isArray(a.nodes))u.push(...a.nodes);else for(let o=0;o<t;o++)r.has(o)||u.push(o);for(let o of u)y(o,null);for(let o=0;o<t;o++)!r.has(o)&&!u.includes(o)&&y(o,null);return i}function Je(n){return new TextDecoder().decode(n)}var Ne=ee().decoders;function Qe(n,e){Ne.set(n.toLowerCase(),e)}function me(n){return Ne.get(n.toLowerCase())}function ke(n){let e=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let i=t.getUint32(0,!0);if(i!==1179937895){let T=t.getUint8(0);throw T===123||T===32||T===10||T===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${i.toString(16)}`)}let r=t.getUint32(4,!0);if(r!==2)throw new Error(`Unsupported GLB version: ${r}`);let s=t.getUint32(8,!0),l=12,y=null,u=null;for(;l+8<=s&&l+8<=e.byteLength;){let T=t.getUint32(l,!0),M=t.getUint32(l+4,!0),h=l+8;if(h+T>e.byteLength)throw new Error(`Truncated GLB chunk: required ${h+T} bytes, buffer has ${e.byteLength}`);if(M===1313821514){let E=new Uint8Array(e,h,T),D=Je(E);y=JSON.parse(D,(F,C)=>F==="__proto__"||F==="constructor"||F==="prototype"?void 0:C)}else M===5130562&&(u=e.slice(h,h+T));l=h+T}if(!y)throw new Error("Missing JSON chunk in GLB");let a=y.extensionsRequired||[];if(a.includes("KHR_draco_mesh_compression")&&!me("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(a.includes("EXT_meshopt_compression")&&!me("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(a.includes("KHR_texture_basisu")&&!me("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let o=u||new ArrayBuffer(0),m={gltf:y,bin:o,animations:[]};for(let T of Y)T.onParseGLB?.(m);return m}function et(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 he(n){if(et(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return ke(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Ge=`#version 300 es
|
|
17
|
+
function Ue(n,e,t){let i=[],r=new Map,s=[],a=[],b=[],l=new Map,o=h=>{let D=r.get(h);return D===void 0&&(D=i.length,i.push({op:h}),r.set(h,D)),D},c=h=>{let D=l.get(h);return D===void 0&&(D=b.length,b.push({id:h}),l.set(h,D)),D},m=(h,D={})=>s.push({declaration:o(h),...D})-1,E=(h,D,g)=>a.push({id:h,type:D,value:g})-1,P=h=>({node:h,socket:"value"}),M=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(M&&typeof M=="object"){let h=Array.isArray(M.graphs)?M.graphs[M.graph??0]:M;if(h&&Array.isArray(h.nodes)){let D=Array.isArray(h.declarations)?h.declarations:[];for(let g of D)g?.op&&o(g.op);Array.isArray(h.variables)&&a.push(...h.variables);for(let g of h.events||[])g?.id&&c(g.id);for(let g of h.nodes){if(!g||typeof g!="object")continue;let F=g.op||(typeof g.declaration=="number"?D[g.declaration]?.op:"");s.push(F?{...g,declaration:o(F)}:{...g})}}}let y=(h,D,g="translation")=>g==="baseColorFactor"||g==="metallicFactor"||g==="roughnessFactor"?`/materials/${Math.max(0,D)}/pbrMetallicRoughness/${g}`:g==="emissiveFactor"||g==="alphaCutoff"?`/materials/${Math.max(0,D)}/${g}`:g==="visible"?`/nodes/${h}/extensions/KHR_node_visibility/visible`:`/nodes/${h}/${g}`,R=new Map;n.forEach((h,D)=>{typeof h?.name=="string"&&!R.has(h.name)&&R.set(h.name,D)});let N=(h,D)=>typeof h.target=="string"&&R.has(h.target)?R.get(h.target):typeof h.targetNode=="number"?h.targetNode:D,B=h=>{let D=n[h];return(typeof D?.mesh=="number"?e[D.mesh]?.primitives?.[0]?.material:0)??0};for(let h=0;h<n.length;h++){let D=n[h],g=D?.extras?.interactivity;if(!g||typeof g!="object")continue;let F=(typeof D.mesh=="number"?e[D.mesh]?.primitives?.[0]?.material:0)??0,U=f=>{let A=Array.isArray(f)?f:[f],u=[];for(let d=0;d<A.length;d++){let p=A[d];if(!p||typeof p!="object")continue;let C=p.action||"interpolate",x=typeof p.duration=="number"?p.duration:.35;if(C==="toggleTransform"){let L=p.property==="rotation"||p.property==="scale"?p.property:"translation",I=L==="rotation"?D.rotation||[0,0,0,1]:L==="scale"?D.scale||[1,1,1]:D.translation||[0,0,0],H=`/nodes/${h}/${L}`,G=E(`__toggle_${h}_${d}`,"bool",!1),v=m("variable/get",{configuration:{variable:G}}),V=m("math/not",{values:{a:P(v)}}),k=m("variable/set",{configuration:{variable:G},values:{value:P(V)}}),O=m("pointer/interpolate",{configuration:{pointer:H},values:{value:{value:Array.isArray(p.to)?p.to:I},duration:{value:x}}}),W=m("pointer/interpolate",{configuration:{pointer:H},values:{value:{value:Array.isArray(p.from)?p.from:I},duration:{value:x}}});s[k].flows={out:{node:m("flow/branch",{values:{condition:P(v)},flows:{true:{node:O},false:{node:W}}})}},u.push(k)}else if(C==="interpolate"){let L=p.to??p.value;if(L===void 0)continue;let I={value:{value:L},duration:{value:x}};p.from!==void 0&&(I.from={value:p.from}),u.push(m("pointer/interpolate",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:y(N(p,h),B(N(p,h)),p.property)},values:I}))}else if(C==="setProperty"){if(p.value===void 0)continue;u.push(m("pointer/set",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:y(N(p,h),B(N(p,h)),p.property)},values:{value:{value:p.value}}}))}else if(C==="toggleVisibility"){let L=N(p,h),I=E(`__vis_${L}_${d}`,"bool",!0),H=m("variable/get",{configuration:{variable:I}}),G=m("math/not",{values:{a:P(H)}}),v=m("variable/set",{configuration:{variable:I},values:{value:P(G)}});s[v].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${L}/extensions/KHR_node_visibility/visible`},values:{value:P(H)}})}},u.push(v)}else if(C==="cycleMaterialColor"&&Array.isArray(p.colors)&&p.colors.length>0){let L=typeof p.duration=="number"?p.duration:.25,I=`/materials/${Math.max(0,F)}/pbrMetallicRoughness/baseColorFactor`,H=E(`__color_idx_${h}_${d}`,"int",0),G=m("variable/get",{configuration:{variable:H}}),v=m("math/add",{values:{a:P(G),b:{value:1}}}),V=m("math/rem",{values:{a:P(v),b:{value:p.colors.length}}}),k=m("variable/set",{configuration:{variable:H},values:{value:P(V)}}),O={};for(let W=0;W<p.colors.length;W++){let S=p.colors[W],_=Array.isArray(S)&&S.length>=3?[S[0],S[1],S[2],S[3]??1]:[1,1,1,1];O[String(W)]={node:L>0?m("pointer/interpolate",{configuration:{pointer:I},values:{value:{value:_},duration:{value:L}}}):m("pointer/set",{configuration:{pointer:I},values:{value:{value:_}}})}}s[k].flows={out:{node:m("flow/switch",{values:{selection:P(G)},flows:O})}},u.push(k)}else if(C==="playAnimation")u.push(m("animation/start",{configuration:{animation:p.animation??p.clip??0}}));else if(C==="stopAnimation")u.push(m("animation/stop"));else if(C==="sendEvent"){let L={};for(let[I,H]of Object.entries(p.values||{}))L[I]={value:H};u.push(m("event/send",{configuration:{event:c(String(p.event??p.id??"custom"))},values:L}))}}if(!u.length)return null;if(u.length===1)return u[0];let T={};return u.forEach((d,p)=>{T[String(p)]={node:d}}),m("flow/sequence",{flows:T})},w=(f,A,u)=>{let T=U(A);T!==null&&m(f,{...u?{configuration:u}:{},flows:{out:{node:T}}})};if(g.onSelect&&w("pointer/onSelect",g.onSelect,{nodeIndex:h}),g.onHoverIn&&w("pointer/onHoverIn",g.onHoverIn,{nodeIndex:h}),g.onHoverOut&&w("pointer/onHoverOut",g.onHoverOut,{nodeIndex:h}),g.onStart&&w("event/onStart",g.onStart),g.onReceive&&typeof g.onReceive=="object")for(let[f,A]of Object.entries(g.onReceive))w("event/receive",A,{event:c(f)})}return s.length?{graphs:[{declarations:i,nodes:s,variables:a,events:b}],graph:0}:null}var Te="__THREE_LIVE_REGISTRY__";function ae(){let n=typeof globalThis<"u"?globalThis:{};if(!n[Te]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,Te,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[Te]=e}}return n[Te]}var te=ae().plugins;function Be(n){let e=ae().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function ke(){return ae().plugins}function J(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function Ae(n,e,t,i,r){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let a=1/(i-r);return n[10]=(r+i)*a,n[14]=2*r*i*a,n}function Re(n,e,t,i){let[r,s,a]=e,[b,l,o]=i,[c,m,E]=t,P=r-c,M=s-m,y=a-E,R=Math.hypot(P,M,y);R<=1e-5?(P=0,M=0,y=1):(P/=R,M/=R,y/=R);let N=l*y-o*M,B=o*P-b*y,h=b*M-l*P;R=Math.hypot(N,B,h),R<=1e-5?(N=0,B=0,h=0):(N/=R,B/=R,h/=R);let D=M*h-y*B,g=y*N-P*h,F=P*B-M*N;return R=Math.hypot(D,g,F),R<=1e-5?(D=0,g=0,F=0):(D/=R,g/=R,F/=R),n[0]=N,n[1]=D,n[2]=P,n[3]=0,n[4]=B,n[5]=g,n[6]=M,n[7]=0,n[8]=h,n[9]=F,n[10]=y,n[11]=0,n[12]=-(N*r+B*s+h*a),n[13]=-(D*r+g*s+F*a),n[14]=-(P*r+M*s+y*a),n[15]=1,n}function ee(n,e,t){let i=e[0],r=e[1],s=e[2],a=e[3],b=e[4],l=e[5],o=e[6],c=e[7],m=e[8],E=e[9],P=e[10],M=e[11],y=e[12],R=e[13],N=e[14],B=e[15],h=t[0],D=t[1],g=t[2],F=t[3];return n[0]=h*i+D*b+g*m+F*y,n[1]=h*r+D*l+g*E+F*R,n[2]=h*s+D*o+g*P+F*N,n[3]=h*a+D*c+g*M+F*B,h=t[4],D=t[5],g=t[6],F=t[7],n[4]=h*i+D*b+g*m+F*y,n[5]=h*r+D*l+g*E+F*R,n[6]=h*s+D*o+g*P+F*N,n[7]=h*a+D*c+g*M+F*B,h=t[8],D=t[9],g=t[10],F=t[11],n[8]=h*i+D*b+g*m+F*y,n[9]=h*r+D*l+g*E+F*R,n[10]=h*s+D*o+g*P+F*N,n[11]=h*a+D*c+g*M+F*B,h=t[12],D=t[13],g=t[14],F=t[15],n[12]=h*i+D*b+g*m+F*y,n[13]=h*r+D*l+g*E+F*R,n[14]=h*s+D*o+g*P+F*N,n[15]=h*a+D*c+g*M+F*B,n}function ye(n,e,t,i){let r=e[0],s=e[1],a=e[2],b=e[3],l=r+r,o=s+s,c=a+a,m=r*l,E=r*o,P=r*c,M=s*o,y=s*c,R=a*c,N=b*l,B=b*o,h=b*c,D=i[0],g=i[1],F=i[2];return n[0]=(1-(M+R))*D,n[1]=(E+h)*D,n[2]=(P-B)*D,n[3]=0,n[4]=(E-h)*g,n[5]=(1-(m+R))*g,n[6]=(y+N)*g,n[7]=0,n[8]=(P+B)*F,n[9]=(y-N)*F,n[10]=(1-(m+M))*F,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function re(n,e){let t=e[0],i=e[1],r=e[2],s=e[4],a=e[5],b=e[6],l=e[8],o=e[9],c=e[10],m=c*a-b*o,E=-c*s+b*l,P=o*s-a*l,M=t*m+i*E+r*P;return M&&(M=1/M,n[0]=m*M,n[1]=E*M,n[2]=P*M,n[3]=(-c*i+r*o)*M,n[4]=(c*t-r*l)*M,n[5]=(-o*t+i*l)*M,n[6]=(b*i-r*a)*M,n[7]=(-b*t+r*s)*M,n[8]=(a*t-i*s)*M),n}function Ve(n,e){let t=e[0],i=e[1],r=e[2],s=e[3],a=e[4],b=e[5],l=e[6],o=e[7],c=e[8],m=e[9],E=e[10],P=e[11],M=e[12],y=e[13],R=e[14],N=e[15],B=t*b-i*a,h=t*l-r*a,D=t*o-s*a,g=i*l-r*b,F=i*o-s*b,U=r*o-s*l,w=c*y-m*M,f=c*R-E*M,A=c*N-P*M,u=m*R-E*y,T=m*N-P*y,d=E*N-P*R,p=B*d-h*T+D*u+g*A-F*f+U*w;return p?(p=1/p,n[0]=(b*d-l*T+o*u)*p,n[1]=(r*T-i*d-s*u)*p,n[2]=(y*U-R*F+N*g)*p,n[3]=(E*F-m*U-P*g)*p,n[4]=(l*A-a*d-o*f)*p,n[5]=(t*d-r*A+s*f)*p,n[6]=(R*D-M*U-N*h)*p,n[7]=(c*U-E*D+P*h)*p,n[8]=(a*T-b*A+o*w)*p,n[9]=(i*A-t*T-s*w)*p,n[10]=(M*F-y*D+N*B)*p,n[11]=(m*D-c*F-P*B)*p,n[12]=(b*f-a*u-l*w)*p,n[13]=(t*u-i*f+r*w)*p,n[14]=(y*h-M*g-R*B)*p,n[15]=(c*g-m*h+E*B)*p,n):null}function Ce(n,e,t,i,r){let s=r[0]*e+r[4]*t+r[8]*i+r[12],a=r[1]*e+r[5]*t+r[9]*i+r[13],b=r[2]*e+r[6]*t+r[10]*i+r[14],l=r[3]*e+r[7]*t+r[11]*i+r[15],o=l!==0?1/l:1;n[0]=s*o,n[1]=a*o,n[2]=b*o}function Oe(n,e,t,i,r,s,a,b,l,o,c,m,E,P,M,y,R=0){let N=o-a,B=c-b,h=m-l,D=E-a,g=P-b,F=M-l,U=r*F-s*g,w=s*D-i*F,f=i*g-r*D,A=N*U+B*w+h*f;if(A>-1e-7&&A<1e-7)return!1;let u=1/A,T=n-a,d=e-b,p=t-l,C=u*(T*U+d*w+p*f);if(C<-R||C>1+R)return!1;let x=d*h-p*B,L=p*N-T*h,I=T*B-d*N,H=u*(i*x+r*L+s*I);if(H<-R||C+H>1+R)return!1;let G=u*(D*x+g*L+F*I);if(G>1e-4&&G<y.distance){y.distance=G,y.point=[n+i*G,e+r*G,t+s*G];let v=B*F-h*g,V=h*D-N*F,k=N*g-B*D,O=Math.hypot(v,V,k)||1;return y.normal=[v/O,V/O,k/O],!0}return!1}function we(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,i=[];for(let c=0;c<t;c++)i.push(J());if(t===0)return i;let r=new Set;for(let c of n.nodes)if(Array.isArray(c.children))for(let m of c.children)r.add(m);let s=new Set,a=128,b=(c,m,E=0)=>{if(E>a||c<0||c>=t||s.has(c))return;s.add(c);let P=n.nodes[c];if(!P)return;let M=J();if(e&&e[c])M.set(e[c]);else if(P.matrix&&P.matrix.length===16)M.set(P.matrix);else{let R=P.translation||[0,0,0],N=P.rotation||[0,0,0,1],B=P.scale||[1,1,1];ye(M,N,R,B)}let y=i[c];if(m?ee(y,m,M):y.set(M),Array.isArray(P.children))for(let R of P.children)typeof R=="number"&&b(R,y,E+1)},l=[],o=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(o&&Array.isArray(o.nodes))l.push(...o.nodes);else for(let c=0;c<t;c++)r.has(c)||l.push(c);for(let c of l)b(c,null);for(let c=0;c<t;c++)!r.has(c)&&!l.includes(c)&&b(c,null);return i}function at(n){return new TextDecoder().decode(n)}var $e=ae().decoders;function ot(n,e){$e.set(n.toLowerCase(),e)}function fe(n){return $e.get(n.toLowerCase())}function We(n){let e=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let i=t.getUint32(0,!0);if(i!==1179937895){let E=t.getUint8(0);throw E===123||E===32||E===10||E===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${i.toString(16)}`)}let r=t.getUint32(4,!0);if(r!==2)throw new Error(`Unsupported GLB version: ${r}`);let s=t.getUint32(8,!0),a=12,b=null,l=null;for(;a+8<=s&&a+8<=e.byteLength;){let E=t.getUint32(a,!0),P=t.getUint32(a+4,!0),M=a+8;if(M+E>e.byteLength)throw new Error(`Truncated GLB chunk: required ${M+E} bytes, buffer has ${e.byteLength}`);if(P===1313821514){let y=new Uint8Array(e,M,E),R=at(y);b=JSON.parse(R,(N,B)=>N==="__proto__"||N==="constructor"||N==="prototype"?void 0:B)}else P===5130562&&(l=e.slice(M,M+E));a=M+E}if(!b)throw new Error("Missing JSON chunk in GLB");let o=b.extensionsRequired||[];if(o.includes("KHR_draco_mesh_compression")&&!fe("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(o.includes("EXT_meshopt_compression")&&!fe("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(o.includes("KHR_texture_basisu")&&!fe("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let c=l||new ArrayBuffer(0),m={gltf:b,bin:c,animations:[]};for(let E of te)E.onParseGLB?.(m);return m}function ct(n,e,t){return e%4===0?new Float32Array(n,e,t):new Float32Array(n.slice(e,e+t*4))}function ut(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 xe(n){if(ut(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return We(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Xe=`#version 300 es
|
|
18
18
|
layout(location=0) in vec3 aPosition;
|
|
19
19
|
layout(location=1) in vec3 aNormal;
|
|
20
20
|
layout(location=2) in vec2 aUV;
|
|
@@ -32,7 +32,7 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
32
32
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
33
33
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
34
34
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
35
|
-
}`,
|
|
35
|
+
}`,lt=`#version 300 es
|
|
36
36
|
precision highp float;
|
|
37
37
|
in vec3 vNormal,vWorldPos;
|
|
38
38
|
in vec2 vUV;
|
|
@@ -108,9 +108,33 @@ float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
|
|
|
108
108
|
return mix(color,newPeak*vec3(1.0),g);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
vec3 acesToneMapping(vec3 color){
|
|
112
|
+
color*=0.6;
|
|
113
|
+
return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
vec3 agxToneMapping(vec3 color){
|
|
117
|
+
color=max(color,vec3(0.0));
|
|
118
|
+
vec3 inset=vec3(
|
|
119
|
+
0.84247906*color.r+0.0784336*color.g+0.07922375*color.b,
|
|
120
|
+
0.04232824*color.r+0.87846864*color.g+0.07916613*color.b,
|
|
121
|
+
0.04237565*color.r+0.0784336*color.g+0.87914297*color.b);
|
|
122
|
+
vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
|
|
123
|
+
vec3 x2=ev*ev;
|
|
124
|
+
vec3 x4=x2*x2;
|
|
125
|
+
vec3 s=15.5*x4*x2-40.14*x4*ev+31.96*x4-6.868*x2*ev+0.4298*x2+0.1191*ev-0.00232;
|
|
126
|
+
vec3 outset=vec3(
|
|
127
|
+
1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
|
|
128
|
+
-0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
|
|
129
|
+
-0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
|
|
130
|
+
return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
131
|
+
}
|
|
132
|
+
|
|
111
133
|
vec3 applyToneMapping(vec3 color,int mode){
|
|
112
134
|
if(mode==0)return neutralToneMapping(color);
|
|
113
135
|
if(mode==1)return color/(color+vec3(1.0));
|
|
136
|
+
if(mode==3)return acesToneMapping(color);
|
|
137
|
+
if(mode==4)return agxToneMapping(color);
|
|
114
138
|
return color;
|
|
115
139
|
}
|
|
116
140
|
|
|
@@ -198,19 +222,19 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
198
222
|
float outAlpha=base.a;
|
|
199
223
|
/*XRD_O*/
|
|
200
224
|
fragColor=vec4(color,outAlpha);
|
|
201
|
-
}
|
|
225
|
+
}`;var mt=`#version 300 es
|
|
202
226
|
layout(location=0) in vec3 aPosition;
|
|
203
227
|
uniform mat4 uMVP;
|
|
204
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
228
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ht=`#version 300 es
|
|
205
229
|
precision highp float;
|
|
206
230
|
uniform vec4 uColorId;
|
|
207
231
|
out vec4 fragColor;
|
|
208
|
-
void main(){fragColor=uColorId;}`;function _e(n,e,t){let i=n.createShader(e);if(n.shaderSource(i,t),n.compileShader(i),!n.getShaderParameter(i,35713)){let r=n.getShaderInfoLog(i);throw n.deleteShader(i),new Error(`Shader compile error: ${r}`)}return i}function Ae(n,e,t){let i=_e(n,35633,e),r=_e(n,35632,t),s=n.createProgram();if(n.attachShader(s,i),n.attachShader(s,r),n.linkProgram(s),!n.getProgramParameter(s,35714)){let l=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${l}`)}return s}function we(n,e,t){let i={};for(let r of t)i[r]=n.getUniformLocation(e,r);return i}var Ue=["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","uViewportSize","uSectionPlane","uSectionEnabled"];function Oe(){let n=ee().xrDepthShader;return{fs:tt.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...Ue,...n.uniformNames]:Ue}}function rt(n){if(typeof n!="string")return null;let e=n.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 Re(n,e,t,i,r,s,l){if(i===void 0||!e.accessors?.[i])return null;let y=e.accessors[i],u=e.bufferViews[y.bufferView],a=(u.byteOffset||0)+(y.byteOffset||0),o=u.byteStride&&u.byteStride>s*4?u.byteStride>>2:s,m;if(o===s)m=new Float32Array(t,a,y.count*s);else{m=new Float32Array(y.count*s);let M=new Float32Array(t,u.byteOffset||0,Math.floor(u.byteLength/4)),h=(y.byteOffset||0)>>2;for(let E=0;E<y.count;E++){let D=h+E*o;for(let F=0;F<s;F++)m[E*s+F]=M[D+F]}}let T=n.createBuffer();return l.push(T),n.bindBuffer(34962,T),n.bufferData(34962,m,35044),n.enableVertexAttribArray(r),n.vertexAttribPointer(r,s,5126,!1,0,0),m}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 Be(n,e,t=Ve,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:r,bin:s}=e,l=[],y=ye(r),u=[];if(Array.isArray(r.nodes))for(let x=0;x<r.nodes.length;x++){let b=r.nodes[x];b.mesh!==void 0&&r.meshes&&r.meshes[b.mesh]&&u.push({node:b,nodeIdx:x,meshIdx:b.mesh})}let a=u.length>0?u:(r.meshes||[]).map((x,b)=>({node:x,nodeIdx:-1,meshIdx:b})),o=[];if(Array.isArray(e.lights)&&e.lights.length>0)o.push(...e.lights);else if(r.extensions?.KHR_lights_punctual?.lights){let x=r.extensions.KHR_lights_punctual.lights;for(let b of x){let A=b.type==="directional"?"directional":b.type==="point"?"point":"ambient";o.push({type:A,color:b.color||[1,1,1],intensity:b.intensity!==void 0?b.intensity:1})}}if(o.length===0&&(o.push({type:"ambient",color:[1,1,1],intensity:.35}),o.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),a.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${a.length}`);let m=[];if(r.textures&&r.images){if(r.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${r.textures.length}`);for(let x=0;x<r.textures.length;x++){let b=r.textures[x],A=r.images[b.source];if(A){let P=n.createTexture();if(n.bindTexture(3553,P),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),A.bufferView!==void 0){let I=r.bufferViews[A.bufferView],g=s.slice(I.byteOffset||0,(I.byteOffset||0)+I.byteLength),d=new Blob([g],{type:A.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(d).then(U=>{n.bindTexture(3553,P),n.texImage2D(3553,0,6408,6408,5121,U),n.generateMipmap(3553),i?.()}).catch(()=>{})}else if(A.uri){let I=rt(A.uri);if(I){let g=new Image;g.crossOrigin="anonymous",g.referrerPolicy="no-referrer",g.onload=()=>{n.bindTexture(3553,P),n.texImage2D(3553,0,6408,6408,5121,g),n.generateMipmap(3553),i?.()},g.src=I}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",A.uri)}m.push(P)}else m.push(null)}}let T=[1/0,1/0,1/0],M=[-1/0,-1/0,-1/0],h=0,E=0;for(let x=0;x<a.length;x++){let b=a[x],A=r.meshes[b.meshIdx],P=b.nodeIdx>=0?y[b.nodeIdx]:q(),I=new Float32Array(9);te(I,P);let g={name:b.node.name||A.name||`Mesh_${b.meshIdx}`,nodeIndex:b.nodeIdx,transform:P,normalMatrix:I,primitives:[],extras:b.node.extras||A.extras};for(let d of A.primitives||[]){if(d.extensions?.KHR_draco_mesh_compression){let X=me("draco");X&&X.decodePrimitive(r,d,s)}let U=[],S=n.createVertexArray();n.bindVertexArray(S);let V=r.accessors[d.attributes.POSITION],G=Number(V?.count??0);if(!Number.isFinite(G)||G<0||h+G>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(h+=G,V?.min&&V?.max)for(let X=0;X<3;X++){let Q=P[12+X],ue=P[12+X];for(let ne=0;ne<3;ne++){let fe=P[ne*4+X]*V.min[ne],de=P[ne*4+X]*V.max[ne];Q+=fe<de?fe:de,ue+=fe>de?fe:de}Q<T[X]&&(T[X]=Q),ue>M[X]&&(M[X]=ue)}let L=Re(n,r,s,d.attributes.POSITION,0,3,U);Re(n,r,s,d.attributes.NORMAL,1,3,U),Re(n,r,s,d.attributes.TEXCOORD_0,2,2,U);let _=0,R=5123,k=null;if(d.indices!==void 0){let X=r.accessors[d.indices],ue=(r.bufferViews[X.bufferView].byteOffset||0)+(X.byteOffset||0);if(_=Number(X.count??0),!Number.isFinite(_)||_<0||E+_>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);E+=_,R=X.componentType===5125?5125||5125:5123||5123;let ne=n.createBuffer();U.push(ne),n.bindBuffer(34963,ne),X.componentType===5125?(k=new Uint32Array(s,ue,X.count),n.bufferData(34963,k,35044)):(k=new Uint16Array(s,ue,X.count),n.bufferData(34963,k,35044))}else _=V.count;let N={};for(let X of Y)if(X.onBuildPrimitiveVAO){let Q=X.onBuildPrimitiveVAO(n,S,d,r,s);Q&&(N[X.name]=Q)}n.bindVertexArray(null);let O=r.materials&&d.material!==void 0?r.materials[d.material]:null,B=Oe(),H=Ge,W=B.fs,$=!1;for(let X of Y)if(X.onResolveShader){let Q=X.onResolveShader(d,O,H,W);Q&&(H=Q.vs,W=Q.fs,$=!0)}let j=$?Ae(n,H,W):null,ie=j?we(n,j,B.uniforms):null,K=O?.pbrMetallicRoughness,re=K?.baseColorFactor||[.8,.8,.8,1],se=K?.metallicFactor??.1,ae=K?.roughnessFactor??.5,Z=O?.extensions?.KHR_materials_clearcoat,oe=Z?Z.clearcoatFactor??1:0,ce=Math.max(.04,Z?.clearcoatRoughnessFactor??.04),le=K?.baseColorTexture!==void 0&&m[K.baseColorTexture.index]?m[K.baseColorTexture.index]:null,Xe=K?.metallicRoughnessTexture!==void 0&&m[K.metallicRoughnessTexture.index]?m[K.metallicRoughnessTexture.index]:null,Ke=O?.normalTexture!==void 0&&m[O.normalTexture.index]?m[O.normalTexture.index]:null,qe=O?.normalTexture?.scale??1,Ye=O?.occlusionTexture!==void 0&&m[O.occlusionTexture.index]?m[O.occlusionTexture.index]:null,Ze=O?.occlusionTexture?.strength??1,je=!!(O?.extensions?.KHR_materials_transmission||N.materials?.isTransmissive);g.primitives.push({vao:S,indexCount:_,indexType:R,baseColor:re,metallic:se,roughness:ae,clearcoat:oe,clearcoatRoughness:ce,positions:L,indices:k,texture:le,metallicRoughnessTexture:Xe,normalTexture:Ke,occlusionTexture:Ye,normalScale:qe,occlusionStrength:Ze,buffers:U,materialIndex:d.material,pluginData:N,customProgram:j,customUniforms:ie,isTransmissive:je})}l.push(g)}isFinite(T[0])||(T=[-1,-1,-1]),isFinite(M[0])||(M=[1,1,1]);let D=[(T[0]+M[0])/2,(T[1]+M[1])/2,(T[2]+M[2])/2],F=M[0]-T[0],C=M[1]-T[1],f=M[2]-T[2],v=Math.max(Math.hypot(F,C,f)/2,.5),p=[T[0],T[1],T[2]],w=[M[0],M[1],M[2]],c=e.animations;if(!c){for(let x of Y)if(x.onParseGLB?.(e),e.animations){c=e.animations;break}}return c||(c=[]),{meshes:l,bounds:{center:D,radius:v,min:p,max:w},lights:o,animations:c,worldMatrices:y}}var ve=class{constructor(e,t,i){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=q();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=q();this.viewMatrix=q();this.modelMatrix=q();this.mvpMatrix=q();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:q(),rawValueToMeters:.001,format:0};this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),r=a}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let l=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!l:l&&(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 y=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!y)throw new Error("WebGL2 not supported");this.gl=y;let u=Oe();this.renderProg=Ae(y,Ge,u.fs),this.pickProg=Ae(y,nt,it),this.uRender=we(y,this.renderProg,u.uniforms),this.uPick=we(y,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){Qe(e,t)}static getDecoder(e){return me(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),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),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 i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:l,worldMatrices:y}=Be(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=l||[],this.worldMatrices=y||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let a of e.gltf.nodes)this.initialNodeTransforms.push({t:a.translation?[a.translation[0],a.translation[1],a.translation[2]]:[0,0,0],r:a.rotation?[a.rotation[0],a.rotation[1],a.rotation[2],a.rotation[3]]:[0,0,0,1],s:a.scale?[a.scale[0],a.scale[1],a.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let a of Y)a.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),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(ke(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(he(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=he(e),{meshes:r}=Be(this.gl,i,Ve,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],te(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),te(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],l=[],y=[];for(let u of this.lights){let a=u.color||[1,1,1],o=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")i=[a[0]*o,a[1]*o,a[2]*o];else if(u.type==="directional"&&r.length<6){let m=u.direction||[.5,1,.8];r.push(m[0],m[1],m[2]),s.push(a[0]*o,a[1]*o,a[2]*o)}else if(u.type==="point"&&l.length<6){let m=u.position||[0,0,0];l.push(m[0],m[1],m[2]),y.push(a[0]*o,a[1]*o,a[2]*o)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,l.length/3),l.length>0&&(t.uniform3fv(e.uPointLightPos,l),t.uniform3fv(e.uPointLightColor,y)),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 Y)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Y)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,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.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,i)=>{let r=this.meshes.flatMap(o=>o.primitives.filter(m=>m.materialIndex===i||e.length===1&&m.materialIndex===void 0)),s=r[0],l=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],y=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,a={baseColorFactor:l,metallicFactor:y,roughnessFactor:u,setBaseColorFactor:o=>{let m=[o[0],o[1],o[2],o[3]??1];a.baseColorFactor=m,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=m);for(let T of r)T.baseColor=m;this.render()},setMetallicFactor:o=>{a.metallicFactor=o,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=o);for(let m of r)m.metallic=o;this.render()},setRoughnessFactor:o=>{a.roughnessFactor=o,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=o);for(let m of r)m.roughness=o;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:a}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.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 Y)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],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,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){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),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);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 i=q();J(i,this.projMatrix,this.viewMatrix);let[r,s,l]=e,y=t?t[0]:0,u=t?t[1]:0,a=t?t[2]:0,o=this.modelRootMatrix;o&&(r=o[0]*e[0]+o[4]*e[1]+o[8]*e[2]+o[12],s=o[1]*e[0]+o[5]*e[1]+o[9]*e[2]+o[13],l=o[2]*e[0]+o[6]*e[1]+o[10]*e[2]+o[14],t&&(y=o[0]*t[0]+o[4]*t[1]+o[8]*t[2],u=o[1]*t[0]+o[5]*t[1]+o[9]*t[2],a=o[2]*t[0]+o[6]*t[1]+o[10]*t[2]));let m=i[0]*r+i[4]*s+i[8]*l+i[12],T=i[1]*r+i[5]*s+i[9]*l+i[13],M=i[2]*r+i[6]*s+i[10]*l+i[14],h=i[3]*r+i[7]*s+i[11]*l+i[15];if(h<=1e-4)return{x:0,y:0,z:1,visible:!1};let E=m/h,D=T/h,F=M/h,C=this.canvas.getBoundingClientRect(),f=C.width||this.canvas.clientWidth||this.canvas.width||300,v=C.height||this.canvas.clientHeight||this.canvas.height||150,p=(E*.5+.5)*f,w=(-D*.5+.5)*v,c=E>=-1.1&&E<=1.1&&D>=-1.1&&D<=1.1&&F>=-1&&F<=1;if(c&&t){let x=this.customTarget||this.bounds.center,b=x[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),A=x[1]+this.currDistance*Math.sin(this.currPhi),P=x[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),I=[r-b,s-A,l-P];y*I[0]+u*I[1]+a*I[2]>.05&&(c=!1)}return{x:p,y:w,z:F,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 i=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},r=t.clientX-i.x,s=t.clientY-i.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(r,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let l=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],y=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],a=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-r*l[0]+s*y[0])*a,u[1]+=(-r*l[1]+s*y[1])*a,u[2]+=(-r*l[2]+s*y[2])*a,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-r*.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 i=e.getBoundingClientRect(),r=Math.floor((t.clientX-i.left)*(e.width/Math.max(i.width,1))),s=Math.floor((t.clientY-i.top)*(e.height/Math.max(i.height,1)));this.performMeshPick(r,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 i=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*i)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let i=t.detail||{};i.reset?this.resetCamera():this.setCamera(i.theta,i.phi,i.distance,i.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 i=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=i,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 i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,l=i.height||300,y=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),u=r.height>0?Math.floor((t-r.top)*(l/r.height)):Math.floor(t);return this.performMeshPick(y,u,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),l=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let y=q();J(y,this.projMatrix,this.viewMatrix);let u=[],a=Math.max(0,Math.min(s-1,e)),o=Math.max(0,Math.min(l-1,l-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==l)&&this.resizePickingFbo(s,l),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,l),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16384|256),r.useProgram(this.pickProg);for(let c=0;c<this.meshes.length;c++){let x=this.meshes[c];if(x.visible===!1||x.isPluginMesh)continue;let b=c+1,A=(b&255)/255,P=(b>>8&255)/255,I=(b>>16&255)/255;r.uniform4f(this.uPick.uColorId,A,P,I,1),J(this.modelMatrix,this.modelRootMatrix,x.transform),J(this.mvpMatrix,y,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let g of x.primitives)r.bindVertexArray(g.vao),r.drawElements(4,g.indexCount,g.indexType,0)}let p=new Uint8Array(4);r.readPixels(a,o,1,1,6408,5121,p),r.bindFramebuffer(36160,null);let w=p[0]+(p[1]<<8)+(p[2]<<16);w>0&&w<=this.meshes.length&&(u=[this.meshes[w-1]])}u.length===0&&(u=this.meshes.filter(p=>p.visible!==!1));let m=null,T=1/0,M=[0,0,0],h=[0,1,0],E=this.customTarget||this.bounds.center,D=E[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),F=E[1]+this.currDistance*Math.sin(this.currPhi),C=E[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let p of u){J(this.modelMatrix,this.modelRootMatrix,p.transform),J(this.mvpMatrix,y,this.modelMatrix);let w=q();if(!Ce(w,this.mvpMatrix))continue;let c=(a+.5)/s*2-1,x=(o+.5)/l*2-1,b=[0,0,0],A=[0,0,0];Me(b,c,x,-1,w),Me(A,c,x,1,w);let P=A[0]-b[0],I=A[1]-b[1],g=A[2]-b[2],d=Math.hypot(P,I,g)||1,U=P/d,S=I/d,V=g/d,G={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((_=>{for(let R of p.primitives){if(!R.positions)continue;let k=R.positions,N=R.indices,O=Math.floor(N?N.length/3:k.length/9);for(let B=0;B<O;B++){let H=N?N[B*3]:B*3,W=N?N[B*3+1]:B*3+1,$=N?N[B*3+2]:B*3+2;Ie(b[0],b[1],b[2],U,S,V,k[H*3],k[H*3+1],k[H*3+2],k[W*3],k[W*3+1],k[W*3+2],k[$*3],k[$*3+1],k[$*3+2],G,_)}}})(1e-4),isFinite(G.distance)){let _=G.point[0],R=G.point[1],k=G.point[2],N=this.modelMatrix,O=N[0]*_+N[4]*R+N[8]*k+N[12],B=N[1]*_+N[5]*R+N[9]*k+N[13],H=N[2]*_+N[6]*R+N[10]*k+N[14],W=O-D,$=B-F,j=H-C,ie=Math.hypot(W,$,j);if(ie<T){te(this.normalMatrix,this.modelMatrix);let K=this.normalMatrix,re=G.normal[0],se=G.normal[1],ae=G.normal[2],Z=K[0]*re+K[3]*se+K[6]*ae,oe=K[1]*re+K[4]*se+K[7]*ae,ce=K[2]*re+K[5]*se+K[8]*ae,le=Math.hypot(Z,oe,ce)||1;Z/=le,oe/=le,ce/=le,Z*W+oe*$+ce*j>0&&(Z=-Z,oe=-oe,ce=-ce),m=p,T=Math.round(ie*1e3)/1e3,M=[Math.round(O*1e3)/1e3,Math.round(B*1e3)/1e3,Math.round(H*1e3)/1e3],h=[Math.round(Z*1e3)/1e3,Math.round(oe*1e3)/1e3,Math.round(ce*1e3)/1e3]}}}if(!m)return null;let v={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:T,hitPoint:M,normal:h,screenX:e,screenY:t};if(i){for(let p of Y)p.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 i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,l=r?Math.max(1,t-i):i,y=(s+.5)/l*2-1;return Math.floor((y*.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);be(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center,r=i[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=i[1]+this.currDistance*Math.sin(this.currPhi),l=i[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);ge(this.viewMatrix,[r,s,l],i,[0,1,0]),J(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(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),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 i of Y)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of Y)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 i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}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),i=this.bounds.center[0],r=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]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let l of Y)l.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 l of Y)l.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 i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let l={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(l),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:l}))}}renderXRView(e,t,i,r,s=!0,l=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let y=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,a=e?.transform?.position,o=a?[a.x,a.y,a.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:y,projMatrix:u,eyePos:o,viewport:r,eye:e?.eye||"none",clear:l>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),p=Math.max(1,this.canvas.height||1),w=Math.max(1,Math.floor(v*.5)),c=Math.max(1,v-w),x=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),b=this.customTarget||this.bounds.center,A=b[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),P=b[1]+this.currDistance*Math.sin(this.currPhi),I=b[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),g=Math.cos(this.currTheta),d=-Math.sin(this.currTheta),U=.032,S=q(),V=q(),G=[A-g*U,P,I-d*U],L=[b[0]-g*U*.25,b[1],b[2]-d*U*.25];be(S,this.fov,w/p,.1,x),ge(V,G,L,[0,1,0]);let _=q(),R=q(),k=[A+g*U,P,I+d*U],N=[b[0]+g*U*.25,b[1],b[2]+d*U*.25];be(_,this.fov,c/p,.1,x),ge(R,k,N,[0,1,0]),this.render({viewMatrix:V,projMatrix:S,eyePos:G,viewport:[0,0,w,p],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:R,projMatrix:_,eyePos:k,viewport:[w,0,c,p],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,p);return}let t=this.gl,i=0,r=0,s=this.canvas.width,l=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],l=e.viewport[3],t.viewport(i,r,s,l)):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 y=q(),u=e?.viewMatrix??this.viewMatrix;J(y,e?.projMatrix??this.projMatrix,u);let a=ee().xrDepthShader,o=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,m=this.customTarget||this.bounds.center,T=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),M=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),h=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let v of Y)v.onBeforeDrawScene?.(this,t,y,[T,M,h],o);let E=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&E===0)return;let D=e?.eye||"none",F=!1,C=E>0?[...this.backdropMeshes,...this.meshes]:this.meshes,f=v=>{for(let p=0;p<C.length;p++){let w=C[p];if(w.visible===!1)continue;let c=this.selectedMeshName!==""&&w.name===this.selectedMeshName;p<E||w.worldSpace===!0||w.name==="__xr_reticle__"?this.modelMatrix.set(w.transform):J(this.modelMatrix,this.modelRootMatrix,w.transform),J(this.mvpMatrix,y,this.modelMatrix),te(w.normalMatrix,this.modelMatrix);let x=w.extras?.xr?.stereo||w.userData?.xr?.stereo,b=0,A=0,P=1,I=1;x==="sbs"?(P=.5,b=D==="right"?.5:0):x==="ou"&&(I=.5,A=D==="right"?.5:0);for(let g of w.primitives){let d=!!g.isTransmissive;if(!v&&d){F=!0;continue}if(v&&!d)continue;let U=g.customProgram||this.renderProg,S=g.customUniforms||this.uRender;t.useProgram(U),t.uniform1i(S.uToneMapping,o),t.uniform1f(S.uEnvIntensity,this.envIntensity),t.uniform3f(S.uCameraPos,T,M,h),t.uniform1f(S.uEmissive,c?1:0),t.uniformMatrix4fv(S.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(S.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(S.uNormalMatrix,!1,w.normalMatrix),S.uUvTransform&&t.uniform4f(S.uUvTransform,b,A,P,I),S.uViewportSize&&t.uniform2f(S.uViewportSize,Math.max(1,s),Math.max(1,l)),a?.bind(t,S,this.xrDepthState,u,[i,r,Math.max(1,s),Math.max(1,l)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(S.uEnvironmentMap,4),t.uniform1i(S.uHasEnvironmentMap,1)):t.uniform1i(S.uHasEnvironmentMap,0),this.bindLights(S),S.uSectionEnabled&&t.uniform1i(S.uSectionEnabled,0);for(let V of Y)V.onBeforeDrawPrimitive?.(t,U,g,w,this.worldMatrices||[],this.gltf);t.uniform4fv(S.uBaseColor,g.baseColor),t.uniform1f(S.uMetallic,g.metallic),t.uniform1f(S.uRoughness,g.roughness),S.uClearcoat&&t.uniform2f(S.uClearcoat,g.clearcoat??0,g.clearcoatRoughness??.04),g.texture?(t.activeTexture(33984),t.bindTexture(3553,g.texture),t.uniform1i(S.uBaseColorTexture,0),t.uniform1i(S.uHasTexture,1)):t.uniform1i(S.uHasTexture,0),g.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,g.metallicRoughnessTexture),t.uniform1i(S.uMetallicRoughnessTexture,1),t.uniform1i(S.uHasMetallicRoughnessTexture,1)):t.uniform1i(S.uHasMetallicRoughnessTexture,0),g.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,g.normalTexture),t.uniform1i(S.uNormalTexture,2),t.uniform1i(S.uHasNormalTexture,1),t.uniform1f(S.uNormalScale,g.normalScale)):t.uniform1i(S.uHasNormalTexture,0),g.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,g.occlusionTexture),t.uniform1i(S.uOcclusionTexture,3),t.uniform1i(S.uHasOcclusionTexture,1),t.uniform1f(S.uOcclusionStrength,g.occlusionStrength)):t.uniform1i(S.uHasOcclusionTexture,0),t.bindVertexArray(g.vao),t.drawElements(4,g.indexCount,g.indexType,0)}}};if(f(!1),F){for(let v of Y)v.onBeforeTransmissivePass?.(t,this);f(!0)}for(let v of Y)v.onAfterRender?.(t,this,y)}disposeMeshListGpuResources(e){let t=this.gl;for(let i of e)for(let r of i.primitives){if(r.vao&&t.deleteVertexArray(r.vao),r.buffers)for(let s of r.buffers)t.deleteBuffer(s);r.texture&&t.deleteTexture(r.texture),r.metallicRoughnessTexture&&t.deleteTexture(r.metallicRoughnessTexture),r.normalTexture&&t.deleteTexture(r.normalTexture),r.occlusionTexture&&t.deleteTexture(r.occlusionTexture),r.customProgram&&t.deleteProgram(r.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 Y)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()}};ve.registerPlugin=Se,ve.getRegisteredPlugins=Fe;function st(n){return n+3&-4}function at(n){let e={};return n.grab&&(e.interactable={mode:typeof n.grab=="string"?n.grab:"2-hand"},e.movable={scaleInZ:!!n.scale,minScale:typeof n.scale=="object"?n.scale.min??.1:.1,maxScale:typeof n.scale=="object"?n.scale.max??10:10}),n.billboard&&(e.billboard={mode:typeof n.billboard=="string"?n.billboard:"capsule"}),n.follow&&(e.follow={target:typeof n.follow=="object"?n.follow.mode??"head":n.follow}),n.anchor&&(e.anchor={plane:n.anchor}),n.physics&&n.physics!=="none"&&(e.rigidbody={type:n.physics}),e}function ot(n,e){n.updateMatrixWorld(!0);let t=[],i=0,r=[],s=[],l=[],y=[],u=new Set,a=[],o=[],m=new Map,T=[];function M(c,x){let b=new Uint8Array(c.buffer,c.byteOffset,c.byteLength),A=st(b.byteLength),P=new Uint8Array(A);P.set(b),t.push(P);let I=r.length;return r.push({buffer:0,byteOffset:i,byteLength:b.byteLength,target:x}),i+=A,I}function h(c,x,b,A,P,I,g){let d=M(c,b),U=s.length,S={bufferView:d,byteOffset:0,componentType:A,count:P,type:x};return I&&(S.min=I),g&&(S.max=g),s.push(S),U}n.traverse(c=>{(c.isLight||c.color&&c.intensity!==void 0)&&T.push({type:c.type,color:[c.color.r,c.color.g,c.color.b],intensity:c.intensity,position:[c.position.x,c.position.y,c.position.z]})});let E=[];function D(c){let x={name:c.name||""},b=c.position,A=c.quaternion,P=c.scale;if((b.x||b.y||b.z)&&(x.translation=[b.x,b.y,b.z]),(A.x||A.y||A.z||A.w!==1)&&(x.rotation=[A.x,A.y,A.z,A.w]),(P.x!==1||P.y!==1||P.z!==1)&&(x.scale=[P.x,P.y,P.z]),c.userData&&Object.keys(c.userData).length>0&&(x.extras=JSON.parse(JSON.stringify(c.userData,(g,d)=>{if(!(g==="__proto__"||g==="prototype"||g==="constructor"))return typeof d=="function"?void 0:d})),c.userData.xr)){let g=at(c.userData.xr);x.extensions={...x.extensions||{},MOZ_hubs_components:g,ANDROID_xr_scenecore:g},ee().xrTraitSerializer?.gltfNode(x,c.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(c.geometry){let g=c.geometry,d=g.attributes.position;if(d&&d.count>0){let U=[1/0,1/0,1/0],S=[-1/0,-1/0,-1/0];for(let _=0;_<d.count;_++){let R=d.getX(_),k=d.getY(_),N=d.getZ(_);R<U[0]&&(U[0]=R),R>S[0]&&(S[0]=R),k<U[1]&&(U[1]=k),k>S[1]&&(S[1]=k),N<U[2]&&(U[2]=N),N>S[2]&&(S[2]=N)}let G={attributes:{POSITION:h(d.array,"VEC3",34962,5126,d.count,U,S)}};if(g.attributes.normal&&(G.attributes.NORMAL=h(g.attributes.normal.array,"VEC3",34962,5126,g.attributes.normal.count)),g.attributes.uv&&(G.attributes.TEXCOORD_0=h(g.attributes.uv.array,"VEC2",34962,5126,g.attributes.uv.count)),g.index){let _=g.index.array instanceof Uint32Array;G.indices=h(g.index.array,"SCALAR",34963,_?5125:5123,g.index.count)}if(c.material){let _=m.get(c.material);if(_===void 0){_=o.length,m.set(c.material,_);let R=c.material,k={name:R.name||"",pbrMetallicRoughness:{baseColorFactor:[R.color.r,R.color.g,R.color.b,R.opacity],metallicFactor:R.metalness,roughnessFactor:R.roughness},doubleSided:R.side===2||R.doubleSided};if(R.emissive&&(R.emissive.r>0||R.emissive.g>0||R.emissive.b>0)){let O=R.emissiveIntensity??1;k.emissiveFactor=[R.emissive.r*O,R.emissive.g*O,R.emissive.b*O]}let N={};R.clearcoat>0&&(N.KHR_materials_clearcoat={clearcoatFactor:R.clearcoat,clearcoatRoughnessFactor:R.clearcoatRoughness||0}),R.sheen>0&&(N.KHR_materials_sheen={sheenColorFactor:R.sheenColor?[R.sheenColor.r,R.sheenColor.g,R.sheenColor.b]:[1,1,1],sheenRoughnessFactor:R.sheenRoughness||0}),R.transmission>0&&(N.KHR_materials_transmission={transmissionFactor:R.transmission}),R.thickness>0&&(N.KHR_materials_volume={thicknessFactor:R.thickness,attenuationDistance:R.attenuationDistance??1/0,attenuationColor:R.attenuationColor?[R.attenuationColor.r,R.attenuationColor.g,R.attenuationColor.b]:[1,1,1]}),R.ior!==void 0&&R.ior!==1.5&&(N.KHR_materials_ior={ior:R.ior}),R.dispersion>0&&(N.KHR_materials_dispersion={dispersion:R.dispersion}),R.iridescence>0&&(N.KHR_materials_iridescence={iridescenceFactor:R.iridescence,iridescenceIor:R.iridescenceIOR??1.3}),Object.keys(N).length>0&&(k.extensions=N),o.push(k)}G.material=_}let L=l.length;l.push({primitives:[G],name:c.name,...x.extras?{extras:x.extras}:{}}),x.mesh=L}}let I=y.length;if(y.push(x),a.push(c),c.children.length>0){x.children=[];for(let g of c.children)x.children.push(D(g))}return I}for(let c of n.children)E.push(D(c));let F=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),C=[];if(typeof F=="function"&&a.length>0){let c=e?.duration??4,x=e?.fps??15,b=Math.max(2,Math.round(c*x)+1),A=new Float32Array(b),P=a.map(L=>({px:L.position.x,py:L.position.y,pz:L.position.z,qx:L.quaternion.x,qy:L.quaternion.y,qz:L.quaternion.z,qw:L.quaternion.w,sx:L.scale.x,sy:L.scale.y,sz:L.scale.z})),I=a.map(()=>new Float32Array(b*3)),g=a.map(()=>new Float32Array(b*4)),d=a.map(()=>new Float32Array(b*3));for(let L=0;L<b;L++){let _=L/(b-1)*c;A[L]=_;try{F(_)}catch{}for(let R=0;R<a.length;R++){let k=a[R];I[R][L*3]=k.position.x,I[R][L*3+1]=k.position.y,I[R][L*3+2]=k.position.z,g[R][L*4]=k.quaternion.x,g[R][L*4+1]=k.quaternion.y,g[R][L*4+2]=k.quaternion.z,g[R][L*4+3]=k.quaternion.w,d[R][L*3]=k.scale.x,d[R][L*3+1]=k.scale.y,d[R][L*3+2]=k.scale.z}}for(let L=0;L<a.length;L++){let _=a[L],R=P[L];_.position.set(R.px,R.py,R.pz),_.quaternion.set(R.qx,R.qy,R.qz,R.qw),_.scale.set(R.sx,R.sy,R.sz)}n.updateMatrixWorld(!0);let U=null,S=()=>(U===null&&(U=h(A,"SCALAR",0,5126,b,[0],[c])),U),V=[],G=[];for(let L=0;L<a.length;L++){let _=P[L],R=!1,k=!1,N=!1;for(let O=0;O<b;O++)(Math.abs(I[L][O*3]-_.px)>1e-4||Math.abs(I[L][O*3+1]-_.py)>1e-4||Math.abs(I[L][O*3+2]-_.pz)>1e-4)&&(R=!0),(Math.abs(g[L][O*4]-_.qx)>1e-4||Math.abs(g[L][O*4+1]-_.qy)>1e-4||Math.abs(g[L][O*4+2]-_.qz)>1e-4||Math.abs(g[L][O*4+3]-_.qw)>1e-4)&&(k=!0),(Math.abs(d[L][O*3]-_.sx)>1e-4||Math.abs(d[L][O*3+1]-_.sy)>1e-4||Math.abs(d[L][O*3+2]-_.sz)>1e-4)&&(N=!0);if(R){let O=h(I[L],"VEC3",0,5126,b),B=V.length;V.push({input:S(),interpolation:"LINEAR",output:O}),G.push({sampler:B,target:{node:L,path:"translation"}})}if(k){let O=h(g[L],"VEC4",0,5126,b),B=V.length;V.push({input:S(),interpolation:"LINEAR",output:O}),G.push({sampler:B,target:{node:L,path:"rotation"}})}if(N){let O=h(d[L],"VEC3",0,5126,b),B=V.length;V.push({input:S(),interpolation:"LINEAR",output:O}),G.push({sampler:B,target:{node:L,path:"scale"}})}}G.length>0&&C.push({name:"ProceduralLoop",samplers:V,channels:G})}let f=Pe(y,l,n.userData),v={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:E}],scene:0,nodes:y,meshes:l,materials:o,accessors:s,bufferViews:r,buffers:[{byteLength:i}],...C.length>0?{animations:C}:{},...f||u.size>0?{extensionsUsed:[...f?["KHR_interactivity"]:[],...u]}:{},...f?{extensions:{KHR_interactivity:f}}:{}},p=new Uint8Array(i),w=0;for(let c of t)p.set(c,w),w+=c.byteLength;return{gltf:v,bin:p.buffer,lights:T,environmentIntensity:n.environmentIntensity}}function Te(n){return new TextEncoder().encode(n)}function Dt(n,e){let{gltf:t,bin:i}=ot(n,e),r=JSON.stringify(t),s=Te(r),l=(4-s.byteLength%4)%4,y=s.byteLength+l,u=20+y+8+i.byteLength,a=new Uint8Array(u),o=new DataView(a.buffer);o.setUint32(0,1179937895,!0),o.setUint32(4,2,!0),o.setUint32(8,u,!0),o.setUint32(12,y,!0),o.setUint32(16,1313821514,!0),a.set(s,20);for(let T=0;T<l;T++)a[20+s.byteLength+T]=32;let m=20+y;return o.setUint32(m,i.byteLength,!0),o.setUint32(m+4,5130562,!0),a.set(new Uint8Array(i),m+8),a}function ct(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(i=>{if(i.geometry){let r=i.geometry,s=r.attributes.position;if(!s||s.count===0)return;let l=s.count,y=new Float32Array(l*3),u=i.matrixWorld.elements;for(let c=0;c<l;c++){let x=s.getX(c),b=s.getY(c),A=s.getZ(c);y[c*3]=u[0]*x+u[4]*b+u[8]*A+u[12],y[c*3+1]=u[1]*x+u[5]*b+u[9]*A+u[13],y[c*3+2]=u[2]*x+u[6]*b+u[10]*A+u[14]}let a;if(r.attributes.normal){let c=r.attributes.normal;a=new Float32Array(l*3);let x=new Float32Array(9);te(x,u);for(let b=0;b<l;b++){let A=c.getX(b),P=c.getY(b),I=c.getZ(b),g=x[0]*A+x[3]*P+x[6]*I,d=x[1]*A+x[4]*P+x[7]*I,U=x[2]*A+x[5]*P+x[8]*I,S=Math.hypot(g,d,U)||1;a[b*3]=g/S,a[b*3+1]=d/S,a[b*3+2]=U/S}}let o;if(r.attributes.uv){let c=r.attributes.uv;o=new Float32Array(l*2);for(let x=0;x<l;x++)o[x*2]=c.getX(x),o[x*2+1]=c.getY(x)}let m;if(r.index)m=r.index.array;else{m=l>65535?new Uint32Array(l):new Uint16Array(l);for(let c=0;c<l;c++)m[c]=c}let T="DefaultMaterial",M=[.8,.8,.8],h=.5,E=.1,D=0,F=0,C=1.5,f=1,v=[0,0,0];if(i.material){let c=i.material;T=c.name||`Material_${t.length}`,c.color&&(M=[c.color.r,c.color.g,c.color.b]),typeof c.roughness=="number"&&(h=c.roughness),typeof c.metalness=="number"&&(E=c.metalness),typeof c.clearcoat=="number"&&(D=c.clearcoat),typeof c.clearcoatRoughness=="number"&&(F=c.clearcoatRoughness),typeof c.ior=="number"&&(C=c.ior);let x=typeof c.opacity=="number"?c.opacity:1,b=typeof c.transmission=="number"?c.transmission:0;if(f=x*(1-b),c.emissive&&(c.emissive.r>0||c.emissive.g>0||c.emissive.b>0)){let A=c.emissiveIntensity??1;v=[c.emissive.r*A,c.emissive.g*A,c.emissive.b*A]}}let p,w=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof w=="function"){let c=e?.duration??4,x=e?.fps??4,b=Math.max(2,Math.round(c*x)+1),A=[],P=[],I=[],g=[],d=[i.position.x,i.position.y,i.position.z],U=[i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w],S=[i.scale.x,i.scale.y,i.scale.z],V=!1;for(let G=0;G<b;G++){let L=G/(b-1)*c;A.push(L);try{w(L)}catch{}P.push([i.position.x,i.position.y,i.position.z]),I.push([i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w]),g.push([i.scale.x,i.scale.y,i.scale.z]),(Math.abs(i.position.x-d[0])>1e-4||Math.abs(i.position.y-d[1])>1e-4||Math.abs(i.position.z-d[2])>1e-4||Math.abs(i.quaternion.x-U[0])>1e-4||Math.abs(i.quaternion.y-U[1])>1e-4||Math.abs(i.quaternion.z-U[2])>1e-4||Math.abs(i.quaternion.w-U[3])>1e-4||Math.abs(i.scale.x-S[0])>1e-4)&&(V=!0)}i.position.set(d[0],d[1],d[2]),i.quaternion.set(U[0],U[1],U[2],U[3]),i.scale.set(S[0],S[1],S[2]),V&&(p={times:A,translations:P,rotations:I,scales:g})}t.push({name:i.name||`Mesh_${t.length}`,positions:y,indices:m,normals:a,uvs:o,materialName:T,color:M,roughness:h,metallic:E,clearcoat:D,clearcoatRoughness:F,ior:C,opacity:f,emissiveColor:v,xrTraits:i.userData?.xr,timeSamples:p})}}),t}function $e(n){let e=[],t=n.gltf,i=n.bin,r=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),s=t.accessors||[],l=t.bufferViews||[],y=t.materials||[],u=t.meshes||[],a=t.nodes||[];function o(M){let h=s[M];if(!h)throw new Error(`Accessor ${M} not found`);let E=l[h.bufferView||0],D=(E.byteOffset||0)+(h.byteOffset||0),F=E.byteLength||0,C=r.slice(D,D+F);return{acc:h,buffer:C}}let m=new Map;if(a.length>0){let M=ye(t);for(let h=0;h<M.length;h++)m.set(h,M[h])}function T(M,h,E,D){let F=u[M];if(!F)return;let C=new Float32Array(9);te(C,h);for(let f=0;f<(F.primitives||[]).length;f++){let v=F.primitives[f],p=v.attributes?.POSITION;if(p===void 0)continue;let{acc:w,buffer:c}=o(p),x=new Float32Array(c,0,w.count*3),b=new Float32Array(x.length);for(let B=0;B<w.count;B++){let H=x[B*3],W=x[B*3+1],$=x[B*3+2];b[B*3]=h[0]*H+h[4]*W+h[8]*$+h[12],b[B*3+1]=h[1]*H+h[5]*W+h[9]*$+h[13],b[B*3+2]=h[2]*H+h[6]*W+h[10]*$+h[14]}let A,P=v.attributes?.NORMAL;if(P!==void 0){let{acc:B,buffer:H}=o(P),W=new Float32Array(H,0,B.count*3);A=new Float32Array(W.length);for(let $=0;$<B.count;$++){let j=W[$*3],ie=W[$*3+1],K=W[$*3+2],re=C[0]*j+C[3]*ie+C[6]*K,se=C[1]*j+C[4]*ie+C[7]*K,ae=C[2]*j+C[5]*ie+C[8]*K,Z=Math.hypot(re,se,ae)||1;A[$*3]=re/Z,A[$*3+1]=se/Z,A[$*3+2]=ae/Z}}let I,g=v.attributes?.TEXCOORD_0;if(g!==void 0){let{acc:B,buffer:H}=o(g);I=new Float32Array(H,0,B.count*2)}let d;if(v.indices!==void 0){let{acc:B,buffer:H}=o(v.indices);B.componentType===5125?d=new Uint32Array(H,0,B.count):d=new Uint16Array(H,0,B.count);let W=w.count;for(let $ of d)if($>=W)throw new Error(`SecurityError: Index buffer value (${$}) out of vertex bounds [0, ${W}).`)}else{let B=w.count;d=B>65535?new Uint32Array(B):new Uint16Array(B);for(let H=0;H<B;H++)d[H]=H}let U="DefaultMaterial",S=[.8,.8,.8],V=.5,G=.1,L=0,_=0,R=1.5,k=1,N=[0,0,0];if(v.material!==void 0&&y[v.material]){let B=y[v.material];U=B.name||`Material_${v.material}`;let H=B.pbrMetallicRoughness||{},W=1;Array.isArray(H.baseColorFactor)&&(S=[H.baseColorFactor[0],H.baseColorFactor[1],H.baseColorFactor[2]],typeof H.baseColorFactor[3]=="number"&&(W=H.baseColorFactor[3])),typeof H.roughnessFactor=="number"&&(V=H.roughnessFactor),typeof H.metallicFactor=="number"&&(G=H.metallicFactor),Array.isArray(B.emissiveFactor)&&B.emissiveFactor.length>=3&&(N=[B.emissiveFactor[0],B.emissiveFactor[1],B.emissiveFactor[2]]);let $=B.extensions||{};$.KHR_materials_clearcoat&&(L=$.KHR_materials_clearcoat.clearcoatFactor??0,_=$.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),$.KHR_materials_ior&&typeof $.KHR_materials_ior.ior=="number"&&(R=$.KHR_materials_ior.ior);let j=$.KHR_materials_transmission?.transmissionFactor??0;k=W*(1-j)}let O=(F.primitives||[]).length>1?`${E}_p${f}`:E;e.push({name:O,positions:b,indices:d,normals:A,uvs:I,materialName:U,color:S,roughness:V,metallic:G,clearcoat:L,clearcoatRoughness:_,ior:R,opacity:k,emissiveColor:N,xrTraits:D?.xr||F.extras?.xr})}}if(a.length>0)for(let M=0;M<a.length;M++){let h=a[M];if(h.mesh!==void 0&&h.mesh<u.length){let E=m.get(M)||q(),D=h.name||u[h.mesh].name||`Node_${M}`;T(h.mesh,E,D,h.extras)}}else{let M=q();for(let h=0;h<u.length;h++){let E=u[h].name||`Mesh_${h}`;T(h,M,E,u[h].extras)}}return e}function De(n,e){if(!n||typeof n!="string")return e;let t=n.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(t)&&(t="_"+t),t||e}function He(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function z(n){if(!Number.isFinite(n)||Math.abs(n)<1e-7)return"0";let e=Number(n.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function ze(n){let e=n.length/3,t=new Array(e);for(let i=0;i<e;i++)t[i]=`(${z(n[i*3])}, ${z(n[i*3+1])}, ${z(n[i*3+2])})`;return t.join(", ")}function ut(n,e){let t=new Array(e);for(let i=0;i<e;i++)t[i]=`(${z(n[i*2])}, ${z(1-n[i*2+1])})`;return t.join(", ")}function lt(n){return Array.from(n).join(", ")}function Ee(n){let e=new Map;for(let u of n){let a=De(u.materialName,"DefaultMaterial");e.has(a)||e.set(a,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}let t=0,i=null;for(let u of n){if(u.timeSamples&&u.timeSamples.times.length>0){let a=u.timeSamples.times[u.timeSamples.times.length-1];a>t&&(t=a)}u.xrTraits?.anchor&&!i&&(i=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let r="";t>0&&(r=`startTimeCode = 0
|
|
209
|
-
endTimeCode = ${
|
|
232
|
+
void main(){fragColor=uColorId;}`;function Ge(n,e,t){let i=n.createShader(e);if(n.shaderSource(i,t),n.compileShader(i),!n.getShaderParameter(i,35713)){let r=n.getShaderInfoLog(i);throw n.deleteShader(i),new Error(`Shader compile error: ${r}`)}return i}function Pe(n,e,t){let i=Ge(n,35633,e),r=Ge(n,35632,t),s=n.createProgram();if(n.attachShader(s,i),n.attachShader(s,r),n.linkProgram(s),!n.getProgramParameter(s,35714)){let a=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${a}`)}return s}function Ie(n,e,t){let i={};for(let r of t)i[r]=n.getUniformLocation(e,r);return i}var He=["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","uViewportSize","uSectionPlane","uSectionEnabled"];function qe(){let n=ae().xrDepthShader;return{fs:lt.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...He,...n.uniformNames]:He}}function ft(n){if(typeof n!="string")return null;let e=n.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 Se(n,e,t,i,r,s,a){if(i===void 0||!e.accessors?.[i])return null;let b=e.accessors[i],l=e.bufferViews[b.bufferView],o=(l.byteOffset||0)+(b.byteOffset||0),c=l.byteStride&&l.byteStride>s*4?l.byteStride>>2:s,m;if(c===s)m=new Float32Array(t,o,b.count*s);else{m=new Float32Array(b.count*s);let P=new Float32Array(t,l.byteOffset||0,Math.floor(l.byteLength/4)),M=(b.byteOffset||0)>>2;for(let y=0;y<b.count;y++){let R=M+y*c;for(let N=0;N<s;N++)m[y*s+N]=P[R+N]}}let E=n.createBuffer();return a.push(E),n.bindBuffer(34962,E),n.bufferData(34962,m,35044),n.enableVertexAttribArray(r),n.vertexAttribPointer(r,s,5126,!1,0,0),m}var Pt=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Ke=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function ze(n,e,t=Ke,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:r}=e,s=fe("meshopt");s?.decodeBufferViews&&s.decodeBufferViews(r,e);let a=e.bin,b=[],l=[],o=r.extensions?.KHR_materials_variants;if(o&&Array.isArray(o.variants))for(let u of o.variants)u&&typeof u.name=="string"&&l.push(u.name);let c=we(r),m=[];if(Array.isArray(r.nodes))for(let u=0;u<r.nodes.length;u++){let T=r.nodes[u];T.mesh!==void 0&&r.meshes&&r.meshes[T.mesh]&&m.push({node:T,nodeIdx:u,meshIdx:T.mesh})}let E=m.length>0?m:(r.meshes||[]).map((u,T)=>({node:u,nodeIdx:-1,meshIdx:T})),P=[];if(Array.isArray(e.lights)&&e.lights.length>0)P.push(...e.lights);else if(r.extensions?.KHR_lights_punctual?.lights){let u=r.extensions.KHR_lights_punctual.lights;for(let T of u){let d=T.type==="directional"?"directional":T.type==="point"?"point":"ambient";P.push({type:d,color:T.color||[1,1,1],intensity:T.intensity!==void 0?T.intensity:1})}}if(P.length===0&&(P.push({type:"ambient",color:[1,1,1],intensity:.35}),P.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),E.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${E.length}`);let M=[];if(r.textures&&r.images){if(r.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${r.textures.length}`);for(let u=0;u<r.textures.length;u++){let T=r.textures[u],d=r.images[T.source];if(d){let p=n.createTexture();if(n.bindTexture(3553,p),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=r.bufferViews[d.bufferView],x=a.slice(C.byteOffset||0,(C.byteOffset||0)+C.byteLength),L=new Blob([x],{type:d.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(L).then(I=>{n.bindTexture(3553,p),n.texImage2D(3553,0,6408,6408,5121,I),n.generateMipmap(3553),i?.()}).catch(()=>{})}else if(d.uri){let C=ft(d.uri);if(C){let x=new Image;x.crossOrigin="anonymous",x.referrerPolicy="no-referrer",x.onload=()=>{n.bindTexture(3553,p),n.texImage2D(3553,0,6408,6408,5121,x),n.generateMipmap(3553),i?.()},x.src=C}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",d.uri)}M.push(p)}else M.push(null)}}let y=[1/0,1/0,1/0],R=[-1/0,-1/0,-1/0],N=0,B=0;for(let u=0;u<E.length;u++){let T=E[u],d=r.meshes[T.meshIdx],p=T.nodeIdx>=0?c[T.nodeIdx]:J(),C=new Float32Array(9);re(C,p);let x={name:T.node.name||d.name||`Mesh_${T.meshIdx}`,nodeIndex:T.nodeIdx,transform:p,normalMatrix:C,primitives:[],extras:T.node.extras||d.extras},L=T.node?.extensions?.EXT_mesh_gpu_instancing;if(L&&L.attributes&&typeof L.attributes=="object"){let I=L.attributes,H=I.TRANSLATION!==void 0?r.accessors?.[I.TRANSLATION]:null,G=I.ROTATION!==void 0?r.accessors?.[I.ROTATION]:null,v=I.SCALE!==void 0?r.accessors?.[I.SCALE]:null,V=I._COLOR_0!==void 0?r.accessors?.[I._COLOR_0]:null,k=Number(H?.count??G?.count??v?.count??0);if(!Number.isFinite(k)||k<0||k>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${k}`);if(k>0){let O=(X,Z)=>{if(!X||X.bufferView===void 0||!r.bufferViews?.[X.bufferView])return null;let j=(r.bufferViews[X.bufferView].byteOffset||0)+(X.byteOffset||0);return ct(a,j,k*Z)},W=O(H,3),S=O(G,4),_=O(v,3),$=V?.type==="VEC4"?4:3,z=O(V,$),K=new Float32Array(k*16),Q=J();for(let X=0;X<k;X++){let Z=W?[W[X*3],W[X*3+1],W[X*3+2]]:[0,0,0],oe=S?[S[X*4],S[X*4+1],S[X*4+2],S[X*4+3]]:[0,0,0,1],j=_?[_[X*3],_[X*3+1],_[X*3+2]]:[1,1,1];ye(Q,oe,Z,j),K.set(Q,X*16)}if(x.instanceMatrices=K,z){let X=new Float32Array(k*3);for(let Z=0;Z<k;Z++)X[Z*3]=z[Z*$],X[Z*3+1]=z[Z*$+1],X[Z*3+2]=z[Z*$+2];x.instanceColors=X}}}for(let I of d.primitives||[]){if(I.extensions?.KHR_draco_mesh_compression){let Y=fe("draco");Y&&Y.decodePrimitive(r,I,a)}let H=[],G=n.createVertexArray();n.bindVertexArray(G);let v=r.accessors[I.attributes.POSITION],V=Number(v?.count??0);if(!Number.isFinite(V)||V<0||N+V>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(N+=V,v?.min&&v?.max){let Y=ne=>{for(let ie=0;ie<3;ie++){let se=ne[12+ie],ge=ne[12+ie];for(let he=0;he<3;he++){let ve=ne[he*4+ie]*v.min[he],Me=ne[he*4+ie]*v.max[he];se+=ve<Me?ve:Me,ge+=ve>Me?ve:Me}se<y[ie]&&(y[ie]=se),ge>R[ie]&&(R[ie]=ge)}};if(x.instanceMatrices&&x.instanceMatrices.length>=16){let ne=x.instanceMatrices.length>>4,ie=J();for(let se=0;se<ne;se++){let ge=x.instanceMatrices.subarray(se*16,se*16+16);ee(ie,p,ge),Y(ie)}}else Y(p)}let k=Se(n,r,a,I.attributes.POSITION,0,3,H);Se(n,r,a,I.attributes.NORMAL,1,3,H),Se(n,r,a,I.attributes.TEXCOORD_0,2,2,H);let O=0,W=5123,S=null;if(I.indices!==void 0){let Y=r.accessors[I.indices],ie=(r.bufferViews[Y.bufferView].byteOffset||0)+(Y.byteOffset||0);if(O=Number(Y.count??0),!Number.isFinite(O)||O<0||B+O>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);B+=O,W=Y.componentType===5125?5125||5125:5123||5123;let se=n.createBuffer();H.push(se),n.bindBuffer(34963,se),Y.componentType===5125?(S=new Uint32Array(a,ie,Y.count),n.bufferData(34963,S,35044)):(S=new Uint16Array(a,ie,Y.count),n.bufferData(34963,S,35044))}else O=v.count;let _={};for(let Y of te)if(Y.onBuildPrimitiveVAO){let ne=Y.onBuildPrimitiveVAO(n,G,I,r,a);ne&&(_[Y.name]=ne)}n.bindVertexArray(null);let $=r.materials&&I.material!==void 0?r.materials[I.material]:null,z=qe(),K=Xe,Q=z.fs,X=!1;for(let Y of te)if(Y.onResolveShader){let ne=Y.onResolveShader(I,$,K,Q);ne&&(K=ne.vs,Q=ne.fs,X=!0)}let Z=X?Pe(n,K,Q):null,oe=Z?Ie(n,Z,z.uniforms):null,j=$?.pbrMetallicRoughness,ue=j?.baseColorFactor||[.8,.8,.8,1],de=j?.metallicFactor??.1,pe=j?.roughnessFactor??.5,ce=$?.extensions?.KHR_materials_clearcoat,le=ce?ce.clearcoatFactor??1:0,me=Math.max(.04,ce?.clearcoatRoughnessFactor??.04),be=j?.baseColorTexture!==void 0&&M[j.baseColorTexture.index]?M[j.baseColorTexture.index]:null,Qe=j?.metallicRoughnessTexture!==void 0&&M[j.metallicRoughnessTexture.index]?M[j.metallicRoughnessTexture.index]:null,et=$?.normalTexture!==void 0&&M[$.normalTexture.index]?M[$.normalTexture.index]:null,tt=$?.normalTexture?.scale??1,nt=$?.occlusionTexture!==void 0&&M[$.occlusionTexture.index]?M[$.occlusionTexture.index]:null,it=$?.occlusionTexture?.strength??1,rt=!!($?.extensions?.KHR_materials_transmission||_.materials?.isTransmissive),Ne=I.extensions?.KHR_materials_variants?.mappings,st=Array.isArray(Ne)?Ne.filter(Y=>Y&&typeof Y.material=="number"&&Array.isArray(Y.variants)).map(Y=>({material:Y.material|0,variants:Y.variants.map(ne=>Number(ne)|0)})):void 0;x.primitives.push({vao:G,indexCount:O,indexType:W,baseColor:ue,metallic:de,roughness:pe,clearcoat:le,clearcoatRoughness:me,positions:k,indices:S,texture:be,metallicRoughnessTexture:Qe,normalTexture:et,occlusionTexture:nt,normalScale:tt,occlusionStrength:it,buffers:H,materialIndex:I.material,defaultMaterialIndex:I.material,variantMappings:st,pluginData:_,customProgram:Z,customUniforms:oe,isTransmissive:rt})}b.push(x)}isFinite(y[0])||(y=[-1,-1,-1]),isFinite(R[0])||(R=[1,1,1]);let h=[(y[0]+R[0])/2,(y[1]+R[1])/2,(y[2]+R[2])/2],D=R[0]-y[0],g=R[1]-y[1],F=R[2]-y[2],U=Math.max(Math.hypot(D,g,F)/2,.5),w=[y[0],y[1],y[2]],f=[R[0],R[1],R[2]],A=e.animations;if(!A){for(let u of te)if(u.onParseGLB?.(e),e.animations){A=e.animations;break}}return A||(A=[]),{meshes:b,bounds:{center:h,radius:U,min:w,max:f},lights:P,animations:A,worldMatrices:c,gpuTextures:M,availableVariants:l}}var Ee=class{constructor(e,t,i){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=J();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.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=J();this.viewMatrix=J();this.modelMatrix=J();this.mvpMatrix=J();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:J(),rawValueToMeters:.001,format:0};this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),r=o}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!a:a&&(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.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),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 b=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!b)throw new Error("WebGL2 not supported");this.gl=b;let l=qe();this.renderProg=Pe(b,Xe,l.fs),this.pickProg=Pe(b,mt,ht),this.uRender=Ie(b,this.renderProg,l.uniforms),this.uPick=Ie(b,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){ot(e,t)}static getDecoder(e){return fe(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),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),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 i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:a,worldMatrices:b,gpuTextures:l,availableVariants:o}=ze(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=a||[],this.worldMatrices=b||[],this.gpuTextures=l||[],this.availableVariants=o||[],this.gltf=e.gltf,this.activeVariantName&&this.applyVariantMaterial(this.activeVariantName),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let m of e.gltf.nodes)this.initialNodeTransforms.push({t:m.translation?[m.translation[0],m.translation[1],m.translation[2]]:[0,0,0],r:m.rotation?[m.rotation[0],m.rotation[1],m.rotation[2],m.rotation[3]]:[0,0,0,1],s:m.scale?[m.scale[0],m.scale[1],m.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let m of te)m.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.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(We(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(xe(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=xe(e),{meshes:r}=ze(this.gl,i,Ke,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],re(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),re(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],a=[],b=[];for(let l of this.lights){let o=l.color||[1,1,1],c=l.intensity!==void 0?l.intensity:1;if(l.type==="ambient")i=[o[0]*c,o[1]*c,o[2]*c];else if(l.type==="directional"&&r.length<6){let m=l.direction||[.5,1,.8];r.push(m[0],m[1],m[2]),s.push(o[0]*c,o[1]*c,o[2]*c)}else if(l.type==="point"&&a.length<6){let m=l.position||[0,0,0];a.push(m[0],m[1],m[2]),b.push(o[0]*c,o[1]*c,o[2]*c)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,a.length/3),a.length>0&&(t.uniform3fv(e.uPointLightPos,a),t.uniform3fv(e.uPointLightColor,b)),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 te)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of te)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,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.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,i)=>{let r=this.meshes.flatMap(c=>c.primitives.filter(m=>m.materialIndex===i||e.length===1&&m.materialIndex===void 0)),s=r[0],a=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],b=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,l=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,o={baseColorFactor:a,metallicFactor:b,roughnessFactor:l,setBaseColorFactor:c=>{let m=[c[0],c[1],c[2],c[3]??1];o.baseColorFactor=m,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=m);for(let E of r)E.baseColor=m;this.render()},setMetallicFactor:c=>{o.metallicFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=c);for(let m of r)m.metallic=c;this.render()},setRoughnessFactor:c=>{o.roughnessFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=c);for(let m of r)m.roughness=c;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:o}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.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)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e===""||e==="default",i=-1;if(t)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(e),i<0)return!1;this.activeVariantName=e}let r=this.gltf?.materials;if(!Array.isArray(r))return t;for(let s of this.meshes)for(let a of s.primitives){let b=a.defaultMaterialIndex;if(!t&&Array.isArray(a.variantMappings)){for(let m of a.variantMappings)if(Array.isArray(m.variants)&&m.variants.includes(i)){b=m.material;break}}if(b===void 0||!r[b]){a.materialIndex=void 0,a.baseColor=[.8,.8,.8,1],a.metallic=.1,a.roughness=.5,a.clearcoat=0,a.clearcoatRoughness=.04,a.texture=null,a.metallicRoughnessTexture=null,a.normalTexture=null,a.normalScale=1,a.occlusionTexture=null,a.occlusionStrength=1,a.isTransmissive=!1;continue}let l=r[b];a.materialIndex=b;let o=l.pbrMetallicRoughness;a.baseColor=o?.baseColorFactor?[o.baseColorFactor[0],o.baseColorFactor[1],o.baseColorFactor[2],o.baseColorFactor[3]??1]:[.8,.8,.8,1],a.metallic=o?.metallicFactor??.1,a.roughness=o?.roughnessFactor??.5;let c=l.extensions?.KHR_materials_clearcoat;a.clearcoat=c?c.clearcoatFactor??1:0,a.clearcoatRoughness=Math.max(.04,c?.clearcoatRoughnessFactor??.04),a.texture=o?.baseColorTexture!==void 0&&this.gpuTextures[o.baseColorTexture.index]?this.gpuTextures[o.baseColorTexture.index]:null,a.metallicRoughnessTexture=o?.metallicRoughnessTexture!==void 0&&this.gpuTextures[o.metallicRoughnessTexture.index]?this.gpuTextures[o.metallicRoughnessTexture.index]:null,a.normalTexture=l.normalTexture!==void 0&&this.gpuTextures[l.normalTexture.index]?this.gpuTextures[l.normalTexture.index]:null,a.normalScale=l.normalTexture?.scale??1,a.occlusionTexture=l.occlusionTexture!==void 0&&this.gpuTextures[l.occlusionTexture.index]?this.gpuTextures[l.occlusionTexture.index]:null,a.occlusionStrength=l.occlusionTexture?.strength??1,a.isTransmissive=!!(l.extensions?.KHR_materials_transmission||a.pluginData?.materials?.isTransmissive)}return!0}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 te)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],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,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){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),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);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 i=J();ee(i,this.projMatrix,this.viewMatrix);let[r,s,a]=e,b=t?t[0]:0,l=t?t[1]:0,o=t?t[2]:0,c=this.modelRootMatrix;c&&(r=c[0]*e[0]+c[4]*e[1]+c[8]*e[2]+c[12],s=c[1]*e[0]+c[5]*e[1]+c[9]*e[2]+c[13],a=c[2]*e[0]+c[6]*e[1]+c[10]*e[2]+c[14],t&&(b=c[0]*t[0]+c[4]*t[1]+c[8]*t[2],l=c[1]*t[0]+c[5]*t[1]+c[9]*t[2],o=c[2]*t[0]+c[6]*t[1]+c[10]*t[2]));let m=i[0]*r+i[4]*s+i[8]*a+i[12],E=i[1]*r+i[5]*s+i[9]*a+i[13],P=i[2]*r+i[6]*s+i[10]*a+i[14],M=i[3]*r+i[7]*s+i[11]*a+i[15];if(M<=1e-4)return{x:0,y:0,z:1,visible:!1};let y=m/M,R=E/M,N=P/M,B=this.canvas.getBoundingClientRect(),h=B.width||this.canvas.clientWidth||this.canvas.width||300,D=B.height||this.canvas.clientHeight||this.canvas.height||150,g=(y*.5+.5)*h,F=(-R*.5+.5)*D,U=y>=-1.1&&y<=1.1&&R>=-1.1&&R<=1.1&&N>=-1&&N<=1;if(U&&t){let w=this.customTarget||this.bounds.center,f=w[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),A=w[1]+this.currDistance*Math.sin(this.currPhi),u=w[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),T=[r-f,s-A,a-u];b*T[0]+l*T[1]+o*T[2]>.05&&(U=!1)}return{x:g,y:F,z:N,visible:U}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}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 i=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},r=t.clientX-i.x,s=t.clientY-i.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(r,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],b=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],l=this.customTarget?[...this.customTarget]:[...this.bounds.center],o=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;l[0]+=(-r*a[0]+s*b[0])*o,l[1]+=(-r*a[1]+s*b[1])*o,l[2]+=(-r*a[2]+s*b[2])*o,this.customTarget=l}else this.targetTheta=this.clampTheta(this.targetTheta-r*.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 i=e.getBoundingClientRect(),r=Math.floor((t.clientX-i.left)*(e.width/Math.max(i.width,1))),s=Math.floor((t.clientY-i.top)*(e.height/Math.max(i.height,1)));this.performMeshPick(r,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 i=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*i)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let i=t.detail||{};i.reset?this.resetCamera():this.setCamera(i.theta,i.phi,i.distance,i.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 i=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=i,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=i,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=i,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=i,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 i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,a=i.height||300,b=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),l=r.height>0?Math.floor((t-r.top)*(a/r.height)):Math.floor(t);return this.performMeshPick(b,l,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),a=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let b=J();ee(b,this.projMatrix,this.viewMatrix);let l=[],o=Math.max(0,Math.min(s-1,e)),c=Math.max(0,Math.min(a-1,a-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==a)&&this.resizePickingFbo(s,a),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,a),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16384|256),r.useProgram(this.pickProg);for(let w=0;w<this.meshes.length;w++){let f=this.meshes[w];if(f.visible===!1||f.isPluginMesh)continue;let A=w+1,u=(A&255)/255,T=(A>>8&255)/255,d=(A>>16&255)/255;r.uniform4f(this.uPick.uColorId,u,T,d,1),ee(this.modelMatrix,this.modelRootMatrix,f.transform);let p=f.instanceMatrices;if(p&&p.length>=16){let C=p.length>>4,x=J();for(let L of f.primitives){r.bindVertexArray(L.vao);for(let I=0;I<C;I++)ee(x,this.modelMatrix,p.subarray(I*16,I*16+16)),ee(this.mvpMatrix,b,x),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),L.indices?r.drawElements(4,L.indexCount,L.indexType,0):r.drawArrays(4,0,L.indexCount)}}else{ee(this.mvpMatrix,b,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let C of f.primitives)r.bindVertexArray(C.vao),C.indices?r.drawElements(4,C.indexCount,C.indexType,0):r.drawArrays(4,0,C.indexCount)}}let F=new Uint8Array(4);r.readPixels(o,c,1,1,6408,5121,F),r.bindFramebuffer(36160,null);let U=F[0]+(F[1]<<8)+(F[2]<<16);U>0&&U<=this.meshes.length&&(l=[this.meshes[U-1]])}l.length===0&&(l=this.meshes.filter(F=>F.visible!==!1));let m=null,E=1/0,P=[0,0,0],M=[0,1,0],y=this.customTarget||this.bounds.center,R=y[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),N=y[1]+this.currDistance*Math.sin(this.currPhi),B=y[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),h=J();for(let F of l){ee(h,this.modelRootMatrix,F.transform);let U=F.instanceMatrices,w=U&&U.length>=16?U.length>>4:1;for(let f=0;f<w;f++){U&&U.length>=16?ee(this.modelMatrix,h,U.subarray(f*16,f*16+16)):this.modelMatrix.set(h),ee(this.mvpMatrix,b,this.modelMatrix);let A=J();if(!Ve(A,this.mvpMatrix))continue;let u=(o+.5)/s*2-1,T=(c+.5)/a*2-1,d=[0,0,0],p=[0,0,0];Ce(d,u,T,-1,A),Ce(p,u,T,1,A);let C=p[0]-d[0],x=p[1]-d[1],L=p[2]-d[2],I=Math.hypot(C,x,L)||1,H=C/I,G=x/I,v=L/I,V={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((O=>{for(let W of F.primitives){if(!W.positions)continue;let S=W.positions,_=W.indices,$=Math.floor(_?_.length/3:S.length/9);for(let z=0;z<$;z++){let K=_?_[z*3]:z*3,Q=_?_[z*3+1]:z*3+1,X=_?_[z*3+2]:z*3+2;Oe(d[0],d[1],d[2],H,G,v,S[K*3],S[K*3+1],S[K*3+2],S[Q*3],S[Q*3+1],S[Q*3+2],S[X*3],S[X*3+1],S[X*3+2],V,O)}}})(1e-4),isFinite(V.distance)){let O=V.point[0],W=V.point[1],S=V.point[2],_=this.modelMatrix,$=_[0]*O+_[4]*W+_[8]*S+_[12],z=_[1]*O+_[5]*W+_[9]*S+_[13],K=_[2]*O+_[6]*W+_[10]*S+_[14],Q=$-R,X=z-N,Z=K-B,oe=Math.hypot(Q,X,Z);if(oe<E){re(this.normalMatrix,this.modelMatrix);let j=this.normalMatrix,ue=V.normal[0],de=V.normal[1],pe=V.normal[2],ce=j[0]*ue+j[3]*de+j[6]*pe,le=j[1]*ue+j[4]*de+j[7]*pe,me=j[2]*ue+j[5]*de+j[8]*pe,be=Math.hypot(ce,le,me)||1;ce/=be,le/=be,me/=be,ce*Q+le*X+me*Z>0&&(ce=-ce,le=-le,me=-me),m=F,E=Math.round(oe*1e3)/1e3,P=[Math.round($*1e3)/1e3,Math.round(z*1e3)/1e3,Math.round(K*1e3)/1e3],M=[Math.round(ce*1e3)/1e3,Math.round(le*1e3)/1e3,Math.round(me*1e3)/1e3]}}}}if(!m)return null;let g={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:E,hitPoint:P,normal:M,screenX:e,screenY:t};if(i){for(let F of te)F.onMeshSelect?.(this,g);this.opts.onMeshClick&&this.opts.onMeshClick(g),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:g}))}return g}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,a=r?Math.max(1,t-i):i,b=(s+.5)/a*2-1;return Math.floor((b*.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);Ae(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center,r=i[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=i[1]+this.currDistance*Math.sin(this.currPhi),a=i[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Re(this.viewMatrix,[r,s,a],i,[0,1,0]),ee(this.mvpMatrix,this.projMatrix,this.viewMatrix),re(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),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 i of te)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of te)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 i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}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),i=this.bounds.center[0],r=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]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let a of te)a.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 a of te)a.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 i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let a={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(a),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:a}))}}renderXRView(e,t,i,r,s=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let b=e?.transform?.inverse?.matrix||this.viewMatrix,l=e?.projectionMatrix||this.projMatrix,o=e?.transform?.position,c=o?[o.x,o.y,o.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:b,projMatrix:l,eyePos:c,viewport:r,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&this.stereoSBS){let D=Math.max(2,this.canvas.width||2),g=Math.max(1,this.canvas.height||1),F=Math.max(1,Math.floor(D*.5)),U=Math.max(1,D-F),w=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),f=this.customTarget||this.bounds.center,A=f[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),u=f[1]+this.currDistance*Math.sin(this.currPhi),T=f[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),d=Math.cos(this.currTheta),p=-Math.sin(this.currTheta),C=.032,x=J(),L=J(),I=[A-d*C,u,T-p*C],H=[f[0]-d*C*.25,f[1],f[2]-p*C*.25];Ae(x,this.fov,F/g,.1,w),Re(L,I,H,[0,1,0]);let G=J(),v=J(),V=[A+d*C,u,T+p*C],k=[f[0]+d*C*.25,f[1],f[2]+p*C*.25];Ae(G,this.fov,U/g,.1,w),Re(v,V,k,[0,1,0]),this.render({viewMatrix:L,projMatrix:x,eyePos:I,viewport:[0,0,F,g],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:v,projMatrix:G,eyePos:V,viewport:[F,0,U,g],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,D,g);return}let t=this.gl,i=0,r=0,s=this.canvas.width,a=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],a=e.viewport[3],t.viewport(i,r,s,a)):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 b=J(),l=e?.viewMatrix??this.viewMatrix;ee(b,e?.projMatrix??this.projMatrix,l);let o=ae().xrDepthShader,c=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:this.toneMapping==="aces"?3:this.toneMapping==="agx"?4:0,m=this.customTarget||this.bounds.center,E=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),P=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),M=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let D of te)D.onBeforeDrawScene?.(this,t,b,[E,P,M],c);let y=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&y===0)return;let R=e?.eye||"none",N=!1,B=y>0?[...this.backdropMeshes,...this.meshes]:this.meshes,h=D=>{for(let g=0;g<B.length;g++){let F=B[g];if(F.visible===!1)continue;let U=this.selectedMeshName!==""&&F.name===this.selectedMeshName;g<y||F.worldSpace===!0||F.name==="__xr_reticle__"?this.modelMatrix.set(F.transform):ee(this.modelMatrix,this.modelRootMatrix,F.transform),ee(this.mvpMatrix,b,this.modelMatrix),re(F.normalMatrix,this.modelMatrix);let w=F.extras?.xr?.stereo||F.userData?.xr?.stereo,f=0,A=0,u=1,T=1;w==="sbs"?(u=.5,f=R==="right"?.5:0):w==="ou"&&(T=.5,A=R==="right"?.5:0);for(let d of F.primitives){let p=!!d.isTransmissive;if(!D&&p){N=!0;continue}if(D&&!p)continue;let C=d.customProgram||this.renderProg,x=d.customUniforms||this.uRender;t.useProgram(C),t.uniform1i(x.uToneMapping,c),t.uniform1f(x.uEnvIntensity,this.envIntensity),t.uniform3f(x.uCameraPos,E,P,M),t.uniform1f(x.uEmissive,U?1:0),t.uniformMatrix4fv(x.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(x.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(x.uNormalMatrix,!1,F.normalMatrix),x.uUvTransform&&t.uniform4f(x.uUvTransform,f,A,u,T),x.uViewportSize&&t.uniform2f(x.uViewportSize,Math.max(1,s),Math.max(1,a)),o?.bind(t,x,this.xrDepthState,l,[i,r,Math.max(1,s),Math.max(1,a)]),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),x.uSectionEnabled&&t.uniform1i(x.uSectionEnabled,0);for(let I of te)I.onBeforeDrawPrimitive?.(t,C,d,F,this.worldMatrices||[],this.gltf);t.uniform4fv(x.uBaseColor,d.baseColor),t.uniform1f(x.uMetallic,d.metallic),t.uniform1f(x.uRoughness,d.roughness),x.uClearcoat&&t.uniform2f(x.uClearcoat,d.clearcoat??0,d.clearcoatRoughness??.04),d.texture?(t.activeTexture(33984),t.bindTexture(3553,d.texture),t.uniform1i(x.uBaseColorTexture,0),t.uniform1i(x.uHasTexture,1)):t.uniform1i(x.uHasTexture,0),d.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,d.metallicRoughnessTexture),t.uniform1i(x.uMetallicRoughnessTexture,1),t.uniform1i(x.uHasMetallicRoughnessTexture,1)):t.uniform1i(x.uHasMetallicRoughnessTexture,0),d.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,d.normalTexture),t.uniform1i(x.uNormalTexture,2),t.uniform1i(x.uHasNormalTexture,1),t.uniform1f(x.uNormalScale,d.normalScale)):t.uniform1i(x.uHasNormalTexture,0),d.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,d.occlusionTexture),t.uniform1i(x.uOcclusionTexture,3),t.uniform1i(x.uHasOcclusionTexture,1),t.uniform1f(x.uOcclusionStrength,d.occlusionStrength)):t.uniform1i(x.uHasOcclusionTexture,0),t.bindVertexArray(d.vao);let L=F.instanceMatrices;if(L&&L.length>=16){let I=L.length>>4,H=F.instanceColors,G=J(),v=new Float32Array(9),V=[d.baseColor[0],d.baseColor[1],d.baseColor[2],d.baseColor[3]];for(let k=0;k<I;k++)ee(G,this.modelMatrix,L.subarray(k*16,k*16+16)),ee(this.mvpMatrix,b,G),re(v,G),t.uniformMatrix4fv(x.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(x.uModel,!1,G),t.uniformMatrix3fv(x.uNormalMatrix,!1,v),H&&(V[0]=d.baseColor[0]*H[k*3],V[1]=d.baseColor[1]*H[k*3+1],V[2]=d.baseColor[2]*H[k*3+2],V[3]=d.baseColor[3],t.uniform4fv(x.uBaseColor,V)),d.indices?t.drawElements(4,d.indexCount,d.indexType,0):t.drawArrays(4,0,d.indexCount)}else d.indices?t.drawElements(4,d.indexCount,d.indexType,0):t.drawArrays(4,0,d.indexCount)}}};if(h(!1),N){for(let D of te)D.onBeforeTransmissivePass?.(t,this);h(!0)}for(let D of te)D.onAfterRender?.(t,this,b)}disposeMeshListGpuResources(e,t){let i=this.gl,r=new Set,s=a=>{a&&!r.has(a)&&(r.add(a),i.deleteTexture(a))};for(let a of e)for(let b of a.primitives){if(b.vao&&i.deleteVertexArray(b.vao),b.buffers)for(let l of b.buffers)i.deleteBuffer(l);s(b.texture),s(b.metallicRoughnessTexture),s(b.normalTexture),s(b.occlusionTexture),b.customProgram&&i.deleteProgram(b.customProgram)}if(t)for(let a of t)s(a)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of te)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()}};Ee.registerPlugin=Be,Ee.getRegisteredPlugins=ke;function dt(n){return n+3&-4}function pt(n,e=0){let t=(v,V)=>typeof v=="number"&&Number.isFinite(v)?v:V,i=t(n[e+12],0),r=t(n[e+13],0),s=t(n[e+14],0),a=t(n[e+0],1),b=t(n[e+1],0),l=t(n[e+2],0),o=t(n[e+4],0),c=t(n[e+5],1),m=t(n[e+6],0),E=t(n[e+8],0),P=t(n[e+9],0),M=t(n[e+10],1),y=Math.hypot(a,b,l),R=Math.hypot(o,c,m),N=Math.hypot(E,P,M);a*(c*M-P*m)-o*(b*M-P*l)+E*(b*m-c*l)<0&&(y=-y);let h=Math.abs(y)>1e-8?1/y:0,D=Math.abs(R)>1e-8?1/R:0,g=Math.abs(N)>1e-8?1/N:0,F=a*h,U=b*h,w=l*h,f=o*D,A=c*D,u=m*D,T=E*g,d=P*g,p=M*g,C=F+A+p,x=0,L=0,I=0,H=1;if(C>0){let v=.5/Math.sqrt(C+1);H=.25/v,x=(u-d)*v,L=(T-w)*v,I=(U-f)*v}else if(F>A&&F>p){let v=2*Math.sqrt(Math.max(0,1+F-A-p));v>1e-8&&(H=(u-d)/v,x=.25*v,L=(f+U)/v,I=(T+w)/v)}else if(A>p){let v=2*Math.sqrt(Math.max(0,1+A-F-p));v>1e-8&&(H=(T-w)/v,x=(f+U)/v,L=.25*v,I=(u+d)/v)}else{let v=2*Math.sqrt(Math.max(0,1+p-F-A));v>1e-8&&(H=(U-f)/v,x=(T+w)/v,L=(u+d)/v,I=.25*v)}let G=Math.hypot(x,L,I,H);return G>1e-8&&Number.isFinite(G)?(x/=G,L/=G,I/=G,H/=G):(x=0,L=0,I=0,H=1),{t:[i,r,s],r:[x,L,I,H],s:[y,R,N]}}function bt(n){let e={};return n.grab&&(e.interactable={mode:typeof n.grab=="string"?n.grab:"2-hand"},e.movable={scaleInZ:!!n.scale,minScale:typeof n.scale=="object"?n.scale.min??.1:.1,maxScale:typeof n.scale=="object"?n.scale.max??10:10}),n.billboard&&(e.billboard={mode:typeof n.billboard=="string"?n.billboard:"capsule"}),n.follow&&(e.follow={target:typeof n.follow=="object"?n.follow.mode??"head":n.follow}),n.anchor&&(e.anchor={plane:n.anchor}),n.physics&&n.physics!=="none"&&(e.rigidbody={type:n.physics}),e}function gt(n,e){n.updateMatrixWorld(!0);let t=[],i=0,r=[],s=[],a=[],b=[],l=new Set,o=[],c=[],m=new Map,E=[],P=[];function M(f){let A=m.get(f);if(A!==void 0)return A;A=c.length,m.set(f,A);let u=f,T=u.color?.r??.8,d=u.color?.g??.8,p=u.color?.b??.8,C=u.opacity??1,x={name:u.name||"",pbrMetallicRoughness:{baseColorFactor:[T,d,p,C],metallicFactor:u.metalness??.1,roughnessFactor:u.roughness??.5},doubleSided:u.side===2||!!u.doubleSided};if(u.emissive&&(u.emissive.r>0||u.emissive.g>0||u.emissive.b>0)){let I=u.emissiveIntensity??1;x.emissiveFactor=[u.emissive.r*I,u.emissive.g*I,u.emissive.b*I]}let L={};return u.clearcoat&&u.clearcoat>0&&(L.KHR_materials_clearcoat={clearcoatFactor:u.clearcoat,clearcoatRoughnessFactor:u.clearcoatRoughness||0}),u.sheen&&u.sheen>0&&(L.KHR_materials_sheen={sheenColorFactor:u.sheenColor?[u.sheenColor.r,u.sheenColor.g,u.sheenColor.b]:[1,1,1],sheenRoughnessFactor:u.sheenRoughness||0}),u.transmission&&u.transmission>0&&(L.KHR_materials_transmission={transmissionFactor:u.transmission}),u.thickness&&u.thickness>0&&(L.KHR_materials_volume={thicknessFactor:u.thickness,attenuationDistance:u.attenuationDistance??1/0,attenuationColor:u.attenuationColor?[u.attenuationColor.r,u.attenuationColor.g,u.attenuationColor.b]:[1,1,1]}),u.ior!==void 0&&u.ior!==1.5&&(L.KHR_materials_ior={ior:u.ior}),u.dispersion&&u.dispersion>0&&(L.KHR_materials_dispersion={dispersion:u.dispersion}),u.iridescence&&u.iridescence>0&&(L.KHR_materials_iridescence={iridescenceFactor:u.iridescence,iridescenceIor:u.iridescenceIOR??1.3}),Object.keys(L).length>0&&(x.extensions=L),c.push(x),A}function y(f,A){let u=new Uint8Array(f.buffer,f.byteOffset,f.byteLength),T=dt(u.byteLength),d=new Uint8Array(T);d.set(u),t.push(d);let p=r.length;return r.push({buffer:0,byteOffset:i,byteLength:u.byteLength,target:A}),i+=T,p}function R(f,A,u,T,d,p,C){let x=y(f,u),L=s.length,I={bufferView:x,byteOffset:0,componentType:T,count:d,type:A};return p&&(I.min=p),C&&(I.max=C),s.push(I),L}n.traverse(f=>{(f.isLight||f.color&&f.intensity!==void 0)&&P.push({type:f.type,color:[f.color.r,f.color.g,f.color.b],intensity:f.intensity,position:[f.position.x,f.position.y,f.position.z]})});let N=[];function B(f){let A={name:f.name||""},u=f.position,T=f.quaternion,d=f.scale;if((u.x||u.y||u.z)&&(A.translation=[u.x,u.y,u.z]),(T.x||T.y||T.z||T.w!==1)&&(A.rotation=[T.x,T.y,T.z,T.w]),(d.x!==1||d.y!==1||d.z!==1)&&(A.scale=[d.x,d.y,d.z]),f.userData&&Object.keys(f.userData).length>0&&(A.extras=JSON.parse(JSON.stringify(f.userData,(C,x)=>{if(!(C==="__proto__"||C==="prototype"||C==="constructor"))return typeof x=="function"?void 0:x})),f.userData.xr)){let C=bt(f.userData.xr);A.extensions={...A.extensions||{},MOZ_hubs_components:C,ANDROID_xr_scenecore:C},ae().xrTraitSerializer?.gltfNode(A,f.userData.xr),l.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(f.geometry){let C=f.geometry,x=C.attributes.position;if(x&&x.count>0){let L=[1/0,1/0,1/0],I=[-1/0,-1/0,-1/0];for(let O=0;O<x.count;O++){let W=x.getX(O),S=x.getY(O),_=x.getZ(O);W<L[0]&&(L[0]=W),W>I[0]&&(I[0]=W),S<L[1]&&(L[1]=S),S>I[1]&&(I[1]=S),_<L[2]&&(L[2]=_),_>I[2]&&(I[2]=_)}let G={attributes:{POSITION:R(x.array,"VEC3",34962,5126,x.count,L,I)}};if(C.attributes.normal&&(G.attributes.NORMAL=R(C.attributes.normal.array,"VEC3",34962,5126,C.attributes.normal.count)),C.attributes.uv&&(G.attributes.TEXCOORD_0=R(C.attributes.uv.array,"VEC2",34962,5126,C.attributes.uv.count)),C.index){let O=C.index.array instanceof Uint32Array;G.indices=R(C.index.array,"SCALAR",34963,O?5125:5123,C.index.count)}f.material&&(G.material=M(f.material));let v=f.userData?.variants;if(v&&typeof v=="object"){let O=new Map;for(let W of Object.keys(v)){if(!W||W==="__proto__"||W==="constructor"||W==="prototype")continue;let S=v[W];if(!S||typeof S!="object")continue;let _=E.indexOf(W);if(_===-1&&E.length<256&&(_=E.length,E.push(W)),_===-1)continue;let $=M(S),z=O.get($);z||(z=[],O.set($,z)),z.push(_)}if(O.size>0){let W=[];for(let[S,_]of O.entries())W.push({material:S,variants:_});G.extensions={...G.extensions||{},KHR_materials_variants:{mappings:W}},l.add("KHR_materials_variants")}}let V=f;if(V.isInstancedMesh&&typeof V.count=="number"&&V.count>0&&V.instanceMatrix?.array){let O=Math.min(1e4,Math.floor(V.count)),W=V.instanceMatrix.array,S=new Float32Array(O*3),_=new Float32Array(O*4),$=new Float32Array(O*3);for(let K=0;K<O;K++){let{t:Q,r:X,s:Z}=pt(W,K*16);S[K*3]=Q[0],S[K*3+1]=Q[1],S[K*3+2]=Q[2],_[K*4]=X[0],_[K*4+1]=X[1],_[K*4+2]=X[2],_[K*4+3]=X[3],$[K*3]=Z[0],$[K*3+1]=Z[1],$[K*3+2]=Z[2]}let z={TRANSLATION:R(S,"VEC3",0,5126,O),ROTATION:R(_,"VEC4",0,5126,O),SCALE:R($,"VEC3",0,5126,O)};if(V.instanceColor?.array&&V.instanceColor.array.length>=O*3){let K=new Float32Array(V.instanceColor.array.subarray(0,O*3));z._COLOR_0=R(K,"VEC3",0,5126,O)}A.extensions={...A.extensions||{},EXT_mesh_gpu_instancing:{attributes:z}},l.add("EXT_mesh_gpu_instancing")}let k=a.length;a.push({primitives:[G],name:f.name,...A.extras?{extras:A.extras}:{}}),A.mesh=k}}let p=b.length;if(b.push(A),o.push(f),f.children.length>0){A.children=[];for(let C of f.children)A.children.push(B(C))}return p}for(let f of n.children)N.push(B(f));let h=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),D=[];if(typeof h=="function"&&o.length>0){let f=e?.duration??4,A=e?.fps??15,u=Math.max(2,Math.round(f*A)+1),T=new Float32Array(u),d=o.map(v=>({px:v.position.x,py:v.position.y,pz:v.position.z,qx:v.quaternion.x,qy:v.quaternion.y,qz:v.quaternion.z,qw:v.quaternion.w,sx:v.scale.x,sy:v.scale.y,sz:v.scale.z})),p=o.map(()=>new Float32Array(u*3)),C=o.map(()=>new Float32Array(u*4)),x=o.map(()=>new Float32Array(u*3));for(let v=0;v<u;v++){let V=v/(u-1)*f;T[v]=V;try{h(V)}catch{}for(let k=0;k<o.length;k++){let O=o[k];p[k][v*3]=O.position.x,p[k][v*3+1]=O.position.y,p[k][v*3+2]=O.position.z,C[k][v*4]=O.quaternion.x,C[k][v*4+1]=O.quaternion.y,C[k][v*4+2]=O.quaternion.z,C[k][v*4+3]=O.quaternion.w,x[k][v*3]=O.scale.x,x[k][v*3+1]=O.scale.y,x[k][v*3+2]=O.scale.z}}for(let v=0;v<o.length;v++){let V=o[v],k=d[v];V.position.set(k.px,k.py,k.pz),V.quaternion.set(k.qx,k.qy,k.qz,k.qw),V.scale.set(k.sx,k.sy,k.sz)}n.updateMatrixWorld(!0);let L=null,I=()=>(L===null&&(L=R(T,"SCALAR",0,5126,u,[0],[f])),L),H=[],G=[];for(let v=0;v<o.length;v++){let V=d[v],k=!1,O=!1,W=!1;for(let S=0;S<u;S++)(Math.abs(p[v][S*3]-V.px)>1e-4||Math.abs(p[v][S*3+1]-V.py)>1e-4||Math.abs(p[v][S*3+2]-V.pz)>1e-4)&&(k=!0),(Math.abs(C[v][S*4]-V.qx)>1e-4||Math.abs(C[v][S*4+1]-V.qy)>1e-4||Math.abs(C[v][S*4+2]-V.qz)>1e-4||Math.abs(C[v][S*4+3]-V.qw)>1e-4)&&(O=!0),(Math.abs(x[v][S*3]-V.sx)>1e-4||Math.abs(x[v][S*3+1]-V.sy)>1e-4||Math.abs(x[v][S*3+2]-V.sz)>1e-4)&&(W=!0);if(k){let S=R(p[v],"VEC3",0,5126,u),_=H.length;H.push({input:I(),interpolation:"LINEAR",output:S}),G.push({sampler:_,target:{node:v,path:"translation"}})}if(O){let S=R(C[v],"VEC4",0,5126,u),_=H.length;H.push({input:I(),interpolation:"LINEAR",output:S}),G.push({sampler:_,target:{node:v,path:"rotation"}})}if(W){let S=R(x[v],"VEC3",0,5126,u),_=H.length;H.push({input:I(),interpolation:"LINEAR",output:S}),G.push({sampler:_,target:{node:v,path:"scale"}})}}G.length>0&&D.push({name:"ProceduralLoop",samplers:H,channels:G})}let g=Ue(b,a,n.userData),F={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:N}],scene:0,nodes:b,meshes:a,materials:c,accessors:s,bufferViews:r,buffers:[{byteLength:i}],...D.length>0?{animations:D}:{},...g||l.size>0?{extensionsUsed:[...g?["KHR_interactivity"]:[],...l]}:{},...g||E.length>0?{extensions:{...g?{KHR_interactivity:g}:{},...E.length>0?{KHR_materials_variants:{variants:E.map(f=>({name:f}))}}:{}}}:{}},U=new Uint8Array(i),w=0;for(let f of t)U.set(f,w),w+=f.byteLength;return{gltf:F,bin:U.buffer,lights:P,environmentIntensity:n.environmentIntensity}}function Fe(n){return new TextEncoder().encode(n)}function Ut(n,e){let{gltf:t,bin:i}=gt(n,e),r=JSON.stringify(t),s=Fe(r),a=(4-s.byteLength%4)%4,b=s.byteLength+a,l=20+b+8+i.byteLength,o=new Uint8Array(l),c=new DataView(o.buffer);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0),c.setUint32(8,l,!0),c.setUint32(12,b,!0),c.setUint32(16,1313821514,!0),o.set(s,20);for(let E=0;E<a;E++)o[20+s.byteLength+E]=32;let m=20+b;return c.setUint32(m,i.byteLength,!0),c.setUint32(m+4,5130562,!0),o.set(new Uint8Array(i),m+8),o}function yt(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(i=>{if(i.geometry){let r=i.geometry,s=r.attributes.position;if(!s||s.count===0)return;let a=s.count,b=new Float32Array(a*3),l=i.matrixWorld.elements;for(let w=0;w<a;w++){let f=s.getX(w),A=s.getY(w),u=s.getZ(w);b[w*3]=l[0]*f+l[4]*A+l[8]*u+l[12],b[w*3+1]=l[1]*f+l[5]*A+l[9]*u+l[13],b[w*3+2]=l[2]*f+l[6]*A+l[10]*u+l[14]}let o;if(r.attributes.normal){let w=r.attributes.normal;o=new Float32Array(a*3);let f=new Float32Array(9);re(f,l);for(let A=0;A<a;A++){let u=w.getX(A),T=w.getY(A),d=w.getZ(A),p=f[0]*u+f[3]*T+f[6]*d,C=f[1]*u+f[4]*T+f[7]*d,x=f[2]*u+f[5]*T+f[8]*d,L=Math.hypot(p,C,x)||1;o[A*3]=p/L,o[A*3+1]=C/L,o[A*3+2]=x/L}}let c;if(r.attributes.uv){let w=r.attributes.uv;c=new Float32Array(a*2);for(let f=0;f<a;f++)c[f*2]=w.getX(f),c[f*2+1]=w.getY(f)}let m;if(r.index)m=r.index.array;else{m=a>65535?new Uint32Array(a):new Uint16Array(a);for(let w=0;w<a;w++)m[w]=w}let E="DefaultMaterial",P=[.8,.8,.8],M=.5,y=.1,R=0,N=0,B=1.5,h=1,D=[0,0,0];if(i.material){let w=i.material;E=w.name||`Material_${t.length}`,w.color&&(P=[w.color.r,w.color.g,w.color.b]),typeof w.roughness=="number"&&(M=w.roughness),typeof w.metalness=="number"&&(y=w.metalness),typeof w.clearcoat=="number"&&(R=w.clearcoat),typeof w.clearcoatRoughness=="number"&&(N=w.clearcoatRoughness),typeof w.ior=="number"&&(B=w.ior);let f=typeof w.opacity=="number"?w.opacity:1,A=typeof w.transmission=="number"?w.transmission:0;if(h=f*(1-A),w.emissive&&(w.emissive.r>0||w.emissive.g>0||w.emissive.b>0)){let u=w.emissiveIntensity??1;D=[w.emissive.r*u,w.emissive.g*u,w.emissive.b*u]}}let g,F=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof F=="function"){let w=e?.duration??4,f=e?.fps??4,A=Math.max(2,Math.round(w*f)+1),u=[],T=[],d=[],p=[],C=[i.position.x,i.position.y,i.position.z],x=[i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w],L=[i.scale.x,i.scale.y,i.scale.z],I=!1;for(let H=0;H<A;H++){let G=H/(A-1)*w;u.push(G);try{F(G)}catch{}T.push([i.position.x,i.position.y,i.position.z]),d.push([i.quaternion.x,i.quaternion.y,i.quaternion.z,i.quaternion.w]),p.push([i.scale.x,i.scale.y,i.scale.z]),(Math.abs(i.position.x-C[0])>1e-4||Math.abs(i.position.y-C[1])>1e-4||Math.abs(i.position.z-C[2])>1e-4||Math.abs(i.quaternion.x-x[0])>1e-4||Math.abs(i.quaternion.y-x[1])>1e-4||Math.abs(i.quaternion.z-x[2])>1e-4||Math.abs(i.quaternion.w-x[3])>1e-4||Math.abs(i.scale.x-L[0])>1e-4)&&(I=!0)}i.position.set(C[0],C[1],C[2]),i.quaternion.set(x[0],x[1],x[2],x[3]),i.scale.set(L[0],L[1],L[2]),I&&(g={times:u,translations:T,rotations:d,scales:p})}let U=i;if(U.isInstancedMesh&&typeof U.count=="number"&&U.count>0&&U.instanceMatrix?.array){let w=Math.min(1e3,Math.floor(U.count)),f=U.instanceMatrix.array,A=U.instanceColor?.array,u=i.name||`Mesh_${t.length}`,T=new Float32Array(16),d=new Float32Array(9);for(let p=0;p<w;p++){let C=f.subarray(p*16,(p+1)*16);ee(T,l,C);let x=new Float32Array(a*3);for(let G=0;G<a;G++){let v=s.getX(G),V=s.getY(G),k=s.getZ(G);x[G*3]=T[0]*v+T[4]*V+T[8]*k+T[12],x[G*3+1]=T[1]*v+T[5]*V+T[9]*k+T[13],x[G*3+2]=T[2]*v+T[6]*V+T[10]*k+T[14]}let L;if(r.attributes.normal){let G=r.attributes.normal;L=new Float32Array(a*3),re(d,T);for(let v=0;v<a;v++){let V=G.getX(v),k=G.getY(v),O=G.getZ(v),W=d[0]*V+d[3]*k+d[6]*O,S=d[1]*V+d[4]*k+d[7]*O,_=d[2]*V+d[5]*k+d[8]*O,$=Math.hypot(W,S,_)||1;L[v*3]=W/$,L[v*3+1]=S/$,L[v*3+2]=_/$}}let I=P,H=E;A&&A.length>=(p+1)*3&&(I=[P[0]*A[p*3],P[1]*A[p*3+1],P[2]*A[p*3+2]],H=`${E}_inst_${p}`),t.push({name:`${u}_${p}`,positions:x,indices:m,normals:L,uvs:c,materialName:H,color:I,roughness:M,metallic:y,clearcoat:R,clearcoatRoughness:N,ior:B,opacity:h,emissiveColor:D,xrTraits:i.userData?.xr})}return}t.push({name:i.name||`Mesh_${t.length}`,positions:b,indices:m,normals:o,uvs:c,materialName:E,color:P,roughness:M,metallic:y,clearcoat:R,clearcoatRoughness:N,ior:B,opacity:h,emissiveColor:D,xrTraits:i.userData?.xr,timeSamples:g})}}),t}function je(n){let e=[],t=n.gltf,i=ae().decoders.get("meshopt");i&&typeof i.decodeBufferViews=="function"&&i.decodeBufferViews(t,n);let r=n.bin,s=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),a=t.accessors||[],b=t.bufferViews||[],l=t.materials||[],o=t.meshes||[],c=t.nodes||[];function m(M){let y=a[M];if(!y)throw new Error(`Accessor ${M} not found`);let R=b[y.bufferView||0],N=(R.byteOffset||0)+(y.byteOffset||0),B=R.byteLength||0,h=s.slice(N,N+B);return{acc:y,buffer:h}}let E=new Map;if(c.length>0){let M=we(t);for(let y=0;y<M.length;y++)E.set(y,M[y])}function P(M,y,R,N){let B=o[M];if(!B)return;let h=new Float32Array(9);re(h,y);for(let D=0;D<(B.primitives||[]).length;D++){let g=B.primitives[D],F=g.attributes?.POSITION;if(F===void 0)continue;let{acc:U,buffer:w}=m(F),f=new Float32Array(w,0,U.count*3),A=new Float32Array(f.length);for(let S=0;S<U.count;S++){let _=f[S*3],$=f[S*3+1],z=f[S*3+2];A[S*3]=y[0]*_+y[4]*$+y[8]*z+y[12],A[S*3+1]=y[1]*_+y[5]*$+y[9]*z+y[13],A[S*3+2]=y[2]*_+y[6]*$+y[10]*z+y[14]}let u,T=g.attributes?.NORMAL;if(T!==void 0){let{acc:S,buffer:_}=m(T),$=new Float32Array(_,0,S.count*3);u=new Float32Array($.length);for(let z=0;z<S.count;z++){let K=$[z*3],Q=$[z*3+1],X=$[z*3+2],Z=h[0]*K+h[3]*Q+h[6]*X,oe=h[1]*K+h[4]*Q+h[7]*X,j=h[2]*K+h[5]*Q+h[8]*X,ue=Math.hypot(Z,oe,j)||1;u[z*3]=Z/ue,u[z*3+1]=oe/ue,u[z*3+2]=j/ue}}let d,p=g.attributes?.TEXCOORD_0;if(p!==void 0){let{acc:S,buffer:_}=m(p);d=new Float32Array(_,0,S.count*2)}let C;if(g.indices!==void 0){let{acc:S,buffer:_}=m(g.indices);S.componentType===5125?C=new Uint32Array(_,0,S.count):C=new Uint16Array(_,0,S.count);let $=U.count;for(let z of C)if(z>=$)throw new Error(`SecurityError: Index buffer value (${z}) out of vertex bounds [0, ${$}).`)}else{let S=U.count;C=S>65535?new Uint32Array(S):new Uint16Array(S);for(let _=0;_<S;_++)C[_]=_}let x="DefaultMaterial",L=[.8,.8,.8],I=.5,H=.1,G=0,v=0,V=1.5,k=1,O=[0,0,0];if(g.material!==void 0&&l[g.material]){let S=l[g.material];x=S.name||`Material_${g.material}`;let _=S.pbrMetallicRoughness||{},$=1;Array.isArray(_.baseColorFactor)&&(L=[_.baseColorFactor[0],_.baseColorFactor[1],_.baseColorFactor[2]],typeof _.baseColorFactor[3]=="number"&&($=_.baseColorFactor[3])),typeof _.roughnessFactor=="number"&&(I=_.roughnessFactor),typeof _.metallicFactor=="number"&&(H=_.metallicFactor),Array.isArray(S.emissiveFactor)&&S.emissiveFactor.length>=3&&(O=[S.emissiveFactor[0],S.emissiveFactor[1],S.emissiveFactor[2]]);let z=S.extensions||{};z.KHR_materials_clearcoat&&(G=z.KHR_materials_clearcoat.clearcoatFactor??0,v=z.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),z.KHR_materials_ior&&typeof z.KHR_materials_ior.ior=="number"&&(V=z.KHR_materials_ior.ior);let K=z.KHR_materials_transmission?.transmissionFactor??0;k=$*(1-K)}let W=(B.primitives||[]).length>1?`${R}_p${D}`:R;e.push({name:W,positions:A,indices:C,normals:u,uvs:d,materialName:x,color:L,roughness:I,metallic:H,clearcoat:G,clearcoatRoughness:v,ior:V,opacity:k,emissiveColor:O,xrTraits:N?.xr||B.extras?.xr})}}if(c.length>0)for(let M=0;M<c.length;M++){let y=c[M];if(y.mesh!==void 0&&y.mesh<o.length){let R=E.get(M)||J(),N=y.name||o[y.mesh].name||`Node_${M}`,B=y.extensions?.EXT_mesh_gpu_instancing?.attributes;if(B&&typeof B=="object"){let h=B.TRANSLATION,D=B.ROTATION,g=B.SCALE,F=h!==void 0?(()=>{let{acc:A,buffer:u}=m(h);return new Float32Array(u,0,A.count*3)})():null,U=D!==void 0?(()=>{let{acc:A,buffer:u}=m(D);return new Float32Array(u,0,A.count*4)})():null,w=g!==void 0?(()=>{let{acc:A,buffer:u}=m(g);return new Float32Array(u,0,A.count*3)})():null,f=Math.min(1e3,F?F.length/3:U?U.length/4:w?w.length/3:0);if(f>0){let A=new Float32Array(16),u=new Float32Array(16);for(let T=0;T<f;T++){let d=F?[F[T*3],F[T*3+1],F[T*3+2]]:[0,0,0],p=U?[U[T*4],U[T*4+1],U[T*4+2],U[T*4+3]]:[0,0,0,1],C=w?[w[T*3],w[T*3+1],w[T*3+2]]:[1,1,1];ye(A,p,d,C),ee(u,R,A),P(y.mesh,u,`${N}_${T}`,y.extras)}continue}}P(y.mesh,R,N,y.extras)}}else{let M=J();for(let y=0;y<o.length;y++){let R=o[y].name||`Mesh_${y}`;P(y,M,R,o[y].extras)}}return e}function Le(n,e){if(!n||typeof n!="string")return e;let t=n.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(t)&&(t="_"+t),t||e}function Ye(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function q(n){if(!Number.isFinite(n)||Math.abs(n)<1e-7)return"0";let e=Number(n.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function Ze(n){let e=n.length/3,t=new Array(e);for(let i=0;i<e;i++)t[i]=`(${q(n[i*3])}, ${q(n[i*3+1])}, ${q(n[i*3+2])})`;return t.join(", ")}function xt(n,e){let t=new Array(e);for(let i=0;i<e;i++)t[i]=`(${q(n[i*2])}, ${q(1-n[i*2+1])})`;return t.join(", ")}function vt(n){return Array.from(n).join(", ")}function _e(n){let e=new Map;for(let l of n){let o=Le(l.materialName,"DefaultMaterial");e.has(o)||e.set(o,{color:l.color||[.8,.8,.8],roughness:l.roughness??.5,metallic:l.metallic??0,clearcoat:l.clearcoat??0,clearcoatRoughness:l.clearcoatRoughness??0,ior:l.ior??1.5,opacity:l.opacity??1,emissiveColor:l.emissiveColor||[0,0,0]})}let t=0,i=null;for(let l of n){if(l.timeSamples&&l.timeSamples.times.length>0){let o=l.timeSamples.times[l.timeSamples.times.length-1];o>t&&(t=o)}l.xrTraits?.anchor&&!i&&(i=l.xrTraits.anchor==="vertical"||l.xrTraits.anchor==="wall"?"vertical":"horizontal")}let r="";t>0&&(r=`startTimeCode = 0
|
|
233
|
+
endTimeCode = ${q(t)}
|
|
210
234
|
timeCodesPerSecond = 1.0
|
|
211
235
|
`);let s="";i&&(s=`uniform token preliminary:anchoring:type = "plane"
|
|
212
236
|
uniform token preliminary:planeAnchoring:alignment = "${i}"
|
|
213
|
-
`);let
|
|
237
|
+
`);let a=`#usda 1.0
|
|
214
238
|
(
|
|
215
239
|
defaultPrim = "Root"
|
|
216
240
|
metersPerUnit = 1.0
|
|
@@ -223,55 +247,55 @@ kind = "component"
|
|
|
223
247
|
{
|
|
224
248
|
${s}def Scope "Materials"
|
|
225
249
|
{
|
|
226
|
-
`;for(let[
|
|
227
|
-
`,
|
|
228
|
-
`),
|
|
229
|
-
`),
|
|
230
|
-
`),(
|
|
231
|
-
`),
|
|
250
|
+
`;for(let[l,o]of e.entries()){let[c,m,E]=o.color,[P,M,y]=o.emissiveColor,R="";o.clearcoat>0&&(R+=`float inputs:clearcoat = ${q(o.clearcoat)}
|
|
251
|
+
`,R+=`float inputs:clearcoatRoughness = ${q(o.clearcoatRoughness)}
|
|
252
|
+
`),o.ior!==1.5&&(R+=`float inputs:ior = ${q(o.ior)}
|
|
253
|
+
`),o.opacity<1&&(R+=`float inputs:opacity = ${q(o.opacity)}
|
|
254
|
+
`),(P>0||M>0||y>0)&&(R+=`color3f inputs:emissiveColor = (${q(P)}, ${q(M)}, ${q(y)})
|
|
255
|
+
`),a+=`def Material "${l}"
|
|
232
256
|
{
|
|
233
257
|
def Shader "PBRShader"
|
|
234
258
|
{
|
|
235
259
|
uniform token info:id = "UsdPreviewSurface"
|
|
236
|
-
color3f inputs:diffuseColor = (${
|
|
237
|
-
float inputs:metallic = ${
|
|
238
|
-
float inputs:roughness = ${
|
|
239
|
-
${
|
|
260
|
+
color3f inputs:diffuseColor = (${q(c)}, ${q(m)}, ${q(E)})
|
|
261
|
+
float inputs:metallic = ${q(o.metallic)}
|
|
262
|
+
float inputs:roughness = ${q(o.roughness)}
|
|
263
|
+
${R}token outputs:surface
|
|
240
264
|
}
|
|
241
|
-
token outputs:surface.connect = </Root/Materials/${
|
|
265
|
+
token outputs:surface.connect = </Root/Materials/${l}/PBRShader.outputs:surface>
|
|
242
266
|
}
|
|
243
|
-
`}
|
|
267
|
+
`}a+=`}
|
|
244
268
|
def Scope "Meshes"
|
|
245
269
|
{
|
|
246
|
-
`;let
|
|
270
|
+
`;let b=new Set;for(let l=0;l<n.length;l++){let o=n[l],c=o.positions.length/3,m=1/0,E=1/0,P=1/0,M=-1/0,y=-1/0,R=-1/0;for(let U=0;U<c;U++){let w=o.positions[U*3],f=o.positions[U*3+1],A=o.positions[U*3+2];w<m&&(m=w),w>M&&(M=w),f<E&&(E=f),f>y&&(y=f),A<P&&(P=A),A>R&&(R=A)}isFinite(m)||(m=E=P=-1,M=y=R=1);let N=Math.floor(o.indices.length/3),B=Le(o.materialName,"DefaultMaterial"),h=Le(o.name,`Mesh_${l}`);b.has(h)&&(h=`${h}_${l}`),b.add(h);let D=N>0?N===1?"3":"3, ".repeat(N-1)+"3":"",g=o.xrTraits,F="";if(g){let U=[];g.physics&&g.physics!=="none"&&U.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let w=ae().xrTraitSerializer?.usdLines(g,Ye)??[];if(!w.length)for(let f of["grab","billboard","follow","anchor","physics"]){let A=f==="follow"&&typeof g.follow=="object"?g.follow.mode??"head":g[f];A!==void 0&&w.push(`string ${f} = "${Ye(A)}"`)}w.length>0&&U.push(`customData = {
|
|
247
271
|
dictionary xr = {
|
|
248
|
-
${
|
|
272
|
+
${w.join(`
|
|
249
273
|
`)}
|
|
250
274
|
}
|
|
251
|
-
}`),
|
|
252
|
-
${
|
|
275
|
+
}`),U.length>0&&(F=` (
|
|
276
|
+
${U.join(`
|
|
253
277
|
`)}
|
|
254
|
-
)`)}if(
|
|
278
|
+
)`)}if(a+=`def Mesh "${h}"${F}
|
|
255
279
|
{
|
|
256
|
-
`,
|
|
257
|
-
bool physics:kinematicEnabled = ${
|
|
280
|
+
`,g?.physics&&g.physics!=="none"){let U=g.physics==="static"?"true":"false";a+=`bool physics:rigidBodyEnabled = true
|
|
281
|
+
bool physics:kinematicEnabled = ${U}
|
|
258
282
|
bool physics:collisionEnabled = true
|
|
259
|
-
`}if(
|
|
260
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
283
|
+
`}if(o.timeSamples&&o.timeSamples.times.length>0){let U=o.timeSamples,w=U.times.map((u,T)=>{let d=U.translations?.[T]||[0,0,0];return`${q(u)}: (${q(d[0])}, ${q(d[1])}, ${q(d[2])})`}).join(", "),f=U.times.map((u,T)=>{let d=U.rotations?.[T]||[0,0,0,1];return`${q(u)}: (${q(d[3])}, ${q(d[0])}, ${q(d[1])}, ${q(d[2])})`}).join(", "),A=U.times.map((u,T)=>{let d=U.scales?.[T]||[1,1,1];return`${q(u)}: (${q(d[0])}, ${q(d[1])}, ${q(d[2])})`}).join(", ");a+=`double3 xformOp:translate.timeSamples = { ${w} }
|
|
284
|
+
quatf xformOp:orient.timeSamples = { ${f} }
|
|
261
285
|
double3 xformOp:scale.timeSamples = { ${A} }
|
|
262
286
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
263
|
-
`}
|
|
264
|
-
int[] faceVertexCounts = [${
|
|
265
|
-
int[] faceVertexIndices = [${
|
|
266
|
-
point3f[] points = [${
|
|
267
|
-
`,
|
|
287
|
+
`}a+=`float3[] extent = [(${q(m)}, ${q(E)}, ${q(P)}), (${q(M)}, ${q(y)}, ${q(R)})]
|
|
288
|
+
int[] faceVertexCounts = [${D}]
|
|
289
|
+
int[] faceVertexIndices = [${vt(o.indices)}]
|
|
290
|
+
point3f[] points = [${Ze(o.positions)}]
|
|
291
|
+
`,o.normals&&o.normals.length===o.positions.length&&(a+=`normal3f[] normals = [${Ze(o.normals)}] (
|
|
268
292
|
interpolation = "vertex"
|
|
269
293
|
)
|
|
270
|
-
`),
|
|
294
|
+
`),o.uvs&&o.uvs.length===c*2&&(a+=`texCoord2f[] primvars:st = [${xt(o.uvs,c)}] (
|
|
271
295
|
interpolation = "vertex"
|
|
272
296
|
)
|
|
273
|
-
`),
|
|
297
|
+
`),a+=`rel material:binding = </Root/Materials/${B}>
|
|
274
298
|
}
|
|
275
|
-
`}return
|
|
299
|
+
`}return a+=`}
|
|
276
300
|
}
|
|
277
|
-
`,
|
|
301
|
+
`,a}function Mt(n,e){if(n&&typeof n.traverse=="function"){let r=yt(n,e);return _e(r)}let t=xe(n),i=je(t);return _e(i)}var De=null;function Tt(n){if(!De){De=new Uint32Array(256);for(let t=0;t<256;t++){let i=t;for(let r=0;r<8;r++)i=i&1?3988292384^i>>>1:i>>>1;De[t]=i}}let e=4294967295;for(let t=0;t<n.length;t++)e=De[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function Je(n){let e=[],t=0,i=[];for(let c of n){let m=Fe(c.filename),E=Tt(c.data),P=c.data.length,M=30+m.length,y=t+M,R=0,N=y%64;N!==0&&(R=64-N);let B=new Uint8Array(M+R),h=new DataView(B.buffer);h.setUint32(0,67324752,!0),h.setUint16(4,20,!0),h.setUint16(6,0,!0),h.setUint16(8,0,!0),h.setUint16(10,0,!0),h.setUint16(12,0,!0),h.setUint32(14,E,!0),h.setUint32(18,P,!0),h.setUint32(22,P,!0),h.setUint16(26,m.length,!0),h.setUint16(28,R,!0),B.set(m,30),R>0&&B.fill(0,30+m.length),e.push({offset:t,size:P,crc:E,filenameBytes:m,entry:c}),i.push(B),i.push(c.data),t+=B.length+c.data.length}let r=t;for(let c of e){let m=new Uint8Array(46+c.filenameBytes.length),E=new DataView(m.buffer);E.setUint32(0,33639248,!0),E.setUint16(4,20,!0),E.setUint16(6,20,!0),E.setUint16(8,0,!0),E.setUint16(10,0,!0),E.setUint16(12,0,!0),E.setUint16(14,0,!0),E.setUint32(16,c.crc,!0),E.setUint32(20,c.size,!0),E.setUint32(24,c.size,!0),E.setUint16(28,c.filenameBytes.length,!0),E.setUint16(30,0,!0),E.setUint16(32,0,!0),E.setUint16(34,0,!0),E.setUint16(36,0,!0),E.setUint32(38,0,!0),E.setUint32(42,c.offset,!0),m.set(c.filenameBytes,46),i.push(m),t+=m.length}let s=t-r,a=new Uint8Array(22),b=new DataView(a.buffer);b.setUint32(0,101010256,!0),b.setUint16(4,0,!0),b.setUint16(6,0,!0),b.setUint16(8,e.length,!0),b.setUint16(10,e.length,!0),b.setUint32(12,s,!0),b.setUint32(16,r,!0),b.setUint16(20,0,!0),i.push(a),t+=22;let l=new Uint8Array(t),o=0;for(let c of i)l.set(c,o),o+=c.length;return l}function At(n){let e=Mt(n),t=Fe(e);return Je([{filename:"model.usda",data:t}])}function Rt(n){let e=xe(n),t=je(e),i=_e(t),r=Fe(i);return Je([{filename:"model.usda",data:r}])}function wt(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?At(n):Rt(n)}function Bt(n){let e=wt(n);return new Blob([e],{type:"model/vnd.usdz+zip"})}export{Je as buildUSDZZip,Tt as calculateCRC32,Ue as compileInteractivityGraph,Bt as createUSDZBlob,Fe as encodeUtf8,je as extractMeshesFromGLB,yt as extractMeshesFromScene,Mt as generateUSDA,_e as generateUSDAFromMeshes,wt as generateUSDZ,Rt as glbToUSDZ,Le as sanitizeUsdIdentifier,Ye as sanitizeUsdStringLiteral,gt as sceneToCanvas3D,Ut as sceneToGLB,At as sceneToUSDZ};
|