three-live 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/three-author-engine.js +89 -62
- package/dist/three-author.cjs +86 -59
- package/dist/three-author.d.ts +1 -0
- package/dist/three-author.js +86 -59
- package/dist/three-convert.cjs +79 -52
- package/dist/three-convert.d.ts +1 -0
- package/dist/three-convert.js +80 -53
- package/dist/three-live-animation.d.ts +1 -0
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +1 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +2 -2
- package/dist/three-live-element.d.ts +1 -0
- package/dist/three-live-element.js +2 -2
- package/dist/three-live-full.cjs +94 -67
- package/dist/three-live-full.js +102 -75
- package/dist/three-live-full.min.js +95 -68
- package/dist/three-live-studio.d.ts +1 -0
- package/dist/three-live-viewer.cjs +2 -2
- package/dist/three-live-viewer.d.ts +1 -0
- package/dist/three-live-viewer.js +2 -2
- package/dist/three-live-viewer.min.js +2 -2
- package/dist/three-live.cjs +85 -58
- package/dist/three-live.js +85 -58
- package/dist/three-live.min.js +85 -58
- package/dist/three-view.d.ts +1 -0
- package/dist/three-xr.cjs +80 -53
- package/dist/three-xr.d.ts +1 -0
- package/dist/three-xr.js +83 -56
- package/package.json +19 -1
package/dist/three-convert.cjs
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/var Ge=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,Dt=Object.getOwnPropertyNames,Et=Object.prototype.hasOwnProperty,St=(t,e)=>{for(var i in e)Ge(t,i,{get:e[i],enumerable:!0})},Pt=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Dt(e))!Et.call(t,a)&&a!==i&&Ge(t,a,{get:()=>e[a],enumerable:!(r=Rt(e,a))||r.enumerable});return t},Ct=t=>Pt(Ge({},"__esModule",{value:!0}),t),Yt={};St(Yt,{buildUSDZZip:()=>Mt,calculateCRC32:()=>xt,compileInteractivityGraph:()=>Oe,createUSDZBlob:()=>qt,encodeUtf8:()=>Ne,extractMeshesFromGLB:()=>Be,extractMeshesFromScene:()=>yt,generateUSDA:()=>vt,generateUSDAFromMeshes:()=>Fe,generateUSDZ:()=>wt,glbToUSDZ:()=>At,sanitizeUsdIdentifier:()=>we,sanitizeUsdStringLiteral:()=>_e,sceneToCanvas3D:()=>bt,sceneToGLB:()=>Wt,sceneToUSDZ:()=>Kt}),module.exports=Ct(Yt);function Oe(t,e,i){let r=[],a=new Map,s=[],m=[],f=[],p=new Map,u=h=>{let n=a.get(h);return n===void 0&&(n=r.length,r.push({op:h}),a.set(h,n)),n},d=h=>{let n=p.get(h);return n===void 0&&(n=f.length,f.push({id:h}),p.set(h,n)),n},y=(h,n={})=>s.push({declaration:u(h),...n})-1,R=(h,n,b)=>m.push({id:h,type:n,value:b})-1,S=h=>({node:h,socket:"value"}),l=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(l&&typeof l=="object"){let h=Array.isArray(l.graphs)?l.graphs[l.graph??0]:l;if(h&&Array.isArray(h.nodes)){let n=Array.isArray(h.declarations)?h.declarations:[];for(let b of n)b?.op&&u(b.op);Array.isArray(h.variables)&&m.push(...h.variables);for(let b of h.events||[])b?.id&&d(b.id);for(let b of h.nodes){if(!b||typeof b!="object")continue;let A=b.op||(typeof b.declaration=="number"?n[b.declaration]?.op:"");s.push(A?{...b,declaration:u(A)}:{...b})}}}let x=(h,n,b="translation")=>b==="baseColorFactor"||b==="metallicFactor"||b==="roughnessFactor"?`/materials/${Math.max(0,n)}/pbrMetallicRoughness/${b}`:b==="emissiveFactor"||b==="alphaCutoff"?`/materials/${Math.max(0,n)}/${b}`:b==="visible"?`/nodes/${h}/extensions/KHR_node_visibility/visible`:`/nodes/${h}/${b}`,T=new Map;t.forEach((h,n)=>{typeof h?.name=="string"&&!T.has(h.name)&&T.set(h.name,n)});let w=(h,n)=>typeof h.target=="string"&&T.has(h.target)?T.get(h.target):typeof h.targetNode=="number"?h.targetNode:n,v=h=>{let n=t[h];return(typeof n?.mesh=="number"?e[n.mesh]?.primitives?.[0]?.material:0)??0};for(let h=0;h<t.length;h++){let n=t[h],b=n?.extras?.interactivity;if(!b||typeof b!="object")continue;let A=(typeof n.mesh=="number"?e[n.mesh]?.primitives?.[0]?.material:0)??0,$=_=>{let L=Array.isArray(_)?_:[_],C=[];for(let M=0;M<L.length;M++){let o=L[M];if(!o||typeof o!="object")continue;let V=o.action||"interpolate",X=typeof o.duration=="number"?o.duration:.35;if(V==="toggleTransform"){let g=o.property==="rotation"||o.property==="scale"?o.property:"translation",I=g==="rotation"?n.rotation||[0,0,0,1]:g==="scale"?n.scale||[1,1,1]:n.translation||[0,0,0],c=`/nodes/${h}/${g}`,P=R(`__toggle_${h}_${M}`,"bool",!1),j=y("variable/get",{configuration:{variable:P}}),G=y("math/not",{values:{a:S(j)}}),U=y("variable/set",{configuration:{variable:P},values:{value:S(G)}}),Z=y("pointer/interpolate",{configuration:{pointer:c},values:{value:{value:Array.isArray(o.to)?o.to:I},duration:{value:X}}}),E=y("pointer/interpolate",{configuration:{pointer:c},values:{value:{value:Array.isArray(o.from)?o.from:I},duration:{value:X}}});s[U].flows={out:{node:y("flow/branch",{values:{condition:S(j)},flows:{true:{node:Z},false:{node:E}}})}},C.push(U)}else if(V==="interpolate"){let g=o.to??o.value;if(g===void 0)continue;let I={value:{value:g},duration:{value:X}};o.from!==void 0&&(I.from={value:o.from}),C.push(y("pointer/interpolate",{configuration:{pointer:typeof o.pointer=="string"?o.pointer:x(w(o,h),v(w(o,h)),o.property)},values:I}))}else if(V==="setProperty"){if(o.value===void 0)continue;C.push(y("pointer/set",{configuration:{pointer:typeof o.pointer=="string"?o.pointer:x(w(o,h),v(w(o,h)),o.property)},values:{value:{value:o.value}}}))}else if(V==="toggleVisibility"){let g=w(o,h),I=R(`__vis_${g}_${M}`,"bool",!0),c=y("variable/get",{configuration:{variable:I}}),P=y("math/not",{values:{a:S(c)}}),j=y("variable/set",{configuration:{variable:I},values:{value:S(P)}});s[j].flows={out:{node:y("pointer/set",{configuration:{pointer:`/nodes/${g}/extensions/KHR_node_visibility/visible`},values:{value:S(c)}})}},C.push(j)}else if(V==="cycleMaterialColor"&&Array.isArray(o.colors)&&o.colors.length>0){let g=typeof o.duration=="number"?o.duration:.25,I=`/materials/${Math.max(0,A)}/pbrMetallicRoughness/baseColorFactor`,c=R(`__color_idx_${h}_${M}`,"int",0),P=y("variable/get",{configuration:{variable:c}}),j=y("math/add",{values:{a:S(P),b:{value:1}}}),G=y("math/rem",{values:{a:S(j),b:{value:o.colors.length}}}),U=y("variable/set",{configuration:{variable:c},values:{value:S(G)}}),Z={};for(let E=0;E<o.colors.length;E++){let q=o.colors[E],k=Array.isArray(q)&&q.length>=3?[q[0],q[1],q[2],q[3]??1]:[1,1,1,1];Z[String(E)]={node:g>0?y("pointer/interpolate",{configuration:{pointer:I},values:{value:{value:k},duration:{value:g}}}):y("pointer/set",{configuration:{pointer:I},values:{value:{value:k}}})}}s[U].flows={out:{node:y("flow/switch",{values:{selection:S(P)},flows:Z})}},C.push(U)}else if(V==="playAnimation")C.push(y("animation/start",{configuration:{animation:o.animation??o.clip??0}}));else if(V==="stopAnimation")C.push(y("animation/stop"));else if(V==="sendEvent"){let g={};for(let[I,c]of Object.entries(o.values||{}))g[I]={value:c};C.push(y("event/send",{configuration:{event:d(String(o.event??o.id??"custom"))},values:g}))}}if(!C.length)return null;if(C.length===1)return C[0];let D={};return C.forEach((M,o)=>{D[String(o)]={node:M}}),y("flow/sequence",{flows:D})},B=(_,L,C)=>{let D=$(L);D!==null&&y(_,{...C?{configuration:C}:{},flows:{out:{node:D}}})};if(b.onSelect&&B("pointer/onSelect",b.onSelect,{nodeIndex:h}),b.onHoverIn&&B("pointer/onHoverIn",b.onHoverIn,{nodeIndex:h}),b.onHoverOut&&B("pointer/onHoverOut",b.onHoverOut,{nodeIndex:h}),b.onStart&&B("event/onStart",b.onStart),b.onReceive&&typeof b.onReceive=="object")for(let[_,L]of Object.entries(b.onReceive))B("event/receive",L,{event:d(_)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:m,events:f}],graph:0}:null}var De="__THREE_LIVE_REGISTRY__";function de(){let t=typeof globalThis<"u"?globalThis:{};if(!t[De]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,De,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[De]=e}}return t[De]}var ue=de().plugins;function Ke(t){let e=de().plugins;e.some(i=>i.name===t.name)||e.push(t),t.onRegister?.()}function qe(){return de().plugins}var Lt={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Ve(t,e,i,r){if(!i||i.bufferView===void 0)return null;let a=t.bufferViews?.[i.bufferView];if(!a)return null;let s=Number(i.count??0);if(!Number.isInteger(s)||s<=0)return null;let m=i.componentType??5126,f=Lt[m];if(!f)throw new RangeError(`glTF accessor has unsupported componentType ${m}`);let p=f*r,u=a.byteStride&&a.byteStride>0?a.byteStride:p,d=(a.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(d)||d<0||u<p||d+(s-1)*u+p>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(m===5126&&u===p&&d%4===0)return new Float32Array(e,d,s*r);let y=new DataView(e),R=i.normalized===!0,S=new Float32Array(s*r);for(let l=0;l<s;l++){let x=d+l*u;for(let T=0;T<r;T++){let w=x+T*f,v;switch(m){case 5126:v=y.getFloat32(w,!0);break;case 5120:v=y.getInt8(w),R&&(v=Math.max(v/127,-1));break;case 5121:v=y.getUint8(w),R&&(v/=255);break;case 5122:v=y.getInt16(w,!0),R&&(v=Math.max(v/32767,-1));break;case 5123:v=y.getUint16(w,!0),R&&(v/=65535);break;default:v=y.getUint32(w,!0),R&&(v/=4294967295)}S[l*r+T]=v}}return S}function Ye(t,e){let i=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,a=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),m=Number(e.rotation??0)||0,f=Math.cos(m),p=Math.sin(m),u=(Number.isFinite(a)?a:1)*f,d=(Number.isFinite(a)?a:1)*p,y=-(Number.isFinite(s)?s:1)*p,R=(Number.isFinite(s)?s:1)*f;for(let S=0;S+1<t.length;S+=2){let l=t[S],x=t[S+1];t[S]=u*l+d*x+i,t[S+1]=y*l+R*x+r}}function Ee(t,e,i,r=!0){let a=[],s=null;try{for(let[m,f]of[[35633,e],[35632,i]]){let p=t.createShader(m);if(!p){if(r)throw new Error("Shader allocation failed");return null}if(a.push(p),t.shaderSource(p,f),t.compileShader(p),t.getShaderParameter&&!t.getShaderParameter(p,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(p)}`);return null}}if(s=t.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let m of a)t.attachShader(s,m);if(t.linkProgram(s),t.getProgramParameter&&!t.getProgramParameter(s,35714)){let m=r?t.getProgramInfoLog(s):null;if(t.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${m}`);return null}return s}finally{for(let m of a)s&&t.detachShader?.(s,m),t.deleteShader?.(m)}}function se(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Se(t,e,i,r,a){let s=1/Math.tan(e/2);t.fill(0),t[0]=s/i,t[5]=s,t[11]=-1;let m=1/(r-a);return t[10]=(a+r)*m,t[14]=2*a*r*m,t}function Pe(t,e,i,r){let[a,s,m]=e,[f,p,u]=r,[d,y,R]=i,S=a-d,l=s-y,x=m-R,T=Math.hypot(S,l,x);T<=1e-5?(S=0,l=0,x=1):(S/=T,l/=T,x/=T);let w=p*x-u*l,v=u*S-f*x,h=f*l-p*S;T=Math.hypot(w,v,h),T<=1e-5?(w=0,v=0,h=0):(w/=T,v/=T,h/=T);let n=l*h-x*v,b=x*w-S*h,A=S*v-l*w;return T=Math.hypot(n,b,A),T<=1e-5?(n=0,b=0,A=0):(n/=T,b/=T,A/=T),t[0]=w,t[1]=n,t[2]=S,t[3]=0,t[4]=v,t[5]=b,t[6]=l,t[7]=0,t[8]=h,t[9]=A,t[10]=x,t[11]=0,t[12]=-(w*a+v*s+h*m),t[13]=-(n*a+b*s+A*m),t[14]=-(S*a+l*s+x*m),t[15]=1,t}function me(t,e,i){let r=e[0],a=e[1],s=e[2],m=e[3],f=e[4],p=e[5],u=e[6],d=e[7],y=e[8],R=e[9],S=e[10],l=e[11],x=e[12],T=e[13],w=e[14],v=e[15],h=i[0],n=i[1],b=i[2],A=i[3];return t[0]=h*r+n*f+b*y+A*x,t[1]=h*a+n*p+b*R+A*T,t[2]=h*s+n*u+b*S+A*w,t[3]=h*m+n*d+b*l+A*v,h=i[4],n=i[5],b=i[6],A=i[7],t[4]=h*r+n*f+b*y+A*x,t[5]=h*a+n*p+b*R+A*T,t[6]=h*s+n*u+b*S+A*w,t[7]=h*m+n*d+b*l+A*v,h=i[8],n=i[9],b=i[10],A=i[11],t[8]=h*r+n*f+b*y+A*x,t[9]=h*a+n*p+b*R+A*T,t[10]=h*s+n*u+b*S+A*w,t[11]=h*m+n*d+b*l+A*v,h=i[12],n=i[13],b=i[14],A=i[15],t[12]=h*r+n*f+b*y+A*x,t[13]=h*a+n*p+b*R+A*T,t[14]=h*s+n*u+b*S+A*w,t[15]=h*m+n*d+b*l+A*v,t}function He(t,e,i,r){let a=e[0],s=e[1],m=e[2],f=e[3],p=a+a,u=s+s,d=m+m,y=a*p,R=a*u,S=a*d,l=s*u,x=s*d,T=m*d,w=f*p,v=f*u,h=f*d,n=r[0],b=r[1],A=r[2];return t[0]=(1-(l+T))*n,t[1]=(R+h)*n,t[2]=(S-v)*n,t[3]=0,t[4]=(R-h)*b,t[5]=(1-(y+T))*b,t[6]=(x+w)*b,t[7]=0,t[8]=(S+v)*A,t[9]=(x-w)*A,t[10]=(1-(y+l))*A,t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1,t}function be(t,e,i=0){let r=e[0],a=e[1],s=e[2],m=e[4],f=e[5],p=e[6],u=e[8],d=e[9],y=e[10],R=y*f-p*d,S=-y*m+p*u,l=d*m-f*u,x=r*R+a*S+s*l;return!x||i>0&&(!Number.isFinite(x)||Math.abs(x)<=i)||(x=1/x,t[0]=R*x,t[1]=S*x,t[2]=l*x,t[3]=(-y*a+s*d)*x,t[4]=(y*r-s*u)*x,t[5]=(-d*r+a*u)*x,t[6]=(p*a-s*f)*x,t[7]=(-p*r+s*m)*x,t[8]=(f*r-a*m)*x),t}function Ze(t,e){let i=e[0],r=e[1],a=e[2],s=e[3],m=e[4],f=e[5],p=e[6],u=e[7],d=e[8],y=e[9],R=e[10],S=e[11],l=e[12],x=e[13],T=e[14],w=e[15],v=i*f-r*m,h=i*p-a*m,n=i*u-s*m,b=r*p-a*f,A=r*u-s*f,$=a*u-s*p,B=d*x-y*l,_=d*T-R*l,L=d*w-S*l,C=y*T-R*x,D=y*w-S*x,M=R*w-S*T,o=v*M-h*D+n*C+b*L-A*_+$*B;return o?(o=1/o,t[0]=(f*M-p*D+u*C)*o,t[1]=(a*D-r*M-s*C)*o,t[2]=(x*$-T*A+w*b)*o,t[3]=(R*A-y*$-S*b)*o,t[4]=(p*L-m*M-u*_)*o,t[5]=(i*M-a*L+s*_)*o,t[6]=(T*n-l*$-w*h)*o,t[7]=(d*$-R*n+S*h)*o,t[8]=(m*D-f*L+u*B)*o,t[9]=(r*L-i*D-s*B)*o,t[10]=(l*A-x*n+w*v)*o,t[11]=(y*n-d*A-S*v)*o,t[12]=(f*_-m*C-p*B)*o,t[13]=(i*C-r*_+a*B)*o,t[14]=(x*h-l*b-T*v)*o,t[15]=(d*b-y*h+R*v)*o,t):null}function $e(t,e,i,r,a){let s=a[0]*e+a[4]*i+a[8]*r+a[12],m=a[1]*e+a[5]*i+a[9]*r+a[13],f=a[2]*e+a[6]*i+a[10]*r+a[14],p=a[3]*e+a[7]*i+a[11]*r+a[15],u=p!==0?1/p:1;t[0]=s*u,t[1]=m*u,t[2]=f*u}function Je(t,e,i,r,a,s,m,f,p,u,d,y,R,S,l,x,T=0){let w=u-m,v=d-f,h=y-p,n=R-m,b=S-f,A=l-p,$=a*A-s*b,B=s*n-r*A,_=r*b-a*n,L=w*$+v*B+h*_;if(L>-1e-7&&L<1e-7)return!1;let C=1/L,D=t-m,M=e-f,o=i-p,V=C*(D*$+M*B+o*_);if(V<-T||V>1+T)return!1;let X=M*h-o*v,g=o*w-D*h,I=D*v-M*w,c=C*(r*X+a*g+s*I);if(c<-T||V+c>1+T)return!1;let P=C*(n*X+b*g+A*I);if(P>1e-4&&P<x.distance){x.distance=P,x.point=[t+r*P,e+a*P,i+s*P];let j=v*A-h*b,G=h*n-w*A,U=w*b-v*n,Z=Math.hypot(j,G,U)||1;return x.normal=[j/Z,G/Z,U/Z],!0}return!1}function Qe(t,e){let i=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let d=0;d<i;d++)r.push(se());if(i===0)return r;let a=new Set;for(let d of t.nodes)if(Array.isArray(d.children))for(let y of d.children)a.add(y);let s=new Set,m=128,f=(d,y,R=0)=>{if(R>m||d<0||d>=i||s.has(d))return;s.add(d);let S=t.nodes[d];if(!S)return;let l=se();if(e&&e[d])l.set(e[d]);else if(S.matrix&&S.matrix.length===16)l.set(S.matrix);else{let T=S.translation||[0,0,0],w=S.rotation||[0,0,0,1],v=S.scale||[1,1,1];He(l,w,T,v)}let x=r[d];if(y?me(x,y,l):x.set(l),Array.isArray(S.children))for(let T of S.children)typeof T=="number"&&f(T,x,R+1)},p=[],u=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(u&&Array.isArray(u.nodes))p.push(...u.nodes);else for(let d=0;d<i;d++)a.has(d)||p.push(d);for(let d of p)f(d,null);for(let d=0;d<i;d++)!a.has(d)&&!p.includes(d)&&f(d,null);return r}var nt=["neutral","reinhard","none","aces","agx"];function je(t){let e=String(t??"").trim().toLowerCase();return nt.includes(e)?e:"neutral"}function It(t){return nt.indexOf(je(t))}function _t(t){return new TextDecoder().decode(t)}var rt=de().decoders;function Ft(t,e){rt.set(t.toLowerCase(),e)}function Me(t){return rt.get(t.toLowerCase())}function it(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 R=i.getUint8(0);throw R===123||R===32||R===10||R===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 a=i.getUint32(4,!0);if(a!==2)throw new Error(`Unsupported GLB version: ${a}`);let s=i.getUint32(8,!0),m=12,f=null,p=null;for(;m+8<=s&&m+8<=e.byteLength;){let R=i.getUint32(m,!0),S=i.getUint32(m+4,!0),l=m+8;if(l+R>e.byteLength)throw new Error(`Truncated GLB chunk: required ${l+R} bytes, buffer has ${e.byteLength}`);if(S===1313821514){let x=new Uint8Array(e,l,R),T=_t(x);f=JSON.parse(T,(w,v)=>w==="__proto__"||w==="constructor"||w==="prototype"?void 0:v)}else S===5130562&&(p=e.slice(l,l+R));m=l+R}if(!f)throw new Error("Missing JSON chunk in GLB");let u=f.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!Me("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let R of["EXT_meshopt_compression","KHR_meshopt_compression"])if(u.includes(R)&&!Me("meshopt"))throw new Error(`Model requires ${R}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(u.includes("KHR_texture_basisu")&&!Me("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let d=p||new ArrayBuffer(0),y={gltf:f,bin:d,animations:[]};for(let R of ue)R.onParseGLB?.(y);return y}function Nt(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 Ae(t){if(Nt(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return it(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var st=`#version 300 es
|
|
16
|
+
*/var Oe=Object.defineProperty,wt=Object.getOwnPropertyDescriptor,Rt=Object.getOwnPropertyNames,Dt=Object.prototype.hasOwnProperty,St=(e,t)=>{for(var i in t)Oe(e,i,{get:t[i],enumerable:!0})},Et=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Rt(t))!Dt.call(e,a)&&a!==i&&Oe(e,a,{get:()=>t[a],enumerable:!(r=wt(t,a))||r.enumerable});return e},Pt=e=>Et(Oe({},"__esModule",{value:!0}),e),Yt={};St(Yt,{buildUSDZZip:()=>vt,calculateCRC32:()=>xt,compileInteractivityGraph:()=>Ve,createUSDZBlob:()=>qt,encodeUtf8:()=>Ue,extractMeshesFromGLB:()=>ke,extractMeshesFromScene:()=>qe,generateUSDA:()=>Xt,generateUSDAFromMeshes:()=>Be,generateUSDZ:()=>At,glbToUSDZ:()=>Tt,sanitizeUsdIdentifier:()=>Se,sanitizeUsdStringLiteral:()=>De,sceneToCanvas3D:()=>gt,sceneToGLB:()=>zt,sceneToUSDZ:()=>Kt}),module.exports=Pt(Yt);function Ve(e,t,i){let r=[],a=new Map,s=[],m=[],p=[],g=new Map,c=u=>{let l=a.get(u);return l===void 0&&(l=r.length,r.push({op:u}),a.set(u,l)),l},v=u=>{let l=g.get(u);return l===void 0&&(l=p.length,p.push({id:u}),g.set(u,l)),l},y=(u,l={})=>s.push({declaration:c(u),...l})-1,D=(u,l,M)=>m.push({id:u,type:l,value:M})-1,S=u=>({node:u,socket:"value"}),h=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(h&&typeof h=="object"){let u=Array.isArray(h.graphs)?h.graphs[h.graph??0]:h;if(u&&Array.isArray(u.nodes)){let l=Array.isArray(u.declarations)?u.declarations:[];for(let M of l)M?.op&&c(M.op);Array.isArray(u.variables)&&m.push(...u.variables);for(let M of u.events||[])M?.id&&v(M.id);for(let M of u.nodes){if(!M||typeof M!="object")continue;let P=M.op||(typeof M.declaration=="number"?l[M.declaration]?.op:"");s.push(P?{...M,declaration:c(P)}:{...M})}}}let b=(u,l,M="translation")=>M==="baseColorFactor"||M==="metallicFactor"||M==="roughnessFactor"?`/materials/${Math.max(0,l)}/pbrMetallicRoughness/${M}`:M==="emissiveFactor"||M==="alphaCutoff"?`/materials/${Math.max(0,l)}/${M}`:M==="visible"?`/nodes/${u}/extensions/KHR_node_visibility/visible`:`/nodes/${u}/${M}`,C=new Map;e.forEach((u,l)=>{typeof u?.name=="string"&&!C.has(u.name)&&C.set(u.name,l)});let A=(u,l)=>typeof u.target=="string"&&C.has(u.target)?C.get(u.target):typeof u.targetNode=="number"?u.targetNode:l,w=u=>{let l=e[u];return(typeof l?.mesh=="number"?t[l.mesh]?.primitives?.[0]?.material:0)??0};for(let u=0;u<e.length;u++){let l=e[u],M=l?.extras?.interactivity;if(!M||typeof M!="object")continue;let P=(typeof l.mesh=="number"?t[l.mesh]?.primitives?.[0]?.material:0)??0,$=F=>{let _=Array.isArray(F)?F:[F],T=[];for(let R=0;R<_.length;R++){let n=_[R];if(!n||typeof n!="object")continue;let E=n.action||"interpolate",G=typeof n.duration=="number"?n.duration:.35;if(E==="toggleTransform"){let f=n.property==="rotation"||n.property==="scale"?n.property:"translation",x=f==="rotation"?l.rotation||[0,0,0,1]:f==="scale"?l.scale||[1,1,1]:l.translation||[0,0,0],o=`/nodes/${u}/${f}`,d=D(`__toggle_${u}_${R}`,"bool",!1),U=y("variable/get",{configuration:{variable:d}}),j=y("math/not",{values:{a:S(U)}}),B=y("variable/set",{configuration:{variable:d},values:{value:S(j)}}),Y=y("pointer/interpolate",{configuration:{pointer:o},values:{value:{value:Array.isArray(n.to)?n.to:x},duration:{value:G}}}),H=y("pointer/interpolate",{configuration:{pointer:o},values:{value:{value:Array.isArray(n.from)?n.from:x},duration:{value:G}}});s[B].flows={out:{node:y("flow/branch",{values:{condition:S(U)},flows:{true:{node:Y},false:{node:H}}})}},T.push(B)}else if(E==="interpolate"){let f=n.to??n.value;if(f===void 0)continue;let x={value:{value:f},duration:{value:G}};n.from!==void 0&&(x.from={value:n.from}),T.push(y("pointer/interpolate",{configuration:{pointer:typeof n.pointer=="string"?n.pointer:b(A(n,u),w(A(n,u)),n.property)},values:x}))}else if(E==="setProperty"){if(n.value===void 0)continue;T.push(y("pointer/set",{configuration:{pointer:typeof n.pointer=="string"?n.pointer:b(A(n,u),w(A(n,u)),n.property)},values:{value:{value:n.value}}}))}else if(E==="toggleVisibility"){let f=A(n,u),x=D(`__vis_${f}_${R}`,"bool",!0),o=y("variable/get",{configuration:{variable:x}}),d=y("math/not",{values:{a:S(o)}}),U=y("variable/set",{configuration:{variable:x},values:{value:S(d)}});s[U].flows={out:{node:y("pointer/set",{configuration:{pointer:`/nodes/${f}/extensions/KHR_node_visibility/visible`},values:{value:S(o)}})}},T.push(U)}else if(E==="cycleMaterialColor"&&Array.isArray(n.colors)&&n.colors.length>0){let f=typeof n.duration=="number"?n.duration:.25,x=`/materials/${Math.max(0,P)}/pbrMetallicRoughness/baseColorFactor`,o=D(`__color_idx_${u}_${R}`,"int",0),d=y("variable/get",{configuration:{variable:o}}),U=y("math/add",{values:{a:S(d),b:{value:1}}}),j=y("math/rem",{values:{a:S(U),b:{value:n.colors.length}}}),B=y("variable/set",{configuration:{variable:o},values:{value:S(j)}}),Y={};for(let H=0;H<n.colors.length;H++){let Z=n.colors[H],te=Array.isArray(Z)&&Z.length>=3?[Z[0],Z[1],Z[2],Z[3]??1]:[1,1,1,1];Y[String(H)]={node:f>0?y("pointer/interpolate",{configuration:{pointer:x},values:{value:{value:te},duration:{value:f}}}):y("pointer/set",{configuration:{pointer:x},values:{value:{value:te}}})}}s[B].flows={out:{node:y("flow/switch",{values:{selection:S(d)},flows:Y})}},T.push(B)}else if(E==="playAnimation")T.push(y("animation/start",{configuration:{animation:n.animation??n.clip??0}}));else if(E==="stopAnimation")T.push(y("animation/stop"));else if(E==="sendEvent"){let f={};for(let[x,o]of Object.entries(n.values||{}))f[x]={value:o};T.push(y("event/send",{configuration:{event:v(String(n.event??n.id??"custom"))},values:f}))}}if(!T.length)return null;if(T.length===1)return T[0];let L={};return T.forEach((R,n)=>{L[String(n)]={node:R}}),y("flow/sequence",{flows:L})},V=(F,_,T)=>{let L=$(_);L!==null&&y(F,{...T?{configuration:T}:{},flows:{out:{node:L}}})};if(M.onSelect&&V("pointer/onSelect",M.onSelect,{nodeIndex:u}),M.onHoverIn&&V("pointer/onHoverIn",M.onHoverIn,{nodeIndex:u}),M.onHoverOut&&V("pointer/onHoverOut",M.onHoverOut,{nodeIndex:u}),M.onStart&&V("event/onStart",M.onStart),M.onReceive&&typeof M.onReceive=="object")for(let[F,_]of Object.entries(M.onReceive))V("event/receive",_,{event:v(F)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:m,events:p}],graph:0}:null}var Ee="__THREE_LIVE_REGISTRY__";function pe(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Ee]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Ee,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Ee]=t}}return e[Ee]}var me=pe().plugins;function Ye(e){let t=pe().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function Ze(){return pe().plugins}var Ct={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function $e(e,t,i,r){if(!i||i.bufferView===void 0)return null;let a=e.bufferViews?.[i.bufferView];if(!a)return null;let s=Number(i.count??0);if(!Number.isInteger(s)||s<=0)return null;let m=i.componentType??5126,p=Ct[m];if(!p)throw new RangeError(`glTF accessor has unsupported componentType ${m}`);let g=p*r,c=a.byteStride&&a.byteStride>0?a.byteStride:g,v=(a.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(v)||v<0||c<g||v+(s-1)*c+g>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(m===5126&&c===g&&v%4===0)return new Float32Array(t,v,s*r);let y=new DataView(t),D=i.normalized===!0,S=new Float32Array(s*r);for(let h=0;h<s;h++){let b=v+h*c;for(let C=0;C<r;C++){let A=b+C*p,w;switch(m){case 5126:w=y.getFloat32(A,!0);break;case 5120:w=y.getInt8(A),D&&(w=Math.max(w/127,-1));break;case 5121:w=y.getUint8(A),D&&(w/=255);break;case 5122:w=y.getInt16(A,!0),D&&(w=Math.max(w/32767,-1));break;case 5123:w=y.getUint16(A,!0),D&&(w/=65535);break;default:w=y.getUint32(A,!0),D&&(w/=4294967295)}S[h*r+C]=w}}return S}function Je(e,t){let i=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,a=Number(t.scale?.[0]??1),s=Number(t.scale?.[1]??1),m=Number(t.rotation??0)||0,p=Math.cos(m),g=Math.sin(m),c=(Number.isFinite(a)?a:1)*p,v=(Number.isFinite(a)?a:1)*g,y=-(Number.isFinite(s)?s:1)*g,D=(Number.isFinite(s)?s:1)*p;for(let S=0;S+1<e.length;S+=2){let h=e[S],b=e[S+1];e[S]=c*h+v*b+i,e[S+1]=y*h+D*b+r}}function Pe(e,t,i,r=!0){let a=[],s=null;try{for(let[m,p]of[[35633,t],[35632,i]]){let g=e.createShader(m);if(!g){if(r)throw new Error("Shader allocation failed");return null}if(a.push(g),e.shaderSource(g,p),e.compileShader(g),e.getShaderParameter&&!e.getShaderParameter(g,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(g)}`);return null}}if(s=e.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let m of a)e.attachShader(s,m);if(e.linkProgram(s),e.getProgramParameter&&!e.getProgramParameter(s,35714)){let m=r?e.getProgramInfoLog(s):null;if(e.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${m}`);return null}return s}finally{for(let m of a)s&&e.detachShader?.(s,m),e.deleteShader?.(m)}}function ce(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Ce(e,t,i,r,a){let s=1/Math.tan(t/2);e.fill(0),e[0]=s/i,e[5]=s,e[11]=-1;let m=1/(r-a);return e[10]=(a+r)*m,e[14]=2*a*r*m,e}function Le(e,t,i,r){let[a,s,m]=t,[p,g,c]=r,[v,y,D]=i,S=a-v,h=s-y,b=m-D,C=Math.hypot(S,h,b);C<=1e-5?(S=0,h=0,b=1):(S/=C,h/=C,b/=C);let A=g*b-c*h,w=c*S-p*b,u=p*h-g*S;C=Math.hypot(A,w,u),C<=1e-5?(A=0,w=0,u=0):(A/=C,w/=C,u/=C);let l=h*u-b*w,M=b*A-S*u,P=S*w-h*A;return C=Math.hypot(l,M,P),C<=1e-5?(l=0,M=0,P=0):(l/=C,M/=C,P/=C),e[0]=A,e[1]=l,e[2]=S,e[3]=0,e[4]=w,e[5]=M,e[6]=h,e[7]=0,e[8]=u,e[9]=P,e[10]=b,e[11]=0,e[12]=-(A*a+w*s+u*m),e[13]=-(l*a+M*s+P*m),e[14]=-(S*a+h*s+b*m),e[15]=1,e}function fe(e,t,i){let r=t[0],a=t[1],s=t[2],m=t[3],p=t[4],g=t[5],c=t[6],v=t[7],y=t[8],D=t[9],S=t[10],h=t[11],b=t[12],C=t[13],A=t[14],w=t[15],u=i[0],l=i[1],M=i[2],P=i[3];return e[0]=u*r+l*p+M*y+P*b,e[1]=u*a+l*g+M*D+P*C,e[2]=u*s+l*c+M*S+P*A,e[3]=u*m+l*v+M*h+P*w,u=i[4],l=i[5],M=i[6],P=i[7],e[4]=u*r+l*p+M*y+P*b,e[5]=u*a+l*g+M*D+P*C,e[6]=u*s+l*c+M*S+P*A,e[7]=u*m+l*v+M*h+P*w,u=i[8],l=i[9],M=i[10],P=i[11],e[8]=u*r+l*p+M*y+P*b,e[9]=u*a+l*g+M*D+P*C,e[10]=u*s+l*c+M*S+P*A,e[11]=u*m+l*v+M*h+P*w,u=i[12],l=i[13],M=i[14],P=i[15],e[12]=u*r+l*p+M*y+P*b,e[13]=u*a+l*g+M*D+P*C,e[14]=u*s+l*c+M*S+P*A,e[15]=u*m+l*v+M*h+P*w,e}function He(e,t,i,r){let a=t[0],s=t[1],m=t[2],p=t[3],g=a+a,c=s+s,v=m+m,y=a*g,D=a*c,S=a*v,h=s*c,b=s*v,C=m*v,A=p*g,w=p*c,u=p*v,l=r[0],M=r[1],P=r[2];return e[0]=(1-(h+C))*l,e[1]=(D+u)*l,e[2]=(S-w)*l,e[3]=0,e[4]=(D-u)*M,e[5]=(1-(y+C))*M,e[6]=(b+A)*M,e[7]=0,e[8]=(S+w)*P,e[9]=(b-A)*P,e[10]=(1-(y+h))*P,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function ve(e,t,i=0){let r=t[0],a=t[1],s=t[2],m=t[4],p=t[5],g=t[6],c=t[8],v=t[9],y=t[10],D=y*p-g*v,S=-y*m+g*c,h=v*m-p*c,b=r*D+a*S+s*h;return!b||i>0&&(!Number.isFinite(b)||Math.abs(b)<=i)||(b=1/b,e[0]=D*b,e[1]=S*b,e[2]=h*b,e[3]=(-y*a+s*v)*b,e[4]=(y*r-s*c)*b,e[5]=(-v*r+a*c)*b,e[6]=(g*a-s*p)*b,e[7]=(-g*r+s*m)*b,e[8]=(p*r-a*m)*b),e}function Qe(e,t){let i=t[0],r=t[1],a=t[2],s=t[3],m=t[4],p=t[5],g=t[6],c=t[7],v=t[8],y=t[9],D=t[10],S=t[11],h=t[12],b=t[13],C=t[14],A=t[15],w=i*p-r*m,u=i*g-a*m,l=i*c-s*m,M=r*g-a*p,P=r*c-s*p,$=a*c-s*g,V=v*b-y*h,F=v*C-D*h,_=v*A-S*h,T=y*C-D*b,L=y*A-S*b,R=D*A-S*C,n=w*R-u*L+l*T+M*_-P*F+$*V;return n?(n=1/n,e[0]=(p*R-g*L+c*T)*n,e[1]=(a*L-r*R-s*T)*n,e[2]=(b*$-C*P+A*M)*n,e[3]=(D*P-y*$-S*M)*n,e[4]=(g*_-m*R-c*F)*n,e[5]=(i*R-a*_+s*F)*n,e[6]=(C*l-h*$-A*u)*n,e[7]=(v*$-D*l+S*u)*n,e[8]=(m*L-p*_+c*V)*n,e[9]=(r*_-i*L-s*V)*n,e[10]=(h*P-b*l+A*w)*n,e[11]=(y*l-v*P-S*w)*n,e[12]=(p*F-m*T-g*V)*n,e[13]=(i*T-r*F+a*V)*n,e[14]=(b*u-h*M-C*w)*n,e[15]=(v*M-y*u+D*w)*n,e):null}function ze(e,t,i,r,a){let s=a[0]*t+a[4]*i+a[8]*r+a[12],m=a[1]*t+a[5]*i+a[9]*r+a[13],p=a[2]*t+a[6]*i+a[10]*r+a[14],g=a[3]*t+a[7]*i+a[11]*r+a[15],c=g!==0?1/g:1;e[0]=s*c,e[1]=m*c,e[2]=p*c}function et(e,t,i,r,a,s,m,p,g,c,v,y,D,S,h,b,C=0){let A=c-m,w=v-p,u=y-g,l=D-m,M=S-p,P=h-g,$=a*P-s*M,V=s*l-r*P,F=r*M-a*l,_=A*$+w*V+u*F;if(_>-1e-7&&_<1e-7)return!1;let T=1/_,L=e-m,R=t-p,n=i-g,E=T*(L*$+R*V+n*F);if(E<-C||E>1+C)return!1;let G=R*u-n*w,f=n*A-L*u,x=L*w-R*A,o=T*(r*G+a*f+s*x);if(o<-C||E+o>1+C)return!1;let d=T*(l*G+M*f+P*x);if(d>1e-4&&d<b.distance){b.distance=d,b.point=[e+r*d,t+a*d,i+s*d];let U=w*P-u*M,j=u*l-A*P,B=A*M-w*l,Y=Math.hypot(U,j,B)||1;return b.normal=[U/Y,j/Y,B/Y],!0}return!1}function tt(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let v=0;v<i;v++)r.push(ce());if(i===0)return r;let a=new Set;for(let v of e.nodes)if(Array.isArray(v.children))for(let y of v.children)a.add(y);let s=new Set,m=128,p=(v,y,D=0)=>{if(D>m||v<0||v>=i||s.has(v))return;s.add(v);let S=e.nodes[v];if(!S)return;let h=ce();if(t&&t[v])h.set(t[v]);else if(S.matrix&&S.matrix.length===16)h.set(S.matrix);else{let C=S.translation||[0,0,0],A=S.rotation||[0,0,0,1],w=S.scale||[1,1,1];He(h,A,C,w)}let b=r[v];if(y?fe(b,y,h):b.set(h),Array.isArray(S.children))for(let C of S.children)typeof C=="number"&&p(C,b,D+1)},g=[],c=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(c&&Array.isArray(c.nodes))g.push(...c.nodes);else for(let v=0;v<i;v++)a.has(v)||g.push(v);for(let v of g)p(v,null);for(let v=0;v<i;v++)!a.has(v)&&!g.includes(v)&&p(v,null);return r}var it=["neutral","reinhard","none","aces","agx"];function Xe(e){let t=String(e??"").trim().toLowerCase();return it.includes(t)?t:"neutral"}function Lt(e){return it.indexOf(Xe(e))}function It(e){return new TextDecoder().decode(e)}var st=pe().decoders;function Ft(e,t){st.set(e.toLowerCase(),t)}function Ae(e){return st.get(e.toLowerCase())}function ot(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 D=i.getUint8(0);throw D===123||D===32||D===10||D===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 a=i.getUint32(4,!0);if(a!==2)throw new Error(`Unsupported GLB version: ${a}`);let s=i.getUint32(8,!0),m=12,p=null,g=null;for(;m+8<=s&&m+8<=t.byteLength;){let D=i.getUint32(m,!0),S=i.getUint32(m+4,!0),h=m+8;if(h+D>t.byteLength)throw new Error(`Truncated GLB chunk: required ${h+D} bytes, buffer has ${t.byteLength}`);if(S===1313821514){let b=new Uint8Array(t,h,D),C=It(b);p=JSON.parse(C,(A,w)=>A==="__proto__"||A==="constructor"||A==="prototype"?void 0:w)}else S===5130562&&(g=t.slice(h,h+D));m=h+D}if(!p)throw new Error("Missing JSON chunk in GLB");let c=p.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!Ae("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let D of["EXT_meshopt_compression","KHR_meshopt_compression"])if(c.includes(D)&&!Ae("meshopt"))throw new Error(`Model requires ${D}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!Ae("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let v=g||new ArrayBuffer(0),y={gltf:p,bin:v,animations:[]};for(let D of me)D.onParseGLB?.(y);return y}function _t(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 Re(e){if(_t(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return ot(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var at=`#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
|
+
}`,Nt=`#version 300 es
|
|
52
52
|
precision highp float;
|
|
53
53
|
in vec3 vNormal,vWorldPos;
|
|
54
54
|
in vec2 vUV;
|
|
@@ -239,19 +239,19 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
239
239
|
float outAlpha=base.a;
|
|
240
240
|
/*XRD_O*/
|
|
241
241
|
fragColor=vec4(color,outAlpha);
|
|
242
|
-
}`,
|
|
242
|
+
}`,Bt=`#version 300 es
|
|
243
243
|
layout(location=0) in vec3 aPosition;
|
|
244
244
|
uniform mat4 uMVP;
|
|
245
245
|
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Ut=`#version 300 es
|
|
246
246
|
precision highp float;
|
|
247
247
|
uniform vec4 uColorId;
|
|
248
248
|
out vec4 fragColor;
|
|
249
|
-
void main(){fragColor=uColorId;}`;function Xe(t,e,i){let r={};for(let a of i)r[a]=t.getUniformLocation(e,a);return r}var et=["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 ot(){let t=de().xrDepthShader;return{fs:Bt.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...et,...t.uniformNames]:et}}function Gt(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 ze(t,e,i,r,a,s,m,f){if(r===void 0||!e.accessors?.[r])return null;let p=Ve(e,i,e.accessors[r],s);if(!p)return null;f&&(p=p.slice(),Ye(p,f));let u=t.createBuffer();return m.push(u),t.bindBuffer(34962,u),t.bufferData(34962,p,35044),t.enableVertexAttribArray(a),t.vertexAttribPointer(a,s,5126,!1,0,0),p}function We(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function at(t,e,i){let r=ot(),a=st,s=r.fs,m=!1;for(let p of ue)if(p.onResolveShader){let u=p.onResolveShader(e,i,a,s);u&&(a=u.vs,s=u.fs,m=!0)}let f=m?Ee(t,a,s):null;return{program:f,uniforms:f?Xe(t,f,r.uniforms):null}}function Ot(t,e,i){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let a=r.length>>4,s=e.instanceColors,m=new Float32Array(a*20);for(let p=0;p<a;p++)m.set(r.subarray(p*16,p*16+16),p*20),m[p*20+16]=s?s[p*3]:1,m[p*20+17]=s?s[p*3+1]:1,m[p*20+18]=s?s[p*3+2]:1,m[p*20+19]=1;let f=t.createBuffer();i.push(f),t.bindBuffer(34962,f),t.bufferData(34962,m,35044);for(let p=0;p<5;p++)t.enableVertexAttribArray(8+p),t.vertexAttribPointer(8+p,4,5126,!1,80,p*16),t.vertexAttribDivisor(8+p,1);return!0}function Vt(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 a of r){let s=a?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var un=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),ut=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ce(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function ct(t,e){let i=t?.pbrMetallicRoughness,r=i?.baseColorFactor,a=t?.extensions?.KHR_materials_clearcoat,s=m=>m!==void 0&&e[m.index]?e[m.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:a?a.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,a?.clearcoatRoughnessFactor??.04),texture:s(i?.baseColorTexture),metallicRoughnessTexture:s(i?.metallicRoughnessTexture),normalTexture:s(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:s(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function lt(t,e,i){let r=new Set,a=s=>{s&&!r.has(s)&&(r.add(s),t.deleteTexture(s))};for(let s of e)for(let m of s.primitives){if(m.vao&&t.deleteVertexArray(m.vao),m.buffers)for(let p of m.buffers)t.deleteBuffer(p);a(m.texture),a(m.metallicRoughnessTexture),a(m.normalTexture),a(m.occlusionTexture);let f=new Set;m.customProgram&&f.add(m.customProgram);for(let p of m.programCache?.values()??[])p.program&&f.add(p.program);for(let p of f)t.deleteProgram(p)}if(i)for(let s of i)a(s)}function tt(t,e,i=ut,r){let a={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Ht(t,e,i,r,a)}catch(s){let m=a.mesh&&!a.meshes.includes(a.mesh)?[...a.meshes,a.mesh]:a.meshes;lt(t,m,a.gpuTextures),a.vao&&t.deleteVertexArray(a.vao);for(let f of a.buffers)t.deleteBuffer(f);throw s}}function Ht(t,e,i,r,a){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,m=Me("meshopt");m?.decodeBufferViews&&m.decodeBufferViews(s,e);let f=e.bin,p=[];a.meshes=p;let u=[],d=s.extensions?.KHR_materials_variants;d&&Array.isArray(d.variants)&&d.variants.forEach((M,o)=>{u.push(typeof M?.name=="string"&&M.name?M.name:`Variant_${o}`)});let y=Qe(s),R=[];if(Array.isArray(s.nodes))for(let M=0;M<s.nodes.length;M++){let o=s.nodes[M];o.mesh!==void 0&&s.meshes&&s.meshes[o.mesh]&&R.push({node:o,nodeIdx:M,meshIdx:o.mesh})}let S=R.length>0?R:(s.meshes||[]).map((M,o)=>({node:M,nodeIdx:-1,meshIdx:o})),l=[],x=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(x)for(let M of x)l.push({...M,type:M.type||M.light_type||"point",innerConeAngle:M.innerConeAngle??M.inner_cone_angle,outerConeAngle:M.outerConeAngle??M.outer_cone_angle});else if(s.extensions?.KHR_lights_punctual?.lights){let M=s.extensions.KHR_lights_punctual.lights;for(let o of M){let V=o.type==="directional"?"directional":o.type==="point"?"point":o.type==="spot"?"spot":"ambient";l.push({type:V,color:o.color||[1,1,1],intensity:o.intensity!==void 0?o.intensity:1})}}if(l.length===0&&(l.push({type:"ambient",color:[1,1,1],intensity:.35}),l.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),S.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${S.length}`);let T=[];if(a.gpuTextures=T,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 M=0;M<s.textures.length;M++){let o=s.textures[M],V=s.images[o.source];if(V){let X=t.createTexture();t.bindTexture(3553,X),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729);let g=I=>{t.bindTexture(3553,X),t.texImage2D(3553,0,6408,6408,5121,I),t.generateMipmap(3553),r?.()};if(V.bufferView!==void 0){let I=s.bufferViews[V.bufferView],c=I.byteOffset||0,P=new Blob([f.slice(c,c+I.byteLength)],{type:V.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(P).then(g).catch(()=>{})}else if(V.uri){let I=Gt(V.uri);if(I){let c=new Image;c.crossOrigin="anonymous",c.referrerPolicy="no-referrer",c.onload=()=>g(c),c.src=I}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",V.uri)}T.push(X)}else T.push(null)}}let w=[1/0,1/0,1/0],v=[-1/0,-1/0,-1/0],h=0,n=0;for(let M=0;M<S.length;M++){let o=S[M],V=s.meshes[o.meshIdx],X=o.nodeIdx>=0?y[o.nodeIdx]:se(),g=new Float32Array(9);be(g,X);let I={name:o.node.name||V.name||`Mesh_${o.meshIdx}`,nodeIndex:o.nodeIdx,transform:X,normalMatrix:g,primitives:[],extras:o.node.extras||V.extras,...o.node?.visible===!1||o.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};a.mesh=I;let c=o.node?.extensions?.EXT_mesh_gpu_instancing;if(c&&c.attributes&&typeof c.attributes=="object"){let P=c.attributes,j=P.TRANSLATION!==void 0?s.accessors?.[P.TRANSLATION]:null,G=P.ROTATION!==void 0?s.accessors?.[P.ROTATION]:null,U=P.SCALE!==void 0?s.accessors?.[P.SCALE]:null,Z=P._COLOR_0!==void 0?s.accessors?.[P._COLOR_0]:null,E=Number(j?.count??G?.count??U?.count??0);if(!Number.isFinite(E)||E<0||E>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${E}`);if(E>0){let q=(N,Q)=>{if(!N||N.bufferView===void 0||!s.bufferViews?.[N.bufferView])return null;let Zt=N.componentType??5126,Qt=Jt=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${Jt})`),null);if(Zt!==5120&&Zt!==5121&&Zt!==5122&&Zt!==5123&&Zt!==5126)return Qt(`componentType ${Zt}`);if(!(Number(N.count)>=E))return Qt(`count ${N.count} < ${E}`);let Y=null;try{Y=Ve(s,f,{...N,count:E},Q)}catch{return Qt("out of bounds")}return!Y||!Y.every(Number.isFinite)?Qt("non-finite value"):Y},k=q(j,3),H=q(G,4),F=q(U,3),K=Z?.type==="VEC4"?4:3,O=q(Z,K),W=new Float32Array(E*16),z=se();for(let N=0;N<E;N++){let Q=k?[k[N*3],k[N*3+1],k[N*3+2]]:[0,0,0],Zt=H?[H[N*4],H[N*4+1],H[N*4+2],H[N*4+3]]:[0,0,0,1],Qt=F?[F[N*3],F[N*3+1],F[N*3+2]]:[1,1,1];He(z,Zt,Q,Qt),W.set(z,N*16)}if(I.instanceMatrices=W,O){let N=new Float32Array(E*3);for(let Q=0;Q<E;Q++)N[Q*3]=O[Q*K],N[Q*3+1]=O[Q*K+1],N[Q*3+2]=O[Q*K+2];I.instanceColors=N}}}for(let P of V.primitives||[]){if(P.extensions?.KHR_draco_mesh_compression){let Y=Me("draco");Y&&Y.decodePrimitive(s,P,f)}let j=[],G=t.createVertexArray();a.vao=G,a.buffers=j,t.bindVertexArray(G);let U=Ot(t,I,j),Z=s.accessors[P.attributes.POSITION],E=Number(Z?.count??0);if(!Number.isFinite(E)||E<0||h+E>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(h+=E,Z?.min&&Z?.max){let Y=Jt=>{for(let te=0;te<3;te++){let ne=Jt[12+te],ee=Jt[12+te];for(let ie=0;ie<3;ie++){let ae=Jt[ie*4+te]*Z.min[ie],re=Jt[ie*4+te]*Z.max[ie];ne+=ae<re?ae:re,ee+=ae>re?ae:re}ne<w[te]&&(w[te]=ne),ee>v[te]&&(v[te]=ee)}};if(I.instanceMatrices&&I.instanceMatrices.length>=16){let Jt=I.instanceMatrices.length>>4,te=se();for(let ne=0;ne<Jt;ne++){let ee=I.instanceMatrices.subarray(ne*16,ne*16+16);me(te,X,ee),Y(te)}}else Y(X)}let q=ze(t,s,f,P.attributes.POSITION,0,3,j);ze(t,s,f,P.attributes.NORMAL,1,3,j),ze(t,s,f,P.attributes.TEXCOORD_0,2,2,j,Vt(s,P));let k=0,H=5123,F=null;if(P.indices!==void 0){let Y=s.accessors[P.indices],Jt=(s.bufferViews[Y.bufferView].byteOffset||0)+(Y.byteOffset||0);if(k=Number(Y.count??0),!Number.isFinite(k)||k<0||n+k>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);n+=k,H=Y.componentType===5125?5125:5123;let te=t.createBuffer();j.push(te),t.bindBuffer(34963,te),Y.componentType===5125?F=new Uint32Array(f,Jt,Y.count):Y.componentType===5121?F=Uint16Array.from(new Uint8Array(f,Jt,Y.count)):F=Jt%2===0?new Uint16Array(f,Jt,Y.count):new Uint16Array(f.slice(Jt,Jt+Y.count*2)),t.bufferData(34963,F,35044)}else k=Z.count;let K={};for(let Y of ue)if(Y.onBuildPrimitiveVAO){let Jt=Y.onBuildPrimitiveVAO(t,G,P,s,f);Jt&&(K[Y.name]=Jt)}t.bindVertexArray(null);let O=s.materials&&P.material!==void 0?s.materials[P.material]:null,{program:W,uniforms:z}=at(t,P,O),N=ct(O,T),Q=!!(O?.extensions?.KHR_materials_transmission||K.materials?.isTransmissive),Zt=P.extensions?.KHR_materials_variants?.mappings,Qt=Array.isArray(Zt)?Zt.filter(Y=>Y&&typeof Y.material=="number"&&Array.isArray(Y.variants)).map(Y=>({material:Y.material|0,variants:Y.variants.map(Jt=>Number(Jt)|0)})):void 0;I.primitives.push({vao:G,instanced:U,indexCount:k,indexType:H,...N,positions:q,indices:F,buffers:j,materialIndex:P.material,defaultMaterialIndex:P.material,variantMappings:Qt,primitiveDef:P,programCache:new Map([[P.material??-1,{program:W,uniforms:z}]]),pluginData:K,customProgram:W,customUniforms:z,isTransmissive:Q})}p.push(I)}isFinite(w[0])||(w=[-1,-1,-1]),isFinite(v[0])||(v=[1,1,1]);let b=[(w[0]+v[0])/2,(w[1]+v[1])/2,(w[2]+v[2])/2],A=v[0]-w[0],$=v[1]-w[1],B=v[2]-w[2],_=Math.max(Math.hypot(A,$,B)/2,.5),L=[w[0],w[1],w[2]],C=[v[0],v[1],v[2]],D=e.animations;if(!D){for(let M of ue)if(M.onParseGLB?.(e),e.animations){D=e.animations;break}}return D||(D=[]),{meshes:p,bounds:{center:b,radius:_,min:L,max:C},lights:l,animations:D,worldMatrices:y,gpuTextures:T,availableVariants:u}}function Te(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 Le=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=se(),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=se(),this.viewMatrix=se(),this.activeViewMatrix=null,this.modelMatrix=se(),this.mvpMatrix=se(),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:se(),rawValueToMeters:.001,format:0},this.container=t;let r,a;if(e&&typeof e.getContext=="function"?(r=e,a=i):(a=e,r=a?.canvas),!r){let f=t.querySelector("canvas");f||(f=document.createElement("canvas"),f.style.width="100%",f.style.height="100%",f.style.display="block",f.style.touchAction="none",t.prepend(f)),r=f}this.canvas=r,this.opts=a||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=We(this.opts.exposure)),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=je(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 m=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m,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(t,e){Ft(t,e)}static getDecoder(t){return Me(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=ot();this.renderProg=Ee(t,st,e.fs),this.pickProg=Ee(t,kt,Ut),this.uRender=Xe(t,this.renderProg,e.uniforms),this.uPick=Xe(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let e of ue)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;if(typeof t.createFramebuffer!="function")return;this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer();let e=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=e,this.pickFboHeight=i,t.bindTexture(3553,this.pickTexture),t.texImage2D(3553,0,6408,e,i,0,6408,5121,null),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728),t.bindRenderbuffer(36161,this.pickDepth),t.renderbufferStorage(36161,33189,e,i),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),a=Math.max(1,e);this.pickFboWidth=r,this.pickFboHeight=a,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,a,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,a)}loadGLBData(t,e){let{meshes:i,bounds:r,lights:a,animations:s,worldMatrices:m,gpuTextures:f,availableVariants:p}=tt(this.gl,t,e,()=>this.render());if(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=a,this.animations=s||[],this.worldMatrices=m||[],this.gpuTextures=f||[],this.availableVariants=p||[],this.gltf=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(t.gltf?.nodes))for(let y of t.gltf.nodes)this.initialNodeTransforms.push({t:y.translation?[y.translation[0],y.translation[1],y.translation[2]]:[0,0,0],r:y.rotation?[y.rotation[0],y.rotation[1],y.rotation[2],y.rotation[3]]:[0,0,0,1],s:y.scale?[y.scale[0],y.scale[1],y.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let y of ue)y.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 u=t.exposure??t.gltf?.extras?.exposure??t.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=We(u));let d=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.environmentIntensity;d!==void 0&&(this.envIntensity=Math.max(0,Number(d)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(t){this.loadGLBData(it(t))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let t of ue)t.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(Ae(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let i=Ae(t),{meshes:r}=tt(this.gl,i,ut,()=>this.render());if(e)for(let a of r)a.transform[12]+=e[0],a.transform[13]+=e[1],a.transform[14]+=e[2],be(a.normalMatrix,a.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?r=t.get(i.name)??t.get(e):Array.isArray(t)?r=t[e]:t&&typeof t=="object"&&(Object.prototype.hasOwnProperty.call(t,i.name)?r=t[i.name]:Object.prototype.hasOwnProperty.call(t,e)&&(r=t[e])),r&&r.length===16&&(i.transform.set(r),be(i.normalMatrix,i.transform))}}bindLights(t=this.uRender){let e=this.gl,i=[.28,.28,.28],r=[],a=[],s=[],m=[],f=[],p=[];for(let u of this.lights){let d=u.color||[1,1,1],y=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")i=[d[0]*y,d[1]*y,d[2]*y];else if(u.type==="directional"&&r.length<6){let R=u.direction||[.5,1,.8];r.push(R[0],R[1],R[2]),a.push(d[0]*y,d[1]*y,d[2]*y)}else if((u.type==="point"||u.type==="spot")&&s.length<6){let R=u.position||[0,0,0];if(s.push(R[0],R[1],R[2]),m.push(d[0]*y,d[1]*y,d[2]*y),u.type==="spot"){let S=u.direction||[0,-1,0],l=Math.max(.01,Math.min(Math.PI/2,u.outerConeAngle??Math.PI/3)),x=Math.max(0,Math.min(l-1e-4,u.innerConeAngle??0));f.push(S[0],S[1],S[2]),p.push(Math.cos(x),Math.cos(l))}else f.push(0,-1,0),p.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),a.push(1,1,1)),e.uniform3fv(t.uAmbientColor,i),e.uniform1i(t.uNumDirLights,r.length/3),r.length>0&&(e.uniform3fv(t.uDirLightDir,r),e.uniform3fv(t.uDirLightColor,a)),e.uniform1i(t.uNumPointLights,s.length/3),s.length>0&&(e.uniform3fv(t.uPointLightPos,s),e.uniform3fv(t.uPointLightColor,m),t.uPointLightSpotDir&&e.uniform3fv(t.uPointLightSpotDir,f),t.uPointLightSpotCone&&e.uniform2fv(t.uPointLightSpotCone,p)),e.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=We(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=je(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){for(let e of ue)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t);return}}async setSkyboxImage(t){for(let e of ue)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(u=>u.primitives.filter(d=>d.materialIndex===i||t.length===1&&d.materialIndex===void 0)),a=r[0],s=a?[...a.baseColor]:e.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=a?a.metallic:e.pbrMetallicRoughness?.metallicFactor??.1,f=a?a.roughness:e.pbrMetallicRoughness?.roughnessFactor??.5,p={baseColorFactor:s,metallicFactor:m,roughnessFactor:f,setBaseColorFactor:u=>{let d=[u[0],u[1],u[2],u[3]??1];p.baseColorFactor=d,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.baseColorFactor=d);for(let y of r)y.baseColor=d;this.render()},setMetallicFactor:u=>{p.metallicFactor=u,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.metallicFactor=u);for(let d of r)d.metallic=u;this.render()},setRoughnessFactor:u=>{p.roughnessFactor=u,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.roughnessFactor=u);for(let d of r)d.roughness=u;this.render()}};return{name:e.name||`Material_${i}`,pbrMetallicRoughness:p}})}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 a of this.meshes)for(let s of a.primitives){let m=s.defaultMaterialIndex;if(!e&&Array.isArray(s.variantMappings)){for(let p of s.variantMappings)if(Array.isArray(p.variants)&&p.variants.includes(i)){m=p.material;break}}let f=m!==void 0?r[m]:void 0;s.materialIndex=f?m:void 0,Object.assign(s,ct(f,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,f??null)}return!0}applyPrimitiveProgram(t,e,i){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let r=e??-1,a=t.programCache.get(r);a||(a=at(this.gl,{...t.primitiveDef,material:e},i),t.programCache.set(r,a)),t.customProgram=a.program,t.customUniforms=a.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 ue)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){t.minTheta!==void 0&&(this.minTheta=t.minTheta*Math.PI/180),t.maxTheta!==void 0&&(this.maxTheta=t.maxTheta*Math.PI/180),t.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,t.minPhi*Math.PI/180)),t.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,t.maxPhi*Math.PI/180)),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(){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(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.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(e,Math.min(i,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){if(t!==void 0&&(this.initialTheta=this.clampTheta(t*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),e!==void 0&&(this.initialPhi=this.clampPhi(e*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let a=this.clampDistance(i);this.initialDistance=a,this.customDistance=!0,this.targetDistance=a,this.currDistance=a}else if(r!==void 0&&r>0){let a=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=a,this.customDistance=!0,this.targetDistance=a,this.currDistance=a}else{this.customDistance=!1;let a=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=a,this.targetDistance=a,this.currDistance=a}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(t,e){let i=se();me(i,this.projMatrix,this.viewMatrix);let[r,a,s]=t,m=e?e[0]:0,f=e?e[1]:0,p=e?e[2]:0,u=this.modelRootMatrix;u&&(r=u[0]*t[0]+u[4]*t[1]+u[8]*t[2]+u[12],a=u[1]*t[0]+u[5]*t[1]+u[9]*t[2]+u[13],s=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]+u[14],e&&(m=u[0]*e[0]+u[4]*e[1]+u[8]*e[2],f=u[1]*e[0]+u[5]*e[1]+u[9]*e[2],p=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]));let d=i[0]*r+i[4]*a+i[8]*s+i[12],y=i[1]*r+i[5]*a+i[9]*s+i[13],R=i[2]*r+i[6]*a+i[10]*s+i[14],S=i[3]*r+i[7]*a+i[11]*s+i[15];if(S<=1e-4)return{x:0,y:0,z:1,visible:!1};let l=d/S,x=y/S,T=R/S,w=this.canvas.getBoundingClientRect(),v=w.width||this.canvas.clientWidth||this.canvas.width||300,h=w.height||this.canvas.clientHeight||this.canvas.height||150,n=(l*.5+.5)*v,b=(-x*.5+.5)*h,A=l>=-1.1&&l<=1.1&&x>=-1.1&&x<=1.1&&T>=-1&&T<=1;if(A&&e){let[$,B,_]=Te(this),L=[r-$,a-B,s-_];m*L[0]+f*L[1]+p*L[2]>.05&&(A=!1)}return{x:n,y:b,z:T,visible:A}}setSelectedMesh(t){this.selectedMeshName=t||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let t=this.canvas,e=()=>typeof performance<"u"?performance.now():Date.now();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},a=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(a,s),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let m=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],f=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],p=this.customTarget?[...this.customTarget]:[...this.bounds.center],u=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;p[0]+=(-a*m[0]+s*f[0])*u,p[1]+=(-a*m[1]+s*f[1])*u,p[2]+=(-a*m[2]+s*f[2])*u,this.customTarget=p}else this.targetTheta=this.clampTheta(this.targetTheta-a*.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(),a=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(a,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,a)=>{this[a]&&(i.removeEventListener(r,this[a]),this[a]=null)},e=this.canvas;t(e,"webglcontextlost","boundContextLost"),t(e,"webglcontextrestored","boundContextRestored"),t(e,"contextmenu","boundContextMenu"),t(e,"pointerdown","boundPointerDown"),t(e,"pointermove","boundPointerMove"),t(e,"pointerup","boundPointerUp"),t(e,"wheel","boundWheel"),t(e,"keydown","boundKeyDown"),t(this.container,"setCamera","boundSetCamera"),t(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(t,e){let i=this.canvas,r=i.getBoundingClientRect(),a=i.width||300,s=i.height||300,m=r.width>0?Math.floor((t-r.left)*(a/r.width)):Math.floor(t),f=r.height>0?Math.floor((e-r.top)*(s/r.height)):Math.floor(e);return this.performMeshPick(m,f,!1)}performMeshPick(t,e,i=!0){if(this.meshes.length===0)return null;let r=this.gl,a=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);t=this.mapStereoPickX(t,a);let m=se();me(m,this.projMatrix,this.viewMatrix);let f=[],p=Math.max(0,Math.min(a-1,t)),u=Math.max(0,Math.min(s-1,s-1-e));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==a||this.pickFboHeight!==s)&&this.resizePickingFbo(a,s),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,a,s),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let b=0;b<this.meshes.length;b++){let A=this.meshes[b];if(A.visible===!1||A.isPluginMesh)continue;let $=b+1,B=($&255)/255,_=($>>8&255)/255,L=($>>16&255)/255;r.uniform4f(this.uPick.uColorId,B,_,L,1),me(this.modelMatrix,this.modelRootMatrix,A.transform);let C=A.instanceMatrices;if(C&&C.length>=16){let D=C.length>>4,M=se();for(let o of A.primitives){r.bindVertexArray(o.vao);for(let V=0;V<D;V++)me(M,this.modelMatrix,C.subarray(V*16,V*16+16)),me(this.mvpMatrix,m,M),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Ce(r,o)}}else{me(this.mvpMatrix,m,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let D of A.primitives)r.bindVertexArray(D.vao),Ce(r,D)}}let h=new Uint8Array(4);r.readPixels(p,u,1,1,6408,5121,h),r.bindFramebuffer(36160,null);let n=h[0]+(h[1]<<8)+(h[2]<<16);n>0&&n<=this.meshes.length&&(f=[this.meshes[n-1]])}f.length===0&&(f=this.meshes.filter(h=>h.visible!==!1));let d=null,y=1/0,R=[0,0,0],S=[0,1,0],[l,x,T]=Te(this),w=se();for(let h of f){me(w,this.modelRootMatrix,h.transform);let n=h.instanceMatrices,b=n&&n.length>=16?n.length>>4:1;for(let A=0;A<b;A++){n&&n.length>=16?me(this.modelMatrix,w,n.subarray(A*16,A*16+16)):this.modelMatrix.set(w),me(this.mvpMatrix,m,this.modelMatrix);let $=se();if(!Ze($,this.mvpMatrix))continue;let B=(p+.5)/a*2-1,_=(u+.5)/s*2-1,L=[0,0,0],C=[0,0,0];$e(L,B,_,-1,$),$e(C,B,_,1,$);let D=C[0]-L[0],M=C[1]-L[1],o=C[2]-L[2],V=Math.hypot(D,M,o)||1,X=D/V,g=M/V,I=o/V,c={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((P=>{for(let j of h.primitives){if(!j.positions)continue;let G=j.positions,U=j.indices,Z=Math.floor(U?U.length/3:G.length/9);for(let E=0;E<Z;E++){let q=U?U[E*3]:E*3,k=U?U[E*3+1]:E*3+1,H=U?U[E*3+2]:E*3+2;Je(L[0],L[1],L[2],X,g,I,G[q*3],G[q*3+1],G[q*3+2],G[k*3],G[k*3+1],G[k*3+2],G[H*3],G[H*3+1],G[H*3+2],c,P)}}})(1e-4),isFinite(c.distance)){let P=c.point[0],j=c.point[1],G=c.point[2],U=this.modelMatrix,Z=U[0]*P+U[4]*j+U[8]*G+U[12],E=U[1]*P+U[5]*j+U[9]*G+U[13],q=U[2]*P+U[6]*j+U[10]*G+U[14],k=Z-l,H=E-x,F=q-T,K=Math.hypot(k,H,F);if(K<y){be(this.normalMatrix,this.modelMatrix);let O=this.normalMatrix,W=c.normal[0],z=c.normal[1],N=c.normal[2],Q=O[0]*W+O[3]*z+O[6]*N,Zt=O[1]*W+O[4]*z+O[7]*N,Qt=O[2]*W+O[5]*z+O[8]*N,Y=Math.hypot(Q,Zt,Qt)||1;Q/=Y,Zt/=Y,Qt/=Y,Q*k+Zt*H+Qt*F>0&&(Q=-Q,Zt=-Zt,Qt=-Qt),d=h,y=Math.round(K*1e3)/1e3,R=[Math.round(Z*1e3)/1e3,Math.round(E*1e3)/1e3,Math.round(q*1e3)/1e3],S=[Math.round(Q*1e3)/1e3,Math.round(Zt*1e3)/1e3,Math.round(Qt*1e3)/1e3]}}}}if(!d)return null;let v={meshIndex:this.meshes.indexOf(d),meshName:d.name,nodeIndex:d.nodeIndex,distance:y,hitPoint:R,normal:S,screenX:t,screenY:e};if(i){for(let h of ue)h.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}mapStereoPickX(t,e){if(!this.stereoSBS||this.xrSessionActive||e<2)return t;let i=Math.max(1,Math.floor(e*.5)),r=t>=i,a=r?t-i:t,s=r?Math.max(1,e-i):i,m=(a+.5)/s*2-1;return Math.floor((m*.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);Se(this.projMatrix,this.fov,t,.1,e);let i=this.customTarget||this.bounds.center;Pe(this.viewMatrix,Te(this),i,[0,1,0]),me(this.mvpMatrix,this.projMatrix,this.viewMatrix),be(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 ue)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(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let e of ue)e.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();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=this.bounds.center[0],r=this.bounds.center[2],a=this.modelRootMatrix;a[0]=t,a[1]=0,a[2]=-e,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=e,a[9]=0,a[10]=t,a[11]=0,a[12]=i-(t*i+e*r),a[13]=0,a[14]=r-(-e*i+t*r),a[15]=1}setVisible(t){this.isVisible=t}update(t){for(let s of ue)s.onUpdate?.(this,t);let e=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&e-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let s of ue)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),a=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(a-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=a;let s={theta:i,phi:r,zoom:a,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,a=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let m=t?.transform?.inverse?.matrix||this.viewMatrix,f=t?.projectionMatrix||this.projMatrix,p=t?.transform?.position,u=p?[p.x,p.y,p.z]:[0,1.6,0];e?this.modelRootMatrix.set(e):i&&e&&this.modelRootMatrix.set(e),this.render({viewMatrix:m,projMatrix:f,eyePos:u,viewport:r,eye:t?.eye||"none",clear:s>0?!1:t?.eye!=="right",isAR:a})}render(t){if(this.contextLost)return;if(!t&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),h=Math.max(1,this.canvas.height||1),n=Math.max(1,Math.floor(v*.5)),b=Math.max(1,v-n),A=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),$=this.customTarget||this.bounds.center,[B,_,L]=Te(this),C=Math.cos(this.currTheta),D=-Math.sin(this.currTheta),M=.032,o=se(),V=se(),X=[B-C*M,_,L-D*M],g=[$[0]-C*M*.25,$[1],$[2]-D*M*.25];Se(o,this.fov,n/h,.1,A),Pe(V,X,g,[0,1,0]);let I=se(),c=se(),P=[B+C*M,_,L+D*M],j=[$[0]+C*M*.25,$[1],$[2]+D*M*.25];Se(I,this.fov,b/h,.1,A),Pe(c,P,j,[0,1,0]),this.render({viewMatrix:V,projMatrix:o,eyePos:X,viewport:[0,0,n,h],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:c,projMatrix:I,eyePos:P,viewport:[n,0,b,h],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,h);return}let e=this.gl,i=0,r=0,a=this.canvas.width,s=this.canvas.height;t?.viewport?(i=t.viewport[0],r=t.viewport[1],a=t.viewport[2],s=t.viewport[3],e.viewport(i,r,a,s)):e.viewport(0,0,this.canvas.width,this.canvas.height),e.enable(2929),(!t||t.clear!==!1)&&(t?.isAR?e.clearColor(0,0,0,0):e.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),e.clear(16640));let m=se(),f=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=f,me(m,t?.projMatrix??this.projMatrix,f);let p=de().xrDepthShader,u=It(this.toneMapping),[d,y,R]=t?t.eyePos:Te(this);for(let v of ue)v.onBeforeDrawScene?.(this,e,m,[d,y,R],u);let S=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&S===0)return;let l=t?.eye||"none",x=!1,T=S>0?[...this.backdropMeshes,...this.meshes]:this.meshes,w=v=>{for(let h=0;h<T.length;h++){let n=T[h];if(n.visible===!1)continue;let b=this.selectedMeshName!==""&&n.name===this.selectedMeshName;h<S||n.worldSpace===!0||n.name==="__xr_reticle__"?this.modelMatrix.set(n.transform):me(this.modelMatrix,this.modelRootMatrix,n.transform),me(this.mvpMatrix,m,this.modelMatrix),be(n.normalMatrix,this.modelMatrix);let A=n.extras?.xr?.stereo||n.userData?.xr?.stereo,$=0,B=0,_=1,L=1;A==="sbs"?(_=.5,$=l==="right"?.5:0):A==="ou"&&(L=.5,B=l==="right"?.5:0);for(let C of n.primitives){let D=!!C.isTransmissive;if(!v&&D){x=!0;continue}if(v&&!D)continue;let M=C.customProgram||this.renderProg,o=C.customUniforms||this.uRender;e.useProgram(M),e.vertexAttrib3f(3,0,0,0),o.uInstanced&&e.uniform1i(o.uInstanced,0),e.uniform1i(o.uToneMapping,u),e.uniform1f(o.uEnvIntensity,this.envIntensity),o.uExposure&&e.uniform1f(o.uExposure,this.exposure),e.uniform3f(o.uCameraPos,d,y,R),e.uniform1f(o.uEmissive,b?1:0),e.uniformMatrix4fv(o.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(o.uModel,!1,this.modelMatrix),e.uniformMatrix3fv(o.uNormalMatrix,!1,n.normalMatrix),o.uUvTransform&&e.uniform4f(o.uUvTransform,$,B,_,L),o.uViewportSize&&e.uniform2f(o.uViewportSize,Math.max(1,a),Math.max(1,s)),p?.bind(e,o,this.xrDepthState,f,[i,r,Math.max(1,a),Math.max(1,s)]),this.environmentTexture?(e.activeTexture(33988),e.bindTexture(3553,this.environmentTexture),e.uniform1i(o.uEnvironmentMap,4),e.uniform1i(o.uHasEnvironmentMap,1)):e.uniform1i(o.uHasEnvironmentMap,0),this.bindLights(o),o.uSectionEnabled&&e.uniform1i(o.uSectionEnabled,0);for(let X of ue)X.onBeforeDrawPrimitive?.(e,M,C,n,this.worldMatrices||[],this.gltf);e.uniform4fv(o.uBaseColor,C.baseColor),e.uniform1f(o.uMetallic,C.metallic),e.uniform1f(o.uRoughness,C.roughness),o.uClearcoat&&e.uniform2f(o.uClearcoat,C.clearcoat??0,C.clearcoatRoughness??.04),C.texture?(e.activeTexture(33984),e.bindTexture(3553,C.texture),e.uniform1i(o.uBaseColorTexture,0),e.uniform1i(o.uHasTexture,1)):e.uniform1i(o.uHasTexture,0),C.metallicRoughnessTexture?(e.activeTexture(33985),e.bindTexture(3553,C.metallicRoughnessTexture),e.uniform1i(o.uMetallicRoughnessTexture,1),e.uniform1i(o.uHasMetallicRoughnessTexture,1)):e.uniform1i(o.uHasMetallicRoughnessTexture,0),C.normalTexture?(e.activeTexture(33986),e.bindTexture(3553,C.normalTexture),e.uniform1i(o.uNormalTexture,2),e.uniform1i(o.uHasNormalTexture,1),e.uniform1f(o.uNormalScale,C.normalScale)):e.uniform1i(o.uHasNormalTexture,0),C.occlusionTexture?(e.activeTexture(33987),e.bindTexture(3553,C.occlusionTexture),e.uniform1i(o.uOcclusionTexture,3),e.uniform1i(o.uHasOcclusionTexture,1),e.uniform1f(o.uOcclusionStrength,C.occlusionStrength)):e.uniform1i(o.uHasOcclusionTexture,0),e.bindVertexArray(C.vao);let V=n.instanceMatrices;if(C.instanceCount!==void 0)e.drawElementsInstanced(4,C.indexCount,C.indexType,0,C.instanceCount);else if(V&&V.length>=16&&C.instanced&&o.uInstanced&&o.uViewProj){let X=V.length>>4;e.uniform1i(o.uInstanced,1),e.uniformMatrix4fv(o.uViewProj,!1,m),C.indices?e.drawElementsInstanced(4,C.indexCount,C.indexType,0,X):e.drawArraysInstanced(4,0,C.indexCount,X),e.uniform1i(o.uInstanced,0)}else if(V&&V.length>=16){let X=V.length>>4,g=n.instanceColors,I=se(),c=new Float32Array(9),P=[C.baseColor[0],C.baseColor[1],C.baseColor[2],C.baseColor[3]];for(let j=0;j<X;j++)me(I,this.modelMatrix,V.subarray(j*16,j*16+16)),me(this.mvpMatrix,m,I),be(c,I),e.uniformMatrix4fv(o.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(o.uModel,!1,I),e.uniformMatrix3fv(o.uNormalMatrix,!1,c),g&&(P[0]=C.baseColor[0]*g[j*3],P[1]=C.baseColor[1]*g[j*3+1],P[2]=C.baseColor[2]*g[j*3+2],P[3]=C.baseColor[3],e.uniform4fv(o.uBaseColor,P)),Ce(e,C)}else Ce(e,C)}}};if(w(!1),x){for(let v of ue)v.onBeforeTransmissivePass?.(e,this);w(!0)}for(let v of ue)v.onAfterRender?.(e,this,m,t?.eye??"none",[i,r,a,s],t?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(t,e){lt(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 ue)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()}};Le.registerPlugin=Ke,Le.getRegisteredPlugins=qe;function $t(t){return t+3&-4}var J=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function ft(t,e){let i=e,r=1;for(;t.has(i);)i=`${e}_${r++}`;return t.add(i),i}function dt(t,e=0){let[i,r,a,,s,m,f,,p,u,d,,y,R,S]=Array.from({length:15},(c,P)=>J(t[e+P],P%5===0?1:0)),l=Math.hypot(i,r,a),x=Math.hypot(s,m,f),T=Math.hypot(p,u,d);i*(m*d-u*f)-s*(r*d-u*a)+p*(r*f-m*a)<0&&(l=-l);let w=Math.abs(l)>1e-8?1/l:0,v=Math.abs(x)>1e-8?1/x:0,h=Math.abs(T)>1e-8?1/T:0,n=i*w,b=r*w,A=a*w,$=s*v,B=m*v,_=f*v,L=p*h,C=u*h,D=d*h,M=n+B+D,o=0,V=0,X=0,g=1;if(M>0){let c=.5/Math.sqrt(M+1);g=.25/c,o=(_-C)*c,V=(L-A)*c,X=(b-$)*c}else if(n>B&&n>D){let c=2*Math.sqrt(Math.max(0,1+n-B-D));c>1e-8&&(g=(_-C)/c,o=.25*c,V=($+b)/c,X=(L+A)/c)}else if(B>D){let c=2*Math.sqrt(Math.max(0,1+B-n-D));c>1e-8&&(g=(L-A)/c,o=($+b)/c,V=.25*c,X=(_+C)/c)}else{let c=2*Math.sqrt(Math.max(0,1+D-n-B));c>1e-8&&(g=(b-$)/c,o=(L+A)/c,V=(_+C)/c,X=.25*c)}let I=Math.hypot(o,V,X,g);return I>1e-8&&Number.isFinite(I)?(o/=I,V/=I,X/=I,g/=I):(o=0,V=0,X=0,g=1),{t:[y,R,S],r:[o,V,X,g],s:[l,x,T]}}function zt(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 ge=(t,e,i,r)=>typeof t=="number"&&Number.isFinite(t)?Math.max(e,Math.min(i,t)):r;function pt(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,a=typeof i.preset=="string"?i.preset:void 0;return!r&&!a?null:{ae:i,src:r,preset:a,volume:ge(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function bt(t,e){return gt(t,e)[0]}function gt(t,e){t.updateMatrixWorld(!0);let i=[],r=0,a=[],s=[],m=[],f=[],p=new Set,u=[],d=[],y=new Map,R=[],S=[],l=[],x=new Map,T=[],w=[];function v(g){let I=y.get(g);if(I!==void 0)return I;I=d.length,y.set(g,I);let c=g,P=c.color?.r??.8,j=c.color?.g??.8,G=c.color?.b??.8,U=c.opacity??1,Z={baseColorFactor:[P,j,G,U],metallicFactor:c.metalness??0,roughnessFactor:c.roughness??.5},E={};if(c.map){let H="";typeof c.map=="string"?H=c.map:typeof c.map.source=="string"?H=c.map.source:typeof c.map.image=="string"&&(H=c.map.image);let F=H.trim(),K=F&&!/[\x00-\x1f\x7f\\]|\.\./.test(F)&&(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(F)||!F.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(F))?F:null;if(K){let W=x.get(K);if(W===void 0){let z=R.length;R.push({uri:K}),S.length===0&&S.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),W=l.length,l.push({sampler:0,source:z}),x.set(K,W)}Z.baseColorTexture={index:W}}let O=c.map.avgColor;Array.isArray(O)&&O.length>=3&&(E.avgColor=[O[0],O[1],O[2]])}let q={name:c.name||"",pbrMetallicRoughness:Z,doubleSided:c.side===2||!!c.doubleSided,...Object.keys(E).length>0?{extras:E}:{}};if(c.emissive&&(c.emissive.r>0||c.emissive.g>0||c.emissive.b>0)){let H=c.emissiveIntensity??1;q.emissiveFactor=[c.emissive.r*H,c.emissive.g*H,c.emissive.b*H]}let k={};return c.clearcoat&&c.clearcoat>0&&(k.KHR_materials_clearcoat={clearcoatFactor:c.clearcoat,clearcoatRoughnessFactor:c.clearcoatRoughness||0}),c.sheen&&c.sheen>0&&(k.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&&(k.KHR_materials_transmission={transmissionFactor:c.transmission}),c.thickness&&c.thickness>0&&(k.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&&(k.KHR_materials_ior={ior:c.ior}),c.dispersion&&c.dispersion>0&&(k.KHR_materials_dispersion={dispersion:c.dispersion}),c.iridescence&&c.iridescence>0&&(k.KHR_materials_iridescence={iridescenceFactor:c.iridescence,iridescenceIor:c.iridescenceIOR??1.3}),Object.keys(k).length>0&&(q.extensions=k),d.push(q),I}function h(g,I){let c=new Uint8Array(g.buffer,g.byteOffset,g.byteLength),P=$t(c.byteLength),j=new Uint8Array(P);j.set(c),i.push(j);let G=a.length;return a.push({buffer:0,byteOffset:r,byteLength:c.byteLength,target:I}),r+=P,G}function n(g,I,c,P,j,G,U){let Z=h(g,c),E=s.length,q={bufferView:Z,byteOffset:0,componentType:P,count:j,type:I};return G&&(q.min=G),U&&(q.max=U),s.push(q),E}t.traverse(g=>{if(g.isLight||g.color&&g.intensity!==void 0){let I=g.matrixWorld?.elements,c=J(I?I[12]:g.position?.x,0),P=J(I?I[13]:g.position?.y,0),j=J(I?I[14]:g.position?.z,0),G=g.target,U=G?.parent?G?.matrixWorld?.elements:void 0,Z=J(U?U[12]:G?.position?.x,0),E=J(U?U[13]:G?.position?.y,0),q=J(U?U[14]:G?.position?.z,0),k=Z-c,H=E-P,F=q-j,K=Math.hypot(k,H,F),O=Math.max(.01,Math.min(Math.PI/2,J(g.angle,Math.PI/3))),W=Math.max(0,Math.min(1,J(g.penumbra,0)));w.push({type:g.type,color:[g.color.r,g.color.g,g.color.b],intensity:g.intensity,position:[c,P,j],...g.type==="spot"?{direction:K>1e-6?[k/K,H/K,F/K]:[0,-1,0],outerConeAngle:O,innerConeAngle:Math.max(0,O*(1-W)),range:Math.max(0,J(g.distance,0))}:g.type==="point"?{range:Math.max(0,J(g.distance,0))}:{}})}});let b=[],A=new Set([t]),$=[];if(Array.isArray(t.children))for(let g=t.children.length-1;g>=0;g--)$.push({obj:t.children[g],parentKids:b});for(;$.length>0;){let{obj:g,parentKids:I}=$.pop();if(!g||typeof g!="object"||A.has(g))continue;A.add(g),g._bakeAuthorGeometry?.(),de().materializeDeclarativeGeometry?.(g);let c=!!(g.userData&&(g.userData.xr&&typeof g.userData.xr=="object"&&Object.keys(g.userData.xr).length>0||g.userData.interactivity&&typeof g.userData.interactivity=="object"&&Object.keys(g.userData.interactivity).length>0)),P={name:g.name||(c?`Node_${f.length}`:"")},j=J(g.position?.x,0),G=J(g.position?.y,0),U=J(g.position?.z,0),Z=J(g.quaternion?.x,0),E=J(g.quaternion?.y,0),q=J(g.quaternion?.z,0),k=J(g.quaternion?.w,1),H=J(g.scale?.x,1),F=J(g.scale?.y,1),K=J(g.scale?.z,1);if((j||G||U)&&(P.translation=[j,G,U]),(Z||E||q||k!==1)&&(P.rotation=[Z,E,q,k]),(H!==1||F!==1||K!==1)&&(P.scale=[H,F,K]),g.visible===!1&&(P.extensions={...P.extensions||{},KHR_node_visibility:{visible:!1}},p.add("KHR_node_visibility")),g.userData&&Object.keys(g.userData).length>0&&(P.extras=JSON.parse(JSON.stringify(g.userData,(z,N)=>{if(!(z==="__proto__"||z==="prototype"||z==="constructor"))return typeof N=="function"?void 0:N})),g.userData.xr)){let z=zt(g.userData.xr);P.extensions={...P.extensions||{},MOZ_hubs_components:z,ANDROID_xr_scenecore:z},de().xrTraitSerializer?.gltfNode(P,g.userData.xr),p.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(g.geometry){let z=g.geometry,N=z.attributes.position;if(N&&N.count>0){let Q=[1/0,1/0,1/0],Zt=[-1/0,-1/0,-1/0];for(let ee=0;ee<N.count;ee++){let ie=N.getX(ee),ae=N.getY(ee),re=N.getZ(ee);ie<Q[0]&&(Q[0]=ie),ie>Zt[0]&&(Zt[0]=ie),ae<Q[1]&&(Q[1]=ae),ae>Zt[1]&&(Zt[1]=ae),re<Q[2]&&(Q[2]=re),re>Zt[2]&&(Zt[2]=re)}let Qt={attributes:{POSITION:n(N.array,"VEC3",34962,5126,N.count,Q,Zt)}};if(z.attributes.normal&&(Qt.attributes.NORMAL=n(z.attributes.normal.array,"VEC3",34962,5126,z.attributes.normal.count)),z.attributes.uv&&(Qt.attributes.TEXCOORD_0=n(z.attributes.uv.array,"VEC2",34962,5126,z.attributes.uv.count)),z.index){let ee=z.index.array instanceof Uint32Array;Qt.indices=n(z.index.array,"SCALAR",34963,ee?5125:5123,z.index.count)}let Y=Array.isArray(g.material)?g.material[0]:g.material;Y&&(Qt.material=v(Y));let Jt=g.userData?.variants;if(Jt&&typeof Jt=="object"){let ee=new Map;for(let ie of Object.keys(Jt)){if(!ie||ie==="__proto__"||ie==="constructor"||ie==="prototype")continue;let ae=Jt[ie];if(!ae||typeof ae!="object")continue;let re=T.indexOf(ie);if(re===-1&&T.length<256&&(re=T.length,T.push(ie)),re===-1)continue;let he=v(ae),ce=ee.get(he);ce||(ce=[],ee.set(he,ce)),ce.push(re)}if(ee.size>0){let ie=[];for(let[ae,re]of ee.entries())ie.push({material:ae,variants:re});Qt.extensions={...Qt.extensions||{},KHR_materials_variants:{mappings:ie}},p.add("KHR_materials_variants")}}let te=g;if(te.isInstancedMesh&&typeof te.count=="number"&&te.count>0&&te.instanceMatrix?.array){let ee=Math.min(1e4,Math.floor(te.count)),ie=te.instanceMatrix.array,ae=new Float32Array(ee*3),re=new Float32Array(ee*4),he=new Float32Array(ee*3);for(let oe=0;oe<ee;oe++){let{t:ve,r:fe,s:xe}=dt(ie,oe*16);ae[oe*3]=ve[0],ae[oe*3+1]=ve[1],ae[oe*3+2]=ve[2],re[oe*4]=fe[0],re[oe*4+1]=fe[1],re[oe*4+2]=fe[2],re[oe*4+3]=fe[3],he[oe*3]=xe[0],he[oe*3+1]=xe[1],he[oe*3+2]=xe[2]}let ce={TRANSLATION:n(ae,"VEC3",0,5126,ee),ROTATION:n(re,"VEC4",0,5126,ee),SCALE:n(he,"VEC3",0,5126,ee)};if(te.instanceColor?.array&&te.instanceColor.array.length>=ee*3){let oe=new Float32Array(te.instanceColor.array.subarray(0,ee*3));ce._COLOR_0=n(oe,"VEC3",0,5126,ee)}P.extensions={...P.extensions||{},EXT_mesh_gpu_instancing:{attributes:ce}},p.add("EXT_mesh_gpu_instancing")}let ne=m.length;m.push({primitives:[Qt],name:g.name,...P.extras?{extras:P.extras}:{}}),P.mesh=ne}}let O=f.length;f.push(P),u.push(g),I.push(O);let W=g.children;if(Array.isArray(W)&&W.length>0){let z=[];P.children=z;for(let N=W.length-1;N>=0;N--)$.push({obj:W[N],parentKids:z})}}for(let g=0;g<f.length;g++){let I=f[g];I.children&&I.children.length===0?delete I.children:I.children&&I.children.length>0&&(I.extras?.xr?.lod||I.extensions?.ANDROID_xr_scenecore?.lod||u[g]?.isLOD)&&(I.extensions={...I.extensions||{},MSFT_lod:{ids:[...I.children]}},p.add("MSFT_lod"))}let B=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),_=[];if(typeof B=="function"&&u.length>0){let g=e?.duration??4,I=e?.fps??15,c=Math.max(2,Math.round(g*I)+1),P=new Float32Array(c),j=u.map(F=>[J(F.position?.x,0),J(F.position?.y,0),J(F.position?.z,0),J(F.quaternion?.x,0),J(F.quaternion?.y,0),J(F.quaternion?.z,0),J(F.quaternion?.w,1),J(F.scale?.x,1),J(F.scale?.y,1),J(F.scale?.z,1)]),G=u.map(()=>new Float32Array(c*3)),U=u.map(()=>new Float32Array(c*4)),Z=u.map(()=>new Float32Array(c*3));for(let F=0;F<c;F++){let K=F/(c-1)*g;P[F]=K;try{B(K)}catch{}for(let O=0;O<u.length;O++){let W=u[O];G[O][F*3]=J(W.position?.x,0),G[O][F*3+1]=J(W.position?.y,0),G[O][F*3+2]=J(W.position?.z,0);let z=J(W.quaternion?.x,0),N=J(W.quaternion?.y,0),Q=J(W.quaternion?.z,0),Zt=J(W.quaternion?.w,1),Qt=Math.hypot(z,N,Q,Zt)||1;if(z/=Qt,N/=Qt,Q/=Qt,Zt/=Qt,F>0){let Y=(F-1)*4,Jt=U[O];Jt[Y]*z+Jt[Y+1]*N+Jt[Y+2]*Q+Jt[Y+3]*Zt<0&&(z=-z,N=-N,Q=-Q,Zt=-Zt)}U[O][F*4]=z,U[O][F*4+1]=N,U[O][F*4+2]=Q,U[O][F*4+3]=Zt,Z[O][F*3]=J(W.scale?.x,1),Z[O][F*3+1]=J(W.scale?.y,1),Z[O][F*3+2]=J(W.scale?.z,1)}}for(let F=0;F<u.length;F++){let K=u[F],O=j[F];K.position?.set(O[0],O[1],O[2]),K.quaternion?.set(O[3],O[4],O[5],O[6]),K.scale?.set(O[7],O[8],O[9])}t.updateMatrixWorld(!0);let E=null,q=()=>(E===null&&(E=n(P,"SCALAR",0,5126,c,[0],[g])),E),k=[],H=[];for(let F=0;F<u.length;F++){let K=j[F],O=(z,N,Q)=>z.some((Zt,Qt)=>Math.abs(Zt-K[Q+Qt%N])>1e-4),W=(z,N,Q,Zt)=>{z&&H.push({sampler:k.push({input:q(),interpolation:"LINEAR",output:n(N,Q,0,5126,c)})-1,target:{node:F,path:Zt}})};W(O(G[F],3,0),G[F],"VEC3","translation"),W(O(U[F],4,3),U[F],"VEC4","rotation"),W(O(Z[F],3,7),Z[F],"VEC3","scale")}H.length>0&&_.push({name:"ProceduralLoop",samplers:k,channels:H})}let L=Oe(f,m,t.userData),C=[],D=[],M=[];for(let g=0;g<f.length;g++){let I=f[g],c=pt(I.extras?.xr);if(!c)continue;let{ae:P,src:j,preset:G,volume:U,loop:Z,isGlobal:E}=c,q=I.name||`Node_${g}`,k=D.length;D.push({name:`${q}_source`,gain:U,loop:Z,autoPlay:typeof P.autoplay=="boolean"?P.autoplay:!0,...j!==void 0?{audio:C.push({uri:j})-1}:{},...G?{extras:{preset:G,pitch:ge(P.pitch,.25,4,1)}}:{}});let H=M.length,F=ge(P.refDistance,.05,100,1),K=ge(P.coneInnerAngle,0,360,360),O=ge(P.coneOuterAngle,K,360,360);M.push({name:`${q}_emitter`,type:E?"global":"positional",gain:U,sources:[k],...E?{}:{positional:{distanceModel:P.distanceModel==="linear"||P.distanceModel==="exponential"?P.distanceModel:"inverse",refDistance:F,maxDistance:ge(P.maxDistance,F,500,Math.max(F,25)),rolloffFactor:ge(P.rolloffFactor,0,10,1),coneInnerAngle:+(K*Math.PI/180).toFixed(6),coneOuterAngle:+(O*Math.PI/180).toFixed(6),coneOuterGain:ge(P.coneOuterGain,0,1,0)}}}),I.extensions={...I.extensions||{},KHR_audio_emitter:{emitter:H}},p.add("KHR_audio_emitter")}let o={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:b}],scene:0,nodes:f,meshes:m,materials:d,...R.length>0?{images:R}:{},...S.length>0?{samplers:S}:{},...l.length>0?{textures:l}:{},accessors:s,bufferViews:a,buffers:[{byteLength:r}],..._.length>0?{animations:_}:{},...L||p.size>0?{extensionsUsed:[...L?["KHR_interactivity"]:[],...p]}:{},...L||T.length>0||M.length>0?{extensions:{...L?{KHR_interactivity:L}:{},...T.length>0?{KHR_materials_variants:{variants:T.map(g=>({name:g}))}}:{},...M.length>0?{KHR_audio_emitter:{...C.length>0?{audio:C}:{},sources:D,emitters:M}}:{}}}:{}},V=new Uint8Array(r),X=0;for(let g of i)V.set(g,X),X+=g.byteLength;return[{gltf:o,bin:V.buffer,lights:w,environmentIntensity:t.environmentIntensity},u]}function Ne(t){return new TextEncoder().encode(t)}function Wt(t,e){let{gltf:i,bin:r}=bt(t,e),a=JSON.stringify(i),s=Ne(a),m=(4-s.byteLength%4)%4,f=s.byteLength+m,p=20+f+8+r.byteLength,u=new Uint8Array(p),d=new DataView(u.buffer);d.setUint32(0,1179937895,!0),d.setUint32(4,2,!0),d.setUint32(8,p,!0),d.setUint32(12,f,!0),d.setUint32(16,1313821514,!0),u.set(s,20);for(let R=0;R<m;R++)u[20+s.byteLength+R]=32;let y=20+f;return d.setUint32(y,r.byteLength,!0),d.setUint32(y+4,5130562,!0),u.set(new Uint8Array(r),y+8),u}function yt(t,e){let[i,r]=gt(t,e);return Be(i,r)}function Be(t,e){let i=[],r=t.gltf,a=de().decoders.get("meshopt");a&&typeof a.decodeBufferViews=="function"&&a.decodeBufferViews(r,t);let s=t.bin,m=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),f=r.accessors||[],p=r.bufferViews||[],u=r.materials||[],d=r.meshes||[],y=r.nodes||[],R=new Set,S=u.map((T,w)=>ft(R,we(T?.name,`Material_${w}`)));function l(T){let w=f[T];if(!w)throw new Error(`Accessor ${T} not found`);let v=p[w.bufferView||0],h=(v.byteOffset||0)+(w.byteOffset||0),n=v.byteLength||0;return{acc:w,buffer:m.slice(h,h+n)}}function x(T,w,v,h){let n=[],b=d[T];if(!b)return n;let A=b.primitives||[];for(let $=0;$<A.length;$++){let B=A[$],_=B.attributes?.POSITION;if(_===void 0)continue;let{acc:L,buffer:C}=l(_),D=new Float32Array(C,0,L.count*3),M,o=B.attributes?.NORMAL;if(o!==void 0){let{acc:k,buffer:H}=l(o),F=new Float32Array(H,0,k.count*3);M=new Float32Array(F.length);for(let K=0;K<k.count;K++){let O=F[K*3],W=F[K*3+1],z=F[K*3+2],N=Math.hypot(O,W,z)||1;M[K*3]=O/N,M[K*3+1]=W/N,M[K*3+2]=z/N}}let V,X=B.attributes?.TEXCOORD_0;if(X!==void 0){let{acc:k,buffer:H}=l(X);V=new Float32Array(H,0,k.count*2)}let g;if(B.indices!==void 0){let{acc:k,buffer:H}=l(B.indices);g=k.componentType===5125?new Uint32Array(H,0,k.count):new Uint16Array(H,0,k.count);let F=L.count;for(let K of g)if(K>=F)throw new Error(`SecurityError: Index buffer value (${K}) out of vertex bounds [0, ${F}).`)}else{let k=L.count;g=k>65535?new Uint32Array(k):new Uint16Array(k);for(let H=0;H<k;H++)g[H]=H}let I="DefaultMaterial",c=[.8,.8,.8],P=.5,j=0,G=0,U=0,Z=1.5,E=1,q=[0,0,0];if(B.material!==void 0&&u[B.material]){let k=u[B.material];I=S[B.material]||`Material_${B.material}`;let H=k.pbrMetallicRoughness||{},F=(z,N)=>Array.isArray(z)&&z.length>=3?[z[0],z[1],z[2]]:N;c=F(H.baseColorFactor,[1,1,1]);let K=k.extras?.avgColor;Array.isArray(K)&&K.length>=3&&(c=[c[0]*K[0],c[1]*K[1],c[2]*K[2]]);let O=Array.isArray(H.baseColorFactor)&&typeof H.baseColorFactor[3]=="number"?H.baseColorFactor[3]:1;typeof H.roughnessFactor=="number"&&(P=H.roughnessFactor),typeof H.metallicFactor=="number"&&(j=H.metallicFactor),q=F(k.emissiveFactor,[0,0,0]);let W=k.extensions||{};W.KHR_materials_clearcoat&&(G=W.KHR_materials_clearcoat.clearcoatFactor??0,U=W.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof W.KHR_materials_ior?.ior=="number"&&(Z=W.KHR_materials_ior.ior),E=O*(1-(W.KHR_materials_transmission?.transmissionFactor??0))}n.push({name:A.length>1?`${w}_p${$}`:w,positions:D,indices:g,normals:M,uvs:V,materialName:I,color:c,roughness:P,metallic:j,clearcoat:G,clearcoatRoughness:U,ior:Z,opacity:E,emissiveColor:q,xrTraits:v||b.extras?.xr,...h?{invisible:!0}:{}})}return n}if(y.length>0){let T=new Float32Array(0),w=new Uint16Array(0),v=(D,M)=>{if(D===void 0)return null;let{acc:o,buffer:V}=l(D);return new Float32Array(V,0,o.count*M)},h=(D,M)=>Array.isArray(D)&&D.length>=3?[J(D[0],M),J(D[1],M),J(D[2],M)]:[M,M,M],n=(D,M,o)=>D&&D.length>=(M+1)*3?[D[M*3],D[M*3+1],D[M*3+2]]:o,b=(D,M,o)=>D&&D.length>=(M+1)*4?[D[M*4],D[M*4+1],D[M*4+2],D[M*4+3]]:o,A=new Map,$=r.animations?.[0];if($&&Array.isArray($.channels)&&Array.isArray($.samplers))for(let D of $.channels){let M=$.samplers[D?.sampler],o=D?.target?.node,V=D?.target?.path;if(!M||typeof o!="number"||M.input===void 0)continue;let X=A.get(o);X||(X={input:M.input},A.set(o,X)),V==="translation"?X.t=M.output:V==="rotation"?X.r=M.output:V==="scale"&&(X.s=M.output)}let B=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(B)||B.length===0){let D=new Set;for(let M of y)if(Array.isArray(M?.children))for(let o of M.children)D.add(o);B=[];for(let M=0;M<y.length;M++)D.has(M)||B.push(M);B.length===0&&(B=[0])}let _=new Set,L=[],C=(D,M)=>{if(Array.isArray(D))for(let o=D.length-1;o>=0;o--)L.push({idx:D[o],out:M})};for(C(B,i);L.length>0;){let{idx:D,out:M}=L.pop();if(typeof D!="number"||D<0||D>=y.length||_.has(D))continue;_.add(D);let o=y[D];if(!o)continue;let V=[0,0,0],X=[0,0,0,1],g=[1,1,1];if(Array.isArray(o.matrix)&&o.matrix.length===16){let E=dt(o.matrix);V=E.t,X=E.r,g=E.s}else V=h(o.translation,0),Array.isArray(o.rotation)&&o.rotation.length>=4&&(X=[J(o.rotation[0],0),J(o.rotation[1],0),J(o.rotation[2],0),J(o.rotation[3],1)]),g=h(o.scale,1);let I,c=A.get(D);if(c){let E=v(c.input,1);if(E&&E.length>0){let q=v(c.t,3),k=v(c.r,4),H=v(c.s,3),F=Array.from(E),K=[],O=[],W=[];for(let z=0;z<E.length;z++)K.push(n(q,z,V)),O.push(b(k,z,X)),W.push(n(H,z,g));I={times:F,translations:K,rotations:O,scales:W}}}let P=Array.isArray(o.children)?o.children:[],j=typeof o.mesh=="number"&&o.mesh>=0&&o.mesh<d.length,G=e?.[D]?.userData?.xr??o.extras?.xr;if(!j&&P.length===0&&(o.camera!==void 0||o.extensions?.KHR_lights_punctual||!o.name&&!o.extras&&!G&&!I))continue;let U=(E,q,k)=>({name:E,positions:T,indices:w,isXform:!0,xrTraits:G,timeSamples:I,translation:V,rotation:X,scale:g,children:q,...k?{invisible:!0}:{}}),Z=o.visible===!1||o.extensions?.KHR_node_visibility?.visible===!1||e?.[D]?.visible===!1;if(j){let E=o.name||d[o.mesh]?.name||`Mesh_${D}`,q=x(o.mesh,E,G,Z),k=o.extensions?.EXT_mesh_gpu_instancing?.attributes;if(k&&typeof k=="object"&&q.length>0){let H=v(k.TRANSLATION,3),F=v(k.ROTATION,4),K=v(k.SCALE,3),O=v(k._COLOR_0,3),W=Math.min(1e3,H?H.length/3:F?F.length/4:K?K.length/3:0);if(W>0){let z=[];for(let N=0;N<W;N++){let Q=n(H,N,[0,0,0]),Zt=b(F,N,[0,0,0,1]),Qt=n(K,N,[1,1,1]);for(let Y of q){let Jt=Y.color||[.8,.8,.8],te=O&&O.length>=(N+1)*3;z.push({...Y,name:`${Y.name}_${N}`,materialName:te?`${Y.materialName}_inst_${N}`:Y.materialName,color:te?[Jt[0]*O[N*3],Jt[1]*O[N*3+1],Jt[2]*O[N*3+2]]:Y.color,translation:Q,rotation:Zt,scale:Qt})}}C(P,z),M.push(U(E,z,Z));continue}}if(q.length===1)q[0].translation=V,q[0].rotation=X,q[0].scale=g,q[0].timeSamples=I,P.length>0&&(q[0].children=[],C(P,q[0].children)),M.push(q[0]);else{let H=[...q];C(P,H),M.push(U(E,H,Z))}}else{let E=[];C(P,E),M.push(U(o.name||`Group_${D}`,E,Z))}}}else for(let T=0;T<d.length;T++){let w=d[T].name||`Mesh_${T}`;i.push(...x(T,w,d[T].extras?.xr))}return i}function we(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 _e(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function le(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 pe=(t,e,i)=>`(${le(t)}, ${le(e)}, ${le(i)})`,mt=(t,e,i,r)=>`(${le(t)}, ${le(e)}, ${le(i)}, ${le(r)})`;function ht(t){let e=t.length/3,i=new Array(e);for(let r=0;r<e;r++)i[r]=pe(t[r*3],t[r*3+1],t[r*3+2]);return i.join(", ")}function jt(t,e){let i=new Array(e);for(let r=0;r<e;r++)i[r]=`(${le(t[r*2])}, ${le(1-t[r*2+1])})`;return i.join(", ")}function Xt(t){return Array.from(t).join(", ")}function Fe(t){let e=new Map,i=0,r=null,a=[...t];for(;a.length>0;){let l=a.pop();if(!l.isXform&&l.positions&&l.positions.length>0){let x=we(l.materialName,"DefaultMaterial");e.has(x)||e.set(x,{color:l.color||[.8,.8,.8],roughness:l.roughness??.5,metallic:l.metallic??0,clearcoat:l.clearcoat??0,clearcoatRoughness:l.clearcoatRoughness??0,ior:l.ior??1.5,opacity:l.opacity??1,emissiveColor:l.emissiveColor||[0,0,0]})}if(l.timeSamples&&l.timeSamples.times.length>0){let x=l.timeSamples.times[l.timeSamples.times.length-1];x>i&&(i=x)}if(l.xrTraits?.anchor&&!r&&(r=l.xrTraits.anchor==="vertical"||l.xrTraits.anchor==="wall"?"vertical":"horizontal"),l.children)for(let x=l.children.length-1;x>=0;x--)a.push(l.children[x])}let s="";i>0&&(s=`startTimeCode = 0
|
|
250
|
-
endTimeCode = ${
|
|
249
|
+
void main(){fragColor=uColorId;}`;function Ke(e,t,i){let r={};for(let a of i)r[a]=e.getUniformLocation(t,a);return r}var nt=["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 ut(){let e=pe().xrDepthShader;return{fs:Nt.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...nt,...e.uniformNames]:nt}}function kt(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 We(e,t,i,r,a,s,m,p){if(r===void 0||!t.accessors?.[r])return null;let g=$e(t,i,t.accessors[r],s);if(!g)return null;p&&(g=g.slice(),Je(g,p));let c=e.createBuffer();return m.push(c),e.bindBuffer(34962,c),e.bufferData(34962,g,35044),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,s,5126,!1,0,0),g}function je(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function ct(e,t,i){let r=ut(),a=at,s=r.fs,m=!1;for(let g of me)if(g.onResolveShader){let c=g.onResolveShader(t,i,a,s);c&&(a=c.vs,s=c.fs,m=!0)}let p=m?Pe(e,a,s):null;return{program:p,uniforms:p?Ke(e,p,r.uniforms):null}}function Gt(e,t,i){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let a=r.length>>4,s=t.instanceColors,m=new Float32Array(a*20);for(let g=0;g<a;g++)m.set(r.subarray(g*16,g*16+16),g*20),m[g*20+16]=s?s[g*3]:1,m[g*20+17]=s?s[g*3+1]:1,m[g*20+18]=s?s[g*3+2]:1,m[g*20+19]=1;let p=e.createBuffer();i.push(p),e.bindBuffer(34962,p),e.bufferData(34962,m,35044);for(let g=0;g<5;g++)e.enableVertexAttribArray(8+g),e.vertexAttribPointer(8+g,4,5126,!1,80,g*16),e.vertexAttribDivisor(8+g,1);return!0}function Ot(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 a of r){let s=a?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var un=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),lt=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ie(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function mt(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,a=e?.extensions?.KHR_materials_clearcoat,s=m=>m!==void 0&&t[m.index]?t[m.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:a?a.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,a?.clearcoatRoughnessFactor??.04),texture:s(i?.baseColorTexture),metallicRoughnessTexture:s(i?.metallicRoughnessTexture),normalTexture:s(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:s(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function ht(e,t,i){let r=new Set,a=s=>{s&&!r.has(s)&&(r.add(s),e.deleteTexture(s))};for(let s of t)for(let m of s.primitives){if(m.vao&&e.deleteVertexArray(m.vao),m.buffers)for(let g of m.buffers)e.deleteBuffer(g);a(m.texture),a(m.metallicRoughnessTexture),a(m.normalTexture),a(m.occlusionTexture);let p=new Set;m.customProgram&&p.add(m.customProgram);for(let g of m.programCache?.values()??[])g.program&&p.add(g.program);for(let g of p)e.deleteProgram(g)}if(i)for(let s of i)a(s)}function rt(e,t,i=lt,r){let a={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Vt(e,t,i,r,a)}catch(s){let m=a.mesh&&!a.meshes.includes(a.mesh)?[...a.meshes,a.mesh]:a.meshes;ht(e,m,a.gpuTextures),a.vao&&e.deleteVertexArray(a.vao);for(let p of a.buffers)e.deleteBuffer(p);throw s}}function Vt(e,t,i,r,a){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=t,m=Ae("meshopt");m?.decodeBufferViews&&m.decodeBufferViews(s,t);let p=t.bin,g=[];a.meshes=g;let c=[],v=s.extensions?.KHR_materials_variants;v&&Array.isArray(v.variants)&&v.variants.forEach((R,n)=>{c.push(typeof R?.name=="string"&&R.name?R.name:`Variant_${n}`)});let y=tt(s),D=[];if(Array.isArray(s.nodes))for(let R=0;R<s.nodes.length;R++){let n=s.nodes[R];n.mesh!==void 0&&s.meshes&&s.meshes[n.mesh]&&D.push({node:n,nodeIdx:R,meshIdx:n.mesh})}let S=D.length>0?D:(s.meshes||[]).map((R,n)=>({node:R,nodeIdx:-1,meshIdx:n})),h=[],b=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(s.asset?.extras?.lights)&&s.asset.extras.lights.length>0?s.asset.extras.lights:null;if(b)for(let R of b)h.push({...R,type:R.type||R.light_type||"point",innerConeAngle:R.innerConeAngle??R.inner_cone_angle,outerConeAngle:R.outerConeAngle??R.outer_cone_angle});else if(s.extensions?.KHR_lights_punctual?.lights){let R=s.extensions.KHR_lights_punctual.lights;for(let n of R){let E=n.type==="directional"?"directional":n.type==="point"?"point":n.type==="spot"?"spot":"ambient";h.push({type:E,color:n.color||[1,1,1],intensity:n.intensity!==void 0?n.intensity:1})}}if(h.length===0&&(h.push({type:"ambient",color:[1,1,1],intensity:.35}),h.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),S.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${S.length}`);let C=[];if(a.gpuTextures=C,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 R=0;R<s.textures.length;R++){let n=s.textures[R],E=s.images[n.source];if(E){let G=e.createTexture();e.bindTexture(3553,G),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 f=x=>{e.bindTexture(3553,G),e.texImage2D(3553,0,6408,6408,5121,x),e.generateMipmap(3553),r?.()};if(E.bufferView!==void 0){let x=s.bufferViews[E.bufferView],o=x.byteOffset||0,d=new Blob([p.slice(o,o+x.byteLength)],{type:E.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(d).then(f).catch(()=>{})}else if(E.uri){let x=kt(E.uri);if(x){let o=new Image;o.crossOrigin="anonymous",o.referrerPolicy="no-referrer",o.onload=()=>f(o),o.src=x}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",E.uri)}C.push(G)}else C.push(null)}}let A=[1/0,1/0,1/0],w=[-1/0,-1/0,-1/0],u=0,l=0;for(let R=0;R<S.length;R++){let n=S[R],E=s.meshes[n.meshIdx],G=n.nodeIdx>=0?y[n.nodeIdx]:ce(),f=new Float32Array(9);ve(f,G);let x={name:n.node.name||E.name||`Mesh_${n.meshIdx}`,nodeIndex:n.nodeIdx,transform:G,normalMatrix:f,primitives:[],extras:n.node.extras||E.extras,...n.node?.visible===!1||n.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};a.mesh=x;let o=n.node?.extensions?.EXT_mesh_gpu_instancing;if(o&&o.attributes&&typeof o.attributes=="object"){let d=o.attributes,U=d.TRANSLATION!==void 0?s.accessors?.[d.TRANSLATION]:null,j=d.ROTATION!==void 0?s.accessors?.[d.ROTATION]:null,B=d.SCALE!==void 0?s.accessors?.[d.SCALE]:null,Y=d._COLOR_0!==void 0?s.accessors?.[d._COLOR_0]:null,H=Number(U?.count??j?.count??B?.count??0);if(!Number.isFinite(H)||H<0||H>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${H}`);if(H>0){let Z=(I,N)=>{if(!I||I.bufferView===void 0||!s.bufferViews?.[I.bufferView])return null;let z=I.componentType??5126,X=J=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${J})`),null);if(z!==5120&&z!==5121&&z!==5122&&z!==5123&&z!==5126)return X(`componentType ${z}`);if(!(Number(I.count)>=H))return X(`count ${I.count} < ${H}`);let q=null;try{q=$e(s,p,{...I,count:H},N)}catch{return X("out of bounds")}return!q||!q.every(Number.isFinite)?X("non-finite value"):q},te=Z(U,3),re=Z(j,4),k=Z(B,3),ie=Y?.type==="VEC4"?4:3,O=Z(Y,ie),K=new Float32Array(H*16),W=ce();for(let I=0;I<H;I++){let N=te?[te[I*3],te[I*3+1],te[I*3+2]]:[0,0,0],z=re?[re[I*4],re[I*4+1],re[I*4+2],re[I*4+3]]:[0,0,0,1],X=k?[k[I*3],k[I*3+1],k[I*3+2]]:[1,1,1];He(W,z,N,X),K.set(W,I*16)}if(x.instanceMatrices=K,O){let I=new Float32Array(H*3);for(let N=0;N<H;N++)I[N*3]=O[N*ie],I[N*3+1]=O[N*ie+1],I[N*3+2]=O[N*ie+2];x.instanceColors=I}}}for(let d of E.primitives||[]){if(d.extensions?.KHR_draco_mesh_compression){let q=Ae("draco");q&&q.decodePrimitive(s,d,p)}let U=[],j=e.createVertexArray();a.vao=j,a.buffers=U,e.bindVertexArray(j);let B=Gt(e,x,U),Y=s.accessors[d.attributes.POSITION],H=Number(Y?.count??0);if(!Number.isFinite(H)||H<0||u+H>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(u+=H,Y?.min&&Y?.max){let q=J=>{for(let Q=0;Q<3;Q++){let ue=J[12+Q],ae=J[12+Q];for(let se=0;se<3;se++){let oe=J[se*4+Q]*Y.min[se],ne=J[se*4+Q]*Y.max[se];ue+=oe<ne?oe:ne,ae+=oe>ne?oe:ne}ue<A[Q]&&(A[Q]=ue),ae>w[Q]&&(w[Q]=ae)}};if(x.instanceMatrices&&x.instanceMatrices.length>=16){let J=x.instanceMatrices.length>>4,Q=ce();for(let ue=0;ue<J;ue++){let ae=x.instanceMatrices.subarray(ue*16,ue*16+16);fe(Q,G,ae),q(Q)}}else q(G)}let Z=We(e,s,p,d.attributes.POSITION,0,3,U);We(e,s,p,d.attributes.NORMAL,1,3,U),We(e,s,p,d.attributes.TEXCOORD_0,2,2,U,Ot(s,d));let te=0,re=5123,k=null;if(d.indices!==void 0){let q=s.accessors[d.indices],J=(s.bufferViews[q.bufferView].byteOffset||0)+(q.byteOffset||0);if(te=Number(q.count??0),!Number.isFinite(te)||te<0||l+te>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);l+=te,re=q.componentType===5125?5125:5123;let Q=e.createBuffer();U.push(Q),e.bindBuffer(34963,Q),q.componentType===5125?k=new Uint32Array(p,J,q.count):q.componentType===5121?k=Uint16Array.from(new Uint8Array(p,J,q.count)):k=J%2===0?new Uint16Array(p,J,q.count):new Uint16Array(p.slice(J,J+q.count*2)),e.bufferData(34963,k,35044)}else te=Y.count;let ie={};for(let q of me)if(q.onBuildPrimitiveVAO){let J=q.onBuildPrimitiveVAO(e,j,d,s,p);J&&(ie[q.name]=J)}e.bindVertexArray(null);let O=s.materials&&d.material!==void 0?s.materials[d.material]:null,{program:K,uniforms:W}=ct(e,d,O),I=mt(O,C),N=!!(O?.extensions?.KHR_materials_transmission||ie.materials?.isTransmissive),z=d.extensions?.KHR_materials_variants?.mappings,X=Array.isArray(z)?z.filter(q=>q&&typeof q.material=="number"&&Array.isArray(q.variants)).map(q=>({material:q.material|0,variants:q.variants.map(J=>Number(J)|0)})):void 0;x.primitives.push({vao:j,instanced:B,indexCount:te,indexType:re,...I,positions:Z,indices:k,buffers:U,materialIndex:d.material,defaultMaterialIndex:d.material,variantMappings:X,primitiveDef:d,programCache:new Map([[d.material??-1,{program:K,uniforms:W}]]),pluginData:ie,customProgram:K,customUniforms:W,isTransmissive:N})}g.push(x)}isFinite(A[0])||(A=[-1,-1,-1]),isFinite(w[0])||(w=[1,1,1]);let M=[(A[0]+w[0])/2,(A[1]+w[1])/2,(A[2]+w[2])/2],P=w[0]-A[0],$=w[1]-A[1],V=w[2]-A[2],F=Math.max(Math.hypot(P,$,V)/2,.5),_=[A[0],A[1],A[2]],T=[w[0],w[1],w[2]],L=t.animations;if(!L){for(let R of me)if(R.onParseGLB?.(t),t.animations){L=t.animations;break}}return L||(L=[]),{meshes:g,bounds:{center:M,radius:F,min:_,max:T},lights:h,animations:L,worldMatrices:y,gpuTextures:C,availableVariants:c}}function we(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 Fe=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=ce(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=ce(),this.viewMatrix=ce(),this.activeViewMatrix=null,this.modelMatrix=ce(),this.mvpMatrix=ce(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshName="",this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:ce(),rawValueToMeters:.001,format:0},this.container=e;let r,a;if(t&&typeof t.getContext=="function"?(r=t,a=i):(a=t,r=a?.canvas),!r){let p=e.querySelector("canvas");p||(p=document.createElement("canvas"),p.style.width="100%",p.style.height="100%",p.style.display="block",p.style.touchAction="none",e.prepend(p)),r=p}this.canvas=r,this.opts=a||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=je(this.opts.exposure)),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=Xe(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let m=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!m)throw new Error("WebGL2 not supported");this.gl=m,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){Ft(e,t)}static getDecoder(e){return Ae(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=ut();this.renderProg=Pe(e,at,t.fs),this.pickProg=Pe(e,Bt,Ut),this.uRender=Ke(e,this.renderProg,t.uniforms),this.uPick=Ke(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of me)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),a=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=a,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,a,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,a)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:a,animations:s,worldMatrices:m,gpuTextures:p,availableVariants:g}=rt(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=a,this.animations=s||[],this.worldMatrices=m||[],this.gpuTextures=p||[],this.availableVariants=g||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let y of e.gltf.nodes)this.initialNodeTransforms.push({t:y.translation?[y.translation[0],y.translation[1],y.translation[2]]:[0,0,0],r:y.rotation?[y.rotation[0],y.rotation[1],y.rotation[2],y.rotation[3]]:[0,0,0,1],s:y.scale?[y.scale[0],y.scale[1],y.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let y of me)y.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 c=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;c!==void 0&&(this.exposure=je(c));let v=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;v!==void 0&&(this.envIntensity=Math.max(0,Number(v)||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(ot(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of me)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Re(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=Re(e),{meshes:r}=rt(this.gl,i,lt,()=>this.render());if(t)for(let a of r)a.transform[12]+=t[0],a.transform[13]+=t[1],a.transform[14]+=t[2],ve(a.normalMatrix,a.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),ve(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],a=[],s=[],m=[],p=[],g=[];for(let c of this.lights){let v=c.color||[1,1,1],y=c.intensity!==void 0?c.intensity:1;if(c.type==="ambient")i=[v[0]*y,v[1]*y,v[2]*y];else if(c.type==="directional"&&r.length<6){let D=c.direction||[.5,1,.8];r.push(D[0],D[1],D[2]),a.push(v[0]*y,v[1]*y,v[2]*y)}else if((c.type==="point"||c.type==="spot")&&s.length<6){let D=c.position||[0,0,0];if(s.push(D[0],D[1],D[2]),m.push(v[0]*y,v[1]*y,v[2]*y),c.type==="spot"){let S=c.direction||[0,-1,0],h=Math.max(.01,Math.min(Math.PI/2,c.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(h-1e-4,c.innerConeAngle??0));p.push(S[0],S[1],S[2]),g.push(Math.cos(b),Math.cos(h))}else p.push(0,-1,0),g.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),a.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,a)),t.uniform1i(e.uNumPointLights,s.length/3),s.length>0&&(t.uniform3fv(e.uPointLightPos,s),t.uniform3fv(e.uPointLightColor,m),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,p),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,g)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=je(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Xe(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of me)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of me)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(c=>c.primitives.filter(v=>v.materialIndex===i||e.length===1&&v.materialIndex===void 0)),a=r[0],s=a?[...a.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],m=a?a.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,p=a?a.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,g={baseColorFactor:s,metallicFactor:m,roughnessFactor:p,setBaseColorFactor:c=>{let v=[c[0],c[1],c[2],c[3]??1];g.baseColorFactor=v,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=v);for(let y of r)y.baseColor=v;this.render()},setMetallicFactor:c=>{g.metallicFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=c);for(let v of r)v.metallic=c;this.render()},setRoughnessFactor:c=>{g.roughnessFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=c);for(let v of r)v.roughness=c;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:g}})}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 a of this.meshes)for(let s of a.primitives){let m=s.defaultMaterialIndex;if(!t&&Array.isArray(s.variantMappings)){for(let g of s.variantMappings)if(Array.isArray(g.variants)&&g.variants.includes(i)){m=g.material;break}}let p=m!==void 0?r[m]:void 0;s.materialIndex=p?m:void 0,Object.assign(s,mt(p,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,p??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,a=e.programCache.get(r);a||(a=ct(this.gl,{...e.primitiveDef,material:t},i),e.programCache.set(r,a)),e.customProgram=a.program,e.customUniforms=a.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 me)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 a=this.clampDistance(i);this.initialDistance=a,this.customDistance=!0,this.targetDistance=a,this.currDistance=a}else if(r!==void 0&&r>0){let a=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=a,this.customDistance=!0,this.targetDistance=a,this.currDistance=a}else{this.customDistance=!1;let a=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=a,this.targetDistance=a,this.currDistance=a}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=ce();fe(i,this.projMatrix,this.viewMatrix);let[r,a,s]=e,m=t?t[0]:0,p=t?t[1]:0,g=t?t[2]:0,c=this.modelRootMatrix;c&&(r=c[0]*e[0]+c[4]*e[1]+c[8]*e[2]+c[12],a=c[1]*e[0]+c[5]*e[1]+c[9]*e[2]+c[13],s=c[2]*e[0]+c[6]*e[1]+c[10]*e[2]+c[14],t&&(m=c[0]*t[0]+c[4]*t[1]+c[8]*t[2],p=c[1]*t[0]+c[5]*t[1]+c[9]*t[2],g=c[2]*t[0]+c[6]*t[1]+c[10]*t[2]));let v=i[0]*r+i[4]*a+i[8]*s+i[12],y=i[1]*r+i[5]*a+i[9]*s+i[13],D=i[2]*r+i[6]*a+i[10]*s+i[14],S=i[3]*r+i[7]*a+i[11]*s+i[15];if(S<=1e-4)return{x:0,y:0,z:1,visible:!1};let h=v/S,b=y/S,C=D/S,A=this.canvas.getBoundingClientRect(),w=A.width||this.canvas.clientWidth||this.canvas.width||300,u=A.height||this.canvas.clientHeight||this.canvas.height||150,l=(h*.5+.5)*w,M=(-b*.5+.5)*u,P=h>=-1.1&&h<=1.1&&b>=-1.1&&b<=1.1&&C>=-1&&C<=1;if(P&&t){let[$,V,F]=we(this),_=[r-$,a-V,s-F];m*_[0]+p*_[1]+g*_[2]>.05&&(P=!1)}return{x:l,y:M,z:C,visible:P}}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},a=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(a,s),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let m=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],p=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],g=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;g[0]+=(-a*m[0]+s*p[0])*c,g[1]+=(-a*m[1]+s*p[1])*c,g[2]+=(-a*m[2]+s*p[2])*c,this.customTarget=g}else this.targetTheta=this.clampTheta(this.targetTheta-a*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.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(),a=Math.floor((i.clientX-r.left)*(e.width/Math.max(r.width,1))),s=Math.floor((i.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(a,s,!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,a)=>{this[a]&&(i.removeEventListener(r,this[a]),this[a]=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(),a=i.width||300,s=i.height||300,m=r.width>0?Math.floor((e-r.left)*(a/r.width)):Math.floor(e),p=r.height>0?Math.floor((t-r.top)*(s/r.height)):Math.floor(t);return this.performMeshPick(m,p,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,a=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,a);let m=ce();fe(m,this.projMatrix,this.viewMatrix);let p=[],g=Math.max(0,Math.min(a-1,e)),c=Math.max(0,Math.min(s-1,s-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==a||this.pickFboHeight!==s)&&this.resizePickingFbo(a,s),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,a,s),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let M=0;M<this.meshes.length;M++){let P=this.meshes[M];if(P.visible===!1||P.isPluginMesh)continue;let $=M+1,V=($&255)/255,F=($>>8&255)/255,_=($>>16&255)/255;r.uniform4f(this.uPick.uColorId,V,F,_,1),fe(this.modelMatrix,this.modelRootMatrix,P.transform);let T=P.instanceMatrices;if(T&&T.length>=16){let L=T.length>>4,R=ce();for(let n of P.primitives){r.bindVertexArray(n.vao);for(let E=0;E<L;E++)fe(R,this.modelMatrix,T.subarray(E*16,E*16+16)),fe(this.mvpMatrix,m,R),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Ie(r,n)}}else{fe(this.mvpMatrix,m,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let L of P.primitives)r.bindVertexArray(L.vao),Ie(r,L)}}let u=new Uint8Array(4);r.readPixels(g,c,1,1,6408,5121,u),r.bindFramebuffer(36160,null);let l=u[0]+(u[1]<<8)+(u[2]<<16);l>0&&l<=this.meshes.length&&(p=[this.meshes[l-1]])}p.length===0&&(p=this.meshes.filter(u=>u.visible!==!1));let v=null,y=1/0,D=[0,0,0],S=[0,1,0],[h,b,C]=we(this),A=ce();for(let u of p){fe(A,this.modelRootMatrix,u.transform);let l=u.instanceMatrices,M=l&&l.length>=16?l.length>>4:1;for(let P=0;P<M;P++){l&&l.length>=16?fe(this.modelMatrix,A,l.subarray(P*16,P*16+16)):this.modelMatrix.set(A),fe(this.mvpMatrix,m,this.modelMatrix);let $=ce();if(!Qe($,this.mvpMatrix))continue;let V=(g+.5)/a*2-1,F=(c+.5)/s*2-1,_=[0,0,0],T=[0,0,0];ze(_,V,F,-1,$),ze(T,V,F,1,$);let L=T[0]-_[0],R=T[1]-_[1],n=T[2]-_[2],E=Math.hypot(L,R,n)||1,G=L/E,f=R/E,x=n/E,o={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((d=>{for(let U of u.primitives){if(!U.positions)continue;let j=U.positions,B=U.indices,Y=Math.floor(B?B.length/3:j.length/9);for(let H=0;H<Y;H++){let Z=B?B[H*3]:H*3,te=B?B[H*3+1]:H*3+1,re=B?B[H*3+2]:H*3+2;et(_[0],_[1],_[2],G,f,x,j[Z*3],j[Z*3+1],j[Z*3+2],j[te*3],j[te*3+1],j[te*3+2],j[re*3],j[re*3+1],j[re*3+2],o,d)}}})(1e-4),isFinite(o.distance)){let d=o.point[0],U=o.point[1],j=o.point[2],B=this.modelMatrix,Y=B[0]*d+B[4]*U+B[8]*j+B[12],H=B[1]*d+B[5]*U+B[9]*j+B[13],Z=B[2]*d+B[6]*U+B[10]*j+B[14],te=Y-h,re=H-b,k=Z-C,ie=Math.hypot(te,re,k);if(ie<y){ve(this.normalMatrix,this.modelMatrix);let O=this.normalMatrix,K=o.normal[0],W=o.normal[1],I=o.normal[2],N=O[0]*K+O[3]*W+O[6]*I,z=O[1]*K+O[4]*W+O[7]*I,X=O[2]*K+O[5]*W+O[8]*I,q=Math.hypot(N,z,X)||1;N/=q,z/=q,X/=q,N*te+z*re+X*k>0&&(N=-N,z=-z,X=-X),v=u,y=Math.round(ie*1e3)/1e3,D=[Math.round(Y*1e3)/1e3,Math.round(H*1e3)/1e3,Math.round(Z*1e3)/1e3],S=[Math.round(N*1e3)/1e3,Math.round(z*1e3)/1e3,Math.round(X*1e3)/1e3]}}}}if(!v)return null;let w={meshIndex:this.meshes.indexOf(v),meshName:v.name,nodeIndex:v.nodeIndex,distance:y,hitPoint:D,normal:S,screenX:e,screenY:t};if(i){for(let u of me)u.onMeshSelect?.(this,w);this.opts.onMeshClick&&this.opts.onMeshClick(w),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:w}))}return w}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,a=r?e-i:e,s=r?Math.max(1,t-i):i,m=(a+.5)/s*2-1;return Math.floor((m*.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);Ce(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;Le(this.viewMatrix,we(this),i,[0,1,0]),fe(this.mvpMatrix,this.projMatrix,this.viewMatrix),ve(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 me)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 me)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],a=this.modelRootMatrix;a[0]=e,a[1]=0,a[2]=-t,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=t,a[9]=0,a[10]=e,a[11]=0,a[12]=i-(e*i+t*r),a[13]=0,a[14]=r-(-t*i+e*r),a[15]=1}setVisible(e){this.isVisible=e}update(e){for(let s of me)s.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 s of me)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),a=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(a-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=a;let s={theta:i,phi:r,zoom:a,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(e,t,i,r,a=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let m=e?.transform?.inverse?.matrix||this.viewMatrix,p=e?.projectionMatrix||this.projMatrix,g=e?.transform?.position,c=g?[g.x,g.y,g.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:m,projMatrix:p,eyePos:c,viewport:r,eye:e?.eye||"none",clear:s>0?!1:e?.eye!=="right",isAR:a})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let w=Math.max(2,this.canvas.width||2),u=Math.max(1,this.canvas.height||1),l=Math.max(1,Math.floor(w*.5)),M=Math.max(1,w-l),P=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),$=this.customTarget||this.bounds.center,[V,F,_]=we(this),T=Math.cos(this.currTheta),L=-Math.sin(this.currTheta),R=.032,n=ce(),E=ce(),G=[V-T*R,F,_-L*R],f=[$[0]-T*R*.25,$[1],$[2]-L*R*.25];Ce(n,this.fov,l/u,.1,P),Le(E,G,f,[0,1,0]);let x=ce(),o=ce(),d=[V+T*R,F,_+L*R],U=[$[0]+T*R*.25,$[1],$[2]+L*R*.25];Ce(x,this.fov,M/u,.1,P),Le(o,d,U,[0,1,0]),this.render({viewMatrix:E,projMatrix:n,eyePos:G,viewport:[0,0,l,u],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:o,projMatrix:x,eyePos:d,viewport:[l,0,M,u],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,w,u);return}let t=this.gl,i=0,r=0,a=this.canvas.width,s=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],a=e.viewport[2],s=e.viewport[3],t.viewport(i,r,a,s)):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 m=ce(),p=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=p,fe(m,e?.projMatrix??this.projMatrix,p);let g=pe().xrDepthShader,c=Lt(this.toneMapping),[v,y,D]=e?e.eyePos:we(this);for(let w of me)w.onBeforeDrawScene?.(this,t,m,[v,y,D],c);let S=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&S===0)return;let h=e?.eye||"none",b=!1,C=S>0?[...this.backdropMeshes,...this.meshes]:this.meshes,A=w=>{for(let u=0;u<C.length;u++){let l=C[u];if(l.visible===!1)continue;let M=this.selectedMeshName!==""&&l.name===this.selectedMeshName;u<S||l.worldSpace===!0||l.name==="__xr_reticle__"?this.modelMatrix.set(l.transform):fe(this.modelMatrix,this.modelRootMatrix,l.transform),fe(this.mvpMatrix,m,this.modelMatrix),ve(l.normalMatrix,this.modelMatrix);let P=l.extras?.xr?.stereo||l.userData?.xr?.stereo,$=0,V=0,F=1,_=1;P==="sbs"?(F=.5,$=h==="right"?.5:0):P==="ou"&&(_=.5,V=h==="right"?.5:0);for(let T of l.primitives){let L=!!T.isTransmissive;if(!w&&L){b=!0;continue}if(w&&!L)continue;let R=T.customProgram||this.renderProg,n=T.customUniforms||this.uRender;t.useProgram(R),t.vertexAttrib3f(3,0,0,0),n.uInstanced&&t.uniform1i(n.uInstanced,0),t.uniform1i(n.uToneMapping,c),t.uniform1f(n.uEnvIntensity,this.envIntensity),n.uExposure&&t.uniform1f(n.uExposure,this.exposure),t.uniform3f(n.uCameraPos,v,y,D),t.uniform1f(n.uEmissive,M?1:0),t.uniformMatrix4fv(n.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(n.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(n.uNormalMatrix,!1,l.normalMatrix),n.uUvTransform&&t.uniform4f(n.uUvTransform,$,V,F,_),n.uViewportSize&&t.uniform2f(n.uViewportSize,Math.max(1,a),Math.max(1,s)),g?.bind(t,n,this.xrDepthState,p,[i,r,Math.max(1,a),Math.max(1,s)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(n.uEnvironmentMap,4),t.uniform1i(n.uHasEnvironmentMap,1)):t.uniform1i(n.uHasEnvironmentMap,0),this.bindLights(n),n.uSectionEnabled&&t.uniform1i(n.uSectionEnabled,0);for(let G of me)G.onBeforeDrawPrimitive?.(t,R,T,l,this.worldMatrices||[],this.gltf);t.uniform4fv(n.uBaseColor,T.baseColor),t.uniform1f(n.uMetallic,T.metallic),t.uniform1f(n.uRoughness,T.roughness),n.uClearcoat&&t.uniform2f(n.uClearcoat,T.clearcoat??0,T.clearcoatRoughness??.04),T.texture?(t.activeTexture(33984),t.bindTexture(3553,T.texture),t.uniform1i(n.uBaseColorTexture,0),t.uniform1i(n.uHasTexture,1)):t.uniform1i(n.uHasTexture,0),T.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,T.metallicRoughnessTexture),t.uniform1i(n.uMetallicRoughnessTexture,1),t.uniform1i(n.uHasMetallicRoughnessTexture,1)):t.uniform1i(n.uHasMetallicRoughnessTexture,0),T.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,T.normalTexture),t.uniform1i(n.uNormalTexture,2),t.uniform1i(n.uHasNormalTexture,1),t.uniform1f(n.uNormalScale,T.normalScale)):t.uniform1i(n.uHasNormalTexture,0),T.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,T.occlusionTexture),t.uniform1i(n.uOcclusionTexture,3),t.uniform1i(n.uHasOcclusionTexture,1),t.uniform1f(n.uOcclusionStrength,T.occlusionStrength)):t.uniform1i(n.uHasOcclusionTexture,0),t.bindVertexArray(T.vao);let E=l.instanceMatrices;if(T.instanceCount!==void 0)t.drawElementsInstanced(4,T.indexCount,T.indexType,0,T.instanceCount);else if(E&&E.length>=16&&T.instanced&&n.uInstanced&&n.uViewProj){let G=E.length>>4;t.uniform1i(n.uInstanced,1),t.uniformMatrix4fv(n.uViewProj,!1,m),T.indices?t.drawElementsInstanced(4,T.indexCount,T.indexType,0,G):t.drawArraysInstanced(4,0,T.indexCount,G),t.uniform1i(n.uInstanced,0)}else if(E&&E.length>=16){let G=E.length>>4,f=l.instanceColors,x=ce(),o=new Float32Array(9),d=[T.baseColor[0],T.baseColor[1],T.baseColor[2],T.baseColor[3]];for(let U=0;U<G;U++)fe(x,this.modelMatrix,E.subarray(U*16,U*16+16)),fe(this.mvpMatrix,m,x),ve(o,x),t.uniformMatrix4fv(n.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(n.uModel,!1,x),t.uniformMatrix3fv(n.uNormalMatrix,!1,o),f&&(d[0]=T.baseColor[0]*f[U*3],d[1]=T.baseColor[1]*f[U*3+1],d[2]=T.baseColor[2]*f[U*3+2],d[3]=T.baseColor[3],t.uniform4fv(n.uBaseColor,d)),Ie(t,T)}else Ie(t,T)}}};if(A(!1),b){for(let w of me)w.onBeforeTransmissivePass?.(t,this);A(!0)}for(let w of me)w.onAfterRender?.(t,this,m,e?.eye??"none",[i,r,a,s],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){ht(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 me)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()}};Fe.registerPlugin=Ye,Fe.getRegisteredPlugins=Ze;function $t(e){return e+3&-4}var ee=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function dt(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function pt(e,t=0){let[i,r,a,,s,m,p,,g,c,v,,y,D,S]=Array.from({length:15},(o,d)=>ee(e[t+d],d%5===0?1:0)),h=Math.hypot(i,r,a),b=Math.hypot(s,m,p),C=Math.hypot(g,c,v);i*(m*v-c*p)-s*(r*v-c*a)+g*(r*p-m*a)<0&&(h=-h);let A=Math.abs(h)>1e-8?1/h:0,w=Math.abs(b)>1e-8?1/b:0,u=Math.abs(C)>1e-8?1/C:0,l=i*A,M=r*A,P=a*A,$=s*w,V=m*w,F=p*w,_=g*u,T=c*u,L=v*u,R=l+V+L,n=0,E=0,G=0,f=1;if(R>0){let o=.5/Math.sqrt(R+1);f=.25/o,n=(F-T)*o,E=(_-P)*o,G=(M-$)*o}else if(l>V&&l>L){let o=2*Math.sqrt(Math.max(0,1+l-V-L));o>1e-8&&(f=(F-T)/o,n=.25*o,E=($+M)/o,G=(_+P)/o)}else if(V>L){let o=2*Math.sqrt(Math.max(0,1+V-l-L));o>1e-8&&(f=(_-P)/o,n=($+M)/o,E=.25*o,G=(F+T)/o)}else{let o=2*Math.sqrt(Math.max(0,1+L-l-V));o>1e-8&&(f=(M-$)/o,n=(_+P)/o,E=(F+T)/o,G=.25*o)}let x=Math.hypot(n,E,G,f);return x>1e-8&&Number.isFinite(x)?(n/=x,E/=x,G/=x,f/=x):(n=0,E=0,G=0,f=1),{t:[y,D,S],r:[n,E,G,f],s:[h,b,C]}}function Ht(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 Me=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function bt(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,a=typeof i.preset=="string"?i.preset:void 0;return!r&&!a?null:{ae:i,src:r,preset:a,volume:Me(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function gt(e,t){return yt(e,t)[0]}function yt(e,t){e.updateMatrixWorld(!0);let i=[],r=0,a=[],s=[],m=[],p=[],g=new Set,c=[],v=[],y=new Map,D=[],S=[],h=[],b=new Map,C=[],A=[];function w(f){let x=y.get(f);if(x!==void 0)return x;x=v.length,y.set(f,x);let o=f,d=o.color?.r??1,U=o.color?.g??1,j=o.color?.b??1,B=o.opacity??1,Y={baseColorFactor:[d,U,j,B],metallicFactor:o.metalness??0,roughnessFactor:o.roughness??.5},H={},Z=N=>{if(!N)return;let z=(typeof N=="string"?N:typeof N.source=="string"?N.source:typeof N.image=="string"?N.image:"").trim();if(!z||/[\x00-\x1f\x7f\\]|\.\./.test(z)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(z)||!z.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(z)))return;let X=b.get(z);if(X===void 0){let q=D.length;D.push({uri:z}),S.length===0&&S.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),X=h.length,h.push({sampler:0,source:q}),b.set(z,X)}return{index:X}},te=Z(o.map);te&&(Y.baseColorTexture=te);let re=Z(o.roughnessMap||o.metalnessMap);re&&(Y.metallicRoughnessTexture=re);let k=o.map?.avgColor;Array.isArray(k)&&k.length>=3&&(H.avgColor=[k[0],k[1],k[2]]);let ie=Z(o.normalMap),O=Z(o.emissiveMap),K=Z(o.aoMap),W={name:o.name||"",pbrMetallicRoughness:Y,doubleSided:o.side===2||!!o.doubleSided,...ie?{normalTexture:ie}:{},...O?{emissiveTexture:O}:{},...K?{occlusionTexture:K}:{},...Object.keys(H).length>0?{extras:H}:{}};if(o.emissive&&(o.emissive.r>0||o.emissive.g>0||o.emissive.b>0)){let N=o.emissiveIntensity??1;W.emissiveFactor=[o.emissive.r*N,o.emissive.g*N,o.emissive.b*N]}let I={};return o.clearcoat&&o.clearcoat>0&&(I.KHR_materials_clearcoat={clearcoatFactor:o.clearcoat,clearcoatRoughnessFactor:o.clearcoatRoughness||0}),o.sheen&&o.sheen>0&&(I.KHR_materials_sheen={sheenColorFactor:o.sheenColor?[o.sheenColor.r,o.sheenColor.g,o.sheenColor.b]:[1,1,1],sheenRoughnessFactor:o.sheenRoughness||0}),o.transmission&&o.transmission>0&&(I.KHR_materials_transmission={transmissionFactor:o.transmission}),o.thickness&&o.thickness>0&&(I.KHR_materials_volume={thicknessFactor:o.thickness,attenuationDistance:o.attenuationDistance??1/0,attenuationColor:o.attenuationColor?[o.attenuationColor.r,o.attenuationColor.g,o.attenuationColor.b]:[1,1,1]}),o.ior!==void 0&&o.ior!==1.5&&(I.KHR_materials_ior={ior:o.ior}),o.dispersion&&o.dispersion>0&&(I.KHR_materials_dispersion={dispersion:o.dispersion}),o.iridescence&&o.iridescence>0&&(I.KHR_materials_iridescence={iridescenceFactor:o.iridescence,iridescenceIor:o.iridescenceIOR??1.3}),Object.keys(I).length>0&&(W.extensions=I),v.push(W),x}function u(f,x){let o=new Uint8Array(f.buffer,f.byteOffset,f.byteLength),d=$t(o.byteLength),U=new Uint8Array(d);U.set(o),i.push(U);let j=a.length;return a.push({buffer:0,byteOffset:r,byteLength:o.byteLength,target:x}),r+=d,j}function l(f,x,o,d,U,j,B){let Y=u(f,o),H=s.length,Z={bufferView:Y,byteOffset:0,componentType:d,count:U,type:x};return j&&(Z.min=j),B&&(Z.max=B),s.push(Z),H}e.traverse(f=>{if(f.isLight||f.color&&f.intensity!==void 0){let x=f.matrixWorld?.elements,o=ee(x?x[12]:f.position?.x,0),d=ee(x?x[13]:f.position?.y,0),U=ee(x?x[14]:f.position?.z,0),j=f.target,B=j?.parent?j?.matrixWorld?.elements:void 0,Y=ee(B?B[12]:j?.position?.x,0),H=ee(B?B[13]:j?.position?.y,0),Z=ee(B?B[14]:j?.position?.z,0),te=Y-o,re=H-d,k=Z-U,ie=Math.hypot(te,re,k),O=Math.max(.01,Math.min(Math.PI/2,ee(f.angle,Math.PI/3))),K=Math.max(0,Math.min(1,ee(f.penumbra,0)));A.push({type:f.type,color:[f.color.r,f.color.g,f.color.b],intensity:f.intensity,position:[o,d,U],...f.type==="spot"?{direction:ie>1e-6?[te/ie,re/ie,k/ie]:[0,-1,0],outerConeAngle:O,innerConeAngle:Math.max(0,O*(1-K)),range:Math.max(0,ee(f.distance,0))}:f.type==="point"?{range:Math.max(0,ee(f.distance,0))}:{}})}});let M=[],P=new Set([e]),$=[];if(Array.isArray(e.children))for(let f=e.children.length-1;f>=0;f--)$.push({obj:e.children[f],parentKids:M});for(;$.length>0;){let{obj:f,parentKids:x}=$.pop();if(!f||typeof f!="object"||P.has(f))continue;P.add(f),f._bakeAuthorGeometry?.(),pe().materializeDeclarativeGeometry?.(f);let o=!!(f.userData&&(f.userData.xr&&typeof f.userData.xr=="object"&&Object.keys(f.userData.xr).length>0||f.userData.interactivity&&typeof f.userData.interactivity=="object"&&Object.keys(f.userData.interactivity).length>0)),d={name:f.name||(o?`Node_${p.length}`:"")},U=ee(f.position?.x,0),j=ee(f.position?.y,0),B=ee(f.position?.z,0),Y=ee(f.quaternion?.x,0),H=ee(f.quaternion?.y,0),Z=ee(f.quaternion?.z,0),te=ee(f.quaternion?.w,1),re=ee(f.scale?.x,1),k=ee(f.scale?.y,1),ie=ee(f.scale?.z,1);if((U||j||B)&&(d.translation=[U,j,B]),(Y||H||Z||te!==1)&&(d.rotation=[Y,H,Z,te]),(re!==1||k!==1||ie!==1)&&(d.scale=[re,k,ie]),f.visible===!1&&(d.extensions={...d.extensions||{},KHR_node_visibility:{visible:!1}},g.add("KHR_node_visibility")),f.userData&&Object.keys(f.userData).length>0&&(d.extras=JSON.parse(JSON.stringify(f.userData,(W,I)=>{if(!(W==="__proto__"||W==="prototype"||W==="constructor"))return typeof I=="function"?void 0:I})),f.userData.xr)){let W=Ht(f.userData.xr);d.extensions={...d.extensions||{},MOZ_hubs_components:W,ANDROID_xr_scenecore:W},pe().xrTraitSerializer?.gltfNode(d,f.userData.xr),g.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(f.geometry){let W=f.geometry,I=W.attributes.position;if(I&&I.count>0){let N=[1/0,1/0,1/0],z=[-1/0,-1/0,-1/0];for(let ae=0;ae<I.count;ae++){let se=I.getX(ae),oe=I.getY(ae),ne=I.getZ(ae);se<N[0]&&(N[0]=se),se>z[0]&&(z[0]=se),oe<N[1]&&(N[1]=oe),oe>z[1]&&(z[1]=oe),ne<N[2]&&(N[2]=ne),ne>z[2]&&(z[2]=ne)}let X={attributes:{POSITION:l(I.array,"VEC3",34962,5126,I.count,N,z)}};if(W.attributes.normal&&(X.attributes.NORMAL=l(W.attributes.normal.array,"VEC3",34962,5126,W.attributes.normal.count)),W.attributes.uv&&(X.attributes.TEXCOORD_0=l(W.attributes.uv.array,"VEC2",34962,5126,W.attributes.uv.count)),W.index){let ae=W.index.array instanceof Uint32Array;X.indices=l(W.index.array,"SCALAR",34963,ae?5125:5123,W.index.count)}let q=Array.isArray(f.material)?f.material[0]:f.material;q&&(X.material=w(q));let J=f.userData?.variants;if(J&&typeof J=="object"){let ae=new Map;for(let se of Object.keys(J)){if(!se||se==="__proto__"||se==="constructor"||se==="prototype")continue;let oe=J[se];if(!oe||typeof oe!="object")continue;let ne=C.indexOf(se);if(ne===-1&&C.length<256&&(ne=C.length,C.push(se)),ne===-1)continue;let de=w(oe),ge=ae.get(de);ge||(ge=[],ae.set(de,ge)),ge.push(ne)}if(ae.size>0){let se=[];for(let[oe,ne]of ae.entries())se.push({material:oe,variants:ne});X.extensions={...X.extensions||{},KHR_materials_variants:{mappings:se}},g.add("KHR_materials_variants")}}let Q=f;if(Q.isInstancedMesh&&typeof Q.count=="number"&&Q.count>0&&Q.instanceMatrix?.array){let ae=Math.min(1e4,Math.floor(Q.count)),se=Q.instanceMatrix.array,oe=new Float32Array(ae*3),ne=new Float32Array(ae*4),de=new Float32Array(ae*3);for(let le=0;le<ae;le++){let{t:be,r:ye,s:Te}=pt(se,le*16);oe[le*3]=be[0],oe[le*3+1]=be[1],oe[le*3+2]=be[2],ne[le*4]=ye[0],ne[le*4+1]=ye[1],ne[le*4+2]=ye[2],ne[le*4+3]=ye[3],de[le*3]=Te[0],de[le*3+1]=Te[1],de[le*3+2]=Te[2]}let ge={TRANSLATION:l(oe,"VEC3",0,5126,ae),ROTATION:l(ne,"VEC4",0,5126,ae),SCALE:l(de,"VEC3",0,5126,ae)};if(Q.instanceColor?.array&&Q.instanceColor.array.length>=ae*3){let le=new Float32Array(Q.instanceColor.array.subarray(0,ae*3));ge._COLOR_0=l(le,"VEC3",0,5126,ae)}d.extensions={...d.extensions||{},EXT_mesh_gpu_instancing:{attributes:ge}},g.add("EXT_mesh_gpu_instancing")}let ue=m.length;m.push({primitives:[X],name:f.name,...d.extras?{extras:d.extras}:{}}),d.mesh=ue}}let O=p.length;p.push(d),c.push(f),x.push(O);let K=f.children;if(Array.isArray(K)&&K.length>0){let W=[];d.children=W;for(let I=K.length-1;I>=0;I--)$.push({obj:K[I],parentKids:W})}}for(let f=0;f<p.length;f++){let x=p[f];x.children&&x.children.length===0?delete x.children:x.children&&x.children.length>0&&(x.extras?.xr?.lod||x.extensions?.ANDROID_xr_scenecore?.lod||c[f]?.isLOD)&&(x.extensions={...x.extensions||{},MSFT_lod:{ids:[...x.children]}},g.add("MSFT_lod"))}let V=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),F=[];if(typeof V=="function"&&c.length>0){let f=t?.duration??4,x=t?.fps??15,o=Math.max(2,Math.round(f*x)+1),d=new Float32Array(o),U=c.map(k=>[ee(k.position?.x,0),ee(k.position?.y,0),ee(k.position?.z,0),ee(k.quaternion?.x,0),ee(k.quaternion?.y,0),ee(k.quaternion?.z,0),ee(k.quaternion?.w,1),ee(k.scale?.x,1),ee(k.scale?.y,1),ee(k.scale?.z,1)]),j=c.map(()=>new Float32Array(o*3)),B=c.map(()=>new Float32Array(o*4)),Y=c.map(()=>new Float32Array(o*3));for(let k=0;k<o;k++){let ie=k/(o-1)*f;d[k]=ie;try{V(ie)}catch{}for(let O=0;O<c.length;O++){let K=c[O];j[O][k*3]=ee(K.position?.x,0),j[O][k*3+1]=ee(K.position?.y,0),j[O][k*3+2]=ee(K.position?.z,0);let W=ee(K.quaternion?.x,0),I=ee(K.quaternion?.y,0),N=ee(K.quaternion?.z,0),z=ee(K.quaternion?.w,1),X=Math.hypot(W,I,N,z)||1;if(W/=X,I/=X,N/=X,z/=X,k>0){let q=(k-1)*4,J=B[O];J[q]*W+J[q+1]*I+J[q+2]*N+J[q+3]*z<0&&(W=-W,I=-I,N=-N,z=-z)}B[O][k*4]=W,B[O][k*4+1]=I,B[O][k*4+2]=N,B[O][k*4+3]=z,Y[O][k*3]=ee(K.scale?.x,1),Y[O][k*3+1]=ee(K.scale?.y,1),Y[O][k*3+2]=ee(K.scale?.z,1)}}for(let k=0;k<c.length;k++){let ie=c[k],O=U[k];ie.position?.set(O[0],O[1],O[2]),ie.quaternion?.set(O[3],O[4],O[5],O[6]),ie.scale?.set(O[7],O[8],O[9])}e.updateMatrixWorld(!0);let H=null,Z=()=>(H===null&&(H=l(d,"SCALAR",0,5126,o,[0],[f])),H),te=[],re=[];for(let k=0;k<c.length;k++){let ie=U[k],O=(W,I,N)=>W.some((z,X)=>Math.abs(z-ie[N+X%I])>1e-4),K=(W,I,N,z)=>{W&&re.push({sampler:te.push({input:Z(),interpolation:"LINEAR",output:l(I,N,0,5126,o)})-1,target:{node:k,path:z}})};K(O(j[k],3,0),j[k],"VEC3","translation"),K(O(B[k],4,3),B[k],"VEC4","rotation"),K(O(Y[k],3,7),Y[k],"VEC3","scale")}re.length>0&&F.push({name:"ProceduralLoop",samplers:te,channels:re})}let _=Ve(p,m,e.userData),T=[],L=[],R=[];for(let f=0;f<p.length;f++){let x=p[f],o=bt(x.extras?.xr);if(!o)continue;let{ae:d,src:U,preset:j,volume:B,loop:Y,isGlobal:H}=o,Z=x.name||`Node_${f}`,te=L.length;L.push({name:`${Z}_source`,gain:B,loop:Y,autoPlay:typeof d.autoplay=="boolean"?d.autoplay:!0,...U!==void 0?{audio:T.push({uri:U})-1}:{},...j?{extras:{preset:j,pitch:Me(d.pitch,.25,4,1)}}:{}});let re=R.length,k=Me(d.refDistance,.05,100,1),ie=Me(d.coneInnerAngle,0,360,360),O=Me(d.coneOuterAngle,ie,360,360);R.push({name:`${Z}_emitter`,type:H?"global":"positional",gain:B,sources:[te],...H?{}:{positional:{distanceModel:d.distanceModel==="linear"||d.distanceModel==="exponential"?d.distanceModel:"inverse",refDistance:k,maxDistance:Me(d.maxDistance,k,500,Math.max(k,25)),rolloffFactor:Me(d.rolloffFactor,0,10,1),coneInnerAngle:+(ie*Math.PI/180).toFixed(6),coneOuterAngle:+(O*Math.PI/180).toFixed(6),coneOuterGain:Me(d.coneOuterGain,0,1,0)}}}),x.extensions={...x.extensions||{},KHR_audio_emitter:{emitter:re}},g.add("KHR_audio_emitter")}let n={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:M}],scene:0,nodes:p,meshes:m,materials:v,...D.length>0?{images:D}:{},...S.length>0?{samplers:S}:{},...h.length>0?{textures:h}:{},accessors:s,bufferViews:a,buffers:[{byteLength:r}],...F.length>0?{animations:F}:{},..._||g.size>0?{extensionsUsed:[..._?["KHR_interactivity"]:[],...g]}:{},..._||C.length>0||R.length>0?{extensions:{..._?{KHR_interactivity:_}:{},...C.length>0?{KHR_materials_variants:{variants:C.map(f=>({name:f}))}}:{},...R.length>0?{KHR_audio_emitter:{...T.length>0?{audio:T}:{},sources:L,emitters:R}}:{}}}:{}},E=new Uint8Array(r),G=0;for(let f of i)E.set(f,G),G+=f.byteLength;return[{gltf:n,bin:E.buffer,lights:A,environmentIntensity:e.environmentIntensity},c]}function Ue(e){return new TextEncoder().encode(e)}function zt(e,t){let{gltf:i,bin:r}=gt(e,t),a=JSON.stringify(i),s=Ue(a),m=(4-s.byteLength%4)%4,p=s.byteLength+m,g=20+p+8+r.byteLength,c=new Uint8Array(g),v=new DataView(c.buffer);v.setUint32(0,1179937895,!0),v.setUint32(4,2,!0),v.setUint32(8,g,!0),v.setUint32(12,p,!0),v.setUint32(16,1313821514,!0),c.set(s,20);for(let D=0;D<m;D++)c[20+s.byteLength+D]=32;let y=20+p;return v.setUint32(y,r.byteLength,!0),v.setUint32(y+4,5130562,!0),c.set(new Uint8Array(r),y+8),c}function qe(e,t){let[i,r]=yt(e,t);return ke(i,r)}function ke(e,t){let i=[],r=e.gltf,a=pe().decoders.get("meshopt");a&&typeof a.decodeBufferViews=="function"&&a.decodeBufferViews(r,e);let s=e.bin,m=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),p=r.accessors||[],g=r.bufferViews||[],c=r.materials||[],v=r.meshes||[],y=r.nodes||[],D=r.textures||[],S=r.images||[],h=r.samplers||[],b=new Set,C=c.map((P,$)=>dt(b,Se(P?.name,`Material_${$}`))),A=new Map;function w(P){let $=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(P);if(!$)return null;let V=$[2].replace(/\s+/g,""),F=V.endsWith("==")?2:V.endsWith("=")?1:0,_=new Uint8Array((V.length*3>>2)-F),T=R=>{let n=V.charCodeAt(R);return n>96?n-71:n>64?n-65:n>47?n+4:n===43?62:n===47?63:0},L=0;for(let R=0;R<V.length;R+=4){let n=T(R)<<18|T(R+1)<<12|T(R+2)<<6|T(R+3);_[L++]=n>>16&255,L<_.length&&(_[L++]=n>>8&255),L<_.length&&(_[L++]=n&255)}return _}function u(P,$,V){let F=P?.index;if(typeof F!="number")return;let _=D[F],T=_?.source;if(typeof T!="number"||!S[T])return;let L=A.get(T);if(L===void 0){L=null;let E=S[T],G=null;if(typeof E.bufferView=="number"){let f=g[E.bufferView],x=f?.byteOffset||0,o=f?.byteLength||0;f&&o>0&&x>=0&&x+o<=m.byteLength&&(G=new Uint8Array(m,x,o))}else typeof E.uri=="string"&&(G=w(E.uri));if(G&&G.byteLength>0){let f=G[0]===255&&G[1]===216&&G[2]===255||!(G[0]===137&&G[1]===80)&&/jpe?g/i.test(E.mimeType||E.uri||"");L={file:`texture_${T}.${f?"jpg":"png"}`,data:G}}A.set(T,L)}if(!L)return;let R=typeof _.sampler=="number"?h[_.sampler]:void 0,n=E=>E===33071?"clamp":E===33648?"mirror":"repeat";return{file:L.file,data:L.data,wrapS:n(R?.wrapS),wrapT:n(R?.wrapT),...$?{scale:$}:{},...V?{bias:V}:{}}}function l(P){let $=p[P];if(!$)throw new Error(`Accessor ${P} not found`);let V=g[$.bufferView||0],F=(V.byteOffset||0)+($.byteOffset||0),_=V.byteLength||0;return{acc:$,buffer:m.slice(F,F+_)}}function M(P,$,V,F){let _=[],T=v[P];if(!T)return _;let L=T.primitives||[];for(let R=0;R<L.length;R++){let n=L[R],E=n.attributes?.POSITION;if(E===void 0)continue;let{acc:G,buffer:f}=l(E),x=new Float32Array(f,0,G.count*3),o,d=n.attributes?.NORMAL;if(d!==void 0){let{acc:I,buffer:N}=l(d),z=new Float32Array(N,0,I.count*3);o=new Float32Array(z.length);for(let X=0;X<I.count;X++){let q=z[X*3],J=z[X*3+1],Q=z[X*3+2],ue=Math.hypot(q,J,Q)||1;o[X*3]=q/ue,o[X*3+1]=J/ue,o[X*3+2]=Q/ue}}let U,j=n.attributes?.TEXCOORD_0;if(j!==void 0){let{acc:I,buffer:N}=l(j);U=new Float32Array(N,0,I.count*2)}let B;if(n.indices!==void 0){let{acc:I,buffer:N}=l(n.indices);B=I.componentType===5125?new Uint32Array(N,0,I.count):new Uint16Array(N,0,I.count);let z=G.count;for(let X of B)if(X>=z)throw new Error(`SecurityError: Index buffer value (${X}) out of vertex bounds [0, ${z}).`)}else{let I=G.count;B=I>65535?new Uint32Array(I):new Uint16Array(I);for(let N=0;N<I;N++)B[N]=N}let Y="DefaultMaterial",H=[1,1,1],Z=.5,te=0,re=0,k=0,ie=1.5,O=1,K=[0,0,0],W;if(n.material!==void 0&&c[n.material]){let I=c[n.material];Y=C[n.material]||`Material_${n.material}`;let N=I.pbrMetallicRoughness||{},z=(be,ye)=>Array.isArray(be)&&be.length>=3?[be[0],be[1],be[2]]:ye;H=z(N.baseColorFactor,[1,1,1]);let X=Array.isArray(N.baseColorFactor)&&typeof N.baseColorFactor[3]=="number"?N.baseColorFactor[3]:1,q=H[0]!==1||H[1]!==1||H[2]!==1||X!==1,J=u(N.baseColorTexture,q?[H[0],H[1],H[2],X]:void 0),Q=I.extras?.avgColor;!J&&Array.isArray(Q)&&Q.length>=3&&(H=[H[0]*Q[0],H[1]*Q[1],H[2]*Q[2]]),typeof N.roughnessFactor=="number"&&(Z=N.roughnessFactor),typeof N.metallicFactor=="number"&&(te=N.metallicFactor);let ue=typeof N.roughnessFactor=="number"?N.roughnessFactor:1,ae=typeof N.metallicFactor=="number"?N.metallicFactor:1,se=u(N.metallicRoughnessTexture,ue!==1||ae!==1?[1,ue,ae,1]:void 0);K=z(I.emissiveFactor,[0,0,0]);let oe=(K[0]>0||K[1]>0||K[2]>0)&&(K[0]!==1||K[1]!==1||K[2]!==1)?[K[0],K[1],K[2],1]:void 0,ne=u(I.emissiveTexture,oe),de=u(I.normalTexture,[2,2,2,1],[-1,-1,-1,0]),ge=u(I.occlusionTexture);(J||se||de||ne||ge)&&(W=[J,se,de,ne,ge]);let le=I.extensions||{};le.KHR_materials_clearcoat&&(re=le.KHR_materials_clearcoat.clearcoatFactor??0,k=le.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof le.KHR_materials_ior?.ior=="number"&&(ie=le.KHR_materials_ior.ior),O=X*(1-(le.KHR_materials_transmission?.transmissionFactor??0))}_.push({name:L.length>1?`${$}_p${R}`:$,positions:x,indices:B,normals:o,uvs:U,materialName:Y,color:H,roughness:Z,metallic:te,clearcoat:re,clearcoatRoughness:k,ior:ie,opacity:O,emissiveColor:K,...W?{textures:W}:{},xrTraits:V||T.extras?.xr,...F?{invisible:!0}:{}})}return _}if(y.length>0){let P=new Float32Array(0),$=new Uint16Array(0),V=(x,o)=>{if(x===void 0)return null;let{acc:d,buffer:U}=l(x);return new Float32Array(U,0,d.count*o)},F=(x,o)=>Array.isArray(x)&&x.length>=3?[ee(x[0],o),ee(x[1],o),ee(x[2],o)]:[o,o,o],_=(x,o,d)=>x&&x.length>=(o+1)*3?[x[o*3],x[o*3+1],x[o*3+2]]:d,T=(x,o,d)=>x&&x.length>=(o+1)*4?[x[o*4],x[o*4+1],x[o*4+2],x[o*4+3]]:d,L=new Map,R=r.animations?.[0];if(R&&Array.isArray(R.channels)&&Array.isArray(R.samplers))for(let x of R.channels){let o=R.samplers[x?.sampler],d=x?.target?.node,U=x?.target?.path;if(!o||typeof d!="number"||o.input===void 0)continue;let j=L.get(d);j||(j={input:o.input},L.set(d,j)),U==="translation"?j.t=o.output:U==="rotation"?j.r=o.output:U==="scale"&&(j.s=o.output)}let n=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(n)||n.length===0){let x=new Set;for(let o of y)if(Array.isArray(o?.children))for(let d of o.children)x.add(d);n=[];for(let o=0;o<y.length;o++)x.has(o)||n.push(o);n.length===0&&(n=[0])}let E=new Set,G=[],f=(x,o)=>{if(Array.isArray(x))for(let d=x.length-1;d>=0;d--)G.push({idx:x[d],out:o})};for(f(n,i);G.length>0;){let{idx:x,out:o}=G.pop();if(typeof x!="number"||x<0||x>=y.length||E.has(x))continue;E.add(x);let d=y[x];if(!d)continue;let U=[0,0,0],j=[0,0,0,1],B=[1,1,1];if(Array.isArray(d.matrix)&&d.matrix.length===16){let O=pt(d.matrix);U=O.t,j=O.r,B=O.s}else U=F(d.translation,0),Array.isArray(d.rotation)&&d.rotation.length>=4&&(j=[ee(d.rotation[0],0),ee(d.rotation[1],0),ee(d.rotation[2],0),ee(d.rotation[3],1)]),B=F(d.scale,1);let Y,H=L.get(x);if(H){let O=V(H.input,1);if(O&&O.length>0){let K=V(H.t,3),W=V(H.r,4),I=V(H.s,3),N=Array.from(O),z=[],X=[],q=[];for(let J=0;J<O.length;J++)z.push(_(K,J,U)),X.push(T(W,J,j)),q.push(_(I,J,B));Y={times:N,translations:z,rotations:X,scales:q}}}let Z=Array.isArray(d.children)?d.children:[],te=typeof d.mesh=="number"&&d.mesh>=0&&d.mesh<v.length,re=t?.[x]?.userData?.xr??d.extras?.xr;if(!te&&Z.length===0&&(d.camera!==void 0||d.extensions?.KHR_lights_punctual||!d.name&&!d.extras&&!re&&!Y))continue;let k=(O,K,W)=>({name:O,positions:P,indices:$,isXform:!0,xrTraits:re,timeSamples:Y,translation:U,rotation:j,scale:B,children:K,...W?{invisible:!0}:{}}),ie=d.visible===!1||d.extensions?.KHR_node_visibility?.visible===!1||t?.[x]?.visible===!1;if(te){let O=d.name||v[d.mesh]?.name||`Mesh_${x}`,K=M(d.mesh,O,re,ie),W=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(W&&typeof W=="object"&&K.length>0){let I=V(W.TRANSLATION,3),N=V(W.ROTATION,4),z=V(W.SCALE,3),X=V(W._COLOR_0,3),q=Math.min(1e3,I?I.length/3:N?N.length/4:z?z.length/3:0);if(q>0){let J=[];for(let Q=0;Q<q;Q++){let ue=_(I,Q,[0,0,0]),ae=T(N,Q,[0,0,0,1]),se=_(z,Q,[1,1,1]);for(let oe of K){let ne=oe.color||[.8,.8,.8],de=X&&X.length>=(Q+1)*3;J.push({...oe,name:`${oe.name}_${Q}`,materialName:de?`${oe.materialName}_inst_${Q}`:oe.materialName,color:de?[ne[0]*X[Q*3],ne[1]*X[Q*3+1],ne[2]*X[Q*3+2]]:oe.color,translation:ue,rotation:ae,scale:se})}}f(Z,J),o.push(k(O,J,ie));continue}}if(K.length===1)K[0].translation=U,K[0].rotation=j,K[0].scale=B,K[0].timeSamples=Y,Z.length>0&&(K[0].children=[],f(Z,K[0].children)),o.push(K[0]);else{let I=[...K];f(Z,I),o.push(k(O,I,ie))}}else{let O=[];f(Z,O),o.push(k(d.name||`Group_${x}`,O,ie))}}}else for(let P=0;P<v.length;P++){let $=v[P].name||`Mesh_${P}`;i.push(...M(P,$,v[P].extras?.xr))}return i}function Se(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 De(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function he(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 xe=(e,t,i)=>`(${he(e)}, ${he(t)}, ${he(i)})`,_e=(e,t,i,r)=>`(${he(e)}, ${he(t)}, ${he(i)}, ${he(r)})`;function ft(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=xe(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function Wt(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${he(e[r*2])}, ${he(1-e[r*2+1])})`;return i.join(", ")}function jt(e){return Array.from(e).join(", ")}function Be(e){let t=new Map,i=0,r=null,a=[...e];for(;a.length>0;){let h=a.pop();if(!h.isXform&&h.positions&&h.positions.length>0){let b=Se(h.materialName,"DefaultMaterial");t.has(b)||t.set(b,{color:h.color||[1,1,1],roughness:h.roughness??.5,metallic:h.metallic??0,clearcoat:h.clearcoat??0,clearcoatRoughness:h.clearcoatRoughness??0,ior:h.ior??1.5,opacity:h.opacity??1,emissiveColor:h.emissiveColor||[0,0,0],textures:h.textures})}if(h.timeSamples&&h.timeSamples.times.length>0){let b=h.timeSamples.times[h.timeSamples.times.length-1];b>i&&(i=b)}if(h.xrTraits?.anchor&&!r&&(r=h.xrTraits.anchor==="vertical"||h.xrTraits.anchor==="wall"?"vertical":"horizontal"),h.children)for(let b=h.children.length-1;b>=0;b--)a.push(h.children[b])}let s="";i>0&&(s=`startTimeCode = 0
|
|
250
|
+
endTimeCode = ${he(i)}
|
|
251
251
|
timeCodesPerSecond = 1.0
|
|
252
252
|
`);let m="";r&&(m=`uniform token preliminary:anchoring:type = "plane"
|
|
253
253
|
uniform token preliminary:planeAnchoring:alignment = "${r}"
|
|
254
|
-
`);let
|
|
254
|
+
`);let p=`#usda 1.0
|
|
255
255
|
(
|
|
256
256
|
defaultPrim = "Root"
|
|
257
257
|
metersPerUnit = 1.0
|
|
@@ -264,78 +264,105 @@ kind = "component"
|
|
|
264
264
|
{
|
|
265
265
|
${m}def Scope "Materials"
|
|
266
266
|
{
|
|
267
|
-
`;for(let[
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
`),
|
|
272
|
-
`),
|
|
267
|
+
`;for(let[h,b]of t.entries()){let[C,A,w]=b.color,[u,l,M]=b.emissiveColor,P=`/Root/Materials/${h}`,[$,V,F,_,T]=b.textures||[],L=(f,x)=>`.connect = <${P}/${f}.outputs:${x}>`,R=$?`color3f inputs:diffuseColor${L("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${xe(C,A,w)}`,n=V?`float inputs:metallic${L("MetallicRoughnessTexture","b")}
|
|
268
|
+
float inputs:roughness${L("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${he(b.metallic)}
|
|
269
|
+
float inputs:roughness = ${he(b.roughness)}`,E="";b.clearcoat>0&&(E+=`float inputs:clearcoat = ${he(b.clearcoat)}
|
|
270
|
+
`,E+=`float inputs:clearcoatRoughness = ${he(b.clearcoatRoughness)}
|
|
271
|
+
`),b.ior!==1.5&&(E+=`float inputs:ior = ${he(b.ior)}
|
|
272
|
+
`),b.opacity<1&&(E+=`float inputs:opacity = ${he(b.opacity)}
|
|
273
|
+
`),_?E+=`color3f inputs:emissiveColor${L("EmissiveTexture","rgb")}
|
|
274
|
+
`:(u>0||l>0||M>0)&&(E+=`color3f inputs:emissiveColor = ${xe(u,l,M)}
|
|
275
|
+
`),F&&(E+=`normal3f inputs:normal${L("NormalTexture","rgb")}
|
|
276
|
+
`),T&&(E+=`float inputs:occlusion${L("OcclusionTexture","r")}
|
|
277
|
+
`);let G="";if($||V||F||_||T){G+=`def Shader "PrimvarReader"
|
|
278
|
+
{
|
|
279
|
+
uniform token info:id = "UsdPrimvarReader_float2"
|
|
280
|
+
string inputs:varname = "st"
|
|
281
|
+
float2 outputs:result
|
|
282
|
+
}
|
|
283
|
+
`;let f=(x,o,d,U)=>{if(!o)return;let j=o.scale?`float4 inputs:scale = ${_e(o.scale[0],o.scale[1],o.scale[2],o.scale[3])}
|
|
284
|
+
`:"",B=o.bias?`float4 inputs:bias = ${_e(o.bias[0],o.bias[1],o.bias[2],o.bias[3])}
|
|
285
|
+
`:"";G+=`def Shader "${x}"
|
|
286
|
+
{
|
|
287
|
+
uniform token info:id = "UsdUVTexture"
|
|
288
|
+
asset inputs:file = @${De(o.file)}@
|
|
289
|
+
float2 inputs:st${L("PrimvarReader","result")}
|
|
290
|
+
token inputs:sourceColorSpace = "${d}"
|
|
291
|
+
token inputs:wrapS = "${o.wrapS||"repeat"}"
|
|
292
|
+
token inputs:wrapT = "${o.wrapT||"repeat"}"
|
|
293
|
+
${j}${B}${U}}
|
|
294
|
+
`};f("DiffuseTexture",$,"sRGB",`float3 outputs:rgb
|
|
295
|
+
`),f("MetallicRoughnessTexture",V,"raw",`float outputs:g
|
|
296
|
+
float outputs:b
|
|
297
|
+
`),f("NormalTexture",F,"raw",`float3 outputs:rgb
|
|
298
|
+
`),f("EmissiveTexture",_,"sRGB",`float3 outputs:rgb
|
|
299
|
+
`),f("OcclusionTexture",T,"raw",`float outputs:r
|
|
300
|
+
`)}p+=`def Material "${h}"
|
|
273
301
|
{
|
|
274
302
|
def Shader "PBRShader"
|
|
275
303
|
{
|
|
276
304
|
uniform token info:id = "UsdPreviewSurface"
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
${A}token outputs:surface
|
|
281
|
-
}
|
|
282
|
-
token outputs:surface.connect = </Root/Materials/${l}/PBRShader.outputs:surface>
|
|
305
|
+
${R}
|
|
306
|
+
${n}
|
|
307
|
+
${E}token outputs:surface
|
|
283
308
|
}
|
|
284
|
-
|
|
309
|
+
token outputs:surface${L("PBRShader","surface")}
|
|
310
|
+
${G}}
|
|
311
|
+
`}p+=`}
|
|
285
312
|
def Scope "Meshes"
|
|
286
313
|
{
|
|
287
|
-
`;let
|
|
314
|
+
`;let g=(h,b,C)=>{let A=[];b&&A.push('"MaterialBindingAPI"');let w=!!(h?.rigidBody&&h.rigidBody!=="none"&&(typeof h.rigidBody!="object"||h.rigidBody.enabled!==!1)),u=!!(h?.physics&&h.physics!=="none"||w);u&&A.push(...w?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let l=[];if(A.length>0&&l.push(`prepend apiSchemas = [${A.join(", ")}]`),h){let F=pe().xrTraitSerializer?.usdLines(h,De)??[];if(!F.length)for(let _ of["grab","billboard","follow","anchor","physics"]){let T=_==="follow"&&typeof h.follow=="object"?h.follow.mode??"head":h[_];T!==void 0&&F.push(`string ${_} = "${De(T)}"`)}F.length>0&&l.push(`customData = {
|
|
288
315
|
dictionary xr = {
|
|
289
|
-
${
|
|
316
|
+
${F.join(`
|
|
290
317
|
`)}
|
|
291
318
|
}
|
|
292
|
-
}`)}let
|
|
293
|
-
${
|
|
319
|
+
}`)}let M=l.length>0?` (
|
|
320
|
+
${l.join(`
|
|
294
321
|
`)}
|
|
295
|
-
)`:"",
|
|
296
|
-
`:"";if(
|
|
297
|
-
bool physics:kinematicEnabled = ${
|
|
322
|
+
)`:"",P=C?`uniform token visibility = "invisible"
|
|
323
|
+
`:"";if(u){let F=h?.rigidBody??h?.physics,_=F?.body??F?.mode??F;P+=`bool physics:rigidBodyEnabled = true
|
|
324
|
+
bool physics:kinematicEnabled = ${_==="static"||_==="kinematic"}
|
|
298
325
|
bool physics:collisionEnabled = true
|
|
299
|
-
`,
|
|
300
|
-
`)}let $=
|
|
326
|
+
`,F?.mass>0&&Number.isFinite(F.mass)&&(P+=`float physics:mass = ${he(F.mass)}
|
|
327
|
+
`)}let $=bt(h),V=$?`def SpatialAudio "AudioEmitter"
|
|
301
328
|
{
|
|
302
|
-
${$.src?`asset inputs:file = @${
|
|
329
|
+
${$.src?`asset inputs:file = @${De($.src)}@
|
|
303
330
|
`:""}uniform token inputs:auralMode = "${$.isGlobal?"nonSpatial":"spatial"}"
|
|
304
331
|
uniform token inputs:playbackMode = "${$.loop?"loopFromStart":"onceFromStart"}"
|
|
305
|
-
double gain = ${
|
|
332
|
+
double gain = ${he($.volume)}
|
|
306
333
|
}
|
|
307
|
-
`:"";return{header:
|
|
334
|
+
`:"";return{header:M,body:P,tail:V}},c=h=>{if(h.timeSamples&&h.timeSamples.times.length>0){let l=h.timeSamples,M=(F,_,T)=>l.times.map((L,R)=>`${he(L)}: ${T(F?.[R]||_)}`).join(", "),P=M(l.translations,[0,0,0],F=>xe(F[0],F[1],F[2])),$=M(l.rotations,[0,0,0,1],F=>{let _=Math.hypot(F[0],F[1],F[2],F[3])||1;return _e(F[3]/_,F[0]/_,F[1]/_,F[2]/_)}),V=M(l.scales,[1,1,1],F=>xe(F[0],F[1],F[2]));return`double3 xformOp:translate.timeSamples = { ${P} }
|
|
308
335
|
quatf xformOp:orient.timeSamples = { ${$} }
|
|
309
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
336
|
+
double3 xformOp:scale.timeSamples = { ${V} }
|
|
310
337
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
311
|
-
`}let
|
|
312
|
-
`,
|
|
313
|
-
`,
|
|
314
|
-
`,
|
|
315
|
-
`),
|
|
316
|
-
int[] faceVertexCounts = [${
|
|
317
|
-
int[] faceVertexIndices = [${
|
|
318
|
-
point3f[] points = [${
|
|
319
|
-
`;return
|
|
338
|
+
`}let b=[],C="",A=h.translation;A&&(Math.abs(A[0])>1e-7||Math.abs(A[1])>1e-7||Math.abs(A[2])>1e-7)&&(C+=`double3 xformOp:translate = ${xe(A[0],A[1],A[2])}
|
|
339
|
+
`,b.push('"xformOp:translate"'));let w=h.rotation;if(w){let l=Math.hypot(w[0],w[1],w[2],w[3])||1,M=w[0]/l,P=w[1]/l,$=w[2]/l,V=w[3]/l;(1-Math.abs(V)>1e-7||Math.hypot(M,P,$)>1e-7)&&(C+=`quatf xformOp:orient = ${_e(V,M,P,$)}
|
|
340
|
+
`,b.push('"xformOp:orient"'))}let u=h.scale;return u&&(Math.abs(u[0]-1)>1e-7||Math.abs(u[1]-1)>1e-7||Math.abs(u[2]-1)>1e-7)&&(C+=`float3 xformOp:scale = ${xe(u[0],u[1],u[2])}
|
|
341
|
+
`,b.push('"xformOp:scale"')),b.length>0&&(C+=`uniform token[] xformOpOrder = [${b.join(", ")}]
|
|
342
|
+
`),C},v=h=>{let b=h.positions.length/3,C=1/0,A=1/0,w=1/0,u=-1/0,l=-1/0,M=-1/0;for(let _=0;_<b;_++){let T=h.positions[_*3],L=h.positions[_*3+1],R=h.positions[_*3+2];T<C&&(C=T),T>u&&(u=T),L<A&&(A=L),L>l&&(l=L),R<w&&(w=R),R>M&&(M=R)}isFinite(C)||(C=A=w=-1,u=l=M=1);let P=Math.floor(h.indices.length/3),$=Se(h.materialName,"DefaultMaterial"),V=P>0?P===1?"3":"3, ".repeat(P-1)+"3":"",F=`float3[] extent = [${xe(C,A,w)}, ${xe(u,l,M)}]
|
|
343
|
+
int[] faceVertexCounts = [${V}]
|
|
344
|
+
int[] faceVertexIndices = [${jt(h.indices)}]
|
|
345
|
+
point3f[] points = [${ft(h.positions)}]
|
|
346
|
+
`;return h.normals&&h.normals.length===h.positions.length&&(F+=`normal3f[] normals = [${ft(h.normals)}] (
|
|
320
347
|
interpolation = "vertex"
|
|
321
348
|
)
|
|
322
|
-
`),
|
|
349
|
+
`),h.uvs&&h.uvs.length===b*2&&(F+=`texCoord2f[] primvars:st = [${Wt(h.uvs,b)}] (
|
|
323
350
|
interpolation = "vertex"
|
|
324
351
|
)
|
|
325
|
-
`),
|
|
326
|
-
`,
|
|
327
|
-
`;continue}let{node:
|
|
352
|
+
`),F+=`rel material:binding = </Root/Materials/${$}>
|
|
353
|
+
`,F},y=new Set,D=[];for(let h=e.length-1;h>=0;h--)D.push({node:e[h],siblings:y});let S=0;for(;D.length>0;){let h=D.pop();if(h.close){p+=`}
|
|
354
|
+
`;continue}let{node:b,siblings:C}=h,A=!!(b.isXform||b.positions.length===0),w=dt(C,Se(b.name,A?`Group_${S}`:`Mesh_${S}`));S++;let u=b.children||[];if(A){let l=g(b.xrTraits,!1,b.invisible);p+=`def Xform "${w}"${l.header}
|
|
328
355
|
{
|
|
329
|
-
${
|
|
356
|
+
${l.body}${c(b)}${l.tail}`,D.push({close:!0});let M=new Set;for(let P=u.length-1;P>=0;P--)D.push({node:u[P],siblings:M})}else if(u.length>0){let l=g(b.xrTraits,!1,b.invisible),M=`${w}_mesh`;p+=`def Xform "${w}"${l.header}
|
|
330
357
|
{
|
|
331
|
-
${
|
|
358
|
+
${l.body}${c(b)}${l.tail}`,p+=`def Mesh "${M}" (
|
|
332
359
|
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
333
360
|
)
|
|
334
361
|
{
|
|
335
|
-
${
|
|
336
|
-
`,
|
|
362
|
+
${v(b)}}
|
|
363
|
+
`,D.push({close:!0});let P=new Set([M]);for(let $=u.length-1;$>=0;$--)D.push({node:u[$],siblings:P})}else{let l=g(b.xrTraits,!0,b.invisible);p+=`def Mesh "${w}"${l.header}
|
|
337
364
|
{
|
|
338
|
-
${
|
|
339
|
-
`}}return
|
|
365
|
+
${l.body}${c(b)}${v(b)}${l.tail}}
|
|
366
|
+
`}}return p+=`}
|
|
340
367
|
}
|
|
341
|
-
`,
|
|
368
|
+
`,p}function Xt(e,t){if(e&&typeof e.traverse=="function"){let a=qe(e,t);return Be(a)}let i=Re(e),r=ke(i);return Be(r)}var Ne=null;function xt(e){if(!Ne){Ne=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let a=0;a<8;a++)r=r&1?3988292384^r>>>1:r>>>1;Ne[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=Ne[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function vt(e){let t=[],i=0,r=[];for(let v of e){let y=Ue(v.filename),D=xt(v.data),S=v.data.length,h=30+y.length,b=(i+h)%64,C=b!==0?64-b:0;C>0&&C<4&&(C+=64);let A=new Uint8Array(h+C),w=new DataView(A.buffer);w.setUint32(0,67324752,!0),w.setUint16(4,20,!0),w.setUint32(14,D,!0),w.setUint32(18,S,!0),w.setUint32(22,S,!0),w.setUint16(26,y.length,!0),w.setUint16(28,C,!0),A.set(y,30),C>=4&&(w.setUint16(h,6534,!0),w.setUint16(h+2,C-4,!0)),t.push({offset:i,size:S,crc:D,filenameBytes:y,entry:v}),r.push(A,v.data),i+=A.length+v.data.length}let a=i;for(let v of t){let y=new Uint8Array(46+v.filenameBytes.length),D=new DataView(y.buffer);D.setUint32(0,33639248,!0),D.setUint16(4,20,!0),D.setUint16(6,20,!0),D.setUint32(16,v.crc,!0),D.setUint32(20,v.size,!0),D.setUint32(24,v.size,!0),D.setUint16(28,v.filenameBytes.length,!0),D.setUint32(42,v.offset,!0),y.set(v.filenameBytes,46),r.push(y),i+=y.length}let s=i-a,m=new Uint8Array(22),p=new DataView(m.buffer);p.setUint32(0,101010256,!0),p.setUint16(8,t.length,!0),p.setUint16(10,t.length,!0),p.setUint32(12,s,!0),p.setUint32(16,a,!0),r.push(m),i+=22;let g=new Uint8Array(i),c=0;for(let v of r)g.set(v,c),c+=v.length;return g}function Mt(e){let t=[{filename:"model.usda",data:Ue(Be(e))}],i=new Set(["model.usda"]),r=[...e];for(;r.length>0;){let a=r.pop();for(let s of a.textures||[])s?.file&&s.data?.byteLength&&!i.has(s.file)&&(i.add(s.file),t.push({filename:s.file,data:s.data}));if(a.children)for(let s=a.children.length-1;s>=0;s--)r.push(a.children[s])}return vt(t)}function Kt(e){return Mt(qe(e))}function Tt(e){return Mt(ke(Re(e)))}function At(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():Tt(e)}function qt(e){let t=At(e);return new Blob([t],{type:"model/vnd.usdz+zip"})}
|