three-live 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/three-author-engine.js +89 -62
- package/dist/three-author.cjs +86 -59
- package/dist/three-author.d.ts +1 -0
- package/dist/three-author.js +86 -59
- package/dist/three-convert.cjs +79 -52
- package/dist/three-convert.d.ts +1 -0
- package/dist/three-convert.js +80 -53
- package/dist/three-live-animation.d.ts +1 -0
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +1 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +2 -2
- package/dist/three-live-element.d.ts +1 -0
- package/dist/three-live-element.js +2 -2
- package/dist/three-live-full.cjs +94 -67
- package/dist/three-live-full.js +102 -75
- package/dist/three-live-full.min.js +95 -68
- package/dist/three-live-studio.d.ts +1 -0
- package/dist/three-live-viewer.cjs +2 -2
- package/dist/three-live-viewer.d.ts +1 -0
- package/dist/three-live-viewer.js +2 -2
- package/dist/three-live-viewer.min.js +2 -2
- package/dist/three-live.cjs +85 -58
- package/dist/three-live.js +85 -58
- package/dist/three-live.min.js +85 -58
- package/dist/three-view.d.ts +1 -0
- package/dist/three-xr.cjs +80 -53
- package/dist/three-xr.d.ts +1 -0
- package/dist/three-xr.js +83 -56
- package/package.json +19 -1
package/dist/three-author.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/function zr(e,t,i){let r=[],s=new Map,n=[],o=[],a=[],h=new Map,l=m=>{let p=s.get(m);return p===void 0&&(p=r.length,r.push({op:m}),s.set(m,p)),p},c=m=>{let p=h.get(m);return p===void 0&&(p=a.length,a.push({id:m}),h.set(m,p)),p},f=(m,p={})=>n.push({declaration:l(m),...p})-1,y=(m,p,v)=>o.push({id:m,type:p,value:v})-1,g=m=>({node:m,socket:"value"}),u=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(u&&typeof u=="object"){let m=Array.isArray(u.graphs)?u.graphs[u.graph??0]:u;if(m&&Array.isArray(m.nodes)){let p=Array.isArray(m.declarations)?m.declarations:[];for(let v of p)v?.op&&l(v.op);Array.isArray(m.variables)&&o.push(...m.variables);for(let v of m.events||[])v?.id&&c(v.id);for(let v of m.nodes){if(!v||typeof v!="object")continue;let R=v.op||(typeof v.declaration=="number"?p[v.declaration]?.op:"");n.push(R?{...v,declaration:l(R)}:{...v})}}}let b=(m,p,v="translation")=>v==="baseColorFactor"||v==="metallicFactor"||v==="roughnessFactor"?`/materials/${Math.max(0,p)}/pbrMetallicRoughness/${v}`:v==="emissiveFactor"||v==="alphaCutoff"?`/materials/${Math.max(0,p)}/${v}`:v==="visible"?`/nodes/${m}/extensions/KHR_node_visibility/visible`:`/nodes/${m}/${v}`,w=new Map;e.forEach((m,p)=>{typeof m?.name=="string"&&!w.has(m.name)&&w.set(m.name,p)});let M=(m,p)=>typeof m.target=="string"&&w.has(m.target)?w.get(m.target):typeof m.targetNode=="number"?m.targetNode:p,x=m=>{let p=e[m];return(typeof p?.mesh=="number"?t[p.mesh]?.primitives?.[0]?.material:0)??0};for(let m=0;m<e.length;m++){let p=e[m],v=p?.extras?.interactivity;if(!v||typeof v!="object")continue;let R=(typeof p.mesh=="number"?t[p.mesh]?.primitives?.[0]?.material:0)??0,L=N=>{let _=Array.isArray(N)?N:[N],A=[];for(let C=0;C<_.length;C++){let d=_[C];if(!d||typeof d!="object")continue;let k=d.action||"interpolate",$=typeof d.duration=="number"?d.duration:.35;if(k==="toggleTransform"){let S=d.property==="rotation"||d.property==="scale"?d.property:"translation",D=S==="rotation"?p.rotation||[0,0,0,1]:S==="scale"?p.scale||[1,1,1]:p.translation||[0,0,0],T=`/nodes/${m}/${S}`,P=y(`__toggle_${m}_${C}`,"bool",!1),j=f("variable/get",{configuration:{variable:P}}),W=f("math/not",{values:{a:g(j)}}),V=f("variable/set",{configuration:{variable:P},values:{value:g(W)}}),Z=f("pointer/interpolate",{configuration:{pointer:T},values:{value:{value:Array.isArray(d.to)?d.to:D},duration:{value:$}}}),U=f("pointer/interpolate",{configuration:{pointer:T},values:{value:{value:Array.isArray(d.from)?d.from:D},duration:{value:$}}});n[V].flows={out:{node:f("flow/branch",{values:{condition:g(j)},flows:{true:{node:Z},false:{node:U}}})}},A.push(V)}else if(k==="interpolate"){let S=d.to??d.value;if(S===void 0)continue;let D={value:{value:S},duration:{value:$}};d.from!==void 0&&(D.from={value:d.from}),A.push(f("pointer/interpolate",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:b(M(d,m),x(M(d,m)),d.property)},values:D}))}else if(k==="setProperty"){if(d.value===void 0)continue;A.push(f("pointer/set",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:b(M(d,m),x(M(d,m)),d.property)},values:{value:{value:d.value}}}))}else if(k==="toggleVisibility"){let S=M(d,m),D=y(`__vis_${S}_${C}`,"bool",!0),T=f("variable/get",{configuration:{variable:D}}),P=f("math/not",{values:{a:g(T)}}),j=f("variable/set",{configuration:{variable:D},values:{value:g(P)}});n[j].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${S}/extensions/KHR_node_visibility/visible`},values:{value:g(T)}})}},A.push(j)}else if(k==="cycleMaterialColor"&&Array.isArray(d.colors)&&d.colors.length>0){let S=typeof d.duration=="number"?d.duration:.25,D=`/materials/${Math.max(0,R)}/pbrMetallicRoughness/baseColorFactor`,T=y(`__color_idx_${m}_${C}`,"int",0),P=f("variable/get",{configuration:{variable:T}}),j=f("math/add",{values:{a:g(P),b:{value:1}}}),W=f("math/rem",{values:{a:g(j),b:{value:d.colors.length}}}),V=f("variable/set",{configuration:{variable:T},values:{value:g(W)}}),Z={};for(let U=0;U<d.colors.length;U++){let X=d.colors[U],O=Array.isArray(X)&&X.length>=3?[X[0],X[1],X[2],X[3]??1]:[1,1,1,1];Z[String(U)]={node:S>0?f("pointer/interpolate",{configuration:{pointer:D},values:{value:{value:O},duration:{value:S}}}):f("pointer/set",{configuration:{pointer:D},values:{value:{value:O}}})}}n[V].flows={out:{node:f("flow/switch",{values:{selection:g(P)},flows:Z})}},A.push(V)}else if(k==="playAnimation")A.push(f("animation/start",{configuration:{animation:d.animation??d.clip??0}}));else if(k==="stopAnimation")A.push(f("animation/stop"));else if(k==="sendEvent"){let S={};for(let[D,T]of Object.entries(d.values||{}))S[D]={value:T};A.push(f("event/send",{configuration:{event:c(String(d.event??d.id??"custom"))},values:S}))}}if(!A.length)return null;if(A.length===1)return A[0];let E={};return A.forEach((C,d)=>{E[String(d)]={node:C}}),f("flow/sequence",{flows:E})},I=(N,_,A)=>{let E=L(_);E!==null&&f(N,{...A?{configuration:A}:{},flows:{out:{node:E}}})};if(v.onSelect&&I("pointer/onSelect",v.onSelect,{nodeIndex:m}),v.onHoverIn&&I("pointer/onHoverIn",v.onHoverIn,{nodeIndex:m}),v.onHoverOut&&I("pointer/onHoverOut",v.onHoverOut,{nodeIndex:m}),v.onStart&&I("event/onStart",v.onStart),v.onReceive&&typeof v.onReceive=="object")for(let[N,_]of Object.entries(v.onReceive))I("event/receive",_,{event:c(N)})}return n.length?{graphs:[{declarations:r,nodes:n,variables:o,events:a}],graph:0}:null}var Vr='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).',Or="Security Error: client-side scripts require allow-client-scripts opt-in.",Jt="__THREE_LIVE_REGISTRY__";function ut(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Jt]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Jt,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Jt]=t}}return e[Jt]}var mt=ut().plugins;function Br(e){let t=ut().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function $r(){return ut().plugins}function ht(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ge(e,t,i,r,s){let n=1/Math.tan(t/2);e.fill(0),e[0]=n/i,e[5]=n,e[11]=-1;let o=1/(r-s);return e[10]=(s+r)*o,e[14]=2*s*r*o,e}function Qt(e,t,i,r){let[s,n,o]=t,[a,h,l]=r,[c,f,y]=i,g=s-c,u=n-f,b=o-y,w=Math.hypot(g,u,b);w<=1e-5?(g=0,u=0,b=1):(g/=w,u/=w,b/=w);let M=h*b-l*u,x=l*g-a*b,m=a*u-h*g;w=Math.hypot(M,x,m),w<=1e-5?(M=0,x=0,m=0):(M/=w,x/=w,m/=w);let p=u*m-b*x,v=b*M-g*m,R=g*x-u*M;return w=Math.hypot(p,v,R),w<=1e-5?(p=0,v=0,R=0):(p/=w,v/=w,R/=w),e[0]=M,e[1]=p,e[2]=g,e[3]=0,e[4]=x,e[5]=v,e[6]=u,e[7]=0,e[8]=m,e[9]=R,e[10]=b,e[11]=0,e[12]=-(M*s+x*n+m*o),e[13]=-(p*s+v*n+R*o),e[14]=-(g*s+u*n+b*o),e[15]=1,e}function dt(e,t,i){let r=t[0],s=t[1],n=t[2],o=t[3],a=t[4],h=t[5],l=t[6],c=t[7],f=t[8],y=t[9],g=t[10],u=t[11],b=t[12],w=t[13],M=t[14],x=t[15],m=i[0],p=i[1],v=i[2],R=i[3];return e[0]=m*r+p*a+v*f+R*b,e[1]=m*s+p*h+v*y+R*w,e[2]=m*n+p*l+v*g+R*M,e[3]=m*o+p*c+v*u+R*x,m=i[4],p=i[5],v=i[6],R=i[7],e[4]=m*r+p*a+v*f+R*b,e[5]=m*s+p*h+v*y+R*w,e[6]=m*n+p*l+v*g+R*M,e[7]=m*o+p*c+v*u+R*x,m=i[8],p=i[9],v=i[10],R=i[11],e[8]=m*r+p*a+v*f+R*b,e[9]=m*s+p*h+v*y+R*w,e[10]=m*n+p*l+v*g+R*M,e[11]=m*o+p*c+v*u+R*x,m=i[12],p=i[13],v=i[14],R=i[15],e[12]=m*r+p*a+v*f+R*b,e[13]=m*s+p*h+v*y+R*w,e[14]=m*n+p*l+v*g+R*M,e[15]=m*o+p*c+v*u+R*x,e}function ye(e,t,i,r){let s=t[0],n=t[1],o=t[2],a=t[3],h=s+s,l=n+n,c=o+o,f=s*h,y=s*l,g=s*c,u=n*l,b=n*c,w=o*c,M=a*h,x=a*l,m=a*c,p=r[0],v=r[1],R=r[2];return e[0]=(1-(u+w))*p,e[1]=(y+m)*p,e[2]=(g-x)*p,e[3]=0,e[4]=(y-m)*v,e[5]=(1-(f+w))*v,e[6]=(b+M)*v,e[7]=0,e[8]=(g+x)*R,e[9]=(b-M)*R,e[10]=(1-(f+u))*R,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function Pt(e,t,i=0){let r=t[0],s=t[1],n=t[2],o=t[4],a=t[5],h=t[6],l=t[8],c=t[9],f=t[10],y=f*a-h*c,g=-f*o+h*l,u=c*o-a*l,b=r*y+s*g+n*u;return!b||i>0&&(!Number.isFinite(b)||Math.abs(b)<=i)||(b=1/b,e[0]=y*b,e[1]=g*b,e[2]=u*b,e[3]=(-f*s+n*c)*b,e[4]=(f*r-n*l)*b,e[5]=(-c*r+s*l)*b,e[6]=(h*s-n*a)*b,e[7]=(-h*r+n*o)*b,e[8]=(a*r-s*o)*b),e}function Gr(e,t){let i=t[0],r=t[1],s=t[2],n=t[3],o=t[4],a=t[5],h=t[6],l=t[7],c=t[8],f=t[9],y=t[10],g=t[11],u=t[12],b=t[13],w=t[14],M=t[15],x=i*a-r*o,m=i*h-s*o,p=i*l-n*o,v=r*h-s*a,R=r*l-n*a,L=s*l-n*h,I=c*b-f*u,N=c*w-y*u,_=c*M-g*u,A=f*w-y*b,E=f*M-g*b,C=y*M-g*w,d=x*C-m*E+p*A+v*_-R*N+L*I;return d?(d=1/d,e[0]=(a*C-h*E+l*A)*d,e[1]=(s*E-r*C-n*A)*d,e[2]=(b*L-w*R+M*v)*d,e[3]=(y*R-f*L-g*v)*d,e[4]=(h*_-o*C-l*N)*d,e[5]=(i*C-s*_+n*N)*d,e[6]=(w*p-u*L-M*m)*d,e[7]=(c*L-y*p+g*m)*d,e[8]=(o*E-a*_+l*I)*d,e[9]=(r*_-i*E-n*I)*d,e[10]=(u*R-b*p+M*x)*d,e[11]=(f*p-c*R-g*x)*d,e[12]=(a*N-o*A-h*I)*d,e[13]=(i*A-r*N+s*I)*d,e[14]=(b*m-u*v-w*x)*d,e[15]=(c*v-f*m+y*x)*d,e):null}function Ye(e,t,i,r,s){let n=s[0]*t+s[4]*i+s[8]*r+s[12],o=s[1]*t+s[5]*i+s[9]*r+s[13],a=s[2]*t+s[6]*i+s[10]*r+s[14],h=s[3]*t+s[7]*i+s[11]*r+s[15],l=h!==0?1/h:1;e[0]=n*l,e[1]=o*l,e[2]=a*l}function Hr(e,t,i,r,s,n,o,a,h,l,c,f,y,g,u,b,w=0){let M=l-o,x=c-a,m=f-h,p=y-o,v=g-a,R=u-h,L=s*R-n*v,I=n*p-r*R,N=r*v-s*p,_=M*L+x*I+m*N;if(_>-1e-7&&_<1e-7)return!1;let A=1/_,E=e-o,C=t-a,d=i-h,k=A*(E*L+C*I+d*N);if(k<-w||k>1+w)return!1;let $=C*m-d*x,S=d*M-E*m,D=E*x-C*M,T=A*(r*$+s*S+n*D);if(T<-w||k+T>1+w)return!1;let P=A*(p*$+v*S+R*D);if(P>1e-4&&P<b.distance){b.distance=P,b.point=[e+r*P,t+s*P,i+n*P];let j=x*R-m*v,W=m*p-M*R,V=M*v-x*p,Z=Math.hypot(j,W,V)||1;return b.normal=[j/Z,W/Z,V/Z],!0}return!1}function jr(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let c=0;c<i;c++)r.push(ht());if(i===0)return r;let s=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let f of c.children)s.add(f);let n=new Set,o=128,a=(c,f,y=0)=>{if(y>o||c<0||c>=i||n.has(c))return;n.add(c);let g=e.nodes[c];if(!g)return;let u=ht();if(t&&t[c])u.set(t[c]);else if(g.matrix&&g.matrix.length===16)u.set(g.matrix);else{let w=g.translation||[0,0,0],M=g.rotation||[0,0,0,1],x=g.scale||[1,1,1];ye(u,M,w,x)}let b=r[c];if(f?dt(b,f,u):b.set(u),Array.isArray(g.children))for(let w of g.children)typeof w=="number"&&a(w,b,y+1)},h=[],l=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(l&&Array.isArray(l.nodes))h.push(...l.nodes);else for(let c=0;c<i;c++)s.has(c)||h.push(c);for(let c of h)a(c,null);for(let c=0;c<i;c++)!s.has(c)&&!h.includes(c)&&a(c,null);return r}var Wr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Ze(e,t,i,r){if(!i||i.bufferView===void 0)return null;let s=e.bufferViews?.[i.bufferView];if(!s)return null;let n=Number(i.count??0);if(!Number.isInteger(n)||n<=0)return null;let o=i.componentType??5126,a=Wr[o];if(!a)throw new RangeError(`glTF accessor has unsupported componentType ${o}`);let h=a*r,l=s.byteStride&&s.byteStride>0?s.byteStride:h,c=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(c)||c<0||l<h||c+(n-1)*l+h>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(o===5126&&l===h&&c%4===0)return new Float32Array(t,c,n*r);let f=new DataView(t),y=i.normalized===!0,g=new Float32Array(n*r);for(let u=0;u<n;u++){let b=c+u*l;for(let w=0;w<r;w++){let M=b+w*a,x;switch(o){case 5126:x=f.getFloat32(M,!0);break;case 5120:x=f.getInt8(M),y&&(x=Math.max(x/127,-1));break;case 5121:x=f.getUint8(M),y&&(x/=255);break;case 5122:x=f.getInt16(M,!0),y&&(x=Math.max(x/32767,-1));break;case 5123:x=f.getUint16(M,!0),y&&(x/=65535);break;default:x=f.getUint32(M,!0),y&&(x/=4294967295)}g[u*r+w]=x}}return g}function Xr(e,t){let i=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,s=Number(t.scale?.[0]??1),n=Number(t.scale?.[1]??1),o=Number(t.rotation??0)||0,a=Math.cos(o),h=Math.sin(o),l=(Number.isFinite(s)?s:1)*a,c=(Number.isFinite(s)?s:1)*h,f=-(Number.isFinite(n)?n:1)*h,y=(Number.isFinite(n)?n:1)*a;for(let g=0;g+1<e.length;g+=2){let u=e[g],b=e[g+1];e[g]=l*u+c*b+i,e[g+1]=f*u+y*b+r}}function be(e,t,i,r=!0){let s=[],n=null;try{for(let[o,a]of[[35633,t],[35632,i]]){let h=e.createShader(o);if(!h){if(r)throw new Error("Shader allocation failed");return null}if(s.push(h),e.shaderSource(h,a),e.compileShader(h),e.getShaderParameter&&!e.getShaderParameter(h,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(h)}`);return null}}if(n=e.createProgram(),!n){if(r)throw new Error("Program allocation failed");return null}for(let o of s)e.attachShader(n,o);if(e.linkProgram(n),e.getProgramParameter&&!e.getProgramParameter(n,35714)){let o=r?e.getProgramInfoLog(n):null;if(e.deleteProgram?.(n),n=null,r)throw new Error(`Program link error: ${o}`);return null}return n}finally{for(let o of s)n&&e.detachShader?.(n,o),e.deleteShader?.(o)}}var Je=["neutral","reinhard","none","aces","agx"];function xe(e){let t=String(e??"").trim().toLowerCase();return Je.includes(t)?t:"neutral"}function qr(e){return Je.indexOf(xe(e))}function Kr(e){return new TextDecoder().decode(e)}var Qe=ut().decoders;function Yr(e,t){Qe.set(e.toLowerCase(),t)}function Vt(e){return Qe.get(e.toLowerCase())}function ti(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,i=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let y=i.getUint8(0);throw y===123||y===32||y===10||y===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let n=i.getUint32(8,!0),o=12,a=null,h=null;for(;o+8<=n&&o+8<=t.byteLength;){let y=i.getUint32(o,!0),g=i.getUint32(o+4,!0),u=o+8;if(u+y>t.byteLength)throw new Error(`Truncated GLB chunk: required ${u+y} bytes, buffer has ${t.byteLength}`);if(g===1313821514){let b=new Uint8Array(t,u,y),w=Kr(b);a=JSON.parse(w,(M,x)=>M==="__proto__"||M==="constructor"||M==="prototype"?void 0:x)}else g===5130562&&(h=t.slice(u,u+y));o=u+y}if(!a)throw new Error("Missing JSON chunk in GLB");let l=a.extensionsRequired||[];if(l.includes("KHR_draco_mesh_compression")&&!Vt("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let y of["EXT_meshopt_compression","KHR_meshopt_compression"])if(l.includes(y)&&!Vt("meshopt"))throw new Error(`Model requires ${y}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(l.includes("KHR_texture_basisu")&&!Vt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let c=h||new ArrayBuffer(0),f={gltf:a,bin:c,animations:[]};for(let y of mt)y.onParseGLB?.(f);return f}function Zr(e){return typeof e=="object"&&e!==null&&"gltf"in e&&typeof e.gltf=="object"&&e.gltf!==null&&"bin"in e&&(e.bin instanceof ArrayBuffer||ArrayBuffer.isView(e.bin))}function te(e){if(Zr(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return ti(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ei=`#version 300 es
|
|
16
|
+
*/function kr(e,t,i){let r=[],s=new Map,n=[],a=[],o=[],l=new Map,h=c=>{let m=s.get(c);return m===void 0&&(m=r.length,r.push({op:c}),s.set(c,m)),m},u=c=>{let m=l.get(c);return m===void 0&&(m=o.length,o.push({id:c}),l.set(c,m)),m},f=(c,m={})=>n.push({declaration:h(c),...m})-1,g=(c,m,v)=>a.push({id:c,type:m,value:v})-1,w=c=>({node:c,socket:"value"}),p=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(p&&typeof p=="object"){let c=Array.isArray(p.graphs)?p.graphs[p.graph??0]:p;if(c&&Array.isArray(c.nodes)){let m=Array.isArray(c.declarations)?c.declarations:[];for(let v of m)v?.op&&h(v.op);Array.isArray(c.variables)&&a.push(...c.variables);for(let v of c.events||[])v?.id&&u(v.id);for(let v of c.nodes){if(!v||typeof v!="object")continue;let S=v.op||(typeof v.declaration=="number"?m[v.declaration]?.op:"");n.push(S?{...v,declaration:h(S)}:{...v})}}}let b=(c,m,v="translation")=>v==="baseColorFactor"||v==="metallicFactor"||v==="roughnessFactor"?`/materials/${Math.max(0,m)}/pbrMetallicRoughness/${v}`:v==="emissiveFactor"||v==="alphaCutoff"?`/materials/${Math.max(0,m)}/${v}`:v==="visible"?`/nodes/${c}/extensions/KHR_node_visibility/visible`:`/nodes/${c}/${v}`,T=new Map;e.forEach((c,m)=>{typeof c?.name=="string"&&!T.has(c.name)&&T.set(c.name,m)});let x=(c,m)=>typeof c.target=="string"&&T.has(c.target)?T.get(c.target):typeof c.targetNode=="number"?c.targetNode:m,M=c=>{let m=e[c];return(typeof m?.mesh=="number"?t[m.mesh]?.primitives?.[0]?.material:0)??0};for(let c=0;c<e.length;c++){let m=e[c],v=m?.extras?.interactivity;if(!v||typeof v!="object")continue;let S=(typeof m.mesh=="number"?t[m.mesh]?.primitives?.[0]?.material:0)??0,D=P=>{let N=Array.isArray(P)?P:[P],C=[];for(let E=0;E<N.length;E++){let y=N[E];if(!y||typeof y!="object")continue;let F=y.action||"interpolate",z=typeof y.duration=="number"?y.duration:.35;if(F==="toggleTransform"){let A=y.property==="rotation"||y.property==="scale"?y.property:"translation",_=A==="rotation"?m.rotation||[0,0,0,1]:A==="scale"?m.scale||[1,1,1]:m.translation||[0,0,0],d=`/nodes/${c}/${A}`,R=g(`__toggle_${c}_${E}`,"bool",!1),G=f("variable/get",{configuration:{variable:R}}),H=f("math/not",{values:{a:w(G)}}),B=f("variable/set",{configuration:{variable:R},values:{value:w(H)}}),Z=f("pointer/interpolate",{configuration:{pointer:d},values:{value:{value:Array.isArray(y.to)?y.to:_},duration:{value:z}}}),k=f("pointer/interpolate",{configuration:{pointer:d},values:{value:{value:Array.isArray(y.from)?y.from:_},duration:{value:z}}});n[B].flows={out:{node:f("flow/branch",{values:{condition:w(G)},flows:{true:{node:Z},false:{node:k}}})}},C.push(B)}else if(F==="interpolate"){let A=y.to??y.value;if(A===void 0)continue;let _={value:{value:A},duration:{value:z}};y.from!==void 0&&(_.from={value:y.from}),C.push(f("pointer/interpolate",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:b(x(y,c),M(x(y,c)),y.property)},values:_}))}else if(F==="setProperty"){if(y.value===void 0)continue;C.push(f("pointer/set",{configuration:{pointer:typeof y.pointer=="string"?y.pointer:b(x(y,c),M(x(y,c)),y.property)},values:{value:{value:y.value}}}))}else if(F==="toggleVisibility"){let A=x(y,c),_=g(`__vis_${A}_${E}`,"bool",!0),d=f("variable/get",{configuration:{variable:_}}),R=f("math/not",{values:{a:w(d)}}),G=f("variable/set",{configuration:{variable:_},values:{value:w(R)}});n[G].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${A}/extensions/KHR_node_visibility/visible`},values:{value:w(d)}})}},C.push(G)}else if(F==="cycleMaterialColor"&&Array.isArray(y.colors)&&y.colors.length>0){let A=typeof y.duration=="number"?y.duration:.25,_=`/materials/${Math.max(0,S)}/pbrMetallicRoughness/baseColorFactor`,d=g(`__color_idx_${c}_${E}`,"int",0),R=f("variable/get",{configuration:{variable:d}}),G=f("math/add",{values:{a:w(R),b:{value:1}}}),H=f("math/rem",{values:{a:w(G),b:{value:y.colors.length}}}),B=f("variable/set",{configuration:{variable:d},values:{value:w(H)}}),Z={};for(let k=0;k<y.colors.length;k++){let Y=y.colors[k],rt=Array.isArray(Y)&&Y.length>=3?[Y[0],Y[1],Y[2],Y[3]??1]:[1,1,1,1];Z[String(k)]={node:A>0?f("pointer/interpolate",{configuration:{pointer:_},values:{value:{value:rt},duration:{value:A}}}):f("pointer/set",{configuration:{pointer:_},values:{value:{value:rt}}})}}n[B].flows={out:{node:f("flow/switch",{values:{selection:w(R)},flows:Z})}},C.push(B)}else if(F==="playAnimation")C.push(f("animation/start",{configuration:{animation:y.animation??y.clip??0}}));else if(F==="stopAnimation")C.push(f("animation/stop"));else if(F==="sendEvent"){let A={};for(let[_,d]of Object.entries(y.values||{}))A[_]={value:d};C.push(f("event/send",{configuration:{event:u(String(y.event??y.id??"custom"))},values:A}))}}if(!C.length)return null;if(C.length===1)return C[0];let L={};return C.forEach((E,y)=>{L[String(y)]={node:E}}),f("flow/sequence",{flows:L})},I=(P,N,C)=>{let L=D(N);L!==null&&f(P,{...C?{configuration:C}:{},flows:{out:{node:L}}})};if(v.onSelect&&I("pointer/onSelect",v.onSelect,{nodeIndex:c}),v.onHoverIn&&I("pointer/onHoverIn",v.onHoverIn,{nodeIndex:c}),v.onHoverOut&&I("pointer/onHoverOut",v.onHoverOut,{nodeIndex:c}),v.onStart&&I("event/onStart",v.onStart),v.onReceive&&typeof v.onReceive=="object")for(let[P,N]of Object.entries(v.onReceive))I("event/receive",N,{event:u(P)})}return n.length?{graphs:[{declarations:r,nodes:n,variables:a,events:o}],graph:0}:null}var $r='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).',Or="Security Error: client-side scripts require allow-client-scripts opt-in.",Qt="__THREE_LIVE_REGISTRY__";function mt(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Qt]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Qt,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Qt]=t}}return e[Qt]}var pt=mt().plugins;function Br(e){let t=mt().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function zr(){return mt().plugins}function ct(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function be(e,t,i,r,s){let n=1/Math.tan(t/2);e.fill(0),e[0]=n/i,e[5]=n,e[11]=-1;let a=1/(r-s);return e[10]=(s+r)*a,e[14]=2*s*r*a,e}function te(e,t,i,r){let[s,n,a]=t,[o,l,h]=r,[u,f,g]=i,w=s-u,p=n-f,b=a-g,T=Math.hypot(w,p,b);T<=1e-5?(w=0,p=0,b=1):(w/=T,p/=T,b/=T);let x=l*b-h*p,M=h*w-o*b,c=o*p-l*w;T=Math.hypot(x,M,c),T<=1e-5?(x=0,M=0,c=0):(x/=T,M/=T,c/=T);let m=p*c-b*M,v=b*x-w*c,S=w*M-p*x;return T=Math.hypot(m,v,S),T<=1e-5?(m=0,v=0,S=0):(m/=T,v/=T,S/=T),e[0]=x,e[1]=m,e[2]=w,e[3]=0,e[4]=M,e[5]=v,e[6]=p,e[7]=0,e[8]=c,e[9]=S,e[10]=b,e[11]=0,e[12]=-(x*s+M*n+c*a),e[13]=-(m*s+v*n+S*a),e[14]=-(w*s+p*n+b*a),e[15]=1,e}function yt(e,t,i){let r=t[0],s=t[1],n=t[2],a=t[3],o=t[4],l=t[5],h=t[6],u=t[7],f=t[8],g=t[9],w=t[10],p=t[11],b=t[12],T=t[13],x=t[14],M=t[15],c=i[0],m=i[1],v=i[2],S=i[3];return e[0]=c*r+m*o+v*f+S*b,e[1]=c*s+m*l+v*g+S*T,e[2]=c*n+m*h+v*w+S*x,e[3]=c*a+m*u+v*p+S*M,c=i[4],m=i[5],v=i[6],S=i[7],e[4]=c*r+m*o+v*f+S*b,e[5]=c*s+m*l+v*g+S*T,e[6]=c*n+m*h+v*w+S*x,e[7]=c*a+m*u+v*p+S*M,c=i[8],m=i[9],v=i[10],S=i[11],e[8]=c*r+m*o+v*f+S*b,e[9]=c*s+m*l+v*g+S*T,e[10]=c*n+m*h+v*w+S*x,e[11]=c*a+m*u+v*p+S*M,c=i[12],m=i[13],v=i[14],S=i[15],e[12]=c*r+m*o+v*f+S*b,e[13]=c*s+m*l+v*g+S*T,e[14]=c*n+m*h+v*w+S*x,e[15]=c*a+m*u+v*p+S*M,e}function xe(e,t,i,r){let s=t[0],n=t[1],a=t[2],o=t[3],l=s+s,h=n+n,u=a+a,f=s*l,g=s*h,w=s*u,p=n*h,b=n*u,T=a*u,x=o*l,M=o*h,c=o*u,m=r[0],v=r[1],S=r[2];return e[0]=(1-(p+T))*m,e[1]=(g+c)*m,e[2]=(w-M)*m,e[3]=0,e[4]=(g-c)*v,e[5]=(1-(f+T))*v,e[6]=(b+x)*v,e[7]=0,e[8]=(w+M)*S,e[9]=(b-x)*S,e[10]=(1-(f+p))*S,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function Et(e,t,i=0){let r=t[0],s=t[1],n=t[2],a=t[4],o=t[5],l=t[6],h=t[8],u=t[9],f=t[10],g=f*o-l*u,w=-f*a+l*h,p=u*a-o*h,b=r*g+s*w+n*p;return!b||i>0&&(!Number.isFinite(b)||Math.abs(b)<=i)||(b=1/b,e[0]=g*b,e[1]=w*b,e[2]=p*b,e[3]=(-f*s+n*u)*b,e[4]=(f*r-n*h)*b,e[5]=(-u*r+s*h)*b,e[6]=(l*s-n*o)*b,e[7]=(-l*r+n*a)*b,e[8]=(o*r-s*a)*b),e}function Vr(e,t){let i=t[0],r=t[1],s=t[2],n=t[3],a=t[4],o=t[5],l=t[6],h=t[7],u=t[8],f=t[9],g=t[10],w=t[11],p=t[12],b=t[13],T=t[14],x=t[15],M=i*o-r*a,c=i*l-s*a,m=i*h-n*a,v=r*l-s*o,S=r*h-n*o,D=s*h-n*l,I=u*b-f*p,P=u*T-g*p,N=u*x-w*p,C=f*T-g*b,L=f*x-w*b,E=g*x-w*T,y=M*E-c*L+m*C+v*N-S*P+D*I;return y?(y=1/y,e[0]=(o*E-l*L+h*C)*y,e[1]=(s*L-r*E-n*C)*y,e[2]=(b*D-T*S+x*v)*y,e[3]=(g*S-f*D-w*v)*y,e[4]=(l*N-a*E-h*P)*y,e[5]=(i*E-s*N+n*P)*y,e[6]=(T*m-p*D-x*c)*y,e[7]=(u*D-g*m+w*c)*y,e[8]=(a*L-o*N+h*I)*y,e[9]=(r*N-i*L-n*I)*y,e[10]=(p*S-b*m+x*M)*y,e[11]=(f*m-u*S-w*M)*y,e[12]=(o*P-a*C-l*I)*y,e[13]=(i*C-r*P+s*I)*y,e[14]=(b*c-p*v-T*M)*y,e[15]=(u*v-f*c+g*M)*y,e):null}function Ke(e,t,i,r,s){let n=s[0]*t+s[4]*i+s[8]*r+s[12],a=s[1]*t+s[5]*i+s[9]*r+s[13],o=s[2]*t+s[6]*i+s[10]*r+s[14],l=s[3]*t+s[7]*i+s[11]*r+s[15],h=l!==0?1/l:1;e[0]=n*h,e[1]=a*h,e[2]=o*h}function Gr(e,t,i,r,s,n,a,o,l,h,u,f,g,w,p,b,T=0){let x=h-a,M=u-o,c=f-l,m=g-a,v=w-o,S=p-l,D=s*S-n*v,I=n*m-r*S,P=r*v-s*m,N=x*D+M*I+c*P;if(N>-1e-7&&N<1e-7)return!1;let C=1/N,L=e-a,E=t-o,y=i-l,F=C*(L*D+E*I+y*P);if(F<-T||F>1+T)return!1;let z=E*c-y*M,A=y*x-L*c,_=L*M-E*x,d=C*(r*z+s*A+n*_);if(d<-T||F+d>1+T)return!1;let R=C*(m*z+v*A+S*_);if(R>1e-4&&R<b.distance){b.distance=R,b.point=[e+r*R,t+s*R,i+n*R];let G=M*S-c*v,H=c*m-x*S,B=x*v-M*m,Z=Math.hypot(G,H,B)||1;return b.normal=[G/Z,H/Z,B/Z],!0}return!1}function Hr(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let u=0;u<i;u++)r.push(ct());if(i===0)return r;let s=new Set;for(let u of e.nodes)if(Array.isArray(u.children))for(let f of u.children)s.add(f);let n=new Set,a=128,o=(u,f,g=0)=>{if(g>a||u<0||u>=i||n.has(u))return;n.add(u);let w=e.nodes[u];if(!w)return;let p=ct();if(t&&t[u])p.set(t[u]);else if(w.matrix&&w.matrix.length===16)p.set(w.matrix);else{let T=w.translation||[0,0,0],x=w.rotation||[0,0,0,1],M=w.scale||[1,1,1];xe(p,x,T,M)}let b=r[u];if(f?yt(b,f,p):b.set(p),Array.isArray(w.children))for(let T of w.children)typeof T=="number"&&o(T,b,g+1)},l=[],h=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(h&&Array.isArray(h.nodes))l.push(...h.nodes);else for(let u=0;u<i;u++)s.has(u)||l.push(u);for(let u of l)o(u,null);for(let u=0;u<i;u++)!s.has(u)&&!l.includes(u)&&o(u,null);return r}var jr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Ye(e,t,i,r){if(!i||i.bufferView===void 0)return null;let s=e.bufferViews?.[i.bufferView];if(!s)return null;let n=Number(i.count??0);if(!Number.isInteger(n)||n<=0)return null;let a=i.componentType??5126,o=jr[a];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let l=o*r,h=s.byteStride&&s.byteStride>0?s.byteStride:l,u=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(u)||u<0||h<l||u+(n-1)*h+l>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(a===5126&&h===l&&u%4===0)return new Float32Array(t,u,n*r);let f=new DataView(t),g=i.normalized===!0,w=new Float32Array(n*r);for(let p=0;p<n;p++){let b=u+p*h;for(let T=0;T<r;T++){let x=b+T*o,M;switch(a){case 5126:M=f.getFloat32(x,!0);break;case 5120:M=f.getInt8(x),g&&(M=Math.max(M/127,-1));break;case 5121:M=f.getUint8(x),g&&(M/=255);break;case 5122:M=f.getInt16(x,!0),g&&(M=Math.max(M/32767,-1));break;case 5123:M=f.getUint16(x,!0),g&&(M/=65535);break;default:M=f.getUint32(x,!0),g&&(M/=4294967295)}w[p*r+T]=M}}return w}function Wr(e,t){let i=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,s=Number(t.scale?.[0]??1),n=Number(t.scale?.[1]??1),a=Number(t.rotation??0)||0,o=Math.cos(a),l=Math.sin(a),h=(Number.isFinite(s)?s:1)*o,u=(Number.isFinite(s)?s:1)*l,f=-(Number.isFinite(n)?n:1)*l,g=(Number.isFinite(n)?n:1)*o;for(let w=0;w+1<e.length;w+=2){let p=e[w],b=e[w+1];e[w]=h*p+u*b+i,e[w+1]=f*p+g*b+r}}function ve(e,t,i,r=!0){let s=[],n=null;try{for(let[a,o]of[[35633,t],[35632,i]]){let l=e.createShader(a);if(!l){if(r)throw new Error("Shader allocation failed");return null}if(s.push(l),e.shaderSource(l,o),e.compileShader(l),e.getShaderParameter&&!e.getShaderParameter(l,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(l)}`);return null}}if(n=e.createProgram(),!n){if(r)throw new Error("Program allocation failed");return null}for(let a of s)e.attachShader(n,a);if(e.linkProgram(n),e.getProgramParameter&&!e.getProgramParameter(n,35714)){let a=r?e.getProgramInfoLog(n):null;if(e.deleteProgram?.(n),n=null,r)throw new Error(`Program link error: ${a}`);return null}return n}finally{for(let a of s)n&&e.detachShader?.(n,a),e.deleteShader?.(a)}}var Ze=["neutral","reinhard","none","aces","agx"];function Me(e){let t=String(e??"").trim().toLowerCase();return Ze.includes(t)?t:"neutral"}function Xr(e){return Ze.indexOf(Me(e))}function qr(e){return new TextDecoder().decode(e)}var Je=mt().decoders;function Kr(e,t){Je.set(e.toLowerCase(),t)}function zt(e){return Je.get(e.toLowerCase())}function Qe(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,i=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let g=i.getUint8(0);throw g===123||g===32||g===10||g===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let n=i.getUint32(8,!0),a=12,o=null,l=null;for(;a+8<=n&&a+8<=t.byteLength;){let g=i.getUint32(a,!0),w=i.getUint32(a+4,!0),p=a+8;if(p+g>t.byteLength)throw new Error(`Truncated GLB chunk: required ${p+g} bytes, buffer has ${t.byteLength}`);if(w===1313821514){let b=new Uint8Array(t,p,g),T=qr(b);o=JSON.parse(T,(x,M)=>x==="__proto__"||x==="constructor"||x==="prototype"?void 0:M)}else w===5130562&&(l=t.slice(p,p+g));a=p+g}if(!o)throw new Error("Missing JSON chunk in GLB");let h=o.extensionsRequired||[];if(h.includes("KHR_draco_mesh_compression")&&!zt("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let g of["EXT_meshopt_compression","KHR_meshopt_compression"])if(h.includes(g)&&!zt("meshopt"))throw new Error(`Model requires ${g}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(h.includes("KHR_texture_basisu")&&!zt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=l||new ArrayBuffer(0),f={gltf:o,bin:u,animations:[]};for(let g of pt)g.onParseGLB?.(f);return f}function Yr(e){return typeof e=="object"&&e!==null&&"gltf"in e&&typeof e.gltf=="object"&&e.gltf!==null&&"bin"in e&&(e.bin instanceof ArrayBuffer||ArrayBuffer.isView(e.bin))}function we(e){if(Yr(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return Qe(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ti=`#version 300 es
|
|
17
17
|
layout(location=0) in vec3 aPos;
|
|
18
18
|
layout(location=3) in vec3 aOff;
|
|
19
19
|
layout(location=1) in vec3 aNormal;
|
|
@@ -48,7 +48,7 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
48
48
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
49
49
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
50
50
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
51
|
-
}`,
|
|
51
|
+
}`,Zr=`#version 300 es
|
|
52
52
|
precision highp float;
|
|
53
53
|
in vec3 vNormal,vWorldPos;
|
|
54
54
|
in vec2 vUV;
|
|
@@ -239,19 +239,19 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
239
239
|
float outAlpha=base.a;
|
|
240
240
|
/*XRD_O*/
|
|
241
241
|
fragColor=vec4(color,outAlpha);
|
|
242
|
-
}`,
|
|
242
|
+
}`,Jr=`#version 300 es
|
|
243
243
|
layout(location=0) in vec3 aPosition;
|
|
244
244
|
uniform mat4 uMVP;
|
|
245
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
245
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Qr=`#version 300 es
|
|
246
246
|
precision highp float;
|
|
247
247
|
uniform vec4 uColorId;
|
|
248
248
|
out vec4 fragColor;
|
|
249
|
-
void main(){fragColor=uColorId;}`;function ve(e,t,i){let r={};for(let s of i)r[s]=e.getUniformLocation(t,s);return r}var ii=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function ri(){let e=ut().xrDepthShader;return{fs:Jr.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...ii,...e.uniformNames]:ii}}function es(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let i=t.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:i.startsWith("https://")||i.startsWith("blob:")?t:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Me(e,t,i,r,s,n,o,a){if(r===void 0||!t.accessors?.[r])return null;let h=Ze(t,i,t.accessors[r],n);if(!h)return null;a&&(h=h.slice(),Xr(h,a));let l=e.createBuffer();return o.push(l),e.bindBuffer(34962,l),e.bufferData(34962,h,35044),e.enableVertexAttribArray(s),e.vertexAttribPointer(s,n,5126,!1,0,0),h}function we(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function si(e,t,i){let r=ri(),s=ei,n=r.fs,o=!1;for(let h of mt)if(h.onResolveShader){let l=h.onResolveShader(t,i,s,n);l&&(s=l.vs,n=l.fs,o=!0)}let a=o?be(e,s,n):null;return{program:a,uniforms:a?ve(e,a,r.uniforms):null}}function is(e,t,i){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let s=r.length>>4,n=t.instanceColors,o=new Float32Array(s*20);for(let h=0;h<s;h++)o.set(r.subarray(h*16,h*16+16),h*20),o[h*20+16]=n?n[h*3]:1,o[h*20+17]=n?n[h*3+1]:1,o[h*20+18]=n?n[h*3+2]:1,o[h*20+19]=1;let a=e.createBuffer();i.push(a),e.bindBuffer(34962,a),e.bufferData(34962,o,35044);for(let h=0;h<5;h++)e.enableVertexAttribArray(8+h),e.vertexAttribPointer(8+h,4,5126,!1,80,h*16),e.vertexAttribDivisor(8+h,1);return!0}function rs(e,t){let i=e.materials?.[t?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let s of r){let n=s?.extensions?.KHR_texture_transform;if(n&&typeof n=="object")return n}return null}var Ns=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),ni=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function ee(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function ai(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,s=e?.extensions?.KHR_materials_clearcoat,n=o=>o!==void 0&&t[o.index]?t[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:n(i?.baseColorTexture),metallicRoughnessTexture:n(i?.metallicRoughnessTexture),normalTexture:n(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:n(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function oi(e,t,i){let r=new Set,s=n=>{n&&!r.has(n)&&(r.add(n),e.deleteTexture(n))};for(let n of t)for(let o of n.primitives){if(o.vao&&e.deleteVertexArray(o.vao),o.buffers)for(let h of o.buffers)e.deleteBuffer(h);s(o.texture),s(o.metallicRoughnessTexture),s(o.normalTexture),s(o.occlusionTexture);let a=new Set;o.customProgram&&a.add(o.customProgram);for(let h of o.programCache?.values()??[])h.program&&a.add(h.program);for(let h of a)e.deleteProgram(h)}if(i)for(let n of i)s(n)}function li(e,t,i=ni,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ss(e,t,i,r,s)}catch(n){let o=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;oi(e,o,s.gpuTextures),s.vao&&e.deleteVertexArray(s.vao);for(let a of s.buffers)e.deleteBuffer(a);throw n}}function ss(e,t,i,r,s){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n}=t,o=Vt("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(n,t);let a=t.bin,h=[];s.meshes=h;let l=[],c=n.extensions?.KHR_materials_variants;c&&Array.isArray(c.variants)&&c.variants.forEach((C,d)=>{l.push(typeof C?.name=="string"&&C.name?C.name:`Variant_${d}`)});let f=jr(n),y=[];if(Array.isArray(n.nodes))for(let C=0;C<n.nodes.length;C++){let d=n.nodes[C];d.mesh!==void 0&&n.meshes&&n.meshes[d.mesh]&&y.push({node:d,nodeIdx:C,meshIdx:d.mesh})}let g=y.length>0?y:(n.meshes||[]).map((C,d)=>({node:C,nodeIdx:-1,meshIdx:d})),u=[],b=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(n.asset?.extras?.lights)&&n.asset.extras.lights.length>0?n.asset.extras.lights:null;if(b)for(let C of b)u.push({...C,type:C.type||C.light_type||"point",innerConeAngle:C.innerConeAngle??C.inner_cone_angle,outerConeAngle:C.outerConeAngle??C.outer_cone_angle});else if(n.extensions?.KHR_lights_punctual?.lights){let C=n.extensions.KHR_lights_punctual.lights;for(let d of C){let k=d.type==="directional"?"directional":d.type==="point"?"point":d.type==="spot"?"spot":"ambient";u.push({type:k,color:d.color||[1,1,1],intensity:d.intensity!==void 0?d.intensity:1})}}if(u.length===0&&(u.push({type:"ambient",color:[1,1,1],intensity:.35}),u.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),g.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${g.length}`);let w=[];if(s.gpuTextures=w,n.textures&&n.images){if(n.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${n.textures.length}`);for(let C=0;C<n.textures.length;C++){let d=n.textures[C],k=n.images[d.source];if(k){let $=e.createTexture();e.bindTexture(3553,$),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let S=D=>{e.bindTexture(3553,$),e.texImage2D(3553,0,6408,6408,5121,D),e.generateMipmap(3553),r?.()};if(k.bufferView!==void 0){let D=n.bufferViews[k.bufferView],T=D.byteOffset||0,P=new Blob([a.slice(T,T+D.byteLength)],{type:k.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(P).then(S).catch(()=>{})}else if(k.uri){let D=es(k.uri);if(D){let T=new Image;T.crossOrigin="anonymous",T.referrerPolicy="no-referrer",T.onload=()=>S(T),T.src=D}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",k.uri)}w.push($)}else w.push(null)}}let M=[1/0,1/0,1/0],x=[-1/0,-1/0,-1/0],m=0,p=0;for(let C=0;C<g.length;C++){let d=g[C],k=n.meshes[d.meshIdx],$=d.nodeIdx>=0?f[d.nodeIdx]:ht(),S=new Float32Array(9);Pt(S,$);let D={name:d.node.name||k.name||`Mesh_${d.meshIdx}`,nodeIndex:d.nodeIdx,transform:$,normalMatrix:S,primitives:[],extras:d.node.extras||k.extras,...d.node?.visible===!1||d.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};s.mesh=D;let T=d.node?.extensions?.EXT_mesh_gpu_instancing;if(T&&T.attributes&&typeof T.attributes=="object"){let P=T.attributes,j=P.TRANSLATION!==void 0?n.accessors?.[P.TRANSLATION]:null,W=P.ROTATION!==void 0?n.accessors?.[P.ROTATION]:null,V=P.SCALE!==void 0?n.accessors?.[P.SCALE]:null,Z=P._COLOR_0!==void 0?n.accessors?.[P._COLOR_0]:null,U=Number(j?.count??W?.count??V?.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 X=(z,tt)=>{if(!z||z.bufferView===void 0||!n.bufferViews?.[z.bufferView])return null;let et=z.componentType??5126,rt=it=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${it})`),null);if(et!==5120&&et!==5121&&et!==5122&&et!==5123&&et!==5126)return rt(`componentType ${et}`);if(!(Number(z.count)>=U))return rt(`count ${z.count} < ${U}`);let J=null;try{J=Ze(n,a,{...z,count:U},tt)}catch{return rt("out of bounds")}return!J||!J.every(Number.isFinite)?rt("non-finite value"):J},O=X(j,3),G=X(W,4),F=X(V,3),H=Z?.type==="VEC4"?4:3,B=X(Z,H),K=new Float32Array(U*16),q=ht();for(let z=0;z<U;z++){let tt=O?[O[z*3],O[z*3+1],O[z*3+2]]:[0,0,0],et=G?[G[z*4],G[z*4+1],G[z*4+2],G[z*4+3]]:[0,0,0,1],rt=F?[F[z*3],F[z*3+1],F[z*3+2]]:[1,1,1];ye(q,et,tt,rt),K.set(q,z*16)}if(D.instanceMatrices=K,B){let z=new Float32Array(U*3);for(let tt=0;tt<U;tt++)z[tt*3]=B[tt*H],z[tt*3+1]=B[tt*H+1],z[tt*3+2]=B[tt*H+2];D.instanceColors=z}}}for(let P of k.primitives||[]){if(P.extensions?.KHR_draco_mesh_compression){let J=Vt("draco");J&&J.decodePrimitive(n,P,a)}let j=[],W=e.createVertexArray();s.vao=W,s.buffers=j,e.bindVertexArray(W);let V=is(e,D,j),Z=n.accessors[P.attributes.POSITION],U=Number(Z?.count??0);if(!Number.isFinite(U)||U<0||m+U>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(m+=U,Z?.min&&Z?.max){let J=it=>{for(let st=0;st<3;st++){let wt=it[12+st],nt=it[12+st];for(let ot=0;ot<3;ot++){let ct=it[ot*4+st]*Z.min[ot],lt=it[ot*4+st]*Z.max[ot];wt+=ct<lt?ct:lt,nt+=ct>lt?ct:lt}wt<M[st]&&(M[st]=wt),nt>x[st]&&(x[st]=nt)}};if(D.instanceMatrices&&D.instanceMatrices.length>=16){let it=D.instanceMatrices.length>>4,st=ht();for(let wt=0;wt<it;wt++){let nt=D.instanceMatrices.subarray(wt*16,wt*16+16);dt(st,$,nt),J(st)}}else J($)}let X=Me(e,n,a,P.attributes.POSITION,0,3,j);Me(e,n,a,P.attributes.NORMAL,1,3,j),Me(e,n,a,P.attributes.TEXCOORD_0,2,2,j,rs(n,P));let O=0,G=5123,F=null;if(P.indices!==void 0){let J=n.accessors[P.indices],it=(n.bufferViews[J.bufferView].byteOffset||0)+(J.byteOffset||0);if(O=Number(J.count??0),!Number.isFinite(O)||O<0||p+O>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);p+=O,G=J.componentType===5125?5125:5123;let st=e.createBuffer();j.push(st),e.bindBuffer(34963,st),J.componentType===5125?F=new Uint32Array(a,it,J.count):J.componentType===5121?F=Uint16Array.from(new Uint8Array(a,it,J.count)):F=it%2===0?new Uint16Array(a,it,J.count):new Uint16Array(a.slice(it,it+J.count*2)),e.bufferData(34963,F,35044)}else O=Z.count;let H={};for(let J of mt)if(J.onBuildPrimitiveVAO){let it=J.onBuildPrimitiveVAO(e,W,P,n,a);it&&(H[J.name]=it)}e.bindVertexArray(null);let B=n.materials&&P.material!==void 0?n.materials[P.material]:null,{program:K,uniforms:q}=si(e,P,B),z=ai(B,w),tt=!!(B?.extensions?.KHR_materials_transmission||H.materials?.isTransmissive),et=P.extensions?.KHR_materials_variants?.mappings,rt=Array.isArray(et)?et.filter(J=>J&&typeof J.material=="number"&&Array.isArray(J.variants)).map(J=>({material:J.material|0,variants:J.variants.map(it=>Number(it)|0)})):void 0;D.primitives.push({vao:W,instanced:V,indexCount:O,indexType:G,...z,positions:X,indices:F,buffers:j,materialIndex:P.material,defaultMaterialIndex:P.material,variantMappings:rt,primitiveDef:P,programCache:new Map([[P.material??-1,{program:K,uniforms:q}]]),pluginData:H,customProgram:K,customUniforms:q,isTransmissive:tt})}h.push(D)}isFinite(M[0])||(M=[-1,-1,-1]),isFinite(x[0])||(x=[1,1,1]);let v=[(M[0]+x[0])/2,(M[1]+x[1])/2,(M[2]+x[2])/2],R=x[0]-M[0],L=x[1]-M[1],I=x[2]-M[2],N=Math.max(Math.hypot(R,L,I)/2,.5),_=[M[0],M[1],M[2]],A=[x[0],x[1],x[2]],E=t.animations;if(!E){for(let C of mt)if(C.onParseGLB?.(t),t.animations){E=t.animations;break}}return E||(E=[]),{meshes:h,bounds:{center:v,radius:N,min:_,max:A},lights:u,animations:E,worldMatrices:f,gpuTextures:w,availableVariants:l}}function Gt(e){let t=e.customTarget||e.bounds.center,i=e.currDistance*Math.cos(e.currPhi);return[t[0]+i*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+i*Math.cos(e.currTheta)]}var hi=class{constructor(e,t,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=ht(),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=ht(),this.viewMatrix=ht(),this.activeViewMatrix=null,this.modelMatrix=ht(),this.mvpMatrix=ht(),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:ht(),rawValueToMeters:.001,format:0},this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),r=a}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let n=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!n:n&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=we(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=xe(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 o=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!o)throw new Error("WebGL2 not supported");this.gl=o,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Yr(e,t)}static getDecoder(e){return Vt(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=ri();this.renderProg=be(e,ei,t.fs),this.pickProg=be(e,Qr,ts),this.uRender=ve(e,this.renderProg,t.uniforms),this.uPick=ve(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of mt)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:n,worldMatrices:o,gpuTextures:a,availableVariants:h}=li(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=n||[],this.worldMatrices=o||[],this.gpuTextures=a||[],this.availableVariants=h||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of mt)f.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let l=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;l!==void 0&&(this.exposure=we(l));let c=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;c!==void 0&&(this.envIntensity=Math.max(0,Number(c)||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(ti(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of mt)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(te(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=te(e),{meshes:r}=li(this.gl,i,ni,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],Pt(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),Pt(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],n=[],o=[],a=[],h=[];for(let l of this.lights){let c=l.color||[1,1,1],f=l.intensity!==void 0?l.intensity:1;if(l.type==="ambient")i=[c[0]*f,c[1]*f,c[2]*f];else if(l.type==="directional"&&r.length<6){let y=l.direction||[.5,1,.8];r.push(y[0],y[1],y[2]),s.push(c[0]*f,c[1]*f,c[2]*f)}else if((l.type==="point"||l.type==="spot")&&n.length<6){let y=l.position||[0,0,0];if(n.push(y[0],y[1],y[2]),o.push(c[0]*f,c[1]*f,c[2]*f),l.type==="spot"){let g=l.direction||[0,-1,0],u=Math.max(.01,Math.min(Math.PI/2,l.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(u-1e-4,l.innerConeAngle??0));a.push(g[0],g[1],g[2]),h.push(Math.cos(b),Math.cos(u))}else a.push(0,-1,0),h.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,n.length/3),n.length>0&&(t.uniform3fv(e.uPointLightPos,n),t.uniform3fv(e.uPointLightColor,o),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,a),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,h)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=we(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=xe(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of mt)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of mt)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,i)=>{let r=this.meshes.flatMap(l=>l.primitives.filter(c=>c.materialIndex===i||e.length===1&&c.materialIndex===void 0)),s=r[0],n=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],o=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,a=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,h={baseColorFactor:n,metallicFactor:o,roughnessFactor:a,setBaseColorFactor:l=>{let c=[l[0],l[1],l[2],l[3]??1];h.baseColorFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=c);for(let f of r)f.baseColor=c;this.render()},setMetallicFactor:l=>{h.metallicFactor=l,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=l);for(let c of r)c.metallic=l;this.render()},setRoughnessFactor:l=>{h.roughnessFactor=l,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=l);for(let c of r)c.roughness=l;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:h}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",i=-1;if(t)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(e),i<0)return!1;this.activeVariantName=e}let r=this.gltf?.materials;if(!Array.isArray(r))return t;for(let s of this.meshes)for(let n of s.primitives){let o=n.defaultMaterialIndex;if(!t&&Array.isArray(n.variantMappings)){for(let h of n.variantMappings)if(Array.isArray(h.variants)&&h.variants.includes(i)){o=h.material;break}}let a=o!==void 0?r[o]:void 0;n.materialIndex=a?o:void 0,Object.assign(n,ai(a,this.gpuTextures)),this.applyPrimitiveProgram(n,n.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,s=e.programCache.get(r);s||(s=si(this.gl,{...e.primitiveDef,material:t},i),e.programCache.set(r,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of mt)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let i=ht();dt(i,this.projMatrix,this.viewMatrix);let[r,s,n]=e,o=t?t[0]:0,a=t?t[1]:0,h=t?t[2]:0,l=this.modelRootMatrix;l&&(r=l[0]*e[0]+l[4]*e[1]+l[8]*e[2]+l[12],s=l[1]*e[0]+l[5]*e[1]+l[9]*e[2]+l[13],n=l[2]*e[0]+l[6]*e[1]+l[10]*e[2]+l[14],t&&(o=l[0]*t[0]+l[4]*t[1]+l[8]*t[2],a=l[1]*t[0]+l[5]*t[1]+l[9]*t[2],h=l[2]*t[0]+l[6]*t[1]+l[10]*t[2]));let c=i[0]*r+i[4]*s+i[8]*n+i[12],f=i[1]*r+i[5]*s+i[9]*n+i[13],y=i[2]*r+i[6]*s+i[10]*n+i[14],g=i[3]*r+i[7]*s+i[11]*n+i[15];if(g<=1e-4)return{x:0,y:0,z:1,visible:!1};let u=c/g,b=f/g,w=y/g,M=this.canvas.getBoundingClientRect(),x=M.width||this.canvas.clientWidth||this.canvas.width||300,m=M.height||this.canvas.clientHeight||this.canvas.height||150,p=(u*.5+.5)*x,v=(-b*.5+.5)*m,R=u>=-1.1&&u<=1.1&&b>=-1.1&&b<=1.1&&w>=-1&&w<=1;if(R&&t){let[L,I,N]=Gt(this),_=[r-L,s-I,n-N];o*_[0]+a*_[1]+h*_[2]>.05&&(R=!1)}return{x:p,y:v,z:w,visible:R}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=i=>{i.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,e.setPointerCapture(i.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},s=i.clientX-r.x,n=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(s,n),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let o=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],a=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],h=this.customTarget?[...this.customTarget]:[...this.bounds.center],l=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;h[0]+=(-s*o[0]+n*a[0])*l,h[1]+=(-s*o[1]+n*a[1])*l,h[2]+=(-s*o[2]+n*a[2])*l,this.customTarget=h}else this.targetTheta=this.clampTheta(this.targetTheta-s*.008),this.targetPhi=this.clampPhi(this.targetPhi+n*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=t(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=e.getBoundingClientRect(),s=Math.floor((i.clientX-r.left)*(e.width/Math.max(r.width,1))),n=Math.floor((i.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(s,n,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=t();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),i.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(i,r,s)=>{this[s]&&(i.removeEventListener(r,this[s]),this[s]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,n=i.height||300,o=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),a=r.height>0?Math.floor((t-r.top)*(n/r.height)):Math.floor(t);return this.performMeshPick(o,a,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),n=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let o=ht();dt(o,this.projMatrix,this.viewMatrix);let a=[],h=Math.max(0,Math.min(s-1,e)),l=Math.max(0,Math.min(n-1,n-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==n)&&this.resizePickingFbo(s,n),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,n),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let v=0;v<this.meshes.length;v++){let R=this.meshes[v];if(R.visible===!1||R.isPluginMesh)continue;let L=v+1,I=(L&255)/255,N=(L>>8&255)/255,_=(L>>16&255)/255;r.uniform4f(this.uPick.uColorId,I,N,_,1),dt(this.modelMatrix,this.modelRootMatrix,R.transform);let A=R.instanceMatrices;if(A&&A.length>=16){let E=A.length>>4,C=ht();for(let d of R.primitives){r.bindVertexArray(d.vao);for(let k=0;k<E;k++)dt(C,this.modelMatrix,A.subarray(k*16,k*16+16)),dt(this.mvpMatrix,o,C),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),ee(r,d)}}else{dt(this.mvpMatrix,o,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let E of R.primitives)r.bindVertexArray(E.vao),ee(r,E)}}let m=new Uint8Array(4);r.readPixels(h,l,1,1,6408,5121,m),r.bindFramebuffer(36160,null);let p=m[0]+(m[1]<<8)+(m[2]<<16);p>0&&p<=this.meshes.length&&(a=[this.meshes[p-1]])}a.length===0&&(a=this.meshes.filter(m=>m.visible!==!1));let c=null,f=1/0,y=[0,0,0],g=[0,1,0],[u,b,w]=Gt(this),M=ht();for(let m of a){dt(M,this.modelRootMatrix,m.transform);let p=m.instanceMatrices,v=p&&p.length>=16?p.length>>4:1;for(let R=0;R<v;R++){p&&p.length>=16?dt(this.modelMatrix,M,p.subarray(R*16,R*16+16)):this.modelMatrix.set(M),dt(this.mvpMatrix,o,this.modelMatrix);let L=ht();if(!Gr(L,this.mvpMatrix))continue;let I=(h+.5)/s*2-1,N=(l+.5)/n*2-1,_=[0,0,0],A=[0,0,0];Ye(_,I,N,-1,L),Ye(A,I,N,1,L);let E=A[0]-_[0],C=A[1]-_[1],d=A[2]-_[2],k=Math.hypot(E,C,d)||1,$=E/k,S=C/k,D=d/k,T={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((P=>{for(let j of m.primitives){if(!j.positions)continue;let W=j.positions,V=j.indices,Z=Math.floor(V?V.length/3:W.length/9);for(let U=0;U<Z;U++){let X=V?V[U*3]:U*3,O=V?V[U*3+1]:U*3+1,G=V?V[U*3+2]:U*3+2;Hr(_[0],_[1],_[2],$,S,D,W[X*3],W[X*3+1],W[X*3+2],W[O*3],W[O*3+1],W[O*3+2],W[G*3],W[G*3+1],W[G*3+2],T,P)}}})(1e-4),isFinite(T.distance)){let P=T.point[0],j=T.point[1],W=T.point[2],V=this.modelMatrix,Z=V[0]*P+V[4]*j+V[8]*W+V[12],U=V[1]*P+V[5]*j+V[9]*W+V[13],X=V[2]*P+V[6]*j+V[10]*W+V[14],O=Z-u,G=U-b,F=X-w,H=Math.hypot(O,G,F);if(H<f){Pt(this.normalMatrix,this.modelMatrix);let B=this.normalMatrix,K=T.normal[0],q=T.normal[1],z=T.normal[2],tt=B[0]*K+B[3]*q+B[6]*z,et=B[1]*K+B[4]*q+B[7]*z,rt=B[2]*K+B[5]*q+B[8]*z,J=Math.hypot(tt,et,rt)||1;tt/=J,et/=J,rt/=J,tt*O+et*G+rt*F>0&&(tt=-tt,et=-et,rt=-rt),c=m,f=Math.round(H*1e3)/1e3,y=[Math.round(Z*1e3)/1e3,Math.round(U*1e3)/1e3,Math.round(X*1e3)/1e3],g=[Math.round(tt*1e3)/1e3,Math.round(et*1e3)/1e3,Math.round(rt*1e3)/1e3]}}}}if(!c)return null;let x={meshIndex:this.meshes.indexOf(c),meshName:c.name,nodeIndex:c.nodeIndex,distance:f,hitPoint:y,normal:g,screenX:e,screenY:t};if(i){for(let m of mt)m.onMeshSelect?.(this,x);this.opts.onMeshClick&&this.opts.onMeshClick(x),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:x}))}return x}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,n=r?Math.max(1,t-i):i,o=(s+.5)/n*2-1;return Math.floor((o*.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 i=this.customTarget||this.bounds.center;Qt(this.viewMatrix,Gt(this),i,[0,1,0]),dt(this.mvpMatrix,this.projMatrix,this.viewMatrix),Pt(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let i of mt)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of mt)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let n of mt)n.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let n of mt)n.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let n={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(n),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:n}))}}renderXRView(e,t,i,r,s=!0,n=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let o=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,h=e?.transform?.position,l=h?[h.x,h.y,h.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:o,projMatrix:a,eyePos:l,viewport:r,eye:e?.eye||"none",clear:n>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let x=Math.max(2,this.canvas.width||2),m=Math.max(1,this.canvas.height||1),p=Math.max(1,Math.floor(x*.5)),v=Math.max(1,x-p),R=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),L=this.customTarget||this.bounds.center,[I,N,_]=Gt(this),A=Math.cos(this.currTheta),E=-Math.sin(this.currTheta),C=.032,d=ht(),k=ht(),$=[I-A*C,N,_-E*C],S=[L[0]-A*C*.25,L[1],L[2]-E*C*.25];ge(d,this.fov,p/m,.1,R),Qt(k,$,S,[0,1,0]);let D=ht(),T=ht(),P=[I+A*C,N,_+E*C],j=[L[0]+A*C*.25,L[1],L[2]+E*C*.25];ge(D,this.fov,v/m,.1,R),Qt(T,P,j,[0,1,0]),this.render({viewMatrix:k,projMatrix:d,eyePos:$,viewport:[0,0,p,m],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:T,projMatrix:D,eyePos:P,viewport:[p,0,v,m],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,x,m);return}let t=this.gl,i=0,r=0,s=this.canvas.width,n=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],n=e.viewport[3],t.viewport(i,r,s,n)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16640));let o=ht(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,dt(o,e?.projMatrix??this.projMatrix,a);let h=ut().xrDepthShader,l=qr(this.toneMapping),[c,f,y]=e?e.eyePos:Gt(this);for(let x of mt)x.onBeforeDrawScene?.(this,t,o,[c,f,y],l);let g=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&g===0)return;let u=e?.eye||"none",b=!1,w=g>0?[...this.backdropMeshes,...this.meshes]:this.meshes,M=x=>{for(let m=0;m<w.length;m++){let p=w[m];if(p.visible===!1)continue;let v=this.selectedMeshName!==""&&p.name===this.selectedMeshName;m<g||p.worldSpace===!0||p.name==="__xr_reticle__"?this.modelMatrix.set(p.transform):dt(this.modelMatrix,this.modelRootMatrix,p.transform),dt(this.mvpMatrix,o,this.modelMatrix),Pt(p.normalMatrix,this.modelMatrix);let R=p.extras?.xr?.stereo||p.userData?.xr?.stereo,L=0,I=0,N=1,_=1;R==="sbs"?(N=.5,L=u==="right"?.5:0):R==="ou"&&(_=.5,I=u==="right"?.5:0);for(let A of p.primitives){let E=!!A.isTransmissive;if(!x&&E){b=!0;continue}if(x&&!E)continue;let C=A.customProgram||this.renderProg,d=A.customUniforms||this.uRender;t.useProgram(C),t.vertexAttrib3f(3,0,0,0),d.uInstanced&&t.uniform1i(d.uInstanced,0),t.uniform1i(d.uToneMapping,l),t.uniform1f(d.uEnvIntensity,this.envIntensity),d.uExposure&&t.uniform1f(d.uExposure,this.exposure),t.uniform3f(d.uCameraPos,c,f,y),t.uniform1f(d.uEmissive,v?1:0),t.uniformMatrix4fv(d.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(d.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(d.uNormalMatrix,!1,p.normalMatrix),d.uUvTransform&&t.uniform4f(d.uUvTransform,L,I,N,_),d.uViewportSize&&t.uniform2f(d.uViewportSize,Math.max(1,s),Math.max(1,n)),h?.bind(t,d,this.xrDepthState,a,[i,r,Math.max(1,s),Math.max(1,n)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(d.uEnvironmentMap,4),t.uniform1i(d.uHasEnvironmentMap,1)):t.uniform1i(d.uHasEnvironmentMap,0),this.bindLights(d),d.uSectionEnabled&&t.uniform1i(d.uSectionEnabled,0);for(let $ of mt)$.onBeforeDrawPrimitive?.(t,C,A,p,this.worldMatrices||[],this.gltf);t.uniform4fv(d.uBaseColor,A.baseColor),t.uniform1f(d.uMetallic,A.metallic),t.uniform1f(d.uRoughness,A.roughness),d.uClearcoat&&t.uniform2f(d.uClearcoat,A.clearcoat??0,A.clearcoatRoughness??.04),A.texture?(t.activeTexture(33984),t.bindTexture(3553,A.texture),t.uniform1i(d.uBaseColorTexture,0),t.uniform1i(d.uHasTexture,1)):t.uniform1i(d.uHasTexture,0),A.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,A.metallicRoughnessTexture),t.uniform1i(d.uMetallicRoughnessTexture,1),t.uniform1i(d.uHasMetallicRoughnessTexture,1)):t.uniform1i(d.uHasMetallicRoughnessTexture,0),A.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,A.normalTexture),t.uniform1i(d.uNormalTexture,2),t.uniform1i(d.uHasNormalTexture,1),t.uniform1f(d.uNormalScale,A.normalScale)):t.uniform1i(d.uHasNormalTexture,0),A.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,A.occlusionTexture),t.uniform1i(d.uOcclusionTexture,3),t.uniform1i(d.uHasOcclusionTexture,1),t.uniform1f(d.uOcclusionStrength,A.occlusionStrength)):t.uniform1i(d.uHasOcclusionTexture,0),t.bindVertexArray(A.vao);let k=p.instanceMatrices;if(A.instanceCount!==void 0)t.drawElementsInstanced(4,A.indexCount,A.indexType,0,A.instanceCount);else if(k&&k.length>=16&&A.instanced&&d.uInstanced&&d.uViewProj){let $=k.length>>4;t.uniform1i(d.uInstanced,1),t.uniformMatrix4fv(d.uViewProj,!1,o),A.indices?t.drawElementsInstanced(4,A.indexCount,A.indexType,0,$):t.drawArraysInstanced(4,0,A.indexCount,$),t.uniform1i(d.uInstanced,0)}else if(k&&k.length>=16){let $=k.length>>4,S=p.instanceColors,D=ht(),T=new Float32Array(9),P=[A.baseColor[0],A.baseColor[1],A.baseColor[2],A.baseColor[3]];for(let j=0;j<$;j++)dt(D,this.modelMatrix,k.subarray(j*16,j*16+16)),dt(this.mvpMatrix,o,D),Pt(T,D),t.uniformMatrix4fv(d.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(d.uModel,!1,D),t.uniformMatrix3fv(d.uNormalMatrix,!1,T),S&&(P[0]=A.baseColor[0]*S[j*3],P[1]=A.baseColor[1]*S[j*3+1],P[2]=A.baseColor[2]*S[j*3+2],P[3]=A.baseColor[3],t.uniform4fv(d.uBaseColor,P)),ee(t,A)}else ee(t,A)}}};if(M(!1),b){for(let x of mt)x.onBeforeTransmissivePass?.(t,this);M(!0)}for(let x of mt)x.onAfterRender?.(t,this,o,e?.eye??"none",[i,r,s,n],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){oi(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 mt)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()}};hi.registerPlugin=Br,hi.getRegisteredPlugins=$r;function ns(e){return e+3&-4}var Q=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function ui(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function ci(e,t=0){let[i,r,s,,n,o,a,,h,l,c,,f,y,g]=Array.from({length:15},(T,P)=>Q(e[t+P],P%5===0?1:0)),u=Math.hypot(i,r,s),b=Math.hypot(n,o,a),w=Math.hypot(h,l,c);i*(o*c-l*a)-n*(r*c-l*s)+h*(r*a-o*s)<0&&(u=-u);let M=Math.abs(u)>1e-8?1/u:0,x=Math.abs(b)>1e-8?1/b:0,m=Math.abs(w)>1e-8?1/w:0,p=i*M,v=r*M,R=s*M,L=n*x,I=o*x,N=a*x,_=h*m,A=l*m,E=c*m,C=p+I+E,d=0,k=0,$=0,S=1;if(C>0){let T=.5/Math.sqrt(C+1);S=.25/T,d=(N-A)*T,k=(_-R)*T,$=(v-L)*T}else if(p>I&&p>E){let T=2*Math.sqrt(Math.max(0,1+p-I-E));T>1e-8&&(S=(N-A)/T,d=.25*T,k=(L+v)/T,$=(_+R)/T)}else if(I>E){let T=2*Math.sqrt(Math.max(0,1+I-p-E));T>1e-8&&(S=(_-R)/T,d=(L+v)/T,k=.25*T,$=(N+A)/T)}else{let T=2*Math.sqrt(Math.max(0,1+E-p-I));T>1e-8&&(S=(v-L)/T,d=(_+R)/T,k=(N+A)/T,$=.25*T)}let D=Math.hypot(d,k,$,S);return D>1e-8&&Number.isFinite(D)?(d/=D,k/=D,$/=D,S/=D):(d=0,k=0,$=0,S=1),{t:[f,y,g],r:[d,k,$,S],s:[u,b,w]}}function as(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var _t=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function mi(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let i=typeof t=="string"?{preset:t}:t,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,s=typeof i.preset=="string"?i.preset:void 0;return!r&&!s?null:{ae:i,src:r,preset:s,volume:_t(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function Ht(e,t){return fi(e,t)[0]}function fi(e,t){e.updateMatrixWorld(!0);let i=[],r=0,s=[],n=[],o=[],a=[],h=new Set,l=[],c=[],f=new Map,y=[],g=[],u=[],b=new Map,w=[],M=[];function x(S){let D=f.get(S);if(D!==void 0)return D;D=c.length,f.set(S,D);let T=S,P=T.color?.r??.8,j=T.color?.g??.8,W=T.color?.b??.8,V=T.opacity??1,Z={baseColorFactor:[P,j,W,V],metallicFactor:T.metalness??0,roughnessFactor:T.roughness??.5},U={};if(T.map){let G="";typeof T.map=="string"?G=T.map:typeof T.map.source=="string"?G=T.map.source:typeof T.map.image=="string"&&(G=T.map.image);let F=G.trim(),H=F&&!/[\x00-\x1f\x7f\\]|\.\./.test(F)&&(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(F)||!F.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(F))?F:null;if(H){let K=b.get(H);if(K===void 0){let q=y.length;y.push({uri:H}),g.length===0&&g.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),K=u.length,u.push({sampler:0,source:q}),b.set(H,K)}Z.baseColorTexture={index:K}}let B=T.map.avgColor;Array.isArray(B)&&B.length>=3&&(U.avgColor=[B[0],B[1],B[2]])}let X={name:T.name||"",pbrMetallicRoughness:Z,doubleSided:T.side===2||!!T.doubleSided,...Object.keys(U).length>0?{extras:U}:{}};if(T.emissive&&(T.emissive.r>0||T.emissive.g>0||T.emissive.b>0)){let G=T.emissiveIntensity??1;X.emissiveFactor=[T.emissive.r*G,T.emissive.g*G,T.emissive.b*G]}let O={};return T.clearcoat&&T.clearcoat>0&&(O.KHR_materials_clearcoat={clearcoatFactor:T.clearcoat,clearcoatRoughnessFactor:T.clearcoatRoughness||0}),T.sheen&&T.sheen>0&&(O.KHR_materials_sheen={sheenColorFactor:T.sheenColor?[T.sheenColor.r,T.sheenColor.g,T.sheenColor.b]:[1,1,1],sheenRoughnessFactor:T.sheenRoughness||0}),T.transmission&&T.transmission>0&&(O.KHR_materials_transmission={transmissionFactor:T.transmission}),T.thickness&&T.thickness>0&&(O.KHR_materials_volume={thicknessFactor:T.thickness,attenuationDistance:T.attenuationDistance??1/0,attenuationColor:T.attenuationColor?[T.attenuationColor.r,T.attenuationColor.g,T.attenuationColor.b]:[1,1,1]}),T.ior!==void 0&&T.ior!==1.5&&(O.KHR_materials_ior={ior:T.ior}),T.dispersion&&T.dispersion>0&&(O.KHR_materials_dispersion={dispersion:T.dispersion}),T.iridescence&&T.iridescence>0&&(O.KHR_materials_iridescence={iridescenceFactor:T.iridescence,iridescenceIor:T.iridescenceIOR??1.3}),Object.keys(O).length>0&&(X.extensions=O),c.push(X),D}function m(S,D){let T=new Uint8Array(S.buffer,S.byteOffset,S.byteLength),P=ns(T.byteLength),j=new Uint8Array(P);j.set(T),i.push(j);let W=s.length;return s.push({buffer:0,byteOffset:r,byteLength:T.byteLength,target:D}),r+=P,W}function p(S,D,T,P,j,W,V){let Z=m(S,T),U=n.length,X={bufferView:Z,byteOffset:0,componentType:P,count:j,type:D};return W&&(X.min=W),V&&(X.max=V),n.push(X),U}e.traverse(S=>{if(S.isLight||S.color&&S.intensity!==void 0){let D=S.matrixWorld?.elements,T=Q(D?D[12]:S.position?.x,0),P=Q(D?D[13]:S.position?.y,0),j=Q(D?D[14]:S.position?.z,0),W=S.target,V=W?.parent?W?.matrixWorld?.elements:void 0,Z=Q(V?V[12]:W?.position?.x,0),U=Q(V?V[13]:W?.position?.y,0),X=Q(V?V[14]:W?.position?.z,0),O=Z-T,G=U-P,F=X-j,H=Math.hypot(O,G,F),B=Math.max(.01,Math.min(Math.PI/2,Q(S.angle,Math.PI/3))),K=Math.max(0,Math.min(1,Q(S.penumbra,0)));M.push({type:S.type,color:[S.color.r,S.color.g,S.color.b],intensity:S.intensity,position:[T,P,j],...S.type==="spot"?{direction:H>1e-6?[O/H,G/H,F/H]:[0,-1,0],outerConeAngle:B,innerConeAngle:Math.max(0,B*(1-K)),range:Math.max(0,Q(S.distance,0))}:S.type==="point"?{range:Math.max(0,Q(S.distance,0))}:{}})}});let v=[],R=new Set([e]),L=[];if(Array.isArray(e.children))for(let S=e.children.length-1;S>=0;S--)L.push({obj:e.children[S],parentKids:v});for(;L.length>0;){let{obj:S,parentKids:D}=L.pop();if(!S||typeof S!="object"||R.has(S))continue;R.add(S),S._bakeAuthorGeometry?.(),ut().materializeDeclarativeGeometry?.(S);let T=!!(S.userData&&(S.userData.xr&&typeof S.userData.xr=="object"&&Object.keys(S.userData.xr).length>0||S.userData.interactivity&&typeof S.userData.interactivity=="object"&&Object.keys(S.userData.interactivity).length>0)),P={name:S.name||(T?`Node_${a.length}`:"")},j=Q(S.position?.x,0),W=Q(S.position?.y,0),V=Q(S.position?.z,0),Z=Q(S.quaternion?.x,0),U=Q(S.quaternion?.y,0),X=Q(S.quaternion?.z,0),O=Q(S.quaternion?.w,1),G=Q(S.scale?.x,1),F=Q(S.scale?.y,1),H=Q(S.scale?.z,1);if((j||W||V)&&(P.translation=[j,W,V]),(Z||U||X||O!==1)&&(P.rotation=[Z,U,X,O]),(G!==1||F!==1||H!==1)&&(P.scale=[G,F,H]),S.visible===!1&&(P.extensions={...P.extensions||{},KHR_node_visibility:{visible:!1}},h.add("KHR_node_visibility")),S.userData&&Object.keys(S.userData).length>0&&(P.extras=JSON.parse(JSON.stringify(S.userData,(q,z)=>{if(!(q==="__proto__"||q==="prototype"||q==="constructor"))return typeof z=="function"?void 0:z})),S.userData.xr)){let q=as(S.userData.xr);P.extensions={...P.extensions||{},MOZ_hubs_components:q,ANDROID_xr_scenecore:q},ut().xrTraitSerializer?.gltfNode(P,S.userData.xr),h.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(S.geometry){let q=S.geometry,z=q.attributes.position;if(z&&z.count>0){let tt=[1/0,1/0,1/0],et=[-1/0,-1/0,-1/0];for(let nt=0;nt<z.count;nt++){let ot=z.getX(nt),ct=z.getY(nt),lt=z.getZ(nt);ot<tt[0]&&(tt[0]=ot),ot>et[0]&&(et[0]=ot),ct<tt[1]&&(tt[1]=ct),ct>et[1]&&(et[1]=ct),lt<tt[2]&&(tt[2]=lt),lt>et[2]&&(et[2]=lt)}let rt={attributes:{POSITION:p(z.array,"VEC3",34962,5126,z.count,tt,et)}};if(q.attributes.normal&&(rt.attributes.NORMAL=p(q.attributes.normal.array,"VEC3",34962,5126,q.attributes.normal.count)),q.attributes.uv&&(rt.attributes.TEXCOORD_0=p(q.attributes.uv.array,"VEC2",34962,5126,q.attributes.uv.count)),q.index){let nt=q.index.array instanceof Uint32Array;rt.indices=p(q.index.array,"SCALAR",34963,nt?5125:5123,q.index.count)}let J=Array.isArray(S.material)?S.material[0]:S.material;J&&(rt.material=x(J));let it=S.userData?.variants;if(it&&typeof it=="object"){let nt=new Map;for(let ot of Object.keys(it)){if(!ot||ot==="__proto__"||ot==="constructor"||ot==="prototype")continue;let ct=it[ot];if(!ct||typeof ct!="object")continue;let lt=w.indexOf(ot);if(lt===-1&&w.length<256&&(lt=w.length,w.push(ot)),lt===-1)continue;let Lt=x(ct),It=nt.get(Lt);It||(It=[],nt.set(Lt,It)),It.push(lt)}if(nt.size>0){let ot=[];for(let[ct,lt]of nt.entries())ot.push({material:ct,variants:lt});rt.extensions={...rt.extensions||{},KHR_materials_variants:{mappings:ot}},h.add("KHR_materials_variants")}}let st=S;if(st.isInstancedMesh&&typeof st.count=="number"&&st.count>0&&st.instanceMatrix?.array){let nt=Math.min(1e4,Math.floor(st.count)),ot=st.instanceMatrix.array,ct=new Float32Array(nt*3),lt=new Float32Array(nt*4),Lt=new Float32Array(nt*3);for(let bt=0;bt<nt;bt++){let{t:pe,r:Zt,s:de}=ci(ot,bt*16);ct[bt*3]=pe[0],ct[bt*3+1]=pe[1],ct[bt*3+2]=pe[2],lt[bt*4]=Zt[0],lt[bt*4+1]=Zt[1],lt[bt*4+2]=Zt[2],lt[bt*4+3]=Zt[3],Lt[bt*3]=de[0],Lt[bt*3+1]=de[1],Lt[bt*3+2]=de[2]}let It={TRANSLATION:p(ct,"VEC3",0,5126,nt),ROTATION:p(lt,"VEC4",0,5126,nt),SCALE:p(Lt,"VEC3",0,5126,nt)};if(st.instanceColor?.array&&st.instanceColor.array.length>=nt*3){let bt=new Float32Array(st.instanceColor.array.subarray(0,nt*3));It._COLOR_0=p(bt,"VEC3",0,5126,nt)}P.extensions={...P.extensions||{},EXT_mesh_gpu_instancing:{attributes:It}},h.add("EXT_mesh_gpu_instancing")}let wt=o.length;o.push({primitives:[rt],name:S.name,...P.extras?{extras:P.extras}:{}}),P.mesh=wt}}let B=a.length;a.push(P),l.push(S),D.push(B);let K=S.children;if(Array.isArray(K)&&K.length>0){let q=[];P.children=q;for(let z=K.length-1;z>=0;z--)L.push({obj:K[z],parentKids:q})}}for(let S=0;S<a.length;S++){let D=a[S];D.children&&D.children.length===0?delete D.children:D.children&&D.children.length>0&&(D.extras?.xr?.lod||D.extensions?.ANDROID_xr_scenecore?.lod||l[S]?.isLOD)&&(D.extensions={...D.extensions||{},MSFT_lod:{ids:[...D.children]}},h.add("MSFT_lod"))}let I=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),N=[];if(typeof I=="function"&&l.length>0){let S=t?.duration??4,D=t?.fps??15,T=Math.max(2,Math.round(S*D)+1),P=new Float32Array(T),j=l.map(F=>[Q(F.position?.x,0),Q(F.position?.y,0),Q(F.position?.z,0),Q(F.quaternion?.x,0),Q(F.quaternion?.y,0),Q(F.quaternion?.z,0),Q(F.quaternion?.w,1),Q(F.scale?.x,1),Q(F.scale?.y,1),Q(F.scale?.z,1)]),W=l.map(()=>new Float32Array(T*3)),V=l.map(()=>new Float32Array(T*4)),Z=l.map(()=>new Float32Array(T*3));for(let F=0;F<T;F++){let H=F/(T-1)*S;P[F]=H;try{I(H)}catch{}for(let B=0;B<l.length;B++){let K=l[B];W[B][F*3]=Q(K.position?.x,0),W[B][F*3+1]=Q(K.position?.y,0),W[B][F*3+2]=Q(K.position?.z,0);let q=Q(K.quaternion?.x,0),z=Q(K.quaternion?.y,0),tt=Q(K.quaternion?.z,0),et=Q(K.quaternion?.w,1),rt=Math.hypot(q,z,tt,et)||1;if(q/=rt,z/=rt,tt/=rt,et/=rt,F>0){let J=(F-1)*4,it=V[B];it[J]*q+it[J+1]*z+it[J+2]*tt+it[J+3]*et<0&&(q=-q,z=-z,tt=-tt,et=-et)}V[B][F*4]=q,V[B][F*4+1]=z,V[B][F*4+2]=tt,V[B][F*4+3]=et,Z[B][F*3]=Q(K.scale?.x,1),Z[B][F*3+1]=Q(K.scale?.y,1),Z[B][F*3+2]=Q(K.scale?.z,1)}}for(let F=0;F<l.length;F++){let H=l[F],B=j[F];H.position?.set(B[0],B[1],B[2]),H.quaternion?.set(B[3],B[4],B[5],B[6]),H.scale?.set(B[7],B[8],B[9])}e.updateMatrixWorld(!0);let U=null,X=()=>(U===null&&(U=p(P,"SCALAR",0,5126,T,[0],[S])),U),O=[],G=[];for(let F=0;F<l.length;F++){let H=j[F],B=(q,z,tt)=>q.some((et,rt)=>Math.abs(et-H[tt+rt%z])>1e-4),K=(q,z,tt,et)=>{q&&G.push({sampler:O.push({input:X(),interpolation:"LINEAR",output:p(z,tt,0,5126,T)})-1,target:{node:F,path:et}})};K(B(W[F],3,0),W[F],"VEC3","translation"),K(B(V[F],4,3),V[F],"VEC4","rotation"),K(B(Z[F],3,7),Z[F],"VEC3","scale")}G.length>0&&N.push({name:"ProceduralLoop",samplers:O,channels:G})}let _=zr(a,o,e.userData),A=[],E=[],C=[];for(let S=0;S<a.length;S++){let D=a[S],T=mi(D.extras?.xr);if(!T)continue;let{ae:P,src:j,preset:W,volume:V,loop:Z,isGlobal:U}=T,X=D.name||`Node_${S}`,O=E.length;E.push({name:`${X}_source`,gain:V,loop:Z,autoPlay:typeof P.autoplay=="boolean"?P.autoplay:!0,...j!==void 0?{audio:A.push({uri:j})-1}:{},...W?{extras:{preset:W,pitch:_t(P.pitch,.25,4,1)}}:{}});let G=C.length,F=_t(P.refDistance,.05,100,1),H=_t(P.coneInnerAngle,0,360,360),B=_t(P.coneOuterAngle,H,360,360);C.push({name:`${X}_emitter`,type:U?"global":"positional",gain:V,sources:[O],...U?{}:{positional:{distanceModel:P.distanceModel==="linear"||P.distanceModel==="exponential"?P.distanceModel:"inverse",refDistance:F,maxDistance:_t(P.maxDistance,F,500,Math.max(F,25)),rolloffFactor:_t(P.rolloffFactor,0,10,1),coneInnerAngle:+(H*Math.PI/180).toFixed(6),coneOuterAngle:+(B*Math.PI/180).toFixed(6),coneOuterGain:_t(P.coneOuterGain,0,1,0)}}}),D.extensions={...D.extensions||{},KHR_audio_emitter:{emitter:G}},h.add("KHR_audio_emitter")}let d={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:v}],scene:0,nodes:a,meshes:o,materials:c,...y.length>0?{images:y}:{},...g.length>0?{samplers:g}:{},...u.length>0?{textures:u}:{},accessors:n,bufferViews:s,buffers:[{byteLength:r}],...N.length>0?{animations:N}:{},..._||h.size>0?{extensionsUsed:[..._?["KHR_interactivity"]:[],...h]}:{},..._||w.length>0||C.length>0?{extensions:{..._?{KHR_interactivity:_}:{},...w.length>0?{KHR_materials_variants:{variants:w.map(S=>({name:S}))}}:{},...C.length>0?{KHR_audio_emitter:{...A.length>0?{audio:A}:{},sources:E,emitters:C}}:{}}}:{}},k=new Uint8Array(r),$=0;for(let S of i)k.set(S,$),$+=S.byteLength;return[{gltf:d,bin:k.buffer,lights:M,environmentIntensity:e.environmentIntensity},l]}function Te(e){return new TextEncoder().encode(e)}function ie(e,t){let{gltf:i,bin:r}=Ht(e,t),s=JSON.stringify(i),n=Te(s),o=(4-n.byteLength%4)%4,a=n.byteLength+o,h=20+a+8+r.byteLength,l=new Uint8Array(h),c=new DataView(l.buffer);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0),c.setUint32(8,h,!0),c.setUint32(12,a,!0),c.setUint32(16,1313821514,!0),l.set(n,20);for(let y=0;y<o;y++)l[20+n.byteLength+y]=32;let f=20+a;return c.setUint32(f,r.byteLength,!0),c.setUint32(f+4,5130562,!0),l.set(new Uint8Array(r),f+8),l}function os(e,t){let[i,r]=fi(e,t);return Se(i,r)}function Se(e,t){let i=[],r=e.gltf,s=ut().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,e);let n=e.bin,o=n instanceof ArrayBuffer?n:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),a=r.accessors||[],h=r.bufferViews||[],l=r.materials||[],c=r.meshes||[],f=r.nodes||[],y=new Set,g=l.map((w,M)=>ui(y,re(w?.name,`Material_${M}`)));function u(w){let M=a[w];if(!M)throw new Error(`Accessor ${w} not found`);let x=h[M.bufferView||0],m=(x.byteOffset||0)+(M.byteOffset||0),p=x.byteLength||0;return{acc:M,buffer:o.slice(m,m+p)}}function b(w,M,x,m){let p=[],v=c[w];if(!v)return p;let R=v.primitives||[];for(let L=0;L<R.length;L++){let I=R[L],N=I.attributes?.POSITION;if(N===void 0)continue;let{acc:_,buffer:A}=u(N),E=new Float32Array(A,0,_.count*3),C,d=I.attributes?.NORMAL;if(d!==void 0){let{acc:O,buffer:G}=u(d),F=new Float32Array(G,0,O.count*3);C=new Float32Array(F.length);for(let H=0;H<O.count;H++){let B=F[H*3],K=F[H*3+1],q=F[H*3+2],z=Math.hypot(B,K,q)||1;C[H*3]=B/z,C[H*3+1]=K/z,C[H*3+2]=q/z}}let k,$=I.attributes?.TEXCOORD_0;if($!==void 0){let{acc:O,buffer:G}=u($);k=new Float32Array(G,0,O.count*2)}let S;if(I.indices!==void 0){let{acc:O,buffer:G}=u(I.indices);S=O.componentType===5125?new Uint32Array(G,0,O.count):new Uint16Array(G,0,O.count);let F=_.count;for(let H of S)if(H>=F)throw new Error(`SecurityError: Index buffer value (${H}) out of vertex bounds [0, ${F}).`)}else{let O=_.count;S=O>65535?new Uint32Array(O):new Uint16Array(O);for(let G=0;G<O;G++)S[G]=G}let D="DefaultMaterial",T=[.8,.8,.8],P=.5,j=0,W=0,V=0,Z=1.5,U=1,X=[0,0,0];if(I.material!==void 0&&l[I.material]){let O=l[I.material];D=g[I.material]||`Material_${I.material}`;let G=O.pbrMetallicRoughness||{},F=(q,z)=>Array.isArray(q)&&q.length>=3?[q[0],q[1],q[2]]:z;T=F(G.baseColorFactor,[1,1,1]);let H=O.extras?.avgColor;Array.isArray(H)&&H.length>=3&&(T=[T[0]*H[0],T[1]*H[1],T[2]*H[2]]);let B=Array.isArray(G.baseColorFactor)&&typeof G.baseColorFactor[3]=="number"?G.baseColorFactor[3]:1;typeof G.roughnessFactor=="number"&&(P=G.roughnessFactor),typeof G.metallicFactor=="number"&&(j=G.metallicFactor),X=F(O.emissiveFactor,[0,0,0]);let K=O.extensions||{};K.KHR_materials_clearcoat&&(W=K.KHR_materials_clearcoat.clearcoatFactor??0,V=K.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof K.KHR_materials_ior?.ior=="number"&&(Z=K.KHR_materials_ior.ior),U=B*(1-(K.KHR_materials_transmission?.transmissionFactor??0))}p.push({name:R.length>1?`${M}_p${L}`:M,positions:E,indices:S,normals:C,uvs:k,materialName:D,color:T,roughness:P,metallic:j,clearcoat:W,clearcoatRoughness:V,ior:Z,opacity:U,emissiveColor:X,xrTraits:x||v.extras?.xr,...m?{invisible:!0}:{}})}return p}if(f.length>0){let w=new Float32Array(0),M=new Uint16Array(0),x=(E,C)=>{if(E===void 0)return null;let{acc:d,buffer:k}=u(E);return new Float32Array(k,0,d.count*C)},m=(E,C)=>Array.isArray(E)&&E.length>=3?[Q(E[0],C),Q(E[1],C),Q(E[2],C)]:[C,C,C],p=(E,C,d)=>E&&E.length>=(C+1)*3?[E[C*3],E[C*3+1],E[C*3+2]]:d,v=(E,C,d)=>E&&E.length>=(C+1)*4?[E[C*4],E[C*4+1],E[C*4+2],E[C*4+3]]:d,R=new Map,L=r.animations?.[0];if(L&&Array.isArray(L.channels)&&Array.isArray(L.samplers))for(let E of L.channels){let C=L.samplers[E?.sampler],d=E?.target?.node,k=E?.target?.path;if(!C||typeof d!="number"||C.input===void 0)continue;let $=R.get(d);$||($={input:C.input},R.set(d,$)),k==="translation"?$.t=C.output:k==="rotation"?$.r=C.output:k==="scale"&&($.s=C.output)}let I=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(I)||I.length===0){let E=new Set;for(let C of f)if(Array.isArray(C?.children))for(let d of C.children)E.add(d);I=[];for(let C=0;C<f.length;C++)E.has(C)||I.push(C);I.length===0&&(I=[0])}let N=new Set,_=[],A=(E,C)=>{if(Array.isArray(E))for(let d=E.length-1;d>=0;d--)_.push({idx:E[d],out:C})};for(A(I,i);_.length>0;){let{idx:E,out:C}=_.pop();if(typeof E!="number"||E<0||E>=f.length||N.has(E))continue;N.add(E);let d=f[E];if(!d)continue;let k=[0,0,0],$=[0,0,0,1],S=[1,1,1];if(Array.isArray(d.matrix)&&d.matrix.length===16){let U=ci(d.matrix);k=U.t,$=U.r,S=U.s}else k=m(d.translation,0),Array.isArray(d.rotation)&&d.rotation.length>=4&&($=[Q(d.rotation[0],0),Q(d.rotation[1],0),Q(d.rotation[2],0),Q(d.rotation[3],1)]),S=m(d.scale,1);let D,T=R.get(E);if(T){let U=x(T.input,1);if(U&&U.length>0){let X=x(T.t,3),O=x(T.r,4),G=x(T.s,3),F=Array.from(U),H=[],B=[],K=[];for(let q=0;q<U.length;q++)H.push(p(X,q,k)),B.push(v(O,q,$)),K.push(p(G,q,S));D={times:F,translations:H,rotations:B,scales:K}}}let P=Array.isArray(d.children)?d.children:[],j=typeof d.mesh=="number"&&d.mesh>=0&&d.mesh<c.length,W=t?.[E]?.userData?.xr??d.extras?.xr;if(!j&&P.length===0&&(d.camera!==void 0||d.extensions?.KHR_lights_punctual||!d.name&&!d.extras&&!W&&!D))continue;let V=(U,X,O)=>({name:U,positions:w,indices:M,isXform:!0,xrTraits:W,timeSamples:D,translation:k,rotation:$,scale:S,children:X,...O?{invisible:!0}:{}}),Z=d.visible===!1||d.extensions?.KHR_node_visibility?.visible===!1||t?.[E]?.visible===!1;if(j){let U=d.name||c[d.mesh]?.name||`Mesh_${E}`,X=b(d.mesh,U,W,Z),O=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(O&&typeof O=="object"&&X.length>0){let G=x(O.TRANSLATION,3),F=x(O.ROTATION,4),H=x(O.SCALE,3),B=x(O._COLOR_0,3),K=Math.min(1e3,G?G.length/3:F?F.length/4:H?H.length/3:0);if(K>0){let q=[];for(let z=0;z<K;z++){let tt=p(G,z,[0,0,0]),et=v(F,z,[0,0,0,1]),rt=p(H,z,[1,1,1]);for(let J of X){let it=J.color||[.8,.8,.8],st=B&&B.length>=(z+1)*3;q.push({...J,name:`${J.name}_${z}`,materialName:st?`${J.materialName}_inst_${z}`:J.materialName,color:st?[it[0]*B[z*3],it[1]*B[z*3+1],it[2]*B[z*3+2]]:J.color,translation:tt,rotation:et,scale:rt})}}A(P,q),C.push(V(U,q,Z));continue}}if(X.length===1)X[0].translation=k,X[0].rotation=$,X[0].scale=S,X[0].timeSamples=D,P.length>0&&(X[0].children=[],A(P,X[0].children)),C.push(X[0]);else{let G=[...X];A(P,G),C.push(V(U,G,Z))}}else{let U=[];A(P,U),C.push(V(d.name||`Group_${E}`,U,Z))}}}else for(let w=0;w<c.length;w++){let M=c[w].name||`Mesh_${w}`;i.push(...b(w,M,c[w].extras?.xr))}return i}function re(e,t){if(!e||typeof e!="string")return t;let i=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||t}function Re(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function pt(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var St=(e,t,i)=>`(${pt(e)}, ${pt(t)}, ${pt(i)})`,pi=(e,t,i,r)=>`(${pt(e)}, ${pt(t)}, ${pt(i)}, ${pt(r)})`;function di(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=St(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function ls(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${pt(e[r*2])}, ${pt(1-e[r*2+1])})`;return i.join(", ")}function hs(e){return Array.from(e).join(", ")}function Ce(e){let t=new Map,i=0,r=null,s=[...e];for(;s.length>0;){let u=s.pop();if(!u.isXform&&u.positions&&u.positions.length>0){let b=re(u.materialName,"DefaultMaterial");t.has(b)||t.set(b,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}if(u.timeSamples&&u.timeSamples.times.length>0){let b=u.timeSamples.times[u.timeSamples.times.length-1];b>i&&(i=b)}if(u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal"),u.children)for(let b=u.children.length-1;b>=0;b--)s.push(u.children[b])}let n="";i>0&&(n=`startTimeCode = 0
|
|
250
|
-
endTimeCode = ${
|
|
249
|
+
void main(){fragColor=uColorId;}`;function Te(e,t,i){let r={};for(let s of i)r[s]=e.getUniformLocation(t,s);return r}var ei=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function ii(){let e=mt().xrDepthShader;return{fs:Zr.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...ei,...e.uniformNames]:ei}}function ts(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let i=t.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:i.startsWith("https://")||i.startsWith("blob:")?t:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Se(e,t,i,r,s,n,a,o){if(r===void 0||!t.accessors?.[r])return null;let l=Ye(t,i,t.accessors[r],n);if(!l)return null;o&&(l=l.slice(),Wr(l,o));let h=e.createBuffer();return a.push(h),e.bindBuffer(34962,h),e.bufferData(34962,l,35044),e.enableVertexAttribArray(s),e.vertexAttribPointer(s,n,5126,!1,0,0),l}function Ae(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function ri(e,t,i){let r=ii(),s=ti,n=r.fs,a=!1;for(let l of pt)if(l.onResolveShader){let h=l.onResolveShader(t,i,s,n);h&&(s=h.vs,n=h.fs,a=!0)}let o=a?ve(e,s,n):null;return{program:o,uniforms:o?Te(e,o,r.uniforms):null}}function es(e,t,i){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let s=r.length>>4,n=t.instanceColors,a=new Float32Array(s*20);for(let l=0;l<s;l++)a.set(r.subarray(l*16,l*16+16),l*20),a[l*20+16]=n?n[l*3]:1,a[l*20+17]=n?n[l*3+1]:1,a[l*20+18]=n?n[l*3+2]:1,a[l*20+19]=1;let o=e.createBuffer();i.push(o),e.bindBuffer(34962,o),e.bufferData(34962,a,35044);for(let l=0;l<5;l++)e.enableVertexAttribArray(8+l),e.vertexAttribPointer(8+l,4,5126,!1,80,l*16),e.vertexAttribDivisor(8+l,1);return!0}function is(e,t){let i=e.materials?.[t?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let s of r){let n=s?.extensions?.KHR_texture_transform;if(n&&typeof n=="object")return n}return null}var Ns=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),si=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function ee(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function ni(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,s=e?.extensions?.KHR_materials_clearcoat,n=a=>a!==void 0&&t[a.index]?t[a.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:n(i?.baseColorTexture),metallicRoughnessTexture:n(i?.metallicRoughnessTexture),normalTexture:n(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:n(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function ai(e,t,i){let r=new Set,s=n=>{n&&!r.has(n)&&(r.add(n),e.deleteTexture(n))};for(let n of t)for(let a of n.primitives){if(a.vao&&e.deleteVertexArray(a.vao),a.buffers)for(let l of a.buffers)e.deleteBuffer(l);s(a.texture),s(a.metallicRoughnessTexture),s(a.normalTexture),s(a.occlusionTexture);let o=new Set;a.customProgram&&o.add(a.customProgram);for(let l of a.programCache?.values()??[])l.program&&o.add(l.program);for(let l of o)e.deleteProgram(l)}if(i)for(let n of i)s(n)}function oi(e,t,i=si,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return rs(e,t,i,r,s)}catch(n){let a=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;ai(e,a,s.gpuTextures),s.vao&&e.deleteVertexArray(s.vao);for(let o of s.buffers)e.deleteBuffer(o);throw n}}function rs(e,t,i,r,s){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n}=t,a=zt("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(n,t);let o=t.bin,l=[];s.meshes=l;let h=[],u=n.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((E,y)=>{h.push(typeof E?.name=="string"&&E.name?E.name:`Variant_${y}`)});let f=Hr(n),g=[];if(Array.isArray(n.nodes))for(let E=0;E<n.nodes.length;E++){let y=n.nodes[E];y.mesh!==void 0&&n.meshes&&n.meshes[y.mesh]&&g.push({node:y,nodeIdx:E,meshIdx:y.mesh})}let w=g.length>0?g:(n.meshes||[]).map((E,y)=>({node:E,nodeIdx:-1,meshIdx:y})),p=[],b=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(n.asset?.extras?.lights)&&n.asset.extras.lights.length>0?n.asset.extras.lights:null;if(b)for(let E of b)p.push({...E,type:E.type||E.light_type||"point",innerConeAngle:E.innerConeAngle??E.inner_cone_angle,outerConeAngle:E.outerConeAngle??E.outer_cone_angle});else if(n.extensions?.KHR_lights_punctual?.lights){let E=n.extensions.KHR_lights_punctual.lights;for(let y of E){let F=y.type==="directional"?"directional":y.type==="point"?"point":y.type==="spot"?"spot":"ambient";p.push({type:F,color:y.color||[1,1,1],intensity:y.intensity!==void 0?y.intensity:1})}}if(p.length===0&&(p.push({type:"ambient",color:[1,1,1],intensity:.35}),p.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),w.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${w.length}`);let T=[];if(s.gpuTextures=T,n.textures&&n.images){if(n.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${n.textures.length}`);for(let E=0;E<n.textures.length;E++){let y=n.textures[E],F=n.images[y.source];if(F){let z=e.createTexture();e.bindTexture(3553,z),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let A=_=>{e.bindTexture(3553,z),e.texImage2D(3553,0,6408,6408,5121,_),e.generateMipmap(3553),r?.()};if(F.bufferView!==void 0){let _=n.bufferViews[F.bufferView],d=_.byteOffset||0,R=new Blob([o.slice(d,d+_.byteLength)],{type:F.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(R).then(A).catch(()=>{})}else if(F.uri){let _=ts(F.uri);if(_){let d=new Image;d.crossOrigin="anonymous",d.referrerPolicy="no-referrer",d.onload=()=>A(d),d.src=_}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",F.uri)}T.push(z)}else T.push(null)}}let x=[1/0,1/0,1/0],M=[-1/0,-1/0,-1/0],c=0,m=0;for(let E=0;E<w.length;E++){let y=w[E],F=n.meshes[y.meshIdx],z=y.nodeIdx>=0?f[y.nodeIdx]:ct(),A=new Float32Array(9);Et(A,z);let _={name:y.node.name||F.name||`Mesh_${y.meshIdx}`,nodeIndex:y.nodeIdx,transform:z,normalMatrix:A,primitives:[],extras:y.node.extras||F.extras,...y.node?.visible===!1||y.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};s.mesh=_;let d=y.node?.extensions?.EXT_mesh_gpu_instancing;if(d&&d.attributes&&typeof d.attributes=="object"){let R=d.attributes,G=R.TRANSLATION!==void 0?n.accessors?.[R.TRANSLATION]:null,H=R.ROTATION!==void 0?n.accessors?.[R.ROTATION]:null,B=R.SCALE!==void 0?n.accessors?.[R.SCALE]:null,Z=R._COLOR_0!==void 0?n.accessors?.[R._COLOR_0]:null,k=Number(G?.count??H?.count??B?.count??0);if(!Number.isFinite(k)||k<0||k>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${k}`);if(k>0){let Y=(U,O)=>{if(!U||U.bufferView===void 0||!n.bufferViews?.[U.bufferView])return null;let j=U.componentType??5126,q=et=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${et})`),null);if(j!==5120&&j!==5121&&j!==5122&&j!==5123&&j!==5126)return q(`componentType ${j}`);if(!(Number(U.count)>=k))return q(`count ${U.count} < ${k}`);let K=null;try{K=Ye(n,o,{...U,count:k},O)}catch{return q("out of bounds")}return!K||!K.every(Number.isFinite)?q("non-finite value"):K},rt=Y(G,3),st=Y(H,4),$=Y(B,3),J=Z?.type==="VEC4"?4:3,V=Y(Z,J),W=new Float32Array(k*16),X=ct();for(let U=0;U<k;U++){let O=rt?[rt[U*3],rt[U*3+1],rt[U*3+2]]:[0,0,0],j=st?[st[U*4],st[U*4+1],st[U*4+2],st[U*4+3]]:[0,0,0,1],q=$?[$[U*3],$[U*3+1],$[U*3+2]]:[1,1,1];xe(X,j,O,q),W.set(X,U*16)}if(_.instanceMatrices=W,V){let U=new Float32Array(k*3);for(let O=0;O<k;O++)U[O*3]=V[O*J],U[O*3+1]=V[O*J+1],U[O*3+2]=V[O*J+2];_.instanceColors=U}}}for(let R of F.primitives||[]){if(R.extensions?.KHR_draco_mesh_compression){let K=zt("draco");K&&K.decodePrimitive(n,R,o)}let G=[],H=e.createVertexArray();s.vao=H,s.buffers=G,e.bindVertexArray(H);let B=es(e,_,G),Z=n.accessors[R.attributes.POSITION],k=Number(Z?.count??0);if(!Number.isFinite(k)||k<0||c+k>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(c+=k,Z?.min&&Z?.max){let K=et=>{for(let it=0;it<3;it++){let dt=et[12+it],nt=et[12+it];for(let at=0;at<3;at++){let ot=et[at*4+it]*Z.min[at],lt=et[at*4+it]*Z.max[at];dt+=ot<lt?ot:lt,nt+=ot>lt?ot:lt}dt<x[it]&&(x[it]=dt),nt>M[it]&&(M[it]=nt)}};if(_.instanceMatrices&&_.instanceMatrices.length>=16){let et=_.instanceMatrices.length>>4,it=ct();for(let dt=0;dt<et;dt++){let nt=_.instanceMatrices.subarray(dt*16,dt*16+16);yt(it,z,nt),K(it)}}else K(z)}let Y=Se(e,n,o,R.attributes.POSITION,0,3,G);Se(e,n,o,R.attributes.NORMAL,1,3,G),Se(e,n,o,R.attributes.TEXCOORD_0,2,2,G,is(n,R));let rt=0,st=5123,$=null;if(R.indices!==void 0){let K=n.accessors[R.indices],et=(n.bufferViews[K.bufferView].byteOffset||0)+(K.byteOffset||0);if(rt=Number(K.count??0),!Number.isFinite(rt)||rt<0||m+rt>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);m+=rt,st=K.componentType===5125?5125:5123;let it=e.createBuffer();G.push(it),e.bindBuffer(34963,it),K.componentType===5125?$=new Uint32Array(o,et,K.count):K.componentType===5121?$=Uint16Array.from(new Uint8Array(o,et,K.count)):$=et%2===0?new Uint16Array(o,et,K.count):new Uint16Array(o.slice(et,et+K.count*2)),e.bufferData(34963,$,35044)}else rt=Z.count;let J={};for(let K of pt)if(K.onBuildPrimitiveVAO){let et=K.onBuildPrimitiveVAO(e,H,R,n,o);et&&(J[K.name]=et)}e.bindVertexArray(null);let V=n.materials&&R.material!==void 0?n.materials[R.material]:null,{program:W,uniforms:X}=ri(e,R,V),U=ni(V,T),O=!!(V?.extensions?.KHR_materials_transmission||J.materials?.isTransmissive),j=R.extensions?.KHR_materials_variants?.mappings,q=Array.isArray(j)?j.filter(K=>K&&typeof K.material=="number"&&Array.isArray(K.variants)).map(K=>({material:K.material|0,variants:K.variants.map(et=>Number(et)|0)})):void 0;_.primitives.push({vao:H,instanced:B,indexCount:rt,indexType:st,...U,positions:Y,indices:$,buffers:G,materialIndex:R.material,defaultMaterialIndex:R.material,variantMappings:q,primitiveDef:R,programCache:new Map([[R.material??-1,{program:W,uniforms:X}]]),pluginData:J,customProgram:W,customUniforms:X,isTransmissive:O})}l.push(_)}isFinite(x[0])||(x=[-1,-1,-1]),isFinite(M[0])||(M=[1,1,1]);let v=[(x[0]+M[0])/2,(x[1]+M[1])/2,(x[2]+M[2])/2],S=M[0]-x[0],D=M[1]-x[1],I=M[2]-x[2],P=Math.max(Math.hypot(S,D,I)/2,.5),N=[x[0],x[1],x[2]],C=[M[0],M[1],M[2]],L=t.animations;if(!L){for(let E of pt)if(E.onParseGLB?.(t),t.animations){L=t.animations;break}}return L||(L=[]),{meshes:l,bounds:{center:v,radius:P,min:N,max:C},lights:p,animations:L,worldMatrices:f,gpuTextures:T,availableVariants:h}}function jt(e){let t=e.customTarget||e.bounds.center,i=e.currDistance*Math.cos(e.currPhi);return[t[0]+i*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+i*Math.cos(e.currTheta)]}var li=class{constructor(e,t,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=ct(),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=ct(),this.viewMatrix=ct(),this.activeViewMatrix=null,this.modelMatrix=ct(),this.mvpMatrix=ct(),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:ct(),rawValueToMeters:.001,format:0},this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),r=o}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let n=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!n:n&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=Ae(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=Me(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let a=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!a)throw new Error("WebGL2 not supported");this.gl=a,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Kr(e,t)}static getDecoder(e){return zt(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=ii();this.renderProg=ve(e,ti,t.fs),this.pickProg=ve(e,Jr,Qr),this.uRender=Te(e,this.renderProg,t.uniforms),this.uPick=Te(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of pt)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:n,worldMatrices:a,gpuTextures:o,availableVariants:l}=oi(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=n||[],this.worldMatrices=a||[],this.gpuTextures=o||[],this.availableVariants=l||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of pt)f.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let h=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;h!==void 0&&(this.exposure=Ae(h));let u=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(Qe(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of pt)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(we(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=we(e),{meshes:r}=oi(this.gl,i,si,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],Et(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),Et(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],n=[],a=[],o=[],l=[];for(let h of this.lights){let u=h.color||[1,1,1],f=h.intensity!==void 0?h.intensity:1;if(h.type==="ambient")i=[u[0]*f,u[1]*f,u[2]*f];else if(h.type==="directional"&&r.length<6){let g=h.direction||[.5,1,.8];r.push(g[0],g[1],g[2]),s.push(u[0]*f,u[1]*f,u[2]*f)}else if((h.type==="point"||h.type==="spot")&&n.length<6){let g=h.position||[0,0,0];if(n.push(g[0],g[1],g[2]),a.push(u[0]*f,u[1]*f,u[2]*f),h.type==="spot"){let w=h.direction||[0,-1,0],p=Math.max(.01,Math.min(Math.PI/2,h.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(p-1e-4,h.innerConeAngle??0));o.push(w[0],w[1],w[2]),l.push(Math.cos(b),Math.cos(p))}else o.push(0,-1,0),l.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,n.length/3),n.length>0&&(t.uniform3fv(e.uPointLightPos,n),t.uniform3fv(e.uPointLightColor,a),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,o),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,l)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Ae(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=Me(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of pt)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of pt)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,i)=>{let r=this.meshes.flatMap(h=>h.primitives.filter(u=>u.materialIndex===i||e.length===1&&u.materialIndex===void 0)),s=r[0],n=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],a=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,l={baseColorFactor:n,metallicFactor:a,roughnessFactor:o,setBaseColorFactor:h=>{let u=[h[0],h[1],h[2],h[3]??1];l.baseColorFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=u);for(let f of r)f.baseColor=u;this.render()},setMetallicFactor:h=>{l.metallicFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=h);for(let u of r)u.metallic=h;this.render()},setRoughnessFactor:h=>{l.roughnessFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=h);for(let u of r)u.roughness=h;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:l}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",i=-1;if(t)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(e),i<0)return!1;this.activeVariantName=e}let r=this.gltf?.materials;if(!Array.isArray(r))return t;for(let s of this.meshes)for(let n of s.primitives){let a=n.defaultMaterialIndex;if(!t&&Array.isArray(n.variantMappings)){for(let l of n.variantMappings)if(Array.isArray(l.variants)&&l.variants.includes(i)){a=l.material;break}}let o=a!==void 0?r[a]:void 0;n.materialIndex=o?a:void 0,Object.assign(n,ni(o,this.gpuTextures)),this.applyPrimitiveProgram(n,n.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,s=e.programCache.get(r);s||(s=ri(this.gl,{...e.primitiveDef,material:t},i),e.programCache.set(r,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of pt)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let i=ct();yt(i,this.projMatrix,this.viewMatrix);let[r,s,n]=e,a=t?t[0]:0,o=t?t[1]:0,l=t?t[2]:0,h=this.modelRootMatrix;h&&(r=h[0]*e[0]+h[4]*e[1]+h[8]*e[2]+h[12],s=h[1]*e[0]+h[5]*e[1]+h[9]*e[2]+h[13],n=h[2]*e[0]+h[6]*e[1]+h[10]*e[2]+h[14],t&&(a=h[0]*t[0]+h[4]*t[1]+h[8]*t[2],o=h[1]*t[0]+h[5]*t[1]+h[9]*t[2],l=h[2]*t[0]+h[6]*t[1]+h[10]*t[2]));let u=i[0]*r+i[4]*s+i[8]*n+i[12],f=i[1]*r+i[5]*s+i[9]*n+i[13],g=i[2]*r+i[6]*s+i[10]*n+i[14],w=i[3]*r+i[7]*s+i[11]*n+i[15];if(w<=1e-4)return{x:0,y:0,z:1,visible:!1};let p=u/w,b=f/w,T=g/w,x=this.canvas.getBoundingClientRect(),M=x.width||this.canvas.clientWidth||this.canvas.width||300,c=x.height||this.canvas.clientHeight||this.canvas.height||150,m=(p*.5+.5)*M,v=(-b*.5+.5)*c,S=p>=-1.1&&p<=1.1&&b>=-1.1&&b<=1.1&&T>=-1&&T<=1;if(S&&t){let[D,I,P]=jt(this),N=[r-D,s-I,n-P];a*N[0]+o*N[1]+l*N[2]>.05&&(S=!1)}return{x:m,y:v,z:T,visible:S}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=i=>{i.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,e.setPointerCapture(i.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},s=i.clientX-r.x,n=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(s,n),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],l=this.customTarget?[...this.customTarget]:[...this.bounds.center],h=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;l[0]+=(-s*a[0]+n*o[0])*h,l[1]+=(-s*a[1]+n*o[1])*h,l[2]+=(-s*a[2]+n*o[2])*h,this.customTarget=l}else this.targetTheta=this.clampTheta(this.targetTheta-s*.008),this.targetPhi=this.clampPhi(this.targetPhi+n*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=t(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=e.getBoundingClientRect(),s=Math.floor((i.clientX-r.left)*(e.width/Math.max(r.width,1))),n=Math.floor((i.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(s,n,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=t();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),i.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(i,r,s)=>{this[s]&&(i.removeEventListener(r,this[s]),this[s]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,n=i.height||300,a=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),o=r.height>0?Math.floor((t-r.top)*(n/r.height)):Math.floor(t);return this.performMeshPick(a,o,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),n=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let a=ct();yt(a,this.projMatrix,this.viewMatrix);let o=[],l=Math.max(0,Math.min(s-1,e)),h=Math.max(0,Math.min(n-1,n-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==n)&&this.resizePickingFbo(s,n),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,n),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let v=0;v<this.meshes.length;v++){let S=this.meshes[v];if(S.visible===!1||S.isPluginMesh)continue;let D=v+1,I=(D&255)/255,P=(D>>8&255)/255,N=(D>>16&255)/255;r.uniform4f(this.uPick.uColorId,I,P,N,1),yt(this.modelMatrix,this.modelRootMatrix,S.transform);let C=S.instanceMatrices;if(C&&C.length>=16){let L=C.length>>4,E=ct();for(let y of S.primitives){r.bindVertexArray(y.vao);for(let F=0;F<L;F++)yt(E,this.modelMatrix,C.subarray(F*16,F*16+16)),yt(this.mvpMatrix,a,E),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),ee(r,y)}}else{yt(this.mvpMatrix,a,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let L of S.primitives)r.bindVertexArray(L.vao),ee(r,L)}}let c=new Uint8Array(4);r.readPixels(l,h,1,1,6408,5121,c),r.bindFramebuffer(36160,null);let m=c[0]+(c[1]<<8)+(c[2]<<16);m>0&&m<=this.meshes.length&&(o=[this.meshes[m-1]])}o.length===0&&(o=this.meshes.filter(c=>c.visible!==!1));let u=null,f=1/0,g=[0,0,0],w=[0,1,0],[p,b,T]=jt(this),x=ct();for(let c of o){yt(x,this.modelRootMatrix,c.transform);let m=c.instanceMatrices,v=m&&m.length>=16?m.length>>4:1;for(let S=0;S<v;S++){m&&m.length>=16?yt(this.modelMatrix,x,m.subarray(S*16,S*16+16)):this.modelMatrix.set(x),yt(this.mvpMatrix,a,this.modelMatrix);let D=ct();if(!Vr(D,this.mvpMatrix))continue;let I=(l+.5)/s*2-1,P=(h+.5)/n*2-1,N=[0,0,0],C=[0,0,0];Ke(N,I,P,-1,D),Ke(C,I,P,1,D);let L=C[0]-N[0],E=C[1]-N[1],y=C[2]-N[2],F=Math.hypot(L,E,y)||1,z=L/F,A=E/F,_=y/F,d={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((R=>{for(let G of c.primitives){if(!G.positions)continue;let H=G.positions,B=G.indices,Z=Math.floor(B?B.length/3:H.length/9);for(let k=0;k<Z;k++){let Y=B?B[k*3]:k*3,rt=B?B[k*3+1]:k*3+1,st=B?B[k*3+2]:k*3+2;Gr(N[0],N[1],N[2],z,A,_,H[Y*3],H[Y*3+1],H[Y*3+2],H[rt*3],H[rt*3+1],H[rt*3+2],H[st*3],H[st*3+1],H[st*3+2],d,R)}}})(1e-4),isFinite(d.distance)){let R=d.point[0],G=d.point[1],H=d.point[2],B=this.modelMatrix,Z=B[0]*R+B[4]*G+B[8]*H+B[12],k=B[1]*R+B[5]*G+B[9]*H+B[13],Y=B[2]*R+B[6]*G+B[10]*H+B[14],rt=Z-p,st=k-b,$=Y-T,J=Math.hypot(rt,st,$);if(J<f){Et(this.normalMatrix,this.modelMatrix);let V=this.normalMatrix,W=d.normal[0],X=d.normal[1],U=d.normal[2],O=V[0]*W+V[3]*X+V[6]*U,j=V[1]*W+V[4]*X+V[7]*U,q=V[2]*W+V[5]*X+V[8]*U,K=Math.hypot(O,j,q)||1;O/=K,j/=K,q/=K,O*rt+j*st+q*$>0&&(O=-O,j=-j,q=-q),u=c,f=Math.round(J*1e3)/1e3,g=[Math.round(Z*1e3)/1e3,Math.round(k*1e3)/1e3,Math.round(Y*1e3)/1e3],w=[Math.round(O*1e3)/1e3,Math.round(j*1e3)/1e3,Math.round(q*1e3)/1e3]}}}}if(!u)return null;let M={meshIndex:this.meshes.indexOf(u),meshName:u.name,nodeIndex:u.nodeIndex,distance:f,hitPoint:g,normal:w,screenX:e,screenY:t};if(i){for(let c of pt)c.onMeshSelect?.(this,M);this.opts.onMeshClick&&this.opts.onMeshClick(M),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:M}))}return M}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,n=r?Math.max(1,t-i):i,a=(s+.5)/n*2-1;return Math.floor((a*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);be(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;te(this.viewMatrix,jt(this),i,[0,1,0]),yt(this.mvpMatrix,this.projMatrix,this.viewMatrix),Et(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let i of pt)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of pt)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let n of pt)n.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let n of pt)n.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let n={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(n),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:n}))}}renderXRView(e,t,i,r,s=!0,n=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let a=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,l=e?.transform?.position,h=l?[l.x,l.y,l.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:a,projMatrix:o,eyePos:h,viewport:r,eye:e?.eye||"none",clear:n>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let M=Math.max(2,this.canvas.width||2),c=Math.max(1,this.canvas.height||1),m=Math.max(1,Math.floor(M*.5)),v=Math.max(1,M-m),S=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),D=this.customTarget||this.bounds.center,[I,P,N]=jt(this),C=Math.cos(this.currTheta),L=-Math.sin(this.currTheta),E=.032,y=ct(),F=ct(),z=[I-C*E,P,N-L*E],A=[D[0]-C*E*.25,D[1],D[2]-L*E*.25];be(y,this.fov,m/c,.1,S),te(F,z,A,[0,1,0]);let _=ct(),d=ct(),R=[I+C*E,P,N+L*E],G=[D[0]+C*E*.25,D[1],D[2]+L*E*.25];be(_,this.fov,v/c,.1,S),te(d,R,G,[0,1,0]),this.render({viewMatrix:F,projMatrix:y,eyePos:z,viewport:[0,0,m,c],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:d,projMatrix:_,eyePos:R,viewport:[m,0,v,c],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,M,c);return}let t=this.gl,i=0,r=0,s=this.canvas.width,n=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],n=e.viewport[3],t.viewport(i,r,s,n)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16640));let a=ct(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,yt(a,e?.projMatrix??this.projMatrix,o);let l=mt().xrDepthShader,h=Xr(this.toneMapping),[u,f,g]=e?e.eyePos:jt(this);for(let M of pt)M.onBeforeDrawScene?.(this,t,a,[u,f,g],h);let w=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&w===0)return;let p=e?.eye||"none",b=!1,T=w>0?[...this.backdropMeshes,...this.meshes]:this.meshes,x=M=>{for(let c=0;c<T.length;c++){let m=T[c];if(m.visible===!1)continue;let v=this.selectedMeshName!==""&&m.name===this.selectedMeshName;c<w||m.worldSpace===!0||m.name==="__xr_reticle__"?this.modelMatrix.set(m.transform):yt(this.modelMatrix,this.modelRootMatrix,m.transform),yt(this.mvpMatrix,a,this.modelMatrix),Et(m.normalMatrix,this.modelMatrix);let S=m.extras?.xr?.stereo||m.userData?.xr?.stereo,D=0,I=0,P=1,N=1;S==="sbs"?(P=.5,D=p==="right"?.5:0):S==="ou"&&(N=.5,I=p==="right"?.5:0);for(let C of m.primitives){let L=!!C.isTransmissive;if(!M&&L){b=!0;continue}if(M&&!L)continue;let E=C.customProgram||this.renderProg,y=C.customUniforms||this.uRender;t.useProgram(E),t.vertexAttrib3f(3,0,0,0),y.uInstanced&&t.uniform1i(y.uInstanced,0),t.uniform1i(y.uToneMapping,h),t.uniform1f(y.uEnvIntensity,this.envIntensity),y.uExposure&&t.uniform1f(y.uExposure,this.exposure),t.uniform3f(y.uCameraPos,u,f,g),t.uniform1f(y.uEmissive,v?1:0),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(y.uNormalMatrix,!1,m.normalMatrix),y.uUvTransform&&t.uniform4f(y.uUvTransform,D,I,P,N),y.uViewportSize&&t.uniform2f(y.uViewportSize,Math.max(1,s),Math.max(1,n)),l?.bind(t,y,this.xrDepthState,o,[i,r,Math.max(1,s),Math.max(1,n)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(y.uEnvironmentMap,4),t.uniform1i(y.uHasEnvironmentMap,1)):t.uniform1i(y.uHasEnvironmentMap,0),this.bindLights(y),y.uSectionEnabled&&t.uniform1i(y.uSectionEnabled,0);for(let z of pt)z.onBeforeDrawPrimitive?.(t,E,C,m,this.worldMatrices||[],this.gltf);t.uniform4fv(y.uBaseColor,C.baseColor),t.uniform1f(y.uMetallic,C.metallic),t.uniform1f(y.uRoughness,C.roughness),y.uClearcoat&&t.uniform2f(y.uClearcoat,C.clearcoat??0,C.clearcoatRoughness??.04),C.texture?(t.activeTexture(33984),t.bindTexture(3553,C.texture),t.uniform1i(y.uBaseColorTexture,0),t.uniform1i(y.uHasTexture,1)):t.uniform1i(y.uHasTexture,0),C.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,C.metallicRoughnessTexture),t.uniform1i(y.uMetallicRoughnessTexture,1),t.uniform1i(y.uHasMetallicRoughnessTexture,1)):t.uniform1i(y.uHasMetallicRoughnessTexture,0),C.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,C.normalTexture),t.uniform1i(y.uNormalTexture,2),t.uniform1i(y.uHasNormalTexture,1),t.uniform1f(y.uNormalScale,C.normalScale)):t.uniform1i(y.uHasNormalTexture,0),C.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,C.occlusionTexture),t.uniform1i(y.uOcclusionTexture,3),t.uniform1i(y.uHasOcclusionTexture,1),t.uniform1f(y.uOcclusionStrength,C.occlusionStrength)):t.uniform1i(y.uHasOcclusionTexture,0),t.bindVertexArray(C.vao);let F=m.instanceMatrices;if(C.instanceCount!==void 0)t.drawElementsInstanced(4,C.indexCount,C.indexType,0,C.instanceCount);else if(F&&F.length>=16&&C.instanced&&y.uInstanced&&y.uViewProj){let z=F.length>>4;t.uniform1i(y.uInstanced,1),t.uniformMatrix4fv(y.uViewProj,!1,a),C.indices?t.drawElementsInstanced(4,C.indexCount,C.indexType,0,z):t.drawArraysInstanced(4,0,C.indexCount,z),t.uniform1i(y.uInstanced,0)}else if(F&&F.length>=16){let z=F.length>>4,A=m.instanceColors,_=ct(),d=new Float32Array(9),R=[C.baseColor[0],C.baseColor[1],C.baseColor[2],C.baseColor[3]];for(let G=0;G<z;G++)yt(_,this.modelMatrix,F.subarray(G*16,G*16+16)),yt(this.mvpMatrix,a,_),Et(d,_),t.uniformMatrix4fv(y.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(y.uModel,!1,_),t.uniformMatrix3fv(y.uNormalMatrix,!1,d),A&&(R[0]=C.baseColor[0]*A[G*3],R[1]=C.baseColor[1]*A[G*3+1],R[2]=C.baseColor[2]*A[G*3+2],R[3]=C.baseColor[3],t.uniform4fv(y.uBaseColor,R)),ee(t,C)}else ee(t,C)}}};if(x(!1),b){for(let M of pt)M.onBeforeTransmissivePass?.(t,this);x(!0)}for(let M of pt)M.onAfterRender?.(t,this,a,e?.eye??"none",[i,r,s,n],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){ai(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 pt)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()}};li.registerPlugin=Br,li.getRegisteredPlugins=zr;function ss(e){return e+3&-4}var tt=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function hi(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function ui(e,t=0){let[i,r,s,,n,a,o,,l,h,u,,f,g,w]=Array.from({length:15},(d,R)=>tt(e[t+R],R%5===0?1:0)),p=Math.hypot(i,r,s),b=Math.hypot(n,a,o),T=Math.hypot(l,h,u);i*(a*u-h*o)-n*(r*u-h*s)+l*(r*o-a*s)<0&&(p=-p);let x=Math.abs(p)>1e-8?1/p:0,M=Math.abs(b)>1e-8?1/b:0,c=Math.abs(T)>1e-8?1/T:0,m=i*x,v=r*x,S=s*x,D=n*M,I=a*M,P=o*M,N=l*c,C=h*c,L=u*c,E=m+I+L,y=0,F=0,z=0,A=1;if(E>0){let d=.5/Math.sqrt(E+1);A=.25/d,y=(P-C)*d,F=(N-S)*d,z=(v-D)*d}else if(m>I&&m>L){let d=2*Math.sqrt(Math.max(0,1+m-I-L));d>1e-8&&(A=(P-C)/d,y=.25*d,F=(D+v)/d,z=(N+S)/d)}else if(I>L){let d=2*Math.sqrt(Math.max(0,1+I-m-L));d>1e-8&&(A=(N-S)/d,y=(D+v)/d,F=.25*d,z=(P+C)/d)}else{let d=2*Math.sqrt(Math.max(0,1+L-m-I));d>1e-8&&(A=(v-D)/d,y=(N+S)/d,F=(P+C)/d,z=.25*d)}let _=Math.hypot(y,F,z,A);return _>1e-8&&Number.isFinite(_)?(y/=_,F/=_,z/=_,A/=_):(y=0,F=0,z=0,A=1),{t:[f,g,w],r:[y,F,z,A],s:[p,b,T]}}function ns(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var Dt=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function ci(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let i=typeof t=="string"?{preset:t}:t,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,s=typeof i.preset=="string"?i.preset:void 0;return!r&&!s?null:{ae:i,src:r,preset:s,volume:Dt(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function Wt(e,t){return mi(e,t)[0]}function mi(e,t){e.updateMatrixWorld(!0);let i=[],r=0,s=[],n=[],a=[],o=[],l=new Set,h=[],u=[],f=new Map,g=[],w=[],p=[],b=new Map,T=[],x=[];function M(A){let _=f.get(A);if(_!==void 0)return _;_=u.length,f.set(A,_);let d=A,R=d.color?.r??1,G=d.color?.g??1,H=d.color?.b??1,B=d.opacity??1,Z={baseColorFactor:[R,G,H,B],metallicFactor:d.metalness??0,roughnessFactor:d.roughness??.5},k={},Y=O=>{if(!O)return;let j=(typeof O=="string"?O:typeof O.source=="string"?O.source:typeof O.image=="string"?O.image:"").trim();if(!j||/[\x00-\x1f\x7f\\]|\.\./.test(j)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(j)||!j.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(j)))return;let q=b.get(j);if(q===void 0){let K=g.length;g.push({uri:j}),w.length===0&&w.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),q=p.length,p.push({sampler:0,source:K}),b.set(j,q)}return{index:q}},rt=Y(d.map);rt&&(Z.baseColorTexture=rt);let st=Y(d.roughnessMap||d.metalnessMap);st&&(Z.metallicRoughnessTexture=st);let $=d.map?.avgColor;Array.isArray($)&&$.length>=3&&(k.avgColor=[$[0],$[1],$[2]]);let J=Y(d.normalMap),V=Y(d.emissiveMap),W=Y(d.aoMap),X={name:d.name||"",pbrMetallicRoughness:Z,doubleSided:d.side===2||!!d.doubleSided,...J?{normalTexture:J}:{},...V?{emissiveTexture:V}:{},...W?{occlusionTexture:W}:{},...Object.keys(k).length>0?{extras:k}:{}};if(d.emissive&&(d.emissive.r>0||d.emissive.g>0||d.emissive.b>0)){let O=d.emissiveIntensity??1;X.emissiveFactor=[d.emissive.r*O,d.emissive.g*O,d.emissive.b*O]}let U={};return d.clearcoat&&d.clearcoat>0&&(U.KHR_materials_clearcoat={clearcoatFactor:d.clearcoat,clearcoatRoughnessFactor:d.clearcoatRoughness||0}),d.sheen&&d.sheen>0&&(U.KHR_materials_sheen={sheenColorFactor:d.sheenColor?[d.sheenColor.r,d.sheenColor.g,d.sheenColor.b]:[1,1,1],sheenRoughnessFactor:d.sheenRoughness||0}),d.transmission&&d.transmission>0&&(U.KHR_materials_transmission={transmissionFactor:d.transmission}),d.thickness&&d.thickness>0&&(U.KHR_materials_volume={thicknessFactor:d.thickness,attenuationDistance:d.attenuationDistance??1/0,attenuationColor:d.attenuationColor?[d.attenuationColor.r,d.attenuationColor.g,d.attenuationColor.b]:[1,1,1]}),d.ior!==void 0&&d.ior!==1.5&&(U.KHR_materials_ior={ior:d.ior}),d.dispersion&&d.dispersion>0&&(U.KHR_materials_dispersion={dispersion:d.dispersion}),d.iridescence&&d.iridescence>0&&(U.KHR_materials_iridescence={iridescenceFactor:d.iridescence,iridescenceIor:d.iridescenceIOR??1.3}),Object.keys(U).length>0&&(X.extensions=U),u.push(X),_}function c(A,_){let d=new Uint8Array(A.buffer,A.byteOffset,A.byteLength),R=ss(d.byteLength),G=new Uint8Array(R);G.set(d),i.push(G);let H=s.length;return s.push({buffer:0,byteOffset:r,byteLength:d.byteLength,target:_}),r+=R,H}function m(A,_,d,R,G,H,B){let Z=c(A,d),k=n.length,Y={bufferView:Z,byteOffset:0,componentType:R,count:G,type:_};return H&&(Y.min=H),B&&(Y.max=B),n.push(Y),k}e.traverse(A=>{if(A.isLight||A.color&&A.intensity!==void 0){let _=A.matrixWorld?.elements,d=tt(_?_[12]:A.position?.x,0),R=tt(_?_[13]:A.position?.y,0),G=tt(_?_[14]:A.position?.z,0),H=A.target,B=H?.parent?H?.matrixWorld?.elements:void 0,Z=tt(B?B[12]:H?.position?.x,0),k=tt(B?B[13]:H?.position?.y,0),Y=tt(B?B[14]:H?.position?.z,0),rt=Z-d,st=k-R,$=Y-G,J=Math.hypot(rt,st,$),V=Math.max(.01,Math.min(Math.PI/2,tt(A.angle,Math.PI/3))),W=Math.max(0,Math.min(1,tt(A.penumbra,0)));x.push({type:A.type,color:[A.color.r,A.color.g,A.color.b],intensity:A.intensity,position:[d,R,G],...A.type==="spot"?{direction:J>1e-6?[rt/J,st/J,$/J]:[0,-1,0],outerConeAngle:V,innerConeAngle:Math.max(0,V*(1-W)),range:Math.max(0,tt(A.distance,0))}:A.type==="point"?{range:Math.max(0,tt(A.distance,0))}:{}})}});let v=[],S=new Set([e]),D=[];if(Array.isArray(e.children))for(let A=e.children.length-1;A>=0;A--)D.push({obj:e.children[A],parentKids:v});for(;D.length>0;){let{obj:A,parentKids:_}=D.pop();if(!A||typeof A!="object"||S.has(A))continue;S.add(A),A._bakeAuthorGeometry?.(),mt().materializeDeclarativeGeometry?.(A);let d=!!(A.userData&&(A.userData.xr&&typeof A.userData.xr=="object"&&Object.keys(A.userData.xr).length>0||A.userData.interactivity&&typeof A.userData.interactivity=="object"&&Object.keys(A.userData.interactivity).length>0)),R={name:A.name||(d?`Node_${o.length}`:"")},G=tt(A.position?.x,0),H=tt(A.position?.y,0),B=tt(A.position?.z,0),Z=tt(A.quaternion?.x,0),k=tt(A.quaternion?.y,0),Y=tt(A.quaternion?.z,0),rt=tt(A.quaternion?.w,1),st=tt(A.scale?.x,1),$=tt(A.scale?.y,1),J=tt(A.scale?.z,1);if((G||H||B)&&(R.translation=[G,H,B]),(Z||k||Y||rt!==1)&&(R.rotation=[Z,k,Y,rt]),(st!==1||$!==1||J!==1)&&(R.scale=[st,$,J]),A.visible===!1&&(R.extensions={...R.extensions||{},KHR_node_visibility:{visible:!1}},l.add("KHR_node_visibility")),A.userData&&Object.keys(A.userData).length>0&&(R.extras=JSON.parse(JSON.stringify(A.userData,(X,U)=>{if(!(X==="__proto__"||X==="prototype"||X==="constructor"))return typeof U=="function"?void 0:U})),A.userData.xr)){let X=ns(A.userData.xr);R.extensions={...R.extensions||{},MOZ_hubs_components:X,ANDROID_xr_scenecore:X},mt().xrTraitSerializer?.gltfNode(R,A.userData.xr),l.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(A.geometry){let X=A.geometry,U=X.attributes.position;if(U&&U.count>0){let O=[1/0,1/0,1/0],j=[-1/0,-1/0,-1/0];for(let nt=0;nt<U.count;nt++){let at=U.getX(nt),ot=U.getY(nt),lt=U.getZ(nt);at<O[0]&&(O[0]=at),at>j[0]&&(j[0]=at),ot<O[1]&&(O[1]=ot),ot>j[1]&&(j[1]=ot),lt<O[2]&&(O[2]=lt),lt>j[2]&&(j[2]=lt)}let q={attributes:{POSITION:m(U.array,"VEC3",34962,5126,U.count,O,j)}};if(X.attributes.normal&&(q.attributes.NORMAL=m(X.attributes.normal.array,"VEC3",34962,5126,X.attributes.normal.count)),X.attributes.uv&&(q.attributes.TEXCOORD_0=m(X.attributes.uv.array,"VEC2",34962,5126,X.attributes.uv.count)),X.index){let nt=X.index.array instanceof Uint32Array;q.indices=m(X.index.array,"SCALAR",34963,nt?5125:5123,X.index.count)}let K=Array.isArray(A.material)?A.material[0]:A.material;K&&(q.material=M(K));let et=A.userData?.variants;if(et&&typeof et=="object"){let nt=new Map;for(let at of Object.keys(et)){if(!at||at==="__proto__"||at==="constructor"||at==="prototype")continue;let ot=et[at];if(!ot||typeof ot!="object")continue;let lt=T.indexOf(at);if(lt===-1&&T.length<256&&(lt=T.length,T.push(at)),lt===-1)continue;let Mt=M(ot),St=nt.get(Mt);St||(St=[],nt.set(Mt,St)),St.push(lt)}if(nt.size>0){let at=[];for(let[ot,lt]of nt.entries())at.push({material:ot,variants:lt});q.extensions={...q.extensions||{},KHR_materials_variants:{mappings:at}},l.add("KHR_materials_variants")}}let it=A;if(it.isInstancedMesh&&typeof it.count=="number"&&it.count>0&&it.instanceMatrix?.array){let nt=Math.min(1e4,Math.floor(it.count)),at=it.instanceMatrix.array,ot=new Float32Array(nt*3),lt=new Float32Array(nt*4),Mt=new Float32Array(nt*3);for(let ut=0;ut<nt;ut++){let{t:Rt,r:Bt,s:ye}=ui(at,ut*16);ot[ut*3]=Rt[0],ot[ut*3+1]=Rt[1],ot[ut*3+2]=Rt[2],lt[ut*4]=Bt[0],lt[ut*4+1]=Bt[1],lt[ut*4+2]=Bt[2],lt[ut*4+3]=Bt[3],Mt[ut*3]=ye[0],Mt[ut*3+1]=ye[1],Mt[ut*3+2]=ye[2]}let St={TRANSLATION:m(ot,"VEC3",0,5126,nt),ROTATION:m(lt,"VEC4",0,5126,nt),SCALE:m(Mt,"VEC3",0,5126,nt)};if(it.instanceColor?.array&&it.instanceColor.array.length>=nt*3){let ut=new Float32Array(it.instanceColor.array.subarray(0,nt*3));St._COLOR_0=m(ut,"VEC3",0,5126,nt)}R.extensions={...R.extensions||{},EXT_mesh_gpu_instancing:{attributes:St}},l.add("EXT_mesh_gpu_instancing")}let dt=a.length;a.push({primitives:[q],name:A.name,...R.extras?{extras:R.extras}:{}}),R.mesh=dt}}let V=o.length;o.push(R),h.push(A),_.push(V);let W=A.children;if(Array.isArray(W)&&W.length>0){let X=[];R.children=X;for(let U=W.length-1;U>=0;U--)D.push({obj:W[U],parentKids:X})}}for(let A=0;A<o.length;A++){let _=o[A];_.children&&_.children.length===0?delete _.children:_.children&&_.children.length>0&&(_.extras?.xr?.lod||_.extensions?.ANDROID_xr_scenecore?.lod||h[A]?.isLOD)&&(_.extensions={..._.extensions||{},MSFT_lod:{ids:[..._.children]}},l.add("MSFT_lod"))}let I=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),P=[];if(typeof I=="function"&&h.length>0){let A=t?.duration??4,_=t?.fps??15,d=Math.max(2,Math.round(A*_)+1),R=new Float32Array(d),G=h.map($=>[tt($.position?.x,0),tt($.position?.y,0),tt($.position?.z,0),tt($.quaternion?.x,0),tt($.quaternion?.y,0),tt($.quaternion?.z,0),tt($.quaternion?.w,1),tt($.scale?.x,1),tt($.scale?.y,1),tt($.scale?.z,1)]),H=h.map(()=>new Float32Array(d*3)),B=h.map(()=>new Float32Array(d*4)),Z=h.map(()=>new Float32Array(d*3));for(let $=0;$<d;$++){let J=$/(d-1)*A;R[$]=J;try{I(J)}catch{}for(let V=0;V<h.length;V++){let W=h[V];H[V][$*3]=tt(W.position?.x,0),H[V][$*3+1]=tt(W.position?.y,0),H[V][$*3+2]=tt(W.position?.z,0);let X=tt(W.quaternion?.x,0),U=tt(W.quaternion?.y,0),O=tt(W.quaternion?.z,0),j=tt(W.quaternion?.w,1),q=Math.hypot(X,U,O,j)||1;if(X/=q,U/=q,O/=q,j/=q,$>0){let K=($-1)*4,et=B[V];et[K]*X+et[K+1]*U+et[K+2]*O+et[K+3]*j<0&&(X=-X,U=-U,O=-O,j=-j)}B[V][$*4]=X,B[V][$*4+1]=U,B[V][$*4+2]=O,B[V][$*4+3]=j,Z[V][$*3]=tt(W.scale?.x,1),Z[V][$*3+1]=tt(W.scale?.y,1),Z[V][$*3+2]=tt(W.scale?.z,1)}}for(let $=0;$<h.length;$++){let J=h[$],V=G[$];J.position?.set(V[0],V[1],V[2]),J.quaternion?.set(V[3],V[4],V[5],V[6]),J.scale?.set(V[7],V[8],V[9])}e.updateMatrixWorld(!0);let k=null,Y=()=>(k===null&&(k=m(R,"SCALAR",0,5126,d,[0],[A])),k),rt=[],st=[];for(let $=0;$<h.length;$++){let J=G[$],V=(X,U,O)=>X.some((j,q)=>Math.abs(j-J[O+q%U])>1e-4),W=(X,U,O,j)=>{X&&st.push({sampler:rt.push({input:Y(),interpolation:"LINEAR",output:m(U,O,0,5126,d)})-1,target:{node:$,path:j}})};W(V(H[$],3,0),H[$],"VEC3","translation"),W(V(B[$],4,3),B[$],"VEC4","rotation"),W(V(Z[$],3,7),Z[$],"VEC3","scale")}st.length>0&&P.push({name:"ProceduralLoop",samplers:rt,channels:st})}let N=kr(o,a,e.userData),C=[],L=[],E=[];for(let A=0;A<o.length;A++){let _=o[A],d=ci(_.extras?.xr);if(!d)continue;let{ae:R,src:G,preset:H,volume:B,loop:Z,isGlobal:k}=d,Y=_.name||`Node_${A}`,rt=L.length;L.push({name:`${Y}_source`,gain:B,loop:Z,autoPlay:typeof R.autoplay=="boolean"?R.autoplay:!0,...G!==void 0?{audio:C.push({uri:G})-1}:{},...H?{extras:{preset:H,pitch:Dt(R.pitch,.25,4,1)}}:{}});let st=E.length,$=Dt(R.refDistance,.05,100,1),J=Dt(R.coneInnerAngle,0,360,360),V=Dt(R.coneOuterAngle,J,360,360);E.push({name:`${Y}_emitter`,type:k?"global":"positional",gain:B,sources:[rt],...k?{}:{positional:{distanceModel:R.distanceModel==="linear"||R.distanceModel==="exponential"?R.distanceModel:"inverse",refDistance:$,maxDistance:Dt(R.maxDistance,$,500,Math.max($,25)),rolloffFactor:Dt(R.rolloffFactor,0,10,1),coneInnerAngle:+(J*Math.PI/180).toFixed(6),coneOuterAngle:+(V*Math.PI/180).toFixed(6),coneOuterGain:Dt(R.coneOuterGain,0,1,0)}}}),_.extensions={..._.extensions||{},KHR_audio_emitter:{emitter:st}},l.add("KHR_audio_emitter")}let y={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:v}],scene:0,nodes:o,meshes:a,materials:u,...g.length>0?{images:g}:{},...w.length>0?{samplers:w}:{},...p.length>0?{textures:p}:{},accessors:n,bufferViews:s,buffers:[{byteLength:r}],...P.length>0?{animations:P}:{},...N||l.size>0?{extensionsUsed:[...N?["KHR_interactivity"]:[],...l]}:{},...N||T.length>0||E.length>0?{extensions:{...N?{KHR_interactivity:N}:{},...T.length>0?{KHR_materials_variants:{variants:T.map(A=>({name:A}))}}:{},...E.length>0?{KHR_audio_emitter:{...C.length>0?{audio:C}:{},sources:L,emitters:E}}:{}}}:{}},F=new Uint8Array(r),z=0;for(let A of i)F.set(A,z),z+=A.byteLength;return[{gltf:y,bin:F.buffer,lights:x,environmentIntensity:e.environmentIntensity},h]}function Re(e){return new TextEncoder().encode(e)}function ie(e,t){let{gltf:i,bin:r}=Wt(e,t),s=JSON.stringify(i),n=Re(s),a=(4-n.byteLength%4)%4,o=n.byteLength+a,l=20+o+8+r.byteLength,h=new Uint8Array(l),u=new DataView(h.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,l,!0),u.setUint32(12,o,!0),u.setUint32(16,1313821514,!0),h.set(n,20);for(let g=0;g<a;g++)h[20+n.byteLength+g]=32;let f=20+o;return u.setUint32(f,r.byteLength,!0),u.setUint32(f+4,5130562,!0),h.set(new Uint8Array(r),f+8),h}function as(e,t){let[i,r]=mi(e,t);return pi(i,r)}function pi(e,t){let i=[],r=e.gltf,s=mt().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,e);let n=e.bin,a=n instanceof ArrayBuffer?n:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),o=r.accessors||[],l=r.bufferViews||[],h=r.materials||[],u=r.meshes||[],f=r.nodes||[],g=r.textures||[],w=r.images||[],p=r.samplers||[],b=new Set,T=h.map((S,D)=>hi(b,re(S?.name,`Material_${D}`))),x=new Map;function M(S){let D=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(S);if(!D)return null;let I=D[2].replace(/\s+/g,""),P=I.endsWith("==")?2:I.endsWith("=")?1:0,N=new Uint8Array((I.length*3>>2)-P),C=E=>{let y=I.charCodeAt(E);return y>96?y-71:y>64?y-65:y>47?y+4:y===43?62:y===47?63:0},L=0;for(let E=0;E<I.length;E+=4){let y=C(E)<<18|C(E+1)<<12|C(E+2)<<6|C(E+3);N[L++]=y>>16&255,L<N.length&&(N[L++]=y>>8&255),L<N.length&&(N[L++]=y&255)}return N}function c(S,D,I){let P=S?.index;if(typeof P!="number")return;let N=g[P],C=N?.source;if(typeof C!="number"||!w[C])return;let L=x.get(C);if(L===void 0){L=null;let F=w[C],z=null;if(typeof F.bufferView=="number"){let A=l[F.bufferView],_=A?.byteOffset||0,d=A?.byteLength||0;A&&d>0&&_>=0&&_+d<=a.byteLength&&(z=new Uint8Array(a,_,d))}else typeof F.uri=="string"&&(z=M(F.uri));if(z&&z.byteLength>0){let A=z[0]===255&&z[1]===216&&z[2]===255||!(z[0]===137&&z[1]===80)&&/jpe?g/i.test(F.mimeType||F.uri||"");L={file:`texture_${C}.${A?"jpg":"png"}`,data:z}}x.set(C,L)}if(!L)return;let E=typeof N.sampler=="number"?p[N.sampler]:void 0,y=F=>F===33071?"clamp":F===33648?"mirror":"repeat";return{file:L.file,data:L.data,wrapS:y(E?.wrapS),wrapT:y(E?.wrapT),...D?{scale:D}:{},...I?{bias:I}:{}}}function m(S){let D=o[S];if(!D)throw new Error(`Accessor ${S} not found`);let I=l[D.bufferView||0],P=(I.byteOffset||0)+(D.byteOffset||0),N=I.byteLength||0;return{acc:D,buffer:a.slice(P,P+N)}}function v(S,D,I,P){let N=[],C=u[S];if(!C)return N;let L=C.primitives||[];for(let E=0;E<L.length;E++){let y=L[E],F=y.attributes?.POSITION;if(F===void 0)continue;let{acc:z,buffer:A}=m(F),_=new Float32Array(A,0,z.count*3),d,R=y.attributes?.NORMAL;if(R!==void 0){let{acc:U,buffer:O}=m(R),j=new Float32Array(O,0,U.count*3);d=new Float32Array(j.length);for(let q=0;q<U.count;q++){let K=j[q*3],et=j[q*3+1],it=j[q*3+2],dt=Math.hypot(K,et,it)||1;d[q*3]=K/dt,d[q*3+1]=et/dt,d[q*3+2]=it/dt}}let G,H=y.attributes?.TEXCOORD_0;if(H!==void 0){let{acc:U,buffer:O}=m(H);G=new Float32Array(O,0,U.count*2)}let B;if(y.indices!==void 0){let{acc:U,buffer:O}=m(y.indices);B=U.componentType===5125?new Uint32Array(O,0,U.count):new Uint16Array(O,0,U.count);let j=z.count;for(let q of B)if(q>=j)throw new Error(`SecurityError: Index buffer value (${q}) out of vertex bounds [0, ${j}).`)}else{let U=z.count;B=U>65535?new Uint32Array(U):new Uint16Array(U);for(let O=0;O<U;O++)B[O]=O}let Z="DefaultMaterial",k=[1,1,1],Y=.5,rt=0,st=0,$=0,J=1.5,V=1,W=[0,0,0],X;if(y.material!==void 0&&h[y.material]){let U=h[y.material];Z=T[y.material]||`Material_${y.material}`;let O=U.pbrMetallicRoughness||{},j=(Rt,Bt)=>Array.isArray(Rt)&&Rt.length>=3?[Rt[0],Rt[1],Rt[2]]:Bt;k=j(O.baseColorFactor,[1,1,1]);let q=Array.isArray(O.baseColorFactor)&&typeof O.baseColorFactor[3]=="number"?O.baseColorFactor[3]:1,K=k[0]!==1||k[1]!==1||k[2]!==1||q!==1,et=c(O.baseColorTexture,K?[k[0],k[1],k[2],q]:void 0),it=U.extras?.avgColor;!et&&Array.isArray(it)&&it.length>=3&&(k=[k[0]*it[0],k[1]*it[1],k[2]*it[2]]),typeof O.roughnessFactor=="number"&&(Y=O.roughnessFactor),typeof O.metallicFactor=="number"&&(rt=O.metallicFactor);let dt=typeof O.roughnessFactor=="number"?O.roughnessFactor:1,nt=typeof O.metallicFactor=="number"?O.metallicFactor:1,at=c(O.metallicRoughnessTexture,dt!==1||nt!==1?[1,dt,nt,1]:void 0);W=j(U.emissiveFactor,[0,0,0]);let ot=(W[0]>0||W[1]>0||W[2]>0)&&(W[0]!==1||W[1]!==1||W[2]!==1)?[W[0],W[1],W[2],1]:void 0,lt=c(U.emissiveTexture,ot),Mt=c(U.normalTexture,[2,2,2,1],[-1,-1,-1,0]),St=c(U.occlusionTexture);(et||at||Mt||lt||St)&&(X=[et,at,Mt,lt,St]);let ut=U.extensions||{};ut.KHR_materials_clearcoat&&(st=ut.KHR_materials_clearcoat.clearcoatFactor??0,$=ut.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof ut.KHR_materials_ior?.ior=="number"&&(J=ut.KHR_materials_ior.ior),V=q*(1-(ut.KHR_materials_transmission?.transmissionFactor??0))}N.push({name:L.length>1?`${D}_p${E}`:D,positions:_,indices:B,normals:d,uvs:G,materialName:Z,color:k,roughness:Y,metallic:rt,clearcoat:st,clearcoatRoughness:$,ior:J,opacity:V,emissiveColor:W,...X?{textures:X}:{},xrTraits:I||C.extras?.xr,...P?{invisible:!0}:{}})}return N}if(f.length>0){let S=new Float32Array(0),D=new Uint16Array(0),I=(_,d)=>{if(_===void 0)return null;let{acc:R,buffer:G}=m(_);return new Float32Array(G,0,R.count*d)},P=(_,d)=>Array.isArray(_)&&_.length>=3?[tt(_[0],d),tt(_[1],d),tt(_[2],d)]:[d,d,d],N=(_,d,R)=>_&&_.length>=(d+1)*3?[_[d*3],_[d*3+1],_[d*3+2]]:R,C=(_,d,R)=>_&&_.length>=(d+1)*4?[_[d*4],_[d*4+1],_[d*4+2],_[d*4+3]]:R,L=new Map,E=r.animations?.[0];if(E&&Array.isArray(E.channels)&&Array.isArray(E.samplers))for(let _ of E.channels){let d=E.samplers[_?.sampler],R=_?.target?.node,G=_?.target?.path;if(!d||typeof R!="number"||d.input===void 0)continue;let H=L.get(R);H||(H={input:d.input},L.set(R,H)),G==="translation"?H.t=d.output:G==="rotation"?H.r=d.output:G==="scale"&&(H.s=d.output)}let y=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(y)||y.length===0){let _=new Set;for(let d of f)if(Array.isArray(d?.children))for(let R of d.children)_.add(R);y=[];for(let d=0;d<f.length;d++)_.has(d)||y.push(d);y.length===0&&(y=[0])}let F=new Set,z=[],A=(_,d)=>{if(Array.isArray(_))for(let R=_.length-1;R>=0;R--)z.push({idx:_[R],out:d})};for(A(y,i);z.length>0;){let{idx:_,out:d}=z.pop();if(typeof _!="number"||_<0||_>=f.length||F.has(_))continue;F.add(_);let R=f[_];if(!R)continue;let G=[0,0,0],H=[0,0,0,1],B=[1,1,1];if(Array.isArray(R.matrix)&&R.matrix.length===16){let V=ui(R.matrix);G=V.t,H=V.r,B=V.s}else G=P(R.translation,0),Array.isArray(R.rotation)&&R.rotation.length>=4&&(H=[tt(R.rotation[0],0),tt(R.rotation[1],0),tt(R.rotation[2],0),tt(R.rotation[3],1)]),B=P(R.scale,1);let Z,k=L.get(_);if(k){let V=I(k.input,1);if(V&&V.length>0){let W=I(k.t,3),X=I(k.r,4),U=I(k.s,3),O=Array.from(V),j=[],q=[],K=[];for(let et=0;et<V.length;et++)j.push(N(W,et,G)),q.push(C(X,et,H)),K.push(N(U,et,B));Z={times:O,translations:j,rotations:q,scales:K}}}let Y=Array.isArray(R.children)?R.children:[],rt=typeof R.mesh=="number"&&R.mesh>=0&&R.mesh<u.length,st=t?.[_]?.userData?.xr??R.extras?.xr;if(!rt&&Y.length===0&&(R.camera!==void 0||R.extensions?.KHR_lights_punctual||!R.name&&!R.extras&&!st&&!Z))continue;let $=(V,W,X)=>({name:V,positions:S,indices:D,isXform:!0,xrTraits:st,timeSamples:Z,translation:G,rotation:H,scale:B,children:W,...X?{invisible:!0}:{}}),J=R.visible===!1||R.extensions?.KHR_node_visibility?.visible===!1||t?.[_]?.visible===!1;if(rt){let V=R.name||u[R.mesh]?.name||`Mesh_${_}`,W=v(R.mesh,V,st,J),X=R.extensions?.EXT_mesh_gpu_instancing?.attributes;if(X&&typeof X=="object"&&W.length>0){let U=I(X.TRANSLATION,3),O=I(X.ROTATION,4),j=I(X.SCALE,3),q=I(X._COLOR_0,3),K=Math.min(1e3,U?U.length/3:O?O.length/4:j?j.length/3:0);if(K>0){let et=[];for(let it=0;it<K;it++){let dt=N(U,it,[0,0,0]),nt=C(O,it,[0,0,0,1]),at=N(j,it,[1,1,1]);for(let ot of W){let lt=ot.color||[.8,.8,.8],Mt=q&&q.length>=(it+1)*3;et.push({...ot,name:`${ot.name}_${it}`,materialName:Mt?`${ot.materialName}_inst_${it}`:ot.materialName,color:Mt?[lt[0]*q[it*3],lt[1]*q[it*3+1],lt[2]*q[it*3+2]]:ot.color,translation:dt,rotation:nt,scale:at})}}A(Y,et),d.push($(V,et,J));continue}}if(W.length===1)W[0].translation=G,W[0].rotation=H,W[0].scale=B,W[0].timeSamples=Z,Y.length>0&&(W[0].children=[],A(Y,W[0].children)),d.push(W[0]);else{let U=[...W];A(Y,U),d.push($(V,U,J))}}else{let V=[];A(Y,V),d.push($(R.name||`Group_${_}`,V,J))}}}else for(let S=0;S<u.length;S++){let D=u[S].name||`Mesh_${S}`;i.push(...v(S,D,u[S].extras?.xr))}return i}function re(e,t){if(!e||typeof e!="string")return t;let i=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||t}function se(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function gt(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var _t=(e,t,i)=>`(${gt(e)}, ${gt(t)}, ${gt(i)})`,ne=(e,t,i,r)=>`(${gt(e)}, ${gt(t)}, ${gt(i)}, ${gt(r)})`;function fi(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=_t(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function os(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${gt(e[r*2])}, ${gt(1-e[r*2+1])})`;return i.join(", ")}function ls(e){return Array.from(e).join(", ")}function hs(e){let t=new Map,i=0,r=null,s=[...e];for(;s.length>0;){let p=s.pop();if(!p.isXform&&p.positions&&p.positions.length>0){let b=re(p.materialName,"DefaultMaterial");t.has(b)||t.set(b,{color:p.color||[1,1,1],roughness:p.roughness??.5,metallic:p.metallic??0,clearcoat:p.clearcoat??0,clearcoatRoughness:p.clearcoatRoughness??0,ior:p.ior??1.5,opacity:p.opacity??1,emissiveColor:p.emissiveColor||[0,0,0],textures:p.textures})}if(p.timeSamples&&p.timeSamples.times.length>0){let b=p.timeSamples.times[p.timeSamples.times.length-1];b>i&&(i=b)}if(p.xrTraits?.anchor&&!r&&(r=p.xrTraits.anchor==="vertical"||p.xrTraits.anchor==="wall"?"vertical":"horizontal"),p.children)for(let b=p.children.length-1;b>=0;b--)s.push(p.children[b])}let n="";i>0&&(n=`startTimeCode = 0
|
|
250
|
+
endTimeCode = ${gt(i)}
|
|
251
251
|
timeCodesPerSecond = 1.0
|
|
252
|
-
`);let
|
|
252
|
+
`);let a="";r&&(a=`uniform token preliminary:anchoring:type = "plane"
|
|
253
253
|
uniform token preliminary:planeAnchoring:alignment = "${r}"
|
|
254
|
-
`);let
|
|
254
|
+
`);let o=`#usda 1.0
|
|
255
255
|
(
|
|
256
256
|
defaultPrim = "Root"
|
|
257
257
|
metersPerUnit = 1.0
|
|
@@ -262,90 +262,117 @@ def Xform "Root" (
|
|
|
262
262
|
kind = "component"
|
|
263
263
|
)
|
|
264
264
|
{
|
|
265
|
-
${
|
|
265
|
+
${a}def Scope "Materials"
|
|
266
|
+
{
|
|
267
|
+
`;for(let[p,b]of t.entries()){let[T,x,M]=b.color,[c,m,v]=b.emissiveColor,S=`/Root/Materials/${p}`,[D,I,P,N,C]=b.textures||[],L=(A,_)=>`.connect = <${S}/${A}.outputs:${_}>`,E=D?`color3f inputs:diffuseColor${L("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${_t(T,x,M)}`,y=I?`float inputs:metallic${L("MetallicRoughnessTexture","b")}
|
|
268
|
+
float inputs:roughness${L("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${gt(b.metallic)}
|
|
269
|
+
float inputs:roughness = ${gt(b.roughness)}`,F="";b.clearcoat>0&&(F+=`float inputs:clearcoat = ${gt(b.clearcoat)}
|
|
270
|
+
`,F+=`float inputs:clearcoatRoughness = ${gt(b.clearcoatRoughness)}
|
|
271
|
+
`),b.ior!==1.5&&(F+=`float inputs:ior = ${gt(b.ior)}
|
|
272
|
+
`),b.opacity<1&&(F+=`float inputs:opacity = ${gt(b.opacity)}
|
|
273
|
+
`),N?F+=`color3f inputs:emissiveColor${L("EmissiveTexture","rgb")}
|
|
274
|
+
`:(c>0||m>0||v>0)&&(F+=`color3f inputs:emissiveColor = ${_t(c,m,v)}
|
|
275
|
+
`),P&&(F+=`normal3f inputs:normal${L("NormalTexture","rgb")}
|
|
276
|
+
`),C&&(F+=`float inputs:occlusion${L("OcclusionTexture","r")}
|
|
277
|
+
`);let z="";if(D||I||P||N||C){z+=`def Shader "PrimvarReader"
|
|
266
278
|
{
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
279
|
+
uniform token info:id = "UsdPrimvarReader_float2"
|
|
280
|
+
string inputs:varname = "st"
|
|
281
|
+
float2 outputs:result
|
|
282
|
+
}
|
|
283
|
+
`;let A=(_,d,R,G)=>{if(!d)return;let H=d.scale?`float4 inputs:scale = ${ne(d.scale[0],d.scale[1],d.scale[2],d.scale[3])}
|
|
284
|
+
`:"",B=d.bias?`float4 inputs:bias = ${ne(d.bias[0],d.bias[1],d.bias[2],d.bias[3])}
|
|
285
|
+
`:"";z+=`def Shader "${_}"
|
|
286
|
+
{
|
|
287
|
+
uniform token info:id = "UsdUVTexture"
|
|
288
|
+
asset inputs:file = @${se(d.file)}@
|
|
289
|
+
float2 inputs:st${L("PrimvarReader","result")}
|
|
290
|
+
token inputs:sourceColorSpace = "${R}"
|
|
291
|
+
token inputs:wrapS = "${d.wrapS||"repeat"}"
|
|
292
|
+
token inputs:wrapT = "${d.wrapT||"repeat"}"
|
|
293
|
+
${H}${B}${G}}
|
|
294
|
+
`};A("DiffuseTexture",D,"sRGB",`float3 outputs:rgb
|
|
295
|
+
`),A("MetallicRoughnessTexture",I,"raw",`float outputs:g
|
|
296
|
+
float outputs:b
|
|
297
|
+
`),A("NormalTexture",P,"raw",`float3 outputs:rgb
|
|
298
|
+
`),A("EmissiveTexture",N,"sRGB",`float3 outputs:rgb
|
|
299
|
+
`),A("OcclusionTexture",C,"raw",`float outputs:r
|
|
300
|
+
`)}o+=`def Material "${p}"
|
|
273
301
|
{
|
|
274
302
|
def Shader "PBRShader"
|
|
275
303
|
{
|
|
276
304
|
uniform token info:id = "UsdPreviewSurface"
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
${R}token outputs:surface
|
|
281
|
-
}
|
|
282
|
-
token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
|
|
305
|
+
${E}
|
|
306
|
+
${y}
|
|
307
|
+
${F}token outputs:surface
|
|
283
308
|
}
|
|
284
|
-
|
|
309
|
+
token outputs:surface${L("PBRShader","surface")}
|
|
310
|
+
${z}}
|
|
311
|
+
`}o+=`}
|
|
285
312
|
def Scope "Meshes"
|
|
286
313
|
{
|
|
287
|
-
`;let
|
|
314
|
+
`;let l=(p,b,T)=>{let x=[];b&&x.push('"MaterialBindingAPI"');let M=!!(p?.rigidBody&&p.rigidBody!=="none"&&(typeof p.rigidBody!="object"||p.rigidBody.enabled!==!1)),c=!!(p?.physics&&p.physics!=="none"||M);c&&x.push(...M?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let m=[];if(x.length>0&&m.push(`prepend apiSchemas = [${x.join(", ")}]`),p){let P=mt().xrTraitSerializer?.usdLines(p,se)??[];if(!P.length)for(let N of["grab","billboard","follow","anchor","physics"]){let C=N==="follow"&&typeof p.follow=="object"?p.follow.mode??"head":p[N];C!==void 0&&P.push(`string ${N} = "${se(C)}"`)}P.length>0&&m.push(`customData = {
|
|
288
315
|
dictionary xr = {
|
|
289
|
-
${
|
|
316
|
+
${P.join(`
|
|
290
317
|
`)}
|
|
291
318
|
}
|
|
292
|
-
}`)}let v=
|
|
293
|
-
${
|
|
319
|
+
}`)}let v=m.length>0?` (
|
|
320
|
+
${m.join(`
|
|
294
321
|
`)}
|
|
295
|
-
)`:"",
|
|
296
|
-
`:"";if(
|
|
297
|
-
bool physics:kinematicEnabled = ${
|
|
322
|
+
)`:"",S=T?`uniform token visibility = "invisible"
|
|
323
|
+
`:"";if(c){let P=p?.rigidBody??p?.physics,N=P?.body??P?.mode??P;S+=`bool physics:rigidBodyEnabled = true
|
|
324
|
+
bool physics:kinematicEnabled = ${N==="static"||N==="kinematic"}
|
|
298
325
|
bool physics:collisionEnabled = true
|
|
299
|
-
`,
|
|
300
|
-
`)}let
|
|
326
|
+
`,P?.mass>0&&Number.isFinite(P.mass)&&(S+=`float physics:mass = ${gt(P.mass)}
|
|
327
|
+
`)}let D=ci(p),I=D?`def SpatialAudio "AudioEmitter"
|
|
301
328
|
{
|
|
302
|
-
${
|
|
303
|
-
`:""}uniform token inputs:auralMode = "${
|
|
304
|
-
uniform token inputs:playbackMode = "${
|
|
305
|
-
double gain = ${
|
|
329
|
+
${D.src?`asset inputs:file = @${se(D.src)}@
|
|
330
|
+
`:""}uniform token inputs:auralMode = "${D.isGlobal?"nonSpatial":"spatial"}"
|
|
331
|
+
uniform token inputs:playbackMode = "${D.loop?"loopFromStart":"onceFromStart"}"
|
|
332
|
+
double gain = ${gt(D.volume)}
|
|
306
333
|
}
|
|
307
|
-
`:"";return{header:v,body:
|
|
308
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
334
|
+
`:"";return{header:v,body:S,tail:I}},h=p=>{if(p.timeSamples&&p.timeSamples.times.length>0){let m=p.timeSamples,v=(P,N,C)=>m.times.map((L,E)=>`${gt(L)}: ${C(P?.[E]||N)}`).join(", "),S=v(m.translations,[0,0,0],P=>_t(P[0],P[1],P[2])),D=v(m.rotations,[0,0,0,1],P=>{let N=Math.hypot(P[0],P[1],P[2],P[3])||1;return ne(P[3]/N,P[0]/N,P[1]/N,P[2]/N)}),I=v(m.scales,[1,1,1],P=>_t(P[0],P[1],P[2]));return`double3 xformOp:translate.timeSamples = { ${S} }
|
|
335
|
+
quatf xformOp:orient.timeSamples = { ${D} }
|
|
309
336
|
double3 xformOp:scale.timeSamples = { ${I} }
|
|
310
337
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
311
|
-
`}let b=[],
|
|
312
|
-
`,b.push('"xformOp:translate"'));let
|
|
313
|
-
`,b.push('"xformOp:orient"'))}let
|
|
314
|
-
`,b.push('"xformOp:scale"')),b.length>0&&(
|
|
315
|
-
`),
|
|
338
|
+
`}let b=[],T="",x=p.translation;x&&(Math.abs(x[0])>1e-7||Math.abs(x[1])>1e-7||Math.abs(x[2])>1e-7)&&(T+=`double3 xformOp:translate = ${_t(x[0],x[1],x[2])}
|
|
339
|
+
`,b.push('"xformOp:translate"'));let M=p.rotation;if(M){let m=Math.hypot(M[0],M[1],M[2],M[3])||1,v=M[0]/m,S=M[1]/m,D=M[2]/m,I=M[3]/m;(1-Math.abs(I)>1e-7||Math.hypot(v,S,D)>1e-7)&&(T+=`quatf xformOp:orient = ${ne(I,v,S,D)}
|
|
340
|
+
`,b.push('"xformOp:orient"'))}let c=p.scale;return c&&(Math.abs(c[0]-1)>1e-7||Math.abs(c[1]-1)>1e-7||Math.abs(c[2]-1)>1e-7)&&(T+=`float3 xformOp:scale = ${_t(c[0],c[1],c[2])}
|
|
341
|
+
`,b.push('"xformOp:scale"')),b.length>0&&(T+=`uniform token[] xformOpOrder = [${b.join(", ")}]
|
|
342
|
+
`),T},u=p=>{let b=p.positions.length/3,T=1/0,x=1/0,M=1/0,c=-1/0,m=-1/0,v=-1/0;for(let N=0;N<b;N++){let C=p.positions[N*3],L=p.positions[N*3+1],E=p.positions[N*3+2];C<T&&(T=C),C>c&&(c=C),L<x&&(x=L),L>m&&(m=L),E<M&&(M=E),E>v&&(v=E)}isFinite(T)||(T=x=M=-1,c=m=v=1);let S=Math.floor(p.indices.length/3),D=re(p.materialName,"DefaultMaterial"),I=S>0?S===1?"3":"3, ".repeat(S-1)+"3":"",P=`float3[] extent = [${_t(T,x,M)}, ${_t(c,m,v)}]
|
|
316
343
|
int[] faceVertexCounts = [${I}]
|
|
317
|
-
int[] faceVertexIndices = [${
|
|
318
|
-
point3f[] points = [${
|
|
319
|
-
`;return
|
|
344
|
+
int[] faceVertexIndices = [${ls(p.indices)}]
|
|
345
|
+
point3f[] points = [${fi(p.positions)}]
|
|
346
|
+
`;return p.normals&&p.normals.length===p.positions.length&&(P+=`normal3f[] normals = [${fi(p.normals)}] (
|
|
320
347
|
interpolation = "vertex"
|
|
321
348
|
)
|
|
322
|
-
`),
|
|
349
|
+
`),p.uvs&&p.uvs.length===b*2&&(P+=`texCoord2f[] primvars:st = [${os(p.uvs,b)}] (
|
|
323
350
|
interpolation = "vertex"
|
|
324
351
|
)
|
|
325
|
-
`),
|
|
326
|
-
`,
|
|
327
|
-
`;continue}let{node:b,siblings:
|
|
352
|
+
`),P+=`rel material:binding = </Root/Materials/${D}>
|
|
353
|
+
`,P},f=new Set,g=[];for(let p=e.length-1;p>=0;p--)g.push({node:e[p],siblings:f});let w=0;for(;g.length>0;){let p=g.pop();if(p.close){o+=`}
|
|
354
|
+
`;continue}let{node:b,siblings:T}=p,x=!!(b.isXform||b.positions.length===0),M=hi(T,re(b.name,x?`Group_${w}`:`Mesh_${w}`));w++;let c=b.children||[];if(x){let m=l(b.xrTraits,!1,b.invisible);o+=`def Xform "${M}"${m.header}
|
|
328
355
|
{
|
|
329
|
-
${
|
|
356
|
+
${m.body}${h(b)}${m.tail}`,g.push({close:!0});let v=new Set;for(let S=c.length-1;S>=0;S--)g.push({node:c[S],siblings:v})}else if(c.length>0){let m=l(b.xrTraits,!1,b.invisible),v=`${M}_mesh`;o+=`def Xform "${M}"${m.header}
|
|
330
357
|
{
|
|
331
|
-
${
|
|
358
|
+
${m.body}${h(b)}${m.tail}`,o+=`def Mesh "${v}" (
|
|
332
359
|
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
333
360
|
)
|
|
334
361
|
{
|
|
335
|
-
${
|
|
336
|
-
`,
|
|
362
|
+
${u(b)}}
|
|
363
|
+
`,g.push({close:!0});let S=new Set([v]);for(let D=c.length-1;D>=0;D--)g.push({node:c[D],siblings:S})}else{let m=l(b.xrTraits,!0,b.invisible);o+=`def Mesh "${M}"${m.header}
|
|
337
364
|
{
|
|
338
|
-
${
|
|
339
|
-
`}}return
|
|
365
|
+
${m.body}${h(b)}${u(b)}${m.tail}}
|
|
366
|
+
`}}return o+=`}
|
|
340
367
|
}
|
|
341
|
-
`,a}function us(e,t){if(e&&typeof e.traverse=="function"){let s=os(e,t);return Ce(s)}let i=te(e),r=Se(i);return Ce(r)}var se=null;function Ae(e){if(!se){se=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let s=0;s<8;s++)r=r&1?3988292384^r>>>1:r>>>1;se[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=se[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function cs(e){let t=[],i=0,r=[];for(let c of e){let f=Te(c.filename),y=Ae(c.data),g=c.data.length,u=30+f.length,b=(i+u)%64,w=b!==0?64-b:0,M=new Uint8Array(u+w),x=new DataView(M.buffer);x.setUint32(0,67324752,!0),x.setUint16(4,20,!0),x.setUint32(14,y,!0),x.setUint32(18,g,!0),x.setUint32(22,g,!0),x.setUint16(26,f.length,!0),x.setUint16(28,w,!0),M.set(f,30),t.push({offset:i,size:g,crc:y,filenameBytes:f,entry:c}),r.push(M,c.data),i+=M.length+c.data.length}let s=i;for(let c of t){let f=new Uint8Array(46+c.filenameBytes.length),y=new DataView(f.buffer);y.setUint32(0,33639248,!0),y.setUint16(4,20,!0),y.setUint16(6,20,!0),y.setUint32(16,c.crc,!0),y.setUint32(20,c.size,!0),y.setUint32(24,c.size,!0),y.setUint16(28,c.filenameBytes.length,!0),y.setUint32(42,c.offset,!0),f.set(c.filenameBytes,46),r.push(f),i+=f.length}let n=i-s,o=new Uint8Array(22),a=new DataView(o.buffer);a.setUint32(0,101010256,!0),a.setUint16(8,t.length,!0),a.setUint16(10,t.length,!0),a.setUint32(12,n,!0),a.setUint32(16,s,!0),r.push(o),i+=22;let h=new Uint8Array(i),l=0;for(let c of r)h.set(c,l),l+=c.length;return h}var gi=e=>cs([{filename:"model.usda",data:Te(e)}]);function ne(e){return gi(us(e))}function Pe(e){return gi(Ce(Se(te(e))))}function yi(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():Pe(e)}var Tt=class _r{constructor(t=0,i=0){this.x=Number(t),this.y=Number(i)}set(t,i){return this.x=Number(t),this.y=Number(i),this}clone(){return new _r(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},Y=class Er{constructor(t=0,i=0,r=0){this.x=Number(t),this.y=Number(i),this.z=Number(r)}set(t,i,r){return this.x=Number(t),this.y=Number(i),this.z=Number(r),this}clone(){return new Er(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addVectors(t,i){return this.x=t.x+i.x,this.y=t.y+i.y,this.z=t.z+i.z,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subVectors(t,i){return this.x=t.x-i.x,this.y=t.y-i.y,this.z=t.z-i.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,i){return this.x+=t.x*i,this.y+=t.y*i,this.z+=t.z*i,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5&&(this.x/=t,this.y/=t,this.z/=t),this}cross(t){let i=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,s=this.x*t.y-this.y*t.x;return this.x=i,this.y=r,this.z=s,this}crossVectors(t,i){let r=t.x,s=t.y,n=t.z,o=i.x,a=i.y,h=i.z;return this.x=s*h-n*a,this.y=n*o-r*h,this.z=r*a-s*o,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}distanceTo(t){return Math.hypot(this.x-t.x,this.y-t.y,this.z-t.z)}lerp(t,i){return this.lerpVectors(this,t,i)}lerpVectors(t,i,r){return this.x=t.x+(i.x-t.x)*r,this.y=t.y+(i.y-t.y)*r,this.z=t.z+(i.z-t.z)*r,this}applyMatrix4(t){let i=this.x,r=this.y,s=this.z,n=t.elements,o=1/(n[3]*i+n[7]*r+n[11]*s+n[15]);return this.x=(n[0]*i+n[4]*r+n[8]*s+n[12])*o,this.y=(n[1]*i+n[5]*r+n[9]*s+n[13])*o,this.z=(n[2]*i+n[6]*r+n[10]*s+n[14])*o,this}},bi=class{constructor(e=0,t=0,i=0,r=1){this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r)}set(e,t,i,r){return this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r),this}},_e=class Nr{constructor(t=0,i=0,r=0,s="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}set(t,i,r,s=this.order){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s,this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this.order=t.order,this._onChangeCallback?.(),this}clone(){return new Nr(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},Ee=class Dr{constructor(t=0,i=0,r=0,s=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s)}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}get w(){return this._w}set w(t){this._w=Number(t),this._onChangeCallback?.()}set(t,i,r,s){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s),this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback?.(),this}clone(){return new Dr(this._x,this._y,this._z,this._w)}setFromEuler(t,i=!0){let r=t.x,s=t.y,n=t.z,o=Math.cos(r/2),a=Math.cos(s/2),h=Math.cos(n/2),l=Math.sin(r/2),c=Math.sin(s/2),f=Math.sin(n/2);return this._x=l*a*h+o*c*f,this._y=o*c*h-l*a*f,this._z=o*a*f+l*c*h,this._w=o*a*h-l*c*f,i&&this._onChangeCallback?.(),this}setFromAxisAngle(t,i){let r=i/2,s=Math.sin(r);return this.set(t.x*s,t.y*s,t.z*s,Math.cos(r))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,i){let r=t.dot(i)+1;return r<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*i.z-t.z*i.y,t.z*i.x-t.x*i.z,t.x*i.y-t.y*i.x,r).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,i){let r=t.x,s=t.y,n=t.z,o=t.w,a=i.x,h=i.y,l=i.z,c=i.w;return this._x=r*c+o*a+s*l-n*h,this._y=s*c+o*h+n*a-r*l,this._z=n*c+o*l+r*h-s*a,this._w=o*c-r*a-s*h-n*l,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Ot=class Lr{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,this}copy(t){return this.elements.set(t.elements),this}clone(){let t=new Lr;return t.copy(this),t}compose(t,i,r){return ye(this.elements,[i.x,i.y,i.z,i.w],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,i){return dt(this.elements,t.elements,i.elements),this}lookAt(t,i,r){return Qt(this.elements,[t.x,t.y,t.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(t){let i=new Y(0,0,0),r=new Y(1,1,1);return this.compose(i,t,r)}makeTranslation(t,i,r){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(t,i,r){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},xi=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 Pt(this.elements,e.elements),this}},xt=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,ae=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,vi={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},Rt=class Ir{constructor(t,i,r){this.r=1,this.g=1,this.b=1,t!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(t,i,r):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let i=t.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let s=parseInt(r,16);r.length===6&&!Number.isNaN(s)&&this.setHex(s)}else if(i in vi)this.setHex(vi[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let s=n=>xt(Math.max(0,Math.min(1,(parseFloat(n)||0)/(n.endsWith("%")?100:255))));this.setRGB(s(r[0]),s(r[1]),s(r[2]))}}return this}setHSL(t,i,r){if(t=((Number(t)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let a=xt(r);return this.setRGB(a,a,a)}let s=r<=.5?r*(1+i):r+i-r*i,n=2*r-s,o=a=>(a<0&&(a+=1),a>1&&(a-=1),a<1/6?n+(s-n)*6*a:a<1/2?s:a<2/3?n+(s-n)*6*(2/3-a):n);return this.setRGB(xt(o(t+1/3)),xt(o(t)),xt(o(t-1/3)))}lerp(t,i){let r=Number(i)||0;return this.r+=(t.r-this.r)*r,this.g+=(t.g-this.g)*r,this.b+=(t.b-this.b)*r,this}lerpColors(t,i,r){let s=Number(r)||0;return this.r=t.r+(i.r-t.r)*s,this.g=t.g+(i.g-t.g)*s,this.b=t.b+(i.b-t.b)*s,this}multiplyScalar(t){let i=Number(t)||0;return this.r*=i,this.g*=i,this.b*=i,this}setScalar(t){let i=Number(t)||0;return this.setRGB(i,i,i)}setHex(t){let i=Math.floor(t);return this.r=xt((i>>16&255)/255),this.g=xt((i>>8&255)/255),this.b=xt((i&255)/255),this}setRGB(t,i,r){return this.r=Number(t),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.r=xt(this.r),this.g=xt(this.g),this.b=xt(this.b),this}convertLinearToSRGB(){return this.r=ae(this.r),this.g=ae(this.g),this.b=ae(this.b),this}getHex(){let t=i=>Math.round(ae(Math.max(0,Math.min(1,i)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new Ir(this.r,this.g,this.b)}},Mi={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,i)=>Math.max(t,Math.min(i,e)),lerp:(e,t,i)=>e+(t-e)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},gt=class Fr{constructor(t,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=i;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/i)}getX(t){return this.array[t*this.itemSize]}getY(t){return this.array[t*this.itemSize+1]}getZ(t){return this.array[t*this.itemSize+2]}setX(t,i){return this.array[t*this.itemSize]=i,this.needsUpdate=!0,this}setY(t,i){return this.array[t*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(t,i){return this.array[t*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(t,i,r,s){let n=t*this.itemSize;return this.array[n]=i,this.array[n+1]=r,this.array[n+2]=s,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new Fr(new t(this.array),this.itemSize)}},wi=class extends gt{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},Ti=class extends gt{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},Si=class extends gt{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},ft=class kr{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,i){return this.attributes[t]=i,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof gt)this.index=t;else if(Array.isArray(t)){let i=0;for(let r of t)r>i&&(i=r);this.index=new gt(new(i>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new gt(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let i=t.count,r=new Float32Array(i*3),s=new Y,n=new Y,o=new Y,a=new Y,h=new Y,l=this.index?.array,c=l?l.length:i;for(let f=0;f<c;f+=3){let y=l?l[f]:f,g=l?l[f+1]:f+1,u=l?l[f+2]:f+2;s.set(t.getX(y),t.getY(y),t.getZ(y)),n.set(t.getX(g),t.getY(g),t.getZ(g)),o.set(t.getX(u),t.getY(u),t.getZ(u)),a.subVectors(o,n),h.subVectors(s,n),a.cross(h).normalize();for(let b of[y,g,u])r[b*3]+=a.x,r[b*3+1]+=a.y,r[b*3+2]+=a.z}for(let f=0;f<i;f++){let y=r[f*3],g=r[f*3+1],u=r[f*3+2],b=Math.hypot(y,g,u)||1;r[f*3]=y/b,r[f*3+1]=g/b,r[f*3+2]=u/b}return this.setAttribute("normal",new gt(r,3)),this}setFromBuffers(t,i,r,s){this.setAttribute("position",new gt(t,3)),this.setAttribute("normal",new gt(i,3)),this.setAttribute("uv",new gt(r,2)),this.setIndex(s)}setFromPoints(t){let i=[];if(Array.isArray(t))for(let r of t)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new gt(i,3))}computeBoundingBox(){let t=this.attributes.position,i=new Y(1/0,1/0,1/0),r=new Y(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let s=0;s<t.count;s++){let n=t.getX(s),o=t.getY(s),a=t.getZ(s);n<i.x&&(i.x=n),o<i.y&&(i.y=o),a<i.z&&(i.z=a),n>r.x&&(r.x=n),o>r.y&&(r.y=o),a>r.z&&(r.z=a)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,i){let r=this.attributes.position;if(r){let s=r.array;for(let n=0;n<s.length;n+=3)t(s,n);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,i=0,r=0){return this._xform((s,n)=>{s[n]+=t,s[n+1]+=i,s[n+2]+=r})}scale(t=1,i=1,r=1){return this._xform((s,n)=>{s[n]*=t,s[n+1]*=i,s[n+2]*=r},!0)}_rot(t,i,r){let s=Math.cos(r),n=Math.sin(r);for(let o of[this.attributes.position,this.attributes.normal]){if(!o)continue;let a=o.array;for(let h=0;h<a.length;h+=3){let l=a[h+t],c=a[h+i];a[h+t]=l*s-c*n,a[h+i]=l*n+c*s}o.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let i=this.attributes.position;if(i&&t?.elements){let r=new Y;for(let s=0;s<i.count;s++)r.set(i.getX(s),i.getY(s),i.getZ(s)).applyMatrix4(t),i.setXYZ(s,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let t=new kr;t.name=this.name;for(let i of Object.keys(this.attributes))t.attributes[i]=this.attributes[i].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},Ne=class extends ft{constructor(e=1,t=1,i=1){super();let r=e/2,s=t/2,n=i/2,o=[-r,-s,n,r,-s,n,r,s,n,-r,s,n,r,-s,-n,-r,-s,-n,-r,s,-n,r,s,-n,-r,s,n,r,s,n,r,s,-n,-r,s,-n,-r,-s,-n,r,-s,-n,r,-s,n,-r,-s,n,r,-s,n,r,-s,-n,r,s,-n,r,s,n,-r,-s,-n,-r,-s,n,-r,s,n,-r,s,-n],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],h=[],l=[];for(let c=0;c<6;c++){let f=c*4;h.push(0,0,1,0,1,1,0,1),l.push(f,f+1,f+2,f,f+2,f+3)}this.setFromBuffers(o,a,h,l)}},Ri=class extends ft{constructor(e=1,t=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let s=[],n=[],o=[],a=[];for(let h=0;h<=r;h++){let l=h/r;for(let c=0;c<=i;c++){let f=c/i;if(s.push((f-.5)*e,(.5-l)*t,0),n.push(0,0,1),o.push(f,1-l),h>0&&c>0){let y=(i+1)*h+c-1,g=y-(i+1);a.push(g,y,g+1,y,y+1,g+1)}}}this.setFromBuffers(s,n,o,a)}},Ci=class extends ft{constructor(e=1,t=16,i=12){super(),t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));let r=[],s=[],n=[],o=[];for(let a=0;a<=i;a++){let h=a/i;for(let l=0;l<=t;l++){let c=l/t,f=c*Math.PI*2,y=h*Math.PI,g=-Math.cos(f)*Math.sin(y),u=Math.cos(y),b=Math.sin(f)*Math.sin(y);if(r.push(e*g,e*u,e*b),s.push(g,u,b),n.push(c,1-h),a>0&&l>0){let w=(t+1)*a+l,M=w-(t+1),x=M-1,m=w-1;a!==1&&o.push(M,x,w),a!==i&&o.push(x,m,w)}}}this.setFromBuffers(r,s,n,o)}},De=class extends ft{constructor(e=1,t=1,i=1,r=16){super(),r=Math.max(3,Math.floor(r));let s=[],n=[],o=[],a=[],h=i/2;for(let c=0;c<=1;c++){let f=c,y=c===0?e:t,g=c===0?h:-h;for(let u=0;u<=r;u++){let b=u/r,w=b*Math.PI*2,M=Math.sin(w),x=Math.cos(w);s.push(y*M,g,y*x),n.push(M,0,x),o.push(b,1-f)}}for(let c=0;c<r;c++){let f=c,y=c+r+1,g=c+r+2,u=c+1;a.push(f,y,u,y,g,u)}let l=(c,f)=>{if(c<=0)return;let y=f*h,g=s.length/3;s.push(0,y,0),n.push(0,f,0),o.push(.5,.5);let u=s.length/3;for(let b=0;b<=r;b++){let w=b/r*Math.PI*2,M=Math.sin(w),x=Math.cos(w);s.push(c*M,y,c*x),n.push(0,f,0),o.push(x*.5+.5,.5+f*M*.5)}for(let b=0;b<r;b++)a.push(g,u+b+(f>0?0:1),u+b+(f>0?1:0))};l(e,1),l(t,-1),this.setFromBuffers(s,n,o,a)}},Ai=class extends De{constructor(e=1,t=1,i=16){super(0,e,t,i)}},Pi=class extends ft{constructor(e=1,t=.4,i=12,r=48,s=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let n=[],o=[],a=[],h=[];for(let l=0;l<=i;l++){let c=l/i*Math.PI*2,f=Math.cos(c),y=Math.sin(c);for(let g=0;g<=r;g++){let u=g/r*s,b=Math.cos(u),w=Math.sin(u);if(n.push((e+t*f)*b,(e+t*f)*w,t*y),o.push(f*b,f*w,y),a.push(g/r,l/i),l>0&&g>0){let M=(r+1)*l+g-1,x=M-(r+1);h.push(M,x,M+1,x,x+1,M+1)}}}this.setFromBuffers(n,o,a,h)}};function _i(e,t,i,r,s){let n=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),o=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),a=Number(r)||.1,h=[],l=[],c=[],f=[],y=new Y,g=new Y,u=new Y,b=new Y,w=new Y;for(let x=0;x<=n;x++){let m=x/n;s(Math.max(0,m-.001),y),s(Math.min(1,m+.001),g),u.subVectors(g,y).normalize(),x===0&&b.set(Math.abs(u.y)>.9?1:0,Math.abs(u.y)>.9?0:1,0),w.crossVectors(u,b).normalize(),b.crossVectors(w,u).normalize(),s(m,y);for(let p=0;p<=o;p++){let v=p/o*Math.PI*2,R=-a*Math.cos(v),L=a*Math.sin(v),I=R*b.x+L*w.x,N=R*b.y+L*w.y,_=R*b.z+L*w.z;h.push(y.x+I,y.y+N,y.z+_);let A=Math.hypot(I,N,_)||1;l.push(I/A,N/A,_/A),c.push(m,p/o)}}let M=o+1;for(let x=1;x<=n;x++){let m=M*(x-1),p=m+M;for(let v=1;v<=o;v++){let R=m+v-1,L=p+v-1;f.push(R,L,m+v,L,p+v,m+v)}}e.setFromBuffers(h,l,c,f)}var Ei=class extends ft{constructor(e=1,t=.4,i=64,r=8,s=2,n=3){super(),i=Math.floor(i),r=Math.floor(r),_i(this,i,r,t,(o,a)=>{let h=o*s*Math.PI*2,l=n/s*h,c=e*(2+Math.cos(l))*.5;a.set(c*Math.cos(h),c*Math.sin(h),e*Math.sin(l)*.5)})}},Ft=class{getPoint(e,t=new Y){return t}getPointAt(e,t=new Y){return this.getPoint(e,t)}getTangent(e,t=new Y){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),i=[];for(let r=0;r<=t;r++)i.push(this.getPoint(r/t));return i}getSpacedPoints(e=5){return this.getPoints(e)}},Ni=class extends Ft{constructor(e=new Y,t=new Y){super(),this.v1=e,this.v2=t}getPoint(e,t=new Y){return t.lerpVectors(this.v1,this.v2,e)}},Di=class extends Ft{constructor(e=new Y,t=new Y,i=new Y){super(),this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new Y){return t.lerpVectors(this.v0,this.v1,e).lerp(new Y().lerpVectors(this.v1,this.v2,e),e)}},Li=class extends Ft{constructor(e=new Y,t=new Y,i=new Y,r=new Y){super(),this.v0=e,this.v1=t,this.v2=i,this.v3=r}getPoint(e,t=new Y){let i=new Y().lerpVectors(this.v0,this.v1,e),r=new Y().lerpVectors(this.v1,this.v2,e),s=new Y().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(i.lerp(r,e),r.lerp(s,e),e)}},Ii=class extends Ft{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new Y){let i=this.points,r=i.length;if(!r)return t.set(0,0,0);if(r===1)return t.copy(i[0]);let s=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(e)||0)),n=Math.floor(s),o=s-n;!this.closed&&n>=r-1&&(n=r-2,o=1);let a=b=>i[this.closed?(b%r+r)%r:Math.max(0,Math.min(r-1,b))],h=a(n-1),l=a(n),c=a(n+1),f=a(n+2),y=o*o,g=y*o,u=(b,w,M,x)=>.5*(2*w+(M-b)*o+(2*b-5*w+4*M-x)*y+(3*w-b-3*M+x)*g);return t.set(u(h.x,l.x,c.x,f.x),u(h.y,l.y,c.y,f.y),u(h.z,l.z,c.z,f.z))}},Le=class extends ft{constructor(e=[new Tt(0,-.5),new Tt(.5,0),new Tt(0,.5)],t=12,i=0,r=Math.PI*2){super();let s=Array.isArray(e)&&e.length>=2?e:[new Tt(.2,0),new Tt(.2,.5)],n=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),o=[],a=[],h=[],l=[],c=s.length;for(let f=0;f<=n;f++){let y=f/n,g=i+y*r,u=Math.sin(g),b=Math.cos(g);for(let w=0;w<c;w++){let M=s[w],x=Number(M?.x)||0,m=Number(M?.y)||0;o.push(x*u,m,x*b);let p=s[Math.max(0,w-1)],v=s[Math.min(c-1,w+1)],R=(Number(v?.x)||0)-(Number(p?.x)||0),L=(Number(v?.y)||0)-(Number(p?.y)||0),I=Math.hypot(L,R)||1;a.push(L/I*u,-R/I,L/I*b),h.push(y,w/(c-1))}}for(let f=0;f<n;f++){let y=f*c;for(let g=0;g<c-1;g++){let u=y+g,b=y+c+g;l.push(u,b,u+1,b,b+1,u+1)}}this.setFromBuffers(o,a,h,l)}},Fi=class extends ft{constructor(e,t=64,i=1,r=8,s=!1){super(),_i(this,t,r,i,(n,o)=>{let a=e?.getPointAt??e?.getPoint;if(typeof a=="function"){let h=a.call(e,n,o);h&&h!==o&&o.copy(h)}else o.set(0,n,0)})}},oe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",le=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Tt(1,1),this.offset=new Tt(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},ki=class extends le{constructor(e=null,t=1,i=1,r=1023,s=1009,n,o=1001,a=1001,h=1003,l=1003,c=1,f=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1;let y=Number(t),g=Number(i),u=e&&typeof e.length=="number"?e:null;this.width=y,this.height=g,this.image={data:u,width:y,height:g},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(o)||1001,this.wrapT=Number(a)||1001,this.magFilter=Number(h)||1003,this.minFilter=Number(l)||1003,this.colorSpace=f||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,i=Number(e?.width??this.width),r=Number(e?.height??this.height);if(!t||!t.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let s=Math.max(1,i|0),n=Math.max(1,r|0),o=s*n,a=this.format,h=a===1021||a===1024||a===1028||t.length===o?1:a===1025||a===1030||t.length===o*2?2:a===1022||t.length===o*3?3:4,l=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,c=Math.min(s,96),f=Math.min(n,96),y=f*(1+c*4),g=new Uint8Array(68+y),u=new DataView(g.buffer);u.setUint32(0,2303741511),u.setUint32(4,218765834),u.setUint32(8,13),u.setUint32(12,1229472850),u.setUint32(16,c),u.setUint32(20,f),g[24]=8,g[25]=6,u.setUint32(29,Ae(g.subarray(12,29))),u.setUint32(33,y+11),u.setUint32(37,1229209940),g[41]=120,g[42]=1,g[43]=1,u.setUint16(44,y,!0),u.setUint16(46,~y&65535,!0);let b=48,w=1,M=0,x=0,m=0,p=0,v=0,R=_=>{if(!Number.isFinite(_))return 0;let A=l&&_<=1?_*255:_;return A>0?A<255?A+.5|0:255:0};for(let _=0;_<f;_++){let A=_*n/f|0,E=this.flipY?n-1-A:A;g[b++]=0,M+=w;for(let C=0;C<c;C++){let d=(E*s+(C*s/c|0))*h,k=a===1021?255:R(t[d]??0),$=h>=3||a===1030?R(t[d+1]??0):k,S=h>=3?R(t[d+2]??0):a===1030?0:k,D=h===4?R(t[d+3]??255):a===1021?R(t[d]??255):a===1025?R(t[d+1]??255):255;g[b++]=k,w+=k,M+=w,g[b++]=$,w+=$,M+=w,g[b++]=S,w+=S,M+=w,g[b++]=D,w+=D,M+=w,x+=k,m+=$,p+=S,v+=D}w%=65521,M%=65521}u.setUint32(b,(M<<16|w)>>>0),u.setUint32(b+4,Ae(g.subarray(37,b+4))),u.setUint32(b+12,1229278788),u.setUint32(b+16,2923585666);let L=c*f*255,I=this.colorSpace==="srgb-linear";this.avgColor=[I?x/L:xt(x/L),I?m/L:xt(m/L),I?p/L:xt(p/L),v/L];let N=["data:image/png;base64,"];for(let _=0;_<g.length;_+=3){let A=g[_]<<16|(g[_+1]??0)<<8|(g[_+2]??0);N.push(oe[A>>18&63]+oe[A>>12&63]+(_+1<g.length?oe[A>>6&63]:"=")+(_+2<g.length?oe[A&63]:"="))}this.source=N.join("")}},Ui=class{load(e,t){let i=new le(e);return t?.(i),i}};function yt(e,t){return e!==void 0?Number(e):t}function Ie(e,t){return e!==void 0?!!e:t}var Mt=class{constructor(e={}){this.name=e.name||"",this.color=new Rt(e.color!==void 0?e.color:16777215),this.emissive=new Rt(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=yt(e.emissiveIntensity,1),this.roughness=yt(e.roughness,.5),this.metalness=yt(e.metalness,0),this.opacity=yt(e.opacity,1),this.transparent=Ie(e.transparent,!1),this.wireframe=Ie(e.wireframe,!1),this.side=yt(e.side,2),this.doubleSided=Ie(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=yt(e.clearcoat,0),this.clearcoatRoughness=yt(e.clearcoatRoughness,0),this.sheen=yt(e.sheen,0),this.sheenColor=new Rt(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=yt(e.sheenRoughness,0),this.transmission=yt(e.transmission,0),this.thickness=yt(e.thickness,0),this.attenuationColor=new Rt(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=yt(e.attenuationDistance,1/0),this.ior=yt(e.ior,1.5),this.dispersion=yt(e.dispersion,0),this.iridescence=yt(e.iridescence,0),this.iridescenceIOR=yt(e.iridescenceIOR,1.3)}dispose(){}},jt=class extends Mt{},zi=class extends Mt{},Vi=class extends Mt{},Oi=class extends Mt{},Bi=class extends Mt{},Ct=class Ur{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 Y,this.rotation=new _e,this.quaternion=new Ee,this.scale=new Y(1,1,1),this.matrix=new Ot,this.matrixWorld=new Ot,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,i=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),s=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(i,r,s)})}add(...t){for(let i of t)i&&i instanceof Ur&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...t){for(let i of t){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(t){let i=new Set,r=[this];for(;r.length>0;){let s=r.pop();if(!s||typeof s!="object"||i.has(s))continue;i.add(s),t(s);let n=s.children;if(Array.isArray(n))for(let o=n.length-1;o>=0;o--)r.push(n[o])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(i=>{Gi(i),(i.matrixAutoUpdate||t)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(t,i,r){let s=typeof t=="object"?t:new Y(t,i,r);this.target instanceof Y?this.target.copy(s):this.target?.position instanceof Y&&this.target.position.copy(s),this.updateMatrixWorld(!0);let n=new Ot;n.lookAt(this.position,s,new Y(0,1,0));let o=n.elements,a=o[0],h=o[4],l=o[8],c=o[1],f=o[5],y=o[9],g=o[2],u=o[6],b=o[10],w=a+f+b;if(w>0){let M=.5/Math.sqrt(w+1);this.quaternion.set((u-y)*M,(l-g)*M,(c-h)*M,.25/M)}}translateOnAxis(t,i){let r=t.clone().applyMatrix4(new Ot().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(t){return this.translateOnAxis(new Y(1,0,0),t)}translateY(t){return this.translateOnAxis(new Y(0,1,0),t)}translateZ(t){return this.translateOnAxis(new Y(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}clone(t=!0){let i=this instanceof $t?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Et?new Et(this.geometry,this.material):new this.constructor;i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,i.castShadow=this.castShadow,i.receiveShadow=this.receiveShadow;try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(t)for(let r of this.children)i.add(r.clone(!0));return i}},$i=class extends Ct{},Et=class extends Ct{constructor(e,t){super(),this.isMesh=!0;let i=Array.isArray(t)?t[0]:t;this.geometry=e instanceof ft?e:e?(kt("unsupported geometry","BoxGeometry"),new Ne(.5,.5,.5)):new ft,this.material=i instanceof Mt?i:i?(kt("unsupported material","MeshStandardMaterial"),new jt({color:13421772})):new jt}};function Gi(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=ut().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var Wt=1e4,Fe=class extends Et{constructor(e,t,i=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>Wt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${Wt})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let n=0;n<this.count;n++){let o=n*16;s[o]=1,s[o+5]=1,s[o+10]=1,s[o+15]=1}this.instanceMatrix=new gt(s,16)}setMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++){let o=Number(t.elements[n]);r[s+n]=Number.isFinite(o)?o:n%5===0?1:0}}getMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++)t.elements[n]=r[s+n]}setColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let n=new Float32Array(this.count*3);n.fill(1),this.instanceColor=new gt(n,3)}let r=this.instanceColor.array,s=i*3;r[s]=Number.isFinite(t.r)?t.r:1,r[s+1]=Number.isFinite(t.g)?t.g:1,r[s+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){t.setRGB(1,1,1);return}let r=this.instanceColor.array,s=i*3;t.setRGB(r[s],r[s+1],r[s+2])}dispose(){}},Xt=class extends Ct{constructor(e=16777215,t=1){super(),this.color=new Rt(e),this.intensity=Number(t),this.type="directional"}},ke=class extends Xt{constructor(e,t){super(e,t),this.type="ambient"}},Hi=class extends Xt{constructor(e,t){super(e,t),this.target=new Ct,this.type="directional"}},Ue=class extends Xt{constructor(e,t,i=0,r=2){super(e,t),this.type="point",this.distance=i,this.decay=r}},ze=class extends Ct{},ji=class extends ze{constructor(e=45,t=1,i=.1,r=1e3){super(),this.target=new Y(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(i),this.far=Number(r)}},Ve=class extends Ct{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Nt.validate(this),Ht(this)}toGLB(){return Nt.validate(this),ie(this)}toUSDZ(){return Nt.validate(this),ne(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(i=>{if(i instanceof Et){let r=new Float32Array(i.matrixWorld.elements);e.set(t,r),i.name&&e.set(i.name,r),t++}}),e}},Oe=Ht,Be=ie,Wi=ne,Nt=class{static validate(e){let t=0,i=0,r=0,s=new Set,n=(a,h,l)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${h}). Found: ${l}`)},o=(a,h)=>{if(!Number.isFinite(h))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(h)}), which cannot be bounds-checked.`);return h};e.traverse(a=>{if(Gi(a),a instanceof Et||a.geometry?.attributes?.position?.count){if(r++,r>1e3&&n("MESHES",1e3,r),a instanceof Fe){let l=o("instance",a.count);(l<0||l>Wt)&&n("INSTANCES",Wt,l)}let h=a.geometry;if(h){let l=0;if(h.attributes.position&&(l=o("vertex",h.attributes.position.count),t+=l,t>1e5&&n("VERTICES",1e5,t)),h.index){let c=o("index",h.index.count);i+=c,i>3e5&&n("INDICES",3e5,i);let f=h.index.array;if(f&&l>0){let y=Math.min(c,f.length);for(let g=0;g<y;g++){let u=f[g];if(!Number.isFinite(u)||u<0||u>=l)throw new Error(`SecurityError: Index buffer value (${String(u)}) out of vertex bounds [0, ${l}).`)}}}}if(a.material){let l=a.material;l.map&&s.add(l.map),l.normalMap&&s.add(l.normalMap),l.roughnessMap&&s.add(l.roughnessMap)}}}),s.size>16&&n("TEXTURES",16,s.size);for(let a of s){let h=a,l=h.image,c=Number(l?.width??h.width??0)||0,f=Number(l?.height??h.height??0)||0;(!Number.isFinite(c)||!Number.isFinite(f)||c>2048||f>2048)&&n("TEXTURE_DIMENSION",2048,Math.max(c,f))}}},Xi=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let i=new Rt(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){Nt.validate(e);let r=(s,n)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(n&&n.length?self.postMessage(s,n):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),n={};for(let[o,a]of s.entries())n[o]=Array.from(a);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:n})}else{this.hasInitialModelRendered=!0;let s=Oe(e),n=Be(e),o=(s.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:n.buffer,dynamicLights:o,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[n.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(e.getMeshTransforms()):(i.loadModel(e.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function qi(){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 Ki=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=qi(),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=qi();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function ms(){}var qt=new Proxy(ms,{get:(e,t)=>{if(t==="isProxy")return!0;if(!(t==="constructor"||t==="__proto__"||t==="prototype"))return t==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:t==="shadowMap"?{enabled:!1,type:0}:t==="capabilities"?{isWebGL2:!0,maxTextures:16}:t===Symbol.toPrimitive?()=>0:qt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>qt,construct:()=>qt}),Yi=(()=>{try{if(typeof document>"u")return null;let e=document.currentScript;return e?.src?e.src:e?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([e.textContent],{type:"text/javascript"})):null}catch{return null}})();function he(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Bt(e,t){if(!e||typeof e!="string")return!1;let i=e.trim();if(!i)return!1;try{let r=new URL(i,he());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||t?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var Zi,Kt;function Ji(e){if(!Bt(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(Kt===void 0||Zi!==t){Zi=t;try{Kt=t.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Bt(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{Kt=null}}return Kt?Kt.createScriptURL(e):e}function fs(e){ut().sandboxEngineSrc=e}function $e(){let e=ut().sandboxEngineSrc;if(e)return e;if(Yi)return Yi;try{if(typeof document>"u")return null;let t=he(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let s=r.src;if(!s)continue;let n=new URL(s,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(n)&&Bt(s,{requireSameOrigin:!0}))return s}}catch{}return null}function Ge(e,t){if(!Bt(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,he()).href}function ps(){let e=$e();if(!e)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");return Ge(e,"sandbox engine")}function ds(e){ut().sandboxIframeSrc=e}function Qi(){let e=ut().sandboxIframeSrc;if(e)return e;let t=$e();if(!t||!Bt(t))return null;let i=new URL(t,he());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function gs(){let e=Qi();if(!e)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");return Ge(e,"sandbox iframe")}function ys(e){ut().allowClientScripts=e}function tr(){return!!ut().allowClientScripts}function bs(e){return Ge(e,"procedural scene script")}var xs=["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 vs(e,t){let i=self,r=e.nonce,s=e.engineSrc,n=e.allowedScriptUrl,o=e.allowClientScripts,a=e.revoked,h=i.postMessage.bind(i);function l(m){h({type:"ERROR",nonce:r,message:String(m)})}let c=typeof i.importScripts=="function"?i.importScripts.bind(i):null,f=n,y=null;try{let m=s;if(typeof i.trustedTypes<"u"&&i.trustedTypes&&typeof i.trustedTypes.createPolicy=="function")try{let p={createScriptURL:function(R){if(R!==s&&(!n||R!==n))throw new TypeError("Disallowed worker importScripts URL");return R}};o&&(p.createScript=function(R){return String(R)});let v=i.trustedTypes.createPolicy("three-live#worker-boot",p);m=v.createScriptURL(s),n&&(f=v.createScriptURL(n)),o&&typeof v.createScript=="function"&&(y=v.createScript.bind(v))}catch{}c(m)}catch(m){l('Sandbox failed to load the Three-Live engine from "'+s+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(m&&m.message||m));return}let g=i.THREE;if(!g||typeof g.Scene!="function"){l('Sandbox loaded "'+s+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(t)){let m=i.__THREE_LIVE_REGISTRY__;for(let p=0;p<t.length;p++)if(typeof t[p]=="function")try{t[p](g,m)}catch{}}function u(m,p,v){let R=i;for(;R&&R!==Object.prototype;){if(!v&&R!==i)try{delete R[m]}catch{}if(!v||R===i||Object.prototype.hasOwnProperty.call(R,m))try{Object.defineProperty(R,m,v?{value:p,writable:!1,configurable:!1}:{value:p,writable:!1,configurable:!1,enumerable:!1})}catch{}try{R=Object.getPrototypeOf(R)}catch{break}}}for(let m=0;m<a.length;m++)u(a[m],void 0);u("performance",Object.freeze({now:function(){return Date.now()}}));let b=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],w=!1;function M(m,p){if(m.type==="3D_MODEL_READY"){if(w)return;w=!0}m.nonce=r,p&&p.length?h(m,p):h(m)}u("postMessage",function(m,p){if(!m||b.indexOf(m.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+b.join(", ")+").");M(m,p)},!0);let x=!1;i.onmessage=function(m){let p=m&&m.data;if(!(!p||p.nonce!==r)&&!(p.type!=="EXECUTE"&&p.type!=="EXECUTE_URL")&&!x){x=!0;try{let v=new g.Scene,R=new g.PerspectiveCamera(60,1,.1,1e3),L=new g.WebGLRenderer({isSandboxed:!0});if(p.type==="EXECUTE_URL"){if(!n||p.scriptUrl!==n||typeof c!="function"){l("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let I=f||n,N=c;if(c=null,f=null,i.THREE=g,i.scene=v,i.camera=R,i.renderer=L,N(I),typeof i.__THREE_LIVE_SCENE__=="function"){let _=i.__THREE_LIVE_SCENE__(g,v,R,L);_&&typeof _.toGLB=="function"&&(v=_)}else i.scene&&typeof i.scene.toGLB=="function"&&(v=i.scene)}else{if(!o){l("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let I=y?(0,eval)(y(`(function (THREE, scene, camera, renderer) {
|
|
368
|
+
`,o}var ae=null;function _e(e){if(!ae){ae=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let s=0;s<8;s++)r=r&1?3988292384^r>>>1:r>>>1;ae[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=ae[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function us(e){let t=[],i=0,r=[];for(let u of e){let f=Re(u.filename),g=_e(u.data),w=u.data.length,p=30+f.length,b=(i+p)%64,T=b!==0?64-b:0;T>0&&T<4&&(T+=64);let x=new Uint8Array(p+T),M=new DataView(x.buffer);M.setUint32(0,67324752,!0),M.setUint16(4,20,!0),M.setUint32(14,g,!0),M.setUint32(18,w,!0),M.setUint32(22,w,!0),M.setUint16(26,f.length,!0),M.setUint16(28,T,!0),x.set(f,30),T>=4&&(M.setUint16(p,6534,!0),M.setUint16(p+2,T-4,!0)),t.push({offset:i,size:w,crc:g,filenameBytes:f,entry:u}),r.push(x,u.data),i+=x.length+u.data.length}let s=i;for(let u of t){let f=new Uint8Array(46+u.filenameBytes.length),g=new DataView(f.buffer);g.setUint32(0,33639248,!0),g.setUint16(4,20,!0),g.setUint16(6,20,!0),g.setUint32(16,u.crc,!0),g.setUint32(20,u.size,!0),g.setUint32(24,u.size,!0),g.setUint16(28,u.filenameBytes.length,!0),g.setUint32(42,u.offset,!0),f.set(u.filenameBytes,46),r.push(f),i+=f.length}let n=i-s,a=new Uint8Array(22),o=new DataView(a.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,t.length,!0),o.setUint16(10,t.length,!0),o.setUint32(12,n,!0),o.setUint32(16,s,!0),r.push(a),i+=22;let l=new Uint8Array(i),h=0;for(let u of r)l.set(u,h),h+=u.length;return l}function di(e){let t=[{filename:"model.usda",data:Re(hs(e))}],i=new Set(["model.usda"]),r=[...e];for(;r.length>0;){let s=r.pop();for(let n of s.textures||[])n?.file&&n.data?.byteLength&&!i.has(n.file)&&(i.add(n.file),t.push({filename:n.file,data:n.data}));if(s.children)for(let n=s.children.length-1;n>=0;n--)r.push(s.children[n])}return us(t)}function oe(e){return di(as(e))}function Ce(e){return di(pi(we(e)))}function gi(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():Ce(e)}var At=class Cr{constructor(t=0,i=0){this.x=Number(t),this.y=Number(i)}set(t,i){return this.x=Number(t),this.y=Number(i),this}clone(){return new Cr(this.x,this.y)}copy(t){return this.set(t.x,t.y)}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},Q=class Pr{constructor(t=0,i=0,r=0){this.x=Number(t),this.y=Number(i),this.z=Number(r)}set(t,i,r){return this.x=Number(t),this.y=Number(i),this.z=Number(r),this}clone(){return new Pr(this.x,this.y,this.z)}copy(t){return this.set(t.x,t.y,t.z)}add(t){return this.addVectors(this,t)}addVectors(t,i){return this.set(t.x+i.x,t.y+i.y,t.z+i.z)}sub(t){return this.subVectors(this,t)}subVectors(t,i){return this.set(t.x-i.x,t.y-i.y,t.z-i.z)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t)}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,i){return this.set(this.x+t.x*i,this.y+t.y*i,this.z+t.z*i)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5?this.multiplyScalar(1/t):this}cross(t){return this.crossVectors(this,t)}crossVectors(t,i){let r=t.x,s=t.y,n=t.z,a=i.x,o=i.y,l=i.z;return this.set(s*l-n*o,n*a-r*l,r*o-s*a)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}distanceTo(t){return Math.hypot(this.x-t.x,this.y-t.y,this.z-t.z)}lerp(t,i){return this.lerpVectors(this,t,i)}lerpVectors(t,i,r){return this.x=t.x+(i.x-t.x)*r,this.y=t.y+(i.y-t.y)*r,this.z=t.z+(i.z-t.z)*r,this}applyMatrix4(t){let i=this.x,r=this.y,s=this.z,n=t.elements,a=1/(n[3]*i+n[7]*r+n[11]*s+n[15]);return this.x=(n[0]*i+n[4]*r+n[8]*s+n[12])*a,this.y=(n[1]*i+n[5]*r+n[9]*s+n[13])*a,this.z=(n[2]*i+n[6]*r+n[10]*s+n[14])*a,this}},yi=class{constructor(e=0,t=0,i=0,r=1){this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r)}set(e,t,i,r){return this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r),this}},Pe=class Nr{constructor(t=0,i=0,r=0,s="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}set(t,i,r,s=this.order){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s,this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.order)}clone(){return new Nr(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},le=class Er{constructor(t=0,i=0,r=0,s=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s)}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}get w(){return this._w}set w(t){this._w=Number(t),this._onChangeCallback?.()}set(t,i,r,s){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s),this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){return new Er(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(t,i=!0){let r=t.x,s=t.y,n=t.z,a=Math.cos(r/2),o=Math.cos(s/2),l=Math.cos(n/2),h=Math.sin(r/2),u=Math.sin(s/2),f=Math.sin(n/2);return this._x=h*o*l+a*u*f,this._y=a*u*l-h*o*f,this._z=a*o*f+h*u*l,this._w=a*o*l-h*u*f,i&&this._onChangeCallback?.(),this}setFromAxisAngle(t,i){let r=i/2,s=Math.sin(r);return this.set(t.x*s,t.y*s,t.z*s,Math.cos(r))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,i){let r=t.dot(i)+1;return r<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*i.z-t.z*i.y,t.z*i.x-t.x*i.z,t.x*i.y-t.y*i.x,r).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,i){let r=t.x,s=t.y,n=t.z,a=t.w,o=i.x,l=i.y,h=i.z,u=i.w;return this._x=r*u+a*o+s*h-n*l,this._y=s*u+a*l+n*o-r*h,this._z=n*u+a*h+r*l-s*o,this._w=a*u-r*o-s*l-n*h,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Vt=class Dr{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,this}copy(t){return this.elements.set(t.elements),this}clone(){let t=new Dr;return t.copy(this),t}compose(t,i,r){return xe(this.elements,[i.x,i.y,i.z,i.w],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,i){return yt(this.elements,t.elements,i.elements),this}lookAt(t,i,r){return te(this.elements,[t.x,t.y,t.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(t){let i=new Q(0,0,0),r=new Q(1,1,1);return this.compose(i,t,r)}makeTranslation(t,i,r){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(t,i,r){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},bi=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 Et(this.elements,e.elements),this}},vt=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,he=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,xi={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},Ct=class Lr{constructor(t,i,r){this.r=1,this.g=1,this.b=1,t!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(t,i,r):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let i=t.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let s=parseInt(r,16);r.length===6&&!Number.isNaN(s)&&this.setHex(s)}else if(i in xi)this.setHex(xi[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let s=n=>vt(Math.max(0,Math.min(1,(parseFloat(n)||0)/(n.endsWith("%")?100:255))));this.setRGB(s(r[0]),s(r[1]),s(r[2]))}}return this}setHSL(t,i,r){if(t=((Number(t)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let o=vt(r);return this.setRGB(o,o,o)}let s=r<=.5?r*(1+i):r+i-r*i,n=2*r-s,a=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?n+(s-n)*6*o:o<1/2?s:o<2/3?n+(s-n)*6*(2/3-o):n);return this.setRGB(vt(a(t+1/3)),vt(a(t)),vt(a(t-1/3)))}lerp(t,i){return this.lerpColors(this,t,i)}lerpColors(t,i,r){let s=Number(r)||0;return this.setRGB(t.r+(i.r-t.r)*s,t.g+(i.g-t.g)*s,t.b+(i.b-t.b)*s)}multiplyScalar(t){let i=Number(t)||0;return this.setRGB(this.r*i,this.g*i,this.b*i)}setScalar(t){let i=Number(t)||0;return this.setRGB(i,i,i)}setHex(t){let i=Math.floor(t);return this.setRGB(vt((i>>16&255)/255),vt((i>>8&255)/255),vt((i&255)/255))}setRGB(t,i,r){return this.r=Number(t),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.setRGB(vt(this.r),vt(this.g),vt(this.b))}convertLinearToSRGB(){return this.setRGB(he(this.r),he(this.g),he(this.b))}getHex(){let t=i=>Math.round(he(Math.max(0,Math.min(1,i)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(t){return this.setRGB(t.r,t.g,t.b)}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new Lr(this.r,this.g,this.b)}},vi={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,i)=>Math.max(t,Math.min(i,e)),lerp:(e,t,i)=>e+(t-e)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},bt=class Ir{constructor(t,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=i;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/i)}getX(t){return this.array[t*this.itemSize]}getY(t){return this.array[t*this.itemSize+1]}getZ(t){return this.array[t*this.itemSize+2]}setX(t,i){return this.array[t*this.itemSize]=i,this.needsUpdate=!0,this}setY(t,i){return this.array[t*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(t,i){return this.array[t*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(t,i,r,s){let n=t*this.itemSize;return this.array[n]=i,this.array[n+1]=r,this.array[n+2]=s,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new Ir(new t(this.array),this.itemSize)}},Mi=class extends bt{constructor(e,t){super(e instanceof Float32Array||Array.isArray(e)?e:new Float32Array(e),t)}},wi=class extends bt{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},Ti=class extends bt{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},ft=class Fr{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,i){return this.attributes[t]=i,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof bt)this.index=t;else if(Array.isArray(t)){let i=0;for(let r of t)r>i&&(i=r);this.index=new bt(new(i>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new bt(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let i=!1;if(typeof i=="function"){let l=i(t.array,this.index?.array);return this.setAttribute("normal",new bt(l,3)),this}let r=t.count,s=t.array,n=new Float32Array(r*3),a=this.index?.array,o=a?a.length:r;for(let l=0;l<o;l+=3){let h=(a?a[l]:l)*3,u=(a?a[l+1]:l+1)*3,f=(a?a[l+2]:l+2)*3,g=s[u],w=s[u+1],p=s[u+2],b=s[f]-g,T=s[f+1]-w,x=s[f+2]-p,M=s[h]-g,c=s[h+1]-w,m=s[h+2]-p,v=T*m-x*c,S=x*M-b*m,D=b*c-T*M;n[h]+=v,n[h+1]+=S,n[h+2]+=D,n[u]+=v,n[u+1]+=S,n[u+2]+=D,n[f]+=v,n[f+1]+=S,n[f+2]+=D}for(let l=0;l<r*3;l+=3){let h=n[l],u=n[l+1],f=n[l+2],g=Math.hypot(h,u,f)||1;n[l]=h/g,n[l+1]=u/g,n[l+2]=f/g}return this.setAttribute("normal",new bt(n,3)),this}setFromBuffers(t,i,r,s){this.setAttribute("position",new bt(t,3)),this.setAttribute("normal",new bt(i,3)),this.setAttribute("uv",new bt(r,2)),this.setIndex(s)}setFromPoints(t){let i=[];if(Array.isArray(t))for(let r of t)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new bt(i,3))}computeBoundingBox(){let t=this.attributes.position,i=new Q(1/0,1/0,1/0),r=new Q(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let s=0;s<t.count;s++){let n=t.getX(s),a=t.getY(s),o=t.getZ(s);n<i.x&&(i.x=n),a<i.y&&(i.y=a),o<i.z&&(i.z=o),n>r.x&&(r.x=n),a>r.y&&(r.y=a),o>r.z&&(r.z=o)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,i){let r=this.attributes.position;if(r){let s=r.array;for(let n=0;n<s.length;n+=3)t(s,n);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,i=0,r=0){return this._xform((s,n)=>{s[n]+=t,s[n+1]+=i,s[n+2]+=r})}scale(t=1,i=1,r=1){return this._xform((s,n)=>{s[n]*=t,s[n+1]*=i,s[n+2]*=r},!0)}_rot(t,i,r){let s=Math.cos(r),n=Math.sin(r);for(let a of[this.attributes.position,this.attributes.normal]){if(!a)continue;let o=a.array;for(let l=0;l<o.length;l+=3){let h=o[l+t],u=o[l+i];o[l+t]=h*s-u*n,o[l+i]=h*n+u*s}a.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let i=this.attributes.position;if(i&&t?.elements){let r=new Q;for(let s=0;s<i.count;s++)r.set(i.getX(s),i.getY(s),i.getZ(s)).applyMatrix4(t),i.setXYZ(s,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let t=new Fr;t.name=this.name;for(let i of Object.keys(this.attributes))t.attributes[i]=this.attributes[i].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},Ne=class extends ft{constructor(e=1,t=1,i=1){super();let r=e/2,s=t/2,n=i/2,a=[-r,-s,n,r,-s,n,r,s,n,-r,s,n,r,-s,-n,-r,-s,-n,-r,s,-n,r,s,-n,-r,s,n,r,s,n,r,s,-n,-r,s,-n,-r,-s,-n,r,-s,-n,r,-s,n,-r,-s,n,r,-s,n,r,-s,-n,r,s,-n,r,s,n,-r,-s,-n,-r,-s,n,-r,s,n,-r,s,-n],o=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],l=[],h=[];for(let u=0;u<6;u++){let f=u*4;l.push(0,0,1,0,1,1,0,1),h.push(f,f+1,f+2,f,f+2,f+3)}this.setFromBuffers(a,o,l,h)}},Si=class extends ft{constructor(e=1,t=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let s=[],n=[],a=[],o=[];for(let l=0;l<=r;l++){let h=l/r;for(let u=0;u<=i;u++){let f=u/i;if(s.push((f-.5)*e,(.5-h)*t,0),n.push(0,0,1),a.push(f,1-h),l>0&&u>0){let g=(i+1)*l+u-1,w=g-(i+1);o.push(w,g,w+1,g,g+1,w+1)}}}this.setFromBuffers(s,n,a,o)}},Ai=class extends ft{constructor(e=1,t=16,i=12,r=0,s=Math.PI*2,n=0,a=Math.PI){super(),t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));let o=[],l=[],h=[],u=[],f=Math.min(n+a,Math.PI);for(let g=0;g<=i;g++){let w=g/i,p=n+w*a;for(let b=0;b<=t;b++){let T=b/t,x=r+T*s,M=-Math.cos(x)*Math.sin(p),c=Math.cos(p),m=Math.sin(x)*Math.sin(p);if(o.push(e*M,e*c,e*m),l.push(M,c,m),h.push(T,1-w),g>0&&b>0){let v=(t+1)*g+b,S=v-(t+1),D=S-1,I=v-1;(g!==1||n>0)&&u.push(S,D,v),(g!==i||f<Math.PI)&&u.push(D,I,v)}}}this.setFromBuffers(o,l,h,u)}},Ee=class extends ft{constructor(e=1,t=1,i=1,r=16,s=1,n=!1,a=0,o=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),s=Math.max(1,Math.floor(Number(s)||1));let l=[],h=[],u=[],f=[],g=i/2,w=(t-e)/(i||1),p=r+1;for(let T=0;T<=s;T++){let x=T/s,M=x*(t-e)+e,c=g-x*i;for(let m=0;m<=r;m++){let v=m/r,S=a+v*o,D=Math.sin(S),I=Math.cos(S),P=Math.hypot(D,w,I)||1;if(l.push(M*D,c,M*I),h.push(D/P,w/P,I/P),u.push(v,1-x),T<s&&m<r){let N=T*p+m,C=N+p;f.push(N,C,N+1,C,C+1,N+1)}}}let b=(T,x)=>{if(n||T<=0)return;let M=x*g,c=l.length/3;l.push(0,M,0),h.push(0,x,0),u.push(.5,.5);let m=c+1;for(let v=0;v<=r;v++){let S=a+v/r*o,D=Math.sin(S),I=Math.cos(S);l.push(T*D,M,T*I),h.push(0,x,0),u.push(I*.5+.5,.5+x*D*.5),v<r&&f.push(c,m+v+(x>0?0:1),m+v+(x>0?1:0))}};b(e,1),b(t,-1),this.setFromBuffers(l,h,u,f)}},Ri=class extends Ee{constructor(e=1,t=1,i=16,r=1,s=!1,n=0,a=Math.PI*2){super(0,e,t,i,r,s,n,a)}},_i=class extends ft{constructor(e=1,t=.4,i=12,r=48,s=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let n=[],a=[],o=[],l=[];for(let h=0;h<=i;h++){let u=h/i*Math.PI*2,f=Math.cos(u),g=Math.sin(u);for(let w=0;w<=r;w++){let p=w/r*s,b=Math.cos(p),T=Math.sin(p);if(n.push((e+t*f)*b,(e+t*f)*T,t*g),a.push(f*b,f*T,g),o.push(w/r,h/i),h>0&&w>0){let x=(r+1)*h+w-1,M=x-(r+1);l.push(x,M,x+1,M,M+1,x+1)}}}this.setFromBuffers(n,a,o,l)}};function Ci(e,t,i,r,s){let n=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),a=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),o=Number(r)||.1,l=[],h=[],u=[],f=[],g=[],w=new Q,p=new Q,b=new Q;for(let x=0;x<=n;x++){let M=new Q;s(x/n,M),g.push(M)}let T=a+1;for(let x=0;x<=n;x++){let M=x/n,c=g[x];w.subVectors(g[Math.min(n,x+1)],g[Math.max(0,x-1)]).normalize(),x===0&&p.set(Math.abs(w.y)>.9?1:0,Math.abs(w.y)>.9?0:1,0),b.crossVectors(w,p).normalize(),p.crossVectors(b,w).normalize();for(let m=0;m<=a;m++){let v=m/a*Math.PI*2,S=-Math.cos(v),D=Math.sin(v),I=S*p.x+D*b.x,P=S*p.y+D*b.y,N=S*p.z+D*b.z;if(l.push(c.x+o*I,c.y+o*P,c.z+o*N),h.push(I,P,N),u.push(M,m/a),x>0&&m>0){let C=T*(x-1)+m-1,L=C+T;f.push(C,L,C+1,L,L+1,C+1)}}}e.setFromBuffers(l,h,u,f)}var Pi=class extends ft{constructor(e=1,t=.4,i=64,r=8,s=2,n=3){super(),i=Math.floor(i),r=Math.floor(r),Ci(this,i,r,t,(a,o)=>{let l=a*s*Math.PI*2,h=n/s*l,u=e*(2+Math.cos(h))*.5;o.set(u*Math.cos(l),u*Math.sin(l),e*Math.sin(h)*.5)})}},Ut=class{getPoint(e,t=new Q){return t}getPointAt(e,t=new Q){return this.getPoint(e,t)}getTangent(e,t=new Q){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),i=[];for(let r=0;r<=t;r++)i.push(this.getPoint(r/t));return i}getSpacedPoints(e=5){return this.getPoints(e)}},Ni=class extends Ut{constructor(e=new Q,t=new Q){super(),this.v1=e,this.v2=t}getPoint(e,t=new Q){return t.lerpVectors(this.v1,this.v2,e)}},Ei=class extends Ut{constructor(e=new Q,t=new Q,i=new Q){super(),this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new Q){return t.lerpVectors(this.v0,this.v1,e).lerp(new Q().lerpVectors(this.v1,this.v2,e),e)}},Di=class extends Ut{constructor(e=new Q,t=new Q,i=new Q,r=new Q){super(),this.v0=e,this.v1=t,this.v2=i,this.v3=r}getPoint(e,t=new Q){let i=new Q().lerpVectors(this.v0,this.v1,e),r=new Q().lerpVectors(this.v1,this.v2,e),s=new Q().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(i.lerp(r,e),r.lerp(s,e),e)}},Li=class extends Ut{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new Q){let i=this.points,r=i.length;if(!r)return t.set(0,0,0);if(r===1)return t.copy(i[0]);let s=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(e)||0)),n=Math.floor(s),a=s-n;!this.closed&&n>=r-1&&(n=r-2,a=1);let o=b=>i[this.closed?(b%r+r)%r:Math.max(0,Math.min(r-1,b))],l=o(n-1),h=o(n),u=o(n+1),f=o(n+2),g=a*a,w=g*a,p=(b,T,x,M)=>.5*(2*T+(x-b)*a+(2*b-5*T+4*x-M)*g+(3*T-b-3*x+M)*w);return t.set(p(l.x,h.x,u.x,f.x),p(l.y,h.y,u.y,f.y),p(l.z,h.z,u.z,f.z))}},De=class extends ft{constructor(e=[new At(0,-.5),new At(.5,0),new At(0,.5)],t=12,i=0,r=Math.PI*2){super();let s=Array.isArray(e)&&e.length>=2?e:[new At(.2,0),new At(.2,.5)],n=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),a=[],o=[],l=[],h=[],u=s.length;for(let f=0;f<=n;f++){let g=f/n,w=i+g*r,p=Math.sin(w),b=Math.cos(w),T=f*u;for(let x=0;x<u;x++){let M=s[x],c=Number(M?.x)||0,m=Number(M?.y)||0;a.push(c*p,m,c*b);let v=s[Math.max(0,x-1)],S=s[Math.min(u-1,x+1)],D=(Number(S?.x)||0)-(Number(v?.x)||0),I=(Number(S?.y)||0)-(Number(v?.y)||0),P=Math.hypot(I,D)||1;if(o.push(I/P*p,-D/P,I/P*b),l.push(g,x/(u-1)),f<n&&x<u-1){let N=T+x,C=N+u;h.push(N,C,N+1,C,C+1,N+1)}}}this.setFromBuffers(a,o,l,h)}},Ii=class extends ft{constructor(e,t=64,i=1,r=8,s=!1){super(),Ci(this,t,r,i,(n,a)=>{let o=e?.getPointAt??e?.getPoint;if(typeof o=="function"){let l=o.call(e,n,a);l&&l!==a&&a.copy(l)}else a.set(0,n,0)})}},ue="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ce=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new At(1,1),this.offset=new At(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Fi=class extends ce{constructor(e=null,t=1,i=1,r=1023,s=1009,n,a=1001,o=1001,l=1003,h=1003,u=1,f=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let g=Number(t),w=Number(i),p=e&&typeof e.length=="number"?e:null;this.width=g,this.height=w,this.image={data:p,width:g,height:w},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(a)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(l)||1003,this.minFilter=Number(h)||1003,this.colorSpace=f||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,i=Number(e?.width??this.width),r=Number(e?.height??this.height);if(!t||!t.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let s=Math.max(1,i|0),n=Math.max(1,r|0),a=s*n,o=this.format,l=o===1021||o===1024||o===1028||t.length===a?1:o===1025||o===1030||t.length===a*2?2:o===1022||t.length===a*3?3:4,h=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,u=Math.min(s,48),f=Math.min(n,48),g=(this.flipY?257:1)^this.colorSpace.length^t.length,w=Math.max(1,t.length>>6|0);for(let L=0;L<t.length;L+=w)g=Math.imul(g^(t[L]*256|0),16777619)|0;if(g===this._sig&&this.source)return;this._sig=g;let p=f*(1+u*4),b=new Uint8Array(68+p),T=new DataView(b.buffer);T.setUint32(0,2303741511),T.setUint32(4,218765834),T.setUint32(8,13),T.setUint32(12,1229472850),T.setUint32(16,u),T.setUint32(20,f),b[24]=8,b[25]=6,T.setUint32(29,_e(b.subarray(12,29))),T.setUint32(33,p+11),T.setUint32(37,1229209940),b[41]=120,b[42]=1,b[43]=1,T.setUint16(44,p,!0),T.setUint16(46,~p&65535,!0);let x=48,M=1,c=0,m=0,v=0,S=0,D=0,I=L=>{if(!Number.isFinite(L))return 0;let E=h&&L<=1?L*255:L;return E>0?E<255?E+.5|0:255:0};for(let L=0;L<f;L++){let E=L*n/f|0,y=this.flipY?n-1-E:E;b[x++]=0,c+=M;for(let F=0;F<u;F++){let z=(y*s+(F*s/u|0))*l,A=o===1021?255:I(t[z]??0),_=l>=3||o===1030?I(t[z+1]??0):A,d=l>=3?I(t[z+2]??0):o===1030?0:A,R=l===4?I(t[z+3]??255):o===1021?I(t[z]??255):o===1025?I(t[z+1]??255):255;b[x++]=A,M+=A,c+=M,b[x++]=_,M+=_,c+=M,b[x++]=d,M+=d,c+=M,b[x++]=R,M+=R,c+=M,m+=A,v+=_,S+=d,D+=R}M%=65521,c%=65521}T.setUint32(x,(c<<16|M)>>>0),T.setUint32(x+4,_e(b.subarray(37,x+4))),T.setUint32(x+12,1229278788),T.setUint32(x+16,2923585666);let P=u*f*255,N=this.colorSpace==="srgb-linear";this.avgColor=[N?m/P:vt(m/P),N?v/P:vt(v/P),N?S/P:vt(S/P),D/P];let C=["data:image/png;base64,"];for(let L=0;L<b.length;L+=3){let E=b[L]<<16|(b[L+1]??0)<<8|(b[L+2]??0);C.push(ue[E>>18&63]+ue[E>>12&63]+(L+1<b.length?ue[E>>6&63]:"=")+(L+2<b.length?ue[E&63]:"="))}this.source=C.join("")}},Ui=class{load(e,t){let i=new ce(e);return t?.(i),i}};function xt(e,t){return e!==void 0?Number(e):t}function Le(e,t){return e!==void 0?!!e:t}var Tt=class{constructor(e={}){this.name=e.name||"",this.color=new Ct(e.color??16777215),this.emissive=new Ct(e.emissive??0),this.emissiveIntensity=xt(e.emissiveIntensity,1),this.roughness=xt(e.roughness,.5),this.metalness=xt(e.metalness,0),this.opacity=xt(e.opacity,1),this.transparent=Le(e.transparent,!1),this.wireframe=Le(e.wireframe,!1),this.side=xt(e.side,2),this.doubleSided=Le(e.doubleSided,!0),this.map=e.map||null;for(let t of["normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])e[t]&&(this[t]=e[t]);this.clearcoat=xt(e.clearcoat,0),this.clearcoatRoughness=xt(e.clearcoatRoughness,0),this.sheen=xt(e.sheen,0),this.sheenColor=new Ct(e.sheenColor??0),this.sheenRoughness=xt(e.sheenRoughness,0),this.transmission=xt(e.transmission,0),this.thickness=xt(e.thickness,0),this.attenuationColor=new Ct(e.attenuationColor??16777215),this.attenuationDistance=xt(e.attenuationDistance,1/0),this.ior=xt(e.ior,1.5),this.dispersion=xt(e.dispersion,0),this.iridescence=xt(e.iridescence,0),this.iridescenceIOR=xt(e.iridescenceIOR,1.3)}dispose(){}},Xt=class extends Tt{},ki=class extends Tt{},$i=class extends Tt{},Oi=class extends Tt{},Bi=class extends Tt{},Pt=class Ur{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 Q,this.rotation=new Pe,this.quaternion=new le,this.scale=new Q(1,1,1),this.matrix=new Vt,this.matrixWorld=new Vt,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,i=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),s=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(i,r,s)})}add(...t){for(let i of t)i&&i instanceof Ur&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...t){for(let i of t){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(t){let i=new Set,r=[this];for(;r.length>0;){let s=r.pop();if(!s||typeof s!="object"||i.has(s))continue;i.add(s),t(s);let n=s.children;if(Array.isArray(n))for(let a=n.length-1;a>=0;a--)r.push(n[a])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(i=>{Vi(i),(i.matrixAutoUpdate||t)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(t,i,r){let s=typeof t=="object"?t:new Q(t,i,r);this.target instanceof Q?this.target.copy(s):this.target?.position instanceof Q&&this.target.position.copy(s),this.updateMatrixWorld(!0);let n=new Vt;n.lookAt(this.position,s,new Q(0,1,0));let a=n.elements,o=a[0],l=a[4],h=a[8],u=a[1],f=a[5],g=a[9],w=a[2],p=a[6],b=a[10],T=o+f+b;if(T>0){let x=.5/Math.sqrt(T+1);this.quaternion.set((p-g)*x,(h-w)*x,(u-l)*x,.25/x)}}translateOnAxis(t,i){let r=t.clone().applyMatrix4(new Vt().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(t){return this.translateOnAxis(new Q(1,0,0),t)}translateY(t){return this.translateOnAxis(new Q(0,1,0),t)}translateZ(t){return this.translateOnAxis(new Q(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}_chain(){let t=[];for(let i=this;i&&t.length<64;i=i.parent)t.push(i);return t}_syncWorld(){let t=this._chain();for(let i=t.length-1;i>=0;i--){let r=t[i];r.updateMatrix?.(),r.parent?.matrixWorld?r.matrixWorld.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrixWorld?.copy(r.matrix)}return this.matrixWorld.elements}getWorldPosition(t=new Q){let i=this._syncWorld();return t.set(i[12],i[13],i[14])}getWorldScale(t=new Q){let i=this._syncWorld();return t.set(Math.hypot(i[0],i[1],i[2]),Math.hypot(i[4],i[5],i[6]),Math.hypot(i[8],i[9],i[10]))}getWorldDirection(t=new Q){let i=this._syncWorld();return t.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(t=new le){let i=this._chain();t.set(0,0,0,1);for(let r=i.length-1;r>=0;r--)t.multiply(i[r].quaternion);return t}clone(t=!0){let i=this instanceof Ht?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Lt?new Lt(this.geometry,this.material):new this.constructor;i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,i.castShadow=this.castShadow,i.receiveShadow=this.receiveShadow;try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(t)for(let r of this.children)i.add(r.clone(!0));return i}},zi=class extends Pt{},Lt=class extends Pt{constructor(e,t){super(),this.isMesh=!0;let i=Array.isArray(t)?t[0]:t;this.geometry=e instanceof ft?e:e?(kt("unsupported geometry","BoxGeometry"),new Ne(.5,.5,.5)):new ft,this.material=i instanceof Tt?i:i?(kt("unsupported material","MeshStandardMaterial"),new Xt({color:13421772})):new Xt}};function Vi(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=mt().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var qt=1e4,Ie=class extends Lt{constructor(e,t,i=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>qt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${qt})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let n=0;n<this.count;n++){let a=n*16;s[a]=1,s[a+5]=1,s[a+10]=1,s[a+15]=1}this.instanceMatrix=new bt(s,16)}setMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++){let a=Number(t.elements[n]);r[s+n]=Number.isFinite(a)?a:n%5===0?1:0}}getMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++)t.elements[n]=r[s+n]}setColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let n=new Float32Array(this.count*3);n.fill(1),this.instanceColor=new bt(n,3)}let r=this.instanceColor.array,s=i*3;r[s]=Number.isFinite(t.r)?t.r:1,r[s+1]=Number.isFinite(t.g)?t.g:1,r[s+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){t.setRGB(1,1,1);return}let r=this.instanceColor.array,s=i*3;t.setRGB(r[s],r[s+1],r[s+2])}dispose(){}},Kt=class extends Pt{constructor(e=16777215,t=1){super(),this.color=new Ct(e),this.intensity=Number(t),this.type="directional"}},Fe=class extends Kt{constructor(e,t){super(e,t),this.type="ambient"}},Gi=class extends Kt{constructor(e,t){super(e,t),this.target=new Pt,this.type="directional"}},Ue=class extends Kt{constructor(e,t,i=0,r=2){super(e,t),this.type="point",this.distance=i,this.decay=r}},ke=class extends Pt{},Hi=class extends ke{constructor(e=45,t=1,i=.1,r=1e3){super(),this.target=new Q(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(i),this.far=Number(r)}},$e=class extends Pt{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return It.validate(this),Wt(this)}toGLB(){return It.validate(this),ie(this)}toUSDZ(){return It.validate(this),oe(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(i=>{if(i instanceof Lt){let r=new Float32Array(i.matrixWorld.elements);e.set(t,r),i.name&&e.set(i.name,r),t++}}),e}},Oe=Wt,Be=ie,ji=oe,It=class{static validate(e){let t=0,i=0,r=0,s=new Set,n=(o,l,h)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${l}). Found: ${h}`)},a=(o,l)=>{if(!Number.isFinite(l))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(l)}), which cannot be bounds-checked.`);return l};e.traverse(o=>{if(Vi(o),o instanceof Lt||o.geometry?.attributes?.position?.count){if(r++,r>1e3&&n("MESHES",1e3,r),o instanceof Ie){let h=a("instance",o.count);(h<0||h>qt)&&n("INSTANCES",qt,h)}let l=o.geometry;if(l){let h=0;if(l.attributes.position&&(h=a("vertex",l.attributes.position.count),t+=h,t>1e5&&n("VERTICES",1e5,t)),l.index){let u=a("index",l.index.count);i+=u,i>3e5&&n("INDICES",3e5,i);let f=l.index.array;if(f&&h>0){let g=Math.min(u,f.length);for(let w=0;w<g;w++){let p=f[w];if(!Number.isFinite(p)||p<0||p>=h)throw new Error(`SecurityError: Index buffer value (${String(p)}) out of vertex bounds [0, ${h}).`)}}}}if(o.material){let h=o.material;for(let u of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])h[u]&&s.add(h[u])}}}),s.size>16&&n("TEXTURES",16,s.size);for(let o of s){let l=o,h=l.image,u=Number(h?.width??l.width??0)||0,f=Number(h?.height??l.height??0)||0;(!Number.isFinite(u)||!Number.isFinite(f)||u>2048||f>2048)&&n("TEXTURE_DIMENSION",2048,Math.max(u,f))}}},Wi=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let i=new Ct(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){It.validate(e);let r=(s,n)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(n&&n.length?self.postMessage(s,n):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),n={};for(let[a,o]of s.entries())n[a]=Array.from(o);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:n})}else{this.hasInitialModelRendered=!0;let s=Oe(e),n=Be(e),a=(s.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:n.buffer,dynamicLights:a,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[n.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(e.getMeshTransforms()):(i.loadModel(e.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function Xi(){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 qi=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=Xi(),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=Xi();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function cs(){}var Yt=new Proxy(cs,{get:(e,t)=>{if(t==="isProxy")return!0;if(!(t==="constructor"||t==="__proto__"||t==="prototype"))return t==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:t==="shadowMap"?{enabled:!1,type:0}:t==="capabilities"?{isWebGL2:!0,maxTextures:16}:t===Symbol.toPrimitive?()=>0:Yt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Yt,construct:()=>Yt}),Ki=(()=>{try{if(typeof document>"u")return null;let e=document.currentScript;return e?.src?e.src:e?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([e.textContent],{type:"text/javascript"})):null}catch{return null}})();function me(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Gt(e,t){if(!e||typeof e!="string")return!1;let i=e.trim();if(!i)return!1;try{let r=new URL(i,me());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||t?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var Yi,Zt;function Zi(e){if(!Gt(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(Zt===void 0||Yi!==t){Yi=t;try{Zt=t.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Gt(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{Zt=null}}return Zt?Zt.createScriptURL(e):e}function ms(e){mt().sandboxEngineSrc=e}function ze(){let e=mt().sandboxEngineSrc;if(e)return e;if(Ki)return Ki;try{if(typeof document>"u")return null;let t=me(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let s=r.src;if(!s)continue;let n=new URL(s,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(n)&&Gt(s,{requireSameOrigin:!0}))return s}}catch{}return null}function Ve(e,t){if(!Gt(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,me()).href}function ps(){let e=ze();if(!e)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");return Ve(e,"sandbox engine")}function fs(e){mt().sandboxIframeSrc=e}function Ji(){let e=mt().sandboxIframeSrc;if(e)return e;let t=ze();if(!t||!Gt(t))return null;let i=new URL(t,me());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function ds(){let e=Ji();if(!e)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");return Ve(e,"sandbox iframe")}function gs(e){mt().allowClientScripts=e}function Qi(){return!!mt().allowClientScripts}function ys(e){return Ve(e,"procedural scene script")}var bs=["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 xs(e,t){let i=self,r=e.nonce,s=e.engineSrc,n=e.allowedScriptUrl,a=e.allowClientScripts,o=e.revoked,l=i.postMessage.bind(i);function h(c){l({type:"ERROR",nonce:r,message:String(c)})}let u=typeof i.importScripts=="function"?i.importScripts.bind(i):null,f=n,g=null;try{let c=s;if(typeof i.trustedTypes<"u"&&i.trustedTypes&&typeof i.trustedTypes.createPolicy=="function")try{let m={createScriptURL:function(S){if(S!==s&&(!n||S!==n))throw new TypeError("Disallowed worker importScripts URL");return S}};a&&(m.createScript=function(S){return String(S)});let v=i.trustedTypes.createPolicy("three-live#worker-boot",m);c=v.createScriptURL(s),n&&(f=v.createScriptURL(n)),a&&typeof v.createScript=="function"&&(g=v.createScript.bind(v))}catch{}u(c)}catch(c){h('Sandbox failed to load the Three-Live engine from "'+s+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(c&&c.message||c));return}let w=i.THREE;if(!w||typeof w.Scene!="function"){h('Sandbox loaded "'+s+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(t)){let c=i.__THREE_LIVE_REGISTRY__;for(let m=0;m<t.length;m++)if(typeof t[m]=="function")try{t[m](w,c)}catch{}}function p(c,m,v){let S=i;for(;S&&S!==Object.prototype;){if(!v&&S!==i)try{delete S[c]}catch{}if(!v||S===i||Object.prototype.hasOwnProperty.call(S,c))try{Object.defineProperty(S,c,v?{value:m,writable:!1,configurable:!1}:{value:m,writable:!1,configurable:!1,enumerable:!1})}catch{}try{S=Object.getPrototypeOf(S)}catch{break}}}for(let c=0;c<o.length;c++)p(o[c],void 0);p("performance",Object.freeze({now:function(){return Date.now()}}));let b=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],T=!1;function x(c,m){if(c.type==="3D_MODEL_READY"){if(T)return;T=!0}c.nonce=r,m&&m.length?l(c,m):l(c)}p("postMessage",function(c,m){if(!c||b.indexOf(c.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+b.join(", ")+").");x(c,m)},!0);let M=!1;i.onmessage=function(c){let m=c&&c.data;if(!(!m||m.nonce!==r)&&!(m.type!=="EXECUTE"&&m.type!=="EXECUTE_URL")&&!M){M=!0;try{let v=new w.Scene,S=new w.PerspectiveCamera(60,1,.1,1e3),D=new w.WebGLRenderer({isSandboxed:!0});if(m.type==="EXECUTE_URL"){if(!n||m.scriptUrl!==n||typeof u!="function"){h("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let I=f||n,P=u;if(u=null,f=null,i.THREE=w,i.scene=v,i.camera=S,i.renderer=D,P(I),typeof i.__THREE_LIVE_SCENE__=="function"){let N=i.__THREE_LIVE_SCENE__(w,v,S,D);N&&typeof N.toGLB=="function"&&(v=N)}else i.scene&&typeof i.scene.toGLB=="function"&&(v=i.scene)}else{if(!a){h("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let I=g?(0,eval)(g(`(function (THREE, scene, camera, renderer) {
|
|
342
369
|
return (function () {
|
|
343
|
-
`+
|
|
370
|
+
`+m.script+`
|
|
344
371
|
;
|
|
345
372
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
346
373
|
})();
|
|
347
374
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
348
|
-
`+
|
|
375
|
+
`+m.script+`
|
|
349
376
|
;
|
|
350
377
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
351
|
-
})();`);y=null;let N=I(g,v,R,L);N&&typeof N.toGLB=="function"&&(v=N)}if(!w){g.SceneQuotaValidator&&g.SceneQuotaValidator.validate(v);let I=v.toGLB(),N=I instanceof ArrayBuffer?I:I.buffer.slice(I.byteOffset,I.byteOffset+I.byteLength);M({type:"3D_MODEL_READY",glbBuffer:N},[N])}h({type:"DONE",nonce:r})}catch(v){l(v&&v.message||v)}}},h({type:"READY",nonce:r})}function He(e,t,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,n={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:s,revoked:xs},o=(ut().workerExtensionInstallers??[]).map(a=>`(${a.toString()})`).join(",");return`'use strict';(${vs.toString()})(${JSON.stringify(n)},[${o}]);`}function er(e){e.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),e.onToast?.("Security Error: script timed out and was stopped.")}var Dt=0;function ir(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Ms(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var ws=1024,Ts=256;function rr(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let i=e[t];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function je(e,t){if(!e||typeof e!="object")return null;let i=e;if(i.nonce!==t)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,ws)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!rr(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let s=Object.keys(r);if(s.length>1e3)return null;let n=Object.create(null),o=r;for(let a of s){if(a.length>Ts||a==="__proto__"||a==="constructor"||a==="prototype")return null;let h=o[a];if(!rr(h))return null;n[a]=h}return{type:"3D_UPDATE_TRANSFORMS",transforms:n}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function Ss(e){let t=Ms(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function sr(e,t,i,r){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":i();return;case"ERROR":i(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Rs(e,t,i,r){let s=ir(),n=He(t,s,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.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=i,Dt++;let a=!1,h=!1,l={modelDispatched:!1},c,f=()=>{if(a||h)return;let b=o.contentWindow;!b||typeof b.postMessage!="function"||(h=!0,b.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:n,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:s,workerSource:n,script:e.script},"*"))},y=()=>{},g=b=>{if(a||!o.contentWindow||b.source!==o.contentWindow)return;let w=b.data;if(w&&typeof w=="object"&&w.type==="IFRAME_READY"){f();return}let M=je(w,s);M&&sr(M,r,y,l)};y=()=>{a||(a=!0,c!==void 0&&clearTimeout(c),Dt=Math.max(0,Dt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",g),typeof o.remove=="function"?o.remove():o.parentNode&&o.parentNode.removeChild(o))},c=setTimeout(()=>{a||(y(),er(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",g),o.onload=()=>{f()},o.onerror=()=>{y(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let u=document.body||document.documentElement;if(!u||typeof u.appendChild!="function"){y();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(b),b}return u.appendChild(o),{terminate:y}}function nr(e,t,i,r){if(t==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(t==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Dt>=32)return r(`SecurityError: ${Dt} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let s;try{s=ps()}catch(y){let g=y instanceof Error?y.message:String(y);return r(g,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let y;try{y=gs()}catch(g){let u=g instanceof Error?g.message:String(g);return r(u,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Rs(e,s,y,i))}catch(g){return Promise.reject(g)}}let n=ir(),o=He(s,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a;try{let y=new Blob([o],{type:"application/javascript"}),g=URL.createObjectURL(y);try{let u=Ji(g);a=new Worker(u)}finally{URL.revokeObjectURL(g)}}catch(y){let g=y instanceof Error?y.message:String(y);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${g}`,"Security Error: Failed to start Worker sandbox.")}Dt++;let h=!1,l={modelDispatched:!1},c,f=()=>{h||(h=!0,c!==void 0&&clearTimeout(c),Dt=Math.max(0,Dt-1),a.terminate())};return c=setTimeout(()=>{h||(f(),er(i))},3e3),a.onmessage=y=>{let g=je(y.data,n);g&&sr(g,i,f,l)},a.onerror=y=>{f(),i.onError?.(new Error(`Worker execution error: ${y.message}`))},e.kind==="url"?a.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:n}):a.postMessage({type:"EXECUTE",script:e.script,nonce:n}),Promise.resolve({terminate:f})}function ar(e,t){return e==="none"||e==="unsafe-host-realm"?t(`SecurityError: sandbox="${e}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${e}" is not permitted.`):e!=="worker"&&e!=="iframe"?t(`SecurityError: Unsupported sandbox mode "${e}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var or=e=>(t,i)=>{let r=new Error(t);return e.onError?.(r),i&&e.onToast?.(i),Promise.reject(r)},lr={execute(e,t,i,r){let s=or(i),n=ar(t,s);if(n)return n;try{Ss(e)}catch(o){let a=o instanceof Error?o.message:String(o);return s(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??tr()?nr({kind:"script",script:e},t,i,s):s(Vr,Or)},executeUrl(e,t,i){let r=or(i),s=ar(t,r);if(s)return s;let n;try{n=bs(e)}catch(o){let a=o instanceof Error?o.message:String(o);return r(a,"Security Error: disallowed scene script URL.")}return nr({kind:"url",scriptUrl:n},t,i,r)}},ue=new Set;function kt(e,t){let i=`[three-live] ${e} is unsupported; degraded to ${t}.`;ue.has(i)||(ue.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function hr(){return Array.from(ue)}function ur(){ue.clear()}var We=class extends jt{constructor(e={}){kt("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},i=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:i!==void 0?i:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},cr=We,Ut=class extends ft{constructor(e=[],t=[],i=1,r=0){super();let s=Number(i)||1,n=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),o=n+1,a=[],h=[],l=[],c=[],f=new Y,y=new Y,g=new Y,u=(M,x)=>x.set(e[M*3]||0,e[M*3+1]||0,e[M*3+2]||0),b=(M,x)=>{let m=M.clone().normalize();a.push(m.x*s,m.y*s,m.z*s),h.push(x.x,x.y,x.z),l.push(Math.atan2(m.z,-m.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,m.y)))/Math.PI)},w=(M,x,m)=>{let p=a.length/3,v=n===0?new Y().subVectors(m,x).cross(new Y().subVectors(M,x)).normalize():null;b(M,v||M.clone().normalize()),b(x,v||x.clone().normalize()),b(m,v||m.clone().normalize()),c.push(p,p+1,p+2)};for(let M=0;M<t.length;M+=3){u(t[M],f),u(t[M+1],y),u(t[M+2],g);let x=[];for(let m=0;m<=o;m++){x[m]=[];let p=f.clone().lerp(g,m/o),v=y.clone().lerp(g,m/o),R=o-m;for(let L=0;L<=R;L++)x[m][L]=R===0?p.clone():p.clone().lerp(v,L/R)}for(let m=0;m<o;m++)for(let p=0;p<2*(o-m)-1;p++){let v=p>>1;(p&1)===0?w(x[m][v+1],x[m+1][v],x[m][v]):w(x[m][v+1],x[m+1][v+1],x[m+1][v])}}this.setFromBuffers(a,h,l,c)}},Cs=Ut,mr=class extends Ut{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},ce=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],fr=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],pr=class extends Ut{constructor(e=1,t=0){super(ce,fr,e,t)}},at=(1+Math.sqrt(5))/2,dr=class extends Ut{constructor(e=1,t=0){super([-1,at,0,1,at,0,-1,-at,0,1,-at,0,0,-1,at,0,1,at,0,-1,-at,0,1,-at,at,0,-1,at,0,1,-at,0,-1,-at,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},vt=1/at,gr=class extends Ut{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-vt,-at,0,-vt,at,0,vt,-at,0,vt,at,-vt,-at,0,-vt,at,0,vt,-at,0,vt,at,0,-at,0,-vt,at,0,-vt,-at,0,vt,at,0,vt],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},yr=class extends Le{constructor(e=1,t=1,i=4,r=8){let s=Math.max(1e-4,Number(e)||1),n=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,o=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),a=[];for(let h=-1;h<=1;h+=2)for(let l=0;l<=o;l++){if(h>0&&l===0&&n===0)continue;let c=(h<0?l/o-1:l/o)*(Math.PI/2);a.push(new Tt(Math.max(0,Math.cos(c)*s),h*n+Math.sin(c)*s))}super(a,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},Xe=class extends ft{constructor(e=.5,t=1,i=32,r=1,s=0,n=Math.PI*2){super();let o=Math.max(1e-4,Number(t)||1),a=Number(e),h=Number.isFinite(a)?Math.max(0,a):o*.5,l=Math.max(o,h),c=Math.min(l*.999,Math.min(o,h)),f=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),y=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),g=Number.isFinite(Number(s))?Number(s):0,u=Number.isFinite(Number(n))?Number(n):Math.PI*2,b=[],w=[],M=[],x=[];for(let m=0;m<=y;m++){let p=c+m/y*(l-c);for(let v=0;v<=f;v++){let R=g+v/f*u,L=Math.cos(R),I=Math.sin(R);if(b.push(p*L,p*I,0),w.push(0,0,1),M.push(p/l*L*.5+.5,p/l*I*.5+.5),m<y&&v<f){let N=m*(f+1)+v,_=N+f+1;p>1e-6&&x.push(N,_,N+1),x.push(_,_+1,N+1)}}}this.setFromBuffers(b,w,M,x)}},br=class extends Xe{constructor(e=1,t=32,i=0,r=Math.PI*2){super(0,e,t,1,i,r)}},qe=class extends Mt{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},me=class extends Mt{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},xr=class extends me{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function vr(e,t){let i=e?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,s=e?.index?.array,n=Math.min(8192,Math.floor((s?s.length:i.count)/3)),o=y=>`${Math.round((r[y*3]||0)*1e4)},${Math.round((r[y*3+1]||0)*1e4)},${Math.round((r[y*3+2]||0)*1e4)}`,a=t===void 0,h=a?1:Math.cos(t*Math.PI/180),l={},c=[],f=(y,g)=>c.push(r[y*3]||0,r[y*3+1]||0,r[y*3+2]||0,r[g*3]||0,r[g*3+1]||0,r[g*3+2]||0);for(let y=0;y<n;y++){let g=s?s[y*3]:y*3,u=s?s[y*3+1]:y*3+1,b=s?s[y*3+2]:y*3+2,w=r[g*3]||0,M=r[g*3+1]||0,x=r[g*3+2]||0,m=(r[u*3]||0)-w,p=(r[u*3+1]||0)-M,v=(r[u*3+2]||0)-x,R=(r[b*3]||0)-w,L=(r[b*3+1]||0)-M,I=(r[b*3+2]||0)-x,N=p*I-v*L,_=v*R-m*I,A=m*L-p*R,E=Math.hypot(N,_,A);if(!a&&E<1e-8)continue;E>0&&(N/=E,_/=E,A/=E);let C=[g,u,b];for(let d=0;d<3;d++){let k=C[d],$=C[(d+1)%3],S=o(k),D=o($);if(S===D)continue;let T=S<D?`${S}|${D}`:`${D}|${S}`,P=l[T];P?P.m||(P.m=1,P.nx*N+P.ny*_+P.nz*A<=h&&f(k,$)):(l[T]={va:k,vb:$,nx:N,ny:_,nz:A,m:a?1:0},a&&f(k,$))}}if(!a){let y=Object.keys(l);for(let g=0;g<y.length;g++){let u=l[y[g]];u&&!u.m&&f(u.va,u.vb)}}return new Float32Array(c)}var Mr=class extends ft{constructor(e){super(),this.setAttribute("position",new gt(vr(e),3)),this.__isSegmentPairs=!0}},wr=class extends ft{constructor(e,t=1){super();let i=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new gt(vr(e,i),3)),this.__isSegmentPairs=!0}};function As(e,t,i=1){let r=new ft;r.__baked=!0;let s=e?.attributes?.position;if(!s?.array||s.count<2)return r;let n=s.array,o=e.index?.array,a=e.__isSegmentPairs?"segments":t,h=o?o.length:s.count,l=Math.min(4096,Math.max(0,a==="segments"?Math.floor(h/2):a==="loop"&&h>=3?h:h-1));if(l===0)return r;e.computeBoundingBox();let c=e.boundingBox,f=c&&c.max.distanceTo(c.min)||1,y=Math.max(.0015,Math.min(.025,f*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),g=[],u=[],b=[],w=[];for(let M=0;M<l;M++){let x=a==="segments"?M*2:M,m=a==="segments"?M*2+1:(M+1)%h,p=o?o[x]:x,v=o?o[m]:m,R=n[p*3]||0,L=n[p*3+1]||0,I=n[p*3+2]||0,N=(n[v*3]||0)-R,_=(n[v*3+1]||0)-L,A=(n[v*3+2]||0)-I,E=Math.hypot(N,_,A);if(E<1e-6)continue;let C=N/E,d=_/E,k=A/E,$=(Math.abs(d)<.9?Math.hypot(k,C):Math.hypot(k,d))||1,S=Math.abs(d)<.9?k/$:0,D=Math.abs(d)<.9?0:-k/$,T=Math.abs(d)<.9?-C/$:d/$,P=d*T-k*D,j=k*S-C*T,W=C*D-d*S,V=g.length/3,Z=[[S,D,T],[P,j,W],[-S,-D,-T],[-P,-j,-W]];for(let U=0;U<2;U++){let X=R+U*N,O=L+U*_,G=I+U*A;for(let F=0;F<4;F++){let H=Z[F];g.push(X+H[0]*y,O+H[1]*y,G+H[2]*y),u.push(H[0],H[1],H[2]),b.push(F/4,U)}}for(let U=0;U<4;U++){let X=(U+1)%4;w.push(V+U,V+X,V+4+X,V+U,V+4+X,V+4+U)}}return g.length>0&&r.setFromBuffers(g,u,b,w),r}function Ps(e,t=.05){let i=new ft;i.__baked=!0;let r=e?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,n=r.count,o=Math.min(n,5e3),a=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),h=[],l=[],c=[],f=[];for(let y=0;y<o;y++){let g=n<=5e3?y:Math.floor(y*n/o),u=s[g*3]||0,b=s[g*3+1]||0,w=s[g*3+2]||0,M=y*6;for(let x=0;x<6;x++){let m=ce[x*3],p=ce[x*3+1],v=ce[x*3+2];h.push(u+m*a,b+p*a,w+v*a),l.push(m,p,v),c.push(.5,.5)}for(let x=0;x<24;x++)f.push(M+fr[x])}return i.setFromBuffers(h,l,c,f),i}var $t=class extends Et{constructor(e,t,i="strip"){let r=t&&typeof t=="object"?t:{},s=t instanceof Mt?t:i==="points"?new qe(r):new me(r),n=e instanceof ft?e:new ft;super(n,s),this.isLine=!0,this._lineMode=i,this._sourceGeo=n}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=t.array,r=Math.min(t.count,64),s=0,n=0,o=0;for(let a=0;a<r;a++)s+=i[a*3]||0,n+=i[a*3+1]||0,o+=i[a*3+2]||0;this.material.color.setRGB(s/r,n/r,o/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?Ps(this._sourceGeo,this.material?.size??.05):As(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},Tr=class extends $t{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},Sr=class extends $t{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},Rr=class extends $t{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},Cr=class extends Ue{constructor(e,t,i=0,r=Math.PI/3,s=0,n=2){super(e,t,i,n),this.target=new Ct,this.type="spot";let o=Number(r);this.angle=Number.isFinite(o)?Math.max(.01,Math.min(Math.PI/2,o)):Math.PI/3;let a=Number(s);this.penumbra=Number.isFinite(a)?Math.max(0,Math.min(1,a)):0}},Ke=class extends ke{constructor(e,t,i){kt("HemisphereLight","AmbientLight"),super(e,i),this.groundColor=new Rt(t??4473924)}},Ar=Ke,Pr={Vector2:Tt,Vector3:Y,Vector4:bi,Euler:_e,Quaternion:Ee,Matrix4:Ot,Matrix3:xi,Color:Rt,MathUtils:Mi,BufferAttribute:gt,Float32BufferAttribute:wi,Uint16BufferAttribute:Ti,Uint32BufferAttribute:Si,BufferGeometry:ft,BoxGeometry:Ne,PlaneGeometry:Ri,SphereGeometry:Ci,CylinderGeometry:De,ConeGeometry:Ai,TorusGeometry:Pi,TorusKnotGeometry:Ei,Curve:Ft,Curve3:Ft,LineCurve3:Ni,QuadraticBezierCurve3:Di,CubicBezierCurve3:Li,CatmullRomCurve3:Ii,LatheGeometry:Le,TubeGeometry:Fi,PolyhedronGeometry:Ut,IcosahedronGeometry:dr,OctahedronGeometry:pr,DodecahedronGeometry:gr,TetrahedronGeometry:mr,CapsuleGeometry:yr,RingGeometry:Xe,CircleGeometry:br,WireframeGeometry:Mr,EdgesGeometry:wr,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:le,DataTexture:ki,TextureLoader:Ui,Material:Mt,MeshStandardMaterial:jt,MeshBasicMaterial:zi,MeshLambertMaterial:Vi,MeshPhongMaterial:Oi,MeshPhysicalMaterial:Bi,PointsMaterial:qe,LineBasicMaterial:me,LineDashedMaterial:xr,ShaderMaterial:We,RawShaderMaterial:cr,Object3D:Ct,Group:$i,Mesh:Et,InstancedMesh:Fe,Line:$t,LineLoop:Tr,LineSegments:Sr,Points:Rr,Light:Xt,AmbientLight:ke,DirectionalLight:Hi,PointLight:Ue,SpotLight:Cr,HemisphereLight:Ke,RectAreaLight:Ar,Camera:ze,PerspectiveCamera:ji,Scene:Ve,WebGLRenderer:Xi,Clock:Ki,SceneQuotaValidator:Nt,exportSceneToCanvas3D:Oe,exportSceneToGLB:Be,exportSceneToUSDZ:Wi,generateUSDZ:yi,glbToUSDZ:Pe,sceneToCanvas3D:Ht,sceneToGLB:ie,sceneToUSDZ:ne,authorScriptRunner:lr,getAuthorWarnings:hr,clearAuthorWarnings:ur};Object.freeze(Nt),Object.freeze(Nt.prototype),Object.freeze(Ve.prototype),Object.freeze(Pr);var zt=new Proxy(Pr,{get:(e,t)=>{if(t in e)return e[t];let i=ut().authorNamespace;return i&&typeof t=="string"&&t in i?i[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&kt(`THREE.${t}`,"no-op proxy"),qt)},has:(e,t)=>{if(t in e)return!0;let i=ut().authorNamespace;return!!(i&&typeof t=="string"&&t in i)},set:(e,t)=>{throw new TypeError(`Cannot assign to read only property '${String(t)}' of #<THREE>`)},defineProperty:(e,t)=>{throw new TypeError(`Cannot define property '${String(t)}', object is not extensible`)},deleteProperty:(e,t)=>{throw new TypeError(`Cannot delete property '${String(t)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),fe=ut();if(fe.threeNamespace=zt,fe.workerExtensionInstallers)for(let e of fe.workerExtensionInstallers)e(zt,fe);var Yt={name:"three_author",THREE:zt},_s=Yt,At=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof At.THREE>"u"&&(At.THREE=zt),typeof At.requestAnimationFrame!="function"&&(At.requestAnimationFrame=e=>(typeof e=="function"&&typeof At.__three_live_raf_cb__!="function"&&(At.__three_live_raf_cb__=e),At.__three_live_in_step__||kt("requestAnimationFrame","single-frame static evaluation"),0)),typeof At.cancelAnimationFrame!="function"&&(At.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=zt,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=Yt,e.ThreeLivePlugins.three_author=Yt,e.ThreeLivePlugins["three-author"]=Yt}var Es=zt;export{ke as AmbientLight,Ne as BoxGeometry,gt as BufferAttribute,ft as BufferGeometry,ze as Camera,yr as CapsuleGeometry,Ii as CatmullRomCurve3,br as CircleGeometry,Ki as Clock,Rt as Color,Ai as ConeGeometry,Li as CubicBezierCurve3,Ft as Curve3,De as CylinderGeometry,ki as DataTexture,Hi as DirectionalLight,gr as DodecahedronGeometry,wr as EdgesGeometry,_e as Euler,wi as Float32BufferAttribute,$i as Group,Ke as HemisphereLight,dr as IcosahedronGeometry,Fe as InstancedMesh,Le as LatheGeometry,Xt as Light,$t as Line,me as LineBasicMaterial,Ni as LineCurve3,xr as LineDashedMaterial,Tr as LineLoop,Sr as LineSegments,Wt as MAX_INSTANCES_PER_MESH,Mt as Material,Mi as MathUtils,xi as Matrix3,Ot as Matrix4,Et as Mesh,zi as MeshBasicMaterial,Vi as MeshLambertMaterial,Oi as MeshPhongMaterial,Bi as MeshPhysicalMaterial,jt as MeshStandardMaterial,Ct as Object3D,pr as OctahedronGeometry,ji as PerspectiveCamera,Ri as PlaneGeometry,Ue as PointLight,Rr as Points,qe as PointsMaterial,Cs as PolyhedronFallbackGeometry,Ut as PolyhedronGeometry,Di as QuadraticBezierCurve3,Ee as Quaternion,cr as RawShaderMaterial,Ar as RectAreaLight,Xe as RingGeometry,Ve as Scene,Nt as SceneQuotaValidator,We as ShaderMaterial,Ci as SphereGeometry,Cr as SpotLight,zt as THREE,mr as TetrahedronGeometry,le as Texture,Ui as TextureLoader,Pi as TorusGeometry,Ei as TorusKnotGeometry,Fi as TubeGeometry,Ti as Uint16BufferAttribute,Si as Uint32BufferAttribute,Tt as Vector2,Y as Vector3,bi as Vector4,Xi as WebGLRenderer,Mr as WireframeGeometry,lr as authorScriptRunner,He as buildSandboxWorkerSource,ur as clearAuthorWarnings,Es as default,Oe as exportSceneToCanvas3D,Be as exportSceneToGLB,Wi as exportSceneToUSDZ,yi as generateUSDZ,tr as getAllowClientScripts,hr as getAuthorWarnings,$e as getSandboxEngineSrc,Qi as getSandboxIframeSrc,Pe as glbToUSDZ,Bt as isAllowedSandboxEngineUrl,qt as noopProxy,Ht as sceneToCanvas3D,ie as sceneToGLB,ne as sceneToUSDZ,ys as setAllowClientScripts,fs as setSandboxEngineSrc,ds as setSandboxIframeSrc,Yt as threeAuthorPlugin,_s as threeMicroPlugin,Ji as toTrustedWorkerScriptURL,je as validateSandboxWorkerMessage,kt as warnUnsupported};
|
|
378
|
+
})();`);g=null;let P=I(w,v,S,D);P&&typeof P.toGLB=="function"&&(v=P)}if(!T){w.SceneQuotaValidator&&w.SceneQuotaValidator.validate(v);let I=v.toGLB(),P=I instanceof ArrayBuffer?I:I.buffer.slice(I.byteOffset,I.byteOffset+I.byteLength);x({type:"3D_MODEL_READY",glbBuffer:P},[P])}l({type:"DONE",nonce:r})}catch(v){h(v&&v.message||v)}}},l({type:"READY",nonce:r})}function Ge(e,t,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,n={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:s,revoked:bs},a=(mt().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${xs.toString()})(${JSON.stringify(n)},[${a}]);`}function tr(e){e.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),e.onToast?.("Security Error: script timed out and was stopped.")}var Ft=0;function er(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function vs(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var Ms=1024,ws=256;function ir(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let i=e[t];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function He(e,t){if(!e||typeof e!="object")return null;let i=e;if(i.nonce!==t)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Ms)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!ir(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let s=Object.keys(r);if(s.length>1e3)return null;let n=Object.create(null),a=r;for(let o of s){if(o.length>ws||o==="__proto__"||o==="constructor"||o==="prototype")return null;let l=a[o];if(!ir(l))return null;n[o]=l}return{type:"3D_UPDATE_TRANSFORMS",transforms:n}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function Ts(e){let t=vs(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function rr(e,t,i,r){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":i();return;case"ERROR":i(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Ss(e,t,i,r){let s=er(),n=Ge(t,s,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a=document.createElement("iframe");a.setAttribute("sandbox","allow-scripts"),a.setAttribute("aria-hidden","true"),a.tabIndex=-1,a.style.display="none",a.src=i,Ft++;let o=!1,l=!1,h={modelDispatched:!1},u,f=()=>{if(o||l)return;let b=a.contentWindow;!b||typeof b.postMessage!="function"||(l=!0,b.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:n,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:s,workerSource:n,script:e.script},"*"))},g=()=>{},w=b=>{if(o||!a.contentWindow||b.source!==a.contentWindow)return;let T=b.data;if(T&&typeof T=="object"&&T.type==="IFRAME_READY"){f();return}let x=He(T,s);x&&rr(x,r,g,h)};g=()=>{o||(o=!0,u!==void 0&&clearTimeout(u),Ft=Math.max(0,Ft-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",w),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},u=setTimeout(()=>{o||(g(),tr(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",w),a.onload=()=>{f()},a.onerror=()=>{g(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let p=document.body||document.documentElement;if(!p||typeof p.appendChild!="function"){g();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(b),b}return p.appendChild(a),{terminate:g}}function sr(e,t,i,r){if(t==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(t==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Ft>=32)return r(`SecurityError: ${Ft} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let s;try{s=ps()}catch(g){let w=g instanceof Error?g.message:String(g);return r(w,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let g;try{g=ds()}catch(w){let p=w instanceof Error?w.message:String(w);return r(p,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Ss(e,s,g,i))}catch(w){return Promise.reject(w)}}let n=er(),a=Ge(s,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let g=new Blob([a],{type:"application/javascript"}),w=URL.createObjectURL(g);try{let p=Zi(w);o=new Worker(p)}finally{URL.revokeObjectURL(w)}}catch(g){let w=g instanceof Error?g.message:String(g);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${w}`,"Security Error: Failed to start Worker sandbox.")}Ft++;let l=!1,h={modelDispatched:!1},u,f=()=>{l||(l=!0,u!==void 0&&clearTimeout(u),Ft=Math.max(0,Ft-1),o.terminate())};return u=setTimeout(()=>{l||(f(),tr(i))},3e3),o.onmessage=g=>{let w=He(g.data,n);w&&rr(w,i,f,h)},o.onerror=g=>{f(),i.onError?.(new Error(`Worker execution error: ${g.message}`))},e.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:n}):o.postMessage({type:"EXECUTE",script:e.script,nonce:n}),Promise.resolve({terminate:f})}function nr(e,t){return e==="none"||e==="unsafe-host-realm"?t(`SecurityError: sandbox="${e}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${e}" is not permitted.`):e!=="worker"&&e!=="iframe"?t(`SecurityError: Unsupported sandbox mode "${e}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var ar=e=>(t,i)=>{let r=new Error(t);return e.onError?.(r),i&&e.onToast?.(i),Promise.reject(r)},or={execute(e,t,i,r){let s=ar(i),n=nr(t,s);if(n)return n;try{Ts(e)}catch(a){let o=a instanceof Error?a.message:String(a);return s(o,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Qi()?sr({kind:"script",script:e},t,i,s):s($r,Or)},executeUrl(e,t,i){let r=ar(i),s=nr(t,r);if(s)return s;let n;try{n=ys(e)}catch(a){let o=a instanceof Error?a.message:String(a);return r(o,"Security Error: disallowed scene script URL.")}return sr({kind:"url",scriptUrl:n},t,i,r)}},pe=new Set;function kt(e,t){let i=`[three-live] ${e} is unsupported; degraded to ${t}.`;pe.has(i)||(pe.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function lr(){return Array.from(pe)}function hr(){pe.clear()}var je=class extends Xt{constructor(e={}){kt("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},i=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:i!==void 0?i:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},ur=je,$t=class extends ft{constructor(e=[],t=[],i=1,r=0){super();let s=Number(i)||1,n=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),a=n+1,o=[],l=[],h=[],u=[],f=new Q,g=new Q,w=new Q,p=(x,M)=>M.set(e[x*3]||0,e[x*3+1]||0,e[x*3+2]||0),b=(x,M)=>{let c=x.clone().normalize();o.push(c.x*s,c.y*s,c.z*s),l.push(M.x,M.y,M.z),h.push(Math.atan2(c.z,-c.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,c.y)))/Math.PI)},T=(x,M,c)=>{let m=o.length/3,v=n===0?new Q().subVectors(c,M).cross(new Q().subVectors(x,M)).normalize():null;b(x,v||x.clone().normalize()),b(M,v||M.clone().normalize()),b(c,v||c.clone().normalize()),u.push(m,m+1,m+2)};for(let x=0;x<t.length;x+=3){p(t[x],f),p(t[x+1],g),p(t[x+2],w);let M=[];for(let c=0;c<=a;c++){M[c]=[];let m=f.clone().lerp(w,c/a),v=g.clone().lerp(w,c/a),S=a-c;for(let D=0;D<=S;D++)M[c][D]=S===0?m.clone():m.clone().lerp(v,D/S)}for(let c=0;c<a;c++)for(let m=0;m<2*(a-c)-1;m++){let v=m>>1;(m&1)===0?T(M[c][v+1],M[c+1][v],M[c][v]):T(M[c][v+1],M[c+1][v+1],M[c+1][v])}}this.setFromBuffers(o,l,h,u)}},As=$t,cr=class extends $t{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},fe=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],mr=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],pr=class extends $t{constructor(e=1,t=0){super(fe,mr,e,t)}},ht=(1+Math.sqrt(5))/2,fr=class extends $t{constructor(e=1,t=0){super([-1,ht,0,1,ht,0,-1,-ht,0,1,-ht,0,0,-1,ht,0,1,ht,0,-1,-ht,0,1,-ht,ht,0,-1,ht,0,1,-ht,0,-1,-ht,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},wt=1/ht,dr=class extends $t{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-wt,-ht,0,-wt,ht,0,wt,-ht,0,wt,ht,-wt,-ht,0,-wt,ht,0,wt,-ht,0,wt,ht,0,-ht,0,-wt,ht,0,-wt,-ht,0,wt,ht,0,wt],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},gr=class extends De{constructor(e=1,t=1,i=4,r=8){let s=Math.max(1e-4,Number(e)||1),n=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,a=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),o=[];for(let l=-1;l<=1;l+=2)for(let h=0;h<=a;h++){if(l>0&&h===0&&n===0)continue;let u=(l<0?h/a-1:h/a)*(Math.PI/2);o.push(new At(Math.max(0,Math.cos(u)*s),l*n+Math.sin(u)*s))}super(o,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},We=class extends ft{constructor(e=.5,t=1,i=32,r=1,s=0,n=Math.PI*2){super();let a=Math.max(1e-4,Number(t)||1),o=Number(e),l=Number.isFinite(o)?Math.max(0,o):a*.5,h=Math.max(a,l),u=Math.min(h*.999,Math.min(a,l)),f=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),g=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),w=Number.isFinite(Number(s))?Number(s):0,p=Number.isFinite(Number(n))?Number(n):Math.PI*2,b=[],T=[],x=[],M=[];for(let c=0;c<=g;c++){let m=u+c/g*(h-u);for(let v=0;v<=f;v++){let S=w+v/f*p,D=Math.cos(S),I=Math.sin(S);if(b.push(m*D,m*I,0),T.push(0,0,1),x.push(m/h*D*.5+.5,m/h*I*.5+.5),c<g&&v<f){let P=c*(f+1)+v,N=P+f+1;m>1e-6&&M.push(P,N,P+1),M.push(N,N+1,P+1)}}}this.setFromBuffers(b,T,x,M)}},yr=class extends We{constructor(e=1,t=32,i=0,r=Math.PI*2){super(0,e,t,1,i,r)}},Xe=class extends Tt{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},de=class extends Tt{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},br=class extends de{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function xr(e,t){let i=e?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,s=e?.index?.array,n=Math.min(8192,Math.floor((s?s.length:i.count)/3)),a=g=>`${Math.round((r[g*3]||0)*1e4)},${Math.round((r[g*3+1]||0)*1e4)},${Math.round((r[g*3+2]||0)*1e4)}`,o=t===void 0,l=o?1:Math.cos(t*Math.PI/180),h={},u=[],f=(g,w)=>u.push(r[g*3]||0,r[g*3+1]||0,r[g*3+2]||0,r[w*3]||0,r[w*3+1]||0,r[w*3+2]||0);for(let g=0;g<n;g++){let w=s?s[g*3]:g*3,p=s?s[g*3+1]:g*3+1,b=s?s[g*3+2]:g*3+2,T=r[w*3]||0,x=r[w*3+1]||0,M=r[w*3+2]||0,c=(r[p*3]||0)-T,m=(r[p*3+1]||0)-x,v=(r[p*3+2]||0)-M,S=(r[b*3]||0)-T,D=(r[b*3+1]||0)-x,I=(r[b*3+2]||0)-M,P=m*I-v*D,N=v*S-c*I,C=c*D-m*S,L=Math.hypot(P,N,C);if(!o&&L<1e-8)continue;L>0&&(P/=L,N/=L,C/=L);let E=[w,p,b];for(let y=0;y<3;y++){let F=E[y],z=E[(y+1)%3],A=a(F),_=a(z);if(A===_)continue;let d=A<_?`${A}|${_}`:`${_}|${A}`,R=h[d];R?R.m||(R.m=1,R.nx*P+R.ny*N+R.nz*C<=l&&f(F,z)):(h[d]={va:F,vb:z,nx:P,ny:N,nz:C,m:o?1:0},o&&f(F,z))}}if(!o){let g=Object.keys(h);for(let w=0;w<g.length;w++){let p=h[g[w]];p&&!p.m&&f(p.va,p.vb)}}return new Float32Array(u)}var vr=class extends ft{constructor(e){super(),this.setAttribute("position",new bt(xr(e),3)),this.__isSegmentPairs=!0}},Mr=class extends ft{constructor(e,t=1){super();let i=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new bt(xr(e,i),3)),this.__isSegmentPairs=!0}};function Rs(e,t,i=1){let r=new ft;r.__baked=!0;let s=e?.attributes?.position;if(!s?.array||s.count<2)return r;let n=s.array,a=e.index?.array,o=e.__isSegmentPairs?"segments":t,l=a?a.length:s.count,h=Math.min(4096,Math.max(0,o==="segments"?Math.floor(l/2):o==="loop"&&l>=3?l:l-1));if(h===0)return r;e.computeBoundingBox();let u=e.boundingBox,f=u&&u.max.distanceTo(u.min)||1,g=Math.max(.0015,Math.min(.025,f*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),w=[],p=[],b=[],T=[];for(let x=0;x<h;x++){let M=o==="segments"?x*2:x,c=o==="segments"?x*2+1:(x+1)%l,m=a?a[M]:M,v=a?a[c]:c,S=n[m*3]||0,D=n[m*3+1]||0,I=n[m*3+2]||0,P=(n[v*3]||0)-S,N=(n[v*3+1]||0)-D,C=(n[v*3+2]||0)-I,L=Math.hypot(P,N,C);if(L<1e-6)continue;let E=P/L,y=N/L,F=C/L,z=(Math.abs(y)<.9?Math.hypot(F,E):Math.hypot(F,y))||1,A=Math.abs(y)<.9?F/z:0,_=Math.abs(y)<.9?0:-F/z,d=Math.abs(y)<.9?-E/z:y/z,R=y*d-F*_,G=F*A-E*d,H=E*_-y*A,B=w.length/3,Z=[[A,_,d],[R,G,H],[-A,-_,-d],[-R,-G,-H]];for(let k=0;k<2;k++){let Y=S+k*P,rt=D+k*N,st=I+k*C;for(let $=0;$<4;$++){let J=Z[$];w.push(Y+J[0]*g,rt+J[1]*g,st+J[2]*g),p.push(J[0],J[1],J[2]),b.push($/4,k)}}for(let k=0;k<4;k++){let Y=(k+1)%4;T.push(B+k,B+Y,B+4+Y,B+k,B+4+Y,B+4+k)}}return w.length>0&&r.setFromBuffers(w,p,b,T),r}function _s(e,t=.05){let i=new ft;i.__baked=!0;let r=e?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,n=r.count,a=Math.min(n,5e3),o=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),l=[],h=[],u=[],f=[];for(let g=0;g<a;g++){let w=n<=5e3?g:Math.floor(g*n/a),p=s[w*3]||0,b=s[w*3+1]||0,T=s[w*3+2]||0,x=g*6;for(let M=0;M<6;M++){let c=fe[M*3],m=fe[M*3+1],v=fe[M*3+2];l.push(p+c*o,b+m*o,T+v*o),h.push(c,m,v),u.push(.5,.5)}for(let M=0;M<24;M++)f.push(x+mr[M])}return i.setFromBuffers(l,h,u,f),i}var Ht=class extends Lt{constructor(e,t,i="strip"){let r=t&&typeof t=="object"?t:{},s=t instanceof Tt?t:i==="points"?new Xe(r):new de(r),n=e instanceof ft?e:new ft;super(n,s),this.isLine=!0,this._lineMode=i,this._sourceGeo=n}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=t.array,r=Math.min(t.count,64),s=0,n=0,a=0;for(let o=0;o<r;o++)s+=i[o*3]||0,n+=i[o*3+1]||0,a+=i[o*3+2]||0;this.material.color.setRGB(s/r,n/r,a/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?_s(this._sourceGeo,this.material?.size??.05):Rs(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},wr=class extends Ht{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},Tr=class extends Ht{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},Sr=class extends Ht{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},Ar=class extends Ue{constructor(e,t,i=0,r=Math.PI/3,s=0,n=2){super(e,t,i,n),this.target=new Pt,this.type="spot";let a=Number(r);this.angle=Number.isFinite(a)?Math.max(.01,Math.min(Math.PI/2,a)):Math.PI/3;let o=Number(s);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},qe=class extends Fe{constructor(e,t,i){kt("HemisphereLight","AmbientLight"),super(e,i),this.groundColor=new Ct(t??4473924)}},Rr=qe,_r={Vector2:At,Vector3:Q,Vector4:yi,Euler:Pe,Quaternion:le,Matrix4:Vt,Matrix3:bi,Color:Ct,MathUtils:vi,BufferAttribute:bt,Float32BufferAttribute:Mi,Uint16BufferAttribute:wi,Uint32BufferAttribute:Ti,BufferGeometry:ft,BoxGeometry:Ne,PlaneGeometry:Si,SphereGeometry:Ai,CylinderGeometry:Ee,ConeGeometry:Ri,TorusGeometry:_i,TorusKnotGeometry:Pi,Curve:Ut,Curve3:Ut,LineCurve3:Ni,QuadraticBezierCurve3:Ei,CubicBezierCurve3:Di,CatmullRomCurve3:Li,LatheGeometry:De,TubeGeometry:Ii,PolyhedronGeometry:$t,IcosahedronGeometry:fr,OctahedronGeometry:pr,DodecahedronGeometry:dr,TetrahedronGeometry:cr,CapsuleGeometry:gr,RingGeometry:We,CircleGeometry:yr,WireframeGeometry:vr,EdgesGeometry:Mr,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:ce,DataTexture:Fi,TextureLoader:Ui,Material:Tt,MeshStandardMaterial:Xt,MeshBasicMaterial:ki,MeshLambertMaterial:$i,MeshPhongMaterial:Oi,MeshPhysicalMaterial:Bi,PointsMaterial:Xe,LineBasicMaterial:de,LineDashedMaterial:br,ShaderMaterial:je,RawShaderMaterial:ur,Object3D:Pt,Group:zi,Mesh:Lt,InstancedMesh:Ie,Line:Ht,LineLoop:wr,LineSegments:Tr,Points:Sr,Light:Kt,AmbientLight:Fe,DirectionalLight:Gi,PointLight:Ue,SpotLight:Ar,HemisphereLight:qe,RectAreaLight:Rr,Camera:ke,PerspectiveCamera:Hi,Scene:$e,WebGLRenderer:Wi,Clock:qi,SceneQuotaValidator:It,exportSceneToCanvas3D:Oe,exportSceneToGLB:Be,exportSceneToUSDZ:ji,generateUSDZ:gi,glbToUSDZ:Ce,sceneToCanvas3D:Wt,sceneToGLB:ie,sceneToUSDZ:oe,authorScriptRunner:or,getAuthorWarnings:lr,clearAuthorWarnings:hr};Object.freeze(It),Object.freeze(It.prototype),Object.freeze($e.prototype),Object.freeze(_r);var Ot=new Proxy(_r,{get:(e,t)=>{if(t in e)return e[t];let i=mt().authorNamespace;return i&&typeof t=="string"&&t in i?i[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&kt(`THREE.${t}`,"no-op proxy"),Yt)},has:(e,t)=>{if(t in e)return!0;let i=mt().authorNamespace;return!!(i&&typeof t=="string"&&t in i)},set:(e,t)=>{throw new TypeError(`Cannot assign to read only property '${String(t)}' of #<THREE>`)},defineProperty:(e,t)=>{throw new TypeError(`Cannot define property '${String(t)}', object is not extensible`)},deleteProperty:(e,t)=>{throw new TypeError(`Cannot delete property '${String(t)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),ge=mt();if(ge.threeNamespace=Ot,ge.workerExtensionInstallers)for(let e of ge.workerExtensionInstallers)e(Ot,ge);var Jt={name:"three_author",THREE:Ot},Cs=Jt,Nt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof Nt.THREE>"u"&&(Nt.THREE=Ot),typeof Nt.requestAnimationFrame!="function"&&(Nt.requestAnimationFrame=e=>(typeof e=="function"&&typeof Nt.__three_live_raf_cb__!="function"&&(Nt.__three_live_raf_cb__=e),Nt.__three_live_in_step__||kt("requestAnimationFrame","single-frame static evaluation"),0)),typeof Nt.cancelAnimationFrame!="function"&&(Nt.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=Ot,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=Jt,e.ThreeLivePlugins.three_author=Jt,e.ThreeLivePlugins["three-author"]=Jt}var Ps=Ot;export{Fe as AmbientLight,Ne as BoxGeometry,bt as BufferAttribute,ft as BufferGeometry,ke as Camera,gr as CapsuleGeometry,Li as CatmullRomCurve3,yr as CircleGeometry,qi as Clock,Ct as Color,Ri as ConeGeometry,Di as CubicBezierCurve3,Ut as Curve3,Ee as CylinderGeometry,Fi as DataTexture,Gi as DirectionalLight,dr as DodecahedronGeometry,Mr as EdgesGeometry,Pe as Euler,Mi as Float32BufferAttribute,zi as Group,qe as HemisphereLight,fr as IcosahedronGeometry,Ie as InstancedMesh,De as LatheGeometry,Kt as Light,Ht as Line,de as LineBasicMaterial,Ni as LineCurve3,br as LineDashedMaterial,wr as LineLoop,Tr as LineSegments,qt as MAX_INSTANCES_PER_MESH,Tt as Material,vi as MathUtils,bi as Matrix3,Vt as Matrix4,Lt as Mesh,ki as MeshBasicMaterial,$i as MeshLambertMaterial,Oi as MeshPhongMaterial,Bi as MeshPhysicalMaterial,Xt as MeshStandardMaterial,Pt as Object3D,pr as OctahedronGeometry,Hi as PerspectiveCamera,Si as PlaneGeometry,Ue as PointLight,Sr as Points,Xe as PointsMaterial,As as PolyhedronFallbackGeometry,$t as PolyhedronGeometry,Ei as QuadraticBezierCurve3,le as Quaternion,ur as RawShaderMaterial,Rr as RectAreaLight,We as RingGeometry,$e as Scene,It as SceneQuotaValidator,je as ShaderMaterial,Ai as SphereGeometry,Ar as SpotLight,Ot as THREE,cr as TetrahedronGeometry,ce as Texture,Ui as TextureLoader,_i as TorusGeometry,Pi as TorusKnotGeometry,Ii as TubeGeometry,wi as Uint16BufferAttribute,Ti as Uint32BufferAttribute,At as Vector2,Q as Vector3,yi as Vector4,Wi as WebGLRenderer,vr as WireframeGeometry,or as authorScriptRunner,Ge as buildSandboxWorkerSource,hr as clearAuthorWarnings,Ps as default,Oe as exportSceneToCanvas3D,Be as exportSceneToGLB,ji as exportSceneToUSDZ,gi as generateUSDZ,Qi as getAllowClientScripts,lr as getAuthorWarnings,ze as getSandboxEngineSrc,Ji as getSandboxIframeSrc,Ce as glbToUSDZ,Gt as isAllowedSandboxEngineUrl,Yt as noopProxy,Wt as sceneToCanvas3D,ie as sceneToGLB,oe as sceneToUSDZ,gs as setAllowClientScripts,ms as setSandboxEngineSrc,fs as setSandboxIframeSrc,Jt as threeAuthorPlugin,Cs as threeMicroPlugin,Zi as toTrustedWorkerScriptURL,He as validateSandboxWorkerMessage,kt as warnUnsupported};
|