three-live 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/index.d.ts +190 -0
- package/dist/three-author-engine.js +171 -163
- package/dist/three-author.cjs +145 -163
- package/dist/three-author.d.ts +190 -0
- package/dist/three-author.js +145 -163
- package/dist/three-convert.cjs +142 -160
- package/dist/three-convert.d.ts +190 -0
- package/dist/three-convert.js +142 -160
- package/dist/three-live-ai.cjs +41 -0
- package/dist/three-live-ai.d.ts +759 -0
- package/dist/three-live-ai.js +41 -0
- package/dist/three-live-ai.min.js +41 -0
- package/dist/three-live-animation.cjs +6 -6
- package/dist/three-live-animation.d.ts +190 -0
- package/dist/three-live-animation.js +5 -5
- package/dist/three-live-animation.min.js +5 -5
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +190 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +50 -85
- package/dist/three-live-element.d.ts +190 -0
- package/dist/three-live-element.js +50 -85
- package/dist/three-live-full.cjs +907 -189
- package/dist/three-live-full.js +907 -189
- package/dist/three-live-full.min.js +907 -189
- package/dist/three-live-procedural.cjs +16 -0
- package/dist/three-live-procedural.d.ts +759 -0
- package/dist/three-live-procedural.js +16 -0
- package/dist/three-live-procedural.min.js +16 -0
- package/dist/three-live-sandbox.html +11 -1
- package/dist/three-live-studio.cjs +72 -17
- package/dist/three-live-studio.d.ts +190 -0
- package/dist/three-live-studio.js +72 -17
- package/dist/three-live-studio.min.js +73 -18
- package/dist/three-live-tsl.cjs +103 -0
- package/dist/three-live-tsl.d.ts +759 -0
- package/dist/three-live-tsl.js +103 -0
- package/dist/three-live-tsl.min.js +103 -0
- package/dist/three-live-viewer.cjs +50 -85
- package/dist/three-live-viewer.d.ts +190 -0
- package/dist/three-live-viewer.js +50 -85
- package/dist/three-live-viewer.min.js +50 -85
- package/dist/three-live-webgpu.cjs +585 -0
- package/dist/three-live-webgpu.d.ts +759 -0
- package/dist/three-live-webgpu.js +585 -0
- package/dist/three-live-webgpu.min.js +585 -0
- package/dist/three-live.cjs +147 -165
- package/dist/three-live.js +147 -165
- package/dist/three-live.min.js +147 -165
- package/dist/three-view.cjs +49 -84
- package/dist/three-view.d.ts +190 -0
- package/dist/three-view.js +50 -85
- package/dist/three-xr.cjs +141 -159
- package/dist/three-xr.d.ts +190 -0
- package/dist/three-xr.js +140 -158
- package/package.json +21 -1
package/dist/three-author.cjs
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/var wn=Object.defineProperty,Vr=Object.getOwnPropertyDescriptor,zr=Object.getOwnPropertyNames,Gr=Object.prototype.hasOwnProperty,Hr=(e,t)=>{for(var i in t)wn(e,i,{get:t[i],enumerable:!0})},$r=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of zr(t))!Gr.call(e,s)&&s!==i&&wn(e,s,{get:()=>t[s],enumerable:!(r=Vr(t,s))||r.enumerable});return e},Xr=e=>$r(wn({},"__esModule",{value:!0}),e),Di={};Hr(Di,{AmbientLight:()=>ht,BoxGeometry:()=>at,BufferAttribute:()=>ge,BufferGeometry:()=>de,Camera:()=>dt,CapsuleGeometry:()=>dn,CatmullRomCurve3:()=>Yt,CircleGeometry:()=>pn,Clock:()=>cn,Color:()=>we,ConeGeometry:()=>Ht,CubicBezierCurve3:()=>Kt,Curve3:()=>Fe,CylinderGeometry:()=>ct,DataTexture:()=>Zt,DirectionalLight:()=>sn,DodecahedronGeometry:()=>fn,EdgesGeometry:()=>yn,Euler:()=>ot,Float32BufferAttribute:()=>Ot,Group:()=>rn,HemisphereLight:()=>xt,IcosahedronGeometry:()=>hn,InstancedMesh:()=>mt,LatheGeometry:()=>ut,Light:()=>Ge,Line:()=>Ve,LineBasicMaterial:()=>Je,LineCurve3:()=>Wt,LineDashedMaterial:()=>bn,LineLoop:()=>xn,LineSegments:()=>vn,MAX_INSTANCES_PER_MESH:()=>lt,Material:()=>Me,MathUtils:()=>Tr,Matrix3:()=>Ut,Matrix4:()=>Be,Mesh:()=>Ie,MeshBasicMaterial:()=>Qt,MeshLambertMaterial:()=>en,MeshPhongMaterial:()=>tn,MeshPhysicalMaterial:()=>nn,MeshStandardMaterial:()=>ze,Object3D:()=>Ae,OctahedronGeometry:()=>mn,PerspectiveCamera:()=>on,PlaneGeometry:()=>zt,PointLight:()=>ft,Points:()=>Mn,PointsMaterial:()=>yt,PolyhedronFallbackGeometry:()=>wi,PolyhedronGeometry:()=>ke,QuadraticBezierCurve3:()=>jt,Quaternion:()=>Ye,RawShaderMaterial:()=>Fr,RectAreaLight:()=>Or,RingGeometry:()=>gt,Scene:()=>pt,SceneQuotaValidator:()=>De,ShaderMaterial:()=>bt,SphereGeometry:()=>Gt,SpotLight:()=>Tn,THREE:()=>$e,TetrahedronGeometry:()=>ln,Texture:()=>qe,TextureLoader:()=>Jt,TorusGeometry:()=>$t,TorusKnotGeometry:()=>Xt,TubeGeometry:()=>qt,Uint16BufferAttribute:()=>Bt,Uint32BufferAttribute:()=>Vt,Vector2:()=>Se,Vector3:()=>ee,Vector4:()=>kt,WebGLRenderer:()=>an,WireframeGeometry:()=>gn,authorScriptRunner:()=>Nr,buildSandboxWorkerSource:()=>Bn,clearAuthorWarnings:()=>Pr,default:()=>Ci,exportSceneToCanvas3D:()=>Fn,exportSceneToGLB:()=>kn,exportSceneToUSDZ:()=>wr,generateUSDZ:()=>Ln,getAllowClientScripts:()=>Rr,getAuthorWarnings:()=>Lr,getSandboxEngineSrc:()=>Un,getSandboxIframeSrc:()=>Er,glbToUSDZ:()=>It,isAllowedSandboxEngineUrl:()=>Ze,noopProxy:()=>it,sceneToCanvas3D:()=>Ke,sceneToGLB:()=>tt,sceneToUSDZ:()=>nt,setAllowClientScripts:()=>bi,setSandboxEngineSrc:()=>hi,setSandboxIframeSrc:()=>di,threeAuthorPlugin:()=>st,threeMicroPlugin:()=>Ri,toTrustedWorkerScriptURL:()=>Ar,validateSandboxWorkerMessage:()=>Vn,warnUnsupported:()=>He}),module.exports=Xr(Di);function zn(e,t,i){let r=[],s=new Map,n=[],a=[],o=[],l=new Map,h=c=>{let m=s.get(c);return m===void 0&&(m=r.length,r.push({op:c}),s.set(c,m)),m},u=c=>{let m=l.get(c);return m===void 0&&(m=o.length,o.push({id:c}),l.set(c,m)),m},f=(c,m={})=>n.push({declaration:h(c),...m})-1,g=(c,m,v)=>a.push({id:c,type:m,value:v})-1,w=c=>({node:c,socket:"value"}),p=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(p&&typeof p=="object"){let c=Array.isArray(p.graphs)?p.graphs[p.graph??0]:p;if(c&&Array.isArray(c.nodes)){let m=Array.isArray(c.declarations)?c.declarations:[];for(let v of m)v?.op&&h(v.op);Array.isArray(c.variables)&&a.push(...c.variables);for(let v of c.events||[])v?.id&&u(v.id);for(let v of c.nodes){if(!v||typeof v!="object")continue;let S=v.op||(typeof v.declaration=="number"?m[v.declaration]?.op:"");n.push(S?{...v,declaration:h(S)}:{...v})}}}let b=(c,m,v="translation")=>v==="baseColorFactor"||v==="metallicFactor"||v==="roughnessFactor"?`/materials/${Math.max(0,m)}/pbrMetallicRoughness/${v}`:v==="emissiveFactor"||v==="alphaCutoff"?`/materials/${Math.max(0,m)}/${v}`:v==="visible"?`/nodes/${c}/extensions/KHR_node_visibility/visible`:`/nodes/${c}/${v}`,T=new Map;e.forEach((c,m)=>{typeof c?.name=="string"&&!T.has(c.name)&&T.set(c.name,m)});let x=(c,m)=>typeof c.target=="string"&&T.has(c.target)?T.get(c.target):typeof c.targetNode=="number"?c.targetNode:m,M=c=>{let m=e[c];return(typeof m?.mesh=="number"?t[m.mesh]?.primitives?.[0]?.material:0)??0};for(let c=0;c<e.length;c++){let m=e[c],v=m?.extras?.interactivity;if(!v||typeof v!="object")continue;let S=(typeof m.mesh=="number"?t[m.mesh]?.primitives?.[0]?.material:0)??0,D=P=>{let N=Array.isArray(P)?P:[P],C=[];for(let E=0;E<N.length;E++){let y=N[E];if(!y||typeof y!="object")continue;let F=y.action||"interpolate",z=typeof y.duration=="number"?y.duration:.35;if(F==="toggleTransform"){let A=y.property==="rotation"||y.property==="scale"?y.property:"translation",_=A==="rotation"?m.rotation||[0,0,0,1]:A==="scale"?m.scale||[1,1,1]:m.translation||[0,0,0],d=`/nodes/${c}/${A}`,R=g(`__toggle_${c}_${E}`,"bool",!1),G=f("variable/get",{configuration:{variable:R}}),H=f("math/not",{values:{a:w(G)}}),B=f("variable/set",{configuration:{variable:R},values:{value:w(H)}}),Z=f("pointer/interpolate",{configuration:{pointer:d},values:{value:{value:Array.isArray(y.to)?y.to:_},duration:{value:z}}}),k=f("pointer/interpolate",{configuration:{pointer:d},values:{value:{value:Array.isArray(y.from)?y.from:_},duration:{value:z}}});n[B].flows={out:{node:f("flow/branch",{values:{condition:w(G)},flows:{true:{node:Z},false:{node:k}}})}},C.push(B)}else if(F==="interpolate"){let A=y.to??y.value;if(A===void 0)continue;let _={value:{value:A},duration:{value:z}};y.from!==void 0&&(_.from={value:y.from}),C.push(f("pointer/interpolate",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:b(x(y,c),M(x(y,c)),y.property)},values:_}))}else if(F==="setProperty"){if(y.value===void 0)continue;C.push(f("pointer/set",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:b(x(y,c),M(x(y,c)),y.property)},values:{value:{value:y.value}}}))}else if(F==="toggleVisibility"){let A=x(y,c),_=g(`__vis_${A}_${E}`,"bool",!0),d=f("variable/get",{configuration:{variable:_}}),R=f("math/not",{values:{a:w(d)}}),G=f("variable/set",{configuration:{variable:_},values:{value:w(R)}});n[G].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${A}/extensions/KHR_node_visibility/visible`},values:{value:w(d)}})}},C.push(G)}else if(F==="cycleMaterialColor"&&Array.isArray(y.colors)&&y.colors.length>0){let A=typeof y.duration=="number"?y.duration:.25,_=`/materials/${Math.max(0,S)}/pbrMetallicRoughness/baseColorFactor`,d=g(`__color_idx_${c}_${E}`,"int",0),R=f("variable/get",{configuration:{variable:d}}),G=f("math/add",{values:{a:w(R),b:{value:1}}}),H=f("math/rem",{values:{a:w(G),b:{value:y.colors.length}}}),B=f("variable/set",{configuration:{variable:d},values:{value:w(H)}}),Z={};for(let k=0;k<y.colors.length;k++){let Y=y.colors[k],ie=Array.isArray(Y)&&Y.length>=3?[Y[0],Y[1],Y[2],Y[3]??1]:[1,1,1,1];Z[String(k)]={node:A>0?f("pointer/interpolate",{configuration:{pointer:_},values:{value:{value:ie},duration:{value:A}}}):f("pointer/set",{configuration:{pointer:_},values:{value:{value:ie}}})}}n[B].flows={out:{node:f("flow/switch",{values:{selection:w(R)},flows:Z})}},C.push(B)}else if(F==="playAnimation")C.push(f("animation/start",{configuration:{animation:y.animation??y.clip??0}}));else if(F==="stopAnimation")C.push(f("animation/stop"));else if(F==="sendEvent"){let A={};for(let[_,d]of Object.entries(y.values||{}))A[_]={value:d};C.push(f("event/send",{configuration:{event:u(String(y.event??y.id??"custom"))},values:A}))}}if(!C.length)return null;if(C.length===1)return C[0];let L={};return C.forEach((E,y)=>{L[String(y)]={node:E}}),f("flow/sequence",{flows:L})},I=(P,N,C)=>{let L=D(N);L!==null&&f(P,{...C?{configuration:C}:{},flows:{out:{node:L}}})};if(v.onSelect&&I("pointer/onSelect",v.onSelect,{nodeIndex:c}),v.onHoverIn&&I("pointer/onHoverIn",v.onHoverIn,{nodeIndex:c}),v.onHoverOut&&I("pointer/onHoverOut",v.onHoverOut,{nodeIndex:c}),v.onStart&&I("event/onStart",v.onStart),v.onReceive&&typeof v.onReceive=="object")for(let[P,N]of Object.entries(v.onReceive))I("event/receive",N,{event:u(P)})}return n.length?{graphs:[{declarations:r,nodes:n,variables:a,events:o}],graph:0}:null}var Gn='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).',Hn="Security Error: client-side scripts require allow-client-scripts opt-in.",vt="__THREE_LIVE_REGISTRY__";function le(){let e=typeof globalThis<"u"?globalThis:{};if(!e[vt]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,vt,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[vt]=t}}return e[vt]}var pe=le().plugins;function $n(e){let t=le().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function Xn(){return le().plugins}function he(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Mt(e,t,i,r,s){let n=1/Math.tan(t/2);e.fill(0),e[0]=n/i,e[5]=n,e[11]=-1;let a=1/(r-s);return e[10]=(s+r)*a,e[14]=2*s*r*a,e}function We(e,t,i,r){let[s,n,a]=t,[o,l,h]=r,[u,f,g]=i,w=s-u,p=n-f,b=a-g,T=Math.hypot(w,p,b);T<=1e-5?(w=0,p=0,b=1):(w/=T,p/=T,b/=T);let x=l*b-h*p,M=h*w-o*b,c=o*p-l*w;T=Math.hypot(x,M,c),T<=1e-5?(x=0,M=0,c=0):(x/=T,M/=T,c/=T);let m=p*c-b*M,v=b*x-w*c,S=w*M-p*x;return T=Math.hypot(m,v,S),T<=1e-5?(m=0,v=0,S=0):(m/=T,v/=T,S/=T),e[0]=x,e[1]=m,e[2]=w,e[3]=0,e[4]=M,e[5]=v,e[6]=p,e[7]=0,e[8]=c,e[9]=S,e[10]=b,e[11]=0,e[12]=-(x*s+M*n+c*a),e[13]=-(m*s+v*n+S*a),e[14]=-(w*s+p*n+b*a),e[15]=1,e}function be(e,t,i){let r=t[0],s=t[1],n=t[2],a=t[3],o=t[4],l=t[5],h=t[6],u=t[7],f=t[8],g=t[9],w=t[10],p=t[11],b=t[12],T=t[13],x=t[14],M=t[15],c=i[0],m=i[1],v=i[2],S=i[3];return e[0]=c*r+m*o+v*f+S*b,e[1]=c*s+m*l+v*g+S*T,e[2]=c*n+m*h+v*w+S*x,e[3]=c*a+m*u+v*p+S*M,c=i[4],m=i[5],v=i[6],S=i[7],e[4]=c*r+m*o+v*f+S*b,e[5]=c*s+m*l+v*g+S*T,e[6]=c*n+m*h+v*w+S*x,e[7]=c*a+m*u+v*p+S*M,c=i[8],m=i[9],v=i[10],S=i[11],e[8]=c*r+m*o+v*f+S*b,e[9]=c*s+m*l+v*g+S*T,e[10]=c*n+m*h+v*w+S*x,e[11]=c*a+m*u+v*p+S*M,c=i[12],m=i[13],v=i[14],S=i[15],e[12]=c*r+m*o+v*f+S*b,e[13]=c*s+m*l+v*g+S*T,e[14]=c*n+m*h+v*w+S*x,e[15]=c*a+m*u+v*p+S*M,e}function Qe(e,t,i,r){let s=t[0],n=t[1],a=t[2],o=t[3],l=s+s,h=n+n,u=a+a,f=s*l,g=s*h,w=s*u,p=n*h,b=n*u,T=a*u,x=o*l,M=o*h,c=o*u,m=r[0],v=r[1],S=r[2];return e[0]=(1-(p+T))*m,e[1]=(g+c)*m,e[2]=(w-M)*m,e[3]=0,e[4]=(g-c)*v,e[5]=(1-(f+T))*v,e[6]=(b+x)*v,e[7]=0,e[8]=(w+M)*S,e[9]=(b-x)*S,e[10]=(1-(f+p))*S,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function Ce(e,t,i=0){let r=t[0],s=t[1],n=t[2],a=t[4],o=t[5],l=t[6],h=t[8],u=t[9],f=t[10],g=f*o-l*u,w=-f*a+l*h,p=u*a-o*h,b=r*g+s*w+n*p;return!b||i>0&&(!Number.isFinite(b)||Math.abs(b)<=i)||(b=1/b,e[0]=g*b,e[1]=w*b,e[2]=p*b,e[3]=(-f*s+n*u)*b,e[4]=(f*r-n*h)*b,e[5]=(-u*r+s*h)*b,e[6]=(l*s-n*o)*b,e[7]=(-l*r+n*a)*b,e[8]=(o*r-s*a)*b),e}function Wn(e,t){let i=t[0],r=t[1],s=t[2],n=t[3],a=t[4],o=t[5],l=t[6],h=t[7],u=t[8],f=t[9],g=t[10],w=t[11],p=t[12],b=t[13],T=t[14],x=t[15],M=i*o-r*a,c=i*l-s*a,m=i*h-n*a,v=r*l-s*o,S=r*h-n*o,D=s*h-n*l,I=u*b-f*p,P=u*T-g*p,N=u*x-w*p,C=f*T-g*b,L=f*x-w*b,E=g*x-w*T,y=M*E-c*L+m*C+v*N-S*P+D*I;return y?(y=1/y,e[0]=(o*E-l*L+h*C)*y,e[1]=(s*L-r*E-n*C)*y,e[2]=(b*D-T*S+x*v)*y,e[3]=(g*S-f*D-w*v)*y,e[4]=(l*N-a*E-h*P)*y,e[5]=(i*E-s*N+n*P)*y,e[6]=(T*m-p*D-x*c)*y,e[7]=(u*D-g*m+w*c)*y,e[8]=(a*L-o*N+h*I)*y,e[9]=(r*N-i*L-n*I)*y,e[10]=(p*S-b*m+x*M)*y,e[11]=(f*m-u*S-w*M)*y,e[12]=(o*P-a*C-l*I)*y,e[13]=(i*C-r*P+s*I)*y,e[14]=(b*c-p*v-T*M)*y,e[15]=(u*v-f*c+g*M)*y,e):null}function An(e,t,i,r,s){let n=s[0]*t+s[4]*i+s[8]*r+s[12],a=s[1]*t+s[5]*i+s[9]*r+s[13],o=s[2]*t+s[6]*i+s[10]*r+s[14],l=s[3]*t+s[7]*i+s[11]*r+s[15],h=l!==0?1/l:1;e[0]=n*h,e[1]=a*h,e[2]=o*h}function jn(e,t,i,r,s,n,a,o,l,h,u,f,g,w,p,b,T=0){let x=h-a,M=u-o,c=f-l,m=g-a,v=w-o,S=p-l,D=s*S-n*v,I=n*m-r*S,P=r*v-s*m,N=x*D+M*I+c*P;if(N>-1e-7&&N<1e-7)return!1;let C=1/N,L=e-a,E=t-o,y=i-l,F=C*(L*D+E*I+y*P);if(F<-T||F>1+T)return!1;let z=E*c-y*M,A=y*x-L*c,_=L*M-E*x,d=C*(r*z+s*A+n*_);if(d<-T||F+d>1+T)return!1;let R=C*(m*z+v*A+S*_);if(R>1e-4&&R<b.distance){b.distance=R,b.point=[e+r*R,t+s*R,i+n*R];let G=M*S-c*v,H=c*m-x*S,B=x*v-M*m,Z=Math.hypot(G,H,B)||1;return b.normal=[G/Z,H/Z,B/Z],!0}return!1}function Kn(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let u=0;u<i;u++)r.push(he());if(i===0)return r;let s=new Set;for(let u of e.nodes)if(Array.isArray(u.children))for(let f of u.children)s.add(f);let n=new Set,a=128,o=(u,f,g=0)=>{if(g>a||u<0||u>=i||n.has(u))return;n.add(u);let w=e.nodes[u];if(!w)return;let p=he();if(t&&t[u])p.set(t[u]);else if(w.matrix&&w.matrix.length===16)p.set(w.matrix);else{let T=w.translation||[0,0,0],x=w.rotation||[0,0,0,1],M=w.scale||[1,1,1];Qe(p,x,T,M)}let b=r[u];if(f?be(b,f,p):b.set(p),Array.isArray(w.children))for(let T of w.children)typeof T=="number"&&o(T,b,g+1)},l=[],h=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(h&&Array.isArray(h.nodes))l.push(...h.nodes);else for(let u=0;u<i;u++)s.has(u)||l.push(u);for(let u of l)o(u,null);for(let u=0;u<i;u++)!s.has(u)&&!l.includes(u)&&o(u,null);return r}var Wr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function En(e,t,i,r){if(!i||i.bufferView===void 0)return null;let s=e.bufferViews?.[i.bufferView];if(!s)return null;let n=Number(i.count??0);if(!Number.isInteger(n)||n<=0)return null;let a=i.componentType??5126,o=Wr[a];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let l=o*r,h=s.byteStride&&s.byteStride>0?s.byteStride:l,u=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(u)||u<0||h<l||u+(n-1)*h+l>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(a===5126&&h===l&&u%4===0)return new Float32Array(t,u,n*r);let f=new DataView(t),g=i.normalized===!0,w=new Float32Array(n*r);for(let p=0;p<n;p++){let b=u+p*h;for(let T=0;T<r;T++){let x=b+T*o,M;switch(a){case 5126:M=f.getFloat32(x,!0);break;case 5120:M=f.getInt8(x),g&&(M=Math.max(M/127,-1));break;case 5121:M=f.getUint8(x),g&&(M/=255);break;case 5122:M=f.getInt16(x,!0),g&&(M=Math.max(M/32767,-1));break;case 5123:M=f.getUint16(x,!0),g&&(M/=65535);break;default:M=f.getUint32(x,!0),g&&(M/=4294967295)}w[p*r+T]=M}}return w}function Yn(e,t){let i=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,s=Number(t.scale?.[0]??1),n=Number(t.scale?.[1]??1),a=Number(t.rotation??0)||0,o=Math.cos(a),l=Math.sin(a),h=(Number.isFinite(s)?s:1)*o,u=(Number.isFinite(s)?s:1)*l,f=-(Number.isFinite(n)?n:1)*l,g=(Number.isFinite(n)?n:1)*o;for(let w=0;w+1<e.length;w+=2){let p=e[w],b=e[w+1];e[w]=h*p+u*b+i,e[w+1]=f*p+g*b+r}}function Tt(e,t,i,r=!0){let s=[],n=null;try{for(let[a,o]of[[35633,t],[35632,i]]){let l=e.createShader(a);if(!l){if(r)throw new Error("Shader allocation failed");return null}if(s.push(l),e.shaderSource(l,o),e.compileShader(l),e.getShaderParameter&&!e.getShaderParameter(l,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(l)}`);return null}}if(n=e.createProgram(),!n){if(r)throw new Error("Program allocation failed");return null}for(let a of s)e.attachShader(n,a);if(e.linkProgram(n),e.getProgramParameter&&!e.getProgramParameter(n,35714)){let a=r?e.getProgramInfoLog(n):null;if(e.deleteProgram?.(n),n=null,r)throw new Error(`Program link error: ${a}`);return null}return n}finally{for(let a of s)n&&e.detachShader?.(n,a),e.deleteShader?.(a)}}var Jn=["neutral","reinhard","none","aces","agx"];function Dn(e){let t=String(e??"").trim().toLowerCase();return Jn.includes(t)?t:"neutral"}function jr(e){return Jn.indexOf(Dn(e))}function Kr(e){return new TextDecoder().decode(e)}var Qn=le().decoders;function Yr(e,t){Qn.set(e.toLowerCase(),t)}function je(e){return Qn.get(e.toLowerCase())}function er(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,i=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let g=i.getUint8(0);throw g===123||g===32||g===10||g===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 s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let n=i.getUint32(8,!0),a=12,o=null,l=null;for(;a+8<=n&&a+8<=t.byteLength;){let g=i.getUint32(a,!0),w=i.getUint32(a+4,!0),p=a+8;if(p+g>t.byteLength)throw new Error(`Truncated GLB chunk: required ${p+g} bytes, buffer has ${t.byteLength}`);if(w===1313821514){let b=new Uint8Array(t,p,g),T=Kr(b);o=JSON.parse(T,(x,M)=>x==="__proto__"||x==="constructor"||x==="prototype"?void 0:M)}else w===5130562&&(l=t.slice(p,p+g));a=p+g}if(!o)throw new Error("Missing JSON chunk in GLB");let h=o.extensionsRequired||[];if(h.includes("KHR_draco_mesh_compression")&&!je("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let g of["EXT_meshopt_compression","KHR_meshopt_compression"])if(h.includes(g)&&!je("meshopt"))throw new Error(`Model requires ${g}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(h.includes("KHR_texture_basisu")&&!je("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=l||new ArrayBuffer(0),f={gltf:o,bin:u,animations:[]};for(let g of pe)g.onParseGLB?.(f);return f}function qr(e){return typeof e=="object"&&e!==null&&"gltf"in e&&typeof e.gltf=="object"&&e.gltf!==null&&"bin"in e&&(e.bin instanceof ArrayBuffer||ArrayBuffer.isView(e.bin))}function wt(e){if(qr(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return er(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var tr=`#version 300 es
|
|
16
|
+
*/var On=Object.defineProperty,ni=Object.getOwnPropertyDescriptor,ri=Object.getOwnPropertyNames,ii=Object.prototype.hasOwnProperty,oi=(t,e)=>{for(var i in e)On(t,i,{get:e[i],enumerable:!0})},si=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ri(e))!ii.call(t,n)&&n!==i&&On(t,n,{get:()=>e[n],enumerable:!(r=ni(e,n))||r.enumerable});return t},ai=t=>si(On({},"__esModule",{value:!0}),t),Ki={};oi(Ki,{AmbientLight:()=>St,BoxGeometry:()=>bt,BufferAttribute:()=>we,BufferGeometry:()=>xe,Camera:()=>_t,CapsuleGeometry:()=>_n,CatmullRomCurve3:()=>sn,CircleGeometry:()=>An,Clock:()=>yn,Color:()=>Pe,ConeGeometry:()=>Qt,CubicBezierCurve3:()=>on,Curve3:()=>ze,CylinderGeometry:()=>gt,DataTexture:()=>cn,DirectionalLight:()=>pn,DodecahedronGeometry:()=>wn,EdgesGeometry:()=>Rn,Euler:()=>pt,Float32BufferAttribute:()=>Kt,Group:()=>fn,HemisphereLight:()=>Lt,IcosahedronGeometry:()=>Sn,InstancedMesh:()=>vt,LatheGeometry:()=>yt,Light:()=>Ge,LightShadow:()=>Mt,Line:()=>Ke,LineBasicMaterial:()=>nt,LineCurve3:()=>nn,LineDashedMaterial:()=>Tn,LineLoop:()=>Ln,LineSegments:()=>Cn,MAX_INSTANCES_PER_MESH:()=>xt,Material:()=>Ce,MathUtils:()=>Br,Matrix3:()=>Xt,Matrix4:()=>We,Mesh:()=>Oe,MeshBasicMaterial:()=>ln,MeshLambertMaterial:()=>mn,MeshPhongMaterial:()=>hn,MeshPhysicalMaterial:()=>dn,MeshStandardMaterial:()=>qe,Object3D:()=>ke,OctahedronGeometry:()=>Mn,PerspectiveCamera:()=>bn,PlaneGeometry:()=>Zt,PointLight:()=>wt,Points:()=>Dn,PointsMaterial:()=>Rt,PolyhedronFallbackGeometry:()=>Hi,PolyhedronGeometry:()=>He,QuadraticBezierCurve3:()=>rn,Quaternion:()=>Qe,RawShaderMaterial:()=>Jr,RectAreaLight:()=>Nn,RingGeometry:()=>Et,Scene:()=>At,SceneQuotaValidator:()=>Ue,ShaderMaterial:()=>Tt,SphereGeometry:()=>Jt,SpotLight:()=>In,THREE:()=>Ze,TetrahedronGeometry:()=>vn,Texture:()=>et,TextureLoader:()=>un,TorusGeometry:()=>en,TorusKnotGeometry:()=>tn,TubeGeometry:()=>an,Uint16BufferAttribute:()=>Yt,Uint32BufferAttribute:()=>qt,Vector2:()=>Ee,Vector3:()=>Q,Vector4:()=>Wt,WebGLRenderer:()=>gn,WireframeGeometry:()=>En,authorScriptRunner:()=>Yr,buildSandboxWorkerSource:()=>or,clearAuthorWarnings:()=>Zr,default:()=>Xi,exportSceneToCanvas3D:()=>tr,exportSceneToGLB:()=>nr,exportSceneToUSDZ:()=>Gr,generateUSDZ:()=>Jn,getAllowClientScripts:()=>$r,getAuthorWarnings:()=>qr,getSandboxEngineSrc:()=>rr,getSandboxIframeSrc:()=>jr,glbToUSDZ:()=>zt,isAllowedSandboxEngineUrl:()=>tt,noopProxy:()=>dt,sceneToCanvas3D:()=>Je,sceneToGLB:()=>lt,sceneToUSDZ:()=>mt,setAllowClientScripts:()=>Pi,setSandboxEngineSrc:()=>Ci,setSandboxIframeSrc:()=>Ii,threeAuthorPlugin:()=>ft,threeMicroPlugin:()=>Wi,toTrustedWorkerScriptURL:()=>Hr,validateSandboxWorkerMessage:()=>sr,warnUnsupported:()=>Xe}),module.exports=ai(Ki);function cr(t,e,i){let r=[],n=new Map,s=[],a=[],o=[],l=new Map,y=p=>{let x=n.get(p);return x===void 0&&(x=r.length,r.push({op:p}),n.set(p,x)),x},f=p=>{let x=l.get(p);return x===void 0&&(x=o.length,o.push({id:p}),l.set(p,x)),x},b=(p,x={})=>s.push({declaration:y(p),...x})-1,h=(p,x,w)=>a.push({id:p,type:x,value:w})-1,d=p=>({node:p,socket:"value"}),v=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(v&&typeof v=="object"){let p=Array.isArray(v.graphs)?v.graphs[v.graph??0]:v;if(p&&Array.isArray(p.nodes)){let x=Array.isArray(p.declarations)?p.declarations:[];for(let w of x)w?.op&&y(w.op);Array.isArray(p.variables)&&a.push(...p.variables);for(let w of p.events||[])w?.id&&f(w.id);for(let w of p.nodes){if(!w||typeof w!="object")continue;let _=w.op||(typeof w.declaration=="number"?x[w.declaration]?.op:"");s.push(_?{...w,declaration:y(_)}:{...w})}}}let M=(p,x,w="translation")=>w==="baseColorFactor"||w==="metallicFactor"||w==="roughnessFactor"?`/materials/${Math.max(0,x)}/pbrMetallicRoughness/${w}`:w==="emissiveFactor"||w==="alphaCutoff"?`/materials/${Math.max(0,x)}/${w}`:w==="visible"?`/nodes/${p}/extensions/KHR_node_visibility/visible`:`/nodes/${p}/${w}`,m=new Map;t.forEach((p,x)=>{typeof p?.name=="string"&&!m.has(p.name)&&m.set(p.name,x)});let u=(p,x)=>typeof p.target=="string"&&m.has(p.target)?m.get(p.target):typeof p.targetNode=="number"?p.targetNode:x,g=p=>{let x=t[p];return(typeof x?.mesh=="number"?e[x.mesh]?.primitives?.[0]?.material:0)??0};for(let p=0;p<t.length;p++){let x=t[p],w=x?.extras?.interactivity;if(!w||typeof w!="object")continue;let _=(typeof x.mesh=="number"?e[x.mesh]?.primitives?.[0]?.material:0)??0,N=E=>{let T=Array.isArray(E)?E:[E],S=[];for(let D=0;D<T.length;D++){let R=T[D];if(!R||typeof R!="object")continue;let F=R.action||"interpolate",k=typeof R.duration=="number"?R.duration:.35;if(F==="toggleTransform"){let V=R.property==="rotation"||R.property==="scale"?R.property:"translation",L=V==="rotation"?x.rotation||[0,0,0,1]:V==="scale"?x.scale||[1,1,1]:x.translation||[0,0,0],O=`/nodes/${p}/${V}`,c=h(`__toggle_${p}_${D}`,"bool",!1),I=b("variable/get",{configuration:{variable:c}}),C=b("math/not",{values:{a:d(I)}}),U=b("variable/set",{configuration:{variable:c},values:{value:d(C)}}),j=b("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Array.isArray(R.to)?R.to:L},duration:{value:k}}}),H=b("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Array.isArray(R.from)?R.from:L},duration:{value:k}}});s[U].flows={out:{node:b("flow/branch",{values:{condition:d(I)},flows:{true:{node:j},false:{node:H}}})}},S.push(U)}else if(F==="interpolate"){let V=R.to??R.value;if(V===void 0)continue;let L={value:{value:V},duration:{value:k}};R.from!==void 0&&(L.from={value:R.from}),S.push(b("pointer/interpolate",{configuration:{pointer:typeof R.pointer=="string"?R.pointer:M(u(R,p),g(u(R,p)),R.property)},values:L}))}else if(F==="setProperty"){if(R.value===void 0)continue;S.push(b("pointer/set",{configuration:{pointer:typeof R.pointer=="string"?R.pointer:M(u(R,p),g(u(R,p)),R.property)},values:{value:{value:R.value}}}))}else if(F==="toggleVisibility"){let V=u(R,p),L=h(`__vis_${V}_${D}`,"bool",!0),O=b("variable/get",{configuration:{variable:L}}),c=b("math/not",{values:{a:d(O)}}),I=b("variable/set",{configuration:{variable:L},values:{value:d(c)}});s[I].flows={out:{node:b("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:d(O)}})}},S.push(I)}else if(F==="cycleMaterialColor"&&Array.isArray(R.colors)&&R.colors.length>0){let V=typeof R.duration=="number"?R.duration:.25,L=`/materials/${Math.max(0,_)}/pbrMetallicRoughness/baseColorFactor`,O=h(`__color_idx_${p}_${D}`,"int",0),c=b("variable/get",{configuration:{variable:O}}),I=b("math/add",{values:{a:d(c),b:{value:1}}}),C=b("math/rem",{values:{a:d(I),b:{value:R.colors.length}}}),U=b("variable/set",{configuration:{variable:O},values:{value:d(C)}}),j={};for(let H=0;H<R.colors.length;H++){let Y=R.colors[H],q=Array.isArray(Y)&&Y.length>=3?[Y[0],Y[1],Y[2],Y[3]??1]:[1,1,1,1];j[String(H)]={node:V>0?b("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:q},duration:{value:V}}}):b("pointer/set",{configuration:{pointer:L},values:{value:{value:q}}})}}s[U].flows={out:{node:b("flow/switch",{values:{selection:d(c)},flows:j})}},S.push(U)}else if(F==="playAnimation")S.push(b("animation/start",{configuration:{animation:R.animation??R.clip??0}}));else if(F==="stopAnimation")S.push(b("animation/stop"));else if(F==="sendEvent"){let V={};for(let[L,O]of Object.entries(R.values||{}))V[L]={value:O};S.push(b("event/send",{configuration:{event:f(String(R.event??R.id??"custom"))},values:V}))}}if(!S.length)return null;if(S.length===1)return S[0];let A={};return S.forEach((D,R)=>{A[String(R)]={node:D}}),b("flow/sequence",{flows:A})},P=(E,T,S)=>{let A=N(T);A!==null&&b(E,{...S?{configuration:S}:{},flows:{out:{node:A}}})};if(w.onSelect&&P("pointer/onSelect",w.onSelect,{nodeIndex:p}),w.onHoverIn&&P("pointer/onHoverIn",w.onHoverIn,{nodeIndex:p}),w.onHoverOut&&P("pointer/onHoverOut",w.onHoverOut,{nodeIndex:p}),w.onStart&&P("event/onStart",w.onStart),w.onReceive&&typeof w.onReceive=="object")for(let[E,T]of Object.entries(w.onReceive))P("event/receive",T,{event:f(E)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:a,events:o}],graph:0}:null}var ur='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).',lr="Security Error: client-side scripts require allow-client-scripts opt-in.",Dt="__THREE_LIVE_REGISTRY__";function de(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Dt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Dt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Dt]=e}}return t[Dt]}var ge=de().plugins;function mr(t){let e=de().plugins;e.some(i=>i.name===t.name)||e.push(t),t.onRegister?.()}function hr(){return de().plugins}function ve(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Bn(t,e,i,r,n){let s=1/Math.tan(e/2);t.fill(0),t[0]=s/i,t[5]=s,t[11]=-1;let a=1/(r-n);return t[10]=(n+r)*a,t[14]=2*n*r*a,t}function it(t,e,i,r){let[n,s,a]=e,[o,l,y]=r,[f,b,h]=i,d=n-f,v=s-b,M=a-h,m=Math.hypot(d,v,M);m<=1e-5?(d=0,v=0,M=1):(d/=m,v/=m,M/=m);let u=l*M-y*v,g=y*d-o*M,p=o*v-l*d;m=Math.hypot(u,g,p),m<=1e-5?(u=0,g=0,p=0):(u/=m,g/=m,p/=m);let x=v*p-M*g,w=M*u-d*p,_=d*g-v*u;return m=Math.hypot(x,w,_),m<=1e-5?(x=0,w=0,_=0):(x/=m,w/=m,_/=m),t[0]=u,t[1]=x,t[2]=d,t[3]=0,t[4]=g,t[5]=w,t[6]=v,t[7]=0,t[8]=p,t[9]=_,t[10]=M,t[11]=0,t[12]=-(u*n+g*s+p*a),t[13]=-(x*n+w*s+_*a),t[14]=-(d*n+v*s+M*a),t[15]=1,t}function Me(t,e,i){let r=e[0],n=e[1],s=e[2],a=e[3],o=e[4],l=e[5],y=e[6],f=e[7],b=e[8],h=e[9],d=e[10],v=e[11],M=e[12],m=e[13],u=e[14],g=e[15],p=i[0],x=i[1],w=i[2],_=i[3];return t[0]=p*r+x*o+w*b+_*M,t[1]=p*n+x*l+w*h+_*m,t[2]=p*s+x*y+w*d+_*u,t[3]=p*a+x*f+w*v+_*g,p=i[4],x=i[5],w=i[6],_=i[7],t[4]=p*r+x*o+w*b+_*M,t[5]=p*n+x*l+w*h+_*m,t[6]=p*s+x*y+w*d+_*u,t[7]=p*a+x*f+w*v+_*g,p=i[8],x=i[9],w=i[10],_=i[11],t[8]=p*r+x*o+w*b+_*M,t[9]=p*n+x*l+w*h+_*m,t[10]=p*s+x*y+w*d+_*u,t[11]=p*a+x*f+w*v+_*g,p=i[12],x=i[13],w=i[14],_=i[15],t[12]=p*r+x*o+w*b+_*M,t[13]=p*n+x*l+w*h+_*m,t[14]=p*s+x*y+w*d+_*u,t[15]=p*a+x*f+w*v+_*g,t}function ot(t,e,i,r){let n=e[0],s=e[1],a=e[2],o=e[3],l=n+n,y=s+s,f=a+a,b=n*l,h=n*y,d=n*f,v=s*y,M=s*f,m=a*f,u=o*l,g=o*y,p=o*f,x=r[0],w=r[1],_=r[2];return t[0]=(1-(v+m))*x,t[1]=(h+p)*x,t[2]=(d-g)*x,t[3]=0,t[4]=(h-p)*w,t[5]=(1-(b+m))*w,t[6]=(M+u)*w,t[7]=0,t[8]=(d+g)*_,t[9]=(M-u)*_,t[10]=(1-(b+v))*_,t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1,t}function Fe(t,e,i=0){let r=e[0],n=e[1],s=e[2],a=e[4],o=e[5],l=e[6],y=e[8],f=e[9],b=e[10],h=b*o-l*f,d=-b*a+l*y,v=f*a-o*y,M=r*h+n*d+s*v;return!M||i>0&&(!Number.isFinite(M)||Math.abs(M)<=i)||(M=1/M,t[0]=h*M,t[1]=d*M,t[2]=v*M,t[3]=(-b*n+s*f)*M,t[4]=(b*r-s*y)*M,t[5]=(-f*r+n*y)*M,t[6]=(l*n-s*o)*M,t[7]=(-l*r+s*a)*M,t[8]=(o*r-n*a)*M),t}function dr(t,e){let i=e[0],r=e[1],n=e[2],s=e[3],a=e[4],o=e[5],l=e[6],y=e[7],f=e[8],b=e[9],h=e[10],d=e[11],v=e[12],M=e[13],m=e[14],u=e[15],g=i*o-r*a,p=i*l-n*a,x=i*y-s*a,w=r*l-n*o,_=r*y-s*o,N=n*y-s*l,P=f*M-b*v,E=f*m-h*v,T=f*u-d*v,S=b*m-h*M,A=b*u-d*M,D=h*u-d*m,R=g*D-p*A+x*S+w*T-_*E+N*P;return R?(R=1/R,t[0]=(o*D-l*A+y*S)*R,t[1]=(n*A-r*D-s*S)*R,t[2]=(M*N-m*_+u*w)*R,t[3]=(h*_-b*N-d*w)*R,t[4]=(l*T-a*D-y*E)*R,t[5]=(i*D-n*T+s*E)*R,t[6]=(m*x-v*N-u*p)*R,t[7]=(f*N-h*x+d*p)*R,t[8]=(a*A-o*T+y*P)*R,t[9]=(r*T-i*A-s*P)*R,t[10]=(v*_-M*x+u*g)*R,t[11]=(b*x-f*_-d*g)*R,t[12]=(o*E-a*S-l*P)*R,t[13]=(i*S-r*E+n*P)*R,t[14]=(M*p-v*w-m*g)*R,t[15]=(f*w-b*p+h*g)*R,t):null}function Vn(t,e,i,r,n){let s=n[0]*e+n[4]*i+n[8]*r+n[12],a=n[1]*e+n[5]*i+n[9]*r+n[13],o=n[2]*e+n[6]*i+n[10]*r+n[14],l=n[3]*e+n[7]*i+n[11]*r+n[15],y=l!==0?1/l:1;t[0]=s*y,t[1]=a*y,t[2]=o*y}function fr(t,e,i,r,n,s,a,o,l,y,f,b,h,d,v,M,m=0){let u=y-a,g=f-o,p=b-l,x=h-a,w=d-o,_=v-l,N=n*_-s*w,P=s*x-r*_,E=r*w-n*x,T=u*N+g*P+p*E;if(T>-1e-7&&T<1e-7)return!1;let S=1/T,A=t-a,D=e-o,R=i-l,F=S*(A*N+D*P+R*E);if(F<-m||F>1+m)return!1;let k=D*p-R*g,V=R*u-A*p,L=A*g-D*u,O=S*(r*k+n*V+s*L);if(O<-m||F+O>1+m)return!1;let c=S*(x*k+w*V+_*L);if(c>1e-4&&c<M.distance){M.distance=c,M.point=[t+r*c,e+n*c,i+s*c];let I=g*_-p*w,C=p*x-u*_,U=u*w-g*x,j=Math.hypot(I,C,U)||1;return M.normal=[I/j,C/j,U/j],!0}return!1}function zn(t,e){let i=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let f=0;f<i;f++)r.push(ve());if(i===0)return r;let n=new Set;for(let f of t.nodes)if(Array.isArray(f.children))for(let b of f.children)n.add(b);let s=new Set,a=128,o=(f,b,h=0)=>{if(h>a||f<0||f>=i||s.has(f))return;s.add(f);let d=t.nodes[f];if(!d)return;let v=ve();if(e&&e[f])v.set(e[f]);else if(d.matrix&&d.matrix.length===16)v.set(d.matrix);else{let m=d.translation||[0,0,0],u=d.rotation||[0,0,0,1],g=d.scale||[1,1,1];ot(v,u,m,g)}let M=r[f];if(b?Me(M,b,v):M.set(v),Array.isArray(d.children))for(let m of d.children)typeof m=="number"&&o(m,M,h+1)},l=[],y=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(y&&Array.isArray(y.nodes))l.push(...y.nodes);else for(let f=0;f<i;f++)n.has(f)||l.push(f);for(let f of l)o(f,null);for(let f=0;f<i;f++)!n.has(f)&&!l.includes(f)&&o(f,null);return r}function Gn(t){if(typeof t!="function")return null;let e=new Uint32Array(256);for(let h=0;h<256;h++){let d=h;for(let v=0;v<8;v++)d=d&1?3988292384^d>>>1:d>>>1;e[h]=d>>>0}let i=(h,d,v)=>{let M=4294967295;for(let m=d;m<v;m++)M=e[(M^h[m])&255]^M>>>8;return(M^4294967295)>>>0},r=(h,d)=>(h[d]<<24|h[d+1]<<16|h[d+2]<<8|h[d+3])>>>0,n=(h,d,v)=>{h[d]=v>>>24,h[d+1]=v>>>16&255,h[d+2]=v>>>8&255,h[d+3]=v&255},s=h=>{let d=new t("deflate"),v=d.writable.getWriter();v.write(h).catch(()=>{}),v.close().catch(()=>{});let M=d.readable.getReader(),m=[],u=0,g=()=>M.read().then(p=>{if(p.done){let x=new Uint8Array(u),w=0;for(let _=0;_<m.length;_++)x.set(m[_],w),w+=m[_].length;return x}return p.value&&(m.push(p.value),u+=p.value.length),g()});return g()},a=h=>{if(h.length<45||r(h,0)!==2303741511||r(h,12)!==1229472850)return null;let d=r(h,16),v=r(h,20);if(h[24]!==8||h[25]!==6||h[28]!==0||!d||!v||d>4096||v>4096)return null;let M=1+d*4,m=new Uint8Array(M*v),u=0,g=33,p=-2,x=0,w=[],_=!1;for(;g+8<=h.length&&!_;){let N=r(h,g),P=r(h,g+4),E=g+8,T=E+N;if(T+4>h.length)return null;if(P===1229209940)for(let S=E;S<T&&!_;){if(p<0)p++,S++;else if(x>0){let A=Math.min(x,T-S);if(u+A>m.length)return null;m.set(h.subarray(S,S+A),u),u+=A,S+=A,x-=A,x===0&&w[0]&1&&(_=!0)}else{if(w.push(h[S++]),w.length===1&&w[0]>>1&3)return null;if(w.length===5){let A=w[1]|w[2]<<8;if((A^(w[3]|w[4]<<8))!==65535)return null;x=A,A===0&&(w[0]&1&&(_=!0),w=[])}}x===0&&w.length===5&&(w=[])}else if(P===1229278788)break;g=T+4}if(u!==m.length)return null;for(let N=0;N<v;N++)if(m[N*M]!==0)return null;return{w:d,h:v,raw:m}},o=(h,d,v)=>{let M=d*4,m=M+1,u=new Uint8Array(h.length),g=new Uint8Array(M),p=new Uint8Array(M);for(let x=0;x<v;x++){let w=x*m+1,_=w-m,N=0,P=1/0;for(let E=0;E<5;E++){if(E===3||(E===2||E===4)&&x===0)continue;let T=0;for(let S=0;S<M;S++){let A=S>=4?h[w+S-4]:0,D=x>0?h[_+S]:0,R=0;if(E===1)R=A;else if(E===2)R=D;else if(E===4){let k=S>=4&&x>0?h[_+S-4]:0,V=A+D-k,L=Math.abs(V-A),O=Math.abs(V-D),c=Math.abs(V-k);R=L<=O&&L<=c?A:O<=c?D:k}let F=h[w+S]-R&255;g[S]=F,T+=F<128?F:256-F}T<P&&(P=T,N=E,p.set(g))}u[x*m]=N,u.set(p,w)}return u},l=h=>{let d=null;try{d=a(h)}catch{d=null}if(!d)return Promise.resolve(h);let{w:v,h:M,raw:m}=d;return s(o(m,v,M)).then(u=>{let g=45+u.length+12;if(g>=h.length)return h;let p=new Uint8Array(g);p.set(h.subarray(0,33),0),n(p,33,u.length),n(p,37,1229209940),p.set(u,41),n(p,41+u.length,i(p,37,41+u.length));let x=45+u.length;return n(p,x,0),n(p,x+4,1229278788),n(p,x+8,2923585666),p},()=>h)},y=new Int16Array(128).fill(-1),f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let h=0;h<64;h++)y[f.charCodeAt(h)]=h;let b=h=>{let d=h.length;for(;d>0&&h.charCodeAt(d-1)===61;)d--;let v=new Uint8Array(Math.floor(d*3/4)),M=0,m=0,u=0;for(let g=0;g<d;g++){let p=h.charCodeAt(g),x=p<128?y[p]:-1;if(x<0)return null;M=(M<<6|x)&16777215,m+=6,m>=8&&(m-=8,v[u++]=M>>m&255)}return u===v.length?v:null};return{png:l,glb:h=>{let d=(S,A)=>(S[A]|S[A+1]<<8|S[A+2]<<16|S[A+3]<<24)>>>0,v=(S,A,D)=>{S[A]=D&255,S[A+1]=D>>>8&255,S[A+2]=D>>>16&255,S[A+3]=D>>>24},M,m=new Uint8Array(0);try{if(h.length<20||d(h,0)!==1179937895)return Promise.resolve(h);let S=Math.min(h.length,d(h,8)),A=d(h,12);if(d(h,16)!==1313821514||20+A>S)return Promise.resolve(h);M=JSON.parse(new TextDecoder().decode(h.subarray(20,20+A)));let D=20+A;if(D+8<=S){let R=d(h,D);if(d(h,D+4)!==5130562||D+8+R>S)return Promise.resolve(h);m=h.subarray(D+8,D+8+R)}}catch{return Promise.resolve(h)}if(!M||typeof M!="object")return Promise.resolve(h);let u=Array.isArray(M.bufferViews)?M.bufferViews:[],g=Array.isArray(M.images)?M.images:[],p=[],x=[],w=[],_="data:image/png;base64,";for(let S=0;S<g.length;S++){let A=g[S];if(!A||typeof A!="object")continue;let D=u[A.bufferView];if(typeof A.uri=="string"&&A.uri.indexOf(_)===0){let R=b(A.uri.slice(_.length));R&&(x.push(S),w.push(R))}else A.mimeType==="image/png"&&D&&(D.buffer||0)===0&&p.indexOf(A.bufferView)<0&&p.push(A.bufferView)}if(!p.length&&!x.length)return Promise.resolve(h);let N=[];for(let S=0;S<u.length;S++)N.push(S);N.sort((S,A)=>(u[S].byteOffset||0)-(u[A].byteOffset||0));let P=0;for(let S=0;S<N.length;S++){let A=u[N[S]],D=A.byteOffset||0;if(typeof A.byteLength!="number"||(A.buffer||0)!==0||D<P||D+A.byteLength>m.length)return Promise.resolve(h);P=D+A.byteLength}let E=S=>{let A=u[S].byteOffset||0;return m.subarray(A,A+u[S].byteLength)},T=[];for(let S=0;S<p.length;S++)T.push(l(E(p[S])));for(let S=0;S<w.length;S++)T.push(l(w[S]));return Promise.all(T).then(S=>{let A=[];for(let c=0;c<u.length;c++){let I=p.indexOf(c);A.push(I>=0?S[I]:E(c))}let D=0;for(let c=0;c<N.length;c++)D=(D+3&-4)+A[N[c]].length;for(let c=0;c<x.length;c++)D=(D+3&-4)+S[p.length+c].length;let R=D+3&-4,F=new Uint8Array(R),k=0;for(let c=0;c<N.length;c++){let I=N[c];k=k+3&-4,F.set(A[I],k),u[I].byteOffset=k,u[I].byteLength=A[I].length,k+=A[I].length}for(let c=0;c<x.length;c++){let I=S[p.length+c];k=k+3&-4,F.set(I,k);let C=g[x[c]];delete C.uri,C.mimeType="image/png",C.bufferView=u.length,u.push({buffer:0,byteOffset:k,byteLength:I.length}),k+=I.length}M.bufferViews=u,!Array.isArray(M.buffers)||!M.buffers.length?M.buffers=[{byteLength:R}]:M.buffers[0].byteLength=R;let V=new TextEncoder().encode(JSON.stringify(M)),L=V.length+3&-4;if(L!==V.length){let c=new Uint8Array(L).fill(32);c.set(V),V=c}let O=new Uint8Array(20+L+8+R);return v(O,0,1179937895),v(O,4,2),v(O,8,O.length),v(O,12,L),v(O,16,1313821514),O.set(V,20),v(O,20+L,R),v(O,24+L,5130562),O.set(F,28+L),O.length<h.length?O:h})}}}var ci={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Hn(t,e,i,r){if(!i||i.bufferView===void 0)return null;let n=t.bufferViews?.[i.bufferView];if(!n)return null;let s=Number(i.count??0);if(!Number.isInteger(s)||s<=0)return null;let a=i.componentType??5126,o=ci[a];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let l=o*r,y=n.byteStride&&n.byteStride>0?n.byteStride:l,f=(n.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(f)||f<0||y<l||f+(s-1)*y+l>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(a===5126&&y===l&&f%4===0)return new Float32Array(e,f,s*r);let b=new DataView(e),h=i.normalized===!0,d=new Float32Array(s*r);for(let v=0;v<s;v++){let M=f+v*y;for(let m=0;m<r;m++){let u=M+m*o,g;switch(a){case 5126:g=b.getFloat32(u,!0);break;case 5120:g=b.getInt8(u),h&&(g=Math.max(g/127,-1));break;case 5121:g=b.getUint8(u),h&&(g/=255);break;case 5122:g=b.getInt16(u,!0),h&&(g=Math.max(g/32767,-1));break;case 5123:g=b.getUint16(u,!0),h&&(g/=65535);break;default:g=b.getUint32(u,!0),h&&(g/=4294967295)}d[v*r+m]=g}}return d}function pr(t,e){let i=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,n=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),a=Number(e.rotation??0)||0,o=Math.cos(a),l=Math.sin(a),y=(Number.isFinite(n)?n:1)*o,f=(Number.isFinite(n)?n:1)*l,b=-(Number.isFinite(s)?s:1)*l,h=(Number.isFinite(s)?s:1)*o;for(let d=0;d+1<t.length;d+=2){let v=t[d],M=t[d+1];t[d]=y*v+f*M+i,t[d+1]=b*v+h*M+r}}function st(t,e,i,r=!0){let n=[],s=null;try{for(let[a,o]of[[35633,e],[35632,i]]){let l=t.createShader(a);if(!l){if(r)throw new Error("Shader allocation failed");return null}if(n.push(l),t.shaderSource(l,o),t.compileShader(l),t.getShaderParameter&&!t.getShaderParameter(l,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(l)}`);return null}}if(s=t.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let a of n)t.attachShader(s,a);if(t.linkProgram(s),t.getProgramParameter&&!t.getProgramParameter(s,35714)){let a=r?t.getProgramInfoLog(s):null;if(t.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${a}`);return null}return s}finally{for(let a of n)s&&t.detachShader?.(s,a),t.deleteShader?.(a)}}var gr=["neutral","reinhard","none","aces","agx"];function Wn(t){let e=String(t??"").trim().toLowerCase();return gr.includes(e)?e:"neutral"}function ui(t){return gr.indexOf(Wn(t))}function li(t){return new TextDecoder().decode(t)}var yr=de().decoders;function mi(t,e){yr.set(t.toLowerCase(),e)}function Ft(t){return yr.get(t.toLowerCase())}function xr(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,i=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let h=i.getUint8(0);throw h===123||h===32||h===10||h===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let n=i.getUint32(4,!0);if(n!==2)throw new Error(`Unsupported GLB version: ${n}`);let s=i.getUint32(8,!0),a=12,o=null,l=null;for(;a+8<=s&&a+8<=e.byteLength;){let h=i.getUint32(a,!0),d=i.getUint32(a+4,!0),v=a+8;if(v+h>e.byteLength)throw new Error(`Truncated GLB chunk: required ${v+h} bytes, buffer has ${e.byteLength}`);if(d===1313821514){let M=new Uint8Array(e,v,h),m=li(M);o=JSON.parse(m,(u,g)=>u==="__proto__"||u==="constructor"||u==="prototype"?void 0:g)}else d===5130562&&(l=e.slice(v,v+h));a=v+h}if(!o)throw new Error("Missing JSON chunk in GLB");let y=o.extensionsRequired||[];for(let[h,d]of[["KHR_draco_mesh_compression","draco"],["EXT_meshopt_compression","meshopt"],["KHR_meshopt_compression","meshopt"],["KHR_texture_basisu","ktx2"]])if(y.includes(h)&&!Ft(d))throw new Error(`Model requires ${h}. Register a decoder via ThreeLiveElement.registerDecoder('${d}', decoder).`);let f=l||new ArrayBuffer(0),b={gltf:o,bin:f,animations:[],animationsParsed:!1};for(let h of ge)h.onParseGLB?.(b);return b}function Yn(t,e=zn(t)){let i=t?.extensions?.KHR_lights_punctual?.lights;if(!Array.isArray(i))return[];let r=[],n=new Set,s=(a,o,l,y)=>{let f=a.type,b=f==="directional"||f==="point"||f==="spot"?f:"ambient",h=o?o[8]:-.5,d=o?o[9]:-1,v=o?o[10]:-.8,M=Math.hypot(h,d,v)||1,m=a.extras?.shadow??l,u=a.name||y,g={type:b,color:a.color||[1,1,1],intensity:a.intensity??1};u&&(g.name=u),o&&(g.position=[o[12],o[13],o[14]]),b==="directional"&&o?g.direction=[h/M,d/M,v/M]:(b==="spot"&&(g.direction=o?[-h/M,-d/M,-v/M]:[0,-1,0],g.innerConeAngle=a.spot?.innerConeAngle??0,g.outerConeAngle=a.spot?.outerConeAngle??Math.PI/4),g.range=a.range),m&&(g.shadow=m),r.push(g)};return(t.nodes||[]).forEach((a,o)=>{let l=a?.extensions?.KHR_lights_punctual?.light;typeof l=="number"&&i[l]&&(n.add(l),s(i[l],e[o],a.extras?.shadow,a.name))}),i.forEach((a,o)=>{n.has(o)||s(a)}),r}function hi(t){return typeof t=="object"&&t!==null&&"gltf"in t&&typeof t.gltf=="object"&&t.gltf!==null&&"bin"in t&&(t.bin instanceof ArrayBuffer||ArrayBuffer.isView(t.bin))}function Ut(t){if(hi(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return xr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Xn=`#version 300 es
|
|
17
17
|
layout(location=0) in vec3 aPos;
|
|
18
18
|
layout(location=3) in vec3 aOff;
|
|
19
19
|
layout(location=1) in vec3 aNormal;
|
|
@@ -48,7 +48,7 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
48
48
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
49
49
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
50
50
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
51
|
-
}`,
|
|
51
|
+
}`,di=`#version 300 es
|
|
52
52
|
precision highp float;
|
|
53
53
|
in vec3 vNormal,vWorldPos;
|
|
54
54
|
in vec2 vUV;
|
|
@@ -57,117 +57,81 @@ in vec4 vInstTint;
|
|
|
57
57
|
#define uBaseColor (uBaseColor*vInstTint)
|
|
58
58
|
uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity,uExposure;
|
|
59
59
|
uniform vec2 uClearcoat;
|
|
60
|
-
uniform vec3 uCameraPos,uAmbientColor;
|
|
61
|
-
uniform
|
|
62
|
-
uniform
|
|
60
|
+
uniform vec3 uCameraPos,uAmbientColor,uEmissiveFactor;
|
|
61
|
+
uniform mat3 uHemi;
|
|
62
|
+
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uEmissiveTexture;
|
|
63
|
+
uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uHasEmissiveTexture;
|
|
63
64
|
uniform float uNormalScale,uOcclusionStrength;
|
|
64
|
-
/*XRD_U*/
|
|
65
|
+
/*XRD_U*//*SHD_U*/
|
|
65
66
|
uniform vec2 uViewportSize;
|
|
66
67
|
uniform vec4 uSectionPlane;
|
|
67
68
|
uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
|
|
68
69
|
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2],uPointLightSpotDir[2];
|
|
69
70
|
uniform vec2 uPointLightSpotCone[2];
|
|
70
71
|
out vec4 fragColor;
|
|
71
|
-
|
|
72
72
|
vec2 envBRDF(float r,float n){
|
|
73
|
-
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04);
|
|
74
|
-
vec4 rv=r*c0+c1;
|
|
73
|
+
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04),rv=r*c0+c1;
|
|
75
74
|
float a=min(rv.x*rv.x,exp2(-9.28*n))*rv.x+rv.y;
|
|
76
75
|
return vec2(-1.04,1.04)*a+rv.zw;
|
|
77
76
|
}
|
|
78
|
-
|
|
79
77
|
vec3 F_SchlickRoughness(vec3 F0,float r,float n){
|
|
80
78
|
return F0+(max(vec3(1.0-r),F0)-F0)*pow(clamp(1.0-n,0.0,1.0),5.0);
|
|
81
79
|
}
|
|
82
|
-
|
|
83
80
|
vec3 getStudioRadiance(vec3 R,float r){
|
|
84
|
-
vec3 kd=normalize(vec3(0.0,1.0,0.35));
|
|
81
|
+
vec3 kd=normalize(vec3(0.0,1.0,0.35)),fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
85
82
|
float ki=pow(max(dot(R,kd),0.0),mix(96.0,1.5,r))*mix(2.4,0.5,r);
|
|
86
|
-
vec3 fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
87
83
|
float fi=pow(max(dot(R,fd),0.0),mix(36.0,1.2,r))*mix(1.3,0.35,r);
|
|
88
84
|
float ri=pow(clamp(1.0-abs(R.y),0.0,1.0),3.5)*mix(0.55,0.22,r);
|
|
89
|
-
|
|
90
|
-
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;
|
|
85
|
+
return mix(vec3(0.06,0.06,0.08),vec3(0.48,0.50,0.55),R.y*0.5+0.5)+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
|
|
91
86
|
}
|
|
92
|
-
|
|
93
|
-
vec3
|
|
94
|
-
vec3
|
|
95
|
-
|
|
96
|
-
vec3
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
vec2 duv2=dFdy(uv);
|
|
100
|
-
vec3 dp2perp=cross(dp2,N);
|
|
101
|
-
vec3 dp1perp=cross(N,dp1);
|
|
102
|
-
vec3 T=dp2perp*duv1.x+dp1perp*duv2.x;
|
|
103
|
-
vec3 B=dp2perp*duv1.y+dp1perp*duv2.y;
|
|
104
|
-
float invmax=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
105
|
-
return normalize(mat3(T*invmax,B*invmax,N)*normalize(mapNormal));
|
|
87
|
+
vec3 perturbNormal(vec3 N,vec3 V,vec2 uv,sampler2D m,float s){
|
|
88
|
+
vec3 q=texture(m,uv).xyz*2.0-1.0;q.xy*=s;
|
|
89
|
+
vec3 p1=dFdx(vWorldPos),p2=dFdy(vWorldPos),c2=cross(p2,N),c1=cross(N,p1);
|
|
90
|
+
vec2 u1=dFdx(uv),u2=dFdy(uv);
|
|
91
|
+
vec3 T=c2*u1.x+c1*u2.x,B=c2*u1.y+c1*u2.y;
|
|
92
|
+
float k=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
93
|
+
return normalize(mat3(T*k,B*k,N)*normalize(q));
|
|
106
94
|
}
|
|
107
|
-
|
|
108
95
|
vec2 equirectangularUV(vec3 dir){
|
|
109
96
|
vec3 d=normalize(dir);
|
|
110
|
-
|
|
111
|
-
float v=asin(clamp(d.y,-1.0,1.0))*0.31830988618+0.5;
|
|
112
|
-
return vec2(u,1.0-v);
|
|
97
|
+
return vec2(atan(d.z,d.x)*0.15915494309+0.5,0.5-asin(clamp(d.y,-1.0,1.0))*0.31830988618);
|
|
113
98
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
float
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if(peak<startCompression)return color;
|
|
123
|
-
const float d=1.0-startCompression;
|
|
124
|
-
float newPeak=1.0-d*d/(peak+d-startCompression);
|
|
125
|
-
color*=newPeak/peak;
|
|
126
|
-
float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
|
|
127
|
-
return mix(color,newPeak*vec3(1.0),g);
|
|
99
|
+
vec3 neutralToneMapping(vec3 c){
|
|
100
|
+
float x=min(c.r,min(c.g,c.b));
|
|
101
|
+
c-=x<0.08?x-6.25*x*x:0.04;
|
|
102
|
+
float p=max(c.r,max(c.g,c.b));
|
|
103
|
+
if(p<0.76)return c;
|
|
104
|
+
float n=1.0-0.0576/(p-0.52);
|
|
105
|
+
c*=n/p;
|
|
106
|
+
return mix(c,vec3(n),1.0-1.0/(0.15*(p-n)+1.0));
|
|
128
107
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
color*=0.6;
|
|
132
|
-
return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
|
|
108
|
+
vec3 acesToneMapping(vec3 c){
|
|
109
|
+
c*=0.6;return clamp((c*(2.51*c+0.03))/(c*(2.43*c+0.59)+0.14),0.0,1.0);
|
|
133
110
|
}
|
|
134
|
-
|
|
135
|
-
vec3
|
|
136
|
-
|
|
137
|
-
vec3
|
|
138
|
-
|
|
139
|
-
0.
|
|
140
|
-
0.
|
|
141
|
-
vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
|
|
142
|
-
vec3 x2=ev*ev;
|
|
143
|
-
vec3 x4=x2*x2;
|
|
144
|
-
vec3 s=15.5*x4*x2-40.14*x4*ev+31.96*x4-6.868*x2*ev+0.4298*x2+0.1191*ev-0.00232;
|
|
145
|
-
vec3 outset=vec3(
|
|
146
|
-
1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
|
|
147
|
-
-0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
|
|
148
|
-
-0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
|
|
149
|
-
return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
111
|
+
vec3 agxToneMapping(vec3 c){
|
|
112
|
+
c=max(c,vec3(0.0));
|
|
113
|
+
vec3 i=mat3(0.84247906,0.04232824,0.04237565,0.0784336,0.87846864,0.0784336,0.07922375,0.07916613,0.87914297)*c;
|
|
114
|
+
vec3 e=clamp((log2(max(i,vec3(1e-6)))+12.47393)/16.5,0.0,1.0),x2=e*e,x4=x2*x2;
|
|
115
|
+
vec3 s=15.5*x4*x2-40.14*x4*e+31.96*x4-6.868*x2*e+0.4298*x2+0.1191*e-0.00232;
|
|
116
|
+
vec3 o=mat3(1.196879,-0.05289685,-0.05297164,-0.09802088,1.15190313,-0.09804345,-0.09902974,-0.09896118,1.15107367)*s;
|
|
117
|
+
return clamp(pow(max(o,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
150
118
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if(mode==0)return neutralToneMapping(color);
|
|
154
|
-
if(mode==1)return color/(color+vec3(1.0));
|
|
155
|
-
if(mode==3)return acesToneMapping(color);
|
|
156
|
-
if(mode==4)return agxToneMapping(color);
|
|
157
|
-
return color;
|
|
119
|
+
vec3 applyToneMapping(vec3 c,int m){
|
|
120
|
+
return m==0?neutralToneMapping(c):m==1?c/(c+vec3(1.0)):m==3?acesToneMapping(c):m==4?agxToneMapping(c):c;
|
|
158
121
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return base*max(dot(N,L),0.0)*0.75+vec3(pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
|
|
122
|
+
vec3 evalLight(vec3 L,vec3 V,vec3 N,vec3 b,float e,float w){
|
|
123
|
+
float h=max(dot(N,normalize(L+V)),0.0);
|
|
124
|
+
return b*max(dot(N,L),0.0)*0.75+vec3(pow(h,e)*w+uClearcoat.x*pow(h,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
|
|
163
125
|
}
|
|
164
126
|
|
|
165
127
|
void main(){
|
|
166
128
|
if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
|
|
167
129
|
vec4 base=uBaseColor;
|
|
168
130
|
if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
|
|
131
|
+
if(base.a<0.004)discard;
|
|
132
|
+
vec3 em=uHasEmissiveTexture==1?uEmissiveFactor*texture(uEmissiveTexture,vUV).rgb:uEmissiveFactor;
|
|
169
133
|
if(length(vNormal)<1e-4&&uHasTexture==1){
|
|
170
|
-
vec3 unlit=base.rgb+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
134
|
+
vec3 unlit=base.rgb+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
171
135
|
fragColor=vec4(unlit,base.a);
|
|
172
136
|
return;
|
|
173
137
|
}
|
|
@@ -199,7 +163,7 @@ float specWeight=mix(0.22*gloss,1.0,metallic);
|
|
|
199
163
|
vec3 directLight=vec3(0.0);
|
|
200
164
|
for(int i=0;i<2;i++){
|
|
201
165
|
if(i>=uNumDirLights)break;
|
|
202
|
-
directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i]
|
|
166
|
+
directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i]/*SHD_D*/;
|
|
203
167
|
}
|
|
204
168
|
for(int i=0;i<2;i++){
|
|
205
169
|
if(i>=uNumPointLights)break;
|
|
@@ -208,7 +172,7 @@ float dist=length(toLight);
|
|
|
208
172
|
vec3 L=toLight/max(dist,0.0001);
|
|
209
173
|
float spotAtt=clamp((dot(-L,uPointLightSpotDir[i])-uPointLightSpotCone[i].y)/max(uPointLightSpotCone[i].x-uPointLightSpotCone[i].y,0.0001),0.0,1.0);
|
|
210
174
|
spotAtt*=spotAtt;
|
|
211
|
-
directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist)
|
|
175
|
+
directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist)/*SHD_P*/;
|
|
212
176
|
}
|
|
213
177
|
|
|
214
178
|
vec3 R=reflect(-V,N);
|
|
@@ -228,8 +192,9 @@ envDiffuse=mix(vec3(0.10,0.10,0.12),vec3(0.52,0.54,0.58),N.y*0.5+0.5);
|
|
|
228
192
|
}
|
|
229
193
|
|
|
230
194
|
vec3 kD=(vec3(1.0)-F)*(1.0-metallic);
|
|
195
|
+
directLight+=kD*base.rgb*mix(uHemi[1],uHemi[0],dot(N,uHemi[2])*0.5+0.5)*occ;
|
|
231
196
|
vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
232
|
-
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
197
|
+
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
233
198
|
if(uClearcoat.x>0.0){
|
|
234
199
|
vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
|
|
235
200
|
color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
@@ -239,140 +204,157 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
239
204
|
float outAlpha=base.a;
|
|
240
205
|
/*XRD_O*/
|
|
241
206
|
fragColor=vec4(color,outAlpha);
|
|
242
|
-
}`,
|
|
207
|
+
}`,fi=`#version 300 es
|
|
243
208
|
layout(location=0) in vec3 aPosition;
|
|
244
209
|
uniform mat4 uMVP;
|
|
245
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
210
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,pi=`#version 300 es
|
|
246
211
|
precision highp float;
|
|
247
212
|
uniform vec4 uColorId;
|
|
248
213
|
out vec4 fragColor;
|
|
249
|
-
void main(){fragColor=uColorId;}`;function In(e,t,i){let r={};for(let s of i)r[s]=e.getUniformLocation(t,s);return r}var qn=["uMVP","uModel","uInstanced","uViewProj","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","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function nr(){let e=le().xrDepthShader;return{fs:Zr.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...qn,...e.uniformNames]:qn}}function ei(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let i=t.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:i.startsWith("https://")||i.startsWith("blob:")?t:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Rn(e,t,i,r,s,n,a,o){if(r===void 0||!t.accessors?.[r])return null;let l=En(t,i,t.accessors[r],n);if(!l)return null;o&&(l=l.slice(),Yn(l,o));let h=e.createBuffer();return a.push(h),e.bindBuffer(34962,h),e.bufferData(34962,l,35044),e.enableVertexAttribArray(s),e.vertexAttribPointer(s,n,5126,!1,0,0),l}function Cn(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function rr(e,t,i){let r=nr(),s=tr,n=r.fs,a=!1;for(let l of pe)if(l.onResolveShader){let h=l.onResolveShader(t,i,s,n);h&&(s=h.vs,n=h.fs,a=!0)}let o=a?Tt(e,s,n):null;return{program:o,uniforms:o?In(e,o,r.uniforms):null}}function ti(e,t,i){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let s=r.length>>4,n=t.instanceColors,a=new Float32Array(s*20);for(let l=0;l<s;l++)a.set(r.subarray(l*16,l*16+16),l*20),a[l*20+16]=n?n[l*3]:1,a[l*20+17]=n?n[l*3+1]:1,a[l*20+18]=n?n[l*3+2]:1,a[l*20+19]=1;let o=e.createBuffer();i.push(o),e.bindBuffer(34962,o),e.bufferData(34962,a,35044);for(let l=0;l<5;l++)e.enableVertexAttribArray(8+l),e.vertexAttribPointer(8+l,4,5126,!1,80,l*16),e.vertexAttribDivisor(8+l,1);return!0}function ni(e,t){let i=e.materials?.[t?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let s of r){let n=s?.extensions?.KHR_texture_transform;if(n&&typeof n=="object")return n}return null}var Gi=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),ir=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function _t(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function sr(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,s=e?.extensions?.KHR_materials_clearcoat,n=a=>a!==void 0&&t[a.index]?t[a.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:n(i?.baseColorTexture),metallicRoughnessTexture:n(i?.metallicRoughnessTexture),normalTexture:n(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:n(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function or(e,t,i){let r=new Set,s=n=>{n&&!r.has(n)&&(r.add(n),e.deleteTexture(n))};for(let n of t)for(let a of n.primitives){if(a.vao&&e.deleteVertexArray(a.vao),a.buffers)for(let l of a.buffers)e.deleteBuffer(l);s(a.texture),s(a.metallicRoughnessTexture),s(a.normalTexture),s(a.occlusionTexture);let o=new Set;a.customProgram&&o.add(a.customProgram);for(let l of a.programCache?.values()??[])l.program&&o.add(l.program);for(let l of o)e.deleteProgram(l)}if(i)for(let n of i)s(n)}function Zn(e,t,i=ir,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ri(e,t,i,r,s)}catch(n){let a=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;or(e,a,s.gpuTextures),s.vao&&e.deleteVertexArray(s.vao);for(let o of s.buffers)e.deleteBuffer(o);throw n}}function ri(e,t,i,r,s){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n}=t,a=je("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(n,t);let o=t.bin,l=[];s.meshes=l;let h=[],u=n.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((E,y)=>{h.push(typeof E?.name=="string"&&E.name?E.name:`Variant_${y}`)});let f=Kn(n),g=[];if(Array.isArray(n.nodes))for(let E=0;E<n.nodes.length;E++){let y=n.nodes[E];y.mesh!==void 0&&n.meshes&&n.meshes[y.mesh]&&g.push({node:y,nodeIdx:E,meshIdx:y.mesh})}let w=g.length>0?g:(n.meshes||[]).map((E,y)=>({node:E,nodeIdx:-1,meshIdx:y})),p=[],b=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(n.asset?.extras?.lights)&&n.asset.extras.lights.length>0?n.asset.extras.lights:null;if(b)for(let E of b)p.push({...E,type:E.type||E.light_type||"point",innerConeAngle:E.innerConeAngle??E.inner_cone_angle,outerConeAngle:E.outerConeAngle??E.outer_cone_angle});else if(n.extensions?.KHR_lights_punctual?.lights){let E=n.extensions.KHR_lights_punctual.lights;for(let y of E){let F=y.type==="directional"?"directional":y.type==="point"?"point":y.type==="spot"?"spot":"ambient";p.push({type:F,color:y.color||[1,1,1],intensity:y.intensity!==void 0?y.intensity:1})}}if(p.length===0&&(p.push({type:"ambient",color:[1,1,1],intensity:.35}),p.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),w.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${w.length}`);let T=[];if(s.gpuTextures=T,n.textures&&n.images){if(n.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${n.textures.length}`);for(let E=0;E<n.textures.length;E++){let y=n.textures[E],F=n.images[y.source];if(F){let z=e.createTexture();e.bindTexture(3553,z),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let A=_=>{e.bindTexture(3553,z),e.texImage2D(3553,0,6408,6408,5121,_),e.generateMipmap(3553),r?.()};if(F.bufferView!==void 0){let _=n.bufferViews[F.bufferView],d=_.byteOffset||0,R=new Blob([o.slice(d,d+_.byteLength)],{type:F.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(R).then(A).catch(()=>{})}else if(F.uri){let _=ei(F.uri);if(_){let d=new Image;d.crossOrigin="anonymous",d.referrerPolicy="no-referrer",d.onload=()=>A(d),d.src=_}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",F.uri)}T.push(z)}else T.push(null)}}let x=[1/0,1/0,1/0],M=[-1/0,-1/0,-1/0],c=0,m=0;for(let E=0;E<w.length;E++){let y=w[E],F=n.meshes[y.meshIdx],z=y.nodeIdx>=0?f[y.nodeIdx]:he(),A=new Float32Array(9);Ce(A,z);let _={name:y.node.name||F.name||`Mesh_${y.meshIdx}`,nodeIndex:y.nodeIdx,transform:z,normalMatrix:A,primitives:[],extras:y.node.extras||F.extras,...y.node?.visible===!1||y.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};s.mesh=_;let d=y.node?.extensions?.EXT_mesh_gpu_instancing;if(d&&d.attributes&&typeof d.attributes=="object"){let R=d.attributes,G=R.TRANSLATION!==void 0?n.accessors?.[R.TRANSLATION]:null,H=R.ROTATION!==void 0?n.accessors?.[R.ROTATION]:null,B=R.SCALE!==void 0?n.accessors?.[R.SCALE]:null,Z=R._COLOR_0!==void 0?n.accessors?.[R._COLOR_0]:null,k=Number(G?.count??H?.count??B?.count??0);if(!Number.isFinite(k)||k<0||k>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${k}`);if(k>0){let Y=(U,$)=>{if(!U||U.bufferView===void 0||!n.bufferViews?.[U.bufferView])return null;let j=U.componentType??5126,q=Q=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Q})`),null);if(j!==5120&&j!==5121&&j!==5122&&j!==5123&&j!==5126)return q(`componentType ${j}`);if(!(Number(U.count)>=k))return q(`count ${U.count} < ${k}`);let K=null;try{K=En(n,o,{...U,count:k},$)}catch{return q("out of bounds")}return!K||!K.every(Number.isFinite)?q("non-finite value"):K},ie=Y(G,3),re=Y(H,4),O=Y(B,3),J=Z?.type==="VEC4"?4:3,V=Y(Z,J),W=new Float32Array(k*16),X=he();for(let U=0;U<k;U++){let $=ie?[ie[U*3],ie[U*3+1],ie[U*3+2]]:[0,0,0],j=re?[re[U*4],re[U*4+1],re[U*4+2],re[U*4+3]]:[0,0,0,1],q=O?[O[U*3],O[U*3+1],O[U*3+2]]:[1,1,1];Qe(X,j,$,q),W.set(X,U*16)}if(_.instanceMatrices=W,V){let U=new Float32Array(k*3);for(let $=0;$<k;$++)U[$*3]=V[$*J],U[$*3+1]=V[$*J+1],U[$*3+2]=V[$*J+2];_.instanceColors=U}}}for(let R of F.primitives||[]){if(R.extensions?.KHR_draco_mesh_compression){let K=je("draco");K&&K.decodePrimitive(n,R,o)}let G=[],H=e.createVertexArray();s.vao=H,s.buffers=G,e.bindVertexArray(H);let B=ti(e,_,G),Z=n.accessors[R.attributes.POSITION],k=Number(Z?.count??0);if(!Number.isFinite(k)||k<0||c+k>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(c+=k,Z?.min&&Z?.max){let K=Q=>{for(let te=0;te<3;te++){let fe=Q[12+te],se=Q[12+te];for(let ae=0;ae<3;ae++){let oe=Q[ae*4+te]*Z.min[ae],ce=Q[ae*4+te]*Z.max[ae];fe+=oe<ce?oe:ce,se+=oe>ce?oe:ce}fe<x[te]&&(x[te]=fe),se>M[te]&&(M[te]=se)}};if(_.instanceMatrices&&_.instanceMatrices.length>=16){let Q=_.instanceMatrices.length>>4,te=he();for(let fe=0;fe<Q;fe++){let se=_.instanceMatrices.subarray(fe*16,fe*16+16);be(te,z,se),K(te)}}else K(z)}let Y=Rn(e,n,o,R.attributes.POSITION,0,3,G);Rn(e,n,o,R.attributes.NORMAL,1,3,G),Rn(e,n,o,R.attributes.TEXCOORD_0,2,2,G,ni(n,R));let ie=0,re=5123,O=null;if(R.indices!==void 0){let K=n.accessors[R.indices],Q=(n.bufferViews[K.bufferView].byteOffset||0)+(K.byteOffset||0);if(ie=Number(K.count??0),!Number.isFinite(ie)||ie<0||m+ie>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);m+=ie,re=K.componentType===5125?5125:5123;let te=e.createBuffer();G.push(te),e.bindBuffer(34963,te),K.componentType===5125?O=new Uint32Array(o,Q,K.count):K.componentType===5121?O=Uint16Array.from(new Uint8Array(o,Q,K.count)):O=Q%2===0?new Uint16Array(o,Q,K.count):new Uint16Array(o.slice(Q,Q+K.count*2)),e.bufferData(34963,O,35044)}else ie=Z.count;let J={};for(let K of pe)if(K.onBuildPrimitiveVAO){let Q=K.onBuildPrimitiveVAO(e,H,R,n,o);Q&&(J[K.name]=Q)}e.bindVertexArray(null);let V=n.materials&&R.material!==void 0?n.materials[R.material]:null,{program:W,uniforms:X}=rr(e,R,V),U=sr(V,T),$=!!(V?.extensions?.KHR_materials_transmission||J.materials?.isTransmissive),j=R.extensions?.KHR_materials_variants?.mappings,q=Array.isArray(j)?j.filter(K=>K&&typeof K.material=="number"&&Array.isArray(K.variants)).map(K=>({material:K.material|0,variants:K.variants.map(Q=>Number(Q)|0)})):void 0;_.primitives.push({vao:H,instanced:B,indexCount:ie,indexType:re,...U,positions:Y,indices:O,buffers:G,materialIndex:R.material,defaultMaterialIndex:R.material,variantMappings:q,primitiveDef:R,programCache:new Map([[R.material??-1,{program:W,uniforms:X}]]),pluginData:J,customProgram:W,customUniforms:X,isTransmissive:$})}l.push(_)}isFinite(x[0])||(x=[-1,-1,-1]),isFinite(M[0])||(M=[1,1,1]);let v=[(x[0]+M[0])/2,(x[1]+M[1])/2,(x[2]+M[2])/2],S=M[0]-x[0],D=M[1]-x[1],I=M[2]-x[2],P=Math.max(Math.hypot(S,D,I)/2,.5),N=[x[0],x[1],x[2]],C=[M[0],M[1],M[2]],L=t.animations;if(!L){for(let E of pe)if(E.onParseGLB?.(t),t.animations){L=t.animations;break}}return L||(L=[]),{meshes:l,bounds:{center:v,radius:P,min:N,max:C},lights:p,animations:L,worldMatrices:f,gpuTextures:T,availableVariants:h}}function et(e){let t=e.customTarget||e.bounds.center,i=e.currDistance*Math.cos(e.currPhi);return[t[0]+i*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+i*Math.cos(e.currTheta)]}var St=class{constructor(e,t,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=he(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=he(),this.viewMatrix=he(),this.activeViewMatrix=null,this.modelMatrix=he(),this.mvpMatrix=he(),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.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:he(),rawValueToMeters:.001,format:0},this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),r=o}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let n=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!n:n&&(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.exposure=Cn(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=Dn(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let a=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!a)throw new Error("WebGL2 not supported");this.gl=a,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Yr(e,t)}static getDecoder(e){return je(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=nr();this.renderProg=Tt(e,tr,t.fs),this.pickProg=Tt(e,Jr,Qr),this.uRender=In(e,this.renderProg,t.uniforms),this.uPick=In(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of pe)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:n,worldMatrices:a,gpuTextures:o,availableVariants:l}=Zn(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=n||[],this.worldMatrices=a||[],this.gpuTextures=o||[],this.availableVariants=l||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of pe)f.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let h=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;h!==void 0&&(this.exposure=Cn(h));let u=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u)||0)),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(er(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of pe)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(wt(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=wt(e),{meshes:r}=Zn(this.gl,i,ir,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],Ce(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),Ce(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],n=[],a=[],o=[],l=[];for(let h of this.lights){let u=h.color||[1,1,1],f=h.intensity!==void 0?h.intensity:1;if(h.type==="ambient")i=[u[0]*f,u[1]*f,u[2]*f];else if(h.type==="directional"&&r.length<6){let g=h.direction||[.5,1,.8];r.push(g[0],g[1],g[2]),s.push(u[0]*f,u[1]*f,u[2]*f)}else if((h.type==="point"||h.type==="spot")&&n.length<6){let g=h.position||[0,0,0];if(n.push(g[0],g[1],g[2]),a.push(u[0]*f,u[1]*f,u[2]*f),h.type==="spot"){let w=h.direction||[0,-1,0],p=Math.max(.01,Math.min(Math.PI/2,h.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(p-1e-4,h.innerConeAngle??0));o.push(w[0],w[1],w[2]),l.push(Math.cos(b),Math.cos(p))}else o.push(0,-1,0),l.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,n.length/3),n.length>0&&(t.uniform3fv(e.uPointLightPos,n),t.uniform3fv(e.uPointLightColor,a),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,o),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,l)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Cn(e)}getExposure(){return this.exposure}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=Dn(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of pe)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of pe)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,i)=>{let r=this.meshes.flatMap(h=>h.primitives.filter(u=>u.materialIndex===i||e.length===1&&u.materialIndex===void 0)),s=r[0],n=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],a=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,l={baseColorFactor:n,metallicFactor:a,roughnessFactor:o,setBaseColorFactor:h=>{let u=[h[0],h[1],h[2],h[3]??1];l.baseColorFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=u);for(let f of r)f.baseColor=u;this.render()},setMetallicFactor:h=>{l.metallicFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=h);for(let u of r)u.metallic=h;this.render()},setRoughnessFactor:h=>{l.roughnessFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);for(let u of r)u.roughness=h;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:l}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",i=-1;if(t)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(e),i<0)return!1;this.activeVariantName=e}let r=this.gltf?.materials;if(!Array.isArray(r))return t;for(let s of this.meshes)for(let n of s.primitives){let a=n.defaultMaterialIndex;if(!t&&Array.isArray(n.variantMappings)){for(let l of n.variantMappings)if(Array.isArray(l.variants)&&l.variants.includes(i)){a=l.material;break}}let o=a!==void 0?r[a]:void 0;n.materialIndex=o?a:void 0,Object.assign(n,sr(o,this.gpuTextures)),this.applyPrimitiveProgram(n,n.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,s=e.programCache.get(r);s||(s=rr(this.gl,{...e.primitiveDef,material:t},i),e.programCache.set(r,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of pe)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let i=he();be(i,this.projMatrix,this.viewMatrix);let[r,s,n]=e,a=t?t[0]:0,o=t?t[1]:0,l=t?t[2]:0,h=this.modelRootMatrix;h&&(r=h[0]*e[0]+h[4]*e[1]+h[8]*e[2]+h[12],s=h[1]*e[0]+h[5]*e[1]+h[9]*e[2]+h[13],n=h[2]*e[0]+h[6]*e[1]+h[10]*e[2]+h[14],t&&(a=h[0]*t[0]+h[4]*t[1]+h[8]*t[2],o=h[1]*t[0]+h[5]*t[1]+h[9]*t[2],l=h[2]*t[0]+h[6]*t[1]+h[10]*t[2]));let u=i[0]*r+i[4]*s+i[8]*n+i[12],f=i[1]*r+i[5]*s+i[9]*n+i[13],g=i[2]*r+i[6]*s+i[10]*n+i[14],w=i[3]*r+i[7]*s+i[11]*n+i[15];if(w<=1e-4)return{x:0,y:0,z:1,visible:!1};let p=u/w,b=f/w,T=g/w,x=this.canvas.getBoundingClientRect(),M=x.width||this.canvas.clientWidth||this.canvas.width||300,c=x.height||this.canvas.clientHeight||this.canvas.height||150,m=(p*.5+.5)*M,v=(-b*.5+.5)*c,S=p>=-1.1&&p<=1.1&&b>=-1.1&&b<=1.1&&T>=-1&&T<=1;if(S&&t){let[D,I,P]=et(this),N=[r-D,s-I,n-P];a*N[0]+o*N[1]+l*N[2]>.05&&(S=!1)}return{x:m,y:v,z:T,visible:S}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=i=>{i.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,e.setPointerCapture(i.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},s=i.clientX-r.x,n=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(s,n),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],l=this.customTarget?[...this.customTarget]:[...this.bounds.center],h=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;l[0]+=(-s*a[0]+n*o[0])*h,l[1]+=(-s*a[1]+n*o[1])*h,l[2]+=(-s*a[2]+n*o[2])*h,this.customTarget=l}else this.targetTheta=this.clampTheta(this.targetTheta-s*.008),this.targetPhi=this.clampPhi(this.targetPhi+n*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=t(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=e.getBoundingClientRect(),s=Math.floor((i.clientX-r.left)*(e.width/Math.max(r.width,1))),n=Math.floor((i.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(s,n,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=t();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.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=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),i.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(i,r,s)=>{this[s]&&(i.removeEventListener(r,this[s]),this[s]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,n=i.height||300,a=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),o=r.height>0?Math.floor((t-r.top)*(n/r.height)):Math.floor(t);return this.performMeshPick(a,o,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),n=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let a=he();be(a,this.projMatrix,this.viewMatrix);let o=[],l=Math.max(0,Math.min(s-1,e)),h=Math.max(0,Math.min(n-1,n-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==n)&&this.resizePickingFbo(s,n),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,n),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let v=0;v<this.meshes.length;v++){let S=this.meshes[v];if(S.visible===!1||S.isPluginMesh)continue;let D=v+1,I=(D&255)/255,P=(D>>8&255)/255,N=(D>>16&255)/255;r.uniform4f(this.uPick.uColorId,I,P,N,1),be(this.modelMatrix,this.modelRootMatrix,S.transform);let C=S.instanceMatrices;if(C&&C.length>=16){let L=C.length>>4,E=he();for(let y of S.primitives){r.bindVertexArray(y.vao);for(let F=0;F<L;F++)be(E,this.modelMatrix,C.subarray(F*16,F*16+16)),be(this.mvpMatrix,a,E),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),_t(r,y)}}else{be(this.mvpMatrix,a,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let L of S.primitives)r.bindVertexArray(L.vao),_t(r,L)}}let c=new Uint8Array(4);r.readPixels(l,h,1,1,6408,5121,c),r.bindFramebuffer(36160,null);let m=c[0]+(c[1]<<8)+(c[2]<<16);m>0&&m<=this.meshes.length&&(o=[this.meshes[m-1]])}o.length===0&&(o=this.meshes.filter(c=>c.visible!==!1));let u=null,f=1/0,g=[0,0,0],w=[0,1,0],[p,b,T]=et(this),x=he();for(let c of o){be(x,this.modelRootMatrix,c.transform);let m=c.instanceMatrices,v=m&&m.length>=16?m.length>>4:1;for(let S=0;S<v;S++){m&&m.length>=16?be(this.modelMatrix,x,m.subarray(S*16,S*16+16)):this.modelMatrix.set(x),be(this.mvpMatrix,a,this.modelMatrix);let D=he();if(!Wn(D,this.mvpMatrix))continue;let I=(l+.5)/s*2-1,P=(h+.5)/n*2-1,N=[0,0,0],C=[0,0,0];An(N,I,P,-1,D),An(C,I,P,1,D);let L=C[0]-N[0],E=C[1]-N[1],y=C[2]-N[2],F=Math.hypot(L,E,y)||1,z=L/F,A=E/F,_=y/F,d={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((R=>{for(let G of c.primitives){if(!G.positions)continue;let H=G.positions,B=G.indices,Z=Math.floor(B?B.length/3:H.length/9);for(let k=0;k<Z;k++){let Y=B?B[k*3]:k*3,ie=B?B[k*3+1]:k*3+1,re=B?B[k*3+2]:k*3+2;jn(N[0],N[1],N[2],z,A,_,H[Y*3],H[Y*3+1],H[Y*3+2],H[ie*3],H[ie*3+1],H[ie*3+2],H[re*3],H[re*3+1],H[re*3+2],d,R)}}})(1e-4),isFinite(d.distance)){let R=d.point[0],G=d.point[1],H=d.point[2],B=this.modelMatrix,Z=B[0]*R+B[4]*G+B[8]*H+B[12],k=B[1]*R+B[5]*G+B[9]*H+B[13],Y=B[2]*R+B[6]*G+B[10]*H+B[14],ie=Z-p,re=k-b,O=Y-T,J=Math.hypot(ie,re,O);if(J<f){Ce(this.normalMatrix,this.modelMatrix);let V=this.normalMatrix,W=d.normal[0],X=d.normal[1],U=d.normal[2],$=V[0]*W+V[3]*X+V[6]*U,j=V[1]*W+V[4]*X+V[7]*U,q=V[2]*W+V[5]*X+V[8]*U,K=Math.hypot($,j,q)||1;$/=K,j/=K,q/=K,$*ie+j*re+q*O>0&&($=-$,j=-j,q=-q),u=c,f=Math.round(J*1e3)/1e3,g=[Math.round(Z*1e3)/1e3,Math.round(k*1e3)/1e3,Math.round(Y*1e3)/1e3],w=[Math.round($*1e3)/1e3,Math.round(j*1e3)/1e3,Math.round(q*1e3)/1e3]}}}}if(!u)return null;let M={meshIndex:this.meshes.indexOf(u),meshName:u.name,nodeIndex:u.nodeIndex,distance:f,hitPoint:g,normal:w,screenX:e,screenY:t};if(i){for(let c of pe)c.onMeshSelect?.(this,M);this.opts.onMeshClick&&this.opts.onMeshClick(M),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:M}))}return M}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,n=r?Math.max(1,t-i):i,a=(s+.5)/n*2-1;return Math.floor((a*.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);Mt(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;We(this.viewMatrix,et(this),i,[0,1,0]),be(this.mvpMatrix,this.projMatrix,this.viewMatrix),Ce(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let i of pe)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of pe)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let n of pe)n.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 n of pe)n.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let n={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(n),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:n}))}}renderXRView(e,t,i,r,s=!0,n=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let a=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,l=e?.transform?.position,h=l?[l.x,l.y,l.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:a,projMatrix:o,eyePos:h,viewport:r,eye:e?.eye||"none",clear:n>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let M=Math.max(2,this.canvas.width||2),c=Math.max(1,this.canvas.height||1),m=Math.max(1,Math.floor(M*.5)),v=Math.max(1,M-m),S=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),D=this.customTarget||this.bounds.center,[I,P,N]=et(this),C=Math.cos(this.currTheta),L=-Math.sin(this.currTheta),E=.032,y=he(),F=he(),z=[I-C*E,P,N-L*E],A=[D[0]-C*E*.25,D[1],D[2]-L*E*.25];Mt(y,this.fov,m/c,.1,S),We(F,z,A,[0,1,0]);let _=he(),d=he(),R=[I+C*E,P,N+L*E],G=[D[0]+C*E*.25,D[1],D[2]+L*E*.25];Mt(_,this.fov,v/c,.1,S),We(d,R,G,[0,1,0]),this.render({viewMatrix:F,projMatrix:y,eyePos:z,viewport:[0,0,m,c],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:d,projMatrix:_,eyePos:R,viewport:[m,0,v,c],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,M,c);return}let t=this.gl,i=0,r=0,s=this.canvas.width,n=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],n=e.viewport[3],t.viewport(i,r,s,n)):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(16640));let a=he(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,be(a,e?.projMatrix??this.projMatrix,o);let l=le().xrDepthShader,h=jr(this.toneMapping),[u,f,g]=e?e.eyePos:et(this);for(let M of pe)M.onBeforeDrawScene?.(this,t,a,[u,f,g],h);let w=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&w===0)return;let p=e?.eye||"none",b=!1,T=w>0?[...this.backdropMeshes,...this.meshes]:this.meshes,x=M=>{for(let c=0;c<T.length;c++){let m=T[c];if(m.visible===!1)continue;let v=this.selectedMeshName!==""&&m.name===this.selectedMeshName;c<w||m.worldSpace===!0||m.name==="__xr_reticle__"?this.modelMatrix.set(m.transform):be(this.modelMatrix,this.modelRootMatrix,m.transform),be(this.mvpMatrix,a,this.modelMatrix),Ce(m.normalMatrix,this.modelMatrix);let S=m.extras?.xr?.stereo||m.userData?.xr?.stereo,D=0,I=0,P=1,N=1;S==="sbs"?(P=.5,D=p==="right"?.5:0):S==="ou"&&(N=.5,I=p==="right"?.5:0);for(let C of m.primitives){let L=!!C.isTransmissive;if(!M&&L){b=!0;continue}if(M&&!L)continue;let E=C.customProgram||this.renderProg,y=C.customUniforms||this.uRender;t.useProgram(E),t.vertexAttrib3f(3,0,0,0),y.uInstanced&&t.uniform1i(y.uInstanced,0),t.uniform1i(y.uToneMapping,h),t.uniform1f(y.uEnvIntensity,this.envIntensity),y.uExposure&&t.uniform1f(y.uExposure,this.exposure),t.uniform3f(y.uCameraPos,u,f,g),t.uniform1f(y.uEmissive,v?1:0),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(y.uNormalMatrix,!1,m.normalMatrix),y.uUvTransform&&t.uniform4f(y.uUvTransform,D,I,P,N),y.uViewportSize&&t.uniform2f(y.uViewportSize,Math.max(1,s),Math.max(1,n)),l?.bind(t,y,this.xrDepthState,o,[i,r,Math.max(1,s),Math.max(1,n)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(y.uEnvironmentMap,4),t.uniform1i(y.uHasEnvironmentMap,1)):t.uniform1i(y.uHasEnvironmentMap,0),this.bindLights(y),y.uSectionEnabled&&t.uniform1i(y.uSectionEnabled,0);for(let z of pe)z.onBeforeDrawPrimitive?.(t,E,C,m,this.worldMatrices||[],this.gltf);t.uniform4fv(y.uBaseColor,C.baseColor),t.uniform1f(y.uMetallic,C.metallic),t.uniform1f(y.uRoughness,C.roughness),y.uClearcoat&&t.uniform2f(y.uClearcoat,C.clearcoat??0,C.clearcoatRoughness??.04),C.texture?(t.activeTexture(33984),t.bindTexture(3553,C.texture),t.uniform1i(y.uBaseColorTexture,0),t.uniform1i(y.uHasTexture,1)):t.uniform1i(y.uHasTexture,0),C.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,C.metallicRoughnessTexture),t.uniform1i(y.uMetallicRoughnessTexture,1),t.uniform1i(y.uHasMetallicRoughnessTexture,1)):t.uniform1i(y.uHasMetallicRoughnessTexture,0),C.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,C.normalTexture),t.uniform1i(y.uNormalTexture,2),t.uniform1i(y.uHasNormalTexture,1),t.uniform1f(y.uNormalScale,C.normalScale)):t.uniform1i(y.uHasNormalTexture,0),C.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,C.occlusionTexture),t.uniform1i(y.uOcclusionTexture,3),t.uniform1i(y.uHasOcclusionTexture,1),t.uniform1f(y.uOcclusionStrength,C.occlusionStrength)):t.uniform1i(y.uHasOcclusionTexture,0),t.bindVertexArray(C.vao);let F=m.instanceMatrices;if(C.instanceCount!==void 0)t.drawElementsInstanced(4,C.indexCount,C.indexType,0,C.instanceCount);else if(F&&F.length>=16&&C.instanced&&y.uInstanced&&y.uViewProj){let z=F.length>>4;t.uniform1i(y.uInstanced,1),t.uniformMatrix4fv(y.uViewProj,!1,a),C.indices?t.drawElementsInstanced(4,C.indexCount,C.indexType,0,z):t.drawArraysInstanced(4,0,C.indexCount,z),t.uniform1i(y.uInstanced,0)}else if(F&&F.length>=16){let z=F.length>>4,A=m.instanceColors,_=he(),d=new Float32Array(9),R=[C.baseColor[0],C.baseColor[1],C.baseColor[2],C.baseColor[3]];for(let G=0;G<z;G++)be(_,this.modelMatrix,F.subarray(G*16,G*16+16)),be(this.mvpMatrix,a,_),Ce(d,_),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,_),t.uniformMatrix3fv(y.uNormalMatrix,!1,d),A&&(R[0]=C.baseColor[0]*A[G*3],R[1]=C.baseColor[1]*A[G*3+1],R[2]=C.baseColor[2]*A[G*3+2],R[3]=C.baseColor[3],t.uniform4fv(y.uBaseColor,R)),_t(t,C)}else _t(t,C)}}};if(x(!1),b){for(let M of pe)M.onBeforeTransmissivePass?.(t,this);x(!0)}for(let M of pe)M.onAfterRender?.(t,this,a,e?.eye??"none",[i,r,s,n],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){or(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of pe)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()}};St.registerPlugin=$n,St.getRegisteredPlugins=Xn;function ii(e){return e+3&-4}var ne=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function cr(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function ur(e,t=0){let[i,r,s,,n,a,o,,l,h,u,,f,g,w]=Array.from({length:15},(d,R)=>ne(e[t+R],R%5===0?1:0)),p=Math.hypot(i,r,s),b=Math.hypot(n,a,o),T=Math.hypot(l,h,u);i*(a*u-h*o)-n*(r*u-h*s)+l*(r*o-a*s)<0&&(p=-p);let x=Math.abs(p)>1e-8?1/p:0,M=Math.abs(b)>1e-8?1/b:0,c=Math.abs(T)>1e-8?1/T:0,m=i*x,v=r*x,S=s*x,D=n*M,I=a*M,P=o*M,N=l*c,C=h*c,L=u*c,E=m+I+L,y=0,F=0,z=0,A=1;if(E>0){let d=.5/Math.sqrt(E+1);A=.25/d,y=(P-C)*d,F=(N-S)*d,z=(v-D)*d}else if(m>I&&m>L){let d=2*Math.sqrt(Math.max(0,1+m-I-L));d>1e-8&&(A=(P-C)/d,y=.25*d,F=(D+v)/d,z=(N+S)/d)}else if(I>L){let d=2*Math.sqrt(Math.max(0,1+I-m-L));d>1e-8&&(A=(N-S)/d,y=(D+v)/d,F=.25*d,z=(P+C)/d)}else{let d=2*Math.sqrt(Math.max(0,1+L-m-I));d>1e-8&&(A=(v-D)/d,y=(N+S)/d,F=(P+C)/d,z=.25*d)}let _=Math.hypot(y,F,z,A);return _>1e-8&&Number.isFinite(_)?(y/=_,F/=_,z/=_,A/=_):(y=0,F=0,z=0,A=1),{t:[f,g,w],r:[y,F,z,A],s:[p,b,T]}}function si(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var Ue=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function lr(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let i=typeof t=="string"?{preset:t}:t,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,s=typeof i.preset=="string"?i.preset:void 0;return!r&&!s?null:{ae:i,src:r,preset:s,volume:Ue(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function Ke(e,t){return mr(e,t)[0]}function mr(e,t){e.updateMatrixWorld(!0);let i=[],r=0,s=[],n=[],a=[],o=[],l=new Set,h=[],u=[],f=new Map,g=[],w=[],p=[],b=new Map,T=[],x=[];function M(A){let _=f.get(A);if(_!==void 0)return _;_=u.length,f.set(A,_);let d=A,R=d.color?.r??1,G=d.color?.g??1,H=d.color?.b??1,B=d.opacity??1,Z={baseColorFactor:[R,G,H,B],metallicFactor:d.metalness??0,roughnessFactor:d.roughness??.5},k={},Y=$=>{if(!$)return;let j=(typeof $=="string"?$:typeof $.source=="string"?$.source:typeof $.image=="string"?$.image:"").trim();if(!j||/[\x00-\x1f\x7f\\]|\.\./.test(j)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(j)||!j.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(j)))return;let q=b.get(j);if(q===void 0){let K=g.length;g.push({uri:j}),w.length===0&&w.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),q=p.length,p.push({sampler:0,source:K}),b.set(j,q)}return{index:q}},ie=Y(d.map);ie&&(Z.baseColorTexture=ie);let re=Y(d.roughnessMap||d.metalnessMap);re&&(Z.metallicRoughnessTexture=re);let O=d.map?.avgColor;Array.isArray(O)&&O.length>=3&&(k.avgColor=[O[0],O[1],O[2]]);let J=Y(d.normalMap),V=Y(d.emissiveMap),W=Y(d.aoMap),X={name:d.name||"",pbrMetallicRoughness:Z,doubleSided:d.side===2||!!d.doubleSided,...J?{normalTexture:J}:{},...V?{emissiveTexture:V}:{},...W?{occlusionTexture:W}:{},...Object.keys(k).length>0?{extras:k}:{}};if(d.emissive&&(d.emissive.r>0||d.emissive.g>0||d.emissive.b>0)){let $=d.emissiveIntensity??1;X.emissiveFactor=[d.emissive.r*$,d.emissive.g*$,d.emissive.b*$]}let U={};return d.clearcoat&&d.clearcoat>0&&(U.KHR_materials_clearcoat={clearcoatFactor:d.clearcoat,clearcoatRoughnessFactor:d.clearcoatRoughness||0}),d.sheen&&d.sheen>0&&(U.KHR_materials_sheen={sheenColorFactor:d.sheenColor?[d.sheenColor.r,d.sheenColor.g,d.sheenColor.b]:[1,1,1],sheenRoughnessFactor:d.sheenRoughness||0}),d.transmission&&d.transmission>0&&(U.KHR_materials_transmission={transmissionFactor:d.transmission}),d.thickness&&d.thickness>0&&(U.KHR_materials_volume={thicknessFactor:d.thickness,attenuationDistance:d.attenuationDistance??1/0,attenuationColor:d.attenuationColor?[d.attenuationColor.r,d.attenuationColor.g,d.attenuationColor.b]:[1,1,1]}),d.ior!==void 0&&d.ior!==1.5&&(U.KHR_materials_ior={ior:d.ior}),d.dispersion&&d.dispersion>0&&(U.KHR_materials_dispersion={dispersion:d.dispersion}),d.iridescence&&d.iridescence>0&&(U.KHR_materials_iridescence={iridescenceFactor:d.iridescence,iridescenceIor:d.iridescenceIOR??1.3}),Object.keys(U).length>0&&(X.extensions=U),u.push(X),_}function c(A,_){let d=new Uint8Array(A.buffer,A.byteOffset,A.byteLength),R=ii(d.byteLength),G=new Uint8Array(R);G.set(d),i.push(G);let H=s.length;return s.push({buffer:0,byteOffset:r,byteLength:d.byteLength,target:_}),r+=R,H}function m(A,_,d,R,G,H,B){let Z=c(A,d),k=n.length,Y={bufferView:Z,byteOffset:0,componentType:R,count:G,type:_};return H&&(Y.min=H),B&&(Y.max=B),n.push(Y),k}e.traverse(A=>{if(A.isLight||A.color&&A.intensity!==void 0){let _=A.matrixWorld?.elements,d=ne(_?_[12]:A.position?.x,0),R=ne(_?_[13]:A.position?.y,0),G=ne(_?_[14]:A.position?.z,0),H=A.target,B=H?.parent?H?.matrixWorld?.elements:void 0,Z=ne(B?B[12]:H?.position?.x,0),k=ne(B?B[13]:H?.position?.y,0),Y=ne(B?B[14]:H?.position?.z,0),ie=Z-d,re=k-R,O=Y-G,J=Math.hypot(ie,re,O),V=Math.max(.01,Math.min(Math.PI/2,ne(A.angle,Math.PI/3))),W=Math.max(0,Math.min(1,ne(A.penumbra,0)));x.push({type:A.type,color:[A.color.r,A.color.g,A.color.b],intensity:A.intensity,position:[d,R,G],...A.type==="spot"?{direction:J>1e-6?[ie/J,re/J,O/J]:[0,-1,0],outerConeAngle:V,innerConeAngle:Math.max(0,V*(1-W)),range:Math.max(0,ne(A.distance,0))}:A.type==="point"?{range:Math.max(0,ne(A.distance,0))}:{}})}});let v=[],S=new Set([e]),D=[];if(Array.isArray(e.children))for(let A=e.children.length-1;A>=0;A--)D.push({obj:e.children[A],parentKids:v});for(;D.length>0;){let{obj:A,parentKids:_}=D.pop();if(!A||typeof A!="object"||S.has(A))continue;S.add(A),A._bakeAuthorGeometry?.(),le().materializeDeclarativeGeometry?.(A);let d=!!(A.userData&&(A.userData.xr&&typeof A.userData.xr=="object"&&Object.keys(A.userData.xr).length>0||A.userData.interactivity&&typeof A.userData.interactivity=="object"&&Object.keys(A.userData.interactivity).length>0)),R={name:A.name||(d?`Node_${o.length}`:"")},G=ne(A.position?.x,0),H=ne(A.position?.y,0),B=ne(A.position?.z,0),Z=ne(A.quaternion?.x,0),k=ne(A.quaternion?.y,0),Y=ne(A.quaternion?.z,0),ie=ne(A.quaternion?.w,1),re=ne(A.scale?.x,1),O=ne(A.scale?.y,1),J=ne(A.scale?.z,1);if((G||H||B)&&(R.translation=[G,H,B]),(Z||k||Y||ie!==1)&&(R.rotation=[Z,k,Y,ie]),(re!==1||O!==1||J!==1)&&(R.scale=[re,O,J]),A.visible===!1&&(R.extensions={...R.extensions||{},KHR_node_visibility:{visible:!1}},l.add("KHR_node_visibility")),A.userData&&Object.keys(A.userData).length>0&&(R.extras=JSON.parse(JSON.stringify(A.userData,(X,U)=>{if(!(X==="__proto__"||X==="prototype"||X==="constructor"))return typeof U=="function"?void 0:U})),A.userData.xr)){let X=si(A.userData.xr);R.extensions={...R.extensions||{},MOZ_hubs_components:X,ANDROID_xr_scenecore:X},le().xrTraitSerializer?.gltfNode(R,A.userData.xr),l.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(A.geometry){let X=A.geometry,U=X.attributes.position;if(U&&U.count>0){let $=[1/0,1/0,1/0],j=[-1/0,-1/0,-1/0];for(let se=0;se<U.count;se++){let ae=U.getX(se),oe=U.getY(se),ce=U.getZ(se);ae<$[0]&&($[0]=ae),ae>j[0]&&(j[0]=ae),oe<$[1]&&($[1]=oe),oe>j[1]&&(j[1]=oe),ce<$[2]&&($[2]=ce),ce>j[2]&&(j[2]=ce)}let q={attributes:{POSITION:m(U.array,"VEC3",34962,5126,U.count,$,j)}};if(X.attributes.normal&&(q.attributes.NORMAL=m(X.attributes.normal.array,"VEC3",34962,5126,X.attributes.normal.count)),X.attributes.uv&&(q.attributes.TEXCOORD_0=m(X.attributes.uv.array,"VEC2",34962,5126,X.attributes.uv.count)),X.index){let se=X.index.array instanceof Uint32Array;q.indices=m(X.index.array,"SCALAR",34963,se?5125:5123,X.index.count)}let K=Array.isArray(A.material)?A.material[0]:A.material;K&&(q.material=M(K));let Q=A.userData?.variants;if(Q&&typeof Q=="object"){let se=new Map;for(let ae of Object.keys(Q)){if(!ae||ae==="__proto__"||ae==="constructor"||ae==="prototype")continue;let oe=Q[ae];if(!oe||typeof oe!="object")continue;let ce=T.indexOf(ae);if(ce===-1&&T.length<256&&(ce=T.length,T.push(ae)),ce===-1)continue;let Te=M(oe),Re=se.get(Te);Re||(Re=[],se.set(Te,Re)),Re.push(ce)}if(se.size>0){let ae=[];for(let[oe,ce]of se.entries())ae.push({material:oe,variants:ce});q.extensions={...q.extensions||{},KHR_materials_variants:{mappings:ae}},l.add("KHR_materials_variants")}}let te=A;if(te.isInstancedMesh&&typeof te.count=="number"&&te.count>0&&te.instanceMatrix?.array){let se=Math.min(1e4,Math.floor(te.count)),ae=te.instanceMatrix.array,oe=new Float32Array(se*3),ce=new Float32Array(se*4),Te=new Float32Array(se*3);for(let me=0;me<se;me++){let{t:Ne,r:Ee,s:Xe}=ur(ae,me*16);oe[me*3]=Ne[0],oe[me*3+1]=Ne[1],oe[me*3+2]=Ne[2],ce[me*4]=Ee[0],ce[me*4+1]=Ee[1],ce[me*4+2]=Ee[2],ce[me*4+3]=Ee[3],Te[me*3]=Xe[0],Te[me*3+1]=Xe[1],Te[me*3+2]=Xe[2]}let Re={TRANSLATION:m(oe,"VEC3",0,5126,se),ROTATION:m(ce,"VEC4",0,5126,se),SCALE:m(Te,"VEC3",0,5126,se)};if(te.instanceColor?.array&&te.instanceColor.array.length>=se*3){let me=new Float32Array(te.instanceColor.array.subarray(0,se*3));Re._COLOR_0=m(me,"VEC3",0,5126,se)}R.extensions={...R.extensions||{},EXT_mesh_gpu_instancing:{attributes:Re}},l.add("EXT_mesh_gpu_instancing")}let fe=a.length;a.push({primitives:[q],name:A.name,...R.extras?{extras:R.extras}:{}}),R.mesh=fe}}let V=o.length;o.push(R),h.push(A),_.push(V);let W=A.children;if(Array.isArray(W)&&W.length>0){let X=[];R.children=X;for(let U=W.length-1;U>=0;U--)D.push({obj:W[U],parentKids:X})}}for(let A=0;A<o.length;A++){let _=o[A];_.children&&_.children.length===0?delete _.children:_.children&&_.children.length>0&&(_.extras?.xr?.lod||_.extensions?.ANDROID_xr_scenecore?.lod||h[A]?.isLOD)&&(_.extensions={..._.extensions||{},MSFT_lod:{ids:[..._.children]}},l.add("MSFT_lod"))}let I=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),P=[];if(typeof I=="function"&&h.length>0){let A=t?.duration??4,_=t?.fps??15,d=Math.max(2,Math.round(A*_)+1),R=new Float32Array(d),G=h.map(O=>[ne(O.position?.x,0),ne(O.position?.y,0),ne(O.position?.z,0),ne(O.quaternion?.x,0),ne(O.quaternion?.y,0),ne(O.quaternion?.z,0),ne(O.quaternion?.w,1),ne(O.scale?.x,1),ne(O.scale?.y,1),ne(O.scale?.z,1)]),H=h.map(()=>new Float32Array(d*3)),B=h.map(()=>new Float32Array(d*4)),Z=h.map(()=>new Float32Array(d*3));for(let O=0;O<d;O++){let J=O/(d-1)*A;R[O]=J;try{I(J)}catch{}for(let V=0;V<h.length;V++){let W=h[V];H[V][O*3]=ne(W.position?.x,0),H[V][O*3+1]=ne(W.position?.y,0),H[V][O*3+2]=ne(W.position?.z,0);let X=ne(W.quaternion?.x,0),U=ne(W.quaternion?.y,0),$=ne(W.quaternion?.z,0),j=ne(W.quaternion?.w,1),q=Math.hypot(X,U,$,j)||1;if(X/=q,U/=q,$/=q,j/=q,O>0){let K=(O-1)*4,Q=B[V];Q[K]*X+Q[K+1]*U+Q[K+2]*$+Q[K+3]*j<0&&(X=-X,U=-U,$=-$,j=-j)}B[V][O*4]=X,B[V][O*4+1]=U,B[V][O*4+2]=$,B[V][O*4+3]=j,Z[V][O*3]=ne(W.scale?.x,1),Z[V][O*3+1]=ne(W.scale?.y,1),Z[V][O*3+2]=ne(W.scale?.z,1)}}for(let O=0;O<h.length;O++){let J=h[O],V=G[O];J.position?.set(V[0],V[1],V[2]),J.quaternion?.set(V[3],V[4],V[5],V[6]),J.scale?.set(V[7],V[8],V[9])}e.updateMatrixWorld(!0);let k=null,Y=()=>(k===null&&(k=m(R,"SCALAR",0,5126,d,[0],[A])),k),ie=[],re=[];for(let O=0;O<h.length;O++){let J=G[O],V=(X,U,$)=>X.some((j,q)=>Math.abs(j-J[$+q%U])>1e-4),W=(X,U,$,j)=>{X&&re.push({sampler:ie.push({input:Y(),interpolation:"LINEAR",output:m(U,$,0,5126,d)})-1,target:{node:O,path:j}})};W(V(H[O],3,0),H[O],"VEC3","translation"),W(V(B[O],4,3),B[O],"VEC4","rotation"),W(V(Z[O],3,7),Z[O],"VEC3","scale")}re.length>0&&P.push({name:"ProceduralLoop",samplers:ie,channels:re})}let N=zn(o,a,e.userData),C=[],L=[],E=[];for(let A=0;A<o.length;A++){let _=o[A],d=lr(_.extras?.xr);if(!d)continue;let{ae:R,src:G,preset:H,volume:B,loop:Z,isGlobal:k}=d,Y=_.name||`Node_${A}`,ie=L.length;L.push({name:`${Y}_source`,gain:B,loop:Z,autoPlay:typeof R.autoplay=="boolean"?R.autoplay:!0,...G!==void 0?{audio:C.push({uri:G})-1}:{},...H?{extras:{preset:H,pitch:Ue(R.pitch,.25,4,1)}}:{}});let re=E.length,O=Ue(R.refDistance,.05,100,1),J=Ue(R.coneInnerAngle,0,360,360),V=Ue(R.coneOuterAngle,J,360,360);E.push({name:`${Y}_emitter`,type:k?"global":"positional",gain:B,sources:[ie],...k?{}:{positional:{distanceModel:R.distanceModel==="linear"||R.distanceModel==="exponential"?R.distanceModel:"inverse",refDistance:O,maxDistance:Ue(R.maxDistance,O,500,Math.max(O,25)),rolloffFactor:Ue(R.rolloffFactor,0,10,1),coneInnerAngle:+(J*Math.PI/180).toFixed(6),coneOuterAngle:+(V*Math.PI/180).toFixed(6),coneOuterGain:Ue(R.coneOuterGain,0,1,0)}}}),_.extensions={..._.extensions||{},KHR_audio_emitter:{emitter:re}},l.add("KHR_audio_emitter")}let y={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:v}],scene:0,nodes:o,meshes:a,materials:u,...g.length>0?{images:g}:{},...w.length>0?{samplers:w}:{},...p.length>0?{textures:p}:{},accessors:n,bufferViews:s,buffers:[{byteLength:r}],...P.length>0?{animations:P}:{},...N||l.size>0?{extensionsUsed:[...N?["KHR_interactivity"]:[],...l]}:{},...N||T.length>0||E.length>0?{extensions:{...N?{KHR_interactivity:N}:{},...T.length>0?{KHR_materials_variants:{variants:T.map(A=>({name:A}))}}:{},...E.length>0?{KHR_audio_emitter:{...C.length>0?{audio:C}:{},sources:L,emitters:E}}:{}}}:{}},F=new Uint8Array(r),z=0;for(let A of i)F.set(A,z),z+=A.byteLength;return[{gltf:y,bin:F.buffer,lights:x,environmentIntensity:e.environmentIntensity},h]}function Nn(e){return new TextEncoder().encode(e)}function tt(e,t){let{gltf:i,bin:r}=Ke(e,t),s=JSON.stringify(i),n=Nn(s),a=(4-n.byteLength%4)%4,o=n.byteLength+a,l=20+o+8+r.byteLength,h=new Uint8Array(l),u=new DataView(h.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,l,!0),u.setUint32(12,o,!0),u.setUint32(16,1313821514,!0),h.set(n,20);for(let g=0;g<a;g++)h[20+n.byteLength+g]=32;let f=20+o;return u.setUint32(f,r.byteLength,!0),u.setUint32(f+4,5130562,!0),h.set(new Uint8Array(r),f+8),h}function oi(e,t){let[i,r]=mr(e,t);return hr(i,r)}function hr(e,t){let i=[],r=e.gltf,s=le().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,e);let n=e.bin,a=n instanceof ArrayBuffer?n:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),o=r.accessors||[],l=r.bufferViews||[],h=r.materials||[],u=r.meshes||[],f=r.nodes||[],g=r.textures||[],w=r.images||[],p=r.samplers||[],b=new Set,T=h.map((S,D)=>cr(b,Ct(S?.name,`Material_${D}`))),x=new Map;function M(S){let D=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(S);if(!D)return null;let I=D[2].replace(/\s+/g,""),P=I.endsWith("==")?2:I.endsWith("=")?1:0,N=new Uint8Array((I.length*3>>2)-P),C=E=>{let y=I.charCodeAt(E);return y>96?y-71:y>64?y-65:y>47?y+4:y===43?62:y===47?63:0},L=0;for(let E=0;E<I.length;E+=4){let y=C(E)<<18|C(E+1)<<12|C(E+2)<<6|C(E+3);N[L++]=y>>16&255,L<N.length&&(N[L++]=y>>8&255),L<N.length&&(N[L++]=y&255)}return N}function c(S,D,I){let P=S?.index;if(typeof P!="number")return;let N=g[P],C=N?.source;if(typeof C!="number"||!w[C])return;let L=x.get(C);if(L===void 0){L=null;let F=w[C],z=null;if(typeof F.bufferView=="number"){let A=l[F.bufferView],_=A?.byteOffset||0,d=A?.byteLength||0;A&&d>0&&_>=0&&_+d<=a.byteLength&&(z=new Uint8Array(a,_,d))}else typeof F.uri=="string"&&(z=M(F.uri));if(z&&z.byteLength>0){let A=z[0]===255&&z[1]===216&&z[2]===255||!(z[0]===137&&z[1]===80)&&/jpe?g/i.test(F.mimeType||F.uri||"");L={file:`texture_${C}.${A?"jpg":"png"}`,data:z}}x.set(C,L)}if(!L)return;let E=typeof N.sampler=="number"?p[N.sampler]:void 0,y=F=>F===33071?"clamp":F===33648?"mirror":"repeat";return{file:L.file,data:L.data,wrapS:y(E?.wrapS),wrapT:y(E?.wrapT),...D?{scale:D}:{},...I?{bias:I}:{}}}function m(S){let D=o[S];if(!D)throw new Error(`Accessor ${S} not found`);let I=l[D.bufferView||0],P=(I.byteOffset||0)+(D.byteOffset||0),N=I.byteLength||0;return{acc:D,buffer:a.slice(P,P+N)}}function v(S,D,I,P){let N=[],C=u[S];if(!C)return N;let L=C.primitives||[];for(let E=0;E<L.length;E++){let y=L[E],F=y.attributes?.POSITION;if(F===void 0)continue;let{acc:z,buffer:A}=m(F),_=new Float32Array(A,0,z.count*3),d,R=y.attributes?.NORMAL;if(R!==void 0){let{acc:U,buffer:$}=m(R),j=new Float32Array($,0,U.count*3);d=new Float32Array(j.length);for(let q=0;q<U.count;q++){let K=j[q*3],Q=j[q*3+1],te=j[q*3+2],fe=Math.hypot(K,Q,te)||1;d[q*3]=K/fe,d[q*3+1]=Q/fe,d[q*3+2]=te/fe}}let G,H=y.attributes?.TEXCOORD_0;if(H!==void 0){let{acc:U,buffer:$}=m(H);G=new Float32Array($,0,U.count*2)}let B;if(y.indices!==void 0){let{acc:U,buffer:$}=m(y.indices);B=U.componentType===5125?new Uint32Array($,0,U.count):new Uint16Array($,0,U.count);let j=z.count;for(let q of B)if(q>=j)throw new Error(`SecurityError: Index buffer value (${q}) out of vertex bounds [0, ${j}).`)}else{let U=z.count;B=U>65535?new Uint32Array(U):new Uint16Array(U);for(let $=0;$<U;$++)B[$]=$}let Z="DefaultMaterial",k=[1,1,1],Y=.5,ie=0,re=0,O=0,J=1.5,V=1,W=[0,0,0],X;if(y.material!==void 0&&h[y.material]){let U=h[y.material];Z=T[y.material]||`Material_${y.material}`;let $=U.pbrMetallicRoughness||{},j=(Ne,Ee)=>Array.isArray(Ne)&&Ne.length>=3?[Ne[0],Ne[1],Ne[2]]:Ee;k=j($.baseColorFactor,[1,1,1]);let q=Array.isArray($.baseColorFactor)&&typeof $.baseColorFactor[3]=="number"?$.baseColorFactor[3]:1,K=k[0]!==1||k[1]!==1||k[2]!==1||q!==1,Q=c($.baseColorTexture,K?[k[0],k[1],k[2],q]:void 0),te=U.extras?.avgColor;!Q&&Array.isArray(te)&&te.length>=3&&(k=[k[0]*te[0],k[1]*te[1],k[2]*te[2]]),typeof $.roughnessFactor=="number"&&(Y=$.roughnessFactor),typeof $.metallicFactor=="number"&&(ie=$.metallicFactor);let fe=typeof $.roughnessFactor=="number"?$.roughnessFactor:1,se=typeof $.metallicFactor=="number"?$.metallicFactor:1,ae=c($.metallicRoughnessTexture,fe!==1||se!==1?[1,fe,se,1]:void 0);W=j(U.emissiveFactor,[0,0,0]);let oe=(W[0]>0||W[1]>0||W[2]>0)&&(W[0]!==1||W[1]!==1||W[2]!==1)?[W[0],W[1],W[2],1]:void 0,ce=c(U.emissiveTexture,oe),Te=c(U.normalTexture,[2,2,2,1],[-1,-1,-1,0]),Re=c(U.occlusionTexture);(Q||ae||Te||ce||Re)&&(X=[Q,ae,Te,ce,Re]);let me=U.extensions||{};me.KHR_materials_clearcoat&&(re=me.KHR_materials_clearcoat.clearcoatFactor??0,O=me.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof me.KHR_materials_ior?.ior=="number"&&(J=me.KHR_materials_ior.ior),V=q*(1-(me.KHR_materials_transmission?.transmissionFactor??0))}N.push({name:L.length>1?`${D}_p${E}`:D,positions:_,indices:B,normals:d,uvs:G,materialName:Z,color:k,roughness:Y,metallic:ie,clearcoat:re,clearcoatRoughness:O,ior:J,opacity:V,emissiveColor:W,...X?{textures:X}:{},xrTraits:I||C.extras?.xr,...P?{invisible:!0}:{}})}return N}if(f.length>0){let S=new Float32Array(0),D=new Uint16Array(0),I=(_,d)=>{if(_===void 0)return null;let{acc:R,buffer:G}=m(_);return new Float32Array(G,0,R.count*d)},P=(_,d)=>Array.isArray(_)&&_.length>=3?[ne(_[0],d),ne(_[1],d),ne(_[2],d)]:[d,d,d],N=(_,d,R)=>_&&_.length>=(d+1)*3?[_[d*3],_[d*3+1],_[d*3+2]]:R,C=(_,d,R)=>_&&_.length>=(d+1)*4?[_[d*4],_[d*4+1],_[d*4+2],_[d*4+3]]:R,L=new Map,E=r.animations?.[0];if(E&&Array.isArray(E.channels)&&Array.isArray(E.samplers))for(let _ of E.channels){let d=E.samplers[_?.sampler],R=_?.target?.node,G=_?.target?.path;if(!d||typeof R!="number"||d.input===void 0)continue;let H=L.get(R);H||(H={input:d.input},L.set(R,H)),G==="translation"?H.t=d.output:G==="rotation"?H.r=d.output:G==="scale"&&(H.s=d.output)}let y=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(y)||y.length===0){let _=new Set;for(let d of f)if(Array.isArray(d?.children))for(let R of d.children)_.add(R);y=[];for(let d=0;d<f.length;d++)_.has(d)||y.push(d);y.length===0&&(y=[0])}let F=new Set,z=[],A=(_,d)=>{if(Array.isArray(_))for(let R=_.length-1;R>=0;R--)z.push({idx:_[R],out:d})};for(A(y,i);z.length>0;){let{idx:_,out:d}=z.pop();if(typeof _!="number"||_<0||_>=f.length||F.has(_))continue;F.add(_);let R=f[_];if(!R)continue;let G=[0,0,0],H=[0,0,0,1],B=[1,1,1];if(Array.isArray(R.matrix)&&R.matrix.length===16){let V=ur(R.matrix);G=V.t,H=V.r,B=V.s}else G=P(R.translation,0),Array.isArray(R.rotation)&&R.rotation.length>=4&&(H=[ne(R.rotation[0],0),ne(R.rotation[1],0),ne(R.rotation[2],0),ne(R.rotation[3],1)]),B=P(R.scale,1);let Z,k=L.get(_);if(k){let V=I(k.input,1);if(V&&V.length>0){let W=I(k.t,3),X=I(k.r,4),U=I(k.s,3),$=Array.from(V),j=[],q=[],K=[];for(let Q=0;Q<V.length;Q++)j.push(N(W,Q,G)),q.push(C(X,Q,H)),K.push(N(U,Q,B));Z={times:$,translations:j,rotations:q,scales:K}}}let Y=Array.isArray(R.children)?R.children:[],ie=typeof R.mesh=="number"&&R.mesh>=0&&R.mesh<u.length,re=t?.[_]?.userData?.xr??R.extras?.xr;if(!ie&&Y.length===0&&(R.camera!==void 0||R.extensions?.KHR_lights_punctual||!R.name&&!R.extras&&!re&&!Z))continue;let O=(V,W,X)=>({name:V,positions:S,indices:D,isXform:!0,xrTraits:re,timeSamples:Z,translation:G,rotation:H,scale:B,children:W,...X?{invisible:!0}:{}}),J=R.visible===!1||R.extensions?.KHR_node_visibility?.visible===!1||t?.[_]?.visible===!1;if(ie){let V=R.name||u[R.mesh]?.name||`Mesh_${_}`,W=v(R.mesh,V,re,J),X=R.extensions?.EXT_mesh_gpu_instancing?.attributes;if(X&&typeof X=="object"&&W.length>0){let U=I(X.TRANSLATION,3),$=I(X.ROTATION,4),j=I(X.SCALE,3),q=I(X._COLOR_0,3),K=Math.min(1e3,U?U.length/3:$?$.length/4:j?j.length/3:0);if(K>0){let Q=[];for(let te=0;te<K;te++){let fe=N(U,te,[0,0,0]),se=C($,te,[0,0,0,1]),ae=N(j,te,[1,1,1]);for(let oe of W){let ce=oe.color||[.8,.8,.8],Te=q&&q.length>=(te+1)*3;Q.push({...oe,name:`${oe.name}_${te}`,materialName:Te?`${oe.materialName}_inst_${te}`:oe.materialName,color:Te?[ce[0]*q[te*3],ce[1]*q[te*3+1],ce[2]*q[te*3+2]]:oe.color,translation:fe,rotation:se,scale:ae})}}A(Y,Q),d.push(O(V,Q,J));continue}}if(W.length===1)W[0].translation=G,W[0].rotation=H,W[0].scale=B,W[0].timeSamples=Z,Y.length>0&&(W[0].children=[],A(Y,W[0].children)),d.push(W[0]);else{let U=[...W];A(Y,U),d.push(O(V,U,J))}}else{let V=[];A(Y,V),d.push(O(R.name||`Group_${_}`,V,J))}}}else for(let S=0;S<u.length;S++){let D=u[S].name||`Mesh_${S}`;i.push(...v(S,D,u[S].extras?.xr))}return i}function Ct(e,t){if(!e||typeof e!="string")return t;let i=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||t}function At(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ye(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var Le=(e,t,i)=>`(${ye(e)}, ${ye(t)}, ${ye(i)})`,Et=(e,t,i,r)=>`(${ye(e)}, ${ye(t)}, ${ye(i)}, ${ye(r)})`;function ar(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=Le(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function ai(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${ye(e[r*2])}, ${ye(1-e[r*2+1])})`;return i.join(", ")}function ci(e){return Array.from(e).join(", ")}function ui(e){let t=new Map,i=0,r=null,s=[...e];for(;s.length>0;){let p=s.pop();if(!p.isXform&&p.positions&&p.positions.length>0){let b=Ct(p.materialName,"DefaultMaterial");t.has(b)||t.set(b,{color:p.color||[1,1,1],roughness:p.roughness??.5,metallic:p.metallic??0,clearcoat:p.clearcoat??0,clearcoatRoughness:p.clearcoatRoughness??0,ior:p.ior??1.5,opacity:p.opacity??1,emissiveColor:p.emissiveColor||[0,0,0],textures:p.textures})}if(p.timeSamples&&p.timeSamples.times.length>0){let b=p.timeSamples.times[p.timeSamples.times.length-1];b>i&&(i=b)}if(p.xrTraits?.anchor&&!r&&(r=p.xrTraits.anchor==="vertical"||p.xrTraits.anchor==="wall"?"vertical":"horizontal"),p.children)for(let b=p.children.length-1;b>=0;b--)s.push(p.children[b])}let n="";i>0&&(n=`startTimeCode = 0
|
|
250
|
-
endTimeCode = ${ye(
|
|
214
|
+
void main(){fragColor=uColorId;}`;function kt(t,e,i){let r={};for(let n of i)r[n]=t.getUniformLocation(e,n);return r}var bi="uMVP uModel uInstanced uViewProj uNormalMatrix uUvTransform uBaseColor uMetallic uRoughness uClearcoat uEmissive uCameraPos uBaseColorTexture uHasTexture uMetallicRoughnessTexture uHasMetallicRoughnessTexture uNormalTexture uHasNormalTexture uNormalScale uOcclusionTexture uHasOcclusionTexture uOcclusionStrength uEmissiveFactor uEmissiveTexture uHasEmissiveTexture uToneMapping uEnvironmentMap uHasEnvironmentMap uAmbientColor uHemi uNumDirLights uDirLightDir uDirLightColor uNumPointLights uPointLightPos uPointLightColor uPointLightSpotDir uPointLightSpotCone uEnvIntensity uExposure uViewportSize uSectionPlane uSectionEnabled".split(" ");function Kn(){let t=de(),e=t.xrDepthShader,i=t.shadowMapShader;return{fs:di.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||"").replace("/*SHD_U*/",i?.uniformsGLSL||"").replace("/*SHD_D*/",i?.dirGLSL||"").replace("/*SHD_P*/",i?.ptGLSL||""),uniforms:[...bi,...e?.uniformNames||[],...i?.uniformNames||[]]}}function gi(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let i=e.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:i.startsWith("https://")||i.startsWith("blob:")?e:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function jn(t,e,i,r,n,s,a,o){if(r===void 0||!e.accessors?.[r])return null;let l=Hn(e,i,e.accessors[r],s);if(!l)return null;o&&(l=l.slice(),pr(l,o));let y=t.createBuffer();return a.push(y),t.bindBuffer(34962,y),t.bufferData(34962,l,35044),t.enableVertexAttribArray(n),t.vertexAttribPointer(n,s,5126,!1,0,0),l}function $n(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function vr(t,e,i){let r=Kn(),n=Xn,s=r.fs,a=!1;for(let l of ge)if(l.onResolveShader){let y=l.onResolveShader(e,i,n,s);y&&(n=y.vs,s=y.fs,a=!0)}let o=a?st(t,n,s):null;return{program:o,uniforms:o?kt(t,o,r.uniforms):null}}function yi(t,e,i){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let n=r.length>>4,s=e.instanceColors,a=new Float32Array(n*20);for(let l=0;l<n;l++)a.set(r.subarray(l*16,l*16+16),l*20),a[l*20+16]=s?s[l*3]:1,a[l*20+17]=s?s[l*3+1]:1,a[l*20+18]=s?s[l*3+2]:1,a[l*20+19]=1;let o=t.createBuffer();i.push(o),t.bindBuffer(34962,o),t.bufferData(34962,a,35044);for(let l=0;l<5;l++)t.enableVertexAttribArray(8+l),t.vertexAttribPointer(8+l,4,5126,!1,80,l*16),t.vertexAttribDivisor(8+l,1);return!0}function xi(t,e){let i=t.materials?.[e?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let n of r){let s=n?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var ao=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Mr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function It(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function Sr(t,e){let i=t?.pbrMetallicRoughness,r=i?.baseColorFactor,n=t?.emissiveFactor,s=t?.extensions?.KHR_materials_clearcoat,a=o=>o!==void 0&&e[o.index]?e[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:a(i?.baseColorTexture),metallicRoughnessTexture:a(i?.metallicRoughnessTexture),normalTexture:a(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:a(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,emissiveTexture:a(t?.emissiveTexture),emissiveFactor:Array.isArray(n)&&n.length>=3?[n[0],n[1],n[2]]:[0,0,0],isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function wr(t,e,i){let r=new Set,n=s=>{s&&!r.has(s)&&(r.add(s),t.deleteTexture(s))};for(let s of e)for(let a of s.primitives){if(a.vao&&t.deleteVertexArray(a.vao),a.buffers)for(let l of a.buffers)t.deleteBuffer(l);for(let l of[a.texture,a.metallicRoughnessTexture,a.normalTexture,a.occlusionTexture,a.emissiveTexture])n(l);let o=new Set;a.customProgram&&o.add(a.customProgram);for(let l of a.programCache?.values()??[])l.program&&o.add(l.program);for(let l of o)t.deleteProgram(l)}if(i)for(let s of i)n(s)}function br(t,e,i=Mr,r){let n={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return vi(t,e,i,r,n)}catch(s){let a=n.mesh&&!n.meshes.includes(n.mesh)?[...n.meshes,n.mesh]:n.meshes;wr(t,a,n.gpuTextures),n.vao&&t.deleteVertexArray(n.vao);for(let o of n.buffers)t.deleteBuffer(o);throw s}}function vi(t,e,i,r,n){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,a=Ft("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(s,e);let o=e.bin,l=[];n.meshes=l;let y=[],f=s.extensions?.KHR_materials_variants;f&&Array.isArray(f.variants)&&f.variants.forEach((T,S)=>{y.push(typeof T?.name=="string"&&T.name?T.name:`Variant_${S}`)});let b=zn(s),h=[];if(Array.isArray(s.nodes))for(let T=0;T<s.nodes.length;T++){let S=s.nodes[T];S.mesh!==void 0&&s.meshes&&s.meshes[S.mesh]&&h.push({node:S,nodeIdx:T,meshIdx:S.mesh})}let d=h.length>0?h:(s.meshes||[]).map((T,S)=>({node:T,nodeIdx:-1,meshIdx:S})),v=[],M=Array.isArray(e.lights)&&e.lights.length>0?e.lights:Array.isArray(s.asset?.extras?.lights)&&s.asset.extras.lights.length>0?s.asset.extras.lights:null;if(M)for(let T of M)v.push({...T,type:T.type||T.light_type||"point",groundColor:T.groundColor??T.ground_color,innerConeAngle:T.innerConeAngle??T.inner_cone_angle,outerConeAngle:T.outerConeAngle??T.outer_cone_angle});else s.extensions?.KHR_lights_punctual?.lights&&v.push(...Yn(s,b));if(v.length===0&&(v.push({type:"ambient",color:[1,1,1],intensity:.35}),v.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),d.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${d.length}`);let m=[];if(n.gpuTextures=m,s.textures&&s.images){if(s.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${s.textures.length}`);for(let T=0;T<s.textures.length;T++){let S=s.textures[T],A=s.images[S.source];if(A){let D=t.createTexture();t.bindTexture(3553,D),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255]));for(let[F,k]of[[10242,10497],[10243,10497],[10241,9729],[10240,9729]])t.texParameteri(3553,F,k);let R=F=>{D.__gpuImageSource=F,t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,F),t.generateMipmap(3553),r?.()};if(A.bufferView!==void 0){let F=s.bufferViews[A.bufferView],k=F.byteOffset||0,V=new Blob([o.slice(k,k+F.byteLength)],{type:A.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(V).then(R).catch(()=>{})}else if(A.uri){let F=gi(A.uri);if(F){let k=new Image;k.crossOrigin="anonymous",k.referrerPolicy="no-referrer",k.onload=()=>R(k),k.src=F}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",A.uri)}m.push(D)}else m.push(null)}}let u=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0],p=0,x=0;for(let T=0;T<d.length;T++){let S=d[T],A=s.meshes[S.meshIdx],D=S.nodeIdx>=0?b[S.nodeIdx]:ve(),R=new Float32Array(9);Fe(R,D);let F=S.node?.extras?.shadow,k={name:S.node.name||A.name||`Mesh_${S.meshIdx}`,nodeIndex:S.nodeIdx,transform:D,normalMatrix:R,primitives:[],extras:S.node.extras||A.extras,...S.node?.visible===!1||S.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{},...typeof F?.cast=="boolean"?{castShadow:F.cast}:{},...typeof F?.receive=="boolean"?{receiveShadow:F.receive}:{}};n.mesh=k;let V=S.node?.extensions?.EXT_mesh_gpu_instancing;if(V&&V.attributes&&typeof V.attributes=="object"){let L=V.attributes,O=L.TRANSLATION!==void 0?s.accessors?.[L.TRANSLATION]:null,c=L.ROTATION!==void 0?s.accessors?.[L.ROTATION]:null,I=L.SCALE!==void 0?s.accessors?.[L.SCALE]:null,C=L._COLOR_0!==void 0?s.accessors?.[L._COLOR_0]:null,U=Number(O?.count??c?.count??I?.count??0);if(!Number.isFinite(U)||U<0||U>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${U}`);if(U>0){let j=(B,X)=>{if(!B||B.bufferView===void 0||!s.bufferViews?.[B.bufferView])return null;let z=B.componentType??5126,ee=K=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${K})`),null);if(z!==5120&&z!==5121&&z!==5122&&z!==5123&&z!==5126)return ee(`componentType ${z}`);if(!(Number(B.count)>=U))return ee(`count ${B.count} < ${U}`);let te=null;try{te=Hn(s,o,{...B,count:U},X)}catch{return ee("out of bounds")}return!te||!te.every(Number.isFinite)?ee("non-finite value"):te},H=j(O,3),Y=j(c,4),q=j(I,3),ne=C?.type==="VEC4"?4:3,ie=j(C,ne),oe=new Float32Array(U*16),he=ve();for(let B=0;B<U;B++){let X=B*3,z=B*4;ot(he,Y?[Y[z],Y[z+1],Y[z+2],Y[z+3]]:[0,0,0,1],H?[H[X],H[X+1],H[X+2]]:[0,0,0],q?[q[X],q[X+1],q[X+2]]:[1,1,1]),oe.set(he,B*16)}if(k.instanceMatrices=oe,ie){let B=new Float32Array(U*3);for(let X=0;X<U;X++)B[X*3]=ie[X*ne],B[X*3+1]=ie[X*ne+1],B[X*3+2]=ie[X*ne+2];k.instanceColors=B}}}for(let L of A.primitives||[]){if(L.extensions?.KHR_draco_mesh_compression){let $=Ft("draco");$&&$.decodePrimitive(s,L,o)}let O=[],c=t.createVertexArray();n.vao=c,n.buffers=O,t.bindVertexArray(c);let I=yi(t,k,O),C=s.accessors[L.attributes.POSITION],U=Number(C?.count??0);if(!Number.isFinite(U)||U<0||p+U>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(p+=U,C?.min&&C?.max){let $=G=>{for(let W=0;W<3;W++){let Z=G[12+W],ae=Z;for(let se=0;se<3;se++){let fe=G[se*4+W]*C.min[se],re=G[se*4+W]*C.max[se];Z+=fe<re?fe:re,ae+=fe>re?fe:re}Z<u[W]&&(u[W]=Z),ae>g[W]&&(g[W]=ae)}};if(k.instanceMatrices&&k.instanceMatrices.length>=16){let G=k.instanceMatrices.length>>4,W=ve();for(let Z=0;Z<G;Z++)Me(W,D,k.instanceMatrices.subarray(Z*16,Z*16+16)),$(W)}else $(D)}let j=jn(t,s,o,L.attributes.POSITION,0,3,O),H=jn(t,s,o,L.attributes.NORMAL,1,3,O),Y=jn(t,s,o,L.attributes.TEXCOORD_0,2,2,O,xi(s,L)),q=0,ne=5123,ie=null;if(L.indices!==void 0){let $=s.accessors[L.indices],G=(s.bufferViews[$.bufferView].byteOffset||0)+($.byteOffset||0);if(q=Number($.count??0),!Number.isFinite(q)||q<0||x+q>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);x+=q,ne=$.componentType===5125?5125:5123;let W=t.createBuffer();O.push(W),t.bindBuffer(34963,W),$.componentType===5125?ie=new Uint32Array(o,G,$.count):$.componentType===5121?ie=Uint16Array.from(new Uint8Array(o,G,$.count)):ie=G%2===0?new Uint16Array(o,G,$.count):new Uint16Array(o.slice(G,G+$.count*2)),t.bufferData(34963,ie,35044)}else q=C.count;let oe={};for(let $ of ge)if($.onBuildPrimitiveVAO){let G=$.onBuildPrimitiveVAO(t,c,L,s,o);G&&(oe[$.name]=G)}t.bindVertexArray(null);let he=s.materials&&L.material!==void 0?s.materials[L.material]:null,{program:B,uniforms:X}=vr(t,L,he),z=Sr(he,m),ee=!!(he?.extensions?.KHR_materials_transmission||oe.materials?.isTransmissive),te=L.extensions?.KHR_materials_variants?.mappings,K=Array.isArray(te)?te.filter($=>$&&typeof $.material=="number"&&Array.isArray($.variants)).map($=>({material:$.material|0,variants:$.variants.map(G=>Number(G)|0)})):void 0;k.primitives.push({vao:c,instanced:I,indexCount:q,indexType:ne,...z,positions:j,normals:H,uvs:Y,indices:ie,buffers:O,materialIndex:L.material,defaultMaterialIndex:L.material,variantMappings:K,primitiveDef:L,programCache:new Map([[L.material??-1,{program:B,uniforms:X}]]),pluginData:oe,customProgram:B,customUniforms:X,isTransmissive:ee})}l.push(k)}isFinite(u[0])||(u=[-1,-1,-1]),isFinite(g[0])||(g=[1,1,1]);let w=[(u[0]+g[0])/2,(u[1]+g[1])/2,(u[2]+g[2])/2],_=Math.max(Math.hypot(g[0]-u[0],g[1]-u[1],g[2]-u[2])/2,.5),N=[...u],P=[...g],E=e.animations;if(e.animationsParsed===!1||!E){for(let T of ge)if(T.onParseGLB?.(e),e.animations){E=e.animations;break}}return E||(E=[]),{meshes:l,bounds:{center:w,radius:_,min:N,max:P},lights:v,animations:E,worldMatrices:b,gpuTextures:m,availableVariants:y}}function Nt(){return typeof performance<"u"?performance.now():Date.now()}function at(t){let e=t.customTarget||t.bounds.center,i=t.currDistance*Math.cos(t.currPhi);return[e[0]+i*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+i*Math.cos(t.currTheta)]}var Pt=class{constructor(t,e,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=ve(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.environmentSource=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=ve(),this.viewMatrix=ve(),this.activeViewMatrix=null,this.modelMatrix=ve(),this.mvpMatrix=ve(),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.selectedMeshNames=new Set,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.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:ve(),rawValueToMeters:.001,format:0},this.container=t;let r,n;if(e&&typeof e.getContext=="function"?(r=e,n=i):(n=e,r=n?.canvas),!r){let l=t.querySelector("canvas");l||(l=document.createElement("canvas"),l.style.cssText="width:100%;height:100%;display:block;touch-action:none",t.prepend(l)),r=l}this.canvas=r;let s=this.opts=n||{};s.clearColor&&(this.clearColor=s.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;s.autoRotate!==void 0?this.autoRotate=s.autoRotate&&!a:a&&(this.autoRotate=!1),s.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=s.autoRotateSpeed),s.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(s.autoRotateDelay)||0)),s.exposure!==void 0&&(this.exposure=$n(s.exposure)),s.camera&&this.setInitialCamera(s.camera.theta,s.camera.phi,s.camera.distance,s.camera.zoom),(s.shadowIntensity!==void 0||s.shadowSoftness!==void 0)&&this.setShadow(s.shadowIntensity??0,s.shadowSoftness),s.shadowMaps!==void 0&&(this.shadowMaps=s.shadowMaps),s.toneMapping!==void 0&&(this.toneMapping=Wn(s.toneMapping)),s.autoplay!==void 0&&(this.autoplay=s.autoplay),s.animationName!==void 0&&(this.animationName=s.animationName),s.variantName!==void 0&&(this.activeVariantName=s.variantName||null),s.fieldOfView!==void 0&&(this.fov=s.fieldOfView*Math.PI/180),s.distanceMode!==void 0&&(this.distanceMode=s.distanceMode),s.cameraTarget!==void 0&&(this.setTarget(s.cameraTarget[0],s.cameraTarget[1],s.cameraTarget[2]),this.initialCustomTarget=[...s.cameraTarget]),(s.minCameraOrbit||s.maxCameraOrbit)&&this.setOrbitLimits({minTheta:s.minCameraOrbit?.theta,maxTheta:s.maxCameraOrbit?.theta,minPhi:s.minCameraOrbit?.phi,maxPhi:s.maxCameraOrbit?.phi,minDistance:s.minCameraOrbit?.distance,maxDistance:s.maxCameraOrbit?.distance});let o=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!o)throw new Error("WebGL2 not supported");this.gl=o,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),s.environmentImage&&this.setEnvironmentImage(s.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&s.autoStart!==!1&&this.start()}static registerDecoder(t,e){mi(t,e)}static getDecoder(t){return Ft(t)}setupContextLossHandling(){let t=this.canvas;typeof t?.addEventListener=="function"&&(this.boundContextLost=e=>{e.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),t.addEventListener("webglcontextlost",this.boundContextLost),t.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let t=this.gl,e=Kn();this.renderProg=st(t,Xn,e.fs),this.pickProg=st(t,fi,pi),this.uRender=kt(t,this.renderProg,e.uniforms),this.uPick=kt(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}recompileRenderProgram(){if(this.contextLost)return;let t=this.gl,e=Kn();this.renderProg&&t.deleteProgram(this.renderProg),this.renderProg=st(t,Xn,e.fs),this.uRender=kt(t,this.renderProg,e.uniforms);for(let i of this.meshes)for(let r of i.primitives)r.customProgram&&(t.deleteProgram(r.customProgram),r.programCache?.clear(),this.applyPrimitiveProgram(r,r.materialIndex,this.gltf?.materials?.[r.materialIndex??-1]??null))}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let e of ge)e.onContextRestored?.(t,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let t=this.gl;typeof t.createFramebuffer=="function"&&(this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer(),this.resizePickingFbo(this.canvas.width,this.canvas.height),t.bindFramebuffer(36160,this.pickFbo),t.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),t.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),t.bindFramebuffer(36160,null))}resizePickingFbo(t,e){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,t),n=Math.max(1,e);this.pickFboWidth=r,this.pickFboHeight=n,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,n,0,6408,5121,null),i.texParameteri(3553,10241,9728),i.texParameteri(3553,10240,9728),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,n)}loadGLBData(t,e){let{meshes:i,bounds:r,lights:n,animations:s,worldMatrices:a,gpuTextures:o,availableVariants:l}=br(this.gl,t,e,()=>this.render());this.lastGlbData=t,this.lastLimits=e,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=n,this.animations=s||[],this.worldMatrices=a||[],this.gpuTextures=o||[],this.availableVariants=l||[],this.gltf=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=(t.gltf?.nodes||[]).map(b=>({t:[b.translation?.[0]??0,b.translation?.[1]??0,b.translation?.[2]??0],r:[b.rotation?.[0]??0,b.rotation?.[1]??0,b.rotation?.[2]??0,b.rotation?.[3]??1],s:[b.scale?.[0]??1,b.scale?.[1]??1,b.scale?.[2]??1]})),this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let b of ge)b.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let y=t.exposure??t.gltf?.extras?.exposure??t.gltf?.asset?.extras?.exposure;y!==void 0&&(this.exposure=$n(y));let f=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.environmentIntensity;f!==void 0&&(this.envIntensity=Math.max(0,Number(f)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(t){this.loadGLBData(xr(t))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let t of ge)t.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(Ut(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let i=Ut(t),{meshes:r}=br(this.gl,i,Mr,()=>this.render());if(e)for(let n of r)n.transform[12]+=e[0],n.transform[13]+=e[1],n.transform[14]+=e[2],Fe(n.normalMatrix,n.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(t,e,i,r=1){this.clearColor=[t,e,i,r]}updateMeshTransforms(t){for(let e=0;e<this.meshes.length;e++){let i=this.meshes[e],r=t instanceof Map?t.get(i.name)??t.get(e):Array.isArray(t)?t[e]:t&&typeof t=="object"?Object.prototype.hasOwnProperty.call(t,i.name)?t[i.name]:Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0:void 0;r&&r.length===16&&(i.transform.set(r),Fe(i.normalMatrix,i.transform))}}bindLights(t=this.uRender){let e=this.gl,i=[.28,.28,.28],r=[0,0,0,0,0,0,0,1,0],n=!1,s=[],a=[],o=[],l=[],y=[],f=[];for(let b of this.lights){let h=b.color||[1,1,1],d=b.intensity!==void 0?b.intensity:1;if(b.type==="ambient")i=[h[0]*d,h[1]*d,h[2]*d];else if(b.type==="hemisphere"){n=!0;let v=b.groundColor||[.2,.2,.2],M=d*.65;for(let g=0;g<3;g++)r[g]+=h[g]*M,r[g+3]+=v[g]*M;let m=b.position||[0,1,0],u=Math.hypot(m[0],m[1],m[2]);u>1e-5&&(r[6]=m[0]/u,r[7]=m[1]/u,r[8]=m[2]/u)}else if(b.type==="directional"&&s.length<6){let v=b.direction||[.5,1,.8];s.push(v[0],v[1],v[2]),a.push(h[0]*d,h[1]*d,h[2]*d)}else if((b.type==="point"||b.type==="spot")&&o.length<6){let v=b.position||[0,0,0];if(o.push(v[0],v[1],v[2]),l.push(h[0]*d,h[1]*d,h[2]*d),b.type==="spot"){let M=b.direction||[0,-1,0],m=Math.max(.01,Math.min(Math.PI/2,b.outerConeAngle??Math.PI/3)),u=Math.max(0,Math.min(m-1e-4,b.innerConeAngle??0));y.push(M[0],M[1],M[2]),f.push(Math.cos(u),Math.cos(m))}else y.push(0,-1,0),f.push(-2,-3)}}s.length===0&&!n&&(s.push(.5,1,.8),a.push(1,1,1)),e.uniform3fv(t.uAmbientColor,i),t.uHemi&&e.uniformMatrix3fv(t.uHemi,!1,r),e.uniform1i(t.uNumDirLights,s.length/3),s.length>0&&(e.uniform3fv(t.uDirLightDir,s),e.uniform3fv(t.uDirLightColor,a)),e.uniform1i(t.uNumPointLights,o.length/3),o.length>0&&(e.uniform3fv(t.uPointLightPos,o),e.uniform3fv(t.uPointLightColor,l),t.uPointLightSpotDir&&e.uniform3fv(t.uPointLightSpotDir,y),t.uPointLightSpotCone&&e.uniform2fv(t.uPointLightSpotCone,f)),e.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=$n(t)}getExposure(){return this.exposure}setShadow(t,e){this.shadowIntensity=Math.max(0,Math.min(1,Number(t)||0)),e!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(e)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(t){this.toneMapping=Wn(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){this.environmentSource=t&&typeof t=="object"?t:null;for(let e of ge)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t),this.render();return}this.render()}async setSkyboxImage(t){for(let e of ge)if(e.setSkyboxImage){await e.setSkyboxImage(this,t);return}}setInteractive(t){this.interactive=t}isInteractive(){return this.interactive}getCameraOrbit(){let t=this.currTheta,e=this.currPhi,i=this.currDistance;return{theta:t,phi:e,radius:i,toString(){return`${t.toFixed(4)}rad ${e.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let t=this.customTarget||this.bounds.center;return{x:t[0],y:t[1],z:t[2],toString(){return`${t[0].toFixed(4)}m ${t[1].toFixed(4)}m ${t[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let t=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return t.map((e,i)=>{let r=this.meshes.flatMap(f=>f.primitives.filter(b=>b.materialIndex===i||t.length===1&&b.materialIndex===void 0)),n=r[0],s=n?[...n.baseColor]:e.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],a=n?n.metallic:e.pbrMetallicRoughness?.metallicFactor??.1,o=n?n.roughness:e.pbrMetallicRoughness?.roughnessFactor??.5,l=(f,b,h)=>{y[f]=h,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness[f]=h);for(let d of r)d[b]=h;this.render()},y={baseColorFactor:s,metallicFactor:a,roughnessFactor:o,setBaseColorFactor:f=>l("baseColorFactor","baseColor",[f[0],f[1],f[2],f[3]??1]),setMetallicFactor:f=>l("metallicFactor","metallic",f),setRoughnessFactor:f=>l("roughnessFactor","roughness",f)};return{name:e.name||`Material_${i}`,pbrMetallicRoughness:y}})}playAnimation(t){if(this.animations.length!==0){if(t){let e=this.animations.find(i=>i.name===t);e&&(this.currentClip=e)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(t=>t.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(t){let e=this.applyVariantMaterial(t);return e&&this.gl&&this.render(),e}applyVariantMaterial(t){let e=t===null||t==="",i=-1;if(e)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(t),i<0)return!1;this.activeVariantName=t}let r=this.gltf?.materials;if(!Array.isArray(r))return e;for(let n of this.meshes)for(let s of n.primitives){let a=s.defaultMaterialIndex;if(!e&&Array.isArray(s.variantMappings)){for(let l of s.variantMappings)if(Array.isArray(l.variants)&&l.variants.includes(i)){a=l.material;break}}let o=a!==void 0?r[a]:void 0;s.materialIndex=o?a:void 0,Object.assign(s,Sr(o,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,o??null)}return!0}applyPrimitiveProgram(t,e,i){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let r=e??-1,n=t.programCache.get(r);n||(n=vr(this.gl,{...t.primitiveDef,material:e},i),t.programCache.set(r,n)),t.customProgram=n.program,t.customUniforms=n.uniforms,t.pluginData&&(t.pluginData.materials=t.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(t){this.autoplay=t,t?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(t){this.animationName=t,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(t)}evaluateAnimation(t){for(let e of ge)if(e.evaluateAnimation){e.evaluateAnimation(this,t);return}}setTarget(t,e,i){this.customTarget=[t,e,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(t){let e=Math.max(10,Math.min(90,t));this.fov=e*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(t){if(this.distanceMode=t,!this.customDistance){let e=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=e,this.targetDistance=e,this.currDistance=e,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(t){let e=Math.PI/180,i=Math.PI*.48;t.minTheta!==void 0&&(this.minTheta=t.minTheta*e),t.maxTheta!==void 0&&(this.maxTheta=t.maxTheta*e),t.minPhi!==void 0&&(this.minPhi=Math.max(-i,t.minPhi*e)),t.maxPhi!==void 0&&(this.maxPhi=Math.min(i,t.maxPhi*e)),t.minDistance!==void 0&&(this.minDistanceLimit=t.minDistance),t.maxDistance!==void 0&&(this.maxDistanceLimit=t.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){let t=180/Math.PI;return{minTheta:isFinite(this.minTheta)?this.minTheta*t:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*t:void 0,minPhi:this.minPhi*t,maxPhi:this.maxPhi*t,minDistance:this.minDistanceLimit??void 0,maxDistance:this.maxDistanceLimit??void 0}}clampTheta(t){return Math.max(this.minTheta,Math.min(this.maxTheta,t))}clampPhi(t){return Math.max(this.minPhi,Math.min(this.maxPhi,t))}clampDistance(t){let e=this.bounds?.radius;return Math.max(this.minDistanceLimit??(e?e*.5:.1),Math.min(this.maxDistanceLimit??(e?e*8:100),t))}setCamera(t,e,i,r){t!==void 0&&(this.targetTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.targetPhi=this.clampPhi(e*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(t,e,i,r){t!==void 0&&(this.initialTheta=this.targetTheta=this.currTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.initialPhi=this.targetPhi=this.currPhi=this.clampPhi(e*Math.PI/180));let n=i!==void 0&&i>0?i:r!==void 0&&r>0?this.bounds.radius*2.5/r:null;this.customDistance=n!==null,this.initialDistance=this.targetDistance=this.currDistance=this.clampDistance(n??(this.distanceMode==="absolute"?3:this.bounds.radius*2.5)),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.targetDistance=this.clampDistance(this.initialDistance??this.bounds.radius*2.5),this.customTarget=this.initialCustomTarget?[...this.initialCustomTarget]:null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(t,e){let i=ve();Me(i,this.projMatrix,this.viewMatrix);let r=(P,E,T=1)=>[P[0]*E[0]+P[4]*E[1]+P[8]*E[2]+P[12]*T,P[1]*E[0]+P[5]*E[1]+P[9]*E[2]+P[13]*T,P[2]*E[0]+P[6]*E[1]+P[10]*E[2]+P[14]*T,P[3]*E[0]+P[7]*E[1]+P[11]*E[2]+P[15]*T],n=this.modelRootMatrix,[s,a,o]=n?r(n,t):t,[l,y,f]=e?n?r(n,e,0):e:[0,0,0],[b,h,d,v]=r(i,[s,a,o]);if(v<=1e-4)return{x:0,y:0,z:1,visible:!1};let M=b/v,m=h/v,u=d/v,g=this.canvas.getBoundingClientRect(),p=g.width||this.canvas.clientWidth||this.canvas.width||300,x=g.height||this.canvas.clientHeight||this.canvas.height||150,w=(M*.5+.5)*p,_=(-m*.5+.5)*x,N=M>=-1.1&&M<=1.1&&m>=-1.1&&m<=1.1&&u>=-1&&u<=1;if(N&&e){let[P,E,T]=at(this),S=[s-P,a-E,o-T];l*S[0]+y*S[1]+f*S[2]>.05&&(N=!1)}return{x:w,y:_,z:u,visible:N}}setSelectedMesh(t){this.setSelectedMeshes([t])}setSelectedMeshes(t){this.selectedMeshNames=new Set(t.filter(Boolean))}getSelectedMesh(){return[...this.selectedMeshNames][0]||""}setupEvents(){let t=this.canvas,e=Nt;this.boundContextMenu=i=>{i.preventDefault()},t.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=e(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,t.setPointerCapture(i.pointerId))},t.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=e();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},n=i.clientX-r.x,s=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(n,s),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],l=this.customTarget?[...this.customTarget]:[...this.bounds.center],y=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;l[0]+=(-n*a[0]+s*o[0])*y,l[1]+=(-n*a[1]+s*o[1])*y,l[2]+=(-n*a[2]+s*o[2])*y,this.customTarget=l}else this.targetTheta=this.clampTheta(this.targetTheta-n*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},t.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=e(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{t.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=t.getBoundingClientRect(),n=Math.floor((i.clientX-r.left)*(t.width/Math.max(r.width,1))),s=Math.floor((i.clientY-r.top)*(t.height/Math.max(r.height,1)));this.performMeshPick(n,s,!0)}},t.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=e();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},t.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),t.tabIndex!==void 0&&t.tabIndex<0&&(t.tabIndex=0),t.getAttribute?.("role")||t.setAttribute?.("role","region"),t.getAttribute?.("aria-label")||t.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=e(),i.preventDefault()}},t.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let t=(i,r,n)=>{this[n]&&(i.removeEventListener(r,this[n]),this[n]=null)},e=this.canvas;for(let[i,r]of[["webglcontextlost","boundContextLost"],["webglcontextrestored","boundContextRestored"],["contextmenu","boundContextMenu"],["pointerdown","boundPointerDown"],["pointermove","boundPointerMove"],["pointerup","boundPointerUp"],["wheel","boundWheel"],["keydown","boundKeyDown"]])t(e,i,r);t(this.container,"setCamera","boundSetCamera"),t(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(t,e){let i=this.canvas,r=i.getBoundingClientRect(),n=i.width||300,s=i.height||300,a=r.width>0?Math.floor((t-r.left)*(n/r.width)):Math.floor(t),o=r.height>0?Math.floor((e-r.top)*(s/r.height)):Math.floor(e);return this.performMeshPick(a,o,!1)}performMeshPick(t,e,i=!0){if(this.meshes.length===0)return null;let r=this.gl,n=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);t=this.mapStereoPickX(t,n);let a=ve();Me(a,this.projMatrix,this.viewMatrix);let o=[],l=Math.max(0,Math.min(n-1,t)),y=Math.max(0,Math.min(s-1,s-1-e));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==n||this.pickFboHeight!==s)&&this.resizePickingFbo(n,s),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,n,s),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let w=0;w<this.meshes.length;w++){let _=this.meshes[w];if(_.visible===!1||_.isPluginMesh)continue;let N=w+1,P=(N&255)/255,E=(N>>8&255)/255,T=(N>>16&255)/255;r.uniform4f(this.uPick.uColorId,P,E,T,1),Me(this.modelMatrix,this.modelRootMatrix,_.transform);let S=_.instanceMatrices;if(S&&S.length>=16){let A=S.length>>4,D=ve();for(let R of _.primitives){r.bindVertexArray(R.vao);for(let F=0;F<A;F++)Me(D,this.modelMatrix,S.subarray(F*16,F*16+16)),Me(this.mvpMatrix,a,D),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),It(r,R)}}else{Me(this.mvpMatrix,a,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let A of _.primitives)r.bindVertexArray(A.vao),It(r,A)}}let p=new Uint8Array(4);r.readPixels(l,y,1,1,6408,5121,p),r.bindFramebuffer(36160,null);let x=p[0]+(p[1]<<8)+(p[2]<<16);x>0&&x<=this.meshes.length&&(o=[this.meshes[x-1]])}o.length===0&&(o=this.meshes.filter(p=>p.visible!==!1));let f=null,b=1/0,h=[0,0,0],d=[0,1,0],[v,M,m]=at(this),u=ve();for(let p of o){Me(u,this.modelRootMatrix,p.transform);let x=p.instanceMatrices,w=x&&x.length>=16?x.length>>4:1;for(let _=0;_<w;_++){x&&x.length>=16?Me(this.modelMatrix,u,x.subarray(_*16,_*16+16)):this.modelMatrix.set(u),Me(this.mvpMatrix,a,this.modelMatrix);let N=ve();if(!dr(N,this.mvpMatrix))continue;let P=(l+.5)/n*2-1,E=(y+.5)/s*2-1,T=[0,0,0],S=[0,0,0];Vn(T,P,E,-1,N),Vn(S,P,E,1,N);let A=S[0]-T[0],D=S[1]-T[1],R=S[2]-T[2],F=Math.hypot(A,D,R)||1,k=A/F,V=D/F,L=R/F,O={distance:1/0,point:[0,0,0],normal:[0,1,0]};for(let c of p.primitives){if(!c.positions)continue;let I=c.positions,C=c.indices,U=Math.floor(C?C.length/3:I.length/9);for(let j=0;j<U;j++){let H=(C?C[j*3]:j*3)*3,Y=(C?C[j*3+1]:j*3+1)*3,q=(C?C[j*3+2]:j*3+2)*3;fr(T[0],T[1],T[2],k,V,L,I[H],I[H+1],I[H+2],I[Y],I[Y+1],I[Y+2],I[q],I[q+1],I[q+2],O,1e-4)}}if(isFinite(O.distance)){let c=O.point[0],I=O.point[1],C=O.point[2],U=this.modelMatrix,j=U[0]*c+U[4]*I+U[8]*C+U[12],H=U[1]*c+U[5]*I+U[9]*C+U[13],Y=U[2]*c+U[6]*I+U[10]*C+U[14],q=j-v,ne=H-M,ie=Y-m,oe=Math.hypot(q,ne,ie);if(oe<b){Fe(this.normalMatrix,this.modelMatrix);let he=this.normalMatrix,B=O.normal[0],X=O.normal[1],z=O.normal[2],ee=he[0]*B+he[3]*X+he[6]*z,te=he[1]*B+he[4]*X+he[7]*z,K=he[2]*B+he[5]*X+he[8]*z,$=Math.hypot(ee,te,K)||1;ee/=$,te/=$,K/=$,ee*q+te*ne+K*ie>0&&(ee=-ee,te=-te,K=-K);let G=W=>Math.round(W*1e3)/1e3;f=p,b=G(oe),h=[G(j),G(H),G(Y)],d=[G(ee),G(te),G(K)]}}}}if(!f)return null;let g={meshIndex:this.meshes.indexOf(f),meshName:f.name,nodeIndex:f.nodeIndex,distance:b,hitPoint:h,normal:d,screenX:t,screenY:e};if(i){for(let p of ge)p.onMeshSelect?.(this,g);this.opts.onMeshClick&&this.opts.onMeshClick(g),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:g}))}return g}mapStereoPickX(t,e){if(!this.stereoSBS||this.xrSessionActive||e<2)return t;let i=Math.max(1,Math.floor(e*.5)),r=t>=i,n=r?t-i:t,s=r?Math.max(1,e-i):i,a=(n+.5)/s*2-1;return Math.floor((a*.5+1)*.5*e)}setStereoSBS(t){this.stereoSBS=!!t,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let t=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),e=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Bn(this.projMatrix,this.fov,t,.1,e);let i=this.customTarget||this.bounds.center;it(this.viewMatrix,at(this),i,[0,1,0]),Me(this.mvpMatrix,this.projMatrix,this.viewMatrix),Fe(this.normalMatrix,this.modelMatrix)}resize(){let t=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),e=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(e.width*t)),r=Math.max(1,Math.floor(e.height*t));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(t){let e=this.xrSessionActive;if(this.xrSessionActive=t,e&&!t){this.xrDepthState.enabled=!1;for(let i of ge)i.onXRSessionEnd?.(this);if(this.lastTime=Nt(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let e of ge)e.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=Nt();let t=e=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((e-this.lastTime)/1e3,0),.1);if(this.lastTime=e,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(t))};this.animFrameId=requestAnimationFrame(t)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(t){this.autoRotate=t}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(t){this.autoRotateSpeed=t}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(t){this.autoRotateDelay=Math.max(0,Number(t)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(t=0){this.turntableRotation=Number(t)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let t=Math.cos(this.turntableRotation),e=Math.sin(this.turntableRotation),[i,,r]=this.bounds.center;this.modelRootMatrix.set([t,0,-e,0,0,1,0,0,e,0,t,0,i-(t*i+e*r),0,r-(-e*i+t*r),1])}setVisible(t){this.isVisible=t}update(t){for(let s of ge)s.onUpdate?.(this,t);let e=Nt();if(!this.isPointerDown&&this.autoRotate&&e-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let s of ge)s.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),n=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(n-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=n;let s={theta:i,phi:r,zoom:n,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(t,e,i,r,n=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let a=t?.transform?.inverse?.matrix||this.viewMatrix,o=t?.projectionMatrix||this.projMatrix,l=t?.transform?.position,y=l?[l.x,l.y,l.z]:[0,1.6,0];e&&this.modelRootMatrix.set(e),this.render({viewMatrix:a,projMatrix:o,eyePos:y,viewport:r,eye:t?.eye||"none",clear:s>0?!1:t?.eye!=="right",isAR:n})}render(t){if(this.contextLost)return;if(!t&&this.stereoSBS){let _=Math.max(2,this.canvas.width||2),N=Math.max(1,this.canvas.height||1),P=Math.max(1,Math.floor(_*.5)),E=Math.max(1,_-P),T=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),S=this.customTarget||this.bounds.center,[A,D,R]=at(this),F=Math.cos(this.currTheta),k=-Math.sin(this.currTheta),V=.032;for(let L of[-1,1]){let O=ve(),c=ve(),I=L<0?P:E,C=[A+L*F*V,D,R+L*k*V];Bn(O,this.fov,I/N,.1,T),it(c,C,[S[0]+L*F*V*.25,S[1],S[2]+L*k*V*.25],[0,1,0]),this.render({viewMatrix:c,projMatrix:O,eyePos:C,viewport:[L<0?0:P,0,I,N],eye:L<0?"left":"right",clear:L<0,isAR:!1})}this.gl.viewport(0,0,_,N);return}let e=this.gl,[i,r,n,s]=t?.viewport||[0,0,this.canvas.width,this.canvas.height];if(e.viewport(i,r,n,s),e.enable(2929),!t||t.clear!==!1){let _=t?.isAR?[0,0,0,0]:this.clearColor;e.clearColor(_[0],_[1],_[2],_[3]),e.clear(16640)}let a=ve(),o=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o;let l=t?.projMatrix??this.projMatrix;Me(a,l,o);let y=de(),f=y.xrDepthShader,b=ui(this.toneMapping),[h,d,v]=t?t.eyePos:at(this);for(let _ of ge)_.onBeforeDrawScene?.(this,e,a,[h,d,v],b);let M=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&M===0){y.gpuSceneAccelerator?.hideLayer?.(this);return}let m=t?.eye||"none",u=!t||t.clear!==!1;if(!this.xrSessionActive&&y.gpuSceneAccelerator?.renderScene(this,a,l,o,[h,d,v],b,[i,r,n,s],m,u,!!t?.isAR)){u&&!this.skyboxTexture&&(e.clearColor(0,0,0,0),e.clear(16384));for(let _ of ge)_.name.includes("webgpu")&&_.onAfterRender?.(e,this,a,m,[i,r,n,s],l);return}let g=!1,p=M>0?[...this.backdropMeshes,...this.meshes]:this.meshes,x=(_,N,P,E)=>{N?(e.activeTexture(33984+_),e.bindTexture(3553,N),e.uniform1i(P,_),e.uniform1i(E,1)):e.uniform1i(E,0)},w=_=>{for(let N=0;N<p.length;N++){let P=p[N];if(P.visible===!1)continue;let E=this.selectedMeshNames.has(P.name);if(N<M||P.worldSpace===!0||P.name==="__xr_reticle__")this.modelMatrix.set(P.transform);else{Me(this.modelMatrix,this.modelRootMatrix,P.transform);let F=!t&&(P.extras?.xr?.billboard??P.userData?.xr?.billboard);if(F){let k=this.modelMatrix,V=Math.hypot(k[0],k[1],k[2])||1,L=Math.hypot(k[4],k[5],k[6])||1,O=Math.hypot(k[8],k[9],k[10])||1,c=F==="y"||F==="cylindrical"||F==="capsule",I=h-k[12],C=v-k[14],U=Math.hypot(I,C),j=U>1e-5?I/U:0,H=U>1e-5?C/U:1;k.set(c?[H*V,0,-j*V,0,0,L,0,0,j*O,0,H*O]:[o[0]*V,o[4]*V,o[8]*V,0,o[1]*L,o[5]*L,o[9]*L,0,o[2]*O,o[6]*O,o[10]*O])}}Me(this.mvpMatrix,a,this.modelMatrix),Fe(P.normalMatrix,this.modelMatrix);let T=P.extras?.xr?.stereo||P.userData?.xr?.stereo,S=0,A=0,D=1,R=1;T==="sbs"?(D=.5,S=m==="right"?.5:0):T==="ou"&&(R=.5,A=m==="right"?.5:0);for(let F of P.primitives){let k=!!F.isTransmissive;if(!_&&k){g=!0;continue}if(_&&!k)continue;let V=F.customProgram||this.renderProg,L=F.customUniforms||this.uRender;e.useProgram(V),e.vertexAttrib3f(3,0,0,0),L.uInstanced&&e.uniform1i(L.uInstanced,0),e.uniform1i(L.uToneMapping,b),e.uniform1f(L.uEnvIntensity,this.envIntensity),L.uExposure&&e.uniform1f(L.uExposure,this.exposure),e.uniform3f(L.uCameraPos,h,d,v),e.uniform1f(L.uEmissive,E?1:0),e.uniformMatrix4fv(L.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(L.uModel,!1,this.modelMatrix),e.uniformMatrix3fv(L.uNormalMatrix,!1,P.normalMatrix),L.uUvTransform&&e.uniform4f(L.uUvTransform,S,A,D,R),L.uViewportSize&&e.uniform2f(L.uViewportSize,Math.max(1,n),Math.max(1,s)),f?.bind(e,L,this.xrDepthState,o,[i,r,Math.max(1,n),Math.max(1,s)]),y.shadowMapShader?.bind(e,L,this,P),x(4,this.environmentTexture,L.uEnvironmentMap,L.uHasEnvironmentMap),this.bindLights(L),L.uSectionEnabled&&e.uniform1i(L.uSectionEnabled,0);for(let c of ge)c.onBeforeDrawPrimitive?.(e,V,F,P,this.worldMatrices||[],this.gltf);e.uniform4fv(L.uBaseColor,F.baseColor),e.uniform1f(L.uMetallic,F.metallic),e.uniform1f(L.uRoughness,F.roughness),L.uClearcoat&&e.uniform2f(L.uClearcoat,F.clearcoat??0,F.clearcoatRoughness??.04),x(0,F.texture,L.uBaseColorTexture,L.uHasTexture),x(1,F.metallicRoughnessTexture,L.uMetallicRoughnessTexture,L.uHasMetallicRoughnessTexture),x(2,F.normalTexture,L.uNormalTexture,L.uHasNormalTexture),F.normalTexture&&e.uniform1f(L.uNormalScale,F.normalScale),x(3,F.occlusionTexture,L.uOcclusionTexture,L.uHasOcclusionTexture),F.occlusionTexture&&e.uniform1f(L.uOcclusionStrength,F.occlusionStrength),e.uniform3fv(L.uEmissiveFactor,F.emissiveFactor),x(8,F.emissiveTexture,L.uEmissiveTexture,L.uHasEmissiveTexture),e.bindVertexArray(F.vao);let O=P.instanceMatrices;if(F.instanceCount!==void 0)e.drawElementsInstanced(4,F.indexCount,F.indexType,0,F.instanceCount);else if(O&&O.length>=16&&F.instanced&&L.uInstanced&&L.uViewProj){let c=O.length>>4;e.uniform1i(L.uInstanced,1),e.uniformMatrix4fv(L.uViewProj,!1,a),F.indices?e.drawElementsInstanced(4,F.indexCount,F.indexType,0,c):e.drawArraysInstanced(4,0,F.indexCount,c),e.uniform1i(L.uInstanced,0)}else if(O&&O.length>=16){let c=O.length>>4,I=P.instanceColors,C=ve(),U=new Float32Array(9);for(let j=0;j<c;j++){if(Me(C,this.modelMatrix,O.subarray(j*16,j*16+16)),Me(this.mvpMatrix,a,C),Fe(U,C),e.uniformMatrix4fv(L.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(L.uModel,!1,C),e.uniformMatrix3fv(L.uNormalMatrix,!1,U),I){let H=F.baseColor,Y=j*3;e.uniform4fv(L.uBaseColor,[H[0]*I[Y],H[1]*I[Y+1],H[2]*I[Y+2],H[3]])}It(e,F)}}else It(e,F)}}};if(w(!1),g){for(let _ of ge)_.onBeforeTransmissivePass?.(e,this);w(!0)}for(let _ of ge)_.onAfterRender?.(e,this,a,m,[i,r,n,s],l)}disposeMeshListGpuResources(t,e){wr(this.gl,t,e)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let t=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let e of ge)e.onDestroy?.(t,this);this.environmentTexture&&(t.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&t.deleteProgram(this.renderProg),this.pickProg&&t.deleteProgram(this.pickProg),this.pickFbo&&t.deleteFramebuffer(this.pickFbo),this.pickTexture&&t.deleteTexture(this.pickTexture),this.pickDepth&&t.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};Pt.registerPlugin=mr,Pt.getRegisteredPlugins=hr;function Mi(t){return t+3&-4}var J=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function qn(t,e){let i=e,r=1;for(;t.has(i);)i=`${e}_${r++}`;return t.add(i),i}function Ar(t,e,i){let r=Math.hypot(t,e,i)||1,n=t/r,s=e/r,a=-(i/r);if(a<-.999999)return[0,1,0,0];let o=Math.sqrt((1+a)*2);return[s/o,-n/o,0,o*.5]}function Tr(t,e=0){let[i,r,n,,s,a,o,,l,y,f,,b,h,d]=Array.from({length:15},(O,c)=>J(t[e+c],c%5===0?1:0)),v=Math.hypot(i,r,n),M=Math.hypot(s,a,o),m=Math.hypot(l,y,f);i*(a*f-y*o)-s*(r*f-y*n)+l*(r*o-a*n)<0&&(v=-v);let u=Math.abs(v)>1e-8?1/v:0,g=Math.abs(M)>1e-8?1/M:0,p=Math.abs(m)>1e-8?1/m:0,x=i*u,w=r*u,_=n*u,N=s*g,P=a*g,E=o*g,T=l*p,S=y*p,A=f*p,D=x+P+A,R=0,F=0,k=0,V=1;if(D>0){let O=.5/Math.sqrt(D+1);V=.25/O,R=(E-S)*O,F=(T-_)*O,k=(w-N)*O}else if(x>P&&x>A){let O=2*Math.sqrt(Math.max(0,1+x-P-A));O>1e-8&&(V=(E-S)/O,R=.25*O,F=(N+w)/O,k=(T+_)/O)}else if(P>A){let O=2*Math.sqrt(Math.max(0,1+P-x-A));O>1e-8&&(V=(T-_)/O,R=(N+w)/O,F=.25*O,k=(E+S)/O)}else{let O=2*Math.sqrt(Math.max(0,1+A-x-P));O>1e-8&&(V=(w-N)/O,R=(T+_)/O,F=(E+S)/O,k=.25*O)}let L=Math.hypot(R,F,k,V);return L>1e-8&&Number.isFinite(L)?(R/=L,F/=L,k/=L,V/=L):(R=0,F=0,k=0,V=1),{t:[b,h,d],r:[R,F,k,V],s:[v,M,m]}}function Si(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}var Ie=(t,e,i,r)=>typeof t=="number"&&Number.isFinite(t)?Math.max(e,Math.min(i,t)):r;function Er(t){let e=t?.audioEmitter??t?.spatialAudio??(typeof t?.audio=="object"&&t.audio&&("preset"in t.audio||"distanceModel"in t.audio||"coneInnerAngle"in t.audio||"maxDistance"in t.audio||"volume"in t.audio)?t.audio:typeof t?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(t.audio)?{preset:t.audio}:void 0);if(!e||typeof e=="object"&&e.enabled===!1)return null;let i=typeof e=="string"?{preset:e}:e,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,n=typeof i.preset=="string"?i.preset:void 0;return!r&&!n?null:{ae:i,src:r,preset:n,volume:Ie(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function wi(t){let e=t?.material,i=e?._presetMaps?.map;if(!i||i!==e.map)return null;let r=/^ai_([0-9a-f]{16})_albedo$/.exec(String(i.name??""));return r?r[1]:null}function Je(t,e){return Rr(t,e)[0]}function Rr(t,e){t.updateMatrixWorld(!0);let i=[],r=0,n=[],s=[],a=[],o=[],l=new Set,y=[],f=[],b=new Map,h=[],d=[],v=[],M=new Map,m=[],u=[],g=[],p=!1;function x(c){let I=b.get(c);if(I!==void 0)return I;I=f.length,b.set(c,I);let C=c,U=C.color?.r??1,j=C.color?.g??1,H=C.color?.b??1,Y=C.opacity??1,q={baseColorFactor:[U,j,H,Y],metallicFactor:C.metalness??0,roughnessFactor:C.roughness??.5},ne={},ie=re=>{if(!re)return;let Ae=(typeof re=="string"?re:typeof re.source=="string"?re.source:typeof re.image=="string"?re.image:"").trim();if(!Ae||/[\x00-\x1f\x7f\\]|\.\./.test(Ae)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(Ae)||!Ae.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(Ae)))return;let le=M.get(Ae);if(le===void 0){let me=h.length;h.push({uri:Ae}),d.length===0&&d.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),le=v.length,v.push({sampler:0,source:me}),M.set(Ae,le)}return{index:le}},oe=C._packPbr?.(),he=ie(C.map);he&&(q.baseColorTexture=he);let B=ie(oe?.mrUri||C.roughnessMap||C.metalnessMap);B&&(q.metallicRoughnessTexture=B);let X=C.map?.avgColor;Array.isArray(X)&&X.length>=3&&(ne.avgColor=[X[0],X[1],X[2]]);let z=ie(oe?.normUri||C.normalMap),ee=C.normalScale,te=oe?.normUri?oe.normScale??1:typeof ee=="number"?Math.max(0,J(ee,1)):ee?Math.max(0,(J(ee.x,1)+J(ee.y,1))*.5):1;z&&te!==1&&(z.scale=te);let K=ie(C.emissiveMap),$=ie(C.aoMap),G=Math.max(0,Math.min(1,J(C.aoMapIntensity,1)));$&&G!==1&&($.strength=G);let W={name:C.name||"",pbrMetallicRoughness:q,doubleSided:C.side===2||!!C.doubleSided,...Y<1||C.transparent?{alphaMode:"BLEND"}:{},...z?{normalTexture:z}:{},...K?{emissiveTexture:K}:{},...$?{occlusionTexture:$}:{},...Object.keys(ne).length>0?{extras:ne}:{}},Z=Math.max(0,J(C.emissiveIntensity,1)),ae=C.emissive&&(C.emissive.r>0||C.emissive.g>0||C.emissive.b>0);(ae||K&&!C._em&&Z>0)&&(W.emissiveFactor=ae?[C.emissive.r*Z,C.emissive.g*Z,C.emissive.b*Z]:[Z,Z,Z]);let se={};C.clearcoat&&C.clearcoat>0&&(se.KHR_materials_clearcoat={clearcoatFactor:C.clearcoat,clearcoatRoughnessFactor:C.clearcoatRoughness||0}),C.sheen&&C.sheen>0&&(se.KHR_materials_sheen={sheenColorFactor:C.sheenColor?[C.sheenColor.r,C.sheenColor.g,C.sheenColor.b]:[1,1,1],sheenRoughnessFactor:C.sheenRoughness||0}),C.transmission&&C.transmission>0&&(se.KHR_materials_transmission={transmissionFactor:C.transmission}),C.thickness&&C.thickness>0&&(se.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&&(se.KHR_materials_ior={ior:C.ior}),C.dispersion&&C.dispersion>0&&(se.KHR_materials_dispersion={dispersion:C.dispersion}),C.iridescence&&C.iridescence>0&&(se.KHR_materials_iridescence={iridescenceFactor:C.iridescence,iridescenceIor:C.iridescenceIOR??1.3});let fe=C._serializeTslGraph?.();return fe&&(se.GOOGLE_material_tsl=fe,l.add("GOOGLE_material_tsl")),Object.keys(se).length>0&&(W.extensions=se),f.push(W),I}function w(c,I){let C=new Uint8Array(c.buffer,c.byteOffset,c.byteLength),U=Mi(C.byteLength),j=new Uint8Array(U);j.set(C),i.push(j);let H=n.length;return n.push({buffer:0,byteOffset:r,byteLength:C.byteLength,target:I}),r+=U,H}function _(c,I,C,U,j,H,Y){let q=w(c,C),ne=s.length,ie={bufferView:q,byteOffset:0,componentType:U,count:j,type:I};return H&&(ie.min=H),Y&&(ie.max=Y),s.push(ie),ne}let N=[],P=[],E=new Set([t]),T=[];if(Array.isArray(t.children))for(let c=t.children.length-1;c>=0;c--)T.push({obj:t.children[c],parentKids:P});for(;T.length>0;){let{obj:c,parentKids:I}=T.pop();if(!c||typeof c!="object"||E.has(c))continue;E.add(c),c._bakeAuthorGeometry?.(),de().materializeDeclarativeGeometry?.(c);let C=!!(c.userData&&(c.userData.xr&&typeof c.userData.xr=="object"&&Object.keys(c.userData.xr).length>0||c.userData.interactivity&&typeof c.userData.interactivity=="object"&&Object.keys(c.userData.interactivity).length>0)),U={name:c.name||(C?`Node_${o.length}`:"")},j=J(c.position?.x,0),H=J(c.position?.y,0),Y=J(c.position?.z,0),q=J(c.quaternion?.x,0),ne=J(c.quaternion?.y,0),ie=J(c.quaternion?.z,0),oe=J(c.quaternion?.w,1),he=J(c.scale?.x,1),B=J(c.scale?.y,1),X=J(c.scale?.z,1);if((j||H||Y)&&(U.translation=[j,H,Y]),(q||ne||ie||oe!==1)&&(U.rotation=[q,ne,ie,oe]),(he!==1||B!==1||X!==1)&&(U.scale=[he,B,X]),c.visible===!1&&(U.extensions={...U.extensions||{},KHR_node_visibility:{visible:!1}},l.add("KHR_node_visibility")),c.userData&&Object.keys(c.userData).length>0&&(U.extras=JSON.parse(JSON.stringify(c.userData,($,G)=>{if(!($==="__proto__"||$==="prototype"||$==="constructor"))return typeof G=="function"?void 0:G})),c.userData.xr)){let $=Si(c.userData.xr);U.extensions={...U.extensions||{},MOZ_hubs_components:$,ANDROID_xr_scenecore:$},de().xrTraitSerializer?.gltfNode(U,c.userData.xr);let G=wi(c),W=U.extras?.xr?.material;G&&W&&typeof W=="object"&&!Array.isArray(W)&&(W.textureKey=G),l.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}let z=c,ee=z.isLight||z.color&&z.intensity!==void 0;if(!ee&&(z._castShdSet||z._recvShdSet||c.castShadow||c.receiveShadow)&&(U.extras={...U.extras||{},shadow:{cast:!!c.castShadow,receive:z._recvShdSet?!!c.receiveShadow:!!(c.receiveShadow||c.castShadow)}}),ee){let $=z.matrixWorld?.elements,G=J($?$[12]:c.position?.x,0),W=J($?$[13]:c.position?.y,0),Z=J($?$[14]:c.position?.z,0),ae=z.target,se=ae?.parent?ae?.matrixWorld?.elements:void 0,fe=J(se?se[12]:ae?.position?.x,0),re=J(se?se[13]:ae?.position?.y,0),Ae=J(se?se[14]:ae?.position?.z,0),le=fe-G,me=re-W,ue=Ae-Z,ce=Math.hypot(le,me,ue),Te=Math.max(.01,Math.min(Math.PI/2,J(z.angle,Math.PI/3))),_e=Math.max(0,Math.min(1,J(z.penumbra,0))),pe=Math.max(0,Te*(1-_e)),Le=Math.max(0,J(z.distance,0)),je=c.type==="directional"||c.type==="spot"||c.type==="point",Be;if(c.castShadow&&je){let Ye=z.shadow,Zi=Math.max(256,Math.min(2048,Math.round(J(Ye?.mapSize?.x??Ye?.mapSize?.width,1024))));Be={cast:!0,mapSize:Zi<=384?256:Zi<=768?512:Zi<=1536?1024:2048,bias:Ie(Ye?.bias,-.05,.05,-5e-4),normalBias:Ie(Ye?.normalBias,0,.2,.015),radius:Ie(Ye?.radius,0,8,1.5)},p=!0}let Ct=G-fe,qi=W-re,Yi=Z-Ae,rt=Math.hypot(Ct,qi,Yi);u.push({type:c.type,color:[c.color.r,c.color.g,c.color.b],intensity:c.intensity,position:c.type==="directional"?[Ct,qi,Yi]:[G,W,Z],...c.type==="directional"?{direction:rt>1e-6?[Ct/rt,qi/rt,Yi/rt]:[0,1,0]}:c.type==="spot"?{direction:ce>1e-6?[le/ce,me/ce,ue/ce]:[0,-1,0],outerConeAngle:Te,innerConeAngle:pe,range:Le}:c.type==="point"?{range:Le}:c.type==="hemisphere"&&z.groundColor?{groundColor:[z.groundColor.r,z.groundColor.g,z.groundColor.b]}:{},...Be?{shadow:Be}:{}}),je&&N.push({node:U,obj:c,px:G,py:W,pz:Z,tx:fe,ty:re,tz:Ae,dx:le,dy:me,dz:ue,dLen:ce,outerAngle:Te,innerAngle:pe,range:Le,shadowSpec:Be})}if(c.geometry){let $=c.geometry,G=$.attributes.position;if(G&&G.count>0){let W=[1/0,1/0,1/0],Z=[-1/0,-1/0,-1/0];for(let le=0;le<G.count;le++){let me=G.getX(le),ue=G.getY(le),ce=G.getZ(le);me<W[0]&&(W[0]=me),me>Z[0]&&(Z[0]=me),ue<W[1]&&(W[1]=ue),ue>Z[1]&&(Z[1]=ue),ce<W[2]&&(W[2]=ce),ce>Z[2]&&(Z[2]=ce)}let ae={attributes:{POSITION:_(G.array,"VEC3",34962,5126,G.count,W,Z)}};if($.attributes.normal&&(ae.attributes.NORMAL=_($.attributes.normal.array,"VEC3",34962,5126,$.attributes.normal.count)),$.attributes.uv&&(ae.attributes.TEXCOORD_0=_($.attributes.uv.array,"VEC2",34962,5126,$.attributes.uv.count)),$.index){let le=$.index.array instanceof Uint32Array;ae.indices=_($.index.array,"SCALAR",34963,le?5125:5123,$.index.count)}let se=Array.isArray(c.material)?c.material[0]:c.material;se&&(ae.material=x(se));let fe=c.userData?.variants;if(fe&&typeof fe=="object"){let le=new Map;for(let me of Object.keys(fe)){if(!me||me==="__proto__"||me==="constructor"||me==="prototype")continue;let ue=fe[me];if(!ue||typeof ue!="object")continue;let ce=m.indexOf(me);if(ce===-1&&m.length<256&&(ce=m.length,m.push(me)),ce===-1)continue;let Te=x(ue),_e=le.get(Te);_e||(_e=[],le.set(Te,_e)),_e.push(ce)}if(le.size>0){let me=[];for(let[ue,ce]of le.entries())me.push({material:ue,variants:ce});ae.extensions={...ae.extensions||{},KHR_materials_variants:{mappings:me}},l.add("KHR_materials_variants")}}let re=c;if(re.isInstancedMesh&&typeof re.count=="number"&&re.count>0&&re.instanceMatrix?.array){let le=Math.min(1e4,Math.floor(re.count)),me=re.instanceMatrix.array,ue=new Float32Array(le*3),ce=new Float32Array(le*4),Te=new Float32Array(le*3);for(let pe=0;pe<le;pe++){let{t:Le,r:je,s:Be}=Tr(me,pe*16);ue[pe*3]=Le[0],ue[pe*3+1]=Le[1],ue[pe*3+2]=Le[2],ce[pe*4]=je[0],ce[pe*4+1]=je[1],ce[pe*4+2]=je[2],ce[pe*4+3]=je[3],Te[pe*3]=Be[0],Te[pe*3+1]=Be[1],Te[pe*3+2]=Be[2]}let _e={TRANSLATION:_(ue,"VEC3",0,5126,le),ROTATION:_(ce,"VEC4",0,5126,le),SCALE:_(Te,"VEC3",0,5126,le)};if(re.instanceColor?.array&&re.instanceColor.array.length>=le*3){let pe=new Float32Array(re.instanceColor.array.subarray(0,le*3));_e._COLOR_0=_(pe,"VEC3",0,5126,le)}U.extensions={...U.extensions||{},EXT_mesh_gpu_instancing:{attributes:_e}},l.add("EXT_mesh_gpu_instancing")}let Ae=a.length;a.push({primitives:[ae],name:c.name,...U.extras?{extras:U.extras}:{}}),U.mesh=Ae}}let te=o.length;o.push(U),y.push(c),I.push(te);let K=c.children;if(Array.isArray(K)&&K.length>0){let $=[];U.children=$;for(let G=K.length-1;G>=0;G--)T.push({obj:K[G],parentKids:$})}}if(p)for(let c of N){let I=g.length;if(g.push({name:c.obj.name||`Light_${I}`,type:c.obj.type,color:[c.obj.color.r,c.obj.color.g,c.obj.color.b],intensity:c.obj.intensity,...c.range>0&&(c.obj.type==="point"||c.obj.type==="spot")?{range:c.range}:{},...c.obj.type==="spot"?{spot:{innerConeAngle:c.innerAngle,outerConeAngle:c.outerAngle}}:{},...c.shadowSpec?{extras:{shadow:c.shadowSpec}}:{}}),c.node.extensions={...c.node.extensions||{},KHR_lights_punctual:{light:I}},l.add("KHR_lights_punctual"),c.obj.type==="directional"||c.obj.type==="spot"){let C=c.dLen>1e-6?c.dx/c.dLen:0,U=c.dLen>1e-6?c.dy/c.dLen:-1,j=c.dLen>1e-6?c.dz/c.dLen:0;c.node.rotation=Ar(C,U,j),c.obj.type==="directional"&&(c.tx||c.ty||c.tz)&&(c.node.translation=[c.px-c.tx,c.py-c.ty,c.pz-c.tz])}}for(let c=0;c<o.length;c++){let I=o[c];I.children&&I.children.length===0?delete I.children:I.children&&I.children.length>0&&(I.extras?.xr?.lod||I.extensions?.ANDROID_xr_scenecore?.lod||y[c]?.isLOD)&&(I.extensions={...I.extensions||{},MSFT_lod:{ids:[...I.children]}},l.add("MSFT_lod"))}let S=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),A=[];if(typeof S=="function"&&y.length>0){let c=e?.duration??4,I=e?.fps??15,C=Math.max(2,Math.round(c*I)+1),U=new Float32Array(C),j=y.map(B=>[J(B.position?.x,0),J(B.position?.y,0),J(B.position?.z,0),J(B.quaternion?.x,0),J(B.quaternion?.y,0),J(B.quaternion?.z,0),J(B.quaternion?.w,1),J(B.scale?.x,1),J(B.scale?.y,1),J(B.scale?.z,1)]),H=y.map(()=>new Float32Array(C*3)),Y=y.map(()=>new Float32Array(C*4)),q=y.map(()=>new Float32Array(C*3));for(let B=0;B<C;B++){let X=B/(C-1)*c;U[B]=X;try{S(X)}catch{}for(let z=0;z<y.length;z++){let ee=y[z];H[z][B*3]=J(ee.position?.x,0),H[z][B*3+1]=J(ee.position?.y,0),H[z][B*3+2]=J(ee.position?.z,0);let te=J(ee.quaternion?.x,0),K=J(ee.quaternion?.y,0),$=J(ee.quaternion?.z,0),G=J(ee.quaternion?.w,1),W=Math.hypot(te,K,$,G)||1;if(te/=W,K/=W,$/=W,G/=W,B>0){let Z=(B-1)*4,ae=Y[z];ae[Z]*te+ae[Z+1]*K+ae[Z+2]*$+ae[Z+3]*G<0&&(te=-te,K=-K,$=-$,G=-G)}Y[z][B*4]=te,Y[z][B*4+1]=K,Y[z][B*4+2]=$,Y[z][B*4+3]=G,q[z][B*3]=J(ee.scale?.x,1),q[z][B*3+1]=J(ee.scale?.y,1),q[z][B*3+2]=J(ee.scale?.z,1)}}for(let B=0;B<y.length;B++){let X=y[B],z=j[B];X.position?.set(z[0],z[1],z[2]),X.quaternion?.set(z[3],z[4],z[5],z[6]),X.scale?.set(z[7],z[8],z[9])}t.updateMatrixWorld(!0);let ne=null,ie=()=>(ne===null&&(ne=_(U,"SCALAR",0,5126,C,[0],[c])),ne),oe=[],he=[];for(let B=0;B<y.length;B++){let X=j[B],z=(te,K,$)=>te.some((G,W)=>Math.abs(G-X[$+W%K])>1e-4),ee=(te,K,$,G)=>{te&&he.push({sampler:oe.push({input:ie(),interpolation:"LINEAR",output:_(K,$,0,5126,C)})-1,target:{node:B,path:G}})};ee(z(H[B],3,0),H[B],"VEC3","translation"),ee(z(Y[B],4,3),Y[B],"VEC4","rotation"),ee(z(q[B],3,7),q[B],"VEC3","scale")}he.length>0&&A.push({name:"ProceduralLoop",samplers:oe,channels:he})}let D=cr(o,a,t.userData),R=[],F=[],k=[];for(let c=0;c<o.length;c++){let I=o[c],C=Er(I.extras?.xr);if(!C)continue;let{ae:U,src:j,preset:H,volume:Y,loop:q,isGlobal:ne}=C,ie=I.name||`Node_${c}`,oe=F.length;F.push({name:`${ie}_source`,gain:Y,loop:q,autoPlay:typeof U.autoplay=="boolean"?U.autoplay:!0,...j!==void 0?{audio:R.push({uri:j})-1}:{},...H?{extras:{preset:H,pitch:Ie(U.pitch,.25,4,1)}}:{}});let he=k.length,B=Ie(U.refDistance,.05,100,1),X=Ie(U.coneInnerAngle,0,360,360),z=Ie(U.coneOuterAngle,X,360,360);k.push({name:`${ie}_emitter`,type:ne?"global":"positional",gain:Y,sources:[oe],...ne?{}:{positional:{distanceModel:U.distanceModel==="linear"||U.distanceModel==="exponential"?U.distanceModel:"inverse",refDistance:B,maxDistance:Ie(U.maxDistance,B,500,Math.max(B,25)),rolloffFactor:Ie(U.rolloffFactor,0,10,1),coneInnerAngle:+(X*Math.PI/180).toFixed(6),coneOuterAngle:+(z*Math.PI/180).toFixed(6),coneOuterGain:Ie(U.coneOuterGain,0,1,0)}}}),I.extensions={...I.extensions||{},KHR_audio_emitter:{emitter:he}},l.add("KHR_audio_emitter")}let V={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity,...u.length>0?{lights:u}:{}}},scenes:[{nodes:P}],scene:0,nodes:o,meshes:a,materials:f,...h.length>0?{images:h}:{},...d.length>0?{samplers:d}:{},...v.length>0?{textures:v}:{},accessors:s,bufferViews:n,buffers:[{byteLength:r}],...A.length>0?{animations:A}:{},...D||l.size>0?{extensionsUsed:[...D?["KHR_interactivity"]:[],...l]}:{},...D||m.length>0||k.length>0||g.length>0?{extensions:{...D?{KHR_interactivity:D}:{},...m.length>0?{KHR_materials_variants:{variants:m.map(c=>({name:c}))}}:{},...k.length>0?{KHR_audio_emitter:{...R.length>0?{audio:R}:{},sources:F,emitters:k}}:{},...g.length>0?{KHR_lights_punctual:{lights:g}}:{}}}:{}},L=new Uint8Array(r),O=0;for(let c of i)L.set(c,O),O+=c.byteLength;return[{gltf:V,bin:L.buffer,lights:u,environmentIntensity:t.environmentIntensity},y]}function Zn(t){return new TextEncoder().encode(t)}function lt(t,e){let{gltf:i,bin:r}=Je(t,e),n=JSON.stringify(i),s=Zn(n),a=(4-s.byteLength%4)%4,o=s.byteLength+a,l=20+o+8+r.byteLength,y=new Uint8Array(l),f=new DataView(y.buffer);f.setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,l,!0),f.setUint32(12,o,!0),f.setUint32(16,1313821514,!0),y.set(s,20);for(let h=0;h<a;h++)y[20+s.byteLength+h]=32;let b=20+o;return f.setUint32(b,r.byteLength,!0),f.setUint32(b+4,5130562,!0),y.set(new Uint8Array(r),b+8),y}function _i(t,e){let[i,r]=Rr(t,e);return Lr(i,r)}function Lr(t,e){let i=[],r=t.gltf,n=de().decoders.get("meshopt");n&&typeof n.decodeBufferViews=="function"&&n.decodeBufferViews(r,t);let s=t.bin,a=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),o=r.accessors||[],l=r.bufferViews||[],y=r.materials||[],f=r.meshes||[],b=r.nodes||[],h=r.textures||[],d=r.images||[],v=r.samplers||[],M=new Set,m=y.map((P,E)=>qn(M,ut(P?.name,`Material_${E}`))),u=new Map;function g(P){let E=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(P);if(!E)return null;let T=E[2].replace(/\s+/g,""),S=T.endsWith("==")?2:T.endsWith("=")?1:0,A=new Uint8Array((T.length*3>>2)-S),D=F=>{let k=T.charCodeAt(F);return k>96?k-71:k>64?k-65:k>47?k+4:k===43?62:k===47?63:0},R=0;for(let F=0;F<T.length;F+=4){let k=D(F)<<18|D(F+1)<<12|D(F+2)<<6|D(F+3);A[R++]=k>>16&255,R<A.length&&(A[R++]=k>>8&255),R<A.length&&(A[R++]=k&255)}return A}function p(P,E,T){let S=P?.index;if(typeof S!="number")return;let A=h[S],D=A?.source;if(typeof D!="number"||!d[D])return;let R=u.get(D);if(R===void 0){R=null;let V=d[D],L=null;if(typeof V.bufferView=="number"){let O=l[V.bufferView],c=O?.byteOffset||0,I=O?.byteLength||0;O&&I>0&&c>=0&&c+I<=a.byteLength&&(L=new Uint8Array(a,c,I))}else typeof V.uri=="string"&&(L=g(V.uri));if(L&&L.byteLength>0){let O=L[0]===255&&L[1]===216&&L[2]===255||!(L[0]===137&&L[1]===80)&&/jpe?g/i.test(V.mimeType||V.uri||"");R={file:`texture_${D}.${O?"jpg":"png"}`,data:L}}u.set(D,R)}if(!R)return;let F=typeof A.sampler=="number"?v[A.sampler]:void 0,k=V=>V===33071?"clamp":V===33648?"mirror":"repeat";return{file:R.file,data:R.data,wrapS:k(F?.wrapS),wrapT:k(F?.wrapT),...E?{scale:E}:{},...T?{bias:T}:{}}}function x(P){let E=o[P];if(!E)throw new Error(`Accessor ${P} not found`);let T=l[E.bufferView||0],S=(T.byteOffset||0)+(E.byteOffset||0),A=T.byteLength||0;return{acc:E,buffer:a.slice(S,S+A)}}function w(P,E,T,S){let A=[],D=f[P];if(!D)return A;let R=D.primitives||[];for(let F=0;F<R.length;F++){let k=R[F],V=k.attributes?.POSITION;if(V===void 0)continue;let{acc:L,buffer:O}=x(V),c=new Float32Array(O,0,L.count*3),I,C=k.attributes?.NORMAL;if(C!==void 0){let{acc:K,buffer:$}=x(C),G=new Float32Array($,0,K.count*3);I=new Float32Array(G.length);for(let W=0;W<K.count;W++){let Z=G[W*3],ae=G[W*3+1],se=G[W*3+2],fe=Math.hypot(Z,ae,se)||1;I[W*3]=Z/fe,I[W*3+1]=ae/fe,I[W*3+2]=se/fe}}let U,j=k.attributes?.TEXCOORD_0;if(j!==void 0){let{acc:K,buffer:$}=x(j);U=new Float32Array($,0,K.count*2)}let H;if(k.indices!==void 0){let{acc:K,buffer:$}=x(k.indices);H=K.componentType===5125?new Uint32Array($,0,K.count):new Uint16Array($,0,K.count);let G=L.count;for(let W of H)if(W>=G)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${G}).`)}else{let K=L.count;H=K>65535?new Uint32Array(K):new Uint16Array(K);for(let $=0;$<K;$++)H[$]=$}let Y="DefaultMaterial",q=[1,1,1],ne=.5,ie=0,oe=0,he=0,B=1.5,X=1,z=[0,0,0],ee,te={};if(k.material!==void 0&&y[k.material]){let K=y[k.material];Y=m[k.material]||`Material_${k.material}`;let $=K.pbrMetallicRoughness||{},G=(pe,Le)=>Array.isArray(pe)&&pe.length>=3?[pe[0],pe[1],pe[2]]:Le;q=G($.baseColorFactor,[1,1,1]);let W=Array.isArray($.baseColorFactor)&&typeof $.baseColorFactor[3]=="number"?$.baseColorFactor[3]:1,Z=q[0]!==1||q[1]!==1||q[2]!==1||W!==1,ae=p($.baseColorTexture,Z?[q[0],q[1],q[2],W]:void 0),se=K.extras?.avgColor;!ae&&Array.isArray(se)&&se.length>=3&&(q=[q[0]*se[0],q[1]*se[1],q[2]*se[2]]),typeof $.roughnessFactor=="number"&&(ne=$.roughnessFactor),typeof $.metallicFactor=="number"&&(ie=$.metallicFactor);let fe=typeof $.roughnessFactor=="number"?$.roughnessFactor:1,re=typeof $.metallicFactor=="number"?$.metallicFactor:1,Ae=p($.metallicRoughnessTexture,fe!==1||re!==1?[1,fe,re,1]:void 0);z=G(K.emissiveFactor,[0,0,0]);let le=(z[0]>0||z[1]>0||z[2]>0)&&(z[0]!==1||z[1]!==1||z[2]!==1)?[z[0],z[1],z[2],1]:void 0,me=p(K.emissiveTexture,le),ue=typeof K.normalTexture?.scale=="number"?K.normalTexture.scale:1,ce=p(K.normalTexture,[2*ue,2*ue,2,1],[-ue,-ue,-1,0]),Te=typeof K.occlusionTexture?.strength=="number"?K.occlusionTexture.strength:1,_e=Te!==1?p(K.occlusionTexture,[Te,Te,Te,1],[1-Te,1-Te,1-Te,0]):p(K.occlusionTexture);(ae||Ae||ce||me||_e)&&(ee=[ae,Ae,ce,me,_e]),te=K.extensions||{},te.KHR_materials_clearcoat&&(oe=te.KHR_materials_clearcoat.clearcoatFactor??0,he=te.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof te.KHR_materials_ior?.ior=="number"&&(B=te.KHR_materials_ior.ior),X=W*(1-(te.KHR_materials_transmission?.transmissionFactor??0))}A.push({name:R.length>1?`${E}_p${F}`:E,positions:c,indices:H,normals:I,uvs:U,materialName:Y,color:q,roughness:ne,metallic:ie,clearcoat:oe,clearcoatRoughness:he,ior:B,opacity:X,emissiveColor:z,...ee?{textures:ee}:{},...te.GOOGLE_material_tsl?{tslGraph:te.GOOGLE_material_tsl}:{},xrTraits:T||D.extras?.xr,...S?{invisible:!0}:{}})}return A}if(b.length>0){let P=new Float32Array(0),E=new Uint16Array(0),T=(c,I)=>{if(c===void 0)return null;let{acc:C,buffer:U}=x(c);return new Float32Array(U,0,C.count*I)},S=(c,I)=>Array.isArray(c)&&c.length>=3?[J(c[0],I),J(c[1],I),J(c[2],I)]:[I,I,I],A=(c,I,C)=>c&&c.length>=(I+1)*3?[c[I*3],c[I*3+1],c[I*3+2]]:C,D=(c,I,C)=>c&&c.length>=(I+1)*4?[c[I*4],c[I*4+1],c[I*4+2],c[I*4+3]]:C,R=new Map,F=r.animations?.[0];if(F&&Array.isArray(F.channels)&&Array.isArray(F.samplers))for(let c of F.channels){let I=F.samplers[c?.sampler],C=c?.target?.node,U=c?.target?.path;if(!I||typeof C!="number"||I.input===void 0)continue;let j=R.get(C);j||(j={input:I.input},R.set(C,j)),U==="translation"?j.t=I.output:U==="rotation"?j.r=I.output:U==="scale"&&(j.s=I.output)}let k=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(k)||k.length===0){let c=new Set;for(let I of b)if(Array.isArray(I?.children))for(let C of I.children)c.add(C);k=[];for(let I=0;I<b.length;I++)c.has(I)||k.push(I);k.length===0&&(k=[0])}let V=new Set,L=[],O=(c,I)=>{if(Array.isArray(c))for(let C=c.length-1;C>=0;C--)L.push({idx:c[C],out:I})};for(O(k,i);L.length>0;){let{idx:c,out:I}=L.pop();if(typeof c!="number"||c<0||c>=b.length||V.has(c))continue;V.add(c);let C=b[c];if(!C)continue;let U=[0,0,0],j=[0,0,0,1],H=[1,1,1];if(Array.isArray(C.matrix)&&C.matrix.length===16){let X=Tr(C.matrix);U=X.t,j=X.r,H=X.s}else U=S(C.translation,0),Array.isArray(C.rotation)&&C.rotation.length>=4&&(j=[J(C.rotation[0],0),J(C.rotation[1],0),J(C.rotation[2],0),J(C.rotation[3],1)]),H=S(C.scale,1);let Y,q=R.get(c);if(q){let X=T(q.input,1);if(X&&X.length>0){let z=T(q.t,3),ee=T(q.r,4),te=T(q.s,3),K=Array.from(X),$=[],G=[],W=[];for(let Z=0;Z<X.length;Z++)$.push(A(z,Z,U)),G.push(D(ee,Z,j)),W.push(A(te,Z,H));Y={times:K,translations:$,rotations:G,scales:W}}}let ne=Array.isArray(C.children)?C.children:[],ie=typeof C.mesh=="number"&&C.mesh>=0&&C.mesh<f.length,oe=e?.[c]?.userData?.xr??C.extras?.xr;if(!ie&&ne.length===0&&(C.camera!==void 0||C.extensions?.KHR_lights_punctual||!C.name&&!C.extras&&!oe&&!Y))continue;let he=(X,z,ee)=>({name:X,positions:P,indices:E,isXform:!0,xrTraits:oe,timeSamples:Y,translation:U,rotation:j,scale:H,children:z,...ee?{invisible:!0}:{}}),B=C.visible===!1||C.extensions?.KHR_node_visibility?.visible===!1||e?.[c]?.visible===!1;if(ie){let X=C.name||f[C.mesh]?.name||`Mesh_${c}`,z=w(C.mesh,X,oe,B),ee=e?.[c],te=!!(ee?._castShdSet||ee?._recvShdSet),K=typeof C.extras?.shadow?.cast=="boolean"?C.extras.shadow.cast:te?!!ee?.castShadow:void 0;if(K!==void 0)for(let G of z)G.castShadow=K;let $=C.extensions?.EXT_mesh_gpu_instancing?.attributes;if($&&typeof $=="object"&&z.length>0){let G=T($.TRANSLATION,3),W=T($.ROTATION,4),Z=T($.SCALE,3),ae=T($._COLOR_0,3),se=Math.min(1e3,G?G.length/3:W?W.length/4:Z?Z.length/3:0);if(se>0){let fe=[];for(let re=0;re<se;re++){let Ae=A(G,re,[0,0,0]),le=D(W,re,[0,0,0,1]),me=A(Z,re,[1,1,1]);for(let ue of z){let ce=ue.color||[.8,.8,.8],Te=ae&&ae.length>=(re+1)*3;fe.push({...ue,name:`${ue.name}_${re}`,materialName:Te?`${ue.materialName}_inst_${re}`:ue.materialName,color:Te?[ce[0]*ae[re*3],ce[1]*ae[re*3+1],ce[2]*ae[re*3+2]]:ue.color,translation:Ae,rotation:le,scale:me})}}O(ne,fe),I.push(he(X,fe,B));continue}}if(z.length===1)z[0].translation=U,z[0].rotation=j,z[0].scale=H,z[0].timeSamples=Y,ne.length>0&&(z[0].children=[],O(ne,z[0].children)),I.push(z[0]);else{let G=[...z];O(ne,G),I.push(he(X,G,B))}}else{let X=[];O(ne,X),I.push(he(C.name||`Group_${c}`,X,B))}}}else for(let P=0;P<f.length;P++){let E=f[P].name||`Mesh_${P}`;i.push(...w(P,E,f[P].extras?.xr))}let _=(Array.isArray(t.lights)&&t.lights.length>0?t.lights:void 0)??Yn(r)??(Array.isArray(r?.asset?.extras?.lights)?r.asset.extras.lights:[]),N=[];for(let P=0;P<_.length;P++){let E=_[P];E?.shadow?.cast&&(E.type==="directional"||E.type==="spot"||E.type==="point")&&N.push({name:`Light_${P}`,type:E.type,color:E.color,intensity:E.intensity,position:E.position,direction:E.direction,range:E.range,innerConeAngle:E.innerConeAngle,outerConeAngle:E.outerConeAngle,shadow:E.shadow})}return N.length>0&&(i.__usdaShadowLights=N),i}function ut(t,e){if(!t||typeof t!="string")return e;let i=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||e}function Ot(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ye(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}var Ne=(t,e,i)=>`(${ye(t)}, ${ye(e)}, ${ye(i)})`,ct=(t,e,i,r)=>`(${ye(t)}, ${ye(e)}, ${ye(i)}, ${ye(r)})`;function _r(t){let e=t.length/3,i=new Array(e);for(let r=0;r<e;r++)i[r]=Ne(t[r*3],t[r*3+1],t[r*3+2]);return i.join(", ")}function Ai(t,e){let i=new Array(e);for(let r=0;r<e;r++)i[r]=`(${ye(t[r*2])}, ${ye(1-t[r*2+1])})`;return i.join(", ")}function Ti(t){return Array.from(t).join(", ")}function Ei(t,e){let i=(e??t.__usdaShadowLights??[]).filter(m=>m?.shadow?.cast),r=new Map,n=0,s=null,a=[...t];for(;a.length>0;){let m=a.pop();if(!m.isXform&&m.positions&&m.positions.length>0){let u=ut(m.materialName,"DefaultMaterial");r.has(u)||r.set(u,{color:m.color||[1,1,1],roughness:m.roughness??.5,metallic:m.metallic??0,clearcoat:m.clearcoat??0,clearcoatRoughness:m.clearcoatRoughness??0,ior:m.ior??1.5,opacity:m.opacity??1,emissiveColor:m.emissiveColor||[0,0,0],textures:m.textures,tslGraph:m.tslGraph})}if(m.timeSamples&&m.timeSamples.times.length>0){let u=m.timeSamples.times[m.timeSamples.times.length-1];u>n&&(n=u)}else m.tslGraph&&n<=0&&JSON.stringify(m.tslGraph).includes('"time"')&&(n=60);if(m.xrTraits?.anchor&&!s&&(s=m.xrTraits.anchor==="vertical"||m.xrTraits.anchor==="wall"?"vertical":"horizontal"),m.children)for(let u=m.children.length-1;u>=0;u--)a.push(m.children[u])}let o="";n>0&&(o=`startTimeCode = 0
|
|
215
|
+
endTimeCode = ${ye(n)}
|
|
251
216
|
timeCodesPerSecond = 1.0
|
|
252
|
-
`);let
|
|
253
|
-
uniform token preliminary:planeAnchoring:alignment = "${
|
|
254
|
-
`);let
|
|
217
|
+
`);let l="";s&&(l=`uniform token preliminary:anchoring:type = "plane"
|
|
218
|
+
uniform token preliminary:planeAnchoring:alignment = "${s}"
|
|
219
|
+
`);let y=`#usda 1.0
|
|
255
220
|
(
|
|
256
221
|
defaultPrim = "Root"
|
|
257
222
|
metersPerUnit = 1.0
|
|
258
223
|
upAxis = "Y"
|
|
259
|
-
${
|
|
224
|
+
${o})
|
|
260
225
|
|
|
261
226
|
def Xform "Root" (
|
|
262
227
|
kind = "component"
|
|
263
228
|
)
|
|
264
229
|
{
|
|
265
|
-
${
|
|
230
|
+
${l}def Scope "Materials"
|
|
266
231
|
{
|
|
267
|
-
`;for(let[
|
|
268
|
-
float inputs:roughness${
|
|
269
|
-
float inputs:roughness = ${ye(
|
|
270
|
-
`,
|
|
271
|
-
`),
|
|
272
|
-
`),
|
|
273
|
-
`),
|
|
274
|
-
`:(
|
|
275
|
-
`),
|
|
276
|
-
`),
|
|
277
|
-
`);let
|
|
232
|
+
`;for(let[m,u]of r.entries()){let[g,p,x]=u.color,[w,_,N]=u.emissiveColor,P=`/Root/Materials/${m}`,[E,T,S,A,D]=u.textures||[],R=(I,C)=>`.connect = <${P}/${I}.outputs:${C}>`,F=E?`color3f inputs:diffuseColor${R("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${Ne(g,p,x)}`,k=T?`float inputs:metallic${R("MetallicRoughnessTexture","b")}
|
|
233
|
+
float inputs:roughness${R("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${ye(u.metallic)}
|
|
234
|
+
float inputs:roughness = ${ye(u.roughness)}`,V="";u.clearcoat>0&&(V+=`float inputs:clearcoat = ${ye(u.clearcoat)}
|
|
235
|
+
`,V+=`float inputs:clearcoatRoughness = ${ye(u.clearcoatRoughness)}
|
|
236
|
+
`),u.ior!==1.5&&(V+=`float inputs:ior = ${ye(u.ior)}
|
|
237
|
+
`),u.opacity<1&&(V+=`float inputs:opacity = ${ye(u.opacity)}
|
|
238
|
+
`),A?V+=`color3f inputs:emissiveColor${R("EmissiveTexture","rgb")}
|
|
239
|
+
`:(w>0||_>0||N>0)&&(V+=`color3f inputs:emissiveColor = ${Ne(w,_,N)}
|
|
240
|
+
`),S&&(V+=`normal3f inputs:normal${R("NormalTexture","rgb")}
|
|
241
|
+
`),D&&(V+=`float inputs:occlusion${R("OcclusionTexture","r")}
|
|
242
|
+
`);let L="";if(E||T||S||A||D){L+=`def Shader "PrimvarReader"
|
|
278
243
|
{
|
|
279
244
|
uniform token info:id = "UsdPrimvarReader_float2"
|
|
280
245
|
string inputs:varname = "st"
|
|
281
246
|
float2 outputs:result
|
|
282
247
|
}
|
|
283
|
-
`;let
|
|
284
|
-
`:"",
|
|
285
|
-
`:"";
|
|
248
|
+
`;let I=(C,U,j,H)=>{if(!U)return;let Y=U.scale?`float4 inputs:scale = ${ct(U.scale[0],U.scale[1],U.scale[2],U.scale[3])}
|
|
249
|
+
`:"",q=U.bias?`float4 inputs:bias = ${ct(U.bias[0],U.bias[1],U.bias[2],U.bias[3])}
|
|
250
|
+
`:"";L+=`def Shader "${C}"
|
|
286
251
|
{
|
|
287
252
|
uniform token info:id = "UsdUVTexture"
|
|
288
|
-
asset inputs:file = @${
|
|
289
|
-
float2 inputs:st${
|
|
290
|
-
token inputs:sourceColorSpace = "${
|
|
291
|
-
token inputs:wrapS = "${
|
|
292
|
-
token inputs:wrapT = "${
|
|
293
|
-
${
|
|
294
|
-
`};
|
|
295
|
-
`),
|
|
253
|
+
asset inputs:file = @${Ot(U.file)}@
|
|
254
|
+
float2 inputs:st${R("PrimvarReader","result")}
|
|
255
|
+
token inputs:sourceColorSpace = "${j}"
|
|
256
|
+
token inputs:wrapS = "${U.wrapS||"repeat"}"
|
|
257
|
+
token inputs:wrapT = "${U.wrapT||"repeat"}"
|
|
258
|
+
${Y}${q}${H}}
|
|
259
|
+
`};I("DiffuseTexture",E,"sRGB",`float3 outputs:rgb
|
|
260
|
+
`),I("MetallicRoughnessTexture",T,"raw",`float outputs:g
|
|
296
261
|
float outputs:b
|
|
297
|
-
`),
|
|
298
|
-
`),
|
|
299
|
-
`),
|
|
300
|
-
`)}
|
|
262
|
+
`),I("NormalTexture",S,"raw",`float3 outputs:rgb
|
|
263
|
+
`),I("EmissiveTexture",A,"sRGB",`float3 outputs:rgb
|
|
264
|
+
`),I("OcclusionTexture",D,"raw",`float outputs:r
|
|
265
|
+
`)}let O=`${F}
|
|
266
|
+
${k}
|
|
267
|
+
${V}`,c=u.tslGraph&&de().tslUsdzSerializer?.(u.tslGraph,m,O);c&&(O=c.surfaceInputsUsda||O,L+=c.nodeGraphUsda),y+=`def Material "${m}"
|
|
301
268
|
{
|
|
302
269
|
def Shader "PBRShader"
|
|
303
270
|
{
|
|
304
271
|
uniform token info:id = "UsdPreviewSurface"
|
|
305
|
-
${
|
|
306
|
-
${y}
|
|
307
|
-
${F}token outputs:surface
|
|
272
|
+
${O}token outputs:surface
|
|
308
273
|
}
|
|
309
|
-
token outputs:surface${
|
|
310
|
-
${
|
|
311
|
-
`}
|
|
274
|
+
token outputs:surface${R("PBRShader","surface")}
|
|
275
|
+
${L}}
|
|
276
|
+
`}y+=`}
|
|
312
277
|
def Scope "Meshes"
|
|
313
278
|
{
|
|
314
|
-
`;let
|
|
279
|
+
`;let f=(m,u,g)=>{let p=[];u&&p.push('"MaterialBindingAPI"');let x=!!(m?.rigidBody&&m.rigidBody!=="none"&&(typeof m.rigidBody!="object"||m.rigidBody.enabled!==!1)),w=!!(m?.physics&&m.physics!=="none"||x);w&&p.push(...x?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let _=[];p.length>0&&_.push(`prepend apiSchemas = [${p.join(", ")}]`);let N=de().xrTraitSerializer;if(m){let A=N?.usdLines(m,Ot)??[];if(!A.length)for(let D of["grab","billboard","follow","anchor","physics"]){let R=D==="follow"&&typeof m.follow=="object"?m.follow.mode??"head":m[D];R!==void 0&&A.push(`string ${D} = "${Ot(R)}"`)}A.length>0&&_.push(`customData = {
|
|
315
280
|
dictionary xr = {
|
|
316
|
-
${
|
|
281
|
+
${A.join(`
|
|
317
282
|
`)}
|
|
318
283
|
}
|
|
319
|
-
}`)}let
|
|
320
|
-
${
|
|
284
|
+
}`)}let P=_.length>0?` (
|
|
285
|
+
${_.join(`
|
|
321
286
|
`)}
|
|
322
|
-
)`:"",
|
|
323
|
-
`:"";if(
|
|
324
|
-
bool physics:kinematicEnabled = ${
|
|
287
|
+
)`:"",E=g?`uniform token visibility = "invisible"
|
|
288
|
+
`:"";if(w){let A=m?.rigidBody??m?.physics,D=A?.body??A?.mode??A;E+=`bool physics:rigidBodyEnabled = true
|
|
289
|
+
bool physics:kinematicEnabled = ${D==="static"||D==="kinematic"}
|
|
325
290
|
bool physics:collisionEnabled = true
|
|
326
|
-
`,
|
|
327
|
-
`)}let
|
|
291
|
+
`,A?.mass>0&&Number.isFinite(A.mass)&&(E+=`float physics:mass = ${ye(A.mass)}
|
|
292
|
+
`)}let T=Er(m),S=(T?`def SpatialAudio "AudioEmitter"
|
|
328
293
|
{
|
|
329
|
-
${
|
|
330
|
-
`:""}uniform token inputs:auralMode = "${
|
|
331
|
-
uniform token inputs:playbackMode = "${
|
|
332
|
-
double gain = ${ye(
|
|
294
|
+
${T.src?`asset inputs:file = @${Ot(T.src)}@
|
|
295
|
+
`:""}uniform token inputs:auralMode = "${T.isGlobal?"nonSpatial":"spatial"}"
|
|
296
|
+
uniform token inputs:playbackMode = "${T.loop?"loopFromStart":"onceFromStart"}"
|
|
297
|
+
double gain = ${ye(T.volume)}
|
|
333
298
|
}
|
|
334
|
-
`:"";return{header:
|
|
335
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
336
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
299
|
+
`:"")+(m?N?.usdPrims?.(m)??"":"");return{header:P,body:E,tail:S}},b=m=>{if(m.timeSamples&&m.timeSamples.times.length>0){let _=m.timeSamples,N=(S,A,D)=>_.times.map((R,F)=>`${ye(R)}: ${D(S?.[F]||A)}`).join(", "),P=N(_.translations,[0,0,0],S=>Ne(S[0],S[1],S[2])),E=N(_.rotations,[0,0,0,1],S=>{let A=Math.hypot(S[0],S[1],S[2],S[3])||1;return ct(S[3]/A,S[0]/A,S[1]/A,S[2]/A)}),T=N(_.scales,[1,1,1],S=>Ne(S[0],S[1],S[2]));return`double3 xformOp:translate.timeSamples = { ${P} }
|
|
300
|
+
quatf xformOp:orient.timeSamples = { ${E} }
|
|
301
|
+
double3 xformOp:scale.timeSamples = { ${T} }
|
|
337
302
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
338
|
-
`}let
|
|
339
|
-
`,
|
|
340
|
-
`,
|
|
341
|
-
`,
|
|
342
|
-
`),
|
|
343
|
-
int[] faceVertexCounts = [${
|
|
344
|
-
int[] faceVertexIndices = [${
|
|
345
|
-
point3f[] points = [${
|
|
346
|
-
`;return
|
|
303
|
+
`}let u=[],g="",p=m.translation;p&&(Math.abs(p[0])>1e-7||Math.abs(p[1])>1e-7||Math.abs(p[2])>1e-7)&&(g+=`double3 xformOp:translate = ${Ne(p[0],p[1],p[2])}
|
|
304
|
+
`,u.push('"xformOp:translate"'));let x=m.rotation;if(x){let _=Math.hypot(x[0],x[1],x[2],x[3])||1,N=x[0]/_,P=x[1]/_,E=x[2]/_,T=x[3]/_;(1-Math.abs(T)>1e-7||Math.hypot(N,P,E)>1e-7)&&(g+=`quatf xformOp:orient = ${ct(T,N,P,E)}
|
|
305
|
+
`,u.push('"xformOp:orient"'))}let w=m.scale;return w&&(Math.abs(w[0]-1)>1e-7||Math.abs(w[1]-1)>1e-7||Math.abs(w[2]-1)>1e-7)&&(g+=`float3 xformOp:scale = ${Ne(w[0],w[1],w[2])}
|
|
306
|
+
`,u.push('"xformOp:scale"')),u.length>0&&(g+=`uniform token[] xformOpOrder = [${u.join(", ")}]
|
|
307
|
+
`),g},h=m=>{let u=m.positions.length/3,g=1/0,p=1/0,x=1/0,w=-1/0,_=-1/0,N=-1/0;for(let A=0;A<u;A++){let D=m.positions[A*3],R=m.positions[A*3+1],F=m.positions[A*3+2];D<g&&(g=D),D>w&&(w=D),R<p&&(p=R),R>_&&(_=R),F<x&&(x=F),F>N&&(N=F)}isFinite(g)||(g=p=x=-1,w=_=N=1);let P=Math.floor(m.indices.length/3),E=ut(m.materialName,"DefaultMaterial"),T=P>0?P===1?"3":"3, ".repeat(P-1)+"3":"",S=`float3[] extent = [${Ne(g,p,x)}, ${Ne(w,_,N)}]
|
|
308
|
+
int[] faceVertexCounts = [${T}]
|
|
309
|
+
int[] faceVertexIndices = [${Ti(m.indices)}]
|
|
310
|
+
point3f[] points = [${_r(m.positions)}]
|
|
311
|
+
`;return m.normals&&m.normals.length===m.positions.length&&(S+=`normal3f[] normals = [${_r(m.normals)}] (
|
|
347
312
|
interpolation = "vertex"
|
|
348
313
|
)
|
|
349
|
-
`),
|
|
314
|
+
`),m.uvs&&m.uvs.length===u*2&&(S+=`texCoord2f[] primvars:st = [${Ai(m.uvs,u)}] (
|
|
350
315
|
interpolation = "vertex"
|
|
351
316
|
)
|
|
352
|
-
`),
|
|
353
|
-
`,
|
|
354
|
-
|
|
317
|
+
`),S+=`rel material:binding = </Root/Materials/${E}>
|
|
318
|
+
`,m.castShadow===!1&&i.length>0&&(S+=`bool primvars:doNotCastShadows = 1
|
|
319
|
+
`),S},d=new Set,v=[];for(let m=t.length-1;m>=0;m--)v.push({node:t[m],siblings:d});let M=0;for(;v.length>0;){let m=v.pop();if(m.close){y+=`}
|
|
320
|
+
`;continue}let{node:u,siblings:g}=m,p=!!(u.isXform||u.positions.length===0),x=qn(g,ut(u.name,p?`Group_${M}`:`Mesh_${M}`));M++;let w=u.children||[];if(p){let _=f(u.xrTraits,!1,u.invisible);y+=`def Xform "${x}"${_.header}
|
|
355
321
|
{
|
|
356
|
-
${
|
|
322
|
+
${_.body}${b(u)}${_.tail}`,v.push({close:!0});let N=new Set;for(let P=w.length-1;P>=0;P--)v.push({node:w[P],siblings:N})}else if(w.length>0){let _=f(u.xrTraits,!1,u.invisible),N=`${x}_mesh`;y+=`def Xform "${x}"${_.header}
|
|
357
323
|
{
|
|
358
|
-
${
|
|
324
|
+
${_.body}${b(u)}${_.tail}`,y+=`def Mesh "${N}" (
|
|
359
325
|
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
360
326
|
)
|
|
361
327
|
{
|
|
362
|
-
${u
|
|
363
|
-
`,
|
|
328
|
+
${h(u)}}
|
|
329
|
+
`,v.push({close:!0});let P=new Set([N]);for(let E=w.length-1;E>=0;E--)v.push({node:w[E],siblings:P})}else{let _=f(u.xrTraits,!0,u.invisible);y+=`def Mesh "${x}"${_.header}
|
|
364
330
|
{
|
|
365
|
-
${
|
|
366
|
-
`}}
|
|
367
|
-
|
|
368
|
-
`,o}var Rt=null;function Dt(e){if(!Rt){Rt=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let s=0;s<8;s++)r=r&1?3988292384^r>>>1:r>>>1;Rt[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=Rt[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function li(e){let t=[],i=0,r=[];for(let u of e){let f=Nn(u.filename),g=Dt(u.data),w=u.data.length,p=30+f.length,b=(i+p)%64,T=b!==0?64-b:0;T>0&&T<4&&(T+=64);let x=new Uint8Array(p+T),M=new DataView(x.buffer);M.setUint32(0,67324752,!0),M.setUint16(4,20,!0),M.setUint32(14,g,!0),M.setUint32(18,w,!0),M.setUint32(22,w,!0),M.setUint16(26,f.length,!0),M.setUint16(28,T,!0),x.set(f,30),T>=4&&(M.setUint16(p,6534,!0),M.setUint16(p+2,T-4,!0)),t.push({offset:i,size:w,crc:g,filenameBytes:f,entry:u}),r.push(x,u.data),i+=x.length+u.data.length}let s=i;for(let u of t){let f=new Uint8Array(46+u.filenameBytes.length),g=new DataView(f.buffer);g.setUint32(0,33639248,!0),g.setUint16(4,20,!0),g.setUint16(6,20,!0),g.setUint32(16,u.crc,!0),g.setUint32(20,u.size,!0),g.setUint32(24,u.size,!0),g.setUint16(28,u.filenameBytes.length,!0),g.setUint32(42,u.offset,!0),f.set(u.filenameBytes,46),r.push(f),i+=f.length}let n=i-s,a=new Uint8Array(22),o=new DataView(a.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,t.length,!0),o.setUint16(10,t.length,!0),o.setUint32(12,n,!0),o.setUint32(16,s,!0),r.push(a),i+=22;let l=new Uint8Array(i),h=0;for(let u of r)l.set(u,h),h+=u.length;return l}function fr(e){let t=[{filename:"model.usda",data:Nn(ui(e))}],i=new Set(["model.usda"]),r=[...e];for(;r.length>0;){let s=r.pop();for(let n of s.textures||[])n?.file&&n.data?.byteLength&&!i.has(n.file)&&(i.add(n.file),t.push({filename:n.file,data:n.data}));if(s.children)for(let n=s.children.length-1;n>=0;n--)r.push(s.children[n])}return li(t)}function nt(e){return fr(oi(e))}function It(e){return fr(hr(wt(e)))}function Ln(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():It(e)}var Se=class Pi{constructor(t=0,i=0){this.x=Number(t),this.y=Number(i)}set(t,i){return this.x=Number(t),this.y=Number(i),this}clone(){return new Pi(this.x,this.y)}copy(t){return this.set(t.x,t.y)}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},ee=class Ni{constructor(t=0,i=0,r=0){this.x=Number(t),this.y=Number(i),this.z=Number(r)}set(t,i,r){return this.x=Number(t),this.y=Number(i),this.z=Number(r),this}clone(){return new Ni(this.x,this.y,this.z)}copy(t){return this.set(t.x,t.y,t.z)}add(t){return this.addVectors(this,t)}addVectors(t,i){return this.set(t.x+i.x,t.y+i.y,t.z+i.z)}sub(t){return this.subVectors(this,t)}subVectors(t,i){return this.set(t.x-i.x,t.y-i.y,t.z-i.z)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t)}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,i){return this.set(this.x+t.x*i,this.y+t.y*i,this.z+t.z*i)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5?this.multiplyScalar(1/t):this}cross(t){return this.crossVectors(this,t)}crossVectors(t,i){let r=t.x,s=t.y,n=t.z,a=i.x,o=i.y,l=i.z;return this.set(s*l-n*o,n*a-r*l,r*o-s*a)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}distanceTo(t){return Math.hypot(this.x-t.x,this.y-t.y,this.z-t.z)}lerp(t,i){return this.lerpVectors(this,t,i)}lerpVectors(t,i,r){return this.x=t.x+(i.x-t.x)*r,this.y=t.y+(i.y-t.y)*r,this.z=t.z+(i.z-t.z)*r,this}applyMatrix4(t){let i=this.x,r=this.y,s=this.z,n=t.elements,a=1/(n[3]*i+n[7]*r+n[11]*s+n[15]);return this.x=(n[0]*i+n[4]*r+n[8]*s+n[12])*a,this.y=(n[1]*i+n[5]*r+n[9]*s+n[13])*a,this.z=(n[2]*i+n[6]*r+n[10]*s+n[14])*a,this}},kt=class{constructor(e=0,t=0,i=0,r=1){this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r)}set(e,t,i,r){return this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r),this}},ot=class Li{constructor(t=0,i=0,r=0,s="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}set(t,i,r,s=this.order){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s,this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.order)}clone(){return new Li(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},Ye=class Ii{constructor(t=0,i=0,r=0,s=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s)}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}get w(){return this._w}set w(t){this._w=Number(t),this._onChangeCallback?.()}set(t,i,r,s){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s),this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){return new Ii(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(t,i=!0){let r=t.x,s=t.y,n=t.z,a=Math.cos(r/2),o=Math.cos(s/2),l=Math.cos(n/2),h=Math.sin(r/2),u=Math.sin(s/2),f=Math.sin(n/2);return this._x=h*o*l+a*u*f,this._y=a*u*l-h*o*f,this._z=a*o*f+h*u*l,this._w=a*o*l-h*u*f,i&&this._onChangeCallback?.(),this}setFromAxisAngle(t,i){let r=i/2,s=Math.sin(r);return this.set(t.x*s,t.y*s,t.z*s,Math.cos(r))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,i){let r=t.dot(i)+1;return r<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*i.z-t.z*i.y,t.z*i.x-t.x*i.z,t.x*i.y-t.y*i.x,r).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,i){let r=t.x,s=t.y,n=t.z,a=t.w,o=i.x,l=i.y,h=i.z,u=i.w;return this._x=r*u+a*o+s*h-n*l,this._y=s*u+a*l+n*o-r*h,this._z=n*u+a*h+r*l-s*o,this._w=a*u-r*o-s*l-n*h,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Be=class Fi{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,this}copy(t){return this.elements.set(t.elements),this}clone(){let t=new Fi;return t.copy(this),t}compose(t,i,r){return Qe(this.elements,[i.x,i.y,i.z,i.w],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,i){return be(this.elements,t.elements,i.elements),this}lookAt(t,i,r){return We(this.elements,[t.x,t.y,t.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(t){let i=new ee(0,0,0),r=new ee(1,1,1);return this.compose(i,t,r)}makeTranslation(t,i,r){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(t,i,r){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},Ut=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 Ce(this.elements,e.elements),this}},ve=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Nt=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,dr={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},we=class Ui{constructor(t,i,r){this.r=1,this.g=1,this.b=1,t!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(t,i,r):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let i=t.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let s=parseInt(r,16);r.length===6&&!Number.isNaN(s)&&this.setHex(s)}else if(i in dr)this.setHex(dr[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let s=n=>ve(Math.max(0,Math.min(1,(parseFloat(n)||0)/(n.endsWith("%")?100:255))));this.setRGB(s(r[0]),s(r[1]),s(r[2]))}}return this}setHSL(t,i,r){if(t=((Number(t)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let o=ve(r);return this.setRGB(o,o,o)}let s=r<=.5?r*(1+i):r+i-r*i,n=2*r-s,a=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?n+(s-n)*6*o:o<1/2?s:o<2/3?n+(s-n)*6*(2/3-o):n);return this.setRGB(ve(a(t+1/3)),ve(a(t)),ve(a(t-1/3)))}lerp(t,i){return this.lerpColors(this,t,i)}lerpColors(t,i,r){let s=Number(r)||0;return this.setRGB(t.r+(i.r-t.r)*s,t.g+(i.g-t.g)*s,t.b+(i.b-t.b)*s)}multiplyScalar(t){let i=Number(t)||0;return this.setRGB(this.r*i,this.g*i,this.b*i)}setScalar(t){let i=Number(t)||0;return this.setRGB(i,i,i)}setHex(t){let i=Math.floor(t);return this.setRGB(ve((i>>16&255)/255),ve((i>>8&255)/255),ve((i&255)/255))}setRGB(t,i,r){return this.r=Number(t),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.setRGB(ve(this.r),ve(this.g),ve(this.b))}convertLinearToSRGB(){return this.setRGB(Nt(this.r),Nt(this.g),Nt(this.b))}getHex(){let t=i=>Math.round(Nt(Math.max(0,Math.min(1,i)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(t){return this.setRGB(t.r,t.g,t.b)}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new Ui(this.r,this.g,this.b)}},Tr={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,i)=>Math.max(t,Math.min(i,e)),lerp:(e,t,i)=>e+(t-e)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},ge=class ki{constructor(t,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=i;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/i)}getX(t){return this.array[t*this.itemSize]}getY(t){return this.array[t*this.itemSize+1]}getZ(t){return this.array[t*this.itemSize+2]}setX(t,i){return this.array[t*this.itemSize]=i,this.needsUpdate=!0,this}setY(t,i){return this.array[t*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(t,i){return this.array[t*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(t,i,r,s){let n=t*this.itemSize;return this.array[n]=i,this.array[n+1]=r,this.array[n+2]=s,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new ki(new t(this.array),this.itemSize)}},Ot=class extends ge{constructor(e,t){super(e instanceof Float32Array||Array.isArray(e)?e:new Float32Array(e),t)}},Bt=class extends ge{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},Vt=class extends ge{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},de=class Oi{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,i){return this.attributes[t]=i,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof ge)this.index=t;else if(Array.isArray(t)){let i=0;for(let r of t)r>i&&(i=r);this.index=new ge(new(i>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new ge(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let i=!1;if(typeof i=="function"){let l=i(t.array,this.index?.array);return this.setAttribute("normal",new ge(l,3)),this}let r=t.count,s=t.array,n=new Float32Array(r*3),a=this.index?.array,o=a?a.length:r;for(let l=0;l<o;l+=3){let h=(a?a[l]:l)*3,u=(a?a[l+1]:l+1)*3,f=(a?a[l+2]:l+2)*3,g=s[u],w=s[u+1],p=s[u+2],b=s[f]-g,T=s[f+1]-w,x=s[f+2]-p,M=s[h]-g,c=s[h+1]-w,m=s[h+2]-p,v=T*m-x*c,S=x*M-b*m,D=b*c-T*M;n[h]+=v,n[h+1]+=S,n[h+2]+=D,n[u]+=v,n[u+1]+=S,n[u+2]+=D,n[f]+=v,n[f+1]+=S,n[f+2]+=D}for(let l=0;l<r*3;l+=3){let h=n[l],u=n[l+1],f=n[l+2],g=Math.hypot(h,u,f)||1;n[l]=h/g,n[l+1]=u/g,n[l+2]=f/g}return this.setAttribute("normal",new ge(n,3)),this}setFromBuffers(t,i,r,s){this.setAttribute("position",new ge(t,3)),this.setAttribute("normal",new ge(i,3)),this.setAttribute("uv",new ge(r,2)),this.setIndex(s)}setFromPoints(t){let i=[];if(Array.isArray(t))for(let r of t)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new ge(i,3))}computeBoundingBox(){let t=this.attributes.position,i=new ee(1/0,1/0,1/0),r=new ee(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let s=0;s<t.count;s++){let n=t.getX(s),a=t.getY(s),o=t.getZ(s);n<i.x&&(i.x=n),a<i.y&&(i.y=a),o<i.z&&(i.z=o),n>r.x&&(r.x=n),a>r.y&&(r.y=a),o>r.z&&(r.z=o)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,i){let r=this.attributes.position;if(r){let s=r.array;for(let n=0;n<s.length;n+=3)t(s,n);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,i=0,r=0){return this._xform((s,n)=>{s[n]+=t,s[n+1]+=i,s[n+2]+=r})}scale(t=1,i=1,r=1){return this._xform((s,n)=>{s[n]*=t,s[n+1]*=i,s[n+2]*=r},!0)}_rot(t,i,r){let s=Math.cos(r),n=Math.sin(r);for(let a of[this.attributes.position,this.attributes.normal]){if(!a)continue;let o=a.array;for(let l=0;l<o.length;l+=3){let h=o[l+t],u=o[l+i];o[l+t]=h*s-u*n,o[l+i]=h*n+u*s}a.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let i=this.attributes.position;if(i&&t?.elements){let r=new ee;for(let s=0;s<i.count;s++)r.set(i.getX(s),i.getY(s),i.getZ(s)).applyMatrix4(t),i.setXYZ(s,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let t=new Oi;t.name=this.name;for(let i of Object.keys(this.attributes))t.attributes[i]=this.attributes[i].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},at=class extends de{constructor(e=1,t=1,i=1){super();let r=e/2,s=t/2,n=i/2,a=[-r,-s,n,r,-s,n,r,s,n,-r,s,n,r,-s,-n,-r,-s,-n,-r,s,-n,r,s,-n,-r,s,n,r,s,n,r,s,-n,-r,s,-n,-r,-s,-n,r,-s,-n,r,-s,n,-r,-s,n,r,-s,n,r,-s,-n,r,s,-n,r,s,n,-r,-s,-n,-r,-s,n,-r,s,n,-r,s,-n],o=[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],l=[],h=[];for(let u=0;u<6;u++){let f=u*4;l.push(0,0,1,0,1,1,0,1),h.push(f,f+1,f+2,f,f+2,f+3)}this.setFromBuffers(a,o,l,h)}},zt=class extends de{constructor(e=1,t=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let s=[],n=[],a=[],o=[];for(let l=0;l<=r;l++){let h=l/r;for(let u=0;u<=i;u++){let f=u/i;if(s.push((f-.5)*e,(.5-h)*t,0),n.push(0,0,1),a.push(f,1-h),l>0&&u>0){let g=(i+1)*l+u-1,w=g-(i+1);o.push(w,g,w+1,g,g+1,w+1)}}}this.setFromBuffers(s,n,a,o)}},Gt=class extends de{constructor(e=1,t=16,i=12,r=0,s=Math.PI*2,n=0,a=Math.PI){super(),t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));let o=[],l=[],h=[],u=[],f=Math.min(n+a,Math.PI);for(let g=0;g<=i;g++){let w=g/i,p=n+w*a;for(let b=0;b<=t;b++){let T=b/t,x=r+T*s,M=-Math.cos(x)*Math.sin(p),c=Math.cos(p),m=Math.sin(x)*Math.sin(p);if(o.push(e*M,e*c,e*m),l.push(M,c,m),h.push(T,1-w),g>0&&b>0){let v=(t+1)*g+b,S=v-(t+1),D=S-1,I=v-1;(g!==1||n>0)&&u.push(S,D,v),(g!==i||f<Math.PI)&&u.push(D,I,v)}}}this.setFromBuffers(o,l,h,u)}},ct=class extends de{constructor(e=1,t=1,i=1,r=16,s=1,n=!1,a=0,o=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),s=Math.max(1,Math.floor(Number(s)||1));let l=[],h=[],u=[],f=[],g=i/2,w=(t-e)/(i||1),p=r+1;for(let T=0;T<=s;T++){let x=T/s,M=x*(t-e)+e,c=g-x*i;for(let m=0;m<=r;m++){let v=m/r,S=a+v*o,D=Math.sin(S),I=Math.cos(S),P=Math.hypot(D,w,I)||1;if(l.push(M*D,c,M*I),h.push(D/P,w/P,I/P),u.push(v,1-x),T<s&&m<r){let N=T*p+m,C=N+p;f.push(N,C,N+1,C,C+1,N+1)}}}let b=(T,x)=>{if(n||T<=0)return;let M=x*g,c=l.length/3;l.push(0,M,0),h.push(0,x,0),u.push(.5,.5);let m=c+1;for(let v=0;v<=r;v++){let S=a+v/r*o,D=Math.sin(S),I=Math.cos(S);l.push(T*D,M,T*I),h.push(0,x,0),u.push(I*.5+.5,.5+x*D*.5),v<r&&f.push(c,m+v+(x>0?0:1),m+v+(x>0?1:0))}};b(e,1),b(t,-1),this.setFromBuffers(l,h,u,f)}},Ht=class extends ct{constructor(e=1,t=1,i=16,r=1,s=!1,n=0,a=Math.PI*2){super(0,e,t,i,r,s,n,a)}},$t=class extends de{constructor(e=1,t=.4,i=12,r=48,s=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let n=[],a=[],o=[],l=[];for(let h=0;h<=i;h++){let u=h/i*Math.PI*2,f=Math.cos(u),g=Math.sin(u);for(let w=0;w<=r;w++){let p=w/r*s,b=Math.cos(p),T=Math.sin(p);if(n.push((e+t*f)*b,(e+t*f)*T,t*g),a.push(f*b,f*T,g),o.push(w/r,h/i),h>0&&w>0){let x=(r+1)*h+w-1,M=x-(r+1);l.push(x,M,x+1,M,M+1,x+1)}}}this.setFromBuffers(n,a,o,l)}};function _r(e,t,i,r,s){let n=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),a=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),o=Number(r)||.1,l=[],h=[],u=[],f=[],g=[],w=new ee,p=new ee,b=new ee;for(let x=0;x<=n;x++){let M=new ee;s(x/n,M),g.push(M)}let T=a+1;for(let x=0;x<=n;x++){let M=x/n,c=g[x];w.subVectors(g[Math.min(n,x+1)],g[Math.max(0,x-1)]).normalize(),x===0&&p.set(Math.abs(w.y)>.9?1:0,Math.abs(w.y)>.9?0:1,0),b.crossVectors(w,p).normalize(),p.crossVectors(b,w).normalize();for(let m=0;m<=a;m++){let v=m/a*Math.PI*2,S=-Math.cos(v),D=Math.sin(v),I=S*p.x+D*b.x,P=S*p.y+D*b.y,N=S*p.z+D*b.z;if(l.push(c.x+o*I,c.y+o*P,c.z+o*N),h.push(I,P,N),u.push(M,m/a),x>0&&m>0){let C=T*(x-1)+m-1,L=C+T;f.push(C,L,C+1,L,L+1,C+1)}}}e.setFromBuffers(l,h,u,f)}var Xt=class extends de{constructor(e=1,t=.4,i=64,r=8,s=2,n=3){super(),i=Math.floor(i),r=Math.floor(r),_r(this,i,r,t,(a,o)=>{let l=a*s*Math.PI*2,h=n/s*l,u=e*(2+Math.cos(h))*.5;o.set(u*Math.cos(l),u*Math.sin(l),e*Math.sin(h)*.5)})}},Fe=class{getPoint(e,t=new ee){return t}getPointAt(e,t=new ee){return this.getPoint(e,t)}getTangent(e,t=new ee){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),i=[];for(let r=0;r<=t;r++)i.push(this.getPoint(r/t));return i}getSpacedPoints(e=5){return this.getPoints(e)}},Wt=class extends Fe{constructor(e=new ee,t=new ee){super(),this.v1=e,this.v2=t}getPoint(e,t=new ee){return t.lerpVectors(this.v1,this.v2,e)}},jt=class extends Fe{constructor(e=new ee,t=new ee,i=new ee){super(),this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new ee){return t.lerpVectors(this.v0,this.v1,e).lerp(new ee().lerpVectors(this.v1,this.v2,e),e)}},Kt=class extends Fe{constructor(e=new ee,t=new ee,i=new ee,r=new ee){super(),this.v0=e,this.v1=t,this.v2=i,this.v3=r}getPoint(e,t=new ee){let i=new ee().lerpVectors(this.v0,this.v1,e),r=new ee().lerpVectors(this.v1,this.v2,e),s=new ee().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(i.lerp(r,e),r.lerp(s,e),e)}},Yt=class extends Fe{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new ee){let i=this.points,r=i.length;if(!r)return t.set(0,0,0);if(r===1)return t.copy(i[0]);let s=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(e)||0)),n=Math.floor(s),a=s-n;!this.closed&&n>=r-1&&(n=r-2,a=1);let o=b=>i[this.closed?(b%r+r)%r:Math.max(0,Math.min(r-1,b))],l=o(n-1),h=o(n),u=o(n+1),f=o(n+2),g=a*a,w=g*a,p=(b,T,x,M)=>.5*(2*T+(x-b)*a+(2*b-5*T+4*x-M)*g+(3*T-b-3*x+M)*w);return t.set(p(l.x,h.x,u.x,f.x),p(l.y,h.y,u.y,f.y),p(l.z,h.z,u.z,f.z))}},ut=class extends de{constructor(e=[new Se(0,-.5),new Se(.5,0),new Se(0,.5)],t=12,i=0,r=Math.PI*2){super();let s=Array.isArray(e)&&e.length>=2?e:[new Se(.2,0),new Se(.2,.5)],n=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),a=[],o=[],l=[],h=[],u=s.length;for(let f=0;f<=n;f++){let g=f/n,w=i+g*r,p=Math.sin(w),b=Math.cos(w),T=f*u;for(let x=0;x<u;x++){let M=s[x],c=Number(M?.x)||0,m=Number(M?.y)||0;a.push(c*p,m,c*b);let v=s[Math.max(0,x-1)],S=s[Math.min(u-1,x+1)],D=(Number(S?.x)||0)-(Number(v?.x)||0),I=(Number(S?.y)||0)-(Number(v?.y)||0),P=Math.hypot(I,D)||1;if(o.push(I/P*p,-D/P,I/P*b),l.push(g,x/(u-1)),f<n&&x<u-1){let N=T+x,C=N+u;h.push(N,C,N+1,C,C+1,N+1)}}}this.setFromBuffers(a,o,l,h)}},qt=class extends de{constructor(e,t=64,i=1,r=8,s=!1){super(),_r(this,t,r,i,(n,a)=>{let o=e?.getPointAt??e?.getPoint;if(typeof o=="function"){let l=o.call(e,n,a);l&&l!==a&&a.copy(l)}else a.set(0,n,0)})}},Lt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",qe=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Se(1,1),this.offset=new Se(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Zt=class extends qe{constructor(e=null,t=1,i=1,r=1023,s=1009,n,a=1001,o=1001,l=1003,h=1003,u=1,f=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let g=Number(t),w=Number(i),p=e&&typeof e.length=="number"?e:null;this.width=g,this.height=w,this.image={data:p,width:g,height:w},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(a)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(l)||1003,this.minFilter=Number(h)||1003,this.colorSpace=f||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,i=Number(e?.width??this.width),r=Number(e?.height??this.height);if(!t||!t.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let s=Math.max(1,i|0),n=Math.max(1,r|0),a=s*n,o=this.format,l=o===1021||o===1024||o===1028||t.length===a?1:o===1025||o===1030||t.length===a*2?2:o===1022||t.length===a*3?3:4,h=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,u=Math.min(s,48),f=Math.min(n,48),g=(this.flipY?257:1)^this.colorSpace.length^t.length,w=Math.max(1,t.length>>6|0);for(let L=0;L<t.length;L+=w)g=Math.imul(g^(t[L]*256|0),16777619)|0;if(g===this._sig&&this.source)return;this._sig=g;let p=f*(1+u*4),b=new Uint8Array(68+p),T=new DataView(b.buffer);T.setUint32(0,2303741511),T.setUint32(4,218765834),T.setUint32(8,13),T.setUint32(12,1229472850),T.setUint32(16,u),T.setUint32(20,f),b[24]=8,b[25]=6,T.setUint32(29,Dt(b.subarray(12,29))),T.setUint32(33,p+11),T.setUint32(37,1229209940),b[41]=120,b[42]=1,b[43]=1,T.setUint16(44,p,!0),T.setUint16(46,~p&65535,!0);let x=48,M=1,c=0,m=0,v=0,S=0,D=0,I=L=>{if(!Number.isFinite(L))return 0;let E=h&&L<=1?L*255:L;return E>0?E<255?E+.5|0:255:0};for(let L=0;L<f;L++){let E=L*n/f|0,y=this.flipY?n-1-E:E;b[x++]=0,c+=M;for(let F=0;F<u;F++){let z=(y*s+(F*s/u|0))*l,A=o===1021?255:I(t[z]??0),_=l>=3||o===1030?I(t[z+1]??0):A,d=l>=3?I(t[z+2]??0):o===1030?0:A,R=l===4?I(t[z+3]??255):o===1021?I(t[z]??255):o===1025?I(t[z+1]??255):255;b[x++]=A,M+=A,c+=M,b[x++]=_,M+=_,c+=M,b[x++]=d,M+=d,c+=M,b[x++]=R,M+=R,c+=M,m+=A,v+=_,S+=d,D+=R}M%=65521,c%=65521}T.setUint32(x,(c<<16|M)>>>0),T.setUint32(x+4,Dt(b.subarray(37,x+4))),T.setUint32(x+12,1229278788),T.setUint32(x+16,2923585666);let P=u*f*255,N=this.colorSpace==="srgb-linear";this.avgColor=[N?m/P:ve(m/P),N?v/P:ve(v/P),N?S/P:ve(S/P),D/P];let C=["data:image/png;base64,"];for(let L=0;L<b.length;L+=3){let E=b[L]<<16|(b[L+1]??0)<<8|(b[L+2]??0);C.push(Lt[E>>18&63]+Lt[E>>12&63]+(L+1<b.length?Lt[E>>6&63]:"=")+(L+2<b.length?Lt[E&63]:"="))}this.source=C.join("")}},Jt=class{load(e,t){let i=new qe(e);return t?.(i),i}};function xe(e,t){return e!==void 0?Number(e):t}function Pn(e,t){return e!==void 0?!!e:t}var Me=class{constructor(e={}){this.name=e.name||"",this.color=new we(e.color??16777215),this.emissive=new we(e.emissive??0),this.emissiveIntensity=xe(e.emissiveIntensity,1),this.roughness=xe(e.roughness,.5),this.metalness=xe(e.metalness,0),this.opacity=xe(e.opacity,1),this.transparent=Pn(e.transparent,!1),this.wireframe=Pn(e.wireframe,!1),this.side=xe(e.side,2),this.doubleSided=Pn(e.doubleSided,!0),this.map=e.map||null;for(let t of["normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])e[t]&&(this[t]=e[t]);this.clearcoat=xe(e.clearcoat,0),this.clearcoatRoughness=xe(e.clearcoatRoughness,0),this.sheen=xe(e.sheen,0),this.sheenColor=new we(e.sheenColor??0),this.sheenRoughness=xe(e.sheenRoughness,0),this.transmission=xe(e.transmission,0),this.thickness=xe(e.thickness,0),this.attenuationColor=new we(e.attenuationColor??16777215),this.attenuationDistance=xe(e.attenuationDistance,1/0),this.ior=xe(e.ior,1.5),this.dispersion=xe(e.dispersion,0),this.iridescence=xe(e.iridescence,0),this.iridescenceIOR=xe(e.iridescenceIOR,1.3)}dispose(){}},ze=class extends Me{},Qt=class extends Me{},en=class extends Me{},tn=class extends Me{},nn=class extends Me{},Ae=class $i{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 ee,this.rotation=new ot,this.quaternion=new Ye,this.scale=new ee(1,1,1),this.matrix=new Be,this.matrixWorld=new Be,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,i=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),s=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(i,r,s)})}add(...t){for(let i of t)i&&i instanceof $i&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...t){for(let i of t){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(t){let i=new Set,r=[this];for(;r.length>0;){let s=r.pop();if(!s||typeof s!="object"||i.has(s))continue;i.add(s),t(s);let n=s.children;if(Array.isArray(n))for(let a=n.length-1;a>=0;a--)r.push(n[a])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(i=>{Sr(i),(i.matrixAutoUpdate||t)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(t,i,r){let s=typeof t=="object"?t:new ee(t,i,r);this.target instanceof ee?this.target.copy(s):this.target?.position instanceof ee&&this.target.position.copy(s),this.updateMatrixWorld(!0);let n=new Be;n.lookAt(this.position,s,new ee(0,1,0));let a=n.elements,o=a[0],l=a[4],h=a[8],u=a[1],f=a[5],g=a[9],w=a[2],p=a[6],b=a[10],T=o+f+b;if(T>0){let x=.5/Math.sqrt(T+1);this.quaternion.set((p-g)*x,(h-w)*x,(u-l)*x,.25/x)}}translateOnAxis(t,i){let r=t.clone().applyMatrix4(new Be().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(t){return this.translateOnAxis(new ee(1,0,0),t)}translateY(t){return this.translateOnAxis(new ee(0,1,0),t)}translateZ(t){return this.translateOnAxis(new ee(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}_chain(){let t=[];for(let i=this;i&&t.length<64;i=i.parent)t.push(i);return t}_syncWorld(){let t=this._chain();for(let i=t.length-1;i>=0;i--){let r=t[i];r.updateMatrix?.(),r.parent?.matrixWorld?r.matrixWorld.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrixWorld?.copy(r.matrix)}return this.matrixWorld.elements}getWorldPosition(t=new ee){let i=this._syncWorld();return t.set(i[12],i[13],i[14])}getWorldScale(t=new ee){let i=this._syncWorld();return t.set(Math.hypot(i[0],i[1],i[2]),Math.hypot(i[4],i[5],i[6]),Math.hypot(i[8],i[9],i[10]))}getWorldDirection(t=new ee){let i=this._syncWorld();return t.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(t=new Ye){let i=this._chain();t.set(0,0,0,1);for(let r=i.length-1;r>=0;r--)t.multiply(i[r].quaternion);return t}clone(t=!0){let i=this instanceof Ve?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Ie?new Ie(this.geometry,this.material):new this.constructor;i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,i.castShadow=this.castShadow,i.receiveShadow=this.receiveShadow;try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(t)for(let r of this.children)i.add(r.clone(!0));return i}},rn=class extends Ae{},Ie=class extends Ae{constructor(e,t){super(),this.isMesh=!0;let i=Array.isArray(t)?t[0]:t;this.geometry=e instanceof de?e:e?(He("unsupported geometry","BoxGeometry"),new at(.5,.5,.5)):new de,this.material=i instanceof Me?i:i?(He("unsupported material","MeshStandardMaterial"),new ze({color:13421772})):new ze}};function Sr(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=le().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var lt=1e4,mt=class extends Ie{constructor(e,t,i=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>lt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${lt})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let n=0;n<this.count;n++){let a=n*16;s[a]=1,s[a+5]=1,s[a+10]=1,s[a+15]=1}this.instanceMatrix=new ge(s,16)}setMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++){let a=Number(t.elements[n]);r[s+n]=Number.isFinite(a)?a:n%5===0?1:0}}getMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++)t.elements[n]=r[s+n]}setColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let n=new Float32Array(this.count*3);n.fill(1),this.instanceColor=new ge(n,3)}let r=this.instanceColor.array,s=i*3;r[s]=Number.isFinite(t.r)?t.r:1,r[s+1]=Number.isFinite(t.g)?t.g:1,r[s+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){t.setRGB(1,1,1);return}let r=this.instanceColor.array,s=i*3;t.setRGB(r[s],r[s+1],r[s+2])}dispose(){}},Ge=class extends Ae{constructor(e=16777215,t=1){super(),this.color=new we(e),this.intensity=Number(t),this.type="directional"}},ht=class extends Ge{constructor(e,t){super(e,t),this.type="ambient"}},sn=class extends Ge{constructor(e,t){super(e,t),this.target=new Ae,this.type="directional"}},ft=class extends Ge{constructor(e,t,i=0,r=2){super(e,t),this.type="point",this.distance=i,this.decay=r}},dt=class extends Ae{},on=class extends dt{constructor(e=45,t=1,i=.1,r=1e3){super(),this.target=new ee(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(i),this.far=Number(r)}},pt=class extends Ae{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return De.validate(this),Ke(this)}toGLB(){return De.validate(this),tt(this)}toUSDZ(){return De.validate(this),nt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(i=>{if(i instanceof Ie){let r=new Float32Array(i.matrixWorld.elements);e.set(t,r),i.name&&e.set(i.name,r),t++}}),e}},Fn=Ke,kn=tt,wr=nt,De=class{static validate(e){let t=0,i=0,r=0,s=new Set,n=(o,l,h)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${l}). Found: ${h}`)},a=(o,l)=>{if(!Number.isFinite(l))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(l)}), which cannot be bounds-checked.`);return l};e.traverse(o=>{if(Sr(o),o instanceof Ie||o.geometry?.attributes?.position?.count){if(r++,r>1e3&&n("MESHES",1e3,r),o instanceof mt){let h=a("instance",o.count);(h<0||h>lt)&&n("INSTANCES",lt,h)}let l=o.geometry;if(l){let h=0;if(l.attributes.position&&(h=a("vertex",l.attributes.position.count),t+=h,t>1e5&&n("VERTICES",1e5,t)),l.index){let u=a("index",l.index.count);i+=u,i>3e5&&n("INDICES",3e5,i);let f=l.index.array;if(f&&h>0){let g=Math.min(u,f.length);for(let w=0;w<g;w++){let p=f[w];if(!Number.isFinite(p)||p<0||p>=h)throw new Error(`SecurityError: Index buffer value (${String(p)}) out of vertex bounds [0, ${h}).`)}}}}if(o.material){let h=o.material;for(let u of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])h[u]&&s.add(h[u])}}}),s.size>16&&n("TEXTURES",16,s.size);for(let o of s){let l=o,h=l.image,u=Number(h?.width??l.width??0)||0,f=Number(h?.height??l.height??0)||0;(!Number.isFinite(u)||!Number.isFinite(f)||u>2048||f>2048)&&n("TEXTURE_DIMENSION",2048,Math.max(u,f))}}},an=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,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 i=new we(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){De.validate(e);let r=(s,n)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(n&&n.length?self.postMessage(s,n):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),n={};for(let[a,o]of s.entries())n[a]=Array.from(o);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:n})}else{this.hasInitialModelRendered=!0;let s=Fn(e),n=kn(e),a=(s.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:n.buffer,dynamicLights:a,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[n.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(e.getMeshTransforms()):(i.loadModel(e.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function pr(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var cn=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=pr(),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=pr();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function mi(){}var it=new Proxy(mi,{get:(e,t)=>{if(t==="isProxy")return!0;if(!(t==="constructor"||t==="__proto__"||t==="prototype"))return t==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:t==="shadowMap"?{enabled:!1,type:0}:t==="capabilities"?{isWebGL2:!0,maxTextures:16}:t===Symbol.toPrimitive?()=>0:it},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>it,construct:()=>it}),br=(()=>{try{if(typeof document>"u")return null;let e=document.currentScript;return e?.src?e.src:e?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([e.textContent],{type:"text/javascript"})):null}catch{return null}})();function _n(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Ze(e,t){if(!e||typeof e!="string")return!1;let i=e.trim();if(!i)return!1;try{let r=new URL(i,_n());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||t?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var gr,rt;function Ar(e){if(!Ze(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(rt===void 0||gr!==t){gr=t;try{rt=t.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Ze(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{rt=null}}return rt?rt.createScriptURL(e):e}function hi(e){le().sandboxEngineSrc=e}function Un(){let e=le().sandboxEngineSrc;if(e)return e;if(br)return br;try{if(typeof document>"u")return null;let t=_n(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let s=r.src;if(!s)continue;let n=new URL(s,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(n)&&Ze(s,{requireSameOrigin:!0}))return s}}catch{}return null}function On(e,t){if(!Ze(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,_n()).href}function fi(){let e=Un();if(!e)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.");return On(e,"sandbox engine")}function di(e){le().sandboxIframeSrc=e}function Er(){let e=le().sandboxIframeSrc;if(e)return e;let t=Un();if(!t||!Ze(t))return null;let i=new URL(t,_n());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function pi(){let e=Er();if(!e)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");return On(e,"sandbox iframe")}function bi(e){le().allowClientScripts=e}function Rr(){return!!le().allowClientScripts}function gi(e){return On(e,"procedural scene script")}var yi=["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 xi(e,t){let i=self,r=e.nonce,s=e.engineSrc,n=e.allowedScriptUrl,a=e.allowClientScripts,o=e.revoked,l=i.postMessage.bind(i);function h(c){l({type:"ERROR",nonce:r,message:String(c)})}let u=typeof i.importScripts=="function"?i.importScripts.bind(i):null,f=n,g=null;try{let c=s;if(typeof i.trustedTypes<"u"&&i.trustedTypes&&typeof i.trustedTypes.createPolicy=="function")try{let m={createScriptURL:function(S){if(S!==s&&(!n||S!==n))throw new TypeError("Disallowed worker importScripts URL");return S}};a&&(m.createScript=function(S){return String(S)});let v=i.trustedTypes.createPolicy("three-live#worker-boot",m);c=v.createScriptURL(s),n&&(f=v.createScriptURL(n)),a&&typeof v.createScript=="function"&&(g=v.createScript.bind(v))}catch{}u(c)}catch(c){h('Sandbox failed to load the Three-Live engine from "'+s+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(c&&c.message||c));return}let w=i.THREE;if(!w||typeof w.Scene!="function"){h('Sandbox loaded "'+s+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(t)){let c=i.__THREE_LIVE_REGISTRY__;for(let m=0;m<t.length;m++)if(typeof t[m]=="function")try{t[m](w,c)}catch{}}function p(c,m,v){let S=i;for(;S&&S!==Object.prototype;){if(!v&&S!==i)try{delete S[c]}catch{}if(!v||S===i||Object.prototype.hasOwnProperty.call(S,c))try{Object.defineProperty(S,c,v?{value:m,writable:!1,configurable:!1}:{value:m,writable:!1,configurable:!1,enumerable:!1})}catch{}try{S=Object.getPrototypeOf(S)}catch{break}}}for(let c=0;c<o.length;c++)p(o[c],void 0);p("performance",Object.freeze({now:function(){return Date.now()}}));let b=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],T=!1;function x(c,m){if(c.type==="3D_MODEL_READY"){if(T)return;T=!0}c.nonce=r,m&&m.length?l(c,m):l(c)}p("postMessage",function(c,m){if(!c||b.indexOf(c.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+b.join(", ")+").");x(c,m)},!0);let M=!1;i.onmessage=function(c){let m=c&&c.data;if(!(!m||m.nonce!==r)&&!(m.type!=="EXECUTE"&&m.type!=="EXECUTE_URL")&&!M){M=!0;try{let v=new w.Scene,S=new w.PerspectiveCamera(60,1,.1,1e3),D=new w.WebGLRenderer({isSandboxed:!0});if(m.type==="EXECUTE_URL"){if(!n||m.scriptUrl!==n||typeof u!="function"){h("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let I=f||n,P=u;if(u=null,f=null,i.THREE=w,i.scene=v,i.camera=S,i.renderer=D,P(I),typeof i.__THREE_LIVE_SCENE__=="function"){let N=i.__THREE_LIVE_SCENE__(w,v,S,D);N&&typeof N.toGLB=="function"&&(v=N)}else i.scene&&typeof i.scene.toGLB=="function"&&(v=i.scene)}else{if(!a){h("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let I=g?(0,eval)(g(`(function (THREE, scene, camera, renderer) {
|
|
331
|
+
${_.body}${b(u)}${h(u)}${_.tail}}
|
|
332
|
+
`}}if(y+=`}
|
|
333
|
+
`,i.length>0){y+=`def Scope "Lights"
|
|
334
|
+
{
|
|
335
|
+
`;let m=new Set;for(let u=0;u<i.length;u++){let g=i[u],p=qn(m,ut(g.name,`Light_${u}`)),x=g.type==="directional"?"DistantLight":g.type==="spot"?"DiskLight":"SphereLight",w=g.type==="spot"?'["ShapingAPI", "ShadowAPI"]':'["ShadowAPI"]',[_,N,P]=g.color||[1,1,1],[E,T,S]=g.position||[0,5,5],A=-E,D=-T,R=-S;g.direction&&g.direction.length>=3&&(g.type==="directional"?(A=-g.direction[0],D=-g.direction[1],R=-g.direction[2]):(A=g.direction[0],D=g.direction[1],R=g.direction[2]));let[F,k,V,L]=Ar(A,D,R),O="",c=[];g.type!=="directional"&&(Math.abs(E)>1e-7||Math.abs(T)>1e-7||Math.abs(S)>1e-7)&&(O+=`double3 xformOp:translate = ${Ne(E,T,S)}
|
|
336
|
+
`,c.push('"xformOp:translate"')),g.type!=="point"&&(1-Math.abs(L)>1e-7||Math.hypot(F,k,V)>1e-7)&&(O+=`quatf xformOp:orient = ${ct(L,F,k,V)}
|
|
337
|
+
`,c.push('"xformOp:orient"')),c.length>0&&(O+=`uniform token[] xformOpOrder = [${c.join(", ")}]
|
|
338
|
+
`);let I="";if(g.type==="spot"){let C=(g.outerConeAngle??Math.PI/3)*180/Math.PI,U=(g.innerConeAngle??C*.8)*180/Math.PI,j=C>1e-4?Math.max(0,Math.min(1,1-U/C)):0;I=`float inputs:shaping:cone:angle = ${ye(C)}
|
|
339
|
+
float inputs:shaping:cone:softness = ${ye(j)}
|
|
340
|
+
`}y+=`def ${x} "${p}" (
|
|
341
|
+
prepend apiSchemas = ${w}
|
|
342
|
+
)
|
|
343
|
+
{
|
|
344
|
+
color3f inputs:color = ${Ne(_,N,P)}
|
|
345
|
+
float inputs:intensity = ${ye(g.intensity??1)}
|
|
346
|
+
bool inputs:shadow:enable = 1
|
|
347
|
+
${I}${O}}
|
|
348
|
+
`}y+=`}
|
|
349
|
+
`}return y+=`}
|
|
350
|
+
`,y}var Bt=null;function Vt(t){if(!Bt){Bt=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let n=0;n<8;n++)r=r&1?3988292384^r>>>1:r>>>1;Bt[i]=r}}let e=4294967295;for(let i=0;i<t.length;i++)e=Bt[(e^t[i])&255]^e>>>8;return(e^4294967295)>>>0}function Ri(t){let e=[],i=0,r=[];for(let f of t){let b=Zn(f.filename),h=Vt(f.data),d=f.data.length,v=30+b.length,M=(i+v)%64,m=M!==0?64-M:0;m>0&&m<4&&(m+=64);let u=new Uint8Array(v+m),g=new DataView(u.buffer);g.setUint32(0,67324752,!0),g.setUint16(4,20,!0),g.setUint32(14,h,!0),g.setUint32(18,d,!0),g.setUint32(22,d,!0),g.setUint16(26,b.length,!0),g.setUint16(28,m,!0),u.set(b,30),m>=4&&(g.setUint16(v,6534,!0),g.setUint16(v+2,m-4,!0)),e.push({offset:i,size:d,crc:h,filenameBytes:b,entry:f}),r.push(u,f.data),i+=u.length+f.data.length}let n=i;for(let f of e){let b=new Uint8Array(46+f.filenameBytes.length),h=new DataView(b.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint32(16,f.crc,!0),h.setUint32(20,f.size,!0),h.setUint32(24,f.size,!0),h.setUint16(28,f.filenameBytes.length,!0),h.setUint32(42,f.offset,!0),b.set(f.filenameBytes,46),r.push(b),i+=b.length}let s=i-n,a=new Uint8Array(22),o=new DataView(a.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,e.length,!0),o.setUint16(10,e.length,!0),o.setUint32(12,s,!0),o.setUint32(16,n,!0),r.push(a),i+=22;let l=new Uint8Array(i),y=0;for(let f of r)l.set(f,y),y+=f.length;return l}function Cr(t){let e=[{filename:"model.usda",data:Zn(Ei(t))}],i=new Set(["model.usda"]),r=[...t];for(;r.length>0;){let n=r.pop();for(let s of n.textures||[])s?.file&&s.data?.byteLength&&!i.has(s.file)&&(i.add(s.file),e.push({filename:s.file,data:s.data}));if(n.children)for(let s=n.children.length-1;s>=0;s--)r.push(n.children[s])}return Ri(e)}function mt(t){return Cr(_i(t))}function zt(t){return Cr(Lr(Ut(t)))}function Jn(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():zt(t)}var Ee=class Ji{constructor(e=0,i=0){this.x=Number(e),this.y=Number(i)}set(e,i){return this.x=Number(e),this.y=Number(i),this}clone(){return new Ji(this.x,this.y)}copy(e){return this.set(e.x,e.y)}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}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e)}get width(){return this.x}set width(e){this.x=Number(e)}get height(){return this.y}set height(e){this.y=Number(e)}},Q=class Qi{constructor(e=0,i=0,r=0){this.x=Number(e),this.y=Number(i),this.z=Number(r)}set(e,i,r){return this.x=Number(e),this.y=Number(i),this.z=Number(r),this}clone(){return new Qi(this.x,this.y,this.z)}copy(e){return this.set(e.x,e.y,e.z)}add(e){return this.addVectors(this,e)}addVectors(e,i){return this.set(e.x+i.x,e.y+i.y,e.z+i.z)}sub(e){return this.subVectors(this,e)}subVectors(e,i){return this.set(e.x-i.x,e.y-i.y,e.z-i.z)}multiplyScalar(e){return this.set(this.x*e,this.y*e,this.z*e)}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e,e)}addScaledVector(e,i){return this.set(this.x+e.x*i,this.y+e.y*i,this.z+e.z*i)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5?this.multiplyScalar(1/e):this}cross(e){return this.crossVectors(this,e)}crossVectors(e,i){let r=e.x,n=e.y,s=e.z,a=i.x,o=i.y,l=i.z;return this.set(n*l-s*o,s*a-r*l,r*o-n*a)}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)}lerp(e,i){return this.lerpVectors(this,e,i)}lerpVectors(e,i,r){return this.x=e.x+(i.x-e.x)*r,this.y=e.y+(i.y-e.y)*r,this.z=e.z+(i.z-e.z)*r,this}applyMatrix4(e){let i=this.x,r=this.y,n=this.z,s=e.elements,a=1/(s[3]*i+s[7]*r+s[11]*n+s[15]);return this.x=(s[0]*i+s[4]*r+s[8]*n+s[12])*a,this.y=(s[1]*i+s[5]*r+s[9]*n+s[13])*a,this.z=(s[2]*i+s[6]*r+s[10]*n+s[14])*a,this}},Wt=class{constructor(t=0,e=0,i=0,r=1){this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r)}set(t,e,i,r){return this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r),this}},pt=class es{constructor(e=0,i=0,r=0,n="XYZ"){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=n}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,i,r,n=this.order){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=n,this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.order)}clone(){return new es(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Qe=class ts{constructor(e=0,i=0,r=0,n=1){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(n)}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,i,r,n){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(n),this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.w)}clone(){return new ts(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(e,i=!0){let r=e.x,n=e.y,s=e.z,a=Math.cos(r/2),o=Math.cos(n/2),l=Math.cos(s/2),y=Math.sin(r/2),f=Math.sin(n/2),b=Math.sin(s/2);return this._x=y*o*l+a*f*b,this._y=a*f*l-y*o*b,this._z=a*o*b+y*f*l,this._w=a*o*l-y*f*b,i&&this._onChangeCallback?.(),this}setFromAxisAngle(e,i){let r=i/2,n=Math.sin(r);return this.set(e.x*n,e.y*n,e.z*n,Math.cos(r))}normalize(){let e=Math.hypot(this._x,this._y,this._z,this._w);return e===0?this.set(0,0,0,1):this.set(this._x/e,this._y/e,this._z/e,this._w/e)}setFromUnitVectors(e,i){let r=e.dot(i)+1;return r<1e-6?(Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,0):this.set(0,-e.z,e.y,0)).normalize():this.set(e.y*i.z-e.z*i.y,e.z*i.x-e.x*i.z,e.x*i.y-e.y*i.x,r).normalize()}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,i){let r=e.x,n=e.y,s=e.z,a=e.w,o=i.x,l=i.y,y=i.z,f=i.w;return this._x=r*f+a*o+n*y-s*l,this._y=n*f+a*l+s*o-r*y,this._z=s*f+a*y+r*l-n*o,this._w=a*f-r*o-n*l-s*y,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},We=class is{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 is;return e.copy(this),e}compose(e,i,r){return ot(this.elements,[i.x,i.y,i.z,i.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,i){return Me(this.elements,e.elements,i.elements),this}lookAt(e,i,r){return it(this.elements,[e.x,e.y,e.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let i=new Q(0,0,0),r=new Q(1,1,1);return this.compose(i,e,r)}makeTranslation(e,i,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(e,i,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},Xt=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[4]=1,t[8]=1,this}getNormalMatrix(t){return Fe(this.elements,t.elements),this}},Re=t=>t<=.04045?t/12.92:((t+.055)/1.055)**2.4,Gt=t=>t<=.0031308?t*12.92:1.055*t**(1/2.4)-.055,Dr={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},Pe=class rs{constructor(e,i,r){this.r=1,this.g=1,this.b=1,e!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(e,i,r):this.set(e))}set(e){return typeof e=="number"?this.setHex(e):typeof e=="string"?this.setStyle(e):(e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b)),this)}setStyle(e){let i=e.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let n=parseInt(r,16);r.length===6&&!Number.isNaN(n)&&this.setHex(n)}else if(i in Dr)this.setHex(Dr[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let n=s=>Re(Math.max(0,Math.min(1,(parseFloat(s)||0)/(s.endsWith("%")?100:255))));this.setRGB(n(r[0]),n(r[1]),n(r[2]))}}return this}setHSL(e,i,r){if(e=((Number(e)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let o=Re(r);return this.setRGB(o,o,o)}let n=r<=.5?r*(1+i):r+i-r*i,s=2*r-n,a=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?s+(n-s)*6*o:o<1/2?n:o<2/3?s+(n-s)*6*(2/3-o):s);return this.setRGB(Re(a(e+1/3)),Re(a(e)),Re(a(e-1/3)))}lerp(e,i){return this.lerpColors(this,e,i)}lerpColors(e,i,r){let n=Number(r)||0;return this.setRGB(e.r+(i.r-e.r)*n,e.g+(i.g-e.g)*n,e.b+(i.b-e.b)*n)}multiplyScalar(e){let i=Number(e)||0;return this.setRGB(this.r*i,this.g*i,this.b*i)}setScalar(e){let i=Number(e)||0;return this.setRGB(i,i,i)}setHex(e){let i=Math.floor(e);return this.setRGB(Re((i>>16&255)/255),Re((i>>8&255)/255),Re((i&255)/255))}setRGB(e,i,r){return this.r=Number(e),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.setRGB(Re(this.r),Re(this.g),Re(this.b))}convertLinearToSRGB(){return this.setRGB(Gt(this.r),Gt(this.g),Gt(this.b))}getHex(){let e=i=>Math.round(Gt(Math.max(0,Math.min(1,i)))*255);return e(this.r)<<16|e(this.g)<<8|e(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.setRGB(e.r,e.g,e.b)}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new rs(this.r,this.g,this.b)}},Qn=1234567,Br={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,i)=>Math.max(e,Math.min(i,t)),lerp:(t,e,i)=>t+(e-t)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randInt:(t,e)=>t+Math.floor(Math.random()*(e-t+1)),randFloat:(t,e)=>t+Math.random()*(e-t),randFloatSpread:t=>t*(.5-Math.random()),seededRandom:t=>{t!==void 0&&(Qn=Number.isFinite(t)?t|0:0);let e=Qn=Qn+1831565813|0;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}},we=class ss{constructor(e,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=i;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/i)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.itemSize>=2?this.array[e*this.itemSize+1]:0}getZ(e){return this.itemSize>=3?this.array[e*this.itemSize+2]:0}setX(e,i){return this.array[e*this.itemSize]=i,this.needsUpdate=!0,this}setY(e,i){return this.array[e*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(e,i){return this.array[e*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(e,i,r,n){let s=e*this.itemSize;return this.array[s]=i,this.array[s+1]=r,this.array[s+2]=n,this.needsUpdate=!0,this}setUsage(e){return this}clone(){let e=this.array?.constructor||Float32Array;return new ss(new e(this.array),this.itemSize)}},Kt=class extends we{constructor(t,e){super(t instanceof Float32Array||Array.isArray(t)?t:new Float32Array(t),e)}},Yt=class extends we{constructor(t,e){super(t instanceof Uint16Array?t:new Uint16Array(t),e)}},qt=class extends we{constructor(t,e){super(t instanceof Uint32Array?t:new Uint32Array(t),e)}},xe=class ns{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(e,i){return this.attributes[e]=i,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof we)this.index=e;else if(Array.isArray(e)){let i=0;for(let r of e)r>i&&(i=r);this.index=new we(new(i>65535?Uint32Array:Uint16Array)(e),1)}else e&&e.buffer&&(this.index=new we(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let i=!1;if(typeof i=="function"){let l=i(e.array,this.index?.array);return this.setAttribute("normal",new we(l,3)),this}let r=e.count,n=e.array,s=new Float32Array(r*3),a=this.index?.array,o=a?a.length:r;for(let l=0;l<o;l+=3){let y=(a?a[l]:l)*3,f=(a?a[l+1]:l+1)*3,b=(a?a[l+2]:l+2)*3,h=n[f],d=n[f+1],v=n[f+2],M=n[b]-h,m=n[b+1]-d,u=n[b+2]-v,g=n[y]-h,p=n[y+1]-d,x=n[y+2]-v,w=m*x-u*p,_=u*g-M*x,N=M*p-m*g;s[y]+=w,s[y+1]+=_,s[y+2]+=N,s[f]+=w,s[f+1]+=_,s[f+2]+=N,s[b]+=w,s[b+1]+=_,s[b+2]+=N}for(let l=0;l<r*3;l+=3){let y=s[l],f=s[l+1],b=s[l+2],h=Math.hypot(y,f,b)||1;s[l]=y/h,s[l+1]=f/h,s[l+2]=b/h}return this.setAttribute("normal",new we(s,3)),this}setFromBuffers(e,i,r,n){this.setAttribute("position",new we(e,3)),this.setAttribute("normal",new we(i,3)),this.setAttribute("uv",new we(r,2)),this.setIndex(n)}setFromPoints(e){let i=[];if(Array.isArray(e))for(let r of e)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new we(i,3))}computeBoundingBox(){let e=this.attributes.position,i=new Q(1/0,1/0,1/0),r=new Q(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let n=0;n<e.count;n++){let s=e.getX(n),a=e.getY(n),o=e.getZ(n);s<i.x&&(i.x=s),a<i.y&&(i.y=a),o<i.z&&(i.z=o),s>r.x&&(r.x=s),a>r.y&&(r.y=a),o>r.z&&(r.z=o)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let e=this.computeBoundingBox();return e.max.x<e.min.x?this:this.translate(-(e.min.x+e.max.x)*.5,-(e.min.y+e.max.y)*.5,-(e.min.z+e.max.z)*.5)}_xform(e,i){let r=this.attributes.position;if(r){let n=r.array;for(let s=0;s<n.length;s+=3)e(n,s);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(e=0,i=0,r=0){return this._xform((n,s)=>{n[s]+=e,n[s+1]+=i,n[s+2]+=r})}scale(e=1,i=1,r=1){return this._xform((n,s)=>{n[s]*=e,n[s+1]*=i,n[s+2]*=r},!0)}_rot(e,i,r){let n=Math.cos(r),s=Math.sin(r);for(let a of[this.attributes.position,this.attributes.normal]){if(!a)continue;let o=a.array;for(let l=0;l<o.length;l+=3){let y=o[l+e],f=o[l+i];o[l+e]=y*n-f*s,o[l+i]=y*s+f*n}a.needsUpdate=!0}return this}rotateX(e){return this._rot(1,2,e)}rotateY(e){return this._rot(2,0,e)}rotateZ(e){return this._rot(0,1,e)}applyMatrix4(e){let i=this.attributes.position;if(i&&e?.elements){let r=new Q;for(let n=0;n<i.count;n++)r.set(i.getX(n),i.getY(n),i.getZ(n)).applyMatrix4(e),i.setXYZ(n,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let e=new ns;e.name=this.name;for(let i of Object.keys(this.attributes))e.attributes[i]=this.attributes[i].clone();return this.index&&(e.index=this.index.clone()),e}dispose(){}},bt=class extends xe{constructor(t=1,e=1,i=1){super();let r=t/2,n=e/2,s=i/2,a=[-r,-n,s,r,-n,s,r,n,s,-r,n,s,r,-n,-s,-r,-n,-s,-r,n,-s,r,n,-s,-r,n,s,r,n,s,r,n,-s,-r,n,-s,-r,-n,-s,r,-n,-s,r,-n,s,-r,-n,s,r,-n,s,r,-n,-s,r,n,-s,r,n,s,-r,-n,-s,-r,-n,s,-r,n,s,-r,n,-s],o=[],l=[],y=[];for(let f=0;f<6;f++){let b=f*4,h=2-(f>>1),d=f&1?-1:1;for(let v=0;v<4;v++)o.push(h===0?d:0,h===1?d:0,h===2?d:0);l.push(0,0,1,0,1,1,0,1),y.push(b,b+1,b+2,b,b+2,b+3)}this.setFromBuffers(a,o,l,y)}},Zt=class extends xe{constructor(t=1,e=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let n=[],s=[],a=[],o=[];for(let l=0;l<=r;l++){let y=l/r;for(let f=0;f<=i;f++){let b=f/i;if(n.push((b-.5)*t,(.5-y)*e,0),s.push(0,0,1),a.push(b,1-y),l>0&&f>0){let h=(i+1)*l+f-1,d=h-(i+1);o.push(d,h,d+1,h,h+1,d+1)}}}this.setFromBuffers(n,s,a,o)}},Jt=class extends xe{constructor(t=1,e=16,i=12,r=0,n=Math.PI*2,s=0,a=Math.PI){super(),e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i));let o=[],l=[],y=[],f=[],b=Math.min(s+a,Math.PI);for(let h=0;h<=i;h++){let d=h/i,v=s+d*a;for(let M=0;M<=e;M++){let m=M/e,u=r+m*n,g=-Math.cos(u)*Math.sin(v),p=Math.cos(v),x=Math.sin(u)*Math.sin(v);if(o.push(t*g,t*p,t*x),l.push(g,p,x),y.push(m,1-d),h>0&&M>0){let w=(e+1)*h+M,_=w-(e+1),N=_-1,P=w-1;(h!==1||s>0)&&f.push(_,N,w),(h!==i||b<Math.PI)&&f.push(N,P,w)}}}this.setFromBuffers(o,l,y,f)}},gt=class extends xe{constructor(t=1,e=1,i=1,r=16,n=1,s=!1,a=0,o=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),n=Math.max(1,Math.floor(Number(n)||1));let l=[],y=[],f=[],b=[],h=i/2,d=(e-t)/(i||1),v=r+1;for(let m=0;m<=n;m++){let u=m/n,g=u*(e-t)+t,p=h-u*i;for(let x=0;x<=r;x++){let w=x/r,_=a+w*o,N=Math.sin(_),P=Math.cos(_),E=Math.hypot(N,d,P)||1;if(l.push(g*N,p,g*P),y.push(N/E,d/E,P/E),f.push(w,1-u),m<n&&x<r){let T=m*v+x,S=T+v;b.push(T,S,T+1,S,S+1,T+1)}}}let M=(m,u)=>{if(s||m<=0)return;let g=u*h,p=l.length/3;l.push(0,g,0),y.push(0,u,0),f.push(.5,.5);let x=p+1;for(let w=0;w<=r;w++){let _=a+w/r*o,N=Math.sin(_),P=Math.cos(_);l.push(m*N,g,m*P),y.push(0,u,0),f.push(P*.5+.5,.5+u*N*.5),w<r&&b.push(p,x+w+(u>0?0:1),x+w+(u>0?1:0))}};M(t,1),M(e,-1),this.setFromBuffers(l,y,f,b)}},Qt=class extends gt{constructor(t=1,e=1,i=16,r=1,n=!1,s=0,a=Math.PI*2){super(0,t,e,i,r,n,s,a)}},en=class extends xe{constructor(t=1,e=.4,i=12,r=48,n=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let s=[],a=[],o=[],l=[];for(let y=0;y<=i;y++){let f=y/i*Math.PI*2,b=Math.cos(f),h=Math.sin(f);for(let d=0;d<=r;d++){let v=d/r*n,M=Math.cos(v),m=Math.sin(v);if(s.push((t+e*b)*M,(t+e*b)*m,e*h),a.push(b*M,b*m,h),o.push(d/r,y/i),y>0&&d>0){let u=(r+1)*y+d-1,g=u-(r+1);l.push(u,g,u+1,g,g+1,u+1)}}}this.setFromBuffers(s,a,o,l)}};function Vr(t,e,i,r,n){let s=Math.max(2,Math.min(256,Math.floor(Number(e)||64))),a=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),o=Number(r)||.1,l=[],y=[],f=[],b=[],h=[],d=new Q,v=new Q,M=new Q;for(let u=0;u<=s;u++){let g=new Q;n(u/s,g),h.push(g)}let m=a+1;for(let u=0;u<=s;u++){let g=u/s,p=h[u];d.subVectors(h[Math.min(s,u+1)],h[Math.max(0,u-1)]).normalize(),u===0&&v.set(Math.abs(d.y)>.9?1:0,Math.abs(d.y)>.9?0:1,0),M.crossVectors(d,v).normalize(),v.crossVectors(M,d).normalize();for(let x=0;x<=a;x++){let w=x/a*Math.PI*2,_=-Math.cos(w),N=Math.sin(w),P=_*v.x+N*M.x,E=_*v.y+N*M.y,T=_*v.z+N*M.z;if(l.push(p.x+o*P,p.y+o*E,p.z+o*T),y.push(P,E,T),f.push(g,x/a),u>0&&x>0){let S=m*(u-1)+x-1,A=S+m;b.push(S,A,S+1,A,A+1,S+1)}}}t.setFromBuffers(l,y,f,b)}var tn=class extends xe{constructor(t=1,e=.4,i=64,r=8,n=2,s=3){super(),i=Math.floor(i),r=Math.floor(r),Vr(this,i,r,e,(a,o)=>{let l=a*n*Math.PI*2,y=s/n*l,f=t*(2+Math.cos(y))*.5;o.set(f*Math.cos(l),f*Math.sin(l),t*Math.sin(y)*.5)})}},ze=class{getPoint(t,e=new Q){return e}getPointAt(t,e=new Q){return this.getPoint(t,e)}getTangent(t,e=new Q){return e.subVectors(this.getPoint(Math.min(1,t+.001)),this.getPoint(Math.max(0,t-.001))).normalize()}getPoints(t=5){let e=Math.max(1,Math.min(512,Math.floor(Number(t)||5))),i=[];for(let r=0;r<=e;r++)i.push(this.getPoint(r/e));return i}getSpacedPoints(t=5){return this.getPoints(t)}},nn=class extends ze{constructor(t=new Q,e=new Q){super(),this.v1=t,this.v2=e}getPoint(t,e=new Q){return e.lerpVectors(this.v1,this.v2,t)}},rn=class extends ze{constructor(t=new Q,e=new Q,i=new Q){super(),this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new Q){return e.lerpVectors(this.v0,this.v1,t).lerp(new Q().lerpVectors(this.v1,this.v2,t),t)}},on=class extends ze{constructor(t=new Q,e=new Q,i=new Q,r=new Q){super(),this.v0=t,this.v1=e,this.v2=i,this.v3=r}getPoint(t,e=new Q){let i=new Q().lerpVectors(this.v0,this.v1,t),r=new Q().lerpVectors(this.v1,this.v2,t),n=new Q().lerpVectors(this.v2,this.v3,t);return e.lerpVectors(i.lerp(r,t),r.lerp(n,t),t)}},sn=class extends ze{constructor(t=[],e=!1){super(),this.points=Array.isArray(t)?t:[],this.closed=!!e}getPoint(t,e=new Q){let i=this.points,r=i.length;if(!r)return e.set(0,0,0);if(r===1)return e.copy(i[0]);let n=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(t)||0)),s=Math.floor(n),a=n-s;!this.closed&&s>=r-1&&(s=r-2,a=1);let o=M=>i[this.closed?(M%r+r)%r:Math.max(0,Math.min(r-1,M))],l=o(s-1),y=o(s),f=o(s+1),b=o(s+2),h=a*a,d=h*a,v=(M,m,u,g)=>.5*(2*m+(u-M)*a+(2*M-5*m+4*u-g)*h+(3*m-M-3*u+g)*d);return e.set(v(l.x,y.x,f.x,b.x),v(l.y,y.y,f.y,b.y),v(l.z,y.z,f.z,b.z))}},yt=class extends xe{constructor(t=[new Ee(0,-.5),new Ee(.5,0),new Ee(0,.5)],e=12,i=0,r=Math.PI*2){super();let n=Array.isArray(t)&&t.length>=2?t:[new Ee(.2,0),new Ee(.2,.5)],s=Math.max(3,Math.min(128,Math.floor(Number(e)||12))),a=[],o=[],l=[],y=[],f=n.length;for(let b=0;b<=s;b++){let h=b/s,d=i+h*r,v=Math.sin(d),M=Math.cos(d),m=b*f;for(let u=0;u<f;u++){let g=n[u],p=Number(g?.x)||0,x=Number(g?.y)||0;a.push(p*v,x,p*M);let w=n[Math.max(0,u-1)],_=n[Math.min(f-1,u+1)],N=(Number(_?.x)||0)-(Number(w?.x)||0),P=(Number(_?.y)||0)-(Number(w?.y)||0),E=Math.hypot(P,N)||1;if(o.push(P/E*v,-N/E,P/E*M),l.push(h,u/(f-1)),b<s&&u<f-1){let T=m+u,S=T+f;y.push(T,S,T+1,S,S+1,T+1)}}}this.setFromBuffers(a,o,l,y)}},an=class extends xe{constructor(t,e=64,i=1,r=8,n=!1){super(),Vr(this,e,r,i,(s,a)=>{let o=t?.getPointAt??t?.getPoint;if(typeof o=="function"){let l=o.call(t,s,a);l&&l!==a&&a.copy(l)}else a.set(0,s,0)})}},Ht="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",et=class{constructor(t=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Ee(1,1),this.offset=new Ee(0,0),this.image=null,this.width=0,this.height=0,this.source=t,t&&typeof t=="object"&&(this.image=t)}dispose(){}},cn=class extends et{constructor(t=null,e=1,i=1,r=1023,n=1009,s,a=1001,o=1001,l=1003,y=1003,f=1,b=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let h=Number(e),d=Number(i),v=t&&typeof t.length=="number"?t:null;this.width=h,this.height=d,this.image={data:v,width:h,height:d},this.format=Number(r)||1023,this.type=Number(n)||1009,this.wrapS=Number(a)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(l)||1003,this.minFilter=Number(y)||1003,this.colorSpace=b||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(t){t&&this._bake()}_bake(){let t=this.image,e=t?.data,i=Number(t?.width??this.width),r=Number(t?.height??this.height);if(!e||!e.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let n=Math.max(1,i|0),s=Math.max(1,r|0),a=n*s,o=this.format,l=o===1021||o===1024||o===1028||e.length===a?1:o===1025||o===1030||e.length===a*2?2:o===1022||e.length===a*3?3:4,y=this.type===1015||this.type===1016||e instanceof Float32Array||e instanceof Float64Array,f=Math.min(n,64),b=Math.min(s,64),h=(this.flipY?257:1)^this.colorSpace.length^e.length,d=Math.max(1,e.length>>6|0);for(let A=0;A<e.length;A+=d)h=Math.imul(h^(e[A]*256|0),16777619)|0;if(h===this._sig&&this.source)return;this._sig=h;let v=b*(1+f*4),M=new Uint8Array(68+v),m=new DataView(M.buffer);m.setUint32(0,2303741511),m.setUint32(4,218765834),m.setUint32(8,13),m.setUint32(12,1229472850),m.setUint32(16,f),m.setUint32(20,b),M[24]=8,M[25]=6,m.setUint32(29,Vt(M.subarray(12,29))),m.setUint32(33,v+11),m.setUint32(37,1229209940),M[41]=120,M[42]=1,M[43]=1,m.setUint16(44,v,!0),m.setUint16(46,~v&65535,!0);let u=48,g=1,p=0,x=0,w=0,_=0,N=0,P=A=>{if(!Number.isFinite(A))return 0;let D=y&&A<=1?A*255:A;return D>0?D<255?D+.5|0:255:0};for(let A=0;A<b;A++){let D=A*s/b|0,R=this.flipY?s-1-D:D;M[u++]=0,p+=g;for(let F=0;F<f;F++){let k=(R*n+(F*n/f|0))*l,V=o===1021?255:P(e[k]??0),L=l>=3||o===1030?P(e[k+1]??0):V,O=l>=3?P(e[k+2]??0):o===1030?0:V,c=l===4?P(e[k+3]??255):o===1021?P(e[k]??255):o===1025?P(e[k+1]??255):255;M[u++]=V,g+=V,p+=g,M[u++]=L,g+=L,p+=g,M[u++]=O,g+=O,p+=g,M[u++]=c,g+=c,p+=g,x+=V,w+=L,_+=O,N+=c}g%=65521,p%=65521}m.setUint32(u,(p<<16|g)>>>0),m.setUint32(u+4,Vt(M.subarray(37,u+4))),m.setUint32(u+12,1229278788),m.setUint32(u+16,2923585666);let E=f*b*255,T=this.colorSpace==="srgb-linear";this.avgColor=[T?x/E:Re(x/E),T?w/E:Re(w/E),T?_/E:Re(_/E),N/E];let S=["data:image/png;base64,"];for(let A=0;A<M.length;A+=3){let D=M[A]<<16|(M[A+1]??0)<<8|(M[A+2]??0);S.push(Ht[D>>18&63]+Ht[D>>12&63]+(A+1<M.length?Ht[D>>6&63]:"=")+(A+2<M.length?Ht[D&63]:"="))}this.source=S.join("")}},un=class{load(t,e){let i=new et(t);return e?.(i),i}};function Se(t,e){return t!==void 0?Number(t):e}function er(t,e){return t!==void 0?!!t:e}var Ce=class{constructor(t={}){this.name=t.name||"",this.color=new Pe(t.color??16777215),this._em=t.emissive!==void 0,this.emissive=new Pe(t.emissive??0),this.emissiveIntensity=Se(t.emissiveIntensity,1),this.roughness=Se(t.roughness,t.roughnessMap?1:.5),this.metalness=Se(t.metalness,t.metalnessMap?1:0),this.opacity=Se(t.opacity,1),this.transparent=er(t.transparent,!1),this.wireframe=er(t.wireframe,!1),this.side=Se(t.side,2),this.doubleSided=er(t.doubleSided,!0),this.map=t.map||null,this.normalMap=t.normalMap||null;let e=t.normalScale;this.normalScale=typeof e=="number"?new Ee(e,e):new Ee(Se(e?.x,1),Se(e?.y,1)),this.roughnessMap=t.roughnessMap||null,this.metalnessMap=t.metalnessMap||null,this.emissiveMap=t.emissiveMap||null,this.aoMap=t.aoMap||null,this.aoMapIntensity=Se(t.aoMapIntensity,1),this.bumpMap=t.bumpMap||null,this.bumpScale=Se(t.bumpScale,1),this.clearcoat=Se(t.clearcoat,0),this.clearcoatRoughness=Se(t.clearcoatRoughness,0),this.sheen=Se(t.sheen,0),this.sheenColor=new Pe(t.sheenColor??0),this.sheenRoughness=Se(t.sheenRoughness,0),this.transmission=Se(t.transmission,0),this.thickness=Se(t.thickness,0),this.attenuationColor=new Pe(t.attenuationColor??16777215),this.attenuationDistance=Se(t.attenuationDistance,1/0),this.ior=Se(t.ior,1.5),this.dispersion=Se(t.dispersion,0),this.iridescence=Se(t.iridescence,0),this.iridescenceIOR=Se(t.iridescenceIOR,1.3)}dispose(){}},qe=class extends Ce{},ln=class extends Ce{},mn=class extends Ce{},hn=class extends Ce{},dn=class extends Ce{},ke=class as{constructor(){this.name="",this.matrixAutoUpdate=!0,this.visible=!0,this._castShd=!1,this._castShdSet=!1,this._recvShd=!1,this._recvShdSet=!1,this.parent=null,this.children=[],this.userData={},this.position=new Q,this.rotation=new pt,this.quaternion=new Qe,this.scale=new Q(1,1,1),this.matrix=new We,this.matrixWorld=new We,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,i=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)))),n=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(i,r,n)})}get castShadow(){return this._castShd}set castShadow(e){this._castShd=!!e,this._castShdSet=!0}get receiveShadow(){return this._recvShd}set receiveShadow(e){this._recvShd=!!e,this._recvShdSet=!0}add(...e){for(let i of e)i&&i instanceof as&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...e){for(let i of e){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(e){let i=new Set,r=[this];for(;r.length>0;){let n=r.pop();if(!n||typeof n!="object"||i.has(n))continue;i.add(n),e(n);let s=n.children;if(Array.isArray(s))for(let a=s.length-1;a>=0;a--)r.push(s[a])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){this.traverse(i=>{zr(i),(i.matrixAutoUpdate||e)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(e,i,r){let n=typeof e=="object"?e:new Q(e,i,r);this.target instanceof Q?this.target.copy(n):this.target?.position instanceof Q&&this.target.position.copy(n),this.updateMatrixWorld(!0);let s=new We;s.lookAt(this.position,n,new Q(0,1,0));let a=s.elements,o=a[0],l=a[4],y=a[8],f=a[1],b=a[5],h=a[9],d=a[2],v=a[6],M=a[10],m=o+b+M;if(m>0){let u=.5/Math.sqrt(m+1);this.quaternion.set((v-h)*u,(y-d)*u,(f-l)*u,.25/u)}}translateOnAxis(e,i){let r=e.clone().applyMatrix4(new We().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(e){return this.translateOnAxis(new Q(1,0,0),e)}translateY(e){return this.translateOnAxis(new Q(0,1,0),e)}translateZ(e){return this.translateOnAxis(new Q(0,0,1),e)}rotateX(e){return this.rotation.x+=e,this}rotateY(e){return this.rotation.y+=e,this}rotateZ(e){return this.rotation.z+=e,this}_chain(){let e=[];for(let i=this;i&&e.length<64;i=i.parent)e.push(i);return e}_syncWorld(){let e=this._chain();for(let i=e.length-1;i>=0;i--){let r=e[i];r.updateMatrix?.(),r.parent?.matrixWorld?r.matrixWorld.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrixWorld?.copy(r.matrix)}return this.matrixWorld.elements}getWorldPosition(e=new Q){let i=this._syncWorld();return e.set(i[12],i[13],i[14])}getWorldScale(e=new Q){let i=this._syncWorld();return e.set(Math.hypot(i[0],i[1],i[2]),Math.hypot(i[4],i[5],i[6]),Math.hypot(i[8],i[9],i[10]))}getWorldDirection(e=new Q){let i=this._syncWorld();return e.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(e=new Qe){let i=this._chain();e.set(0,0,0,1);for(let r=i.length-1;r>=0;r--)e.multiply(i[r].quaternion);return e}clone(e=!0){let i=typeof this._cloneCustom=="function"?this._cloneCustom():this instanceof Ke?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Oe?new Oe(this.geometry,this.material):new this.constructor;if(this instanceof Ge){i.color.copy(this.color),i.intensity=this.intensity,i.shadow.copy(this.shadow);let r=this.target;r?.position&&i.target?.position&&i.target.position.copy(r.position),this instanceof Lt&&i.groundColor.copy(this.groundColor)}i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,this._castShdSet&&(i.castShadow=this.castShadow),this._recvShdSet&&(i.receiveShadow=this.receiveShadow);try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(e)for(let r of this.children)i.add(r.clone(!0));return i}},fn=class extends ke{},Oe=class extends ke{constructor(t,e){super(),this.isMesh=!0;let i=Array.isArray(e)?e[0]:e;this.geometry=t instanceof xe?t:t?(Xe("unsupported geometry","BoxGeometry"),new bt(.5,.5,.5)):new xe,this.material=i instanceof Ce?i:i?(Xe("unsupported material","MeshStandardMaterial"),new qe({color:13421772})):new qe}};function zr(t){typeof t?._bakeAuthorGeometry=="function"&&t._bakeAuthorGeometry();let e=de().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var xt=1e4,vt=class extends Oe{constructor(t,e,i=1){super(t,e),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>xt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${xt})`);this.count=Math.floor(r);let n=new Float32Array(this.count*16);for(let s=0;s<this.count;s++){let a=s*16;n[a]=1,n[a+5]=1,n[a+10]=1,n[a+15]=1}this.instanceMatrix=new we(n,16)}setMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,n=i*16;if(!(n+16>r.length))for(let s=0;s<16;s++){let a=Number(e.elements[s]);r[n+s]=Number.isFinite(a)?a:s%5===0?1:0}}getMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,n=i*16;if(!(n+16>r.length))for(let s=0;s<16;s++)e.elements[s]=r[n+s]}setColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let s=new Float32Array(this.count*3);s.fill(1),this.instanceColor=new we(s,3)}let r=this.instanceColor.array,n=i*3;r[n]=Number.isFinite(e.r)?e.r:1,r[n+1]=Number.isFinite(e.g)?e.g:1,r[n+2]=Number.isFinite(e.b)?e.b:1}getColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){e.setRGB(1,1,1);return}let r=this.instanceColor.array,n=i*3;e.setRGB(r[n],r[n+1],r[n+2])}dispose(){}},Mt=class os{constructor(){this.mapSize=new Ee(1024,1024),this.bias=-5e-4,this.normalBias=.015,this.radius=1.5,this.camera={near:.1,far:100,left:-5,right:5,top:5,bottom:-5,fov:50,updateProjectionMatrix:()=>{}}}copy(e){return this.mapSize.copy(e.mapSize),this.bias=Number(e.bias),this.normalBias=Number(e.normalBias),this.radius=Number(e.radius),this}clone(){return new os().copy(this)}},Ge=class extends ke{constructor(t=16777215,e=1){super(),this.isLight=!0,this.shadow=new Mt,this.color=new Pe(t),this.intensity=Number(e),this.type="directional"}},St=class extends Ge{constructor(t,e){super(t,e),this.type="ambient"}},pn=class extends Ge{constructor(t,e){super(t,e),this.target=new ke,this.type="directional"}},wt=class extends Ge{constructor(t,e,i=0,r=2){super(t,e),this.type="point",this.distance=i,this.decay=r}},_t=class extends ke{},bn=class extends _t{constructor(t=45,e=1,i=.1,r=1e3){super(),this.target=new Q(0,0,0),this.fov=Number(t),this.aspect=Number(e),this.near=Number(i),this.far=Number(r)}},At=class extends ke{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Ue.validate(this),Je(this)}toGLB(){return Ue.validate(this),lt(this)}toUSDZ(){return Ue.validate(this),mt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,e=0;return this.traverse(i=>{if(i instanceof Oe){let r=new Float32Array(i.matrixWorld.elements);t.set(e,r),i.name&&t.set(i.name,r),e++}}),t}},tr=Je,nr=lt,Gr=mt;de().makePngDeflater=Gn;var Ue=class{static validate(t){let e=0,i=0,r=0,n=new Set,s=(o,l,y)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${l}). Found: ${y}`)},a=(o,l)=>{if(!Number.isFinite(l))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(l)}), which cannot be bounds-checked.`);return l};t.traverse(o=>{if(zr(o),o instanceof Oe||o.geometry?.attributes?.position?.count){if(r++,r>1e3&&s("MESHES",1e3,r),o instanceof vt){let y=a("instance",o.count);(y<0||y>xt)&&s("INSTANCES",xt,y)}let l=o.geometry;if(l){let y=0;if(l.attributes.position&&(y=a("vertex",l.attributes.position.count),e+=y,e>1e5&&s("VERTICES",1e5,e)),l.index){let f=a("index",l.index.count);i+=f,i>3e5&&s("INDICES",3e5,i);let b=l.index.array;if(b&&y>0){let h=Math.min(f,b.length);for(let d=0;d<h;d++){let v=b[d];if(!Number.isFinite(v)||v<0||v>=y)throw new Error(`SecurityError: Index buffer value (${String(v)}) out of vertex bounds [0, ${y}).`)}}}}if(o.material){let y=o.material;for(let f of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap","bumpMap"])y[f]&&n.add(y[f])}}}),n.size>16&&s("TEXTURES",16,n.size);for(let o of n){let l=o,y=l.image,f=Number(y?.width??l.width??0)||0,b=Number(y?.height??l.height??0)||0;(!Number.isFinite(f)||!Number.isFinite(b)||f>2048||b>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(f,b))}}},gn=class{constructor(t={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=t.canvas||(typeof document<"u"?document.createElement("canvas"):{}),t.viewer&&(this.boundViewer=t.viewer),t.container?.threeLiveViewer&&(this.boundViewer=t.container.threeLiveViewer),t.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=t.canvas.parentElement.threeLiveViewer);let e=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=t.isSandboxed||e,this.containerId=t.containerId||""}setSize(t,e){return this}setPixelRatio(t){return this}setClearColor(t,e=1){let i=new Pe(t);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,e),this}clear(){return this}dispose(){}render(t,e){if(this.isSandboxed){Ue.validate(t);let r=(n,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(n,s):self.postMessage(n))};if(this.hasInitialModelRendered){let n=t.getMeshTransforms(),s={};for(let[a,o]of n.entries())s[a]=Array.from(o);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let n=tr(t),s=nr(t),a=(n.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:a,camera:e?{fov:e.fov||60,position:[e.position.x,e.position.y,e.position.z]}:void 0},[s.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(t.getMeshTransforms()):(i.loadModel(t.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function Ir(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var yn=class{constructor(t=!0){this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1,this.autoStart=t,t&&this.start()}start(){this.startTime=Ir(),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 t=0;if(this.autoStart&&!this.running&&this.start(),this.running){let e=Ir();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}};function Li(){}var dt=new Proxy(Li,{get:(t,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:dt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>dt,construct:()=>dt}),Nr=(()=>{try{if(typeof document>"u")return null;let t=document.currentScript;return t?.src?t.src:t?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([t.textContent],{type:"text/javascript"})):null}catch{return null}})();function Pn(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function tt(t,e){if(!t||typeof t!="string")return!1;let i=t.trim();if(!i)return!1;try{let r=new URL(i,Pn());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 Pr,ht;function Hr(t){if(!tt(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let e=globalThis.trustedTypes;if(!e||typeof e.createPolicy!="function")return t;if(ht===void 0||Pr!==e){Pr=e;try{ht=e.createPolicy("three-live#worker",{createScriptURL:i=>{if(!tt(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{ht=null}}return ht?ht.createScriptURL(t):t}function Ci(t){de().sandboxEngineSrc=t}function rr(){let t=de().sandboxEngineSrc;if(t)return t;if(Nr)return Nr;try{if(typeof document>"u")return null;let e=Pn(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let n=r.src;if(!n)continue;let s=new URL(n,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&tt(n,{requireSameOrigin:!0}))return n}}catch{}return null}function ir(t,e){if(!tt(t))throw new Error(`SecurityError: Disallowed ${e} URL "${t}" (http:, https:, or blob: required).`);return new URL(t,Pn()).href}function Di(){let t=rr();if(!t)throw new Error("SecurityError: Could not locate Three-Live bundle URL for worker sandbox; set ThreeLiveElement.sandboxEngineSrc explicitly.");return ir(t,"sandbox engine")}function Ii(t){de().sandboxIframeSrc=t}function jr(){let t=de().sandboxIframeSrc;if(t)return t;let e=rr();if(!e||!tt(e))return null;let i=new URL(e,Pn());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function Ni(){let t=jr();if(!t)throw new Error("SecurityError: Could not locate three-live-sandbox.html; set ThreeLiveElement.sandboxIframeSrc explicitly.");return ir(t,"sandbox iframe")}function Pi(t){de().allowClientScripts=t}function $r(){return!!de().allowClientScripts}function ki(t){return ir(t,"procedural scene script")}var Fi="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".split(" ");function Ui(t,e,i){let r=self,n=t.nonce,s=t.engineSrc,a=t.allowedScriptUrl,o=t.allowClientScripts,l=t.revoked,y=r.postMessage.bind(r),f=null;try{f=i?i(r.CompressionStream):null}catch{}let b=null;function h(N,P){let E=()=>P&&P.length?y(N,P):y(N);b?b=b.then(E,E):E()}function d(N){h({type:"ERROR",nonce:n,message:String(N)})}let v=typeof r.importScripts=="function"?r.importScripts.bind(r):null,M=a,m=null;try{let N=s;if(typeof r.trustedTypes<"u"&&r.trustedTypes&&typeof r.trustedTypes.createPolicy=="function")try{let P={createScriptURL:function(T){if(T!==s&&(!a||T!==a))throw new TypeError("Disallowed worker importScripts URL");return T}};o&&(P.createScript=function(T){return String(T)});let E=r.trustedTypes.createPolicy("three-live#worker-boot",P);N=E.createScriptURL(s),a&&(M=E.createScriptURL(a)),o&&typeof E.createScript=="function"&&(m=E.createScript.bind(E))}catch{}v(N)}catch(N){d('Sandbox failed to load "'+s+'" (must be an IIFE bundle like three-live.min.js): '+(N&&N.message||N));return}let u=r.THREE;if(!u||typeof u.Scene!="function"){d('Sandbox "'+s+'" did not install THREE; point sandboxEngineSrc at three-live.min.js.');return}if(Array.isArray(e)){let N=r.__THREE_LIVE_REGISTRY__;for(let P=0;P<e.length;P++)if(typeof e[P]=="function")try{e[P](u,N)}catch{}}function g(N,P,E){let T=r;for(;T&&T!==Object.prototype;){if(!E&&T!==r)try{delete T[N]}catch{}if(!E||T===r||Object.prototype.hasOwnProperty.call(T,N))try{Object.defineProperty(T,N,E?{value:P,writable:!1,configurable:!1}:{value:P,writable:!1,configurable:!1,enumerable:!1})}catch{}try{T=Object.getPrototypeOf(T)}catch{break}}}for(let N=0;N<l.length;N++)g(l[N],void 0);g("performance",Object.freeze({now:function(){return Date.now()}}));let p=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],x=!1;function w(N,P){if(N.type==="3D_MODEL_READY"){if(x)return;x=!0}if(N.nonce=n,N.type==="3D_MODEL_READY"&&f&&N.glbBuffer instanceof ArrayBuffer){let E=N.glbBuffer;b=(b||Promise.resolve()).then(()=>f.glb(new Uint8Array(E))).then(T=>{T.buffer!==E&&(N.glbBuffer=T.byteOffset===0&&T.byteLength===T.buffer.byteLength?T.buffer:T.slice().buffer),y(N,[N.glbBuffer])},()=>y(N,[E]));return}P&&P.length?h(N,P):h(N)}g("postMessage",function(N,P){if(!N||p.indexOf(N.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+p.join(", ")+").");w(N,P)},!0);let _=!1;r.onmessage=function(N){let P=N&&N.data;if(!P||P.nonce!==n||P.type!=="EXECUTE"&&P.type!=="EXECUTE_URL"||_)return;_=!0;let E=P.texturePack;if(E&&typeof E=="object"){let T=Object.create(null),S=0;for(let A of Object.keys(E)){let D=E[A],R=D&&D.size;S<64&&/^[0-9a-f]{16}$/.test(A)&&(R===256||R===512||R===1024)&&D.rgba instanceof Uint8Array&&D.rgba.length===R*R*4&&(T[A]=Object.freeze({size:R,rgba:D.rgba}),S++)}r.__three_live_texture_pack__=Object.freeze(T)}try{let T=new u.Scene,S=new u.PerspectiveCamera(60,1,.1,1e3),A=new u.WebGLRenderer({isSandboxed:!0});if(P.type==="EXECUTE_URL"){if(!a||P.scriptUrl!==a||typeof v!="function"){d("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let D=M||a,R=v;if(v=null,M=null,r.THREE=u,r.scene=T,r.camera=S,r.renderer=A,R(D),typeof r.__THREE_LIVE_SCENE__=="function"){let F=r.__THREE_LIVE_SCENE__(u,T,S,A);F&&typeof F.toGLB=="function"&&(T=F)}else r.scene&&typeof r.scene.toGLB=="function"&&(T=r.scene)}else{if(!o){d("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let D=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
|
|
369
351
|
return (function () {
|
|
370
|
-
`+
|
|
352
|
+
`+P.script+`
|
|
371
353
|
;
|
|
372
354
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
373
355
|
})();
|
|
374
356
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
375
|
-
`+
|
|
357
|
+
`+P.script+`
|
|
376
358
|
;
|
|
377
359
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
378
|
-
})();`);g=null;let P=I(w,v,S,D);P&&typeof P.toGLB=="function"&&(v=P)}if(!T){w.SceneQuotaValidator&&w.SceneQuotaValidator.validate(v);let I=v.toGLB(),P=I instanceof ArrayBuffer?I:I.buffer.slice(I.byteOffset,I.byteOffset+I.byteLength);x({type:"3D_MODEL_READY",glbBuffer:P},[P])}l({type:"DONE",nonce:r})}catch(v){h(v&&v.message||v)}}},l({type:"READY",nonce:r})}function Bn(e,t,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,n={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:s,revoked:yi},a=(le().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${xi.toString()})(${JSON.stringify(n)},[${a}]);`}function Cr(e){e.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),e.onToast?.("Security Error: script timed out and was stopped.")}var Oe=0;function Dr(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function vi(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var Mi=1024,Ti=256;function yr(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let i=e[t];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function Vn(e,t){if(!e||typeof e!="object")return null;let i=e;if(i.nonce!==t)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Mi)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!yr(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let s=Object.keys(r);if(s.length>1e3)return null;let n=Object.create(null),a=r;for(let o of s){if(o.length>Ti||o==="__proto__"||o==="constructor"||o==="prototype")return null;let l=a[o];if(!yr(l))return null;n[o]=l}return{type:"3D_UPDATE_TRANSFORMS",transforms:n}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function _i(e){let t=vi(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Ir(e,t,i,r){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":i();return;case"ERROR":i(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Si(e,t,i,r){let s=Dr(),n=Bn(t,s,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a=document.createElement("iframe");a.setAttribute("sandbox","allow-scripts"),a.setAttribute("aria-hidden","true"),a.tabIndex=-1,a.style.display="none",a.src=i,Oe++;let o=!1,l=!1,h={modelDispatched:!1},u,f=()=>{if(o||l)return;let b=a.contentWindow;!b||typeof b.postMessage!="function"||(l=!0,b.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:n,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:s,workerSource:n,script:e.script},"*"))},g=()=>{},w=b=>{if(o||!a.contentWindow||b.source!==a.contentWindow)return;let T=b.data;if(T&&typeof T=="object"&&T.type==="IFRAME_READY"){f();return}let x=Vn(T,s);x&&Ir(x,r,g,h)};g=()=>{o||(o=!0,u!==void 0&&clearTimeout(u),Oe=Math.max(0,Oe-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",w),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},u=setTimeout(()=>{o||(g(),Cr(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",w),a.onload=()=>{f()},a.onerror=()=>{g(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let p=document.body||document.documentElement;if(!p||typeof p.appendChild!="function"){g();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(b),b}return p.appendChild(a),{terminate:g}}function xr(e,t,i,r){if(t==="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(t==="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(Oe>=32)return r(`SecurityError: ${Oe} 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 s;try{s=fi()}catch(g){let w=g instanceof Error?g.message:String(g);return r(w,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let g;try{g=pi()}catch(w){let p=w instanceof Error?w.message:String(w);return r(p,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Si(e,s,g,i))}catch(w){return Promise.reject(w)}}let n=Dr(),a=Bn(s,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let g=new Blob([a],{type:"application/javascript"}),w=URL.createObjectURL(g);try{let p=Ar(w);o=new Worker(p)}finally{URL.revokeObjectURL(w)}}catch(g){let w=g instanceof Error?g.message:String(g);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${w}`,"Security Error: Failed to start Worker sandbox.")}Oe++;let l=!1,h={modelDispatched:!1},u,f=()=>{l||(l=!0,u!==void 0&&clearTimeout(u),Oe=Math.max(0,Oe-1),o.terminate())};return u=setTimeout(()=>{l||(f(),Cr(i))},3e3),o.onmessage=g=>{let w=Vn(g.data,n);w&&Ir(w,i,f,h)},o.onerror=g=>{f(),i.onError?.(new Error(`Worker execution error: ${g.message}`))},e.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:n}):o.postMessage({type:"EXECUTE",script:e.script,nonce:n}),Promise.resolve({terminate:f})}function vr(e,t){return e==="none"||e==="unsafe-host-realm"?t(`SecurityError: sandbox="${e}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${e}" is not permitted.`):e!=="worker"&&e!=="iframe"?t(`SecurityError: Unsupported sandbox mode "${e}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var Mr=e=>(t,i)=>{let r=new Error(t);return e.onError?.(r),i&&e.onToast?.(i),Promise.reject(r)},Nr={execute(e,t,i,r){let s=Mr(i),n=vr(t,s);if(n)return n;try{_i(e)}catch(a){let o=a instanceof Error?a.message:String(a);return s(o,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Rr()?xr({kind:"script",script:e},t,i,s):s(Gn,Hn)},executeUrl(e,t,i){let r=Mr(i),s=vr(t,r);if(s)return s;let n;try{n=gi(e)}catch(a){let o=a instanceof Error?a.message:String(a);return r(o,"Security Error: disallowed scene script URL.")}return xr({kind:"url",scriptUrl:n},t,i,r)}},un=new Set;function He(e,t){let i=`[three-live] ${e} is unsupported; degraded to ${t}.`;un.has(i)||(un.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function Lr(){return Array.from(un)}function Pr(){un.clear()}var bt=class extends ze{constructor(e={}){He("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},i=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:i!==void 0?i:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},Fr=bt,ke=class extends de{constructor(e=[],t=[],i=1,r=0){super();let s=Number(i)||1,n=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),a=n+1,o=[],l=[],h=[],u=[],f=new ee,g=new ee,w=new ee,p=(x,M)=>M.set(e[x*3]||0,e[x*3+1]||0,e[x*3+2]||0),b=(x,M)=>{let c=x.clone().normalize();o.push(c.x*s,c.y*s,c.z*s),l.push(M.x,M.y,M.z),h.push(Math.atan2(c.z,-c.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,c.y)))/Math.PI)},T=(x,M,c)=>{let m=o.length/3,v=n===0?new ee().subVectors(c,M).cross(new ee().subVectors(x,M)).normalize():null;b(x,v||x.clone().normalize()),b(M,v||M.clone().normalize()),b(c,v||c.clone().normalize()),u.push(m,m+1,m+2)};for(let x=0;x<t.length;x+=3){p(t[x],f),p(t[x+1],g),p(t[x+2],w);let M=[];for(let c=0;c<=a;c++){M[c]=[];let m=f.clone().lerp(w,c/a),v=g.clone().lerp(w,c/a),S=a-c;for(let D=0;D<=S;D++)M[c][D]=S===0?m.clone():m.clone().lerp(v,D/S)}for(let c=0;c<a;c++)for(let m=0;m<2*(a-c)-1;m++){let v=m>>1;(m&1)===0?T(M[c][v+1],M[c+1][v],M[c][v]):T(M[c][v+1],M[c+1][v+1],M[c+1][v])}}this.setFromBuffers(o,l,h,u)}},wi=ke,ln=class extends ke{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},Pt=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],kr=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],mn=class extends ke{constructor(e=1,t=0){super(Pt,kr,e,t)}},ue=(1+Math.sqrt(5))/2,hn=class extends ke{constructor(e=1,t=0){super([-1,ue,0,1,ue,0,-1,-ue,0,1,-ue,0,0,-1,ue,0,1,ue,0,-1,-ue,0,1,-ue,ue,0,-1,ue,0,1,-ue,0,-1,-ue,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},_e=1/ue,fn=class extends ke{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-_e,-ue,0,-_e,ue,0,_e,-ue,0,_e,ue,-_e,-ue,0,-_e,ue,0,_e,-ue,0,_e,ue,0,-ue,0,-_e,ue,0,-_e,-ue,0,_e,ue,0,_e],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},dn=class extends ut{constructor(e=1,t=1,i=4,r=8){let s=Math.max(1e-4,Number(e)||1),n=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,a=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),o=[];for(let l=-1;l<=1;l+=2)for(let h=0;h<=a;h++){if(l>0&&h===0&&n===0)continue;let u=(l<0?h/a-1:h/a)*(Math.PI/2);o.push(new Se(Math.max(0,Math.cos(u)*s),l*n+Math.sin(u)*s))}super(o,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},gt=class extends de{constructor(e=.5,t=1,i=32,r=1,s=0,n=Math.PI*2){super();let a=Math.max(1e-4,Number(t)||1),o=Number(e),l=Number.isFinite(o)?Math.max(0,o):a*.5,h=Math.max(a,l),u=Math.min(h*.999,Math.min(a,l)),f=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),g=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),w=Number.isFinite(Number(s))?Number(s):0,p=Number.isFinite(Number(n))?Number(n):Math.PI*2,b=[],T=[],x=[],M=[];for(let c=0;c<=g;c++){let m=u+c/g*(h-u);for(let v=0;v<=f;v++){let S=w+v/f*p,D=Math.cos(S),I=Math.sin(S);if(b.push(m*D,m*I,0),T.push(0,0,1),x.push(m/h*D*.5+.5,m/h*I*.5+.5),c<g&&v<f){let P=c*(f+1)+v,N=P+f+1;m>1e-6&&M.push(P,N,P+1),M.push(N,N+1,P+1)}}}this.setFromBuffers(b,T,x,M)}},pn=class extends gt{constructor(e=1,t=32,i=0,r=Math.PI*2){super(0,e,t,1,i,r)}},yt=class extends Me{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},Je=class extends Me{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},bn=class extends Je{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function Ur(e,t){let i=e?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,s=e?.index?.array,n=Math.min(8192,Math.floor((s?s.length:i.count)/3)),a=g=>`${Math.round((r[g*3]||0)*1e4)},${Math.round((r[g*3+1]||0)*1e4)},${Math.round((r[g*3+2]||0)*1e4)}`,o=t===void 0,l=o?1:Math.cos(t*Math.PI/180),h={},u=[],f=(g,w)=>u.push(r[g*3]||0,r[g*3+1]||0,r[g*3+2]||0,r[w*3]||0,r[w*3+1]||0,r[w*3+2]||0);for(let g=0;g<n;g++){let w=s?s[g*3]:g*3,p=s?s[g*3+1]:g*3+1,b=s?s[g*3+2]:g*3+2,T=r[w*3]||0,x=r[w*3+1]||0,M=r[w*3+2]||0,c=(r[p*3]||0)-T,m=(r[p*3+1]||0)-x,v=(r[p*3+2]||0)-M,S=(r[b*3]||0)-T,D=(r[b*3+1]||0)-x,I=(r[b*3+2]||0)-M,P=m*I-v*D,N=v*S-c*I,C=c*D-m*S,L=Math.hypot(P,N,C);if(!o&&L<1e-8)continue;L>0&&(P/=L,N/=L,C/=L);let E=[w,p,b];for(let y=0;y<3;y++){let F=E[y],z=E[(y+1)%3],A=a(F),_=a(z);if(A===_)continue;let d=A<_?`${A}|${_}`:`${_}|${A}`,R=h[d];R?R.m||(R.m=1,R.nx*P+R.ny*N+R.nz*C<=l&&f(F,z)):(h[d]={va:F,vb:z,nx:P,ny:N,nz:C,m:o?1:0},o&&f(F,z))}}if(!o){let g=Object.keys(h);for(let w=0;w<g.length;w++){let p=h[g[w]];p&&!p.m&&f(p.va,p.vb)}}return new Float32Array(u)}var gn=class extends de{constructor(e){super(),this.setAttribute("position",new ge(Ur(e),3)),this.__isSegmentPairs=!0}},yn=class extends de{constructor(e,t=1){super();let i=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new ge(Ur(e,i),3)),this.__isSegmentPairs=!0}};function Ai(e,t,i=1){let r=new de;r.__baked=!0;let s=e?.attributes?.position;if(!s?.array||s.count<2)return r;let n=s.array,a=e.index?.array,o=e.__isSegmentPairs?"segments":t,l=a?a.length:s.count,h=Math.min(4096,Math.max(0,o==="segments"?Math.floor(l/2):o==="loop"&&l>=3?l:l-1));if(h===0)return r;e.computeBoundingBox();let u=e.boundingBox,f=u&&u.max.distanceTo(u.min)||1,g=Math.max(.0015,Math.min(.025,f*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),w=[],p=[],b=[],T=[];for(let x=0;x<h;x++){let M=o==="segments"?x*2:x,c=o==="segments"?x*2+1:(x+1)%l,m=a?a[M]:M,v=a?a[c]:c,S=n[m*3]||0,D=n[m*3+1]||0,I=n[m*3+2]||0,P=(n[v*3]||0)-S,N=(n[v*3+1]||0)-D,C=(n[v*3+2]||0)-I,L=Math.hypot(P,N,C);if(L<1e-6)continue;let E=P/L,y=N/L,F=C/L,z=(Math.abs(y)<.9?Math.hypot(F,E):Math.hypot(F,y))||1,A=Math.abs(y)<.9?F/z:0,_=Math.abs(y)<.9?0:-F/z,d=Math.abs(y)<.9?-E/z:y/z,R=y*d-F*_,G=F*A-E*d,H=E*_-y*A,B=w.length/3,Z=[[A,_,d],[R,G,H],[-A,-_,-d],[-R,-G,-H]];for(let k=0;k<2;k++){let Y=S+k*P,ie=D+k*N,re=I+k*C;for(let O=0;O<4;O++){let J=Z[O];w.push(Y+J[0]*g,ie+J[1]*g,re+J[2]*g),p.push(J[0],J[1],J[2]),b.push(O/4,k)}}for(let k=0;k<4;k++){let Y=(k+1)%4;T.push(B+k,B+Y,B+4+Y,B+k,B+4+Y,B+4+k)}}return w.length>0&&r.setFromBuffers(w,p,b,T),r}function Ei(e,t=.05){let i=new de;i.__baked=!0;let r=e?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,n=r.count,a=Math.min(n,5e3),o=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),l=[],h=[],u=[],f=[];for(let g=0;g<a;g++){let w=n<=5e3?g:Math.floor(g*n/a),p=s[w*3]||0,b=s[w*3+1]||0,T=s[w*3+2]||0,x=g*6;for(let M=0;M<6;M++){let c=Pt[M*3],m=Pt[M*3+1],v=Pt[M*3+2];l.push(p+c*o,b+m*o,T+v*o),h.push(c,m,v),u.push(.5,.5)}for(let M=0;M<24;M++)f.push(x+kr[M])}return i.setFromBuffers(l,h,u,f),i}var Ve=class extends Ie{constructor(e,t,i="strip"){let r=t&&typeof t=="object"?t:{},s=t instanceof Me?t:i==="points"?new yt(r):new Je(r),n=e instanceof de?e:new de;super(n,s),this.isLine=!0,this._lineMode=i,this._sourceGeo=n}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=t.array,r=Math.min(t.count,64),s=0,n=0,a=0;for(let o=0;o<r;o++)s+=i[o*3]||0,n+=i[o*3+1]||0,a+=i[o*3+2]||0;this.material.color.setRGB(s/r,n/r,a/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?Ei(this._sourceGeo,this.material?.size??.05):Ai(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},xn=class extends Ve{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},vn=class extends Ve{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},Mn=class extends Ve{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},Tn=class extends ft{constructor(e,t,i=0,r=Math.PI/3,s=0,n=2){super(e,t,i,n),this.target=new Ae,this.type="spot";let a=Number(r);this.angle=Number.isFinite(a)?Math.max(.01,Math.min(Math.PI/2,a)):Math.PI/3;let o=Number(s);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},xt=class extends ht{constructor(e,t,i){He("HemisphereLight","AmbientLight"),super(e,i),this.groundColor=new we(t??4473924)}},Or=xt,Br={Vector2:Se,Vector3:ee,Vector4:kt,Euler:ot,Quaternion:Ye,Matrix4:Be,Matrix3:Ut,Color:we,MathUtils:Tr,BufferAttribute:ge,Float32BufferAttribute:Ot,Uint16BufferAttribute:Bt,Uint32BufferAttribute:Vt,BufferGeometry:de,BoxGeometry:at,PlaneGeometry:zt,SphereGeometry:Gt,CylinderGeometry:ct,ConeGeometry:Ht,TorusGeometry:$t,TorusKnotGeometry:Xt,Curve:Fe,Curve3:Fe,LineCurve3:Wt,QuadraticBezierCurve3:jt,CubicBezierCurve3:Kt,CatmullRomCurve3:Yt,LatheGeometry:ut,TubeGeometry:qt,PolyhedronGeometry:ke,IcosahedronGeometry:hn,OctahedronGeometry:mn,DodecahedronGeometry:fn,TetrahedronGeometry:ln,CapsuleGeometry:dn,RingGeometry:gt,CircleGeometry:pn,WireframeGeometry:gn,EdgesGeometry:yn,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:qe,DataTexture:Zt,TextureLoader:Jt,Material:Me,MeshStandardMaterial:ze,MeshBasicMaterial:Qt,MeshLambertMaterial:en,MeshPhongMaterial:tn,MeshPhysicalMaterial:nn,PointsMaterial:yt,LineBasicMaterial:Je,LineDashedMaterial:bn,ShaderMaterial:bt,RawShaderMaterial:Fr,Object3D:Ae,Group:rn,Mesh:Ie,InstancedMesh:mt,Line:Ve,LineLoop:xn,LineSegments:vn,Points:Mn,Light:Ge,AmbientLight:ht,DirectionalLight:sn,PointLight:ft,SpotLight:Tn,HemisphereLight:xt,RectAreaLight:Or,Camera:dt,PerspectiveCamera:on,Scene:pt,WebGLRenderer:an,Clock:cn,SceneQuotaValidator:De,exportSceneToCanvas3D:Fn,exportSceneToGLB:kn,exportSceneToUSDZ:wr,generateUSDZ:Ln,glbToUSDZ:It,sceneToCanvas3D:Ke,sceneToGLB:tt,sceneToUSDZ:nt,authorScriptRunner:Nr,getAuthorWarnings:Lr,clearAuthorWarnings:Pr};Object.freeze(De),Object.freeze(De.prototype),Object.freeze(pt.prototype),Object.freeze(Br);var $e=new Proxy(Br,{get:(e,t)=>{if(t in e)return e[t];let i=le().authorNamespace;return i&&typeof t=="string"&&t in i?i[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&He(`THREE.${t}`,"no-op proxy"),it)},has:(e,t)=>{if(t in e)return!0;let i=le().authorNamespace;return!!(i&&typeof t=="string"&&t in i)},set:(e,t)=>{throw new TypeError(`Cannot assign to read only property '${String(t)}' of #<THREE>`)},defineProperty:(e,t)=>{throw new TypeError(`Cannot define property '${String(t)}', object is not extensible`)},deleteProperty:(e,t)=>{throw new TypeError(`Cannot delete property '${String(t)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),Ft=le();if(Ft.threeNamespace=$e,Ft.workerExtensionInstallers)for(let e of Ft.workerExtensionInstallers)e($e,Ft);var st={name:"three_author",THREE:$e},Ri=st,Pe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof Pe.THREE>"u"&&(Pe.THREE=$e),typeof Pe.requestAnimationFrame!="function"&&(Pe.requestAnimationFrame=e=>(typeof e=="function"&&typeof Pe.__three_live_raf_cb__!="function"&&(Pe.__three_live_raf_cb__=e),Pe.__three_live_in_step__||He("requestAnimationFrame","single-frame static evaluation"),0)),typeof Pe.cancelAnimationFrame!="function"&&(Pe.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=$e,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=st,e.ThreeLivePlugins.three_author=st,e.ThreeLivePlugins["three-author"]=st}var Ci=$e;
|
|
360
|
+
})();`);m=null;let R=D(u,T,S,A);R&&typeof R.toGLB=="function"&&(T=R)}if(!x){u.SceneQuotaValidator&&u.SceneQuotaValidator.validate(T);let D=T.toGLB(),R=D instanceof ArrayBuffer?D:D.buffer.slice(D.byteOffset,D.byteOffset+D.byteLength);w({type:"3D_MODEL_READY",glbBuffer:R},[R])}h({type:"DONE",nonce:n})}catch(T){d(T&&T.message||T)}},h({type:"READY",nonce:n})}function or(t,e,i){let r=i?.allowedScriptUrl??null,n=i?.allowClientScripts??r===null,s={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:n,revoked:Fi},a=(de().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${Ui.toString()})(${JSON.stringify(s)},[${a}],(${Gn.toString()}));`}function Wr(t){t.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),t.onToast?.("Security Error: script timed out and was stopped.")}var $e=0;function Xr(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Oi(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Bi=1024,Vi=256;function kr(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let i=t[e];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function sr(t,e){if(!t||typeof t!="object")return null;let i=t;if(i.nonce!==e)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Bi)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let n of r)if(!kr(n))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let n=Object.keys(r);if(n.length>1e3)return null;let s=Object.create(null),a=r;for(let o of n){if(o.length>Vi||o==="__proto__"||o==="constructor"||o==="prototype")return null;let l=a[o];if(!kr(l))return null;s[o]=l}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function zi(t){let e=Oi(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Kr(t,e,i,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":i();return;case"ERROR":i(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Gi(t,e,i,r){let n=Xr(),s=or(e,n,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a=document.createElement("iframe");a.setAttribute("sandbox","allow-scripts"),a.setAttribute("aria-hidden","true"),a.tabIndex=-1,a.style.display="none",a.src=i,$e++;let o=!1,l=!1,y={modelDispatched:!1},f,b=()=>{if(o||l)return;let M=a.contentWindow;!M||typeof M.postMessage!="function"||(l=!0,M.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:n,workerSource:s,scriptUrl:t.scriptUrl,texturePack:t.texturePack??null}:{type:"SANDBOX_RUN",nonce:n,workerSource:s,script:t.script,texturePack:t.texturePack??null},"*"))},h=()=>{},d=M=>{if(o||!a.contentWindow||M.source!==a.contentWindow)return;let m=M.data;if(m&&typeof m=="object"&&m.type==="IFRAME_READY"){b();return}let u=sr(m,n);u&&Kr(u,r,h,y)};h=()=>{o||(o=!0,f!==void 0&&clearTimeout(f),$e=Math.max(0,$e-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},f=setTimeout(()=>{o||(h(),Wr(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",d),a.onload=()=>{b()},a.onerror=()=>{h(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let v=document.body||document.documentElement;if(!v||typeof v.appendChild!="function"){h();let M=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(M),M}return v.appendChild(a),{terminate:h}}function Fr(t,e,i,r){if(e==="worker"&&typeof Worker>"u")return r("SecurityError: Web Workers are unavailable for sandboxed execution.","Security Error: Web Workers unavailable.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("SecurityError: DOM unavailable for iframe sandbox execution.","Security Error: DOM unavailable for iframe sandbox.");if($e>=32)return r(`SecurityError: ${$e} workers running, meeting SECURITY_3D_MAX_CONCURRENT_TASKS (32).`,"Security Error: too many concurrent sandboxed scripts.");let n;try{n=Di()}catch(h){let d=h instanceof Error?h.message:String(h);return r(d,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let h;try{h=Ni()}catch(d){let v=d instanceof Error?d.message:String(d);return r(v,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Gi(t,n,h,i))}catch(d){return Promise.reject(d)}}let s=Xr(),a=or(n,s,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let h=new Blob([a],{type:"application/javascript"}),d=URL.createObjectURL(h);try{let v=Hr(d);o=new Worker(v)}finally{URL.revokeObjectURL(d)}}catch(h){let d=h instanceof Error?h.message:String(h);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}$e++;let l=!1,y={modelDispatched:!1},f,b=()=>{l||(l=!0,f!==void 0&&clearTimeout(f),$e=Math.max(0,$e-1),o.terminate())};return f=setTimeout(()=>{l||(b(),Wr(i))},3e3),o.onmessage=h=>{let d=sr(h.data,s);d&&Kr(d,i,b,y)},o.onerror=h=>{b(),i.onError?.(new Error(`Worker execution error: ${h.message}`))},t.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:s,texturePack:t.texturePack??null}):o.postMessage({type:"EXECUTE",script:t.script,nonce:s,texturePack:t.texturePack??null}),Promise.resolve({terminate:b})}function Ur(t,e){return t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox="${t}"; require "worker" or "iframe".`,`Security Error: sandbox="${t}" is not permitted.`):null}var Or=t=>(e,i)=>{let r=new Error(e);return t.onError?.(r),i&&t.onToast?.(i),Promise.reject(r)},Yr={execute(t,e,i,r){let n=Or(i),s=Ur(e,n);if(s)return s;try{zi(t)}catch(a){let o=a instanceof Error?a.message:String(a);return n(o,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??$r()?Fr({kind:"script",script:t,texturePack:r?.texturePack},e,i,n):n(ur,lr)},executeUrl(t,e,i,r){let n=Or(i),s=Ur(e,n);if(s)return s;let a;try{a=ki(t)}catch(o){let l=o instanceof Error?o.message:String(o);return n(l,"Security Error: disallowed scene script URL.")}return Fr({kind:"url",scriptUrl:a,texturePack:r?.texturePack},e,i,n)}},xn=new Set;function Xe(t,e){let i=`[three-live] ${t} is unsupported; degraded to ${e}.`;xn.has(i)||(xn.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function qr(){return Array.from(xn)}function Zr(){xn.clear()}var Tt=class extends qe{constructor(t={}){Xe("ShaderMaterial","MeshStandardMaterial");let e=t.uniforms||{},i=e.color?.value??e.uColor?.value??e.diffuse?.value??t.color;super({color:i!==void 0?i:8421504,opacity:e.opacity?.value??t.opacity??1,transparent:!!t.transparent,wireframe:!!t.wireframe,side:t.side}),this.uniforms=e}},Jr=Tt,He=class extends xe{constructor(t=[],e=[],i=1,r=0){super();let n=Number(i)||1,s=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),a=s+1,o=[],l=[],y=[],f=[],b=new Q,h=new Q,d=new Q,v=(u,g)=>g.set(t[u*3]||0,t[u*3+1]||0,t[u*3+2]||0),M=(u,g)=>{let p=u.clone().normalize();o.push(p.x*n,p.y*n,p.z*n),l.push(g.x,g.y,g.z),y.push(Math.atan2(p.z,-p.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,p.y)))/Math.PI)},m=(u,g,p)=>{let x=o.length/3,w=s===0?new Q().subVectors(p,g).cross(new Q().subVectors(u,g)).normalize():null;M(u,w||u.clone().normalize()),M(g,w||g.clone().normalize()),M(p,w||p.clone().normalize()),f.push(x,x+1,x+2)};for(let u=0;u<e.length;u+=3){v(e[u],b),v(e[u+1],h),v(e[u+2],d);let g=[];for(let p=0;p<=a;p++){g[p]=[];let x=b.clone().lerp(d,p/a),w=h.clone().lerp(d,p/a),_=a-p;for(let N=0;N<=_;N++)g[p][N]=_===0?x.clone():x.clone().lerp(w,N/_)}for(let p=0;p<a;p++)for(let x=0;x<2*(a-p)-1;x++){let w=x>>1;(x&1)===0?m(g[p][w+1],g[p+1][w],g[p][w]):m(g[p][w+1],g[p+1][w+1],g[p+1][w])}}this.setFromBuffers(o,l,y,f)}},Hi=He,vn=class extends He{constructor(t=1,e=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],t,e)}},ar=t=>Array.from(t,e=>parseInt(e,36)),jt=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],Qr=ar("024043035052125153134142"),Mn=class extends He{constructor(t=1,e=0){super(jt,Qr,t,e)}},be=(1+Math.sqrt(5))/2,Sn=class extends He{constructor(t=1,e=0){super([-1,be,0,1,be,0,-1,-be,0,1,-be,0,0,-1,be,0,1,be,0,-1,-be,0,1,-be,be,0,-1,be,0,1,-be,0,-1,-be,0,1],ar("0b505101707a0ab1595b4ba2a7671839434232636838949524b62a867981"),t,e)}},De=1/be,wn=class extends He{constructor(t=1,e=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-De,-be,0,-De,be,0,De,-be,0,De,be,-De,-be,0,-De,be,0,De,-be,0,De,be,0,-be,0,-De,be,0,-De,-be,0,De,be,0,De],ar("3b737f3fd7jh7h676fh48h8aha680g8g282a0c101i0ig6a262d6df2gi2i323di19i9bib34ec4c0408b95b5jbj7j5eje4j4h1ce1e5159"),t,e)}},_n=class extends yt{constructor(t=1,e=1,i=4,r=8){let n=Math.max(1e-4,Number(t)||1),s=Math.max(0,Number.isFinite(Number(e))?Number(e):1)*.5,a=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),o=[];for(let l=-1;l<=1;l+=2)for(let y=0;y<=a;y++){if(l>0&&y===0&&s===0)continue;let f=(l<0?y/a-1:y/a)*(Math.PI/2);o.push(new Ee(Math.max(0,Math.cos(f)*n),l*s+Math.sin(f)*n))}super(o,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},Et=class extends xe{constructor(t=.5,e=1,i=32,r=1,n=0,s=Math.PI*2){super();let a=Math.max(1e-4,Number(e)||1),o=Number(t),l=Number.isFinite(o)?Math.max(0,o):a*.5,y=Math.max(a,l),f=Math.min(y*.999,Math.min(a,l)),b=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),h=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),d=Number.isFinite(Number(n))?Number(n):0,v=Number.isFinite(Number(s))?Number(s):Math.PI*2,M=[],m=[],u=[],g=[];for(let p=0;p<=h;p++){let x=f+p/h*(y-f);for(let w=0;w<=b;w++){let _=d+w/b*v,N=Math.cos(_),P=Math.sin(_);if(M.push(x*N,x*P,0),m.push(0,0,1),u.push(x/y*N*.5+.5,x/y*P*.5+.5),p<h&&w<b){let E=p*(b+1)+w,T=E+b+1;x>1e-6&&g.push(E,T,E+1),g.push(T,T+1,E+1)}}}this.setFromBuffers(M,m,u,g)}},An=class extends Et{constructor(t=1,e=32,i=0,r=Math.PI*2){super(0,t,e,1,i,r)}},Rt=class extends Ce{constructor(t={}){super({roughness:.35,metalness:.1,side:2,...t});let e=Number(t.size);this.size=Number.isFinite(e)?Math.max(.002,Math.min(2,e)):.05,this.sizeAttenuation=t.sizeAttenuation!==!1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},nt=class extends Ce{constructor(t={}){super({roughness:.4,metalness:.1,side:2,...t});let e=Number(t.linewidth);this.linewidth=Number.isFinite(e)?Math.max(.5,Math.min(20,e)):1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},Tn=class extends nt{constructor(t={}){super(t),this.dashSize=Number(t.dashSize)||3,this.gapSize=Number(t.gapSize)||1,this.scale=Number(t.scale)||1}};function ei(t,e){let i=t?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,n=t?.index?.array,s=Math.min(8192,Math.floor((n?n.length:i.count)/3)),a=h=>`${Math.round((r[h*3]||0)*1e4)},${Math.round((r[h*3+1]||0)*1e4)},${Math.round((r[h*3+2]||0)*1e4)}`,o=e===void 0,l=o?1:Math.cos(e*Math.PI/180),y={},f=[],b=(h,d)=>f.push(r[h*3]||0,r[h*3+1]||0,r[h*3+2]||0,r[d*3]||0,r[d*3+1]||0,r[d*3+2]||0);for(let h=0;h<s;h++){let d=n?n[h*3]:h*3,v=n?n[h*3+1]:h*3+1,M=n?n[h*3+2]:h*3+2,m=r[d*3]||0,u=r[d*3+1]||0,g=r[d*3+2]||0,p=(r[v*3]||0)-m,x=(r[v*3+1]||0)-u,w=(r[v*3+2]||0)-g,_=(r[M*3]||0)-m,N=(r[M*3+1]||0)-u,P=(r[M*3+2]||0)-g,E=x*P-w*N,T=w*_-p*P,S=p*N-x*_,A=Math.hypot(E,T,S);if(!o&&A<1e-8)continue;A>0&&(E/=A,T/=A,S/=A);let D=[d,v,M];for(let R=0;R<3;R++){let F=D[R],k=D[(R+1)%3],V=a(F),L=a(k);if(V===L)continue;let O=V<L?`${V}|${L}`:`${L}|${V}`,c=y[O];c?c.m||(c.m=1,c.nx*E+c.ny*T+c.nz*S<=l&&b(F,k)):(y[O]={va:F,vb:k,nx:E,ny:T,nz:S,m:o?1:0},o&&b(F,k))}}if(!o){let h=Object.keys(y);for(let d=0;d<h.length;d++){let v=y[h[d]];v&&!v.m&&b(v.va,v.vb)}}return new Float32Array(f)}var En=class extends xe{constructor(t){super(),this.setAttribute("position",new we(ei(t),3)),this.__isSegmentPairs=!0}},Rn=class extends xe{constructor(t,e=1){super();let i=Number.isFinite(Number(e))?Number(e):1;this.setAttribute("position",new we(ei(t,i),3)),this.__isSegmentPairs=!0}};function ji(t,e,i=1){let r=new xe;r.__baked=!0;let n=t?.attributes?.position;if(!n?.array||n.count<2)return r;let s=n.array,a=t.index?.array,o=t.__isSegmentPairs?"segments":e,l=a?a.length:n.count,y=Math.min(4096,Math.max(0,o==="segments"?Math.floor(l/2):o==="loop"&&l>=3?l:l-1));if(y===0)return r;t.computeBoundingBox();let f=t.boundingBox,b=f&&f.max.x>=f.min.x&&f.max.distanceTo(f.min)||1,h=Math.max(.0015,Math.min(.025,b*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),d=[],v=[],M=[],m=[];for(let u=0;u<y;u++){let g=o==="segments"?u*2:u,p=o==="segments"?u*2+1:(u+1)%l,x=a?a[g]:g,w=a?a[p]:p,_=s[x*3]||0,N=s[x*3+1]||0,P=s[x*3+2]||0,E=(s[w*3]||0)-_,T=(s[w*3+1]||0)-N,S=(s[w*3+2]||0)-P,A=Math.hypot(E,T,S);if(A<1e-6)continue;let D=E/A,R=T/A,F=S/A,k=(Math.abs(R)<.9?Math.hypot(F,D):Math.hypot(F,R))||1,V=Math.abs(R)<.9?F/k:0,L=Math.abs(R)<.9?0:-F/k,O=Math.abs(R)<.9?-D/k:R/k,c=R*O-F*L,I=F*V-D*O,C=D*L-R*V,U=d.length/3,j=[[V,L,O],[c,I,C],[-V,-L,-O],[-c,-I,-C]];for(let H=0;H<2;H++){let Y=_+H*E,q=N+H*T,ne=P+H*S;for(let ie=0;ie<4;ie++){let oe=j[ie];d.push(Y+oe[0]*h,q+oe[1]*h,ne+oe[2]*h),v.push(oe[0],oe[1],oe[2]),M.push(ie/4,H)}}for(let H=0;H<4;H++){let Y=(H+1)%4;m.push(U+H,U+Y,U+4+Y,U+H,U+4+Y,U+4+H)}}return d.length>0&&r.setFromBuffers(d,v,M,m),r}function $i(t,e=.05){let i=new xe;i.__baked=!0;let r=t?.attributes?.position;if(!r?.array||r.count<1)return i;let n=r.array,s=r.count,a=Math.min(s,5e3),o=Math.max(.003,Math.min(.25,(Number(e)||.05)*.6)),l=[],y=[],f=[],b=[];for(let h=0;h<a;h++){let d=s<=5e3?h:Math.floor(h*s/a),v=n[d*3]||0,M=n[d*3+1]||0,m=n[d*3+2]||0,u=h*6;for(let g=0;g<6;g++){let p=jt[g*3],x=jt[g*3+1],w=jt[g*3+2];l.push(v+p*o,M+x*o,m+w*o),y.push(p,x,w),f.push(.5,.5)}for(let g=0;g<24;g++)b.push(u+Qr[g])}return i.setFromBuffers(l,y,f,b),i}var Ke=class extends Oe{constructor(t,e,i="strip"){let r=e&&typeof e=="object"?e:{},n=e instanceof Ce?e:i==="points"?new Rt(r):new nt(r),s=t instanceof xe?t:new xe;super(s,n),this.isLine=!0,this._lineMode=i,this._sourceGeo=s}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let t=this._lineMode==="points";if(t){let e=this._sourceGeo?.attributes?.color;if(e?.array&&e.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=e.array,r=Math.min(e.count,64),n=0,s=0,a=0;for(let o=0;o<r;o++)n+=i[o*3]||0,s+=i[o*3+1]||0,a+=i[o*3+2]||0;this.material.color.setRGB(n/r,s/r,a/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(t?1:2)&&(this.geometry=t?$i(this._sourceGeo,this.material?.size??.05):ji(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},Ln=class extends Ke{constructor(t,e){super(t,e,"loop"),this.isLineLoop=!0}},Cn=class extends Ke{constructor(t,e){super(t,e,"segments"),this.isLineSegments=!0}},Dn=class extends Ke{constructor(t,e){super(t,e,"points"),this.isPoints=!0}},In=class extends wt{constructor(t,e,i=0,r=Math.PI/3,n=0,s=2){super(t,e,i,s),this.target=new ke,this.type="spot";let a=Number(r);this.angle=Number.isFinite(a)?Math.max(.01,Math.min(Math.PI/2,a)):Math.PI/3;let o=Number(n);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},Lt=class extends Ge{constructor(t,e,i){super(t,i),this.type="hemisphere",this.groundColor=new Pe(e??4473924),this.position.set(0,1,0)}},Nn=class extends St{constructor(t,e){Xe("RectAreaLight","AmbientLight"),super(t,e)}},ti={Vector2:Ee,Vector3:Q,Vector4:Wt,Euler:pt,Quaternion:Qe,Matrix4:We,Matrix3:Xt,Color:Pe,MathUtils:Br,BufferAttribute:we,Float32BufferAttribute:Kt,Uint16BufferAttribute:Yt,Uint32BufferAttribute:qt,BufferGeometry:xe,BoxGeometry:bt,PlaneGeometry:Zt,SphereGeometry:Jt,CylinderGeometry:gt,ConeGeometry:Qt,TorusGeometry:en,TorusKnotGeometry:tn,Curve:ze,Curve3:ze,LineCurve3:nn,QuadraticBezierCurve3:rn,CubicBezierCurve3:on,CatmullRomCurve3:sn,LatheGeometry:yt,TubeGeometry:an,PolyhedronGeometry:He,IcosahedronGeometry:Sn,OctahedronGeometry:Mn,DodecahedronGeometry:wn,TetrahedronGeometry:vn,CapsuleGeometry:_n,RingGeometry:Et,CircleGeometry:An,WireframeGeometry:En,EdgesGeometry:Rn,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,BasicShadowMap:0,PCFShadowMap:1,PCFSoftShadowMap:2,VSMShadowMap:3,Texture:et,DataTexture:cn,TextureLoader:un,Material:Ce,MeshStandardMaterial:qe,MeshBasicMaterial:ln,MeshLambertMaterial:mn,MeshPhongMaterial:hn,MeshPhysicalMaterial:dn,PointsMaterial:Rt,LineBasicMaterial:nt,LineDashedMaterial:Tn,ShaderMaterial:Tt,RawShaderMaterial:Jr,Object3D:ke,Group:fn,Mesh:Oe,InstancedMesh:vt,Line:Ke,LineLoop:Ln,LineSegments:Cn,Points:Dn,LightShadow:Mt,Light:Ge,AmbientLight:St,DirectionalLight:pn,PointLight:wt,SpotLight:In,HemisphereLight:Lt,RectAreaLight:Nn,Camera:_t,PerspectiveCamera:bn,Scene:At,WebGLRenderer:gn,Clock:yn,SceneQuotaValidator:Ue,exportSceneToCanvas3D:tr,exportSceneToGLB:nr,exportSceneToUSDZ:Gr,generateUSDZ:Jn,glbToUSDZ:zt,sceneToCanvas3D:Je,sceneToGLB:lt,sceneToUSDZ:mt,authorScriptRunner:Yr,warnUnsupported:Xe,getAuthorWarnings:qr,clearAuthorWarnings:Zr};Object.freeze(Ue),Object.freeze(Ue.prototype),Object.freeze(At.prototype),Object.freeze(ti);var Ze=new Proxy(ti,{get:(t,e)=>{if(e in t)return t[e];let i=de().authorNamespace;return i&&typeof e=="string"&&e in i?i[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&Xe(`THREE.${e}`,"no-op proxy"),dt)},has:(t,e)=>{if(e in t)return!0;let i=de().authorNamespace;return!!(i&&typeof e=="string"&&e in i)},set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),$t=de();if($t.threeNamespace=Ze,$t.workerExtensionInstallers)for(let t of $t.workerExtensionInstallers)t(Ze,$t);var ft={name:"three_author",THREE:Ze},Wi=ft,Ve=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof Ve.THREE>"u"&&(Ve.THREE=Ze),typeof Ve.requestAnimationFrame!="function"&&(Ve.requestAnimationFrame=t=>(typeof t=="function"&&typeof Ve.__three_live_raf_cb__!="function"&&(Ve.__three_live_raf_cb__=t),Ve.__three_live_in_step__||Xe("requestAnimationFrame","single-frame static evaluation"),0)),typeof Ve.cancelAnimationFrame!="function"&&(Ve.cancelAnimationFrame=()=>{}),typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=Ze,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=ft,t.ThreeLivePlugins.three_author=ft,t.ThreeLivePlugins["three-author"]=ft}var Xi=Ze;
|