three-live 1.2.4 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/three-author-engine.js +28 -26
- package/dist/three-author.cjs +29 -27
- package/dist/three-author.d.ts +22 -0
- package/dist/three-author.js +29 -27
- package/dist/three-convert.cjs +21 -19
- package/dist/three-convert.d.ts +22 -0
- package/dist/three-convert.js +21 -19
- package/dist/three-live-animation.cjs +4 -4
- package/dist/three-live-animation.d.ts +22 -0
- package/dist/three-live-animation.js +4 -4
- package/dist/three-live-animation.min.js +4 -4
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +22 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +5 -3
- package/dist/three-live-element.d.ts +22 -0
- package/dist/three-live-element.js +5 -3
- package/dist/three-live-full.cjs +48 -46
- package/dist/three-live-full.js +47 -45
- package/dist/three-live-full.min.js +48 -46
- package/dist/three-live-studio.cjs +10 -10
- package/dist/three-live-studio.d.ts +22 -0
- package/dist/three-live-studio.js +10 -10
- package/dist/three-live-studio.min.js +10 -10
- package/dist/three-live-viewer.cjs +5 -3
- package/dist/three-live-viewer.d.ts +22 -0
- package/dist/three-live-viewer.js +5 -3
- package/dist/three-live-viewer.min.js +5 -3
- package/dist/three-live.cjs +23 -21
- package/dist/three-live.js +25 -23
- package/dist/three-live.min.js +23 -21
- package/dist/three-view.cjs +8 -6
- package/dist/three-view.d.ts +22 -0
- package/dist/three-view.js +8 -6
- package/dist/three-xr.cjs +24 -22
- package/dist/three-xr.d.ts +22 -0
- package/dist/three-xr.js +24 -22
- package/package.json +1 -1
package/dist/three-author.js
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
function Zt(n,e,t){let r=[],i=new Map,s=[],o=[],l=[],a=new Map,u=f=>{let R=i.get(f);return R===void 0&&(R=r.length,r.push({op:f}),i.set(f,R)),R},c=f=>{let R=a.get(f);return R===void 0&&(R=l.length,l.push({id:f}),a.set(f,R)),R},h=(f,R={})=>s.push({declaration:u(f),...R})-1,m=(f,R,g)=>o.push({id:f,type:R,value:g})-1,b=f=>({node:f,socket:"value"}),p=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(p&&typeof p=="object"){let f=Array.isArray(p.graphs)?p.graphs[p.graph??0]:p;if(f&&Array.isArray(f.nodes)){let R=Array.isArray(f.declarations)?f.declarations:[];for(let g of R)g?.op&&u(g.op);Array.isArray(f.variables)&&o.push(...f.variables);for(let g of f.events||[])g?.id&&c(g.id);for(let g of f.nodes){if(!g||typeof g!="object")continue;let A=g.op||(typeof g.declaration=="number"?R[g.declaration]?.op:"");s.push(A?{...g,declaration:u(A)}:{...g})}}}let x=(f,R,g="translation")=>g==="baseColorFactor"||g==="metallicFactor"||g==="roughnessFactor"?`/materials/${Math.max(0,R)}/pbrMetallicRoughness/${g}`:g==="emissiveFactor"||g==="alphaCutoff"?`/materials/${Math.max(0,R)}/${g}`:g==="visible"?`/nodes/${f}/extensions/KHR_node_visibility/visible`:`/nodes/${f}/${g}`,T=new Map;n.forEach((f,R)=>{typeof f?.name=="string"&&!T.has(f.name)&&T.set(f.name,R)});let I=(f,R)=>typeof f.target=="string"&&T.has(f.target)?T.get(f.target):typeof f.targetNode=="number"?f.targetNode:R,N=f=>{let R=n[f];return(typeof R?.mesh=="number"?e[R.mesh]?.primitives?.[0]?.material:0)??0};for(let f=0;f<n.length;f++){let R=n[f],g=R?.extras?.interactivity;if(!g||typeof g!="object")continue;let A=(typeof R.mesh=="number"?e[R.mesh]?.primitives?.[0]?.material:0)??0,D=w=>{let C=Array.isArray(w)?w:[w],d=[];for(let S=0;S<C.length;S++){let M=C[S];if(!M||typeof M!="object")continue;let E=M.action||"interpolate",P=typeof M.duration=="number"?M.duration:.35;if(E==="toggleTransform"){let F=M.property==="rotation"||M.property==="scale"?M.property:"translation",B=F==="rotation"?R.rotation||[0,0,0,1]:F==="scale"?R.scale||[1,1,1]:R.translation||[0,0,0],k=`/nodes/${f}/${F}`,O=m(`__toggle_${f}_${S}`,"bool",!1),_=h("variable/get",{configuration:{variable:O}}),G=h("math/not",{values:{a:b(_)}}),z=h("variable/set",{configuration:{variable:O},values:{value:b(G)}}),U=h("pointer/interpolate",{configuration:{pointer:k},values:{value:{value:Array.isArray(M.to)?M.to:B},duration:{value:P}}}),H=h("pointer/interpolate",{configuration:{pointer:k},values:{value:{value:Array.isArray(M.from)?M.from:B},duration:{value:P}}});s[z].flows={out:{node:h("flow/branch",{values:{condition:b(_)},flows:{true:{node:U},false:{node:H}}})}},d.push(z)}else if(E==="interpolate"){let F=M.to??M.value;if(F===void 0)continue;let B={value:{value:F},duration:{value:P}};M.from!==void 0&&(B.from={value:M.from}),d.push(h("pointer/interpolate",{configuration:{pointer:typeof M.pointer=="string"?M.pointer:x(I(M,f),N(I(M,f)),M.property)},values:B}))}else if(E==="setProperty"){if(M.value===void 0)continue;d.push(h("pointer/set",{configuration:{pointer:typeof M.pointer=="string"?M.pointer:x(I(M,f),N(I(M,f)),M.property)},values:{value:{value:M.value}}}))}else if(E==="toggleVisibility"){let F=I(M,f),B=m(`__vis_${F}_${S}`,"bool",!0),k=h("variable/get",{configuration:{variable:B}}),O=h("math/not",{values:{a:b(k)}}),_=h("variable/set",{configuration:{variable:B},values:{value:b(O)}});s[_].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${F}/extensions/KHR_node_visibility/visible`},values:{value:b(k)}})}},d.push(_)}else if(E==="cycleMaterialColor"&&Array.isArray(M.colors)&&M.colors.length>0){let F=typeof M.duration=="number"?M.duration:.25,B=`/materials/${Math.max(0,A)}/pbrMetallicRoughness/baseColorFactor`,k=m(`__color_idx_${f}_${S}`,"int",0),O=h("variable/get",{configuration:{variable:k}}),_=h("math/add",{values:{a:b(O),b:{value:1}}}),G=h("math/rem",{values:{a:b(_),b:{value:M.colors.length}}}),z=h("variable/set",{configuration:{variable:k},values:{value:b(G)}}),U={};for(let H=0;H<M.colors.length;H++){let L=M.colors[H],V=Array.isArray(L)&&L.length>=3?[L[0],L[1],L[2],L[3]??1]:[1,1,1,1];U[String(H)]={node:F>0?h("pointer/interpolate",{configuration:{pointer:B},values:{value:{value:V},duration:{value:F}}}):h("pointer/set",{configuration:{pointer:B},values:{value:{value:V}}})}}s[z].flows={out:{node:h("flow/switch",{values:{selection:b(O)},flows:U})}},d.push(z)}else if(E==="playAnimation")d.push(h("animation/start",{configuration:{animation:M.animation??M.clip??0}}));else if(E==="stopAnimation")d.push(h("animation/stop"));else if(E==="sendEvent"){let F={};for(let[B,k]of Object.entries(M.values||{}))F[B]={value:k};d.push(h("event/send",{configuration:{event:c(String(M.event??M.id??"custom"))},values:F}))}}if(!d.length)return null;if(d.length===1)return d[0];let y={};return d.forEach((S,M)=>{y[String(M)]={node:S}}),h("flow/sequence",{flows:y})},v=(w,C,d)=>{let y=D(C);y!==null&&h(w,{...d?{configuration:d}:{},flows:{out:{node:y}}})};if(g.onSelect&&v("pointer/onSelect",g.onSelect,{nodeIndex:f}),g.onHoverIn&&v("pointer/onHoverIn",g.onHoverIn,{nodeIndex:f}),g.onHoverOut&&v("pointer/onHoverOut",g.onHoverOut,{nodeIndex:f}),g.onStart&&v("event/onStart",g.onStart),g.onReceive&&typeof g.onReceive=="object")for(let[w,C]of Object.entries(g.onReceive))v("event/receive",C,{event:c(w)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:o,events:l}],graph:0}:null}var Jt='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).',Qt="Security Error: client-side scripts require allow-client-scripts opt-in.";var ze="__THREE_LIVE_REGISTRY__";function ee(){let n=typeof globalThis<"u"?globalThis:{};if(!n[ze]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,ze,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[ze]=e}}return n[ze]}var se=ee().plugins;function en(n){let e=ee().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function tn(){return ee().plugins}function Q(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function Ge(n,e,t,r,i){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let o=1/(r-i);return n[10]=(i+r)*o,n[14]=2*i*r*o,n}function Ee(n,e,t,r){let[i,s,o]=e,[l,a,u]=r,[c,h,m]=t,b=i-c,p=s-h,x=o-m,T=Math.hypot(b,p,x);T<=1e-5?(b=0,p=0,x=1):(b/=T,p/=T,x/=T);let I=a*x-u*p,N=u*b-l*x,f=l*p-a*b;T=Math.hypot(I,N,f),T<=1e-5?(I=0,N=0,f=0):(I/=T,N/=T,f/=T);let R=p*f-x*N,g=x*I-b*f,A=b*N-p*I;return T=Math.hypot(R,g,A),T<=1e-5?(R=0,g=0,A=0):(R/=T,g/=T,A/=T),n[0]=I,n[1]=R,n[2]=b,n[3]=0,n[4]=N,n[5]=g,n[6]=p,n[7]=0,n[8]=f,n[9]=A,n[10]=x,n[11]=0,n[12]=-(I*i+N*s+f*o),n[13]=-(R*i+g*s+A*o),n[14]=-(b*i+p*s+x*o),n[15]=1,n}function te(n,e,t){let r=e[0],i=e[1],s=e[2],o=e[3],l=e[4],a=e[5],u=e[6],c=e[7],h=e[8],m=e[9],b=e[10],p=e[11],x=e[12],T=e[13],I=e[14],N=e[15],f=t[0],R=t[1],g=t[2],A=t[3];return n[0]=f*r+R*l+g*h+A*x,n[1]=f*i+R*a+g*m+A*T,n[2]=f*s+R*u+g*b+A*I,n[3]=f*o+R*c+g*p+A*N,f=t[4],R=t[5],g=t[6],A=t[7],n[4]=f*r+R*l+g*h+A*x,n[5]=f*i+R*a+g*m+A*T,n[6]=f*s+R*u+g*b+A*I,n[7]=f*o+R*c+g*p+A*N,f=t[8],R=t[9],g=t[10],A=t[11],n[8]=f*r+R*l+g*h+A*x,n[9]=f*i+R*a+g*m+A*T,n[10]=f*s+R*u+g*b+A*I,n[11]=f*o+R*c+g*p+A*N,f=t[12],R=t[13],g=t[14],A=t[15],n[12]=f*r+R*l+g*h+A*x,n[13]=f*i+R*a+g*m+A*T,n[14]=f*s+R*u+g*b+A*I,n[15]=f*o+R*c+g*p+A*N,n}function we(n,e,t,r){let i=e[0],s=e[1],o=e[2],l=e[3],a=i+i,u=s+s,c=o+o,h=i*a,m=i*u,b=i*c,p=s*u,x=s*c,T=o*c,I=l*a,N=l*u,f=l*c,R=r[0],g=r[1],A=r[2];return n[0]=(1-(p+T))*R,n[1]=(m+f)*R,n[2]=(b-N)*R,n[3]=0,n[4]=(m-f)*g,n[5]=(1-(h+T))*g,n[6]=(x+I)*g,n[7]=0,n[8]=(b+N)*A,n[9]=(x-I)*A,n[10]=(1-(h+p))*A,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function me(n,e){let t=e[0],r=e[1],i=e[2],s=e[4],o=e[5],l=e[6],a=e[8],u=e[9],c=e[10],h=c*o-l*u,m=-c*s+l*a,b=u*s-o*a,p=t*h+r*m+i*b;return p&&(p=1/p,n[0]=h*p,n[1]=m*p,n[2]=b*p,n[3]=(-c*r+i*u)*p,n[4]=(c*t-i*a)*p,n[5]=(-u*t+r*a)*p,n[6]=(l*r-i*o)*p,n[7]=(-l*t+i*s)*p,n[8]=(o*t-r*s)*p),n}function nn(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],o=e[4],l=e[5],a=e[6],u=e[7],c=e[8],h=e[9],m=e[10],b=e[11],p=e[12],x=e[13],T=e[14],I=e[15],N=t*l-r*o,f=t*a-i*o,R=t*u-s*o,g=r*a-i*l,A=r*u-s*l,D=i*u-s*a,v=c*x-h*p,w=c*T-m*p,C=c*I-b*p,d=h*T-m*x,y=h*I-b*x,S=m*I-b*T,M=N*S-f*y+R*d+g*C-A*w+D*v;return M?(M=1/M,n[0]=(l*S-a*y+u*d)*M,n[1]=(i*y-r*S-s*d)*M,n[2]=(x*D-T*A+I*g)*M,n[3]=(m*A-h*D-b*g)*M,n[4]=(a*C-o*S-u*w)*M,n[5]=(t*S-i*C+s*w)*M,n[6]=(T*R-p*D-I*f)*M,n[7]=(c*D-m*R+b*f)*M,n[8]=(o*y-l*C+u*v)*M,n[9]=(r*C-t*y-s*v)*M,n[10]=(p*A-x*R+I*N)*M,n[11]=(h*R-c*A-b*N)*M,n[12]=(l*w-o*d-a*v)*M,n[13]=(t*d-r*w+i*v)*M,n[14]=(x*f-p*g-T*N)*M,n[15]=(c*g-h*f+m*N)*M,n):null}function ht(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],o=i[1]*e+i[5]*t+i[9]*r+i[13],l=i[2]*e+i[6]*t+i[10]*r+i[14],a=i[3]*e+i[7]*t+i[11]*r+i[15],u=a!==0?1/a:1;n[0]=s*u,n[1]=o*u,n[2]=l*u}function rn(n,e,t,r,i,s,o,l,a,u,c,h,m,b,p,x,T=0){let I=u-o,N=c-l,f=h-a,R=m-o,g=b-l,A=p-a,D=i*A-s*g,v=s*R-r*A,w=r*g-i*R,C=I*D+N*v+f*w;if(C>-1e-7&&C<1e-7)return!1;let d=1/C,y=n-o,S=e-l,M=t-a,E=d*(y*D+S*v+M*w);if(E<-T||E>1+T)return!1;let P=S*f-M*N,F=M*I-y*f,B=y*N-S*I,k=d*(r*P+i*F+s*B);if(k<-T||E+k>1+T)return!1;let O=d*(R*P+g*F+A*B);if(O>1e-4&&O<x.distance){x.distance=O,x.point=[n+r*O,e+i*O,t+s*O];let _=N*A-f*g,G=f*R-I*A,z=I*g-N*R,U=Math.hypot(_,G,z)||1;return x.normal=[_/U,G/U,z/U],!0}return!1}function He(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let c=0;c<t;c++)r.push(Q());if(t===0)return r;let i=new Set;for(let c of n.nodes)if(Array.isArray(c.children))for(let h of c.children)i.add(h);let s=new Set,o=128,l=(c,h,m=0)=>{if(m>o||c<0||c>=t||s.has(c))return;s.add(c);let b=n.nodes[c];if(!b)return;let p=Q();if(e&&e[c])p.set(e[c]);else if(b.matrix&&b.matrix.length===16)p.set(b.matrix);else{let T=b.translation||[0,0,0],I=b.rotation||[0,0,0,1],N=b.scale||[1,1,1];we(p,I,T,N)}let x=r[c];if(h?te(x,h,p):x.set(p),Array.isArray(b.children))for(let T of b.children)typeof T=="number"&&l(T,x,m+1)},a=[],u=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(u&&Array.isArray(u.nodes))a.push(...u.nodes);else for(let c=0;c<t;c++)i.has(c)||a.push(c);for(let c of a)l(c,null);for(let c=0;c<t;c++)!i.has(c)&&!a.includes(c)&&l(c,null);return r}var Bn={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function ft(n,e,t,r){if(!t||t.bufferView===void 0)return null;let i=n.bufferViews?.[t.bufferView];if(!i)return null;let s=Number(t.count??0);if(!Number.isInteger(s)||s<=0)return null;let o=t.componentType??5126,l=Bn[o];if(!l)throw new RangeError(`glTF accessor has unsupported componentType ${o}`);let a=l*r,u=i.byteStride&&i.byteStride>0?i.byteStride:a,c=(i.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(c)||c<0||u<a||c+(s-1)*u+a>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(o===5126&&u===a&&c%4===0)return new Float32Array(e,c,s*r);let h=new DataView(e),m=t.normalized===!0,b=new Float32Array(s*r);for(let p=0;p<s;p++){let x=c+p*u;for(let T=0;T<r;T++){let I=x+T*l,N;switch(o){case 5126:N=h.getFloat32(I,!0);break;case 5120:N=h.getInt8(I),m&&(N=Math.max(N/127,-1));break;case 5121:N=h.getUint8(I),m&&(N/=255);break;case 5122:N=h.getInt16(I,!0),m&&(N=Math.max(N/32767,-1));break;case 5123:N=h.getUint16(I,!0),m&&(N/=65535);break;default:N=h.getUint32(I,!0),m&&(N/=4294967295)}b[p*r+T]=N}}return b}function sn(n,e){let t=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),o=Number(e.rotation??0)||0,l=Math.cos(o),a=Math.sin(o),u=(Number.isFinite(i)?i:1)*l,c=(Number.isFinite(i)?i:1)*a,h=-(Number.isFinite(s)?s:1)*a,m=(Number.isFinite(s)?s:1)*l;for(let b=0;b+1<n.length;b+=2){let p=n[b],x=n[b+1];n[b]=u*p+c*x+t,n[b+1]=h*p+m*x+r}}var un=["neutral","reinhard","none","aces","agx"];function bt(n){let e=String(n??"").trim().toLowerCase();return un.includes(e)?e:"neutral"}function Vn(n){return un.indexOf(bt(n))}function zn(n){return new TextDecoder().decode(n)}var ln=ee().decoders;function Gn(n,e){ln.set(n.toLowerCase(),e)}function Ae(n){return ln.get(n.toLowerCase())}function mn(n){let e=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=t.getUint32(0,!0);if(r!==1179937895){let m=t.getUint8(0);throw m===123||m===32||m===10||m===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let s=t.getUint32(8,!0),o=12,l=null,a=null;for(;o+8<=s&&o+8<=e.byteLength;){let m=t.getUint32(o,!0),b=t.getUint32(o+4,!0),p=o+8;if(p+m>e.byteLength)throw new Error(`Truncated GLB chunk: required ${p+m} bytes, buffer has ${e.byteLength}`);if(b===1313821514){let x=new Uint8Array(e,p,m),T=zn(x);l=JSON.parse(T,(I,N)=>I==="__proto__"||I==="constructor"||I==="prototype"?void 0:N)}else b===5130562&&(a=e.slice(p,p+m));o=p+m}if(!l)throw new Error("Missing JSON chunk in GLB");let u=l.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!Ae("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let m of["EXT_meshopt_compression","KHR_meshopt_compression"])if(u.includes(m)&&!Ae("meshopt"))throw new Error(`Model requires ${m}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(u.includes("KHR_texture_basisu")&&!Ae("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let c=a||new ArrayBuffer(0),h={gltf:l,bin:c,animations:[]};for(let m of se)m.onParseGLB?.(h);return h}function Hn(n){return typeof n=="object"&&n!==null&&"gltf"in n&&typeof n.gltf=="object"&&n.gltf!==null&&"bin"in n&&(n.bin instanceof ArrayBuffer||ArrayBuffer.isView(n.bin))}function Pe(n){if(Hn(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return mn(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var hn=`#version 300 es
|
|
18
|
-
layout(location=0) in vec3
|
|
17
|
+
function Zt(n,e,t){let r=[],i=new Map,s=[],o=[],l=[],a=new Map,u=f=>{let E=i.get(f);return E===void 0&&(E=r.length,r.push({op:f}),i.set(f,E)),E},c=f=>{let E=a.get(f);return E===void 0&&(E=l.length,l.push({id:f}),a.set(f,E)),E},h=(f,E={})=>s.push({declaration:u(f),...E})-1,m=(f,E,x)=>o.push({id:f,type:E,value:x})-1,b=f=>({node:f,socket:"value"}),g=t?.interactivity??t?.gltfExtensions?.KHR_interactivity;if(g&&typeof g=="object"){let f=Array.isArray(g.graphs)?g.graphs[g.graph??0]:g;if(f&&Array.isArray(f.nodes)){let E=Array.isArray(f.declarations)?f.declarations:[];for(let x of E)x?.op&&u(x.op);Array.isArray(f.variables)&&o.push(...f.variables);for(let x of f.events||[])x?.id&&c(x.id);for(let x of f.nodes){if(!x||typeof x!="object")continue;let _=x.op||(typeof x.declaration=="number"?E[x.declaration]?.op:"");s.push(_?{...x,declaration:u(_)}:{...x})}}}let d=(f,E,x="translation")=>x==="baseColorFactor"||x==="metallicFactor"||x==="roughnessFactor"?`/materials/${Math.max(0,E)}/pbrMetallicRoughness/${x}`:x==="emissiveFactor"||x==="alphaCutoff"?`/materials/${Math.max(0,E)}/${x}`:x==="visible"?`/nodes/${f}/extensions/KHR_node_visibility/visible`:`/nodes/${f}/${x}`,w=new Map;n.forEach((f,E)=>{typeof f?.name=="string"&&!w.has(f.name)&&w.set(f.name,E)});let C=(f,E)=>typeof f.target=="string"&&w.has(f.target)?w.get(f.target):typeof f.targetNode=="number"?f.targetNode:E,N=f=>{let E=n[f];return(typeof E?.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0};for(let f=0;f<n.length;f++){let E=n[f],x=E?.extras?.interactivity;if(!x||typeof x!="object")continue;let _=(typeof E.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0,D=M=>{let I=Array.isArray(M)?M:[M],p=[];for(let A=0;A<I.length;A++){let T=I[A];if(!T||typeof T!="object")continue;let R=T.action||"interpolate",F=typeof T.duration=="number"?T.duration:.35;if(R==="toggleTransform"){let P=T.property==="rotation"||T.property==="scale"?T.property:"translation",B=P==="rotation"?E.rotation||[0,0,0,1]:P==="scale"?E.scale||[1,1,1]:E.translation||[0,0,0],k=`/nodes/${f}/${P}`,O=m(`__toggle_${f}_${A}`,"bool",!1),S=h("variable/get",{configuration:{variable:O}}),G=h("math/not",{values:{a:b(S)}}),z=h("variable/set",{configuration:{variable:O},values:{value:b(G)}}),U=h("pointer/interpolate",{configuration:{pointer:k},values:{value:{value:Array.isArray(T.to)?T.to:B},duration:{value:F}}}),H=h("pointer/interpolate",{configuration:{pointer:k},values:{value:{value:Array.isArray(T.from)?T.from:B},duration:{value:F}}});s[z].flows={out:{node:h("flow/branch",{values:{condition:b(S)},flows:{true:{node:U},false:{node:H}}})}},p.push(z)}else if(R==="interpolate"){let P=T.to??T.value;if(P===void 0)continue;let B={value:{value:P},duration:{value:F}};T.from!==void 0&&(B.from={value:T.from}),p.push(h("pointer/interpolate",{configuration:{pointer:typeof T.pointer=="string"?T.pointer:d(C(T,f),N(C(T,f)),T.property)},values:B}))}else if(R==="setProperty"){if(T.value===void 0)continue;p.push(h("pointer/set",{configuration:{pointer:typeof T.pointer=="string"?T.pointer:d(C(T,f),N(C(T,f)),T.property)},values:{value:{value:T.value}}}))}else if(R==="toggleVisibility"){let P=C(T,f),B=m(`__vis_${P}_${A}`,"bool",!0),k=h("variable/get",{configuration:{variable:B}}),O=h("math/not",{values:{a:b(k)}}),S=h("variable/set",{configuration:{variable:B},values:{value:b(O)}});s[S].flows={out:{node:h("pointer/set",{configuration:{pointer:`/nodes/${P}/extensions/KHR_node_visibility/visible`},values:{value:b(k)}})}},p.push(S)}else if(R==="cycleMaterialColor"&&Array.isArray(T.colors)&&T.colors.length>0){let P=typeof T.duration=="number"?T.duration:.25,B=`/materials/${Math.max(0,_)}/pbrMetallicRoughness/baseColorFactor`,k=m(`__color_idx_${f}_${A}`,"int",0),O=h("variable/get",{configuration:{variable:k}}),S=h("math/add",{values:{a:b(O),b:{value:1}}}),G=h("math/rem",{values:{a:b(S),b:{value:T.colors.length}}}),z=h("variable/set",{configuration:{variable:k},values:{value:b(G)}}),U={};for(let H=0;H<T.colors.length;H++){let L=T.colors[H],V=Array.isArray(L)&&L.length>=3?[L[0],L[1],L[2],L[3]??1]:[1,1,1,1];U[String(H)]={node:P>0?h("pointer/interpolate",{configuration:{pointer:B},values:{value:{value:V},duration:{value:P}}}):h("pointer/set",{configuration:{pointer:B},values:{value:{value:V}}})}}s[z].flows={out:{node:h("flow/switch",{values:{selection:b(O)},flows:U})}},p.push(z)}else if(R==="playAnimation")p.push(h("animation/start",{configuration:{animation:T.animation??T.clip??0}}));else if(R==="stopAnimation")p.push(h("animation/stop"));else if(R==="sendEvent"){let P={};for(let[B,k]of Object.entries(T.values||{}))P[B]={value:k};p.push(h("event/send",{configuration:{event:c(String(T.event??T.id??"custom"))},values:P}))}}if(!p.length)return null;if(p.length===1)return p[0];let y={};return p.forEach((A,T)=>{y[String(T)]={node:A}}),h("flow/sequence",{flows:y})},v=(M,I,p)=>{let y=D(I);y!==null&&h(M,{...p?{configuration:p}:{},flows:{out:{node:y}}})};if(x.onSelect&&v("pointer/onSelect",x.onSelect,{nodeIndex:f}),x.onHoverIn&&v("pointer/onHoverIn",x.onHoverIn,{nodeIndex:f}),x.onHoverOut&&v("pointer/onHoverOut",x.onHoverOut,{nodeIndex:f}),x.onStart&&v("event/onStart",x.onStart),x.onReceive&&typeof x.onReceive=="object")for(let[M,I]of Object.entries(x.onReceive))v("event/receive",I,{event:c(M)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:o,events:l}],graph:0}:null}var Jt='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).',Qt="Security Error: client-side scripts require allow-client-scripts opt-in.";var ze="__THREE_LIVE_REGISTRY__";function Q(){let n=typeof globalThis<"u"?globalThis:{};if(!n[ze]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(n,ze,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{n[ze]=e}}return n[ze]}var ie=Q().plugins;function en(n){let e=Q().plugins;e.some(t=>t.name===n.name)||e.push(n),n.onRegister?.()}function tn(){return Q().plugins}function J(){let n=new Float32Array(16);return n[0]=1,n[5]=1,n[10]=1,n[15]=1,n}function Ge(n,e,t,r,i){let s=1/Math.tan(e/2);n.fill(0),n[0]=s/t,n[5]=s,n[11]=-1;let o=1/(r-i);return n[10]=(i+r)*o,n[14]=2*i*r*o,n}function Re(n,e,t,r){let[i,s,o]=e,[l,a,u]=r,[c,h,m]=t,b=i-c,g=s-h,d=o-m,w=Math.hypot(b,g,d);w<=1e-5?(b=0,g=0,d=1):(b/=w,g/=w,d/=w);let C=a*d-u*g,N=u*b-l*d,f=l*g-a*b;w=Math.hypot(C,N,f),w<=1e-5?(C=0,N=0,f=0):(C/=w,N/=w,f/=w);let E=g*f-d*N,x=d*C-b*f,_=b*N-g*C;return w=Math.hypot(E,x,_),w<=1e-5?(E=0,x=0,_=0):(E/=w,x/=w,_/=w),n[0]=C,n[1]=E,n[2]=b,n[3]=0,n[4]=N,n[5]=x,n[6]=g,n[7]=0,n[8]=f,n[9]=_,n[10]=d,n[11]=0,n[12]=-(C*i+N*s+f*o),n[13]=-(E*i+x*s+_*o),n[14]=-(b*i+g*s+d*o),n[15]=1,n}function ee(n,e,t){let r=e[0],i=e[1],s=e[2],o=e[3],l=e[4],a=e[5],u=e[6],c=e[7],h=e[8],m=e[9],b=e[10],g=e[11],d=e[12],w=e[13],C=e[14],N=e[15],f=t[0],E=t[1],x=t[2],_=t[3];return n[0]=f*r+E*l+x*h+_*d,n[1]=f*i+E*a+x*m+_*w,n[2]=f*s+E*u+x*b+_*C,n[3]=f*o+E*c+x*g+_*N,f=t[4],E=t[5],x=t[6],_=t[7],n[4]=f*r+E*l+x*h+_*d,n[5]=f*i+E*a+x*m+_*w,n[6]=f*s+E*u+x*b+_*C,n[7]=f*o+E*c+x*g+_*N,f=t[8],E=t[9],x=t[10],_=t[11],n[8]=f*r+E*l+x*h+_*d,n[9]=f*i+E*a+x*m+_*w,n[10]=f*s+E*u+x*b+_*C,n[11]=f*o+E*c+x*g+_*N,f=t[12],E=t[13],x=t[14],_=t[15],n[12]=f*r+E*l+x*h+_*d,n[13]=f*i+E*a+x*m+_*w,n[14]=f*s+E*u+x*b+_*C,n[15]=f*o+E*c+x*g+_*N,n}function Me(n,e,t,r){let i=e[0],s=e[1],o=e[2],l=e[3],a=i+i,u=s+s,c=o+o,h=i*a,m=i*u,b=i*c,g=s*u,d=s*c,w=o*c,C=l*a,N=l*u,f=l*c,E=r[0],x=r[1],_=r[2];return n[0]=(1-(g+w))*E,n[1]=(m+f)*E,n[2]=(b-N)*E,n[3]=0,n[4]=(m-f)*x,n[5]=(1-(h+w))*x,n[6]=(d+C)*x,n[7]=0,n[8]=(b+N)*_,n[9]=(d-C)*_,n[10]=(1-(h+g))*_,n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n}function me(n,e,t=0){let r=e[0],i=e[1],s=e[2],o=e[4],l=e[5],a=e[6],u=e[8],c=e[9],h=e[10],m=h*l-a*c,b=-h*o+a*u,g=c*o-l*u,d=r*m+i*b+s*g;return!d||t>0&&(!Number.isFinite(d)||Math.abs(d)<=t)||(d=1/d,n[0]=m*d,n[1]=b*d,n[2]=g*d,n[3]=(-h*i+s*c)*d,n[4]=(h*r-s*u)*d,n[5]=(-c*r+i*u)*d,n[6]=(a*i-s*l)*d,n[7]=(-a*r+s*o)*d,n[8]=(l*r-i*o)*d),n}function nn(n,e){let t=e[0],r=e[1],i=e[2],s=e[3],o=e[4],l=e[5],a=e[6],u=e[7],c=e[8],h=e[9],m=e[10],b=e[11],g=e[12],d=e[13],w=e[14],C=e[15],N=t*l-r*o,f=t*a-i*o,E=t*u-s*o,x=r*a-i*l,_=r*u-s*l,D=i*u-s*a,v=c*d-h*g,M=c*w-m*g,I=c*C-b*g,p=h*w-m*d,y=h*C-b*d,A=m*C-b*w,T=N*A-f*y+E*p+x*I-_*M+D*v;return T?(T=1/T,n[0]=(l*A-a*y+u*p)*T,n[1]=(i*y-r*A-s*p)*T,n[2]=(d*D-w*_+C*x)*T,n[3]=(m*_-h*D-b*x)*T,n[4]=(a*I-o*A-u*M)*T,n[5]=(t*A-i*I+s*M)*T,n[6]=(w*E-g*D-C*f)*T,n[7]=(c*D-m*E+b*f)*T,n[8]=(o*y-l*I+u*v)*T,n[9]=(r*I-t*y-s*v)*T,n[10]=(g*_-d*E+C*N)*T,n[11]=(h*E-c*_-b*N)*T,n[12]=(l*M-o*p-a*v)*T,n[13]=(t*p-r*M+i*v)*T,n[14]=(d*f-g*x-w*N)*T,n[15]=(c*x-h*f+m*N)*T,n):null}function ft(n,e,t,r,i){let s=i[0]*e+i[4]*t+i[8]*r+i[12],o=i[1]*e+i[5]*t+i[9]*r+i[13],l=i[2]*e+i[6]*t+i[10]*r+i[14],a=i[3]*e+i[7]*t+i[11]*r+i[15],u=a!==0?1/a:1;n[0]=s*u,n[1]=o*u,n[2]=l*u}function rn(n,e,t,r,i,s,o,l,a,u,c,h,m,b,g,d,w=0){let C=u-o,N=c-l,f=h-a,E=m-o,x=b-l,_=g-a,D=i*_-s*x,v=s*E-r*_,M=r*x-i*E,I=C*D+N*v+f*M;if(I>-1e-7&&I<1e-7)return!1;let p=1/I,y=n-o,A=e-l,T=t-a,R=p*(y*D+A*v+T*M);if(R<-w||R>1+w)return!1;let F=A*f-T*N,P=T*C-y*f,B=y*N-A*C,k=p*(r*F+i*P+s*B);if(k<-w||R+k>1+w)return!1;let O=p*(E*F+x*P+_*B);if(O>1e-4&&O<d.distance){d.distance=O,d.point=[n+r*O,e+i*O,t+s*O];let S=N*_-f*x,G=f*E-C*_,z=C*x-N*E,U=Math.hypot(S,G,z)||1;return d.normal=[S/U,G/U,z/U],!0}return!1}function He(n,e){let t=Array.isArray(n?.nodes)?n.nodes.length:0,r=[];for(let c=0;c<t;c++)r.push(J());if(t===0)return r;let i=new Set;for(let c of n.nodes)if(Array.isArray(c.children))for(let h of c.children)i.add(h);let s=new Set,o=128,l=(c,h,m=0)=>{if(m>o||c<0||c>=t||s.has(c))return;s.add(c);let b=n.nodes[c];if(!b)return;let g=J();if(e&&e[c])g.set(e[c]);else if(b.matrix&&b.matrix.length===16)g.set(b.matrix);else{let w=b.translation||[0,0,0],C=b.rotation||[0,0,0,1],N=b.scale||[1,1,1];Me(g,C,w,N)}let d=r[c];if(h?ee(d,h,g):d.set(g),Array.isArray(b.children))for(let w of b.children)typeof w=="number"&&l(w,d,m+1)},a=[],u=n.scenes&&n.scenes[n.scene!==void 0?n.scene:0];if(u&&Array.isArray(u.nodes))a.push(...u.nodes);else for(let c=0;c<t;c++)i.has(c)||a.push(c);for(let c of a)l(c,null);for(let c=0;c<t;c++)!i.has(c)&&!a.includes(c)&&l(c,null);return r}function Xe(n,e,t,r=!0){let i=[],s=null;try{for(let[o,l]of[[35633,e],[35632,t]]){let a=n.createShader(o);if(!a){if(r)throw new Error("Shader allocation failed");return null}if(i.push(a),n.shaderSource(a,l),n.compileShader(a),n.getShaderParameter&&!n.getShaderParameter(a,35713)){if(r)throw new Error(`Shader compile error: ${n.getShaderInfoLog(a)}`);return null}}if(s=n.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let o of i)n.attachShader(s,o);if(n.linkProgram(s),n.getProgramParameter&&!n.getProgramParameter(s,35714)){let o=r?n.getProgramInfoLog(s):null;if(n.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${o}`);return null}return s}finally{for(let o of i)s&&n.detachShader?.(s,o),n.deleteShader?.(o)}}var On={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function dt(n,e,t,r){if(!t||t.bufferView===void 0)return null;let i=n.bufferViews?.[t.bufferView];if(!i)return null;let s=Number(t.count??0);if(!Number.isInteger(s)||s<=0)return null;let o=t.componentType??5126,l=On[o];if(!l)throw new RangeError(`glTF accessor has unsupported componentType ${o}`);let a=l*r,u=i.byteStride&&i.byteStride>0?i.byteStride:a,c=(i.byteOffset||0)+(t.byteOffset||0);if(!Number.isInteger(c)||c<0||u<a||c+(s-1)*u+a>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(o===5126&&u===a&&c%4===0)return new Float32Array(e,c,s*r);let h=new DataView(e),m=t.normalized===!0,b=new Float32Array(s*r);for(let g=0;g<s;g++){let d=c+g*u;for(let w=0;w<r;w++){let C=d+w*l,N;switch(o){case 5126:N=h.getFloat32(C,!0);break;case 5120:N=h.getInt8(C),m&&(N=Math.max(N/127,-1));break;case 5121:N=h.getUint8(C),m&&(N/=255);break;case 5122:N=h.getInt16(C,!0),m&&(N=Math.max(N/32767,-1));break;case 5123:N=h.getUint16(C,!0),m&&(N/=65535);break;default:N=h.getUint32(C,!0),m&&(N/=4294967295)}b[g*r+w]=N}}return b}function sn(n,e){let t=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),o=Number(e.rotation??0)||0,l=Math.cos(o),a=Math.sin(o),u=(Number.isFinite(i)?i:1)*l,c=(Number.isFinite(i)?i:1)*a,h=-(Number.isFinite(s)?s:1)*a,m=(Number.isFinite(s)?s:1)*l;for(let b=0;b+1<n.length;b+=2){let g=n[b],d=n[b+1];n[b]=u*g+c*d+t,n[b+1]=h*g+m*d+r}}var cn=["neutral","reinhard","none","aces","agx"];function yt(n){let e=String(n??"").trim().toLowerCase();return cn.includes(e)?e:"neutral"}function Bn(n){return cn.indexOf(yt(n))}function Vn(n){return new TextDecoder().decode(n)}var un=Q().decoders;function zn(n,e){un.set(n.toLowerCase(),e)}function _e(n){return un.get(n.toLowerCase())}function ln(n){let e=ArrayBuffer.isView(n)?n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength):n,t=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=t.getUint32(0,!0);if(r!==1179937895){let m=t.getUint8(0);throw m===123||m===32||m===10||m===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let s=t.getUint32(8,!0),o=12,l=null,a=null;for(;o+8<=s&&o+8<=e.byteLength;){let m=t.getUint32(o,!0),b=t.getUint32(o+4,!0),g=o+8;if(g+m>e.byteLength)throw new Error(`Truncated GLB chunk: required ${g+m} bytes, buffer has ${e.byteLength}`);if(b===1313821514){let d=new Uint8Array(e,g,m),w=Vn(d);l=JSON.parse(w,(C,N)=>C==="__proto__"||C==="constructor"||C==="prototype"?void 0:N)}else b===5130562&&(a=e.slice(g,g+m));o=g+m}if(!l)throw new Error("Missing JSON chunk in GLB");let u=l.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!_e("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let m of["EXT_meshopt_compression","KHR_meshopt_compression"])if(u.includes(m)&&!_e("meshopt"))throw new Error(`Model requires ${m}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(u.includes("KHR_texture_basisu")&&!_e("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let c=a||new ArrayBuffer(0),h={gltf:l,bin:c,animations:[]};for(let m of ie)m.onParseGLB?.(h);return h}function Gn(n){return typeof n=="object"&&n!==null&&"gltf"in n&&typeof n.gltf=="object"&&n.gltf!==null&&"bin"in n&&(n.bin instanceof ArrayBuffer||ArrayBuffer.isView(n.bin))}function Fe(n){if(Gn(n))return n;if(n instanceof ArrayBuffer||ArrayBuffer.isView(n))return ln(n);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var mn=`#version 300 es
|
|
18
|
+
layout(location=0) in vec3 aPos;
|
|
19
|
+
layout(location=3) in vec3 aOff;
|
|
19
20
|
layout(location=1) in vec3 aNormal;
|
|
20
21
|
layout(location=2) in vec2 aUV;
|
|
21
22
|
uniform mat4 uMVP,uModel;
|
|
@@ -38,6 +39,7 @@ mat3 xrNormalMatrix(){return uInstanced==1?transpose(inverse(mat3(xrModel()))):u
|
|
|
38
39
|
out vec3 vNormal,vWorldPos;
|
|
39
40
|
out vec2 vUV;
|
|
40
41
|
void main(){
|
|
42
|
+
vec3 aPosition=aPos+aOff;
|
|
41
43
|
vInstTint=uInstanced==1?aInstColor:vec4(1.0);
|
|
42
44
|
vec3 rawN=uNormalMatrix*aNormal;
|
|
43
45
|
vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
|
|
@@ -47,7 +49,7 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
47
49
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
48
50
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
49
51
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
50
|
-
}`,
|
|
52
|
+
}`,Hn=`#version 300 es
|
|
51
53
|
precision highp float;
|
|
52
54
|
in vec3 vNormal,vWorldPos;
|
|
53
55
|
in vec2 vUV;
|
|
@@ -240,14 +242,14 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
240
242
|
float outAlpha=base.a;
|
|
241
243
|
/*XRD_O*/
|
|
242
244
|
fragColor=vec4(color,outAlpha);
|
|
243
|
-
}`;var
|
|
245
|
+
}`;var Xn=`#version 300 es
|
|
244
246
|
layout(location=0) in vec3 aPosition;
|
|
245
247
|
uniform mat4 uMVP;
|
|
246
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}
|
|
248
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Wn=`#version 300 es
|
|
247
249
|
precision highp float;
|
|
248
250
|
uniform vec4 uColorId;
|
|
249
251
|
out vec4 fragColor;
|
|
250
|
-
void main(){fragColor=uColorId;}`;function on(n,e,t){let r=n.createShader(e);if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,35713)){let i=n.getShaderInfoLog(r);throw n.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function yt(n,e,t){let r=on(n,35633,e),i=on(n,35632,t),s=n.createProgram();if(n.attachShader(s,r),n.attachShader(s,i),n.linkProgram(s),!n.getProgramParameter(s,35714)){let o=n.getProgramInfoLog(s);throw n.deleteProgram(s),new Error(`Program link error: ${o}`)}return s}function gt(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var an=["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 fn(){let n=ee().xrDepthShader;return{fs:Xn.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...an,...n.uniformNames]:an}}function Yn(n){if(typeof n!="string")return null;let e=n.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let t=e.toLowerCase();return t.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:t.startsWith("https://")||t.startsWith("blob:")?e:t.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function dt(n,e,t,r,i,s,o,l){if(r===void 0||!e.accessors?.[r])return null;let a=ft(e,t,e.accessors[r],s);if(!a)return null;l&&(a=a.slice(),sn(a,l));let u=n.createBuffer();return o.push(u),n.bindBuffer(34962,u),n.bufferData(34962,a,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),a}function pt(n){let e=Number(n);return Number.isFinite(e)?Math.max(0,e):1}function dn(n,e,t){let r=fn(),i=hn,s=r.fs,o=!1;for(let a of se)if(a.onResolveShader){let u=a.onResolveShader(e,t,i,s);u&&(i=u.vs,s=u.fs,o=!0)}let l=o?yt(n,i,s):null;return{program:l,uniforms:l?gt(n,l,r.uniforms):null}}function jn(n,e,t){let r=e.instanceMatrices;if(!r||r.length<16||typeof n.vertexAttribDivisor!="function"||typeof n.drawElementsInstanced!="function")return!1;let i=r.length>>4,s=e.instanceColors,o=new Float32Array(i*20);for(let a=0;a<i;a++)o.set(r.subarray(a*16,a*16+16),a*20),o[a*20+16]=s?s[a*3]:1,o[a*20+17]=s?s[a*3+1]:1,o[a*20+18]=s?s[a*3+2]:1,o[a*20+19]=1;let l=n.createBuffer();t.push(l),n.bindBuffer(34962,l),n.bufferData(34962,o,35044);for(let a=0;a<5;a++)n.enableVertexAttribArray(8+a),n.vertexAttribPointer(8+a,4,5126,!1,80,a*16),n.vertexAttribDivisor(8+a,1);return!0}function Kn(n,e){let t=n.materials?.[e?.material];if(!t)return null;let r=[t.pbrMetallicRoughness?.baseColorTexture,t.pbrMetallicRoughness?.metallicRoughnessTexture,t.normalTexture,t.occlusionTexture,t.emissiveTexture];for(let i of r){let s=i?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var Fr=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),pn=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Xe(n,e){e.indices?n.drawElements(4,e.indexCount,e.indexType,0):n.drawArrays(4,0,e.indexCount)}function bn(n,e){let t=n?.pbrMetallicRoughness,r=t?.baseColorFactor,i=n?.extensions?.KHR_materials_clearcoat,s=o=>o!==void 0&&e[o.index]?e[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:t?.metallicFactor??.1,roughness:t?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:s(t?.baseColorTexture),metallicRoughnessTexture:s(t?.metallicRoughnessTexture),normalTexture:s(n?.normalTexture),normalScale:n?.normalTexture?.scale??1,occlusionTexture:s(n?.occlusionTexture),occlusionStrength:n?.occlusionTexture?.strength??1,isTransmissive:(n?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function yn(n,e,t){let r=new Set,i=s=>{s&&!r.has(s)&&(r.add(s),n.deleteTexture(s))};for(let s of e)for(let o of s.primitives){if(o.vao&&n.deleteVertexArray(o.vao),o.buffers)for(let a of o.buffers)n.deleteBuffer(a);i(o.texture),i(o.metallicRoughnessTexture),i(o.normalTexture),i(o.occlusionTexture);let l=new Set;o.customProgram&&l.add(o.customProgram);for(let a of o.programCache?.values()??[])a.program&&l.add(a.program);for(let a of l)n.deleteProgram(a)}if(t)for(let s of t)i(s)}function cn(n,e,t=pn,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return qn(n,e,t,r,i)}catch(s){let o=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;yn(n,o,i.gpuTextures),i.vao&&n.deleteVertexArray(i.vao);for(let l of i.buffers)n.deleteBuffer(l);throw s}}function qn(n,e,t,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,o=Ae("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(s,e);let l=e.bin,a=[];i.meshes=a;let u=[],c=s.extensions?.KHR_materials_variants;c&&Array.isArray(c.variants)&&c.variants.forEach((y,S)=>{u.push(typeof y?.name=="string"&&y.name?y.name:`Variant_${S}`)});let h=He(s),m=[];if(Array.isArray(s.nodes))for(let y=0;y<s.nodes.length;y++){let S=s.nodes[y];S.mesh!==void 0&&s.meshes&&s.meshes[S.mesh]&&m.push({node:S,nodeIdx:y,meshIdx:S.mesh})}let b=m.length>0?m:(s.meshes||[]).map((y,S)=>({node:y,nodeIdx:-1,meshIdx:S})),p=[];if(Array.isArray(e.lights)&&e.lights.length>0)p.push(...e.lights);else if(s.extensions?.KHR_lights_punctual?.lights){let y=s.extensions.KHR_lights_punctual.lights;for(let S of y){let M=S.type==="directional"?"directional":S.type==="point"?"point":"ambient";p.push({type:M,color:S.color||[1,1,1],intensity:S.intensity!==void 0?S.intensity:1})}}if(p.length===0&&(p.push({type:"ambient",color:[1,1,1],intensity:.35}),p.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),b.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${b.length}`);let x=[];if(i.gpuTextures=x,s.textures&&s.images){if(s.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${s.textures.length}`);for(let y=0;y<s.textures.length;y++){let S=s.textures[y],M=s.images[S.source];if(M){let E=n.createTexture();if(n.bindTexture(3553,E),n.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),n.texParameteri(3553,10242,10497),n.texParameteri(3553,10243,10497),n.texParameteri(3553,10241,9729),n.texParameteri(3553,10240,9729),M.bufferView!==void 0){let P=s.bufferViews[M.bufferView],F=l.slice(P.byteOffset||0,(P.byteOffset||0)+P.byteLength),B=new Blob([F],{type:M.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(B).then(k=>{n.bindTexture(3553,E),n.texImage2D(3553,0,6408,6408,5121,k),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(M.uri){let P=Yn(M.uri);if(P){let F=new Image;F.crossOrigin="anonymous",F.referrerPolicy="no-referrer",F.onload=()=>{n.bindTexture(3553,E),n.texImage2D(3553,0,6408,6408,5121,F),n.generateMipmap(3553),r?.()},F.src=P}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",M.uri)}x.push(E)}else x.push(null)}}let T=[1/0,1/0,1/0],I=[-1/0,-1/0,-1/0],N=0,f=0;for(let y=0;y<b.length;y++){let S=b[y],M=s.meshes[S.meshIdx],E=S.nodeIdx>=0?h[S.nodeIdx]:Q(),P=new Float32Array(9);me(P,E);let F={name:S.node.name||M.name||`Mesh_${S.meshIdx}`,nodeIndex:S.nodeIdx,transform:E,normalMatrix:P,primitives:[],extras:S.node.extras||M.extras};i.mesh=F;let B=S.node?.extensions?.EXT_mesh_gpu_instancing;if(B&&B.attributes&&typeof B.attributes=="object"){let k=B.attributes,O=k.TRANSLATION!==void 0?s.accessors?.[k.TRANSLATION]:null,_=k.ROTATION!==void 0?s.accessors?.[k.ROTATION]:null,G=k.SCALE!==void 0?s.accessors?.[k.SCALE]:null,z=k._COLOR_0!==void 0?s.accessors?.[k._COLOR_0]:null,U=Number(O?.count??_?.count??G?.count??0);if(!Number.isFinite(U)||U<0||U>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${U}`);if(U>0){let H=($,Z)=>{if(!$||$.bufferView===void 0||!s.bufferViews?.[$.bufferView])return null;let oe=$.componentType??5126,ue=re=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${re})`),null);if(oe!==5120&&oe!==5121&&oe!==5122&&oe!==5123&&oe!==5126)return ue(`componentType ${oe}`);if(!(Number($.count)>=U))return ue(`count ${$.count} < ${U}`);let K=null;try{K=ft(s,l,{...$,count:U},Z)}catch{return ue("out of bounds")}return!K||!K.every(Number.isFinite)?ue("non-finite value"):K},L=H(O,3),V=H(_,4),X=H(G,3),W=z?.type==="VEC4"?4:3,Y=H(z,W),ie=new Float32Array(U*16),ce=Q();for(let $=0;$<U;$++){let Z=L?[L[$*3],L[$*3+1],L[$*3+2]]:[0,0,0],oe=V?[V[$*4],V[$*4+1],V[$*4+2],V[$*4+3]]:[0,0,0,1],ue=X?[X[$*3],X[$*3+1],X[$*3+2]]:[1,1,1];we(ce,oe,Z,ue),ie.set(ce,$*16)}if(F.instanceMatrices=ie,Y){let $=new Float32Array(U*3);for(let Z=0;Z<U;Z++)$[Z*3]=Y[Z*W],$[Z*3+1]=Y[Z*W+1],$[Z*3+2]=Y[Z*W+2];F.instanceColors=$}}}for(let k of M.primitives||[]){if(k.extensions?.KHR_draco_mesh_compression){let K=Ae("draco");K&&K.decodePrimitive(s,k,l)}let O=[],_=n.createVertexArray();i.vao=_,i.buffers=O,n.bindVertexArray(_);let G=jn(n,F,O),z=s.accessors[k.attributes.POSITION],U=Number(z?.count??0);if(!Number.isFinite(U)||U<0||N+U>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(N+=U,z?.min&&z?.max){let K=re=>{for(let J=0;J<3;J++){let ae=re[12+J],be=re[12+J];for(let Re=0;Re<3;Re++){let Be=re[Re*4+J]*z.min[Re],Ve=re[Re*4+J]*z.max[Re];ae+=Be<Ve?Be:Ve,be+=Be>Ve?Be:Ve}ae<T[J]&&(T[J]=ae),be>I[J]&&(I[J]=be)}};if(F.instanceMatrices&&F.instanceMatrices.length>=16){let re=F.instanceMatrices.length>>4,J=Q();for(let ae=0;ae<re;ae++){let be=F.instanceMatrices.subarray(ae*16,ae*16+16);te(J,E,be),K(J)}}else K(E)}let H=dt(n,s,l,k.attributes.POSITION,0,3,O);dt(n,s,l,k.attributes.NORMAL,1,3,O),dt(n,s,l,k.attributes.TEXCOORD_0,2,2,O,Kn(s,k));let L=0,V=5123,X=null;if(k.indices!==void 0){let K=s.accessors[k.indices],J=(s.bufferViews[K.bufferView].byteOffset||0)+(K.byteOffset||0);if(L=Number(K.count??0),!Number.isFinite(L)||L<0||f+L>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);f+=L,V=K.componentType===5125?5125||5125:5123||5123;let ae=n.createBuffer();O.push(ae),n.bindBuffer(34963,ae),K.componentType===5125?(X=new Uint32Array(l,J,K.count),n.bufferData(34963,X,35044)):K.componentType===5121?(X=Uint16Array.from(new Uint8Array(l,J,K.count)),n.bufferData(34963,X,35044)):(X=J%2===0?new Uint16Array(l,J,K.count):new Uint16Array(l.slice(J,J+K.count*2)),n.bufferData(34963,X,35044))}else L=z.count;let W={};for(let K of se)if(K.onBuildPrimitiveVAO){let re=K.onBuildPrimitiveVAO(n,_,k,s,l);re&&(W[K.name]=re)}n.bindVertexArray(null);let Y=s.materials&&k.material!==void 0?s.materials[k.material]:null,{program:ie,uniforms:ce}=dn(n,k,Y),$=bn(Y,x),Z=!!(Y?.extensions?.KHR_materials_transmission||W.materials?.isTransmissive),oe=k.extensions?.KHR_materials_variants?.mappings,ue=Array.isArray(oe)?oe.filter(K=>K&&typeof K.material=="number"&&Array.isArray(K.variants)).map(K=>({material:K.material|0,variants:K.variants.map(re=>Number(re)|0)})):void 0;F.primitives.push({vao:_,instanced:G,indexCount:L,indexType:V,...$,positions:H,indices:X,buffers:O,materialIndex:k.material,defaultMaterialIndex:k.material,variantMappings:ue,primitiveDef:k,programCache:new Map([[k.material??-1,{program:ie,uniforms:ce}]]),pluginData:W,customProgram:ie,customUniforms:ce,isTransmissive:Z})}a.push(F)}isFinite(T[0])||(T=[-1,-1,-1]),isFinite(I[0])||(I=[1,1,1]);let R=[(T[0]+I[0])/2,(T[1]+I[1])/2,(T[2]+I[2])/2],g=I[0]-T[0],A=I[1]-T[1],D=I[2]-T[2],v=Math.max(Math.hypot(g,A,D)/2,.5),w=[T[0],T[1],T[2]],C=[I[0],I[1],I[2]],d=e.animations;if(!d){for(let y of se)if(y.onParseGLB?.(e),e.animations){d=e.animations;break}}return d||(d=[]),{meshes:a,bounds:{center:R,radius:v,min:w,max:C},lights:p,animations:d,worldMatrices:h,gpuTextures:x,availableVariants:u}}function Fe(n){let e=n.customTarget||n.bounds.center,t=n.currDistance*Math.cos(n.currPhi);return[e[0]+t*Math.sin(n.currTheta),e[1]+n.currDistance*Math.sin(n.currPhi),e[2]+t*Math.cos(n.currTheta)]}var We=class{constructor(e,t,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=Q();this.clearColor=[0,0,0,0];this.envIntensity=1;this.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=Q();this.viewMatrix=Q();this.activeViewMatrix=null;this.modelMatrix=Q();this.mvpMatrix=Q();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.contextLost=!1;this.lastGlbData=null;this.boundContextLost=null;this.boundContextRestored=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:Q(),rawValueToMeters:.001,format:0};this.container=e;let i,s;if(t&&typeof t.getContext=="function"?(i=t,s=r):(s=t,i=s?.canvas),!i){let 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=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let o=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!o:o&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=pt(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=bt(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,t){Gn(e,t)}static getDecoder(e){return Ae(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=fn();this.renderProg=yt(e,hn,t.fs),this.pickProg=yt(e,Wn,$n),this.uRender=gt(e,this.renderProg,t.uniforms),this.uPick=gt(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of se)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){this.lastGlbData=e,this.lastLimits=t;let{meshes:r,bounds:i,lights:s,animations:o,worldMatrices:l,gpuTextures:a,availableVariants:u}=cn(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=o||[],this.worldMatrices=l||[],this.gpuTextures=a||[],this.availableVariants=u||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let m of e.gltf.nodes)this.initialNodeTransforms.push({t:m.translation?[m.translation[0],m.translation[1],m.translation[2]]:[0,0,0],r:m.rotation?[m.rotation[0],m.rotation[1],m.rotation[2],m.rotation[3]]:[0,0,0,1],s:m.scale?[m.scale[0],m.scale[1],m.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let m of se)m.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 c=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;c!==void 0&&(this.exposure=pt(c));let h=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;h!==void 0&&(this.envIntensity=Math.max(0,Number(h)||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(mn(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Pe(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Pe(e),{meshes:i}=cn(this.gl,r,pn,()=>this.render());if(t)for(let s of i)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],me(s.normalMatrix,s.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),me(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],s=[],o=[],l=[];for(let a of this.lights){let u=a.color||[1,1,1],c=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")r=[u[0]*c,u[1]*c,u[2]*c];else if(a.type==="directional"&&i.length<6){let h=a.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),s.push(u[0]*c,u[1]*c,u[2]*c)}else if(a.type==="point"&&o.length<6){let h=a.position||[0,0,0];o.push(h[0],h[1],h[2]),l.push(u[0]*c,u[1]*c,u[2]*c)}}i.length===0&&(i.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,o.length/3),o.length>0&&(t.uniform3fv(e.uPointLightPos,o),t.uniform3fv(e.uPointLightColor,l)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=pt(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=bt(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of se)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of se)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let i=this.meshes.flatMap(c=>c.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),s=i[0],o=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,a=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,u={baseColorFactor:o,metallicFactor:l,roughnessFactor:a,setBaseColorFactor:c=>{let h=[c[0],c[1],c[2],c[3]??1];u.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let m of i)m.baseColor=h;this.render()},setMetallicFactor:c=>{u.metallicFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=c);for(let h of i)h.metallic=c;this.render()},setRoughnessFactor:c=>{u.roughnessFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=c);for(let h of i)h.roughness=c;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:u}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",r=-1;if(t)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 t;for(let s of this.meshes)for(let o of s.primitives){let l=o.defaultMaterialIndex;if(!t&&Array.isArray(o.variantMappings)){for(let u of o.variantMappings)if(Array.isArray(u.variants)&&u.variants.includes(r)){l=u.material;break}}let a=l!==void 0?i[l]:void 0;o.materialIndex=a?l:void 0,Object.assign(o,bn(a,this.gpuTextures)),this.applyPrimitiveProgram(o,o.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,t,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,s=e.programCache.get(i);s||(s=dn(this.gl,{...e.primitiveDef,material:t},r),e.programCache.set(i,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of se)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=Q();te(r,this.projMatrix,this.viewMatrix);let[i,s,o]=e,l=t?t[0]:0,a=t?t[1]:0,u=t?t[2]:0,c=this.modelRootMatrix;c&&(i=c[0]*e[0]+c[4]*e[1]+c[8]*e[2]+c[12],s=c[1]*e[0]+c[5]*e[1]+c[9]*e[2]+c[13],o=c[2]*e[0]+c[6]*e[1]+c[10]*e[2]+c[14],t&&(l=c[0]*t[0]+c[4]*t[1]+c[8]*t[2],a=c[1]*t[0]+c[5]*t[1]+c[9]*t[2],u=c[2]*t[0]+c[6]*t[1]+c[10]*t[2]));let h=r[0]*i+r[4]*s+r[8]*o+r[12],m=r[1]*i+r[5]*s+r[9]*o+r[13],b=r[2]*i+r[6]*s+r[10]*o+r[14],p=r[3]*i+r[7]*s+r[11]*o+r[15];if(p<=1e-4)return{x:0,y:0,z:1,visible:!1};let x=h/p,T=m/p,I=b/p,N=this.canvas.getBoundingClientRect(),f=N.width||this.canvas.clientWidth||this.canvas.width||300,R=N.height||this.canvas.clientHeight||this.canvas.height||150,g=(x*.5+.5)*f,A=(-T*.5+.5)*R,D=x>=-1.1&&x<=1.1&&T>=-1.1&&T<=1.1&&I>=-1&&I<=1;if(D&&t){let[v,w,C]=Fe(this),d=[i-v,s-w,o-C];l*d[0]+a*d[1]+u*d[2]>.05&&(D=!1)}return{x:g,y:A,z:I,visible:D}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let o=[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],u=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*o[0]+s*l[0])*u,a[1]+=(-i*o[1]+s*l[1])*u,a[2]+=(-i*o[2]+s*l[2])*u,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.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,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,o=r.height||300,l=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),a=i.height>0?Math.floor((t-i.top)*(o/i.height)):Math.floor(t);return this.performMeshPick(l,a,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,s=Math.max(1,this.canvas.width||300),o=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let l=Q();te(l,this.projMatrix,this.viewMatrix);let a=[],u=Math.max(0,Math.min(s-1,e)),c=Math.max(0,Math.min(o-1,o-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==o)&&this.resizePickingFbo(s,o),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,o),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let D=0;D<this.meshes.length;D++){let v=this.meshes[D];if(v.visible===!1||v.isPluginMesh)continue;let w=D+1,C=(w&255)/255,d=(w>>8&255)/255,y=(w>>16&255)/255;i.uniform4f(this.uPick.uColorId,C,d,y,1),te(this.modelMatrix,this.modelRootMatrix,v.transform);let S=v.instanceMatrices;if(S&&S.length>=16){let M=S.length>>4,E=Q();for(let P of v.primitives){i.bindVertexArray(P.vao);for(let F=0;F<M;F++)te(E,this.modelMatrix,S.subarray(F*16,F*16+16)),te(this.mvpMatrix,l,E),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Xe(i,P)}}else{te(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let M of v.primitives)i.bindVertexArray(M.vao),Xe(i,M)}}let g=new Uint8Array(4);i.readPixels(u,c,1,1,6408,5121,g),i.bindFramebuffer(36160,null);let A=g[0]+(g[1]<<8)+(g[2]<<16);A>0&&A<=this.meshes.length&&(a=[this.meshes[A-1]])}a.length===0&&(a=this.meshes.filter(g=>g.visible!==!1));let h=null,m=1/0,b=[0,0,0],p=[0,1,0],[x,T,I]=Fe(this),N=Q();for(let g of a){te(N,this.modelRootMatrix,g.transform);let A=g.instanceMatrices,D=A&&A.length>=16?A.length>>4:1;for(let v=0;v<D;v++){A&&A.length>=16?te(this.modelMatrix,N,A.subarray(v*16,v*16+16)):this.modelMatrix.set(N),te(this.mvpMatrix,l,this.modelMatrix);let w=Q();if(!nn(w,this.mvpMatrix))continue;let C=(u+.5)/s*2-1,d=(c+.5)/o*2-1,y=[0,0,0],S=[0,0,0];ht(y,C,d,-1,w),ht(S,C,d,1,w);let M=S[0]-y[0],E=S[1]-y[1],P=S[2]-y[2],F=Math.hypot(M,E,P)||1,B=M/F,k=E/F,O=P/F,_={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((z=>{for(let U of g.primitives){if(!U.positions)continue;let H=U.positions,L=U.indices,V=Math.floor(L?L.length/3:H.length/9);for(let X=0;X<V;X++){let W=L?L[X*3]:X*3,Y=L?L[X*3+1]:X*3+1,ie=L?L[X*3+2]:X*3+2;rn(y[0],y[1],y[2],B,k,O,H[W*3],H[W*3+1],H[W*3+2],H[Y*3],H[Y*3+1],H[Y*3+2],H[ie*3],H[ie*3+1],H[ie*3+2],_,z)}}})(1e-4),isFinite(_.distance)){let z=_.point[0],U=_.point[1],H=_.point[2],L=this.modelMatrix,V=L[0]*z+L[4]*U+L[8]*H+L[12],X=L[1]*z+L[5]*U+L[9]*H+L[13],W=L[2]*z+L[6]*U+L[10]*H+L[14],Y=V-x,ie=X-T,ce=W-I,$=Math.hypot(Y,ie,ce);if($<m){me(this.normalMatrix,this.modelMatrix);let Z=this.normalMatrix,oe=_.normal[0],ue=_.normal[1],K=_.normal[2],re=Z[0]*oe+Z[3]*ue+Z[6]*K,J=Z[1]*oe+Z[4]*ue+Z[7]*K,ae=Z[2]*oe+Z[5]*ue+Z[8]*K,be=Math.hypot(re,J,ae)||1;re/=be,J/=be,ae/=be,re*Y+J*ie+ae*ce>0&&(re=-re,J=-J,ae=-ae),h=g,m=Math.round($*1e3)/1e3,b=[Math.round(V*1e3)/1e3,Math.round(X*1e3)/1e3,Math.round(W*1e3)/1e3],p=[Math.round(re*1e3)/1e3,Math.round(J*1e3)/1e3,Math.round(ae*1e3)/1e3]}}}}if(!h)return null;let R={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:m,hitPoint:b,normal:p,screenX:e,screenY:t};if(r){for(let g of se)g.onMeshSelect?.(this,R);this.opts.onMeshClick&&this.opts.onMeshClick(R),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:R}))}return R}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,s=i?e-r:e,o=i?Math.max(1,t-r):r,l=(s+.5)/o*2-1;return Math.floor((l*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Ge(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center;Ee(this.viewMatrix,Fe(this),r,[0,1,0]),te(this.mvpMatrix,this.projMatrix,this.viewMatrix),me(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let r of se)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of se)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=r-(e*r+t*i),s[13]=0,s[14]=i-(-t*r+e*i),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let o of se)o.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let o of se)o.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=s;let o={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(o),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:o}))}}renderXRView(e,t,r,i,s=!0,o=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,u=e?.transform?.position,c=u?[u.x,u.y,u.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:l,projMatrix:a,eyePos:c,viewport:i,eye:e?.eye||"none",clear:o>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let f=Math.max(2,this.canvas.width||2),R=Math.max(1,this.canvas.height||1),g=Math.max(1,Math.floor(f*.5)),A=Math.max(1,f-g),D=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),v=this.customTarget||this.bounds.center,[w,C,d]=Fe(this),y=Math.cos(this.currTheta),S=-Math.sin(this.currTheta),M=.032,E=Q(),P=Q(),F=[w-y*M,C,d-S*M],B=[v[0]-y*M*.25,v[1],v[2]-S*M*.25];Ge(E,this.fov,g/R,.1,D),Ee(P,F,B,[0,1,0]);let k=Q(),O=Q(),_=[w+y*M,C,d+S*M],G=[v[0]+y*M*.25,v[1],v[2]+S*M*.25];Ge(k,this.fov,A/R,.1,D),Ee(O,_,G,[0,1,0]),this.render({viewMatrix:P,projMatrix:E,eyePos:F,viewport:[0,0,g,R],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:O,projMatrix:k,eyePos:_,viewport:[g,0,A,R],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,f,R);return}let t=this.gl,r=0,i=0,s=this.canvas.width,o=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],o=e.viewport[3],t.viewport(r,i,s,o)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let l=Q(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,te(l,e?.projMatrix??this.projMatrix,a);let u=ee().xrDepthShader,c=Vn(this.toneMapping),[h,m,b]=e?e.eyePos:Fe(this);for(let f of se)f.onBeforeDrawScene?.(this,t,l,[h,m,b],c);let p=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&p===0)return;let x=e?.eye||"none",T=!1,I=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,N=f=>{for(let R=0;R<I.length;R++){let g=I[R];if(g.visible===!1)continue;let A=this.selectedMeshName!==""&&g.name===this.selectedMeshName;R<p||g.worldSpace===!0||g.name==="__xr_reticle__"?this.modelMatrix.set(g.transform):te(this.modelMatrix,this.modelRootMatrix,g.transform),te(this.mvpMatrix,l,this.modelMatrix),me(g.normalMatrix,this.modelMatrix);let D=g.extras?.xr?.stereo||g.userData?.xr?.stereo,v=0,w=0,C=1,d=1;D==="sbs"?(C=.5,v=x==="right"?.5:0):D==="ou"&&(d=.5,w=x==="right"?.5:0);for(let y of g.primitives){let S=!!y.isTransmissive;if(!f&&S){T=!0;continue}if(f&&!S)continue;let M=y.customProgram||this.renderProg,E=y.customUniforms||this.uRender;t.useProgram(M),t.uniform1i(E.uToneMapping,c),t.uniform1f(E.uEnvIntensity,this.envIntensity),E.uExposure&&t.uniform1f(E.uExposure,this.exposure),t.uniform3f(E.uCameraPos,h,m,b),t.uniform1f(E.uEmissive,A?1:0),t.uniformMatrix4fv(E.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(E.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(E.uNormalMatrix,!1,g.normalMatrix),E.uUvTransform&&t.uniform4f(E.uUvTransform,v,w,C,d),E.uViewportSize&&t.uniform2f(E.uViewportSize,Math.max(1,s),Math.max(1,o)),u?.bind(t,E,this.xrDepthState,a,[r,i,Math.max(1,s),Math.max(1,o)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(E.uEnvironmentMap,4),t.uniform1i(E.uHasEnvironmentMap,1)):t.uniform1i(E.uHasEnvironmentMap,0),this.bindLights(E),E.uSectionEnabled&&t.uniform1i(E.uSectionEnabled,0);for(let F of se)F.onBeforeDrawPrimitive?.(t,M,y,g,this.worldMatrices||[],this.gltf);t.uniform4fv(E.uBaseColor,y.baseColor),t.uniform1f(E.uMetallic,y.metallic),t.uniform1f(E.uRoughness,y.roughness),E.uClearcoat&&t.uniform2f(E.uClearcoat,y.clearcoat??0,y.clearcoatRoughness??.04),y.texture?(t.activeTexture(33984),t.bindTexture(3553,y.texture),t.uniform1i(E.uBaseColorTexture,0),t.uniform1i(E.uHasTexture,1)):t.uniform1i(E.uHasTexture,0),y.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,y.metallicRoughnessTexture),t.uniform1i(E.uMetallicRoughnessTexture,1),t.uniform1i(E.uHasMetallicRoughnessTexture,1)):t.uniform1i(E.uHasMetallicRoughnessTexture,0),y.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,y.normalTexture),t.uniform1i(E.uNormalTexture,2),t.uniform1i(E.uHasNormalTexture,1),t.uniform1f(E.uNormalScale,y.normalScale)):t.uniform1i(E.uHasNormalTexture,0),y.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,y.occlusionTexture),t.uniform1i(E.uOcclusionTexture,3),t.uniform1i(E.uHasOcclusionTexture,1),t.uniform1f(E.uOcclusionStrength,y.occlusionStrength)):t.uniform1i(E.uHasOcclusionTexture,0),t.bindVertexArray(y.vao);let P=g.instanceMatrices;if(P&&P.length>=16&&y.instanced&&E.uInstanced&&E.uViewProj){let F=P.length>>4;t.uniform1i(E.uInstanced,1),t.uniformMatrix4fv(E.uViewProj,!1,l),y.indices?t.drawElementsInstanced(4,y.indexCount,y.indexType,0,F):t.drawArraysInstanced(4,0,y.indexCount,F),t.uniform1i(E.uInstanced,0)}else if(P&&P.length>=16){let F=P.length>>4,B=g.instanceColors,k=Q(),O=new Float32Array(9),_=[y.baseColor[0],y.baseColor[1],y.baseColor[2],y.baseColor[3]];for(let G=0;G<F;G++)te(k,this.modelMatrix,P.subarray(G*16,G*16+16)),te(this.mvpMatrix,l,k),me(O,k),t.uniformMatrix4fv(E.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(E.uModel,!1,k),t.uniformMatrix3fv(E.uNormalMatrix,!1,O),B&&(_[0]=y.baseColor[0]*B[G*3],_[1]=y.baseColor[1]*B[G*3+1],_[2]=y.baseColor[2]*B[G*3+2],_[3]=y.baseColor[3],t.uniform4fv(E.uBaseColor,_)),Xe(t,y)}else Xe(t,y)}}};if(N(!1),T){for(let f of se)f.onBeforeTransmissivePass?.(t,this);N(!0)}for(let f of se)f.onAfterRender?.(t,this,l)}disposeMeshListGpuResources(e,t){yn(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of se)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};We.registerPlugin=en,We.getRegisteredPlugins=tn;function Zn(n){return n+3&-4}function Jn(n,e=0){let t=(_,G)=>typeof _=="number"&&Number.isFinite(_)?_:G,r=t(n[e+12],0),i=t(n[e+13],0),s=t(n[e+14],0),o=t(n[e+0],1),l=t(n[e+1],0),a=t(n[e+2],0),u=t(n[e+4],0),c=t(n[e+5],1),h=t(n[e+6],0),m=t(n[e+8],0),b=t(n[e+9],0),p=t(n[e+10],1),x=Math.hypot(o,l,a),T=Math.hypot(u,c,h),I=Math.hypot(m,b,p);o*(c*p-b*h)-u*(l*p-b*a)+m*(l*h-c*a)<0&&(x=-x);let f=Math.abs(x)>1e-8?1/x:0,R=Math.abs(T)>1e-8?1/T:0,g=Math.abs(I)>1e-8?1/I:0,A=o*f,D=l*f,v=a*f,w=u*R,C=c*R,d=h*R,y=m*g,S=b*g,M=p*g,E=A+C+M,P=0,F=0,B=0,k=1;if(E>0){let _=.5/Math.sqrt(E+1);k=.25/_,P=(d-S)*_,F=(y-v)*_,B=(D-w)*_}else if(A>C&&A>M){let _=2*Math.sqrt(Math.max(0,1+A-C-M));_>1e-8&&(k=(d-S)/_,P=.25*_,F=(w+D)/_,B=(y+v)/_)}else if(C>M){let _=2*Math.sqrt(Math.max(0,1+C-A-M));_>1e-8&&(k=(y-v)/_,P=(w+D)/_,F=.25*_,B=(d+S)/_)}else{let _=2*Math.sqrt(Math.max(0,1+M-A-C));_>1e-8&&(k=(D-w)/_,P=(y+v)/_,F=(d+S)/_,B=.25*_)}let O=Math.hypot(P,F,B,k);return O>1e-8&&Number.isFinite(O)?(P/=O,F/=O,B/=O,k/=O):(P=0,F=0,B=0,k=1),{t:[r,i,s],r:[P,F,B,k],s:[x,T,I]}}function Qn(n){let e={};return n.grab&&(e.interactable={mode:typeof n.grab=="string"?n.grab:"2-hand"},e.movable={scaleInZ:!!n.scale,minScale:typeof n.scale=="object"?n.scale.min??.1:.1,maxScale:typeof n.scale=="object"?n.scale.max??10:10}),n.billboard&&(e.billboard={mode:typeof n.billboard=="string"?n.billboard:"capsule"}),n.follow&&(e.follow={target:typeof n.follow=="object"?n.follow.mode??"head":n.follow}),n.anchor&&(e.anchor={plane:n.anchor}),n.physics&&n.physics!=="none"&&(e.rigidbody={type:n.physics}),e}function ke(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],o=[],l=[],a=new Set,u=[],c=[],h=new Map,m=[],b=[];function p(w){let C=h.get(w);if(C!==void 0)return C;C=c.length,h.set(w,C);let d=w,y=d.color?.r??.8,S=d.color?.g??.8,M=d.color?.b??.8,E=d.opacity??1,P={name:d.name||"",pbrMetallicRoughness:{baseColorFactor:[y,S,M,E],metallicFactor:d.metalness??.1,roughnessFactor:d.roughness??.5},doubleSided:d.side===2||!!d.doubleSided};if(d.emissive&&(d.emissive.r>0||d.emissive.g>0||d.emissive.b>0)){let B=d.emissiveIntensity??1;P.emissiveFactor=[d.emissive.r*B,d.emissive.g*B,d.emissive.b*B]}let F={};return d.clearcoat&&d.clearcoat>0&&(F.KHR_materials_clearcoat={clearcoatFactor:d.clearcoat,clearcoatRoughnessFactor:d.clearcoatRoughness||0}),d.sheen&&d.sheen>0&&(F.KHR_materials_sheen={sheenColorFactor:d.sheenColor?[d.sheenColor.r,d.sheenColor.g,d.sheenColor.b]:[1,1,1],sheenRoughnessFactor:d.sheenRoughness||0}),d.transmission&&d.transmission>0&&(F.KHR_materials_transmission={transmissionFactor:d.transmission}),d.thickness&&d.thickness>0&&(F.KHR_materials_volume={thicknessFactor:d.thickness,attenuationDistance:d.attenuationDistance??1/0,attenuationColor:d.attenuationColor?[d.attenuationColor.r,d.attenuationColor.g,d.attenuationColor.b]:[1,1,1]}),d.ior!==void 0&&d.ior!==1.5&&(F.KHR_materials_ior={ior:d.ior}),d.dispersion&&d.dispersion>0&&(F.KHR_materials_dispersion={dispersion:d.dispersion}),d.iridescence&&d.iridescence>0&&(F.KHR_materials_iridescence={iridescenceFactor:d.iridescence,iridescenceIor:d.iridescenceIOR??1.3}),Object.keys(F).length>0&&(P.extensions=F),c.push(P),C}function x(w,C){let d=new Uint8Array(w.buffer,w.byteOffset,w.byteLength),y=Zn(d.byteLength),S=new Uint8Array(y);S.set(d),t.push(S);let M=i.length;return i.push({buffer:0,byteOffset:r,byteLength:d.byteLength,target:C}),r+=y,M}function T(w,C,d,y,S,M,E){let P=x(w,d),F=s.length,B={bufferView:P,byteOffset:0,componentType:y,count:S,type:C};return M&&(B.min=M),E&&(B.max=E),s.push(B),F}n.traverse(w=>{(w.isLight||w.color&&w.intensity!==void 0)&&b.push({type:w.type,color:[w.color.r,w.color.g,w.color.b],intensity:w.intensity,position:[w.position.x,w.position.y,w.position.z]})});let I=[];function N(w){let C={name:w.name||""},d=w.position,y=w.quaternion,S=w.scale;if((d.x||d.y||d.z)&&(C.translation=[d.x,d.y,d.z]),(y.x||y.y||y.z||y.w!==1)&&(C.rotation=[y.x,y.y,y.z,y.w]),(S.x!==1||S.y!==1||S.z!==1)&&(C.scale=[S.x,S.y,S.z]),w.userData&&Object.keys(w.userData).length>0&&(C.extras=JSON.parse(JSON.stringify(w.userData,(E,P)=>{if(!(E==="__proto__"||E==="prototype"||E==="constructor"))return typeof P=="function"?void 0:P})),w.userData.xr)){let E=Qn(w.userData.xr);C.extensions={...C.extensions||{},MOZ_hubs_components:E,ANDROID_xr_scenecore:E},ee().xrTraitSerializer?.gltfNode(C,w.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(w.geometry){let E=w.geometry,P=E.attributes.position;if(P&&P.count>0){let F=[1/0,1/0,1/0],B=[-1/0,-1/0,-1/0];for(let U=0;U<P.count;U++){let H=P.getX(U),L=P.getY(U),V=P.getZ(U);H<F[0]&&(F[0]=H),H>B[0]&&(B[0]=H),L<F[1]&&(F[1]=L),L>B[1]&&(B[1]=L),V<F[2]&&(F[2]=V),V>B[2]&&(B[2]=V)}let O={attributes:{POSITION:T(P.array,"VEC3",34962,5126,P.count,F,B)}};if(E.attributes.normal&&(O.attributes.NORMAL=T(E.attributes.normal.array,"VEC3",34962,5126,E.attributes.normal.count)),E.attributes.uv&&(O.attributes.TEXCOORD_0=T(E.attributes.uv.array,"VEC2",34962,5126,E.attributes.uv.count)),E.index){let U=E.index.array instanceof Uint32Array;O.indices=T(E.index.array,"SCALAR",34963,U?5125:5123,E.index.count)}w.material&&(O.material=p(w.material));let _=w.userData?.variants;if(_&&typeof _=="object"){let U=new Map;for(let H of Object.keys(_)){if(!H||H==="__proto__"||H==="constructor"||H==="prototype")continue;let L=_[H];if(!L||typeof L!="object")continue;let V=m.indexOf(H);if(V===-1&&m.length<256&&(V=m.length,m.push(H)),V===-1)continue;let X=p(L),W=U.get(X);W||(W=[],U.set(X,W)),W.push(V)}if(U.size>0){let H=[];for(let[L,V]of U.entries())H.push({material:L,variants:V});O.extensions={...O.extensions||{},KHR_materials_variants:{mappings:H}},a.add("KHR_materials_variants")}}let G=w;if(G.isInstancedMesh&&typeof G.count=="number"&&G.count>0&&G.instanceMatrix?.array){let U=Math.min(1e4,Math.floor(G.count)),H=G.instanceMatrix.array,L=new Float32Array(U*3),V=new Float32Array(U*4),X=new Float32Array(U*3);for(let Y=0;Y<U;Y++){let{t:ie,r:ce,s:$}=Jn(H,Y*16);L[Y*3]=ie[0],L[Y*3+1]=ie[1],L[Y*3+2]=ie[2],V[Y*4]=ce[0],V[Y*4+1]=ce[1],V[Y*4+2]=ce[2],V[Y*4+3]=ce[3],X[Y*3]=$[0],X[Y*3+1]=$[1],X[Y*3+2]=$[2]}let W={TRANSLATION:T(L,"VEC3",0,5126,U),ROTATION:T(V,"VEC4",0,5126,U),SCALE:T(X,"VEC3",0,5126,U)};if(G.instanceColor?.array&&G.instanceColor.array.length>=U*3){let Y=new Float32Array(G.instanceColor.array.subarray(0,U*3));W._COLOR_0=T(Y,"VEC3",0,5126,U)}C.extensions={...C.extensions||{},EXT_mesh_gpu_instancing:{attributes:W}},a.add("EXT_mesh_gpu_instancing")}let z=o.length;o.push({primitives:[O],name:w.name,...C.extras?{extras:C.extras}:{}}),C.mesh=z}}let M=l.length;if(l.push(C),u.push(w),w.children.length>0){C.children=[];for(let E of w.children)C.children.push(N(E))}return M}for(let w of n.children)I.push(N(w));let f=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),R=[];if(typeof f=="function"&&u.length>0){let w=e?.duration??4,C=e?.fps??15,d=Math.max(2,Math.round(w*C)+1),y=new Float32Array(d),S=u.map(_=>({px:_.position.x,py:_.position.y,pz:_.position.z,qx:_.quaternion.x,qy:_.quaternion.y,qz:_.quaternion.z,qw:_.quaternion.w,sx:_.scale.x,sy:_.scale.y,sz:_.scale.z})),M=u.map(()=>new Float32Array(d*3)),E=u.map(()=>new Float32Array(d*4)),P=u.map(()=>new Float32Array(d*3));for(let _=0;_<d;_++){let G=_/(d-1)*w;y[_]=G;try{f(G)}catch{}for(let z=0;z<u.length;z++){let U=u[z];M[z][_*3]=U.position.x,M[z][_*3+1]=U.position.y,M[z][_*3+2]=U.position.z,E[z][_*4]=U.quaternion.x,E[z][_*4+1]=U.quaternion.y,E[z][_*4+2]=U.quaternion.z,E[z][_*4+3]=U.quaternion.w,P[z][_*3]=U.scale.x,P[z][_*3+1]=U.scale.y,P[z][_*3+2]=U.scale.z}}for(let _=0;_<u.length;_++){let G=u[_],z=S[_];G.position.set(z.px,z.py,z.pz),G.quaternion.set(z.qx,z.qy,z.qz,z.qw),G.scale.set(z.sx,z.sy,z.sz)}n.updateMatrixWorld(!0);let F=null,B=()=>(F===null&&(F=T(y,"SCALAR",0,5126,d,[0],[w])),F),k=[],O=[];for(let _=0;_<u.length;_++){let G=S[_],z=!1,U=!1,H=!1;for(let L=0;L<d;L++)(Math.abs(M[_][L*3]-G.px)>1e-4||Math.abs(M[_][L*3+1]-G.py)>1e-4||Math.abs(M[_][L*3+2]-G.pz)>1e-4)&&(z=!0),(Math.abs(E[_][L*4]-G.qx)>1e-4||Math.abs(E[_][L*4+1]-G.qy)>1e-4||Math.abs(E[_][L*4+2]-G.qz)>1e-4||Math.abs(E[_][L*4+3]-G.qw)>1e-4)&&(U=!0),(Math.abs(P[_][L*3]-G.sx)>1e-4||Math.abs(P[_][L*3+1]-G.sy)>1e-4||Math.abs(P[_][L*3+2]-G.sz)>1e-4)&&(H=!0);if(z){let L=T(M[_],"VEC3",0,5126,d),V=k.length;k.push({input:B(),interpolation:"LINEAR",output:L}),O.push({sampler:V,target:{node:_,path:"translation"}})}if(U){let L=T(E[_],"VEC4",0,5126,d),V=k.length;k.push({input:B(),interpolation:"LINEAR",output:L}),O.push({sampler:V,target:{node:_,path:"rotation"}})}if(H){let L=T(P[_],"VEC3",0,5126,d),V=k.length;k.push({input:B(),interpolation:"LINEAR",output:L}),O.push({sampler:V,target:{node:_,path:"scale"}})}}O.length>0&&R.push({name:"ProceduralLoop",samplers:k,channels:O})}let g=Zt(l,o,n.userData),A={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:I}],scene:0,nodes:l,meshes:o,materials:c,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...R.length>0?{animations:R}:{},...g||a.size>0?{extensionsUsed:[...g?["KHR_interactivity"]:[],...a]}:{},...g||m.length>0?{extensions:{...g?{KHR_interactivity:g}:{},...m.length>0?{KHR_materials_variants:{variants:m.map(w=>({name:w}))}}:{}}}:{}},D=new Uint8Array(r),v=0;for(let w of t)D.set(w,v),v+=w.byteLength;return{gltf:A,bin:D.buffer,lights:b,environmentIntensity:n.environmentIntensity}}function Ye(n){return new TextEncoder().encode(n)}function je(n,e){let{gltf:t,bin:r}=ke(n,e),i=JSON.stringify(t),s=Ye(i),o=(4-s.byteLength%4)%4,l=s.byteLength+o,a=20+l+8+r.byteLength,u=new Uint8Array(a),c=new DataView(u.buffer);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0),c.setUint32(8,a,!0),c.setUint32(12,l,!0),c.setUint32(16,1313821514,!0),u.set(s,20);for(let m=0;m<o;m++)u[20+s.byteLength+m]=32;let h=20+l;return c.setUint32(h,r.byteLength,!0),c.setUint32(h+4,5130562,!0),u.set(new Uint8Array(r),h+8),u}function er(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,s=i.attributes.position;if(!s||s.count===0)return;let o=s.count,l=new Float32Array(o*3),a=r.matrixWorld.elements;for(let v=0;v<o;v++){let w=s.getX(v),C=s.getY(v),d=s.getZ(v);l[v*3]=a[0]*w+a[4]*C+a[8]*d+a[12],l[v*3+1]=a[1]*w+a[5]*C+a[9]*d+a[13],l[v*3+2]=a[2]*w+a[6]*C+a[10]*d+a[14]}let u;if(i.attributes.normal){let v=i.attributes.normal;u=new Float32Array(o*3);let w=new Float32Array(9);me(w,a);for(let C=0;C<o;C++){let d=v.getX(C),y=v.getY(C),S=v.getZ(C),M=w[0]*d+w[3]*y+w[6]*S,E=w[1]*d+w[4]*y+w[7]*S,P=w[2]*d+w[5]*y+w[8]*S,F=Math.hypot(M,E,P)||1;u[C*3]=M/F,u[C*3+1]=E/F,u[C*3+2]=P/F}}let c;if(i.attributes.uv){let v=i.attributes.uv;c=new Float32Array(o*2);for(let w=0;w<o;w++)c[w*2]=v.getX(w),c[w*2+1]=v.getY(w)}let h;if(i.index)h=i.index.array;else{h=o>65535?new Uint32Array(o):new Uint16Array(o);for(let v=0;v<o;v++)h[v]=v}let m="DefaultMaterial",b=[.8,.8,.8],p=.5,x=.1,T=0,I=0,N=1.5,f=1,R=[0,0,0];if(r.material){let v=r.material;m=v.name||`Material_${t.length}`,v.color&&(b=[v.color.r,v.color.g,v.color.b]),typeof v.roughness=="number"&&(p=v.roughness),typeof v.metalness=="number"&&(x=v.metalness),typeof v.clearcoat=="number"&&(T=v.clearcoat),typeof v.clearcoatRoughness=="number"&&(I=v.clearcoatRoughness),typeof v.ior=="number"&&(N=v.ior);let w=typeof v.opacity=="number"?v.opacity:1,C=typeof v.transmission=="number"?v.transmission:0;if(f=w*(1-C),v.emissive&&(v.emissive.r>0||v.emissive.g>0||v.emissive.b>0)){let d=v.emissiveIntensity??1;R=[v.emissive.r*d,v.emissive.g*d,v.emissive.b*d]}}let g,A=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof A=="function"){let v=e?.duration??4,w=e?.fps??4,C=Math.max(2,Math.round(v*w)+1),d=[],y=[],S=[],M=[],E=[r.position.x,r.position.y,r.position.z],P=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],F=[r.scale.x,r.scale.y,r.scale.z],B=!1;for(let k=0;k<C;k++){let O=k/(C-1)*v;d.push(O);try{A(O)}catch{}y.push([r.position.x,r.position.y,r.position.z]),S.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),M.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-E[0])>1e-4||Math.abs(r.position.y-E[1])>1e-4||Math.abs(r.position.z-E[2])>1e-4||Math.abs(r.quaternion.x-P[0])>1e-4||Math.abs(r.quaternion.y-P[1])>1e-4||Math.abs(r.quaternion.z-P[2])>1e-4||Math.abs(r.quaternion.w-P[3])>1e-4||Math.abs(r.scale.x-F[0])>1e-4)&&(B=!0)}r.position.set(E[0],E[1],E[2]),r.quaternion.set(P[0],P[1],P[2],P[3]),r.scale.set(F[0],F[1],F[2]),B&&(g={times:d,translations:y,rotations:S,scales:M})}let D=r;if(D.isInstancedMesh&&typeof D.count=="number"&&D.count>0&&D.instanceMatrix?.array){let v=Math.min(1e3,Math.floor(D.count)),w=D.instanceMatrix.array,C=D.instanceColor?.array,d=r.name||`Mesh_${t.length}`,y=new Float32Array(16),S=new Float32Array(9);for(let M=0;M<v;M++){let E=w.subarray(M*16,(M+1)*16);te(y,a,E);let P=new Float32Array(o*3);for(let O=0;O<o;O++){let _=s.getX(O),G=s.getY(O),z=s.getZ(O);P[O*3]=y[0]*_+y[4]*G+y[8]*z+y[12],P[O*3+1]=y[1]*_+y[5]*G+y[9]*z+y[13],P[O*3+2]=y[2]*_+y[6]*G+y[10]*z+y[14]}let F;if(i.attributes.normal){let O=i.attributes.normal;F=new Float32Array(o*3),me(S,y);for(let _=0;_<o;_++){let G=O.getX(_),z=O.getY(_),U=O.getZ(_),H=S[0]*G+S[3]*z+S[6]*U,L=S[1]*G+S[4]*z+S[7]*U,V=S[2]*G+S[5]*z+S[8]*U,X=Math.hypot(H,L,V)||1;F[_*3]=H/X,F[_*3+1]=L/X,F[_*3+2]=V/X}}let B=b,k=m;C&&C.length>=(M+1)*3&&(B=[b[0]*C[M*3],b[1]*C[M*3+1],b[2]*C[M*3+2]],k=`${m}_inst_${M}`),t.push({name:`${d}_${M}`,positions:P,indices:h,normals:F,uvs:c,materialName:k,color:B,roughness:p,metallic:x,clearcoat:T,clearcoatRoughness:I,ior:N,opacity:f,emissiveColor:R,xrTraits:r.userData?.xr})}return}t.push({name:r.name||`Mesh_${t.length}`,positions:l,indices:h,normals:u,uvs:c,materialName:m,color:b,roughness:p,metallic:x,clearcoat:T,clearcoatRoughness:I,ior:N,opacity:f,emissiveColor:R,xrTraits:r.userData?.xr,timeSamples:g})}}),t}function vn(n){let e=[],t=n.gltf,r=ee().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(t,n);let i=n.bin,s=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),o=t.accessors||[],l=t.bufferViews||[],a=t.materials||[],u=t.meshes||[],c=t.nodes||[];function h(p){let x=o[p];if(!x)throw new Error(`Accessor ${p} not found`);let T=l[x.bufferView||0],I=(T.byteOffset||0)+(x.byteOffset||0),N=T.byteLength||0,f=s.slice(I,I+N);return{acc:x,buffer:f}}let m=new Map;if(c.length>0){let p=He(t);for(let x=0;x<p.length;x++)m.set(x,p[x])}function b(p,x,T,I){let N=u[p];if(!N)return;let f=new Float32Array(9);me(f,x);for(let R=0;R<(N.primitives||[]).length;R++){let g=N.primitives[R],A=g.attributes?.POSITION;if(A===void 0)continue;let{acc:D,buffer:v}=h(A),w=new Float32Array(v,0,D.count*3),C=new Float32Array(w.length);for(let L=0;L<D.count;L++){let V=w[L*3],X=w[L*3+1],W=w[L*3+2];C[L*3]=x[0]*V+x[4]*X+x[8]*W+x[12],C[L*3+1]=x[1]*V+x[5]*X+x[9]*W+x[13],C[L*3+2]=x[2]*V+x[6]*X+x[10]*W+x[14]}let d,y=g.attributes?.NORMAL;if(y!==void 0){let{acc:L,buffer:V}=h(y),X=new Float32Array(V,0,L.count*3);d=new Float32Array(X.length);for(let W=0;W<L.count;W++){let Y=X[W*3],ie=X[W*3+1],ce=X[W*3+2],$=f[0]*Y+f[3]*ie+f[6]*ce,Z=f[1]*Y+f[4]*ie+f[7]*ce,oe=f[2]*Y+f[5]*ie+f[8]*ce,ue=Math.hypot($,Z,oe)||1;d[W*3]=$/ue,d[W*3+1]=Z/ue,d[W*3+2]=oe/ue}}let S,M=g.attributes?.TEXCOORD_0;if(M!==void 0){let{acc:L,buffer:V}=h(M);S=new Float32Array(V,0,L.count*2)}let E;if(g.indices!==void 0){let{acc:L,buffer:V}=h(g.indices);L.componentType===5125?E=new Uint32Array(V,0,L.count):E=new Uint16Array(V,0,L.count);let X=D.count;for(let W of E)if(W>=X)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${X}).`)}else{let L=D.count;E=L>65535?new Uint32Array(L):new Uint16Array(L);for(let V=0;V<L;V++)E[V]=V}let P="DefaultMaterial",F=[.8,.8,.8],B=.5,k=.1,O=0,_=0,G=1.5,z=1,U=[0,0,0];if(g.material!==void 0&&a[g.material]){let L=a[g.material];P=L.name||`Material_${g.material}`;let V=L.pbrMetallicRoughness||{},X=1;Array.isArray(V.baseColorFactor)&&(F=[V.baseColorFactor[0],V.baseColorFactor[1],V.baseColorFactor[2]],typeof V.baseColorFactor[3]=="number"&&(X=V.baseColorFactor[3])),typeof V.roughnessFactor=="number"&&(B=V.roughnessFactor),typeof V.metallicFactor=="number"&&(k=V.metallicFactor),Array.isArray(L.emissiveFactor)&&L.emissiveFactor.length>=3&&(U=[L.emissiveFactor[0],L.emissiveFactor[1],L.emissiveFactor[2]]);let W=L.extensions||{};W.KHR_materials_clearcoat&&(O=W.KHR_materials_clearcoat.clearcoatFactor??0,_=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),W.KHR_materials_ior&&typeof W.KHR_materials_ior.ior=="number"&&(G=W.KHR_materials_ior.ior);let Y=W.KHR_materials_transmission?.transmissionFactor??0;z=X*(1-Y)}let H=(N.primitives||[]).length>1?`${T}_p${R}`:T;e.push({name:H,positions:C,indices:E,normals:d,uvs:S,materialName:P,color:F,roughness:B,metallic:k,clearcoat:O,clearcoatRoughness:_,ior:G,opacity:z,emissiveColor:U,xrTraits:I?.xr||N.extras?.xr})}}if(c.length>0)for(let p=0;p<c.length;p++){let x=c[p];if(x.mesh!==void 0&&x.mesh<u.length){let T=m.get(p)||Q(),I=x.name||u[x.mesh].name||`Node_${p}`,N=x.extensions?.EXT_mesh_gpu_instancing?.attributes;if(N&&typeof N=="object"){let f=N.TRANSLATION,R=N.ROTATION,g=N.SCALE,A=f!==void 0?(()=>{let{acc:C,buffer:d}=h(f);return new Float32Array(d,0,C.count*3)})():null,D=R!==void 0?(()=>{let{acc:C,buffer:d}=h(R);return new Float32Array(d,0,C.count*4)})():null,v=g!==void 0?(()=>{let{acc:C,buffer:d}=h(g);return new Float32Array(d,0,C.count*3)})():null,w=Math.min(1e3,A?A.length/3:D?D.length/4:v?v.length/3:0);if(w>0){let C=new Float32Array(16),d=new Float32Array(16);for(let y=0;y<w;y++){let S=A?[A[y*3],A[y*3+1],A[y*3+2]]:[0,0,0],M=D?[D[y*4],D[y*4+1],D[y*4+2],D[y*4+3]]:[0,0,0,1],E=v?[v[y*3],v[y*3+1],v[y*3+2]]:[1,1,1];we(C,M,S,E),te(d,T,C),b(x.mesh,d,`${I}_${y}`,x.extras)}continue}}b(x.mesh,T,I,x.extras)}}else{let p=Q();for(let x=0;x<u.length;x++){let T=u[x].name||`Mesh_${x}`;b(x,p,T,u[x].extras)}}return e}function xt(n,e){if(!n||typeof n!="string")return e;let t=n.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(t)&&(t="_"+t),t||e}function gn(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function j(n){if(!Number.isFinite(n)||Math.abs(n)<1e-7)return"0";let e=Number(n.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function xn(n){let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${j(n[r*3])}, ${j(n[r*3+1])}, ${j(n[r*3+2])})`;return t.join(", ")}function tr(n,e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${j(n[r*2])}, ${j(1-n[r*2+1])})`;return t.join(", ")}function nr(n){return Array.from(n).join(", ")}function vt(n){let e=new Map;for(let a of n){let u=xt(a.materialName,"DefaultMaterial");e.has(u)||e.set(u,{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 t=0,r=null;for(let a of n){if(a.timeSamples&&a.timeSamples.times.length>0){let u=a.timeSamples.times[a.timeSamples.times.length-1];u>t&&(t=u)}a.xrTraits?.anchor&&!r&&(r=a.xrTraits.anchor==="vertical"||a.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
|
|
252
|
+
void main(){fragColor=uColorId;}`;function gt(n,e,t){let r={};for(let i of t)r[i]=n.getUniformLocation(e,i);return r}var on=["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 hn(){let n=Q().xrDepthShader;return{fs:Hn.replace("/*XRD_U*/",n?.uniformsGLSL||"").replace("/*XRD_O*/",n?.occlusionGLSL||""),uniforms:n?[...on,...n.uniformNames]:on}}function $n(n){if(typeof n!="string")return null;let e=n.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let t=e.toLowerCase();return t.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:t.startsWith("https://")||t.startsWith("blob:")?e:t.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function pt(n,e,t,r,i,s,o,l){if(r===void 0||!e.accessors?.[r])return null;let a=dt(e,t,e.accessors[r],s);if(!a)return null;l&&(a=a.slice(),sn(a,l));let u=n.createBuffer();return o.push(u),n.bindBuffer(34962,u),n.bufferData(34962,a,35044),n.enableVertexAttribArray(i),n.vertexAttribPointer(i,s,5126,!1,0,0),a}function bt(n){let e=Number(n);return Number.isFinite(e)?Math.max(0,e):1}function fn(n,e,t){let r=hn(),i=mn,s=r.fs,o=!1;for(let a of ie)if(a.onResolveShader){let u=a.onResolveShader(e,t,i,s);u&&(i=u.vs,s=u.fs,o=!0)}let l=o?Xe(n,i,s):null;return{program:l,uniforms:l?gt(n,l,r.uniforms):null}}function Yn(n,e,t){let r=e.instanceMatrices;if(!r||r.length<16||typeof n.vertexAttribDivisor!="function"||typeof n.drawElementsInstanced!="function")return!1;let i=r.length>>4,s=e.instanceColors,o=new Float32Array(i*20);for(let a=0;a<i;a++)o.set(r.subarray(a*16,a*16+16),a*20),o[a*20+16]=s?s[a*3]:1,o[a*20+17]=s?s[a*3+1]:1,o[a*20+18]=s?s[a*3+2]:1,o[a*20+19]=1;let l=n.createBuffer();t.push(l),n.bindBuffer(34962,l),n.bufferData(34962,o,35044);for(let a=0;a<5;a++)n.enableVertexAttribArray(8+a),n.vertexAttribPointer(8+a,4,5126,!1,80,a*16),n.vertexAttribDivisor(8+a,1);return!0}function jn(n,e){let t=n.materials?.[e?.material];if(!t)return null;let r=[t.pbrMetallicRoughness?.baseColorTexture,t.pbrMetallicRoughness?.metallicRoughnessTexture,t.normalTexture,t.occlusionTexture,t.emissiveTexture];for(let i of r){let s=i?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var Fr=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),dn=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function We(n,e){e.indices?n.drawElements(4,e.indexCount,e.indexType,0):n.drawArrays(4,0,e.indexCount)}function pn(n,e){let t=n?.pbrMetallicRoughness,r=t?.baseColorFactor,i=n?.extensions?.KHR_materials_clearcoat,s=o=>o!==void 0&&e[o.index]?e[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:t?.metallicFactor??.1,roughness:t?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:s(t?.baseColorTexture),metallicRoughnessTexture:s(t?.metallicRoughnessTexture),normalTexture:s(n?.normalTexture),normalScale:n?.normalTexture?.scale??1,occlusionTexture:s(n?.occlusionTexture),occlusionStrength:n?.occlusionTexture?.strength??1,isTransmissive:(n?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function bn(n,e,t){let r=new Set,i=s=>{s&&!r.has(s)&&(r.add(s),n.deleteTexture(s))};for(let s of e)for(let o of s.primitives){if(o.vao&&n.deleteVertexArray(o.vao),o.buffers)for(let a of o.buffers)n.deleteBuffer(a);i(o.texture),i(o.metallicRoughnessTexture),i(o.normalTexture),i(o.occlusionTexture);let l=new Set;o.customProgram&&l.add(o.customProgram);for(let a of o.programCache?.values()??[])a.program&&l.add(a.program);for(let a of l)n.deleteProgram(a)}if(t)for(let s of t)i(s)}function an(n,e,t=dn,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Kn(n,e,t,r,i)}catch(s){let o=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;bn(n,o,i.gpuTextures),i.vao&&n.deleteVertexArray(i.vao);for(let l of i.buffers)n.deleteBuffer(l);throw s}}function Kn(n,e,t,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,o=_e("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(s,e);let l=e.bin,a=[];i.meshes=a;let u=[],c=s.extensions?.KHR_materials_variants;c&&Array.isArray(c.variants)&&c.variants.forEach((y,A)=>{u.push(typeof y?.name=="string"&&y.name?y.name:`Variant_${A}`)});let h=He(s),m=[];if(Array.isArray(s.nodes))for(let y=0;y<s.nodes.length;y++){let A=s.nodes[y];A.mesh!==void 0&&s.meshes&&s.meshes[A.mesh]&&m.push({node:A,nodeIdx:y,meshIdx:A.mesh})}let b=m.length>0?m:(s.meshes||[]).map((y,A)=>({node:y,nodeIdx:-1,meshIdx:A})),g=[];if(Array.isArray(e.lights)&&e.lights.length>0)g.push(...e.lights);else if(s.extensions?.KHR_lights_punctual?.lights){let y=s.extensions.KHR_lights_punctual.lights;for(let A of y){let T=A.type==="directional"?"directional":A.type==="point"?"point":"ambient";g.push({type:T,color:A.color||[1,1,1],intensity:A.intensity!==void 0?A.intensity:1})}}if(g.length===0&&(g.push({type:"ambient",color:[1,1,1],intensity:.35}),g.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),b.length>t.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${t.maxMeshes}). Found: ${b.length}`);let d=[];if(i.gpuTextures=d,s.textures&&s.images){if(s.textures.length>t.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${t.maxTextures}). Found: ${s.textures.length}`);for(let y=0;y<s.textures.length;y++){let A=s.textures[y],T=s.images[A.source];if(T){let R=n.createTexture();if(n.bindTexture(3553,R),n.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),n.texParameteri(3553,10242,10497),n.texParameteri(3553,10243,10497),n.texParameteri(3553,10241,9729),n.texParameteri(3553,10240,9729),T.bufferView!==void 0){let F=s.bufferViews[T.bufferView],P=l.slice(F.byteOffset||0,(F.byteOffset||0)+F.byteLength),B=new Blob([P],{type:T.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(B).then(k=>{n.bindTexture(3553,R),n.texImage2D(3553,0,6408,6408,5121,k),n.generateMipmap(3553),r?.()}).catch(()=>{})}else if(T.uri){let F=$n(T.uri);if(F){let P=new Image;P.crossOrigin="anonymous",P.referrerPolicy="no-referrer",P.onload=()=>{n.bindTexture(3553,R),n.texImage2D(3553,0,6408,6408,5121,P),n.generateMipmap(3553),r?.()},P.src=F}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",T.uri)}d.push(R)}else d.push(null)}}let w=[1/0,1/0,1/0],C=[-1/0,-1/0,-1/0],N=0,f=0;for(let y=0;y<b.length;y++){let A=b[y],T=s.meshes[A.meshIdx],R=A.nodeIdx>=0?h[A.nodeIdx]:J(),F=new Float32Array(9);me(F,R);let P={name:A.node.name||T.name||`Mesh_${A.meshIdx}`,nodeIndex:A.nodeIdx,transform:R,normalMatrix:F,primitives:[],extras:A.node.extras||T.extras};i.mesh=P;let B=A.node?.extensions?.EXT_mesh_gpu_instancing;if(B&&B.attributes&&typeof B.attributes=="object"){let k=B.attributes,O=k.TRANSLATION!==void 0?s.accessors?.[k.TRANSLATION]:null,S=k.ROTATION!==void 0?s.accessors?.[k.ROTATION]:null,G=k.SCALE!==void 0?s.accessors?.[k.SCALE]:null,z=k._COLOR_0!==void 0?s.accessors?.[k._COLOR_0]:null,U=Number(O?.count??S?.count??G?.count??0);if(!Number.isFinite(U)||U<0||U>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${U}`);if(U>0){let H=($,q)=>{if(!$||$.bufferView===void 0||!s.bufferViews?.[$.bufferView])return null;let se=$.componentType??5126,ce=ne=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${ne})`),null);if(se!==5120&&se!==5121&&se!==5122&&se!==5123&&se!==5126)return ce(`componentType ${se}`);if(!(Number($.count)>=U))return ce(`count ${$.count} < ${U}`);let K=null;try{K=dt(s,l,{...$,count:U},q)}catch{return ce("out of bounds")}return!K||!K.every(Number.isFinite)?ce("non-finite value"):K},L=H(O,3),V=H(S,4),X=H(G,3),W=z?.type==="VEC4"?4:3,Y=H(z,W),re=new Float32Array(U*16),ae=J();for(let $=0;$<U;$++){let q=L?[L[$*3],L[$*3+1],L[$*3+2]]:[0,0,0],se=V?[V[$*4],V[$*4+1],V[$*4+2],V[$*4+3]]:[0,0,0,1],ce=X?[X[$*3],X[$*3+1],X[$*3+2]]:[1,1,1];Me(ae,se,q,ce),re.set(ae,$*16)}if(P.instanceMatrices=re,Y){let $=new Float32Array(U*3);for(let q=0;q<U;q++)$[q*3]=Y[q*W],$[q*3+1]=Y[q*W+1],$[q*3+2]=Y[q*W+2];P.instanceColors=$}}}for(let k of T.primitives||[]){if(k.extensions?.KHR_draco_mesh_compression){let K=_e("draco");K&&K.decodePrimitive(s,k,l)}let O=[],S=n.createVertexArray();i.vao=S,i.buffers=O,n.bindVertexArray(S);let G=Yn(n,P,O),z=s.accessors[k.attributes.POSITION],U=Number(z?.count??0);if(!Number.isFinite(U)||U<0||N+U>t.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${t.maxVertices}).`);if(N+=U,z?.min&&z?.max){let K=ne=>{for(let Z=0;Z<3;Z++){let oe=ne[12+Z],be=ne[12+Z];for(let Ee=0;Ee<3;Ee++){let Be=ne[Ee*4+Z]*z.min[Ee],Ve=ne[Ee*4+Z]*z.max[Ee];oe+=Be<Ve?Be:Ve,be+=Be>Ve?Be:Ve}oe<w[Z]&&(w[Z]=oe),be>C[Z]&&(C[Z]=be)}};if(P.instanceMatrices&&P.instanceMatrices.length>=16){let ne=P.instanceMatrices.length>>4,Z=J();for(let oe=0;oe<ne;oe++){let be=P.instanceMatrices.subarray(oe*16,oe*16+16);ee(Z,R,be),K(Z)}}else K(R)}let H=pt(n,s,l,k.attributes.POSITION,0,3,O);pt(n,s,l,k.attributes.NORMAL,1,3,O),pt(n,s,l,k.attributes.TEXCOORD_0,2,2,O,jn(s,k));let L=0,V=5123,X=null;if(k.indices!==void 0){let K=s.accessors[k.indices],Z=(s.bufferViews[K.bufferView].byteOffset||0)+(K.byteOffset||0);if(L=Number(K.count??0),!Number.isFinite(L)||L<0||f+L>t.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${t.maxIndices}).`);f+=L,V=K.componentType===5125?5125||5125:5123||5123;let oe=n.createBuffer();O.push(oe),n.bindBuffer(34963,oe),K.componentType===5125?(X=new Uint32Array(l,Z,K.count),n.bufferData(34963,X,35044)):K.componentType===5121?(X=Uint16Array.from(new Uint8Array(l,Z,K.count)),n.bufferData(34963,X,35044)):(X=Z%2===0?new Uint16Array(l,Z,K.count):new Uint16Array(l.slice(Z,Z+K.count*2)),n.bufferData(34963,X,35044))}else L=z.count;let W={};for(let K of ie)if(K.onBuildPrimitiveVAO){let ne=K.onBuildPrimitiveVAO(n,S,k,s,l);ne&&(W[K.name]=ne)}n.bindVertexArray(null);let Y=s.materials&&k.material!==void 0?s.materials[k.material]:null,{program:re,uniforms:ae}=fn(n,k,Y),$=pn(Y,d),q=!!(Y?.extensions?.KHR_materials_transmission||W.materials?.isTransmissive),se=k.extensions?.KHR_materials_variants?.mappings,ce=Array.isArray(se)?se.filter(K=>K&&typeof K.material=="number"&&Array.isArray(K.variants)).map(K=>({material:K.material|0,variants:K.variants.map(ne=>Number(ne)|0)})):void 0;P.primitives.push({vao:S,instanced:G,indexCount:L,indexType:V,...$,positions:H,indices:X,buffers:O,materialIndex:k.material,defaultMaterialIndex:k.material,variantMappings:ce,primitiveDef:k,programCache:new Map([[k.material??-1,{program:re,uniforms:ae}]]),pluginData:W,customProgram:re,customUniforms:ae,isTransmissive:q})}a.push(P)}isFinite(w[0])||(w=[-1,-1,-1]),isFinite(C[0])||(C=[1,1,1]);let E=[(w[0]+C[0])/2,(w[1]+C[1])/2,(w[2]+C[2])/2],x=C[0]-w[0],_=C[1]-w[1],D=C[2]-w[2],v=Math.max(Math.hypot(x,_,D)/2,.5),M=[w[0],w[1],w[2]],I=[C[0],C[1],C[2]],p=e.animations;if(!p){for(let y of ie)if(y.onParseGLB?.(e),e.animations){p=e.animations;break}}return p||(p=[]),{meshes:a,bounds:{center:E,radius:v,min:M,max:I},lights:g,animations:p,worldMatrices:h,gpuTextures:d,availableVariants:u}}function Pe(n){let e=n.customTarget||n.bounds.center,t=n.currDistance*Math.cos(n.currPhi);return[e[0]+t*Math.sin(n.currTheta),e[1]+n.currDistance*Math.sin(n.currPhi),e[2]+t*Math.cos(n.currTheta)]}var $e=class{constructor(e,t,r){this.supportsInstanceOffsets=!0;this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=J();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=J();this.viewMatrix=J();this.activeViewMatrix=null;this.modelMatrix=J();this.mvpMatrix=J();this.normalMatrix=new Float32Array(9);this.initialTheta=.6;this.initialPhi=.35;this.initialDistance=null;this.customDistance=!1;this.distanceMode="auto";this.initialCustomTarget=null;this.customTarget=null;this.fov=Math.PI/4;this.minTheta=-1/0;this.maxTheta=1/0;this.minPhi=-Math.PI*.48;this.maxPhi=Math.PI*.48;this.minDistanceLimit=null;this.maxDistanceLimit=null;this.activePointers=new Map;this.isPanning=!1;this.targetTheta=.6;this.currTheta=.6;this.targetPhi=.35;this.currPhi=.35;this.targetDistance=3;this.currDistance=3;this.autoRotate=!1;this.autoRotateSpeed=Math.PI/6;this.autoRotateDelay=3e3;this.lastInteractionTime=-1/0;this.turntableRotation=0;this.isPointerDown=!1;this.interactive=!0;this.skyboxTexture=null;this.lastPointerX=0;this.lastPointerY=0;this.totalDragDist=0;this.selectedMeshName="";this.pickFbo=null;this.pickTexture=null;this.pickDepth=null;this.pickFboWidth=0;this.pickFboHeight=0;this.animFrameId=null;this.isVisible=!0;this.xrSessionActive=!1;this.lastTime=0;this.lastReportedTheta=-999;this.lastReportedPhi=-999;this.lastReportedZoom=-999;this.boundPointerDown=null;this.boundPointerMove=null;this.boundPointerUp=null;this.boundWheel=null;this.boundKeyDown=null;this.boundContextMenu=null;this.boundSetCamera=null;this.boundResetCamera=null;this.contextLost=!1;this.lastGlbData=null;this.boundContextLost=null;this.boundContextRestored=null;this.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:J(),rawValueToMeters:.001,format:0};this.container=e;let i,s;if(t&&typeof t.getContext=="function"?(i=t,s=r):(s=t,i=s?.canvas),!i){let 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=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let o=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!o:o&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=bt(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=yt(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,t){zn(e,t)}static getDecoder(e){return _e(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=hn();this.renderProg=Xe(e,mn,t.fs),this.pickProg=Xe(e,Xn,Wn),this.uRender=gt(e,this.renderProg,t.uniforms),this.uPick=gt(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of ie)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=s,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,s,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,s)}loadGLBData(e,t){this.lastGlbData=e,this.lastLimits=t;let{meshes:r,bounds:i,lights:s,animations:o,worldMatrices:l,gpuTextures:a,availableVariants:u}=an(this.gl,e,t,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=o||[],this.worldMatrices=l||[],this.gpuTextures=a||[],this.availableVariants=u||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let m of e.gltf.nodes)this.initialNodeTransforms.push({t:m.translation?[m.translation[0],m.translation[1],m.translation[2]]:[0,0,0],r:m.rotation?[m.rotation[0],m.rotation[1],m.rotation[2],m.rotation[3]]:[0,0,0,1],s:m.scale?[m.scale[0],m.scale[1],m.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let m of ie)m.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 c=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;c!==void 0&&(this.exposure=bt(c));let h=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;h!==void 0&&(this.envIntensity=Math.max(0,Number(h)||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(ln(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(Fe(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Fe(e),{meshes:i}=an(this.gl,r,dn,()=>this.render());if(t)for(let s of i)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],me(s.normalMatrix,s.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),me(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],s=[],o=[],l=[];for(let a of this.lights){let u=a.color||[1,1,1],c=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")r=[u[0]*c,u[1]*c,u[2]*c];else if(a.type==="directional"&&i.length<6){let h=a.direction||[.5,1,.8];i.push(h[0],h[1],h[2]),s.push(u[0]*c,u[1]*c,u[2]*c)}else if(a.type==="point"&&o.length<6){let h=a.position||[0,0,0];o.push(h[0],h[1],h[2]),l.push(u[0]*c,u[1]*c,u[2]*c)}}i.length===0&&(i.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,o.length/3),o.length>0&&(t.uniform3fv(e.uPointLightPos,o),t.uniform3fv(e.uPointLightColor,l)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=bt(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=yt(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of ie)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of ie)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let i=this.meshes.flatMap(c=>c.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),s=i[0],o=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,a=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,u={baseColorFactor:o,metallicFactor:l,roughnessFactor:a,setBaseColorFactor:c=>{let h=[c[0],c[1],c[2],c[3]??1];u.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let m of i)m.baseColor=h;this.render()},setMetallicFactor:c=>{u.metallicFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=c);for(let h of i)h.metallic=c;this.render()},setRoughnessFactor:c=>{u.roughnessFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=c);for(let h of i)h.roughness=c;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:u}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",r=-1;if(t)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 t;for(let s of this.meshes)for(let o of s.primitives){let l=o.defaultMaterialIndex;if(!t&&Array.isArray(o.variantMappings)){for(let u of o.variantMappings)if(Array.isArray(u.variants)&&u.variants.includes(r)){l=u.material;break}}let a=l!==void 0?i[l]:void 0;o.materialIndex=a?l:void 0,Object.assign(o,pn(a,this.gpuTextures)),this.applyPrimitiveProgram(o,o.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,t,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,s=e.programCache.get(i);s||(s=fn(this.gl,{...e.primitiveDef,material:t},r),e.programCache.set(i,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of ie)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let s=this.clampDistance(r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(i!==void 0&&i>0){let s=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=J();ee(r,this.projMatrix,this.viewMatrix);let[i,s,o]=e,l=t?t[0]:0,a=t?t[1]:0,u=t?t[2]:0,c=this.modelRootMatrix;c&&(i=c[0]*e[0]+c[4]*e[1]+c[8]*e[2]+c[12],s=c[1]*e[0]+c[5]*e[1]+c[9]*e[2]+c[13],o=c[2]*e[0]+c[6]*e[1]+c[10]*e[2]+c[14],t&&(l=c[0]*t[0]+c[4]*t[1]+c[8]*t[2],a=c[1]*t[0]+c[5]*t[1]+c[9]*t[2],u=c[2]*t[0]+c[6]*t[1]+c[10]*t[2]));let h=r[0]*i+r[4]*s+r[8]*o+r[12],m=r[1]*i+r[5]*s+r[9]*o+r[13],b=r[2]*i+r[6]*s+r[10]*o+r[14],g=r[3]*i+r[7]*s+r[11]*o+r[15];if(g<=1e-4)return{x:0,y:0,z:1,visible:!1};let d=h/g,w=m/g,C=b/g,N=this.canvas.getBoundingClientRect(),f=N.width||this.canvas.clientWidth||this.canvas.width||300,E=N.height||this.canvas.clientHeight||this.canvas.height||150,x=(d*.5+.5)*f,_=(-w*.5+.5)*E,D=d>=-1.1&&d<=1.1&&w>=-1.1&&w<=1.1&&C>=-1&&C<=1;if(D&&t){let[v,M,I]=Pe(this),p=[i-v,s-M,o-I];l*p[0]+a*p[1]+u*p[2]>.05&&(D=!1)}return{x,y:_,z:C,visible:D}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=t=>{t.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=t=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist=0,this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.isPanning=t.button===2||t.shiftKey||this.activePointers.size===2,e.setPointerCapture(t.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=t=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(t.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=t.clientX-r.x,s=t.clientY-r.y;if(this.activePointers.set(t.pointerId,{x:t.clientX,y:t.clientY}),this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.totalDragDist+=Math.hypot(i,s),this.isPanning||t.button===2||t.shiftKey||this.activePointers.size===2){let o=[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],u=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*o[0]+s*l[0])*u,a[1]+=(-i*o[1]+s*l[1])*u,a[2]+=(-i*o[2]+s*l[2])*u,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=t=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(t.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(t.pointerId)}catch{}if(this.totalDragDist<5&&t.button===0){let r=e.getBoundingClientRect(),i=Math.floor((t.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((t.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=t=>{if(!this.interactive)return;t.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(t.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=t=>{let r=t.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=t=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(t.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),t.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),t.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),t.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),t.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),t.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),t.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),t.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.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,t){let r=this.canvas,i=r.getBoundingClientRect(),s=r.width||300,o=r.height||300,l=i.width>0?Math.floor((e-i.left)*(s/i.width)):Math.floor(e),a=i.height>0?Math.floor((t-i.top)*(o/i.height)):Math.floor(t);return this.performMeshPick(l,a,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,s=Math.max(1,this.canvas.width||300),o=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let l=J();ee(l,this.projMatrix,this.viewMatrix);let a=[],u=Math.max(0,Math.min(s-1,e)),c=Math.max(0,Math.min(o-1,o-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==o)&&this.resizePickingFbo(s,o),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,s,o),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let D=0;D<this.meshes.length;D++){let v=this.meshes[D];if(v.visible===!1||v.isPluginMesh)continue;let M=D+1,I=(M&255)/255,p=(M>>8&255)/255,y=(M>>16&255)/255;i.uniform4f(this.uPick.uColorId,I,p,y,1),ee(this.modelMatrix,this.modelRootMatrix,v.transform);let A=v.instanceMatrices;if(A&&A.length>=16){let T=A.length>>4,R=J();for(let F of v.primitives){i.bindVertexArray(F.vao);for(let P=0;P<T;P++)ee(R,this.modelMatrix,A.subarray(P*16,P*16+16)),ee(this.mvpMatrix,l,R),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),We(i,F)}}else{ee(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let T of v.primitives)i.bindVertexArray(T.vao),We(i,T)}}let x=new Uint8Array(4);i.readPixels(u,c,1,1,6408,5121,x),i.bindFramebuffer(36160,null);let _=x[0]+(x[1]<<8)+(x[2]<<16);_>0&&_<=this.meshes.length&&(a=[this.meshes[_-1]])}a.length===0&&(a=this.meshes.filter(x=>x.visible!==!1));let h=null,m=1/0,b=[0,0,0],g=[0,1,0],[d,w,C]=Pe(this),N=J();for(let x of a){ee(N,this.modelRootMatrix,x.transform);let _=x.instanceMatrices,D=_&&_.length>=16?_.length>>4:1;for(let v=0;v<D;v++){_&&_.length>=16?ee(this.modelMatrix,N,_.subarray(v*16,v*16+16)):this.modelMatrix.set(N),ee(this.mvpMatrix,l,this.modelMatrix);let M=J();if(!nn(M,this.mvpMatrix))continue;let I=(u+.5)/s*2-1,p=(c+.5)/o*2-1,y=[0,0,0],A=[0,0,0];ft(y,I,p,-1,M),ft(A,I,p,1,M);let T=A[0]-y[0],R=A[1]-y[1],F=A[2]-y[2],P=Math.hypot(T,R,F)||1,B=T/P,k=R/P,O=F/P,S={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((z=>{for(let U of x.primitives){if(!U.positions)continue;let H=U.positions,L=U.indices,V=Math.floor(L?L.length/3:H.length/9);for(let X=0;X<V;X++){let W=L?L[X*3]:X*3,Y=L?L[X*3+1]:X*3+1,re=L?L[X*3+2]:X*3+2;rn(y[0],y[1],y[2],B,k,O,H[W*3],H[W*3+1],H[W*3+2],H[Y*3],H[Y*3+1],H[Y*3+2],H[re*3],H[re*3+1],H[re*3+2],S,z)}}})(1e-4),isFinite(S.distance)){let z=S.point[0],U=S.point[1],H=S.point[2],L=this.modelMatrix,V=L[0]*z+L[4]*U+L[8]*H+L[12],X=L[1]*z+L[5]*U+L[9]*H+L[13],W=L[2]*z+L[6]*U+L[10]*H+L[14],Y=V-d,re=X-w,ae=W-C,$=Math.hypot(Y,re,ae);if($<m){me(this.normalMatrix,this.modelMatrix);let q=this.normalMatrix,se=S.normal[0],ce=S.normal[1],K=S.normal[2],ne=q[0]*se+q[3]*ce+q[6]*K,Z=q[1]*se+q[4]*ce+q[7]*K,oe=q[2]*se+q[5]*ce+q[8]*K,be=Math.hypot(ne,Z,oe)||1;ne/=be,Z/=be,oe/=be,ne*Y+Z*re+oe*ae>0&&(ne=-ne,Z=-Z,oe=-oe),h=x,m=Math.round($*1e3)/1e3,b=[Math.round(V*1e3)/1e3,Math.round(X*1e3)/1e3,Math.round(W*1e3)/1e3],g=[Math.round(ne*1e3)/1e3,Math.round(Z*1e3)/1e3,Math.round(oe*1e3)/1e3]}}}}if(!h)return null;let E={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:m,hitPoint:b,normal:g,screenX:e,screenY:t};if(r){for(let x of ie)x.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,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,s=i?e-r:e,o=i?Math.max(1,t-r):r,l=(s+.5)/o*2-1;return Math.floor((l*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Ge(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center;Re(this.viewMatrix,Pe(this),r,[0,1,0]),ee(this.mvpMatrix,this.projMatrix,this.viewMatrix),me(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let r of ie)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of ie)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=r-(e*r+t*i),s[13]=0,s[14]=i-(-t*r+e*i),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let o of ie)o.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let o of ie)o.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=s;let o={theta:r,phi:i,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(o),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:o}))}}renderXRView(e,t,r,i,s=!0,o=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,u=e?.transform?.position,c=u?[u.x,u.y,u.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:l,projMatrix:a,eyePos:c,viewport:i,eye:e?.eye||"none",clear:o>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let f=Math.max(2,this.canvas.width||2),E=Math.max(1,this.canvas.height||1),x=Math.max(1,Math.floor(f*.5)),_=Math.max(1,f-x),D=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),v=this.customTarget||this.bounds.center,[M,I,p]=Pe(this),y=Math.cos(this.currTheta),A=-Math.sin(this.currTheta),T=.032,R=J(),F=J(),P=[M-y*T,I,p-A*T],B=[v[0]-y*T*.25,v[1],v[2]-A*T*.25];Ge(R,this.fov,x/E,.1,D),Re(F,P,B,[0,1,0]);let k=J(),O=J(),S=[M+y*T,I,p+A*T],G=[v[0]+y*T*.25,v[1],v[2]+A*T*.25];Ge(k,this.fov,_/E,.1,D),Re(O,S,G,[0,1,0]),this.render({viewMatrix:F,projMatrix:R,eyePos:P,viewport:[0,0,x,E],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:O,projMatrix:k,eyePos:S,viewport:[x,0,_,E],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,f,E);return}let t=this.gl,r=0,i=0,s=this.canvas.width,o=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],s=e.viewport[2],o=e.viewport[3],t.viewport(r,i,s,o)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16384|256));let l=J(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,ee(l,e?.projMatrix??this.projMatrix,a);let u=Q().xrDepthShader,c=Bn(this.toneMapping),[h,m,b]=e?e.eyePos:Pe(this);for(let f of ie)f.onBeforeDrawScene?.(this,t,l,[h,m,b],c);let g=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&g===0)return;let d=e?.eye||"none",w=!1,C=g>0?[...this.backdropMeshes,...this.meshes]:this.meshes,N=f=>{for(let E=0;E<C.length;E++){let x=C[E];if(x.visible===!1)continue;let _=this.selectedMeshName!==""&&x.name===this.selectedMeshName;E<g||x.worldSpace===!0||x.name==="__xr_reticle__"?this.modelMatrix.set(x.transform):ee(this.modelMatrix,this.modelRootMatrix,x.transform),ee(this.mvpMatrix,l,this.modelMatrix),me(x.normalMatrix,this.modelMatrix);let D=x.extras?.xr?.stereo||x.userData?.xr?.stereo,v=0,M=0,I=1,p=1;D==="sbs"?(I=.5,v=d==="right"?.5:0):D==="ou"&&(p=.5,M=d==="right"?.5:0);for(let y of x.primitives){let A=!!y.isTransmissive;if(!f&&A){w=!0;continue}if(f&&!A)continue;let T=y.customProgram||this.renderProg,R=y.customUniforms||this.uRender;t.useProgram(T),t.vertexAttrib3f(3,0,0,0),R.uInstanced&&t.uniform1i(R.uInstanced,0),t.uniform1i(R.uToneMapping,c),t.uniform1f(R.uEnvIntensity,this.envIntensity),R.uExposure&&t.uniform1f(R.uExposure,this.exposure),t.uniform3f(R.uCameraPos,h,m,b),t.uniform1f(R.uEmissive,_?1:0),t.uniformMatrix4fv(R.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(R.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(R.uNormalMatrix,!1,x.normalMatrix),R.uUvTransform&&t.uniform4f(R.uUvTransform,v,M,I,p),R.uViewportSize&&t.uniform2f(R.uViewportSize,Math.max(1,s),Math.max(1,o)),u?.bind(t,R,this.xrDepthState,a,[r,i,Math.max(1,s),Math.max(1,o)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(R.uEnvironmentMap,4),t.uniform1i(R.uHasEnvironmentMap,1)):t.uniform1i(R.uHasEnvironmentMap,0),this.bindLights(R),R.uSectionEnabled&&t.uniform1i(R.uSectionEnabled,0);for(let P of ie)P.onBeforeDrawPrimitive?.(t,T,y,x,this.worldMatrices||[],this.gltf);t.uniform4fv(R.uBaseColor,y.baseColor),t.uniform1f(R.uMetallic,y.metallic),t.uniform1f(R.uRoughness,y.roughness),R.uClearcoat&&t.uniform2f(R.uClearcoat,y.clearcoat??0,y.clearcoatRoughness??.04),y.texture?(t.activeTexture(33984),t.bindTexture(3553,y.texture),t.uniform1i(R.uBaseColorTexture,0),t.uniform1i(R.uHasTexture,1)):t.uniform1i(R.uHasTexture,0),y.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,y.metallicRoughnessTexture),t.uniform1i(R.uMetallicRoughnessTexture,1),t.uniform1i(R.uHasMetallicRoughnessTexture,1)):t.uniform1i(R.uHasMetallicRoughnessTexture,0),y.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,y.normalTexture),t.uniform1i(R.uNormalTexture,2),t.uniform1i(R.uHasNormalTexture,1),t.uniform1f(R.uNormalScale,y.normalScale)):t.uniform1i(R.uHasNormalTexture,0),y.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,y.occlusionTexture),t.uniform1i(R.uOcclusionTexture,3),t.uniform1i(R.uHasOcclusionTexture,1),t.uniform1f(R.uOcclusionStrength,y.occlusionStrength)):t.uniform1i(R.uHasOcclusionTexture,0),t.bindVertexArray(y.vao);let F=x.instanceMatrices;if(y.instanceCount!==void 0)t.drawElementsInstanced(4,y.indexCount,y.indexType,0,y.instanceCount);else if(F&&F.length>=16&&y.instanced&&R.uInstanced&&R.uViewProj){let P=F.length>>4;t.uniform1i(R.uInstanced,1),t.uniformMatrix4fv(R.uViewProj,!1,l),y.indices?t.drawElementsInstanced(4,y.indexCount,y.indexType,0,P):t.drawArraysInstanced(4,0,y.indexCount,P),t.uniform1i(R.uInstanced,0)}else if(F&&F.length>=16){let P=F.length>>4,B=x.instanceColors,k=J(),O=new Float32Array(9),S=[y.baseColor[0],y.baseColor[1],y.baseColor[2],y.baseColor[3]];for(let G=0;G<P;G++)ee(k,this.modelMatrix,F.subarray(G*16,G*16+16)),ee(this.mvpMatrix,l,k),me(O,k),t.uniformMatrix4fv(R.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(R.uModel,!1,k),t.uniformMatrix3fv(R.uNormalMatrix,!1,O),B&&(S[0]=y.baseColor[0]*B[G*3],S[1]=y.baseColor[1]*B[G*3+1],S[2]=y.baseColor[2]*B[G*3+2],S[3]=y.baseColor[3],t.uniform4fv(R.uBaseColor,S)),We(t,y)}else We(t,y)}}};if(N(!1),w){for(let f of ie)f.onBeforeTransmissivePass?.(t,this);N(!0)}for(let f of ie)f.onAfterRender?.(t,this,l,e?.eye??"none",[r,i,s,o],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){bn(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of ie)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};$e.registerPlugin=en,$e.getRegisteredPlugins=tn;function qn(n){return n+3&-4}function Zn(n,e=0){let t=(S,G)=>typeof S=="number"&&Number.isFinite(S)?S:G,r=t(n[e+12],0),i=t(n[e+13],0),s=t(n[e+14],0),o=t(n[e+0],1),l=t(n[e+1],0),a=t(n[e+2],0),u=t(n[e+4],0),c=t(n[e+5],1),h=t(n[e+6],0),m=t(n[e+8],0),b=t(n[e+9],0),g=t(n[e+10],1),d=Math.hypot(o,l,a),w=Math.hypot(u,c,h),C=Math.hypot(m,b,g);o*(c*g-b*h)-u*(l*g-b*a)+m*(l*h-c*a)<0&&(d=-d);let f=Math.abs(d)>1e-8?1/d:0,E=Math.abs(w)>1e-8?1/w:0,x=Math.abs(C)>1e-8?1/C:0,_=o*f,D=l*f,v=a*f,M=u*E,I=c*E,p=h*E,y=m*x,A=b*x,T=g*x,R=_+I+T,F=0,P=0,B=0,k=1;if(R>0){let S=.5/Math.sqrt(R+1);k=.25/S,F=(p-A)*S,P=(y-v)*S,B=(D-M)*S}else if(_>I&&_>T){let S=2*Math.sqrt(Math.max(0,1+_-I-T));S>1e-8&&(k=(p-A)/S,F=.25*S,P=(M+D)/S,B=(y+v)/S)}else if(I>T){let S=2*Math.sqrt(Math.max(0,1+I-_-T));S>1e-8&&(k=(y-v)/S,F=(M+D)/S,P=.25*S,B=(p+A)/S)}else{let S=2*Math.sqrt(Math.max(0,1+T-_-I));S>1e-8&&(k=(D-M)/S,F=(y+v)/S,P=(p+A)/S,B=.25*S)}let O=Math.hypot(F,P,B,k);return O>1e-8&&Number.isFinite(O)?(F/=O,P/=O,B/=O,k/=O):(F=0,P=0,B=0,k=1),{t:[r,i,s],r:[F,P,B,k],s:[d,w,C]}}function Jn(n){let e={};return n.grab&&(e.interactable={mode:typeof n.grab=="string"?n.grab:"2-hand"},e.movable={scaleInZ:!!n.scale,minScale:typeof n.scale=="object"?n.scale.min??.1:.1,maxScale:typeof n.scale=="object"?n.scale.max??10:10}),n.billboard&&(e.billboard={mode:typeof n.billboard=="string"?n.billboard:"capsule"}),n.follow&&(e.follow={target:typeof n.follow=="object"?n.follow.mode??"head":n.follow}),n.anchor&&(e.anchor={plane:n.anchor}),n.physics&&n.physics!=="none"&&(e.rigidbody={type:n.physics}),e}function ke(n,e){n.updateMatrixWorld(!0);let t=[],r=0,i=[],s=[],o=[],l=[],a=new Set,u=[],c=[],h=new Map,m=[],b=[];function g(M){let I=h.get(M);if(I!==void 0)return I;I=c.length,h.set(M,I);let p=M,y=p.color?.r??.8,A=p.color?.g??.8,T=p.color?.b??.8,R=p.opacity??1,F={name:p.name||"",pbrMetallicRoughness:{baseColorFactor:[y,A,T,R],metallicFactor:p.metalness??.1,roughnessFactor:p.roughness??.5},doubleSided:p.side===2||!!p.doubleSided};if(p.emissive&&(p.emissive.r>0||p.emissive.g>0||p.emissive.b>0)){let B=p.emissiveIntensity??1;F.emissiveFactor=[p.emissive.r*B,p.emissive.g*B,p.emissive.b*B]}let P={};return p.clearcoat&&p.clearcoat>0&&(P.KHR_materials_clearcoat={clearcoatFactor:p.clearcoat,clearcoatRoughnessFactor:p.clearcoatRoughness||0}),p.sheen&&p.sheen>0&&(P.KHR_materials_sheen={sheenColorFactor:p.sheenColor?[p.sheenColor.r,p.sheenColor.g,p.sheenColor.b]:[1,1,1],sheenRoughnessFactor:p.sheenRoughness||0}),p.transmission&&p.transmission>0&&(P.KHR_materials_transmission={transmissionFactor:p.transmission}),p.thickness&&p.thickness>0&&(P.KHR_materials_volume={thicknessFactor:p.thickness,attenuationDistance:p.attenuationDistance??1/0,attenuationColor:p.attenuationColor?[p.attenuationColor.r,p.attenuationColor.g,p.attenuationColor.b]:[1,1,1]}),p.ior!==void 0&&p.ior!==1.5&&(P.KHR_materials_ior={ior:p.ior}),p.dispersion&&p.dispersion>0&&(P.KHR_materials_dispersion={dispersion:p.dispersion}),p.iridescence&&p.iridescence>0&&(P.KHR_materials_iridescence={iridescenceFactor:p.iridescence,iridescenceIor:p.iridescenceIOR??1.3}),Object.keys(P).length>0&&(F.extensions=P),c.push(F),I}function d(M,I){let p=new Uint8Array(M.buffer,M.byteOffset,M.byteLength),y=qn(p.byteLength),A=new Uint8Array(y);A.set(p),t.push(A);let T=i.length;return i.push({buffer:0,byteOffset:r,byteLength:p.byteLength,target:I}),r+=y,T}function w(M,I,p,y,A,T,R){let F=d(M,p),P=s.length,B={bufferView:F,byteOffset:0,componentType:y,count:A,type:I};return T&&(B.min=T),R&&(B.max=R),s.push(B),P}n.traverse(M=>{(M.isLight||M.color&&M.intensity!==void 0)&&b.push({type:M.type,color:[M.color.r,M.color.g,M.color.b],intensity:M.intensity,position:[M.position.x,M.position.y,M.position.z]})});let C=[];function N(M){let I={name:M.name||""},p=M.position,y=M.quaternion,A=M.scale;if((p.x||p.y||p.z)&&(I.translation=[p.x,p.y,p.z]),(y.x||y.y||y.z||y.w!==1)&&(I.rotation=[y.x,y.y,y.z,y.w]),(A.x!==1||A.y!==1||A.z!==1)&&(I.scale=[A.x,A.y,A.z]),M.userData&&Object.keys(M.userData).length>0&&(I.extras=JSON.parse(JSON.stringify(M.userData,(R,F)=>{if(!(R==="__proto__"||R==="prototype"||R==="constructor"))return typeof F=="function"?void 0:F})),M.userData.xr)){let R=Jn(M.userData.xr);I.extensions={...I.extensions||{},MOZ_hubs_components:R,ANDROID_xr_scenecore:R},Q().xrTraitSerializer?.gltfNode(I,M.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(M.geometry){let R=M.geometry,F=R.attributes.position;if(F&&F.count>0){let P=[1/0,1/0,1/0],B=[-1/0,-1/0,-1/0];for(let U=0;U<F.count;U++){let H=F.getX(U),L=F.getY(U),V=F.getZ(U);H<P[0]&&(P[0]=H),H>B[0]&&(B[0]=H),L<P[1]&&(P[1]=L),L>B[1]&&(B[1]=L),V<P[2]&&(P[2]=V),V>B[2]&&(B[2]=V)}let O={attributes:{POSITION:w(F.array,"VEC3",34962,5126,F.count,P,B)}};if(R.attributes.normal&&(O.attributes.NORMAL=w(R.attributes.normal.array,"VEC3",34962,5126,R.attributes.normal.count)),R.attributes.uv&&(O.attributes.TEXCOORD_0=w(R.attributes.uv.array,"VEC2",34962,5126,R.attributes.uv.count)),R.index){let U=R.index.array instanceof Uint32Array;O.indices=w(R.index.array,"SCALAR",34963,U?5125:5123,R.index.count)}M.material&&(O.material=g(M.material));let S=M.userData?.variants;if(S&&typeof S=="object"){let U=new Map;for(let H of Object.keys(S)){if(!H||H==="__proto__"||H==="constructor"||H==="prototype")continue;let L=S[H];if(!L||typeof L!="object")continue;let V=m.indexOf(H);if(V===-1&&m.length<256&&(V=m.length,m.push(H)),V===-1)continue;let X=g(L),W=U.get(X);W||(W=[],U.set(X,W)),W.push(V)}if(U.size>0){let H=[];for(let[L,V]of U.entries())H.push({material:L,variants:V});O.extensions={...O.extensions||{},KHR_materials_variants:{mappings:H}},a.add("KHR_materials_variants")}}let G=M;if(G.isInstancedMesh&&typeof G.count=="number"&&G.count>0&&G.instanceMatrix?.array){let U=Math.min(1e4,Math.floor(G.count)),H=G.instanceMatrix.array,L=new Float32Array(U*3),V=new Float32Array(U*4),X=new Float32Array(U*3);for(let Y=0;Y<U;Y++){let{t:re,r:ae,s:$}=Zn(H,Y*16);L[Y*3]=re[0],L[Y*3+1]=re[1],L[Y*3+2]=re[2],V[Y*4]=ae[0],V[Y*4+1]=ae[1],V[Y*4+2]=ae[2],V[Y*4+3]=ae[3],X[Y*3]=$[0],X[Y*3+1]=$[1],X[Y*3+2]=$[2]}let W={TRANSLATION:w(L,"VEC3",0,5126,U),ROTATION:w(V,"VEC4",0,5126,U),SCALE:w(X,"VEC3",0,5126,U)};if(G.instanceColor?.array&&G.instanceColor.array.length>=U*3){let Y=new Float32Array(G.instanceColor.array.subarray(0,U*3));W._COLOR_0=w(Y,"VEC3",0,5126,U)}I.extensions={...I.extensions||{},EXT_mesh_gpu_instancing:{attributes:W}},a.add("EXT_mesh_gpu_instancing")}let z=o.length;o.push({primitives:[O],name:M.name,...I.extras?{extras:I.extras}:{}}),I.mesh=z}}let T=l.length;if(l.push(I),u.push(M),M.children.length>0){I.children=[];for(let R of M.children)I.children.push(N(R))}return T}for(let M of n.children)C.push(N(M));let f=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),E=[];if(typeof f=="function"&&u.length>0){let M=e?.duration??4,I=e?.fps??15,p=Math.max(2,Math.round(M*I)+1),y=new Float32Array(p),A=u.map(S=>({px:S.position.x,py:S.position.y,pz:S.position.z,qx:S.quaternion.x,qy:S.quaternion.y,qz:S.quaternion.z,qw:S.quaternion.w,sx:S.scale.x,sy:S.scale.y,sz:S.scale.z})),T=u.map(()=>new Float32Array(p*3)),R=u.map(()=>new Float32Array(p*4)),F=u.map(()=>new Float32Array(p*3));for(let S=0;S<p;S++){let G=S/(p-1)*M;y[S]=G;try{f(G)}catch{}for(let z=0;z<u.length;z++){let U=u[z];T[z][S*3]=U.position.x,T[z][S*3+1]=U.position.y,T[z][S*3+2]=U.position.z,R[z][S*4]=U.quaternion.x,R[z][S*4+1]=U.quaternion.y,R[z][S*4+2]=U.quaternion.z,R[z][S*4+3]=U.quaternion.w,F[z][S*3]=U.scale.x,F[z][S*3+1]=U.scale.y,F[z][S*3+2]=U.scale.z}}for(let S=0;S<u.length;S++){let G=u[S],z=A[S];G.position.set(z.px,z.py,z.pz),G.quaternion.set(z.qx,z.qy,z.qz,z.qw),G.scale.set(z.sx,z.sy,z.sz)}n.updateMatrixWorld(!0);let P=null,B=()=>(P===null&&(P=w(y,"SCALAR",0,5126,p,[0],[M])),P),k=[],O=[];for(let S=0;S<u.length;S++){let G=A[S],z=!1,U=!1,H=!1;for(let L=0;L<p;L++)(Math.abs(T[S][L*3]-G.px)>1e-4||Math.abs(T[S][L*3+1]-G.py)>1e-4||Math.abs(T[S][L*3+2]-G.pz)>1e-4)&&(z=!0),(Math.abs(R[S][L*4]-G.qx)>1e-4||Math.abs(R[S][L*4+1]-G.qy)>1e-4||Math.abs(R[S][L*4+2]-G.qz)>1e-4||Math.abs(R[S][L*4+3]-G.qw)>1e-4)&&(U=!0),(Math.abs(F[S][L*3]-G.sx)>1e-4||Math.abs(F[S][L*3+1]-G.sy)>1e-4||Math.abs(F[S][L*3+2]-G.sz)>1e-4)&&(H=!0);if(z){let L=w(T[S],"VEC3",0,5126,p),V=k.length;k.push({input:B(),interpolation:"LINEAR",output:L}),O.push({sampler:V,target:{node:S,path:"translation"}})}if(U){let L=w(R[S],"VEC4",0,5126,p),V=k.length;k.push({input:B(),interpolation:"LINEAR",output:L}),O.push({sampler:V,target:{node:S,path:"rotation"}})}if(H){let L=w(F[S],"VEC3",0,5126,p),V=k.length;k.push({input:B(),interpolation:"LINEAR",output:L}),O.push({sampler:V,target:{node:S,path:"scale"}})}}O.length>0&&E.push({name:"ProceduralLoop",samplers:k,channels:O})}let x=Zt(l,o,n.userData),_={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:n.environmentIntensity}},scenes:[{nodes:C}],scene:0,nodes:l,meshes:o,materials:c,accessors:s,bufferViews:i,buffers:[{byteLength:r}],...E.length>0?{animations:E}:{},...x||a.size>0?{extensionsUsed:[...x?["KHR_interactivity"]:[],...a]}:{},...x||m.length>0?{extensions:{...x?{KHR_interactivity:x}:{},...m.length>0?{KHR_materials_variants:{variants:m.map(M=>({name:M}))}}:{}}}:{}},D=new Uint8Array(r),v=0;for(let M of t)D.set(M,v),v+=M.byteLength;return{gltf:_,bin:D.buffer,lights:b,environmentIntensity:n.environmentIntensity}}function je(n){return new TextEncoder().encode(n)}function Ke(n,e){let{gltf:t,bin:r}=ke(n,e),i=JSON.stringify(t),s=je(i),o=(4-s.byteLength%4)%4,l=s.byteLength+o,a=20+l+8+r.byteLength,u=new Uint8Array(a),c=new DataView(u.buffer);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0),c.setUint32(8,a,!0),c.setUint32(12,l,!0),c.setUint32(16,1313821514,!0),u.set(s,20);for(let m=0;m<o;m++)u[20+s.byteLength+m]=32;let h=20+l;return c.setUint32(h,r.byteLength,!0),c.setUint32(h+4,5130562,!0),u.set(new Uint8Array(r),h+8),u}function Qn(n,e){n.updateMatrixWorld(!0);let t=[];return n.traverse(r=>{if(r.geometry){let i=r.geometry,s=i.attributes.position;if(!s||s.count===0)return;let o=s.count,l=new Float32Array(o*3),a=r.matrixWorld.elements;for(let v=0;v<o;v++){let M=s.getX(v),I=s.getY(v),p=s.getZ(v);l[v*3]=a[0]*M+a[4]*I+a[8]*p+a[12],l[v*3+1]=a[1]*M+a[5]*I+a[9]*p+a[13],l[v*3+2]=a[2]*M+a[6]*I+a[10]*p+a[14]}let u;if(i.attributes.normal){let v=i.attributes.normal;u=new Float32Array(o*3);let M=new Float32Array(9);me(M,a);for(let I=0;I<o;I++){let p=v.getX(I),y=v.getY(I),A=v.getZ(I),T=M[0]*p+M[3]*y+M[6]*A,R=M[1]*p+M[4]*y+M[7]*A,F=M[2]*p+M[5]*y+M[8]*A,P=Math.hypot(T,R,F)||1;u[I*3]=T/P,u[I*3+1]=R/P,u[I*3+2]=F/P}}let c;if(i.attributes.uv){let v=i.attributes.uv;c=new Float32Array(o*2);for(let M=0;M<o;M++)c[M*2]=v.getX(M),c[M*2+1]=v.getY(M)}let h;if(i.index)h=i.index.array;else{h=o>65535?new Uint32Array(o):new Uint16Array(o);for(let v=0;v<o;v++)h[v]=v}let m="DefaultMaterial",b=[.8,.8,.8],g=.5,d=.1,w=0,C=0,N=1.5,f=1,E=[0,0,0];if(r.material){let v=r.material;m=v.name||`Material_${t.length}`,v.color&&(b=[v.color.r,v.color.g,v.color.b]),typeof v.roughness=="number"&&(g=v.roughness),typeof v.metalness=="number"&&(d=v.metalness),typeof v.clearcoat=="number"&&(w=v.clearcoat),typeof v.clearcoatRoughness=="number"&&(C=v.clearcoatRoughness),typeof v.ior=="number"&&(N=v.ior);let M=typeof v.opacity=="number"?v.opacity:1,I=typeof v.transmission=="number"?v.transmission:0;if(f=M*(1-I),v.emissive&&(v.emissive.r>0||v.emissive.g>0||v.emissive.b>0)){let p=v.emissiveIntensity??1;E=[v.emissive.r*p,v.emissive.g*p,v.emissive.b*p]}}let x,_=e?.animateCallback||e?.animateFn||(typeof n.userData?.animate=="function"?n.userData.animate:typeof n.__animateFn=="function"?n.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof _=="function"){let v=e?.duration??4,M=e?.fps??4,I=Math.max(2,Math.round(v*M)+1),p=[],y=[],A=[],T=[],R=[r.position.x,r.position.y,r.position.z],F=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],P=[r.scale.x,r.scale.y,r.scale.z],B=!1;for(let k=0;k<I;k++){let O=k/(I-1)*v;p.push(O);try{_(O)}catch{}y.push([r.position.x,r.position.y,r.position.z]),A.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-R[0])>1e-4||Math.abs(r.position.y-R[1])>1e-4||Math.abs(r.position.z-R[2])>1e-4||Math.abs(r.quaternion.x-F[0])>1e-4||Math.abs(r.quaternion.y-F[1])>1e-4||Math.abs(r.quaternion.z-F[2])>1e-4||Math.abs(r.quaternion.w-F[3])>1e-4||Math.abs(r.scale.x-P[0])>1e-4)&&(B=!0)}r.position.set(R[0],R[1],R[2]),r.quaternion.set(F[0],F[1],F[2],F[3]),r.scale.set(P[0],P[1],P[2]),B&&(x={times:p,translations:y,rotations:A,scales:T})}let D=r;if(D.isInstancedMesh&&typeof D.count=="number"&&D.count>0&&D.instanceMatrix?.array){let v=Math.min(1e3,Math.floor(D.count)),M=D.instanceMatrix.array,I=D.instanceColor?.array,p=r.name||`Mesh_${t.length}`,y=new Float32Array(16),A=new Float32Array(9);for(let T=0;T<v;T++){let R=M.subarray(T*16,(T+1)*16);ee(y,a,R);let F=new Float32Array(o*3);for(let O=0;O<o;O++){let S=s.getX(O),G=s.getY(O),z=s.getZ(O);F[O*3]=y[0]*S+y[4]*G+y[8]*z+y[12],F[O*3+1]=y[1]*S+y[5]*G+y[9]*z+y[13],F[O*3+2]=y[2]*S+y[6]*G+y[10]*z+y[14]}let P;if(i.attributes.normal){let O=i.attributes.normal;P=new Float32Array(o*3),me(A,y);for(let S=0;S<o;S++){let G=O.getX(S),z=O.getY(S),U=O.getZ(S),H=A[0]*G+A[3]*z+A[6]*U,L=A[1]*G+A[4]*z+A[7]*U,V=A[2]*G+A[5]*z+A[8]*U,X=Math.hypot(H,L,V)||1;P[S*3]=H/X,P[S*3+1]=L/X,P[S*3+2]=V/X}}let B=b,k=m;I&&I.length>=(T+1)*3&&(B=[b[0]*I[T*3],b[1]*I[T*3+1],b[2]*I[T*3+2]],k=`${m}_inst_${T}`),t.push({name:`${p}_${T}`,positions:F,indices:h,normals:P,uvs:c,materialName:k,color:B,roughness:g,metallic:d,clearcoat:w,clearcoatRoughness:C,ior:N,opacity:f,emissiveColor:E,xrTraits:r.userData?.xr})}return}t.push({name:r.name||`Mesh_${t.length}`,positions:l,indices:h,normals:u,uvs:c,materialName:m,color:b,roughness:g,metallic:d,clearcoat:w,clearcoatRoughness:C,ior:N,opacity:f,emissiveColor:E,xrTraits:r.userData?.xr,timeSamples:x})}}),t}function xn(n){let e=[],t=n.gltf,r=Q().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(t,n);let i=n.bin,s=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),o=t.accessors||[],l=t.bufferViews||[],a=t.materials||[],u=t.meshes||[],c=t.nodes||[];function h(g){let d=o[g];if(!d)throw new Error(`Accessor ${g} not found`);let w=l[d.bufferView||0],C=(w.byteOffset||0)+(d.byteOffset||0),N=w.byteLength||0,f=s.slice(C,C+N);return{acc:d,buffer:f}}let m=new Map;if(c.length>0){let g=He(t);for(let d=0;d<g.length;d++)m.set(d,g[d])}function b(g,d,w,C){let N=u[g];if(!N)return;let f=new Float32Array(9);me(f,d);for(let E=0;E<(N.primitives||[]).length;E++){let x=N.primitives[E],_=x.attributes?.POSITION;if(_===void 0)continue;let{acc:D,buffer:v}=h(_),M=new Float32Array(v,0,D.count*3),I=new Float32Array(M.length);for(let L=0;L<D.count;L++){let V=M[L*3],X=M[L*3+1],W=M[L*3+2];I[L*3]=d[0]*V+d[4]*X+d[8]*W+d[12],I[L*3+1]=d[1]*V+d[5]*X+d[9]*W+d[13],I[L*3+2]=d[2]*V+d[6]*X+d[10]*W+d[14]}let p,y=x.attributes?.NORMAL;if(y!==void 0){let{acc:L,buffer:V}=h(y),X=new Float32Array(V,0,L.count*3);p=new Float32Array(X.length);for(let W=0;W<L.count;W++){let Y=X[W*3],re=X[W*3+1],ae=X[W*3+2],$=f[0]*Y+f[3]*re+f[6]*ae,q=f[1]*Y+f[4]*re+f[7]*ae,se=f[2]*Y+f[5]*re+f[8]*ae,ce=Math.hypot($,q,se)||1;p[W*3]=$/ce,p[W*3+1]=q/ce,p[W*3+2]=se/ce}}let A,T=x.attributes?.TEXCOORD_0;if(T!==void 0){let{acc:L,buffer:V}=h(T);A=new Float32Array(V,0,L.count*2)}let R;if(x.indices!==void 0){let{acc:L,buffer:V}=h(x.indices);L.componentType===5125?R=new Uint32Array(V,0,L.count):R=new Uint16Array(V,0,L.count);let X=D.count;for(let W of R)if(W>=X)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${X}).`)}else{let L=D.count;R=L>65535?new Uint32Array(L):new Uint16Array(L);for(let V=0;V<L;V++)R[V]=V}let F="DefaultMaterial",P=[.8,.8,.8],B=.5,k=.1,O=0,S=0,G=1.5,z=1,U=[0,0,0];if(x.material!==void 0&&a[x.material]){let L=a[x.material];F=L.name||`Material_${x.material}`;let V=L.pbrMetallicRoughness||{},X=1;Array.isArray(V.baseColorFactor)&&(P=[V.baseColorFactor[0],V.baseColorFactor[1],V.baseColorFactor[2]],typeof V.baseColorFactor[3]=="number"&&(X=V.baseColorFactor[3])),typeof V.roughnessFactor=="number"&&(B=V.roughnessFactor),typeof V.metallicFactor=="number"&&(k=V.metallicFactor),Array.isArray(L.emissiveFactor)&&L.emissiveFactor.length>=3&&(U=[L.emissiveFactor[0],L.emissiveFactor[1],L.emissiveFactor[2]]);let W=L.extensions||{};W.KHR_materials_clearcoat&&(O=W.KHR_materials_clearcoat.clearcoatFactor??0,S=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),W.KHR_materials_ior&&typeof W.KHR_materials_ior.ior=="number"&&(G=W.KHR_materials_ior.ior);let Y=W.KHR_materials_transmission?.transmissionFactor??0;z=X*(1-Y)}let H=(N.primitives||[]).length>1?`${w}_p${E}`:w;e.push({name:H,positions:I,indices:R,normals:p,uvs:A,materialName:F,color:P,roughness:B,metallic:k,clearcoat:O,clearcoatRoughness:S,ior:G,opacity:z,emissiveColor:U,xrTraits:C?.xr||N.extras?.xr})}}if(c.length>0)for(let g=0;g<c.length;g++){let d=c[g];if(d.mesh!==void 0&&d.mesh<u.length){let w=m.get(g)||J(),C=d.name||u[d.mesh].name||`Node_${g}`,N=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(N&&typeof N=="object"){let f=N.TRANSLATION,E=N.ROTATION,x=N.SCALE,_=f!==void 0?(()=>{let{acc:I,buffer:p}=h(f);return new Float32Array(p,0,I.count*3)})():null,D=E!==void 0?(()=>{let{acc:I,buffer:p}=h(E);return new Float32Array(p,0,I.count*4)})():null,v=x!==void 0?(()=>{let{acc:I,buffer:p}=h(x);return new Float32Array(p,0,I.count*3)})():null,M=Math.min(1e3,_?_.length/3:D?D.length/4:v?v.length/3:0);if(M>0){let I=new Float32Array(16),p=new Float32Array(16);for(let y=0;y<M;y++){let A=_?[_[y*3],_[y*3+1],_[y*3+2]]:[0,0,0],T=D?[D[y*4],D[y*4+1],D[y*4+2],D[y*4+3]]:[0,0,0,1],R=v?[v[y*3],v[y*3+1],v[y*3+2]]:[1,1,1];Me(I,T,A,R),ee(p,w,I),b(d.mesh,p,`${C}_${y}`,d.extras)}continue}}b(d.mesh,w,C,d.extras)}}else{let g=J();for(let d=0;d<u.length;d++){let w=u[d].name||`Mesh_${d}`;b(d,g,w,u[d].extras)}}return e}function xt(n,e){if(!n||typeof n!="string")return e;let t=n.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(t)&&(t="_"+t),t||e}function yn(n){return String(n??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function j(n){if(!Number.isFinite(n)||Math.abs(n)<1e-7)return"0";let e=Number(n.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function gn(n){let e=n.length/3,t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${j(n[r*3])}, ${j(n[r*3+1])}, ${j(n[r*3+2])})`;return t.join(", ")}function er(n,e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=`(${j(n[r*2])}, ${j(1-n[r*2+1])})`;return t.join(", ")}function tr(n){return Array.from(n).join(", ")}function vt(n){let e=new Map;for(let a of n){let u=xt(a.materialName,"DefaultMaterial");e.has(u)||e.set(u,{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 t=0,r=null;for(let a of n){if(a.timeSamples&&a.timeSamples.times.length>0){let u=a.timeSamples.times[a.timeSamples.times.length-1];u>t&&(t=u)}a.xrTraits?.anchor&&!r&&(r=a.xrTraits.anchor==="vertical"||a.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";t>0&&(i=`startTimeCode = 0
|
|
251
253
|
endTimeCode = ${j(t)}
|
|
252
254
|
timeCodesPerSecond = 1.0
|
|
253
255
|
`);let s="";r&&(s=`uniform token preliminary:anchoring:type = "plane"
|
|
@@ -265,11 +267,11 @@ kind = "component"
|
|
|
265
267
|
{
|
|
266
268
|
${s}def Scope "Materials"
|
|
267
269
|
{
|
|
268
|
-
`;for(let[a,u]of e.entries()){let[c,h,m]=u.color,[b,
|
|
269
|
-
`,
|
|
270
|
-
`),u.ior!==1.5&&(
|
|
271
|
-
`),u.opacity<1&&(
|
|
272
|
-
`),(b>0||
|
|
270
|
+
`;for(let[a,u]of e.entries()){let[c,h,m]=u.color,[b,g,d]=u.emissiveColor,w="";u.clearcoat>0&&(w+=`float inputs:clearcoat = ${j(u.clearcoat)}
|
|
271
|
+
`,w+=`float inputs:clearcoatRoughness = ${j(u.clearcoatRoughness)}
|
|
272
|
+
`),u.ior!==1.5&&(w+=`float inputs:ior = ${j(u.ior)}
|
|
273
|
+
`),u.opacity<1&&(w+=`float inputs:opacity = ${j(u.opacity)}
|
|
274
|
+
`),(b>0||g>0||d>0)&&(w+=`color3f inputs:emissiveColor = (${j(b)}, ${j(g)}, ${j(d)})
|
|
273
275
|
`),o+=`def Material "${a}"
|
|
274
276
|
{
|
|
275
277
|
def Shader "PBRShader"
|
|
@@ -278,48 +280,48 @@ uniform token info:id = "UsdPreviewSurface"
|
|
|
278
280
|
color3f inputs:diffuseColor = (${j(c)}, ${j(h)}, ${j(m)})
|
|
279
281
|
float inputs:metallic = ${j(u.metallic)}
|
|
280
282
|
float inputs:roughness = ${j(u.roughness)}
|
|
281
|
-
${
|
|
283
|
+
${w}token outputs:surface
|
|
282
284
|
}
|
|
283
285
|
token outputs:surface.connect = </Root/Materials/${a}/PBRShader.outputs:surface>
|
|
284
286
|
}
|
|
285
287
|
`}o+=`}
|
|
286
288
|
def Scope "Meshes"
|
|
287
289
|
{
|
|
288
|
-
`;let l=new Set;for(let a=0;a<n.length;a++){let u=n[a],c=u.positions.length/3,h=1/0,m=1/0,b=1/0,
|
|
290
|
+
`;let l=new Set;for(let a=0;a<n.length;a++){let u=n[a],c=u.positions.length/3,h=1/0,m=1/0,b=1/0,g=-1/0,d=-1/0,w=-1/0;for(let D=0;D<c;D++){let v=u.positions[D*3],M=u.positions[D*3+1],I=u.positions[D*3+2];v<h&&(h=v),v>g&&(g=v),M<m&&(m=M),M>d&&(d=M),I<b&&(b=I),I>w&&(w=I)}isFinite(h)||(h=m=b=-1,g=d=w=1);let C=Math.floor(u.indices.length/3),N=xt(u.materialName,"DefaultMaterial"),f=xt(u.name,`Mesh_${a}`);l.has(f)&&(f=`${f}_${a}`),l.add(f);let E=C>0?C===1?"3":"3, ".repeat(C-1)+"3":"",x=u.xrTraits,_="";if(x){let D=[];x.physics&&x.physics!=="none"&&D.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let v=Q().xrTraitSerializer?.usdLines(x,yn)??[];if(!v.length)for(let M of["grab","billboard","follow","anchor","physics"]){let I=M==="follow"&&typeof x.follow=="object"?x.follow.mode??"head":x[M];I!==void 0&&v.push(`string ${M} = "${yn(I)}"`)}v.length>0&&D.push(`customData = {
|
|
289
291
|
dictionary xr = {
|
|
290
292
|
${v.join(`
|
|
291
293
|
`)}
|
|
292
294
|
}
|
|
293
|
-
}`),D.length>0&&(
|
|
295
|
+
}`),D.length>0&&(_=` (
|
|
294
296
|
${D.join(`
|
|
295
297
|
`)}
|
|
296
|
-
)`)}if(o+=`def Mesh "${f}"${
|
|
298
|
+
)`)}if(o+=`def Mesh "${f}"${_}
|
|
297
299
|
{
|
|
298
|
-
`,
|
|
300
|
+
`,x?.physics&&x.physics!=="none"){let D=x.physics==="static"?"true":"false";o+=`bool physics:rigidBodyEnabled = true
|
|
299
301
|
bool physics:kinematicEnabled = ${D}
|
|
300
302
|
bool physics:collisionEnabled = true
|
|
301
|
-
`}if(u.timeSamples&&u.timeSamples.times.length>0){let D=u.timeSamples,v=D.times.map((
|
|
302
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
303
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
303
|
+
`}if(u.timeSamples&&u.timeSamples.times.length>0){let D=u.timeSamples,v=D.times.map((p,y)=>{let A=D.translations?.[y]||[0,0,0];return`${j(p)}: (${j(A[0])}, ${j(A[1])}, ${j(A[2])})`}).join(", "),M=D.times.map((p,y)=>{let A=D.rotations?.[y]||[0,0,0,1];return`${j(p)}: (${j(A[3])}, ${j(A[0])}, ${j(A[1])}, ${j(A[2])})`}).join(", "),I=D.times.map((p,y)=>{let A=D.scales?.[y]||[1,1,1];return`${j(p)}: (${j(A[0])}, ${j(A[1])}, ${j(A[2])})`}).join(", ");o+=`double3 xformOp:translate.timeSamples = { ${v} }
|
|
304
|
+
quatf xformOp:orient.timeSamples = { ${M} }
|
|
305
|
+
double3 xformOp:scale.timeSamples = { ${I} }
|
|
304
306
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
305
|
-
`}o+=`float3[] extent = [(${j(h)}, ${j(m)}, ${j(b)}), (${j(
|
|
306
|
-
int[] faceVertexCounts = [${
|
|
307
|
-
int[] faceVertexIndices = [${
|
|
308
|
-
point3f[] points = [${
|
|
309
|
-
`,u.normals&&u.normals.length===u.positions.length&&(o+=`normal3f[] normals = [${
|
|
307
|
+
`}o+=`float3[] extent = [(${j(h)}, ${j(m)}, ${j(b)}), (${j(g)}, ${j(d)}, ${j(w)})]
|
|
308
|
+
int[] faceVertexCounts = [${E}]
|
|
309
|
+
int[] faceVertexIndices = [${tr(u.indices)}]
|
|
310
|
+
point3f[] points = [${gn(u.positions)}]
|
|
311
|
+
`,u.normals&&u.normals.length===u.positions.length&&(o+=`normal3f[] normals = [${gn(u.normals)}] (
|
|
310
312
|
interpolation = "vertex"
|
|
311
313
|
)
|
|
312
|
-
`),u.uvs&&u.uvs.length===c*2&&(o+=`texCoord2f[] primvars:st = [${
|
|
314
|
+
`),u.uvs&&u.uvs.length===c*2&&(o+=`texCoord2f[] primvars:st = [${er(u.uvs,c)}] (
|
|
313
315
|
interpolation = "vertex"
|
|
314
316
|
)
|
|
315
317
|
`),o+=`rel material:binding = </Root/Materials/${N}>
|
|
316
318
|
}
|
|
317
319
|
`}return o+=`}
|
|
318
320
|
}
|
|
319
|
-
`,o}function rr(n,e){if(n&&typeof n.traverse=="function"){let i=er(n,e);return vt(i)}let t=Pe(n),r=vn(t);return vt(r)}var $e=null;function ir(n){if(!$e){$e=new Uint32Array(256);for(let t=0;t<256;t++){let r=t;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;$e[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=$e[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function wn(n){let e=[],t=0,r=[];for(let c of n){let h=Ye(c.filename),m=ir(c.data),b=c.data.length,p=30+h.length,x=t+p,T=0,I=x%64;I!==0&&(T=64-I);let N=new Uint8Array(p+T),f=new DataView(N.buffer);f.setUint32(0,67324752,!0),f.setUint16(4,20,!0),f.setUint16(6,0,!0),f.setUint16(8,0,!0),f.setUint16(10,0,!0),f.setUint16(12,0,!0),f.setUint32(14,m,!0),f.setUint32(18,b,!0),f.setUint32(22,b,!0),f.setUint16(26,h.length,!0),f.setUint16(28,T,!0),N.set(h,30),T>0&&N.fill(0,30+h.length),e.push({offset:t,size:b,crc:m,filenameBytes:h,entry:c}),r.push(N),r.push(c.data),t+=N.length+c.data.length}let i=t;for(let c of e){let h=new Uint8Array(46+c.filenameBytes.length),m=new DataView(h.buffer);m.setUint32(0,33639248,!0),m.setUint16(4,20,!0),m.setUint16(6,20,!0),m.setUint16(8,0,!0),m.setUint16(10,0,!0),m.setUint16(12,0,!0),m.setUint16(14,0,!0),m.setUint32(16,c.crc,!0),m.setUint32(20,c.size,!0),m.setUint32(24,c.size,!0),m.setUint16(28,c.filenameBytes.length,!0),m.setUint16(30,0,!0),m.setUint16(32,0,!0),m.setUint16(34,0,!0),m.setUint16(36,0,!0),m.setUint32(38,0,!0),m.setUint32(42,c.offset,!0),h.set(c.filenameBytes,46),r.push(h),t+=h.length}let s=t-i,o=new Uint8Array(22),l=new DataView(o.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,s,!0),l.setUint32(16,i,!0),l.setUint16(20,0,!0),r.push(o),t+=22;let a=new Uint8Array(t),u=0;for(let c of r)a.set(c,u),u+=c.length;return a}function Ue(n){let e=rr(n),t=Ye(e);return wn([{filename:"model.usda",data:t}])}function wt(n){let e=Pe(n),t=vn(e),r=vt(t),i=Ye(r);return wn([{filename:"model.usda",data:i}])}function Mn(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Ue(n):wt(n)}var Tt=class n{constructor(e=0,t=0){this.x=Number(e),this.y=Number(t)}set(e,t){return this.x=Number(e),this.y=Number(t),this}clone(){return new n(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},ne=class n{constructor(e=0,t=0,r=0){this.x=Number(e),this.y=Number(t),this.z=Number(r)}set(e,t,r){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this}clone(){return new n(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=i,this}crossVectors(e,t){let r=e.x,i=e.y,s=e.z,o=t.x,l=t.y,a=t.z;return this.x=i*a-s*l,this.y=s*o-r*a,this.z=r*l-i*o,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let t=this.x,r=this.y,i=this.z,s=e.elements,o=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*o,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*o,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*o,this}},Rt=class{constructor(e=0,t=0,r=0,i=1){this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i)}set(e,t,r,i){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i),this}},Je=class n{constructor(e=0,t=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,t,r,i=this.order){return this._x=Number(e),this._y=Number(t),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new n(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Qe=class n{constructor(e=0,t=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,t,r,i){return this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new n(this._x,this._y,this._z,this._w)}setFromEuler(e,t=!0){let r=e.x,i=e.y,s=e.z,o=Math.cos(r/2),l=Math.cos(i/2),a=Math.cos(s/2),u=Math.sin(r/2),c=Math.sin(i/2),h=Math.sin(s/2);return this._x=u*l*a+o*c*h,this._y=o*c*a-u*l*h,this._z=o*l*h+u*c*a,this._w=o*l*a-u*c*h,t&&this._onChangeCallback?.(),this}setFromAxisAngle(e,t){let r=t/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,t){let r=e.x,i=e.y,s=e.z,o=e.w,l=t.x,a=t.y,u=t.z,c=t.w;return this._x=r*c+o*l+i*u-s*a,this._y=i*c+o*a+s*l-r*u,this._z=s*c+o*u+r*a-i*l,this._w=o*c-r*l-i*a-s*u,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},_e=class n{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new n;return e.copy(this),e}compose(e,t,r){return we(this.elements,[t.x,t.y,t.z,t.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,t){return te(this.elements,e.elements,t.elements),this}lookAt(e,t,r){return Ee(this.elements,[e.x,e.y,e.z],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let t=new ne(0,0,0),r=new ne(1,1,1);return this.compose(t,e,r)}makeTranslation(e,t,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(t),this.elements[14]=Number(r),this}makeScale(e,t,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(t),this.elements[10]=Number(r),this}},Et=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 me(this.elements,e.elements),this}},de=class n{constructor(e,t,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(t!==void 0&&r!==void 0?this.setRGB(e,t,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let t=parseInt(e.slice(1),16);this.setHex(t)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let t=Math.floor(e);return this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,this}setRGB(e,t,r){return this.r=Number(e),this.g=Number(t),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new n(this.r,this.g,this.b)}},sr={degToRad:n=>n*Math.PI/180,radToDeg:n=>n*180/Math.PI,clamp:(n,e,t)=>Math.max(e,Math.min(t,n)),lerp:(n,e,t)=>n+(e-n)*t,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(n,e)=>n+Math.random()*(e-n)},q=class{constructor(e,t){this.needsUpdate=!1;if(typeof t!="number"||!Number.isInteger(t)||t<1||t>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(t)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=t;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/t)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,t){return this.array[e*this.itemSize]=t,this.needsUpdate=!0,this}setY(e,t){return this.array[e*this.itemSize+1]=t,this.needsUpdate=!0,this}setZ(e,t){return this.array[e*this.itemSize+2]=t,this.needsUpdate=!0,this}setXYZ(e,t,r,i){let s=e*this.itemSize;return this.array[s]=t,this.array[s+1]=r,this.array[s+2]=i,this.needsUpdate=!0,this}},At=class extends q{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},_t=class extends q{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},St=class extends q{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},he=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,t){return this.attributes[e]=t,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof q)this.index=e;else if(Array.isArray(e)){let t=e.length,r=0;for(let s=0;s<t;s++)e[s]>r&&(r=e[s]);let i=r>65535?new Uint32Array(t):new Uint16Array(t);for(let s=0;s<t;s++)i[s]=e[s];this.index=new q(i,1)}else e&&e.buffer&&(this.index=new q(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let t=e.count,r=new Float32Array(t*3),i=new ne,s=new ne,o=new ne,l=new ne,a=new ne;if(this.index){let u=this.index.array;for(let c=0;c<u.length;c+=3){let h=u[c],m=u[c+1],b=u[c+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(b),e.getY(b),e.getZ(b)),l.subVectors(o,s),a.subVectors(i,s),l.cross(a).normalize();for(let p of[h,m,b])r[p*3]+=l.x,r[p*3+1]+=l.y,r[p*3+2]+=l.z}}else for(let u=0;u<t;u+=3){i.set(e.getX(u),e.getY(u),e.getZ(u)),s.set(e.getX(u+1),e.getY(u+1),e.getZ(u+1)),o.set(e.getX(u+2),e.getY(u+2),e.getZ(u+2)),l.subVectors(o,s),a.subVectors(i,s),l.cross(a).normalize();for(let c=0;c<3;c++)r[(u+c)*3]=l.x,r[(u+c)*3+1]=l.y,r[(u+c)*3+2]=l.z}for(let u=0;u<t;u++){let c=r[u*3],h=r[u*3+1],m=r[u*3+2],b=Math.hypot(c,h,m)||1;r[u*3]=c/b,r[u*3+1]=h/b,r[u*3+2]=m/b}return this.setAttribute("normal",new q(r,3)),this}setFromBuffers(e,t,r,i){this.setAttribute("position",new q(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new q(t instanceof Float32Array?t:new Float32Array(t),3)),this.setAttribute("uv",new q(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}computeBoundingBox(){let e=this.attributes.position,t=new ne(1/0,1/0,1/0),r=new ne(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let i=0;i<e.count;i++){let s=e.getX(i),o=e.getY(i),l=e.getZ(i);s<t.x&&(t.x=s),o<t.y&&(t.y=o),l<t.z&&(t.z=l),s>r.x&&(r.x=s),o>r.y&&(r.y=o),l>r.z&&(r.z=l)}else t.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:t,max:r},this.boundingBox}center(){let e=this.computeBoundingBox(),t=(e.min.x+e.max.x)*.5,r=(e.min.y+e.max.y)*.5,i=(e.min.z+e.max.z)*.5,s=this.attributes.position;if(s&&s.count>0){for(let o=0;o<s.count;o++)s.setXYZ(o,s.getX(o)-t,s.getY(o)-r,s.getZ(o)-i);this.computeBoundingBox()}return this}dispose(){}},et=class extends he{constructor(e=1,t=1,r=1){super();let i=e/2,s=t/2,o=r/2,l=[-i,-s,o,i,-s,o,i,s,o,-i,s,o,i,-s,-o,-i,-s,-o,-i,s,-o,i,s,-o,-i,s,o,i,s,o,i,s,-o,-i,s,-o,-i,-s,-o,i,-s,-o,i,-s,o,-i,-s,o,i,-s,o,i,-s,-o,i,s,-o,i,s,o,-i,-s,-o,-i,-s,o,-i,s,o,-i,s,-o],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],u=[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],c=[];for(let h=0;h<6;h++){let m=h*4;c.push(m,m+1,m+2,m,m+2,m+3)}this.setAttribute("position",new q(new Float32Array(l),3)),this.setAttribute("normal",new q(new Float32Array(a),3)),this.setAttribute("uv",new q(new Float32Array(u),2)),this.setIndex(c)}},Ct=class extends he{constructor(e=1,t=1){super();let r=e/2,i=t/2,s=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],o=[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 q(new Float32Array(s),3)),this.setAttribute("normal",new q(new Float32Array(o),3)),this.setAttribute("uv",new q(new Float32Array(l),2)),this.setIndex(a)}},tt=class extends he{constructor(e=1,t=16,r=12){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));let i=[],s=[],o=[],l=[],a=[];for(let u=0;u<=r;u++){let c=[],h=u/r;for(let m=0;m<=t;m++){let b=m/t,p=b*Math.PI*2,x=h*Math.PI,T=-e*Math.cos(p)*Math.sin(x),I=e*Math.cos(x),N=e*Math.sin(p)*Math.sin(x);i.push(T,I,N);let f=Math.hypot(T,I,N)||1;s.push(T/f,I/f,N/f),o.push(b,1-h),c.push(i.length/3-1)}a.push(c)}for(let u=0;u<r;u++)for(let c=0;c<t;c++){let h=a[u][c+1],m=a[u][c],b=a[u+1][c],p=a[u+1][c+1];u!==0&&l.push(h,m,p),u!==r-1&&l.push(m,b,p)}this.setAttribute("position",new q(new Float32Array(i),3)),this.setAttribute("normal",new q(new Float32Array(s),3)),this.setAttribute("uv",new q(new Float32Array(o),2)),this.setIndex(l)}},Me=class extends he{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let s=[],o=[],l=[],a=[],u=r/2;for(let c=0;c<=1;c++){let h=c,m=c===0?e:t,b=c===0?u:-u;for(let p=0;p<=i;p++){let x=p/i,T=x*Math.PI*2,I=Math.sin(T),N=Math.cos(T);s.push(m*I,b,m*N),o.push(I,0,N),l.push(x,1-h)}}for(let c=0;c<i;c++){let h=c,m=c+i+1,b=c+i+2,p=c+1;a.push(h,m,p,m,b,p)}if(e>0){let c=s.length/3;s.push(0,u,0),o.push(0,1,0),l.push(.5,.5);let h=s.length/3;for(let m=0;m<=i;m++){let b=m/i*Math.PI*2,p=Math.sin(b),x=Math.cos(b);s.push(e*p,u,e*x),o.push(0,1,0),l.push(x*.5+.5,p*.5+.5)}for(let m=0;m<i;m++)a.push(c,h+m,h+m+1)}if(t>0){let c=s.length/3;s.push(0,-u,0),o.push(0,-1,0),l.push(.5,.5);let h=s.length/3;for(let m=0;m<=i;m++){let b=m/i*Math.PI*2,p=Math.sin(b),x=Math.cos(b);s.push(t*p,-u,t*x),o.push(0,-1,0),l.push(x*.5+.5,1-(p*.5+.5))}for(let m=0;m<i;m++)a.push(c,h+m+1,h+m)}this.setAttribute("position",new q(new Float32Array(s),3)),this.setAttribute("normal",new q(new Float32Array(o),3)),this.setAttribute("uv",new q(new Float32Array(l),2)),this.setIndex(a)}},It=class extends Me{constructor(e=1,t=1,r=16){super(0,e,t,r)}},Dt=class extends he{constructor(e=1,t=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let s=[],o=[],l=[],a=[];for(let u=0;u<=r;u++){let c=u/r*Math.PI*2;for(let h=0;h<=i;h++){let m=h/i*Math.PI*2,b=(e+t*Math.cos(c))*Math.cos(m),p=(e+t*Math.cos(c))*Math.sin(m),x=t*Math.sin(c);s.push(b,p,x);let T=e*Math.cos(m),I=e*Math.sin(m),N=b-T,f=p-I,R=x,g=Math.hypot(N,f,R)||1;o.push(N/g,f/g,R/g),l.push(h/i,u/r)}}for(let u=1;u<=r;u++)for(let c=1;c<=i;c++){let h=(i+1)*u+c-1,m=(i+1)*(u-1)+c-1,b=(i+1)*(u-1)+c,p=(i+1)*u+c;a.push(h,m,p,m,b,p)}this.setAttribute("position",new q(new Float32Array(s),3)),this.setAttribute("normal",new q(new Float32Array(o),3)),this.setAttribute("uv",new q(new Float32Array(l),2)),this.setIndex(a)}},Lt=class extends he{constructor(e=1,t=.4,r=64,i=8,s=2,o=3){super(),r=Math.floor(r),i=Math.floor(i);let l=[],a=[],u=[],c=[],h=new ne,m=new ne,b=new ne,p=new ne,x=new ne;function T(f,R){let g=Math.cos(R),A=Math.sin(R),D=o/s*R,v=e*(2+Math.cos(D))*.5;f.set(v*g,v*A,e*Math.sin(D)*.5)}let I=[];for(let f=0;f<=i;++f){let R=f/i*Math.PI*2;I.push(-t*Math.cos(R),t*Math.sin(R),f/i)}for(let f=0;f<=r;++f){let R=f/r,g=R*s*Math.PI*2;T(h,g),T(m,g+.01),b.subVectors(m,h).normalize(),p.addVectors(h,m).normalize(),x.crossVectors(b,p).normalize(),p.crossVectors(x,b).normalize();for(let A=0;A<=i;++A){let D=A*3,v=I[D],w=I[D+1],C=I[D+2],d=v*p.x+w*x.x,y=v*p.y+w*x.y,S=v*p.z+w*x.z;l.push(h.x+d,h.y+y,h.z+S);let M=Math.hypot(d,y,S)||1;a.push(d/M,y/M,S/M),u.push(R,C)}}let N=i+1;for(let f=1;f<=r;f++){let R=N*(f-1),g=R+N;for(let A=1;A<=i;A++){let D=R+(A-1),v=g+(A-1),w=g+A,C=R+A;c.push(D,v,C,v,w,C)}}this.setAttribute("position",new q(new Float32Array(l),3)),this.setAttribute("normal",new q(new Float32Array(a),3)),this.setAttribute("uv",new q(new Float32Array(u),2)),this.setIndex(c)}},nt=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(){}},Nt=class{load(e,t){let r=new nt(e);return t?.(r),r}};function le(n,e){return n!==void 0?Number(n):e}function Mt(n,e){return n!==void 0?!!n:e}var xe=class{constructor(e={}){this.name=e.name||"",this.color=new de(e.color!==void 0?e.color:16777215),this.emissive=new de(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=le(e.emissiveIntensity,1),this.roughness=le(e.roughness,.5),this.metalness=le(e.metalness,.1),this.opacity=le(e.opacity,1),this.transparent=Mt(e.transparent,!1),this.wireframe=Mt(e.wireframe,!1),this.side=le(e.side,2),this.doubleSided=Mt(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=le(e.clearcoat,0),this.clearcoatRoughness=le(e.clearcoatRoughness,0),this.sheen=le(e.sheen,0),this.sheenColor=new de(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=le(e.sheenRoughness,0),this.transmission=le(e.transmission,0),this.thickness=le(e.thickness,0),this.attenuationColor=new de(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=le(e.attenuationDistance,1/0),this.ior=le(e.ior,1.5),this.dispersion=le(e.dispersion,0),this.iridescence=le(e.iridescence,0),this.iridescenceIOR=le(e.iridescenceIOR,1.3)}dispose(){}},Se=class extends xe{},Ft=class extends xe{},Pt=class extends xe{},kt=class extends xe{},Ut=class extends xe{},pe=class n{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new ne,this.rotation=new Je,this.quaternion=new Qe,this.scale=new ne(1,1,1),this.matrix=new _e,this.matrixWorld=new _e,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,t=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(t,r,i)})}add(...e){for(let t of e)t&&t instanceof n&&(t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t));return this}remove(...e){for(let t of e){let r=this.children.indexOf(t);r!==-1&&(t.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let t of this.children)t.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){Cn(this),(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let t of this.children)t.updateMatrixWorld(e)}lookAt(e,t,r){let i=typeof e=="object"?e:new ne(e,t,r);this.updateMatrixWorld(!0);let s=new _e;s.lookAt(this.position,i,new ne(0,1,0));let o=s.elements,l=o[0],a=o[4],u=o[8],c=o[1],h=o[5],m=o[9],b=o[2],p=o[6],x=o[10],T=l+h+x;if(T>0){let I=.5/Math.sqrt(T+1);this.quaternion.set((p-m)*I,(u-b)*I,(c-a)*I,.25/I)}}},Ot=class extends pe{},Ce=class extends pe{constructor(t,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=t instanceof he?t:t?(fe("unsupported geometry","BoxGeometry"),new et(.5,.5,.5)):new he,this.material=i instanceof xe?i:i?(fe("unsupported material","MeshStandardMaterial"),new Se({color:13421772})):new Se}};function Cn(n){let e=ee().materializeDeclarativeGeometry;typeof e=="function"&&e(n)}var rt=1e4,it=class extends Ce{constructor(t,r,i=1){super(t,r);this.instanceColor=null;this.isInstancedMesh=!0;let s=Number(i);if(!Number.isFinite(s)||s<0||s>rt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${rt})`);this.count=Math.floor(s);let o=new Float32Array(this.count*16);for(let l=0;l<this.count;l++){let a=l*16;o[a]=1,o[a+5]=1,o[a+10]=1,o[a+15]=1}this.instanceMatrix=new q(o,16)}setMatrixAt(t,r){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let s=this.instanceMatrix.array,o=i*16;if(!(o+16>s.length))for(let l=0;l<16;l++){let a=Number(r.elements[l]);s[o+l]=Number.isFinite(a)?a:l%5===0?1:0}}getMatrixAt(t,r){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let s=this.instanceMatrix.array,o=i*16;if(!(o+16>s.length))for(let l=0;l<16;l++)r.elements[l]=s[o+l]}setColorAt(t,r){let i=Math.floor(Number(t));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 q(l,3)}let s=this.instanceColor.array,o=i*3;s[o]=Number.isFinite(r.r)?r.r:1,s[o+1]=Number.isFinite(r.g)?r.g:1,s[o+2]=Number.isFinite(r.b)?r.b:1}getColorAt(t,r){let i=Math.floor(Number(t));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 s=this.instanceColor.array,o=i*3;r.setRGB(s[o],s[o+1],s[o+2])}dispose(){}},Ie=class extends pe{constructor(e=16777215,t=1){super(),this.color=new de(e),this.intensity=Number(t),this.type="directional"}},st=class extends Ie{constructor(e,t){super(e,t),this.type="ambient"}},Bt=class extends Ie{constructor(t,r){super(t,r);this.target=new pe;this.type="directional"}},ot=class extends Ie{constructor(t,r,i=0,s=2){super(t,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=s}},at=class extends pe{},Vt=class extends at{constructor(t=45,r=1,i=.1,s=1e3){super();this.target=new ne(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(s)}},ct=class extends pe{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return ge.validate(this),ke(this)}toGLB(){return ge.validate(this),je(this)}toUSDZ(){return ge.validate(this),Ue(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof Ce){let s=new Float32Array(i.matrixWorld.elements);t.set(r,s),i.name&&t.set(i.name,s),r++}}),t}},In=ke,Dn=je,or=Ue;var ge=class{static validate(e){let t=0,r=0,i=0,s=new Set,o=(a,u,c)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${u}). Found: ${c}`)},l=(a,u)=>{if(!Number.isFinite(u))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(u)}), which cannot be bounds-checked.`);return u};e.traverse(a=>{if(Cn(a),a instanceof Ce||a.geometry?.attributes?.position?.count){if(i++,i>1e3&&o("MESHES",1e3,i),a instanceof it){let c=l("instance",a.count);(c<0||c>rt)&&o("INSTANCES",rt,c)}let u=a.geometry;if(u){let c=0;if(u.attributes.position&&(c=l("vertex",u.attributes.position.count),t+=c,t>1e5&&o("VERTICES",1e5,t)),u.index){let h=l("index",u.index.count);r+=h,r>3e5&&o("INDICES",3e5,r);let m=u.index.array;if(m&&c>0){let b=Math.min(h,m.length);for(let p=0;p<b;p++){let x=m[p];if(!Number.isFinite(x)||x<0||x>=c)throw new Error(`SecurityError: Index buffer value (${String(x)}) out of vertex bounds [0, ${c}).`)}}}}if(a.material){let c=a.material;c.map&&s.add(c.map),c.normalMap&&s.add(c.normalMap),c.roughnessMap&&s.add(c.roughnessMap)}}}),s.size>16&&o("TEXTURES",16,s.size);for(let a of s){let u=a,c=u.image,h=Number(c?.width??u.width??0)||0,m=Number(c?.height??u.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(m)||h>2048||m>2048)&&o("TEXTURE_DIMENSION",2048,Math.max(h,m))}}},zt=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new de(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){ge.validate(e);let i=(s,o)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(o&&o.length?self.postMessage(s,o):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),o={};for(let[l,a]of s.entries())o[l]=Array.from(a);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:o})}else{this.hasInitialModelRendered=!0;let s=In(e),o=Dn(e),l=(s.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:o.buffer,dynamicLights:l,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[o.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 Tn(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Gt=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=Tn(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let t=Tn();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function ar(){}var Ke=new Proxy(ar,{get:(n,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:Ke},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Ke,construct:()=>Ke}),Rn=(()=>{try{if(typeof document>"u")return null;let n=document.currentScript;return n?.src?n.src:n?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([n.textContent],{type:"text/javascript"})):null}catch{return null}})();function Le(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Te(n,e){if(!n||typeof n!="string")return!1;let t=n.trim();if(!t)return!1;try{let r=new URL(t,Le());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 En,Oe;function cr(n){if(!Te(n))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${n}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return n;if(Oe===void 0||En!==t){En=t;try{Oe=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Te(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Oe=null}}return Oe?Oe.createScriptURL(n):n}function Xr(n){ee().sandboxEngineSrc=n}function Ln(){let n=ee().sandboxEngineSrc;if(n)return n;if(Rn)return Rn;try{if(typeof document>"u")return null;let e=Le(),t=Array.from(document.querySelectorAll("script[src]"));for(let r of t){let i=r.src;if(!i)continue;let s=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&Te(i,{requireSameOrigin:!0}))return i}}catch{}return null}function ur(){let n=Ln();if(!n)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!Te(n))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Le()).href}function Wr(n){ee().sandboxIframeSrc=n}function lr(){let n=ee().sandboxIframeSrc;if(n)return n;let e=Ln();if(!e||!Te(e))return null;let t=new URL(e,Le());return t.protocol==="blob:"?null:new URL("three-live-sandbox.html",t).href}function mr(){let n=lr();if(!n)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!Te(n))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Le()).href}function $r(n){ee().allowClientScripts=n}function hr(){return!!ee().allowClientScripts}function fr(n){if(!Te(n))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Le()).href}var dr=["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 pr(n,e){let t=self,r=n.nonce,i=n.engineSrc,s=n.allowedScriptUrl,o=n.allowClientScripts,l=n.revoked,a=t.postMessage.bind(t);function u(A){a({type:"ERROR",nonce:r,message:String(A)})}let c=typeof t.importScripts=="function"?t.importScripts.bind(t):null,h=s,m=null;try{let A=i;if(typeof t.trustedTypes<"u"&&t.trustedTypes&&typeof t.trustedTypes.createPolicy=="function")try{let D={createScriptURL:function(w){if(w!==i&&(!s||w!==s))throw new TypeError("Disallowed worker importScripts URL");return w}};o&&(D.createScript=function(w){return String(w)});let v=t.trustedTypes.createPolicy("three-live#worker-boot",D);A=v.createScriptURL(i),s&&(h=v.createScriptURL(s)),o&&typeof v.createScript=="function"&&(m=v.createScript.bind(v))}catch{}c(A)}catch(A){u('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: '+(A&&A.message||A));return}let b=t.THREE;if(!b||typeof b.Scene!="function"){u('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 A=t.__THREE_LIVE_REGISTRY__;for(let D=0;D<e.length;D++)if(typeof e[D]=="function")try{e[D](b,A)}catch{}}for(let A=0;A<l.length;A++){let D=l[A],v=t;for(;v&&v!==Object.prototype;){if(v!==t)try{delete v[D]}catch{}try{Object.defineProperty(v,D,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{v=Object.getPrototypeOf(v)}catch{break}}}let p=Object.freeze({now:function(){return Date.now()}}),x=t;for(;x&&x!==Object.prototype;){if(x!==t)try{delete x.performance}catch{}try{Object.defineProperty(x,"performance",{value:p,writable:!1,configurable:!1,enumerable:!1})}catch{}try{x=Object.getPrototypeOf(x)}catch{break}}let T=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],I=!1;function N(A,D){if(A.type==="3D_MODEL_READY"){if(I)return;I=!0}A.nonce=r,D&&D.length?a(A,D):a(A)}let f=function(A,D){if(!A||T.indexOf(A.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+T.join(", ")+").");N(A,D)},R=t;for(;R&&R!==Object.prototype;){if(R===t||Object.prototype.hasOwnProperty.call(R,"postMessage"))try{Object.defineProperty(R,"postMessage",{value:f,writable:!1,configurable:!1})}catch{}try{R=Object.getPrototypeOf(R)}catch{break}}let g=!1;t.onmessage=function(A){let D=A&&A.data;if(!(!D||D.nonce!==r)&&!(D.type!=="EXECUTE"&&D.type!=="EXECUTE_URL")&&!g){g=!0;try{let v=new b.Scene,w=new b.PerspectiveCamera(60,1,.1,1e3),C=new b.WebGLRenderer({isSandboxed:!0});if(D.type==="EXECUTE_URL"){if(!s||D.scriptUrl!==s||typeof c!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let d=h||s,y=c;if(c=null,h=null,t.THREE=b,t.scene=v,t.camera=w,t.renderer=C,y(d),typeof t.__THREE_LIVE_SCENE__=="function"){let S=t.__THREE_LIVE_SCENE__(b,v,w,C);S&&typeof S.toGLB=="function"&&(v=S)}else t.scene&&typeof t.scene.toGLB=="function"&&(v=t.scene)}else{if(!o){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let d=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
|
|
321
|
+
`,o}function nr(n,e){if(n&&typeof n.traverse=="function"){let i=Qn(n,e);return vt(i)}let t=Fe(n),r=xn(t);return vt(r)}var Ye=null;function rr(n){if(!Ye){Ye=new Uint32Array(256);for(let t=0;t<256;t++){let r=t;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;Ye[t]=r}}let e=4294967295;for(let t=0;t<n.length;t++)e=Ye[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}function vn(n){let e=[],t=0,r=[];for(let c of n){let h=je(c.filename),m=rr(c.data),b=c.data.length,g=30+h.length,d=t+g,w=0,C=d%64;C!==0&&(w=64-C);let N=new Uint8Array(g+w),f=new DataView(N.buffer);f.setUint32(0,67324752,!0),f.setUint16(4,20,!0),f.setUint16(6,0,!0),f.setUint16(8,0,!0),f.setUint16(10,0,!0),f.setUint16(12,0,!0),f.setUint32(14,m,!0),f.setUint32(18,b,!0),f.setUint32(22,b,!0),f.setUint16(26,h.length,!0),f.setUint16(28,w,!0),N.set(h,30),w>0&&N.fill(0,30+h.length),e.push({offset:t,size:b,crc:m,filenameBytes:h,entry:c}),r.push(N),r.push(c.data),t+=N.length+c.data.length}let i=t;for(let c of e){let h=new Uint8Array(46+c.filenameBytes.length),m=new DataView(h.buffer);m.setUint32(0,33639248,!0),m.setUint16(4,20,!0),m.setUint16(6,20,!0),m.setUint16(8,0,!0),m.setUint16(10,0,!0),m.setUint16(12,0,!0),m.setUint16(14,0,!0),m.setUint32(16,c.crc,!0),m.setUint32(20,c.size,!0),m.setUint32(24,c.size,!0),m.setUint16(28,c.filenameBytes.length,!0),m.setUint16(30,0,!0),m.setUint16(32,0,!0),m.setUint16(34,0,!0),m.setUint16(36,0,!0),m.setUint32(38,0,!0),m.setUint32(42,c.offset,!0),h.set(c.filenameBytes,46),r.push(h),t+=h.length}let s=t-i,o=new Uint8Array(22),l=new DataView(o.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,s,!0),l.setUint32(16,i,!0),l.setUint16(20,0,!0),r.push(o),t+=22;let a=new Uint8Array(t),u=0;for(let c of r)a.set(c,u),u+=c.length;return a}function Ue(n){let e=nr(n),t=je(e);return vn([{filename:"model.usda",data:t}])}function Mt(n){let e=Fe(n),t=xn(e),r=vt(t),i=je(r);return vn([{filename:"model.usda",data:i}])}function Mn(n){return n&&typeof n.toUSDZ=="function"?n.toUSDZ():n&&typeof n.traverse=="function"?Ue(n):Mt(n)}var wt=class n{constructor(e=0,t=0){this.x=Number(e),this.y=Number(t)}set(e,t){return this.x=Number(e),this.y=Number(t),this}clone(){return new n(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},te=class n{constructor(e=0,t=0,r=0){this.x=Number(e),this.y=Number(t),this.z=Number(r)}set(e,t,r){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this}clone(){return new n(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=t,this.y=r,this.z=i,this}crossVectors(e,t){let r=e.x,i=e.y,s=e.z,o=t.x,l=t.y,a=t.z;return this.x=i*a-s*l,this.y=s*o-r*a,this.z=r*l-i*o,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)}lerp(e,t){return this.lerpVectors(this,e,t)}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this}applyMatrix4(e){let t=this.x,r=this.y,i=this.z,s=e.elements,o=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*o,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*o,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*o,this}},Et=class{constructor(e=0,t=0,r=0,i=1){this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i)}set(e,t,r,i){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i),this}},Qe=class n{constructor(e=0,t=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,t,r,i=this.order){return this._x=Number(e),this._y=Number(t),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new n(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},et=class n{constructor(e=0,t=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,t,r,i){return this._x=Number(e),this._y=Number(t),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new n(this._x,this._y,this._z,this._w)}setFromEuler(e,t=!0){let r=e.x,i=e.y,s=e.z,o=Math.cos(r/2),l=Math.cos(i/2),a=Math.cos(s/2),u=Math.sin(r/2),c=Math.sin(i/2),h=Math.sin(s/2);return this._x=u*l*a+o*c*h,this._y=o*c*a-u*l*h,this._z=o*l*h+u*c*a,this._w=o*l*a-u*c*h,t&&this._onChangeCallback?.(),this}setFromAxisAngle(e,t){let r=t/2,i=Math.sin(r);return this.set(e.x*i,e.y*i,e.z*i,Math.cos(r))}normalize(){let e=Math.hypot(this._x,this._y,this._z,this._w);return e===0?this.set(0,0,0,1):this.set(this._x/e,this._y/e,this._z/e,this._w/e)}setFromUnitVectors(e,t){let r=e.dot(t)+1;return r<1e-6?(Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,0):this.set(0,-e.z,e.y,0)).normalize():this.set(e.y*t.z-e.z*t.y,e.z*t.x-e.x*t.z,e.x*t.y-e.y*t.x,r).normalize()}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,t){let r=e.x,i=e.y,s=e.z,o=e.w,l=t.x,a=t.y,u=t.z,c=t.w;return this._x=r*c+o*l+i*u-s*a,this._y=i*c+o*a+s*l-r*u,this._z=s*c+o*u+r*a-i*l,this._w=o*c-r*l-i*a-s*u,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},Se=class n{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new n;return e.copy(this),e}compose(e,t,r){return Me(this.elements,[t.x,t.y,t.z,t.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,t){return ee(this.elements,e.elements,t.elements),this}lookAt(e,t,r){return Re(this.elements,[e.x,e.y,e.z],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let t=new te(0,0,0),r=new te(1,1,1);return this.compose(t,e,r)}makeTranslation(e,t,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(t),this.elements[14]=Number(r),this}makeScale(e,t,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(t),this.elements[10]=Number(r),this}},Rt=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 me(this.elements,e.elements),this}},de=class n{constructor(e,t,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(t!==void 0&&r!==void 0?this.setRGB(e,t,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let t=parseInt(e.slice(1),16);this.setHex(t)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let t=Math.floor(e);return this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,this}setRGB(e,t,r){return this.r=Number(e),this.g=Number(t),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new n(this.r,this.g,this.b)}},ir={degToRad:n=>n*Math.PI/180,radToDeg:n=>n*180/Math.PI,clamp:(n,e,t)=>Math.max(e,Math.min(t,n)),lerp:(n,e,t)=>n+(e-n)*t,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(n,e)=>n+Math.random()*(e-n)},le=class{constructor(e,t){this.needsUpdate=!1;if(typeof t!="number"||!Number.isInteger(t)||t<1||t>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(t)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=t;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/t)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,t){return this.array[e*this.itemSize]=t,this.needsUpdate=!0,this}setY(e,t){return this.array[e*this.itemSize+1]=t,this.needsUpdate=!0,this}setZ(e,t){return this.array[e*this.itemSize+2]=t,this.needsUpdate=!0,this}setXYZ(e,t,r,i){let s=e*this.itemSize;return this.array[s]=t,this.array[s+1]=r,this.array[s+2]=i,this.needsUpdate=!0,this}},_t=class extends le{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},St=class extends le{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},At=class extends le{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},he=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,t){return this.attributes[e]=t,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof le)this.index=e;else if(Array.isArray(e)){let t=0;for(let r of e)r>t&&(t=r);this.index=new le(new(t>65535?Uint32Array:Uint16Array)(e),1)}else e&&e.buffer&&(this.index=new le(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let t=e.count,r=new Float32Array(t*3),i=new te,s=new te,o=new te,l=new te,a=new te;if(this.index){let u=this.index.array;for(let c=0;c<u.length;c+=3){let h=u[c],m=u[c+1],b=u[c+2];i.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(b),e.getY(b),e.getZ(b)),l.subVectors(o,s),a.subVectors(i,s),l.cross(a).normalize();for(let g of[h,m,b])r[g*3]+=l.x,r[g*3+1]+=l.y,r[g*3+2]+=l.z}}else for(let u=0;u<t;u+=3){i.set(e.getX(u),e.getY(u),e.getZ(u)),s.set(e.getX(u+1),e.getY(u+1),e.getZ(u+1)),o.set(e.getX(u+2),e.getY(u+2),e.getZ(u+2)),l.subVectors(o,s),a.subVectors(i,s),l.cross(a).normalize();for(let c=0;c<3;c++)r[(u+c)*3]=l.x,r[(u+c)*3+1]=l.y,r[(u+c)*3+2]=l.z}for(let u=0;u<t;u++){let c=r[u*3],h=r[u*3+1],m=r[u*3+2],b=Math.hypot(c,h,m)||1;r[u*3]=c/b,r[u*3+1]=h/b,r[u*3+2]=m/b}return this.setAttribute("normal",new le(r,3)),this}setFromBuffers(e,t,r,i){this.setAttribute("position",new le(e,3)),this.setAttribute("normal",new le(t,3)),this.setAttribute("uv",new le(r,2)),this.setIndex(i)}computeBoundingBox(){let e=this.attributes.position,t=new te(1/0,1/0,1/0),r=new te(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let i=0;i<e.count;i++){let s=e.getX(i),o=e.getY(i),l=e.getZ(i);s<t.x&&(t.x=s),o<t.y&&(t.y=o),l<t.z&&(t.z=l),s>r.x&&(r.x=s),o>r.y&&(r.y=o),l>r.z&&(r.z=l)}else t.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:t,max:r},this.boundingBox}center(){let e=this.computeBoundingBox(),t=(e.min.x+e.max.x)*.5,r=(e.min.y+e.max.y)*.5,i=(e.min.z+e.max.z)*.5,s=this.attributes.position;if(s&&s.count>0){for(let o=0;o<s.count;o++)s.setXYZ(o,s.getX(o)-t,s.getY(o)-r,s.getZ(o)-i);this.computeBoundingBox()}return this}dispose(){}},tt=class extends he{constructor(e=1,t=1,r=1){super();let i=e/2,s=t/2,o=r/2,l=[-i,-s,o,i,-s,o,i,s,o,-i,s,o,i,-s,-o,-i,-s,-o,-i,s,-o,i,s,-o,-i,s,o,i,s,o,i,s,-o,-i,s,-o,-i,-s,-o,i,-s,-o,i,-s,o,-i,-s,o,i,-s,o,i,-s,-o,i,s,-o,i,s,o,-i,-s,-o,-i,-s,o,-i,s,o,-i,s,-o],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],u=[],c=[];for(let h=0;h<6;h++){let m=h*4;u.push(0,0,1,0,1,1,0,1),c.push(m,m+1,m+2,m,m+2,m+3)}this.setFromBuffers(l,a,u,c)}},Ct=class extends he{constructor(e=1,t=1,r=1,i=1){super(),r=Math.max(1,Math.floor(r)),i=Math.max(1,Math.floor(i));let s=[],o=[],l=[],a=[];for(let u=0;u<=i;u++){let c=u/i;for(let h=0;h<=r;h++){let m=h/r;if(s.push((m-.5)*e,(.5-c)*t,0),o.push(0,0,1),l.push(m,1-c),u>0&&h>0){let b=(r+1)*u+h-1,g=b-(r+1);a.push(g,b,g+1,b,b+1,g+1)}}}this.setFromBuffers(s,o,l,a)}},nt=class extends he{constructor(e=1,t=16,r=12){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));let i=[],s=[],o=[],l=[];for(let a=0;a<=r;a++){let u=a/r;for(let c=0;c<=t;c++){let h=c/t,m=h*Math.PI*2,b=u*Math.PI,g=-Math.cos(m)*Math.sin(b),d=Math.cos(b),w=Math.sin(m)*Math.sin(b);if(i.push(e*g,e*d,e*w),s.push(g,d,w),o.push(h,1-u),a>0&&c>0){let C=(t+1)*a+c,N=C-(t+1),f=N-1,E=C-1;a!==1&&l.push(N,f,C),a!==r&&l.push(f,E,C)}}}this.setFromBuffers(i,s,o,l)}},Te=class extends he{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let s=[],o=[],l=[],a=[],u=r/2;for(let c=0;c<=1;c++){let h=c,m=c===0?e:t,b=c===0?u:-u;for(let g=0;g<=i;g++){let d=g/i,w=d*Math.PI*2,C=Math.sin(w),N=Math.cos(w);s.push(m*C,b,m*N),o.push(C,0,N),l.push(d,1-h)}}for(let c=0;c<i;c++){let h=c,m=c+i+1,b=c+i+2,g=c+1;a.push(h,m,g,m,b,g)}if(e>0){let c=s.length/3;s.push(0,u,0),o.push(0,1,0),l.push(.5,.5);let h=s.length/3;for(let m=0;m<=i;m++){let b=m/i*Math.PI*2,g=Math.sin(b),d=Math.cos(b);s.push(e*g,u,e*d),o.push(0,1,0),l.push(d*.5+.5,g*.5+.5)}for(let m=0;m<i;m++)a.push(c,h+m,h+m+1)}if(t>0){let c=s.length/3;s.push(0,-u,0),o.push(0,-1,0),l.push(.5,.5);let h=s.length/3;for(let m=0;m<=i;m++){let b=m/i*Math.PI*2,g=Math.sin(b),d=Math.cos(b);s.push(t*g,-u,t*d),o.push(0,-1,0),l.push(d*.5+.5,1-(g*.5+.5))}for(let m=0;m<i;m++)a.push(c,h+m+1,h+m)}this.setFromBuffers(s,o,l,a)}},It=class extends Te{constructor(e=1,t=1,r=16){super(0,e,t,r)}},Dt=class extends he{constructor(e=1,t=.4,r=12,i=48,s=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],l=[],a=[],u=[];for(let c=0;c<=r;c++){let h=c/r*Math.PI*2,m=Math.cos(h),b=Math.sin(h);for(let g=0;g<=i;g++){let d=g/i*s,w=Math.cos(d),C=Math.sin(d);if(o.push((e+t*m)*w,(e+t*m)*C,t*b),l.push(m*w,m*C,b),a.push(g/i,c/r),c>0&&g>0){let N=(i+1)*c+g-1,f=N-(i+1);u.push(N,f,N+1,f,f+1,N+1)}}}this.setFromBuffers(o,l,a,u)}},Lt=class extends he{constructor(e=1,t=.4,r=64,i=8,s=2,o=3){super(),r=Math.floor(r),i=Math.floor(i);let l=[],a=[],u=[],c=[],h=new te,m=new te,b=new te,g=new te,d=new te;function w(f,E){let x=Math.cos(E),_=Math.sin(E),D=o/s*E,v=e*(2+Math.cos(D))*.5;f.set(v*x,v*_,e*Math.sin(D)*.5)}let C=[];for(let f=0;f<=i;++f){let E=f/i*Math.PI*2;C.push(-t*Math.cos(E),t*Math.sin(E),f/i)}for(let f=0;f<=r;++f){let E=f/r,x=E*s*Math.PI*2;w(h,x),w(m,x+.01),b.subVectors(m,h).normalize(),g.addVectors(h,m).normalize(),d.crossVectors(b,g).normalize(),g.crossVectors(d,b).normalize();for(let _=0;_<=i;++_){let D=_*3,v=C[D],M=C[D+1],I=C[D+2],p=v*g.x+M*d.x,y=v*g.y+M*d.y,A=v*g.z+M*d.z;l.push(h.x+p,h.y+y,h.z+A);let T=Math.hypot(p,y,A)||1;a.push(p/T,y/T,A/T),u.push(E,I)}}let N=i+1;for(let f=1;f<=r;f++){let E=N*(f-1),x=E+N;for(let _=1;_<=i;_++){let D=E+(_-1),v=x+(_-1),M=x+_,I=E+_;c.push(D,v,I,v,M,I)}}this.setFromBuffers(l,a,u,c)}},rt=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(){}},Nt=class{load(e,t){let r=new rt(e);return t?.(r),r}};function ue(n,e){return n!==void 0?Number(n):e}function Tt(n,e){return n!==void 0?!!n:e}var xe=class{constructor(e={}){this.name=e.name||"",this.color=new de(e.color!==void 0?e.color:16777215),this.emissive=new de(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=ue(e.emissiveIntensity,1),this.roughness=ue(e.roughness,.5),this.metalness=ue(e.metalness,.1),this.opacity=ue(e.opacity,1),this.transparent=Tt(e.transparent,!1),this.wireframe=Tt(e.wireframe,!1),this.side=ue(e.side,2),this.doubleSided=Tt(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=ue(e.clearcoat,0),this.clearcoatRoughness=ue(e.clearcoatRoughness,0),this.sheen=ue(e.sheen,0),this.sheenColor=new de(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=ue(e.sheenRoughness,0),this.transmission=ue(e.transmission,0),this.thickness=ue(e.thickness,0),this.attenuationColor=new de(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=ue(e.attenuationDistance,1/0),this.ior=ue(e.ior,1.5),this.dispersion=ue(e.dispersion,0),this.iridescence=ue(e.iridescence,0),this.iridescenceIOR=ue(e.iridescenceIOR,1.3)}dispose(){}},Ae=class extends xe{},Pt=class extends xe{},Ft=class extends xe{},kt=class extends xe{},Ut=class extends xe{},pe=class n{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new te,this.rotation=new Qe,this.quaternion=new et,this.scale=new te(1,1,1),this.matrix=new Se,this.matrixWorld=new Se,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,t=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(t,r,i)})}add(...e){for(let t of e)t&&t instanceof n&&(t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t));return this}remove(...e){for(let t of e){let r=this.children.indexOf(t);r!==-1&&(t.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let t of this.children)t.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){An(this),(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let t of this.children)t.updateMatrixWorld(e)}lookAt(e,t,r){let i=typeof e=="object"?e:new te(e,t,r);this.updateMatrixWorld(!0);let s=new Se;s.lookAt(this.position,i,new te(0,1,0));let o=s.elements,l=o[0],a=o[4],u=o[8],c=o[1],h=o[5],m=o[9],b=o[2],g=o[6],d=o[10],w=l+h+d;if(w>0){let C=.5/Math.sqrt(w+1);this.quaternion.set((g-m)*C,(u-b)*C,(c-a)*C,.25/C)}}},Ot=class extends pe{},Ce=class extends pe{constructor(t,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=t instanceof he?t:t?(fe("unsupported geometry","BoxGeometry"),new tt(.5,.5,.5)):new he,this.material=i instanceof xe?i:i?(fe("unsupported material","MeshStandardMaterial"),new Ae({color:13421772})):new Ae}};function An(n){let e=Q().materializeDeclarativeGeometry;typeof e=="function"&&e(n)}var it=1e4,st=class extends Ce{constructor(t,r,i=1){super(t,r);this.instanceColor=null;this.isInstancedMesh=!0;let s=Number(i);if(!Number.isFinite(s)||s<0||s>it)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${it})`);this.count=Math.floor(s);let o=new Float32Array(this.count*16);for(let l=0;l<this.count;l++){let a=l*16;o[a]=1,o[a+5]=1,o[a+10]=1,o[a+15]=1}this.instanceMatrix=new le(o,16)}setMatrixAt(t,r){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let s=this.instanceMatrix.array,o=i*16;if(!(o+16>s.length))for(let l=0;l<16;l++){let a=Number(r.elements[l]);s[o+l]=Number.isFinite(a)?a:l%5===0?1:0}}getMatrixAt(t,r){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let s=this.instanceMatrix.array,o=i*16;if(!(o+16>s.length))for(let l=0;l<16;l++)r.elements[l]=s[o+l]}setColorAt(t,r){let i=Math.floor(Number(t));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 le(l,3)}let s=this.instanceColor.array,o=i*3;s[o]=Number.isFinite(r.r)?r.r:1,s[o+1]=Number.isFinite(r.g)?r.g:1,s[o+2]=Number.isFinite(r.b)?r.b:1}getColorAt(t,r){let i=Math.floor(Number(t));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 s=this.instanceColor.array,o=i*3;r.setRGB(s[o],s[o+1],s[o+2])}dispose(){}},Ie=class extends pe{constructor(e=16777215,t=1){super(),this.color=new de(e),this.intensity=Number(t),this.type="directional"}},ot=class extends Ie{constructor(e,t){super(e,t),this.type="ambient"}},Bt=class extends Ie{constructor(t,r){super(t,r);this.target=new pe;this.type="directional"}},at=class extends Ie{constructor(t,r,i=0,s=2){super(t,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=s}},ct=class extends pe{},Vt=class extends ct{constructor(t=45,r=1,i=.1,s=1e3){super();this.target=new te(0,0,0);this.fov=Number(t),this.aspect=Number(r),this.near=Number(i),this.far=Number(s)}},ut=class extends pe{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return ge.validate(this),ke(this)}toGLB(){return ge.validate(this),Ke(this)}toUSDZ(){return ge.validate(this),Ue(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,r=0;return this.traverse(i=>{if(i instanceof Ce){let s=new Float32Array(i.matrixWorld.elements);t.set(r,s),i.name&&t.set(i.name,s),r++}}),t}},Cn=ke,In=Ke,sr=Ue;var ge=class{static validate(e){let t=0,r=0,i=0,s=new Set,o=(a,u,c)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${u}). Found: ${c}`)},l=(a,u)=>{if(!Number.isFinite(u))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(u)}), which cannot be bounds-checked.`);return u};e.traverse(a=>{if(An(a),a instanceof Ce||a.geometry?.attributes?.position?.count){if(i++,i>1e3&&o("MESHES",1e3,i),a instanceof st){let c=l("instance",a.count);(c<0||c>it)&&o("INSTANCES",it,c)}let u=a.geometry;if(u){let c=0;if(u.attributes.position&&(c=l("vertex",u.attributes.position.count),t+=c,t>1e5&&o("VERTICES",1e5,t)),u.index){let h=l("index",u.index.count);r+=h,r>3e5&&o("INDICES",3e5,r);let m=u.index.array;if(m&&c>0){let b=Math.min(h,m.length);for(let g=0;g<b;g++){let d=m[g];if(!Number.isFinite(d)||d<0||d>=c)throw new Error(`SecurityError: Index buffer value (${String(d)}) out of vertex bounds [0, ${c}).`)}}}}if(a.material){let c=a.material;c.map&&s.add(c.map),c.normalMap&&s.add(c.normalMap),c.roughnessMap&&s.add(c.roughnessMap)}}}),s.size>16&&o("TEXTURES",16,s.size);for(let a of s){let u=a,c=u.image,h=Number(c?.width??u.width??0)||0,m=Number(c?.height??u.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(m)||h>2048||m>2048)&&o("TEXTURE_DIMENSION",2048,Math.max(h,m))}}},zt=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new de(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){ge.validate(e);let i=(s,o)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(o&&o.length?self.postMessage(s,o):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),o={};for(let[l,a]of s.entries())o[l]=Array.from(a);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:o})}else{this.hasInitialModelRendered=!0;let s=Cn(e),o=In(e),l=(s.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:o.buffer,dynamicLights:l,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[o.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 Tn(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Gt=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=Tn(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let t=Tn();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function or(){}var qe=new Proxy(or,{get:(n,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:qe},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>qe,construct:()=>qe}),wn=(()=>{try{if(typeof document>"u")return null;let n=document.currentScript;return n?.src?n.src:n?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([n.textContent],{type:"text/javascript"})):null}catch{return null}})();function Le(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function we(n,e){if(!n||typeof n!="string")return!1;let t=n.trim();if(!t)return!1;try{let r=new URL(t,Le());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 En,Oe;function ar(n){if(!we(n))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${n}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return n;if(Oe===void 0||En!==t){En=t;try{Oe=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!we(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Oe=null}}return Oe?Oe.createScriptURL(n):n}function Wr(n){Q().sandboxEngineSrc=n}function Dn(){let n=Q().sandboxEngineSrc;if(n)return n;if(wn)return wn;try{if(typeof document>"u")return null;let e=Le(),t=Array.from(document.querySelectorAll("script[src]"));for(let r of t){let i=r.src;if(!i)continue;let s=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&we(i,{requireSameOrigin:!0}))return i}}catch{}return null}function cr(){let n=Dn();if(!n)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!we(n))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Le()).href}function $r(n){Q().sandboxIframeSrc=n}function ur(){let n=Q().sandboxIframeSrc;if(n)return n;let e=Dn();if(!e||!we(e))return null;let t=new URL(e,Le());return t.protocol==="blob:"?null:new URL("three-live-sandbox.html",t).href}function lr(){let n=ur();if(!n)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!we(n))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Le()).href}function Yr(n){Q().allowClientScripts=n}function mr(){return!!Q().allowClientScripts}function hr(n){if(!we(n))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${n}". Only http:, https:, and blob: URLs are permitted.`);return new URL(n,Le()).href}var fr=["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 dr(n,e){let t=self,r=n.nonce,i=n.engineSrc,s=n.allowedScriptUrl,o=n.allowClientScripts,l=n.revoked,a=t.postMessage.bind(t);function u(_){a({type:"ERROR",nonce:r,message:String(_)})}let c=typeof t.importScripts=="function"?t.importScripts.bind(t):null,h=s,m=null;try{let _=i;if(typeof t.trustedTypes<"u"&&t.trustedTypes&&typeof t.trustedTypes.createPolicy=="function")try{let D={createScriptURL:function(M){if(M!==i&&(!s||M!==s))throw new TypeError("Disallowed worker importScripts URL");return M}};o&&(D.createScript=function(M){return String(M)});let v=t.trustedTypes.createPolicy("three-live#worker-boot",D);_=v.createScriptURL(i),s&&(h=v.createScriptURL(s)),o&&typeof v.createScript=="function"&&(m=v.createScript.bind(v))}catch{}c(_)}catch(_){u('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: '+(_&&_.message||_));return}let b=t.THREE;if(!b||typeof b.Scene!="function"){u('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 _=t.__THREE_LIVE_REGISTRY__;for(let D=0;D<e.length;D++)if(typeof e[D]=="function")try{e[D](b,_)}catch{}}for(let _=0;_<l.length;_++){let D=l[_],v=t;for(;v&&v!==Object.prototype;){if(v!==t)try{delete v[D]}catch{}try{Object.defineProperty(v,D,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{v=Object.getPrototypeOf(v)}catch{break}}}let g=Object.freeze({now:function(){return Date.now()}}),d=t;for(;d&&d!==Object.prototype;){if(d!==t)try{delete d.performance}catch{}try{Object.defineProperty(d,"performance",{value:g,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let w=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],C=!1;function N(_,D){if(_.type==="3D_MODEL_READY"){if(C)return;C=!0}_.nonce=r,D&&D.length?a(_,D):a(_)}let f=function(_,D){if(!_||w.indexOf(_.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+w.join(", ")+").");N(_,D)},E=t;for(;E&&E!==Object.prototype;){if(E===t||Object.prototype.hasOwnProperty.call(E,"postMessage"))try{Object.defineProperty(E,"postMessage",{value:f,writable:!1,configurable:!1})}catch{}try{E=Object.getPrototypeOf(E)}catch{break}}let x=!1;t.onmessage=function(_){let D=_&&_.data;if(!(!D||D.nonce!==r)&&!(D.type!=="EXECUTE"&&D.type!=="EXECUTE_URL")&&!x){x=!0;try{let v=new b.Scene,M=new b.PerspectiveCamera(60,1,.1,1e3),I=new b.WebGLRenderer({isSandboxed:!0});if(D.type==="EXECUTE_URL"){if(!s||D.scriptUrl!==s||typeof c!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let p=h||s,y=c;if(c=null,h=null,t.THREE=b,t.scene=v,t.camera=M,t.renderer=I,y(p),typeof t.__THREE_LIVE_SCENE__=="function"){let A=t.__THREE_LIVE_SCENE__(b,v,M,I);A&&typeof A.toGLB=="function"&&(v=A)}else t.scene&&typeof t.scene.toGLB=="function"&&(v=t.scene)}else{if(!o){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let p=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
|
|
320
322
|
return (function () {
|
|
321
323
|
`+D.script+`
|
|
322
324
|
})();
|
|
323
325
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
324
326
|
`+D.script+`
|
|
325
|
-
})();`);m=null;let y=d(b,v,w,C);y&&typeof y.toGLB=="function"&&(v=y)}if(!I){b.SceneQuotaValidator&&b.SceneQuotaValidator.validate(v);let d=v.toGLB(),y=d instanceof ArrayBuffer?d:d.buffer.slice(d.byteOffset,d.byteOffset+d.byteLength);N({type:"3D_MODEL_READY",glbBuffer:y},[y])}a({type:"DONE",nonce:r})}catch(v){u(v&&v.message||v)}}},a({type:"READY",nonce:r})}function Nn(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,s={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:dr},o=(ee().workerExtensionInstallers??[]).map(l=>`(${l.toString()})`).join(",");return`'use strict';(${pr.toString()})(${JSON.stringify(s)},[${o}]);`}function Fn(n){n.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),n.onToast?.("Security Error: script timed out and was stopped.")}var ve=0;function Pn(){try{let n=new Uint32Array(4);return globalThis.crypto?.getRandomValues(n),Array.from(n,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function br(n){try{return new TextEncoder().encode(n).length}catch{return n.length}}var yr=1024,gr=256;function An(n){if(!Array.isArray(n)&&!(n instanceof Float32Array)||n.length!==16)return!1;for(let e=0;e<16;e++){let t=n[e];if(typeof t!="number"||!Number.isFinite(t))return!1}return!0}function kn(n,e){if(!n||typeof n!="object")return null;let t=n;if(t.nonce!==e)return null;switch(t.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof t.message=="string"?t.message:String(t.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,yr)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let s of i)if(!An(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let s=Object.keys(i);if(s.length>1e3)return null;let o=Object.create(null),l=i;for(let a of s){if(a.length>gr||a==="__proto__"||a==="constructor"||a==="prototype")return null;let u=l[a];if(!An(u))return null;o[a]=u}return{type:"3D_UPDATE_TRANSFORMS",transforms:o}}return null}case"3D_MODEL_READY":{let i=t.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function xr(n){let e=br(n);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Un(n,e,t,r){switch(n.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(n.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(n.payload);return;case"DONE":t();return;case"ERROR":t(),e.onError?.(new Error(`Worker script error: ${n.message}`));return;default:return n}}function vr(n,e,t,r){let i=Pn(),s=Nn(e,i,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o=document.createElement("iframe");o.setAttribute("sandbox","allow-scripts"),o.setAttribute("aria-hidden","true"),o.tabIndex=-1,o.style.display="none",o.src=t,ve++;let l=!1,a=!1,u={modelDispatched:!1},c,h=()=>{if(l||a)return;let x=o.contentWindow;!x||typeof x.postMessage!="function"||(a=!0,x.postMessage(n.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:s,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:s,script:n.script},"*"))},m=()=>{},b=x=>{if(l||!o.contentWindow||x.source!==o.contentWindow)return;let T=x.data;if(T&&typeof T=="object"&&T.type==="IFRAME_READY"){h();return}let I=kn(T,i);I&&Un(I,r,m,u)};m=()=>{l||(l=!0,c!==void 0&&clearTimeout(c),ve=Math.max(0,ve-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",b),typeof o.remove=="function"?o.remove():o.parentNode&&o.parentNode.removeChild(o))},c=setTimeout(()=>{l||(m(),Fn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",b),o.onload=()=>{h()},o.onerror=()=>{m(),r.onError?.(new Error(`Sandbox iframe failed to load "${t}". Verify that three-live-sandbox.html is served at that URL.`))};let p=document.body||document.documentElement;if(!p||typeof p.appendChild!="function"){m();let x=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(x),x}return p.appendChild(o),{terminate:m}}function _n(n,e,t,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(ve>=32)return r(`SecurityError: ${ve} 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=ur()}catch(m){let b=m instanceof Error?m.message:String(m);return r(b,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let m;try{m=mr()}catch(b){let p=b instanceof Error?b.message:String(b);return r(p,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(vr(n,i,m,t))}catch(b){return Promise.reject(b)}}let s=Pn(),o=Nn(i,s,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let m=new Blob([o],{type:"application/javascript"}),b=URL.createObjectURL(m);try{let p=cr(b);l=new Worker(p)}finally{URL.revokeObjectURL(b)}}catch(m){let b=m instanceof Error?m.message:String(m);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${b}`,"Security Error: Failed to start Worker sandbox.")}ve++;let a=!1,u={modelDispatched:!1},c,h=()=>{a||(a=!0,c!==void 0&&clearTimeout(c),ve=Math.max(0,ve-1),l.terminate())};return c=setTimeout(()=>{a||(h(),Fn(t))},3e3),l.onmessage=m=>{let b=kn(m.data,s);b&&Un(b,t,h,u)},l.onerror=m=>{h(),t.onError?.(new Error(`Worker execution error: ${m.message}`))},n.kind==="url"?l.postMessage({type:"EXECUTE_URL",scriptUrl:n.scriptUrl,nonce:s}):l.postMessage({type:"EXECUTE",script:n.script,nonce:s}),Promise.resolve({terminate:h})}function Sn(n,e){return n==="none"||n==="unsafe-host-realm"?e(`SecurityError: sandbox="${n}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${n}" is not permitted.`):n!=="worker"&&n!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${n}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var wr={execute(n,e,t,r){let i=(l,a)=>{let u=new Error(l);return t.onError?.(u),a&&t.onToast?.(a),Promise.reject(u)},s=Sn(e,i);if(s)return s;try{xr(n)}catch(l){let a=l instanceof Error?l.message:String(l);return i(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??hr()?_n({kind:"script",script:n},e,t,i):i(Jt,Qt)},executeUrl(n,e,t){let r=(o,l)=>{let a=new Error(o);return t.onError?.(a),l&&t.onToast?.(l),Promise.reject(a)},i=Sn(e,r);if(i)return i;let s;try{s=fr(n)}catch(o){let l=o instanceof Error?o.message:String(o);return r(l,"Security Error: disallowed scene script URL.")}return _n({kind:"url",scriptUrl:s},e,t,r)}},ut=new Set;function fe(n,e){let t=`[three-live] ${n} is unsupported; degraded to ${e}.`;ut.has(t)||(ut.add(t),typeof console<"u"&&typeof console.warn=="function"&&console.warn(t))}function Mr(){return Array.from(ut)}function Tr(){ut.clear()}var lt=class extends Se{constructor(e={}){fe("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},Rr=lt,De=class extends tt{constructor(e=1,t=0,r="PolyhedronGeometry"){fe(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(t,3)));super(e,i,i)}},Ht=class extends De{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Xt=class extends De{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},Wt=class extends De{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},$t=class extends De{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Yt=class extends Me{constructor(e=1,t=1,r=4,i=8){fe("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},jt=class extends Me{constructor(e=.5,t=1,r=16){fe("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},Kt=class extends Me{constructor(e=1,t=16){fe("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},qt=class extends ot{constructor(t,r,i=0,s=Math.PI/3,o=0,l=2){fe("SpotLight","PointLight");super(t,r,i,l);this.target=new pe;this.angle=Math.PI/3;this.penumbra=0;this.angle=s,this.penumbra=o}},mt=class extends st{constructor(e,t,r){fe("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new de(t??4473924)}},Er=mt,On={Vector2:Tt,Vector3:ne,Vector4:Rt,Euler:Je,Quaternion:Qe,Matrix4:_e,Matrix3:Et,Color:de,MathUtils:sr,BufferAttribute:q,Float32BufferAttribute:At,Uint16BufferAttribute:_t,Uint32BufferAttribute:St,BufferGeometry:he,BoxGeometry:et,PlaneGeometry:Ct,SphereGeometry:tt,CylinderGeometry:Me,ConeGeometry:It,TorusGeometry:Dt,TorusKnotGeometry:Lt,IcosahedronGeometry:Ht,OctahedronGeometry:Xt,DodecahedronGeometry:Wt,TetrahedronGeometry:$t,CapsuleGeometry:Yt,RingGeometry:jt,CircleGeometry:Kt,Texture:nt,TextureLoader:Nt,Material:xe,MeshStandardMaterial:Se,MeshBasicMaterial:Ft,MeshLambertMaterial:Pt,MeshPhongMaterial:kt,MeshPhysicalMaterial:Ut,ShaderMaterial:lt,RawShaderMaterial:Rr,Object3D:pe,Group:Ot,Mesh:Ce,InstancedMesh:it,Light:Ie,AmbientLight:st,DirectionalLight:Bt,PointLight:ot,SpotLight:qt,HemisphereLight:mt,RectAreaLight:Er,Camera:at,PerspectiveCamera:Vt,Scene:ct,WebGLRenderer:zt,Clock:Gt,SceneQuotaValidator:ge,exportSceneToCanvas3D:In,exportSceneToGLB:Dn,exportSceneToUSDZ:or,generateUSDZ:Mn,glbToUSDZ:wt,sceneToCanvas3D:ke,sceneToGLB:je,sceneToUSDZ:Ue,authorScriptRunner:wr,getAuthorWarnings:Mr,clearAuthorWarnings:Tr};Object.freeze(ge);Object.freeze(ge.prototype);Object.freeze(ct.prototype);Object.freeze(On);var Ne=new Proxy(On,{get:(n,e)=>{if(e in n)return n[e];let t=ee().authorNamespace;return t&&typeof e=="string"&&e in t?t[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&fe(`THREE.${e}`,"no-op proxy"),Ke)},has:(n,e)=>{if(e in n)return!0;let t=ee().authorNamespace;return!!(t&&typeof e=="string"&&e in t)},set:(n,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(n,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(n,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),qe=ee();qe.threeNamespace=Ne;if(qe.workerExtensionInstallers)for(let n of qe.workerExtensionInstallers)n(Ne,qe);var Ze={name:"three_author",THREE:Ne},Yr=Ze,ye=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof ye.THREE>"u"&&(ye.THREE=Ne);typeof ye.requestAnimationFrame!="function"&&(ye.requestAnimationFrame=n=>(typeof n=="function"&&typeof ye.__three_live_raf_cb__!="function"&&(ye.__three_live_raf_cb__=n),ye.__three_live_in_step__||fe("requestAnimationFrame","single-frame static evaluation"),0));typeof ye.cancelAnimationFrame!="function"&&(ye.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=Ne,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=Ze,n.ThreeLivePlugins.three_author=Ze,n.ThreeLivePlugins["three-author"]=Ze}var jr=Ne;export{st as AmbientLight,et as BoxGeometry,q as BufferAttribute,he as BufferGeometry,at as Camera,Yt as CapsuleGeometry,Kt as CircleGeometry,Gt as Clock,de as Color,It as ConeGeometry,Me as CylinderGeometry,Bt as DirectionalLight,Wt as DodecahedronGeometry,Je as Euler,At as Float32BufferAttribute,Ot as Group,mt as HemisphereLight,Ht as IcosahedronGeometry,it as InstancedMesh,Ie as Light,rt as MAX_INSTANCES_PER_MESH,xe as Material,sr as MathUtils,Et as Matrix3,_e as Matrix4,Ce as Mesh,Ft as MeshBasicMaterial,Pt as MeshLambertMaterial,kt as MeshPhongMaterial,Ut as MeshPhysicalMaterial,Se as MeshStandardMaterial,pe as Object3D,Xt as OctahedronGeometry,Vt as PerspectiveCamera,Ct as PlaneGeometry,ot as PointLight,De as PolyhedronFallbackGeometry,Qe as Quaternion,Rr as RawShaderMaterial,Er as RectAreaLight,jt as RingGeometry,ct as Scene,ge as SceneQuotaValidator,lt as ShaderMaterial,tt as SphereGeometry,qt as SpotLight,Ne as THREE,$t as TetrahedronGeometry,nt as Texture,Nt as TextureLoader,Dt as TorusGeometry,Lt as TorusKnotGeometry,_t as Uint16BufferAttribute,St as Uint32BufferAttribute,Tt as Vector2,ne as Vector3,Rt as Vector4,zt as WebGLRenderer,wr as authorScriptRunner,Nn as buildSandboxWorkerSource,Tr as clearAuthorWarnings,jr as default,In as exportSceneToCanvas3D,Dn as exportSceneToGLB,or as exportSceneToUSDZ,Mn as generateUSDZ,hr as getAllowClientScripts,Mr as getAuthorWarnings,Ln as getSandboxEngineSrc,lr as getSandboxIframeSrc,wt as glbToUSDZ,Te as isAllowedSandboxEngineUrl,Ke as noopProxy,ke as sceneToCanvas3D,je as sceneToGLB,Ue as sceneToUSDZ,$r as setAllowClientScripts,Xr as setSandboxEngineSrc,Wr as setSandboxIframeSrc,Ze as threeAuthorPlugin,Yr as threeMicroPlugin,cr as toTrustedWorkerScriptURL,kn as validateSandboxWorkerMessage,fe as warnUnsupported};
|
|
327
|
+
})();`);m=null;let y=p(b,v,M,I);y&&typeof y.toGLB=="function"&&(v=y)}if(!C){b.SceneQuotaValidator&&b.SceneQuotaValidator.validate(v);let p=v.toGLB(),y=p instanceof ArrayBuffer?p:p.buffer.slice(p.byteOffset,p.byteOffset+p.byteLength);N({type:"3D_MODEL_READY",glbBuffer:y},[y])}a({type:"DONE",nonce:r})}catch(v){u(v&&v.message||v)}}},a({type:"READY",nonce:r})}function Ln(n,e,t){let r=t?.allowedScriptUrl??null,i=t?.allowClientScripts??r===null,s={nonce:e,engineSrc:n,allowedScriptUrl:r,allowClientScripts:i,revoked:fr},o=(Q().workerExtensionInstallers??[]).map(l=>`(${l.toString()})`).join(",");return`'use strict';(${dr.toString()})(${JSON.stringify(s)},[${o}]);`}function Nn(n){n.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),n.onToast?.("Security Error: script timed out and was stopped.")}var ve=0;function Pn(){try{let n=new Uint32Array(4);return globalThis.crypto?.getRandomValues(n),Array.from(n,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function pr(n){try{return new TextEncoder().encode(n).length}catch{return n.length}}var br=1024,yr=256;function Rn(n){if(!Array.isArray(n)&&!(n instanceof Float32Array)||n.length!==16)return!1;for(let e=0;e<16;e++){let t=n[e];if(typeof t!="number"||!Number.isFinite(t))return!1}return!0}function Fn(n,e){if(!n||typeof n!="object")return null;let t=n;if(t.nonce!==e)return null;switch(t.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof t.message=="string"?t.message:String(t.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,br)};case"3D_UPDATE_TRANSFORMS":{let i=t.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let s of i)if(!Rn(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let s=Object.keys(i);if(s.length>1e3)return null;let o=Object.create(null),l=i;for(let a of s){if(a.length>yr||a==="__proto__"||a==="constructor"||a==="prototype")return null;let u=l[a];if(!Rn(u))return null;o[a]=u}return{type:"3D_UPDATE_TRANSFORMS",transforms:o}}return null}case"3D_MODEL_READY":{let i=t.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function gr(n){let e=pr(n);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function kn(n,e,t,r){switch(n.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(n.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(n.payload);return;case"DONE":t();return;case"ERROR":t(),e.onError?.(new Error(`Worker script error: ${n.message}`));return;default:return n}}function xr(n,e,t,r){let i=Pn(),s=Ln(e,i,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o=document.createElement("iframe");o.setAttribute("sandbox","allow-scripts"),o.setAttribute("aria-hidden","true"),o.tabIndex=-1,o.style.display="none",o.src=t,ve++;let l=!1,a=!1,u={modelDispatched:!1},c,h=()=>{if(l||a)return;let d=o.contentWindow;!d||typeof d.postMessage!="function"||(a=!0,d.postMessage(n.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:s,scriptUrl:n.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:s,script:n.script},"*"))},m=()=>{},b=d=>{if(l||!o.contentWindow||d.source!==o.contentWindow)return;let w=d.data;if(w&&typeof w=="object"&&w.type==="IFRAME_READY"){h();return}let C=Fn(w,i);C&&kn(C,r,m,u)};m=()=>{l||(l=!0,c!==void 0&&clearTimeout(c),ve=Math.max(0,ve-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",b),typeof o.remove=="function"?o.remove():o.parentNode&&o.parentNode.removeChild(o))},c=setTimeout(()=>{l||(m(),Nn(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",b),o.onload=()=>{h()},o.onerror=()=>{m(),r.onError?.(new Error(`Sandbox iframe failed to load "${t}". Verify that three-live-sandbox.html is served at that URL.`))};let g=document.body||document.documentElement;if(!g||typeof g.appendChild!="function"){m();let d=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(d),d}return g.appendChild(o),{terminate:m}}function _n(n,e,t,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(ve>=32)return r(`SecurityError: ${ve} 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=cr()}catch(m){let b=m instanceof Error?m.message:String(m);return r(b,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let m;try{m=lr()}catch(b){let g=b instanceof Error?b.message:String(b);return r(g,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(xr(n,i,m,t))}catch(b){return Promise.reject(b)}}let s=Pn(),o=Ln(i,s,n.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:n.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let m=new Blob([o],{type:"application/javascript"}),b=URL.createObjectURL(m);try{let g=ar(b);l=new Worker(g)}finally{URL.revokeObjectURL(b)}}catch(m){let b=m instanceof Error?m.message:String(m);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${b}`,"Security Error: Failed to start Worker sandbox.")}ve++;let a=!1,u={modelDispatched:!1},c,h=()=>{a||(a=!0,c!==void 0&&clearTimeout(c),ve=Math.max(0,ve-1),l.terminate())};return c=setTimeout(()=>{a||(h(),Nn(t))},3e3),l.onmessage=m=>{let b=Fn(m.data,s);b&&kn(b,t,h,u)},l.onerror=m=>{h(),t.onError?.(new Error(`Worker execution error: ${m.message}`))},n.kind==="url"?l.postMessage({type:"EXECUTE_URL",scriptUrl:n.scriptUrl,nonce:s}):l.postMessage({type:"EXECUTE",script:n.script,nonce:s}),Promise.resolve({terminate:h})}function Sn(n,e){return n==="none"||n==="unsafe-host-realm"?e(`SecurityError: sandbox="${n}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${n}" is not permitted.`):n!=="worker"&&n!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${n}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var vr={execute(n,e,t,r){let i=(l,a)=>{let u=new Error(l);return t.onError?.(u),a&&t.onToast?.(a),Promise.reject(u)},s=Sn(e,i);if(s)return s;try{gr(n)}catch(l){let a=l instanceof Error?l.message:String(l);return i(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??mr()?_n({kind:"script",script:n},e,t,i):i(Jt,Qt)},executeUrl(n,e,t){let r=(o,l)=>{let a=new Error(o);return t.onError?.(a),l&&t.onToast?.(l),Promise.reject(a)},i=Sn(e,r);if(i)return i;let s;try{s=hr(n)}catch(o){let l=o instanceof Error?o.message:String(o);return r(l,"Security Error: disallowed scene script URL.")}return _n({kind:"url",scriptUrl:s},e,t,r)}},lt=new Set;function fe(n,e){let t=`[three-live] ${n} is unsupported; degraded to ${e}.`;lt.has(t)||(lt.add(t),typeof console<"u"&&typeof console.warn=="function"&&console.warn(t))}function Mr(){return Array.from(lt)}function Tr(){lt.clear()}var mt=class extends Ae{constructor(e={}){fe("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},wr=mt,De=class extends nt{constructor(e=1,t=0,r="PolyhedronGeometry"){fe(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(t,3)));super(e,i,i)}},Ht=class extends De{constructor(e=1,t=0){super(e,t,"IcosahedronGeometry")}},Xt=class extends De{constructor(e=1,t=0){super(e,t,"OctahedronGeometry")}},Wt=class extends De{constructor(e=1,t=0){super(e,t,"DodecahedronGeometry")}},$t=class extends De{constructor(e=1,t=0){super(e,t,"TetrahedronGeometry")}},Yt=class extends Te{constructor(e=1,t=1,r=4,i=8){fe("CapsuleGeometry","CylinderGeometry"),super(e,e,t+e*2,i)}},jt=class extends Te{constructor(e=.5,t=1,r=16){fe("RingGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,r))}},Kt=class extends Te{constructor(e=1,t=16){fe("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,t))}},qt=class extends at{constructor(t,r,i=0,s=Math.PI/3,o=0,l=2){fe("SpotLight","PointLight");super(t,r,i,l);this.target=new pe;this.angle=Math.PI/3;this.penumbra=0;this.angle=s,this.penumbra=o}},ht=class extends ot{constructor(e,t,r){fe("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new de(t??4473924)}},Er=ht,Un={Vector2:wt,Vector3:te,Vector4:Et,Euler:Qe,Quaternion:et,Matrix4:Se,Matrix3:Rt,Color:de,MathUtils:ir,BufferAttribute:le,Float32BufferAttribute:_t,Uint16BufferAttribute:St,Uint32BufferAttribute:At,BufferGeometry:he,BoxGeometry:tt,PlaneGeometry:Ct,SphereGeometry:nt,CylinderGeometry:Te,ConeGeometry:It,TorusGeometry:Dt,TorusKnotGeometry:Lt,IcosahedronGeometry:Ht,OctahedronGeometry:Xt,DodecahedronGeometry:Wt,TetrahedronGeometry:$t,CapsuleGeometry:Yt,RingGeometry:jt,CircleGeometry:Kt,Texture:rt,TextureLoader:Nt,Material:xe,MeshStandardMaterial:Ae,MeshBasicMaterial:Pt,MeshLambertMaterial:Ft,MeshPhongMaterial:kt,MeshPhysicalMaterial:Ut,ShaderMaterial:mt,RawShaderMaterial:wr,Object3D:pe,Group:Ot,Mesh:Ce,InstancedMesh:st,Light:Ie,AmbientLight:ot,DirectionalLight:Bt,PointLight:at,SpotLight:qt,HemisphereLight:ht,RectAreaLight:Er,Camera:ct,PerspectiveCamera:Vt,Scene:ut,WebGLRenderer:zt,Clock:Gt,SceneQuotaValidator:ge,exportSceneToCanvas3D:Cn,exportSceneToGLB:In,exportSceneToUSDZ:sr,generateUSDZ:Mn,glbToUSDZ:Mt,sceneToCanvas3D:ke,sceneToGLB:Ke,sceneToUSDZ:Ue,authorScriptRunner:vr,getAuthorWarnings:Mr,clearAuthorWarnings:Tr};Object.freeze(ge);Object.freeze(ge.prototype);Object.freeze(ut.prototype);Object.freeze(Un);var Ne=new Proxy(Un,{get:(n,e)=>{if(e in n)return n[e];let t=Q().authorNamespace;return t&&typeof e=="string"&&e in t?t[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&fe(`THREE.${e}`,"no-op proxy"),qe)},has:(n,e)=>{if(e in n)return!0;let t=Q().authorNamespace;return!!(t&&typeof e=="string"&&e in t)},set:(n,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(n,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(n,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),Ze=Q();Ze.threeNamespace=Ne;if(Ze.workerExtensionInstallers)for(let n of Ze.workerExtensionInstallers)n(Ne,Ze);var Je={name:"three_author",THREE:Ne},jr=Je,ye=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof ye.THREE>"u"&&(ye.THREE=Ne);typeof ye.requestAnimationFrame!="function"&&(ye.requestAnimationFrame=n=>(typeof n=="function"&&typeof ye.__three_live_raf_cb__!="function"&&(ye.__three_live_raf_cb__=n),ye.__three_live_in_step__||fe("requestAnimationFrame","single-frame static evaluation"),0));typeof ye.cancelAnimationFrame!="function"&&(ye.cancelAnimationFrame=()=>{});if(typeof window<"u"){let n=window;n.ThreeLive=n.ThreeLive||{},n.ThreeLive.THREE=Ne,n.ThreeLivePlugins=n.ThreeLivePlugins||{},n.ThreeLivePlugins.threeAuthor=Je,n.ThreeLivePlugins.three_author=Je,n.ThreeLivePlugins["three-author"]=Je}var Kr=Ne;export{ot as AmbientLight,tt as BoxGeometry,le as BufferAttribute,he as BufferGeometry,ct as Camera,Yt as CapsuleGeometry,Kt as CircleGeometry,Gt as Clock,de as Color,It as ConeGeometry,Te as CylinderGeometry,Bt as DirectionalLight,Wt as DodecahedronGeometry,Qe as Euler,_t as Float32BufferAttribute,Ot as Group,ht as HemisphereLight,Ht as IcosahedronGeometry,st as InstancedMesh,Ie as Light,it as MAX_INSTANCES_PER_MESH,xe as Material,ir as MathUtils,Rt as Matrix3,Se as Matrix4,Ce as Mesh,Pt as MeshBasicMaterial,Ft as MeshLambertMaterial,kt as MeshPhongMaterial,Ut as MeshPhysicalMaterial,Ae as MeshStandardMaterial,pe as Object3D,Xt as OctahedronGeometry,Vt as PerspectiveCamera,Ct as PlaneGeometry,at as PointLight,De as PolyhedronFallbackGeometry,et as Quaternion,wr as RawShaderMaterial,Er as RectAreaLight,jt as RingGeometry,ut as Scene,ge as SceneQuotaValidator,mt as ShaderMaterial,nt as SphereGeometry,qt as SpotLight,Ne as THREE,$t as TetrahedronGeometry,rt as Texture,Nt as TextureLoader,Dt as TorusGeometry,Lt as TorusKnotGeometry,St as Uint16BufferAttribute,At as Uint32BufferAttribute,wt as Vector2,te as Vector3,Et as Vector4,zt as WebGLRenderer,vr as authorScriptRunner,Ln as buildSandboxWorkerSource,Tr as clearAuthorWarnings,Kr as default,Cn as exportSceneToCanvas3D,In as exportSceneToGLB,sr as exportSceneToUSDZ,Mn as generateUSDZ,mr as getAllowClientScripts,Mr as getAuthorWarnings,Dn as getSandboxEngineSrc,ur as getSandboxIframeSrc,Mt as glbToUSDZ,we as isAllowedSandboxEngineUrl,qe as noopProxy,ke as sceneToCanvas3D,Ke as sceneToGLB,Ue as sceneToUSDZ,Yr as setAllowClientScripts,Wr as setSandboxEngineSrc,$r as setSandboxIframeSrc,Je as threeAuthorPlugin,jr as threeMicroPlugin,ar as toTrustedWorkerScriptURL,Fn as validateSandboxWorkerMessage,fe as warnUnsupported};
|