three-live 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/index.d.ts +66 -2
- package/dist/three-author-engine.js +85 -42
- package/dist/three-author.cjs +84 -42
- package/dist/three-author.d.ts +66 -2
- package/dist/three-author.js +84 -42
- package/dist/three-convert.cjs +84 -42
- package/dist/three-convert.d.ts +66 -2
- package/dist/three-convert.js +84 -42
- package/dist/three-live-animation.cjs +7 -7
- package/dist/three-live-animation.d.ts +66 -2
- package/dist/three-live-animation.js +7 -7
- package/dist/three-live-animation.min.js +7 -7
- package/dist/three-live-cad.cjs +18 -0
- package/dist/{three-live-extras.d.ts → three-live-cad.d.ts} +66 -2
- package/dist/three-live-cad.js +18 -0
- package/dist/three-live-cad.min.js +18 -0
- package/dist/three-live-element.cjs +48 -6
- package/dist/three-live-element.d.ts +66 -2
- package/dist/three-live-element.js +48 -6
- package/dist/three-live-full.cjs +176 -55
- package/dist/three-live-full.js +176 -55
- package/dist/three-live-full.min.js +176 -55
- package/dist/three-live-studio.cjs +120 -0
- package/dist/three-live-studio.d.ts +510 -0
- package/dist/three-live-studio.js +120 -0
- package/dist/three-live-studio.min.js +120 -0
- package/dist/three-live-viewer.cjs +48 -6
- package/dist/three-live-viewer.d.ts +66 -2
- package/dist/three-live-viewer.js +48 -6
- package/dist/three-live-viewer.min.js +48 -6
- package/dist/three-live.cjs +86 -44
- package/dist/three-live.js +86 -44
- package/dist/three-live.min.js +86 -44
- package/dist/three-view.cjs +48 -6
- package/dist/three-view.d.ts +66 -2
- package/dist/three-view.js +48 -6
- package/dist/three-xr.cjs +83 -41
- package/dist/three-xr.d.ts +66 -2
- package/dist/three-xr.js +83 -41
- package/package.json +10 -5
- package/dist/three-live-extras.cjs +0 -42
- package/dist/three-live-extras.js +0 -42
- package/dist/three-live-extras.min.js +0 -42
|
@@ -14,16 +14,32 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
"use strict";var ThreeEngine=(()=>{var Wt=Object.defineProperty;var cr=Object.getOwnPropertyDescriptor;var ur=Object.getOwnPropertyNames;var lr=Object.prototype.hasOwnProperty;var hr=(t,e)=>{for(var n in e)Wt(t,n,{get:e[n],enumerable:!0})},mr=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ur(e))!lr.call(t,i)&&i!==n&&Wt(t,i,{get:()=>e[i],enumerable:!(r=cr(e,i))||r.enumerable});return t};var dr=t=>mr(Wt({},"__esModule",{value:!0}),t);var Di={};hr(Di,{AmbientLight:()=>Ze,BoxGeometry:()=>je,BufferAttribute:()=>G,BufferGeometry:()=>ue,Camera:()=>Qe,CapsuleGeometry:()=>Vt,CircleGeometry:()=>Xt,Clock:()=>Nt,Color:()=>me,ConeGeometry:()=>St,CylinderGeometry:()=>Re,DirectionalLight:()=>Lt,DodecahedronGeometry:()=>zt,Euler:()=>$e,Float32BufferAttribute:()=>vt,Group:()=>Pt,HemisphereLight:()=>tt,IcosahedronGeometry:()=>Ft,Light:()=>Me,Material:()=>de,MathUtils:()=>Xn,Matrix3:()=>xt,Matrix4:()=>be,Mesh:()=>ke,MeshBasicMaterial:()=>_t,MeshLambertMaterial:()=>Ct,MeshPhongMaterial:()=>Dt,MeshPhysicalMaterial:()=>It,MeshStandardMaterial:()=>_e,Object3D:()=>oe,OctahedronGeometry:()=>Ot,PerspectiveCamera:()=>Fe,PlaneGeometry:()=>Et,PointLight:()=>Je,PolyhedronFallbackGeometry:()=>De,Quaternion:()=>Ye,RawShaderMaterial:()=>Qn,RectAreaLight:()=>er,RingGeometry:()=>Ht,Scene:()=>Ce,SceneQuotaValidator:()=>fe,ShaderMaterial:()=>et,SphereGeometry:()=>qe,SpotLight:()=>Gt,THREE:()=>nt,TetrahedronGeometry:()=>Bt,Texture:()=>Ke,TextureLoader:()=>At,TorusGeometry:()=>Rt,TorusKnotGeometry:()=>Mt,Uint16BufferAttribute:()=>Tt,Uint32BufferAttribute:()=>wt,Vector2:()=>yt,Vector3:()=>J,Vector4:()=>gt,WebGLRenderer:()=>Ut,authorScriptRunner:()=>Zn,buildSandboxWorkerSource:()=>hn,clearAuthorWarnings:()=>dn,default:()=>Ci,exportSceneToCanvas3D:()=>cn,exportSceneToGLB:()=>un,exportSceneToUSDZ:()=>Gn,generateUSDZ:()=>Jt,getAllowClientScripts:()=>Yn,getAuthorWarnings:()=>Jn,getSandboxEngineSrc:()=>ln,getSandboxIframeSrc:()=>$n,glbToUSDZ:()=>dt,isAllowedSandboxEngineUrl:()=>Ae,noopProxy:()=>Ne,sceneToCanvas3D:()=>Le,sceneToGLB:()=>He,sceneToUSDZ:()=>Ue,setAllowClientScripts:()=>xi,setSandboxEngineSrc:()=>pi,setSandboxIframeSrc:()=>yi,threeAuthorPlugin:()=>We,threeMicroPlugin:()=>_i,toTrustedWorkerScriptURL:()=>Wn,validateSandboxWorkerMessage:()=>mn,warnUnsupported:()=>se});function ot(t,e,n){let r=[],i=new Map,o=[],c=[],h=[],u=new Map,s=y=>{let w=i.get(y);return w===void 0&&(w=r.length,r.push({op:y}),i.set(y,w)),w},a=y=>{let w=u.get(y);return w===void 0&&(w=h.length,h.push({id:y}),u.set(y,w)),w},m=(y,w={})=>o.push({declaration:s(y),...w})-1,l=(y,w,b)=>c.push({id:y,type:w,value:b})-1,f=y=>({node:y,socket:"value"}),d=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(d&&typeof d=="object"){let y=Array.isArray(d.graphs)?d.graphs[d.graph??0]:d;if(y&&Array.isArray(y.nodes)){let w=Array.isArray(y.declarations)?y.declarations:[];for(let b of w)b?.op&&s(b.op);Array.isArray(y.variables)&&c.push(...y.variables);for(let b of y.events||[])b?.id&&a(b.id);for(let b of y.nodes){if(!b||typeof b!="object")continue;let R=b.op||(typeof b.declaration=="number"?w[b.declaration]?.op:"");o.push(R?{...b,declaration:s(R)}:{...b})}}}let S=(y,w,b="translation")=>b==="baseColorFactor"||b==="metallicFactor"||b==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${b}`:b==="emissiveFactor"||b==="alphaCutoff"?`/materials/${Math.max(0,w)}/${b}`:b==="visible"?`/nodes/${y}/extensions/KHR_node_visibility/visible`:`/nodes/${y}/${b}`,A=new Map;t.forEach((y,w)=>{typeof y?.name=="string"&&!A.has(y.name)&&A.set(y.name,w)});let M=(y,w)=>typeof y.target=="string"&&A.has(y.target)?A.get(y.target):typeof y.targetNode=="number"?y.targetNode:w,P=y=>{let w=t[y];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let y=0;y<t.length;y++){let w=t[y],b=w?.extras?.interactivity;if(!b||typeof b!="object")continue;let R=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,p=v=>{let _=Array.isArray(v)?v:[v],D=[];for(let T=0;T<_.length;T++){let x=_[T];if(!x||typeof x!="object")continue;let L=x.action||"interpolate",I=typeof x.duration=="number"?x.duration:.35;if(L==="toggleTransform"){let H=x.property==="rotation"||x.property==="scale"?x.property:"translation",k=H==="rotation"?w.rotation||[0,0,0,1]:H==="scale"?w.scale||[1,1,1]:w.translation||[0,0,0],U=`/nodes/${y}/${H}`,N=l(`__toggle_${y}_${T}`,"bool",!1),C=m("variable/get",{configuration:{variable:N}}),O=m("math/not",{values:{a:f(C)}}),F=m("variable/set",{configuration:{variable:N},values:{value:f(O)}}),V=m("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.to)?x.to:k},duration:{value:I}}}),z=m("pointer/interpolate",{configuration:{pointer:U},values:{value:{value:Array.isArray(x.from)?x.from:k},duration:{value:I}}});o[F].flows={out:{node:m("flow/branch",{values:{condition:f(C)},flows:{true:{node:V},false:{node:z}}})}},D.push(F)}else if(L==="interpolate"){let H=x.to??x.value;if(H===void 0)continue;let k={value:{value:H},duration:{value:I}};x.from!==void 0&&(k.from={value:x.from}),D.push(m("pointer/interpolate",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:S(M(x,y),P(M(x,y)),x.property)},values:k}))}else if(L==="setProperty"){if(x.value===void 0)continue;D.push(m("pointer/set",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:S(M(x,y),P(M(x,y)),x.property)},values:{value:{value:x.value}}}))}else if(L==="toggleVisibility"){let H=M(x,y),k=l(`__vis_${H}_${T}`,"bool",!0),U=m("variable/get",{configuration:{variable:k}}),N=m("math/not",{values:{a:f(U)}}),C=m("variable/set",{configuration:{variable:k},values:{value:f(N)}});o[C].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${H}/extensions/KHR_node_visibility/visible`},values:{value:f(U)}})}},D.push(C)}else if(L==="cycleMaterialColor"&&Array.isArray(x.colors)&&x.colors.length>0){let H=typeof x.duration=="number"?x.duration:.25,k=`/materials/${Math.max(0,R)}/pbrMetallicRoughness/baseColorFactor`,U=l(`__color_idx_${y}_${T}`,"int",0),N=m("variable/get",{configuration:{variable:U}}),C=m("math/add",{values:{a:f(N),b:{value:1}}}),O=m("math/rem",{values:{a:f(C),b:{value:x.colors.length}}}),F=m("variable/set",{configuration:{variable:U},values:{value:f(O)}}),V={};for(let z=0;z<x.colors.length;z++){let X=x.colors[z],Y=Array.isArray(X)&&X.length>=3?[X[0],X[1],X[2],X[3]??1]:[1,1,1,1];V[String(z)]={node:H>0?m("pointer/interpolate",{configuration:{pointer:k},values:{value:{value:Y},duration:{value:H}}}):m("pointer/set",{configuration:{pointer:k},values:{value:{value:Y}}})}}o[F].flows={out:{node:m("flow/switch",{values:{selection:f(N)},flows:V})}},D.push(F)}else if(L==="playAnimation")D.push(m("animation/start",{configuration:{animation:x.animation??x.clip??0}}));else if(L==="stopAnimation")D.push(m("animation/stop"));else if(L==="sendEvent"){let H={};for(let[k,U]of Object.entries(x.values||{}))H[k]={value:U};D.push(m("event/send",{configuration:{event:a(String(x.event??x.id??"custom"))},values:H}))}}if(!D.length)return null;if(D.length===1)return D[0];let g={};return D.forEach((T,x)=>{g[String(x)]={node:T}}),m("flow/sequence",{flows:g})},E=(v,_,D)=>{let g=p(_);g!==null&&m(v,{...D?{configuration:D}:{},flows:{out:{node:g}}})};if(b.onSelect&&E("pointer/onSelect",b.onSelect,{nodeIndex:y}),b.onHoverIn&&E("pointer/onHoverIn",b.onHoverIn,{nodeIndex:y}),b.onHoverOut&&E("pointer/onHoverOut",b.onHoverOut,{nodeIndex:y}),b.onStart&&E("event/onStart",b.onStart),b.onReceive&&typeof b.onReceive=="object")for(let[v,_]of Object.entries(b.onReceive))E("event/receive",_,{event:a(v)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:c,events:h}],graph:0}:null}var fn='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).',pn="Security Error: client-side scripts require allow-client-scripts opt-in.";var st="__THREE_LIVE_REGISTRY__";function Q(){let t=typeof globalThis<"u"?globalThis:{};if(!t[st]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,st,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[st]=e}}return t[st]}var ee=Q().plugins;function bn(t){let e=Q().plugins;e.some(n=>n.name===t.name)||e.push(t)}function yn(){return Q().plugins}function Z(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function at(t,e,n,r,i){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let c=1/(r-i);return t[10]=(i+r)*c,t[14]=2*i*r*c,t}function Pe(t,e,n,r){let[i,o,c]=e,[h,u,s]=r,[a,m,l]=n,f=i-a,d=o-m,S=c-l,A=Math.hypot(f,d,S);A<=1e-5?(f=0,d=0,S=1):(f/=A,d/=A,S/=A);let M=u*S-s*d,P=s*f-h*S,y=h*d-u*f;A=Math.hypot(M,P,y),A<=1e-5?(M=0,P=0,y=0):(M/=A,P/=A,y/=A);let w=d*y-S*P,b=S*M-f*y,R=f*P-d*M;return A=Math.hypot(w,b,R),A<=1e-5?(w=0,b=0,R=0):(w/=A,b/=A,R/=A),t[0]=M,t[1]=w,t[2]=f,t[3]=0,t[4]=P,t[5]=b,t[6]=d,t[7]=0,t[8]=y,t[9]=R,t[10]=S,t[11]=0,t[12]=-(M*i+P*o+y*c),t[13]=-(w*i+b*o+R*c),t[14]=-(f*i+d*o+S*c),t[15]=1,t}function ie(t,e,n){let r=e[0],i=e[1],o=e[2],c=e[3],h=e[4],u=e[5],s=e[6],a=e[7],m=e[8],l=e[9],f=e[10],d=e[11],S=e[12],A=e[13],M=e[14],P=e[15],y=n[0],w=n[1],b=n[2],R=n[3];return t[0]=y*r+w*h+b*m+R*S,t[1]=y*i+w*u+b*l+R*A,t[2]=y*o+w*s+b*f+R*M,t[3]=y*c+w*a+b*d+R*P,y=n[4],w=n[5],b=n[6],R=n[7],t[4]=y*r+w*h+b*m+R*S,t[5]=y*i+w*u+b*l+R*A,t[6]=y*o+w*s+b*f+R*M,t[7]=y*c+w*a+b*d+R*P,y=n[8],w=n[9],b=n[10],R=n[11],t[8]=y*r+w*h+b*m+R*S,t[9]=y*i+w*u+b*l+R*A,t[10]=y*o+w*s+b*f+R*M,t[11]=y*c+w*a+b*d+R*P,y=n[12],w=n[13],b=n[14],R=n[15],t[12]=y*r+w*h+b*m+R*S,t[13]=y*i+w*u+b*l+R*A,t[14]=y*o+w*s+b*f+R*M,t[15]=y*c+w*a+b*d+R*P,t}function ct(t,e,n,r){let i=e[0],o=e[1],c=e[2],h=e[3],u=i+i,s=o+o,a=c+c,m=i*u,l=i*s,f=i*a,d=o*s,S=o*a,A=c*a,M=h*u,P=h*s,y=h*a,w=r[0],b=r[1],R=r[2];return t[0]=(1-(d+A))*w,t[1]=(l+y)*w,t[2]=(f-P)*w,t[3]=0,t[4]=(l-y)*b,t[5]=(1-(m+A))*b,t[6]=(S+M)*b,t[7]=0,t[8]=(f+P)*R,t[9]=(S-M)*R,t[10]=(1-(m+d))*R,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function ce(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],c=e[5],h=e[6],u=e[8],s=e[9],a=e[10],m=a*c-h*s,l=-a*o+h*u,f=s*o-c*u,d=n*m+r*l+i*f;return d&&(d=1/d,t[0]=m*d,t[1]=(-a*r+i*s)*d,t[2]=(h*r-i*c)*d,t[3]=l*d,t[4]=(a*n-i*u)*d,t[5]=(-h*n+i*o)*d,t[6]=f*d,t[7]=(-s*n+r*u)*d,t[8]=(c*n-r*o)*d),t}function gn(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],c=e[4],h=e[5],u=e[6],s=e[7],a=e[8],m=e[9],l=e[10],f=e[11],d=e[12],S=e[13],A=e[14],M=e[15],P=n*h-r*c,y=n*u-i*c,w=n*s-o*c,b=r*u-i*h,R=r*s-o*h,p=i*s-o*u,E=a*S-m*d,v=a*A-l*d,_=a*M-f*d,D=m*A-l*S,g=m*M-f*S,T=l*M-f*A,x=P*T-y*g+w*D+b*_-R*v+p*E;return x?(x=1/x,t[0]=(h*T-u*g+s*D)*x,t[1]=(i*g-r*T-o*D)*x,t[2]=(S*p-A*R+M*b)*x,t[3]=(l*R-m*p-f*b)*x,t[4]=(u*_-c*T-s*v)*x,t[5]=(n*T-i*_+o*v)*x,t[6]=(A*w-d*p-M*y)*x,t[7]=(a*p-l*w+f*y)*x,t[8]=(c*g-h*_+s*E)*x,t[9]=(r*_-n*g-o*E)*x,t[10]=(d*R-S*w+M*P)*x,t[11]=(m*w-a*R-f*P)*x,t[12]=(h*v-c*D-u*E)*x,t[13]=(n*D-r*v+i*E)*x,t[14]=(S*y-d*b-A*P)*x,t[15]=(a*b-m*y+l*P)*x,t):null}function $t(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],c=i[1]*e+i[5]*n+i[9]*r+i[13],h=i[2]*e+i[6]*n+i[10]*r+i[14],u=i[3]*e+i[7]*n+i[11]*r+i[15],s=u!==0?1/u:1;t[0]=o*s,t[1]=c*s,t[2]=h*s}function xn(t,e,n,r,i,o,c,h,u,s,a,m,l,f,d,S,A=0){let M=s-c,P=a-h,y=m-u,w=l-c,b=f-h,R=d-u,p=i*R-o*b,E=o*w-r*R,v=r*b-i*w,_=M*p+P*E+y*v;if(_>-1e-7&&_<1e-7)return!1;let D=1/_,g=t-c,T=e-h,x=n-u,L=D*(g*p+T*E+x*v);if(L<-A||L>1+A)return!1;let I=T*y-x*P,H=x*M-g*y,k=g*P-T*M,U=D*(r*I+i*H+o*k);if(U<-A||L+U>1+A)return!1;let N=D*(w*I+b*H+R*k);if(N>1e-4&&N<S.distance){S.distance=N,S.point=[t+r*N,e+i*N,n+o*N];let C=P*R-y*b,O=y*w-M*R,F=M*b-P*w,V=Math.hypot(C,O,F)||1;return S.normal=[C/V,O/V,F/V],!0}return!1}function ut(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let a=0;a<n;a++)r.push(Z());if(n===0)return r;let i=new Set;for(let a of t.nodes)if(Array.isArray(a.children))for(let m of a.children)i.add(m);let o=new Set,c=128,h=(a,m,l=0)=>{if(l>c||a<0||a>=n||o.has(a))return;o.add(a);let f=t.nodes[a];if(!f)return;let d=Z();if(e&&e[a])d.set(e[a]);else if(f.matrix&&f.matrix.length===16)d.set(f.matrix);else{let A=f.translation||[0,0,0],M=f.rotation||[0,0,0,1],P=f.scale||[1,1,1];ct(d,M,A,P)}let S=r[a];if(m?ie(S,m,d):S.set(d),Array.isArray(f.children))for(let A of f.children)typeof A=="number"&&h(A,S,l+1)},u=[],s=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(s&&Array.isArray(s.nodes))u.push(...s.nodes);else for(let a=0;a<n;a++)i.has(a)||u.push(a);for(let a of u)h(a,null);for(let a=0;a<n;a++)!i.has(a)&&!u.includes(a)&&h(a,null);return r}function fr(t){return new TextDecoder().decode(t)}var En=Q().decoders;function pr(t,e){En.set(t.toLowerCase(),e)}function Be(t){return En.get(t.toLowerCase())}function Sn(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let l=n.getUint8(0);throw l===123||l===32||l===10||l===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=n.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let o=n.getUint32(8,!0),c=12,h=null,u=null;for(;c+8<=o&&c+8<=e.byteLength;){let l=n.getUint32(c,!0),f=n.getUint32(c+4,!0),d=c+8;if(d+l>e.byteLength)throw new Error(`Truncated GLB chunk: required ${d+l} bytes, buffer has ${e.byteLength}`);if(f===1313821514){let S=new Uint8Array(e,d,l),A=fr(S);h=JSON.parse(A,(M,P)=>M==="__proto__"||M==="constructor"||M==="prototype"?void 0:P)}else f===5130562&&(u=e.slice(d,d+l));c=d+l}if(!h)throw new Error("Missing JSON chunk in GLB");let s=h.extensionsRequired||[];if(s.includes("KHR_draco_mesh_compression")&&!Be("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(s.includes("EXT_meshopt_compression")&&!Be("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(s.includes("KHR_texture_basisu")&&!Be("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let a=u||new ArrayBuffer(0),m={gltf:h,bin:a,animations:[]};for(let l of ee)l.onParseGLB?.(m);return m}function br(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 Ve(t){if(br(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return Sn(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Rn=`#version 300 es
|
|
17
|
+
"use strict";var ThreeEngine=(()=>{var Wn=Object.defineProperty;var Ei=Object.getOwnPropertyDescriptor;var Ri=Object.getOwnPropertyNames;var _i=Object.prototype.hasOwnProperty;var Ci=(t,e)=>{for(var n in e)Wn(t,n,{get:e[n],enumerable:!0})},Ii=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ri(e))!_i.call(t,i)&&i!==n&&Wn(t,i,{get:()=>e[i],enumerable:!(r=Ei(e,i))||r.enumerable});return t};var Di=t=>Ii(Wn({},"__esModule",{value:!0}),t);var is={};Ci(is,{AmbientLight:()=>Qt,BoxGeometry:()=>Yt,BufferAttribute:()=>be,BufferGeometry:()=>Ye,Camera:()=>en,CapsuleGeometry:()=>Vn,CircleGeometry:()=>Gn,Clock:()=>Pn,Color:()=>qe,ConeGeometry:()=>wn,CylinderGeometry:()=>dt,DirectionalLight:()=>Ln,DodecahedronGeometry:()=>Un,Euler:()=>$t,Float32BufferAttribute:()=>xn,Group:()=>Dn,HemisphereLight:()=>nn,IcosahedronGeometry:()=>Fn,InstancedMesh:()=>Ot,Light:()=>bt,MAX_INSTANCES_PER_MESH:()=>Zt,Material:()=>Ke,MathUtils:()=>hi,Matrix3:()=>gn,Matrix4:()=>rt,Mesh:()=>Tt,MeshBasicMaterial:()=>Rn,MeshLambertMaterial:()=>_n,MeshPhongMaterial:()=>Cn,MeshPhysicalMaterial:()=>In,MeshStandardMaterial:()=>pt,Object3D:()=>We,OctahedronGeometry:()=>On,PerspectiveCamera:()=>Ut,PlaneGeometry:()=>Mn,PointLight:()=>Jt,PolyhedronFallbackGeometry:()=>wt,Quaternion:()=>jt,RawShaderMaterial:()=>Ti,RectAreaLight:()=>Mi,RingGeometry:()=>Bn,Scene:()=>Mt,SceneQuotaValidator:()=>et,ShaderMaterial:()=>tn,SphereGeometry:()=>Kt,SpotLight:()=>Hn,THREE:()=>it,TetrahedronGeometry:()=>zn,Texture:()=>qt,TextureLoader:()=>En,TorusGeometry:()=>An,TorusKnotGeometry:()=>Sn,Uint16BufferAttribute:()=>vn,Uint32BufferAttribute:()=>Tn,Vector2:()=>bn,Vector3:()=>De,Vector4:()=>yn,WebGLRenderer:()=>kn,authorScriptRunner:()=>xi,buildSandboxWorkerSource:()=>pr,clearAuthorWarnings:()=>yr,default:()=>rs,exportSceneToCanvas3D:()=>mr,exportSceneToGLB:()=>fr,exportSceneToUSDZ:()=>mi,generateUSDZ:()=>nr,getAllowClientScripts:()=>pi,getAuthorWarnings:()=>vi,getSandboxEngineSrc:()=>dr,getSandboxIframeSrc:()=>di,glbToUSDZ:()=>mn,isAllowedSandboxEngineUrl:()=>yt,noopProxy:()=>Ft,sceneToCanvas3D:()=>kt,sceneToGLB:()=>Gt,sceneToUSDZ:()=>Pt,setAllowClientScripts:()=>jo,setSandboxEngineSrc:()=>Ho,setSandboxIframeSrc:()=>Wo,threeAuthorPlugin:()=>Wt,threeMicroPlugin:()=>ns,toTrustedWorkerScriptURL:()=>fi,validateSandboxWorkerMessage:()=>br,warnUnsupported:()=>$e});function rn(t,e,n){let r=[],i=new Map,o=[],s=[],l=[],a=new Map,c=g=>{let E=i.get(g);return E===void 0&&(E=r.length,r.push({op:g}),i.set(g,E)),E},u=g=>{let E=a.get(g);return E===void 0&&(E=l.length,l.push({id:g}),a.set(g,E)),E},d=(g,E={})=>o.push({declaration:c(g),...E})-1,h=(g,E,w)=>s.push({id:g,type:E,value:w})-1,m=g=>({node:g,socket:"value"}),y=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(y&&typeof y=="object"){let g=Array.isArray(y.graphs)?y.graphs[y.graph??0]:y;if(g&&Array.isArray(g.nodes)){let E=Array.isArray(g.declarations)?g.declarations:[];for(let w of E)w?.op&&c(w.op);Array.isArray(g.variables)&&s.push(...g.variables);for(let w of g.events||[])w?.id&&u(w.id);for(let w of g.nodes){if(!w||typeof w!="object")continue;let N=w.op||(typeof w.declaration=="number"?E[w.declaration]?.op:"");o.push(N?{...w,declaration:c(N)}:{...w})}}}let x=(g,E,w="translation")=>w==="baseColorFactor"||w==="metallicFactor"||w==="roughnessFactor"?`/materials/${Math.max(0,E)}/pbrMetallicRoughness/${w}`:w==="emissiveFactor"||w==="alphaCutoff"?`/materials/${Math.max(0,E)}/${w}`:w==="visible"?`/nodes/${g}/extensions/KHR_node_visibility/visible`:`/nodes/${g}/${w}`,M=new Map;t.forEach((g,E)=>{typeof g?.name=="string"&&!M.has(g.name)&&M.set(g.name,E)});let L=(g,E)=>typeof g.target=="string"&&M.has(g.target)?M.get(g.target):typeof g.targetNode=="number"?g.targetNode:E,F=g=>{let E=t[g];return(typeof E?.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0};for(let g=0;g<t.length;g++){let E=t[g],w=E?.extras?.interactivity;if(!w||typeof w!="object")continue;let N=(typeof E.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0,z=C=>{let I=Array.isArray(C)?C:[C],b=[];for(let f=0;f<I.length;f++){let p=I[f];if(!p||typeof p!="object")continue;let _=p.action||"interpolate",H=typeof p.duration=="number"?p.duration:.35;if(_==="toggleTransform"){let U=p.property==="rotation"||p.property==="scale"?p.property:"translation",Q=U==="rotation"?E.rotation||[0,0,0,1]:U==="scale"?E.scale||[1,1,1]:E.translation||[0,0,0],$=`/nodes/${g}/${U}`,K=h(`__toggle_${g}_${f}`,"bool",!1),P=d("variable/get",{configuration:{variable:K}}),ne=d("math/not",{values:{a:m(P)}}),Z=d("variable/set",{configuration:{variable:K},values:{value:m(ne)}}),q=d("pointer/interpolate",{configuration:{pointer:$},values:{value:{value:Array.isArray(p.to)?p.to:Q},duration:{value:H}}}),ae=d("pointer/interpolate",{configuration:{pointer:$},values:{value:{value:Array.isArray(p.from)?p.from:Q},duration:{value:H}}});o[Z].flows={out:{node:d("flow/branch",{values:{condition:m(P)},flows:{true:{node:q},false:{node:ae}}})}},b.push(Z)}else if(_==="interpolate"){let U=p.to??p.value;if(U===void 0)continue;let Q={value:{value:U},duration:{value:H}};p.from!==void 0&&(Q.from={value:p.from}),b.push(d("pointer/interpolate",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:x(L(p,g),F(L(p,g)),p.property)},values:Q}))}else if(_==="setProperty"){if(p.value===void 0)continue;b.push(d("pointer/set",{configuration:{pointer:typeof p.pointer=="string"?p.pointer:x(L(p,g),F(L(p,g)),p.property)},values:{value:{value:p.value}}}))}else if(_==="toggleVisibility"){let U=L(p,g),Q=h(`__vis_${U}_${f}`,"bool",!0),$=d("variable/get",{configuration:{variable:Q}}),K=d("math/not",{values:{a:m($)}}),P=d("variable/set",{configuration:{variable:Q},values:{value:m(K)}});o[P].flows={out:{node:d("pointer/set",{configuration:{pointer:`/nodes/${U}/extensions/KHR_node_visibility/visible`},values:{value:m($)}})}},b.push(P)}else if(_==="cycleMaterialColor"&&Array.isArray(p.colors)&&p.colors.length>0){let U=typeof p.duration=="number"?p.duration:.25,Q=`/materials/${Math.max(0,N)}/pbrMetallicRoughness/baseColorFactor`,$=h(`__color_idx_${g}_${f}`,"int",0),K=d("variable/get",{configuration:{variable:$}}),P=d("math/add",{values:{a:m(K),b:{value:1}}}),ne=d("math/rem",{values:{a:m(P),b:{value:p.colors.length}}}),Z=d("variable/set",{configuration:{variable:$},values:{value:m(ne)}}),q={};for(let ae=0;ae<p.colors.length;ae++){let V=p.colors[ae],J=Array.isArray(V)&&V.length>=3?[V[0],V[1],V[2],V[3]??1]:[1,1,1,1];q[String(ae)]={node:U>0?d("pointer/interpolate",{configuration:{pointer:Q},values:{value:{value:J},duration:{value:U}}}):d("pointer/set",{configuration:{pointer:Q},values:{value:{value:J}}})}}o[Z].flows={out:{node:d("flow/switch",{values:{selection:m(K)},flows:q})}},b.push(Z)}else if(_==="playAnimation")b.push(d("animation/start",{configuration:{animation:p.animation??p.clip??0}}));else if(_==="stopAnimation")b.push(d("animation/stop"));else if(_==="sendEvent"){let U={};for(let[Q,$]of Object.entries(p.values||{}))U[Q]={value:$};b.push(d("event/send",{configuration:{event:u(String(p.event??p.id??"custom"))},values:U}))}}if(!b.length)return null;if(b.length===1)return b[0];let v={};return b.forEach((f,p)=>{v[String(p)]={node:f}}),d("flow/sequence",{flows:v})},R=(C,I,b)=>{let v=z(I);v!==null&&d(C,{...b?{configuration:b}:{},flows:{out:{node:v}}})};if(w.onSelect&&R("pointer/onSelect",w.onSelect,{nodeIndex:g}),w.onHoverIn&&R("pointer/onHoverIn",w.onHoverIn,{nodeIndex:g}),w.onHoverOut&&R("pointer/onHoverOut",w.onHoverOut,{nodeIndex:g}),w.onStart&&R("event/onStart",w.onStart),w.onReceive&&typeof w.onReceive=="object")for(let[C,I]of Object.entries(w.onReceive))R("event/receive",I,{event:u(C)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:s,events:l}],graph:0}:null}var Ir='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).',Dr="Security Error: client-side scripts require allow-client-scripts opt-in.";var on="__THREE_LIVE_REGISTRY__";function _e(){let t=typeof globalThis<"u"?globalThis:{};if(!t[on]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,on,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[on]=e}}return t[on]}var Ne=_e().plugins;function Lr(t){let e=_e().plugins;e.some(n=>n.name===t.name)||e.push(t),t.onRegister?.()}function kr(){return _e().plugins}function Pr(t,e){if(!t||!t.BufferGeometry)return null;let n=t.Vector2,r=t.Vector3,i=t.Quaternion,o=t.Matrix4,s=t.Matrix3,l=t.Color,a=t.BufferAttribute,c=t.BufferGeometry,u=t.Material,d=t.MeshStandardMaterial,h=t.Mesh,m=8192,y=2048,x=128,M=4096,L=(S,T)=>{let D=S==null?NaN:Number(S);return Number.isFinite(D)?D:T};class F{constructor(T){this.currentPoint=new n(0,0),this.segments=[],Array.isArray(T)&&T.length>0&&this.fromPoints(T)}fromPoints(T){if(!T.length)return this;this.moveTo(T[0].x,T[0].y);for(let D=1;D<T.length;D++)this.lineTo(T[D].x,T[D].y);return this}moveTo(T,D){let A=Number(T)||0,k=Number(D)||0;return this.currentPoint.set(A,k),this.segments.push({type:"move",pts:[A,k]}),this}lineTo(T,D){let A=Number(T)||0,k=Number(D)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(A,k),this.segments.push({type:"line",pts:[A,k]}),this}quadraticCurveTo(T,D,A,k){let O=this.currentPoint.x,B=this.currentPoint.y,X=Number(T)||0,W=Number(D)||0,G=Number(A)||0,j=Number(k)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[O,B]}),this.currentPoint.set(G,j),this.segments.push({type:"quad",pts:[O,B,X,W,G,j]}),this}bezierCurveTo(T,D,A,k,O,B){let X=this.currentPoint.x,W=this.currentPoint.y,G=Number(T)||0,j=Number(D)||0,ee=Number(A)||0,Y=Number(k)||0,ie=Number(O)||0,oe=Number(B)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[X,W]}),this.currentPoint.set(ie,oe),this.segments.push({type:"cubic",pts:[X,W,G,j,ee,Y,ie,oe]}),this}absarc(T,D,A,k,O,B=!1){return this.absellipse(T,D,A,A,k,O,B,0)}arc(T,D,A,k,O,B=!1){return this.absarc(this.currentPoint.x+(Number(T)||0),this.currentPoint.y+(Number(D)||0),A,k,O,B)}absellipse(T,D,A,k,O,B,X=!1,W=0){let G=Number(T)||0,j=Number(D)||0,ee=Math.max(0,Number(A)||0),Y=Math.max(0,Number(k)||0),ie=Number(O)||0,oe=Number(B)||0,ue=X?1:0,le=Number(W)||0;this.segments.push({type:"arc",pts:[G,j,ee,Y,ie,oe,ue,le]});let te=Math.cos(le),he=Math.sin(le),ye=ee*Math.cos(oe),me=Y*Math.sin(oe);return this.currentPoint.set(G+ye*te-me*he,j+ye*he+me*te),this}ellipse(T,D,A,k,O,B,X=!1,W=0){return this.absellipse(this.currentPoint.x+(Number(T)||0),this.currentPoint.y+(Number(D)||0),A,k,O,B,X,W)}closePath(){if(this.segments.length>0){let T=this.segments[0],D=0,A=0;if(T.type==="arc"){let k=T.pts[0],O=T.pts[1],B=T.pts[2],X=T.pts[3],W=T.pts[4],G=T.pts[7],j=Math.cos(G),ee=Math.sin(G),Y=B*Math.cos(W),ie=X*Math.sin(W);D=k+Y*j-ie*ee,A=O+Y*ee+ie*j}else D=T.pts[0],A=T.pts[1];Math.hypot(this.currentPoint.x-D,this.currentPoint.y-A)>1e-6&&this.lineTo(D,A)}return this}getPoints(T=12){let D=Math.max(1,Math.min(128,Math.floor(Number(T)||12))),A=[],k=(O,B)=>{if(A.length>0){let X=A[A.length-1];if(Math.hypot(X.x-O,X.y-B)<1e-6)return}A.push(new n(O,B))};for(let O of this.segments){let B=O.pts;if(O.type==="move"||O.type==="line")k(B[0],B[1]);else if(O.type==="quad"){let X=B[0],W=B[1],G=B[2],j=B[3],ee=B[4],Y=B[5];k(X,W);for(let ie=1;ie<=D;ie++){let oe=ie/D,ue=1-oe;k(ue*ue*X+2*ue*oe*G+oe*oe*ee,ue*ue*W+2*ue*oe*j+oe*oe*Y)}}else if(O.type==="cubic"){let X=B[0],W=B[1],G=B[2],j=B[3],ee=B[4],Y=B[5],ie=B[6],oe=B[7];k(X,W);for(let ue=1;ue<=D;ue++){let le=ue/D,te=1-le,he=te*te,ye=le*le;k(he*te*X+3*he*le*G+3*te*ye*ee+ye*le*ie,he*te*W+3*he*le*j+3*te*ye*Y+ye*le*oe)}}else if(O.type==="arc"){let X=B[0],W=B[1],G=B[2],j=B[3],ee=B[4],Y=B[5],ie=B[6]!==0,oe=B[7],ue=Math.PI*2,le=Y-ee,te=Math.abs(le)<1e-9;for(;le<0;)le+=ue;for(;le>ue;)le-=ue;le<1e-9&&(le=te?0:ue),ie&&!te&&(le=le===ue?-ue:le-ue);let he=Math.cos(oe),ye=Math.sin(oe),me=Math.max(2,D);for(let Ee=0;Ee<=me;Ee++){let ve=Ee/me,Le=ee+ve*le,Me=G*Math.cos(Le),Re=j*Math.sin(Le);k(X+Me*he-Re*ye,W+Me*ye+Re*he)}}}if(A.length>2){let O=A[0],B=A[A.length-1];Math.hypot(O.x-B.x,O.y-B.y)<1e-6&&A.pop()}return A}getSpacedPoints(T=12){return this.getPoints(T)}}class g extends F{constructor(T){super(T),this.holes=[]}extractPoints(T=12){return{shape:this.getPoints(T),holes:this.holes.map(D=>D.getPoints(T))}}}function E(S){let T=0,D=S.length;for(let A=0,k=D-1;A<D;k=A++)T+=S[k].x*S[A].y-S[A].x*S[k].y;return T*.5}function w(S,T,D,A,k,O,B,X){let W=B-D,G=X-A,j=k-D,ee=O-A,Y=S-D,ie=T-A,oe=W*W+G*G,ue=W*j+G*ee,le=W*Y+G*ie,te=j*j+ee*ee,he=j*Y+ee*ie,ye=oe*te-ue*ue;if(Math.abs(ye)<1e-12)return!1;let me=1/ye,Ee=(te*le-ue*he)*me,ve=(oe*he-ue*le)*me;return Ee>=-1e-7&&ve>=-1e-7&&Ee+ve<=1+1e-7}function N(S,T){let D=S.slice();E(D)<0&&D.reverse();let A=D.map(W=>new n(W.x,W.y)),k=D.map((W,G)=>G),O=[];for(let W of T){if(!W||W.length<3)continue;let G=W.slice();E(G)>0&&G.reverse();let j=[],ee=-1/0,Y=0;for(let ie=0;ie<G.length;ie++){let oe=G[ie],ue=A.length;A.push(new n(oe.x,oe.y)),j.push(ue),oe.x>ee&&(ee=oe.x,Y=ie)}O.push({pts:G,indices:j,maxX:ee,maxIdx:Y})}O.sort((W,G)=>G.maxX-W.maxX);let B=(W,G,j)=>(G.x-W.x)*(j.y-W.y)-(G.y-W.y)*(j.x-W.x),X=(W,G,j)=>{for(let ee=0;ee<j.length;ee++){let Y=j[ee],ie=j[(ee+1)%j.length];if(B(W,G,Y)*B(W,G,ie)<0&&B(Y,ie,W)*B(Y,ie,G)<0)return!0}return!1};for(let W of O){let G=W.pts[W.maxIdx],j=G.x,ee=k.length,Y=k.map(te=>A[te]),ie=te=>Math.hypot(Y[te].x-j,Y[te].y-G.y),oe=Y.map((te,he)=>he).sort((te,he)=>+(Y[te].x<j)-+(Y[he].x<j)||ie(te)-ie(he)),ue=oe[0];for(let te of oe){let he=Y[te],ye=Y[(te+ee-1)%ee],me=Y[(te+1)%ee],Ee=B(he,me,G)>=0,ve=B(ye,he,G)>=0;if((B(ye,he,me)>=0?Ee&&ve:Ee||ve)&&!X(G,he,Y)&&!O.some(Me=>X(G,he,Me.pts))){ue=te;break}}let le=[];for(let te=0;te<=ue;te++)le.push(k[te]);for(let te=0;te<=W.indices.length;te++){let he=W.indices[(W.maxIdx+te)%W.indices.length];le.push(he)}for(let te=ue;te<k.length;te++)le.push(k[te]);k=le}return{merged:k.map(W=>A[W]),mergedIndices:k,allVertices:A}}function z(S,T){let D=[],A=S.slice();if(A.length<3)return D;let k=A.length*A.length+64,O=0;for(;A.length>2&&k-- >0;){let B=A.length,X=A[(O+B-1)%B],W=A[O%B],G=A[(O+1)%B],j=T[X],ee=T[W],Y=T[G];if((ee.x-j.x)*(Y.y-j.y)-(ee.y-j.y)*(Y.x-j.x)>1e-9){let oe=!0;for(let ue=0;ue<B;ue++){let le=A[ue];if(le===X||le===W||le===G)continue;let te=T[le];if(w(te.x,te.y,j.x,j.y,ee.x,ee.y,Y.x,Y.y)&&Math.hypot(te.x-j.x,te.y-j.y)>=1e-6&&Math.hypot(te.x-ee.x,te.y-ee.y)>=1e-6&&Math.hypot(te.x-Y.x,te.y-Y.y)>=1e-6){oe=!1;break}}if(oe){D.push([X,W,G]),A.splice(O%B,1),O=Math.max(0,O%B-1);continue}}O++,O>=B*2&&(D.push([X,W,G]),A.splice((O-1)%B,1),O=0)}return D}function R(S,T){let D=S instanceof g?S.extractPoints(T):{shape:S.getPoints(T),holes:[]},A=D.shape.length;for(let k of D.holes)A+=k.length;if(A>M)throw new RangeError(`SecurityError: shape point count (${A}) exceeds MAX_SHAPE_POINTS (${M})`);return D}class C extends c{constructor(T=new g,D=12){super();let A=Array.isArray(T)?T:[T],k=[],O=[],B=[],X=[];for(let W of A){if(!(W instanceof F))continue;let G=R(W,D);if(G.shape.length<3)continue;let{mergedIndices:j,allVertices:ee}=N(G.shape,G.holes),Y=z(j,ee),ie=k.length/3,oe=1/0,ue=1/0,le=-1/0,te=-1/0;for(let me of ee)me.x<oe&&(oe=me.x),me.y<ue&&(ue=me.y),me.x>le&&(le=me.x),me.y>te&&(te=me.y);let he=Math.max(1e-6,le-oe),ye=Math.max(1e-6,te-ue);for(let me of ee)k.push(me.x,me.y,0),O.push(0,0,1),B.push((me.x-oe)/he,(me.y-ue)/ye);for(let[me,Ee,ve]of Y)X.push(ie+me,ie+Ee,ie+ve)}this.setAttribute("position",new a(new Float32Array(k),3)),this.setAttribute("normal",new a(new Float32Array(O),3)),this.setAttribute("uv",new a(new Float32Array(B),2)),this.setIndex(X)}}function I(S){let T=S.length,D=[];for(let A=0;A<T;A++){let k=S[(A+T-1)%T],O=S[A],B=S[(A+1)%T],X=O.x-k.x,W=O.y-k.y,G=Math.hypot(X,W)||1;X/=G,W/=G;let j=B.x-O.x,ee=B.y-O.y,Y=Math.hypot(j,ee)||1;j/=Y,ee/=Y;let ie=W,oe=-X,ue=ee,le=-j,te=ie+ue,he=oe+le,ye=Math.hypot(te,he);if(ye>1e-6){te/=ye,he/=ye;let me=Math.max(.35,te*ie+he*oe);D.push(new n(te/me,he/me))}else D.push(new n(ie,oe))}return D}class b extends c{constructor(T=new g,D={}){super();let A=Array.isArray(T)?T:[T],k=Math.max(1,Math.min(64,Math.floor(L(D.curveSegments,12)))),O=L(D.depth??D.amount,1),B=Math.max(1,Math.min(32,Math.floor(L(D.steps,1)))),X=!!(D.bevelEnabled??!1),W=X?Math.max(0,L(D.bevelThickness,.06)):0,G=X?Math.max(0,L(D.bevelSize,W*.8)):0,j=X?L(D.bevelOffset,0):0,ee=X?Math.max(1,Math.min(8,Math.floor(L(D.bevelSegments,2)))):0,Y=[],ie=[],oe=[],ue=[];for(let le of A){if(!(le instanceof F))continue;let te=R(le,k);if(te.shape.length<3)continue;let he=te.shape.slice();E(he)<0&&he.reverse();let ye=[];for(let de of te.holes){if(de.length<3)continue;let Te=de.slice();E(Te)>0&&Te.reverse(),ye.push(Te)}let{mergedIndices:me,allVertices:Ee}=N(he,ye),ve=z(me,Ee),Le=[he,...ye],Me=[];for(let de of Le){let Te=I(de);for(let we of Te)Me.push(we)}let Re=1/0,Ue=1/0,Fe=-1/0,je=-1/0;for(let de of Ee)de.x<Re&&(Re=de.x),de.y<Ue&&(Ue=de.y),de.x>Fe&&(Fe=de.x),de.y>je&&(je=de.y);let ze=Math.max(1e-6,Fe-Re),Ze=Math.max(1e-6,je-Ue),At=-W,St=O+W,ot=Y.length/3;for(let de=0;de<Ee.length;de++){let Te=Ee[de],we=Me[de]??new n(0,0),ke=Te.x+we.x*j,Pe=Te.y+we.y*j;Y.push(ke,Pe,At),ie.push(0,0,-1),oe.push((ke-Re)/ze,(Pe-Ue)/Ze)}for(let[de,Te,we]of ve)ue.push(ot+de,ot+we,ot+Te);let st=Y.length/3;for(let de=0;de<Ee.length;de++){let Te=Ee[de],we=Me[de]??new n(0,0),ke=Te.x+we.x*j,Pe=Te.y+we.y*j;Y.push(ke,Pe,St),ie.push(0,0,1),oe.push((ke-Re)/ze,(Pe-Ue)/Ze)}for(let[de,Te,we]of ve)ue.push(st+de,st+Te,st+we);let Be=[];if(X&&ee>0)for(let de=0;de<ee;de++){let we=de/ee*Math.PI/2;Be.push({z:-W*Math.cos(we),expand:j+G*Math.sin(we)})}for(let de=0;de<=B;de++){let Te=de/B;Be.push({z:Te*O,expand:j+G})}if(X&&ee>0)for(let de=1;de<=ee;de++){let we=de/ee*Math.PI/2;Be.push({z:O+W*Math.sin(we),expand:j+G*Math.cos(we)})}let Qe=0;for(let de of Le){let Te=de.length;for(let we=0;we<Be.length-1;we++){let ke=Be[we],Pe=Be[we+1];for(let Ge=0;Ge<Te;Ge++){let tt=(Ge+1)%Te,at=de[Ge],ct=de[tt],ut=Me[Qe+Ge],lt=Me[Qe+tt],ht=at.x+ut.x*ke.expand,mt=at.y+ut.y*ke.expand,gt=ct.x+lt.x*ke.expand,nt=ct.y+lt.y*ke.expand,Ai=ct.x+lt.x*Pe.expand,Si=ct.y+lt.y*Pe.expand,gr=at.x+ut.x*Pe.expand,xr=at.y+ut.y*Pe.expand,vr=gt-ht,Tr=nt-mt,Mr=0,wr=gr-ht,Ar=xr-mt,Sr=Pe.z-ke.z,Et=Tr*Sr-Mr*Ar,Rt=Mr*wr-vr*Sr,_t=vr*Ar-Tr*wr,Xn=Math.hypot(Et,Rt,_t)||1;Et/=Xn,Rt/=Xn,_t/=Xn;let Ct=Y.length/3;Y.push(ht,mt,ke.z,gt,nt,ke.z,Ai,Si,Pe.z,gr,xr,Pe.z),ie.push(Et,Rt,_t,Et,Rt,_t,Et,Rt,_t,Et,Rt,_t);let Er=Ge/Te,Rr=(Ge+1)/Te,_r=we/(Be.length-1),Cr=(we+1)/(Be.length-1);oe.push(Er,_r,Rr,_r,Rr,Cr,Er,Cr),ue.push(Ct,Ct+1,Ct+2,Ct,Ct+2,Ct+3)}}Qe+=Te}}this.setAttribute("position",new a(new Float32Array(Y),3)),this.setAttribute("normal",new a(new Float32Array(ie),3)),this.setAttribute("uv",new a(new Float32Array(oe),2)),this.setIndex(ue)}}function v(S){return{x:S.x,y:S.y,z:S.z,nx:S.nx,ny:S.ny,nz:S.nz,u:S.u,v:S.v}}function f(S){return{x:S.x,y:S.y,z:S.z,nx:-S.nx,ny:-S.ny,nz:-S.nz,u:S.u,v:S.v}}function p(S,T,D){let A=S.nx+(T.nx-S.nx)*D,k=S.ny+(T.ny-S.ny)*D,O=S.nz+(T.nz-S.nz)*D,B=Math.hypot(A,k,O)||1;return{x:S.x+(T.x-S.x)*D,y:S.y+(T.y-S.y)*D,z:S.z+(T.z-S.z)*D,nx:A/B,ny:k/B,nz:O/B,u:S.u+(T.u-S.u)*D,v:S.v+(T.v-S.v)*D}}function _(S){if(S.length<3)return null;let T=S[0],D=S[1],A=S[2],k=D.x-T.x,O=D.y-T.y,B=D.z-T.z,X=A.x-T.x,W=A.y-T.y,G=A.z-T.z,j=O*G-B*W,ee=B*X-k*G,Y=k*W-O*X,ie=Math.hypot(j,ee,Y);if(ie<1e-9)return null;j/=ie,ee/=ie,Y/=ie;let oe=j*T.x+ee*T.y+Y*T.z;return{vertices:S,nx:j,ny:ee,nz:Y,w:oe}}function H(S){S.vertices.reverse();for(let T=0;T<S.vertices.length;T++)S.vertices[T]=f(S.vertices[T]);S.nx=-S.nx,S.ny=-S.ny,S.nz=-S.nz,S.w=-S.w}let U=1e-5,Q=0,$=1,K=2,P=3;function ne(S,T,D,A,k,O,B,X,W){let G=0,j=[];for(let ee=0;ee<k.vertices.length;ee++){let Y=k.vertices[ee],ie=S*Y.x+T*Y.y+D*Y.z-A,oe=ie<-U?K:ie>U?$:Q;G|=oe,j.push(oe)}switch(G){case Q:{S*k.nx+T*k.ny+D*k.nz>0?O.push(k):B.push(k);break}case $:X.push(k);break;case K:W.push(k);break;case P:{let ee=[],Y=[],ie=k.vertices.length;for(let he=0;he<ie;he++){let ye=(he+1)%ie,me=j[he],Ee=j[ye],ve=k.vertices[he],Le=k.vertices[ye];if(me!==K&&ee.push(ve),me!==$&&Y.push(me!==K?v(ve):ve),(me|Ee)===P){let Me=Le.x-ve.x,Re=Le.y-ve.y,Ue=Le.z-ve.z,Fe=S*Me+T*Re+D*Ue,je=Math.abs(Fe)>1e-12?(A-(S*ve.x+T*ve.y+D*ve.z))/Fe:.5,ze=p(ve,Le,Math.max(0,Math.min(1,je)));ee.push(ze),Y.push(v(ze))}}let{nx:oe,ny:ue,nz:le,w:te}=k;ee.length>=3&&X.push({vertices:ee,nx:oe,ny:ue,nz:le,w:te}),Y.length>=3&&W.push({vertices:Y,nx:oe,ny:ue,nz:le,w:te});break}default:break}}class Z{constructor(T,D=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,T&&T.length>0&&this.build(T,D)}invert(){for(let D=0;D<this.polygons.length;D++)H(this.polygons[D]);this.nx=-this.nx,this.ny=-this.ny,this.nz=-this.nz,this.w=-this.w,this.front&&this.front.invert(),this.back&&this.back.invert();let T=this.front;this.front=this.back,this.back=T}clipPolygons(T,D=0){if(!this.hasPlane||T.length===0)return T.slice();if(D>=y)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${y})`);let A=[],k=[];for(let O=0;O<T.length;O++)ne(this.nx,this.ny,this.nz,this.w,T[O],A,k,A,k);return this.front&&A.length>0&&(A=this.front.clipPolygons(A,D+1)),this.back?k=k.length>0?this.back.clipPolygons(k,D+1):[]:k=[],A.concat(k)}clipTo(T,D=0){this.polygons.length>0&&(this.polygons=T.clipPolygons(this.polygons,0)),D<y&&(this.front&&this.front.clipTo(T,D+1),this.back&&this.back.clipTo(T,D+1))}allPolygons(T=[]){for(let D=0;D<this.polygons.length;D++)T.push(this.polygons[D]);return this.front&&this.front.allPolygons(T),this.back&&this.back.allPolygons(T),T}build(T,D=0){if(!T.length)return;if(!this.hasPlane){let O=T[0];this.nx=O.nx,this.ny=O.ny,this.nz=O.nz,this.w=O.w,this.hasPlane=!0}if(D>=y)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${y})`);let A=[],k=[];for(let O=0;O<T.length;O++)ne(this.nx,this.ny,this.nz,this.w,T[O],this.polygons,this.polygons,A,k);A.length>0&&(this.front||(this.front=new Z),this.front.build(A,D+1)),k.length>0&&(this.back||(this.back=new Z),this.back.build(k,D+1))}}function q(S,T){let D=S.attributes.position;if(!D||D.count===0)return[];let A=S.attributes.normal,k=S.attributes.uv,O=S.index?S.index.array:null,B=Math.floor(O?O.length/3:D.count/3);if(B>m)throw new RangeError(`SecurityError: CSG input triangle count (${B}) exceeds MAX_CSG_TRIANGLES (${m})`);let X=T?T.elements:null,W=X?X[0]*(X[5]*X[10]-X[9]*X[6])-X[4]*(X[1]*X[10]-X[9]*X[2])+X[8]*(X[1]*X[6]-X[5]*X[2])<0:!1,G=X?new s().getNormalMatrix(T).elements:null,j=Y=>{let ie=D.getX(Y),oe=D.getY(Y),ue=D.getZ(Y),le=A?A.getX(Y):NaN,te=A?A.getY(Y):NaN,he=A?A.getZ(Y):NaN;if(X&&G){let Ee=X[0]*ie+X[4]*oe+X[8]*ue+X[12],ve=X[1]*ie+X[5]*oe+X[9]*ue+X[13],Le=X[2]*ie+X[6]*oe+X[10]*ue+X[14];ie=Ee,oe=ve,ue=Le;let Me=G[0]*le+G[3]*te+G[6]*he,Re=G[1]*le+G[4]*te+G[7]*he,Ue=G[2]*le+G[5]*te+G[8]*he,Fe=Math.hypot(Me,Re,Ue)||1;le=Me/Fe,te=Re/Fe,he=Ue/Fe}let ye=k?k.getX(Y):0,me=k?k.getY(Y):0;return{x:ie,y:oe,z:ue,nx:le,ny:te,nz:he,u:ye,v:me}},ee=[];for(let Y=0;Y<B;Y++){let ie=O?O[Y*3]:Y*3,oe=O?O[Y*3+1]:Y*3+1,ue=O?O[Y*3+2]:Y*3+2,le=_(W?[j(ie),j(ue),j(oe)]:[j(ie),j(oe),j(ue)]);le&&ee.push(le)}return ee}function ae(S){let T=[],D=[],A=[],k=[];for(let B of S){let X=B.vertices;if(X.length<3)continue;let W=T.length/3;for(let G of X)T.push(G.x,G.y,G.z),Number.isFinite(G.nx)&&G.nx*G.nx+G.ny*G.ny+G.nz*G.nz>.5?D.push(G.nx,G.ny,G.nz):D.push(B.nx,B.ny,B.nz),A.push(G.u,G.v);for(let G=1;G<X.length-1;G++)k.push(W,W+G,W+G+1)}let O=new c;return O.setAttribute("position",new a(new Float32Array(T),3)),O.setAttribute("normal",new a(new Float32Array(D),3)),O.setAttribute("uv",new a(new Float32Array(A),2)),O.setIndex(k),O}function V(S,T,D){if(S.length+T.length>m)throw new RangeError(`SecurityError: Combined CSG triangle count (${S.length+T.length}) exceeds MAX_CSG_TRIANGLES (${m})`);if(S.length===0)return D==="union"?T:[];if(T.length===0)return D==="intersect"?[]:S;let A=new Z(S),k=new Z(T);return D==="union"?(A.clipTo(k),k.clipTo(A),k.invert(),k.clipTo(A),k.invert(),A.build(k.allPolygons()),A.allPolygons()):D==="subtract"?(A.invert(),A.clipTo(k),k.clipTo(A),k.invert(),k.clipTo(A),k.invert(),A.build(k.allPolygons()),A.invert(),A.allPolygons()):(A.invert(),k.clipTo(A),k.invert(),A.clipTo(k),k.clipTo(A),A.build(k.allPolygons()),A.invert(),A.allPolygons())}function J(S,T,D,A=null,k=null){let O=q(S,A),B=q(T,k);return ae(V(O,B,D))}function ce(S,T,D){let A=S instanceof h||!!S?.isMesh,k=T instanceof h||!!T?.isMesh,O=A?S.geometry:S,B=k?T.geometry:T,X=null;if(k)if(T.updateMatrix(),A){S.updateMatrix();let ee=new o().makeScale(1/(S.scale.x||1),1/(S.scale.y||1),1/(S.scale.z||1)),Y=Math.hypot(S.quaternion.x,S.quaternion.y,S.quaternion.z,S.quaternion.w)||1,ie=new o().compose(new r(0,0,0),new i(-S.quaternion.x/Y,-S.quaternion.y/Y,-S.quaternion.z/Y,S.quaternion.w/Y),new r(1,1,1)),oe=new o().makeTranslation(-S.position.x,-S.position.y,-S.position.z);X=ee.multiply(ie).multiply(oe).multiply(T.matrix)}else X=T.matrix;let W=J(O,B,D,null,X),G=A?S.material:new d,j=new h(W,G);return A&&(j.position.copy(S.position),j.quaternion.copy(S.quaternion),j.scale.copy(S.scale),j.name=S.name),j}let se={toGeometry:J,subtract(S,T){return ce(S,T,"subtract")},union(S,T){return ce(S,T,"union")},intersect(S,T){return ce(S,T,"intersect")}},fe={0:[[[.15,0],[.85,0],[.85,1],[.15,1],[.15,0]]],1:[[[.3,.8],[.5,1],[.5,0]],[[.2,0],[.8,0]]],2:[[[.15,.8],[.3,1],[.7,1],[.85,.8],[.85,.55],[.15,0],[.85,0]]],3:[[[.15,.85],[.3,1],[.75,1],[.85,.75],[.5,.5],[.85,.25],[.75,0],[.3,0],[.15,.15]]],4:[[[.7,0],[.7,1],[.15,.35],[.9,.35]]],5:[[[.85,1],[.2,1],[.15,.55],[.75,.55],[.85,.3],[.75,0],[.2,0]]],6:[[[.8,.9],[.5,1],[.15,.7],[.15,.15],[.5,0],[.85,.2],[.85,.45],[.5,.55],[.15,.45]]],7:[[[.15,1],[.85,1],[.35,0]]],8:[[[.2,.5],[.15,.75],[.3,1],[.7,1],[.85,.75],[.8,.5],[.2,.5],[.15,.2],[.3,0],[.7,0],[.85,.2],[.8,.5]]],9:[[[.85,.55],[.5,.45],[.15,.55],[.15,.85],[.5,1],[.85,.85],[.85,.2],[.5,0],[.2,.1]]],A:[[[.1,0],[.5,1],[.9,0]],[[.25,.35],[.75,.35]]],B:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.7,.5],[.85,.25],[.7,0],[.15,0]]],C:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.65,0],[.85,.2]]],D:[[[.15,0],[.15,1],[.65,1],[.85,.75],[.85,.25],[.65,0],[.15,0]]],E:[[[.85,1],[.15,1],[.15,0],[.85,0]],[[.15,.5],[.7,.5]]],F:[[[.85,1],[.15,1],[.15,0]],[[.15,.5],[.7,.5]]],G:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.85,0],[.85,.45],[.55,.45]]],H:[[[.15,0],[.15,1]],[[.85,0],[.85,1]],[[.15,.5],[.85,.5]]],I:[[[.25,1],[.75,1]],[[.5,1],[.5,0]],[[.25,0],[.75,0]]],J:[[[.8,1],[.8,.25],[.6,0],[.3,0],[.15,.25]]],K:[[[.15,0],[.15,1]],[[.85,1],[.15,.45],[.85,0]]],L:[[[.15,1],[.15,0],[.85,0]]],M:[[[.1,0],[.1,1],[.5,.35],[.9,1],[.9,0]]],N:[[[.15,0],[.15,1],[.85,0],[.85,1]]],O:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]]],P:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]]],Q:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]],[[.55,.3],[.9,-.05]]],R:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.55,.5],[.85,0]]],S:[[[.85,.85],[.65,1],[.3,1],[.15,.75],[.85,.25],[.7,0],[.3,0],[.15,.15]]],T:[[[.1,1],[.9,1]],[[.5,1],[.5,0]]],U:[[[.15,1],[.15,.25],[.35,0],[.65,0],[.85,.25],[.85,1]]],V:[[[.1,1],[.5,0],[.9,1]]],W:[[[.05,1],[.25,0],[.5,.65],[.75,0],[.95,1]]],X:[[[.15,1],[.85,0]],[[.85,1],[.15,0]]],Y:[[[.15,1],[.5,.5],[.85,1]],[[.5,.5],[.5,0]]],Z:[[[.15,1],[.85,1],[.15,0],[.85,0]]],".":[[[.45,0],[.55,0],[.55,.12],[.45,.12],[.45,0]]],",":[[[.5,.15],[.4,-.1]]],":":[[[.45,.1],[.55,.1]],[[.45,.7],[.55,.7]]],"-":[[[.2,.5],[.8,.5]]],"+":[[[.2,.5],[.8,.5]],[[.5,.2],[.5,.8]]],"=":[[[.2,.35],[.8,.35]],[[.2,.65],[.8,.65]]],"/":[[[.2,0],[.8,1]]],"!":[[[.5,1],[.5,.28]],[[.5,.1],[.5,0]]],"?":[[[.2,.8],[.35,1],[.7,1],[.85,.75],[.5,.45],[.5,.28]],[[.5,.1],[.5,0]]],"(":[[[.65,1],[.35,.65],[.35,.35],[.65,0]]],")":[[[.35,1],[.65,.65],[.65,.35],[.35,0]]],"%":[[[.2,0],[.8,1]],[[.2,.8],[.35,.8],[.35,.95],[.2,.95],[.2,.8]],[[.65,.05],[.8,.05],[.8,.2],[.65,.2],[.65,.05]]],"#":[[[.32,0],[.32,1]],[[.68,0],[.68,1]],[[.12,.35],[.88,.35]],[[.12,.65],[.88,.65]]],$:[[[.8,.8],[.6,.92],[.3,.92],[.18,.72],[.82,.28],[.7,.08],[.4,.08],[.2,.2]],[[.5,1],[.5,0]]],_:[[[.1,0],[.9,0]]],"[":[[[.65,1],[.3,1],[.3,0],[.65,0]]],"]":[[[.35,1],[.7,1],[.7,0],[.35,0]]],"<":[[[.75,.85],[.25,.5],[.75,.15]]],">":[[[.25,.85],[.75,.5],[.25,.15]]],"*":[[[.5,.2],[.5,.8]],[[.2,.35],[.8,.65]],[[.2,.65],[.8,.35]]],"\\":[[[.2,1],[.8,0]]]};class xe extends c{constructor(T="",D={}){super();let A=String(T??"").slice(0,x),k=Math.max(.005,Math.min(100,L(D.size,.2))),O=!!(D.bevelEnabled??!1),B=O?Math.max(0,Math.min(2,L(D.bevelThickness,k*.04))):0,X=O?Math.max(0,Math.min(2,L(D.bevelSize,k*.03))):0,W=Math.max(.001,Math.min(20,L(D.depth??D.height,k*.2)))+B*2,G=k*.085+X,j=k*.68,ee=k*.82,Y=[],ie=[],oe=[],ue=[],le=(ye,me,Ee,ve,Le,Me,Re)=>{let Ue=Ee-ye,Fe=ve-me,je=Math.hypot(Ue,Fe),ze=1,Ze=0;je>1e-6&&(ze=Ue/je,Ze=Fe/je);let At=-Ze*Le,St=ze*Le,ot=ze*Le*.6,st=Ze*Le*.6,Be=ye-ot+At,Qe=me-st+St,de=ye-ot-At,Te=me-st-St,we=Ee+ot-At,ke=ve+st-St,Pe=Ee+ot+At,Ge=ve+st+St,tt=(at,ct,ut,lt,ht,mt,gt)=>{let nt=Y.length/3;Y.push(at[0],at[1],at[2],ct[0],ct[1],ct[2],ut[0],ut[1],ut[2],lt[0],lt[1],lt[2]),ie.push(ht,mt,gt,ht,mt,gt,ht,mt,gt,ht,mt,gt),oe.push(0,0,1,0,1,1,0,1),ue.push(nt,nt+1,nt+2,nt,nt+2,nt+3)};tt([Be,Qe,Re],[de,Te,Re],[we,ke,Re],[Pe,Ge,Re],0,0,1),tt([de,Te,Me],[Be,Qe,Me],[Pe,Ge,Me],[we,ke,Me],0,0,-1),tt([Be,Qe,Me],[de,Te,Me],[de,Te,Re],[Be,Qe,Re],-ze,-Ze,0),tt([we,ke,Me],[Pe,Ge,Me],[Pe,Ge,Re],[we,ke,Re],ze,Ze,0),tt([de,Te,Me],[we,ke,Me],[we,ke,Re],[de,Te,Re],Ze,-ze,0),tt([Pe,Ge,Me],[Be,Qe,Me],[Be,Qe,Re],[Pe,Ge,Re],-Ze,ze,0)},te=0,he=0;for(let ye=0;ye<A.length;ye++){let me=A[ye];if(me===`
|
|
18
|
+
`){te=0,he-=k*1.35;continue}if(me===" "||me===" "){te+=ee*(me===" "?.75:3);continue}if(me==="\r")continue;let Ee=me.toUpperCase(),ve=me!==Ee&&me>="a"&&me<="z",Le=fe[Ee]??fe["?"],Me=ve?k*.76:k,Re=ve?j*.88:j;for(let Ue of Le)for(let Fe=0;Fe<Ue.length-1;Fe++){let je=Ue[Fe],ze=Ue[Fe+1];le(te+je[0]*Re,he+je[1]*Me,te+ze[0]*Re,he+ze[1]*Me,G,-W*.5,W*.5)}te+=ve?ee*.88:ee}this.setAttribute("position",new a(new Float32Array(Y),3)),this.setAttribute("normal",new a(new Float32Array(ie),3)),this.setAttribute("uv",new a(new Float32Array(oe),2)),this.setIndex(ue),D.center!==!1?this.center():this.computeBoundingBox()}}function Se(S){if(!S)return;let T=S,D=S.userData?.xr?.text;if(D!=null&&D!==!1){let k=T.geometry?.attributes?.position;if((!k||k.count===0)&&S.userData._textApplied!==!0){let O="",B=.08,X=.015,W;if(typeof D=="string"||typeof D=="number")O=String(D);else if(typeof D=="object"){let G=D;O=String(G.text??G.value??""),G.size!==void 0&&(B=Number(G.size)||.08),(G.depth!==void 0||G.height!==void 0)&&(X=Number(G.depth??G.height)||B*.2),(typeof G.color=="string"||typeof G.color=="number")&&(W=G.color)}O.trim().length>0&&(T.geometry=new xe(O,{size:B,depth:X}),S.userData._textApplied=!0,T.material instanceof u?W!==void 0&&S.userData._autoTextColorApplied!==!0&&(T.material.color=new l(W),S.userData._autoTextColorApplied=!0):T.material=new d({color:W??16317180}))}}let A=S.userData?.csg;if(A&&typeof A=="object"&&S.userData._csgApplied!==!0&&T.geometry instanceof c&&T.geometry.attributes.position?.count>0){S.userData._csgApplied=!0;let k=Array.isArray(A)?A:[A],O=T.geometry;for(let B of k){if(!B||typeof B!="object")continue;let X=B,W=String(X.op??X.operation??"subtract"),G=W==="union"||W==="intersect"?W:"subtract",j=X.target??X.mesh??X.geometry;if(j instanceof h||j instanceof c)try{let ee=G==="union"?se.union(T,j):G==="intersect"?se.intersect(T,j):se.subtract(T,j);T.geometry!==O&&T.geometry.dispose?.(),T.geometry=ee.geometry}catch(ee){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",ee)}}}}let pe={Path:F,Shape:g,ShapeGeometry:C,ExtrudeGeometry:b,TextGeometry:xe,CSG:se,MAX_CSG_TRIANGLES:m,MAX_BSP_DEPTH:y,MAX_TEXT_GEOMETRY_CHARS:x,MAX_SHAPE_POINTS:M,materializeDeclarativeGeometry:Se};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,pe),e.materializeDeclarativeGeometry=Se),pe}function Ce(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function sn(t,e,n,r,i){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let s=1/(r-i);return t[10]=(i+r)*s,t[14]=2*i*r*s,t}function It(t,e,n,r){let[i,o,s]=e,[l,a,c]=r,[u,d,h]=n,m=i-u,y=o-d,x=s-h,M=Math.hypot(m,y,x);M<=1e-5?(m=0,y=0,x=1):(m/=M,y/=M,x/=M);let L=a*x-c*y,F=c*m-l*x,g=l*y-a*m;M=Math.hypot(L,F,g),M<=1e-5?(L=0,F=0,g=0):(L/=M,F/=M,g/=M);let E=y*g-x*F,w=x*L-m*g,N=m*F-y*L;return M=Math.hypot(E,w,N),M<=1e-5?(E=0,w=0,N=0):(E/=M,w/=M,N/=M),t[0]=L,t[1]=E,t[2]=m,t[3]=0,t[4]=F,t[5]=w,t[6]=y,t[7]=0,t[8]=g,t[9]=N,t[10]=x,t[11]=0,t[12]=-(L*i+F*o+g*s),t[13]=-(E*i+w*o+N*s),t[14]=-(m*i+y*o+x*s),t[15]=1,t}function Ie(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],l=e[4],a=e[5],c=e[6],u=e[7],d=e[8],h=e[9],m=e[10],y=e[11],x=e[12],M=e[13],L=e[14],F=e[15],g=n[0],E=n[1],w=n[2],N=n[3];return t[0]=g*r+E*l+w*d+N*x,t[1]=g*i+E*a+w*h+N*M,t[2]=g*o+E*c+w*m+N*L,t[3]=g*s+E*u+w*y+N*F,g=n[4],E=n[5],w=n[6],N=n[7],t[4]=g*r+E*l+w*d+N*x,t[5]=g*i+E*a+w*h+N*M,t[6]=g*o+E*c+w*m+N*L,t[7]=g*s+E*u+w*y+N*F,g=n[8],E=n[9],w=n[10],N=n[11],t[8]=g*r+E*l+w*d+N*x,t[9]=g*i+E*a+w*h+N*M,t[10]=g*o+E*c+w*m+N*L,t[11]=g*s+E*u+w*y+N*F,g=n[12],E=n[13],w=n[14],N=n[15],t[12]=g*r+E*l+w*d+N*x,t[13]=g*i+E*a+w*h+N*M,t[14]=g*o+E*c+w*m+N*L,t[15]=g*s+E*u+w*y+N*F,t}function xt(t,e,n,r){let i=e[0],o=e[1],s=e[2],l=e[3],a=i+i,c=o+o,u=s+s,d=i*a,h=i*c,m=i*u,y=o*c,x=o*u,M=s*u,L=l*a,F=l*c,g=l*u,E=r[0],w=r[1],N=r[2];return t[0]=(1-(y+M))*E,t[1]=(h+g)*E,t[2]=(m-F)*E,t[3]=0,t[4]=(h-g)*w,t[5]=(1-(d+M))*w,t[6]=(x+L)*w,t[7]=0,t[8]=(m+F)*N,t[9]=(x-L)*N,t[10]=(1-(d+y))*N,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function He(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],s=e[5],l=e[6],a=e[8],c=e[9],u=e[10],d=u*s-l*c,h=-u*o+l*a,m=c*o-s*a,y=n*d+r*h+i*m;return y&&(y=1/y,t[0]=d*y,t[1]=h*y,t[2]=m*y,t[3]=(-u*r+i*c)*y,t[4]=(u*n-i*a)*y,t[5]=(-c*n+r*a)*y,t[6]=(l*r-i*s)*y,t[7]=(-l*n+i*o)*y,t[8]=(s*n-r*o)*y),t}function Nr(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],l=e[5],a=e[6],c=e[7],u=e[8],d=e[9],h=e[10],m=e[11],y=e[12],x=e[13],M=e[14],L=e[15],F=n*l-r*s,g=n*a-i*s,E=n*c-o*s,w=r*a-i*l,N=r*c-o*l,z=i*c-o*a,R=u*x-d*y,C=u*M-h*y,I=u*L-m*y,b=d*M-h*x,v=d*L-m*x,f=h*L-m*M,p=F*f-g*v+E*b+w*I-N*C+z*R;return p?(p=1/p,t[0]=(l*f-a*v+c*b)*p,t[1]=(i*v-r*f-o*b)*p,t[2]=(x*z-M*N+L*w)*p,t[3]=(h*N-d*z-m*w)*p,t[4]=(a*I-s*f-c*C)*p,t[5]=(n*f-i*I+o*C)*p,t[6]=(M*E-y*z-L*g)*p,t[7]=(u*z-h*E+m*g)*p,t[8]=(s*v-l*I+c*R)*p,t[9]=(r*I-n*v-o*R)*p,t[10]=(y*N-x*E+L*F)*p,t[11]=(d*E-u*N-m*F)*p,t[12]=(l*C-s*b-a*R)*p,t[13]=(n*b-r*C+i*R)*p,t[14]=(x*g-y*w-M*F)*p,t[15]=(u*w-d*g+h*F)*p,t):null}function $n(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],s=i[1]*e+i[5]*n+i[9]*r+i[13],l=i[2]*e+i[6]*n+i[10]*r+i[14],a=i[3]*e+i[7]*n+i[11]*r+i[15],c=a!==0?1/a:1;t[0]=o*c,t[1]=s*c,t[2]=l*c}function Fr(t,e,n,r,i,o,s,l,a,c,u,d,h,m,y,x,M=0){let L=c-s,F=u-l,g=d-a,E=h-s,w=m-l,N=y-a,z=i*N-o*w,R=o*E-r*N,C=r*w-i*E,I=L*z+F*R+g*C;if(I>-1e-7&&I<1e-7)return!1;let b=1/I,v=t-s,f=e-l,p=n-a,_=b*(v*z+f*R+p*C);if(_<-M||_>1+M)return!1;let H=f*g-p*F,U=p*L-v*g,Q=v*F-f*L,$=b*(r*H+i*U+o*Q);if($<-M||_+$>1+M)return!1;let K=b*(E*H+w*U+N*Q);if(K>1e-4&&K<x.distance){x.distance=K,x.point=[t+r*K,e+i*K,n+o*K];let P=F*N-g*w,ne=g*E-L*N,Z=L*w-F*E,q=Math.hypot(P,ne,Z)||1;return x.normal=[P/q,ne/q,Z/q],!0}return!1}function an(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let u=0;u<n;u++)r.push(Ce());if(n===0)return r;let i=new Set;for(let u of t.nodes)if(Array.isArray(u.children))for(let d of u.children)i.add(d);let o=new Set,s=128,l=(u,d,h=0)=>{if(h>s||u<0||u>=n||o.has(u))return;o.add(u);let m=t.nodes[u];if(!m)return;let y=Ce();if(e&&e[u])y.set(e[u]);else if(m.matrix&&m.matrix.length===16)y.set(m.matrix);else{let M=m.translation||[0,0,0],L=m.rotation||[0,0,0,1],F=m.scale||[1,1,1];xt(y,L,M,F)}let x=r[u];if(d?Ie(x,d,y):x.set(y),Array.isArray(m.children))for(let M of m.children)typeof M=="number"&&l(M,x,h+1)},a=[],c=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(c&&Array.isArray(c.nodes))a.push(...c.nodes);else for(let u=0;u<n;u++)i.has(u)||a.push(u);for(let u of a)l(u,null);for(let u=0;u<n;u++)!i.has(u)&&!a.includes(u)&&l(u,null);return r}function jn(t,e){function n(a,c,u,d){let h=typeof a=="number"?a:Number(a);return Number.isFinite(h)?Math.max(c,Math.min(u,h)):d}function r(a,c){let d=a[0]*c[0]+a[1]*c[1]+a[2]*c[2]+1;if(d<1e-6){if(Math.abs(a[0])>Math.abs(a[2])){let L=Math.hypot(a[1],a[0])||1;return[-a[1]/L,a[0]/L,0,0]}let M=Math.hypot(a[2],a[1])||1;return[0,-a[2]/M,a[1]/M,0]}let h=a[1]*c[2]-a[2]*c[1],m=a[2]*c[0]-a[0]*c[2],y=a[0]*c[1]-a[1]*c[0],x=Math.hypot(h,m,y,d)||1;return[h/x,m/x,y/x,d/x]}function i(a,c,u,d,h){let m=c[0]-a[0],y=c[1]-a[1],x=c[2]-a[2],M=Math.hypot(m,y,x),L=u[0]-c[0],F=u[1]-c[1],g=u[2]-c[2],E=Math.hypot(L,F,g);if(M<1e-6||E<1e-6)return{rootPos:[a[0],a[1],a[2]],midPos:[c[0],c[1],c[2]],effectorPos:[u[0],u[1],u[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let w=[m/M,y/M,x/M],N=[L/E,F/E,g/E],z=d[0]-a[0],R=d[1]-a[1],C=d[2]-a[2],I=Math.hypot(z,R,C),b=I>1e-6?[z/I,R/I,C/I]:w,v=Math.abs(M-E)+1e-5,f=Math.max(v,M+E-1e-5),p=Math.max(v,Math.min(f,I>1e-6?I:v)),_=n((M*M+p*p-E*E)/(2*M*p),-1,1,1),H=Math.sqrt(Math.max(0,1-_*_)),U=h?h[0]-a[0]:m,Q=h?h[1]-a[1]:y,$=h?h[2]-a[2]:x,K=U*b[0]+Q*b[1]+$*b[2],P=U-b[0]*K,ne=Q-b[1]*K,Z=$-b[2]*K,q=Math.hypot(P,ne,Z);if(q<=1e-6){let T=Math.abs(b[1])<.99?0:1,D=Math.abs(b[1])<.99?1:0,A=0;P=b[1]*A-b[2]*D,ne=b[2]*T-b[0]*A,Z=b[0]*D-b[1]*T,q=Math.hypot(P,ne,Z)||1}let ae=[P/q,ne/q,Z/q],V=[a[0]+b[0]*(M*_)+ae[0]*(M*H),a[1]+b[1]*(M*_)+ae[1]*(M*H),a[2]+b[2]*(M*_)+ae[2]*(M*H)],J=[a[0]+b[0]*p,a[1]+b[1]*p,a[2]+b[2]*p],ce=J[0]-V[0],se=J[1]-V[1],fe=J[2]-V[2],xe=Math.hypot(ce,se,fe),Se=xe>1e-6?[ce/xe,se/xe,fe/xe]:b,pe=[V[0]+Se[0]*E,V[1]+Se[1]*E,V[2]+Se[2]*E],S=[(V[0]-a[0])/M,(V[1]-a[1])/M,(V[2]-a[2])/M];return{rootPos:[a[0],a[1],a[2]],midPos:V,effectorPos:pe,rootRotation:r(w,S),midRotation:r(N,Se)}}function o(a,c,u=8,d=.001){let h=a.length;if(h<2)return{positions:a.map(I=>[I[0],I[1],I[2]]),rotations:[],iterations:0};let m=a.map(I=>[I[0],I[1],I[2]]),y=[],x=[],M=0;for(let I=0;I<h-1;I++){let b=m[I+1][0]-m[I][0],v=m[I+1][1]-m[I][1],f=m[I+1][2]-m[I][2],p=Math.hypot(b,v,f);y.push(p),M+=p,x.push(p>1e-6?[b/p,v/p,f/p]:[0,1,0])}let L=[m[0][0],m[0][1],m[0][2]],F=Math.round(n(u,1,32,8)),g=n(d,1e-5,.1,.001),E=c[0]-L[0],w=c[1]-L[1],N=c[2]-L[2],z=Math.hypot(E,w,N),R=0;if(z>=M&&M>1e-6){let I=z>1e-6?[E/z,w/z,N/z]:x[0];m[0]=[L[0],L[1],L[2]];for(let b=0;b<h-1;b++){let v=y[b];m[b+1]=[m[b][0]+I[0]*v,m[b][1]+I[1]*v,m[b][2]+I[2]*v]}R=1}else for(let I=1;I<=F;I++){let b=m[h-1];if(Math.hypot(b[0]-c[0],b[1]-c[1],b[2]-c[2])<=g)break;R=I;let f=(p,_,H,U,Q)=>{let $=_[0]-p[0],K=_[1]-p[1],P=_[2]-p[2],ne=Math.hypot($,K,P);if(ne>1e-6){let Z=H/ne;return[p[0]+$*Z,p[1]+K*Z,p[2]+P*Z]}return[p[0]+U[0]*H*Q,p[1]+U[1]*H*Q,p[2]+U[2]*H*Q]};m[h-1]=[c[0],c[1],c[2]];for(let p=h-2;p>=0;p--)m[p]=f(m[p+1],m[p],y[p],x[p],-1);m[0]=[L[0],L[1],L[2]];for(let p=0;p<h-1;p++)m[p+1]=f(m[p],m[p+1],y[p],x[p],1)}let C=[];for(let I=0;I<h-1;I++){let b=m[I+1][0]-m[I][0],v=m[I+1][1]-m[I][1],f=m[I+1][2]-m[I][2],p=Math.hypot(b,v,f),_=p>1e-6?[b/p,v/p,f/p]:x[I];C.push(r(x[I],_))}return{positions:m,rotations:C,iterations:R}}function s(a){if(!a||typeof a!="object"||Array.isArray(a))return null;let c=a;if(c.enabled===!1)return null;let u=g=>{if(typeof g!="string")return;let E=g.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(E)?E:void 0},d=g=>Array.isArray(g)&&g.length===3&&g.every(E=>typeof E=="number"&&Number.isFinite(E))?[n(g[0],-1e3,1e3,0),n(g[1],-1e3,1e3,0),n(g[2],-1e3,1e3,0)]:void 0,h=u(c.root),m=u(c.effector);if(!h||!m)return null;let y=u(c.mid),x=d(c.target)??u(c.target);if(!x)return null;let M=c.pole??c.poleTarget,L=d(M)??u(M),F=c.solver==="fabrik"?"fabrik":c.solver==="two-bone"||y?"two-bone":"fabrik";return{root:h,...y?{mid:y}:{},effector:m,target:x,...L?{pole:L}:{},solver:F,iterations:Math.round(n(c.iterations,1,32,8)),tolerance:n(c.tolerance,1e-5,.1,.001),weight:n(c.weight,0,1,1)}}let l=Object.freeze({solveTwoBone:i,solveFABRIK:o,parseIKTrait:s});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=l),{clampNum:n,parseIKTrait:s,quatFromUnitVectors:r,solveTwoBoneIK:i,solveFABRIK:o,IKSolver:l}}var Dt=jn(),hs=Dt.clampNum,ms=Dt.parseIKTrait,fs=Dt.quatFromUnitVectors,ds=Dt.solveTwoBoneIK,ps=Dt.solveFABRIK,bs=Dt.IKSolver;var Li={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Yn(t,e,n,r){if(!n||n.bufferView===void 0)return null;let i=t.bufferViews?.[n.bufferView];if(!i)return null;let o=Number(n.count??0);if(!Number.isInteger(o)||o<=0)return null;let s=n.componentType??5126,l=Li[s];if(!l)throw new RangeError(`glTF accessor has unsupported componentType ${s}`);let a=l*r,c=i.byteStride&&i.byteStride>0?i.byteStride:a,u=(i.byteOffset||0)+(n.byteOffset||0);if(!Number.isInteger(u)||u<0||c<a||u+(o-1)*c+a>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(s===5126&&c===a&&u%4===0)return new Float32Array(e,u,o*r);let d=new DataView(e),h=n.normalized===!0,m=new Float32Array(o*r);for(let y=0;y<o;y++){let x=u+y*c;for(let M=0;M<r;M++){let L=x+M*l,F;switch(s){case 5126:F=d.getFloat32(L,!0);break;case 5120:F=d.getInt8(L),h&&(F=Math.max(F/127,-1));break;case 5121:F=d.getUint8(L),h&&(F/=255);break;case 5122:F=d.getInt16(L,!0),h&&(F=Math.max(F/32767,-1));break;case 5123:F=d.getUint16(L,!0),h&&(F/=65535);break;default:F=d.getUint32(L,!0),h&&(F/=4294967295)}m[y*r+M]=F}}return m}function Or(t,e){let n=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),o=Number(e.scale?.[1]??1),s=Number(e.rotation??0)||0,l=Math.cos(s),a=Math.sin(s),c=(Number.isFinite(i)?i:1)*l,u=(Number.isFinite(i)?i:1)*a,d=-(Number.isFinite(o)?o:1)*a,h=(Number.isFinite(o)?o:1)*l;for(let m=0;m+1<t.length;m+=2){let y=t[m],x=t[m+1];t[m]=c*y+u*x+n,t[m+1]=d*y+h*x+r}}var Br=["neutral","reinhard","none","aces","agx"];function Zn(t){let e=String(t??"").trim().toLowerCase();return Br.includes(e)?e:"neutral"}function ki(t){return Br.indexOf(Zn(t))}function Pi(t){return new TextDecoder().decode(t)}var Gr=_e().decoders;function Ni(t,e){Gr.set(t.toLowerCase(),e)}function Lt(t){return Gr.get(t.toLowerCase())}function Hr(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let h=n.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 i=n.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let o=n.getUint32(8,!0),s=12,l=null,a=null;for(;s+8<=o&&s+8<=e.byteLength;){let h=n.getUint32(s,!0),m=n.getUint32(s+4,!0),y=s+8;if(y+h>e.byteLength)throw new Error(`Truncated GLB chunk: required ${y+h} bytes, buffer has ${e.byteLength}`);if(m===1313821514){let x=new Uint8Array(e,y,h),M=Pi(x);l=JSON.parse(M,(L,F)=>L==="__proto__"||L==="constructor"||L==="prototype"?void 0:F)}else m===5130562&&(a=e.slice(y,y+h));s=y+h}if(!l)throw new Error("Missing JSON chunk in GLB");let c=l.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!Lt("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let h of["EXT_meshopt_compression","KHR_meshopt_compression"])if(c.includes(h)&&!Lt("meshopt"))throw new Error(`Model requires ${h}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!Lt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=a||new ArrayBuffer(0),d={gltf:l,bin:u,animations:[]};for(let h of Ne)h.onParseGLB?.(d);return d}function Fi(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 Bt(t){if(Fi(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return Hr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Xr=`#version 300 es
|
|
18
19
|
layout(location=0) in vec3 aPosition;
|
|
19
20
|
layout(location=1) in vec3 aNormal;
|
|
20
21
|
layout(location=2) in vec2 aUV;
|
|
21
22
|
uniform mat4 uMVP,uModel;
|
|
22
23
|
uniform mat3 uNormalMatrix;
|
|
23
24
|
uniform vec4 uUvTransform;
|
|
25
|
+
layout(location=8) in vec4 aInst0;
|
|
26
|
+
layout(location=9) in vec4 aInst1;
|
|
27
|
+
layout(location=10) in vec4 aInst2;
|
|
28
|
+
layout(location=11) in vec4 aInst3;
|
|
29
|
+
layout(location=12) in vec4 aInstColor;
|
|
30
|
+
uniform int uInstanced;
|
|
31
|
+
uniform mat4 uViewProj;
|
|
32
|
+
out vec4 vInstTint;
|
|
33
|
+
mat4 xrModel(){return uInstanced==1?uModel*mat4(aInst0,aInst1,aInst2,aInst3):uModel;}
|
|
34
|
+
mat4 xrMVP(){return uInstanced==1?uViewProj*xrModel():uMVP;}
|
|
35
|
+
mat3 xrNormalMatrix(){return uInstanced==1?transpose(inverse(mat3(xrModel()))):uNormalMatrix;}
|
|
36
|
+
#define uModel xrModel()
|
|
37
|
+
#define uMVP xrMVP()
|
|
38
|
+
#define uNormalMatrix xrNormalMatrix()
|
|
24
39
|
out vec3 vNormal,vWorldPos;
|
|
25
40
|
out vec2 vUV;
|
|
26
41
|
void main(){
|
|
42
|
+
vInstTint=uInstanced==1?aInstColor:vec4(1.0);
|
|
27
43
|
vec3 rawN=uNormalMatrix*aNormal;
|
|
28
44
|
vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
|
|
29
45
|
vec4 world=uModel*vec4(aPosition,1.0);
|
|
@@ -32,12 +48,14 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
32
48
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
33
49
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
34
50
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
35
|
-
}`,
|
|
51
|
+
}`,Oi=`#version 300 es
|
|
36
52
|
precision highp float;
|
|
37
53
|
in vec3 vNormal,vWorldPos;
|
|
38
54
|
in vec2 vUV;
|
|
39
55
|
uniform vec4 uBaseColor;
|
|
40
|
-
|
|
56
|
+
in vec4 vInstTint;
|
|
57
|
+
#define uBaseColor (uBaseColor*vInstTint)
|
|
58
|
+
uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity,uExposure;
|
|
41
59
|
uniform vec2 uClearcoat;
|
|
42
60
|
uniform vec3 uCameraPos,uAmbientColor;
|
|
43
61
|
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap;
|
|
@@ -108,9 +126,33 @@ float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
|
|
|
108
126
|
return mix(color,newPeak*vec3(1.0),g);
|
|
109
127
|
}
|
|
110
128
|
|
|
129
|
+
vec3 acesToneMapping(vec3 color){
|
|
130
|
+
color*=0.6;
|
|
131
|
+
return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
vec3 agxToneMapping(vec3 color){
|
|
135
|
+
color=max(color,vec3(0.0));
|
|
136
|
+
vec3 inset=vec3(
|
|
137
|
+
0.84247906*color.r+0.0784336*color.g+0.07922375*color.b,
|
|
138
|
+
0.04232824*color.r+0.87846864*color.g+0.07916613*color.b,
|
|
139
|
+
0.04237565*color.r+0.0784336*color.g+0.87914297*color.b);
|
|
140
|
+
vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
|
|
141
|
+
vec3 x2=ev*ev;
|
|
142
|
+
vec3 x4=x2*x2;
|
|
143
|
+
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;
|
|
144
|
+
vec3 outset=vec3(
|
|
145
|
+
1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
|
|
146
|
+
-0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
|
|
147
|
+
-0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
|
|
148
|
+
return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
149
|
+
}
|
|
150
|
+
|
|
111
151
|
vec3 applyToneMapping(vec3 color,int mode){
|
|
112
152
|
if(mode==0)return neutralToneMapping(color);
|
|
113
153
|
if(mode==1)return color/(color+vec3(1.0));
|
|
154
|
+
if(mode==3)return acesToneMapping(color);
|
|
155
|
+
if(mode==4)return agxToneMapping(color);
|
|
114
156
|
return color;
|
|
115
157
|
}
|
|
116
158
|
|
|
@@ -194,23 +236,24 @@ if(uClearcoat.x>0.0){
|
|
|
194
236
|
vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
|
|
195
237
|
color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
196
238
|
}
|
|
239
|
+
color*=uExposure;
|
|
197
240
|
color=applyToneMapping(color,uToneMapping);
|
|
198
241
|
float outAlpha=base.a;
|
|
199
242
|
/*XRD_O*/
|
|
200
243
|
fragColor=vec4(color,outAlpha);
|
|
201
|
-
}
|
|
244
|
+
}`;var Ui=`#version 300 es
|
|
202
245
|
layout(location=0) in vec3 aPosition;
|
|
203
246
|
uniform mat4 uMVP;
|
|
204
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
247
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,zi=`#version 300 es
|
|
205
248
|
precision highp float;
|
|
206
249
|
uniform vec4 uColorId;
|
|
207
250
|
out vec4 fragColor;
|
|
208
|
-
void main(){fragColor=uColorId;}`;function vn(t,e,n){let r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,35713)){let i=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function jt(t,e,n){let r=vn(t,35633,e),i=vn(t,35632,n),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,35714)){let c=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${c}`)}return o}function qt(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var Tn=["uMVP","uModel","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uViewportSize","uSectionPlane","uSectionEnabled"];function Mn(){let t=Q().xrDepthShader;return{fs:yr.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...Tn,...t.uniformNames]:Tn}}function vr(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Yt(t,e,n,r,i,o,c){if(r===void 0||!e.accessors?.[r])return null;let h=e.accessors[r],u=e.bufferViews[h.bufferView],s=(u.byteOffset||0)+(h.byteOffset||0),a=u.byteStride&&u.byteStride>o*4?u.byteStride>>2:o,m;if(a===o)m=new Float32Array(n,s,h.count*o);else{m=new Float32Array(h.count*o);let f=new Float32Array(n,u.byteOffset||0,Math.floor(u.byteLength/4)),d=(h.byteOffset||0)>>2;for(let S=0;S<h.count;S++){let A=d+S*a;for(let M=0;M<o;M++)m[S*o+M]=f[A+M]}}let l=t.createBuffer();return c.push(l),t.bindBuffer(34962,l),t.bufferData(34962,m,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),m}var Oi=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),An=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function wn(t,e,n=An,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:o}=e,c=[],h=ut(i),u=[];if(Array.isArray(i.nodes))for(let E=0;E<i.nodes.length;E++){let v=i.nodes[E];v.mesh!==void 0&&i.meshes&&i.meshes[v.mesh]&&u.push({node:v,nodeIdx:E,meshIdx:v.mesh})}let s=u.length>0?u:(i.meshes||[]).map((E,v)=>({node:E,nodeIdx:-1,meshIdx:v})),a=[];if(Array.isArray(e.lights)&&e.lights.length>0)a.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let E=i.extensions.KHR_lights_punctual.lights;for(let v of E){let _=v.type==="directional"?"directional":v.type==="point"?"point":"ambient";a.push({type:_,color:v.color||[1,1,1],intensity:v.intensity!==void 0?v.intensity:1})}}if(a.length===0&&(a.push({type:"ambient",color:[1,1,1],intensity:.35}),a.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),s.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${s.length}`);let m=[];if(i.textures&&i.images){if(i.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${i.textures.length}`);for(let E=0;E<i.textures.length;E++){let v=i.textures[E],_=i.images[v.source];if(_){let D=t.createTexture();if(t.bindTexture(3553,D),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),_.bufferView!==void 0){let g=i.bufferViews[_.bufferView],T=o.slice(g.byteOffset||0,(g.byteOffset||0)+g.byteLength),x=new Blob([T],{type:_.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(x).then(L=>{t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,L),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let g=vr(_.uri);if(g){let T=new Image;T.crossOrigin="anonymous",T.referrerPolicy="no-referrer",T.onload=()=>{t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,T),t.generateMipmap(3553),r?.()},T.src=g}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.uri)}m.push(D)}else m.push(null)}}let l=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0],d=0,S=0;for(let E=0;E<s.length;E++){let v=s[E],_=i.meshes[v.meshIdx],D=v.nodeIdx>=0?h[v.nodeIdx]:Z(),g=new Float32Array(9);ce(g,D);let T={name:v.node.name||_.name||`Mesh_${v.meshIdx}`,nodeIndex:v.nodeIdx,transform:D,normalMatrix:g,primitives:[],extras:v.node.extras||_.extras};for(let x of _.primitives||[]){if(x.extensions?.KHR_draco_mesh_compression){let j=Be("draco");j&&j.decodePrimitive(i,x,o)}let L=[],I=t.createVertexArray();t.bindVertexArray(I);let H=i.accessors[x.attributes.POSITION],k=Number(H?.count??0);if(!Number.isFinite(k)||k<0||d+k>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(d+=k,H?.min&&H?.max)for(let j=0;j<3;j++){let le=D[12+j],Ie=D[12+j];for(let pe=0;pe<3;pe++){let rt=D[pe*4+j]*H.min[pe],it=D[pe*4+j]*H.max[pe];le+=rt<it?rt:it,Ie+=rt>it?rt:it}le<l[j]&&(l[j]=le),Ie>f[j]&&(f[j]=Ie)}let U=Yt(t,i,o,x.attributes.POSITION,0,3,L);Yt(t,i,o,x.attributes.NORMAL,1,3,L),Yt(t,i,o,x.attributes.TEXCOORD_0,2,2,L);let N=0,C=5123,O=null;if(x.indices!==void 0){let j=i.accessors[x.indices],Ie=(i.bufferViews[j.bufferView].byteOffset||0)+(j.byteOffset||0);if(N=Number(j.count??0),!Number.isFinite(N)||N<0||S+N>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);S+=N,C=j.componentType===5125?5125||5125:5123||5123;let pe=t.createBuffer();L.push(pe),t.bindBuffer(34963,pe),j.componentType===5125?(O=new Uint32Array(o,Ie,j.count),t.bufferData(34963,O,35044)):(O=new Uint16Array(o,Ie,j.count),t.bufferData(34963,O,35044))}else N=H.count;let F={};for(let j of ee)if(j.onBuildPrimitiveVAO){let le=j.onBuildPrimitiveVAO(t,I,x,i,o);le&&(F[j.name]=le)}t.bindVertexArray(null);let V=i.materials&&x.material!==void 0?i.materials[x.material]:null,z=Mn(),X=Rn,Y=z.fs,$=!1;for(let j of ee)if(j.onResolveShader){let le=j.onResolveShader(x,V,X,Y);le&&(X=le.vs,Y=le.fs,$=!0)}let ae=$?jt(t,X,Y):null,ye=ae?qt(t,ae,z.uniforms):null,K=V?.pbrMetallicRoughness,ge=K?.baseColorFactor||[.8,.8,.8,1],xe=K?.metallicFactor??.1,ve=K?.roughnessFactor??.5,re=V?.extensions?.KHR_materials_clearcoat,Te=re?re.clearcoatFactor??1:0,we=Math.max(.04,re?.clearcoatRoughnessFactor??.04),ze=K?.baseColorTexture!==void 0&&m[K.baseColorTexture.index]?m[K.baseColorTexture.index]:null,nr=K?.metallicRoughnessTexture!==void 0&&m[K.metallicRoughnessTexture.index]?m[K.metallicRoughnessTexture.index]:null,rr=V?.normalTexture!==void 0&&m[V.normalTexture.index]?m[V.normalTexture.index]:null,ir=V?.normalTexture?.scale??1,or=V?.occlusionTexture!==void 0&&m[V.occlusionTexture.index]?m[V.occlusionTexture.index]:null,sr=V?.occlusionTexture?.strength??1,ar=!!(V?.extensions?.KHR_materials_transmission||F.materials?.isTransmissive);T.primitives.push({vao:I,indexCount:N,indexType:C,baseColor:ge,metallic:xe,roughness:ve,clearcoat:Te,clearcoatRoughness:we,positions:U,indices:O,texture:ze,metallicRoughnessTexture:nr,normalTexture:rr,occlusionTexture:or,normalScale:ir,occlusionStrength:sr,buffers:L,materialIndex:x.material,pluginData:F,customProgram:ae,customUniforms:ye,isTransmissive:ar})}c.push(T)}isFinite(l[0])||(l=[-1,-1,-1]),isFinite(f[0])||(f=[1,1,1]);let A=[(l[0]+f[0])/2,(l[1]+f[1])/2,(l[2]+f[2])/2],M=f[0]-l[0],P=f[1]-l[1],y=f[2]-l[2],w=Math.max(Math.hypot(M,P,y)/2,.5),b=[l[0],l[1],l[2]],R=[f[0],f[1],f[2]],p=e.animations;if(!p){for(let E of ee)if(E.onParseGLB?.(e),e.animations){p=e.animations;break}}return p||(p=[]),{meshes:c,bounds:{center:A,radius:w,min:b,max:R},lights:a,animations:p,worldMatrices:h}}var lt=class{constructor(e,n,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=Z();this.clearColor=[0,0,0,0];this.envIntensity=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=Z();this.viewMatrix=Z();this.modelMatrix=Z();this.mvpMatrix=Z();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:Z(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let s=e.querySelector("canvas");s||(s=document.createElement("canvas"),s.style.width="100%",s.style.height="100%",s.style.display="block",s.style.touchAction="none",e.prepend(s)),i=s}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let c=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!c:c&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.envIntensity=Math.max(0,Number(this.opts.exposure))),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=this.opts.toneMapping),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let h=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!h)throw new Error("WebGL2 not supported");this.gl=h;let u=Mn();this.renderProg=jt(h,Rn,u.fs),this.pickProg=jt(h,gr,xr),this.uRender=qt(h,this.renderProg,u.uniforms),this.uPick=qt(h,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){pr(e,n)}static getDecoder(e){return Be(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,n){let{meshes:r,bounds:i,lights:o,animations:c,worldMatrices:h}=wn(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=c||[],this.worldMatrices=h||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let s of e.gltf.nodes)this.initialNodeTransforms.push({t:s.translation?[s.translation[0],s.translation[1],s.translation[2]]:[0,0,0],r:s.rotation?[s.rotation[0],s.rotation[1],s.rotation[2],s.rotation[3]]:[0,0,0,1],s:s.scale?[s.scale[0],s.scale[1],s.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let s of ee)s.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u))),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(Sn(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Ve(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Ve(e),{meshes:i}=wn(this.gl,r,An,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],ce(o.normalMatrix,o.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,n,r,i=1){this.clearColor=[e,n,r,i]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;e instanceof Map?i=e.get(r.name)??e.get(n):Array.isArray(e)?i=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,n)&&(i=e[n])),i&&i.length===16&&(r.transform.set(i),ce(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],c=[],h=[];for(let u of this.lights){let s=u.color||[1,1,1],a=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[s[0]*a,s[1]*a,s[2]*a];else if(u.type==="directional"&&i.length<6){let m=u.direction||[.5,1,.8];i.push(m[0],m[1],m[2]),o.push(s[0]*a,s[1]*a,s[2]*a)}else if(u.type==="point"&&c.length<6){let m=u.position||[0,0,0];c.push(m[0],m[1],m[2]),h.push(s[0]*a,s[1]*a,s[2]*a)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,r),n.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(e.uDirLightDir,i),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,c.length/3),c.length>0&&(n.uniform3fv(e.uPointLightPos,c),n.uniform3fv(e.uPointLightColor,h)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of ee)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of ee)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:e,phi:n,radius:r,toString(){return`${e.toFixed(4)}rad ${n.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((n,r)=>{let i=this.meshes.flatMap(a=>a.primitives.filter(m=>m.materialIndex===r||e.length===1&&m.materialIndex===void 0)),o=i[0],c=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],h=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,u=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,s={baseColorFactor:c,metallicFactor:h,roughnessFactor:u,setBaseColorFactor:a=>{let m=[a[0],a[1],a[2],a[3]??1];s.baseColorFactor=m,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=m);for(let l of i)l.baseColor=m;this.render()},setMetallicFactor:a=>{s.metallicFactor=a,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=a);for(let m of i)m.metallic=a;this.render()},setRoughnessFactor:a=>{s.roughnessFactor=a,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=a);for(let m of i)m.roughness=a;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:s}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(r=>r.name===e);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let n of ee)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,r){this.customTarget=[e,n,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,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 n=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(n,Math.min(r,e))}setCamera(e,n,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,n,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}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,n){let r=Z();ie(r,this.projMatrix,this.viewMatrix);let[i,o,c]=e,h=n?n[0]:0,u=n?n[1]:0,s=n?n[2]:0,a=this.modelRootMatrix;a&&(i=a[0]*e[0]+a[4]*e[1]+a[8]*e[2]+a[12],o=a[1]*e[0]+a[5]*e[1]+a[9]*e[2]+a[13],c=a[2]*e[0]+a[6]*e[1]+a[10]*e[2]+a[14],n&&(h=a[0]*n[0]+a[4]*n[1]+a[8]*n[2],u=a[1]*n[0]+a[5]*n[1]+a[9]*n[2],s=a[2]*n[0]+a[6]*n[1]+a[10]*n[2]));let m=r[0]*i+r[4]*o+r[8]*c+r[12],l=r[1]*i+r[5]*o+r[9]*c+r[13],f=r[2]*i+r[6]*o+r[10]*c+r[14],d=r[3]*i+r[7]*o+r[11]*c+r[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let S=m/d,A=l/d,M=f/d,P=this.canvas.getBoundingClientRect(),y=P.width||this.canvas.clientWidth||this.canvas.width||300,w=P.height||this.canvas.clientHeight||this.canvas.height||150,b=(S*.5+.5)*y,R=(-A*.5+.5)*w,p=S>=-1.1&&S<=1.1&&A>=-1.1&&A<=1.1&&M>=-1&&M<=1;if(p&&n){let E=this.customTarget||this.bounds.center,v=E[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=E[1]+this.currDistance*Math.sin(this.currPhi),D=E[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),g=[i-v,o-_,c-D];h*g[0]+u*g[1]+s*g[2]>.05&&(p=!1)}return{x:b,y:R,z:M,visible:p}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=n.clientX-r.x,o=n.clientY-r.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(i,o),this.isPanning||n.button===2||n.shiftKey||this.activePointers.size===2){let c=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],h=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],s=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;u[0]+=(-i*c[0]+o*h[0])*s,u[1]+=(-i*c[1]+o*h[1])*s,u[2]+=(-i*c[2]+o*h[2])*s,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=e.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(e.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let r=n.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=n=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,c=r.height||300,h=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),u=i.height>0?Math.floor((n-i.top)*(c/i.height)):Math.floor(n);return this.performMeshPick(h,u,!1)}performMeshPick(e,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),c=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let h=Z();ie(h,this.projMatrix,this.viewMatrix);let u=[],s=Math.max(0,Math.min(o-1,e)),a=Math.max(0,Math.min(c-1,c-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==c)&&this.resizePickingFbo(o,c),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,c),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let p=0;p<this.meshes.length;p++){let E=this.meshes[p];if(E.visible===!1||E.isPluginMesh)continue;let v=p+1,_=(v&255)/255,D=(v>>8&255)/255,g=(v>>16&255)/255;i.uniform4f(this.uPick.uColorId,_,D,g,1),ie(this.modelMatrix,this.modelRootMatrix,E.transform),ie(this.mvpMatrix,h,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let T of E.primitives)i.bindVertexArray(T.vao),i.drawElements(4,T.indexCount,T.indexType,0)}let b=new Uint8Array(4);i.readPixels(s,a,1,1,6408,5121,b),i.bindFramebuffer(36160,null);let R=b[0]+(b[1]<<8)+(b[2]<<16);R>0&&R<=this.meshes.length&&(u=[this.meshes[R-1]])}u.length===0&&(u=this.meshes.filter(b=>b.visible!==!1));let m=null,l=1/0,f=[0,0,0],d=[0,1,0],S=this.customTarget||this.bounds.center,A=S[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),M=S[1]+this.currDistance*Math.sin(this.currPhi),P=S[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let b of u){ie(this.modelMatrix,this.modelRootMatrix,b.transform),ie(this.mvpMatrix,h,this.modelMatrix);let R=Z();if(!gn(R,this.mvpMatrix))continue;let p=(s+.5)/o*2-1,E=(a+.5)/c*2-1,v=[0,0,0],_=[0,0,0];$t(v,p,E,-1,R),$t(_,p,E,1,R);let D=_[0]-v[0],g=_[1]-v[1],T=_[2]-v[2],x=Math.hypot(D,g,T)||1,L=D/x,I=g/x,H=T/x,k={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((N=>{for(let C of b.primitives){if(!C.positions)continue;let O=C.positions,F=C.indices,V=Math.floor(F?F.length/3:O.length/9);for(let z=0;z<V;z++){let X=F?F[z*3]:z*3,Y=F?F[z*3+1]:z*3+1,$=F?F[z*3+2]:z*3+2;xn(v[0],v[1],v[2],L,I,H,O[X*3],O[X*3+1],O[X*3+2],O[Y*3],O[Y*3+1],O[Y*3+2],O[$*3],O[$*3+1],O[$*3+2],k,N)}}})(1e-4),isFinite(k.distance)){let N=k.point[0],C=k.point[1],O=k.point[2],F=this.modelMatrix,V=F[0]*N+F[4]*C+F[8]*O+F[12],z=F[1]*N+F[5]*C+F[9]*O+F[13],X=F[2]*N+F[6]*C+F[10]*O+F[14],Y=V-A,$=z-M,ae=X-P,ye=Math.hypot(Y,$,ae);if(ye<l){ce(this.normalMatrix,this.modelMatrix);let K=this.normalMatrix,ge=k.normal[0],xe=k.normal[1],ve=k.normal[2],re=K[0]*ge+K[3]*xe+K[6]*ve,Te=K[1]*ge+K[4]*xe+K[7]*ve,we=K[2]*ge+K[5]*xe+K[8]*ve,ze=Math.hypot(re,Te,we)||1;re/=ze,Te/=ze,we/=ze,re*Y+Te*$+we*ae>0&&(re=-re,Te=-Te,we=-we),m=b,l=Math.round(ye*1e3)/1e3,f=[Math.round(V*1e3)/1e3,Math.round(z*1e3)/1e3,Math.round(X*1e3)/1e3],d=[Math.round(re*1e3)/1e3,Math.round(Te*1e3)/1e3,Math.round(we*1e3)/1e3]}}}if(!m)return null;let w={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:l,hitPoint:f,normal:d,screenX:e,screenY:n};if(r){for(let b of ee)b.onMeshSelect?.(this,w);this.opts.onMeshClick&&this.opts.onMeshClick(w),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:w}))}return w}mapStereoPickX(e,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return e;let r=Math.max(1,Math.floor(n*.5)),i=e>=r,o=i?e-r:e,c=i?Math.max(1,n-r):r,h=(o+.5)/c*2-1;return Math.floor((h*.5+1)*.5*n)}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),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);at(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),o=r[1]+this.currDistance*Math.sin(this.currPhi),c=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Pe(this.viewMatrix,[i,o,c],r,[0,1,0]),ie(this.mvpMatrix,this.projMatrix,this.viewMatrix),ce(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*e)),i=Math.max(1,Math.floor(n.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let n=this.xrSessionActive;if(this.xrSessionActive=e,n&&!e){this.xrDepthState.enabled=!1;for(let r of ee)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let n of ee)n.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=n=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((n-this.lastTime)/1e3,0),.1);if(this.lastTime=n,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+n*i),o[13]=0,o[14]=i-(-n*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let c of ee)c.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let c of ee)c.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let c={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(c),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:c}))}}renderXRView(e,n,r,i,o=!0,c=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let h=e?.transform?.inverse?.matrix||this.viewMatrix,u=e?.projectionMatrix||this.projMatrix,s=e?.transform?.position,a=s?[s.x,s.y,s.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:h,projMatrix:u,eyePos:a,viewport:i,eye:e?.eye||"none",clear:c>0?!1:e?.eye!=="right",isAR:o})}render(e){if(!e&&this.stereoSBS){let w=Math.max(2,this.canvas.width||2),b=Math.max(1,this.canvas.height||1),R=Math.max(1,Math.floor(w*.5)),p=Math.max(1,w-R),E=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),v=this.customTarget||this.bounds.center,_=v[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),D=v[1]+this.currDistance*Math.sin(this.currPhi),g=v[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),T=Math.cos(this.currTheta),x=-Math.sin(this.currTheta),L=.032,I=Z(),H=Z(),k=[_-T*L,D,g-x*L],U=[v[0]-T*L*.25,v[1],v[2]-x*L*.25];at(I,this.fov,R/b,.1,E),Pe(H,k,U,[0,1,0]);let N=Z(),C=Z(),O=[_+T*L,D,g+x*L],F=[v[0]+T*L*.25,v[1],v[2]+x*L*.25];at(N,this.fov,p/b,.1,E),Pe(C,O,F,[0,1,0]),this.render({viewMatrix:H,projMatrix:I,eyePos:k,viewport:[0,0,R,b],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:C,projMatrix:N,eyePos:O,viewport:[R,0,p,b],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,w,b);return}let n=this.gl,r=0,i=0,o=this.canvas.width,c=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],c=e.viewport[3],n.viewport(r,i,o,c)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?n.clearColor(0,0,0,0):n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let h=Z(),u=e?.viewMatrix??this.viewMatrix;ie(h,e?.projMatrix??this.projMatrix,u);let s=Q().xrDepthShader,a=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,m=this.customTarget||this.bounds.center,l=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),f=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),d=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let w of ee)w.onBeforeDrawScene?.(this,n,h,[l,f,d],a);let S=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&S===0)return;let A=e?.eye||"none",M=!1,P=S>0?[...this.backdropMeshes,...this.meshes]:this.meshes,y=w=>{for(let b=0;b<P.length;b++){let R=P[b];if(R.visible===!1)continue;let p=this.selectedMeshName!==""&&R.name===this.selectedMeshName;b<S||R.worldSpace===!0||R.name==="__xr_reticle__"?this.modelMatrix.set(R.transform):ie(this.modelMatrix,this.modelRootMatrix,R.transform),ie(this.mvpMatrix,h,this.modelMatrix),ce(R.normalMatrix,this.modelMatrix);let E=R.extras?.xr?.stereo||R.userData?.xr?.stereo,v=0,_=0,D=1,g=1;E==="sbs"?(D=.5,v=A==="right"?.5:0):E==="ou"&&(g=.5,_=A==="right"?.5:0);for(let T of R.primitives){let x=!!T.isTransmissive;if(!w&&x){M=!0;continue}if(w&&!x)continue;let L=T.customProgram||this.renderProg,I=T.customUniforms||this.uRender;n.useProgram(L),n.uniform1i(I.uToneMapping,a),n.uniform1f(I.uEnvIntensity,this.envIntensity),n.uniform3f(I.uCameraPos,l,f,d),n.uniform1f(I.uEmissive,p?1:0),n.uniformMatrix4fv(I.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(I.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(I.uNormalMatrix,!1,R.normalMatrix),I.uUvTransform&&n.uniform4f(I.uUvTransform,v,_,D,g),I.uViewportSize&&n.uniform2f(I.uViewportSize,Math.max(1,o),Math.max(1,c)),s?.bind(n,I,this.xrDepthState,u,[r,i,Math.max(1,o),Math.max(1,c)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(I.uEnvironmentMap,4),n.uniform1i(I.uHasEnvironmentMap,1)):n.uniform1i(I.uHasEnvironmentMap,0),this.bindLights(I),I.uSectionEnabled&&n.uniform1i(I.uSectionEnabled,0);for(let H of ee)H.onBeforeDrawPrimitive?.(n,L,T,R,this.worldMatrices||[],this.gltf);n.uniform4fv(I.uBaseColor,T.baseColor),n.uniform1f(I.uMetallic,T.metallic),n.uniform1f(I.uRoughness,T.roughness),I.uClearcoat&&n.uniform2f(I.uClearcoat,T.clearcoat??0,T.clearcoatRoughness??.04),T.texture?(n.activeTexture(33984),n.bindTexture(3553,T.texture),n.uniform1i(I.uBaseColorTexture,0),n.uniform1i(I.uHasTexture,1)):n.uniform1i(I.uHasTexture,0),T.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,T.metallicRoughnessTexture),n.uniform1i(I.uMetallicRoughnessTexture,1),n.uniform1i(I.uHasMetallicRoughnessTexture,1)):n.uniform1i(I.uHasMetallicRoughnessTexture,0),T.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,T.normalTexture),n.uniform1i(I.uNormalTexture,2),n.uniform1i(I.uHasNormalTexture,1),n.uniform1f(I.uNormalScale,T.normalScale)):n.uniform1i(I.uHasNormalTexture,0),T.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,T.occlusionTexture),n.uniform1i(I.uOcclusionTexture,3),n.uniform1i(I.uHasOcclusionTexture,1),n.uniform1f(I.uOcclusionStrength,T.occlusionStrength)):n.uniform1i(I.uHasOcclusionTexture,0),n.bindVertexArray(T.vao),n.drawElements(4,T.indexCount,T.indexType,0)}}};if(y(!1),M){for(let w of ee)w.onBeforeTransmissivePass?.(n,this);y(!0)}for(let w of ee)w.onAfterRender?.(n,this,h)}disposeMeshListGpuResources(e){let n=this.gl;for(let r of e)for(let i of r.primitives){if(i.vao&&n.deleteVertexArray(i.vao),i.buffers)for(let o of i.buffers)n.deleteBuffer(o);i.texture&&n.deleteTexture(i.texture),i.metallicRoughnessTexture&&n.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&n.deleteTexture(i.normalTexture),i.occlusionTexture&&n.deleteTexture(i.occlusionTexture),i.customProgram&&n.deleteProgram(i.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of ee)n.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()}};lt.registerPlugin=bn,lt.getRegisteredPlugins=yn;function Tr(t){return t+3&-4}function wr(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}function Le(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],c=[],h=[],u=new Set,s=[],a=[],m=new Map,l=[];function f(p,E){let v=new Uint8Array(p.buffer,p.byteOffset,p.byteLength),_=Tr(v.byteLength),D=new Uint8Array(_);D.set(v),n.push(D);let g=i.length;return i.push({buffer:0,byteOffset:r,byteLength:v.byteLength,target:E}),r+=_,g}function d(p,E,v,_,D,g,T){let x=f(p,v),L=o.length,I={bufferView:x,byteOffset:0,componentType:_,count:D,type:E};return g&&(I.min=g),T&&(I.max=T),o.push(I),L}t.traverse(p=>{(p.isLight||p.color&&p.intensity!==void 0)&&l.push({type:p.type,color:[p.color.r,p.color.g,p.color.b],intensity:p.intensity,position:[p.position.x,p.position.y,p.position.z]})});let S=[];function A(p){let E={name:p.name||""},v=p.position,_=p.quaternion,D=p.scale;if((v.x||v.y||v.z)&&(E.translation=[v.x,v.y,v.z]),(_.x||_.y||_.z||_.w!==1)&&(E.rotation=[_.x,_.y,_.z,_.w]),(D.x!==1||D.y!==1||D.z!==1)&&(E.scale=[D.x,D.y,D.z]),p.userData&&Object.keys(p.userData).length>0&&(E.extras=JSON.parse(JSON.stringify(p.userData,(T,x)=>{if(!(T==="__proto__"||T==="prototype"||T==="constructor"))return typeof x=="function"?void 0:x})),p.userData.xr)){let T=wr(p.userData.xr);E.extensions={...E.extensions||{},MOZ_hubs_components:T,ANDROID_xr_scenecore:T},Q().xrTraitSerializer?.gltfNode(E,p.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(p.geometry){let T=p.geometry,x=T.attributes.position;if(x&&x.count>0){let L=[1/0,1/0,1/0],I=[-1/0,-1/0,-1/0];for(let N=0;N<x.count;N++){let C=x.getX(N),O=x.getY(N),F=x.getZ(N);C<L[0]&&(L[0]=C),C>I[0]&&(I[0]=C),O<L[1]&&(L[1]=O),O>I[1]&&(I[1]=O),F<L[2]&&(L[2]=F),F>I[2]&&(I[2]=F)}let k={attributes:{POSITION:d(x.array,"VEC3",34962,5126,x.count,L,I)}};if(T.attributes.normal&&(k.attributes.NORMAL=d(T.attributes.normal.array,"VEC3",34962,5126,T.attributes.normal.count)),T.attributes.uv&&(k.attributes.TEXCOORD_0=d(T.attributes.uv.array,"VEC2",34962,5126,T.attributes.uv.count)),T.index){let N=T.index.array instanceof Uint32Array;k.indices=d(T.index.array,"SCALAR",34963,N?5125:5123,T.index.count)}if(p.material){let N=m.get(p.material);if(N===void 0){N=a.length,m.set(p.material,N);let C=p.material,O={name:C.name||"",pbrMetallicRoughness:{baseColorFactor:[C.color.r,C.color.g,C.color.b,C.opacity],metallicFactor:C.metalness,roughnessFactor:C.roughness},doubleSided:C.side===2||C.doubleSided};if(C.emissive&&(C.emissive.r>0||C.emissive.g>0||C.emissive.b>0)){let V=C.emissiveIntensity??1;O.emissiveFactor=[C.emissive.r*V,C.emissive.g*V,C.emissive.b*V]}let F={};C.clearcoat>0&&(F.KHR_materials_clearcoat={clearcoatFactor:C.clearcoat,clearcoatRoughnessFactor:C.clearcoatRoughness||0}),C.sheen>0&&(F.KHR_materials_sheen={sheenColorFactor:C.sheenColor?[C.sheenColor.r,C.sheenColor.g,C.sheenColor.b]:[1,1,1],sheenRoughnessFactor:C.sheenRoughness||0}),C.transmission>0&&(F.KHR_materials_transmission={transmissionFactor:C.transmission}),C.thickness>0&&(F.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&&(F.KHR_materials_ior={ior:C.ior}),C.dispersion>0&&(F.KHR_materials_dispersion={dispersion:C.dispersion}),C.iridescence>0&&(F.KHR_materials_iridescence={iridescenceFactor:C.iridescence,iridescenceIor:C.iridescenceIOR??1.3}),Object.keys(F).length>0&&(O.extensions=F),a.push(O)}k.material=N}let U=c.length;c.push({primitives:[k],name:p.name,...E.extras?{extras:E.extras}:{}}),E.mesh=U}}let g=h.length;if(h.push(E),s.push(p),p.children.length>0){E.children=[];for(let T of p.children)E.children.push(A(T))}return g}for(let p of t.children)S.push(A(p));let M=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),P=[];if(typeof M=="function"&&s.length>0){let p=e?.duration??4,E=e?.fps??15,v=Math.max(2,Math.round(p*E)+1),_=new Float32Array(v),D=s.map(U=>({px:U.position.x,py:U.position.y,pz:U.position.z,qx:U.quaternion.x,qy:U.quaternion.y,qz:U.quaternion.z,qw:U.quaternion.w,sx:U.scale.x,sy:U.scale.y,sz:U.scale.z})),g=s.map(()=>new Float32Array(v*3)),T=s.map(()=>new Float32Array(v*4)),x=s.map(()=>new Float32Array(v*3));for(let U=0;U<v;U++){let N=U/(v-1)*p;_[U]=N;try{M(N)}catch{}for(let C=0;C<s.length;C++){let O=s[C];g[C][U*3]=O.position.x,g[C][U*3+1]=O.position.y,g[C][U*3+2]=O.position.z,T[C][U*4]=O.quaternion.x,T[C][U*4+1]=O.quaternion.y,T[C][U*4+2]=O.quaternion.z,T[C][U*4+3]=O.quaternion.w,x[C][U*3]=O.scale.x,x[C][U*3+1]=O.scale.y,x[C][U*3+2]=O.scale.z}}for(let U=0;U<s.length;U++){let N=s[U],C=D[U];N.position.set(C.px,C.py,C.pz),N.quaternion.set(C.qx,C.qy,C.qz,C.qw),N.scale.set(C.sx,C.sy,C.sz)}t.updateMatrixWorld(!0);let L=null,I=()=>(L===null&&(L=d(_,"SCALAR",0,5126,v,[0],[p])),L),H=[],k=[];for(let U=0;U<s.length;U++){let N=D[U],C=!1,O=!1,F=!1;for(let V=0;V<v;V++)(Math.abs(g[U][V*3]-N.px)>1e-4||Math.abs(g[U][V*3+1]-N.py)>1e-4||Math.abs(g[U][V*3+2]-N.pz)>1e-4)&&(C=!0),(Math.abs(T[U][V*4]-N.qx)>1e-4||Math.abs(T[U][V*4+1]-N.qy)>1e-4||Math.abs(T[U][V*4+2]-N.qz)>1e-4||Math.abs(T[U][V*4+3]-N.qw)>1e-4)&&(O=!0),(Math.abs(x[U][V*3]-N.sx)>1e-4||Math.abs(x[U][V*3+1]-N.sy)>1e-4||Math.abs(x[U][V*3+2]-N.sz)>1e-4)&&(F=!0);if(C){let V=d(g[U],"VEC3",0,5126,v),z=H.length;H.push({input:I(),interpolation:"LINEAR",output:V}),k.push({sampler:z,target:{node:U,path:"translation"}})}if(O){let V=d(T[U],"VEC4",0,5126,v),z=H.length;H.push({input:I(),interpolation:"LINEAR",output:V}),k.push({sampler:z,target:{node:U,path:"rotation"}})}if(F){let V=d(x[U],"VEC3",0,5126,v),z=H.length;H.push({input:I(),interpolation:"LINEAR",output:V}),k.push({sampler:z,target:{node:U,path:"scale"}})}}k.length>0&&P.push({name:"ProceduralLoop",samplers:H,channels:k})}let y=ot(h,c,t.userData),w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:S}],scene:0,nodes:h,meshes:c,materials:a,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...P.length>0?{animations:P}:{},...y||u.size>0?{extensionsUsed:[...y?["KHR_interactivity"]:[],...u]}:{},...y?{extensions:{KHR_interactivity:y}}:{}},b=new Uint8Array(r),R=0;for(let p of n)b.set(p,R),R+=p.byteLength;return{gltf:w,bin:b.buffer,lights:l,environmentIntensity:t.environmentIntensity}}function mt(t){return new TextEncoder().encode(t)}function He(t,e){let{gltf:n,bin:r}=Le(t,e),i=JSON.stringify(n),o=mt(i),c=(4-o.byteLength%4)%4,h=o.byteLength+c,u=20+h+8+r.byteLength,s=new Uint8Array(u),a=new DataView(s.buffer);a.setUint32(0,1179937895,!0),a.setUint32(4,2,!0),a.setUint32(8,u,!0),a.setUint32(12,h,!0),a.setUint32(16,1313821514,!0),s.set(o,20);for(let l=0;l<c;l++)s[20+o.byteLength+l]=32;let m=20+h;return a.setUint32(m,r.byteLength,!0),a.setUint32(m+4,5130562,!0),s.set(new Uint8Array(r),m+8),s}function Er(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let c=o.count,h=new Float32Array(c*3),u=r.matrixWorld.elements;for(let p=0;p<c;p++){let E=o.getX(p),v=o.getY(p),_=o.getZ(p);h[p*3]=u[0]*E+u[4]*v+u[8]*_+u[12],h[p*3+1]=u[1]*E+u[5]*v+u[9]*_+u[13],h[p*3+2]=u[2]*E+u[6]*v+u[10]*_+u[14]}let s;if(i.attributes.normal){let p=i.attributes.normal;s=new Float32Array(c*3);let E=new Float32Array(9);ce(E,u);for(let v=0;v<c;v++){let _=p.getX(v),D=p.getY(v),g=p.getZ(v),T=E[0]*_+E[3]*D+E[6]*g,x=E[1]*_+E[4]*D+E[7]*g,L=E[2]*_+E[5]*D+E[8]*g,I=Math.hypot(T,x,L)||1;s[v*3]=T/I,s[v*3+1]=x/I,s[v*3+2]=L/I}}let a;if(i.attributes.uv){let p=i.attributes.uv;a=new Float32Array(c*2);for(let E=0;E<c;E++)a[E*2]=p.getX(E),a[E*2+1]=p.getY(E)}let m;if(i.index)m=i.index.array;else{m=c>65535?new Uint32Array(c):new Uint16Array(c);for(let p=0;p<c;p++)m[p]=p}let l="DefaultMaterial",f=[.8,.8,.8],d=.5,S=.1,A=0,M=0,P=1.5,y=1,w=[0,0,0];if(r.material){let p=r.material;l=p.name||`Material_${n.length}`,p.color&&(f=[p.color.r,p.color.g,p.color.b]),typeof p.roughness=="number"&&(d=p.roughness),typeof p.metalness=="number"&&(S=p.metalness),typeof p.clearcoat=="number"&&(A=p.clearcoat),typeof p.clearcoatRoughness=="number"&&(M=p.clearcoatRoughness),typeof p.ior=="number"&&(P=p.ior);let E=typeof p.opacity=="number"?p.opacity:1,v=typeof p.transmission=="number"?p.transmission:0;if(y=E*(1-v),p.emissive&&(p.emissive.r>0||p.emissive.g>0||p.emissive.b>0)){let _=p.emissiveIntensity??1;w=[p.emissive.r*_,p.emissive.g*_,p.emissive.b*_]}}let b,R=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);if(typeof R=="function"){let p=e?.duration??4,E=e?.fps??4,v=Math.max(2,Math.round(p*E)+1),_=[],D=[],g=[],T=[],x=[r.position.x,r.position.y,r.position.z],L=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],I=[r.scale.x,r.scale.y,r.scale.z],H=!1;for(let k=0;k<v;k++){let U=k/(v-1)*p;_.push(U);try{R(U)}catch{}D.push([r.position.x,r.position.y,r.position.z]),g.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),T.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-x[0])>1e-4||Math.abs(r.position.y-x[1])>1e-4||Math.abs(r.position.z-x[2])>1e-4||Math.abs(r.quaternion.x-L[0])>1e-4||Math.abs(r.quaternion.y-L[1])>1e-4||Math.abs(r.quaternion.z-L[2])>1e-4||Math.abs(r.quaternion.w-L[3])>1e-4||Math.abs(r.scale.x-I[0])>1e-4)&&(H=!0)}r.position.set(x[0],x[1],x[2]),r.quaternion.set(L[0],L[1],L[2],L[3]),r.scale.set(I[0],I[1],I[2]),H&&(b={times:_,translations:D,rotations:g,scales:T})}n.push({name:r.name||`Mesh_${n.length}`,positions:h,indices:m,normals:s,uvs:a,materialName:l,color:f,roughness:d,metallic:S,clearcoat:A,clearcoatRoughness:M,ior:P,opacity:y,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:b})}}),n}function Dn(t){let e=[],n=t.gltf,r=t.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),o=n.accessors||[],c=n.bufferViews||[],h=n.materials||[],u=n.meshes||[],s=n.nodes||[];function a(f){let d=o[f];if(!d)throw new Error(`Accessor ${f} not found`);let S=c[d.bufferView||0],A=(S.byteOffset||0)+(d.byteOffset||0),M=S.byteLength||0,P=i.slice(A,A+M);return{acc:d,buffer:P}}let m=new Map;if(s.length>0){let f=ut(n);for(let d=0;d<f.length;d++)m.set(d,f[d])}function l(f,d,S,A){let M=u[f];if(!M)return;let P=new Float32Array(9);ce(P,d);for(let y=0;y<(M.primitives||[]).length;y++){let w=M.primitives[y],b=w.attributes?.POSITION;if(b===void 0)continue;let{acc:R,buffer:p}=a(b),E=new Float32Array(p,0,R.count*3),v=new Float32Array(E.length);for(let z=0;z<R.count;z++){let X=E[z*3],Y=E[z*3+1],$=E[z*3+2];v[z*3]=d[0]*X+d[4]*Y+d[8]*$+d[12],v[z*3+1]=d[1]*X+d[5]*Y+d[9]*$+d[13],v[z*3+2]=d[2]*X+d[6]*Y+d[10]*$+d[14]}let _,D=w.attributes?.NORMAL;if(D!==void 0){let{acc:z,buffer:X}=a(D),Y=new Float32Array(X,0,z.count*3);_=new Float32Array(Y.length);for(let $=0;$<z.count;$++){let ae=Y[$*3],ye=Y[$*3+1],K=Y[$*3+2],ge=P[0]*ae+P[3]*ye+P[6]*K,xe=P[1]*ae+P[4]*ye+P[7]*K,ve=P[2]*ae+P[5]*ye+P[8]*K,re=Math.hypot(ge,xe,ve)||1;_[$*3]=ge/re,_[$*3+1]=xe/re,_[$*3+2]=ve/re}}let g,T=w.attributes?.TEXCOORD_0;if(T!==void 0){let{acc:z,buffer:X}=a(T);g=new Float32Array(X,0,z.count*2)}let x;if(w.indices!==void 0){let{acc:z,buffer:X}=a(w.indices);z.componentType===5125?x=new Uint32Array(X,0,z.count):x=new Uint16Array(X,0,z.count);let Y=R.count;for(let $ of x)if($>=Y)throw new Error(`SecurityError: Index buffer value (${$}) out of vertex bounds [0, ${Y}).`)}else{let z=R.count;x=z>65535?new Uint32Array(z):new Uint16Array(z);for(let X=0;X<z;X++)x[X]=X}let L="DefaultMaterial",I=[.8,.8,.8],H=.5,k=.1,U=0,N=0,C=1.5,O=1,F=[0,0,0];if(w.material!==void 0&&h[w.material]){let z=h[w.material];L=z.name||`Material_${w.material}`;let X=z.pbrMetallicRoughness||{},Y=1;Array.isArray(X.baseColorFactor)&&(I=[X.baseColorFactor[0],X.baseColorFactor[1],X.baseColorFactor[2]],typeof X.baseColorFactor[3]=="number"&&(Y=X.baseColorFactor[3])),typeof X.roughnessFactor=="number"&&(H=X.roughnessFactor),typeof X.metallicFactor=="number"&&(k=X.metallicFactor),Array.isArray(z.emissiveFactor)&&z.emissiveFactor.length>=3&&(F=[z.emissiveFactor[0],z.emissiveFactor[1],z.emissiveFactor[2]]);let $=z.extensions||{};$.KHR_materials_clearcoat&&(U=$.KHR_materials_clearcoat.clearcoatFactor??0,N=$.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),$.KHR_materials_ior&&typeof $.KHR_materials_ior.ior=="number"&&(C=$.KHR_materials_ior.ior);let ae=$.KHR_materials_transmission?.transmissionFactor??0;O=Y*(1-ae)}let V=(M.primitives||[]).length>1?`${S}_p${y}`:S;e.push({name:V,positions:v,indices:x,normals:_,uvs:g,materialName:L,color:I,roughness:H,metallic:k,clearcoat:U,clearcoatRoughness:N,ior:C,opacity:O,emissiveColor:F,xrTraits:A?.xr||M.extras?.xr})}}if(s.length>0)for(let f=0;f<s.length;f++){let d=s[f];if(d.mesh!==void 0&&d.mesh<u.length){let S=m.get(f)||Z(),A=d.name||u[d.mesh].name||`Node_${f}`;l(d.mesh,S,A,d.extras)}}else{let f=Z();for(let d=0;d<u.length;d++){let S=u[d].name||`Mesh_${d}`;l(d,f,S,u[d].extras)}}return e}function Kt(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function _n(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function W(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}function Cn(t){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(t)}let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${W(t[r*3])}, ${W(t[r*3+1])}, ${W(t[r*3+2])})`;return n.join(", ")}function Sr(t,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(t)}let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${W(t[r*2])}, ${W(1-t[r*2+1])})`;return n.join(", ")}function Rr(t){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(t)}return Array.from(t).join(", ")}function Zt(t){let e=new Map;for(let u of t){let s=Kt(u.materialName,"DefaultMaterial");e.has(s)||e.set(s,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}let n=0,r=null;for(let u of t){if(u.timeSamples&&u.timeSamples.times.length>0){let s=u.timeSamples.times[u.timeSamples.times.length-1];s>n&&(n=s)}u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
|
|
209
|
-
endTimeCode = ${
|
|
251
|
+
void main(){fragColor=uColorId;}`;function Ur(t,e,n){let r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,35713)){let i=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function Qn(t,e,n){let r=Ur(t,35633,e),i=Ur(t,35632,n),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,35714)){let s=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${s}`)}return o}function Jn(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var zr=["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","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function Wr(){let t=_e().xrDepthShader;return{fs:Oi.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...zr,...t.uniformNames]:zr}}function Vi(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Kn(t,e,n,r,i,o,s,l){if(r===void 0||!e.accessors?.[r])return null;let a=Yn(e,n,e.accessors[r],o);if(!a)return null;l&&(a=a.slice(),Or(a,l));let c=t.createBuffer();return s.push(c),t.bindBuffer(34962,c),t.bufferData(34962,a,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),a}function qn(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function $r(t,e,n){let r=Wr(),i=Xr,o=r.fs,s=!1;for(let a of Ne)if(a.onResolveShader){let c=a.onResolveShader(e,n,i,o);c&&(i=c.vs,o=c.fs,s=!0)}let l=s?Qn(t,i,o):null;return{program:l,uniforms:l?Jn(t,l,r.uniforms):null}}function Bi(t,e,n){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let i=r.length>>4,o=e.instanceColors,s=new Float32Array(i*20);for(let a=0;a<i;a++)s.set(r.subarray(a*16,a*16+16),a*20),s[a*20+16]=o?o[a*3]:1,s[a*20+17]=o?o[a*3+1]:1,s[a*20+18]=o?o[a*3+2]:1,s[a*20+19]=1;let l=t.createBuffer();n.push(l),t.bindBuffer(34962,l),t.bufferData(34962,s,35044);for(let a=0;a<5;a++)t.enableVertexAttribArray(8+a),t.vertexAttribPointer(8+a,4,5126,!1,80,a*16),t.vertexAttribDivisor(8+a,1);return!0}function Gi(t,e){let n=t.materials?.[e?.material];if(!n)return null;let r=[n.pbrMetallicRoughness?.baseColorTexture,n.pbrMetallicRoughness?.metallicRoughnessTexture,n.normalTexture,n.occlusionTexture,n.emissiveTexture];for(let i of r){let o=i?.extensions?.KHR_texture_transform;if(o&&typeof o=="object")return o}return null}var Ms=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),jr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function cn(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function Yr(t,e){let n=t?.pbrMetallicRoughness,r=n?.baseColorFactor,i=t?.extensions?.KHR_materials_clearcoat,o=s=>s!==void 0&&e[s.index]?e[s.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:n?.metallicFactor??.1,roughness:n?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:o(n?.baseColorTexture),metallicRoughnessTexture:o(n?.metallicRoughnessTexture),normalTexture:o(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:o(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Kr(t,e,n){let r=new Set,i=o=>{o&&!r.has(o)&&(r.add(o),t.deleteTexture(o))};for(let o of e)for(let s of o.primitives){if(s.vao&&t.deleteVertexArray(s.vao),s.buffers)for(let a of s.buffers)t.deleteBuffer(a);i(s.texture),i(s.metallicRoughnessTexture),i(s.normalTexture),i(s.occlusionTexture);let l=new Set;s.customProgram&&l.add(s.customProgram);for(let a of s.programCache?.values()??[])a.program&&l.add(a.program);for(let a of l)t.deleteProgram(a)}if(n)for(let o of n)i(o)}function Vr(t,e,n=jr,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Hi(t,e,n,r,i)}catch(o){let s=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Kr(t,s,i.gpuTextures),i.vao&&t.deleteVertexArray(i.vao);for(let l of i.buffers)t.deleteBuffer(l);throw o}}function Hi(t,e,n,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:o}=e,s=Lt("meshopt");s?.decodeBufferViews&&s.decodeBufferViews(o,e);let l=e.bin,a=[];i.meshes=a;let c=[],u=o.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((v,f)=>{c.push(typeof v?.name=="string"&&v.name?v.name:`Variant_${f}`)});let d=an(o),h=[];if(Array.isArray(o.nodes))for(let v=0;v<o.nodes.length;v++){let f=o.nodes[v];f.mesh!==void 0&&o.meshes&&o.meshes[f.mesh]&&h.push({node:f,nodeIdx:v,meshIdx:f.mesh})}let m=h.length>0?h:(o.meshes||[]).map((v,f)=>({node:v,nodeIdx:-1,meshIdx:f})),y=[];if(Array.isArray(e.lights)&&e.lights.length>0)y.push(...e.lights);else if(o.extensions?.KHR_lights_punctual?.lights){let v=o.extensions.KHR_lights_punctual.lights;for(let f of v){let p=f.type==="directional"?"directional":f.type==="point"?"point":"ambient";y.push({type:p,color:f.color||[1,1,1],intensity:f.intensity!==void 0?f.intensity:1})}}if(y.length===0&&(y.push({type:"ambient",color:[1,1,1],intensity:.35}),y.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),m.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${m.length}`);let x=[];if(i.gpuTextures=x,o.textures&&o.images){if(o.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${o.textures.length}`);for(let v=0;v<o.textures.length;v++){let f=o.textures[v],p=o.images[f.source];if(p){let _=t.createTexture();if(t.bindTexture(3553,_),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),p.bufferView!==void 0){let H=o.bufferViews[p.bufferView],U=l.slice(H.byteOffset||0,(H.byteOffset||0)+H.byteLength),Q=new Blob([U],{type:p.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(Q).then($=>{t.bindTexture(3553,_),t.texImage2D(3553,0,6408,6408,5121,$),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(p.uri){let H=Vi(p.uri);if(H){let U=new Image;U.crossOrigin="anonymous",U.referrerPolicy="no-referrer",U.onload=()=>{t.bindTexture(3553,_),t.texImage2D(3553,0,6408,6408,5121,U),t.generateMipmap(3553),r?.()},U.src=H}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",p.uri)}x.push(_)}else x.push(null)}}let M=[1/0,1/0,1/0],L=[-1/0,-1/0,-1/0],F=0,g=0;for(let v=0;v<m.length;v++){let f=m[v],p=o.meshes[f.meshIdx],_=f.nodeIdx>=0?d[f.nodeIdx]:Ce(),H=new Float32Array(9);He(H,_);let U={name:f.node.name||p.name||`Mesh_${f.meshIdx}`,nodeIndex:f.nodeIdx,transform:_,normalMatrix:H,primitives:[],extras:f.node.extras||p.extras};i.mesh=U;let Q=f.node?.extensions?.EXT_mesh_gpu_instancing;if(Q&&Q.attributes&&typeof Q.attributes=="object"){let $=Q.attributes,K=$.TRANSLATION!==void 0?o.accessors?.[$.TRANSLATION]:null,P=$.ROTATION!==void 0?o.accessors?.[$.ROTATION]:null,ne=$.SCALE!==void 0?o.accessors?.[$.SCALE]:null,Z=$._COLOR_0!==void 0?o.accessors?.[$._COLOR_0]:null,q=Number(K?.count??P?.count??ne?.count??0);if(!Number.isFinite(q)||q<0||q>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${q}`);if(q>0){let ae=(pe,S)=>{if(!pe||pe.bufferView===void 0||!o.bufferViews?.[pe.bufferView])return null;let T=pe.componentType??5126,D=k=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${k})`),null);if(T!==5120&&T!==5121&&T!==5122&&T!==5123&&T!==5126)return D(`componentType ${T}`);if(!(Number(pe.count)>=q))return D(`count ${pe.count} < ${q}`);let A=null;try{A=Yn(o,l,{...pe,count:q},S)}catch{return D("out of bounds")}return!A||!A.every(Number.isFinite)?D("non-finite value"):A},V=ae(K,3),J=ae(P,4),ce=ae(ne,3),se=Z?.type==="VEC4"?4:3,fe=ae(Z,se),xe=new Float32Array(q*16),Se=Ce();for(let pe=0;pe<q;pe++){let S=V?[V[pe*3],V[pe*3+1],V[pe*3+2]]:[0,0,0],T=J?[J[pe*4],J[pe*4+1],J[pe*4+2],J[pe*4+3]]:[0,0,0,1],D=ce?[ce[pe*3],ce[pe*3+1],ce[pe*3+2]]:[1,1,1];xt(Se,T,S,D),xe.set(Se,pe*16)}if(U.instanceMatrices=xe,fe){let pe=new Float32Array(q*3);for(let S=0;S<q;S++)pe[S*3]=fe[S*se],pe[S*3+1]=fe[S*se+1],pe[S*3+2]=fe[S*se+2];U.instanceColors=pe}}}for(let $ of p.primitives||[]){if($.extensions?.KHR_draco_mesh_compression){let A=Lt("draco");A&&A.decodePrimitive(o,$,l)}let K=[],P=t.createVertexArray();i.vao=P,i.buffers=K,t.bindVertexArray(P);let ne=Bi(t,U,K),Z=o.accessors[$.attributes.POSITION],q=Number(Z?.count??0);if(!Number.isFinite(q)||q<0||F+q>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(F+=q,Z?.min&&Z?.max){let A=k=>{for(let O=0;O<3;O++){let B=k[12+O],X=k[12+O];for(let W=0;W<3;W++){let G=k[W*4+O]*Z.min[W],j=k[W*4+O]*Z.max[W];B+=G<j?G:j,X+=G>j?G:j}B<M[O]&&(M[O]=B),X>L[O]&&(L[O]=X)}};if(U.instanceMatrices&&U.instanceMatrices.length>=16){let k=U.instanceMatrices.length>>4,O=Ce();for(let B=0;B<k;B++){let X=U.instanceMatrices.subarray(B*16,B*16+16);Ie(O,_,X),A(O)}}else A(_)}let ae=Kn(t,o,l,$.attributes.POSITION,0,3,K);Kn(t,o,l,$.attributes.NORMAL,1,3,K),Kn(t,o,l,$.attributes.TEXCOORD_0,2,2,K,Gi(o,$));let V=0,J=5123,ce=null;if($.indices!==void 0){let A=o.accessors[$.indices],O=(o.bufferViews[A.bufferView].byteOffset||0)+(A.byteOffset||0);if(V=Number(A.count??0),!Number.isFinite(V)||V<0||g+V>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);g+=V,J=A.componentType===5125?5125||5125:5123||5123;let B=t.createBuffer();K.push(B),t.bindBuffer(34963,B),A.componentType===5125?(ce=new Uint32Array(l,O,A.count),t.bufferData(34963,ce,35044)):A.componentType===5121?(ce=Uint16Array.from(new Uint8Array(l,O,A.count)),t.bufferData(34963,ce,35044)):(ce=O%2===0?new Uint16Array(l,O,A.count):new Uint16Array(l.slice(O,O+A.count*2)),t.bufferData(34963,ce,35044))}else V=Z.count;let se={};for(let A of Ne)if(A.onBuildPrimitiveVAO){let k=A.onBuildPrimitiveVAO(t,P,$,o,l);k&&(se[A.name]=k)}t.bindVertexArray(null);let fe=o.materials&&$.material!==void 0?o.materials[$.material]:null,{program:xe,uniforms:Se}=$r(t,$,fe),pe=Yr(fe,x),S=!!(fe?.extensions?.KHR_materials_transmission||se.materials?.isTransmissive),T=$.extensions?.KHR_materials_variants?.mappings,D=Array.isArray(T)?T.filter(A=>A&&typeof A.material=="number"&&Array.isArray(A.variants)).map(A=>({material:A.material|0,variants:A.variants.map(k=>Number(k)|0)})):void 0;U.primitives.push({vao:P,instanced:ne,indexCount:V,indexType:J,...pe,positions:ae,indices:ce,buffers:K,materialIndex:$.material,defaultMaterialIndex:$.material,variantMappings:D,primitiveDef:$,programCache:new Map([[$.material??-1,{program:xe,uniforms:Se}]]),pluginData:se,customProgram:xe,customUniforms:Se,isTransmissive:S})}a.push(U)}isFinite(M[0])||(M=[-1,-1,-1]),isFinite(L[0])||(L=[1,1,1]);let E=[(M[0]+L[0])/2,(M[1]+L[1])/2,(M[2]+L[2])/2],w=L[0]-M[0],N=L[1]-M[1],z=L[2]-M[2],R=Math.max(Math.hypot(w,N,z)/2,.5),C=[M[0],M[1],M[2]],I=[L[0],L[1],L[2]],b=e.animations;if(!b){for(let v of Ne)if(v.onParseGLB?.(e),e.animations){b=e.animations;break}}return b||(b=[]),{meshes:a,bounds:{center:E,radius:R,min:C,max:I},lights:y,animations:b,worldMatrices:d,gpuTextures:x,availableVariants:c}}function Vt(t){let e=t.customTarget||t.bounds.center,n=t.currDistance*Math.cos(t.currPhi);return[e[0]+n*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+n*Math.cos(t.currTheta)]}var un=class{constructor(e,n,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=Ce();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=Ce();this.viewMatrix=Ce();this.activeViewMatrix=null;this.modelMatrix=Ce();this.mvpMatrix=Ce();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:Ce(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),i=a}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(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=qn(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=Zn(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 l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,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,n){Ni(e,n)}static getDecoder(e){return Lt(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=n=>{n.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,n=Wr();this.renderProg=Qn(e,Xr,n.fs),this.pickProg=Qn(e,Ui,zi),this.uRender=Jn(e,this.renderProg,n.uniforms),this.uPick=Jn(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let n of Ne)n.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 n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,n){this.lastGlbData=e,this.lastLimits=n;let{meshes:r,bounds:i,lights:o,animations:s,worldMatrices:l,gpuTextures:a,availableVariants:c}=Vr(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=s||[],this.worldMatrices=l||[],this.gpuTextures=a||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let h of e.gltf.nodes)this.initialNodeTransforms.push({t:h.translation?[h.translation[0],h.translation[1],h.translation[2]]:[0,0,0],r:h.rotation?[h.rotation[0],h.rotation[1],h.rotation[2],h.rotation[3]]:[0,0,0,1],s:h.scale?[h.scale[0],h.scale[1],h.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let h of Ne)h.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=qn(u));let d=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;d!==void 0&&(this.envIntensity=Math.max(0,Number(d)||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(Hr(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Bt(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Bt(e),{meshes:i}=Vr(this.gl,r,jr,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],He(o.normalMatrix,o.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,n,r,i=1){this.clearColor=[e,n,r,i]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;e instanceof Map?i=e.get(r.name)??e.get(n):Array.isArray(e)?i=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,n)&&(i=e[n])),i&&i.length===16&&(r.transform.set(i),He(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],s=[],l=[];for(let a of this.lights){let c=a.color||[1,1,1],u=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")r=[c[0]*u,c[1]*u,c[2]*u];else if(a.type==="directional"&&i.length<6){let d=a.direction||[.5,1,.8];i.push(d[0],d[1],d[2]),o.push(c[0]*u,c[1]*u,c[2]*u)}else if(a.type==="point"&&s.length<6){let d=a.position||[0,0,0];s.push(d[0],d[1],d[2]),l.push(c[0]*u,c[1]*u,c[2]*u)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,r),n.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(e.uDirLightDir,i),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,s.length/3),s.length>0&&(n.uniform3fv(e.uPointLightPos,s),n.uniform3fv(e.uPointLightColor,l)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=qn(e)}getExposure(){return this.exposure}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Zn(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of Ne)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of Ne)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:e,phi:n,radius:r,toString(){return`${e.toFixed(4)}rad ${n.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((n,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(d=>d.materialIndex===r||e.length===1&&d.materialIndex===void 0)),o=i[0],s=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,a=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:s,metallicFactor:l,roughnessFactor:a,setBaseColorFactor:u=>{let d=[u[0],u[1],u[2],u[3]??1];c.baseColorFactor=d,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=d);for(let h of i)h.baseColor=d;this.render()},setMetallicFactor:u=>{c.metallicFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=u);for(let d of i)d.metallic=u;this.render()},setRoughnessFactor:u=>{c.roughnessFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=u);for(let d of i)d.roughness=u;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:c}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(r=>r.name===e);n&&(this.currentClip=n)}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 n=this.applyVariantMaterial(e);return n&&this.gl&&this.render(),n}applyVariantMaterial(e){let n=e===null||e==="",r=-1;if(n)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return n;for(let o of this.meshes)for(let s of o.primitives){let l=s.defaultMaterialIndex;if(!n&&Array.isArray(s.variantMappings)){for(let c of s.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(r)){l=c.material;break}}let a=l!==void 0?i[l]:void 0;s.materialIndex=a?l:void 0,Object.assign(s,Yr(a,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,n,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=n??-1,o=e.programCache.get(i);o||(o=$r(this.gl,{...e.primitiveDef,material:n},r),e.programCache.set(i,o)),e.customProgram=o.program,e.customUniforms=o.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 n of Ne)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,r){this.customTarget=[e,n,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,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 n=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(n,Math.min(r,e))}setCamera(e,n,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,n,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}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,n){let r=Ce();Ie(r,this.projMatrix,this.viewMatrix);let[i,o,s]=e,l=n?n[0]:0,a=n?n[1]:0,c=n?n[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],o=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],s=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],n&&(l=u[0]*n[0]+u[4]*n[1]+u[8]*n[2],a=u[1]*n[0]+u[5]*n[1]+u[9]*n[2],c=u[2]*n[0]+u[6]*n[1]+u[10]*n[2]));let d=r[0]*i+r[4]*o+r[8]*s+r[12],h=r[1]*i+r[5]*o+r[9]*s+r[13],m=r[2]*i+r[6]*o+r[10]*s+r[14],y=r[3]*i+r[7]*o+r[11]*s+r[15];if(y<=1e-4)return{x:0,y:0,z:1,visible:!1};let x=d/y,M=h/y,L=m/y,F=this.canvas.getBoundingClientRect(),g=F.width||this.canvas.clientWidth||this.canvas.width||300,E=F.height||this.canvas.clientHeight||this.canvas.height||150,w=(x*.5+.5)*g,N=(-M*.5+.5)*E,z=x>=-1.1&&x<=1.1&&M>=-1.1&&M<=1.1&&L>=-1&&L<=1;if(z&&n){let[R,C,I]=Vt(this),b=[i-R,o-C,s-I];l*b[0]+a*b[1]+c*b[2]>.05&&(z=!1)}return{x:w,y:N,z:L,visible:z}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=n.clientX-r.x,o=n.clientY-r.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(i,o),this.isPanning||n.button===2||n.shiftKey||this.activePointers.size===2){let s=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],l=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*s[0]+o*l[0])*c,a[1]+=(-i*s[1]+o*l[1])*c,a[2]+=(-i*s[2]+o*l[2])*c,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=e.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(e.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let r=n.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=n=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextLost&&(e.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(e.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,s=r.height||300,l=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),a=i.height>0?Math.floor((n-i.top)*(s/i.height)):Math.floor(n);return this.performMeshPick(l,a,!1)}performMeshPick(e,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let l=Ce();Ie(l,this.projMatrix,this.viewMatrix);let a=[],c=Math.max(0,Math.min(o-1,e)),u=Math.max(0,Math.min(s-1,s-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==s)&&this.resizePickingFbo(o,s),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,s),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let z=0;z<this.meshes.length;z++){let R=this.meshes[z];if(R.visible===!1||R.isPluginMesh)continue;let C=z+1,I=(C&255)/255,b=(C>>8&255)/255,v=(C>>16&255)/255;i.uniform4f(this.uPick.uColorId,I,b,v,1),Ie(this.modelMatrix,this.modelRootMatrix,R.transform);let f=R.instanceMatrices;if(f&&f.length>=16){let p=f.length>>4,_=Ce();for(let H of R.primitives){i.bindVertexArray(H.vao);for(let U=0;U<p;U++)Ie(_,this.modelMatrix,f.subarray(U*16,U*16+16)),Ie(this.mvpMatrix,l,_),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),cn(i,H)}}else{Ie(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let p of R.primitives)i.bindVertexArray(p.vao),cn(i,p)}}let w=new Uint8Array(4);i.readPixels(c,u,1,1,6408,5121,w),i.bindFramebuffer(36160,null);let N=w[0]+(w[1]<<8)+(w[2]<<16);N>0&&N<=this.meshes.length&&(a=[this.meshes[N-1]])}a.length===0&&(a=this.meshes.filter(w=>w.visible!==!1));let d=null,h=1/0,m=[0,0,0],y=[0,1,0],[x,M,L]=Vt(this),F=Ce();for(let w of a){Ie(F,this.modelRootMatrix,w.transform);let N=w.instanceMatrices,z=N&&N.length>=16?N.length>>4:1;for(let R=0;R<z;R++){N&&N.length>=16?Ie(this.modelMatrix,F,N.subarray(R*16,R*16+16)):this.modelMatrix.set(F),Ie(this.mvpMatrix,l,this.modelMatrix);let C=Ce();if(!Nr(C,this.mvpMatrix))continue;let I=(c+.5)/o*2-1,b=(u+.5)/s*2-1,v=[0,0,0],f=[0,0,0];$n(v,I,b,-1,C),$n(f,I,b,1,C);let p=f[0]-v[0],_=f[1]-v[1],H=f[2]-v[2],U=Math.hypot(p,_,H)||1,Q=p/U,$=_/U,K=H/U,P={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((Z=>{for(let q of w.primitives){if(!q.positions)continue;let ae=q.positions,V=q.indices,J=Math.floor(V?V.length/3:ae.length/9);for(let ce=0;ce<J;ce++){let se=V?V[ce*3]:ce*3,fe=V?V[ce*3+1]:ce*3+1,xe=V?V[ce*3+2]:ce*3+2;Fr(v[0],v[1],v[2],Q,$,K,ae[se*3],ae[se*3+1],ae[se*3+2],ae[fe*3],ae[fe*3+1],ae[fe*3+2],ae[xe*3],ae[xe*3+1],ae[xe*3+2],P,Z)}}})(1e-4),isFinite(P.distance)){let Z=P.point[0],q=P.point[1],ae=P.point[2],V=this.modelMatrix,J=V[0]*Z+V[4]*q+V[8]*ae+V[12],ce=V[1]*Z+V[5]*q+V[9]*ae+V[13],se=V[2]*Z+V[6]*q+V[10]*ae+V[14],fe=J-x,xe=ce-M,Se=se-L,pe=Math.hypot(fe,xe,Se);if(pe<h){He(this.normalMatrix,this.modelMatrix);let S=this.normalMatrix,T=P.normal[0],D=P.normal[1],A=P.normal[2],k=S[0]*T+S[3]*D+S[6]*A,O=S[1]*T+S[4]*D+S[7]*A,B=S[2]*T+S[5]*D+S[8]*A,X=Math.hypot(k,O,B)||1;k/=X,O/=X,B/=X,k*fe+O*xe+B*Se>0&&(k=-k,O=-O,B=-B),d=w,h=Math.round(pe*1e3)/1e3,m=[Math.round(J*1e3)/1e3,Math.round(ce*1e3)/1e3,Math.round(se*1e3)/1e3],y=[Math.round(k*1e3)/1e3,Math.round(O*1e3)/1e3,Math.round(B*1e3)/1e3]}}}}if(!d)return null;let E={meshIndex:this.meshes.indexOf(d),meshName:d.name,nodeIndex:d.nodeIndex,distance:h,hitPoint:m,normal:y,screenX:e,screenY:n};if(r){for(let w of Ne)w.onMeshSelect?.(this,E);this.opts.onMeshClick&&this.opts.onMeshClick(E),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:E}))}return E}mapStereoPickX(e,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return e;let r=Math.max(1,Math.floor(n*.5)),i=e>=r,o=i?e-r:e,s=i?Math.max(1,n-r):r,l=(o+.5)/s*2-1;return Math.floor((l*.5+1)*.5*n)}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),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);sn(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center;It(this.viewMatrix,Vt(this),r,[0,1,0]),Ie(this.mvpMatrix,this.projMatrix,this.viewMatrix),He(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*e)),i=Math.max(1,Math.floor(n.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let n=this.xrSessionActive;if(this.xrSessionActive=e,n&&!e){this.xrDepthState.enabled=!1;for(let r of Ne)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let n of Ne)n.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=n=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((n-this.lastTime)/1e3,0),.1);if(this.lastTime=n,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+n*i),o[13]=0,o[14]=i-(-n*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let s of Ne)s.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let s of Ne)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 r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let s={theta:r,phi:i,zoom:o,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(e,n,r,i,o=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,u=c?[c.x,c.y,c.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:l,projMatrix:a,eyePos:u,viewport:i,eye:e?.eye||"none",clear:s>0?!1:e?.eye!=="right",isAR:o})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let g=Math.max(2,this.canvas.width||2),E=Math.max(1,this.canvas.height||1),w=Math.max(1,Math.floor(g*.5)),N=Math.max(1,g-w),z=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),R=this.customTarget||this.bounds.center,[C,I,b]=Vt(this),v=Math.cos(this.currTheta),f=-Math.sin(this.currTheta),p=.032,_=Ce(),H=Ce(),U=[C-v*p,I,b-f*p],Q=[R[0]-v*p*.25,R[1],R[2]-f*p*.25];sn(_,this.fov,w/E,.1,z),It(H,U,Q,[0,1,0]);let $=Ce(),K=Ce(),P=[C+v*p,I,b+f*p],ne=[R[0]+v*p*.25,R[1],R[2]+f*p*.25];sn($,this.fov,N/E,.1,z),It(K,P,ne,[0,1,0]),this.render({viewMatrix:H,projMatrix:_,eyePos:U,viewport:[0,0,w,E],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:K,projMatrix:$,eyePos:P,viewport:[w,0,N,E],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,g,E);return}let n=this.gl,r=0,i=0,o=this.canvas.width,s=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],s=e.viewport[3],n.viewport(r,i,o,s)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?n.clearColor(0,0,0,0):n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let l=Ce(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,Ie(l,e?.projMatrix??this.projMatrix,a);let c=_e().xrDepthShader,u=ki(this.toneMapping),[d,h,m]=e?e.eyePos:Vt(this);for(let g of Ne)g.onBeforeDrawScene?.(this,n,l,[d,h,m],u);let y=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&y===0)return;let x=e?.eye||"none",M=!1,L=y>0?[...this.backdropMeshes,...this.meshes]:this.meshes,F=g=>{for(let E=0;E<L.length;E++){let w=L[E];if(w.visible===!1)continue;let N=this.selectedMeshName!==""&&w.name===this.selectedMeshName;E<y||w.worldSpace===!0||w.name==="__xr_reticle__"?this.modelMatrix.set(w.transform):Ie(this.modelMatrix,this.modelRootMatrix,w.transform),Ie(this.mvpMatrix,l,this.modelMatrix),He(w.normalMatrix,this.modelMatrix);let z=w.extras?.xr?.stereo||w.userData?.xr?.stereo,R=0,C=0,I=1,b=1;z==="sbs"?(I=.5,R=x==="right"?.5:0):z==="ou"&&(b=.5,C=x==="right"?.5:0);for(let v of w.primitives){let f=!!v.isTransmissive;if(!g&&f){M=!0;continue}if(g&&!f)continue;let p=v.customProgram||this.renderProg,_=v.customUniforms||this.uRender;n.useProgram(p),n.uniform1i(_.uToneMapping,u),n.uniform1f(_.uEnvIntensity,this.envIntensity),_.uExposure&&n.uniform1f(_.uExposure,this.exposure),n.uniform3f(_.uCameraPos,d,h,m),n.uniform1f(_.uEmissive,N?1:0),n.uniformMatrix4fv(_.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(_.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(_.uNormalMatrix,!1,w.normalMatrix),_.uUvTransform&&n.uniform4f(_.uUvTransform,R,C,I,b),_.uViewportSize&&n.uniform2f(_.uViewportSize,Math.max(1,o),Math.max(1,s)),c?.bind(n,_,this.xrDepthState,a,[r,i,Math.max(1,o),Math.max(1,s)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(_.uEnvironmentMap,4),n.uniform1i(_.uHasEnvironmentMap,1)):n.uniform1i(_.uHasEnvironmentMap,0),this.bindLights(_),_.uSectionEnabled&&n.uniform1i(_.uSectionEnabled,0);for(let U of Ne)U.onBeforeDrawPrimitive?.(n,p,v,w,this.worldMatrices||[],this.gltf);n.uniform4fv(_.uBaseColor,v.baseColor),n.uniform1f(_.uMetallic,v.metallic),n.uniform1f(_.uRoughness,v.roughness),_.uClearcoat&&n.uniform2f(_.uClearcoat,v.clearcoat??0,v.clearcoatRoughness??.04),v.texture?(n.activeTexture(33984),n.bindTexture(3553,v.texture),n.uniform1i(_.uBaseColorTexture,0),n.uniform1i(_.uHasTexture,1)):n.uniform1i(_.uHasTexture,0),v.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,v.metallicRoughnessTexture),n.uniform1i(_.uMetallicRoughnessTexture,1),n.uniform1i(_.uHasMetallicRoughnessTexture,1)):n.uniform1i(_.uHasMetallicRoughnessTexture,0),v.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,v.normalTexture),n.uniform1i(_.uNormalTexture,2),n.uniform1i(_.uHasNormalTexture,1),n.uniform1f(_.uNormalScale,v.normalScale)):n.uniform1i(_.uHasNormalTexture,0),v.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,v.occlusionTexture),n.uniform1i(_.uOcclusionTexture,3),n.uniform1i(_.uHasOcclusionTexture,1),n.uniform1f(_.uOcclusionStrength,v.occlusionStrength)):n.uniform1i(_.uHasOcclusionTexture,0),n.bindVertexArray(v.vao);let H=w.instanceMatrices;if(H&&H.length>=16&&v.instanced&&_.uInstanced&&_.uViewProj){let U=H.length>>4;n.uniform1i(_.uInstanced,1),n.uniformMatrix4fv(_.uViewProj,!1,l),v.indices?n.drawElementsInstanced(4,v.indexCount,v.indexType,0,U):n.drawArraysInstanced(4,0,v.indexCount,U),n.uniform1i(_.uInstanced,0)}else if(H&&H.length>=16){let U=H.length>>4,Q=w.instanceColors,$=Ce(),K=new Float32Array(9),P=[v.baseColor[0],v.baseColor[1],v.baseColor[2],v.baseColor[3]];for(let ne=0;ne<U;ne++)Ie($,this.modelMatrix,H.subarray(ne*16,ne*16+16)),Ie(this.mvpMatrix,l,$),He(K,$),n.uniformMatrix4fv(_.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(_.uModel,!1,$),n.uniformMatrix3fv(_.uNormalMatrix,!1,K),Q&&(P[0]=v.baseColor[0]*Q[ne*3],P[1]=v.baseColor[1]*Q[ne*3+1],P[2]=v.baseColor[2]*Q[ne*3+2],P[3]=v.baseColor[3],n.uniform4fv(_.uBaseColor,P)),cn(n,v)}else cn(n,v)}}};if(F(!1),M){for(let g of Ne)g.onBeforeTransmissivePass?.(n,this);F(!0)}for(let g of Ne)g.onAfterRender?.(n,this,l)}disposeMeshListGpuResources(e,n){Kr(this.gl,e,n)}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 n of Ne)n.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()}};un.registerPlugin=Lr,un.getRegisteredPlugins=kr;function Xi(t){return t+3&-4}function Wi(t,e=0){let n=(P,ne)=>typeof P=="number"&&Number.isFinite(P)?P:ne,r=n(t[e+12],0),i=n(t[e+13],0),o=n(t[e+14],0),s=n(t[e+0],1),l=n(t[e+1],0),a=n(t[e+2],0),c=n(t[e+4],0),u=n(t[e+5],1),d=n(t[e+6],0),h=n(t[e+8],0),m=n(t[e+9],0),y=n(t[e+10],1),x=Math.hypot(s,l,a),M=Math.hypot(c,u,d),L=Math.hypot(h,m,y);s*(u*y-m*d)-c*(l*y-m*a)+h*(l*d-u*a)<0&&(x=-x);let g=Math.abs(x)>1e-8?1/x:0,E=Math.abs(M)>1e-8?1/M:0,w=Math.abs(L)>1e-8?1/L:0,N=s*g,z=l*g,R=a*g,C=c*E,I=u*E,b=d*E,v=h*w,f=m*w,p=y*w,_=N+I+p,H=0,U=0,Q=0,$=1;if(_>0){let P=.5/Math.sqrt(_+1);$=.25/P,H=(b-f)*P,U=(v-R)*P,Q=(z-C)*P}else if(N>I&&N>p){let P=2*Math.sqrt(Math.max(0,1+N-I-p));P>1e-8&&($=(b-f)/P,H=.25*P,U=(C+z)/P,Q=(v+R)/P)}else if(I>p){let P=2*Math.sqrt(Math.max(0,1+I-N-p));P>1e-8&&($=(v-R)/P,H=(C+z)/P,U=.25*P,Q=(b+f)/P)}else{let P=2*Math.sqrt(Math.max(0,1+p-N-I));P>1e-8&&($=(z-C)/P,H=(v+R)/P,U=(b+f)/P,Q=.25*P)}let K=Math.hypot(H,U,Q,$);return K>1e-8&&Number.isFinite(K)?(H/=K,U/=K,Q/=K,$/=K):(H=0,U=0,Q=0,$=1),{t:[r,i,o],r:[H,U,Q,$],s:[x,M,L]}}function $i(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}function kt(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],s=[],l=[],a=new Set,c=[],u=[],d=new Map,h=[],m=[];function y(C){let I=d.get(C);if(I!==void 0)return I;I=u.length,d.set(C,I);let b=C,v=b.color?.r??.8,f=b.color?.g??.8,p=b.color?.b??.8,_=b.opacity??1,H={name:b.name||"",pbrMetallicRoughness:{baseColorFactor:[v,f,p,_],metallicFactor:b.metalness??.1,roughnessFactor:b.roughness??.5},doubleSided:b.side===2||!!b.doubleSided};if(b.emissive&&(b.emissive.r>0||b.emissive.g>0||b.emissive.b>0)){let Q=b.emissiveIntensity??1;H.emissiveFactor=[b.emissive.r*Q,b.emissive.g*Q,b.emissive.b*Q]}let U={};return b.clearcoat&&b.clearcoat>0&&(U.KHR_materials_clearcoat={clearcoatFactor:b.clearcoat,clearcoatRoughnessFactor:b.clearcoatRoughness||0}),b.sheen&&b.sheen>0&&(U.KHR_materials_sheen={sheenColorFactor:b.sheenColor?[b.sheenColor.r,b.sheenColor.g,b.sheenColor.b]:[1,1,1],sheenRoughnessFactor:b.sheenRoughness||0}),b.transmission&&b.transmission>0&&(U.KHR_materials_transmission={transmissionFactor:b.transmission}),b.thickness&&b.thickness>0&&(U.KHR_materials_volume={thicknessFactor:b.thickness,attenuationDistance:b.attenuationDistance??1/0,attenuationColor:b.attenuationColor?[b.attenuationColor.r,b.attenuationColor.g,b.attenuationColor.b]:[1,1,1]}),b.ior!==void 0&&b.ior!==1.5&&(U.KHR_materials_ior={ior:b.ior}),b.dispersion&&b.dispersion>0&&(U.KHR_materials_dispersion={dispersion:b.dispersion}),b.iridescence&&b.iridescence>0&&(U.KHR_materials_iridescence={iridescenceFactor:b.iridescence,iridescenceIor:b.iridescenceIOR??1.3}),Object.keys(U).length>0&&(H.extensions=U),u.push(H),I}function x(C,I){let b=new Uint8Array(C.buffer,C.byteOffset,C.byteLength),v=Xi(b.byteLength),f=new Uint8Array(v);f.set(b),n.push(f);let p=i.length;return i.push({buffer:0,byteOffset:r,byteLength:b.byteLength,target:I}),r+=v,p}function M(C,I,b,v,f,p,_){let H=x(C,b),U=o.length,Q={bufferView:H,byteOffset:0,componentType:v,count:f,type:I};return p&&(Q.min=p),_&&(Q.max=_),o.push(Q),U}t.traverse(C=>{(C.isLight||C.color&&C.intensity!==void 0)&&m.push({type:C.type,color:[C.color.r,C.color.g,C.color.b],intensity:C.intensity,position:[C.position.x,C.position.y,C.position.z]})});let L=[];function F(C){let I={name:C.name||""},b=C.position,v=C.quaternion,f=C.scale;if((b.x||b.y||b.z)&&(I.translation=[b.x,b.y,b.z]),(v.x||v.y||v.z||v.w!==1)&&(I.rotation=[v.x,v.y,v.z,v.w]),(f.x!==1||f.y!==1||f.z!==1)&&(I.scale=[f.x,f.y,f.z]),C.userData&&Object.keys(C.userData).length>0&&(I.extras=JSON.parse(JSON.stringify(C.userData,(_,H)=>{if(!(_==="__proto__"||_==="prototype"||_==="constructor"))return typeof H=="function"?void 0:H})),C.userData.xr)){let _=$i(C.userData.xr);I.extensions={...I.extensions||{},MOZ_hubs_components:_,ANDROID_xr_scenecore:_},_e().xrTraitSerializer?.gltfNode(I,C.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(C.geometry){let _=C.geometry,H=_.attributes.position;if(H&&H.count>0){let U=[1/0,1/0,1/0],Q=[-1/0,-1/0,-1/0];for(let q=0;q<H.count;q++){let ae=H.getX(q),V=H.getY(q),J=H.getZ(q);ae<U[0]&&(U[0]=ae),ae>Q[0]&&(Q[0]=ae),V<U[1]&&(U[1]=V),V>Q[1]&&(Q[1]=V),J<U[2]&&(U[2]=J),J>Q[2]&&(Q[2]=J)}let K={attributes:{POSITION:M(H.array,"VEC3",34962,5126,H.count,U,Q)}};if(_.attributes.normal&&(K.attributes.NORMAL=M(_.attributes.normal.array,"VEC3",34962,5126,_.attributes.normal.count)),_.attributes.uv&&(K.attributes.TEXCOORD_0=M(_.attributes.uv.array,"VEC2",34962,5126,_.attributes.uv.count)),_.index){let q=_.index.array instanceof Uint32Array;K.indices=M(_.index.array,"SCALAR",34963,q?5125:5123,_.index.count)}C.material&&(K.material=y(C.material));let P=C.userData?.variants;if(P&&typeof P=="object"){let q=new Map;for(let ae of Object.keys(P)){if(!ae||ae==="__proto__"||ae==="constructor"||ae==="prototype")continue;let V=P[ae];if(!V||typeof V!="object")continue;let J=h.indexOf(ae);if(J===-1&&h.length<256&&(J=h.length,h.push(ae)),J===-1)continue;let ce=y(V),se=q.get(ce);se||(se=[],q.set(ce,se)),se.push(J)}if(q.size>0){let ae=[];for(let[V,J]of q.entries())ae.push({material:V,variants:J});K.extensions={...K.extensions||{},KHR_materials_variants:{mappings:ae}},a.add("KHR_materials_variants")}}let ne=C;if(ne.isInstancedMesh&&typeof ne.count=="number"&&ne.count>0&&ne.instanceMatrix?.array){let q=Math.min(1e4,Math.floor(ne.count)),ae=ne.instanceMatrix.array,V=new Float32Array(q*3),J=new Float32Array(q*4),ce=new Float32Array(q*3);for(let fe=0;fe<q;fe++){let{t:xe,r:Se,s:pe}=Wi(ae,fe*16);V[fe*3]=xe[0],V[fe*3+1]=xe[1],V[fe*3+2]=xe[2],J[fe*4]=Se[0],J[fe*4+1]=Se[1],J[fe*4+2]=Se[2],J[fe*4+3]=Se[3],ce[fe*3]=pe[0],ce[fe*3+1]=pe[1],ce[fe*3+2]=pe[2]}let se={TRANSLATION:M(V,"VEC3",0,5126,q),ROTATION:M(J,"VEC4",0,5126,q),SCALE:M(ce,"VEC3",0,5126,q)};if(ne.instanceColor?.array&&ne.instanceColor.array.length>=q*3){let fe=new Float32Array(ne.instanceColor.array.subarray(0,q*3));se._COLOR_0=M(fe,"VEC3",0,5126,q)}I.extensions={...I.extensions||{},EXT_mesh_gpu_instancing:{attributes:se}},a.add("EXT_mesh_gpu_instancing")}let Z=s.length;s.push({primitives:[K],name:C.name,...I.extras?{extras:I.extras}:{}}),I.mesh=Z}}let p=l.length;if(l.push(I),c.push(C),C.children.length>0){I.children=[];for(let _ of C.children)I.children.push(F(_))}return p}for(let C of t.children)L.push(F(C));let g=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),E=[];if(typeof g=="function"&&c.length>0){let C=e?.duration??4,I=e?.fps??15,b=Math.max(2,Math.round(C*I)+1),v=new Float32Array(b),f=c.map(P=>({px:P.position.x,py:P.position.y,pz:P.position.z,qx:P.quaternion.x,qy:P.quaternion.y,qz:P.quaternion.z,qw:P.quaternion.w,sx:P.scale.x,sy:P.scale.y,sz:P.scale.z})),p=c.map(()=>new Float32Array(b*3)),_=c.map(()=>new Float32Array(b*4)),H=c.map(()=>new Float32Array(b*3));for(let P=0;P<b;P++){let ne=P/(b-1)*C;v[P]=ne;try{g(ne)}catch{}for(let Z=0;Z<c.length;Z++){let q=c[Z];p[Z][P*3]=q.position.x,p[Z][P*3+1]=q.position.y,p[Z][P*3+2]=q.position.z,_[Z][P*4]=q.quaternion.x,_[Z][P*4+1]=q.quaternion.y,_[Z][P*4+2]=q.quaternion.z,_[Z][P*4+3]=q.quaternion.w,H[Z][P*3]=q.scale.x,H[Z][P*3+1]=q.scale.y,H[Z][P*3+2]=q.scale.z}}for(let P=0;P<c.length;P++){let ne=c[P],Z=f[P];ne.position.set(Z.px,Z.py,Z.pz),ne.quaternion.set(Z.qx,Z.qy,Z.qz,Z.qw),ne.scale.set(Z.sx,Z.sy,Z.sz)}t.updateMatrixWorld(!0);let U=null,Q=()=>(U===null&&(U=M(v,"SCALAR",0,5126,b,[0],[C])),U),$=[],K=[];for(let P=0;P<c.length;P++){let ne=f[P],Z=!1,q=!1,ae=!1;for(let V=0;V<b;V++)(Math.abs(p[P][V*3]-ne.px)>1e-4||Math.abs(p[P][V*3+1]-ne.py)>1e-4||Math.abs(p[P][V*3+2]-ne.pz)>1e-4)&&(Z=!0),(Math.abs(_[P][V*4]-ne.qx)>1e-4||Math.abs(_[P][V*4+1]-ne.qy)>1e-4||Math.abs(_[P][V*4+2]-ne.qz)>1e-4||Math.abs(_[P][V*4+3]-ne.qw)>1e-4)&&(q=!0),(Math.abs(H[P][V*3]-ne.sx)>1e-4||Math.abs(H[P][V*3+1]-ne.sy)>1e-4||Math.abs(H[P][V*3+2]-ne.sz)>1e-4)&&(ae=!0);if(Z){let V=M(p[P],"VEC3",0,5126,b),J=$.length;$.push({input:Q(),interpolation:"LINEAR",output:V}),K.push({sampler:J,target:{node:P,path:"translation"}})}if(q){let V=M(_[P],"VEC4",0,5126,b),J=$.length;$.push({input:Q(),interpolation:"LINEAR",output:V}),K.push({sampler:J,target:{node:P,path:"rotation"}})}if(ae){let V=M(H[P],"VEC3",0,5126,b),J=$.length;$.push({input:Q(),interpolation:"LINEAR",output:V}),K.push({sampler:J,target:{node:P,path:"scale"}})}}K.length>0&&E.push({name:"ProceduralLoop",samplers:$,channels:K})}let w=rn(l,s,t.userData),N={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:L}],scene:0,nodes:l,meshes:s,materials:u,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...E.length>0?{animations:E}:{},...w||a.size>0?{extensionsUsed:[...w?["KHR_interactivity"]:[],...a]}:{},...w||h.length>0?{extensions:{...w?{KHR_interactivity:w}:{},...h.length>0?{KHR_materials_variants:{variants:h.map(C=>({name:C}))}}:{}}}:{}},z=new Uint8Array(r),R=0;for(let C of n)z.set(C,R),R+=C.byteLength;return{gltf:N,bin:z.buffer,lights:m,environmentIntensity:t.environmentIntensity}}function hn(t){return new TextEncoder().encode(t)}function Gt(t,e){let{gltf:n,bin:r}=kt(t,e),i=JSON.stringify(n),o=hn(i),s=(4-o.byteLength%4)%4,l=o.byteLength+s,a=20+l+8+r.byteLength,c=new Uint8Array(a),u=new DataView(c.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,a,!0),u.setUint32(12,l,!0),u.setUint32(16,1313821514,!0),c.set(o,20);for(let h=0;h<s;h++)c[20+o.byteLength+h]=32;let d=20+l;return u.setUint32(d,r.byteLength,!0),u.setUint32(d+4,5130562,!0),c.set(new Uint8Array(r),d+8),c}function ji(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let s=o.count,l=new Float32Array(s*3),a=r.matrixWorld.elements;for(let R=0;R<s;R++){let C=o.getX(R),I=o.getY(R),b=o.getZ(R);l[R*3]=a[0]*C+a[4]*I+a[8]*b+a[12],l[R*3+1]=a[1]*C+a[5]*I+a[9]*b+a[13],l[R*3+2]=a[2]*C+a[6]*I+a[10]*b+a[14]}let c;if(i.attributes.normal){let R=i.attributes.normal;c=new Float32Array(s*3);let C=new Float32Array(9);He(C,a);for(let I=0;I<s;I++){let b=R.getX(I),v=R.getY(I),f=R.getZ(I),p=C[0]*b+C[3]*v+C[6]*f,_=C[1]*b+C[4]*v+C[7]*f,H=C[2]*b+C[5]*v+C[8]*f,U=Math.hypot(p,_,H)||1;c[I*3]=p/U,c[I*3+1]=_/U,c[I*3+2]=H/U}}let u;if(i.attributes.uv){let R=i.attributes.uv;u=new Float32Array(s*2);for(let C=0;C<s;C++)u[C*2]=R.getX(C),u[C*2+1]=R.getY(C)}let d;if(i.index)d=i.index.array;else{d=s>65535?new Uint32Array(s):new Uint16Array(s);for(let R=0;R<s;R++)d[R]=R}let h="DefaultMaterial",m=[.8,.8,.8],y=.5,x=.1,M=0,L=0,F=1.5,g=1,E=[0,0,0];if(r.material){let R=r.material;h=R.name||`Material_${n.length}`,R.color&&(m=[R.color.r,R.color.g,R.color.b]),typeof R.roughness=="number"&&(y=R.roughness),typeof R.metalness=="number"&&(x=R.metalness),typeof R.clearcoat=="number"&&(M=R.clearcoat),typeof R.clearcoatRoughness=="number"&&(L=R.clearcoatRoughness),typeof R.ior=="number"&&(F=R.ior);let C=typeof R.opacity=="number"?R.opacity:1,I=typeof R.transmission=="number"?R.transmission:0;if(g=C*(1-I),R.emissive&&(R.emissive.r>0||R.emissive.g>0||R.emissive.b>0)){let b=R.emissiveIntensity??1;E=[R.emissive.r*b,R.emissive.g*b,R.emissive.b*b]}}let w,N=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);if(typeof N=="function"){let R=e?.duration??4,C=e?.fps??4,I=Math.max(2,Math.round(R*C)+1),b=[],v=[],f=[],p=[],_=[r.position.x,r.position.y,r.position.z],H=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],U=[r.scale.x,r.scale.y,r.scale.z],Q=!1;for(let $=0;$<I;$++){let K=$/(I-1)*R;b.push(K);try{N(K)}catch{}v.push([r.position.x,r.position.y,r.position.z]),f.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),p.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-_[0])>1e-4||Math.abs(r.position.y-_[1])>1e-4||Math.abs(r.position.z-_[2])>1e-4||Math.abs(r.quaternion.x-H[0])>1e-4||Math.abs(r.quaternion.y-H[1])>1e-4||Math.abs(r.quaternion.z-H[2])>1e-4||Math.abs(r.quaternion.w-H[3])>1e-4||Math.abs(r.scale.x-U[0])>1e-4)&&(Q=!0)}r.position.set(_[0],_[1],_[2]),r.quaternion.set(H[0],H[1],H[2],H[3]),r.scale.set(U[0],U[1],U[2]),Q&&(w={times:b,translations:v,rotations:f,scales:p})}let z=r;if(z.isInstancedMesh&&typeof z.count=="number"&&z.count>0&&z.instanceMatrix?.array){let R=Math.min(1e3,Math.floor(z.count)),C=z.instanceMatrix.array,I=z.instanceColor?.array,b=r.name||`Mesh_${n.length}`,v=new Float32Array(16),f=new Float32Array(9);for(let p=0;p<R;p++){let _=C.subarray(p*16,(p+1)*16);Ie(v,a,_);let H=new Float32Array(s*3);for(let K=0;K<s;K++){let P=o.getX(K),ne=o.getY(K),Z=o.getZ(K);H[K*3]=v[0]*P+v[4]*ne+v[8]*Z+v[12],H[K*3+1]=v[1]*P+v[5]*ne+v[9]*Z+v[13],H[K*3+2]=v[2]*P+v[6]*ne+v[10]*Z+v[14]}let U;if(i.attributes.normal){let K=i.attributes.normal;U=new Float32Array(s*3),He(f,v);for(let P=0;P<s;P++){let ne=K.getX(P),Z=K.getY(P),q=K.getZ(P),ae=f[0]*ne+f[3]*Z+f[6]*q,V=f[1]*ne+f[4]*Z+f[7]*q,J=f[2]*ne+f[5]*Z+f[8]*q,ce=Math.hypot(ae,V,J)||1;U[P*3]=ae/ce,U[P*3+1]=V/ce,U[P*3+2]=J/ce}}let Q=m,$=h;I&&I.length>=(p+1)*3&&(Q=[m[0]*I[p*3],m[1]*I[p*3+1],m[2]*I[p*3+2]],$=`${h}_inst_${p}`),n.push({name:`${b}_${p}`,positions:H,indices:d,normals:U,uvs:u,materialName:$,color:Q,roughness:y,metallic:x,clearcoat:M,clearcoatRoughness:L,ior:F,opacity:g,emissiveColor:E,xrTraits:r.userData?.xr})}return}n.push({name:r.name||`Mesh_${n.length}`,positions:l,indices:d,normals:c,uvs:u,materialName:h,color:m,roughness:y,metallic:x,clearcoat:M,clearcoatRoughness:L,ior:F,opacity:g,emissiveColor:E,xrTraits:r.userData?.xr,timeSamples:w})}}),n}function Qr(t){let e=[],n=t.gltf,r=_e().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(n,t);let i=t.bin,o=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),s=n.accessors||[],l=n.bufferViews||[],a=n.materials||[],c=n.meshes||[],u=n.nodes||[];function d(y){let x=s[y];if(!x)throw new Error(`Accessor ${y} not found`);let M=l[x.bufferView||0],L=(M.byteOffset||0)+(x.byteOffset||0),F=M.byteLength||0,g=o.slice(L,L+F);return{acc:x,buffer:g}}let h=new Map;if(u.length>0){let y=an(n);for(let x=0;x<y.length;x++)h.set(x,y[x])}function m(y,x,M,L){let F=c[y];if(!F)return;let g=new Float32Array(9);He(g,x);for(let E=0;E<(F.primitives||[]).length;E++){let w=F.primitives[E],N=w.attributes?.POSITION;if(N===void 0)continue;let{acc:z,buffer:R}=d(N),C=new Float32Array(R,0,z.count*3),I=new Float32Array(C.length);for(let V=0;V<z.count;V++){let J=C[V*3],ce=C[V*3+1],se=C[V*3+2];I[V*3]=x[0]*J+x[4]*ce+x[8]*se+x[12],I[V*3+1]=x[1]*J+x[5]*ce+x[9]*se+x[13],I[V*3+2]=x[2]*J+x[6]*ce+x[10]*se+x[14]}let b,v=w.attributes?.NORMAL;if(v!==void 0){let{acc:V,buffer:J}=d(v),ce=new Float32Array(J,0,V.count*3);b=new Float32Array(ce.length);for(let se=0;se<V.count;se++){let fe=ce[se*3],xe=ce[se*3+1],Se=ce[se*3+2],pe=g[0]*fe+g[3]*xe+g[6]*Se,S=g[1]*fe+g[4]*xe+g[7]*Se,T=g[2]*fe+g[5]*xe+g[8]*Se,D=Math.hypot(pe,S,T)||1;b[se*3]=pe/D,b[se*3+1]=S/D,b[se*3+2]=T/D}}let f,p=w.attributes?.TEXCOORD_0;if(p!==void 0){let{acc:V,buffer:J}=d(p);f=new Float32Array(J,0,V.count*2)}let _;if(w.indices!==void 0){let{acc:V,buffer:J}=d(w.indices);V.componentType===5125?_=new Uint32Array(J,0,V.count):_=new Uint16Array(J,0,V.count);let ce=z.count;for(let se of _)if(se>=ce)throw new Error(`SecurityError: Index buffer value (${se}) out of vertex bounds [0, ${ce}).`)}else{let V=z.count;_=V>65535?new Uint32Array(V):new Uint16Array(V);for(let J=0;J<V;J++)_[J]=J}let H="DefaultMaterial",U=[.8,.8,.8],Q=.5,$=.1,K=0,P=0,ne=1.5,Z=1,q=[0,0,0];if(w.material!==void 0&&a[w.material]){let V=a[w.material];H=V.name||`Material_${w.material}`;let J=V.pbrMetallicRoughness||{},ce=1;Array.isArray(J.baseColorFactor)&&(U=[J.baseColorFactor[0],J.baseColorFactor[1],J.baseColorFactor[2]],typeof J.baseColorFactor[3]=="number"&&(ce=J.baseColorFactor[3])),typeof J.roughnessFactor=="number"&&(Q=J.roughnessFactor),typeof J.metallicFactor=="number"&&($=J.metallicFactor),Array.isArray(V.emissiveFactor)&&V.emissiveFactor.length>=3&&(q=[V.emissiveFactor[0],V.emissiveFactor[1],V.emissiveFactor[2]]);let se=V.extensions||{};se.KHR_materials_clearcoat&&(K=se.KHR_materials_clearcoat.clearcoatFactor??0,P=se.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),se.KHR_materials_ior&&typeof se.KHR_materials_ior.ior=="number"&&(ne=se.KHR_materials_ior.ior);let fe=se.KHR_materials_transmission?.transmissionFactor??0;Z=ce*(1-fe)}let ae=(F.primitives||[]).length>1?`${M}_p${E}`:M;e.push({name:ae,positions:I,indices:_,normals:b,uvs:f,materialName:H,color:U,roughness:Q,metallic:$,clearcoat:K,clearcoatRoughness:P,ior:ne,opacity:Z,emissiveColor:q,xrTraits:L?.xr||F.extras?.xr})}}if(u.length>0)for(let y=0;y<u.length;y++){let x=u[y];if(x.mesh!==void 0&&x.mesh<c.length){let M=h.get(y)||Ce(),L=x.name||c[x.mesh].name||`Node_${y}`,F=x.extensions?.EXT_mesh_gpu_instancing?.attributes;if(F&&typeof F=="object"){let g=F.TRANSLATION,E=F.ROTATION,w=F.SCALE,N=g!==void 0?(()=>{let{acc:I,buffer:b}=d(g);return new Float32Array(b,0,I.count*3)})():null,z=E!==void 0?(()=>{let{acc:I,buffer:b}=d(E);return new Float32Array(b,0,I.count*4)})():null,R=w!==void 0?(()=>{let{acc:I,buffer:b}=d(w);return new Float32Array(b,0,I.count*3)})():null,C=Math.min(1e3,N?N.length/3:z?z.length/4:R?R.length/3:0);if(C>0){let I=new Float32Array(16),b=new Float32Array(16);for(let v=0;v<C;v++){let f=N?[N[v*3],N[v*3+1],N[v*3+2]]:[0,0,0],p=z?[z[v*4],z[v*4+1],z[v*4+2],z[v*4+3]]:[0,0,0,1],_=R?[R[v*3],R[v*3+1],R[v*3+2]]:[1,1,1];xt(I,p,f,_),Ie(b,M,I),m(x.mesh,b,`${L}_${v}`,x.extras)}continue}}m(x.mesh,M,L,x.extras)}}else{let y=Ce();for(let x=0;x<c.length;x++){let M=c[x].name||`Mesh_${x}`;m(x,y,M,c[x].extras)}}return e}function er(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function qr(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ge(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}function Zr(t){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(t)}let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${ge(t[r*3])}, ${ge(t[r*3+1])}, ${ge(t[r*3+2])})`;return n.join(", ")}function Yi(t,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(t)}let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${ge(t[r*2])}, ${ge(1-t[r*2+1])})`;return n.join(", ")}function Ki(t){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(t)}return Array.from(t).join(", ")}function tr(t){let e=new Map;for(let a of t){let c=er(a.materialName,"DefaultMaterial");e.has(c)||e.set(c,{color:a.color||[.8,.8,.8],roughness:a.roughness??.5,metallic:a.metallic??0,clearcoat:a.clearcoat??0,clearcoatRoughness:a.clearcoatRoughness??0,ior:a.ior??1.5,opacity:a.opacity??1,emissiveColor:a.emissiveColor||[0,0,0]})}let n=0,r=null;for(let a of t){if(a.timeSamples&&a.timeSamples.times.length>0){let c=a.timeSamples.times[a.timeSamples.times.length-1];c>n&&(n=c)}a.xrTraits?.anchor&&!r&&(r=a.xrTraits.anchor==="vertical"||a.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
|
|
252
|
+
endTimeCode = ${ge(n)}
|
|
210
253
|
timeCodesPerSecond = 1.0
|
|
211
254
|
`);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
|
|
212
255
|
uniform token preliminary:planeAnchoring:alignment = "${r}"
|
|
213
|
-
`);let
|
|
256
|
+
`);let s=`#usda 1.0
|
|
214
257
|
(
|
|
215
258
|
defaultPrim = "Root"
|
|
216
259
|
metersPerUnit = 1.0
|
|
@@ -223,61 +266,61 @@ kind = "component"
|
|
|
223
266
|
{
|
|
224
267
|
${o}def Scope "Materials"
|
|
225
268
|
{
|
|
226
|
-
`;for(let[
|
|
227
|
-
`,
|
|
228
|
-
`),
|
|
229
|
-
`),
|
|
230
|
-
`),(
|
|
231
|
-
`),
|
|
269
|
+
`;for(let[a,c]of e.entries()){let[u,d,h]=c.color,[m,y,x]=c.emissiveColor,M="";c.clearcoat>0&&(M+=`float inputs:clearcoat = ${ge(c.clearcoat)}
|
|
270
|
+
`,M+=`float inputs:clearcoatRoughness = ${ge(c.clearcoatRoughness)}
|
|
271
|
+
`),c.ior!==1.5&&(M+=`float inputs:ior = ${ge(c.ior)}
|
|
272
|
+
`),c.opacity<1&&(M+=`float inputs:opacity = ${ge(c.opacity)}
|
|
273
|
+
`),(m>0||y>0||x>0)&&(M+=`color3f inputs:emissiveColor = (${ge(m)}, ${ge(y)}, ${ge(x)})
|
|
274
|
+
`),s+=`def Material "${a}"
|
|
232
275
|
{
|
|
233
276
|
def Shader "PBRShader"
|
|
234
277
|
{
|
|
235
278
|
uniform token info:id = "UsdPreviewSurface"
|
|
236
|
-
color3f inputs:diffuseColor = (${
|
|
237
|
-
float inputs:metallic = ${
|
|
238
|
-
float inputs:roughness = ${
|
|
239
|
-
${
|
|
279
|
+
color3f inputs:diffuseColor = (${ge(u)}, ${ge(d)}, ${ge(h)})
|
|
280
|
+
float inputs:metallic = ${ge(c.metallic)}
|
|
281
|
+
float inputs:roughness = ${ge(c.roughness)}
|
|
282
|
+
${M}token outputs:surface
|
|
240
283
|
}
|
|
241
|
-
token outputs:surface.connect = </Root/Materials/${
|
|
284
|
+
token outputs:surface.connect = </Root/Materials/${a}/PBRShader.outputs:surface>
|
|
242
285
|
}
|
|
243
|
-
`}
|
|
286
|
+
`}s+=`}
|
|
244
287
|
def Scope "Meshes"
|
|
245
288
|
{
|
|
246
|
-
`;let
|
|
289
|
+
`;let l=new Set;for(let a=0;a<t.length;a++){let c=t[a],u=c.positions.length/3,d=1/0,h=1/0,m=1/0,y=-1/0,x=-1/0,M=-1/0;for(let z=0;z<u;z++){let R=c.positions[z*3],C=c.positions[z*3+1],I=c.positions[z*3+2];R<d&&(d=R),R>y&&(y=R),C<h&&(h=C),C>x&&(x=C),I<m&&(m=I),I>M&&(M=I)}isFinite(d)||(d=h=m=-1,y=x=M=1);let L=Math.floor(c.indices.length/3),F=er(c.materialName,"DefaultMaterial"),g=er(c.name,`Mesh_${a}`);l.has(g)&&(g=`${g}_${a}`),l.add(g);let E=L>0?L===1?"3":"3, ".repeat(L-1)+"3":"",w=c.xrTraits,N="";if(w){let z=[];w.physics&&w.physics!=="none"&&z.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let R=_e().xrTraitSerializer?.usdLines(w,qr)??[];if(!R.length)for(let C of["grab","billboard","follow","anchor","physics"]){let I=C==="follow"&&typeof w.follow=="object"?w.follow.mode??"head":w[C];I!==void 0&&R.push(`string ${C} = "${qr(I)}"`)}R.length>0&&z.push(`customData = {
|
|
247
290
|
dictionary xr = {
|
|
248
|
-
${
|
|
291
|
+
${R.join(`
|
|
249
292
|
`)}
|
|
250
293
|
}
|
|
251
|
-
}`),
|
|
252
|
-
${
|
|
294
|
+
}`),z.length>0&&(N=` (
|
|
295
|
+
${z.join(`
|
|
253
296
|
`)}
|
|
254
|
-
)`)}if(
|
|
297
|
+
)`)}if(s+=`def Mesh "${g}"${N}
|
|
255
298
|
{
|
|
256
|
-
`,
|
|
257
|
-
bool physics:kinematicEnabled = ${
|
|
299
|
+
`,w?.physics&&w.physics!=="none"){let z=w.physics==="static"?"true":"false";s+=`bool physics:rigidBodyEnabled = true
|
|
300
|
+
bool physics:kinematicEnabled = ${z}
|
|
258
301
|
bool physics:collisionEnabled = true
|
|
259
|
-
`}if(
|
|
260
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
261
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
302
|
+
`}if(c.timeSamples&&c.timeSamples.times.length>0){let z=c.timeSamples,R=z.times.map((b,v)=>{let f=z.translations?.[v]||[0,0,0];return`${ge(b)}: (${ge(f[0])}, ${ge(f[1])}, ${ge(f[2])})`}).join(", "),C=z.times.map((b,v)=>{let f=z.rotations?.[v]||[0,0,0,1];return`${ge(b)}: (${ge(f[3])}, ${ge(f[0])}, ${ge(f[1])}, ${ge(f[2])})`}).join(", "),I=z.times.map((b,v)=>{let f=z.scales?.[v]||[1,1,1];return`${ge(b)}: (${ge(f[0])}, ${ge(f[1])}, ${ge(f[2])})`}).join(", ");s+=`double3 xformOp:translate.timeSamples = { ${R} }
|
|
303
|
+
quatf xformOp:orient.timeSamples = { ${C} }
|
|
304
|
+
double3 xformOp:scale.timeSamples = { ${I} }
|
|
262
305
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
263
|
-
`}
|
|
264
|
-
int[] faceVertexCounts = [${
|
|
265
|
-
int[] faceVertexIndices = [${
|
|
266
|
-
point3f[] points = [${
|
|
267
|
-
`,
|
|
306
|
+
`}s+=`float3[] extent = [(${ge(d)}, ${ge(h)}, ${ge(m)}), (${ge(y)}, ${ge(x)}, ${ge(M)})]
|
|
307
|
+
int[] faceVertexCounts = [${E}]
|
|
308
|
+
int[] faceVertexIndices = [${Ki(c.indices)}]
|
|
309
|
+
point3f[] points = [${Zr(c.positions)}]
|
|
310
|
+
`,c.normals&&c.normals.length===c.positions.length&&(s+=`normal3f[] normals = [${Zr(c.normals)}] (
|
|
268
311
|
interpolation = "vertex"
|
|
269
312
|
)
|
|
270
|
-
`),
|
|
313
|
+
`),c.uvs&&c.uvs.length===u*2&&(s+=`texCoord2f[] primvars:st = [${Yi(c.uvs,u)}] (
|
|
271
314
|
interpolation = "vertex"
|
|
272
315
|
)
|
|
273
|
-
`),
|
|
316
|
+
`),s+=`rel material:binding = </Root/Materials/${F}>
|
|
274
317
|
}
|
|
275
|
-
`}return
|
|
318
|
+
`}return s+=`}
|
|
276
319
|
}
|
|
277
|
-
`,c}function Mr(t,e){if(t&&typeof t.traverse=="function"){let i=Er(t,e);return Zt(i)}let n=Ve(t),r=Dn(n);return Zt(r)}var ht=null;function Ar(t){{let n=globalThis.__three_live_native_crc32__;if(typeof n=="function")return n(t)}if(!ht){ht=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;ht[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=ht[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function In(t){{let a=globalThis.__three_live_native_build_usdz_zip__;if(typeof a=="function")return a(t)}let e=[],n=0,r=[];for(let a of t){let m=mt(a.filename),l=Ar(a.data),f=a.data.length,d=30+m.length,S=n+d,A=0,M=S%64;M!==0&&(A=64-M);let P=new Uint8Array(d+A),y=new DataView(P.buffer);y.setUint32(0,67324752,!0),y.setUint16(4,20,!0),y.setUint16(6,0,!0),y.setUint16(8,0,!0),y.setUint16(10,0,!0),y.setUint16(12,0,!0),y.setUint32(14,l,!0),y.setUint32(18,f,!0),y.setUint32(22,f,!0),y.setUint16(26,m.length,!0),y.setUint16(28,A,!0),P.set(m,30),A>0&&P.fill(0,30+m.length),e.push({offset:n,size:f,crc:l,filenameBytes:m,entry:a}),r.push(P),r.push(a.data),n+=P.length+a.data.length}let i=n;for(let a of e){let m=new Uint8Array(46+a.filenameBytes.length),l=new DataView(m.buffer);l.setUint32(0,33639248,!0),l.setUint16(4,20,!0),l.setUint16(6,20,!0),l.setUint16(8,0,!0),l.setUint16(10,0,!0),l.setUint16(12,0,!0),l.setUint16(14,0,!0),l.setUint32(16,a.crc,!0),l.setUint32(20,a.size,!0),l.setUint32(24,a.size,!0),l.setUint16(28,a.filenameBytes.length,!0),l.setUint16(30,0,!0),l.setUint16(32,0,!0),l.setUint16(34,0,!0),l.setUint16(36,0,!0),l.setUint32(38,0,!0),l.setUint32(42,a.offset,!0),m.set(a.filenameBytes,46),r.push(m),n+=m.length}let o=n-i,c=new Uint8Array(22),h=new DataView(c.buffer);h.setUint32(0,101010256,!0),h.setUint16(4,0,!0),h.setUint16(6,0,!0),h.setUint16(8,e.length,!0),h.setUint16(10,e.length,!0),h.setUint32(12,o,!0),h.setUint32(16,i,!0),h.setUint16(20,0,!0),r.push(c),n+=22;let u=new Uint8Array(n),s=0;for(let a of r)u.set(a,s),s+=a.length;return u}function Ue(t){let e=Mr(t),n=mt(e);return In([{filename:"model.usda",data:n}])}function dt(t){let e=Ve(t),n=Dn(e),r=Zt(n),i=mt(r);return In([{filename:"model.usda",data:i}])}function Jt(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?Ue(t):dt(t)}function B(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function Ee(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function q(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function he(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function _r(t){let e=q(t);if(!e||e.lazy===!1)return null;let n=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=n!=="head";return{mode:n,lazy:!0,distance:B(e.distance,.1,10,r?.15:1),deadzoneDeg:B(e.deadzoneDeg,0,90,r?0:15),stiffness:B(e.stiffness,.5,40,6),height:B(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function Cr(t){let e=q(t);if(!e)return null;let n=e.target;return{target:Ee(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:B(e.radius,.01,50,.5),speed:B(e.speed,-20,20,.5),height:B(e.height,-10,10,0),phase:B(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function Dr(t){if(!t)return null;let e=q(t)??{},n=B(e.minScale,.001,1e3,.1),r=B(e.maxScale,n,1e3,Math.max(n,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:n,maxScale:r}}var Ir=2e3,Pr={rain:600,snow:400,sparks:300,confetti:300};function Lr(t){let e=q(t);if(!e)return null;let n=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,i=c=>B(c,.05,50,2),o=Ee(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[2,2,2];return{preset:n,count:Math.round(B(e.count,1,Ir,Pr[n])),area:o,speed:B(e.speed,.05,10,1)}}var Ur=4e3;function Nr(t){if(!t)return null;let e=q(t)??{};return{prompt:he(e.prompt,Ur)??"What is this?",holdMs:B(e.holdMs,100,5e3,600)}}function kr(t){if(!t)return null;let e=q(t)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function en(t){let e=he(t,4096)?.trim();if(!(!e||/[\x00-\x20\\%]/.test(e))){if(/^https:\/\/[^/]/i.test(e))return e;if(!(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)))return e.split(/[/?#]/).includes("..")?void 0:e}}function Fr(t){if(typeof t=="string"){let r=en(t);return r?{src:r,refDistance:1,loop:!1}:null}let e=q(t),n=en(e?.src);return!e||!n?null:{src:n,refDistance:B(e.refDistance,.01,1e3,1),loop:e.loop===!0}}function ft(t,e){let n=he(t,16)?.trim();if(!n)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:e}var Or=new Set(["m","cm","mm","in","ft-in","auto"]),Pn=["x","y","z"];function zr(t){if(!t)return null;let e=q(t);if(e&&e.enabled===!1)return null;let n=e?.unit,r=typeof n=="string"&&Or.has(n)?n:"auto",i=e?.axes,o=new Set(Array.isArray(i)?i.filter(h=>typeof h=="string"):typeof i=="string"?i.split(""):[]),c=Pn.filter(h=>o.has(h));return{enabled:!0,unit:r,axes:c.length>0?c:[...Pn],color:ft(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var Br=new Set(["none","floor","wall","ceiling","any"]);function Vr(t){if(!t)return null;let e=q(t)??{},n=e.grid,r=c=>B(c,.001,100,.1),i=Ee(n)?[r(n[0]),r(n[1]),r(n[2])]:typeof n=="number"&&Number.isFinite(n)&&n>0?[r(n),r(n),r(n)]:null,o=e.surface;return{grid:i,angleDeg:B(e.angleDeg,0,180,0),surface:typeof o=="string"&&Br.has(o)?o:"none",socketTag:he(e.socketTag,128)??"",radius:B(e.radius,.01,2,.15)}}function Hr(t){if(typeof t=="string"){let r=he(t,128);return r?{tag:r,radius:.15,alignRotation:!0,highlightColor:"#22c55e"}:null}let e=q(t),n=he(e?.tag,128);return!e||!n?null:{tag:n,radius:B(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:ft(e.highlightColor,"#22c55e")}}function Xr(t){if(!t)return null;let e=q(t);if(e&&e.enabled===!1)return null;let n=e?.action;return{enabled:!0,dwellMs:Math.round(B(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:n==="ask"?"ask":"select"}}function Gr(t){if(!t)return null;let e=q(t);if(e&&e.enabled===!1)return null;let n=e?.direction,r=null;if(Ee(n)){let i=Math.hypot(n[0],n[1],n[2]);i>1e-8&&(r=[n[0]/i,n[1]/i,n[2]/i])}return{enabled:!0,direction:r,distance:B(e?.distance,0,10,.35),layer:Math.round(B(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var tn=new Set(["__proto__","constructor","prototype"]);function Wr(t){if(typeof t!="string")return;let e=t.trim().slice(0,128);if(!(!e||tn.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function Qt(t){let e=q(t);if(!e||e.persist===!1)return null;let n=Wr(e.id);return e.persist!==!0&&!n?null:n?{id:n,persist:!0}:{persist:!0}}function $r(t){return t===!0||t==="walkable"?"walkable":t===!1||t==="blocked"?"blocked":null}var Ln=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),Yr=new Set(["capsule","cylindrical","spherical"]),Xe=[];function Un(t){Xe.includes(t)||Xe.push(t)}function pt(t){let e=q(t);if(!e)return null;let n=Array.isArray(e.traits)?e.traits:[],r=v=>n.includes(v),i={},o=e.grab;o==="1-hand"||o==="2-hand"?i.grab=o:(o===!0||e.grabbable===!0||r("grab"))&&(i.grab="2-hand"),i.grab&&(i.grabbable=!0);let c=e.scale??e.scalable;if(c||r("scale")){let v=q(c)??{},_=B(v.min,.001,1e3,.05);i.scale={min:_,max:B(v.max,_,1e3,Math.max(_,5))},i.scalable=!0}let h=e.billboard;typeof h=="string"&&Yr.has(h)?i.billboard=h:(h===!0||r("billboard"))&&(i.billboard="capsule");let u=e.follow,s=typeof u=="string"?u:q(u)?.mode;if(typeof u=="string"?u:q(u)?.lazy===!1)i.follow=s==="hand-left"||s==="hand-right"?s:"head";else{let v=_r(u);v&&(i.follow=v)}let a=e.anchor;if(typeof a=="string"&&Ln.has(a))i.anchor=a;else{let _=q(a)?.target;typeof _=="string"&&Ln.has(_)&&(i.anchor=_);let D=Qt(a)??Qt(e.anchorPersist);D&&(i.anchorPersist=D)}if(!i.anchorPersist){let v=Qt(e.anchorPersist);v&&(i.anchorPersist=v)}(e.physics==="dynamic"||e.physics==="static")&&(i.physics=e.physics);let m=Cr(e.orbit);m&&(i.orbit=m);let l=Dr(e.handles);l&&(i.handles=l);let f=Lr(e.particles);f&&(i.particles=f);let d=Nr(e.holdToAsk);d&&(i.holdToAsk=d);let S=kr(e.worldUnderstanding);S&&(i.worldUnderstanding=S);let A=en(e.splatUrl);A&&(i.splatUrl=A);let M=he(e.spatialSlot);M&&(i.spatialSlot=M);let P=Fr(e.audio);P&&(i.audio=P);let y=zr(e.dimensions);y&&(i.dimensions=y);let w=Vr(e.snapTo);w&&(i.snapTo=w);let b=Hr(e.snapSocket);b&&(i.snapSocket=b);let R=Xr(e.gaze);R&&(i.gaze=R);let p=Gr(e.explode);p&&(i.explode=p);let E=$r(e.navigable);E&&(i.navigable=E),typeof e.sync=="boolean"&&(i.sync=e.sync),e.pointerEvents==="none"&&(i.pointerEvents="none");for(let v of Xe)v.normalize(e,i);return Object.keys(i).length>0?i:null}function nn(t){let e={};if(t.grab&&(e.interactable={mode:t.grab},e.movable={systemMovable:!0,scaleInZ:!!t.scale,minScale:t.scale?.min??.05,maxScale:t.scale?.max??5}),t.billboard&&(e.billboard={mode:t.billboard}),typeof t.follow=="string"?e.follow={target:t.follow,lazy:!1}:t.follow&&(e.follow={target:t.follow.mode,lazy:!0,distance:t.follow.distance,deadzoneDeg:t.follow.deadzoneDeg,stiffness:t.follow.stiffness,height:t.follow.height,faceUser:t.follow.faceUser}),t.anchor||t.anchorPersist){let n={};t.anchor&&(n.planeType=t.anchor==="vertical"||t.anchor==="wall"?"VERTICAL":"HORIZONTAL",n.semanticType=t.anchor.toUpperCase()),t.anchorPersist&&(n.persist=t.anchorPersist.persist,t.anchorPersist.id&&(n.id=t.anchorPersist.id)),e.anchor=n}t.physics&&(e.rigidbody={type:t.physics}),t.orbit&&(e.orbit={...t.orbit}),t.handles&&(e.resizable={...t.handles}),t.particles&&(e.particles={...t.particles}),t.holdToAsk&&(e.holdToAsk={...t.holdToAsk}),t.worldUnderstanding&&(e.worldUnderstanding={...t.worldUnderstanding}),t.splatUrl&&(e.splat={url:t.splatUrl}),t.spatialSlot&&(e.spatialPanel={slot:t.spatialSlot}),t.audio&&(e.spatialAudio={...t.audio}),t.dimensions&&(e.dimensions={...t.dimensions,axes:[...t.dimensions.axes]}),t.snapTo&&(e.snapTo={...t.snapTo,grid:t.snapTo.grid?[...t.snapTo.grid]:null}),t.snapSocket&&(e.snapSocket={...t.snapSocket}),t.gaze&&(e.gaze={...t.gaze}),t.explode&&(e.explode={...t.explode,direction:t.explode.direction?[...t.explode.direction]:null}),t.navigable&&(e.navigable={mode:t.navigable}),typeof t.sync=="boolean"&&(e.sync={enabled:t.sync});for(let n of Xe)n.sceneCore(t,e);return e}function jr(t){let e={},n=(r,i)=>{for(let[o,c]of Object.entries(i)){let h=r+o[0].toUpperCase()+o.slice(1);typeof c=="string"||typeof c=="number"||typeof c=="boolean"?e[h]=c:Ee(c)&&(e[h]=[c[0],c[1],c[2]])}};t.grab&&(e.grab=t.grab),t.scale&&n("scale",t.scale),t.billboard&&(e.billboard=t.billboard),typeof t.follow=="string"?e.follow=t.follow:t.follow&&(e.follow=t.follow.mode,n("follow",{...t.follow,mode:void 0})),t.anchor&&(e.anchor=t.anchor),t.anchorPersist&&(e.anchorPersist=t.anchorPersist.persist,t.anchorPersist.id&&(e.anchorId=t.anchorPersist.id)),t.physics&&(e.physics=t.physics),t.orbit&&n("orbit",t.orbit),t.handles&&(e.handles=!0,n("handles",t.handles)),t.particles&&n("particles",t.particles),t.holdToAsk&&(e.holdToAsk=!0,n("holdToAsk",t.holdToAsk)),t.worldUnderstanding&&n("worldUnderstanding",t.worldUnderstanding),t.splatUrl&&(e.splatUrl=t.splatUrl),t.spatialSlot&&(e.spatialSlot=t.spatialSlot),t.audio&&n("audio",t.audio),t.dimensions&&n("dimensions",{...t.dimensions,axes:t.dimensions.axes.join("")}),t.snapTo&&(e.snapTo=!0,n("snapTo",t.snapTo)),t.snapSocket&&n("snapSocket",t.snapSocket),t.gaze&&n("gaze",t.gaze),t.explode&&n("explode",t.explode),t.navigable&&(e.navigable=t.navigable),typeof t.sync=="boolean"&&(e.sync=t.sync),t.pointerEvents&&(e.pointerEvents=t.pointerEvents);for(let r of Xe)r.usd(t,n,e);return e}function qr(t,e){let n=pt(e);if(!n)return;let r={...t.extras?.xr,...n};n.anchor===void 0&&typeof r.anchor=="object"&&delete r.anchor,t.extras={...t.extras,xr:r},t.extensions={...t.extensions,MOZ_hubs_components:rn(n),ANDROID_xr_scenecore:nn(n)}}function rn(t){let e={};return t.grab&&(e.grabbable={cursor:!0,hand:!0}),t.billboard&&(e.billboard={onlyY:t.billboard!=="spherical"}),e}function Kr(t,e){let n=pt(t),r=[];if(!n)return r;for(let[i,o]of Object.entries(jr(n)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof o=="boolean"?r.push(`bool ${i} = ${o}`):typeof o=="number"?Number.isFinite(o)&&r.push(`double ${i} = ${o}`):typeof o=="string"?r.push(`string ${i} = "${e(o)}"`):o.length===3&&o.every(c=>Number.isFinite(c))&&r.push(`double3 ${i} = (${o.join(", ")})`));return r}function Nn(){try{Object.defineProperty(Q(),"xrTraitSerializer",{value:Object.freeze({gltfNode:qr,usdLines:Kr}),writable:!1,configurable:!1,enumerable:!0})}catch{}}function sn(t){if(typeof t!="string")return;let e=t.trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(e)&&!tn.has(e)?e:void 0}function bt(t,e,n){return typeof t=="string"&&e.includes(t)?t:n}var Zr=["third-person","first-person","top-down","fixed"],Jr=["idle","walk","run","jump"];function Qr(t){if(!t)return null;let e=q(t)??(typeof t=="string"?{cameraMode:t}:{});if(e.enabled===!1)return null;let n=B(e.radius,.05,5,.35),r=q(e.clips)??{},i={};for(let o of Jr){let c=he(r[o],128);c&&(i[o]=c)}return{speed:B(e.speed,.1,20,4),runMultiplier:B(e.runMultiplier,1,4,1.6),jumpVelocity:B(e.jumpVelocity,0,30,5.5),gravity:B(e.gravity,0,50,15),radius:n,height:B(e.height,n*2,10,Math.max(1.4,n*2)),cameraMode:bt(e.cameraMode,Zr,"third-person"),cameraDistance:B(e.cameraDistance,.5,50,3.5),cameraHeight:B(e.cameraHeight,-10,50,1.8),clips:i}}var ei=["patrol","chase","flee","wander","follow"],ti=32,on="user";function ni(t){if(!t)return null;let e=q(t)??(typeof t=="string"?{mode:t}:{});if(e.enabled===!1)return null;let n=bt(e.mode,ei,"wander"),r=e.target,i=r==="camera"||r===on?on:he(r,256)??"";!i&&(n==="chase"||n==="flee"||n==="follow")&&(i=on);let o=h=>B(h,-1e4,1e4,0),c=Array.isArray(e.waypoints)?e.waypoints.filter(Ee).slice(0,ti).map(h=>[o(h[0]),o(h[1]),o(h[2])]):[];return{mode:n,target:i,speed:B(e.speed,.1,20,2),turnSpeed:B(e.turnSpeed,.1,50,6),sightRadius:B(e.sightRadius,0,100,6),stopDistance:B(e.stopDistance,.01,10,.6),separationRadius:B(e.separationRadius,0,10,.8),waypoints:c,loopWaypoints:e.loopWaypoints!==!1}}function ri(t){if(!t)return null;let e=q(t)??(typeof t=="number"?{max:t}:{});if(e.enabled===!1)return null;let n=B(e.max,1,1e6,100);return{max:n,current:B(e.current,0,n,n),group:sn(e.group)??"neutral",showBar:e.showBar===!0,cooldownMs:Math.round(B(e.cooldownMs,0,1e4,250)),hideOnDepleted:e.hideOnDepleted!==!1,scoreValue:B(e.scoreValue,-1e6,1e6,0),contactAmount:B(e.contactAmount,0,1e6,0)}}var ii=16;function oi(t){if(!t)return null;let e=q(t)??(typeof t=="string"?{shape:t}:{});if(e.enabled===!1)return null;let n=bt(e.shape,["box","sphere"],"box"),r=e.size,i=m=>B(m,.01,1e3,1),o=Ee(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[1,1,1],c=B(e.radius??(typeof r=="number"?r:void 0),.01,1e3,.5),h=e.watchGroups,u=[...new Set((Array.isArray(h)?h:h===void 0?[]:[h]).map(sn).filter(m=>m!==void 0))].slice(0,ii),s={shape:n,size:o,radius:c,watchGroups:u},a=ft(e.color,"");return a?{...s,color:a}:s}var si=32;function ai(t){let e=q(t)??(typeof t=="string"?{template:t}:null),n=he(e?.template,256)?.trim();return!e||!n||e.enabled===!1?null:{template:n,intervalSec:B(e.intervalSec,.05,3600,3),maxActive:Math.round(B(e.maxActive,1,si,8)),totalCount:Math.round(B(e.totalCount,0,1e4,0)),spawnRadius:B(e.spawnRadius,0,100,0)}}var ci=["pickup","checkpoint","time-bonus","restore","key"];function ui(t){if(!t)return null;let e=q(t)??(typeof t=="string"?{type:t}:{});if(e.enabled===!1)return null;let n=bt(e.type,ci,"pickup"),r=n==="pickup";return{type:n,amount:B(e.amount??e.points,-1e6,1e6,10),tag:sn(e.tag)??"",radius:B(e.radius,.05,50,.65),required:e.required===!0,order:Math.round(B(e.order,0,1e3,0)),spinSpeed:B(e.spinSpeed,-50,50,r?2.5:0),bobAmplitude:B(e.bobAmplitude,0,5,r?.08:0),respawnSec:B(e.respawnSec,0,3600,0)}}var li=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],hi=["onTap","onObjective","onHit","onDepleted","onZoneEnter","onZoneExit","onSpawn","onJump","onLand"];function mi(t){let e=q(t);if(!e)return null;let n={};for(let r of hi){let i=e[r];typeof i=="string"&&li.includes(i)&&(n[r]=i)}return Object.keys(n).length===0?null:{cues:n,pitchJitter:B(e.pitchJitter,0,.5,.08),volume:B(e.volume,0,1,1),spatial:e.spatial!==!1}}var di={normalize(t,e){let n=Qr(t.character);n&&(e.character=n);let r=ni(t.agent);r&&(e.agent=r);let i=ri(t.integrity);i&&(e.integrity=i);let o=oi(t.zone);o&&(e.zone=o);let c=ai(t.spawner);c&&(e.spawner=c);let h=ui(t.objective);h&&(e.objective=h);let u=mi(t.audioCues);u&&(e.audioCues=u),t.collidable===!0&&(e.collidable=!0)},sceneCore(t,e){t.character&&(e.character={...t.character,clips:{...t.character.clips}}),t.agent&&(e.agent={...t.agent,waypoints:t.agent.waypoints.map(n=>[...n])}),t.integrity&&(e.integrity={...t.integrity}),t.zone&&(e.zone={...t.zone,size:[...t.zone.size],watchGroups:[...t.zone.watchGroups]}),t.spawner&&(e.spawner={...t.spawner}),t.objective&&(e.objective={...t.objective}),t.audioCues&&(e.audioCues={...t.audioCues,cues:{...t.audioCues.cues}}),t.collidable&&(e.collidable={enabled:!0})},usd(t,e,n){if(t.character){n.character=!0,e("character",{...t.character,clips:void 0});for(let[r,i]of Object.entries(t.character.clips))n["characterClip"+r[0].toUpperCase()+r.slice(1)]=i}t.agent&&(e("agent",{...t.agent,waypoints:void 0}),n.agentWaypointCount=t.agent.waypoints.length,t.agent.waypoints.forEach((r,i)=>{n[`agentWaypoint${i}`]=[r[0],r[1],r[2]]})),t.integrity&&(n.integrity=!0,e("integrity",t.integrity)),t.zone&&e("zone",{...t.zone,watchGroups:t.zone.watchGroups.join(",")}),t.spawner&&e("spawner",t.spawner),t.objective&&e("objective",t.objective),t.audioCues&&(e("audioCues",{...t.audioCues,cues:void 0}),e("audioCues",t.audioCues.cues)),t.collidable&&(n.collidable=!0)}};function kn(){Un(di)}var yt=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},J=class t{constructor(e=0,n=0,r=0){this.x=Number(e),this.y=Number(n),this.z=Number(r)}set(e,n,r){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(e,n){let r=e.x,i=e.y,o=e.z,c=n.x,h=n.y,u=n.z;return this.x=i*u-o*h,this.y=o*c-r*u,this.z=r*h-i*c,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let n=this.x,r=this.y,i=this.z,o=e.elements,c=1/(o[3]*n+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*n+o[4]*r+o[8]*i+o[12])*c,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*c,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*c,this}},gt=class{constructor(e=0,n=0,r=0,i=1){this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(e,n,r,i){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},$e=class t{constructor(e=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,n,r,i=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Ye=class t{constructor(e=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,n,r,i){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let r=e.x,i=e.y,o=e.z,c=Math.cos(r/2),h=Math.cos(i/2),u=Math.cos(o/2),s=Math.sin(r/2),a=Math.sin(i/2),m=Math.sin(o/2);return this._x=s*h*u+c*a*m,this._y=c*a*u-s*h*m,this._z=c*h*m+s*a*u,this._w=c*h*u-s*a*m,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,c=e.w,h=n.x,u=n.y,s=n.z,a=n.w;return this._x=r*a+c*h+i*s-o*u,this._y=i*a+c*u+o*h-r*s,this._z=o*a+c*s+r*u-i*h,this._w=c*a-r*h-i*u-o*s,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},be=class t{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 t;return e.copy(this),e}compose(e,n,r){return ct(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return ie(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return Pe(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let n=new J(0,0,0),r=new J(1,1,1);return this.compose(n,e,r)}makeTranslation(e,n,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(e,n,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},xt=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}},me=class t{constructor(e,n,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(e,n,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,r){return this.r=Number(e),this.g=Number(n),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},Xn={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},G=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;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/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,r,i){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},vt=class extends G{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},Tt=class extends G{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},wt=class extends G{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},ue=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof G)this.index=e;else if(Array.isArray(e)){let n=0;for(let i=0;i<e.length;i++)e[i]>n&&(n=e[i]);let r=n>65535?new Uint32Array(e):new Uint16Array(e);this.index=new G(r,1)}else e&&e.buffer&&(this.index=new G(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let n=e.count,r=new Float32Array(n*3),i=new J,o=new J,c=new J,h=new J,u=new J;if(this.index){let s=this.index.array;for(let a=0;a<s.length;a+=3){let m=s[a],l=s[a+1],f=s[a+2];i.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(l),e.getY(l),e.getZ(l)),c.set(e.getX(f),e.getY(f),e.getZ(f)),h.subVectors(c,o),u.subVectors(i,o),h.cross(u).normalize();for(let d of[m,l,f])r[d*3]+=h.x,r[d*3+1]+=h.y,r[d*3+2]+=h.z}}else for(let s=0;s<n;s+=3){i.set(e.getX(s),e.getY(s),e.getZ(s)),o.set(e.getX(s+1),e.getY(s+1),e.getZ(s+1)),c.set(e.getX(s+2),e.getY(s+2),e.getZ(s+2)),h.subVectors(c,o),u.subVectors(i,o),h.cross(u).normalize();for(let a=0;a<3;a++)r[(s+a)*3]=h.x,r[(s+a)*3+1]=h.y,r[(s+a)*3+2]=h.z}for(let s=0;s<n;s++){let a=r[s*3],m=r[s*3+1],l=r[s*3+2],f=Math.hypot(a,m,l)||1;r[s*3]=a/f,r[s*3+1]=m/f,r[s*3+2]=l/f}return this.setAttribute("normal",new G(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new G(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new G(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new G(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},je=class extends ue{constructor(e=1,n=1,r=1){super();{let m=globalThis.__three_live_native_box__;if(typeof m=="function"){let l=m(e,n,r);this.setFromBuffers(l.positions,l.normals,l.uvs,l.indices);return}}let i=e/2,o=n/2,c=r/2,h=[-i,-o,c,i,-o,c,i,o,c,-i,o,c,i,-o,-c,-i,-o,-c,-i,o,-c,i,o,-c,-i,o,c,i,o,c,i,o,-c,-i,o,-c,-i,-o,-c,i,-o,-c,i,-o,c,-i,-o,c,i,-o,c,i,-o,-c,i,o,-c,i,o,c,-i,-o,-c,-i,-o,c,-i,o,c,-i,o,-c],u=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],s=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],a=[];for(let m=0;m<6;m++){let l=m*4;a.push(l,l+1,l+2,l,l+2,l+3)}this.setAttribute("position",new G(new Float32Array(h),3)),this.setAttribute("normal",new G(new Float32Array(u),3)),this.setAttribute("uv",new G(new Float32Array(s),2)),this.setIndex(a)}},Et=class extends ue{constructor(e=1,n=1){super();let r=e/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],c=[0,0,1,0,0,1,0,0,1,0,0,1],h=[0,1,1,1,0,0,1,0],u=[0,2,1,2,3,1];this.setAttribute("position",new G(new Float32Array(o),3)),this.setAttribute("normal",new G(new Float32Array(c),3)),this.setAttribute("uv",new G(new Float32Array(h),2)),this.setIndex(u)}},qe=class extends ue{constructor(e=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));{let s=globalThis.__three_live_native_sphere__;if(typeof s=="function"){let a=s(e,n,r);this.setAttribute("position",new G(a.positions,3)),this.setAttribute("normal",new G(a.normals,3)),this.setAttribute("uv",new G(a.uvs,2)),this.setIndex(a.indices);return}}let i=[],o=[],c=[],h=[],u=[];for(let s=0;s<=r;s++){let a=[],m=s/r;for(let l=0;l<=n;l++){let f=l/n,d=f*Math.PI*2,S=m*Math.PI,A=-e*Math.cos(d)*Math.sin(S),M=e*Math.cos(S),P=e*Math.sin(d)*Math.sin(S);i.push(A,M,P);let y=Math.hypot(A,M,P)||1;o.push(A/y,M/y,P/y),c.push(f,1-m),a.push(i.length/3-1)}u.push(a)}for(let s=0;s<r;s++)for(let a=0;a<n;a++){let m=u[s][a+1],l=u[s][a],f=u[s+1][a],d=u[s+1][a+1];s!==0&&h.push(m,l,d),s!==r-1&&h.push(l,f,d)}this.setAttribute("position",new G(new Float32Array(i),3)),this.setAttribute("normal",new G(new Float32Array(o),3)),this.setAttribute("uv",new G(new Float32Array(c),2)),this.setIndex(h)}},Re=class extends ue{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));{let a=globalThis.__three_live_native_cylinder__;if(typeof a=="function"){let m=a(e,n,r,i);this.setAttribute("position",new G(m.positions,3)),this.setAttribute("normal",new G(m.normals,3)),this.setAttribute("uv",new G(m.uvs,2)),this.setIndex(m.indices);return}}let o=[],c=[],h=[],u=[],s=r/2;for(let a=0;a<=1;a++){let m=a,l=a===0?e:n,f=a===0?s:-s;for(let d=0;d<=i;d++){let S=d/i,A=S*Math.PI*2,M=Math.sin(A),P=Math.cos(A);o.push(l*M,f,l*P),c.push(M,0,P),h.push(S,1-m)}}for(let a=0;a<i;a++){let m=a,l=a+i+1,f=a+i+2,d=a+1;u.push(m,l,d,l,f,d)}if(e>0){let a=o.length/3;o.push(0,s,0),c.push(0,1,0),h.push(.5,.5);let m=o.length/3;for(let l=0;l<=i;l++){let f=l/i*Math.PI*2,d=Math.sin(f),S=Math.cos(f);o.push(e*d,s,e*S),c.push(0,1,0),h.push(S*.5+.5,d*.5+.5)}for(let l=0;l<i;l++)u.push(a,m+l,m+l+1)}if(n>0){let a=o.length/3;o.push(0,-s,0),c.push(0,-1,0),h.push(.5,.5);let m=o.length/3;for(let l=0;l<=i;l++){let f=l/i*Math.PI*2,d=Math.sin(f),S=Math.cos(f);o.push(n*d,-s,n*S),c.push(0,-1,0),h.push(S*.5+.5,1-(d*.5+.5))}for(let l=0;l<i;l++)u.push(a,m+l+1,m+l)}this.setAttribute("position",new G(new Float32Array(o),3)),this.setAttribute("normal",new G(new Float32Array(c),3)),this.setAttribute("uv",new G(new Float32Array(h),2)),this.setIndex(u)}},St=class extends Re{constructor(e=1,n=1,r=16){super(0,e,n,r)}},Rt=class extends ue{constructor(e=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],c=[],h=[],u=[];for(let s=0;s<=r;s++){let a=s/r*Math.PI*2;for(let m=0;m<=i;m++){let l=m/i*Math.PI*2,f=(e+n*Math.cos(a))*Math.cos(l),d=(e+n*Math.cos(a))*Math.sin(l),S=n*Math.sin(a);o.push(f,d,S);let A=e*Math.cos(l),M=e*Math.sin(l),P=f-A,y=d-M,w=S,b=Math.hypot(P,y,w)||1;c.push(P/b,y/b,w/b),h.push(m/i,s/r)}}for(let s=1;s<=r;s++)for(let a=1;a<=i;a++){let m=(i+1)*s+a-1,l=(i+1)*(s-1)+a-1,f=(i+1)*(s-1)+a,d=(i+1)*s+a;u.push(m,l,d,l,f,d)}this.setAttribute("position",new G(new Float32Array(o),3)),this.setAttribute("normal",new G(new Float32Array(c),3)),this.setAttribute("uv",new G(new Float32Array(h),2)),this.setIndex(u)}},Mt=class extends ue{constructor(e=1,n=.4,r=64,i=8,o=2,c=3){super(),r=Math.floor(r),i=Math.floor(i);{let y=globalThis.__three_live_native_torus_knot__;if(typeof y=="function"){let w=y(e,n,r,i,o,c);this.setAttribute("position",new G(w.positions,3)),this.setAttribute("normal",new G(w.normals,3)),this.setAttribute("uv",new G(w.uvs,2)),this.setIndex(w.indices);return}}let h=[],u=[],s=[],a=[],m=new J,l=new J,f=new J,d=new J,S=new J;function A(y,w){let b=Math.cos(w),R=Math.sin(w),p=c/o*w,E=e*(2+Math.cos(p))*.5;y.set(E*b,E*R,e*Math.sin(p)*.5)}let M=[];for(let y=0;y<=i;++y){let w=y/i*Math.PI*2;M.push(-n*Math.cos(w),n*Math.sin(w),y/i)}for(let y=0;y<=r;++y){let w=y/r,b=w*o*Math.PI*2;A(m,b),A(l,b+.01),f.subVectors(l,m).normalize(),d.addVectors(m,l).normalize(),S.crossVectors(f,d).normalize(),d.crossVectors(S,f).normalize();for(let R=0;R<=i;++R){let p=R*3,E=M[p],v=M[p+1],_=M[p+2],D=E*d.x+v*S.x,g=E*d.y+v*S.y,T=E*d.z+v*S.z;h.push(m.x+D,m.y+g,m.z+T);let x=Math.hypot(D,g,T)||1;u.push(D/x,g/x,T/x),s.push(w,_)}}let P=i+1;for(let y=1;y<=r;y++){let w=P*(y-1),b=w+P;for(let R=1;R<=i;R++){let p=w+(R-1),E=b+(R-1),v=b+R,_=w+R;a.push(p,E,_,E,v,_)}}this.setAttribute("position",new G(new Float32Array(h),3)),this.setAttribute("normal",new G(new Float32Array(u),3)),this.setAttribute("uv",new G(new Float32Array(s),2)),this.setIndex(a)}},Ke=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},At=class{load(e,n){let r=new Ke(e);return n?.(r),r}};function ne(t,e){return t!==void 0?Number(t):e}function an(t,e){return t!==void 0?!!t:e}var de=class{constructor(e={}){this.name=e.name||"",this.color=new me(e.color!==void 0?e.color:16777215),this.emissive=new me(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=ne(e.emissiveIntensity,1),this.roughness=ne(e.roughness,.5),this.metalness=ne(e.metalness,.1),this.opacity=ne(e.opacity,1),this.transparent=an(e.transparent,!1),this.wireframe=an(e.wireframe,!1),this.side=ne(e.side,2),this.doubleSided=an(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=ne(e.clearcoat,0),this.clearcoatRoughness=ne(e.clearcoatRoughness,0),this.sheen=ne(e.sheen,0),this.sheenColor=new me(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=ne(e.sheenRoughness,0),this.transmission=ne(e.transmission,0),this.thickness=ne(e.thickness,0),this.attenuationColor=new me(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=ne(e.attenuationDistance,1/0),this.ior=ne(e.ior,1.5),this.dispersion=ne(e.dispersion,0),this.iridescence=ne(e.iridescence,0),this.iridescenceIOR=ne(e.iridescenceIOR,1.3)}dispose(){}},_e=class extends de{},_t=class extends de{},Ct=class extends de{},Dt=class extends de{},It=class extends de{},oe=class t{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new J,this.rotation=new $e,this.quaternion=new Ye,this.scale=new J(1,1,1),this.matrix=new be,this.matrixWorld=new be,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,r,i)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,r){let i=typeof e=="object"?e:new J(e,n,r);this.updateMatrixWorld(!0);let o=new be;o.lookAt(this.position,i,new J(0,1,0));let c=o.elements,h=c[0],u=c[4],s=c[8],a=c[1],m=c[5],l=c[9],f=c[2],d=c[6],S=c[10],A=h+m+S;if(A>0){let M=.5/Math.sqrt(A+1);this.quaternion.set((d-l)*M,(s-f)*M,(a-u)*M,.25/M)}}},Pt=class extends oe{},ke=class extends oe{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof ue?n:n?(se("unsupported geometry","BoxGeometry"),new je(.5,.5,.5)):new ue,this.material=i instanceof de?i:i?(se("unsupported material","MeshStandardMaterial"),new _e({color:13421772})):new _e}},Me=class extends oe{constructor(e=16777215,n=1){super(),this.color=new me(e),this.intensity=Number(n),this.type="directional"}},Ze=class extends Me{constructor(e,n){super(e,n),this.type="ambient"}},Lt=class extends Me{constructor(n,r){super(n,r);this.target=new oe;this.type="directional"}},Je=class extends Me{constructor(n,r,i=0,o=2){super(n,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},Qe=class extends oe{},Fe=class extends Qe{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new J(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},Ce=class extends oe{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return fe.validate(this),Le(this)}toGLB(){return fe.validate(this),He(this)}toUSDZ(){return fe.validate(this),Ue(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof ke){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},cn=Le,un=He,Gn=Ue;var fe=class{static validate(e){let n=0,r=0,i=0,o=new Set,c=(u,s,a)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${u} (${s}). Found: ${a}`)},h=(u,s)=>{if(!Number.isFinite(s))throw new Error(`SecurityError: Scene reports a non-finite ${u} count (${String(s)}), which cannot be bounds-checked.`);return s};e.traverse(u=>{if(u instanceof ke){i++,i>1e3&&c("MESHES",1e3,i);let s=u.geometry;if(s){let a=0;if(s.attributes.position&&(a=h("vertex",s.attributes.position.count),n+=a,n>1e5&&c("VERTICES",1e5,n)),s.index){let m=h("index",s.index.count);r+=m,r>3e5&&c("INDICES",3e5,r);let l=s.index.array;if(l&&a>0){let f=Math.min(m,l.length);for(let d=0;d<f;d++){let S=l[d];if(!Number.isFinite(S)||S<0||S>=a)throw new Error(`SecurityError: Index buffer value (${String(S)}) out of vertex bounds [0, ${a}).`)}}}}if(u.material){let a=u.material;a.map&&o.add(a.map),a.normalMap&&o.add(a.normalMap),a.roughnessMap&&o.add(a.roughnessMap)}}}),o.size>16&&c("TEXTURES",16,o.size);for(let u of o){let s=u,a=s.image,m=Number(a?.width??s.width??0)||0,l=Number(a?.height??s.height??0)||0;(!Number.isFinite(m)||!Number.isFinite(l)||m>2048||l>2048)&&c("TEXTURE_DIMENSION",2048,Math.max(m,l))}}},Ut=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let r=new me(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){fe.validate(e);let i=(o,c)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(c&&c.length?self.postMessage(o,c):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),c={};for(let[h,u]of o.entries())c[h]=Array.from(u);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:c})}else{this.hasInitialModelRendered=!0;let o=cn(e),c=un(e),h=(o.lights||[]).map(u=>({type:u.type,color:u.color,intensity:u.intensity,position:u.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:c.buffer,dynamicLights:h,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[c.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Fn(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Nt=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=Fn(),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 n=Fn();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function fi(){}var Ne=new Proxy(fi,{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:Ne},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Ne,construct:()=>Ne}),On=(()=>{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 Oe(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Ae(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,Oe());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 zn,Ge;function Wn(t){if(!Ae(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(Ge===void 0||zn!==n){zn=n;try{Ge=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Ae(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Ge=null}}return Ge?Ge.createScriptURL(t):t}function pi(t){Q().sandboxEngineSrc=t}function ln(){let t=Q().sandboxEngineSrc;if(t)return t;if(On)return On;try{if(typeof document>"u")return null;let e=Oe(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&Ae(i,{requireSameOrigin:!0}))return i}}catch{}return null}function bi(){let t=ln();if(!t)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!Ae(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Oe()).href}function yi(t){Q().sandboxIframeSrc=t}function $n(){let t=Q().sandboxIframeSrc;if(t)return t;let e=ln();if(!e||!Ae(e))return null;let n=new URL(e,Oe());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function gi(){let t=$n();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!Ae(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Oe()).href}function xi(t){Q().allowClientScripts=t}function Yn(){return!!Q().allowClientScripts}function vi(t){if(!Ae(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Oe()).href}var Ti=["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 wi(t){let e=self,n=t.nonce,r=t.engineSrc,i=t.allowedScriptUrl,o=t.allowClientScripts,c=t.revoked,h=e.postMessage.bind(e);function u(b){h({type:"ERROR",nonce:n,message:String(b)})}let s=typeof e.importScripts=="function"?e.importScripts.bind(e):null,a=i,m=null;try{let b=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let R={createScriptURL:function(E){if(E!==r&&(!i||E!==i))throw new TypeError("Disallowed worker importScripts URL");return E}};o&&(R.createScript=function(E){return String(E)});let p=e.trustedTypes.createPolicy("three-live#worker-boot",R);b=p.createScriptURL(r),i&&(a=p.createScriptURL(i)),o&&typeof p.createScript=="function"&&(m=p.createScript.bind(p))}catch{}s(b)}catch(b){u('Sandbox failed to load the Three-Live engine from "'+r+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(b&&b.message||b));return}let l=e.THREE;if(!l||typeof l.Scene!="function"){u('Sandbox loaded "'+r+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let b=0;b<c.length;b++){let R=c[b],p=e;for(;p&&p!==Object.prototype;){if(p!==e)try{delete p[R]}catch{}try{Object.defineProperty(p,R,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{p=Object.getPrototypeOf(p)}catch{break}}}let f=Object.freeze({now:function(){return Date.now()}}),d=e;for(;d&&d!==Object.prototype;){if(d!==e)try{delete d.performance}catch{}try{Object.defineProperty(d,"performance",{value:f,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let S=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],A=!1;function M(b,R){if(b.type==="3D_MODEL_READY"){if(A)return;A=!0}b.nonce=n,R&&R.length?h(b,R):h(b)}let P=function(b,R){if(!b||S.indexOf(b.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+S.join(", ")+").");M(b,R)},y=e;for(;y&&y!==Object.prototype;){if(y===e||Object.prototype.hasOwnProperty.call(y,"postMessage"))try{Object.defineProperty(y,"postMessage",{value:P,writable:!1,configurable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}let w=!1;e.onmessage=function(b){let R=b&&b.data;if(!(!R||R.nonce!==n)&&!(R.type!=="EXECUTE"&&R.type!=="EXECUTE_URL")&&!w){w=!0;try{let p=new l.Scene,E=new l.PerspectiveCamera(60,1,.1,1e3),v=new l.WebGLRenderer({isSandboxed:!0});if(R.type==="EXECUTE_URL"){if(!i||R.scriptUrl!==i||typeof s!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let _=a||i,D=s;if(s=null,a=null,e.THREE=l,e.scene=p,e.camera=E,e.renderer=v,D(_),typeof e.__THREE_LIVE_SCENE__=="function"){let g=e.__THREE_LIVE_SCENE__(l,p,E,v);g&&typeof g.toGLB=="function"&&(p=g)}else e.scene&&typeof e.scene.toGLB=="function"&&(p=e.scene)}else{if(!o){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let _=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
|
|
320
|
+
`,s}function qi(t,e){if(t&&typeof t.traverse=="function"){let i=ji(t,e);return tr(i)}let n=Bt(t),r=Qr(n);return tr(r)}var ln=null;function Zi(t){{let n=globalThis.__three_live_native_crc32__;if(typeof n=="function")return n(t)}if(!ln){ln=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;ln[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=ln[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function Jr(t){{let u=globalThis.__three_live_native_build_usdz_zip__;if(typeof u=="function")return u(t)}let e=[],n=0,r=[];for(let u of t){let d=hn(u.filename),h=Zi(u.data),m=u.data.length,y=30+d.length,x=n+y,M=0,L=x%64;L!==0&&(M=64-L);let F=new Uint8Array(y+M),g=new DataView(F.buffer);g.setUint32(0,67324752,!0),g.setUint16(4,20,!0),g.setUint16(6,0,!0),g.setUint16(8,0,!0),g.setUint16(10,0,!0),g.setUint16(12,0,!0),g.setUint32(14,h,!0),g.setUint32(18,m,!0),g.setUint32(22,m,!0),g.setUint16(26,d.length,!0),g.setUint16(28,M,!0),F.set(d,30),M>0&&F.fill(0,30+d.length),e.push({offset:n,size:m,crc:h,filenameBytes:d,entry:u}),r.push(F),r.push(u.data),n+=F.length+u.data.length}let i=n;for(let u of e){let d=new Uint8Array(46+u.filenameBytes.length),h=new DataView(d.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint16(8,0,!0),h.setUint16(10,0,!0),h.setUint16(12,0,!0),h.setUint16(14,0,!0),h.setUint32(16,u.crc,!0),h.setUint32(20,u.size,!0),h.setUint32(24,u.size,!0),h.setUint16(28,u.filenameBytes.length,!0),h.setUint16(30,0,!0),h.setUint16(32,0,!0),h.setUint16(34,0,!0),h.setUint16(36,0,!0),h.setUint32(38,0,!0),h.setUint32(42,u.offset,!0),d.set(u.filenameBytes,46),r.push(d),n+=d.length}let o=n-i,s=new Uint8Array(22),l=new DataView(s.buffer);l.setUint32(0,101010256,!0),l.setUint16(4,0,!0),l.setUint16(6,0,!0),l.setUint16(8,e.length,!0),l.setUint16(10,e.length,!0),l.setUint32(12,o,!0),l.setUint32(16,i,!0),l.setUint16(20,0,!0),r.push(s),n+=22;let a=new Uint8Array(n),c=0;for(let u of r)a.set(u,c),c+=u.length;return a}function Pt(t){let e=qi(t),n=hn(e);return Jr([{filename:"model.usda",data:n}])}function mn(t){let e=Bt(t),n=Qr(e),r=tr(n),i=hn(r);return Jr([{filename:"model.usda",data:i}])}function nr(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?Pt(t):mn(t)}function re(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function Je(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function Ae(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Xe(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function Qi(t){let e=Ae(t);if(!e||e.lazy===!1)return null;let n=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=n!=="head";return{mode:n,lazy:!0,distance:re(e.distance,.1,10,r?.15:1),deadzoneDeg:re(e.deadzoneDeg,0,90,r?0:15),stiffness:re(e.stiffness,.5,40,6),height:re(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function Ji(t){let e=Ae(t);if(!e)return null;let n=e.target;return{target:Je(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:re(e.radius,.01,50,.5),speed:re(e.speed,-20,20,.5),height:re(e.height,-10,10,0),phase:re(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function eo(t){if(!t)return null;let e=Ae(t)??{},n=re(e.minScale,.001,1e3,.1),r=re(e.maxScale,n,1e3,Math.max(n,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:n,maxScale:r}}var to=2e3,no={rain:600,snow:400,sparks:300,confetti:300};function ro(t){let e=Ae(t);if(!e)return null;let n=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,i=s=>re(s,.05,50,2),o=Je(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[2,2,2];return{preset:n,count:Math.round(re(e.count,1,to,no[n])),area:o,speed:re(e.speed,.05,10,1)}}var io=4e3;function oo(t){if(!t)return null;let e=Ae(t)??{};return{prompt:Xe(e.prompt,io)??"What is this?",holdMs:re(e.holdMs,100,5e3,600)}}function so(t){if(!t)return null;let e=Ae(t)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function ir(t){let e=Xe(t,4096)?.trim();if(!(!e||/[\x00-\x20\\%]/.test(e))){if(/^https:\/\/[^/]/i.test(e))return e;if(!(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)))return e.split(/[/?#]/).includes("..")?void 0:e}}function ao(t){if(typeof t=="string"){let r=ir(t);return r?{src:r,refDistance:1,loop:!1}:null}let e=Ae(t),n=ir(e?.src);return!e||!n?null:{src:n,refDistance:re(e.refDistance,.01,1e3,1),loop:e.loop===!0}}function vt(t,e){let n=Xe(t,16)?.trim();if(!n)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:e}var co=new Set(["m","cm","mm","in","ft-in","auto"]),ei=["x","y","z"];function uo(t){if(!t)return null;let e=Ae(t);if(e&&e.enabled===!1)return null;let n=e?.unit,r=typeof n=="string"&&co.has(n)?n:"auto",i=e?.axes,o=new Set(Array.isArray(i)?i.filter(l=>typeof l=="string"):typeof i=="string"?i.split(""):[]),s=ei.filter(l=>o.has(l));return{enabled:!0,unit:r,axes:s.length>0?s:[...ei],color:vt(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var lo=new Set(["none","floor","wall","ceiling","any"]);function ho(t){if(!t)return null;let e=Ae(t)??{},n=e.grid,r=s=>re(s,.001,100,.1),i=Je(n)?[r(n[0]),r(n[1]),r(n[2])]:typeof n=="number"&&Number.isFinite(n)&&n>0?[r(n),r(n),r(n)]:null,o=e.surface;return{grid:i,angleDeg:re(e.angleDeg,0,180,0),surface:typeof o=="string"&&lo.has(o)?o:"none",socketTag:Xe(e.socketTag,128)??"",radius:re(e.radius,.01,2,.15)}}function mo(t){if(typeof t=="string"){let r=Xe(t,128);return r?{tag:r,radius:.15,alignRotation:!0,highlightColor:"#22c55e"}:null}let e=Ae(t),n=Xe(e?.tag,128);return!e||!n?null:{tag:n,radius:re(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:vt(e.highlightColor,"#22c55e")}}function fo(t){if(!t)return null;let e=Ae(t);if(e&&e.enabled===!1)return null;let n=e?.action;return{enabled:!0,dwellMs:Math.round(re(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:n==="ask"?"ask":"select"}}function po(t){if(!t)return null;let e=Ae(t);if(e&&e.enabled===!1)return null;let n=e?.direction,r=null;if(Je(n)){let i=Math.hypot(n[0],n[1],n[2]);i>1e-8&&(r=[n[0]/i,n[1]/i,n[2]/i])}return{enabled:!0,direction:r,distance:re(e?.distance,0,10,.35),layer:Math.round(re(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var or=new Set(["__proto__","constructor","prototype"]);function Nt(t){if(typeof t!="string")return;let e=t.trim().slice(0,128);if(!(!e||or.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function rr(t){let e=Ae(t);if(!e||e.persist===!1)return null;let n=Nt(e.id);return e.persist!==!0&&!n?null:n?{id:n,persist:!0}:{persist:!0}}function bo(t){return t===!0||t==="walkable"?"walkable":t===!1||t==="blocked"?"blocked":null}function yo(t){if(typeof t=="string"){let s=Xe(t,256);return s?{text:s,size:.12,depth:.02,color:"#ffffff"}:null}let e=Ae(t);if(!e)return null;let n=Xe(e.text??e.value,256);if(!n)return null;let r=re(e.size,.005,10,.12),i=re(e.depth??e.height,.001,5,r*.2),o=vt(e.color,"#ffffff");return{text:n,size:r,depth:i,color:o}}function go(t){if(t===!1||t===null||t===void 0)return null;if(typeof t=="number")return!Number.isFinite(t)||t<=0?null:{enabled:!0,strength:re(t,0,5,.35),threshold:.8,radius:.5};if(t===!0)return{enabled:!0,strength:.35,threshold:.8,radius:.5};let e=Ae(t);if(!e||e.enabled===!1)return null;let n=re(e.strength??e.intensity,0,5,.35);return n<=0?null:{enabled:!0,strength:n,threshold:re(e.threshold,0,4,.8),radius:re(e.radius,0,2,.5)}}function xo(t){if(!t)return null;if(typeof t=="string")return{enabled:!0,color:vt(t,"#38bdf8"),thickness:3,pulse:!1};if(t===!0)return{enabled:!0,color:"#38bdf8",thickness:3,pulse:!1};let e=Ae(t);if(!e||e.enabled===!1)return null;let n=e.thickness??e.width;return{enabled:!0,color:vt(e.color,"#38bdf8"),thickness:re(typeof n=="number"&&n>0&&n<.25?Math.max(1.5,n*140):n,.5,20,3),pulse:e.pulse===!0}}function vo(t){let e=Ae(t);if(!e||e.enabled===!1)return null;let n=Nt(e.root),r=Nt(e.effector);if(!n||!r)return null;let i=Nt(e.mid),o=e.target,s;if(Je(o))s=[re(o[0],-1e3,1e3,0),re(o[1],-1e3,1e3,0),re(o[2],-1e3,1e3,0)];else{let u=Nt(o);if(!u)return null;s=u}let l=e.pole??e.poleTarget,a=Je(l)?[re(l[0],-1e3,1e3,0),re(l[1],-1e3,1e3,0),re(l[2],-1e3,1e3,0)]:Nt(l),c=e.solver==="fabrik"?"fabrik":e.solver==="two-bone"||i?"two-bone":"fabrik";return{root:n,...i?{mid:i}:{},effector:r,target:s,...a?{pole:a}:{},solver:c,iterations:Math.round(re(e.iterations,1,32,8)),tolerance:re(e.tolerance,1e-5,.1,.001),weight:re(e.weight,0,1,1)}}var ti=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),To=new Set(["capsule","cylindrical","spherical"]),Ht=[];function ni(t){Ht.includes(t)||Ht.push(t)}function fn(t){let e=Ae(t);if(!e)return null;let n=Array.isArray(e.traits)?e.traits:[],r=f=>n.includes(f),i={},o=e.grab;o==="1-hand"||o==="2-hand"?i.grab=o:(o===!0||e.grabbable===!0||r("grab"))&&(i.grab="2-hand"),i.grab&&(i.grabbable=!0);let s=e.scale??e.scalable;if(s||r("scale")){let f=Ae(s)??{},p=re(f.min,.001,1e3,.05);i.scale={min:p,max:re(f.max,p,1e3,Math.max(p,5))},i.scalable=!0}let l=e.billboard;typeof l=="string"&&To.has(l)?i.billboard=l:(l===!0||r("billboard"))&&(i.billboard="capsule");let a=e.follow,c=typeof a=="string"?a:Ae(a)?.mode;if(typeof a=="string"?a:Ae(a)?.lazy===!1)i.follow=c==="hand-left"||c==="hand-right"?c:"head";else{let f=Qi(a);f&&(i.follow=f)}let u=e.anchor;if(typeof u=="string"&&ti.has(u))i.anchor=u;else{let p=Ae(u)?.target;typeof p=="string"&&ti.has(p)&&(i.anchor=p);let _=rr(u)??rr(e.anchorPersist);_&&(i.anchorPersist=_)}if(!i.anchorPersist){let f=rr(e.anchorPersist);f&&(i.anchorPersist=f)}(e.physics==="dynamic"||e.physics==="static")&&(i.physics=e.physics);let d=Ji(e.orbit);d&&(i.orbit=d);let h=eo(e.handles);h&&(i.handles=h);let m=ro(e.particles);m&&(i.particles=m);let y=oo(e.holdToAsk);y&&(i.holdToAsk=y);let x=so(e.worldUnderstanding);x&&(i.worldUnderstanding=x);let M=ir(e.splatUrl);M&&(i.splatUrl=M),(e.splatQuality==="high"||e.splatQuality==="standard")&&(i.splatQuality=e.splatQuality);let L=Xe(e.spatialSlot);L&&(i.spatialSlot=L);let F=ao(e.audio);F&&(i.audio=F);let g=uo(e.dimensions);g&&(i.dimensions=g);let E=ho(e.snapTo);E&&(i.snapTo=E);let w=mo(e.snapSocket);w&&(i.snapSocket=w);let N=fo(e.gaze);N&&(i.gaze=N);let z=po(e.explode);z&&(i.explode=z);let R=bo(e.navigable);R&&(i.navigable=R);let C=yo(e.text);C&&(i.text=C);let I=go(e.bloom);I&&(i.bloom=I);let b=xo(e.outline);b&&(i.outline=b);let v=vo(e.ik);v&&(i.ik=v),typeof e.sync=="boolean"&&(i.sync=e.sync),e.pointerEvents==="none"&&(i.pointerEvents="none");for(let f of Ht)f.normalize(e,i);return Object.keys(i).length>0?i:null}function sr(t){let e={};if(t.grab&&(e.interactable={mode:t.grab},e.movable={systemMovable:!0,scaleInZ:!!t.scale,minScale:t.scale?.min??.05,maxScale:t.scale?.max??5}),t.billboard&&(e.billboard={mode:t.billboard}),typeof t.follow=="string"?e.follow={target:t.follow,lazy:!1}:t.follow&&(e.follow={target:t.follow.mode,lazy:!0,distance:t.follow.distance,deadzoneDeg:t.follow.deadzoneDeg,stiffness:t.follow.stiffness,height:t.follow.height,faceUser:t.follow.faceUser}),t.anchor||t.anchorPersist){let n={};t.anchor&&(n.planeType=t.anchor==="vertical"||t.anchor==="wall"?"VERTICAL":"HORIZONTAL",n.semanticType=t.anchor.toUpperCase()),t.anchorPersist&&(n.persist=t.anchorPersist.persist,t.anchorPersist.id&&(n.id=t.anchorPersist.id)),e.anchor=n}t.physics&&(e.rigidbody={type:t.physics}),t.orbit&&(e.orbit={...t.orbit}),t.handles&&(e.resizable={...t.handles}),t.particles&&(e.particles={...t.particles}),t.holdToAsk&&(e.holdToAsk={...t.holdToAsk}),t.worldUnderstanding&&(e.worldUnderstanding={...t.worldUnderstanding}),t.splatUrl&&(e.splat=t.splatQuality?{url:t.splatUrl,quality:t.splatQuality}:{url:t.splatUrl}),t.spatialSlot&&(e.spatialPanel={slot:t.spatialSlot}),t.audio&&(e.spatialAudio={...t.audio}),t.dimensions&&(e.dimensions={...t.dimensions,axes:[...t.dimensions.axes]}),t.snapTo&&(e.snapTo={...t.snapTo,grid:t.snapTo.grid?[...t.snapTo.grid]:null}),t.snapSocket&&(e.snapSocket={...t.snapSocket}),t.gaze&&(e.gaze={...t.gaze}),t.explode&&(e.explode={...t.explode,direction:t.explode.direction?[...t.explode.direction]:null}),t.navigable&&(e.navigable={mode:t.navigable}),t.text&&(e.text3d={...t.text}),t.bloom&&(e.bloom={...t.bloom}),t.outline&&(e.outline={...t.outline}),t.ik&&(e.ik={...t.ik,...Array.isArray(t.ik.target)?{target:[...t.ik.target]}:{},...Array.isArray(t.ik.pole)?{pole:[...t.ik.pole]}:{}}),typeof t.sync=="boolean"&&(e.sync={enabled:t.sync});for(let n of Ht)n.sceneCore(t,e);return e}function Mo(t){let e={},n=(r,i)=>{for(let[o,s]of Object.entries(i)){let l=r+o[0].toUpperCase()+o.slice(1);typeof s=="string"||typeof s=="number"||typeof s=="boolean"?e[l]=s:Je(s)&&(e[l]=[s[0],s[1],s[2]])}};t.grab&&(e.grab=t.grab),t.scale&&n("scale",t.scale),t.billboard&&(e.billboard=t.billboard),typeof t.follow=="string"?e.follow=t.follow:t.follow&&(e.follow=t.follow.mode,n("follow",{...t.follow,mode:void 0})),t.anchor&&(e.anchor=t.anchor),t.anchorPersist&&(e.anchorPersist=t.anchorPersist.persist,t.anchorPersist.id&&(e.anchorId=t.anchorPersist.id)),t.physics&&(e.physics=t.physics),t.orbit&&n("orbit",t.orbit),t.handles&&(e.handles=!0,n("handles",t.handles)),t.particles&&n("particles",t.particles),t.holdToAsk&&(e.holdToAsk=!0,n("holdToAsk",t.holdToAsk)),t.worldUnderstanding&&n("worldUnderstanding",t.worldUnderstanding),t.splatUrl&&(e.splatUrl=t.splatUrl),t.splatQuality&&(e.splatQuality=t.splatQuality),t.spatialSlot&&(e.spatialSlot=t.spatialSlot),t.audio&&n("audio",t.audio),t.dimensions&&n("dimensions",{...t.dimensions,axes:t.dimensions.axes.join("")}),t.snapTo&&(e.snapTo=!0,n("snapTo",t.snapTo)),t.snapSocket&&n("snapSocket",t.snapSocket),t.gaze&&n("gaze",t.gaze),t.explode&&n("explode",t.explode),t.navigable&&(e.navigable=t.navigable),t.text&&n("text",t.text),t.bloom&&n("bloom",t.bloom),t.outline&&n("outline",t.outline),t.ik&&n("ik",t.ik),typeof t.sync=="boolean"&&(e.sync=t.sync),t.pointerEvents&&(e.pointerEvents=t.pointerEvents);for(let r of Ht)r.usd(t,n,e);return e}function wo(t,e){let n=fn(e);if(!n)return;let r={...t.extras?.xr,...n};n.anchor===void 0&&typeof r.anchor=="object"&&delete r.anchor,t.extras={...t.extras,xr:r},t.extensions={...t.extensions,MOZ_hubs_components:ar(n),ANDROID_xr_scenecore:sr(n)}}function ar(t){let e={};return t.grab&&(e.grabbable={cursor:!0,hand:!0}),t.billboard&&(e.billboard={onlyY:t.billboard!=="spherical"}),e}function Ao(t,e){let n=fn(t),r=[];if(!n)return r;for(let[i,o]of Object.entries(Mo(n)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof o=="boolean"?r.push(`bool ${i} = ${o}`):typeof o=="number"?Number.isFinite(o)&&r.push(`double ${i} = ${o}`):typeof o=="string"?r.push(`string ${i} = "${e(o)}"`):o.length===3&&o.every(s=>Number.isFinite(s))&&r.push(`double3 ${i} = (${o.join(", ")})`));return r}function ri(){try{Object.defineProperty(_e(),"xrTraitSerializer",{value:Object.freeze({gltfNode:wo,usdLines:Ao}),writable:!1,configurable:!1,enumerable:!0})}catch{}}function ur(t){if(typeof t!="string")return;let e=t.trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(e)&&!or.has(e)?e:void 0}function dn(t,e,n){return typeof t=="string"&&e.includes(t)?t:n}var So=["third-person","first-person","top-down","fixed"],Eo=["idle","walk","run","jump"];function Ro(t){if(!t)return null;let e=Ae(t)??(typeof t=="string"?{cameraMode:t}:{});if(e.enabled===!1)return null;let n=re(e.radius,.05,5,.35),r=Ae(e.clips)??{},i={};for(let o of Eo){let s=Xe(r[o],128);s&&(i[o]=s)}return{speed:re(e.speed,.1,20,4),runMultiplier:re(e.runMultiplier,1,4,1.6),jumpVelocity:re(e.jumpVelocity,0,30,5.5),gravity:re(e.gravity,0,50,15),radius:n,height:re(e.height,n*2,10,Math.max(1.4,n*2)),cameraMode:dn(e.cameraMode,So,"third-person"),cameraDistance:re(e.cameraDistance,.5,50,3.5),cameraHeight:re(e.cameraHeight,-10,50,1.8),clips:i}}var _o=["patrol","chase","flee","wander","follow"],Co=32,cr="user";function Io(t){if(!t)return null;let e=Ae(t)??(typeof t=="string"?{mode:t}:{});if(e.enabled===!1)return null;let n=dn(e.mode,_o,"wander"),r=e.target,i=r==="camera"||r===cr?cr:Xe(r,256)??"";!i&&(n==="chase"||n==="flee"||n==="follow")&&(i=cr);let o=l=>re(l,-1e4,1e4,0),s=Array.isArray(e.waypoints)?e.waypoints.filter(Je).slice(0,Co).map(l=>[o(l[0]),o(l[1]),o(l[2])]):[];return{mode:n,target:i,speed:re(e.speed,.1,20,2),turnSpeed:re(e.turnSpeed,.1,50,6),sightRadius:re(e.sightRadius,0,100,6),stopDistance:re(e.stopDistance,.01,10,.6),separationRadius:re(e.separationRadius,0,10,.8),waypoints:s,loopWaypoints:e.loopWaypoints!==!1}}function Do(t){if(!t)return null;let e=Ae(t)??(typeof t=="number"?{max:t}:{});if(e.enabled===!1)return null;let n=re(e.max,1,1e6,100);return{max:n,current:re(e.current,0,n,n),group:ur(e.group)??"neutral",showBar:e.showBar===!0,cooldownMs:Math.round(re(e.cooldownMs,0,1e4,250)),hideOnDepleted:e.hideOnDepleted!==!1,scoreValue:re(e.scoreValue,-1e6,1e6,0),contactAmount:re(e.contactAmount,0,1e6,0)}}var Lo=16;function ko(t){if(!t)return null;let e=Ae(t)??(typeof t=="string"?{shape:t}:{});if(e.enabled===!1)return null;let n=dn(e.shape,["box","sphere"],"box"),r=e.size,i=d=>re(d,.01,1e3,1),o=Je(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[1,1,1],s=re(e.radius??(typeof r=="number"?r:void 0),.01,1e3,.5),l=e.watchGroups,a=[...new Set((Array.isArray(l)?l:l===void 0?[]:[l]).map(ur).filter(d=>d!==void 0))].slice(0,Lo),c={shape:n,size:o,radius:s,watchGroups:a},u=vt(e.color,"");return u?{...c,color:u}:c}var Po=32;function No(t){let e=Ae(t)??(typeof t=="string"?{template:t}:null),n=Xe(e?.template,256)?.trim();return!e||!n||e.enabled===!1?null:{template:n,intervalSec:re(e.intervalSec,.05,3600,3),maxActive:Math.round(re(e.maxActive,1,Po,8)),totalCount:Math.round(re(e.totalCount,0,1e4,0)),spawnRadius:re(e.spawnRadius,0,100,0)}}var Fo=["pickup","checkpoint","time-bonus","restore","key"];function Oo(t){if(!t)return null;let e=Ae(t)??(typeof t=="string"?{type:t}:{});if(e.enabled===!1)return null;let n=dn(e.type,Fo,"pickup"),r=n==="pickup";return{type:n,amount:re(e.amount??e.points,-1e6,1e6,10),tag:ur(e.tag)??"",radius:re(e.radius,.05,50,.65),required:e.required===!0,order:Math.round(re(e.order,0,1e3,0)),spinSpeed:re(e.spinSpeed,-50,50,r?2.5:0),bobAmplitude:re(e.bobAmplitude,0,5,r?.08:0),respawnSec:re(e.respawnSec,0,3600,0)}}var Uo=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],zo=["onTap","onObjective","onHit","onDepleted","onZoneEnter","onZoneExit","onSpawn","onJump","onLand"];function Vo(t){let e=Ae(t);if(!e)return null;let n={};for(let r of zo){let i=e[r];typeof i=="string"&&Uo.includes(i)&&(n[r]=i)}return Object.keys(n).length===0?null:{cues:n,pitchJitter:re(e.pitchJitter,0,.5,.08),volume:re(e.volume,0,1,1),spatial:e.spatial!==!1}}var Bo={normalize(t,e){let n=Ro(t.character);n&&(e.character=n);let r=Io(t.agent);r&&(e.agent=r);let i=Do(t.integrity);i&&(e.integrity=i);let o=ko(t.zone);o&&(e.zone=o);let s=No(t.spawner);s&&(e.spawner=s);let l=Oo(t.objective);l&&(e.objective=l);let a=Vo(t.audioCues);a&&(e.audioCues=a),t.collidable===!0&&(e.collidable=!0)},sceneCore(t,e){t.character&&(e.character={...t.character,clips:{...t.character.clips}}),t.agent&&(e.agent={...t.agent,waypoints:t.agent.waypoints.map(n=>[...n])}),t.integrity&&(e.integrity={...t.integrity}),t.zone&&(e.zone={...t.zone,size:[...t.zone.size],watchGroups:[...t.zone.watchGroups]}),t.spawner&&(e.spawner={...t.spawner}),t.objective&&(e.objective={...t.objective}),t.audioCues&&(e.audioCues={...t.audioCues,cues:{...t.audioCues.cues}}),t.collidable&&(e.collidable={enabled:!0})},usd(t,e,n){if(t.character){n.character=!0,e("character",{...t.character,clips:void 0});for(let[r,i]of Object.entries(t.character.clips))n["characterClip"+r[0].toUpperCase()+r.slice(1)]=i}t.agent&&(e("agent",{...t.agent,waypoints:void 0}),n.agentWaypointCount=t.agent.waypoints.length,t.agent.waypoints.forEach((r,i)=>{n[`agentWaypoint${i}`]=[r[0],r[1],r[2]]})),t.integrity&&(n.integrity=!0,e("integrity",t.integrity)),t.zone&&e("zone",{...t.zone,watchGroups:t.zone.watchGroups.join(",")}),t.spawner&&e("spawner",t.spawner),t.objective&&e("objective",t.objective),t.audioCues&&(e("audioCues",{...t.audioCues,cues:void 0}),e("audioCues",t.audioCues.cues)),t.collidable&&(n.collidable=!0)}};function ii(){ni(Bo)}var bn=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},De=class t{constructor(e=0,n=0,r=0){this.x=Number(e),this.y=Number(n),this.z=Number(r)}set(e,n,r){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(e,n){let r=e.x,i=e.y,o=e.z,s=n.x,l=n.y,a=n.z;return this.x=i*a-o*l,this.y=o*s-r*a,this.z=r*l-i*s,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let n=this.x,r=this.y,i=this.z,o=e.elements,s=1/(o[3]*n+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*n+o[4]*r+o[8]*i+o[12])*s,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*s,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*s,this}},yn=class{constructor(e=0,n=0,r=0,i=1){this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(e,n,r,i){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},$t=class t{constructor(e=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,n,r,i=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},jt=class t{constructor(e=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,n,r,i){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let r=e.x,i=e.y,o=e.z,s=Math.cos(r/2),l=Math.cos(i/2),a=Math.cos(o/2),c=Math.sin(r/2),u=Math.sin(i/2),d=Math.sin(o/2);return this._x=c*l*a+s*u*d,this._y=s*u*a-c*l*d,this._z=s*l*d+c*u*a,this._w=s*l*a-c*u*d,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,s=e.w,l=n.x,a=n.y,c=n.z,u=n.w;return this._x=r*u+s*l+i*c-o*a,this._y=i*u+s*a+o*l-r*c,this._z=o*u+s*c+r*a-i*l,this._w=s*u-r*l-i*a-o*c,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},rt=class t{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 t;return e.copy(this),e}compose(e,n,r){return xt(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return Ie(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return It(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let n=new De(0,0,0),r=new De(1,1,1);return this.compose(n,e,r)}makeTranslation(e,n,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(e,n,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},gn=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 He(this.elements,e.elements),this}},qe=class t{constructor(e,n,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(e,n,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,r){return this.r=Number(e),this.g=Number(n),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},hi={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},be=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;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/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,r,i){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},xn=class extends be{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},vn=class extends be{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},Tn=class extends be{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},Ye=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof be)this.index=e;else if(Array.isArray(e)){let n=0;for(let i=0;i<e.length;i++)e[i]>n&&(n=e[i]);let r=n>65535?new Uint32Array(e):new Uint16Array(e);this.index=new be(r,1)}else e&&e.buffer&&(this.index=new be(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let n=e.count,r=new Float32Array(n*3),i=new De,o=new De,s=new De,l=new De,a=new De;if(this.index){let c=this.index.array;for(let u=0;u<c.length;u+=3){let d=c[u],h=c[u+1],m=c[u+2];i.set(e.getX(d),e.getY(d),e.getZ(d)),o.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(m),e.getY(m),e.getZ(m)),l.subVectors(s,o),a.subVectors(i,o),l.cross(a).normalize();for(let y of[d,h,m])r[y*3]+=l.x,r[y*3+1]+=l.y,r[y*3+2]+=l.z}}else for(let c=0;c<n;c+=3){i.set(e.getX(c),e.getY(c),e.getZ(c)),o.set(e.getX(c+1),e.getY(c+1),e.getZ(c+1)),s.set(e.getX(c+2),e.getY(c+2),e.getZ(c+2)),l.subVectors(s,o),a.subVectors(i,o),l.cross(a).normalize();for(let u=0;u<3;u++)r[(c+u)*3]=l.x,r[(c+u)*3+1]=l.y,r[(c+u)*3+2]=l.z}for(let c=0;c<n;c++){let u=r[c*3],d=r[c*3+1],h=r[c*3+2],m=Math.hypot(u,d,h)||1;r[c*3]=u/m,r[c*3+1]=d/m,r[c*3+2]=h/m}return this.setAttribute("normal",new be(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new be(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new be(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new be(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}computeBoundingBox(){let e=this.attributes.position,n=new De(1/0,1/0,1/0),r=new De(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let i=0;i<e.count;i++){let o=e.getX(i),s=e.getY(i),l=e.getZ(i);o<n.x&&(n.x=o),s<n.y&&(n.y=s),l<n.z&&(n.z=l),o>r.x&&(r.x=o),s>r.y&&(r.y=s),l>r.z&&(r.z=l)}else n.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:n,max:r},this.boundingBox}center(){let e=this.computeBoundingBox(),n=(e.min.x+e.max.x)*.5,r=(e.min.y+e.max.y)*.5,i=(e.min.z+e.max.z)*.5,o=this.attributes.position;if(o&&o.count>0){for(let s=0;s<o.count;s++)o.setXYZ(s,o.getX(s)-n,o.getY(s)-r,o.getZ(s)-i);this.computeBoundingBox()}return this}dispose(){}},Yt=class extends Ye{constructor(e=1,n=1,r=1){super();{let d=globalThis.__three_live_native_box__;if(typeof d=="function"){let h=d(e,n,r);this.setFromBuffers(h.positions,h.normals,h.uvs,h.indices);return}}let i=e/2,o=n/2,s=r/2,l=[-i,-o,s,i,-o,s,i,o,s,-i,o,s,i,-o,-s,-i,-o,-s,-i,o,-s,i,o,-s,-i,o,s,i,o,s,i,o,-s,-i,o,-s,-i,-o,-s,i,-o,-s,i,-o,s,-i,-o,s,i,-o,s,i,-o,-s,i,o,-s,i,o,s,-i,-o,-s,-i,-o,s,-i,o,s,-i,o,-s],a=[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],c=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],u=[];for(let d=0;d<6;d++){let h=d*4;u.push(h,h+1,h+2,h,h+2,h+3)}this.setAttribute("position",new be(new Float32Array(l),3)),this.setAttribute("normal",new be(new Float32Array(a),3)),this.setAttribute("uv",new be(new Float32Array(c),2)),this.setIndex(u)}},Mn=class extends Ye{constructor(e=1,n=1){super();let r=e/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],s=[0,0,1,0,0,1,0,0,1,0,0,1],l=[0,1,1,1,0,0,1,0],a=[0,2,1,2,3,1];this.setAttribute("position",new be(new Float32Array(o),3)),this.setAttribute("normal",new be(new Float32Array(s),3)),this.setAttribute("uv",new be(new Float32Array(l),2)),this.setIndex(a)}},Kt=class extends Ye{constructor(e=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));{let c=globalThis.__three_live_native_sphere__;if(typeof c=="function"){let u=c(e,n,r);this.setAttribute("position",new be(u.positions,3)),this.setAttribute("normal",new be(u.normals,3)),this.setAttribute("uv",new be(u.uvs,2)),this.setIndex(u.indices);return}}let i=[],o=[],s=[],l=[],a=[];for(let c=0;c<=r;c++){let u=[],d=c/r;for(let h=0;h<=n;h++){let m=h/n,y=m*Math.PI*2,x=d*Math.PI,M=-e*Math.cos(y)*Math.sin(x),L=e*Math.cos(x),F=e*Math.sin(y)*Math.sin(x);i.push(M,L,F);let g=Math.hypot(M,L,F)||1;o.push(M/g,L/g,F/g),s.push(m,1-d),u.push(i.length/3-1)}a.push(u)}for(let c=0;c<r;c++)for(let u=0;u<n;u++){let d=a[c][u+1],h=a[c][u],m=a[c+1][u],y=a[c+1][u+1];c!==0&&l.push(d,h,y),c!==r-1&&l.push(h,m,y)}this.setAttribute("position",new be(new Float32Array(i),3)),this.setAttribute("normal",new be(new Float32Array(o),3)),this.setAttribute("uv",new be(new Float32Array(s),2)),this.setIndex(l)}},dt=class extends Ye{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));{let u=globalThis.__three_live_native_cylinder__;if(typeof u=="function"){let d=u(e,n,r,i);this.setAttribute("position",new be(d.positions,3)),this.setAttribute("normal",new be(d.normals,3)),this.setAttribute("uv",new be(d.uvs,2)),this.setIndex(d.indices);return}}let o=[],s=[],l=[],a=[],c=r/2;for(let u=0;u<=1;u++){let d=u,h=u===0?e:n,m=u===0?c:-c;for(let y=0;y<=i;y++){let x=y/i,M=x*Math.PI*2,L=Math.sin(M),F=Math.cos(M);o.push(h*L,m,h*F),s.push(L,0,F),l.push(x,1-d)}}for(let u=0;u<i;u++){let d=u,h=u+i+1,m=u+i+2,y=u+1;a.push(d,h,y,h,m,y)}if(e>0){let u=o.length/3;o.push(0,c,0),s.push(0,1,0),l.push(.5,.5);let d=o.length/3;for(let h=0;h<=i;h++){let m=h/i*Math.PI*2,y=Math.sin(m),x=Math.cos(m);o.push(e*y,c,e*x),s.push(0,1,0),l.push(x*.5+.5,y*.5+.5)}for(let h=0;h<i;h++)a.push(u,d+h,d+h+1)}if(n>0){let u=o.length/3;o.push(0,-c,0),s.push(0,-1,0),l.push(.5,.5);let d=o.length/3;for(let h=0;h<=i;h++){let m=h/i*Math.PI*2,y=Math.sin(m),x=Math.cos(m);o.push(n*y,-c,n*x),s.push(0,-1,0),l.push(x*.5+.5,1-(y*.5+.5))}for(let h=0;h<i;h++)a.push(u,d+h+1,d+h)}this.setAttribute("position",new be(new Float32Array(o),3)),this.setAttribute("normal",new be(new Float32Array(s),3)),this.setAttribute("uv",new be(new Float32Array(l),2)),this.setIndex(a)}},wn=class extends dt{constructor(e=1,n=1,r=16){super(0,e,n,r)}},An=class extends Ye{constructor(e=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],s=[],l=[],a=[];for(let c=0;c<=r;c++){let u=c/r*Math.PI*2;for(let d=0;d<=i;d++){let h=d/i*Math.PI*2,m=(e+n*Math.cos(u))*Math.cos(h),y=(e+n*Math.cos(u))*Math.sin(h),x=n*Math.sin(u);o.push(m,y,x);let M=e*Math.cos(h),L=e*Math.sin(h),F=m-M,g=y-L,E=x,w=Math.hypot(F,g,E)||1;s.push(F/w,g/w,E/w),l.push(d/i,c/r)}}for(let c=1;c<=r;c++)for(let u=1;u<=i;u++){let d=(i+1)*c+u-1,h=(i+1)*(c-1)+u-1,m=(i+1)*(c-1)+u,y=(i+1)*c+u;a.push(d,h,y,h,m,y)}this.setAttribute("position",new be(new Float32Array(o),3)),this.setAttribute("normal",new be(new Float32Array(s),3)),this.setAttribute("uv",new be(new Float32Array(l),2)),this.setIndex(a)}},Sn=class extends Ye{constructor(e=1,n=.4,r=64,i=8,o=2,s=3){super(),r=Math.floor(r),i=Math.floor(i);{let g=globalThis.__three_live_native_torus_knot__;if(typeof g=="function"){let E=g(e,n,r,i,o,s);this.setAttribute("position",new be(E.positions,3)),this.setAttribute("normal",new be(E.normals,3)),this.setAttribute("uv",new be(E.uvs,2)),this.setIndex(E.indices);return}}let l=[],a=[],c=[],u=[],d=new De,h=new De,m=new De,y=new De,x=new De;function M(g,E){let w=Math.cos(E),N=Math.sin(E),z=s/o*E,R=e*(2+Math.cos(z))*.5;g.set(R*w,R*N,e*Math.sin(z)*.5)}let L=[];for(let g=0;g<=i;++g){let E=g/i*Math.PI*2;L.push(-n*Math.cos(E),n*Math.sin(E),g/i)}for(let g=0;g<=r;++g){let E=g/r,w=E*o*Math.PI*2;M(d,w),M(h,w+.01),m.subVectors(h,d).normalize(),y.addVectors(d,h).normalize(),x.crossVectors(m,y).normalize(),y.crossVectors(x,m).normalize();for(let N=0;N<=i;++N){let z=N*3,R=L[z],C=L[z+1],I=L[z+2],b=R*y.x+C*x.x,v=R*y.y+C*x.y,f=R*y.z+C*x.z;l.push(d.x+b,d.y+v,d.z+f);let p=Math.hypot(b,v,f)||1;a.push(b/p,v/p,f/p),c.push(E,I)}}let F=i+1;for(let g=1;g<=r;g++){let E=F*(g-1),w=E+F;for(let N=1;N<=i;N++){let z=E+(N-1),R=w+(N-1),C=w+N,I=E+N;u.push(z,R,I,R,C,I)}}this.setAttribute("position",new be(new Float32Array(l),3)),this.setAttribute("normal",new be(new Float32Array(a),3)),this.setAttribute("uv",new be(new Float32Array(c),2)),this.setIndex(u)}},qt=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},En=class{load(e,n){let r=new qt(e);return n?.(r),r}};function Ve(t,e){return t!==void 0?Number(t):e}function lr(t,e){return t!==void 0?!!t:e}var Ke=class{constructor(e={}){this.name=e.name||"",this.color=new qe(e.color!==void 0?e.color:16777215),this.emissive=new qe(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=Ve(e.emissiveIntensity,1),this.roughness=Ve(e.roughness,.5),this.metalness=Ve(e.metalness,.1),this.opacity=Ve(e.opacity,1),this.transparent=lr(e.transparent,!1),this.wireframe=lr(e.wireframe,!1),this.side=Ve(e.side,2),this.doubleSided=lr(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=Ve(e.clearcoat,0),this.clearcoatRoughness=Ve(e.clearcoatRoughness,0),this.sheen=Ve(e.sheen,0),this.sheenColor=new qe(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=Ve(e.sheenRoughness,0),this.transmission=Ve(e.transmission,0),this.thickness=Ve(e.thickness,0),this.attenuationColor=new qe(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=Ve(e.attenuationDistance,1/0),this.ior=Ve(e.ior,1.5),this.dispersion=Ve(e.dispersion,0),this.iridescence=Ve(e.iridescence,0),this.iridescenceIOR=Ve(e.iridescenceIOR,1.3)}dispose(){}},pt=class extends Ke{},Rn=class extends Ke{},_n=class extends Ke{},Cn=class extends Ke{},In=class extends Ke{},We=class t{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 De,this.rotation=new $t,this.quaternion=new jt,this.scale=new De(1,1,1),this.matrix=new rt,this.matrixWorld=new rt,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,r,i)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){hr(this),(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,r){let i=typeof e=="object"?e:new De(e,n,r);this.updateMatrixWorld(!0);let o=new rt;o.lookAt(this.position,i,new De(0,1,0));let s=o.elements,l=s[0],a=s[4],c=s[8],u=s[1],d=s[5],h=s[9],m=s[2],y=s[6],x=s[10],M=l+d+x;if(M>0){let L=.5/Math.sqrt(M+1);this.quaternion.set((y-h)*L,(c-m)*L,(u-a)*L,.25/L)}}},Dn=class extends We{},Tt=class extends We{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof Ye?n:n?($e("unsupported geometry","BoxGeometry"),new Yt(.5,.5,.5)):new Ye,this.material=i instanceof Ke?i:i?($e("unsupported material","MeshStandardMaterial"),new pt({color:13421772})):new pt}};function hr(t){let e=_e().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var Zt=1e4,Ot=class extends Tt{constructor(n,r,i=1){super(n,r);this.instanceColor=null;this.isInstancedMesh=!0;let o=Number(i);if(!Number.isFinite(o)||o<0||o>Zt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${Zt})`);this.count=Math.floor(o);let s=new Float32Array(this.count*16);for(let l=0;l<this.count;l++){let a=l*16;s[a]=1,s[a+5]=1,s[a+10]=1,s[a+15]=1}this.instanceMatrix=new be(s,16)}setMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let l=0;l<16;l++){let a=Number(r.elements[l]);o[s+l]=Number.isFinite(a)?a:l%5===0?1:0}}getMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let l=0;l<16;l++)r.elements[l]=o[s+l]}setColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let l=new Float32Array(this.count*3);l.fill(1),this.instanceColor=new be(l,3)}let o=this.instanceColor.array,s=i*3;o[s]=Number.isFinite(r.r)?r.r:1,o[s+1]=Number.isFinite(r.g)?r.g:1,o[s+2]=Number.isFinite(r.b)?r.b:1}getColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){r.setRGB(1,1,1);return}let o=this.instanceColor.array,s=i*3;r.setRGB(o[s],o[s+1],o[s+2])}dispose(){}},bt=class extends We{constructor(e=16777215,n=1){super(),this.color=new qe(e),this.intensity=Number(n),this.type="directional"}},Qt=class extends bt{constructor(e,n){super(e,n),this.type="ambient"}},Ln=class extends bt{constructor(n,r){super(n,r);this.target=new We;this.type="directional"}},Jt=class extends bt{constructor(n,r,i=0,o=2){super(n,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},en=class extends We{},Ut=class extends en{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new De(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},Mt=class extends We{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return et.validate(this),kt(this)}toGLB(){return et.validate(this),Gt(this)}toUSDZ(){return et.validate(this),Pt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof Tt){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},mr=kt,fr=Gt,mi=Pt;var et=class{static validate(e){let n=0,r=0,i=0,o=new Set,s=(a,c,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${c}). Found: ${u}`)},l=(a,c)=>{if(!Number.isFinite(c))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(c)}), which cannot be bounds-checked.`);return c};e.traverse(a=>{if(hr(a),a instanceof Tt||a.geometry?.attributes?.position?.count){if(i++,i>1e3&&s("MESHES",1e3,i),a instanceof Ot){let u=l("instance",a.count);(u<0||u>Zt)&&s("INSTANCES",Zt,u)}let c=a.geometry;if(c){let u=0;if(c.attributes.position&&(u=l("vertex",c.attributes.position.count),n+=u,n>1e5&&s("VERTICES",1e5,n)),c.index){let d=l("index",c.index.count);r+=d,r>3e5&&s("INDICES",3e5,r);let h=c.index.array;if(h&&u>0){let m=Math.min(d,h.length);for(let y=0;y<m;y++){let x=h[y];if(!Number.isFinite(x)||x<0||x>=u)throw new Error(`SecurityError: Index buffer value (${String(x)}) out of vertex bounds [0, ${u}).`)}}}}if(a.material){let u=a.material;u.map&&o.add(u.map),u.normalMap&&o.add(u.normalMap),u.roughnessMap&&o.add(u.roughnessMap)}}}),o.size>16&&s("TEXTURES",16,o.size);for(let a of o){let c=a,u=c.image,d=Number(u?.width??c.width??0)||0,h=Number(u?.height??c.height??0)||0;(!Number.isFinite(d)||!Number.isFinite(h)||d>2048||h>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(d,h))}}},kn=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let r=new qe(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){et.validate(e);let i=(o,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(o,s):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),s={};for(let[l,a]of o.entries())s[l]=Array.from(a);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let o=mr(e),s=fr(e),l=(o.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:l,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[s.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function oi(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Pn=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=oi(),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 n=oi();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function Go(){}var Ft=new Proxy(Go,{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:Ft},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Ft,construct:()=>Ft}),si=(()=>{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 zt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function yt(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,zt());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 ai,Xt;function fi(t){if(!yt(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(Xt===void 0||ai!==n){ai=n;try{Xt=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!yt(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Xt=null}}return Xt?Xt.createScriptURL(t):t}function Ho(t){_e().sandboxEngineSrc=t}function dr(){let t=_e().sandboxEngineSrc;if(t)return t;if(si)return si;try{if(typeof document>"u")return null;let e=zt(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&yt(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Xo(){let t=dr();if(!t)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!yt(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,zt()).href}function Wo(t){_e().sandboxIframeSrc=t}function di(){let t=_e().sandboxIframeSrc;if(t)return t;let e=dr();if(!e||!yt(e))return null;let n=new URL(e,zt());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function $o(){let t=di();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!yt(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,zt()).href}function jo(t){_e().allowClientScripts=t}function pi(){return!!_e().allowClientScripts}function Yo(t){if(!yt(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,zt()).href}var Ko=["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 qo(t,e){let n=self,r=t.nonce,i=t.engineSrc,o=t.allowedScriptUrl,s=t.allowClientScripts,l=t.revoked,a=n.postMessage.bind(n);function c(N){a({type:"ERROR",nonce:r,message:String(N)})}let u=typeof n.importScripts=="function"?n.importScripts.bind(n):null,d=o,h=null;try{let N=i;if(typeof n.trustedTypes<"u"&&n.trustedTypes&&typeof n.trustedTypes.createPolicy=="function")try{let z={createScriptURL:function(C){if(C!==i&&(!o||C!==o))throw new TypeError("Disallowed worker importScripts URL");return C}};s&&(z.createScript=function(C){return String(C)});let R=n.trustedTypes.createPolicy("three-live#worker-boot",z);N=R.createScriptURL(i),o&&(d=R.createScriptURL(o)),s&&typeof R.createScript=="function"&&(h=R.createScript.bind(R))}catch{}u(N)}catch(N){c('Sandbox failed to load the Three-Live engine from "'+i+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(N&&N.message||N));return}let m=n.THREE;if(!m||typeof m.Scene!="function"){c('Sandbox loaded "'+i+'" 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(e)){let N=n.__THREE_LIVE_REGISTRY__;for(let z=0;z<e.length;z++)if(typeof e[z]=="function")try{e[z](m,N)}catch{}}for(let N=0;N<l.length;N++){let z=l[N],R=n;for(;R&&R!==Object.prototype;){if(R!==n)try{delete R[z]}catch{}try{Object.defineProperty(R,z,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{R=Object.getPrototypeOf(R)}catch{break}}}let y=Object.freeze({now:function(){return Date.now()}}),x=n;for(;x&&x!==Object.prototype;){if(x!==n)try{delete x.performance}catch{}try{Object.defineProperty(x,"performance",{value:y,writable:!1,configurable:!1,enumerable:!1})}catch{}try{x=Object.getPrototypeOf(x)}catch{break}}let M=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],L=!1;function F(N,z){if(N.type==="3D_MODEL_READY"){if(L)return;L=!0}N.nonce=r,z&&z.length?a(N,z):a(N)}let g=function(N,z){if(!N||M.indexOf(N.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+M.join(", ")+").");F(N,z)},E=n;for(;E&&E!==Object.prototype;){if(E===n||Object.prototype.hasOwnProperty.call(E,"postMessage"))try{Object.defineProperty(E,"postMessage",{value:g,writable:!1,configurable:!1})}catch{}try{E=Object.getPrototypeOf(E)}catch{break}}let w=!1;n.onmessage=function(N){let z=N&&N.data;if(!(!z||z.nonce!==r)&&!(z.type!=="EXECUTE"&&z.type!=="EXECUTE_URL")&&!w){w=!0;try{let R=new m.Scene,C=new m.PerspectiveCamera(60,1,.1,1e3),I=new m.WebGLRenderer({isSandboxed:!0});if(z.type==="EXECUTE_URL"){if(!o||z.scriptUrl!==o||typeof u!="function"){c("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let b=d||o,v=u;if(u=null,d=null,n.THREE=m,n.scene=R,n.camera=C,n.renderer=I,v(b),typeof n.__THREE_LIVE_SCENE__=="function"){let f=n.__THREE_LIVE_SCENE__(m,R,C,I);f&&typeof f.toGLB=="function"&&(R=f)}else n.scene&&typeof n.scene.toGLB=="function"&&(R=n.scene)}else{if(!s){c("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let b=h?(0,eval)(h(`(function (THREE, scene, camera, renderer) {
|
|
278
321
|
return (function () {
|
|
279
|
-
`+
|
|
322
|
+
`+z.script+`
|
|
280
323
|
})();
|
|
281
324
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
282
|
-
`+
|
|
283
|
-
})();`);m=null;let D=_(l,p,E,v);D&&typeof D.toGLB=="function"&&(p=D)}if(!A){l.SceneQuotaValidator&&l.SceneQuotaValidator.validate(p);let _=p.toGLB(),D=_ instanceof ArrayBuffer?_:_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);M({type:"3D_MODEL_READY",glbBuffer:D},[D])}h({type:"DONE",nonce:n})}catch(p){u(p&&p.message||p)}}},h({type:"READY",nonce:n})}function hn(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Ti};return`'use strict';(${wi.toString()})(${JSON.stringify(o)});`}function jn(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 Se=0;function qn(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Ei(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Si=1024,Ri=256;function Bn(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function mn(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Si)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!Bn(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let c=Object.create(null),h=i;for(let u of o){if(u.length>Ri||u==="__proto__"||u==="constructor"||u==="prototype")return null;let s=h[u];if(!Bn(s))return null;c[u]=s}return{type:"3D_UPDATE_TRANSFORMS",transforms:c}}return null}case"3D_MODEL_READY":{let i=n.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function Mi(t){let e=Ei(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Kn(t,e,n,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":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Ai(t,e,n,r){let i=qn(),o=hn(e,i,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),c=document.createElement("iframe");c.setAttribute("sandbox","allow-scripts"),c.setAttribute("aria-hidden","true"),c.tabIndex=-1,c.style.display="none",c.src=n,Se++;let h=!1,u=!1,s={modelDispatched:!1},a,m=()=>{if(h||u)return;let S=c.contentWindow;!S||typeof S.postMessage!="function"||(u=!0,S.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:t.script},"*"))},l=()=>{},f=S=>{if(h||!c.contentWindow||S.source!==c.contentWindow)return;let A=S.data;if(A&&typeof A=="object"&&A.type==="IFRAME_READY"){m();return}let M=mn(A,i);M&&Kn(M,r,l,s)};l=()=>{h||(h=!0,a!==void 0&&clearTimeout(a),Se=Math.max(0,Se-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",f),typeof c.remove=="function"?c.remove():c.parentNode&&c.parentNode.removeChild(c))},a=setTimeout(()=>{h||(l(),jn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",f),c.onload=()=>{m()},c.onerror=()=>{l(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let d=document.body||document.documentElement;if(!d||typeof d.appendChild!="function"){l();let S=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(S),S}return d.appendChild(c),{terminate:l}}function Vn(t,e,n,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Se>=32)return r(`SecurityError: ${Se} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=bi()}catch(l){let f=l instanceof Error?l.message:String(l);return r(f,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let l;try{l=gi()}catch(f){let d=f instanceof Error?f.message:String(f);return r(d,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Ai(t,i,l,n))}catch(f){return Promise.reject(f)}}let o=qn(),c=hn(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),h;try{let l=new Blob([c],{type:"application/javascript"}),f=URL.createObjectURL(l);try{let d=Wn(f);h=new Worker(d)}finally{URL.revokeObjectURL(f)}}catch(l){let f=l instanceof Error?l.message:String(l);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${f}`,"Security Error: Failed to start Worker sandbox.")}Se++;let u=!1,s={modelDispatched:!1},a,m=()=>{u||(u=!0,a!==void 0&&clearTimeout(a),Se=Math.max(0,Se-1),h.terminate())};return a=setTimeout(()=>{u||(m(),jn(n))},3e3),h.onmessage=l=>{let f=mn(l.data,o);f&&Kn(f,n,m,s)},h.onerror=l=>{m(),n.onError?.(new Error(`Worker execution error: ${l.message}`))},t.kind==="url"?h.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):h.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:m})}function Hn(t,e){return t==="none"||t==="unsafe-host-realm"?e(`SecurityError: sandbox="${t}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${t}" is not permitted.`):t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${t}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var Zn={execute(t,e,n,r){let i=(h,u)=>{let s=new Error(h);return n.onError?.(s),u&&n.onToast?.(u),Promise.reject(s)},o=Hn(e,i);if(o)return o;try{Mi(t)}catch(h){let u=h instanceof Error?h.message:String(h);return i(u,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Yn()?Vn({kind:"script",script:t},e,n,i):i(fn,pn)},executeUrl(t,e,n){let r=(c,h)=>{let u=new Error(c);return n.onError?.(u),h&&n.onToast?.(h),Promise.reject(u)},i=Hn(e,r);if(i)return i;let o;try{o=vi(t)}catch(c){let h=c instanceof Error?c.message:String(c);return r(h,"Security Error: disallowed scene script URL.")}return Vn({kind:"url",scriptUrl:o},e,n,r)}},kt=new Set;function se(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;kt.has(n)||(kt.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function Jn(){return Array.from(kt)}function dn(){kt.clear()}var et=class extends _e{constructor(e={}){se("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},Qn=et,De=class extends qe{constructor(e=1,n=0,r="PolyhedronGeometry"){se(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},Ft=class extends De{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},Ot=class extends De{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},zt=class extends De{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},Bt=class extends De{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},Vt=class extends Re{constructor(e=1,n=1,r=4,i=8){se("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},Ht=class extends Re{constructor(e=.5,n=1,r=16){se("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},Xt=class extends Re{constructor(e=1,n=16){se("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},Gt=class extends Je{constructor(n,r,i=0,o=Math.PI/3,c=0,h=2){se("SpotLight","PointLight");super(n,r,i,h);this.target=new oe;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=c}},tt=class extends Ze{constructor(e,n,r){se("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new me(n??4473924)}},er=tt,tr={Vector2:yt,Vector3:J,Vector4:gt,Euler:$e,Quaternion:Ye,Matrix4:be,Matrix3:xt,Color:me,MathUtils:Xn,BufferAttribute:G,Float32BufferAttribute:vt,Uint16BufferAttribute:Tt,Uint32BufferAttribute:wt,BufferGeometry:ue,BoxGeometry:je,PlaneGeometry:Et,SphereGeometry:qe,CylinderGeometry:Re,ConeGeometry:St,TorusGeometry:Rt,TorusKnotGeometry:Mt,IcosahedronGeometry:Ft,OctahedronGeometry:Ot,DodecahedronGeometry:zt,TetrahedronGeometry:Bt,CapsuleGeometry:Vt,RingGeometry:Ht,CircleGeometry:Xt,Texture:Ke,TextureLoader:At,Material:de,MeshStandardMaterial:_e,MeshBasicMaterial:_t,MeshLambertMaterial:Ct,MeshPhongMaterial:Dt,MeshPhysicalMaterial:It,ShaderMaterial:et,RawShaderMaterial:Qn,Object3D:oe,Group:Pt,Mesh:ke,Light:Me,AmbientLight:Ze,DirectionalLight:Lt,PointLight:Je,SpotLight:Gt,HemisphereLight:tt,RectAreaLight:er,Camera:Qe,PerspectiveCamera:Fe,Scene:Ce,WebGLRenderer:Ut,Clock:Nt,SceneQuotaValidator:fe,exportSceneToCanvas3D:cn,exportSceneToGLB:un,exportSceneToUSDZ:Gn,generateUSDZ:Jt,glbToUSDZ:dt,sceneToCanvas3D:Le,sceneToGLB:He,sceneToUSDZ:Ue,authorScriptRunner:Zn,getAuthorWarnings:Jn,clearAuthorWarnings:dn};Object.freeze(fe);Object.freeze(fe.prototype);Object.freeze(Ce.prototype);Object.freeze(tr);var nt=new Proxy(tr,{get:(t,e)=>e in t?t[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&se(`THREE.${e}`,"no-op proxy"),Ne),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")}}),We={name:"three_author",THREE:nt},_i=We,te=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof te.THREE>"u"&&(te.THREE=nt);typeof te.requestAnimationFrame!="function"&&(te.requestAnimationFrame=()=>(se("requestAnimationFrame","single-frame static evaluation"),0));typeof te.cancelAnimationFrame!="function"&&(te.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=nt,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=We,t.ThreeLivePlugins.three_author=We,t.ThreeLivePlugins["three-author"]=We}{Nn(),kn();let t=new Ce,e=new Fe(45,1,.1,1e3);e.position.set(0,2,5),te.scene=t,te.camera=e,typeof te.window>"u"&&(te.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof te.document>"u"&&(te.document={createElement:()=>({getContext:()=>Ne,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(te,"__three_live_reset_scene__",{value:function(){dn(),t=new Ce,e=new Fe(45,1,.1,1e3),e.position.set(0,2,5),te.scene=t,te.camera=e},writable:!1,configurable:!1});let r=function(u){if(u==null)return null;let s=2e4,a=new Set,m=(l,f)=>{if(--s<0||f>32)return;if(l===null||typeof l=="string"||typeof l=="boolean")return l;if(typeof l=="number")return Number.isFinite(l)?l:void 0;if(typeof l!="object"||a.has(l))return;a.add(l);let d;if(Array.isArray(l)){d=[];for(let S of l)d.push(m(S,f+1)??null)}else{d={};for(let S of Object.keys(l)){if(S==="__proto__"||S==="prototype"||S==="constructor")continue;let A=m(l[S],f+1);A!==void 0&&(d[S]=A)}}return a.delete(l),d};try{return m(u,0)??null}catch{return null}},i=15*1024,o=1e3*4,c=function(u){let s=pt(u);if(!s)return{};let a=JSON.stringify({...u,...s});return a.length>i&&(se(`userData.xr larger than ${i} characters`,"canonical XR traits only"),a=JSON.stringify(s)),{xr_normalized_json:a,xr_scenecore_json:JSON.stringify(nn(s)),xr_hubs_json:JSON.stringify(rn(s))}};Object.defineProperty(te,"__three_live_extract_scene_raw__",{value:function(){let u=[],s=[],a=[],m=[];function l(g){if(!g)return null;let T=m.indexOf(g);if(T===-1){m.push(g);let x="";g.map&&(typeof g.map=="string"?x=g.map:g.map.source?x=g.map.source:g.map.image&&(x=g.map.image)),s.push({name:g.name||`Material_${s.length}`,base_color:[g.color.r,g.color.g,g.color.b,g.opacity!==void 0?g.opacity:1],metallic:g.metalness!==void 0?g.metalness:.1,roughness:g.roughness!==void 0?g.roughness:.5,double_sided:g.side===2||g.doubleSided,base_color_texture:x||null,clearcoat:g.clearcoat||0,clearcoat_roughness:g.clearcoatRoughness||0,transmission:g.transmission||0,ior:g.ior!==void 0?g.ior:1.5,thickness:g.thickness||0}),T=s.length-1}return T}let f=(g,T)=>typeof g=="number"&&Number.isFinite(g)?g:T,d=[],S=[],A=!1,M=te.scene||t,P=new be().compose({x:f(M.position?.x,0),y:f(M.position?.y,0),z:f(M.position?.z,0)},{x:f(M.quaternion?.x,0),y:f(M.quaternion?.y,0),z:f(M.quaternion?.z,0),w:f(M.quaternion?.w,1)},{x:f(M.scale?.x,1),y:f(M.scale?.y,1),z:f(M.scale?.z,1)}),y=new Set([M]);{let g=new Set([M]),T=Array.isArray(M.children)?[...M.children]:[],x=0;for(;T.length>0&&x<=o;){let L=T.pop();if(!(!(L instanceof oe)||g.has(L))&&(g.add(L),x++,Array.isArray(L.children)))for(let I of L.children)T.push(I)}if(x>o)return{meshes:[],nodes:new Array(x),materials:[],lights:[]}}let w=[],b=(g,T)=>{let x=Array.isArray(g.children)?g.children:[];for(let L=x.length-1;L>=0;L--)w.push([x[L],T])};b(M,-1);let R=g=>{let T=[];for(let L=g;L>=0&&T.length<=d.length;L=d[L].parent)T.push(L);let x=P.clone();for(let L=T.length-1;L>=0;L--){let I=d[T[L]];x.multiply(new be().compose({x:I.translation[0],y:I.translation[1],z:I.translation[2]},{x:I.rotation[0],y:I.rotation[1],z:I.rotation[2],w:I.rotation[3]},{x:I.scale[0],y:I.scale[1],z:I.scale[2]}))}return x};for(;w.length>0;){let[g,T]=w.pop();if(!(g instanceof oe)||y.has(g))continue;y.add(g);let x=[f(g.position?.x,0),f(g.position?.y,0),f(g.position?.z,0)],L=[f(g.quaternion?.x,0),f(g.quaternion?.y,0),f(g.quaternion?.z,0),f(g.quaternion?.w,1)],I=[f(g.scale?.x,1),f(g.scale?.y,1),f(g.scale?.z,1)],H=-1,k=g.geometry,U=k?.attributes?.position;U&&U.array&&U.count>0&&(H=u.length,u.push({name:g.name||`Mesh_${u.length}`,raw_positions:U.array,raw_normals:k.attributes.normal?k.attributes.normal.array:null,raw_uvs:k.attributes.uv?k.attributes.uv.array:null,raw_indices:k.index?k.index.array:null,vertex_count:U.count,material_index:l(g.material instanceof de?g.material:null)}));let N=r(g.userData?.xr),C=!!g.userData?.xr&&N!==null,O=d.length;d.push({name:typeof g.name=="string"?g.name.slice(0,1024):"",parent:T,translation:x,rotation:L,scale:I,mesh:H,xr_traits_json:C?JSON.stringify(N):null,...C?c(N):{}});let F=r(g.userData?.interactivity);if(S.push(F),F&&(A=!0),d.length>o)break;if(g instanceof Me){let V=R(O).elements;a.push({light_type:g.type,color:[g.color.r,g.color.g,g.color.b],intensity:g.intensity,position:[f(V[12],0),f(V[13],0),f(V[14],0)]})}b(g,O)}let p=(g,T)=>g.every((x,L)=>x===T[L]),E=r({interactivity:M.userData?.interactivity,gltfExtensions:{KHR_interactivity:M.userData?.gltfExtensions?.KHR_interactivity}}),v=!!(E?.interactivity??E?.gltfExtensions?.KHR_interactivity),_=null;(A||v)&&(_=ot(d.map((g,T)=>({name:g.name,...g.mesh>=0?{mesh:g.mesh}:{},...p(g.translation,[0,0,0])?{}:{translation:g.translation},...p(g.rotation,[0,0,0,1])?{}:{rotation:g.rotation},...p(g.scale,[1,1,1])?{}:{scale:g.scale},extras:S[T]?{interactivity:S[T]}:void 0})),u.map(g=>({primitives:[{material:g.material_index??0}]})),E??void 0));let D=te.camera||e;return{meshes:u,nodes:d,materials:s,lights:a,interactivity_json:_?JSON.stringify(_):null,camera:{fov:D.fov||45,position:D.position?[D.position.x,D.position.y,D.position.z]:[0,2,5],target:D.target?[D.target.x,D.target.y,D.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var Ci=nt;return dr(Di);})();
|
|
325
|
+
`+z.script+`
|
|
326
|
+
})();`);h=null;let v=b(m,R,C,I);v&&typeof v.toGLB=="function"&&(R=v)}if(!L){m.SceneQuotaValidator&&m.SceneQuotaValidator.validate(R);let b=R.toGLB(),v=b instanceof ArrayBuffer?b:b.buffer.slice(b.byteOffset,b.byteOffset+b.byteLength);F({type:"3D_MODEL_READY",glbBuffer:v},[v])}a({type:"DONE",nonce:r})}catch(R){c(R&&R.message||R)}}},a({type:"READY",nonce:r})}function pr(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Ko},s=(_e().workerExtensionInstallers??[]).map(l=>`(${l.toString()})`).join(",");return`'use strict';(${qo.toString()})(${JSON.stringify(o)},[${s}]);`}function bi(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 ft=0;function yi(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Zo(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Qo=1024,Jo=256;function ci(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function br(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Qo)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!ci(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let s=Object.create(null),l=i;for(let a of o){if(a.length>Jo||a==="__proto__"||a==="constructor"||a==="prototype")return null;let c=l[a];if(!ci(c))return null;s[a]=c}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let i=n.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function es(t){let e=Zo(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function gi(t,e,n,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":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function ts(t,e,n,r){let i=yi(),o=pr(e,i,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),s=document.createElement("iframe");s.setAttribute("sandbox","allow-scripts"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.style.display="none",s.src=n,ft++;let l=!1,a=!1,c={modelDispatched:!1},u,d=()=>{if(l||a)return;let x=s.contentWindow;!x||typeof x.postMessage!="function"||(a=!0,x.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:t.script},"*"))},h=()=>{},m=x=>{if(l||!s.contentWindow||x.source!==s.contentWindow)return;let M=x.data;if(M&&typeof M=="object"&&M.type==="IFRAME_READY"){d();return}let L=br(M,i);L&&gi(L,r,h,c)};h=()=>{l||(l=!0,u!==void 0&&clearTimeout(u),ft=Math.max(0,ft-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",m),typeof s.remove=="function"?s.remove():s.parentNode&&s.parentNode.removeChild(s))},u=setTimeout(()=>{l||(h(),bi(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",m),s.onload=()=>{d()},s.onerror=()=>{h(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let y=document.body||document.documentElement;if(!y||typeof y.appendChild!="function"){h();let x=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(x),x}return y.appendChild(s),{terminate:h}}function ui(t,e,n,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(ft>=32)return r(`SecurityError: ${ft} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=Xo()}catch(h){let m=h instanceof Error?h.message:String(h);return r(m,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let h;try{h=$o()}catch(m){let y=m instanceof Error?m.message:String(m);return r(y,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(ts(t,i,h,n))}catch(m){return Promise.reject(m)}}let o=yi(),s=pr(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let h=new Blob([s],{type:"application/javascript"}),m=URL.createObjectURL(h);try{let y=fi(m);l=new Worker(y)}finally{URL.revokeObjectURL(m)}}catch(h){let m=h instanceof Error?h.message:String(h);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${m}`,"Security Error: Failed to start Worker sandbox.")}ft++;let a=!1,c={modelDispatched:!1},u,d=()=>{a||(a=!0,u!==void 0&&clearTimeout(u),ft=Math.max(0,ft-1),l.terminate())};return u=setTimeout(()=>{a||(d(),bi(n))},3e3),l.onmessage=h=>{let m=br(h.data,o);m&&gi(m,n,d,c)},l.onerror=h=>{d(),n.onError?.(new Error(`Worker execution error: ${h.message}`))},t.kind==="url"?l.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):l.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:d})}function li(t,e){return t==="none"||t==="unsafe-host-realm"?e(`SecurityError: sandbox="${t}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${t}" is not permitted.`):t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${t}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var xi={execute(t,e,n,r){let i=(l,a)=>{let c=new Error(l);return n.onError?.(c),a&&n.onToast?.(a),Promise.reject(c)},o=li(e,i);if(o)return o;try{es(t)}catch(l){let a=l instanceof Error?l.message:String(l);return i(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??pi()?ui({kind:"script",script:t},e,n,i):i(Ir,Dr)},executeUrl(t,e,n){let r=(s,l)=>{let a=new Error(s);return n.onError?.(a),l&&n.onToast?.(l),Promise.reject(a)},i=li(e,r);if(i)return i;let o;try{o=Yo(t)}catch(s){let l=s instanceof Error?s.message:String(s);return r(l,"Security Error: disallowed scene script URL.")}return ui({kind:"url",scriptUrl:o},e,n,r)}},Nn=new Set;function $e(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;Nn.has(n)||(Nn.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function vi(){return Array.from(Nn)}function yr(){Nn.clear()}var tn=class extends pt{constructor(e={}){$e("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},Ti=tn,wt=class extends Kt{constructor(e=1,n=0,r="PolyhedronGeometry"){$e(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},Fn=class extends wt{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},On=class extends wt{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},Un=class extends wt{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},zn=class extends wt{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},Vn=class extends dt{constructor(e=1,n=1,r=4,i=8){$e("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},Bn=class extends dt{constructor(e=.5,n=1,r=16){$e("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},Gn=class extends dt{constructor(e=1,n=16){$e("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},Hn=class extends Jt{constructor(n,r,i=0,o=Math.PI/3,s=0,l=2){$e("SpotLight","PointLight");super(n,r,i,l);this.target=new We;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=s}},nn=class extends Qt{constructor(e,n,r){$e("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new qe(n??4473924)}},Mi=nn,wi={Vector2:bn,Vector3:De,Vector4:yn,Euler:$t,Quaternion:jt,Matrix4:rt,Matrix3:gn,Color:qe,MathUtils:hi,BufferAttribute:be,Float32BufferAttribute:xn,Uint16BufferAttribute:vn,Uint32BufferAttribute:Tn,BufferGeometry:Ye,BoxGeometry:Yt,PlaneGeometry:Mn,SphereGeometry:Kt,CylinderGeometry:dt,ConeGeometry:wn,TorusGeometry:An,TorusKnotGeometry:Sn,IcosahedronGeometry:Fn,OctahedronGeometry:On,DodecahedronGeometry:Un,TetrahedronGeometry:zn,CapsuleGeometry:Vn,RingGeometry:Bn,CircleGeometry:Gn,Texture:qt,TextureLoader:En,Material:Ke,MeshStandardMaterial:pt,MeshBasicMaterial:Rn,MeshLambertMaterial:_n,MeshPhongMaterial:Cn,MeshPhysicalMaterial:In,ShaderMaterial:tn,RawShaderMaterial:Ti,Object3D:We,Group:Dn,Mesh:Tt,InstancedMesh:Ot,Light:bt,AmbientLight:Qt,DirectionalLight:Ln,PointLight:Jt,SpotLight:Hn,HemisphereLight:nn,RectAreaLight:Mi,Camera:en,PerspectiveCamera:Ut,Scene:Mt,WebGLRenderer:kn,Clock:Pn,SceneQuotaValidator:et,exportSceneToCanvas3D:mr,exportSceneToGLB:fr,exportSceneToUSDZ:mi,generateUSDZ:nr,glbToUSDZ:mn,sceneToCanvas3D:kt,sceneToGLB:Gt,sceneToUSDZ:Pt,authorScriptRunner:xi,getAuthorWarnings:vi,clearAuthorWarnings:yr};Object.freeze(et);Object.freeze(et.prototype);Object.freeze(Mt.prototype);Object.freeze(wi);var it=new Proxy(wi,{get:(t,e)=>{if(e in t)return t[e];let n=_e().authorNamespace;return n&&typeof e=="string"&&e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&$e(`THREE.${e}`,"no-op proxy"),Ft)},has:(t,e)=>{if(e in t)return!0;let n=_e().authorNamespace;return!!(n&&typeof e=="string"&&e in n)},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")}}),pn=_e();pn.threeNamespace=it;if(pn.workerExtensionInstallers)for(let t of pn.workerExtensionInstallers)t(it,pn);var Wt={name:"three_author",THREE:it},ns=Wt,Oe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Oe.THREE>"u"&&(Oe.THREE=it);typeof Oe.requestAnimationFrame!="function"&&(Oe.requestAnimationFrame=()=>($e("requestAnimationFrame","single-frame static evaluation"),0));typeof Oe.cancelAnimationFrame!="function"&&(Oe.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=it,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=Wt,t.ThreeLivePlugins.three_author=Wt,t.ThreeLivePlugins["three-author"]=Wt}{ri(),ii(),Pr(it,_e()),jn(it,_e());let t=new Mt,e=new Ut(45,1,.1,1e3);e.position.set(0,2,5),Oe.scene=t,Oe.camera=e,typeof Oe.window>"u"&&(Oe.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof Oe.document>"u"&&(Oe.document={createElement:()=>({getContext:()=>Ft,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(Oe,"__three_live_reset_scene__",{value:function(){yr(),t=new Mt,e=new Ut(45,1,.1,1e3),e.position.set(0,2,5),Oe.scene=t,Oe.camera=e},writable:!1,configurable:!1});let r=function(a){if(a==null)return null;let c=2e4,u=new Set,d=(h,m)=>{if(--c<0||m>32)return;if(h===null||typeof h=="string"||typeof h=="boolean")return h;if(typeof h=="number")return Number.isFinite(h)?h:void 0;if(typeof h!="object"||u.has(h))return;u.add(h);let y;if(Array.isArray(h)){y=[];for(let x of h)y.push(d(x,m+1)??null)}else{y={};for(let x of Object.keys(h)){if(x==="__proto__"||x==="prototype"||x==="constructor")continue;let M=d(h[x],m+1);M!==void 0&&(y[x]=M)}}return u.delete(h),y};try{return d(a,0)??null}catch{return null}},i=15*1024,o=1e3*4,s=function(a){let c=fn(a);if(!c)return{};let u=JSON.stringify({...a,...c});return u.length>i&&($e(`userData.xr larger than ${i} characters`,"canonical XR traits only"),u=JSON.stringify(c)),{xr_normalized_json:u,xr_scenecore_json:JSON.stringify(sr(c)),xr_hubs_json:JSON.stringify(ar(c))}};Object.defineProperty(Oe,"__three_live_extract_scene_raw__",{value:function(){let a=[],c=[],u=[],d=[];function h(f){if(!f)return null;let p=d.indexOf(f);if(p===-1){d.push(f);let _="";f.map&&(typeof f.map=="string"?_=f.map:f.map.source?_=f.map.source:f.map.image&&(_=f.map.image)),c.push({name:f.name||`Material_${c.length}`,base_color:[f.color.r,f.color.g,f.color.b,f.opacity!==void 0?f.opacity:1],metallic:f.metalness!==void 0?f.metalness:.1,roughness:f.roughness!==void 0?f.roughness:.5,double_sided:f.side===2||f.doubleSided,base_color_texture:_||null,clearcoat:f.clearcoat||0,clearcoat_roughness:f.clearcoatRoughness||0,transmission:f.transmission||0,ior:f.ior!==void 0?f.ior:1.5,thickness:f.thickness||0}),p=c.length-1}return p}let m=(f,p)=>typeof f=="number"&&Number.isFinite(f)?f:p,y=[],x=[],M=[],L=!1,F=Oe.scene||t,g=new rt().compose({x:m(F.position?.x,0),y:m(F.position?.y,0),z:m(F.position?.z,0)},{x:m(F.quaternion?.x,0),y:m(F.quaternion?.y,0),z:m(F.quaternion?.z,0),w:m(F.quaternion?.w,1)},{x:m(F.scale?.x,1),y:m(F.scale?.y,1),z:m(F.scale?.z,1)}),E=new Set([F]);{let f=new Set([F]),p=Array.isArray(F.children)?[...F.children]:[],_=0;for(;p.length>0&&_<=o;){let H=p.pop();if(!(!(H instanceof We)||f.has(H))&&(f.add(H),_++,Array.isArray(H.children)))for(let U of H.children)p.push(U)}if(_>o)return{meshes:[],nodes:new Array(_),materials:[],lights:[]}}let w=[],N=(f,p)=>{let _=Array.isArray(f.children)?f.children:[];for(let H=_.length-1;H>=0;H--)w.push([_[H],p])};N(F,-1);let z=f=>{let p=[];for(let H=f;H>=0&&p.length<=y.length;H=y[H].parent)p.push(H);let _=g.clone();for(let H=p.length-1;H>=0;H--){let U=y[p[H]];_.multiply(new rt().compose({x:U.translation[0],y:U.translation[1],z:U.translation[2]},{x:U.rotation[0],y:U.rotation[1],z:U.rotation[2],w:U.rotation[3]},{x:U.scale[0],y:U.scale[1],z:U.scale[2]}))}return _};for(;w.length>0;){let[f,p]=w.pop();if(!(f instanceof We)||E.has(f))continue;E.add(f);let _=[m(f.position?.x,0),m(f.position?.y,0),m(f.position?.z,0)],H=[m(f.quaternion?.x,0),m(f.quaternion?.y,0),m(f.quaternion?.z,0),m(f.quaternion?.w,1)],U=[m(f.scale?.x,1),m(f.scale?.y,1),m(f.scale?.z,1)];hr(f);let Q=-1,$=f.geometry,K=$?.attributes?.position;if(K&&K.array&&K.count>0){Q=a.length;let V=null,J=f.userData?.variants;if(J&&typeof J=="object"){let ce=new Map;for(let se of Object.keys(J)){if(!se||se==="__proto__"||se==="constructor"||se==="prototype")continue;let fe=J[se],xe=fe instanceof Ke?fe:fe&&typeof fe=="object"?new pt(fe):null;if(!xe)continue;let Se=x.indexOf(se);if(Se===-1&&x.length<256&&(Se=x.length,x.push(se)),Se===-1)continue;let pe=h(xe);if(pe!==null){let S=ce.get(pe);S||(S=[],ce.set(pe,S)),S.push(Se)}}if(ce.size>0){let se=[];for(let[fe,xe]of ce.entries())se.push({material:fe,variants:xe});V=JSON.stringify({mappings:se})}}a.push({name:f.name||`Mesh_${a.length}`,raw_positions:K.array,raw_normals:$.attributes.normal?$.attributes.normal.array:null,raw_uvs:$.attributes.uv?$.attributes.uv.array:null,raw_indices:$.index?$.index.array:null,vertex_count:K.count,material_index:h(f.material instanceof Ke?f.material:null),variant_mappings_json:V})}let P=r(f.userData?.xr),ne=!!f.userData?.xr&&P!==null,Z=y.length,q=f instanceof Ot&&f.count>0&&f.instanceMatrix?.array;y.push({name:typeof f.name=="string"?f.name.slice(0,1024):"",parent:p,translation:_,rotation:H,scale:U,mesh:Q,xr_traits_json:ne?JSON.stringify(P):null,...ne?s(P):{},...q?{instance_matrices:f.instanceMatrix.array.subarray(0,f.count*16),instance_colors:f.instanceColor?.array?f.instanceColor.array.subarray(0,f.count*3):null}:{}});let ae=r(f.userData?.interactivity);if(M.push(ae),ae&&(L=!0),y.length>o)break;if(f instanceof bt){let V=z(Z).elements;u.push({light_type:f.type,color:[f.color.r,f.color.g,f.color.b],intensity:f.intensity,position:[m(V[12],0),m(V[13],0),m(V[14],0)]})}N(f,Z)}let R=(f,p)=>f.every((_,H)=>_===p[H]),C=r({interactivity:F.userData?.interactivity,gltfExtensions:{KHR_interactivity:F.userData?.gltfExtensions?.KHR_interactivity}}),I=!!(C?.interactivity??C?.gltfExtensions?.KHR_interactivity),b=null;(L||I)&&(b=rn(y.map((f,p)=>({name:f.name,...f.mesh>=0?{mesh:f.mesh}:{},...R(f.translation,[0,0,0])?{}:{translation:f.translation},...R(f.rotation,[0,0,0,1])?{}:{rotation:f.rotation},...R(f.scale,[1,1,1])?{}:{scale:f.scale},extras:M[p]?{interactivity:M[p]}:void 0})),a.map(f=>({primitives:[{material:f.material_index??0}]})),C??void 0));let v=Oe.camera||e;return{meshes:a,nodes:y,materials:c,lights:u,interactivity_json:b?JSON.stringify(b):null,variants_json:x.length>0?JSON.stringify({variants:x.map(f=>({name:f}))}):null,camera:{fov:v.fov||45,position:v.position?[v.position.x,v.position.y,v.position.z]:[0,2,5],target:v.target?[v.target.x,v.target.y,v.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var rs=it;return Di(is);})();
|