three-live 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/index.d.ts +190 -0
- package/dist/three-author-engine.js +171 -163
- package/dist/three-author.cjs +145 -163
- package/dist/three-author.d.ts +190 -0
- package/dist/three-author.js +145 -163
- package/dist/three-convert.cjs +142 -160
- package/dist/three-convert.d.ts +190 -0
- package/dist/three-convert.js +142 -160
- package/dist/three-live-ai.cjs +41 -0
- package/dist/three-live-ai.d.ts +759 -0
- package/dist/three-live-ai.js +41 -0
- package/dist/three-live-ai.min.js +41 -0
- package/dist/three-live-animation.cjs +6 -6
- package/dist/three-live-animation.d.ts +190 -0
- package/dist/three-live-animation.js +5 -5
- package/dist/three-live-animation.min.js +5 -5
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +190 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +50 -85
- package/dist/three-live-element.d.ts +190 -0
- package/dist/three-live-element.js +50 -85
- package/dist/three-live-full.cjs +907 -189
- package/dist/three-live-full.js +907 -189
- package/dist/three-live-full.min.js +907 -189
- package/dist/three-live-procedural.cjs +16 -0
- package/dist/three-live-procedural.d.ts +759 -0
- package/dist/three-live-procedural.js +16 -0
- package/dist/three-live-procedural.min.js +16 -0
- package/dist/three-live-sandbox.html +11 -1
- package/dist/three-live-studio.cjs +72 -17
- package/dist/three-live-studio.d.ts +190 -0
- package/dist/three-live-studio.js +72 -17
- package/dist/three-live-studio.min.js +73 -18
- package/dist/three-live-tsl.cjs +103 -0
- package/dist/three-live-tsl.d.ts +759 -0
- package/dist/three-live-tsl.js +103 -0
- package/dist/three-live-tsl.min.js +103 -0
- package/dist/three-live-viewer.cjs +50 -85
- package/dist/three-live-viewer.d.ts +190 -0
- package/dist/three-live-viewer.js +50 -85
- package/dist/three-live-viewer.min.js +50 -85
- package/dist/three-live-webgpu.cjs +585 -0
- package/dist/three-live-webgpu.d.ts +759 -0
- package/dist/three-live-webgpu.js +585 -0
- package/dist/three-live-webgpu.min.js +585 -0
- package/dist/three-live.cjs +147 -165
- package/dist/three-live.js +147 -165
- package/dist/three-live.min.js +147 -165
- package/dist/three-view.cjs +49 -84
- package/dist/three-view.d.ts +190 -0
- package/dist/three-view.js +50 -85
- package/dist/three-xr.cjs +141 -159
- package/dist/three-xr.d.ts +190 -0
- package/dist/three-xr.js +140 -158
- package/package.json +21 -1
package/dist/three-author.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 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
|
|
16
|
+
*/function is(t,e,i){let r=[],n=new Map,s=[],a=[],o=[],l=new Map,y=p=>{let x=n.get(p);return x===void 0&&(x=r.length,r.push({op:p}),n.set(p,x)),x},f=p=>{let x=l.get(p);return x===void 0&&(x=o.length,o.push({id:p}),l.set(p,x)),x},b=(p,x={})=>s.push({declaration:y(p),...x})-1,h=(p,x,w)=>a.push({id:p,type:x,value:w})-1,d=p=>({node:p,socket:"value"}),v=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(v&&typeof v=="object"){let p=Array.isArray(v.graphs)?v.graphs[v.graph??0]:v;if(p&&Array.isArray(p.nodes)){let x=Array.isArray(p.declarations)?p.declarations:[];for(let w of x)w?.op&&y(w.op);Array.isArray(p.variables)&&a.push(...p.variables);for(let w of p.events||[])w?.id&&f(w.id);for(let w of p.nodes){if(!w||typeof w!="object")continue;let _=w.op||(typeof w.declaration=="number"?x[w.declaration]?.op:"");s.push(_?{...w,declaration:y(_)}:{...w})}}}let M=(p,x,w="translation")=>w==="baseColorFactor"||w==="metallicFactor"||w==="roughnessFactor"?`/materials/${Math.max(0,x)}/pbrMetallicRoughness/${w}`:w==="emissiveFactor"||w==="alphaCutoff"?`/materials/${Math.max(0,x)}/${w}`:w==="visible"?`/nodes/${p}/extensions/KHR_node_visibility/visible`:`/nodes/${p}/${w}`,m=new Map;t.forEach((p,x)=>{typeof p?.name=="string"&&!m.has(p.name)&&m.set(p.name,x)});let u=(p,x)=>typeof p.target=="string"&&m.has(p.target)?m.get(p.target):typeof p.targetNode=="number"?p.targetNode:x,g=p=>{let x=t[p];return(typeof x?.mesh=="number"?e[x.mesh]?.primitives?.[0]?.material:0)??0};for(let p=0;p<t.length;p++){let x=t[p],w=x?.extras?.interactivity;if(!w||typeof w!="object")continue;let _=(typeof x.mesh=="number"?e[x.mesh]?.primitives?.[0]?.material:0)??0,N=E=>{let T=Array.isArray(E)?E:[E],S=[];for(let D=0;D<T.length;D++){let R=T[D];if(!R||typeof R!="object")continue;let I=R.action||"interpolate",k=typeof R.duration=="number"?R.duration:.35;if(I==="toggleTransform"){let V=R.property==="rotation"||R.property==="scale"?R.property:"translation",L=V==="rotation"?x.rotation||[0,0,0,1]:V==="scale"?x.scale||[1,1,1]:x.translation||[0,0,0],O=`/nodes/${p}/${V}`,c=h(`__toggle_${p}_${D}`,"bool",!1),F=b("variable/get",{configuration:{variable:c}}),C=b("math/not",{values:{a:d(F)}}),U=b("variable/set",{configuration:{variable:c},values:{value:d(C)}}),H=b("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Array.isArray(R.to)?R.to:L},duration:{value:k}}}),j=b("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Array.isArray(R.from)?R.from:L},duration:{value:k}}});s[U].flows={out:{node:b("flow/branch",{values:{condition:d(F)},flows:{true:{node:H},false:{node:j}}})}},S.push(U)}else if(I==="interpolate"){let V=R.to??R.value;if(V===void 0)continue;let L={value:{value:V},duration:{value:k}};R.from!==void 0&&(L.from={value:R.from}),S.push(b("pointer/interpolate",{configuration:{pointer:typeof R.pointer=="string"?R.pointer:M(u(R,p),g(u(R,p)),R.property)},values:L}))}else if(I==="setProperty"){if(R.value===void 0)continue;S.push(b("pointer/set",{configuration:{pointer:typeof R.pointer=="string"?R.pointer:M(u(R,p),g(u(R,p)),R.property)},values:{value:{value:R.value}}}))}else if(I==="toggleVisibility"){let V=u(R,p),L=h(`__vis_${V}_${D}`,"bool",!0),O=b("variable/get",{configuration:{variable:L}}),c=b("math/not",{values:{a:d(O)}}),F=b("variable/set",{configuration:{variable:L},values:{value:d(c)}});s[F].flows={out:{node:b("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:d(O)}})}},S.push(F)}else if(I==="cycleMaterialColor"&&Array.isArray(R.colors)&&R.colors.length>0){let V=typeof R.duration=="number"?R.duration:.25,L=`/materials/${Math.max(0,_)}/pbrMetallicRoughness/baseColorFactor`,O=h(`__color_idx_${p}_${D}`,"int",0),c=b("variable/get",{configuration:{variable:O}}),F=b("math/add",{values:{a:d(c),b:{value:1}}}),C=b("math/rem",{values:{a:d(F),b:{value:R.colors.length}}}),U=b("variable/set",{configuration:{variable:O},values:{value:d(C)}}),H={};for(let j=0;j<R.colors.length;j++){let Y=R.colors[j],q=Array.isArray(Y)&&Y.length>=3?[Y[0],Y[1],Y[2],Y[3]??1]:[1,1,1,1];H[String(j)]={node:V>0?b("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:q},duration:{value:V}}}):b("pointer/set",{configuration:{pointer:L},values:{value:{value:q}}})}}s[U].flows={out:{node:b("flow/switch",{values:{selection:d(c)},flows:H})}},S.push(U)}else if(I==="playAnimation")S.push(b("animation/start",{configuration:{animation:R.animation??R.clip??0}}));else if(I==="stopAnimation")S.push(b("animation/stop"));else if(I==="sendEvent"){let V={};for(let[L,O]of Object.entries(R.values||{}))V[L]={value:O};S.push(b("event/send",{configuration:{event:f(String(R.event??R.id??"custom"))},values:V}))}}if(!S.length)return null;if(S.length===1)return S[0];let A={};return S.forEach((D,R)=>{A[String(R)]={node:D}}),b("flow/sequence",{flows:A})},P=(E,T,S)=>{let A=N(T);A!==null&&b(E,{...S?{configuration:S}:{},flows:{out:{node:A}}})};if(w.onSelect&&P("pointer/onSelect",w.onSelect,{nodeIndex:p}),w.onHoverIn&&P("pointer/onHoverIn",w.onHoverIn,{nodeIndex:p}),w.onHoverOut&&P("pointer/onHoverOut",w.onHoverOut,{nodeIndex:p}),w.onStart&&P("event/onStart",w.onStart),w.onReceive&&typeof w.onReceive=="object")for(let[E,T]of Object.entries(w.onReceive))P("event/receive",T,{event:f(E)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:a,events:o}],graph:0}:null}var rs='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).',ss="Security Error: client-side scripts require allow-client-scripts opt-in.",lt="__THREE_LIVE_REGISTRY__";function ge(){let t=typeof globalThis<"u"?globalThis:{};if(!t[lt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,lt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[lt]=e}}return t[lt]}var xe=ge().plugins;function ns(t){let e=ge().plugins;e.some(i=>i.name===t.name)||e.push(t),t.onRegister?.()}function as(){return ge().plugins}function ve(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function mi(t,e,i,r,n){let s=1/Math.tan(e/2);t.fill(0),t[0]=s/i,t[5]=s,t[11]=-1;let a=1/(r-n);return t[10]=(n+r)*a,t[14]=2*n*r*a,t}function Lt(t,e,i,r){let[n,s,a]=e,[o,l,y]=r,[f,b,h]=i,d=n-f,v=s-b,M=a-h,m=Math.hypot(d,v,M);m<=1e-5?(d=0,v=0,M=1):(d/=m,v/=m,M/=m);let u=l*M-y*v,g=y*d-o*M,p=o*v-l*d;m=Math.hypot(u,g,p),m<=1e-5?(u=0,g=0,p=0):(u/=m,g/=m,p/=m);let x=v*p-M*g,w=M*u-d*p,_=d*g-v*u;return m=Math.hypot(x,w,_),m<=1e-5?(x=0,w=0,_=0):(x/=m,w/=m,_/=m),t[0]=u,t[1]=x,t[2]=d,t[3]=0,t[4]=g,t[5]=w,t[6]=v,t[7]=0,t[8]=p,t[9]=_,t[10]=M,t[11]=0,t[12]=-(u*n+g*s+p*a),t[13]=-(x*n+w*s+_*a),t[14]=-(d*n+v*s+M*a),t[15]=1,t}function Te(t,e,i){let r=e[0],n=e[1],s=e[2],a=e[3],o=e[4],l=e[5],y=e[6],f=e[7],b=e[8],h=e[9],d=e[10],v=e[11],M=e[12],m=e[13],u=e[14],g=e[15],p=i[0],x=i[1],w=i[2],_=i[3];return t[0]=p*r+x*o+w*b+_*M,t[1]=p*n+x*l+w*h+_*m,t[2]=p*s+x*y+w*d+_*u,t[3]=p*a+x*f+w*v+_*g,p=i[4],x=i[5],w=i[6],_=i[7],t[4]=p*r+x*o+w*b+_*M,t[5]=p*n+x*l+w*h+_*m,t[6]=p*s+x*y+w*d+_*u,t[7]=p*a+x*f+w*v+_*g,p=i[8],x=i[9],w=i[10],_=i[11],t[8]=p*r+x*o+w*b+_*M,t[9]=p*n+x*l+w*h+_*m,t[10]=p*s+x*y+w*d+_*u,t[11]=p*a+x*f+w*v+_*g,p=i[12],x=i[13],w=i[14],_=i[15],t[12]=p*r+x*o+w*b+_*M,t[13]=p*n+x*l+w*h+_*m,t[14]=p*s+x*y+w*d+_*u,t[15]=p*a+x*f+w*v+_*g,t}function Nt(t,e,i,r){let n=e[0],s=e[1],a=e[2],o=e[3],l=n+n,y=s+s,f=a+a,b=n*l,h=n*y,d=n*f,v=s*y,M=s*f,m=a*f,u=o*l,g=o*y,p=o*f,x=r[0],w=r[1],_=r[2];return t[0]=(1-(v+m))*x,t[1]=(h+p)*x,t[2]=(d-g)*x,t[3]=0,t[4]=(h-p)*w,t[5]=(1-(b+m))*w,t[6]=(M+u)*w,t[7]=0,t[8]=(d+g)*_,t[9]=(M-u)*_,t[10]=(1-(b+v))*_,t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1,t}function Oe(t,e,i=0){let r=e[0],n=e[1],s=e[2],a=e[4],o=e[5],l=e[6],y=e[8],f=e[9],b=e[10],h=b*o-l*f,d=-b*a+l*y,v=f*a-o*y,M=r*h+n*d+s*v;return!M||i>0&&(!Number.isFinite(M)||Math.abs(M)<=i)||(M=1/M,t[0]=h*M,t[1]=d*M,t[2]=v*M,t[3]=(-b*n+s*f)*M,t[4]=(b*r-s*y)*M,t[5]=(-f*r+n*y)*M,t[6]=(l*n-s*o)*M,t[7]=(-l*r+s*a)*M,t[8]=(o*r-n*a)*M),t}function os(t,e){let i=e[0],r=e[1],n=e[2],s=e[3],a=e[4],o=e[5],l=e[6],y=e[7],f=e[8],b=e[9],h=e[10],d=e[11],v=e[12],M=e[13],m=e[14],u=e[15],g=i*o-r*a,p=i*l-n*a,x=i*y-s*a,w=r*l-n*o,_=r*y-s*o,N=n*y-s*l,P=f*M-b*v,E=f*m-h*v,T=f*u-d*v,S=b*m-h*M,A=b*u-d*M,D=h*u-d*m,R=g*D-p*A+x*S+w*T-_*E+N*P;return R?(R=1/R,t[0]=(o*D-l*A+y*S)*R,t[1]=(n*A-r*D-s*S)*R,t[2]=(M*N-m*_+u*w)*R,t[3]=(h*_-b*N-d*w)*R,t[4]=(l*T-a*D-y*E)*R,t[5]=(i*D-n*T+s*E)*R,t[6]=(m*x-v*N-u*p)*R,t[7]=(f*N-h*x+d*p)*R,t[8]=(a*A-o*T+y*P)*R,t[9]=(r*T-i*A-s*P)*R,t[10]=(v*_-M*x+u*g)*R,t[11]=(b*x-f*_-d*g)*R,t[12]=(o*E-a*S-l*P)*R,t[13]=(i*S-r*E+n*P)*R,t[14]=(M*p-v*w-m*g)*R,t[15]=(f*w-b*p+h*g)*R,t):null}function fi(t,e,i,r,n){let s=n[0]*e+n[4]*i+n[8]*r+n[12],a=n[1]*e+n[5]*i+n[9]*r+n[13],o=n[2]*e+n[6]*i+n[10]*r+n[14],l=n[3]*e+n[7]*i+n[11]*r+n[15],y=l!==0?1/l:1;t[0]=s*y,t[1]=a*y,t[2]=o*y}function ls(t,e,i,r,n,s,a,o,l,y,f,b,h,d,v,M,m=0){let u=y-a,g=f-o,p=b-l,x=h-a,w=d-o,_=v-l,N=n*_-s*w,P=s*x-r*_,E=r*w-n*x,T=u*N+g*P+p*E;if(T>-1e-7&&T<1e-7)return!1;let S=1/T,A=t-a,D=e-o,R=i-l,I=S*(A*N+D*P+R*E);if(I<-m||I>1+m)return!1;let k=D*p-R*g,V=R*u-A*p,L=A*g-D*u,O=S*(r*k+n*V+s*L);if(O<-m||I+O>1+m)return!1;let c=S*(x*k+w*V+_*L);if(c>1e-4&&c<M.distance){M.distance=c,M.point=[t+r*c,e+n*c,i+s*c];let F=g*_-p*w,C=p*x-u*_,U=u*w-g*x,H=Math.hypot(F,C,U)||1;return M.normal=[F/H,C/H,U/H],!0}return!1}function pi(t,e){let i=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let f=0;f<i;f++)r.push(ve());if(i===0)return r;let n=new Set;for(let f of t.nodes)if(Array.isArray(f.children))for(let b of f.children)n.add(b);let s=new Set,a=128,o=(f,b,h=0)=>{if(h>a||f<0||f>=i||s.has(f))return;s.add(f);let d=t.nodes[f];if(!d)return;let v=ve();if(e&&e[f])v.set(e[f]);else if(d.matrix&&d.matrix.length===16)v.set(d.matrix);else{let m=d.translation||[0,0,0],u=d.rotation||[0,0,0,1],g=d.scale||[1,1,1];Nt(v,u,m,g)}let M=r[f];if(b?Te(M,b,v):M.set(v),Array.isArray(d.children))for(let m of d.children)typeof m=="number"&&o(m,M,h+1)},l=[],y=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(y&&Array.isArray(y.nodes))l.push(...y.nodes);else for(let f=0;f<i;f++)n.has(f)||l.push(f);for(let f of l)o(f,null);for(let f=0;f<i;f++)!n.has(f)&&!l.includes(f)&&o(f,null);return r}function di(t){if(typeof t!="function")return null;let e=new Uint32Array(256);for(let h=0;h<256;h++){let d=h;for(let v=0;v<8;v++)d=d&1?3988292384^d>>>1:d>>>1;e[h]=d>>>0}let i=(h,d,v)=>{let M=4294967295;for(let m=d;m<v;m++)M=e[(M^h[m])&255]^M>>>8;return(M^4294967295)>>>0},r=(h,d)=>(h[d]<<24|h[d+1]<<16|h[d+2]<<8|h[d+3])>>>0,n=(h,d,v)=>{h[d]=v>>>24,h[d+1]=v>>>16&255,h[d+2]=v>>>8&255,h[d+3]=v&255},s=h=>{let d=new t("deflate"),v=d.writable.getWriter();v.write(h).catch(()=>{}),v.close().catch(()=>{});let M=d.readable.getReader(),m=[],u=0,g=()=>M.read().then(p=>{if(p.done){let x=new Uint8Array(u),w=0;for(let _=0;_<m.length;_++)x.set(m[_],w),w+=m[_].length;return x}return p.value&&(m.push(p.value),u+=p.value.length),g()});return g()},a=h=>{if(h.length<45||r(h,0)!==2303741511||r(h,12)!==1229472850)return null;let d=r(h,16),v=r(h,20);if(h[24]!==8||h[25]!==6||h[28]!==0||!d||!v||d>4096||v>4096)return null;let M=1+d*4,m=new Uint8Array(M*v),u=0,g=33,p=-2,x=0,w=[],_=!1;for(;g+8<=h.length&&!_;){let N=r(h,g),P=r(h,g+4),E=g+8,T=E+N;if(T+4>h.length)return null;if(P===1229209940)for(let S=E;S<T&&!_;){if(p<0)p++,S++;else if(x>0){let A=Math.min(x,T-S);if(u+A>m.length)return null;m.set(h.subarray(S,S+A),u),u+=A,S+=A,x-=A,x===0&&w[0]&1&&(_=!0)}else{if(w.push(h[S++]),w.length===1&&w[0]>>1&3)return null;if(w.length===5){let A=w[1]|w[2]<<8;if((A^(w[3]|w[4]<<8))!==65535)return null;x=A,A===0&&(w[0]&1&&(_=!0),w=[])}}x===0&&w.length===5&&(w=[])}else if(P===1229278788)break;g=T+4}if(u!==m.length)return null;for(let N=0;N<v;N++)if(m[N*M]!==0)return null;return{w:d,h:v,raw:m}},o=(h,d,v)=>{let M=d*4,m=M+1,u=new Uint8Array(h.length),g=new Uint8Array(M),p=new Uint8Array(M);for(let x=0;x<v;x++){let w=x*m+1,_=w-m,N=0,P=1/0;for(let E=0;E<5;E++){if(E===3||(E===2||E===4)&&x===0)continue;let T=0;for(let S=0;S<M;S++){let A=S>=4?h[w+S-4]:0,D=x>0?h[_+S]:0,R=0;if(E===1)R=A;else if(E===2)R=D;else if(E===4){let k=S>=4&&x>0?h[_+S-4]:0,V=A+D-k,L=Math.abs(V-A),O=Math.abs(V-D),c=Math.abs(V-k);R=L<=O&&L<=c?A:O<=c?D:k}let I=h[w+S]-R&255;g[S]=I,T+=I<128?I:256-I}T<P&&(P=T,N=E,p.set(g))}u[x*m]=N,u.set(p,w)}return u},l=h=>{let d=null;try{d=a(h)}catch{d=null}if(!d)return Promise.resolve(h);let{w:v,h:M,raw:m}=d;return s(o(m,v,M)).then(u=>{let g=45+u.length+12;if(g>=h.length)return h;let p=new Uint8Array(g);p.set(h.subarray(0,33),0),n(p,33,u.length),n(p,37,1229209940),p.set(u,41),n(p,41+u.length,i(p,37,41+u.length));let x=45+u.length;return n(p,x,0),n(p,x+4,1229278788),n(p,x+8,2923585666),p},()=>h)},y=new Int16Array(128).fill(-1),f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let h=0;h<64;h++)y[f.charCodeAt(h)]=h;let b=h=>{let d=h.length;for(;d>0&&h.charCodeAt(d-1)===61;)d--;let v=new Uint8Array(Math.floor(d*3/4)),M=0,m=0,u=0;for(let g=0;g<d;g++){let p=h.charCodeAt(g),x=p<128?y[p]:-1;if(x<0)return null;M=(M<<6|x)&16777215,m+=6,m>=8&&(m-=8,v[u++]=M>>m&255)}return u===v.length?v:null};return{png:l,glb:h=>{let d=(S,A)=>(S[A]|S[A+1]<<8|S[A+2]<<16|S[A+3]<<24)>>>0,v=(S,A,D)=>{S[A]=D&255,S[A+1]=D>>>8&255,S[A+2]=D>>>16&255,S[A+3]=D>>>24},M,m=new Uint8Array(0);try{if(h.length<20||d(h,0)!==1179937895)return Promise.resolve(h);let S=Math.min(h.length,d(h,8)),A=d(h,12);if(d(h,16)!==1313821514||20+A>S)return Promise.resolve(h);M=JSON.parse(new TextDecoder().decode(h.subarray(20,20+A)));let D=20+A;if(D+8<=S){let R=d(h,D);if(d(h,D+4)!==5130562||D+8+R>S)return Promise.resolve(h);m=h.subarray(D+8,D+8+R)}}catch{return Promise.resolve(h)}if(!M||typeof M!="object")return Promise.resolve(h);let u=Array.isArray(M.bufferViews)?M.bufferViews:[],g=Array.isArray(M.images)?M.images:[],p=[],x=[],w=[],_="data:image/png;base64,";for(let S=0;S<g.length;S++){let A=g[S];if(!A||typeof A!="object")continue;let D=u[A.bufferView];if(typeof A.uri=="string"&&A.uri.indexOf(_)===0){let R=b(A.uri.slice(_.length));R&&(x.push(S),w.push(R))}else A.mimeType==="image/png"&&D&&(D.buffer||0)===0&&p.indexOf(A.bufferView)<0&&p.push(A.bufferView)}if(!p.length&&!x.length)return Promise.resolve(h);let N=[];for(let S=0;S<u.length;S++)N.push(S);N.sort((S,A)=>(u[S].byteOffset||0)-(u[A].byteOffset||0));let P=0;for(let S=0;S<N.length;S++){let A=u[N[S]],D=A.byteOffset||0;if(typeof A.byteLength!="number"||(A.buffer||0)!==0||D<P||D+A.byteLength>m.length)return Promise.resolve(h);P=D+A.byteLength}let E=S=>{let A=u[S].byteOffset||0;return m.subarray(A,A+u[S].byteLength)},T=[];for(let S=0;S<p.length;S++)T.push(l(E(p[S])));for(let S=0;S<w.length;S++)T.push(l(w[S]));return Promise.all(T).then(S=>{let A=[];for(let c=0;c<u.length;c++){let F=p.indexOf(c);A.push(F>=0?S[F]:E(c))}let D=0;for(let c=0;c<N.length;c++)D=(D+3&-4)+A[N[c]].length;for(let c=0;c<x.length;c++)D=(D+3&-4)+S[p.length+c].length;let R=D+3&-4,I=new Uint8Array(R),k=0;for(let c=0;c<N.length;c++){let F=N[c];k=k+3&-4,I.set(A[F],k),u[F].byteOffset=k,u[F].byteLength=A[F].length,k+=A[F].length}for(let c=0;c<x.length;c++){let F=S[p.length+c];k=k+3&-4,I.set(F,k);let C=g[x[c]];delete C.uri,C.mimeType="image/png",C.bufferView=u.length,u.push({buffer:0,byteOffset:k,byteLength:F.length}),k+=F.length}M.bufferViews=u,!Array.isArray(M.buffers)||!M.buffers.length?M.buffers=[{byteLength:R}]:M.buffers[0].byteLength=R;let V=new TextEncoder().encode(JSON.stringify(M)),L=V.length+3&-4;if(L!==V.length){let c=new Uint8Array(L).fill(32);c.set(V),V=c}let O=new Uint8Array(20+L+8+R);return v(O,0,1179937895),v(O,4,2),v(O,8,O.length),v(O,12,L),v(O,16,1313821514),O.set(V,20),v(O,20+L,R),v(O,24+L,5130562),O.set(I,28+L),O.length<h.length?O:h})}}}var hs={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function gi(t,e,i,r){if(!i||i.bufferView===void 0)return null;let n=t.bufferViews?.[i.bufferView];if(!n)return null;let s=Number(i.count??0);if(!Number.isInteger(s)||s<=0)return null;let a=i.componentType??5126,o=hs[a];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let l=o*r,y=n.byteStride&&n.byteStride>0?n.byteStride:l,f=(n.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(f)||f<0||y<l||f+(s-1)*y+l>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(a===5126&&y===l&&f%4===0)return new Float32Array(e,f,s*r);let b=new DataView(e),h=i.normalized===!0,d=new Float32Array(s*r);for(let v=0;v<s;v++){let M=f+v*y;for(let m=0;m<r;m++){let u=M+m*o,g;switch(a){case 5126:g=b.getFloat32(u,!0);break;case 5120:g=b.getInt8(u),h&&(g=Math.max(g/127,-1));break;case 5121:g=b.getUint8(u),h&&(g/=255);break;case 5122:g=b.getInt16(u,!0),h&&(g=Math.max(g/32767,-1));break;case 5123:g=b.getUint16(u,!0),h&&(g/=65535);break;default:g=b.getUint32(u,!0),h&&(g/=4294967295)}d[v*r+m]=g}}return d}function us(t,e){let i=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,n=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),a=Number(e.rotation??0)||0,o=Math.cos(a),l=Math.sin(a),y=(Number.isFinite(n)?n:1)*o,f=(Number.isFinite(n)?n:1)*l,b=-(Number.isFinite(s)?s:1)*l,h=(Number.isFinite(s)?s:1)*o;for(let d=0;d+1<t.length;d+=2){let v=t[d],M=t[d+1];t[d]=y*v+f*M+i,t[d+1]=b*v+h*M+r}}function ht(t,e,i,r=!0){let n=[],s=null;try{for(let[a,o]of[[35633,e],[35632,i]]){let l=t.createShader(a);if(!l){if(r)throw new Error("Shader allocation failed");return null}if(n.push(l),t.shaderSource(l,o),t.compileShader(l),t.getShaderParameter&&!t.getShaderParameter(l,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(l)}`);return null}}if(s=t.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let a of n)t.attachShader(s,a);if(t.linkProgram(s),t.getProgramParameter&&!t.getProgramParameter(s,35714)){let a=r?t.getProgramInfoLog(s):null;if(t.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${a}`);return null}return s}finally{for(let a of n)s&&t.detachShader?.(s,a),t.deleteShader?.(a)}}var yi=["neutral","reinhard","none","aces","agx"];function Dt(t){let e=String(t??"").trim().toLowerCase();return yi.includes(e)?e:"neutral"}function cs(t){return yi.indexOf(Dt(t))}function ms(t){return new TextDecoder().decode(t)}var bi=ge().decoders;function fs(t,e){bi.set(t.toLowerCase(),e)}function ut(t){return bi.get(t.toLowerCase())}function xi(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,i=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let h=i.getUint8(0);throw h===123||h===32||h===10||h===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let n=i.getUint32(4,!0);if(n!==2)throw new Error(`Unsupported GLB version: ${n}`);let s=i.getUint32(8,!0),a=12,o=null,l=null;for(;a+8<=s&&a+8<=e.byteLength;){let h=i.getUint32(a,!0),d=i.getUint32(a+4,!0),v=a+8;if(v+h>e.byteLength)throw new Error(`Truncated GLB chunk: required ${v+h} bytes, buffer has ${e.byteLength}`);if(d===1313821514){let M=new Uint8Array(e,v,h),m=ms(M);o=JSON.parse(m,(u,g)=>u==="__proto__"||u==="constructor"||u==="prototype"?void 0:g)}else d===5130562&&(l=e.slice(v,v+h));a=v+h}if(!o)throw new Error("Missing JSON chunk in GLB");let y=o.extensionsRequired||[];for(let[h,d]of[["KHR_draco_mesh_compression","draco"],["EXT_meshopt_compression","meshopt"],["KHR_meshopt_compression","meshopt"],["KHR_texture_basisu","ktx2"]])if(y.includes(h)&&!ut(d))throw new Error(`Model requires ${h}. Register a decoder via ThreeLiveElement.registerDecoder('${d}', decoder).`);let f=l||new ArrayBuffer(0),b={gltf:o,bin:f,animations:[],animationsParsed:!1};for(let h of xe)h.onParseGLB?.(b);return b}function vi(t,e=pi(t)){let i=t?.extensions?.KHR_lights_punctual?.lights;if(!Array.isArray(i))return[];let r=[],n=new Set,s=(a,o,l,y)=>{let f=a.type,b=f==="directional"||f==="point"||f==="spot"?f:"ambient",h=o?o[8]:-.5,d=o?o[9]:-1,v=o?o[10]:-.8,M=Math.hypot(h,d,v)||1,m=a.extras?.shadow??l,u=a.name||y,g={type:b,color:a.color||[1,1,1],intensity:a.intensity??1};u&&(g.name=u),o&&(g.position=[o[12],o[13],o[14]]),b==="directional"&&o?g.direction=[h/M,d/M,v/M]:(b==="spot"&&(g.direction=o?[-h/M,-d/M,-v/M]:[0,-1,0],g.innerConeAngle=a.spot?.innerConeAngle??0,g.outerConeAngle=a.spot?.outerConeAngle??Math.PI/4),g.range=a.range),m&&(g.shadow=m),r.push(g)};return(t.nodes||[]).forEach((a,o)=>{let l=a?.extensions?.KHR_lights_punctual?.light;typeof l=="number"&&i[l]&&(n.add(l),s(i[l],e[o],a.extras?.shadow,a.name))}),i.forEach((a,o)=>{n.has(o)||s(a)}),r}function ps(t){return typeof t=="object"&&t!==null&&"gltf"in t&&typeof t.gltf=="object"&&t.gltf!==null&&"bin"in t&&(t.bin instanceof ArrayBuffer||ArrayBuffer.isView(t.bin))}function It(t){if(ps(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return xi(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Ft=`#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
|
+
}`,ds=`#version 300 es
|
|
52
52
|
precision highp float;
|
|
53
53
|
in vec3 vNormal,vWorldPos;
|
|
54
54
|
in vec2 vUV;
|
|
@@ -57,117 +57,81 @@ in vec4 vInstTint;
|
|
|
57
57
|
#define uBaseColor (uBaseColor*vInstTint)
|
|
58
58
|
uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity,uExposure;
|
|
59
59
|
uniform vec2 uClearcoat;
|
|
60
|
-
uniform vec3 uCameraPos,uAmbientColor;
|
|
61
|
-
uniform
|
|
62
|
-
uniform
|
|
60
|
+
uniform vec3 uCameraPos,uAmbientColor,uEmissiveFactor;
|
|
61
|
+
uniform mat3 uHemi;
|
|
62
|
+
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uEmissiveTexture;
|
|
63
|
+
uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uHasEmissiveTexture;
|
|
63
64
|
uniform float uNormalScale,uOcclusionStrength;
|
|
64
|
-
/*XRD_U*/
|
|
65
|
+
/*XRD_U*//*SHD_U*/
|
|
65
66
|
uniform vec2 uViewportSize;
|
|
66
67
|
uniform vec4 uSectionPlane;
|
|
67
68
|
uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
|
|
68
69
|
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2],uPointLightSpotDir[2];
|
|
69
70
|
uniform vec2 uPointLightSpotCone[2];
|
|
70
71
|
out vec4 fragColor;
|
|
71
|
-
|
|
72
72
|
vec2 envBRDF(float r,float n){
|
|
73
|
-
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04);
|
|
74
|
-
vec4 rv=r*c0+c1;
|
|
73
|
+
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04),rv=r*c0+c1;
|
|
75
74
|
float a=min(rv.x*rv.x,exp2(-9.28*n))*rv.x+rv.y;
|
|
76
75
|
return vec2(-1.04,1.04)*a+rv.zw;
|
|
77
76
|
}
|
|
78
|
-
|
|
79
77
|
vec3 F_SchlickRoughness(vec3 F0,float r,float n){
|
|
80
78
|
return F0+(max(vec3(1.0-r),F0)-F0)*pow(clamp(1.0-n,0.0,1.0),5.0);
|
|
81
79
|
}
|
|
82
|
-
|
|
83
80
|
vec3 getStudioRadiance(vec3 R,float r){
|
|
84
|
-
vec3 kd=normalize(vec3(0.0,1.0,0.35));
|
|
81
|
+
vec3 kd=normalize(vec3(0.0,1.0,0.35)),fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
85
82
|
float ki=pow(max(dot(R,kd),0.0),mix(96.0,1.5,r))*mix(2.4,0.5,r);
|
|
86
|
-
vec3 fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
87
83
|
float fi=pow(max(dot(R,fd),0.0),mix(36.0,1.2,r))*mix(1.3,0.35,r);
|
|
88
84
|
float ri=pow(clamp(1.0-abs(R.y),0.0,1.0),3.5)*mix(0.55,0.22,r);
|
|
89
|
-
|
|
90
|
-
return ag+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
|
|
85
|
+
return mix(vec3(0.06,0.06,0.08),vec3(0.48,0.50,0.55),R.y*0.5+0.5)+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
|
|
91
86
|
}
|
|
92
|
-
|
|
93
|
-
vec3
|
|
94
|
-
vec3
|
|
95
|
-
|
|
96
|
-
vec3
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
vec2 duv2=dFdy(uv);
|
|
100
|
-
vec3 dp2perp=cross(dp2,N);
|
|
101
|
-
vec3 dp1perp=cross(N,dp1);
|
|
102
|
-
vec3 T=dp2perp*duv1.x+dp1perp*duv2.x;
|
|
103
|
-
vec3 B=dp2perp*duv1.y+dp1perp*duv2.y;
|
|
104
|
-
float invmax=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
105
|
-
return normalize(mat3(T*invmax,B*invmax,N)*normalize(mapNormal));
|
|
87
|
+
vec3 perturbNormal(vec3 N,vec3 V,vec2 uv,sampler2D m,float s){
|
|
88
|
+
vec3 q=texture(m,uv).xyz*2.0-1.0;q.xy*=s;
|
|
89
|
+
vec3 p1=dFdx(vWorldPos),p2=dFdy(vWorldPos),c2=cross(p2,N),c1=cross(N,p1);
|
|
90
|
+
vec2 u1=dFdx(uv),u2=dFdy(uv);
|
|
91
|
+
vec3 T=c2*u1.x+c1*u2.x,B=c2*u1.y+c1*u2.y;
|
|
92
|
+
float k=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
93
|
+
return normalize(mat3(T*k,B*k,N)*normalize(q));
|
|
106
94
|
}
|
|
107
|
-
|
|
108
95
|
vec2 equirectangularUV(vec3 dir){
|
|
109
96
|
vec3 d=normalize(dir);
|
|
110
|
-
|
|
111
|
-
float v=asin(clamp(d.y,-1.0,1.0))*0.31830988618+0.5;
|
|
112
|
-
return vec2(u,1.0-v);
|
|
97
|
+
return vec2(atan(d.z,d.x)*0.15915494309+0.5,0.5-asin(clamp(d.y,-1.0,1.0))*0.31830988618);
|
|
113
98
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
float
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if(peak<startCompression)return color;
|
|
123
|
-
const float d=1.0-startCompression;
|
|
124
|
-
float newPeak=1.0-d*d/(peak+d-startCompression);
|
|
125
|
-
color*=newPeak/peak;
|
|
126
|
-
float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
|
|
127
|
-
return mix(color,newPeak*vec3(1.0),g);
|
|
99
|
+
vec3 neutralToneMapping(vec3 c){
|
|
100
|
+
float x=min(c.r,min(c.g,c.b));
|
|
101
|
+
c-=x<0.08?x-6.25*x*x:0.04;
|
|
102
|
+
float p=max(c.r,max(c.g,c.b));
|
|
103
|
+
if(p<0.76)return c;
|
|
104
|
+
float n=1.0-0.0576/(p-0.52);
|
|
105
|
+
c*=n/p;
|
|
106
|
+
return mix(c,vec3(n),1.0-1.0/(0.15*(p-n)+1.0));
|
|
128
107
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
color*=0.6;
|
|
132
|
-
return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
|
|
108
|
+
vec3 acesToneMapping(vec3 c){
|
|
109
|
+
c*=0.6;return clamp((c*(2.51*c+0.03))/(c*(2.43*c+0.59)+0.14),0.0,1.0);
|
|
133
110
|
}
|
|
134
|
-
|
|
135
|
-
vec3
|
|
136
|
-
|
|
137
|
-
vec3
|
|
138
|
-
|
|
139
|
-
0.
|
|
140
|
-
0.
|
|
141
|
-
vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
|
|
142
|
-
vec3 x2=ev*ev;
|
|
143
|
-
vec3 x4=x2*x2;
|
|
144
|
-
vec3 s=15.5*x4*x2-40.14*x4*ev+31.96*x4-6.868*x2*ev+0.4298*x2+0.1191*ev-0.00232;
|
|
145
|
-
vec3 outset=vec3(
|
|
146
|
-
1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
|
|
147
|
-
-0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
|
|
148
|
-
-0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
|
|
149
|
-
return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
111
|
+
vec3 agxToneMapping(vec3 c){
|
|
112
|
+
c=max(c,vec3(0.0));
|
|
113
|
+
vec3 i=mat3(0.84247906,0.04232824,0.04237565,0.0784336,0.87846864,0.0784336,0.07922375,0.07916613,0.87914297)*c;
|
|
114
|
+
vec3 e=clamp((log2(max(i,vec3(1e-6)))+12.47393)/16.5,0.0,1.0),x2=e*e,x4=x2*x2;
|
|
115
|
+
vec3 s=15.5*x4*x2-40.14*x4*e+31.96*x4-6.868*x2*e+0.4298*x2+0.1191*e-0.00232;
|
|
116
|
+
vec3 o=mat3(1.196879,-0.05289685,-0.05297164,-0.09802088,1.15190313,-0.09804345,-0.09902974,-0.09896118,1.15107367)*s;
|
|
117
|
+
return clamp(pow(max(o,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
150
118
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if(mode==0)return neutralToneMapping(color);
|
|
154
|
-
if(mode==1)return color/(color+vec3(1.0));
|
|
155
|
-
if(mode==3)return acesToneMapping(color);
|
|
156
|
-
if(mode==4)return agxToneMapping(color);
|
|
157
|
-
return color;
|
|
119
|
+
vec3 applyToneMapping(vec3 c,int m){
|
|
120
|
+
return m==0?neutralToneMapping(c):m==1?c/(c+vec3(1.0)):m==3?acesToneMapping(c):m==4?agxToneMapping(c):c;
|
|
158
121
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return base*max(dot(N,L),0.0)*0.75+vec3(pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
|
|
122
|
+
vec3 evalLight(vec3 L,vec3 V,vec3 N,vec3 b,float e,float w){
|
|
123
|
+
float h=max(dot(N,normalize(L+V)),0.0);
|
|
124
|
+
return b*max(dot(N,L),0.0)*0.75+vec3(pow(h,e)*w+uClearcoat.x*pow(h,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
|
|
163
125
|
}
|
|
164
126
|
|
|
165
127
|
void main(){
|
|
166
128
|
if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
|
|
167
129
|
vec4 base=uBaseColor;
|
|
168
130
|
if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
|
|
131
|
+
if(base.a<0.004)discard;
|
|
132
|
+
vec3 em=uHasEmissiveTexture==1?uEmissiveFactor*texture(uEmissiveTexture,vUV).rgb:uEmissiveFactor;
|
|
169
133
|
if(length(vNormal)<1e-4&&uHasTexture==1){
|
|
170
|
-
vec3 unlit=base.rgb+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
134
|
+
vec3 unlit=base.rgb+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
171
135
|
fragColor=vec4(unlit,base.a);
|
|
172
136
|
return;
|
|
173
137
|
}
|
|
@@ -199,7 +163,7 @@ float specWeight=mix(0.22*gloss,1.0,metallic);
|
|
|
199
163
|
vec3 directLight=vec3(0.0);
|
|
200
164
|
for(int i=0;i<2;i++){
|
|
201
165
|
if(i>=uNumDirLights)break;
|
|
202
|
-
directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i]
|
|
166
|
+
directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i]/*SHD_D*/;
|
|
203
167
|
}
|
|
204
168
|
for(int i=0;i<2;i++){
|
|
205
169
|
if(i>=uNumPointLights)break;
|
|
@@ -208,7 +172,7 @@ float dist=length(toLight);
|
|
|
208
172
|
vec3 L=toLight/max(dist,0.0001);
|
|
209
173
|
float spotAtt=clamp((dot(-L,uPointLightSpotDir[i])-uPointLightSpotCone[i].y)/max(uPointLightSpotCone[i].x-uPointLightSpotCone[i].y,0.0001),0.0,1.0);
|
|
210
174
|
spotAtt*=spotAtt;
|
|
211
|
-
directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist)
|
|
175
|
+
directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist)/*SHD_P*/;
|
|
212
176
|
}
|
|
213
177
|
|
|
214
178
|
vec3 R=reflect(-V,N);
|
|
@@ -228,8 +192,9 @@ envDiffuse=mix(vec3(0.10,0.10,0.12),vec3(0.52,0.54,0.58),N.y*0.5+0.5);
|
|
|
228
192
|
}
|
|
229
193
|
|
|
230
194
|
vec3 kD=(vec3(1.0)-F)*(1.0-metallic);
|
|
195
|
+
directLight+=kD*base.rgb*mix(uHemi[1],uHemi[0],dot(N,uHemi[2])*0.5+0.5)*occ;
|
|
231
196
|
vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
232
|
-
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
197
|
+
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
233
198
|
if(uClearcoat.x>0.0){
|
|
234
199
|
vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
|
|
235
200
|
color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
@@ -239,140 +204,157 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
239
204
|
float outAlpha=base.a;
|
|
240
205
|
/*XRD_O*/
|
|
241
206
|
fragColor=vec4(color,outAlpha);
|
|
242
|
-
}`,
|
|
207
|
+
}`,gs=`#version 300 es
|
|
243
208
|
layout(location=0) in vec3 aPosition;
|
|
244
209
|
uniform mat4 uMVP;
|
|
245
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
210
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ys=`#version 300 es
|
|
246
211
|
precision highp float;
|
|
247
212
|
uniform vec4 uColorId;
|
|
248
213
|
out vec4 fragColor;
|
|
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 = ${
|
|
214
|
+
void main(){fragColor=uColorId;}`;function ct(t,e,i){let r={};for(let n of i)r[n]=t.getUniformLocation(e,n);return r}var bs="uMVP uModel uInstanced uViewProj uNormalMatrix uUvTransform uBaseColor uMetallic uRoughness uClearcoat uEmissive uCameraPos uBaseColorTexture uHasTexture uMetallicRoughnessTexture uHasMetallicRoughnessTexture uNormalTexture uHasNormalTexture uNormalScale uOcclusionTexture uHasOcclusionTexture uOcclusionStrength uEmissiveFactor uEmissiveTexture uHasEmissiveTexture uToneMapping uEnvironmentMap uHasEnvironmentMap uAmbientColor uHemi uNumDirLights uDirLightDir uDirLightColor uNumPointLights uPointLightPos uPointLightColor uPointLightSpotDir uPointLightSpotCone uEnvIntensity uExposure uViewportSize uSectionPlane uSectionEnabled".split(" ");function kt(){let t=ge(),e=t.xrDepthShader,i=t.shadowMapShader;return{fs:ds.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||"").replace("/*SHD_U*/",i?.uniformsGLSL||"").replace("/*SHD_D*/",i?.dirGLSL||"").replace("/*SHD_P*/",i?.ptGLSL||""),uniforms:[...bs,...e?.uniformNames||[],...i?.uniformNames||[]]}}function xs(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let i=e.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:i.startsWith("https://")||i.startsWith("blob:")?e:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Ut(t,e,i,r,n,s,a,o){if(r===void 0||!e.accessors?.[r])return null;let l=gi(e,i,e.accessors[r],s);if(!l)return null;o&&(l=l.slice(),us(l,o));let y=t.createBuffer();return a.push(y),t.bindBuffer(34962,y),t.bufferData(34962,l,35044),t.enableVertexAttribArray(n),t.vertexAttribPointer(n,s,5126,!1,0,0),l}function Ot(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function Mi(t,e,i){let r=kt(),n=Ft,s=r.fs,a=!1;for(let l of xe)if(l.onResolveShader){let y=l.onResolveShader(e,i,n,s);y&&(n=y.vs,s=y.fs,a=!0)}let o=a?ht(t,n,s):null;return{program:o,uniforms:o?ct(t,o,r.uniforms):null}}function vs(t,e,i){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let n=r.length>>4,s=e.instanceColors,a=new Float32Array(n*20);for(let l=0;l<n;l++)a.set(r.subarray(l*16,l*16+16),l*20),a[l*20+16]=s?s[l*3]:1,a[l*20+17]=s?s[l*3+1]:1,a[l*20+18]=s?s[l*3+2]:1,a[l*20+19]=1;let o=t.createBuffer();i.push(o),t.bindBuffer(34962,o),t.bufferData(34962,a,35044);for(let l=0;l<5;l++)t.enableVertexAttribArray(8+l),t.vertexAttribPointer(8+l,4,5126,!1,80,l*16),t.vertexAttribDivisor(8+l,1);return!0}function Ms(t,e){let i=t.materials?.[e?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let n of r){let s=n?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var Ys=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),wi=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function mt(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function Si(t,e){let i=t?.pbrMetallicRoughness,r=i?.baseColorFactor,n=t?.emissiveFactor,s=t?.extensions?.KHR_materials_clearcoat,a=o=>o!==void 0&&e[o.index]?e[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:a(i?.baseColorTexture),metallicRoughnessTexture:a(i?.metallicRoughnessTexture),normalTexture:a(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:a(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,emissiveTexture:a(t?.emissiveTexture),emissiveFactor:Array.isArray(n)&&n.length>=3?[n[0],n[1],n[2]]:[0,0,0],isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Ti(t,e,i){let r=new Set,n=s=>{s&&!r.has(s)&&(r.add(s),t.deleteTexture(s))};for(let s of e)for(let a of s.primitives){if(a.vao&&t.deleteVertexArray(a.vao),a.buffers)for(let l of a.buffers)t.deleteBuffer(l);for(let l of[a.texture,a.metallicRoughnessTexture,a.normalTexture,a.occlusionTexture,a.emissiveTexture])n(l);let o=new Set;a.customProgram&&o.add(a.customProgram);for(let l of a.programCache?.values()??[])l.program&&o.add(l.program);for(let l of o)t.deleteProgram(l)}if(i)for(let s of i)n(s)}function Ai(t,e,i=wi,r){let n={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ws(t,e,i,r,n)}catch(s){let a=n.mesh&&!n.meshes.includes(n.mesh)?[...n.meshes,n.mesh]:n.meshes;Ti(t,a,n.gpuTextures),n.vao&&t.deleteVertexArray(n.vao);for(let o of n.buffers)t.deleteBuffer(o);throw s}}function ws(t,e,i,r,n){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,a=ut("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(s,e);let o=e.bin,l=[];n.meshes=l;let y=[],f=s.extensions?.KHR_materials_variants;f&&Array.isArray(f.variants)&&f.variants.forEach((T,S)=>{y.push(typeof T?.name=="string"&&T.name?T.name:`Variant_${S}`)});let b=pi(s),h=[];if(Array.isArray(s.nodes))for(let T=0;T<s.nodes.length;T++){let S=s.nodes[T];S.mesh!==void 0&&s.meshes&&s.meshes[S.mesh]&&h.push({node:S,nodeIdx:T,meshIdx:S.mesh})}let d=h.length>0?h:(s.meshes||[]).map((T,S)=>({node:T,nodeIdx:-1,meshIdx:S})),v=[],M=Array.isArray(e.lights)&&e.lights.length>0?e.lights:Array.isArray(s.asset?.extras?.lights)&&s.asset.extras.lights.length>0?s.asset.extras.lights:null;if(M)for(let T of M)v.push({...T,type:T.type||T.light_type||"point",groundColor:T.groundColor??T.ground_color,innerConeAngle:T.innerConeAngle??T.inner_cone_angle,outerConeAngle:T.outerConeAngle??T.outer_cone_angle});else s.extensions?.KHR_lights_punctual?.lights&&v.push(...vi(s,b));if(v.length===0&&(v.push({type:"ambient",color:[1,1,1],intensity:.35}),v.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),d.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${d.length}`);let m=[];if(n.gpuTextures=m,s.textures&&s.images){if(s.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${s.textures.length}`);for(let T=0;T<s.textures.length;T++){let S=s.textures[T],A=s.images[S.source];if(A){let D=t.createTexture();t.bindTexture(3553,D),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255]));for(let[I,k]of[[10242,10497],[10243,10497],[10241,9729],[10240,9729]])t.texParameteri(3553,I,k);let R=I=>{D.__gpuImageSource=I,t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,I),t.generateMipmap(3553),r?.()};if(A.bufferView!==void 0){let I=s.bufferViews[A.bufferView],k=I.byteOffset||0,V=new Blob([o.slice(k,k+I.byteLength)],{type:A.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(V).then(R).catch(()=>{})}else if(A.uri){let I=xs(A.uri);if(I){let k=new Image;k.crossOrigin="anonymous",k.referrerPolicy="no-referrer",k.onload=()=>R(k),k.src=I}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",A.uri)}m.push(D)}else m.push(null)}}let u=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0],p=0,x=0;for(let T=0;T<d.length;T++){let S=d[T],A=s.meshes[S.meshIdx],D=S.nodeIdx>=0?b[S.nodeIdx]:ve(),R=new Float32Array(9);Oe(R,D);let I=S.node?.extras?.shadow,k={name:S.node.name||A.name||`Mesh_${S.meshIdx}`,nodeIndex:S.nodeIdx,transform:D,normalMatrix:R,primitives:[],extras:S.node.extras||A.extras,...S.node?.visible===!1||S.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{},...typeof I?.cast=="boolean"?{castShadow:I.cast}:{},...typeof I?.receive=="boolean"?{receiveShadow:I.receive}:{}};n.mesh=k;let V=S.node?.extensions?.EXT_mesh_gpu_instancing;if(V&&V.attributes&&typeof V.attributes=="object"){let L=V.attributes,O=L.TRANSLATION!==void 0?s.accessors?.[L.TRANSLATION]:null,c=L.ROTATION!==void 0?s.accessors?.[L.ROTATION]:null,F=L.SCALE!==void 0?s.accessors?.[L.SCALE]:null,C=L._COLOR_0!==void 0?s.accessors?.[L._COLOR_0]:null,U=Number(O?.count??c?.count??F?.count??0);if(!Number.isFinite(U)||U<0||U>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${U}`);if(U>0){let H=(B,X)=>{if(!B||B.bufferView===void 0||!s.bufferViews?.[B.bufferView])return null;let z=B.componentType??5126,Q=K=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${K})`),null);if(z!==5120&&z!==5121&&z!==5122&&z!==5123&&z!==5126)return Q(`componentType ${z}`);if(!(Number(B.count)>=U))return Q(`count ${B.count} < ${U}`);let te=null;try{te=gi(s,o,{...B,count:U},X)}catch{return Q("out of bounds")}return!te||!te.every(Number.isFinite)?Q("non-finite value"):te},j=H(O,3),Y=H(c,4),q=H(F,3),ne=C?.type==="VEC4"?4:3,ie=H(C,ne),oe=new Float32Array(U*16),he=ve();for(let B=0;B<U;B++){let X=B*3,z=B*4;Nt(he,Y?[Y[z],Y[z+1],Y[z+2],Y[z+3]]:[0,0,0,1],j?[j[X],j[X+1],j[X+2]]:[0,0,0],q?[q[X],q[X+1],q[X+2]]:[1,1,1]),oe.set(he,B*16)}if(k.instanceMatrices=oe,ie){let B=new Float32Array(U*3);for(let X=0;X<U;X++)B[X*3]=ie[X*ne],B[X*3+1]=ie[X*ne+1],B[X*3+2]=ie[X*ne+2];k.instanceColors=B}}}for(let L of A.primitives||[]){if(L.extensions?.KHR_draco_mesh_compression){let $=ut("draco");$&&$.decodePrimitive(s,L,o)}let O=[],c=t.createVertexArray();n.vao=c,n.buffers=O,t.bindVertexArray(c);let F=vs(t,k,O),C=s.accessors[L.attributes.POSITION],U=Number(C?.count??0);if(!Number.isFinite(U)||U<0||p+U>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(p+=U,C?.min&&C?.max){let $=G=>{for(let W=0;W<3;W++){let J=G[12+W],ae=J;for(let se=0;se<3;se++){let fe=G[se*4+W]*C.min[se],re=G[se*4+W]*C.max[se];J+=fe<re?fe:re,ae+=fe>re?fe:re}J<u[W]&&(u[W]=J),ae>g[W]&&(g[W]=ae)}};if(k.instanceMatrices&&k.instanceMatrices.length>=16){let G=k.instanceMatrices.length>>4,W=ve();for(let J=0;J<G;J++)Te(W,D,k.instanceMatrices.subarray(J*16,J*16+16)),$(W)}else $(D)}let H=Ut(t,s,o,L.attributes.POSITION,0,3,O),j=Ut(t,s,o,L.attributes.NORMAL,1,3,O),Y=Ut(t,s,o,L.attributes.TEXCOORD_0,2,2,O,Ms(s,L)),q=0,ne=5123,ie=null;if(L.indices!==void 0){let $=s.accessors[L.indices],G=(s.bufferViews[$.bufferView].byteOffset||0)+($.byteOffset||0);if(q=Number($.count??0),!Number.isFinite(q)||q<0||x+q>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);x+=q,ne=$.componentType===5125?5125:5123;let W=t.createBuffer();O.push(W),t.bindBuffer(34963,W),$.componentType===5125?ie=new Uint32Array(o,G,$.count):$.componentType===5121?ie=Uint16Array.from(new Uint8Array(o,G,$.count)):ie=G%2===0?new Uint16Array(o,G,$.count):new Uint16Array(o.slice(G,G+$.count*2)),t.bufferData(34963,ie,35044)}else q=C.count;let oe={};for(let $ of xe)if($.onBuildPrimitiveVAO){let G=$.onBuildPrimitiveVAO(t,c,L,s,o);G&&(oe[$.name]=G)}t.bindVertexArray(null);let he=s.materials&&L.material!==void 0?s.materials[L.material]:null,{program:B,uniforms:X}=Mi(t,L,he),z=Si(he,m),Q=!!(he?.extensions?.KHR_materials_transmission||oe.materials?.isTransmissive),te=L.extensions?.KHR_materials_variants?.mappings,K=Array.isArray(te)?te.filter($=>$&&typeof $.material=="number"&&Array.isArray($.variants)).map($=>({material:$.material|0,variants:$.variants.map(G=>Number(G)|0)})):void 0;k.primitives.push({vao:c,instanced:F,indexCount:q,indexType:ne,...z,positions:H,normals:j,uvs:Y,indices:ie,buffers:O,materialIndex:L.material,defaultMaterialIndex:L.material,variantMappings:K,primitiveDef:L,programCache:new Map([[L.material??-1,{program:B,uniforms:X}]]),pluginData:oe,customProgram:B,customUniforms:X,isTransmissive:Q})}l.push(k)}isFinite(u[0])||(u=[-1,-1,-1]),isFinite(g[0])||(g=[1,1,1]);let w=[(u[0]+g[0])/2,(u[1]+g[1])/2,(u[2]+g[2])/2],_=Math.max(Math.hypot(g[0]-u[0],g[1]-u[1],g[2]-u[2])/2,.5),N=[...u],P=[...g],E=e.animations;if(e.animationsParsed===!1||!E){for(let T of xe)if(T.onParseGLB?.(e),e.animations){E=e.animations;break}}return E||(E=[]),{meshes:l,bounds:{center:w,radius:_,min:N,max:P},lights:v,animations:E,worldMatrices:b,gpuTextures:m,availableVariants:y}}function ft(){return typeof performance<"u"?performance.now():Date.now()}function Je(t){let e=t.customTarget||t.bounds.center,i=t.currDistance*Math.cos(t.currPhi);return[e[0]+i*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+i*Math.cos(t.currTheta)]}var _i=class{constructor(t,e,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=ve(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.environmentSource=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=ve(),this.viewMatrix=ve(),this.activeViewMatrix=null,this.modelMatrix=ve(),this.mvpMatrix=ve(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshNames=new Set,this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:ve(),rawValueToMeters:.001,format:0},this.container=t;let r,n;if(e&&typeof e.getContext=="function"?(r=e,n=i):(n=e,r=n?.canvas),!r){let l=t.querySelector("canvas");l||(l=document.createElement("canvas"),l.style.cssText="width:100%;height:100%;display:block;touch-action:none",t.prepend(l)),r=l}this.canvas=r;let s=this.opts=n||{};s.clearColor&&(this.clearColor=s.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;s.autoRotate!==void 0?this.autoRotate=s.autoRotate&&!a:a&&(this.autoRotate=!1),s.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=s.autoRotateSpeed),s.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(s.autoRotateDelay)||0)),s.exposure!==void 0&&(this.exposure=Ot(s.exposure)),s.camera&&this.setInitialCamera(s.camera.theta,s.camera.phi,s.camera.distance,s.camera.zoom),(s.shadowIntensity!==void 0||s.shadowSoftness!==void 0)&&this.setShadow(s.shadowIntensity??0,s.shadowSoftness),s.shadowMaps!==void 0&&(this.shadowMaps=s.shadowMaps),s.toneMapping!==void 0&&(this.toneMapping=Dt(s.toneMapping)),s.autoplay!==void 0&&(this.autoplay=s.autoplay),s.animationName!==void 0&&(this.animationName=s.animationName),s.variantName!==void 0&&(this.activeVariantName=s.variantName||null),s.fieldOfView!==void 0&&(this.fov=s.fieldOfView*Math.PI/180),s.distanceMode!==void 0&&(this.distanceMode=s.distanceMode),s.cameraTarget!==void 0&&(this.setTarget(s.cameraTarget[0],s.cameraTarget[1],s.cameraTarget[2]),this.initialCustomTarget=[...s.cameraTarget]),(s.minCameraOrbit||s.maxCameraOrbit)&&this.setOrbitLimits({minTheta:s.minCameraOrbit?.theta,maxTheta:s.maxCameraOrbit?.theta,minPhi:s.minCameraOrbit?.phi,maxPhi:s.maxCameraOrbit?.phi,minDistance:s.minCameraOrbit?.distance,maxDistance:s.maxCameraOrbit?.distance});let o=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!o)throw new Error("WebGL2 not supported");this.gl=o,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),s.environmentImage&&this.setEnvironmentImage(s.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&s.autoStart!==!1&&this.start()}static registerDecoder(t,e){fs(t,e)}static getDecoder(t){return ut(t)}setupContextLossHandling(){let t=this.canvas;typeof t?.addEventListener=="function"&&(this.boundContextLost=e=>{e.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),t.addEventListener("webglcontextlost",this.boundContextLost),t.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let t=this.gl,e=kt();this.renderProg=ht(t,Ft,e.fs),this.pickProg=ht(t,gs,ys),this.uRender=ct(t,this.renderProg,e.uniforms),this.uPick=ct(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}recompileRenderProgram(){if(this.contextLost)return;let t=this.gl,e=kt();this.renderProg&&t.deleteProgram(this.renderProg),this.renderProg=ht(t,Ft,e.fs),this.uRender=ct(t,this.renderProg,e.uniforms);for(let i of this.meshes)for(let r of i.primitives)r.customProgram&&(t.deleteProgram(r.customProgram),r.programCache?.clear(),this.applyPrimitiveProgram(r,r.materialIndex,this.gltf?.materials?.[r.materialIndex??-1]??null))}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let e of xe)e.onContextRestored?.(t,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let t=this.gl;typeof t.createFramebuffer=="function"&&(this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer(),this.resizePickingFbo(this.canvas.width,this.canvas.height),t.bindFramebuffer(36160,this.pickFbo),t.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),t.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),t.bindFramebuffer(36160,null))}resizePickingFbo(t,e){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,t),n=Math.max(1,e);this.pickFboWidth=r,this.pickFboHeight=n,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,n,0,6408,5121,null),i.texParameteri(3553,10241,9728),i.texParameteri(3553,10240,9728),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,n)}loadGLBData(t,e){let{meshes:i,bounds:r,lights:n,animations:s,worldMatrices:a,gpuTextures:o,availableVariants:l}=Ai(this.gl,t,e,()=>this.render());this.lastGlbData=t,this.lastLimits=e,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=n,this.animations=s||[],this.worldMatrices=a||[],this.gpuTextures=o||[],this.availableVariants=l||[],this.gltf=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=(t.gltf?.nodes||[]).map(b=>({t:[b.translation?.[0]??0,b.translation?.[1]??0,b.translation?.[2]??0],r:[b.rotation?.[0]??0,b.rotation?.[1]??0,b.rotation?.[2]??0,b.rotation?.[3]??1],s:[b.scale?.[0]??1,b.scale?.[1]??1,b.scale?.[2]??1]})),this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let b of xe)b.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let y=t.exposure??t.gltf?.extras?.exposure??t.gltf?.asset?.extras?.exposure;y!==void 0&&(this.exposure=Ot(y));let f=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.environmentIntensity;f!==void 0&&(this.envIntensity=Math.max(0,Number(f)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(t){this.loadGLBData(xi(t))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let t of xe)t.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(It(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let i=It(t),{meshes:r}=Ai(this.gl,i,wi,()=>this.render());if(e)for(let n of r)n.transform[12]+=e[0],n.transform[13]+=e[1],n.transform[14]+=e[2],Oe(n.normalMatrix,n.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(t,e,i,r=1){this.clearColor=[t,e,i,r]}updateMeshTransforms(t){for(let e=0;e<this.meshes.length;e++){let i=this.meshes[e],r=t instanceof Map?t.get(i.name)??t.get(e):Array.isArray(t)?t[e]:t&&typeof t=="object"?Object.prototype.hasOwnProperty.call(t,i.name)?t[i.name]:Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0:void 0;r&&r.length===16&&(i.transform.set(r),Oe(i.normalMatrix,i.transform))}}bindLights(t=this.uRender){let e=this.gl,i=[.28,.28,.28],r=[0,0,0,0,0,0,0,1,0],n=!1,s=[],a=[],o=[],l=[],y=[],f=[];for(let b of this.lights){let h=b.color||[1,1,1],d=b.intensity!==void 0?b.intensity:1;if(b.type==="ambient")i=[h[0]*d,h[1]*d,h[2]*d];else if(b.type==="hemisphere"){n=!0;let v=b.groundColor||[.2,.2,.2],M=d*.65;for(let g=0;g<3;g++)r[g]+=h[g]*M,r[g+3]+=v[g]*M;let m=b.position||[0,1,0],u=Math.hypot(m[0],m[1],m[2]);u>1e-5&&(r[6]=m[0]/u,r[7]=m[1]/u,r[8]=m[2]/u)}else if(b.type==="directional"&&s.length<6){let v=b.direction||[.5,1,.8];s.push(v[0],v[1],v[2]),a.push(h[0]*d,h[1]*d,h[2]*d)}else if((b.type==="point"||b.type==="spot")&&o.length<6){let v=b.position||[0,0,0];if(o.push(v[0],v[1],v[2]),l.push(h[0]*d,h[1]*d,h[2]*d),b.type==="spot"){let M=b.direction||[0,-1,0],m=Math.max(.01,Math.min(Math.PI/2,b.outerConeAngle??Math.PI/3)),u=Math.max(0,Math.min(m-1e-4,b.innerConeAngle??0));y.push(M[0],M[1],M[2]),f.push(Math.cos(u),Math.cos(m))}else y.push(0,-1,0),f.push(-2,-3)}}s.length===0&&!n&&(s.push(.5,1,.8),a.push(1,1,1)),e.uniform3fv(t.uAmbientColor,i),t.uHemi&&e.uniformMatrix3fv(t.uHemi,!1,r),e.uniform1i(t.uNumDirLights,s.length/3),s.length>0&&(e.uniform3fv(t.uDirLightDir,s),e.uniform3fv(t.uDirLightColor,a)),e.uniform1i(t.uNumPointLights,o.length/3),o.length>0&&(e.uniform3fv(t.uPointLightPos,o),e.uniform3fv(t.uPointLightColor,l),t.uPointLightSpotDir&&e.uniform3fv(t.uPointLightSpotDir,y),t.uPointLightSpotCone&&e.uniform2fv(t.uPointLightSpotCone,f)),e.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=Ot(t)}getExposure(){return this.exposure}setShadow(t,e){this.shadowIntensity=Math.max(0,Math.min(1,Number(t)||0)),e!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(e)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(t){this.toneMapping=Dt(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){this.environmentSource=t&&typeof t=="object"?t:null;for(let e of xe)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t),this.render();return}this.render()}async setSkyboxImage(t){for(let e of xe)if(e.setSkyboxImage){await e.setSkyboxImage(this,t);return}}setInteractive(t){this.interactive=t}isInteractive(){return this.interactive}getCameraOrbit(){let t=this.currTheta,e=this.currPhi,i=this.currDistance;return{theta:t,phi:e,radius:i,toString(){return`${t.toFixed(4)}rad ${e.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let t=this.customTarget||this.bounds.center;return{x:t[0],y:t[1],z:t[2],toString(){return`${t[0].toFixed(4)}m ${t[1].toFixed(4)}m ${t[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let t=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return t.map((e,i)=>{let r=this.meshes.flatMap(f=>f.primitives.filter(b=>b.materialIndex===i||t.length===1&&b.materialIndex===void 0)),n=r[0],s=n?[...n.baseColor]:e.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],a=n?n.metallic:e.pbrMetallicRoughness?.metallicFactor??.1,o=n?n.roughness:e.pbrMetallicRoughness?.roughnessFactor??.5,l=(f,b,h)=>{y[f]=h,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness[f]=h);for(let d of r)d[b]=h;this.render()},y={baseColorFactor:s,metallicFactor:a,roughnessFactor:o,setBaseColorFactor:f=>l("baseColorFactor","baseColor",[f[0],f[1],f[2],f[3]??1]),setMetallicFactor:f=>l("metallicFactor","metallic",f),setRoughnessFactor:f=>l("roughnessFactor","roughness",f)};return{name:e.name||`Material_${i}`,pbrMetallicRoughness:y}})}playAnimation(t){if(this.animations.length!==0){if(t){let e=this.animations.find(i=>i.name===t);e&&(this.currentClip=e)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(t=>t.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(t){let e=this.applyVariantMaterial(t);return e&&this.gl&&this.render(),e}applyVariantMaterial(t){let e=t===null||t==="",i=-1;if(e)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(t),i<0)return!1;this.activeVariantName=t}let r=this.gltf?.materials;if(!Array.isArray(r))return e;for(let n of this.meshes)for(let s of n.primitives){let a=s.defaultMaterialIndex;if(!e&&Array.isArray(s.variantMappings)){for(let l of s.variantMappings)if(Array.isArray(l.variants)&&l.variants.includes(i)){a=l.material;break}}let o=a!==void 0?r[a]:void 0;s.materialIndex=o?a:void 0,Object.assign(s,Si(o,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,o??null)}return!0}applyPrimitiveProgram(t,e,i){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let r=e??-1,n=t.programCache.get(r);n||(n=Mi(this.gl,{...t.primitiveDef,material:e},i),t.programCache.set(r,n)),t.customProgram=n.program,t.customUniforms=n.uniforms,t.pluginData&&(t.pluginData.materials=t.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(t){this.autoplay=t,t?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(t){this.animationName=t,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(t)}evaluateAnimation(t){for(let e of xe)if(e.evaluateAnimation){e.evaluateAnimation(this,t);return}}setTarget(t,e,i){this.customTarget=[t,e,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(t){let e=Math.max(10,Math.min(90,t));this.fov=e*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(t){if(this.distanceMode=t,!this.customDistance){let e=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=e,this.targetDistance=e,this.currDistance=e,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(t){let e=Math.PI/180,i=Math.PI*.48;t.minTheta!==void 0&&(this.minTheta=t.minTheta*e),t.maxTheta!==void 0&&(this.maxTheta=t.maxTheta*e),t.minPhi!==void 0&&(this.minPhi=Math.max(-i,t.minPhi*e)),t.maxPhi!==void 0&&(this.maxPhi=Math.min(i,t.maxPhi*e)),t.minDistance!==void 0&&(this.minDistanceLimit=t.minDistance),t.maxDistance!==void 0&&(this.maxDistanceLimit=t.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){let t=180/Math.PI;return{minTheta:isFinite(this.minTheta)?this.minTheta*t:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*t:void 0,minPhi:this.minPhi*t,maxPhi:this.maxPhi*t,minDistance:this.minDistanceLimit??void 0,maxDistance:this.maxDistanceLimit??void 0}}clampTheta(t){return Math.max(this.minTheta,Math.min(this.maxTheta,t))}clampPhi(t){return Math.max(this.minPhi,Math.min(this.maxPhi,t))}clampDistance(t){let e=this.bounds?.radius;return Math.max(this.minDistanceLimit??(e?e*.5:.1),Math.min(this.maxDistanceLimit??(e?e*8:100),t))}setCamera(t,e,i,r){t!==void 0&&(this.targetTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.targetPhi=this.clampPhi(e*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(t,e,i,r){t!==void 0&&(this.initialTheta=this.targetTheta=this.currTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.initialPhi=this.targetPhi=this.currPhi=this.clampPhi(e*Math.PI/180));let n=i!==void 0&&i>0?i:r!==void 0&&r>0?this.bounds.radius*2.5/r:null;this.customDistance=n!==null,this.initialDistance=this.targetDistance=this.currDistance=this.clampDistance(n??(this.distanceMode==="absolute"?3:this.bounds.radius*2.5)),this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.targetDistance=this.clampDistance(this.initialDistance??this.bounds.radius*2.5),this.customTarget=this.initialCustomTarget?[...this.initialCustomTarget]:null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(t,e){let i=ve();Te(i,this.projMatrix,this.viewMatrix);let r=(P,E,T=1)=>[P[0]*E[0]+P[4]*E[1]+P[8]*E[2]+P[12]*T,P[1]*E[0]+P[5]*E[1]+P[9]*E[2]+P[13]*T,P[2]*E[0]+P[6]*E[1]+P[10]*E[2]+P[14]*T,P[3]*E[0]+P[7]*E[1]+P[11]*E[2]+P[15]*T],n=this.modelRootMatrix,[s,a,o]=n?r(n,t):t,[l,y,f]=e?n?r(n,e,0):e:[0,0,0],[b,h,d,v]=r(i,[s,a,o]);if(v<=1e-4)return{x:0,y:0,z:1,visible:!1};let M=b/v,m=h/v,u=d/v,g=this.canvas.getBoundingClientRect(),p=g.width||this.canvas.clientWidth||this.canvas.width||300,x=g.height||this.canvas.clientHeight||this.canvas.height||150,w=(M*.5+.5)*p,_=(-m*.5+.5)*x,N=M>=-1.1&&M<=1.1&&m>=-1.1&&m<=1.1&&u>=-1&&u<=1;if(N&&e){let[P,E,T]=Je(this),S=[s-P,a-E,o-T];l*S[0]+y*S[1]+f*S[2]>.05&&(N=!1)}return{x:w,y:_,z:u,visible:N}}setSelectedMesh(t){this.setSelectedMeshes([t])}setSelectedMeshes(t){this.selectedMeshNames=new Set(t.filter(Boolean))}getSelectedMesh(){return[...this.selectedMeshNames][0]||""}setupEvents(){let t=this.canvas,e=ft;this.boundContextMenu=i=>{i.preventDefault()},t.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=e(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,t.setPointerCapture(i.pointerId))},t.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=e();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},n=i.clientX-r.x,s=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(n,s),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],l=this.customTarget?[...this.customTarget]:[...this.bounds.center],y=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;l[0]+=(-n*a[0]+s*o[0])*y,l[1]+=(-n*a[1]+s*o[1])*y,l[2]+=(-n*a[2]+s*o[2])*y,this.customTarget=l}else this.targetTheta=this.clampTheta(this.targetTheta-n*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},t.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=e(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{t.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=t.getBoundingClientRect(),n=Math.floor((i.clientX-r.left)*(t.width/Math.max(r.width,1))),s=Math.floor((i.clientY-r.top)*(t.height/Math.max(r.height,1)));this.performMeshPick(n,s,!0)}},t.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=e();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},t.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),t.tabIndex!==void 0&&t.tabIndex<0&&(t.tabIndex=0),t.getAttribute?.("role")||t.setAttribute?.("role","region"),t.getAttribute?.("aria-label")||t.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=e(),i.preventDefault()}},t.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let t=(i,r,n)=>{this[n]&&(i.removeEventListener(r,this[n]),this[n]=null)},e=this.canvas;for(let[i,r]of[["webglcontextlost","boundContextLost"],["webglcontextrestored","boundContextRestored"],["contextmenu","boundContextMenu"],["pointerdown","boundPointerDown"],["pointermove","boundPointerMove"],["pointerup","boundPointerUp"],["wheel","boundWheel"],["keydown","boundKeyDown"]])t(e,i,r);t(this.container,"setCamera","boundSetCamera"),t(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(t,e){let i=this.canvas,r=i.getBoundingClientRect(),n=i.width||300,s=i.height||300,a=r.width>0?Math.floor((t-r.left)*(n/r.width)):Math.floor(t),o=r.height>0?Math.floor((e-r.top)*(s/r.height)):Math.floor(e);return this.performMeshPick(a,o,!1)}performMeshPick(t,e,i=!0){if(this.meshes.length===0)return null;let r=this.gl,n=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);t=this.mapStereoPickX(t,n);let a=ve();Te(a,this.projMatrix,this.viewMatrix);let o=[],l=Math.max(0,Math.min(n-1,t)),y=Math.max(0,Math.min(s-1,s-1-e));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==n||this.pickFboHeight!==s)&&this.resizePickingFbo(n,s),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,n,s),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let w=0;w<this.meshes.length;w++){let _=this.meshes[w];if(_.visible===!1||_.isPluginMesh)continue;let N=w+1,P=(N&255)/255,E=(N>>8&255)/255,T=(N>>16&255)/255;r.uniform4f(this.uPick.uColorId,P,E,T,1),Te(this.modelMatrix,this.modelRootMatrix,_.transform);let S=_.instanceMatrices;if(S&&S.length>=16){let A=S.length>>4,D=ve();for(let R of _.primitives){r.bindVertexArray(R.vao);for(let I=0;I<A;I++)Te(D,this.modelMatrix,S.subarray(I*16,I*16+16)),Te(this.mvpMatrix,a,D),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),mt(r,R)}}else{Te(this.mvpMatrix,a,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let A of _.primitives)r.bindVertexArray(A.vao),mt(r,A)}}let p=new Uint8Array(4);r.readPixels(l,y,1,1,6408,5121,p),r.bindFramebuffer(36160,null);let x=p[0]+(p[1]<<8)+(p[2]<<16);x>0&&x<=this.meshes.length&&(o=[this.meshes[x-1]])}o.length===0&&(o=this.meshes.filter(p=>p.visible!==!1));let f=null,b=1/0,h=[0,0,0],d=[0,1,0],[v,M,m]=Je(this),u=ve();for(let p of o){Te(u,this.modelRootMatrix,p.transform);let x=p.instanceMatrices,w=x&&x.length>=16?x.length>>4:1;for(let _=0;_<w;_++){x&&x.length>=16?Te(this.modelMatrix,u,x.subarray(_*16,_*16+16)):this.modelMatrix.set(u),Te(this.mvpMatrix,a,this.modelMatrix);let N=ve();if(!os(N,this.mvpMatrix))continue;let P=(l+.5)/n*2-1,E=(y+.5)/s*2-1,T=[0,0,0],S=[0,0,0];fi(T,P,E,-1,N),fi(S,P,E,1,N);let A=S[0]-T[0],D=S[1]-T[1],R=S[2]-T[2],I=Math.hypot(A,D,R)||1,k=A/I,V=D/I,L=R/I,O={distance:1/0,point:[0,0,0],normal:[0,1,0]};for(let c of p.primitives){if(!c.positions)continue;let F=c.positions,C=c.indices,U=Math.floor(C?C.length/3:F.length/9);for(let H=0;H<U;H++){let j=(C?C[H*3]:H*3)*3,Y=(C?C[H*3+1]:H*3+1)*3,q=(C?C[H*3+2]:H*3+2)*3;ls(T[0],T[1],T[2],k,V,L,F[j],F[j+1],F[j+2],F[Y],F[Y+1],F[Y+2],F[q],F[q+1],F[q+2],O,1e-4)}}if(isFinite(O.distance)){let c=O.point[0],F=O.point[1],C=O.point[2],U=this.modelMatrix,H=U[0]*c+U[4]*F+U[8]*C+U[12],j=U[1]*c+U[5]*F+U[9]*C+U[13],Y=U[2]*c+U[6]*F+U[10]*C+U[14],q=H-v,ne=j-M,ie=Y-m,oe=Math.hypot(q,ne,ie);if(oe<b){Oe(this.normalMatrix,this.modelMatrix);let he=this.normalMatrix,B=O.normal[0],X=O.normal[1],z=O.normal[2],Q=he[0]*B+he[3]*X+he[6]*z,te=he[1]*B+he[4]*X+he[7]*z,K=he[2]*B+he[5]*X+he[8]*z,$=Math.hypot(Q,te,K)||1;Q/=$,te/=$,K/=$,Q*q+te*ne+K*ie>0&&(Q=-Q,te=-te,K=-K);let G=W=>Math.round(W*1e3)/1e3;f=p,b=G(oe),h=[G(H),G(j),G(Y)],d=[G(Q),G(te),G(K)]}}}}if(!f)return null;let g={meshIndex:this.meshes.indexOf(f),meshName:f.name,nodeIndex:f.nodeIndex,distance:b,hitPoint:h,normal:d,screenX:t,screenY:e};if(i){for(let p of xe)p.onMeshSelect?.(this,g);this.opts.onMeshClick&&this.opts.onMeshClick(g),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:g}))}return g}mapStereoPickX(t,e){if(!this.stereoSBS||this.xrSessionActive||e<2)return t;let i=Math.max(1,Math.floor(e*.5)),r=t>=i,n=r?t-i:t,s=r?Math.max(1,e-i):i,a=(n+.5)/s*2-1;return Math.floor((a*.5+1)*.5*e)}setStereoSBS(t){this.stereoSBS=!!t,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let t=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),e=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);mi(this.projMatrix,this.fov,t,.1,e);let i=this.customTarget||this.bounds.center;Lt(this.viewMatrix,Je(this),i,[0,1,0]),Te(this.mvpMatrix,this.projMatrix,this.viewMatrix),Oe(this.normalMatrix,this.modelMatrix)}resize(){let t=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),e=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(e.width*t)),r=Math.max(1,Math.floor(e.height*t));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(t){let e=this.xrSessionActive;if(this.xrSessionActive=t,e&&!t){this.xrDepthState.enabled=!1;for(let i of xe)i.onXRSessionEnd?.(this);if(this.lastTime=ft(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let e of xe)e.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=ft();let t=e=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((e-this.lastTime)/1e3,0),.1);if(this.lastTime=e,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(t))};this.animFrameId=requestAnimationFrame(t)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(t){this.autoRotate=t}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(t){this.autoRotateSpeed=t}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(t){this.autoRotateDelay=Math.max(0,Number(t)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(t=0){this.turntableRotation=Number(t)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let t=Math.cos(this.turntableRotation),e=Math.sin(this.turntableRotation),[i,,r]=this.bounds.center;this.modelRootMatrix.set([t,0,-e,0,0,1,0,0,e,0,t,0,i-(t*i+e*r),0,r-(-e*i+t*r),1])}setVisible(t){this.isVisible=t}update(t){for(let s of xe)s.onUpdate?.(this,t);let e=ft();if(!this.isPointerDown&&this.autoRotate&&e-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let s of xe)s.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),n=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(n-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=n;let s={theta:i,phi:r,zoom:n,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(t,e,i,r,n=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let a=t?.transform?.inverse?.matrix||this.viewMatrix,o=t?.projectionMatrix||this.projMatrix,l=t?.transform?.position,y=l?[l.x,l.y,l.z]:[0,1.6,0];e&&this.modelRootMatrix.set(e),this.render({viewMatrix:a,projMatrix:o,eyePos:y,viewport:r,eye:t?.eye||"none",clear:s>0?!1:t?.eye!=="right",isAR:n})}render(t){if(this.contextLost)return;if(!t&&this.stereoSBS){let _=Math.max(2,this.canvas.width||2),N=Math.max(1,this.canvas.height||1),P=Math.max(1,Math.floor(_*.5)),E=Math.max(1,_-P),T=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),S=this.customTarget||this.bounds.center,[A,D,R]=Je(this),I=Math.cos(this.currTheta),k=-Math.sin(this.currTheta),V=.032;for(let L of[-1,1]){let O=ve(),c=ve(),F=L<0?P:E,C=[A+L*I*V,D,R+L*k*V];mi(O,this.fov,F/N,.1,T),Lt(c,C,[S[0]+L*I*V*.25,S[1],S[2]+L*k*V*.25],[0,1,0]),this.render({viewMatrix:c,projMatrix:O,eyePos:C,viewport:[L<0?0:P,0,F,N],eye:L<0?"left":"right",clear:L<0,isAR:!1})}this.gl.viewport(0,0,_,N);return}let e=this.gl,[i,r,n,s]=t?.viewport||[0,0,this.canvas.width,this.canvas.height];if(e.viewport(i,r,n,s),e.enable(2929),!t||t.clear!==!1){let _=t?.isAR?[0,0,0,0]:this.clearColor;e.clearColor(_[0],_[1],_[2],_[3]),e.clear(16640)}let a=ve(),o=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o;let l=t?.projMatrix??this.projMatrix;Te(a,l,o);let y=ge(),f=y.xrDepthShader,b=cs(this.toneMapping),[h,d,v]=t?t.eyePos:Je(this);for(let _ of xe)_.onBeforeDrawScene?.(this,e,a,[h,d,v],b);let M=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&M===0){y.gpuSceneAccelerator?.hideLayer?.(this);return}let m=t?.eye||"none",u=!t||t.clear!==!1;if(!this.xrSessionActive&&y.gpuSceneAccelerator?.renderScene(this,a,l,o,[h,d,v],b,[i,r,n,s],m,u,!!t?.isAR)){u&&!this.skyboxTexture&&(e.clearColor(0,0,0,0),e.clear(16384));for(let _ of xe)_.name.includes("webgpu")&&_.onAfterRender?.(e,this,a,m,[i,r,n,s],l);return}let g=!1,p=M>0?[...this.backdropMeshes,...this.meshes]:this.meshes,x=(_,N,P,E)=>{N?(e.activeTexture(33984+_),e.bindTexture(3553,N),e.uniform1i(P,_),e.uniform1i(E,1)):e.uniform1i(E,0)},w=_=>{for(let N=0;N<p.length;N++){let P=p[N];if(P.visible===!1)continue;let E=this.selectedMeshNames.has(P.name);if(N<M||P.worldSpace===!0||P.name==="__xr_reticle__")this.modelMatrix.set(P.transform);else{Te(this.modelMatrix,this.modelRootMatrix,P.transform);let I=!t&&(P.extras?.xr?.billboard??P.userData?.xr?.billboard);if(I){let k=this.modelMatrix,V=Math.hypot(k[0],k[1],k[2])||1,L=Math.hypot(k[4],k[5],k[6])||1,O=Math.hypot(k[8],k[9],k[10])||1,c=I==="y"||I==="cylindrical"||I==="capsule",F=h-k[12],C=v-k[14],U=Math.hypot(F,C),H=U>1e-5?F/U:0,j=U>1e-5?C/U:1;k.set(c?[j*V,0,-H*V,0,0,L,0,0,H*O,0,j*O]:[o[0]*V,o[4]*V,o[8]*V,0,o[1]*L,o[5]*L,o[9]*L,0,o[2]*O,o[6]*O,o[10]*O])}}Te(this.mvpMatrix,a,this.modelMatrix),Oe(P.normalMatrix,this.modelMatrix);let T=P.extras?.xr?.stereo||P.userData?.xr?.stereo,S=0,A=0,D=1,R=1;T==="sbs"?(D=.5,S=m==="right"?.5:0):T==="ou"&&(R=.5,A=m==="right"?.5:0);for(let I of P.primitives){let k=!!I.isTransmissive;if(!_&&k){g=!0;continue}if(_&&!k)continue;let V=I.customProgram||this.renderProg,L=I.customUniforms||this.uRender;e.useProgram(V),e.vertexAttrib3f(3,0,0,0),L.uInstanced&&e.uniform1i(L.uInstanced,0),e.uniform1i(L.uToneMapping,b),e.uniform1f(L.uEnvIntensity,this.envIntensity),L.uExposure&&e.uniform1f(L.uExposure,this.exposure),e.uniform3f(L.uCameraPos,h,d,v),e.uniform1f(L.uEmissive,E?1:0),e.uniformMatrix4fv(L.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(L.uModel,!1,this.modelMatrix),e.uniformMatrix3fv(L.uNormalMatrix,!1,P.normalMatrix),L.uUvTransform&&e.uniform4f(L.uUvTransform,S,A,D,R),L.uViewportSize&&e.uniform2f(L.uViewportSize,Math.max(1,n),Math.max(1,s)),f?.bind(e,L,this.xrDepthState,o,[i,r,Math.max(1,n),Math.max(1,s)]),y.shadowMapShader?.bind(e,L,this,P),x(4,this.environmentTexture,L.uEnvironmentMap,L.uHasEnvironmentMap),this.bindLights(L),L.uSectionEnabled&&e.uniform1i(L.uSectionEnabled,0);for(let c of xe)c.onBeforeDrawPrimitive?.(e,V,I,P,this.worldMatrices||[],this.gltf);e.uniform4fv(L.uBaseColor,I.baseColor),e.uniform1f(L.uMetallic,I.metallic),e.uniform1f(L.uRoughness,I.roughness),L.uClearcoat&&e.uniform2f(L.uClearcoat,I.clearcoat??0,I.clearcoatRoughness??.04),x(0,I.texture,L.uBaseColorTexture,L.uHasTexture),x(1,I.metallicRoughnessTexture,L.uMetallicRoughnessTexture,L.uHasMetallicRoughnessTexture),x(2,I.normalTexture,L.uNormalTexture,L.uHasNormalTexture),I.normalTexture&&e.uniform1f(L.uNormalScale,I.normalScale),x(3,I.occlusionTexture,L.uOcclusionTexture,L.uHasOcclusionTexture),I.occlusionTexture&&e.uniform1f(L.uOcclusionStrength,I.occlusionStrength),e.uniform3fv(L.uEmissiveFactor,I.emissiveFactor),x(8,I.emissiveTexture,L.uEmissiveTexture,L.uHasEmissiveTexture),e.bindVertexArray(I.vao);let O=P.instanceMatrices;if(I.instanceCount!==void 0)e.drawElementsInstanced(4,I.indexCount,I.indexType,0,I.instanceCount);else if(O&&O.length>=16&&I.instanced&&L.uInstanced&&L.uViewProj){let c=O.length>>4;e.uniform1i(L.uInstanced,1),e.uniformMatrix4fv(L.uViewProj,!1,a),I.indices?e.drawElementsInstanced(4,I.indexCount,I.indexType,0,c):e.drawArraysInstanced(4,0,I.indexCount,c),e.uniform1i(L.uInstanced,0)}else if(O&&O.length>=16){let c=O.length>>4,F=P.instanceColors,C=ve(),U=new Float32Array(9);for(let H=0;H<c;H++){if(Te(C,this.modelMatrix,O.subarray(H*16,H*16+16)),Te(this.mvpMatrix,a,C),Oe(U,C),e.uniformMatrix4fv(L.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(L.uModel,!1,C),e.uniformMatrix3fv(L.uNormalMatrix,!1,U),F){let j=I.baseColor,Y=H*3;e.uniform4fv(L.uBaseColor,[j[0]*F[Y],j[1]*F[Y+1],j[2]*F[Y+2],j[3]])}mt(e,I)}}else mt(e,I)}}};if(w(!1),g){for(let _ of xe)_.onBeforeTransmissivePass?.(e,this);w(!0)}for(let _ of xe)_.onAfterRender?.(e,this,a,m,[i,r,n,s],l)}disposeMeshListGpuResources(t,e){Ti(this.gl,t,e)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let t=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let e of xe)e.onDestroy?.(t,this);this.environmentTexture&&(t.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&t.deleteProgram(this.renderProg),this.pickProg&&t.deleteProgram(this.pickProg),this.pickFbo&&t.deleteFramebuffer(this.pickFbo),this.pickTexture&&t.deleteTexture(this.pickTexture),this.pickDepth&&t.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};_i.registerPlugin=ns,_i.getRegisteredPlugins=as;function Ss(t){return t+3&-4}var Z=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function $t(t,e){let i=e,r=1;for(;t.has(i);)i=`${e}_${r++}`;return t.add(i),i}function Pi(t,e,i){let r=Math.hypot(t,e,i)||1,n=t/r,s=e/r,a=-(i/r);if(a<-.999999)return[0,1,0,0];let o=Math.sqrt((1+a)*2);return[s/o,-n/o,0,o*.5]}function Ci(t,e=0){let[i,r,n,,s,a,o,,l,y,f,,b,h,d]=Array.from({length:15},(O,c)=>Z(t[e+c],c%5===0?1:0)),v=Math.hypot(i,r,n),M=Math.hypot(s,a,o),m=Math.hypot(l,y,f);i*(a*f-y*o)-s*(r*f-y*n)+l*(r*o-a*n)<0&&(v=-v);let u=Math.abs(v)>1e-8?1/v:0,g=Math.abs(M)>1e-8?1/M:0,p=Math.abs(m)>1e-8?1/m:0,x=i*u,w=r*u,_=n*u,N=s*g,P=a*g,E=o*g,T=l*p,S=y*p,A=f*p,D=x+P+A,R=0,I=0,k=0,V=1;if(D>0){let O=.5/Math.sqrt(D+1);V=.25/O,R=(E-S)*O,I=(T-_)*O,k=(w-N)*O}else if(x>P&&x>A){let O=2*Math.sqrt(Math.max(0,1+x-P-A));O>1e-8&&(V=(E-S)/O,R=.25*O,I=(N+w)/O,k=(T+_)/O)}else if(P>A){let O=2*Math.sqrt(Math.max(0,1+P-x-A));O>1e-8&&(V=(T-_)/O,R=(N+w)/O,I=.25*O,k=(E+S)/O)}else{let O=2*Math.sqrt(Math.max(0,1+A-x-P));O>1e-8&&(V=(w-N)/O,R=(T+_)/O,I=(E+S)/O,k=.25*O)}let L=Math.hypot(R,I,k,V);return L>1e-8&&Number.isFinite(L)?(R/=L,I/=L,k/=L,V/=L):(R=0,I=0,k=0,V=1),{t:[b,h,d],r:[R,I,k,V],s:[v,M,m]}}function Ts(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}var Ee=(t,e,i,r)=>typeof t=="number"&&Number.isFinite(t)?Math.max(e,Math.min(i,t)):r;function Ri(t){let e=t?.audioEmitter??t?.spatialAudio??(typeof t?.audio=="object"&&t.audio&&("preset"in t.audio||"distanceModel"in t.audio||"coneInnerAngle"in t.audio||"maxDistance"in t.audio||"volume"in t.audio)?t.audio:typeof t?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(t.audio)?{preset:t.audio}:void 0);if(!e||typeof e=="object"&&e.enabled===!1)return null;let i=typeof e=="string"?{preset:e}:e,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,n=typeof i.preset=="string"?i.preset:void 0;return!r&&!n?null:{ae:i,src:r,preset:n,volume:Ee(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function As(t){let e=t?.material,i=e?._presetMaps?.map;if(!i||i!==e.map)return null;let r=/^ai_([0-9a-f]{16})_albedo$/.exec(String(i.name??""));return r?r[1]:null}function Qe(t,e){return Ei(t,e)[0]}function Ei(t,e){t.updateMatrixWorld(!0);let i=[],r=0,n=[],s=[],a=[],o=[],l=new Set,y=[],f=[],b=new Map,h=[],d=[],v=[],M=new Map,m=[],u=[],g=[],p=!1;function x(c){let F=b.get(c);if(F!==void 0)return F;F=f.length,b.set(c,F);let C=c,U=C.color?.r??1,H=C.color?.g??1,j=C.color?.b??1,Y=C.opacity??1,q={baseColorFactor:[U,H,j,Y],metallicFactor:C.metalness??0,roughnessFactor:C.roughness??.5},ne={},ie=re=>{if(!re)return;let Se=(typeof re=="string"?re:typeof re.source=="string"?re.source:typeof re.image=="string"?re.image:"").trim();if(!Se||/[\x00-\x1f\x7f\\]|\.\./.test(Se)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(Se)||!Se.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(Se)))return;let le=M.get(Se);if(le===void 0){let me=h.length;h.push({uri:Se}),d.length===0&&d.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),le=v.length,v.push({sampler:0,source:me}),M.set(Se,le)}return{index:le}},oe=C._packPbr?.(),he=ie(C.map);he&&(q.baseColorTexture=he);let B=ie(oe?.mrUri||C.roughnessMap||C.metalnessMap);B&&(q.metallicRoughnessTexture=B);let X=C.map?.avgColor;Array.isArray(X)&&X.length>=3&&(ne.avgColor=[X[0],X[1],X[2]]);let z=ie(oe?.normUri||C.normalMap),Q=C.normalScale,te=oe?.normUri?oe.normScale??1:typeof Q=="number"?Math.max(0,Z(Q,1)):Q?Math.max(0,(Z(Q.x,1)+Z(Q.y,1))*.5):1;z&&te!==1&&(z.scale=te);let K=ie(C.emissiveMap),$=ie(C.aoMap),G=Math.max(0,Math.min(1,Z(C.aoMapIntensity,1)));$&&G!==1&&($.strength=G);let W={name:C.name||"",pbrMetallicRoughness:q,doubleSided:C.side===2||!!C.doubleSided,...Y<1||C.transparent?{alphaMode:"BLEND"}:{},...z?{normalTexture:z}:{},...K?{emissiveTexture:K}:{},...$?{occlusionTexture:$}:{},...Object.keys(ne).length>0?{extras:ne}:{}},J=Math.max(0,Z(C.emissiveIntensity,1)),ae=C.emissive&&(C.emissive.r>0||C.emissive.g>0||C.emissive.b>0);(ae||K&&!C._em&&J>0)&&(W.emissiveFactor=ae?[C.emissive.r*J,C.emissive.g*J,C.emissive.b*J]:[J,J,J]);let se={};C.clearcoat&&C.clearcoat>0&&(se.KHR_materials_clearcoat={clearcoatFactor:C.clearcoat,clearcoatRoughnessFactor:C.clearcoatRoughness||0}),C.sheen&&C.sheen>0&&(se.KHR_materials_sheen={sheenColorFactor:C.sheenColor?[C.sheenColor.r,C.sheenColor.g,C.sheenColor.b]:[1,1,1],sheenRoughnessFactor:C.sheenRoughness||0}),C.transmission&&C.transmission>0&&(se.KHR_materials_transmission={transmissionFactor:C.transmission}),C.thickness&&C.thickness>0&&(se.KHR_materials_volume={thicknessFactor:C.thickness,attenuationDistance:C.attenuationDistance??1/0,attenuationColor:C.attenuationColor?[C.attenuationColor.r,C.attenuationColor.g,C.attenuationColor.b]:[1,1,1]}),C.ior!==void 0&&C.ior!==1.5&&(se.KHR_materials_ior={ior:C.ior}),C.dispersion&&C.dispersion>0&&(se.KHR_materials_dispersion={dispersion:C.dispersion}),C.iridescence&&C.iridescence>0&&(se.KHR_materials_iridescence={iridescenceFactor:C.iridescence,iridescenceIor:C.iridescenceIOR??1.3});let fe=C._serializeTslGraph?.();return fe&&(se.GOOGLE_material_tsl=fe,l.add("GOOGLE_material_tsl")),Object.keys(se).length>0&&(W.extensions=se),f.push(W),F}function w(c,F){let C=new Uint8Array(c.buffer,c.byteOffset,c.byteLength),U=Ss(C.byteLength),H=new Uint8Array(U);H.set(C),i.push(H);let j=n.length;return n.push({buffer:0,byteOffset:r,byteLength:C.byteLength,target:F}),r+=U,j}function _(c,F,C,U,H,j,Y){let q=w(c,C),ne=s.length,ie={bufferView:q,byteOffset:0,componentType:U,count:H,type:F};return j&&(ie.min=j),Y&&(ie.max=Y),s.push(ie),ne}let N=[],P=[],E=new Set([t]),T=[];if(Array.isArray(t.children))for(let c=t.children.length-1;c>=0;c--)T.push({obj:t.children[c],parentKids:P});for(;T.length>0;){let{obj:c,parentKids:F}=T.pop();if(!c||typeof c!="object"||E.has(c))continue;E.add(c),c._bakeAuthorGeometry?.(),ge().materializeDeclarativeGeometry?.(c);let C=!!(c.userData&&(c.userData.xr&&typeof c.userData.xr=="object"&&Object.keys(c.userData.xr).length>0||c.userData.interactivity&&typeof c.userData.interactivity=="object"&&Object.keys(c.userData.interactivity).length>0)),U={name:c.name||(C?`Node_${o.length}`:"")},H=Z(c.position?.x,0),j=Z(c.position?.y,0),Y=Z(c.position?.z,0),q=Z(c.quaternion?.x,0),ne=Z(c.quaternion?.y,0),ie=Z(c.quaternion?.z,0),oe=Z(c.quaternion?.w,1),he=Z(c.scale?.x,1),B=Z(c.scale?.y,1),X=Z(c.scale?.z,1);if((H||j||Y)&&(U.translation=[H,j,Y]),(q||ne||ie||oe!==1)&&(U.rotation=[q,ne,ie,oe]),(he!==1||B!==1||X!==1)&&(U.scale=[he,B,X]),c.visible===!1&&(U.extensions={...U.extensions||{},KHR_node_visibility:{visible:!1}},l.add("KHR_node_visibility")),c.userData&&Object.keys(c.userData).length>0&&(U.extras=JSON.parse(JSON.stringify(c.userData,($,G)=>{if(!($==="__proto__"||$==="prototype"||$==="constructor"))return typeof G=="function"?void 0:G})),c.userData.xr)){let $=Ts(c.userData.xr);U.extensions={...U.extensions||{},MOZ_hubs_components:$,ANDROID_xr_scenecore:$},ge().xrTraitSerializer?.gltfNode(U,c.userData.xr);let G=As(c),W=U.extras?.xr?.material;G&&W&&typeof W=="object"&&!Array.isArray(W)&&(W.textureKey=G),l.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}let z=c,Q=z.isLight||z.color&&z.intensity!==void 0;if(!Q&&(z._castShdSet||z._recvShdSet||c.castShadow||c.receiveShadow)&&(U.extras={...U.extras||{},shadow:{cast:!!c.castShadow,receive:z._recvShdSet?!!c.receiveShadow:!!(c.receiveShadow||c.castShadow)}}),Q){let $=z.matrixWorld?.elements,G=Z($?$[12]:c.position?.x,0),W=Z($?$[13]:c.position?.y,0),J=Z($?$[14]:c.position?.z,0),ae=z.target,se=ae?.parent?ae?.matrixWorld?.elements:void 0,fe=Z(se?se[12]:ae?.position?.x,0),re=Z(se?se[13]:ae?.position?.y,0),Se=Z(se?se[14]:ae?.position?.z,0),le=fe-G,me=re-W,ue=Se-J,ce=Math.hypot(le,me,ue),ye=Math.max(.01,Math.min(Math.PI/2,Z(z.angle,Math.PI/3))),Ce=Math.max(0,Math.min(1,Z(z.penumbra,0))),de=Math.max(0,ye*(1-Ce)),De=Math.max(0,Z(z.distance,0)),Ge=c.type==="directional"||c.type==="spot"||c.type==="point",Ue;if(c.castShadow&&Ge){let Ze=z.shadow,Et=Math.max(256,Math.min(2048,Math.round(Z(Ze?.mapSize?.x??Ze?.mapSize?.width,1024))));Ue={cast:!0,mapSize:Et<=384?256:Et<=768?512:Et<=1536?1024:2048,bias:Ee(Ze?.bias,-.05,.05,-5e-4),normalBias:Ee(Ze?.normalBias,0,.2,.015),radius:Ee(Ze?.radius,0,8,1.5)},p=!0}let Pt=G-fe,Ct=W-re,Rt=J-Se,ot=Math.hypot(Pt,Ct,Rt);u.push({type:c.type,color:[c.color.r,c.color.g,c.color.b],intensity:c.intensity,position:c.type==="directional"?[Pt,Ct,Rt]:[G,W,J],...c.type==="directional"?{direction:ot>1e-6?[Pt/ot,Ct/ot,Rt/ot]:[0,1,0]}:c.type==="spot"?{direction:ce>1e-6?[le/ce,me/ce,ue/ce]:[0,-1,0],outerConeAngle:ye,innerConeAngle:de,range:De}:c.type==="point"?{range:De}:c.type==="hemisphere"&&z.groundColor?{groundColor:[z.groundColor.r,z.groundColor.g,z.groundColor.b]}:{},...Ue?{shadow:Ue}:{}}),Ge&&N.push({node:U,obj:c,px:G,py:W,pz:J,tx:fe,ty:re,tz:Se,dx:le,dy:me,dz:ue,dLen:ce,outerAngle:ye,innerAngle:de,range:De,shadowSpec:Ue})}if(c.geometry){let $=c.geometry,G=$.attributes.position;if(G&&G.count>0){let W=[1/0,1/0,1/0],J=[-1/0,-1/0,-1/0];for(let le=0;le<G.count;le++){let me=G.getX(le),ue=G.getY(le),ce=G.getZ(le);me<W[0]&&(W[0]=me),me>J[0]&&(J[0]=me),ue<W[1]&&(W[1]=ue),ue>J[1]&&(J[1]=ue),ce<W[2]&&(W[2]=ce),ce>J[2]&&(J[2]=ce)}let ae={attributes:{POSITION:_(G.array,"VEC3",34962,5126,G.count,W,J)}};if($.attributes.normal&&(ae.attributes.NORMAL=_($.attributes.normal.array,"VEC3",34962,5126,$.attributes.normal.count)),$.attributes.uv&&(ae.attributes.TEXCOORD_0=_($.attributes.uv.array,"VEC2",34962,5126,$.attributes.uv.count)),$.index){let le=$.index.array instanceof Uint32Array;ae.indices=_($.index.array,"SCALAR",34963,le?5125:5123,$.index.count)}let se=Array.isArray(c.material)?c.material[0]:c.material;se&&(ae.material=x(se));let fe=c.userData?.variants;if(fe&&typeof fe=="object"){let le=new Map;for(let me of Object.keys(fe)){if(!me||me==="__proto__"||me==="constructor"||me==="prototype")continue;let ue=fe[me];if(!ue||typeof ue!="object")continue;let ce=m.indexOf(me);if(ce===-1&&m.length<256&&(ce=m.length,m.push(me)),ce===-1)continue;let ye=x(ue),Ce=le.get(ye);Ce||(Ce=[],le.set(ye,Ce)),Ce.push(ce)}if(le.size>0){let me=[];for(let[ue,ce]of le.entries())me.push({material:ue,variants:ce});ae.extensions={...ae.extensions||{},KHR_materials_variants:{mappings:me}},l.add("KHR_materials_variants")}}let re=c;if(re.isInstancedMesh&&typeof re.count=="number"&&re.count>0&&re.instanceMatrix?.array){let le=Math.min(1e4,Math.floor(re.count)),me=re.instanceMatrix.array,ue=new Float32Array(le*3),ce=new Float32Array(le*4),ye=new Float32Array(le*3);for(let de=0;de<le;de++){let{t:De,r:Ge,s:Ue}=Ci(me,de*16);ue[de*3]=De[0],ue[de*3+1]=De[1],ue[de*3+2]=De[2],ce[de*4]=Ge[0],ce[de*4+1]=Ge[1],ce[de*4+2]=Ge[2],ce[de*4+3]=Ge[3],ye[de*3]=Ue[0],ye[de*3+1]=Ue[1],ye[de*3+2]=Ue[2]}let Ce={TRANSLATION:_(ue,"VEC3",0,5126,le),ROTATION:_(ce,"VEC4",0,5126,le),SCALE:_(ye,"VEC3",0,5126,le)};if(re.instanceColor?.array&&re.instanceColor.array.length>=le*3){let de=new Float32Array(re.instanceColor.array.subarray(0,le*3));Ce._COLOR_0=_(de,"VEC3",0,5126,le)}U.extensions={...U.extensions||{},EXT_mesh_gpu_instancing:{attributes:Ce}},l.add("EXT_mesh_gpu_instancing")}let Se=a.length;a.push({primitives:[ae],name:c.name,...U.extras?{extras:U.extras}:{}}),U.mesh=Se}}let te=o.length;o.push(U),y.push(c),F.push(te);let K=c.children;if(Array.isArray(K)&&K.length>0){let $=[];U.children=$;for(let G=K.length-1;G>=0;G--)T.push({obj:K[G],parentKids:$})}}if(p)for(let c of N){let F=g.length;if(g.push({name:c.obj.name||`Light_${F}`,type:c.obj.type,color:[c.obj.color.r,c.obj.color.g,c.obj.color.b],intensity:c.obj.intensity,...c.range>0&&(c.obj.type==="point"||c.obj.type==="spot")?{range:c.range}:{},...c.obj.type==="spot"?{spot:{innerConeAngle:c.innerAngle,outerConeAngle:c.outerAngle}}:{},...c.shadowSpec?{extras:{shadow:c.shadowSpec}}:{}}),c.node.extensions={...c.node.extensions||{},KHR_lights_punctual:{light:F}},l.add("KHR_lights_punctual"),c.obj.type==="directional"||c.obj.type==="spot"){let C=c.dLen>1e-6?c.dx/c.dLen:0,U=c.dLen>1e-6?c.dy/c.dLen:-1,H=c.dLen>1e-6?c.dz/c.dLen:0;c.node.rotation=Pi(C,U,H),c.obj.type==="directional"&&(c.tx||c.ty||c.tz)&&(c.node.translation=[c.px-c.tx,c.py-c.ty,c.pz-c.tz])}}for(let c=0;c<o.length;c++){let F=o[c];F.children&&F.children.length===0?delete F.children:F.children&&F.children.length>0&&(F.extras?.xr?.lod||F.extensions?.ANDROID_xr_scenecore?.lod||y[c]?.isLOD)&&(F.extensions={...F.extensions||{},MSFT_lod:{ids:[...F.children]}},l.add("MSFT_lod"))}let S=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),A=[];if(typeof S=="function"&&y.length>0){let c=e?.duration??4,F=e?.fps??15,C=Math.max(2,Math.round(c*F)+1),U=new Float32Array(C),H=y.map(B=>[Z(B.position?.x,0),Z(B.position?.y,0),Z(B.position?.z,0),Z(B.quaternion?.x,0),Z(B.quaternion?.y,0),Z(B.quaternion?.z,0),Z(B.quaternion?.w,1),Z(B.scale?.x,1),Z(B.scale?.y,1),Z(B.scale?.z,1)]),j=y.map(()=>new Float32Array(C*3)),Y=y.map(()=>new Float32Array(C*4)),q=y.map(()=>new Float32Array(C*3));for(let B=0;B<C;B++){let X=B/(C-1)*c;U[B]=X;try{S(X)}catch{}for(let z=0;z<y.length;z++){let Q=y[z];j[z][B*3]=Z(Q.position?.x,0),j[z][B*3+1]=Z(Q.position?.y,0),j[z][B*3+2]=Z(Q.position?.z,0);let te=Z(Q.quaternion?.x,0),K=Z(Q.quaternion?.y,0),$=Z(Q.quaternion?.z,0),G=Z(Q.quaternion?.w,1),W=Math.hypot(te,K,$,G)||1;if(te/=W,K/=W,$/=W,G/=W,B>0){let J=(B-1)*4,ae=Y[z];ae[J]*te+ae[J+1]*K+ae[J+2]*$+ae[J+3]*G<0&&(te=-te,K=-K,$=-$,G=-G)}Y[z][B*4]=te,Y[z][B*4+1]=K,Y[z][B*4+2]=$,Y[z][B*4+3]=G,q[z][B*3]=Z(Q.scale?.x,1),q[z][B*3+1]=Z(Q.scale?.y,1),q[z][B*3+2]=Z(Q.scale?.z,1)}}for(let B=0;B<y.length;B++){let X=y[B],z=H[B];X.position?.set(z[0],z[1],z[2]),X.quaternion?.set(z[3],z[4],z[5],z[6]),X.scale?.set(z[7],z[8],z[9])}t.updateMatrixWorld(!0);let ne=null,ie=()=>(ne===null&&(ne=_(U,"SCALAR",0,5126,C,[0],[c])),ne),oe=[],he=[];for(let B=0;B<y.length;B++){let X=H[B],z=(te,K,$)=>te.some((G,W)=>Math.abs(G-X[$+W%K])>1e-4),Q=(te,K,$,G)=>{te&&he.push({sampler:oe.push({input:ie(),interpolation:"LINEAR",output:_(K,$,0,5126,C)})-1,target:{node:B,path:G}})};Q(z(j[B],3,0),j[B],"VEC3","translation"),Q(z(Y[B],4,3),Y[B],"VEC4","rotation"),Q(z(q[B],3,7),q[B],"VEC3","scale")}he.length>0&&A.push({name:"ProceduralLoop",samplers:oe,channels:he})}let D=is(o,a,t.userData),R=[],I=[],k=[];for(let c=0;c<o.length;c++){let F=o[c],C=Ri(F.extras?.xr);if(!C)continue;let{ae:U,src:H,preset:j,volume:Y,loop:q,isGlobal:ne}=C,ie=F.name||`Node_${c}`,oe=I.length;I.push({name:`${ie}_source`,gain:Y,loop:q,autoPlay:typeof U.autoplay=="boolean"?U.autoplay:!0,...H!==void 0?{audio:R.push({uri:H})-1}:{},...j?{extras:{preset:j,pitch:Ee(U.pitch,.25,4,1)}}:{}});let he=k.length,B=Ee(U.refDistance,.05,100,1),X=Ee(U.coneInnerAngle,0,360,360),z=Ee(U.coneOuterAngle,X,360,360);k.push({name:`${ie}_emitter`,type:ne?"global":"positional",gain:Y,sources:[oe],...ne?{}:{positional:{distanceModel:U.distanceModel==="linear"||U.distanceModel==="exponential"?U.distanceModel:"inverse",refDistance:B,maxDistance:Ee(U.maxDistance,B,500,Math.max(B,25)),rolloffFactor:Ee(U.rolloffFactor,0,10,1),coneInnerAngle:+(X*Math.PI/180).toFixed(6),coneOuterAngle:+(z*Math.PI/180).toFixed(6),coneOuterGain:Ee(U.coneOuterGain,0,1,0)}}}),F.extensions={...F.extensions||{},KHR_audio_emitter:{emitter:he}},l.add("KHR_audio_emitter")}let V={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity,...u.length>0?{lights:u}:{}}},scenes:[{nodes:P}],scene:0,nodes:o,meshes:a,materials:f,...h.length>0?{images:h}:{},...d.length>0?{samplers:d}:{},...v.length>0?{textures:v}:{},accessors:s,bufferViews:n,buffers:[{byteLength:r}],...A.length>0?{animations:A}:{},...D||l.size>0?{extensionsUsed:[...D?["KHR_interactivity"]:[],...l]}:{},...D||m.length>0||k.length>0||g.length>0?{extensions:{...D?{KHR_interactivity:D}:{},...m.length>0?{KHR_materials_variants:{variants:m.map(c=>({name:c}))}}:{},...k.length>0?{KHR_audio_emitter:{...R.length>0?{audio:R}:{},sources:I,emitters:k}}:{},...g.length>0?{KHR_lights_punctual:{lights:g}}:{}}}:{}},L=new Uint8Array(r),O=0;for(let c of i)L.set(c,O),O+=c.byteLength;return[{gltf:V,bin:L.buffer,lights:u,environmentIntensity:t.environmentIntensity},y]}function Vt(t){return new TextEncoder().encode(t)}function pt(t,e){let{gltf:i,bin:r}=Qe(t,e),n=JSON.stringify(i),s=Vt(n),a=(4-s.byteLength%4)%4,o=s.byteLength+a,l=20+o+8+r.byteLength,y=new Uint8Array(l),f=new DataView(y.buffer);f.setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,l,!0),f.setUint32(12,o,!0),f.setUint32(16,1313821514,!0),y.set(s,20);for(let h=0;h<a;h++)y[20+s.byteLength+h]=32;let b=20+o;return f.setUint32(b,r.byteLength,!0),f.setUint32(b+4,5130562,!0),y.set(new Uint8Array(r),b+8),y}function _s(t,e){let[i,r]=Ei(t,e);return Li(i,r)}function Li(t,e){let i=[],r=t.gltf,n=ge().decoders.get("meshopt");n&&typeof n.decodeBufferViews=="function"&&n.decodeBufferViews(r,t);let s=t.bin,a=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),o=r.accessors||[],l=r.bufferViews||[],y=r.materials||[],f=r.meshes||[],b=r.nodes||[],h=r.textures||[],d=r.images||[],v=r.samplers||[],M=new Set,m=y.map((P,E)=>$t(M,et(P?.name,`Material_${E}`))),u=new Map;function g(P){let E=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(P);if(!E)return null;let T=E[2].replace(/\s+/g,""),S=T.endsWith("==")?2:T.endsWith("=")?1:0,A=new Uint8Array((T.length*3>>2)-S),D=I=>{let k=T.charCodeAt(I);return k>96?k-71:k>64?k-65:k>47?k+4:k===43?62:k===47?63:0},R=0;for(let I=0;I<T.length;I+=4){let k=D(I)<<18|D(I+1)<<12|D(I+2)<<6|D(I+3);A[R++]=k>>16&255,R<A.length&&(A[R++]=k>>8&255),R<A.length&&(A[R++]=k&255)}return A}function p(P,E,T){let S=P?.index;if(typeof S!="number")return;let A=h[S],D=A?.source;if(typeof D!="number"||!d[D])return;let R=u.get(D);if(R===void 0){R=null;let V=d[D],L=null;if(typeof V.bufferView=="number"){let O=l[V.bufferView],c=O?.byteOffset||0,F=O?.byteLength||0;O&&F>0&&c>=0&&c+F<=a.byteLength&&(L=new Uint8Array(a,c,F))}else typeof V.uri=="string"&&(L=g(V.uri));if(L&&L.byteLength>0){let O=L[0]===255&&L[1]===216&&L[2]===255||!(L[0]===137&&L[1]===80)&&/jpe?g/i.test(V.mimeType||V.uri||"");R={file:`texture_${D}.${O?"jpg":"png"}`,data:L}}u.set(D,R)}if(!R)return;let I=typeof A.sampler=="number"?v[A.sampler]:void 0,k=V=>V===33071?"clamp":V===33648?"mirror":"repeat";return{file:R.file,data:R.data,wrapS:k(I?.wrapS),wrapT:k(I?.wrapT),...E?{scale:E}:{},...T?{bias:T}:{}}}function x(P){let E=o[P];if(!E)throw new Error(`Accessor ${P} not found`);let T=l[E.bufferView||0],S=(T.byteOffset||0)+(E.byteOffset||0),A=T.byteLength||0;return{acc:E,buffer:a.slice(S,S+A)}}function w(P,E,T,S){let A=[],D=f[P];if(!D)return A;let R=D.primitives||[];for(let I=0;I<R.length;I++){let k=R[I],V=k.attributes?.POSITION;if(V===void 0)continue;let{acc:L,buffer:O}=x(V),c=new Float32Array(O,0,L.count*3),F,C=k.attributes?.NORMAL;if(C!==void 0){let{acc:K,buffer:$}=x(C),G=new Float32Array($,0,K.count*3);F=new Float32Array(G.length);for(let W=0;W<K.count;W++){let J=G[W*3],ae=G[W*3+1],se=G[W*3+2],fe=Math.hypot(J,ae,se)||1;F[W*3]=J/fe,F[W*3+1]=ae/fe,F[W*3+2]=se/fe}}let U,H=k.attributes?.TEXCOORD_0;if(H!==void 0){let{acc:K,buffer:$}=x(H);U=new Float32Array($,0,K.count*2)}let j;if(k.indices!==void 0){let{acc:K,buffer:$}=x(k.indices);j=K.componentType===5125?new Uint32Array($,0,K.count):new Uint16Array($,0,K.count);let G=L.count;for(let W of j)if(W>=G)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${G}).`)}else{let K=L.count;j=K>65535?new Uint32Array(K):new Uint16Array(K);for(let $=0;$<K;$++)j[$]=$}let Y="DefaultMaterial",q=[1,1,1],ne=.5,ie=0,oe=0,he=0,B=1.5,X=1,z=[0,0,0],Q,te={};if(k.material!==void 0&&y[k.material]){let K=y[k.material];Y=m[k.material]||`Material_${k.material}`;let $=K.pbrMetallicRoughness||{},G=(de,De)=>Array.isArray(de)&&de.length>=3?[de[0],de[1],de[2]]:De;q=G($.baseColorFactor,[1,1,1]);let W=Array.isArray($.baseColorFactor)&&typeof $.baseColorFactor[3]=="number"?$.baseColorFactor[3]:1,J=q[0]!==1||q[1]!==1||q[2]!==1||W!==1,ae=p($.baseColorTexture,J?[q[0],q[1],q[2],W]:void 0),se=K.extras?.avgColor;!ae&&Array.isArray(se)&&se.length>=3&&(q=[q[0]*se[0],q[1]*se[1],q[2]*se[2]]),typeof $.roughnessFactor=="number"&&(ne=$.roughnessFactor),typeof $.metallicFactor=="number"&&(ie=$.metallicFactor);let fe=typeof $.roughnessFactor=="number"?$.roughnessFactor:1,re=typeof $.metallicFactor=="number"?$.metallicFactor:1,Se=p($.metallicRoughnessTexture,fe!==1||re!==1?[1,fe,re,1]:void 0);z=G(K.emissiveFactor,[0,0,0]);let le=(z[0]>0||z[1]>0||z[2]>0)&&(z[0]!==1||z[1]!==1||z[2]!==1)?[z[0],z[1],z[2],1]:void 0,me=p(K.emissiveTexture,le),ue=typeof K.normalTexture?.scale=="number"?K.normalTexture.scale:1,ce=p(K.normalTexture,[2*ue,2*ue,2,1],[-ue,-ue,-1,0]),ye=typeof K.occlusionTexture?.strength=="number"?K.occlusionTexture.strength:1,Ce=ye!==1?p(K.occlusionTexture,[ye,ye,ye,1],[1-ye,1-ye,1-ye,0]):p(K.occlusionTexture);(ae||Se||ce||me||Ce)&&(Q=[ae,Se,ce,me,Ce]),te=K.extensions||{},te.KHR_materials_clearcoat&&(oe=te.KHR_materials_clearcoat.clearcoatFactor??0,he=te.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof te.KHR_materials_ior?.ior=="number"&&(B=te.KHR_materials_ior.ior),X=W*(1-(te.KHR_materials_transmission?.transmissionFactor??0))}A.push({name:R.length>1?`${E}_p${I}`:E,positions:c,indices:j,normals:F,uvs:U,materialName:Y,color:q,roughness:ne,metallic:ie,clearcoat:oe,clearcoatRoughness:he,ior:B,opacity:X,emissiveColor:z,...Q?{textures:Q}:{},...te.GOOGLE_material_tsl?{tslGraph:te.GOOGLE_material_tsl}:{},xrTraits:T||D.extras?.xr,...S?{invisible:!0}:{}})}return A}if(b.length>0){let P=new Float32Array(0),E=new Uint16Array(0),T=(c,F)=>{if(c===void 0)return null;let{acc:C,buffer:U}=x(c);return new Float32Array(U,0,C.count*F)},S=(c,F)=>Array.isArray(c)&&c.length>=3?[Z(c[0],F),Z(c[1],F),Z(c[2],F)]:[F,F,F],A=(c,F,C)=>c&&c.length>=(F+1)*3?[c[F*3],c[F*3+1],c[F*3+2]]:C,D=(c,F,C)=>c&&c.length>=(F+1)*4?[c[F*4],c[F*4+1],c[F*4+2],c[F*4+3]]:C,R=new Map,I=r.animations?.[0];if(I&&Array.isArray(I.channels)&&Array.isArray(I.samplers))for(let c of I.channels){let F=I.samplers[c?.sampler],C=c?.target?.node,U=c?.target?.path;if(!F||typeof C!="number"||F.input===void 0)continue;let H=R.get(C);H||(H={input:F.input},R.set(C,H)),U==="translation"?H.t=F.output:U==="rotation"?H.r=F.output:U==="scale"&&(H.s=F.output)}let k=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(k)||k.length===0){let c=new Set;for(let F of b)if(Array.isArray(F?.children))for(let C of F.children)c.add(C);k=[];for(let F=0;F<b.length;F++)c.has(F)||k.push(F);k.length===0&&(k=[0])}let V=new Set,L=[],O=(c,F)=>{if(Array.isArray(c))for(let C=c.length-1;C>=0;C--)L.push({idx:c[C],out:F})};for(O(k,i);L.length>0;){let{idx:c,out:F}=L.pop();if(typeof c!="number"||c<0||c>=b.length||V.has(c))continue;V.add(c);let C=b[c];if(!C)continue;let U=[0,0,0],H=[0,0,0,1],j=[1,1,1];if(Array.isArray(C.matrix)&&C.matrix.length===16){let X=Ci(C.matrix);U=X.t,H=X.r,j=X.s}else U=S(C.translation,0),Array.isArray(C.rotation)&&C.rotation.length>=4&&(H=[Z(C.rotation[0],0),Z(C.rotation[1],0),Z(C.rotation[2],0),Z(C.rotation[3],1)]),j=S(C.scale,1);let Y,q=R.get(c);if(q){let X=T(q.input,1);if(X&&X.length>0){let z=T(q.t,3),Q=T(q.r,4),te=T(q.s,3),K=Array.from(X),$=[],G=[],W=[];for(let J=0;J<X.length;J++)$.push(A(z,J,U)),G.push(D(Q,J,H)),W.push(A(te,J,j));Y={times:K,translations:$,rotations:G,scales:W}}}let ne=Array.isArray(C.children)?C.children:[],ie=typeof C.mesh=="number"&&C.mesh>=0&&C.mesh<f.length,oe=e?.[c]?.userData?.xr??C.extras?.xr;if(!ie&&ne.length===0&&(C.camera!==void 0||C.extensions?.KHR_lights_punctual||!C.name&&!C.extras&&!oe&&!Y))continue;let he=(X,z,Q)=>({name:X,positions:P,indices:E,isXform:!0,xrTraits:oe,timeSamples:Y,translation:U,rotation:H,scale:j,children:z,...Q?{invisible:!0}:{}}),B=C.visible===!1||C.extensions?.KHR_node_visibility?.visible===!1||e?.[c]?.visible===!1;if(ie){let X=C.name||f[C.mesh]?.name||`Mesh_${c}`,z=w(C.mesh,X,oe,B),Q=e?.[c],te=!!(Q?._castShdSet||Q?._recvShdSet),K=typeof C.extras?.shadow?.cast=="boolean"?C.extras.shadow.cast:te?!!Q?.castShadow:void 0;if(K!==void 0)for(let G of z)G.castShadow=K;let $=C.extensions?.EXT_mesh_gpu_instancing?.attributes;if($&&typeof $=="object"&&z.length>0){let G=T($.TRANSLATION,3),W=T($.ROTATION,4),J=T($.SCALE,3),ae=T($._COLOR_0,3),se=Math.min(1e3,G?G.length/3:W?W.length/4:J?J.length/3:0);if(se>0){let fe=[];for(let re=0;re<se;re++){let Se=A(G,re,[0,0,0]),le=D(W,re,[0,0,0,1]),me=A(J,re,[1,1,1]);for(let ue of z){let ce=ue.color||[.8,.8,.8],ye=ae&&ae.length>=(re+1)*3;fe.push({...ue,name:`${ue.name}_${re}`,materialName:ye?`${ue.materialName}_inst_${re}`:ue.materialName,color:ye?[ce[0]*ae[re*3],ce[1]*ae[re*3+1],ce[2]*ae[re*3+2]]:ue.color,translation:Se,rotation:le,scale:me})}}O(ne,fe),F.push(he(X,fe,B));continue}}if(z.length===1)z[0].translation=U,z[0].rotation=H,z[0].scale=j,z[0].timeSamples=Y,ne.length>0&&(z[0].children=[],O(ne,z[0].children)),F.push(z[0]);else{let G=[...z];O(ne,G),F.push(he(X,G,B))}}else{let X=[];O(ne,X),F.push(he(C.name||`Group_${c}`,X,B))}}}else for(let P=0;P<f.length;P++){let E=f[P].name||`Mesh_${P}`;i.push(...w(P,E,f[P].extras?.xr))}let _=(Array.isArray(t.lights)&&t.lights.length>0?t.lights:void 0)??vi(r)??(Array.isArray(r?.asset?.extras?.lights)?r.asset.extras.lights:[]),N=[];for(let P=0;P<_.length;P++){let E=_[P];E?.shadow?.cast&&(E.type==="directional"||E.type==="spot"||E.type==="point")&&N.push({name:`Light_${P}`,type:E.type,color:E.color,intensity:E.intensity,position:E.position,direction:E.direction,range:E.range,innerConeAngle:E.innerConeAngle,outerConeAngle:E.outerConeAngle,shadow:E.shadow})}return N.length>0&&(i.__usdaShadowLights=N),i}function et(t,e){if(!t||typeof t!="string")return e;let i=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||e}function dt(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function be(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}var Le=(t,e,i)=>`(${be(t)}, ${be(e)}, ${be(i)})`,tt=(t,e,i,r)=>`(${be(t)}, ${be(e)}, ${be(i)}, ${be(r)})`;function Ni(t){let e=t.length/3,i=new Array(e);for(let r=0;r<e;r++)i[r]=Le(t[r*3],t[r*3+1],t[r*3+2]);return i.join(", ")}function Ps(t,e){let i=new Array(e);for(let r=0;r<e;r++)i[r]=`(${be(t[r*2])}, ${be(1-t[r*2+1])})`;return i.join(", ")}function Cs(t){return Array.from(t).join(", ")}function Rs(t,e){let i=(e??t.__usdaShadowLights??[]).filter(m=>m?.shadow?.cast),r=new Map,n=0,s=null,a=[...t];for(;a.length>0;){let m=a.pop();if(!m.isXform&&m.positions&&m.positions.length>0){let u=et(m.materialName,"DefaultMaterial");r.has(u)||r.set(u,{color:m.color||[1,1,1],roughness:m.roughness??.5,metallic:m.metallic??0,clearcoat:m.clearcoat??0,clearcoatRoughness:m.clearcoatRoughness??0,ior:m.ior??1.5,opacity:m.opacity??1,emissiveColor:m.emissiveColor||[0,0,0],textures:m.textures,tslGraph:m.tslGraph})}if(m.timeSamples&&m.timeSamples.times.length>0){let u=m.timeSamples.times[m.timeSamples.times.length-1];u>n&&(n=u)}else m.tslGraph&&n<=0&&JSON.stringify(m.tslGraph).includes('"time"')&&(n=60);if(m.xrTraits?.anchor&&!s&&(s=m.xrTraits.anchor==="vertical"||m.xrTraits.anchor==="wall"?"vertical":"horizontal"),m.children)for(let u=m.children.length-1;u>=0;u--)a.push(m.children[u])}let o="";n>0&&(o=`startTimeCode = 0
|
|
215
|
+
endTimeCode = ${be(n)}
|
|
251
216
|
timeCodesPerSecond = 1.0
|
|
252
|
-
`);let
|
|
253
|
-
uniform token preliminary:planeAnchoring:alignment = "${
|
|
254
|
-
`);let
|
|
217
|
+
`);let l="";s&&(l=`uniform token preliminary:anchoring:type = "plane"
|
|
218
|
+
uniform token preliminary:planeAnchoring:alignment = "${s}"
|
|
219
|
+
`);let y=`#usda 1.0
|
|
255
220
|
(
|
|
256
221
|
defaultPrim = "Root"
|
|
257
222
|
metersPerUnit = 1.0
|
|
258
223
|
upAxis = "Y"
|
|
259
|
-
${
|
|
224
|
+
${o})
|
|
260
225
|
|
|
261
226
|
def Xform "Root" (
|
|
262
227
|
kind = "component"
|
|
263
228
|
)
|
|
264
229
|
{
|
|
265
|
-
${
|
|
230
|
+
${l}def Scope "Materials"
|
|
266
231
|
{
|
|
267
|
-
`;for(let[
|
|
268
|
-
float inputs:roughness${
|
|
269
|
-
float inputs:roughness = ${
|
|
270
|
-
`,
|
|
271
|
-
`),
|
|
272
|
-
`),
|
|
273
|
-
`),
|
|
274
|
-
`:(
|
|
275
|
-
`),
|
|
276
|
-
`),
|
|
277
|
-
`);let
|
|
232
|
+
`;for(let[m,u]of r.entries()){let[g,p,x]=u.color,[w,_,N]=u.emissiveColor,P=`/Root/Materials/${m}`,[E,T,S,A,D]=u.textures||[],R=(F,C)=>`.connect = <${P}/${F}.outputs:${C}>`,I=E?`color3f inputs:diffuseColor${R("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${Le(g,p,x)}`,k=T?`float inputs:metallic${R("MetallicRoughnessTexture","b")}
|
|
233
|
+
float inputs:roughness${R("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${be(u.metallic)}
|
|
234
|
+
float inputs:roughness = ${be(u.roughness)}`,V="";u.clearcoat>0&&(V+=`float inputs:clearcoat = ${be(u.clearcoat)}
|
|
235
|
+
`,V+=`float inputs:clearcoatRoughness = ${be(u.clearcoatRoughness)}
|
|
236
|
+
`),u.ior!==1.5&&(V+=`float inputs:ior = ${be(u.ior)}
|
|
237
|
+
`),u.opacity<1&&(V+=`float inputs:opacity = ${be(u.opacity)}
|
|
238
|
+
`),A?V+=`color3f inputs:emissiveColor${R("EmissiveTexture","rgb")}
|
|
239
|
+
`:(w>0||_>0||N>0)&&(V+=`color3f inputs:emissiveColor = ${Le(w,_,N)}
|
|
240
|
+
`),S&&(V+=`normal3f inputs:normal${R("NormalTexture","rgb")}
|
|
241
|
+
`),D&&(V+=`float inputs:occlusion${R("OcclusionTexture","r")}
|
|
242
|
+
`);let L="";if(E||T||S||A||D){L+=`def Shader "PrimvarReader"
|
|
278
243
|
{
|
|
279
244
|
uniform token info:id = "UsdPrimvarReader_float2"
|
|
280
245
|
string inputs:varname = "st"
|
|
281
246
|
float2 outputs:result
|
|
282
247
|
}
|
|
283
|
-
`;let
|
|
284
|
-
`:"",
|
|
285
|
-
`:"";
|
|
248
|
+
`;let F=(C,U,H,j)=>{if(!U)return;let Y=U.scale?`float4 inputs:scale = ${tt(U.scale[0],U.scale[1],U.scale[2],U.scale[3])}
|
|
249
|
+
`:"",q=U.bias?`float4 inputs:bias = ${tt(U.bias[0],U.bias[1],U.bias[2],U.bias[3])}
|
|
250
|
+
`:"";L+=`def Shader "${C}"
|
|
286
251
|
{
|
|
287
252
|
uniform token info:id = "UsdUVTexture"
|
|
288
|
-
asset inputs:file = @${
|
|
289
|
-
float2 inputs:st${
|
|
290
|
-
token inputs:sourceColorSpace = "${
|
|
291
|
-
token inputs:wrapS = "${
|
|
292
|
-
token inputs:wrapT = "${
|
|
293
|
-
${
|
|
294
|
-
`};
|
|
295
|
-
`),
|
|
253
|
+
asset inputs:file = @${dt(U.file)}@
|
|
254
|
+
float2 inputs:st${R("PrimvarReader","result")}
|
|
255
|
+
token inputs:sourceColorSpace = "${H}"
|
|
256
|
+
token inputs:wrapS = "${U.wrapS||"repeat"}"
|
|
257
|
+
token inputs:wrapT = "${U.wrapT||"repeat"}"
|
|
258
|
+
${Y}${q}${j}}
|
|
259
|
+
`};F("DiffuseTexture",E,"sRGB",`float3 outputs:rgb
|
|
260
|
+
`),F("MetallicRoughnessTexture",T,"raw",`float outputs:g
|
|
296
261
|
float outputs:b
|
|
297
|
-
`),
|
|
298
|
-
`),
|
|
299
|
-
`),
|
|
300
|
-
`)}
|
|
262
|
+
`),F("NormalTexture",S,"raw",`float3 outputs:rgb
|
|
263
|
+
`),F("EmissiveTexture",A,"sRGB",`float3 outputs:rgb
|
|
264
|
+
`),F("OcclusionTexture",D,"raw",`float outputs:r
|
|
265
|
+
`)}let O=`${I}
|
|
266
|
+
${k}
|
|
267
|
+
${V}`,c=u.tslGraph&&ge().tslUsdzSerializer?.(u.tslGraph,m,O);c&&(O=c.surfaceInputsUsda||O,L+=c.nodeGraphUsda),y+=`def Material "${m}"
|
|
301
268
|
{
|
|
302
269
|
def Shader "PBRShader"
|
|
303
270
|
{
|
|
304
271
|
uniform token info:id = "UsdPreviewSurface"
|
|
305
|
-
${
|
|
306
|
-
${y}
|
|
307
|
-
${F}token outputs:surface
|
|
272
|
+
${O}token outputs:surface
|
|
308
273
|
}
|
|
309
|
-
token outputs:surface${
|
|
310
|
-
${
|
|
311
|
-
`}
|
|
274
|
+
token outputs:surface${R("PBRShader","surface")}
|
|
275
|
+
${L}}
|
|
276
|
+
`}y+=`}
|
|
312
277
|
def Scope "Meshes"
|
|
313
278
|
{
|
|
314
|
-
`;let
|
|
279
|
+
`;let f=(m,u,g)=>{let p=[];u&&p.push('"MaterialBindingAPI"');let x=!!(m?.rigidBody&&m.rigidBody!=="none"&&(typeof m.rigidBody!="object"||m.rigidBody.enabled!==!1)),w=!!(m?.physics&&m.physics!=="none"||x);w&&p.push(...x?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let _=[];p.length>0&&_.push(`prepend apiSchemas = [${p.join(", ")}]`);let N=ge().xrTraitSerializer;if(m){let A=N?.usdLines(m,dt)??[];if(!A.length)for(let D of["grab","billboard","follow","anchor","physics"]){let R=D==="follow"&&typeof m.follow=="object"?m.follow.mode??"head":m[D];R!==void 0&&A.push(`string ${D} = "${dt(R)}"`)}A.length>0&&_.push(`customData = {
|
|
315
280
|
dictionary xr = {
|
|
316
|
-
${
|
|
281
|
+
${A.join(`
|
|
317
282
|
`)}
|
|
318
283
|
}
|
|
319
|
-
}`)}let
|
|
320
|
-
${
|
|
284
|
+
}`)}let P=_.length>0?` (
|
|
285
|
+
${_.join(`
|
|
321
286
|
`)}
|
|
322
|
-
)`:"",
|
|
323
|
-
`:"";if(
|
|
324
|
-
bool physics:kinematicEnabled = ${
|
|
287
|
+
)`:"",E=g?`uniform token visibility = "invisible"
|
|
288
|
+
`:"";if(w){let A=m?.rigidBody??m?.physics,D=A?.body??A?.mode??A;E+=`bool physics:rigidBodyEnabled = true
|
|
289
|
+
bool physics:kinematicEnabled = ${D==="static"||D==="kinematic"}
|
|
325
290
|
bool physics:collisionEnabled = true
|
|
326
|
-
`,
|
|
327
|
-
`)}let
|
|
291
|
+
`,A?.mass>0&&Number.isFinite(A.mass)&&(E+=`float physics:mass = ${be(A.mass)}
|
|
292
|
+
`)}let T=Ri(m),S=(T?`def SpatialAudio "AudioEmitter"
|
|
328
293
|
{
|
|
329
|
-
${
|
|
330
|
-
`:""}uniform token inputs:auralMode = "${
|
|
331
|
-
uniform token inputs:playbackMode = "${
|
|
332
|
-
double gain = ${
|
|
294
|
+
${T.src?`asset inputs:file = @${dt(T.src)}@
|
|
295
|
+
`:""}uniform token inputs:auralMode = "${T.isGlobal?"nonSpatial":"spatial"}"
|
|
296
|
+
uniform token inputs:playbackMode = "${T.loop?"loopFromStart":"onceFromStart"}"
|
|
297
|
+
double gain = ${be(T.volume)}
|
|
333
298
|
}
|
|
334
|
-
`:"";return{header:
|
|
335
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
336
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
299
|
+
`:"")+(m?N?.usdPrims?.(m)??"":"");return{header:P,body:E,tail:S}},b=m=>{if(m.timeSamples&&m.timeSamples.times.length>0){let _=m.timeSamples,N=(S,A,D)=>_.times.map((R,I)=>`${be(R)}: ${D(S?.[I]||A)}`).join(", "),P=N(_.translations,[0,0,0],S=>Le(S[0],S[1],S[2])),E=N(_.rotations,[0,0,0,1],S=>{let A=Math.hypot(S[0],S[1],S[2],S[3])||1;return tt(S[3]/A,S[0]/A,S[1]/A,S[2]/A)}),T=N(_.scales,[1,1,1],S=>Le(S[0],S[1],S[2]));return`double3 xformOp:translate.timeSamples = { ${P} }
|
|
300
|
+
quatf xformOp:orient.timeSamples = { ${E} }
|
|
301
|
+
double3 xformOp:scale.timeSamples = { ${T} }
|
|
337
302
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
338
|
-
`}let
|
|
339
|
-
`,
|
|
340
|
-
`,
|
|
341
|
-
`,
|
|
342
|
-
`),
|
|
343
|
-
int[] faceVertexCounts = [${
|
|
344
|
-
int[] faceVertexIndices = [${
|
|
345
|
-
point3f[] points = [${
|
|
346
|
-
`;return
|
|
303
|
+
`}let u=[],g="",p=m.translation;p&&(Math.abs(p[0])>1e-7||Math.abs(p[1])>1e-7||Math.abs(p[2])>1e-7)&&(g+=`double3 xformOp:translate = ${Le(p[0],p[1],p[2])}
|
|
304
|
+
`,u.push('"xformOp:translate"'));let x=m.rotation;if(x){let _=Math.hypot(x[0],x[1],x[2],x[3])||1,N=x[0]/_,P=x[1]/_,E=x[2]/_,T=x[3]/_;(1-Math.abs(T)>1e-7||Math.hypot(N,P,E)>1e-7)&&(g+=`quatf xformOp:orient = ${tt(T,N,P,E)}
|
|
305
|
+
`,u.push('"xformOp:orient"'))}let w=m.scale;return w&&(Math.abs(w[0]-1)>1e-7||Math.abs(w[1]-1)>1e-7||Math.abs(w[2]-1)>1e-7)&&(g+=`float3 xformOp:scale = ${Le(w[0],w[1],w[2])}
|
|
306
|
+
`,u.push('"xformOp:scale"')),u.length>0&&(g+=`uniform token[] xformOpOrder = [${u.join(", ")}]
|
|
307
|
+
`),g},h=m=>{let u=m.positions.length/3,g=1/0,p=1/0,x=1/0,w=-1/0,_=-1/0,N=-1/0;for(let A=0;A<u;A++){let D=m.positions[A*3],R=m.positions[A*3+1],I=m.positions[A*3+2];D<g&&(g=D),D>w&&(w=D),R<p&&(p=R),R>_&&(_=R),I<x&&(x=I),I>N&&(N=I)}isFinite(g)||(g=p=x=-1,w=_=N=1);let P=Math.floor(m.indices.length/3),E=et(m.materialName,"DefaultMaterial"),T=P>0?P===1?"3":"3, ".repeat(P-1)+"3":"",S=`float3[] extent = [${Le(g,p,x)}, ${Le(w,_,N)}]
|
|
308
|
+
int[] faceVertexCounts = [${T}]
|
|
309
|
+
int[] faceVertexIndices = [${Cs(m.indices)}]
|
|
310
|
+
point3f[] points = [${Ni(m.positions)}]
|
|
311
|
+
`;return m.normals&&m.normals.length===m.positions.length&&(S+=`normal3f[] normals = [${Ni(m.normals)}] (
|
|
347
312
|
interpolation = "vertex"
|
|
348
313
|
)
|
|
349
|
-
`),
|
|
314
|
+
`),m.uvs&&m.uvs.length===u*2&&(S+=`texCoord2f[] primvars:st = [${Ps(m.uvs,u)}] (
|
|
350
315
|
interpolation = "vertex"
|
|
351
316
|
)
|
|
352
|
-
`),
|
|
353
|
-
`,
|
|
354
|
-
|
|
317
|
+
`),S+=`rel material:binding = </Root/Materials/${E}>
|
|
318
|
+
`,m.castShadow===!1&&i.length>0&&(S+=`bool primvars:doNotCastShadows = 1
|
|
319
|
+
`),S},d=new Set,v=[];for(let m=t.length-1;m>=0;m--)v.push({node:t[m],siblings:d});let M=0;for(;v.length>0;){let m=v.pop();if(m.close){y+=`}
|
|
320
|
+
`;continue}let{node:u,siblings:g}=m,p=!!(u.isXform||u.positions.length===0),x=$t(g,et(u.name,p?`Group_${M}`:`Mesh_${M}`));M++;let w=u.children||[];if(p){let _=f(u.xrTraits,!1,u.invisible);y+=`def Xform "${x}"${_.header}
|
|
355
321
|
{
|
|
356
|
-
${
|
|
322
|
+
${_.body}${b(u)}${_.tail}`,v.push({close:!0});let N=new Set;for(let P=w.length-1;P>=0;P--)v.push({node:w[P],siblings:N})}else if(w.length>0){let _=f(u.xrTraits,!1,u.invisible),N=`${x}_mesh`;y+=`def Xform "${x}"${_.header}
|
|
357
323
|
{
|
|
358
|
-
${
|
|
324
|
+
${_.body}${b(u)}${_.tail}`,y+=`def Mesh "${N}" (
|
|
359
325
|
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
360
326
|
)
|
|
361
327
|
{
|
|
362
|
-
${u
|
|
363
|
-
`,
|
|
328
|
+
${h(u)}}
|
|
329
|
+
`,v.push({close:!0});let P=new Set([N]);for(let E=w.length-1;E>=0;E--)v.push({node:w[E],siblings:P})}else{let _=f(u.xrTraits,!0,u.invisible);y+=`def Mesh "${x}"${_.header}
|
|
364
330
|
{
|
|
365
|
-
${
|
|
366
|
-
`}}
|
|
367
|
-
|
|
368
|
-
`,o}var 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) {
|
|
331
|
+
${_.body}${b(u)}${h(u)}${_.tail}}
|
|
332
|
+
`}}if(y+=`}
|
|
333
|
+
`,i.length>0){y+=`def Scope "Lights"
|
|
334
|
+
{
|
|
335
|
+
`;let m=new Set;for(let u=0;u<i.length;u++){let g=i[u],p=$t(m,et(g.name,`Light_${u}`)),x=g.type==="directional"?"DistantLight":g.type==="spot"?"DiskLight":"SphereLight",w=g.type==="spot"?'["ShapingAPI", "ShadowAPI"]':'["ShadowAPI"]',[_,N,P]=g.color||[1,1,1],[E,T,S]=g.position||[0,5,5],A=-E,D=-T,R=-S;g.direction&&g.direction.length>=3&&(g.type==="directional"?(A=-g.direction[0],D=-g.direction[1],R=-g.direction[2]):(A=g.direction[0],D=g.direction[1],R=g.direction[2]));let[I,k,V,L]=Pi(A,D,R),O="",c=[];g.type!=="directional"&&(Math.abs(E)>1e-7||Math.abs(T)>1e-7||Math.abs(S)>1e-7)&&(O+=`double3 xformOp:translate = ${Le(E,T,S)}
|
|
336
|
+
`,c.push('"xformOp:translate"')),g.type!=="point"&&(1-Math.abs(L)>1e-7||Math.hypot(I,k,V)>1e-7)&&(O+=`quatf xformOp:orient = ${tt(L,I,k,V)}
|
|
337
|
+
`,c.push('"xformOp:orient"')),c.length>0&&(O+=`uniform token[] xformOpOrder = [${c.join(", ")}]
|
|
338
|
+
`);let F="";if(g.type==="spot"){let C=(g.outerConeAngle??Math.PI/3)*180/Math.PI,U=(g.innerConeAngle??C*.8)*180/Math.PI,H=C>1e-4?Math.max(0,Math.min(1,1-U/C)):0;F=`float inputs:shaping:cone:angle = ${be(C)}
|
|
339
|
+
float inputs:shaping:cone:softness = ${be(H)}
|
|
340
|
+
`}y+=`def ${x} "${p}" (
|
|
341
|
+
prepend apiSchemas = ${w}
|
|
342
|
+
)
|
|
343
|
+
{
|
|
344
|
+
color3f inputs:color = ${Le(_,N,P)}
|
|
345
|
+
float inputs:intensity = ${be(g.intensity??1)}
|
|
346
|
+
bool inputs:shadow:enable = 1
|
|
347
|
+
${F}${O}}
|
|
348
|
+
`}y+=`}
|
|
349
|
+
`}return y+=`}
|
|
350
|
+
`,y}var gt=null;function zt(t){if(!gt){gt=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let n=0;n<8;n++)r=r&1?3988292384^r>>>1:r>>>1;gt[i]=r}}let e=4294967295;for(let i=0;i<t.length;i++)e=gt[(e^t[i])&255]^e>>>8;return(e^4294967295)>>>0}function Es(t){let e=[],i=0,r=[];for(let f of t){let b=Vt(f.filename),h=zt(f.data),d=f.data.length,v=30+b.length,M=(i+v)%64,m=M!==0?64-M:0;m>0&&m<4&&(m+=64);let u=new Uint8Array(v+m),g=new DataView(u.buffer);g.setUint32(0,67324752,!0),g.setUint16(4,20,!0),g.setUint32(14,h,!0),g.setUint32(18,d,!0),g.setUint32(22,d,!0),g.setUint16(26,b.length,!0),g.setUint16(28,m,!0),u.set(b,30),m>=4&&(g.setUint16(v,6534,!0),g.setUint16(v+2,m-4,!0)),e.push({offset:i,size:d,crc:h,filenameBytes:b,entry:f}),r.push(u,f.data),i+=u.length+f.data.length}let n=i;for(let f of e){let b=new Uint8Array(46+f.filenameBytes.length),h=new DataView(b.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint32(16,f.crc,!0),h.setUint32(20,f.size,!0),h.setUint32(24,f.size,!0),h.setUint16(28,f.filenameBytes.length,!0),h.setUint32(42,f.offset,!0),b.set(f.filenameBytes,46),r.push(b),i+=b.length}let s=i-n,a=new Uint8Array(22),o=new DataView(a.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,e.length,!0),o.setUint16(10,e.length,!0),o.setUint32(12,s,!0),o.setUint32(16,n,!0),r.push(a),i+=22;let l=new Uint8Array(i),y=0;for(let f of r)l.set(f,y),y+=f.length;return l}function Di(t){let e=[{filename:"model.usda",data:Vt(Rs(t))}],i=new Set(["model.usda"]),r=[...t];for(;r.length>0;){let n=r.pop();for(let s of n.textures||[])s?.file&&s.data?.byteLength&&!i.has(s.file)&&(i.add(s.file),e.push({filename:s.file,data:s.data}));if(n.children)for(let s=n.children.length-1;s>=0;s--)r.push(n.children[s])}return Es(e)}function yt(t){return Di(_s(t))}function Bt(t){return Di(Li(It(t)))}function Ii(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():Bt(t)}var Pe=class Wr{constructor(e=0,i=0){this.x=Number(e),this.y=Number(i)}set(e,i){return this.x=Number(e),this.y=Number(i),this}clone(){return new Wr(this.x,this.y)}copy(e){return this.set(e.x,e.y)}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e)}get width(){return this.x}set width(e){this.x=Number(e)}get height(){return this.y}set height(e){this.y=Number(e)}},ee=class Xr{constructor(e=0,i=0,r=0){this.x=Number(e),this.y=Number(i),this.z=Number(r)}set(e,i,r){return this.x=Number(e),this.y=Number(i),this.z=Number(r),this}clone(){return new Xr(this.x,this.y,this.z)}copy(e){return this.set(e.x,e.y,e.z)}add(e){return this.addVectors(this,e)}addVectors(e,i){return this.set(e.x+i.x,e.y+i.y,e.z+i.z)}sub(e){return this.subVectors(this,e)}subVectors(e,i){return this.set(e.x-i.x,e.y-i.y,e.z-i.z)}multiplyScalar(e){return this.set(this.x*e,this.y*e,this.z*e)}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e,e)}addScaledVector(e,i){return this.set(this.x+e.x*i,this.y+e.y*i,this.z+e.z*i)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5?this.multiplyScalar(1/e):this}cross(e){return this.crossVectors(this,e)}crossVectors(e,i){let r=e.x,n=e.y,s=e.z,a=i.x,o=i.y,l=i.z;return this.set(n*l-s*o,s*a-r*l,r*o-n*a)}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}lerp(e,i){return this.lerpVectors(this,e,i)}lerpVectors(e,i,r){return this.x=e.x+(i.x-e.x)*r,this.y=e.y+(i.y-e.y)*r,this.z=e.z+(i.z-e.z)*r,this}applyMatrix4(e){let i=this.x,r=this.y,n=this.z,s=e.elements,a=1/(s[3]*i+s[7]*r+s[11]*n+s[15]);return this.x=(s[0]*i+s[4]*r+s[8]*n+s[12])*a,this.y=(s[1]*i+s[5]*r+s[9]*n+s[13])*a,this.z=(s[2]*i+s[6]*r+s[10]*n+s[14])*a,this}},Fi=class{constructor(t=0,e=0,i=0,r=1){this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r)}set(t,e,i,r){return this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r),this}},Gt=class qr{constructor(e=0,i=0,r=0,n="XYZ"){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=n}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,i,r,n=this.order){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=n,this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.order)}clone(){return new qr(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},bt=class Kr{constructor(e=0,i=0,r=0,n=1){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(n)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,i,r,n){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(n),this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.w)}clone(){return new Kr(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(e,i=!0){let r=e.x,n=e.y,s=e.z,a=Math.cos(r/2),o=Math.cos(n/2),l=Math.cos(s/2),y=Math.sin(r/2),f=Math.sin(n/2),b=Math.sin(s/2);return this._x=y*o*l+a*f*b,this._y=a*f*l-y*o*b,this._z=a*o*b+y*f*l,this._w=a*o*l-y*f*b,i&&this._onChangeCallback?.(),this}setFromAxisAngle(e,i){let r=i/2,n=Math.sin(r);return this.set(e.x*n,e.y*n,e.z*n,Math.cos(r))}normalize(){let e=Math.hypot(this._x,this._y,this._z,this._w);return e===0?this.set(0,0,0,1):this.set(this._x/e,this._y/e,this._z/e,this._w/e)}setFromUnitVectors(e,i){let r=e.dot(i)+1;return r<1e-6?(Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,0):this.set(0,-e.z,e.y,0)).normalize():this.set(e.y*i.z-e.z*i.y,e.z*i.x-e.x*i.z,e.x*i.y-e.y*i.x,r).normalize()}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,i){let r=e.x,n=e.y,s=e.z,a=e.w,o=i.x,l=i.y,y=i.z,f=i.w;return this._x=r*f+a*o+n*y-s*l,this._y=n*f+a*l+s*o-r*y,this._z=s*f+a*y+r*l-n*o,this._w=a*f-r*o-n*l-s*y,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},qe=class Yr{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new Yr;return e.copy(this),e}compose(e,i,r){return Nt(this.elements,[i.x,i.y,i.z,i.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,i){return Te(this.elements,e.elements,i.elements),this}lookAt(e,i,r){return Lt(this.elements,[e.x,e.y,e.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let i=new ee(0,0,0),r=new ee(1,1,1);return this.compose(i,e,r)}makeTranslation(e,i,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(e,i,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},ki=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[4]=1,t[8]=1,this}getNormalMatrix(t){return Oe(this.elements,t.elements),this}},_e=t=>t<=.04045?t/12.92:((t+.055)/1.055)**2.4,xt=t=>t<=.0031308?t*12.92:1.055*t**(1/2.4)-.055,Ui={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},Ie=class Zr{constructor(e,i,r){this.r=1,this.g=1,this.b=1,e!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(e,i,r):this.set(e))}set(e){return typeof e=="number"?this.setHex(e):typeof e=="string"?this.setStyle(e):(e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b)),this)}setStyle(e){let i=e.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let n=parseInt(r,16);r.length===6&&!Number.isNaN(n)&&this.setHex(n)}else if(i in Ui)this.setHex(Ui[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let n=s=>_e(Math.max(0,Math.min(1,(parseFloat(s)||0)/(s.endsWith("%")?100:255))));this.setRGB(n(r[0]),n(r[1]),n(r[2]))}}return this}setHSL(e,i,r){if(e=((Number(e)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let o=_e(r);return this.setRGB(o,o,o)}let n=r<=.5?r*(1+i):r+i-r*i,s=2*r-n,a=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?s+(n-s)*6*o:o<1/2?n:o<2/3?s+(n-s)*6*(2/3-o):s);return this.setRGB(_e(a(e+1/3)),_e(a(e)),_e(a(e-1/3)))}lerp(e,i){return this.lerpColors(this,e,i)}lerpColors(e,i,r){let n=Number(r)||0;return this.setRGB(e.r+(i.r-e.r)*n,e.g+(i.g-e.g)*n,e.b+(i.b-e.b)*n)}multiplyScalar(e){let i=Number(e)||0;return this.setRGB(this.r*i,this.g*i,this.b*i)}setScalar(e){let i=Number(e)||0;return this.setRGB(i,i,i)}setHex(e){let i=Math.floor(e);return this.setRGB(_e((i>>16&255)/255),_e((i>>8&255)/255),_e((i&255)/255))}setRGB(e,i,r){return this.r=Number(e),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.setRGB(_e(this.r),_e(this.g),_e(this.b))}convertLinearToSRGB(){return this.setRGB(xt(this.r),xt(this.g),xt(this.b))}getHex(){let e=i=>Math.round(xt(Math.max(0,Math.min(1,i)))*255);return e(this.r)<<16|e(this.g)<<8|e(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.setRGB(e.r,e.g,e.b)}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new Zr(this.r,this.g,this.b)}},Ht=1234567,Oi={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,i)=>Math.max(e,Math.min(i,t)),lerp:(t,e,i)=>t+(e-t)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randInt:(t,e)=>t+Math.floor(Math.random()*(e-t+1)),randFloat:(t,e)=>t+Math.random()*(e-t),randFloatSpread:t=>t*(.5-Math.random()),seededRandom:t=>{t!==void 0&&(Ht=Number.isFinite(t)?t|0:0);let e=Ht=Ht+1831565813|0;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}},Ae=class Jr{constructor(e,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=i;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/i)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.itemSize>=2?this.array[e*this.itemSize+1]:0}getZ(e){return this.itemSize>=3?this.array[e*this.itemSize+2]:0}setX(e,i){return this.array[e*this.itemSize]=i,this.needsUpdate=!0,this}setY(e,i){return this.array[e*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(e,i){return this.array[e*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(e,i,r,n){let s=e*this.itemSize;return this.array[s]=i,this.array[s+1]=r,this.array[s+2]=n,this.needsUpdate=!0,this}setUsage(e){return this}clone(){let e=this.array?.constructor||Float32Array;return new Jr(new e(this.array),this.itemSize)}},$i=class extends Ae{constructor(t,e){super(t instanceof Float32Array||Array.isArray(t)?t:new Float32Array(t),e)}},Vi=class extends Ae{constructor(t,e){super(t instanceof Uint16Array?t:new Uint16Array(t),e)}},zi=class extends Ae{constructor(t,e){super(t instanceof Uint32Array?t:new Uint32Array(t),e)}},Me=class Qr{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(e,i){return this.attributes[e]=i,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof Ae)this.index=e;else if(Array.isArray(e)){let i=0;for(let r of e)r>i&&(i=r);this.index=new Ae(new(i>65535?Uint32Array:Uint16Array)(e),1)}else e&&e.buffer&&(this.index=new Ae(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let i=!1;if(typeof i=="function"){let l=i(e.array,this.index?.array);return this.setAttribute("normal",new Ae(l,3)),this}let r=e.count,n=e.array,s=new Float32Array(r*3),a=this.index?.array,o=a?a.length:r;for(let l=0;l<o;l+=3){let y=(a?a[l]:l)*3,f=(a?a[l+1]:l+1)*3,b=(a?a[l+2]:l+2)*3,h=n[f],d=n[f+1],v=n[f+2],M=n[b]-h,m=n[b+1]-d,u=n[b+2]-v,g=n[y]-h,p=n[y+1]-d,x=n[y+2]-v,w=m*x-u*p,_=u*g-M*x,N=M*p-m*g;s[y]+=w,s[y+1]+=_,s[y+2]+=N,s[f]+=w,s[f+1]+=_,s[f+2]+=N,s[b]+=w,s[b+1]+=_,s[b+2]+=N}for(let l=0;l<r*3;l+=3){let y=s[l],f=s[l+1],b=s[l+2],h=Math.hypot(y,f,b)||1;s[l]=y/h,s[l+1]=f/h,s[l+2]=b/h}return this.setAttribute("normal",new Ae(s,3)),this}setFromBuffers(e,i,r,n){this.setAttribute("position",new Ae(e,3)),this.setAttribute("normal",new Ae(i,3)),this.setAttribute("uv",new Ae(r,2)),this.setIndex(n)}setFromPoints(e){let i=[];if(Array.isArray(e))for(let r of e)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new Ae(i,3))}computeBoundingBox(){let e=this.attributes.position,i=new ee(1/0,1/0,1/0),r=new ee(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let n=0;n<e.count;n++){let s=e.getX(n),a=e.getY(n),o=e.getZ(n);s<i.x&&(i.x=s),a<i.y&&(i.y=a),o<i.z&&(i.z=o),s>r.x&&(r.x=s),a>r.y&&(r.y=a),o>r.z&&(r.z=o)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let e=this.computeBoundingBox();return e.max.x<e.min.x?this:this.translate(-(e.min.x+e.max.x)*.5,-(e.min.y+e.max.y)*.5,-(e.min.z+e.max.z)*.5)}_xform(e,i){let r=this.attributes.position;if(r){let n=r.array;for(let s=0;s<n.length;s+=3)e(n,s);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(e=0,i=0,r=0){return this._xform((n,s)=>{n[s]+=e,n[s+1]+=i,n[s+2]+=r})}scale(e=1,i=1,r=1){return this._xform((n,s)=>{n[s]*=e,n[s+1]*=i,n[s+2]*=r},!0)}_rot(e,i,r){let n=Math.cos(r),s=Math.sin(r);for(let a of[this.attributes.position,this.attributes.normal]){if(!a)continue;let o=a.array;for(let l=0;l<o.length;l+=3){let y=o[l+e],f=o[l+i];o[l+e]=y*n-f*s,o[l+i]=y*s+f*n}a.needsUpdate=!0}return this}rotateX(e){return this._rot(1,2,e)}rotateY(e){return this._rot(2,0,e)}rotateZ(e){return this._rot(0,1,e)}applyMatrix4(e){let i=this.attributes.position;if(i&&e?.elements){let r=new ee;for(let n=0;n<i.count;n++)r.set(i.getX(n),i.getY(n),i.getZ(n)).applyMatrix4(e),i.setXYZ(n,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let e=new Qr;e.name=this.name;for(let i of Object.keys(this.attributes))e.attributes[i]=this.attributes[i].clone();return this.index&&(e.index=this.index.clone()),e}dispose(){}},jt=class extends Me{constructor(t=1,e=1,i=1){super();let r=t/2,n=e/2,s=i/2,a=[-r,-n,s,r,-n,s,r,n,s,-r,n,s,r,-n,-s,-r,-n,-s,-r,n,-s,r,n,-s,-r,n,s,r,n,s,r,n,-s,-r,n,-s,-r,-n,-s,r,-n,-s,r,-n,s,-r,-n,s,r,-n,s,r,-n,-s,r,n,-s,r,n,s,-r,-n,-s,-r,-n,s,-r,n,s,-r,n,-s],o=[],l=[],y=[];for(let f=0;f<6;f++){let b=f*4,h=2-(f>>1),d=f&1?-1:1;for(let v=0;v<4;v++)o.push(h===0?d:0,h===1?d:0,h===2?d:0);l.push(0,0,1,0,1,1,0,1),y.push(b,b+1,b+2,b,b+2,b+3)}this.setFromBuffers(a,o,l,y)}},Bi=class extends Me{constructor(t=1,e=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let n=[],s=[],a=[],o=[];for(let l=0;l<=r;l++){let y=l/r;for(let f=0;f<=i;f++){let b=f/i;if(n.push((b-.5)*t,(.5-y)*e,0),s.push(0,0,1),a.push(b,1-y),l>0&&f>0){let h=(i+1)*l+f-1,d=h-(i+1);o.push(d,h,d+1,h,h+1,d+1)}}}this.setFromBuffers(n,s,a,o)}},Gi=class extends Me{constructor(t=1,e=16,i=12,r=0,n=Math.PI*2,s=0,a=Math.PI){super(),e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i));let o=[],l=[],y=[],f=[],b=Math.min(s+a,Math.PI);for(let h=0;h<=i;h++){let d=h/i,v=s+d*a;for(let M=0;M<=e;M++){let m=M/e,u=r+m*n,g=-Math.cos(u)*Math.sin(v),p=Math.cos(v),x=Math.sin(u)*Math.sin(v);if(o.push(t*g,t*p,t*x),l.push(g,p,x),y.push(m,1-d),h>0&&M>0){let w=(e+1)*h+M,_=w-(e+1),N=_-1,P=w-1;(h!==1||s>0)&&f.push(_,N,w),(h!==i||b<Math.PI)&&f.push(N,P,w)}}}this.setFromBuffers(o,l,y,f)}},Wt=class extends Me{constructor(t=1,e=1,i=1,r=16,n=1,s=!1,a=0,o=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),n=Math.max(1,Math.floor(Number(n)||1));let l=[],y=[],f=[],b=[],h=i/2,d=(e-t)/(i||1),v=r+1;for(let m=0;m<=n;m++){let u=m/n,g=u*(e-t)+t,p=h-u*i;for(let x=0;x<=r;x++){let w=x/r,_=a+w*o,N=Math.sin(_),P=Math.cos(_),E=Math.hypot(N,d,P)||1;if(l.push(g*N,p,g*P),y.push(N/E,d/E,P/E),f.push(w,1-u),m<n&&x<r){let T=m*v+x,S=T+v;b.push(T,S,T+1,S,S+1,T+1)}}}let M=(m,u)=>{if(s||m<=0)return;let g=u*h,p=l.length/3;l.push(0,g,0),y.push(0,u,0),f.push(.5,.5);let x=p+1;for(let w=0;w<=r;w++){let _=a+w/r*o,N=Math.sin(_),P=Math.cos(_);l.push(m*N,g,m*P),y.push(0,u,0),f.push(P*.5+.5,.5+u*N*.5),w<r&&b.push(p,x+w+(u>0?0:1),x+w+(u>0?1:0))}};M(t,1),M(e,-1),this.setFromBuffers(l,y,f,b)}},Hi=class extends Wt{constructor(t=1,e=1,i=16,r=1,n=!1,s=0,a=Math.PI*2){super(0,t,e,i,r,n,s,a)}},ji=class extends Me{constructor(t=1,e=.4,i=12,r=48,n=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let s=[],a=[],o=[],l=[];for(let y=0;y<=i;y++){let f=y/i*Math.PI*2,b=Math.cos(f),h=Math.sin(f);for(let d=0;d<=r;d++){let v=d/r*n,M=Math.cos(v),m=Math.sin(v);if(s.push((t+e*b)*M,(t+e*b)*m,e*h),a.push(b*M,b*m,h),o.push(d/r,y/i),y>0&&d>0){let u=(r+1)*y+d-1,g=u-(r+1);l.push(u,g,u+1,g,g+1,u+1)}}}this.setFromBuffers(s,a,o,l)}};function Wi(t,e,i,r,n){let s=Math.max(2,Math.min(256,Math.floor(Number(e)||64))),a=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),o=Number(r)||.1,l=[],y=[],f=[],b=[],h=[],d=new ee,v=new ee,M=new ee;for(let u=0;u<=s;u++){let g=new ee;n(u/s,g),h.push(g)}let m=a+1;for(let u=0;u<=s;u++){let g=u/s,p=h[u];d.subVectors(h[Math.min(s,u+1)],h[Math.max(0,u-1)]).normalize(),u===0&&v.set(Math.abs(d.y)>.9?1:0,Math.abs(d.y)>.9?0:1,0),M.crossVectors(d,v).normalize(),v.crossVectors(M,d).normalize();for(let x=0;x<=a;x++){let w=x/a*Math.PI*2,_=-Math.cos(w),N=Math.sin(w),P=_*v.x+N*M.x,E=_*v.y+N*M.y,T=_*v.z+N*M.z;if(l.push(p.x+o*P,p.y+o*E,p.z+o*T),y.push(P,E,T),f.push(g,x/a),u>0&&x>0){let S=m*(u-1)+x-1,A=S+m;b.push(S,A,S+1,A,A+1,S+1)}}}t.setFromBuffers(l,y,f,b)}var Xi=class extends Me{constructor(t=1,e=.4,i=64,r=8,n=2,s=3){super(),i=Math.floor(i),r=Math.floor(r),Wi(this,i,r,e,(a,o)=>{let l=a*n*Math.PI*2,y=s/n*l,f=t*(2+Math.cos(y))*.5;o.set(f*Math.cos(l),f*Math.sin(l),t*Math.sin(y)*.5)})}},He=class{getPoint(t,e=new ee){return e}getPointAt(t,e=new ee){return this.getPoint(t,e)}getTangent(t,e=new ee){return e.subVectors(this.getPoint(Math.min(1,t+.001)),this.getPoint(Math.max(0,t-.001))).normalize()}getPoints(t=5){let e=Math.max(1,Math.min(512,Math.floor(Number(t)||5))),i=[];for(let r=0;r<=e;r++)i.push(this.getPoint(r/e));return i}getSpacedPoints(t=5){return this.getPoints(t)}},qi=class extends He{constructor(t=new ee,e=new ee){super(),this.v1=t,this.v2=e}getPoint(t,e=new ee){return e.lerpVectors(this.v1,this.v2,t)}},Ki=class extends He{constructor(t=new ee,e=new ee,i=new ee){super(),this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new ee){return e.lerpVectors(this.v0,this.v1,t).lerp(new ee().lerpVectors(this.v1,this.v2,t),t)}},Yi=class extends He{constructor(t=new ee,e=new ee,i=new ee,r=new ee){super(),this.v0=t,this.v1=e,this.v2=i,this.v3=r}getPoint(t,e=new ee){let i=new ee().lerpVectors(this.v0,this.v1,t),r=new ee().lerpVectors(this.v1,this.v2,t),n=new ee().lerpVectors(this.v2,this.v3,t);return e.lerpVectors(i.lerp(r,t),r.lerp(n,t),t)}},Zi=class extends He{constructor(t=[],e=!1){super(),this.points=Array.isArray(t)?t:[],this.closed=!!e}getPoint(t,e=new ee){let i=this.points,r=i.length;if(!r)return e.set(0,0,0);if(r===1)return e.copy(i[0]);let n=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(t)||0)),s=Math.floor(n),a=n-s;!this.closed&&s>=r-1&&(s=r-2,a=1);let o=M=>i[this.closed?(M%r+r)%r:Math.max(0,Math.min(r-1,M))],l=o(s-1),y=o(s),f=o(s+1),b=o(s+2),h=a*a,d=h*a,v=(M,m,u,g)=>.5*(2*m+(u-M)*a+(2*M-5*m+4*u-g)*h+(3*m-M-3*u+g)*d);return e.set(v(l.x,y.x,f.x,b.x),v(l.y,y.y,f.y,b.y),v(l.z,y.z,f.z,b.z))}},Xt=class extends Me{constructor(t=[new Pe(0,-.5),new Pe(.5,0),new Pe(0,.5)],e=12,i=0,r=Math.PI*2){super();let n=Array.isArray(t)&&t.length>=2?t:[new Pe(.2,0),new Pe(.2,.5)],s=Math.max(3,Math.min(128,Math.floor(Number(e)||12))),a=[],o=[],l=[],y=[],f=n.length;for(let b=0;b<=s;b++){let h=b/s,d=i+h*r,v=Math.sin(d),M=Math.cos(d),m=b*f;for(let u=0;u<f;u++){let g=n[u],p=Number(g?.x)||0,x=Number(g?.y)||0;a.push(p*v,x,p*M);let w=n[Math.max(0,u-1)],_=n[Math.min(f-1,u+1)],N=(Number(_?.x)||0)-(Number(w?.x)||0),P=(Number(_?.y)||0)-(Number(w?.y)||0),E=Math.hypot(P,N)||1;if(o.push(P/E*v,-N/E,P/E*M),l.push(h,u/(f-1)),b<s&&u<f-1){let T=m+u,S=T+f;y.push(T,S,T+1,S,S+1,T+1)}}}this.setFromBuffers(a,o,l,y)}},Ji=class extends Me{constructor(t,e=64,i=1,r=8,n=!1){super(),Wi(this,e,r,i,(s,a)=>{let o=t?.getPointAt??t?.getPoint;if(typeof o=="function"){let l=o.call(t,s,a);l&&l!==a&&a.copy(l)}else a.set(0,s,0)})}},vt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Mt=class{constructor(t=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Pe(1,1),this.offset=new Pe(0,0),this.image=null,this.width=0,this.height=0,this.source=t,t&&typeof t=="object"&&(this.image=t)}dispose(){}},Qi=class extends Mt{constructor(t=null,e=1,i=1,r=1023,n=1009,s,a=1001,o=1001,l=1003,y=1003,f=1,b=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let h=Number(e),d=Number(i),v=t&&typeof t.length=="number"?t:null;this.width=h,this.height=d,this.image={data:v,width:h,height:d},this.format=Number(r)||1023,this.type=Number(n)||1009,this.wrapS=Number(a)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(l)||1003,this.minFilter=Number(y)||1003,this.colorSpace=b||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(t){t&&this._bake()}_bake(){let t=this.image,e=t?.data,i=Number(t?.width??this.width),r=Number(t?.height??this.height);if(!e||!e.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let n=Math.max(1,i|0),s=Math.max(1,r|0),a=n*s,o=this.format,l=o===1021||o===1024||o===1028||e.length===a?1:o===1025||o===1030||e.length===a*2?2:o===1022||e.length===a*3?3:4,y=this.type===1015||this.type===1016||e instanceof Float32Array||e instanceof Float64Array,f=Math.min(n,64),b=Math.min(s,64),h=(this.flipY?257:1)^this.colorSpace.length^e.length,d=Math.max(1,e.length>>6|0);for(let A=0;A<e.length;A+=d)h=Math.imul(h^(e[A]*256|0),16777619)|0;if(h===this._sig&&this.source)return;this._sig=h;let v=b*(1+f*4),M=new Uint8Array(68+v),m=new DataView(M.buffer);m.setUint32(0,2303741511),m.setUint32(4,218765834),m.setUint32(8,13),m.setUint32(12,1229472850),m.setUint32(16,f),m.setUint32(20,b),M[24]=8,M[25]=6,m.setUint32(29,zt(M.subarray(12,29))),m.setUint32(33,v+11),m.setUint32(37,1229209940),M[41]=120,M[42]=1,M[43]=1,m.setUint16(44,v,!0),m.setUint16(46,~v&65535,!0);let u=48,g=1,p=0,x=0,w=0,_=0,N=0,P=A=>{if(!Number.isFinite(A))return 0;let D=y&&A<=1?A*255:A;return D>0?D<255?D+.5|0:255:0};for(let A=0;A<b;A++){let D=A*s/b|0,R=this.flipY?s-1-D:D;M[u++]=0,p+=g;for(let I=0;I<f;I++){let k=(R*n+(I*n/f|0))*l,V=o===1021?255:P(e[k]??0),L=l>=3||o===1030?P(e[k+1]??0):V,O=l>=3?P(e[k+2]??0):o===1030?0:V,c=l===4?P(e[k+3]??255):o===1021?P(e[k]??255):o===1025?P(e[k+1]??255):255;M[u++]=V,g+=V,p+=g,M[u++]=L,g+=L,p+=g,M[u++]=O,g+=O,p+=g,M[u++]=c,g+=c,p+=g,x+=V,w+=L,_+=O,N+=c}g%=65521,p%=65521}m.setUint32(u,(p<<16|g)>>>0),m.setUint32(u+4,zt(M.subarray(37,u+4))),m.setUint32(u+12,1229278788),m.setUint32(u+16,2923585666);let E=f*b*255,T=this.colorSpace==="srgb-linear";this.avgColor=[T?x/E:_e(x/E),T?w/E:_e(w/E),T?_/E:_e(_/E),N/E];let S=["data:image/png;base64,"];for(let A=0;A<M.length;A+=3){let D=M[A]<<16|(M[A+1]??0)<<8|(M[A+2]??0);S.push(vt[D>>18&63]+vt[D>>12&63]+(A+1<M.length?vt[D>>6&63]:"=")+(A+2<M.length?vt[D&63]:"="))}this.source=S.join("")}},er=class{load(t,e){let i=new Mt(t);return e?.(i),i}};function we(t,e){return t!==void 0?Number(t):e}function qt(t,e){return t!==void 0?!!t:e}var Ne=class{constructor(t={}){this.name=t.name||"",this.color=new Ie(t.color??16777215),this._em=t.emissive!==void 0,this.emissive=new Ie(t.emissive??0),this.emissiveIntensity=we(t.emissiveIntensity,1),this.roughness=we(t.roughness,t.roughnessMap?1:.5),this.metalness=we(t.metalness,t.metalnessMap?1:0),this.opacity=we(t.opacity,1),this.transparent=qt(t.transparent,!1),this.wireframe=qt(t.wireframe,!1),this.side=we(t.side,2),this.doubleSided=qt(t.doubleSided,!0),this.map=t.map||null,this.normalMap=t.normalMap||null;let e=t.normalScale;this.normalScale=typeof e=="number"?new Pe(e,e):new Pe(we(e?.x,1),we(e?.y,1)),this.roughnessMap=t.roughnessMap||null,this.metalnessMap=t.metalnessMap||null,this.emissiveMap=t.emissiveMap||null,this.aoMap=t.aoMap||null,this.aoMapIntensity=we(t.aoMapIntensity,1),this.bumpMap=t.bumpMap||null,this.bumpScale=we(t.bumpScale,1),this.clearcoat=we(t.clearcoat,0),this.clearcoatRoughness=we(t.clearcoatRoughness,0),this.sheen=we(t.sheen,0),this.sheenColor=new Ie(t.sheenColor??0),this.sheenRoughness=we(t.sheenRoughness,0),this.transmission=we(t.transmission,0),this.thickness=we(t.thickness,0),this.attenuationColor=new Ie(t.attenuationColor??16777215),this.attenuationDistance=we(t.attenuationDistance,1/0),this.ior=we(t.ior,1.5),this.dispersion=we(t.dispersion,0),this.iridescence=we(t.iridescence,0),this.iridescenceIOR=we(t.iridescenceIOR,1.3)}dispose(){}},it=class extends Ne{},tr=class extends Ne{},ir=class extends Ne{},rr=class extends Ne{},sr=class extends Ne{},Fe=class es{constructor(){this.name="",this.matrixAutoUpdate=!0,this.visible=!0,this._castShd=!1,this._castShdSet=!1,this._recvShd=!1,this._recvShdSet=!1,this.parent=null,this.children=[],this.userData={},this.position=new ee,this.rotation=new Gt,this.quaternion=new bt,this.scale=new ee(1,1,1),this.matrix=new qe,this.matrixWorld=new qe,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,i=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),n=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(i,r,n)})}get castShadow(){return this._castShd}set castShadow(e){this._castShd=!!e,this._castShdSet=!0}get receiveShadow(){return this._recvShd}set receiveShadow(e){this._recvShd=!!e,this._recvShdSet=!0}add(...e){for(let i of e)i&&i instanceof es&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...e){for(let i of e){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(e){let i=new Set,r=[this];for(;r.length>0;){let n=r.pop();if(!n||typeof n!="object"||i.has(n))continue;i.add(n),e(n);let s=n.children;if(Array.isArray(s))for(let a=s.length-1;a>=0;a--)r.push(s[a])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){this.traverse(i=>{ar(i),(i.matrixAutoUpdate||e)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(e,i,r){let n=typeof e=="object"?e:new ee(e,i,r);this.target instanceof ee?this.target.copy(n):this.target?.position instanceof ee&&this.target.position.copy(n),this.updateMatrixWorld(!0);let s=new qe;s.lookAt(this.position,n,new ee(0,1,0));let a=s.elements,o=a[0],l=a[4],y=a[8],f=a[1],b=a[5],h=a[9],d=a[2],v=a[6],M=a[10],m=o+b+M;if(m>0){let u=.5/Math.sqrt(m+1);this.quaternion.set((v-h)*u,(y-d)*u,(f-l)*u,.25/u)}}translateOnAxis(e,i){let r=e.clone().applyMatrix4(new qe().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(e){return this.translateOnAxis(new ee(1,0,0),e)}translateY(e){return this.translateOnAxis(new ee(0,1,0),e)}translateZ(e){return this.translateOnAxis(new ee(0,0,1),e)}rotateX(e){return this.rotation.x+=e,this}rotateY(e){return this.rotation.y+=e,this}rotateZ(e){return this.rotation.z+=e,this}_chain(){let e=[];for(let i=this;i&&e.length<64;i=i.parent)e.push(i);return e}_syncWorld(){let e=this._chain();for(let i=e.length-1;i>=0;i--){let r=e[i];r.updateMatrix?.(),r.parent?.matrixWorld?r.matrixWorld.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrixWorld?.copy(r.matrix)}return this.matrixWorld.elements}getWorldPosition(e=new ee){let i=this._syncWorld();return e.set(i[12],i[13],i[14])}getWorldScale(e=new ee){let i=this._syncWorld();return e.set(Math.hypot(i[0],i[1],i[2]),Math.hypot(i[4],i[5],i[6]),Math.hypot(i[8],i[9],i[10]))}getWorldDirection(e=new ee){let i=this._syncWorld();return e.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(e=new bt){let i=this._chain();e.set(0,0,0,1);for(let r=i.length-1;r>=0;r--)e.multiply(i[r].quaternion);return e}clone(e=!0){let i=typeof this._cloneCustom=="function"?this._cloneCustom():this instanceof Ye?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof $e?new $e(this.geometry,this.material):new this.constructor;if(this instanceof je){i.color.copy(this.color),i.intensity=this.intensity,i.shadow.copy(this.shadow);let r=this.target;r?.position&&i.target?.position&&i.target.position.copy(r.position),this instanceof ci&&i.groundColor.copy(this.groundColor)}i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,this._castShdSet&&(i.castShadow=this.castShadow),this._recvShdSet&&(i.receiveShadow=this.receiveShadow);try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(e)for(let r of this.children)i.add(r.clone(!0));return i}},nr=class extends Fe{},$e=class extends Fe{constructor(t,e){super(),this.isMesh=!0;let i=Array.isArray(e)?e[0]:e;this.geometry=t instanceof Me?t:t?(Be("unsupported geometry","BoxGeometry"),new jt(.5,.5,.5)):new Me,this.material=i instanceof Ne?i:i?(Be("unsupported material","MeshStandardMaterial"),new it({color:13421772})):new it}};function ar(t){typeof t?._bakeAuthorGeometry=="function"&&t._bakeAuthorGeometry();let e=ge().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var rt=1e4,Kt=class extends $e{constructor(t,e,i=1){super(t,e),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>rt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${rt})`);this.count=Math.floor(r);let n=new Float32Array(this.count*16);for(let s=0;s<this.count;s++){let a=s*16;n[a]=1,n[a+5]=1,n[a+10]=1,n[a+15]=1}this.instanceMatrix=new Ae(n,16)}setMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,n=i*16;if(!(n+16>r.length))for(let s=0;s<16;s++){let a=Number(e.elements[s]);r[n+s]=Number.isFinite(a)?a:s%5===0?1:0}}getMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,n=i*16;if(!(n+16>r.length))for(let s=0;s<16;s++)e.elements[s]=r[n+s]}setColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let s=new Float32Array(this.count*3);s.fill(1),this.instanceColor=new Ae(s,3)}let r=this.instanceColor.array,n=i*3;r[n]=Number.isFinite(e.r)?e.r:1,r[n+1]=Number.isFinite(e.g)?e.g:1,r[n+2]=Number.isFinite(e.b)?e.b:1}getColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){e.setRGB(1,1,1);return}let r=this.instanceColor.array,n=i*3;e.setRGB(r[n],r[n+1],r[n+2])}dispose(){}},Yt=class ts{constructor(){this.mapSize=new Pe(1024,1024),this.bias=-5e-4,this.normalBias=.015,this.radius=1.5,this.camera={near:.1,far:100,left:-5,right:5,top:5,bottom:-5,fov:50,updateProjectionMatrix:()=>{}}}copy(e){return this.mapSize.copy(e.mapSize),this.bias=Number(e.bias),this.normalBias=Number(e.normalBias),this.radius=Number(e.radius),this}clone(){return new ts().copy(this)}},je=class extends Fe{constructor(t=16777215,e=1){super(),this.isLight=!0,this.shadow=new Yt,this.color=new Ie(t),this.intensity=Number(e),this.type="directional"}},Zt=class extends je{constructor(t,e){super(t,e),this.type="ambient"}},or=class extends je{constructor(t,e){super(t,e),this.target=new Fe,this.type="directional"}},Jt=class extends je{constructor(t,e,i=0,r=2){super(t,e),this.type="point",this.distance=i,this.decay=r}},Qt=class extends Fe{},lr=class extends Qt{constructor(t=45,e=1,i=.1,r=1e3){super(),this.target=new ee(0,0,0),this.fov=Number(t),this.aspect=Number(e),this.near=Number(i),this.far=Number(r)}},ei=class extends Fe{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Ve.validate(this),Qe(this)}toGLB(){return Ve.validate(this),pt(this)}toUSDZ(){return Ve.validate(this),yt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,e=0;return this.traverse(i=>{if(i instanceof $e){let r=new Float32Array(i.matrixWorld.elements);t.set(e,r),i.name&&t.set(i.name,r),e++}}),t}},ti=Qe,ii=pt,hr=yt;ge().makePngDeflater=di;var Ve=class{static validate(t){let e=0,i=0,r=0,n=new Set,s=(o,l,y)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${l}). Found: ${y}`)},a=(o,l)=>{if(!Number.isFinite(l))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(l)}), which cannot be bounds-checked.`);return l};t.traverse(o=>{if(ar(o),o instanceof $e||o.geometry?.attributes?.position?.count){if(r++,r>1e3&&s("MESHES",1e3,r),o instanceof Kt){let y=a("instance",o.count);(y<0||y>rt)&&s("INSTANCES",rt,y)}let l=o.geometry;if(l){let y=0;if(l.attributes.position&&(y=a("vertex",l.attributes.position.count),e+=y,e>1e5&&s("VERTICES",1e5,e)),l.index){let f=a("index",l.index.count);i+=f,i>3e5&&s("INDICES",3e5,i);let b=l.index.array;if(b&&y>0){let h=Math.min(f,b.length);for(let d=0;d<h;d++){let v=b[d];if(!Number.isFinite(v)||v<0||v>=y)throw new Error(`SecurityError: Index buffer value (${String(v)}) out of vertex bounds [0, ${y}).`)}}}}if(o.material){let y=o.material;for(let f of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap","bumpMap"])y[f]&&n.add(y[f])}}}),n.size>16&&s("TEXTURES",16,n.size);for(let o of n){let l=o,y=l.image,f=Number(y?.width??l.width??0)||0,b=Number(y?.height??l.height??0)||0;(!Number.isFinite(f)||!Number.isFinite(b)||f>2048||b>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(f,b))}}},ur=class{constructor(t={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=t.canvas||(typeof document<"u"?document.createElement("canvas"):{}),t.viewer&&(this.boundViewer=t.viewer),t.container?.threeLiveViewer&&(this.boundViewer=t.container.threeLiveViewer),t.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=t.canvas.parentElement.threeLiveViewer);let e=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=t.isSandboxed||e,this.containerId=t.containerId||""}setSize(t,e){return this}setPixelRatio(t){return this}setClearColor(t,e=1){let i=new Ie(t);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,e),this}clear(){return this}dispose(){}render(t,e){if(this.isSandboxed){Ve.validate(t);let r=(n,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(n,s):self.postMessage(n))};if(this.hasInitialModelRendered){let n=t.getMeshTransforms(),s={};for(let[a,o]of n.entries())s[a]=Array.from(o);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let n=ti(t),s=ii(t),a=(n.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:a,camera:e?{fov:e.fov||60,position:[e.position.x,e.position.y,e.position.z]}:void 0},[s.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(t.getMeshTransforms()):(i.loadModel(t.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function cr(){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 mr=class{constructor(t=!0){this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1,this.autoStart=t,t&&this.start()}start(){this.startTime=cr(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running&&this.start(),this.running){let e=cr();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}};function Ls(){}var st=new Proxy(Ls,{get:(t,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:st},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>st,construct:()=>st}),fr=(()=>{try{if(typeof document>"u")return null;let t=document.currentScript;return t?.src?t.src:t?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([t.textContent],{type:"text/javascript"})):null}catch{return null}})();function wt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Ke(t,e){if(!t||typeof t!="string")return!1;let i=t.trim();if(!i)return!1;try{let r=new URL(i,wt());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||e?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var pr,nt;function dr(t){if(!Ke(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let e=globalThis.trustedTypes;if(!e||typeof e.createPolicy!="function")return t;if(nt===void 0||pr!==e){pr=e;try{nt=e.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Ke(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{nt=null}}return nt?nt.createScriptURL(t):t}function Ns(t){ge().sandboxEngineSrc=t}function ri(){let t=ge().sandboxEngineSrc;if(t)return t;if(fr)return fr;try{if(typeof document>"u")return null;let e=wt(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let n=r.src;if(!n)continue;let s=new URL(n,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&Ke(n,{requireSameOrigin:!0}))return n}}catch{}return null}function si(t,e){if(!Ke(t))throw new Error(`SecurityError: Disallowed ${e} URL "${t}" (http:, https:, or blob: required).`);return new URL(t,wt()).href}function Ds(){let t=ri();if(!t)throw new Error("SecurityError: Could not locate Three-Live bundle URL for worker sandbox; set ThreeLiveElement.sandboxEngineSrc explicitly.");return si(t,"sandbox engine")}function Is(t){ge().sandboxIframeSrc=t}function gr(){let t=ge().sandboxIframeSrc;if(t)return t;let e=ri();if(!e||!Ke(e))return null;let i=new URL(e,wt());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function Fs(){let t=gr();if(!t)throw new Error("SecurityError: Could not locate three-live-sandbox.html; set ThreeLiveElement.sandboxIframeSrc explicitly.");return si(t,"sandbox iframe")}function ks(t){ge().allowClientScripts=t}function yr(){return!!ge().allowClientScripts}function Us(t){return si(t,"procedural scene script")}var Os="fetch XMLHttpRequest WebSocket WebSocketStream WebTransport EventSource importScripts Request Response Headers navigator WorkerNavigator WorkerLocation RTCPeerConnection RTCDataChannel FontFace FontFaceSet fonts PerformanceObserver ReportingObserver indexedDB IDBFactory caches CacheStorage Cache cookieStore StorageManager FileSystemHandle Worker SharedWorker ServiceWorker ServiceWorkerContainer ServiceWorkerRegistration registration clients BroadcastChannel MessageChannel MessagePort createImageBitmap OffscreenCanvas WebAssembly WorkerGlobalScope DedicatedWorkerGlobalScope trustedTypes TrustedTypePolicyFactory SharedArrayBuffer Atomics".split(" ");function $s(t,e,i){let r=self,n=t.nonce,s=t.engineSrc,a=t.allowedScriptUrl,o=t.allowClientScripts,l=t.revoked,y=r.postMessage.bind(r),f=null;try{f=i?i(r.CompressionStream):null}catch{}let b=null;function h(N,P){let E=()=>P&&P.length?y(N,P):y(N);b?b=b.then(E,E):E()}function d(N){h({type:"ERROR",nonce:n,message:String(N)})}let v=typeof r.importScripts=="function"?r.importScripts.bind(r):null,M=a,m=null;try{let N=s;if(typeof r.trustedTypes<"u"&&r.trustedTypes&&typeof r.trustedTypes.createPolicy=="function")try{let P={createScriptURL:function(T){if(T!==s&&(!a||T!==a))throw new TypeError("Disallowed worker importScripts URL");return T}};o&&(P.createScript=function(T){return String(T)});let E=r.trustedTypes.createPolicy("three-live#worker-boot",P);N=E.createScriptURL(s),a&&(M=E.createScriptURL(a)),o&&typeof E.createScript=="function"&&(m=E.createScript.bind(E))}catch{}v(N)}catch(N){d('Sandbox failed to load "'+s+'" (must be an IIFE bundle like three-live.min.js): '+(N&&N.message||N));return}let u=r.THREE;if(!u||typeof u.Scene!="function"){d('Sandbox "'+s+'" did not install THREE; point sandboxEngineSrc at three-live.min.js.');return}if(Array.isArray(e)){let N=r.__THREE_LIVE_REGISTRY__;for(let P=0;P<e.length;P++)if(typeof e[P]=="function")try{e[P](u,N)}catch{}}function g(N,P,E){let T=r;for(;T&&T!==Object.prototype;){if(!E&&T!==r)try{delete T[N]}catch{}if(!E||T===r||Object.prototype.hasOwnProperty.call(T,N))try{Object.defineProperty(T,N,E?{value:P,writable:!1,configurable:!1}:{value:P,writable:!1,configurable:!1,enumerable:!1})}catch{}try{T=Object.getPrototypeOf(T)}catch{break}}}for(let N=0;N<l.length;N++)g(l[N],void 0);g("performance",Object.freeze({now:function(){return Date.now()}}));let p=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],x=!1;function w(N,P){if(N.type==="3D_MODEL_READY"){if(x)return;x=!0}if(N.nonce=n,N.type==="3D_MODEL_READY"&&f&&N.glbBuffer instanceof ArrayBuffer){let E=N.glbBuffer;b=(b||Promise.resolve()).then(()=>f.glb(new Uint8Array(E))).then(T=>{T.buffer!==E&&(N.glbBuffer=T.byteOffset===0&&T.byteLength===T.buffer.byteLength?T.buffer:T.slice().buffer),y(N,[N.glbBuffer])},()=>y(N,[E]));return}P&&P.length?h(N,P):h(N)}g("postMessage",function(N,P){if(!N||p.indexOf(N.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+p.join(", ")+").");w(N,P)},!0);let _=!1;r.onmessage=function(N){let P=N&&N.data;if(!P||P.nonce!==n||P.type!=="EXECUTE"&&P.type!=="EXECUTE_URL"||_)return;_=!0;let E=P.texturePack;if(E&&typeof E=="object"){let T=Object.create(null),S=0;for(let A of Object.keys(E)){let D=E[A],R=D&&D.size;S<64&&/^[0-9a-f]{16}$/.test(A)&&(R===256||R===512||R===1024)&&D.rgba instanceof Uint8Array&&D.rgba.length===R*R*4&&(T[A]=Object.freeze({size:R,rgba:D.rgba}),S++)}r.__three_live_texture_pack__=Object.freeze(T)}try{let T=new u.Scene,S=new u.PerspectiveCamera(60,1,.1,1e3),A=new u.WebGLRenderer({isSandboxed:!0});if(P.type==="EXECUTE_URL"){if(!a||P.scriptUrl!==a||typeof v!="function"){d("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let D=M||a,R=v;if(v=null,M=null,r.THREE=u,r.scene=T,r.camera=S,r.renderer=A,R(D),typeof r.__THREE_LIVE_SCENE__=="function"){let I=r.__THREE_LIVE_SCENE__(u,T,S,A);I&&typeof I.toGLB=="function"&&(T=I)}else r.scene&&typeof r.scene.toGLB=="function"&&(T=r.scene)}else{if(!o){d("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let D=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
|
|
369
351
|
return (function () {
|
|
370
|
-
`+
|
|
352
|
+
`+P.script+`
|
|
371
353
|
;
|
|
372
354
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
373
355
|
})();
|
|
374
356
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
375
|
-
`+
|
|
357
|
+
`+P.script+`
|
|
376
358
|
;
|
|
377
359
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
378
|
-
})();`);g=null;let P=I(w,v,S,D);P&&typeof P.toGLB=="function"&&(v=P)}if(!T){w.SceneQuotaValidator&&w.SceneQuotaValidator.validate(v);let I=v.toGLB(),P=I instanceof ArrayBuffer?I:I.buffer.slice(I.byteOffset,I.byteOffset+I.byteLength);x({type:"3D_MODEL_READY",glbBuffer:P},[P])}l({type:"DONE",nonce:r})}catch(v){h(v&&v.message||v)}}},l({type:"READY",nonce:r})}function 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};
|
|
360
|
+
})();`);m=null;let R=D(u,T,S,A);R&&typeof R.toGLB=="function"&&(T=R)}if(!x){u.SceneQuotaValidator&&u.SceneQuotaValidator.validate(T);let D=T.toGLB(),R=D instanceof ArrayBuffer?D:D.buffer.slice(D.byteOffset,D.byteOffset+D.byteLength);w({type:"3D_MODEL_READY",glbBuffer:R},[R])}h({type:"DONE",nonce:n})}catch(T){d(T&&T.message||T)}},h({type:"READY",nonce:n})}function ni(t,e,i){let r=i?.allowedScriptUrl??null,n=i?.allowClientScripts??r===null,s={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:n,revoked:Os},a=(ge().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${$s.toString()})(${JSON.stringify(s)},[${a}],(${di.toString()}));`}function br(t){t.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),t.onToast?.("Security Error: script timed out and was stopped.")}var ze=0;function xr(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Vs(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var zs=1024,Bs=256;function vr(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let i=t[e];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function ai(t,e){if(!t||typeof t!="object")return null;let i=t;if(i.nonce!==e)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,zs)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let n of r)if(!vr(n))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let n=Object.keys(r);if(n.length>1e3)return null;let s=Object.create(null),a=r;for(let o of n){if(o.length>Bs||o==="__proto__"||o==="constructor"||o==="prototype")return null;let l=a[o];if(!vr(l))return null;s[o]=l}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function Gs(t){let e=Vs(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Mr(t,e,i,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":i();return;case"ERROR":i(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Hs(t,e,i,r){let n=xr(),s=ni(e,n,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a=document.createElement("iframe");a.setAttribute("sandbox","allow-scripts"),a.setAttribute("aria-hidden","true"),a.tabIndex=-1,a.style.display="none",a.src=i,ze++;let o=!1,l=!1,y={modelDispatched:!1},f,b=()=>{if(o||l)return;let M=a.contentWindow;!M||typeof M.postMessage!="function"||(l=!0,M.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:n,workerSource:s,scriptUrl:t.scriptUrl,texturePack:t.texturePack??null}:{type:"SANDBOX_RUN",nonce:n,workerSource:s,script:t.script,texturePack:t.texturePack??null},"*"))},h=()=>{},d=M=>{if(o||!a.contentWindow||M.source!==a.contentWindow)return;let m=M.data;if(m&&typeof m=="object"&&m.type==="IFRAME_READY"){b();return}let u=ai(m,n);u&&Mr(u,r,h,y)};h=()=>{o||(o=!0,f!==void 0&&clearTimeout(f),ze=Math.max(0,ze-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},f=setTimeout(()=>{o||(h(),br(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",d),a.onload=()=>{b()},a.onerror=()=>{h(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let v=document.body||document.documentElement;if(!v||typeof v.appendChild!="function"){h();let M=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(M),M}return v.appendChild(a),{terminate:h}}function wr(t,e,i,r){if(e==="worker"&&typeof Worker>"u")return r("SecurityError: Web Workers are unavailable for sandboxed execution.","Security Error: Web Workers unavailable.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("SecurityError: DOM unavailable for iframe sandbox execution.","Security Error: DOM unavailable for iframe sandbox.");if(ze>=32)return r(`SecurityError: ${ze} workers running, meeting SECURITY_3D_MAX_CONCURRENT_TASKS (32).`,"Security Error: too many concurrent sandboxed scripts.");let n;try{n=Ds()}catch(h){let d=h instanceof Error?h.message:String(h);return r(d,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let h;try{h=Fs()}catch(d){let v=d instanceof Error?d.message:String(d);return r(v,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Hs(t,n,h,i))}catch(d){return Promise.reject(d)}}let s=xr(),a=ni(n,s,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let h=new Blob([a],{type:"application/javascript"}),d=URL.createObjectURL(h);try{let v=dr(d);o=new Worker(v)}finally{URL.revokeObjectURL(d)}}catch(h){let d=h instanceof Error?h.message:String(h);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}ze++;let l=!1,y={modelDispatched:!1},f,b=()=>{l||(l=!0,f!==void 0&&clearTimeout(f),ze=Math.max(0,ze-1),o.terminate())};return f=setTimeout(()=>{l||(b(),br(i))},3e3),o.onmessage=h=>{let d=ai(h.data,s);d&&Mr(d,i,b,y)},o.onerror=h=>{b(),i.onError?.(new Error(`Worker execution error: ${h.message}`))},t.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:s,texturePack:t.texturePack??null}):o.postMessage({type:"EXECUTE",script:t.script,nonce:s,texturePack:t.texturePack??null}),Promise.resolve({terminate:b})}function Sr(t,e){return t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox="${t}"; require "worker" or "iframe".`,`Security Error: sandbox="${t}" is not permitted.`):null}var Tr=t=>(e,i)=>{let r=new Error(e);return t.onError?.(r),i&&t.onToast?.(i),Promise.reject(r)},Ar={execute(t,e,i,r){let n=Tr(i),s=Sr(e,n);if(s)return s;try{Gs(t)}catch(a){let o=a instanceof Error?a.message:String(a);return n(o,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??yr()?wr({kind:"script",script:t,texturePack:r?.texturePack},e,i,n):n(rs,ss)},executeUrl(t,e,i,r){let n=Tr(i),s=Sr(e,n);if(s)return s;let a;try{a=Us(t)}catch(o){let l=o instanceof Error?o.message:String(o);return n(l,"Security Error: disallowed scene script URL.")}return wr({kind:"url",scriptUrl:a,texturePack:r?.texturePack},e,i,n)}},St=new Set;function Be(t,e){let i=`[three-live] ${t} is unsupported; degraded to ${e}.`;St.has(i)||(St.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function _r(){return Array.from(St)}function Pr(){St.clear()}var oi=class extends it{constructor(t={}){Be("ShaderMaterial","MeshStandardMaterial");let e=t.uniforms||{},i=e.color?.value??e.uColor?.value??e.diffuse?.value??t.color;super({color:i!==void 0?i:8421504,opacity:e.opacity?.value??t.opacity??1,transparent:!!t.transparent,wireframe:!!t.wireframe,side:t.side}),this.uniforms=e}},Cr=oi,We=class extends Me{constructor(t=[],e=[],i=1,r=0){super();let n=Number(i)||1,s=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),a=s+1,o=[],l=[],y=[],f=[],b=new ee,h=new ee,d=new ee,v=(u,g)=>g.set(t[u*3]||0,t[u*3+1]||0,t[u*3+2]||0),M=(u,g)=>{let p=u.clone().normalize();o.push(p.x*n,p.y*n,p.z*n),l.push(g.x,g.y,g.z),y.push(Math.atan2(p.z,-p.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,p.y)))/Math.PI)},m=(u,g,p)=>{let x=o.length/3,w=s===0?new ee().subVectors(p,g).cross(new ee().subVectors(u,g)).normalize():null;M(u,w||u.clone().normalize()),M(g,w||g.clone().normalize()),M(p,w||p.clone().normalize()),f.push(x,x+1,x+2)};for(let u=0;u<e.length;u+=3){v(e[u],b),v(e[u+1],h),v(e[u+2],d);let g=[];for(let p=0;p<=a;p++){g[p]=[];let x=b.clone().lerp(d,p/a),w=h.clone().lerp(d,p/a),_=a-p;for(let N=0;N<=_;N++)g[p][N]=_===0?x.clone():x.clone().lerp(w,N/_)}for(let p=0;p<a;p++)for(let x=0;x<2*(a-p)-1;x++){let w=x>>1;(x&1)===0?m(g[p][w+1],g[p+1][w],g[p][w]):m(g[p][w+1],g[p+1][w+1],g[p+1][w])}}this.setFromBuffers(o,l,y,f)}},js=We,Rr=class extends We{constructor(t=1,e=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],t,e)}},li=t=>Array.from(t,e=>parseInt(e,36)),Tt=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],Er=li("024043035052125153134142"),Lr=class extends We{constructor(t=1,e=0){super(Tt,Er,t,e)}},pe=(1+Math.sqrt(5))/2,Nr=class extends We{constructor(t=1,e=0){super([-1,pe,0,1,pe,0,-1,-pe,0,1,-pe,0,0,-1,pe,0,1,pe,0,-1,-pe,0,1,-pe,pe,0,-1,pe,0,1,-pe,0,-1,-pe,0,1],li("0b505101707a0ab1595b4ba2a7671839434232636838949524b62a867981"),t,e)}},Re=1/pe,Dr=class extends We{constructor(t=1,e=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-Re,-pe,0,-Re,pe,0,Re,-pe,0,Re,pe,-Re,-pe,0,-Re,pe,0,Re,-pe,0,Re,pe,0,-pe,0,-Re,pe,0,-Re,-pe,0,Re,pe,0,Re],li("3b737f3fd7jh7h676fh48h8aha680g8g282a0c101i0ig6a262d6df2gi2i323di19i9bib34ec4c0408b95b5jbj7j5eje4j4h1ce1e5159"),t,e)}},Ir=class extends Xt{constructor(t=1,e=1,i=4,r=8){let n=Math.max(1e-4,Number(t)||1),s=Math.max(0,Number.isFinite(Number(e))?Number(e):1)*.5,a=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),o=[];for(let l=-1;l<=1;l+=2)for(let y=0;y<=a;y++){if(l>0&&y===0&&s===0)continue;let f=(l<0?y/a-1:y/a)*(Math.PI/2);o.push(new Pe(Math.max(0,Math.cos(f)*n),l*s+Math.sin(f)*n))}super(o,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},hi=class extends Me{constructor(t=.5,e=1,i=32,r=1,n=0,s=Math.PI*2){super();let a=Math.max(1e-4,Number(e)||1),o=Number(t),l=Number.isFinite(o)?Math.max(0,o):a*.5,y=Math.max(a,l),f=Math.min(y*.999,Math.min(a,l)),b=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),h=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),d=Number.isFinite(Number(n))?Number(n):0,v=Number.isFinite(Number(s))?Number(s):Math.PI*2,M=[],m=[],u=[],g=[];for(let p=0;p<=h;p++){let x=f+p/h*(y-f);for(let w=0;w<=b;w++){let _=d+w/b*v,N=Math.cos(_),P=Math.sin(_);if(M.push(x*N,x*P,0),m.push(0,0,1),u.push(x/y*N*.5+.5,x/y*P*.5+.5),p<h&&w<b){let E=p*(b+1)+w,T=E+b+1;x>1e-6&&g.push(E,T,E+1),g.push(T,T+1,E+1)}}}this.setFromBuffers(M,m,u,g)}},Fr=class extends hi{constructor(t=1,e=32,i=0,r=Math.PI*2){super(0,t,e,1,i,r)}},ui=class extends Ne{constructor(t={}){super({roughness:.35,metalness:.1,side:2,...t});let e=Number(t.size);this.size=Number.isFinite(e)?Math.max(.002,Math.min(2,e)):.05,this.sizeAttenuation=t.sizeAttenuation!==!1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},At=class extends Ne{constructor(t={}){super({roughness:.4,metalness:.1,side:2,...t});let e=Number(t.linewidth);this.linewidth=Number.isFinite(e)?Math.max(.5,Math.min(20,e)):1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},kr=class extends At{constructor(t={}){super(t),this.dashSize=Number(t.dashSize)||3,this.gapSize=Number(t.gapSize)||1,this.scale=Number(t.scale)||1}};function Ur(t,e){let i=t?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,n=t?.index?.array,s=Math.min(8192,Math.floor((n?n.length:i.count)/3)),a=h=>`${Math.round((r[h*3]||0)*1e4)},${Math.round((r[h*3+1]||0)*1e4)},${Math.round((r[h*3+2]||0)*1e4)}`,o=e===void 0,l=o?1:Math.cos(e*Math.PI/180),y={},f=[],b=(h,d)=>f.push(r[h*3]||0,r[h*3+1]||0,r[h*3+2]||0,r[d*3]||0,r[d*3+1]||0,r[d*3+2]||0);for(let h=0;h<s;h++){let d=n?n[h*3]:h*3,v=n?n[h*3+1]:h*3+1,M=n?n[h*3+2]:h*3+2,m=r[d*3]||0,u=r[d*3+1]||0,g=r[d*3+2]||0,p=(r[v*3]||0)-m,x=(r[v*3+1]||0)-u,w=(r[v*3+2]||0)-g,_=(r[M*3]||0)-m,N=(r[M*3+1]||0)-u,P=(r[M*3+2]||0)-g,E=x*P-w*N,T=w*_-p*P,S=p*N-x*_,A=Math.hypot(E,T,S);if(!o&&A<1e-8)continue;A>0&&(E/=A,T/=A,S/=A);let D=[d,v,M];for(let R=0;R<3;R++){let I=D[R],k=D[(R+1)%3],V=a(I),L=a(k);if(V===L)continue;let O=V<L?`${V}|${L}`:`${L}|${V}`,c=y[O];c?c.m||(c.m=1,c.nx*E+c.ny*T+c.nz*S<=l&&b(I,k)):(y[O]={va:I,vb:k,nx:E,ny:T,nz:S,m:o?1:0},o&&b(I,k))}}if(!o){let h=Object.keys(y);for(let d=0;d<h.length;d++){let v=y[h[d]];v&&!v.m&&b(v.va,v.vb)}}return new Float32Array(f)}var Or=class extends Me{constructor(t){super(),this.setAttribute("position",new Ae(Ur(t),3)),this.__isSegmentPairs=!0}},$r=class extends Me{constructor(t,e=1){super();let i=Number.isFinite(Number(e))?Number(e):1;this.setAttribute("position",new Ae(Ur(t,i),3)),this.__isSegmentPairs=!0}};function Ws(t,e,i=1){let r=new Me;r.__baked=!0;let n=t?.attributes?.position;if(!n?.array||n.count<2)return r;let s=n.array,a=t.index?.array,o=t.__isSegmentPairs?"segments":e,l=a?a.length:n.count,y=Math.min(4096,Math.max(0,o==="segments"?Math.floor(l/2):o==="loop"&&l>=3?l:l-1));if(y===0)return r;t.computeBoundingBox();let f=t.boundingBox,b=f&&f.max.x>=f.min.x&&f.max.distanceTo(f.min)||1,h=Math.max(.0015,Math.min(.025,b*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),d=[],v=[],M=[],m=[];for(let u=0;u<y;u++){let g=o==="segments"?u*2:u,p=o==="segments"?u*2+1:(u+1)%l,x=a?a[g]:g,w=a?a[p]:p,_=s[x*3]||0,N=s[x*3+1]||0,P=s[x*3+2]||0,E=(s[w*3]||0)-_,T=(s[w*3+1]||0)-N,S=(s[w*3+2]||0)-P,A=Math.hypot(E,T,S);if(A<1e-6)continue;let D=E/A,R=T/A,I=S/A,k=(Math.abs(R)<.9?Math.hypot(I,D):Math.hypot(I,R))||1,V=Math.abs(R)<.9?I/k:0,L=Math.abs(R)<.9?0:-I/k,O=Math.abs(R)<.9?-D/k:R/k,c=R*O-I*L,F=I*V-D*O,C=D*L-R*V,U=d.length/3,H=[[V,L,O],[c,F,C],[-V,-L,-O],[-c,-F,-C]];for(let j=0;j<2;j++){let Y=_+j*E,q=N+j*T,ne=P+j*S;for(let ie=0;ie<4;ie++){let oe=H[ie];d.push(Y+oe[0]*h,q+oe[1]*h,ne+oe[2]*h),v.push(oe[0],oe[1],oe[2]),M.push(ie/4,j)}}for(let j=0;j<4;j++){let Y=(j+1)%4;m.push(U+j,U+Y,U+4+Y,U+j,U+4+Y,U+4+j)}}return d.length>0&&r.setFromBuffers(d,v,M,m),r}function Xs(t,e=.05){let i=new Me;i.__baked=!0;let r=t?.attributes?.position;if(!r?.array||r.count<1)return i;let n=r.array,s=r.count,a=Math.min(s,5e3),o=Math.max(.003,Math.min(.25,(Number(e)||.05)*.6)),l=[],y=[],f=[],b=[];for(let h=0;h<a;h++){let d=s<=5e3?h:Math.floor(h*s/a),v=n[d*3]||0,M=n[d*3+1]||0,m=n[d*3+2]||0,u=h*6;for(let g=0;g<6;g++){let p=Tt[g*3],x=Tt[g*3+1],w=Tt[g*3+2];l.push(v+p*o,M+x*o,m+w*o),y.push(p,x,w),f.push(.5,.5)}for(let g=0;g<24;g++)b.push(u+Er[g])}return i.setFromBuffers(l,y,f,b),i}var Ye=class extends $e{constructor(t,e,i="strip"){let r=e&&typeof e=="object"?e:{},n=e instanceof Ne?e:i==="points"?new ui(r):new At(r),s=t instanceof Me?t:new Me;super(s,n),this.isLine=!0,this._lineMode=i,this._sourceGeo=s}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let t=this._lineMode==="points";if(t){let e=this._sourceGeo?.attributes?.color;if(e?.array&&e.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=e.array,r=Math.min(e.count,64),n=0,s=0,a=0;for(let o=0;o<r;o++)n+=i[o*3]||0,s+=i[o*3+1]||0,a+=i[o*3+2]||0;this.material.color.setRGB(n/r,s/r,a/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(t?1:2)&&(this.geometry=t?Xs(this._sourceGeo,this.material?.size??.05):Ws(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},Vr=class extends Ye{constructor(t,e){super(t,e,"loop"),this.isLineLoop=!0}},zr=class extends Ye{constructor(t,e){super(t,e,"segments"),this.isLineSegments=!0}},Br=class extends Ye{constructor(t,e){super(t,e,"points"),this.isPoints=!0}},Gr=class extends Jt{constructor(t,e,i=0,r=Math.PI/3,n=0,s=2){super(t,e,i,s),this.target=new Fe,this.type="spot";let a=Number(r);this.angle=Number.isFinite(a)?Math.max(.01,Math.min(Math.PI/2,a)):Math.PI/3;let o=Number(n);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},ci=class extends je{constructor(t,e,i){super(t,i),this.type="hemisphere",this.groundColor=new Ie(e??4473924),this.position.set(0,1,0)}},Hr=class extends Zt{constructor(t,e){Be("RectAreaLight","AmbientLight"),super(t,e)}},jr={Vector2:Pe,Vector3:ee,Vector4:Fi,Euler:Gt,Quaternion:bt,Matrix4:qe,Matrix3:ki,Color:Ie,MathUtils:Oi,BufferAttribute:Ae,Float32BufferAttribute:$i,Uint16BufferAttribute:Vi,Uint32BufferAttribute:zi,BufferGeometry:Me,BoxGeometry:jt,PlaneGeometry:Bi,SphereGeometry:Gi,CylinderGeometry:Wt,ConeGeometry:Hi,TorusGeometry:ji,TorusKnotGeometry:Xi,Curve:He,Curve3:He,LineCurve3:qi,QuadraticBezierCurve3:Ki,CubicBezierCurve3:Yi,CatmullRomCurve3:Zi,LatheGeometry:Xt,TubeGeometry:Ji,PolyhedronGeometry:We,IcosahedronGeometry:Nr,OctahedronGeometry:Lr,DodecahedronGeometry:Dr,TetrahedronGeometry:Rr,CapsuleGeometry:Ir,RingGeometry:hi,CircleGeometry:Fr,WireframeGeometry:Or,EdgesGeometry:$r,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,BasicShadowMap:0,PCFShadowMap:1,PCFSoftShadowMap:2,VSMShadowMap:3,Texture:Mt,DataTexture:Qi,TextureLoader:er,Material:Ne,MeshStandardMaterial:it,MeshBasicMaterial:tr,MeshLambertMaterial:ir,MeshPhongMaterial:rr,MeshPhysicalMaterial:sr,PointsMaterial:ui,LineBasicMaterial:At,LineDashedMaterial:kr,ShaderMaterial:oi,RawShaderMaterial:Cr,Object3D:Fe,Group:nr,Mesh:$e,InstancedMesh:Kt,Line:Ye,LineLoop:Vr,LineSegments:zr,Points:Br,LightShadow:Yt,Light:je,AmbientLight:Zt,DirectionalLight:or,PointLight:Jt,SpotLight:Gr,HemisphereLight:ci,RectAreaLight:Hr,Camera:Qt,PerspectiveCamera:lr,Scene:ei,WebGLRenderer:ur,Clock:mr,SceneQuotaValidator:Ve,exportSceneToCanvas3D:ti,exportSceneToGLB:ii,exportSceneToUSDZ:hr,generateUSDZ:Ii,glbToUSDZ:Bt,sceneToCanvas3D:Qe,sceneToGLB:pt,sceneToUSDZ:yt,authorScriptRunner:Ar,warnUnsupported:Be,getAuthorWarnings:_r,clearAuthorWarnings:Pr};Object.freeze(Ve),Object.freeze(Ve.prototype),Object.freeze(ei.prototype),Object.freeze(jr);var Xe=new Proxy(jr,{get:(t,e)=>{if(e in t)return t[e];let i=ge().authorNamespace;return i&&typeof e=="string"&&e in i?i[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&Be(`THREE.${e}`,"no-op proxy"),st)},has:(t,e)=>{if(e in t)return!0;let i=ge().authorNamespace;return!!(i&&typeof e=="string"&&e in i)},set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),_t=ge();if(_t.threeNamespace=Xe,_t.workerExtensionInstallers)for(let t of _t.workerExtensionInstallers)t(Xe,_t);var at={name:"three_author",THREE:Xe},qs=at,ke=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof ke.THREE>"u"&&(ke.THREE=Xe),typeof ke.requestAnimationFrame!="function"&&(ke.requestAnimationFrame=t=>(typeof t=="function"&&typeof ke.__three_live_raf_cb__!="function"&&(ke.__three_live_raf_cb__=t),ke.__three_live_in_step__||Be("requestAnimationFrame","single-frame static evaluation"),0)),typeof ke.cancelAnimationFrame!="function"&&(ke.cancelAnimationFrame=()=>{}),typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=Xe,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=at,t.ThreeLivePlugins.three_author=at,t.ThreeLivePlugins["three-author"]=at}var Ks=Xe;export{Zt as AmbientLight,jt as BoxGeometry,Ae as BufferAttribute,Me as BufferGeometry,Qt as Camera,Ir as CapsuleGeometry,Zi as CatmullRomCurve3,Fr as CircleGeometry,mr as Clock,Ie as Color,Hi as ConeGeometry,Yi as CubicBezierCurve3,He as Curve3,Wt as CylinderGeometry,Qi as DataTexture,or as DirectionalLight,Dr as DodecahedronGeometry,$r as EdgesGeometry,Gt as Euler,$i as Float32BufferAttribute,nr as Group,ci as HemisphereLight,Nr as IcosahedronGeometry,Kt as InstancedMesh,Xt as LatheGeometry,je as Light,Yt as LightShadow,Ye as Line,At as LineBasicMaterial,qi as LineCurve3,kr as LineDashedMaterial,Vr as LineLoop,zr as LineSegments,rt as MAX_INSTANCES_PER_MESH,Ne as Material,Oi as MathUtils,ki as Matrix3,qe as Matrix4,$e as Mesh,tr as MeshBasicMaterial,ir as MeshLambertMaterial,rr as MeshPhongMaterial,sr as MeshPhysicalMaterial,it as MeshStandardMaterial,Fe as Object3D,Lr as OctahedronGeometry,lr as PerspectiveCamera,Bi as PlaneGeometry,Jt as PointLight,Br as Points,ui as PointsMaterial,js as PolyhedronFallbackGeometry,We as PolyhedronGeometry,Ki as QuadraticBezierCurve3,bt as Quaternion,Cr as RawShaderMaterial,Hr as RectAreaLight,hi as RingGeometry,ei as Scene,Ve as SceneQuotaValidator,oi as ShaderMaterial,Gi as SphereGeometry,Gr as SpotLight,Xe as THREE,Rr as TetrahedronGeometry,Mt as Texture,er as TextureLoader,ji as TorusGeometry,Xi as TorusKnotGeometry,Ji as TubeGeometry,Vi as Uint16BufferAttribute,zi as Uint32BufferAttribute,Pe as Vector2,ee as Vector3,Fi as Vector4,ur as WebGLRenderer,Or as WireframeGeometry,Ar as authorScriptRunner,ni as buildSandboxWorkerSource,Pr as clearAuthorWarnings,Ks as default,ti as exportSceneToCanvas3D,ii as exportSceneToGLB,hr as exportSceneToUSDZ,Ii as generateUSDZ,yr as getAllowClientScripts,_r as getAuthorWarnings,ri as getSandboxEngineSrc,gr as getSandboxIframeSrc,Bt as glbToUSDZ,Ke as isAllowedSandboxEngineUrl,st as noopProxy,Qe as sceneToCanvas3D,pt as sceneToGLB,yt as sceneToUSDZ,ks as setAllowClientScripts,Ns as setSandboxEngineSrc,Is as setSandboxIframeSrc,at as threeAuthorPlugin,qs as threeMicroPlugin,dr as toTrustedWorkerScriptURL,ai as validateSandboxWorkerMessage,Be as warnUnsupported};
|