three-live 0.0.1-alpha.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +58 -0
- package/dist/index.d.ts +224 -0
- package/dist/three-author-engine.js +297 -0
- package/dist/three-author.cjs +297 -0
- package/dist/three-author.d.ts +224 -0
- package/dist/three-author.js +297 -0
- package/dist/three-convert.cjs +291 -0
- package/dist/three-convert.d.ts +224 -0
- package/dist/three-convert.js +291 -0
- package/dist/three-live-animation.cjs +36 -0
- package/dist/three-live-animation.d.ts +224 -0
- package/dist/three-live-animation.js +36 -0
- package/dist/three-live-animation.min.js +36 -0
- package/dist/three-live-element.cjs +222 -0
- package/dist/three-live-element.d.ts +224 -0
- package/dist/three-live-element.js +222 -0
- package/dist/three-live-extras.cjs +42 -0
- package/dist/three-live-extras.d.ts +224 -0
- package/dist/three-live-extras.js +42 -0
- package/dist/three-live-extras.min.js +42 -0
- package/dist/three-live-full.cjs +341 -0
- package/dist/three-live-full.js +341 -0
- package/dist/three-live-full.min.js +341 -0
- package/dist/three-live-sandbox.html +157 -0
- package/dist/three-live-viewer.cjs +222 -0
- package/dist/three-live-viewer.d.ts +224 -0
- package/dist/three-live-viewer.js +222 -0
- package/dist/three-live-viewer.min.js +222 -0
- package/dist/three-live.cjs +299 -0
- package/dist/three-live.js +299 -0
- package/dist/three-live.min.js +299 -0
- package/dist/three-view.cjs +222 -0
- package/dist/three-view.d.ts +224 -0
- package/dist/three-view.js +222 -0
- package/dist/three-xr.cjs +291 -0
- package/dist/three-xr.d.ts +224 -0
- package/dist/three-xr.js +291 -0
- package/package.json +78 -6
- package/index.js +0 -1
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
"use strict";var ThreeEngine=(()=>{var zt=Object.defineProperty;var Kn=Object.getOwnPropertyDescriptor;var Zn=Object.getOwnPropertyNames;var Jn=Object.prototype.hasOwnProperty;var Qn=(n,e)=>{for(var t in e)zt(n,t,{get:e[t],enumerable:!0})},er=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Zn(e))!Jn.call(n,i)&&i!==t&&zt(n,i,{get:()=>e[i],enumerable:!(r=Kn(e,i))||r.enumerable});return n};var tr=n=>er(zt({},"__esModule",{value:!0}),n);var $r={};Qn($r,{AmbientLight:()=>qe,BoxGeometry:()=>We,BufferAttribute:()=>X,BufferGeometry:()=>ce,Camera:()=>Ke,CapsuleGeometry:()=>Nt,CircleGeometry:()=>Ot,Clock:()=>Ct,Color:()=>he,ConeGeometry:()=>xt,CylinderGeometry:()=>Ee,DirectionalLight:()=>_t,DodecahedronGeometry:()=>Ut,Euler:()=>Xe,Float32BufferAttribute:()=>pt,Group:()=>At,HemisphereLight:()=>Je,IcosahedronGeometry:()=>Lt,Light:()=>Me,Material:()=>me,MathUtils:()=>Ln,Matrix3:()=>dt,Matrix4:()=>ye,Mesh:()=>Ue,MeshBasicMaterial:()=>Et,MeshLambertMaterial:()=>Mt,MeshPhongMaterial:()=>Rt,MeshPhysicalMaterial:()=>St,MeshStandardMaterial:()=>Se,Object3D:()=>ie,OctahedronGeometry:()=>Pt,PerspectiveCamera:()=>Fe,PlaneGeometry:()=>gt,PointLight:()=>je,PolyhedronFallbackGeometry:()=>_e,Quaternion:()=>Ge,RawShaderMaterial:()=>Hn,RectAreaLight:()=>Xn,RingGeometry:()=>kt,Scene:()=>Ae,SceneQuotaValidator:()=>pe,ShaderMaterial:()=>Ze,SphereGeometry:()=>$e,SpotLight:()=>Bt,THREE:()=>Qe,TetrahedronGeometry:()=>Ft,Texture:()=>Ye,TextureLoader:()=>Tt,TorusGeometry:()=>vt,TorusKnotGeometry:()=>wt,Uint16BufferAttribute:()=>bt,Uint32BufferAttribute:()=>yt,Vector2:()=>mt,Vector3:()=>j,Vector4:()=>ft,WebGLRenderer:()=>Dt,authorScriptRunner:()=>zn,buildSandboxWorkerSource:()=>rn,clearAuthorWarnings:()=>on,default:()=>Wr,exportSceneToCanvas3D:()=>en,exportSceneToGLB:()=>tn,exportSceneToUSDZ:()=>Pn,generateUSDZ:()=>Yt,getAllowClientScripts:()=>Nn,getAuthorWarnings:()=>Vn,getSandboxEngineSrc:()=>nn,getSandboxIframeSrc:()=>Fn,glbToUSDZ:()=>lt,isAllowedSandboxEngineUrl:()=>Re,noopProxy:()=>Pe,sceneToCanvas3D:()=>Ie,sceneToGLB:()=>ze,sceneToUSDZ:()=>Le,setAllowClientScripts:()=>Fr,setSandboxEngineSrc:()=>Ir,setSandboxIframeSrc:()=>Pr,threeAuthorPlugin:()=>He,threeMicroPlugin:()=>Gr,toTrustedWorkerScriptURL:()=>Un,validateSandboxWorkerMessage:()=>sn,warnUnsupported:()=>se});function nt(n,e,t){let r=[],i=new Map,s=[],c=[],m=[],u=new Map,o=b=>{let w=i.get(b);return w===void 0&&(w=r.length,r.push({op:b}),i.set(b,w)),w},a=b=>{let w=u.get(b);return w===void 0&&(w=m.length,m.push({id:b}),u.set(b,w)),w},h=(b,w={})=>s.push({declaration:o(b),...w})-1,l=(b,w,y)=>c.push({id:b,type:w,value:y})-1,d=b=>({node:b,socket:"value"}),f=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(f&&typeof f=="object"){let b=Array.isArray(f.graphs)?f.graphs[f.graph??0]:f;if(b&&Array.isArray(b.nodes)){let w=Array.isArray(b.declarations)?b.declarations:[];for(let y of w)y?.op&&o(y.op);Array.isArray(b.variables)&&c.push(...b.variables);for(let y of b.events||[])y?.id&&a(y.id);for(let y of b.nodes){if(!y||typeof y!="object")continue;let R=y.op||(typeof y.declaration=="number"?w[y.declaration]?.op:"");s.push(R?{...y,declaration:o(R)}:{...y})}}}let T=(b,w,y="translation")=>y==="baseColorFactor"||y==="metallicFactor"||y==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${y}`:y==="emissiveFactor"||y==="alphaCutoff"?`/materials/${Math.max(0,w)}/${y}`:y==="visible"?`/nodes/${b}/extensions/KHR_node_visibility/visible`:`/nodes/${b}/${y}`,A=new Map;n.forEach((b,w)=>{typeof b?.name=="string"&&!A.has(b.name)&&A.set(b.name,w)});let S=(b,w)=>typeof b.target=="string"&&A.has(b.target)?A.get(b.target):typeof b.targetNode=="number"?b.targetNode:w,L=b=>{let w=n[b];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let b=0;b<n.length;b++){let w=n[b],y=w?.extras?.interactivity;if(!y||typeof y!="object")continue;let R=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,p=M=>{let _=Array.isArray(M)?M:[M],I=[];for(let v=0;v<_.length;v++){let x=_[v];if(!x||typeof x!="object")continue;let P=x.action||"interpolate",D=typeof x.duration=="number"?x.duration:.35;if(P==="toggleTransform"){let V=x.property==="rotation"||x.property==="scale"?x.property:"translation",N=V==="rotation"?w.rotation||[0,0,0,1]:V==="scale"?w.scale||[1,1,1]:w.translation||[0,0,0],U=`/nodes/${b}/${V}`,F=l(`__toggle_${b}_${v}`,"bool",!1),C=h("variable/get",{configuration:{variable:F}}),B=h("math/not",{values:{a:d(C)}}),k=h("variable/set",{configuration:{variable:F},values:{value:d(B)}}),z=h("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.to)?x.to:N},duration:{value:D}}}),O=h("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.from)?x.from:N},duration:{value:D}}});s[k].flows={out:{node:h("flow/branch",{values:{condition:d(C)},flows:{true:{node:z},false:{node:O}}})}},I.push(k)}else if(P==="interpolate"){let V=x.to??x.value;if(V===void 0)continue;let N={value:{value:V},duration:{value:D}};x.from!==void 0&&(N.from={value:x.from}),I.push(h("pointer/interpolate",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:T(S(x,b),L(S(x,b)),x.property)},values:N}))}else if(P==="setProperty"){if(x.value===void 0)continue;I.push(h("pointer/set",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:T(S(x,b),L(S(x,b)),x.property)},values:{value:{value:x.value}}}))}else if(P==="toggleVisibility"){let V=S(x,b),N=l(`__vis_${V}_${v}`,"bool",!0),U=h("variable/get",{configuration:{variable:N}}),F=h("math/not",{values:{a:d(U)}}),C=h("variable/set",{configuration:{variable:N},values:{value:d(F)}});s[C].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:d(U)}})}},I.push(C)}else if(P==="cycleMaterialColor"&&Array.isArray(x.colors)&&x.colors.length>0){let V=typeof x.duration=="number"?x.duration:.25,N=`/materials/${Math.max(0,R)}/pbrMetallicRoughness/baseColorFactor`,U=l(`__color_idx_${b}_${v}`,"int",0),F=h("variable/get",{configuration:{variable:U}}),C=h("math/add",{values:{a:d(F),b:{value:1}}}),B=h("math/rem",{values:{a:d(C),b:{value:x.colors.length}}}),k=h("variable/set",{configuration:{variable:U},values:{value:d(B)}}),z={};for(let O=0;O<x.colors.length;O++){let H=x.colors[O],Y=Array.isArray(H)&&H.length>=3?[H[0],H[1],H[2],H[3]??1]:[1,1,1,1];z[String(O)]={node:V>0?h("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Y},duration:{value:V}}}):h("pointer/set",{configuration:{pointer:N},values:{value:{value:Y}}})}}s[k].flows={out:{node:h("flow/switch",{values:{selection:d(F)},flows:z})}},I.push(k)}else if(P==="playAnimation")I.push(h("animation/start",{configuration:{animation:x.animation??x.clip??0}}));else if(P==="stopAnimation")I.push(h("animation/stop"));else if(P==="sendEvent"){let V={};for(let[N,U]of Object.entries(x.values||{}))V[N]={value:U};I.push(h("event/send",{configuration:{event:a(String(x.event??x.id??"custom"))},values:V}))}}if(!I.length)return null;if(I.length===1)return I[0];let g={};return I.forEach((v,x)=>{g[String(x)]={node:v}}),h("flow/sequence",{flows:g})},E=(M,_,I)=>{let g=p(_);g!==null&&h(M,{...I?{configuration:I}:{},flows:{out:{node:g}}})};if(y.onSelect&&E("pointer/onSelect",y.onSelect,{nodeIndex:b}),y.onHoverIn&&E("pointer/onHoverIn",y.onHoverIn,{nodeIndex:b}),y.onHoverOut&&E("pointer/onHoverOut",y.onHoverOut,{nodeIndex:b}),y.onStart&&E("event/onStart",y.onStart),y.onReceive&&typeof y.onReceive=="object")for(let[M,_]of Object.entries(y.onReceive))E("event/receive",_,{event:a(M)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:c,events:m}],graph:0}:null}var an='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',cn="Security Error: client-side scripts require allow-client-scripts opt-in.";var rt="__THREE_LIVE_REGISTRY__";function J(){let n=typeof globalThis<"u"?globalThis:{};if(!n[rt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,rt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[rt]=e}}return n[rt]}var K=J().plugins;function un(n){let e=J().plugins;e.some(t=>t.name===n.name)||e.push(n)}function ln(){return J().plugins}function q(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function it(n,e,t,r,i){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let c=1/(r-i);return n[10]=(i+r)*c,n[14]=2*i*r*c,n}function Ce(n,e,t,r){let[i,s,c]=e,[m,u,o]=r,[a,h,l]=t,d=i-a,f=s-h,T=c-l,A=Math.hypot(d,f,T);A<=1e-5?(d=0,f=0,T=1):(d/=A,f/=A,T/=A);let S=u*T-o*f,L=o*d-m*T,b=m*f-u*d;A=Math.hypot(S,L,b),A<=1e-5?(S=0,L=0,b=0):(S/=A,L/=A,b/=A);let w=f*b-T*L,y=T*S-d*b,R=d*L-f*S;return A=Math.hypot(w,y,R),A<=1e-5?(w=0,y=0,R=0):(w/=A,y/=A,R/=A),n[0]=S,n[1]=w,n[2]=d,n[3]=0,n[4]=L,n[5]=y,n[6]=f,n[7]=0,n[8]=b,n[9]=R,n[10]=T,n[11]=0,n[12]=-(S*i+L*s+b*c),n[13]=-(w*i+y*s+R*c),n[14]=-(d*i+f*s+T*c),n[15]=1,n}function re(n,e,t){let r=e[0],i=e[1],s=e[2],c=e[3],m=e[4],u=e[5],o=e[6],a=e[7],h=e[8],l=e[9],d=e[10],f=e[11],T=e[12],A=e[13],S=e[14],L=e[15],b=t[0],w=t[1],y=t[2],R=t[3];return n[0]=b*r+w*m+y*h+R*T,n[1]=b*i+w*u+y*l+R*A,n[2]=b*s+w*o+y*d+R*S,n[3]=b*c+w*a+y*f+R*L,b=t[4],w=t[5],y=t[6],R=t[7],n[4]=b*r+w*m+y*h+R*T,n[5]=b*i+w*u+y*l+R*A,n[6]=b*s+w*o+y*d+R*S,n[7]=b*c+w*a+y*f+R*L,b=t[8],w=t[9],y=t[10],R=t[11],n[8]=b*r+w*m+y*h+R*T,n[9]=b*i+w*u+y*l+R*A,n[10]=b*s+w*o+y*d+R*S,n[11]=b*c+w*a+y*f+R*L,b=t[12],w=t[13],y=t[14],R=t[15],n[12]=b*r+w*m+y*h+R*T,n[13]=b*i+w*u+y*l+R*A,n[14]=b*s+w*o+y*d+R*S,n[15]=b*c+w*a+y*f+R*L,n}function st(n,e,t,r){let i=e[0],s=e[1],c=e[2],m=e[3],u=i+i,o=s+s,a=c+c,h=i*u,l=i*o,d=i*a,f=s*o,T=s*a,A=c*a,S=m*u,L=m*o,b=m*a,w=r[0],y=r[1],R=r[2];return n[0]=(1-(f+A))*w,n[1]=(l+b)*w,n[2]=(d-L)*w,n[3]=0,n[4]=(l-b)*y,n[5]=(1-(h+A))*y,n[6]=(T+S)*y,n[7]=0,n[8]=(d+L)*R,n[9]=(T-S)*R,n[10]=(1-(h+f))*R,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function ae(n,e){let t=e[0],r=e[1],i=e[2],s=e[4],c=e[5],m=e[6],u=e[8],o=e[9],a=e[10],h=a*c-m*o,l=-a*s+m*u,d=o*s-c*u,f=t*h+r*l+i*d;return f&&(f=1/f,n[0]=h*f,n[1]=(-a*r+i*o)*f,n[2]=(m*r-i*c)*f,n[3]=l*f,n[4]=(a*t-i*u)*f,n[5]=(-m*t+i*s)*f,n[6]=d*f,n[7]=(-o*t+r*u)*f,n[8]=(c*t-r*s)*f),n}function hn(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],c=e[4],m=e[5],u=e[6],o=e[7],a=e[8],h=e[9],l=e[10],d=e[11],f=e[12],T=e[13],A=e[14],S=e[15],L=t*m-r*c,b=t*u-i*c,w=t*o-s*c,y=r*u-i*m,R=r*o-s*m,p=i*o-s*u,E=a*T-h*f,M=a*A-l*f,_=a*S-d*f,I=h*A-l*T,g=h*S-d*T,v=l*S-d*A,x=L*v-b*g+w*I+y*_-R*M+p*E;return x?(x=1/x,n[0]=(m*v-u*g+o*I)*x,n[1]=(i*g-r*v-s*I)*x,n[2]=(T*p-A*R+S*y)*x,n[3]=(l*R-h*p-d*y)*x,n[4]=(u*_-c*v-o*M)*x,n[5]=(t*v-i*_+s*M)*x,n[6]=(A*w-f*p-S*b)*x,n[7]=(a*p-l*w+d*b)*x,n[8]=(c*g-m*_+o*E)*x,n[9]=(r*_-t*g-s*E)*x,n[10]=(f*R-T*w+S*L)*x,n[11]=(h*w-a*R-d*L)*x,n[12]=(m*M-c*I-u*E)*x,n[13]=(t*I-r*M+i*E)*x,n[14]=(T*b-f*y-A*L)*x,n[15]=(a*y-h*b+l*L)*x,n):null}function Vt(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],c=i[1]*e+i[5]*t+i[9]*r+i[13],m=i[2]*e+i[6]*t+i[10]*r+i[14],u=i[3]*e+i[7]*t+i[11]*r+i[15],o=u!==0?1/u:1;n[0]=s*o,n[1]=c*o,n[2]=m*o}function mn(n,e,t,r,i,s,c,m,u,o,a,h,l,d,f,T,A=0){let S=o-c,L=a-m,b=h-u,w=l-c,y=d-m,R=f-u,p=i*R-s*y,E=s*w-r*R,M=r*y-i*w,_=S*p+L*E+b*M;if(_>-1e-7&&_<1e-7)return!1;let I=1/_,g=n-c,v=e-m,x=t-u,P=I*(g*p+v*E+x*M);if(P<-A||P>1+A)return!1;let D=v*b-x*L,V=x*S-g*b,N=g*L-v*S,U=I*(r*D+i*V+s*N);if(U<-A||P+U>1+A)return!1;let F=I*(w*D+y*V+R*N);if(F>1e-4&&F<T.distance){T.distance=F,T.point=[n+r*F,e+i*F,t+s*F];let C=L*R-b*y,B=b*w-S*R,k=S*y-L*w,z=Math.hypot(C,B,k)||1;return T.normal=[C/z,B/z,k/z],!0}return!1}function ot(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let a=0;a<t;a++)r.push(q());if(t===0)return r;let i=new Set;for(let a of n.nodes)if(Array.isArray(a.children))for(let h of a.children)i.add(h);let s=new Set,c=128,m=(a,h,l=0)=>{if(l>c||a<0||a>=t||s.has(a))return;s.add(a);let d=n.nodes[a];if(!d)return;let f=q();if(e&&e[a])f.set(e[a]);else if(d.matrix&&d.matrix.length===16)f.set(d.matrix);else{let A=d.translation||[0,0,0],S=d.rotation||[0,0,0,1],L=d.scale||[1,1,1];st(f,S,A,L)}let T=r[a];if(h?re(T,h,f):T.set(f),Array.isArray(d.children))for(let A of d.children)typeof A=="number"&&m(A,T,l+1)},u=[],o=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(o&&Array.isArray(o.nodes))u.push(...o.nodes);else for(let a=0;a<t;a++)i.has(a)||u.push(a);for(let a of u)m(a,null);for(let a=0;a<t;a++)!i.has(a)&&!u.includes(a)&&m(a,null);return r}function nr(n){return new TextDecoder().decode(n)}var pn=J().decoders;function rr(n,e){pn.set(n.toLowerCase(),e)}function Oe(n){return pn.get(n.toLowerCase())}function bn(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 r=t.getUint32(0,!0);if(r!==1179937895){let l=t.getUint8(0);throw l===123||l===32||l===10||l===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let s=t.getUint32(8,!0),c=12,m=null,u=null;for(;c+8<=s&&c+8<=e.byteLength;){let l=t.getUint32(c,!0),d=t.getUint32(c+4,!0),f=c+8;if(f+l>e.byteLength)throw new Error(`Truncated GLB chunk: required ${f+l} bytes, buffer has ${e.byteLength}`);if(d===1313821514){let T=new Uint8Array(e,f,l),A=nr(T);m=JSON.parse(A,(S,L)=>S==="__proto__"||S==="constructor"||S==="prototype"?void 0:L)}else d===5130562&&(u=e.slice(f,f+l));c=f+l}if(!m)throw new Error("Missing JSON chunk in GLB");let o=m.extensionsRequired||[];if(o.includes("KHR_draco_mesh_compression")&&!Oe("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(o.includes("EXT_meshopt_compression")&&!Oe("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(o.includes("KHR_texture_basisu")&&!Oe("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=u||new ArrayBuffer(0),h={gltf:m,bin:a,animations:[]};for(let l of K)l.onParseGLB?.(h);return h}function ir(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 Be(n){if(ir(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return bn(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var yn=`#version 300 es
|
|
18
|
+
layout(location=0) in vec3 aPosition;
|
|
19
|
+
layout(location=1) in vec3 aNormal;
|
|
20
|
+
layout(location=2) in vec2 aUV;
|
|
21
|
+
uniform mat4 uMVP,uModel;
|
|
22
|
+
uniform mat3 uNormalMatrix;
|
|
23
|
+
uniform vec4 uUvTransform;
|
|
24
|
+
out vec3 vNormal,vWorldPos;
|
|
25
|
+
out vec2 vUV;
|
|
26
|
+
void main(){
|
|
27
|
+
vec3 rawN=uNormalMatrix*aNormal;
|
|
28
|
+
vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
|
|
29
|
+
vec4 world=uModel*vec4(aPosition,1.0);
|
|
30
|
+
vWorldPos=world.xyz;
|
|
31
|
+
vec2 scaleUV=uUvTransform.zw;
|
|
32
|
+
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
33
|
+
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
34
|
+
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
35
|
+
}`,gn=`#version 300 es
|
|
36
|
+
precision highp float;
|
|
37
|
+
in vec3 vNormal,vWorldPos;
|
|
38
|
+
in vec2 vUV;
|
|
39
|
+
uniform vec4 uBaseColor;
|
|
40
|
+
uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity;
|
|
41
|
+
uniform vec2 uClearcoat;
|
|
42
|
+
uniform vec3 uCameraPos,uAmbientColor;
|
|
43
|
+
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uXrDepthTex;
|
|
44
|
+
uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uXrDepthEnabled,uXrDepthFormat;
|
|
45
|
+
uniform float uNormalScale,uOcclusionStrength,uXrRawValueToMeters;
|
|
46
|
+
uniform mat4 uXrDepthUVTransform;
|
|
47
|
+
uniform vec2 uViewportSize;
|
|
48
|
+
uniform vec4 uViewport;
|
|
49
|
+
uniform vec3 uCameraFwd;
|
|
50
|
+
uniform int uToneMapping,uNumDirLights,uNumPointLights;
|
|
51
|
+
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
|
|
52
|
+
out vec4 fragColor;
|
|
53
|
+
|
|
54
|
+
vec2 envBRDF(float r,float n){
|
|
55
|
+
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04);
|
|
56
|
+
vec4 rv=r*c0+c1;
|
|
57
|
+
float a=min(rv.x*rv.x,exp2(-9.28*n))*rv.x+rv.y;
|
|
58
|
+
return vec2(-1.04,1.04)*a+rv.zw;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
vec3 F_SchlickRoughness(vec3 F0,float r,float n){
|
|
62
|
+
return F0+(max(vec3(1.0-r),F0)-F0)*pow(clamp(1.0-n,0.0,1.0),5.0);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
vec3 getStudioRadiance(vec3 R,float r){
|
|
66
|
+
vec3 kd=normalize(vec3(0.0,1.0,0.35));
|
|
67
|
+
float ki=pow(max(dot(R,kd),0.0),mix(96.0,1.5,r))*mix(2.4,0.5,r);
|
|
68
|
+
vec3 fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
69
|
+
float fi=pow(max(dot(R,fd),0.0),mix(36.0,1.2,r))*mix(1.3,0.35,r);
|
|
70
|
+
float ri=pow(clamp(1.0-abs(R.y),0.0,1.0),3.5)*mix(0.55,0.22,r);
|
|
71
|
+
vec3 ag=mix(vec3(0.06,0.06,0.08),vec3(0.48,0.50,0.55),R.y*0.5+0.5);
|
|
72
|
+
return ag+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
vec3 perturbNormal(vec3 N,vec3 V,vec2 uv,sampler2D normalMap,float scale){
|
|
76
|
+
vec3 mapNormal=texture(normalMap,uv).xyz*2.0-1.0;
|
|
77
|
+
mapNormal.xy*=scale;
|
|
78
|
+
vec3 dp1=dFdx(vWorldPos);
|
|
79
|
+
vec3 dp2=dFdy(vWorldPos);
|
|
80
|
+
vec2 duv1=dFdx(uv);
|
|
81
|
+
vec2 duv2=dFdy(uv);
|
|
82
|
+
vec3 dp2perp=cross(dp2,N);
|
|
83
|
+
vec3 dp1perp=cross(N,dp1);
|
|
84
|
+
vec3 T=dp2perp*duv1.x+dp1perp*duv2.x;
|
|
85
|
+
vec3 B=dp2perp*duv1.y+dp1perp*duv2.y;
|
|
86
|
+
float invmax=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
87
|
+
return normalize(mat3(T*invmax,B*invmax,N)*normalize(mapNormal));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
vec2 equirectangularUV(vec3 dir){
|
|
91
|
+
vec3 d=normalize(dir);
|
|
92
|
+
float u=atan(d.z,d.x)*0.15915494309+0.5;
|
|
93
|
+
float v=asin(clamp(d.y,-1.0,1.0))*0.31830988618+0.5;
|
|
94
|
+
return vec2(u,1.0-v);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
vec3 neutralToneMapping(vec3 color){
|
|
98
|
+
const float startCompression=0.76;
|
|
99
|
+
const float desaturation=0.15;
|
|
100
|
+
float x=min(color.r,min(color.g,color.b));
|
|
101
|
+
float offset=x<0.08?x-6.25*x*x:0.04;
|
|
102
|
+
color-=offset;
|
|
103
|
+
float peak=max(color.r,max(color.g,color.b));
|
|
104
|
+
if(peak<startCompression)return color;
|
|
105
|
+
const float d=1.0-startCompression;
|
|
106
|
+
float newPeak=1.0-d*d/(peak+d-startCompression);
|
|
107
|
+
color*=newPeak/peak;
|
|
108
|
+
float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
|
|
109
|
+
return mix(color,newPeak*vec3(1.0),g);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
vec3 applyToneMapping(vec3 color,int mode){
|
|
113
|
+
if(mode==0)return neutralToneMapping(color);
|
|
114
|
+
if(mode==1)return color/(color+vec3(1.0));
|
|
115
|
+
return color;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
void main(){
|
|
119
|
+
vec4 base=uBaseColor;
|
|
120
|
+
if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
|
|
121
|
+
if(length(vNormal)<1e-4&&uHasTexture==1){
|
|
122
|
+
vec3 unlit=base.rgb+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
123
|
+
fragColor=vec4(unlit,base.a);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
vec3 N=length(vNormal)<1e-4?normalize(cross(dFdx(vWorldPos),dFdy(vWorldPos))):normalize(vNormal);
|
|
127
|
+
if(!gl_FrontFacing)N=-N;
|
|
128
|
+
vec3 V=normalize(uCameraPos-vWorldPos);
|
|
129
|
+
if(uHasNormalTexture==1){
|
|
130
|
+
N=perturbNormal(N,V,vUV,uNormalTexture,uNormalScale);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
float metallic=uMetallic;
|
|
134
|
+
float roughness=uRoughness;
|
|
135
|
+
if(uHasMetallicRoughnessTexture==1){
|
|
136
|
+
vec4 mr=texture(uMetallicRoughnessTexture,vUV);
|
|
137
|
+
roughness*=mr.g;
|
|
138
|
+
metallic*=mr.b;
|
|
139
|
+
}
|
|
140
|
+
roughness=clamp(roughness,0.04,1.0);
|
|
141
|
+
metallic=clamp(metallic,0.0,1.0);
|
|
142
|
+
|
|
143
|
+
float occ=1.0;
|
|
144
|
+
if(uHasOcclusionTexture==1){
|
|
145
|
+
occ=mix(1.0,texture(uOcclusionTexture,vUV).r,uOcclusionStrength);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
float gloss=1.0-roughness;
|
|
149
|
+
float specExp=mix(16.0,256.0,gloss*gloss);
|
|
150
|
+
float specWeight=mix(0.22*gloss,1.0,metallic);
|
|
151
|
+
vec3 directLight=vec3(0.0);
|
|
152
|
+
for(int i=0;i<2;i++){
|
|
153
|
+
if(i>=uNumDirLights)break;
|
|
154
|
+
vec3 L=normalize(uDirLightDir[i]);
|
|
155
|
+
float NdotL=max(dot(N,L),0.0);
|
|
156
|
+
vec3 H=normalize(L+V);
|
|
157
|
+
float NoH=max(dot(N,H),0.0);
|
|
158
|
+
float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
|
|
159
|
+
directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uDirLightColor[i];
|
|
160
|
+
}
|
|
161
|
+
for(int i=0;i<2;i++){
|
|
162
|
+
if(i>=uNumPointLights)break;
|
|
163
|
+
vec3 toLight=uPointLightPos[i]-vWorldPos;
|
|
164
|
+
float dist=length(toLight);
|
|
165
|
+
vec3 L=toLight/max(dist,0.0001);
|
|
166
|
+
float atten=1.0/(1.0+0.09*dist+0.032*dist*dist);
|
|
167
|
+
float NdotL=max(dot(N,L),0.0);
|
|
168
|
+
vec3 H=normalize(L+V);
|
|
169
|
+
float NoH=max(dot(N,H),0.0);
|
|
170
|
+
float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
|
|
171
|
+
directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uPointLightColor[i]*atten;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
vec3 R=reflect(-V,N);
|
|
175
|
+
float NoV=clamp(dot(N,V),0.001,1.0);
|
|
176
|
+
vec3 F0=mix(vec3(0.04),base.rgb,metallic);
|
|
177
|
+
vec3 F=F_SchlickRoughness(F0,roughness,NoV);
|
|
178
|
+
vec2 brdf=envBRDF(roughness,NoV);
|
|
179
|
+
|
|
180
|
+
vec3 specularIBL;
|
|
181
|
+
vec3 envDiffuse;
|
|
182
|
+
if(uHasEnvironmentMap==1){
|
|
183
|
+
specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
|
|
184
|
+
envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
|
|
185
|
+
}else{
|
|
186
|
+
specularIBL=getStudioRadiance(R,roughness)*(F*brdf.x+brdf.y);
|
|
187
|
+
envDiffuse=mix(vec3(0.10,0.10,0.12),vec3(0.52,0.54,0.58),N.y*0.5+0.5);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
vec3 kD=(vec3(1.0)-F)*(1.0-metallic);
|
|
191
|
+
vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
192
|
+
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
193
|
+
if(uClearcoat.x>0.0){
|
|
194
|
+
vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
|
|
195
|
+
color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
196
|
+
}
|
|
197
|
+
color=applyToneMapping(color,uToneMapping);
|
|
198
|
+
float outAlpha=base.a;
|
|
199
|
+
if(uXrDepthEnabled==1){
|
|
200
|
+
vec2 normViewUV=vec2((gl_FragCoord.x-uViewport.x)/max(uViewport.z,1.0),1.0-(gl_FragCoord.y-uViewport.y)/max(uViewport.w,1.0));
|
|
201
|
+
vec2 depthUV=(uXrDepthUVTransform*vec4(normViewUV,0.0,1.0)).xy;
|
|
202
|
+
if(depthUV.x>=0.0&&depthUV.x<=1.0&&depthUV.y>=0.0&&depthUV.y<=1.0){
|
|
203
|
+
vec4 depthSample=texture(uXrDepthTex,depthUV);
|
|
204
|
+
float rawDepth=uXrDepthFormat==1?depthSample.r:(depthSample.r*255.0+depthSample.a*65280.0);
|
|
205
|
+
float realDepth=rawDepth*uXrRawValueToMeters;
|
|
206
|
+
float virtDepth=dot(uCameraFwd,uCameraFwd)>0.5?dot(vWorldPos-uCameraPos,uCameraFwd):length(uCameraPos-vWorldPos);
|
|
207
|
+
if(rawDepth>0.0&&(uXrDepthFormat==1||rawDepth<65500.0)&&realDepth>0.15&&realDepth<20.0&&virtDepth>realDepth+0.02){
|
|
208
|
+
float occAlpha=1.0-smoothstep(0.0,0.035,virtDepth-realDepth-0.02);
|
|
209
|
+
outAlpha*=occAlpha;
|
|
210
|
+
if(outAlpha<0.01)discard;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
fragColor=vec4(color,outAlpha);
|
|
215
|
+
}`,sr=`#version 300 es
|
|
216
|
+
layout(location=0) in vec3 aPosition;
|
|
217
|
+
uniform mat4 uMVP;
|
|
218
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,or=`#version 300 es
|
|
219
|
+
precision highp float;
|
|
220
|
+
uniform vec4 uColorId;
|
|
221
|
+
out vec4 fragColor;
|
|
222
|
+
void main(){fragColor=uColorId;}`;function fn(n,e,t){let r=n.createShader(e);if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,35713)){let i=n.getShaderInfoLog(r);throw n.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function Xt(n,e,t){let r=fn(n,35633,e),i=fn(n,35632,t),s=n.createProgram();if(n.attachShader(s,r),n.attachShader(s,i),n.linkProgram(s),!n.getProgramParameter(s,35714)){let c=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${c}`)}return s}function Gt(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var xn=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uXrDepthTex","uXrDepthEnabled","uXrDepthFormat","uXrRawValueToMeters","uXrDepthUVTransform","uViewportSize","uViewport","uCameraFwd"];function ar(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 Ht(n,e,t,r,i,s,c){if(r===void 0||!e.accessors?.[r])return null;let m=e.accessors[r],u=e.bufferViews[m.bufferView],o=(u.byteOffset||0)+(m.byteOffset||0),a=u.byteStride&&u.byteStride>s*4?u.byteStride>>2:s,h;if(a===s)h=new Float32Array(t,o,m.count*s);else{h=new Float32Array(m.count*s);let d=new Float32Array(t,u.byteOffset||0,Math.floor(u.byteLength/4)),f=(m.byteOffset||0)>>2;for(let T=0;T<m.count;T++){let A=f+T*a;for(let S=0;S<s;S++)h[T*s+S]=d[A+S]}}let l=n.createBuffer();return c.push(l),n.bindBuffer(34962,l),n.bufferData(34962,h,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),h}var ei=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),vn=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function dn(n,e,t=vn,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:s}=e,c=[],m=ot(i),u=[];if(Array.isArray(i.nodes))for(let E=0;E<i.nodes.length;E++){let M=i.nodes[E];M.mesh!==void 0&&i.meshes&&i.meshes[M.mesh]&&u.push({node:M,nodeIdx:E,meshIdx:M.mesh})}let o=u.length>0?u:(i.meshes||[]).map((E,M)=>({node:E,nodeIdx:-1,meshIdx:M})),a=[];if(Array.isArray(e.lights)&&e.lights.length>0)a.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let E=i.extensions.KHR_lights_punctual.lights;for(let M of E){let _=M.type==="directional"?"directional":M.type==="point"?"point":"ambient";a.push({type:_,color:M.color||[1,1,1],intensity:M.intensity!==void 0?M.intensity:1})}}if(a.length===0&&(a.push({type:"ambient",color:[1,1,1],intensity:.35}),a.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),o.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${o.length}`);let h=[];if(i.textures&&i.images){if(i.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${i.textures.length}`);for(let E=0;E<i.textures.length;E++){let M=i.textures[E],_=i.images[M.source];if(_){let I=n.createTexture();if(n.bindTexture(3553,I),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),_.bufferView!==void 0){let g=i.bufferViews[_.bufferView],v=s.slice(g.byteOffset||0,(g.byteOffset||0)+g.byteLength),x=new Blob([v],{type:_.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(x).then(P=>{n.bindTexture(3553,I),n.texImage2D(3553,0,6408,6408,5121,P),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let g=ar(_.uri);if(g){let v=new Image;v.crossOrigin="anonymous",v.referrerPolicy="no-referrer",v.onload=()=>{n.bindTexture(3553,I),n.texImage2D(3553,0,6408,6408,5121,v),n.generateMipmap(3553),r?.()},v.src=g}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.uri)}h.push(I)}else h.push(null)}}let l=[1/0,1/0,1/0],d=[-1/0,-1/0,-1/0],f=0,T=0;for(let E=0;E<o.length;E++){let M=o[E],_=i.meshes[M.meshIdx],I=M.nodeIdx>=0?m[M.nodeIdx]:q(),g=new Float32Array(9);ae(g,I);let v={name:M.node.name||_.name||`Mesh_${M.meshIdx}`,nodeIndex:M.nodeIdx,transform:I,normalMatrix:g,primitives:[],extras:M.node.extras||_.extras};for(let x of _.primitives||[]){if(x.extensions?.KHR_draco_mesh_compression){let $=Oe("draco");$&&$.decodePrimitive(i,x,s)}let P=[],D=n.createVertexArray();n.bindVertexArray(D);let V=i.accessors[x.attributes.POSITION],N=Number(V?.count??0);if(!Number.isFinite(N)||N<0||f+N>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(f+=N,V?.min&&V?.max)for(let $=0;$<3;$++){let ue=I[12+$],De=I[12+$];for(let be=0;be<3;be++){let et=I[be*4+$]*V.min[be],tt=I[be*4+$]*V.max[be];ue+=et<tt?et:tt,De+=et>tt?et:tt}ue<l[$]&&(l[$]=ue),De>d[$]&&(d[$]=De)}let U=Ht(n,i,s,x.attributes.POSITION,0,3,P);Ht(n,i,s,x.attributes.NORMAL,1,3,P),Ht(n,i,s,x.attributes.TEXCOORD_0,2,2,P);let F=0,C=5123,B=null;if(x.indices!==void 0){let $=i.accessors[x.indices],De=(i.bufferViews[$.bufferView].byteOffset||0)+($.byteOffset||0);if(F=Number($.count??0),!Number.isFinite(F)||F<0||T+F>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);T+=F,C=$.componentType===5125?5125||5125:5123||5123;let be=n.createBuffer();P.push(be),n.bindBuffer(34963,be),$.componentType===5125?(B=new Uint32Array(s,De,$.count),n.bufferData(34963,B,35044)):(B=new Uint16Array(s,De,$.count),n.bufferData(34963,B,35044))}else F=V.count;let k={};for(let $ of K)if($.onBuildPrimitiveVAO){let ue=$.onBuildPrimitiveVAO(n,D,x,i,s);ue&&(k[$.name]=ue)}n.bindVertexArray(null);let z=i.materials&&x.material!==void 0?i.materials[x.material]:null,O=yn,H=gn,Y=!1;for(let $ of K)if($.onResolveShader){let ue=$.onResolveShader(x,z,O,H);ue&&(O=ue.vs,H=ue.fs,Y=!0)}let W=Y?Xt(n,O,H):null,fe=W?Gt(n,W,xn):null,ee=z?.pbrMetallicRoughness,ne=ee?.baseColorFactor||[.8,.8,.8,1],ge=ee?.metallicFactor??.1,xe=ee?.roughnessFactor??.5,de=z?.extensions?.KHR_materials_clearcoat,oe=de?de.clearcoatFactor??1:0,ve=Math.max(.04,de?.clearcoatRoughnessFactor??.04),we=ee?.baseColorTexture!==void 0&&h[ee.baseColorTexture.index]?h[ee.baseColorTexture.index]:null,ke=ee?.metallicRoughnessTexture!==void 0&&h[ee.metallicRoughnessTexture.index]?h[ee.metallicRoughnessTexture.index]:null,Wn=z?.normalTexture!==void 0&&h[z.normalTexture.index]?h[z.normalTexture.index]:null,$n=z?.normalTexture?.scale??1,Yn=z?.occlusionTexture!==void 0&&h[z.occlusionTexture.index]?h[z.occlusionTexture.index]:null,qn=z?.occlusionTexture?.strength??1,jn=!!(z?.extensions?.KHR_materials_transmission||k.materials?.isTransmissive);v.primitives.push({vao:D,indexCount:F,indexType:C,baseColor:ne,metallic:ge,roughness:xe,clearcoat:oe,clearcoatRoughness:ve,positions:U,indices:B,texture:we,metallicRoughnessTexture:ke,normalTexture:Wn,occlusionTexture:Yn,normalScale:$n,occlusionStrength:qn,buffers:P,materialIndex:x.material,pluginData:k,customProgram:W,customUniforms:fe,isTransmissive:jn})}c.push(v)}isFinite(l[0])||(l=[-1,-1,-1]),isFinite(d[0])||(d=[1,1,1]);let A=[(l[0]+d[0])/2,(l[1]+d[1])/2,(l[2]+d[2])/2],S=d[0]-l[0],L=d[1]-l[1],b=d[2]-l[2],w=Math.max(Math.hypot(S,L,b)/2,.5),y=[l[0],l[1],l[2]],R=[d[0],d[1],d[2]],p=e.animations;if(!p){for(let E of K)if(E.onParseGLB?.(e),e.animations){p=e.animations;break}}return p||(p=[]),{meshes:c,bounds:{center:A,radius:w,min:y,max:R},lights:a,animations:p,worldMatrices:m}}var at=class{constructor(e,t,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=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 i,s;if(t&&typeof t.getContext=="function"?(i=t,s=r):(s=t,i=s?.canvas),!i){let u=e.querySelector("canvas");u||(u=document.createElement("canvas"),u.style.width="100%",u.style.height="100%",u.style.display="block",u.style.touchAction="none",e.prepend(u)),i=u}this.canvas=i,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let c=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!c:c&&(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 m=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m,this.renderProg=Xt(m,yn,gn),this.pickProg=Xt(m,sr,or),this.uRender=Gt(m,this.renderProg,xn),this.uPick=Gt(m,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){rr(e,t)}static getDecoder(e){return Oe(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:s,animations:c,worldMatrices:m}=dn(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=c||[],this.worldMatrices=m||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let o of e.gltf.nodes)this.initialNodeTransforms.push({t:o.translation?[o.translation[0],o.translation[1],o.translation[2]]:[0,0,0],r:o.rotation?[o.rotation[0],o.rotation[1],o.rotation[2],o.rotation[3]]:[0,0,0,1],s:o.scale?[o.scale[0],o.scale[1],o.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let o of K)o.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let 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(bn(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(Be(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Be(e),{meshes:i}=dn(this.gl,r,vn,()=>this.render());if(t)for(let s of i)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],ae(s.normalMatrix,s.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),ae(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],s=[],c=[],m=[];for(let u of this.lights){let o=u.color||[1,1,1],a=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[o[0]*a,o[1]*a,o[2]*a];else if(u.type==="directional"&&i.length<6){let h=u.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),s.push(o[0]*a,o[1]*a,o[2]*a)}else if(u.type==="point"&&c.length<6){let h=u.position||[0,0,0];c.push(h[0],h[1],h[2]),m.push(o[0]*a,o[1]*a,o[2]*a)}}i.length===0&&(i.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,c.length/3),c.length>0&&(t.uniform3fv(e.uPointLightPos,c),t.uniform3fv(e.uPointLightColor,m)),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 K)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of K)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let i=this.meshes.flatMap(a=>a.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),s=i[0],c=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,u=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,o={baseColorFactor:c,metallicFactor:m,roughnessFactor:u,setBaseColorFactor:a=>{let h=[a[0],a[1],a[2],a[3]??1];o.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let l of i)l.baseColor=h;this.render()},setMetallicFactor:a=>{o.metallicFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=a);for(let h of i)h.metallic=a;this.render()},setRoughnessFactor:a=>{o.roughnessFactor=a,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=a);for(let h of i)h.roughness=a;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:o}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of K)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=q();re(r,this.projMatrix,this.viewMatrix);let[i,s,c]=e,m=t?t[0]:0,u=t?t[1]:0,o=t?t[2]:0,a=this.modelRootMatrix;a&&(i=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],s=a[1]*e[0]+a[5]*e[1]+a[9]*e[2]+a[13],c=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]+a[14],t&&(m=a[0]*t[0]+a[4]*t[1]+a[8]*t[2],u=a[1]*t[0]+a[5]*t[1]+a[9]*t[2],o=a[2]*t[0]+a[6]*t[1]+a[10]*t[2]));let h=r[0]*i+r[4]*s+r[8]*c+r[12],l=r[1]*i+r[5]*s+r[9]*c+r[13],d=r[2]*i+r[6]*s+r[10]*c+r[14],f=r[3]*i+r[7]*s+r[11]*c+r[15];if(f<=1e-4)return{x:0,y:0,z:1,visible:!1};let T=h/f,A=l/f,S=d/f,L=this.canvas.getBoundingClientRect(),b=L.width||this.canvas.clientWidth||this.canvas.width||300,w=L.height||this.canvas.clientHeight||this.canvas.height||150,y=(T*.5+.5)*b,R=(-A*.5+.5)*w,p=T>=-1.1&&T<=1.1&&A>=-1.1&&A<=1.1&&S>=-1&&S<=1;if(p&&t){let E=this.customTarget||this.bounds.center,M=E[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=E[1]+this.currDistance*Math.sin(this.currPhi),I=E[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),g=[i-M,s-_,c-I];m*g[0]+u*g[1]+o*g[2]>.05&&(p=!1)}return{x:y,y:R,z:S,visible:p}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let c=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],m=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],o=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-i*c[0]+s*m[0])*o,u[1]+=(-i*c[1]+s*m[1])*o,u[2]+=(-i*c[2]+s*m[2])*o,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,c=r.height||300,m=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),u=i.height>0?Math.floor((t-i.top)*(c/i.height)):Math.floor(t);return this.performMeshPick(m,u,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,s=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let m=q();re(m,this.projMatrix,this.viewMatrix);let u=[],o=Math.max(0,Math.min(s-1,e)),a=Math.max(0,Math.min(c-1,c-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==c)&&this.resizePickingFbo(s,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let p=0;p<this.meshes.length;p++){let E=this.meshes[p];if(E.visible===!1||E.isPluginMesh)continue;let M=p+1,_=(M&255)/255,I=(M>>8&255)/255,g=(M>>16&255)/255;i.uniform4f(this.uPick.uColorId,_,I,g,1),re(this.modelMatrix,this.modelRootMatrix,E.transform),re(this.mvpMatrix,m,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let v of E.primitives)i.bindVertexArray(v.vao),i.drawElements(4,v.indexCount,v.indexType,0)}let y=new Uint8Array(4);i.readPixels(o,a,1,1,6408,5121,y),i.bindFramebuffer(36160,null);let R=y[0]+(y[1]<<8)+(y[2]<<16);R>0&&R<=this.meshes.length&&(u=[this.meshes[R-1]])}u.length===0&&(u=this.meshes.filter(y=>y.visible!==!1));let h=null,l=1/0,d=[0,0,0],f=[0,1,0],T=this.customTarget||this.bounds.center,A=T[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),S=T[1]+this.currDistance*Math.sin(this.currPhi),L=T[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let y of u){re(this.modelMatrix,this.modelRootMatrix,y.transform),re(this.mvpMatrix,m,this.modelMatrix);let R=q();if(!hn(R,this.mvpMatrix))continue;let p=(o+.5)/s*2-1,E=(a+.5)/c*2-1,M=[0,0,0],_=[0,0,0];Vt(M,p,E,-1,R),Vt(_,p,E,1,R);let I=_[0]-M[0],g=_[1]-M[1],v=_[2]-M[2],x=Math.hypot(I,g,v)||1,P=I/x,D=g/x,V=v/x,N={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((F=>{for(let C of y.primitives){if(!C.positions)continue;let B=C.positions,k=C.indices,z=Math.floor(k?k.length/3:B.length/9);for(let O=0;O<z;O++){let H=k?k[O*3]:O*3,Y=k?k[O*3+1]:O*3+1,W=k?k[O*3+2]:O*3+2;mn(M[0],M[1],M[2],P,D,V,B[H*3],B[H*3+1],B[H*3+2],B[Y*3],B[Y*3+1],B[Y*3+2],B[W*3],B[W*3+1],B[W*3+2],N,F)}}})(1e-4),isFinite(N.distance)){let F=N.point[0],C=N.point[1],B=N.point[2],k=this.modelMatrix,z=k[0]*F+k[4]*C+k[8]*B+k[12],O=k[1]*F+k[5]*C+k[9]*B+k[13],H=k[2]*F+k[6]*C+k[10]*B+k[14],Y=z-A,W=O-S,fe=H-L,ee=Math.hypot(Y,W,fe);if(ee<l){ae(this.normalMatrix,this.modelMatrix);let ne=this.normalMatrix,ge=N.normal[0],xe=N.normal[1],de=N.normal[2],oe=ne[0]*ge+ne[3]*xe+ne[6]*de,ve=ne[1]*ge+ne[4]*xe+ne[7]*de,we=ne[2]*ge+ne[5]*xe+ne[8]*de,ke=Math.hypot(oe,ve,we)||1;oe/=ke,ve/=ke,we/=ke,oe*Y+ve*W+we*fe>0&&(oe=-oe,ve=-ve,we=-we),h=y,l=Math.round(ee*1e3)/1e3,d=[Math.round(z*1e3)/1e3,Math.round(O*1e3)/1e3,Math.round(H*1e3)/1e3],f=[Math.round(oe*1e3)/1e3,Math.round(ve*1e3)/1e3,Math.round(we*1e3)/1e3]}}}if(!h)return null;let w={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:l,hitPoint:d,normal:f,screenX:e,screenY:t};if(r){for(let y of K)y.onMeshSelect?.(this,w);this.opts.onMeshClick&&this.opts.onMeshClick(w),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:w}))}return w}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,s=i?e-r:e,c=i?Math.max(1,t-r):r,m=(s+.5)/c*2-1;return Math.floor((m*.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);it(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),s=r[1]+this.currDistance*Math.sin(this.currPhi),c=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Ce(this.viewMatrix,[i,s,c],r,[0,1,0]),re(this.mvpMatrix,this.projMatrix,this.viewMatrix),ae(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let r of K)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of K)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=r-(e*r+t*i),s[13]=0,s[14]=i-(-t*r+e*i),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let c of K)c.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 c of K)c.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=s;let c={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(c),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:c}))}}renderXRView(e,t,r,i,s=!0,c=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let m=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,o=e?.transform?.position,a=o?[o.x,o.y,o.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:m,projMatrix:u,eyePos:a,viewport:i,eye:e?.eye||"none",clear:c>0?!1:e?.eye!=="right",isAR:s})}render(e){if(!e&&this.stereoSBS){let w=Math.max(2,this.canvas.width||2),y=Math.max(1,this.canvas.height||1),R=Math.max(1,Math.floor(w*.5)),p=Math.max(1,w-R),E=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),M=this.customTarget||this.bounds.center,_=M[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),I=M[1]+this.currDistance*Math.sin(this.currPhi),g=M[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),v=Math.cos(this.currTheta),x=-Math.sin(this.currTheta),P=.032,D=q(),V=q(),N=[_-v*P,I,g-x*P],U=[M[0]-v*P*.25,M[1],M[2]-x*P*.25];it(D,this.fov,R/y,.1,E),Ce(V,N,U,[0,1,0]);let F=q(),C=q(),B=[_+v*P,I,g+x*P],k=[M[0]+v*P*.25,M[1],M[2]+x*P*.25];it(F,this.fov,p/y,.1,E),Ce(C,B,k,[0,1,0]),this.render({viewMatrix:V,projMatrix:D,eyePos:N,viewport:[0,0,R,y],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:C,projMatrix:F,eyePos:B,viewport:[R,0,p,y],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,w,y);return}let t=this.gl,r=0,i=0,s=this.canvas.width,c=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],c=e.viewport[3],t.viewport(r,i,s,c)):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 m=q(),u=e?.viewMatrix??this.viewMatrix;re(m,e?.projMatrix??this.projMatrix,u);let o=[-u[2],-u[6],-u[10]],a=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,h=this.customTarget||this.bounds.center,l=e?e.eyePos[0]:h[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),d=e?e.eyePos[1]:h[1]+this.currDistance*Math.sin(this.currPhi),f=e?e.eyePos[2]:h[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let w of K)w.onBeforeDrawScene?.(this,t,m,[l,d,f],a);let T=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&T===0)return;let A=e?.eye||"none",S=!1,L=T>0?[...this.backdropMeshes,...this.meshes]:this.meshes,b=w=>{for(let y=0;y<L.length;y++){let R=L[y];if(R.visible===!1)continue;let p=this.selectedMeshName!==""&&R.name===this.selectedMeshName;y<T||R.worldSpace===!0||R.name==="__xr_reticle__"?this.modelMatrix.set(R.transform):re(this.modelMatrix,this.modelRootMatrix,R.transform),re(this.mvpMatrix,m,this.modelMatrix),ae(R.normalMatrix,this.modelMatrix);let E=R.extras?.xr?.stereo||R.userData?.xr?.stereo,M=0,_=0,I=1,g=1;E==="sbs"?(I=.5,M=A==="right"?.5:0):E==="ou"&&(g=.5,_=A==="right"?.5:0);for(let v of R.primitives){let x=!!v.isTransmissive;if(!w&&x){S=!0;continue}if(w&&!x)continue;let P=v.customProgram||this.renderProg,D=v.customUniforms||this.uRender;t.useProgram(P),t.uniform1i(D.uToneMapping,a),t.uniform1f(D.uEnvIntensity,this.envIntensity),t.uniform3f(D.uCameraPos,l,d,f),D.uCameraFwd&&t.uniform3f(D.uCameraFwd,o[0],o[1],o[2]),t.uniform1f(D.uEmissive,p?1:0),t.uniformMatrix4fv(D.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(D.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(D.uNormalMatrix,!1,R.normalMatrix),D.uUvTransform&&t.uniform4f(D.uUvTransform,M,_,I,g),D.uViewportSize&&t.uniform2f(D.uViewportSize,Math.max(1,s),Math.max(1,c)),D.uViewport&&t.uniform4f(D.uViewport,r,i,Math.max(1,s),Math.max(1,c)),this.xrDepthState.enabled&&this.xrDepthState.texture?(t.activeTexture(33989),t.bindTexture(3553,this.xrDepthState.texture),D.uXrDepthTex&&t.uniform1i(D.uXrDepthTex,5),D.uXrDepthEnabled&&t.uniform1i(D.uXrDepthEnabled,1),D.uXrDepthFormat&&t.uniform1i(D.uXrDepthFormat,this.xrDepthState.format||0),D.uXrRawValueToMeters&&t.uniform1f(D.uXrRawValueToMeters,this.xrDepthState.rawValueToMeters),D.uXrDepthUVTransform&&t.uniformMatrix4fv(D.uXrDepthUVTransform,!1,this.xrDepthState.uvTransform)):D.uXrDepthEnabled&&t.uniform1i(D.uXrDepthEnabled,0),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(D.uEnvironmentMap,4),t.uniform1i(D.uHasEnvironmentMap,1)):t.uniform1i(D.uHasEnvironmentMap,0),this.bindLights(D);for(let V of K)V.onBeforeDrawPrimitive?.(t,P,v,R,this.worldMatrices||[],this.gltf);t.uniform4fv(D.uBaseColor,v.baseColor),t.uniform1f(D.uMetallic,v.metallic),t.uniform1f(D.uRoughness,v.roughness),D.uClearcoat&&t.uniform2f(D.uClearcoat,v.clearcoat??0,v.clearcoatRoughness??.04),v.texture?(t.activeTexture(33984),t.bindTexture(3553,v.texture),t.uniform1i(D.uBaseColorTexture,0),t.uniform1i(D.uHasTexture,1)):t.uniform1i(D.uHasTexture,0),v.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,v.metallicRoughnessTexture),t.uniform1i(D.uMetallicRoughnessTexture,1),t.uniform1i(D.uHasMetallicRoughnessTexture,1)):t.uniform1i(D.uHasMetallicRoughnessTexture,0),v.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,v.normalTexture),t.uniform1i(D.uNormalTexture,2),t.uniform1i(D.uHasNormalTexture,1),t.uniform1f(D.uNormalScale,v.normalScale)):t.uniform1i(D.uHasNormalTexture,0),v.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,v.occlusionTexture),t.uniform1i(D.uOcclusionTexture,3),t.uniform1i(D.uHasOcclusionTexture,1),t.uniform1f(D.uOcclusionStrength,v.occlusionStrength)):t.uniform1i(D.uHasOcclusionTexture,0),t.bindVertexArray(v.vao),t.drawElements(4,v.indexCount,v.indexType,0)}}};if(b(!1),S){for(let w of K)w.onBeforeTransmissivePass?.(t,this);b(!0)}for(let w of K)w.onAfterRender?.(t,this,m)}disposeMeshListGpuResources(e){let t=this.gl;for(let r of e)for(let i of r.primitives){if(i.vao&&t.deleteVertexArray(i.vao),i.buffers)for(let s of i.buffers)t.deleteBuffer(s);i.texture&&t.deleteTexture(i.texture),i.metallicRoughnessTexture&&t.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&t.deleteTexture(i.normalTexture),i.occlusionTexture&&t.deleteTexture(i.occlusionTexture),i.customProgram&&t.deleteProgram(i.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 K)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()}};at.registerPlugin=un,at.getRegisteredPlugins=ln;function cr(n){return n+3&-4}function ur(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 Ie(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],c=[],m=[],u=new Set,o=[],a=[],h=new Map,l=[];function d(p,E){let M=new Uint8Array(p.buffer,p.byteOffset,p.byteLength),_=cr(M.byteLength),I=new Uint8Array(_);I.set(M),t.push(I);let g=i.length;return i.push({buffer:0,byteOffset:r,byteLength:M.byteLength,target:E}),r+=_,g}function f(p,E,M,_,I,g,v){let x=d(p,M),P=s.length,D={bufferView:x,byteOffset:0,componentType:_,count:I,type:E};return g&&(D.min=g),v&&(D.max=v),s.push(D),P}n.traverse(p=>{(p.isLight||p.color&&p.intensity!==void 0)&&l.push({type:p.type,color:[p.color.r,p.color.g,p.color.b],intensity:p.intensity,position:[p.position.x,p.position.y,p.position.z]})});let T=[];function A(p){let E={name:p.name||""},M=p.position,_=p.quaternion,I=p.scale;if((M.x||M.y||M.z)&&(E.translation=[M.x,M.y,M.z]),(_.x||_.y||_.z||_.w!==1)&&(E.rotation=[_.x,_.y,_.z,_.w]),(I.x!==1||I.y!==1||I.z!==1)&&(E.scale=[I.x,I.y,I.z]),p.userData&&Object.keys(p.userData).length>0&&(E.extras=JSON.parse(JSON.stringify(p.userData,(v,x)=>{if(!(v==="__proto__"||v==="prototype"||v==="constructor"))return typeof x=="function"?void 0:x})),p.userData.xr)){let v=ur(p.userData.xr);E.extensions={...E.extensions||{},MOZ_hubs_components:v,ANDROID_xr_scenecore:v},J().xrTraitSerializer?.gltfNode(E,p.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(p.geometry){let v=p.geometry,x=v.attributes.position;if(x&&x.count>0){let P=[1/0,1/0,1/0],D=[-1/0,-1/0,-1/0];for(let F=0;F<x.count;F++){let C=x.getX(F),B=x.getY(F),k=x.getZ(F);C<P[0]&&(P[0]=C),C>D[0]&&(D[0]=C),B<P[1]&&(P[1]=B),B>D[1]&&(D[1]=B),k<P[2]&&(P[2]=k),k>D[2]&&(D[2]=k)}let N={attributes:{POSITION:f(x.array,"VEC3",34962,5126,x.count,P,D)}};if(v.attributes.normal&&(N.attributes.NORMAL=f(v.attributes.normal.array,"VEC3",34962,5126,v.attributes.normal.count)),v.attributes.uv&&(N.attributes.TEXCOORD_0=f(v.attributes.uv.array,"VEC2",34962,5126,v.attributes.uv.count)),v.index){let F=v.index.array instanceof Uint32Array;N.indices=f(v.index.array,"SCALAR",34963,F?5125:5123,v.index.count)}if(p.material){let F=h.get(p.material);if(F===void 0){F=a.length,h.set(p.material,F);let C=p.material,B={name:C.name||"",pbrMetallicRoughness:{baseColorFactor:[C.color.r,C.color.g,C.color.b,C.opacity],metallicFactor:C.metalness,roughnessFactor:C.roughness},doubleSided:C.side===2||C.doubleSided};if(C.emissive&&(C.emissive.r>0||C.emissive.g>0||C.emissive.b>0)){let z=C.emissiveIntensity??1;B.emissiveFactor=[C.emissive.r*z,C.emissive.g*z,C.emissive.b*z]}let k={};C.clearcoat>0&&(k.KHR_materials_clearcoat={clearcoatFactor:C.clearcoat,clearcoatRoughnessFactor:C.clearcoatRoughness||0}),C.sheen>0&&(k.KHR_materials_sheen={sheenColorFactor:C.sheenColor?[C.sheenColor.r,C.sheenColor.g,C.sheenColor.b]:[1,1,1],sheenRoughnessFactor:C.sheenRoughness||0}),C.transmission>0&&(k.KHR_materials_transmission={transmissionFactor:C.transmission}),C.thickness>0&&(k.KHR_materials_volume={thicknessFactor:C.thickness,attenuationDistance:C.attenuationDistance??1/0,attenuationColor:C.attenuationColor?[C.attenuationColor.r,C.attenuationColor.g,C.attenuationColor.b]:[1,1,1]}),C.ior!==void 0&&C.ior!==1.5&&(k.KHR_materials_ior={ior:C.ior}),C.dispersion>0&&(k.KHR_materials_dispersion={dispersion:C.dispersion}),C.iridescence>0&&(k.KHR_materials_iridescence={iridescenceFactor:C.iridescence,iridescenceIor:C.iridescenceIOR??1.3}),Object.keys(k).length>0&&(B.extensions=k),a.push(B)}N.material=F}let U=c.length;c.push({primitives:[N],name:p.name,...E.extras?{extras:E.extras}:{}}),E.mesh=U}}let g=m.length;if(m.push(E),o.push(p),p.children.length>0){E.children=[];for(let v of p.children)E.children.push(A(v))}return g}for(let p of n.children)T.push(A(p));let S=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),L=[];if(typeof S=="function"&&o.length>0){let p=e?.duration??4,E=e?.fps??15,M=Math.max(2,Math.round(p*E)+1),_=new Float32Array(M),I=o.map(U=>({px:U.position.x,py:U.position.y,pz:U.position.z,qx:U.quaternion.x,qy:U.quaternion.y,qz:U.quaternion.z,qw:U.quaternion.w,sx:U.scale.x,sy:U.scale.y,sz:U.scale.z})),g=o.map(()=>new Float32Array(M*3)),v=o.map(()=>new Float32Array(M*4)),x=o.map(()=>new Float32Array(M*3));for(let U=0;U<M;U++){let F=U/(M-1)*p;_[U]=F;try{S(F)}catch{}for(let C=0;C<o.length;C++){let B=o[C];g[C][U*3]=B.position.x,g[C][U*3+1]=B.position.y,g[C][U*3+2]=B.position.z,v[C][U*4]=B.quaternion.x,v[C][U*4+1]=B.quaternion.y,v[C][U*4+2]=B.quaternion.z,v[C][U*4+3]=B.quaternion.w,x[C][U*3]=B.scale.x,x[C][U*3+1]=B.scale.y,x[C][U*3+2]=B.scale.z}}for(let U=0;U<o.length;U++){let F=o[U],C=I[U];F.position.set(C.px,C.py,C.pz),F.quaternion.set(C.qx,C.qy,C.qz,C.qw),F.scale.set(C.sx,C.sy,C.sz)}n.updateMatrixWorld(!0);let P=null,D=()=>(P===null&&(P=f(_,"SCALAR",0,5126,M,[0],[p])),P),V=[],N=[];for(let U=0;U<o.length;U++){let F=I[U],C=!1,B=!1,k=!1;for(let z=0;z<M;z++)(Math.abs(g[U][z*3]-F.px)>1e-4||Math.abs(g[U][z*3+1]-F.py)>1e-4||Math.abs(g[U][z*3+2]-F.pz)>1e-4)&&(C=!0),(Math.abs(v[U][z*4]-F.qx)>1e-4||Math.abs(v[U][z*4+1]-F.qy)>1e-4||Math.abs(v[U][z*4+2]-F.qz)>1e-4||Math.abs(v[U][z*4+3]-F.qw)>1e-4)&&(B=!0),(Math.abs(x[U][z*3]-F.sx)>1e-4||Math.abs(x[U][z*3+1]-F.sy)>1e-4||Math.abs(x[U][z*3+2]-F.sz)>1e-4)&&(k=!0);if(C){let z=f(g[U],"VEC3",0,5126,M),O=V.length;V.push({input:D(),interpolation:"LINEAR",output:z}),N.push({sampler:O,target:{node:U,path:"translation"}})}if(B){let z=f(v[U],"VEC4",0,5126,M),O=V.length;V.push({input:D(),interpolation:"LINEAR",output:z}),N.push({sampler:O,target:{node:U,path:"rotation"}})}if(k){let z=f(x[U],"VEC3",0,5126,M),O=V.length;V.push({input:D(),interpolation:"LINEAR",output:z}),N.push({sampler:O,target:{node:U,path:"scale"}})}}N.length>0&&L.push({name:"ProceduralLoop",samplers:V,channels:N})}let b=nt(m,c,n.userData),w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:T}],scene:0,nodes:m,meshes:c,materials:a,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...L.length>0?{animations:L}:{},...b||u.size>0?{extensionsUsed:[...b?["KHR_interactivity"]:[],...u]}:{},...b?{extensions:{KHR_interactivity:b}}:{}},y=new Uint8Array(r),R=0;for(let p of t)y.set(p,R),R+=p.byteLength;return{gltf:w,bin:y.buffer,lights:l,environmentIntensity:n.environmentIntensity}}function ut(n){return new TextEncoder().encode(n)}function ze(n,e){let{gltf:t,bin:r}=Ie(n,e),i=JSON.stringify(t),s=ut(i),c=(4-s.byteLength%4)%4,m=s.byteLength+c,u=20+m+8+r.byteLength,o=new Uint8Array(u),a=new DataView(o.buffer);a.setUint32(0,1179937895,!0),a.setUint32(4,2,!0),a.setUint32(8,u,!0),a.setUint32(12,m,!0),a.setUint32(16,1313821514,!0),o.set(s,20);for(let l=0;l<c;l++)o[20+s.byteLength+l]=32;let h=20+m;return a.setUint32(h,r.byteLength,!0),a.setUint32(h+4,5130562,!0),o.set(new Uint8Array(r),h+8),o}function lr(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,s=i.attributes.position;if(!s||s.count===0)return;let c=s.count,m=new Float32Array(c*3),u=r.matrixWorld.elements;for(let p=0;p<c;p++){let E=s.getX(p),M=s.getY(p),_=s.getZ(p);m[p*3]=u[0]*E+u[4]*M+u[8]*_+u[12],m[p*3+1]=u[1]*E+u[5]*M+u[9]*_+u[13],m[p*3+2]=u[2]*E+u[6]*M+u[10]*_+u[14]}let o;if(i.attributes.normal){let p=i.attributes.normal;o=new Float32Array(c*3);let E=new Float32Array(9);ae(E,u);for(let M=0;M<c;M++){let _=p.getX(M),I=p.getY(M),g=p.getZ(M),v=E[0]*_+E[3]*I+E[6]*g,x=E[1]*_+E[4]*I+E[7]*g,P=E[2]*_+E[5]*I+E[8]*g,D=Math.hypot(v,x,P)||1;o[M*3]=v/D,o[M*3+1]=x/D,o[M*3+2]=P/D}}let a;if(i.attributes.uv){let p=i.attributes.uv;a=new Float32Array(c*2);for(let E=0;E<c;E++)a[E*2]=p.getX(E),a[E*2+1]=p.getY(E)}let h;if(i.index)h=i.index.array;else{h=c>65535?new Uint32Array(c):new Uint16Array(c);for(let p=0;p<c;p++)h[p]=p}let l="DefaultMaterial",d=[.8,.8,.8],f=.5,T=.1,A=0,S=0,L=1.5,b=1,w=[0,0,0];if(r.material){let p=r.material;l=p.name||`Material_${t.length}`,p.color&&(d=[p.color.r,p.color.g,p.color.b]),typeof p.roughness=="number"&&(f=p.roughness),typeof p.metalness=="number"&&(T=p.metalness),typeof p.clearcoat=="number"&&(A=p.clearcoat),typeof p.clearcoatRoughness=="number"&&(S=p.clearcoatRoughness),typeof p.ior=="number"&&(L=p.ior);let E=typeof p.opacity=="number"?p.opacity:1,M=typeof p.transmission=="number"?p.transmission:0;if(b=E*(1-M),p.emissive&&(p.emissive.r>0||p.emissive.g>0||p.emissive.b>0)){let _=p.emissiveIntensity??1;w=[p.emissive.r*_,p.emissive.g*_,p.emissive.b*_]}}let y,R=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 R=="function"){let p=e?.duration??4,E=e?.fps??4,M=Math.max(2,Math.round(p*E)+1),_=[],I=[],g=[],v=[],x=[r.position.x,r.position.y,r.position.z],P=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],D=[r.scale.x,r.scale.y,r.scale.z],V=!1;for(let N=0;N<M;N++){let U=N/(M-1)*p;_.push(U);try{R(U)}catch{}I.push([r.position.x,r.position.y,r.position.z]),g.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),v.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-x[0])>1e-4||Math.abs(r.position.y-x[1])>1e-4||Math.abs(r.position.z-x[2])>1e-4||Math.abs(r.quaternion.x-P[0])>1e-4||Math.abs(r.quaternion.y-P[1])>1e-4||Math.abs(r.quaternion.z-P[2])>1e-4||Math.abs(r.quaternion.w-P[3])>1e-4||Math.abs(r.scale.x-D[0])>1e-4)&&(V=!0)}r.position.set(x[0],x[1],x[2]),r.quaternion.set(P[0],P[1],P[2],P[3]),r.scale.set(D[0],D[1],D[2]),V&&(y={times:_,translations:I,rotations:g,scales:v})}t.push({name:r.name||`Mesh_${t.length}`,positions:m,indices:h,normals:o,uvs:a,materialName:l,color:d,roughness:f,metallic:T,clearcoat:A,clearcoatRoughness:S,ior:L,opacity:b,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:y})}}),t}function En(n){let e=[],t=n.gltf,r=n.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),s=t.accessors||[],c=t.bufferViews||[],m=t.materials||[],u=t.meshes||[],o=t.nodes||[];function a(d){let f=s[d];if(!f)throw new Error(`Accessor ${d} not found`);let T=c[f.bufferView||0],A=(T.byteOffset||0)+(f.byteOffset||0),S=T.byteLength||0,L=i.slice(A,A+S);return{acc:f,buffer:L}}let h=new Map;if(o.length>0){let d=ot(t);for(let f=0;f<d.length;f++)h.set(f,d[f])}function l(d,f,T,A){let S=u[d];if(!S)return;let L=new Float32Array(9);ae(L,f);for(let b=0;b<(S.primitives||[]).length;b++){let w=S.primitives[b],y=w.attributes?.POSITION;if(y===void 0)continue;let{acc:R,buffer:p}=a(y),E=new Float32Array(p,0,R.count*3),M=new Float32Array(E.length);for(let O=0;O<R.count;O++){let H=E[O*3],Y=E[O*3+1],W=E[O*3+2];M[O*3]=f[0]*H+f[4]*Y+f[8]*W+f[12],M[O*3+1]=f[1]*H+f[5]*Y+f[9]*W+f[13],M[O*3+2]=f[2]*H+f[6]*Y+f[10]*W+f[14]}let _,I=w.attributes?.NORMAL;if(I!==void 0){let{acc:O,buffer:H}=a(I),Y=new Float32Array(H,0,O.count*3);_=new Float32Array(Y.length);for(let W=0;W<O.count;W++){let fe=Y[W*3],ee=Y[W*3+1],ne=Y[W*3+2],ge=L[0]*fe+L[3]*ee+L[6]*ne,xe=L[1]*fe+L[4]*ee+L[7]*ne,de=L[2]*fe+L[5]*ee+L[8]*ne,oe=Math.hypot(ge,xe,de)||1;_[W*3]=ge/oe,_[W*3+1]=xe/oe,_[W*3+2]=de/oe}}let g,v=w.attributes?.TEXCOORD_0;if(v!==void 0){let{acc:O,buffer:H}=a(v);g=new Float32Array(H,0,O.count*2)}let x;if(w.indices!==void 0){let{acc:O,buffer:H}=a(w.indices);O.componentType===5125?x=new Uint32Array(H,0,O.count):x=new Uint16Array(H,0,O.count);let Y=R.count;for(let W of x)if(W>=Y)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${Y}).`)}else{let O=R.count;x=O>65535?new Uint32Array(O):new Uint16Array(O);for(let H=0;H<O;H++)x[H]=H}let P="DefaultMaterial",D=[.8,.8,.8],V=.5,N=.1,U=0,F=0,C=1.5,B=1,k=[0,0,0];if(w.material!==void 0&&m[w.material]){let O=m[w.material];P=O.name||`Material_${w.material}`;let H=O.pbrMetallicRoughness||{},Y=1;Array.isArray(H.baseColorFactor)&&(D=[H.baseColorFactor[0],H.baseColorFactor[1],H.baseColorFactor[2]],typeof H.baseColorFactor[3]=="number"&&(Y=H.baseColorFactor[3])),typeof H.roughnessFactor=="number"&&(V=H.roughnessFactor),typeof H.metallicFactor=="number"&&(N=H.metallicFactor),Array.isArray(O.emissiveFactor)&&O.emissiveFactor.length>=3&&(k=[O.emissiveFactor[0],O.emissiveFactor[1],O.emissiveFactor[2]]);let W=O.extensions||{};W.KHR_materials_clearcoat&&(U=W.KHR_materials_clearcoat.clearcoatFactor??0,F=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),W.KHR_materials_ior&&typeof W.KHR_materials_ior.ior=="number"&&(C=W.KHR_materials_ior.ior);let fe=W.KHR_materials_transmission?.transmissionFactor??0;B=Y*(1-fe)}let z=(S.primitives||[]).length>1?`${T}_p${b}`:T;e.push({name:z,positions:M,indices:x,normals:_,uvs:g,materialName:P,color:D,roughness:V,metallic:N,clearcoat:U,clearcoatRoughness:F,ior:C,opacity:B,emissiveColor:k,xrTraits:A?.xr||S.extras?.xr})}}if(o.length>0)for(let d=0;d<o.length;d++){let f=o[d];if(f.mesh!==void 0&&f.mesh<u.length){let T=h.get(d)||q(),A=f.name||u[f.mesh].name||`Node_${d}`;l(f.mesh,T,A,f.extras)}}else{let d=q();for(let f=0;f<u.length;f++){let T=u[f].name||`Mesh_${f}`;l(f,d,T,u[f].extras)}}return e}function Wt(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 wn(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function G(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 Tn(n){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(n)}let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${G(n[r*3])}, ${G(n[r*3+1])}, ${G(n[r*3+2])})`;return t.join(", ")}function hr(n,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(n)}let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${G(n[r*2])}, ${G(1-n[r*2+1])})`;return t.join(", ")}function mr(n){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(n)}return Array.from(n).join(", ")}function $t(n){let e=new Map;for(let u of n){let o=Wt(u.materialName,"DefaultMaterial");e.has(o)||e.set(o,{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,r=null;for(let u of n){if(u.timeSamples&&u.timeSamples.times.length>0){let o=u.timeSamples.times[u.timeSamples.times.length-1];o>t&&(t=o)}u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
|
|
223
|
+
endTimeCode = ${G(t)}
|
|
224
|
+
timeCodesPerSecond = 1.0
|
|
225
|
+
`);let s="";r&&(s=`uniform token preliminary:anchoring:type = "plane"
|
|
226
|
+
uniform token preliminary:planeAnchoring:alignment = "${r}"
|
|
227
|
+
`);let c=`#usda 1.0
|
|
228
|
+
(
|
|
229
|
+
defaultPrim = "Root"
|
|
230
|
+
metersPerUnit = 1.0
|
|
231
|
+
upAxis = "Y"
|
|
232
|
+
${i})
|
|
233
|
+
|
|
234
|
+
def Xform "Root" (
|
|
235
|
+
kind = "component"
|
|
236
|
+
)
|
|
237
|
+
{
|
|
238
|
+
${s}def Scope "Materials"
|
|
239
|
+
{
|
|
240
|
+
`;for(let[u,o]of e.entries()){let[a,h,l]=o.color,[d,f,T]=o.emissiveColor,A="";o.clearcoat>0&&(A+=`float inputs:clearcoat = ${G(o.clearcoat)}
|
|
241
|
+
`,A+=`float inputs:clearcoatRoughness = ${G(o.clearcoatRoughness)}
|
|
242
|
+
`),o.ior!==1.5&&(A+=`float inputs:ior = ${G(o.ior)}
|
|
243
|
+
`),o.opacity<1&&(A+=`float inputs:opacity = ${G(o.opacity)}
|
|
244
|
+
`),(d>0||f>0||T>0)&&(A+=`color3f inputs:emissiveColor = (${G(d)}, ${G(f)}, ${G(T)})
|
|
245
|
+
`),c+=`def Material "${u}"
|
|
246
|
+
{
|
|
247
|
+
def Shader "PBRShader"
|
|
248
|
+
{
|
|
249
|
+
uniform token info:id = "UsdPreviewSurface"
|
|
250
|
+
color3f inputs:diffuseColor = (${G(a)}, ${G(h)}, ${G(l)})
|
|
251
|
+
float inputs:metallic = ${G(o.metallic)}
|
|
252
|
+
float inputs:roughness = ${G(o.roughness)}
|
|
253
|
+
${A}token outputs:surface
|
|
254
|
+
}
|
|
255
|
+
token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
|
|
256
|
+
}
|
|
257
|
+
`}c+=`}
|
|
258
|
+
def Scope "Meshes"
|
|
259
|
+
{
|
|
260
|
+
`;let m=new Set;for(let u=0;u<n.length;u++){let o=n[u],a=o.positions.length/3,h=1/0,l=1/0,d=1/0,f=-1/0,T=-1/0,A=-1/0;for(let p=0;p<a;p++){let E=o.positions[p*3],M=o.positions[p*3+1],_=o.positions[p*3+2];E<h&&(h=E),E>f&&(f=E),M<l&&(l=M),M>T&&(T=M),_<d&&(d=_),_>A&&(A=_)}isFinite(h)||(h=l=d=-1,f=T=A=1);let S=Math.floor(o.indices.length/3),L=Wt(o.materialName,"DefaultMaterial"),b=Wt(o.name,`Mesh_${u}`);m.has(b)&&(b=`${b}_${u}`),m.add(b);let w=S>0?S===1?"3":"3, ".repeat(S-1)+"3":"",y=o.xrTraits,R="";if(y){let p=[];y.physics&&y.physics!=="none"&&p.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let E=J().xrTraitSerializer?.usdLines(y,wn)??[];if(!E.length)for(let M of["grab","billboard","follow","anchor","physics"]){let _=M==="follow"&&typeof y.follow=="object"?y.follow.mode??"head":y[M];_!==void 0&&E.push(`string ${M} = "${wn(_)}"`)}E.length>0&&p.push(`customData = {
|
|
261
|
+
dictionary xr = {
|
|
262
|
+
${E.join(`
|
|
263
|
+
`)}
|
|
264
|
+
}
|
|
265
|
+
}`),p.length>0&&(R=` (
|
|
266
|
+
${p.join(`
|
|
267
|
+
`)}
|
|
268
|
+
)`)}if(c+=`def Mesh "${b}"${R}
|
|
269
|
+
{
|
|
270
|
+
`,y?.physics&&y.physics!=="none"){let p=y.physics==="static"?"true":"false";c+=`bool physics:rigidBodyEnabled = true
|
|
271
|
+
bool physics:kinematicEnabled = ${p}
|
|
272
|
+
bool physics:collisionEnabled = true
|
|
273
|
+
`}if(o.timeSamples&&o.timeSamples.times.length>0){let p=o.timeSamples,E=p.times.map((I,g)=>{let v=p.translations?.[g]||[0,0,0];return`${G(I)}: (${G(v[0])}, ${G(v[1])}, ${G(v[2])})`}).join(", "),M=p.times.map((I,g)=>{let v=p.rotations?.[g]||[0,0,0,1];return`${G(I)}: (${G(v[3])}, ${G(v[0])}, ${G(v[1])}, ${G(v[2])})`}).join(", "),_=p.times.map((I,g)=>{let v=p.scales?.[g]||[1,1,1];return`${G(I)}: (${G(v[0])}, ${G(v[1])}, ${G(v[2])})`}).join(", ");c+=`double3 xformOp:translate.timeSamples = { ${E} }
|
|
274
|
+
quatf xformOp:orient.timeSamples = { ${M} }
|
|
275
|
+
double3 xformOp:scale.timeSamples = { ${_} }
|
|
276
|
+
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
277
|
+
`}c+=`float3[] extent = [(${G(h)}, ${G(l)}, ${G(d)}), (${G(f)}, ${G(T)}, ${G(A)})]
|
|
278
|
+
int[] faceVertexCounts = [${w}]
|
|
279
|
+
int[] faceVertexIndices = [${mr(o.indices)}]
|
|
280
|
+
point3f[] points = [${Tn(o.positions)}]
|
|
281
|
+
`,o.normals&&o.normals.length===o.positions.length&&(c+=`normal3f[] normals = [${Tn(o.normals)}] (
|
|
282
|
+
interpolation = "vertex"
|
|
283
|
+
)
|
|
284
|
+
`),o.uvs&&o.uvs.length===a*2&&(c+=`texCoord2f[] primvars:st = [${hr(o.uvs,a)}] (
|
|
285
|
+
interpolation = "vertex"
|
|
286
|
+
)
|
|
287
|
+
`),c+=`rel material:binding = </Root/Materials/${L}>
|
|
288
|
+
}
|
|
289
|
+
`}return c+=`}
|
|
290
|
+
}
|
|
291
|
+
`,c}function fr(n,e){if(n&&typeof n.traverse=="function"){let i=lr(n,e);return $t(i)}let t=Be(n),r=En(t);return $t(r)}var ct=null;function dr(n){{let t=globalThis.__three_live_native_crc32__;if(typeof t=="function")return t(n)}if(!ct){ct=new Uint32Array(256);for(let t=0;t<256;t++){let r=t;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;ct[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=ct[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function Mn(n){{let a=globalThis.__three_live_native_build_usdz_zip__;if(typeof a=="function")return a(n)}let e=[],t=0,r=[];for(let a of n){let h=ut(a.filename),l=dr(a.data),d=a.data.length,f=30+h.length,T=t+f,A=0,S=T%64;S!==0&&(A=64-S);let L=new Uint8Array(f+A),b=new DataView(L.buffer);b.setUint32(0,67324752,!0),b.setUint16(4,20,!0),b.setUint16(6,0,!0),b.setUint16(8,0,!0),b.setUint16(10,0,!0),b.setUint16(12,0,!0),b.setUint32(14,l,!0),b.setUint32(18,d,!0),b.setUint32(22,d,!0),b.setUint16(26,h.length,!0),b.setUint16(28,A,!0),L.set(h,30),A>0&&L.fill(0,30+h.length),e.push({offset:t,size:d,crc:l,filenameBytes:h,entry:a}),r.push(L),r.push(a.data),t+=L.length+a.data.length}let i=t;for(let a of e){let h=new Uint8Array(46+a.filenameBytes.length),l=new DataView(h.buffer);l.setUint32(0,33639248,!0),l.setUint16(4,20,!0),l.setUint16(6,20,!0),l.setUint16(8,0,!0),l.setUint16(10,0,!0),l.setUint16(12,0,!0),l.setUint16(14,0,!0),l.setUint32(16,a.crc,!0),l.setUint32(20,a.size,!0),l.setUint32(24,a.size,!0),l.setUint16(28,a.filenameBytes.length,!0),l.setUint16(30,0,!0),l.setUint16(32,0,!0),l.setUint16(34,0,!0),l.setUint16(36,0,!0),l.setUint32(38,0,!0),l.setUint32(42,a.offset,!0),h.set(a.filenameBytes,46),r.push(h),t+=h.length}let s=t-i,c=new Uint8Array(22),m=new DataView(c.buffer);m.setUint32(0,101010256,!0),m.setUint16(4,0,!0),m.setUint16(6,0,!0),m.setUint16(8,e.length,!0),m.setUint16(10,e.length,!0),m.setUint32(12,s,!0),m.setUint32(16,i,!0),m.setUint16(20,0,!0),r.push(c),t+=22;let u=new Uint8Array(t),o=0;for(let a of r)u.set(a,o),o+=a.length;return u}function Le(n){let e=fr(n),t=ut(e);return Mn([{filename:"model.usda",data:t}])}function lt(n){let e=Be(n),t=En(e),r=$t(t),i=ut(r);return Mn([{filename:"model.usda",data:i}])}function Yt(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Le(n):lt(n)}function Q(n,e,t,r){let i=typeof n=="number"&&Number.isFinite(n)?n:r;return Math.max(e,Math.min(t,i))}function jt(n){return Array.isArray(n)&&n.length>=3&&Number.isFinite(n[0])&&Number.isFinite(n[1])&&Number.isFinite(n[2])}function le(n){return n&&typeof n=="object"&&!Array.isArray(n)?n:null}function Kt(n,e=256){return typeof n=="string"&&n.length>0?n.slice(0,e):void 0}function pr(n){let e=le(n);if(!e||e.lazy===!1)return null;let t=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=t!=="head";return{mode:t,lazy:!0,distance:Q(e.distance,.1,10,r?.15:1),deadzoneDeg:Q(e.deadzoneDeg,0,90,r?0:15),stiffness:Q(e.stiffness,.5,40,6),height:Q(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function br(n){let e=le(n);if(!e)return null;let t=e.target;return{target:jt(t)?[t[0],t[1],t[2]]:typeof t=="string"&&t.length>0&&t.length<=256?t:[0,0,0],radius:Q(e.radius,.01,50,.5),speed:Q(e.speed,-20,20,.5),height:Q(e.height,-10,10,0),phase:Q(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function yr(n){if(!n)return null;let e=le(n)??{},t=Q(e.minScale,.001,1e3,.1),r=Q(e.maxScale,t,1e3,Math.max(t,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:t,maxScale:r}}var gr=2e3,xr={rain:600,snow:400,sparks:300,confetti:300};function vr(n){let e=le(n);if(!e)return null;let t=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,i=c=>Q(c,.05,50,2),s=jt(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[2,2,2];return{preset:t,count:Math.round(Q(e.count,1,gr,xr[t])),area:s,speed:Q(e.speed,.05,10,1)}}var wr=4e3;function Tr(n){if(!n)return null;let e=le(n)??{};return{prompt:Kt(e.prompt,wr)??"What is this?",holdMs:Q(e.holdMs,100,5e3,600)}}function Er(n){if(!n)return null;let e=le(n)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function qt(n){let e=Kt(n,4096)?.trim();if(!(!e||/[\x00-\x20\\%]/.test(e))){if(/^https:\/\/[^/]/i.test(e))return e;if(!(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)))return e.split(/[/?#]/).includes("..")?void 0:e}}function Mr(n){if(typeof n=="string"){let r=qt(n);return r?{src:r,refDistance:1,loop:!1}:null}let e=le(n),t=qt(e?.src);return!e||!t?null:{src:t,refDistance:Q(e.refDistance,.01,1e3,1),loop:e.loop===!0}}var Rr=new Set(["horizontal","vertical","floor","wall","table"]),Sr=new Set(["capsule","cylindrical","spherical"]);function ht(n){let e=le(n);if(!e)return null;let t=Array.isArray(e.traits)?e.traits:[],r=b=>t.includes(b),i={},s=e.grab;s==="1-hand"||s==="2-hand"?i.grab=s:(s===!0||e.grabbable===!0||r("grab"))&&(i.grab="2-hand"),i.grab&&(i.grabbable=!0);let c=e.scale??e.scalable;if(c||r("scale")){let b=le(c)??{},w=Q(b.min,.001,1e3,.05);i.scale={min:w,max:Q(b.max,w,1e3,Math.max(w,5))},i.scalable=!0}let m=e.billboard;typeof m=="string"&&Sr.has(m)?i.billboard=m:(m===!0||r("billboard"))&&(i.billboard="capsule");let u=e.follow,o=typeof u=="string"?u:le(u)?.mode;if(typeof u=="string"?u:le(u)?.lazy===!1)i.follow=o==="hand-left"||o==="hand-right"?o:"head";else{let b=pr(u);b&&(i.follow=b)}let a=e.anchor;typeof a=="string"&&Rr.has(a)&&(i.anchor=a),(e.physics==="dynamic"||e.physics==="static")&&(i.physics=e.physics);let h=br(e.orbit);h&&(i.orbit=h);let l=yr(e.handles);l&&(i.handles=l);let d=vr(e.particles);d&&(i.particles=d);let f=Tr(e.holdToAsk);f&&(i.holdToAsk=f);let T=Er(e.worldUnderstanding);T&&(i.worldUnderstanding=T);let A=qt(e.splatUrl);A&&(i.splatUrl=A);let S=Kt(e.spatialSlot);S&&(i.spatialSlot=S);let L=Mr(e.audio);return L&&(i.audio=L),e.pointerEvents==="none"&&(i.pointerEvents="none"),Object.keys(i).length>0?i:null}function Zt(n){let e={};return n.grab&&(e.interactable={mode:n.grab},e.movable={systemMovable:!0,scaleInZ:!!n.scale,minScale:n.scale?.min??.05,maxScale:n.scale?.max??5}),n.billboard&&(e.billboard={mode:n.billboard}),typeof n.follow=="string"?e.follow={target:n.follow,lazy:!1}:n.follow&&(e.follow={target:n.follow.mode,lazy:!0,distance:n.follow.distance,deadzoneDeg:n.follow.deadzoneDeg,stiffness:n.follow.stiffness,height:n.follow.height,faceUser:n.follow.faceUser}),n.anchor&&(e.anchor={planeType:n.anchor==="vertical"||n.anchor==="wall"?"VERTICAL":"HORIZONTAL",semanticType:n.anchor.toUpperCase()}),n.physics&&(e.rigidbody={type:n.physics}),n.orbit&&(e.orbit={...n.orbit}),n.handles&&(e.resizable={...n.handles}),n.particles&&(e.particles={...n.particles}),n.holdToAsk&&(e.holdToAsk={...n.holdToAsk}),n.worldUnderstanding&&(e.worldUnderstanding={...n.worldUnderstanding}),n.splatUrl&&(e.splat={url:n.splatUrl}),n.spatialSlot&&(e.spatialPanel={slot:n.spatialSlot}),n.audio&&(e.spatialAudio={...n.audio}),e}function Ar(n){let e={},t=(r,i)=>{for(let[s,c]of Object.entries(i)){let m=r+s[0].toUpperCase()+s.slice(1);typeof c=="string"||typeof c=="number"||typeof c=="boolean"?e[m]=c:jt(c)&&(e[m]=[c[0],c[1],c[2]])}};return n.grab&&(e.grab=n.grab),n.scale&&t("scale",n.scale),n.billboard&&(e.billboard=n.billboard),typeof n.follow=="string"?e.follow=n.follow:n.follow&&(e.follow=n.follow.mode,t("follow",{...n.follow,mode:void 0})),n.anchor&&(e.anchor=n.anchor),n.physics&&(e.physics=n.physics),n.orbit&&t("orbit",n.orbit),n.handles&&(e.handles=!0,t("handles",n.handles)),n.particles&&t("particles",n.particles),n.holdToAsk&&(e.holdToAsk=!0,t("holdToAsk",n.holdToAsk)),n.worldUnderstanding&&t("worldUnderstanding",n.worldUnderstanding),n.splatUrl&&(e.splatUrl=n.splatUrl),n.spatialSlot&&(e.spatialSlot=n.spatialSlot),n.audio&&t("audio",n.audio),n.pointerEvents&&(e.pointerEvents=n.pointerEvents),e}function _r(n,e){let t=ht(e);t&&(n.extras={...n.extras,xr:{...n.extras?.xr,...t}},n.extensions={...n.extensions,MOZ_hubs_components:Jt(t),ANDROID_xr_scenecore:Zt(t)})}function Jt(n){let e={};return n.grab&&(e.grabbable={cursor:!0,hand:!0}),n.billboard&&(e.billboard={onlyY:n.billboard!=="spherical"}),e}function Dr(n,e){let t=ht(n),r=[];if(!t)return r;for(let[i,s]of Object.entries(Ar(t)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof s=="boolean"?r.push(`bool ${i} = ${s}`):typeof s=="number"?Number.isFinite(s)&&r.push(`double ${i} = ${s}`):typeof s=="string"?r.push(`string ${i} = "${e(s)}"`):s.length===3&&s.every(c=>Number.isFinite(c))&&r.push(`double3 ${i} = (${s.join(", ")})`));return r}function Rn(){try{Object.defineProperty(J(),"xrTraitSerializer",{value:Object.freeze({gltfNode:_r,usdLines:Dr}),writable:!1,configurable:!1,enumerable:!0})}catch{}}var mt=class n{constructor(e=0,t=0){this.x=Number(e),this.y=Number(t)}set(e,t){return this.x=Number(e),this.y=Number(t),this}clone(){return new n(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},j=class n{constructor(e=0,t=0,r=0){this.x=Number(e),this.y=Number(t),this.z=Number(r)}set(e,t,r){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this}clone(){return new n(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=i,this}crossVectors(e,t){let r=e.x,i=e.y,s=e.z,c=t.x,m=t.y,u=t.z;return this.x=i*u-s*m,this.y=s*c-r*u,this.z=r*m-i*c,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let t=this.x,r=this.y,i=this.z,s=e.elements,c=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*c,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*c,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*c,this}},ft=class{constructor(e=0,t=0,r=0,i=1){this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i)}set(e,t,r,i){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i),this}},Xe=class n{constructor(e=0,t=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,t,r,i=this.order){return this._x=Number(e),this._y=Number(t),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new n(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Ge=class n{constructor(e=0,t=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,t,r,i){return this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new n(this._x,this._y,this._z,this._w)}setFromEuler(e,t=!0){let r=e.x,i=e.y,s=e.z,c=Math.cos(r/2),m=Math.cos(i/2),u=Math.cos(s/2),o=Math.sin(r/2),a=Math.sin(i/2),h=Math.sin(s/2);return this._x=o*m*u+c*a*h,this._y=c*a*u-o*m*h,this._z=c*m*h+o*a*u,this._w=c*m*u-o*a*h,t&&this._onChangeCallback?.(),this}setFromAxisAngle(e,t){let r=t/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,t){let r=e.x,i=e.y,s=e.z,c=e.w,m=t.x,u=t.y,o=t.z,a=t.w;return this._x=r*a+c*m+i*o-s*u,this._y=i*a+c*u+s*m-r*o,this._z=s*a+c*o+r*u-i*m,this._w=c*a-r*m-i*u-s*o,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},ye=class n{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new n;return e.copy(this),e}compose(e,t,r){return st(this.elements,[t.x,t.y,t.z,t.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,t){return re(this.elements,e.elements,t.elements),this}lookAt(e,t,r){return Ce(this.elements,[e.x,e.y,e.z],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let t=new j(0,0,0),r=new j(1,1,1);return this.compose(t,e,r)}makeTranslation(e,t,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(t),this.elements[14]=Number(r),this}makeScale(e,t,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(t),this.elements[10]=Number(r),this}},dt=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return ae(this.elements,e.elements),this}},he=class n{constructor(e,t,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(t!==void 0&&r!==void 0?this.setRGB(e,t,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let t=parseInt(e.slice(1),16);this.setHex(t)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let t=Math.floor(e);return this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,this}setRGB(e,t,r){return this.r=Number(e),this.g=Number(t),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new n(this.r,this.g,this.b)}},Ln={degToRad:n=>n*Math.PI/180,radToDeg:n=>n*180/Math.PI,clamp:(n,e,t)=>Math.max(e,Math.min(t,n)),lerp:(n,e,t)=>n+(e-n)*t,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(n,e)=>n+Math.random()*(e-n)},X=class{constructor(e,t){this.needsUpdate=!1;if(typeof t!="number"||!Number.isInteger(t)||t<1||t>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(t)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=t;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/t)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,t){return this.array[e*this.itemSize]=t,this.needsUpdate=!0,this}setY(e,t){return this.array[e*this.itemSize+1]=t,this.needsUpdate=!0,this}setZ(e,t){return this.array[e*this.itemSize+2]=t,this.needsUpdate=!0,this}setXYZ(e,t,r,i){let s=e*this.itemSize;return this.array[s]=t,this.array[s+1]=r,this.array[s+2]=i,this.needsUpdate=!0,this}},pt=class extends X{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},bt=class extends X{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},yt=class extends X{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},ce=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,t){return this.attributes[e]=t,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof X)this.index=e;else if(Array.isArray(e)){let t=0;for(let i=0;i<e.length;i++)e[i]>t&&(t=e[i]);let r=t>65535?new Uint32Array(e):new Uint16Array(e);this.index=new X(r,1)}else e&&e.buffer&&(this.index=new X(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let t=e.count,r=new Float32Array(t*3),i=new j,s=new j,c=new j,m=new j,u=new j;if(this.index){let o=this.index.array;for(let a=0;a<o.length;a+=3){let h=o[a],l=o[a+1],d=o[a+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(l),e.getY(l),e.getZ(l)),c.set(e.getX(d),e.getY(d),e.getZ(d)),m.subVectors(c,s),u.subVectors(i,s),m.cross(u).normalize();for(let f of[h,l,d])r[f*3]+=m.x,r[f*3+1]+=m.y,r[f*3+2]+=m.z}}else for(let o=0;o<t;o+=3){i.set(e.getX(o),e.getY(o),e.getZ(o)),s.set(e.getX(o+1),e.getY(o+1),e.getZ(o+1)),c.set(e.getX(o+2),e.getY(o+2),e.getZ(o+2)),m.subVectors(c,s),u.subVectors(i,s),m.cross(u).normalize();for(let a=0;a<3;a++)r[(o+a)*3]=m.x,r[(o+a)*3+1]=m.y,r[(o+a)*3+2]=m.z}for(let o=0;o<t;o++){let a=r[o*3],h=r[o*3+1],l=r[o*3+2],d=Math.hypot(a,h,l)||1;r[o*3]=a/d,r[o*3+1]=h/d,r[o*3+2]=l/d}return this.setAttribute("normal",new X(r,3)),this}setFromBuffers(e,t,r,i){this.setAttribute("position",new X(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new X(t instanceof Float32Array?t:new Float32Array(t),3)),this.setAttribute("uv",new X(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},We=class extends ce{constructor(e=1,t=1,r=1){super();{let h=globalThis.__three_live_native_box__;if(typeof h=="function"){let l=h(e,t,r);this.setFromBuffers(l.positions,l.normals,l.uvs,l.indices);return}}let i=e/2,s=t/2,c=r/2,m=[-i,-s,c,i,-s,c,i,s,c,-i,s,c,i,-s,-c,-i,-s,-c,-i,s,-c,i,s,-c,-i,s,c,i,s,c,i,s,-c,-i,s,-c,-i,-s,-c,i,-s,-c,i,-s,c,-i,-s,c,i,-s,c,i,-s,-c,i,s,-c,i,s,c,-i,-s,-c,-i,-s,c,-i,s,c,-i,s,-c],u=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],o=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],a=[];for(let h=0;h<6;h++){let l=h*4;a.push(l,l+1,l+2,l,l+2,l+3)}this.setAttribute("position",new X(new Float32Array(m),3)),this.setAttribute("normal",new X(new Float32Array(u),3)),this.setAttribute("uv",new X(new Float32Array(o),2)),this.setIndex(a)}},gt=class extends ce{constructor(e=1,t=1){super();let r=e/2,i=t/2,s=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],c=[0,0,1,0,0,1,0,0,1,0,0,1],m=[0,1,1,1,0,0,1,0],u=[0,2,1,2,3,1];this.setAttribute("position",new X(new Float32Array(s),3)),this.setAttribute("normal",new X(new Float32Array(c),3)),this.setAttribute("uv",new X(new Float32Array(m),2)),this.setIndex(u)}},$e=class extends ce{constructor(e=1,t=16,r=12){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));{let o=globalThis.__three_live_native_sphere__;if(typeof o=="function"){let a=o(e,t,r);this.setAttribute("position",new X(a.positions,3)),this.setAttribute("normal",new X(a.normals,3)),this.setAttribute("uv",new X(a.uvs,2)),this.setIndex(a.indices);return}}let i=[],s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=[],h=o/r;for(let l=0;l<=t;l++){let d=l/t,f=d*Math.PI*2,T=h*Math.PI,A=-e*Math.cos(f)*Math.sin(T),S=e*Math.cos(T),L=e*Math.sin(f)*Math.sin(T);i.push(A,S,L);let b=Math.hypot(A,S,L)||1;s.push(A/b,S/b,L/b),c.push(d,1-h),a.push(i.length/3-1)}u.push(a)}for(let o=0;o<r;o++)for(let a=0;a<t;a++){let h=u[o][a+1],l=u[o][a],d=u[o+1][a],f=u[o+1][a+1];o!==0&&m.push(h,l,f),o!==r-1&&m.push(l,d,f)}this.setAttribute("position",new X(new Float32Array(i),3)),this.setAttribute("normal",new X(new Float32Array(s),3)),this.setAttribute("uv",new X(new Float32Array(c),2)),this.setIndex(m)}},Ee=class extends ce{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));{let a=globalThis.__three_live_native_cylinder__;if(typeof a=="function"){let h=a(e,t,r,i);this.setAttribute("position",new X(h.positions,3)),this.setAttribute("normal",new X(h.normals,3)),this.setAttribute("uv",new X(h.uvs,2)),this.setIndex(h.indices);return}}let s=[],c=[],m=[],u=[],o=r/2;for(let a=0;a<=1;a++){let h=a,l=a===0?e:t,d=a===0?o:-o;for(let f=0;f<=i;f++){let T=f/i,A=T*Math.PI*2,S=Math.sin(A),L=Math.cos(A);s.push(l*S,d,l*L),c.push(S,0,L),m.push(T,1-h)}}for(let a=0;a<i;a++){let h=a,l=a+i+1,d=a+i+2,f=a+1;u.push(h,l,f,l,d,f)}if(e>0){let a=s.length/3;s.push(0,o,0),c.push(0,1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let d=l/i*Math.PI*2,f=Math.sin(d),T=Math.cos(d);s.push(e*f,o,e*T),c.push(0,1,0),m.push(T*.5+.5,f*.5+.5)}for(let l=0;l<i;l++)u.push(a,h+l,h+l+1)}if(t>0){let a=s.length/3;s.push(0,-o,0),c.push(0,-1,0),m.push(.5,.5);let h=s.length/3;for(let l=0;l<=i;l++){let d=l/i*Math.PI*2,f=Math.sin(d),T=Math.cos(d);s.push(t*f,-o,t*T),c.push(0,-1,0),m.push(T*.5+.5,1-(f*.5+.5))}for(let l=0;l<i;l++)u.push(a,h+l+1,h+l)}this.setAttribute("position",new X(new Float32Array(s),3)),this.setAttribute("normal",new X(new Float32Array(c),3)),this.setAttribute("uv",new X(new Float32Array(m),2)),this.setIndex(u)}},xt=class extends Ee{constructor(e=1,t=1,r=16){super(0,e,t,r)}},vt=class extends ce{constructor(e=1,t=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let s=[],c=[],m=[],u=[];for(let o=0;o<=r;o++){let a=o/r*Math.PI*2;for(let h=0;h<=i;h++){let l=h/i*Math.PI*2,d=(e+t*Math.cos(a))*Math.cos(l),f=(e+t*Math.cos(a))*Math.sin(l),T=t*Math.sin(a);s.push(d,f,T);let A=e*Math.cos(l),S=e*Math.sin(l),L=d-A,b=f-S,w=T,y=Math.hypot(L,b,w)||1;c.push(L/y,b/y,w/y),m.push(h/i,o/r)}}for(let o=1;o<=r;o++)for(let a=1;a<=i;a++){let h=(i+1)*o+a-1,l=(i+1)*(o-1)+a-1,d=(i+1)*(o-1)+a,f=(i+1)*o+a;u.push(h,l,f,l,d,f)}this.setAttribute("position",new X(new Float32Array(s),3)),this.setAttribute("normal",new X(new Float32Array(c),3)),this.setAttribute("uv",new X(new Float32Array(m),2)),this.setIndex(u)}},wt=class extends ce{constructor(e=1,t=.4,r=64,i=8,s=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);{let b=globalThis.__three_live_native_torus_knot__;if(typeof b=="function"){let w=b(e,t,r,i,s,c);this.setAttribute("position",new X(w.positions,3)),this.setAttribute("normal",new X(w.normals,3)),this.setAttribute("uv",new X(w.uvs,2)),this.setIndex(w.indices);return}}let m=[],u=[],o=[],a=[],h=new j,l=new j,d=new j,f=new j,T=new j;function A(b,w){let y=Math.cos(w),R=Math.sin(w),p=c/s*w,E=e*(2+Math.cos(p))*.5;b.set(E*y,E*R,e*Math.sin(p)*.5)}let S=[];for(let b=0;b<=i;++b){let w=b/i*Math.PI*2;S.push(-t*Math.cos(w),t*Math.sin(w),b/i)}for(let b=0;b<=r;++b){let w=b/r,y=w*s*Math.PI*2;A(h,y),A(l,y+.01),d.subVectors(l,h).normalize(),f.addVectors(h,l).normalize(),T.crossVectors(d,f).normalize(),f.crossVectors(T,d).normalize();for(let R=0;R<=i;++R){let p=R*3,E=S[p],M=S[p+1],_=S[p+2],I=E*f.x+M*T.x,g=E*f.y+M*T.y,v=E*f.z+M*T.z;m.push(h.x+I,h.y+g,h.z+v);let x=Math.hypot(I,g,v)||1;u.push(I/x,g/x,v/x),o.push(w,_)}}let L=i+1;for(let b=1;b<=r;b++){let w=L*(b-1),y=w+L;for(let R=1;R<=i;R++){let p=w+(R-1),E=y+(R-1),M=y+R,_=w+R;a.push(p,E,_,E,M,_)}}this.setAttribute("position",new X(new Float32Array(m),3)),this.setAttribute("normal",new X(new Float32Array(u),3)),this.setAttribute("uv",new X(new Float32Array(o),2)),this.setIndex(a)}},Ye=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Tt=class{load(e,t){let r=new Ye(e);return t?.(r),r}};function te(n,e){return n!==void 0?Number(n):e}function Qt(n,e){return n!==void 0?!!n:e}var me=class{constructor(e={}){this.name=e.name||"",this.color=new he(e.color!==void 0?e.color:16777215),this.emissive=new he(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=te(e.emissiveIntensity,1),this.roughness=te(e.roughness,.5),this.metalness=te(e.metalness,.1),this.opacity=te(e.opacity,1),this.transparent=Qt(e.transparent,!1),this.wireframe=Qt(e.wireframe,!1),this.side=te(e.side,2),this.doubleSided=Qt(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=te(e.clearcoat,0),this.clearcoatRoughness=te(e.clearcoatRoughness,0),this.sheen=te(e.sheen,0),this.sheenColor=new he(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=te(e.sheenRoughness,0),this.transmission=te(e.transmission,0),this.thickness=te(e.thickness,0),this.attenuationColor=new he(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=te(e.attenuationDistance,1/0),this.ior=te(e.ior,1.5),this.dispersion=te(e.dispersion,0),this.iridescence=te(e.iridescence,0),this.iridescenceIOR=te(e.iridescenceIOR,1.3)}dispose(){}},Se=class extends me{},Et=class extends me{},Mt=class extends me{},Rt=class extends me{},St=class extends me{},ie=class n{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new j,this.rotation=new Xe,this.quaternion=new Ge,this.scale=new j(1,1,1),this.matrix=new ye,this.matrixWorld=new ye,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,t=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(t,r,i)})}add(...e){for(let t of e)t&&t instanceof n&&(t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t));return this}remove(...e){for(let t of e){let r=this.children.indexOf(t);r!==-1&&(t.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let t of this.children)t.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let t of this.children)t.updateMatrixWorld(e)}lookAt(e,t,r){let i=typeof e=="object"?e:new j(e,t,r);this.updateMatrixWorld(!0);let s=new ye;s.lookAt(this.position,i,new j(0,1,0));let c=s.elements,m=c[0],u=c[4],o=c[8],a=c[1],h=c[5],l=c[9],d=c[2],f=c[6],T=c[10],A=m+h+T;if(A>0){let S=.5/Math.sqrt(A+1);this.quaternion.set((f-l)*S,(o-d)*S,(a-u)*S,.25/S)}}},At=class extends ie{},Ue=class extends ie{constructor(t,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=t instanceof ce?t:t?(se("unsupported geometry","BoxGeometry"),new We(.5,.5,.5)):new ce,this.material=i instanceof me?i:i?(se("unsupported material","MeshStandardMaterial"),new Se({color:13421772})):new Se}},Me=class extends ie{constructor(e=16777215,t=1){super(),this.color=new he(e),this.intensity=Number(t),this.type="directional"}},qe=class extends Me{constructor(e,t){super(e,t),this.type="ambient"}},_t=class extends Me{constructor(t,r){super(t,r);this.target=new ie;this.type="directional"}},je=class extends Me{constructor(t,r,i=0,s=2){super(t,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=s}},Ke=class extends ie{},Fe=class extends Ke{constructor(t=45,r=1,i=.1,s=1e3){super();this.target=new j(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(s)}},Ae=class extends ie{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return pe.validate(this),Ie(this)}toGLB(){return pe.validate(this),ze(this)}toUSDZ(){return pe.validate(this),Le(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof Ue){let s=new Float32Array(i.matrixWorld.elements);t.set(r,s),i.name&&t.set(i.name,s),r++}}),t}},en=Ie,tn=ze,Pn=Le;var pe=class{static validate(e){let t=0,r=0,i=0,s=new Set,c=(u,o,a)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${u} (${o}). Found: ${a}`)},m=(u,o)=>{if(!Number.isFinite(o))throw new Error(`SecurityError: Scene reports a non-finite ${u} count (${String(o)}), which cannot be bounds-checked.`);return o};e.traverse(u=>{if(u instanceof Ue){i++,i>1e3&&c("MESHES",1e3,i);let o=u.geometry;if(o){let a=0;if(o.attributes.position&&(a=m("vertex",o.attributes.position.count),t+=a,t>1e5&&c("VERTICES",1e5,t)),o.index){let h=m("index",o.index.count);r+=h,r>3e5&&c("INDICES",3e5,r);let l=o.index.array;if(l&&a>0){let d=Math.min(h,l.length);for(let f=0;f<d;f++){let T=l[f];if(!Number.isFinite(T)||T<0||T>=a)throw new Error(`SecurityError: Index buffer value (${String(T)}) out of vertex bounds [0, ${a}).`)}}}}if(u.material){let a=u.material;a.map&&s.add(a.map),a.normalMap&&s.add(a.normalMap),a.roughnessMap&&s.add(a.roughnessMap)}}}),s.size>16&&c("TEXTURES",16,s.size);for(let u of s){let o=u,a=o.image,h=Number(a?.width??o.width??0)||0,l=Number(a?.height??o.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(l)||h>2048||l>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(h,l))}}},Dt=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new he(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){pe.validate(e);let i=(s,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(s,c):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),c={};for(let[m,u]of s.entries())c[m]=Array.from(u);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let s=en(e),c=tn(e),m=(s.lights||[]).map(u=>({type:u.type,color:u.color,intensity:u.intensity,position:u.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:c.buffer,dynamicLights:m,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[c.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Sn(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Ct=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=Sn(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let t=Sn();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function Cr(){}var Pe=new Proxy(Cr,{get:(n,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:Pe},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Pe,construct:()=>Pe}),An=(()=>{try{if(typeof document>"u")return null;let n=document.currentScript;return n?.src?n.src:n?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([n.textContent],{type:"text/javascript"})):null}catch{return null}})();function Ne(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Re(n,e){if(!n||typeof n!="string")return!1;let t=n.trim();if(!t)return!1;try{let r=new URL(t,Ne());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||e?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var _n,Ve;function Un(n){if(!Re(n))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${n}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return n;if(Ve===void 0||_n!==t){_n=t;try{Ve=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Re(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Ve=null}}return Ve?Ve.createScriptURL(n):n}function Ir(n){J().sandboxEngineSrc=n}function nn(){let n=J().sandboxEngineSrc;if(n)return n;if(An)return An;try{if(typeof document>"u")return null;let e=Ne(),t=Array.from(document.querySelectorAll("script[src]"));for(let r of t){let i=r.src;if(!i)continue;let s=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&Re(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Lr(){let n=nn();if(!n)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!Re(n))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Ne()).href}function Pr(n){J().sandboxIframeSrc=n}function Fn(){let n=J().sandboxIframeSrc;if(n)return n;let e=nn();if(!e||!Re(e))return null;let t=new URL(e,Ne());return t.protocol==="blob:"?null:new URL("three-live-sandbox.html",t).href}function Ur(){let n=Fn();if(!n)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!Re(n))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Ne()).href}function Fr(n){J().allowClientScripts=n}function Nn(){return!!J().allowClientScripts}function Nr(n){if(!Re(n))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Ne()).href}var kr=["fetch","XMLHttpRequest","WebSocket","WebSocketStream","WebTransport","EventSource","importScripts","Request","Response","Headers","navigator","WorkerNavigator","WorkerLocation","RTCPeerConnection","RTCDataChannel","FontFace","FontFaceSet","fonts","PerformanceObserver","ReportingObserver","indexedDB","IDBFactory","caches","CacheStorage","Cache","cookieStore","StorageManager","FileSystemHandle","Worker","SharedWorker","ServiceWorker","ServiceWorkerContainer","ServiceWorkerRegistration","registration","clients","BroadcastChannel","MessageChannel","MessagePort","createImageBitmap","OffscreenCanvas","WebAssembly","WorkerGlobalScope","DedicatedWorkerGlobalScope","trustedTypes","TrustedTypePolicyFactory","SharedArrayBuffer","Atomics"];function Or(n){let e=self,t=n.nonce,r=n.engineSrc,i=n.allowedScriptUrl,s=n.allowClientScripts,c=n.revoked,m=e.postMessage.bind(e);function u(y){m({type:"ERROR",nonce:t,message:String(y)})}let o=typeof e.importScripts=="function"?e.importScripts.bind(e):null,a=i,h=null;try{let y=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let R={createScriptURL:function(E){if(E!==r&&(!i||E!==i))throw new TypeError("Disallowed worker importScripts URL");return E}};s&&(R.createScript=function(E){return String(E)});let p=e.trustedTypes.createPolicy("three-live#worker-boot",R);y=p.createScriptURL(r),i&&(a=p.createScriptURL(i)),s&&typeof p.createScript=="function"&&(h=p.createScript.bind(p))}catch{}o(y)}catch(y){u('Sandbox failed to load the Three-Live engine from "'+r+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(y&&y.message||y));return}let l=e.THREE;if(!l||typeof l.Scene!="function"){u('Sandbox loaded "'+r+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let y=0;y<c.length;y++){let R=c[y],p=e;for(;p&&p!==Object.prototype;){if(p!==e)try{delete p[R]}catch{}try{Object.defineProperty(p,R,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{p=Object.getPrototypeOf(p)}catch{break}}}let d=Object.freeze({now:function(){return Date.now()}}),f=e;for(;f&&f!==Object.prototype;){if(f!==e)try{delete f.performance}catch{}try{Object.defineProperty(f,"performance",{value:d,writable:!1,configurable:!1,enumerable:!1})}catch{}try{f=Object.getPrototypeOf(f)}catch{break}}let T=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],A=!1;function S(y,R){if(y.type==="3D_MODEL_READY"){if(A)return;A=!0}y.nonce=t,R&&R.length?m(y,R):m(y)}let L=function(y,R){if(!y||T.indexOf(y.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+T.join(", ")+").");S(y,R)},b=e;for(;b&&b!==Object.prototype;){if(b===e||Object.prototype.hasOwnProperty.call(b,"postMessage"))try{Object.defineProperty(b,"postMessage",{value:L,writable:!1,configurable:!1})}catch{}try{b=Object.getPrototypeOf(b)}catch{break}}let w=!1;e.onmessage=function(y){let R=y&&y.data;if(!(!R||R.nonce!==t)&&!(R.type!=="EXECUTE"&&R.type!=="EXECUTE_URL")&&!w){w=!0;try{let p=new l.Scene,E=new l.PerspectiveCamera(60,1,.1,1e3),M=new l.WebGLRenderer({isSandboxed:!0});if(R.type==="EXECUTE_URL"){if(!i||R.scriptUrl!==i||typeof o!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let _=a||i,I=o;if(o=null,a=null,e.THREE=l,e.scene=p,e.camera=E,e.renderer=M,I(_),typeof e.__THREE_LIVE_SCENE__=="function"){let g=e.__THREE_LIVE_SCENE__(l,p,E,M);g&&typeof g.toGLB=="function"&&(p=g)}else e.scene&&typeof e.scene.toGLB=="function"&&(p=e.scene)}else{if(!s){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let _=h?(0,eval)(h(`(function (THREE, scene, camera, renderer) {
|
|
292
|
+
return (function () {
|
|
293
|
+
`+R.script+`
|
|
294
|
+
})();
|
|
295
|
+
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
296
|
+
`+R.script+`
|
|
297
|
+
})();`);h=null;let I=_(l,p,E,M);I&&typeof I.toGLB=="function"&&(p=I)}if(!A){l.SceneQuotaValidator&&l.SceneQuotaValidator.validate(p);let _=p.toGLB(),I=_ instanceof ArrayBuffer?_:_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);S({type:"3D_MODEL_READY",glbBuffer:I},[I])}m({type:"DONE",nonce:t})}catch(p){u(p&&p.message||p)}}},m({type:"READY",nonce:t})}function rn(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,s={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:kr};return`'use strict';(${Or.toString()})(${JSON.stringify(s)});`}function kn(n){n.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),n.onToast?.("Security Error: script timed out and was stopped.")}var Te=0;function On(){try{let n=new Uint32Array(4);return globalThis.crypto?.getRandomValues(n),Array.from(n,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Br(n){try{return new TextEncoder().encode(n).length}catch{return n.length}}var zr=1024,Vr=256;function Dn(n){if(!Array.isArray(n)&&!(n instanceof Float32Array)||n.length!==16)return!1;for(let e=0;e<16;e++){let t=n[e];if(typeof t!="number"||!Number.isFinite(t))return!1}return!0}function sn(n,e){if(!n||typeof n!="object")return null;let t=n;if(t.nonce!==e)return null;switch(t.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof t.message=="string"?t.message:String(t.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,zr)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let s of i)if(!Dn(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let s=Object.keys(i);if(s.length>1e3)return null;let c=Object.create(null),m=i;for(let u of s){if(u.length>Vr||u==="__proto__"||u==="constructor"||u==="prototype")return null;let o=m[u];if(!Dn(o))return null;c[u]=o}return{type:"3D_UPDATE_TRANSFORMS",transforms:c}}return null}case"3D_MODEL_READY":{let i=t.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function Hr(n){let e=Br(n);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Bn(n,e,t,r){switch(n.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(n.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(n.payload);return;case"DONE":t();return;case"ERROR":t(),e.onError?.(new Error(`Worker script error: ${n.message}`));return;default:return n}}function Xr(n,e,t,r){let i=On(),s=rn(e,i,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),c=document.createElement("iframe");c.setAttribute("sandbox","allow-scripts"),c.setAttribute("aria-hidden","true"),c.tabIndex=-1,c.style.display="none",c.src=t,Te++;let m=!1,u=!1,o={modelDispatched:!1},a,h=()=>{if(m||u)return;let T=c.contentWindow;!T||typeof T.postMessage!="function"||(u=!0,T.postMessage(n.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:s,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:s,script:n.script},"*"))},l=()=>{},d=T=>{if(m||!c.contentWindow||T.source!==c.contentWindow)return;let A=T.data;if(A&&typeof A=="object"&&A.type==="IFRAME_READY"){h();return}let S=sn(A,i);S&&Bn(S,r,l,o)};l=()=>{m||(m=!0,a!==void 0&&clearTimeout(a),Te=Math.max(0,Te-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),typeof c.remove=="function"?c.remove():c.parentNode&&c.parentNode.removeChild(c))},a=setTimeout(()=>{m||(l(),kn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",d),c.onload=()=>{h()},c.onerror=()=>{l(),r.onError?.(new Error(`Sandbox iframe failed to load "${t}". Verify that three-live-sandbox.html is served at that URL.`))};let f=document.body||document.documentElement;if(!f||typeof f.appendChild!="function"){l();let T=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(T),T}return f.appendChild(c),{terminate:l}}function Cn(n,e,t,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Te>=32)return r(`SecurityError: ${Te} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=Lr()}catch(l){let d=l instanceof Error?l.message:String(l);return r(d,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let l;try{l=Ur()}catch(d){let f=d instanceof Error?d.message:String(d);return r(f,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Xr(n,i,l,t))}catch(d){return Promise.reject(d)}}let s=On(),c=rn(i,s,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),m;try{let l=new Blob([c],{type:"application/javascript"}),d=URL.createObjectURL(l);try{let f=Un(d);m=new Worker(f)}finally{URL.revokeObjectURL(d)}}catch(l){let d=l instanceof Error?l.message:String(l);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}Te++;let u=!1,o={modelDispatched:!1},a,h=()=>{u||(u=!0,a!==void 0&&clearTimeout(a),Te=Math.max(0,Te-1),m.terminate())};return a=setTimeout(()=>{u||(h(),kn(t))},3e3),m.onmessage=l=>{let d=sn(l.data,s);d&&Bn(d,t,h,o)},m.onerror=l=>{h(),t.onError?.(new Error(`Worker execution error: ${l.message}`))},n.kind==="url"?m.postMessage({type:"EXECUTE_URL",scriptUrl:n.scriptUrl,nonce:s}):m.postMessage({type:"EXECUTE",script:n.script,nonce:s}),Promise.resolve({terminate:h})}function In(n,e){return n==="none"||n==="unsafe-host-realm"?e(`SecurityError: sandbox="${n}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${n}" is not permitted.`):n!=="worker"&&n!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${n}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var zn={execute(n,e,t,r){let i=(m,u)=>{let o=new Error(m);return t.onError?.(o),u&&t.onToast?.(u),Promise.reject(o)},s=In(e,i);if(s)return s;try{Hr(n)}catch(m){let u=m instanceof Error?m.message:String(m);return i(u,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Nn()?Cn({kind:"script",script:n},e,t,i):i(an,cn)},executeUrl(n,e,t){let r=(c,m)=>{let u=new Error(c);return t.onError?.(u),m&&t.onToast?.(m),Promise.reject(u)},i=In(e,r);if(i)return i;let s;try{s=Nr(n)}catch(c){let m=c instanceof Error?c.message:String(c);return r(m,"Security Error: disallowed scene script URL.")}return Cn({kind:"url",scriptUrl:s},e,t,r)}},It=new Set;function se(n,e){let t=`[three-live] ${n} is unsupported; degraded to ${e}.`;It.has(t)||(It.add(t),typeof console<"u"&&typeof console.warn=="function"&&console.warn(t))}function Vn(){return Array.from(It)}function on(){It.clear()}var Ze=class extends Se{constructor(e={}){se("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},Hn=Ze,_e=class extends $e{constructor(e=1,t=0,r="PolyhedronGeometry"){se(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(t,3)));super(e,i,i)}},Lt=class extends _e{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Pt=class extends _e{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},Ut=class extends _e{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},Ft=class extends _e{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Nt=class extends Ee{constructor(e=1,t=1,r=4,i=8){se("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},kt=class extends Ee{constructor(e=.5,t=1,r=16){se("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},Ot=class extends Ee{constructor(e=1,t=16){se("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},Bt=class extends je{constructor(t,r,i=0,s=Math.PI/3,c=0,m=2){se("SpotLight","PointLight");super(t,r,i,m);this.target=new ie;this.angle=Math.PI/3;this.penumbra=0;this.angle=s,this.penumbra=c}},Je=class extends qe{constructor(e,t,r){se("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new he(t??4473924)}},Xn=Je,Gn={Vector2:mt,Vector3:j,Vector4:ft,Euler:Xe,Quaternion:Ge,Matrix4:ye,Matrix3:dt,Color:he,MathUtils:Ln,BufferAttribute:X,Float32BufferAttribute:pt,Uint16BufferAttribute:bt,Uint32BufferAttribute:yt,BufferGeometry:ce,BoxGeometry:We,PlaneGeometry:gt,SphereGeometry:$e,CylinderGeometry:Ee,ConeGeometry:xt,TorusGeometry:vt,TorusKnotGeometry:wt,IcosahedronGeometry:Lt,OctahedronGeometry:Pt,DodecahedronGeometry:Ut,TetrahedronGeometry:Ft,CapsuleGeometry:Nt,RingGeometry:kt,CircleGeometry:Ot,Texture:Ye,TextureLoader:Tt,Material:me,MeshStandardMaterial:Se,MeshBasicMaterial:Et,MeshLambertMaterial:Mt,MeshPhongMaterial:Rt,MeshPhysicalMaterial:St,ShaderMaterial:Ze,RawShaderMaterial:Hn,Object3D:ie,Group:At,Mesh:Ue,Light:Me,AmbientLight:qe,DirectionalLight:_t,PointLight:je,SpotLight:Bt,HemisphereLight:Je,RectAreaLight:Xn,Camera:Ke,PerspectiveCamera:Fe,Scene:Ae,WebGLRenderer:Dt,Clock:Ct,SceneQuotaValidator:pe,exportSceneToCanvas3D:en,exportSceneToGLB:tn,exportSceneToUSDZ:Pn,generateUSDZ:Yt,glbToUSDZ:lt,sceneToCanvas3D:Ie,sceneToGLB:ze,sceneToUSDZ:Le,authorScriptRunner:zn,getAuthorWarnings:Vn,clearAuthorWarnings:on};Object.freeze(pe);Object.freeze(pe.prototype);Object.freeze(Ae.prototype);Object.freeze(Gn);var Qe=new Proxy(Gn,{get:(n,e)=>e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&se(`THREE.${e}`,"no-op proxy"),Pe),set:(n,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(n,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(n,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),He={name:"three_author",THREE:Qe},Gr=He,Z=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Z.THREE>"u"&&(Z.THREE=Qe);typeof Z.requestAnimationFrame!="function"&&(Z.requestAnimationFrame=()=>(se("requestAnimationFrame","single-frame static evaluation"),0));typeof Z.cancelAnimationFrame!="function"&&(Z.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=Qe,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=He,n.ThreeLivePlugins.three_author=He,n.ThreeLivePlugins["three-author"]=He}{Rn();let n=new Ae,e=new Fe(45,1,.1,1e3);e.position.set(0,2,5),Z.scene=n,Z.camera=e,typeof Z.window>"u"&&(Z.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof Z.document>"u"&&(Z.document={createElement:()=>({getContext:()=>Pe,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(Z,"__three_live_reset_scene__",{value:function(){on(),n=new Ae,e=new Fe(45,1,.1,1e3),e.position.set(0,2,5),Z.scene=n,Z.camera=e},writable:!1,configurable:!1});let r=function(u){if(u==null)return null;let o=2e4,a=new Set,h=(l,d)=>{if(--o<0||d>32)return;if(l===null||typeof l=="string"||typeof l=="boolean")return l;if(typeof l=="number")return Number.isFinite(l)?l:void 0;if(typeof l!="object"||a.has(l))return;a.add(l);let f;if(Array.isArray(l)){f=[];for(let T of l)f.push(h(T,d+1)??null)}else{f={};for(let T of Object.keys(l)){if(T==="__proto__"||T==="prototype"||T==="constructor")continue;let A=h(l[T],d+1);A!==void 0&&(f[T]=A)}}return a.delete(l),f};try{return h(u,0)??null}catch{return null}},i=15*1024,s=1e3*4,c=function(u){let o=ht(u);if(!o)return{};let a=JSON.stringify({...u,...o});return a.length>i&&(se(`userData.xr larger than ${i} characters`,"canonical XR traits only"),a=JSON.stringify(o)),{xr_normalized_json:a,xr_scenecore_json:JSON.stringify(Zt(o)),xr_hubs_json:JSON.stringify(Jt(o))}};Object.defineProperty(Z,"__three_live_extract_scene_raw__",{value:function(){let u=[],o=[],a=[],h=[];function l(g){if(!g)return null;let v=h.indexOf(g);if(v===-1){h.push(g);let x="";g.map&&(typeof g.map=="string"?x=g.map:g.map.source?x=g.map.source:g.map.image&&(x=g.map.image)),o.push({name:g.name||`Material_${o.length}`,base_color:[g.color.r,g.color.g,g.color.b,g.opacity!==void 0?g.opacity:1],metallic:g.metalness!==void 0?g.metalness:.1,roughness:g.roughness!==void 0?g.roughness:.5,double_sided:g.side===2||g.doubleSided,base_color_texture:x||null,clearcoat:g.clearcoat||0,clearcoat_roughness:g.clearcoatRoughness||0,transmission:g.transmission||0,ior:g.ior!==void 0?g.ior:1.5,thickness:g.thickness||0}),v=o.length-1}return v}let d=(g,v)=>typeof g=="number"&&Number.isFinite(g)?g:v,f=[],T=[],A=!1,S=Z.scene||n,L=new ye().compose({x:d(S.position?.x,0),y:d(S.position?.y,0),z:d(S.position?.z,0)},{x:d(S.quaternion?.x,0),y:d(S.quaternion?.y,0),z:d(S.quaternion?.z,0),w:d(S.quaternion?.w,1)},{x:d(S.scale?.x,1),y:d(S.scale?.y,1),z:d(S.scale?.z,1)}),b=new Set([S]);{let g=new Set([S]),v=Array.isArray(S.children)?[...S.children]:[],x=0;for(;v.length>0&&x<=s;){let P=v.pop();if(!(!(P instanceof ie)||g.has(P))&&(g.add(P),x++,Array.isArray(P.children)))for(let D of P.children)v.push(D)}if(x>s)return{meshes:[],nodes:new Array(x),materials:[],lights:[]}}let w=[],y=(g,v)=>{let x=Array.isArray(g.children)?g.children:[];for(let P=x.length-1;P>=0;P--)w.push([x[P],v])};y(S,-1);let R=g=>{let v=[];for(let P=g;P>=0&&v.length<=f.length;P=f[P].parent)v.push(P);let x=L.clone();for(let P=v.length-1;P>=0;P--){let D=f[v[P]];x.multiply(new ye().compose({x:D.translation[0],y:D.translation[1],z:D.translation[2]},{x:D.rotation[0],y:D.rotation[1],z:D.rotation[2],w:D.rotation[3]},{x:D.scale[0],y:D.scale[1],z:D.scale[2]}))}return x};for(;w.length>0;){let[g,v]=w.pop();if(!(g instanceof ie)||b.has(g))continue;b.add(g);let x=[d(g.position?.x,0),d(g.position?.y,0),d(g.position?.z,0)],P=[d(g.quaternion?.x,0),d(g.quaternion?.y,0),d(g.quaternion?.z,0),d(g.quaternion?.w,1)],D=[d(g.scale?.x,1),d(g.scale?.y,1),d(g.scale?.z,1)],V=-1,N=g.geometry,U=N?.attributes?.position;U&&U.array&&U.count>0&&(V=u.length,u.push({name:g.name||`Mesh_${u.length}`,raw_positions:U.array,raw_normals:N.attributes.normal?N.attributes.normal.array:null,raw_uvs:N.attributes.uv?N.attributes.uv.array:null,raw_indices:N.index?N.index.array:null,vertex_count:U.count,material_index:l(g.material instanceof me?g.material:null)}));let F=r(g.userData?.xr),C=!!g.userData?.xr&&F!==null,B=f.length;f.push({name:typeof g.name=="string"?g.name.slice(0,1024):"",parent:v,translation:x,rotation:P,scale:D,mesh:V,xr_traits_json:C?JSON.stringify(F):null,...C?c(F):{}});let k=r(g.userData?.interactivity);if(T.push(k),k&&(A=!0),f.length>s)break;if(g instanceof Me){let z=R(B).elements;a.push({light_type:g.type,color:[g.color.r,g.color.g,g.color.b],intensity:g.intensity,position:[d(z[12],0),d(z[13],0),d(z[14],0)]})}y(g,B)}let p=(g,v)=>g.every((x,P)=>x===v[P]),E=r({interactivity:S.userData?.interactivity,gltfExtensions:{KHR_interactivity:S.userData?.gltfExtensions?.KHR_interactivity}}),M=!!(E?.interactivity??E?.gltfExtensions?.KHR_interactivity),_=null;(A||M)&&(_=nt(f.map((g,v)=>({name:g.name,...g.mesh>=0?{mesh:g.mesh}:{},...p(g.translation,[0,0,0])?{}:{translation:g.translation},...p(g.rotation,[0,0,0,1])?{}:{rotation:g.rotation},...p(g.scale,[1,1,1])?{}:{scale:g.scale},extras:T[v]?{interactivity:T[v]}:void 0})),u.map(g=>({primitives:[{material:g.material_index??0}]})),E??void 0));let I=Z.camera||e;return{meshes:u,nodes:f,materials:o,lights:a,interactivity_json:_?JSON.stringify(_):null,camera:{fov:I.fov||45,position:I.position?[I.position.x,I.position.y,I.position.z]:[0,2,5],target:I.target?[I.target.x,I.target.y,I.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var Wr=Qe;return tr($r);})();
|